@tmagic/editor 1.3.0-alpha.1 → 1.3.0-alpha.3

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.
Files changed (91) hide show
  1. package/dist/tmagic-editor.js +853 -516
  2. package/dist/tmagic-editor.js.map +1 -1
  3. package/dist/tmagic-editor.umd.cjs +853 -515
  4. package/dist/tmagic-editor.umd.cjs.map +1 -1
  5. package/package.json +17 -18
  6. package/src/Editor.vue +1 -1
  7. package/src/components/CodeDraftEditor.vue +5 -1
  8. package/src/components/ContentMenu.vue +5 -1
  9. package/src/components/FunctionEditor.vue +6 -1
  10. package/src/components/Icon.vue +5 -1
  11. package/src/components/Layout.vue +5 -1
  12. package/src/components/ScrollBar.vue +5 -1
  13. package/src/components/ScrollViewer.vue +5 -1
  14. package/src/components/SearchInput.vue +4 -0
  15. package/src/components/ToolButton.vue +5 -1
  16. package/src/fields/Code.vue +5 -1
  17. package/src/fields/CodeLink.vue +5 -1
  18. package/src/fields/CodeSelect.vue +6 -2
  19. package/src/fields/CodeSelectCol.vue +6 -2
  20. package/src/fields/DataSourceFields.vue +5 -1
  21. package/src/fields/DataSourceInput.vue +357 -0
  22. package/src/fields/EventSelect.vue +8 -3
  23. package/src/fields/KeyValue.vue +4 -0
  24. package/src/fields/UISelect.vue +5 -1
  25. package/src/icons/AppManageIcon.vue +5 -1
  26. package/src/icons/CodeIcon.vue +5 -1
  27. package/src/index.ts +3 -0
  28. package/src/initService.ts +67 -0
  29. package/src/layouts/AddPageBox.vue +5 -1
  30. package/src/layouts/CodeEditor.vue +5 -1
  31. package/src/layouts/Framework.vue +5 -1
  32. package/src/layouts/NavMenu.vue +5 -1
  33. package/src/layouts/PropsPanel.vue +5 -1
  34. package/src/layouts/Resizer.vue +5 -1
  35. package/src/layouts/sidebar/ComponentListPanel.vue +5 -1
  36. package/src/layouts/sidebar/LayerMenu.vue +5 -1
  37. package/src/layouts/sidebar/LayerPanel.vue +5 -1
  38. package/src/layouts/sidebar/Sidebar.vue +11 -7
  39. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +5 -1
  40. package/src/layouts/sidebar/code-block/CodeBlockList.vue +5 -1
  41. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +4 -0
  42. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +4 -0
  43. package/src/layouts/workspace/Breadcrumb.vue +5 -1
  44. package/src/layouts/workspace/PageBar.vue +5 -1
  45. package/src/layouts/workspace/PageBarScrollContainer.vue +5 -1
  46. package/src/layouts/workspace/Stage.vue +5 -1
  47. package/src/layouts/workspace/ViewerMenu.vue +5 -1
  48. package/src/layouts/workspace/Workspace.vue +5 -1
  49. package/src/services/dep.ts +3 -0
  50. package/types/Editor.vue.d.ts +1 -1
  51. package/types/components/CodeDraftEditor.vue.d.ts +6 -3
  52. package/types/components/ContentMenu.vue.d.ts +8 -5
  53. package/types/components/FunctionEditor.vue.d.ts +66 -45
  54. package/types/components/Icon.vue.d.ts +2 -2
  55. package/types/components/Layout.vue.d.ts +9 -6
  56. package/types/components/ScrollBar.vue.d.ts +1 -1
  57. package/types/components/ScrollViewer.vue.d.ts +8 -5
  58. package/types/components/SearchInput.vue.d.ts +1 -1
  59. package/types/components/ToolButton.vue.d.ts +8 -5
  60. package/types/fields/Code.vue.d.ts +1 -1
  61. package/types/fields/CodeLink.vue.d.ts +9 -9
  62. package/types/fields/CodeSelect.vue.d.ts +10 -7
  63. package/types/fields/CodeSelectCol.vue.d.ts +8 -5
  64. package/types/fields/DataSourceFields.vue.d.ts +8 -5
  65. package/types/fields/DataSourceInput.vue.d.ts +54 -0
  66. package/types/fields/EventSelect.vue.d.ts +3 -3
  67. package/types/fields/KeyValue.vue.d.ts +8 -5
  68. package/types/fields/UISelect.vue.d.ts +1 -1
  69. package/types/icons/AppManageIcon.vue.d.ts +1 -1
  70. package/types/icons/CodeIcon.vue.d.ts +1 -1
  71. package/types/index.d.ts +1 -0
  72. package/types/layouts/AddPageBox.vue.d.ts +1 -1
  73. package/types/layouts/CodeEditor.vue.d.ts +7 -4
  74. package/types/layouts/Framework.vue.d.ts +13 -10
  75. package/types/layouts/NavMenu.vue.d.ts +7 -4
  76. package/types/layouts/PropsPanel.vue.d.ts +2 -2
  77. package/types/layouts/Resizer.vue.d.ts +2 -2
  78. package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +4 -4
  79. package/types/layouts/sidebar/LayerMenu.vue.d.ts +2 -2
  80. package/types/layouts/sidebar/LayerPanel.vue.d.ts +5 -5
  81. package/types/layouts/sidebar/Sidebar.vue.d.ts +18 -15
  82. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +4 -4
  83. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +7 -7
  84. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +1 -1
  85. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +3 -3
  86. package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -1
  87. package/types/layouts/workspace/PageBar.vue.d.ts +5 -5
  88. package/types/layouts/workspace/PageBarScrollContainer.vue.d.ts +2 -2
  89. package/types/layouts/workspace/Stage.vue.d.ts +2 -2
  90. package/types/layouts/workspace/ViewerMenu.vue.d.ts +7 -4
  91. package/types/layouts/workspace/Workspace.vue.d.ts +8 -8
@@ -0,0 +1,357 @@
1
+ <template>
2
+ <component
3
+ v-if="disabled || isFocused"
4
+ :is="getConfig('components')?.autocomplete.component || 'el-autocomplete'"
5
+ class="tmagic-design-auto-complete"
6
+ ref="autocomplete"
7
+ v-model="state"
8
+ v-bind="
9
+ getConfig('components')?.autocomplete.props({
10
+ disabled,
11
+ size,
12
+ fetchSuggestions: querySearch,
13
+ triggerOnFocus: false,
14
+ clearable: true,
15
+ }) || {}
16
+ "
17
+ style="width: 100%"
18
+ @blur="blurHandler"
19
+ @change="changeHandler"
20
+ @input="inputHandler"
21
+ @select="selectHandler"
22
+ >
23
+ <template #suffix>
24
+ <Icon :icon="Coin" />
25
+ </template>
26
+ <template #default="{ item }">
27
+ <div style="display: flex; flex-direction: column; line-height: 1.2em">
28
+ <div>{{ item.text }}</div>
29
+ <span style="font-size: 10px; color: rgba(0, 0, 0, 0.6)">{{ item.value }}</span>
30
+ </div>
31
+ </template>
32
+ </component>
33
+ <div :class="`el-input el-input--${size}`" @mouseup="mouseupHandler" v-else>
34
+ <div :class="`el-input__wrapper ${isFocused ? ' is-focus' : ''}`">
35
+ <div class="el-input__inner">
36
+ <template v-for="(item, index) in displayState">
37
+ <span :key="index" v-if="item.type === 'text'" style="margin-right: 2px">{{ item.value }}</span>
38
+ <TMagicTag :key="index" :size="size" v-if="item.type === 'var'">{{ item.value }}</TMagicTag>
39
+ </template>
40
+ </div>
41
+ </div>
42
+ </div>
43
+ </template>
44
+
45
+ <script setup lang="ts">
46
+ import { computed, inject, nextTick, ref, watch } from 'vue';
47
+ import { Coin } from '@element-plus/icons-vue';
48
+
49
+ import { FieldSize, getConfig, TMagicAutocomplete, TMagicTag } from '@tmagic/design';
50
+ import type { DataSchema, DataSourceSchema } from '@tmagic/schema';
51
+
52
+ import Icon from '@editor/components/Icon.vue';
53
+ import type { Services } from '@editor/type';
54
+
55
+ defineOptions({
56
+ name: 'MEditorDataSourceInput',
57
+ });
58
+
59
+ const props = withDefaults(
60
+ defineProps<{
61
+ config: {
62
+ type: 'data-source-input';
63
+ name: string;
64
+ text: string;
65
+ };
66
+ model: Record<string, any>;
67
+ name: string;
68
+ prop: string;
69
+ disabled: boolean;
70
+ lastValues?: Record<string, any>;
71
+ size?: FieldSize;
72
+ }>(),
73
+ {
74
+ disabled: false,
75
+ },
76
+ );
77
+
78
+ const emit = defineEmits<(e: 'change', value: string) => void>();
79
+
80
+ const { dataSourceService } = inject<Services>('services') || {};
81
+
82
+ const autocomplete = ref<InstanceType<typeof TMagicAutocomplete>>();
83
+ const isFocused = ref(false);
84
+ const state = ref('');
85
+ const displayState = ref<{ value: string; type: 'var' | 'text' }[]>([]);
86
+
87
+ const input = computed<HTMLInputElement>(() => autocomplete.value?.inputRef?.input);
88
+ const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
89
+
90
+ const setDisplayState = () => {
91
+ displayState.value = [];
92
+
93
+ const matches = state.value.matchAll(/\{\{([\s\S]+?)\}\}/g);
94
+ let index = 0;
95
+ for (const match of matches) {
96
+ if (typeof match.index === 'undefined') break;
97
+
98
+ displayState.value.push({
99
+ type: 'text',
100
+ value: state.value.substring(index, match.index),
101
+ });
102
+
103
+ let dsText = '';
104
+ let ds: DataSourceSchema | undefined;
105
+ let fields: DataSchema[] | undefined;
106
+
107
+ match[1].split('.').forEach((item, index) => {
108
+ if (index === 0) {
109
+ ds = dataSources.value.find((ds) => ds.id === item);
110
+ dsText += ds?.title || item;
111
+ fields = ds?.fields;
112
+ return;
113
+ }
114
+
115
+ const field = fields?.find((field) => field.name === item);
116
+ fields = field?.fields;
117
+ dsText += `.${field?.title || item}`;
118
+ });
119
+
120
+ displayState.value.push({
121
+ type: 'var',
122
+ value: dsText,
123
+ });
124
+
125
+ index = match.index + match[0].length;
126
+ }
127
+
128
+ if (index < state.value.length) {
129
+ displayState.value.push({
130
+ type: 'text',
131
+ value: state.value.substring(index),
132
+ });
133
+ }
134
+ };
135
+
136
+ watch(
137
+ () => props.model[props.name],
138
+ (value = '') => {
139
+ state.value = value;
140
+
141
+ setDisplayState();
142
+ },
143
+ { immediate: true },
144
+ );
145
+
146
+ const mouseupHandler = async () => {
147
+ isFocused.value = true;
148
+ await nextTick();
149
+ autocomplete.value?.focus();
150
+ };
151
+
152
+ const blurHandler = () => {
153
+ isFocused.value = false;
154
+
155
+ setDisplayState();
156
+ };
157
+
158
+ const changeHandler = (v: string) => {
159
+ emit('change', v);
160
+ };
161
+
162
+ let inputText = '';
163
+
164
+ const inputHandler = (v: string) => {
165
+ if (!v) {
166
+ inputText = v;
167
+ }
168
+ };
169
+
170
+ /**
171
+ * 光标位置是不是}
172
+ * @param selectionStart 光标位置
173
+ */
174
+ const isRightCurlyBracket = (selectionStart = 0) => {
175
+ const lastChar = inputText.substring(selectionStart - 1, selectionStart);
176
+ return lastChar === '}';
177
+ };
178
+
179
+ /**
180
+ * 获取光标位置
181
+ */
182
+ const getSelectionStart = () => {
183
+ let selectionStart = input.value?.selectionStart || 0;
184
+
185
+ // 输入法可能会自动补全},如果当前光标前面一个字符是},则光标前移一位
186
+ if (isRightCurlyBracket(selectionStart)) {
187
+ selectionStart -= 1;
188
+ }
189
+
190
+ return selectionStart;
191
+ };
192
+
193
+ /**
194
+ * 当前输入的是{
195
+ * @param leftCurlyBracketIndex {字符索引
196
+ */
197
+ const curCharIsLeftCurlyBracket = (leftCurlyBracketIndex: number) =>
198
+ leftCurlyBracketIndex > -1 && leftCurlyBracketIndex === getSelectionStart() - 1;
199
+
200
+ /**
201
+ * 当前输入的是.
202
+ * @param leftCurlyBracketIndex .字符索引
203
+ */
204
+ const curCharIsDot = (dotIndex: number) => dotIndex > -1 && dotIndex === getSelectionStart() - 1;
205
+
206
+ /**
207
+ * @param leftCurlyBracketIndex 左大括号字符索引
208
+ * @param cb 建议的方法
209
+ */
210
+ const dsQuerySearch = (queryString: string, leftCurlyBracketIndex: number, cb: (data: { value: string }[]) => void) => {
211
+ let result: DataSourceSchema[] = [];
212
+
213
+ if (curCharIsLeftCurlyBracket(leftCurlyBracketIndex)) {
214
+ // 当前输入的是{
215
+ result = dataSources.value;
216
+ } else if (leftCurlyBracketIndex > -1) {
217
+ // 当前输入的是{xx
218
+ const queryName = queryString.substring(leftCurlyBracketIndex + 1).toLowerCase();
219
+ result = dataSources.value.filter((ds) => ds.title?.toLowerCase().includes(queryName) || ds.id.includes(queryName));
220
+ }
221
+
222
+ cb(
223
+ result.map((ds) => ({
224
+ value: ds.id,
225
+ text: ds.title,
226
+ type: 'dataSource',
227
+ })),
228
+ );
229
+ };
230
+
231
+ /**
232
+ * 字段提示
233
+ * @param queryString 当前输入框内的字符串
234
+ * @param leftAngleIndex {字符索引
235
+ * @param dotIndex .字符索引
236
+ * @param cb 建议回调
237
+ */
238
+ const fieldQuerySearch = (
239
+ queryString: string,
240
+ leftAngleIndex: number,
241
+ dotIndex: number,
242
+ cb: (data: { value: string }[]) => void,
243
+ ) => {
244
+ let result: DataSchema[] = [];
245
+
246
+ const dsKey = queryString.substring(leftAngleIndex + 1, dotIndex);
247
+ // 可能是xx.xx.xx,存在链式调用
248
+ const keys = dsKey.split('.');
249
+ // 最前的是数据源id
250
+ const ds = dataSources.value.find((ds) => ds.id === keys.shift());
251
+ if (!ds) {
252
+ return;
253
+ }
254
+
255
+ let fields = ds.fields || [];
256
+
257
+ // 后面这些事字段
258
+ let key = keys.shift();
259
+ while (key) {
260
+ for (const field of fields) {
261
+ if (field.name === key) {
262
+ fields = field.fields || [];
263
+ key = keys.shift();
264
+ break;
265
+ }
266
+ }
267
+ }
268
+
269
+ if (curCharIsDot(dotIndex)) {
270
+ // 当前输入的是.
271
+ result = fields || [];
272
+ } else if (dotIndex > -1) {
273
+ const queryName = queryString.substring(dotIndex + 1).toLowerCase();
274
+ result =
275
+ fields.filter(
276
+ (field) => field.name?.toLowerCase().includes(queryName) || field.title?.toLowerCase().includes(queryName),
277
+ ) || [];
278
+ }
279
+
280
+ cb(
281
+ result.map((field) => ({
282
+ value: field.name,
283
+ text: field.title,
284
+ type: 'field',
285
+ })),
286
+ );
287
+ };
288
+
289
+ /**
290
+ * 数据源提示
291
+ * @param queryString 当前输入框内的字符串
292
+ * @param cb 建议回调
293
+ */
294
+ const querySearch = (queryString: string, cb: (data: { value: string }[]) => void) => {
295
+ inputText = queryString;
296
+
297
+ const selectionStart = getSelectionStart();
298
+
299
+ const curQueryString = queryString.substring(0, selectionStart);
300
+
301
+ const fieldKeyStringLastIndex = curQueryString.lastIndexOf('.');
302
+ const dsKeyStringLastIndex = curQueryString.lastIndexOf('{');
303
+
304
+ const isFieldTip = fieldKeyStringLastIndex > dsKeyStringLastIndex;
305
+
306
+ if (isFieldTip) {
307
+ fieldQuerySearch(curQueryString, dsKeyStringLastIndex, fieldKeyStringLastIndex, cb);
308
+ } else {
309
+ dsQuerySearch(curQueryString, dsKeyStringLastIndex, cb);
310
+ }
311
+ };
312
+
313
+ /**
314
+ * 选择建议
315
+ * @param value 建议值
316
+ * @param type 建议类型,是数据源还是字段
317
+ */
318
+ const selectHandler = async ({ value, type }: { value: string; type: 'dataSource' | 'field' }) => {
319
+ const isDataSource = type === 'dataSource';
320
+ const selectionStart = input.value?.selectionStart || 0;
321
+ let startText = inputText.substring(0, selectionStart);
322
+
323
+ const dotIndex = startText.lastIndexOf('.');
324
+ const leftCurlyBracketIndex = startText.lastIndexOf('{');
325
+
326
+ const endText = inputText.substring(selectionStart);
327
+
328
+ let suggestText = value;
329
+
330
+ if (isDataSource) {
331
+ if (!curCharIsLeftCurlyBracket(leftCurlyBracketIndex)) {
332
+ startText = startText.substring(0, leftCurlyBracketIndex + 1);
333
+ }
334
+
335
+ // 当前光标后一位是否为},不是的话需要补上
336
+ if (!isRightCurlyBracket(selectionStart + 1)) {
337
+ suggestText = `${suggestText}}`;
338
+ }
339
+ suggestText = `{${suggestText}}`;
340
+ } else if (!curCharIsDot(dotIndex)) {
341
+ startText = startText.substring(0, dotIndex + 1);
342
+ }
343
+
344
+ state.value = `${startText}${suggestText}${endText}`;
345
+
346
+ await nextTick();
347
+
348
+ // 由于选择数据源时会在后面补全}}, 所以光标要前移2位
349
+ let newSelectionStart = 0;
350
+ if (isDataSource) {
351
+ newSelectionStart = leftCurlyBracketIndex + suggestText.length - 1;
352
+ } else {
353
+ newSelectionStart = dotIndex + suggestText.length + 1;
354
+ }
355
+ input.value?.setSelectionRange(newSelectionStart, newSelectionStart);
356
+ };
357
+ </script>
@@ -33,8 +33,8 @@
33
33
  </div>
34
34
  </template>
35
35
 
36
- <script lang="ts" setup name="MEditorEventSelect">
37
- import { computed, defineProps, inject } from 'vue';
36
+ <script lang="ts" setup>
37
+ import { computed, inject } from 'vue';
38
38
  import { Delete } from '@element-plus/icons-vue';
39
39
  import { has } from 'lodash-es';
40
40
 
@@ -44,7 +44,9 @@ import { ActionType } from '@tmagic/schema';
44
44
 
45
45
  import type { EventSelectConfig, Services } from '@editor/type';
46
46
 
47
- const services = inject<Services>('services');
47
+ defineOptions({
48
+ name: 'MEditorEventSelect',
49
+ });
48
50
 
49
51
  const props = defineProps<{
50
52
  config: EventSelectConfig;
@@ -53,8 +55,11 @@ const props = defineProps<{
53
55
  name: string;
54
56
  size: 'small' | 'default' | 'large';
55
57
  }>();
58
+
56
59
  const emit = defineEmits(['change']);
57
60
 
61
+ const services = inject<Services>('services');
62
+
58
63
  // 事件名称下拉框表单配置
59
64
  const eventNameConfig = computed(() => {
60
65
  const defaultEventNameConfig = {
@@ -38,6 +38,10 @@ import { Delete, Plus } from '@element-plus/icons-vue';
38
38
 
39
39
  import { TMagicButton, TMagicInput } from '@tmagic/design';
40
40
 
41
+ defineOptions({
42
+ name: 'MEditorKeyValue',
43
+ });
44
+
41
45
  const props = withDefaults(
42
46
  defineProps<{
43
47
  config: {
@@ -12,7 +12,7 @@
12
12
  </div>
13
13
  </template>
14
14
 
15
- <script lang="ts" setup name="MEditorUISelect">
15
+ <script lang="ts" setup>
16
16
  import { computed, inject, ref } from 'vue';
17
17
  import { Close, Delete } from '@element-plus/icons-vue';
18
18
 
@@ -21,6 +21,10 @@ import { FormState } from '@tmagic/form';
21
21
 
22
22
  import type { Services } from '@editor/type';
23
23
 
24
+ defineOptions({
25
+ name: 'MEditorUISelect',
26
+ });
27
+
24
28
  const props = defineProps<{
25
29
  config: any;
26
30
  model: any;
@@ -8,4 +8,8 @@
8
8
  </svg>
9
9
  </template>
10
10
 
11
- <script lang="ts" setup name="MEditorAppManageIcon"></script>
11
+ <script lang="ts" setup>
12
+ defineOptions({
13
+ name: 'MEditorAppManageIcon',
14
+ });
15
+ </script>
@@ -23,4 +23,8 @@
23
23
  </svg>
24
24
  </template>
25
25
 
26
- <script lang="ts" setup name="MEditorCodeIcon"></script>
26
+ <script lang="ts" setup>
27
+ defineOptions({
28
+ name: 'MEditorCodeIcon',
29
+ });
30
+ </script>
package/src/index.ts CHANGED
@@ -22,6 +22,7 @@ import CodeLink from './fields/CodeLink.vue';
22
22
  import CodeSelect from './fields/CodeSelect.vue';
23
23
  import CodeSelectCol from './fields/CodeSelectCol.vue';
24
24
  import DataSourceFields from './fields/DataSourceFields.vue';
25
+ import DataSourceInput from './fields/DataSourceInput.vue';
25
26
  import EventSelect from './fields/EventSelect.vue';
26
27
  import KeyValue from './fields/KeyValue.vue';
27
28
  import uiSelect from './fields/UISelect.vue';
@@ -51,6 +52,7 @@ export { default as LayerPanel } from './layouts/sidebar/LayerPanel.vue';
51
52
  export { default as CodeSelect } from './fields/CodeSelect.vue';
52
53
  export { default as CodeSelectCol } from './fields/CodeSelectCol.vue';
53
54
  export { default as DataSourceFields } from './fields/DataSourceFields.vue';
55
+ export { default as DataSourceInput } from './fields/DataSourceInput.vue';
54
56
  export { default as EventSelect } from './fields/EventSelect.vue';
55
57
  export { default as KeyValue } from './fields/KeyValue.vue';
56
58
  export { default as CodeBlockList } from './layouts/sidebar/code-block/CodeBlockList.vue';
@@ -81,5 +83,6 @@ export default {
81
83
  app.component('m-fields-event-select', EventSelect);
82
84
  app.component('m-fields-data-source-fields', DataSourceFields);
83
85
  app.component('m-fields-key-value', KeyValue);
86
+ app.component('m-fields-data-source-input', DataSourceInput);
84
87
  },
85
88
  };
@@ -1,8 +1,10 @@
1
1
  import type { ExtractPropTypes } from 'vue';
2
2
  import { onUnmounted, toRaw, watch } from 'vue';
3
+ import { cloneDeep } from 'lodash-es';
3
4
 
4
5
  import type { EventOption } from '@tmagic/core';
5
6
  import type { CodeBlockContent, DataSourceSchema, Id, MApp, MNode, MPage } from '@tmagic/schema';
7
+ import { getNodes } from '@tmagic/utils';
6
8
 
7
9
  import type { Target } from './services/dep';
8
10
  import { createCodeBlockTarget, createDataSourceTarget } from './utils/dep';
@@ -110,6 +112,50 @@ export const initServiceEvents = (
110
112
  emit: (event: 'props-panel-mounted' | 'update:modelValue', ...args: any[]) => void,
111
113
  { editorService, codeBlockService, dataSourceService, depService }: Services,
112
114
  ) => {
115
+ const getApp = () => {
116
+ const stage = editorService.get('stage');
117
+ return stage?.renderer.runtime?.getApp?.();
118
+ };
119
+
120
+ const updateDataSoucreSchema = () => {
121
+ const root = editorService.get('root');
122
+
123
+ if (root?.dataSources) {
124
+ getApp()?.dataSourceManager?.updateSchema(root.dataSources);
125
+ }
126
+ };
127
+
128
+ const upateNodeWhenDataSourceChange = (nodes: MNode[]) => {
129
+ const root = editorService.get('root');
130
+ const stage = editorService.get('stage');
131
+
132
+ if (!root || !stage) return;
133
+
134
+ const app = getApp();
135
+
136
+ if (!app) return;
137
+
138
+ if (app.dsl) {
139
+ app.dsl.dataSourceDeps = root.dataSourceDeps;
140
+ app.dsl.dataSources = root.dataSources;
141
+ }
142
+
143
+ updateDataSoucreSchema();
144
+
145
+ nodes.forEach((node) => {
146
+ const deps = Object.values(root.dataSourceDeps || {});
147
+ deps.forEach((dep) => {
148
+ if (dep[node.id]) {
149
+ stage.update({
150
+ config: cloneDeep(node),
151
+ parentId: editorService.getParentById(node.id)?.id,
152
+ root: cloneDeep(root),
153
+ });
154
+ }
155
+ });
156
+ });
157
+ };
158
+
113
159
  const targetAddHandler = (target: Target) => {
114
160
  if (target.type !== 'data-source') return;
115
161
 
@@ -130,8 +176,18 @@ export const initServiceEvents = (
130
176
  delete root.dataSourceDeps[id];
131
177
  };
132
178
 
179
+ const depUpdateHandler = (node: MNode) => {
180
+ upateNodeWhenDataSourceChange([node]);
181
+ };
182
+
183
+ const collectedHandler = (nodes: MNode[]) => {
184
+ upateNodeWhenDataSourceChange(nodes);
185
+ };
186
+
133
187
  depService.on('add-target', targetAddHandler);
134
188
  depService.on('remove-target', targetRemoveHandler);
189
+ depService.on('dep-update', depUpdateHandler);
190
+ depService.on('collected', collectedHandler);
135
191
 
136
192
  const rootChangeHandler = async (value: MApp, preValue?: MApp | null) => {
137
193
  const nodeId = editorService.get('node')?.id || props.defaultSelected;
@@ -218,16 +274,25 @@ export const initServiceEvents = (
218
274
 
219
275
  const dataSourceAddHandler = (config: DataSourceSchema) => {
220
276
  depService.addTarget(createDataSourceTarget(config.id, config));
277
+ getApp()?.dataSourceManager?.addDataSource(config);
221
278
  };
222
279
 
223
280
  const dataSourceUpdateHandler = (config: DataSourceSchema) => {
224
281
  if (config.title) {
225
282
  depService.getTarget(config.id)!.name = config.title;
226
283
  }
284
+ const root = editorService.get('root');
285
+
286
+ const targets = depService.getTargets('data-source');
287
+
288
+ const nodes = getNodes(Object.keys(targets[config.id].deps), root?.items);
289
+
290
+ upateNodeWhenDataSourceChange(nodes);
227
291
  };
228
292
 
229
293
  const dataSourceRemoveHandler = (id: string) => {
230
294
  depService.removeTarget(id);
295
+ getApp()?.dataSourceManager?.removeDataSource(id);
231
296
  };
232
297
 
233
298
  dataSourceService.on('add', dataSourceAddHandler);
@@ -237,6 +302,8 @@ export const initServiceEvents = (
237
302
  onUnmounted(() => {
238
303
  depService.off('add-target', targetAddHandler);
239
304
  depService.off('remove-target', targetRemoveHandler);
305
+ depService.off('dep-update', depUpdateHandler);
306
+ depService.off('collected', collectedHandler);
240
307
 
241
308
  editorService.off('history-change', historyChangeHandler);
242
309
  editorService.off('root-change', rootChangeHandler);
@@ -11,7 +11,7 @@
11
11
  </div>
12
12
  </template>
13
13
 
14
- <script lang="ts" setup name="MEditorAddPageBox">
14
+ <script lang="ts" setup>
15
15
  import { inject, toRaw } from 'vue';
16
16
  import { Plus } from '@element-plus/icons-vue';
17
17
 
@@ -21,6 +21,10 @@ import MIcon from '@editor/components/Icon.vue';
21
21
  import type { Services } from '@editor/type';
22
22
  import { generatePageNameByApp } from '@editor/utils';
23
23
 
24
+ defineOptions({
25
+ name: 'MEditorAddPageBox',
26
+ });
27
+
24
28
  const services = inject<Services>('services');
25
29
 
26
30
  const clickHandler = () => {
@@ -2,12 +2,16 @@
2
2
  <div ref="codeEditor" class="magic-code-editor"></div>
3
3
  </template>
4
4
 
5
- <script lang="ts" setup name="MEditorCodeEditor">
5
+ <script lang="ts" setup>
6
6
  import { onMounted, onUnmounted, ref, watch } from 'vue';
7
7
  import { throttle } from 'lodash-es';
8
8
  import * as monaco from 'monaco-editor';
9
9
  import serialize from 'serialize-javascript';
10
10
 
11
+ defineOptions({
12
+ name: 'MEditorCodeEditor',
13
+ });
14
+
11
15
  const props = withDefaults(
12
16
  defineProps<{
13
17
  initValues?: string | Object;
@@ -42,7 +42,7 @@
42
42
  </div>
43
43
  </template>
44
44
 
45
- <script lang="ts" setup name="MEditorFramework">
45
+ <script lang="ts" setup>
46
46
  import { computed, inject, ref, watch } from 'vue';
47
47
 
48
48
  import { TMagicScrollbar } from '@tmagic/design';
@@ -52,6 +52,10 @@ import type { GetColumnWidth, Services } from '@editor/type';
52
52
 
53
53
  import AddPageBox from './AddPageBox.vue';
54
54
 
55
+ defineOptions({
56
+ name: 'MEditorFramework',
57
+ });
58
+
55
59
  const DEFAULT_LEFT_COLUMN_WIDTH = 310;
56
60
  const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
57
61
 
@@ -6,7 +6,7 @@
6
6
  </div>
7
7
  </template>
8
8
 
9
- <script lang="ts" setup name="MEditorNavMenu">
9
+ <script lang="ts" setup>
10
10
  import { computed, inject, markRaw } from 'vue';
11
11
  import { Back, Delete, FullScreen, Grid, Memo, Right, ScaleToOriginal, ZoomIn, ZoomOut } from '@element-plus/icons-vue';
12
12
 
@@ -15,6 +15,10 @@ import { NodeType } from '@tmagic/schema';
15
15
  import ToolButton from '@editor/components/ToolButton.vue';
16
16
  import { ColumnLayout, MenuBarData, MenuButton, MenuComponent, MenuItem, Services } from '@editor/type';
17
17
 
18
+ defineOptions({
19
+ name: 'MEditorNavMenu',
20
+ });
21
+
18
22
  const props = withDefaults(
19
23
  defineProps<{
20
24
  data?: MenuBarData;
@@ -13,7 +13,7 @@
13
13
  </div>
14
14
  </template>
15
15
 
16
- <script lang="ts" setup name="MEditorPropsPanel">
16
+ <script lang="ts" setup>
17
17
  import { computed, getCurrentInstance, inject, onMounted, onUnmounted, ref, watchEffect } from 'vue';
18
18
 
19
19
  import { tMagicMessage } from '@tmagic/design';
@@ -22,6 +22,10 @@ import { MForm } from '@tmagic/form';
22
22
 
23
23
  import type { Services } from '@editor/type';
24
24
 
25
+ defineOptions({
26
+ name: 'MEditorPropsPanel',
27
+ });
28
+
25
29
  const emit = defineEmits(['mounted']);
26
30
 
27
31
  const internalInstance = getCurrentInstance();
@@ -4,10 +4,14 @@
4
4
  </span>
5
5
  </template>
6
6
 
7
- <script lang="ts" setup name="MEditorResizer">
7
+ <script lang="ts" setup>
8
8
  import { onMounted, onUnmounted, ref } from 'vue';
9
9
  import Gesto from 'gesto';
10
10
 
11
+ defineOptions({
12
+ name: 'MEditorResizer',
13
+ });
14
+
11
15
  const emit = defineEmits(['change']);
12
16
 
13
17
  const target = ref<HTMLSpanElement>();