Coder Social home page Coder Social logo

ui-ace's Introduction

UI.Ace directive Build Status

This directive allows you to add ACE editor elements.

Requirements

Usage

You can get it from Bower

bower install angular-ui-ace#bower

This will copy the UI.Ace files into a bower_components folder, along with its dependencies. Load the script files in your application:

<script type="text/javascript" src="bower_components/ace-builds/src-min-noconflict/ace.js"></script>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="bower_components/angular-ui-ace/ui-ace.js"></script>

Add the UI.Ace module as a dependency to your application module:

var myAppModule = angular.module('MyApp', ['ui.ace']);

Finally, add the directive to your html:

<div ui-ace></div>

To see something it's better to add some CSS, like

.ace_editor { height: 200px; }

Options

Ace doesn't provide a one gate access to all the options the jquery way. Each option is configured with the function of a specific instance. See the api doc for more.

Although, ui-ace automatically handles some handy options :

  • showGutter : to show the gutter or not.
  • useWrapMode : to set whether or not line wrapping is enabled.
  • theme : to set the theme to use.
  • mode : to set the mode to use.
  • onLoad : callback when the editor has finished loading (see below).
  • onChange : callback when the editor content is changed ().
  • onBlur : callback when the editor is blurred ().
  • firstLineNumber : to set the firstLineNumber (default: 1)
<div ui-ace="{
  useWrapMode : true,
  showGutter: false,
  theme:'twilight',
  mode: 'xml',
  firstLineNumber: 5,
  onLoad: aceLoaded,
  onChange: aceChanged
}"></div>

You'll want to define the onLoad and the onChange callback on your scope:

myAppModule.controller('MyController', [ '$scope', function($scope) {

  $scope.aceLoaded = function(_editor) {
    // Options
    _editor.setReadOnly(true);
  };

  $scope.aceChanged = function(e) {
    //
  };

}]);

To handle other options you'll have to use a direct access to the Ace created instance (see below).

Advanced Options

You can specify advanced options and even require options in the directive, as well. For this example, you will have to include the ext-language_tools.js file from the ace source code.

This will copy the UI.Ace files into a bower_components folder, along with its dependencies. Load the script files in your application:

<script type="text/javascript" src="bower_components/ace-builds/src-min-noconflict/ext-language_tools.js"></script>
<div ui-ace="{
  require: ['ace/ext/language_tools'],
  advanced: {
      enableSnippets: true,
      enableBasicAutocompletion: true,
      enableLiveAutocompletion: true
  }
}"></div>

To include options applicable to the ACE renderer, you can use the rendererOptions key:

<div ui-ace="{
  rendererOptions: {
      maxLinks: Infinity
  }
}"></div>

Support for concatenated bundles

Trying to use ace with concatenated javascript files usually fails because it changes the physical location of the workerPath. If you need to work with bundled or minified versions of ace, you can specify the original location of the workerPath on disk (not the bundled file).

This should be the folder on disk where ace.js resides.

<div ui-ace="{
  workerPath: '/path/to/ace/folder'
}"></div>

Working with ng-model

The ui-ace directive plays nicely with ng-model.

The ng-model will be watched for to set the Ace EditSession value (by setValue).

The ui-ace directive stores and expects the model value to be a standard javascript String.

Can be read only

Simple demo

<div ui-ace readonly></div>
or
Check me to make Ace readonly: <input type="checkbox" ng-model="checked" ><br/>
<div ui-ace ng-readonly="checked"></div>

Ace instance direct access

For more interaction with the Ace instance in the directive, we provide a direct access to it. Using

<div ui-ace="{ onLoad : aceLoaded }" ></div>

the $scope.aceLoaded function will be called with the Ace Editor instance as first argument

myAppModule.controller('MyController', [ '$scope', function($scope) {

  $scope.aceLoaded = function(_editor){
    // Editor part
    var _session = _editor.getSession();
    var _renderer = _editor.renderer;

    // Options
    _editor.setReadOnly(true);
    _session.setUndoManager(new ace.UndoManager());
    _renderer.setShowGutter(false);

    // Events
    _editor.on("changeSession", function(){ ... });
    _session.on("change", function(){ ... });
  };

}]);

Testing

We use Karma and jshint to ensure the quality of the code. The easiest way to run these checks is to use grunt:

npm install -g grunt-cli
npm install && bower install
grunt

The karma task will try to open Firefox and Chrome as browser in which to run the tests. Make sure this is available or change the configuration in test\karma.conf.js

Grunt Serve

We have one task to serve them all !

grunt serve

It's equal to run separately:

  • grunt connect:server : giving you a development server at http://127.0.0.1:8000/.

  • grunt karma:server : giving you a Karma server to run tests (at http://localhost:9876/ by default). You can force a test on this server with grunt karma:unit:run.

  • grunt watch : will automatically test your code and build your demo. You can demo generation with grunt build:gh-pages.

Dist

This repo is using the angular-ui/angular-ui-publisher. New tags will automatically trigger a new publication. To test is locally you can trigger a :

grunt dist build:bower

it will put the final files in the 'dist' folder and a sample of the bower tag output in the 'out/built/bower' folder.

ui-ace's People

Contributors

0x-r4bbit avatar benshell avatar choxi avatar ciel avatar douglasduteil avatar ebuildy avatar erikpena avatar marshall007 avatar mlabieniec avatar nickradford avatar peterdavehello avatar powerkiki avatar proloser avatar rebornix avatar ricochet1k avatar rotoshine avatar slopjong avatar wesleycho avatar zeitiger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ui-ace's Issues

Specify font family or families and font size?

I didn't see an easy way to do this. I tried the obvious, with no luck:

  $scope.uiAceConfig =
    useWrapMode : true
    showGutter: true
    theme: 'twilight'
    mode: 'html'
    fontFamily: 'Inconsolata'
    fontSize: '16px'
<div ui-ace="uiAceConfig" ng-model="content.html"></div>

Anyone find a way to do this? Thanks!

Automatically scrolling cursor into view after selection change this will be disabled in the next version set editor.$blockScrolling = Infinity to disable this message

After upgraded to version 1.1.9. The console started be polluted by this message:

Automatically scrolling cursor into view after selection change this will be disabled in the next version set editor.$blockScrolling = Infinity to disable this message

I have a lot of ui-ace editors, most of them don't have any onLoad. Can you take them away? Thanks.

$applyAsync() is only in Angular v1.3 and above.

I assume your intention was to continue supporting those of us lingering on the 1.1.x and 1.2.x branches, but unfortunately moving from $apply() to $applyAsync() has failed in that endeavor. I haven't read the conversation for why that move needed to be made, but the newer function is undefined on $scope in earlier branches and this causes erratic, breaking behavior.

Syntax error message doesn't disappear

In some cases the syntax error doesn't disappear anymore. As the screenshot shows I can edit the json in ace which is rendered as a tree on the right, which perfectly works.

If no other people are experiencing this, it has to be a local issue, which I need to investigate further.

2014-04-16-211059_803x128_scrot

Access to ace.config

is it possible to forward options or get access to the ace.config object? in our case we want to modify the basePath option to load themes and mode files from a specific folder

ace.config.set("basePath", "/path/to/src");

JSON Stringify on Arrays and Objects

Is there some specific reason why the ui-ace throws an exception when we are dealing with array or object types? At the first glance it seems perfectly safe to just stringify those types. Am I missing something?

Just wanted to hear your opinion about stringifying those before I submitted a PR.

ui-ace editor options set after, rather than before, onLoad callback function is called

In our app, we have a page with 3 ui-ace editors on the same page - one in html mode, one in css mode, and one in javascript mode. We use the same onLoad callback function for all three, since we want to set most of the same ACE options. But we also want to do a couple things specific to which editor is being configured. In order to determine, in the onLoad function, which of the three editors was being configured, we checked if the editor's mode was html, css, or javascript.

We recently upgraded Angular from 1.2 to 1.3, and ui-ace from 1.1.2 to 1.2.1. After these upgrades, the code described above stopped working, because the onLoad function was being called before, rather than after, the ui-ace options specified in the html had been applied.

Run the below plunk with the browser console open and watch the logging. Notice, that in onchange, the mode specified via ui-ace options in the html has not yet been set on the ACE editor (it's still set to the default mode, "text"), but after a $timeout, the mode has been set to "css".

http://plnkr.co/edit/QGr1j8jjRCVsaTVDveEA?p=preview

The question is, does it make more sense to call the onLoad callback before or after setting the ui-ace options on the ACE editor. I'm thinking setting them before might be more intuitive. What do you think?

Whatever is decided, I think it would be good to document the order in the README.

Set validity of ngModel

Hey,

what would be the best way to set the validity of ngModel, based on the value of getAnnotations?

I can access the getAnntations values by doing the following in my controller

$scope.aceLoaded = function(editor) {
  editor.getSession().on('changeAnnotation', function() {
    var annot = editor.getSession().getAnnotations();
  });
};

Within the uiAcedirective it would be possible to set the validity of the model by calling ngModel.$setValidity('annotations', isValid)

Whats your opinion about implementing this within the uiAce directive?

Bests, Mark

Broken on 1.3.2

ui.ace was working on angular-1.3.0-beta.9 but is broken on 1.3.2 with this error:

TypeError: Cannot read property '$formatters' of null
    at link (http://localhost:3041/vendor/angular-ui-ace/ui-ace.js:171:18)
    at invokeLinkFn (http://localhost:3041/vendor/angular/angular.js:8125:9)
    at nodeLinkFn (http://localhost:3041/vendor/angular/angular.js:7637:11)
    at compositeLinkFn (http://localhost:3041/vendor/angular/angular.js:6993:13)
    at nodeLinkFn (http://localhost:3041/vendor/angular/angular.js:7632:24)
    at compositeLinkFn (http://localhost:3041/vendor/angular/angular.js:6993:13)
    at compositeLinkFn (http://localhost:3041/vendor/angular/angular.js:6996:13)
    at publicLinkFn (http://localhost:3041/vendor/angular/angular.js:6872:30)
    at compile (http://localhost:3041/vendor/angular-ui-router/release/angular-ui-router.js:2805:9)
    at invokeLinkFn (http://localhost:3041/vendor/angular/angular.js:8125:9) <div ui-ace="{
          useWrapMode : true,
          showGutter: false,
          theme:'twilight',
          mode: 'sql',
          onLoad: aceLoaded,
          onChange: aceChanged
        }" class=" ace_editor ace-tm"> 

$digest already in progress

I sadly can't reproduce this error very easily but there are cases where I was making multiple editors on a page with ng-models (in an ng-repeat directive) and I was getting $digest already in progress from the onchange handler. There is already a line in here checking for scope.$$phase but I had to also check the rootscope using scope.$root.$$phase. This fixed my problem and appeared to work fine. I have no idea what the ramifications of this are as I'm pretty new to this stuff but I'd hoped that someone here could tell me.

Adding a custom ace/mode crashes with "define not defined"

angular-ui-ace works great, I got ACE embedded in my Angular app. Next problem is I'm trying to load a custom mode. In my $scope.aceLoaded callback, I am able to set the modePath as follows:

ace.config.set("modePath", "customModes");
...
session.setMode('ace/mode/tester');

So far so good, it loads the mode-tester.js mode from customModes. However, mode-test.js promply crashes with:

Uncaught ReferenceError: define is not defined 

At the first line which looks like this (see the Wiki):

define('ace/mode/tester', function(require, exports, module) {

So clearly, things like "define" and "require" aren't getting set up. Not sure if this is a requirejs thing, although it seems as thus far I haven't needed to use requirejs with Angular.

Any ideas?

editor.insert doesn't appear to trigger model change

I'm trying to create some actions to insert pre-defined text into the editor, but it doesn't appear to cause the model to change.

template:

in controller:

editor.insert("text to insert");

this is not causing the updateDefinition() method to be called.

Form elements?

Does Ace work with other elements besides <div>? I've got something like this:

<div ui-ace style="height: 200px;"></div>

...which shows the ace editor in the div, as expected. But if I just change it to this:

<textarea ui-ace class="form-control" style="height: 200px;"></textarea>

I can't even load the page -- Chromium tab will just hang, and eventually crash.

EDIT: sorry, I copied the sample code in incorrectly -- fixed now.

No license in javascript

The javascript file does not contain any comment as to the source of the code or the license it is under. This makes it difficult for end users to see the license. Could this be added to the source files?

"$digest already in progress" error occurs when using onChange attribute with ui-ace 0.2.0

After upgrading to ui-ace 0.2.0, I get the following error when ui-ace calls my onChange function:

Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.3.8/$rootScope/inprog?p0=%24digest
    at REGEX_STRING_REGEXP (https://localtest.evergage.com:8443/ui/bower_components/angular/angular.js:63:12)
    at beginPhase (https://localtest.evergage.com:8443/ui/bower_components/angular/angular.js:14737:15)
    at Scope.$get.Scope.$apply (https://localtest.evergage.com:8443/ui/bower_components/angular/angular.js:14481:11)
    at link.executeUserCallback (https://localtest.evergage.com:8443/ui/bower_components/angular-ui-ace/ui-ace.js:199:19)
    at Array.link.listenerFactory.onChange (https://localtest.evergage.com:8443/ui/bower_components/angular-ui-ace/ui-ace.js:237:15)
    at r._signal (https://localtest.evergage.com:8443/ui/bower_components/ace-builds/src-min-noconflict/ace.js:1:48711)
    at onChange (https://localtest.evergage.com:8443/ui/bower_components/ace-builds/src-min-noconflict/ace.js:1:149291)
    at r._signal (https://localtest.evergage.com:8443/ui/bower_components/ace-builds/src-min-noconflict/ace.js:1:48711)
    at removeInLine (https://localtest.evergage.com:8443/ui/bower_components/ace-builds/src-min-noconflict/ace.js:1:120868)
    at remove (https://localtest.evergage.com:8443/ui/bower_components/ace-builds/src-min-noconflict/ace.js:1:120408)

I am using Angular 1.3.8 and Ace 1.1.7.

Here's what my HTML looks like:

<div ng-model="formData.cssContent"
        ui-ace="{ useWrapMode: true, mode: 'css', onLoad: aceLoaded, onChange: contentChanged }"         
        ng-readonly="!contentEditable">
</div>

Different height for multiple ace editors in one page

I use the recommended way to set the height of the editor by adding this global CSS:

.ace_editor {
    height: 200px;
}

Now what if I have two ace editors, but I want to set different height for them. How can I set height separately for them?

Thanks,
Elgs

Opt tabSize missing

The option tabSize is missing in the directive so when we define it, it's not taken in account by ace.

  if (angular.isDefined(opts.tabSize)) {
    session.setTabSize(opts.tabSize);
  }

OnLoad option does not get evaluated to function

Based on the OnLoad example in the ReadMe, the function name is not $eval-ed to the OnLoad function defined on a ng-controller's scope.

I suspect that this will also occur with onChange as well

Upgrade dependency to latest version of Ace editor?

version 1.1.1 has some significant improvements over 1.0.0

Using Ace 1.1.1 in my ui-ace setup seems to result in the editor initialising but now displaying (what's with that?).

Has anyone looked into where the incompatibility lies? How hard would a fix be?


Update: setting .ace_editor { position: absolute; } seems to fix the no display issue. Are there any other reasons to be hesitant about updating ui-ace's dependency?

Dynamic mode using model variable

Hi there!

It's possible to set editor mode dynamically, using model variable?

I already tried use them as parameter on the onLoad function but it appears not be supported.

Thanks!

Update Ace

Seems like ace has stopped tagging releases in ajaxorg/ace-builds (last one was 8 months ago), despite lots of new updates being released.

Would it be possible to update ui-ace's dependencies to just use the latest from ace-builds?

Add marker _session.addMarker

It is possible to create marker for example.
I have error with Range constructor
TypeError: Illegal constructor
Example :

$scope.aceLoaded = function(_editor){
var _session = _editor.getSession();
_session.addMarker(new Range(1, 0, 10, 0), "ace_active-line", "fullLine");
};

Update version available via Bower

The version available via bower doesn't match the updated one in github. In particular I needed the code from #26 , so I had to track the github commit rather than the normal bower install.

inside of aceLoaded getValue() returns null

when calling aceLoaded getValue() or getLine(0) returns null. So the value is not available in this moment.

$scope.aceLoaded = function(_editor) {
    var _session = _editor.getSession();
    console.log(_session.getValue());

Theme and mode 404 when using minified/bundled js and workerPath

I'm using requirejs, as as such, all JS gets concatenated into a single file. I'm setting workerPath to the correct folder containing Ace, but theme and mode don't seem to get picked up. Even specifying paths for both have no effect.
screenshot 2015-04-23 00 32 28

Any thoughts on how to correctly get theme and mode working with a requirejs / concatenated / uglified / set up?

Relevant config:

    $scope.uiAceConfig =
      theme: 'chrome'
      mode: 'html'
      onLoad: $scope.aceLoaded
      workerPath: '/public/lib/ace-builds/src-min-noconflict'

Thanks!

onLoad and directives

The onLoad option works great if the parent element is a controller, however if it's a directive it's never called:

http://plnkr.co/edit/CvPSaccYVKZfoesJC7o4?

The problem is it just hasn't binded yet. I hacked around it using this:

    setTimeout(function() {
        opts = angular.extend({}, options, scope.$eval(attrs.uiAce));
        if (angular.isFunction(opts.onLoad)) {
            opts.onLoad(acee);
        }
    }, 0);

However this clearly is slightly hacky (not to mention I had to edit ui-ace, which I'd rather not do). A $watch would probably work as well (and be more appropriate here).

(Thanks for this directive, by the way -- it's been an awesome help.)

Contribution guidance

Hi there - my team uses angular-ui-ace and would love to help with some outstanding issues:

  • Existing issues #65, #43, and #29
  • Helping however possible with the release cycle time - from getting a release tagged to having it available via bower
  • Triage/label/review issues/PRs

I know I can just do PRs on the first three, and we've already dealt with things like #43 via bower overrides, but what about the second? I noticed there is a bower branch, tags, a download link to the tag on http://angular-ui.github.io/ui-ace/. Just looking for some contribution guidance here. Let me know where you could use the most help.

ace.js in bower.json

I'm working on learning AngularJS and associated workflow using the Yeoman generator-angular to scaffold the basic seed project. I'm evaluating a couple embeddable editors and installed ui-ace via Bower:

bower install angular-ui-ace -S

This properly installs everything to bower_components and adds ui-ace.js as a dependency in bower.json:

{
  ...
  "angular-ui-ace": "~0.1.1"
}

Which in turn adds the script to index.html on grunt:

<script src="bower_components/angular-ui-ace/ui-ace.js"></script>

The issue is ace.js (which is required) is not added as a dependency on install:

<script type="text/javascript" src="bower_components/ace-builds/src-min-noconflict/ace.js"></script>

Does anyone know the proper syntax to add it as a dependency in bower.json so it is included in my build?

onLoad callback not being called

I am following the Readme, and I can't get the onLoad callback to work. During troubleshoooting, it appears that

    if (angular.isFunction(opts.onLoad)) 

in ui-ace.js is evaluating false. No code placed in this block executes.

My controller is taken straight from the readme.

var myModule = angular.module('joes_ide', ['ui.ace']);

myModule.controller('MyController', [ '$scope', function($scope) {

  $scope.aceLoaded = function(_editor){
    // Editor part
    var _session = _editor.getSession();
    var _renderer = _editor.renderer;

    // Options
    _editor.setReadOnly(true);
    _session.setUndoManager(new ace.UndoManager());
    _renderer.setShowGutter(false);

    // Events
  //  _editor.on("changeSession", function(){ ... });
   // _session.on("change", function(){ ... });
  };

}]);

Likewise, my view-

<div ui-ace="{
  useWrapMode : true,
  showGutter: false,
  theme:'twilight',
  mode: 'xml',
  onLoad: aceLoaded,
  onChange: aceChanged
}"></div>

Changing value on the $scope not updating the editor?

Hi,

I was a bit surprised to find out that when I update the $scope variable, the editor does not update.
Do I need to call some update method? Does that mean I need to save the editor from the onLoad event? Or is there something I can inject into my controller?

I'm wondering why this is not built-in.

Thanks

readonly doesn't appear to work

When we try to use <div ui-ace readonly="true"></div>, the editor doesn't become read-only. I think it may have something to do with the fact that the browser renders readonly="true" as just readonly, and if you only include the readonly attribute itself in the Plunker example, it doesn't work either. The ="true" part is mandatory but you can't get that to show up in the source (at least not in Chrome stable).

cc: @jmartin4563

Support fontSize

I propose to support also this option

    if (angular.isDefined(opts.fontsize)) {
      acee.setFontSize(opts.fontsize);
    }

That we could use as aceOption :

$scope.aceOption = {
mode: 'xml',
theme: $scope.theme.toLowerCase(),
fontsize: '18px',

How do you initialize the editor when directives get compiled after the controller?

I haven't been able to get the example editor initialization to work because it looks like the directive is compiled after the controller is initialized. Here's an example:

In the html:

<div ng-controller="MyController">
  <div ui-ace scope-instance="foo"></div>
</div>

In the controller:

myAppModule.controller('MyController', [ '$scope', function($scope) {

  // this is undefined because
  // the controller is initialized 
  // before the directive is compiled
  var _editor = $scope.foo; 
}]);

memory leaks

Ace will leak when the directive is removed by angular.

I had the editor in a tab-content controlled by ng-switch, the results were bad.

My solution for now is just using my own tab implementation that does not delete and recreate the elements like ng-switch does.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.