slate-angular 20.2.3 → 20.2.5

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.
@@ -1473,7 +1473,7 @@ const measureHeightByIndics = (editor, indics, force = false) => {
1473
1473
  let hasChanged = false;
1474
1474
  indics.forEach((index, i) => {
1475
1475
  const element = editor.children[index];
1476
- const preHeight = getRealHeightByElement(editor, element, 0);
1476
+ const preHeight = getRealHeightByElement(editor, element);
1477
1477
  if (preHeight && !force) {
1478
1478
  if (isDebug) {
1479
1479
  const height = measureHeightByElement(editor, element);
@@ -1491,7 +1491,7 @@ const measureHeightByIndics = (editor, indics, force = false) => {
1491
1491
  const getBusinessTop = (editor) => {
1492
1492
  return EDITOR_TO_BUSINESS_TOP.get(editor) ?? 0;
1493
1493
  };
1494
- const getRealHeightByElement = (editor, element, defaultHeight) => {
1494
+ const getRealHeightByElement = (editor, element) => {
1495
1495
  const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
1496
1496
  const key = AngularEditor.findKey(editor, element);
1497
1497
  const height = heights?.get(key.id);
@@ -1501,20 +1501,19 @@ const getRealHeightByElement = (editor, element, defaultHeight) => {
1501
1501
  if (heights?.has(key.id)) {
1502
1502
  console.error('getBlockHeight: invalid height value', key.id, height);
1503
1503
  }
1504
- return editor.getRoughHeight(element, defaultHeight);
1504
+ return null;
1505
1505
  };
1506
1506
  const buildHeightsAndAccumulatedHeights = (editor) => {
1507
1507
  const children = (editor.children || []);
1508
1508
  const heights = new Array(children.length);
1509
- const visibleStates = new Array(children.length);
1510
1509
  const accumulatedHeights = new Array(children.length + 1);
1511
1510
  accumulatedHeights[0] = 0;
1512
1511
  for (let i = 0; i < children.length; i++) {
1513
- const height = getRealHeightByElement(editor, children[i], VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT);
1512
+ const height = getRealHeightByElement(editor, children[i]) || editor.getRoughHeight(children[i]);
1514
1513
  heights[i] = height;
1515
1514
  accumulatedHeights[i + 1] = accumulatedHeights[i] + height;
1516
1515
  }
1517
- return { heights, accumulatedHeights, visibleStates };
1516
+ return { heights, accumulatedHeights };
1518
1517
  };
1519
1518
  const calculateVirtualTopHeight = (editor, startIndex) => {
1520
1519
  const { accumulatedHeights } = buildHeightsAndAccumulatedHeights(editor);
@@ -3084,10 +3083,11 @@ class ListRender {
3084
3083
  for (let i = 0; i < children.length; i++) {
3085
3084
  const rootNodes = [...getRootNodes(this.views[i], this.blockCards[i])];
3086
3085
  const index = this.viewContext.editor.children.indexOf(children[i]);
3087
- const height = getRealHeightByElement(this.viewContext.editor, children[i]);
3086
+ const height = getRealHeightByElement(this.viewContext.editor, children[i]) ||
3087
+ this.viewContext.editor.getRoughHeight(children[i]);
3088
3088
  rootNodes.forEach(rootNode => {
3089
3089
  rootNode.setAttribute('debug-index', index.toString());
3090
- rootNode.setAttribute('debug-height', height.toString());
3090
+ rootNode.setAttribute('debug-height', height?.toString());
3091
3091
  });
3092
3092
  }
3093
3093
  }
@@ -3899,7 +3899,7 @@ class SlateEditable {
3899
3899
  }, 100);
3900
3900
  }
3901
3901
  const adjustedScrollTop = Math.max(0, scrollTop - getBusinessTop(this.editor));
3902
- const { heights, accumulatedHeights, visibleStates } = buildHeightsAndAccumulatedHeights(this.editor);
3902
+ const { heights, accumulatedHeights } = buildHeightsAndAccumulatedHeights(this.editor);
3903
3903
  const totalHeight = accumulatedHeights[elementLength];
3904
3904
  const maxScrollTop = Math.max(0, totalHeight - viewportHeight);
3905
3905
  const limitedScrollTop = Math.min(adjustedScrollTop, maxScrollTop);
@@ -3911,7 +3911,8 @@ class SlateEditable {
3911
3911
  for (let i = 0; i < elementLength && accumulatedOffset < viewBottom; i++) {
3912
3912
  const currentHeight = heights[i];
3913
3913
  const nextOffset = accumulatedOffset + currentHeight;
3914
- if (!visibleStates[i]) {
3914
+ const isVisible = this.editor.isVisible(children[i]);
3915
+ if (!isVisible) {
3915
3916
  accumulatedOffset = nextOffset;
3916
3917
  continue;
3917
3918
  }
@@ -4021,11 +4022,9 @@ class SlateEditable {
4021
4022
  debugLog('log', 'oldIndexesInViewport:', oldIndexesInViewport);
4022
4023
  debugLog('log', 'newIndexesInViewport:', newIndexesInViewport);
4023
4024
  // this.editor.children[index] will be undefined when it is removed
4024
- debugLog('log', 'changedIndexesOfTop:', needRemoveOnTop ? '-' : needAddOnTop ? '+' : '-', changedIndexesOfTop, changedIndexesOfTop.map(index => (this.editor.children[index] &&
4025
- getRealHeightByElement(this.editor, this.editor.children[index], 0)) ||
4025
+ debugLog('log', 'changedIndexesOfTop:', needRemoveOnTop ? '-' : needAddOnTop ? '+' : '-', changedIndexesOfTop, changedIndexesOfTop.map(index => (this.editor.children[index] && getRealHeightByElement(this.editor, this.editor.children[index])) ||
4026
4026
  0));
4027
- debugLog('log', 'changedIndexesOfBottom:', needAddOnBottom ? '+' : needRemoveOnBottom ? '-' : '+', changedIndexesOfBottom, changedIndexesOfBottom.map(index => (this.editor.children[index] &&
4028
- getRealHeightByElement(this.editor, this.editor.children[index], 0)) ||
4027
+ debugLog('log', 'changedIndexesOfBottom:', needAddOnBottom ? '+' : needRemoveOnBottom ? '-' : '+', changedIndexesOfBottom, changedIndexesOfBottom.map(index => (this.editor.children[index] && getRealHeightByElement(this.editor, this.editor.children[index])) ||
4029
4028
  0));
4030
4029
  const needTop = virtualView.heights.slice(0, newIndexesInViewport[0]).reduce((acc, height) => acc + height, 0);
4031
4030
  const needBottom = virtualView.heights