@tmagic/stage 1.8.0-beta.21 → 1.8.0-beta.22

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.
@@ -81,17 +81,20 @@ var StageMask = class extends Rule {
81
81
  this.page = page;
82
82
  this.initObserverIntersection();
83
83
  this.initObserverWrapper();
84
+ this.syncPageSize();
84
85
  }
85
86
  /**
86
- * 处理页面大小变更,同步页面和mask大小
87
+ * 处理页面大小变更,同步页面和 mask 大小
88
+ * @description 仅处理当前 page 且仍挂载在文档中的 entry;非当前页、已卸载或宽高为 0 的回调会被忽略
87
89
  * @param entries ResizeObserverEntry,获取页面最新大小
88
90
  */
89
91
  pageResize(entries) {
90
- const [entry] = entries;
91
- const { clientHeight, clientWidth } = entry.target;
92
- this.setHeight(clientHeight);
93
- this.setWidth(clientWidth);
94
- this.scroll();
92
+ if (!this.page || !entries.length) return;
93
+ const entry = entries.find((item) => item.target === this.page);
94
+ if (!entry) return;
95
+ const { target } = entry;
96
+ if (!target.isConnected) return;
97
+ this.applyPageSize(target.clientWidth, target.clientHeight);
95
98
  }
96
99
  /**
97
100
  * 监听一个组件是否在画布可视区域内
@@ -132,6 +135,7 @@ var StageMask = class extends Rule {
132
135
  this.content?.remove();
133
136
  this.page = null;
134
137
  this.pageScrollParent = null;
138
+ this.intersectionObserver?.disconnect();
135
139
  this.wrapperResizeObserver?.disconnect();
136
140
  }
137
141
  on(eventName, listener) {
@@ -202,6 +206,22 @@ var StageMask = class extends Rule {
202
206
  this.content.dispatchEvent(event);
203
207
  }
204
208
  /**
209
+ * 从当前页面同步蒙层宽高,并修正滚动偏移
210
+ */
211
+ syncPageSize() {
212
+ if (!this.page?.isConnected) return;
213
+ this.applyPageSize(this.page.clientWidth, this.page.clientHeight);
214
+ }
215
+ /**
216
+ * 应用页面尺寸到蒙层;宽高为 0 时忽略,避免切换/布局过程中把 editor-mask 置空
217
+ */
218
+ applyPageSize(clientWidth, clientHeight) {
219
+ if (clientWidth <= 0 || clientHeight <= 0) return;
220
+ this.setHeight(clientHeight);
221
+ this.setWidth(clientWidth);
222
+ this.scroll();
223
+ }
224
+ /**
205
225
  * 设置蒙层高度
206
226
  * @param height 高度
207
227
  */
@@ -4373,17 +4373,20 @@
4373
4373
  this.page = page;
4374
4374
  this.initObserverIntersection();
4375
4375
  this.initObserverWrapper();
4376
+ this.syncPageSize();
4376
4377
  }
4377
4378
  /**
4378
- * 处理页面大小变更,同步页面和mask大小
4379
+ * 处理页面大小变更,同步页面和 mask 大小
4380
+ * @description 仅处理当前 page 且仍挂载在文档中的 entry;非当前页、已卸载或宽高为 0 的回调会被忽略
4379
4381
  * @param entries ResizeObserverEntry,获取页面最新大小
4380
4382
  */
4381
4383
  pageResize(entries) {
4382
- const [entry] = entries;
4383
- const { clientHeight, clientWidth } = entry.target;
4384
- this.setHeight(clientHeight);
4385
- this.setWidth(clientWidth);
4386
- this.scroll();
4384
+ if (!this.page || !entries.length) return;
4385
+ const entry = entries.find((item) => item.target === this.page);
4386
+ if (!entry) return;
4387
+ const { target } = entry;
4388
+ if (!target.isConnected) return;
4389
+ this.applyPageSize(target.clientWidth, target.clientHeight);
4387
4390
  }
4388
4391
  /**
4389
4392
  * 监听一个组件是否在画布可视区域内
@@ -4424,6 +4427,7 @@
4424
4427
  this.content?.remove();
4425
4428
  this.page = null;
4426
4429
  this.pageScrollParent = null;
4430
+ this.intersectionObserver?.disconnect();
4427
4431
  this.wrapperResizeObserver?.disconnect();
4428
4432
  }
4429
4433
  on(eventName, listener) {
@@ -4494,6 +4498,22 @@
4494
4498
  this.content.dispatchEvent(event);
4495
4499
  }
4496
4500
  /**
4501
+ * 从当前页面同步蒙层宽高,并修正滚动偏移
4502
+ */
4503
+ syncPageSize() {
4504
+ if (!this.page?.isConnected) return;
4505
+ this.applyPageSize(this.page.clientWidth, this.page.clientHeight);
4506
+ }
4507
+ /**
4508
+ * 应用页面尺寸到蒙层;宽高为 0 时忽略,避免切换/布局过程中把 editor-mask 置空
4509
+ */
4510
+ applyPageSize(clientWidth, clientHeight) {
4511
+ if (clientWidth <= 0 || clientHeight <= 0) return;
4512
+ this.setHeight(clientHeight);
4513
+ this.setWidth(clientWidth);
4514
+ this.scroll();
4515
+ }
4516
+ /**
4497
4517
  * 设置蒙层高度
4498
4518
  * @param height 高度
4499
4519
  */
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.8.0-beta.21",
2
+ "version": "1.8.0-beta.22",
3
3
  "name": "@tmagic/stage",
4
4
  "type": "module",
5
5
  "sideEffects": false,
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "peerDependencies": {
46
46
  "typescript": "^6.0.3",
47
- "@tmagic/core": "1.8.0-beta.21"
47
+ "@tmagic/core": "1.8.0-beta.22"
48
48
  },
49
49
  "peerDependenciesMeta": {
50
50
  "typescript": {
package/src/StageMask.ts CHANGED
@@ -117,19 +117,27 @@ export default class StageMask extends Rule {
117
117
  this.page = page;
118
118
  this.initObserverIntersection();
119
119
  this.initObserverWrapper();
120
+ // 页面切换后立即同步一次;ResizeObserver 首次回调可能仍上报旧页/0 尺寸
121
+ this.syncPageSize();
120
122
  }
121
123
 
122
124
  /**
123
- * 处理页面大小变更,同步页面和mask大小
125
+ * 处理页面大小变更,同步页面和 mask 大小
126
+ * @description 仅处理当前 page 且仍挂载在文档中的 entry;非当前页、已卸载或宽高为 0 的回调会被忽略
124
127
  * @param entries ResizeObserverEntry,获取页面最新大小
125
128
  */
126
129
  public pageResize(entries: ResizeObserverEntry[]): void {
127
- const [entry] = entries;
128
- const { clientHeight, clientWidth } = entry.target;
129
- this.setHeight(clientHeight);
130
- this.setWidth(clientWidth);
130
+ if (!this.page || !entries.length) return;
131
131
 
132
- this.scroll();
132
+ // 取当前 page 对应 entry,避免 batch 中首项是旧页时整批被丢弃
133
+ const entry = entries.find((item) => item.target === this.page);
134
+ if (!entry) return;
135
+
136
+ const { target } = entry;
137
+ // 旧页卸载后仍可能回调,已断开连接的节点不再同步尺寸
138
+ if (!target.isConnected) return;
139
+
140
+ this.applyPageSize(target.clientWidth, target.clientHeight);
133
141
  }
134
142
 
135
143
  /**
@@ -186,6 +194,7 @@ export default class StageMask extends Rule {
186
194
  this.content?.remove();
187
195
  this.page = null;
188
196
  this.pageScrollParent = null;
197
+ this.intersectionObserver?.disconnect();
189
198
  this.wrapperResizeObserver?.disconnect();
190
199
  }
191
200
 
@@ -287,6 +296,26 @@ export default class StageMask extends Rule {
287
296
  this.content.dispatchEvent(event);
288
297
  }
289
298
 
299
+ /**
300
+ * 从当前页面同步蒙层宽高,并修正滚动偏移
301
+ */
302
+ private syncPageSize(): void {
303
+ if (!this.page?.isConnected) return;
304
+
305
+ this.applyPageSize(this.page.clientWidth, this.page.clientHeight);
306
+ }
307
+
308
+ /**
309
+ * 应用页面尺寸到蒙层;宽高为 0 时忽略,避免切换/布局过程中把 editor-mask 置空
310
+ */
311
+ private applyPageSize(clientWidth: number, clientHeight: number): void {
312
+ if (clientWidth <= 0 || clientHeight <= 0) return;
313
+
314
+ this.setHeight(clientHeight);
315
+ this.setWidth(clientWidth);
316
+ this.scroll();
317
+ }
318
+
290
319
  /**
291
320
  * 设置蒙层高度
292
321
  * @param height 高度
package/types/index.d.ts CHANGED
@@ -710,7 +710,8 @@ declare class StageMask extends Rule {
710
710
  */
711
711
  observe(page: HTMLElement): void;
712
712
  /**
713
- * 处理页面大小变更,同步页面和mask大小
713
+ * 处理页面大小变更,同步页面和 mask 大小
714
+ * @description 仅处理当前 page 且仍挂载在文档中的 entry;非当前页、已卸载或宽高为 0 的回调会被忽略
714
715
  * @param entries ResizeObserverEntry,获取页面最新大小
715
716
  */
716
717
  pageResize(entries: ResizeObserverEntry[]): void;
@@ -742,6 +743,14 @@ declare class StageMask extends Rule {
742
743
  private initObserverWrapper;
743
744
  private scroll;
744
745
  private scrollTo;
746
+ /**
747
+ * 从当前页面同步蒙层宽高,并修正滚动偏移
748
+ */
749
+ private syncPageSize;
750
+ /**
751
+ * 应用页面尺寸到蒙层;宽高为 0 时忽略,避免切换/布局过程中把 editor-mask 置空
752
+ */
753
+ private applyPageSize;
745
754
  /**
746
755
  * 设置蒙层高度
747
756
  * @param height 高度