@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
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
/*! Kittl SDK - https://kittl.com - see license for terms */
|
|
3
3
|
|
|
4
4
|
var FROM_EXTENSION_COMMANDS = {
|
|
5
|
+
/** Capability-owned AI callback registration. */
|
|
6
|
+
AI_GENERATOR_SUBSCRIBE: "ai-generator-subscribe",
|
|
7
|
+
/** Capability-owned AI callback teardown. */
|
|
8
|
+
AI_GENERATOR_UNSUBSCRIBE: "ai-generator-unsubscribe",
|
|
5
9
|
/** SDK API call */
|
|
6
10
|
SDK_CALL: "sdk-call",
|
|
7
11
|
/** AI handler registration */
|
|
@@ -50,6 +54,8 @@ var FROM_EXTENSION_COMMANDS = {
|
|
|
50
54
|
LOADED: "loaded"
|
|
51
55
|
};
|
|
52
56
|
var TO_EXTENSION_COMMANDS = {
|
|
57
|
+
/** Callback payload for generator or pending-set subscriptions. */
|
|
58
|
+
AI_GENERATOR_UPDATE: "ai-generator-update",
|
|
53
59
|
/** SDK API response */
|
|
54
60
|
SDK_RESPONSE: "sdk-response",
|
|
55
61
|
/** File browser fetch content request */
|
|
@@ -66,6 +72,10 @@ var TO_EXTENSION_COMMANDS = {
|
|
|
66
72
|
APP_STATE_UPDATE: "app-state-update"
|
|
67
73
|
};
|
|
68
74
|
|
|
75
|
+
function isAIGeneratorUpdateMessage(data) {
|
|
76
|
+
return !!data && typeof data === "object" && "command" in data && data.command === "ai-generator-update" && "subscriptionId" in data && typeof data.subscriptionId === "string";
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
var isSDKResponseMessage = (data) => {
|
|
70
80
|
return typeof data === "object" && data !== null && "command" in data && data.command === TO_EXTENSION_COMMANDS.SDK_RESPONSE && "messageId" in data && typeof data.messageId === "string";
|
|
71
81
|
};
|
|
@@ -135,7 +145,10 @@ var APPROVED_EXTENSION_COMMUNICATION_DOMAINS = [
|
|
|
135
145
|
"https://app.stagingdesigner.com",
|
|
136
146
|
"https://*.stagingdesigner.com",
|
|
137
147
|
"http://localhost:3000",
|
|
138
|
-
"https://app.kittl.com"
|
|
148
|
+
"https://app.kittl.com",
|
|
149
|
+
// website, for sandboxed standalone dashboard pages
|
|
150
|
+
"http://localhost:3003",
|
|
151
|
+
"https://www.kittl.com"
|
|
139
152
|
];
|
|
140
153
|
var toOrigin = (value) => {
|
|
141
154
|
if (!value) {
|
|
@@ -190,8 +203,15 @@ var getParentDomain = () => {
|
|
|
190
203
|
};
|
|
191
204
|
|
|
192
205
|
var pendingRequests = /* @__PURE__ */ new Map();
|
|
206
|
+
var sdkVersion;
|
|
207
|
+
function setSDKVersion(version2) {
|
|
208
|
+
sdkVersion = version2;
|
|
209
|
+
}
|
|
193
210
|
var postMessageToParent = (message) => {
|
|
194
|
-
window.parent.postMessage(
|
|
211
|
+
window.parent.postMessage(
|
|
212
|
+
sdkVersion === void 0 ? message : { ...message, sdkVersion },
|
|
213
|
+
getParentDomain()
|
|
214
|
+
);
|
|
195
215
|
};
|
|
196
216
|
var sendMessage = (message) => {
|
|
197
217
|
postMessageToParent(message);
|
|
@@ -214,6 +234,27 @@ var sendLoaded = () => {
|
|
|
214
234
|
};
|
|
215
235
|
|
|
216
236
|
var createSDKCallMessage = {
|
|
237
|
+
aiGenerator: (dots, args, messageId) => ({
|
|
238
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
239
|
+
dots,
|
|
240
|
+
args,
|
|
241
|
+
messageId,
|
|
242
|
+
apiType: "aiGenerator"
|
|
243
|
+
}),
|
|
244
|
+
mockup: (dots, args, messageId) => ({
|
|
245
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
246
|
+
dots,
|
|
247
|
+
args,
|
|
248
|
+
messageId,
|
|
249
|
+
apiType: "mockup"
|
|
250
|
+
}),
|
|
251
|
+
fileBrowser: (dots, args, messageId) => ({
|
|
252
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
253
|
+
dots,
|
|
254
|
+
args,
|
|
255
|
+
messageId,
|
|
256
|
+
apiType: "fileBrowser"
|
|
257
|
+
}),
|
|
217
258
|
ai: (dots, args, messageId) => ({
|
|
218
259
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
219
260
|
dots,
|
|
@@ -249,6 +290,13 @@ var createSDKCallMessage = {
|
|
|
249
290
|
messageId,
|
|
250
291
|
apiType: "font"
|
|
251
292
|
}),
|
|
293
|
+
project: (dots, args, messageId) => ({
|
|
294
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
295
|
+
dots,
|
|
296
|
+
args,
|
|
297
|
+
messageId,
|
|
298
|
+
apiType: "project"
|
|
299
|
+
}),
|
|
252
300
|
state: (dots, args, messageId) => ({
|
|
253
301
|
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
254
302
|
dots,
|
|
@@ -269,6 +317,27 @@ var createSDKCallMessage = {
|
|
|
269
317
|
args,
|
|
270
318
|
messageId,
|
|
271
319
|
apiType: "data"
|
|
320
|
+
}),
|
|
321
|
+
brandKit: (dots, args, messageId) => ({
|
|
322
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
323
|
+
dots,
|
|
324
|
+
args,
|
|
325
|
+
messageId,
|
|
326
|
+
apiType: "brandKit"
|
|
327
|
+
}),
|
|
328
|
+
openMicroEditor: (dots, args, messageId) => ({
|
|
329
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
330
|
+
dots,
|
|
331
|
+
args,
|
|
332
|
+
messageId,
|
|
333
|
+
apiType: "openMicroEditor"
|
|
334
|
+
}),
|
|
335
|
+
openMainEditor: (dots, args, messageId) => ({
|
|
336
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
337
|
+
dots,
|
|
338
|
+
args,
|
|
339
|
+
messageId,
|
|
340
|
+
apiType: "openMainEditor"
|
|
272
341
|
})
|
|
273
342
|
};
|
|
274
343
|
function createApiProxy(apiType) {
|
|
@@ -285,6 +354,64 @@ function createApiProxy(apiType) {
|
|
|
285
354
|
});
|
|
286
355
|
}
|
|
287
356
|
|
|
357
|
+
function createAIGeneratorBridgeApi() {
|
|
358
|
+
const callbacks = /* @__PURE__ */ new Map();
|
|
359
|
+
const proxy = createApiProxy("aiGenerator");
|
|
360
|
+
async function subscribe(request, callback) {
|
|
361
|
+
const subscriptionId = generateMessageId();
|
|
362
|
+
callbacks.set(subscriptionId, callback);
|
|
363
|
+
let response;
|
|
364
|
+
try {
|
|
365
|
+
response = await sendMessage({
|
|
366
|
+
command: "ai-generator-subscribe",
|
|
367
|
+
...request,
|
|
368
|
+
subscriptionId,
|
|
369
|
+
messageId: generateMessageId()
|
|
370
|
+
});
|
|
371
|
+
} catch (error) {
|
|
372
|
+
callbacks.delete(subscriptionId);
|
|
373
|
+
throw error;
|
|
374
|
+
}
|
|
375
|
+
if (!response.isOk) {
|
|
376
|
+
callbacks.delete(subscriptionId);
|
|
377
|
+
throw new Error(response.error.message);
|
|
378
|
+
}
|
|
379
|
+
return () => {
|
|
380
|
+
callbacks.delete(subscriptionId);
|
|
381
|
+
postMessageToParent({
|
|
382
|
+
command: "ai-generator-unsubscribe",
|
|
383
|
+
subscriptionId
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
const methods = {
|
|
388
|
+
registerGenerator: (id, callback) => subscribe({ method: "registerGenerator", args: [id] }, (update) => {
|
|
389
|
+
if (update) callback(update);
|
|
390
|
+
}),
|
|
391
|
+
subscribeToGenerationUpdates: (ids, callback) => subscribe(
|
|
392
|
+
{ method: "subscribeToGenerationUpdates", args: [ids] },
|
|
393
|
+
(update) => {
|
|
394
|
+
if (update) callback(update);
|
|
395
|
+
}
|
|
396
|
+
),
|
|
397
|
+
subscribeToPendingGenerations: (callback) => subscribe(
|
|
398
|
+
{ method: "subscribeToPendingGenerations", args: [] },
|
|
399
|
+
() => callback()
|
|
400
|
+
),
|
|
401
|
+
/** Callers may reuse richer internal submission objects; never send their local abort callbacks. */
|
|
402
|
+
cancelGenerations: (submission) => proxy.cancelGenerations({
|
|
403
|
+
generationIds: submission.generationIds,
|
|
404
|
+
until: submission.until
|
|
405
|
+
})
|
|
406
|
+
};
|
|
407
|
+
return {
|
|
408
|
+
api: new Proxy(proxy, {
|
|
409
|
+
get: (target, property, receiver) => property in methods ? methods[property] : Reflect.get(target, property, receiver)
|
|
410
|
+
}),
|
|
411
|
+
dispatch: (message) => callbacks.get(message.subscriptionId)?.(message.update)
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
288
415
|
var generationHandlers = /* @__PURE__ */ new Map();
|
|
289
416
|
var generationSubscriptions = /* @__PURE__ */ new Map();
|
|
290
417
|
var dispatchAIGenerationUpdate = (subscriptionId, update) => {
|
|
@@ -652,7 +779,7 @@ var SandboxedAuthClient = class {
|
|
|
652
779
|
}
|
|
653
780
|
};
|
|
654
781
|
|
|
655
|
-
var
|
|
782
|
+
var createBatchFor = async (apiType) => {
|
|
656
783
|
const response = await sendMessage({
|
|
657
784
|
command: FROM_EXTENSION_COMMANDS.BATCH_CREATE,
|
|
658
785
|
messageId: generateMessageId()
|
|
@@ -661,14 +788,17 @@ var createBatch = async () => {
|
|
|
661
788
|
throw response.error;
|
|
662
789
|
}
|
|
663
790
|
const { batchKey } = response.result;
|
|
664
|
-
const sendDesignCall = (dots, args) =>
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
791
|
+
const sendDesignCall = (dots, args) => {
|
|
792
|
+
const message = {
|
|
793
|
+
command: FROM_EXTENSION_COMMANDS.SDK_CALL,
|
|
794
|
+
dots: apiType === "project" ? ["design", "api", ...dots] : dots,
|
|
795
|
+
args,
|
|
796
|
+
messageId: generateMessageId(),
|
|
797
|
+
apiType,
|
|
798
|
+
batchKey
|
|
799
|
+
};
|
|
800
|
+
return sendMessage(message);
|
|
801
|
+
};
|
|
672
802
|
const commit = async () => {
|
|
673
803
|
const res = await sendMessage({
|
|
674
804
|
command: FROM_EXTENSION_COMMANDS.BATCH_COMMIT,
|
|
@@ -695,6 +825,8 @@ var createBatch = async () => {
|
|
|
695
825
|
};
|
|
696
826
|
return buildNode([]);
|
|
697
827
|
};
|
|
828
|
+
var createBatch = () => createBatchFor("design");
|
|
829
|
+
var createProjectBatch = () => createBatchFor("project");
|
|
698
830
|
|
|
699
831
|
var createContextBridgeApi = () => {
|
|
700
832
|
const contextProxy = createApiProxy("context");
|
|
@@ -862,6 +994,7 @@ var designStateApi = createDesignStateBridgeApi();
|
|
|
862
994
|
var appStateApi = createAppStateBridgeApi();
|
|
863
995
|
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
864
996
|
var authClient = new SandboxedAuthClient();
|
|
997
|
+
var aiGeneratorBridge = createAIGeneratorBridgeApi();
|
|
865
998
|
var handleIncomingMessage = (event) => {
|
|
866
999
|
const parent = window.parent;
|
|
867
1000
|
if (!parent || parent === window) {
|
|
@@ -884,6 +1017,10 @@ var handleIncomingMessage = (event) => {
|
|
|
884
1017
|
statelessApi.dispatch(data.type, data.payload);
|
|
885
1018
|
return;
|
|
886
1019
|
}
|
|
1020
|
+
if (isAIGeneratorUpdateMessage(data)) {
|
|
1021
|
+
aiGeneratorBridge.dispatch(data);
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
887
1024
|
if (isAIGenerationUpdatePushMessage(data)) {
|
|
888
1025
|
dispatchAIGenerationUpdate(data.subscriptionId, data.update);
|
|
889
1026
|
return;
|
|
@@ -908,7 +1045,28 @@ var handleIncomingMessage = (event) => {
|
|
|
908
1045
|
);
|
|
909
1046
|
}
|
|
910
1047
|
};
|
|
1048
|
+
var projectProxy = createApiProxy("project");
|
|
1049
|
+
var projectApi = {
|
|
1050
|
+
design: {
|
|
1051
|
+
state: {
|
|
1052
|
+
getState: projectProxy.design.state.getState,
|
|
1053
|
+
subscribe: designStateApi.subscribe
|
|
1054
|
+
},
|
|
1055
|
+
api: projectProxy.design.api,
|
|
1056
|
+
createBatch: createProjectBatch
|
|
1057
|
+
},
|
|
1058
|
+
app: {
|
|
1059
|
+
state: {
|
|
1060
|
+
getState: projectProxy.app.state.getState,
|
|
1061
|
+
subscribe: appStateApi.subscribe
|
|
1062
|
+
},
|
|
1063
|
+
api: projectProxy.app.api
|
|
1064
|
+
}
|
|
1065
|
+
};
|
|
911
1066
|
var bridgeHandlers = {
|
|
1067
|
+
aiGenerator: aiGeneratorBridge.api,
|
|
1068
|
+
brandKit: createApiProxy("brandKit"),
|
|
1069
|
+
mockup: createApiProxy("mockup"),
|
|
912
1070
|
ai: createAIApiProxy(),
|
|
913
1071
|
context: contextApi,
|
|
914
1072
|
data: createApiProxy("data"),
|
|
@@ -917,12 +1075,17 @@ var bridgeHandlers = {
|
|
|
917
1075
|
appStore: appStateApi,
|
|
918
1076
|
export: createApiProxy("export"),
|
|
919
1077
|
font: createApiProxy("font"),
|
|
1078
|
+
project: projectApi,
|
|
920
1079
|
state: createApiProxy("state"),
|
|
921
1080
|
upload: createApiProxy("upload"),
|
|
922
|
-
fileBrowser:
|
|
1081
|
+
fileBrowser: { getFiles: createApiProxy("fileBrowser").getFiles },
|
|
1082
|
+
fileBrowserRegistration: createFileBrowserApiProxy(),
|
|
1083
|
+
openMicroEditor: createApiProxy("openMicroEditor"),
|
|
1084
|
+
openMainEditor: createApiProxy("openMainEditor"),
|
|
923
1085
|
auth: authClient,
|
|
924
1086
|
stateless: statelessApi,
|
|
925
|
-
createBatch
|
|
1087
|
+
createBatch,
|
|
1088
|
+
createProjectBatch
|
|
926
1089
|
};
|
|
927
1090
|
|
|
928
1091
|
// src/api/utils.ts
|
|
@@ -965,7 +1128,7 @@ var DragAndDropApi = class {
|
|
|
965
1128
|
async dropImage(input) {
|
|
966
1129
|
let objectId = null;
|
|
967
1130
|
try {
|
|
968
|
-
const offset = unwrapResult(await this.context.get()).
|
|
1131
|
+
const offset = unwrapResult(await this.context.get()).iframeOffset;
|
|
969
1132
|
const params = this.buildDropImageParams(input, offset);
|
|
970
1133
|
objectId = await this.addDroppedImage(params);
|
|
971
1134
|
if (input.persistImage) {
|
|
@@ -1196,29 +1359,31 @@ var DragAndDropApi = class {
|
|
|
1196
1359
|
|
|
1197
1360
|
// src/createEditorSDKAPIs.ts
|
|
1198
1361
|
function createEditorSDKAPIs() {
|
|
1362
|
+
const { project } = bridgeHandlers;
|
|
1363
|
+
const dragAndDrop = new DragAndDropApi({
|
|
1364
|
+
state: project.app.api,
|
|
1365
|
+
context: bridgeHandlers.context,
|
|
1366
|
+
design: project.design.api,
|
|
1367
|
+
upload: bridgeHandlers.upload
|
|
1368
|
+
});
|
|
1199
1369
|
return {
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1370
|
+
aiGenerator: bridgeHandlers.aiGenerator,
|
|
1371
|
+
mockup: bridgeHandlers.mockup,
|
|
1372
|
+
project,
|
|
1203
1373
|
export: bridgeHandlers.export,
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
context: bridgeHandlers.context,
|
|
1207
|
-
dragAndDrop: new DragAndDropApi({
|
|
1208
|
-
state: bridgeHandlers.state,
|
|
1209
|
-
context: bridgeHandlers.context,
|
|
1210
|
-
design: bridgeHandlers.design,
|
|
1211
|
-
upload: bridgeHandlers.upload
|
|
1212
|
-
}),
|
|
1213
|
-
state: bridgeHandlers.state,
|
|
1374
|
+
helpers: { dragAndDrop },
|
|
1375
|
+
dragAndDrop,
|
|
1214
1376
|
auth: bridgeHandlers.auth,
|
|
1215
1377
|
upload: bridgeHandlers.upload,
|
|
1216
1378
|
stateless: bridgeHandlers.stateless,
|
|
1217
1379
|
font: bridgeHandlers.font,
|
|
1218
|
-
|
|
1380
|
+
fileBrowser: bridgeHandlers.fileBrowser
|
|
1219
1381
|
};
|
|
1220
1382
|
}
|
|
1221
1383
|
|
|
1384
|
+
// package.json
|
|
1385
|
+
var version = "1.0.0";
|
|
1386
|
+
|
|
1222
1387
|
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
1223
1388
|
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
1224
1389
|
if (typeof document === "undefined") {
|
|
@@ -1259,12 +1424,17 @@ function createKittlSDK(apis) {
|
|
|
1259
1424
|
handleIncomingMessage(event);
|
|
1260
1425
|
}
|
|
1261
1426
|
);
|
|
1262
|
-
|
|
1427
|
+
const { context } = apis;
|
|
1428
|
+
const themeSynced = context?.get && context.subscribe ? syncHtmlDataThemeFromHostContext({
|
|
1429
|
+
context
|
|
1430
|
+
}) : Promise.resolve();
|
|
1431
|
+
void themeSynced.catch(() => void 0).then(() => {
|
|
1263
1432
|
kittl2.onLoadedCallback?.();
|
|
1264
1433
|
sendLoaded();
|
|
1265
1434
|
});
|
|
1266
1435
|
};
|
|
1267
1436
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
1437
|
+
setSDKVersion(version);
|
|
1268
1438
|
window.kittl = kittl2;
|
|
1269
1439
|
if (document.readyState === "loading") {
|
|
1270
1440
|
document.addEventListener("DOMContentLoaded", initSdk);
|
|
@@ -1278,7 +1448,13 @@ function createKittlSDK(apis) {
|
|
|
1278
1448
|
// src/editorContentPanel.ts
|
|
1279
1449
|
var kittl = createKittlSDK({
|
|
1280
1450
|
...createEditorSDKAPIs(),
|
|
1281
|
-
|
|
1451
|
+
context: bridgeHandlers.context,
|
|
1452
|
+
brandKit: bridgeHandlers.brandKit,
|
|
1453
|
+
fileBrowser: {
|
|
1454
|
+
getFiles: bridgeHandlers.fileBrowser.getFiles,
|
|
1455
|
+
// Keep existing content-panel extensions working while registration moves to sharedFileBrowser context.
|
|
1456
|
+
registerUploadBrowser: bridgeHandlers.fileBrowserRegistration.registerUploadBrowser
|
|
1457
|
+
}
|
|
1282
1458
|
});
|
|
1283
1459
|
export {
|
|
1284
1460
|
kittl,
|