slate-angular 20.2.2 → 20.2.4
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 +36 -43
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +4 -7
- 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 } from 'rxjs';
|
|
8
|
+
import { Subject, debounceTime } 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';
|
|
@@ -1491,11 +1491,7 @@ const measureHeightByIndics = (editor, indics, force = false) => {
|
|
|
1491
1491
|
const getBusinessTop = (editor) => {
|
|
1492
1492
|
return EDITOR_TO_BUSINESS_TOP.get(editor) ?? 0;
|
|
1493
1493
|
};
|
|
1494
|
-
const getRealHeightByElement = (editor, element, defaultHeight
|
|
1495
|
-
const visible = isVisible ?? editor.isVisible(element);
|
|
1496
|
-
if (!visible) {
|
|
1497
|
-
return 0;
|
|
1498
|
-
}
|
|
1494
|
+
const getRealHeightByElement = (editor, element, defaultHeight) => {
|
|
1499
1495
|
const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
|
|
1500
1496
|
const key = AngularEditor.findKey(editor, element);
|
|
1501
1497
|
const height = heights?.get(key.id);
|
|
@@ -1505,22 +1501,19 @@ const getRealHeightByElement = (editor, element, defaultHeight = VIRTUAL_SCROLL_
|
|
|
1505
1501
|
if (heights?.has(key.id)) {
|
|
1506
1502
|
console.error('getBlockHeight: invalid height value', key.id, height);
|
|
1507
1503
|
}
|
|
1508
|
-
return defaultHeight;
|
|
1504
|
+
return editor.getRoughHeight(element, defaultHeight);
|
|
1509
1505
|
};
|
|
1510
1506
|
const buildHeightsAndAccumulatedHeights = (editor) => {
|
|
1511
1507
|
const children = (editor.children || []);
|
|
1512
1508
|
const heights = new Array(children.length);
|
|
1513
|
-
const visibleStates = new Array(children.length);
|
|
1514
1509
|
const accumulatedHeights = new Array(children.length + 1);
|
|
1515
1510
|
accumulatedHeights[0] = 0;
|
|
1516
1511
|
for (let i = 0; i < children.length; i++) {
|
|
1517
|
-
const
|
|
1518
|
-
visibleStates[i] = isVisible;
|
|
1519
|
-
const height = getRealHeightByElement(editor, children[i], VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, isVisible);
|
|
1512
|
+
const height = getRealHeightByElement(editor, children[i], VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT);
|
|
1520
1513
|
heights[i] = height;
|
|
1521
1514
|
accumulatedHeights[i + 1] = accumulatedHeights[i] + height;
|
|
1522
1515
|
}
|
|
1523
|
-
return { heights, accumulatedHeights
|
|
1516
|
+
return { heights, accumulatedHeights };
|
|
1524
1517
|
};
|
|
1525
1518
|
const calculateVirtualTopHeight = (editor, startIndex) => {
|
|
1526
1519
|
const { accumulatedHeights } = buildHeightsAndAccumulatedHeights(editor);
|
|
@@ -1737,6 +1730,9 @@ const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
|
|
|
1737
1730
|
e.isVisible = element => {
|
|
1738
1731
|
return true;
|
|
1739
1732
|
};
|
|
1733
|
+
e.getRoughHeight = (element, defaultHeight) => {
|
|
1734
|
+
return defaultHeight === undefined ? VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT : defaultHeight;
|
|
1735
|
+
};
|
|
1740
1736
|
return e;
|
|
1741
1737
|
};
|
|
1742
1738
|
|
|
@@ -2341,7 +2337,6 @@ class BaseElementFlavour extends BaseFlavour {
|
|
|
2341
2337
|
this.getOutletElement = () => {
|
|
2342
2338
|
return this.nativeElement.querySelector('.children-outlet');
|
|
2343
2339
|
};
|
|
2344
|
-
this.stableHeight = null;
|
|
2345
2340
|
}
|
|
2346
2341
|
get element() {
|
|
2347
2342
|
return this._context && this._context.element;
|
|
@@ -2428,20 +2423,11 @@ class BaseElementFlavour extends BaseFlavour {
|
|
|
2428
2423
|
readonly: this._context.readonly
|
|
2429
2424
|
};
|
|
2430
2425
|
}
|
|
2431
|
-
isStableHeight() {
|
|
2432
|
-
return false;
|
|
2433
|
-
}
|
|
2434
2426
|
getRealHeight() {
|
|
2435
|
-
if (this.isStableHeight() && this.stableHeight !== null) {
|
|
2436
|
-
return this.stableHeight;
|
|
2437
|
-
}
|
|
2438
2427
|
const blockCard = getBlockCardByNativeElement(this.nativeElement);
|
|
2439
2428
|
const target = blockCard || this.nativeElement;
|
|
2440
2429
|
const computedStyle = getComputedStyle(target);
|
|
2441
2430
|
const height = Math.ceil(target.getBoundingClientRect().height) + parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom);
|
|
2442
|
-
if (this.isStableHeight()) {
|
|
2443
|
-
this.stableHeight = height;
|
|
2444
|
-
}
|
|
2445
2431
|
return height;
|
|
2446
2432
|
}
|
|
2447
2433
|
}
|
|
@@ -3323,6 +3309,7 @@ class SlateEditable {
|
|
|
3323
3309
|
this.inViewportChildren = [];
|
|
3324
3310
|
this.inViewportIndics = [];
|
|
3325
3311
|
this.keyHeightMap = new Map();
|
|
3312
|
+
this.viewportRefresh$ = new Subject();
|
|
3326
3313
|
this.virtualScrollInitialized = false;
|
|
3327
3314
|
}
|
|
3328
3315
|
ngOnInit() {
|
|
@@ -3394,6 +3381,7 @@ class SlateEditable {
|
|
|
3394
3381
|
const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.handlePreRendering();
|
|
3395
3382
|
this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount, childrenWithPreRenderingIndics);
|
|
3396
3383
|
}
|
|
3384
|
+
this.viewportRefresh$.next();
|
|
3397
3385
|
}
|
|
3398
3386
|
else {
|
|
3399
3387
|
if (!this.listRender.initialized) {
|
|
@@ -3647,17 +3635,18 @@ class SlateEditable {
|
|
|
3647
3635
|
diff = this.diffVirtualViewport(virtualView, 'second');
|
|
3648
3636
|
}
|
|
3649
3637
|
}
|
|
3650
|
-
const oldInViewportChildren = this.inViewportChildren;
|
|
3638
|
+
// const oldInViewportChildren = this.inViewportChildren;
|
|
3651
3639
|
this.applyVirtualView(virtualView);
|
|
3652
3640
|
const { preRenderingCount, childrenWithPreRendering, childrenWithPreRenderingIndics } = this.handlePreRendering();
|
|
3653
3641
|
this.listRender.update(childrenWithPreRendering, this.editor, this.context, preRenderingCount, childrenWithPreRenderingIndics);
|
|
3654
3642
|
// 新增或者修改的才需要重算,计算出这个结果
|
|
3655
|
-
const remeasureIndics = [];
|
|
3656
|
-
this.inViewportChildren.forEach((child, index) => {
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
});
|
|
3643
|
+
// const remeasureIndics = [];
|
|
3644
|
+
// this.inViewportChildren.forEach((child, index) => {
|
|
3645
|
+
// if (oldInViewportChildren.indexOf(child) === -1) {
|
|
3646
|
+
// remeasureIndics.push(this.inViewportIndics[index]);
|
|
3647
|
+
// }
|
|
3648
|
+
// });
|
|
3649
|
+
this.viewportRefresh$.next();
|
|
3661
3650
|
}
|
|
3662
3651
|
updateContext() {
|
|
3663
3652
|
const decorations = this.generateDecorations();
|
|
@@ -3745,15 +3734,27 @@ class SlateEditable {
|
|
|
3745
3734
|
if (entries.length > 0 && entries[0].contentRect.width !== editorResizeObserverRectWidth) {
|
|
3746
3735
|
editorResizeObserverRectWidth = entries[0].contentRect.width;
|
|
3747
3736
|
this.keyHeightMap.clear();
|
|
3748
|
-
const remeasureIndics = this.inViewportIndics;
|
|
3749
|
-
measureHeightByIndics(this.editor, remeasureIndics, true);
|
|
3750
3737
|
EDITOR_TO_ROOT_NODE_WIDTH.set(this.editor, this.virtualTopHeightElement.getBoundingClientRect().width);
|
|
3738
|
+
this.viewportRefresh$.next();
|
|
3751
3739
|
if (isDebug) {
|
|
3752
3740
|
debugLog('log', 'editorResizeObserverRectWidth: ', editorResizeObserverRectWidth, 'EDITOR_TO_ROOT_NODE_WIDTH: ', EDITOR_TO_ROOT_NODE_WIDTH.get(this.editor));
|
|
3753
3741
|
}
|
|
3754
3742
|
}
|
|
3755
3743
|
});
|
|
3756
3744
|
this.editorResizeObserver.observe(this.elementRef.nativeElement);
|
|
3745
|
+
this.viewportRefresh$.pipe(debounceTime(1000)).subscribe(() => {
|
|
3746
|
+
// const res = measureHeightByIndics(this.editor, this.inViewportIndics);
|
|
3747
|
+
// if (isDebug) {
|
|
3748
|
+
// debugLog(
|
|
3749
|
+
// 'log',
|
|
3750
|
+
// 'viewportRefresh$ debounceTime 1000ms',
|
|
3751
|
+
// 'inViewportIndics: ',
|
|
3752
|
+
// this.inViewportIndics,
|
|
3753
|
+
// 'measureHeightByIndics height changed: ',
|
|
3754
|
+
// res
|
|
3755
|
+
// );
|
|
3756
|
+
// }
|
|
3757
|
+
});
|
|
3757
3758
|
}
|
|
3758
3759
|
}
|
|
3759
3760
|
setVirtualSpaceHeight(topHeight, bottomHeight) {
|
|
@@ -3852,6 +3853,7 @@ class SlateEditable {
|
|
|
3852
3853
|
if (!AngularEditor.isReadOnly(this.editor) && this.editor.selection) {
|
|
3853
3854
|
this.toNativeSelection(false);
|
|
3854
3855
|
}
|
|
3856
|
+
this.viewportRefresh$.next();
|
|
3855
3857
|
}
|
|
3856
3858
|
}
|
|
3857
3859
|
if (isDebug) {
|
|
@@ -3896,7 +3898,7 @@ class SlateEditable {
|
|
|
3896
3898
|
}, 100);
|
|
3897
3899
|
}
|
|
3898
3900
|
const adjustedScrollTop = Math.max(0, scrollTop - getBusinessTop(this.editor));
|
|
3899
|
-
const { heights, accumulatedHeights
|
|
3901
|
+
const { heights, accumulatedHeights } = buildHeightsAndAccumulatedHeights(this.editor);
|
|
3900
3902
|
const totalHeight = accumulatedHeights[elementLength];
|
|
3901
3903
|
const maxScrollTop = Math.max(0, totalHeight - viewportHeight);
|
|
3902
3904
|
const limitedScrollTop = Math.min(adjustedScrollTop, maxScrollTop);
|
|
@@ -3908,7 +3910,8 @@ class SlateEditable {
|
|
|
3908
3910
|
for (let i = 0; i < elementLength && accumulatedOffset < viewBottom; i++) {
|
|
3909
3911
|
const currentHeight = heights[i];
|
|
3910
3912
|
const nextOffset = accumulatedOffset + currentHeight;
|
|
3911
|
-
|
|
3913
|
+
const isVisible = this.editor.isVisible(children[i]);
|
|
3914
|
+
if (!isVisible) {
|
|
3912
3915
|
accumulatedOffset = nextOffset;
|
|
3913
3916
|
continue;
|
|
3914
3917
|
}
|
|
@@ -5023,7 +5026,6 @@ class BaseElementComponent extends BaseComponent {
|
|
|
5023
5026
|
}
|
|
5024
5027
|
return null;
|
|
5025
5028
|
};
|
|
5026
|
-
this.stableHeight = null;
|
|
5027
5029
|
}
|
|
5028
5030
|
get element() {
|
|
5029
5031
|
return this._context && this._context.element;
|
|
@@ -5106,20 +5108,11 @@ class BaseElementComponent extends BaseComponent {
|
|
|
5106
5108
|
readonly: this._context.readonly
|
|
5107
5109
|
};
|
|
5108
5110
|
}
|
|
5109
|
-
isStableHeight() {
|
|
5110
|
-
return false;
|
|
5111
|
-
}
|
|
5112
5111
|
getRealHeight() {
|
|
5113
|
-
if (this.isStableHeight() && this.stableHeight !== null) {
|
|
5114
|
-
return this.stableHeight;
|
|
5115
|
-
}
|
|
5116
5112
|
const blockCard = getBlockCardByNativeElement(this.nativeElement);
|
|
5117
5113
|
const target = blockCard || this.nativeElement;
|
|
5118
5114
|
const computedStyle = getComputedStyle(target);
|
|
5119
5115
|
const height = Math.ceil(target.getBoundingClientRect().height) + parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom);
|
|
5120
|
-
if (this.isStableHeight()) {
|
|
5121
|
-
this.stableHeight = height;
|
|
5122
|
-
}
|
|
5123
5116
|
return height;
|
|
5124
5117
|
}
|
|
5125
5118
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.12", ngImport: i0, type: BaseElementComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|