@tmagic/editor 1.5.11 → 1.5.13

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.5.11",
2
+ "version": "1.5.13",
3
3
  "name": "@tmagic/editor",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -58,11 +58,11 @@
58
58
  "moveable": "^0.53.0",
59
59
  "serialize-javascript": "^6.0.0",
60
60
  "sortablejs": "^1.15.2",
61
- "@tmagic/form": "1.5.11",
62
- "@tmagic/design": "1.5.11",
63
- "@tmagic/utils": "1.5.11",
64
- "@tmagic/stage": "1.5.11",
65
- "@tmagic/table": "1.5.11"
61
+ "@tmagic/design": "1.5.13",
62
+ "@tmagic/stage": "1.5.13",
63
+ "@tmagic/form": "1.5.13",
64
+ "@tmagic/table": "1.5.13",
65
+ "@tmagic/utils": "1.5.13"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/events": "^3.0.0",
@@ -76,7 +76,7 @@
76
76
  "monaco-editor": "^0.48.0",
77
77
  "typescript": "*",
78
78
  "vue": ">=3.5.0",
79
- "@tmagic/core": "1.5.11"
79
+ "@tmagic/core": "1.5.13"
80
80
  },
81
81
  "peerDependenciesMeta": {
82
82
  "typescript": {
@@ -59,7 +59,7 @@
59
59
  </template>
60
60
 
61
61
  <script lang="ts" setup>
62
- import { computed, inject, Ref, ref, useTemplateRef } from 'vue';
62
+ import { computed, inject, nextTick, Ref, ref, useTemplateRef, watch } from 'vue';
63
63
 
64
64
  import type { CodeBlockContent } from '@tmagic/core';
65
65
  import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
@@ -95,6 +95,8 @@ const props = defineProps<{
95
95
 
96
96
  const emit = defineEmits<{
97
97
  submit: [values: CodeBlockContent, eventData: ContainerChangeEventData];
98
+ close: [];
99
+ open: [];
98
100
  }>();
99
101
 
100
102
  const { codeBlockService, uiService } = useServices();
@@ -261,6 +263,16 @@ const closedHandler = () => {
261
263
  const parentFloating = inject<Ref<HTMLDivElement | null>>('parentFloating', ref(null));
262
264
  const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(uiService, parentFloating);
263
265
 
266
+ watch(boxVisible, (visible) => {
267
+ nextTick(() => {
268
+ if (!visible) {
269
+ emit('close');
270
+ } else {
271
+ emit('open');
272
+ }
273
+ });
274
+ });
275
+
264
276
  defineExpose({
265
277
  async show() {
266
278
  calcBoxPosition();
@@ -37,7 +37,7 @@
37
37
  </template>
38
38
 
39
39
  <script lang="ts" setup>
40
- import { computed, nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef } from 'vue';
40
+ import { computed, nextTick, onBeforeUnmount, onMounted, type Ref, ref, useTemplateRef } from 'vue';
41
41
 
42
42
  import { useZIndex } from '@tmagic/design';
43
43
 
@@ -73,7 +73,7 @@ const menuEl = useTemplateRef<HTMLDivElement>('menu');
73
73
  const buttonRefs = useTemplateRef<InstanceType<typeof ToolButton>[]>('buttons');
74
74
  const subMenuRef = useTemplateRef<any>('subMenu');
75
75
  const visible = ref(false);
76
- const subMenuData = ref<(MenuButton | MenuComponent)[]>([]);
76
+ const subMenuData: Ref<(MenuButton | MenuComponent)[]> = ref<(MenuButton | MenuComponent)[]>([]);
77
77
  const zIndex = useZIndex();
78
78
  const curZIndex = ref<number>(0);
79
79
 
@@ -502,6 +502,7 @@ export const initServiceEvents = (
502
502
  isModifyField =
503
503
  changeRecord.propPath === 'fields' ||
504
504
  /fields.(\d)+.name/.test(changeRecord.propPath) ||
505
+ /fields.(\d)+.defaultValue/.test(changeRecord.propPath) ||
505
506
  /fields.(\d)+$/.test(changeRecord.propPath);
506
507
 
507
508
  isModifyMock = changeRecord.propPath === 'mocks';
@@ -523,25 +524,35 @@ export const initServiceEvents = (
523
524
  if (Array.isArray(root?.items)) {
524
525
  depService.clearIdleTasks();
525
526
 
526
- removeDataSourceTarget(config.id);
527
- initDataSourceDepTarget(config);
528
-
529
527
  let collectIdlePromises: Promise<void[]>[] = [];
530
528
  if (isModifyField) {
529
+ depService.removeTarget(config.id, DepTargetType.DATA_SOURCE);
530
+ depService.removeTarget(config.id, DepTargetType.DATA_SOURCE_COND);
531
+
532
+ depService.addTarget(createDataSourceTarget(config, reactive({})));
533
+ depService.addTarget(createDataSourceCondTarget(config, reactive({})));
534
+
531
535
  collectIdlePromises = [
532
536
  collectIdle(root.items, true, DepTargetType.DATA_SOURCE),
533
537
  collectIdle(root.items, true, DepTargetType.DATA_SOURCE_COND),
534
538
  ];
535
539
  } else if (isModifyMock) {
540
+ depService.removeTarget(config.id, DepTargetType.DATA_SOURCE);
541
+
542
+ depService.addTarget(createDataSourceTarget(config, reactive({})));
543
+
536
544
  collectIdlePromises = [collectIdle(root.items, true, DepTargetType.DATA_SOURCE)];
537
545
  } else if (isModifyMethod) {
546
+ depService.removeTarget(config.id, DepTargetType.DATA_SOURCE_METHOD);
547
+
548
+ depService.addTarget(createDataSourceMethodTarget(config, reactive({})));
549
+
538
550
  collectIdlePromises = [collectIdle(root.items, true, DepTargetType.DATA_SOURCE_METHOD)];
539
551
  }
540
- Promise.all(collectIdlePromises).then(() => {
541
- updateDataSourceSchema();
542
- updateDsData();
543
- updateStageNodes(root.items);
544
- });
552
+ Promise.all(collectIdlePromises)
553
+ .then(() => updateDataSourceSchema())
554
+ .then(() => updateDsData())
555
+ .then(() => updateStageNodes(root.items));
545
556
  }
546
557
  } else if (root?.dataSources) {
547
558
  updateDsData();
@@ -616,20 +627,31 @@ export const initServiceEvents = (
616
627
  }
617
628
  root.dataSourceCondDeps[target.id] = target.deps;
618
629
  }
630
+
631
+ if (target.type === DepTargetType.DATA_SOURCE_METHOD) {
632
+ if (!root.dataSourceMethodDeps) {
633
+ root.dataSourceMethodDeps = {};
634
+ }
635
+ root.dataSourceMethodDeps[target.id] = target.deps;
636
+ }
619
637
  };
620
638
 
621
- const targetRemoveHandler = (id: string | number) => {
639
+ const targetRemoveHandler = (id: string | number, type: DepTargetType) => {
622
640
  const root = editorService.get('root');
623
641
 
624
642
  if (!root) return;
625
643
 
626
- if (root.dataSourceDeps) {
644
+ if (root.dataSourceDeps && type === DepTargetType.DATA_SOURCE) {
627
645
  delete root.dataSourceDeps[id];
628
646
  }
629
647
 
630
- if (root.dataSourceCondDeps) {
648
+ if (root.dataSourceCondDeps && type === DepTargetType.DATA_SOURCE_COND) {
631
649
  delete root.dataSourceCondDeps[id];
632
650
  }
651
+
652
+ if (root.dataSourceMethodDeps && type === DepTargetType.DATA_SOURCE_METHOD) {
653
+ delete root.dataSourceMethodDeps[id];
654
+ }
633
655
  };
634
656
 
635
657
  depService.on('add-target', targetAddHandler);
@@ -173,6 +173,7 @@ const nodeContentMenuHandler = (event: MouseEvent, data: TreeNodeData) => {
173
173
  };
174
174
 
175
175
  defineExpose({
176
+ nodeStatusMap,
176
177
  filter: filterTextChangeHandler,
177
178
  deleteCode,
178
179
  });
@@ -32,6 +32,8 @@
32
32
  :disabled="!editable"
33
33
  :content="codeConfig"
34
34
  @submit="submitCodeBlockHandler"
35
+ @close="editDialogCloseHandler"
36
+ @open="editDialogOpenHandler"
35
37
  ></CodeBlockEditor>
36
38
 
37
39
  <Teleport to="body">
@@ -87,7 +89,7 @@ const { codeBlockService } = useServices();
87
89
 
88
90
  const editable = computed(() => codeBlockService.getEditStatus());
89
91
 
90
- const { codeBlockEditor, codeConfig, editCode, deleteCode, createCodeBlock, submitCodeBlockHandler } =
92
+ const { codeId, codeBlockEditor, codeConfig, editCode, deleteCode, createCodeBlock, submitCodeBlockHandler } =
91
93
  useCodeBlockEdit(codeBlockService);
92
94
 
93
95
  const codeBlockListRef = useTemplateRef<InstanceType<typeof CodeBlockList>>('codeBlockList');
@@ -100,6 +102,22 @@ eventBus?.on('edit-code', (id: string) => {
100
102
  editCode(id);
101
103
  });
102
104
 
105
+ const editDialogOpenHandler = () => {
106
+ if (codeBlockListRef.value) {
107
+ for (const [statusId, status] of codeBlockListRef.value.nodeStatusMap.entries()) {
108
+ status.selected = statusId === codeId.value;
109
+ }
110
+ }
111
+ };
112
+
113
+ const editDialogCloseHandler = () => {
114
+ if (codeBlockListRef.value) {
115
+ for (const [, status] of codeBlockListRef.value.nodeStatusMap.entries()) {
116
+ status.selected = false;
117
+ }
118
+ }
119
+ };
120
+
103
121
  const {
104
122
  nodeContentMenuHandler,
105
123
  menuData: contentMenuData,
@@ -22,7 +22,7 @@
22
22
  </template>
23
23
 
24
24
  <script setup lang="ts">
25
- import { inject, Ref, ref, watchEffect } from 'vue';
25
+ import { inject, nextTick, Ref, ref, watch, watchEffect } from 'vue';
26
26
 
27
27
  import type { DataSourceSchema } from '@tmagic/core';
28
28
  import { tMagicMessage } from '@tmagic/design';
@@ -48,6 +48,8 @@ const width = defineModel<number>('width', { default: 670 });
48
48
 
49
49
  const emit = defineEmits<{
50
50
  submit: [v: any, eventData: ContainerChangeEventData];
51
+ close: [];
52
+ open: [id: string];
51
53
  }>();
52
54
 
53
55
  const { uiService, dataSourceService } = useServices();
@@ -73,6 +75,16 @@ const errorHandler = (error: any) => {
73
75
  tMagicMessage.error(error.message);
74
76
  };
75
77
 
78
+ watch(boxVisible, (visible) => {
79
+ nextTick(() => {
80
+ if (!visible) {
81
+ emit('close');
82
+ } else if (initValues.value?.id) {
83
+ emit('open', initValues.value.id);
84
+ }
85
+ });
86
+ });
87
+
76
88
  defineExpose({
77
89
  show() {
78
90
  calcBoxPosition();
@@ -178,6 +178,7 @@ const nodeContentMenuHandler = (event: MouseEvent, data: TreeNodeData) => {
178
178
  };
179
179
 
180
180
  defineExpose({
181
+ nodeStatusMap,
181
182
  filter: filterTextChangeHandler,
182
183
  });
183
184
  </script>
@@ -45,6 +45,8 @@
45
45
  :values="dataSourceValues"
46
46
  :title="dialogTitle"
47
47
  @submit="submitDataSourceHandler"
48
+ @close="editDialogCloseHandler"
49
+ @open="editDialogOpenHandler"
48
50
  ></DataSourceConfigPanel>
49
51
 
50
52
  <Teleport to="body">
@@ -93,6 +95,22 @@ const { dataSourceService } = useServices();
93
95
  const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } =
94
96
  useDataSourceEdit(dataSourceService);
95
97
 
98
+ const editDialogOpenHandler = (id: string) => {
99
+ if (dataSourceList.value) {
100
+ for (const [statusId, status] of dataSourceList.value.nodeStatusMap.entries()) {
101
+ status.selected = statusId === id;
102
+ }
103
+ }
104
+ };
105
+
106
+ const editDialogCloseHandler = () => {
107
+ if (dataSourceList.value) {
108
+ for (const [, status] of dataSourceList.value.nodeStatusMap.entries()) {
109
+ status.selected = false;
110
+ }
111
+ }
112
+ };
113
+
96
114
  const datasourceTypeList = computed(() =>
97
115
  [
98
116
  { text: '基础', type: 'base' },
@@ -28,7 +28,7 @@ import BaseService from './BaseService';
28
28
 
29
29
  export interface DepEvents {
30
30
  'add-target': [target: Target];
31
- 'remove-target': [id: string | number];
31
+ 'remove-target': [id: string | number, type: string | DepTargetType];
32
32
  collected: [nodes: MNode[], deep: boolean];
33
33
  'ds-collected': [nodes: MNode[], deep: boolean];
34
34
  }
@@ -77,7 +77,7 @@ class Dep extends BaseService {
77
77
  if (!targets) return;
78
78
 
79
79
  for (const target of Object.values(targets)) {
80
- this.emit('remove-target', target.id);
80
+ this.emit('remove-target', target.id, type);
81
81
  }
82
82
  }
83
83
 
@@ -96,7 +96,7 @@ class Dep extends BaseService {
96
96
 
97
97
  public removeTarget(id: Id, type: string = DepTargetType.DEFAULT) {
98
98
  this.watcher.removeTarget(id, type);
99
- this.emit('remove-target', id);
99
+ this.emit('remove-target', id, type);
100
100
  }
101
101
 
102
102
  public clearTargets() {
@@ -57,7 +57,7 @@ class Events extends BaseService {
57
57
  }
58
58
 
59
59
  public getMethod(type: string) {
60
- return cloneDeep(methodMap[toLine(type)]);
60
+ return cloneDeep(methodMap[toLine(type)]) || [];
61
61
  }
62
62
 
63
63
  public resetState() {