@tmagic/editor 1.2.0-beta.4 → 1.2.0-beta.6

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.4",
2
+ "version": "1.2.0-beta.6",
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.4",
49
- "@tmagic/design": "1.2.0-beta.4",
50
- "@tmagic/form": "1.2.0-beta.4",
51
- "@tmagic/schema": "1.2.0-beta.4",
52
- "@tmagic/stage": "1.2.0-beta.4",
53
- "@tmagic/utils": "1.2.0-beta.4",
48
+ "@tmagic/core": "1.2.0-beta.6",
49
+ "@tmagic/design": "1.2.0-beta.6",
50
+ "@tmagic/form": "1.2.0-beta.6",
51
+ "@tmagic/schema": "1.2.0-beta.6",
52
+ "@tmagic/stage": "1.2.0-beta.6",
53
+ "@tmagic/utils": "1.2.0-beta.6",
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.4",
66
- "@tmagic/form": "1.2.0-beta.4",
65
+ "@tmagic/design": "1.2.0-beta.6",
66
+ "@tmagic/form": "1.2.0-beta.6",
67
67
  "monaco-editor": "^0.34.0",
68
68
  "vue": "^3.2.37"
69
69
  },
@@ -10,7 +10,7 @@
10
10
  @save="saveCode"
11
11
  ></magic-code-editor>
12
12
 
13
- <layout
13
+ <Layout
14
14
  v-else
15
15
  class="m-editor-content"
16
16
  left-class="m-editor-framework-left"
@@ -29,21 +29,21 @@
29
29
  <template #center>
30
30
  <slot v-if="pageLength > 0" name="workspace"></slot>
31
31
  <slot v-else name="empty">
32
- <add-page-box></add-page-box>
32
+ <AddPageBox></AddPageBox>
33
33
  </slot>
34
34
  </template>
35
35
 
36
- <template v-if="pageLength > 0" #right>
36
+ <template v-if="pageLength > 0 && nodes.length === 1" #right>
37
37
  <TMagicScrollbar>
38
38
  <slot name="props-panel"></slot>
39
39
  </TMagicScrollbar>
40
40
  </template>
41
- </layout>
41
+ </Layout>
42
42
  </div>
43
43
  </template>
44
44
 
45
45
  <script lang="ts" setup>
46
- import { computed, inject, ref, watchEffect } from 'vue';
46
+ import { computed, inject, ref, watch } from 'vue';
47
47
 
48
48
  import { TMagicScrollbar } from '@tmagic/design';
49
49
  import type { MApp } from '@tmagic/schema';
@@ -68,27 +68,65 @@ withDefaults(
68
68
  const { editorService, uiService } = inject<Services>('services') || {};
69
69
 
70
70
  const root = computed(() => editorService?.get<MApp>('root'));
71
+ const nodes = computed(() => editorService?.get<Node[]>('nodes') || []);
71
72
 
72
73
  const pageLength = computed(() => editorService?.get<number>('pageLength') || 0);
73
74
  const showSrc = computed(() => uiService?.get<boolean>('showSrc'));
75
+
76
+ const LEFT_COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorLeftColumnWidthData';
77
+ const RIGHT_COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorRightColumnWidthData';
78
+
79
+ const leftColumnWidthCacheData = Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY));
80
+ const RightColumnWidthCacheData = Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY));
81
+
74
82
  const columnWidth = ref<Partial<GetColumnWidth>>({
75
- left: DEFAULT_LEFT_COLUMN_WIDTH,
83
+ left: leftColumnWidthCacheData,
76
84
  center: 0,
77
- right: 0,
78
- });
79
- uiService?.set('columnWidth', columnWidth.value);
80
-
81
- watchEffect(() => {
82
- if (pageLength.value <= 0) {
83
- columnWidth.value.right = undefined;
84
- columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH;
85
- } else {
86
- columnWidth.value.right = columnWidth.value.right || DEFAULT_RIGHT_COLUMN_WIDTH;
87
- columnWidth.value.center =
88
- globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH;
89
- }
85
+ right: RightColumnWidthCacheData,
90
86
  });
91
87
 
88
+ watch(
89
+ pageLength,
90
+ (length) => {
91
+ const left = columnWidth.value.left || DEFAULT_LEFT_COLUMN_WIDTH;
92
+
93
+ columnWidth.value.left = left;
94
+
95
+ if (length <= 0) {
96
+ columnWidth.value.right = undefined;
97
+ columnWidth.value.center = globalThis.document.body.clientWidth - left;
98
+ } else {
99
+ const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
100
+ columnWidth.value.right = right;
101
+ columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
102
+ }
103
+
104
+ uiService?.set('columnWidth', columnWidth);
105
+ },
106
+ {
107
+ immediate: true,
108
+ },
109
+ );
110
+
111
+ watch(
112
+ () => columnWidth.value.right,
113
+ (right) => {
114
+ if (typeof right === 'undefined') return;
115
+ globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${right}`);
116
+ },
117
+ );
118
+
119
+ watch(
120
+ () => columnWidth.value.left,
121
+ (left) => {
122
+ globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${left}`);
123
+ },
124
+ );
125
+
126
+ const columnWidthChange = (columnWidth: GetColumnWidth) => {
127
+ uiService?.set('columnWidth', columnWidth);
128
+ };
129
+
92
130
  const saveCode = (value: string) => {
93
131
  try {
94
132
  // eslint-disable-next-line no-eval
@@ -97,21 +135,4 @@ const saveCode = (value: string) => {
97
135
  console.error(e);
98
136
  }
99
137
  };
100
-
101
- const COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorColumnWidthData';
102
-
103
- const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
104
- if (columnWidthCacheData) {
105
- try {
106
- const columnWidthCache = JSON.parse(columnWidthCacheData);
107
- columnWidth.value = columnWidthCache;
108
- } catch (e) {
109
- console.error(e);
110
- }
111
- }
112
-
113
- const columnWidthChange = (columnWidth: GetColumnWidth) => {
114
- uiService?.set('columnWidth', columnWidth);
115
- globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
116
- };
117
138
  </script>
@@ -74,8 +74,13 @@ const center = ref(0);
74
74
 
75
75
  const changeLeft = (deltaX: number) => {
76
76
  if (typeof props.left === 'undefined') return;
77
- const left = Math.max(props.left + deltaX, props.minLeft) || 0;
77
+ let left = Math.max(props.left + deltaX, props.minLeft) || 0;
78
78
  emit('update:left', left);
79
+
80
+ if (clientWidth - left - (props.right || 0) <= 0) {
81
+ left = props.left;
82
+ }
83
+
79
84
  center.value = clientWidth - left - (props.right || 0);
80
85
 
81
86
  emit('change', {
@@ -87,8 +92,13 @@ const changeLeft = (deltaX: number) => {
87
92
 
88
93
  const changeRight = (deltaX: number) => {
89
94
  if (typeof props.right === 'undefined') return;
90
- const right = Math.max(props.right - deltaX, props.minRight) || 0;
95
+ let right = Math.max(props.right - deltaX, props.minRight) || 0;
91
96
  emit('update:right', right);
97
+
98
+ if (clientWidth - (props.left || 0) - right <= 0) {
99
+ right = props.right;
100
+ }
101
+
92
102
  center.value = clientWidth - (props.left || 0) - right;
93
103
 
94
104
  emit('change', {
@@ -4,11 +4,11 @@
4
4
 
5
5
  <TMagicCollapse class="ui-component-panel" :model-value="collapseValue">
6
6
  <TMagicInput
7
- prefix-icon="el-icon-search"
8
7
  placeholder="输入关键字进行过滤"
9
8
  class="search-input"
10
9
  size="small"
11
10
  clearable
11
+ :prefix-icon="Search"
12
12
  v-model="searchText"
13
13
  />
14
14
  <template v-for="(group, index) in list">
@@ -40,7 +40,7 @@
40
40
 
41
41
  <script lang="ts" setup>
42
42
  import { computed, inject, ref } from 'vue';
43
- import { Grid } from '@element-plus/icons-vue';
43
+ import { Grid, Search } from '@element-plus/icons-vue';
44
44
  import serialize from 'serialize-javascript';
45
45
 
46
46
  import { TMagicCollapse, TMagicCollapseItem, TMagicInput, TMagicScrollbar, TMagicTooltip } from '@tmagic/design';
@@ -7,16 +7,18 @@
7
7
  <slot name="layer-panel-header"></slot>
8
8
 
9
9
  <TMagicInput
10
- class="filterInput"
10
+ v-model="filterText"
11
+ class="search-input"
11
12
  size="small"
12
13
  placeholder="输入关键字进行过滤"
13
14
  clearable
14
- v-model="filterText"
15
+ :prefix-icon="Search"
15
16
  @change="filterTextChangeHandler"
16
17
  ></TMagicInput>
17
18
 
18
19
  <TMagicTree
19
20
  v-if="values.length"
21
+ class="magic-editor-layer-tree"
20
22
  ref="tree"
21
23
  node-key="id"
22
24
  empty-text="页面空荡荡的"
@@ -64,7 +66,8 @@
64
66
  </template>
65
67
 
66
68
  <script lang="ts" setup>
67
- import { computed, inject, ref, watch } from 'vue';
69
+ import { computed, inject, nextTick, ref, watch } from 'vue';
70
+ import { Search } from '@element-plus/icons-vue';
68
71
  import KeyController from 'keycon';
69
72
  import { throttle } from 'lodash-es';
70
73
 
@@ -204,8 +207,16 @@ const filterTextChangeHandler = (val: string) => {
204
207
  tree.value?.filter(val);
205
208
  };
206
209
 
207
- // 展开树节点
208
- const expandNodes = () => {
210
+ // 树节点更新后展开上次展开过的节点
211
+ const expandNodes = async () => {
212
+ if (!tree.value) return;
213
+ await nextTick();
214
+ tree.value &&
215
+ Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]: [string, any]) => {
216
+ if (node.expanded && node.data.items) {
217
+ expandedKeys.set(id, id);
218
+ }
219
+ });
209
220
  expandedKeys.forEach((key) => {
210
221
  if (!tree.value) return;
211
222
  tree.value.getNode(key)?.expand();
@@ -213,28 +224,9 @@ const expandNodes = () => {
213
224
  };
214
225
 
215
226
  watch(
216
- () => editorService?.get('nodes'),
227
+ () => editorService?.get<MNode[]>('nodes'),
217
228
  (nodes) => {
218
- if (!tree.value) return;
219
- if (!editorService) return;
220
- if (!nodes) return;
221
- selectedNodes.value = nodes as unknown as MNode[];
222
-
223
- const parent = editorService.get('parent');
224
- if (!parent?.id) return;
225
-
226
- const treeNode = tree.value.getNode(parent.id);
227
- treeNode?.updateChildren();
228
-
229
- setTimeout(() => {
230
- tree.value &&
231
- Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]: [string, any]) => {
232
- if (node.expanded && node.data.items) {
233
- expandedKeys.set(id, id);
234
- }
235
- });
236
- expandNodes();
237
- });
229
+ selectedNodes.value = nodes ?? [];
238
230
  },
239
231
  );
240
232
 
@@ -255,7 +247,16 @@ const setTreeKeyStatus = () => {
255
247
  }
256
248
  };
257
249
 
258
- watch(selectedIds, () => {
250
+ watch([selectedIds, tree], async () => {
251
+ if (!tree.value || !editorService) return;
252
+ const parent = editorService.get('parent');
253
+ if (!parent?.id) return;
254
+
255
+ const treeNode = tree.value.getNode(parent.id);
256
+ treeNode?.updateChildren();
257
+ await expandNodes();
258
+
259
+ // 设置高亮节点操作一定要在刷新展开状态之后,否则可能导致设置的高亮无效
259
260
  setTreeKeyStatus();
260
261
  });
261
262
 
@@ -484,10 +484,10 @@ class Editor extends BaseService {
484
484
  parentNodeItems[index] = newConfig;
485
485
 
486
486
  // 将update后的配置更新到nodes中
487
- const nodes = this.get('nodes');
487
+ const nodes = this.get<MNode[]>('nodes') || [];
488
488
  const targetIndex = nodes.findIndex((nodeItem: MNode) => `${nodeItem.id}` === `${newConfig.id}`);
489
489
  nodes.splice(targetIndex, 1, newConfig);
490
- this.set('nodes', nodes);
490
+ this.set('nodes', [...nodes]);
491
491
 
492
492
  this.get<StageCore | null>('stage')?.update({
493
493
  config: cloneDeep(newConfig),
@@ -1,11 +1,11 @@
1
1
  .ui-component-panel {
2
2
  height: 100%;
3
3
  border-top: 0 !important;
4
- margin-top: 50px;
4
+ margin-top: 48px;
5
5
  background-color: $--sidebar-content-background-color;
6
6
 
7
7
  .search-input {
8
- background: #f8fbff;
8
+ background: #fff;
9
9
  color: #bbbbbb;
10
10
  padding: 10px;
11
11
  position: absolute;
@@ -15,11 +15,7 @@
15
15
  z-index: 1;
16
16
 
17
17
  .el-input__prefix {
18
- padding: 10px;
19
- }
20
-
21
- .el-input__suffix {
22
- padding: 10px 5px;
18
+ padding: 7px;
23
19
  }
24
20
  }
25
21
 
@@ -10,10 +10,15 @@
10
10
  left: 0;
11
11
  z-index: 1;
12
12
 
13
- .el-input__suffix {
14
- padding: 10px 5px;
13
+ .el-input__prefix {
14
+ padding: 7px;
15
15
  }
16
16
  }
17
+
18
+ .magic-editor-layer-tree {
19
+ padding-top: 48px;
20
+ }
21
+
17
22
  .node-content {
18
23
  flex: 1;
19
24
  display: flex;
@@ -46,6 +46,7 @@ export const useStage = (stageOptions: StageOptions) => {
46
46
  ]);
47
47
 
48
48
  stage.on('select', (el: HTMLElement) => {
49
+ if (`${editorService.get('node')?.id}` === el.id) return;
49
50
  editorService.select(el.id);
50
51
  });
51
52
 
@@ -1,3 +1,4 @@
1
+ import { nextTick } from 'vue';
1
2
  declare const _default: {
2
3
  new (...args: any[]): {
3
4
  $: import("vue").ComponentInternalInstance;
@@ -34,7 +35,7 @@ declare const _default: {
34
35
  errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null, info: string) => boolean | void)[]) | undefined;
35
36
  };
36
37
  $forceUpdate: () => void;
37
- $nextTick: typeof import("vue").nextTick;
38
+ $nextTick: typeof nextTick;
38
39
  $watch(source: string | Function, cb: Function, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
39
40
  } & Readonly<import("vue").ExtractPropTypes<{}>> & import("vue").ShallowUnwrapRef<{}> & {} & import("vue").ComponentCustomProperties;
40
41
  __isFragment?: undefined;