slate-angular 20.2.22 → 20.2.23

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.
@@ -389,6 +389,7 @@ const HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY &&
389
389
  const VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT = 32;
390
390
  const SLATE_DEBUG_KEY = '__SLATE_DEBUG__';
391
391
  const SLATE_DEBUG_KEY_SCROLL_TOP = '__SLATE_DEBUG_SCROLL_TOP__';
392
+ const SLATE_DEBUG_KEY_UPDATE = '__SLATE_DEBUG_UPDATE__';
392
393
 
393
394
  /**
394
395
  * Symbols.
@@ -1009,7 +1010,7 @@ const getBlockCardByNativeElement = (nativeElement) => {
1009
1010
  return null;
1010
1011
  };
1011
1012
 
1012
- const roundTo = (value, precision = 2) => {
1013
+ const roundTo = (value, precision = 1) => {
1013
1014
  const factor = 10 ** precision;
1014
1015
  const n = Math.round(value * factor) / factor;
1015
1016
  return Object.is(n, -0) ? 0 : n;
@@ -1020,6 +1021,7 @@ const VIRTUAL_BOTTOM_HEIGHT_CLASS_NAME = 'virtual-bottom-height';
1020
1021
  const VIRTUAL_CENTER_OUTLET_CLASS_NAME = 'virtual-center-outlet';
1021
1022
  const isDebug = localStorage.getItem(SLATE_DEBUG_KEY) === 'true';
1022
1023
  const isDebugScrollTop = localStorage.getItem(SLATE_DEBUG_KEY_SCROLL_TOP) === 'true';
1024
+ const isDebugUpdate = localStorage.getItem(SLATE_DEBUG_KEY_UPDATE) === 'true';
1023
1025
  const ELEMENT_KEY_TO_HEIGHTS = new WeakMap();
1024
1026
  const EDITOR_TO_BUSINESS_TOP = new WeakMap();
1025
1027
  const EDITOR_TO_VIRTUAL_SCROLL_CONFIG = new WeakMap();
@@ -1082,26 +1084,17 @@ const calcHeightByElement = (editor, element) => {
1082
1084
  cacheHeightByElement(editor, element, height);
1083
1085
  return height;
1084
1086
  };
1085
- const measureHeightByIndics = (editor, indics, force = false) => {
1087
+ const measureHeightByIndics = (editor, indics, source) => {
1086
1088
  let hasChanged = false;
1087
1089
  indics.forEach((index, i) => {
1088
1090
  const element = editor.children[index];
1089
1091
  const preHeight = getCachedHeightByElement(editor, element);
1090
- if (preHeight && !force) {
1091
- if (isDebug) {
1092
- const height = calcHeightByElement(editor, element);
1093
- if (height !== preHeight) {
1094
- debugLog('warn', 'calcHeightByElement: height not equal, index: ', index, 'preHeight: ', preHeight, 'height: ', height);
1095
- }
1096
- }
1097
- return;
1098
- }
1099
1092
  const currentHeight = calcHeightByElement(editor, element);
1100
1093
  if (isValidNumber(currentHeight) && currentHeight !== preHeight) {
1101
1094
  hasChanged = true;
1102
1095
  }
1103
1096
  if (isDebug && isValidNumber(currentHeight)) {
1104
- debugLog('log', 'measureHeightByIndics: index: ', index, 'preHeight: ', preHeight, 'height: ', currentHeight);
1097
+ debugLog('log', `measureHeightByIndics(${source}), index: `, index, 'preHeight: ', preHeight, 'height: ', currentHeight);
1105
1098
  }
1106
1099
  });
1107
1100
  return hasChanged;
@@ -3513,6 +3506,9 @@ class SlateEditable {
3513
3506
  }
3514
3507
  else {
3515
3508
  const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.appendPreRenderingToViewport(visibleStates);
3509
+ if (isDebugUpdate) {
3510
+ debugLog('log', 'writeValue update list render');
3511
+ }
3516
3512
  this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount, childrenWithPreRenderingIndics);
3517
3513
  }
3518
3514
  const remeasureIndics = this.getChangedIndics(previousInViewportChildren);
@@ -3619,7 +3615,7 @@ class SlateEditable {
3619
3615
  });
3620
3616
  }), debounceTime(500), filter(() => pendingRemeasureIndics.length > 0))
3621
3617
  .subscribe((previousValue) => {
3622
- const changed = measureHeightByIndics(this.editor, pendingRemeasureIndics, true);
3618
+ const changed = measureHeightByIndics(this.editor, pendingRemeasureIndics, 'data-changed');
3623
3619
  if (changed) {
3624
3620
  if (previousValue.tryUpdateViewport) {
3625
3621
  this.tryUpdateVirtualViewport();
@@ -3660,7 +3656,8 @@ class SlateEditable {
3660
3656
  if (!this.virtualScrollInitialized) {
3661
3657
  return 0;
3662
3658
  }
3663
- return parseFloat(this.virtualTopHeightElement.style.height.replace('px', ''));
3659
+ const rect = this.virtualTopHeightElement.getBoundingClientRect();
3660
+ return roundTo(rect.height, 1);
3664
3661
  }
3665
3662
  appendPreRenderingToViewport(visibleStates) {
3666
3663
  let preRenderingCount = 0;
@@ -3718,7 +3715,7 @@ class SlateEditable {
3718
3715
  const visibleStates = this.editor.getAllVisibleStates();
3719
3716
  const accumulateTopHeigh = calculateAccumulatedTopHeight(this.editor, this.inViewportIndics[0], visibleStates);
3720
3717
  this.setTopHeightDebugInfo(accumulateTopHeigh, this.inViewportIndics[0] - 1);
3721
- if (realTopHeight !== accumulateTopHeigh) {
3718
+ if (realTopHeight !== accumulateTopHeigh && Math.abs(realTopHeight - accumulateTopHeigh) > 1) {
3722
3719
  if (isDebug) {
3723
3720
  debugLog('log', 'update top height since dirty state,增加高度: ', accumulateTopHeigh - realTopHeight);
3724
3721
  }
@@ -3736,16 +3733,22 @@ class SlateEditable {
3736
3733
  let diff = this.diffVirtualViewport(virtualView);
3737
3734
  if (diff.isDifferent && diff.needRemoveOnTop && !isFromScrollTo) {
3738
3735
  const remeasureIndics = diff.changedIndexesOfTop;
3739
- const changed = measureHeightByIndics(this.editor, remeasureIndics);
3736
+ const changed = measureHeightByIndics(this.editor, remeasureIndics, 'need-remove-from-top');
3740
3737
  if (changed) {
3741
3738
  virtualView = this.calculateVirtualViewport(visibleStates);
3742
3739
  diff = this.diffVirtualViewport(virtualView, 'second');
3740
+ if (!diff.isDifferent && isDebug) {
3741
+ debugLog('log', 'viewport need not change after remeasure');
3742
+ }
3743
3743
  }
3744
3744
  }
3745
3745
  if (diff.isDifferent) {
3746
3746
  this.applyVirtualView(virtualView);
3747
3747
  if (this.listRender.initialized) {
3748
3748
  const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.appendPreRenderingToViewport(visibleStates);
3749
+ if (isDebugUpdate) {
3750
+ debugLog('log', 'tryUpdateVirtualViewport update list render');
3751
+ }
3749
3752
  this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount, childrenWithPreRenderingIndics);
3750
3753
  if (diff.needAddOnTop && !isFromScrollTo && diff.changedIndexesOfTop.length === 1) {
3751
3754
  const remeasureAddedIndics = diff.changedIndexesOfTop;
@@ -3754,7 +3757,7 @@ class SlateEditable {
3754
3757
  }
3755
3758
  const startIndexBeforeAdd = diff.changedIndexesOfTop[diff.changedIndexesOfTop.length - 1] + 1;
3756
3759
  const topHeightBeforeAdd = virtualView.accumulatedHeights[startIndexBeforeAdd];
3757
- const changed = measureHeightByIndics(this.editor, remeasureAddedIndics);
3760
+ const changed = measureHeightByIndics(this.editor, remeasureAddedIndics, 'need-add-from-top');
3758
3761
  if (changed) {
3759
3762
  const newHeights = buildHeightsAndAccumulatedHeights(this.editor, visibleStates);
3760
3763
  const actualTopHeightAfterAdd = newHeights.accumulatedHeights[startIndexBeforeAdd];
@@ -3797,7 +3800,6 @@ class SlateEditable {
3797
3800
  businessTop = calcBusinessTop(this.editor);
3798
3801
  }
3799
3802
  const { heights, accumulatedHeights } = buildHeightsAndAccumulatedHeights(this.editor, visibleStates);
3800
- const totalHeight = accumulatedHeights[elementLength] + businessTop;
3801
3803
  let startPosition = Math.max(scrollTop - businessTop, 0);
3802
3804
  let endPosition = startPosition + viewportHeight;
3803
3805
  if (scrollTop < businessTop) {
@@ -3838,8 +3840,7 @@ class SlateEditable {
3838
3840
  const inViewportStartIndex = inViewportIndics[0];
3839
3841
  const inViewportEndIndex = inViewportIndics[inViewportIndics.length - 1];
3840
3842
  const top = accumulatedHeights[inViewportStartIndex];
3841
- // todo: totalHeight: totalHeight 逻辑需要优化
3842
- const bottom = totalHeight - accumulatedHeights[inViewportEndIndex + 1];
3843
+ const bottom = accumulatedHeights[elementLength] - accumulatedHeights[inViewportEndIndex + 1];
3843
3844
  return {
3844
3845
  inViewportChildren,
3845
3846
  inViewportIndics,
@@ -4127,7 +4128,7 @@ class SlateEditable {
4127
4128
  forceRender() {
4128
4129
  this.updateContext();
4129
4130
  if (this.isEnabledVirtualScroll()) {
4130
- this.updateListRenderAndRemeasureHeights();
4131
+ this.updateListRenderAndRemeasureHeights('forceRender');
4131
4132
  }
4132
4133
  else {
4133
4134
  this.listRender.update(this.editor.children, this.editor, this.context);
@@ -4177,14 +4178,14 @@ class SlateEditable {
4177
4178
  const changed = this.updateContext();
4178
4179
  if (changed) {
4179
4180
  if (this.isEnabledVirtualScroll()) {
4180
- this.updateListRenderAndRemeasureHeights();
4181
+ this.updateListRenderAndRemeasureHeights('render');
4181
4182
  }
4182
4183
  else {
4183
4184
  this.listRender.update(this.editor.children, this.editor, this.context);
4184
4185
  }
4185
4186
  }
4186
4187
  }
4187
- updateListRenderAndRemeasureHeights() {
4188
+ updateListRenderAndRemeasureHeights(origin) {
4188
4189
  const operations = this.editor.operations;
4189
4190
  const firstIndex = this.inViewportIndics[0];
4190
4191
  const operationsOfFirstElementMerged = operations.filter(op => op.type === 'merge_node' && op.path.length === 1 && firstIndex === op.path[0] - 1);
@@ -4220,16 +4221,13 @@ class SlateEditable {
4220
4221
  }
4221
4222
  this.inViewportIndics = newInViewportIndics;
4222
4223
  this.inViewportChildren = newInViewportChildren;
4223
- if (isDebug) {
4224
- debugLog('log', 'updateListRenderAndRemeasureHeights', 'mutationOfFirstElementHeight', 'newInViewportIndics', newInViewportIndics);
4225
- }
4226
4224
  }
4227
4225
  else {
4228
4226
  let virtualView = this.calculateVirtualViewport(visibleStates);
4229
4227
  let diff = this.diffVirtualViewport(virtualView, 'onChange');
4230
4228
  if (diff.isDifferent && diff.needRemoveOnTop) {
4231
4229
  const remeasureIndics = diff.changedIndexesOfTop;
4232
- const changed = measureHeightByIndics(this.editor, remeasureIndics);
4230
+ const changed = measureHeightByIndics(this.editor, remeasureIndics, 'need-remove-from-top');
4233
4231
  if (changed) {
4234
4232
  virtualView = this.calculateVirtualViewport(visibleStates);
4235
4233
  diff = this.diffVirtualViewport(virtualView, 'second');
@@ -4238,6 +4236,9 @@ class SlateEditable {
4238
4236
  this.applyVirtualView(virtualView);
4239
4237
  }
4240
4238
  const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.appendPreRenderingToViewport(visibleStates);
4239
+ if (isDebugUpdate) {
4240
+ debugLog('log', 'updateListRenderAndRemeasureHeights update list render', 'origin', origin);
4241
+ }
4241
4242
  this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount, childrenWithPreRenderingIndics);
4242
4243
  const remeasureIndics = this.getChangedIndics(previousInViewportChildren);
4243
4244
  if (remeasureIndics.length) {
@@ -5529,5 +5530,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
5529
5530
  * Generated bundle index. Do not edit.
5530
5531
  */
5531
5532
 
5532
- 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_VIEWPORT_HEIGHT, EDITOR_TO_VIRTUAL_SCROLL_CONFIG, 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_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_BOTTOM_HEIGHT_CLASS_NAME, VIRTUAL_CENTER_OUTLET_CLASS_NAME, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VIRTUAL_TOP_HEIGHT_CLASS_NAME, VoidTextFlavour, blobAsString, buildHTMLText, buildHeightsAndAccumulatedHeights, cacheHeightByElement, calcBusinessTop, calcHeightByElement, calculateAccumulatedTopHeight, check, clearMinHeightByElement, completeTable, createClipboardData, createText, createThrottleRAF, debugLog, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getBusinessTop, getCachedHeightByElement, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getContentHeight, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText, getScrollContainer, getSelection, getSlateFragmentAttribute, getViewportHeight, getZeroTextNode, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, isClipboardWriteTextSupported, isComponentType, isDOMText, isDebug, isDebugScrollTop, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isSelectionInsideVoid, isTemplateRef, isValid, isValidNumber, measureHeightByIndics, normalize, roundTo, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setMinHeightByElement, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5533
+ 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_VIEWPORT_HEIGHT, EDITOR_TO_VIRTUAL_SCROLL_CONFIG, 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_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, SLATE_DEBUG_KEY_UPDATE, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, SlateString, VIRTUAL_BOTTOM_HEIGHT_CLASS_NAME, VIRTUAL_CENTER_OUTLET_CLASS_NAME, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VIRTUAL_TOP_HEIGHT_CLASS_NAME, VoidTextFlavour, blobAsString, buildHTMLText, buildHeightsAndAccumulatedHeights, cacheHeightByElement, calcBusinessTop, calcHeightByElement, calculateAccumulatedTopHeight, check, clearMinHeightByElement, completeTable, createClipboardData, createText, createThrottleRAF, debugLog, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getBusinessTop, getCachedHeightByElement, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getContentHeight, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText, getScrollContainer, getSelection, getSlateFragmentAttribute, getViewportHeight, getZeroTextNode, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, isClipboardWriteTextSupported, isComponentType, isDOMText, isDebug, isDebugScrollTop, isDebugUpdate, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isSelectionInsideVoid, isTemplateRef, isValid, isValidNumber, measureHeightByIndics, normalize, roundTo, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setMinHeightByElement, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5533
5534
  //# sourceMappingURL=slate-angular.mjs.map