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