@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,208 @@
1
+ import { Entity } from '@cicctencent/ark-util';
2
+ import { Communicator } from '@cicctencent/postmessage-channel';
3
+ import type { EditorConfig, Project, MenuData, CheckRequestItem, History } from '@cicctencent/low-code-core';
4
+ import ProjectDomain from './ProjectDomain';
5
+ import DataHistoryDomain from './DataHistoryDomain';
6
+ /**
7
+ * @public
8
+ */
9
+ export interface PreviewDomainState<T = ProjectDomain> {
10
+ project: T;
11
+ communicator: Communicator;
12
+ }
13
+ /**
14
+ * @public
15
+ */
16
+ export default class PreviewDomain extends Entity<PreviewDomainState> {
17
+ history: DataHistoryDomain<History>;
18
+ /**
19
+ * @public
20
+ * @param state - 初始化数据
21
+ */
22
+ constructor(state: PreviewDomainState);
23
+ /**
24
+ * @public
25
+ */
26
+ updateHistory(): void;
27
+ /**
28
+ * @public
29
+ */
30
+ get projectDomain(): ProjectDomain;
31
+ /**
32
+ * @public
33
+ */
34
+ get projectState(): {
35
+ projectData: {
36
+ meta: import("@cicctencent/low-code-core").ProjectMeta;
37
+ pages: import("@cicctencent/low-code-core").ProjectData;
38
+ };
39
+ currentComponentPath: string;
40
+ };
41
+ /**
42
+ * @public
43
+ * 添加历史记录
44
+ */
45
+ addHistory(): void;
46
+ /**
47
+ * @public
48
+ * 编辑器展示配置
49
+ */
50
+ get config(): EditorConfig;
51
+ /**
52
+ * @public
53
+ * 获取项目数据
54
+ */
55
+ get projectData(): Project;
56
+ /**
57
+ * @public
58
+ * 更新激活状态。由于激活状态与历史记录变化关联度比较大,收敛到这里
59
+ * @param path - 路径
60
+ */
61
+ activate(path?: string): void;
62
+ /**
63
+ * @public
64
+ */
65
+ subscribe: {
66
+ /**
67
+ * @public
68
+ * @param param0 - 从模拟器发送过来的数据
69
+ * @returns
70
+ */
71
+ init: ({ data: project }: {
72
+ data: any;
73
+ }) => any;
74
+ /**
75
+ * @public
76
+ * @param param0 - 从模拟器发送过来的数据
77
+ * @returns
78
+ */
79
+ click: ({ data: { key, value } }: {
80
+ data: {
81
+ key: any;
82
+ value: any;
83
+ };
84
+ }) => any;
85
+ /**
86
+ * @public
87
+ * @param param0 - 从模拟器发送过来的数据
88
+ */
89
+ drag: ({ data: { key, value } }: {
90
+ data: {
91
+ key: any;
92
+ value: any;
93
+ };
94
+ }) => void;
95
+ /**
96
+ * @public
97
+ * @param param0 - 从模拟器发送过来的数据
98
+ */
99
+ set: ({ data: { key, value } }: {
100
+ data: {
101
+ key: any;
102
+ value: any;
103
+ };
104
+ }) => void;
105
+ /**
106
+ * @public
107
+ * @param param0 - 从模拟器发送过来的数据
108
+ * @returns
109
+ */
110
+ contextmenu: ({ data: { key } }: {
111
+ data: {
112
+ key: any;
113
+ };
114
+ }) => MenuData;
115
+ /**
116
+ * @public
117
+ * 校验
118
+ */
119
+ validate: ({ data }: {
120
+ data: any;
121
+ }) => Promise<CheckRequestItem[]>;
122
+ /**
123
+ * @public
124
+ * 导航树移动组件
125
+ */
126
+ splice: ({ data }: {
127
+ data: any;
128
+ }) => void;
129
+ /**
130
+ * @public
131
+ * @param param0 - 从模拟器发送过来的数据
132
+ */
133
+ action: ({ data: { action, value } }: {
134
+ data: {
135
+ action: any;
136
+ value: any;
137
+ };
138
+ }) => void;
139
+ };
140
+ /**
141
+ * @public
142
+ * @param cmd - 命令字
143
+ * @param payload - 发送给模拟器的内容
144
+ * @returns
145
+ */
146
+ commit(cmd: any, payload: any): Promise<Record<string, any>>;
147
+ /**
148
+ * @public
149
+ */
150
+ publish: {
151
+ /**
152
+ * @public
153
+ * 在加载完时,告诉编辑器
154
+ * @returns
155
+ */
156
+ load: () => Promise<Record<string, any>>;
157
+ /**
158
+ * @public
159
+ * 调用编辑器的交互方法,如让编辑器弹出toast等
160
+ * @param data - 发送给模拟器的内容
161
+ * @returns
162
+ */
163
+ action: (data: {
164
+ key: string;
165
+ value: any;
166
+ }) => Promise<Record<string, any>>;
167
+ /**
168
+ * @public
169
+ * 如果project发生变化,则需update通知编辑器
170
+ * @param forceUpdate - 是否强制更新
171
+ */
172
+ update: (forceUpdate?: boolean) => void;
173
+ /**
174
+ * @public
175
+ * @param imgUrl - 图片url
176
+ */
177
+ updateScreenShot: (imgUrl: string) => void;
178
+ };
179
+ /**
180
+ * @public
181
+ * @param currentProject - 当前项目信息
182
+ */
183
+ replaceProject(currentProject: History): void;
184
+ /**
185
+ * @public
186
+ */
187
+ function: {
188
+ /**
189
+ * @public
190
+ */
191
+ simulatorSizeList: ({ key, value }: {
192
+ key: any;
193
+ value: any;
194
+ }) => void;
195
+ /**
196
+ * @public
197
+ */
198
+ title: () => void;
199
+ /**
200
+ * @public
201
+ */
202
+ undo: () => void;
203
+ /**
204
+ * @public
205
+ */
206
+ redo: () => void;
207
+ };
208
+ }
@@ -0,0 +1,490 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
27
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ var __read = (this && this.__read) || function (o, n) {
53
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
54
+ if (!m) return o;
55
+ var i = m.call(o), r, ar = [], e;
56
+ try {
57
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
58
+ }
59
+ catch (error) { e = { error: error }; }
60
+ finally {
61
+ try {
62
+ if (r && !r.done && (m = i["return"])) m.call(i);
63
+ }
64
+ finally { if (e) throw e.error; }
65
+ }
66
+ return ar;
67
+ };
68
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
69
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
70
+ if (ar || !(i in from)) {
71
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
72
+ ar[i] = from[i];
73
+ }
74
+ }
75
+ return to.concat(ar || Array.prototype.slice.call(from));
76
+ };
77
+ // 模拟器预览实体
78
+ import { log, error, Entity, cloneDeep, isEqual, toPlainObject, } from '@cicctencent/ark-util';
79
+ import { ComponentType } from '@cicctencent/low-code-core';
80
+ import DataHistoryDomain from './DataHistoryDomain';
81
+ var logTag = '[low-code-preview PreviewDomain]';
82
+ var logInfo = log(logTag);
83
+ var logError = error(logTag);
84
+ /**
85
+ * @public
86
+ */
87
+ var PreviewDomain = /** @class */ (function (_super) {
88
+ __extends(PreviewDomain, _super);
89
+ /**
90
+ * @public
91
+ * @param state - 初始化数据
92
+ */
93
+ function PreviewDomain(state) {
94
+ var _this = _super.call(this, state) || this;
95
+ /**
96
+ * @public
97
+ */
98
+ _this.subscribe = {
99
+ /**
100
+ * @public
101
+ * @param param0 - 从模拟器发送过来的数据
102
+ * @returns
103
+ */
104
+ init: function (_a) {
105
+ var project = _a.data;
106
+ if (!isEqual(_this.projectData, project)) {
107
+ // 空数据或者与旧数据相同,则不处理
108
+ logInfo('init', project);
109
+ _this.projectDomain.setProject(project);
110
+ // 通知模拟器更新project数据
111
+ _this.emit('updateProject', _this.projectDomain);
112
+ // 通知编辑器更新config和project数据 config会改变两次
113
+ _this.publish.update();
114
+ }
115
+ _this.history.reset();
116
+ _this.addHistory();
117
+ return toPlainObject(_this.config);
118
+ },
119
+ /**
120
+ * @public
121
+ * @param param0 - 从模拟器发送过来的数据
122
+ * @returns
123
+ */
124
+ click: function (_a) {
125
+ var _b = _a.data, key = _b.key, value = _b.value;
126
+ logInfo('click', key, value, key);
127
+ if (['undo', 'redo'].includes(key.action)) {
128
+ _this.function[key.action](key);
129
+ // 不新增记录
130
+ return toPlainObject(_this.config);
131
+ }
132
+ else if (key.module === 'function' && _this.function[key.action]) {
133
+ _this.function[key.action]({ key: key, value: value });
134
+ }
135
+ else if (key.action in _this.projectDomain) {
136
+ _this.projectDomain[key.action](key, value);
137
+ }
138
+ else {
139
+ return null;
140
+ }
141
+ _this.addHistory(); // addHistory 会触发更新,这里就不用返回数据了。降低通讯成本
142
+ },
143
+ /**
144
+ * @public
145
+ * @param param0 - 从模拟器发送过来的数据
146
+ */
147
+ drag: function (_a) {
148
+ var _b = _a.data, key = _b.key, value = _b.value;
149
+ _this.projectDomain.componentDrag(key, value);
150
+ _this.addHistory();
151
+ },
152
+ /**
153
+ * @public
154
+ * @param param0 - 从模拟器发送过来的数据
155
+ */
156
+ set: function (_a) {
157
+ var _b = _a.data, key = _b.key, value = _b.value;
158
+ logInfo('set', key, value);
159
+ _this.projectDomain[key.action](key.path, value);
160
+ _this.addHistory(); // addHistory 会触发更新,这里就不用返回数据了
161
+ },
162
+ /**
163
+ * @public
164
+ * @param param0 - 从模拟器发送过来的数据
165
+ * @returns
166
+ */
167
+ contextmenu: function (_a) {
168
+ var key = _a.data.key;
169
+ var menus = [];
170
+ try {
171
+ _this.projectDomain.activate(key);
172
+ menus = _this.projectDomain.menuData;
173
+ _this.activate();
174
+ }
175
+ catch (e) {
176
+ logError(e);
177
+ }
178
+ return toPlainObject({
179
+ config: _this.config,
180
+ menus: menus,
181
+ });
182
+ },
183
+ /**
184
+ * @public
185
+ * 校验
186
+ */
187
+ validate: function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
188
+ var result;
189
+ var data = _b.data;
190
+ return __generator(this, function (_c) {
191
+ switch (_c.label) {
192
+ case 0: return [4 /*yield*/, this.send('validatePage', data)];
193
+ case 1:
194
+ result = _c.sent();
195
+ logInfo('validate result', result, this.config);
196
+ return [2 /*return*/, toPlainObject({ config: this.config, result: result })];
197
+ }
198
+ });
199
+ }); },
200
+ /**
201
+ * @public
202
+ * 导航树移动组件
203
+ */
204
+ splice: function (_a) {
205
+ var data = _a.data;
206
+ logInfo('splice', data);
207
+ var draggingNode = data.draggingNode, dropNode = data.dropNode, dropType = data.dropType;
208
+ var curentDropNodePath = dropNode.key.path;
209
+ if (dropType === 'inner' && dropNode.type === ComponentType.Container) {
210
+ curentDropNodePath = "".concat(curentDropNodePath, ".children.0");
211
+ }
212
+ _this.projectDomain.moveTo(draggingNode.key.path, curentDropNodePath);
213
+ _this.addHistory(); // addHistory 会触发更新,这里就不用返回数据了
214
+ },
215
+ /**
216
+ * @public
217
+ * @param param0 - 从模拟器发送过来的数据
218
+ */
219
+ action: function (_a) {
220
+ var _b = _a.data, action = _b.action, value = _b.value;
221
+ logInfo('action', action, value);
222
+ _this.projectDomain.action(action, value);
223
+ _this.addHistory(); // addHistory 会触发更新,这里就不用返回数据了。降低通讯成本
224
+ }
225
+ };
226
+ /**
227
+ * @public
228
+ */
229
+ _this.publish = {
230
+ /**
231
+ * @public
232
+ * 在加载完时,告诉编辑器
233
+ * @returns
234
+ */
235
+ load: function () { return _this.commit('load', _this.config); },
236
+ /**
237
+ * @public
238
+ * 调用编辑器的交互方法,如让编辑器弹出toast等
239
+ * @param data - 发送给模拟器的内容
240
+ * @returns
241
+ */
242
+ action: function (data) { return _this.commit('action', data); },
243
+ /**
244
+ * @public
245
+ * 如果project发生变化,则需update通知编辑器
246
+ * @param forceUpdate - 是否强制更新
247
+ */
248
+ update: function (forceUpdate) {
249
+ if (forceUpdate === void 0) { forceUpdate = false; }
250
+ try {
251
+ _this.commit('update', {
252
+ config: _this.config,
253
+ project: _this.projectData,
254
+ forceUpdate: forceUpdate,
255
+ });
256
+ }
257
+ catch (err) {
258
+ console.error(err);
259
+ }
260
+ },
261
+ /**
262
+ * @public
263
+ * @param imgUrl - 图片url
264
+ */
265
+ updateScreenShot: function (imgUrl) {
266
+ _this.commit('updateScreenShot', imgUrl);
267
+ },
268
+ };
269
+ /**
270
+ * @public
271
+ */
272
+ _this.function = {
273
+ /**
274
+ * @public
275
+ */
276
+ simulatorSizeList: function (_a) {
277
+ var key = _a.key, value = _a.value;
278
+ _this.projectDomain.setProjectMeta(value);
279
+ },
280
+ /**
281
+ * @public
282
+ */
283
+ title: function () {
284
+ _this.publish.action(toPlainObject({ key: 'editTitle' }));
285
+ },
286
+ /**
287
+ * @public
288
+ */
289
+ undo: function () {
290
+ var data = _this.history.undo();
291
+ if (data) {
292
+ _this.replaceProject(cloneDeep(data));
293
+ }
294
+ },
295
+ /**
296
+ * @public
297
+ */
298
+ redo: function () {
299
+ var data = _this.history.redo();
300
+ if (data) {
301
+ _this.replaceProject(cloneDeep(data));
302
+ }
303
+ },
304
+ };
305
+ _this.state = state;
306
+ _this.history = new DataHistoryDomain();
307
+ Object.entries(_this.subscribe).forEach(function (_a) {
308
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
309
+ _this.state.communicator.subscribe(key, value.bind(_this));
310
+ });
311
+ // 发送到编辑器
312
+ _this.projectDomain.on('emitEditor', function (cmd) {
313
+ var _a;
314
+ var params = [];
315
+ for (var _i = 1; _i < arguments.length; _i++) {
316
+ params[_i - 1] = arguments[_i];
317
+ }
318
+ _this.publish[cmd]
319
+ ? (_a = _this.publish)[cmd].apply(_a, __spreadArray([], __read(params), false)) : _this.commit(cmd, params === null || params === void 0 ? void 0 : params[0]);
320
+ });
321
+ // 发送到Preview
322
+ _this.projectDomain.on('emitPreview', _this.emit.bind(_this));
323
+ _this.projectDomain.on('updateHistory', _this.updateHistory.bind(_this));
324
+ return _this;
325
+ }
326
+ /**
327
+ * @public
328
+ */
329
+ PreviewDomain.prototype.updateHistory = function () {
330
+ this.history.update(this.projectState);
331
+ this.emit('updateProject', this.projectDomain);
332
+ this.publish.update();
333
+ };
334
+ Object.defineProperty(PreviewDomain.prototype, "projectDomain", {
335
+ /**
336
+ * @public
337
+ */
338
+ get: function () {
339
+ return this.state.project;
340
+ },
341
+ enumerable: false,
342
+ configurable: true
343
+ });
344
+ Object.defineProperty(PreviewDomain.prototype, "projectState", {
345
+ /**
346
+ * @public
347
+ */
348
+ get: function () {
349
+ var _a = this.projectData, meta = _a.meta, pages = _a.pages;
350
+ return {
351
+ projectData: {
352
+ meta: meta,
353
+ pages: pages,
354
+ }, currentComponentPath: this.projectDomain.currentComponentPath
355
+ };
356
+ },
357
+ enumerable: false,
358
+ configurable: true
359
+ });
360
+ /**
361
+ * @public
362
+ * 添加历史记录
363
+ */
364
+ PreviewDomain.prototype.addHistory = function () {
365
+ var currentProject = this.history.data || {};
366
+ var projectState = this.projectState;
367
+ // 获取组件信息
368
+ if (currentProject.currentComponentPath === projectState.currentComponentPath) {
369
+ var value = this.projectDomain.needUpdateHistory(currentProject);
370
+ // 如果返回true,表示更新历史记录,不新增
371
+ if (value) {
372
+ try {
373
+ // 通知模拟器更新project数据
374
+ this.emit('updateProject', this.projectDomain);
375
+ // 通知编辑器更新config和project数据 config会改变两次
376
+ this.publish.update();
377
+ }
378
+ catch (e) {
379
+ console.error(e);
380
+ }
381
+ return;
382
+ }
383
+ }
384
+ if (this.history.add(projectState)) {
385
+ try {
386
+ // 通知模拟器更新project数据
387
+ this.emit('updateProject', this.projectDomain);
388
+ // 通知编辑器更新config和project数据 config会改变两次
389
+ this.publish.update();
390
+ }
391
+ catch (e) {
392
+ console.error(e);
393
+ }
394
+ this.activate();
395
+ }
396
+ };
397
+ Object.defineProperty(PreviewDomain.prototype, "config", {
398
+ /**
399
+ * @public
400
+ * 编辑器展示配置
401
+ */
402
+ get: function () {
403
+ var config = this.projectDomain.config;
404
+ var functionData = config.functionData;
405
+ if (functionData) {
406
+ // 设置撤销重做是否可点击
407
+ if (functionData.undo) {
408
+ functionData.undo.clickable = this.history.canUndo;
409
+ }
410
+ if (functionData.redo) {
411
+ functionData.redo.clickable = this.history.canRedo;
412
+ }
413
+ }
414
+ return config;
415
+ },
416
+ enumerable: false,
417
+ configurable: true
418
+ });
419
+ Object.defineProperty(PreviewDomain.prototype, "projectData", {
420
+ /**
421
+ * @public
422
+ * 获取项目数据
423
+ */
424
+ get: function () {
425
+ return this.projectDomain.state.project;
426
+ },
427
+ enumerable: false,
428
+ configurable: true
429
+ });
430
+ /**
431
+ * @public
432
+ * 更新激活状态。由于激活状态与历史记录变化关联度比较大,收敛到这里
433
+ * @param path - 路径
434
+ */
435
+ PreviewDomain.prototype.activate = function (path) {
436
+ var _a;
437
+ var project = this.state.project;
438
+ if (path) {
439
+ // 提供给外部用
440
+ project.activate({ path: path });
441
+ this.publish.update();
442
+ }
443
+ // 通知模拟器
444
+ this.emit('activate', (_a = project.currentComponent) === null || _a === void 0 ? void 0 : _a.componentId);
445
+ };
446
+ /**
447
+ * @public
448
+ * @param cmd - 命令字
449
+ * @param payload - 发送给模拟器的内容
450
+ * @returns
451
+ */
452
+ PreviewDomain.prototype.commit = function (cmd, payload) {
453
+ return __awaiter(this, void 0, void 0, function () {
454
+ var data;
455
+ return __generator(this, function (_a) {
456
+ switch (_a.label) {
457
+ case 0:
458
+ logInfo('publish begin', cmd, payload);
459
+ return [4 /*yield*/, this.state.communicator.publish(cmd, toPlainObject(payload))];
460
+ case 1:
461
+ data = (_a.sent()).data;
462
+ logInfo('publish end', cmd, payload, data);
463
+ return [2 /*return*/, data];
464
+ }
465
+ });
466
+ });
467
+ };
468
+ /**
469
+ * @public
470
+ * @param currentProject - 当前项目信息
471
+ */
472
+ PreviewDomain.prototype.replaceProject = function (currentProject) {
473
+ try {
474
+ this.projectDomain.replaceProject(currentProject);
475
+ // 通知模拟器更新project数据
476
+ this.emit('updateProject', this.projectDomain);
477
+ this.commit('update', {
478
+ config: this.config,
479
+ project: currentProject === null || currentProject === void 0 ? void 0 : currentProject.projectData,
480
+ forceUpdate: true,
481
+ });
482
+ this.activate();
483
+ }
484
+ catch (e) {
485
+ console.error(e);
486
+ }
487
+ };
488
+ return PreviewDomain;
489
+ }(Entity));
490
+ export default PreviewDomain;