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

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.2.0-beta.19",
2
+ "version": "1.2.0-beta.20",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -45,12 +45,12 @@
45
45
  "dependencies": {
46
46
  "@babel/core": "^7.18.0",
47
47
  "@element-plus/icons-vue": "^2.0.9",
48
- "@tmagic/core": "1.2.0-beta.19",
49
- "@tmagic/design": "1.2.0-beta.19",
50
- "@tmagic/form": "1.2.0-beta.19",
51
- "@tmagic/schema": "1.2.0-beta.19",
52
- "@tmagic/stage": "1.2.0-beta.19",
53
- "@tmagic/utils": "1.2.0-beta.19",
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",
54
54
  "buffer": "^6.0.3",
55
55
  "color": "^3.1.3",
56
56
  "events": "^3.3.0",
@@ -62,8 +62,8 @@
62
62
  "vue": "^3.2.37"
63
63
  },
64
64
  "peerDependencies": {
65
- "@tmagic/design": "1.2.0-beta.19",
66
- "@tmagic/form": "1.2.0-beta.19",
65
+ "@tmagic/design": "1.2.0-beta.20",
66
+ "@tmagic/form": "1.2.0-beta.20",
67
67
  "monaco-editor": "^0.34.0",
68
68
  "vue": "^3.2.37"
69
69
  },
package/src/Editor.vue CHANGED
@@ -224,15 +224,25 @@ export default defineComponent({
224
224
 
225
225
  setup(props, { emit }) {
226
226
  editorService.on('root-change', (value) => {
227
- const node = editorService.get<MNode | null>('node');
228
- const nodeId = node?.id || props.defaultSelected;
229
- if (nodeId && node !== value) {
230
- editorService.select(nodeId);
231
- } else {
227
+ const nodeId = editorService.get<MNode | null>('node')?.id || props.defaultSelected;
228
+ let node;
229
+ if (nodeId) {
230
+ node = editorService.getNodeById(nodeId);
231
+ }
232
+
233
+ if (node && node !== value) {
234
+ editorService.select(node.id);
235
+ } else if (value?.items?.length) {
236
+ editorService.select(value.items[0]);
237
+ } else if (value?.id) {
232
238
  editorService.set('nodes', [value]);
239
+ editorService.set('parent', null);
240
+ editorService.set('page', null);
233
241
  }
234
242
 
235
- emit('update:modelValue', toRaw(editorService.get('root')));
243
+ if (toRaw(value) !== toRaw(editorService.get('root'))) {
244
+ emit('update:modelValue', value);
245
+ }
236
246
  });
237
247
 
238
248
  // 初始值变化,重新设置节点信息
@@ -62,7 +62,7 @@ const zoom = computed(() => services?.uiService.get<number>('zoom') || 1);
62
62
  const node = computed(() => services?.editorService.get<MNode>('node'));
63
63
 
64
64
  watchEffect(() => {
65
- if (stage) return;
65
+ if (stage || !page.value) return;
66
66
 
67
67
  if (!stageContainer.value) return;
68
68
  if (!(stageOptions?.runtimeUrl || stageOptions?.render) || !root.value) return;
@@ -352,6 +352,9 @@ class Editor extends BaseService {
352
352
 
353
353
  const newNodes = await Promise.all(
354
354
  addNodes.map((node) => {
355
+ if (isPage(node)) {
356
+ return this.doAdd(node, this.get('root'));
357
+ }
355
358
  const parentNode = parent && typeof parent !== 'function' ? parent : getAddParent(node);
356
359
  if (!parentNode) throw new Error('未找到父元素');
357
360
  return this.doAdd(node, parentNode);
@@ -579,7 +582,7 @@ class Editor extends BaseService {
579
582
 
580
583
  const pasteConfigs = await this.doPaste(config, position);
581
584
 
582
- return this.add(pasteConfigs);
585
+ return this.add(pasteConfigs, this.get('parent'));
583
586
  }
584
587
 
585
588
  public async doPaste(config: MNode[], position: PastePosition = {}): Promise<MNode[]> {
@@ -21,3 +21,4 @@ export * from './props';
21
21
  export * from './logger';
22
22
  export * from './editor';
23
23
  export * from './stage';
24
+ export * from './operator';
@@ -3,3 +3,4 @@ export * from './props';
3
3
  export * from './logger';
4
4
  export * from './editor';
5
5
  export * from './stage';
6
+ export * from './operator';