slate-angular 1.6.5 → 1.7.4

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.
@@ -2177,6 +2177,31 @@
2177
2177
  }
2178
2178
  this.cdr.markForCheck();
2179
2179
  };
2180
+ BaseLeafComponent.prototype.renderPlaceholder = function () {
2181
+ // issue-1: IME input was interrupted
2182
+ // issue-2: IME input focus jumping
2183
+ // Issue occurs when the span node of the placeholder is before the slateString span node
2184
+ if (this.context.leaf['placeholder']) {
2185
+ if (!this.placeholderElement) {
2186
+ this.placeholderElement = document.createElement('span');
2187
+ this.placeholderElement.innerText = this.context.leaf['placeholder'];
2188
+ this.placeholderElement.contentEditable = 'false';
2189
+ this.placeholderElement.setAttribute('data-slate-placeholder', 'true');
2190
+ this.nativeElement.classList.add('leaf-with-placeholder');
2191
+ this.nativeElement.appendChild(this.placeholderElement);
2192
+ }
2193
+ }
2194
+ else {
2195
+ this.destroyPlaceholder();
2196
+ }
2197
+ };
2198
+ BaseLeafComponent.prototype.destroyPlaceholder = function () {
2199
+ if (this.placeholderElement) {
2200
+ this.placeholderElement.remove();
2201
+ this.placeholderElement = null;
2202
+ this.nativeElement.classList.remove('leaf-with-placeholder');
2203
+ }
2204
+ };
2180
2205
  return BaseLeafComponent;
2181
2206
  }(BaseComponent));
2182
2207
  BaseLeafComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: BaseLeafComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Directive });
@@ -2295,7 +2320,7 @@
2295
2320
  }
2296
2321
  Object.defineProperty(BaseTextComponent.prototype, "text", {
2297
2322
  get: function () {
2298
- return this._context.text;
2323
+ return this._context && this._context.text;
2299
2324
  },
2300
2325
  enumerable: false,
2301
2326
  configurable: true
@@ -2346,7 +2371,6 @@
2346
2371
  // first diff
2347
2372
  differ.diff(this.childrenComponent);
2348
2373
  var parentElement = this.elementRef.nativeElement.parentElement;
2349
- var firstChildComponent = this.childrenComponent.first;
2350
2374
  if (this.childrenComponent.length > 0) {
2351
2375
  parentElement.insertBefore(this.createFragment(), this.elementRef.nativeElement);
2352
2376
  this.elementRef.nativeElement.remove();
@@ -2354,41 +2378,15 @@
2354
2378
  this.childrenComponent.changes.subscribe(function (value) {
2355
2379
  var iterableChanges = differ.diff(_this.childrenComponent);
2356
2380
  if (iterableChanges) {
2357
- iterableChanges.forEachAddedItem(function (record) {
2358
- // first insert
2359
- if (_this.elementRef.nativeElement.parentElement && _this.elementRef.nativeElement.parentElement === parentElement) {
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();
2381
+ iterableChanges.forEachOperation(function (record, previousIndex, currentIndex) {
2382
+ // removed
2383
+ if (currentIndex === null) {
2364
2384
  return;
2365
2385
  }
2366
- // insert at start location
2367
- if (record.currentIndex === 0 && firstChildComponent) {
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
- }
2386
+ // added or moved
2387
+ _this.handleContainerItemChange(record, parentElement);
2389
2388
  });
2390
2389
  }
2391
- firstChildComponent = _this.childrenComponent.first;
2392
2390
  });
2393
2391
  };
2394
2392
  ViewContainer.prototype.getPreviousRootNode = function (currentIndex) {
@@ -2411,6 +2409,39 @@
2411
2409
  });
2412
2410
  return fragment;
2413
2411
  };
2412
+ ViewContainer.prototype.handleContainerItemChange = function (record, parentElement) {
2413
+ // first insert
2414
+ if (this.elementRef.nativeElement.parentElement && this.elementRef.nativeElement.parentElement === parentElement) {
2415
+ var fragment = document.createDocumentFragment();
2416
+ fragment.append.apply(fragment, __spreadArray([], __read(record.item.rootNodes)));
2417
+ parentElement.insertBefore(fragment, this.elementRef.nativeElement);
2418
+ this.elementRef.nativeElement.remove();
2419
+ return;
2420
+ }
2421
+ // insert at start location
2422
+ if (record.currentIndex === 0) {
2423
+ var fragment = document.createDocumentFragment();
2424
+ fragment.append.apply(fragment, __spreadArray([], __read(record.item.rootNodes)));
2425
+ parentElement.prepend(fragment);
2426
+ }
2427
+ else {
2428
+ // insert afterend of previous component end
2429
+ var previousRootNode_1 = this.getPreviousRootNode(record.currentIndex);
2430
+ if (previousRootNode_1) {
2431
+ record.item.rootNodes.forEach(function (rootNode) {
2432
+ previousRootNode_1.insertAdjacentElement('afterend', rootNode);
2433
+ previousRootNode_1 = rootNode;
2434
+ });
2435
+ }
2436
+ else {
2437
+ this.viewContext.editor.onError({
2438
+ code: exports.SlateErrorCode.NotFoundPreviousRootNodeError,
2439
+ name: 'not found previous rootNode',
2440
+ nativeError: null
2441
+ });
2442
+ }
2443
+ }
2444
+ };
2414
2445
  return ViewContainer;
2415
2446
  }());
2416
2447
  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 });
@@ -2497,6 +2528,14 @@
2497
2528
  function SlateDefaultLeafComponent() {
2498
2529
  return _super !== null && _super.apply(this, arguments) || this;
2499
2530
  }
2531
+ SlateDefaultLeafComponent.prototype.onContextChange = function () {
2532
+ _super.prototype.onContextChange.call(this);
2533
+ this.renderPlaceholder();
2534
+ };
2535
+ SlateDefaultLeafComponent.prototype.ngOnDestroy = function () {
2536
+ // Because the placeholder span is not in the current component, it is destroyed along with the current component
2537
+ this.destroyPlaceholder();
2538
+ };
2500
2539
  return SlateDefaultLeafComponent;
2501
2540
  }(BaseLeafComponent));
2502
2541
  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 });
@@ -3022,6 +3061,7 @@
3022
3061
  });
3023
3062
  this.editor.children = normalize(value);
3024
3063
  }
3064
+ this.initializeContext();
3025
3065
  this.cdr.markForCheck();
3026
3066
  }
3027
3067
  };
@@ -3140,7 +3180,7 @@
3140
3180
  // need exec after this.cdr.detectChanges() to render HTML
3141
3181
  // need exec before this.toNativeSelection() to correct native selection
3142
3182
  if (this.isComposing) {
3143
- // Compposition input text be not rendered when user composition input with selection is expanded
3183
+ // Composition input text be not rendered when user composition input with selection is expanded
3144
3184
  // At this time, the following matching conditions are met, assign isComposing to false, and the status is wrong
3145
3185
  // this time condition is true and isComposiing is assigned false
3146
3186
  // Therefore, need to wait for the composition input text to be rendered before performing condition matching
@@ -3173,7 +3213,7 @@
3173
3213
  this.context = {
3174
3214
  parent: this.editor,
3175
3215
  selection: this.editor.selection,
3176
- decorations: this.decorate([this.editor, []]),
3216
+ decorations: this.generateDecorations(),
3177
3217
  decorate: this.decorate,
3178
3218
  readonly: this.readonly
3179
3219
  };
@@ -3190,20 +3230,49 @@
3190
3230
  };
3191
3231
  };
3192
3232
  SlateEditableComponent.prototype.detectContext = function () {
3233
+ var decorations = this.generateDecorations();
3193
3234
  if (this.context.selection !== this.editor.selection ||
3194
3235
  this.context.decorate !== this.decorate ||
3195
- this.context.readonly !== this.readonly) {
3196
- var decorations = this.decorate([this.editor, []]);
3197
- var isSameDecorations = isDecoratorRangeListEqual(this.context.decorations, decorations);
3236
+ this.context.readonly !== this.readonly ||
3237
+ !isDecoratorRangeListEqual(this.context.decorations, decorations)) {
3198
3238
  this.context = {
3199
3239
  parent: this.editor,
3200
3240
  selection: this.editor.selection,
3201
- decorations: isSameDecorations ? this.context.decorations : decorations,
3241
+ decorations: decorations,
3202
3242
  decorate: this.decorate,
3203
3243
  readonly: this.readonly
3204
3244
  };
3205
3245
  }
3206
3246
  };
3247
+ SlateEditableComponent.prototype.composePlaceholderDecorate = function (editor) {
3248
+ if (this.placeholderDecorate) {
3249
+ return this.placeholderDecorate(editor) || [];
3250
+ }
3251
+ if (this.placeholder &&
3252
+ editor.children.length === 1 &&
3253
+ Array.from(slate.Node.texts(editor)).length === 1 &&
3254
+ slate.Node.string(editor) === '') {
3255
+ var start = slate.Editor.start(editor, []);
3256
+ return [
3257
+ {
3258
+ placeholder: this.placeholder,
3259
+ anchor: start,
3260
+ focus: start,
3261
+ },
3262
+ ];
3263
+ }
3264
+ else {
3265
+ return [];
3266
+ }
3267
+ };
3268
+ SlateEditableComponent.prototype.generateDecorations = function () {
3269
+ var decorations = this.decorate([this.editor, []]);
3270
+ var placeholderDecorations = this.isComposing
3271
+ ? []
3272
+ : this.composePlaceholderDecorate(this.editor);
3273
+ decorations.push.apply(decorations, __spreadArray([], __read(placeholderDecorations)));
3274
+ return decorations;
3275
+ };
3207
3276
  //#region event proxy
3208
3277
  SlateEditableComponent.prototype.addEventListener = function (eventName, listener, target) {
3209
3278
  var _this = this;
@@ -3424,6 +3493,8 @@
3424
3493
  // so we need avoid repeat isnertText by isComposing === true,
3425
3494
  this.isComposing = false;
3426
3495
  }
3496
+ this.detectContext();
3497
+ this.cdr.detectChanges();
3427
3498
  };
3428
3499
  SlateEditableComponent.prototype.onDOMCompositionStart = function (event) {
3429
3500
  var selection = this.editor.selection;
@@ -3437,6 +3508,8 @@
3437
3508
  if (hasEditableTarget(this.editor, event.target) && !this.isDOMEventHandled(event, this.compositionStart)) {
3438
3509
  this.isComposing = true;
3439
3510
  }
3511
+ this.detectContext();
3512
+ this.cdr.detectChanges();
3440
3513
  };
3441
3514
  SlateEditableComponent.prototype.onDOMCopy = function (event) {
3442
3515
  var window = AngularEditor.getWindow(this.editor);
@@ -3706,6 +3779,25 @@
3706
3779
  return;
3707
3780
  }
3708
3781
  }
3782
+ else {
3783
+ if (IS_CHROME || IS_SAFARI) {
3784
+ // COMPAT: Chrome and Safari support `beforeinput` event but do not fire
3785
+ // an event when deleting backwards in a selected void inline node
3786
+ if (selection &&
3787
+ (hotkeys.isDeleteBackward(nativeEvent) ||
3788
+ hotkeys.isDeleteForward(nativeEvent)) &&
3789
+ slate.Range.isCollapsed(selection)) {
3790
+ var currentNode = slate.Node.parent(editor, selection.anchor.path);
3791
+ if (slate.Element.isElement(currentNode) &&
3792
+ slate.Editor.isVoid(editor, currentNode) &&
3793
+ slate.Editor.isInline(editor, currentNode)) {
3794
+ event.preventDefault();
3795
+ slate.Editor.deleteBackward(editor, { unit: 'block' });
3796
+ return;
3797
+ }
3798
+ }
3799
+ }
3800
+ }
3709
3801
  }
3710
3802
  catch (error) {
3711
3803
  this.editor.onError({ code: exports.SlateErrorCode.OnDOMKeydownError, nativeError: error });
@@ -3740,7 +3832,7 @@
3740
3832
  if (!slate.Range.isCollapsed(this.editor.selection)) {
3741
3833
  slate.Editor.deleteFragment(this.editor);
3742
3834
  }
3743
- // just handle Non-IME input
3835
+ // just handle Non-IME input
3744
3836
  if (!this.isComposing) {
3745
3837
  slate.Editor.insertText(this.editor, text);
3746
3838
  }
@@ -3769,11 +3861,11 @@
3769
3861
  return SlateEditableComponent;
3770
3862
  }());
3771
3863
  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: [{
3864
+ 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
3865
  provide: forms.NG_VALUE_ACCESSOR,
3774
3866
  useExisting: i0.forwardRef(function () { return SlateEditableComponent; }),
3775
3867
  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\" [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 });
3868
+ }], 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
3869
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateEditableComponent, decorators: [{
3778
3870
  type: i0.Component,
3779
3871
  args: [{
@@ -3804,12 +3896,16 @@
3804
3896
  type: i0.Input
3805
3897
  }], decorate: [{
3806
3898
  type: i0.Input
3899
+ }], placeholderDecorate: [{
3900
+ type: i0.Input
3807
3901
  }], isStrictDecorate: [{
3808
3902
  type: i0.Input
3809
3903
  }], trackBy: [{
3810
3904
  type: i0.Input
3811
3905
  }], readonly: [{
3812
3906
  type: i0.Input
3907
+ }], placeholder: [{
3908
+ type: i0.Input
3813
3909
  }], beforeInput: [{
3814
3910
  type: i0.Input
3815
3911
  }], blur: [{