@tmagic/editor 1.0.0-rc.6 → 1.0.0-rc.9
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 +3 -0
- package/dist/tmagic-editor.es.js +93 -91
- package/dist/tmagic-editor.es.js.map +1 -1
- package/dist/tmagic-editor.umd.js +92 -92
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/dist/types/src/Editor.vue.d.ts +17 -1
- package/dist/types/src/fields/Code.vue.d.ts +4 -4
- package/dist/types/src/fields/CodeLink.vue.d.ts +1 -3
- package/dist/types/src/layouts/PropsPanel.vue.d.ts +2 -4
- package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +3 -31
- package/dist/types/src/services/history.d.ts +1 -18
- package/dist/types/src/services/props.d.ts +8 -2
- package/dist/types/src/type.d.ts +9 -0
- package/dist/types/src/utils/editor.d.ts +0 -6
- package/dist/types/src/utils/props.d.ts +8 -1
- package/package.json +11 -20
- package/src/Editor.vue +21 -8
- package/src/layouts/workspace/Stage.vue +11 -31
- package/src/layouts/workspace/Workspace.vue +2 -28
- package/src/services/editor.ts +1 -2
- package/src/services/props.ts +62 -7
- package/src/theme/workspace.scss +4 -0
- package/src/type.ts +10 -0
- package/src/utils/editor.ts +1 -50
- package/src/utils/props.ts +30 -7
- package/LICENSE +0 -5432
- package/coverage/clover.xml +0 -1615
- package/coverage/coverage-final.json +0 -36
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -206
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/Editor.vue.html +0 -853
- package/coverage/lcov-report/src/components/ContentMenu.vue.html +0 -505
- package/coverage/lcov-report/src/components/Icon.vue.html +0 -172
- package/coverage/lcov-report/src/components/ScrollViewer.vue.html +0 -283
- package/coverage/lcov-report/src/components/ToolButton.vue.html +0 -772
- package/coverage/lcov-report/src/components/index.html +0 -161
- package/coverage/lcov-report/src/index.html +0 -131
- package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +0 -214
- package/coverage/lcov-report/src/layouts/Framework.vue.html +0 -343
- package/coverage/lcov-report/src/layouts/NavMenu.vue.html +0 -208
- package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +0 -319
- package/coverage/lcov-report/src/layouts/Resizer.vue.html +0 -268
- package/coverage/lcov-report/src/layouts/index.html +0 -176
- package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +0 -358
- package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +0 -430
- package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +0 -775
- package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +0 -226
- package/coverage/lcov-report/src/layouts/sidebar/TabPane.vue.html +0 -289
- package/coverage/lcov-report/src/layouts/sidebar/index.html +0 -176
- package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +0 -718
- package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +0 -766
- package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +0 -577
- package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +0 -649
- package/coverage/lcov-report/src/layouts/workspace/index.html +0 -161
- package/coverage/lcov-report/src/services/BaseService.ts.html +0 -643
- package/coverage/lcov-report/src/services/componentList.ts.html +0 -229
- package/coverage/lcov-report/src/services/editor.ts.html +0 -2167
- package/coverage/lcov-report/src/services/events.ts.html +0 -331
- package/coverage/lcov-report/src/services/history.ts.html +0 -478
- package/coverage/lcov-report/src/services/index.html +0 -206
- package/coverage/lcov-report/src/services/props.ts.html +0 -415
- package/coverage/lcov-report/src/services/ui.ts.html +0 -580
- package/coverage/lcov-report/src/type.ts.html +0 -850
- package/coverage/lcov-report/src/utils/compose.ts.html +0 -184
- package/coverage/lcov-report/src/utils/config.ts.html +0 -172
- package/coverage/lcov-report/src/utils/editor.ts.html +0 -850
- package/coverage/lcov-report/src/utils/index.html +0 -221
- package/coverage/lcov-report/src/utils/index.ts.html +0 -151
- package/coverage/lcov-report/src/utils/logger.ts.html +0 -226
- package/coverage/lcov-report/src/utils/props.ts.html +0 -796
- package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +0 -733
- package/coverage/lcov-report/src/utils/undo-redo.ts.html +0 -313
- package/coverage/lcov.info +0 -3893
- package/dist/types/src/components/ToolButton.vue.d.ts +0 -46
- package/dist/types/src/fields/UISelect.vue.d.ts +0 -35
- package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +0 -18
|
@@ -62,6 +62,9 @@ declare const _default: DefineComponent<{
|
|
|
62
62
|
/** 画布中组件选中框的移动范围 */
|
|
63
63
|
moveableOptions: {
|
|
64
64
|
type: PropType<MoveableOptions | ((core?: StageCore | undefined) => MoveableOptions)>;
|
|
65
|
+
default: () => (core?: StageCore | undefined) => {
|
|
66
|
+
container: HTMLElement | null | undefined;
|
|
67
|
+
};
|
|
65
68
|
};
|
|
66
69
|
/** 编辑器初始化时默认选中的组件ID */
|
|
67
70
|
defaultSelected: {
|
|
@@ -69,6 +72,7 @@ declare const _default: DefineComponent<{
|
|
|
69
72
|
};
|
|
70
73
|
canSelect: {
|
|
71
74
|
type: PropType<(el: HTMLElement) => boolean | Promise<boolean>>;
|
|
75
|
+
default: (el: HTMLElement) => boolean;
|
|
72
76
|
};
|
|
73
77
|
stageRect: {
|
|
74
78
|
type: PropType<StageRect>;
|
|
@@ -77,6 +81,9 @@ declare const _default: DefineComponent<{
|
|
|
77
81
|
type: ObjectConstructor;
|
|
78
82
|
default: () => {};
|
|
79
83
|
};
|
|
84
|
+
updateDragEl: {
|
|
85
|
+
type: PropType<(el: HTMLDivElement, target: HTMLElement) => void>;
|
|
86
|
+
};
|
|
80
87
|
}, Services, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ("props-panel-mounted" | "update:modelValue")[], "props-panel-mounted" | "update:modelValue", VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
|
|
81
88
|
/** 页面初始值 */
|
|
82
89
|
modelValue: {
|
|
@@ -135,6 +142,9 @@ declare const _default: DefineComponent<{
|
|
|
135
142
|
/** 画布中组件选中框的移动范围 */
|
|
136
143
|
moveableOptions: {
|
|
137
144
|
type: PropType<MoveableOptions | ((core?: StageCore | undefined) => MoveableOptions)>;
|
|
145
|
+
default: () => (core?: StageCore | undefined) => {
|
|
146
|
+
container: HTMLElement | null | undefined;
|
|
147
|
+
};
|
|
138
148
|
};
|
|
139
149
|
/** 编辑器初始化时默认选中的组件ID */
|
|
140
150
|
defaultSelected: {
|
|
@@ -142,6 +152,7 @@ declare const _default: DefineComponent<{
|
|
|
142
152
|
};
|
|
143
153
|
canSelect: {
|
|
144
154
|
type: PropType<(el: HTMLElement) => boolean | Promise<boolean>>;
|
|
155
|
+
default: (el: HTMLElement) => boolean;
|
|
145
156
|
};
|
|
146
157
|
stageRect: {
|
|
147
158
|
type: PropType<StageRect>;
|
|
@@ -150,6 +161,9 @@ declare const _default: DefineComponent<{
|
|
|
150
161
|
type: ObjectConstructor;
|
|
151
162
|
default: () => {};
|
|
152
163
|
};
|
|
164
|
+
updateDragEl: {
|
|
165
|
+
type: PropType<(el: HTMLDivElement, target: HTMLElement) => void>;
|
|
166
|
+
};
|
|
153
167
|
}>> & {
|
|
154
168
|
"onProps-panel-mounted"?: ((...args: any[]) => any) | undefined;
|
|
155
169
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
@@ -157,12 +171,14 @@ declare const _default: DefineComponent<{
|
|
|
157
171
|
menu: MenuBarData;
|
|
158
172
|
layerContentMenu: MenuItem[];
|
|
159
173
|
stageContentMenu: MenuItem[];
|
|
160
|
-
autoScrollIntoView: boolean;
|
|
161
174
|
codeOptions: Record<string, any>;
|
|
162
175
|
modelValue: MApp;
|
|
163
176
|
componentGroupList: ComponentGroup[];
|
|
177
|
+
autoScrollIntoView: boolean;
|
|
164
178
|
propsConfigs: Record<string, FormConfig>;
|
|
165
179
|
propsValues: Record<string, MNode>;
|
|
166
180
|
eventMethodList: Record<string, any>;
|
|
181
|
+
moveableOptions: MoveableOptions | ((core?: StageCore | undefined) => MoveableOptions);
|
|
182
|
+
canSelect: (el: HTMLElement) => boolean | Promise<boolean>;
|
|
167
183
|
}>;
|
|
168
184
|
export default _default;
|
|
@@ -16,9 +16,9 @@ declare const _default: DefineComponent<Readonly<{
|
|
|
16
16
|
}>>> & {
|
|
17
17
|
onChange?: ((...args: any[]) => any) | undefined;
|
|
18
18
|
}, {
|
|
19
|
-
name
|
|
20
|
-
config
|
|
21
|
-
model
|
|
22
|
-
prop
|
|
19
|
+
readonly name?: any;
|
|
20
|
+
readonly config?: any;
|
|
21
|
+
readonly model?: any;
|
|
22
|
+
readonly prop?: any;
|
|
23
23
|
}>;
|
|
24
24
|
export default _default;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { DefineComponent, Ref, ComputedRef, ComponentOptionsMixin, VNodeProps, AllowedComponentProps, ComponentCustomProps, ExtractPropTypes } from 'vue';
|
|
2
|
+
import type { FormValue } from '@tmagic/form';
|
|
2
3
|
declare const _default: DefineComponent<{}, {
|
|
3
|
-
values: Ref<
|
|
4
|
-
[x: string]: any;
|
|
5
|
-
[x: number]: any;
|
|
6
|
-
}>;
|
|
4
|
+
values: Ref<FormValue>;
|
|
7
5
|
configForm: Ref<any>;
|
|
8
6
|
curFormConfig: any;
|
|
9
7
|
propsPanelSize: ComputedRef<unknown>;
|
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
import type { DefineComponent, Ref, ComputedRef, ComponentOptionsMixin, VNodeProps, AllowedComponentProps, ComponentCustomProps, ExtractPropTypes
|
|
1
|
+
import type { DefineComponent, Ref, ComputedRef, ComponentOptionsMixin, EmitsOptions, VNodeProps, AllowedComponentProps, ComponentCustomProps, ExtractPropTypes } from 'vue';
|
|
2
2
|
import type { MPage } from '@tmagic/schema';
|
|
3
|
-
|
|
4
|
-
import StageCore from '@tmagic/stage';
|
|
5
|
-
declare const _default: DefineComponent<{
|
|
6
|
-
runtimeUrl: StringConstructor;
|
|
7
|
-
autoScrollIntoView: BooleanConstructor;
|
|
8
|
-
render: {
|
|
9
|
-
type: PropType<() => HTMLDivElement>;
|
|
10
|
-
};
|
|
11
|
-
moveableOptions: {
|
|
12
|
-
type: PropType<MoveableOptions | ((core?: StageCore | undefined) => MoveableOptions)>;
|
|
13
|
-
};
|
|
14
|
-
canSelect: {
|
|
15
|
-
type: PropType<(el: HTMLElement) => boolean | Promise<boolean>>;
|
|
16
|
-
};
|
|
17
|
-
}, {
|
|
3
|
+
declare const _default: DefineComponent<{}, {
|
|
18
4
|
workspace: Ref<HTMLDivElement | undefined>;
|
|
19
5
|
page: ComputedRef<MPage | undefined>;
|
|
20
|
-
},
|
|
21
|
-
runtimeUrl: StringConstructor;
|
|
22
|
-
autoScrollIntoView: BooleanConstructor;
|
|
23
|
-
render: {
|
|
24
|
-
type: PropType<() => HTMLDivElement>;
|
|
25
|
-
};
|
|
26
|
-
moveableOptions: {
|
|
27
|
-
type: PropType<MoveableOptions | ((core?: StageCore | undefined) => MoveableOptions)>;
|
|
28
|
-
};
|
|
29
|
-
canSelect: {
|
|
30
|
-
type: PropType<(el: HTMLElement) => boolean | Promise<boolean>>;
|
|
31
|
-
};
|
|
32
|
-
}>>, {
|
|
33
|
-
autoScrollIntoView: boolean;
|
|
34
|
-
}>;
|
|
6
|
+
}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{}>>, {}>;
|
|
35
7
|
export default _default;
|
|
@@ -15,24 +15,7 @@ export interface HistoryState {
|
|
|
15
15
|
declare class History extends BaseService {
|
|
16
16
|
state: {
|
|
17
17
|
pageId?: Id | undefined;
|
|
18
|
-
pageSteps:
|
|
19
|
-
[x: string]: {
|
|
20
|
-
pushElement: (element: StepValue) => void;
|
|
21
|
-
canUndo: () => boolean;
|
|
22
|
-
undo: () => StepValue | null;
|
|
23
|
-
canRedo: () => boolean;
|
|
24
|
-
redo: () => StepValue | null;
|
|
25
|
-
getCurrentElement: () => StepValue | null;
|
|
26
|
-
};
|
|
27
|
-
[x: number]: {
|
|
28
|
-
pushElement: (element: StepValue) => void;
|
|
29
|
-
canUndo: () => boolean;
|
|
30
|
-
undo: () => StepValue | null;
|
|
31
|
-
canRedo: () => boolean;
|
|
32
|
-
redo: () => StepValue | null;
|
|
33
|
-
getCurrentElement: () => StepValue | null;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
18
|
+
pageSteps: Record<Id, UndoRedo<StepValue>>;
|
|
36
19
|
canRedo: boolean;
|
|
37
20
|
canUndo: boolean;
|
|
38
21
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FormConfig } from '@tmagic/form';
|
|
2
|
-
import type { MNode } from '@tmagic/schema';
|
|
2
|
+
import type { MNode, MPage } from '@tmagic/schema';
|
|
3
3
|
import BaseService from './BaseService';
|
|
4
4
|
declare class Props extends BaseService {
|
|
5
5
|
private state;
|
|
@@ -29,7 +29,13 @@ declare class Props extends BaseService {
|
|
|
29
29
|
* @param type 组件类型
|
|
30
30
|
* @returns 组件初始值
|
|
31
31
|
*/
|
|
32
|
-
getPropsValue(type: string, defaultValue?:
|
|
32
|
+
getPropsValue(type: string, defaultValue?: Record<string, any>): Promise<any>;
|
|
33
|
+
createId(type: string | number): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* 将组件与组件的子元素配置中的id都设置成一个新的ID
|
|
36
|
+
* @param {Object} config 组件配置
|
|
37
|
+
*/
|
|
38
|
+
setNewItemId(config: MNode, parent?: MPage): Promise<void>;
|
|
33
39
|
}
|
|
34
40
|
export declare type PropsService = Props;
|
|
35
41
|
declare const _default: Props;
|
package/dist/types/src/type.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Component } from 'vue';
|
|
|
2
2
|
import type { FormConfig } from '@tmagic/form';
|
|
3
3
|
import type { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
|
|
4
4
|
import type StageCore from '@tmagic/stage';
|
|
5
|
+
import type { MoveableOptions } from '@tmagic/stage';
|
|
5
6
|
import type { ComponentListService } from './services/componentList';
|
|
6
7
|
import type { EditorService } from './services/editor';
|
|
7
8
|
import type { EventsService } from './services/events';
|
|
@@ -21,6 +22,14 @@ export interface Services {
|
|
|
21
22
|
componentListService: ComponentListService;
|
|
22
23
|
uiService: UiService;
|
|
23
24
|
}
|
|
25
|
+
export interface StageOptions {
|
|
26
|
+
runtimeUrl: string;
|
|
27
|
+
autoScrollIntoView: boolean;
|
|
28
|
+
render: () => HTMLDivElement;
|
|
29
|
+
moveableOptions: MoveableOptions | ((core?: StageCore) => MoveableOptions);
|
|
30
|
+
canSelect: (el: HTMLElement) => boolean | Promise<boolean>;
|
|
31
|
+
updateDragEl: (el: HTMLDivElement) => void;
|
|
32
|
+
}
|
|
24
33
|
export interface StoreState {
|
|
25
34
|
root: MApp | null;
|
|
26
35
|
page: MPage | null;
|
|
@@ -2,7 +2,6 @@ import type { MApp, MContainer, MNode, MPage } from '@tmagic/schema';
|
|
|
2
2
|
import type StageCore from '@tmagic/stage';
|
|
3
3
|
import { Layout } from '../type';
|
|
4
4
|
export declare const COPY_STORAGE_KEY = "$MagicEditorCopyData";
|
|
5
|
-
export declare const generateId: (type: string | number) => string;
|
|
6
5
|
/**
|
|
7
6
|
* 获取所有页面配置
|
|
8
7
|
* @param app DSL跟节点
|
|
@@ -27,11 +26,6 @@ export declare const generatePageName: (pageNameList: string[]) => string;
|
|
|
27
26
|
* @returns {string}
|
|
28
27
|
*/
|
|
29
28
|
export declare const generatePageNameByApp: (app: MApp) => string;
|
|
30
|
-
/**
|
|
31
|
-
* 将组件与组件的子元素配置中的id都设置成一个新的ID
|
|
32
|
-
* @param {Object} config 组件配置
|
|
33
|
-
*/
|
|
34
|
-
export declare const setNewItemId: (config: MNode, parent?: MPage | undefined) => void;
|
|
35
29
|
/**
|
|
36
30
|
* @param {Object} node
|
|
37
31
|
* @returns {boolean}
|
|
@@ -41,9 +41,16 @@ export declare const DEFAULT_CONFIG: FormConfig;
|
|
|
41
41
|
* @param type 组件类型
|
|
42
42
|
* @returns Object
|
|
43
43
|
*/
|
|
44
|
-
export declare const getDefaultPropsValue: (type: string) => {
|
|
44
|
+
export declare const getDefaultPropsValue: (type: string, id: string) => {
|
|
45
45
|
type: string;
|
|
46
46
|
id: string;
|
|
47
47
|
style: {};
|
|
48
48
|
name: string;
|
|
49
|
+
items: never[];
|
|
50
|
+
} | {
|
|
51
|
+
type: string;
|
|
52
|
+
id: string;
|
|
53
|
+
style: {};
|
|
54
|
+
name: string;
|
|
55
|
+
items?: undefined;
|
|
49
56
|
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-rc.
|
|
2
|
+
"version": "1.0.0-rc.9",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"dist/*",
|
|
@@ -22,9 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "vite build"
|
|
26
|
-
"test": "jest --maxWorkers=8",
|
|
27
|
-
"test:coverage": "jest --maxWorkers=16 --coverage"
|
|
25
|
+
"build": "vite build"
|
|
28
26
|
},
|
|
29
27
|
"engines": {
|
|
30
28
|
"node": ">=14"
|
|
@@ -45,11 +43,11 @@
|
|
|
45
43
|
"dependencies": {
|
|
46
44
|
"@babel/core": "^7.18.0",
|
|
47
45
|
"@element-plus/icons": "0.0.11",
|
|
48
|
-
"@tmagic/core": "
|
|
49
|
-
"@tmagic/form": "
|
|
50
|
-
"@tmagic/schema": "
|
|
51
|
-
"@tmagic/stage": "
|
|
52
|
-
"@tmagic/utils": "
|
|
46
|
+
"@tmagic/core": "1.0.0-rc.9",
|
|
47
|
+
"@tmagic/form": "1.0.0-rc.9",
|
|
48
|
+
"@tmagic/schema": "1.0.0-rc.9",
|
|
49
|
+
"@tmagic/stage": "1.0.0-rc.9",
|
|
50
|
+
"@tmagic/utils": "1.0.0-rc.9",
|
|
53
51
|
"buffer": "^6.0.3",
|
|
54
52
|
"color": "^3.1.3",
|
|
55
53
|
"element-plus": "^2.2.0",
|
|
@@ -62,31 +60,24 @@
|
|
|
62
60
|
"vue": "^3.2.0"
|
|
63
61
|
},
|
|
64
62
|
"peerDependencies": {
|
|
65
|
-
"@tmagic/form": "
|
|
63
|
+
"@tmagic/form": "1.0.0-rc.9",
|
|
66
64
|
"element-plus": "^2.2.0",
|
|
65
|
+
"monaco-editor": "^0.32.1",
|
|
67
66
|
"vue": "^3.2.0"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
|
70
69
|
"@types/events": "^3.0.0",
|
|
71
|
-
"@types/jest": "^27.5.1",
|
|
72
70
|
"@types/lodash-es": "^4.17.4",
|
|
73
71
|
"@types/node": "^15.12.4",
|
|
74
72
|
"@types/serialize-javascript": "^5.0.1",
|
|
75
73
|
"@vitejs/plugin-vue": "^1.2.3",
|
|
76
74
|
"@vitejs/plugin-vue-jsx": "^1.1.6",
|
|
77
75
|
"@vue/compiler-sfc": "^3.2.0",
|
|
78
|
-
"@vue/test-utils": "^2.0.0
|
|
79
|
-
"@vue/vue3-jest": "^27.0.0-alpha.4",
|
|
80
|
-
"babel-jest": "^27.0.6",
|
|
81
|
-
"jest": "^27.5.1",
|
|
82
|
-
"jest-serializer-vue": "^2.0.2",
|
|
83
|
-
"jest-transform-stub": "^2.0.0",
|
|
76
|
+
"@vue/test-utils": "^2.0.0",
|
|
84
77
|
"sass": "^1.35.1",
|
|
85
|
-
"ts-jest": "^27.1.4",
|
|
86
78
|
"typescript": "^4.3.4",
|
|
87
79
|
"vite": "^2.3.7",
|
|
88
80
|
"vite-plugin-dts": "^0.9.6",
|
|
89
81
|
"vue-tsc": "^0.0.24"
|
|
90
|
-
}
|
|
91
|
-
"gitHead": "a93928e56d73b7924991e899a4dfaf9614cd357c"
|
|
82
|
+
}
|
|
92
83
|
}
|
package/src/Editor.vue
CHANGED
|
@@ -12,13 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
<template #workspace :editorService="editorService">
|
|
14
14
|
<slot name="workspace">
|
|
15
|
-
<workspace
|
|
16
|
-
:runtime-url="runtimeUrl"
|
|
17
|
-
:auto-scroll-into-view="autoScrollIntoView"
|
|
18
|
-
:render="render"
|
|
19
|
-
:moveable-options="moveableOptions"
|
|
20
|
-
:can-select="canSelect"
|
|
21
|
-
>
|
|
15
|
+
<workspace>
|
|
22
16
|
<template #workspace-content><slot name="workspace-content" :editorService="editorService"></slot></template>
|
|
23
17
|
<template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
|
|
24
18
|
<template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
|
|
@@ -37,7 +31,7 @@
|
|
|
37
31
|
</template>
|
|
38
32
|
|
|
39
33
|
<script lang="ts">
|
|
40
|
-
import { defineComponent, onUnmounted, PropType, provide, toRaw, watch } from 'vue';
|
|
34
|
+
import { defineComponent, onUnmounted, PropType, provide, reactive, toRaw, watch } from 'vue';
|
|
41
35
|
|
|
42
36
|
import { EventOption } from '@tmagic/core';
|
|
43
37
|
import type { FormConfig } from '@tmagic/form';
|
|
@@ -136,6 +130,9 @@ export default defineComponent({
|
|
|
136
130
|
/** 画布中组件选中框的移动范围 */
|
|
137
131
|
moveableOptions: {
|
|
138
132
|
type: [Object, Function] as PropType<MoveableOptions | ((core?: StageCore) => MoveableOptions)>,
|
|
133
|
+
default: () => (core?: StageCore) => ({
|
|
134
|
+
container: core?.renderer?.contentWindow?.document.getElementById('app'),
|
|
135
|
+
}),
|
|
139
136
|
},
|
|
140
137
|
|
|
141
138
|
/** 编辑器初始化时默认选中的组件ID */
|
|
@@ -145,6 +142,7 @@ export default defineComponent({
|
|
|
145
142
|
|
|
146
143
|
canSelect: {
|
|
147
144
|
type: Function as PropType<(el: HTMLElement) => boolean | Promise<boolean>>,
|
|
145
|
+
default: (el: HTMLElement) => Boolean(el.id),
|
|
148
146
|
},
|
|
149
147
|
|
|
150
148
|
stageRect: {
|
|
@@ -155,6 +153,10 @@ export default defineComponent({
|
|
|
155
153
|
type: Object,
|
|
156
154
|
default: () => ({}),
|
|
157
155
|
},
|
|
156
|
+
|
|
157
|
+
updateDragEl: {
|
|
158
|
+
type: Function as PropType<(el: HTMLDivElement, target: HTMLElement) => void>,
|
|
159
|
+
},
|
|
158
160
|
},
|
|
159
161
|
|
|
160
162
|
emits: ['props-panel-mounted', 'update:modelValue'],
|
|
@@ -249,6 +251,17 @@ export default defineComponent({
|
|
|
249
251
|
|
|
250
252
|
provide('layerContentMenu', props.layerContentMenu);
|
|
251
253
|
provide('stageContentMenu', props.stageContentMenu);
|
|
254
|
+
provide(
|
|
255
|
+
'stageOptions',
|
|
256
|
+
reactive({
|
|
257
|
+
runtimeUrl: props.runtimeUrl,
|
|
258
|
+
autoScrollIntoView: props.autoScrollIntoView,
|
|
259
|
+
render: props.render,
|
|
260
|
+
moveableOptions: props.moveableOptions,
|
|
261
|
+
canSelect: props.canSelect,
|
|
262
|
+
updateDragEl: props.updateDragEl,
|
|
263
|
+
}),
|
|
264
|
+
);
|
|
252
265
|
|
|
253
266
|
return services;
|
|
254
267
|
},
|
|
@@ -28,7 +28,6 @@ import {
|
|
|
28
28
|
markRaw,
|
|
29
29
|
onMounted,
|
|
30
30
|
onUnmounted,
|
|
31
|
-
PropType,
|
|
32
31
|
ref,
|
|
33
32
|
toRaw,
|
|
34
33
|
watch,
|
|
@@ -37,11 +36,11 @@ import {
|
|
|
37
36
|
import { cloneDeep } from 'lodash-es';
|
|
38
37
|
|
|
39
38
|
import type { MApp, MNode, MPage } from '@tmagic/schema';
|
|
40
|
-
import type {
|
|
39
|
+
import type { Runtime, SortEventData, UpdateEventData } from '@tmagic/stage';
|
|
41
40
|
import StageCore from '@tmagic/stage';
|
|
42
41
|
|
|
43
42
|
import ScrollViewer from '@editor/components/ScrollViewer.vue';
|
|
44
|
-
import { Layout, Services, StageRect } from '@editor/type';
|
|
43
|
+
import { Layout, Services, StageOptions, StageRect } from '@editor/type';
|
|
45
44
|
|
|
46
45
|
import ViewerMenu from './ViewerMenu.vue';
|
|
47
46
|
|
|
@@ -53,29 +52,9 @@ export default defineComponent({
|
|
|
53
52
|
ScrollViewer,
|
|
54
53
|
},
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
render: {
|
|
58
|
-
type: Function as PropType<() => HTMLDivElement>,
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
runtimeUrl: String,
|
|
62
|
-
autoScrollIntoView: Boolean,
|
|
63
|
-
|
|
64
|
-
canSelect: {
|
|
65
|
-
type: Function as PropType<(el: HTMLElement) => boolean | Promise<boolean>>,
|
|
66
|
-
default: (el: HTMLElement) => Boolean(el.id),
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
moveableOptions: {
|
|
70
|
-
type: [Object, Function] as PropType<MoveableOptions | ((core?: StageCore) => MoveableOptions)>,
|
|
71
|
-
default: () => (core?: StageCore) => ({
|
|
72
|
-
container: core?.renderer?.contentWindow?.document.getElementById('app'),
|
|
73
|
-
}),
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
setup(props) {
|
|
55
|
+
setup() {
|
|
78
56
|
const services = inject<Services>('services');
|
|
57
|
+
const stageOptions = inject<StageOptions>('stageOptions');
|
|
79
58
|
|
|
80
59
|
const stageWrap = ref<InstanceType<typeof ScrollViewer>>();
|
|
81
60
|
const stageContainer = ref<HTMLDivElement>();
|
|
@@ -95,15 +74,15 @@ export default defineComponent({
|
|
|
95
74
|
if (stage) return;
|
|
96
75
|
|
|
97
76
|
if (!stageContainer.value) return;
|
|
98
|
-
if (!(
|
|
77
|
+
if (!(stageOptions?.runtimeUrl || stageOptions?.render) || !root.value) return;
|
|
99
78
|
|
|
100
79
|
stage = new StageCore({
|
|
101
|
-
render:
|
|
102
|
-
runtimeUrl:
|
|
80
|
+
render: stageOptions.render,
|
|
81
|
+
runtimeUrl: stageOptions.runtimeUrl,
|
|
103
82
|
zoom: zoom.value,
|
|
104
|
-
autoScrollIntoView:
|
|
83
|
+
autoScrollIntoView: stageOptions.autoScrollIntoView,
|
|
105
84
|
canSelect: (el, event, stop) => {
|
|
106
|
-
const elCanSelect =
|
|
85
|
+
const elCanSelect = stageOptions.canSelect(el);
|
|
107
86
|
// 在组件联动过程中不能再往下选择,返回并触发 ui-select
|
|
108
87
|
if (uiSelectMode.value && elCanSelect && event.type === 'mousedown') {
|
|
109
88
|
document.dispatchEvent(new CustomEvent('ui-select', { detail: el }));
|
|
@@ -112,7 +91,8 @@ export default defineComponent({
|
|
|
112
91
|
|
|
113
92
|
return elCanSelect;
|
|
114
93
|
},
|
|
115
|
-
moveableOptions:
|
|
94
|
+
moveableOptions: stageOptions.moveableOptions,
|
|
95
|
+
updateDragEl: stageOptions.updateDragEl,
|
|
116
96
|
});
|
|
117
97
|
|
|
118
98
|
services?.editorService.set('stage', markRaw(stage));
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="m-editor-workspace" tabindex="1" ref="workspace">
|
|
3
|
-
<magic-stage
|
|
4
|
-
:key="page?.id"
|
|
5
|
-
:runtime-url="runtimeUrl"
|
|
6
|
-
:auto-scroll-into-view="autoScrollIntoView"
|
|
7
|
-
:render="render"
|
|
8
|
-
:moveable-options="moveableOptions"
|
|
9
|
-
:can-select="canSelect"
|
|
10
|
-
></magic-stage>
|
|
3
|
+
<magic-stage :key="page?.id"></magic-stage>
|
|
11
4
|
|
|
12
5
|
<slot name="workspace-content"></slot>
|
|
13
6
|
|
|
@@ -19,12 +12,10 @@
|
|
|
19
12
|
</template>
|
|
20
13
|
|
|
21
14
|
<script lang="ts">
|
|
22
|
-
import { computed, defineComponent, inject, onMounted, onUnmounted,
|
|
15
|
+
import { computed, defineComponent, inject, onMounted, onUnmounted, ref } from 'vue';
|
|
23
16
|
import KeyController from 'keycon';
|
|
24
17
|
|
|
25
18
|
import type { MNode, MPage } from '@tmagic/schema';
|
|
26
|
-
import type { MoveableOptions } from '@tmagic/stage';
|
|
27
|
-
import StageCore from '@tmagic/stage';
|
|
28
19
|
import { isPage } from '@tmagic/utils';
|
|
29
20
|
|
|
30
21
|
import type { Services } from '@editor/type';
|
|
@@ -40,23 +31,6 @@ export default defineComponent({
|
|
|
40
31
|
MagicStage,
|
|
41
32
|
},
|
|
42
33
|
|
|
43
|
-
props: {
|
|
44
|
-
runtimeUrl: String,
|
|
45
|
-
autoScrollIntoView: Boolean,
|
|
46
|
-
|
|
47
|
-
render: {
|
|
48
|
-
type: Function as PropType<() => HTMLDivElement>,
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
moveableOptions: {
|
|
52
|
-
type: [Object, Function] as PropType<MoveableOptions | ((core?: StageCore) => MoveableOptions)>,
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
canSelect: {
|
|
56
|
-
type: Function as PropType<(el: HTMLElement) => boolean | Promise<boolean>>,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
|
|
60
34
|
setup() {
|
|
61
35
|
const services = inject<Services>('services');
|
|
62
36
|
const workspace = ref<HTMLDivElement>();
|
package/src/services/editor.ts
CHANGED
|
@@ -38,7 +38,6 @@ import {
|
|
|
38
38
|
initPosition,
|
|
39
39
|
isFixed,
|
|
40
40
|
setLayout,
|
|
41
|
-
setNewItemId,
|
|
42
41
|
} from '@editor/utils/editor';
|
|
43
42
|
import { log } from '@editor/utils/logger';
|
|
44
43
|
|
|
@@ -495,7 +494,7 @@ class Editor extends BaseService {
|
|
|
495
494
|
return;
|
|
496
495
|
}
|
|
497
496
|
|
|
498
|
-
setNewItemId(config, this.get('root'));
|
|
497
|
+
await propsService.setNewItemId(config, this.get('root'));
|
|
499
498
|
if (config.style) {
|
|
500
499
|
config.style = {
|
|
501
500
|
...config.style,
|
package/src/services/props.ts
CHANGED
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { reactive } from 'vue';
|
|
20
|
-
import { cloneDeep, mergeWith } from 'lodash-es';
|
|
20
|
+
import { cloneDeep, mergeWith, random } from 'lodash-es';
|
|
21
21
|
|
|
22
22
|
import type { FormConfig } from '@tmagic/form';
|
|
23
|
-
import type { MComponent, MNode } from '@tmagic/schema';
|
|
24
|
-
import {
|
|
23
|
+
import type { Id, MComponent, MNode, MPage } from '@tmagic/schema';
|
|
24
|
+
import { NodeType } from '@tmagic/schema';
|
|
25
|
+
import { isPop, toLine } from '@tmagic/utils';
|
|
25
26
|
|
|
26
27
|
import type { PropsState } from '@editor/type';
|
|
27
28
|
import { DEFAULT_CONFIG, fillConfig, getDefaultPropsValue } from '@editor/utils/props';
|
|
@@ -35,7 +36,7 @@ class Props extends BaseService {
|
|
|
35
36
|
});
|
|
36
37
|
|
|
37
38
|
constructor() {
|
|
38
|
-
super(['setPropsConfig', 'getPropsConfig', 'setPropsValue', 'getPropsValue']);
|
|
39
|
+
super(['setPropsConfig', 'getPropsConfig', 'setPropsValue', 'getPropsValue', 'createId', 'setNewItemId']);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
public setPropsConfigs(configs: Record<string, FormConfig>) {
|
|
@@ -87,7 +88,7 @@ class Props extends BaseService {
|
|
|
87
88
|
* @param type 组件类型
|
|
88
89
|
* @returns 组件初始值
|
|
89
90
|
*/
|
|
90
|
-
public async getPropsValue(type: string, defaultValue = {}) {
|
|
91
|
+
public async getPropsValue(type: string, defaultValue: Record<string, any> = {}) {
|
|
91
92
|
if (type === 'area') {
|
|
92
93
|
const value = (await this.getPropsValue('button')) as MComponent;
|
|
93
94
|
value.className = 'action-area';
|
|
@@ -98,13 +99,67 @@ class Props extends BaseService {
|
|
|
98
99
|
return value;
|
|
99
100
|
}
|
|
100
101
|
|
|
102
|
+
const data = cloneDeep(defaultValue as any);
|
|
103
|
+
|
|
104
|
+
await this.setNewItemId(data);
|
|
105
|
+
|
|
101
106
|
return {
|
|
102
|
-
...getDefaultPropsValue(type),
|
|
103
|
-
...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}),
|
|
107
|
+
...getDefaultPropsValue(type, await this.createId(type)),
|
|
108
|
+
...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}), data),
|
|
104
109
|
};
|
|
105
110
|
}
|
|
111
|
+
|
|
112
|
+
public async createId(type: string | number): Promise<string> {
|
|
113
|
+
return `${type}_${random(10000, false)}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 将组件与组件的子元素配置中的id都设置成一个新的ID
|
|
118
|
+
* @param {Object} config 组件配置
|
|
119
|
+
*/
|
|
120
|
+
/* eslint no-param-reassign: ["error", { "props": false }] */
|
|
121
|
+
public async setNewItemId(config: MNode, parent?: MPage) {
|
|
122
|
+
const oldId = config.id;
|
|
123
|
+
|
|
124
|
+
config.id = await this.createId(config.type || 'component');
|
|
125
|
+
|
|
126
|
+
// 只有弹窗在页面下的一级子元素才有效
|
|
127
|
+
if (isPop(config) && parent?.type === NodeType.PAGE) {
|
|
128
|
+
updatePopId(oldId, config.id, parent);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (config.items && Array.isArray(config.items)) {
|
|
132
|
+
for (const item of config.items) {
|
|
133
|
+
await this.setNewItemId(item, config as MPage);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
106
137
|
}
|
|
107
138
|
|
|
139
|
+
/**
|
|
140
|
+
* 复制页面时,需要把组件下关联的弹窗id换测复制出来的弹窗的id
|
|
141
|
+
* @param {number} oldId 复制的源弹窗id
|
|
142
|
+
* @param {number} popId 新的弹窗id
|
|
143
|
+
* @param {Object} pageConfig 页面配置
|
|
144
|
+
*/
|
|
145
|
+
const updatePopId = (oldId: Id, popId: Id, pageConfig: MPage) => {
|
|
146
|
+
pageConfig.items?.forEach((config) => {
|
|
147
|
+
if (config.pop === oldId) {
|
|
148
|
+
config.pop = popId;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (config.popId === oldId) {
|
|
153
|
+
config.popId = popId;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (Array.isArray(config.items)) {
|
|
158
|
+
updatePopId(oldId, popId, config as MPage);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
|
|
108
163
|
export type PropsService = Props;
|
|
109
164
|
|
|
110
165
|
export default new Props();
|