@tmagic/editor 1.3.0-beta.5 → 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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.0-beta.5",
2
+ "version": "1.3.0-beta.6",
3
3
  "name": "@tmagic/editor",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -12,6 +12,7 @@
12
12
  "types": "types/index.d.ts",
13
13
  "exports": {
14
14
  ".": {
15
+ "types": "./types/index.d.ts",
15
16
  "import": "./dist/tmagic-editor.js",
16
17
  "require": "./dist/tmagic-editor.umd.cjs"
17
18
  },
@@ -46,13 +47,13 @@
46
47
  "dependencies": {
47
48
  "@babel/core": "^7.18.0",
48
49
  "@element-plus/icons-vue": "^2.0.9",
49
- "@tmagic/core": "1.3.0-beta.5",
50
- "@tmagic/design": "1.3.0-beta.5",
51
- "@tmagic/form": "1.3.0-beta.5",
52
- "@tmagic/schema": "1.3.0-beta.5",
53
- "@tmagic/stage": "1.3.0-beta.5",
54
- "@tmagic/table": "1.3.0-beta.5",
55
- "@tmagic/utils": "1.3.0-beta.5",
50
+ "@tmagic/core": "1.3.0-beta.6",
51
+ "@tmagic/design": "1.3.0-beta.6",
52
+ "@tmagic/form": "1.3.0-beta.6",
53
+ "@tmagic/schema": "1.3.0-beta.6",
54
+ "@tmagic/stage": "1.3.0-beta.6",
55
+ "@tmagic/table": "1.3.0-beta.6",
56
+ "@tmagic/utils": "1.3.0-beta.6",
56
57
  "buffer": "^6.0.3",
57
58
  "color": "^3.1.3",
58
59
  "events": "^3.3.0",
@@ -64,8 +65,8 @@
64
65
  "vue": "^3.3.4"
65
66
  },
66
67
  "peerDependencies": {
67
- "@tmagic/design": "1.3.0-beta.5",
68
- "@tmagic/form": "1.3.0-beta.5",
68
+ "@tmagic/design": "1.3.0-beta.6",
69
+ "@tmagic/form": "1.3.0-beta.6",
69
70
  "monaco-editor": "^0.41.0",
70
71
  "vue": "^3.3.4"
71
72
  },
@@ -91,5 +91,6 @@ const addHandler = () => {
91
91
 
92
92
  const deleteHandler = (index: number) => {
93
93
  records.value.splice(index, 1);
94
+ emit('change', getValue());
94
95
  };
95
96
  </script>
@@ -47,6 +47,7 @@ const props = withDefaults(
47
47
  parse?: boolean;
48
48
  }>(),
49
49
  {
50
+ initValues: '',
50
51
  autoSave: true,
51
52
  language: 'javascript',
52
53
  options: () => ({
@@ -7,7 +7,7 @@ import type { DataSourceSchema } from '@tmagic/schema';
7
7
  import { guid } from '@tmagic/utils';
8
8
 
9
9
  import type { DatasourceTypeOption } from '@editor/type';
10
- import { getFormConfig } from '@editor/utils/data-source';
10
+ import { getFormConfig, getFormValue } from '@editor/utils/data-source';
11
11
 
12
12
  import BaseService from './BaseService';
13
13
 
@@ -50,7 +50,7 @@ class DataSource extends BaseService {
50
50
  }
51
51
 
52
52
  public getFormValue(type = 'base') {
53
- return this.get('values')[type];
53
+ return getFormValue(type, this.get('values')[type]);
54
54
  }
55
55
 
56
56
  public setFormValue(type: string, value: Partial<DataSourceSchema>) {
@@ -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
 
@@ -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,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';