@tmagic/editor 1.4.7 → 1.4.8
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 +1 -1
- package/dist/tmagic-editor.js +314 -452
- package/dist/tmagic-editor.umd.cjs +313 -450
- package/package.json +15 -11
- package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
- package/types/services/editor.d.ts +19 -2
- package/types/services/props.d.ts +5 -5
- package/types/type.d.ts +6 -0
- package/types/utils/editor.d.ts +1 -0
- package/src/Editor.vue +0 -211
- package/src/components/CodeBlockEditor.vue +0 -268
- package/src/components/CodeParams.vue +0 -60
- package/src/components/ContentMenu.vue +0 -193
- package/src/components/FloatingBox.vue +0 -178
- package/src/components/Icon.vue +0 -27
- package/src/components/Resizer.vue +0 -23
- package/src/components/ScrollBar.vue +0 -151
- package/src/components/ScrollViewer.vue +0 -128
- package/src/components/SearchInput.vue +0 -37
- package/src/components/SplitView.vue +0 -186
- package/src/components/ToolButton.vue +0 -138
- package/src/components/Tree.vue +0 -71
- package/src/components/TreeNode.vue +0 -150
- package/src/editorProps.ts +0 -117
- package/src/fields/Code.vue +0 -50
- package/src/fields/CodeLink.vue +0 -80
- package/src/fields/CodeSelect.vue +0 -132
- package/src/fields/CodeSelectCol.vue +0 -139
- package/src/fields/DataSourceFieldSelect.vue +0 -149
- package/src/fields/DataSourceFields.vue +0 -323
- package/src/fields/DataSourceInput.vue +0 -331
- package/src/fields/DataSourceMethodSelect.vue +0 -153
- package/src/fields/DataSourceMethods.vue +0 -104
- package/src/fields/DataSourceMocks.vue +0 -255
- package/src/fields/DataSourceSelect.vue +0 -98
- package/src/fields/EventSelect.vue +0 -375
- package/src/fields/KeyValue.vue +0 -137
- package/src/fields/PageFragmentSelect.vue +0 -63
- package/src/fields/UISelect.vue +0 -135
- package/src/hooks/index.ts +0 -24
- package/src/hooks/use-code-block-edit.ts +0 -83
- package/src/hooks/use-data-source-edit.ts +0 -46
- package/src/hooks/use-data-source-method.ts +0 -100
- package/src/hooks/use-editor-content-height.ts +0 -26
- package/src/hooks/use-filter.ts +0 -55
- package/src/hooks/use-float-box.ts +0 -76
- package/src/hooks/use-getso.ts +0 -35
- package/src/hooks/use-next-float-box-position.ts +0 -29
- package/src/hooks/use-node-status.ts +0 -48
- package/src/hooks/use-stage.ts +0 -129
- package/src/hooks/use-window-rect.ts +0 -20
- package/src/icons/AppManageIcon.vue +0 -15
- package/src/icons/CenterIcon.vue +0 -13
- package/src/icons/CodeIcon.vue +0 -28
- package/src/icons/FolderMinusIcon.vue +0 -22
- package/src/icons/PinIcon.vue +0 -25
- package/src/icons/PinnedIcon.vue +0 -25
- package/src/index.ts +0 -118
- package/src/initService.ts +0 -443
- package/src/layouts/AddPageBox.vue +0 -55
- package/src/layouts/CodeEditor.vue +0 -226
- package/src/layouts/Framework.vue +0 -163
- package/src/layouts/NavMenu.vue +0 -200
- package/src/layouts/PropsPanel.vue +0 -130
- package/src/layouts/page-bar/AddButton.vue +0 -48
- package/src/layouts/page-bar/PageBar.vue +0 -159
- package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
- package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
- package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
- package/src/layouts/sidebar/Sidebar.vue +0 -278
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -160
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
- package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -172
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
- package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
- package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
- package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
- package/src/layouts/sidebar/layer/use-click.ts +0 -110
- package/src/layouts/sidebar/layer/use-drag.ts +0 -161
- package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
- package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
- package/src/layouts/workspace/Breadcrumb.vue +0 -35
- package/src/layouts/workspace/Workspace.vue +0 -46
- package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
- package/src/layouts/workspace/viewer/Stage.vue +0 -246
- package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
- package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
- package/src/services/BaseService.ts +0 -230
- package/src/services/codeBlock.ts +0 -327
- package/src/services/componentList.ts +0 -58
- package/src/services/dataSource.ts +0 -216
- package/src/services/dep.ts +0 -152
- package/src/services/editor.ts +0 -1096
- package/src/services/events.ts +0 -93
- package/src/services/history.ts +0 -126
- package/src/services/keybinding.ts +0 -220
- package/src/services/props.ts +0 -271
- package/src/services/stageOverlay.ts +0 -212
- package/src/services/storage.ts +0 -155
- package/src/services/ui.ts +0 -156
- package/src/shims-vue.d.ts +0 -6
- package/src/theme/breadcrumb.scss +0 -6
- package/src/theme/code-block.scss +0 -6
- package/src/theme/code-editor.scss +0 -38
- package/src/theme/common/var.scss +0 -14
- package/src/theme/component-list-panel.scss +0 -95
- package/src/theme/content-menu.scss +0 -76
- package/src/theme/data-source-field.scss +0 -12
- package/src/theme/data-source-fields.scss +0 -13
- package/src/theme/data-source-input.scss +0 -18
- package/src/theme/data-source-methods.scss +0 -13
- package/src/theme/data-source.scss +0 -28
- package/src/theme/event.scss +0 -37
- package/src/theme/floating-box.scss +0 -32
- package/src/theme/framework.scss +0 -69
- package/src/theme/icon.scss +0 -12
- package/src/theme/index.scss +0 -10
- package/src/theme/key-value.scss +0 -20
- package/src/theme/layer-panel.scss +0 -26
- package/src/theme/layout.scss +0 -9
- package/src/theme/nav-menu.scss +0 -78
- package/src/theme/page-bar.scss +0 -89
- package/src/theme/page-fragment-select.scss +0 -14
- package/src/theme/props-panel.scss +0 -55
- package/src/theme/resizer.scss +0 -66
- package/src/theme/ruler.scss +0 -38
- package/src/theme/search-input.scss +0 -14
- package/src/theme/sidebar.scss +0 -79
- package/src/theme/stage.scss +0 -76
- package/src/theme/theme.scss +0 -27
- package/src/theme/tree.scss +0 -89
- package/src/theme/workspace.scss +0 -9
- package/src/type.ts +0 -746
- package/src/utils/compose.ts +0 -52
- package/src/utils/config.ts +0 -29
- package/src/utils/content-menu.ts +0 -95
- package/src/utils/data-source/formConfigs/base.ts +0 -30
- package/src/utils/data-source/formConfigs/http.ts +0 -60
- package/src/utils/data-source/index.ts +0 -243
- package/src/utils/editor.ts +0 -294
- package/src/utils/idle-task.ts +0 -72
- package/src/utils/index.ts +0 -24
- package/src/utils/keybinding-config.ts +0 -125
- package/src/utils/logger.ts +0 -47
- package/src/utils/monaco-editor.ts +0 -8
- package/src/utils/operator.ts +0 -106
- package/src/utils/props.ts +0 -504
- package/src/utils/scroll-viewer.ts +0 -165
- package/src/utils/tree.ts +0 -15
- package/src/utils/undo-redo.ts +0 -76
- package/tsconfig.build.json +0 -16
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.
|
|
2
|
+
"version": "1.4.8",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
},
|
|
23
23
|
"./*": "./*"
|
|
24
24
|
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"types"
|
|
28
|
+
],
|
|
25
29
|
"license": "Apache-2.0",
|
|
26
30
|
"engines": {
|
|
27
31
|
"node": ">=18"
|
|
@@ -50,8 +54,8 @@
|
|
|
50
54
|
"lodash-es": "^4.17.21",
|
|
51
55
|
"moveable": "^0.53.0",
|
|
52
56
|
"serialize-javascript": "^6.0.0",
|
|
53
|
-
"@tmagic/dep": "1.4.
|
|
54
|
-
"@tmagic/table": "1.4.
|
|
57
|
+
"@tmagic/dep": "1.4.8",
|
|
58
|
+
"@tmagic/table": "1.4.8"
|
|
55
59
|
},
|
|
56
60
|
"devDependencies": {
|
|
57
61
|
"@types/events": "^3.0.0",
|
|
@@ -65,19 +69,19 @@
|
|
|
65
69
|
"sass": "^1.77.0",
|
|
66
70
|
"tsc-alias": "^1.8.5",
|
|
67
71
|
"type-fest": "^4.10.3",
|
|
68
|
-
"vite": "^5.
|
|
69
|
-
"vue-tsc": "^2.0.
|
|
72
|
+
"vite": "^5.3.1",
|
|
73
|
+
"vue-tsc": "^2.0.19"
|
|
70
74
|
},
|
|
71
75
|
"peerDependencies": {
|
|
72
76
|
"monaco-editor": "^0.48.0",
|
|
73
77
|
"vue": "^3.4.27",
|
|
74
78
|
"typescript": "*",
|
|
75
|
-
"@tmagic/core": "1.4.
|
|
76
|
-
"@tmagic/design": "1.4.
|
|
77
|
-
"@tmagic/form": "1.4.
|
|
78
|
-
"@tmagic/
|
|
79
|
-
"@tmagic/
|
|
80
|
-
"@tmagic/utils": "1.4.
|
|
79
|
+
"@tmagic/core": "1.4.8",
|
|
80
|
+
"@tmagic/design": "1.4.8",
|
|
81
|
+
"@tmagic/form": "1.4.8",
|
|
82
|
+
"@tmagic/stage": "1.4.8",
|
|
83
|
+
"@tmagic/schema": "1.4.8",
|
|
84
|
+
"@tmagic/utils": "1.4.8"
|
|
81
85
|
},
|
|
82
86
|
"peerDependenciesMeta": {
|
|
83
87
|
"typescript": {
|
|
@@ -60,5 +60,5 @@ export declare const useClick: (services: Services | undefined, isCtrlKeyDown: R
|
|
|
60
60
|
}> | undefined>;
|
|
61
61
|
nodeClickHandler: (event: MouseEvent, data: TreeNodeData) => void;
|
|
62
62
|
nodeContentMenuHandler(event: MouseEvent, data: TreeNodeData): void;
|
|
63
|
-
highlightHandler:
|
|
63
|
+
highlightHandler: (event: MouseEvent, data: TreeNodeData) => void;
|
|
64
64
|
};
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { Writable } from 'type-fest';
|
|
2
2
|
import { type TargetOptions } from '@tmagic/dep';
|
|
3
|
-
import type { Id, MContainer, MNode } from '@tmagic/schema';
|
|
3
|
+
import type { Id, MContainer, MNode, MPage, MPageFragment } from '@tmagic/schema';
|
|
4
4
|
import BaseService from '../services/BaseService';
|
|
5
5
|
import type { AddMNode, AsyncHookPlugin, EditorNodeInfo, PastePosition, StepValue, StoreState, StoreStateKey } from '../type';
|
|
6
6
|
import { LayerOffset, Layout } from '../type';
|
|
7
|
+
export interface EditorEvents {
|
|
8
|
+
'root-change': [value: StoreState['root'], preValue?: StoreState['root']];
|
|
9
|
+
select: [node: MNode | null];
|
|
10
|
+
add: [nodes: MNode[]];
|
|
11
|
+
remove: [nodes: MNode[]];
|
|
12
|
+
update: [nodes: MNode[]];
|
|
13
|
+
'move-layer': [offset: number | LayerOffset];
|
|
14
|
+
'drag-to': [data: {
|
|
15
|
+
targetIndex: number;
|
|
16
|
+
configs: MNode | MNode[];
|
|
17
|
+
targetParent: MContainer;
|
|
18
|
+
}];
|
|
19
|
+
'history-change': [data: MPage | MPageFragment];
|
|
20
|
+
}
|
|
7
21
|
declare const canUsePluginMethods: {
|
|
8
22
|
async: readonly ["getLayout", "highlight", "select", "multiSelect", "doAdd", "add", "doRemove", "remove", "doUpdate", "update", "sort", "copy", "paste", "doPaste", "doAlignCenter", "alignCenter", "moveLayer", "moveToContainer", "dragTo", "undo", "redo", "move"];
|
|
9
23
|
sync: never[];
|
|
@@ -136,7 +150,7 @@ declare class Editor extends BaseService {
|
|
|
136
150
|
* @param targetId 容器ID
|
|
137
151
|
*/
|
|
138
152
|
moveToContainer(config: MNode, targetId: Id): Promise<MNode | undefined>;
|
|
139
|
-
dragTo(config: MNode, targetParent: MContainer, targetIndex: number): Promise<void>;
|
|
153
|
+
dragTo(config: MNode | MNode[], targetParent: MContainer, targetIndex: number): Promise<void>;
|
|
140
154
|
/**
|
|
141
155
|
* 撤销当前操作
|
|
142
156
|
* @returns 上一次数据
|
|
@@ -152,6 +166,9 @@ declare class Editor extends BaseService {
|
|
|
152
166
|
destroy(): void;
|
|
153
167
|
resetModifiedNodeId(): void;
|
|
154
168
|
usePlugin(options: AsyncHookPlugin<AsyncMethodName, Editor>): void;
|
|
169
|
+
on<Name extends keyof EditorEvents, Param extends EditorEvents[Name]>(eventName: Name, listener: (...args: Param) => void | Promise<void>): this;
|
|
170
|
+
once<Name extends keyof EditorEvents, Param extends EditorEvents[Name]>(eventName: Name, listener: (...args: Param) => void | Promise<void>): this;
|
|
171
|
+
emit<Name extends keyof EditorEvents, Param extends EditorEvents[Name]>(eventName: Name, ...args: Param): boolean;
|
|
155
172
|
private addModifiedNodeId;
|
|
156
173
|
private pushHistoryState;
|
|
157
174
|
private changeHistoryState;
|
|
@@ -2,7 +2,7 @@ import { Writable } from 'type-fest';
|
|
|
2
2
|
import { type TargetOptions } from '@tmagic/dep';
|
|
3
3
|
import type { FormConfig } from '@tmagic/form';
|
|
4
4
|
import type { MNode } from '@tmagic/schema';
|
|
5
|
-
import type { AsyncHookPlugin, SyncHookPlugin } from '../type';
|
|
5
|
+
import type { AsyncHookPlugin, PropsFormConfigFunction, PropsFormValueFunction, SyncHookPlugin } from '../type';
|
|
6
6
|
import BaseService from './BaseService';
|
|
7
7
|
declare const canUsePluginMethods: {
|
|
8
8
|
async: readonly ["setPropsConfig", "getPropsConfig", "setPropsValue", "getPropsValue", "fillConfig", "getDefaultPropsValue"];
|
|
@@ -13,22 +13,22 @@ type SyncMethodName = Writable<(typeof canUsePluginMethods)['sync']>;
|
|
|
13
13
|
declare class Props extends BaseService {
|
|
14
14
|
private state;
|
|
15
15
|
constructor();
|
|
16
|
-
setPropsConfigs(configs: Record<string, FormConfig>): void;
|
|
16
|
+
setPropsConfigs(configs: Record<string, FormConfig | PropsFormConfigFunction>): void;
|
|
17
17
|
fillConfig(config: FormConfig, labelWidth?: string): Promise<FormConfig>;
|
|
18
|
-
setPropsConfig(type: string, config: FormConfig): Promise<void>;
|
|
18
|
+
setPropsConfig(type: string, config: FormConfig | PropsFormConfigFunction): Promise<void>;
|
|
19
19
|
/**
|
|
20
20
|
* 获取指点类型的组件属性表单配置
|
|
21
21
|
* @param type 组件类型
|
|
22
22
|
* @returns 组件属性表单配置
|
|
23
23
|
*/
|
|
24
24
|
getPropsConfig(type: string): Promise<FormConfig>;
|
|
25
|
-
setPropsValues(values: Record<string, Partial<MNode
|
|
25
|
+
setPropsValues(values: Record<string, Partial<MNode> | PropsFormValueFunction>): void;
|
|
26
26
|
/**
|
|
27
27
|
* 为指点类型组件设置组件初始值
|
|
28
28
|
* @param type 组件类型
|
|
29
29
|
* @param value 组件初始值
|
|
30
30
|
*/
|
|
31
|
-
setPropsValue(type: string, value: Partial<MNode>): Promise<void>;
|
|
31
|
+
setPropsValue(type: string, value: Partial<MNode> | PropsFormValueFunction): Promise<void>;
|
|
32
32
|
/**
|
|
33
33
|
* 获取指定类型的组件初始值
|
|
34
34
|
* @param type 组件类型
|
package/types/type.d.ts
CHANGED
|
@@ -617,3 +617,9 @@ export interface EventBus extends EventEmitter {
|
|
|
617
617
|
on<Name extends keyof EventBusEvent, Param extends EventBusEvent[Name]>(eventName: Name, listener: (...args: Param) => void): this;
|
|
618
618
|
emit<Name extends keyof EventBusEvent, Param extends EventBusEvent[Name]>(eventName: Name, ...args: Param): boolean;
|
|
619
619
|
}
|
|
620
|
+
export type PropsFormConfigFunction = (data: {
|
|
621
|
+
editorService: EditorService;
|
|
622
|
+
}) => FormConfig;
|
|
623
|
+
export type PropsFormValueFunction = (data: {
|
|
624
|
+
editorService: EditorService;
|
|
625
|
+
}) => Partial<MNode>;
|
package/types/utils/editor.d.ts
CHANGED
|
@@ -56,3 +56,4 @@ export interface NodeItem {
|
|
|
56
56
|
[key: string]: any;
|
|
57
57
|
}
|
|
58
58
|
export declare const traverseNode: <T extends NodeItem = NodeItem>(node: T, cb: (node: T, parents: T[]) => void, parents?: T[]) => void;
|
|
59
|
+
export declare const moveItemsInContainer: (sourceIndices: number[], parent: MContainer, targetIndex: number) => void;
|
package/src/Editor.vue
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<Framework :disabled-page-fragment="disabledPageFragment">
|
|
3
|
-
<template #header>
|
|
4
|
-
<slot name="header"></slot>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<template #nav>
|
|
8
|
-
<slot name="nav" :editorService="editorService"><TMagicNavMenu :data="menu"></TMagicNavMenu></slot>
|
|
9
|
-
</template>
|
|
10
|
-
|
|
11
|
-
<template #content-before>
|
|
12
|
-
<slot name="content-before"></slot>
|
|
13
|
-
</template>
|
|
14
|
-
|
|
15
|
-
<template #src-code><slot name="src-code" :editorService="editorService"></slot></template>
|
|
16
|
-
|
|
17
|
-
<template #sidebar>
|
|
18
|
-
<slot name="sidebar" :editorService="editorService">
|
|
19
|
-
<Sidebar :data="sidebar" :layer-content-menu="layerContentMenu" :custom-content-menu="customContentMenu">
|
|
20
|
-
<template #layer-panel-header>
|
|
21
|
-
<slot name="layer-panel-header"></slot>
|
|
22
|
-
</template>
|
|
23
|
-
|
|
24
|
-
<template #layer-node-content="{ data }">
|
|
25
|
-
<slot name="layer-node-content" :data="data"></slot>
|
|
26
|
-
</template>
|
|
27
|
-
|
|
28
|
-
<template #layer-node-label="{ data }">
|
|
29
|
-
<slot name="layer-node-label" :data="data"></slot>
|
|
30
|
-
</template>
|
|
31
|
-
|
|
32
|
-
<template #layer-node-tool="{ data }">
|
|
33
|
-
<slot name="layer-node-tool" :data="data"></slot>
|
|
34
|
-
</template>
|
|
35
|
-
|
|
36
|
-
<template #component-list-panel-header>
|
|
37
|
-
<slot name="component-list-panel-header"></slot>
|
|
38
|
-
</template>
|
|
39
|
-
|
|
40
|
-
<template #component-list-item="{ component }">
|
|
41
|
-
<slot name="component-list-item" :component="component"></slot>
|
|
42
|
-
</template>
|
|
43
|
-
|
|
44
|
-
<template #code-block-panel-header>
|
|
45
|
-
<slot name="code-block-panel-header"></slot>
|
|
46
|
-
</template>
|
|
47
|
-
|
|
48
|
-
<template #code-block-panel-tool="{ id, data }">
|
|
49
|
-
<slot name="code-block-panel-tool" :id="id" :data="data"></slot>
|
|
50
|
-
</template>
|
|
51
|
-
|
|
52
|
-
<template #code-block-panel-search>
|
|
53
|
-
<slot name="code-block-panel-search"></slot>
|
|
54
|
-
</template>
|
|
55
|
-
|
|
56
|
-
<template #data-source-panel-tool="{ data }">
|
|
57
|
-
<slot name="data-source-panel-tool" :data="data"></slot>
|
|
58
|
-
</template>
|
|
59
|
-
|
|
60
|
-
<template #data-source-panel-search>
|
|
61
|
-
<slot name="data-source-panel-search"></slot>
|
|
62
|
-
</template>
|
|
63
|
-
</Sidebar>
|
|
64
|
-
</slot>
|
|
65
|
-
</template>
|
|
66
|
-
|
|
67
|
-
<template #workspace>
|
|
68
|
-
<slot name="workspace" :editorService="editorService">
|
|
69
|
-
<Workspace
|
|
70
|
-
:disabled-stage-overlay="disabledStageOverlay"
|
|
71
|
-
:stage-content-menu="stageContentMenu"
|
|
72
|
-
:custom-content-menu="customContentMenu"
|
|
73
|
-
>
|
|
74
|
-
<template #stage><slot name="stage"></slot></template>
|
|
75
|
-
<template #workspace-content><slot name="workspace-content" :editorService="editorService"></slot></template>
|
|
76
|
-
</Workspace>
|
|
77
|
-
</slot>
|
|
78
|
-
</template>
|
|
79
|
-
|
|
80
|
-
<template #props-panel>
|
|
81
|
-
<slot name="props-panel">
|
|
82
|
-
<PropsPanel
|
|
83
|
-
:extend-state="extendFormState"
|
|
84
|
-
:disabled-show-src="disabledShowSrc"
|
|
85
|
-
@mounted="(instance: any) => $emit('props-panel-mounted', instance)"
|
|
86
|
-
@form-error="(e: any) => $emit('props-form-error', e)"
|
|
87
|
-
@submit-error="(e: any) => $emit('props-submit-error', e)"
|
|
88
|
-
>
|
|
89
|
-
<template #props-panel-header>
|
|
90
|
-
<slot name="props-panel-header"></slot>
|
|
91
|
-
</template>
|
|
92
|
-
</PropsPanel>
|
|
93
|
-
</slot>
|
|
94
|
-
</template>
|
|
95
|
-
|
|
96
|
-
<template #empty><slot name="empty" :editorService="editorService"></slot></template>
|
|
97
|
-
|
|
98
|
-
<template #content-after>
|
|
99
|
-
<slot name="content-after"></slot>
|
|
100
|
-
</template>
|
|
101
|
-
|
|
102
|
-
<template #footer>
|
|
103
|
-
<slot name="footer"></slot>
|
|
104
|
-
</template>
|
|
105
|
-
|
|
106
|
-
<template #page-bar><slot name="page-bar"></slot></template>
|
|
107
|
-
<template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
|
|
108
|
-
<template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
|
|
109
|
-
</Framework>
|
|
110
|
-
</template>
|
|
111
|
-
|
|
112
|
-
<script lang="ts" setup>
|
|
113
|
-
import { EventEmitter } from 'events';
|
|
114
|
-
|
|
115
|
-
import { provide } from 'vue';
|
|
116
|
-
|
|
117
|
-
import type { MApp } from '@tmagic/schema';
|
|
118
|
-
|
|
119
|
-
import Framework from './layouts/Framework.vue';
|
|
120
|
-
import TMagicNavMenu from './layouts/NavMenu.vue';
|
|
121
|
-
import PropsPanel from './layouts/PropsPanel.vue';
|
|
122
|
-
import Sidebar from './layouts/sidebar/Sidebar.vue';
|
|
123
|
-
import Workspace from './layouts/workspace/Workspace.vue';
|
|
124
|
-
import codeBlockService from './services/codeBlock';
|
|
125
|
-
import componentListService from './services/componentList';
|
|
126
|
-
import dataSourceService from './services/dataSource';
|
|
127
|
-
import depService from './services/dep';
|
|
128
|
-
import editorService, { type EditorService } from './services/editor';
|
|
129
|
-
import eventsService from './services/events';
|
|
130
|
-
import historyService from './services/history';
|
|
131
|
-
import keybindingService from './services/keybinding';
|
|
132
|
-
import propsService from './services/props';
|
|
133
|
-
import stageOverlayService from './services/stageOverlay';
|
|
134
|
-
import storageService from './services/storage';
|
|
135
|
-
import uiService from './services/ui';
|
|
136
|
-
import keybindingConfig from './utils/keybinding-config';
|
|
137
|
-
import { defaultEditorProps, EditorProps } from './editorProps';
|
|
138
|
-
import { initServiceEvents, initServiceState } from './initService';
|
|
139
|
-
import type { EventBus, FrameworkSlots, PropsPanelSlots, Services, SidebarSlots, WorkspaceSlots } from './type';
|
|
140
|
-
|
|
141
|
-
defineSlots<
|
|
142
|
-
FrameworkSlots &
|
|
143
|
-
WorkspaceSlots &
|
|
144
|
-
SidebarSlots &
|
|
145
|
-
PropsPanelSlots & {
|
|
146
|
-
workspace(props: { editorService: EditorService }): any;
|
|
147
|
-
'workspace-content'(props: { editorService: EditorService }): any;
|
|
148
|
-
}
|
|
149
|
-
>();
|
|
150
|
-
|
|
151
|
-
defineOptions({
|
|
152
|
-
name: 'MEditor',
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
const emit = defineEmits<{
|
|
156
|
-
'props-panel-mounted': [instance: InstanceType<typeof PropsPanel>];
|
|
157
|
-
'update:modelValue': [value: MApp | null];
|
|
158
|
-
'props-form-error': [e: any];
|
|
159
|
-
'props-submit-error': [e: any];
|
|
160
|
-
}>();
|
|
161
|
-
|
|
162
|
-
const props = withDefaults(defineProps<EditorProps>(), defaultEditorProps);
|
|
163
|
-
|
|
164
|
-
const services: Services = {
|
|
165
|
-
componentListService,
|
|
166
|
-
eventsService,
|
|
167
|
-
historyService,
|
|
168
|
-
propsService,
|
|
169
|
-
editorService,
|
|
170
|
-
uiService,
|
|
171
|
-
storageService,
|
|
172
|
-
codeBlockService,
|
|
173
|
-
depService,
|
|
174
|
-
dataSourceService,
|
|
175
|
-
keybindingService,
|
|
176
|
-
stageOverlayService,
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
initServiceEvents(props, emit, services);
|
|
180
|
-
initServiceState(props, services);
|
|
181
|
-
keybindingService.register(keybindingConfig);
|
|
182
|
-
keybindingService.registerEl('global');
|
|
183
|
-
|
|
184
|
-
const stageOptions = {
|
|
185
|
-
runtimeUrl: props.runtimeUrl,
|
|
186
|
-
autoScrollIntoView: props.autoScrollIntoView,
|
|
187
|
-
render: props.render,
|
|
188
|
-
moveableOptions: props.moveableOptions,
|
|
189
|
-
canSelect: props.canSelect,
|
|
190
|
-
updateDragEl: props.updateDragEl,
|
|
191
|
-
isContainer: props.isContainer,
|
|
192
|
-
containerHighlightClassName: props.containerHighlightClassName,
|
|
193
|
-
containerHighlightDuration: props.containerHighlightDuration,
|
|
194
|
-
containerHighlightType: props.containerHighlightType,
|
|
195
|
-
disabledDragStart: props.disabledDragStart,
|
|
196
|
-
renderType: props.renderType,
|
|
197
|
-
guidesOptions: props.guidesOptions,
|
|
198
|
-
disabledMultiSelect: props.disabledMultiSelect,
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
stageOverlayService.set('stageOptions', stageOptions);
|
|
202
|
-
|
|
203
|
-
provide('services', services);
|
|
204
|
-
|
|
205
|
-
provide('codeOptions', props.codeOptions);
|
|
206
|
-
provide('stageOptions', stageOptions);
|
|
207
|
-
|
|
208
|
-
provide<EventBus>('eventBus', new EventEmitter());
|
|
209
|
-
|
|
210
|
-
defineExpose(services);
|
|
211
|
-
</script>
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<!-- 代码块编辑区 -->
|
|
3
|
-
<FloatingBox
|
|
4
|
-
v-model:visible="boxVisible"
|
|
5
|
-
v-model:width="width"
|
|
6
|
-
v-model:height="codeBlockEditorHeight"
|
|
7
|
-
:title="content.name ? `${disabled ? '查看' : '编辑'}${content.name}` : '新增代码'"
|
|
8
|
-
:position="boxPosition"
|
|
9
|
-
:before-close="beforeClose"
|
|
10
|
-
>
|
|
11
|
-
<template #body>
|
|
12
|
-
<MFormBox
|
|
13
|
-
class="m-editor-code-block-editor"
|
|
14
|
-
ref="formBox"
|
|
15
|
-
label-width="80px"
|
|
16
|
-
:close-on-press-escape="false"
|
|
17
|
-
:title="content.name"
|
|
18
|
-
:config="functionConfig"
|
|
19
|
-
:values="content"
|
|
20
|
-
:disabled="disabled"
|
|
21
|
-
style="height: 100%"
|
|
22
|
-
@change="changeHandler"
|
|
23
|
-
@submit="submitForm"
|
|
24
|
-
@error="errorHandler"
|
|
25
|
-
@closed="closedHandler"
|
|
26
|
-
>
|
|
27
|
-
<template #left>
|
|
28
|
-
<TMagicButton v-if="!disabled" type="primary" link @click="difVisible = true">查看修改</TMagicButton>
|
|
29
|
-
</template>
|
|
30
|
-
</MFormBox>
|
|
31
|
-
</template>
|
|
32
|
-
</FloatingBox>
|
|
33
|
-
|
|
34
|
-
<Teleport to="body">
|
|
35
|
-
<TMagicDialog title="查看修改" v-model="difVisible" fullscreen>
|
|
36
|
-
<div style="display: flex; margin-bottom: 10px">
|
|
37
|
-
<div style="flex: 1"><TMagicTag size="small" type="info">修改前</TMagicTag></div>
|
|
38
|
-
<div style="flex: 1"><TMagicTag size="small" type="success">修改后</TMagicTag></div>
|
|
39
|
-
</div>
|
|
40
|
-
|
|
41
|
-
<CodeEditor
|
|
42
|
-
v-if="difVisible"
|
|
43
|
-
ref="magicVsEditor"
|
|
44
|
-
type="diff"
|
|
45
|
-
language="json"
|
|
46
|
-
:initValues="content.content"
|
|
47
|
-
:modifiedValues="formBox?.form?.values.content"
|
|
48
|
-
:style="`height: ${windowRect.height - 150}px`"
|
|
49
|
-
></CodeEditor>
|
|
50
|
-
|
|
51
|
-
<template #footer>
|
|
52
|
-
<span class="dialog-footer">
|
|
53
|
-
<TMagicButton size="small" @click="difVisible = false">取消</TMagicButton>
|
|
54
|
-
<TMagicButton size="small" type="primary" @click="diffChange">确定</TMagicButton>
|
|
55
|
-
</span>
|
|
56
|
-
</template>
|
|
57
|
-
</TMagicDialog>
|
|
58
|
-
</Teleport>
|
|
59
|
-
</template>
|
|
60
|
-
|
|
61
|
-
<script lang="ts" setup>
|
|
62
|
-
import { computed, inject, Ref, ref } from 'vue';
|
|
63
|
-
|
|
64
|
-
import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
|
|
65
|
-
import { ColumnConfig, FormConfig, FormState, MFormBox } from '@tmagic/form';
|
|
66
|
-
import type { CodeBlockContent } from '@tmagic/schema';
|
|
67
|
-
|
|
68
|
-
import FloatingBox from '@editor/components/FloatingBox.vue';
|
|
69
|
-
import { useEditorContentHeight } from '@editor/hooks/use-editor-content-height';
|
|
70
|
-
import { useNextFloatBoxPosition } from '@editor/hooks/use-next-float-box-position';
|
|
71
|
-
import { useWindowRect } from '@editor/hooks/use-window-rect';
|
|
72
|
-
import CodeEditor from '@editor/layouts/CodeEditor.vue';
|
|
73
|
-
import type { Services } from '@editor/type';
|
|
74
|
-
import { getConfig } from '@editor/utils/config';
|
|
75
|
-
|
|
76
|
-
defineOptions({
|
|
77
|
-
name: 'MEditorCodeBlockEditor',
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const width = defineModel<number>('width', { default: 670 });
|
|
81
|
-
const boxVisible = defineModel<boolean>('visible', { default: false });
|
|
82
|
-
|
|
83
|
-
const props = defineProps<{
|
|
84
|
-
content: CodeBlockContent;
|
|
85
|
-
disabled?: boolean;
|
|
86
|
-
isDataSource?: boolean;
|
|
87
|
-
dataSourceType?: string;
|
|
88
|
-
}>();
|
|
89
|
-
|
|
90
|
-
const emit = defineEmits<{
|
|
91
|
-
submit: [values: CodeBlockContent];
|
|
92
|
-
}>();
|
|
93
|
-
|
|
94
|
-
const services = inject<Services>('services');
|
|
95
|
-
|
|
96
|
-
const { height: codeBlockEditorHeight } = useEditorContentHeight();
|
|
97
|
-
|
|
98
|
-
const difVisible = ref(false);
|
|
99
|
-
const { rect: windowRect } = useWindowRect();
|
|
100
|
-
|
|
101
|
-
const magicVsEditor = ref<InstanceType<typeof CodeEditor>>();
|
|
102
|
-
|
|
103
|
-
const diffChange = () => {
|
|
104
|
-
if (!magicVsEditor.value || !formBox.value?.form) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
formBox.value.form.values.content = magicVsEditor.value.getEditorValue();
|
|
109
|
-
|
|
110
|
-
difVisible.value = false;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const defaultParamColConfig: ColumnConfig = {
|
|
114
|
-
type: 'row',
|
|
115
|
-
label: '参数类型',
|
|
116
|
-
items: [
|
|
117
|
-
{
|
|
118
|
-
text: '参数类型',
|
|
119
|
-
labelWidth: '70px',
|
|
120
|
-
type: 'select',
|
|
121
|
-
name: 'type',
|
|
122
|
-
options: [
|
|
123
|
-
{
|
|
124
|
-
text: '数字',
|
|
125
|
-
label: '数字',
|
|
126
|
-
value: 'number',
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
text: '字符串',
|
|
130
|
-
label: '字符串',
|
|
131
|
-
value: 'text',
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
text: '组件',
|
|
135
|
-
label: '组件',
|
|
136
|
-
value: 'ui-select',
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const functionConfig = computed<FormConfig>(() => [
|
|
144
|
-
{
|
|
145
|
-
text: '名称',
|
|
146
|
-
name: 'name',
|
|
147
|
-
rules: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
text: '描述',
|
|
151
|
-
name: 'desc',
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
text: '执行时机',
|
|
155
|
-
name: 'timing',
|
|
156
|
-
type: 'select',
|
|
157
|
-
options: () => {
|
|
158
|
-
const options = [
|
|
159
|
-
{ text: '初始化前', value: 'beforeInit' },
|
|
160
|
-
{ text: '初始化后', value: 'afterInit' },
|
|
161
|
-
];
|
|
162
|
-
if (props.dataSourceType !== 'base') {
|
|
163
|
-
options.push({ text: '请求前', value: 'beforeRequest' });
|
|
164
|
-
options.push({ text: '请求后', value: 'afterRequest' });
|
|
165
|
-
}
|
|
166
|
-
return options;
|
|
167
|
-
},
|
|
168
|
-
display: () => props.isDataSource,
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
type: 'table',
|
|
172
|
-
border: true,
|
|
173
|
-
text: '参数',
|
|
174
|
-
enableFullscreen: false,
|
|
175
|
-
enableToggleMode: false,
|
|
176
|
-
name: 'params',
|
|
177
|
-
dropSort: false,
|
|
178
|
-
items: [
|
|
179
|
-
{
|
|
180
|
-
type: 'text',
|
|
181
|
-
label: '参数名',
|
|
182
|
-
name: 'name',
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
type: 'text',
|
|
186
|
-
label: '描述',
|
|
187
|
-
name: 'extra',
|
|
188
|
-
},
|
|
189
|
-
services?.codeBlockService.getParamsColConfig() || defaultParamColConfig,
|
|
190
|
-
],
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
name: 'content',
|
|
194
|
-
type: 'vs-code',
|
|
195
|
-
options: inject('codeOptions', {}),
|
|
196
|
-
height: '500px',
|
|
197
|
-
onChange: (formState: FormState | undefined, code: string) => {
|
|
198
|
-
try {
|
|
199
|
-
// 检测js代码是否存在语法错误
|
|
200
|
-
getConfig('parseDSL')(code);
|
|
201
|
-
|
|
202
|
-
return code;
|
|
203
|
-
} catch (error: any) {
|
|
204
|
-
tMagicMessage.error(error.message);
|
|
205
|
-
|
|
206
|
-
throw error;
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
]);
|
|
211
|
-
|
|
212
|
-
const submitForm = (values: CodeBlockContent) => {
|
|
213
|
-
changedValue.value = undefined;
|
|
214
|
-
emit('submit', values);
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const errorHandler = (error: any) => {
|
|
218
|
-
tMagicMessage.error(error.message);
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const formBox = ref<InstanceType<typeof MFormBox>>();
|
|
222
|
-
|
|
223
|
-
const changedValue = ref<CodeBlockContent>();
|
|
224
|
-
const changeHandler = (values: CodeBlockContent) => {
|
|
225
|
-
changedValue.value = values;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
const beforeClose = (done: (cancel?: boolean) => void) => {
|
|
229
|
-
if (!changedValue.value) {
|
|
230
|
-
done();
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
tMagicMessageBox
|
|
234
|
-
.confirm('当前代码块已修改,是否保存?', '提示', {
|
|
235
|
-
confirmButtonText: '保存并关闭',
|
|
236
|
-
cancelButtonText: '不保存并关闭',
|
|
237
|
-
type: 'warning',
|
|
238
|
-
distinguishCancelAndClose: true,
|
|
239
|
-
})
|
|
240
|
-
.then(() => {
|
|
241
|
-
changedValue.value && submitForm(changedValue.value);
|
|
242
|
-
done();
|
|
243
|
-
})
|
|
244
|
-
.catch((action: string) => {
|
|
245
|
-
if (action === 'cancel') {
|
|
246
|
-
}
|
|
247
|
-
done(action === 'cancel');
|
|
248
|
-
});
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
const closedHandler = () => {
|
|
252
|
-
changedValue.value = undefined;
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
const parentFloating = inject<Ref<HTMLDivElement | null>>('parentFloating', ref(null));
|
|
256
|
-
const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(services?.uiService, parentFloating);
|
|
257
|
-
|
|
258
|
-
defineExpose({
|
|
259
|
-
async show() {
|
|
260
|
-
calcBoxPosition();
|
|
261
|
-
boxVisible.value = true;
|
|
262
|
-
},
|
|
263
|
-
|
|
264
|
-
async hide() {
|
|
265
|
-
boxVisible.value = false;
|
|
266
|
-
},
|
|
267
|
-
});
|
|
268
|
-
</script>
|