@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/types/utils/props.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { FormConfig, FormState } from '@tmagic/form';
|
|
1
|
+
import type { FormConfig, FormState, TabPaneConfig } from '@tmagic/form';
|
|
2
|
+
export declare const styleTabConfig: TabPaneConfig;
|
|
3
|
+
export declare const eventTabConfig: TabPaneConfig;
|
|
4
|
+
export declare const advancedTabConfig: TabPaneConfig;
|
|
5
|
+
export declare const displayTabConfig: TabPaneConfig;
|
|
2
6
|
/**
|
|
3
7
|
* 统一为组件属性表单加上事件、高级、样式配置
|
|
4
8
|
* @param config 组件属性配置
|
|
@@ -6,106 +10,13 @@ import { FormConfig, FormState } from '@tmagic/form';
|
|
|
6
10
|
*/
|
|
7
11
|
export declare const fillConfig: (config?: FormConfig) => {
|
|
8
12
|
type: string;
|
|
9
|
-
items:
|
|
13
|
+
items: {
|
|
14
|
+
[x: string]: any;
|
|
15
|
+
status?: string | undefined;
|
|
10
16
|
title: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
labelWidth: string;
|
|
17
|
-
items: {
|
|
18
|
-
name: string;
|
|
19
|
-
items: ({
|
|
20
|
-
type: string;
|
|
21
|
-
legend: string;
|
|
22
|
-
items: ({
|
|
23
|
-
name: string;
|
|
24
|
-
type: string;
|
|
25
|
-
activeValue: string;
|
|
26
|
-
inactiveValue: string;
|
|
27
|
-
defaultValue: string;
|
|
28
|
-
text: string;
|
|
29
|
-
disabled?: undefined;
|
|
30
|
-
} | {
|
|
31
|
-
name: string;
|
|
32
|
-
text: string;
|
|
33
|
-
type?: undefined;
|
|
34
|
-
activeValue?: undefined;
|
|
35
|
-
inactiveValue?: undefined;
|
|
36
|
-
defaultValue?: undefined;
|
|
37
|
-
disabled?: undefined;
|
|
38
|
-
} | {
|
|
39
|
-
name: string;
|
|
40
|
-
text: string;
|
|
41
|
-
disabled: (vm: FormState, { model }: any) => boolean;
|
|
42
|
-
type?: undefined;
|
|
43
|
-
activeValue?: undefined;
|
|
44
|
-
inactiveValue?: undefined;
|
|
45
|
-
defaultValue?: undefined;
|
|
46
|
-
})[];
|
|
47
|
-
name?: undefined;
|
|
48
|
-
} | {
|
|
49
|
-
type: string;
|
|
50
|
-
legend: string;
|
|
51
|
-
items: ({
|
|
52
|
-
name: string;
|
|
53
|
-
text: string;
|
|
54
|
-
type?: undefined;
|
|
55
|
-
defaultValue?: undefined;
|
|
56
|
-
options?: undefined;
|
|
57
|
-
} | {
|
|
58
|
-
name: string;
|
|
59
|
-
text: string;
|
|
60
|
-
type: string;
|
|
61
|
-
defaultValue?: undefined;
|
|
62
|
-
options?: undefined;
|
|
63
|
-
} | {
|
|
64
|
-
name: string;
|
|
65
|
-
text: string;
|
|
66
|
-
type: string;
|
|
67
|
-
defaultValue: string;
|
|
68
|
-
options: {
|
|
69
|
-
text: string;
|
|
70
|
-
value: string;
|
|
71
|
-
}[];
|
|
72
|
-
} | {
|
|
73
|
-
name: string;
|
|
74
|
-
text: string;
|
|
75
|
-
defaultValue: string;
|
|
76
|
-
type?: undefined;
|
|
77
|
-
options?: undefined;
|
|
78
|
-
})[];
|
|
79
|
-
name?: undefined;
|
|
80
|
-
} | {
|
|
81
|
-
type: string;
|
|
82
|
-
legend: string;
|
|
83
|
-
name: string;
|
|
84
|
-
items: {
|
|
85
|
-
name: string;
|
|
86
|
-
text: string;
|
|
87
|
-
}[];
|
|
88
|
-
})[];
|
|
89
|
-
}[];
|
|
90
|
-
lazy?: undefined;
|
|
91
|
-
} | {
|
|
92
|
-
title: string;
|
|
93
|
-
items: {
|
|
94
|
-
name: string;
|
|
95
|
-
type: string;
|
|
96
|
-
labelWidth: number;
|
|
97
|
-
}[];
|
|
98
|
-
labelWidth?: undefined;
|
|
99
|
-
lazy?: undefined;
|
|
100
|
-
} | {
|
|
101
|
-
title: string;
|
|
102
|
-
lazy: boolean;
|
|
103
|
-
items: {
|
|
104
|
-
name: string;
|
|
105
|
-
text: string;
|
|
106
|
-
labelWidth: string;
|
|
107
|
-
type: string;
|
|
108
|
-
}[];
|
|
109
|
-
labelWidth?: undefined;
|
|
110
|
-
})[];
|
|
17
|
+
lazy?: boolean | undefined;
|
|
18
|
+
labelWidth?: string | undefined;
|
|
19
|
+
items: FormConfig;
|
|
20
|
+
onTabClick?: ((mForm: FormState | undefined, tab: any, data: any) => void) | undefined;
|
|
21
|
+
}[];
|
|
111
22
|
}[];
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="m-editor-wrapper" :class="isFullScreen ? 'fullScreen' : 'normal'">
|
|
3
|
-
<magic-code-editor
|
|
4
|
-
ref="codeEditor"
|
|
5
|
-
class="m-editor-container"
|
|
6
|
-
:init-values="`${codeContent}`"
|
|
7
|
-
@save="saveCodeDraft"
|
|
8
|
-
:language="language"
|
|
9
|
-
:options="codeOptions"
|
|
10
|
-
></magic-code-editor>
|
|
11
|
-
<div class="m-editor-content-bottom" v-if="editable">
|
|
12
|
-
<TMagicButton type="primary" class="button" @click="toggleFullScreen">
|
|
13
|
-
{{ isFullScreen ? '退出全屏' : '全屏' }}</TMagicButton
|
|
14
|
-
>
|
|
15
|
-
<TMagicButton type="primary" class="button" @click="saveAndClose">确认</TMagicButton>
|
|
16
|
-
<TMagicButton class="button" @click="close">关闭</TMagicButton>
|
|
17
|
-
</div>
|
|
18
|
-
<div class="m-editor-content-bottom" v-else>
|
|
19
|
-
<TMagicButton type="primary" class="button" @click="toggleFullScreen">
|
|
20
|
-
{{ isFullScreen ? '退出全屏' : '全屏' }}</TMagicButton
|
|
21
|
-
>
|
|
22
|
-
<TMagicButton class="button" @click="close">关闭</TMagicButton>
|
|
23
|
-
</div>
|
|
24
|
-
</div>
|
|
25
|
-
</template>
|
|
26
|
-
<script lang="ts" setup name="MEditorCodeDraftEditor">
|
|
27
|
-
import { computed, inject, ref, watchEffect } from 'vue';
|
|
28
|
-
import type * as monaco from 'monaco-editor';
|
|
29
|
-
|
|
30
|
-
import { TMagicButton, tMagicMessage, tMagicMessageBox } from '@tmagic/design';
|
|
31
|
-
import { Id } from '@tmagic/schema';
|
|
32
|
-
import { datetimeFormatter } from '@tmagic/utils';
|
|
33
|
-
|
|
34
|
-
import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
|
|
35
|
-
import type { Services } from '@editor/type';
|
|
36
|
-
|
|
37
|
-
const props = withDefaults(
|
|
38
|
-
defineProps<{
|
|
39
|
-
/** 代码id */
|
|
40
|
-
id: Id;
|
|
41
|
-
/** 代码内容 */
|
|
42
|
-
content: string;
|
|
43
|
-
/** 是否可编辑 */
|
|
44
|
-
editable?: boolean;
|
|
45
|
-
/** 是否自动保存草稿 */
|
|
46
|
-
autoSaveDraft?: boolean;
|
|
47
|
-
/** 编辑器参数 */
|
|
48
|
-
codeOptions?: Object;
|
|
49
|
-
/** 编辑器语言 */
|
|
50
|
-
language?: string;
|
|
51
|
-
}>(),
|
|
52
|
-
{
|
|
53
|
-
editable: true,
|
|
54
|
-
autoSaveDraft: true,
|
|
55
|
-
},
|
|
56
|
-
);
|
|
57
|
-
const emit = defineEmits(['close', 'saveAndClose']);
|
|
58
|
-
|
|
59
|
-
const services = inject<Services>('services');
|
|
60
|
-
|
|
61
|
-
const codeContent = ref<string>('');
|
|
62
|
-
const editorContent = ref<string>('');
|
|
63
|
-
const codeEditor = ref<InstanceType<typeof MagicCodeEditor>>();
|
|
64
|
-
// 原始代码内容
|
|
65
|
-
const originCodeContent = ref<string>('');
|
|
66
|
-
const isFullScreen = ref<boolean>(false);
|
|
67
|
-
|
|
68
|
-
const codeOptions = computed(() => ({
|
|
69
|
-
...props.codeOptions,
|
|
70
|
-
readOnly: !props.editable,
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
watchEffect(() => {
|
|
74
|
-
codeContent.value = props.content;
|
|
75
|
-
if (!originCodeContent.value) {
|
|
76
|
-
// 暂存原始的代码内容
|
|
77
|
-
originCodeContent.value = codeContent.value;
|
|
78
|
-
}
|
|
79
|
-
// 有草稿时展示上次保存的草稿内容
|
|
80
|
-
const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
|
|
81
|
-
if (codeDraft) {
|
|
82
|
-
codeContent.value = codeDraft;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// 保存草稿
|
|
87
|
-
const saveCodeDraft = async (codeValue: string) => {
|
|
88
|
-
if (!props.autoSaveDraft) return;
|
|
89
|
-
if (originCodeContent.value === codeValue) {
|
|
90
|
-
// 没修改或改回原样 有草稿的话删除草稿
|
|
91
|
-
services?.codeBlockService.removeCodeDraft(props.id);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
services?.codeBlockService.setCodeDraft(props.id, codeValue);
|
|
95
|
-
tMagicMessage.success(`代码草稿成功保存到本地 ${datetimeFormatter(new Date())}`);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// 保存并关闭
|
|
99
|
-
const saveAndClose = (): void => {
|
|
100
|
-
if (!codeEditor.value || !props.editable) return;
|
|
101
|
-
// 代码内容
|
|
102
|
-
editorContent.value = (codeEditor.value.getEditor() as monaco.editor.IStandaloneCodeEditor)?.getValue();
|
|
103
|
-
emit('saveAndClose', editorContent.value);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// 关闭弹窗
|
|
107
|
-
const close = async (): Promise<void> => {
|
|
108
|
-
const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
|
|
109
|
-
if (codeDraft) {
|
|
110
|
-
try {
|
|
111
|
-
await tMagicMessageBox.confirm('您有代码修改未保存,是否保存后再关闭?', '提示', {
|
|
112
|
-
confirmButtonText: '保存并关闭',
|
|
113
|
-
cancelButtonText: '直接关闭',
|
|
114
|
-
type: 'warning',
|
|
115
|
-
distinguishCancelAndClose: true,
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// 保存之后再关闭
|
|
119
|
-
saveAndClose();
|
|
120
|
-
} catch (action: any) {
|
|
121
|
-
if (action === 'cancel') {
|
|
122
|
-
// 删除草稿 直接关闭
|
|
123
|
-
services?.codeBlockService.removeCodeDraft(props.id);
|
|
124
|
-
emit('close');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
emit('close');
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// 切换全屏
|
|
133
|
-
const toggleFullScreen = (): void => {
|
|
134
|
-
isFullScreen.value = !isFullScreen.value;
|
|
135
|
-
if (codeEditor.value) {
|
|
136
|
-
codeEditor.value.focus();
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
defineExpose({
|
|
141
|
-
saveAndClose,
|
|
142
|
-
close,
|
|
143
|
-
});
|
|
144
|
-
</script>
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<TMagicCard shadow="never">
|
|
3
|
-
<template #header>
|
|
4
|
-
<div class="code-name-wrapper">
|
|
5
|
-
<div class="code-name-label">代码块名称</div>
|
|
6
|
-
<TMagicInput class="code-name-input" v-model="codeName" :disabled="!editable" />
|
|
7
|
-
</div>
|
|
8
|
-
<div class="code-name-wrapper">
|
|
9
|
-
<div class="code-name-label">参数</div>
|
|
10
|
-
<m-form-table
|
|
11
|
-
style="width: 800px"
|
|
12
|
-
:config="tableConfig"
|
|
13
|
-
:model="tableModel"
|
|
14
|
-
:enableToggleMode="false"
|
|
15
|
-
name="params"
|
|
16
|
-
prop="params"
|
|
17
|
-
size="small"
|
|
18
|
-
>
|
|
19
|
-
</m-form-table>
|
|
20
|
-
</div>
|
|
21
|
-
</template>
|
|
22
|
-
<CodeDraftEditor
|
|
23
|
-
ref="codeDraftEditor"
|
|
24
|
-
:id="id"
|
|
25
|
-
:content="codeContent"
|
|
26
|
-
:editable="editable"
|
|
27
|
-
:autoSaveDraft="autoSaveDraft"
|
|
28
|
-
:codeOptions="codeOptions"
|
|
29
|
-
language="javascript"
|
|
30
|
-
@saveAndClose="saveAndClose"
|
|
31
|
-
@close="close"
|
|
32
|
-
></CodeDraftEditor>
|
|
33
|
-
</TMagicCard>
|
|
34
|
-
</template>
|
|
35
|
-
<script lang="ts" setup name="MEditorFunctionEditor">
|
|
36
|
-
import { inject, ref, watchEffect } from 'vue';
|
|
37
|
-
import { cloneDeep } from 'lodash-es';
|
|
38
|
-
|
|
39
|
-
import { TMagicCard, TMagicInput, tMagicMessage } from '@tmagic/design';
|
|
40
|
-
import { ColumnConfig, TableConfig } from '@tmagic/form';
|
|
41
|
-
import { CodeParam, Id } from '@tmagic/schema';
|
|
42
|
-
|
|
43
|
-
import type { Services } from '@editor/type';
|
|
44
|
-
|
|
45
|
-
import CodeDraftEditor from './CodeDraftEditor.vue';
|
|
46
|
-
const defaultParamColConfig: ColumnConfig = {
|
|
47
|
-
type: 'row',
|
|
48
|
-
label: '参数类型',
|
|
49
|
-
items: [
|
|
50
|
-
{
|
|
51
|
-
text: '参数类型',
|
|
52
|
-
labelWidth: '70px',
|
|
53
|
-
type: 'select',
|
|
54
|
-
name: 'type',
|
|
55
|
-
options: [
|
|
56
|
-
{
|
|
57
|
-
text: '数字',
|
|
58
|
-
label: '数字',
|
|
59
|
-
value: 'number',
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
text: '字符串',
|
|
63
|
-
label: '字符串',
|
|
64
|
-
value: 'text',
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const props = withDefaults(
|
|
72
|
-
defineProps<{
|
|
73
|
-
/** 代码块id */
|
|
74
|
-
id: Id;
|
|
75
|
-
/** 代码块名称 */
|
|
76
|
-
name: string;
|
|
77
|
-
/** 代码内容 */
|
|
78
|
-
content: string;
|
|
79
|
-
/** 是否可编辑 */
|
|
80
|
-
editable?: boolean;
|
|
81
|
-
/** 是否自动保存草稿 */
|
|
82
|
-
autoSaveDraft?: boolean;
|
|
83
|
-
/** 编辑器扩展参数 */
|
|
84
|
-
codeOptions?: object;
|
|
85
|
-
/** 代码参数扩展配置 */
|
|
86
|
-
paramsColConfig?: ColumnConfig;
|
|
87
|
-
}>(),
|
|
88
|
-
{
|
|
89
|
-
editable: true,
|
|
90
|
-
autoSaveDraft: true,
|
|
91
|
-
},
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const paramsColConfig = props.paramsColConfig || defaultParamColConfig;
|
|
95
|
-
|
|
96
|
-
const tableConfig: TableConfig = {
|
|
97
|
-
type: 'table',
|
|
98
|
-
border: true,
|
|
99
|
-
enableFullscreen: false,
|
|
100
|
-
name: 'params',
|
|
101
|
-
maxHeight: '300px',
|
|
102
|
-
dropSort: false,
|
|
103
|
-
items: [
|
|
104
|
-
{
|
|
105
|
-
type: 'text',
|
|
106
|
-
label: '参数名',
|
|
107
|
-
name: 'name',
|
|
108
|
-
width: 200,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
type: 'text',
|
|
112
|
-
label: '参数注释',
|
|
113
|
-
name: 'tip',
|
|
114
|
-
width: 200,
|
|
115
|
-
},
|
|
116
|
-
paramsColConfig,
|
|
117
|
-
],
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const services = inject<Services>('services');
|
|
121
|
-
|
|
122
|
-
const codeName = ref<string>('');
|
|
123
|
-
const codeContent = ref<string>('');
|
|
124
|
-
const evalRes = ref(true);
|
|
125
|
-
|
|
126
|
-
const tableModel = ref<{ params: CodeParam[] }>();
|
|
127
|
-
watchEffect(() => {
|
|
128
|
-
codeName.value = props.name;
|
|
129
|
-
codeContent.value = props.content;
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const initTableModel = (): void => {
|
|
133
|
-
const codeDsl = cloneDeep(services?.codeBlockService.getCodeDsl());
|
|
134
|
-
if (!codeDsl) return;
|
|
135
|
-
tableModel.value = {
|
|
136
|
-
params: codeDsl[props.id]?.params || [],
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
initTableModel();
|
|
141
|
-
|
|
142
|
-
// 保存前钩子
|
|
143
|
-
const beforeSave = (codeValue: string): boolean => {
|
|
144
|
-
try {
|
|
145
|
-
// eval检测js代码是否存在语法错误
|
|
146
|
-
// eslint-disable-next-line no-eval
|
|
147
|
-
eval(codeValue);
|
|
148
|
-
return true;
|
|
149
|
-
} catch (e: any) {
|
|
150
|
-
tMagicMessage.error(e.stack);
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// 保存代码
|
|
156
|
-
const saveCode = async (codeValue: string): Promise<void> => {
|
|
157
|
-
if (!props.editable) return;
|
|
158
|
-
evalRes.value = beforeSave(codeValue);
|
|
159
|
-
if (evalRes.value) {
|
|
160
|
-
// 存入dsl
|
|
161
|
-
await services?.codeBlockService.setCodeDslById(props.id, {
|
|
162
|
-
name: codeName.value,
|
|
163
|
-
content: codeValue,
|
|
164
|
-
params: tableModel.value?.params || [],
|
|
165
|
-
});
|
|
166
|
-
tMagicMessage.success('代码成功保存到本地');
|
|
167
|
-
// 删除草稿
|
|
168
|
-
services?.codeBlockService.removeCodeDraft(props.id);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
// 保存并关闭
|
|
173
|
-
const saveAndClose = async (codeValue: string): Promise<void> => {
|
|
174
|
-
await saveCode(codeValue);
|
|
175
|
-
if (evalRes.value) {
|
|
176
|
-
close();
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
// 关闭弹窗
|
|
181
|
-
const close = (): void => {
|
|
182
|
-
services?.codeBlockService.setCodeEditorShowStatus(false);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const codeDraftEditor = ref<InstanceType<typeof CodeDraftEditor>>();
|
|
186
|
-
|
|
187
|
-
defineExpose({
|
|
188
|
-
codeDraftEditor,
|
|
189
|
-
});
|
|
190
|
-
</script>
|
package/src/layouts/Resizer.vue
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<span ref="target" class="m-editor-resizer">
|
|
3
|
-
<slot></slot>
|
|
4
|
-
</span>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script lang="ts" setup name="MEditorResizer">
|
|
8
|
-
import { onMounted, onUnmounted, ref } from 'vue';
|
|
9
|
-
import Gesto from 'gesto';
|
|
10
|
-
|
|
11
|
-
const emit = defineEmits(['change']);
|
|
12
|
-
|
|
13
|
-
const target = ref<HTMLSpanElement>();
|
|
14
|
-
|
|
15
|
-
let getso: Gesto;
|
|
16
|
-
|
|
17
|
-
onMounted(() => {
|
|
18
|
-
if (!target.value) return;
|
|
19
|
-
getso = new Gesto(target.value, {
|
|
20
|
-
container: window,
|
|
21
|
-
pinchOutside: true,
|
|
22
|
-
}).on('drag', (e) => {
|
|
23
|
-
if (!target.value) return;
|
|
24
|
-
|
|
25
|
-
emit('change', e.deltaX);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
onUnmounted(() => {
|
|
30
|
-
getso?.unset();
|
|
31
|
-
});
|
|
32
|
-
</script>
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<TMagicDrawer
|
|
3
|
-
class="code-editor-dialog"
|
|
4
|
-
:model-value="true"
|
|
5
|
-
:title="currentTitle"
|
|
6
|
-
:close-on-press-escape="true"
|
|
7
|
-
:append-to-body="true"
|
|
8
|
-
:show-close="false"
|
|
9
|
-
:close-on-click-modal="true"
|
|
10
|
-
:size="size"
|
|
11
|
-
:before-close="handleClose"
|
|
12
|
-
>
|
|
13
|
-
<Layout v-model:left="left" :min-left="45" class="code-editor-layout">
|
|
14
|
-
<!-- 右侧区域 -->
|
|
15
|
-
<template #center>
|
|
16
|
-
<div v-if="!isEmpty(codeConfig)" class="m-editor-code-block-editor-panel">
|
|
17
|
-
<slot name="code-block-edit-panel-header" :id="id"></slot>
|
|
18
|
-
<FunctionEditor
|
|
19
|
-
ref="functionEditor"
|
|
20
|
-
v-if="codeConfig"
|
|
21
|
-
:id="id"
|
|
22
|
-
:name="codeConfig.name"
|
|
23
|
-
:content="codeConfig.content"
|
|
24
|
-
:paramsColConfig="paramsColConfig"
|
|
25
|
-
:editable="!!editable"
|
|
26
|
-
:autoSaveDraft="true"
|
|
27
|
-
:codeOptions="codeOptions"
|
|
28
|
-
></FunctionEditor>
|
|
29
|
-
</div>
|
|
30
|
-
</template>
|
|
31
|
-
</Layout>
|
|
32
|
-
</TMagicDrawer>
|
|
33
|
-
</template>
|
|
34
|
-
|
|
35
|
-
<script lang="ts" setup name="MEditorCodeBlockEditor">
|
|
36
|
-
import { computed, inject, reactive, ref, watchEffect } from 'vue';
|
|
37
|
-
import { cloneDeep, forIn, isEmpty } from 'lodash-es';
|
|
38
|
-
|
|
39
|
-
import { TMagicDrawer } from '@tmagic/design';
|
|
40
|
-
import { ColumnConfig } from '@tmagic/form';
|
|
41
|
-
import { CodeBlockContent } from '@tmagic/schema';
|
|
42
|
-
|
|
43
|
-
import FunctionEditor from '@editor/components/FunctionEditor.vue';
|
|
44
|
-
import Layout from '@editor/components/Layout.vue';
|
|
45
|
-
import type { ListState, Services } from '@editor/type';
|
|
46
|
-
import { serializeConfig } from '@editor/utils/editor';
|
|
47
|
-
|
|
48
|
-
const services = inject<Services>('services');
|
|
49
|
-
const codeOptions = inject('codeOptions', {});
|
|
50
|
-
|
|
51
|
-
defineProps<{
|
|
52
|
-
paramsColConfig?: ColumnConfig;
|
|
53
|
-
}>();
|
|
54
|
-
|
|
55
|
-
const size = computed(() => globalThis.document.body.clientWidth - (services?.uiService.get('columnWidth').left || 0));
|
|
56
|
-
|
|
57
|
-
const left = ref(200);
|
|
58
|
-
const currentTitle = ref('');
|
|
59
|
-
// 编辑器当前需展示的代码块内容
|
|
60
|
-
const codeConfig = ref<CodeBlockContent | null>(null);
|
|
61
|
-
// select选择的内容(ListState)
|
|
62
|
-
const state = reactive<ListState>({
|
|
63
|
-
codeList: [],
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const id = computed(() => services?.codeBlockService.getId() || '');
|
|
67
|
-
const editable = computed(() => services?.codeBlockService.getEditStatus());
|
|
68
|
-
// 当前选中组件绑定的代码块id数组
|
|
69
|
-
const selectedIds = computed(() => services?.codeBlockService.getCombineIds() || []);
|
|
70
|
-
|
|
71
|
-
watchEffect(async () => {
|
|
72
|
-
codeConfig.value = cloneDeep(await services?.codeBlockService.getCodeContentById(id.value)) || null;
|
|
73
|
-
if (!codeConfig.value) return;
|
|
74
|
-
codeConfig.value.content = serializeConfig(codeConfig.value.content);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
watchEffect(async () => {
|
|
78
|
-
const codeDsl = (await services?.codeBlockService.getCodeDslByIds(selectedIds.value)) || null;
|
|
79
|
-
if (!codeDsl) return;
|
|
80
|
-
state.codeList = [];
|
|
81
|
-
forIn(codeDsl, (value: CodeBlockContent, key: string) => {
|
|
82
|
-
state.codeList.push({
|
|
83
|
-
id: key,
|
|
84
|
-
name: value.name,
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
currentTitle.value = state.codeList[0]?.name || '';
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const functionEditor = ref<InstanceType<typeof FunctionEditor>>();
|
|
91
|
-
|
|
92
|
-
const handleClose = async () => {
|
|
93
|
-
// 触发codeDraftEditor组件关闭事件
|
|
94
|
-
await functionEditor.value?.codeDraftEditor?.close();
|
|
95
|
-
};
|
|
96
|
-
</script>
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Id } from '@tmagic/schema';
|
|
2
|
-
declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
3
|
-
/** 代码id */
|
|
4
|
-
id: Id;
|
|
5
|
-
/** 代码内容 */
|
|
6
|
-
content: string;
|
|
7
|
-
/** 是否可编辑 */
|
|
8
|
-
editable?: boolean | undefined;
|
|
9
|
-
/** 是否自动保存草稿 */
|
|
10
|
-
autoSaveDraft?: boolean | undefined;
|
|
11
|
-
/** 编辑器参数 */
|
|
12
|
-
codeOptions?: Object | undefined;
|
|
13
|
-
/** 编辑器语言 */
|
|
14
|
-
language?: string | undefined;
|
|
15
|
-
}>, {
|
|
16
|
-
editable: boolean;
|
|
17
|
-
autoSaveDraft: boolean;
|
|
18
|
-
}>, {
|
|
19
|
-
saveAndClose: () => void;
|
|
20
|
-
close: () => Promise<void>;
|
|
21
|
-
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("close" | "saveAndClose")[], "close" | "saveAndClose", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
22
|
-
/** 代码id */
|
|
23
|
-
id: Id;
|
|
24
|
-
/** 代码内容 */
|
|
25
|
-
content: string;
|
|
26
|
-
/** 是否可编辑 */
|
|
27
|
-
editable?: boolean | undefined;
|
|
28
|
-
/** 是否自动保存草稿 */
|
|
29
|
-
autoSaveDraft?: boolean | undefined;
|
|
30
|
-
/** 编辑器参数 */
|
|
31
|
-
codeOptions?: Object | undefined;
|
|
32
|
-
/** 编辑器语言 */
|
|
33
|
-
language?: string | undefined;
|
|
34
|
-
}>, {
|
|
35
|
-
editable: boolean;
|
|
36
|
-
autoSaveDraft: boolean;
|
|
37
|
-
}>>> & {
|
|
38
|
-
onClose?: ((...args: any[]) => any) | undefined;
|
|
39
|
-
onSaveAndClose?: ((...args: any[]) => any) | undefined;
|
|
40
|
-
}, {
|
|
41
|
-
editable: boolean;
|
|
42
|
-
autoSaveDraft: boolean;
|
|
43
|
-
}>;
|
|
44
|
-
export default _default;
|
|
45
|
-
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
46
|
-
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
47
|
-
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
48
|
-
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
49
|
-
} : {
|
|
50
|
-
type: import('vue').PropType<T[K]>;
|
|
51
|
-
required: true;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
type __VLS_WithDefaults<P, D> = {
|
|
55
|
-
[K in keyof Pick<P, keyof P>]: K extends keyof D ? P[K] & {
|
|
56
|
-
default: D[K];
|
|
57
|
-
} : P[K];
|
|
58
|
-
};
|