@cicctencent/low-code-simulate-base 0.0.0-stage → 1.1.10

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 (82) hide show
  1. package/README.md +1 -3
  2. package/__tests__/plugin.spec.ts +40 -0
  3. package/__tests__/utils.transform.test.ts +37 -0
  4. package/api-extractor.json +36 -0
  5. package/build/md.js +25 -0
  6. package/dist/VCComponent.d.ts +5 -0
  7. package/dist/VCComponent.js +91 -0
  8. package/dist/domain/BaseProjectDomain.d.ts +389 -0
  9. package/dist/domain/BaseProjectDomain.js +1305 -0
  10. package/dist/domain/ComponentManager.d.ts +78 -0
  11. package/dist/domain/ComponentManager.js +293 -0
  12. package/dist/domain/DataHistoryDomain.d.ts +53 -0
  13. package/dist/domain/DataHistoryDomain.js +110 -0
  14. package/dist/domain/PreviewDomain.d.ts +208 -0
  15. package/dist/domain/PreviewDomain.js +490 -0
  16. package/dist/domain/ProjectDomain.d.ts +209 -0
  17. package/dist/domain/ProjectDomain.js +138 -0
  18. package/dist/event/generateEventHandler.d.ts +21 -0
  19. package/dist/event/generateEventHandler.js +218 -0
  20. package/dist/event/generateEventSchema.d.ts +123 -0
  21. package/dist/event/generateEventSchema.js +342 -0
  22. package/dist/event/register.d.ts +56 -0
  23. package/dist/event/register.js +207 -0
  24. package/dist/index.d.ts +1369 -0
  25. package/dist/index.js +28 -0
  26. package/dist/plugin/onH5PageValidate.d.ts +7 -0
  27. package/dist/plugin/onH5PageValidate.js +178 -0
  28. package/dist/plugin/onPlaceholder.d.ts +6 -0
  29. package/dist/plugin/onPlaceholder.js +68 -0
  30. package/dist/plugin/subscribeInsertUploadList.d.ts +6 -0
  31. package/dist/plugin/subscribeInsertUploadList.js +49 -0
  32. package/dist/plugin/subscribeSetTitle.d.ts +6 -0
  33. package/dist/plugin/subscribeSetTitle.js +16 -0
  34. package/dist/plugin/subscribeTransformComponentMeta.d.ts +14 -0
  35. package/dist/plugin/subscribeTransformComponentMeta.js +31 -0
  36. package/dist/plugin/subscribeValidateField.d.ts +7 -0
  37. package/dist/plugin/subscribeValidateField.js +57 -0
  38. package/dist/plugin/subscribeValidateUpload.d.ts +6 -0
  39. package/dist/plugin/subscribeValidateUpload.js +92 -0
  40. package/dist/utils/base64.d.ts +14 -0
  41. package/dist/utils/base64.js +14 -0
  42. package/dist/utils/buildInVariable.d.ts +61 -0
  43. package/dist/utils/buildInVariable.js +216 -0
  44. package/dist/utils/dom.d.ts +14 -0
  45. package/dist/utils/dom.js +19 -0
  46. package/dist/utils/index.d.ts +55 -0
  47. package/dist/utils/index.js +201 -0
  48. package/dist/utils/transform.d.ts +39 -0
  49. package/dist/utils/transform.js +191 -0
  50. package/dist/utils/validate.d.ts +7 -0
  51. package/dist/utils/validate.js +18 -0
  52. package/docs/.api/low-code-simulate-base.api.json +8450 -0
  53. package/jest.config.ts +20 -0
  54. package/package.json +45 -4
  55. package/src/VCComponent.ts +118 -0
  56. package/src/domain/BaseProjectDomain.ts +1341 -0
  57. package/src/domain/ComponentManager.ts +241 -0
  58. package/src/domain/DataHistoryDomain.ts +102 -0
  59. package/src/domain/PreviewDomain.ts +424 -0
  60. package/src/domain/ProjectDomain.ts +244 -0
  61. package/src/event/generateEventHandler.ts +162 -0
  62. package/src/event/generateEventSchema.ts +371 -0
  63. package/src/event/register.ts +181 -0
  64. package/src/index.ts +61 -0
  65. package/src/plugin/onH5PageValidate.ts +179 -0
  66. package/src/plugin/onPlaceholder.ts +71 -0
  67. package/src/plugin/subscribeInsertUploadList.ts +51 -0
  68. package/src/plugin/subscribeSetTitle.ts +18 -0
  69. package/src/plugin/subscribeTransformComponentMeta.ts +38 -0
  70. package/src/plugin/subscribeValidateField.ts +65 -0
  71. package/src/plugin/subscribeValidateUpload.ts +116 -0
  72. package/src/utils/base64.ts +17 -0
  73. package/src/utils/buildInVariable.ts +157 -0
  74. package/src/utils/dom.ts +30 -0
  75. package/src/utils/index.ts +194 -0
  76. package/src/utils/transform.ts +171 -0
  77. package/src/utils/validate.ts +19 -0
  78. package/temp/low-code-simulate-base.api.md +597 -0
  79. package/test/plugin.test.ts +4 -0
  80. package/tsconfig.build.json +9 -0
  81. package/tsconfig.json +9 -0
  82. package/tsconfig.test.json +14 -0
@@ -0,0 +1,424 @@
1
+ // 模拟器预览实体
2
+ import {
3
+ log,
4
+ error,
5
+ Entity,
6
+ cloneDeep,
7
+ isEqual,
8
+ toPlainObject,
9
+ } from '@cicctencent/ark-util';
10
+ import { Communicator } from '@cicctencent/postmessage-channel';
11
+
12
+ import type {
13
+ EditorConfig,
14
+ Project,
15
+ MenuData,
16
+ ComponentItem,
17
+ CheckRequestItem,
18
+ History,
19
+ } from '@cicctencent/low-code-core';
20
+ import { ComponentType } from '@cicctencent/low-code-core';
21
+ import ProjectDomain from './ProjectDomain';
22
+ import DataHistoryDomain from './DataHistoryDomain';
23
+
24
+ const logTag = '[low-code-preview PreviewDomain]';
25
+ const logInfo = log(logTag);
26
+ const logError = error(logTag);
27
+
28
+
29
+ /**
30
+ * @public
31
+ */
32
+ export interface PreviewDomainState<T = ProjectDomain> {
33
+ project: T; // 项目数据
34
+ communicator: Communicator; // 用于和模拟器通讯的通讯器
35
+ }
36
+
37
+ /**
38
+ * @public
39
+ */
40
+ export default class PreviewDomain extends Entity<PreviewDomainState> {
41
+
42
+
43
+ history: DataHistoryDomain<History>;
44
+
45
+ /**
46
+ * @public
47
+ * @param state - 初始化数据
48
+ */
49
+ constructor(state: PreviewDomainState) {
50
+ super(state);
51
+ this.state = state;
52
+ this.history = new DataHistoryDomain<History>();
53
+ Object.entries(this.subscribe).forEach(([key, value]) => {
54
+ this.state.communicator.subscribe(key, value.bind(this));
55
+ });
56
+ // 发送到编辑器
57
+ this.projectDomain.on('emitEditor', (cmd: string, ...params: any[]) => {
58
+ this.publish[cmd]
59
+ ? this.publish[cmd](...params)
60
+ : this.commit(cmd, params?.[0]);
61
+ });
62
+ // 发送到Preview
63
+ this.projectDomain.on('emitPreview', this.emit.bind(this));
64
+ this.projectDomain.on('updateHistory', this.updateHistory.bind(this));
65
+ }
66
+
67
+ /**
68
+ * @public
69
+ */
70
+ updateHistory() {
71
+ this.history.update(this.projectState);
72
+ this.emit('updateProject', this.projectDomain);
73
+ this.publish.update();
74
+ }
75
+
76
+ /**
77
+ * @public
78
+ */
79
+ get projectDomain() {
80
+ return this.state.project;
81
+ }
82
+
83
+ /**
84
+ * @public
85
+ */
86
+ get projectState() {
87
+ const { meta, pages } = this.projectData;
88
+ return {
89
+ projectData: {
90
+ meta: meta,
91
+ pages: pages,
92
+ }, currentComponentPath: this.projectDomain.currentComponentPath
93
+ };
94
+ }
95
+
96
+ /**
97
+ * @public
98
+ * 添加历史记录
99
+ */
100
+ addHistory() {
101
+ const currentProject = this.history.data || {};
102
+ const projectState = this.projectState;
103
+ // 获取组件信息
104
+ if (currentProject.currentComponentPath === projectState.currentComponentPath) {
105
+ const value = this.projectDomain.needUpdateHistory(currentProject);
106
+ // 如果返回true,表示更新历史记录,不新增
107
+ if (value) {
108
+ try {
109
+ // 通知模拟器更新project数据
110
+ this.emit('updateProject', this.projectDomain);
111
+ // 通知编辑器更新config和project数据 config会改变两次
112
+ this.publish.update();
113
+ } catch (e) {
114
+ console.error(e);
115
+ }
116
+ return;
117
+ }
118
+ }
119
+ if (this.history.add(projectState)) {
120
+ try {
121
+ // 通知模拟器更新project数据
122
+ this.emit('updateProject', this.projectDomain);
123
+ // 通知编辑器更新config和project数据 config会改变两次
124
+ this.publish.update();
125
+ } catch (e) {
126
+ console.error(e);
127
+ }
128
+ this.activate();
129
+ }
130
+ }
131
+
132
+ /**
133
+ * @public
134
+ * 编辑器展示配置
135
+ */
136
+ get config(): EditorConfig {
137
+ const { config } = this.projectDomain;
138
+ const { functionData } = config;
139
+ if (functionData) {
140
+ // 设置撤销重做是否可点击
141
+ if (functionData.undo) {
142
+ functionData.undo.clickable = this.history.canUndo;
143
+ }
144
+
145
+ if (functionData.redo) {
146
+ functionData.redo.clickable = this.history.canRedo;
147
+ }
148
+ }
149
+
150
+ return config;
151
+ }
152
+
153
+ /**
154
+ * @public
155
+ * 获取项目数据
156
+ */
157
+ get projectData(): Project {
158
+ return this.projectDomain.state.project;
159
+ }
160
+
161
+ /**
162
+ * @public
163
+ * 更新激活状态。由于激活状态与历史记录变化关联度比较大,收敛到这里
164
+ * @param path - 路径
165
+ */
166
+ activate(path?: string) {
167
+ const { project } = this.state
168
+ if (path) {
169
+ // 提供给外部用
170
+ project.activate({ path });
171
+ this.publish.update();
172
+ }
173
+ // 通知模拟器
174
+ this.emit('activate', project.currentComponent?.componentId);
175
+ }
176
+
177
+ /**
178
+ * @public
179
+ */
180
+ subscribe = {
181
+ /**
182
+ * @public
183
+ * @param param0 - 从模拟器发送过来的数据
184
+ * @returns
185
+ */
186
+ init: ({ data: project }) => {
187
+ if (!isEqual(this.projectData, project)) {
188
+ // 空数据或者与旧数据相同,则不处理
189
+ logInfo('init', project);
190
+ this.projectDomain.setProject(project);
191
+ // 通知模拟器更新project数据
192
+ this.emit('updateProject', this.projectDomain);
193
+ // 通知编辑器更新config和project数据 config会改变两次
194
+ this.publish.update();
195
+ }
196
+ this.history.reset();
197
+ this.addHistory();
198
+ return toPlainObject(this.config);
199
+
200
+ },
201
+ /**
202
+ * @public
203
+ * @param param0 - 从模拟器发送过来的数据
204
+ * @returns
205
+ */
206
+ click: ({ data: { key, value } }) => {
207
+ logInfo('click', key, value, key);
208
+ if (['undo', 'redo'].includes(key.action)) {
209
+ this.function[key.action](key);
210
+ // 不新增记录
211
+ return toPlainObject(this.config);
212
+ } else if (key.module === 'function' && this.function[key.action]) {
213
+ this.function[key.action]({ key, value });
214
+ } else if (key.action in this.projectDomain) {
215
+ this.projectDomain[key.action](key, value);
216
+ } else {
217
+ return null;
218
+ }
219
+ this.addHistory(); // addHistory 会触发更新,这里就不用返回数据了。降低通讯成本
220
+ },
221
+ /**
222
+ * @public
223
+ * @param param0 - 从模拟器发送过来的数据
224
+ */
225
+ drag: ({ data: { key, value } }) => {
226
+ this.projectDomain.componentDrag(key, value);
227
+ this.addHistory();
228
+ },
229
+ /**
230
+ * @public
231
+ * @param param0 - 从模拟器发送过来的数据
232
+ */
233
+ set: ({ data: { key, value } }) => {
234
+ logInfo('set', key, value);
235
+ this.projectDomain[key.action](key.path, value);
236
+ this.addHistory(); // addHistory 会触发更新,这里就不用返回数据了
237
+ },
238
+ /**
239
+ * @public
240
+ * @param param0 - 从模拟器发送过来的数据
241
+ * @returns
242
+ */
243
+ contextmenu: ({ data: { key } }): MenuData => {
244
+ let menus = [];
245
+ try {
246
+ this.projectDomain.activate(key);
247
+ menus = this.projectDomain.menuData;
248
+ this.activate();
249
+ } catch (e) {
250
+ logError(e);
251
+ }
252
+ return toPlainObject({
253
+ config: this.config,
254
+ menus,
255
+ });
256
+ },
257
+ /**
258
+ * @public
259
+ * 校验
260
+ */
261
+ validate: async ({ data }): Promise<CheckRequestItem[]> => {
262
+ // 发布时校验所有组件表单数据。模拟器校验数据不通过,可以给编辑器发模态框或toast
263
+ const result = await this.send('validatePage', data);
264
+ logInfo('validate result', result, this.config);
265
+ return toPlainObject({ config: this.config, result });
266
+ },
267
+ /**
268
+ * @public
269
+ * 导航树移动组件
270
+ */
271
+ splice: ({ data }) => {
272
+ logInfo('splice', data);
273
+ const { draggingNode, dropNode, dropType } = data;
274
+ let curentDropNodePath = dropNode.key.path;
275
+ if (dropType === 'inner' && dropNode.type === ComponentType.Container) {
276
+ curentDropNodePath = `${curentDropNodePath}.children.0`;
277
+ }
278
+ this.projectDomain.moveTo(draggingNode.key.path, curentDropNodePath);
279
+ this.addHistory(); // addHistory 会触发更新,这里就不用返回数据了
280
+ },
281
+ /**
282
+ * @public
283
+ * @param param0 - 从模拟器发送过来的数据
284
+ */
285
+ action: ({ data: { action, value } }) => {
286
+ logInfo('action', action, value);
287
+ this.projectDomain.action(action, value);
288
+ this.addHistory(); // addHistory 会触发更新,这里就不用返回数据了。降低通讯成本
289
+ }
290
+ };
291
+
292
+
293
+
294
+ /**
295
+ * @public
296
+ * @param cmd - 命令字
297
+ * @param payload - 发送给模拟器的内容
298
+ * @returns
299
+ */
300
+ async commit(cmd, payload) {
301
+ logInfo('publish begin', cmd, payload);
302
+ const { data } = await this.state.communicator.publish(
303
+ cmd,
304
+ toPlainObject(payload)
305
+ );
306
+ logInfo('publish end', cmd, payload, data);
307
+ return data;
308
+ }
309
+ /**
310
+ * @public
311
+ */
312
+ publish = {
313
+ /**
314
+ * @public
315
+ * 在加载完时,告诉编辑器
316
+ * @returns
317
+ */
318
+ load: () => this.commit('load', this.config),
319
+ /**
320
+ * @public
321
+ * 调用编辑器的交互方法,如让编辑器弹出toast等
322
+ * @param data - 发送给模拟器的内容
323
+ * @returns
324
+ */
325
+ action: (data: { key: string; value: any }) => this.commit('action', data),
326
+ /**
327
+ * @public
328
+ * 如果project发生变化,则需update通知编辑器
329
+ * @param forceUpdate - 是否强制更新
330
+ */
331
+ update: (forceUpdate = false) => {
332
+ try {
333
+ this.commit('update', {
334
+ config: this.config,
335
+ project: this.projectData,
336
+ forceUpdate,
337
+ });
338
+ } catch (err) {
339
+ console.error(err);
340
+ }
341
+ },
342
+ /**
343
+ * @public
344
+ * @param imgUrl - 图片url
345
+ */
346
+ updateScreenShot: (imgUrl: string) => {
347
+ this.commit('updateScreenShot', imgUrl);
348
+ },
349
+ };
350
+
351
+ /**
352
+ * @public
353
+ * @param currentProject - 当前项目信息
354
+ */
355
+ replaceProject(currentProject: History) {
356
+ try {
357
+ this.projectDomain.replaceProject(currentProject);
358
+
359
+ // 通知模拟器更新project数据
360
+ this.emit('updateProject', this.projectDomain);
361
+ this.commit('update', {
362
+ config: this.config,
363
+ project: currentProject?.projectData,
364
+ forceUpdate: true,
365
+ });
366
+ this.activate();
367
+ } catch (e) {
368
+ console.error(e);
369
+ }
370
+ }
371
+ /**
372
+ * @public
373
+ */
374
+ function = {
375
+ /**
376
+ * @public
377
+ */
378
+ simulatorSizeList: ({ key, value }) => {
379
+ this.projectDomain.setProjectMeta(value);
380
+ },
381
+ /**
382
+ * @public
383
+ */
384
+ title: () => {
385
+ this.publish.action(toPlainObject({ key: 'editTitle' }));
386
+ },
387
+ /**
388
+ * @public
389
+ */
390
+ undo: (): void => {
391
+ const data = this.history.undo();
392
+ if (data) {
393
+ this.replaceProject(cloneDeep(data));
394
+ }
395
+ },
396
+ /**
397
+ * @public
398
+ */
399
+ redo: (): void => {
400
+ const data = this.history.redo();
401
+ if (data) {
402
+ this.replaceProject(cloneDeep(data));
403
+ }
404
+ },
405
+ };
406
+
407
+ // subscribe.init 模拟器接收编辑器传过来的初始化数据,此时初始化history
408
+ // subscribe.click 处理编辑器元素被点击的行为,根据key,分发到function等方法进行处理。如果是添加组件等,则调用project相关方法进行处理
409
+ // subscribe.drag 计算出需要插入的位置,调用project.componentDrag处理
410
+ // subscribe.set 设置组件数据,project.config处理
411
+ // subscribe.contextmenu 返回右键菜单数据
412
+ // subscribe.validate 调用project.validate检查数据的正确性,如果不正确,则调用pushlish.action告诉编辑器。
413
+ // subscribe.updateScreenShot 返回页面dom截图
414
+ // subscribe.insert 调用project.componentInsert处理
415
+ // subscribe.validateUpload 文件上传校验
416
+ // pushlish.transformComponentMeta 转换组件元信息
417
+ // pushlish.load 在加载完时,告诉编辑器
418
+ // pushlish.action 调用编辑器的交互方法,如让编辑器弹出toast等
419
+ // pushlish.update 如果project发生变化,则需update通知编辑器
420
+
421
+ // function.undo 撤销
422
+ // function.redo 重做
423
+ // function.simulator 模拟器尺寸调整,调用project.config处理
424
+ }
@@ -0,0 +1,244 @@
1
+ import { Entity, get, set } from '@cicctencent/ark-util';
2
+ import type {
3
+ Project,
4
+ GroupTree,
5
+ LowCodeKey,
6
+ Component,
7
+ FunctionData,
8
+ FunctionConfig,
9
+ EditorConfig,
10
+ ComponentItem,
11
+ History,
12
+ } from '@cicctencent/low-code-core';
13
+ import { ProjectDomainState } from './BaseProjectDomain';
14
+
15
+ /**
16
+ * @public
17
+ */
18
+ export const navTreeKey = { module: 'navTree' };
19
+ /**
20
+ * @public
21
+ */
22
+ export const componentTreeKey = { module: 'componentTree' };
23
+
24
+ /**
25
+ * @public
26
+ */
27
+ export interface SpliceState {
28
+ draggingNode: Component;
29
+ dropNode: Component;
30
+ dropType: 'after' | 'before';
31
+ }
32
+ /**
33
+ * @public
34
+ */
35
+ export interface InsertUploadData {
36
+ /* 需填入prop的key */
37
+ key: string;
38
+ /* 组件名 */
39
+ name: string;
40
+ /* 上传素材url列表 */
41
+ list: string[];
42
+ }
43
+
44
+ /**
45
+ * @public
46
+ * 项目实体是与业务有关的 每个业务可以有自己的数据结构
47
+ * 项目可能有多个页面 每个页面有自己的组件列表 但当前最多只会有一个页面或一个组件处于选中状态
48
+ */
49
+ export default abstract class ProjectDomain extends Entity<any> {
50
+ /**
51
+ * 当前编辑页面索引
52
+ * @public
53
+ */
54
+ abstract currentPageIndex: number;
55
+ /**
56
+ * 当前编辑组件索引路径
57
+ * @public
58
+ */
59
+ abstract currentComponentPath: string;
60
+ /**
61
+ * @public
62
+ */
63
+ declare state: ProjectDomainState;
64
+
65
+ /**
66
+ * 项目名称
67
+ * @public
68
+ */
69
+ abstract get title(): string;
70
+ /**
71
+ * config.navTreeData 导航树配置
72
+ * @public
73
+ */
74
+ abstract get navTreeData(): any;
75
+ /**
76
+ * config.componentTreeData 组件库配置
77
+ * @public
78
+ */
79
+ abstract get componentTreeData(): any;
80
+ /**
81
+ * config.schemaData 表单配置
82
+ *
83
+ * @public
84
+ */
85
+ abstract get schemaData(): any;
86
+ /**
87
+ * 菜单数据
88
+ * @public
89
+ */
90
+ abstract get menuData(): any;
91
+ /**
92
+ * 当前组件配置
93
+ * @public
94
+ */
95
+ abstract get currentComponent(): any;
96
+ /**
97
+ * 获取functionData
98
+ * @public
99
+ */
100
+ abstract get functionData(): FunctionData;
101
+ /**
102
+ * 替换project数据 undo,redo
103
+ * @public
104
+ * @param store - History数据
105
+ */
106
+ abstract replaceProject(store: History): void;
107
+
108
+ /**
109
+ * 项目的所有页面
110
+ * @public
111
+ */
112
+ abstract get pages(): any;
113
+ /**
114
+ * 扩展信息
115
+ * @public
116
+ * @deprecated 减少使用
117
+ */
118
+ get extend(): Record<string, any> {
119
+ return {};
120
+ };
121
+ /**
122
+ * @public
123
+ */
124
+ abstract get config(): EditorConfig;
125
+ /**
126
+ * Action
127
+ * @public
128
+ * @param name - 组件名
129
+ */
130
+ abstract action(name: string, data: any): void;
131
+
132
+ /**
133
+ * 设置项目数据
134
+ * @public
135
+ * @param project - 项目数据
136
+ */
137
+ abstract setProject(project: any): void;
138
+ /**
139
+ * 移动组件到某个位置
140
+ * @public
141
+ * @param originPath - 原路径
142
+ * @param newPath - 目标路径
143
+ * @example
144
+ * moveTo('0.components.0.list.0', '0.components.0.list.1')
145
+ */
146
+ abstract moveTo(originPath, newPath): void;
147
+ /**
148
+ * 生成componentPath
149
+ * @public
150
+ * @param flagKey - 根据该字段找到组件
151
+ */
152
+ abstract generateComponentPath(flagKey: any, ...args: any[]): string;
153
+
154
+ /**
155
+ * 是更新还是插入历史栈,true表示更新,false表示插入(影响撤销、重做栈)
156
+ * @public
157
+ */
158
+ abstract needUpdateHistory(project: any): boolean;
159
+
160
+ /**
161
+ * 激活。比如点击了导航树或者某个组件,currentPageIndex或currentComponentPath需要变化
162
+ * @public
163
+ */
164
+ abstract activate(key: Partial<LowCodeKey>): void;
165
+
166
+ /**
167
+ * 删除组件
168
+ * @public
169
+ */
170
+ abstract componentDelete(key: LowCodeKey): void;
171
+
172
+ /**
173
+ * 复制组件
174
+ * @public
175
+ */
176
+ abstract componentCopy(key: LowCodeKey): void;
177
+ /**
178
+ * 处理通过拖拽方式插入的组件
179
+ * @public
180
+ */
181
+ abstract componentDrag(key: LowCodeKey, value: any): void;
182
+ /**
183
+ * 插入组件
184
+ * @public
185
+ */
186
+ abstract componentInsert(value: any): void;
187
+
188
+ /**
189
+ * 上移组件
190
+ * @public
191
+ */
192
+ abstract componentMoveUp(key: LowCodeKey): void;
193
+ /**
194
+ * 下移组件
195
+ * @public
196
+ */
197
+ abstract componentMoveDown(key: LowCodeKey): void;
198
+
199
+ /**
200
+ * @public
201
+ * 设置projectMeta数据,项目宽高等
202
+ */
203
+ setProjectMeta(value) {
204
+ this.state.project.meta = { ...this.state.project.meta, ...value };
205
+ }
206
+ /**
207
+ * @public
208
+ * 根据componentPath获取组件数据
209
+ */
210
+ pathToData(path: string, pages?: any): ComponentItem | any {
211
+ return path ? get(pages || this.state.project.pages, path) : null;
212
+ }
213
+ /**
214
+ * @public
215
+ * @param path - 组件路径
216
+ * @param value - 数据
217
+ * @returns
218
+ */
219
+ setPathData(path: string, value: Record<string, any>) {
220
+ const data = this.pathToData(path);
221
+ return set(this.pages, path, { ...data, ...value });
222
+ }
223
+ /**
224
+ * 通知编辑器
225
+ * @param cmd - 模拟器推送给编辑器的事件名
226
+ * @param params - 事件传递的参数
227
+ * @deprecated 减少使用
228
+ * @public
229
+ */
230
+
231
+ publishEditor(cmd: string, ...params: any[]): void {
232
+ this.emit('emitEditor', cmd, ...params);
233
+ }
234
+ /**
235
+ * 通知模拟器
236
+ * @param cmd - 模拟器通知模拟器视图的事件名
237
+ * @param params - 事件传递的参数
238
+ * @deprecated 减少使用
239
+ * @public
240
+ */
241
+ publishPreview(cmd: string, ...params: any[]): void {
242
+ this.emit('emitPreview', cmd, ...params);
243
+ }
244
+ }