@tmagic/editor 1.3.0-beta.4 → 1.3.0-beta.6

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 (34) hide show
  1. package/dist/style.css +4 -4
  2. package/dist/tmagic-editor.js +301 -195
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +301 -193
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +11 -10
  7. package/src/components/Icon.vue +5 -1
  8. package/src/fields/CodeSelectCol.vue +1 -2
  9. package/src/fields/DataSourceMethodSelect.vue +0 -3
  10. package/src/fields/EventSelect.vue +4 -5
  11. package/src/fields/KeyValue.vue +1 -0
  12. package/src/fields/UISelect.vue +3 -3
  13. package/src/hooks/use-stage.ts +7 -2
  14. package/src/layouts/CodeEditor.vue +1 -0
  15. package/src/layouts/sidebar/ComponentListPanel.vue +4 -3
  16. package/src/layouts/sidebar/layer/LayerNode.vue +7 -5
  17. package/src/layouts/sidebar/layer/LayerPanel.vue +4 -2
  18. package/src/layouts/sidebar/layer/use-keybinding.ts +11 -8
  19. package/src/layouts/sidebar/layer/use-node-status.ts +9 -5
  20. package/src/layouts/workspace/viewer/Stage.vue +2 -1
  21. package/src/services/dataSource.ts +2 -2
  22. package/src/theme/event.scss +1 -3
  23. package/src/theme/framework.scss +0 -2
  24. package/src/theme/layer-panel.scss +4 -0
  25. package/src/type.ts +19 -0
  26. package/src/utils/data-source/index.ts +117 -34
  27. package/src/utils/keybinding-config.ts +31 -26
  28. package/src/utils/props.ts +1 -0
  29. package/types/layouts/CodeEditor.vue.d.ts +4 -1
  30. package/types/layouts/sidebar/layer/LayerNode.vue.d.ts +1 -1
  31. package/types/layouts/sidebar/layer/use-keybinding.d.ts +3 -2
  32. package/types/type.d.ts +18 -0
  33. package/types/utils/data-source/index.d.ts +1 -0
  34. package/types/utils/keybinding-config.d.ts +4 -0
@@ -1,4 +1,4 @@
1
- import { FormConfig } from '@tmagic/form';
1
+ import { FormConfig, FormState } from '@tmagic/form';
2
2
  import { DataSchema, DataSourceSchema } from '@tmagic/schema';
3
3
 
4
4
  import BaseFormConfig from './formConfigs/base';
@@ -8,47 +8,72 @@ const fillConfig = (config: FormConfig): FormConfig => [
8
8
  ...BaseFormConfig(),
9
9
  ...config,
10
10
  {
11
- type: 'panel',
12
- title: '数据定义',
11
+ type: 'tab',
13
12
  items: [
14
13
  {
15
- name: 'fields',
16
- type: 'data-source-fields',
17
- defaultValue: () => [],
14
+ title: '数据定义',
15
+ items: [
16
+ {
17
+ name: 'fields',
18
+ type: 'data-source-fields',
19
+ defaultValue: () => [],
20
+ },
21
+ ],
18
22
  },
19
- ],
20
- },
21
- {
22
- type: 'panel',
23
- title: '方法定义',
24
- items: [
25
23
  {
26
- name: 'methods',
27
- type: 'data-source-methods',
28
- defaultValue: () => [],
24
+ title: '方法定义',
25
+ items: [
26
+ {
27
+ name: 'methods',
28
+ type: 'data-source-methods',
29
+ defaultValue: () => [],
30
+ },
31
+ ],
29
32
  },
30
- ],
31
- },
32
- {
33
- type: 'panel',
34
- title: '事件配置',
35
- display: false,
36
- items: [
37
33
  {
38
- name: 'events',
39
- src: 'datasource',
40
- type: 'event-select',
34
+ title: '事件配置',
35
+ display: false,
36
+ items: [
37
+ {
38
+ name: 'events',
39
+ src: 'datasource',
40
+ type: 'event-select',
41
+ },
42
+ ],
41
43
  },
42
- ],
43
- },
44
- {
45
- type: 'panel',
46
- title: 'mock数据',
47
- items: [
48
44
  {
49
- name: 'mocks',
50
- type: 'data-source-mocks',
51
- defaultValue: () => [],
45
+ title: 'mock数据',
46
+ items: [
47
+ {
48
+ name: 'mocks',
49
+ type: 'data-source-mocks',
50
+ defaultValue: () => [],
51
+ },
52
+ ],
53
+ },
54
+ {
55
+ title: '请求参数裁剪',
56
+ display: (formState: FormState, { model }: any) => model.type === 'http',
57
+ items: [
58
+ {
59
+ name: 'beforeRequest',
60
+ type: 'vs-code',
61
+ parse: true,
62
+ height: '600px',
63
+ },
64
+ ],
65
+ },
66
+ {
67
+ title: '响应数据裁剪',
68
+ display: (formState: FormState, { model }: any) => model.type === 'http',
69
+ items: [
70
+ {
71
+ name: 'afterResponse',
72
+ type: 'vs-code',
73
+ parse: true,
74
+ height: '600px',
75
+ },
76
+ ],
52
77
  },
53
78
  ],
54
79
  },
@@ -65,6 +90,64 @@ export const getFormConfig = (type: string, configs: Record<string, FormConfig>)
65
90
  }
66
91
  };
67
92
 
93
+ export const getFormValue = (type: string, values: Partial<DataSourceSchema>): Partial<DataSourceSchema> => {
94
+ if (type !== 'http') {
95
+ return values;
96
+ }
97
+
98
+ return {
99
+ beforeRequest: `(options, context) => {
100
+ /**
101
+ * 用户可以直接编写函数,在原始接口调用之前,会运行该函数,将这个函数的返回值作为该数据源接口的入参
102
+ *
103
+ * options: HttpOptions
104
+ *
105
+ * interface HttpOptions {
106
+ * // 请求链接
107
+ * url: string;
108
+ * // query参数
109
+ * params?: Record<string, string>;
110
+ * // body数据
111
+ * data?: Record<string, any>;
112
+ * // 请求头
113
+ * headers?: Record<string, string>;
114
+ * // 请求方法 GET/POST
115
+ * method?: Method;
116
+ * }
117
+ *
118
+ * context:上下文对象
119
+ *
120
+ * interface Content {
121
+ * app: AppCore;
122
+ * dataSource: HttpDataSource;
123
+ * }
124
+ *
125
+ * return: HttpOptions
126
+ */
127
+
128
+ // 此处的返回值会作为这个接口的入参
129
+ return options;
130
+ }`,
131
+ afterResponse: `(response, context) => {
132
+ /**
133
+ * 用户可以直接编写函数,在原始接口返回之后,会运行该函数,将这个函数的返回值作为该数据源接口的返回
134
+
135
+ * context:上下文对象
136
+ *
137
+ * interface Content {
138
+ * app: AppCore;
139
+ * dataSource: HttpDataSource;
140
+ * }
141
+ *
142
+ */
143
+
144
+ // 此处的返回值会作为这个接口的返回值
145
+ return response;
146
+ }`,
147
+ ...values,
148
+ };
149
+ };
150
+
68
151
  export const getDisplayField = (dataSources: DataSourceSchema[], key: string) => {
69
152
  const displayState: { value: string; type: 'var' | 'text' }[] = [];
70
153
 
@@ -1,120 +1,125 @@
1
1
  import { KeyBindingCommand, KeyBindingItem } from '@editor/type';
2
2
 
3
+ export enum KeyBindingContainerKey {
4
+ STAGE = 'stage',
5
+ LAYER_PANEL = 'layer-panel',
6
+ }
7
+
3
8
  export default [
4
9
  {
5
10
  command: KeyBindingCommand.DELETE_NODE,
6
11
  keybinding: ['delete', 'backspace'],
7
12
  when: [
8
- ['stage', 'keyup'],
9
- ['layer-panel', 'keydown'],
13
+ [KeyBindingContainerKey.STAGE, 'keyup'],
14
+ [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
10
15
  ],
11
16
  },
12
17
  {
13
18
  command: KeyBindingCommand.COPY_NODE,
14
19
  keybinding: 'ctrl+c',
15
20
  when: [
16
- ['stage', 'keydown'],
17
- ['layer-panel', 'keydown'],
21
+ [KeyBindingContainerKey.STAGE, 'keydown'],
22
+ [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
18
23
  ],
19
24
  },
20
25
  {
21
26
  command: KeyBindingCommand.PASTE_NODE,
22
27
  keybinding: 'ctrl+v',
23
28
  when: [
24
- ['stage', 'keydown'],
25
- ['layer-panel', 'keydown'],
29
+ [KeyBindingContainerKey.STAGE, 'keydown'],
30
+ [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
26
31
  ],
27
32
  },
28
33
  {
29
34
  command: KeyBindingCommand.CUT_NODE,
30
35
  keybinding: 'ctrl+x',
31
36
  when: [
32
- ['stage', 'keydown'],
33
- ['layer-panel', 'keydown'],
37
+ [KeyBindingContainerKey.STAGE, 'keydown'],
38
+ [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
34
39
  ],
35
40
  },
36
41
  {
37
42
  command: KeyBindingCommand.UNDO,
38
43
  keybinding: 'ctrl+z',
39
44
  when: [
40
- ['stage', 'keydown'],
41
- ['layer-panel', 'keydown'],
45
+ [KeyBindingContainerKey.STAGE, 'keydown'],
46
+ [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
42
47
  ],
43
48
  },
44
49
  {
45
50
  command: KeyBindingCommand.REDO,
46
51
  keybinding: 'ctrl+shift+z',
47
52
  when: [
48
- ['stage', 'keydown'],
49
- ['layer-panel', 'keydown'],
53
+ [KeyBindingContainerKey.STAGE, 'keydown'],
54
+ [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
50
55
  ],
51
56
  },
52
57
  {
53
58
  command: KeyBindingCommand.MOVE_UP_1,
54
59
  keybinding: 'up',
55
- when: [['stage', 'keydown']],
60
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
56
61
  },
57
62
  {
58
63
  command: KeyBindingCommand.MOVE_DOWN_1,
59
64
  keybinding: 'down',
60
- when: [['stage', 'keydown']],
65
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
61
66
  },
62
67
  {
63
68
  command: KeyBindingCommand.MOVE_LEFT_1,
64
69
  keybinding: 'left',
65
- when: [['stage', 'keydown']],
70
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
66
71
  },
67
72
  {
68
73
  command: KeyBindingCommand.MOVE_RIGHT_1,
69
74
  keybinding: 'right',
70
- when: [['stage', 'keydown']],
75
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
71
76
  },
72
77
  {
73
78
  command: KeyBindingCommand.MOVE_UP_10,
74
79
  keybinding: 'ctrl+up',
75
- when: [['stage', 'keydown']],
80
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
76
81
  },
77
82
  {
78
83
  command: KeyBindingCommand.MOVE_DOWN_10,
79
84
  keybinding: 'ctrl+down',
80
- when: [['stage', 'keydown']],
85
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
81
86
  },
82
87
  {
83
88
  command: KeyBindingCommand.MOVE_LEFT_10,
84
89
  keybinding: 'ctrl+left',
85
- when: [['stage', 'keydown']],
90
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
86
91
  },
87
92
  {
88
93
  command: KeyBindingCommand.MOVE_RIGHT_10,
89
94
  keybinding: 'ctrl+right',
90
- when: [['stage', 'keydown']],
95
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
91
96
  },
92
97
  {
93
98
  command: KeyBindingCommand.SWITCH_NODE,
94
99
  keybinding: 'tab',
95
100
  when: [
96
- ['stage', 'keydown'],
97
- ['layer-panel', 'keydown'],
101
+ [KeyBindingContainerKey.STAGE, 'keydown'],
102
+ [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
98
103
  ],
99
104
  },
100
105
  {
101
106
  command: KeyBindingCommand.ZOOM_IN,
102
107
  keybinding: ['ctrl+=', 'ctrl+numpadplus'],
103
- when: [['stage', 'keydown']],
108
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
104
109
  },
105
110
  {
106
111
  command: KeyBindingCommand.ZOOM_OUT,
107
112
  keybinding: ['ctrl+-', 'ctrl+numpad-'],
108
- when: [['stage', 'keydown']],
113
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
109
114
  },
110
115
  {
111
116
  command: KeyBindingCommand.ZOOM_FIT,
112
117
  keybinding: 'ctrl+0',
113
- when: [['stage', 'keydown']],
118
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
114
119
  },
115
120
  {
116
121
  command: KeyBindingCommand.ZOOM_RESET,
117
122
  keybinding: 'ctrl+1',
118
- when: [['stage', 'keydown']],
123
+ when: [[KeyBindingContainerKey.STAGE, 'keydown']],
119
124
  },
120
125
  ] as KeyBindingItem[];
@@ -206,6 +206,7 @@ export const eventTabConfig: TabPaneConfig = {
206
206
  {
207
207
  name: 'events',
208
208
  src: 'component',
209
+ labelWidth: '100px',
209
210
  type: 'event-select',
210
211
  },
211
212
  ],
@@ -11,6 +11,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
11
11
  autoSave?: boolean | undefined;
12
12
  parse?: boolean | undefined;
13
13
  }>, {
14
+ initValues: string;
14
15
  autoSave: boolean;
15
16
  language: string;
16
17
  options: () => {
@@ -37,6 +38,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
37
38
  autoSave?: boolean | undefined;
38
39
  parse?: boolean | undefined;
39
40
  }>, {
41
+ initValues: string;
40
42
  autoSave: boolean;
41
43
  language: string;
42
44
  options: () => {
@@ -50,9 +52,10 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
50
52
  options: {
51
53
  [key: string]: any;
52
54
  };
55
+ parse: boolean;
56
+ initValues: any;
53
57
  language: string;
54
58
  autoSave: boolean;
55
- parse: boolean;
56
59
  }, {}>;
57
60
  export default _default;
58
61
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
@@ -1,5 +1,5 @@
1
1
  import type { MContainer, MNode } from '@tmagic/schema';
2
- import type { LayerNodeSlots } from '../../../type';
2
+ import { LayerNodeSlots } from '../../../type';
3
3
  declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
4
4
  data: MNode;
5
5
  parent?: MContainer | undefined;
@@ -1,4 +1,5 @@
1
+ import { type Ref } from 'vue';
1
2
  import type { Services } from '../../../type';
2
- export declare const useKeybinding: (services: Services | undefined) => {
3
- isCtrlKeyDown: import("vue").Ref<boolean>;
3
+ export declare const useKeybinding: (services: Services | undefined, contianer: Ref<HTMLDivElement | undefined>) => {
4
+ isCtrlKeyDown: Ref<boolean>;
4
5
  };
package/types/type.d.ts CHANGED
@@ -273,6 +273,8 @@ export interface SideBarData {
273
273
  export interface ComponentItem {
274
274
  /** 显示文案 */
275
275
  text: string;
276
+ /** 详情,用于tooltip */
277
+ desc?: string;
276
278
  /** 组件类型 */
277
279
  type: string;
278
280
  /** Vue组件或url */
@@ -386,6 +388,7 @@ export interface EventSelectConfig {
386
388
  name: string;
387
389
  type: 'event-select';
388
390
  src: 'datasource' | 'component';
391
+ labelWidth?: string;
389
392
  /** 事件名称表单配置 */
390
393
  eventNameConfig?: FormItem;
391
394
  /** 动作类型配置 */
@@ -454,6 +457,7 @@ export interface KeyBindingCacheItem {
454
457
  export interface CodeSelectColConfig {
455
458
  type: 'code-select-col';
456
459
  name: string;
460
+ text: string;
457
461
  labelWidth?: number | string;
458
462
  disabled?: boolean | FilterFunction;
459
463
  display?: boolean | FilterFunction;
@@ -461,6 +465,7 @@ export interface CodeSelectColConfig {
461
465
  export interface DataSourceMethodSelectConfig {
462
466
  type: 'data-source-method-select';
463
467
  name: string;
468
+ text: string;
464
469
  labelWidth?: number | string;
465
470
  disabled?: boolean | FilterFunction;
466
471
  display?: boolean | FilterFunction;
@@ -473,6 +478,7 @@ export interface DataSourceFieldSelectConfig {
473
478
  disabled?: boolean | FilterFunction;
474
479
  display?: boolean | FilterFunction;
475
480
  }
481
+ /** 依赖收集的目标类型 */
476
482
  export declare enum DepTargetType {
477
483
  DEFAULT = "default",
478
484
  /** 代码块 */
@@ -484,16 +490,28 @@ export declare enum DepTargetType {
484
490
  /** 数据源条件 */
485
491
  DATA_SOURCE_COND = "data-source-cond"
486
492
  }
493
+ /** 可新增的数据源类型选项 */
487
494
  export interface DatasourceTypeOption {
495
+ /** 数据源类型 */
488
496
  type: string;
497
+ /** 数据源名称 */
489
498
  text: string;
490
499
  }
500
+ /** 组件树节点状态 */
491
501
  export interface LayerNodeStatus {
502
+ /** 显隐 */
492
503
  visible: boolean;
504
+ /** 展开子节点 */
493
505
  expand: boolean;
506
+ /** 选中 */
494
507
  selected: boolean;
495
508
  }
509
+ /** 拖拽类型 */
496
510
  export declare enum DragType {
511
+ /** 从组件列表拖到画布 */
497
512
  COMPONENT_LIST = "component-list",
513
+ /** 拖动组件树节点 */
498
514
  LAYER_TREE = "layer-tree"
499
515
  }
516
+ /** 当uiService.get('uiSelectMode')为true,点击组件(包括任何形式,组件树/画布)时触发的事件名 */
517
+ export declare const UI_SELECT_MODE_EVENT_NAME = "ui-select";
@@ -1,6 +1,7 @@
1
1
  import { FormConfig } from '@tmagic/form';
2
2
  import { DataSourceSchema } from '@tmagic/schema';
3
3
  export declare const getFormConfig: (type: string, configs: Record<string, FormConfig>) => FormConfig;
4
+ export declare const getFormValue: (type: string, values: Partial<DataSourceSchema>) => Partial<DataSourceSchema>;
4
5
  export declare const getDisplayField: (dataSources: DataSourceSchema[], key: string) => {
5
6
  value: string;
6
7
  type: 'var' | 'text';
@@ -1,3 +1,7 @@
1
1
  import { KeyBindingItem } from '../type';
2
+ export declare enum KeyBindingContainerKey {
3
+ STAGE = "stage",
4
+ LAYER_PANEL = "layer-panel"
5
+ }
2
6
  declare const _default: KeyBindingItem[];
3
7
  export default _default;