@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
package/types/type.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Component } from 'vue';
|
|
2
|
-
import type { FormConfig, FormItem } from '@tmagic/form';
|
|
2
|
+
import type { ColumnConfig, FilterFunction, FormConfig, FormItem } from '@tmagic/form';
|
|
3
3
|
import type { CodeBlockContent, CodeBlockDSL, Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
|
|
4
4
|
import type StageCore from '@tmagic/stage';
|
|
5
5
|
import type { ContainerHighlightType, CustomizeMoveableOptionsCallbackConfig, MoveableOptions, UpdateDragEl } from '@tmagic/stage';
|
|
@@ -18,7 +18,7 @@ import type { UndoRedo } from './utils/undo-redo';
|
|
|
18
18
|
export type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> | MNode;
|
|
19
19
|
export type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
|
|
20
20
|
export interface InstallOptions {
|
|
21
|
-
parseDSL: (dsl: string) =>
|
|
21
|
+
parseDSL: <T = any>(dsl: string) => T;
|
|
22
22
|
[key: string]: any;
|
|
23
23
|
}
|
|
24
24
|
export interface Services {
|
|
@@ -263,18 +263,15 @@ export interface ScrollViewerEvent {
|
|
|
263
263
|
scrollWidth: number;
|
|
264
264
|
}
|
|
265
265
|
export type CodeState = {
|
|
266
|
-
/** 是否展示代码块编辑区 */
|
|
267
|
-
isShowCodeEditor: boolean;
|
|
268
266
|
/** 代码块DSL数据源 */
|
|
269
267
|
codeDsl: CodeBlockDSL | null;
|
|
270
|
-
/** 当前选中的代码块id */
|
|
271
|
-
id: Id;
|
|
272
268
|
/** 代码块是否可编辑 */
|
|
273
269
|
editable: boolean;
|
|
274
270
|
/** list模式下左侧展示的代码列表 */
|
|
275
271
|
combineIds: string[];
|
|
276
272
|
/** 为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除) */
|
|
277
273
|
undeletableList: Id[];
|
|
274
|
+
paramsColConfig?: ColumnConfig;
|
|
278
275
|
};
|
|
279
276
|
export type HookData = {
|
|
280
277
|
/** 代码块id */
|
|
@@ -346,6 +343,8 @@ export interface EventSelectConfig {
|
|
|
346
343
|
compActionConfig?: FormItem;
|
|
347
344
|
/** 联动代码配置 */
|
|
348
345
|
codeActionConfig?: FormItem;
|
|
346
|
+
/** 联动数据源配置 */
|
|
347
|
+
dataSourceActionConfig?: FormItem;
|
|
349
348
|
}
|
|
350
349
|
export declare enum KeyBindingCommand {
|
|
351
350
|
/** 复制 */
|
|
@@ -399,3 +398,17 @@ export interface KeyBindingCacheItem {
|
|
|
399
398
|
eventType: 'keyup' | 'keydown';
|
|
400
399
|
binded: boolean;
|
|
401
400
|
}
|
|
401
|
+
export interface CodeSelectColConfig {
|
|
402
|
+
type: 'code-select-col';
|
|
403
|
+
name: string;
|
|
404
|
+
labelWidth?: number | string;
|
|
405
|
+
disabled?: boolean | FilterFunction;
|
|
406
|
+
display?: boolean | FilterFunction;
|
|
407
|
+
}
|
|
408
|
+
export interface DataSourceMethodSelectConfig {
|
|
409
|
+
type: 'data-source-method-select';
|
|
410
|
+
name: string;
|
|
411
|
+
labelWidth?: number | string;
|
|
412
|
+
disabled?: boolean | FilterFunction;
|
|
413
|
+
display?: boolean | FilterFunction;
|
|
414
|
+
}
|
|
@@ -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 language?: string | undefined;
|
|
75
|
-
readonly codeOptions?: Object | undefined;
|
|
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
72
|
content: {
|
|
102
|
-
type: import("vue").PropType<
|
|
73
|
+
type: import("vue").PropType<CodeBlockContent>;
|
|
103
74
|
required: true;
|
|
104
75
|
};
|
|
105
|
-
|
|
106
|
-
type: import("vue").PropType<string>;
|
|
107
|
-
};
|
|
108
|
-
codeOptions: {
|
|
109
|
-
type: import("vue").PropType<Object>;
|
|
110
|
-
};
|
|
111
|
-
autoSaveDraft: {
|
|
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
103
|
content: {
|
|
155
|
-
type: import("vue").PropType<
|
|
104
|
+
type: import("vue").PropType<CodeBlockContent>;
|
|
156
105
|
required: true;
|
|
157
106
|
};
|
|
158
|
-
|
|
159
|
-
type: import("vue").PropType<string>;
|
|
160
|
-
};
|
|
161
|
-
codeOptions: {
|
|
162
|
-
type: import("vue").PropType<Object>;
|
|
163
|
-
};
|
|
164
|
-
autoSaveDraft: {
|
|
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>
|