slate-angular 20.2.0-next.3 → 20.2.0-next.5
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 +35 -44
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +1 -2
- package/package.json +1 -1
|
@@ -2579,7 +2579,7 @@ class SlateEditable {
|
|
|
2579
2579
|
return;
|
|
2580
2580
|
}
|
|
2581
2581
|
if (diff.isMissingTop) {
|
|
2582
|
-
const result = this.remeasureHeightByIndics(
|
|
2582
|
+
const result = this.remeasureHeightByIndics(diff.diffTopRenderedIndexes);
|
|
2583
2583
|
if (result) {
|
|
2584
2584
|
virtualView = this.refreshVirtualView();
|
|
2585
2585
|
diff = this.diffVirtualView(virtualView, 'second');
|
|
@@ -2646,7 +2646,8 @@ class SlateEditable {
|
|
|
2646
2646
|
this.renderedChildren = [];
|
|
2647
2647
|
this.virtualVisibleIndexes = new Set();
|
|
2648
2648
|
this.measuredHeights = new Map();
|
|
2649
|
-
|
|
2649
|
+
// the height from scroll container top to editor top height element
|
|
2650
|
+
this.businessHeight = 0;
|
|
2650
2651
|
this.virtualScrollInitialized = false;
|
|
2651
2652
|
}
|
|
2652
2653
|
ngOnInit() {
|
|
@@ -2959,7 +2960,7 @@ class SlateEditable {
|
|
|
2959
2960
|
this.elementRef.nativeElement.appendChild(this.virtualTopHeightElement);
|
|
2960
2961
|
this.elementRef.nativeElement.appendChild(this.virtualCenterOutlet);
|
|
2961
2962
|
this.elementRef.nativeElement.appendChild(this.virtualBottomHeightElement);
|
|
2962
|
-
|
|
2963
|
+
this.businessHeight = this.virtualTopHeightElement.getBoundingClientRect()?.top ?? 0;
|
|
2963
2964
|
}
|
|
2964
2965
|
}
|
|
2965
2966
|
changeVirtualHeight(topHeight, bottomHeight) {
|
|
@@ -2980,10 +2981,9 @@ class SlateEditable {
|
|
|
2980
2981
|
heights: []
|
|
2981
2982
|
};
|
|
2982
2983
|
}
|
|
2983
|
-
const scrollTop = this.virtualConfig.scrollTop
|
|
2984
|
+
const scrollTop = this.virtualConfig.scrollTop;
|
|
2984
2985
|
const viewportHeight = this.virtualConfig.viewportHeight ?? 0;
|
|
2985
2986
|
if (!viewportHeight) {
|
|
2986
|
-
// 已经启用虚拟滚动,但可视区域高度还未获取到,先置空不渲染
|
|
2987
2987
|
return {
|
|
2988
2988
|
renderedChildren: [],
|
|
2989
2989
|
visibleIndexes: new Set(),
|
|
@@ -2992,36 +2992,41 @@ class SlateEditable {
|
|
|
2992
2992
|
heights: []
|
|
2993
2993
|
};
|
|
2994
2994
|
}
|
|
2995
|
-
const
|
|
2995
|
+
const elementLength = children.length;
|
|
2996
|
+
const adjustedScrollTop = Math.max(0, scrollTop - this.businessHeight);
|
|
2996
2997
|
const heights = children.map((_, idx) => this.getBlockHeight(idx));
|
|
2997
2998
|
const accumulatedHeights = this.buildAccumulatedHeight(heights);
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
const startIndex = Math.max(0, visibleStart - bufferCount);
|
|
3005
|
-
const top = accumulatedHeights[startIndex];
|
|
3006
|
-
const bufferBelowHeight = this.getBufferBelowHeight(viewportHeight, visibleStart, bufferCount);
|
|
3007
|
-
const targetHeight = accumulatedHeights[visibleStart] - top + viewportHeight + bufferBelowHeight;
|
|
2999
|
+
const totalHeight = accumulatedHeights[elementLength];
|
|
3000
|
+
const maxScrollTop = Math.max(0, totalHeight - viewportHeight);
|
|
3001
|
+
const limitedScrollTop = Math.min(adjustedScrollTop, maxScrollTop);
|
|
3002
|
+
const viewBottom = limitedScrollTop + viewportHeight + this.businessHeight;
|
|
3003
|
+
let accumulatedOffset = 0;
|
|
3004
|
+
let visibleStartIndex = -1;
|
|
3008
3005
|
const visible = [];
|
|
3009
3006
|
const visibleIndexes = [];
|
|
3010
|
-
let
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3007
|
+
for (let i = 0; i < elementLength && accumulatedOffset < viewBottom; i++) {
|
|
3008
|
+
const currentHeight = heights[i];
|
|
3009
|
+
const nextOffset = accumulatedOffset + currentHeight;
|
|
3010
|
+
// 可视区域有交集,加入渲染
|
|
3011
|
+
if (nextOffset > limitedScrollTop && accumulatedOffset < viewBottom) {
|
|
3012
|
+
if (visibleStartIndex === -1)
|
|
3013
|
+
visibleStartIndex = i; // 第一个相交起始位置
|
|
3014
|
+
visible.push(children[i]);
|
|
3015
|
+
visibleIndexes.push(i);
|
|
3016
|
+
}
|
|
3017
|
+
accumulatedOffset = nextOffset;
|
|
3018
|
+
}
|
|
3019
|
+
if (visibleStartIndex === -1 && elementLength) {
|
|
3020
|
+
visibleStartIndex = elementLength - 1;
|
|
3021
|
+
visible.push(children[visibleStartIndex]);
|
|
3022
|
+
visibleIndexes.push(visibleStartIndex);
|
|
3023
|
+
}
|
|
3024
|
+
const visibleEndIndex = visibleStartIndex === -1 ? elementLength - 1 : (visibleIndexes[visibleIndexes.length - 1] ?? visibleStartIndex);
|
|
3025
|
+
const top = visibleStartIndex === -1 ? 0 : accumulatedHeights[visibleStartIndex];
|
|
3026
|
+
const bottom = totalHeight - accumulatedHeights[visibleEndIndex + 1];
|
|
3022
3027
|
return {
|
|
3023
|
-
renderedChildren,
|
|
3024
|
-
visibleIndexes:
|
|
3028
|
+
renderedChildren: visible.length ? visible : children,
|
|
3029
|
+
visibleIndexes: new Set(visibleIndexes),
|
|
3025
3030
|
top,
|
|
3026
3031
|
bottom,
|
|
3027
3032
|
heights
|
|
@@ -3141,20 +3146,6 @@ class SlateEditable {
|
|
|
3141
3146
|
}
|
|
3142
3147
|
return accumulatedHeights;
|
|
3143
3148
|
}
|
|
3144
|
-
getBufferBelowHeight(viewportHeight, visibleStart, bufferCount) {
|
|
3145
|
-
let blockHeight = 0;
|
|
3146
|
-
let start = visibleStart;
|
|
3147
|
-
// 循环累计高度超出视图高度代表找到向下缓冲区的起始位置
|
|
3148
|
-
while (blockHeight < viewportHeight) {
|
|
3149
|
-
blockHeight += this.getBlockHeight(start);
|
|
3150
|
-
start++;
|
|
3151
|
-
}
|
|
3152
|
-
let bufferHeight = 0;
|
|
3153
|
-
for (let i = start; i < start + bufferCount; i++) {
|
|
3154
|
-
bufferHeight += this.getBlockHeight(i);
|
|
3155
|
-
}
|
|
3156
|
-
return bufferHeight;
|
|
3157
|
-
}
|
|
3158
3149
|
scheduleMeasureVisibleHeights() {
|
|
3159
3150
|
if (!this.shouldUseVirtual()) {
|
|
3160
3151
|
return;
|