slate-angular 20.2.4 → 20.2.6

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.
@@ -1454,6 +1454,7 @@ const isDebugScrollTop = localStorage.getItem(SLATE_DEBUG_KEY_SCROLL_TOP) === 't
1454
1454
  const ELEMENT_KEY_TO_HEIGHTS = new WeakMap();
1455
1455
  const EDITOR_TO_BUSINESS_TOP = new WeakMap();
1456
1456
  const EDITOR_TO_ROOT_NODE_WIDTH = new WeakMap();
1457
+ const EDITOR_TO_IS_FROM_SCROLL_TO = new WeakMap();
1457
1458
  const debugLog = (type, ...args) => {
1458
1459
  const doc = document;
1459
1460
  VirtualScrollDebugOverlay.log(doc, type, ...args);
@@ -1473,7 +1474,7 @@ const measureHeightByIndics = (editor, indics, force = false) => {
1473
1474
  let hasChanged = false;
1474
1475
  indics.forEach((index, i) => {
1475
1476
  const element = editor.children[index];
1476
- const preHeight = getRealHeightByElement(editor, element, 0);
1477
+ const preHeight = getRealHeightByElement(editor, element);
1477
1478
  if (preHeight && !force) {
1478
1479
  if (isDebug) {
1479
1480
  const height = measureHeightByElement(editor, element);
@@ -1491,7 +1492,7 @@ const measureHeightByIndics = (editor, indics, force = false) => {
1491
1492
  const getBusinessTop = (editor) => {
1492
1493
  return EDITOR_TO_BUSINESS_TOP.get(editor) ?? 0;
1493
1494
  };
1494
- const getRealHeightByElement = (editor, element, defaultHeight) => {
1495
+ const getRealHeightByElement = (editor, element) => {
1495
1496
  const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
1496
1497
  const key = AngularEditor.findKey(editor, element);
1497
1498
  const height = heights?.get(key.id);
@@ -1501,7 +1502,7 @@ const getRealHeightByElement = (editor, element, defaultHeight) => {
1501
1502
  if (heights?.has(key.id)) {
1502
1503
  console.error('getBlockHeight: invalid height value', key.id, height);
1503
1504
  }
1504
- return editor.getRoughHeight(element, defaultHeight);
1505
+ return null;
1505
1506
  };
1506
1507
  const buildHeightsAndAccumulatedHeights = (editor) => {
1507
1508
  const children = (editor.children || []);
@@ -1509,7 +1510,7 @@ const buildHeightsAndAccumulatedHeights = (editor) => {
1509
1510
  const accumulatedHeights = new Array(children.length + 1);
1510
1511
  accumulatedHeights[0] = 0;
1511
1512
  for (let i = 0; i < children.length; i++) {
1512
- const height = getRealHeightByElement(editor, children[i], VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT);
1513
+ const height = getRealHeightByElement(editor, children[i]) || editor.getRoughHeight(children[i]);
1513
1514
  heights[i] = height;
1514
1515
  accumulatedHeights[i + 1] = accumulatedHeights[i] + height;
1515
1516
  }
@@ -1530,6 +1531,11 @@ const scrollToElement = (editor, element, scrollTo) => {
1530
1531
  }
1531
1532
  const { accumulatedHeights } = buildHeightsAndAccumulatedHeights(editor);
1532
1533
  scrollTo((accumulatedHeights[anchorIndex] ?? 0) + getBusinessTop(editor));
1534
+ EDITOR_TO_IS_FROM_SCROLL_TO.set(editor, true);
1535
+ setTimeout(() => {
1536
+ console.log('scrollToElement: end scroll');
1537
+ EDITOR_TO_IS_FROM_SCROLL_TO.set(editor, false);
1538
+ }, 0);
1533
1539
  };
1534
1540
 
1535
1541
  const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
@@ -3083,10 +3089,11 @@ class ListRender {
3083
3089
  for (let i = 0; i < children.length; i++) {
3084
3090
  const rootNodes = [...getRootNodes(this.views[i], this.blockCards[i])];
3085
3091
  const index = this.viewContext.editor.children.indexOf(children[i]);
3086
- const height = getRealHeightByElement(this.viewContext.editor, children[i]);
3092
+ const height = getRealHeightByElement(this.viewContext.editor, children[i]) ||
3093
+ this.viewContext.editor.getRoughHeight(children[i]);
3087
3094
  rootNodes.forEach(rootNode => {
3088
3095
  rootNode.setAttribute('debug-index', index.toString());
3089
- rootNode.setAttribute('debug-height', height.toString());
3096
+ rootNode.setAttribute('debug-height', height?.toString());
3090
3097
  });
3091
3098
  }
3092
3099
  }
@@ -3801,7 +3808,8 @@ class SlateEditable {
3801
3808
  if (isDebug) {
3802
3809
  debugLog('log', 'tryUpdateVirtualViewport');
3803
3810
  }
3804
- if (this.inViewportIndics.length > 0) {
3811
+ const isFromScrollTo = EDITOR_TO_IS_FROM_SCROLL_TO.get(this.editor);
3812
+ if (this.inViewportIndics.length > 0 && !isFromScrollTo) {
3805
3813
  const topHeight = this.getActualVirtualTopHeight();
3806
3814
  const refreshVirtualTopHeight = calculateVirtualTopHeight(this.editor, this.inViewportIndics[0]);
3807
3815
  if (topHeight !== refreshVirtualTopHeight) {
@@ -3819,7 +3827,7 @@ class SlateEditable {
3819
3827
  }
3820
3828
  let virtualView = this.calculateVirtualViewport();
3821
3829
  let diff = this.diffVirtualViewport(virtualView);
3822
- if (diff.isDifferent && diff.needRemoveOnTop) {
3830
+ if (diff.isDifferent && diff.needRemoveOnTop && !isFromScrollTo) {
3823
3831
  const remeasureIndics = diff.changedIndexesOfTop;
3824
3832
  const changed = measureHeightByIndics(this.editor, remeasureIndics);
3825
3833
  if (changed) {
@@ -3832,7 +3840,7 @@ class SlateEditable {
3832
3840
  if (this.listRender.initialized) {
3833
3841
  const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.handlePreRendering();
3834
3842
  this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount, childrenWithPreRenderingIndics);
3835
- if (diff.needAddOnTop) {
3843
+ if (diff.needAddOnTop && !isFromScrollTo) {
3836
3844
  const remeasureAddedIndics = diff.changedIndexesOfTop;
3837
3845
  if (isDebug) {
3838
3846
  debugLog('log', 'needAddOnTop to remeasure heights: ', remeasureAddedIndics);
@@ -4021,11 +4029,9 @@ class SlateEditable {
4021
4029
  debugLog('log', 'oldIndexesInViewport:', oldIndexesInViewport);
4022
4030
  debugLog('log', 'newIndexesInViewport:', newIndexesInViewport);
4023
4031
  // 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)) ||
4032
+ debugLog('log', 'changedIndexesOfTop:', needRemoveOnTop ? '-' : needAddOnTop ? '+' : '-', changedIndexesOfTop, changedIndexesOfTop.map(index => (this.editor.children[index] && getRealHeightByElement(this.editor, this.editor.children[index])) ||
4026
4033
  0));
4027
- debugLog('log', 'changedIndexesOfBottom:', needAddOnBottom ? '+' : needRemoveOnBottom ? '-' : '+', changedIndexesOfBottom, changedIndexesOfBottom.map(index => (this.editor.children[index] &&
4028
- getRealHeightByElement(this.editor, this.editor.children[index], 0)) ||
4034
+ debugLog('log', 'changedIndexesOfBottom:', needAddOnBottom ? '+' : needRemoveOnBottom ? '-' : '+', changedIndexesOfBottom, changedIndexesOfBottom.map(index => (this.editor.children[index] && getRealHeightByElement(this.editor, this.editor.children[index])) ||
4029
4035
  0));
4030
4036
  const needTop = virtualView.heights.slice(0, newIndexesInViewport[0]).reduce((acc, height) => acc + height, 0);
4031
4037
  const needBottom = virtualView.heights
@@ -5273,5 +5279,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
5273
5279
  * Generated bundle index. Do not edit.
5274
5280
  */
5275
5281
 
5276
- 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_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, calculateVirtualTopHeight, check, completeTable, createClipboardData, createText, createThrottleRAF, debugLog, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getBusinessTop, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getContentHeight, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText, getRealHeightByElement, 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, measureHeightByElement, measureHeightByIndics, normalize, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5282
+ 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, calculateVirtualTopHeight, check, completeTable, createClipboardData, createText, createThrottleRAF, debugLog, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getBusinessTop, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getContentHeight, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText, getRealHeightByElement, 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, measureHeightByElement, measureHeightByIndics, normalize, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5277
5283
  //# sourceMappingURL=slate-angular.mjs.map