@tmagic/editor 1.3.0-alpha.2 → 1.3.0-alpha.21
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 +91 -120
- package/dist/tmagic-editor.js +4609 -3257
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +5708 -4337
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +21 -22
- package/src/Editor.vue +29 -7
- package/src/components/CodeBlockEditor.vue +170 -0
- package/src/components/CodeParams.vue +60 -0
- package/src/components/ContentMenu.vue +30 -11
- package/src/components/Icon.vue +5 -1
- package/src/components/Resizer.vue +45 -0
- package/src/components/ScrollBar.vue +5 -1
- package/src/components/ScrollViewer.vue +5 -1
- package/src/components/SearchInput.vue +4 -0
- package/src/components/{Layout.vue → SplitView.vue} +8 -4
- package/src/components/ToolButton.vue +5 -1
- package/src/editorProps.ts +35 -4
- package/src/fields/Code.vue +28 -20
- package/src/fields/CodeLink.vue +15 -10
- package/src/fields/CodeSelect.vue +19 -10
- package/src/fields/CodeSelectCol.vue +67 -83
- package/src/fields/DataSourceFieldSelect.vue +47 -0
- package/src/fields/DataSourceFields.vue +24 -21
- package/src/fields/DataSourceInput.vue +318 -0
- package/src/fields/DataSourceMethodSelect.vue +136 -0
- package/src/fields/DataSourceMethods.vue +103 -0
- package/src/fields/DataSourceSelect.vue +68 -0
- package/src/fields/EventSelect.vue +62 -22
- package/src/fields/KeyValue.vue +13 -11
- package/src/fields/UISelect.vue +59 -15
- 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/AppManageIcon.vue +5 -1
- package/src/icons/CenterIcon.vue +13 -0
- package/src/icons/CodeIcon.vue +5 -3
- package/src/index.ts +24 -3
- package/src/initService.ts +75 -16
- package/src/layouts/AddPageBox.vue +5 -1
- package/src/layouts/CodeEditor.vue +66 -11
- package/src/layouts/Framework.vue +32 -28
- package/src/layouts/NavMenu.vue +5 -1
- package/src/layouts/PropsPanel.vue +14 -4
- package/src/layouts/sidebar/ComponentListPanel.vue +11 -10
- package/src/layouts/sidebar/LayerMenu.vue +13 -25
- package/src/layouts/sidebar/LayerNode.vue +40 -0
- package/src/layouts/sidebar/LayerPanel.vue +71 -28
- package/src/layouts/sidebar/Sidebar.vue +13 -17
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +84 -118
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +63 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +39 -34
- package/src/layouts/sidebar/data-source/DataSourceList.vue +145 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +17 -65
- package/src/layouts/workspace/Breadcrumb.vue +5 -1
- package/src/layouts/workspace/PageBar.vue +5 -1
- package/src/layouts/workspace/PageBarScrollContainer.vue +5 -1
- package/src/layouts/workspace/Stage.vue +30 -8
- package/src/layouts/workspace/ViewerMenu.vue +15 -36
- package/src/layouts/workspace/Workspace.vue +9 -134
- package/src/services/codeBlock.ts +20 -72
- package/src/services/dataSource.ts +17 -2
- package/src/services/dep.ts +23 -20
- package/src/services/editor.ts +3 -3
- package/src/services/keybinding.ts +185 -0
- package/src/services/props.ts +2 -2
- package/src/services/storage.ts +3 -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-input.scss +18 -0
- package/src/theme/data-source-methods.scss +13 -0
- package/src/theme/event.scss +15 -12
- package/src/theme/framework.scss +0 -3
- package/src/theme/layer-panel.scss +6 -0
- package/src/theme/layout.scss +4 -0
- package/src/theme/resizer.scss +25 -10
- package/src/theme/stage.scss +4 -0
- package/src/theme/theme.scss +2 -0
- package/src/type.ts +105 -7
- package/src/utils/config.ts +1 -1
- package/src/utils/content-menu.ts +92 -0
- package/src/utils/data-source/formConfigs/base.ts +35 -30
- package/src/utils/data-source/index.ts +75 -6
- package/src/utils/dep.ts +39 -7
- package/src/utils/index.ts +1 -1
- package/src/utils/keybinding-config.ts +120 -0
- package/src/utils/props.ts +298 -155
- package/src/utils/undo-redo.ts +1 -1
- package/types/Editor.vue.d.ts +37 -4
- 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 +8 -3
- package/types/components/Icon.vue.d.ts +2 -2
- package/types/{layouts → components}/Resizer.vue.d.ts +2 -2
- package/types/components/ScrollBar.vue.d.ts +1 -1
- package/types/components/ScrollViewer.vue.d.ts +8 -5
- package/types/components/SearchInput.vue.d.ts +1 -1
- package/types/components/{Layout.vue.d.ts → SplitView.vue.d.ts} +9 -6
- package/types/components/ToolButton.vue.d.ts +10 -7
- package/types/editorProps.d.ts +23 -4
- package/types/fields/Code.vue.d.ts +23 -18
- package/types/fields/CodeLink.vue.d.ts +13 -22
- package/types/fields/CodeSelect.vue.d.ts +12 -20
- package/types/fields/CodeSelectCol.vue.d.ts +14 -15
- package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
- package/types/fields/DataSourceFields.vue.d.ts +13 -21
- package/types/fields/DataSourceInput.vue.d.ts +34 -0
- 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 +40 -0
- package/types/fields/EventSelect.vue.d.ts +3 -14
- package/types/fields/KeyValue.vue.d.ts +15 -27
- package/types/fields/UISelect.vue.d.ts +3 -12
- package/types/hooks/index.d.ts +3 -0
- package/types/hooks/use-code-block-edit.d.ts +125 -0
- package/types/hooks/use-data-source-method.d.ts +123 -0
- package/types/icons/AppManageIcon.vue.d.ts +1 -1
- package/types/icons/CenterIcon.vue.d.ts +2 -0
- package/types/icons/CodeIcon.vue.d.ts +1 -1
- package/types/index.d.ts +12 -2
- package/types/initService.d.ts +2 -2
- package/types/layouts/AddPageBox.vue.d.ts +1 -1
- package/types/layouts/CodeEditor.vue.d.ts +18 -10
- package/types/layouts/Framework.vue.d.ts +11 -32
- package/types/layouts/NavMenu.vue.d.ts +7 -4
- package/types/layouts/PropsPanel.vue.d.ts +276 -4
- package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +4 -4
- package/types/layouts/sidebar/LayerMenu.vue.d.ts +2 -2
- package/types/layouts/sidebar/LayerNode.vue.d.ts +16 -0
- package/types/layouts/sidebar/LayerPanel.vue.d.ts +5 -5
- package/types/layouts/sidebar/Sidebar.vue.d.ts +16 -16
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +7 -12
- package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +28 -0
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +4 -2
- 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/layouts/workspace/Breadcrumb.vue.d.ts +1 -1
- package/types/layouts/workspace/PageBar.vue.d.ts +5 -5
- package/types/layouts/workspace/PageBarScrollContainer.vue.d.ts +2 -2
- package/types/layouts/workspace/Stage.vue.d.ts +2 -2
- package/types/layouts/workspace/ViewerMenu.vue.d.ts +7 -4
- package/types/layouts/workspace/Workspace.vue.d.ts +9 -9
- 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/keybinding.d.ts +20 -0
- package/types/services/props.d.ts +10 -115
- package/types/type.d.ts +97 -7
- package/types/utils/config.d.ts +1 -1
- package/types/utils/content-menu.d.ts +7 -0
- package/types/utils/data-source/formConfigs/base.d.ts +2 -2
- package/types/utils/data-source/index.d.ts +7 -1
- package/types/utils/dep.d.ts +4 -2
- package/types/utils/index.d.ts +1 -1
- package/types/utils/keybinding-config.d.ts +3 -0
- package/types/utils/props.d.ts +13 -102
- package/src/components/CodeDraftEditor.vue +0 -144
- package/src/components/FunctionEditor.vue +0 -190
- package/src/layouts/Resizer.vue +0 -32
- package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -96
- package/types/components/CodeDraftEditor.vue.d.ts +0 -58
- package/types/components/FunctionEditor.vue.d.ts +0 -192
- package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +0 -25
- /package/types/{utils/stage.d.ts → hooks/use-stage.d.ts} +0 -0
package/src/editorProps.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { PropType } from 'vue';
|
|
2
2
|
|
|
3
3
|
import type { EventOption } from '@tmagic/core';
|
|
4
|
-
import type { FormConfig } from '@tmagic/form';
|
|
5
|
-
import type { MApp, MNode } from '@tmagic/schema';
|
|
4
|
+
import type { FormConfig, FormState } from '@tmagic/form';
|
|
5
|
+
import type { DataSourceSchema, MApp, MNode } from '@tmagic/schema';
|
|
6
6
|
import StageCore, {
|
|
7
7
|
CONTAINER_HIGHLIGHT_CLASS_NAME,
|
|
8
8
|
ContainerHighlightType,
|
|
@@ -11,7 +11,15 @@ import StageCore, {
|
|
|
11
11
|
UpdateDragEl,
|
|
12
12
|
} from '@tmagic/stage';
|
|
13
13
|
|
|
14
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
ComponentGroup,
|
|
16
|
+
DatasourceTypeOption,
|
|
17
|
+
MenuBarData,
|
|
18
|
+
MenuButton,
|
|
19
|
+
MenuComponent,
|
|
20
|
+
SideBarData,
|
|
21
|
+
StageRect,
|
|
22
|
+
} from './type';
|
|
15
23
|
|
|
16
24
|
export default {
|
|
17
25
|
/** 页面初始值 */
|
|
@@ -27,6 +35,12 @@ export default {
|
|
|
27
35
|
default: () => [],
|
|
28
36
|
},
|
|
29
37
|
|
|
38
|
+
/** 左侧面板中的组件列表 */
|
|
39
|
+
datasourceList: {
|
|
40
|
+
type: Array as PropType<DatasourceTypeOption[]>,
|
|
41
|
+
default: () => [],
|
|
42
|
+
},
|
|
43
|
+
|
|
30
44
|
/** 左侧面板配置 */
|
|
31
45
|
sidebar: {
|
|
32
46
|
type: Object as PropType<SideBarData>,
|
|
@@ -69,7 +83,7 @@ export default {
|
|
|
69
83
|
|
|
70
84
|
/** 添加组件时的默认值 */
|
|
71
85
|
propsValues: {
|
|
72
|
-
type: Object as PropType<Record<string, MNode
|
|
86
|
+
type: Object as PropType<Record<string, Partial<MNode>>>,
|
|
73
87
|
default: () => ({}),
|
|
74
88
|
},
|
|
75
89
|
|
|
@@ -79,6 +93,19 @@ export default {
|
|
|
79
93
|
default: () => ({}),
|
|
80
94
|
},
|
|
81
95
|
|
|
96
|
+
/** 组件的属性配置表单的dsl */
|
|
97
|
+
datasourceConfigs: {
|
|
98
|
+
type: Object as PropType<Record<string, FormConfig>>,
|
|
99
|
+
default: () => ({}),
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
/** 添加数据源时的默认值 */
|
|
103
|
+
datasourceValues: {
|
|
104
|
+
type: Object as PropType<Record<string, Partial<DataSourceSchema>>>,
|
|
105
|
+
default: () => ({}),
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/** 数据源的属性配置表单的dsl */
|
|
82
109
|
dataScourceConfigs: {
|
|
83
110
|
type: Object as PropType<Record<string, FormConfig>>,
|
|
84
111
|
default: () => ({}),
|
|
@@ -137,4 +164,8 @@ export default {
|
|
|
137
164
|
disabledDragStart: {
|
|
138
165
|
type: Boolean,
|
|
139
166
|
},
|
|
167
|
+
|
|
168
|
+
extendFormState: {
|
|
169
|
+
type: Function as PropType<(state: FormState) => Record<string, any> | Promise<Record<string, any>>>,
|
|
170
|
+
},
|
|
140
171
|
};
|
package/src/fields/Code.vue
CHANGED
|
@@ -1,31 +1,39 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
:
|
|
2
|
+
<MagicCodeEditor
|
|
3
|
+
:height="config.height"
|
|
4
4
|
:init-values="model[name]"
|
|
5
|
-
:language="language"
|
|
6
|
-
:options="
|
|
5
|
+
:language="config.language"
|
|
6
|
+
:options="{
|
|
7
|
+
...config.options,
|
|
8
|
+
readOnly: disabled,
|
|
9
|
+
}"
|
|
7
10
|
@save="save"
|
|
8
|
-
></
|
|
11
|
+
></MagicCodeEditor>
|
|
9
12
|
</template>
|
|
10
13
|
|
|
11
|
-
<script lang="ts" setup
|
|
12
|
-
import {
|
|
14
|
+
<script lang="ts" setup>
|
|
15
|
+
import type { FieldProps } from '@tmagic/form';
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
|
|
18
|
+
|
|
19
|
+
defineOptions({
|
|
20
|
+
name: 'MEditorCode',
|
|
21
|
+
});
|
|
15
22
|
|
|
16
|
-
const
|
|
17
|
-
model: any;
|
|
18
|
-
name: string;
|
|
19
|
-
config: {
|
|
20
|
-
language?: string;
|
|
21
|
-
options?: Object;
|
|
22
|
-
height?: string;
|
|
23
|
-
};
|
|
24
|
-
prop: string;
|
|
25
|
-
}>();
|
|
23
|
+
const emit = defineEmits(['change']);
|
|
26
24
|
|
|
27
|
-
const
|
|
28
|
-
|
|
25
|
+
const props = withDefaults(
|
|
26
|
+
defineProps<
|
|
27
|
+
FieldProps<{
|
|
28
|
+
language?: string;
|
|
29
|
+
options?: Object;
|
|
30
|
+
height?: string;
|
|
31
|
+
}>
|
|
32
|
+
>(),
|
|
33
|
+
{
|
|
34
|
+
disabled: false,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
29
37
|
|
|
30
38
|
const save = (v: string) => {
|
|
31
39
|
props.model[props.name] = v;
|
package/src/fields/CodeLink.vue
CHANGED
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
<m-fields-link :config="formConfig" :model="modelValue" name="form" @change="changeHandler"></m-fields-link>
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
|
-
<script lang="ts" setup
|
|
5
|
+
<script lang="ts" setup>
|
|
6
6
|
import { computed, reactive, watch } from 'vue';
|
|
7
7
|
import serialize from 'serialize-javascript';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import type { FieldProps } from '@tmagic/form';
|
|
10
|
+
|
|
11
|
+
import { getConfig } from '@editor/utils/config';
|
|
12
|
+
|
|
13
|
+
defineOptions({
|
|
14
|
+
name: 'MEditorCodeLink',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const props = defineProps<
|
|
18
|
+
FieldProps<{
|
|
11
19
|
type: 'code-link';
|
|
12
20
|
name: string;
|
|
13
21
|
text?: string;
|
|
14
22
|
formTitle?: string;
|
|
15
23
|
codeOptions?: Object;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
name: string;
|
|
19
|
-
prop: string;
|
|
20
|
-
}>();
|
|
24
|
+
}>
|
|
25
|
+
>();
|
|
21
26
|
|
|
22
27
|
const emit = defineEmits(['change']);
|
|
23
28
|
|
|
@@ -65,8 +70,8 @@ const changeHandler = (v: Record<string, any>) => {
|
|
|
65
70
|
if (!props.name || !props.model) return;
|
|
66
71
|
|
|
67
72
|
try {
|
|
68
|
-
|
|
69
|
-
props.model[props.name] =
|
|
73
|
+
const parseDSL = getConfig('parseDSL');
|
|
74
|
+
props.model[props.name] = parseDSL(`(${v[props.name]})`);
|
|
70
75
|
emit('change', props.model[props.name]);
|
|
71
76
|
} catch (e) {
|
|
72
77
|
console.error(e);
|
|
@@ -6,25 +6,30 @@
|
|
|
6
6
|
</div>
|
|
7
7
|
</template>
|
|
8
8
|
|
|
9
|
-
<script lang="ts" setup
|
|
10
|
-
import { computed,
|
|
9
|
+
<script lang="ts" setup>
|
|
10
|
+
import { computed, inject, watch } from 'vue';
|
|
11
11
|
import { isEmpty } from 'lodash-es';
|
|
12
12
|
|
|
13
13
|
import { TMagicCard } from '@tmagic/design';
|
|
14
|
+
import type { FieldProps } from '@tmagic/form';
|
|
14
15
|
import { HookType } from '@tmagic/schema';
|
|
15
16
|
|
|
17
|
+
import type { Services } from '@editor/type';
|
|
18
|
+
|
|
19
|
+
defineOptions({
|
|
20
|
+
name: 'MEditorCodeSelect',
|
|
21
|
+
});
|
|
22
|
+
|
|
16
23
|
const emit = defineEmits(['change']);
|
|
17
24
|
|
|
25
|
+
const services = inject<Services>('services');
|
|
26
|
+
|
|
18
27
|
const props = withDefaults(
|
|
19
|
-
defineProps<
|
|
20
|
-
|
|
28
|
+
defineProps<
|
|
29
|
+
FieldProps<{
|
|
21
30
|
className?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
prop: string;
|
|
25
|
-
name: string;
|
|
26
|
-
size: 'small' | 'default' | 'large';
|
|
27
|
-
}>(),
|
|
31
|
+
}>
|
|
32
|
+
>(),
|
|
28
33
|
{},
|
|
29
34
|
);
|
|
30
35
|
|
|
@@ -32,10 +37,14 @@ const codeConfig = computed(() => ({
|
|
|
32
37
|
type: 'group-list',
|
|
33
38
|
name: 'hookData',
|
|
34
39
|
enableToggleMode: false,
|
|
40
|
+
expandAll: true,
|
|
41
|
+
titleKey: 'codeId',
|
|
35
42
|
items: [
|
|
36
43
|
{
|
|
37
44
|
type: 'code-select-col',
|
|
45
|
+
name: 'codeId',
|
|
38
46
|
labelWidth: 0,
|
|
47
|
+
disabled: () => !services?.codeBlockService.getEditStatus(),
|
|
39
48
|
},
|
|
40
49
|
],
|
|
41
50
|
}));
|
|
@@ -9,53 +9,80 @@
|
|
|
9
9
|
@change="onParamsChangeHandler"
|
|
10
10
|
></m-form-container>
|
|
11
11
|
<!-- 查看/编辑按钮 -->
|
|
12
|
-
<Icon class="icon" :icon="
|
|
12
|
+
<Icon v-if="model[name]" class="icon" :icon="!disabled ? Edit : View" @click="editCode(model[name])"></Icon>
|
|
13
13
|
</div>
|
|
14
|
+
|
|
14
15
|
<!-- 参数填写框 -->
|
|
15
|
-
<
|
|
16
|
+
<CodeParams
|
|
17
|
+
v-if="paramsConfig.length"
|
|
18
|
+
name="params"
|
|
19
|
+
:model="model"
|
|
20
|
+
:size="size"
|
|
21
|
+
:params-config="paramsConfig"
|
|
22
|
+
@change="onParamsChangeHandler"
|
|
23
|
+
></CodeParams>
|
|
24
|
+
|
|
25
|
+
<CodeBlockEditor
|
|
26
|
+
ref="codeBlockEditor"
|
|
27
|
+
v-if="codeConfig"
|
|
28
|
+
:disabled="disabled"
|
|
29
|
+
:content="codeConfig"
|
|
30
|
+
@submit="submitCodeBlockHandler"
|
|
31
|
+
></CodeBlockEditor>
|
|
16
32
|
</div>
|
|
17
33
|
</template>
|
|
18
34
|
|
|
19
|
-
<script lang="ts" setup name="
|
|
20
|
-
import { computed,
|
|
35
|
+
<script lang="ts" setup name="">
|
|
36
|
+
import { computed, inject, ref } from 'vue';
|
|
21
37
|
import { Edit, View } from '@element-plus/icons-vue';
|
|
22
38
|
import { isEmpty, map } from 'lodash-es';
|
|
23
39
|
|
|
24
|
-
import { createValues,
|
|
25
|
-
import { Id } from '@tmagic/schema';
|
|
40
|
+
import { createValues, FieldProps } from '@tmagic/form';
|
|
41
|
+
import type { Id } from '@tmagic/schema';
|
|
26
42
|
|
|
43
|
+
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
44
|
+
import CodeParams from '@editor/components/CodeParams.vue';
|
|
27
45
|
import Icon from '@editor/components/Icon.vue';
|
|
28
|
-
import
|
|
46
|
+
import { useCodeBlockEdit } from '@editor/hooks/use-code-block-edit';
|
|
47
|
+
import type { CodeParamStatement, CodeSelectColConfig, Services } from '@editor/type';
|
|
48
|
+
|
|
49
|
+
defineOptions({
|
|
50
|
+
name: 'MEditorCodeSelectCol',
|
|
51
|
+
});
|
|
29
52
|
|
|
30
53
|
const services = inject<Services>('services');
|
|
31
|
-
const mForm = inject<FormState>('mForm');
|
|
32
54
|
const emit = defineEmits(['change']);
|
|
33
55
|
|
|
34
|
-
const props = withDefaults(
|
|
35
|
-
|
|
36
|
-
config: any;
|
|
37
|
-
model: any;
|
|
38
|
-
prop: string;
|
|
39
|
-
name: string;
|
|
40
|
-
size: 'small' | 'default' | 'large';
|
|
41
|
-
}>(),
|
|
42
|
-
{},
|
|
43
|
-
);
|
|
44
|
-
const codeDsl = computed(() => services?.codeBlockService.getCodeDsl());
|
|
45
|
-
const editable = computed(() => services?.codeBlockService.getEditStatus());
|
|
46
|
-
const codeParamsConfig = ref<FieldsetConfig>({
|
|
47
|
-
type: 'fieldset',
|
|
48
|
-
items: [],
|
|
49
|
-
legend: '参数',
|
|
50
|
-
labelWidth: '70px',
|
|
51
|
-
name: 'params',
|
|
52
|
-
display: false,
|
|
56
|
+
const props = withDefaults(defineProps<FieldProps<CodeSelectColConfig>>(), {
|
|
57
|
+
disabled: false,
|
|
53
58
|
});
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 根据代码块id获取代码块参数配置
|
|
62
|
+
* @param codeId 代码块ID
|
|
63
|
+
*/
|
|
64
|
+
const getParamItemsConfig = (codeId?: Id): CodeParamStatement[] => {
|
|
65
|
+
if (!codeDsl.value || !codeId) return [];
|
|
66
|
+
|
|
67
|
+
const paramStatements = codeDsl.value[codeId]?.params;
|
|
68
|
+
|
|
69
|
+
if (isEmpty(paramStatements)) return [];
|
|
70
|
+
|
|
71
|
+
return paramStatements.map((paramState: CodeParamStatement) => ({
|
|
72
|
+
labelWidth: '100px',
|
|
73
|
+
text: paramState.name,
|
|
74
|
+
...paramState,
|
|
75
|
+
}));
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const codeDsl = computed(() => services?.codeBlockService.getCodeDsl());
|
|
79
|
+
const paramsConfig = ref<CodeParamStatement[]>(getParamItemsConfig(props.model[props.name]));
|
|
80
|
+
|
|
54
81
|
const selectConfig = {
|
|
55
82
|
type: 'select',
|
|
56
83
|
text: '代码块',
|
|
57
|
-
name:
|
|
58
|
-
labelWidth: '
|
|
84
|
+
name: props.name,
|
|
85
|
+
labelWidth: '80px',
|
|
59
86
|
options: () => {
|
|
60
87
|
if (codeDsl.value) {
|
|
61
88
|
return map(codeDsl.value, (value, key) => ({
|
|
@@ -68,68 +95,25 @@ const selectConfig = {
|
|
|
68
95
|
},
|
|
69
96
|
onChange: (formState: any, codeId: Id, { model }: any) => {
|
|
70
97
|
// 通过下拉框选择的codeId变化后修正model的值,避免写入其他codeId的params
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
};
|
|
98
|
+
paramsConfig.value = getParamItemsConfig(codeId);
|
|
74
99
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (!codeDsl.value) return [];
|
|
81
|
-
const paramStatements = codeDsl.value[codeId]?.params;
|
|
82
|
-
if (isEmpty(paramStatements)) return [];
|
|
83
|
-
return paramStatements.map((paramState: CodeParamStatement) => ({
|
|
84
|
-
labelWidth: '100px',
|
|
85
|
-
text: paramState.name,
|
|
86
|
-
...paramState,
|
|
87
|
-
}));
|
|
88
|
-
};
|
|
100
|
+
if (paramsConfig.value.length) {
|
|
101
|
+
model.params = createValues(formState, paramsConfig.value, {}, model.params);
|
|
102
|
+
} else {
|
|
103
|
+
model.params = {};
|
|
104
|
+
}
|
|
89
105
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* @param codeId 代码块ID
|
|
93
|
-
*/
|
|
94
|
-
const getCodeParamsConfig = (codeId: Id) => {
|
|
95
|
-
const paramsConfig = getParamItemsConfig(codeId);
|
|
96
|
-
// 如果参数没有填值,则使用createValues补全空值
|
|
97
|
-
if (!props.model.params || isEmpty(props.model.params)) {
|
|
98
|
-
props.model.params = {};
|
|
99
|
-
createValues(mForm, paramsConfig, {}, props.model.params);
|
|
100
|
-
}
|
|
101
|
-
codeParamsConfig.value = {
|
|
102
|
-
type: 'fieldset',
|
|
103
|
-
items: paramsConfig,
|
|
104
|
-
legend: '参数',
|
|
105
|
-
labelWidth: '70px',
|
|
106
|
-
name: 'params',
|
|
107
|
-
display: !isEmpty(paramsConfig),
|
|
108
|
-
};
|
|
106
|
+
return codeId;
|
|
107
|
+
},
|
|
109
108
|
};
|
|
110
109
|
|
|
111
110
|
/**
|
|
112
111
|
* 参数值修改更新
|
|
113
112
|
*/
|
|
114
|
-
const onParamsChangeHandler = () => {
|
|
113
|
+
const onParamsChangeHandler = (value: any) => {
|
|
114
|
+
props.model.params = value.params;
|
|
115
115
|
emit('change', props.model);
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
// TODO onchange在watch之前触发
|
|
120
|
-
watch(
|
|
121
|
-
() => props.model.codeId,
|
|
122
|
-
(codeId: Id) => {
|
|
123
|
-
if (!codeId) return;
|
|
124
|
-
getCodeParamsConfig(codeId);
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
immediate: true,
|
|
128
|
-
},
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
// 打开代码编辑框
|
|
132
|
-
const editCode = () => {
|
|
133
|
-
services?.codeBlockService.setCodeEditorContent(true, props.model.codeId);
|
|
134
|
-
};
|
|
118
|
+
const { codeBlockEditor, codeConfig, editCode, submitCodeBlockHandler } = useCodeBlockEdit(services?.codeBlockService);
|
|
135
119
|
</script>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<m-form-container
|
|
3
|
+
:config="{
|
|
4
|
+
...config,
|
|
5
|
+
...cascaderConfig,
|
|
6
|
+
}"
|
|
7
|
+
:model="model"
|
|
8
|
+
@change="onChangeHandler"
|
|
9
|
+
></m-form-container>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
import { computed, inject } from 'vue';
|
|
14
|
+
|
|
15
|
+
import type { FieldProps } from '@tmagic/form';
|
|
16
|
+
|
|
17
|
+
import type { DataSourceFieldSelectConfig, Services } from '@editor/type';
|
|
18
|
+
|
|
19
|
+
const services = inject<Services>('services');
|
|
20
|
+
const emit = defineEmits(['change']);
|
|
21
|
+
|
|
22
|
+
const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(), {
|
|
23
|
+
disabled: false,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
|
|
27
|
+
|
|
28
|
+
const cascaderConfig = {
|
|
29
|
+
type: 'cascader',
|
|
30
|
+
name: props.name,
|
|
31
|
+
options: () =>
|
|
32
|
+
dataSources.value
|
|
33
|
+
?.filter((ds) => ds.fields?.length)
|
|
34
|
+
?.map((ds) => ({
|
|
35
|
+
label: ds.title || ds.id,
|
|
36
|
+
value: ds.id,
|
|
37
|
+
children: ds.fields?.map((field) => ({
|
|
38
|
+
label: field.title,
|
|
39
|
+
value: field.name,
|
|
40
|
+
})),
|
|
41
|
+
})) || [],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const onChangeHandler = (value: any) => {
|
|
45
|
+
emit('change', value);
|
|
46
|
+
};
|
|
47
|
+
</script>
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="m-editor-data-source-fields">
|
|
3
|
-
<MagicTable :data="model[name]" :columns="
|
|
3
|
+
<MagicTable :data="model[name]" :columns="fieldColumns"></MagicTable>
|
|
4
4
|
|
|
5
5
|
<div class="m-editor-data-source-fields-footer">
|
|
6
6
|
<TMagicButton size="small" type="primary" :disabled="disabled" plain @click="newHandler()">添加</TMagicButton>
|
|
7
7
|
</div>
|
|
8
8
|
|
|
9
|
-
<
|
|
9
|
+
<MFormDrawer
|
|
10
10
|
ref="addDialog"
|
|
11
|
+
label-width="80px"
|
|
11
12
|
:title="filedTitle"
|
|
12
13
|
:config="dataSourceFieldsConfig"
|
|
13
14
|
:values="fieldValues"
|
|
14
15
|
:parentValues="model[name]"
|
|
16
|
+
:disabled="disabled"
|
|
15
17
|
@submit="fieldChange"
|
|
16
|
-
></
|
|
18
|
+
></MFormDrawer>
|
|
17
19
|
</div>
|
|
18
20
|
</template>
|
|
19
21
|
|
|
@@ -21,19 +23,19 @@
|
|
|
21
23
|
import { ref } from 'vue';
|
|
22
24
|
|
|
23
25
|
import { TMagicButton, tMagicMessageBox } from '@tmagic/design';
|
|
24
|
-
import { FormConfig, FormState,
|
|
26
|
+
import { FieldProps, FormConfig, FormState, MFormDrawer } from '@tmagic/form';
|
|
25
27
|
import { MagicTable } from '@tmagic/table';
|
|
26
28
|
|
|
29
|
+
defineOptions({
|
|
30
|
+
name: 'MEditorDataSourceFields',
|
|
31
|
+
});
|
|
32
|
+
|
|
27
33
|
const props = withDefaults(
|
|
28
|
-
defineProps<
|
|
29
|
-
|
|
34
|
+
defineProps<
|
|
35
|
+
FieldProps<{
|
|
30
36
|
type: 'data-source-fields';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
prop: string;
|
|
34
|
-
disabled: boolean;
|
|
35
|
-
name: string;
|
|
36
|
-
}>(),
|
|
37
|
+
}>
|
|
38
|
+
>(),
|
|
37
39
|
{
|
|
38
40
|
disabled: false,
|
|
39
41
|
},
|
|
@@ -41,32 +43,29 @@ const props = withDefaults(
|
|
|
41
43
|
|
|
42
44
|
const emit = defineEmits(['change']);
|
|
43
45
|
|
|
44
|
-
const addDialog = ref<InstanceType<typeof
|
|
46
|
+
const addDialog = ref<InstanceType<typeof MFormDrawer>>();
|
|
45
47
|
const fieldValues = ref<Record<string, any>>({});
|
|
46
48
|
const filedTitle = ref('');
|
|
47
49
|
|
|
48
50
|
const newHandler = () => {
|
|
49
|
-
if (!addDialog.value) return;
|
|
50
51
|
fieldValues.value = {};
|
|
51
52
|
filedTitle.value = '新增属性';
|
|
52
|
-
addDialog.value
|
|
53
|
+
addDialog.value?.show();
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
const fieldChange = ({ index, ...value }: Record<string, any>) => {
|
|
56
|
-
if (!addDialog.value) return;
|
|
57
|
-
|
|
58
57
|
if (index > -1) {
|
|
59
58
|
props.model[props.name][index] = value;
|
|
60
59
|
} else {
|
|
61
60
|
props.model[props.name].push(value);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
addDialog.value
|
|
63
|
+
addDialog.value?.hide();
|
|
65
64
|
|
|
66
65
|
emit('change', props.model[props.name]);
|
|
67
66
|
};
|
|
68
67
|
|
|
69
|
-
const
|
|
68
|
+
const fieldColumns = [
|
|
70
69
|
{
|
|
71
70
|
label: '属性名称',
|
|
72
71
|
prop: 'title',
|
|
@@ -79,6 +78,10 @@ const filedColumns = [
|
|
|
79
78
|
label: '属性描述',
|
|
80
79
|
prop: 'desc',
|
|
81
80
|
},
|
|
81
|
+
{
|
|
82
|
+
label: '默认值',
|
|
83
|
+
prop: 'defaultValue',
|
|
84
|
+
},
|
|
82
85
|
{
|
|
83
86
|
label: '操作',
|
|
84
87
|
fixed: 'right',
|
|
@@ -86,13 +89,12 @@ const filedColumns = [
|
|
|
86
89
|
{
|
|
87
90
|
text: '编辑',
|
|
88
91
|
handler: (row: Record<string, any>, index: number) => {
|
|
89
|
-
if (!addDialog.value) return;
|
|
90
92
|
fieldValues.value = {
|
|
91
93
|
...row,
|
|
92
94
|
index,
|
|
93
95
|
};
|
|
94
96
|
filedTitle.value = `编辑${row.title}`;
|
|
95
|
-
addDialog.value
|
|
97
|
+
addDialog.value?.show();
|
|
96
98
|
},
|
|
97
99
|
},
|
|
98
100
|
{
|
|
@@ -157,6 +159,7 @@ const dataSourceFieldsConfig: FormConfig = [
|
|
|
157
159
|
{
|
|
158
160
|
name: 'description',
|
|
159
161
|
text: '描述',
|
|
162
|
+
type: 'textarea',
|
|
160
163
|
},
|
|
161
164
|
{
|
|
162
165
|
name: 'defaultValue',
|