@tmagic/editor 1.1.0-beta.10 → 1.1.0-beta.11

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.1.0-beta.10",
2
+ "version": "1.1.0-beta.11",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -45,11 +45,11 @@
45
45
  "dependencies": {
46
46
  "@babel/core": "^7.18.0",
47
47
  "@element-plus/icons-vue": "^2.0.6",
48
- "@tmagic/core": "1.1.0-beta.10",
49
- "@tmagic/form": "1.1.0-beta.10",
50
- "@tmagic/schema": "1.1.0-beta.10",
51
- "@tmagic/stage": "1.1.0-beta.10",
52
- "@tmagic/utils": "1.1.0-beta.10",
48
+ "@tmagic/core": "1.1.0-beta.11",
49
+ "@tmagic/form": "1.1.0-beta.11",
50
+ "@tmagic/schema": "1.1.0-beta.11",
51
+ "@tmagic/stage": "1.1.0-beta.11",
52
+ "@tmagic/utils": "1.1.0-beta.11",
53
53
  "buffer": "^6.0.3",
54
54
  "color": "^3.1.3",
55
55
  "element-plus": "^2.2.6",
@@ -62,7 +62,7 @@
62
62
  "vue": "^3.2.37"
63
63
  },
64
64
  "peerDependencies": {
65
- "@tmagic/form": "1.1.0-beta.10",
65
+ "@tmagic/form": "1.1.0-beta.11",
66
66
  "element-plus": "^2.2.6",
67
67
  "monaco-editor": "^0.32.1",
68
68
  "vue": "^3.2.37"
@@ -3,8 +3,8 @@
3
3
  <el-button type="danger" :icon="Delete" text style="padding: 0">取消</el-button>
4
4
  </div>
5
5
  <div class="m-fields-ui-select" v-else @click="startSelect" style="display: flex">
6
- <el-tooltip content="清除">
7
- <el-button v-if="val" style="padding: 0" type="danger" :icon="Close" text @click.stop="deleteHandler"></el-button>
6
+ <el-tooltip v-if="val" content="清除">
7
+ <el-button style="padding: 0" type="danger" :icon="Close" text @click.stop="deleteHandler"></el-button>
8
8
  </el-tooltip>
9
9
  <el-tooltip :content="val ? toName + '_' + val : '点击此处选择'">
10
10
  <el-button text style="padding: 0; margin: 0">{{ val ? toName + '_' + val : '点击此处选择' }}</el-button>
@@ -15,6 +15,7 @@
15
15
  v-if="values.length"
16
16
  ref="tree"
17
17
  node-key="id"
18
+ empty-text="页面空荡荡的"
18
19
  draggable
19
20
  :default-expanded-keys="expandedKeys"
20
21
  :load="loadItems"
@@ -29,7 +30,8 @@
29
30
  @node-click="clickHandler"
30
31
  @node-contextmenu="contextmenu"
31
32
  @node-drag-end="handleDragEnd"
32
- empty-text="页面空荡荡的"
33
+ @node-collapse="handleCollapse"
34
+ @node-expand="handleExpand"
33
35
  >
34
36
  <template #default="{ node, data }">
35
37
  <div
@@ -60,7 +62,7 @@ import { computed, defineComponent, inject, Ref, ref, watchEffect } from 'vue';
60
62
  import type { ElTree } from 'element-plus';
61
63
  import { throttle } from 'lodash-es';
62
64
 
63
- import type { MNode, MPage } from '@tmagic/schema';
65
+ import type { Id, MNode, MPage } from '@tmagic/schema';
64
66
  import { MContainer, NodeType } from '@tmagic/schema';
65
67
  import StageCore from '@tmagic/stage';
66
68
 
@@ -122,22 +124,41 @@ const useDrop = (tree: Ref<InstanceType<typeof ElTree> | undefined>, editorServi
122
124
  });
123
125
 
124
126
  const useStatus = (tree: Ref<InstanceType<typeof ElTree> | undefined>, editorService?: EditorService) => {
125
- const highlightNode = ref<MNode>();
126
127
  const node = ref<MNode>();
127
128
  const page = computed(() => editorService?.get('page'));
129
+ const expandedKeys = new Map<Id, Id>();
130
+
131
+ const expandNodes = () => {
132
+ expandedKeys.forEach((key) => {
133
+ if (!tree.value) return;
134
+ tree.value.getNode(key)?.expand();
135
+ });
136
+ };
128
137
 
129
138
  watchEffect(() => {
130
139
  if (!tree.value) return;
131
- node.value = editorService?.get('node');
132
- node.value && tree.value.setCurrentKey(node.value.id, true);
140
+ if (!editorService) return;
141
+ node.value = editorService.get('node');
142
+
143
+ if (!node.value) return;
133
144
 
134
- const parent = editorService?.get('parent');
145
+ tree.value.setCurrentKey(node.value.id, true);
146
+
147
+ const parent = editorService.get('parent');
135
148
  if (!parent?.id) return;
136
149
 
137
150
  const treeNode = tree.value.getNode(parent.id);
138
151
  treeNode?.updateChildren();
139
152
 
140
- highlightNode.value = editorService?.get('highlightNode');
153
+ setTimeout(() => {
154
+ tree.value &&
155
+ Object.entries(tree.value.store.nodesMap).forEach(([id, node]) => {
156
+ if (node.expanded && node.data.items) {
157
+ expandedKeys.set(id, id);
158
+ }
159
+ });
160
+ expandNodes();
161
+ });
141
162
  });
142
163
 
143
164
  return {
@@ -153,9 +174,19 @@ const useStatus = (tree: Ref<InstanceType<typeof ElTree> | undefined>, editorSer
153
174
  resolve([]);
154
175
  },
155
176
 
156
- highlightNode,
177
+ highlightNode: computed(() => editorService?.get('highlightNode')),
157
178
  clickNode: node,
158
179
  expandedKeys: computed(() => (node.value ? [node.value.id] : [])),
180
+
181
+ handleCollapse: (data: MNode) => {
182
+ expandedKeys.delete(data.id);
183
+ },
184
+
185
+ handleExpand: (data: MNode) => {
186
+ const parent = editorService?.getParentById(data.id);
187
+ if (!parent?.id) return;
188
+ expandedKeys.set(parent.id, parent.id);
189
+ },
159
190
  };
160
191
  };
161
192
 
@@ -1,5 +1,5 @@
1
1
  import { Ref } from 'vue';
2
- import type { MNode } from '@tmagic/schema';
2
+ import type { Id, MNode } from '@tmagic/schema';
3
3
  declare const _default: import("vue").DefineComponent<{}, {
4
4
  highlightHandler: import("lodash-es").DebouncedFunc<(data: MNode) => void>;
5
5
  toggleClickFlag: () => void;
@@ -13,9 +13,11 @@ declare const _default: import("vue").DefineComponent<{}, {
13
13
  handleDragEnd(e: any): Promise<void>;
14
14
  values: import("vue").ComputedRef<MNode[]>;
15
15
  loadItems: (node: any, resolve: Function) => any;
16
- highlightNode: Ref<MNode | undefined>;
16
+ highlightNode: import("vue").ComputedRef<MNode | undefined>;
17
17
  clickNode: Ref<MNode | undefined>;
18
- expandedKeys: import("vue").ComputedRef<import("@tmagic/schema").Id[]>;
18
+ expandedKeys: import("vue").ComputedRef<Id[]>;
19
+ handleCollapse: (data: MNode) => void;
20
+ handleExpand: (data: MNode) => void;
19
21
  tree: Ref<({
20
22
  $: import("vue").ComponentInternalInstance;
21
23
  $data: {};