slate-angular 16.1.0-next.1 → 16.1.0-next.11

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.
Files changed (40) hide show
  1. package/components/children/children-outlet.component.d.ts +9 -0
  2. package/components/editable/editable.component.d.ts +1 -1
  3. package/components/string/default-string.component.d.ts +1 -1
  4. package/esm2022/components/block-card/block-card.component.mjs +2 -2
  5. package/esm2022/components/children/children-outlet.component.mjs +22 -0
  6. package/esm2022/components/children/children.component.mjs +2 -4
  7. package/esm2022/components/editable/editable.component.mjs +24 -10
  8. package/esm2022/components/leaf/token.mjs +1 -1
  9. package/esm2022/components/string/default-string.component.mjs +1 -1
  10. package/esm2022/components/string/string.component.mjs +1 -1
  11. package/esm2022/components/text/token.mjs +1 -1
  12. package/esm2022/module.mjs +7 -16
  13. package/esm2022/plugins/angular-editor.mjs +28 -7
  14. package/esm2022/plugins/with-angular.mjs +5 -4
  15. package/esm2022/public-api.mjs +3 -2
  16. package/esm2022/utils/constants.mjs +2 -0
  17. package/esm2022/utils/index.mjs +2 -1
  18. package/esm2022/utils/throttle.mjs +1 -1
  19. package/esm2022/view/base.mjs +51 -22
  20. package/esm2022/view/container.mjs +1 -1
  21. package/esm2022/view/context-change.mjs +13 -0
  22. package/esm2022/view/context.mjs +1 -1
  23. package/esm2022/view/render/leaves-render.mjs +8 -6
  24. package/esm2022/view/render/list-render.mjs +34 -12
  25. package/esm2022/view/render/utils.mjs +20 -7
  26. package/fesm2022/slate-angular.mjs +213 -78
  27. package/fesm2022/slate-angular.mjs.map +1 -1
  28. package/module.d.ts +2 -1
  29. package/package.json +7 -7
  30. package/plugins/angular-editor.d.ts +3 -2
  31. package/public-api.d.ts +2 -1
  32. package/utils/constants.d.ts +1 -0
  33. package/utils/index.d.ts +1 -0
  34. package/view/base.d.ts +10 -7
  35. package/view/{before-context-change.d.ts → context-change.d.ts} +4 -0
  36. package/view/context.d.ts +1 -3
  37. package/view/render/leaves-render.d.ts +2 -1
  38. package/view/render/list-render.d.ts +5 -3
  39. package/view/render/utils.d.ts +2 -2
  40. package/esm2022/view/before-context-change.mjs +0 -7
@@ -1,4 +1,4 @@
1
- import { Editor, Range, Transforms, Path, Element, Text as Text$1, Node } from 'slate';
1
+ import { Editor, Range, Element, Transforms, Path, Text as Text$1, Node } from 'slate';
2
2
  import { isKeyHotkey } from 'is-hotkey';
3
3
  import * as i0 from '@angular/core';
4
4
  import { TemplateRef, Component, ChangeDetectionStrategy, ViewChild, Directive, Input, InjectionToken, ComponentRef, IterableDiffers, HostBinding, inject, ViewContainerRef, forwardRef, ElementRef, Inject, NgModule } from '@angular/core';
@@ -415,7 +415,7 @@ const AngularEditor = {
415
415
  const [start, end] = Range.edges(selection);
416
416
  const endBlock = Editor.above(editor, {
417
417
  at: end,
418
- match: node => Editor.isBlock(editor, node)
418
+ match: node => Element.isElement(node) && Editor.isBlock(editor, node)
419
419
  });
420
420
  return Editor.isStart(editor, end, endBlock[1]);
421
421
  },
@@ -637,7 +637,7 @@ const AngularEditor = {
637
637
  // If the drop target is inside a void node, move it into either the
638
638
  // next or previous node, depending on which side the `x` and `y`
639
639
  // coordinates are closest to.
640
- if (Editor.isVoid(editor, node)) {
640
+ if (Element.isElement(node) && Editor.isVoid(editor, node)) {
641
641
  const rect = target.getBoundingClientRect();
642
642
  const isPrev = editor.isInline(node) ? x - rect.left < rect.left + rect.width - x : y - rect.top < rect.top + rect.height - y;
643
643
  const edge = Editor.point(editor, path, {
@@ -751,9 +751,10 @@ const AngularEditor = {
751
751
  else if (voidNode) {
752
752
  // For void nodes, the element with the offset key will be a cousin, not an
753
753
  // ancestor, so find it by going down from the nearest void parent.
754
- leafNode = voidNode.querySelector('[data-slate-leaf]');
755
- parentNode = voidNode.querySelector('[data-slate-length="0"]');
756
- textNode = leafNode.closest('[data-slate-node="text"]');
754
+ const spacer = voidNode.querySelector('[data-slate-spacer="true"]');
755
+ leafNode = spacer.firstElementChild;
756
+ parentNode = leafNode.firstElementChild;
757
+ textNode = spacer;
757
758
  domNode = leafNode;
758
759
  offset = domNode.textContent.length;
759
760
  }
@@ -814,9 +815,29 @@ const AngularEditor = {
814
815
  if (anchorNode == null || focusNode == null || anchorOffset == null || focusOffset == null) {
815
816
  throw new Error(`Cannot resolve a Slate range from DOM range: ${domRange}`);
816
817
  }
818
+ // COMPAT: Triple-clicking a word in chrome will sometimes place the focus
819
+ // inside a `contenteditable="false"` DOM node following the word, which
820
+ // will cause `toSlatePoint` to throw an error. (2023/03/07)
821
+ if ('getAttribute' in focusNode &&
822
+ focusNode.getAttribute('contenteditable') === 'false' &&
823
+ focusNode.getAttribute('data-slate-void') !== 'true') {
824
+ focusNode = anchorNode;
825
+ focusOffset = anchorNode.textContent?.length || 0;
826
+ }
817
827
  const anchor = AngularEditor.toSlatePoint(editor, [anchorNode, anchorOffset]);
818
828
  const focus = isCollapsed ? anchor : AngularEditor.toSlatePoint(editor, [focusNode, focusOffset]);
819
- return { anchor, focus };
829
+ let range = { anchor: anchor, focus: focus };
830
+ // if the selection is a hanging range that ends in a void
831
+ // and the DOM focus is an Element
832
+ // (meaning that the selection ends before the element)
833
+ // unhang the range to avoid mistakenly including the void
834
+ if (Range.isExpanded(range) &&
835
+ Range.isForward(range) &&
836
+ isDOMElement(focusNode) &&
837
+ Editor.void(editor, { at: range.focus, mode: 'highest' })) {
838
+ range = Editor.unhangRange(editor, range, { voids: true });
839
+ }
840
+ return range;
820
841
  },
821
842
  isLeafBlock(editor, node) {
822
843
  return Element.isElement(node) && !editor.isInline(node) && Editor.hasInlines(editor, node);
@@ -1008,6 +1029,24 @@ function normalize(document) {
1008
1029
  return document.filter(value => Element.isElement(value) && isValid(value));
1009
1030
  }
1010
1031
 
1032
+ const createThrottleRAF = () => {
1033
+ let timerId = null;
1034
+ const throttleRAF = (fn) => {
1035
+ const scheduleFunc = () => {
1036
+ timerId = requestAnimationFrame(() => {
1037
+ timerId = null;
1038
+ fn();
1039
+ });
1040
+ };
1041
+ if (timerId !== null) {
1042
+ cancelAnimationFrame(timerId);
1043
+ timerId = null;
1044
+ }
1045
+ scheduleFunc();
1046
+ };
1047
+ return throttleRAF;
1048
+ };
1049
+
1011
1050
  /**
1012
1051
  * Utilities for single-line deletion
1013
1052
  */
@@ -1061,7 +1100,7 @@ const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
1061
1100
  }
1062
1101
  if (editor.selection && Range.isCollapsed(editor.selection)) {
1063
1102
  const parentBlockEntry = Editor.above(editor, {
1064
- match: n => Editor.isBlock(editor, n),
1103
+ match: n => Element.isElement(n) && Editor.isBlock(editor, n),
1065
1104
  at: editor.selection
1066
1105
  });
1067
1106
  if (parentBlockEntry) {
@@ -1211,7 +1250,7 @@ const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
1211
1250
  }
1212
1251
  else {
1213
1252
  const node = Node.parent(editor, selection.anchor.path);
1214
- if (Editor.isVoid(editor, node)) {
1253
+ if (Element.isElement(node) && Editor.isVoid(editor, node)) {
1215
1254
  Transforms.delete(editor);
1216
1255
  }
1217
1256
  }
@@ -1254,6 +1293,7 @@ const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
1254
1293
  e.onKeydown = () => { };
1255
1294
  e.onClick = () => { };
1256
1295
  e.isBlockCard = element => false;
1296
+ e.isExpanded = element => true;
1257
1297
  e.onError = (errorData) => {
1258
1298
  if (errorData.nativeError) {
1259
1299
  console.error(errorData.nativeError);
@@ -1693,8 +1733,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImpor
1693
1733
  selector: 'slate-children',
1694
1734
  template: ``,
1695
1735
  changeDetection: ChangeDetectionStrategy.OnPush,
1696
- standalone: true,
1697
- imports: [NgFor]
1736
+ standalone: true
1698
1737
  }]
1699
1738
  }], propDecorators: { children: [{
1700
1739
  type: Input
@@ -1715,6 +1754,12 @@ function hasBeforeContextChange(value) {
1715
1754
  }
1716
1755
  return false;
1717
1756
  }
1757
+ function hasAfterContextChange(value) {
1758
+ if (value.afterContextChange) {
1759
+ return true;
1760
+ }
1761
+ return false;
1762
+ }
1718
1763
 
1719
1764
  class SlateBlockCard {
1720
1765
  get nativeElement() {
@@ -1727,7 +1772,6 @@ class SlateBlockCard {
1727
1772
  this.elementRef = elementRef;
1728
1773
  }
1729
1774
  ngOnInit() {
1730
- this.append();
1731
1775
  this.nativeElement.classList.add(`slate-block-card`);
1732
1776
  }
1733
1777
  append() {
@@ -1735,6 +1779,7 @@ class SlateBlockCard {
1735
1779
  }
1736
1780
  initializeCenter(rootNodes) {
1737
1781
  this.centerRootNodes = rootNodes;
1782
+ this.append();
1738
1783
  }
1739
1784
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: SlateBlockCard, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); }
1740
1785
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.1", type: SlateBlockCard, isStandalone: true, selector: "slate-block-card, [slateBlockCard]", viewQueries: [{ propertyName: "centerContianer", first: true, predicate: ["centerContianer"], descendants: true, static: true }], ngImport: i0, template: "<span card-target=\"card-left\" class=\"card-left\">{{ '\\uFEFF' }}</span>\n<div card-target=\"card-center\" #centerContianer></div>\n<span card-target=\"card-right\" class=\"card-right\">{{ '\\uFEFF' }}</span>\n" }); }
@@ -1788,14 +1833,20 @@ function updateContext(view, newContext, viewContext) {
1788
1833
  view.detectChanges();
1789
1834
  }
1790
1835
  }
1791
- function mount(views, blockCards, outletElement) {
1836
+ function mount(views, blockCards, outletParent, outletElement) {
1792
1837
  if (views.length > 0) {
1793
- const result = [];
1838
+ const fragment = document.createDocumentFragment();
1794
1839
  views.forEach((view, index) => {
1795
1840
  const blockCard = blockCards ? blockCards[index] : undefined;
1796
- result.push(...getRootNodes(view, blockCard));
1841
+ fragment.append(...getRootNodes(view, blockCard));
1797
1842
  });
1798
- outletElement.append(...result);
1843
+ if (outletElement) {
1844
+ outletElement.parentElement.insertBefore(fragment, outletElement);
1845
+ outletElement.remove();
1846
+ }
1847
+ else {
1848
+ outletParent.prepend(fragment);
1849
+ }
1799
1850
  }
1800
1851
  }
1801
1852
  function getRootNodes(ref, blockCard) {
@@ -1824,7 +1875,7 @@ function getRootNodes(ref, blockCard) {
1824
1875
  return result;
1825
1876
  }
1826
1877
  }
1827
- function mountOnItemChange(index, item, views, blockCards, outletElement, viewContext) {
1878
+ function mountOnItemChange(index, item, views, blockCards, outletParent, firstRootNode, viewContext) {
1828
1879
  const view = views[index];
1829
1880
  let rootNodes = getRootNodes(view);
1830
1881
  if (blockCards) {
@@ -1835,7 +1886,14 @@ function mountOnItemChange(index, item, views, blockCards, outletElement, viewCo
1835
1886
  }
1836
1887
  }
1837
1888
  if (index === 0) {
1838
- outletElement.prepend(...rootNodes);
1889
+ if (firstRootNode) {
1890
+ rootNodes.forEach(rootNode => {
1891
+ firstRootNode.insertAdjacentElement('beforebegin', rootNode);
1892
+ });
1893
+ }
1894
+ else {
1895
+ outletParent.prepend(...rootNodes);
1896
+ }
1839
1897
  }
1840
1898
  else {
1841
1899
  const previousView = views[index - 1];
@@ -1850,19 +1908,22 @@ function mountOnItemChange(index, item, views, blockCards, outletElement, viewCo
1850
1908
  }
1851
1909
 
1852
1910
  class ListRender {
1853
- constructor(viewContext, viewContainerRef, getOutletElement) {
1911
+ constructor(viewContext, viewContainerRef, getOutletParent, getOutletElement) {
1854
1912
  this.viewContext = viewContext;
1855
1913
  this.viewContainerRef = viewContainerRef;
1914
+ this.getOutletParent = getOutletParent;
1856
1915
  this.getOutletElement = getOutletElement;
1857
1916
  this.views = [];
1858
1917
  this.blockCards = [];
1859
1918
  this.contexts = [];
1860
1919
  this.viewTypes = [];
1920
+ this.differ = null;
1861
1921
  this.initialized = false;
1862
1922
  }
1863
- initialize(children, parent, parentPath, childrenContext) {
1923
+ initialize(children, parent, childrenContext) {
1864
1924
  this.initialized = true;
1865
1925
  this.children = children;
1926
+ const parentPath = AngularEditor.findPath(this.viewContext.editor, parent);
1866
1927
  children.forEach((descendant, index) => {
1867
1928
  NODE_TO_INDEX.set(descendant, index);
1868
1929
  NODE_TO_PARENT.set(descendant, parent);
@@ -1875,19 +1936,24 @@ class ListRender {
1875
1936
  this.viewTypes.push(viewType);
1876
1937
  this.blockCards.push(blockCard);
1877
1938
  });
1878
- mount(this.views, this.blockCards, this.getOutletElement());
1939
+ mount(this.views, this.blockCards, this.getOutletParent(), this.getOutletElement());
1879
1940
  const newDiffers = this.viewContainerRef.injector.get(IterableDiffers);
1880
1941
  this.differ = newDiffers.find(children).create(trackBy$1(this.viewContext));
1881
1942
  this.differ.diff(children);
1882
1943
  }
1883
- update(children, parent, parentPath, childrenContext) {
1944
+ update(children, parent, childrenContext) {
1884
1945
  if (!this.initialized) {
1885
- this.initialize(children, parent, parentPath, childrenContext);
1946
+ this.initialize(children, parent, childrenContext);
1886
1947
  return;
1887
1948
  }
1888
- const outletElement = this.getOutletElement();
1949
+ if (!this.differ) {
1950
+ throw new Error('Exception: Can not find differ ');
1951
+ }
1952
+ const outletParent = this.getOutletParent();
1889
1953
  const diffResult = this.differ.diff(children);
1954
+ const parentPath = AngularEditor.findPath(this.viewContext.editor, parent);
1890
1955
  if (diffResult) {
1956
+ let firstRootNode = getRootNodes(this.views[0], this.blockCards[0])[0];
1891
1957
  const newContexts = [];
1892
1958
  const newViewTypes = [];
1893
1959
  const newViews = [];
@@ -1906,7 +1972,7 @@ class ListRender {
1906
1972
  newContexts.push(context);
1907
1973
  newViews.push(view);
1908
1974
  newBlockCards.push(blockCard);
1909
- mountOnItemChange(record.currentIndex, record.item, newViews, newBlockCards, outletElement, this.viewContext);
1975
+ mountOnItemChange(record.currentIndex, record.item, newViews, newBlockCards, outletParent, firstRootNode, this.viewContext);
1910
1976
  }
1911
1977
  else {
1912
1978
  const previousView = this.views[record.previousIndex];
@@ -1937,7 +2003,7 @@ class ListRender {
1937
2003
  newBlockCards.push(blockCard);
1938
2004
  }
1939
2005
  });
1940
- diffResult.forEachOperation((record) => {
2006
+ diffResult.forEachOperation(record => {
1941
2007
  // removed
1942
2008
  if (record.currentIndex === null) {
1943
2009
  const view = this.views[record.previousIndex];
@@ -1947,7 +2013,7 @@ class ListRender {
1947
2013
  }
1948
2014
  // moved
1949
2015
  if (record.previousIndex !== null && record.currentIndex !== null) {
1950
- mountOnItemChange(record.currentIndex, record.item, newViews, newBlockCards, outletElement, this.viewContext);
2016
+ mountOnItemChange(record.currentIndex, record.item, newViews, newBlockCards, outletParent, firstRootNode, this.viewContext);
1951
2017
  // Solve the block-card DOMElement loss when moving nodes
1952
2018
  newBlockCards[record.currentIndex]?.instance.append();
1953
2019
  }
@@ -1974,6 +2040,22 @@ class ListRender {
1974
2040
  this.contexts = newContexts;
1975
2041
  }
1976
2042
  }
2043
+ destroy() {
2044
+ this.children.forEach((element, index) => {
2045
+ if (this.views[index]) {
2046
+ this.views[index].destroy();
2047
+ }
2048
+ if (this.blockCards[index]) {
2049
+ this.blockCards[index].destroy();
2050
+ }
2051
+ });
2052
+ this.views = [];
2053
+ this.blockCards = [];
2054
+ this.contexts = [];
2055
+ this.viewTypes = [];
2056
+ this.initialized = false;
2057
+ this.differ = null;
2058
+ }
1977
2059
  }
1978
2060
  function getContext$1(index, item, parentPath, childrenContext, viewContext) {
1979
2061
  if (Element.isElement(item)) {
@@ -1983,7 +2065,6 @@ function getContext$1(index, item, parentPath, childrenContext, viewContext) {
1983
2065
  const isVoid = viewContext.editor.isVoid(item);
1984
2066
  const elementContext = {
1985
2067
  element: item,
1986
- path: parentPath.concat(index),
1987
2068
  ...computedContext,
1988
2069
  attributes: {
1989
2070
  'data-slate-node': 'element',
@@ -1997,7 +2078,6 @@ function getContext$1(index, item, parentPath, childrenContext, viewContext) {
1997
2078
  }
1998
2079
  if (isVoid) {
1999
2080
  elementContext.attributes['data-slate-void'] = true;
2000
- elementContext.attributes.contenteditable = false;
2001
2081
  }
2002
2082
  return elementContext;
2003
2083
  }
@@ -2092,9 +2172,10 @@ function memoizedTextContext(prev, next) {
2092
2172
  }
2093
2173
 
2094
2174
  class LeavesRender {
2095
- constructor(viewContext, viewContainerRef, getOutletElement) {
2175
+ constructor(viewContext, viewContainerRef, getOutletParent, getOutletElement) {
2096
2176
  this.viewContext = viewContext;
2097
2177
  this.viewContainerRef = viewContainerRef;
2178
+ this.getOutletParent = getOutletParent;
2098
2179
  this.getOutletElement = getOutletElement;
2099
2180
  this.views = [];
2100
2181
  this.contexts = [];
@@ -2112,16 +2193,17 @@ class LeavesRender {
2112
2193
  this.contexts.push(context);
2113
2194
  this.viewTypes.push(viewType);
2114
2195
  });
2115
- mount(this.views, null, this.getOutletElement());
2196
+ mount(this.views, null, this.getOutletParent(), this.getOutletElement());
2116
2197
  const newDiffers = this.viewContainerRef.injector.get(IterableDiffers);
2117
2198
  this.differ = newDiffers.find(this.leaves).create(trackBy(this.viewContext));
2118
2199
  this.differ.diff(this.leaves);
2119
2200
  }
2120
2201
  update(context) {
2121
2202
  const { leaves, contexts } = this.getLeaves(context);
2122
- const outletElement = this.getOutletElement();
2203
+ const outletParent = this.getOutletParent();
2123
2204
  const diffResult = this.differ.diff(leaves);
2124
2205
  if (diffResult) {
2206
+ let firstRootNode = getRootNodes(this.views[0])[0];
2125
2207
  const newContexts = [];
2126
2208
  const newViewTypes = [];
2127
2209
  const newViews = [];
@@ -2134,7 +2216,7 @@ class LeavesRender {
2134
2216
  view = createEmbeddedViewOrComponent(viewType, context, this.viewContext, this.viewContainerRef);
2135
2217
  newContexts.push(context);
2136
2218
  newViews.push(view);
2137
- mountOnItemChange(record.currentIndex, record.item, newViews, null, outletElement, this.viewContext);
2219
+ mountOnItemChange(record.currentIndex, record.item, newViews, null, outletParent, firstRootNode, this.viewContext);
2138
2220
  }
2139
2221
  else {
2140
2222
  const previousView = this.views[record.previousIndex];
@@ -2159,7 +2241,7 @@ class LeavesRender {
2159
2241
  view.destroy();
2160
2242
  });
2161
2243
  diffResult.forEachMovedItem(record => {
2162
- mountOnItemChange(record.currentIndex, record.item, newViews, null, outletElement, this.viewContext);
2244
+ mountOnItemChange(record.currentIndex, record.item, newViews, null, outletParent, firstRootNode, this.viewContext);
2163
2245
  });
2164
2246
  this.viewTypes = newViewTypes;
2165
2247
  this.views = newViews;
@@ -2193,6 +2275,26 @@ function trackBy(viewContext) {
2193
2275
  };
2194
2276
  }
2195
2277
 
2278
+ class SlateChildrenOutlet {
2279
+ constructor(elementRef) {
2280
+ this.elementRef = elementRef;
2281
+ }
2282
+ getNativeElement() {
2283
+ return this.elementRef.nativeElement;
2284
+ }
2285
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: SlateChildrenOutlet, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); }
2286
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.1", type: SlateChildrenOutlet, isStandalone: true, selector: "slate-children-outlet", ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
2287
+ }
2288
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: SlateChildrenOutlet, decorators: [{
2289
+ type: Component,
2290
+ args: [{
2291
+ selector: 'slate-children-outlet',
2292
+ template: ``,
2293
+ changeDetection: ChangeDetectionStrategy.OnPush,
2294
+ standalone: true
2295
+ }]
2296
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }]; } });
2297
+
2196
2298
  /**
2197
2299
  * base class for custom element component or text component
2198
2300
  */
@@ -2203,6 +2305,12 @@ class BaseComponent {
2203
2305
  }
2204
2306
  this._context = value;
2205
2307
  this.onContextChange();
2308
+ if (this.initialized) {
2309
+ this.cdr.detectChanges();
2310
+ }
2311
+ if (hasAfterContextChange(this)) {
2312
+ this.afterContextChange();
2313
+ }
2206
2314
  }
2207
2315
  get context() {
2208
2316
  return this._context;
@@ -2216,6 +2324,7 @@ class BaseComponent {
2216
2324
  constructor(elementRef, cdr) {
2217
2325
  this.elementRef = elementRef;
2218
2326
  this.cdr = cdr;
2327
+ this.initialized = false;
2219
2328
  }
2220
2329
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive }); }
2221
2330
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.1", type: BaseComponent, inputs: { context: "context", viewContext: "viewContext" }, ngImport: i0 }); }
@@ -2233,7 +2342,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImpor
2233
2342
  class BaseLeafComponent extends BaseComponent {
2234
2343
  constructor() {
2235
2344
  super(...arguments);
2236
- this.initialized = false;
2237
2345
  this.isSlateLeaf = true;
2238
2346
  }
2239
2347
  get text() {
@@ -2249,7 +2357,6 @@ class BaseLeafComponent extends BaseComponent {
2249
2357
  if (!this.initialized) {
2250
2358
  return;
2251
2359
  }
2252
- this.cdr.detectChanges();
2253
2360
  }
2254
2361
  renderPlaceholder() {
2255
2362
  // issue-1: IME input was interrupted
@@ -2302,10 +2409,15 @@ class BaseElementComponent extends BaseComponent {
2302
2409
  constructor() {
2303
2410
  super(...arguments);
2304
2411
  this.viewContainerRef = inject(ViewContainerRef);
2305
- this.initialized = false;
2306
- this.getOutletElement = () => {
2412
+ this.getOutletParent = () => {
2307
2413
  return this.elementRef.nativeElement;
2308
2414
  };
2415
+ this.getOutletElement = () => {
2416
+ if (this.childrenOutletInstance) {
2417
+ return this.childrenOutletInstance.getNativeElement();
2418
+ }
2419
+ return null;
2420
+ };
2309
2421
  }
2310
2422
  get element() {
2311
2423
  return this._context && this._context.element;
@@ -2313,9 +2425,6 @@ class BaseElementComponent extends BaseComponent {
2313
2425
  get selection() {
2314
2426
  return this._context && this._context.selection;
2315
2427
  }
2316
- get path() {
2317
- return this._context && this._context.path;
2318
- }
2319
2428
  get decorations() {
2320
2429
  return this._context && this._context.decorations;
2321
2430
  }
@@ -2336,8 +2445,10 @@ class BaseElementComponent extends BaseComponent {
2336
2445
  this.nativeElement.setAttribute(key, this._context.attributes[key]);
2337
2446
  }
2338
2447
  this.initialized = true;
2339
- this.listRender = new ListRender(this.viewContext, this.viewContainerRef, this.getOutletElement);
2340
- this.listRender.initialize(this.children, this.element, this.path, this.childrenContext);
2448
+ this.listRender = new ListRender(this.viewContext, this.viewContainerRef, this.getOutletParent, this.getOutletElement);
2449
+ if (this.editor.isExpanded(this.element)) {
2450
+ this.listRender.initialize(this.children, this.element, this.childrenContext);
2451
+ }
2341
2452
  }
2342
2453
  updateWeakMap() {
2343
2454
  NODE_TO_ELEMENT.set(this.element, this.nativeElement);
@@ -2358,8 +2469,17 @@ class BaseElementComponent extends BaseComponent {
2358
2469
  if (!this.initialized) {
2359
2470
  return;
2360
2471
  }
2361
- this.listRender.update(this.children, this.element, this.path, this.childrenContext);
2362
- this.cdr.detectChanges();
2472
+ this.updateChildrenView();
2473
+ }
2474
+ updateChildrenView() {
2475
+ if (this.editor.isExpanded(this.element)) {
2476
+ this.listRender.update(this.children, this.element, this.childrenContext);
2477
+ }
2478
+ else {
2479
+ if (this.listRender.initialized) {
2480
+ this.listRender.destroy();
2481
+ }
2482
+ }
2363
2483
  }
2364
2484
  getChildrenContext() {
2365
2485
  return {
@@ -2371,29 +2491,37 @@ class BaseElementComponent extends BaseComponent {
2371
2491
  };
2372
2492
  }
2373
2493
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseElementComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
2374
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.1", type: BaseElementComponent, usesInheritance: true, ngImport: i0 }); }
2494
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.1", type: BaseElementComponent, viewQueries: [{ propertyName: "childrenOutletInstance", first: true, predicate: SlateChildrenOutlet, descendants: true, static: true }], usesInheritance: true, ngImport: i0 }); }
2375
2495
  }
2376
2496
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseElementComponent, decorators: [{
2377
2497
  type: Directive
2378
- }] });
2498
+ }], propDecorators: { childrenOutletInstance: [{
2499
+ type: ViewChild,
2500
+ args: [SlateChildrenOutlet, { static: true }]
2501
+ }] } });
2379
2502
  /**
2380
2503
  * base class for custom text component
2381
2504
  */
2382
2505
  class BaseTextComponent extends BaseComponent {
2383
2506
  constructor() {
2384
2507
  super(...arguments);
2385
- this.initialized = false;
2386
2508
  this.viewContainerRef = inject(ViewContainerRef);
2387
- this.getOutletElement = () => {
2509
+ this.getOutletParent = () => {
2388
2510
  return this.elementRef.nativeElement;
2389
2511
  };
2512
+ this.getOutletElement = () => {
2513
+ if (this.childrenOutletInstance) {
2514
+ return this.childrenOutletInstance.getNativeElement();
2515
+ }
2516
+ return null;
2517
+ };
2390
2518
  }
2391
2519
  get text() {
2392
2520
  return this._context && this._context.text;
2393
2521
  }
2394
2522
  ngOnInit() {
2395
2523
  this.initialized = true;
2396
- this.leavesRender = new LeavesRender(this.viewContext, this.viewContainerRef, this.getOutletElement);
2524
+ this.leavesRender = new LeavesRender(this.viewContext, this.viewContainerRef, this.getOutletParent, this.getOutletElement);
2397
2525
  this.leavesRender.initialize(this.context);
2398
2526
  }
2399
2527
  updateWeakMap() {
@@ -2411,14 +2539,16 @@ class BaseTextComponent extends BaseComponent {
2411
2539
  return;
2412
2540
  }
2413
2541
  this.leavesRender.update(this.context);
2414
- this.cdr.detectChanges();
2415
2542
  }
2416
2543
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseTextComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
2417
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.1", type: BaseTextComponent, usesInheritance: true, ngImport: i0 }); }
2544
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.1", type: BaseTextComponent, viewQueries: [{ propertyName: "childrenOutletInstance", first: true, predicate: SlateChildrenOutlet, descendants: true, static: true }], usesInheritance: true, ngImport: i0 }); }
2418
2545
  }
2419
2546
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseTextComponent, decorators: [{
2420
2547
  type: Directive
2421
- }] });
2548
+ }], propDecorators: { childrenOutletInstance: [{
2549
+ type: ViewChild,
2550
+ args: [SlateChildrenOutlet, { static: true }]
2551
+ }] } });
2422
2552
 
2423
2553
  class SlateLeaves extends ViewContainer {
2424
2554
  constructor() {
@@ -2818,6 +2948,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImpor
2818
2948
 
2819
2949
  const SLATE_DEFAULT_LEAF_COMPONENT_TOKEN = new InjectionToken('slate-default-leaf-token');
2820
2950
 
2951
+ const TRIPLE_CLICK = 3;
2952
+
2821
2953
  // not correctly clipboardData on beforeinput
2822
2954
  const forceOnDOMPaste = IS_SAFARI;
2823
2955
  class SlateEditable {
@@ -2856,7 +2988,7 @@ class SlateEditable {
2856
2988
  this.dataSlateNode = 'value';
2857
2989
  this.dataGramm = false;
2858
2990
  this.viewContainerRef = inject(ViewContainerRef);
2859
- this.getOutletElement = () => {
2991
+ this.getOutletParent = () => {
2860
2992
  return this.elementRef.nativeElement;
2861
2993
  };
2862
2994
  }
@@ -2884,7 +3016,7 @@ class SlateEditable {
2884
3016
  // add browser class
2885
3017
  let browserClass = IS_FIREFOX ? 'firefox' : IS_SAFARI ? 'safari' : '';
2886
3018
  browserClass && this.elementRef.nativeElement.classList.add(browserClass);
2887
- this.listRender = new ListRender(this.viewContext, this.viewContainerRef, this.getOutletElement);
3019
+ this.listRender = new ListRender(this.viewContext, this.viewContainerRef, this.getOutletParent, () => null);
2888
3020
  }
2889
3021
  ngOnChanges(simpleChanges) {
2890
3022
  if (!this.initialized) {
@@ -2926,10 +3058,10 @@ class SlateEditable {
2926
3058
  }
2927
3059
  this.initializeContext();
2928
3060
  if (!this.listRender.initialized) {
2929
- this.listRender.initialize(this.editor.children, this.editor, [], this.context);
3061
+ this.listRender.initialize(this.editor.children, this.editor, this.context);
2930
3062
  }
2931
3063
  else {
2932
- this.listRender.update(this.editor.children, this.editor, [], this.context);
3064
+ this.listRender.update(this.editor.children, this.editor, this.context);
2933
3065
  }
2934
3066
  this.cdr.markForCheck();
2935
3067
  }
@@ -3047,7 +3179,7 @@ class SlateEditable {
3047
3179
  ngDoCheck() { }
3048
3180
  forceRender() {
3049
3181
  this.updateContext();
3050
- this.listRender.update(this.editor.children, this.editor, [], this.context);
3182
+ this.listRender.update(this.editor.children, this.editor, this.context);
3051
3183
  // repair collaborative editing when Chinese input is interrupted by other users' cursors
3052
3184
  // when the DOMElement where the selection is located is removed
3053
3185
  // the compositionupdate and compositionend events will no longer be fired
@@ -3086,7 +3218,7 @@ class SlateEditable {
3086
3218
  render() {
3087
3219
  const changed = this.updateContext();
3088
3220
  if (changed) {
3089
- this.listRender.update(this.editor.children, this.editor, [], this.context);
3221
+ this.listRender.update(this.editor.children, this.editor, this.context);
3090
3222
  }
3091
3223
  }
3092
3224
  updateContext() {
@@ -3421,6 +3553,19 @@ class SlateEditable {
3421
3553
  const end = Editor.end(this.editor, path);
3422
3554
  const startVoid = Editor.void(this.editor, { at: start });
3423
3555
  const endVoid = Editor.void(this.editor, { at: end });
3556
+ if (event.detail === TRIPLE_CLICK && path.length >= 1) {
3557
+ let blockPath = path;
3558
+ if (!(Element.isElement(node) && Editor.isBlock(this.editor, node))) {
3559
+ const block = Editor.above(this.editor, {
3560
+ match: n => Element.isElement(n) && Editor.isBlock(this.editor, n),
3561
+ at: path
3562
+ });
3563
+ blockPath = block?.[1] ?? path.slice(0, 1);
3564
+ }
3565
+ const range = Editor.range(this.editor, blockPath);
3566
+ Transforms.select(this.editor, range);
3567
+ return;
3568
+ }
3424
3569
  if (startVoid && endVoid && Path.equals(startVoid[1], endVoid[1])) {
3425
3570
  const range = Editor.range(this.editor, start);
3426
3571
  Transforms.select(this.editor, range);
@@ -3487,7 +3632,7 @@ class SlateEditable {
3487
3632
  // that drops are allowed. Editable content is droppable by
3488
3633
  // default, and calling `preventDefault` hides the cursor.
3489
3634
  const node = AngularEditor.toSlateNode(this.editor, event.target);
3490
- if (Editor.isVoid(this.editor, node)) {
3635
+ if (Element.isElement(node) && Editor.isVoid(this.editor, node)) {
3491
3636
  event.preventDefault();
3492
3637
  }
3493
3638
  }
@@ -3496,7 +3641,7 @@ class SlateEditable {
3496
3641
  if (!this.readonly && hasTarget(this.editor, event.target) && !this.isDOMEventHandled(event, this.dragStart)) {
3497
3642
  const node = AngularEditor.toSlateNode(this.editor, event.target);
3498
3643
  const path = AngularEditor.findPath(this.editor, node);
3499
- const voidMatch = Editor.isVoid(this.editor, node) || Editor.void(this.editor, { at: path, voids: true });
3644
+ const voidMatch = Element.isElement(node) && (Editor.isVoid(this.editor, node) || Editor.void(this.editor, { at: path, voids: true }));
3500
3645
  // If starting a drag on a void node, make sure it is selected
3501
3646
  // so that it shows up in the selection's fragment.
3502
3647
  if (voidMatch) {
@@ -4019,7 +4164,7 @@ const hasTarget = (editor, target) => {
4019
4164
  */
4020
4165
  const isTargetInsideVoid = (editor, target) => {
4021
4166
  const slateNode = hasTarget(editor, target) && AngularEditor.toSlateNode(editor, target);
4022
- return Editor.isVoid(editor, slateNode);
4167
+ return Element.isElement(slateNode) && Editor.isVoid(editor, slateNode);
4023
4168
  };
4024
4169
  const hasStringTarget = (domSelection) => {
4025
4170
  return ((domSelection.anchorNode.parentElement.hasAttribute('data-slate-string') ||
@@ -4075,12 +4220,8 @@ class SlateModule {
4075
4220
  SlateBlockCard,
4076
4221
  SlateLeaves,
4077
4222
  SlateDefaultLeaf,
4078
- SlateDefaultString], exports: [SlateEditable,
4079
- SlateChildren,
4080
- SlateElement,
4081
- SlateLeaves,
4082
- SlateString,
4083
- SlateDefaultString] }); }
4223
+ SlateDefaultString,
4224
+ SlateChildrenOutlet], exports: [SlateEditable, SlateChildren, SlateChildrenOutlet, SlateElement, SlateLeaves, SlateString, SlateDefaultString] }); }
4084
4225
  static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: SlateModule, providers: [
4085
4226
  {
4086
4227
  provide: SLATE_DEFAULT_ELEMENT_COMPONENT_TOKEN,
@@ -4104,16 +4245,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImpor
4104
4245
  SlateBlockCard,
4105
4246
  SlateLeaves,
4106
4247
  SlateDefaultLeaf,
4107
- SlateDefaultString
4108
- ],
4109
- exports: [
4110
- SlateEditable,
4111
- SlateChildren,
4112
- SlateElement,
4113
- SlateLeaves,
4114
- SlateString,
4115
- SlateDefaultString
4248
+ SlateDefaultString,
4249
+ SlateChildrenOutlet
4116
4250
  ],
4251
+ exports: [SlateEditable, SlateChildren, SlateChildrenOutlet, SlateElement, SlateLeaves, SlateString, SlateDefaultString],
4117
4252
  providers: [
4118
4253
  {
4119
4254
  provide: SLATE_DEFAULT_ELEMENT_COMPONENT_TOKEN,
@@ -4131,5 +4266,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImpor
4131
4266
  * Generated bundle index. Do not edit.
4132
4267
  */
4133
4268
 
4134
- export { AngularEditor, BaseComponent, BaseElementComponent, BaseLeafComponent, BaseTextComponent, DOMComment, DOMElement, DOMNode, DOMRange, DOMSelection, DOMStaticRange, DOMText, EDITOR_TO_ELEMENT, EDITOR_TO_ON_CHANGE, EDITOR_TO_PLACEHOLDER, EDITOR_TO_WINDOW, ELEMENT_TO_COMPONENT, ELEMENT_TO_NODE, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_CLICKING, IS_DRAGGING, IS_EDGE_LEGACY, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_FOCUSED, IS_IOS, IS_QQBROWSER, IS_READONLY, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, KEY_TO_ELEMENT, Key, NODE_TO_ELEMENT, NODE_TO_INDEX, NODE_TO_KEY, NODE_TO_PARENT, PLACEHOLDER_SYMBOL, SlateChildren, SlateDefaultString, SlateEditable, SlateElement, SlateErrorCode, SlateLeaves, SlateModule, SlateString, check, defaultScrollSelectionIntoView, getCardTargetAttribute, getClipboardData, getDefaultView, getEditableChild, getEditableChildAndIndex, getPlainText, getSlateFragmentAttribute, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hasEditableTarget, hasShadowRoot, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isComponentType, isDOMComment, isDOMElement, isDOMNode, isDOMSelection, isDOMText, isDecoratorRangeListEqual, isEmpty, isPlainTextOnlyPaste, isTemplateRef, isValid, normalize, normalizeDOMPoint, shallowCompare, withAngular };
4269
+ export { AngularEditor, BaseComponent, BaseElementComponent, BaseLeafComponent, BaseTextComponent, DOMComment, DOMElement, DOMNode, DOMRange, DOMSelection, DOMStaticRange, DOMText, EDITOR_TO_ELEMENT, EDITOR_TO_ON_CHANGE, EDITOR_TO_PLACEHOLDER, EDITOR_TO_WINDOW, ELEMENT_TO_COMPONENT, ELEMENT_TO_NODE, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_CLICKING, IS_DRAGGING, IS_EDGE_LEGACY, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_FOCUSED, IS_IOS, IS_QQBROWSER, IS_READONLY, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, KEY_TO_ELEMENT, Key, NODE_TO_ELEMENT, NODE_TO_INDEX, NODE_TO_KEY, NODE_TO_PARENT, PLACEHOLDER_SYMBOL, SlateChildren, SlateChildrenOutlet, SlateDefaultString, SlateEditable, SlateElement, SlateErrorCode, SlateLeaves, SlateModule, SlateString, check, createThrottleRAF, defaultScrollSelectionIntoView, getCardTargetAttribute, getClipboardData, getDefaultView, getEditableChild, getEditableChildAndIndex, getPlainText, getSlateFragmentAttribute, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hasEditableTarget, hasShadowRoot, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isComponentType, isDOMComment, isDOMElement, isDOMNode, isDOMSelection, isDOMText, isDecoratorRangeListEqual, isEmpty, isPlainTextOnlyPaste, isTemplateRef, isValid, normalize, normalizeDOMPoint, shallowCompare, withAngular };
4135
4270
  //# sourceMappingURL=slate-angular.mjs.map