slate-angular 20.2.0-next.12 → 20.2.0-next.13
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 +53 -53
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +11 -11
- package/package.json +1 -1
|
@@ -3074,8 +3074,8 @@ const forceOnDOMPaste = IS_SAFARI;
|
|
|
3074
3074
|
const isDebug = localStorage.getItem(SLATE_DEBUG_KEY) === 'true';
|
|
3075
3075
|
class SlateEditable {
|
|
3076
3076
|
set virtualScroll(config) {
|
|
3077
|
-
this.
|
|
3078
|
-
this.
|
|
3077
|
+
this.virtualScrollConfig = config;
|
|
3078
|
+
this.tryUpdateVirtualViewport();
|
|
3079
3079
|
}
|
|
3080
3080
|
get hasBeforeInputSupport() {
|
|
3081
3081
|
return HAS_BEFORE_INPUT_SUPPORT;
|
|
@@ -3120,14 +3120,14 @@ class SlateEditable {
|
|
|
3120
3120
|
return null;
|
|
3121
3121
|
}
|
|
3122
3122
|
};
|
|
3123
|
-
this.
|
|
3123
|
+
this.virtualScrollConfig = {
|
|
3124
3124
|
enabled: false,
|
|
3125
3125
|
scrollTop: 0,
|
|
3126
3126
|
viewportHeight: 0
|
|
3127
3127
|
};
|
|
3128
|
-
this.
|
|
3129
|
-
this.
|
|
3130
|
-
this.
|
|
3128
|
+
this.inViewportChildren = [];
|
|
3129
|
+
this.inViewportIndics = new Set();
|
|
3130
|
+
this.keyHeightMap = new Map();
|
|
3131
3131
|
// the height from scroll container top to editor top height element
|
|
3132
3132
|
this.businessHeight = 0;
|
|
3133
3133
|
this.virtualScrollInitialized = false;
|
|
@@ -3141,7 +3141,7 @@ class SlateEditable {
|
|
|
3141
3141
|
NODE_TO_ELEMENT.set(this.editor, this.elementRef.nativeElement);
|
|
3142
3142
|
ELEMENT_TO_NODE.set(this.elementRef.nativeElement, this.editor);
|
|
3143
3143
|
IS_READ_ONLY.set(this.editor, this.readonly);
|
|
3144
|
-
ELEMENT_KEY_TO_HEIGHTS.set(this.editor, this.
|
|
3144
|
+
ELEMENT_KEY_TO_HEIGHTS.set(this.editor, this.keyHeightMap);
|
|
3145
3145
|
EDITOR_TO_ON_CHANGE.set(this.editor, () => {
|
|
3146
3146
|
this.ngZone.run(() => {
|
|
3147
3147
|
this.onChange();
|
|
@@ -3155,7 +3155,7 @@ class SlateEditable {
|
|
|
3155
3155
|
// add browser class
|
|
3156
3156
|
let browserClass = IS_FIREFOX ? 'firefox' : IS_SAFARI ? 'safari' : '';
|
|
3157
3157
|
browserClass && this.elementRef.nativeElement.classList.add(browserClass);
|
|
3158
|
-
this.
|
|
3158
|
+
this.initializeVirtualScroll();
|
|
3159
3159
|
this.listRender = new ListRender(this.viewContext, this.viewContainerRef, this.getOutletParent, this.getOutletElement);
|
|
3160
3160
|
}
|
|
3161
3161
|
ngOnChanges(simpleChanges) {
|
|
@@ -3187,9 +3187,9 @@ class SlateEditable {
|
|
|
3187
3187
|
if (value && value.length) {
|
|
3188
3188
|
this.editor.children = value;
|
|
3189
3189
|
this.initializeContext();
|
|
3190
|
-
const virtualView = this.
|
|
3190
|
+
const virtualView = this.calculateVirtualViewport();
|
|
3191
3191
|
this.applyVirtualView(virtualView);
|
|
3192
|
-
const childrenForRender = virtualView.
|
|
3192
|
+
const childrenForRender = virtualView.inViewportChildren;
|
|
3193
3193
|
if (!this.listRender.initialized) {
|
|
3194
3194
|
this.listRender.initialize(childrenForRender, this.editor, this.context);
|
|
3195
3195
|
}
|
|
@@ -3230,8 +3230,8 @@ class SlateEditable {
|
|
|
3230
3230
|
toNativeSelection() {
|
|
3231
3231
|
try {
|
|
3232
3232
|
let { selection } = this.editor;
|
|
3233
|
-
if (this.
|
|
3234
|
-
const indics = Array.from(this.
|
|
3233
|
+
if (this.virtualScrollConfig?.enabled && selection) {
|
|
3234
|
+
const indics = Array.from(this.inViewportIndics.values());
|
|
3235
3235
|
if (indics.length > 0) {
|
|
3236
3236
|
const currentVisibleRange = {
|
|
3237
3237
|
anchor: Editor.start(this.editor, [indics[0]]),
|
|
@@ -3335,10 +3335,10 @@ class SlateEditable {
|
|
|
3335
3335
|
ngDoCheck() { }
|
|
3336
3336
|
forceRender() {
|
|
3337
3337
|
this.updateContext();
|
|
3338
|
-
const virtualView = this.
|
|
3338
|
+
const virtualView = this.calculateVirtualViewport();
|
|
3339
3339
|
this.applyVirtualView(virtualView);
|
|
3340
|
-
const visibleIndexes = Array.from(this.
|
|
3341
|
-
this.listRender.update(this.
|
|
3340
|
+
const visibleIndexes = Array.from(this.inViewportIndics);
|
|
3341
|
+
this.listRender.update(this.inViewportChildren, this.editor, this.context);
|
|
3342
3342
|
this.remeasureHeightByIndics(visibleIndexes);
|
|
3343
3343
|
// repair collaborative editing when Chinese input is interrupted by other users' cursors
|
|
3344
3344
|
// when the DOMElement where the selection is located is removed
|
|
@@ -3378,9 +3378,9 @@ class SlateEditable {
|
|
|
3378
3378
|
render() {
|
|
3379
3379
|
const changed = this.updateContext();
|
|
3380
3380
|
if (changed) {
|
|
3381
|
-
const virtualView = this.
|
|
3381
|
+
const virtualView = this.calculateVirtualViewport();
|
|
3382
3382
|
this.applyVirtualView(virtualView);
|
|
3383
|
-
this.listRender.update(virtualView.
|
|
3383
|
+
this.listRender.update(virtualView.inViewportChildren, this.editor, this.context);
|
|
3384
3384
|
this.scheduleMeasureVisibleHeights();
|
|
3385
3385
|
}
|
|
3386
3386
|
}
|
|
@@ -3444,14 +3444,14 @@ class SlateEditable {
|
|
|
3444
3444
|
decorations.push(...placeholderDecorations);
|
|
3445
3445
|
return decorations;
|
|
3446
3446
|
}
|
|
3447
|
-
|
|
3448
|
-
return !!(this.
|
|
3447
|
+
isEnabledVirtualScroll() {
|
|
3448
|
+
return !!(this.virtualScrollConfig && this.virtualScrollConfig.enabled);
|
|
3449
3449
|
}
|
|
3450
|
-
|
|
3450
|
+
initializeVirtualScroll() {
|
|
3451
3451
|
if (this.virtualScrollInitialized) {
|
|
3452
3452
|
return;
|
|
3453
3453
|
}
|
|
3454
|
-
if (this.
|
|
3454
|
+
if (this.virtualScrollConfig && this.virtualScrollConfig.enabled) {
|
|
3455
3455
|
this.virtualScrollInitialized = true;
|
|
3456
3456
|
this.virtualTopHeightElement = document.createElement('div');
|
|
3457
3457
|
this.virtualTopHeightElement.classList.add('virtual-top-height');
|
|
@@ -3469,7 +3469,7 @@ class SlateEditable {
|
|
|
3469
3469
|
this.editorResizeObserver = new ResizeObserver(entries => {
|
|
3470
3470
|
if (entries.length > 0 && entries[0].contentRect.width !== editorResizeObserverRectWidth) {
|
|
3471
3471
|
editorResizeObserverRectWidth = entries[0].contentRect.width;
|
|
3472
|
-
this.remeasureHeightByIndics(Array.from(this.
|
|
3472
|
+
this.remeasureHeightByIndics(Array.from(this.inViewportIndics));
|
|
3473
3473
|
}
|
|
3474
3474
|
});
|
|
3475
3475
|
this.editorResizeObserver.observe(this.elementRef.nativeElement);
|
|
@@ -3479,7 +3479,7 @@ class SlateEditable {
|
|
|
3479
3479
|
}
|
|
3480
3480
|
}
|
|
3481
3481
|
}
|
|
3482
|
-
|
|
3482
|
+
setVirtualSpaceHeight(topHeight, bottomHeight) {
|
|
3483
3483
|
if (!this.virtualScrollInitialized) {
|
|
3484
3484
|
return;
|
|
3485
3485
|
}
|
|
@@ -3490,19 +3490,19 @@ class SlateEditable {
|
|
|
3490
3490
|
const doc = this.elementRef?.nativeElement?.ownerDocument ?? document;
|
|
3491
3491
|
VirtualScrollDebugOverlay.log(doc, type, ...args);
|
|
3492
3492
|
}
|
|
3493
|
-
|
|
3493
|
+
tryUpdateVirtualViewport() {
|
|
3494
3494
|
this.refreshVirtualViewAnimId && cancelAnimationFrame(this.refreshVirtualViewAnimId);
|
|
3495
3495
|
this.refreshVirtualViewAnimId = requestAnimationFrame(() => {
|
|
3496
|
-
let virtualView = this.
|
|
3497
|
-
let diff = this.
|
|
3496
|
+
let virtualView = this.calculateVirtualViewport();
|
|
3497
|
+
let diff = this.diffVirtualViewport(virtualView);
|
|
3498
3498
|
if (!diff.isDiff) {
|
|
3499
3499
|
return;
|
|
3500
3500
|
}
|
|
3501
3501
|
if (diff.isMissingTop) {
|
|
3502
3502
|
const result = this.remeasureHeightByIndics(diff.diffTopRenderedIndexes);
|
|
3503
3503
|
if (result) {
|
|
3504
|
-
virtualView = this.
|
|
3505
|
-
diff = this.
|
|
3504
|
+
virtualView = this.calculateVirtualViewport();
|
|
3505
|
+
diff = this.diffVirtualViewport(virtualView, 'second');
|
|
3506
3506
|
if (!diff.isDiff) {
|
|
3507
3507
|
return;
|
|
3508
3508
|
}
|
|
@@ -3510,7 +3510,7 @@ class SlateEditable {
|
|
|
3510
3510
|
}
|
|
3511
3511
|
this.applyVirtualView(virtualView);
|
|
3512
3512
|
if (this.listRender.initialized) {
|
|
3513
|
-
this.listRender.update(virtualView.
|
|
3513
|
+
this.listRender.update(virtualView.inViewportChildren, this.editor, this.context);
|
|
3514
3514
|
if (!AngularEditor.isReadOnly(this.editor) && this.editor.selection) {
|
|
3515
3515
|
this.toNativeSelection();
|
|
3516
3516
|
}
|
|
@@ -3518,26 +3518,26 @@ class SlateEditable {
|
|
|
3518
3518
|
this.scheduleMeasureVisibleHeights();
|
|
3519
3519
|
});
|
|
3520
3520
|
}
|
|
3521
|
-
|
|
3521
|
+
calculateVirtualViewport() {
|
|
3522
3522
|
const children = (this.editor.children || []);
|
|
3523
|
-
if (!children.length || !this.
|
|
3523
|
+
if (!children.length || !this.isEnabledVirtualScroll()) {
|
|
3524
3524
|
return {
|
|
3525
|
-
|
|
3525
|
+
inViewportChildren: children,
|
|
3526
3526
|
visibleIndexes: new Set(),
|
|
3527
3527
|
top: 0,
|
|
3528
3528
|
bottom: 0,
|
|
3529
3529
|
heights: []
|
|
3530
3530
|
};
|
|
3531
3531
|
}
|
|
3532
|
-
const scrollTop = this.
|
|
3532
|
+
const scrollTop = this.virtualScrollConfig.scrollTop;
|
|
3533
3533
|
if (isDebug) {
|
|
3534
3534
|
const doc = this.elementRef?.nativeElement?.ownerDocument ?? document;
|
|
3535
3535
|
VirtualScrollDebugOverlay.syncScrollTop(doc, Number.isFinite(scrollTop) ? scrollTop : 0);
|
|
3536
3536
|
}
|
|
3537
|
-
const viewportHeight = this.
|
|
3537
|
+
const viewportHeight = this.virtualScrollConfig.viewportHeight ?? 0;
|
|
3538
3538
|
if (!viewportHeight) {
|
|
3539
3539
|
return {
|
|
3540
|
-
|
|
3540
|
+
inViewportChildren: [],
|
|
3541
3541
|
visibleIndexes: new Set(),
|
|
3542
3542
|
top: 0,
|
|
3543
3543
|
bottom: 0,
|
|
@@ -3577,7 +3577,7 @@ class SlateEditable {
|
|
|
3577
3577
|
const top = visibleStartIndex === -1 ? 0 : accumulatedHeights[visibleStartIndex];
|
|
3578
3578
|
const bottom = totalHeight - accumulatedHeights[visibleEndIndex + 1];
|
|
3579
3579
|
return {
|
|
3580
|
-
|
|
3580
|
+
inViewportChildren: visible.length ? visible : children,
|
|
3581
3581
|
visibleIndexes: new Set(visibleIndexes),
|
|
3582
3582
|
top,
|
|
3583
3583
|
bottom,
|
|
@@ -3585,19 +3585,19 @@ class SlateEditable {
|
|
|
3585
3585
|
};
|
|
3586
3586
|
}
|
|
3587
3587
|
applyVirtualView(virtualView) {
|
|
3588
|
-
this.
|
|
3589
|
-
this.
|
|
3590
|
-
this.
|
|
3588
|
+
this.inViewportChildren = virtualView.inViewportChildren;
|
|
3589
|
+
this.setVirtualSpaceHeight(virtualView.top, virtualView.bottom);
|
|
3590
|
+
this.inViewportIndics = virtualView.visibleIndexes;
|
|
3591
3591
|
}
|
|
3592
|
-
|
|
3593
|
-
if (!this.
|
|
3592
|
+
diffVirtualViewport(virtualView, stage = 'first') {
|
|
3593
|
+
if (!this.inViewportChildren.length) {
|
|
3594
3594
|
return {
|
|
3595
3595
|
isDiff: true,
|
|
3596
3596
|
diffTopRenderedIndexes: [],
|
|
3597
3597
|
diffBottomRenderedIndexes: []
|
|
3598
3598
|
};
|
|
3599
3599
|
}
|
|
3600
|
-
const oldVisibleIndexes = [...this.
|
|
3600
|
+
const oldVisibleIndexes = [...this.inViewportIndics];
|
|
3601
3601
|
const newVisibleIndexes = [...virtualView.visibleIndexes];
|
|
3602
3602
|
const firstNewIndex = newVisibleIndexes[0];
|
|
3603
3603
|
const lastNewIndex = newVisibleIndexes[newVisibleIndexes.length - 1];
|
|
@@ -3653,7 +3653,7 @@ class SlateEditable {
|
|
|
3653
3653
|
}
|
|
3654
3654
|
}
|
|
3655
3655
|
if (isDebug) {
|
|
3656
|
-
this.debugLog('log', `======
|
|
3656
|
+
this.debugLog('log', `====== diffVirtualViewport stage: ${stage} ======`);
|
|
3657
3657
|
this.debugLog('log', 'oldVisibleIndexes:', oldVisibleIndexes);
|
|
3658
3658
|
this.debugLog('log', 'newVisibleIndexes:', newVisibleIndexes);
|
|
3659
3659
|
this.debugLog('log', 'diffTopRenderedIndexes:', isMissingTop ? '-' : isAddedTop ? '+' : '-', diffTopRenderedIndexes, diffTopRenderedIndexes.map(index => this.getBlockHeight(index, 0)));
|
|
@@ -3692,11 +3692,11 @@ class SlateEditable {
|
|
|
3692
3692
|
return defaultHeight;
|
|
3693
3693
|
}
|
|
3694
3694
|
const key = AngularEditor.findKey(this.editor, node);
|
|
3695
|
-
const height = this.
|
|
3695
|
+
const height = this.keyHeightMap.get(key.id);
|
|
3696
3696
|
if (typeof height === 'number') {
|
|
3697
3697
|
return height;
|
|
3698
3698
|
}
|
|
3699
|
-
if (this.
|
|
3699
|
+
if (this.keyHeightMap.has(key.id)) {
|
|
3700
3700
|
console.error('getBlockHeight: invalid height value', key.id, height);
|
|
3701
3701
|
}
|
|
3702
3702
|
return defaultHeight;
|
|
@@ -3710,7 +3710,7 @@ class SlateEditable {
|
|
|
3710
3710
|
return accumulatedHeights;
|
|
3711
3711
|
}
|
|
3712
3712
|
scheduleMeasureVisibleHeights() {
|
|
3713
|
-
if (!this.
|
|
3713
|
+
if (!this.isEnabledVirtualScroll()) {
|
|
3714
3714
|
return;
|
|
3715
3715
|
}
|
|
3716
3716
|
this.measureVisibleHeightsAnimId && cancelAnimationFrame(this.measureVisibleHeightsAnimId);
|
|
@@ -3720,14 +3720,14 @@ class SlateEditable {
|
|
|
3720
3720
|
}
|
|
3721
3721
|
measureVisibleHeights() {
|
|
3722
3722
|
const children = (this.editor.children || []);
|
|
3723
|
-
this.
|
|
3723
|
+
this.inViewportIndics.forEach(index => {
|
|
3724
3724
|
const node = children[index];
|
|
3725
3725
|
if (!node) {
|
|
3726
3726
|
return;
|
|
3727
3727
|
}
|
|
3728
3728
|
const key = AngularEditor.findKey(this.editor, node);
|
|
3729
3729
|
// 跳过已测过的块,除非强制测量
|
|
3730
|
-
if (this.
|
|
3730
|
+
if (this.keyHeightMap.has(key.id)) {
|
|
3731
3731
|
return;
|
|
3732
3732
|
}
|
|
3733
3733
|
const view = ELEMENT_TO_COMPONENT.get(node);
|
|
@@ -3737,11 +3737,11 @@ class SlateEditable {
|
|
|
3737
3737
|
const ret = view.getRealHeight();
|
|
3738
3738
|
if (ret instanceof Promise) {
|
|
3739
3739
|
ret.then(height => {
|
|
3740
|
-
this.
|
|
3740
|
+
this.keyHeightMap.set(key.id, height);
|
|
3741
3741
|
});
|
|
3742
3742
|
}
|
|
3743
3743
|
else {
|
|
3744
|
-
this.
|
|
3744
|
+
this.keyHeightMap.set(key.id, ret);
|
|
3745
3745
|
}
|
|
3746
3746
|
});
|
|
3747
3747
|
}
|
|
@@ -3758,12 +3758,12 @@ class SlateEditable {
|
|
|
3758
3758
|
if (!view) {
|
|
3759
3759
|
return;
|
|
3760
3760
|
}
|
|
3761
|
-
const prevHeight = this.
|
|
3761
|
+
const prevHeight = this.keyHeightMap.get(key.id);
|
|
3762
3762
|
const ret = view.getRealHeight();
|
|
3763
3763
|
if (ret instanceof Promise) {
|
|
3764
3764
|
ret.then(height => {
|
|
3765
3765
|
if (height !== prevHeight) {
|
|
3766
|
-
this.
|
|
3766
|
+
this.keyHeightMap.set(key.id, height);
|
|
3767
3767
|
isHeightChanged = true;
|
|
3768
3768
|
if (isDebug) {
|
|
3769
3769
|
this.debugLog('log', `remeasureHeightByIndics, index: ${index} prevHeight: ${prevHeight} newHeight: ${height}`);
|
|
@@ -3773,7 +3773,7 @@ class SlateEditable {
|
|
|
3773
3773
|
}
|
|
3774
3774
|
else {
|
|
3775
3775
|
if (ret !== prevHeight) {
|
|
3776
|
-
this.
|
|
3776
|
+
this.keyHeightMap.set(key.id, ret);
|
|
3777
3777
|
isHeightChanged = true;
|
|
3778
3778
|
if (isDebug) {
|
|
3779
3779
|
this.debugLog('log', `remeasureHeightByIndics, index: ${index} prevHeight: ${prevHeight} newHeight: ${ret}`);
|