slate-angular 20.2.0-next.16 → 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.
- package/fesm2022/slate-angular.mjs +86 -45
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +12 -8
- package/package.json +1 -1
|
@@ -362,6 +362,7 @@ const PLACEHOLDER_SYMBOL = Symbol('placeholder');
|
|
|
362
362
|
*/
|
|
363
363
|
const ELEMENT_TO_COMPONENT = new WeakMap();
|
|
364
364
|
const IS_ENABLED_VIRTUAL_SCROLL = new WeakMap();
|
|
365
|
+
const EDITOR_TO_VIRTUAL_SCROLL_SELECTION = new WeakMap();
|
|
365
366
|
const EDITOR_TO_AFTER_VIEW_INIT_QUEUE = new WeakMap();
|
|
366
367
|
|
|
367
368
|
const AngularEditor = {
|
|
@@ -474,7 +475,6 @@ const HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY &&
|
|
|
474
475
|
globalThis.InputEvent &&
|
|
475
476
|
// @ts-ignore The `getTargetRanges` property isn't recognized.
|
|
476
477
|
typeof globalThis.InputEvent.prototype.getTargetRanges === 'function';
|
|
477
|
-
const VIRTUAL_SCROLL_DEFAULT_BUFFER_COUNT = 3;
|
|
478
478
|
const VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT = 40;
|
|
479
479
|
const SLATE_DEBUG_KEY = '__SLATE_DEBUG__';
|
|
480
480
|
|
|
@@ -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;
|
|
@@ -971,7 +982,14 @@ const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
|
|
|
971
982
|
}
|
|
972
983
|
// Create a fake selection so that we can add a Base64-encoded copy of the
|
|
973
984
|
// fragment to the HTML, to decode on future pastes.
|
|
974
|
-
|
|
985
|
+
let domRange;
|
|
986
|
+
if (AngularEditor.isEnabledVirtualScroll(e)) {
|
|
987
|
+
const virtualScrollSelection = EDITOR_TO_VIRTUAL_SCROLL_SELECTION.get(e);
|
|
988
|
+
if (virtualScrollSelection) {
|
|
989
|
+
domRange = AngularEditor.toDOMRange(e, virtualScrollSelection);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
domRange = domRange ?? AngularEditor.toDOMRange(e, selection);
|
|
975
993
|
let contents = domRange.cloneContents();
|
|
976
994
|
let attach = contents.childNodes[0];
|
|
977
995
|
// Make sure attach is non-empty, since empty nodes will not get copied.
|
|
@@ -3078,8 +3096,6 @@ class VirtualScrollDebugOverlay {
|
|
|
3078
3096
|
}
|
|
3079
3097
|
}
|
|
3080
3098
|
|
|
3081
|
-
const JUST_NOW_UPDATED_VIRTUAL_VIEW = new WeakMap();
|
|
3082
|
-
const ELEMENT_KEY_TO_HEIGHTS = new WeakMap();
|
|
3083
3099
|
// not correctly clipboardData on beforeinput
|
|
3084
3100
|
const forceOnDOMPaste = IS_SAFARI;
|
|
3085
3101
|
const isDebug = localStorage.getItem(SLATE_DEBUG_KEY) === 'true';
|
|
@@ -3211,7 +3227,7 @@ class SlateEditable {
|
|
|
3211
3227
|
else {
|
|
3212
3228
|
this.listRender.update(childrenForRender, this.editor, this.context);
|
|
3213
3229
|
}
|
|
3214
|
-
this.
|
|
3230
|
+
this.tryMeasureInViewportChildrenHeights();
|
|
3215
3231
|
}
|
|
3216
3232
|
else {
|
|
3217
3233
|
if (!this.listRender.initialized) {
|
|
@@ -3251,26 +3267,35 @@ class SlateEditable {
|
|
|
3251
3267
|
this.addEventListener(event.name, () => { });
|
|
3252
3268
|
});
|
|
3253
3269
|
}
|
|
3270
|
+
calculateVirtualScrollSelection(selection) {
|
|
3271
|
+
if (selection) {
|
|
3272
|
+
const indics = Array.from(this.inViewportIndics.values());
|
|
3273
|
+
if (indics.length > 0) {
|
|
3274
|
+
const currentVisibleRange = {
|
|
3275
|
+
anchor: Editor.start(this.editor, [indics[0]]),
|
|
3276
|
+
focus: Editor.end(this.editor, [indics[indics.length - 1]])
|
|
3277
|
+
};
|
|
3278
|
+
const [start, end] = Range.edges(selection);
|
|
3279
|
+
const forwardSelection = { anchor: start, focus: end };
|
|
3280
|
+
const intersectedSelection = Range.intersection(forwardSelection, currentVisibleRange);
|
|
3281
|
+
EDITOR_TO_VIRTUAL_SCROLL_SELECTION.set(this.editor, intersectedSelection);
|
|
3282
|
+
if (!intersectedSelection || !Range.equals(intersectedSelection, forwardSelection)) {
|
|
3283
|
+
if (isDebug) {
|
|
3284
|
+
this.debugLog('log', `selection is not in visible range, selection: ${JSON.stringify(selection)}, intersectedSelection: ${JSON.stringify(intersectedSelection)}`);
|
|
3285
|
+
}
|
|
3286
|
+
return intersectedSelection;
|
|
3287
|
+
}
|
|
3288
|
+
return selection;
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
EDITOR_TO_VIRTUAL_SCROLL_SELECTION.set(this.editor, null);
|
|
3292
|
+
return selection;
|
|
3293
|
+
}
|
|
3254
3294
|
toNativeSelection() {
|
|
3255
3295
|
try {
|
|
3256
3296
|
let { selection } = this.editor;
|
|
3257
|
-
if (this.isEnabledVirtualScroll()
|
|
3258
|
-
|
|
3259
|
-
if (indics.length > 0) {
|
|
3260
|
-
const currentVisibleRange = {
|
|
3261
|
-
anchor: Editor.start(this.editor, [indics[0]]),
|
|
3262
|
-
focus: Editor.end(this.editor, [indics[indics.length - 1]])
|
|
3263
|
-
};
|
|
3264
|
-
const [start, end] = Range.edges(selection);
|
|
3265
|
-
const forwardSelection = { anchor: start, focus: end };
|
|
3266
|
-
const intersectedSelection = Range.intersection(forwardSelection, currentVisibleRange);
|
|
3267
|
-
if (!intersectedSelection || !Range.equals(intersectedSelection, forwardSelection)) {
|
|
3268
|
-
selection = intersectedSelection;
|
|
3269
|
-
if (isDebug) {
|
|
3270
|
-
this.debugLog('log', `selection is not in visible range, selection: ${JSON.stringify(selection)}, intersectedSelection: ${JSON.stringify(intersectedSelection)}`);
|
|
3271
|
-
}
|
|
3272
|
-
}
|
|
3273
|
-
}
|
|
3297
|
+
if (this.isEnabledVirtualScroll()) {
|
|
3298
|
+
selection = this.calculateVirtualScrollSelection(selection);
|
|
3274
3299
|
}
|
|
3275
3300
|
const root = AngularEditor.findDocumentOrShadowRoot(this.editor);
|
|
3276
3301
|
const { activeElement } = root;
|
|
@@ -3360,11 +3385,7 @@ class SlateEditable {
|
|
|
3360
3385
|
forceRender() {
|
|
3361
3386
|
this.updateContext();
|
|
3362
3387
|
if (this.isEnabledVirtualScroll()) {
|
|
3363
|
-
|
|
3364
|
-
this.applyVirtualView(virtualView);
|
|
3365
|
-
this.listRender.update(this.inViewportChildren, this.editor, this.context);
|
|
3366
|
-
const visibleIndexes = Array.from(this.inViewportIndics);
|
|
3367
|
-
this.remeasureHeightByIndics(visibleIndexes);
|
|
3388
|
+
this.updateListRenderAndRemeasureHeights();
|
|
3368
3389
|
}
|
|
3369
3390
|
else {
|
|
3370
3391
|
this.listRender.update(this.editor.children, this.editor, this.context);
|
|
@@ -3408,16 +3429,31 @@ class SlateEditable {
|
|
|
3408
3429
|
const changed = this.updateContext();
|
|
3409
3430
|
if (changed) {
|
|
3410
3431
|
if (this.isEnabledVirtualScroll()) {
|
|
3411
|
-
|
|
3412
|
-
this.applyVirtualView(virtualView);
|
|
3413
|
-
this.listRender.update(virtualView.inViewportChildren, this.editor, this.context);
|
|
3414
|
-
this.scheduleMeasureVisibleHeights();
|
|
3432
|
+
this.updateListRenderAndRemeasureHeights();
|
|
3415
3433
|
}
|
|
3416
3434
|
else {
|
|
3417
3435
|
this.listRender.update(this.editor.children, this.editor, this.context);
|
|
3418
3436
|
}
|
|
3419
3437
|
}
|
|
3420
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
|
+
}
|
|
3421
3457
|
updateContext() {
|
|
3422
3458
|
const decorations = this.generateDecorations();
|
|
3423
3459
|
if (this.context.selection !== this.editor.selection ||
|
|
@@ -3503,7 +3539,8 @@ class SlateEditable {
|
|
|
3503
3539
|
this.editorResizeObserver = new ResizeObserver(entries => {
|
|
3504
3540
|
if (entries.length > 0 && entries[0].contentRect.width !== editorResizeObserverRectWidth) {
|
|
3505
3541
|
editorResizeObserverRectWidth = entries[0].contentRect.width;
|
|
3506
|
-
|
|
3542
|
+
const remeasureIndics = Array.from(this.inViewportIndics);
|
|
3543
|
+
this.remeasureHeightByIndics(remeasureIndics);
|
|
3507
3544
|
}
|
|
3508
3545
|
});
|
|
3509
3546
|
this.editorResizeObserver.observe(this.elementRef.nativeElement);
|
|
@@ -3525,15 +3562,16 @@ class SlateEditable {
|
|
|
3525
3562
|
VirtualScrollDebugOverlay.log(doc, type, ...args);
|
|
3526
3563
|
}
|
|
3527
3564
|
tryUpdateVirtualViewport() {
|
|
3528
|
-
this.
|
|
3529
|
-
this.
|
|
3565
|
+
this.tryUpdateVirtualViewportAnimId && cancelAnimationFrame(this.tryUpdateVirtualViewportAnimId);
|
|
3566
|
+
this.tryUpdateVirtualViewportAnimId = requestAnimationFrame(() => {
|
|
3530
3567
|
let virtualView = this.calculateVirtualViewport();
|
|
3531
3568
|
let diff = this.diffVirtualViewport(virtualView);
|
|
3532
3569
|
if (!diff.isDiff) {
|
|
3533
3570
|
return;
|
|
3534
3571
|
}
|
|
3535
3572
|
if (diff.isMissingTop) {
|
|
3536
|
-
const
|
|
3573
|
+
const remeasureIndics = diff.diffTopRenderedIndexes;
|
|
3574
|
+
const result = this.remeasureHeightByIndics(remeasureIndics);
|
|
3537
3575
|
if (result) {
|
|
3538
3576
|
virtualView = this.calculateVirtualViewport();
|
|
3539
3577
|
diff = this.diffVirtualViewport(virtualView, 'second');
|
|
@@ -3549,7 +3587,7 @@ class SlateEditable {
|
|
|
3549
3587
|
this.toNativeSelection();
|
|
3550
3588
|
}
|
|
3551
3589
|
}
|
|
3552
|
-
this.
|
|
3590
|
+
this.tryMeasureInViewportChildrenHeights();
|
|
3553
3591
|
});
|
|
3554
3592
|
}
|
|
3555
3593
|
calculateVirtualViewport() {
|
|
@@ -3743,12 +3781,12 @@ class SlateEditable {
|
|
|
3743
3781
|
}
|
|
3744
3782
|
return accumulatedHeights;
|
|
3745
3783
|
}
|
|
3746
|
-
|
|
3784
|
+
tryMeasureInViewportChildrenHeights() {
|
|
3747
3785
|
if (!this.isEnabledVirtualScroll()) {
|
|
3748
3786
|
return;
|
|
3749
3787
|
}
|
|
3750
|
-
this.
|
|
3751
|
-
this.
|
|
3788
|
+
this.tryMeasureInViewportChildrenHeightsAnimId && cancelAnimationFrame(this.tryMeasureInViewportChildrenHeightsAnimId);
|
|
3789
|
+
this.tryMeasureInViewportChildrenHeightsAnimId = requestAnimationFrame(() => {
|
|
3752
3790
|
this.measureVisibleHeights();
|
|
3753
3791
|
});
|
|
3754
3792
|
}
|
|
@@ -3782,7 +3820,7 @@ class SlateEditable {
|
|
|
3782
3820
|
remeasureHeightByIndics(indics) {
|
|
3783
3821
|
const children = (this.editor.children || []);
|
|
3784
3822
|
let isHeightChanged = false;
|
|
3785
|
-
indics.forEach(index => {
|
|
3823
|
+
indics.forEach((index, i) => {
|
|
3786
3824
|
const node = children[index];
|
|
3787
3825
|
if (!node) {
|
|
3788
3826
|
return;
|
|
@@ -3796,21 +3834,21 @@ class SlateEditable {
|
|
|
3796
3834
|
const ret = view.getRealHeight();
|
|
3797
3835
|
if (ret instanceof Promise) {
|
|
3798
3836
|
ret.then(height => {
|
|
3837
|
+
this.keyHeightMap.set(key.id, height);
|
|
3799
3838
|
if (height !== prevHeight) {
|
|
3800
|
-
this.keyHeightMap.set(key.id, height);
|
|
3801
3839
|
isHeightChanged = true;
|
|
3802
3840
|
if (isDebug) {
|
|
3803
|
-
this.debugLog('log', `
|
|
3841
|
+
this.debugLog('log', `remeasure element height, index: ${index} prevHeight: ${prevHeight} newHeight: ${height}`);
|
|
3804
3842
|
}
|
|
3805
3843
|
}
|
|
3806
3844
|
});
|
|
3807
3845
|
}
|
|
3808
3846
|
else {
|
|
3847
|
+
this.keyHeightMap.set(key.id, ret);
|
|
3809
3848
|
if (ret !== prevHeight) {
|
|
3810
|
-
this.keyHeightMap.set(key.id, ret);
|
|
3811
3849
|
isHeightChanged = true;
|
|
3812
3850
|
if (isDebug) {
|
|
3813
|
-
this.debugLog('log', `
|
|
3851
|
+
this.debugLog('log', `remeasure element height, index: ${index} prevHeight: ${prevHeight} newHeight: ${ret}`);
|
|
3814
3852
|
}
|
|
3815
3853
|
}
|
|
3816
3854
|
}
|
|
@@ -3830,6 +3868,9 @@ class SlateEditable {
|
|
|
3830
3868
|
toSlateSelection() {
|
|
3831
3869
|
if ((!this.isComposing || IS_ANDROID) && !this.isUpdatingSelection && !this.isDraggingInternally) {
|
|
3832
3870
|
try {
|
|
3871
|
+
if (isDebug) {
|
|
3872
|
+
console.log('toSlateSelection');
|
|
3873
|
+
}
|
|
3833
3874
|
const root = AngularEditor.findDocumentOrShadowRoot(this.editor);
|
|
3834
3875
|
const { activeElement } = root;
|
|
3835
3876
|
const el = AngularEditor.toDOMNode(this.editor, this.editor);
|
|
@@ -5027,5 +5068,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
|
|
|
5027
5068
|
* Generated bundle index. Do not edit.
|
|
5028
5069
|
*/
|
|
5029
5070
|
|
|
5030
|
-
export { AngularEditor, BaseComponent, BaseElementComponent, BaseElementFlavour, BaseFlavour, BaseLeafComponent, BaseLeafFlavour, BaseTextComponent, BaseTextFlavour, BlockCardRef, DEFAULT_ELEMENT_HEIGHT, DefaultTextFlavour, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, 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,
|
|
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 };
|
|
5031
5072
|
//# sourceMappingURL=slate-angular.mjs.map
|