@progress/kendo-angular-editor 2.5.0-dev.202111261548 → 3.0.0-dev.202201121058
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/dist/cdn/js/kendo-angular-editor.js +2 -2
- package/dist/cdn/main.js +1 -1
- package/dist/es/common/error-messages.js +3 -2
- package/dist/es/config/commands.js +2 -2
- package/dist/es/config/schema.js +1 -2
- package/dist/es/config/table-commands.js +1 -363
- package/dist/es/editor.component.js +99 -71
- package/dist/es/main.js +1 -0
- package/dist/es/package-metadata.js +1 -1
- package/dist/{es2015/config/table-nodes.d.ts → es/preventable-events/paste-event-data.js} +0 -5
- package/dist/es/preventable-events/paste-event.js +25 -0
- package/dist/es2015/common/error-messages.js +3 -2
- package/dist/es2015/common/paste-cleanup-settings.d.ts +14 -0
- package/dist/es2015/config/commands.js +2 -2
- package/dist/es2015/config/schema.js +1 -2
- package/dist/es2015/config/table-commands.d.ts +0 -36
- package/dist/es2015/config/table-commands.js +1 -357
- package/dist/es2015/editor.component.d.ts +15 -10
- package/dist/es2015/editor.component.js +99 -71
- package/dist/es2015/index.metadata.json +1 -1
- package/dist/es2015/main.d.ts +2 -0
- package/dist/es2015/main.js +1 -0
- package/dist/es2015/package-metadata.js +1 -1
- package/dist/es2015/preventable-events/paste-event-data.d.ts +21 -0
- package/dist/es2015/preventable-events/paste-event-data.js +4 -0
- package/dist/es2015/preventable-events/paste-event.d.ts +27 -0
- package/dist/es2015/preventable-events/paste-event.js +20 -0
- package/dist/fesm2015/index.js +263 -1596
- package/dist/fesm5/index.js +285 -1641
- package/dist/npm/common/error-messages.js +3 -1
- package/dist/npm/config/commands.js +1 -1
- package/dist/npm/config/schema.js +1 -2
- package/dist/npm/config/table-commands.js +1 -368
- package/dist/npm/editor.component.js +95 -67
- package/dist/npm/main.js +2 -0
- package/dist/npm/package-metadata.js +1 -1
- package/dist/npm/preventable-events/paste-event-data.js +6 -0
- package/dist/npm/preventable-events/paste-event.js +27 -0
- package/dist/systemjs/kendo-angular-editor.js +1 -1
- package/package.json +5 -5
- package/dist/es/config/table-nodes.js +0 -146
- package/dist/es/config/tables/CellSelection.js +0 -268
- package/dist/es/config/tables/TableMap.js +0 -333
- package/dist/es/config/tables/table-utils.js +0 -302
- package/dist/es2015/config/table-nodes.js +0 -145
- package/dist/es2015/config/tables/CellSelection.d.ts +0 -35
- package/dist/es2015/config/tables/CellSelection.js +0 -256
- package/dist/es2015/config/tables/TableMap.d.ts +0 -35
- package/dist/es2015/config/tables/TableMap.js +0 -329
- package/dist/es2015/config/tables/table-utils.d.ts +0 -77
- package/dist/es2015/config/tables/table-utils.js +0 -299
- package/dist/npm/config/table-nodes.js +0 -157
- package/dist/npm/config/tables/CellSelection.js +0 -270
- package/dist/npm/config/tables/TableMap.js +0 -338
- package/dist/npm/config/tables/table-utils.js +0 -307
|
@@ -6,12 +6,12 @@ import * as tslib_1 from "tslib";
|
|
|
6
6
|
var EditorComponent_1;
|
|
7
7
|
import { Component, HostBinding, ViewChild, ContentChild, ViewContainerRef, Output, ElementRef, EventEmitter, forwardRef, Input, ChangeDetectorRef, NgZone, isDevMode } from '@angular/core';
|
|
8
8
|
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
9
|
-
import { BehaviorSubject, fromEvent,
|
|
10
|
-
import { map, filter,
|
|
9
|
+
import { BehaviorSubject, fromEvent, Subject, zip } from 'rxjs';
|
|
10
|
+
import { map, filter, take } from 'rxjs/operators';
|
|
11
11
|
import { ToolBarComponent } from '@progress/kendo-angular-toolbar';
|
|
12
12
|
import { DialogService } from '@progress/kendo-angular-dialog';
|
|
13
|
-
import { isDocumentAvailable, KendoInput } from '@progress/kendo-angular-common';
|
|
14
|
-
import { buildKeymap, buildListKeymap,
|
|
13
|
+
import { hasObservers, isDocumentAvailable, KendoInput } from '@progress/kendo-angular-common';
|
|
14
|
+
import { buildKeymap, buildListKeymap, getHtml, pasteCleanup, sanitize, removeComments, sanitizeClassAttr, sanitizeStyleAttr, removeAttribute, placeholder, EditorView, EditorState, baseKeymap, keymap, history, parseContent, Plugin, PluginKey, TextSelection, Schema, AllSelection, gapCursor, getSelectionText, imageResizing, tableEditing } from '@progress/kendo-editor-common';
|
|
15
15
|
import { validatePackage } from '@progress/kendo-licensing';
|
|
16
16
|
import { packageMetadata } from './package-metadata';
|
|
17
17
|
import { schema } from './config/schema';
|
|
@@ -26,15 +26,16 @@ import { EditorLocalizationService } from './localization/editor-localization.se
|
|
|
26
26
|
import { defaultStyle, tablesStyles, rtlStyles } from './common/styles';
|
|
27
27
|
import { EditorErrorMessages } from './common/error-messages';
|
|
28
28
|
import { EditorToolsService } from './tools/tools.service';
|
|
29
|
+
import { EditorPasteEvent } from './preventable-events/paste-event';
|
|
29
30
|
const EMPTY_PARAGRAPH = '<p></p>';
|
|
30
31
|
const defaultPasteCleanupSettings = {
|
|
31
32
|
convertMsLists: false,
|
|
32
33
|
removeAttributes: [],
|
|
33
34
|
removeHtmlComments: false,
|
|
34
|
-
removeInvalidHTML:
|
|
35
|
+
removeInvalidHTML: true,
|
|
35
36
|
removeMsClasses: false,
|
|
36
37
|
removeMsStyles: false,
|
|
37
|
-
stripTags: [
|
|
38
|
+
stripTags: []
|
|
38
39
|
};
|
|
39
40
|
const removeCommentsIf = conditionallyExecute(removeComments);
|
|
40
41
|
const removeInvalidHTMLIf = conditionallyExecute(sanitize);
|
|
@@ -71,14 +72,6 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
71
72
|
* @default false
|
|
72
73
|
*/
|
|
73
74
|
this.applyToWord = false;
|
|
74
|
-
/**
|
|
75
|
-
* By design, the Editor emits `valueChange`, updates the model and the ToolBar state on each keystroke.
|
|
76
|
-
* When you are interested in ignoring the new values for a given amout of time and take only the most recent one, you can use the `updateInterval` property.
|
|
77
|
-
* A possible use case is to get the new values and to update the ToolBar state at a maximum rate per second in order to speed up your application.
|
|
78
|
-
* The specified interval (in milliseconds) should be a positive number.
|
|
79
|
-
* By default the `updateInterval` is set to 100 miliseconds. If set to zero the delay will be disabled entirely.
|
|
80
|
-
*/
|
|
81
|
-
this.updateInterval = 100;
|
|
82
75
|
/**
|
|
83
76
|
* By default, whitespace is collapsed as per HTML's rules.
|
|
84
77
|
* Set to `true` to preserve whitespace, but normalize newlines to spaces.
|
|
@@ -104,6 +97,11 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
104
97
|
* Fires when the content area of the Editor is focused ([see example]({% slug overview_editor %}#toc-events)).
|
|
105
98
|
*/
|
|
106
99
|
this.onFocus = new EventEmitter();
|
|
100
|
+
/**
|
|
101
|
+
* Fires when the user performs paste in the content area of the Editor ([see example]({% slug overview_editor %}#toc-events)).
|
|
102
|
+
* The event is preventable. If you cancel it, the Editor content will not change.
|
|
103
|
+
*/
|
|
104
|
+
this.paste = new EventEmitter();
|
|
107
105
|
/**
|
|
108
106
|
* Fires when the content area of the Editor is blurred ([see example]({% slug overview_editor %}#toc-events)).
|
|
109
107
|
*/
|
|
@@ -119,10 +117,76 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
119
117
|
this.valueModified = new Subject();
|
|
120
118
|
this._readonly = false;
|
|
121
119
|
this._placeholder = '';
|
|
120
|
+
this.inForm = false;
|
|
122
121
|
this.afterViewInit = new Subject();
|
|
123
122
|
this.contentAreaLoaded = new Subject();
|
|
124
|
-
this.
|
|
123
|
+
this.dispatchTransaction = (tr) => {
|
|
124
|
+
const docChanged = tr.docChanged;
|
|
125
|
+
if (this.disabled || (this.readonly && docChanged)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (docChanged) {
|
|
129
|
+
const doc = tr.doc;
|
|
130
|
+
const html = getHtml({ doc });
|
|
131
|
+
this.trOnChange = tr;
|
|
132
|
+
this.htmlOnChange = html;
|
|
133
|
+
this.ngZone.run(() => {
|
|
134
|
+
this.valueModified.next(html);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (!docChanged || this.inForm) {
|
|
138
|
+
this.view.updateState(this.view.state.apply(tr));
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
this.transformPastedHTML = (dirtyHtml) => {
|
|
142
|
+
const pasteCleanupSettings = Object.assign({}, defaultPasteCleanupSettings, this.pasteCleanupSettings);
|
|
143
|
+
const html = pipe(removeInvalidHTMLIf(pasteCleanupSettings.removeInvalidHTML), removeCommentsIf(pasteCleanupSettings.removeHtmlComments))(dirtyHtml);
|
|
144
|
+
const clean = pasteCleanup(html, {
|
|
145
|
+
convertMsLists: pasteCleanupSettings.convertMsLists,
|
|
146
|
+
stripTags: pasteCleanupSettings.stripTags.join('|'),
|
|
147
|
+
attributes: getPasteCleanupAttributes(pasteCleanupSettings)
|
|
148
|
+
});
|
|
149
|
+
if (hasObservers(this.paste)) {
|
|
150
|
+
const event = new EditorPasteEvent(clean, dirtyHtml, this._pasteEvent);
|
|
151
|
+
this.ngZone.run(() => this.paste.emit(event));
|
|
152
|
+
return event.isDefaultPrevented() ? '' : event.cleanedHtml;
|
|
153
|
+
}
|
|
154
|
+
return clean;
|
|
155
|
+
};
|
|
156
|
+
this.changeValue = (value) => {
|
|
157
|
+
const prev = this._value;
|
|
158
|
+
this._value = value;
|
|
159
|
+
if (!this._view) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (this.htmlOnChange === value && this.trOnChange) {
|
|
163
|
+
this.view.updateState(this.view.state.apply(this.trOnChange));
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
if ((prev || '') !== (value || '')) {
|
|
167
|
+
const iframeContentWindowNotPresent = this.iframe && !this.container.element.nativeElement.contentWindow;
|
|
168
|
+
if (iframeContentWindowNotPresent) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const state = this.view.state;
|
|
172
|
+
const nextDoc = parseContent(value || '', state.schema, { preserveWhitespace: this.preserveWhitespace });
|
|
173
|
+
const tr = state.tr
|
|
174
|
+
.setSelection(new AllSelection(state.doc))
|
|
175
|
+
.replaceSelectionWith(nextDoc);
|
|
176
|
+
this.view.updateState(state.apply(tr));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
this.trOnChange = null;
|
|
180
|
+
this.htmlOnChange = null;
|
|
181
|
+
};
|
|
182
|
+
this.onChangeCallback = (value) => {
|
|
183
|
+
this.changeValue(value);
|
|
184
|
+
};
|
|
125
185
|
this.onTouchedCallback = (_) => { }; // tslint:disable-line:no-empty
|
|
186
|
+
this.onPaste = (_view, nativeEvent) => {
|
|
187
|
+
this._pasteEvent = nativeEvent;
|
|
188
|
+
return false;
|
|
189
|
+
};
|
|
126
190
|
validatePackage(packageMetadata);
|
|
127
191
|
this.direction = localization.rtl ? 'rtl' : 'ltr';
|
|
128
192
|
// https://stackoverflow.com/questions/56572483/chrome-is-synchronously-handling-iframe-loading-whereas-firefox-handles-it-asyn
|
|
@@ -132,25 +196,12 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
132
196
|
* Sets the value of the Editor ([see example]({% slug overview_editor %}#toc-basic-usage)).
|
|
133
197
|
*/
|
|
134
198
|
set value(value) {
|
|
135
|
-
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
this._value = value;
|
|
139
|
-
this._previousValue = value;
|
|
140
|
-
if (this._view) {
|
|
141
|
-
const iframeContentWindowNotPresent = this.iframe && !this.container.element.nativeElement.contentWindow;
|
|
142
|
-
if (iframeContentWindowNotPresent) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
this.exec('setHTML', {
|
|
146
|
-
content: this._value || '',
|
|
147
|
-
parseOptions: {
|
|
148
|
-
preserveWhitespace: this.preserveWhitespace
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
199
|
+
this.changeValue(value);
|
|
152
200
|
}
|
|
153
201
|
get value() {
|
|
202
|
+
if (this.trOnChange) {
|
|
203
|
+
return this.htmlOnChange;
|
|
204
|
+
}
|
|
154
205
|
let value = this._view ? this.getSource() : this._value;
|
|
155
206
|
if (value === EMPTY_PARAGRAPH) {
|
|
156
207
|
return this._value ? '' : this._value;
|
|
@@ -340,6 +391,9 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
340
391
|
}
|
|
341
392
|
}
|
|
342
393
|
ngOnChanges(changes) {
|
|
394
|
+
if (changes.value && this.view) {
|
|
395
|
+
this.changeValue(changes.value.currentValue);
|
|
396
|
+
}
|
|
343
397
|
if (changes.iframe && !changes.iframe.isFirstChange()) {
|
|
344
398
|
this.ngZone.onStable.pipe(take(1)).subscribe(() => this.initialize());
|
|
345
399
|
}
|
|
@@ -425,8 +479,6 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
425
479
|
const command = editorCommands[commandName](attr);
|
|
426
480
|
// Executes a ProseMirror command.
|
|
427
481
|
command(this._view.state, this._view.dispatch, this._view);
|
|
428
|
-
// See the `dispatchTransaction` comments.
|
|
429
|
-
// this.stateChange.emit(updateToolBar(this.view));
|
|
430
482
|
}
|
|
431
483
|
/**
|
|
432
484
|
* Opens a dialog.
|
|
@@ -511,6 +563,7 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
511
563
|
* @hidden
|
|
512
564
|
*/
|
|
513
565
|
writeValue(value) {
|
|
566
|
+
this.inForm = true;
|
|
514
567
|
// To avoid confusion, non-existent values are always undefined.
|
|
515
568
|
this.value = value === null ? undefined : value;
|
|
516
569
|
}
|
|
@@ -538,7 +591,6 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
538
591
|
return;
|
|
539
592
|
}
|
|
540
593
|
const currentSchema = this.schema || schema;
|
|
541
|
-
const that = this;
|
|
542
594
|
const containerNativeElement = this.container.element.nativeElement;
|
|
543
595
|
const contentNode = parseContent((this.value || '').trim(), currentSchema, { preserveWhitespace: this.preserveWhitespace });
|
|
544
596
|
if (this.iframe) {
|
|
@@ -580,16 +632,13 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
580
632
|
}
|
|
581
633
|
})
|
|
582
634
|
}),
|
|
583
|
-
new Plugin({
|
|
584
|
-
key: new PluginKey('editor-filter-disabled-state'),
|
|
585
|
-
filterTransaction: () => !this.disabled
|
|
586
|
-
}),
|
|
587
635
|
history(),
|
|
588
636
|
keymap(buildListKeymap(currentSchema)),
|
|
589
637
|
keymap(buildKeymap(currentSchema, { applyToWord: this.applyToWord })),
|
|
590
638
|
keymap(baseKeymap),
|
|
591
639
|
gapCursor(),
|
|
592
|
-
imageResizing()
|
|
640
|
+
imageResizing(),
|
|
641
|
+
tableEditing()
|
|
593
642
|
];
|
|
594
643
|
if (this.placeholder) {
|
|
595
644
|
defaultPlugins.push(placeholder(this.placeholder));
|
|
@@ -609,31 +658,10 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
609
658
|
this._view = new EditorView({ mount: this.viewMountElement }, {
|
|
610
659
|
state,
|
|
611
660
|
editable: () => !this.readonly,
|
|
612
|
-
dispatchTransaction:
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
// When the user utilizes keyboard shortcuts—for example, `Ctrl`+`b`—
|
|
617
|
-
// `tr.docChanged` is `true` and the toolbar is not updated.
|
|
618
|
-
// A possible future solution is to move the keymaps to the service.
|
|
619
|
-
// if (!tr.docChanged) {
|
|
620
|
-
// that.stateChange.emit(updateToolBar(that.view));
|
|
621
|
-
// }
|
|
622
|
-
const value = that.value;
|
|
623
|
-
if (!hasSameMarkup(value, that._previousValue, this.state.schema)) {
|
|
624
|
-
that._previousValue = value;
|
|
625
|
-
that.ngZone.run(() => that.valueModified.next(value));
|
|
626
|
-
}
|
|
627
|
-
},
|
|
628
|
-
transformPastedHTML: (html) => {
|
|
629
|
-
const pasteCleanupSettings = Object.assign({}, defaultPasteCleanupSettings, this.pasteCleanupSettings);
|
|
630
|
-
const clean = pipe(removeCommentsIf(pasteCleanupSettings.removeHtmlComments), removeInvalidHTMLIf(pasteCleanupSettings.removeInvalidHTML))(html);
|
|
631
|
-
const attributes = getPasteCleanupAttributes(pasteCleanupSettings);
|
|
632
|
-
return pasteCleanup(clean, {
|
|
633
|
-
convertMsLists: pasteCleanupSettings.convertMsLists,
|
|
634
|
-
stripTags: pasteCleanupSettings.stripTags.join('|'),
|
|
635
|
-
attributes
|
|
636
|
-
});
|
|
661
|
+
dispatchTransaction: this.dispatchTransaction,
|
|
662
|
+
transformPastedHTML: this.transformPastedHTML,
|
|
663
|
+
handleDOMEvents: {
|
|
664
|
+
paste: this.onPaste
|
|
637
665
|
}
|
|
638
666
|
});
|
|
639
667
|
});
|
|
@@ -674,7 +702,7 @@ let EditorComponent = EditorComponent_1 = class EditorComponent {
|
|
|
674
702
|
this.cdr.detectChanges();
|
|
675
703
|
}
|
|
676
704
|
}));
|
|
677
|
-
this.subs.add(
|
|
705
|
+
this.subs.add(this.valueModified.subscribe((value) => {
|
|
678
706
|
this.onChangeCallback(value);
|
|
679
707
|
this.valueChange.emit(value);
|
|
680
708
|
this.cdr.markForCheck();
|
|
@@ -767,10 +795,6 @@ tslib_1.__decorate([
|
|
|
767
795
|
tslib_1.__metadata("design:type", String),
|
|
768
796
|
tslib_1.__metadata("design:paramtypes", [String])
|
|
769
797
|
], EditorComponent.prototype, "placeholder", null);
|
|
770
|
-
tslib_1.__decorate([
|
|
771
|
-
Input(),
|
|
772
|
-
tslib_1.__metadata("design:type", Number)
|
|
773
|
-
], EditorComponent.prototype, "updateInterval", void 0);
|
|
774
798
|
tslib_1.__decorate([
|
|
775
799
|
Input(),
|
|
776
800
|
tslib_1.__metadata("design:type", Object)
|
|
@@ -791,6 +815,10 @@ tslib_1.__decorate([
|
|
|
791
815
|
Output('focus'),
|
|
792
816
|
tslib_1.__metadata("design:type", EventEmitter)
|
|
793
817
|
], EditorComponent.prototype, "onFocus", void 0);
|
|
818
|
+
tslib_1.__decorate([
|
|
819
|
+
Output(),
|
|
820
|
+
tslib_1.__metadata("design:type", EventEmitter)
|
|
821
|
+
], EditorComponent.prototype, "paste", void 0);
|
|
794
822
|
tslib_1.__decorate([
|
|
795
823
|
Output('blur'),
|
|
796
824
|
tslib_1.__metadata("design:type", EventEmitter)
|
|
@@ -1038,7 +1066,7 @@ EditorComponent = EditorComponent_1 = tslib_1.__decorate([
|
|
|
1038
1066
|
<div *ngIf="!iframe" #content [attr.dir]="direction" class="k-editor-content"></div>
|
|
1039
1067
|
|
|
1040
1068
|
<div class="k-editor-content" *ngIf="iframe">
|
|
1041
|
-
<iframe #content frameborder="0" class="k-iframe" (load)="iframeOnLoad()"></iframe>
|
|
1069
|
+
<iframe #content srcdoc="<!DOCTYPE html>" frameborder="0" class="k-iframe" (load)="iframeOnLoad()"></iframe>
|
|
1042
1070
|
</div>
|
|
1043
1071
|
|
|
1044
1072
|
<ng-container #dialogsContainer></ng-container>
|