@tmagic/editor 1.3.15 → 1.4.0-beta.1
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 +875 -530
- package/dist/tmagic-editor.umd.cjs +891 -545
- package/package.json +23 -21
- package/src/Editor.vue +8 -0
- package/src/components/CodeBlockEditor.vue +50 -24
- package/src/components/FloatingBox.vue +53 -12
- package/src/fields/Code.vue +12 -10
- package/src/fields/CodeLink.vue +9 -9
- package/src/fields/CodeSelect.vue +7 -5
- package/src/fields/CodeSelectCol.vue +1 -1
- package/src/fields/DataSourceFieldSelect.vue +118 -27
- package/src/fields/DataSourceFields.vue +10 -3
- package/src/fields/DataSourceInput.vue +7 -7
- package/src/fields/DataSourceMethodSelect.vue +1 -1
- package/src/fields/DataSourceMethods.vue +3 -3
- package/src/fields/DataSourceMocks.vue +3 -3
- package/src/fields/DataSourceSelect.vue +6 -18
- package/src/fields/EventSelect.vue +1 -1
- package/src/fields/KeyValue.vue +8 -8
- package/src/fields/PageFragmentSelect.vue +1 -1
- package/src/fields/UISelect.vue +5 -5
- package/src/hooks/use-code-block-edit.ts +0 -1
- package/src/index.ts +3 -2
- package/src/layouts/NavMenu.vue +21 -2
- package/src/layouts/sidebar/Sidebar.vue +16 -1
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -1
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +3 -0
- package/src/services/BaseService.ts +5 -2
- package/src/services/codeBlock.ts +14 -8
- package/src/services/dataSource.ts +39 -26
- package/src/services/editor.ts +46 -25
- package/src/services/events.ts +4 -4
- package/src/services/props.ts +44 -35
- package/src/services/stageOverlay.ts +14 -7
- package/src/services/storage.ts +14 -8
- package/src/services/ui.ts +20 -19
- package/src/theme/code-editor.scss +6 -0
- package/src/theme/component-list-panel.scss +79 -71
- package/src/theme/floating-box.scss +2 -0
- package/src/theme/layer-panel.scss +1 -0
- package/src/theme/sidebar.scss +6 -3
- package/src/type.ts +82 -37
- package/src/utils/operator.ts +37 -39
- package/src/utils/props.ts +174 -37
- package/types/components/CodeBlockEditor.vue.d.ts +4 -4
- package/types/components/CodeParams.vue.d.ts +5 -5
- package/types/components/ContentMenu.vue.d.ts +12 -12
- package/types/components/FloatingBox.vue.d.ts +14 -12
- package/types/components/Icon.vue.d.ts +3 -3
- package/types/components/Resizer.vue.d.ts +3 -3
- package/types/components/ScrollBar.vue.d.ts +3 -3
- package/types/components/ScrollViewer.vue.d.ts +12 -12
- package/types/components/SearchInput.vue.d.ts +1 -1
- package/types/components/SplitView.vue.d.ts +11 -11
- package/types/components/ToolButton.vue.d.ts +13 -13
- package/types/components/Tree.vue.d.ts +24 -14
- package/types/components/TreeNode.vue.d.ts +22 -12
- package/types/fields/Code.vue.d.ts +14 -14
- package/types/fields/CodeLink.vue.d.ts +6 -10
- package/types/fields/CodeSelect.vue.d.ts +14 -14
- package/types/fields/CodeSelectCol.vue.d.ts +11 -11
- package/types/fields/DataSourceFieldSelect.vue.d.ts +11 -11
- package/types/fields/DataSourceFields.vue.d.ts +11 -11
- package/types/fields/DataSourceInput.vue.d.ts +14 -18
- package/types/fields/DataSourceMethodSelect.vue.d.ts +11 -11
- package/types/fields/DataSourceMethods.vue.d.ts +11 -11
- package/types/fields/DataSourceMocks.vue.d.ts +11 -11
- package/types/fields/DataSourceSelect.vue.d.ts +13 -26
- package/types/fields/EventSelect.vue.d.ts +3 -3
- package/types/fields/KeyValue.vue.d.ts +14 -18
- package/types/fields/PageFragmentSelect.vue.d.ts +11 -11
- package/types/fields/UISelect.vue.d.ts +8 -4
- package/types/hooks/use-code-block-edit.d.ts +51 -89
- package/types/hooks/use-data-source-method.d.ts +51 -89
- package/types/hooks/use-node-status.d.ts +6 -1
- package/types/icons/AppManageIcon.vue.d.ts +1 -1
- package/types/icons/CenterIcon.vue.d.ts +1 -1
- package/types/icons/CodeIcon.vue.d.ts +1 -1
- package/types/icons/FolderMinusIcon.vue.d.ts +1 -1
- package/types/icons/PinIcon.vue.d.ts +1 -1
- package/types/icons/PinnedIcon.vue.d.ts +1 -1
- package/types/index.d.ts +1 -0
- package/types/layouts/AddPageBox.vue.d.ts +3 -3
- package/types/layouts/CodeEditor.vue.d.ts +12 -12
- package/types/layouts/Framework.vue.d.ts +9 -9
- package/types/layouts/NavMenu.vue.d.ts +11 -11
- package/types/layouts/PropsPanel.vue.d.ts +193 -243
- package/types/layouts/page-bar/AddButton.vue.d.ts +3 -3
- package/types/layouts/page-bar/PageBar.vue.d.ts +8 -8
- package/types/layouts/page-bar/PageBarScrollContainer.vue.d.ts +8 -8
- package/types/layouts/page-bar/SwitchTypeButton.vue.d.ts +3 -3
- package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +1 -1
- package/types/layouts/sidebar/Sidebar.vue.d.ts +12 -12
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +10 -10
- package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +9 -9
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -3
- package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +3 -3
- package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +9 -9
- package/types/layouts/sidebar/layer/LayerMenu.vue.d.ts +11 -11
- package/types/layouts/sidebar/layer/LayerNodeTool.vue.d.ts +3 -3
- package/types/layouts/sidebar/layer/LayerPanel.vue.d.ts +9 -9
- package/types/layouts/sidebar/layer/use-click.d.ts +42 -76
- package/types/layouts/sidebar/layer/use-node-status.d.ts +6 -1
- package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -1
- package/types/layouts/workspace/Workspace.vue.d.ts +12 -12
- package/types/layouts/workspace/viewer/NodeListMenu.vue.d.ts +1 -1
- package/types/layouts/workspace/viewer/Stage.vue.d.ts +11 -11
- package/types/layouts/workspace/viewer/StageOverlay.vue.d.ts +1 -1
- package/types/layouts/workspace/viewer/ViewerMenu.vue.d.ts +12 -12
- package/types/services/BaseService.d.ts +5 -2
- package/types/services/codeBlock.d.ts +8 -0
- package/types/services/dataSource.d.ts +9 -2
- package/types/services/editor.d.ts +8 -1
- package/types/services/props.d.ts +15 -22
- package/types/services/stageOverlay.d.ts +8 -1
- package/types/services/storage.d.ts +8 -0
- package/types/services/ui.d.ts +15 -9
- package/types/type.d.ts +51 -32
- package/types/utils/operator.d.ts +1 -1
- package/types/utils/props.d.ts +2 -13
|
@@ -48,7 +48,7 @@ import { computed, inject, nextTick, ref, watch } from 'vue';
|
|
|
48
48
|
import { Coin } from '@element-plus/icons-vue';
|
|
49
49
|
|
|
50
50
|
import { getConfig, TMagicAutocomplete, TMagicTag } from '@tmagic/design';
|
|
51
|
-
import type { FieldProps } from '@tmagic/form';
|
|
51
|
+
import type { FieldProps, FormItem } from '@tmagic/form';
|
|
52
52
|
import type { DataSchema, DataSourceSchema } from '@tmagic/schema';
|
|
53
53
|
|
|
54
54
|
import Icon from '@editor/components/Icon.vue';
|
|
@@ -56,16 +56,16 @@ import type { Services } from '@editor/type';
|
|
|
56
56
|
import { getDisplayField } from '@editor/utils/data-source';
|
|
57
57
|
|
|
58
58
|
defineOptions({
|
|
59
|
-
name: '
|
|
59
|
+
name: 'MFieldsDataSourceInput',
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
const props = withDefaults(
|
|
63
63
|
defineProps<
|
|
64
|
-
FieldProps<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
FieldProps<
|
|
65
|
+
{
|
|
66
|
+
type: 'data-source-input';
|
|
67
|
+
} & FormItem
|
|
68
|
+
>
|
|
69
69
|
>(),
|
|
70
70
|
{
|
|
71
71
|
disabled: false,
|
|
@@ -49,7 +49,7 @@ import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
|
|
|
49
49
|
import type { CodeParamStatement, DataSourceMethodSelectConfig, Services } from '@editor/type';
|
|
50
50
|
|
|
51
51
|
defineOptions({
|
|
52
|
-
name: '
|
|
52
|
+
name: 'MFieldsDataSourceMethodSelect',
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
const mForm = inject<FormState | undefined>('mForm');
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
import { TMagicButton } from '@tmagic/design';
|
|
25
25
|
import type { FieldProps } from '@tmagic/form';
|
|
26
26
|
import type { CodeBlockContent } from '@tmagic/schema';
|
|
27
|
-
import { MagicTable } from '@tmagic/table';
|
|
27
|
+
import { type ColumnConfig, MagicTable } from '@tmagic/table';
|
|
28
28
|
|
|
29
29
|
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
30
30
|
import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
|
|
31
31
|
import type { CodeParamStatement } from '@editor/type';
|
|
32
32
|
|
|
33
33
|
defineOptions({
|
|
34
|
-
name: '
|
|
34
|
+
name: 'MFieldsDataSourceMethods',
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
const props = withDefaults(
|
|
@@ -49,7 +49,7 @@ const emit = defineEmits(['change']);
|
|
|
49
49
|
|
|
50
50
|
const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
|
|
51
51
|
|
|
52
|
-
const methodColumns = [
|
|
52
|
+
const methodColumns: ColumnConfig[] = [
|
|
53
53
|
{
|
|
54
54
|
label: '名称',
|
|
55
55
|
prop: 'name',
|
|
@@ -26,14 +26,14 @@ import { computed, inject, ref } from 'vue';
|
|
|
26
26
|
import { TMagicButton, tMagicMessageBox, TMagicSwitch } from '@tmagic/design';
|
|
27
27
|
import { type FieldProps, type FormConfig, type FormState, MFormDrawer } from '@tmagic/form';
|
|
28
28
|
import type { MockSchema } from '@tmagic/schema';
|
|
29
|
-
import { MagicTable } from '@tmagic/table';
|
|
29
|
+
import { type ColumnConfig, MagicTable } from '@tmagic/table';
|
|
30
30
|
import { getDefaultValueFromFields } from '@tmagic/utils';
|
|
31
31
|
|
|
32
32
|
import CodeEditor from '@editor/layouts/CodeEditor.vue';
|
|
33
33
|
import { Services } from '@editor/type';
|
|
34
34
|
|
|
35
35
|
defineOptions({
|
|
36
|
-
name: '
|
|
36
|
+
name: 'MFieldsDataSourceMocks',
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
const props = withDefaults(
|
|
@@ -117,7 +117,7 @@ const formConfig: FormConfig = [
|
|
|
117
117
|
},
|
|
118
118
|
];
|
|
119
119
|
|
|
120
|
-
const columns = [
|
|
120
|
+
const columns: ColumnConfig[] = [
|
|
121
121
|
{
|
|
122
122
|
type: 'expand',
|
|
123
123
|
component: CodeEditor,
|
|
@@ -14,31 +14,19 @@
|
|
|
14
14
|
<script setup lang="ts">
|
|
15
15
|
import { computed, inject } from 'vue';
|
|
16
16
|
|
|
17
|
-
import { FieldProps, MSelect, SelectConfig } from '@tmagic/form';
|
|
17
|
+
import { type FieldProps, MSelect, type SelectConfig } from '@tmagic/form';
|
|
18
18
|
|
|
19
|
-
import { Services } from '../type';
|
|
19
|
+
import type { DataSourceSelect, Services } from '../type';
|
|
20
20
|
|
|
21
21
|
defineOptions({
|
|
22
|
-
name: '
|
|
22
|
+
name: 'MFieldsDataSourceSelect',
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
const emit = defineEmits(['change']);
|
|
26
26
|
|
|
27
|
-
const props = withDefaults(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type: 'data-source-select';
|
|
31
|
-
name: string;
|
|
32
|
-
text?: string;
|
|
33
|
-
placeholder?: string;
|
|
34
|
-
dataSourceType?: string;
|
|
35
|
-
value?: 'id' | 'value';
|
|
36
|
-
}>
|
|
37
|
-
>(),
|
|
38
|
-
{
|
|
39
|
-
disabled: false,
|
|
40
|
-
},
|
|
41
|
-
);
|
|
27
|
+
const props = withDefaults(defineProps<FieldProps<DataSourceSelect>>(), {
|
|
28
|
+
disabled: false,
|
|
29
|
+
});
|
|
42
30
|
|
|
43
31
|
const { dataSourceService } = inject<Services>('services') || {};
|
|
44
32
|
|
|
@@ -61,7 +61,7 @@ import { ActionType } from '@tmagic/schema';
|
|
|
61
61
|
import type { CodeSelectColConfig, DataSourceMethodSelectConfig, EventSelectConfig, Services } from '@editor/type';
|
|
62
62
|
|
|
63
63
|
defineOptions({
|
|
64
|
-
name: '
|
|
64
|
+
name: 'MFieldsEventSelect',
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
const props = defineProps<FieldProps<EventSelectConfig>>();
|
package/src/fields/KeyValue.vue
CHANGED
|
@@ -63,23 +63,23 @@ import { ref, watchEffect } from 'vue';
|
|
|
63
63
|
import { Delete, Plus } from '@element-plus/icons-vue';
|
|
64
64
|
|
|
65
65
|
import { TMagicButton, TMagicInput } from '@tmagic/design';
|
|
66
|
-
import type { FieldProps } from '@tmagic/form';
|
|
66
|
+
import type { FieldProps, FormItem } from '@tmagic/form';
|
|
67
67
|
|
|
68
68
|
import CodeIcon from '@editor/icons/CodeIcon.vue';
|
|
69
69
|
import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
|
|
70
70
|
|
|
71
71
|
defineOptions({
|
|
72
|
-
name: '
|
|
72
|
+
name: 'MFieldsKeyValue',
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
const props = withDefaults(
|
|
76
76
|
defineProps<
|
|
77
|
-
FieldProps<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
FieldProps<
|
|
78
|
+
{
|
|
79
|
+
type: 'key-value';
|
|
80
|
+
advanced?: boolean;
|
|
81
|
+
} & FormItem
|
|
82
|
+
>
|
|
83
83
|
>(),
|
|
84
84
|
{
|
|
85
85
|
disabled: false,
|
|
@@ -26,7 +26,7 @@ import Icon from '@editor/components/Icon.vue';
|
|
|
26
26
|
import type { PageFragmentSelectConfig, Services } from '@editor/type';
|
|
27
27
|
|
|
28
28
|
defineOptions({
|
|
29
|
-
name: '
|
|
29
|
+
name: 'MFieldsPageFragmentSelect',
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
const services = inject<Services>('services');
|
package/src/fields/UISelect.vue
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
:size="size"
|
|
27
27
|
@click="selectNode(val)"
|
|
28
28
|
@mouseenter="highlight(val)"
|
|
29
|
-
@mouseleave="
|
|
29
|
+
@mouseleave="unhighlight"
|
|
30
30
|
>{{ `${toName}_${val}` }}</TMagicButton
|
|
31
31
|
>
|
|
32
32
|
</TMagicTooltip>
|
|
@@ -46,16 +46,16 @@ import { Close, Delete } from '@element-plus/icons-vue';
|
|
|
46
46
|
import { throttle } from 'lodash-es';
|
|
47
47
|
|
|
48
48
|
import { TMagicButton, TMagicTooltip } from '@tmagic/design';
|
|
49
|
-
import type { FieldProps, FormState } from '@tmagic/form';
|
|
49
|
+
import type { FieldProps, FormItem, FormState } from '@tmagic/form';
|
|
50
50
|
import type { Id } from '@tmagic/schema';
|
|
51
51
|
|
|
52
52
|
import { Services, UI_SELECT_MODE_EVENT_NAME } from '@editor/type';
|
|
53
53
|
|
|
54
54
|
defineOptions({
|
|
55
|
-
name: '
|
|
55
|
+
name: 'MFieldsUISelect',
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
const props = defineProps<FieldProps<
|
|
58
|
+
const props = defineProps<FieldProps<{ type: 'ui-select' } & FormItem>>();
|
|
59
59
|
|
|
60
60
|
const emit = defineEmits(['change']);
|
|
61
61
|
|
|
@@ -115,7 +115,7 @@ const highlight = throttle((id: Id) => {
|
|
|
115
115
|
services?.stageOverlayService.get('stage')?.highlight(id);
|
|
116
116
|
}, 150);
|
|
117
117
|
|
|
118
|
-
const
|
|
118
|
+
const unhighlight = () => {
|
|
119
119
|
services?.editorService.set('highlightNode', null);
|
|
120
120
|
services?.editorService.get('stage')?.clearHighlight();
|
|
121
121
|
services?.stageOverlayService.get('stage')?.clearHighlight();
|
package/src/index.ts
CHANGED
|
@@ -73,6 +73,7 @@ export { default as EventSelect } from './fields/EventSelect.vue';
|
|
|
73
73
|
export { default as KeyValue } from './fields/KeyValue.vue';
|
|
74
74
|
export { default as CodeBlockList } from './layouts/sidebar/code-block/CodeBlockList.vue';
|
|
75
75
|
export { default as CodeBlockListPanel } from './layouts/sidebar/code-block/CodeBlockListPanel.vue';
|
|
76
|
+
export { default as DataSourceConfigPanel } from './layouts/sidebar/data-source/DataSourceConfigPanel.vue';
|
|
76
77
|
export { default as PropsPanel } from './layouts/PropsPanel.vue';
|
|
77
78
|
export { default as ToolButton } from './components/ToolButton.vue';
|
|
78
79
|
export { default as ContentMenu } from './components/ContentMenu.vue';
|
|
@@ -95,11 +96,11 @@ export default {
|
|
|
95
96
|
// eslint-disable-next-line no-param-reassign
|
|
96
97
|
app.config.globalProperties.$TMAGIC_EDITOR = option;
|
|
97
98
|
setConfig(option);
|
|
98
|
-
app.component(Editor.name
|
|
99
|
+
app.component(`${Editor.name || 'MEditor'}`, Editor);
|
|
100
|
+
app.component('magic-code-editor', CodeEditor);
|
|
99
101
|
app.component('m-fields-ui-select', uiSelect);
|
|
100
102
|
app.component('m-fields-code-link', CodeLink);
|
|
101
103
|
app.component('m-fields-vs-code', Code);
|
|
102
|
-
app.component('magic-code-editor', CodeEditor);
|
|
103
104
|
app.component('m-fields-code-select', CodeSelect);
|
|
104
105
|
app.component('m-fields-code-select-col', CodeSelectCol);
|
|
105
106
|
app.component('m-fields-event-select', EventSelect);
|
package/src/layouts/NavMenu.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="m-editor-nav-menu" :style="{ height: `${height}px` }">
|
|
2
|
+
<div class="m-editor-nav-menu" :style="{ height: `${height}px` }" ref="navMenu">
|
|
3
3
|
<div v-for="key in keys" :class="`menu-${key}`" :key="key" :style="`width: ${columnWidth?.[key]}px`">
|
|
4
4
|
<ToolButton :data="item" v-for="(item, index) in buttons[key]" :key="index"></ToolButton>
|
|
5
5
|
</div>
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
</template>
|
|
8
8
|
|
|
9
9
|
<script lang="ts" setup>
|
|
10
|
-
import { computed, inject, markRaw } from 'vue';
|
|
10
|
+
import { computed, inject, markRaw, onBeforeUnmount, onMounted, ref } from 'vue';
|
|
11
11
|
import { Back, Delete, FullScreen, Grid, Memo, Right, ScaleToOriginal, ZoomIn, ZoomOut } from '@element-plus/icons-vue';
|
|
12
12
|
|
|
13
13
|
import { NodeType } from '@tmagic/schema';
|
|
@@ -178,4 +178,23 @@ const buttons = computed(() => {
|
|
|
178
178
|
});
|
|
179
179
|
return data;
|
|
180
180
|
});
|
|
181
|
+
|
|
182
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
183
|
+
const rect = navMenu.value?.getBoundingClientRect();
|
|
184
|
+
if (rect) {
|
|
185
|
+
uiService?.set('navMenuRect', {
|
|
186
|
+
left: rect.left,
|
|
187
|
+
top: rect.top,
|
|
188
|
+
width: rect.width,
|
|
189
|
+
height: rect.height,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
const navMenu = ref<HTMLDivElement>();
|
|
194
|
+
onMounted(() => {
|
|
195
|
+
navMenu.value && resizeObserver.observe(navMenu.value);
|
|
196
|
+
});
|
|
197
|
+
onBeforeUnmount(() => {
|
|
198
|
+
resizeObserver.disconnect();
|
|
199
|
+
});
|
|
181
200
|
</script>
|
|
@@ -66,6 +66,11 @@
|
|
|
66
66
|
<component v-else-if="config.slots?.codeBlockPanelTool" :is="config.slots.codeBlockPanelTool" />
|
|
67
67
|
</template>
|
|
68
68
|
|
|
69
|
+
<template #code-block-panel-search v-if="config.$key === 'code-block' || config.slots?.codeBlockPanelSearch">
|
|
70
|
+
<slot v-if="config.$key === 'code-block'" name="code-block-panel-search"></slot>
|
|
71
|
+
<component v-else-if="config.slots?.codeBlockPanelSearch" :is="config.slots.codeBlockPanelSearch" />
|
|
72
|
+
</template>
|
|
73
|
+
|
|
69
74
|
<template
|
|
70
75
|
#layer-node-content="{ data: nodeData }"
|
|
71
76
|
v-if="config.$key === 'layer' || config.slots?.layerNodeContent"
|
|
@@ -86,11 +91,16 @@
|
|
|
86
91
|
|
|
87
92
|
<template
|
|
88
93
|
#data-source-panel-tool="{ data }"
|
|
89
|
-
v-if="config.$key === 'data-source' || config.slots?.
|
|
94
|
+
v-if="config.$key === 'data-source' || config.slots?.dataSourcePanelTool"
|
|
90
95
|
>
|
|
91
96
|
<slot v-if="config.$key === 'data-source'" name="data-source-panel-tool" :data="data"></slot>
|
|
92
97
|
<component v-else-if="config.slots?.DataSourcePanelTool" :is="config.slots.DataSourcePanelTool" />
|
|
93
98
|
</template>
|
|
99
|
+
|
|
100
|
+
<template #data-source-panel-search v-if="config.$key === 'data-source' || config.slots?.dataSourcePanelSearch">
|
|
101
|
+
<slot v-if="config.$key === 'data-source'" name="data-source-panel-search"></slot>
|
|
102
|
+
<component v-else-if="config.slots?.dataSourcePanelSearch" :is="config.slots.dataSourcePanelSearch" />
|
|
103
|
+
</template>
|
|
94
104
|
</component>
|
|
95
105
|
</div>
|
|
96
106
|
</div>
|
|
@@ -194,6 +204,11 @@ const getItemConfig = (data: SideItem): SideComponent => {
|
|
|
194
204
|
text: '代码编辑',
|
|
195
205
|
component: CodeBlockListPanel,
|
|
196
206
|
slots: {},
|
|
207
|
+
boxComponentConfig: {
|
|
208
|
+
props: {
|
|
209
|
+
slideType: 'box',
|
|
210
|
+
},
|
|
211
|
+
},
|
|
197
212
|
},
|
|
198
213
|
'data-source': {
|
|
199
214
|
$key: 'data-source',
|
|
@@ -20,11 +20,14 @@
|
|
|
20
20
|
></ToolButton>
|
|
21
21
|
</div>
|
|
22
22
|
</TMagicPopover>
|
|
23
|
+
|
|
24
|
+
<slot name="data-source-panel-search"></slot>
|
|
23
25
|
</div>
|
|
24
26
|
|
|
25
27
|
<!-- 数据源列表 -->
|
|
26
28
|
<DataSourceList @edit="editHandler" @remove="removeHandler"></DataSourceList>
|
|
27
29
|
</TMagicScrollbar>
|
|
30
|
+
|
|
28
31
|
<DataSourceConfigPanel
|
|
29
32
|
ref="editDialog"
|
|
30
33
|
:disabled="!editable"
|
|
@@ -103,7 +103,7 @@ const doAsyncAction = async (
|
|
|
103
103
|
* 例如:
|
|
104
104
|
* Class EditorService extends BaseService {
|
|
105
105
|
* constructor() {
|
|
106
|
-
* super(['add']);
|
|
106
|
+
* super([ { name: 'add', isAsync: true },]);
|
|
107
107
|
* }
|
|
108
108
|
* add(value) { return result; }
|
|
109
109
|
* };
|
|
@@ -131,7 +131,7 @@ const doAsyncAction = async (
|
|
|
131
131
|
* 例如:
|
|
132
132
|
* Class EditorService extends BaseService {
|
|
133
133
|
* constructor() {
|
|
134
|
-
* super(['add']);
|
|
134
|
+
* super([ { name: 'add', isAsync: true },]);
|
|
135
135
|
* }
|
|
136
136
|
* add(value) { return result; }
|
|
137
137
|
* };
|
|
@@ -194,6 +194,9 @@ export default class extends EventEmitter {
|
|
|
194
194
|
});
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
/**
|
|
198
|
+
* @deprecated 请使用usePlugin代替
|
|
199
|
+
*/
|
|
197
200
|
public use(options: Record<string, Function>) {
|
|
198
201
|
Object.entries(options).forEach(([methodName, method]: [string, Function]) => {
|
|
199
202
|
if (typeof method === 'function') this.middleware[methodName].push(method);
|
|
@@ -18,16 +18,24 @@
|
|
|
18
18
|
|
|
19
19
|
import { reactive } from 'vue';
|
|
20
20
|
import { keys, pick } from 'lodash-es';
|
|
21
|
+
import type { Writable } from 'type-fest';
|
|
21
22
|
|
|
22
23
|
import type { ColumnConfig } from '@tmagic/form';
|
|
23
24
|
import type { CodeBlockContent, CodeBlockDSL, Id } from '@tmagic/schema';
|
|
24
25
|
|
|
25
|
-
import type { CodeState } from '@editor/type';
|
|
26
|
+
import type { AsyncHookPlugin, CodeState } from '@editor/type';
|
|
26
27
|
import { CODE_DRAFT_STORAGE_KEY } from '@editor/type';
|
|
27
28
|
import { getConfig } from '@editor/utils/config';
|
|
28
29
|
|
|
29
30
|
import BaseService from './BaseService';
|
|
30
31
|
|
|
32
|
+
const canUsePluginMethods = {
|
|
33
|
+
async: ['setCodeDslById', 'setEditStatus', 'setCombineIds', 'setUndeleteableList', 'deleteCodeDslByIds'] as const,
|
|
34
|
+
sync: [],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type AsyncMethodName = Writable<(typeof canUsePluginMethods)['async']>;
|
|
38
|
+
|
|
31
39
|
class CodeBlock extends BaseService {
|
|
32
40
|
private state = reactive<CodeState>({
|
|
33
41
|
codeDsl: null,
|
|
@@ -38,13 +46,7 @@ class CodeBlock extends BaseService {
|
|
|
38
46
|
});
|
|
39
47
|
|
|
40
48
|
constructor() {
|
|
41
|
-
super(
|
|
42
|
-
{ name: 'setCodeDslById', isAsync: true },
|
|
43
|
-
{ name: 'setEditStatus', isAsync: true },
|
|
44
|
-
{ name: 'setCombineIds', isAsync: true },
|
|
45
|
-
{ name: 'setUndeleteableList', isAsync: true },
|
|
46
|
-
{ name: 'deleteCodeDslByIds', isAsync: true },
|
|
47
|
-
]);
|
|
49
|
+
super(canUsePluginMethods.async.map((methodName) => ({ name: methodName, isAsync: true })));
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
@@ -243,6 +245,10 @@ class CodeBlock extends BaseService {
|
|
|
243
245
|
this.removeAllListeners();
|
|
244
246
|
this.removeAllPlugins();
|
|
245
247
|
}
|
|
248
|
+
|
|
249
|
+
public usePlugin(options: AsyncHookPlugin<AsyncMethodName, CodeBlock>): void {
|
|
250
|
+
super.usePlugin(options);
|
|
251
|
+
}
|
|
246
252
|
}
|
|
247
253
|
|
|
248
254
|
export type CodeBlockService = CodeBlock;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { reactive } from 'vue';
|
|
2
2
|
import { cloneDeep } from 'lodash-es';
|
|
3
|
+
import { Writable } from 'type-fest';
|
|
3
4
|
|
|
4
5
|
import type { EventOption } from '@tmagic/core';
|
|
5
6
|
import type { FormConfig } from '@tmagic/form';
|
|
6
7
|
import type { DataSourceSchema } from '@tmagic/schema';
|
|
7
|
-
import { guid } from '@tmagic/utils';
|
|
8
|
+
import { guid, toLine } from '@tmagic/utils';
|
|
8
9
|
|
|
9
|
-
import type { DatasourceTypeOption } from '@editor/type';
|
|
10
|
+
import type { DatasourceTypeOption, SyncHookPlugin } from '@editor/type';
|
|
10
11
|
import { getFormConfig, getFormValue } from '@editor/utils/data-source';
|
|
11
12
|
|
|
12
13
|
import BaseService from './BaseService';
|
|
@@ -22,6 +23,27 @@ interface State {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
type StateKey = keyof State;
|
|
26
|
+
|
|
27
|
+
const canUsePluginMethods = {
|
|
28
|
+
async: [],
|
|
29
|
+
sync: [
|
|
30
|
+
'getFormConfig',
|
|
31
|
+
'setFormConfig',
|
|
32
|
+
'getFormValue',
|
|
33
|
+
'setFormValue',
|
|
34
|
+
'getFormEvent',
|
|
35
|
+
'setFormEvent',
|
|
36
|
+
'getFormMethod',
|
|
37
|
+
'setFormMethod',
|
|
38
|
+
'add',
|
|
39
|
+
'update',
|
|
40
|
+
'remove',
|
|
41
|
+
'createId',
|
|
42
|
+
] as const,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type SyncMethodName = Writable<(typeof canUsePluginMethods)['sync']>;
|
|
46
|
+
|
|
25
47
|
class DataSource extends BaseService {
|
|
26
48
|
private state = reactive<State>({
|
|
27
49
|
datasourceTypeList: [],
|
|
@@ -34,20 +56,7 @@ class DataSource extends BaseService {
|
|
|
34
56
|
});
|
|
35
57
|
|
|
36
58
|
constructor() {
|
|
37
|
-
super(
|
|
38
|
-
{ name: 'getFormConfig', isAsync: false },
|
|
39
|
-
{ name: 'setFormConfig', isAsync: false },
|
|
40
|
-
{ name: 'getFormValue', isAsync: false },
|
|
41
|
-
{ name: 'setFormValue', isAsync: false },
|
|
42
|
-
{ name: 'getFormEvent', isAsync: false },
|
|
43
|
-
{ name: 'setFormEvent', isAsync: false },
|
|
44
|
-
{ name: 'getFormMethod', isAsync: false },
|
|
45
|
-
{ name: 'setFormMethod', isAsync: false },
|
|
46
|
-
{ name: 'add', isAsync: false },
|
|
47
|
-
{ name: 'update', isAsync: false },
|
|
48
|
-
{ name: 'remove', isAsync: false },
|
|
49
|
-
{ name: 'createId', isAsync: false },
|
|
50
|
-
]);
|
|
59
|
+
super(canUsePluginMethods.sync.map((methodName) => ({ name: methodName, isAsync: false })));
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
public set<K extends StateKey, T extends State[K]>(name: K, value: T) {
|
|
@@ -59,35 +68,35 @@ class DataSource extends BaseService {
|
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
public getFormConfig(type = 'base') {
|
|
62
|
-
return getFormConfig(type, this.get('configs'));
|
|
71
|
+
return getFormConfig(toLine(type), this.get('configs'));
|
|
63
72
|
}
|
|
64
73
|
|
|
65
74
|
public setFormConfig(type: string, config: FormConfig) {
|
|
66
|
-
this.get('configs')[type] = config;
|
|
75
|
+
this.get('configs')[toLine(type)] = config;
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
public getFormValue(type = 'base') {
|
|
70
|
-
return getFormValue(type, this.get('values')[type]);
|
|
79
|
+
return getFormValue(toLine(type), this.get('values')[type]);
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
public setFormValue(type: string, value: Partial<DataSourceSchema>) {
|
|
74
|
-
this.get('values')[type] = value;
|
|
83
|
+
this.get('values')[toLine(type)] = value;
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
public getFormEvent(type = 'base') {
|
|
78
|
-
return this.get('events')[type] || [];
|
|
87
|
+
return this.get('events')[toLine(type)] || [];
|
|
79
88
|
}
|
|
80
89
|
|
|
81
90
|
public setFormEvent(type: string, value: EventOption[] = []) {
|
|
82
|
-
this.get('events')[type] = value;
|
|
91
|
+
this.get('events')[toLine(type)] = value;
|
|
83
92
|
}
|
|
84
93
|
|
|
85
94
|
public getFormMethod(type = 'base') {
|
|
86
|
-
return this.get('methods')[type] || [];
|
|
95
|
+
return this.get('methods')[toLine(type)] || [];
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
public setFormMethod(type: string, value: EventOption[] = []) {
|
|
90
|
-
this.get('methods')[type] = value;
|
|
99
|
+
this.get('methods')[toLine(type)] = value;
|
|
91
100
|
}
|
|
92
101
|
|
|
93
102
|
public add(config: DataSourceSchema) {
|
|
@@ -123,6 +132,10 @@ class DataSource extends BaseService {
|
|
|
123
132
|
this.emit('remove', id);
|
|
124
133
|
}
|
|
125
134
|
|
|
135
|
+
public createId(): string {
|
|
136
|
+
return `ds_${guid()}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
126
139
|
public getDataSourceById(id: string) {
|
|
127
140
|
return this.get('dataSources').find((ds) => ds.id === id);
|
|
128
141
|
}
|
|
@@ -137,8 +150,8 @@ class DataSource extends BaseService {
|
|
|
137
150
|
this.removeAllPlugins();
|
|
138
151
|
}
|
|
139
152
|
|
|
140
|
-
|
|
141
|
-
|
|
153
|
+
public usePlugin(options: SyncHookPlugin<SyncMethodName, DataSource>): void {
|
|
154
|
+
super.usePlugin(options);
|
|
142
155
|
}
|
|
143
156
|
}
|
|
144
157
|
|