@kittl/sdk 0.0.9 → 1.0.0-alpha.1
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/dashboardStandalonePage/sdk.d.ts +8261 -0
- package/dist/{kittl-sdk.esm.js → dashboardStandalonePage/sdk.esm.js} +191 -301
- package/dist/{kittl-sdk.js → dashboardStandalonePage/sdk.js} +191 -301
- package/dist/editorContentPanel/sdk.d.ts +5951 -90
- package/dist/editorContentPanel/sdk.esm.js +206 -30
- package/dist/editorContentPanel/sdk.js +206 -30
- package/dist/editorScriptRunner/sdk.d.ts +5425 -133
- package/dist/editorScriptRunner/sdk.esm.js +204 -30
- package/dist/editorScriptRunner/sdk.js +204 -30
- package/dist/sharedFileBrowser/sdk.d.ts +185 -2609
- package/dist/sharedFileBrowser/sdk.esm.js +192 -16
- package/dist/sharedFileBrowser/sdk.js +192 -16
- package/package.json +8 -7
- package/dist/sdk.d.ts +0 -2756
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
var FROM_EXTENSION_COMMANDS = {
|
|
15
|
+
/** Capability-owned AI callback registration. */
|
|
16
|
+
AI_GENERATOR_SUBSCRIBE: "ai-generator-subscribe",
|
|
17
|
+
/** Capability-owned AI callback teardown. */
|
|
18
|
+
AI_GENERATOR_UNSUBSCRIBE: "ai-generator-unsubscribe",
|
|
15
19
|
/** SDK API call */
|
|
16
20
|
SDK_CALL: "sdk-call",
|
|
17
21
|
/** AI handler registration */
|
|
@@ -60,6 +64,8 @@
|
|
|
60
64
|
LOADED: "loaded"
|
|
61
65
|
};
|
|
62
66
|
var TO_EXTENSION_COMMANDS = {
|
|
67
|
+
/** Callback payload for generator or pending-set subscriptions. */
|
|
68
|
+
AI_GENERATOR_UPDATE: "ai-generator-update",
|
|
63
69
|
/** SDK API response */
|
|
64
70
|
SDK_RESPONSE: "sdk-response",
|
|
65
71
|
/** File browser fetch content request */
|
|
@@ -76,6 +82,10 @@
|
|
|
76
82
|
APP_STATE_UPDATE: "app-state-update"
|
|
77
83
|
};
|
|
78
84
|
|
|
85
|
+
function isAIGeneratorUpdateMessage(data) {
|
|
86
|
+
return !!data && typeof data === "object" && "command" in data && data.command === "ai-generator-update" && "subscriptionId" in data && typeof data.subscriptionId === "string";
|
|
87
|
+
}
|
|
88
|
+
|
|
79
89
|
var isSDKResponseMessage = (data) => {
|
|
80
90
|
return typeof data === "object" && data !== null && "command" in data && data.command === TO_EXTENSION_COMMANDS.SDK_RESPONSE && "messageId" in data && typeof data.messageId === "string";
|
|
81
91
|
};
|
|
@@ -145,7 +155,10 @@
|
|
|
145
155
|
"https://app.stagingdesigner.com",
|
|
146
156
|
"https://*.stagingdesigner.com",
|
|
147
157
|
"http://localhost:3000",
|
|
148
|
-
"https://app.kittl.com"
|
|
158
|
+
"https://app.kittl.com",
|
|
159
|
+
// website, for sandboxed standalone dashboard pages
|
|
160
|
+
"http://localhost:3003",
|
|
161
|
+
"https://www.kittl.com"
|
|
149
162
|
];
|
|
150
163
|
var toOrigin = (value) => {
|
|
151
164
|
if (!value) {
|
|
@@ -200,8 +213,15 @@
|
|
|
200
213
|
};
|
|
201
214
|
|
|
202
215
|
var pendingRequests = /* @__PURE__ */ new Map();
|
|
216
|
+
var sdkVersion;
|
|
217
|
+
function setSDKVersion(version2) {
|
|
218
|
+
sdkVersion = version2;
|
|
219
|
+
}
|
|
203
220
|
var postMessageToParent = (message) => {
|
|
204
|
-
window.parent.postMessage(
|
|
221
|
+
window.parent.postMessage(
|
|
222
|
+
sdkVersion === void 0 ? message : { ...message, sdkVersion },
|
|
223
|
+
getParentDomain()
|
|
224
|
+
);
|
|
205
225
|
};
|
|
206
226
|
var sendMessage = (message) => {
|
|
207
227
|
postMessageToParent(message);
|
|
@@ -224,6 +244,27 @@
|
|
|
224
244
|
};
|
|
225
245
|
|
|
226
246
|
var createSDKCallMessage = {
|
|
247
|
+
aiGenerator: (dots, args, messageId) => ({
|
|
248
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
249
|
+
dots,
|
|
250
|
+
args,
|
|
251
|
+
messageId,
|
|
252
|
+
apiType: "aiGenerator"
|
|
253
|
+
}),
|
|
254
|
+
mockup: (dots, args, messageId) => ({
|
|
255
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
256
|
+
dots,
|
|
257
|
+
args,
|
|
258
|
+
messageId,
|
|
259
|
+
apiType: "mockup"
|
|
260
|
+
}),
|
|
261
|
+
fileBrowser: (dots, args, messageId) => ({
|
|
262
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
263
|
+
dots,
|
|
264
|
+
args,
|
|
265
|
+
messageId,
|
|
266
|
+
apiType: "fileBrowser"
|
|
267
|
+
}),
|
|
227
268
|
ai: (dots, args, messageId) => ({
|
|
228
269
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
229
270
|
dots,
|
|
@@ -259,6 +300,13 @@
|
|
|
259
300
|
messageId,
|
|
260
301
|
apiType: "font"
|
|
261
302
|
}),
|
|
303
|
+
project: (dots, args, messageId) => ({
|
|
304
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
305
|
+
dots,
|
|
306
|
+
args,
|
|
307
|
+
messageId,
|
|
308
|
+
apiType: "project"
|
|
309
|
+
}),
|
|
262
310
|
state: (dots, args, messageId) => ({
|
|
263
311
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
264
312
|
dots,
|
|
@@ -279,6 +327,27 @@
|
|
|
279
327
|
args,
|
|
280
328
|
messageId,
|
|
281
329
|
apiType: "data"
|
|
330
|
+
}),
|
|
331
|
+
brandKit: (dots, args, messageId) => ({
|
|
332
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
333
|
+
dots,
|
|
334
|
+
args,
|
|
335
|
+
messageId,
|
|
336
|
+
apiType: "brandKit"
|
|
337
|
+
}),
|
|
338
|
+
openMicroEditor: (dots, args, messageId) => ({
|
|
339
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
340
|
+
dots,
|
|
341
|
+
args,
|
|
342
|
+
messageId,
|
|
343
|
+
apiType: "openMicroEditor"
|
|
344
|
+
}),
|
|
345
|
+
openMainEditor: (dots, args, messageId) => ({
|
|
346
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
347
|
+
dots,
|
|
348
|
+
args,
|
|
349
|
+
messageId,
|
|
350
|
+
apiType: "openMainEditor"
|
|
282
351
|
})
|
|
283
352
|
};
|
|
284
353
|
function createApiProxy(apiType) {
|
|
@@ -295,6 +364,64 @@
|
|
|
295
364
|
});
|
|
296
365
|
}
|
|
297
366
|
|
|
367
|
+
function createAIGeneratorBridgeApi() {
|
|
368
|
+
const callbacks = /* @__PURE__ */ new Map();
|
|
369
|
+
const proxy = createApiProxy("aiGenerator");
|
|
370
|
+
async function subscribe(request, callback) {
|
|
371
|
+
const subscriptionId = generateMessageId();
|
|
372
|
+
callbacks.set(subscriptionId, callback);
|
|
373
|
+
let response;
|
|
374
|
+
try {
|
|
375
|
+
response = await sendMessage({
|
|
376
|
+
command: "ai-generator-subscribe",
|
|
377
|
+
...request,
|
|
378
|
+
subscriptionId,
|
|
379
|
+
messageId: generateMessageId()
|
|
380
|
+
});
|
|
381
|
+
} catch (error) {
|
|
382
|
+
callbacks.delete(subscriptionId);
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
if (!response.isOk) {
|
|
386
|
+
callbacks.delete(subscriptionId);
|
|
387
|
+
throw new Error(response.error.message);
|
|
388
|
+
}
|
|
389
|
+
return () => {
|
|
390
|
+
callbacks.delete(subscriptionId);
|
|
391
|
+
postMessageToParent({
|
|
392
|
+
command: "ai-generator-unsubscribe",
|
|
393
|
+
subscriptionId
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
const methods = {
|
|
398
|
+
registerGenerator: (id, callback) => subscribe({ method: "registerGenerator", args: [id] }, (update) => {
|
|
399
|
+
if (update) callback(update);
|
|
400
|
+
}),
|
|
401
|
+
subscribeToGenerationUpdates: (ids, callback) => subscribe(
|
|
402
|
+
{ method: "subscribeToGenerationUpdates", args: [ids] },
|
|
403
|
+
(update) => {
|
|
404
|
+
if (update) callback(update);
|
|
405
|
+
}
|
|
406
|
+
),
|
|
407
|
+
subscribeToPendingGenerations: (callback) => subscribe(
|
|
408
|
+
{ method: "subscribeToPendingGenerations", args: [] },
|
|
409
|
+
() => callback()
|
|
410
|
+
),
|
|
411
|
+
/** Callers may reuse richer internal submission objects; never send their local abort callbacks. */
|
|
412
|
+
cancelGenerations: (submission) => proxy.cancelGenerations({
|
|
413
|
+
generationIds: submission.generationIds,
|
|
414
|
+
until: submission.until
|
|
415
|
+
})
|
|
416
|
+
};
|
|
417
|
+
return {
|
|
418
|
+
api: new Proxy(proxy, {
|
|
419
|
+
get: (target, property, receiver) => property in methods ? methods[property] : Reflect.get(target, property, receiver)
|
|
420
|
+
}),
|
|
421
|
+
dispatch: (message) => callbacks.get(message.subscriptionId)?.(message.update)
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
298
425
|
var generationHandlers = /* @__PURE__ */ new Map();
|
|
299
426
|
var generationSubscriptions = /* @__PURE__ */ new Map();
|
|
300
427
|
var dispatchAIGenerationUpdate = (subscriptionId, update) => {
|
|
@@ -662,7 +789,7 @@
|
|
|
662
789
|
}
|
|
663
790
|
};
|
|
664
791
|
|
|
665
|
-
var
|
|
792
|
+
var createBatchFor = async (apiType) => {
|
|
666
793
|
const response = await sendMessage({
|
|
667
794
|
command: FROM_EXTENSION_COMMANDS.BATCH_CREATE,
|
|
668
795
|
messageId: generateMessageId()
|
|
@@ -671,14 +798,17 @@
|
|
|
671
798
|
throw response.error;
|
|
672
799
|
}
|
|
673
800
|
const { batchKey } = response.result;
|
|
674
|
-
const sendDesignCall = (dots, args) =>
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
801
|
+
const sendDesignCall = (dots, args) => {
|
|
802
|
+
const message = {
|
|
803
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
804
|
+
dots: apiType === "project" ? ["design", "api", ...dots] : dots,
|
|
805
|
+
args,
|
|
806
|
+
messageId: generateMessageId(),
|
|
807
|
+
apiType,
|
|
808
|
+
batchKey
|
|
809
|
+
};
|
|
810
|
+
return sendMessage(message);
|
|
811
|
+
};
|
|
682
812
|
const commit = async () => {
|
|
683
813
|
const res = await sendMessage({
|
|
684
814
|
command: FROM_EXTENSION_COMMANDS.BATCH_COMMIT,
|
|
@@ -705,6 +835,8 @@
|
|
|
705
835
|
};
|
|
706
836
|
return buildNode([]);
|
|
707
837
|
};
|
|
838
|
+
var createBatch = () => createBatchFor("design");
|
|
839
|
+
var createProjectBatch = () => createBatchFor("project");
|
|
708
840
|
|
|
709
841
|
var createContextBridgeApi = () => {
|
|
710
842
|
const contextProxy = createApiProxy("context");
|
|
@@ -872,6 +1004,7 @@
|
|
|
872
1004
|
var appStateApi = createAppStateBridgeApi();
|
|
873
1005
|
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
874
1006
|
var authClient = new SandboxedAuthClient();
|
|
1007
|
+
var aiGeneratorBridge = createAIGeneratorBridgeApi();
|
|
875
1008
|
var handleIncomingMessage = (event) => {
|
|
876
1009
|
const parent = window.parent;
|
|
877
1010
|
if (!parent || parent === window) {
|
|
@@ -894,6 +1027,10 @@
|
|
|
894
1027
|
statelessApi.dispatch(data.type, data.payload);
|
|
895
1028
|
return;
|
|
896
1029
|
}
|
|
1030
|
+
if (isAIGeneratorUpdateMessage(data)) {
|
|
1031
|
+
aiGeneratorBridge.dispatch(data);
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
897
1034
|
if (isAIGenerationUpdatePushMessage(data)) {
|
|
898
1035
|
dispatchAIGenerationUpdate(data.subscriptionId, data.update);
|
|
899
1036
|
return;
|
|
@@ -918,7 +1055,28 @@
|
|
|
918
1055
|
);
|
|
919
1056
|
}
|
|
920
1057
|
};
|
|
1058
|
+
var projectProxy = createApiProxy("project");
|
|
1059
|
+
var projectApi = {
|
|
1060
|
+
design: {
|
|
1061
|
+
state: {
|
|
1062
|
+
getState: projectProxy.design.state.getState,
|
|
1063
|
+
subscribe: designStateApi.subscribe
|
|
1064
|
+
},
|
|
1065
|
+
api: projectProxy.design.api,
|
|
1066
|
+
createBatch: createProjectBatch
|
|
1067
|
+
},
|
|
1068
|
+
app: {
|
|
1069
|
+
state: {
|
|
1070
|
+
getState: projectProxy.app.state.getState,
|
|
1071
|
+
subscribe: appStateApi.subscribe
|
|
1072
|
+
},
|
|
1073
|
+
api: projectProxy.app.api
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
921
1076
|
var bridgeHandlers = {
|
|
1077
|
+
aiGenerator: aiGeneratorBridge.api,
|
|
1078
|
+
brandKit: createApiProxy("brandKit"),
|
|
1079
|
+
mockup: createApiProxy("mockup"),
|
|
922
1080
|
ai: createAIApiProxy(),
|
|
923
1081
|
context: contextApi,
|
|
924
1082
|
data: createApiProxy("data"),
|
|
@@ -927,12 +1085,17 @@
|
|
|
927
1085
|
appStore: appStateApi,
|
|
928
1086
|
export: createApiProxy("export"),
|
|
929
1087
|
font: createApiProxy("font"),
|
|
1088
|
+
project: projectApi,
|
|
930
1089
|
state: createApiProxy("state"),
|
|
931
1090
|
upload: createApiProxy("upload"),
|
|
932
|
-
fileBrowser:
|
|
1091
|
+
fileBrowser: { getFiles: createApiProxy("fileBrowser").getFiles },
|
|
1092
|
+
fileBrowserRegistration: createFileBrowserApiProxy(),
|
|
1093
|
+
openMicroEditor: createApiProxy("openMicroEditor"),
|
|
1094
|
+
openMainEditor: createApiProxy("openMainEditor"),
|
|
933
1095
|
auth: authClient,
|
|
934
1096
|
stateless: statelessApi,
|
|
935
|
-
createBatch
|
|
1097
|
+
createBatch,
|
|
1098
|
+
createProjectBatch
|
|
936
1099
|
};
|
|
937
1100
|
|
|
938
1101
|
// src/api/dragAndDrop/DragAndDropApi.ts
|
|
@@ -967,7 +1130,7 @@
|
|
|
967
1130
|
async dropImage(input) {
|
|
968
1131
|
let objectId = null;
|
|
969
1132
|
try {
|
|
970
|
-
const offset = unwrapResult(await this.context.get()).
|
|
1133
|
+
const offset = unwrapResult(await this.context.get()).iframeOffset;
|
|
971
1134
|
const params = this.buildDropImageParams(input, offset);
|
|
972
1135
|
objectId = await this.addDroppedImage(params);
|
|
973
1136
|
if (input.persistImage) {
|
|
@@ -1198,29 +1361,31 @@
|
|
|
1198
1361
|
|
|
1199
1362
|
// src/createEditorSDKAPIs.ts
|
|
1200
1363
|
function createEditorSDKAPIs() {
|
|
1364
|
+
const { project } = bridgeHandlers;
|
|
1365
|
+
const dragAndDrop = new DragAndDropApi({
|
|
1366
|
+
state: project.app.api,
|
|
1367
|
+
context: bridgeHandlers.context,
|
|
1368
|
+
design: project.design.api,
|
|
1369
|
+
upload: bridgeHandlers.upload
|
|
1370
|
+
});
|
|
1201
1371
|
return {
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1372
|
+
aiGenerator: bridgeHandlers.aiGenerator,
|
|
1373
|
+
mockup: bridgeHandlers.mockup,
|
|
1374
|
+
project,
|
|
1205
1375
|
export: bridgeHandlers.export,
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
context: bridgeHandlers.context,
|
|
1209
|
-
dragAndDrop: new DragAndDropApi({
|
|
1210
|
-
state: bridgeHandlers.state,
|
|
1211
|
-
context: bridgeHandlers.context,
|
|
1212
|
-
design: bridgeHandlers.design,
|
|
1213
|
-
upload: bridgeHandlers.upload
|
|
1214
|
-
}),
|
|
1215
|
-
state: bridgeHandlers.state,
|
|
1376
|
+
helpers: { dragAndDrop },
|
|
1377
|
+
dragAndDrop,
|
|
1216
1378
|
auth: bridgeHandlers.auth,
|
|
1217
1379
|
upload: bridgeHandlers.upload,
|
|
1218
1380
|
stateless: bridgeHandlers.stateless,
|
|
1219
1381
|
font: bridgeHandlers.font,
|
|
1220
|
-
|
|
1382
|
+
fileBrowser: bridgeHandlers.fileBrowser
|
|
1221
1383
|
};
|
|
1222
1384
|
}
|
|
1223
1385
|
|
|
1386
|
+
// package.json
|
|
1387
|
+
var version = "1.0.0";
|
|
1388
|
+
|
|
1224
1389
|
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
1225
1390
|
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
1226
1391
|
if (typeof document === "undefined") {
|
|
@@ -1261,12 +1426,17 @@
|
|
|
1261
1426
|
handleIncomingMessage(event);
|
|
1262
1427
|
}
|
|
1263
1428
|
);
|
|
1264
|
-
|
|
1429
|
+
const { context } = apis;
|
|
1430
|
+
const themeSynced = context?.get && context.subscribe ? syncHtmlDataThemeFromHostContext({
|
|
1431
|
+
context
|
|
1432
|
+
}) : Promise.resolve();
|
|
1433
|
+
void themeSynced.catch(() => void 0).then(() => {
|
|
1265
1434
|
kittl2.onLoadedCallback?.();
|
|
1266
1435
|
sendLoaded();
|
|
1267
1436
|
});
|
|
1268
1437
|
};
|
|
1269
1438
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
1439
|
+
setSDKVersion(version);
|
|
1270
1440
|
window.kittl = kittl2;
|
|
1271
1441
|
if (document.readyState === "loading") {
|
|
1272
1442
|
document.addEventListener("DOMContentLoaded", initSdk);
|
|
@@ -1278,5 +1448,9 @@
|
|
|
1278
1448
|
}
|
|
1279
1449
|
|
|
1280
1450
|
// src/editorScriptRunner.ts
|
|
1281
|
-
var kittl = createKittlSDK(
|
|
1451
|
+
var kittl = createKittlSDK({
|
|
1452
|
+
...createEditorSDKAPIs(),
|
|
1453
|
+
// nothing is contextually relevant to a hidden script runner yet
|
|
1454
|
+
context: {}
|
|
1455
|
+
});
|
|
1282
1456
|
})();
|