@tmagic/editor 1.0.0-beta.1

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.
Files changed (98) hide show
  1. package/dist/style.css +505 -0
  2. package/dist/tmagic-editor.es.js +4233 -0
  3. package/dist/tmagic-editor.es.js.map +1 -0
  4. package/dist/tmagic-editor.umd.js +4276 -0
  5. package/dist/tmagic-editor.umd.js.map +1 -0
  6. package/dist/types/src/Editor.vue.d.ts +136 -0
  7. package/dist/types/src/components/Icon.vue.d.ts +13 -0
  8. package/dist/types/src/components/ToolButton.vue.d.ts +35 -0
  9. package/dist/types/src/fields/Code.vue.d.ts +24 -0
  10. package/dist/types/src/fields/CodeLink.vue.d.ts +54 -0
  11. package/dist/types/src/fields/UISelect.vue.d.ts +32 -0
  12. package/dist/types/src/index.d.ts +19 -0
  13. package/dist/types/src/layouts/AddPageBox.vue.d.ts +5 -0
  14. package/dist/types/src/layouts/CodeEditor.vue.d.ts +46 -0
  15. package/dist/types/src/layouts/Framework.vue.d.ts +11 -0
  16. package/dist/types/src/layouts/NavMenu.vue.d.ts +24 -0
  17. package/dist/types/src/layouts/PropsPanel.vue.d.ts +13 -0
  18. package/dist/types/src/layouts/Resizer.vue.d.ts +13 -0
  19. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +12 -0
  20. package/dist/types/src/layouts/sidebar/LayerMenu.vue.d.ts +31 -0
  21. package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +973 -0
  22. package/dist/types/src/layouts/sidebar/Sidebar.vue.d.ts +27 -0
  23. package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +11 -0
  24. package/dist/types/src/layouts/workspace/Stage.vue.d.ts +153 -0
  25. package/dist/types/src/layouts/workspace/ViewerMenu.vue.d.ts +18 -0
  26. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +37 -0
  27. package/dist/types/src/services/BaseService.d.ts +56 -0
  28. package/dist/types/src/services/editor.d.ts +122 -0
  29. package/dist/types/src/services/events.d.ts +16 -0
  30. package/dist/types/src/services/history.d.ts +51 -0
  31. package/dist/types/src/services/props.d.ts +36 -0
  32. package/dist/types/src/services/ui.d.ts +26 -0
  33. package/dist/types/src/shims-vue.d.ts +6 -0
  34. package/dist/types/src/type.d.ts +183 -0
  35. package/dist/types/src/utils/compose.d.ts +5 -0
  36. package/dist/types/src/utils/config.d.ts +4 -0
  37. package/dist/types/src/utils/editor.d.ts +45 -0
  38. package/dist/types/src/utils/index.d.ts +4 -0
  39. package/dist/types/src/utils/logger.d.ts +5 -0
  40. package/dist/types/src/utils/props.d.ts +49 -0
  41. package/dist/types/src/utils/undo-redo.d.ts +12 -0
  42. package/dist/types/src/vite-env.d.ts +1 -0
  43. package/package.json +57 -0
  44. package/src/Editor.vue +234 -0
  45. package/src/components/Icon.vue +29 -0
  46. package/src/components/ToolButton.vue +188 -0
  47. package/src/fields/Code.vue +35 -0
  48. package/src/fields/CodeLink.vue +81 -0
  49. package/src/fields/UISelect.vue +100 -0
  50. package/src/index.ts +63 -0
  51. package/src/layouts/AddPageBox.vue +41 -0
  52. package/src/layouts/CodeEditor.vue +188 -0
  53. package/src/layouts/Framework.vue +73 -0
  54. package/src/layouts/NavMenu.vue +37 -0
  55. package/src/layouts/PropsPanel.vue +81 -0
  56. package/src/layouts/Resizer.vue +61 -0
  57. package/src/layouts/sidebar/ComponentListPanel.vue +69 -0
  58. package/src/layouts/sidebar/LayerMenu.vue +117 -0
  59. package/src/layouts/sidebar/LayerPanel.vue +209 -0
  60. package/src/layouts/sidebar/Sidebar.vue +86 -0
  61. package/src/layouts/workspace/PageBar.vue +83 -0
  62. package/src/layouts/workspace/Stage.vue +221 -0
  63. package/src/layouts/workspace/ViewerMenu.vue +110 -0
  64. package/src/layouts/workspace/Workspace.vue +98 -0
  65. package/src/services/BaseService.ts +138 -0
  66. package/src/services/componentList.ts +48 -0
  67. package/src/services/editor.ts +521 -0
  68. package/src/services/events.ts +82 -0
  69. package/src/services/history.ts +124 -0
  70. package/src/services/props.ts +110 -0
  71. package/src/services/ui.ts +101 -0
  72. package/src/shims-vue.d.ts +6 -0
  73. package/src/theme/code-editor.scss +7 -0
  74. package/src/theme/common/var.scss +13 -0
  75. package/src/theme/component-list-panel.scss +102 -0
  76. package/src/theme/content-menu.scss +39 -0
  77. package/src/theme/framework.scss +72 -0
  78. package/src/theme/index.scss +13 -0
  79. package/src/theme/layer-panel.scss +68 -0
  80. package/src/theme/nav-menu.scss +69 -0
  81. package/src/theme/page-bar.scss +31 -0
  82. package/src/theme/props-panel.scss +17 -0
  83. package/src/theme/resizer.scss +51 -0
  84. package/src/theme/ruler.scss +38 -0
  85. package/src/theme/sidebar.scss +97 -0
  86. package/src/theme/stage.scss +22 -0
  87. package/src/theme/workspace.scss +5 -0
  88. package/src/type.ts +236 -0
  89. package/src/utils/compose.ts +33 -0
  90. package/src/utils/config.ts +29 -0
  91. package/src/utils/editor.ts +244 -0
  92. package/src/utils/index.ts +22 -0
  93. package/src/utils/logger.ts +47 -0
  94. package/src/utils/props.ts +218 -0
  95. package/src/utils/undo-redo.ts +76 -0
  96. package/src/vite-env.d.ts +1 -0
  97. package/tsconfig.json +9 -0
  98. package/vite.config.ts +30 -0
@@ -0,0 +1,183 @@
1
+ import { Component } from 'vue';
2
+ import { FormConfig } from '@tmagic/form';
3
+ import { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
4
+ import StageCore from '@tmagic/stage';
5
+ import type { ComponentListService } from './services/componentList';
6
+ import type { EditorService } from './services/editor';
7
+ import type { EventsService } from './services/events';
8
+ import type { HistoryService } from './services/history';
9
+ import type { PropsService } from './services/props';
10
+ import type { UiService } from './services/ui';
11
+ export declare type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> | MNode;
12
+ export declare type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
13
+ export interface InstallOptions {
14
+ [key: string]: any;
15
+ }
16
+ export interface Services {
17
+ editorService: EditorService;
18
+ historyService: HistoryService;
19
+ eventsService: EventsService;
20
+ propsService: PropsService;
21
+ componentListService: ComponentListService;
22
+ uiService: UiService;
23
+ }
24
+ export interface StoreState {
25
+ root: MApp | null;
26
+ page: MPage | null;
27
+ parent: MContainer | null;
28
+ node: MNode | null;
29
+ stage: StageCore | null;
30
+ modifiedNodeIds: Map<Id, Id>;
31
+ }
32
+ export interface PropsState {
33
+ propsConfigMap: Record<string, FormConfig>;
34
+ propsValueMap: Record<string, MNode>;
35
+ }
36
+ export interface ComponentGroupState {
37
+ list: ComponentGroup[];
38
+ }
39
+ export interface SetColumnWidth {
40
+ left?: number;
41
+ center?: number | 'auto';
42
+ right?: number;
43
+ }
44
+ export interface GetColumnWidth {
45
+ left: number;
46
+ center: number;
47
+ right: number;
48
+ }
49
+ export interface UiState {
50
+ /** 当前点击画布是否触发选中,true: 不触发,false: 触发,默认为false */
51
+ uiSelectMode: boolean;
52
+ /** 是否显示整个配置源码, true: 显示, false: 不显示,默认为false */
53
+ showSrc: boolean;
54
+ /** 画布显示放大倍数,默认为 1 */
55
+ zoom: number;
56
+ /** 画布顶层div的样式,可用于改变画布的大小 */
57
+ stageStyle: Record<string, string | number>;
58
+ /** 编辑器列布局每一列的宽度,分为左中右三列 */
59
+ columnWidth: GetColumnWidth;
60
+ /** 是否显示画布参考线,true: 显示,false: 不显示,默认为true */
61
+ showGuides: boolean;
62
+ /** 是否显示标尺,true: 显示,false: 不显示,默认为true */
63
+ showRule: boolean;
64
+ }
65
+ export interface EditorNodeInfo {
66
+ node?: MNode;
67
+ parent?: MContainer;
68
+ page?: MPage;
69
+ }
70
+ export interface AddMNode {
71
+ type: string;
72
+ name?: string;
73
+ [key: string]: any;
74
+ }
75
+ /**
76
+ * 菜单按钮
77
+ */
78
+ export interface MenuButton {
79
+ /**
80
+ * 按钮类型
81
+ * button: 只有文字不带边框的按钮
82
+ * text: 纯文本
83
+ * dropdown: 下拉菜单
84
+ * divider: 分隔线
85
+ * zoom: 放大缩小
86
+ */
87
+ type: 'button' | 'dropdown' | 'text' | 'divider' | 'zoom';
88
+ /** 展示的文案 */
89
+ text?: string;
90
+ /** 鼠标悬浮是显示的气泡中的文案 */
91
+ tooltip?: string;
92
+ /** element-plus icon class */
93
+ icon?: string | Component<{}, {}, any>;
94
+ /** 是否置灰,默认为false */
95
+ disabled?: boolean | ((data?: Services) => boolean);
96
+ /** 是否显示,默认为true */
97
+ display?: boolean | ((data?: Services) => boolean);
98
+ /** type为button/dropdown时点击运行的方法 */
99
+ handler?: (data?: Services) => Promise<any> | any;
100
+ /** type为dropdown时,下拉的菜单列表 */
101
+ items?: {
102
+ /** 展示的文案 */
103
+ text: string;
104
+ /** 点击运行的方法 */
105
+ handler(data: Services): any;
106
+ }[];
107
+ }
108
+ export interface MenuComponent {
109
+ type: 'component';
110
+ /** Vue3组件 */
111
+ component: any;
112
+ /** 传入组件的props对象 */
113
+ props?: Record<string, any>;
114
+ /** 组件监听的事件对象,如:{ click: () => { console.log('click'); } } */
115
+ listeners?: Record<string, Function>;
116
+ slots?: Record<string, any>;
117
+ /** 是否显示,默认为true */
118
+ display?: boolean | ((data?: Services) => Promise<boolean> | boolean);
119
+ }
120
+ /**
121
+ * '/': 分隔符
122
+ * 'delete': 删除按钮
123
+ * 'undo': 撤销按钮
124
+ * 'redo': 恢复按钮
125
+ * 'zoom-in': 放大按钮
126
+ * 'zoom-out': 缩小按钮
127
+ */
128
+ export declare type MenuItem = '/' | 'delete' | 'undo' | 'redo' | 'zoom' | 'zoom-in' | 'zoom-out' | 'guides' | 'rule' | MenuButton | MenuComponent;
129
+ /** 工具栏 */
130
+ export interface MenuBarData {
131
+ /** 顶部工具栏左边项 */
132
+ left?: MenuItem[];
133
+ /** 顶部工具栏中间项 */
134
+ center?: MenuItem[];
135
+ /** 顶部工具栏右边项 */
136
+ right?: MenuItem[];
137
+ }
138
+ export interface SideComponent extends MenuComponent {
139
+ /** 显示文案 */
140
+ text: string;
141
+ /** element-plus icon class */
142
+ icon: Component<{}, {}, any>;
143
+ }
144
+ /**
145
+ * component-list: 组件列表
146
+ * layer: 已选组件树
147
+ */
148
+ export declare type SideItem = 'component-list' | 'layer' | SideComponent;
149
+ /** 工具栏 */
150
+ export interface SideBarData {
151
+ /** 容器类型 */
152
+ type: 'tabs';
153
+ /** 默认激活的内容 */
154
+ status: string;
155
+ /** panel列表 */
156
+ items: SideItem[];
157
+ }
158
+ export interface ComponentItem {
159
+ /** 显示文案 */
160
+ text: string;
161
+ /** 组件类型 */
162
+ type: string;
163
+ /** element-plus icon class */
164
+ icon?: string | Component;
165
+ [key: string]: any;
166
+ }
167
+ export interface ComponentGroup {
168
+ /** 显示文案 */
169
+ title: string;
170
+ /** 组内列表 */
171
+ items: ComponentItem[];
172
+ }
173
+ export declare enum LayerOffset {
174
+ TOP = "top",
175
+ BOTTOM = "bottom"
176
+ }
177
+ /** 容器布局 */
178
+ export declare enum Layout {
179
+ FLEX = "flex",
180
+ FIXED = "fixed",
181
+ RELATIVE = "relative",
182
+ ABSOLUTE = "absolute"
183
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @param {Array} middleware
3
+ * @return {Function}
4
+ */
5
+ export declare const compose: (middleware: Function[]) => (args: any[], next?: Function | undefined) => Promise<void>;
@@ -0,0 +1,4 @@
1
+ import { InstallOptions } from '../type';
2
+ declare const setConfig: (option: InstallOptions) => void;
3
+ declare const getConfig: (key: keyof InstallOptions) => unknown;
4
+ export { getConfig, setConfig };
@@ -0,0 +1,45 @@
1
+ import { MApp, MContainer, MNode, MPage } from '@tmagic/schema';
2
+ import { Layout } from '../type';
3
+ export declare const COPY_STORAGE_KEY = "$MagicEditorCopyData";
4
+ export declare const generateId: (type: string | number) => string;
5
+ /**
6
+ * 获取所有页面配置
7
+ * @param app DSL跟节点
8
+ * @returns 所有页面配置
9
+ */
10
+ export declare const getPageList: (app: MApp) => MPage[];
11
+ /**
12
+ * 获取所有页面名称
13
+ * @param pages 所有页面配置
14
+ * @returns 所有页面名称
15
+ */
16
+ export declare const getPageNameList: (pages: MPage[]) => string[];
17
+ /**
18
+ * 新增页面时,生成页面名称
19
+ * @param {Object} pageNameList 所有页面名称
20
+ * @returns {string}
21
+ */
22
+ export declare const generatePageName: (pageNameList: string[]) => string;
23
+ /**
24
+ * 新增页面时,生成页面名称
25
+ * @param {Object} app 所有页面配置
26
+ * @returns {string}
27
+ */
28
+ export declare const generatePageNameByApp: (app: MApp) => string;
29
+ /**
30
+ * 将组件与组件的子元素配置中的id都设置成一个新的ID
31
+ * @param {Object} config 组件配置
32
+ */
33
+ export declare const setNewItemId: (config: MNode, parent?: MPage | undefined) => void;
34
+ /**
35
+ * @param {Object} node
36
+ * @returns {boolean}
37
+ */
38
+ export declare const isFixed: (node: MNode) => boolean;
39
+ export declare const getNodeIndex: (node: MNode, parent: MContainer) => number;
40
+ export declare const toRelative: (node: MNode) => MNode;
41
+ export declare const initPosition: (node: MNode, layout: Layout) => MNode;
42
+ export declare const setLayout: (node: MNode, layout: Layout) => MNode;
43
+ export declare const change2Fixed: (node: MNode, root: MApp) => MNode;
44
+ export declare const Fixed2Other: (node: MNode, root: MApp, getLayout: (node: MNode) => Promise<Layout>) => Promise<MNode>;
45
+ export declare const defaults: (object: any, source: any) => any;
@@ -0,0 +1,4 @@
1
+ export * from './config';
2
+ export * from './props';
3
+ export * from './logger';
4
+ export * from './editor';
@@ -0,0 +1,5 @@
1
+ export declare const log: (...args: any[]) => void;
2
+ export declare const info: (...args: any[]) => void;
3
+ export declare const warn: (...args: any[]) => void;
4
+ export declare const debug: (...args: any[]) => void;
5
+ export declare const error: (...args: any[]) => void;
@@ -0,0 +1,49 @@
1
+ import type { ChildConfig, FormConfig, FormState } from '@tmagic/form';
2
+ /**
3
+ * 统一为组件属性表单加上事件、高级、样式配置
4
+ * @param config 组件属性配置
5
+ * @returns Object
6
+ */
7
+ export declare const fillConfig: (config?: FormConfig) => {
8
+ type: string;
9
+ items: ({
10
+ title: string;
11
+ labelWidth: string;
12
+ items: (ChildConfig & {
13
+ [key: string]: any;
14
+ })[];
15
+ } | {
16
+ title: string;
17
+ items: {
18
+ type: string;
19
+ name: string;
20
+ items: ({
21
+ name: string;
22
+ label: string;
23
+ type: string;
24
+ options: (mForm: FormState, { formValue }: any) => {
25
+ text: string;
26
+ value: string;
27
+ }[];
28
+ } | {
29
+ name: string;
30
+ label: string;
31
+ type: string;
32
+ options?: undefined;
33
+ })[];
34
+ }[];
35
+ labelWidth?: undefined;
36
+ })[];
37
+ }[];
38
+ export declare const DEFAULT_CONFIG: FormConfig;
39
+ /**
40
+ * 获取默认属性配置
41
+ * @param type 组件类型
42
+ * @returns Object
43
+ */
44
+ export declare const getDefaultPropsValue: (type: string) => {
45
+ type: string;
46
+ id: string;
47
+ style: {};
48
+ name: string;
49
+ };
@@ -0,0 +1,12 @@
1
+ export declare class UndoRedo<T = any> {
2
+ private elementList;
3
+ private listCursor;
4
+ private listMaxSize;
5
+ constructor(listMaxSize?: number);
6
+ pushElement(element: T): void;
7
+ canUndo(): boolean;
8
+ undo(): T | null;
9
+ canRedo(): boolean;
10
+ redo(): T | null;
11
+ getCurrentElement(): T | null;
12
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "version": "1.0.0-beta.1",
3
+ "name": "@tmagic/editor",
4
+ "main": "dist/magic-editor.umd.js",
5
+ "module": "dist/magic-editor.es.js",
6
+ "style": "dist/style.css",
7
+ "types": "dist/types/src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/magic-editor.es.js",
11
+ "require": "./dist/magic-editor.umd.js"
12
+ },
13
+ "./dist/style.css": {
14
+ "import": "./dist/style.css",
15
+ "require": "./dist/style.css"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "vite build"
20
+ },
21
+ "engines": {
22
+ "node": ">=14"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/Tencent/tmagic-editor.git"
27
+ },
28
+ "dependencies": {
29
+ "@element-plus/icons": "0.0.11",
30
+ "@tmagic/core": "^1.0.0-beta.1",
31
+ "@tmagic/form": "^1.0.0-beta.1",
32
+ "@tmagic/schema": "^1.0.0-beta.1",
33
+ "@tmagic/stage": "^1.0.0-beta.1",
34
+ "@tmagic/utils": "^1.0.0-beta.1",
35
+ "color": "^3.1.3",
36
+ "element-plus": "^2.0.2",
37
+ "events": "^3.3.0",
38
+ "lodash-es": "^4.17.21",
39
+ "serialize-javascript": "^6.0.0",
40
+ "vue": "^3.2.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/events": "^3.0.0",
44
+ "@types/lodash-es": "^4.17.4",
45
+ "@types/node": "^15.12.4",
46
+ "@types/serialize-javascript": "^5.0.1",
47
+ "@vitejs/plugin-vue": "^1.2.3",
48
+ "@vitejs/plugin-vue-jsx": "^1.1.6",
49
+ "@vue/compiler-sfc": "^3.2.0",
50
+ "@vue/test-utils": "^2.0.0-rc.12",
51
+ "sass": "^1.35.1",
52
+ "typescript": "^4.3.4",
53
+ "vite": "^2.3.7",
54
+ "vite-plugin-dts": "^0.9.6",
55
+ "vue-tsc": "^0.0.24"
56
+ }
57
+ }
package/src/Editor.vue ADDED
@@ -0,0 +1,234 @@
1
+ <template>
2
+ <framework>
3
+ <template #nav>
4
+ <slot name="nav" :editorService="editorService"><nav-menu :data="menu"></nav-menu></slot>
5
+ </template>
6
+
7
+ <template #sidebar>
8
+ <slot name="sidebar" :editorService="editorService">
9
+ <sidebar :data="sidebar"></sidebar>
10
+ </slot>
11
+ </template>
12
+
13
+ <template #workspace :editorService="editorService">
14
+ <slot name="workspace">
15
+ <workspace
16
+ :runtime-url="runtimeUrl"
17
+ :render="render"
18
+ :moveable-options="moveableOptions"
19
+ :can-select="canSelect"
20
+ >
21
+ <template #workspace-content><slot name="workspace-content" :editorService="editorService"></slot></template>
22
+ <template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
23
+ <template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
24
+ </workspace>
25
+ </slot>
26
+ </template>
27
+
28
+ <template #propsPanel>
29
+ <slot name="propsPanel">
30
+ <props-panel ref="propsPanel" @mounted="(instance) => $emit('props-panel-mounted', instance)"></props-panel>
31
+ </slot>
32
+ </template>
33
+
34
+ <template #empty><slot name="empty" :editorService="editorService"></slot></template>
35
+ </framework>
36
+ </template>
37
+
38
+ <script lang="ts">
39
+ import { defineComponent, onUnmounted, PropType, provide, toRaw, watch } from 'vue';
40
+
41
+ import { EventOption } from '@tmagic/core';
42
+ import type { FormConfig } from '@tmagic/form';
43
+ import type { MApp, MNode } from '@tmagic/schema';
44
+ import type StageCore from '@tmagic/stage';
45
+ import type { MoveableOptions } from '@tmagic/stage';
46
+
47
+ import Framework from '@editor/layouts/Framework.vue';
48
+ import NavMenu from '@editor/layouts/NavMenu.vue';
49
+ import PropsPanel from '@editor/layouts/PropsPanel.vue';
50
+ import Sidebar from '@editor/layouts/sidebar/Sidebar.vue';
51
+ import Workspace from '@editor/layouts/workspace/Workspace.vue';
52
+ import componentListService from '@editor/services/componentList';
53
+ import editorService from '@editor/services/editor';
54
+ import eventsService from '@editor/services/events';
55
+ import historyService from '@editor/services/history';
56
+ import propsService from '@editor/services/props';
57
+ import uiService from '@editor/services/ui';
58
+ import type { ComponentGroup, MenuBarData, Services, SideBarData } from '@editor/type';
59
+
60
+ export default defineComponent({
61
+ name: 'm-editor',
62
+
63
+ components: {
64
+ NavMenu,
65
+ Sidebar,
66
+ Workspace,
67
+ PropsPanel,
68
+ Framework,
69
+ },
70
+
71
+ props: {
72
+ /** 页面初始值 */
73
+ modelValue: {
74
+ type: Object as PropType<MApp>,
75
+ default: () => ({}),
76
+ require: true,
77
+ },
78
+
79
+ /** 左侧面板中的组件列表 */
80
+ componentGroupList: {
81
+ type: Array as PropType<ComponentGroup[]>,
82
+ default: () => [],
83
+ },
84
+
85
+ /** 左侧面板配置 */
86
+ sidebar: {
87
+ type: Object as PropType<SideBarData>,
88
+ },
89
+
90
+ /** 顶部工具栏配置 */
91
+ menu: {
92
+ type: Object as PropType<MenuBarData>,
93
+ default: () => ({ left: [], right: [] }),
94
+ },
95
+
96
+ /** 中间工作区域中画布渲染的内容 */
97
+ render: {
98
+ type: Function as PropType<() => HTMLDivElement>,
99
+ },
100
+
101
+ /** 中间工作区域中画布通过iframe渲染时的页面url */
102
+ runtimeUrl: String,
103
+
104
+ /** 组件的属性配置表单的dsl */
105
+ propsConfigs: {
106
+ type: Object as PropType<Record<string, FormConfig>>,
107
+ default: () => ({}),
108
+ },
109
+
110
+ /** 添加组件时的默认值 */
111
+ propsValues: {
112
+ type: Object as PropType<Record<string, MNode>>,
113
+ default: () => ({}),
114
+ },
115
+
116
+ /** 组件联动事件选项列表 */
117
+ eventMethodList: {
118
+ type: Object,
119
+ default: () => ({}),
120
+ },
121
+
122
+ /** 画布中组件选中框的移动范围 */
123
+ moveableOptions: {
124
+ type: [Object, Function] as PropType<MoveableOptions | ((core?: StageCore) => MoveableOptions)>,
125
+ },
126
+
127
+ /** 编辑器初始化时默认选中的组件ID */
128
+ defaultSelected: {
129
+ type: [Number, String],
130
+ },
131
+
132
+ canSelect: {
133
+ type: Function as PropType<(el: HTMLElement) => boolean | Promise<boolean>>,
134
+ },
135
+
136
+ stageStyle: {
137
+ type: [String, Object] as PropType<Record<string, string | number>>,
138
+ },
139
+ },
140
+
141
+ emits: ['props-panel-mounted', 'update:modelValue'],
142
+
143
+ setup(props, { emit }) {
144
+ editorService.on('root-change', () => {
145
+ const node = editorService.get<MNode | null>('node') || props.defaultSelected;
146
+ node && editorService.select(node);
147
+ emit('update:modelValue', toRaw(editorService.get('root')));
148
+ });
149
+
150
+ // 初始值变化,重新设置节点信息
151
+ watch(
152
+ () => props.modelValue,
153
+ (modelValue) => editorService.set('root', modelValue),
154
+ {
155
+ immediate: true,
156
+ },
157
+ );
158
+
159
+ watch(
160
+ () => props.componentGroupList,
161
+ (componentGroupList) => componentListService.setList(componentGroupList),
162
+ {
163
+ immediate: true,
164
+ },
165
+ );
166
+
167
+ watch(
168
+ () => props.propsConfigs,
169
+ (configs) => propsService.setPropsConfigs(configs),
170
+ {
171
+ immediate: true,
172
+ },
173
+ );
174
+
175
+ watch(
176
+ () => props.propsValues,
177
+ (values) => propsService.setPropsValues(values),
178
+ {
179
+ immediate: true,
180
+ },
181
+ );
182
+
183
+ watch(
184
+ () => props.eventMethodList,
185
+ (eventMethodList) => {
186
+ const eventsList: Record<string, EventOption[]> = {};
187
+ const methodsList: Record<string, EventOption[]> = {};
188
+
189
+ Object.keys(eventMethodList).forEach((type: string) => {
190
+ eventsList[type] = eventMethodList[type].events;
191
+ methodsList[type] = eventMethodList[type].methods;
192
+ });
193
+
194
+ eventsService.setEvents(eventsList);
195
+ eventsService.setMethods(methodsList);
196
+ },
197
+ {
198
+ immediate: true,
199
+ },
200
+ );
201
+
202
+ watch(
203
+ () => props.defaultSelected,
204
+ (defaultSelected) => defaultSelected && editorService.select(defaultSelected),
205
+ {
206
+ immediate: true,
207
+ },
208
+ );
209
+
210
+ watch(
211
+ () => props.stageStyle,
212
+ (stageStyle) => uiService.set('stageStyle', stageStyle),
213
+ {
214
+ immediate: true,
215
+ },
216
+ );
217
+
218
+ onUnmounted(() => editorService.destroy());
219
+
220
+ const services: Services = {
221
+ componentListService,
222
+ eventsService,
223
+ historyService,
224
+ propsService,
225
+ editorService,
226
+ uiService,
227
+ };
228
+
229
+ provide('services', services);
230
+
231
+ return services;
232
+ },
233
+ });
234
+ </script>
@@ -0,0 +1,29 @@
1
+ <template>
2
+ <el-icon v-if="!icon"><edit></edit></el-icon>
3
+ <img v-else-if="typeof icon === 'string' && icon.startsWith('http')" :src="icon" />
4
+ <i v-else-if="typeof icon === 'string'" :class="icon"></i>
5
+ <el-icon v-else><component :is="toRaw(icon)"></component></el-icon>
6
+ </template>
7
+
8
+ <script lang="ts">
9
+ import { Component, defineComponent, PropType, toRaw } from 'vue';
10
+ import { Edit } from '@element-plus/icons';
11
+
12
+ export default defineComponent({
13
+ name: 'm-icon',
14
+
15
+ components: { Edit },
16
+
17
+ props: {
18
+ icon: {
19
+ type: [String, Object] as PropType<string | Component>,
20
+ },
21
+ },
22
+
23
+ setup() {
24
+ return {
25
+ toRaw,
26
+ };
27
+ },
28
+ });
29
+ </script>