slate-angular 20.2.1 → 20.2.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.
@@ -1510,17 +1510,17 @@ const getRealHeightByElement = (editor, element, defaultHeight = VIRTUAL_SCROLL_
1510
1510
  const buildHeightsAndAccumulatedHeights = (editor) => {
1511
1511
  const children = (editor.children || []);
1512
1512
  const heights = new Array(children.length);
1513
- const visibles = new Array(children.length);
1513
+ const visibleStates = new Array(children.length);
1514
1514
  const accumulatedHeights = new Array(children.length + 1);
1515
1515
  accumulatedHeights[0] = 0;
1516
1516
  for (let i = 0; i < children.length; i++) {
1517
1517
  const isVisible = editor.isVisible(children[i]);
1518
- visibles[i] = isVisible;
1518
+ visibleStates[i] = isVisible;
1519
1519
  const height = getRealHeightByElement(editor, children[i], VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, isVisible);
1520
1520
  heights[i] = height;
1521
1521
  accumulatedHeights[i + 1] = accumulatedHeights[i] + height;
1522
1522
  }
1523
- return { heights, accumulatedHeights, visibles };
1523
+ return { heights, accumulatedHeights, visibleStates };
1524
1524
  };
1525
1525
  const calculateVirtualTopHeight = (editor, startIndex) => {
1526
1526
  const { accumulatedHeights } = buildHeightsAndAccumulatedHeights(editor);
@@ -2622,6 +2622,9 @@ class SlateStringRender {
2622
2622
  if (this.type === StringType.normalString) {
2623
2623
  this.nativeElement.textContent = this.leaf.text;
2624
2624
  }
2625
+ if (this.type === StringType.compatibleString) {
2626
+ updateCompatibleStringNode(this.nativeElement, this.leaf.text);
2627
+ }
2625
2628
  }
2626
2629
  getElementStringLength() {
2627
2630
  return Node.string(this.context.parent).length;
@@ -2656,6 +2659,12 @@ const createCompatibleStringNode = (text) => {
2656
2659
  stringNode.appendChild(zeroWidthSpan);
2657
2660
  return stringNode;
2658
2661
  };
2662
+ const updateCompatibleStringNode = (stringNode, text) => {
2663
+ const zeroWidthSpan = stringNode.querySelector('span');
2664
+ stringNode.textContent = text;
2665
+ stringNode.appendChild(zeroWidthSpan);
2666
+ return stringNode;
2667
+ };
2659
2668
  const createLineBreakEmptyStringDOM = (elementStringLength) => {
2660
2669
  const stringNode = document.createElement('span');
2661
2670
  stringNode.setAttribute('data-slate-zero-width', 'n');
@@ -3628,7 +3637,16 @@ class SlateEditable {
3628
3637
  }
3629
3638
  }
3630
3639
  updateListRenderAndRemeasureHeights() {
3631
- const virtualView = this.calculateVirtualViewport();
3640
+ let virtualView = this.calculateVirtualViewport();
3641
+ let diff = this.diffVirtualViewport(virtualView, 'onChange');
3642
+ if (diff.isDifferent && diff.needRemoveOnTop) {
3643
+ const remeasureIndics = diff.changedIndexesOfTop;
3644
+ const changed = measureHeightByIndics(this.editor, remeasureIndics);
3645
+ if (changed) {
3646
+ virtualView = this.calculateVirtualViewport();
3647
+ diff = this.diffVirtualViewport(virtualView, 'second');
3648
+ }
3649
+ }
3632
3650
  const oldInViewportChildren = this.inViewportChildren;
3633
3651
  this.applyVirtualView(virtualView);
3634
3652
  const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.handlePreRendering();
@@ -3640,9 +3658,6 @@ class SlateEditable {
3640
3658
  remeasureIndics.push(this.inViewportIndics[index]);
3641
3659
  }
3642
3660
  });
3643
- if (isDebug && remeasureIndics.length > 0) {
3644
- console.log('remeasure height by indics: ', remeasureIndics);
3645
- }
3646
3661
  }
3647
3662
  updateContext() {
3648
3663
  const decorations = this.generateDecorations();
@@ -3881,7 +3896,7 @@ class SlateEditable {
3881
3896
  }, 100);
3882
3897
  }
3883
3898
  const adjustedScrollTop = Math.max(0, scrollTop - getBusinessTop(this.editor));
3884
- const { heights, accumulatedHeights, visibles } = buildHeightsAndAccumulatedHeights(this.editor);
3899
+ const { heights, accumulatedHeights, visibleStates } = buildHeightsAndAccumulatedHeights(this.editor);
3885
3900
  const totalHeight = accumulatedHeights[elementLength];
3886
3901
  const maxScrollTop = Math.max(0, totalHeight - viewportHeight);
3887
3902
  const limitedScrollTop = Math.min(adjustedScrollTop, maxScrollTop);
@@ -3893,7 +3908,7 @@ class SlateEditable {
3893
3908
  for (let i = 0; i < elementLength && accumulatedOffset < viewBottom; i++) {
3894
3909
  const currentHeight = heights[i];
3895
3910
  const nextOffset = accumulatedOffset + currentHeight;
3896
- if (!visibles[i]) {
3911
+ if (!visibleStates[i]) {
3897
3912
  accumulatedOffset = nextOffset;
3898
3913
  continue;
3899
3914
  }
@@ -4002,8 +4017,13 @@ class SlateEditable {
4002
4017
  debugLog('log', `====== diffVirtualViewport stage: ${stage} ======`);
4003
4018
  debugLog('log', 'oldIndexesInViewport:', oldIndexesInViewport);
4004
4019
  debugLog('log', 'newIndexesInViewport:', newIndexesInViewport);
4005
- debugLog('log', 'changedIndexesOfTop:', needRemoveOnTop ? '-' : needAddOnTop ? '+' : '-', changedIndexesOfTop, changedIndexesOfTop.map(index => getRealHeightByElement(this.editor, this.editor.children[index], 0)));
4006
- debugLog('log', 'changedIndexesOfBottom:', needAddOnBottom ? '+' : needRemoveOnBottom ? '-' : '+', changedIndexesOfBottom, changedIndexesOfBottom.map(index => getRealHeightByElement(this.editor, this.editor.children[index], 0)));
4020
+ // this.editor.children[index] will be undefined when it is removed
4021
+ debugLog('log', 'changedIndexesOfTop:', needRemoveOnTop ? '-' : needAddOnTop ? '+' : '-', changedIndexesOfTop, changedIndexesOfTop.map(index => (this.editor.children[index] &&
4022
+ getRealHeightByElement(this.editor, this.editor.children[index], 0)) ||
4023
+ 0));
4024
+ debugLog('log', 'changedIndexesOfBottom:', needAddOnBottom ? '+' : needRemoveOnBottom ? '-' : '+', changedIndexesOfBottom, changedIndexesOfBottom.map(index => (this.editor.children[index] &&
4025
+ getRealHeightByElement(this.editor, this.editor.children[index], 0)) ||
4026
+ 0));
4007
4027
  const needTop = virtualView.heights.slice(0, newIndexesInViewport[0]).reduce((acc, height) => acc + height, 0);
4008
4028
  const needBottom = virtualView.heights
4009
4029
  .slice(newIndexesInViewport[newIndexesInViewport.length - 1] + 1)