@tmagic/editor 1.5.0-beta.14 → 1.5.0-beta.16
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 +61 -6
- package/dist/tmagic-editor.js +507 -242
- package/dist/tmagic-editor.umd.cjs +507 -243
- package/package.json +12 -10
- package/src/components/CodeBlockEditor.vue +11 -5
- package/src/components/CodeParams.vue +3 -3
- package/src/fields/Code.vue +1 -2
- package/src/fields/CodeSelect.vue +13 -11
- package/src/fields/CodeSelectCol.vue +32 -5
- package/src/fields/CondOpSelect.vue +5 -2
- package/src/fields/DataSourceFields.vue +31 -12
- package/src/fields/DataSourceMethods.vue +72 -14
- package/src/fields/DisplayConds.vue +8 -3
- package/src/fields/EventSelect.vue +25 -8
- package/src/fields/KeyValue.vue +15 -10
- package/src/hooks/index.ts +0 -1
- package/src/hooks/use-code-block-edit.ts +1 -1
- package/src/hooks/use-data-source-edit.ts +3 -2
- package/src/initService.ts +105 -25
- package/src/layouts/Framework.vue +0 -3
- package/src/layouts/PropsPanel.vue +3 -3
- package/src/layouts/page-bar/PageBar.vue +46 -3
- package/src/layouts/page-bar/PageBarScrollContainer.vue +49 -24
- package/src/layouts/page-bar/PageList.vue +4 -2
- package/src/layouts/sidebar/Sidebar.vue +3 -0
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +6 -1
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +7 -5
- package/src/layouts/sidebar/data-source/DataSourceList.vue +6 -1
- package/src/layouts/workspace/Workspace.vue +5 -2
- package/src/layouts/workspace/viewer/Stage.vue +12 -5
- package/src/services/dataSource.ts +12 -5
- package/src/services/dep.ts +49 -11
- package/src/services/editor.ts +26 -11
- package/src/theme/page-bar.scss +24 -9
- package/src/theme/search-input.scss +1 -0
- package/src/utils/data-source/formConfigs/http.ts +2 -0
- package/src/utils/data-source/index.ts +2 -2
- package/src/utils/editor.ts +78 -2
- package/src/utils/idle-task.ts +34 -3
- package/src/utils/props.ts +3 -3
- package/types/index.d.ts +805 -1170
- package/src/hooks/use-data-source-method.ts +0 -100
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { nextTick, ref } from 'vue';
|
|
2
|
-
import { cloneDeep } from 'lodash-es';
|
|
3
|
-
|
|
4
|
-
import type { CodeBlockContent, DataSourceSchema } from '@tmagic/core';
|
|
5
|
-
import { tMagicMessage } from '@tmagic/design';
|
|
6
|
-
|
|
7
|
-
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
8
|
-
import { getEditorConfig } from '@editor/utils/config';
|
|
9
|
-
|
|
10
|
-
export const useDataSourceMethod = () => {
|
|
11
|
-
const codeConfig = ref<CodeBlockContent>();
|
|
12
|
-
const codeBlockEditor = ref<InstanceType<typeof CodeBlockEditor>>();
|
|
13
|
-
|
|
14
|
-
const dataSource = ref<DataSourceSchema>();
|
|
15
|
-
const dataSourceMethod = ref('');
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
codeConfig,
|
|
19
|
-
codeBlockEditor,
|
|
20
|
-
|
|
21
|
-
createCode: async (model: DataSourceSchema) => {
|
|
22
|
-
codeConfig.value = {
|
|
23
|
-
name: '',
|
|
24
|
-
content: `({ params, dataSource, app }) => {\n // place your code here\n}`,
|
|
25
|
-
params: [],
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
await nextTick();
|
|
29
|
-
|
|
30
|
-
dataSource.value = model;
|
|
31
|
-
dataSourceMethod.value = '';
|
|
32
|
-
|
|
33
|
-
codeBlockEditor.value?.show();
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
editCode: async (model: DataSourceSchema, methodName: string) => {
|
|
37
|
-
const method = model.methods?.find((method) => method.name === methodName);
|
|
38
|
-
|
|
39
|
-
if (!method) {
|
|
40
|
-
tMagicMessage.error('获取数据源方法失败');
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let codeContent = method.content || `({ params, dataSource, app }) => {\n // place your code here\n}`;
|
|
45
|
-
|
|
46
|
-
if (typeof codeContent !== 'string') {
|
|
47
|
-
codeContent = codeContent.toString();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
codeConfig.value = {
|
|
51
|
-
...cloneDeep(method),
|
|
52
|
-
content: codeContent,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
await nextTick();
|
|
56
|
-
|
|
57
|
-
dataSource.value = model;
|
|
58
|
-
dataSourceMethod.value = methodName;
|
|
59
|
-
|
|
60
|
-
codeBlockEditor.value?.show();
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
deleteCode: async (model: DataSourceSchema, methodName: string) => {
|
|
64
|
-
if (!model.methods) return;
|
|
65
|
-
|
|
66
|
-
const index = model.methods.findIndex((method) => method.name === methodName);
|
|
67
|
-
|
|
68
|
-
if (index === -1) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
model.methods.splice(index, 1);
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
submitCode: (values: CodeBlockContent) => {
|
|
76
|
-
if (!dataSource.value) return;
|
|
77
|
-
|
|
78
|
-
if (!dataSource.value.methods) {
|
|
79
|
-
dataSource.value.methods = [];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (values.content) {
|
|
83
|
-
// 在保存的时候转换代码内容
|
|
84
|
-
const parseDSL = getEditorConfig('parseDSL');
|
|
85
|
-
if (typeof values.content === 'string') {
|
|
86
|
-
values.content = parseDSL<(...args: any[]) => any>(values.content);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (dataSourceMethod.value) {
|
|
91
|
-
const index = dataSource.value.methods.findIndex((method) => method.name === dataSourceMethod.value);
|
|
92
|
-
dataSource.value.methods.splice(index, 1, values);
|
|
93
|
-
} else {
|
|
94
|
-
dataSource.value.methods.push(values);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
codeBlockEditor.value?.hide();
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
};
|