slate-angular 20.2.0-next.25 → 20.2.0-next.26
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 +54 -100
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +3 -4
- package/package.json +1 -1
|
@@ -957,6 +957,30 @@ const fallbackCopyText = async (text) => {
|
|
|
957
957
|
|
|
958
958
|
const ELEMENT_KEY_TO_HEIGHTS = new WeakMap();
|
|
959
959
|
const EDITOR_TO_BUSINESS_TOP = new WeakMap();
|
|
960
|
+
const measureHeightByElement = (editor, element) => {
|
|
961
|
+
const key = AngularEditor.findKey(editor, element);
|
|
962
|
+
const view = ELEMENT_TO_COMPONENT.get(element);
|
|
963
|
+
if (!view) {
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
const ret = view.getRealHeight();
|
|
967
|
+
const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
|
|
968
|
+
heights.set(key.id, ret);
|
|
969
|
+
return ret;
|
|
970
|
+
};
|
|
971
|
+
const measureHeightByIndics = (editor, indics, force = false) => {
|
|
972
|
+
let hasChanged = false;
|
|
973
|
+
indics.forEach((index, i) => {
|
|
974
|
+
const element = editor.children[index];
|
|
975
|
+
const preHeight = getRealHeightByElement(editor, element, 0);
|
|
976
|
+
if (preHeight && !force) {
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
hasChanged = true;
|
|
980
|
+
measureHeightByElement(editor, element);
|
|
981
|
+
});
|
|
982
|
+
return hasChanged;
|
|
983
|
+
};
|
|
960
984
|
const getBusinessTop = (editor) => {
|
|
961
985
|
return EDITOR_TO_BUSINESS_TOP.get(editor) ?? 0;
|
|
962
986
|
};
|
|
@@ -965,9 +989,6 @@ const getRealHeightByElement = (editor, element, defaultHeight = VIRTUAL_SCROLL_
|
|
|
965
989
|
if (!isVisible) {
|
|
966
990
|
return 0;
|
|
967
991
|
}
|
|
968
|
-
if (!element) {
|
|
969
|
-
return defaultHeight;
|
|
970
|
-
}
|
|
971
992
|
const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
|
|
972
993
|
const key = AngularEditor.findKey(editor, element);
|
|
973
994
|
const height = heights?.get(key.id);
|
|
@@ -3291,7 +3312,6 @@ class SlateEditable {
|
|
|
3291
3312
|
const { preRenderingCount, childrenWithPreRendering } = this.handlePreRendering();
|
|
3292
3313
|
this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount);
|
|
3293
3314
|
}
|
|
3294
|
-
this.tryMeasureInViewportChildrenHeights();
|
|
3295
3315
|
}
|
|
3296
3316
|
else {
|
|
3297
3317
|
if (!this.listRender.initialized) {
|
|
@@ -3516,7 +3536,7 @@ class SlateEditable {
|
|
|
3516
3536
|
if (isDebug && remeasureIndics.length > 0) {
|
|
3517
3537
|
console.log('remeasure height by indics: ', remeasureIndics);
|
|
3518
3538
|
}
|
|
3519
|
-
this.
|
|
3539
|
+
measureHeightByIndics(this.editor, remeasureIndics, true);
|
|
3520
3540
|
}
|
|
3521
3541
|
updateContext() {
|
|
3522
3542
|
const decorations = this.generateDecorations();
|
|
@@ -3604,7 +3624,7 @@ class SlateEditable {
|
|
|
3604
3624
|
editorResizeObserverRectWidth = entries[0].contentRect.width;
|
|
3605
3625
|
this.keyHeightMap.clear();
|
|
3606
3626
|
const remeasureIndics = this.inViewportIndics;
|
|
3607
|
-
this.
|
|
3627
|
+
measureHeightByIndics(this.editor, remeasureIndics);
|
|
3608
3628
|
}
|
|
3609
3629
|
});
|
|
3610
3630
|
this.editorResizeObserver.observe(this.elementRef.nativeElement);
|
|
@@ -3659,37 +3679,46 @@ class SlateEditable {
|
|
|
3659
3679
|
}
|
|
3660
3680
|
let virtualView = this.calculateVirtualViewport();
|
|
3661
3681
|
let diff = this.diffVirtualViewport(virtualView);
|
|
3682
|
+
if (diff.isDifferent && diff.needRemoveOnTop) {
|
|
3683
|
+
const remeasureIndics = diff.changedIndexesOfTop;
|
|
3684
|
+
const changed = measureHeightByIndics(this.editor, remeasureIndics);
|
|
3685
|
+
if (changed) {
|
|
3686
|
+
virtualView = this.calculateVirtualViewport();
|
|
3687
|
+
diff = this.diffVirtualViewport(virtualView, 'second');
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3662
3690
|
if (diff.isDifferent) {
|
|
3663
3691
|
this.applyVirtualView(virtualView);
|
|
3664
3692
|
if (this.listRender.initialized) {
|
|
3665
3693
|
const { preRenderingCount, childrenWithPreRendering } = this.handlePreRendering();
|
|
3666
3694
|
this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount);
|
|
3695
|
+
if (diff.needAddOnTop) {
|
|
3696
|
+
const remeasureAddedIndics = diff.changedIndexesOfTop;
|
|
3697
|
+
if (isDebug) {
|
|
3698
|
+
this.debugLog('log', 'needAddOnTop to remeasure heights: ', remeasureAddedIndics);
|
|
3699
|
+
}
|
|
3700
|
+
const startIndexBeforeAdd = diff.changedIndexesOfTop[diff.changedIndexesOfTop.length - 1] + 1;
|
|
3701
|
+
const topHeightBeforeAdd = virtualView.accumulatedHeights[startIndexBeforeAdd];
|
|
3702
|
+
const result = measureHeightByIndics(this.editor, remeasureAddedIndics);
|
|
3703
|
+
if (result) {
|
|
3704
|
+
const newHeights = buildHeightsAndAccumulatedHeights(this.editor);
|
|
3705
|
+
const actualTopHeightAfterAdd = newHeights.accumulatedHeights[startIndexBeforeAdd];
|
|
3706
|
+
const newTopHeight = virtualView.top - (actualTopHeightAfterAdd - topHeightBeforeAdd);
|
|
3707
|
+
this.setVirtualSpaceHeight(newTopHeight);
|
|
3708
|
+
if (isDebug) {
|
|
3709
|
+
this.debugLog('log', `update top height since will add element in top(正数减去高度,负数代表增加高度): ${actualTopHeightAfterAdd - topHeightBeforeAdd}`);
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3667
3713
|
if (!AngularEditor.isReadOnly(this.editor) && this.editor.selection) {
|
|
3668
3714
|
this.toNativeSelection();
|
|
3669
3715
|
}
|
|
3670
3716
|
}
|
|
3671
|
-
if (diff.needAddOnTop) {
|
|
3672
|
-
const remeasureAddedIndics = diff.changedIndexesOfTop;
|
|
3673
|
-
if (isDebug) {
|
|
3674
|
-
this.debugLog('log', 'needAddOnTop to remeasure heights: ', remeasureAddedIndics);
|
|
3675
|
-
}
|
|
3676
|
-
const startIndexBeforeAdd = diff.changedIndexesOfTop[diff.changedIndexesOfTop.length - 1] + 1;
|
|
3677
|
-
const topHeightBeforeAdd = virtualView.accumulatedHeights[startIndexBeforeAdd];
|
|
3678
|
-
const result = this.remeasureHeightByIndics(remeasureAddedIndics);
|
|
3679
|
-
if (result) {
|
|
3680
|
-
const newHeights = buildHeightsAndAccumulatedHeights(this.editor);
|
|
3681
|
-
const actualTopHeightAfterAdd = newHeights.accumulatedHeights[startIndexBeforeAdd];
|
|
3682
|
-
const newTopHeight = virtualView.top - (actualTopHeightAfterAdd - topHeightBeforeAdd);
|
|
3683
|
-
this.setVirtualSpaceHeight(newTopHeight);
|
|
3684
|
-
this.debugLog('log', `update top height cause added element in top, 减去: ${actualTopHeightAfterAdd - topHeightBeforeAdd}`);
|
|
3685
|
-
}
|
|
3686
|
-
}
|
|
3687
|
-
this.tryMeasureInViewportChildrenHeights();
|
|
3688
3717
|
}
|
|
3689
3718
|
else {
|
|
3690
3719
|
const topHeight = this.getVirtualTopHeight();
|
|
3691
3720
|
if (virtualView.top !== topHeight) {
|
|
3692
|
-
this.debugLog('log', 'update top height
|
|
3721
|
+
this.debugLog('log', 'update top height since invalid status(正数减去高度,负数代表增加高度): ', topHeight - virtualView.top);
|
|
3693
3722
|
this.setVirtualSpaceHeight(virtualView.top);
|
|
3694
3723
|
}
|
|
3695
3724
|
}
|
|
@@ -3875,81 +3904,6 @@ class SlateEditable {
|
|
|
3875
3904
|
changedIndexesOfBottom: []
|
|
3876
3905
|
};
|
|
3877
3906
|
}
|
|
3878
|
-
tryMeasureInViewportChildrenHeights() {
|
|
3879
|
-
if (!this.isEnabledVirtualScroll()) {
|
|
3880
|
-
return;
|
|
3881
|
-
}
|
|
3882
|
-
this.tryMeasureInViewportChildrenHeightsAnimId && cancelAnimationFrame(this.tryMeasureInViewportChildrenHeightsAnimId);
|
|
3883
|
-
this.tryMeasureInViewportChildrenHeightsAnimId = requestAnimationFrame(() => {
|
|
3884
|
-
this.measureVisibleHeights();
|
|
3885
|
-
});
|
|
3886
|
-
}
|
|
3887
|
-
measureVisibleHeights() {
|
|
3888
|
-
const children = (this.editor.children || []);
|
|
3889
|
-
const inViewportIndics = [...this.inViewportIndics];
|
|
3890
|
-
inViewportIndics.forEach(index => {
|
|
3891
|
-
const node = children[index];
|
|
3892
|
-
if (!node) {
|
|
3893
|
-
return;
|
|
3894
|
-
}
|
|
3895
|
-
const key = AngularEditor.findKey(this.editor, node);
|
|
3896
|
-
// 跳过已测过的块,除非强制测量
|
|
3897
|
-
if (this.keyHeightMap.has(key.id)) {
|
|
3898
|
-
return;
|
|
3899
|
-
}
|
|
3900
|
-
const view = ELEMENT_TO_COMPONENT.get(node);
|
|
3901
|
-
if (!view) {
|
|
3902
|
-
return;
|
|
3903
|
-
}
|
|
3904
|
-
const ret = view.getRealHeight();
|
|
3905
|
-
if (ret instanceof Promise) {
|
|
3906
|
-
ret.then(height => {
|
|
3907
|
-
this.keyHeightMap.set(key.id, height);
|
|
3908
|
-
});
|
|
3909
|
-
}
|
|
3910
|
-
else {
|
|
3911
|
-
this.keyHeightMap.set(key.id, ret);
|
|
3912
|
-
}
|
|
3913
|
-
});
|
|
3914
|
-
}
|
|
3915
|
-
remeasureHeightByIndics(indics) {
|
|
3916
|
-
const children = (this.editor.children || []);
|
|
3917
|
-
let isHeightChanged = false;
|
|
3918
|
-
indics.forEach((index, i) => {
|
|
3919
|
-
const node = children[index];
|
|
3920
|
-
if (!node) {
|
|
3921
|
-
return;
|
|
3922
|
-
}
|
|
3923
|
-
const key = AngularEditor.findKey(this.editor, node);
|
|
3924
|
-
const view = ELEMENT_TO_COMPONENT.get(node);
|
|
3925
|
-
if (!view) {
|
|
3926
|
-
return;
|
|
3927
|
-
}
|
|
3928
|
-
const prevHeight = this.keyHeightMap.get(key.id);
|
|
3929
|
-
const ret = view.getRealHeight();
|
|
3930
|
-
if (ret instanceof Promise) {
|
|
3931
|
-
ret.then(height => {
|
|
3932
|
-
this.keyHeightMap.set(key.id, height);
|
|
3933
|
-
if (height !== prevHeight) {
|
|
3934
|
-
isHeightChanged = true;
|
|
3935
|
-
if (isDebug) {
|
|
3936
|
-
this.debugLog('log', `remeasure element height, index: ${index} prevHeight: ${prevHeight} newHeight: ${height}`);
|
|
3937
|
-
}
|
|
3938
|
-
}
|
|
3939
|
-
});
|
|
3940
|
-
}
|
|
3941
|
-
else {
|
|
3942
|
-
this.keyHeightMap.set(key.id, ret);
|
|
3943
|
-
if (ret !== prevHeight) {
|
|
3944
|
-
isHeightChanged = true;
|
|
3945
|
-
if (isDebug) {
|
|
3946
|
-
this.debugLog('log', `remeasure element height, index: ${index} prevHeight: ${prevHeight} newHeight: ${ret}`);
|
|
3947
|
-
}
|
|
3948
|
-
}
|
|
3949
|
-
}
|
|
3950
|
-
});
|
|
3951
|
-
return isHeightChanged;
|
|
3952
|
-
}
|
|
3953
3907
|
//#region event proxy
|
|
3954
3908
|
addEventListener(eventName, listener, target = this.elementRef.nativeElement) {
|
|
3955
3909
|
this.manualListeners.push(this.renderer2.listen(target, eventName, (event) => {
|
|
@@ -5182,5 +5136,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
|
|
|
5182
5136
|
* Generated bundle index. Do not edit.
|
|
5183
5137
|
*/
|
|
5184
5138
|
|
|
5185
|
-
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, SLATE_DEBUG_KEY_SCROLL_TOP, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, SlateString, 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 };
|
|
5139
|
+
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, SLATE_DEBUG_KEY_SCROLL_TOP, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, SlateString, 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, measureHeightByElement, measureHeightByIndics, normalize, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
|
|
5186
5140
|
//# sourceMappingURL=slate-angular.mjs.map
|