@ctrl/ngx-codemirror 4.1.0 → 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.
- package/README.md +9 -8
- package/codemirror.component.d.ts +6 -3
- package/codemirror.module.d.ts +5 -0
- package/ctrl-ngx-codemirror.d.ts +1 -0
- package/esm2020/codemirror.component.mjs +220 -0
- package/esm2020/codemirror.module.mjs +16 -0
- package/{esm2015/ctrl-ngx-codemirror.js → esm2020/ctrl-ngx-codemirror.mjs} +1 -1
- package/{esm2015/public_api.js → esm2020/public_api.mjs} +1 -1
- package/fesm2015/{ctrl-ngx-codemirror.js → ctrl-ngx-codemirror.mjs} +75 -49
- package/fesm2015/ctrl-ngx-codemirror.mjs.map +1 -0
- package/fesm2020/ctrl-ngx-codemirror.mjs +240 -0
- package/fesm2020/ctrl-ngx-codemirror.mjs.map +1 -0
- package/package.json +24 -13
- package/bundles/ctrl-ngx-codemirror.umd.js +0 -226
- package/bundles/ctrl-ngx-codemirror.umd.js.map +0 -1
- package/bundles/ctrl-ngx-codemirror.umd.min.js +0 -2
- package/bundles/ctrl-ngx-codemirror.umd.min.js.map +0 -1
- package/ctrl-ngx-codemirror.metadata.json +0 -1
- package/esm2015/codemirror.component.js +0 -198
- package/esm2015/codemirror.module.js +0 -11
- package/fesm2015/ctrl-ngx-codemirror.js.map +0 -1
@@ -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,YAAO,GAAP,OAAO,CAAQ;;QAzC7D,cAAS,GAAG,EAAE,CAAC;;QAEf,SAAI,GAAG,YAAY,CAAC;;QAEpB,cAAS,GAAG,KAAK,CAAC;;QAalB,2BAAsB,GAAG,KAAK,CAAC;;QAE9B,mBAAc,GAAG,IAAI,YAAY,EAAU,CAAC;;QAE5C,gBAAW,GAAG,IAAI,YAAY,EAAW,CAAC;;;QAG1C,WAAM,GAAG,IAAI,YAAY,EAAc,CAAC;;;QAGxC,SAAI,GAAG,IAAI,YAAY,EAAuB,CAAC;QAEzD,UAAK,GAAG,EAAE,CAAC;QACX,aAAQ,GAAG,KAAK,CAAC;QACjB,cAAS,GAAG,KAAK,CAAC;;QAiIV,aAAQ,GAAG,CAAC,CAAM,QAAO,CAAC;;QAE1B,cAAS,GAAG,SAAQ,CAAC;KAzH6C;;;;;IAhC1E,IACI,OAAO,CAAC,KAA6B;QACvC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AK;oBAC1B,eAAe,EAAE,uBAAuB,CAAC,MAAM;iBAChD;2HAKU,SAAS;sBAAjB,KAAK;gBAEG,IAAI;sBAAZ,KAAK;gBAEG,SAAS;sBAAjB,KAAK;gBAMF,OAAO;sBADV,KAAK;gBAQG,sBAAsB;sBAA9B,KAAK;gBAEI,cAAc;sBAAvB,MAAM;gBAEG,WAAW;sBAApB,MAAM;gBAGG,MAAM;sBAAf,MAAM;gBAGG,IAAI;sBAAb,MAAM;gBACW,GAAG;sBAApB,SAAS;uBAAC,KAAK;;;MC5EL,gBAAgB;;6GAAhB,gBAAgB;8GAAhB,gBAAgB,iBAFZ,mBAAmB,aADxB,mBAAmB;8GAGlB,gBAAgB;2FAAhB,gBAAgB;kBAJ5B,QAAQ;mBAAC;oBACR,OAAO,EAAE,CAAC,mBAAmB,CAAC;oBAC9B,YAAY,EAAE,CAAC,mBAAmB,CAAC;iBACpC;;;ACPD;;;;;;"}
|
package/package.json
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
{
|
2
2
|
"$schema": "../../node_modules/ng-packagr/package.schema.json",
|
3
3
|
"name": "@ctrl/ngx-codemirror",
|
4
|
-
"version": "
|
4
|
+
"version": "5.1.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"description": "CodeMirror wrapper for Angular",
|
7
7
|
"dependencies": {
|
8
|
-
"@types/codemirror": "^
|
9
|
-
"tslib": "^2.
|
8
|
+
"@types/codemirror": "^5.60.5",
|
9
|
+
"tslib": "^2.3.0"
|
10
10
|
},
|
11
11
|
"peerDependencies": {
|
12
|
-
"@angular/core": ">=
|
13
|
-
"@angular/forms": ">=
|
14
|
-
"codemirror": ">=5.
|
12
|
+
"@angular/core": ">=12.0.0-0",
|
13
|
+
"@angular/forms": ">=12.0.0-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
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"
|
29
|
-
"fesm2015": "fesm2015/ctrl-ngx-codemirror.
|
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
|
-
"
|
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,226 +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
|
-
// tslint:disable-next-line:no-output-native
|
31
|
-
this.scroll = new core.EventEmitter();
|
32
|
-
/* called when file(s) are dropped */
|
33
|
-
// tslint:disable-next-line: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
|
-
this._codeMirror = typeof CodeMirror !== 'undefined' ? CodeMirror : require('codemirror');
|
63
|
-
return this._codeMirror;
|
64
|
-
},
|
65
|
-
enumerable: false,
|
66
|
-
configurable: true
|
67
|
-
});
|
68
|
-
CodemirrorComponent.prototype.ngAfterViewInit = function () {
|
69
|
-
var _this = this;
|
70
|
-
if (!this.ref) {
|
71
|
-
return;
|
72
|
-
}
|
73
|
-
// in order to allow for universal rendering, we import Codemirror runtime with `require` to prevent node errors
|
74
|
-
this._ngZone.runOutsideAngular(function () {
|
75
|
-
_this.codeMirror = _this.codeMirrorGlobal.fromTextArea(_this.ref.nativeElement, _this._options);
|
76
|
-
_this.codeMirror.on('cursorActivity', function (cm) { return _this._ngZone.run(function () { return _this.cursorActive(cm); }); });
|
77
|
-
_this.codeMirror.on('scroll', _this.scrollChanged.bind(_this));
|
78
|
-
_this.codeMirror.on('blur', function () { return _this._ngZone.run(function () { return _this.focusChanged(false); }); });
|
79
|
-
_this.codeMirror.on('focus', function () { return _this._ngZone.run(function () { return _this.focusChanged(true); }); });
|
80
|
-
_this.codeMirror.on('change', function (cm, change) { return _this._ngZone.run(function () { return _this.codemirrorValueChanged(cm, change); }); });
|
81
|
-
_this.codeMirror.on('drop', function (cm, e) {
|
82
|
-
_this._ngZone.run(function () { return _this.dropFiles(cm, e); });
|
83
|
-
});
|
84
|
-
_this.codeMirror.setValue(_this.value);
|
85
|
-
});
|
86
|
-
};
|
87
|
-
CodemirrorComponent.prototype.ngDoCheck = function () {
|
88
|
-
var _this = this;
|
89
|
-
if (!this._differ) {
|
90
|
-
return;
|
91
|
-
}
|
92
|
-
// check options have not changed
|
93
|
-
var changes = this._differ.diff(this._options);
|
94
|
-
if (changes) {
|
95
|
-
changes.forEachChangedItem(function (option) { return _this.setOptionIfChanged(option.key, option.currentValue); });
|
96
|
-
changes.forEachAddedItem(function (option) { return _this.setOptionIfChanged(option.key, option.currentValue); });
|
97
|
-
changes.forEachRemovedItem(function (option) { return _this.setOptionIfChanged(option.key, option.currentValue); });
|
98
|
-
}
|
99
|
-
};
|
100
|
-
CodemirrorComponent.prototype.ngOnDestroy = function () {
|
101
|
-
// is there a lighter-weight way to remove the cm instance?
|
102
|
-
if (this.codeMirror) {
|
103
|
-
this.codeMirror.toTextArea();
|
104
|
-
}
|
105
|
-
};
|
106
|
-
CodemirrorComponent.prototype.codemirrorValueChanged = function (cm, change) {
|
107
|
-
if (change.origin !== 'setValue') {
|
108
|
-
this.value = cm.getValue();
|
109
|
-
this.onChange(this.value);
|
110
|
-
}
|
111
|
-
};
|
112
|
-
CodemirrorComponent.prototype.setOptionIfChanged = function (optionName, newValue) {
|
113
|
-
if (!this.codeMirror) {
|
114
|
-
return;
|
115
|
-
}
|
116
|
-
// cast to any to handle strictly typed option names
|
117
|
-
// could possibly import settings strings available in the future
|
118
|
-
this.codeMirror.setOption(optionName, newValue);
|
119
|
-
};
|
120
|
-
CodemirrorComponent.prototype.focusChanged = function (focused) {
|
121
|
-
this.onTouched();
|
122
|
-
this.isFocused = focused;
|
123
|
-
this.focusChange.emit(focused);
|
124
|
-
};
|
125
|
-
CodemirrorComponent.prototype.scrollChanged = function (cm) {
|
126
|
-
this.scroll.emit(cm.getScrollInfo());
|
127
|
-
};
|
128
|
-
CodemirrorComponent.prototype.cursorActive = function (cm) {
|
129
|
-
this.cursorActivity.emit(cm);
|
130
|
-
};
|
131
|
-
CodemirrorComponent.prototype.dropFiles = function (cm, e) {
|
132
|
-
this.drop.emit([cm, e]);
|
133
|
-
};
|
134
|
-
/** Implemented as part of ControlValueAccessor. */
|
135
|
-
CodemirrorComponent.prototype.writeValue = function (value) {
|
136
|
-
if (value === null || value === undefined) {
|
137
|
-
return;
|
138
|
-
}
|
139
|
-
if (!this.codeMirror) {
|
140
|
-
this.value = value;
|
141
|
-
return;
|
142
|
-
}
|
143
|
-
var cur = this.codeMirror.getValue();
|
144
|
-
if (value !== cur &&
|
145
|
-
normalizeLineEndings(cur) !== normalizeLineEndings(value)) {
|
146
|
-
this.value = value;
|
147
|
-
if (this.preserveScrollPosition) {
|
148
|
-
var prevScrollPosition = this.codeMirror.getScrollInfo();
|
149
|
-
this.codeMirror.setValue(this.value);
|
150
|
-
this.codeMirror.scrollTo(prevScrollPosition.left, prevScrollPosition.top);
|
151
|
-
}
|
152
|
-
else {
|
153
|
-
this.codeMirror.setValue(this.value);
|
154
|
-
}
|
155
|
-
}
|
156
|
-
};
|
157
|
-
/** Implemented as part of ControlValueAccessor. */
|
158
|
-
CodemirrorComponent.prototype.registerOnChange = function (fn) {
|
159
|
-
this.onChange = fn;
|
160
|
-
};
|
161
|
-
/** Implemented as part of ControlValueAccessor. */
|
162
|
-
CodemirrorComponent.prototype.registerOnTouched = function (fn) {
|
163
|
-
this.onTouched = fn;
|
164
|
-
};
|
165
|
-
/** Implemented as part of ControlValueAccessor. */
|
166
|
-
CodemirrorComponent.prototype.setDisabledState = function (isDisabled) {
|
167
|
-
this.disabled = isDisabled;
|
168
|
-
this.setOptionIfChanged('readOnly', this.disabled);
|
169
|
-
};
|
170
|
-
return CodemirrorComponent;
|
171
|
-
}());
|
172
|
-
CodemirrorComponent.decorators = [
|
173
|
-
{ type: core.Component, args: [{
|
174
|
-
selector: 'ngx-codemirror',
|
175
|
-
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 ",
|
176
|
-
providers: [
|
177
|
-
{
|
178
|
-
provide: forms.NG_VALUE_ACCESSOR,
|
179
|
-
useExisting: core.forwardRef(function () { return CodemirrorComponent; }),
|
180
|
-
multi: true,
|
181
|
-
},
|
182
|
-
],
|
183
|
-
preserveWhitespaces: false,
|
184
|
-
changeDetection: core.ChangeDetectionStrategy.OnPush
|
185
|
-
},] }
|
186
|
-
];
|
187
|
-
CodemirrorComponent.ctorParameters = function () { return [
|
188
|
-
{ type: core.KeyValueDiffers },
|
189
|
-
{ type: core.NgZone }
|
190
|
-
]; };
|
191
|
-
CodemirrorComponent.propDecorators = {
|
192
|
-
className: [{ type: core.Input }],
|
193
|
-
name: [{ type: core.Input }],
|
194
|
-
autoFocus: [{ type: core.Input }],
|
195
|
-
options: [{ type: core.Input }],
|
196
|
-
preserveScrollPosition: [{ type: core.Input }],
|
197
|
-
cursorActivity: [{ type: core.Output }],
|
198
|
-
focusChange: [{ type: core.Output }],
|
199
|
-
scroll: [{ type: core.Output }],
|
200
|
-
drop: [{ type: core.Output }],
|
201
|
-
ref: [{ type: core.ViewChild, args: ['ref', { static: true },] }]
|
202
|
-
};
|
203
|
-
|
204
|
-
var CodemirrorModule = /** @class */ (function () {
|
205
|
-
function CodemirrorModule() {
|
206
|
-
}
|
207
|
-
return CodemirrorModule;
|
208
|
-
}());
|
209
|
-
CodemirrorModule.decorators = [
|
210
|
-
{ type: core.NgModule, args: [{
|
211
|
-
exports: [CodemirrorComponent],
|
212
|
-
declarations: [CodemirrorComponent],
|
213
|
-
},] }
|
214
|
-
];
|
215
|
-
|
216
|
-
/**
|
217
|
-
* Generated bundle index. Do not edit.
|
218
|
-
*/
|
219
|
-
|
220
|
-
exports.CodemirrorComponent = CodemirrorComponent;
|
221
|
-
exports.CodemirrorModule = CodemirrorModule;
|
222
|
-
|
223
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
224
|
-
|
225
|
-
})));
|
226
|
-
//# 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 {\n Editor,\n EditorChangeLinkedList,\n EditorFromTextArea,\n ScrollInfo,\n} 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 /* 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 // tslint:disable-next-line:no-output-native\n @Output() scroll = new EventEmitter<ScrollInfo>();\n /* called when file(s) are dropped */\n // tslint:disable-next-line:no-output-native\n @Output() drop = new EventEmitter<[Editor, DragEvent]>();\n @ViewChild('ref', { static: true }) ref!: ElementRef;\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 this._codeMirror = typeof CodeMirror !== 'undefined' ? CodeMirror : require('codemirror');\n return this._codeMirror;\n }\n\n ngAfterViewInit(): void {\n if (!this.ref) {\n return;\n }\n // in order to allow for universal rendering, we import Codemirror runtime with `require` to prevent node errors\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 =>\n this._ngZone.run(() => this.cursorActive(cm)),\n );\n this.codeMirror.on('scroll', this.scrollChanged.bind(this));\n this.codeMirror.on('blur', () =>\n this._ngZone.run(() => this.focusChanged(false)),\n );\n this.codeMirror.on('focus', () =>\n this._ngZone.run(() => this.focusChanged(true)),\n );\n this.codeMirror.on(\n 'change',\n (cm: Editor, change: EditorChangeLinkedList) =>\n this._ngZone.run(() => this.codemirrorValueChanged(cm, change)),\n );\n this.codeMirror.on(\n 'drop',\n (cm: Editor, e: DragEvent) => {\n this._ngZone.run(() => this.dropFiles(cm, e));\n }\n );\n this.codeMirror.setValue(this.value);\n });\n }\n ngDoCheck(): void {\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 =>\n this.setOptionIfChanged(option.key, option.currentValue),\n );\n changes.forEachRemovedItem(option =>\n this.setOptionIfChanged(option.key, option.currentValue),\n );\n }\n }\n ngOnDestroy(): void {\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: EditorChangeLinkedList): void {\n if (change.origin !== 'setValue') {\n this.value = cm.getValue();\n this.onChange(this.value);\n }\n }\n setOptionIfChanged(optionName: string, newValue: any): void {\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): void {\n this.onTouched();\n this.isFocused = focused;\n this.focusChange.emit(focused);\n }\n scrollChanged(cm: Editor): void {\n this.scroll.emit(cm.getScrollInfo());\n }\n cursorActive(cm: Editor): void {\n this.cursorActivity.emit(cm);\n }\n dropFiles(cm: Editor, e: DragEvent): void {\n this.drop.emit([cm, e]);\n }\n /** Implemented as part of ControlValueAccessor. */\n writeValue(value: string): void {\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 (\n value !== cur &&\n normalizeLineEndings(cur) !== normalizeLineEndings(value)\n ) {\n this.value = value;\n if (this.preserveScrollPosition) {\n const prevScrollPosition = this.codeMirror.getScrollInfo();\n this.codeMirror.setValue(this.value);\n this.codeMirror.scrollTo(\n prevScrollPosition.left,\n prevScrollPosition.top,\n );\n } else {\n this.codeMirror.setValue(this.value);\n }\n }\n }\n\n /** Implemented as part of ControlValueAccessor. */\n registerOnChange(fn: (value: string) => void): void {\n this.onChange = fn;\n }\n /** Implemented as part of ControlValueAccessor. */\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n /** Implemented as part of ControlValueAccessor. */\n setDisabledState(isDisabled: boolean): void {\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":";;;;;;EAwBA,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;;MAwEC,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;;UAsJV,aAAQ,GAAG,UAAC,CAAM,KAAO,CAAC;;UAE1B,cAAS,GAAG,eAAQ,CAAC;OA9I6C;MAhC1E,sBACI,wCAAO;;;;;eADX,UACY,KAA6B;cACvC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;cACtB,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,KAAK,EAAE;kBAC1B,IAAI,CAAC,OAAO,GAAG,IAA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D,mBAAmB,EAAE,KAAK;kBAC1B,eAAe,EAAEC,4BAAuB,CAAC,MAAM;eAChD;;;cA9CCC,oBAAe;cACfC,WAAM;;;0BAiDLC,UAAK;qBAELA,UAAK;0BAELA,UAAK;wBAKLA,UAAK;uCAQLA,UAAK;+BAELC,WAAM;4BAENA,WAAM;uBAGNA,WAAM;qBAGNA,WAAM;oBACNC,cAAS,SAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;;;;MChFpC;;;;;cAJCC,aAAQ,SAAC;kBACR,OAAO,EAAE,CAAC,mBAAmB,CAAC;kBAC9B,YAAY,EAAE,CAAC,mBAAmB,CAAC;eACpC;;;ECPD;;;;;;;;;;;;;"}
|
@@ -1,2 +0,0 @@
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@angular/core"),require("@angular/forms")):"function"==typeof define&&define.amd?define("@ctrl/ngx-codemirror",["exports","@angular/core","@angular/forms"],r):r(((e="undefined"!=typeof globalThis?globalThis:e||self).ctrl=e.ctrl||{},e.ctrl["ngx-codemirror"]={}),e.ng.core,e.ng.forms)}(this,(function(e,r,t){"use strict";function o(e){return e?e.replace(/\r\n|\r/g,"\n"):e}var n=function(){function e(e,t){this._differs=e,this._ngZone=t,this.className="",this.name="codemirror",this.autoFocus=!1,this.preserveScrollPosition=!1,this.cursorActivity=new r.EventEmitter,this.focusChange=new r.EventEmitter,this.scroll=new r.EventEmitter,this.drop=new r.EventEmitter,this.value="",this.disabled=!1,this.isFocused=!1,this.onChange=function(e){},this.onTouched=function(){}}return Object.defineProperty(e.prototype,"options",{set:function(e){this._options=e,!this._differ&&e&&(this._differ=this._differs.find(e).create())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"codeMirrorGlobal",{get:function(){return this._codeMirror||(this._codeMirror="undefined"!=typeof CodeMirror?CodeMirror:require("codemirror")),this._codeMirror},enumerable:!1,configurable:!0}),e.prototype.ngAfterViewInit=function(){var e=this;this.ref&&this._ngZone.runOutsideAngular((function(){e.codeMirror=e.codeMirrorGlobal.fromTextArea(e.ref.nativeElement,e._options),e.codeMirror.on("cursorActivity",(function(r){return e._ngZone.run((function(){return e.cursorActive(r)}))})),e.codeMirror.on("scroll",e.scrollChanged.bind(e)),e.codeMirror.on("blur",(function(){return e._ngZone.run((function(){return e.focusChanged(!1)}))})),e.codeMirror.on("focus",(function(){return e._ngZone.run((function(){return e.focusChanged(!0)}))})),e.codeMirror.on("change",(function(r,t){return e._ngZone.run((function(){return e.codemirrorValueChanged(r,t)}))})),e.codeMirror.on("drop",(function(r,t){e._ngZone.run((function(){return e.dropFiles(r,t)}))})),e.codeMirror.setValue(e.value)}))},e.prototype.ngDoCheck=function(){var e=this;if(this._differ){var r=this._differ.diff(this._options);r&&(r.forEachChangedItem((function(r){return e.setOptionIfChanged(r.key,r.currentValue)})),r.forEachAddedItem((function(r){return e.setOptionIfChanged(r.key,r.currentValue)})),r.forEachRemovedItem((function(r){return e.setOptionIfChanged(r.key,r.currentValue)})))}},e.prototype.ngOnDestroy=function(){this.codeMirror&&this.codeMirror.toTextArea()},e.prototype.codemirrorValueChanged=function(e,r){"setValue"!==r.origin&&(this.value=e.getValue(),this.onChange(this.value))},e.prototype.setOptionIfChanged=function(e,r){this.codeMirror&&this.codeMirror.setOption(e,r)},e.prototype.focusChanged=function(e){this.onTouched(),this.isFocused=e,this.focusChange.emit(e)},e.prototype.scrollChanged=function(e){this.scroll.emit(e.getScrollInfo())},e.prototype.cursorActive=function(e){this.cursorActivity.emit(e)},e.prototype.dropFiles=function(e,r){this.drop.emit([e,r])},e.prototype.writeValue=function(e){if(null!=e)if(this.codeMirror){var r=this.codeMirror.getValue();if(e!==r&&o(r)!==o(e))if(this.value=e,this.preserveScrollPosition){var t=this.codeMirror.getScrollInfo();this.codeMirror.setValue(this.value),this.codeMirror.scrollTo(t.left,t.top)}else this.codeMirror.setValue(this.value)}else this.value=e},e.prototype.registerOnChange=function(e){this.onChange=e},e.prototype.registerOnTouched=function(e){this.onTouched=e},e.prototype.setDisabledState=function(e){this.disabled=e,this.setOptionIfChanged("readOnly",this.disabled)},e}();n.decorators=[{type:r.Component,args:[{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:t.NG_VALUE_ACCESSOR,useExisting:r.forwardRef((function(){return n})),multi:!0}],preserveWhitespaces:!1,changeDetection:r.ChangeDetectionStrategy.OnPush}]}],n.ctorParameters=function(){return[{type:r.KeyValueDiffers},{type:r.NgZone}]},n.propDecorators={className:[{type:r.Input}],name:[{type:r.Input}],autoFocus:[{type:r.Input}],options:[{type:r.Input}],preserveScrollPosition:[{type:r.Input}],cursorActivity:[{type:r.Output}],focusChange:[{type:r.Output}],scroll:[{type:r.Output}],drop:[{type:r.Output}],ref:[{type:r.ViewChild,args:["ref",{static:!0}]}]};var i=function(){};i.decorators=[{type:r.NgModule,args:[{exports:[n],declarations:[n]}]}],e.CodemirrorComponent=n,e.CodemirrorModule=i,Object.defineProperty(e,"__esModule",{value:!0})}));
|
2
|
-
//# sourceMappingURL=ctrl-ngx-codemirror.umd.min.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/codemirror.component.ts","../../src/lib/codemirror.module.ts"],"names":["normalizeLineEndings","str","replace","CodemirrorComponent","_differs","_ngZone","this","className","name","autoFocus","preserveScrollPosition","cursorActivity","EventEmitter","focusChange","scroll","drop","value","disabled","isFocused","onChange","_","onTouched","Object","defineProperty","prototype","_options","_differ","find","create","_codeMirror","CodeMirror","require","ngAfterViewInit","_this","ref","runOutsideAngular","codeMirror","codeMirrorGlobal","fromTextArea","nativeElement","on","cm","run","cursorActive","scrollChanged","bind","focusChanged","change","codemirrorValueChanged","e","dropFiles","setValue","ngDoCheck","changes","diff","forEachChangedItem","option","setOptionIfChanged","key","currentValue","forEachAddedItem","forEachRemovedItem","ngOnDestroy","toTextArea","origin","getValue","optionName","newValue","setOption","focused","emit","getScrollInfo","writeValue","cur","prevScrollPosition","scrollTo","left","top","registerOnChange","fn","registerOnTouched","setDisabledState","isDisabled","Component","args","selector","template","providers","provide","NG_VALUE_ACCESSOR","useExisting","forwardRef","multi","preserveWhitespaces","changeDetection","ChangeDetectionStrategy","OnPush","KeyValueDiffers","NgZone","Input","Output","ViewChild","static","NgModule","exports","declarations"],"mappings":"sZAwBA,SAASA,EAAqBC,GAC5B,OAAKA,EAGEA,EAAIC,QAAQ,WAAY,MAFtBD,mBA2ET,SAAAE,EAAoBC,EAAmCC,GAAnCC,KAAAF,SAAAA,EAAmCE,KAAAD,QAAAA,EAzC9CC,KAAAC,UAAY,GAEZD,KAAAE,KAAO,aAEPF,KAAAG,WAAY,EAaZH,KAAAI,wBAAyB,EAExBJ,KAAAK,eAAiB,IAAIC,EAAAA,aAErBN,KAAAO,YAAc,IAAID,EAAAA,aAGlBN,KAAAQ,OAAS,IAAIF,EAAAA,aAGbN,KAAAS,KAAO,IAAIH,EAAAA,aAErBN,KAAAU,MAAQ,GACRV,KAAAW,UAAW,EACXX,KAAAY,WAAY,EAsJJZ,KAAAa,SAAW,SAACC,KAEZd,KAAAe,UAAY,oBA9KpBC,OAAAC,eACIpB,EAAAqB,UAAA,UAAO,KADX,SACYR,GACVV,KAAKmB,SAAWT,GACXV,KAAKoB,SAAWV,IACnBV,KAAKoB,QAAUpB,KAAKF,SAASuB,KAAKX,GAAOY,2CA8B7CN,OAAAC,eAAIpB,EAAAqB,UAAA,mBAAgB,KAApB,WACE,OAAIlB,KAAKuB,cAITvB,KAAKuB,YAAoC,oBAAfC,WAA6BA,WAAaC,QAAQ,eAHnEzB,KAAKuB,6CAOhB1B,EAAAqB,UAAAQ,gBAAA,WAAA,IAAAC,EAAA3B,KACOA,KAAK4B,KAIV5B,KAAKD,QAAQ8B,mBAAkB,WAC7BF,EAAKG,WAAaH,EAAKI,iBAA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ACTC,SAAU,iBACVC,SAAU,yOAWVC,UAAW,CACT,CACEC,QAASC,EAAAA,kBACTC,YAAaC,EAAAA,YAAW,WAAM,OAAAxF,KAC9ByF,OAAO,IAGXC,qBAAqB,EACrBC,gBAAiBC,EAAAA,wBAAwBC,oDA7CzCC,EAAAA,uBACAC,EAAAA,6CAiDCC,EAAAA,oBAEAA,EAAAA,yBAEAA,EAAAA,uBAKAA,EAAAA,sCAQAA,EAAAA,8BAEAC,EAAAA,4BAEAA,EAAAA,uBAGAA,EAAAA,qBAGAA,EAAAA,oBACAC,EAAAA,UAASjB,KAAA,CAAC,MAAO,CAAEkB,QAAQ,aChF9B,iCAJCC,EAAAA,SAAQnB,KAAA,CAAC,CACRoB,QAAS,CAACrG,GACVsG,aAAc,CAACtG","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 {\n Editor,\n EditorChangeLinkedList,\n EditorFromTextArea,\n ScrollInfo,\n} 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 /* 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 // tslint:disable-next-line:no-output-native\n @Output() scroll = new EventEmitter<ScrollInfo>();\n /* called when file(s) are dropped */\n // tslint:disable-next-line:no-output-native\n @Output() drop = new EventEmitter<[Editor, DragEvent]>();\n @ViewChild('ref', { static: true }) ref!: ElementRef;\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 this._codeMirror = typeof CodeMirror !== 'undefined' ? CodeMirror : require('codemirror');\n return this._codeMirror;\n }\n\n ngAfterViewInit(): void {\n if (!this.ref) {\n return;\n }\n // in order to allow for universal rendering, we import Codemirror runtime with `require` to prevent node errors\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 =>\n this._ngZone.run(() => this.cursorActive(cm)),\n );\n this.codeMirror.on('scroll', this.scrollChanged.bind(this));\n this.codeMirror.on('blur', () =>\n this._ngZone.run(() => this.focusChanged(false)),\n );\n this.codeMirror.on('focus', () =>\n this._ngZone.run(() => this.focusChanged(true)),\n );\n this.codeMirror.on(\n 'change',\n (cm: Editor, change: EditorChangeLinkedList) =>\n this._ngZone.run(() => this.codemirrorValueChanged(cm, change)),\n );\n this.codeMirror.on(\n 'drop',\n (cm: Editor, e: DragEvent) => {\n this._ngZone.run(() => this.dropFiles(cm, e));\n }\n );\n this.codeMirror.setValue(this.value);\n });\n }\n ngDoCheck(): void {\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 =>\n this.setOptionIfChanged(option.key, option.currentValue),\n );\n changes.forEachRemovedItem(option =>\n this.setOptionIfChanged(option.key, option.currentValue),\n );\n }\n }\n ngOnDestroy(): void {\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: EditorChangeLinkedList): void {\n if (change.origin !== 'setValue') {\n this.value = cm.getValue();\n this.onChange(this.value);\n }\n }\n setOptionIfChanged(optionName: string, newValue: any): void {\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): void {\n this.onTouched();\n this.isFocused = focused;\n this.focusChange.emit(focused);\n }\n scrollChanged(cm: Editor): void {\n this.scroll.emit(cm.getScrollInfo());\n }\n cursorActive(cm: Editor): void {\n this.cursorActivity.emit(cm);\n }\n dropFiles(cm: Editor, e: DragEvent): void {\n this.drop.emit([cm, e]);\n }\n /** Implemented as part of ControlValueAccessor. */\n writeValue(value: string): void {\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 (\n value !== cur &&\n normalizeLineEndings(cur) !== normalizeLineEndings(value)\n ) {\n this.value = value;\n if (this.preserveScrollPosition) {\n const prevScrollPosition = this.codeMirror.getScrollInfo();\n this.codeMirror.setValue(this.value);\n this.codeMirror.scrollTo(\n prevScrollPosition.left,\n prevScrollPosition.top,\n );\n } else {\n this.codeMirror.setValue(this.value);\n }\n }\n }\n\n /** Implemented as part of ControlValueAccessor. */\n registerOnChange(fn: (value: string) => void): void {\n this.onChange = fn;\n }\n /** Implemented as part of ControlValueAccessor. */\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n /** Implemented as part of ControlValueAccessor. */\n setDisabledState(isDisabled: boolean): void {\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"]}
|