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