@wix/editor 1.335.0 → 1.337.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 +212 -514
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +206 -508
- package/dist/esm/index.js.map +1 -1
- package/dist/statics/index.js +214 -514
- package/dist/statics/index.js.map +1 -1
- package/dist/types/index.d.ts +58 -183
- package/package.json +4 -5
package/dist/statics/index.js
CHANGED
|
@@ -1,279 +1,10 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@wix/
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@wix/
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.editorPlatformSdk = {}, global.
|
|
5
|
-
})(this, (function (exports,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@wix/editor-platform-environment-api'), require('@wix/editor-platform-contexts'), require('@wix/public-editor-platform-errors'), require('@wix/sdk-runtime/host-modules')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@wix/editor-platform-environment-api', '@wix/editor-platform-contexts', '@wix/public-editor-platform-errors', '@wix/sdk-runtime/host-modules'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.editorPlatformSdk = {}, global.editorPlatformEnvironmentApi, global.editorPlatformContexts, global.publicEditorPlatformErrors, global.hostModules));
|
|
5
|
+
})(this, (function (exports, editorPlatformEnvironmentApi, editorPlatformContexts, publicEditorPlatformErrors, hostModules) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
EditorPlatformApplicationContextErrorCode2["IncorrectEnvironment"] = "IncorrectEnvironment";
|
|
9
|
-
EditorPlatformApplicationContextErrorCode2["ClientAuthError"] = "ClientAuthError";
|
|
10
|
-
return EditorPlatformApplicationContextErrorCode2;
|
|
11
|
-
})(EditorPlatformApplicationContextErrorCode || {});
|
|
12
|
-
class EditorPlatformApplicationContextError extends publicEditorPlatformErrors.BaseError {
|
|
13
|
-
state = {};
|
|
14
|
-
constructor(message, code) {
|
|
15
|
-
super(message, code, "Editor Platform Application Context Error");
|
|
16
|
-
}
|
|
17
|
-
withUrl(url) {
|
|
18
|
-
this.state = { ...this.state, url };
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
withAppDefinitionId(appDefinitionId) {
|
|
22
|
-
this.state = { ...this.state, appDefinitionId };
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const createEditorPlatformApplicationContextError = publicEditorPlatformErrors.createErrorBuilder(EditorPlatformApplicationContextError);
|
|
27
|
-
async function transformEventPayload(eventPayload, privateAPI) {
|
|
28
|
-
if (!eventPayload?.type) {
|
|
29
|
-
return eventPayload;
|
|
30
|
-
}
|
|
31
|
-
switch (eventPayload.type) {
|
|
32
|
-
case "componentSelectionChanged":
|
|
33
|
-
const componentRefs = eventPayload.componentRefs || [];
|
|
34
|
-
const components = await Promise.all(
|
|
35
|
-
componentRefs.map((ref) => {
|
|
36
|
-
return privateAPI.components.getComponent(ref);
|
|
37
|
-
})
|
|
38
|
-
);
|
|
39
|
-
return {
|
|
40
|
-
type: eventPayload.type,
|
|
41
|
-
components
|
|
42
|
-
};
|
|
43
|
-
default:
|
|
44
|
-
return eventPayload;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
class ApplicationBoundEvents {
|
|
48
|
-
constructor(appDefinitionId, events, privateAPI) {
|
|
49
|
-
this.appDefinitionId = appDefinitionId;
|
|
50
|
-
this.privateAPI = privateAPI;
|
|
51
|
-
this.events = events;
|
|
52
|
-
this.subscribe = events.subscribe.bind(events);
|
|
53
|
-
this.commit = events.commit.bind(events);
|
|
54
|
-
this.startTransaction = events.startTransaction.bind(events);
|
|
55
|
-
this.silent = events.silent.bind(events);
|
|
56
|
-
}
|
|
57
|
-
events;
|
|
58
|
-
subscribe;
|
|
59
|
-
commit;
|
|
60
|
-
startTransaction;
|
|
61
|
-
silent;
|
|
62
|
-
notify(event) {
|
|
63
|
-
this.events.notify({
|
|
64
|
-
type: event.type,
|
|
65
|
-
payload: event.payload,
|
|
66
|
-
meta: {
|
|
67
|
-
appDefinitionId: this.appDefinitionId
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
notifyCustomEvent(type, payload) {
|
|
72
|
-
this.notify({
|
|
73
|
-
type: publicEditorPlatformEvents.PlatformAppEvent.CustomEvent,
|
|
74
|
-
payload: {
|
|
75
|
-
...payload,
|
|
76
|
-
type
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* TODO: we should use same interface for all events
|
|
82
|
-
* (subscribe vs addEventListener)
|
|
83
|
-
*/
|
|
84
|
-
addEventListener(eventType, fn) {
|
|
85
|
-
return this.events.subscribe(async (event) => {
|
|
86
|
-
const isAppMatch = event.meta?.appDefinitionId === this.appDefinitionId || event.meta?.appDefinitionId === null;
|
|
87
|
-
const transformPayload = () => transformEventPayload(event.payload, this.privateAPI);
|
|
88
|
-
if (eventType === "*") {
|
|
89
|
-
fn(await transformPayload());
|
|
90
|
-
} else if (event.type === publicEditorPlatformEvents.PlatformAppEvent.CustomEvent) {
|
|
91
|
-
if (eventType === event.payload?.type && !isAppMatch) {
|
|
92
|
-
fn(await transformPayload());
|
|
93
|
-
}
|
|
94
|
-
} else if (event.type === publicEditorPlatformEvents.PlatformAppEvent.HostEvent) {
|
|
95
|
-
if (eventType === event.payload?.type && isAppMatch) {
|
|
96
|
-
fn(await transformPayload());
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
const WAIT_INJECTED_TIMEOUT = 200;
|
|
103
|
-
const WAIT_INJECTED_RETRY_COUNT = 50;
|
|
104
|
-
class ContextInjectionStatus {
|
|
105
|
-
_resolveContextInjected = () => {
|
|
106
|
-
};
|
|
107
|
-
_isInjected = false;
|
|
108
|
-
key;
|
|
109
|
-
constructor(uuid) {
|
|
110
|
-
this.key = `__${uuid}_CONTEXT_INJECTION_STATUS_KEY`;
|
|
111
|
-
if (!globalThis[this.key]) {
|
|
112
|
-
globalThis[this.key] = new Promise((resolve) => {
|
|
113
|
-
this._resolveContextInjected = () => {
|
|
114
|
-
this._isInjected = true;
|
|
115
|
-
resolve();
|
|
116
|
-
};
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
isInjected() {
|
|
121
|
-
return !!this._isInjected;
|
|
122
|
-
}
|
|
123
|
-
resolveInjected() {
|
|
124
|
-
this._resolveContextInjected?.();
|
|
125
|
-
}
|
|
126
|
-
waitInjected() {
|
|
127
|
-
return new Promise((resolve, reject) => {
|
|
128
|
-
let injected = false;
|
|
129
|
-
let timeoutId;
|
|
130
|
-
let retryCount = 0;
|
|
131
|
-
const timeout = () => {
|
|
132
|
-
if (injected) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
timeoutId = setTimeout(() => {
|
|
136
|
-
retryCount++;
|
|
137
|
-
if (retryCount < WAIT_INJECTED_RETRY_COUNT) {
|
|
138
|
-
if (retryCount % 10 === 0) {
|
|
139
|
-
console.log(
|
|
140
|
-
createEditorPlatformApplicationContextError(
|
|
141
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
142
|
-
"contexts are not resolved, still re-trying"
|
|
143
|
-
).withMessage(`try number ${retryCount}`).message
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
timeout();
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (!injected) {
|
|
150
|
-
const error = createEditorPlatformApplicationContextError(
|
|
151
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
152
|
-
"contexts are not resolved, threw by timeout"
|
|
153
|
-
);
|
|
154
|
-
reject(error);
|
|
155
|
-
}
|
|
156
|
-
}, WAIT_INJECTED_TIMEOUT);
|
|
157
|
-
};
|
|
158
|
-
timeout();
|
|
159
|
-
const _waitContextInjectedPromise = globalThis[this.key];
|
|
160
|
-
_waitContextInjectedPromise.then(() => {
|
|
161
|
-
injected = true;
|
|
162
|
-
clearTimeout(timeoutId);
|
|
163
|
-
resolve();
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
const ENVIRONMENT_CONTEXT_KEY = "__ENVIRONMENT_CONTEXT_KEY";
|
|
169
|
-
var PlatformEnvironment = /* @__PURE__ */ ((PlatformEnvironment2) => {
|
|
170
|
-
PlatformEnvironment2["Worker"] = "Worker";
|
|
171
|
-
PlatformEnvironment2["Frame"] = "Frame";
|
|
172
|
-
PlatformEnvironment2["ComponentPanel"] = "ComponentPanel";
|
|
173
|
-
return PlatformEnvironment2;
|
|
174
|
-
})(PlatformEnvironment || {});
|
|
175
|
-
class EnvironmentContext {
|
|
176
|
-
constructor(environmentContext) {
|
|
177
|
-
this.environmentContext = environmentContext;
|
|
178
|
-
}
|
|
179
|
-
static status = new ContextInjectionStatus("environment");
|
|
180
|
-
static async inject(context) {
|
|
181
|
-
if (globalThis[ENVIRONMENT_CONTEXT_KEY]) {
|
|
182
|
-
throw createEditorPlatformApplicationContextError(
|
|
183
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
184
|
-
"Environment context already exists and should not be overridden"
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
globalThis[ENVIRONMENT_CONTEXT_KEY] = new EnvironmentContext(context);
|
|
188
|
-
this.status.resolveInjected();
|
|
189
|
-
}
|
|
190
|
-
static async getInstance() {
|
|
191
|
-
await this.status.waitInjected();
|
|
192
|
-
return globalThis[ENVIRONMENT_CONTEXT_KEY];
|
|
193
|
-
}
|
|
194
|
-
getPrivateAPI() {
|
|
195
|
-
return this.environmentContext.privateApi;
|
|
196
|
-
}
|
|
197
|
-
getEvents() {
|
|
198
|
-
return this.environmentContext.events;
|
|
199
|
-
}
|
|
200
|
-
getApplicationAPIs() {
|
|
201
|
-
return this.environmentContext.applicationAPIs ?? {};
|
|
202
|
-
}
|
|
203
|
-
getEnvironment() {
|
|
204
|
-
return this.environmentContext.environment;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
const APPLICATION_CONTEXT_KEY = "__APPLICATION_CONTEXT_KEY";
|
|
208
|
-
class ApplicationContext {
|
|
209
|
-
constructor(applicationContext, environment) {
|
|
210
|
-
this.applicationContext = applicationContext;
|
|
211
|
-
this.environment = environment;
|
|
212
|
-
this.events = new ApplicationBoundEvents(
|
|
213
|
-
this.applicationContext.appDefinitionId,
|
|
214
|
-
this.environment.getEvents(),
|
|
215
|
-
this.environment.getPrivateAPI()
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
static status = new ContextInjectionStatus("application");
|
|
219
|
-
/**
|
|
220
|
-
* TODO: use generics for context type
|
|
221
|
-
* - application
|
|
222
|
-
* - editor
|
|
223
|
-
*/
|
|
224
|
-
static async inject(context) {
|
|
225
|
-
const environment = await EnvironmentContext.getInstance();
|
|
226
|
-
if (environment.getEnvironment() !== PlatformEnvironment.Frame) {
|
|
227
|
-
throw createEditorPlatformApplicationContextError(
|
|
228
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
229
|
-
"Application context can be injected only in frame environment"
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
if (globalThis[APPLICATION_CONTEXT_KEY]) {
|
|
233
|
-
throw createEditorPlatformApplicationContextError(
|
|
234
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
235
|
-
"Application context already exists and should not be overridden"
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
globalThis[APPLICATION_CONTEXT_KEY] = new ApplicationContext(
|
|
239
|
-
context,
|
|
240
|
-
await EnvironmentContext.getInstance()
|
|
241
|
-
);
|
|
242
|
-
this.status.resolveInjected();
|
|
243
|
-
}
|
|
244
|
-
static async getInstance() {
|
|
245
|
-
const environment = await EnvironmentContext.getInstance();
|
|
246
|
-
if (environment.getEnvironment() === PlatformEnvironment.Frame) {
|
|
247
|
-
await this.status.waitInjected();
|
|
248
|
-
return globalThis[APPLICATION_CONTEXT_KEY];
|
|
249
|
-
} else {
|
|
250
|
-
return __APPLICATION_CONTEXT_KEY;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
events;
|
|
254
|
-
getAppDefinitionId() {
|
|
255
|
-
return this.applicationContext.appDefinitionId;
|
|
256
|
-
}
|
|
257
|
-
getBindings() {
|
|
258
|
-
return this.applicationContext;
|
|
259
|
-
}
|
|
260
|
-
getEvents() {
|
|
261
|
-
return this.events;
|
|
262
|
-
}
|
|
263
|
-
getPrivateAPI() {
|
|
264
|
-
return this.environment.getPrivateAPI();
|
|
265
|
-
}
|
|
266
|
-
getPrivateApplicationAPI() {
|
|
267
|
-
const appDefinitionId = this.getAppDefinitionId();
|
|
268
|
-
if (!appDefinitionId) {
|
|
269
|
-
throw createEditorPlatformApplicationContextError(
|
|
270
|
-
EditorPlatformApplicationContextErrorCode.IncorrectEnvironment,
|
|
271
|
-
"appDefinitionId is not available"
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
return this.environment.getApplicationAPIs()[appDefinitionId];
|
|
275
|
-
}
|
|
276
|
-
}
|
|
7
|
+
new editorPlatformEnvironmentApi.EditorPlatformContextEnvironment().expose();
|
|
277
8
|
|
|
278
9
|
class EditorPlatformSDKAuthError extends publicEditorPlatformErrors.BaseError {
|
|
279
10
|
state = {};
|
|
@@ -296,7 +27,7 @@
|
|
|
296
27
|
let instance;
|
|
297
28
|
return {
|
|
298
29
|
getAuthHeaders: async () => {
|
|
299
|
-
const context = await ApplicationContext.getInstance();
|
|
30
|
+
const context = await editorPlatformContexts.ApplicationContext.getInstance();
|
|
300
31
|
const bindings = context.getBindings();
|
|
301
32
|
const privateAPI = context.getPrivateAPI();
|
|
302
33
|
if (!bindings.appDefinitionId) {
|
|
@@ -334,118 +65,110 @@
|
|
|
334
65
|
};
|
|
335
66
|
};
|
|
336
67
|
|
|
337
|
-
const INIT_KEY = "_EP_TRANSPORT_INIT_KEY";
|
|
338
|
-
if (!globalThis[INIT_KEY]) {
|
|
339
|
-
const isWorker = typeof importScripts === "function";
|
|
340
|
-
if (isWorker) {
|
|
341
|
-
editorPlatformTransport.WorkerConsumerEndpoint.exposeAPI(new platformWorkerApi.PlatformWorkerAPI());
|
|
342
|
-
} else {
|
|
343
|
-
editorPlatformTransport.IFrameConsumerEndpoint.exposeAPI(new platformFrameApi.PlatformFrameAPI());
|
|
344
|
-
}
|
|
345
|
-
globalThis[INIT_KEY] = true;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
68
|
class PlatformSDKShape {
|
|
349
|
-
constructor(namespace,
|
|
69
|
+
constructor(namespace, shapeConstructor) {
|
|
350
70
|
this.namespace = namespace;
|
|
351
|
-
this.
|
|
71
|
+
this.shapeConstructor = shapeConstructor;
|
|
352
72
|
}
|
|
353
73
|
build() {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
return async (...args) => {
|
|
361
|
-
const [environmentContext, applicationContext] = await Promise.all([
|
|
362
|
-
host.environmentContext,
|
|
363
|
-
host.applicationContext
|
|
364
|
-
]);
|
|
365
|
-
return value({
|
|
366
|
-
environmentContext,
|
|
367
|
-
applicationContext
|
|
368
|
-
})(...args);
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
return async (...args) => {
|
|
372
|
-
const [environmentContext, applicationContext] = await Promise.all([
|
|
373
|
-
EnvironmentContext.getInstance(),
|
|
374
|
-
ApplicationContext.getInstance()
|
|
375
|
-
]);
|
|
376
|
-
return value({
|
|
377
|
-
environmentContext,
|
|
378
|
-
applicationContext
|
|
379
|
-
})(...args);
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
])
|
|
383
|
-
)
|
|
74
|
+
const instance = new this.shapeConstructor();
|
|
75
|
+
const methods = Object.getOwnPropertyNames(
|
|
76
|
+
Object.getPrototypeOf(instance)
|
|
77
|
+
).filter(
|
|
78
|
+
(prop) => prop !== "constructor" && typeof // @ts-expect-error
|
|
79
|
+
instance[prop] === "function"
|
|
384
80
|
);
|
|
81
|
+
const api = methods.reduce((acc, method) => {
|
|
82
|
+
return {
|
|
83
|
+
...acc,
|
|
84
|
+
[method]: (host) => {
|
|
85
|
+
if (host?.applicationContext) {
|
|
86
|
+
const _instance = instance.withApplicationContext(
|
|
87
|
+
host.applicationContext
|
|
88
|
+
);
|
|
89
|
+
return _instance[method].bind(_instance);
|
|
90
|
+
} else {
|
|
91
|
+
return instance[method].bind(instance);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}, {});
|
|
96
|
+
return hostModules.createHostModule(api);
|
|
385
97
|
}
|
|
386
98
|
}
|
|
387
99
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
appDefinitionId
|
|
399
|
-
);
|
|
400
|
-
};
|
|
401
|
-
},
|
|
402
|
-
getAppInstance({ applicationContext }) {
|
|
403
|
-
return async () => {
|
|
404
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
405
|
-
const bindings = applicationContext.getBindings();
|
|
406
|
-
return privateAPI.info.getAppInstance(bindings.appDefinitionId);
|
|
407
|
-
};
|
|
100
|
+
class BaseSDKShape {
|
|
101
|
+
/**
|
|
102
|
+
* note, constructor might be called multiple times
|
|
103
|
+
* because of the context override
|
|
104
|
+
*/
|
|
105
|
+
constructor(overrideApplicationContext = null) {
|
|
106
|
+
this.overrideApplicationContext = overrideApplicationContext;
|
|
107
|
+
}
|
|
108
|
+
getApplicationContext() {
|
|
109
|
+
return this.overrideApplicationContext ? this.overrideApplicationContext : editorPlatformContexts.ApplicationContext.getInstance();
|
|
408
110
|
}
|
|
409
|
-
|
|
410
|
-
|
|
111
|
+
async getEnvironmentContext() {
|
|
112
|
+
return (await this.getApplicationContext()).getEnvironmentContext();
|
|
113
|
+
}
|
|
114
|
+
async getPlatformPrivateAPI() {
|
|
115
|
+
return (await this.getApplicationContext()).getPrivateAPI();
|
|
116
|
+
}
|
|
117
|
+
async getContextBindings() {
|
|
118
|
+
return (await this.getApplicationContext()).getBindings();
|
|
119
|
+
}
|
|
120
|
+
withApplicationContext(applicationContext) {
|
|
121
|
+
return new this.constructor(applicationContext);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
411
124
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
return
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
125
|
+
class ApplicationSDKShape extends BaseSDKShape {
|
|
126
|
+
async getPrivateAPI() {
|
|
127
|
+
return (await this.getApplicationContext()).getPrivateApplicationAPI();
|
|
128
|
+
}
|
|
129
|
+
async getPublicAPI(appDefinitionId) {
|
|
130
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
131
|
+
return privateAPI.applicationManager.getPublicApplicationAPI(
|
|
132
|
+
appDefinitionId
|
|
133
|
+
);
|
|
421
134
|
}
|
|
422
|
-
|
|
423
|
-
|
|
135
|
+
async getAppInstance() {
|
|
136
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
137
|
+
const bindings = await this.getContextBindings();
|
|
138
|
+
return privateAPI.info.getAppInstance(bindings.appDefinitionId);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
var index$5 = new PlatformSDKShape("application", ApplicationSDKShape).build();
|
|
424
142
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
143
|
+
class ComponentsSDKShape extends BaseSDKShape {
|
|
144
|
+
async getSelectedComponents() {
|
|
145
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
146
|
+
const refs = await privateAPI.components.getSelectedComponents();
|
|
147
|
+
return Promise.all(
|
|
148
|
+
refs.map((ref) => privateAPI.components.getComponent(ref))
|
|
149
|
+
);
|
|
430
150
|
}
|
|
431
|
-
}
|
|
432
|
-
var
|
|
151
|
+
}
|
|
152
|
+
var components = new PlatformSDKShape("components", ComponentsSDKShape).build();
|
|
433
153
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
return
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
154
|
+
class EventsSDKShape extends BaseSDKShape {
|
|
155
|
+
async addEventListener(name, cb) {
|
|
156
|
+
return (await this.getApplicationContext()).getEvents().addEventListener(name, cb);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
var index$4 = new PlatformSDKShape("events", EventsSDKShape).build();
|
|
160
|
+
|
|
161
|
+
class InfoSDKShape extends BaseSDKShape {
|
|
162
|
+
async getViewMode() {
|
|
163
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
164
|
+
return privateAPI.info.getViewMode();
|
|
165
|
+
}
|
|
166
|
+
async getLanguageCode() {
|
|
167
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
168
|
+
return privateAPI.info.getLanguageCode();
|
|
446
169
|
}
|
|
447
|
-
}
|
|
448
|
-
var index$
|
|
170
|
+
}
|
|
171
|
+
var index$3 = new PlatformSDKShape("info", InfoSDKShape).build();
|
|
449
172
|
|
|
450
173
|
var WidgetShapeErrorCode = /* @__PURE__ */ ((WidgetShapeErrorCode2) => {
|
|
451
174
|
WidgetShapeErrorCode2["UndefinedCompRef"] = "UndefinedCompRef";
|
|
@@ -458,31 +181,28 @@
|
|
|
458
181
|
}
|
|
459
182
|
const createWidgetShapeError = publicEditorPlatformErrors.createErrorBuilder(WidgetShapeError);
|
|
460
183
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
return
|
|
479
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
480
|
-
const compRef = await getSelectedComponentRef();
|
|
481
|
-
await privateAPI.customElement.setAttribute(compRef, propName, value);
|
|
482
|
-
};
|
|
184
|
+
class WidgetSDKShape extends BaseSDKShape {
|
|
185
|
+
async getProp(propName) {
|
|
186
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
187
|
+
const compRef = await this.#getSelectedComponentRef();
|
|
188
|
+
return privateAPI.customElement.getAttribute(compRef, propName);
|
|
189
|
+
}
|
|
190
|
+
async setProp(propName, value) {
|
|
191
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
192
|
+
const compRef = await this.#getSelectedComponentRef();
|
|
193
|
+
await privateAPI.customElement.setAttribute(compRef, propName, value);
|
|
194
|
+
}
|
|
195
|
+
async #getSelectedComponentRef() {
|
|
196
|
+
const selected = await components.getSelectedComponents();
|
|
197
|
+
const compRef = selected[0]?.compRef;
|
|
198
|
+
if (!compRef) {
|
|
199
|
+
throw createWidgetShapeError(WidgetShapeErrorCode.UndefinedCompRef);
|
|
200
|
+
}
|
|
201
|
+
return compRef;
|
|
483
202
|
}
|
|
484
|
-
}
|
|
485
|
-
|
|
203
|
+
}
|
|
204
|
+
const widgetShape = new PlatformSDKShape("widget", WidgetSDKShape);
|
|
205
|
+
var index$2 = widgetShape.build();
|
|
486
206
|
|
|
487
207
|
const UNDERLINE_DEFINITION = "underline";
|
|
488
208
|
function extractFontVar(fontString) {
|
|
@@ -587,145 +307,125 @@
|
|
|
587
307
|
}
|
|
588
308
|
}
|
|
589
309
|
};
|
|
590
|
-
|
|
591
|
-
selectColor(
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
310
|
+
class InputsSDKShape extends BaseSDKShape {
|
|
311
|
+
async selectColor(value, options) {
|
|
312
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
313
|
+
let colorValue = parseColorString(value);
|
|
314
|
+
let colorResult = colorValueToCSS(colorValue);
|
|
315
|
+
await privateAPI.inputs.openColorPicker(
|
|
316
|
+
{
|
|
317
|
+
color: colorValue?.cssVariableName || colorValue?.theme || colorValue?.color
|
|
318
|
+
},
|
|
319
|
+
({
|
|
320
|
+
color,
|
|
321
|
+
theme,
|
|
322
|
+
cssVariableTheme
|
|
323
|
+
}) => {
|
|
324
|
+
colorValue = {
|
|
601
325
|
color,
|
|
602
326
|
theme,
|
|
603
|
-
cssVariableTheme
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const fontValue = parseFontString(value);
|
|
621
|
-
let _value = value;
|
|
622
|
-
await privateAPI.inputs.openFontPickerV2(
|
|
623
|
-
{
|
|
624
|
-
...options,
|
|
625
|
-
panelSectionsDefinition: {
|
|
626
|
-
htmlTag: "hidden"
|
|
627
|
-
},
|
|
628
|
-
componentStyle: fonts.transformFontInternalValue(fontValue)
|
|
327
|
+
cssVariableName: cssVariableTheme
|
|
328
|
+
};
|
|
329
|
+
colorResult = colorValueToCSS(colorValue);
|
|
330
|
+
options?.onChange?.(colorResult);
|
|
331
|
+
}
|
|
332
|
+
);
|
|
333
|
+
return colorResult;
|
|
334
|
+
}
|
|
335
|
+
async selectFont(value, options) {
|
|
336
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
337
|
+
const fontValue = parseFontString(value);
|
|
338
|
+
let _value = value;
|
|
339
|
+
await privateAPI.inputs.openFontPickerV2(
|
|
340
|
+
{
|
|
341
|
+
...options,
|
|
342
|
+
panelSectionsDefinition: {
|
|
343
|
+
htmlTag: "hidden"
|
|
629
344
|
},
|
|
630
|
-
(
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
345
|
+
componentStyle: fonts.transformFontInternalValue(fontValue)
|
|
346
|
+
},
|
|
347
|
+
(font, accessibility) => {
|
|
348
|
+
_value = {
|
|
349
|
+
font: fontValueToCSS(font),
|
|
350
|
+
textDecoration: font.underline ? UNDERLINE_DEFINITION : void 0
|
|
351
|
+
};
|
|
352
|
+
options?.onChange?.(_value);
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
return _value;
|
|
640
356
|
}
|
|
641
|
-
}
|
|
642
|
-
var index =
|
|
357
|
+
}
|
|
358
|
+
var index$1 = new PlatformSDKShape("inputs", InputsSDKShape).build();
|
|
643
359
|
|
|
644
|
-
|
|
645
|
-
getData(
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
},
|
|
675
|
-
selectMedia({ applicationContext }) {
|
|
360
|
+
class ExternalPanelsSDKShape extends BaseSDKShape {
|
|
361
|
+
async getData() {
|
|
362
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
363
|
+
return privateAPI.externalPanels.getData();
|
|
364
|
+
}
|
|
365
|
+
async setData(newData) {
|
|
366
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
367
|
+
return privateAPI.externalPanels.setData(newData);
|
|
368
|
+
}
|
|
369
|
+
async getStyle() {
|
|
370
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
371
|
+
return privateAPI.externalPanels.getStyle();
|
|
372
|
+
}
|
|
373
|
+
async setStyle(newStyle) {
|
|
374
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
375
|
+
return privateAPI.externalPanels.setStyle(newStyle);
|
|
376
|
+
}
|
|
377
|
+
async getTheme() {
|
|
378
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
379
|
+
return privateAPI.externalPanels.getTheme();
|
|
380
|
+
}
|
|
381
|
+
async selectMedia() {
|
|
382
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
383
|
+
return privateAPI.externalPanels.selectMedia();
|
|
384
|
+
}
|
|
385
|
+
async selectLink(...options) {
|
|
386
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
387
|
+
return privateAPI.externalPanels.selectLink(...options);
|
|
388
|
+
}
|
|
389
|
+
async selectColor(...options) {
|
|
676
390
|
return async () => {
|
|
677
|
-
const privateAPI =
|
|
678
|
-
return privateAPI.externalPanels.selectMedia();
|
|
679
|
-
};
|
|
680
|
-
},
|
|
681
|
-
selectLink({ applicationContext }) {
|
|
682
|
-
return async (...options) => {
|
|
683
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
684
|
-
return privateAPI.externalPanels.selectLink(...options);
|
|
685
|
-
};
|
|
686
|
-
},
|
|
687
|
-
selectColor({ applicationContext }) {
|
|
688
|
-
return async (...options) => {
|
|
689
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
391
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
690
392
|
return privateAPI.externalPanels.selectColor(...options);
|
|
691
393
|
};
|
|
692
|
-
},
|
|
693
|
-
translate({ applicationContext }) {
|
|
694
|
-
return async (key, values) => {
|
|
695
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
696
|
-
return privateAPI.externalPanels.translate(key, values);
|
|
697
|
-
};
|
|
698
394
|
}
|
|
699
|
-
|
|
700
|
-
|
|
395
|
+
async translate(key, values) {
|
|
396
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
397
|
+
return privateAPI.externalPanels.translate(key, values);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
var index = new PlatformSDKShape(
|
|
401
|
+
"externalPanels",
|
|
402
|
+
ExternalPanelsSDKShape
|
|
403
|
+
).build();
|
|
701
404
|
|
|
702
|
-
const
|
|
405
|
+
const frame = () => {
|
|
703
406
|
const queryParams = new URLSearchParams(window.location.search);
|
|
704
407
|
return {
|
|
705
408
|
environment: {},
|
|
409
|
+
applicationContext: editorPlatformContexts.ApplicationContext.getInstance(),
|
|
706
410
|
channel: {
|
|
707
411
|
observeState: async () => {
|
|
708
412
|
return { disconnect() {
|
|
709
413
|
} };
|
|
710
414
|
}
|
|
711
415
|
},
|
|
712
|
-
environmentContext: EnvironmentContext.getInstance(),
|
|
713
|
-
applicationContext: ApplicationContext.getInstance(),
|
|
714
416
|
essentials: queryParams.has("essentials") ? JSON.parse(queryParams.get("essentials")) : {}
|
|
715
417
|
};
|
|
716
418
|
};
|
|
717
|
-
|
|
718
|
-
const editorPlatformWorkerHost = () => {
|
|
419
|
+
const worker = () => {
|
|
719
420
|
return {
|
|
720
421
|
environment: {},
|
|
422
|
+
applicationContext: editorPlatformContexts.ApplicationContext.getInstance(),
|
|
721
423
|
channel: {
|
|
722
424
|
observeState: async () => {
|
|
723
425
|
return { disconnect() {
|
|
724
426
|
} };
|
|
725
427
|
}
|
|
726
|
-
}
|
|
727
|
-
environmentContext: EnvironmentContext.getInstance(),
|
|
728
|
-
applicationContext: ApplicationContext.getInstance()
|
|
428
|
+
}
|
|
729
429
|
};
|
|
730
430
|
};
|
|
731
431
|
|
|
@@ -733,21 +433,21 @@
|
|
|
733
433
|
host: () => {
|
|
734
434
|
const isWorker = typeof importScripts === "function";
|
|
735
435
|
if (isWorker) {
|
|
736
|
-
return
|
|
436
|
+
return worker();
|
|
737
437
|
}
|
|
738
|
-
return
|
|
438
|
+
return frame();
|
|
739
439
|
},
|
|
740
440
|
auth
|
|
741
441
|
};
|
|
742
442
|
|
|
743
|
-
exports.application = index$
|
|
443
|
+
exports.application = index$5;
|
|
744
444
|
exports.components = components;
|
|
745
445
|
exports.editor = editor;
|
|
746
|
-
exports.events = index$
|
|
747
|
-
exports.externalPanels =
|
|
748
|
-
exports.info = index$
|
|
749
|
-
exports.inputs = index;
|
|
750
|
-
exports.widget = index$
|
|
446
|
+
exports.events = index$4;
|
|
447
|
+
exports.externalPanels = index;
|
|
448
|
+
exports.info = index$3;
|
|
449
|
+
exports.inputs = index$1;
|
|
450
|
+
exports.widget = index$2;
|
|
751
451
|
|
|
752
452
|
}));
|
|
753
453
|
//# sourceMappingURL=index.js.map
|