slate-angular 15.1.0-next.1 → 15.1.0-next.2

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.
@@ -3,6 +3,7 @@ import { isKeyHotkey } from 'is-hotkey';
3
3
  import * as i0 from '@angular/core';
4
4
  import { TemplateRef, Component, ChangeDetectionStrategy, ViewChild, Directive, Input, HostBinding, ViewChildren, InjectionToken, Inject, forwardRef, ElementRef, NgModule } from '@angular/core';
5
5
  import getDirection from 'direction';
6
+ import scrollIntoView from 'scroll-into-view-if-needed';
6
7
  import { Subject } from 'rxjs';
7
8
  import { NG_VALUE_ACCESSOR } from '@angular/forms';
8
9
  import { HistoryEditor } from 'slate-history';
@@ -2601,6 +2602,7 @@ class SlateEditableComponent {
2601
2602
  this.onTouchedCallback = () => { };
2602
2603
  this.onChangeCallback = () => { };
2603
2604
  this.decorate = () => [];
2605
+ this.scrollSelectionIntoView = defaultScrollSelectionIntoView;
2604
2606
  this.isStrictDecorate = true;
2605
2607
  this.trackBy = () => null;
2606
2608
  this.readonly = false;
@@ -2766,6 +2768,7 @@ class SlateEditableComponent {
2766
2768
  else {
2767
2769
  domSelection.removeAllRanges();
2768
2770
  }
2771
+ this.scrollSelectionIntoView(this.editor, newDomRange);
2769
2772
  setTimeout(() => {
2770
2773
  // COMPAT: In Firefox, it's not enough to create a range, you also need
2771
2774
  // to focus the contenteditable element too. (2016/11/16)
@@ -3567,7 +3570,7 @@ class SlateEditableComponent {
3567
3570
  }
3568
3571
  }
3569
3572
  SlateEditableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: SlateEditableComponent, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Component });
3570
- SlateEditableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.4", 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: [
3573
+ SlateEditableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.4", type: SlateEditableComponent, selector: "slate-editable", inputs: { editor: "editor", renderElement: "renderElement", renderLeaf: "renderLeaf", renderText: "renderText", decorate: "decorate", placeholderDecorate: "placeholderDecorate", scrollSelectionIntoView: "scrollSelectionIntoView", 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: [
3571
3574
  {
3572
3575
  provide: NG_VALUE_ACCESSOR,
3573
3576
  useExisting: forwardRef(() => SlateEditableComponent),
@@ -3602,6 +3605,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.4", ngImpor
3602
3605
  type: Input
3603
3606
  }], placeholderDecorate: [{
3604
3607
  type: Input
3608
+ }], scrollSelectionIntoView: [{
3609
+ type: Input
3605
3610
  }], isStrictDecorate: [{
3606
3611
  type: Input
3607
3612
  }], trackBy: [{
@@ -3660,6 +3665,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.4", ngImpor
3660
3665
  type: ViewChild,
3661
3666
  args: ['templateComponent', { static: true, read: ElementRef }]
3662
3667
  }] } });
3668
+ const defaultScrollSelectionIntoView = (editor, domRange) => {
3669
+ // This was affecting the selection of multiple blocks and dragging behavior,
3670
+ // so enabled only if the selection has been collapsed.
3671
+ if (domRange.getBoundingClientRect && (!editor.selection || (editor.selection && Range.isCollapsed(editor.selection)))) {
3672
+ const leafEl = domRange.startContainer.parentElement;
3673
+ leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange);
3674
+ scrollIntoView(leafEl, {
3675
+ scrollMode: 'if-needed'
3676
+ });
3677
+ delete leafEl.getBoundingClientRect;
3678
+ }
3679
+ };
3663
3680
  /**
3664
3681
  * Check if the target is editable and in the editor.
3665
3682
  */