@ctrl/ngx-codemirror 5.0.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,240 @@
1
+ import * as i0 from '@angular/core';
2
+ import { EventEmitter, forwardRef, Component, ChangeDetectionStrategy, Input, Output, ViewChild, NgModule } from '@angular/core';
3
+ import { NG_VALUE_ACCESSOR } from '@angular/forms';
4
+
5
+ function normalizeLineEndings(str) {
6
+ if (!str) {
7
+ return str;
8
+ }
9
+ return str.replace(/\r\n|\r/g, '\n');
10
+ }
11
+ class CodemirrorComponent {
12
+ constructor(_differs, _ngZone) {
13
+ this._differs = _differs;
14
+ this._ngZone = _ngZone;
15
+ /* class applied to the created textarea */
16
+ this.className = '';
17
+ /* name applied to the created textarea */
18
+ this.name = 'codemirror';
19
+ /* autofocus setting applied to the created textarea */
20
+ this.autoFocus = false;
21
+ /* preserve previous scroll position after updating value */
22
+ this.preserveScrollPosition = false;
23
+ /* called when the text cursor is moved */
24
+ this.cursorActivity = new EventEmitter();
25
+ /* called when the editor is focused or loses focus */
26
+ this.focusChange = new EventEmitter();
27
+ /* called when the editor is scrolled */
28
+ // eslint-disable-next-line @angular-eslint/no-output-native
29
+ this.scroll = new EventEmitter();
30
+ /* called when file(s) are dropped */
31
+ // eslint-disable-next-line @angular-eslint/no-output-native
32
+ this.drop = new EventEmitter();
33
+ this.value = '';
34
+ this.disabled = false;
35
+ this.isFocused = false;
36
+ /** Implemented as part of ControlValueAccessor. */
37
+ this.onChange = (_) => { };
38
+ /** Implemented as part of ControlValueAccessor. */
39
+ this.onTouched = () => { };
40
+ }
41
+ /**
42
+ * set options for codemirror
43
+ * @link http://codemirror.net/doc/manual.html#config
44
+ */
45
+ set options(value) {
46
+ this._options = value;
47
+ if (!this._differ && value) {
48
+ this._differ = this._differs.find(value).create();
49
+ }
50
+ }
51
+ get codeMirrorGlobal() {
52
+ if (this._codeMirror) {
53
+ return this._codeMirror;
54
+ }
55
+ // in order to allow for universal rendering, we import Codemirror runtime with `require` to prevent node errors
56
+ this._codeMirror = typeof CodeMirror !== 'undefined' ? CodeMirror : require('codemirror');
57
+ return this._codeMirror;
58
+ }
59
+ ngAfterViewInit() {
60
+ this._ngZone.runOutsideAngular(() => {
61
+ this.codeMirror = this.codeMirrorGlobal.fromTextArea(this.ref.nativeElement, this._options);
62
+ this.codeMirror.on('cursorActivity', cm => this._ngZone.run(() => this.cursorActive(cm)));
63
+ this.codeMirror.on('scroll', this.scrollChanged.bind(this));
64
+ this.codeMirror.on('blur', () => this._ngZone.run(() => this.focusChanged(false)));
65
+ this.codeMirror.on('focus', () => this._ngZone.run(() => this.focusChanged(true)));
66
+ this.codeMirror.on('change', (cm, change) => this._ngZone.run(() => this.codemirrorValueChanged(cm, change)));
67
+ this.codeMirror.on('drop', (cm, e) => {
68
+ this._ngZone.run(() => this.dropFiles(cm, e));
69
+ });
70
+ this.codeMirror.setValue(this.value);
71
+ });
72
+ }
73
+ ngDoCheck() {
74
+ if (!this._differ) {
75
+ return;
76
+ }
77
+ // check options have not changed
78
+ const changes = this._differ.diff(this._options);
79
+ if (changes) {
80
+ changes.forEachChangedItem(option => this.setOptionIfChanged(option.key, option.currentValue));
81
+ changes.forEachAddedItem(option => this.setOptionIfChanged(option.key, option.currentValue));
82
+ changes.forEachRemovedItem(option => this.setOptionIfChanged(option.key, option.currentValue));
83
+ }
84
+ }
85
+ ngOnDestroy() {
86
+ // is there a lighter-weight way to remove the cm instance?
87
+ if (this.codeMirror) {
88
+ this.codeMirror.toTextArea();
89
+ }
90
+ }
91
+ codemirrorValueChanged(cm, change) {
92
+ const cmVal = cm.getValue();
93
+ if (this.value !== cmVal) {
94
+ this.value = cmVal;
95
+ this.onChange(this.value);
96
+ }
97
+ }
98
+ setOptionIfChanged(optionName, newValue) {
99
+ if (!this.codeMirror) {
100
+ return;
101
+ }
102
+ // cast to any to handle strictly typed option names
103
+ // could possibly import settings strings available in the future
104
+ this.codeMirror.setOption(optionName, newValue);
105
+ }
106
+ focusChanged(focused) {
107
+ this.onTouched();
108
+ this.isFocused = focused;
109
+ this.focusChange.emit(focused);
110
+ }
111
+ scrollChanged(cm) {
112
+ this.scroll.emit(cm.getScrollInfo());
113
+ }
114
+ cursorActive(cm) {
115
+ this.cursorActivity.emit(cm);
116
+ }
117
+ dropFiles(cm, e) {
118
+ this.drop.emit([cm, e]);
119
+ }
120
+ /** Implemented as part of ControlValueAccessor. */
121
+ writeValue(value) {
122
+ if (value === null || value === undefined) {
123
+ return;
124
+ }
125
+ if (!this.codeMirror) {
126
+ this.value = value;
127
+ return;
128
+ }
129
+ const cur = this.codeMirror.getValue();
130
+ if (value !== cur && normalizeLineEndings(cur) !== normalizeLineEndings(value)) {
131
+ this.value = value;
132
+ if (this.preserveScrollPosition) {
133
+ const prevScrollPosition = this.codeMirror.getScrollInfo();
134
+ this.codeMirror.setValue(this.value);
135
+ this.codeMirror.scrollTo(prevScrollPosition.left, prevScrollPosition.top);
136
+ }
137
+ else {
138
+ this.codeMirror.setValue(this.value);
139
+ }
140
+ }
141
+ }
142
+ /** Implemented as part of ControlValueAccessor. */
143
+ registerOnChange(fn) {
144
+ this.onChange = fn;
145
+ }
146
+ /** Implemented as part of ControlValueAccessor. */
147
+ registerOnTouched(fn) {
148
+ this.onTouched = fn;
149
+ }
150
+ /** Implemented as part of ControlValueAccessor. */
151
+ setDisabledState(isDisabled) {
152
+ this.disabled = isDisabled;
153
+ this.setOptionIfChanged('readOnly', this.disabled);
154
+ }
155
+ }
156
+ CodemirrorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: CodemirrorComponent, deps: [{ token: i0.KeyValueDiffers }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
157
+ CodemirrorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.1", type: CodemirrorComponent, selector: "ngx-codemirror", inputs: { className: "className", name: "name", autoFocus: "autoFocus", options: "options", preserveScrollPosition: "preserveScrollPosition" }, outputs: { cursorActivity: "cursorActivity", focusChange: "focusChange", scroll: "scroll", drop: "drop" }, providers: [
158
+ {
159
+ provide: NG_VALUE_ACCESSOR,
160
+ useExisting: forwardRef(() => CodemirrorComponent),
161
+ multi: true,
162
+ },
163
+ ], viewQueries: [{ propertyName: "ref", first: true, predicate: ["ref"], descendants: true }], ngImport: i0, template: `
164
+ <textarea
165
+ [name]="name"
166
+ class="ngx-codemirror {{ className }}"
167
+ [class.ngx-codemirror--focused]="isFocused"
168
+ autocomplete="off"
169
+ [autofocus]="autoFocus"
170
+ #ref
171
+ >
172
+ </textarea>
173
+ `, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
174
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: CodemirrorComponent, decorators: [{
175
+ type: Component,
176
+ args: [{
177
+ selector: 'ngx-codemirror',
178
+ template: `
179
+ <textarea
180
+ [name]="name"
181
+ class="ngx-codemirror {{ className }}"
182
+ [class.ngx-codemirror--focused]="isFocused"
183
+ autocomplete="off"
184
+ [autofocus]="autoFocus"
185
+ #ref
186
+ >
187
+ </textarea>
188
+ `,
189
+ providers: [
190
+ {
191
+ provide: NG_VALUE_ACCESSOR,
192
+ useExisting: forwardRef(() => CodemirrorComponent),
193
+ multi: true,
194
+ },
195
+ ],
196
+ preserveWhitespaces: false,
197
+ changeDetection: ChangeDetectionStrategy.OnPush,
198
+ }]
199
+ }], ctorParameters: function () { return [{ type: i0.KeyValueDiffers }, { type: i0.NgZone }]; }, propDecorators: { className: [{
200
+ type: Input
201
+ }], name: [{
202
+ type: Input
203
+ }], autoFocus: [{
204
+ type: Input
205
+ }], options: [{
206
+ type: Input
207
+ }], preserveScrollPosition: [{
208
+ type: Input
209
+ }], cursorActivity: [{
210
+ type: Output
211
+ }], focusChange: [{
212
+ type: Output
213
+ }], scroll: [{
214
+ type: Output
215
+ }], drop: [{
216
+ type: Output
217
+ }], ref: [{
218
+ type: ViewChild,
219
+ args: ['ref']
220
+ }] } });
221
+
222
+ class CodemirrorModule {
223
+ }
224
+ CodemirrorModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: CodemirrorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
225
+ CodemirrorModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: CodemirrorModule, declarations: [CodemirrorComponent], exports: [CodemirrorComponent] });
226
+ CodemirrorModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: CodemirrorModule });
227
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: CodemirrorModule, decorators: [{
228
+ type: NgModule,
229
+ args: [{
230
+ exports: [CodemirrorComponent],
231
+ declarations: [CodemirrorComponent],
232
+ }]
233
+ }] });
234
+
235
+ /**
236
+ * Generated bundle index. Do not edit.
237
+ */
238
+
239
+ export { CodemirrorComponent, CodemirrorModule };
240
+ //# sourceMappingURL=ctrl-ngx-codemirror.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctrl-ngx-codemirror.mjs","sources":["../../src/lib/codemirror.component.ts","../../src/lib/codemirror.module.ts","../../src/lib/ctrl-ngx-codemirror.ts"],"sourcesContent":["import {\n AfterViewInit,\n ChangeDetectionStrategy,\n Component,\n DoCheck,\n ElementRef,\n EventEmitter,\n forwardRef,\n Input,\n KeyValueDiffer,\n KeyValueDiffers,\n NgZone,\n OnDestroy,\n Output,\n ViewChild,\n} from '@angular/core';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { Editor, EditorChange, EditorFromTextArea, ScrollInfo } from 'codemirror';\n\nfunction normalizeLineEndings(str: string): string {\n if (!str) {\n return str;\n }\n return str.replace(/\\r\\n|\\r/g, '\\n');\n}\n\ndeclare var require: any;\ndeclare var CodeMirror: any;\n\n@Component({\n selector: 'ngx-codemirror',\n template: `\n <textarea\n [name]=\"name\"\n class=\"ngx-codemirror {{ className }}\"\n [class.ngx-codemirror--focused]=\"isFocused\"\n autocomplete=\"off\"\n [autofocus]=\"autoFocus\"\n #ref\n >\n </textarea>\n `,\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => CodemirrorComponent),\n multi: true,\n },\n ],\n preserveWhitespaces: false,\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class CodemirrorComponent\n implements AfterViewInit, OnDestroy, ControlValueAccessor, DoCheck\n{\n /* class applied to the created textarea */\n @Input() className = '';\n /* name applied to the created textarea */\n @Input() name = 'codemirror';\n /* autofocus setting applied to the created textarea */\n @Input() autoFocus = false;\n /**\n * set options for codemirror\n * @link http://codemirror.net/doc/manual.html#config\n */\n @Input()\n set options(value: { [key: string]: any }) {\n this._options = value;\n if (!this._differ && value) {\n this._differ = this._differs.find(value).create();\n }\n }\n /* preserve previous scroll position after updating value */\n @Input() preserveScrollPosition = false;\n /* called when the text cursor is moved */\n @Output() cursorActivity = new EventEmitter<Editor>();\n /* called when the editor is focused or loses focus */\n @Output() focusChange = new EventEmitter<boolean>();\n /* called when the editor is scrolled */\n // eslint-disable-next-line @angular-eslint/no-output-native\n @Output() scroll = new EventEmitter<ScrollInfo>();\n /* called when file(s) are dropped */\n // eslint-disable-next-line @angular-eslint/no-output-native\n @Output() drop = new EventEmitter<[Editor, DragEvent]>();\n @ViewChild('ref') ref!: ElementRef<HTMLTextAreaElement>;\n value = '';\n disabled = false;\n isFocused = false;\n codeMirror?: EditorFromTextArea;\n /**\n * either global variable or required library\n */\n private _codeMirror: any;\n\n private _differ?: KeyValueDiffer<string, any>;\n private _options: any;\n\n constructor(private _differs: KeyValueDiffers, private _ngZone: NgZone) {}\n\n get codeMirrorGlobal(): any {\n if (this._codeMirror) {\n return this._codeMirror;\n }\n\n // in order to allow for universal rendering, we import Codemirror runtime with `require` to prevent node errors\n this._codeMirror = typeof CodeMirror !== 'undefined' ? CodeMirror : require('codemirror');\n return this._codeMirror;\n }\n\n ngAfterViewInit() {\n this._ngZone.runOutsideAngular(() => {\n this.codeMirror = this.codeMirrorGlobal.fromTextArea(\n this.ref.nativeElement,\n this._options,\n ) as EditorFromTextArea;\n this.codeMirror.on('cursorActivity', cm => this._ngZone.run(() => this.cursorActive(cm)));\n this.codeMirror.on('scroll', this.scrollChanged.bind(this));\n this.codeMirror.on('blur', () => this._ngZone.run(() => this.focusChanged(false)));\n this.codeMirror.on('focus', () => this._ngZone.run(() => this.focusChanged(true)));\n this.codeMirror.on('change', (cm, change) =>\n this._ngZone.run(() => this.codemirrorValueChanged(cm, change)),\n );\n this.codeMirror.on('drop', (cm, e) => {\n this._ngZone.run(() => this.dropFiles(cm, e));\n });\n this.codeMirror.setValue(this.value);\n });\n }\n ngDoCheck() {\n if (!this._differ) {\n return;\n }\n // check options have not changed\n const changes = this._differ.diff(this._options);\n if (changes) {\n changes.forEachChangedItem(option =>\n this.setOptionIfChanged(option.key, option.currentValue),\n );\n changes.forEachAddedItem(option => this.setOptionIfChanged(option.key, option.currentValue));\n changes.forEachRemovedItem(option =>\n this.setOptionIfChanged(option.key, option.currentValue),\n );\n }\n }\n ngOnDestroy() {\n // is there a lighter-weight way to remove the cm instance?\n if (this.codeMirror) {\n this.codeMirror.toTextArea();\n }\n }\n codemirrorValueChanged(cm: Editor, change: EditorChange) {\n const cmVal = cm.getValue();\n if (this.value !== cmVal) {\n this.value = cmVal;\n this.onChange(this.value);\n }\n }\n setOptionIfChanged(optionName: string, newValue: any) {\n if (!this.codeMirror) {\n return;\n }\n\n // cast to any to handle strictly typed option names\n // could possibly import settings strings available in the future\n this.codeMirror.setOption(optionName as any, newValue);\n }\n focusChanged(focused: boolean) {\n this.onTouched();\n this.isFocused = focused;\n this.focusChange.emit(focused);\n }\n scrollChanged(cm: Editor) {\n this.scroll.emit(cm.getScrollInfo());\n }\n cursorActive(cm: Editor) {\n this.cursorActivity.emit(cm);\n }\n dropFiles(cm: Editor, e: DragEvent) {\n this.drop.emit([cm, e]);\n }\n /** Implemented as part of ControlValueAccessor. */\n writeValue(value: string) {\n if (value === null || value === undefined) {\n return;\n }\n if (!this.codeMirror) {\n this.value = value;\n return;\n }\n const cur = this.codeMirror.getValue();\n if (value !== cur && normalizeLineEndings(cur) !== normalizeLineEndings(value)) {\n this.value = value;\n if (this.preserveScrollPosition) {\n const prevScrollPosition = this.codeMirror.getScrollInfo();\n this.codeMirror.setValue(this.value);\n this.codeMirror.scrollTo(prevScrollPosition.left, prevScrollPosition.top);\n } else {\n this.codeMirror.setValue(this.value);\n }\n }\n }\n\n /** Implemented as part of ControlValueAccessor. */\n registerOnChange(fn: (value: string) => void) {\n this.onChange = fn;\n }\n /** Implemented as part of ControlValueAccessor. */\n registerOnTouched(fn: () => void) {\n this.onTouched = fn;\n }\n /** Implemented as part of ControlValueAccessor. */\n setDisabledState(isDisabled: boolean) {\n this.disabled = isDisabled;\n this.setOptionIfChanged('readOnly', this.disabled);\n }\n /** Implemented as part of ControlValueAccessor. */\n private onChange = (_: any) => {};\n /** Implemented as part of ControlValueAccessor. */\n private onTouched = () => {};\n}\n","import { NgModule } from '@angular/core';\n\nimport { CodemirrorComponent } from './codemirror.component';\n\n@NgModule({\n exports: [CodemirrorComponent],\n declarations: [CodemirrorComponent],\n})\nexport class CodemirrorModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;AAmBA,SAAS,oBAAoB,CAAC,GAAW;IACvC,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,GAAG,CAAC;KACZ;IACD,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACvC,CAAC;MA4BY,mBAAmB;IA6C9B,YAAoB,QAAyB,EAAU,OAAe;QAAlD,aAAQ,GAAR,QAAQ,CAAiB;QAAU,YA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"@ctrl/ngx-codemirror",
4
- "version": "5.0.1",
4
+ "version": "5.1.0",
5
5
  "license": "MIT",
6
6
  "description": "CodeMirror wrapper for Angular",
7
7
  "dependencies": {
8
- "@types/codemirror": "^5.60.2",
9
- "tslib": "^2.2.0"
8
+ "@types/codemirror": "^5.60.5",
9
+ "tslib": "^2.3.0"
10
10
  },
11
11
  "peerDependencies": {
12
12
  "@angular/core": ">=12.0.0-0",
13
13
  "@angular/forms": ">=12.0.0-0",
14
- "codemirror": ">=5.61.0"
14
+ "codemirror": ">=5.63.3"
15
15
  },
16
16
  "repository": "scttcper/ngx-codemirror",
17
17
  "homepage": "https://github.com/scttcper/ngx-codemirror",
@@ -19,15 +19,26 @@
19
19
  "keywords": [
20
20
  "ngx",
21
21
  "angular",
22
- "wrapper",
23
22
  "codemirror"
24
23
  ],
25
- "main": "bundles/ctrl-ngx-codemirror.umd.js",
26
- "module": "fesm2015/ctrl-ngx-codemirror.js",
27
- "es2015": "fesm2015/ctrl-ngx-codemirror.js",
28
- "esm2015": "esm2015/ctrl-ngx-codemirror.js",
29
- "fesm2015": "fesm2015/ctrl-ngx-codemirror.js",
24
+ "module": "fesm2015/ctrl-ngx-codemirror.mjs",
25
+ "es2020": "fesm2020/ctrl-ngx-codemirror.mjs",
26
+ "esm2020": "esm2020/ctrl-ngx-codemirror.mjs",
27
+ "fesm2020": "fesm2020/ctrl-ngx-codemirror.mjs",
28
+ "fesm2015": "fesm2015/ctrl-ngx-codemirror.mjs",
30
29
  "typings": "ctrl-ngx-codemirror.d.ts",
31
- "metadata": "ctrl-ngx-codemirror.metadata.json",
30
+ "exports": {
31
+ "./package.json": {
32
+ "default": "./package.json"
33
+ },
34
+ ".": {
35
+ "types": "./ctrl-ngx-codemirror.d.ts",
36
+ "esm2020": "./esm2020/ctrl-ngx-codemirror.mjs",
37
+ "es2020": "./fesm2020/ctrl-ngx-codemirror.mjs",
38
+ "es2015": "./fesm2015/ctrl-ngx-codemirror.mjs",
39
+ "node": "./fesm2015/ctrl-ngx-codemirror.mjs",
40
+ "default": "./fesm2020/ctrl-ngx-codemirror.mjs"
41
+ }
42
+ },
32
43
  "sideEffects": false
33
44
  }
@@ -1,223 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms')) :
3
- typeof define === 'function' && define.amd ? define('@ctrl/ngx-codemirror', ['exports', '@angular/core', '@angular/forms'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ctrl = global.ctrl || {}, global.ctrl['ngx-codemirror'] = {}), global.ng.core, global.ng.forms));
5
- }(this, (function (exports, core, forms) { 'use strict';
6
-
7
- function normalizeLineEndings(str) {
8
- if (!str) {
9
- return str;
10
- }
11
- return str.replace(/\r\n|\r/g, '\n');
12
- }
13
- var CodemirrorComponent = /** @class */ (function () {
14
- function CodemirrorComponent(_differs, _ngZone) {
15
- this._differs = _differs;
16
- this._ngZone = _ngZone;
17
- /* class applied to the created textarea */
18
- this.className = '';
19
- /* name applied to the created textarea */
20
- this.name = 'codemirror';
21
- /* autofocus setting applied to the created textarea */
22
- this.autoFocus = false;
23
- /* preserve previous scroll position after updating value */
24
- this.preserveScrollPosition = false;
25
- /* called when the text cursor is moved */
26
- this.cursorActivity = new core.EventEmitter();
27
- /* called when the editor is focused or loses focus */
28
- this.focusChange = new core.EventEmitter();
29
- /* called when the editor is scrolled */
30
- // eslint-disable-next-line @angular-eslint/no-output-native
31
- this.scroll = new core.EventEmitter();
32
- /* called when file(s) are dropped */
33
- // eslint-disable-next-line @angular-eslint/no-output-native
34
- this.drop = new core.EventEmitter();
35
- this.value = '';
36
- this.disabled = false;
37
- this.isFocused = false;
38
- /** Implemented as part of ControlValueAccessor. */
39
- this.onChange = function (_) { };
40
- /** Implemented as part of ControlValueAccessor. */
41
- this.onTouched = function () { };
42
- }
43
- Object.defineProperty(CodemirrorComponent.prototype, "options", {
44
- /**
45
- * set options for codemirror
46
- * @link http://codemirror.net/doc/manual.html#config
47
- */
48
- set: function (value) {
49
- this._options = value;
50
- if (!this._differ && value) {
51
- this._differ = this._differs.find(value).create();
52
- }
53
- },
54
- enumerable: false,
55
- configurable: true
56
- });
57
- Object.defineProperty(CodemirrorComponent.prototype, "codeMirrorGlobal", {
58
- get: function () {
59
- if (this._codeMirror) {
60
- return this._codeMirror;
61
- }
62
- // in order to allow for universal rendering, we import Codemirror runtime with `require` to prevent node errors
63
- this._codeMirror = typeof CodeMirror !== 'undefined' ? CodeMirror : require('codemirror');
64
- return this._codeMirror;
65
- },
66
- enumerable: false,
67
- configurable: true
68
- });
69
- CodemirrorComponent.prototype.ngAfterViewInit = function () {
70
- var _this = this;
71
- this._ngZone.runOutsideAngular(function () {
72
- _this.codeMirror = _this.codeMirrorGlobal.fromTextArea(_this.ref.nativeElement, _this._options);
73
- _this.codeMirror.on('cursorActivity', function (cm) { return _this._ngZone.run(function () { return _this.cursorActive(cm); }); });
74
- _this.codeMirror.on('scroll', _this.scrollChanged.bind(_this));
75
- _this.codeMirror.on('blur', function () { return _this._ngZone.run(function () { return _this.focusChanged(false); }); });
76
- _this.codeMirror.on('focus', function () { return _this._ngZone.run(function () { return _this.focusChanged(true); }); });
77
- _this.codeMirror.on('change', function (cm, change) { return _this._ngZone.run(function () { return _this.codemirrorValueChanged(cm, change); }); });
78
- _this.codeMirror.on('drop', function (cm, e) {
79
- _this._ngZone.run(function () { return _this.dropFiles(cm, e); });
80
- });
81
- _this.codeMirror.setValue(_this.value);
82
- });
83
- };
84
- CodemirrorComponent.prototype.ngDoCheck = function () {
85
- var _this = this;
86
- if (!this._differ) {
87
- return;
88
- }
89
- // check options have not changed
90
- var changes = this._differ.diff(this._options);
91
- if (changes) {
92
- changes.forEachChangedItem(function (option) { return _this.setOptionIfChanged(option.key, option.currentValue); });
93
- changes.forEachAddedItem(function (option) { return _this.setOptionIfChanged(option.key, option.currentValue); });
94
- changes.forEachRemovedItem(function (option) { return _this.setOptionIfChanged(option.key, option.currentValue); });
95
- }
96
- };
97
- CodemirrorComponent.prototype.ngOnDestroy = function () {
98
- // is there a lighter-weight way to remove the cm instance?
99
- if (this.codeMirror) {
100
- this.codeMirror.toTextArea();
101
- }
102
- };
103
- CodemirrorComponent.prototype.codemirrorValueChanged = function (cm, change) {
104
- var cmVal = cm.getValue();
105
- if (this.value !== cmVal) {
106
- this.value = cmVal;
107
- this.onChange(this.value);
108
- }
109
- };
110
- CodemirrorComponent.prototype.setOptionIfChanged = function (optionName, newValue) {
111
- if (!this.codeMirror) {
112
- return;
113
- }
114
- // cast to any to handle strictly typed option names
115
- // could possibly import settings strings available in the future
116
- this.codeMirror.setOption(optionName, newValue);
117
- };
118
- CodemirrorComponent.prototype.focusChanged = function (focused) {
119
- this.onTouched();
120
- this.isFocused = focused;
121
- this.focusChange.emit(focused);
122
- };
123
- CodemirrorComponent.prototype.scrollChanged = function (cm) {
124
- this.scroll.emit(cm.getScrollInfo());
125
- };
126
- CodemirrorComponent.prototype.cursorActive = function (cm) {
127
- this.cursorActivity.emit(cm);
128
- };
129
- CodemirrorComponent.prototype.dropFiles = function (cm, e) {
130
- this.drop.emit([cm, e]);
131
- };
132
- /** Implemented as part of ControlValueAccessor. */
133
- CodemirrorComponent.prototype.writeValue = function (value) {
134
- if (value === null || value === undefined) {
135
- return;
136
- }
137
- if (!this.codeMirror) {
138
- this.value = value;
139
- return;
140
- }
141
- var cur = this.codeMirror.getValue();
142
- if (value !== cur && normalizeLineEndings(cur) !== normalizeLineEndings(value)) {
143
- this.value = value;
144
- if (this.preserveScrollPosition) {
145
- var prevScrollPosition = this.codeMirror.getScrollInfo();
146
- this.codeMirror.setValue(this.value);
147
- this.codeMirror.scrollTo(prevScrollPosition.left, prevScrollPosition.top);
148
- }
149
- else {
150
- this.codeMirror.setValue(this.value);
151
- }
152
- }
153
- };
154
- /** Implemented as part of ControlValueAccessor. */
155
- CodemirrorComponent.prototype.registerOnChange = function (fn) {
156
- this.onChange = fn;
157
- };
158
- /** Implemented as part of ControlValueAccessor. */
159
- CodemirrorComponent.prototype.registerOnTouched = function (fn) {
160
- this.onTouched = fn;
161
- };
162
- /** Implemented as part of ControlValueAccessor. */
163
- CodemirrorComponent.prototype.setDisabledState = function (isDisabled) {
164
- this.disabled = isDisabled;
165
- this.setOptionIfChanged('readOnly', this.disabled);
166
- };
167
- return CodemirrorComponent;
168
- }());
169
- CodemirrorComponent.decorators = [
170
- { type: core.Component, args: [{
171
- selector: 'ngx-codemirror',
172
- template: "\n <textarea\n [name]=\"name\"\n class=\"ngx-codemirror {{ className }}\"\n [class.ngx-codemirror--focused]=\"isFocused\"\n autocomplete=\"off\"\n [autofocus]=\"autoFocus\"\n #ref\n >\n </textarea>\n ",
173
- providers: [
174
- {
175
- provide: forms.NG_VALUE_ACCESSOR,
176
- useExisting: core.forwardRef(function () { return CodemirrorComponent; }),
177
- multi: true,
178
- },
179
- ],
180
- preserveWhitespaces: false,
181
- changeDetection: core.ChangeDetectionStrategy.OnPush
182
- },] }
183
- ];
184
- CodemirrorComponent.ctorParameters = function () { return [
185
- { type: core.KeyValueDiffers },
186
- { type: core.NgZone }
187
- ]; };
188
- CodemirrorComponent.propDecorators = {
189
- className: [{ type: core.Input }],
190
- name: [{ type: core.Input }],
191
- autoFocus: [{ type: core.Input }],
192
- options: [{ type: core.Input }],
193
- preserveScrollPosition: [{ type: core.Input }],
194
- cursorActivity: [{ type: core.Output }],
195
- focusChange: [{ type: core.Output }],
196
- scroll: [{ type: core.Output }],
197
- drop: [{ type: core.Output }],
198
- ref: [{ type: core.ViewChild, args: ['ref',] }]
199
- };
200
-
201
- var CodemirrorModule = /** @class */ (function () {
202
- function CodemirrorModule() {
203
- }
204
- return CodemirrorModule;
205
- }());
206
- CodemirrorModule.decorators = [
207
- { type: core.NgModule, args: [{
208
- exports: [CodemirrorComponent],
209
- declarations: [CodemirrorComponent],
210
- },] }
211
- ];
212
-
213
- /**
214
- * Generated bundle index. Do not edit.
215
- */
216
-
217
- exports.CodemirrorComponent = CodemirrorComponent;
218
- exports.CodemirrorModule = CodemirrorModule;
219
-
220
- Object.defineProperty(exports, '__esModule', { value: true });
221
-
222
- })));
223
- //# sourceMappingURL=ctrl-ngx-codemirror.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ctrl-ngx-codemirror.umd.js","sources":["../../src/lib/codemirror.component.ts","../../src/lib/codemirror.module.ts","../../src/lib/ctrl-ngx-codemirror.ts"],"sourcesContent":["import {\n AfterViewInit,\n ChangeDetectionStrategy,\n Component,\n DoCheck,\n ElementRef,\n EventEmitter,\n forwardRef,\n Input,\n KeyValueDiffer,\n KeyValueDiffers,\n NgZone,\n OnDestroy,\n Output,\n ViewChild,\n} from '@angular/core';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\nimport { Editor, EditorChange, EditorFromTextArea, ScrollInfo } from 'codemirror';\n\nfunction normalizeLineEndings(str: string): string {\n if (!str) {\n return str;\n }\n return str.replace(/\\r\\n|\\r/g, '\\n');\n}\n\ndeclare var require: any;\ndeclare var CodeMirror: any;\n\n@Component({\n selector: 'ngx-codemirror',\n template: `\n <textarea\n [name]=\"name\"\n class=\"ngx-codemirror {{ className }}\"\n [class.ngx-codemirror--focused]=\"isFocused\"\n autocomplete=\"off\"\n [autofocus]=\"autoFocus\"\n #ref\n >\n </textarea>\n `,\n providers: [\n {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => CodemirrorComponent),\n multi: true,\n },\n ],\n preserveWhitespaces: false,\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class CodemirrorComponent\n implements AfterViewInit, OnDestroy, ControlValueAccessor, DoCheck\n{\n /* class applied to the created textarea */\n @Input() className = '';\n /* name applied to the created textarea */\n @Input() name = 'codemirror';\n /* autofocus setting applied to the created textarea */\n @Input() autoFocus = false;\n /**\n * set options for codemirror\n * @link http://codemirror.net/doc/manual.html#config\n */\n @Input()\n set options(value: { [key: string]: any }) {\n this._options = value;\n if (!this._differ && value) {\n this._differ = this._differs.find(value).create();\n }\n }\n /* preserve previous scroll position after updating value */\n @Input() preserveScrollPosition = false;\n /* called when the text cursor is moved */\n @Output() cursorActivity = new EventEmitter<Editor>();\n /* called when the editor is focused or loses focus */\n @Output() focusChange = new EventEmitter<boolean>();\n /* called when the editor is scrolled */\n // eslint-disable-next-line @angular-eslint/no-output-native\n @Output() scroll = new EventEmitter<ScrollInfo>();\n /* called when file(s) are dropped */\n // eslint-disable-next-line @angular-eslint/no-output-native\n @Output() drop = new EventEmitter<[Editor, DragEvent]>();\n @ViewChild('ref') ref!: ElementRef<HTMLTextAreaElement>;\n value = '';\n disabled = false;\n isFocused = false;\n codeMirror?: EditorFromTextArea;\n /**\n * either global variable or required library\n */\n private _codeMirror: any;\n\n private _differ?: KeyValueDiffer<string, any>;\n private _options: any;\n\n constructor(private _differs: KeyValueDiffers, private _ngZone: NgZone) {}\n\n get codeMirrorGlobal(): any {\n if (this._codeMirror) {\n return this._codeMirror;\n }\n\n // in order to allow for universal rendering, we import Codemirror runtime with `require` to prevent node errors\n this._codeMirror = typeof CodeMirror !== 'undefined' ? CodeMirror : require('codemirror');\n return this._codeMirror;\n }\n\n ngAfterViewInit() {\n this._ngZone.runOutsideAngular(() => {\n this.codeMirror = this.codeMirrorGlobal.fromTextArea(\n this.ref.nativeElement,\n this._options,\n ) as EditorFromTextArea;\n this.codeMirror.on('cursorActivity', cm => this._ngZone.run(() => this.cursorActive(cm)));\n this.codeMirror.on('scroll', this.scrollChanged.bind(this));\n this.codeMirror.on('blur', () => this._ngZone.run(() => this.focusChanged(false)));\n this.codeMirror.on('focus', () => this._ngZone.run(() => this.focusChanged(true)));\n this.codeMirror.on('change', (cm, change) =>\n this._ngZone.run(() => this.codemirrorValueChanged(cm, change)),\n );\n this.codeMirror.on('drop', (cm, e) => {\n this._ngZone.run(() => this.dropFiles(cm, e));\n });\n this.codeMirror.setValue(this.value);\n });\n }\n ngDoCheck() {\n if (!this._differ) {\n return;\n }\n // check options have not changed\n const changes = this._differ.diff(this._options);\n if (changes) {\n changes.forEachChangedItem(option =>\n this.setOptionIfChanged(option.key, option.currentValue),\n );\n changes.forEachAddedItem(option => this.setOptionIfChanged(option.key, option.currentValue));\n changes.forEachRemovedItem(option =>\n this.setOptionIfChanged(option.key, option.currentValue),\n );\n }\n }\n ngOnDestroy() {\n // is there a lighter-weight way to remove the cm instance?\n if (this.codeMirror) {\n this.codeMirror.toTextArea();\n }\n }\n codemirrorValueChanged(cm: Editor, change: EditorChange) {\n const cmVal = cm.getValue();\n if (this.value !== cmVal) {\n this.value = cmVal;\n this.onChange(this.value);\n }\n }\n setOptionIfChanged(optionName: string, newValue: any) {\n if (!this.codeMirror) {\n return;\n }\n\n // cast to any to handle strictly typed option names\n // could possibly import settings strings available in the future\n this.codeMirror.setOption(optionName as any, newValue);\n }\n focusChanged(focused: boolean) {\n this.onTouched();\n this.isFocused = focused;\n this.focusChange.emit(focused);\n }\n scrollChanged(cm: Editor) {\n this.scroll.emit(cm.getScrollInfo());\n }\n cursorActive(cm: Editor) {\n this.cursorActivity.emit(cm);\n }\n dropFiles(cm: Editor, e: DragEvent) {\n this.drop.emit([cm, e]);\n }\n /** Implemented as part of ControlValueAccessor. */\n writeValue(value: string) {\n if (value === null || value === undefined) {\n return;\n }\n if (!this.codeMirror) {\n this.value = value;\n return;\n }\n const cur = this.codeMirror.getValue();\n if (value !== cur && normalizeLineEndings(cur) !== normalizeLineEndings(value)) {\n this.value = value;\n if (this.preserveScrollPosition) {\n const prevScrollPosition = this.codeMirror.getScrollInfo();\n this.codeMirror.setValue(this.value);\n this.codeMirror.scrollTo(prevScrollPosition.left, prevScrollPosition.top);\n } else {\n this.codeMirror.setValue(this.value);\n }\n }\n }\n\n /** Implemented as part of ControlValueAccessor. */\n registerOnChange(fn: (value: string) => void) {\n this.onChange = fn;\n }\n /** Implemented as part of ControlValueAccessor. */\n registerOnTouched(fn: () => void) {\n this.onTouched = fn;\n }\n /** Implemented as part of ControlValueAccessor. */\n setDisabledState(isDisabled: boolean) {\n this.disabled = isDisabled;\n this.setOptionIfChanged('readOnly', this.disabled);\n }\n /** Implemented as part of ControlValueAccessor. */\n private onChange = (_: any) => {};\n /** Implemented as part of ControlValueAccessor. */\n private onTouched = () => {};\n}\n","import { NgModule } from '@angular/core';\n\nimport { CodemirrorComponent } from './codemirror.component';\n\n@NgModule({\n exports: [CodemirrorComponent],\n declarations: [CodemirrorComponent],\n})\nexport class CodemirrorModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":["EventEmitter","Component","NG_VALUE_ACCESSOR","forwardRef","ChangeDetectionStrategy","KeyValueDiffers","NgZone","Input","Output","ViewChild","NgModule"],"mappings":";;;;;;EAmBA,SAAS,oBAAoB,CAAC,GAAW;MACvC,IAAI,CAAC,GAAG,EAAE;UACR,OAAO,GAAG,CAAC;OACZ;MACD,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;EACvC,CAAC;;MAyEC,6BAAoB,QAAyB,EAAU,OAAe;UAAlD,aAAQ,GAAR,QAAQ,CAAiB;UAAU,YAAO,GAAP,OAAO,CAAQ;;UAzC7D,cAAS,GAAG,EAAE,CAAC;;UAEf,SAAI,GAAG,YAAY,CAAC;;UAEpB,cAAS,GAAG,KAAK,CAAC;;UAalB,2BAAsB,GAAG,KAAK,CAAC;;UAE9B,mBAAc,GAAG,IAAIA,iBAAY,EAAU,CAAC;;UAE5C,gBAAW,GAAG,IAAIA,iBAAY,EAAW,CAAC;;;UAG1C,WAAM,GAAG,IAAIA,iBAAY,EAAc,CAAC;;;UAGxC,SAAI,GAAG,IAAIA,iBAAY,EAAuB,CAAC;UAEzD,UAAK,GAAG,EAAE,CAAC;UACX,aAAQ,GAAG,KAAK,CAAC;UACjB,cAAS,GAAG,KAAK,CAAC;;UAiIV,aAAQ,GAAG,UAAC,CAAM,KAAO,CAAC;;UAE1B,cAAS,GAAG,eAAQ,CAAC;OAzH6C;MAhC1E,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kBACD,SAAS,EAAE;sBACT;0BACE,OAAO,EAAEC,uBAAiB;0BAC1B,WAAW,EAAEC,eAAU,CAAC,cAAM,OAAA,mBAAmB,GAAA,CAAC;0BAClD,KAAK,EAAE,IAAI;uBACZ;mBACF;kBACD,mBAAmB,EAAE,KAAK;kBAC1B,eAAe,EAAEC,4BAAuB,CAAC,MAAM;eAChD;;;cAzCCC,oBAAe;cACfC,WAAM;;;0BA6CLC,UAAK;qBAELA,UAAK;0BAELA,UAAK;wBAKLA,UAAK;uCAQLA,UAAK;+BAELC,WAAM;4BAENA,WAAM;uBAGNA,WAAM;qBAGNA,WAAM;oBACNC,cAAS,SAAC,KAAK;;;;MC5ElB;;;;;cAJCC,aAAQ,SAAC;kBACR,OAAO,EAAE,CAAC,mBAAmB,CAAC;kBAC9B,YAAY,EAAE,CAAC,mBAAmB,CAAC;eACpC;;;ECPD;;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"__symbolic":"module","version":4,"metadata":{"CodemirrorComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":29,"character":1},"arguments":[{"selector":"ngx-codemirror","template":"\n <textarea\n [name]=\"name\"\n class=\"ngx-codemirror {{ className }}\"\n [class.ngx-codemirror--focused]=\"isFocused\"\n autocomplete=\"off\"\n [autofocus]=\"autoFocus\"\n #ref\n >\n </textarea>\n ","providers":[{"provide":{"__symbolic":"reference","module":"@angular/forms","name":"NG_VALUE_ACCESSOR","line":44,"character":15},"useExisting":{"__symbolic":"reference","name":"CodemirrorComponent"},"multi":true}],"preserveWhitespaces":false,"changeDetection":{"__symbolic":"select","expression":{"__symbolic":"reference","module":"@angular/core","name":"ChangeDetectionStrategy","line":50,"character":19},"member":"OnPush"}}]}],"members":{"className":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":56,"character":3}}]}],"name":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":58,"character":3}}]}],"autoFocus":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":60,"character":3}}]}],"options":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":65,"character":3}}]}],"preserveScrollPosition":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":73,"character":3}}]}],"cursorActivity":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":75,"character":3}}]}],"focusChange":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":77,"character":3}}]}],"scroll":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":80,"character":3}}]}],"drop":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":83,"character":3}}]}],"ref":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild","line":84,"character":3},"arguments":["ref"]}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"KeyValueDiffers","line":97,"character":32},{"__symbolic":"reference","module":"@angular/core","name":"NgZone","line":97,"character":66}]}],"ngAfterViewInit":[{"__symbolic":"method"}],"ngDoCheck":[{"__symbolic":"method"}],"ngOnDestroy":[{"__symbolic":"method"}],"codemirrorValueChanged":[{"__symbolic":"method"}],"setOptionIfChanged":[{"__symbolic":"method"}],"focusChanged":[{"__symbolic":"method"}],"scrollChanged":[{"__symbolic":"method"}],"cursorActive":[{"__symbolic":"method"}],"dropFiles":[{"__symbolic":"method"}],"writeValue":[{"__symbolic":"method"}],"registerOnChange":[{"__symbolic":"method"}],"registerOnTouched":[{"__symbolic":"method"}],"setDisabledState":[{"__symbolic":"method"}]}},"CodemirrorModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":4,"character":1},"arguments":[{"exports":[{"__symbolic":"reference","name":"CodemirrorComponent"}],"declarations":[{"__symbolic":"reference","name":"CodemirrorComponent"}]}]}],"members":{}}},"origins":{"CodemirrorComponent":"./codemirror.component","CodemirrorModule":"./codemirror.module"},"importAs":"@ctrl/ngx-codemirror"}