@wix/editor-application 1.308.0

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 (50) hide show
  1. package/README.md +1 -0
  2. package/dist/cjs/environment-api/index.js +584 -0
  3. package/dist/cjs/environment-api/index.js.map +1 -0
  4. package/dist/cjs/index.js +773 -0
  5. package/dist/cjs/index.js.map +1 -0
  6. package/dist/cjs/platform-frame/index.js +368 -0
  7. package/dist/cjs/platform-frame/index.js.map +1 -0
  8. package/dist/cjs/platform-frame-api/index.js +341 -0
  9. package/dist/cjs/platform-frame-api/index.js.map +1 -0
  10. package/dist/cjs/platform-worker/index.js +552 -0
  11. package/dist/cjs/platform-worker/index.js.map +1 -0
  12. package/dist/cjs/platform-worker-api/index.js +550 -0
  13. package/dist/cjs/platform-worker-api/index.js.map +1 -0
  14. package/dist/esm/environment-api/index.js +579 -0
  15. package/dist/esm/environment-api/index.js.map +1 -0
  16. package/dist/esm/index.js +764 -0
  17. package/dist/esm/index.js.map +1 -0
  18. package/dist/esm/platform-frame/index.js +366 -0
  19. package/dist/esm/platform-frame/index.js.map +1 -0
  20. package/dist/esm/platform-frame-api/index.js +339 -0
  21. package/dist/esm/platform-frame-api/index.js.map +1 -0
  22. package/dist/esm/platform-worker/index.js +550 -0
  23. package/dist/esm/platform-worker/index.js.map +1 -0
  24. package/dist/esm/platform-worker-api/index.js +548 -0
  25. package/dist/esm/platform-worker-api/index.js.map +1 -0
  26. package/dist/statics/environment-api/index.js +586 -0
  27. package/dist/statics/environment-api/index.js.map +1 -0
  28. package/dist/statics/index.js +775 -0
  29. package/dist/statics/index.js.map +1 -0
  30. package/dist/statics/platform-frame/index.js +369 -0
  31. package/dist/statics/platform-frame/index.js.map +1 -0
  32. package/dist/statics/platform-frame-api/index.js +344 -0
  33. package/dist/statics/platform-frame-api/index.js.map +1 -0
  34. package/dist/statics/platform-worker/index.js +553 -0
  35. package/dist/statics/platform-worker/index.js.map +1 -0
  36. package/dist/statics/platform-worker-api/index.js +552 -0
  37. package/dist/statics/platform-worker-api/index.js.map +1 -0
  38. package/dist/types/environment-api/index.d.ts +27 -0
  39. package/dist/types/environment-api/index.d.ts.map +1 -0
  40. package/dist/types/index.d.ts +253 -0
  41. package/dist/types/index.d.ts.map +1 -0
  42. package/dist/types/platform-frame/index.d.ts +27 -0
  43. package/dist/types/platform-frame/index.d.ts.map +1 -0
  44. package/dist/types/platform-frame-api/index.d.ts +27 -0
  45. package/dist/types/platform-frame-api/index.d.ts.map +1 -0
  46. package/dist/types/platform-worker/index.d.ts +27 -0
  47. package/dist/types/platform-worker/index.d.ts.map +1 -0
  48. package/dist/types/platform-worker-api/index.d.ts +27 -0
  49. package/dist/types/platform-worker-api/index.d.ts.map +1 -0
  50. package/package.json +96 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ tbd
@@ -0,0 +1,584 @@
1
+ 'use strict';
2
+
3
+ var publicEditorPlatformEvents = require('@wix/public-editor-platform-events');
4
+ var publicEditorPlatformErrors = require('@wix/public-editor-platform-errors');
5
+ var publicEditorPlatformInterfaces = require('@wix/public-editor-platform-interfaces');
6
+
7
+ var EditorPlatformApplicationContextErrorCode = /* @__PURE__ */ ((EditorPlatformApplicationContextErrorCode2) => {
8
+ EditorPlatformApplicationContextErrorCode2["IncorrectEnvironment"] = "IncorrectEnvironment";
9
+ return EditorPlatformApplicationContextErrorCode2;
10
+ })(EditorPlatformApplicationContextErrorCode || {});
11
+ class EditorPlatformApplicationContextError extends publicEditorPlatformErrors.BaseError {
12
+ state = {};
13
+ constructor(message, code) {
14
+ super(message, code, "Editor Platform Application Context Error");
15
+ }
16
+ withUrl(url) {
17
+ this.state = { ...this.state, url };
18
+ return this;
19
+ }
20
+ withAppDefinitionId(appDefinitionId) {
21
+ this.state = { ...this.state, appDefinitionId };
22
+ return this;
23
+ }
24
+ }
25
+ const createEditorPlatformApplicationContextError = publicEditorPlatformErrors.createErrorBuilder(EditorPlatformApplicationContextError);
26
+ async function transformEventPayload(eventPayload, privateAPI) {
27
+ if (!eventPayload?.type) {
28
+ return eventPayload;
29
+ }
30
+ switch (eventPayload.type) {
31
+ case "componentSelectionChanged":
32
+ const componentRefs = eventPayload.componentRefs || [];
33
+ const components = await Promise.all(
34
+ componentRefs.map((ref) => {
35
+ return privateAPI.components.getComponent(ref);
36
+ })
37
+ );
38
+ return {
39
+ type: eventPayload.type,
40
+ components
41
+ };
42
+ default:
43
+ return eventPayload;
44
+ }
45
+ }
46
+ class ApplicationBoundEvents {
47
+ constructor(appDefinitionId, events, privateAPI) {
48
+ this.appDefinitionId = appDefinitionId;
49
+ this.privateAPI = privateAPI;
50
+ this.events = events;
51
+ this.subscribe = events.subscribe.bind(events);
52
+ this.commit = events.commit.bind(events);
53
+ this.startTransaction = events.startTransaction.bind(events);
54
+ this.silent = events.silent.bind(events);
55
+ }
56
+ events;
57
+ subscribe;
58
+ commit;
59
+ startTransaction;
60
+ silent;
61
+ notify(event) {
62
+ this.events.notify({
63
+ type: event.type,
64
+ payload: event.payload,
65
+ meta: {
66
+ appDefinitionId: this.appDefinitionId
67
+ }
68
+ });
69
+ }
70
+ notifyCustomEvent(type, payload) {
71
+ this.notify({
72
+ type: publicEditorPlatformEvents.PlatformAppEvent.CustomEvent,
73
+ payload: {
74
+ ...payload,
75
+ type
76
+ }
77
+ });
78
+ }
79
+ /**
80
+ * TODO: we should use same interface for all events
81
+ * (subscribe vs addEventListener)
82
+ */
83
+ addEventListener(eventType, fn) {
84
+ return this.events.subscribe(async (event) => {
85
+ const isAppMatch = event.meta?.appDefinitionId === this.appDefinitionId || event.meta?.appDefinitionId === null;
86
+ const transformPayload = () => transformEventPayload(event.payload, this.privateAPI);
87
+ if (eventType === "*") {
88
+ fn(await transformPayload());
89
+ } else if (event.type === publicEditorPlatformEvents.PlatformAppEvent.CustomEvent) {
90
+ if (eventType === event.payload?.type && !isAppMatch) {
91
+ fn(await transformPayload());
92
+ }
93
+ } else if (event.type === publicEditorPlatformEvents.PlatformAppEvent.HostEvent) {
94
+ if (eventType === event.payload?.type && isAppMatch) {
95
+ fn(await transformPayload());
96
+ }
97
+ }
98
+ });
99
+ }
100
+ }
101
+ const WAIT_INJECTED_TIMEOUT = 200;
102
+ const WAIT_INJECTED_RETRY_COUNT = 50;
103
+ class ContextInjectionStatus {
104
+ _resolveContextInjected = () => {
105
+ };
106
+ _isInjected = false;
107
+ key;
108
+ constructor(uuid) {
109
+ this.key = `__${uuid}_CONTEXT_INJECTION_STATUS_KEY`;
110
+ if (!globalThis[this.key]) {
111
+ globalThis[this.key] = new Promise((resolve) => {
112
+ this._resolveContextInjected = () => {
113
+ this._isInjected = true;
114
+ resolve();
115
+ };
116
+ });
117
+ }
118
+ }
119
+ isInjected() {
120
+ return !!this._isInjected;
121
+ }
122
+ resolveInjected() {
123
+ this._resolveContextInjected?.();
124
+ }
125
+ waitInjected() {
126
+ return new Promise((resolve, reject) => {
127
+ let injected = false;
128
+ let timeoutId;
129
+ let retryCount = 0;
130
+ const timeout = () => {
131
+ if (injected) {
132
+ return;
133
+ }
134
+ timeoutId = setTimeout(() => {
135
+ retryCount++;
136
+ if (retryCount < WAIT_INJECTED_RETRY_COUNT) {
137
+ if (retryCount % 10 === 0) {
138
+ console.log(
139
+ createEditorPlatformApplicationContextError(
140
+ EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
141
+ "contexts are not resolved, still re-trying"
142
+ ).withMessage(`try number ${retryCount}`).message
143
+ );
144
+ }
145
+ timeout();
146
+ return;
147
+ }
148
+ if (!injected) {
149
+ const error = createEditorPlatformApplicationContextError(
150
+ EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
151
+ "contexts are not resolved, threw by timeout"
152
+ );
153
+ reject(error);
154
+ }
155
+ }, WAIT_INJECTED_TIMEOUT);
156
+ };
157
+ timeout();
158
+ const _waitContextInjectedPromise = globalThis[this.key];
159
+ _waitContextInjectedPromise.then(() => {
160
+ injected = true;
161
+ clearTimeout(timeoutId);
162
+ resolve();
163
+ });
164
+ });
165
+ }
166
+ }
167
+ const ENVIRONMENT_CONTEXT_KEY = "__ENVIRONMENT_CONTEXT_KEY";
168
+ var PlatformEnvironment = /* @__PURE__ */ ((PlatformEnvironment2) => {
169
+ PlatformEnvironment2["Worker"] = "Worker";
170
+ PlatformEnvironment2["Frame"] = "Frame";
171
+ return PlatformEnvironment2;
172
+ })(PlatformEnvironment || {});
173
+ class EnvironmentContext {
174
+ constructor(environmentContext) {
175
+ this.environmentContext = environmentContext;
176
+ }
177
+ static status = new ContextInjectionStatus("environment");
178
+ static async inject(context) {
179
+ if (globalThis[ENVIRONMENT_CONTEXT_KEY]) {
180
+ throw createEditorPlatformApplicationContextError(
181
+ EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
182
+ "Environment context already exists and should not be overridden"
183
+ );
184
+ }
185
+ globalThis[ENVIRONMENT_CONTEXT_KEY] = new EnvironmentContext(context);
186
+ this.status.resolveInjected();
187
+ }
188
+ static async getInstance() {
189
+ await this.status.waitInjected();
190
+ return globalThis[ENVIRONMENT_CONTEXT_KEY];
191
+ }
192
+ getPrivateAPI() {
193
+ return this.environmentContext.privateApi;
194
+ }
195
+ getEvents() {
196
+ return this.environmentContext.events;
197
+ }
198
+ getApplicationAPIs() {
199
+ return this.environmentContext.applicationAPIs ?? {};
200
+ }
201
+ getEnvironment() {
202
+ return this.environmentContext.environment;
203
+ }
204
+ }
205
+ const APPLICATION_CONTEXT_KEY = "__APPLICATION_CONTEXT_KEY";
206
+ class ApplicationContext {
207
+ constructor(applicationContext, environment) {
208
+ this.applicationContext = applicationContext;
209
+ this.environment = environment;
210
+ this.events = new ApplicationBoundEvents(
211
+ this.applicationContext.appDefinitionId,
212
+ this.environment.getEvents(),
213
+ this.environment.getPrivateAPI()
214
+ );
215
+ }
216
+ static status = new ContextInjectionStatus("application");
217
+ /**
218
+ * TODO: use generics for context type
219
+ * - application
220
+ * - editor
221
+ */
222
+ static async inject(context) {
223
+ const environment = await EnvironmentContext.getInstance();
224
+ if (environment.getEnvironment() !== PlatformEnvironment.Frame) {
225
+ throw createEditorPlatformApplicationContextError(
226
+ EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
227
+ "Application context can be injected only in frame environment"
228
+ );
229
+ }
230
+ if (globalThis[APPLICATION_CONTEXT_KEY]) {
231
+ throw createEditorPlatformApplicationContextError(
232
+ EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
233
+ "Application context already exists and should not be overridden"
234
+ );
235
+ }
236
+ globalThis[APPLICATION_CONTEXT_KEY] = new ApplicationContext(
237
+ context,
238
+ await EnvironmentContext.getInstance()
239
+ );
240
+ this.status.resolveInjected();
241
+ }
242
+ static async getInstance() {
243
+ const environment = await EnvironmentContext.getInstance();
244
+ if (environment.getEnvironment() === PlatformEnvironment.Frame) {
245
+ await this.status.waitInjected();
246
+ return globalThis[APPLICATION_CONTEXT_KEY];
247
+ } else {
248
+ return __APPLICATION_CONTEXT_KEY;
249
+ }
250
+ }
251
+ events;
252
+ getAppDefinitionId() {
253
+ return this.applicationContext.appDefinitionId;
254
+ }
255
+ getBindings() {
256
+ return this.applicationContext;
257
+ }
258
+ getEvents() {
259
+ return this.events;
260
+ }
261
+ getPrivateAPI() {
262
+ return this.environment.getPrivateAPI();
263
+ }
264
+ getPrivateApplicationAPI() {
265
+ const appDefinitionId = this.getAppDefinitionId();
266
+ if (!appDefinitionId) {
267
+ throw createEditorPlatformApplicationContextError(
268
+ EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
269
+ "appDefinitionId is not available"
270
+ );
271
+ }
272
+ return this.environment.getApplicationAPIs()[appDefinitionId];
273
+ }
274
+ }
275
+
276
+ class WorkerEventsBridge {
277
+ constructor(platformAppEvents) {
278
+ this.platformAppEvents = platformAppEvents;
279
+ }
280
+ /**
281
+ * Notify by event from Worker Manager (platform infrastructure)
282
+ */
283
+ notify(event) {
284
+ switch (event.type) {
285
+ case publicEditorPlatformEvents.PlatformLifecycleEvent.EditorReady:
286
+ this.platformAppEvents.notify({
287
+ ...event,
288
+ // @ts-expect-error TODO: fix me
289
+ type: publicEditorPlatformEvents.PlatformAppEvent.EditorReady
290
+ });
291
+ break;
292
+ case publicEditorPlatformEvents.PlatformPrivateEvent.HostEvent:
293
+ this.platformAppEvents.notify({
294
+ ...event,
295
+ type: publicEditorPlatformEvents.PlatformAppEvent.HostEvent
296
+ });
297
+ break;
298
+ }
299
+ }
300
+ /**
301
+ * Subscribe to Worker (Application) event
302
+ */
303
+ subscribe(cb) {
304
+ this.platformAppEvents.subscribe((event) => {
305
+ cb(event);
306
+ });
307
+ }
308
+ }
309
+
310
+ const PLATFORM_FRAME_API_TYPE = "PLATFORM_FRAME_API";
311
+ class PlatformFrameAPI {
312
+ type = PLATFORM_FRAME_API_TYPE;
313
+ #events = new publicEditorPlatformEvents.PlatformAppEventEmitter();
314
+ #eventsBridge = new WorkerEventsBridge(this.#events);
315
+ #privateAPI;
316
+ #applicationPrivateAPI;
317
+ async initFrameEnvironment(appDefinitionId, privateAPI, applicationPrivateAPI) {
318
+ this.#applicationPrivateAPI = applicationPrivateAPI;
319
+ this.#privateAPI = privateAPI;
320
+ await EnvironmentContext.inject({
321
+ environment: PlatformEnvironment.Frame,
322
+ privateApi: privateAPI,
323
+ events: this.#events,
324
+ applicationAPIs: {
325
+ [appDefinitionId]: this.#applicationPrivateAPI
326
+ }
327
+ });
328
+ await ApplicationContext.inject({
329
+ appDefinitionId,
330
+ appDefinitionName: ""
331
+ });
332
+ }
333
+ notify(event) {
334
+ this.#eventsBridge.notify(event);
335
+ }
336
+ subscribe(cb) {
337
+ this.#eventsBridge.subscribe(cb);
338
+ }
339
+ }
340
+
341
+ var EditorPlatformApplicationErrorCode = /* @__PURE__ */ ((EditorPlatformApplicationErrorCode2) => {
342
+ EditorPlatformApplicationErrorCode2["ApplicationRuntimeError"] = "ApplicationRuntimeError";
343
+ EditorPlatformApplicationErrorCode2["ApplicationCreationError"] = "ApplicationCreationError";
344
+ EditorPlatformApplicationErrorCode2["ApplicationLoadError"] = "ApplicationLoadError";
345
+ EditorPlatformApplicationErrorCode2["ApplicationFetchError"] = "ApplicationFetchError";
346
+ EditorPlatformApplicationErrorCode2["ApplicationExecuteError"] = "ApplicationExecuteError";
347
+ EditorPlatformApplicationErrorCode2["ApplicationWasRemoved"] = "ApplicationWasRemoved";
348
+ EditorPlatformApplicationErrorCode2["UndefinedApiMethod"] = "UndefinedApiMethod";
349
+ EditorPlatformApplicationErrorCode2["ApplicationIsNotMutable"] = "ApplicationIsNotMutable";
350
+ EditorPlatformApplicationErrorCode2["FailedToGetPrivateAPI"] = "FailedToGetPrivateAPI";
351
+ return EditorPlatformApplicationErrorCode2;
352
+ })(EditorPlatformApplicationErrorCode || {});
353
+ class EditorPlatformApplicationError extends publicEditorPlatformErrors.BaseError {
354
+ state = {};
355
+ constructor(message, code) {
356
+ super(message, code, "Editor Platform Application Error");
357
+ }
358
+ withUrl(url) {
359
+ this.state = { ...this.state, url };
360
+ return this;
361
+ }
362
+ withAppDefinitionId(appDefinitionId) {
363
+ this.state = { ...this.state, appDefinitionId };
364
+ return this;
365
+ }
366
+ withApiMethod(apiMethod) {
367
+ this.state = { ...this.state, apiMethod };
368
+ return this;
369
+ }
370
+ withApiType(apiType) {
371
+ this.state = { ...this.state, apiType };
372
+ return this;
373
+ }
374
+ }
375
+ const createEditorPlatformApplicationError = publicEditorPlatformErrors.createErrorBuilder(EditorPlatformApplicationError);
376
+
377
+ const APPLICATION_REGISTRY_KEY = "__APPLICATION_REGISTRY_KEY";
378
+ async function executeApplication(events, spec, bundle) {
379
+ const executable = new Function(
380
+ APPLICATION_CONTEXT_KEY,
381
+ APPLICATION_REGISTRY_KEY,
382
+ bundle
383
+ );
384
+ let instance;
385
+ const applicationRegistryCallback = (_instance) => {
386
+ if (instance) {
387
+ throw createEditorPlatformApplicationError(
388
+ EditorPlatformApplicationErrorCode.ApplicationExecuteError,
389
+ "Application registry called more than once"
390
+ ).withAppDefinitionId(spec.appDefinitionId);
391
+ }
392
+ if (_instance.type !== spec.type) {
393
+ throw createEditorPlatformApplicationError(
394
+ EditorPlatformApplicationErrorCode.ApplicationExecuteError,
395
+ "Application has different type"
396
+ ).withMessage("expected type", spec.type).withMessage("received type", _instance.type);
397
+ }
398
+ instance = _instance;
399
+ };
400
+ try {
401
+ const context = { ...spec };
402
+ executable.call(
403
+ void 0,
404
+ new ApplicationContext(context, await EnvironmentContext.getInstance()),
405
+ applicationRegistryCallback
406
+ );
407
+ } catch (e) {
408
+ throw createEditorPlatformApplicationError(
409
+ EditorPlatformApplicationErrorCode.ApplicationExecuteError,
410
+ e.message
411
+ ).withAppDefinitionId(spec.appDefinitionId).withParentError(e);
412
+ }
413
+ return new Promise((resolve, reject) => {
414
+ const unsubscribe = events.subscribe((event) => {
415
+ const timeoutId = setTimeout(() => {
416
+ clearTimeout(timeoutId);
417
+ unsubscribe();
418
+ if (!instance) {
419
+ reject(
420
+ createEditorPlatformApplicationError(
421
+ EditorPlatformApplicationErrorCode.ApplicationExecuteError,
422
+ "Application registry was not called, threw by timeout"
423
+ ).withAppDefinitionId(spec.appDefinitionId)
424
+ );
425
+ }
426
+ }, 5e3);
427
+ if (event.type === publicEditorPlatformEvents.PlatformAppEvent.ApplicationInit && event.meta.appDefinitionId === spec.appDefinitionId) {
428
+ clearTimeout(timeoutId);
429
+ unsubscribe();
430
+ if (!instance) {
431
+ reject(
432
+ createEditorPlatformApplicationError(
433
+ EditorPlatformApplicationErrorCode.ApplicationExecuteError,
434
+ "Application registry was not called"
435
+ ).withAppDefinitionId(spec.appDefinitionId)
436
+ );
437
+ }
438
+ resolve({ instance });
439
+ }
440
+ });
441
+ });
442
+ }
443
+
444
+ class PlatformApplicationContainer {
445
+ constructor(privateApi, events) {
446
+ this.privateApi = privateApi;
447
+ this.events = events;
448
+ this.events.subscribe((event) => {
449
+ switch (event.type) {
450
+ case publicEditorPlatformEvents.PlatformAppEvent.HostEvent: {
451
+ if (event.payload.type === publicEditorPlatformInterfaces.EventType.removeAppCompleted) {
452
+ this.events.withEvent(
453
+ this.events.factories.createApplicationRemovedEvent(
454
+ event.payload.appDefinitionId
455
+ ),
456
+ () => {
457
+ return this.removeApplication(event.payload.appDefinitionId);
458
+ }
459
+ );
460
+ }
461
+ break;
462
+ }
463
+ }
464
+ });
465
+ }
466
+ apps = {};
467
+ async runApplication(app) {
468
+ const bundle = await this.loadApplication(app);
469
+ const instance = await this.executeApplication(app, bundle);
470
+ this.setApplication(app.appDefinitionId, instance);
471
+ return instance;
472
+ }
473
+ setApplication(appDefId, instance) {
474
+ this.apps[appDefId] = instance;
475
+ this.events.withEvent(
476
+ this.events.factories.createApplicationApiInitEvent(
477
+ appDefId,
478
+ // TODO: both types are set here...
479
+ // @ts-expect-error TODO: fix me
480
+ instance?.api?.private ? "private" : "public"
481
+ ),
482
+ () => {
483
+ this.privateApi.applicationManager.setApplication(instance);
484
+ }
485
+ );
486
+ }
487
+ getApplication(appDefId) {
488
+ return this.apps[appDefId];
489
+ }
490
+ getAppDefinitionIds() {
491
+ return Object.keys(this.apps);
492
+ }
493
+ removeApplication(appDefinitionId) {
494
+ delete this.apps[appDefinitionId];
495
+ }
496
+ async loadApplication(app) {
497
+ const url = app.url;
498
+ return this.events.withEvent(
499
+ this.events.factories.createApplicationLoadEvent(app, url),
500
+ async () => {
501
+ try {
502
+ return await this.loadApplicationBundle(url);
503
+ } catch (e) {
504
+ throw createEditorPlatformApplicationError(
505
+ EditorPlatformApplicationErrorCode.ApplicationLoadError
506
+ ).withUrl(url).withAppDefinitionId(app.appDefinitionId).withParentError(e);
507
+ }
508
+ }
509
+ );
510
+ }
511
+ async loadApplicationBundle(url) {
512
+ const res = await fetch("url", {
513
+ method: "GET"
514
+ });
515
+ const isSuccessfulResponse = res.status >= 200 && res.status <= 299;
516
+ if (!isSuccessfulResponse) {
517
+ throw createEditorPlatformApplicationError(
518
+ EditorPlatformApplicationErrorCode.ApplicationFetchError
519
+ ).withUrl(url);
520
+ }
521
+ return res.text();
522
+ }
523
+ async executeApplication(app, bundle) {
524
+ return this.events.withEvent(
525
+ this.events.factories.createApplicationExecuteEvent(app, app.url),
526
+ async () => {
527
+ const { instance } = await executeApplication(this.events, app, bundle);
528
+ return instance;
529
+ }
530
+ );
531
+ }
532
+ }
533
+
534
+ const PLATFORM_WORKER_API_TYPE = "PLATFORM_WORKER_API";
535
+ class PlatformWorkerAPI {
536
+ type = PLATFORM_WORKER_API_TYPE;
537
+ #events = new publicEditorPlatformEvents.PlatformAppEventEmitter();
538
+ #eventsBridge = new WorkerEventsBridge(this.#events);
539
+ #container = null;
540
+ #privateAPI;
541
+ #pendingWaiters = [];
542
+ async initWorkerEnvironment(buildPrivateAPI) {
543
+ this.#privateAPI = await buildPrivateAPI({
544
+ // TODO: should be per application (within the container before app execution)
545
+ type: "EDITOR_ADDON"
546
+ });
547
+ await EnvironmentContext.inject({
548
+ environment: PlatformEnvironment.Worker,
549
+ events: this.#events,
550
+ privateApi: this.#privateAPI,
551
+ applicationAPIs: {}
552
+ });
553
+ this.#container = new PlatformApplicationContainer(
554
+ this.#privateAPI,
555
+ this.#events
556
+ );
557
+ this.#pendingWaiters.forEach((res) => res(this));
558
+ }
559
+ async notify(event) {
560
+ await this.waitReady();
561
+ this.#eventsBridge.notify(event);
562
+ }
563
+ subscribe(cb) {
564
+ this.#eventsBridge.subscribe(cb);
565
+ }
566
+ async runApplication(app) {
567
+ await this.waitReady();
568
+ await this.#container.runApplication(app);
569
+ }
570
+ waitReady() {
571
+ return new Promise((res) => {
572
+ if (this.#privateAPI) {
573
+ return res(this);
574
+ }
575
+ this.#pendingWaiters.push(res);
576
+ });
577
+ }
578
+ }
579
+
580
+ exports.PLATFORM_FRAME_API_TYPE = PLATFORM_FRAME_API_TYPE;
581
+ exports.PLATFORM_WORKER_API_TYPE = PLATFORM_WORKER_API_TYPE;
582
+ exports.PlatformFrameAPI = PlatformFrameAPI;
583
+ exports.PlatformWorkerAPI = PlatformWorkerAPI;
584
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../editor-platform-application-context/dist/esm/index.js","../../../src/Events/WorkerEventsBridge.ts","../../../src/PlatformEnvironmentAPI/PlatformFrameAPI/PlatformFrameAPI.ts","../../../src/errors.ts","../../../src/PlatformApplicationContainer/executeApplication.ts","../../../src/PlatformApplicationContainer/PlatformApplicationContainer.ts","../../../src/PlatformEnvironmentAPI/PlatformWorkerAPI/PlatformWorkerAPI.ts"],"sourcesContent":["import { createErrorBuilder, BaseError } from '@wix/public-editor-platform-errors';\nimport { PlatformAppEvent } from '@wix/public-editor-platform-events';\n\nvar EditorPlatformApplicationContextErrorCode = /* @__PURE__ */ ((EditorPlatformApplicationContextErrorCode2) => {\n EditorPlatformApplicationContextErrorCode2[\"IncorrectEnvironment\"] = \"IncorrectEnvironment\";\n return EditorPlatformApplicationContextErrorCode2;\n})(EditorPlatformApplicationContextErrorCode || {});\nclass EditorPlatformApplicationContextError extends BaseError {\n state = {};\n constructor(message, code) {\n super(message, code, \"Editor Platform Application Context Error\");\n }\n withUrl(url) {\n this.state = { ...this.state, url };\n return this;\n }\n withAppDefinitionId(appDefinitionId) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n}\nconst createEditorPlatformApplicationContextError = createErrorBuilder(EditorPlatformApplicationContextError);\n\nasync function transformEventPayload(eventPayload, privateAPI) {\n if (!eventPayload?.type) {\n return eventPayload;\n }\n switch (eventPayload.type) {\n case \"componentSelectionChanged\":\n const componentRefs = eventPayload.componentRefs || [];\n const components = await Promise.all(\n componentRefs.map((ref) => {\n return privateAPI.components.getComponent(ref);\n })\n );\n return {\n type: eventPayload.type,\n components\n };\n default:\n return eventPayload;\n }\n}\n\nclass ApplicationBoundEvents {\n constructor(appDefinitionId, events, privateAPI) {\n this.appDefinitionId = appDefinitionId;\n this.privateAPI = privateAPI;\n this.events = events;\n this.subscribe = events.subscribe.bind(events);\n this.commit = events.commit.bind(events);\n this.startTransaction = events.startTransaction.bind(events);\n this.silent = events.silent.bind(events);\n }\n events;\n subscribe;\n commit;\n startTransaction;\n silent;\n notify(event) {\n this.events.notify({\n type: event.type,\n payload: event.payload,\n meta: {\n appDefinitionId: this.appDefinitionId\n }\n });\n }\n notifyCustomEvent(type, payload) {\n this.notify({\n type: PlatformAppEvent.CustomEvent,\n payload: {\n ...payload,\n type\n }\n });\n }\n /**\n * TODO: we should use same interface for all events\n * (subscribe vs addEventListener)\n */\n addEventListener(eventType, fn) {\n return this.events.subscribe(async (event) => {\n const isAppMatch = event.meta?.appDefinitionId === this.appDefinitionId || event.meta?.appDefinitionId === null;\n const transformPayload = () => transformEventPayload(event.payload, this.privateAPI);\n if (eventType === \"*\") {\n fn(await transformPayload());\n } else if (event.type === PlatformAppEvent.CustomEvent) {\n if (eventType === event.payload?.type && !isAppMatch) {\n fn(await transformPayload());\n }\n } else if (event.type === PlatformAppEvent.HostEvent) {\n if (eventType === event.payload?.type && isAppMatch) {\n fn(await transformPayload());\n }\n }\n });\n }\n}\n\nconst WAIT_INJECTED_TIMEOUT = 200;\nconst WAIT_INJECTED_RETRY_COUNT = 50;\nclass ContextInjectionStatus {\n _resolveContextInjected = () => {\n };\n _isInjected = false;\n key;\n constructor(uuid) {\n this.key = `__${uuid}_CONTEXT_INJECTION_STATUS_KEY`;\n if (!globalThis[this.key]) {\n globalThis[this.key] = new Promise((resolve) => {\n this._resolveContextInjected = () => {\n this._isInjected = true;\n resolve();\n };\n });\n }\n }\n isInjected() {\n return !!this._isInjected;\n }\n resolveInjected() {\n this._resolveContextInjected?.();\n }\n waitInjected() {\n return new Promise((resolve, reject) => {\n let injected = false;\n let timeoutId;\n let retryCount = 0;\n const timeout = () => {\n if (injected) {\n return;\n }\n timeoutId = setTimeout(() => {\n retryCount++;\n if (retryCount < WAIT_INJECTED_RETRY_COUNT) {\n if (retryCount % 10 === 0) {\n console.log(\n createEditorPlatformApplicationContextError(\n EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,\n \"contexts are not resolved, still re-trying\"\n ).withMessage(`try number ${retryCount}`).message\n );\n }\n timeout();\n return;\n }\n if (!injected) {\n const error = createEditorPlatformApplicationContextError(\n EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,\n \"contexts are not resolved, threw by timeout\"\n );\n reject(error);\n }\n }, WAIT_INJECTED_TIMEOUT);\n };\n timeout();\n const _waitContextInjectedPromise = globalThis[this.key];\n _waitContextInjectedPromise.then(() => {\n injected = true;\n clearTimeout(timeoutId);\n resolve();\n });\n });\n }\n}\n\nconst ENVIRONMENT_CONTEXT_KEY = \"__ENVIRONMENT_CONTEXT_KEY\";\nvar PlatformEnvironment = /* @__PURE__ */ ((PlatformEnvironment2) => {\n PlatformEnvironment2[\"Worker\"] = \"Worker\";\n PlatformEnvironment2[\"Frame\"] = \"Frame\";\n return PlatformEnvironment2;\n})(PlatformEnvironment || {});\nclass EnvironmentContext {\n constructor(environmentContext) {\n this.environmentContext = environmentContext;\n }\n static status = new ContextInjectionStatus(\"environment\");\n static async inject(context) {\n if (globalThis[ENVIRONMENT_CONTEXT_KEY]) {\n throw createEditorPlatformApplicationContextError(\n EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,\n \"Environment context already exists and should not be overridden\"\n );\n }\n globalThis[ENVIRONMENT_CONTEXT_KEY] = new EnvironmentContext(context);\n this.status.resolveInjected();\n }\n static async getInstance() {\n await this.status.waitInjected();\n return globalThis[ENVIRONMENT_CONTEXT_KEY];\n }\n getPrivateAPI() {\n return this.environmentContext.privateApi;\n }\n getEvents() {\n return this.environmentContext.events;\n }\n getApplicationAPIs() {\n return this.environmentContext.applicationAPIs ?? {};\n }\n getEnvironment() {\n return this.environmentContext.environment;\n }\n}\n\nconst APPLICATION_CONTEXT_KEY = \"__APPLICATION_CONTEXT_KEY\";\nclass ApplicationContext {\n constructor(applicationContext, environment) {\n this.applicationContext = applicationContext;\n this.environment = environment;\n this.events = new ApplicationBoundEvents(\n this.applicationContext.appDefinitionId,\n this.environment.getEvents(),\n this.environment.getPrivateAPI()\n );\n }\n static status = new ContextInjectionStatus(\"application\");\n /**\n * TODO: use generics for context type\n * - application\n * - editor\n */\n static async inject(context) {\n const environment = await EnvironmentContext.getInstance();\n if (environment.getEnvironment() !== PlatformEnvironment.Frame) {\n throw createEditorPlatformApplicationContextError(\n EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,\n \"Application context can be injected only in frame environment\"\n );\n }\n if (globalThis[APPLICATION_CONTEXT_KEY]) {\n throw createEditorPlatformApplicationContextError(\n EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,\n \"Application context already exists and should not be overridden\"\n );\n }\n globalThis[APPLICATION_CONTEXT_KEY] = new ApplicationContext(\n context,\n await EnvironmentContext.getInstance()\n );\n this.status.resolveInjected();\n }\n static async getInstance() {\n const environment = await EnvironmentContext.getInstance();\n if (environment.getEnvironment() === PlatformEnvironment.Frame) {\n await this.status.waitInjected();\n return globalThis[APPLICATION_CONTEXT_KEY];\n } else {\n return __APPLICATION_CONTEXT_KEY;\n }\n }\n events;\n getAppDefinitionId() {\n return this.applicationContext.appDefinitionId;\n }\n getBindings() {\n return this.applicationContext;\n }\n getEvents() {\n return this.events;\n }\n getPrivateAPI() {\n return this.environment.getPrivateAPI();\n }\n getPrivateApplicationAPI() {\n const appDefinitionId = this.getAppDefinitionId();\n if (!appDefinitionId) {\n throw createEditorPlatformApplicationContextError(\n EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,\n \"appDefinitionId is not available\"\n );\n }\n return this.environment.getApplicationAPIs()[appDefinitionId];\n }\n}\n\nexport { APPLICATION_CONTEXT_KEY, ApplicationBoundEvents, ApplicationContext, ENVIRONMENT_CONTEXT_KEY, EnvironmentContext, PlatformEnvironment };\n//# sourceMappingURL=index.js.map\n","import {\n IPlatformPrivateEvent,\n PlatformLifecycleEvent,\n PlatformPrivateEvent,\n // --\n IPlatformAppEvent,\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\n\n/**\n * The events bridge between platform events (private) and app events\n */\nexport class WorkerEventsBridge {\n constructor(private platformAppEvents: PlatformAppEventEmitter) {}\n\n /**\n * Notify by event from Worker Manager (platform infrastructure)\n */\n public notify(event: IPlatformPrivateEvent) {\n switch (event.type) {\n case PlatformLifecycleEvent.EditorReady:\n this.platformAppEvents.notify({\n ...event,\n // @ts-expect-error TODO: fix me\n type: PlatformAppEvent.EditorReady,\n });\n break;\n case PlatformPrivateEvent.HostEvent:\n this.platformAppEvents.notify({\n ...event,\n type: PlatformAppEvent.HostEvent,\n });\n break;\n }\n }\n\n /**\n * Subscribe to Worker (Application) event\n */\n public subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.platformAppEvents.subscribe((event) => {\n cb(event);\n });\n }\n}\n","import { IPrivateAPIFixMe } from '../../types';\n\nimport {\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n IPlatformAppEvent,\n} from '@wix/public-editor-platform-events';\nimport {\n EnvironmentContext,\n ApplicationContext,\n PlatformEnvironment,\n} from '@wix/editor-application-context';\n\nimport { WorkerEventsBridge } from '../../Events';\n\nexport const PLATFORM_FRAME_API_TYPE = 'PLATFORM_FRAME_API';\nexport class PlatformFrameAPI {\n type = PLATFORM_FRAME_API_TYPE;\n\n #events = new PlatformAppEventEmitter();\n #eventsBridge = new WorkerEventsBridge(this.#events);\n #privateAPI: IPrivateAPIFixMe;\n #applicationPrivateAPI: any;\n\n async initFrameEnvironment(\n appDefinitionId: string,\n privateAPI: IPrivateAPIFixMe,\n applicationPrivateAPI: any,\n ) {\n this.#applicationPrivateAPI = applicationPrivateAPI;\n this.#privateAPI = privateAPI;\n\n await EnvironmentContext.inject({\n environment: PlatformEnvironment.Frame,\n privateApi: privateAPI,\n events: this.#events,\n applicationAPIs: {\n [appDefinitionId]: this.#applicationPrivateAPI,\n },\n });\n\n await ApplicationContext.inject({\n appDefinitionId,\n appDefinitionName: '',\n });\n }\n\n notify(event: IPlatformPrivateEvent) {\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n}\n","import {\n BaseError,\n createErrorBuilder,\n} from '@wix/public-editor-platform-errors';\n\nexport enum EditorPlatformApplicationErrorCode {\n ApplicationRuntimeError = 'ApplicationRuntimeError',\n ApplicationCreationError = 'ApplicationCreationError',\n ApplicationLoadError = 'ApplicationLoadError',\n ApplicationFetchError = 'ApplicationFetchError',\n ApplicationExecuteError = 'ApplicationExecuteError',\n ApplicationWasRemoved = 'ApplicationWasRemoved',\n UndefinedApiMethod = 'UndefinedApiMethod',\n ApplicationIsNotMutable = 'ApplicationIsNotMutable',\n FailedToGetPrivateAPI = 'FailedToGetPrivateAPI',\n}\n\nclass EditorPlatformApplicationError extends BaseError<EditorPlatformApplicationErrorCode> {\n state: Partial<{\n url: string;\n appDefinitionId: string;\n apiMethod: string;\n apiType: string;\n }> = {};\n\n constructor(message: string, code: EditorPlatformApplicationErrorCode) {\n super(message, code, 'Editor Platform Application Error');\n }\n\n withUrl(url: string) {\n this.state = { ...this.state, url };\n return this;\n }\n\n withAppDefinitionId(appDefinitionId: string) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n\n withApiMethod(apiMethod: string) {\n this.state = { ...this.state, apiMethod };\n return this;\n }\n\n withApiType(apiType: string) {\n this.state = { ...this.state, apiType };\n return this;\n }\n}\n\nexport const createEditorPlatformApplicationError = createErrorBuilder<\n EditorPlatformApplicationErrorCode,\n EditorPlatformApplicationError\n>(EditorPlatformApplicationError);\n","import {\n APPLICATION_CONTEXT_KEY,\n EnvironmentContext,\n ApplicationContext,\n} from '@wix/editor-application-context';\nimport {\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\n\nimport type { EditorPlatformApplication } from '../EditorPlatformApplication';\nimport {\n createEditorPlatformApplicationError,\n EditorPlatformApplicationErrorCode,\n} from '../errors';\nimport { IApplicationSpec } from '../types';\n\nexport const APPLICATION_REGISTRY_KEY = '__APPLICATION_REGISTRY_KEY';\n\nexport type IApplicationRegistry = (\n _instance: EditorPlatformApplication,\n) => void;\n\nexport async function executeApplication(\n events: PlatformAppEventEmitter,\n spec: IApplicationSpec,\n bundle: string,\n): Promise<{\n instance: EditorPlatformApplication;\n}> {\n // eslint-disable-next-line no-new-func\n const executable = new Function(\n APPLICATION_CONTEXT_KEY,\n APPLICATION_REGISTRY_KEY,\n bundle,\n );\n\n let instance: EditorPlatformApplication | undefined;\n\n const applicationRegistryCallback: IApplicationRegistry = (_instance) => {\n if (instance) {\n throw createEditorPlatformApplicationError(\n EditorPlatformApplicationErrorCode.ApplicationExecuteError,\n 'Application registry called more than once',\n ).withAppDefinitionId(spec.appDefinitionId);\n }\n\n if (_instance.type !== spec.type) {\n throw createEditorPlatformApplicationError(\n EditorPlatformApplicationErrorCode.ApplicationExecuteError,\n 'Application has different type',\n )\n .withMessage('expected type', spec.type)\n .withMessage('received type', _instance.type);\n }\n\n instance = _instance;\n };\n\n try {\n const context = { ...spec };\n\n executable.call(\n undefined,\n new ApplicationContext(context, await EnvironmentContext.getInstance()),\n applicationRegistryCallback,\n );\n } catch (e: unknown) {\n throw createEditorPlatformApplicationError(\n EditorPlatformApplicationErrorCode.ApplicationExecuteError,\n (e as Error).message,\n )\n .withAppDefinitionId(spec.appDefinitionId)\n .withParentError(e as Error);\n }\n\n return new Promise((resolve, reject) => {\n const unsubscribe = events.subscribe((event) => {\n const timeoutId = setTimeout(() => {\n clearTimeout(timeoutId);\n unsubscribe();\n\n if (!instance) {\n reject(\n createEditorPlatformApplicationError(\n EditorPlatformApplicationErrorCode.ApplicationExecuteError,\n 'Application registry was not called, threw by timeout',\n ).withAppDefinitionId(spec.appDefinitionId),\n );\n }\n }, 5000);\n\n if (\n event.type === PlatformAppEvent.ApplicationInit &&\n event.meta.appDefinitionId === spec.appDefinitionId\n ) {\n clearTimeout(timeoutId);\n unsubscribe();\n\n if (!instance) {\n reject(\n createEditorPlatformApplicationError(\n EditorPlatformApplicationErrorCode.ApplicationExecuteError,\n 'Application registry was not called',\n ).withAppDefinitionId(spec.appDefinitionId),\n );\n }\n\n resolve({ instance: instance! });\n }\n });\n });\n}\n","import {\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport { EventType } from '@wix/public-editor-platform-interfaces';\nimport {\n createEditorPlatformApplicationError,\n EditorPlatformApplicationErrorCode,\n} from '../errors';\nimport { EditorPlatformApplication } from '../EditorPlatformApplication';\nimport type { IApplicationSpec, IPrivateAPIFixMe } from '../types';\nimport { executeApplication } from './executeApplication';\n\nexport class PlatformApplicationContainer {\n private apps: Record<string, EditorPlatformApplication> = {};\n\n constructor(\n private privateApi: IPrivateAPIFixMe,\n private events: PlatformAppEventEmitter,\n ) {\n this.events.subscribe((event) => {\n switch (event.type) {\n case PlatformAppEvent.HostEvent: {\n if (event.payload.type === EventType.removeAppCompleted) {\n this.events.withEvent(\n this.events.factories.createApplicationRemovedEvent(\n event.payload.appDefinitionId!,\n ),\n () => {\n return this.removeApplication(event.payload.appDefinitionId!);\n },\n );\n }\n break;\n }\n }\n });\n }\n\n public async runApplication(app: IApplicationSpec) {\n const bundle = await this.loadApplication(app);\n const instance = await this.executeApplication(app, bundle);\n\n this.setApplication(app.appDefinitionId, instance);\n\n return instance;\n }\n\n private setApplication(\n appDefId: string,\n instance: EditorPlatformApplication,\n ) {\n this.apps[appDefId] = instance;\n\n this.events.withEvent(\n this.events.factories.createApplicationApiInitEvent(\n appDefId,\n // TODO: both types are set here...\n // @ts-expect-error TODO: fix me\n instance?.api?.private ? 'private' : 'public',\n ),\n () => {\n // NOTE: sometimes I saw this method was called while application was not executed\n this.privateApi.applicationManager.setApplication(instance);\n },\n );\n }\n\n public getApplication(appDefId: string) {\n return this.apps[appDefId];\n }\n\n public getAppDefinitionIds() {\n return Object.keys(this.apps);\n }\n\n private removeApplication(appDefinitionId: string) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.apps[appDefinitionId];\n }\n\n private async loadApplication(app: IApplicationSpec) {\n const url = app.url;\n\n return this.events.withEvent(\n this.events.factories.createApplicationLoadEvent(app, url),\n async () => {\n try {\n return await this.loadApplicationBundle(url);\n } catch (e) {\n throw createEditorPlatformApplicationError(\n EditorPlatformApplicationErrorCode.ApplicationLoadError,\n )\n .withUrl(url)\n .withAppDefinitionId(app.appDefinitionId)\n .withParentError(e as any);\n }\n },\n );\n }\n\n private async loadApplicationBundle(url: string) {\n /**\n * NOTE: we don't use wix http client here\n * because this code is public, while http client is private\n */\n const res = await fetch('url', {\n method: 'GET',\n });\n\n const isSuccessfulResponse = res.status >= 200 && res.status <= 299;\n\n if (!isSuccessfulResponse) {\n throw createEditorPlatformApplicationError(\n EditorPlatformApplicationErrorCode.ApplicationFetchError,\n ).withUrl(url);\n }\n\n return res.text();\n }\n\n private async executeApplication(app: IApplicationSpec, bundle: string) {\n return this.events.withEvent(\n this.events.factories.createApplicationExecuteEvent(app, app.url),\n async () => {\n const { instance } = await executeApplication(this.events, app, bundle);\n return instance;\n },\n );\n }\n}\n","import {\n EnvironmentContext,\n PlatformEnvironment,\n} from '@wix/editor-application-context';\n\nimport { IApplicationSpec, IPrivateAPIFixMe } from '../../types';\nimport {\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n IPlatformAppEvent,\n} from '@wix/public-editor-platform-events';\n\nimport { WorkerEventsBridge } from '../../Events';\n\nimport { PlatformApplicationContainer } from '../../PlatformApplicationContainer';\n\nexport const PLATFORM_WORKER_API_TYPE = 'PLATFORM_WORKER_API';\n\nexport class PlatformWorkerAPI {\n public type = PLATFORM_WORKER_API_TYPE;\n\n #events = new PlatformAppEventEmitter();\n\n #eventsBridge = new WorkerEventsBridge(this.#events);\n #container: PlatformApplicationContainer | null = null;\n #privateAPI: IPrivateAPIFixMe;\n\n #pendingWaiters: ((value: this) => void)[] = [];\n\n async initWorkerEnvironment(\n // TODO: should be Promise response in types\n buildPrivateAPI: (config: any) => IPrivateAPIFixMe,\n ) {\n this.#privateAPI = await buildPrivateAPI({\n // TODO: should be per application (within the container before app execution)\n type: 'EDITOR_ADDON',\n });\n\n await EnvironmentContext.inject({\n environment: PlatformEnvironment.Worker,\n events: this.#events,\n privateApi: this.#privateAPI,\n applicationAPIs: {},\n });\n\n this.#container = new PlatformApplicationContainer(\n this.#privateAPI,\n this.#events,\n );\n\n this.#pendingWaiters.forEach((res) => res(this));\n }\n\n async notify(event: IPlatformPrivateEvent) {\n await this.waitReady();\n\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n\n async runApplication(app: IApplicationSpec) {\n await this.waitReady();\n\n await this.#container!.runApplication(app);\n }\n\n public waitReady(): Promise<this> {\n return new Promise((res) => {\n if (this.#privateAPI) {\n return res(this);\n }\n\n this.#pendingWaiters.push(res);\n });\n }\n}\n"],"names":["BaseError","createErrorBuilder","PlatformAppEvent","PlatformLifecycleEvent","PlatformPrivateEvent","PlatformAppEventEmitter","EditorPlatformApplicationErrorCode","EventType"],"mappings":";;;;;;AAGA,IAAI,yCAAA,qBAA8D,0CAA+C,KAAA;AAC/G,EAAA,0CAAA,CAA2C,sBAAsB,CAAI,GAAA,sBAAA,CAAA;AACrE,EAAO,OAAA,0CAAA,CAAA;AACT,CAAG,EAAA,yCAAA,IAA6C,EAAE,CAAA,CAAA;AAClD,MAAM,8CAA8CA,oCAAU,CAAA;AAAA,EAC5D,QAAQ,EAAC,CAAA;AAAA,EACT,WAAA,CAAY,SAAS,IAAM,EAAA;AACzB,IAAM,KAAA,CAAA,OAAA,EAAS,MAAM,2CAA2C,CAAA,CAAA;AAAA,GAClE;AAAA,EACA,QAAQ,GAAK,EAAA;AACX,IAAA,IAAA,CAAK,KAAQ,GAAA,EAAE,GAAG,IAAA,CAAK,OAAO,GAAI,EAAA,CAAA;AAClC,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAAA,EACA,oBAAoB,eAAiB,EAAA;AACnC,IAAA,IAAA,CAAK,KAAQ,GAAA,E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