@wix/editor-application 1.393.0 → 1.395.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.
- package/dist/cjs/index.js +23 -605
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +23 -602
- package/dist/esm/index.js.map +1 -1
- package/dist/statics/index.js +26 -609
- package/dist/statics/index.js.map +1 -1
- package/dist/types/index.d.ts +18 -192
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +11 -36
- package/dist/cjs/environment-api/index.js +0 -634
- package/dist/cjs/environment-api/index.js.map +0 -1
- package/dist/cjs/platform-frame/index.js +0 -403
- package/dist/cjs/platform-frame/index.js.map +0 -1
- package/dist/cjs/platform-frame-api/index.js +0 -377
- package/dist/cjs/platform-frame-api/index.js.map +0 -1
- package/dist/cjs/platform-worker/index.js +0 -580
- package/dist/cjs/platform-worker/index.js.map +0 -1
- package/dist/cjs/platform-worker-api/index.js +0 -579
- package/dist/cjs/platform-worker-api/index.js.map +0 -1
- package/dist/esm/environment-api/index.js +0 -630
- package/dist/esm/environment-api/index.js.map +0 -1
- package/dist/esm/platform-frame/index.js +0 -401
- package/dist/esm/platform-frame/index.js.map +0 -1
- package/dist/esm/platform-frame-api/index.js +0 -375
- package/dist/esm/platform-frame-api/index.js.map +0 -1
- package/dist/esm/platform-worker/index.js +0 -578
- package/dist/esm/platform-worker/index.js.map +0 -1
- package/dist/esm/platform-worker-api/index.js +0 -577
- package/dist/esm/platform-worker-api/index.js.map +0 -1
- package/dist/statics/environment-api/index.js +0 -636
- package/dist/statics/environment-api/index.js.map +0 -1
- package/dist/statics/platform-frame/index.js +0 -404
- package/dist/statics/platform-frame/index.js.map +0 -1
- package/dist/statics/platform-frame-api/index.js +0 -380
- package/dist/statics/platform-frame-api/index.js.map +0 -1
- package/dist/statics/platform-worker/index.js +0 -581
- package/dist/statics/platform-worker/index.js.map +0 -1
- package/dist/statics/platform-worker-api/index.js +0 -581
- package/dist/statics/platform-worker-api/index.js.map +0 -1
- package/dist/types/environment-api/index.d.ts +0 -59
- package/dist/types/environment-api/index.d.ts.map +0 -1
- package/dist/types/platform-frame/index.d.ts +0 -59
- package/dist/types/platform-frame/index.d.ts.map +0 -1
- package/dist/types/platform-frame-api/index.d.ts +0 -59
- package/dist/types/platform-frame-api/index.d.ts.map +0 -1
- package/dist/types/platform-worker/index.d.ts +0 -59
- package/dist/types/platform-worker/index.d.ts.map +0 -1
- package/dist/types/platform-worker-api/index.d.ts +0 -59
- package/dist/types/platform-worker-api/index.d.ts.map +0 -1
package/dist/statics/index.js
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@wix/public-editor-platform-events'), require('@wix/public-editor-platform-interfaces'), require('@wix/public-editor-platform-errors')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@wix/public-editor-platform-events', '@wix/public-editor-platform-interfaces', '@wix/public-editor-platform-errors'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.EditorPlatformApplicationRuntime = {}, global.publicEditorPlatformEvents, global.publicEditorPlatformInterfaces, global.publicEditorPlatformErrors));
|
|
5
|
-
})(this, (function (exports, publicEditorPlatformEvents, publicEditorPlatformInterfaces, publicEditorPlatformErrors) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@wix/public-editor-platform-events'), require('@wix/public-editor-platform-interfaces'), require('@wix/public-editor-platform-errors'), require('@wix/editor-platform-contexts')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@wix/public-editor-platform-events', '@wix/public-editor-platform-interfaces', '@wix/public-editor-platform-errors', '@wix/editor-platform-contexts'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.EditorPlatformApplicationRuntime = {}, global.publicEditorPlatformEvents, global.publicEditorPlatformInterfaces, global.publicEditorPlatformErrors, global.editorPlatformContexts));
|
|
5
|
+
})(this, (function (exports, publicEditorPlatformEvents, publicEditorPlatformInterfaces, publicEditorPlatformErrors, editorPlatformContexts) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function hash() {
|
|
8
|
+
const _performance = globalThis["performance"];
|
|
9
|
+
if (_performance && _performance.now) {
|
|
10
|
+
return _performance.now();
|
|
11
|
+
}
|
|
12
|
+
let result = "";
|
|
13
|
+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
14
|
+
const charactersLength = characters.length;
|
|
15
|
+
let counter = 0;
|
|
16
|
+
const length = 10;
|
|
17
|
+
while (counter < length) {
|
|
18
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
19
|
+
counter += 1;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
6
23
|
|
|
7
24
|
class ApplicationLifecycle {
|
|
8
25
|
constructor(events) {
|
|
@@ -22,7 +39,7 @@
|
|
|
22
39
|
if (!this.callbacks[event]) {
|
|
23
40
|
this.callbacks[event] = [];
|
|
24
41
|
}
|
|
25
|
-
const id = `${
|
|
42
|
+
const id = `${hash()}`;
|
|
26
43
|
this.callbacks[event].push({
|
|
27
44
|
id,
|
|
28
45
|
fn
|
|
@@ -45,21 +62,12 @@
|
|
|
45
62
|
|
|
46
63
|
var EditorPlatformApplicationErrorCode = /* @__PURE__ */ ((EditorPlatformApplicationErrorCode2) => {
|
|
47
64
|
EditorPlatformApplicationErrorCode2["ApplicationRuntimeError"] = "ApplicationRuntimeError";
|
|
48
|
-
EditorPlatformApplicationErrorCode2["ApplicationCreationError"] = "ApplicationCreationError";
|
|
49
|
-
EditorPlatformApplicationErrorCode2["ApplicationLoadError"] = "ApplicationLoadError";
|
|
50
|
-
EditorPlatformApplicationErrorCode2["ApplicationFetchError"] = "ApplicationFetchError";
|
|
51
|
-
EditorPlatformApplicationErrorCode2["ApplicationExecuteError"] = "ApplicationExecuteError";
|
|
52
|
-
EditorPlatformApplicationErrorCode2["ApplicationWasRemoved"] = "ApplicationWasRemoved";
|
|
53
|
-
EditorPlatformApplicationErrorCode2["UndefinedApiMethod"] = "UndefinedApiMethod";
|
|
54
|
-
EditorPlatformApplicationErrorCode2["ApplicationIsNotMutable"] = "ApplicationIsNotMutable";
|
|
55
|
-
EditorPlatformApplicationErrorCode2["FailedToGetPrivateAPI"] = "FailedToGetPrivateAPI";
|
|
56
|
-
EditorPlatformApplicationErrorCode2["ClientAuthError"] = "ClientAuthError";
|
|
57
65
|
return EditorPlatformApplicationErrorCode2;
|
|
58
66
|
})(EditorPlatformApplicationErrorCode || {});
|
|
59
67
|
class EditorPlatformApplicationError extends publicEditorPlatformErrors.BaseError {
|
|
60
68
|
state = {};
|
|
61
69
|
constructor(message, code) {
|
|
62
|
-
super(message, code, "
|
|
70
|
+
super(message, code, "EP Application Error");
|
|
63
71
|
}
|
|
64
72
|
withUrl(url) {
|
|
65
73
|
this.state = { ...this.state, url };
|
|
@@ -97,8 +105,7 @@
|
|
|
97
105
|
constructor(type, context) {
|
|
98
106
|
this.type = type;
|
|
99
107
|
this.#context = context;
|
|
100
|
-
|
|
101
|
-
this.appDefinitionId = bindings.appDefinitionId;
|
|
108
|
+
this.appDefinitionId = this.#context.getAppDefinitionId();
|
|
102
109
|
const events = this.#context.getEvents();
|
|
103
110
|
this.lifecycle = new ApplicationLifecycle(events);
|
|
104
111
|
events.addEventListener(publicEditorPlatformInterfaces.EventType.removeAppCompleted, (e) => {
|
|
@@ -156,277 +163,6 @@
|
|
|
156
163
|
}
|
|
157
164
|
}
|
|
158
165
|
|
|
159
|
-
var EditorPlatformApplicationContextErrorCode = /* @__PURE__ */ ((EditorPlatformApplicationContextErrorCode2) => {
|
|
160
|
-
EditorPlatformApplicationContextErrorCode2["IncorrectEnvironment"] = "IncorrectEnvironment";
|
|
161
|
-
EditorPlatformApplicationContextErrorCode2["ClientAuthError"] = "ClientAuthError";
|
|
162
|
-
return EditorPlatformApplicationContextErrorCode2;
|
|
163
|
-
})(EditorPlatformApplicationContextErrorCode || {});
|
|
164
|
-
class EditorPlatformApplicationContextError extends publicEditorPlatformErrors.BaseError {
|
|
165
|
-
state = {};
|
|
166
|
-
constructor(message, code) {
|
|
167
|
-
super(message, code, "Editor Platform Application Context Error");
|
|
168
|
-
}
|
|
169
|
-
withUrl(url) {
|
|
170
|
-
this.state = { ...this.state, url };
|
|
171
|
-
return this;
|
|
172
|
-
}
|
|
173
|
-
withAppDefinitionId(appDefinitionId) {
|
|
174
|
-
this.state = { ...this.state, appDefinitionId };
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
const createEditorPlatformApplicationContextError = publicEditorPlatformErrors.createErrorBuilder(EditorPlatformApplicationContextError);
|
|
179
|
-
async function transformEventPayload(eventPayload, privateAPI) {
|
|
180
|
-
if (!eventPayload?.type) {
|
|
181
|
-
return eventPayload;
|
|
182
|
-
}
|
|
183
|
-
switch (eventPayload.type) {
|
|
184
|
-
case "componentSelectionChanged":
|
|
185
|
-
const componentRefs = eventPayload.componentRefs || [];
|
|
186
|
-
const components = await Promise.all(
|
|
187
|
-
componentRefs.map((ref) => {
|
|
188
|
-
return privateAPI.components.getComponent(ref);
|
|
189
|
-
})
|
|
190
|
-
);
|
|
191
|
-
return {
|
|
192
|
-
type: eventPayload.type,
|
|
193
|
-
components
|
|
194
|
-
};
|
|
195
|
-
default:
|
|
196
|
-
return eventPayload;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
class ApplicationBoundEvents {
|
|
200
|
-
constructor(appDefinitionId, events, privateAPI) {
|
|
201
|
-
this.appDefinitionId = appDefinitionId;
|
|
202
|
-
this.privateAPI = privateAPI;
|
|
203
|
-
this.events = events;
|
|
204
|
-
this.subscribe = events.subscribe.bind(events);
|
|
205
|
-
this.commit = events.commit.bind(events);
|
|
206
|
-
this.startTransaction = events.startTransaction.bind(events);
|
|
207
|
-
this.silent = events.silent.bind(events);
|
|
208
|
-
}
|
|
209
|
-
events;
|
|
210
|
-
subscribe;
|
|
211
|
-
commit;
|
|
212
|
-
startTransaction;
|
|
213
|
-
silent;
|
|
214
|
-
notify(event) {
|
|
215
|
-
this.events.notify({
|
|
216
|
-
type: event.type,
|
|
217
|
-
payload: event.payload,
|
|
218
|
-
meta: {
|
|
219
|
-
appDefinitionId: this.appDefinitionId
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
notifyCustomEvent(type, payload) {
|
|
224
|
-
this.notify({
|
|
225
|
-
type: publicEditorPlatformEvents.PlatformAppEvent.CustomEvent,
|
|
226
|
-
payload: {
|
|
227
|
-
...payload,
|
|
228
|
-
type
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* TODO: we should use same interface for all events
|
|
234
|
-
* (subscribe vs addEventListener)
|
|
235
|
-
*/
|
|
236
|
-
addEventListener(eventType, fn) {
|
|
237
|
-
return this.events.subscribe(async (event) => {
|
|
238
|
-
const isAppMatch = event.meta?.appDefinitionId === this.appDefinitionId || event.meta?.appDefinitionId === null;
|
|
239
|
-
const transformPayload = () => transformEventPayload(event.payload, this.privateAPI);
|
|
240
|
-
if (eventType === "*") {
|
|
241
|
-
fn(await transformPayload());
|
|
242
|
-
} else if (event.type === publicEditorPlatformEvents.PlatformAppEvent.CustomEvent) {
|
|
243
|
-
if (eventType === event.payload?.type && !isAppMatch) {
|
|
244
|
-
fn(await transformPayload());
|
|
245
|
-
}
|
|
246
|
-
} else if (event.type === publicEditorPlatformEvents.PlatformAppEvent.HostEvent) {
|
|
247
|
-
if (eventType === event.payload?.type && isAppMatch) {
|
|
248
|
-
fn(await transformPayload());
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
const WAIT_INJECTED_TIMEOUT = 200;
|
|
255
|
-
const WAIT_INJECTED_RETRY_COUNT = 50;
|
|
256
|
-
class ContextInjectionStatus {
|
|
257
|
-
_resolveContextInjected = () => {
|
|
258
|
-
};
|
|
259
|
-
_isInjected = false;
|
|
260
|
-
key;
|
|
261
|
-
constructor(uuid) {
|
|
262
|
-
this.key = `__${uuid}_CONTEXT_INJECTION_STATUS_KEY`;
|
|
263
|
-
if (!globalThis[this.key]) {
|
|
264
|
-
globalThis[this.key] = new Promise((resolve) => {
|
|
265
|
-
this._resolveContextInjected = () => {
|
|
266
|
-
this._isInjected = true;
|
|
267
|
-
resolve();
|
|
268
|
-
};
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
isInjected() {
|
|
273
|
-
return !!this._isInjected;
|
|
274
|
-
}
|
|
275
|
-
resolveInjected() {
|
|
276
|
-
this._resolveContextInjected?.();
|
|
277
|
-
}
|
|
278
|
-
waitInjected() {
|
|
279
|
-
return new Promise((resolve, reject) => {
|
|
280
|
-
let injected = false;
|
|
281
|
-
let timeoutId;
|
|
282
|
-
let retryCount = 0;
|
|
283
|
-
const timeout = () => {
|
|
284
|
-
if (injected) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
timeoutId = setTimeout(() => {
|
|
288
|
-
retryCount++;
|
|
289
|
-
if (retryCount < WAIT_INJECTED_RETRY_COUNT) {
|
|
290
|
-
if (retryCount % 10 === 0) {
|
|
291
|
-
console.log(
|
|
292
|
-
createEditorPlatformApplicationContextError(
|
|
293
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
294
|
-
"contexts are not resolved, still re-trying"
|
|
295
|
-
).withMessage(`try number ${retryCount}`).message
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
timeout();
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
if (!injected) {
|
|
302
|
-
const error = createEditorPlatformApplicationContextError(
|
|
303
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
304
|
-
"contexts are not resolved, threw by timeout"
|
|
305
|
-
);
|
|
306
|
-
reject(error);
|
|
307
|
-
}
|
|
308
|
-
}, WAIT_INJECTED_TIMEOUT);
|
|
309
|
-
};
|
|
310
|
-
timeout();
|
|
311
|
-
const _waitContextInjectedPromise = globalThis[this.key];
|
|
312
|
-
_waitContextInjectedPromise.then(() => {
|
|
313
|
-
injected = true;
|
|
314
|
-
clearTimeout(timeoutId);
|
|
315
|
-
resolve();
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
const ENVIRONMENT_CONTEXT_KEY = "__ENVIRONMENT_CONTEXT_KEY";
|
|
321
|
-
var PlatformEnvironment = /* @__PURE__ */ ((PlatformEnvironment2) => {
|
|
322
|
-
PlatformEnvironment2["Worker"] = "Worker";
|
|
323
|
-
PlatformEnvironment2["Frame"] = "Frame";
|
|
324
|
-
PlatformEnvironment2["ComponentPanel"] = "ComponentPanel";
|
|
325
|
-
return PlatformEnvironment2;
|
|
326
|
-
})(PlatformEnvironment || {});
|
|
327
|
-
class EnvironmentContext {
|
|
328
|
-
constructor(environmentContext) {
|
|
329
|
-
this.environmentContext = environmentContext;
|
|
330
|
-
}
|
|
331
|
-
static status = new ContextInjectionStatus("environment");
|
|
332
|
-
static async inject(context) {
|
|
333
|
-
if (globalThis[ENVIRONMENT_CONTEXT_KEY]) {
|
|
334
|
-
throw createEditorPlatformApplicationContextError(
|
|
335
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
336
|
-
"Environment context already exists and should not be overridden"
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
globalThis[ENVIRONMENT_CONTEXT_KEY] = new EnvironmentContext(context);
|
|
340
|
-
this.status.resolveInjected();
|
|
341
|
-
}
|
|
342
|
-
static async getInstance() {
|
|
343
|
-
await this.status.waitInjected();
|
|
344
|
-
return globalThis[ENVIRONMENT_CONTEXT_KEY];
|
|
345
|
-
}
|
|
346
|
-
getPrivateAPI() {
|
|
347
|
-
return this.environmentContext.privateApi;
|
|
348
|
-
}
|
|
349
|
-
getEvents() {
|
|
350
|
-
return this.environmentContext.events;
|
|
351
|
-
}
|
|
352
|
-
getApplicationAPIs() {
|
|
353
|
-
return this.environmentContext.applicationAPIs ?? {};
|
|
354
|
-
}
|
|
355
|
-
getEnvironment() {
|
|
356
|
-
return this.environmentContext.environment;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
const APPLICATION_CONTEXT_KEY = "__APPLICATION_CONTEXT_KEY";
|
|
360
|
-
class ApplicationContext {
|
|
361
|
-
constructor(applicationContext, environment) {
|
|
362
|
-
this.applicationContext = applicationContext;
|
|
363
|
-
this.environment = environment;
|
|
364
|
-
this.events = new ApplicationBoundEvents(
|
|
365
|
-
this.applicationContext.appDefinitionId,
|
|
366
|
-
this.environment.getEvents(),
|
|
367
|
-
this.environment.getPrivateAPI()
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
-
static status = new ContextInjectionStatus("application");
|
|
371
|
-
/**
|
|
372
|
-
* TODO: use generics for context type
|
|
373
|
-
* - application
|
|
374
|
-
* - editor
|
|
375
|
-
*/
|
|
376
|
-
static async inject(context) {
|
|
377
|
-
const environment = await EnvironmentContext.getInstance();
|
|
378
|
-
if (environment.getEnvironment() !== PlatformEnvironment.Frame) {
|
|
379
|
-
throw createEditorPlatformApplicationContextError(
|
|
380
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
381
|
-
"Application context can be injected only in frame environment"
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
if (globalThis[APPLICATION_CONTEXT_KEY]) {
|
|
385
|
-
throw createEditorPlatformApplicationContextError(
|
|
386
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
387
|
-
"Application context already exists and should not be overridden"
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
globalThis[APPLICATION_CONTEXT_KEY] = new ApplicationContext(
|
|
391
|
-
context,
|
|
392
|
-
await EnvironmentContext.getInstance()
|
|
393
|
-
);
|
|
394
|
-
this.status.resolveInjected();
|
|
395
|
-
}
|
|
396
|
-
static async getInstance() {
|
|
397
|
-
const environment = await EnvironmentContext.getInstance();
|
|
398
|
-
if (environment.getEnvironment() === PlatformEnvironment.Frame) {
|
|
399
|
-
await this.status.waitInjected();
|
|
400
|
-
return globalThis[APPLICATION_CONTEXT_KEY];
|
|
401
|
-
} else {
|
|
402
|
-
return __APPLICATION_CONTEXT_KEY;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
events;
|
|
406
|
-
getAppDefinitionId() {
|
|
407
|
-
return this.applicationContext.appDefinitionId;
|
|
408
|
-
}
|
|
409
|
-
getBindings() {
|
|
410
|
-
return this.applicationContext;
|
|
411
|
-
}
|
|
412
|
-
getEvents() {
|
|
413
|
-
return this.events;
|
|
414
|
-
}
|
|
415
|
-
getPrivateAPI() {
|
|
416
|
-
return this.environment.getPrivateAPI();
|
|
417
|
-
}
|
|
418
|
-
getPrivateApplicationAPI() {
|
|
419
|
-
const appDefinitionId = this.getAppDefinitionId();
|
|
420
|
-
if (!appDefinitionId) {
|
|
421
|
-
throw createEditorPlatformApplicationContextError(
|
|
422
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
423
|
-
"appDefinitionId is not available"
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
return this.environment.getApplicationAPIs()[appDefinitionId];
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
166
|
var ApplicationType = /* @__PURE__ */ ((ApplicationType2) => {
|
|
431
167
|
ApplicationType2["EditorAddon"] = "EDITOR_ADDON";
|
|
432
168
|
ApplicationType2["Platform"] = "PLATFORM";
|
|
@@ -436,7 +172,7 @@
|
|
|
436
172
|
class WixEditorPlatformApplication extends EditorPlatformApplication {
|
|
437
173
|
static async create() {
|
|
438
174
|
return new WixEditorPlatformApplication(
|
|
439
|
-
await ApplicationContext.getInstance()
|
|
175
|
+
await editorPlatformContexts.ApplicationContext.getInstance()
|
|
440
176
|
);
|
|
441
177
|
}
|
|
442
178
|
constructor(context) {
|
|
@@ -446,7 +182,7 @@
|
|
|
446
182
|
|
|
447
183
|
class WixEditorPlatformAddon extends EditorPlatformApplication {
|
|
448
184
|
static async create() {
|
|
449
|
-
const context = await ApplicationContext.getInstance();
|
|
185
|
+
const context = await editorPlatformContexts.ApplicationContext.getInstance();
|
|
450
186
|
return new WixEditorPlatformAddon(context);
|
|
451
187
|
}
|
|
452
188
|
constructor(context) {
|
|
@@ -454,327 +190,8 @@
|
|
|
454
190
|
}
|
|
455
191
|
}
|
|
456
192
|
|
|
457
|
-
class WorkerEventsBridge {
|
|
458
|
-
constructor(platformAppEvents) {
|
|
459
|
-
this.platformAppEvents = platformAppEvents;
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* Notify by event from Worker Manager (platform infrastructure)
|
|
463
|
-
*/
|
|
464
|
-
notify(event) {
|
|
465
|
-
switch (event.type) {
|
|
466
|
-
case publicEditorPlatformEvents.PlatformLifecycleEvent.EditorReady:
|
|
467
|
-
this.platformAppEvents.notify({
|
|
468
|
-
...event,
|
|
469
|
-
// @ts-expect-error TODO: fix me
|
|
470
|
-
type: publicEditorPlatformEvents.PlatformAppEvent.EditorReady
|
|
471
|
-
});
|
|
472
|
-
break;
|
|
473
|
-
case publicEditorPlatformEvents.PlatformPrivateEvent.HostEvent:
|
|
474
|
-
this.platformAppEvents.notify({
|
|
475
|
-
...event,
|
|
476
|
-
type: publicEditorPlatformEvents.PlatformAppEvent.HostEvent
|
|
477
|
-
});
|
|
478
|
-
break;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Subscribe to Worker (Application) event
|
|
483
|
-
*/
|
|
484
|
-
subscribe(cb) {
|
|
485
|
-
this.platformAppEvents.subscribe((event) => {
|
|
486
|
-
cb(event);
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
var PlatformConsumerEnvironmentAPIType = /* @__PURE__ */ ((PlatformConsumerEnvironmentAPIType2) => {
|
|
492
|
-
PlatformConsumerEnvironmentAPIType2["Frame"] = "PLATFORM_FRAME_API";
|
|
493
|
-
PlatformConsumerEnvironmentAPIType2["Worker"] = "PLATFORM_WORKER_API";
|
|
494
|
-
return PlatformConsumerEnvironmentAPIType2;
|
|
495
|
-
})(PlatformConsumerEnvironmentAPIType || {});
|
|
496
|
-
class AbstractEnvironmentAPI {
|
|
497
|
-
constructor(env) {
|
|
498
|
-
this.env = env;
|
|
499
|
-
this.create();
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
const DESIGN_SYSTEM_STYLES_MAP = {
|
|
504
|
-
classic: "https://www.unpkg.com/@wix/design-system/dist/statics/tokens-default.global.css",
|
|
505
|
-
studio: "https://www.unpkg.com/@wix/design-system/dist/statics/tokens-studio.global.css"
|
|
506
|
-
};
|
|
507
|
-
class PlatformFrameAPI extends AbstractEnvironmentAPI {
|
|
508
|
-
type = PlatformConsumerEnvironmentAPIType.Frame;
|
|
509
|
-
#events = new publicEditorPlatformEvents.PlatformAppEventEmitter();
|
|
510
|
-
#eventsBridge = new WorkerEventsBridge(this.#events);
|
|
511
|
-
#privateAPI;
|
|
512
|
-
#applicationPrivateAPI;
|
|
513
|
-
constructor() {
|
|
514
|
-
super(PlatformConsumerEnvironmentAPIType.Frame);
|
|
515
|
-
}
|
|
516
|
-
create() {
|
|
517
|
-
if (typeof globalThis?.document?.head?.prepend === "function") {
|
|
518
|
-
const params = new URL(globalThis.location.href).searchParams;
|
|
519
|
-
const host = params.get("editorType") === "CLASSIC" ? "classic" : "studio";
|
|
520
|
-
const url = DESIGN_SYSTEM_STYLES_MAP[host];
|
|
521
|
-
const isAlreadyLoaded = url && !!document.querySelectorAll(`link[type="text/css"][href="${url}"]`)?.length;
|
|
522
|
-
if (url && !isAlreadyLoaded) {
|
|
523
|
-
const link = document.createElement("link");
|
|
524
|
-
link.setAttribute("rel", "stylesheet");
|
|
525
|
-
link.setAttribute("type", "text/css");
|
|
526
|
-
link.setAttribute("href", url);
|
|
527
|
-
globalThis.document.head.prepend(link);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
async initEnvironment(props) {
|
|
532
|
-
const { applicationPrivateAPI, privateAPI, appDefinitionId } = props;
|
|
533
|
-
this.#applicationPrivateAPI = applicationPrivateAPI;
|
|
534
|
-
this.#privateAPI = privateAPI;
|
|
535
|
-
await EnvironmentContext.inject({
|
|
536
|
-
environment: PlatformEnvironment.Frame,
|
|
537
|
-
privateApi: privateAPI,
|
|
538
|
-
events: this.#events,
|
|
539
|
-
applicationAPIs: {
|
|
540
|
-
[appDefinitionId]: this.#applicationPrivateAPI
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
await ApplicationContext.inject({
|
|
544
|
-
appDefinitionId,
|
|
545
|
-
appDefinitionName: ""
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
notify(event) {
|
|
549
|
-
this.#eventsBridge.notify(event);
|
|
550
|
-
}
|
|
551
|
-
subscribe(cb) {
|
|
552
|
-
this.#eventsBridge.subscribe(cb);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
const APPLICATION_REGISTRY_KEY = "__APPLICATION_REGISTRY_KEY";
|
|
557
|
-
async function executeApplication(events, spec, bundle) {
|
|
558
|
-
const executable = new Function(
|
|
559
|
-
APPLICATION_CONTEXT_KEY,
|
|
560
|
-
APPLICATION_REGISTRY_KEY,
|
|
561
|
-
bundle
|
|
562
|
-
);
|
|
563
|
-
let instance;
|
|
564
|
-
const applicationRegistryCallback = (_instance) => {
|
|
565
|
-
if (instance) {
|
|
566
|
-
throw createEditorPlatformApplicationError(
|
|
567
|
-
EditorPlatformApplicationErrorCode.ApplicationExecuteError,
|
|
568
|
-
"Application registry called more than once"
|
|
569
|
-
).withAppDefinitionId(spec.appDefinitionId);
|
|
570
|
-
}
|
|
571
|
-
if (_instance.type !== spec.type) {
|
|
572
|
-
throw createEditorPlatformApplicationError(
|
|
573
|
-
EditorPlatformApplicationErrorCode.ApplicationExecuteError,
|
|
574
|
-
"Application has different type"
|
|
575
|
-
).withMessage("expected type", spec.type).withMessage("received type", _instance.type);
|
|
576
|
-
}
|
|
577
|
-
instance = _instance;
|
|
578
|
-
};
|
|
579
|
-
try {
|
|
580
|
-
const context = { ...spec };
|
|
581
|
-
executable.call(
|
|
582
|
-
null,
|
|
583
|
-
new ApplicationContext(context, await EnvironmentContext.getInstance()),
|
|
584
|
-
applicationRegistryCallback
|
|
585
|
-
);
|
|
586
|
-
} catch (e) {
|
|
587
|
-
throw createEditorPlatformApplicationError(
|
|
588
|
-
EditorPlatformApplicationErrorCode.ApplicationExecuteError,
|
|
589
|
-
e.message
|
|
590
|
-
).withAppDefinitionId(spec.appDefinitionId).withParentError(e);
|
|
591
|
-
}
|
|
592
|
-
return new Promise((resolve, reject) => {
|
|
593
|
-
const unsubscribe = events.subscribe((event) => {
|
|
594
|
-
const timeoutId = setTimeout(() => {
|
|
595
|
-
clearTimeout(timeoutId);
|
|
596
|
-
unsubscribe();
|
|
597
|
-
if (!instance) {
|
|
598
|
-
reject(
|
|
599
|
-
createEditorPlatformApplicationError(
|
|
600
|
-
EditorPlatformApplicationErrorCode.ApplicationExecuteError,
|
|
601
|
-
"Application registry was not called, threw by timeout"
|
|
602
|
-
).withAppDefinitionId(spec.appDefinitionId)
|
|
603
|
-
);
|
|
604
|
-
}
|
|
605
|
-
}, 5e3);
|
|
606
|
-
if (event.type === publicEditorPlatformEvents.PlatformAppEvent.ApplicationInit && event.meta.appDefinitionId === spec.appDefinitionId) {
|
|
607
|
-
clearTimeout(timeoutId);
|
|
608
|
-
unsubscribe();
|
|
609
|
-
if (!instance) {
|
|
610
|
-
reject(
|
|
611
|
-
createEditorPlatformApplicationError(
|
|
612
|
-
EditorPlatformApplicationErrorCode.ApplicationExecuteError,
|
|
613
|
-
"Application registry was not called"
|
|
614
|
-
).withAppDefinitionId(spec.appDefinitionId)
|
|
615
|
-
);
|
|
616
|
-
}
|
|
617
|
-
resolve({ instance });
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
class PlatformApplicationContainer {
|
|
624
|
-
#apps = {};
|
|
625
|
-
#privateAPI;
|
|
626
|
-
#events;
|
|
627
|
-
constructor(privateApi, events) {
|
|
628
|
-
this.#privateAPI = privateApi;
|
|
629
|
-
this.#events = events;
|
|
630
|
-
this.#events.subscribe((event) => {
|
|
631
|
-
switch (event.type) {
|
|
632
|
-
case publicEditorPlatformEvents.PlatformAppEvent.HostEvent: {
|
|
633
|
-
if (event.payload.type === publicEditorPlatformInterfaces.EventType.removeAppCompleted) {
|
|
634
|
-
void this.#events.withEvent(
|
|
635
|
-
this.#events.factories.createApplicationRemovedEvent(
|
|
636
|
-
event.payload.appDefinitionId
|
|
637
|
-
),
|
|
638
|
-
() => {
|
|
639
|
-
return this.removeApplication(event.payload.appDefinitionId);
|
|
640
|
-
}
|
|
641
|
-
);
|
|
642
|
-
}
|
|
643
|
-
break;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
async runApplication(appSpec) {
|
|
649
|
-
const bundle = await this.loadApplication(appSpec);
|
|
650
|
-
const instance = await this.executeApplication(appSpec, bundle);
|
|
651
|
-
this.setApplication(appSpec.appDefinitionId, instance);
|
|
652
|
-
return instance;
|
|
653
|
-
}
|
|
654
|
-
setApplication(appDefId, instance) {
|
|
655
|
-
this.#apps[appDefId] = instance;
|
|
656
|
-
void this.#events.withEvent(
|
|
657
|
-
this.#events.factories.createApplicationApiInitEvent(
|
|
658
|
-
appDefId,
|
|
659
|
-
// TODO: both types are set here...
|
|
660
|
-
// @ts-expect-error TODO: fix me
|
|
661
|
-
instance?.api?.private ? "private" : "public"
|
|
662
|
-
),
|
|
663
|
-
() => {
|
|
664
|
-
this.#privateAPI.applicationManager.setApplication(instance);
|
|
665
|
-
}
|
|
666
|
-
);
|
|
667
|
-
}
|
|
668
|
-
getApplication(appDefId) {
|
|
669
|
-
return this.#apps[appDefId];
|
|
670
|
-
}
|
|
671
|
-
getAppDefinitionIds() {
|
|
672
|
-
return Object.keys(this.#apps);
|
|
673
|
-
}
|
|
674
|
-
removeApplication(appDefinitionId) {
|
|
675
|
-
delete this.#apps[appDefinitionId];
|
|
676
|
-
}
|
|
677
|
-
async loadApplication(appSpec) {
|
|
678
|
-
const url = appSpec.url;
|
|
679
|
-
return this.#events.withEvent(
|
|
680
|
-
this.#events.factories.createApplicationLoadEvent(appSpec, url),
|
|
681
|
-
async () => {
|
|
682
|
-
try {
|
|
683
|
-
return await this.loadApplicationBundle(url);
|
|
684
|
-
} catch (e) {
|
|
685
|
-
throw createEditorPlatformApplicationError(
|
|
686
|
-
EditorPlatformApplicationErrorCode.ApplicationLoadError
|
|
687
|
-
).withUrl(url).withAppDefinitionId(appSpec.appDefinitionId).withParentError(e);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
async loadApplicationBundle(url) {
|
|
693
|
-
const res = await fetch(url, {
|
|
694
|
-
method: "GET"
|
|
695
|
-
});
|
|
696
|
-
const isSuccessfulResponse = res.status >= 200 && res.status <= 299;
|
|
697
|
-
if (!isSuccessfulResponse) {
|
|
698
|
-
throw createEditorPlatformApplicationError(
|
|
699
|
-
EditorPlatformApplicationErrorCode.ApplicationFetchError
|
|
700
|
-
).withUrl(url);
|
|
701
|
-
}
|
|
702
|
-
return res.text();
|
|
703
|
-
}
|
|
704
|
-
async executeApplication(appSpec, bundle) {
|
|
705
|
-
return this.#events.withEvent(
|
|
706
|
-
this.#events.factories.createApplicationExecuteEvent(
|
|
707
|
-
appSpec,
|
|
708
|
-
appSpec.url
|
|
709
|
-
),
|
|
710
|
-
async () => {
|
|
711
|
-
const { instance } = await executeApplication(
|
|
712
|
-
this.#events,
|
|
713
|
-
appSpec,
|
|
714
|
-
bundle
|
|
715
|
-
);
|
|
716
|
-
return instance;
|
|
717
|
-
}
|
|
718
|
-
);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
class PlatformWorkerAPI extends AbstractEnvironmentAPI {
|
|
723
|
-
type = PlatformConsumerEnvironmentAPIType.Worker;
|
|
724
|
-
#events = new publicEditorPlatformEvents.PlatformAppEventEmitter();
|
|
725
|
-
#eventsBridge = new WorkerEventsBridge(this.#events);
|
|
726
|
-
#container = null;
|
|
727
|
-
#privateAPI;
|
|
728
|
-
#pendingWaiters = [];
|
|
729
|
-
constructor() {
|
|
730
|
-
super(PlatformConsumerEnvironmentAPIType.Worker);
|
|
731
|
-
}
|
|
732
|
-
create() {
|
|
733
|
-
}
|
|
734
|
-
async initEnvironment(props) {
|
|
735
|
-
const { buildPrivateAPI } = props;
|
|
736
|
-
this.#privateAPI = await buildPrivateAPI({
|
|
737
|
-
// TODO: should be per application (within the container before app execution)
|
|
738
|
-
type: "EDITOR_ADDON"
|
|
739
|
-
});
|
|
740
|
-
await EnvironmentContext.inject({
|
|
741
|
-
environment: PlatformEnvironment.Worker,
|
|
742
|
-
events: this.#events,
|
|
743
|
-
privateApi: this.#privateAPI,
|
|
744
|
-
applicationAPIs: {}
|
|
745
|
-
});
|
|
746
|
-
this.#container = new PlatformApplicationContainer(
|
|
747
|
-
this.#privateAPI,
|
|
748
|
-
this.#events
|
|
749
|
-
);
|
|
750
|
-
this.#pendingWaiters.forEach((res) => res(this));
|
|
751
|
-
}
|
|
752
|
-
async notify(event) {
|
|
753
|
-
await this.waitReady();
|
|
754
|
-
this.#eventsBridge.notify(event);
|
|
755
|
-
}
|
|
756
|
-
subscribe(cb) {
|
|
757
|
-
this.#eventsBridge.subscribe(cb);
|
|
758
|
-
}
|
|
759
|
-
async runApplication(app) {
|
|
760
|
-
await this.waitReady();
|
|
761
|
-
await this.#container.runApplication(app);
|
|
762
|
-
}
|
|
763
|
-
waitReady() {
|
|
764
|
-
return new Promise((res) => {
|
|
765
|
-
if (this.#privateAPI) {
|
|
766
|
-
return res(this);
|
|
767
|
-
}
|
|
768
|
-
this.#pendingWaiters.push(res);
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
193
|
exports.ApplicationType = ApplicationType;
|
|
774
194
|
exports.EditorPlatformApplication = EditorPlatformApplication;
|
|
775
|
-
exports.PlatformConsumerEnvironmentAPIType = PlatformConsumerEnvironmentAPIType;
|
|
776
|
-
exports.PlatformFrameAPI = PlatformFrameAPI;
|
|
777
|
-
exports.PlatformWorkerAPI = PlatformWorkerAPI;
|
|
778
195
|
exports.WixEditorPlatformAddon = WixEditorPlatformAddon;
|
|
779
196
|
exports.WixEditorPlatformApplication = WixEditorPlatformApplication;
|
|
780
197
|
|