slate-angular 20.2.0-next.19 → 20.2.0-next.20

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.
@@ -475,7 +475,7 @@ const HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY &&
475
475
  globalThis.InputEvent &&
476
476
  // @ts-ignore The `getTargetRanges` property isn't recognized.
477
477
  typeof globalThis.InputEvent.prototype.getTargetRanges === 'function';
478
- const VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT = 40;
478
+ const VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT = 30;
479
479
  const SLATE_DEBUG_KEY = '__SLATE_DEBUG__';
480
480
 
481
481
  /**
@@ -955,6 +955,10 @@ const fallbackCopyText = async (text) => {
955
955
  };
956
956
 
957
957
  const ELEMENT_KEY_TO_HEIGHTS = new WeakMap();
958
+ const EDITOR_TO_BUSINESS_TOP = new WeakMap();
959
+ const getBusinessTop = (editor) => {
960
+ return EDITOR_TO_BUSINESS_TOP.get(editor) ?? 0;
961
+ };
958
962
  const getRealHeightByElement = (editor, element, defaultHeight = VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT) => {
959
963
  const isVisible = editor.isVisible(element);
960
964
  if (!isVisible) {
@@ -996,7 +1000,7 @@ const scrollToElement = (editor, element, scrollTo) => {
996
1000
  return;
997
1001
  }
998
1002
  const { accumulatedHeights } = buildHeightsAndAccumulatedHeights(editor);
999
- scrollTo(accumulatedHeights[anchorIndex] ?? 0);
1003
+ scrollTo((accumulatedHeights[anchorIndex] ?? 0) + getBusinessTop(editor));
1000
1004
  };
1001
1005
 
1002
1006
  const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
@@ -3136,6 +3140,7 @@ const isDebug = localStorage.getItem(SLATE_DEBUG_KEY) === 'true';
3136
3140
  class SlateEditable {
3137
3141
  set virtualScroll(config) {
3138
3142
  this.virtualScrollConfig = config;
3143
+ console.log('virtualScrollConfig', config);
3139
3144
  IS_ENABLED_VIRTUAL_SCROLL.set(this.editor, config.enabled);
3140
3145
  if (this.isEnabledVirtualScroll()) {
3141
3146
  this.tryUpdateVirtualViewport();
@@ -3187,13 +3192,12 @@ class SlateEditable {
3187
3192
  this.virtualScrollConfig = {
3188
3193
  enabled: false,
3189
3194
  scrollTop: 0,
3190
- viewportHeight: 0
3195
+ viewportHeight: 0,
3196
+ viewportBoundingTop: 0
3191
3197
  };
3192
3198
  this.inViewportChildren = [];
3193
3199
  this.inViewportIndics = new Set();
3194
3200
  this.keyHeightMap = new Map();
3195
- // the height from scroll container top to editor top height element
3196
- this.businessHeight = 0;
3197
3201
  this.virtualScrollInitialized = false;
3198
3202
  }
3199
3203
  ngOnInit() {
@@ -3568,7 +3572,6 @@ class SlateEditable {
3568
3572
  this.elementRef.nativeElement.appendChild(this.virtualTopHeightElement);
3569
3573
  this.elementRef.nativeElement.appendChild(this.virtualCenterOutlet);
3570
3574
  this.elementRef.nativeElement.appendChild(this.virtualBottomHeightElement);
3571
- this.businessHeight = this.virtualTopHeightElement.getBoundingClientRect()?.top ?? 0;
3572
3575
  let editorResizeObserverRectWidth = this.elementRef.nativeElement.getBoundingClientRect()?.width ?? 0;
3573
3576
  this.editorResizeObserver = new ResizeObserver(entries => {
3574
3577
  if (entries.length > 0 && entries[0].contentRect.width !== editorResizeObserverRectWidth) {
@@ -3603,6 +3606,7 @@ class SlateEditable {
3603
3606
  if (!diff.isDiff) {
3604
3607
  return;
3605
3608
  }
3609
+ // diff.isAddedTop
3606
3610
  if (diff.isMissingTop) {
3607
3611
  const remeasureIndics = diff.diffTopRenderedIndexes;
3608
3612
  const result = this.remeasureHeightByIndics(remeasureIndics);
@@ -3651,12 +3655,25 @@ class SlateEditable {
3651
3655
  };
3652
3656
  }
3653
3657
  const elementLength = children.length;
3654
- const adjustedScrollTop = Math.max(0, scrollTop - this.businessHeight);
3658
+ if (!EDITOR_TO_BUSINESS_TOP.has(this.editor)) {
3659
+ EDITOR_TO_BUSINESS_TOP.set(this.editor, 0);
3660
+ setTimeout(() => {
3661
+ const virtualTopBoundingTop = this.virtualTopHeightElement.getBoundingClientRect()?.top ?? 0;
3662
+ const businessTop = Math.ceil(virtualTopBoundingTop) +
3663
+ Math.ceil(this.virtualScrollConfig.scrollTop) -
3664
+ Math.floor(this.virtualScrollConfig.viewportBoundingTop);
3665
+ EDITOR_TO_BUSINESS_TOP.set(this.editor, businessTop);
3666
+ if (isDebug) {
3667
+ this.debugLog('log', 'businessTop', businessTop);
3668
+ }
3669
+ }, 100);
3670
+ }
3671
+ const adjustedScrollTop = Math.max(0, scrollTop - getBusinessTop(this.editor));
3655
3672
  const { heights, accumulatedHeights } = buildHeightsAndAccumulatedHeights(this.editor);
3656
3673
  const totalHeight = accumulatedHeights[elementLength];
3657
3674
  const maxScrollTop = Math.max(0, totalHeight - viewportHeight);
3658
3675
  const limitedScrollTop = Math.min(adjustedScrollTop, maxScrollTop);
3659
- const viewBottom = limitedScrollTop + viewportHeight + this.businessHeight;
3676
+ const viewBottom = limitedScrollTop + viewportHeight + getBusinessTop(this.editor);
3660
3677
  let accumulatedOffset = 0;
3661
3678
  let visibleStartIndex = -1;
3662
3679
  const visible = [];
@@ -5074,5 +5091,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
5074
5091
  * Generated bundle index. Do not edit.
5075
5092
  */
5076
5093
 
5077
- export { AngularEditor, BaseComponent, BaseElementComponent, BaseElementFlavour, BaseFlavour, BaseLeafComponent, BaseLeafFlavour, BaseTextComponent, BaseTextFlavour, BlockCardRef, DEFAULT_ELEMENT_HEIGHT, DefaultTextFlavour, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, 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, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VoidTextFlavour, blobAsString, buildHTMLText, buildHeightsAndAccumulatedHeights, check, completeTable, createClipboardData, createText, createThrottleRAF, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, 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, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isTemplateRef, isValid, normalize, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5094
+ 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_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, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VoidTextFlavour, blobAsString, buildHTMLText, buildHeightsAndAccumulatedHeights, check, completeTable, createClipboardData, createText, createThrottleRAF, 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, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isTemplateRef, isValid, normalize, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5078
5095
  //# sourceMappingURL=slate-angular.mjs.map