@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.
- package/dist/style.css +77 -218
- package/dist/tmagic-editor.js +4143 -3302
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +5289 -4434
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +15 -15
- package/src/Editor.vue +4 -5
- package/src/components/CodeBlockEditor.vue +257 -0
- package/src/components/CodeParams.vue +60 -0
- package/src/components/ContentMenu.vue +11 -3
- package/src/editorProps.ts +30 -5
- package/src/fields/Code.vue +23 -19
- package/src/fields/CodeLink.vue +6 -7
- package/src/fields/CodeSelect.vue +12 -9
- package/src/fields/CodeSelectCol.vue +70 -81
- package/src/fields/DataSourceFieldSelect.vue +47 -0
- package/src/fields/DataSourceFields.vue +28 -22
- package/src/fields/DataSourceInput.vue +21 -58
- package/src/fields/DataSourceMethodSelect.vue +136 -0
- package/src/fields/DataSourceMethods.vue +103 -0
- package/src/fields/DataSourceSelect.vue +5 -12
- package/src/fields/EventSelect.vue +53 -19
- package/src/fields/KeyValue.vue +9 -11
- package/src/fields/UISelect.vue +54 -14
- package/src/hooks/index.ts +21 -0
- package/src/hooks/use-code-block-edit.ts +84 -0
- package/src/hooks/use-data-source-method.ts +100 -0
- package/src/{utils/stage.ts → hooks/use-stage.ts} +4 -7
- package/src/icons/CenterIcon.vue +13 -0
- package/src/icons/CodeIcon.vue +0 -2
- package/src/icons/FolderMinusIcon.vue +22 -0
- package/src/index.ts +12 -0
- package/src/initService.ts +69 -16
- package/src/layouts/CodeEditor.vue +35 -3
- package/src/layouts/Framework.vue +7 -3
- package/src/layouts/PropsPanel.vue +8 -3
- package/src/layouts/sidebar/ComponentListPanel.vue +4 -6
- package/src/layouts/sidebar/LayerMenu.vue +20 -21
- package/src/layouts/sidebar/LayerPanel.vue +12 -2
- package/src/layouts/sidebar/Sidebar.vue +22 -36
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +81 -119
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +64 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +27 -47
- package/src/layouts/sidebar/data-source/DataSourceList.vue +145 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +58 -85
- package/src/layouts/workspace/Stage.vue +3 -2
- package/src/layouts/workspace/ViewerMenu.vue +10 -35
- package/src/services/codeBlock.ts +18 -71
- package/src/services/dataSource.ts +16 -1
- package/src/services/dep.ts +22 -20
- package/src/services/editor.ts +46 -18
- package/src/services/props.ts +2 -2
- package/src/theme/code-block.scss +5 -117
- package/src/theme/code-editor.scss +27 -2
- package/src/theme/content-menu.scss +1 -1
- package/src/theme/data-source-methods.scss +13 -0
- package/src/theme/data-source.scss +11 -0
- package/src/theme/event.scss +15 -12
- package/src/theme/framework.scss +0 -3
- package/src/theme/layout.scss +4 -0
- package/src/theme/sidebar.scss +18 -60
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +47 -7
- package/src/utils/content-menu.ts +92 -0
- package/src/utils/data-source/formConfigs/base.ts +28 -30
- package/src/utils/data-source/index.ts +65 -2
- package/src/utils/dep.ts +33 -7
- package/src/utils/index.ts +1 -1
- package/src/utils/props.ts +298 -189
- package/src/utils/undo-redo.ts +1 -1
- package/types/Editor.vue.d.ts +30 -6
- package/types/components/CodeBlockEditor.vue.d.ts +23 -0
- package/types/components/CodeParams.vue.d.ts +26 -0
- package/types/components/ContentMenu.vue.d.ts +2 -2
- package/types/components/ToolButton.vue.d.ts +3 -3
- package/types/editorProps.d.ts +19 -5
- package/types/fields/Code.vue.d.ts +24 -19
- package/types/fields/CodeLink.vue.d.ts +12 -21
- package/types/fields/CodeSelect.vue.d.ts +6 -17
- package/types/fields/CodeSelectCol.vue.d.ts +10 -14
- package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
- package/types/fields/DataSourceFields.vue.d.ts +7 -18
- package/types/fields/DataSourceInput.vue.d.ts +10 -30
- package/types/fields/DataSourceMethodSelect.vue.d.ts +29 -0
- package/types/fields/DataSourceMethods.vue.d.ts +32 -0
- package/types/fields/DataSourceSelect.vue.d.ts +13 -29
- package/types/fields/EventSelect.vue.d.ts +2 -13
- package/types/fields/KeyValue.vue.d.ts +9 -24
- package/types/fields/UISelect.vue.d.ts +2 -11
- package/types/hooks/index.d.ts +3 -0
- package/types/{components/FunctionEditor.vue.d.ts → hooks/use-code-block-edit.d.ts} +31 -121
- package/types/hooks/use-data-source-method.d.ts +123 -0
- package/types/icons/CenterIcon.vue.d.ts +2 -0
- package/types/icons/FolderMinusIcon.vue.d.ts +2 -0
- package/types/index.d.ts +6 -0
- package/types/initService.d.ts +2 -2
- package/types/layouts/CodeEditor.vue.d.ts +7 -4
- package/types/layouts/PropsPanel.vue.d.ts +274 -2
- package/types/layouts/sidebar/Sidebar.vue.d.ts +0 -3
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +4 -9
- package/types/layouts/sidebar/code-block/{CodeBlockEditor.vue.d.ts → CodeBlockListPanel.vue.d.ts} +9 -5
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -1
- package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +14 -0
- package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +1 -11
- package/types/services/codeBlock.d.ts +6 -37
- package/types/services/dataSource.d.ts +7 -1
- package/types/services/dep.d.ts +12 -21
- package/types/services/editor.d.ts +1 -1
- package/types/services/props.d.ts +10 -115
- package/types/type.d.ts +42 -7
- package/types/utils/content-menu.d.ts +7 -0
- package/types/utils/data-source/formConfigs/base.d.ts +1 -2
- package/types/utils/data-source/index.d.ts +5 -0
- package/types/utils/dep.d.ts +4 -2
- package/types/utils/index.d.ts +1 -1
- package/types/utils/props.d.ts +13 -102
- package/src/components/CodeDraftEditor.vue +0 -148
- package/src/components/FunctionEditor.vue +0 -197
- package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -100
- package/types/components/CodeDraftEditor.vue.d.ts +0 -61
- /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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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,
|
|
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
|
|
7
|
+
import { DepTargetType, HookData } from '@editor/type';
|
|
7
8
|
|
|
8
9
|
export const createCodeBlockTarget = (id: Id, codeBlock: CodeBlockContent) =>
|
|
9
10
|
new Target({
|
|
10
|
-
type:
|
|
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
|
|
28
|
+
export const createDataSourceTarget = (id: Id) =>
|
|
28
29
|
new Target({
|
|
29
|
-
type:
|
|
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
|
|
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
|
});
|