@tmagic/stage 1.5.22 → 1.5.24

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.
@@ -1659,6 +1659,10 @@ class ActionManager extends EventEmitter {
1659
1659
  getDragStatus() {
1660
1660
  return this.dr?.getDragStatus();
1661
1661
  }
1662
+ updateMoveableOptions() {
1663
+ this.dr?.updateMoveable();
1664
+ this.multiDr?.updateMoveable();
1665
+ }
1662
1666
  destroy() {
1663
1667
  this.container.removeEventListener("mousedown", this.mouseDownHandler);
1664
1668
  this.container.removeEventListener("mousemove", this.mouseMoveHandler);
@@ -1907,13 +1911,16 @@ class Rule extends EventEmitter {
1907
1911
  guidesOptions;
1908
1912
  constructor(container, options) {
1909
1913
  super();
1914
+ if (options?.disabledRule) {
1915
+ return;
1916
+ }
1910
1917
  this.guidesOptions = options?.guidesOptions || {};
1911
1918
  this.container = container;
1912
1919
  this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
1913
1920
  this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
1914
1921
  this.containerResizeObserver = new ResizeObserver(() => {
1915
- this.vGuides.resize();
1916
- this.hGuides.resize();
1922
+ this.vGuides?.resize();
1923
+ this.hGuides?.resize();
1917
1924
  });
1918
1925
  this.containerResizeObserver.observe(this.container);
1919
1926
  }
@@ -1923,20 +1930,20 @@ class Rule extends EventEmitter {
1923
1930
  */
1924
1931
  showGuides(isShowGuides = true) {
1925
1932
  this.isShowGuides = isShowGuides;
1926
- this.hGuides.setState({
1933
+ this.hGuides?.setState({
1927
1934
  showGuides: isShowGuides
1928
1935
  });
1929
- this.vGuides.setState({
1936
+ this.vGuides?.setState({
1930
1937
  showGuides: isShowGuides
1931
1938
  });
1932
1939
  }
1933
1940
  setGuides([hLines, vLines]) {
1934
1941
  this.horizontalGuidelines = hLines;
1935
1942
  this.verticalGuidelines = vLines;
1936
- this.hGuides.setState({
1943
+ this.hGuides?.setState({
1937
1944
  defaultGuides: hLines
1938
1945
  });
1939
- this.vGuides.setState({
1946
+ this.vGuides?.setState({
1940
1947
  defaultGuides: vLines
1941
1948
  });
1942
1949
  this.emit("change-guides", {
@@ -1964,12 +1971,12 @@ class Rule extends EventEmitter {
1964
1971
  this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
1965
1972
  this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
1966
1973
  } else {
1967
- this.hGuides.setState({
1974
+ this.hGuides?.setState({
1968
1975
  rulerStyle: {
1969
1976
  visibility: "hidden"
1970
1977
  }
1971
1978
  });
1972
- this.vGuides.setState({
1979
+ this.vGuides?.setState({
1973
1980
  rulerStyle: {
1974
1981
  visibility: "hidden"
1975
1982
  }
@@ -1977,24 +1984,27 @@ class Rule extends EventEmitter {
1977
1984
  }
1978
1985
  }
1979
1986
  scrollRule(scrollTop) {
1980
- this.hGuides.scrollGuides(scrollTop);
1981
- this.hGuides.scroll(0);
1982
- this.vGuides.scrollGuides(0);
1983
- this.vGuides.scroll(scrollTop);
1987
+ this.hGuides?.scrollGuides(scrollTop);
1988
+ this.hGuides?.scroll(0);
1989
+ this.vGuides?.scrollGuides(0);
1990
+ this.vGuides?.scroll(scrollTop);
1984
1991
  }
1985
1992
  destroy() {
1986
1993
  this.destroyGuides();
1987
- this.hGuides.off("changeGuides", this.hGuidesChangeGuidesHandler);
1988
- this.vGuides.off("changeGuides", this.vGuidesChangeGuidesHandler);
1989
- this.containerResizeObserver.disconnect();
1994
+ this.hGuides?.off("changeGuides", this.hGuidesChangeGuidesHandler);
1995
+ this.vGuides?.off("changeGuides", this.vGuidesChangeGuidesHandler);
1996
+ this.containerResizeObserver?.disconnect();
1990
1997
  this.removeAllListeners();
1991
1998
  }
1992
1999
  destroyGuides() {
1993
- this.hGuides.destroy();
1994
- this.vGuides.destroy();
1995
- this.container.querySelectorAll(`.${guidesClass}`).forEach((el) => {
2000
+ this.hGuides?.destroy();
2001
+ this.vGuides?.destroy();
2002
+ this.container?.querySelectorAll(`.${guidesClass}`).forEach((el) => {
1996
2003
  el.remove();
1997
2004
  });
2005
+ this.hGuides = void 0;
2006
+ this.vGuides = void 0;
2007
+ this.container = void 0;
1998
2008
  }
1999
2009
  getGuidesStyle = (type) => ({
2000
2010
  position: "fixed",
@@ -2005,6 +2015,9 @@ class Rule extends EventEmitter {
2005
2015
  height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
2006
2016
  });
2007
2017
  createGuides = (type, defaultGuides = []) => {
2018
+ if (!this.container) {
2019
+ return;
2020
+ }
2008
2021
  const guides = new Guides(this.container, {
2009
2022
  type,
2010
2023
  defaultGuides,
@@ -2534,7 +2547,8 @@ class StageCore extends EventEmitter$1 {
2534
2547
  }
2535
2548
  });
2536
2549
  this.mask = new StageMask({
2537
- guidesOptions: config.guidesOptions
2550
+ guidesOptions: config.guidesOptions,
2551
+ disabledRule: config.disabledRule
2538
2552
  });
2539
2553
  this.actionManager = new ActionManager(this.getActionManagerConfig(config));
2540
2554
  this.initRenderEvent();
@@ -4132,6 +4132,10 @@
4132
4132
  getDragStatus() {
4133
4133
  return this.dr?.getDragStatus();
4134
4134
  }
4135
+ updateMoveableOptions() {
4136
+ this.dr?.updateMoveable();
4137
+ this.multiDr?.updateMoveable();
4138
+ }
4135
4139
  destroy() {
4136
4140
  this.container.removeEventListener("mousedown", this.mouseDownHandler);
4137
4141
  this.container.removeEventListener("mousemove", this.mouseMoveHandler);
@@ -4380,13 +4384,16 @@
4380
4384
  guidesOptions;
4381
4385
  constructor(container, options) {
4382
4386
  super();
4387
+ if (options?.disabledRule) {
4388
+ return;
4389
+ }
4383
4390
  this.guidesOptions = options?.guidesOptions || {};
4384
4391
  this.container = container;
4385
4392
  this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
4386
4393
  this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
4387
4394
  this.containerResizeObserver = new ResizeObserver(() => {
4388
- this.vGuides.resize();
4389
- this.hGuides.resize();
4395
+ this.vGuides?.resize();
4396
+ this.hGuides?.resize();
4390
4397
  });
4391
4398
  this.containerResizeObserver.observe(this.container);
4392
4399
  }
@@ -4396,20 +4403,20 @@
4396
4403
  */
4397
4404
  showGuides(isShowGuides = true) {
4398
4405
  this.isShowGuides = isShowGuides;
4399
- this.hGuides.setState({
4406
+ this.hGuides?.setState({
4400
4407
  showGuides: isShowGuides
4401
4408
  });
4402
- this.vGuides.setState({
4409
+ this.vGuides?.setState({
4403
4410
  showGuides: isShowGuides
4404
4411
  });
4405
4412
  }
4406
4413
  setGuides([hLines, vLines]) {
4407
4414
  this.horizontalGuidelines = hLines;
4408
4415
  this.verticalGuidelines = vLines;
4409
- this.hGuides.setState({
4416
+ this.hGuides?.setState({
4410
4417
  defaultGuides: hLines
4411
4418
  });
4412
- this.vGuides.setState({
4419
+ this.vGuides?.setState({
4413
4420
  defaultGuides: vLines
4414
4421
  });
4415
4422
  this.emit("change-guides", {
@@ -4437,12 +4444,12 @@
4437
4444
  this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
4438
4445
  this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
4439
4446
  } else {
4440
- this.hGuides.setState({
4447
+ this.hGuides?.setState({
4441
4448
  rulerStyle: {
4442
4449
  visibility: "hidden"
4443
4450
  }
4444
4451
  });
4445
- this.vGuides.setState({
4452
+ this.vGuides?.setState({
4446
4453
  rulerStyle: {
4447
4454
  visibility: "hidden"
4448
4455
  }
@@ -4450,24 +4457,27 @@
4450
4457
  }
4451
4458
  }
4452
4459
  scrollRule(scrollTop) {
4453
- this.hGuides.scrollGuides(scrollTop);
4454
- this.hGuides.scroll(0);
4455
- this.vGuides.scrollGuides(0);
4456
- this.vGuides.scroll(scrollTop);
4460
+ this.hGuides?.scrollGuides(scrollTop);
4461
+ this.hGuides?.scroll(0);
4462
+ this.vGuides?.scrollGuides(0);
4463
+ this.vGuides?.scroll(scrollTop);
4457
4464
  }
4458
4465
  destroy() {
4459
4466
  this.destroyGuides();
4460
- this.hGuides.off("changeGuides", this.hGuidesChangeGuidesHandler);
4461
- this.vGuides.off("changeGuides", this.vGuidesChangeGuidesHandler);
4462
- this.containerResizeObserver.disconnect();
4467
+ this.hGuides?.off("changeGuides", this.hGuidesChangeGuidesHandler);
4468
+ this.vGuides?.off("changeGuides", this.vGuidesChangeGuidesHandler);
4469
+ this.containerResizeObserver?.disconnect();
4463
4470
  this.removeAllListeners();
4464
4471
  }
4465
4472
  destroyGuides() {
4466
- this.hGuides.destroy();
4467
- this.vGuides.destroy();
4468
- this.container.querySelectorAll(`.${guidesClass}`).forEach((el) => {
4473
+ this.hGuides?.destroy();
4474
+ this.vGuides?.destroy();
4475
+ this.container?.querySelectorAll(`.${guidesClass}`).forEach((el) => {
4469
4476
  el.remove();
4470
4477
  });
4478
+ this.hGuides = void 0;
4479
+ this.vGuides = void 0;
4480
+ this.container = void 0;
4471
4481
  }
4472
4482
  getGuidesStyle = (type) => ({
4473
4483
  position: "fixed",
@@ -4478,6 +4488,9 @@
4478
4488
  height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
4479
4489
  });
4480
4490
  createGuides = (type, defaultGuides = []) => {
4491
+ if (!this.container) {
4492
+ return;
4493
+ }
4481
4494
  const guides = new Guides(this.container, {
4482
4495
  type,
4483
4496
  defaultGuides,
@@ -5007,7 +5020,8 @@
5007
5020
  }
5008
5021
  });
5009
5022
  this.mask = new StageMask({
5010
- guidesOptions: config.guidesOptions
5023
+ guidesOptions: config.guidesOptions,
5024
+ disabledRule: config.disabledRule
5011
5025
  });
5012
5026
  this.actionManager = new ActionManager(this.getActionManagerConfig(config));
5013
5027
  this.initRenderEvent();
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.22",
2
+ "version": "1.5.24",
3
3
  "name": "@tmagic/stage",
4
4
  "type": "module",
5
5
  "main": "dist/tmagic-stage.umd.cjs",
@@ -37,12 +37,12 @@
37
37
  "scenejs": "^1.10.3"
38
38
  },
39
39
  "devDependencies": {
40
- "@types/events": "^3.0.0",
40
+ "@types/events": "^3.0.3",
41
41
  "@types/lodash-es": "^4.17.4"
42
42
  },
43
43
  "peerDependencies": {
44
- "typescript": "*",
45
- "@tmagic/core": "1.5.22"
44
+ "typescript": "^5.8.3",
45
+ "@tmagic/core": "1.5.24"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "typescript": {
@@ -380,6 +380,11 @@ export default class ActionManager extends EventEmitter {
380
380
  return this.dr?.getDragStatus();
381
381
  }
382
382
 
383
+ public updateMoveableOptions(): void {
384
+ this.dr?.updateMoveable();
385
+ this.multiDr?.updateMoveable();
386
+ }
387
+
383
388
  public destroy(): void {
384
389
  this.container.removeEventListener('mousedown', this.mouseDownHandler);
385
390
  this.container.removeEventListener('mousemove', this.mouseMoveHandler);
package/src/Rule.ts CHANGED
@@ -8,19 +8,23 @@ import type { RuleOptions } from './types';
8
8
  const guidesClass = 'tmagic-stage-guides';
9
9
 
10
10
  export default class Rule extends EventEmitter {
11
- public hGuides: Guides;
12
- public vGuides: Guides;
11
+ public hGuides?: Guides;
12
+ public vGuides?: Guides;
13
13
  public horizontalGuidelines: number[] = [];
14
14
  public verticalGuidelines: number[] = [];
15
15
 
16
- private container: HTMLDivElement;
17
- private containerResizeObserver: ResizeObserver;
16
+ private container?: HTMLDivElement;
17
+ private containerResizeObserver?: ResizeObserver;
18
18
  private isShowGuides = true;
19
19
  private guidesOptions?: Partial<GuidesOptions>;
20
20
 
21
21
  constructor(container: HTMLDivElement, options?: RuleOptions) {
22
22
  super();
23
23
 
24
+ if (options?.disabledRule) {
25
+ return;
26
+ }
27
+
24
28
  this.guidesOptions = options?.guidesOptions || {};
25
29
 
26
30
  this.container = container;
@@ -28,8 +32,8 @@ export default class Rule extends EventEmitter {
28
32
  this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
29
33
 
30
34
  this.containerResizeObserver = new ResizeObserver(() => {
31
- this.vGuides.resize();
32
- this.hGuides.resize();
35
+ this.vGuides?.resize();
36
+ this.hGuides?.resize();
33
37
  });
34
38
 
35
39
  this.containerResizeObserver.observe(this.container);
@@ -42,11 +46,11 @@ export default class Rule extends EventEmitter {
42
46
  public showGuides(isShowGuides = true) {
43
47
  this.isShowGuides = isShowGuides;
44
48
 
45
- this.hGuides.setState({
49
+ this.hGuides?.setState({
46
50
  showGuides: isShowGuides,
47
51
  });
48
52
 
49
- this.vGuides.setState({
53
+ this.vGuides?.setState({
50
54
  showGuides: isShowGuides,
51
55
  });
52
56
  }
@@ -55,11 +59,11 @@ export default class Rule extends EventEmitter {
55
59
  this.horizontalGuidelines = hLines;
56
60
  this.verticalGuidelines = vLines;
57
61
 
58
- this.hGuides.setState({
62
+ this.hGuides?.setState({
59
63
  defaultGuides: hLines,
60
64
  });
61
65
 
62
- this.vGuides.setState({
66
+ this.vGuides?.setState({
63
67
  defaultGuides: vLines,
64
68
  });
65
69
 
@@ -93,13 +97,13 @@ export default class Rule extends EventEmitter {
93
97
  this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
94
98
  this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
95
99
  } else {
96
- this.hGuides.setState({
100
+ this.hGuides?.setState({
97
101
  rulerStyle: {
98
102
  visibility: 'hidden',
99
103
  },
100
104
  });
101
105
 
102
- this.vGuides.setState({
106
+ this.vGuides?.setState({
103
107
  rulerStyle: {
104
108
  visibility: 'hidden',
105
109
  },
@@ -108,28 +112,32 @@ export default class Rule extends EventEmitter {
108
112
  }
109
113
 
110
114
  public scrollRule(scrollTop: number) {
111
- this.hGuides.scrollGuides(scrollTop);
112
- this.hGuides.scroll(0);
115
+ this.hGuides?.scrollGuides(scrollTop);
116
+ this.hGuides?.scroll(0);
113
117
 
114
- this.vGuides.scrollGuides(0);
115
- this.vGuides.scroll(scrollTop);
118
+ this.vGuides?.scrollGuides(0);
119
+ this.vGuides?.scroll(scrollTop);
116
120
  }
117
121
 
118
122
  public destroy(): void {
119
123
  this.destroyGuides();
120
- this.hGuides.off('changeGuides', this.hGuidesChangeGuidesHandler);
121
- this.vGuides.off('changeGuides', this.vGuidesChangeGuidesHandler);
122
- this.containerResizeObserver.disconnect();
124
+ this.hGuides?.off('changeGuides', this.hGuidesChangeGuidesHandler);
125
+ this.vGuides?.off('changeGuides', this.vGuidesChangeGuidesHandler);
126
+ this.containerResizeObserver?.disconnect();
123
127
  this.removeAllListeners();
124
128
  }
125
129
 
126
130
  public destroyGuides(): void {
127
- this.hGuides.destroy();
128
- this.vGuides.destroy();
131
+ this.hGuides?.destroy();
132
+ this.vGuides?.destroy();
129
133
 
130
- this.container.querySelectorAll(`.${guidesClass}`).forEach((el) => {
134
+ this.container?.querySelectorAll(`.${guidesClass}`).forEach((el) => {
131
135
  el.remove();
132
136
  });
137
+
138
+ this.hGuides = undefined;
139
+ this.vGuides = undefined;
140
+ this.container = undefined;
133
141
  }
134
142
 
135
143
  private getGuidesStyle = (type: GuidesType) => ({
@@ -141,7 +149,11 @@ export default class Rule extends EventEmitter {
141
149
  height: type === GuidesType.HORIZONTAL ? '30px' : '100%',
142
150
  });
143
151
 
144
- private createGuides = (type: GuidesType, defaultGuides: number[] = []): Guides => {
152
+ private createGuides = (type: GuidesType, defaultGuides: number[] = []): Guides | undefined => {
153
+ if (!this.container) {
154
+ return;
155
+ }
156
+
145
157
  const guides = new Guides(this.container, {
146
158
  type,
147
159
  defaultGuides,
package/src/StageCore.ts CHANGED
@@ -74,6 +74,7 @@ export default class StageCore extends EventEmitter {
74
74
  });
75
75
  this.mask = new StageMask({
76
76
  guidesOptions: config.guidesOptions,
77
+ disabledRule: config.disabledRule,
77
78
  });
78
79
  this.actionManager = new ActionManager(this.getActionManagerConfig(config));
79
80
 
package/src/types.ts CHANGED
@@ -67,6 +67,7 @@ export interface StageCoreConfig {
67
67
  renderType?: RenderType;
68
68
  guidesOptions?: Partial<GuidesOptions>;
69
69
  disabledMultiSelect?: boolean;
70
+ disabledRule?: boolean;
70
71
  }
71
72
 
72
73
  export interface ActionManagerConfig {
@@ -240,6 +241,7 @@ export interface TargetShadowConfig {
240
241
 
241
242
  export interface RuleOptions {
242
243
  guidesOptions?: Partial<GuidesOptions>;
244
+ disabledRule?: boolean;
243
245
  }
244
246
 
245
247
  export interface CoreEvents {
package/types/index.d.ts CHANGED
@@ -189,6 +189,7 @@ interface StageCoreConfig {
189
189
  renderType?: RenderType;
190
190
  guidesOptions?: Partial<GuidesOptions>;
191
191
  disabledMultiSelect?: boolean;
192
+ disabledRule?: boolean;
192
193
  }
193
194
  interface ActionManagerConfig {
194
195
  container: HTMLElement;
@@ -338,6 +339,7 @@ interface TargetShadowConfig {
338
339
  }
339
340
  interface RuleOptions {
340
341
  guidesOptions?: Partial<GuidesOptions>;
342
+ disabledRule?: boolean;
341
343
  }
342
344
  interface CoreEvents {
343
345
  mounted: [];
@@ -508,6 +510,7 @@ declare class ActionManager extends EventEmitter {
508
510
  */
509
511
  delayedMarkContainer(event: MouseEvent, excludeElList?: Element[]): NodeJS.Timeout | undefined;
510
512
  getDragStatus(): StageDragStatus | undefined;
513
+ updateMoveableOptions(): void;
511
514
  destroy(): void;
512
515
  on<Name extends keyof ActionManagerEvents, Param extends ActionManagerEvents[Name]>(eventName: Name, listener: (...args: Param) => void): this;
513
516
  emit<Name extends keyof ActionManagerEvents, Param extends ActionManagerEvents[Name]>(eventName: Name, ...args: Param): boolean;
@@ -549,12 +552,12 @@ declare class ActionManager extends EventEmitter {
549
552
  }
550
553
 
551
554
  declare class Rule extends EventEmitter {
552
- hGuides: Guides;
553
- vGuides: Guides;
555
+ hGuides?: Guides;
556
+ vGuides?: Guides;
554
557
  horizontalGuidelines: number[];
555
558
  verticalGuidelines: number[];
556
- private container;
557
- private containerResizeObserver;
559
+ private container?;
560
+ private containerResizeObserver?;
558
561
  private isShowGuides;
559
562
  private guidesOptions?;
560
563
  constructor(container: HTMLDivElement, options?: RuleOptions);