slate-angular 20.2.11 → 20.2.12
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 +41 -27
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import * as i0 from '@angular/core';
|
|
|
5
5
|
import { TemplateRef, ComponentRef, IterableDiffers, inject, ViewContainerRef, forwardRef, HostBinding, Input, ChangeDetectionStrategy, Component, NgModule, ElementRef, ChangeDetectorRef, Directive, ViewChild } from '@angular/core';
|
|
6
6
|
import { direction } from 'direction';
|
|
7
7
|
import scrollIntoView from 'scroll-into-view-if-needed';
|
|
8
|
-
import { Subject, debounceTime } from 'rxjs';
|
|
8
|
+
import { Subject, tap, debounceTime, filter } from 'rxjs';
|
|
9
9
|
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
10
10
|
import { HistoryEditor } from 'slate-history';
|
|
11
11
|
import { CommonModule } from '@angular/common';
|
|
@@ -1566,7 +1566,10 @@ const measureHeightByIndics = (editor, indics, force = false) => {
|
|
|
1566
1566
|
return;
|
|
1567
1567
|
}
|
|
1568
1568
|
hasChanged = true;
|
|
1569
|
-
calcHeightByElement(editor, element);
|
|
1569
|
+
const currentHeight = calcHeightByElement(editor, element);
|
|
1570
|
+
if (isDebug) {
|
|
1571
|
+
debugLog('log', 'measureHeightByIndics: height not equal, index: ', index, 'preHeight: ', preHeight, 'height: ', currentHeight);
|
|
1572
|
+
}
|
|
1570
1573
|
});
|
|
1571
1574
|
return hasChanged;
|
|
1572
1575
|
};
|
|
@@ -3383,7 +3386,7 @@ class SlateEditable {
|
|
|
3383
3386
|
this.inViewportChildren = [];
|
|
3384
3387
|
this.inViewportIndics = [];
|
|
3385
3388
|
this.keyHeightMap = new Map();
|
|
3386
|
-
this.
|
|
3389
|
+
this.indicsOfNeedBeMeasured$ = new Subject();
|
|
3387
3390
|
this.virtualScrollInitialized = false;
|
|
3388
3391
|
}
|
|
3389
3392
|
ngOnInit() {
|
|
@@ -3442,6 +3445,7 @@ class SlateEditable {
|
|
|
3442
3445
|
this.editor.children = value;
|
|
3443
3446
|
this.initializeContext();
|
|
3444
3447
|
if (this.isEnabledVirtualScroll()) {
|
|
3448
|
+
const previousInViewportChildren = [...this.inViewportChildren];
|
|
3445
3449
|
const visibleStates = this.editor.getAllVisibleStates();
|
|
3446
3450
|
const virtualView = this.calculateVirtualViewport(visibleStates);
|
|
3447
3451
|
this.applyVirtualView(virtualView);
|
|
@@ -3456,7 +3460,10 @@ class SlateEditable {
|
|
|
3456
3460
|
const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.handlePreRendering(visibleStates);
|
|
3457
3461
|
this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount, childrenWithPreRenderingIndics);
|
|
3458
3462
|
}
|
|
3459
|
-
this.
|
|
3463
|
+
const remeasureIndics = this.getChangedIndics(previousInViewportChildren);
|
|
3464
|
+
if (remeasureIndics.length) {
|
|
3465
|
+
this.indicsOfNeedBeMeasured$.next(remeasureIndics);
|
|
3466
|
+
}
|
|
3460
3467
|
}
|
|
3461
3468
|
else {
|
|
3462
3469
|
if (!this.listRender.initialized) {
|
|
@@ -3701,6 +3708,7 @@ class SlateEditable {
|
|
|
3701
3708
|
}
|
|
3702
3709
|
updateListRenderAndRemeasureHeights() {
|
|
3703
3710
|
const visibleStates = this.editor.getAllVisibleStates();
|
|
3711
|
+
const previousInViewportChildren = [...this.inViewportChildren];
|
|
3704
3712
|
let virtualView = this.calculateVirtualViewport(visibleStates);
|
|
3705
3713
|
let diff = this.diffVirtualViewport(virtualView, 'onChange');
|
|
3706
3714
|
if (diff.isDifferent && diff.needRemoveOnTop) {
|
|
@@ -3711,18 +3719,13 @@ class SlateEditable {
|
|
|
3711
3719
|
diff = this.diffVirtualViewport(virtualView, 'second');
|
|
3712
3720
|
}
|
|
3713
3721
|
}
|
|
3714
|
-
// const oldInViewportChildren = this.inViewportChildren;
|
|
3715
3722
|
this.applyVirtualView(virtualView);
|
|
3716
3723
|
const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.handlePreRendering(visibleStates);
|
|
3717
3724
|
this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount, childrenWithPreRenderingIndics);
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
// remeasureIndics.push(this.inViewportIndics[index]);
|
|
3723
|
-
// }
|
|
3724
|
-
// });
|
|
3725
|
-
this.viewportRefresh$.next();
|
|
3725
|
+
const remeasureIndics = this.getChangedIndics(previousInViewportChildren);
|
|
3726
|
+
if (remeasureIndics.length) {
|
|
3727
|
+
this.indicsOfNeedBeMeasured$.next(remeasureIndics);
|
|
3728
|
+
}
|
|
3726
3729
|
}
|
|
3727
3730
|
updateContext() {
|
|
3728
3731
|
const decorations = this.generateDecorations();
|
|
@@ -3815,28 +3818,40 @@ class SlateEditable {
|
|
|
3815
3818
|
const target = firstDomElement || this.virtualTopHeightElement;
|
|
3816
3819
|
EDITOR_TO_ROOT_NODE_WIDTH.set(this.editor, target.offsetWidth);
|
|
3817
3820
|
updatePreRenderingElementWidth(this.editor);
|
|
3818
|
-
this.viewportRefresh$.next();
|
|
3819
3821
|
if (isDebug) {
|
|
3820
3822
|
debugLog('log', 'editorResizeObserverRectWidth: ', editorResizeObserverRectWidth, 'EDITOR_TO_ROOT_NODE_WIDTH: ', EDITOR_TO_ROOT_NODE_WIDTH.get(this.editor));
|
|
3821
3823
|
}
|
|
3822
3824
|
}
|
|
3823
3825
|
});
|
|
3824
3826
|
this.editorResizeObserver.observe(this.elementRef.nativeElement);
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3827
|
+
let pendingRemeasureIndics = [];
|
|
3828
|
+
this.indicsOfNeedBeMeasured$
|
|
3829
|
+
.pipe(tap((previousValue) => {
|
|
3830
|
+
previousValue.forEach((index) => {
|
|
3831
|
+
if (!pendingRemeasureIndics.includes(index)) {
|
|
3832
|
+
pendingRemeasureIndics.push(index);
|
|
3833
|
+
}
|
|
3834
|
+
});
|
|
3835
|
+
}), debounceTime(500), filter(() => pendingRemeasureIndics.length > 0))
|
|
3836
|
+
.subscribe(() => {
|
|
3837
|
+
measureHeightByIndics(this.editor, pendingRemeasureIndics, true);
|
|
3838
|
+
pendingRemeasureIndics = [];
|
|
3839
|
+
if (isDebug) {
|
|
3840
|
+
debugLog('log', 'exist pendingRemeasureIndics: ', pendingRemeasureIndics, 'will try to update virtual viewport');
|
|
3841
|
+
}
|
|
3842
|
+
this.tryUpdateVirtualViewport();
|
|
3837
3843
|
});
|
|
3838
3844
|
}
|
|
3839
3845
|
}
|
|
3846
|
+
getChangedIndics(previousValue) {
|
|
3847
|
+
const remeasureIndics = [];
|
|
3848
|
+
this.inViewportChildren.forEach((child, index) => {
|
|
3849
|
+
if (previousValue.indexOf(child) === -1) {
|
|
3850
|
+
remeasureIndics.push(this.inViewportIndics[index]);
|
|
3851
|
+
}
|
|
3852
|
+
});
|
|
3853
|
+
return remeasureIndics;
|
|
3854
|
+
}
|
|
3840
3855
|
setVirtualSpaceHeight(topHeight, bottomHeight) {
|
|
3841
3856
|
if (!this.virtualScrollInitialized) {
|
|
3842
3857
|
return;
|
|
@@ -3936,7 +3951,6 @@ class SlateEditable {
|
|
|
3936
3951
|
if (!AngularEditor.isReadOnly(this.editor) && this.editor.selection) {
|
|
3937
3952
|
this.toNativeSelection(false);
|
|
3938
3953
|
}
|
|
3939
|
-
this.viewportRefresh$.next();
|
|
3940
3954
|
}
|
|
3941
3955
|
}
|
|
3942
3956
|
if (isDebug) {
|