slate-angular 20.2.21 → 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();
@@ -3650,11 +3646,18 @@ class SlateEditable {
3650
3646
  this.virtualBottomHeightElement.style.height = `${roundTo(bottomHeight, 1)}px`;
3651
3647
  }
3652
3648
  }
3649
+ setTopHeightDebugInfo(accumulatedHeight, accumulatedEndIndex) {
3650
+ if (isDebug) {
3651
+ this.virtualTopHeightElement.setAttribute('accumulated-height', accumulatedHeight.toString());
3652
+ this.virtualTopHeightElement.setAttribute('accumulated-height-end-index', accumulatedEndIndex.toString());
3653
+ }
3654
+ }
3653
3655
  getActualVirtualTopHeight() {
3654
3656
  if (!this.virtualScrollInitialized) {
3655
3657
  return 0;
3656
3658
  }
3657
- return parseFloat(this.virtualTopHeightElement.style.height.replace('px', ''));
3659
+ const rect = this.virtualTopHeightElement.getBoundingClientRect();
3660
+ return roundTo(rect.height, 1);
3658
3661
  }
3659
3662
  appendPreRenderingToViewport(visibleStates) {
3660
3663
  let preRenderingCount = 0;
@@ -3711,7 +3714,8 @@ class SlateEditable {
3711
3714
  const realTopHeight = this.getActualVirtualTopHeight();
3712
3715
  const visibleStates = this.editor.getAllVisibleStates();
3713
3716
  const accumulateTopHeigh = calculateAccumulatedTopHeight(this.editor, this.inViewportIndics[0], visibleStates);
3714
- if (realTopHeight !== accumulateTopHeigh) {
3717
+ this.setTopHeightDebugInfo(accumulateTopHeigh, this.inViewportIndics[0] - 1);
3718
+ if (realTopHeight !== accumulateTopHeigh && Math.abs(realTopHeight - accumulateTopHeigh) > 1) {
3715
3719
  if (isDebug) {
3716
3720
  debugLog('log', 'update top height since dirty state,增加高度: ', accumulateTopHeigh - realTopHeight);
3717
3721
  }
@@ -3729,33 +3733,40 @@ class SlateEditable {
3729
3733
  let diff = this.diffVirtualViewport(virtualView);
3730
3734
  if (diff.isDifferent && diff.needRemoveOnTop && !isFromScrollTo) {
3731
3735
  const remeasureIndics = diff.changedIndexesOfTop;
3732
- const changed = measureHeightByIndics(this.editor, remeasureIndics);
3736
+ const changed = measureHeightByIndics(this.editor, remeasureIndics, 'need-remove-from-top');
3733
3737
  if (changed) {
3734
3738
  virtualView = this.calculateVirtualViewport(visibleStates);
3735
3739
  diff = this.diffVirtualViewport(virtualView, 'second');
3740
+ if (!diff.isDifferent && isDebug) {
3741
+ debugLog('log', 'viewport need not change after remeasure');
3742
+ }
3736
3743
  }
3737
3744
  }
3738
3745
  if (diff.isDifferent) {
3739
3746
  this.applyVirtualView(virtualView);
3740
3747
  if (this.listRender.initialized) {
3741
3748
  const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.appendPreRenderingToViewport(visibleStates);
3749
+ if (isDebugUpdate) {
3750
+ debugLog('log', 'tryUpdateVirtualViewport update list render');
3751
+ }
3742
3752
  this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount, childrenWithPreRenderingIndics);
3743
- if (diff.needAddOnTop && !isFromScrollTo) {
3753
+ if (diff.needAddOnTop && !isFromScrollTo && diff.changedIndexesOfTop.length === 1) {
3744
3754
  const remeasureAddedIndics = diff.changedIndexesOfTop;
3745
3755
  if (isDebug) {
3746
3756
  debugLog('log', 'needAddOnTop to remeasure heights: ', remeasureAddedIndics);
3747
3757
  }
3748
3758
  const startIndexBeforeAdd = diff.changedIndexesOfTop[diff.changedIndexesOfTop.length - 1] + 1;
3749
3759
  const topHeightBeforeAdd = virtualView.accumulatedHeights[startIndexBeforeAdd];
3750
- const changed = measureHeightByIndics(this.editor, remeasureAddedIndics);
3760
+ const changed = measureHeightByIndics(this.editor, remeasureAddedIndics, 'need-add-from-top');
3751
3761
  if (changed) {
3752
3762
  const newHeights = buildHeightsAndAccumulatedHeights(this.editor, visibleStates);
3753
3763
  const actualTopHeightAfterAdd = newHeights.accumulatedHeights[startIndexBeforeAdd];
3754
3764
  const newTopHeight = virtualView.top - (actualTopHeightAfterAdd - topHeightBeforeAdd);
3765
+ this.setTopHeightDebugInfo(newHeights.accumulatedHeights[this.inViewportIndics[0]], this.inViewportIndics[0] - 1);
3755
3766
  if (topHeightBeforeAdd !== actualTopHeightAfterAdd) {
3756
3767
  this.setVirtualSpaceHeight(newTopHeight);
3757
3768
  if (isDebug) {
3758
- debugLog('log', `update top height since will add element in top,减去高度: ${topHeightBeforeAdd - actualTopHeightAfterAdd}`);
3769
+ debugLog('log', `update top height since will add element in top,减去高度: ${actualTopHeightAfterAdd - topHeightBeforeAdd}`);
3759
3770
  }
3760
3771
  }
3761
3772
  }
@@ -3789,7 +3800,6 @@ class SlateEditable {
3789
3800
  businessTop = calcBusinessTop(this.editor);
3790
3801
  }
3791
3802
  const { heights, accumulatedHeights } = buildHeightsAndAccumulatedHeights(this.editor, visibleStates);
3792
- const totalHeight = accumulatedHeights[elementLength] + businessTop;
3793
3803
  let startPosition = Math.max(scrollTop - businessTop, 0);
3794
3804
  let endPosition = startPosition + viewportHeight;
3795
3805
  if (scrollTop < businessTop) {
@@ -3830,8 +3840,7 @@ class SlateEditable {
3830
3840
  const inViewportStartIndex = inViewportIndics[0];
3831
3841
  const inViewportEndIndex = inViewportIndics[inViewportIndics.length - 1];
3832
3842
  const top = accumulatedHeights[inViewportStartIndex];
3833
- // todo: toggleHeight: toggleHeight 逻辑需要优化
3834
- const bottom = totalHeight - accumulatedHeights[inViewportEndIndex + 1];
3843
+ const bottom = accumulatedHeights[elementLength] - accumulatedHeights[inViewportEndIndex + 1];
3835
3844
  return {
3836
3845
  inViewportChildren,
3837
3846
  inViewportIndics,
@@ -3845,6 +3854,7 @@ class SlateEditable {
3845
3854
  this.inViewportChildren = virtualView.inViewportChildren;
3846
3855
  this.setVirtualSpaceHeight(virtualView.top, virtualView.bottom);
3847
3856
  this.inViewportIndics = virtualView.inViewportIndics;
3857
+ this.setTopHeightDebugInfo(virtualView.top, this.inViewportIndics[0] - 1);
3848
3858
  }
3849
3859
  diffVirtualViewport(virtualView, stage = 'first') {
3850
3860
  if (!this.inViewportChildren.length) {
@@ -4118,7 +4128,7 @@ class SlateEditable {
4118
4128
  forceRender() {
4119
4129
  this.updateContext();
4120
4130
  if (this.isEnabledVirtualScroll()) {
4121
- this.updateListRenderAndRemeasureHeights();
4131
+ this.updateListRenderAndRemeasureHeights('forceRender');
4122
4132
  }
4123
4133
  else {
4124
4134
  this.listRender.update(this.editor.children, this.editor, this.context);
@@ -4168,14 +4178,14 @@ class SlateEditable {
4168
4178
  const changed = this.updateContext();
4169
4179
  if (changed) {
4170
4180
  if (this.isEnabledVirtualScroll()) {
4171
- this.updateListRenderAndRemeasureHeights();
4181
+ this.updateListRenderAndRemeasureHeights('render');
4172
4182
  }
4173
4183
  else {
4174
4184
  this.listRender.update(this.editor.children, this.editor, this.context);
4175
4185
  }
4176
4186
  }
4177
4187
  }
4178
- updateListRenderAndRemeasureHeights() {
4188
+ updateListRenderAndRemeasureHeights(origin) {
4179
4189
  const operations = this.editor.operations;
4180
4190
  const firstIndex = this.inViewportIndics[0];
4181
4191
  const operationsOfFirstElementMerged = operations.filter(op => op.type === 'merge_node' && op.path.length === 1 && firstIndex === op.path[0] - 1);
@@ -4211,16 +4221,13 @@ class SlateEditable {
4211
4221
  }
4212
4222
  this.inViewportIndics = newInViewportIndics;
4213
4223
  this.inViewportChildren = newInViewportChildren;
4214
- if (isDebug) {
4215
- debugLog('log', 'updateListRenderAndRemeasureHeights', 'mutationOfFirstElementHeight', 'newInViewportIndics', newInViewportIndics);
4216
- }
4217
4224
  }
4218
4225
  else {
4219
4226
  let virtualView = this.calculateVirtualViewport(visibleStates);
4220
4227
  let diff = this.diffVirtualViewport(virtualView, 'onChange');
4221
4228
  if (diff.isDifferent && diff.needRemoveOnTop) {
4222
4229
  const remeasureIndics = diff.changedIndexesOfTop;
4223
- const changed = measureHeightByIndics(this.editor, remeasureIndics);
4230
+ const changed = measureHeightByIndics(this.editor, remeasureIndics, 'need-remove-from-top');
4224
4231
  if (changed) {
4225
4232
  virtualView = this.calculateVirtualViewport(visibleStates);
4226
4233
  diff = this.diffVirtualViewport(virtualView, 'second');
@@ -4229,6 +4236,9 @@ class SlateEditable {
4229
4236
  this.applyVirtualView(virtualView);
4230
4237
  }
4231
4238
  const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.appendPreRenderingToViewport(visibleStates);
4239
+ if (isDebugUpdate) {
4240
+ debugLog('log', 'updateListRenderAndRemeasureHeights update list render', 'origin', origin);
4241
+ }
4232
4242
  this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount, childrenWithPreRenderingIndics);
4233
4243
  const remeasureIndics = this.getChangedIndics(previousInViewportChildren);
4234
4244
  if (remeasureIndics.length) {
@@ -5520,5 +5530,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
5520
5530
  * Generated bundle index. Do not edit.
5521
5531
  */
5522
5532
 
5523
- 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 };
5524
5534
  //# sourceMappingURL=slate-angular.mjs.map