Generic DSL Editor directive

This commit is contained in:
BoykoAlex
2016-09-09 13:55:52 -04:00
parent 80f5b0ff6b
commit 21ff8d8972
4 changed files with 182 additions and 4 deletions

93
dist/spring-flo.js vendored
View File

@@ -28749,6 +28749,94 @@ define('directives/graph-editor',['controllers/graph-editor'],function () {
}];
});
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
define('directives/generic-dsl-editor',['angular','underscore','codemirror','codemirror/addon/lint/lint','codemirror/addon/hint/show-hint','codemirror/addon/display/placeholder'],function () {
var angular = require('angular');
var _ = require('underscore');
return ['$injector', function($injector) {
var CodeMirror = require('codemirror');
var doc;
var contentAssistService;
var lintService;
var debounce;
require('codemirror/addon/lint/lint');
require('codemirror/addon/hint/show-hint');
require('codemirror/addon/display/placeholder');
return {
restrict: 'A',
scope: {
dsl: '='
},
link: function (scope, element, attrs) {
if (attrs.contentAssistServiceName) {
contentAssistService = $injector.get(attrs.contentAssistServiceName);
}
if (attrs.lintServiceName) {
lintService = $injector.get(attrs.lintServiceName);
}
if (attrs.debounce) {
debounce = parseInt(attrs.debounce);
}
doc = CodeMirror.fromTextArea(element.context, {
value: scope.dsl,
gutters: ['CodeMirror-lint-markers'],
lint: lintService && angular.isFunction(lintService.getAnnotations) ? {
async: true,
getAnnotations: lintService.getAnnotations
} : undefined,
extraKeys: {'Ctrl-Space': 'autocomplete'},
hintOptions: {
async: 'true',
hint: contentAssistService && angular.isFunction(contentAssistService.complete) ? contentAssistService.complete : undefined
},
lineNumbers: attrs.lineNumbers && attrs.lineNumbers.toLowerCase() === 'true',
lineWrapping: attrs.lineWrapping && attrs.lineWrapping.toLowerCase() === 'true'
});
var dslChangedHandler = function () {
scope.$apply(function() {
scope.dsl = doc.getValue();
});
};
doc.on('change', debounce ? _.debounce(dslChangedHandler, debounce) : dslChangedHandler);
scope.$watch('dsl', function (newValue) {
if (newValue!==doc.getValue()) {
var cursorPosition = doc.getCursor();
doc.setValue(newValue ? newValue : '');
doc.setCursor(cursorPosition);
}
});
}
};
}];
});
/*
* Copyright 2016 the original author or authors.
*
@@ -28770,7 +28858,7 @@ define('directives/graph-editor',['controllers/graph-editor'],function () {
*
* @author Alex Boyko
*/
define('floDirectives',['require','angular','directives/resizer','directives/dsl-editor','directives/code-editor','directives/palette','directives/graph-editor'],function(require) {
define('floDirectives',['require','angular','directives/resizer','directives/dsl-editor','directives/code-editor','directives/palette','directives/graph-editor','directives/generic-dsl-editor'],function(require) {
var angular = require('angular');
@@ -28780,7 +28868,8 @@ define('floDirectives',['require','angular','directives/resizer','directives/dsl
.directive('dslEditor', require('directives/dsl-editor'))
.directive('codeEditor', require('directives/code-editor'))
.directive('floPalette', require('directives/palette'))
.directive('floEditor', require('directives/graph-editor'));
.directive('floEditor', require('directives/graph-editor'))
.directive('genericDslEditor', require('directives/generic-dsl-editor'));
});
/*

File diff suppressed because one or more lines are too long

View File

@@ -29,5 +29,6 @@ define(function(require) {
.directive('dslEditor', require('directives/dsl-editor'))
.directive('codeEditor', require('directives/code-editor'))
.directive('floPalette', require('directives/palette'))
.directive('floEditor', require('directives/graph-editor'));
.directive('floEditor', require('directives/graph-editor'))
.directive('genericDslEditor', require('directives/generic-dsl-editor'));
});

View File

@@ -0,0 +1,88 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
define(function () {
'use strict';
var angular = require('angular');
var _ = require('underscore');
return ['$injector', function($injector) {
var CodeMirror = require('codemirror');
var doc;
var contentAssistService;
var lintService;
var debounce;
require('codemirror/addon/lint/lint');
require('codemirror/addon/hint/show-hint');
require('codemirror/addon/display/placeholder');
return {
restrict: 'A',
scope: {
dsl: '='
},
link: function (scope, element, attrs) {
if (attrs.contentAssistServiceName) {
contentAssistService = $injector.get(attrs.contentAssistServiceName);
}
if (attrs.lintServiceName) {
lintService = $injector.get(attrs.lintServiceName);
}
if (attrs.debounce) {
debounce = parseInt(attrs.debounce);
}
doc = CodeMirror.fromTextArea(element.context, {
value: scope.dsl,
gutters: ['CodeMirror-lint-markers'],
lint: lintService && angular.isFunction(lintService.getAnnotations) ? {
async: true,
getAnnotations: lintService.getAnnotations
} : undefined,
extraKeys: {'Ctrl-Space': 'autocomplete'},
hintOptions: {
async: 'true',
hint: contentAssistService && angular.isFunction(contentAssistService.complete) ? contentAssistService.complete : undefined
},
lineNumbers: attrs.lineNumbers && attrs.lineNumbers.toLowerCase() === 'true',
lineWrapping: attrs.lineWrapping && attrs.lineWrapping.toLowerCase() === 'true'
});
var dslChangedHandler = function () {
scope.$apply(function() {
scope.dsl = doc.getValue();
});
};
doc.on('change', debounce ? _.debounce(dslChangedHandler, debounce) : dslChangedHandler);
scope.$watch('dsl', function (newValue) {
if (newValue!==doc.getValue()) {
var cursorPosition = doc.getCursor();
doc.setValue(newValue ? newValue : '');
doc.setCursor(cursorPosition);
}
});
}
};
}];
});