@tmagic/editor 1.3.0-alpha.2 → 1.3.0-alpha.21

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 (167) hide show
  1. package/dist/style.css +91 -120
  2. package/dist/tmagic-editor.js +4609 -3257
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +5708 -4337
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +21 -22
  7. package/src/Editor.vue +29 -7
  8. package/src/components/CodeBlockEditor.vue +170 -0
  9. package/src/components/CodeParams.vue +60 -0
  10. package/src/components/ContentMenu.vue +30 -11
  11. package/src/components/Icon.vue +5 -1
  12. package/src/components/Resizer.vue +45 -0
  13. package/src/components/ScrollBar.vue +5 -1
  14. package/src/components/ScrollViewer.vue +5 -1
  15. package/src/components/SearchInput.vue +4 -0
  16. package/src/components/{Layout.vue → SplitView.vue} +8 -4
  17. package/src/components/ToolButton.vue +5 -1
  18. package/src/editorProps.ts +35 -4
  19. package/src/fields/Code.vue +28 -20
  20. package/src/fields/CodeLink.vue +15 -10
  21. package/src/fields/CodeSelect.vue +19 -10
  22. package/src/fields/CodeSelectCol.vue +67 -83
  23. package/src/fields/DataSourceFieldSelect.vue +47 -0
  24. package/src/fields/DataSourceFields.vue +24 -21
  25. package/src/fields/DataSourceInput.vue +318 -0
  26. package/src/fields/DataSourceMethodSelect.vue +136 -0
  27. package/src/fields/DataSourceMethods.vue +103 -0
  28. package/src/fields/DataSourceSelect.vue +68 -0
  29. package/src/fields/EventSelect.vue +62 -22
  30. package/src/fields/KeyValue.vue +13 -11
  31. package/src/fields/UISelect.vue +59 -15
  32. package/src/hooks/index.ts +21 -0
  33. package/src/hooks/use-code-block-edit.ts +84 -0
  34. package/src/hooks/use-data-source-method.ts +100 -0
  35. package/src/{utils/stage.ts → hooks/use-stage.ts} +4 -7
  36. package/src/icons/AppManageIcon.vue +5 -1
  37. package/src/icons/CenterIcon.vue +13 -0
  38. package/src/icons/CodeIcon.vue +5 -3
  39. package/src/index.ts +24 -3
  40. package/src/initService.ts +75 -16
  41. package/src/layouts/AddPageBox.vue +5 -1
  42. package/src/layouts/CodeEditor.vue +66 -11
  43. package/src/layouts/Framework.vue +32 -28
  44. package/src/layouts/NavMenu.vue +5 -1
  45. package/src/layouts/PropsPanel.vue +14 -4
  46. package/src/layouts/sidebar/ComponentListPanel.vue +11 -10
  47. package/src/layouts/sidebar/LayerMenu.vue +13 -25
  48. package/src/layouts/sidebar/LayerNode.vue +40 -0
  49. package/src/layouts/sidebar/LayerPanel.vue +71 -28
  50. package/src/layouts/sidebar/Sidebar.vue +13 -17
  51. package/src/layouts/sidebar/code-block/CodeBlockList.vue +84 -118
  52. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +63 -0
  53. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +39 -34
  54. package/src/layouts/sidebar/data-source/DataSourceList.vue +145 -0
  55. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +17 -65
  56. package/src/layouts/workspace/Breadcrumb.vue +5 -1
  57. package/src/layouts/workspace/PageBar.vue +5 -1
  58. package/src/layouts/workspace/PageBarScrollContainer.vue +5 -1
  59. package/src/layouts/workspace/Stage.vue +30 -8
  60. package/src/layouts/workspace/ViewerMenu.vue +15 -36
  61. package/src/layouts/workspace/Workspace.vue +9 -134
  62. package/src/services/codeBlock.ts +20 -72
  63. package/src/services/dataSource.ts +17 -2
  64. package/src/services/dep.ts +23 -20
  65. package/src/services/editor.ts +3 -3
  66. package/src/services/keybinding.ts +185 -0
  67. package/src/services/props.ts +2 -2
  68. package/src/services/storage.ts +3 -2
  69. package/src/theme/code-block.scss +5 -117
  70. package/src/theme/code-editor.scss +27 -2
  71. package/src/theme/content-menu.scss +1 -1
  72. package/src/theme/data-source-input.scss +18 -0
  73. package/src/theme/data-source-methods.scss +13 -0
  74. package/src/theme/event.scss +15 -12
  75. package/src/theme/framework.scss +0 -3
  76. package/src/theme/layer-panel.scss +6 -0
  77. package/src/theme/layout.scss +4 -0
  78. package/src/theme/resizer.scss +25 -10
  79. package/src/theme/stage.scss +4 -0
  80. package/src/theme/theme.scss +2 -0
  81. package/src/type.ts +105 -7
  82. package/src/utils/config.ts +1 -1
  83. package/src/utils/content-menu.ts +92 -0
  84. package/src/utils/data-source/formConfigs/base.ts +35 -30
  85. package/src/utils/data-source/index.ts +75 -6
  86. package/src/utils/dep.ts +39 -7
  87. package/src/utils/index.ts +1 -1
  88. package/src/utils/keybinding-config.ts +120 -0
  89. package/src/utils/props.ts +298 -155
  90. package/src/utils/undo-redo.ts +1 -1
  91. package/types/Editor.vue.d.ts +37 -4
  92. package/types/components/CodeBlockEditor.vue.d.ts +23 -0
  93. package/types/components/CodeParams.vue.d.ts +26 -0
  94. package/types/components/ContentMenu.vue.d.ts +8 -3
  95. package/types/components/Icon.vue.d.ts +2 -2
  96. package/types/{layouts → components}/Resizer.vue.d.ts +2 -2
  97. package/types/components/ScrollBar.vue.d.ts +1 -1
  98. package/types/components/ScrollViewer.vue.d.ts +8 -5
  99. package/types/components/SearchInput.vue.d.ts +1 -1
  100. package/types/components/{Layout.vue.d.ts → SplitView.vue.d.ts} +9 -6
  101. package/types/components/ToolButton.vue.d.ts +10 -7
  102. package/types/editorProps.d.ts +23 -4
  103. package/types/fields/Code.vue.d.ts +23 -18
  104. package/types/fields/CodeLink.vue.d.ts +13 -22
  105. package/types/fields/CodeSelect.vue.d.ts +12 -20
  106. package/types/fields/CodeSelectCol.vue.d.ts +14 -15
  107. package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
  108. package/types/fields/DataSourceFields.vue.d.ts +13 -21
  109. package/types/fields/DataSourceInput.vue.d.ts +34 -0
  110. package/types/fields/DataSourceMethodSelect.vue.d.ts +29 -0
  111. package/types/fields/DataSourceMethods.vue.d.ts +32 -0
  112. package/types/fields/DataSourceSelect.vue.d.ts +40 -0
  113. package/types/fields/EventSelect.vue.d.ts +3 -14
  114. package/types/fields/KeyValue.vue.d.ts +15 -27
  115. package/types/fields/UISelect.vue.d.ts +3 -12
  116. package/types/hooks/index.d.ts +3 -0
  117. package/types/hooks/use-code-block-edit.d.ts +125 -0
  118. package/types/hooks/use-data-source-method.d.ts +123 -0
  119. package/types/icons/AppManageIcon.vue.d.ts +1 -1
  120. package/types/icons/CenterIcon.vue.d.ts +2 -0
  121. package/types/icons/CodeIcon.vue.d.ts +1 -1
  122. package/types/index.d.ts +12 -2
  123. package/types/initService.d.ts +2 -2
  124. package/types/layouts/AddPageBox.vue.d.ts +1 -1
  125. package/types/layouts/CodeEditor.vue.d.ts +18 -10
  126. package/types/layouts/Framework.vue.d.ts +11 -32
  127. package/types/layouts/NavMenu.vue.d.ts +7 -4
  128. package/types/layouts/PropsPanel.vue.d.ts +276 -4
  129. package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +4 -4
  130. package/types/layouts/sidebar/LayerMenu.vue.d.ts +2 -2
  131. package/types/layouts/sidebar/LayerNode.vue.d.ts +16 -0
  132. package/types/layouts/sidebar/LayerPanel.vue.d.ts +5 -5
  133. package/types/layouts/sidebar/Sidebar.vue.d.ts +16 -16
  134. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +7 -12
  135. package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +28 -0
  136. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +4 -2
  137. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +14 -0
  138. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +1 -11
  139. package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -1
  140. package/types/layouts/workspace/PageBar.vue.d.ts +5 -5
  141. package/types/layouts/workspace/PageBarScrollContainer.vue.d.ts +2 -2
  142. package/types/layouts/workspace/Stage.vue.d.ts +2 -2
  143. package/types/layouts/workspace/ViewerMenu.vue.d.ts +7 -4
  144. package/types/layouts/workspace/Workspace.vue.d.ts +9 -9
  145. package/types/services/codeBlock.d.ts +6 -37
  146. package/types/services/dataSource.d.ts +7 -1
  147. package/types/services/dep.d.ts +12 -21
  148. package/types/services/editor.d.ts +1 -1
  149. package/types/services/keybinding.d.ts +20 -0
  150. package/types/services/props.d.ts +10 -115
  151. package/types/type.d.ts +97 -7
  152. package/types/utils/config.d.ts +1 -1
  153. package/types/utils/content-menu.d.ts +7 -0
  154. package/types/utils/data-source/formConfigs/base.d.ts +2 -2
  155. package/types/utils/data-source/index.d.ts +7 -1
  156. package/types/utils/dep.d.ts +4 -2
  157. package/types/utils/index.d.ts +1 -1
  158. package/types/utils/keybinding-config.d.ts +3 -0
  159. package/types/utils/props.d.ts +13 -102
  160. package/src/components/CodeDraftEditor.vue +0 -144
  161. package/src/components/FunctionEditor.vue +0 -190
  162. package/src/layouts/Resizer.vue +0 -32
  163. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -96
  164. package/types/components/CodeDraftEditor.vue.d.ts +0 -58
  165. package/types/components/FunctionEditor.vue.d.ts +0 -192
  166. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +0 -25
  167. /package/types/{utils/stage.d.ts → hooks/use-stage.d.ts} +0 -0
@@ -1,32 +1,37 @@
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
+ import type { DatasourceTypeOption } from '@editor/type';
4
+
5
+ export default function (datasourceTypeList: DatasourceTypeOption[] = []): FormConfig {
6
+ return [
7
+ {
8
+ name: 'id',
9
+ type: 'hidden',
10
+ },
11
+ {
12
+ name: 'type',
13
+ text: '类型',
14
+ type: 'select',
15
+ options: [
16
+ { text: '基础', value: 'base' },
17
+ { text: 'HTTP', value: 'http' },
18
+ ...datasourceTypeList.map((item) => ({ text: item.text, value: item.type })),
19
+ ],
20
+ defaultValue: 'base',
21
+ },
22
+ {
23
+ name: 'title',
24
+ text: '名称',
25
+ rules: [
26
+ {
27
+ required: true,
28
+ message: '请输入名称',
29
+ },
30
+ ],
31
+ },
32
+ {
33
+ name: 'description',
34
+ text: '描述',
35
+ },
36
+ ];
37
+ }
@@ -1,10 +1,13 @@
1
1
  import { FormConfig } from '@tmagic/form';
2
+ import { DataSchema, DataSourceSchema } from '@tmagic/schema';
3
+
4
+ import { DatasourceTypeOption } from '@editor/type';
2
5
 
3
6
  import BaseFormConfig from './formConfigs/base';
4
7
  import HttpFormConfig from './formConfigs/http';
5
8
 
6
- const fillConfig = (config: FormConfig): FormConfig => [
7
- ...BaseFormConfig,
9
+ const fillConfig = (config: FormConfig, datasourceTypeList: DatasourceTypeOption[]): FormConfig => [
10
+ ...BaseFormConfig(datasourceTypeList),
8
11
  ...config,
9
12
  {
10
13
  type: 'panel',
@@ -17,15 +20,81 @@ const fillConfig = (config: FormConfig): FormConfig => [
17
20
  },
18
21
  ],
19
22
  },
23
+ {
24
+ type: 'panel',
25
+ title: '方法定义',
26
+ items: [
27
+ {
28
+ name: 'methods',
29
+ type: 'data-source-methods',
30
+ defaultValue: [],
31
+ },
32
+ ],
33
+ },
20
34
  ];
21
35
 
22
- export const getFormConfig = (type: string, configs: Record<string, FormConfig>): FormConfig => {
36
+ export const getFormConfig = (
37
+ type: string,
38
+ datasourceTypeList: DatasourceTypeOption[],
39
+ configs: Record<string, FormConfig>,
40
+ ): FormConfig => {
23
41
  switch (type) {
24
42
  case 'base':
25
- return fillConfig([]);
43
+ return fillConfig([], datasourceTypeList);
26
44
  case 'http':
27
- return fillConfig(HttpFormConfig);
45
+ return fillConfig(HttpFormConfig, datasourceTypeList);
28
46
  default:
29
- return fillConfig(configs[type] || []);
47
+ return fillConfig(configs[type] || [], datasourceTypeList);
48
+ }
49
+ };
50
+
51
+ export const getDisplayField = (dataSources: DataSourceSchema[], key: string) => {
52
+ const displayState: { value: string; type: 'var' | 'text' }[] = [];
53
+
54
+ // 匹配es6字符串模块
55
+ const matches = key.matchAll(/\$\{([\s\S]+?)\}/g);
56
+ let index = 0;
57
+ for (const match of matches) {
58
+ if (typeof match.index === 'undefined') break;
59
+
60
+ // 字符串常量
61
+ displayState.push({
62
+ type: 'text',
63
+ value: key.substring(index, match.index),
64
+ });
65
+
66
+ let dsText = '';
67
+ let ds: DataSourceSchema | undefined;
68
+ let fields: DataSchema[] | undefined;
69
+
70
+ // 将模块解析成数据源对应的值
71
+ match[1].split('.').forEach((item, index) => {
72
+ if (index === 0) {
73
+ ds = dataSources.find((ds) => ds.id === item);
74
+ dsText += ds?.title || item;
75
+ fields = ds?.fields;
76
+ return;
77
+ }
78
+
79
+ const field = fields?.find((field) => field.name === item);
80
+ fields = field?.fields;
81
+ dsText += `.${field?.title || item}`;
82
+ });
83
+
84
+ displayState.push({
85
+ type: 'var',
86
+ value: dsText,
87
+ });
88
+
89
+ index = match.index + match[0].length;
30
90
  }
91
+
92
+ if (index < key.length) {
93
+ displayState.push({
94
+ type: 'text',
95
+ value: key.substring(index),
96
+ });
97
+ }
98
+
99
+ return displayState;
31
100
  };
package/src/utils/dep.ts CHANGED
@@ -1,16 +1,21 @@
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) => {
15
+ if (id === value) {
16
+ return true;
17
+ }
18
+
14
19
  if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
15
20
  const index = value.hookData.findIndex((item: HookData) => item.codeId === id);
16
21
  return Boolean(index > -1);
@@ -20,10 +25,37 @@ export const createCodeBlockTarget = (id: Id, codeBlock: CodeBlockContent) =>
20
25
  },
21
26
  });
22
27
 
23
- export const createDataSourceTarget = (id: Id, ds: DataSourceSchema) =>
28
+ export const createDataSourceTarget = (id: Id) =>
29
+ new Target({
30
+ type: DepTargetType.DATA_SOURCE,
31
+ id,
32
+ isTarget: (key: string | number, value: any) =>
33
+ // 关联数据源对象或者在模板在使用数据源
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) =>
24
51
  new Target({
25
- type: 'data-source',
52
+ type: DepTargetType.DATA_SOURCE_METHOD,
26
53
  id,
27
- name: ds.title || `${id}`,
28
- isTarget: (key: string | number, value: any) => typeof value === 'string' && value.includes(`${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
+ },
29
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';
@@ -0,0 +1,120 @@
1
+ import { KeyBindingCommand, KeyBindingItem } from '@editor/type';
2
+
3
+ export default [
4
+ {
5
+ command: KeyBindingCommand.DELETE_NODE,
6
+ keybinding: ['delete', 'backspace'],
7
+ when: [
8
+ ['stage', 'keyup'],
9
+ ['layer-panel', 'keydown'],
10
+ ],
11
+ },
12
+ {
13
+ command: KeyBindingCommand.COPY_NODE,
14
+ keybinding: 'ctrl+c',
15
+ when: [
16
+ ['stage', 'keydown'],
17
+ ['layer-panel', 'keydown'],
18
+ ],
19
+ },
20
+ {
21
+ command: KeyBindingCommand.PASTE_NODE,
22
+ keybinding: 'ctrl+v',
23
+ when: [
24
+ ['stage', 'keydown'],
25
+ ['layer-panel', 'keydown'],
26
+ ],
27
+ },
28
+ {
29
+ command: KeyBindingCommand.CUT_NODE,
30
+ keybinding: 'ctrl+x',
31
+ when: [
32
+ ['stage', 'keydown'],
33
+ ['layer-panel', 'keydown'],
34
+ ],
35
+ },
36
+ {
37
+ command: KeyBindingCommand.UNDO,
38
+ keybinding: 'ctrl+z',
39
+ when: [
40
+ ['stage', 'keydown'],
41
+ ['layer-panel', 'keydown'],
42
+ ],
43
+ },
44
+ {
45
+ command: KeyBindingCommand.REDO,
46
+ keybinding: 'ctrl+shift+z',
47
+ when: [
48
+ ['stage', 'keydown'],
49
+ ['layer-panel', 'keydown'],
50
+ ],
51
+ },
52
+ {
53
+ command: KeyBindingCommand.MOVE_UP_1,
54
+ keybinding: 'up',
55
+ when: [['stage', 'keydown']],
56
+ },
57
+ {
58
+ command: KeyBindingCommand.MOVE_DOWN_1,
59
+ keybinding: 'down',
60
+ when: [['stage', 'keydown']],
61
+ },
62
+ {
63
+ command: KeyBindingCommand.MOVE_LEFT_1,
64
+ keybinding: 'left',
65
+ when: [['stage', 'keydown']],
66
+ },
67
+ {
68
+ command: KeyBindingCommand.MOVE_RIGHT_1,
69
+ keybinding: 'right',
70
+ when: [['stage', 'keydown']],
71
+ },
72
+ {
73
+ command: KeyBindingCommand.MOVE_UP_10,
74
+ keybinding: 'ctrl+up',
75
+ when: [['stage', 'keydown']],
76
+ },
77
+ {
78
+ command: KeyBindingCommand.MOVE_DOWN_10,
79
+ keybinding: 'ctrl+down',
80
+ when: [['stage', 'keydown']],
81
+ },
82
+ {
83
+ command: KeyBindingCommand.MOVE_LEFT_10,
84
+ keybinding: 'ctrl+left',
85
+ when: [['stage', 'keydown']],
86
+ },
87
+ {
88
+ command: KeyBindingCommand.MOVE_RIGHT_10,
89
+ keybinding: 'ctrl+right',
90
+ when: [['stage', 'keydown']],
91
+ },
92
+ {
93
+ command: KeyBindingCommand.SWITCH_NODE,
94
+ keybinding: 'tab',
95
+ when: [
96
+ ['stage', 'keydown'],
97
+ ['layer-panel', 'keydown'],
98
+ ],
99
+ },
100
+ {
101
+ command: KeyBindingCommand.ZOOM_IN,
102
+ keybinding: ['ctrl+=', 'ctrl+numpadplus'],
103
+ when: [['stage', 'keydown']],
104
+ },
105
+ {
106
+ command: KeyBindingCommand.ZOOM_OUT,
107
+ keybinding: ['ctrl+-', 'ctrl+numpad-'],
108
+ when: [['stage', 'keydown']],
109
+ },
110
+ {
111
+ command: KeyBindingCommand.ZOOM_FIT,
112
+ keybinding: 'ctrl+0',
113
+ when: [['stage', 'keydown']],
114
+ },
115
+ {
116
+ command: KeyBindingCommand.ZOOM_RESET,
117
+ keybinding: 'ctrl+1',
118
+ when: [['stage', 'keydown']],
119
+ },
120
+ ] as KeyBindingItem[];