This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathindex.js
93 lines (76 loc) · 2.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AceEditorDirective = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _dec, _class;
var _core = require('@angular/core');
var _brace = require('brace');
var _brace2 = _interopRequireDefault(_brace);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var AceEditorDirective = exports.AceEditorDirective = (_dec = (0, _core.Directive)({
selector: '[ace-editor]',
inputs: ['text', 'mode', 'theme', 'readOnly', 'options'],
outputs: ['textChanged', 'editorRef']
}), _dec(_class = function () {
_createClass(AceEditorDirective, [{
key: 'options',
set: function set(value) {
this.editor.setOptions(value || {});
}
}, {
key: 'readOnly',
set: function set(value) {
this._readOnly = value;
this.editor.setReadOnly(value);
}
}, {
key: 'theme',
set: function set(value) {
this._theme = value;
this.editor.setTheme('ace/theme/' + value);
}
}, {
key: 'mode',
set: function set(value) {
this._mode = value;
this.editor.getSession().setMode('ace/mode/' + value);
}
}, {
key: 'text',
set: function set(value) {
if (value === this.oldVal) return;
this.editor.setValue(value);
this.editor.clearSelection();
this.editor.focus();
}
}], [{
key: 'parameters',
get: function get() {
return [[_core.ElementRef]];
}
}]);
function AceEditorDirective(elementRef) {
var _this = this;
_classCallCheck(this, AceEditorDirective);
this.textChanged = new _core.EventEmitter();
this.editorRef = new _core.EventEmitter();
var el = elementRef.nativeElement;
el.classList.add('editor');
this.editor = _brace2.default.edit(el);
setTimeout(function () {
_this.editorRef.next(_this.editor);
});
this.editor.on('change', function () {
var newVal = _this.editor.getValue();
if (newVal === _this.oldVal) return;
if (typeof _this.oldVal !== 'undefined') {
_this.textChanged.next(newVal);
}
_this.oldVal = newVal;
});
}
return AceEditorDirective;
}()) || _class);