@tmagic/editor 1.3.0-alpha.9 → 1.3.0-beta.0

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 (121) hide show
  1. package/dist/style.css +77 -218
  2. package/dist/tmagic-editor.js +4143 -3302
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +5289 -4434
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +15 -15
  7. package/src/Editor.vue +4 -5
  8. package/src/components/CodeBlockEditor.vue +257 -0
  9. package/src/components/CodeParams.vue +60 -0
  10. package/src/components/ContentMenu.vue +11 -3
  11. package/src/editorProps.ts +30 -5
  12. package/src/fields/Code.vue +23 -19
  13. package/src/fields/CodeLink.vue +6 -7
  14. package/src/fields/CodeSelect.vue +12 -9
  15. package/src/fields/CodeSelectCol.vue +70 -81
  16. package/src/fields/DataSourceFieldSelect.vue +47 -0
  17. package/src/fields/DataSourceFields.vue +28 -22
  18. package/src/fields/DataSourceInput.vue +21 -58
  19. package/src/fields/DataSourceMethodSelect.vue +136 -0
  20. package/src/fields/DataSourceMethods.vue +103 -0
  21. package/src/fields/DataSourceSelect.vue +5 -12
  22. package/src/fields/EventSelect.vue +53 -19
  23. package/src/fields/KeyValue.vue +9 -11
  24. package/src/fields/UISelect.vue +54 -14
  25. package/src/hooks/index.ts +21 -0
  26. package/src/hooks/use-code-block-edit.ts +84 -0
  27. package/src/hooks/use-data-source-method.ts +100 -0
  28. package/src/{utils/stage.ts → hooks/use-stage.ts} +4 -7
  29. package/src/icons/CenterIcon.vue +13 -0
  30. package/src/icons/CodeIcon.vue +0 -2
  31. package/src/icons/FolderMinusIcon.vue +22 -0
  32. package/src/index.ts +12 -0
  33. package/src/initService.ts +69 -16
  34. package/src/layouts/CodeEditor.vue +35 -3
  35. package/src/layouts/Framework.vue +7 -3
  36. package/src/layouts/PropsPanel.vue +8 -3
  37. package/src/layouts/sidebar/ComponentListPanel.vue +4 -6
  38. package/src/layouts/sidebar/LayerMenu.vue +20 -21
  39. package/src/layouts/sidebar/LayerPanel.vue +12 -2
  40. package/src/layouts/sidebar/Sidebar.vue +22 -36
  41. package/src/layouts/sidebar/code-block/CodeBlockList.vue +81 -119
  42. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +64 -0
  43. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +27 -47
  44. package/src/layouts/sidebar/data-source/DataSourceList.vue +145 -0
  45. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +58 -85
  46. package/src/layouts/workspace/Stage.vue +3 -2
  47. package/src/layouts/workspace/ViewerMenu.vue +10 -35
  48. package/src/services/codeBlock.ts +18 -71
  49. package/src/services/dataSource.ts +16 -1
  50. package/src/services/dep.ts +22 -20
  51. package/src/services/editor.ts +46 -18
  52. package/src/services/props.ts +2 -2
  53. package/src/theme/code-block.scss +5 -117
  54. package/src/theme/code-editor.scss +27 -2
  55. package/src/theme/content-menu.scss +1 -1
  56. package/src/theme/data-source-methods.scss +13 -0
  57. package/src/theme/data-source.scss +11 -0
  58. package/src/theme/event.scss +15 -12
  59. package/src/theme/framework.scss +0 -3
  60. package/src/theme/layout.scss +4 -0
  61. package/src/theme/sidebar.scss +18 -60
  62. package/src/theme/theme.scss +1 -0
  63. package/src/type.ts +47 -7
  64. package/src/utils/content-menu.ts +92 -0
  65. package/src/utils/data-source/formConfigs/base.ts +28 -30
  66. package/src/utils/data-source/index.ts +65 -2
  67. package/src/utils/dep.ts +33 -7
  68. package/src/utils/index.ts +1 -1
  69. package/src/utils/props.ts +298 -189
  70. package/src/utils/undo-redo.ts +1 -1
  71. package/types/Editor.vue.d.ts +30 -6
  72. package/types/components/CodeBlockEditor.vue.d.ts +23 -0
  73. package/types/components/CodeParams.vue.d.ts +26 -0
  74. package/types/components/ContentMenu.vue.d.ts +2 -2
  75. package/types/components/ToolButton.vue.d.ts +3 -3
  76. package/types/editorProps.d.ts +19 -5
  77. package/types/fields/Code.vue.d.ts +24 -19
  78. package/types/fields/CodeLink.vue.d.ts +12 -21
  79. package/types/fields/CodeSelect.vue.d.ts +6 -17
  80. package/types/fields/CodeSelectCol.vue.d.ts +10 -14
  81. package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
  82. package/types/fields/DataSourceFields.vue.d.ts +7 -18
  83. package/types/fields/DataSourceInput.vue.d.ts +10 -30
  84. package/types/fields/DataSourceMethodSelect.vue.d.ts +29 -0
  85. package/types/fields/DataSourceMethods.vue.d.ts +32 -0
  86. package/types/fields/DataSourceSelect.vue.d.ts +13 -29
  87. package/types/fields/EventSelect.vue.d.ts +2 -13
  88. package/types/fields/KeyValue.vue.d.ts +9 -24
  89. package/types/fields/UISelect.vue.d.ts +2 -11
  90. package/types/hooks/index.d.ts +3 -0
  91. package/types/{components/FunctionEditor.vue.d.ts → hooks/use-code-block-edit.d.ts} +31 -121
  92. package/types/hooks/use-data-source-method.d.ts +123 -0
  93. package/types/icons/CenterIcon.vue.d.ts +2 -0
  94. package/types/icons/FolderMinusIcon.vue.d.ts +2 -0
  95. package/types/index.d.ts +6 -0
  96. package/types/initService.d.ts +2 -2
  97. package/types/layouts/CodeEditor.vue.d.ts +7 -4
  98. package/types/layouts/PropsPanel.vue.d.ts +274 -2
  99. package/types/layouts/sidebar/Sidebar.vue.d.ts +0 -3
  100. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +4 -9
  101. package/types/layouts/sidebar/code-block/{CodeBlockEditor.vue.d.ts → CodeBlockListPanel.vue.d.ts} +9 -5
  102. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -1
  103. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +14 -0
  104. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +1 -11
  105. package/types/services/codeBlock.d.ts +6 -37
  106. package/types/services/dataSource.d.ts +7 -1
  107. package/types/services/dep.d.ts +12 -21
  108. package/types/services/editor.d.ts +1 -1
  109. package/types/services/props.d.ts +10 -115
  110. package/types/type.d.ts +42 -7
  111. package/types/utils/content-menu.d.ts +7 -0
  112. package/types/utils/data-source/formConfigs/base.d.ts +1 -2
  113. package/types/utils/data-source/index.d.ts +5 -0
  114. package/types/utils/dep.d.ts +4 -2
  115. package/types/utils/index.d.ts +1 -1
  116. package/types/utils/props.d.ts +13 -102
  117. package/src/components/CodeDraftEditor.vue +0 -148
  118. package/src/components/FunctionEditor.vue +0 -197
  119. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -100
  120. package/types/components/CodeDraftEditor.vue.d.ts +0 -61
  121. /package/types/{utils/stage.d.ts → hooks/use-stage.d.ts} +0 -0
@@ -1,32 +1,30 @@
1
1
  import type { FormConfig } from '@tmagic/form';
2
2
 
3
- export default [
4
- {
5
- name: 'id',
6
- type: 'hidden',
7
- },
8
- {
9
- name: 'type',
10
- text: '类型',
11
- type: 'select',
12
- options: [
13
- { text: '基础', value: 'base' },
14
- { text: 'HTTP', value: 'http' },
15
- ],
16
- defaultValue: 'base',
17
- },
18
- {
19
- name: 'title',
20
- text: '名称',
21
- rules: [
22
- {
23
- required: true,
24
- message: '请输入名称',
25
- },
26
- ],
27
- },
28
- {
29
- name: 'description',
30
- text: '描述',
31
- },
32
- ] as FormConfig;
3
+ export default function (): FormConfig {
4
+ return [
5
+ {
6
+ name: 'id',
7
+ type: 'hidden',
8
+ },
9
+ {
10
+ name: 'type',
11
+ text: '类型',
12
+ type: 'hidden',
13
+ defaultValue: 'base',
14
+ },
15
+ {
16
+ name: 'title',
17
+ text: '名称',
18
+ rules: [
19
+ {
20
+ required: true,
21
+ message: '请输入名称',
22
+ },
23
+ ],
24
+ },
25
+ {
26
+ name: 'description',
27
+ text: '描述',
28
+ },
29
+ ];
30
+ }
@@ -1,10 +1,11 @@
1
1
  import { FormConfig } from '@tmagic/form';
2
+ import { DataSchema, DataSourceSchema } from '@tmagic/schema';
2
3
 
3
4
  import BaseFormConfig from './formConfigs/base';
4
5
  import HttpFormConfig from './formConfigs/http';
5
6
 
6
7
  const fillConfig = (config: FormConfig): FormConfig => [
7
- ...BaseFormConfig,
8
+ ...BaseFormConfig(),
8
9
  ...config,
9
10
  {
10
11
  type: 'panel',
@@ -13,7 +14,18 @@ const fillConfig = (config: FormConfig): FormConfig => [
13
14
  {
14
15
  name: 'fields',
15
16
  type: 'data-source-fields',
16
- defaultValue: [],
17
+ defaultValue: () => [],
18
+ },
19
+ ],
20
+ },
21
+ {
22
+ type: 'panel',
23
+ title: '方法定义',
24
+ items: [
25
+ {
26
+ name: 'methods',
27
+ type: 'data-source-methods',
28
+ defaultValue: () => [],
17
29
  },
18
30
  ],
19
31
  },
@@ -29,3 +41,54 @@ export const getFormConfig = (type: string, configs: Record<string, FormConfig>)
29
41
  return fillConfig(configs[type] || []);
30
42
  }
31
43
  };
44
+
45
+ export const getDisplayField = (dataSources: DataSourceSchema[], key: string) => {
46
+ const displayState: { value: string; type: 'var' | 'text' }[] = [];
47
+
48
+ // 匹配es6字符串模块
49
+ const matches = key.matchAll(/\$\{([\s\S]+?)\}/g);
50
+ let index = 0;
51
+ for (const match of matches) {
52
+ if (typeof match.index === 'undefined') break;
53
+
54
+ // 字符串常量
55
+ displayState.push({
56
+ type: 'text',
57
+ value: key.substring(index, match.index),
58
+ });
59
+
60
+ let dsText = '';
61
+ let ds: DataSourceSchema | undefined;
62
+ let fields: DataSchema[] | undefined;
63
+
64
+ // 将模块解析成数据源对应的值
65
+ match[1].split('.').forEach((item, index) => {
66
+ if (index === 0) {
67
+ ds = dataSources.find((ds) => ds.id === item);
68
+ dsText += ds?.title || item;
69
+ fields = ds?.fields;
70
+ return;
71
+ }
72
+
73
+ const field = fields?.find((field) => field.name === item);
74
+ fields = field?.fields;
75
+ dsText += `.${field?.title || item}`;
76
+ });
77
+
78
+ displayState.push({
79
+ type: 'var',
80
+ value: dsText,
81
+ });
82
+
83
+ index = match.index + match[0].length;
84
+ }
85
+
86
+ if (index < key.length) {
87
+ displayState.push({
88
+ type: 'text',
89
+ value: key.substring(index),
90
+ });
91
+ }
92
+
93
+ return displayState;
94
+ };
package/src/utils/dep.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import { isEmpty } from 'lodash-es';
2
2
 
3
- import { CodeBlockContent, DataSourceSchema, HookType, Id } from '@tmagic/schema';
3
+ import { CodeBlockContent, HookType, Id } from '@tmagic/schema';
4
4
 
5
+ import dataSourceService from '@editor/services/dataSource';
5
6
  import { Target } from '@editor/services/dep';
6
- import type { HookData } from '@editor/type';
7
+ import { DepTargetType, HookData } from '@editor/type';
7
8
 
8
9
  export const createCodeBlockTarget = (id: Id, codeBlock: CodeBlockContent) =>
9
10
  new Target({
10
- type: 'code-block',
11
+ type: DepTargetType.CODE_BLOCK,
11
12
  id,
12
13
  name: codeBlock.name,
13
14
  isTarget: (key: string | number, value: any) => {
@@ -24,12 +25,37 @@ export const createCodeBlockTarget = (id: Id, codeBlock: CodeBlockContent) =>
24
25
  },
25
26
  });
26
27
 
27
- export const createDataSourceTarget = (id: Id, ds: DataSourceSchema) =>
28
+ export const createDataSourceTarget = (id: Id) =>
28
29
  new Target({
29
- type: 'data-source',
30
+ type: DepTargetType.DATA_SOURCE,
30
31
  id,
31
- name: ds.title || `${id}`,
32
32
  isTarget: (key: string | number, value: any) =>
33
33
  // 关联数据源对象或者在模板在使用数据源
34
- (value.isBindDataSource && value.dataSourceId) || (typeof value === 'string' && value.includes(`${id}`)),
34
+ (value?.isBindDataSource && value.dataSourceId) || (typeof value === 'string' && value.includes(`${id}`)),
35
+ });
36
+
37
+ export const createDataSourceCondTarget = (id: string) =>
38
+ new Target({
39
+ type: DepTargetType.DATA_SOURCE_COND,
40
+ id,
41
+ isTarget: (key: string | number, value: any) => {
42
+ if (!Array.isArray(value) || value[0] !== id) return false;
43
+
44
+ const ds = dataSourceService.getDataSourceById(id);
45
+
46
+ return Boolean(ds?.fields?.find((field) => field.name === value[1]));
47
+ },
48
+ });
49
+
50
+ export const createDataSourceMethodTarget = (id: string) =>
51
+ new Target({
52
+ type: DepTargetType.DATA_SOURCE_METHOD,
53
+ id,
54
+ isTarget: (key: string | number, value: any) => {
55
+ if (!Array.isArray(value) || value[0] !== id) return false;
56
+
57
+ const ds = dataSourceService.getDataSourceById(id);
58
+
59
+ return Boolean(ds?.methods?.find((method) => method.name === value[1]));
60
+ },
35
61
  });
@@ -20,5 +20,5 @@ export * from './config';
20
20
  export * from './props';
21
21
  export * from './logger';
22
22
  export * from './editor';
23
- export * from './stage';
24
23
  export * from './operator';
24
+ export * from './data-source';