@tmagic/editor 1.4.3 → 1.4.5
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 +17 -3
- package/dist/tmagic-editor.js +1309 -1208
- package/dist/tmagic-editor.umd.cjs +1327 -1224
- package/package.json +19 -24
- package/src/Editor.vue +6 -1
- package/src/editorProps.ts +3 -0
- package/src/fields/CodeSelectCol.vue +26 -18
- package/src/fields/DataSourceFieldSelect.vue +23 -61
- package/src/fields/DataSourceMethodSelect.vue +25 -31
- package/src/fields/DataSourceSelect.vue +49 -13
- package/src/fields/EventSelect.vue +37 -14
- package/src/hooks/use-editor-content-height.ts +11 -5
- package/src/layouts/PropsPanel.vue +3 -1
- package/src/layouts/sidebar/Sidebar.vue +24 -8
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +6 -1
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +6 -1
- package/src/layouts/workspace/viewer/Stage.vue +7 -6
- package/src/services/editor.ts +2 -2
- package/src/services/ui.ts +1 -0
- package/src/theme/data-source-field.scss +12 -0
- package/src/theme/props-panel.scss +1 -1
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +31 -2
- package/src/utils/content-menu.ts +7 -3
- package/src/utils/data-source/index.ts +39 -3
- package/src/utils/editor.ts +14 -7
- package/types/components/CodeBlockEditor.vue.d.ts +21 -34
- package/types/components/CodeParams.vue.d.ts +2 -2
- package/types/components/ContentMenu.vue.d.ts +4 -4
- package/types/components/FloatingBox.vue.d.ts +41 -38
- package/types/components/ScrollViewer.vue.d.ts +1 -1
- package/types/components/ToolButton.vue.d.ts +6 -6
- package/types/components/Tree.vue.d.ts +2 -2
- package/types/editorProps.d.ts +3 -0
- package/types/fields/CodeLink.vue.d.ts +2 -2
- package/types/fields/DataSourceFields.vue.d.ts +32 -78
- package/types/fields/DataSourceInput.vue.d.ts +2 -2
- package/types/fields/DataSourceMethods.vue.d.ts +2 -2
- package/types/fields/DataSourceMocks.vue.d.ts +31 -76
- package/types/fields/KeyValue.vue.d.ts +2 -2
- package/types/fields/UISelect.vue.d.ts +2 -2
- package/types/hooks/use-code-block-edit.d.ts +18 -6
- package/types/hooks/use-data-source-edit.d.ts +18 -6
- package/types/hooks/use-data-source-method.d.ts +18 -6
- package/types/layouts/CodeEditor.vue.d.ts +1 -1
- package/types/layouts/PropsPanel.vue.d.ts +40 -38
- package/types/layouts/sidebar/Sidebar.vue.d.ts +7 -7
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +1 -1
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +20 -30
- package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +1 -1
- package/types/layouts/sidebar/layer/LayerMenu.vue.d.ts +8 -8
- package/types/layouts/sidebar/layer/LayerPanel.vue.d.ts +4 -4
- package/types/layouts/sidebar/layer/use-click.d.ts +13 -13
- package/types/layouts/workspace/Workspace.vue.d.ts +4 -4
- package/types/layouts/workspace/viewer/Stage.vue.d.ts +4 -4
- package/types/layouts/workspace/viewer/ViewerMenu.vue.d.ts +8 -8
- package/types/services/dataSource.d.ts +1 -0
- package/types/services/ui.d.ts +19 -1
- package/types/type.d.ts +26 -2
- package/types/utils/data-source/index.d.ts +3 -2
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.
|
|
2
|
+
"version": "1.4.5",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -40,16 +40,7 @@
|
|
|
40
40
|
"typescript"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@babel/core": "^7.18.0",
|
|
44
43
|
"@element-plus/icons-vue": "^2.3.1",
|
|
45
|
-
"@tmagic/core": "1.4.3",
|
|
46
|
-
"@tmagic/dep": "1.4.3",
|
|
47
|
-
"@tmagic/design": "1.4.3",
|
|
48
|
-
"@tmagic/form": "1.4.3",
|
|
49
|
-
"@tmagic/schema": "1.4.3",
|
|
50
|
-
"@tmagic/stage": "1.4.3",
|
|
51
|
-
"@tmagic/table": "1.4.3",
|
|
52
|
-
"@tmagic/utils": "1.4.3",
|
|
53
44
|
"buffer": "^6.0.3",
|
|
54
45
|
"color": "^3.1.3",
|
|
55
46
|
"emmet-monaco-es": "^5.3.0",
|
|
@@ -57,37 +48,41 @@
|
|
|
57
48
|
"gesto": "^1.19.1",
|
|
58
49
|
"keycon": "^1.4.0",
|
|
59
50
|
"lodash-es": "^4.17.21",
|
|
60
|
-
"
|
|
61
|
-
"moveable": "^0.51.1",
|
|
51
|
+
"moveable": "^0.53.0",
|
|
62
52
|
"serialize-javascript": "^6.0.0",
|
|
63
|
-
"
|
|
53
|
+
"@tmagic/dep": "1.4.5",
|
|
54
|
+
"@tmagic/table": "1.4.5"
|
|
64
55
|
},
|
|
65
56
|
"peerDependencies": {
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
57
|
+
"monaco-editor": "^0.48.0",
|
|
58
|
+
"vue": "^3.4.27",
|
|
59
|
+
"@tmagic/design": "1.4.5",
|
|
60
|
+
"@tmagic/form": "1.4.5",
|
|
61
|
+
"@tmagic/schema": "1.4.5",
|
|
62
|
+
"@tmagic/stage": "1.4.5",
|
|
63
|
+
"@tmagic/utils": "1.4.5",
|
|
64
|
+
"@tmagic/core": "1.4.5"
|
|
70
65
|
},
|
|
71
66
|
"devDependencies": {
|
|
72
67
|
"@types/events": "^3.0.0",
|
|
73
68
|
"@types/lodash-es": "^4.17.4",
|
|
74
69
|
"@types/node": "^18.19.0",
|
|
75
70
|
"@types/serialize-javascript": "^5.0.1",
|
|
76
|
-
"@vitejs/plugin-vue": "^
|
|
77
|
-
"@vue/compiler-sfc": "^3.4.
|
|
78
|
-
"@vue/test-utils": "^2.4.
|
|
71
|
+
"@vitejs/plugin-vue": "^5.0.4",
|
|
72
|
+
"@vue/compiler-sfc": "^3.4.27",
|
|
73
|
+
"@vue/test-utils": "^2.4.6",
|
|
79
74
|
"rimraf": "^3.0.2",
|
|
80
|
-
"sass": "^1.
|
|
75
|
+
"sass": "^1.77.0",
|
|
81
76
|
"tsc-alias": "^1.8.5",
|
|
82
77
|
"type-fest": "^4.10.3",
|
|
83
78
|
"typescript": "^5.4.2",
|
|
84
|
-
"vite": "^5.
|
|
85
|
-
"vue-tsc": "^2.0.
|
|
79
|
+
"vite": "^5.2.11",
|
|
80
|
+
"vue-tsc": "^2.0.16"
|
|
86
81
|
},
|
|
87
82
|
"scripts": {
|
|
88
83
|
"build": "npm run build:type && vite build",
|
|
89
84
|
"build:type": "npm run clear:type && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
90
85
|
"clear:type": "rimraf ./types",
|
|
91
|
-
"type
|
|
86
|
+
"check:type": "vue-tsc --noEmit --project tsconfig.build.json"
|
|
92
87
|
}
|
|
93
88
|
}
|
package/src/Editor.vue
CHANGED
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
<slot name="props-panel">
|
|
82
82
|
<PropsPanel
|
|
83
83
|
:extend-state="extendFormState"
|
|
84
|
+
:disabled-show-src="disabledShowSrc"
|
|
84
85
|
@mounted="(instance: any) => $emit('props-panel-mounted', instance)"
|
|
85
86
|
@form-error="(e: any) => $emit('props-form-error', e)"
|
|
86
87
|
@submit-error="(e: any) => $emit('props-submit-error', e)"
|
|
@@ -109,6 +110,8 @@
|
|
|
109
110
|
</template>
|
|
110
111
|
|
|
111
112
|
<script lang="ts" setup>
|
|
113
|
+
import { EventEmitter } from 'events';
|
|
114
|
+
|
|
112
115
|
import { provide } from 'vue';
|
|
113
116
|
|
|
114
117
|
import type { MApp } from '@tmagic/schema';
|
|
@@ -133,7 +136,7 @@ import uiService from './services/ui';
|
|
|
133
136
|
import keybindingConfig from './utils/keybinding-config';
|
|
134
137
|
import { defaultEditorProps, EditorProps } from './editorProps';
|
|
135
138
|
import { initServiceEvents, initServiceState } from './initService';
|
|
136
|
-
import type { FrameworkSlots, PropsPanelSlots, Services, SidebarSlots, WorkspaceSlots } from './type';
|
|
139
|
+
import type { EventBus, FrameworkSlots, PropsPanelSlots, Services, SidebarSlots, WorkspaceSlots } from './type';
|
|
137
140
|
|
|
138
141
|
defineSlots<
|
|
139
142
|
FrameworkSlots &
|
|
@@ -202,5 +205,7 @@ provide('services', services);
|
|
|
202
205
|
provide('codeOptions', props.codeOptions);
|
|
203
206
|
provide('stageOptions', stageOptions);
|
|
204
207
|
|
|
208
|
+
provide<EventBus>('eventBus', new EventEmitter());
|
|
209
|
+
|
|
205
210
|
defineExpose(services);
|
|
206
211
|
</script>
|
package/src/editorProps.ts
CHANGED
|
@@ -80,6 +80,8 @@ export interface EditorProps {
|
|
|
80
80
|
disabledPageFragment?: boolean;
|
|
81
81
|
/** 禁用双击在浮层中单独编辑选中组件 */
|
|
82
82
|
disabledStageOverlay?: boolean;
|
|
83
|
+
/** 禁用属性配置面板右下角显示源码的按钮 */
|
|
84
|
+
disabledShowSrc?: boolean;
|
|
83
85
|
/** 中间工作区域中画布渲染的内容 */
|
|
84
86
|
render?: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
|
|
85
87
|
/** 选中时会在画布上复制出一个大小相同的dom,实际拖拽的是这个dom,此方法用于干预这个dom的生成方式 */
|
|
@@ -101,6 +103,7 @@ export const defaultEditorProps = {
|
|
|
101
103
|
containerHighlightClassName: CONTAINER_HIGHLIGHT_CLASS_NAME,
|
|
102
104
|
containerHighlightDuration: 800,
|
|
103
105
|
containerHighlightType: ContainerHighlightType.DEFAULT,
|
|
106
|
+
disabledShowSrc: false,
|
|
104
107
|
componentGroupList: () => [],
|
|
105
108
|
datasourceList: () => [],
|
|
106
109
|
menu: () => ({ left: [], right: [] }),
|
|
@@ -2,15 +2,23 @@
|
|
|
2
2
|
<div class="m-fields-code-select-col">
|
|
3
3
|
<div class="code-select-container">
|
|
4
4
|
<!-- 代码块下拉框 -->
|
|
5
|
-
<
|
|
5
|
+
<MContainer
|
|
6
6
|
class="select"
|
|
7
7
|
:config="selectConfig"
|
|
8
8
|
:model="model"
|
|
9
9
|
:size="size"
|
|
10
10
|
@change="onParamsChangeHandler"
|
|
11
|
-
></
|
|
11
|
+
></MContainer>
|
|
12
|
+
|
|
12
13
|
<!-- 查看/编辑按钮 -->
|
|
13
|
-
<
|
|
14
|
+
<TMagicButton
|
|
15
|
+
v-if="model[name] && hasCodeBlockSidePanel"
|
|
16
|
+
class="m-fields-select-action-button"
|
|
17
|
+
:size="size"
|
|
18
|
+
@click="editCode(model[name])"
|
|
19
|
+
>
|
|
20
|
+
<MIcon :icon="!notEditable ? Edit : View"></MIcon>
|
|
21
|
+
</TMagicButton>
|
|
14
22
|
</div>
|
|
15
23
|
|
|
16
24
|
<!-- 参数填写框 -->
|
|
@@ -23,14 +31,6 @@
|
|
|
23
31
|
:params-config="paramsConfig"
|
|
24
32
|
@change="onParamsChangeHandler"
|
|
25
33
|
></CodeParams>
|
|
26
|
-
|
|
27
|
-
<CodeBlockEditor
|
|
28
|
-
ref="codeBlockEditor"
|
|
29
|
-
v-if="codeConfig"
|
|
30
|
-
:disabled="notEditable"
|
|
31
|
-
:content="codeConfig"
|
|
32
|
-
@submit="submitCodeBlockHandler"
|
|
33
|
-
></CodeBlockEditor>
|
|
34
34
|
</div>
|
|
35
35
|
</template>
|
|
36
36
|
|
|
@@ -39,14 +39,14 @@ import { computed, inject, ref, watch } from 'vue';
|
|
|
39
39
|
import { Edit, View } from '@element-plus/icons-vue';
|
|
40
40
|
import { isEmpty, map } from 'lodash-es';
|
|
41
41
|
|
|
42
|
-
import {
|
|
42
|
+
import { TMagicButton } from '@tmagic/design';
|
|
43
|
+
import { createValues, type FieldProps, filterFunction, type FormState, MContainer } from '@tmagic/form';
|
|
43
44
|
import type { Id } from '@tmagic/schema';
|
|
44
45
|
|
|
45
|
-
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
46
46
|
import CodeParams from '@editor/components/CodeParams.vue';
|
|
47
|
-
import
|
|
48
|
-
import {
|
|
49
|
-
import
|
|
47
|
+
import MIcon from '@editor/components/Icon.vue';
|
|
48
|
+
import type { CodeParamStatement, CodeSelectColConfig, EventBus, Services } from '@editor/type';
|
|
49
|
+
import { SideItemKey } from '@editor/type';
|
|
50
50
|
|
|
51
51
|
defineOptions({
|
|
52
52
|
name: 'MFieldsCodeSelectCol',
|
|
@@ -54,13 +54,19 @@ defineOptions({
|
|
|
54
54
|
|
|
55
55
|
const mForm = inject<FormState | undefined>('mForm');
|
|
56
56
|
const services = inject<Services>('services');
|
|
57
|
+
const eventBus = inject<EventBus>('eventBus');
|
|
57
58
|
const emit = defineEmits(['change']);
|
|
58
59
|
|
|
59
|
-
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
|
60
60
|
const props = withDefaults(defineProps<FieldProps<CodeSelectColConfig>>(), {
|
|
61
61
|
disabled: false,
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
+
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
|
65
|
+
|
|
66
|
+
const hasCodeBlockSidePanel = computed(() =>
|
|
67
|
+
(services?.uiService.get('sideBarItems') || []).find((item) => item.$key === SideItemKey.CODE_BLOCK),
|
|
68
|
+
);
|
|
69
|
+
|
|
64
70
|
/**
|
|
65
71
|
* 根据代码块id获取代码块参数配置
|
|
66
72
|
* @param codeId 代码块ID
|
|
@@ -127,5 +133,7 @@ const onParamsChangeHandler = (value: any) => {
|
|
|
127
133
|
emit('change', props.model);
|
|
128
134
|
};
|
|
129
135
|
|
|
130
|
-
const
|
|
136
|
+
const editCode = (id: string) => {
|
|
137
|
+
eventBus?.emit('edit-code', id);
|
|
138
|
+
};
|
|
131
139
|
</script>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div class="m-fields-data-source-field-select">
|
|
3
3
|
<component
|
|
4
|
-
style="width: 100%"
|
|
5
4
|
:is="tagName"
|
|
6
5
|
:config="showDataSourceFieldSelect || !config.fieldConfig ? cascaderConfig : config.fieldConfig"
|
|
7
6
|
:model="model"
|
|
@@ -14,13 +13,15 @@
|
|
|
14
13
|
:prop="`${prop}${prop ? '.' : ''}${name}`"
|
|
15
14
|
@change="onChangeHandler"
|
|
16
15
|
></component>
|
|
16
|
+
|
|
17
17
|
<TMagicButton
|
|
18
|
-
v-if="(showDataSourceFieldSelect || !config.fieldConfig) && selectedDataSourceId"
|
|
19
|
-
|
|
18
|
+
v-if="(showDataSourceFieldSelect || !config.fieldConfig) && selectedDataSourceId && hasDataSourceSidePanel"
|
|
19
|
+
class="m-fields-select-action-button"
|
|
20
20
|
:size="size"
|
|
21
21
|
@click="editHandler(selectedDataSourceId)"
|
|
22
|
-
><MIcon :icon="Edit"></MIcon
|
|
22
|
+
><MIcon :icon="!notEditable ? Edit : View"></MIcon
|
|
23
23
|
></TMagicButton>
|
|
24
|
+
|
|
24
25
|
<TMagicButton
|
|
25
26
|
v-if="config.fieldConfig"
|
|
26
27
|
style="margin-left: 5px"
|
|
@@ -29,43 +30,41 @@
|
|
|
29
30
|
@click="showDataSourceFieldSelect = !showDataSourceFieldSelect"
|
|
30
31
|
><MIcon :icon="Coin"></MIcon
|
|
31
32
|
></TMagicButton>
|
|
32
|
-
|
|
33
|
-
<DataSourceConfigPanel
|
|
34
|
-
ref="editDialog"
|
|
35
|
-
:disabled="!editable"
|
|
36
|
-
:values="dataSourceValues"
|
|
37
|
-
:title="dialogTitle"
|
|
38
|
-
@submit="submitDataSourceHandler"
|
|
39
|
-
></DataSourceConfigPanel>
|
|
40
33
|
</div>
|
|
41
34
|
</template>
|
|
42
35
|
|
|
43
36
|
<script setup lang="ts">
|
|
44
37
|
import { computed, inject, ref, resolveComponent, watch } from 'vue';
|
|
45
|
-
import { Coin, Edit } from '@element-plus/icons-vue';
|
|
38
|
+
import { Coin, Edit, View } from '@element-plus/icons-vue';
|
|
46
39
|
|
|
47
40
|
import { TMagicButton } from '@tmagic/design';
|
|
48
|
-
import type { CascaderConfig,
|
|
49
|
-
import { MCascader } from '@tmagic/form';
|
|
50
|
-
import type { DataSchema, DataSourceFieldType } from '@tmagic/schema';
|
|
41
|
+
import type { CascaderConfig, FieldProps, FormState } from '@tmagic/form';
|
|
42
|
+
import { filterFunction, MCascader } from '@tmagic/form';
|
|
51
43
|
import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
|
|
52
44
|
|
|
53
45
|
import MIcon from '@editor/components/Icon.vue';
|
|
54
|
-
import {
|
|
55
|
-
import
|
|
56
|
-
import
|
|
46
|
+
import type { DataSourceFieldSelectConfig, EventBus, Services } from '@editor/type';
|
|
47
|
+
import { SideItemKey } from '@editor/type';
|
|
48
|
+
import { getCascaderOptionsFromFields } from '@editor/utils';
|
|
57
49
|
|
|
58
50
|
defineOptions({
|
|
59
51
|
name: 'MFieldsDataSourceFieldSelect',
|
|
60
52
|
});
|
|
61
53
|
|
|
62
54
|
const services = inject<Services>('services');
|
|
55
|
+
const eventBus = inject<EventBus>('eventBus');
|
|
63
56
|
const emit = defineEmits(['change']);
|
|
64
57
|
|
|
65
58
|
const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(), {
|
|
66
59
|
disabled: false,
|
|
67
60
|
});
|
|
68
61
|
|
|
62
|
+
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
|
63
|
+
|
|
64
|
+
const hasDataSourceSidePanel = computed(() =>
|
|
65
|
+
(services?.uiService.get('sideBarItems') || []).find((item) => item.$key === SideItemKey.DATA_SOURCE),
|
|
66
|
+
);
|
|
67
|
+
|
|
69
68
|
const selectedDataSourceId = computed(() => {
|
|
70
69
|
const value = props.model[props.name];
|
|
71
70
|
if (!Array.isArray(value) || !value.length) {
|
|
@@ -77,43 +76,6 @@ const selectedDataSourceId = computed(() => {
|
|
|
77
76
|
|
|
78
77
|
const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
|
|
79
78
|
|
|
80
|
-
const getOptionChildren = (
|
|
81
|
-
fields: DataSchema[] = [],
|
|
82
|
-
dataSourceFieldType: DataSourceFieldType[] = ['any'],
|
|
83
|
-
): CascaderOption[] => {
|
|
84
|
-
const child: CascaderOption[] = [];
|
|
85
|
-
fields.forEach((field) => {
|
|
86
|
-
if (!dataSourceFieldType.length) {
|
|
87
|
-
dataSourceFieldType.push('any');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const children = getOptionChildren(field.fields, dataSourceFieldType);
|
|
91
|
-
|
|
92
|
-
const item = {
|
|
93
|
-
label: field.title || field.name,
|
|
94
|
-
value: field.name,
|
|
95
|
-
children,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const fieldType = field.type || 'any';
|
|
99
|
-
if (dataSourceFieldType.includes('any') || dataSourceFieldType.includes(fieldType)) {
|
|
100
|
-
child.push(item);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!dataSourceFieldType.includes(fieldType) && !['array', 'object', 'any'].includes(fieldType)) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!children.length && ['object', 'array', 'any'].includes(field.type || '')) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
child.push(item);
|
|
113
|
-
});
|
|
114
|
-
return child;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
79
|
const cascaderConfig = computed<CascaderConfig>(() => {
|
|
118
80
|
const valueIsKey = props.config.value === 'key';
|
|
119
81
|
|
|
@@ -126,7 +88,7 @@ const cascaderConfig = computed<CascaderConfig>(() => {
|
|
|
126
88
|
dataSources.value?.map((ds) => ({
|
|
127
89
|
label: ds.title || ds.id,
|
|
128
90
|
value: valueIsKey ? ds.id : `${DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX}${ds.id}`,
|
|
129
|
-
children:
|
|
91
|
+
children: getCascaderOptionsFromFields(ds.fields, props.config.dataSourceFieldType),
|
|
130
92
|
})) || [];
|
|
131
93
|
return options.filter((option) => option.children.length);
|
|
132
94
|
},
|
|
@@ -181,7 +143,7 @@ const onChangeHandler = (value: any) => {
|
|
|
181
143
|
emit('change', value);
|
|
182
144
|
};
|
|
183
145
|
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
146
|
+
const editHandler = (id: string) => {
|
|
147
|
+
eventBus?.emit('edit-data-source', id);
|
|
148
|
+
};
|
|
187
149
|
</script>
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="m-fields-data-source-method-select">
|
|
3
3
|
<div class="data-source-method-select-container">
|
|
4
|
-
<
|
|
4
|
+
<MContainer
|
|
5
5
|
class="select"
|
|
6
6
|
:config="cascaderConfig"
|
|
7
7
|
:model="model"
|
|
8
|
+
:size="size"
|
|
8
9
|
@change="onChangeHandler"
|
|
9
|
-
></
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
></MContainer>
|
|
11
|
+
|
|
12
|
+
<TMagicButton
|
|
13
|
+
v-if="model[name] && isCustomMethod && hasDataSourceSidePanel"
|
|
14
|
+
class="m-fields-select-action-button"
|
|
15
|
+
:size="size"
|
|
14
16
|
@click="editCodeHandler"
|
|
15
|
-
|
|
17
|
+
>
|
|
18
|
+
<MIcon :icon="!notEditable ? Edit : View"></MIcon>
|
|
19
|
+
</TMagicButton>
|
|
16
20
|
</div>
|
|
17
21
|
|
|
18
22
|
<CodeParams
|
|
@@ -24,14 +28,6 @@
|
|
|
24
28
|
:params-config="paramsConfig"
|
|
25
29
|
@change="onChangeHandler"
|
|
26
30
|
></CodeParams>
|
|
27
|
-
|
|
28
|
-
<CodeBlockEditor
|
|
29
|
-
ref="codeBlockEditor"
|
|
30
|
-
v-if="codeConfig"
|
|
31
|
-
:disabled="notEditable"
|
|
32
|
-
:content="codeConfig"
|
|
33
|
-
@submit="submitCodeBlockHandler"
|
|
34
|
-
></CodeBlockEditor>
|
|
35
31
|
</div>
|
|
36
32
|
</template>
|
|
37
33
|
|
|
@@ -39,14 +35,14 @@
|
|
|
39
35
|
import { computed, inject, ref } from 'vue';
|
|
40
36
|
import { Edit, View } from '@element-plus/icons-vue';
|
|
41
37
|
|
|
42
|
-
import {
|
|
43
|
-
import type
|
|
38
|
+
import { TMagicButton } from '@tmagic/design';
|
|
39
|
+
import { createValues, type FieldProps, filterFunction, type FormState, MContainer } from '@tmagic/form';
|
|
40
|
+
import type { Id } from '@tmagic/schema';
|
|
44
41
|
|
|
45
|
-
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
46
42
|
import CodeParams from '@editor/components/CodeParams.vue';
|
|
47
|
-
import
|
|
48
|
-
import {
|
|
49
|
-
import
|
|
43
|
+
import MIcon from '@editor/components/Icon.vue';
|
|
44
|
+
import type { CodeParamStatement, DataSourceMethodSelectConfig, EventBus, Services } from '@editor/type';
|
|
45
|
+
import { SideItemKey } from '@editor/type';
|
|
50
46
|
|
|
51
47
|
defineOptions({
|
|
52
48
|
name: 'MFieldsDataSourceMethodSelect',
|
|
@@ -54,6 +50,8 @@ defineOptions({
|
|
|
54
50
|
|
|
55
51
|
const mForm = inject<FormState | undefined>('mForm');
|
|
56
52
|
const services = inject<Services>('services');
|
|
53
|
+
const eventBus = inject<EventBus>('eventBus');
|
|
54
|
+
|
|
57
55
|
const emit = defineEmits(['change']);
|
|
58
56
|
|
|
59
57
|
const dataSourceService = services?.dataSourceService;
|
|
@@ -62,6 +60,10 @@ const props = withDefaults(defineProps<FieldProps<DataSourceMethodSelectConfig>>
|
|
|
62
60
|
disabled: false,
|
|
63
61
|
});
|
|
64
62
|
|
|
63
|
+
const hasDataSourceSidePanel = computed(() =>
|
|
64
|
+
(services?.uiService.get('sideBarItems') || []).find((item) => item.$key === SideItemKey.DATA_SOURCE),
|
|
65
|
+
);
|
|
66
|
+
|
|
65
67
|
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
|
66
68
|
|
|
67
69
|
const dataSources = computed(() => dataSourceService?.get('dataSources'));
|
|
@@ -139,21 +141,13 @@ const onChangeHandler = (value: any) => {
|
|
|
139
141
|
emit('change', props.model);
|
|
140
142
|
};
|
|
141
143
|
|
|
142
|
-
const { codeBlockEditor, codeConfig, editCode, submitCode } = useDataSourceMethod();
|
|
143
|
-
|
|
144
144
|
const editCodeHandler = () => {
|
|
145
|
-
const [id
|
|
145
|
+
const [id] = props.model[props.name];
|
|
146
146
|
|
|
147
147
|
const dataSource = dataSourceService?.getDataSourceById(id);
|
|
148
148
|
|
|
149
149
|
if (!dataSource) return;
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
setParamsConfig([id, name]);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const submitCodeBlockHandler = (value: CodeBlockContent) => {
|
|
157
|
-
submitCode(value);
|
|
151
|
+
eventBus?.emit('edit-data-source', id);
|
|
158
152
|
};
|
|
159
153
|
</script>
|
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
<div class="m-fields-data-source-select">
|
|
3
|
+
<MSelect
|
|
4
|
+
:model="model"
|
|
5
|
+
:name="name"
|
|
6
|
+
:size="size"
|
|
7
|
+
:prop="prop"
|
|
8
|
+
:disabled="disabled"
|
|
9
|
+
:config="selectConfig"
|
|
10
|
+
:last-values="lastValues"
|
|
11
|
+
@change="changeHandler"
|
|
12
|
+
></MSelect>
|
|
13
|
+
|
|
14
|
+
<TMagicButton
|
|
15
|
+
v-if="model[name] && hasDataSourceSidePanel"
|
|
16
|
+
class="m-fields-select-action-button"
|
|
17
|
+
:size="size"
|
|
18
|
+
@click="editHandler"
|
|
19
|
+
><MIcon :icon="!notEditable ? Edit : View"></MIcon
|
|
20
|
+
></TMagicButton>
|
|
21
|
+
</div>
|
|
12
22
|
</template>
|
|
13
23
|
|
|
14
24
|
<script setup lang="ts">
|
|
15
25
|
import { computed, inject } from 'vue';
|
|
26
|
+
import { Edit, View } from '@element-plus/icons-vue';
|
|
16
27
|
|
|
17
|
-
import {
|
|
28
|
+
import { TMagicButton } from '@tmagic/design';
|
|
29
|
+
import { type FieldProps, filterFunction, type FormState, MSelect, type SelectConfig } from '@tmagic/form';
|
|
18
30
|
|
|
19
|
-
import
|
|
31
|
+
import MIcon from '@editor/components/Icon.vue';
|
|
32
|
+
import type { DataSourceSelect, EventBus, Services } from '@editor/type';
|
|
33
|
+
import { SideItemKey } from '@editor/type';
|
|
20
34
|
|
|
21
35
|
defineOptions({
|
|
22
36
|
name: 'MFieldsDataSourceSelect',
|
|
@@ -28,10 +42,18 @@ const props = withDefaults(defineProps<FieldProps<DataSourceSelect>>(), {
|
|
|
28
42
|
disabled: false,
|
|
29
43
|
});
|
|
30
44
|
|
|
31
|
-
const
|
|
45
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
46
|
+
const { dataSourceService, uiService } = inject<Services>('services') || {};
|
|
47
|
+
const eventBus = inject<EventBus>('eventBus');
|
|
32
48
|
|
|
33
49
|
const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
|
|
34
50
|
|
|
51
|
+
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
|
52
|
+
|
|
53
|
+
const hasDataSourceSidePanel = computed(() =>
|
|
54
|
+
(uiService?.get('sideBarItems') || []).find((item) => item.$key === SideItemKey.DATA_SOURCE),
|
|
55
|
+
);
|
|
56
|
+
|
|
35
57
|
const selectConfig = computed<SelectConfig>(() => {
|
|
36
58
|
const { type, dataSourceType, value, ...config } = props.config;
|
|
37
59
|
|
|
@@ -59,4 +81,18 @@ const selectConfig = computed<SelectConfig>(() => {
|
|
|
59
81
|
const changeHandler = (value: any) => {
|
|
60
82
|
emit('change', value);
|
|
61
83
|
};
|
|
84
|
+
|
|
85
|
+
const editHandler = () => {
|
|
86
|
+
const value = props.model[props.name];
|
|
87
|
+
|
|
88
|
+
if (!value) return;
|
|
89
|
+
|
|
90
|
+
const id = typeof value === 'string' ? value : value.dataSourceId;
|
|
91
|
+
|
|
92
|
+
const dataSource = dataSourceService?.getDataSourceById(id);
|
|
93
|
+
|
|
94
|
+
if (!dataSource) return;
|
|
95
|
+
|
|
96
|
+
eventBus?.emit('edit-data-source', id);
|
|
97
|
+
};
|
|
62
98
|
</script>
|