@tmagic/editor 1.2.0-beta.20 → 1.2.0-beta.21

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/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
- "version": "1.2.0-beta.20",
2
+ "version": "1.2.0-beta.21",
3
3
  "name": "@tmagic/editor",
4
+ "type": "module",
4
5
  "sideEffects": [
5
6
  "dist/*",
6
7
  "src/theme/*"
7
8
  ],
8
- "main": "dist/tmagic-editor.umd.js",
9
- "module": "dist/tmagic-editor.mjs",
9
+ "main": "dist/tmagic-editor.umd.cjs",
10
+ "module": "dist/tmagic-editor.js",
10
11
  "style": "dist/style.css",
11
12
  "types": "types/index.d.ts",
12
13
  "exports": {
13
14
  ".": {
14
- "import": "./dist/tmagic-editor.mjs",
15
- "require": "./dist/tmagic-editor.umd.js"
15
+ "import": "./dist/tmagic-editor.js",
16
+ "require": "./dist/tmagic-editor.umd.cjs"
16
17
  },
17
18
  "./dist/style.css": {
18
19
  "import": "./dist/style.css",
@@ -45,12 +46,12 @@
45
46
  "dependencies": {
46
47
  "@babel/core": "^7.18.0",
47
48
  "@element-plus/icons-vue": "^2.0.9",
48
- "@tmagic/core": "1.2.0-beta.20",
49
- "@tmagic/design": "1.2.0-beta.20",
50
- "@tmagic/form": "1.2.0-beta.20",
51
- "@tmagic/schema": "1.2.0-beta.20",
52
- "@tmagic/stage": "1.2.0-beta.20",
53
- "@tmagic/utils": "1.2.0-beta.20",
49
+ "@tmagic/core": "1.2.0-beta.21",
50
+ "@tmagic/design": "1.2.0-beta.21",
51
+ "@tmagic/form": "1.2.0-beta.21",
52
+ "@tmagic/schema": "1.2.0-beta.21",
53
+ "@tmagic/stage": "1.2.0-beta.21",
54
+ "@tmagic/utils": "1.2.0-beta.21",
54
55
  "buffer": "^6.0.3",
55
56
  "color": "^3.1.3",
56
57
  "events": "^3.3.0",
@@ -62,8 +63,8 @@
62
63
  "vue": "^3.2.37"
63
64
  },
64
65
  "peerDependencies": {
65
- "@tmagic/design": "1.2.0-beta.20",
66
- "@tmagic/form": "1.2.0-beta.20",
66
+ "@tmagic/design": "1.2.0-beta.21",
67
+ "@tmagic/form": "1.2.0-beta.21",
67
68
  "monaco-editor": "^0.34.0",
68
69
  "vue": "^3.2.37"
69
70
  },
package/src/Editor.vue CHANGED
@@ -316,13 +316,12 @@ export default defineComponent({
316
316
  );
317
317
 
318
318
  onUnmounted(() => {
319
- editorService.destroy();
320
- historyService.destroy();
321
- propsService.destroy();
322
- uiService.destroy();
323
- componentListService.destroy();
324
- storageService.destroy();
325
- codeBlockService.destroy();
319
+ editorService.resetState();
320
+ historyService.resetState();
321
+ propsService.resetState();
322
+ uiService.resetState();
323
+ componentListService.resetState();
324
+ codeBlockService.resetState();
326
325
  });
327
326
 
328
327
  const services: Services = {
@@ -48,7 +48,7 @@ const props = withDefaults(
48
48
  const el = ref<HTMLElement>();
49
49
 
50
50
  const hasLeft = computed(() => typeof props.left !== 'undefined');
51
- const hasRight = computed(() => typeof props.left !== 'undefined');
51
+ const hasRight = computed(() => typeof props.right !== 'undefined');
52
52
 
53
53
  const getCenterWidth = (clientWidth: number, left: number, right: number) => {
54
54
  let center = clientWidth - left - right;
@@ -169,6 +169,11 @@ export default class extends EventEmitter {
169
169
  });
170
170
  }
171
171
 
172
+ public removeAllPlugins() {
173
+ this.pluginOptionsList = {};
174
+ this.middleware = {};
175
+ }
176
+
172
177
  private async doTask() {
173
178
  this.doingTask = true;
174
179
  let task = this.taskList.shift();
@@ -344,7 +344,7 @@ class CodeBlock extends BaseService {
344
344
  this.setCodeDsl(codeDsl);
345
345
  }
346
346
 
347
- public destroy(): void {
347
+ public resetState() {
348
348
  this.state.isShowCodeEditor = false;
349
349
  this.state.codeDsl = null;
350
350
  this.state.id = '';
@@ -354,6 +354,12 @@ class CodeBlock extends BaseService {
354
354
  this.state.undeletableList = [];
355
355
  }
356
356
 
357
+ public destroy(): void {
358
+ this.resetState();
359
+ this.removeAllListeners();
360
+ this.removeAllPlugins();
361
+ }
362
+
357
363
  /**
358
364
  * 删除组件时 如果是容器 需要遍历删除其包含节点的绑定信息
359
365
  * @param {MNode} node 节点信息
@@ -42,9 +42,14 @@ class ComponentList extends BaseService {
42
42
  return this.state.list;
43
43
  }
44
44
 
45
- public destroy() {
45
+ public resetState() {
46
46
  this.state.list = [];
47
+ }
48
+
49
+ public destroy() {
50
+ this.resetState();
47
51
  this.removeAllListeners();
52
+ this.removeAllPlugins();
48
53
  }
49
54
  }
50
55
 
@@ -207,7 +207,7 @@ class Editor extends BaseService {
207
207
  if (page) {
208
208
  historyService.changePage(toRaw(page));
209
209
  } else {
210
- historyService.empty();
210
+ historyService.resetState();
211
211
  }
212
212
 
213
213
  if (node?.id) {
@@ -762,8 +762,7 @@ class Editor extends BaseService {
762
762
  });
763
763
  }
764
764
 
765
- public destroy() {
766
- this.removeAllListeners();
765
+ public resetState() {
767
766
  this.set('root', null);
768
767
  this.set('node', null);
769
768
  this.set('nodes', []);
@@ -775,6 +774,12 @@ class Editor extends BaseService {
775
774
  this.set('pageLength', new Map());
776
775
  }
777
776
 
777
+ public destroy() {
778
+ this.removeAllListeners();
779
+ this.resetState();
780
+ this.removeAllPlugins();
781
+ }
782
+
778
783
  public resetModifiedNodeId() {
779
784
  this.get<Map<Id, Id>>('modifiedNodeIds').clear();
780
785
  }
@@ -76,10 +76,15 @@ class Events extends BaseService {
76
76
  return cloneDeep(methodMap[type] || DEFAULT_METHODS);
77
77
  }
78
78
 
79
- public destroy() {
79
+ public resetState() {
80
80
  eventMap = reactive({});
81
81
  methodMap = reactive({});
82
+ }
83
+
84
+ public destroy() {
85
+ this.resetState();
82
86
  this.removeAllListeners();
87
+ this.removeAllPlugins();
83
88
  }
84
89
  }
85
90
 
@@ -68,7 +68,7 @@ class History extends BaseService {
68
68
  this.emit('page-change', this.state.pageSteps[this.state.pageId]);
69
69
  }
70
70
 
71
- public empty(): void {
71
+ public resetState(): void {
72
72
  this.state.pageId = undefined;
73
73
  this.state.pageSteps = {};
74
74
  this.state.canRedo = false;
@@ -100,8 +100,9 @@ class History extends BaseService {
100
100
  }
101
101
 
102
102
  public destroy(): void {
103
- this.empty();
103
+ this.resetState();
104
104
  this.removeAllListeners();
105
+ this.removeAllPlugins();
105
106
  }
106
107
 
107
108
  private getUndoRedo() {
@@ -171,10 +171,15 @@ class Props extends BaseService {
171
171
  };
172
172
  }
173
173
 
174
- public destroy() {
174
+ public resetState() {
175
175
  this.state.propsConfigMap = {};
176
176
  this.state.propsValueMap = {};
177
+ }
178
+
179
+ public destroy() {
180
+ this.resetState();
177
181
  this.removeAllListeners();
182
+ this.removeAllPlugins();
178
183
  }
179
184
 
180
185
  /**
@@ -109,6 +109,7 @@ export class WebStorage extends BaseService {
109
109
 
110
110
  public destroy() {
111
111
  this.removeAllListeners();
112
+ this.removeAllPlugins();
112
113
  }
113
114
 
114
115
  private getValueAndProtocol(value: string | null) {
@@ -97,8 +97,20 @@ class Ui extends BaseService {
97
97
  return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
98
98
  }
99
99
 
100
+ public resetState() {
101
+ this.set('showSrc', false);
102
+ this.set('uiSelectMode', false);
103
+ this.set('zoom', 1);
104
+ this.set('stageContainerRect', {
105
+ width: 0,
106
+ height: 0,
107
+ });
108
+ }
109
+
100
110
  public destroy() {
111
+ this.resetState();
101
112
  this.removeAllListeners();
113
+ this.removeAllPlugins();
102
114
  }
103
115
 
104
116
  private async setStageRect(value: StageRect) {
@@ -55,5 +55,6 @@ export default class extends EventEmitter {
55
55
  constructor(methods?: string[], serialMethods?: string[]);
56
56
  use(options: Record<string, Function>): void;
57
57
  usePlugin(options: Record<string, Function>): void;
58
+ removeAllPlugins(): void;
58
59
  private doTask;
59
60
  }
@@ -155,6 +155,7 @@ declare class CodeBlock extends BaseService {
155
155
  * @returns void
156
156
  */
157
157
  deleteCompsInRelation(node: MNode): Promise<void>;
158
+ resetState(): void;
158
159
  destroy(): void;
159
160
  /**
160
161
  * 删除组件时 如果是容器 需要遍历删除其包含节点的绑定信息
@@ -8,6 +8,7 @@ declare class ComponentList extends BaseService {
8
8
  */
9
9
  setList(componentGroupList: ComponentGroup[]): void;
10
10
  getList(): ComponentGroup[];
11
+ resetState(): void;
11
12
  destroy(): void;
12
13
  }
13
14
  export declare type ComponentListService = ComponentList;
@@ -133,6 +133,7 @@ declare class Editor extends BaseService {
133
133
  */
134
134
  redo(): Promise<StepValue | null>;
135
135
  move(left: number, top: number): Promise<void>;
136
+ resetState(): void;
136
137
  destroy(): void;
137
138
  resetModifiedNodeId(): void;
138
139
  /**
@@ -10,6 +10,7 @@ declare class Events extends BaseService {
10
10
  setMethods(methods: Record<string, EventOption[]>): void;
11
11
  setMethod(type: string, method: EventOption[]): void;
12
12
  getMethod(type: string): EventOption[];
13
+ resetState(): void;
13
14
  destroy(): void;
14
15
  }
15
16
  export declare type EventsService = Events;
@@ -12,7 +12,7 @@ declare class History extends BaseService {
12
12
  constructor();
13
13
  reset(): void;
14
14
  changePage(page: MPage): void;
15
- empty(): void;
15
+ resetState(): void;
16
16
  push(state: StepValue): StepValue | null;
17
17
  undo(): StepValue | null;
18
18
  redo(): StepValue | null;
@@ -97,6 +97,7 @@ declare class Props extends BaseService {
97
97
  layout?: undefined;
98
98
  items?: undefined;
99
99
  }>;
100
+ resetState(): void;
100
101
  destroy(): void;
101
102
  /**
102
103
  * 生成指定位数的GUID,无【-】格式
@@ -28,6 +28,7 @@ declare class Ui extends BaseService {
28
28
  get<T>(name: keyof typeof state): T;
29
29
  zoom(zoom: number): Promise<void>;
30
30
  calcZoom(): Promise<number>;
31
+ resetState(): void;
31
32
  destroy(): void;
32
33
  private setStageRect;
33
34
  }