@kittl/sdk 0.0.9 → 1.0.0-alpha.2
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/creativeAgentPanel/sdk.d.ts +8667 -0
- package/dist/{kittl-sdk.esm.js → creativeAgentPanel/sdk.esm.js} +199 -301
- package/dist/{kittl-sdk.js → creativeAgentPanel/sdk.js} +199 -301
- package/dist/dashboardStandalonePage/sdk.d.ts +8656 -0
- package/dist/dashboardStandalonePage/sdk.esm.js +1184 -0
- package/dist/dashboardStandalonePage/sdk.js +1184 -0
- package/dist/editorContentPanel/sdk.d.ts +6318 -103
- package/dist/editorContentPanel/sdk.esm.js +214 -30
- package/dist/editorContentPanel/sdk.js +214 -30
- package/dist/editorScriptRunner/sdk.d.ts +5732 -146
- package/dist/editorScriptRunner/sdk.esm.js +212 -30
- package/dist/editorScriptRunner/sdk.js +212 -30
- package/dist/sharedFileBrowser/sdk.d.ts +188 -2609
- package/dist/sharedFileBrowser/sdk.esm.js +200 -16
- package/dist/sharedFileBrowser/sdk.js +200 -16
- package/package.json +14 -7
- package/dist/sdk.d.ts +0 -2756
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
(() => {
|
|
6
6
|
|
|
7
7
|
var FROM_EXTENSION_COMMANDS = {
|
|
8
|
+
/** Capability-owned AI callback registration. */
|
|
9
|
+
AI_GENERATOR_SUBSCRIBE: "ai-generator-subscribe",
|
|
10
|
+
/** Capability-owned AI callback teardown. */
|
|
11
|
+
AI_GENERATOR_UNSUBSCRIBE: "ai-generator-unsubscribe",
|
|
8
12
|
/** SDK API call */
|
|
9
13
|
SDK_CALL: "sdk-call",
|
|
10
14
|
/** AI handler registration */
|
|
@@ -53,6 +57,8 @@
|
|
|
53
57
|
LOADED: "loaded"
|
|
54
58
|
};
|
|
55
59
|
var TO_EXTENSION_COMMANDS = {
|
|
60
|
+
/** Callback payload for generator or pending-set subscriptions. */
|
|
61
|
+
AI_GENERATOR_UPDATE: "ai-generator-update",
|
|
56
62
|
/** SDK API response */
|
|
57
63
|
SDK_RESPONSE: "sdk-response",
|
|
58
64
|
/** File browser fetch content request */
|
|
@@ -69,6 +75,10 @@
|
|
|
69
75
|
APP_STATE_UPDATE: "app-state-update"
|
|
70
76
|
};
|
|
71
77
|
|
|
78
|
+
function isAIGeneratorUpdateMessage(data) {
|
|
79
|
+
return !!data && typeof data === "object" && "command" in data && data.command === "ai-generator-update" && "subscriptionId" in data && typeof data.subscriptionId === "string";
|
|
80
|
+
}
|
|
81
|
+
|
|
72
82
|
var isSDKResponseMessage = (data) => {
|
|
73
83
|
return typeof data === "object" && data !== null && "command" in data && data.command === TO_EXTENSION_COMMANDS.SDK_RESPONSE && "messageId" in data && typeof data.messageId === "string";
|
|
74
84
|
};
|
|
@@ -138,7 +148,10 @@
|
|
|
138
148
|
"https://app.stagingdesigner.com",
|
|
139
149
|
"https://*.stagingdesigner.com",
|
|
140
150
|
"http://localhost:3000",
|
|
141
|
-
"https://app.kittl.com"
|
|
151
|
+
"https://app.kittl.com",
|
|
152
|
+
// website, for sandboxed standalone dashboard pages
|
|
153
|
+
"http://localhost:3003",
|
|
154
|
+
"https://www.kittl.com"
|
|
142
155
|
];
|
|
143
156
|
var toOrigin = (value) => {
|
|
144
157
|
if (!value) {
|
|
@@ -193,8 +206,15 @@
|
|
|
193
206
|
};
|
|
194
207
|
|
|
195
208
|
var pendingRequests = /* @__PURE__ */ new Map();
|
|
209
|
+
var sdkVersion;
|
|
210
|
+
function setSDKVersion(version2) {
|
|
211
|
+
sdkVersion = version2;
|
|
212
|
+
}
|
|
196
213
|
var postMessageToParent = (message) => {
|
|
197
|
-
window.parent.postMessage(
|
|
214
|
+
window.parent.postMessage(
|
|
215
|
+
sdkVersion === void 0 ? message : { ...message, sdkVersion },
|
|
216
|
+
getParentDomain()
|
|
217
|
+
);
|
|
198
218
|
};
|
|
199
219
|
var sendMessage = (message) => {
|
|
200
220
|
postMessageToParent(message);
|
|
@@ -217,6 +237,27 @@
|
|
|
217
237
|
};
|
|
218
238
|
|
|
219
239
|
var createSDKCallMessage = {
|
|
240
|
+
aiGenerator: (dots, args, messageId) => ({
|
|
241
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
242
|
+
dots,
|
|
243
|
+
args,
|
|
244
|
+
messageId,
|
|
245
|
+
apiType: "aiGenerator"
|
|
246
|
+
}),
|
|
247
|
+
mockup: (dots, args, messageId) => ({
|
|
248
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
249
|
+
dots,
|
|
250
|
+
args,
|
|
251
|
+
messageId,
|
|
252
|
+
apiType: "mockup"
|
|
253
|
+
}),
|
|
254
|
+
fileBrowser: (dots, args, messageId) => ({
|
|
255
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
256
|
+
dots,
|
|
257
|
+
args,
|
|
258
|
+
messageId,
|
|
259
|
+
apiType: "fileBrowser"
|
|
260
|
+
}),
|
|
220
261
|
ai: (dots, args, messageId) => ({
|
|
221
262
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
222
263
|
dots,
|
|
@@ -252,6 +293,13 @@
|
|
|
252
293
|
messageId,
|
|
253
294
|
apiType: "font"
|
|
254
295
|
}),
|
|
296
|
+
project: (dots, args, messageId) => ({
|
|
297
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
298
|
+
dots,
|
|
299
|
+
args,
|
|
300
|
+
messageId,
|
|
301
|
+
apiType: "project"
|
|
302
|
+
}),
|
|
255
303
|
state: (dots, args, messageId) => ({
|
|
256
304
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
257
305
|
dots,
|
|
@@ -272,6 +320,34 @@
|
|
|
272
320
|
args,
|
|
273
321
|
messageId,
|
|
274
322
|
apiType: "data"
|
|
323
|
+
}),
|
|
324
|
+
brandKit: (dots, args, messageId) => ({
|
|
325
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
326
|
+
dots,
|
|
327
|
+
args,
|
|
328
|
+
messageId,
|
|
329
|
+
apiType: "brandKit"
|
|
330
|
+
}),
|
|
331
|
+
openMicroEditor: (dots, args, messageId) => ({
|
|
332
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
333
|
+
dots,
|
|
334
|
+
args,
|
|
335
|
+
messageId,
|
|
336
|
+
apiType: "openMicroEditor"
|
|
337
|
+
}),
|
|
338
|
+
openMainEditor: (dots, args, messageId) => ({
|
|
339
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
340
|
+
dots,
|
|
341
|
+
args,
|
|
342
|
+
messageId,
|
|
343
|
+
apiType: "openMainEditor"
|
|
344
|
+
}),
|
|
345
|
+
agent: (dots, args, messageId) => ({
|
|
346
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
347
|
+
dots,
|
|
348
|
+
args,
|
|
349
|
+
messageId,
|
|
350
|
+
apiType: "agent"
|
|
275
351
|
})
|
|
276
352
|
};
|
|
277
353
|
function createApiProxy(apiType) {
|
|
@@ -288,6 +364,64 @@
|
|
|
288
364
|
});
|
|
289
365
|
}
|
|
290
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
|
+
|
|
291
425
|
var generationHandlers = /* @__PURE__ */ new Map();
|
|
292
426
|
var generationSubscriptions = /* @__PURE__ */ new Map();
|
|
293
427
|
var dispatchAIGenerationUpdate = (subscriptionId, update) => {
|
|
@@ -655,7 +789,7 @@
|
|
|
655
789
|
}
|
|
656
790
|
};
|
|
657
791
|
|
|
658
|
-
var
|
|
792
|
+
var createBatchFor = async (apiType) => {
|
|
659
793
|
const response = await sendMessage({
|
|
660
794
|
command: FROM_EXTENSION_COMMANDS.BATCH_CREATE,
|
|
661
795
|
messageId: generateMessageId()
|
|
@@ -664,14 +798,17 @@
|
|
|
664
798
|
throw response.error;
|
|
665
799
|
}
|
|
666
800
|
const { batchKey } = response.result;
|
|
667
|
-
const sendDesignCall = (dots, args) =>
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
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
|
+
};
|
|
675
812
|
const commit = async () => {
|
|
676
813
|
const res = await sendMessage({
|
|
677
814
|
command: FROM_EXTENSION_COMMANDS.BATCH_COMMIT,
|
|
@@ -698,6 +835,8 @@
|
|
|
698
835
|
};
|
|
699
836
|
return buildNode([]);
|
|
700
837
|
};
|
|
838
|
+
var createBatch = () => createBatchFor("design");
|
|
839
|
+
var createProjectBatch = () => createBatchFor("project");
|
|
701
840
|
|
|
702
841
|
var createContextBridgeApi = () => {
|
|
703
842
|
const contextProxy = createApiProxy("context");
|
|
@@ -865,6 +1004,7 @@
|
|
|
865
1004
|
var appStateApi = createAppStateBridgeApi();
|
|
866
1005
|
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
867
1006
|
var authClient = new SandboxedAuthClient();
|
|
1007
|
+
var aiGeneratorBridge = createAIGeneratorBridgeApi();
|
|
868
1008
|
var handleIncomingMessage = (event) => {
|
|
869
1009
|
const parent = window.parent;
|
|
870
1010
|
if (!parent || parent === window) {
|
|
@@ -887,6 +1027,10 @@
|
|
|
887
1027
|
statelessApi.dispatch(data.type, data.payload);
|
|
888
1028
|
return;
|
|
889
1029
|
}
|
|
1030
|
+
if (isAIGeneratorUpdateMessage(data)) {
|
|
1031
|
+
aiGeneratorBridge.dispatch(data);
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
890
1034
|
if (isAIGenerationUpdatePushMessage(data)) {
|
|
891
1035
|
dispatchAIGenerationUpdate(data.subscriptionId, data.update);
|
|
892
1036
|
return;
|
|
@@ -911,7 +1055,29 @@
|
|
|
911
1055
|
);
|
|
912
1056
|
}
|
|
913
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
|
+
};
|
|
914
1076
|
var bridgeHandlers = {
|
|
1077
|
+
agent: createApiProxy("agent"),
|
|
1078
|
+
aiGenerator: aiGeneratorBridge.api,
|
|
1079
|
+
brandKit: createApiProxy("brandKit"),
|
|
1080
|
+
mockup: createApiProxy("mockup"),
|
|
915
1081
|
ai: createAIApiProxy(),
|
|
916
1082
|
context: contextApi,
|
|
917
1083
|
data: createApiProxy("data"),
|
|
@@ -920,12 +1086,17 @@
|
|
|
920
1086
|
appStore: appStateApi,
|
|
921
1087
|
export: createApiProxy("export"),
|
|
922
1088
|
font: createApiProxy("font"),
|
|
1089
|
+
project: projectApi,
|
|
923
1090
|
state: createApiProxy("state"),
|
|
924
1091
|
upload: createApiProxy("upload"),
|
|
925
|
-
fileBrowser:
|
|
1092
|
+
fileBrowser: { getFiles: createApiProxy("fileBrowser").getFiles },
|
|
1093
|
+
fileBrowserRegistration: createFileBrowserApiProxy(),
|
|
1094
|
+
openMicroEditor: createApiProxy("openMicroEditor"),
|
|
1095
|
+
openMainEditor: createApiProxy("openMainEditor"),
|
|
926
1096
|
auth: authClient,
|
|
927
1097
|
stateless: statelessApi,
|
|
928
|
-
createBatch
|
|
1098
|
+
createBatch,
|
|
1099
|
+
createProjectBatch
|
|
929
1100
|
};
|
|
930
1101
|
|
|
931
1102
|
// src/api/utils.ts
|
|
@@ -968,7 +1139,7 @@
|
|
|
968
1139
|
async dropImage(input) {
|
|
969
1140
|
let objectId = null;
|
|
970
1141
|
try {
|
|
971
|
-
const offset = unwrapResult(await this.context.get()).
|
|
1142
|
+
const offset = unwrapResult(await this.context.get()).iframeOffset;
|
|
972
1143
|
const params = this.buildDropImageParams(input, offset);
|
|
973
1144
|
objectId = await this.addDroppedImage(params);
|
|
974
1145
|
if (input.persistImage) {
|
|
@@ -1199,29 +1370,31 @@
|
|
|
1199
1370
|
|
|
1200
1371
|
// src/createEditorSDKAPIs.ts
|
|
1201
1372
|
function createEditorSDKAPIs() {
|
|
1373
|
+
const { project } = bridgeHandlers;
|
|
1374
|
+
const dragAndDrop = new DragAndDropApi({
|
|
1375
|
+
state: project.app.api,
|
|
1376
|
+
context: bridgeHandlers.context,
|
|
1377
|
+
design: project.design.api,
|
|
1378
|
+
upload: bridgeHandlers.upload
|
|
1379
|
+
});
|
|
1202
1380
|
return {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1381
|
+
aiGenerator: bridgeHandlers.aiGenerator,
|
|
1382
|
+
mockup: bridgeHandlers.mockup,
|
|
1383
|
+
project,
|
|
1206
1384
|
export: bridgeHandlers.export,
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
context: bridgeHandlers.context,
|
|
1210
|
-
dragAndDrop: new DragAndDropApi({
|
|
1211
|
-
state: bridgeHandlers.state,
|
|
1212
|
-
context: bridgeHandlers.context,
|
|
1213
|
-
design: bridgeHandlers.design,
|
|
1214
|
-
upload: bridgeHandlers.upload
|
|
1215
|
-
}),
|
|
1216
|
-
state: bridgeHandlers.state,
|
|
1385
|
+
helpers: { dragAndDrop },
|
|
1386
|
+
dragAndDrop,
|
|
1217
1387
|
auth: bridgeHandlers.auth,
|
|
1218
1388
|
upload: bridgeHandlers.upload,
|
|
1219
1389
|
stateless: bridgeHandlers.stateless,
|
|
1220
1390
|
font: bridgeHandlers.font,
|
|
1221
|
-
|
|
1391
|
+
fileBrowser: bridgeHandlers.fileBrowser
|
|
1222
1392
|
};
|
|
1223
1393
|
}
|
|
1224
1394
|
|
|
1395
|
+
// package.json
|
|
1396
|
+
var version = "1.0.0";
|
|
1397
|
+
|
|
1225
1398
|
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
1226
1399
|
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
1227
1400
|
if (typeof document === "undefined") {
|
|
@@ -1262,12 +1435,17 @@
|
|
|
1262
1435
|
handleIncomingMessage(event);
|
|
1263
1436
|
}
|
|
1264
1437
|
);
|
|
1265
|
-
|
|
1438
|
+
const { context } = apis;
|
|
1439
|
+
const themeSynced = context?.get && context.subscribe ? syncHtmlDataThemeFromHostContext({
|
|
1440
|
+
context
|
|
1441
|
+
}) : Promise.resolve();
|
|
1442
|
+
void themeSynced.catch(() => void 0).then(() => {
|
|
1266
1443
|
kittl2.onLoadedCallback?.();
|
|
1267
1444
|
sendLoaded();
|
|
1268
1445
|
});
|
|
1269
1446
|
};
|
|
1270
1447
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
1448
|
+
setSDKVersion(version);
|
|
1271
1449
|
window.kittl = kittl2;
|
|
1272
1450
|
if (document.readyState === "loading") {
|
|
1273
1451
|
document.addEventListener("DOMContentLoaded", initSdk);
|
|
@@ -1281,6 +1459,12 @@
|
|
|
1281
1459
|
// src/editorContentPanel.ts
|
|
1282
1460
|
var kittl = createKittlSDK({
|
|
1283
1461
|
...createEditorSDKAPIs(),
|
|
1284
|
-
|
|
1462
|
+
context: bridgeHandlers.context,
|
|
1463
|
+
brandKit: bridgeHandlers.brandKit,
|
|
1464
|
+
fileBrowser: {
|
|
1465
|
+
getFiles: bridgeHandlers.fileBrowser.getFiles,
|
|
1466
|
+
// Keep existing content-panel extensions working while registration moves to sharedFileBrowser context.
|
|
1467
|
+
registerUploadBrowser: bridgeHandlers.fileBrowserRegistration.registerUploadBrowser
|
|
1468
|
+
}
|
|
1285
1469
|
});
|
|
1286
1470
|
})();
|