slate-angular 20.2.13 → 20.2.14

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.
@@ -1498,6 +1498,9 @@ const ELEMENT_KEY_TO_HEIGHTS = new WeakMap();
1498
1498
  const EDITOR_TO_BUSINESS_TOP = new WeakMap();
1499
1499
  const EDITOR_TO_ROOT_NODE_WIDTH = new WeakMap();
1500
1500
  const EDITOR_TO_IS_FROM_SCROLL_TO = new WeakMap();
1501
+ const isValidNumber = (value) => {
1502
+ return typeof value === 'number' && !Number.isNaN(value);
1503
+ };
1501
1504
  const debugLog = (type, ...args) => {
1502
1505
  const doc = document;
1503
1506
  VirtualScrollDebugOverlay.log(doc, type, ...args);
@@ -1506,7 +1509,7 @@ const cacheHeightByElement = (editor, element, height) => {
1506
1509
  if (!AngularEditor.isEnabledVirtualScroll(editor)) {
1507
1510
  return;
1508
1511
  }
1509
- if (typeof height !== 'number') {
1512
+ if (!isValidNumber(height)) {
1510
1513
  console.error('cacheHeightByElement: height must be number', height);
1511
1514
  return;
1512
1515
  }
@@ -1565,9 +1568,11 @@ const measureHeightByIndics = (editor, indics, force = false) => {
1565
1568
  }
1566
1569
  return;
1567
1570
  }
1568
- hasChanged = true;
1569
1571
  const currentHeight = calcHeightByElement(editor, element);
1570
- if (isDebug) {
1572
+ if (isValidNumber(currentHeight) && currentHeight !== preHeight) {
1573
+ hasChanged = true;
1574
+ }
1575
+ if (isDebug && isValidNumber(currentHeight)) {
1571
1576
  debugLog('log', 'measureHeightByIndics: height not equal, index: ', index, 'preHeight: ', preHeight, 'height: ', currentHeight);
1572
1577
  }
1573
1578
  });
@@ -3837,12 +3842,14 @@ class SlateEditable {
3837
3842
  });
3838
3843
  }), debounceTime(500), filter(() => pendingRemeasureIndics.length > 0))
3839
3844
  .subscribe(() => {
3840
- measureHeightByIndics(this.editor, pendingRemeasureIndics, true);
3841
- pendingRemeasureIndics = [];
3842
- if (isDebug) {
3843
- debugLog('log', 'exist pendingRemeasureIndics: ', pendingRemeasureIndics, 'will try to update virtual viewport');
3845
+ const changed = measureHeightByIndics(this.editor, pendingRemeasureIndics, true);
3846
+ if (changed) {
3847
+ this.tryUpdateVirtualViewport();
3848
+ if (isDebug) {
3849
+ debugLog('log', 'exist pendingRemeasureIndics: ', pendingRemeasureIndics, 'will try to update virtual viewport');
3850
+ }
3844
3851
  }
3845
- this.tryUpdateVirtualViewport();
3852
+ pendingRemeasureIndics = [];
3846
3853
  });
3847
3854
  }
3848
3855
  }
@@ -3973,7 +3980,7 @@ class SlateEditable {
3973
3980
  };
3974
3981
  }
3975
3982
  const scrollTop = this.virtualScrollConfig.scrollTop;
3976
- const viewportHeight = this.virtualScrollConfig.viewportHeight ?? 0;
3983
+ let viewportHeight = this.virtualScrollConfig.viewportHeight ?? 0;
3977
3984
  if (!viewportHeight) {
3978
3985
  return {
3979
3986
  inViewportChildren: [],
@@ -3994,20 +4001,23 @@ class SlateEditable {
3994
4001
  EDITOR_TO_BUSINESS_TOP.set(this.editor, businessTop);
3995
4002
  if (isDebug) {
3996
4003
  debugLog('log', 'businessTop', businessTop);
4004
+ this.virtualTopHeightElement.setAttribute('data-business-top', businessTop.toString());
3997
4005
  }
3998
4006
  }, 100);
3999
4007
  }
4000
- const adjustedScrollTop = Math.max(0, scrollTop - getBusinessTop(this.editor));
4008
+ const businessTop = getBusinessTop(this.editor);
4001
4009
  const { heights, accumulatedHeights } = buildHeightsAndAccumulatedHeights(this.editor, visibleStates);
4002
- const totalHeight = accumulatedHeights[elementLength];
4003
- const maxScrollTop = Math.max(0, totalHeight - viewportHeight);
4004
- const limitedScrollTop = Math.min(adjustedScrollTop, maxScrollTop);
4005
- const viewBottom = limitedScrollTop + viewportHeight;
4010
+ const totalHeight = accumulatedHeights[elementLength] + businessTop;
4011
+ let startPosition = Math.max(scrollTop - businessTop, 0);
4012
+ let endPosition = startPosition + viewportHeight;
4013
+ if (scrollTop < businessTop) {
4014
+ endPosition = startPosition + viewportHeight - (businessTop - scrollTop);
4015
+ }
4006
4016
  let accumulatedOffset = 0;
4007
4017
  let inViewportStartIndex = -1;
4008
4018
  const visible = [];
4009
4019
  const inViewportIndics = [];
4010
- for (let i = 0; i < elementLength && accumulatedOffset < viewBottom; i++) {
4020
+ for (let i = 0; i < elementLength && accumulatedOffset < endPosition; i++) {
4011
4021
  const currentHeight = heights[i];
4012
4022
  const nextOffset = accumulatedOffset + currentHeight;
4013
4023
  const isVisible = visibleStates[i];
@@ -4016,7 +4026,7 @@ class SlateEditable {
4016
4026
  continue;
4017
4027
  }
4018
4028
  // 可视区域有交集,加入渲染
4019
- if (nextOffset > limitedScrollTop && accumulatedOffset < viewBottom) {
4029
+ if (nextOffset > startPosition && accumulatedOffset < endPosition) {
4020
4030
  if (inViewportStartIndex === -1)
4021
4031
  inViewportStartIndex = i; // 第一个相交起始位置
4022
4032
  visible.push(children[i]);
@@ -5373,5 +5383,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
5373
5383
  * Generated bundle index. Do not edit.
5374
5384
  */
5375
5385
 
5376
- export { AngularEditor, BaseComponent, BaseElementComponent, BaseElementFlavour, BaseFlavour, BaseLeafComponent, BaseLeafFlavour, BaseTextComponent, BaseTextFlavour, BlockCardRef, DEFAULT_ELEMENT_HEIGHT, DefaultTextFlavour, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, EDITOR_TO_BUSINESS_TOP, EDITOR_TO_IS_FROM_SCROLL_TO, EDITOR_TO_ROOT_NODE_WIDTH, EDITOR_TO_VIRTUAL_SCROLL_SELECTION, ELEMENT_KEY_TO_HEIGHTS, ELEMENT_TO_COMPONENT, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, FlavourRef, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_ENABLED_VIRTUAL_SCROLL, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_IOS, IS_QQBROWSER, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, PLACEHOLDER_SYMBOL, SLATE_BLOCK_CARD_CLASS_NAME, SLATE_DEBUG_KEY, SLATE_DEBUG_KEY_SCROLL_TOP, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, SlateString, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VoidTextFlavour, blobAsString, buildHTMLText, buildHeightsAndAccumulatedHeights, cacheHeightByElement, calcHeightByElement, calculateVirtualTopHeight, check, clearMinHeightByElement, completeTable, createClipboardData, createText, createThrottleRAF, debugLog, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getBusinessTop, getCachedHeightByElement, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getContentHeight, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText, getSelection, getSlateFragmentAttribute, getZeroTextNode, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, isClipboardWriteTextSupported, isComponentType, isDOMText, isDebug, isDebugScrollTop, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isTemplateRef, isValid, measureHeightByIndics, normalize, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setMinHeightByElement, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5386
+ export { AngularEditor, BaseComponent, BaseElementComponent, BaseElementFlavour, BaseFlavour, BaseLeafComponent, BaseLeafFlavour, BaseTextComponent, BaseTextFlavour, BlockCardRef, DEFAULT_ELEMENT_HEIGHT, DefaultTextFlavour, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, EDITOR_TO_BUSINESS_TOP, EDITOR_TO_IS_FROM_SCROLL_TO, EDITOR_TO_ROOT_NODE_WIDTH, EDITOR_TO_VIRTUAL_SCROLL_SELECTION, ELEMENT_KEY_TO_HEIGHTS, ELEMENT_TO_COMPONENT, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, FlavourRef, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_ENABLED_VIRTUAL_SCROLL, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_IOS, IS_QQBROWSER, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, PLACEHOLDER_SYMBOL, SLATE_BLOCK_CARD_CLASS_NAME, SLATE_DEBUG_KEY, SLATE_DEBUG_KEY_SCROLL_TOP, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, SlateString, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VoidTextFlavour, blobAsString, buildHTMLText, buildHeightsAndAccumulatedHeights, cacheHeightByElement, calcHeightByElement, calculateVirtualTopHeight, check, clearMinHeightByElement, completeTable, createClipboardData, createText, createThrottleRAF, debugLog, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getBusinessTop, getCachedHeightByElement, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getContentHeight, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText, getSelection, getSlateFragmentAttribute, getZeroTextNode, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, isClipboardWriteTextSupported, isComponentType, isDOMText, isDebug, isDebugScrollTop, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isTemplateRef, isValid, isValidNumber, measureHeightByIndics, normalize, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setMinHeightByElement, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5377
5387
  //# sourceMappingURL=slate-angular.mjs.map