@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
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<component
|
|
3
|
+
v-if="disabled || isFocused"
|
|
4
|
+
:is="getConfig('components')?.autocomplete.component || 'el-autocomplete'"
|
|
5
|
+
class="tmagic-design-auto-complete"
|
|
6
|
+
ref="autocomplete"
|
|
7
|
+
v-model="state"
|
|
8
|
+
v-bind="
|
|
9
|
+
getConfig('components')?.autocomplete.props({
|
|
10
|
+
disabled,
|
|
11
|
+
size,
|
|
12
|
+
fetchSuggestions: querySearch,
|
|
13
|
+
triggerOnFocus: false,
|
|
14
|
+
clearable: true,
|
|
15
|
+
}) || {}
|
|
16
|
+
"
|
|
17
|
+
style="width: 100%"
|
|
18
|
+
@blur="blurHandler"
|
|
19
|
+
@change="changeHandler"
|
|
20
|
+
@input="inputHandler"
|
|
21
|
+
@select="selectHandler"
|
|
22
|
+
>
|
|
23
|
+
<template #suffix>
|
|
24
|
+
<Icon :icon="Coin" />
|
|
25
|
+
</template>
|
|
26
|
+
<template #default="{ item }">
|
|
27
|
+
<div style="display: flex; flex-direction: column; line-height: 1.2em">
|
|
28
|
+
<div>{{ item.text }}</div>
|
|
29
|
+
<span style="font-size: 10px; color: rgba(0, 0, 0, 0.6)">{{ item.value }}</span>
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
32
|
+
</component>
|
|
33
|
+
<div :class="`tmagic-data-source-input-text el-input el-input--${size}`" @mouseup="mouseupHandler" v-else>
|
|
34
|
+
<div :class="`tmagic-data-source-input-text-wrapper el-input__wrapper ${isFocused ? ' is-focus' : ''}`">
|
|
35
|
+
<div class="el-input__inner">
|
|
36
|
+
<template v-for="(item, index) in displayState">
|
|
37
|
+
<span :key="index" v-if="item.type === 'text'" style="margin-right: 2px">{{ item.value }}</span>
|
|
38
|
+
<TMagicTag :key="index" :size="size" v-if="item.type === 'var'">{{ item.value }}</TMagicTag>
|
|
39
|
+
</template>
|
|
40
|
+
|
|
41
|
+
<Icon class="tmagic-data-source-input-icon" :icon="Coin" />
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<script setup lang="ts">
|
|
48
|
+
import { computed, inject, nextTick, ref, watch } from 'vue';
|
|
49
|
+
import { Coin } from '@element-plus/icons-vue';
|
|
50
|
+
|
|
51
|
+
import { getConfig, TMagicAutocomplete, TMagicTag } from '@tmagic/design';
|
|
52
|
+
import type { FieldProps } from '@tmagic/form';
|
|
53
|
+
import type { DataSchema, DataSourceSchema } from '@tmagic/schema';
|
|
54
|
+
|
|
55
|
+
import Icon from '@editor/components/Icon.vue';
|
|
56
|
+
import type { Services } from '@editor/type';
|
|
57
|
+
import { getDisplayField } from '@editor/utils/data-source';
|
|
58
|
+
|
|
59
|
+
defineOptions({
|
|
60
|
+
name: 'MEditorDataSourceInput',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const props = withDefaults(
|
|
64
|
+
defineProps<
|
|
65
|
+
FieldProps<{
|
|
66
|
+
type: 'data-source-input';
|
|
67
|
+
name: string;
|
|
68
|
+
text: string;
|
|
69
|
+
}>
|
|
70
|
+
>(),
|
|
71
|
+
{
|
|
72
|
+
disabled: false,
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const emit = defineEmits<{
|
|
77
|
+
change: [value: string];
|
|
78
|
+
}>();
|
|
79
|
+
|
|
80
|
+
const { dataSourceService } = inject<Services>('services') || {};
|
|
81
|
+
|
|
82
|
+
const autocomplete = ref<InstanceType<typeof TMagicAutocomplete>>();
|
|
83
|
+
const isFocused = ref(false);
|
|
84
|
+
const state = ref('');
|
|
85
|
+
const displayState = ref<{ value: string; type: 'var' | 'text' }[]>([]);
|
|
86
|
+
|
|
87
|
+
const input = computed<HTMLInputElement>(() => autocomplete.value?.inputRef?.input);
|
|
88
|
+
const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
|
|
89
|
+
|
|
90
|
+
const setDisplayState = () => {
|
|
91
|
+
displayState.value = getDisplayField(dataSources.value, state.value);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
watch(
|
|
95
|
+
() => props.model[props.name],
|
|
96
|
+
(value = '') => {
|
|
97
|
+
state.value = value;
|
|
98
|
+
|
|
99
|
+
setDisplayState();
|
|
100
|
+
},
|
|
101
|
+
{ immediate: true },
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const mouseupHandler = async () => {
|
|
105
|
+
isFocused.value = true;
|
|
106
|
+
await nextTick();
|
|
107
|
+
autocomplete.value?.focus();
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const blurHandler = () => {
|
|
111
|
+
isFocused.value = false;
|
|
112
|
+
|
|
113
|
+
setDisplayState();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const changeHandler = (v: string) => {
|
|
117
|
+
emit('change', v);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
let inputText = '';
|
|
121
|
+
|
|
122
|
+
const inputHandler = (v: string) => {
|
|
123
|
+
if (!v) {
|
|
124
|
+
inputText = v;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 光标位置是不是}
|
|
130
|
+
* @param selectionStart 光标位置
|
|
131
|
+
*/
|
|
132
|
+
const isRightCurlyBracket = (selectionStart = 0) => {
|
|
133
|
+
const lastChar = inputText.substring(selectionStart - 1, selectionStart);
|
|
134
|
+
return lastChar === '}';
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 获取光标位置
|
|
139
|
+
*/
|
|
140
|
+
const getSelectionStart = () => {
|
|
141
|
+
let selectionStart = input.value?.selectionStart || 0;
|
|
142
|
+
|
|
143
|
+
// 输入法可能会自动补全},如果当前光标前面一个字符是},则光标前移一位
|
|
144
|
+
if (isRightCurlyBracket(selectionStart)) {
|
|
145
|
+
selectionStart -= 1;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return selectionStart;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 当前输入的是{
|
|
153
|
+
* @param leftCurlyBracketIndex {字符索引
|
|
154
|
+
*/
|
|
155
|
+
const curCharIsLeftCurlyBracket = (leftCurlyBracketIndex: number) =>
|
|
156
|
+
leftCurlyBracketIndex > 0 && leftCurlyBracketIndex === getSelectionStart() - 1;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 当前输入的是.
|
|
160
|
+
* @param leftCurlyBracketIndex .字符索引
|
|
161
|
+
*/
|
|
162
|
+
const curCharIsDot = (dotIndex: number) => dotIndex > -1 && dotIndex === getSelectionStart() - 1;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @param leftCurlyBracketIndex 左大括号字符索引
|
|
166
|
+
* @param cb 建议的方法
|
|
167
|
+
*/
|
|
168
|
+
const dsQuerySearch = (queryString: string, leftCurlyBracketIndex: number, cb: (data: { value: string }[]) => void) => {
|
|
169
|
+
let result: DataSourceSchema[] = [];
|
|
170
|
+
|
|
171
|
+
if (curCharIsLeftCurlyBracket(leftCurlyBracketIndex)) {
|
|
172
|
+
// 当前输入的是{
|
|
173
|
+
result = dataSources.value;
|
|
174
|
+
} else if (leftCurlyBracketIndex > 0) {
|
|
175
|
+
// 当前输入的是{xx
|
|
176
|
+
const queryName = queryString.substring(leftCurlyBracketIndex + 1).toLowerCase();
|
|
177
|
+
result = dataSources.value.filter((ds) => ds.title?.toLowerCase().includes(queryName) || ds.id.includes(queryName));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
cb(
|
|
181
|
+
result.map((ds) => ({
|
|
182
|
+
value: ds.id,
|
|
183
|
+
text: ds.title,
|
|
184
|
+
type: 'dataSource',
|
|
185
|
+
})),
|
|
186
|
+
);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 字段提示
|
|
191
|
+
* @param queryString 当前输入框内的字符串
|
|
192
|
+
* @param leftAngleIndex {字符索引
|
|
193
|
+
* @param dotIndex .字符索引
|
|
194
|
+
* @param cb 建议回调
|
|
195
|
+
*/
|
|
196
|
+
const fieldQuerySearch = (
|
|
197
|
+
queryString: string,
|
|
198
|
+
leftAngleIndex: number,
|
|
199
|
+
dotIndex: number,
|
|
200
|
+
cb: (data: { value: string }[]) => void,
|
|
201
|
+
) => {
|
|
202
|
+
let result: DataSchema[] = [];
|
|
203
|
+
|
|
204
|
+
const dsKey = queryString.substring(leftAngleIndex + 1, dotIndex);
|
|
205
|
+
|
|
206
|
+
// 可能是xx.xx.xx,存在链式调用
|
|
207
|
+
const keys = dsKey.split('.');
|
|
208
|
+
|
|
209
|
+
// 最前的是数据源id
|
|
210
|
+
const dsId = keys.shift();
|
|
211
|
+
const ds = dataSources.value.find((ds) => ds.id === dsId);
|
|
212
|
+
if (!ds) {
|
|
213
|
+
cb([]);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let fields = ds.fields || [];
|
|
218
|
+
|
|
219
|
+
// 后面这些是字段
|
|
220
|
+
let key = keys.shift();
|
|
221
|
+
while (key) {
|
|
222
|
+
for (const field of fields) {
|
|
223
|
+
if (field.name === key) {
|
|
224
|
+
fields = field.fields || [];
|
|
225
|
+
key = keys.shift();
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (curCharIsDot(dotIndex)) {
|
|
232
|
+
// 当前输入的是.
|
|
233
|
+
result = fields || [];
|
|
234
|
+
} else if (dotIndex > -1) {
|
|
235
|
+
const queryName = queryString.substring(dotIndex + 1).toLowerCase();
|
|
236
|
+
result =
|
|
237
|
+
fields.filter(
|
|
238
|
+
(field) => field.name?.toLowerCase().includes(queryName) || field.title?.toLowerCase().includes(queryName),
|
|
239
|
+
) || [];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
cb(
|
|
243
|
+
result.map((field) => ({
|
|
244
|
+
value: field.name,
|
|
245
|
+
text: field.title,
|
|
246
|
+
type: 'field',
|
|
247
|
+
})),
|
|
248
|
+
);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* 数据源提示
|
|
253
|
+
* @param queryString 当前输入框内的字符串
|
|
254
|
+
* @param cb 建议回调
|
|
255
|
+
*/
|
|
256
|
+
const querySearch = (queryString: string, cb: (data: { value: string }[]) => void) => {
|
|
257
|
+
inputText = queryString;
|
|
258
|
+
|
|
259
|
+
const selectionStart = getSelectionStart();
|
|
260
|
+
|
|
261
|
+
const curQueryString = queryString.substring(0, selectionStart);
|
|
262
|
+
|
|
263
|
+
const fieldKeyStringLastIndex = curQueryString.lastIndexOf('.');
|
|
264
|
+
const dsKeyStringLastIndex = curQueryString.lastIndexOf('${') + 1;
|
|
265
|
+
|
|
266
|
+
const isFieldTip = fieldKeyStringLastIndex > dsKeyStringLastIndex;
|
|
267
|
+
|
|
268
|
+
if (isFieldTip) {
|
|
269
|
+
fieldQuerySearch(curQueryString, dsKeyStringLastIndex, fieldKeyStringLastIndex, cb);
|
|
270
|
+
} else {
|
|
271
|
+
dsQuerySearch(curQueryString, dsKeyStringLastIndex, cb);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* 选择建议
|
|
277
|
+
* @param value 建议值
|
|
278
|
+
* @param type 建议类型,是数据源还是字段
|
|
279
|
+
*/
|
|
280
|
+
const selectHandler = async ({ value, type }: { value: string; type: 'dataSource' | 'field' }) => {
|
|
281
|
+
const isDataSource = type === 'dataSource';
|
|
282
|
+
const selectionStart = input.value?.selectionStart || 0;
|
|
283
|
+
let startText = inputText.substring(0, selectionStart);
|
|
284
|
+
|
|
285
|
+
const dotIndex = startText.lastIndexOf('.');
|
|
286
|
+
const leftCurlyBracketIndex = startText.lastIndexOf('${') + 1;
|
|
287
|
+
|
|
288
|
+
const endText = inputText.substring(selectionStart);
|
|
289
|
+
|
|
290
|
+
let suggestText = value;
|
|
291
|
+
|
|
292
|
+
if (isDataSource) {
|
|
293
|
+
if (!curCharIsLeftCurlyBracket(leftCurlyBracketIndex)) {
|
|
294
|
+
startText = startText.substring(0, leftCurlyBracketIndex + 1);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// 当前光标后一位是否为},不是的话需要补上
|
|
298
|
+
if (!isRightCurlyBracket(selectionStart + 1)) {
|
|
299
|
+
suggestText = `${suggestText}}`;
|
|
300
|
+
}
|
|
301
|
+
} else if (!curCharIsDot(dotIndex)) {
|
|
302
|
+
startText = startText.substring(0, dotIndex + 1);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
state.value = `${startText}${suggestText}${endText}`;
|
|
306
|
+
|
|
307
|
+
await nextTick();
|
|
308
|
+
|
|
309
|
+
// 由于选择数据源时会在后面补全}, 所以光标要前移2位
|
|
310
|
+
let newSelectionStart = 0;
|
|
311
|
+
if (isDataSource) {
|
|
312
|
+
newSelectionStart = leftCurlyBracketIndex + suggestText.length;
|
|
313
|
+
} else {
|
|
314
|
+
newSelectionStart = dotIndex + suggestText.length + 1;
|
|
315
|
+
}
|
|
316
|
+
input.value?.setSelectionRange(newSelectionStart, newSelectionStart);
|
|
317
|
+
};
|
|
318
|
+
</script>
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="m-fields-data-source-method-select">
|
|
3
|
+
<div class="data-source-method-select-container">
|
|
4
|
+
<m-form-container
|
|
5
|
+
class="select"
|
|
6
|
+
:config="cascaderConfig"
|
|
7
|
+
:model="model"
|
|
8
|
+
@change="onChangeHandler"
|
|
9
|
+
></m-form-container>
|
|
10
|
+
<Icon v-if="model[name]" class="icon" :icon="!disabled ? Edit : View" @click="editCodeHandler"></Icon>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<CodeParams
|
|
14
|
+
v-if="paramsConfig.length"
|
|
15
|
+
name="params"
|
|
16
|
+
:model="model"
|
|
17
|
+
:size="size"
|
|
18
|
+
:disabled="disabled"
|
|
19
|
+
:params-config="paramsConfig"
|
|
20
|
+
@change="onChangeHandler"
|
|
21
|
+
></CodeParams>
|
|
22
|
+
|
|
23
|
+
<CodeBlockEditor
|
|
24
|
+
ref="codeBlockEditor"
|
|
25
|
+
v-if="codeConfig"
|
|
26
|
+
:disabled="disabled"
|
|
27
|
+
:content="codeConfig"
|
|
28
|
+
@submit="submitCodeBlockHandler"
|
|
29
|
+
></CodeBlockEditor>
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<script lang="ts" setup name="">
|
|
34
|
+
import { computed, inject, ref } from 'vue';
|
|
35
|
+
import { Edit, View } from '@element-plus/icons-vue';
|
|
36
|
+
|
|
37
|
+
import { createValues, FieldProps } from '@tmagic/form';
|
|
38
|
+
import type { CodeBlockContent, Id } from '@tmagic/schema';
|
|
39
|
+
|
|
40
|
+
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
41
|
+
import CodeParams from '@editor/components/CodeParams.vue';
|
|
42
|
+
import Icon from '@editor/components/Icon.vue';
|
|
43
|
+
import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
|
|
44
|
+
import type { CodeParamStatement, DataSourceMethodSelectConfig, Services } from '@editor/type';
|
|
45
|
+
|
|
46
|
+
defineOptions({
|
|
47
|
+
name: 'MEditorDataSourceMethodSelect',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const services = inject<Services>('services');
|
|
51
|
+
const emit = defineEmits(['change']);
|
|
52
|
+
|
|
53
|
+
const props = withDefaults(defineProps<FieldProps<DataSourceMethodSelectConfig>>(), {
|
|
54
|
+
disabled: false,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
|
|
58
|
+
|
|
59
|
+
const getParamItemsConfig = ([dataSourceId, medthodName]: [Id, string] = ['', '']): CodeParamStatement[] => {
|
|
60
|
+
if (!dataSourceId) return [];
|
|
61
|
+
|
|
62
|
+
const paramStatements = dataSources.value
|
|
63
|
+
?.find((item) => item.id === dataSourceId)
|
|
64
|
+
?.methods?.find((item) => item.name === medthodName)?.params;
|
|
65
|
+
|
|
66
|
+
if (!paramStatements) return [];
|
|
67
|
+
|
|
68
|
+
return paramStatements.map((paramState: CodeParamStatement) => ({
|
|
69
|
+
labelWidth: '100px',
|
|
70
|
+
text: paramState.name,
|
|
71
|
+
...paramState,
|
|
72
|
+
}));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const paramsConfig = ref<CodeParamStatement[]>(getParamItemsConfig(props.model.dataSourceMethod));
|
|
76
|
+
|
|
77
|
+
const setParamsConfig = (dataSourceMethod: [Id, string], formState: any = {}) => {
|
|
78
|
+
// 通过下拉框选择的codeId变化后修正model的值,避免写入其他codeId的params
|
|
79
|
+
paramsConfig.value = dataSourceMethod ? getParamItemsConfig(dataSourceMethod) : [];
|
|
80
|
+
|
|
81
|
+
if (paramsConfig.value.length) {
|
|
82
|
+
props.model.params = createValues(formState, paramsConfig.value, {}, props.model.params);
|
|
83
|
+
} else {
|
|
84
|
+
props.model.params = {};
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const cascaderConfig = {
|
|
89
|
+
type: 'cascader',
|
|
90
|
+
text: '数据源方法',
|
|
91
|
+
name: props.name,
|
|
92
|
+
labelWidth: '80px',
|
|
93
|
+
options: () =>
|
|
94
|
+
dataSources.value
|
|
95
|
+
?.filter((ds) => ds.methods?.length)
|
|
96
|
+
?.map((ds) => ({
|
|
97
|
+
label: ds.title || ds.id,
|
|
98
|
+
value: ds.id,
|
|
99
|
+
children: ds.methods?.map((method) => ({
|
|
100
|
+
label: method.name,
|
|
101
|
+
value: method.name,
|
|
102
|
+
})),
|
|
103
|
+
})) || [],
|
|
104
|
+
onChange: (formState: any, dataSourceMethod: [Id, string]) => {
|
|
105
|
+
setParamsConfig(dataSourceMethod, formState);
|
|
106
|
+
|
|
107
|
+
return dataSourceMethod;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 参数值修改更新
|
|
113
|
+
*/
|
|
114
|
+
const onChangeHandler = (value: any) => {
|
|
115
|
+
props.model.params = value.params;
|
|
116
|
+
emit('change', props.model);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const { codeBlockEditor, codeConfig, editCode, submitCode } = useDataSourceMethod();
|
|
120
|
+
|
|
121
|
+
const editCodeHandler = () => {
|
|
122
|
+
const [id, name] = props.model[props.name];
|
|
123
|
+
|
|
124
|
+
const dataSource = services?.dataSourceService.getDataSourceById(id);
|
|
125
|
+
|
|
126
|
+
if (!dataSource) return;
|
|
127
|
+
|
|
128
|
+
editCode(dataSource, name);
|
|
129
|
+
|
|
130
|
+
setParamsConfig([id, name]);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const submitCodeBlockHandler = (value: CodeBlockContent) => {
|
|
134
|
+
submitCode(value);
|
|
135
|
+
};
|
|
136
|
+
</script>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="m-editor-data-source-methods">
|
|
3
|
+
<MagicTable :data="model[name]" :columns="methodColumns"></MagicTable>
|
|
4
|
+
|
|
5
|
+
<div class="m-editor-data-source-methods-footer">
|
|
6
|
+
<TMagicButton size="small" type="primary" :disabled="disabled" plain @click="createCodeHandler"
|
|
7
|
+
>添加</TMagicButton
|
|
8
|
+
>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<CodeBlockEditor
|
|
12
|
+
v-if="codeConfig"
|
|
13
|
+
ref="codeBlockEditor"
|
|
14
|
+
:disabled="disabled"
|
|
15
|
+
:content="codeConfig"
|
|
16
|
+
:is-data-source="true"
|
|
17
|
+
@submit="submitCodeHandler"
|
|
18
|
+
></CodeBlockEditor>
|
|
19
|
+
</div>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<script setup lang="ts">
|
|
23
|
+
import { TMagicButton } from '@tmagic/design';
|
|
24
|
+
import type { FieldProps } from '@tmagic/form';
|
|
25
|
+
import type { CodeBlockContent } from '@tmagic/schema';
|
|
26
|
+
import { MagicTable } from '@tmagic/table';
|
|
27
|
+
|
|
28
|
+
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
29
|
+
import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
|
|
30
|
+
import type { CodeParamStatement } from '@editor/type';
|
|
31
|
+
|
|
32
|
+
defineOptions({
|
|
33
|
+
name: 'MEditorDataSourceMethods',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const props = withDefaults(
|
|
37
|
+
defineProps<
|
|
38
|
+
FieldProps<{
|
|
39
|
+
type: 'data-source-methods';
|
|
40
|
+
}>
|
|
41
|
+
>(),
|
|
42
|
+
{
|
|
43
|
+
disabled: false,
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const emit = defineEmits(['change']);
|
|
48
|
+
|
|
49
|
+
const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
|
|
50
|
+
|
|
51
|
+
const methodColumns = [
|
|
52
|
+
{
|
|
53
|
+
label: '名称',
|
|
54
|
+
prop: 'name',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
label: '描述',
|
|
58
|
+
prop: 'desc',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
label: '执行时机',
|
|
62
|
+
prop: 'timing',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
label: '参数',
|
|
66
|
+
prop: 'params',
|
|
67
|
+
formatter: (params: CodeParamStatement[]) => params.map((item) => item.name).join(', '),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
label: '操作',
|
|
71
|
+
fixed: 'right',
|
|
72
|
+
actions: [
|
|
73
|
+
{
|
|
74
|
+
text: '编辑',
|
|
75
|
+
handler: (row: CodeBlockContent) => {
|
|
76
|
+
editCode(props.model, row.name);
|
|
77
|
+
emit('change', props.model[props.name]);
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
text: '删除',
|
|
82
|
+
buttonType: 'danger',
|
|
83
|
+
handler: (row: CodeBlockContent) => {
|
|
84
|
+
deleteCode(props.model, row.name);
|
|
85
|
+
emit('change', props.model[props.name]);
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
const createCodeHandler = () => {
|
|
93
|
+
createCode(props.model);
|
|
94
|
+
|
|
95
|
+
emit('change', props.model[props.name]);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const submitCodeHandler = (values: CodeBlockContent) => {
|
|
99
|
+
submitCode(values);
|
|
100
|
+
|
|
101
|
+
emit('change', props.model[props.name]);
|
|
102
|
+
};
|
|
103
|
+
</script>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<MSelect
|
|
3
|
+
:model="model"
|
|
4
|
+
:name="name"
|
|
5
|
+
:size="size"
|
|
6
|
+
:prop="prop"
|
|
7
|
+
:disabled="disabled"
|
|
8
|
+
:config="selectConfig"
|
|
9
|
+
:last-values="lastValues"
|
|
10
|
+
@change="changeHandler"
|
|
11
|
+
></MSelect>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script setup lang="ts">
|
|
15
|
+
import { computed, inject } from 'vue';
|
|
16
|
+
|
|
17
|
+
import { FieldProps, MSelect, SelectConfig } from '@tmagic/form';
|
|
18
|
+
|
|
19
|
+
import { Services } from '../type';
|
|
20
|
+
|
|
21
|
+
defineOptions({
|
|
22
|
+
name: 'MEditorDataSourceSelect',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const emit = defineEmits(['change']);
|
|
26
|
+
|
|
27
|
+
const props = withDefaults(
|
|
28
|
+
defineProps<
|
|
29
|
+
FieldProps<{
|
|
30
|
+
type: 'data-source-select';
|
|
31
|
+
name: string;
|
|
32
|
+
text: string;
|
|
33
|
+
placeholder: string;
|
|
34
|
+
dataSourceType?: string;
|
|
35
|
+
}>
|
|
36
|
+
>(),
|
|
37
|
+
{
|
|
38
|
+
disabled: false,
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const { dataSourceService } = inject<Services>('services') || {};
|
|
43
|
+
|
|
44
|
+
const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
|
|
45
|
+
|
|
46
|
+
const selectConfig = computed<SelectConfig>(() => {
|
|
47
|
+
const { type, dataSourceType, ...config } = props.config;
|
|
48
|
+
return {
|
|
49
|
+
...config,
|
|
50
|
+
type: 'select',
|
|
51
|
+
valueKey: 'dataSourceId',
|
|
52
|
+
options: dataSources.value
|
|
53
|
+
.filter((ds) => !dataSourceType || ds.type === dataSourceType)
|
|
54
|
+
.map((ds) => ({
|
|
55
|
+
value: {
|
|
56
|
+
isBindDataSource: true,
|
|
57
|
+
dataSourceType: ds.type,
|
|
58
|
+
dataSourceId: ds.id,
|
|
59
|
+
},
|
|
60
|
+
text: ds.title || ds.id,
|
|
61
|
+
})),
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const changeHandler = (value: any) => {
|
|
66
|
+
emit('change', value);
|
|
67
|
+
};
|
|
68
|
+
</script>
|