@tmagic/editor 1.3.0-alpha.13 → 1.3.0-alpha.14
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 +41 -113
- package/dist/tmagic-editor.js +1307 -1197
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +1318 -1204
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +11 -11
- package/src/Editor.vue +0 -4
- package/src/components/CodeBlockEditor.vue +155 -0
- package/src/components/CodeParams.vue +59 -0
- package/src/fields/Code.vue +27 -19
- package/src/fields/CodeSelect.vue +7 -1
- package/src/fields/CodeSelectCol.vue +65 -74
- package/src/fields/DataSourceFields.vue +7 -9
- package/src/fields/DataSourceMethodSelect.vue +147 -0
- package/src/fields/DataSourceMethods.vue +103 -0
- package/src/fields/EventSelect.vue +33 -7
- package/src/icons/CodeIcon.vue +0 -2
- package/src/index.ts +8 -0
- package/src/layouts/CodeEditor.vue +32 -1
- package/src/layouts/Framework.vue +7 -3
- package/src/layouts/sidebar/Sidebar.vue +2 -10
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +73 -124
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +64 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +23 -33
- package/src/layouts/sidebar/data-source/DataSourceList.vue +111 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +13 -81
- package/src/services/codeBlock.ts +17 -70
- package/src/services/dataSource.ts +2 -0
- package/src/theme/code-block.scss +0 -122
- package/src/theme/code-editor.scss +27 -2
- package/src/theme/data-source-methods.scss +13 -0
- package/src/theme/event.scss +15 -12
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +21 -6
- package/src/utils/data-source/index.ts +11 -0
- package/src/utils/use-code-block-edit.ts +84 -0
- package/src/utils/use-data-source-method.ts +101 -0
- package/types/components/CodeBlockEditor.vue.d.ts +21 -0
- package/types/components/CodeParams.vue.d.ts +26 -0
- package/types/components/ContentMenu.vue.d.ts +2 -2
- package/types/fields/Code.vue.d.ts +26 -6
- package/types/fields/CodeSelectCol.vue.d.ts +16 -5
- package/types/fields/DataSourceFields.vue.d.ts +2 -0
- package/types/fields/DataSourceMethodSelect.vue.d.ts +44 -0
- package/types/fields/DataSourceMethods.vue.d.ts +45 -0
- package/types/index.d.ts +4 -0
- package/types/layouts/CodeEditor.vue.d.ts +2 -0
- package/types/layouts/PropsPanel.vue.d.ts +8 -8
- package/types/layouts/sidebar/Sidebar.vue.d.ts +0 -3
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +4 -9
- package/types/layouts/sidebar/code-block/{CodeBlockEditor.vue.d.ts → CodeBlockListPanel.vue.d.ts} +5 -6
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -1
- 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/services/codeBlock.d.ts +5 -36
- package/types/services/dataSource.d.ts +1 -0
- package/types/type.d.ts +19 -6
- package/types/{components/FunctionEditor.vue.d.ts → utils/use-code-block-edit.d.ts} +26 -123
- package/types/utils/use-data-source-method.d.ts +116 -0
- package/src/components/CodeDraftEditor.vue +0 -148
- package/src/components/FunctionEditor.vue +0 -197
- package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -100
- package/types/components/CodeDraftEditor.vue.d.ts +0 -61
|
@@ -1,197 +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>
|
|
36
|
-
import { inject, provide, 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
|
-
import { getConfig } from '@editor/utils/config';
|
|
45
|
-
|
|
46
|
-
import CodeDraftEditor from './CodeDraftEditor.vue';
|
|
47
|
-
|
|
48
|
-
defineOptions({
|
|
49
|
-
name: 'MEditorFunctionEditor',
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
provide('mForm', null);
|
|
53
|
-
|
|
54
|
-
const defaultParamColConfig: ColumnConfig = {
|
|
55
|
-
type: 'row',
|
|
56
|
-
label: '参数类型',
|
|
57
|
-
items: [
|
|
58
|
-
{
|
|
59
|
-
text: '参数类型',
|
|
60
|
-
labelWidth: '70px',
|
|
61
|
-
type: 'select',
|
|
62
|
-
name: 'type',
|
|
63
|
-
options: [
|
|
64
|
-
{
|
|
65
|
-
text: '数字',
|
|
66
|
-
label: '数字',
|
|
67
|
-
value: 'number',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
text: '字符串',
|
|
71
|
-
label: '字符串',
|
|
72
|
-
value: 'text',
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const props = withDefaults(
|
|
80
|
-
defineProps<{
|
|
81
|
-
/** 代码块id */
|
|
82
|
-
id: Id;
|
|
83
|
-
/** 代码块名称 */
|
|
84
|
-
name: string;
|
|
85
|
-
/** 代码内容 */
|
|
86
|
-
content: string;
|
|
87
|
-
/** 是否可编辑 */
|
|
88
|
-
editable?: boolean;
|
|
89
|
-
/** 是否自动保存草稿 */
|
|
90
|
-
autoSaveDraft?: boolean;
|
|
91
|
-
/** 编辑器扩展参数 */
|
|
92
|
-
codeOptions?: object;
|
|
93
|
-
/** 代码参数扩展配置 */
|
|
94
|
-
paramsColConfig?: ColumnConfig;
|
|
95
|
-
}>(),
|
|
96
|
-
{
|
|
97
|
-
editable: true,
|
|
98
|
-
autoSaveDraft: true,
|
|
99
|
-
},
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
const paramsColConfig = props.paramsColConfig || defaultParamColConfig;
|
|
103
|
-
|
|
104
|
-
const tableConfig: TableConfig = {
|
|
105
|
-
type: 'table',
|
|
106
|
-
border: true,
|
|
107
|
-
enableFullscreen: false,
|
|
108
|
-
name: 'params',
|
|
109
|
-
maxHeight: '300px',
|
|
110
|
-
dropSort: false,
|
|
111
|
-
items: [
|
|
112
|
-
{
|
|
113
|
-
type: 'text',
|
|
114
|
-
label: '参数名',
|
|
115
|
-
name: 'name',
|
|
116
|
-
width: 200,
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
type: 'text',
|
|
120
|
-
label: '参数注释',
|
|
121
|
-
name: 'tip',
|
|
122
|
-
width: 200,
|
|
123
|
-
},
|
|
124
|
-
paramsColConfig,
|
|
125
|
-
],
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const services = inject<Services>('services');
|
|
129
|
-
|
|
130
|
-
const codeName = ref<string>('');
|
|
131
|
-
const codeContent = ref<string>('');
|
|
132
|
-
const evalRes = ref(true);
|
|
133
|
-
|
|
134
|
-
const tableModel = ref<{ params: CodeParam[] }>();
|
|
135
|
-
watchEffect(() => {
|
|
136
|
-
codeName.value = props.name;
|
|
137
|
-
codeContent.value = props.content;
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
const initTableModel = (): void => {
|
|
141
|
-
const codeDsl = cloneDeep(services?.codeBlockService.getCodeDsl());
|
|
142
|
-
if (!codeDsl) return;
|
|
143
|
-
tableModel.value = {
|
|
144
|
-
params: codeDsl[props.id]?.params || [],
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
initTableModel();
|
|
149
|
-
|
|
150
|
-
// 保存前钩子
|
|
151
|
-
const beforeSave = (codeValue: string): boolean => {
|
|
152
|
-
try {
|
|
153
|
-
// 检测js代码是否存在语法错误
|
|
154
|
-
getConfig('parseDSL')(codeValue);
|
|
155
|
-
return true;
|
|
156
|
-
} catch (e: any) {
|
|
157
|
-
tMagicMessage.error(e.stack);
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// 保存代码
|
|
163
|
-
const saveCode = async (codeValue: string): Promise<void> => {
|
|
164
|
-
if (!props.editable) return;
|
|
165
|
-
evalRes.value = beforeSave(codeValue);
|
|
166
|
-
if (evalRes.value) {
|
|
167
|
-
// 存入dsl
|
|
168
|
-
await services?.codeBlockService.setCodeDslById(props.id, {
|
|
169
|
-
name: codeName.value,
|
|
170
|
-
content: codeValue,
|
|
171
|
-
params: tableModel.value?.params || [],
|
|
172
|
-
});
|
|
173
|
-
tMagicMessage.success('代码成功保存到本地');
|
|
174
|
-
// 删除草稿
|
|
175
|
-
services?.codeBlockService.removeCodeDraft(props.id);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// 保存并关闭
|
|
180
|
-
const saveAndClose = async (codeValue: string): Promise<void> => {
|
|
181
|
-
await saveCode(codeValue);
|
|
182
|
-
if (evalRes.value) {
|
|
183
|
-
close();
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
// 关闭弹窗
|
|
188
|
-
const close = (): void => {
|
|
189
|
-
services?.codeBlockService.setCodeEditorShowStatus(false);
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const codeDraftEditor = ref<InstanceType<typeof CodeDraftEditor>>();
|
|
193
|
-
|
|
194
|
-
defineExpose({
|
|
195
|
-
codeDraftEditor,
|
|
196
|
-
});
|
|
197
|
-
</script>
|
|
@@ -1,100 +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
|
-
<SplitView 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
|
-
</SplitView>
|
|
32
|
-
</TMagicDrawer>
|
|
33
|
-
</template>
|
|
34
|
-
|
|
35
|
-
<script lang="ts" setup>
|
|
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 SplitView from '@editor/components/SplitView.vue';
|
|
45
|
-
import type { ListState, Services } from '@editor/type';
|
|
46
|
-
import { serializeConfig } from '@editor/utils/editor';
|
|
47
|
-
|
|
48
|
-
defineOptions({
|
|
49
|
-
name: 'MEditorCodeBlockEditor',
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const services = inject<Services>('services');
|
|
53
|
-
const codeOptions = inject('codeOptions', {});
|
|
54
|
-
|
|
55
|
-
defineProps<{
|
|
56
|
-
paramsColConfig?: ColumnConfig;
|
|
57
|
-
}>();
|
|
58
|
-
|
|
59
|
-
const size = computed(() => globalThis.document.body.clientWidth - (services?.uiService.get('columnWidth').left || 0));
|
|
60
|
-
|
|
61
|
-
const left = ref(200);
|
|
62
|
-
const currentTitle = ref('');
|
|
63
|
-
// 编辑器当前需展示的代码块内容
|
|
64
|
-
const codeConfig = ref<CodeBlockContent | null>(null);
|
|
65
|
-
// select选择的内容(ListState)
|
|
66
|
-
const state = reactive<ListState>({
|
|
67
|
-
codeList: [],
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const id = computed(() => services?.codeBlockService.getId() || '');
|
|
71
|
-
const editable = computed(() => services?.codeBlockService.getEditStatus());
|
|
72
|
-
// 当前选中组件绑定的代码块id数组
|
|
73
|
-
const selectedIds = computed(() => services?.codeBlockService.getCombineIds() || []);
|
|
74
|
-
|
|
75
|
-
watchEffect(async () => {
|
|
76
|
-
codeConfig.value = cloneDeep(await services?.codeBlockService.getCodeContentById(id.value)) || null;
|
|
77
|
-
if (!codeConfig.value) return;
|
|
78
|
-
codeConfig.value.content = serializeConfig(codeConfig.value.content);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
watchEffect(async () => {
|
|
82
|
-
const codeDsl = (await services?.codeBlockService.getCodeDslByIds(selectedIds.value)) || null;
|
|
83
|
-
if (!codeDsl) return;
|
|
84
|
-
state.codeList = [];
|
|
85
|
-
forIn(codeDsl, (value: CodeBlockContent, key: string) => {
|
|
86
|
-
state.codeList.push({
|
|
87
|
-
id: key,
|
|
88
|
-
name: value.name,
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
currentTitle.value = state.codeList[0]?.name || '';
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
const functionEditor = ref<InstanceType<typeof FunctionEditor>>();
|
|
95
|
-
|
|
96
|
-
const handleClose = async () => {
|
|
97
|
-
// 触发codeDraftEditor组件关闭事件
|
|
98
|
-
await functionEditor.value?.codeDraftEditor?.close();
|
|
99
|
-
};
|
|
100
|
-
</script>
|
|
@@ -1,61 +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 ? __VLS_Prettify<P[K] & {
|
|
56
|
-
default: D[K];
|
|
57
|
-
}> : P[K];
|
|
58
|
-
};
|
|
59
|
-
type __VLS_Prettify<T> = {
|
|
60
|
-
[K in keyof T]: T[K];
|
|
61
|
-
} & {};
|