slate-angular 20.2.0-next.4 → 20.2.0-next.6
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 +48 -26
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +1 -2
- package/package.json +1 -1
|
@@ -1135,6 +1135,9 @@ const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
|
|
|
1135
1135
|
NODE_TO_KEY.set(node, key);
|
|
1136
1136
|
}
|
|
1137
1137
|
};
|
|
1138
|
+
e.selectAll = () => {
|
|
1139
|
+
Transforms.select(e, []);
|
|
1140
|
+
};
|
|
1138
1141
|
return e;
|
|
1139
1142
|
};
|
|
1140
1143
|
|
|
@@ -1835,7 +1838,7 @@ class BaseElementFlavour extends BaseFlavour {
|
|
|
1835
1838
|
const blockCard = getBlockCardByNativeElement(this.nativeElement);
|
|
1836
1839
|
const target = blockCard || this.nativeElement;
|
|
1837
1840
|
const computedStyle = getComputedStyle(target);
|
|
1838
|
-
const height = target.
|
|
1841
|
+
const height = Math.ceil(target.getBoundingClientRect().height) + parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom);
|
|
1839
1842
|
if (this.isStableHeight()) {
|
|
1840
1843
|
this.stableHeight = height;
|
|
1841
1844
|
}
|
|
@@ -2579,7 +2582,7 @@ class SlateEditable {
|
|
|
2579
2582
|
return;
|
|
2580
2583
|
}
|
|
2581
2584
|
if (diff.isMissingTop) {
|
|
2582
|
-
const result = this.remeasureHeightByIndics(
|
|
2585
|
+
const result = this.remeasureHeightByIndics(diff.diffTopRenderedIndexes);
|
|
2583
2586
|
if (result) {
|
|
2584
2587
|
virtualView = this.refreshVirtualView();
|
|
2585
2588
|
diff = this.diffVirtualView(virtualView, 'second');
|
|
@@ -2591,6 +2594,9 @@ class SlateEditable {
|
|
|
2591
2594
|
this.applyVirtualView(virtualView);
|
|
2592
2595
|
if (this.listRender.initialized) {
|
|
2593
2596
|
this.listRender.update(virtualView.renderedChildren, this.editor, this.context);
|
|
2597
|
+
if (!AngularEditor.isReadOnly(this.editor) && this.editor.selection) {
|
|
2598
|
+
this.toNativeSelection();
|
|
2599
|
+
}
|
|
2594
2600
|
}
|
|
2595
2601
|
this.scheduleMeasureVisibleHeights();
|
|
2596
2602
|
});
|
|
@@ -2646,7 +2652,6 @@ class SlateEditable {
|
|
|
2646
2652
|
this.renderedChildren = [];
|
|
2647
2653
|
this.virtualVisibleIndexes = new Set();
|
|
2648
2654
|
this.measuredHeights = new Map();
|
|
2649
|
-
this.measurePending = false;
|
|
2650
2655
|
// the height from scroll container top to editor top height element
|
|
2651
2656
|
this.businessHeight = 0;
|
|
2652
2657
|
this.virtualScrollInitialized = false;
|
|
@@ -2747,7 +2752,23 @@ class SlateEditable {
|
|
|
2747
2752
|
}
|
|
2748
2753
|
toNativeSelection() {
|
|
2749
2754
|
try {
|
|
2750
|
-
|
|
2755
|
+
let { selection: currentSelection } = this.editor;
|
|
2756
|
+
let selection = currentSelection;
|
|
2757
|
+
if (this.virtualConfig?.enabled) {
|
|
2758
|
+
const indics = Array.from(this.virtualVisibleIndexes.values());
|
|
2759
|
+
if (indics.length > 0) {
|
|
2760
|
+
const currentVisibleRange = {
|
|
2761
|
+
anchor: Editor.start(this.editor, [indics[0]]),
|
|
2762
|
+
focus: Editor.end(this.editor, [indics[indics.length - 1]])
|
|
2763
|
+
};
|
|
2764
|
+
selection = Range.intersection(selection, currentVisibleRange);
|
|
2765
|
+
if ((!selection && currentSelection) || (selection && !Range.equals(selection, currentSelection))) {
|
|
2766
|
+
if (isDebug) {
|
|
2767
|
+
console.log(`selection is not in visible range, selection: ${JSON.stringify(currentSelection)}, intersection selection: ${JSON.stringify(selection)}`);
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2751
2772
|
const root = AngularEditor.findDocumentOrShadowRoot(this.editor);
|
|
2752
2773
|
const { activeElement } = root;
|
|
2753
2774
|
const domSelection = root.getSelection();
|
|
@@ -2954,8 +2975,10 @@ class SlateEditable {
|
|
|
2954
2975
|
this.virtualScrollInitialized = true;
|
|
2955
2976
|
this.virtualTopHeightElement = document.createElement('div');
|
|
2956
2977
|
this.virtualTopHeightElement.classList.add('virtual-top-height');
|
|
2978
|
+
this.virtualTopHeightElement.contentEditable = 'false';
|
|
2957
2979
|
this.virtualBottomHeightElement = document.createElement('div');
|
|
2958
2980
|
this.virtualBottomHeightElement.classList.add('virtual-bottom-height');
|
|
2981
|
+
this.virtualBottomHeightElement.contentEditable = 'false';
|
|
2959
2982
|
this.virtualCenterOutlet = document.createElement('div');
|
|
2960
2983
|
this.virtualCenterOutlet.classList.add('virtual-center-outlet');
|
|
2961
2984
|
this.elementRef.nativeElement.appendChild(this.virtualTopHeightElement);
|
|
@@ -2995,16 +3018,21 @@ class SlateEditable {
|
|
|
2995
3018
|
}
|
|
2996
3019
|
const elementLength = children.length;
|
|
2997
3020
|
const adjustedScrollTop = Math.max(0, scrollTop - this.businessHeight);
|
|
2998
|
-
const
|
|
3021
|
+
const heights = children.map((_, idx) => this.getBlockHeight(idx));
|
|
3022
|
+
const accumulatedHeights = this.buildAccumulatedHeight(heights);
|
|
3023
|
+
const totalHeight = accumulatedHeights[elementLength];
|
|
3024
|
+
const maxScrollTop = Math.max(0, totalHeight - viewportHeight);
|
|
3025
|
+
const limitedScrollTop = Math.min(adjustedScrollTop, maxScrollTop);
|
|
3026
|
+
const viewBottom = limitedScrollTop + viewportHeight + this.businessHeight;
|
|
2999
3027
|
let accumulatedOffset = 0;
|
|
3000
3028
|
let visibleStartIndex = -1;
|
|
3001
3029
|
const visible = [];
|
|
3002
3030
|
const visibleIndexes = [];
|
|
3003
3031
|
for (let i = 0; i < elementLength && accumulatedOffset < viewBottom; i++) {
|
|
3004
|
-
const currentHeight =
|
|
3032
|
+
const currentHeight = heights[i];
|
|
3005
3033
|
const nextOffset = accumulatedOffset + currentHeight;
|
|
3006
3034
|
// 可视区域有交集,加入渲染
|
|
3007
|
-
if (nextOffset >
|
|
3035
|
+
if (nextOffset > limitedScrollTop && accumulatedOffset < viewBottom) {
|
|
3008
3036
|
if (visibleStartIndex === -1)
|
|
3009
3037
|
visibleStartIndex = i; // 第一个相交起始位置
|
|
3010
3038
|
visible.push(children[i]);
|
|
@@ -3012,11 +3040,14 @@ class SlateEditable {
|
|
|
3012
3040
|
}
|
|
3013
3041
|
accumulatedOffset = nextOffset;
|
|
3014
3042
|
}
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3043
|
+
if (visibleStartIndex === -1 && elementLength) {
|
|
3044
|
+
visibleStartIndex = elementLength - 1;
|
|
3045
|
+
visible.push(children[visibleStartIndex]);
|
|
3046
|
+
visibleIndexes.push(visibleStartIndex);
|
|
3047
|
+
}
|
|
3048
|
+
const visibleEndIndex = visibleStartIndex === -1 ? elementLength - 1 : (visibleIndexes[visibleIndexes.length - 1] ?? visibleStartIndex);
|
|
3018
3049
|
const top = visibleStartIndex === -1 ? 0 : accumulatedHeights[visibleStartIndex];
|
|
3019
|
-
const bottom =
|
|
3050
|
+
const bottom = totalHeight - accumulatedHeights[visibleEndIndex + 1];
|
|
3020
3051
|
return {
|
|
3021
3052
|
renderedChildren: visible.length ? visible : children,
|
|
3022
3053
|
visibleIndexes: new Set(visibleIndexes),
|
|
@@ -3139,20 +3170,6 @@ class SlateEditable {
|
|
|
3139
3170
|
}
|
|
3140
3171
|
return accumulatedHeights;
|
|
3141
3172
|
}
|
|
3142
|
-
getBufferBelowHeight(viewportHeight, visibleStart, bufferCount) {
|
|
3143
|
-
let blockHeight = 0;
|
|
3144
|
-
let start = visibleStart;
|
|
3145
|
-
// 循环累计高度超出视图高度代表找到向下缓冲区的起始位置
|
|
3146
|
-
while (blockHeight < viewportHeight) {
|
|
3147
|
-
blockHeight += this.getBlockHeight(start);
|
|
3148
|
-
start++;
|
|
3149
|
-
}
|
|
3150
|
-
let bufferHeight = 0;
|
|
3151
|
-
for (let i = start; i < start + bufferCount; i++) {
|
|
3152
|
-
bufferHeight += this.getBlockHeight(i);
|
|
3153
|
-
}
|
|
3154
|
-
return bufferHeight;
|
|
3155
|
-
}
|
|
3156
3173
|
scheduleMeasureVisibleHeights() {
|
|
3157
3174
|
if (!this.shouldUseVirtual()) {
|
|
3158
3175
|
return;
|
|
@@ -3751,6 +3768,11 @@ class SlateEditable {
|
|
|
3751
3768
|
Transforms.move(editor, { unit: 'word', reverse: isRTL });
|
|
3752
3769
|
return;
|
|
3753
3770
|
}
|
|
3771
|
+
if (isKeyHotkey('mod+a', event)) {
|
|
3772
|
+
this.editor.selectAll();
|
|
3773
|
+
event.preventDefault();
|
|
3774
|
+
return;
|
|
3775
|
+
}
|
|
3754
3776
|
// COMPAT: Certain browsers don't support the `beforeinput` event, so we
|
|
3755
3777
|
// fall back to guessing at the input intention for hotkeys.
|
|
3756
3778
|
// COMPAT: In iOS, some of these hotkeys are handled in the
|
|
@@ -4269,7 +4291,7 @@ class BaseElementComponent extends BaseComponent {
|
|
|
4269
4291
|
const blockCard = getBlockCardByNativeElement(this.nativeElement);
|
|
4270
4292
|
const target = blockCard || this.nativeElement;
|
|
4271
4293
|
const computedStyle = getComputedStyle(target);
|
|
4272
|
-
const height = target.
|
|
4294
|
+
const height = Math.ceil(target.getBoundingClientRect().height) + parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom);
|
|
4273
4295
|
if (this.isStableHeight()) {
|
|
4274
4296
|
this.stableHeight = height;
|
|
4275
4297
|
}
|