@tmagic/stage 1.5.20 → 1.5.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.
@@ -2211,6 +2211,10 @@ class StageMask extends Rule {
2211
2211
  const { clientHeight, clientWidth } = entry.target;
2212
2212
  this.wrapperHeight = clientHeight;
2213
2213
  this.wrapperWidth = clientWidth;
2214
+ if (this.mode === Mode.FIXED) {
2215
+ this.content.style.width = `${this.wrapperWidth}px`;
2216
+ this.content.style.height = `${this.wrapperHeight}px`;
2217
+ }
2214
2218
  this.setMaxScrollLeft();
2215
2219
  this.setMaxScrollTop();
2216
2220
  });
@@ -2250,7 +2254,9 @@ class StageMask extends Rule {
2250
2254
  setHeight(height) {
2251
2255
  this.height = height;
2252
2256
  this.setMaxScrollTop();
2253
- this.content.style.height = `${height}px`;
2257
+ if (this.mode !== Mode.FIXED) {
2258
+ this.content.style.height = `${height}px`;
2259
+ }
2254
2260
  }
2255
2261
  /**
2256
2262
  * 设置蒙层宽度
@@ -2259,7 +2265,9 @@ class StageMask extends Rule {
2259
2265
  setWidth(width) {
2260
2266
  this.width = width;
2261
2267
  this.setMaxScrollLeft();
2262
- this.content.style.width = `${width}px`;
2268
+ if (this.mode !== Mode.FIXED) {
2269
+ this.content.style.width = `${width}px`;
2270
+ }
2263
2271
  }
2264
2272
  /**
2265
2273
  * 计算并设置最大滚动宽度
@@ -2324,7 +2332,10 @@ class StageRender extends EventEmitter$1 {
2324
2332
  }
2325
2333
  }
2326
2334
  getMagicApi = () => ({
2327
- onPageElUpdate: (el) => this.emit("page-el-update", el),
2335
+ id: guid(),
2336
+ onPageElUpdate: (el) => {
2337
+ this.emit("page-el-update", el);
2338
+ },
2328
2339
  onRuntimeReady: (runtime) => {
2329
2340
  if (this.runtime) {
2330
2341
  return;
@@ -2418,14 +2429,27 @@ class StageRender extends EventEmitter$1 {
2418
2429
  "*"
2419
2430
  );
2420
2431
  }
2421
- /**
2422
- * 销毁实例
2423
- */
2424
- destroy() {
2432
+ reloadIframe(url) {
2433
+ if (this.renderType !== RenderType.IFRAME) return;
2434
+ const el = this.iframe?.parentElement;
2435
+ this.destroyIframe();
2436
+ this.runtimeUrl = url;
2437
+ this.createIframe();
2438
+ this.mount(el);
2439
+ this.runtime = null;
2440
+ }
2441
+ destroyIframe() {
2425
2442
  this.iframe?.removeEventListener("load", this.iframeLoadHandler);
2426
2443
  this.contentWindow = null;
2427
2444
  this.iframe?.remove();
2428
2445
  this.iframe = void 0;
2446
+ }
2447
+ /**
2448
+ * 销毁实例
2449
+ */
2450
+ destroy() {
2451
+ this.destroyIframe();
2452
+ globalThis.runtime = void 0;
2429
2453
  this.removeAllListeners();
2430
2454
  }
2431
2455
  on(eventName, listener) {
@@ -2638,6 +2662,9 @@ class StageCore extends EventEmitter$1 {
2638
2662
  enableMultiSelect() {
2639
2663
  this.actionManager?.enableMultiSelect();
2640
2664
  }
2665
+ reloadIframe(url) {
2666
+ this.renderer?.reloadIframe(url);
2667
+ }
2641
2668
  /**
2642
2669
  * 销毁实例
2643
2670
  */
@@ -4684,6 +4684,10 @@
4684
4684
  const { clientHeight, clientWidth } = entry.target;
4685
4685
  this.wrapperHeight = clientHeight;
4686
4686
  this.wrapperWidth = clientWidth;
4687
+ if (this.mode === Mode.FIXED) {
4688
+ this.content.style.width = `${this.wrapperWidth}px`;
4689
+ this.content.style.height = `${this.wrapperHeight}px`;
4690
+ }
4687
4691
  this.setMaxScrollLeft();
4688
4692
  this.setMaxScrollTop();
4689
4693
  });
@@ -4723,7 +4727,9 @@
4723
4727
  setHeight(height) {
4724
4728
  this.height = height;
4725
4729
  this.setMaxScrollTop();
4726
- this.content.style.height = `${height}px`;
4730
+ if (this.mode !== Mode.FIXED) {
4731
+ this.content.style.height = `${height}px`;
4732
+ }
4727
4733
  }
4728
4734
  /**
4729
4735
  * 设置蒙层宽度
@@ -4732,7 +4738,9 @@
4732
4738
  setWidth(width) {
4733
4739
  this.width = width;
4734
4740
  this.setMaxScrollLeft();
4735
- this.content.style.width = `${width}px`;
4741
+ if (this.mode !== Mode.FIXED) {
4742
+ this.content.style.width = `${width}px`;
4743
+ }
4736
4744
  }
4737
4745
  /**
4738
4746
  * 计算并设置最大滚动宽度
@@ -4797,7 +4805,10 @@
4797
4805
  }
4798
4806
  }
4799
4807
  getMagicApi = () => ({
4800
- onPageElUpdate: (el) => this.emit("page-el-update", el),
4808
+ id: core.guid(),
4809
+ onPageElUpdate: (el) => {
4810
+ this.emit("page-el-update", el);
4811
+ },
4801
4812
  onRuntimeReady: (runtime) => {
4802
4813
  if (this.runtime) {
4803
4814
  return;
@@ -4891,14 +4902,27 @@
4891
4902
  "*"
4892
4903
  );
4893
4904
  }
4894
- /**
4895
- * 销毁实例
4896
- */
4897
- destroy() {
4905
+ reloadIframe(url) {
4906
+ if (this.renderType !== RenderType.IFRAME) return;
4907
+ const el = this.iframe?.parentElement;
4908
+ this.destroyIframe();
4909
+ this.runtimeUrl = url;
4910
+ this.createIframe();
4911
+ this.mount(el);
4912
+ this.runtime = null;
4913
+ }
4914
+ destroyIframe() {
4898
4915
  this.iframe?.removeEventListener("load", this.iframeLoadHandler);
4899
4916
  this.contentWindow = null;
4900
4917
  this.iframe?.remove();
4901
4918
  this.iframe = void 0;
4919
+ }
4920
+ /**
4921
+ * 销毁实例
4922
+ */
4923
+ destroy() {
4924
+ this.destroyIframe();
4925
+ globalThis.runtime = void 0;
4902
4926
  this.removeAllListeners();
4903
4927
  }
4904
4928
  on(eventName, listener) {
@@ -5111,6 +5135,9 @@
5111
5135
  enableMultiSelect() {
5112
5136
  this.actionManager?.enableMultiSelect();
5113
5137
  }
5138
+ reloadIframe(url) {
5139
+ this.renderer?.reloadIframe(url);
5140
+ }
5114
5141
  /**
5115
5142
  * 销毁实例
5116
5143
  */
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.20",
2
+ "version": "1.5.22",
3
3
  "name": "@tmagic/stage",
4
4
  "type": "module",
5
5
  "main": "dist/tmagic-stage.umd.cjs",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "peerDependencies": {
44
44
  "typescript": "*",
45
- "@tmagic/core": "1.5.20"
45
+ "@tmagic/core": "1.5.22"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "typescript": {
package/src/StageCore.ts CHANGED
@@ -236,6 +236,10 @@ export default class StageCore extends EventEmitter {
236
236
  this.actionManager?.enableMultiSelect();
237
237
  }
238
238
 
239
+ public reloadIframe(url: string) {
240
+ this.renderer?.reloadIframe(url);
241
+ }
242
+
239
243
  /**
240
244
  * 销毁实例
241
245
  */
package/src/StageMask.ts CHANGED
@@ -236,6 +236,12 @@ export default class StageMask extends Rule {
236
236
  const { clientHeight, clientWidth } = entry.target;
237
237
  this.wrapperHeight = clientHeight;
238
238
  this.wrapperWidth = clientWidth;
239
+
240
+ if (this.mode === Mode.FIXED) {
241
+ this.content.style.width = `${this.wrapperWidth}px`;
242
+ this.content.style.height = `${this.wrapperHeight}px`;
243
+ }
244
+
239
245
  this.setMaxScrollLeft();
240
246
  this.setMaxScrollTop();
241
247
  });
@@ -286,7 +292,9 @@ export default class StageMask extends Rule {
286
292
  private setHeight(height: number): void {
287
293
  this.height = height;
288
294
  this.setMaxScrollTop();
289
- this.content.style.height = `${height}px`;
295
+ if (this.mode !== Mode.FIXED) {
296
+ this.content.style.height = `${height}px`;
297
+ }
290
298
  }
291
299
 
292
300
  /**
@@ -296,7 +304,9 @@ export default class StageMask extends Rule {
296
304
  private setWidth(width: number): void {
297
305
  this.width = width;
298
306
  this.setMaxScrollLeft();
299
- this.content.style.width = `${width}px`;
307
+ if (this.mode !== Mode.FIXED) {
308
+ this.content.style.width = `${width}px`;
309
+ }
300
310
  }
301
311
 
302
312
  /**
@@ -19,7 +19,7 @@
19
19
  import { EventEmitter } from 'events';
20
20
 
21
21
  import type { Id } from '@tmagic/core';
22
- import { getElById, getHost, injectStyle, isSameDomain } from '@tmagic/core';
22
+ import { getElById, getHost, guid, injectStyle, isSameDomain } from '@tmagic/core';
23
23
 
24
24
  import { DEFAULT_ZOOM, RenderType } from './const';
25
25
  import style from './style.css?raw';
@@ -54,7 +54,10 @@ export default class StageRender extends EventEmitter {
54
54
  }
55
55
 
56
56
  public getMagicApi = () => ({
57
- onPageElUpdate: (el: HTMLElement) => this.emit('page-el-update', el),
57
+ id: guid(),
58
+ onPageElUpdate: (el: HTMLElement) => {
59
+ this.emit('page-el-update', el);
60
+ },
58
61
  onRuntimeReady: (runtime: Runtime) => {
59
62
  if (this.runtime) {
60
63
  return;
@@ -172,14 +175,31 @@ export default class StageRender extends EventEmitter {
172
175
  );
173
176
  }
174
177
 
175
- /**
176
- * 销毁实例
177
- */
178
- public destroy(): void {
178
+ public reloadIframe(url: string) {
179
+ if (this.renderType !== RenderType.IFRAME) return;
180
+
181
+ const el = this.iframe?.parentElement;
182
+ this.destroyIframe();
183
+ this.runtimeUrl = url;
184
+ this.createIframe();
185
+ this.mount(el as HTMLDivElement);
186
+ this.runtime = null;
187
+ }
188
+
189
+ public destroyIframe() {
179
190
  this.iframe?.removeEventListener('load', this.iframeLoadHandler);
180
191
  this.contentWindow = null;
181
192
  this.iframe?.remove();
182
193
  this.iframe = undefined;
194
+ }
195
+
196
+ /**
197
+ * 销毁实例
198
+ */
199
+ public destroy(): void {
200
+ this.destroyIframe();
201
+ // @ts-ignore
202
+ globalThis.runtime = undefined;
183
203
  this.removeAllListeners();
184
204
  }
185
205
 
package/src/types.ts CHANGED
@@ -214,6 +214,7 @@ export interface Runtime {
214
214
  }
215
215
 
216
216
  export interface Magic {
217
+ id: string;
217
218
  /** 当前页面的根节点变化时调用该方法,编辑器会同步该el和stage的大小,该方法由stage注入到iframe.contentWindow中 */
218
219
  onPageElUpdate: (el: HTMLElement) => void;
219
220
 
package/types/index.d.ts CHANGED
@@ -317,6 +317,7 @@ interface Runtime {
317
317
  [key: string]: any;
318
318
  }
319
319
  interface Magic {
320
+ id: string;
320
321
  /** 当前页面的根节点变化时调用该方法,编辑器会同步该el和stage的大小,该方法由stage注入到iframe.contentWindow中 */
321
322
  onPageElUpdate: (el: HTMLElement) => void;
322
323
  onRuntimeReady: (runtime: Runtime) => void;
@@ -680,7 +681,8 @@ declare class StageRender extends EventEmitter$1 {
680
681
  private customizedRender?;
681
682
  constructor({ runtimeUrl, zoom, customizedRender, renderType }: StageRenderConfig);
682
683
  getMagicApi: () => {
683
- onPageElUpdate: (el: HTMLElement) => boolean;
684
+ id: string;
685
+ onPageElUpdate: (el: HTMLElement) => void;
684
686
  onRuntimeReady: (runtime: Runtime) => void;
685
687
  };
686
688
  add(data: UpdateData): Promise<void>;
@@ -703,6 +705,8 @@ declare class StageRender extends EventEmitter$1 {
703
705
  getElementsFromPoint(point: Point): HTMLElement[];
704
706
  getTargetElement(id: Id): HTMLElement | null;
705
707
  postTmagicRuntimeReady(): void;
708
+ reloadIframe(url: string): void;
709
+ destroyIframe(): void;
706
710
  /**
707
711
  * 销毁实例
708
712
  */
@@ -788,6 +792,7 @@ declare class StageCore extends EventEmitter$1 {
788
792
  getDragStatus(): _tmagic_editor.StageDragStatus | undefined;
789
793
  disableMultiSelect(): void;
790
794
  enableMultiSelect(): void;
795
+ reloadIframe(url: string): void;
791
796
  /**
792
797
  * 销毁实例
793
798
  */