slate-angular 20.2.0-next.17 → 20.2.0-next.18

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.
@@ -954,6 +954,17 @@ const fallbackCopyText = async (text) => {
954
954
  });
955
955
  };
956
956
 
957
+ const ELEMENT_KEY_TO_HEIGHTS = new WeakMap();
958
+ // 可以完全替换 getBlockHeight
959
+ const getRealHeightByElement = (editor, element) => {
960
+ const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
961
+ const key = AngularEditor.findKey(editor, element);
962
+ return heights?.get(key.id) || 0;
963
+ };
964
+ // 滚动到元素位置
965
+ const scrollToElement = (editor, element, scrollTo) => {
966
+ };
967
+
957
968
  const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
958
969
  let e = editor;
959
970
  let { apply } = e;
@@ -3085,8 +3096,6 @@ class VirtualScrollDebugOverlay {
3085
3096
  }
3086
3097
  }
3087
3098
 
3088
- const JUST_NOW_UPDATED_VIRTUAL_VIEW = new WeakMap();
3089
- const ELEMENT_KEY_TO_HEIGHTS = new WeakMap();
3090
3099
  // not correctly clipboardData on beforeinput
3091
3100
  const forceOnDOMPaste = IS_SAFARI;
3092
3101
  const isDebug = localStorage.getItem(SLATE_DEBUG_KEY) === 'true';
@@ -3218,7 +3227,7 @@ class SlateEditable {
3218
3227
  else {
3219
3228
  this.listRender.update(childrenForRender, this.editor, this.context);
3220
3229
  }
3221
- this.scheduleMeasureVisibleHeights();
3230
+ this.tryMeasureInViewportChildrenHeights();
3222
3231
  }
3223
3232
  else {
3224
3233
  if (!this.listRender.initialized) {
@@ -3376,11 +3385,7 @@ class SlateEditable {
3376
3385
  forceRender() {
3377
3386
  this.updateContext();
3378
3387
  if (this.isEnabledVirtualScroll()) {
3379
- const virtualView = this.calculateVirtualViewport();
3380
- this.applyVirtualView(virtualView);
3381
- this.listRender.update(this.inViewportChildren, this.editor, this.context);
3382
- const visibleIndexes = Array.from(this.inViewportIndics);
3383
- this.remeasureHeightByIndics(visibleIndexes);
3388
+ this.updateListRenderAndRemeasureHeights();
3384
3389
  }
3385
3390
  else {
3386
3391
  this.listRender.update(this.editor.children, this.editor, this.context);
@@ -3424,16 +3429,31 @@ class SlateEditable {
3424
3429
  const changed = this.updateContext();
3425
3430
  if (changed) {
3426
3431
  if (this.isEnabledVirtualScroll()) {
3427
- const virtualView = this.calculateVirtualViewport();
3428
- this.applyVirtualView(virtualView);
3429
- this.listRender.update(virtualView.inViewportChildren, this.editor, this.context);
3430
- this.scheduleMeasureVisibleHeights();
3432
+ this.updateListRenderAndRemeasureHeights();
3431
3433
  }
3432
3434
  else {
3433
3435
  this.listRender.update(this.editor.children, this.editor, this.context);
3434
3436
  }
3435
3437
  }
3436
3438
  }
3439
+ updateListRenderAndRemeasureHeights() {
3440
+ const virtualView = this.calculateVirtualViewport();
3441
+ const oldInViewportChildren = this.inViewportChildren;
3442
+ this.applyVirtualView(virtualView);
3443
+ this.listRender.update(this.inViewportChildren, this.editor, this.context);
3444
+ // 新增或者修改的才需要重算,计算出这个结果
3445
+ const remeasureIndics = [];
3446
+ const newInViewportIndics = Array.from(this.inViewportIndics);
3447
+ this.inViewportChildren.forEach((child, index) => {
3448
+ if (oldInViewportChildren.indexOf(child) === -1) {
3449
+ remeasureIndics.push(newInViewportIndics[index]);
3450
+ }
3451
+ });
3452
+ if (isDebug && remeasureIndics.length > 0) {
3453
+ console.log('remeasure height by indics: ', remeasureIndics);
3454
+ }
3455
+ this.remeasureHeightByIndics(remeasureIndics);
3456
+ }
3437
3457
  updateContext() {
3438
3458
  const decorations = this.generateDecorations();
3439
3459
  if (this.context.selection !== this.editor.selection ||
@@ -3519,7 +3539,8 @@ class SlateEditable {
3519
3539
  this.editorResizeObserver = new ResizeObserver(entries => {
3520
3540
  if (entries.length > 0 && entries[0].contentRect.width !== editorResizeObserverRectWidth) {
3521
3541
  editorResizeObserverRectWidth = entries[0].contentRect.width;
3522
- this.remeasureHeightByIndics(Array.from(this.inViewportIndics));
3542
+ const remeasureIndics = Array.from(this.inViewportIndics);
3543
+ this.remeasureHeightByIndics(remeasureIndics);
3523
3544
  }
3524
3545
  });
3525
3546
  this.editorResizeObserver.observe(this.elementRef.nativeElement);
@@ -3541,15 +3562,16 @@ class SlateEditable {
3541
3562
  VirtualScrollDebugOverlay.log(doc, type, ...args);
3542
3563
  }
3543
3564
  tryUpdateVirtualViewport() {
3544
- this.refreshVirtualViewAnimId && cancelAnimationFrame(this.refreshVirtualViewAnimId);
3545
- this.refreshVirtualViewAnimId = requestAnimationFrame(() => {
3565
+ this.tryUpdateVirtualViewportAnimId && cancelAnimationFrame(this.tryUpdateVirtualViewportAnimId);
3566
+ this.tryUpdateVirtualViewportAnimId = requestAnimationFrame(() => {
3546
3567
  let virtualView = this.calculateVirtualViewport();
3547
3568
  let diff = this.diffVirtualViewport(virtualView);
3548
3569
  if (!diff.isDiff) {
3549
3570
  return;
3550
3571
  }
3551
3572
  if (diff.isMissingTop) {
3552
- const result = this.remeasureHeightByIndics(diff.diffTopRenderedIndexes);
3573
+ const remeasureIndics = diff.diffTopRenderedIndexes;
3574
+ const result = this.remeasureHeightByIndics(remeasureIndics);
3553
3575
  if (result) {
3554
3576
  virtualView = this.calculateVirtualViewport();
3555
3577
  diff = this.diffVirtualViewport(virtualView, 'second');
@@ -3565,7 +3587,7 @@ class SlateEditable {
3565
3587
  this.toNativeSelection();
3566
3588
  }
3567
3589
  }
3568
- this.scheduleMeasureVisibleHeights();
3590
+ this.tryMeasureInViewportChildrenHeights();
3569
3591
  });
3570
3592
  }
3571
3593
  calculateVirtualViewport() {
@@ -3759,12 +3781,12 @@ class SlateEditable {
3759
3781
  }
3760
3782
  return accumulatedHeights;
3761
3783
  }
3762
- scheduleMeasureVisibleHeights() {
3784
+ tryMeasureInViewportChildrenHeights() {
3763
3785
  if (!this.isEnabledVirtualScroll()) {
3764
3786
  return;
3765
3787
  }
3766
- this.measureVisibleHeightsAnimId && cancelAnimationFrame(this.measureVisibleHeightsAnimId);
3767
- this.measureVisibleHeightsAnimId = requestAnimationFrame(() => {
3788
+ this.tryMeasureInViewportChildrenHeightsAnimId && cancelAnimationFrame(this.tryMeasureInViewportChildrenHeightsAnimId);
3789
+ this.tryMeasureInViewportChildrenHeightsAnimId = requestAnimationFrame(() => {
3768
3790
  this.measureVisibleHeights();
3769
3791
  });
3770
3792
  }
@@ -3798,7 +3820,7 @@ class SlateEditable {
3798
3820
  remeasureHeightByIndics(indics) {
3799
3821
  const children = (this.editor.children || []);
3800
3822
  let isHeightChanged = false;
3801
- indics.forEach(index => {
3823
+ indics.forEach((index, i) => {
3802
3824
  const node = children[index];
3803
3825
  if (!node) {
3804
3826
  return;
@@ -3812,21 +3834,21 @@ class SlateEditable {
3812
3834
  const ret = view.getRealHeight();
3813
3835
  if (ret instanceof Promise) {
3814
3836
  ret.then(height => {
3837
+ this.keyHeightMap.set(key.id, height);
3815
3838
  if (height !== prevHeight) {
3816
- this.keyHeightMap.set(key.id, height);
3817
3839
  isHeightChanged = true;
3818
3840
  if (isDebug) {
3819
- this.debugLog('log', `remeasureHeightByIndics, index: ${index} prevHeight: ${prevHeight} newHeight: ${height}`);
3841
+ this.debugLog('log', `remeasure element height, index: ${index} prevHeight: ${prevHeight} newHeight: ${height}`);
3820
3842
  }
3821
3843
  }
3822
3844
  });
3823
3845
  }
3824
3846
  else {
3847
+ this.keyHeightMap.set(key.id, ret);
3825
3848
  if (ret !== prevHeight) {
3826
- this.keyHeightMap.set(key.id, ret);
3827
3849
  isHeightChanged = true;
3828
3850
  if (isDebug) {
3829
- this.debugLog('log', `remeasureHeightByIndics, index: ${index} prevHeight: ${prevHeight} newHeight: ${ret}`);
3851
+ this.debugLog('log', `remeasure element height, index: ${index} prevHeight: ${prevHeight} newHeight: ${ret}`);
3830
3852
  }
3831
3853
  }
3832
3854
  }
@@ -5046,5 +5068,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
5046
5068
  * Generated bundle index. Do not edit.
5047
5069
  */
5048
5070
 
5049
- 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, JUST_NOW_UPDATED_VIRTUAL_VIEW, PLACEHOLDER_SYMBOL, SLATE_BLOCK_CARD_CLASS_NAME, SLATE_DEBUG_KEY, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VoidTextFlavour, blobAsString, buildHTMLText, check, completeTable, createClipboardData, createText, createThrottleRAF, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, 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, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isTemplateRef, isValid, normalize, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5071
+ 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, 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 };
5050
5072
  //# sourceMappingURL=slate-angular.mjs.map