slate-angular 20.2.0-next.2 → 20.2.0-next.3
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 +75 -51
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +7 -3
- package/package.json +1 -1
|
@@ -1739,6 +1739,7 @@ class BaseElementFlavour extends BaseFlavour {
|
|
|
1739
1739
|
this.getOutletElement = () => {
|
|
1740
1740
|
return this.nativeElement.querySelector('.children-outlet');
|
|
1741
1741
|
};
|
|
1742
|
+
this.stableHeight = null;
|
|
1742
1743
|
}
|
|
1743
1744
|
get element() {
|
|
1744
1745
|
return this._context && this._context.element;
|
|
@@ -1824,11 +1825,21 @@ class BaseElementFlavour extends BaseFlavour {
|
|
|
1824
1825
|
readonly: this._context.readonly
|
|
1825
1826
|
};
|
|
1826
1827
|
}
|
|
1828
|
+
isStableHeight() {
|
|
1829
|
+
return false;
|
|
1830
|
+
}
|
|
1827
1831
|
getRealHeight() {
|
|
1832
|
+
if (this.isStableHeight() && this.stableHeight !== null) {
|
|
1833
|
+
return this.stableHeight;
|
|
1834
|
+
}
|
|
1828
1835
|
const blockCard = getBlockCardByNativeElement(this.nativeElement);
|
|
1829
1836
|
const target = blockCard || this.nativeElement;
|
|
1830
1837
|
const computedStyle = getComputedStyle(target);
|
|
1831
|
-
|
|
1838
|
+
const height = target.offsetHeight + parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom);
|
|
1839
|
+
if (this.isStableHeight()) {
|
|
1840
|
+
this.stableHeight = height;
|
|
1841
|
+
}
|
|
1842
|
+
return height;
|
|
1832
1843
|
}
|
|
1833
1844
|
}
|
|
1834
1845
|
|
|
@@ -2562,29 +2573,26 @@ class SlateEditable {
|
|
|
2562
2573
|
this.virtualConfig = config;
|
|
2563
2574
|
this.refreshVirtualViewAnimId && cancelAnimationFrame(this.refreshVirtualViewAnimId);
|
|
2564
2575
|
this.refreshVirtualViewAnimId = requestAnimationFrame(() => {
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
if (diff.isDiff) {
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
this.scheduleMeasureVisibleHeights();
|
|
2578
|
-
});
|
|
2579
|
-
}
|
|
2580
|
-
else {
|
|
2581
|
-
this.applyVirtualView(virtualView);
|
|
2582
|
-
if (this.listRender.initialized) {
|
|
2583
|
-
this.listRender.update(virtualView.renderedChildren, this.editor, this.context);
|
|
2576
|
+
let virtualView = this.refreshVirtualView();
|
|
2577
|
+
let diff = this.diffVirtualView(virtualView);
|
|
2578
|
+
if (!diff.isDiff) {
|
|
2579
|
+
return;
|
|
2580
|
+
}
|
|
2581
|
+
if (diff.isMissingTop) {
|
|
2582
|
+
const result = this.remeasureHeightByIndics([...diff.diffTopRenderedIndexes]);
|
|
2583
|
+
if (result) {
|
|
2584
|
+
virtualView = this.refreshVirtualView();
|
|
2585
|
+
diff = this.diffVirtualView(virtualView, 'second');
|
|
2586
|
+
if (!diff.isDiff) {
|
|
2587
|
+
return;
|
|
2584
2588
|
}
|
|
2585
|
-
this.scheduleMeasureVisibleHeights();
|
|
2586
2589
|
}
|
|
2587
2590
|
}
|
|
2591
|
+
this.applyVirtualView(virtualView);
|
|
2592
|
+
if (this.listRender.initialized) {
|
|
2593
|
+
this.listRender.update(virtualView.renderedChildren, this.editor, this.context);
|
|
2594
|
+
}
|
|
2595
|
+
this.scheduleMeasureVisibleHeights();
|
|
2588
2596
|
});
|
|
2589
2597
|
}
|
|
2590
2598
|
get hasBeforeInputSupport() {
|
|
@@ -2951,6 +2959,7 @@ class SlateEditable {
|
|
|
2951
2959
|
this.elementRef.nativeElement.appendChild(this.virtualTopHeightElement);
|
|
2952
2960
|
this.elementRef.nativeElement.appendChild(this.virtualCenterOutlet);
|
|
2953
2961
|
this.elementRef.nativeElement.appendChild(this.virtualBottomHeightElement);
|
|
2962
|
+
// businessHeight
|
|
2954
2963
|
}
|
|
2955
2964
|
}
|
|
2956
2965
|
changeVirtualHeight(topHeight, bottomHeight) {
|
|
@@ -3023,7 +3032,7 @@ class SlateEditable {
|
|
|
3023
3032
|
this.changeVirtualHeight(virtualView.top, virtualView.bottom);
|
|
3024
3033
|
this.virtualVisibleIndexes = virtualView.visibleIndexes;
|
|
3025
3034
|
}
|
|
3026
|
-
diffVirtualView(virtualView) {
|
|
3035
|
+
diffVirtualView(virtualView, stage = 'first') {
|
|
3027
3036
|
if (!this.renderedChildren.length) {
|
|
3028
3037
|
return {
|
|
3029
3038
|
isDiff: true,
|
|
@@ -3087,6 +3096,7 @@ class SlateEditable {
|
|
|
3087
3096
|
}
|
|
3088
3097
|
}
|
|
3089
3098
|
if (isDebug) {
|
|
3099
|
+
console.log(`====== diffVirtualView stage: ${stage} ======`);
|
|
3090
3100
|
console.log('oldVisibleIndexes:', oldVisibleIndexes);
|
|
3091
3101
|
console.log('newVisibleIndexes:', newVisibleIndexes);
|
|
3092
3102
|
console.log('diffTopRenderedIndexes:', isMissingTop ? '-' : isAddedTop ? '+' : '-', diffTopRenderedIndexes, diffTopRenderedIndexes.map(index => this.getBlockHeight(index, 0)));
|
|
@@ -3149,14 +3159,9 @@ class SlateEditable {
|
|
|
3149
3159
|
if (!this.shouldUseVirtual()) {
|
|
3150
3160
|
return;
|
|
3151
3161
|
}
|
|
3152
|
-
if (this.measurePending) {
|
|
3153
|
-
return;
|
|
3154
|
-
}
|
|
3155
|
-
this.measurePending = true;
|
|
3156
3162
|
this.measureVisibleHeightsAnimId && cancelAnimationFrame(this.measureVisibleHeightsAnimId);
|
|
3157
3163
|
this.measureVisibleHeightsAnimId = requestAnimationFrame(() => {
|
|
3158
3164
|
this.measureVisibleHeights();
|
|
3159
|
-
this.measurePending = false;
|
|
3160
3165
|
});
|
|
3161
3166
|
}
|
|
3162
3167
|
measureVisibleHeights() {
|
|
@@ -3175,16 +3180,21 @@ class SlateEditable {
|
|
|
3175
3180
|
if (!view) {
|
|
3176
3181
|
return;
|
|
3177
3182
|
}
|
|
3178
|
-
view.getRealHeight()
|
|
3179
|
-
|
|
3180
|
-
|
|
3183
|
+
const ret = view.getRealHeight();
|
|
3184
|
+
if (ret instanceof Promise) {
|
|
3185
|
+
ret.then(height => {
|
|
3186
|
+
this.measuredHeights.set(key.id, height);
|
|
3187
|
+
});
|
|
3188
|
+
}
|
|
3189
|
+
else {
|
|
3190
|
+
this.measuredHeights.set(key.id, ret);
|
|
3191
|
+
}
|
|
3181
3192
|
});
|
|
3182
3193
|
}
|
|
3183
|
-
|
|
3194
|
+
remeasureHeightByIndics(indics) {
|
|
3184
3195
|
const children = (this.editor.children || []);
|
|
3185
3196
|
let isHeightChanged = false;
|
|
3186
|
-
|
|
3187
|
-
indexes.forEach(index => {
|
|
3197
|
+
indics.forEach(index => {
|
|
3188
3198
|
const node = children[index];
|
|
3189
3199
|
if (!node) {
|
|
3190
3200
|
return;
|
|
@@ -3194,27 +3204,30 @@ class SlateEditable {
|
|
|
3194
3204
|
if (!view) {
|
|
3195
3205
|
return;
|
|
3196
3206
|
}
|
|
3197
|
-
const
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3207
|
+
const prevHeight = this.measuredHeights.get(key.id);
|
|
3208
|
+
const ret = view.getRealHeight();
|
|
3209
|
+
if (ret instanceof Promise) {
|
|
3210
|
+
ret.then(height => {
|
|
3211
|
+
if (height !== prevHeight) {
|
|
3212
|
+
this.measuredHeights.set(key.id, height);
|
|
3213
|
+
isHeightChanged = true;
|
|
3214
|
+
if (isDebug) {
|
|
3215
|
+
console.log(`remeasureHeightByIndics, index: ${index} prevHeight: ${prevHeight} newHeight: ${height}`);
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
});
|
|
3219
|
+
}
|
|
3220
|
+
else {
|
|
3221
|
+
if (ret !== prevHeight) {
|
|
3222
|
+
this.measuredHeights.set(key.id, ret);
|
|
3204
3223
|
isHeightChanged = true;
|
|
3224
|
+
if (isDebug) {
|
|
3225
|
+
console.log(`remeasureHeightByIndics, index: ${index} prevHeight: ${prevHeight} newHeight: ${ret}`);
|
|
3226
|
+
}
|
|
3205
3227
|
}
|
|
3206
|
-
});
|
|
3207
|
-
if (promise) {
|
|
3208
|
-
promises.push(promise);
|
|
3209
3228
|
}
|
|
3210
3229
|
});
|
|
3211
|
-
|
|
3212
|
-
await Promise.all(promises);
|
|
3213
|
-
if (isHeightChanged && isRefresh) {
|
|
3214
|
-
return this.refreshVirtualView();
|
|
3215
|
-
}
|
|
3216
|
-
}
|
|
3217
|
-
return null;
|
|
3230
|
+
return isHeightChanged;
|
|
3218
3231
|
}
|
|
3219
3232
|
//#region event proxy
|
|
3220
3233
|
addEventListener(eventName, listener, target = this.elementRef.nativeElement) {
|
|
@@ -4166,6 +4179,7 @@ class BaseElementComponent extends BaseComponent {
|
|
|
4166
4179
|
}
|
|
4167
4180
|
return null;
|
|
4168
4181
|
};
|
|
4182
|
+
this.stableHeight = null;
|
|
4169
4183
|
}
|
|
4170
4184
|
get element() {
|
|
4171
4185
|
return this._context && this._context.element;
|
|
@@ -4247,11 +4261,21 @@ class BaseElementComponent extends BaseComponent {
|
|
|
4247
4261
|
readonly: this._context.readonly
|
|
4248
4262
|
};
|
|
4249
4263
|
}
|
|
4264
|
+
isStableHeight() {
|
|
4265
|
+
return false;
|
|
4266
|
+
}
|
|
4250
4267
|
getRealHeight() {
|
|
4268
|
+
if (this.isStableHeight() && this.stableHeight !== null) {
|
|
4269
|
+
return this.stableHeight;
|
|
4270
|
+
}
|
|
4251
4271
|
const blockCard = getBlockCardByNativeElement(this.nativeElement);
|
|
4252
4272
|
const target = blockCard || this.nativeElement;
|
|
4253
4273
|
const computedStyle = getComputedStyle(target);
|
|
4254
|
-
|
|
4274
|
+
const height = target.offsetHeight + parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom);
|
|
4275
|
+
if (this.isStableHeight()) {
|
|
4276
|
+
this.stableHeight = height;
|
|
4277
|
+
}
|
|
4278
|
+
return height;
|
|
4255
4279
|
}
|
|
4256
4280
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.12", ngImport: i0, type: BaseElementComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
4257
4281
|
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.12", type: BaseElementComponent, isStandalone: true, viewQueries: [{ propertyName: "childrenOutletInstance", first: true, predicate: SlateChildrenOutlet, descendants: true, static: true }], usesInheritance: true, ngImport: i0 }); }
|