@cicctencent/low-code-simulate-base 0.0.0-stage → 1.1.9-beta.5

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 +349 -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 +492 -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 +1330 -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 +44 -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 '@jt/ark-util';
2
+ import { Communicator } from '@jt/postmessage-channel';
3
+ import type { EditorConfig, Project, MenuData, CheckRequestItem, History } from '@jt/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("@jt/low-code-core").ProjectMeta;
37
+ pages: import("@jt/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,492 @@
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;
27
+ return g = { next: verb(0), "throw": verb(1), "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 '@jt/ark-util';
79
+ import { ComponentType } from '@jt/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) {
188
+ var data = _a.data;
189
+ return __awaiter(_this, void 0, void 0, function () {
190
+ var result;
191
+ return __generator(this, function (_b) {
192
+ switch (_b.label) {
193
+ case 0: return [4 /*yield*/, this.send('validatePage', data)];
194
+ case 1:
195
+ result = _b.sent();
196
+ logInfo('validate result', result, this.config);
197
+ return [2 /*return*/, toPlainObject({ config: this.config, result: result })];
198
+ }
199
+ });
200
+ });
201
+ },
202
+ /**
203
+ * @public
204
+ * 导航树移动组件
205
+ */
206
+ splice: function (_a) {
207
+ var data = _a.data;
208
+ logInfo('splice', data);
209
+ var draggingNode = data.draggingNode, dropNode = data.dropNode, dropType = data.dropType;
210
+ var curentDropNodePath = dropNode.key.path;
211
+ if (dropType === 'inner' && dropNode.type === ComponentType.Container) {
212
+ curentDropNodePath = "".concat(curentDropNodePath, ".children.0");
213
+ }
214
+ _this.projectDomain.moveTo(draggingNode.key.path, curentDropNodePath);
215
+ _this.addHistory(); // addHistory 会触发更新,这里就不用返回数据了
216
+ },
217
+ /**
218
+ * @public
219
+ * @param param0 - 从模拟器发送过来的数据
220
+ */
221
+ action: function (_a) {
222
+ var _b = _a.data, action = _b.action, value = _b.value;
223
+ logInfo('action', action, value);
224
+ _this.projectDomain.action(action, value);
225
+ _this.addHistory(); // addHistory 会触发更新,这里就不用返回数据了。降低通讯成本
226
+ }
227
+ };
228
+ /**
229
+ * @public
230
+ */
231
+ _this.publish = {
232
+ /**
233
+ * @public
234
+ * 在加载完时,告诉编辑器
235
+ * @returns
236
+ */
237
+ load: function () { return _this.commit('load', _this.config); },
238
+ /**
239
+ * @public
240
+ * 调用编辑器的交互方法,如让编辑器弹出toast等
241
+ * @param data - 发送给模拟器的内容
242
+ * @returns
243
+ */
244
+ action: function (data) { return _this.commit('action', data); },
245
+ /**
246
+ * @public
247
+ * 如果project发生变化,则需update通知编辑器
248
+ * @param forceUpdate - 是否强制更新
249
+ */
250
+ update: function (forceUpdate) {
251
+ if (forceUpdate === void 0) { forceUpdate = false; }
252
+ try {
253
+ _this.commit('update', {
254
+ config: _this.config,
255
+ project: _this.projectData,
256
+ forceUpdate: forceUpdate,
257
+ });
258
+ }
259
+ catch (err) {
260
+ console.error(err);
261
+ }
262
+ },
263
+ /**
264
+ * @public
265
+ * @param imgUrl - 图片url
266
+ */
267
+ updateScreenShot: function (imgUrl) {
268
+ _this.commit('updateScreenShot', imgUrl);
269
+ },
270
+ };
271
+ /**
272
+ * @public
273
+ */
274
+ _this.function = {
275
+ /**
276
+ * @public
277
+ */
278
+ simulatorSizeList: function (_a) {
279
+ var key = _a.key, value = _a.value;
280
+ _this.projectDomain.setProjectMeta(value);
281
+ },
282
+ /**
283
+ * @public
284
+ */
285
+ title: function () {
286
+ _this.publish.action(toPlainObject({ key: 'editTitle' }));
287
+ },
288
+ /**
289
+ * @public
290
+ */
291
+ undo: function () {
292
+ var data = _this.history.undo();
293
+ if (data) {
294
+ _this.replaceProject(cloneDeep(data));
295
+ }
296
+ },
297
+ /**
298
+ * @public
299
+ */
300
+ redo: function () {
301
+ var data = _this.history.redo();
302
+ if (data) {
303
+ _this.replaceProject(cloneDeep(data));
304
+ }
305
+ },
306
+ };
307
+ _this.state = state;
308
+ _this.history = new DataHistoryDomain();
309
+ Object.entries(_this.subscribe).forEach(function (_a) {
310
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
311
+ _this.state.communicator.subscribe(key, value.bind(_this));
312
+ });
313
+ // 发送到编辑器
314
+ _this.projectDomain.on('emitEditor', function (cmd) {
315
+ var _a;
316
+ var params = [];
317
+ for (var _i = 1; _i < arguments.length; _i++) {
318
+ params[_i - 1] = arguments[_i];
319
+ }
320
+ _this.publish[cmd]
321
+ ? (_a = _this.publish)[cmd].apply(_a, __spreadArray([], __read(params), false)) : _this.commit(cmd, params === null || params === void 0 ? void 0 : params[0]);
322
+ });
323
+ // 发送到Preview
324
+ _this.projectDomain.on('emitPreview', _this.emit.bind(_this));
325
+ _this.projectDomain.on('updateHistory', _this.updateHistory.bind(_this));
326
+ return _this;
327
+ }
328
+ /**
329
+ * @public
330
+ */
331
+ PreviewDomain.prototype.updateHistory = function () {
332
+ this.history.update(this.projectState);
333
+ this.emit('updateProject', this.projectDomain);
334
+ this.publish.update();
335
+ };
336
+ Object.defineProperty(PreviewDomain.prototype, "projectDomain", {
337
+ /**
338
+ * @public
339
+ */
340
+ get: function () {
341
+ return this.state.project;
342
+ },
343
+ enumerable: false,
344
+ configurable: true
345
+ });
346
+ Object.defineProperty(PreviewDomain.prototype, "projectState", {
347
+ /**
348
+ * @public
349
+ */
350
+ get: function () {
351
+ var _a = this.projectData, meta = _a.meta, pages = _a.pages;
352
+ return {
353
+ projectData: {
354
+ meta: meta,
355
+ pages: pages,
356
+ }, currentComponentPath: this.projectDomain.currentComponentPath
357
+ };
358
+ },
359
+ enumerable: false,
360
+ configurable: true
361
+ });
362
+ /**
363
+ * @public
364
+ * 添加历史记录
365
+ */
366
+ PreviewDomain.prototype.addHistory = function () {
367
+ var currentProject = this.history.data || {};
368
+ var projectState = this.projectState;
369
+ // 获取组件信息
370
+ if (currentProject.currentComponentPath === projectState.currentComponentPath) {
371
+ var value = this.projectDomain.needUpdateHistory(currentProject);
372
+ // 如果返回true,表示更新历史记录,不新增
373
+ if (value) {
374
+ try {
375
+ // 通知模拟器更新project数据
376
+ this.emit('updateProject', this.projectDomain);
377
+ // 通知编辑器更新config和project数据 config会改变两次
378
+ this.publish.update();
379
+ }
380
+ catch (e) {
381
+ console.error(e);
382
+ }
383
+ return;
384
+ }
385
+ }
386
+ if (this.history.add(projectState)) {
387
+ try {
388
+ // 通知模拟器更新project数据
389
+ this.emit('updateProject', this.projectDomain);
390
+ // 通知编辑器更新config和project数据 config会改变两次
391
+ this.publish.update();
392
+ }
393
+ catch (e) {
394
+ console.error(e);
395
+ }
396
+ this.activate();
397
+ }
398
+ };
399
+ Object.defineProperty(PreviewDomain.prototype, "config", {
400
+ /**
401
+ * @public
402
+ * 编辑器展示配置
403
+ */
404
+ get: function () {
405
+ var config = this.projectDomain.config;
406
+ var functionData = config.functionData;
407
+ if (functionData) {
408
+ // 设置撤销重做是否可点击
409
+ if (functionData.undo) {
410
+ functionData.undo.clickable = this.history.canUndo;
411
+ }
412
+ if (functionData.redo) {
413
+ functionData.redo.clickable = this.history.canRedo;
414
+ }
415
+ }
416
+ return config;
417
+ },
418
+ enumerable: false,
419
+ configurable: true
420
+ });
421
+ Object.defineProperty(PreviewDomain.prototype, "projectData", {
422
+ /**
423
+ * @public
424
+ * 获取项目数据
425
+ */
426
+ get: function () {
427
+ return this.projectDomain.state.project;
428
+ },
429
+ enumerable: false,
430
+ configurable: true
431
+ });
432
+ /**
433
+ * @public
434
+ * 更新激活状态。由于激活状态与历史记录变化关联度比较大,收敛到这里
435
+ * @param path - 路径
436
+ */
437
+ PreviewDomain.prototype.activate = function (path) {
438
+ var _a;
439
+ var project = this.state.project;
440
+ if (path) {
441
+ // 提供给外部用
442
+ project.activate({ path: path });
443
+ this.publish.update();
444
+ }
445
+ // 通知模拟器
446
+ this.emit('activate', (_a = project.currentComponent) === null || _a === void 0 ? void 0 : _a.componentId);
447
+ };
448
+ /**
449
+ * @public
450
+ * @param cmd - 命令字
451
+ * @param payload - 发送给模拟器的内容
452
+ * @returns
453
+ */
454
+ PreviewDomain.prototype.commit = function (cmd, payload) {
455
+ return __awaiter(this, void 0, void 0, function () {
456
+ var data;
457
+ return __generator(this, function (_a) {
458
+ switch (_a.label) {
459
+ case 0:
460
+ logInfo('publish begin', cmd, payload);
461
+ return [4 /*yield*/, this.state.communicator.publish(cmd, toPlainObject(payload))];
462
+ case 1:
463
+ data = (_a.sent()).data;
464
+ logInfo('publish end', cmd, payload, data);
465
+ return [2 /*return*/, data];
466
+ }
467
+ });
468
+ });
469
+ };
470
+ /**
471
+ * @public
472
+ * @param currentProject - 当前项目信息
473
+ */
474
+ PreviewDomain.prototype.replaceProject = function (currentProject) {
475
+ try {
476
+ this.projectDomain.replaceProject(currentProject);
477
+ // 通知模拟器更新project数据
478
+ this.emit('updateProject', this.projectDomain);
479
+ this.commit('update', {
480
+ config: this.config,
481
+ project: currentProject === null || currentProject === void 0 ? void 0 : currentProject.projectData,
482
+ forceUpdate: true,
483
+ });
484
+ this.activate();
485
+ }
486
+ catch (e) {
487
+ console.error(e);
488
+ }
489
+ };
490
+ return PreviewDomain;
491
+ }(Entity));
492
+ export default PreviewDomain;