@tmagic/editor 1.3.0-alpha.12 → 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 +1346 -1195
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +1357 -1202
- 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/fields/UISelect.vue +37 -6
- 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 +79 -117
- 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 +18 -71
- 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 +6 -37
- 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,30 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** 代码内容 */
|
|
9
|
-
content: string;
|
|
10
|
-
/** 是否可编辑 */
|
|
11
|
-
editable?: boolean | undefined;
|
|
12
|
-
/** 是否自动保存草稿 */
|
|
13
|
-
autoSaveDraft?: boolean | undefined;
|
|
14
|
-
/** 编辑器扩展参数 */
|
|
15
|
-
codeOptions?: object | undefined;
|
|
16
|
-
/** 代码参数扩展配置 */
|
|
17
|
-
paramsColConfig?: ColumnConfig | undefined;
|
|
18
|
-
}>, {
|
|
19
|
-
editable: boolean;
|
|
20
|
-
autoSaveDraft: boolean;
|
|
21
|
-
}>, {
|
|
22
|
-
codeDraftEditor: import("vue").Ref<({
|
|
1
|
+
import { nextTick } from 'vue';
|
|
2
|
+
import type { CodeBlockContent } from '@tmagic/schema';
|
|
3
|
+
import type { CodeBlockService } from '../services/codeBlock';
|
|
4
|
+
export declare const useCodeBlockEdit: (codeBlockService?: CodeBlockService) => {
|
|
5
|
+
codeId: import("vue").Ref<string | undefined>;
|
|
6
|
+
codeConfig: import("vue").Ref<CodeBlockContent | undefined>;
|
|
7
|
+
codeBlockEditor: import("vue").Ref<({
|
|
23
8
|
$: import("vue").ComponentInternalInstance;
|
|
24
9
|
$data: {};
|
|
25
10
|
$props: {
|
|
26
|
-
editable?: boolean | undefined;
|
|
27
|
-
autoSaveDraft?: boolean | undefined;
|
|
28
11
|
key?: string | number | symbol | undefined;
|
|
29
12
|
ref?: import("vue").VNodeRef | undefined;
|
|
30
13
|
ref_for?: boolean | undefined;
|
|
@@ -69,12 +52,8 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
69
52
|
}>) => void)[] | undefined;
|
|
70
53
|
class?: unknown;
|
|
71
54
|
style?: unknown;
|
|
72
|
-
readonly
|
|
73
|
-
readonly
|
|
74
|
-
readonly codeOptions?: Object | undefined;
|
|
75
|
-
readonly content: string;
|
|
76
|
-
onClose?: ((...args: any[]) => any) | undefined;
|
|
77
|
-
onSaveAndClose?: ((...args: any[]) => any) | undefined;
|
|
55
|
+
readonly content: CodeBlockContent;
|
|
56
|
+
readonly disabled?: boolean | undefined;
|
|
78
57
|
};
|
|
79
58
|
$attrs: {
|
|
80
59
|
[x: string]: unknown;
|
|
@@ -87,42 +66,20 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
87
66
|
}>;
|
|
88
67
|
$root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null;
|
|
89
68
|
$parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null;
|
|
90
|
-
$emit: (event:
|
|
69
|
+
$emit: (event: string, ...args: any[]) => void;
|
|
91
70
|
$el: any;
|
|
92
71
|
$options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
|
|
93
|
-
id: {
|
|
94
|
-
type: import("vue").PropType<Id>;
|
|
95
|
-
required: true;
|
|
96
|
-
};
|
|
97
|
-
editable: {
|
|
98
|
-
type: import("vue").PropType<boolean>;
|
|
99
|
-
default: boolean;
|
|
100
|
-
};
|
|
101
|
-
language: {
|
|
102
|
-
type: import("vue").PropType<string>;
|
|
103
|
-
};
|
|
104
|
-
codeOptions: {
|
|
105
|
-
type: import("vue").PropType<Object>;
|
|
106
|
-
};
|
|
107
72
|
content: {
|
|
108
|
-
type: import("vue").PropType<
|
|
73
|
+
type: import("vue").PropType<CodeBlockContent>;
|
|
109
74
|
required: true;
|
|
110
75
|
};
|
|
111
|
-
|
|
76
|
+
disabled: {
|
|
112
77
|
type: import("vue").PropType<boolean>;
|
|
113
|
-
default: boolean;
|
|
114
78
|
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}, {
|
|
119
|
-
/** 代码块id */
|
|
120
|
-
saveAndClose: () => void;
|
|
121
|
-
close: () => Promise<void>;
|
|
122
|
-
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("close" | "saveAndClose")[], string, {
|
|
123
|
-
editable: boolean;
|
|
124
|
-
autoSaveDraft: boolean;
|
|
125
|
-
}, {}, string, {}> & {
|
|
79
|
+
}>>, {
|
|
80
|
+
show(): void;
|
|
81
|
+
hide(): void;
|
|
82
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, {}, {}, string, {}> & {
|
|
126
83
|
beforeCreate?: ((() => void) | (() => void)[]) | undefined;
|
|
127
84
|
created?: ((() => void) | (() => void)[]) | undefined;
|
|
128
85
|
beforeMount?: ((() => void) | (() => void)[]) | undefined;
|
|
@@ -140,76 +97,22 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
140
97
|
errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null, info: string) => boolean | void)[]) | undefined;
|
|
141
98
|
};
|
|
142
99
|
$forceUpdate: () => void;
|
|
143
|
-
$nextTick: typeof
|
|
100
|
+
$nextTick: typeof nextTick;
|
|
144
101
|
$watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R) => any : (...args: any) => any, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
|
|
145
102
|
} & Readonly<import("vue").ExtractPropTypes<{
|
|
146
|
-
id: {
|
|
147
|
-
type: import("vue").PropType<Id>;
|
|
148
|
-
required: true;
|
|
149
|
-
};
|
|
150
|
-
editable: {
|
|
151
|
-
type: import("vue").PropType<boolean>;
|
|
152
|
-
default: boolean;
|
|
153
|
-
};
|
|
154
|
-
language: {
|
|
155
|
-
type: import("vue").PropType<string>;
|
|
156
|
-
};
|
|
157
|
-
codeOptions: {
|
|
158
|
-
type: import("vue").PropType<Object>;
|
|
159
|
-
};
|
|
160
103
|
content: {
|
|
161
|
-
type: import("vue").PropType<
|
|
104
|
+
type: import("vue").PropType<CodeBlockContent>;
|
|
162
105
|
required: true;
|
|
163
106
|
};
|
|
164
|
-
|
|
107
|
+
disabled: {
|
|
165
108
|
type: import("vue").PropType<boolean>;
|
|
166
|
-
default: boolean;
|
|
167
109
|
};
|
|
168
|
-
}>> & {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
} & import("vue").ShallowUnwrapRef<{
|
|
172
|
-
/** 代码块id */
|
|
173
|
-
saveAndClose: () => void;
|
|
174
|
-
close: () => Promise<void>;
|
|
110
|
+
}>> & import("vue").ShallowUnwrapRef<{
|
|
111
|
+
show(): void;
|
|
112
|
+
hide(): void;
|
|
175
113
|
}> & {} & import("vue").ComponentCustomProperties & {}) | undefined>;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
name: string;
|
|
181
|
-
/** 代码内容 */
|
|
182
|
-
content: string;
|
|
183
|
-
/** 是否可编辑 */
|
|
184
|
-
editable?: boolean | undefined;
|
|
185
|
-
/** 是否自动保存草稿 */
|
|
186
|
-
autoSaveDraft?: boolean | undefined;
|
|
187
|
-
/** 编辑器扩展参数 */
|
|
188
|
-
codeOptions?: object | undefined;
|
|
189
|
-
/** 代码参数扩展配置 */
|
|
190
|
-
paramsColConfig?: ColumnConfig | undefined;
|
|
191
|
-
}>, {
|
|
192
|
-
editable: boolean;
|
|
193
|
-
autoSaveDraft: boolean;
|
|
194
|
-
}>>>, {
|
|
195
|
-
editable: boolean;
|
|
196
|
-
autoSaveDraft: boolean;
|
|
197
|
-
}, {}>;
|
|
198
|
-
export default _default;
|
|
199
|
-
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
200
|
-
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
201
|
-
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
202
|
-
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
203
|
-
} : {
|
|
204
|
-
type: import('vue').PropType<T[K]>;
|
|
205
|
-
required: true;
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
type __VLS_WithDefaults<P, D> = {
|
|
209
|
-
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
210
|
-
default: D[K];
|
|
211
|
-
}> : P[K];
|
|
114
|
+
createCodeBlock: () => Promise<void>;
|
|
115
|
+
editCode: (id: string) => Promise<void>;
|
|
116
|
+
deleteCode: (key: string) => Promise<void>;
|
|
117
|
+
submitCodeBlockHandler: (values: CodeBlockContent) => Promise<void>;
|
|
212
118
|
};
|
|
213
|
-
type __VLS_Prettify<T> = {
|
|
214
|
-
[K in keyof T]: T[K];
|
|
215
|
-
} & {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { nextTick } from 'vue';
|
|
2
|
+
import type { CodeBlockContent, DataSourceSchema } from '@tmagic/schema';
|
|
3
|
+
export declare const useDataSourceMethod: () => {
|
|
4
|
+
codeConfig: import("vue").Ref<CodeBlockContent | undefined>;
|
|
5
|
+
codeBlockEditor: import("vue").Ref<({
|
|
6
|
+
$: import("vue").ComponentInternalInstance;
|
|
7
|
+
$data: {};
|
|
8
|
+
$props: {
|
|
9
|
+
key?: string | number | symbol | undefined;
|
|
10
|
+
ref?: import("vue").VNodeRef | undefined;
|
|
11
|
+
ref_for?: boolean | undefined;
|
|
12
|
+
ref_key?: string | undefined;
|
|
13
|
+
onVnodeBeforeMount?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}>) => void)[] | undefined;
|
|
18
|
+
onVnodeMounted?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}>) => void)[] | undefined;
|
|
23
|
+
onVnodeBeforeUpdate?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}>, oldVNode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}>, oldVNode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}>) => void)[] | undefined;
|
|
32
|
+
onVnodeUpdated?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}>, oldVNode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}>, oldVNode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}>) => void)[] | undefined;
|
|
41
|
+
onVnodeBeforeUnmount?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
}>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
44
|
+
[key: string]: any;
|
|
45
|
+
}>) => void)[] | undefined;
|
|
46
|
+
onVnodeUnmounted?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
}>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
}>) => void)[] | undefined;
|
|
51
|
+
class?: unknown;
|
|
52
|
+
style?: unknown;
|
|
53
|
+
readonly content: CodeBlockContent;
|
|
54
|
+
readonly disabled?: boolean | undefined;
|
|
55
|
+
};
|
|
56
|
+
$attrs: {
|
|
57
|
+
[x: string]: unknown;
|
|
58
|
+
};
|
|
59
|
+
$refs: {
|
|
60
|
+
[x: string]: unknown;
|
|
61
|
+
};
|
|
62
|
+
$slots: Readonly<{
|
|
63
|
+
[name: string]: import("vue").Slot<any> | undefined;
|
|
64
|
+
}>;
|
|
65
|
+
$root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null;
|
|
66
|
+
$parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null;
|
|
67
|
+
$emit: (event: string, ...args: any[]) => void;
|
|
68
|
+
$el: any;
|
|
69
|
+
$options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
|
|
70
|
+
content: {
|
|
71
|
+
type: import("vue").PropType<CodeBlockContent>;
|
|
72
|
+
required: true;
|
|
73
|
+
};
|
|
74
|
+
disabled: {
|
|
75
|
+
type: import("vue").PropType<boolean>;
|
|
76
|
+
};
|
|
77
|
+
}>>, {
|
|
78
|
+
show(): void;
|
|
79
|
+
hide(): void;
|
|
80
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, {}, {}, string, {}> & {
|
|
81
|
+
beforeCreate?: ((() => void) | (() => void)[]) | undefined;
|
|
82
|
+
created?: ((() => void) | (() => void)[]) | undefined;
|
|
83
|
+
beforeMount?: ((() => void) | (() => void)[]) | undefined;
|
|
84
|
+
mounted?: ((() => void) | (() => void)[]) | undefined;
|
|
85
|
+
beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
|
|
86
|
+
updated?: ((() => void) | (() => void)[]) | undefined;
|
|
87
|
+
activated?: ((() => void) | (() => void)[]) | undefined;
|
|
88
|
+
deactivated?: ((() => void) | (() => void)[]) | undefined;
|
|
89
|
+
beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
|
|
90
|
+
beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
|
|
91
|
+
destroyed?: ((() => void) | (() => void)[]) | undefined;
|
|
92
|
+
unmounted?: ((() => void) | (() => void)[]) | undefined;
|
|
93
|
+
renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
|
|
94
|
+
renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
|
|
95
|
+
errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}>, {}, {}> | null, info: string) => boolean | void)[]) | undefined;
|
|
96
|
+
};
|
|
97
|
+
$forceUpdate: () => void;
|
|
98
|
+
$nextTick: typeof nextTick;
|
|
99
|
+
$watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R) => any : (...args: any) => any, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
|
|
100
|
+
} & Readonly<import("vue").ExtractPropTypes<{
|
|
101
|
+
content: {
|
|
102
|
+
type: import("vue").PropType<CodeBlockContent>;
|
|
103
|
+
required: true;
|
|
104
|
+
};
|
|
105
|
+
disabled: {
|
|
106
|
+
type: import("vue").PropType<boolean>;
|
|
107
|
+
};
|
|
108
|
+
}>> & import("vue").ShallowUnwrapRef<{
|
|
109
|
+
show(): void;
|
|
110
|
+
hide(): void;
|
|
111
|
+
}> & {} & import("vue").ComponentCustomProperties & {}) | undefined>;
|
|
112
|
+
createCode: (model: DataSourceSchema) => Promise<void>;
|
|
113
|
+
editCode: (model: DataSourceSchema, methodName: string) => Promise<void>;
|
|
114
|
+
deleteCode: (model: DataSourceSchema, methodName: string) => Promise<void>;
|
|
115
|
+
submitCode: (values: CodeBlockContent) => void;
|
|
116
|
+
};
|
|
@@ -1,148 +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>
|
|
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
|
-
defineOptions({
|
|
38
|
-
name: 'MEditorCodeDraftEditor',
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const props = withDefaults(
|
|
42
|
-
defineProps<{
|
|
43
|
-
/** 代码id */
|
|
44
|
-
id: Id;
|
|
45
|
-
/** 代码内容 */
|
|
46
|
-
content: string;
|
|
47
|
-
/** 是否可编辑 */
|
|
48
|
-
editable?: boolean;
|
|
49
|
-
/** 是否自动保存草稿 */
|
|
50
|
-
autoSaveDraft?: boolean;
|
|
51
|
-
/** 编辑器参数 */
|
|
52
|
-
codeOptions?: Object;
|
|
53
|
-
/** 编辑器语言 */
|
|
54
|
-
language?: string;
|
|
55
|
-
}>(),
|
|
56
|
-
{
|
|
57
|
-
editable: true,
|
|
58
|
-
autoSaveDraft: true,
|
|
59
|
-
},
|
|
60
|
-
);
|
|
61
|
-
const emit = defineEmits(['close', 'saveAndClose']);
|
|
62
|
-
|
|
63
|
-
const services = inject<Services>('services');
|
|
64
|
-
|
|
65
|
-
const codeContent = ref<string>('');
|
|
66
|
-
const editorContent = ref<string>('');
|
|
67
|
-
const codeEditor = ref<InstanceType<typeof MagicCodeEditor>>();
|
|
68
|
-
// 原始代码内容
|
|
69
|
-
const originCodeContent = ref<string>('');
|
|
70
|
-
const isFullScreen = ref<boolean>(false);
|
|
71
|
-
|
|
72
|
-
const codeOptions = computed(() => ({
|
|
73
|
-
...props.codeOptions,
|
|
74
|
-
readOnly: !props.editable,
|
|
75
|
-
}));
|
|
76
|
-
|
|
77
|
-
watchEffect(() => {
|
|
78
|
-
codeContent.value = props.content;
|
|
79
|
-
if (!originCodeContent.value) {
|
|
80
|
-
// 暂存原始的代码内容
|
|
81
|
-
originCodeContent.value = codeContent.value;
|
|
82
|
-
}
|
|
83
|
-
// 有草稿时展示上次保存的草稿内容
|
|
84
|
-
const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
|
|
85
|
-
if (codeDraft) {
|
|
86
|
-
codeContent.value = codeDraft;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// 保存草稿
|
|
91
|
-
const saveCodeDraft = async (codeValue: string) => {
|
|
92
|
-
if (!props.autoSaveDraft) return;
|
|
93
|
-
if (originCodeContent.value === codeValue) {
|
|
94
|
-
// 没修改或改回原样 有草稿的话删除草稿
|
|
95
|
-
services?.codeBlockService.removeCodeDraft(props.id);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
services?.codeBlockService.setCodeDraft(props.id, codeValue);
|
|
99
|
-
tMagicMessage.success(`代码草稿成功保存到本地 ${datetimeFormatter(new Date())}`);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// 保存并关闭
|
|
103
|
-
const saveAndClose = (): void => {
|
|
104
|
-
if (!codeEditor.value || !props.editable) return;
|
|
105
|
-
// 代码内容
|
|
106
|
-
editorContent.value = (codeEditor.value.getEditor() as monaco.editor.IStandaloneCodeEditor)?.getValue();
|
|
107
|
-
emit('saveAndClose', editorContent.value);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// 关闭弹窗
|
|
111
|
-
const close = async (): Promise<void> => {
|
|
112
|
-
const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
|
|
113
|
-
if (codeDraft) {
|
|
114
|
-
try {
|
|
115
|
-
await tMagicMessageBox.confirm('您有代码修改未保存,是否保存后再关闭?', '提示', {
|
|
116
|
-
confirmButtonText: '保存并关闭',
|
|
117
|
-
cancelButtonText: '直接关闭',
|
|
118
|
-
type: 'warning',
|
|
119
|
-
distinguishCancelAndClose: true,
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// 保存之后再关闭
|
|
123
|
-
saveAndClose();
|
|
124
|
-
} catch (action: any) {
|
|
125
|
-
if (action === 'cancel') {
|
|
126
|
-
// 删除草稿 直接关闭
|
|
127
|
-
services?.codeBlockService.removeCodeDraft(props.id);
|
|
128
|
-
emit('close');
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
} else {
|
|
132
|
-
emit('close');
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// 切换全屏
|
|
137
|
-
const toggleFullScreen = (): void => {
|
|
138
|
-
isFullScreen.value = !isFullScreen.value;
|
|
139
|
-
if (codeEditor.value) {
|
|
140
|
-
codeEditor.value.focus();
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
defineExpose({
|
|
145
|
-
saveAndClose,
|
|
146
|
-
close,
|
|
147
|
-
});
|
|
148
|
-
</script>
|
|
@@ -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>
|