slate-angular 1.6.5 → 1.7.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/bundles/slate-angular.umd.js +99 -42
- package/bundles/slate-angular.umd.js.map +1 -1
- package/components/editable/editable.component.d.ts +6 -2
- package/esm2015/components/editable/editable.component.js +60 -10
- package/esm2015/components/leaf/default-leaf.component.js +12 -3
- package/esm2015/types/feature.js +2 -0
- package/esm2015/types/index.js +2 -1
- package/esm2015/view/container.js +39 -33
- package/fesm2015/slate-angular.js +106 -42
- package/fesm2015/slate-angular.js.map +1 -1
- package/package.json +1 -1
- package/styles/index.scss +10 -0
- package/types/feature.d.ts +4 -0
- package/types/index.d.ts +1 -0
- package/view/container.d.ts +2 -1
|
@@ -2346,7 +2346,6 @@
|
|
|
2346
2346
|
// first diff
|
|
2347
2347
|
differ.diff(this.childrenComponent);
|
|
2348
2348
|
var parentElement = this.elementRef.nativeElement.parentElement;
|
|
2349
|
-
var firstChildComponent = this.childrenComponent.first;
|
|
2350
2349
|
if (this.childrenComponent.length > 0) {
|
|
2351
2350
|
parentElement.insertBefore(this.createFragment(), this.elementRef.nativeElement);
|
|
2352
2351
|
this.elementRef.nativeElement.remove();
|
|
@@ -2354,41 +2353,15 @@
|
|
|
2354
2353
|
this.childrenComponent.changes.subscribe(function (value) {
|
|
2355
2354
|
var iterableChanges = differ.diff(_this.childrenComponent);
|
|
2356
2355
|
if (iterableChanges) {
|
|
2357
|
-
iterableChanges.
|
|
2358
|
-
//
|
|
2359
|
-
if (
|
|
2360
|
-
var fragment = document.createDocumentFragment();
|
|
2361
|
-
fragment.append.apply(fragment, __spreadArray([], __read(record.item.rootNodes)));
|
|
2362
|
-
parentElement.insertBefore(fragment, _this.elementRef.nativeElement);
|
|
2363
|
-
_this.elementRef.nativeElement.remove();
|
|
2356
|
+
iterableChanges.forEachOperation(function (record, previousIndex, currentIndex) {
|
|
2357
|
+
// removed
|
|
2358
|
+
if (currentIndex === null) {
|
|
2364
2359
|
return;
|
|
2365
2360
|
}
|
|
2366
|
-
//
|
|
2367
|
-
|
|
2368
|
-
var fragment = document.createDocumentFragment();
|
|
2369
|
-
fragment.append.apply(fragment, __spreadArray([], __read(record.item.rootNodes)));
|
|
2370
|
-
parentElement.prepend(fragment);
|
|
2371
|
-
}
|
|
2372
|
-
else {
|
|
2373
|
-
// insert afterend of previous component end
|
|
2374
|
-
var previousRootNode_1 = _this.getPreviousRootNode(record.currentIndex);
|
|
2375
|
-
if (previousRootNode_1) {
|
|
2376
|
-
record.item.rootNodes.forEach(function (rootNode) {
|
|
2377
|
-
previousRootNode_1.insertAdjacentElement('afterend', rootNode);
|
|
2378
|
-
previousRootNode_1 = rootNode;
|
|
2379
|
-
});
|
|
2380
|
-
}
|
|
2381
|
-
else {
|
|
2382
|
-
_this.viewContext.editor.onError({
|
|
2383
|
-
code: exports.SlateErrorCode.NotFoundPreviousRootNodeError,
|
|
2384
|
-
name: 'not found previous rootNode',
|
|
2385
|
-
nativeError: null
|
|
2386
|
-
});
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2361
|
+
// added or moved
|
|
2362
|
+
_this.handleContainerItemChange(record, parentElement);
|
|
2389
2363
|
});
|
|
2390
2364
|
}
|
|
2391
|
-
firstChildComponent = _this.childrenComponent.first;
|
|
2392
2365
|
});
|
|
2393
2366
|
};
|
|
2394
2367
|
ViewContainer.prototype.getPreviousRootNode = function (currentIndex) {
|
|
@@ -2411,6 +2384,39 @@
|
|
|
2411
2384
|
});
|
|
2412
2385
|
return fragment;
|
|
2413
2386
|
};
|
|
2387
|
+
ViewContainer.prototype.handleContainerItemChange = function (record, parentElement) {
|
|
2388
|
+
// first insert
|
|
2389
|
+
if (this.elementRef.nativeElement.parentElement && this.elementRef.nativeElement.parentElement === parentElement) {
|
|
2390
|
+
var fragment = document.createDocumentFragment();
|
|
2391
|
+
fragment.append.apply(fragment, __spreadArray([], __read(record.item.rootNodes)));
|
|
2392
|
+
parentElement.insertBefore(fragment, this.elementRef.nativeElement);
|
|
2393
|
+
this.elementRef.nativeElement.remove();
|
|
2394
|
+
return;
|
|
2395
|
+
}
|
|
2396
|
+
// insert at start location
|
|
2397
|
+
if (record.currentIndex === 0) {
|
|
2398
|
+
var fragment = document.createDocumentFragment();
|
|
2399
|
+
fragment.append.apply(fragment, __spreadArray([], __read(record.item.rootNodes)));
|
|
2400
|
+
parentElement.prepend(fragment);
|
|
2401
|
+
}
|
|
2402
|
+
else {
|
|
2403
|
+
// insert afterend of previous component end
|
|
2404
|
+
var previousRootNode_1 = this.getPreviousRootNode(record.currentIndex);
|
|
2405
|
+
if (previousRootNode_1) {
|
|
2406
|
+
record.item.rootNodes.forEach(function (rootNode) {
|
|
2407
|
+
previousRootNode_1.insertAdjacentElement('afterend', rootNode);
|
|
2408
|
+
previousRootNode_1 = rootNode;
|
|
2409
|
+
});
|
|
2410
|
+
}
|
|
2411
|
+
else {
|
|
2412
|
+
this.viewContext.editor.onError({
|
|
2413
|
+
code: exports.SlateErrorCode.NotFoundPreviousRootNodeError,
|
|
2414
|
+
name: 'not found previous rootNode',
|
|
2415
|
+
nativeError: null
|
|
2416
|
+
});
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
};
|
|
2414
2420
|
return ViewContainer;
|
|
2415
2421
|
}());
|
|
2416
2422
|
ViewContainer.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: ViewContainer, deps: [{ token: i0__namespace.ElementRef }, { token: i0__namespace.IterableDiffers }], target: i0__namespace.ɵɵFactoryTarget.Directive });
|
|
@@ -2500,12 +2506,12 @@
|
|
|
2500
2506
|
return SlateDefaultLeafComponent;
|
|
2501
2507
|
}(BaseLeafComponent));
|
|
2502
2508
|
SlateDefaultLeafComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateDefaultLeafComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Component });
|
|
2503
|
-
SlateDefaultLeafComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateDefaultLeafComponent, selector: "span[slateDefaultLeaf]", host: { attributes: { "data-slate-leaf": "true" } }, usesInheritance: true, ngImport: i0__namespace, template: "<span slateString [context]=\"context\" [viewContext]=\"viewContext\"><span>", isInline: true, components: [{ type: SlateStringComponent, selector: "span[slateString]", inputs: ["context"] }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
|
|
2509
|
+
SlateDefaultLeafComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateDefaultLeafComponent, selector: "span[slateDefaultLeaf]", host: { attributes: { "data-slate-leaf": "true" } }, usesInheritance: true, ngImport: i0__namespace, template: "\n <ng-container *ngIf=\"context.leaf['placeholder']\">\n <span contenteditable=\"false\" data-slate-placeholder=\"true\" slate-placeholder=\"true\">{{context.leaf['placeholder']}}</span>\n </ng-container>\n <span slateString [context]=\"context\" [viewContext]=\"viewContext\"><span>", isInline: true, components: [{ type: SlateStringComponent, selector: "span[slateString]", inputs: ["context"] }], directives: [{ type: i2__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
|
|
2504
2510
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateDefaultLeafComponent, decorators: [{
|
|
2505
2511
|
type: i0.Component,
|
|
2506
2512
|
args: [{
|
|
2507
2513
|
selector: 'span[slateDefaultLeaf]',
|
|
2508
|
-
template: "<span slateString [context]=\"context\" [viewContext]=\"viewContext\"><span>",
|
|
2514
|
+
template: "\n <ng-container *ngIf=\"context.leaf['placeholder']\">\n <span contenteditable=\"false\" data-slate-placeholder=\"true\" slate-placeholder=\"true\">{{context.leaf['placeholder']}}</span>\n </ng-container>\n <span slateString [context]=\"context\" [viewContext]=\"viewContext\"><span>",
|
|
2509
2515
|
changeDetection: i0.ChangeDetectionStrategy.OnPush,
|
|
2510
2516
|
host: {
|
|
2511
2517
|
'data-slate-leaf': 'true'
|
|
@@ -2932,6 +2938,7 @@
|
|
|
2932
2938
|
var forceOnDOMPaste = IS_SAFARI;
|
|
2933
2939
|
var SlateEditableComponent = /** @class */ (function () {
|
|
2934
2940
|
function SlateEditableComponent(elementRef, renderer2, cdr, ngZone, injector) {
|
|
2941
|
+
var _this = this;
|
|
2935
2942
|
this.elementRef = elementRef;
|
|
2936
2943
|
this.renderer2 = renderer2;
|
|
2937
2944
|
this.cdr = cdr;
|
|
@@ -2946,6 +2953,22 @@
|
|
|
2946
2953
|
this.onTouchedCallback = function () { };
|
|
2947
2954
|
this.onChangeCallback = function () { };
|
|
2948
2955
|
this.decorate = function () { return []; };
|
|
2956
|
+
this.placeholderDecorate = function (editor) {
|
|
2957
|
+
if (_this.placeholder &&
|
|
2958
|
+
editor.children.length === 1 &&
|
|
2959
|
+
Array.from(slate.Node.texts(editor)).length === 1 &&
|
|
2960
|
+
slate.Node.string(editor) === '') {
|
|
2961
|
+
var start = slate.Editor.start(editor, []);
|
|
2962
|
+
return [{
|
|
2963
|
+
placeholder: _this.placeholder,
|
|
2964
|
+
anchor: start,
|
|
2965
|
+
focus: start
|
|
2966
|
+
}];
|
|
2967
|
+
}
|
|
2968
|
+
else {
|
|
2969
|
+
return [];
|
|
2970
|
+
}
|
|
2971
|
+
};
|
|
2949
2972
|
this.isStrictDecorate = true;
|
|
2950
2973
|
this.trackBy = function () { return null; };
|
|
2951
2974
|
this.readonly = false;
|
|
@@ -3022,6 +3045,7 @@
|
|
|
3022
3045
|
});
|
|
3023
3046
|
this.editor.children = normalize(value);
|
|
3024
3047
|
}
|
|
3048
|
+
this.initializeContext();
|
|
3025
3049
|
this.cdr.markForCheck();
|
|
3026
3050
|
}
|
|
3027
3051
|
};
|
|
@@ -3140,7 +3164,7 @@
|
|
|
3140
3164
|
// need exec after this.cdr.detectChanges() to render HTML
|
|
3141
3165
|
// need exec before this.toNativeSelection() to correct native selection
|
|
3142
3166
|
if (this.isComposing) {
|
|
3143
|
-
//
|
|
3167
|
+
// Composition input text be not rendered when user composition input with selection is expanded
|
|
3144
3168
|
// At this time, the following matching conditions are met, assign isComposing to false, and the status is wrong
|
|
3145
3169
|
// this time condition is true and isComposiing is assigned false
|
|
3146
3170
|
// Therefore, need to wait for the composition input text to be rendered before performing condition matching
|
|
@@ -3173,7 +3197,7 @@
|
|
|
3173
3197
|
this.context = {
|
|
3174
3198
|
parent: this.editor,
|
|
3175
3199
|
selection: this.editor.selection,
|
|
3176
|
-
decorations: this.
|
|
3200
|
+
decorations: this.generateDecorations(),
|
|
3177
3201
|
decorate: this.decorate,
|
|
3178
3202
|
readonly: this.readonly
|
|
3179
3203
|
};
|
|
@@ -3190,20 +3214,26 @@
|
|
|
3190
3214
|
};
|
|
3191
3215
|
};
|
|
3192
3216
|
SlateEditableComponent.prototype.detectContext = function () {
|
|
3217
|
+
var decorations = this.generateDecorations();
|
|
3193
3218
|
if (this.context.selection !== this.editor.selection ||
|
|
3194
3219
|
this.context.decorate !== this.decorate ||
|
|
3195
|
-
this.context.readonly !== this.readonly
|
|
3196
|
-
|
|
3197
|
-
var isSameDecorations = isDecoratorRangeListEqual(this.context.decorations, decorations);
|
|
3220
|
+
this.context.readonly !== this.readonly ||
|
|
3221
|
+
!isDecoratorRangeListEqual(this.context.decorations, decorations)) {
|
|
3198
3222
|
this.context = {
|
|
3199
3223
|
parent: this.editor,
|
|
3200
3224
|
selection: this.editor.selection,
|
|
3201
|
-
decorations:
|
|
3225
|
+
decorations: decorations,
|
|
3202
3226
|
decorate: this.decorate,
|
|
3203
3227
|
readonly: this.readonly
|
|
3204
3228
|
};
|
|
3205
3229
|
}
|
|
3206
3230
|
};
|
|
3231
|
+
SlateEditableComponent.prototype.generateDecorations = function () {
|
|
3232
|
+
var decorations = this.decorate([this.editor, []]);
|
|
3233
|
+
var placeholderDecorations = this.isComposing ? [] : this.placeholderDecorate(this.editor);
|
|
3234
|
+
decorations.push.apply(decorations, __spreadArray([], __read(placeholderDecorations)));
|
|
3235
|
+
return decorations;
|
|
3236
|
+
};
|
|
3207
3237
|
//#region event proxy
|
|
3208
3238
|
SlateEditableComponent.prototype.addEventListener = function (eventName, listener, target) {
|
|
3209
3239
|
var _this = this;
|
|
@@ -3424,6 +3454,8 @@
|
|
|
3424
3454
|
// so we need avoid repeat isnertText by isComposing === true,
|
|
3425
3455
|
this.isComposing = false;
|
|
3426
3456
|
}
|
|
3457
|
+
this.detectContext();
|
|
3458
|
+
this.cdr.detectChanges();
|
|
3427
3459
|
};
|
|
3428
3460
|
SlateEditableComponent.prototype.onDOMCompositionStart = function (event) {
|
|
3429
3461
|
var selection = this.editor.selection;
|
|
@@ -3437,6 +3469,8 @@
|
|
|
3437
3469
|
if (hasEditableTarget(this.editor, event.target) && !this.isDOMEventHandled(event, this.compositionStart)) {
|
|
3438
3470
|
this.isComposing = true;
|
|
3439
3471
|
}
|
|
3472
|
+
this.detectContext();
|
|
3473
|
+
this.cdr.detectChanges();
|
|
3440
3474
|
};
|
|
3441
3475
|
SlateEditableComponent.prototype.onDOMCopy = function (event) {
|
|
3442
3476
|
var window = AngularEditor.getWindow(this.editor);
|
|
@@ -3706,6 +3740,25 @@
|
|
|
3706
3740
|
return;
|
|
3707
3741
|
}
|
|
3708
3742
|
}
|
|
3743
|
+
else {
|
|
3744
|
+
if (IS_CHROME || IS_SAFARI) {
|
|
3745
|
+
// COMPAT: Chrome and Safari support `beforeinput` event but do not fire
|
|
3746
|
+
// an event when deleting backwards in a selected void inline node
|
|
3747
|
+
if (selection &&
|
|
3748
|
+
(hotkeys.isDeleteBackward(nativeEvent) ||
|
|
3749
|
+
hotkeys.isDeleteForward(nativeEvent)) &&
|
|
3750
|
+
slate.Range.isCollapsed(selection)) {
|
|
3751
|
+
var currentNode = slate.Node.parent(editor, selection.anchor.path);
|
|
3752
|
+
if (slate.Element.isElement(currentNode) &&
|
|
3753
|
+
slate.Editor.isVoid(editor, currentNode) &&
|
|
3754
|
+
slate.Editor.isInline(editor, currentNode)) {
|
|
3755
|
+
event.preventDefault();
|
|
3756
|
+
slate.Editor.deleteBackward(editor, { unit: 'block' });
|
|
3757
|
+
return;
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3709
3762
|
}
|
|
3710
3763
|
catch (error) {
|
|
3711
3764
|
this.editor.onError({ code: exports.SlateErrorCode.OnDOMKeydownError, nativeError: error });
|
|
@@ -3769,11 +3822,11 @@
|
|
|
3769
3822
|
return SlateEditableComponent;
|
|
3770
3823
|
}());
|
|
3771
3824
|
SlateEditableComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateEditableComponent, deps: [{ token: i0__namespace.ElementRef }, { token: i0__namespace.Renderer2 }, { token: i0__namespace.ChangeDetectorRef }, { token: i0__namespace.NgZone }, { token: i0__namespace.Injector }], target: i0__namespace.ɵɵFactoryTarget.Component });
|
|
3772
|
-
SlateEditableComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateEditableComponent, selector: "slate-editable", inputs: { editor: "editor", renderElement: "renderElement", renderLeaf: "renderLeaf", renderText: "renderText", decorate: "decorate", isStrictDecorate: "isStrictDecorate", trackBy: "trackBy", readonly: "readonly", beforeInput: "beforeInput", blur: "blur", click: "click", compositionEnd: "compositionEnd", compositionStart: "compositionStart", copy: "copy", cut: "cut", dragOver: "dragOver", dragStart: "dragStart", dragEnd: "dragEnd", drop: "drop", focus: "focus", keydown: "keydown", paste: "paste", spellCheck: "spellCheck", autoCorrect: "autoCorrect", autoCapitalize: "autoCapitalize" }, host: { properties: { "attr.contenteditable": "readonly ? undefined : true", "attr.role": "readonly ? undefined : 'textbox'", "attr.spellCheck": "!hasBeforeInputSupport ? false : spellCheck", "attr.autoCorrect": "!hasBeforeInputSupport ? 'false' : autoCorrect", "attr.autoCapitalize": "!hasBeforeInputSupport ? 'false' : autoCapitalize", "attr.data-slate-editor": "this.dataSlateEditor", "attr.data-slate-node": "this.dataSlateNode", "attr.data-gramm": "this.dataGramm" }, classAttribute: "slate-editable-container" }, providers: [{
|
|
3825
|
+
SlateEditableComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateEditableComponent, selector: "slate-editable", inputs: { editor: "editor", renderElement: "renderElement", renderLeaf: "renderLeaf", renderText: "renderText", decorate: "decorate", placeholderDecorate: "placeholderDecorate", isStrictDecorate: "isStrictDecorate", trackBy: "trackBy", readonly: "readonly", placeholder: "placeholder", beforeInput: "beforeInput", blur: "blur", click: "click", compositionEnd: "compositionEnd", compositionStart: "compositionStart", copy: "copy", cut: "cut", dragOver: "dragOver", dragStart: "dragStart", dragEnd: "dragEnd", drop: "drop", focus: "focus", keydown: "keydown", paste: "paste", spellCheck: "spellCheck", autoCorrect: "autoCorrect", autoCapitalize: "autoCapitalize" }, host: { properties: { "attr.contenteditable": "readonly ? undefined : true", "attr.role": "readonly ? undefined : 'textbox'", "attr.spellCheck": "!hasBeforeInputSupport ? false : spellCheck", "attr.autoCorrect": "!hasBeforeInputSupport ? 'false' : autoCorrect", "attr.autoCapitalize": "!hasBeforeInputSupport ? 'false' : autoCapitalize", "attr.data-slate-editor": "this.dataSlateEditor", "attr.data-slate-node": "this.dataSlateNode", "attr.data-gramm": "this.dataGramm" }, classAttribute: "slate-editable-container" }, providers: [{
|
|
3773
3826
|
provide: forms.NG_VALUE_ACCESSOR,
|
|
3774
3827
|
useExisting: i0.forwardRef(function () { return SlateEditableComponent; }),
|
|
3775
3828
|
multi: true
|
|
3776
|
-
}], viewQueries: [{ propertyName: "templateComponent", first: true, predicate: ["templateComponent"], descendants: true, static: true }, { propertyName: "templateElementRef", first: true, predicate: ["templateComponent"], descendants: true, read: i0.ElementRef, static: true }], usesOnChanges: true, ngImport: i0__namespace, template: "<slate-children [children]=\"editor.children\" [context]=\"context\" [viewContext]=\"viewContext\"
|
|
3829
|
+
}], viewQueries: [{ propertyName: "templateComponent", first: true, predicate: ["templateComponent"], descendants: true, static: true }, { propertyName: "templateElementRef", first: true, predicate: ["templateComponent"], descendants: true, read: i0.ElementRef, static: true }], usesOnChanges: true, ngImport: i0__namespace, template: "<slate-children [children]=\"editor.children\" [context]=\"context\" [viewContext]=\"viewContext\"></slate-children>\n<slate-string-template #templateComponent></slate-string-template>", components: [{ type: SlateChildrenComponent, selector: "slate-children", inputs: ["children", "context", "viewContext"] }, { type: SlateStringTemplateComponent, selector: "slate-string-template" }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
|
|
3777
3830
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateEditableComponent, decorators: [{
|
|
3778
3831
|
type: i0.Component,
|
|
3779
3832
|
args: [{
|
|
@@ -3804,12 +3857,16 @@
|
|
|
3804
3857
|
type: i0.Input
|
|
3805
3858
|
}], decorate: [{
|
|
3806
3859
|
type: i0.Input
|
|
3860
|
+
}], placeholderDecorate: [{
|
|
3861
|
+
type: i0.Input
|
|
3807
3862
|
}], isStrictDecorate: [{
|
|
3808
3863
|
type: i0.Input
|
|
3809
3864
|
}], trackBy: [{
|
|
3810
3865
|
type: i0.Input
|
|
3811
3866
|
}], readonly: [{
|
|
3812
3867
|
type: i0.Input
|
|
3868
|
+
}], placeholder: [{
|
|
3869
|
+
type: i0.Input
|
|
3813
3870
|
}], beforeInput: [{
|
|
3814
3871
|
type: i0.Input
|
|
3815
3872
|
}], blur: [{
|