@tmagic/editor 1.2.0-beta.9 → 1.2.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 (103) hide show
  1. package/dist/style.css +62 -34
  2. package/dist/{tmagic-editor.mjs → tmagic-editor.js} +1641 -1266
  3. package/dist/tmagic-editor.js.map +1 -0
  4. package/dist/{tmagic-editor.umd.js → tmagic-editor.umd.cjs} +1649 -1270
  5. package/dist/tmagic-editor.umd.cjs.map +1 -0
  6. package/package.json +16 -14
  7. package/src/Editor.vue +66 -40
  8. package/src/components/CodeDraftEditor.vue +137 -0
  9. package/src/components/ContentMenu.vue +1 -1
  10. package/src/components/FunctionEditor.vue +190 -0
  11. package/src/components/Icon.vue +1 -1
  12. package/src/{layouts → components}/Layout.vue +54 -15
  13. package/src/components/ScrollBar.vue +1 -1
  14. package/src/components/ScrollViewer.vue +10 -1
  15. package/src/components/ToolButton.vue +1 -1
  16. package/src/fields/Code.vue +1 -1
  17. package/src/fields/CodeLink.vue +1 -1
  18. package/src/fields/CodeSelect.vue +102 -99
  19. package/src/fields/UISelect.vue +3 -3
  20. package/src/index.ts +2 -1
  21. package/src/layouts/AddPageBox.vue +5 -2
  22. package/src/layouts/CodeEditor.vue +2 -3
  23. package/src/layouts/Framework.vue +12 -10
  24. package/src/layouts/NavMenu.vue +11 -8
  25. package/src/layouts/PropsPanel.vue +12 -9
  26. package/src/layouts/Resizer.vue +1 -1
  27. package/src/layouts/sidebar/ComponentListPanel.vue +2 -3
  28. package/src/layouts/sidebar/LayerMenu.vue +9 -7
  29. package/src/layouts/sidebar/LayerPanel.vue +130 -178
  30. package/src/layouts/sidebar/Sidebar.vue +110 -26
  31. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +33 -118
  32. package/src/layouts/sidebar/code-block/CodeBlockList.vue +93 -126
  33. package/src/layouts/workspace/Breadcrumb.vue +6 -7
  34. package/src/layouts/workspace/PageBar.vue +3 -3
  35. package/src/layouts/workspace/PageBarScrollContainer.vue +5 -3
  36. package/src/layouts/workspace/Stage.vue +36 -18
  37. package/src/layouts/workspace/ViewerMenu.vue +16 -15
  38. package/src/layouts/workspace/Workspace.vue +9 -6
  39. package/src/services/BaseService.ts +11 -2
  40. package/src/services/codeBlock.ts +136 -146
  41. package/src/services/componentList.ts +7 -2
  42. package/src/services/editor.ts +161 -85
  43. package/src/services/events.ts +7 -2
  44. package/src/services/history.ts +8 -17
  45. package/src/services/props.ts +8 -3
  46. package/src/services/storage.ts +1 -0
  47. package/src/services/ui.ts +20 -10
  48. package/src/theme/code-block.scss +46 -23
  49. package/src/theme/component-list-panel.scss +8 -5
  50. package/src/type.ts +84 -63
  51. package/src/utils/config.ts +1 -1
  52. package/src/utils/editor.ts +17 -3
  53. package/src/utils/index.ts +2 -1
  54. package/src/utils/logger.ts +1 -1
  55. package/src/utils/operator.ts +12 -12
  56. package/src/utils/props.ts +3 -3
  57. package/src/utils/scroll-viewer.ts +18 -2
  58. package/src/utils/stage.ts +10 -9
  59. package/src/utils/undo-redo.ts +1 -1
  60. package/types/Editor.vue.d.ts +48 -28
  61. package/types/components/CodeDraftEditor.vue.d.ts +55 -0
  62. package/types/components/ContentMenu.vue.d.ts +11 -87
  63. package/types/components/FunctionEditor.vue.d.ts +60 -0
  64. package/types/components/Icon.vue.d.ts +4 -50
  65. package/types/{layouts → components}/Layout.vue.d.ts +12 -1
  66. package/types/components/ScrollBar.vue.d.ts +7 -65
  67. package/types/components/ScrollViewer.vue.d.ts +45 -1
  68. package/types/components/ToolButton.vue.d.ts +12 -78
  69. package/types/fields/Code.vue.d.ts +11 -77
  70. package/types/fields/CodeLink.vue.d.ts +12 -82
  71. package/types/fields/CodeSelect.vue.d.ts +13 -77
  72. package/types/fields/UISelect.vue.d.ts +7 -65
  73. package/types/index.d.ts +1 -0
  74. package/types/layouts/AddPageBox.vue.d.ts +1 -43
  75. package/types/layouts/CodeEditor.vue.d.ts +22 -130
  76. package/types/layouts/NavMenu.vue.d.ts +9 -69
  77. package/types/layouts/sidebar/LayerMenu.vue.d.ts +16 -48
  78. package/types/layouts/sidebar/LayerPanel.vue.d.ts +24 -7
  79. package/types/layouts/sidebar/Sidebar.vue.d.ts +10 -5
  80. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +24 -6
  81. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +11 -5
  82. package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -43
  83. package/types/layouts/workspace/Stage.vue.d.ts +15 -43
  84. package/types/layouts/workspace/ViewerMenu.vue.d.ts +11 -66
  85. package/types/layouts/workspace/Workspace.vue.d.ts +25 -8
  86. package/types/services/BaseService.d.ts +2 -1
  87. package/types/services/codeBlock.d.ts +56 -47
  88. package/types/services/componentList.d.ts +1 -0
  89. package/types/services/editor.d.ts +10 -11
  90. package/types/services/events.d.ts +1 -0
  91. package/types/services/history.d.ts +5 -15
  92. package/types/services/props.d.ts +3 -2
  93. package/types/services/ui.d.ts +24 -24
  94. package/types/type.d.ts +70 -59
  95. package/types/utils/editor.d.ts +1 -0
  96. package/types/utils/index.d.ts +1 -0
  97. package/types/utils/operator.d.ts +1 -1
  98. package/types/utils/props.d.ts +1 -1
  99. package/types/utils/scroll-viewer.d.ts +5 -0
  100. package/dist/tmagic-editor.mjs.map +0 -1
  101. package/dist/tmagic-editor.umd.js.map +0 -1
  102. package/src/layouts/sidebar/TabPane.vue +0 -118
  103. package/types/layouts/sidebar/TabPane.vue.d.ts +0 -82
@@ -1,6 +1,5 @@
1
- import { Id, MNode } from '@tmagic/schema';
2
- import type { CodeBlockContent, CodeBlockDSL } from '../type';
3
- import { CodeEditorMode, CodeSelectOp } from '../type';
1
+ import { CodeBlockContent, CodeBlockDSL, Id, MNode } from '@tmagic/schema';
2
+ import type { CodeRelation } from '../type';
4
3
  import BaseService from './BaseService';
5
4
  declare class CodeBlock extends BaseService {
6
5
  private state;
@@ -13,23 +12,25 @@ declare class CodeBlock extends BaseService {
13
12
  setCodeDsl(codeDsl: CodeBlockDSL): Promise<void>;
14
13
  /**
15
14
  * 获取活动的代码块dsl数据源(默认从dsl中的codeBlocks字段读取)
15
+ * 方法要支持钩子添加扩展,会被重写为异步方法,因此这里显示写为异步以提醒调用者需以异步形式调用
16
16
  * @param {boolean} forceRefresh 是否强制从活动dsl拉取刷新
17
17
  * @returns {CodeBlockDSL | null}
18
18
  */
19
19
  getCodeDsl(forceRefresh?: boolean): Promise<CodeBlockDSL | null>;
20
+ getCodeDslSync(forceRefresh?: boolean): CodeBlockDSL | null;
20
21
  /**
21
22
  * 根据代码块id获取代码块内容
22
- * @param {string} id 代码块id
23
+ * @param {Id} id 代码块id
23
24
  * @returns {CodeBlockContent | null}
24
25
  */
25
- getCodeContentById(id: string): Promise<CodeBlockContent | null>;
26
+ getCodeContentById(id: Id): Promise<CodeBlockContent | null>;
26
27
  /**
27
28
  * 设置代码块ID和代码内容到源dsl
28
- * @param {string} id 代码块id
29
+ * @param {Id} id 代码块id
29
30
  * @param {CodeBlockContent} codeConfig 代码块内容配置信息
30
31
  * @returns {void}
31
32
  */
32
- setCodeDslById(id: string, codeConfig: CodeBlockContent): Promise<void>;
33
+ setCodeDslById(id: Id, codeConfig: CodeBlockContent): Promise<void>;
33
34
  /**
34
35
  * 根据代码块id数组获取代码dsl
35
36
  * @param {string[]} ids 代码块id数组
@@ -50,10 +51,10 @@ declare class CodeBlock extends BaseService {
50
51
  /**
51
52
  * 设置代码编辑面板展示状态及展示内容
52
53
  * @param {boolean} status 是否展示代码编辑面板
53
- * @param {string} id 代码块id
54
+ * @param {Id} id 代码块id
54
55
  * @returns {void}
55
56
  */
56
- setCodeEditorContent(status: boolean, id: string): void;
57
+ setCodeEditorContent(status: boolean, id: Id): void;
57
58
  /**
58
59
  * 获取当前选中的代码块内容
59
60
  * @returns {CodeBlockContent | null}
@@ -72,26 +73,15 @@ declare class CodeBlock extends BaseService {
72
73
  setEditStatus(status: boolean): Promise<void>;
73
74
  /**
74
75
  * 设置当前选中的代码块ID
75
- * @param {string} id 代码块id
76
+ * @param {Id} id 代码块id
76
77
  * @returns {void}
77
78
  */
78
- setId(id: string): void;
79
+ setId(id: Id): void;
79
80
  /**
80
81
  * 获取当前选中的代码块ID
81
- * @returns {string} id 代码块id
82
+ * @returns {Id} id 代码块id
82
83
  */
83
- getId(): string;
84
- /**
85
- * 获取当前模式
86
- * @returns {CodeEditorMode}
87
- */
88
- getMode(): CodeEditorMode;
89
- /**
90
- * 设置当前模式
91
- * @param {CodeEditorMode} mode 模式
92
- * @returns {void}
93
- */
94
- setMode(mode: CodeEditorMode): Promise<void>;
84
+ getId(): Id;
95
85
  /**
96
86
  * 设置当前选中组件已关联绑定的代码块id数组
97
87
  * @param {string[]} ids 代码块id数组
@@ -104,51 +94,70 @@ declare class CodeBlock extends BaseService {
104
94
  */
105
95
  getCombineIds(): string[];
106
96
  /**
107
- * 设置绑定关系
108
- * @param {Id} 组件id
109
- * @param {string[]} diffCodeIds 代码块id数组
110
- * @param {CodeSelectOp} opFlag 操作类型
111
- * @param {string} hook 代码块挂载hook名称
112
- * @returns {void}
97
+ * 刷新绑定关系
98
+ * @returns {CodeRelation | null}
113
99
  */
114
- setCombineRelation(compId: Id, diffCodeIds: string[], opFlag: CodeSelectOp, hook: string): Promise<void>;
100
+ refreshCombineInfo(): CodeRelation | null;
101
+ /**
102
+ * 获取绑定关系
103
+ * @returns {CodeRelation}
104
+ */
105
+ getCombineInfo(): CodeRelation;
115
106
  /**
116
107
  * 获取不可删除列表
117
- * @returns {string[]}
108
+ * @returns {Id[]}
118
109
  */
119
- getUndeletableList(): string[];
110
+ getUndeletableList(): Id[];
120
111
  /**
121
112
  * 设置不可删除列表:为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除)
122
- * @param {string[]} codeIds 代码块id数组
113
+ * @param {Id[]} codeIds 代码块id数组
123
114
  * @returns {void}
124
115
  */
125
- setUndeleteableList(codeIds: string[]): Promise<void>;
116
+ setUndeleteableList(codeIds: Id[]): Promise<void>;
117
+ /**
118
+ * 设置代码草稿
119
+ */
120
+ setCodeDraft(codeId: Id, content: string): void;
121
+ /**
122
+ * 获取代码草稿
123
+ */
124
+ getCodeDraft(codeId: Id): string | null;
125
+ /**
126
+ * 删除代码草稿
127
+ */
128
+ removeCodeDraft(codeId: Id): void;
126
129
  /**
127
130
  * 在dsl数据源中删除指定id的代码块
128
- * @param {string[]} codeIds 需要删除的代码块id数组
131
+ * @param {Id[]} codeIds 需要删除的代码块id数组
129
132
  * @returns {CodeBlockDSL} 删除后的code dsl
130
133
  */
131
- deleteCodeDslByIds(codeIds: string[]): Promise<CodeBlockDSL>;
134
+ deleteCodeDslByIds(codeIds: Id[]): Promise<CodeBlockDSL>;
132
135
  /**
133
136
  * 生成代码块唯一id
134
- * @returns {string} 代码块唯一id
135
- */
136
- getUniqueId(): Promise<string>;
137
- /**
138
- * 一对一解除绑定关系 功能隐藏,暂时注释
139
- * @param {string} compId 组件id
140
- * @param {string} codeId 代码块id
141
- * @param {string[]} codeHooks 代码块挂载hook名称
142
- * @returns {boolean} 结果
137
+ * @returns {Id} 代码块唯一id
143
138
  */
139
+ getUniqueId(): Promise<Id>;
144
140
  /**
145
141
  * 通过组件id解除绑定关系(删除组件)
146
142
  * @param {MNode} compId 组件节点
147
143
  * @returns void
148
144
  */
149
145
  deleteCompsInRelation(node: MNode): Promise<void>;
146
+ resetState(): void;
150
147
  destroy(): void;
151
- private recurseNodes;
148
+ /**
149
+ * 删除组件时 如果是容器 需要遍历删除其包含节点的绑定信息
150
+ * @param {MNode} node 节点信息
151
+ * @param {CodeBlockDSL} codeDsl 代码块
152
+ * @returns void
153
+ */
154
+ private refreshRelationDeep;
155
+ /**
156
+ * 递归遍历dsl中挂载了代码块的节点,并更新绑定关系数据
157
+ * @param {MContainer} node 节点信息
158
+ * @returns void
159
+ */
160
+ private recurseMNode;
152
161
  }
153
162
  export declare type CodeBlockService = CodeBlock;
154
163
  declare const _default: CodeBlock;
@@ -8,6 +8,7 @@ declare class ComponentList extends BaseService {
8
8
  */
9
9
  setList(componentGroupList: ComponentGroup[]): void;
10
10
  getList(): ComponentGroup[];
11
+ resetState(): void;
11
12
  destroy(): void;
12
13
  }
13
14
  export declare type ComponentListService = ComponentList;
@@ -1,6 +1,5 @@
1
1
  import type { CodeBlockDSL, Id, MContainer, MNode } from '@tmagic/schema';
2
- import { StepValue } from '../services/history';
3
- import type { AddMNode, EditorNodeInfo, PastePosition, StoreState } from '../type';
2
+ import type { AddMNode, EditorNodeInfo, PastePosition, StepValue, StoreState, StoreStateKey } from '../type';
4
3
  import { LayerOffset, Layout } from '../type';
5
4
  import BaseService from './BaseService';
6
5
  declare class Editor extends BaseService {
@@ -9,17 +8,16 @@ declare class Editor extends BaseService {
9
8
  constructor();
10
9
  /**
11
10
  * 设置当前指点节点配置
12
- * @param name 'root' | 'page' | 'parent' | 'node' | 'highlightNode' | 'nodes'
11
+ * @param name 'root' | 'page' | 'parent' | 'node' | 'highlightNode' | 'nodes' | 'stage' | 'modifiedNodeIds' | 'pageLength'
13
12
  * @param value MNode
14
- * @returns MNode
15
13
  */
16
- set<T = MNode>(name: keyof StoreState, value: T): void;
14
+ set<K extends StoreStateKey, T extends StoreState[K]>(name: K, value: T): void;
17
15
  /**
18
16
  * 获取当前指点节点配置
19
- * @param name 'root' | 'page' | 'parent' | 'node' | 'highlightNode' | 'nodes'
17
+ * @param name 'root' | 'page' | 'parent' | 'node' | 'highlightNode' | 'nodes' | 'stage' | 'modifiedNodeIds' | 'pageLength'
20
18
  * @returns MNode
21
19
  */
22
- get<T = MNode>(name: keyof StoreState): T;
20
+ get<K extends StoreStateKey>(name: K): StoreState[K];
23
21
  /**
24
22
  * 根据id获取组件、组件的父组件以及组件所属的页面节点
25
23
  * @param {number | string} id 组件id
@@ -33,14 +31,14 @@ declare class Editor extends BaseService {
33
31
  * @param {boolean} raw 是否使用toRaw
34
32
  * @returns 组件节点配置
35
33
  */
36
- getNodeById(id: Id, raw?: boolean): MNode | undefined;
34
+ getNodeById(id: Id, raw?: boolean): MNode | null;
37
35
  /**
38
36
  * 根据ID获取指点节点的父节点配置
39
37
  * @param id 组件ID
40
38
  * @param {boolean} raw 是否使用toRaw
41
39
  * @returns 指点组件的父节点配置
42
40
  */
43
- getParentById(id: Id, raw?: boolean): MContainer | undefined;
41
+ getParentById(id: Id, raw?: boolean): MContainer | null;
44
42
  /**
45
43
  * 只有容器拥有布局
46
44
  */
@@ -51,7 +49,7 @@ declare class Editor extends BaseService {
51
49
  * @returns 当前选中的节点配置
52
50
  */
53
51
  select(config: MNode | Id): Promise<MNode> | never;
54
- selectNextNode(): Promise<MNode> | never;
52
+ selectNextNode(): Promise<MNode | null> | never;
55
53
  selectNextPage(): Promise<MNode> | never;
56
54
  /**
57
55
  * 高亮指定节点
@@ -77,7 +75,6 @@ declare class Editor extends BaseService {
77
75
  /**
78
76
  * 删除组件
79
77
  * @param {Object} node
80
- * @return {Object} 删除的组件配置
81
78
  */
82
79
  remove(nodeOrNodeList: MNode | MNode[]): Promise<void>;
83
80
  doUpdate(config: MNode): Promise<MNode>;
@@ -136,6 +133,7 @@ declare class Editor extends BaseService {
136
133
  */
137
134
  redo(): Promise<StepValue | null>;
138
135
  move(left: number, top: number): Promise<void>;
136
+ resetState(): void;
139
137
  destroy(): void;
140
138
  resetModifiedNodeId(): void;
141
139
  /**
@@ -143,6 +141,7 @@ declare class Editor extends BaseService {
143
141
  * @returns {CodeBlockDSL | null}
144
142
  */
145
143
  getCodeDsl(): Promise<CodeBlockDSL | null>;
144
+ getCodeDslSync(): CodeBlockDSL | null;
146
145
  /**
147
146
  * 设置代码块到dsl的codeBlocks字段
148
147
  * @param {CodeBlockDSL} codeDsl 代码DSL
@@ -10,6 +10,7 @@ declare class Events extends BaseService {
10
10
  setMethods(methods: Record<string, EventOption[]>): void;
11
11
  setMethod(type: string, method: EventOption[]): void;
12
12
  getMethod(type: string): EventOption[];
13
+ resetState(): void;
13
14
  destroy(): void;
14
15
  }
15
16
  export declare type EventsService = Events;
@@ -1,28 +1,18 @@
1
- import type { Id, MPage } from '@tmagic/schema';
1
+ import type { MPage } from '@tmagic/schema';
2
+ import { StepValue } from '../type';
2
3
  import { UndoRedo } from '../utils/undo-redo';
3
4
  import BaseService from './BaseService';
4
- export interface StepValue {
5
- data: MPage;
6
- modifiedNodeIds: Map<Id, Id>;
7
- nodeId: Id;
8
- }
9
- export interface HistoryState {
10
- pageId?: Id;
11
- pageSteps: Record<Id, UndoRedo<StepValue>>;
12
- canRedo: boolean;
13
- canUndo: boolean;
14
- }
15
5
  declare class History extends BaseService {
16
6
  state: {
17
- pageId?: Id | undefined;
18
- pageSteps: Record<Id, UndoRedo<StepValue>>;
7
+ pageId?: import("@tmagic/schema").Id | undefined;
8
+ pageSteps: Record<import("@tmagic/schema").Id, UndoRedo<StepValue>>;
19
9
  canRedo: boolean;
20
10
  canUndo: boolean;
21
11
  };
22
12
  constructor();
23
13
  reset(): void;
24
14
  changePage(page: MPage): void;
25
- empty(): void;
15
+ resetState(): void;
26
16
  push(state: StepValue): StepValue | null;
27
17
  undo(): StepValue | null;
28
18
  redo(): StepValue | null;
@@ -42,8 +42,8 @@ declare class Props extends BaseService {
42
42
  items: {
43
43
  name: string;
44
44
  text: string;
45
- type: string;
46
45
  labelWidth: string;
46
+ type: string;
47
47
  }[];
48
48
  labelWidth?: undefined;
49
49
  })[];
@@ -66,7 +66,7 @@ declare class Props extends BaseService {
66
66
  * @param type 组件类型
67
67
  * @param value 组件初始值
68
68
  */
69
- setPropsValue(type: string, value: MNode): void;
69
+ setPropsValue(type: string, value: MNode): Promise<void>;
70
70
  /**
71
71
  * 获取指定类型的组件初始值
72
72
  * @param type 组件类型
@@ -97,6 +97,7 @@ declare class Props extends BaseService {
97
97
  layout?: undefined;
98
98
  items?: undefined;
99
99
  }>;
100
+ resetState(): void;
100
101
  destroy(): void;
101
102
  /**
102
103
  * 生成指定位数的GUID,无【-】格式
@@ -1,33 +1,33 @@
1
1
  import type { UiState } from '../type';
2
2
  import BaseService from './BaseService';
3
- declare const state: {
4
- uiSelectMode: boolean;
5
- showSrc: boolean;
6
- zoom: number;
7
- stageContainerRect: {
8
- width: number;
9
- height: number;
10
- };
11
- stageRect: {
12
- width: number;
13
- height: number;
14
- };
15
- columnWidth: {
16
- left: number;
17
- center: number;
18
- right: number;
19
- };
20
- showGuides: boolean;
21
- showRule: boolean;
22
- propsPanelSize: "small" | "large" | "default";
23
- showAddPageButton: boolean;
24
- };
25
3
  declare class Ui extends BaseService {
26
4
  constructor();
27
- set<T = any>(name: keyof UiState, value: T): void;
28
- get<T>(name: keyof typeof state): T;
5
+ set<K extends keyof UiState, T extends UiState[K]>(name: K, value: T): void;
6
+ get<K extends keyof UiState>(name: K): {
7
+ uiSelectMode: boolean;
8
+ showSrc: boolean;
9
+ zoom: number;
10
+ stageContainerRect: {
11
+ width: number;
12
+ height: number;
13
+ };
14
+ stageRect: {
15
+ width: number;
16
+ height: number;
17
+ };
18
+ columnWidth: {
19
+ left: number;
20
+ center: number;
21
+ right: number;
22
+ };
23
+ showGuides: boolean;
24
+ showRule: boolean;
25
+ propsPanelSize: "small" | "default" | "large";
26
+ showAddPageButton: boolean;
27
+ }[K];
29
28
  zoom(zoom: number): Promise<void>;
30
29
  calcZoom(): Promise<number>;
30
+ resetState(): void;
31
31
  destroy(): void;
32
32
  private setStageRect;
33
33
  }
package/types/type.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { Component } from 'vue';
2
2
  import type { FormConfig } from '@tmagic/form';
3
- import type { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
3
+ import type { CodeBlockContent, CodeBlockDSL, Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
4
4
  import type StageCore from '@tmagic/stage';
5
- import type { ContainerHighlightType, MoveableOptions } from '@tmagic/stage';
5
+ import type { ContainerHighlightType, CustomizeMoveableOptionsCallbackConfig, MoveableOptions, UpdateDragEl } from '@tmagic/stage';
6
6
  import type { CodeBlockService } from './services/codeBlock';
7
7
  import type { ComponentListService } from './services/componentList';
8
8
  import type { EditorService } from './services/editor';
@@ -11,6 +11,7 @@ import type { HistoryService } from './services/history';
11
11
  import type { PropsService } from './services/props';
12
12
  import type { StorageService } from './services/storage';
13
13
  import type { UiService } from './services/ui';
14
+ import type { UndoRedo } from './utils/undo-redo';
14
15
  export declare type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> | MNode;
15
16
  export declare type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
16
17
  export interface InstallOptions {
@@ -32,11 +33,12 @@ export interface StageOptions {
32
33
  containerHighlightClassName: string;
33
34
  containerHighlightDuration: number;
34
35
  containerHighlightType: ContainerHighlightType;
35
- render: () => HTMLDivElement;
36
- moveableOptions: MoveableOptions | ((core?: StageCore) => MoveableOptions);
36
+ disabledDragStart?: boolean;
37
+ render: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
38
+ moveableOptions: MoveableOptions | ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions);
37
39
  canSelect: (el: HTMLElement) => boolean | Promise<boolean>;
38
40
  isContainer: (el: HTMLElement) => boolean | Promise<boolean>;
39
- updateDragEl: (el: HTMLDivElement) => void;
41
+ updateDragEl: UpdateDragEl;
40
42
  }
41
43
  export interface StoreState {
42
44
  root: MApp | null;
@@ -49,6 +51,7 @@ export interface StoreState {
49
51
  modifiedNodeIds: Map<Id, Id>;
50
52
  pageLength: number;
51
53
  }
54
+ export declare type StoreStateKey = keyof StoreState;
52
55
  export interface PropsState {
53
56
  propsConfigMap: Record<string, FormConfig>;
54
57
  propsValueMap: Record<string, MNode>;
@@ -98,9 +101,9 @@ export interface UiState {
98
101
  showAddPageButton: boolean;
99
102
  }
100
103
  export interface EditorNodeInfo {
101
- node?: MNode;
102
- parent?: MContainer;
103
- page?: MPage;
104
+ node: MNode | null;
105
+ parent: MContainer | null;
106
+ page: MPage | null;
104
107
  }
105
108
  export interface AddMNode {
106
109
  type: string;
@@ -128,18 +131,17 @@ export interface MenuButton {
128
131
  * 按钮类型
129
132
  * button: 只有文字不带边框的按钮
130
133
  * text: 纯文本
134
+ * divider: 分割线
131
135
  * dropdown: 下拉菜单
132
- * divider: 分隔线
133
- * zoom: 放大缩小
134
136
  */
135
- type: 'button' | 'dropdown' | 'text' | 'divider' | 'zoom';
137
+ type: 'button' | 'text' | 'divider' | 'dropdown';
136
138
  /** 当type为divider时有效,分割线方向, 默认vertical */
137
139
  direction?: 'horizontal' | 'vertical';
138
140
  /** 展示的文案 */
139
141
  text?: string;
140
142
  /** 鼠标悬浮是显示的气泡中的文案 */
141
143
  tooltip?: string;
142
- /** element-plus icon class */
144
+ /** Vue组件或url */
143
145
  icon?: string | Component<{}, {}, any>;
144
146
  /** 是否置灰,默认为false */
145
147
  disabled?: boolean | ((data?: Services) => boolean);
@@ -147,8 +149,8 @@ export interface MenuButton {
147
149
  display?: boolean | ((data?: Services) => boolean);
148
150
  /** type为button/dropdown时点击运行的方法 */
149
151
  handler?: (data: Services, event: MouseEvent) => Promise<any> | any;
150
- /** type为dropdown时,下拉的菜单列表, 或者有子菜单时 */
151
152
  className?: string;
153
+ /** type为dropdown时,下拉的菜单列表, 或者有子菜单时 */
152
154
  items?: MenuButton[];
153
155
  }
154
156
  export interface MenuComponent {
@@ -163,16 +165,22 @@ export interface MenuComponent {
163
165
  /** 是否显示,默认为true */
164
166
  className?: string;
165
167
  display?: boolean | ((data?: Services) => Promise<boolean> | boolean);
168
+ [key: string]: any;
166
169
  }
167
170
  /**
168
171
  * '/': 分隔符
169
172
  * 'delete': 删除按钮
170
173
  * 'undo': 撤销按钮
171
174
  * 'redo': 恢复按钮
175
+ * 'zoom': 'zoom-in', 'zoom-out', 'scale-to-original', 'scale-to-fit' 的集合
172
176
  * 'zoom-in': 放大按钮
173
177
  * 'zoom-out': 缩小按钮
178
+ * 'guides': 显示隐藏参考线
179
+ * 'rule': 显示隐藏标尺
180
+ * 'scale-to-original': 缩放到实际大小
181
+ * 'scale-to-fit': 缩放以适应
174
182
  */
175
- export declare type MenuItem = '/' | 'delete' | 'undo' | 'redo' | 'zoom' | 'zoom-in' | 'zoom-out' | 'guides' | 'rule' | MenuButton | MenuComponent | string;
183
+ export declare type MenuItem = '/' | 'delete' | 'undo' | 'redo' | 'zoom' | 'zoom-in' | 'zoom-out' | 'guides' | 'rule' | 'scale-to-original' | 'scale-to-fit' | MenuButton | MenuComponent | string;
176
184
  /** 工具栏 */
177
185
  export interface MenuBarData {
178
186
  /** 顶部工具栏左边项 */
@@ -185,12 +193,13 @@ export interface MenuBarData {
185
193
  export interface SideComponent extends MenuComponent {
186
194
  /** 显示文案 */
187
195
  text: string;
188
- /** element-plus icon class */
196
+ /** vue组件或url */
189
197
  icon: Component<{}, {}, any>;
190
198
  }
191
199
  /**
192
200
  * component-list: 组件列表
193
201
  * layer: 已选组件树
202
+ * code-block: 代码块
194
203
  */
195
204
  export declare type SideItem = 'component-list' | 'layer' | 'code-block' | SideComponent;
196
205
  /** 工具栏 */
@@ -207,8 +216,9 @@ export interface ComponentItem {
207
216
  text: string;
208
217
  /** 组件类型 */
209
218
  type: string;
210
- /** element-plus icon class */
211
- icon?: string | Component;
219
+ /** Vue组件或url */
220
+ icon?: string | Component<{}, {}, any>;
221
+ /** 新增组件时需要透传到组价节点上的数据 */
212
222
  data?: {
213
223
  [key: string]: any;
214
224
  };
@@ -245,65 +255,55 @@ export interface ScrollViewerEvent {
245
255
  scrollHeight: number;
246
256
  scrollWidth: number;
247
257
  }
248
- export interface CodeBlockDSL {
249
- [id: string]: CodeBlockContent;
250
- }
251
- export interface CodeBlockContent {
252
- /** 代码块名称 */
253
- name: string;
254
- /** 代码块内容 */
255
- content: string;
256
- /** 代码块与组件的绑定关系 */
257
- comps?: CodeRelation;
258
- /** 扩展字段 */
259
- [propName: string]: any;
260
- }
261
258
  export declare type CodeState = {
262
259
  /** 是否展示代码块编辑区 */
263
260
  isShowCodeEditor: boolean;
264
261
  /** 代码块DSL数据源 */
265
262
  codeDsl: CodeBlockDSL | null;
266
263
  /** 当前选中的代码块id */
267
- id: string;
264
+ id: Id;
268
265
  /** 代码块是否可编辑 */
269
266
  editable: boolean;
270
- /** 代码编辑面板的展示模式 */
271
- mode: CodeEditorMode;
272
267
  /** list模式下左侧展示的代码列表 */
273
268
  combineIds: string[];
274
269
  /** 为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除) */
275
- undeletableList: string[];
270
+ undeletableList: Id[];
271
+ /** 代码块和组件的绑定关系 */
272
+ relations: CodeRelation;
273
+ };
274
+ export declare type HookData = {
275
+ /** 代码块id */
276
+ codeId: Id;
277
+ /** 参数 */
278
+ params?: object;
276
279
  };
277
280
  export declare type CodeRelation = {
278
- /** 组件id:['created'] */
279
- [compId: string | number]: string[];
281
+ [codeId: Id]: {
282
+ /** 组件id:['created'] */
283
+ [compId: Id]: string[];
284
+ };
280
285
  };
281
- export declare enum CodeEditorMode {
282
- /** 左侧菜单,右侧代码 */
283
- LIST = "list",
284
- /** 全屏代码 */
285
- EDITOR = "editor"
286
- }
287
- export interface CodeDslList {
286
+ export interface CodeDslItem {
288
287
  /** 代码块id */
289
- id: string;
288
+ id: Id;
290
289
  /** 代码块名称 */
291
290
  name: string;
292
291
  /** 代码块函数内容 */
293
292
  codeBlockContent?: CodeBlockContent;
294
293
  /** 是否展示代码绑定关系 */
295
294
  showRelation?: boolean;
295
+ /** 代码块对应绑定的组件信息 */
296
+ combineInfo?: CombineInfo[];
297
+ }
298
+ export interface CombineInfo {
299
+ /** 组件id */
300
+ compId: Id;
301
+ /** 组件名称 */
302
+ compName: string;
296
303
  }
297
304
  export interface ListState {
298
305
  /** 代码块列表 */
299
- codeList: CodeDslList[];
300
- }
301
- export interface ListRelationState extends ListState {
302
- /** 与代码块绑定的组件id信息 */
303
- bindComps: {
304
- /** 代码块id : 组件信息 */
305
- [id: string]: MNode[];
306
- };
306
+ codeList: CodeDslItem[];
307
307
  }
308
308
  export declare enum CodeDeleteErrorType {
309
309
  /** 代码块存在于不可删除列表中 */
@@ -311,11 +311,22 @@ export declare enum CodeDeleteErrorType {
311
311
  /** 代码块存在绑定关系 */
312
312
  BIND = "bind"
313
313
  }
314
- export declare enum CodeSelectOp {
315
- /** 增加 */
316
- ADD = "add",
317
- /** 删除 */
318
- DELETE = "delete",
319
- /** 单选修改 */
320
- CHANGE = "change"
314
+ export declare const CODE_DRAFT_STORAGE_KEY = "magicCodeDraft";
315
+ export interface CodeParamStatement {
316
+ /** 参数名称 */
317
+ name: string;
318
+ /** 参数类型 */
319
+ type?: string;
320
+ [key: string]: any;
321
+ }
322
+ export interface StepValue {
323
+ data: MPage;
324
+ modifiedNodeIds: Map<Id, Id>;
325
+ nodeId: Id;
326
+ }
327
+ export interface HistoryState {
328
+ pageId?: Id;
329
+ pageSteps: Record<Id, UndoRedo<StepValue>>;
330
+ canRedo: boolean;
331
+ canUndo: boolean;
321
332
  }
@@ -45,3 +45,4 @@ export declare const fixNodeLeft: (config: MNode, parent: MContainer, doc?: Docu
45
45
  export declare const fixNodePosition: (config: MNode, parent: MContainer, stage: StageCore | null) => {
46
46
  [key: string]: any;
47
47
  } | undefined;
48
+ export declare const serializeConfig: (config: any) => string;
@@ -3,3 +3,4 @@ export * from './props';
3
3
  export * from './logger';
4
4
  export * from './editor';
5
5
  export * from './stage';
6
+ export * from './operator';
@@ -17,5 +17,5 @@ export declare const getPositionInContainer: (position: PastePosition | undefine
17
17
  left: number;
18
18
  top: number;
19
19
  };
20
- export declare const getAddParent: (node: MNode) => MContainer | undefined;
20
+ export declare const getAddParent: (node: MNode) => MContainer | null | undefined;
21
21
  export declare const getDefaultConfig: (addNode: AddMNode, parentNode: MContainer) => Promise<any>;
@@ -41,8 +41,8 @@ export declare const fillConfig: (config?: FormConfig) => {
41
41
  items: {
42
42
  name: string;
43
43
  text: string;
44
- type: string;
45
44
  labelWidth: string;
45
+ type: string;
46
46
  }[];
47
47
  labelWidth?: undefined;
48
48
  })[];