@wix/editor 1.334.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 -516
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +183 -510
- package/dist/esm/index.js.map +1 -1
- package/dist/statics/index.js +191 -516
- package/dist/statics/index.js.map +1 -1
- package/dist/types/index.d.ts +51 -186
- package/package.json +6 -7
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 { WorkerConsumerChannel, IFrameConsumerChannel } 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,120 +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
|
-
const channel = new WorkerConsumerChannel();
|
|
343
|
-
channel.expose(new PlatformWorkerAPI());
|
|
344
|
-
} else {
|
|
345
|
-
const channel = new IFrameConsumerChannel();
|
|
346
|
-
channel.expose(new PlatformFrameAPI());
|
|
347
|
-
}
|
|
348
|
-
globalThis[INIT_KEY] = true;
|
|
349
|
-
}
|
|
65
|
+
new EditorPlatformContextEnvironment().expose();
|
|
350
66
|
|
|
351
67
|
class PlatformSDKShape {
|
|
352
|
-
constructor(namespace,
|
|
68
|
+
constructor(namespace, shapeConstructor) {
|
|
353
69
|
this.namespace = namespace;
|
|
354
|
-
this.
|
|
70
|
+
this.shapeConstructor = shapeConstructor;
|
|
355
71
|
}
|
|
356
72
|
build() {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return async (...args) => {
|
|
364
|
-
const [environmentContext, applicationContext] = await Promise.all([
|
|
365
|
-
host.environmentContext,
|
|
366
|
-
host.applicationContext
|
|
367
|
-
]);
|
|
368
|
-
return value({
|
|
369
|
-
environmentContext,
|
|
370
|
-
applicationContext
|
|
371
|
-
})(...args);
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
return async (...args) => {
|
|
375
|
-
const [environmentContext, applicationContext] = await Promise.all([
|
|
376
|
-
EnvironmentContext.getInstance(),
|
|
377
|
-
ApplicationContext.getInstance()
|
|
378
|
-
]);
|
|
379
|
-
return value({
|
|
380
|
-
environmentContext,
|
|
381
|
-
applicationContext
|
|
382
|
-
})(...args);
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
])
|
|
386
|
-
)
|
|
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"
|
|
387
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);
|
|
388
88
|
}
|
|
389
89
|
}
|
|
390
90
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
getPublicAPI({ applicationContext }) {
|
|
398
|
-
return async (appDefinitionId) => {
|
|
399
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
400
|
-
return privateAPI.applicationManager.getPublicApplicationAPI(
|
|
401
|
-
appDefinitionId
|
|
402
|
-
);
|
|
403
|
-
};
|
|
404
|
-
},
|
|
405
|
-
getAppInstance({ applicationContext }) {
|
|
406
|
-
return async () => {
|
|
407
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
408
|
-
const bindings = applicationContext.getBindings();
|
|
409
|
-
return privateAPI.info.getAppInstance(bindings.appDefinitionId);
|
|
410
|
-
};
|
|
91
|
+
class BaseSDKShape {
|
|
92
|
+
getApplicationContext() {
|
|
93
|
+
return ApplicationContext.getInstance();
|
|
94
|
+
}
|
|
95
|
+
async getPlatformPrivateAPI() {
|
|
96
|
+
return (await this.getApplicationContext()).getPrivateAPI();
|
|
411
97
|
}
|
|
412
|
-
|
|
413
|
-
|
|
98
|
+
async getContextBindings() {
|
|
99
|
+
return (await this.getApplicationContext()).getBindings();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
414
102
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
return
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
+
);
|
|
424
112
|
}
|
|
425
|
-
|
|
426
|
-
|
|
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();
|
|
427
120
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
+
);
|
|
433
128
|
}
|
|
434
|
-
}
|
|
435
|
-
var
|
|
129
|
+
}
|
|
130
|
+
var components = new PlatformSDKShape("components", ComponentsSDKShape).build();
|
|
436
131
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
};
|
|
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();
|
|
449
143
|
}
|
|
450
|
-
|
|
451
|
-
|
|
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();
|
|
452
150
|
|
|
453
151
|
var WidgetShapeErrorCode = /* @__PURE__ */ ((WidgetShapeErrorCode2) => {
|
|
454
152
|
WidgetShapeErrorCode2["UndefinedCompRef"] = "UndefinedCompRef";
|
|
@@ -461,31 +159,28 @@ class WidgetShapeError extends BaseError {
|
|
|
461
159
|
}
|
|
462
160
|
const createWidgetShapeError = createErrorBuilder(WidgetShapeError);
|
|
463
161
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
return
|
|
482
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
483
|
-
const compRef = await getSelectedComponentRef();
|
|
484
|
-
await privateAPI.customElement.setAttribute(compRef, propName, value);
|
|
485
|
-
};
|
|
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;
|
|
486
180
|
}
|
|
487
|
-
}
|
|
488
|
-
|
|
181
|
+
}
|
|
182
|
+
const widgetShape = new PlatformSDKShape("widget", WidgetSDKShape);
|
|
183
|
+
var index$2 = widgetShape.build();
|
|
489
184
|
|
|
490
185
|
const UNDERLINE_DEFINITION = "underline";
|
|
491
186
|
function extractFontVar(fontString) {
|
|
@@ -590,119 +285,102 @@ const fonts = {
|
|
|
590
285
|
}
|
|
591
286
|
}
|
|
592
287
|
};
|
|
593
|
-
|
|
594
|
-
selectColor(
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
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 = {
|
|
604
303
|
color,
|
|
605
304
|
theme,
|
|
606
|
-
cssVariableTheme
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
const fontValue = parseFontString(value);
|
|
624
|
-
let _value = value;
|
|
625
|
-
await privateAPI.inputs.openFontPickerV2(
|
|
626
|
-
{
|
|
627
|
-
...options,
|
|
628
|
-
panelSectionsDefinition: {
|
|
629
|
-
htmlTag: "hidden"
|
|
630
|
-
},
|
|
631
|
-
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"
|
|
632
322
|
},
|
|
633
|
-
(
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
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;
|
|
643
334
|
}
|
|
644
|
-
}
|
|
645
|
-
var index =
|
|
335
|
+
}
|
|
336
|
+
var index$1 = new PlatformSDKShape("inputs", InputsSDKShape).build();
|
|
646
337
|
|
|
647
|
-
|
|
648
|
-
getData(
|
|
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
|
-
|
|
677
|
-
},
|
|
678
|
-
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) {
|
|
679
368
|
return async () => {
|
|
680
|
-
const privateAPI =
|
|
681
|
-
return privateAPI.externalPanels.selectMedia();
|
|
682
|
-
};
|
|
683
|
-
},
|
|
684
|
-
selectLink({ applicationContext }) {
|
|
685
|
-
return async (...options) => {
|
|
686
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
687
|
-
return privateAPI.externalPanels.selectLink(...options);
|
|
688
|
-
};
|
|
689
|
-
},
|
|
690
|
-
selectColor({ applicationContext }) {
|
|
691
|
-
return async (...options) => {
|
|
692
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
369
|
+
const privateAPI = await this.getPlatformPrivateAPI();
|
|
693
370
|
return privateAPI.externalPanels.selectColor(...options);
|
|
694
371
|
};
|
|
695
|
-
},
|
|
696
|
-
translate({ applicationContext }) {
|
|
697
|
-
return async (key, values) => {
|
|
698
|
-
const privateAPI = applicationContext.getPrivateAPI();
|
|
699
|
-
return privateAPI.externalPanels.translate(key, values);
|
|
700
|
-
};
|
|
701
372
|
}
|
|
702
|
-
|
|
703
|
-
|
|
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();
|
|
704
382
|
|
|
705
|
-
const
|
|
383
|
+
const frame = () => {
|
|
706
384
|
const queryParams = new URLSearchParams(window.location.search);
|
|
707
385
|
return {
|
|
708
386
|
environment: {},
|
|
@@ -712,13 +390,10 @@ const editorPlatformFrameHost = () => {
|
|
|
712
390
|
} };
|
|
713
391
|
}
|
|
714
392
|
},
|
|
715
|
-
environmentContext: EnvironmentContext.getInstance(),
|
|
716
|
-
applicationContext: ApplicationContext.getInstance(),
|
|
717
393
|
essentials: queryParams.has("essentials") ? JSON.parse(queryParams.get("essentials")) : {}
|
|
718
394
|
};
|
|
719
395
|
};
|
|
720
|
-
|
|
721
|
-
const editorPlatformWorkerHost = () => {
|
|
396
|
+
const worker = () => {
|
|
722
397
|
return {
|
|
723
398
|
environment: {},
|
|
724
399
|
channel: {
|
|
@@ -726,9 +401,7 @@ const editorPlatformWorkerHost = () => {
|
|
|
726
401
|
return { disconnect() {
|
|
727
402
|
} };
|
|
728
403
|
}
|
|
729
|
-
}
|
|
730
|
-
environmentContext: EnvironmentContext.getInstance(),
|
|
731
|
-
applicationContext: ApplicationContext.getInstance()
|
|
404
|
+
}
|
|
732
405
|
};
|
|
733
406
|
};
|
|
734
407
|
|
|
@@ -736,12 +409,12 @@ const editor = {
|
|
|
736
409
|
host: () => {
|
|
737
410
|
const isWorker = typeof importScripts === "function";
|
|
738
411
|
if (isWorker) {
|
|
739
|
-
return
|
|
412
|
+
return worker();
|
|
740
413
|
}
|
|
741
|
-
return
|
|
414
|
+
return frame();
|
|
742
415
|
},
|
|
743
416
|
auth
|
|
744
417
|
};
|
|
745
418
|
|
|
746
|
-
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 };
|
|
747
420
|
//# sourceMappingURL=index.js.map
|