slate-angular 20.2.0-next.23 → 20.2.0-next.24
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 +93 -55
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +10 -4
- package/package.json +1 -1
|
@@ -2352,8 +2352,9 @@ class ListRender {
|
|
|
2352
2352
|
this.viewTypes = [];
|
|
2353
2353
|
this.differ = null;
|
|
2354
2354
|
this.initialized = false;
|
|
2355
|
+
this.preRenderingHTMLElement = [];
|
|
2355
2356
|
}
|
|
2356
|
-
initialize(children, parent, childrenContext) {
|
|
2357
|
+
initialize(children, parent, childrenContext, preRenderingCount = 0) {
|
|
2357
2358
|
this.initialized = true;
|
|
2358
2359
|
this.children = children;
|
|
2359
2360
|
const isRoot = parent === this.viewContext.editor;
|
|
@@ -2379,15 +2380,26 @@ class ListRender {
|
|
|
2379
2380
|
executeAfterViewInit(this.viewContext.editor);
|
|
2380
2381
|
}
|
|
2381
2382
|
}
|
|
2382
|
-
update(children, parent, childrenContext) {
|
|
2383
|
+
update(children, parent, childrenContext, preRenderingCount = 0) {
|
|
2383
2384
|
if (!this.initialized || this.children.length === 0) {
|
|
2384
|
-
this.initialize(children, parent, childrenContext);
|
|
2385
|
+
this.initialize(children, parent, childrenContext, preRenderingCount);
|
|
2385
2386
|
return;
|
|
2386
2387
|
}
|
|
2387
2388
|
if (!this.differ) {
|
|
2388
2389
|
throw new Error('Exception: Can not find differ ');
|
|
2389
2390
|
}
|
|
2390
2391
|
const outletParent = this.getOutletParent();
|
|
2392
|
+
if (this.preRenderingHTMLElement.length > 0) {
|
|
2393
|
+
const preRenderingElement = [...this.preRenderingHTMLElement];
|
|
2394
|
+
preRenderingElement.forEach((rootNodes, index) => {
|
|
2395
|
+
rootNodes.forEach(rootNode => {
|
|
2396
|
+
rootNode.style.position = '';
|
|
2397
|
+
rootNode.style.top = '';
|
|
2398
|
+
rootNode.style.width = '';
|
|
2399
|
+
});
|
|
2400
|
+
});
|
|
2401
|
+
this.preRenderingHTMLElement = [];
|
|
2402
|
+
}
|
|
2391
2403
|
const diffResult = this.differ.diff(children);
|
|
2392
2404
|
const parentPath = AngularEditor.findPath(this.viewContext.editor, parent);
|
|
2393
2405
|
const isRoot = parent === this.viewContext.editor;
|
|
@@ -2485,6 +2497,15 @@ class ListRender {
|
|
|
2485
2497
|
});
|
|
2486
2498
|
this.contexts = newContexts;
|
|
2487
2499
|
}
|
|
2500
|
+
if (preRenderingCount > 0) {
|
|
2501
|
+
for (let i = 0; i < preRenderingCount; i++) {
|
|
2502
|
+
const rootNodes = [...getRootNodes(this.views[i], this.blockCards[i])];
|
|
2503
|
+
rootNodes.forEach(rootNode => {
|
|
2504
|
+
rootNode.style = `position: absolute;top: -100%;`;
|
|
2505
|
+
});
|
|
2506
|
+
this.preRenderingHTMLElement.push(rootNodes);
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2488
2509
|
}
|
|
2489
2510
|
destroy() {
|
|
2490
2511
|
this.children.forEach((element, index) => {
|
|
@@ -3200,7 +3221,7 @@ class SlateEditable {
|
|
|
3200
3221
|
viewportBoundingTop: 0
|
|
3201
3222
|
};
|
|
3202
3223
|
this.inViewportChildren = [];
|
|
3203
|
-
this.inViewportIndics =
|
|
3224
|
+
this.inViewportIndics = [];
|
|
3204
3225
|
this.keyHeightMap = new Map();
|
|
3205
3226
|
this.virtualScrollInitialized = false;
|
|
3206
3227
|
}
|
|
@@ -3267,7 +3288,8 @@ class SlateEditable {
|
|
|
3267
3288
|
this.listRender.initialize(childrenForRender, this.editor, this.context);
|
|
3268
3289
|
}
|
|
3269
3290
|
else {
|
|
3270
|
-
|
|
3291
|
+
const { preRenderingCount, childrenWithPreRendering } = this.handlePreRendering();
|
|
3292
|
+
this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount);
|
|
3271
3293
|
}
|
|
3272
3294
|
this.tryMeasureInViewportChildrenHeights();
|
|
3273
3295
|
}
|
|
@@ -3311,7 +3333,7 @@ class SlateEditable {
|
|
|
3311
3333
|
}
|
|
3312
3334
|
calculateVirtualScrollSelection(selection) {
|
|
3313
3335
|
if (selection) {
|
|
3314
|
-
const indics =
|
|
3336
|
+
const indics = this.inViewportIndics;
|
|
3315
3337
|
if (indics.length > 0) {
|
|
3316
3338
|
const currentVisibleRange = {
|
|
3317
3339
|
anchor: Editor.start(this.editor, [indics[0]]),
|
|
@@ -3482,13 +3504,13 @@ class SlateEditable {
|
|
|
3482
3504
|
const virtualView = this.calculateVirtualViewport();
|
|
3483
3505
|
const oldInViewportChildren = this.inViewportChildren;
|
|
3484
3506
|
this.applyVirtualView(virtualView);
|
|
3485
|
-
|
|
3507
|
+
const { preRenderingCount, childrenWithPreRendering } = this.handlePreRendering();
|
|
3508
|
+
this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount);
|
|
3486
3509
|
// 新增或者修改的才需要重算,计算出这个结果
|
|
3487
3510
|
const remeasureIndics = [];
|
|
3488
|
-
const newInViewportIndics = Array.from(this.inViewportIndics);
|
|
3489
3511
|
this.inViewportChildren.forEach((child, index) => {
|
|
3490
3512
|
if (oldInViewportChildren.indexOf(child) === -1) {
|
|
3491
|
-
remeasureIndics.push(
|
|
3513
|
+
remeasureIndics.push(this.inViewportIndics[index]);
|
|
3492
3514
|
}
|
|
3493
3515
|
});
|
|
3494
3516
|
if (isDebug && remeasureIndics.length > 0) {
|
|
@@ -3581,7 +3603,7 @@ class SlateEditable {
|
|
|
3581
3603
|
if (entries.length > 0 && entries[0].contentRect.width !== editorResizeObserverRectWidth) {
|
|
3582
3604
|
editorResizeObserverRectWidth = entries[0].contentRect.width;
|
|
3583
3605
|
this.keyHeightMap.clear();
|
|
3584
|
-
const remeasureIndics =
|
|
3606
|
+
const remeasureIndics = this.inViewportIndics;
|
|
3585
3607
|
this.remeasureHeightByIndics(remeasureIndics);
|
|
3586
3608
|
}
|
|
3587
3609
|
});
|
|
@@ -3597,62 +3619,77 @@ class SlateEditable {
|
|
|
3597
3619
|
return;
|
|
3598
3620
|
}
|
|
3599
3621
|
this.virtualTopHeightElement.style.height = `${topHeight}px`;
|
|
3600
|
-
|
|
3622
|
+
if (bottomHeight !== undefined) {
|
|
3623
|
+
this.virtualBottomHeightElement.style.height = `${bottomHeight}px`;
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3626
|
+
getVirtualTopHeight() {
|
|
3627
|
+
if (!this.virtualScrollInitialized) {
|
|
3628
|
+
return 0;
|
|
3629
|
+
}
|
|
3630
|
+
return parseFloat(this.virtualTopHeightElement.style.height.replace('px', ''));
|
|
3601
3631
|
}
|
|
3602
3632
|
debugLog(type, ...args) {
|
|
3603
3633
|
const doc = this.elementRef?.nativeElement?.ownerDocument ?? document;
|
|
3604
3634
|
VirtualScrollDebugOverlay.log(doc, type, ...args);
|
|
3605
3635
|
}
|
|
3636
|
+
handlePreRendering() {
|
|
3637
|
+
let preRenderingCount = 0;
|
|
3638
|
+
const childrenWithPreRendering = [...this.inViewportChildren];
|
|
3639
|
+
if (this.inViewportIndics[0] !== 0) {
|
|
3640
|
+
preRenderingCount = 1;
|
|
3641
|
+
childrenWithPreRendering.unshift(this.editor.children[this.inViewportIndics[0] - 1]);
|
|
3642
|
+
}
|
|
3643
|
+
return { preRenderingCount, childrenWithPreRendering };
|
|
3644
|
+
}
|
|
3606
3645
|
tryUpdateVirtualViewport() {
|
|
3646
|
+
if (isDebug) {
|
|
3647
|
+
this.debugLog('log', 'tryUpdateVirtualViewport');
|
|
3648
|
+
}
|
|
3607
3649
|
this.tryUpdateVirtualViewportAnimId && cancelAnimationFrame(this.tryUpdateVirtualViewportAnimId);
|
|
3608
3650
|
this.tryUpdateVirtualViewportAnimId = requestAnimationFrame(() => {
|
|
3651
|
+
if (isDebug) {
|
|
3652
|
+
this.debugLog('log', 'tryUpdateVirtualViewport Anim start');
|
|
3653
|
+
}
|
|
3609
3654
|
let virtualView = this.calculateVirtualViewport();
|
|
3610
3655
|
let diff = this.diffVirtualViewport(virtualView);
|
|
3611
|
-
if (
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
if (result) {
|
|
3619
|
-
virtualView = this.calculateVirtualViewport();
|
|
3620
|
-
diff = this.diffVirtualViewport(virtualView, 'second');
|
|
3621
|
-
if (!diff.isDiff) {
|
|
3622
|
-
return;
|
|
3656
|
+
if (diff.isDiff) {
|
|
3657
|
+
this.applyVirtualView(virtualView);
|
|
3658
|
+
if (this.listRender.initialized) {
|
|
3659
|
+
const { preRenderingCount, childrenWithPreRendering } = this.handlePreRendering();
|
|
3660
|
+
this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount);
|
|
3661
|
+
if (!AngularEditor.isReadOnly(this.editor) && this.editor.selection) {
|
|
3662
|
+
this.toNativeSelection();
|
|
3623
3663
|
}
|
|
3624
3664
|
}
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3665
|
+
if (diff.isAddedTop) {
|
|
3666
|
+
const remeasureAddedIndics = diff.diffTopRenderedIndexes;
|
|
3667
|
+
if (isDebug) {
|
|
3668
|
+
this.debugLog('log', 'isAddedTop to remeasure heights: ', remeasureAddedIndics);
|
|
3669
|
+
}
|
|
3670
|
+
const startIndexBeforeAdd = diff.diffTopRenderedIndexes[diff.diffTopRenderedIndexes.length - 1] + 1;
|
|
3671
|
+
const topHeightBeforeAdd = virtualView.accumulatedHeights[startIndexBeforeAdd];
|
|
3672
|
+
const result = this.remeasureHeightByIndics(remeasureAddedIndics);
|
|
3673
|
+
if (result) {
|
|
3674
|
+
const newHeights = buildHeightsAndAccumulatedHeights(this.editor);
|
|
3675
|
+
const actualTopHeightAfterAdd = newHeights.accumulatedHeights[startIndexBeforeAdd];
|
|
3676
|
+
const newTopHeight = virtualView.top - (actualTopHeightAfterAdd - topHeightBeforeAdd);
|
|
3677
|
+
this.setVirtualSpaceHeight(newTopHeight);
|
|
3678
|
+
this.debugLog('log', `update top height cause added element in top, 减去: ${actualTopHeightAfterAdd - topHeightBeforeAdd}`);
|
|
3679
|
+
}
|
|
3631
3680
|
}
|
|
3681
|
+
this.tryMeasureInViewportChildrenHeights();
|
|
3632
3682
|
}
|
|
3633
|
-
|
|
3634
|
-
const
|
|
3635
|
-
if (
|
|
3636
|
-
this.debugLog('log', '
|
|
3637
|
-
|
|
3638
|
-
const startIndexBeforeAdd = diff.diffTopRenderedIndexes[diff.diffTopRenderedIndexes.length - 1] + 1;
|
|
3639
|
-
const topHeightBeforeAdd = virtualView.accumulatedHeights[startIndexBeforeAdd];
|
|
3640
|
-
const result = this.remeasureHeightByIndics(remeasureAddedIndics);
|
|
3641
|
-
if (result) {
|
|
3642
|
-
const newHeights = buildHeightsAndAccumulatedHeights(this.editor);
|
|
3643
|
-
const visibleStartIndex = diff.diffTopRenderedIndexes[0];
|
|
3644
|
-
const actualTopHeightAfterAdd = newHeights.accumulatedHeights[startIndexBeforeAdd];
|
|
3645
|
-
const adjustedTopHeight = (visibleStartIndex === -1 ? 0 : newHeights.accumulatedHeights[visibleStartIndex]) -
|
|
3646
|
-
(actualTopHeightAfterAdd - topHeightBeforeAdd);
|
|
3647
|
-
if (adjustedTopHeight !== virtualView.top) {
|
|
3648
|
-
if (isDebug) {
|
|
3649
|
-
this.debugLog('log', `update top height cause added element in top: ${adjustedTopHeight}, old height: ${virtualView.top}`);
|
|
3650
|
-
}
|
|
3651
|
-
this.virtualTopHeightElement.style.height = `${adjustedTopHeight}px`;
|
|
3652
|
-
}
|
|
3683
|
+
else {
|
|
3684
|
+
const topHeight = this.getVirtualTopHeight();
|
|
3685
|
+
if (virtualView.top !== topHeight) {
|
|
3686
|
+
this.debugLog('log', 'update top height: ', virtualView.top - topHeight, 'start index', this.inViewportIndics[0]);
|
|
3687
|
+
this.setVirtualSpaceHeight(virtualView.top);
|
|
3653
3688
|
}
|
|
3654
3689
|
}
|
|
3655
|
-
|
|
3690
|
+
if (isDebug) {
|
|
3691
|
+
this.debugLog('log', 'tryUpdateVirtualViewport Anim end');
|
|
3692
|
+
}
|
|
3656
3693
|
});
|
|
3657
3694
|
}
|
|
3658
3695
|
calculateVirtualViewport() {
|
|
@@ -3660,7 +3697,7 @@ class SlateEditable {
|
|
|
3660
3697
|
if (!children.length || !this.isEnabledVirtualScroll()) {
|
|
3661
3698
|
return {
|
|
3662
3699
|
inViewportChildren: children,
|
|
3663
|
-
visibleIndexes:
|
|
3700
|
+
visibleIndexes: [],
|
|
3664
3701
|
top: 0,
|
|
3665
3702
|
bottom: 0,
|
|
3666
3703
|
heights: []
|
|
@@ -3675,7 +3712,7 @@ class SlateEditable {
|
|
|
3675
3712
|
if (!viewportHeight) {
|
|
3676
3713
|
return {
|
|
3677
3714
|
inViewportChildren: [],
|
|
3678
|
-
visibleIndexes:
|
|
3715
|
+
visibleIndexes: [],
|
|
3679
3716
|
top: 0,
|
|
3680
3717
|
bottom: 0,
|
|
3681
3718
|
heights: []
|
|
@@ -3727,7 +3764,7 @@ class SlateEditable {
|
|
|
3727
3764
|
const bottom = totalHeight - accumulatedHeights[visibleEndIndex + 1];
|
|
3728
3765
|
return {
|
|
3729
3766
|
inViewportChildren: visible.length ? visible : children,
|
|
3730
|
-
visibleIndexes
|
|
3767
|
+
visibleIndexes,
|
|
3731
3768
|
top,
|
|
3732
3769
|
bottom,
|
|
3733
3770
|
heights,
|
|
@@ -3812,7 +3849,7 @@ class SlateEditable {
|
|
|
3812
3849
|
const needBottom = virtualView.heights
|
|
3813
3850
|
.slice(newVisibleIndexes[newVisibleIndexes.length - 1] + 1)
|
|
3814
3851
|
.reduce((acc, height) => acc + height, 0);
|
|
3815
|
-
this.debugLog('log', 'newTopHeight:', needTop, 'prevTopHeight:', parseFloat(this.virtualTopHeightElement.style.height));
|
|
3852
|
+
this.debugLog('log', needTop - parseFloat(this.virtualTopHeightElement.style.height), 'newTopHeight:', needTop, 'prevTopHeight:', parseFloat(this.virtualTopHeightElement.style.height));
|
|
3816
3853
|
this.debugLog('log', 'newBottomHeight:', needBottom, 'prevBottomHeight:', parseFloat(this.virtualBottomHeightElement.style.height));
|
|
3817
3854
|
this.debugLog('warn', '=========== Dividing line ===========');
|
|
3818
3855
|
}
|
|
@@ -3843,7 +3880,8 @@ class SlateEditable {
|
|
|
3843
3880
|
}
|
|
3844
3881
|
measureVisibleHeights() {
|
|
3845
3882
|
const children = (this.editor.children || []);
|
|
3846
|
-
this.inViewportIndics
|
|
3883
|
+
const inViewportIndics = [...this.inViewportIndics];
|
|
3884
|
+
inViewportIndics.forEach(index => {
|
|
3847
3885
|
const node = children[index];
|
|
3848
3886
|
if (!node) {
|
|
3849
3887
|
return;
|