@tmagic/editor 1.3.0-beta.8 → 1.3.1

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,5 +1,5 @@
1
1
  {
2
- "version": "1.3.0-beta.8",
2
+ "version": "1.3.1",
3
3
  "name": "@tmagic/editor",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -47,13 +47,13 @@
47
47
  "dependencies": {
48
48
  "@babel/core": "^7.18.0",
49
49
  "@element-plus/icons-vue": "^2.0.9",
50
- "@tmagic/core": "1.3.0-beta.8",
51
- "@tmagic/design": "1.3.0-beta.8",
52
- "@tmagic/form": "1.3.0-beta.8",
53
- "@tmagic/schema": "1.3.0-beta.8",
54
- "@tmagic/stage": "1.3.0-beta.8",
55
- "@tmagic/table": "1.3.0-beta.8",
56
- "@tmagic/utils": "1.3.0-beta.8",
50
+ "@tmagic/core": "1.3.1",
51
+ "@tmagic/design": "1.3.1",
52
+ "@tmagic/form": "1.3.1",
53
+ "@tmagic/schema": "1.3.1",
54
+ "@tmagic/stage": "1.3.1",
55
+ "@tmagic/table": "1.3.1",
56
+ "@tmagic/utils": "1.3.1",
57
57
  "buffer": "^6.0.3",
58
58
  "color": "^3.1.3",
59
59
  "events": "^3.3.0",
@@ -65,8 +65,8 @@
65
65
  "vue": "^3.3.4"
66
66
  },
67
67
  "peerDependencies": {
68
- "@tmagic/design": "1.3.0-beta.8",
69
- "@tmagic/form": "1.3.0-beta.8",
68
+ "@tmagic/design": "1.3.1",
69
+ "@tmagic/form": "1.3.1",
70
70
  "monaco-editor": "^0.41.0",
71
71
  "vue": "^3.3.4"
72
72
  },
@@ -276,26 +276,6 @@ export const initServiceEvents = (
276
276
  };
277
277
 
278
278
  const rootChangeHandler = async (value: MApp | null, preValue?: MApp | null) => {
279
- const nodeId = editorService.get('node')?.id || props.defaultSelected;
280
- let node;
281
- if (nodeId) {
282
- node = editorService.getNodeById(nodeId);
283
- }
284
-
285
- if (node && node !== value) {
286
- await editorService.select(node.id);
287
- } else if (value?.items?.length) {
288
- await editorService.select(value.items[0]);
289
- } else if (value?.id) {
290
- editorService.set('nodes', [value]);
291
- editorService.set('parent', null);
292
- editorService.set('page', null);
293
- }
294
-
295
- if (toRaw(value) !== toRaw(preValue)) {
296
- emit('update:modelValue', value);
297
- }
298
-
299
279
  if (!value) return;
300
280
 
301
281
  value.codeBlocks = value.codeBlocks || {};
@@ -314,12 +294,32 @@ export const initServiceEvents = (
314
294
  initDataSourceDepTarget(ds);
315
295
  });
316
296
 
317
- if (value && Array.isArray(value.items)) {
297
+ if (Array.isArray(value.items)) {
318
298
  depService.collect(value.items, true);
319
299
  } else {
320
300
  depService.clear();
321
301
  delete value.dataSourceDeps;
322
302
  }
303
+
304
+ const nodeId = editorService.get('node')?.id || props.defaultSelected;
305
+ let node;
306
+ if (nodeId) {
307
+ node = editorService.getNodeById(nodeId);
308
+ }
309
+
310
+ if (node && node !== value) {
311
+ await editorService.select(node.id);
312
+ } else if (value.items?.length) {
313
+ await editorService.select(value.items[0]);
314
+ } else if (value.id) {
315
+ editorService.set('nodes', [value]);
316
+ editorService.set('parent', null);
317
+ editorService.set('page', null);
318
+ }
319
+
320
+ if (toRaw(value) !== toRaw(preValue)) {
321
+ emit('update:modelValue', value);
322
+ }
323
323
  };
324
324
 
325
325
  // 新增节点,收集依赖
@@ -149,7 +149,6 @@ const tree = ref<InstanceType<typeof TMagicTree>>();
149
149
 
150
150
  defineExpose({
151
151
  filter(val: string) {
152
- debugger;
153
152
  tree.value?.filter(val);
154
153
  },
155
154
  });
@@ -33,7 +33,7 @@
33
33
  import { computed, inject, markRaw, nextTick, onMounted, onUnmounted, ref, toRaw, watch, watchEffect } from 'vue';
34
34
  import { cloneDeep } from 'lodash-es';
35
35
 
36
- import type { MContainer } from '@tmagic/schema';
36
+ import type { MApp, MContainer } from '@tmagic/schema';
37
37
  import StageCore, { calcValueByFontsize, getOffset, Runtime } from '@tmagic/stage';
38
38
 
39
39
  import ScrollViewer from '@editor/components/ScrollViewer.vue';
@@ -105,12 +105,6 @@ watch(zoom, (zoom) => {
105
105
  stage.setZoom(zoom);
106
106
  });
107
107
 
108
- watch(root, (root) => {
109
- if (runtime && root) {
110
- runtime.updateRootConfig?.(cloneDeep(toRaw(root)));
111
- }
112
- });
113
-
114
108
  watch(page, (page) => {
115
109
  if (runtime && page) {
116
110
  runtime.updatePageId?.(page.id);
@@ -120,6 +114,14 @@ watch(page, (page) => {
120
114
  }
121
115
  });
122
116
 
117
+ const rootChangeHandler = (root: MApp) => {
118
+ if (runtime && root) {
119
+ runtime.updateRootConfig?.(cloneDeep(toRaw(root)));
120
+ }
121
+ };
122
+
123
+ services?.editorService.on('root-change', rootChangeHandler);
124
+
123
125
  const resizeObserver = new ResizeObserver((entries) => {
124
126
  for (const { contentRect } of entries) {
125
127
  services?.uiService.set('stageContainerRect', {
@@ -141,6 +143,7 @@ onUnmounted(() => {
141
143
  resizeObserver.disconnect();
142
144
  services?.editorService.set('stage', null);
143
145
  services?.keybindingService.unregisteEl('stage');
146
+ services?.editorService.off('root-change', rootChangeHandler);
144
147
  });
145
148
 
146
149
  const parseDSL = getConfig('parseDSL');
@@ -36,6 +36,7 @@ import {
36
36
  getInitPositionStyle,
37
37
  getNodeIndex,
38
38
  isFixed,
39
+ setChilrenLayout,
39
40
  setLayout,
40
41
  } from '@editor/utils/editor';
41
42
  import { beforePaste, getAddParent } from '@editor/utils/operator';
@@ -510,8 +511,8 @@ class Editor extends BaseService {
510
511
 
511
512
  const newLayout = await this.getLayout(newConfig);
512
513
  const layout = await this.getLayout(node);
513
- if (newLayout !== layout) {
514
- newConfig = setLayout(newConfig, newLayout);
514
+ if (Array.isArray(newConfig.items) && newLayout !== layout) {
515
+ newConfig = setChilrenLayout(newConfig as MContainer, newLayout);
515
516
  }
516
517
 
517
518
  parentNodeItems[index] = newConfig;
@@ -788,7 +789,15 @@ class Editor extends BaseService {
788
789
  }
789
790
  }
790
791
 
792
+ const layout = await this.getLayout(parent);
793
+ const newLayout = await this.getLayout(targetParent);
794
+
795
+ if (newLayout !== layout) {
796
+ setLayout(config, newLayout);
797
+ }
798
+
791
799
  parent.items?.splice(index, 1);
800
+
792
801
  targetParent.items?.splice(targetIndex, 0, config);
793
802
 
794
803
  const page = this.get('page');
@@ -129,23 +129,28 @@ export const getInitPositionStyle = (style: Record<string, any> = {}, layout: La
129
129
  return style;
130
130
  };
131
131
 
132
- export const setLayout = (node: MNode, layout: Layout) => {
132
+ export const setChilrenLayout = (node: MContainer, layout: Layout) => {
133
133
  node.items?.forEach((child: MNode) => {
134
- if (isPop(child)) return;
134
+ setLayout(child, layout);
135
+ });
136
+ return node;
137
+ };
135
138
 
136
- const style = child.style || {};
139
+ export const setLayout = (node: MNode, layout: Layout) => {
140
+ if (isPop(node)) return;
137
141
 
138
- // fixed 不做处理
139
- if (style.position === 'fixed') return;
142
+ const style = node.style || {};
140
143
 
141
- if (layout !== Layout.RELATIVE) {
142
- style.position = 'absolute';
143
- } else {
144
- child.style = getRelativeStyle(style);
145
- child.style.right = 'auto';
146
- child.style.bottom = 'auto';
147
- }
148
- });
144
+ // fixed 不做处理
145
+ if (style.position === 'fixed') return;
146
+
147
+ if (layout !== Layout.RELATIVE) {
148
+ style.position = 'absolute';
149
+ } else {
150
+ node.style = getRelativeStyle(style);
151
+ node.style.right = 'auto';
152
+ node.style.bottom = 'auto';
153
+ }
149
154
  return node;
150
155
  };
151
156
 
@@ -34,7 +34,8 @@ export declare const isFixed: (node: MNode) => boolean;
34
34
  export declare const getNodeIndex: (id: Id, parent: MContainer | MApp) => number;
35
35
  export declare const getRelativeStyle: (style?: Record<string, any>) => Record<string, any>;
36
36
  export declare const getInitPositionStyle: (style: Record<string, any> | undefined, layout: Layout) => Record<string, any>;
37
- export declare const setLayout: (node: MNode, layout: Layout) => MNode;
37
+ export declare const setChilrenLayout: (node: MContainer, layout: Layout) => MContainer;
38
+ export declare const setLayout: (node: MNode, layout: Layout) => import("@tmagic/schema").MComponent | undefined;
38
39
  export declare const change2Fixed: (node: MNode, root: MApp) => {
39
40
  left: number;
40
41
  top: number;