@tmagic/editor 1.5.16 → 1.5.17

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.
@@ -13,7 +13,7 @@
13
13
  </template>
14
14
 
15
15
  <script lang="ts" setup>
16
- import type { FieldProps, FormItem } from '@tmagic/form';
16
+ import type { CodeConfig, FieldProps } from '@tmagic/form';
17
17
 
18
18
  import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
19
19
 
@@ -25,23 +25,9 @@ const emit = defineEmits<{
25
25
  change: [value: string | any];
26
26
  }>();
27
27
 
28
- withDefaults(
29
- defineProps<
30
- FieldProps<
31
- {
32
- language?: string;
33
- options?: {
34
- [key: string]: any;
35
- };
36
- height?: string;
37
- parse?: boolean;
38
- } & FormItem
39
- >
40
- >(),
41
- {
42
- disabled: false,
43
- },
44
- );
28
+ withDefaults(defineProps<FieldProps<CodeConfig>>(), {
29
+ disabled: false,
30
+ });
45
31
 
46
32
  const save = (v: string | any) => {
47
33
  emit('change', v);
@@ -6,7 +6,7 @@
6
6
  import { computed, reactive, watch } from 'vue';
7
7
  import serialize from 'serialize-javascript';
8
8
 
9
- import type { FieldProps, FormItem } from '@tmagic/form';
9
+ import type { CodeLinkConfig, FieldProps } from '@tmagic/form';
10
10
 
11
11
  import { getEditorConfig } from '@editor/utils/config';
12
12
 
@@ -14,15 +14,7 @@ defineOptions({
14
14
  name: 'MFieldsCodeLink',
15
15
  });
16
16
 
17
- const props = defineProps<
18
- FieldProps<
19
- {
20
- type: 'code-link';
21
- formTitle?: string;
22
- codeOptions?: Object;
23
- } & FormItem
24
- >
25
- >();
17
+ const props = defineProps<FieldProps<CodeLinkConfig>>();
26
18
 
27
19
  const emit = defineEmits(['change']);
28
20
 
@@ -21,7 +21,7 @@ import { isEmpty } from 'lodash-es';
21
21
 
22
22
  import { HookCodeType, HookType } from '@tmagic/core';
23
23
  import { TMagicCard } from '@tmagic/design';
24
- import type { ContainerChangeEventData, FieldProps, FormItem, GroupListConfig } from '@tmagic/form';
24
+ import type { CodeSelectConfig, ContainerChangeEventData, FieldProps, GroupListConfig } from '@tmagic/form';
25
25
  import { MContainer } from '@tmagic/form';
26
26
 
27
27
  import { useServices } from '@editor/hooks/use-services';
@@ -36,16 +36,7 @@ const emit = defineEmits<{
36
36
 
37
37
  const { dataSourceService, codeBlockService } = useServices();
38
38
 
39
- const props = withDefaults(
40
- defineProps<
41
- FieldProps<
42
- {
43
- className?: string;
44
- } & FormItem
45
- >
46
- >(),
47
- {},
48
- );
39
+ const props = withDefaults(defineProps<FieldProps<CodeSelectConfig>>(), {});
49
40
 
50
41
  const codeConfig = computed<GroupListConfig>(() => ({
51
42
  type: 'group-list',
@@ -42,6 +42,7 @@ import { isEmpty, map } from 'lodash-es';
42
42
  import type { Id } from '@tmagic/core';
43
43
  import { TMagicButton } from '@tmagic/design';
44
44
  import {
45
+ type CodeSelectColConfig,
45
46
  type ContainerChangeEventData,
46
47
  createValues,
47
48
  type FieldProps,
@@ -53,7 +54,7 @@ import {
53
54
  import CodeParams from '@editor/components/CodeParams.vue';
54
55
  import MIcon from '@editor/components/Icon.vue';
55
56
  import { useServices } from '@editor/hooks/use-services';
56
- import type { CodeParamStatement, CodeSelectColConfig, EventBus } from '@editor/type';
57
+ import type { CodeParamStatement, EventBus } from '@editor/type';
57
58
  import { SideItemKey } from '@editor/type';
58
59
 
59
60
  defineOptions({
@@ -30,10 +30,9 @@
30
30
  import { computed } from 'vue';
31
31
 
32
32
  import { getDesignConfig, TMagicSelect } from '@tmagic/design';
33
- import type { FieldProps } from '@tmagic/form';
33
+ import type { CondOpSelectConfig, FieldProps } from '@tmagic/form';
34
34
 
35
35
  import { useServices } from '@editor/hooks/use-services';
36
- import type { CondOpSelectConfig } from '@editor/type';
37
36
  import { arrayOptions, eqOptions, numberOptions } from '@editor/utils';
38
37
 
39
38
  defineOptions({
@@ -44,12 +44,11 @@ import { Coin } from '@element-plus/icons-vue';
44
44
 
45
45
  import { DataSchema } from '@tmagic/core';
46
46
  import { TMagicButton, tMagicMessage, TMagicTooltip } from '@tmagic/design';
47
- import type { ContainerChangeEventData, FieldProps, FormState } from '@tmagic/form';
47
+ import type { ContainerChangeEventData, DataSourceFieldSelectConfig, FieldProps, FormState } from '@tmagic/form';
48
48
  import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
49
49
 
50
50
  import MIcon from '@editor/components/Icon.vue';
51
51
  import { useServices } from '@editor/hooks/use-services';
52
- import type { DataSourceFieldSelectConfig } from '@editor/type';
53
52
  import { removeDataSourceFieldPrefix } from '@editor/utils';
54
53
 
55
54
  import FieldSelect from './FieldSelect.vue';
@@ -53,6 +53,7 @@ import type { DataSchema } from '@tmagic/core';
53
53
  import { TMagicButton, tMagicMessage, tMagicMessageBox } from '@tmagic/design';
54
54
  import {
55
55
  type ContainerChangeEventData,
56
+ type DataSourceFieldsConfig,
56
57
  type FieldProps,
57
58
  type FormConfig,
58
59
  type FormState,
@@ -71,16 +72,9 @@ defineOptions({
71
72
  name: 'MFieldsDataSourceFields',
72
73
  });
73
74
 
74
- const props = withDefaults(
75
- defineProps<
76
- FieldProps<{
77
- type: 'data-source-fields';
78
- }>
79
- >(),
80
- {
81
- disabled: false,
82
- },
83
- );
75
+ const props = withDefaults(defineProps<FieldProps<DataSourceFieldsConfig>>(), {
76
+ disabled: false,
77
+ });
84
78
 
85
79
  const emit = defineEmits<{
86
80
  change: [v: any, eventData?: ContainerChangeEventData];
@@ -53,7 +53,7 @@ import { Coin } from '@element-plus/icons-vue';
53
53
 
54
54
  import type { DataSchema, DataSourceSchema } from '@tmagic/core';
55
55
  import { getDesignConfig, TMagicAutocomplete, TMagicTag } from '@tmagic/design';
56
- import type { FieldProps, FormItem } from '@tmagic/form';
56
+ import type { DataSourceInputConfig, FieldProps } from '@tmagic/form';
57
57
  import { getKeysArray, isNumber } from '@tmagic/utils';
58
58
 
59
59
  import Icon from '@editor/components/Icon.vue';
@@ -64,18 +64,9 @@ defineOptions({
64
64
  name: 'MFieldsDataSourceInput',
65
65
  });
66
66
 
67
- const props = withDefaults(
68
- defineProps<
69
- FieldProps<
70
- {
71
- type: 'data-source-input';
72
- } & FormItem
73
- >
74
- >(),
75
- {
76
- disabled: false,
77
- },
78
- );
67
+ const props = withDefaults(defineProps<FieldProps<DataSourceInputConfig>>(), {
68
+ disabled: false,
69
+ });
79
70
 
80
71
  const emit = defineEmits<{
81
72
  change: [value: string];
@@ -39,6 +39,7 @@ import type { Id } from '@tmagic/core';
39
39
  import { TMagicButton, TMagicTooltip } from '@tmagic/design';
40
40
  import {
41
41
  createValues,
42
+ type DataSourceMethodSelectConfig,
42
43
  type FieldProps,
43
44
  filterFunction,
44
45
  type FormState,
@@ -49,7 +50,7 @@ import {
49
50
  import CodeParams from '@editor/components/CodeParams.vue';
50
51
  import MIcon from '@editor/components/Icon.vue';
51
52
  import { useServices } from '@editor/hooks/use-services';
52
- import type { CodeParamStatement, DataSourceMethodSelectConfig, EventBus } from '@editor/type';
53
+ import type { CodeParamStatement, EventBus } from '@editor/type';
53
54
  import { SideItemKey } from '@editor/type';
54
55
 
55
56
  defineOptions({
@@ -26,7 +26,7 @@ import { cloneDeep } from 'lodash-es';
26
26
 
27
27
  import type { CodeBlockContent } from '@tmagic/core';
28
28
  import { TMagicButton, tMagicMessageBox } from '@tmagic/design';
29
- import type { ContainerChangeEventData, FieldProps } from '@tmagic/form';
29
+ import type { ContainerChangeEventData, DataSourceMethodsConfig, FieldProps } from '@tmagic/form';
30
30
  import { type ColumnConfig, MagicTable } from '@tmagic/table';
31
31
 
32
32
  import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
@@ -37,16 +37,9 @@ defineOptions({
37
37
  name: 'MFieldsDataSourceMethods',
38
38
  });
39
39
 
40
- const props = withDefaults(
41
- defineProps<
42
- FieldProps<{
43
- type: 'data-source-methods';
44
- }>
45
- >(),
46
- {
47
- disabled: false,
48
- },
49
- );
40
+ const props = withDefaults(defineProps<FieldProps<DataSourceMethodsConfig>>(), {
41
+ disabled: false,
42
+ });
50
43
 
51
44
  const emit = defineEmits(['change']);
52
45
 
@@ -32,7 +32,7 @@ import { inject, Ref, ref } from 'vue';
32
32
 
33
33
  import type { MockSchema } from '@tmagic/core';
34
34
  import { TMagicButton, tMagicMessageBox, TMagicSwitch } from '@tmagic/design';
35
- import { type FieldProps, type FormConfig, type FormState, MFormBox } from '@tmagic/form';
35
+ import { type DataSourceMocksConfig, type FieldProps, type FormConfig, type FormState, MFormBox } from '@tmagic/form';
36
36
  import { type ColumnConfig, MagicTable } from '@tmagic/table';
37
37
  import { getDefaultValueFromFields } from '@tmagic/utils';
38
38
 
@@ -47,16 +47,9 @@ defineOptions({
47
47
  name: 'MFieldsDataSourceMocks',
48
48
  });
49
49
 
50
- const props = withDefaults(
51
- defineProps<
52
- FieldProps<{
53
- type: 'data-source-mocks';
54
- }>
55
- >(),
56
- {
57
- disabled: false,
58
- },
59
- );
50
+ const props = withDefaults(defineProps<FieldProps<DataSourceMocksConfig>>(), {
51
+ disabled: false,
52
+ });
60
53
 
61
54
  const emit = defineEmits(['change']);
62
55
 
@@ -24,11 +24,18 @@ import { computed, inject } from 'vue';
24
24
  import { Edit, View } from '@element-plus/icons-vue';
25
25
 
26
26
  import { TMagicButton, TMagicTooltip } from '@tmagic/design';
27
- import { type FieldProps, filterFunction, type FormState, MSelect, type SelectConfig } from '@tmagic/form';
27
+ import {
28
+ type DataSourceSelect,
29
+ type FieldProps,
30
+ filterFunction,
31
+ type FormState,
32
+ MSelect,
33
+ type SelectConfig,
34
+ } from '@tmagic/form';
28
35
 
29
36
  import MIcon from '@editor/components/Icon.vue';
30
37
  import { useServices } from '@editor/hooks/use-services';
31
- import type { DataSourceSelect, EventBus } from '@editor/type';
38
+ import type { EventBus } from '@editor/type';
32
39
  import { SideItemKey } from '@editor/type';
33
40
 
34
41
  defineOptions({
@@ -18,8 +18,8 @@ import { computed, inject } from 'vue';
18
18
  import type { DisplayCond } from '@tmagic/core';
19
19
  import {
20
20
  type ContainerChangeEventData,
21
+ type DisplayCondsConfig,
21
22
  type FieldProps,
22
- type FilterFunction,
23
23
  filterFunction,
24
24
  type FormState,
25
25
  type GroupListConfig,
@@ -37,17 +37,9 @@ const emit = defineEmits<{
37
37
  change: [value: DisplayCond[], eventData?: ContainerChangeEventData];
38
38
  }>();
39
39
 
40
- const props = withDefaults(
41
- defineProps<
42
- FieldProps<{
43
- titlePrefix?: string;
44
- parentFields?: string[] | FilterFunction<string[]>;
45
- }>
46
- >(),
47
- {
48
- disabled: false,
49
- },
50
- );
40
+ const props = withDefaults(defineProps<FieldProps<DisplayCondsConfig>>(), {
41
+ disabled: false,
42
+ });
51
43
 
52
44
  const { dataSourceService } = useServices();
53
45
  const mForm = inject<FormState | undefined>('mForm');
@@ -60,7 +60,10 @@ import { TMagicButton } from '@tmagic/design';
60
60
  import type {
61
61
  CascaderOption,
62
62
  ChildConfig,
63
+ CodeSelectColConfig,
63
64
  ContainerChangeEventData,
65
+ DataSourceMethodSelectConfig,
66
+ EventSelectConfig,
64
67
  FieldProps,
65
68
  FormState,
66
69
  OnChangeHandlerData,
@@ -70,7 +73,6 @@ import { MContainer as MFormContainer, MPanel } from '@tmagic/form';
70
73
  import { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, traverseNode } from '@tmagic/utils';
71
74
 
72
75
  import { useServices } from '@editor/hooks/use-services';
73
- import type { CodeSelectColConfig, DataSourceMethodSelectConfig, EventSelectConfig } from '@editor/type';
74
76
  import { getCascaderOptionsFromFields } from '@editor/utils';
75
77
 
76
78
  defineOptions({
@@ -63,7 +63,7 @@ import { ref, watchEffect } from 'vue';
63
63
  import { Delete, Plus } from '@element-plus/icons-vue';
64
64
 
65
65
  import { TMagicButton, TMagicInput } from '@tmagic/design';
66
- import type { FieldProps, FormItem } from '@tmagic/form';
66
+ import type { FieldProps, KeyValueConfig } from '@tmagic/form';
67
67
 
68
68
  import CodeIcon from '@editor/icons/CodeIcon.vue';
69
69
  import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
@@ -72,19 +72,9 @@ defineOptions({
72
72
  name: 'MFieldsKeyValue',
73
73
  });
74
74
 
75
- const props = withDefaults(
76
- defineProps<
77
- FieldProps<
78
- {
79
- type: 'key-value';
80
- advanced?: boolean;
81
- } & FormItem
82
- >
83
- >(),
84
- {
85
- disabled: false,
86
- },
87
- );
75
+ const props = withDefaults(defineProps<FieldProps<KeyValueConfig>>(), {
76
+ disabled: false,
77
+ });
88
78
 
89
79
  const emit = defineEmits<{
90
80
  change: [value: Record<string, any>];
@@ -20,11 +20,10 @@ import { computed } from 'vue';
20
20
  import { Edit } from '@element-plus/icons-vue';
21
21
 
22
22
  import { Id, NodeType } from '@tmagic/core';
23
- import { FieldProps } from '@tmagic/form';
23
+ import { FieldProps, type PageFragmentSelectConfig } from '@tmagic/form';
24
24
 
25
25
  import Icon from '@editor/components/Icon.vue';
26
26
  import { useServices } from '@editor/hooks/use-services';
27
- import type { PageFragmentSelectConfig } from '@editor/type';
28
27
 
29
28
  defineOptions({
30
29
  name: 'MFieldsPageFragmentSelect',
@@ -47,7 +47,7 @@ import { throttle } from 'lodash-es';
47
47
 
48
48
  import type { Id, MNode } from '@tmagic/core';
49
49
  import { TMagicButton, TMagicTooltip } from '@tmagic/design';
50
- import type { FieldProps, FormItem, FormState } from '@tmagic/form';
50
+ import type { FieldProps, FormState, UISelectConfig } from '@tmagic/form';
51
51
  import { getIdFromEl } from '@tmagic/utils';
52
52
 
53
53
  import { useServices } from '@editor/hooks/use-services';
@@ -57,7 +57,7 @@ defineOptions({
57
57
  name: 'MFieldsUISelect',
58
58
  });
59
59
 
60
- const props = defineProps<FieldProps<{ type: 'ui-select' } & FormItem>>();
60
+ const props = defineProps<FieldProps<UISelectConfig>>();
61
61
 
62
62
  const emit = defineEmits(['change']);
63
63
 
@@ -278,20 +278,21 @@ export const initServiceEvents = (
278
278
  });
279
279
  };
280
280
 
281
+ const getPageIdByNode = (node: MComponent) => {
282
+ let pageId: Id | undefined;
283
+
284
+ if (isPage(node)) {
285
+ pageId = node.id;
286
+ } else {
287
+ const info = editorService.getNodeInfo(node.id);
288
+ pageId = info.page?.id;
289
+ }
290
+
291
+ return pageId;
292
+ };
293
+
281
294
  const collectIdle = (nodes: MComponent[], deep: boolean, type?: DepTargetType) =>
282
- Promise.all(
283
- nodes.map((node) => {
284
- let pageId: Id | undefined;
285
-
286
- if (isPage(node)) {
287
- pageId = node.id;
288
- } else {
289
- const info = editorService.getNodeInfo(node.id);
290
- pageId = info.page?.id;
291
- }
292
- return depService.collectIdle([node], { pageId }, deep, type);
293
- }),
294
- );
295
+ Promise.all(nodes.map((node) => depService.collectIdle([node], { pageId: getPageIdByNode(node) }, deep, type)));
295
296
 
296
297
  watch(
297
298
  () => editorService.get('stage'),
@@ -338,7 +339,8 @@ export const initServiceEvents = (
338
339
 
339
340
  if (Array.isArray(value.items)) {
340
341
  depService.clearIdleTasks();
341
- collectIdle(value.items, true).then(() => {
342
+
343
+ (typeof Worker === 'undefined' ? collectIdle(value.items, true) : depService.collectByWorker(value)).then(() => {
342
344
  updateStageNodes(value.items);
343
345
  });
344
346
  } else {
@@ -629,16 +631,12 @@ export const initServiceEvents = (
629
631
  root.dataSourceDeps = {};
630
632
  }
631
633
  root.dataSourceDeps[target.id] = target.deps;
632
- }
633
-
634
- if (target.type === DepTargetType.DATA_SOURCE_COND) {
634
+ } else if (target.type === DepTargetType.DATA_SOURCE_COND) {
635
635
  if (!root.dataSourceCondDeps) {
636
636
  root.dataSourceCondDeps = {};
637
637
  }
638
638
  root.dataSourceCondDeps[target.id] = target.deps;
639
- }
640
-
641
- if (target.type === DepTargetType.DATA_SOURCE_METHOD) {
639
+ } else if (target.type === DepTargetType.DATA_SOURCE_METHOD) {
642
640
  if (!root.dataSourceMethodDeps) {
643
641
  root.dataSourceMethodDeps = {};
644
642
  }
@@ -17,12 +17,14 @@
17
17
  */
18
18
  import { reactive, shallowReactive } from 'vue';
19
19
  import { throttle } from 'lodash-es';
20
+ import serialize from 'serialize-javascript';
20
21
 
21
- import type { DepExtendedData, Id, MNode, Target, TargetNode } from '@tmagic/core';
22
- import { DepTargetType, Watcher } from '@tmagic/core';
22
+ import type { DepData, DepExtendedData, Id, MApp, MNode, Target, TargetNode } from '@tmagic/core';
23
+ import { DepTargetType, traverseTarget, Watcher } from '@tmagic/core';
23
24
  import { isPage } from '@tmagic/utils';
24
25
 
25
- import { IdleTask } from '@editor/utils/idle-task';
26
+ import { IdleTask } from '@editor/utils/dep/idle-task';
27
+ import Work from '@editor/utils/dep/worker.ts?worker&inline';
26
28
 
27
29
  import BaseService from './BaseService';
28
30
 
@@ -50,6 +52,8 @@ class Dep extends BaseService {
50
52
 
51
53
  private watcher = new Watcher({ initialTargets: reactive({}) });
52
54
 
55
+ private waitingWorker?: Promise<void>;
56
+
53
57
  constructor() {
54
58
  super();
55
59
 
@@ -114,7 +118,11 @@ class Dep extends BaseService {
114
118
  this.emit('ds-collected', nodes, deep);
115
119
  }
116
120
 
117
- public collectIdle(nodes: MNode[], depExtendedData: DepExtendedData = {}, deep = false, type?: DepTargetType) {
121
+ public async collectIdle(nodes: MNode[], depExtendedData: DepExtendedData = {}, deep = false, type?: DepTargetType) {
122
+ if (this.waitingWorker) {
123
+ await this.waitingWorker;
124
+ }
125
+
118
126
  this.set('collecting', true);
119
127
  let startTask = false;
120
128
  this.watcher.collectByCallback(nodes, type, ({ node, target }) => {
@@ -141,6 +149,48 @@ class Dep extends BaseService {
141
149
  });
142
150
  }
143
151
 
152
+ public collectByWorker(dsl: MApp) {
153
+ this.set('collecting', true);
154
+
155
+ const { promise, resolve: waitingResolve } = Promise.withResolvers<void>();
156
+
157
+ this.waitingWorker = promise;
158
+
159
+ return new Promise<Record<string, Record<string, DepData>>>((resolve) => {
160
+ const worker = new Work();
161
+ worker.postMessage({
162
+ dsl: serialize(dsl),
163
+ });
164
+ worker.onmessage = (e) => {
165
+ resolve(e.data);
166
+ };
167
+ worker.onerror = () => {
168
+ resolve({});
169
+ };
170
+ }).then((depsData) => {
171
+ traverseTarget(this.watcher.getTargetsList(), (target) => {
172
+ if (depsData[target.type]?.[target.id]) {
173
+ target.deps = reactive(depsData[target.type][target.id]);
174
+
175
+ if (target.type === DepTargetType.DATA_SOURCE && dsl.dataSourceDeps) {
176
+ dsl.dataSourceDeps[target.id] = target.deps;
177
+ } else if (target.type === DepTargetType.DATA_SOURCE_COND && dsl.dataSourceCondDeps) {
178
+ dsl.dataSourceCondDeps[target.id] = target.deps;
179
+ } else if (target.type === DepTargetType.DATA_SOURCE_METHOD) {
180
+ dsl.dataSourceMethodDeps[target.id] = target.deps;
181
+ }
182
+ }
183
+ });
184
+
185
+ this.set('collecting', false);
186
+ this.emit('collected', dsl.items, true);
187
+ this.emit('ds-collected', dsl.items, true);
188
+ waitingResolve();
189
+
190
+ return depsData;
191
+ });
192
+ }
193
+
144
194
  public collectNode(node: MNode, target: Target, depExtendedData: DepExtendedData = {}, deep = false) {
145
195
  // 先删除原有依赖,重新收集
146
196
  if (isPage(node)) {