@tmagic/editor 1.3.0-alpha.8 → 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 (124) hide show
  1. package/dist/style.css +82 -218
  2. package/dist/tmagic-editor.js +4985 -3999
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +5013 -4012
  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 +68 -0
  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 +15 -0
  33. package/src/initService.ts +73 -16
  34. package/src/layouts/CodeEditor.vue +62 -10
  35. package/src/layouts/Framework.vue +7 -3
  36. package/src/layouts/PropsPanel.vue +8 -3
  37. package/src/layouts/sidebar/ComponentListPanel.vue +6 -9
  38. package/src/layouts/sidebar/LayerMenu.vue +20 -21
  39. package/src/layouts/sidebar/LayerNode.vue +40 -0
  40. package/src/layouts/sidebar/LayerPanel.vue +14 -5
  41. package/src/layouts/sidebar/Sidebar.vue +22 -36
  42. package/src/layouts/sidebar/code-block/CodeBlockList.vue +81 -119
  43. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +64 -0
  44. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +27 -47
  45. package/src/layouts/sidebar/data-source/DataSourceList.vue +145 -0
  46. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +58 -69
  47. package/src/layouts/workspace/Stage.vue +13 -5
  48. package/src/layouts/workspace/ViewerMenu.vue +10 -35
  49. package/src/services/codeBlock.ts +18 -71
  50. package/src/services/dataSource.ts +16 -1
  51. package/src/services/dep.ts +23 -20
  52. package/src/services/editor.ts +46 -18
  53. package/src/services/props.ts +2 -2
  54. package/src/theme/code-block.scss +5 -117
  55. package/src/theme/code-editor.scss +27 -2
  56. package/src/theme/content-menu.scss +1 -1
  57. package/src/theme/data-source-methods.scss +13 -0
  58. package/src/theme/data-source.scss +11 -0
  59. package/src/theme/event.scss +15 -12
  60. package/src/theme/framework.scss +0 -3
  61. package/src/theme/layer-panel.scss +6 -0
  62. package/src/theme/layout.scss +4 -0
  63. package/src/theme/sidebar.scss +18 -60
  64. package/src/theme/theme.scss +1 -0
  65. package/src/type.ts +47 -7
  66. package/src/utils/content-menu.ts +92 -0
  67. package/src/utils/data-source/formConfigs/base.ts +28 -30
  68. package/src/utils/data-source/index.ts +65 -2
  69. package/src/utils/dep.ts +39 -7
  70. package/src/utils/index.ts +1 -1
  71. package/src/utils/props.ts +298 -189
  72. package/src/utils/undo-redo.ts +1 -1
  73. package/types/Editor.vue.d.ts +30 -6
  74. package/types/components/CodeBlockEditor.vue.d.ts +23 -0
  75. package/types/components/CodeParams.vue.d.ts +26 -0
  76. package/types/components/ContentMenu.vue.d.ts +2 -2
  77. package/types/components/ToolButton.vue.d.ts +3 -3
  78. package/types/editorProps.d.ts +19 -5
  79. package/types/fields/Code.vue.d.ts +24 -19
  80. package/types/fields/CodeLink.vue.d.ts +12 -21
  81. package/types/fields/CodeSelect.vue.d.ts +6 -17
  82. package/types/fields/CodeSelectCol.vue.d.ts +10 -14
  83. package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
  84. package/types/fields/DataSourceFields.vue.d.ts +7 -18
  85. package/types/fields/DataSourceInput.vue.d.ts +10 -30
  86. package/types/fields/DataSourceMethodSelect.vue.d.ts +29 -0
  87. package/types/fields/DataSourceMethods.vue.d.ts +32 -0
  88. package/types/fields/DataSourceSelect.vue.d.ts +40 -0
  89. package/types/fields/EventSelect.vue.d.ts +2 -13
  90. package/types/fields/KeyValue.vue.d.ts +9 -24
  91. package/types/fields/UISelect.vue.d.ts +2 -11
  92. package/types/hooks/index.d.ts +3 -0
  93. package/types/{components/FunctionEditor.vue.d.ts → hooks/use-code-block-edit.d.ts} +31 -119
  94. package/types/hooks/use-data-source-method.d.ts +123 -0
  95. package/types/icons/CenterIcon.vue.d.ts +2 -0
  96. package/types/icons/FolderMinusIcon.vue.d.ts +2 -0
  97. package/types/index.d.ts +7 -0
  98. package/types/initService.d.ts +2 -2
  99. package/types/layouts/CodeEditor.vue.d.ts +10 -4
  100. package/types/layouts/PropsPanel.vue.d.ts +274 -2
  101. package/types/layouts/sidebar/LayerNode.vue.d.ts +16 -0
  102. package/types/layouts/sidebar/Sidebar.vue.d.ts +0 -3
  103. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +4 -9
  104. package/types/layouts/sidebar/code-block/{CodeBlockEditor.vue.d.ts → CodeBlockListPanel.vue.d.ts} +9 -5
  105. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -1
  106. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +14 -0
  107. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +1 -11
  108. package/types/services/codeBlock.d.ts +6 -37
  109. package/types/services/dataSource.d.ts +7 -1
  110. package/types/services/dep.d.ts +12 -21
  111. package/types/services/editor.d.ts +1 -1
  112. package/types/services/props.d.ts +10 -115
  113. package/types/type.d.ts +42 -7
  114. package/types/utils/content-menu.d.ts +7 -0
  115. package/types/utils/data-source/formConfigs/base.d.ts +1 -2
  116. package/types/utils/data-source/index.d.ts +5 -0
  117. package/types/utils/dep.d.ts +4 -2
  118. package/types/utils/index.d.ts +1 -1
  119. package/types/utils/props.d.ts +13 -102
  120. package/src/components/CodeDraftEditor.vue +0 -148
  121. package/src/components/FunctionEditor.vue +0 -197
  122. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -100
  123. package/types/components/CodeDraftEditor.vue.d.ts +0 -61
  124. /package/types/{utils/stage.d.ts → hooks/use-stage.d.ts} +0 -0
package/src/type.ts CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  import type { Component } from 'vue';
20
20
 
21
- import type { FormConfig, FormItem } from '@tmagic/form';
21
+ import type { ColumnConfig, FilterFunction, FormConfig, FormItem } from '@tmagic/form';
22
22
  import type { CodeBlockContent, CodeBlockDSL, Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
23
23
  import type StageCore from '@tmagic/stage';
24
24
  import type {
@@ -45,7 +45,7 @@ export type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> |
45
45
  export type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
46
46
 
47
47
  export interface InstallOptions {
48
- parseDSL: (dsl: string) => MApp;
48
+ parseDSL: <T = any>(dsl: string) => T;
49
49
  [key: string]: any;
50
50
  }
51
51
 
@@ -93,7 +93,7 @@ export type StoreStateKey = keyof StoreState;
93
93
 
94
94
  export interface PropsState {
95
95
  propsConfigMap: Record<string, FormConfig>;
96
- propsValueMap: Record<string, MNode>;
96
+ propsValueMap: Record<string, Partial<MNode>>;
97
97
  }
98
98
 
99
99
  export interface ComponentGroupState {
@@ -334,18 +334,15 @@ export interface ScrollViewerEvent {
334
334
  }
335
335
 
336
336
  export type CodeState = {
337
- /** 是否展示代码块编辑区 */
338
- isShowCodeEditor: boolean;
339
337
  /** 代码块DSL数据源 */
340
338
  codeDsl: CodeBlockDSL | null;
341
- /** 当前选中的代码块id */
342
- id: Id;
343
339
  /** 代码块是否可编辑 */
344
340
  editable: boolean;
345
341
  /** list模式下左侧展示的代码列表 */
346
342
  combineIds: string[];
347
343
  /** 为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除) */
348
344
  undeletableList: Id[];
345
+ paramsColConfig?: ColumnConfig;
349
346
  };
350
347
 
351
348
  export type HookData = {
@@ -429,6 +426,8 @@ export interface EventSelectConfig {
429
426
  compActionConfig?: FormItem;
430
427
  /** 联动代码配置 */
431
428
  codeActionConfig?: FormItem;
429
+ /** 联动数据源配置 */
430
+ dataSourceActionConfig?: FormItem;
432
431
  }
433
432
 
434
433
  export enum KeyBindingCommand {
@@ -485,3 +484,44 @@ export interface KeyBindingCacheItem {
485
484
  eventType: 'keyup' | 'keydown';
486
485
  binded: boolean;
487
486
  }
487
+
488
+ export interface CodeSelectColConfig {
489
+ type: 'code-select-col';
490
+ name: string;
491
+ labelWidth?: number | string;
492
+ disabled?: boolean | FilterFunction;
493
+ display?: boolean | FilterFunction;
494
+ }
495
+
496
+ export interface DataSourceMethodSelectConfig {
497
+ type: 'data-source-method-select';
498
+ name: string;
499
+ labelWidth?: number | string;
500
+ disabled?: boolean | FilterFunction;
501
+ display?: boolean | FilterFunction;
502
+ }
503
+
504
+ export interface DataSourceFieldSelectConfig {
505
+ type: 'data-source-field-select';
506
+ name: string;
507
+ labelWidth?: number | string;
508
+ disabled?: boolean | FilterFunction;
509
+ display?: boolean | FilterFunction;
510
+ }
511
+
512
+ export enum DepTargetType {
513
+ DEFAULT = 'default',
514
+ /** 代码块 */
515
+ CODE_BLOCK = 'code-block',
516
+ /** 数据源 */
517
+ DATA_SOURCE = 'data-source',
518
+ /** 数据源方法 */
519
+ DATA_SOURCE_METHOD = 'data-source-method',
520
+ /** 数据源条件 */
521
+ DATA_SOURCE_COND = 'data-source-cond',
522
+ }
523
+
524
+ export interface DatasourceTypeOption {
525
+ type: string;
526
+ text: string;
527
+ }
@@ -0,0 +1,92 @@
1
+ import { computed, markRaw, Ref, ref } from 'vue';
2
+ import { CopyDocument, Delete, DocumentCopy } from '@element-plus/icons-vue';
3
+
4
+ import { Id, MContainer, NodeType } from '@tmagic/schema';
5
+ import { isPage } from '@tmagic/utils';
6
+
7
+ import ContentMenu from '@editor/components/ContentMenu.vue';
8
+ import type { MenuButton, Services } from '@editor/type';
9
+
10
+ export const useDeleteMenu = (): MenuButton => ({
11
+ type: 'button',
12
+ text: '删除',
13
+ icon: Delete,
14
+ display: (services) => {
15
+ const node = services?.editorService?.get('node');
16
+ return node?.type !== NodeType.ROOT && !isPage(node);
17
+ },
18
+ handler: (services) => {
19
+ const nodes = services?.editorService?.get('nodes');
20
+ nodes && services?.editorService?.remove(nodes);
21
+ },
22
+ });
23
+
24
+ const canPaste = ref(false);
25
+
26
+ export const useCopyMenu = (): MenuButton => ({
27
+ type: 'button',
28
+ text: '复制',
29
+ icon: markRaw(CopyDocument),
30
+ handler: (services) => {
31
+ const nodes = services?.editorService?.get('nodes');
32
+ nodes && services?.editorService?.copy(nodes);
33
+ canPaste.value = true;
34
+ },
35
+ });
36
+
37
+ export const usePasteMenu = (menu?: Ref<InstanceType<typeof ContentMenu> | undefined>): MenuButton => ({
38
+ type: 'button',
39
+ text: '粘贴',
40
+ icon: markRaw(DocumentCopy),
41
+ display: () => canPaste.value,
42
+ handler: (services) => {
43
+ const nodes = services?.editorService?.get('nodes');
44
+ if (!nodes || nodes.length === 0) return;
45
+
46
+ if (menu?.value?.$el) {
47
+ const stage = services?.editorService?.get('stage');
48
+ const rect = menu.value.$el.getBoundingClientRect();
49
+ const parentRect = stage?.container?.getBoundingClientRect();
50
+ const initialLeft = (rect.left || 0) - (parentRect?.left || 0);
51
+ const initialTop = (rect.top || 0) - (parentRect?.top || 0);
52
+ services?.editorService?.paste({ left: initialLeft, top: initialTop });
53
+ } else {
54
+ services?.editorService?.paste();
55
+ }
56
+ },
57
+ });
58
+
59
+ const moveTo = (id: Id, services?: Services) => {
60
+ if (!services?.editorService) return;
61
+
62
+ const nodes = services.editorService.get('nodes') || [];
63
+ const parent = services.editorService.getNodeById(id) as MContainer;
64
+
65
+ if (!parent) return;
66
+
67
+ services?.editorService.add(nodes, parent);
68
+ services?.editorService.remove(nodes);
69
+ };
70
+
71
+ export const useMoveToMenu = (services?: Services): MenuButton => {
72
+ const root = computed(() => services?.editorService?.get('root'));
73
+
74
+ return {
75
+ type: 'button',
76
+ text: '移动至',
77
+ display: (services) => {
78
+ const node = services?.editorService?.get('node');
79
+ const pageLength = services?.editorService?.get('pageLength') || 0;
80
+ return !isPage(node) && pageLength > 1;
81
+ },
82
+ items: (root.value?.items || [])
83
+ .filter((page) => page.id !== services?.editorService?.get('page')?.id)
84
+ .map((page) => ({
85
+ text: `${page.name}(${page.id})`,
86
+ type: 'button',
87
+ handler: (services?: Services) => {
88
+ moveTo(page.id, services);
89
+ },
90
+ })),
91
+ };
92
+ };
@@ -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,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';