slate-angular 20.2.0-next.18 → 20.2.0-next.19
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.
- package/fesm2022/slate-angular.mjs +42 -36
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +7 -5
- package/package.json +1 -1
|
@@ -955,14 +955,48 @@ const fallbackCopyText = async (text) => {
|
|
|
955
955
|
};
|
|
956
956
|
|
|
957
957
|
const ELEMENT_KEY_TO_HEIGHTS = new WeakMap();
|
|
958
|
-
|
|
959
|
-
const
|
|
958
|
+
const getRealHeightByElement = (editor, element, defaultHeight = VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT) => {
|
|
959
|
+
const isVisible = editor.isVisible(element);
|
|
960
|
+
if (!isVisible) {
|
|
961
|
+
return 0;
|
|
962
|
+
}
|
|
963
|
+
if (!element) {
|
|
964
|
+
return defaultHeight;
|
|
965
|
+
}
|
|
960
966
|
const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
|
|
961
967
|
const key = AngularEditor.findKey(editor, element);
|
|
962
|
-
|
|
968
|
+
const height = heights?.get(key.id);
|
|
969
|
+
if (typeof height === 'number') {
|
|
970
|
+
return height;
|
|
971
|
+
}
|
|
972
|
+
if (heights?.has(key.id)) {
|
|
973
|
+
console.error('getBlockHeight: invalid height value', key.id, height);
|
|
974
|
+
}
|
|
975
|
+
return defaultHeight;
|
|
976
|
+
};
|
|
977
|
+
const buildHeightsAndAccumulatedHeights = (editor) => {
|
|
978
|
+
const children = (editor.children || []);
|
|
979
|
+
const heights = new Array(children.length);
|
|
980
|
+
const accumulatedHeights = new Array(children.length + 1);
|
|
981
|
+
accumulatedHeights[0] = 0;
|
|
982
|
+
for (let i = 0; i < children.length; i++) {
|
|
983
|
+
const height = getRealHeightByElement(editor, children[i]);
|
|
984
|
+
heights[i] = height;
|
|
985
|
+
accumulatedHeights[i + 1] = accumulatedHeights[i] + height;
|
|
986
|
+
}
|
|
987
|
+
return { heights, accumulatedHeights };
|
|
963
988
|
};
|
|
964
|
-
// 滚动到元素位置
|
|
965
989
|
const scrollToElement = (editor, element, scrollTo) => {
|
|
990
|
+
const children = editor.children;
|
|
991
|
+
if (!children.length) {
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
const anchorIndex = children.findIndex(item => item === element);
|
|
995
|
+
if (anchorIndex < 0) {
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
const { accumulatedHeights } = buildHeightsAndAccumulatedHeights(editor);
|
|
999
|
+
scrollTo(accumulatedHeights[anchorIndex] ?? 0);
|
|
966
1000
|
};
|
|
967
1001
|
|
|
968
1002
|
const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
|
|
@@ -3618,8 +3652,7 @@ class SlateEditable {
|
|
|
3618
3652
|
}
|
|
3619
3653
|
const elementLength = children.length;
|
|
3620
3654
|
const adjustedScrollTop = Math.max(0, scrollTop - this.businessHeight);
|
|
3621
|
-
const heights =
|
|
3622
|
-
const accumulatedHeights = this.buildAccumulatedHeight(heights);
|
|
3655
|
+
const { heights, accumulatedHeights } = buildHeightsAndAccumulatedHeights(this.editor);
|
|
3623
3656
|
const totalHeight = accumulatedHeights[elementLength];
|
|
3624
3657
|
const maxScrollTop = Math.max(0, totalHeight - viewportHeight);
|
|
3625
3658
|
const limitedScrollTop = Math.min(adjustedScrollTop, maxScrollTop);
|
|
@@ -3728,8 +3761,8 @@ class SlateEditable {
|
|
|
3728
3761
|
this.debugLog('log', `====== diffVirtualViewport stage: ${stage} ======`);
|
|
3729
3762
|
this.debugLog('log', 'oldVisibleIndexes:', oldVisibleIndexes);
|
|
3730
3763
|
this.debugLog('log', 'newVisibleIndexes:', newVisibleIndexes);
|
|
3731
|
-
this.debugLog('log', 'diffTopRenderedIndexes:', isMissingTop ? '-' : isAddedTop ? '+' : '-', diffTopRenderedIndexes, diffTopRenderedIndexes.map(index => this.
|
|
3732
|
-
this.debugLog('log', 'diffBottomRenderedIndexes:', isAddedBottom ? '+' : isMissingBottom ? '-' : '+', diffBottomRenderedIndexes, diffBottomRenderedIndexes.map(index => this.
|
|
3764
|
+
this.debugLog('log', 'diffTopRenderedIndexes:', isMissingTop ? '-' : isAddedTop ? '+' : '-', diffTopRenderedIndexes, diffTopRenderedIndexes.map(index => getRealHeightByElement(this.editor, this.editor.children[index], 0)));
|
|
3765
|
+
this.debugLog('log', 'diffBottomRenderedIndexes:', isAddedBottom ? '+' : isMissingBottom ? '-' : '+', diffBottomRenderedIndexes, diffBottomRenderedIndexes.map(index => getRealHeightByElement(this.editor, this.editor.children[index], 0)));
|
|
3733
3766
|
const needTop = virtualView.heights.slice(0, newVisibleIndexes[0]).reduce((acc, height) => acc + height, 0);
|
|
3734
3767
|
const needBottom = virtualView.heights
|
|
3735
3768
|
.slice(newVisibleIndexes[newVisibleIndexes.length - 1] + 1)
|
|
@@ -3754,33 +3787,6 @@ class SlateEditable {
|
|
|
3754
3787
|
diffBottomRenderedIndexes: []
|
|
3755
3788
|
};
|
|
3756
3789
|
}
|
|
3757
|
-
getBlockHeight(index, defaultHeight = VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT) {
|
|
3758
|
-
const node = this.editor.children[index];
|
|
3759
|
-
const isVisible = this.editor.isVisible(node);
|
|
3760
|
-
if (!isVisible) {
|
|
3761
|
-
return 0;
|
|
3762
|
-
}
|
|
3763
|
-
if (!node) {
|
|
3764
|
-
return defaultHeight;
|
|
3765
|
-
}
|
|
3766
|
-
const key = AngularEditor.findKey(this.editor, node);
|
|
3767
|
-
const height = this.keyHeightMap.get(key.id);
|
|
3768
|
-
if (typeof height === 'number') {
|
|
3769
|
-
return height;
|
|
3770
|
-
}
|
|
3771
|
-
if (this.keyHeightMap.has(key.id)) {
|
|
3772
|
-
console.error('getBlockHeight: invalid height value', key.id, height);
|
|
3773
|
-
}
|
|
3774
|
-
return defaultHeight;
|
|
3775
|
-
}
|
|
3776
|
-
buildAccumulatedHeight(heights) {
|
|
3777
|
-
const accumulatedHeights = new Array(heights.length + 1).fill(0);
|
|
3778
|
-
for (let i = 0; i < heights.length; i++) {
|
|
3779
|
-
// 存储前 i 个的累计高度
|
|
3780
|
-
accumulatedHeights[i + 1] = accumulatedHeights[i] + heights[i];
|
|
3781
|
-
}
|
|
3782
|
-
return accumulatedHeights;
|
|
3783
|
-
}
|
|
3784
3790
|
tryMeasureInViewportChildrenHeights() {
|
|
3785
3791
|
if (!this.isEnabledVirtualScroll()) {
|
|
3786
3792
|
return;
|
|
@@ -5068,5 +5074,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
|
|
|
5068
5074
|
* Generated bundle index. Do not edit.
|
|
5069
5075
|
*/
|
|
5070
5076
|
|
|
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 };
|
|
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 };
|
|
5072
5078
|
//# sourceMappingURL=slate-angular.mjs.map
|