@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.
@@ -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(message, getParentDomain());
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,27 @@
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"
275
344
  })
276
345
  };
277
346
  function createApiProxy(apiType) {
@@ -288,6 +357,64 @@
288
357
  });
289
358
  }
290
359
 
360
+ function createAIGeneratorBridgeApi() {
361
+ const callbacks = /* @__PURE__ */ new Map();
362
+ const proxy = createApiProxy("aiGenerator");
363
+ async function subscribe(request, callback) {
364
+ const subscriptionId = generateMessageId();
365
+ callbacks.set(subscriptionId, callback);
366
+ let response;
367
+ try {
368
+ response = await sendMessage({
369
+ command: "ai-generator-subscribe",
370
+ ...request,
371
+ subscriptionId,
372
+ messageId: generateMessageId()
373
+ });
374
+ } catch (error) {
375
+ callbacks.delete(subscriptionId);
376
+ throw error;
377
+ }
378
+ if (!response.isOk) {
379
+ callbacks.delete(subscriptionId);
380
+ throw new Error(response.error.message);
381
+ }
382
+ return () => {
383
+ callbacks.delete(subscriptionId);
384
+ postMessageToParent({
385
+ command: "ai-generator-unsubscribe",
386
+ subscriptionId
387
+ });
388
+ };
389
+ }
390
+ const methods = {
391
+ registerGenerator: (id, callback) => subscribe({ method: "registerGenerator", args: [id] }, (update) => {
392
+ if (update) callback(update);
393
+ }),
394
+ subscribeToGenerationUpdates: (ids, callback) => subscribe(
395
+ { method: "subscribeToGenerationUpdates", args: [ids] },
396
+ (update) => {
397
+ if (update) callback(update);
398
+ }
399
+ ),
400
+ subscribeToPendingGenerations: (callback) => subscribe(
401
+ { method: "subscribeToPendingGenerations", args: [] },
402
+ () => callback()
403
+ ),
404
+ /** Callers may reuse richer internal submission objects; never send their local abort callbacks. */
405
+ cancelGenerations: (submission) => proxy.cancelGenerations({
406
+ generationIds: submission.generationIds,
407
+ until: submission.until
408
+ })
409
+ };
410
+ return {
411
+ api: new Proxy(proxy, {
412
+ get: (target, property, receiver) => property in methods ? methods[property] : Reflect.get(target, property, receiver)
413
+ }),
414
+ dispatch: (message) => callbacks.get(message.subscriptionId)?.(message.update)
415
+ };
416
+ }
417
+
291
418
  var generationHandlers = /* @__PURE__ */ new Map();
292
419
  var generationSubscriptions = /* @__PURE__ */ new Map();
293
420
  var dispatchAIGenerationUpdate = (subscriptionId, update) => {
@@ -655,7 +782,7 @@
655
782
  }
656
783
  };
657
784
 
658
- var createBatch = async () => {
785
+ var createBatchFor = async (apiType) => {
659
786
  const response = await sendMessage({
660
787
  command: FROM_EXTENSION_COMMANDS.BATCH_CREATE,
661
788
  messageId: generateMessageId()
@@ -664,14 +791,17 @@
664
791
  throw response.error;
665
792
  }
666
793
  const { batchKey } = response.result;
667
- const sendDesignCall = (dots, args) => sendMessage({
668
- command: FROM_EXTENSION_COMMANDS.SDK_CALL,
669
- dots,
670
- args,
671
- messageId: generateMessageId(),
672
- apiType: "design",
673
- batchKey
674
- });
794
+ const sendDesignCall = (dots, args) => {
795
+ const message = {
796
+ command: FROM_EXTENSION_COMMANDS.SDK_CALL,
797
+ dots: apiType === "project" ? ["design", "api", ...dots] : dots,
798
+ args,
799
+ messageId: generateMessageId(),
800
+ apiType,
801
+ batchKey
802
+ };
803
+ return sendMessage(message);
804
+ };
675
805
  const commit = async () => {
676
806
  const res = await sendMessage({
677
807
  command: FROM_EXTENSION_COMMANDS.BATCH_COMMIT,
@@ -698,6 +828,8 @@
698
828
  };
699
829
  return buildNode([]);
700
830
  };
831
+ var createBatch = () => createBatchFor("design");
832
+ var createProjectBatch = () => createBatchFor("project");
701
833
 
702
834
  var createContextBridgeApi = () => {
703
835
  const contextProxy = createApiProxy("context");
@@ -865,6 +997,7 @@
865
997
  var appStateApi = createAppStateBridgeApi();
866
998
  var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
867
999
  var authClient = new SandboxedAuthClient();
1000
+ var aiGeneratorBridge = createAIGeneratorBridgeApi();
868
1001
  var handleIncomingMessage = (event) => {
869
1002
  const parent = window.parent;
870
1003
  if (!parent || parent === window) {
@@ -887,6 +1020,10 @@
887
1020
  statelessApi.dispatch(data.type, data.payload);
888
1021
  return;
889
1022
  }
1023
+ if (isAIGeneratorUpdateMessage(data)) {
1024
+ aiGeneratorBridge.dispatch(data);
1025
+ return;
1026
+ }
890
1027
  if (isAIGenerationUpdatePushMessage(data)) {
891
1028
  dispatchAIGenerationUpdate(data.subscriptionId, data.update);
892
1029
  return;
@@ -911,7 +1048,28 @@
911
1048
  );
912
1049
  }
913
1050
  };
1051
+ var projectProxy = createApiProxy("project");
1052
+ var projectApi = {
1053
+ design: {
1054
+ state: {
1055
+ getState: projectProxy.design.state.getState,
1056
+ subscribe: designStateApi.subscribe
1057
+ },
1058
+ api: projectProxy.design.api,
1059
+ createBatch: createProjectBatch
1060
+ },
1061
+ app: {
1062
+ state: {
1063
+ getState: projectProxy.app.state.getState,
1064
+ subscribe: appStateApi.subscribe
1065
+ },
1066
+ api: projectProxy.app.api
1067
+ }
1068
+ };
914
1069
  var bridgeHandlers = {
1070
+ aiGenerator: aiGeneratorBridge.api,
1071
+ brandKit: createApiProxy("brandKit"),
1072
+ mockup: createApiProxy("mockup"),
915
1073
  ai: createAIApiProxy(),
916
1074
  context: contextApi,
917
1075
  data: createApiProxy("data"),
@@ -920,12 +1078,17 @@
920
1078
  appStore: appStateApi,
921
1079
  export: createApiProxy("export"),
922
1080
  font: createApiProxy("font"),
1081
+ project: projectApi,
923
1082
  state: createApiProxy("state"),
924
1083
  upload: createApiProxy("upload"),
925
- fileBrowser: createFileBrowserApiProxy(),
1084
+ fileBrowser: { getFiles: createApiProxy("fileBrowser").getFiles },
1085
+ fileBrowserRegistration: createFileBrowserApiProxy(),
1086
+ openMicroEditor: createApiProxy("openMicroEditor"),
1087
+ openMainEditor: createApiProxy("openMainEditor"),
926
1088
  auth: authClient,
927
1089
  stateless: statelessApi,
928
- createBatch
1090
+ createBatch,
1091
+ createProjectBatch
929
1092
  };
930
1093
 
931
1094
  // src/api/utils.ts
@@ -968,7 +1131,7 @@
968
1131
  async dropImage(input) {
969
1132
  let objectId = null;
970
1133
  try {
971
- const offset = unwrapResult(await this.context.get()).dragAndDrop.offset;
1134
+ const offset = unwrapResult(await this.context.get()).iframeOffset;
972
1135
  const params = this.buildDropImageParams(input, offset);
973
1136
  objectId = await this.addDroppedImage(params);
974
1137
  if (input.persistImage) {
@@ -1199,29 +1362,31 @@
1199
1362
 
1200
1363
  // src/createEditorSDKAPIs.ts
1201
1364
  function createEditorSDKAPIs() {
1365
+ const { project } = bridgeHandlers;
1366
+ const dragAndDrop = new DragAndDropApi({
1367
+ state: project.app.api,
1368
+ context: bridgeHandlers.context,
1369
+ design: project.design.api,
1370
+ upload: bridgeHandlers.upload
1371
+ });
1202
1372
  return {
1203
- ai: bridgeHandlers.ai,
1204
- data: bridgeHandlers.data,
1205
- design: bridgeHandlers.design,
1373
+ aiGenerator: bridgeHandlers.aiGenerator,
1374
+ mockup: bridgeHandlers.mockup,
1375
+ project,
1206
1376
  export: bridgeHandlers.export,
1207
- designStore: bridgeHandlers.designStore,
1208
- appStore: bridgeHandlers.appStore,
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,
1377
+ helpers: { dragAndDrop },
1378
+ dragAndDrop,
1217
1379
  auth: bridgeHandlers.auth,
1218
1380
  upload: bridgeHandlers.upload,
1219
1381
  stateless: bridgeHandlers.stateless,
1220
1382
  font: bridgeHandlers.font,
1221
- createBatch: bridgeHandlers.createBatch
1383
+ fileBrowser: bridgeHandlers.fileBrowser
1222
1384
  };
1223
1385
  }
1224
1386
 
1387
+ // package.json
1388
+ var version = "1.0.0";
1389
+
1225
1390
  // src/utils/syncHtmlDataThemeFromHostContext.ts
1226
1391
  async function syncHtmlDataThemeFromHostContext(kittl2) {
1227
1392
  if (typeof document === "undefined") {
@@ -1262,12 +1427,17 @@
1262
1427
  handleIncomingMessage(event);
1263
1428
  }
1264
1429
  );
1265
- void syncHtmlDataThemeFromHostContext(kittl2).then(() => {
1430
+ const { context } = apis;
1431
+ const themeSynced = context?.get && context.subscribe ? syncHtmlDataThemeFromHostContext({
1432
+ context
1433
+ }) : Promise.resolve();
1434
+ void themeSynced.catch(() => void 0).then(() => {
1266
1435
  kittl2.onLoadedCallback?.();
1267
1436
  sendLoaded();
1268
1437
  });
1269
1438
  };
1270
1439
  if (typeof document !== "undefined" && typeof window !== "undefined") {
1440
+ setSDKVersion(version);
1271
1441
  window.kittl = kittl2;
1272
1442
  if (document.readyState === "loading") {
1273
1443
  document.addEventListener("DOMContentLoaded", initSdk);
@@ -1281,6 +1451,12 @@
1281
1451
  // src/editorContentPanel.ts
1282
1452
  var kittl = createKittlSDK({
1283
1453
  ...createEditorSDKAPIs(),
1284
- fileBrowser: bridgeHandlers.fileBrowser
1454
+ context: bridgeHandlers.context,
1455
+ brandKit: bridgeHandlers.brandKit,
1456
+ fileBrowser: {
1457
+ getFiles: bridgeHandlers.fileBrowser.getFiles,
1458
+ // Keep existing content-panel extensions working while registration moves to sharedFileBrowser context.
1459
+ registerUploadBrowser: bridgeHandlers.fileBrowserRegistration.registerUploadBrowser
1460
+ }
1285
1461
  });
1286
1462
  })();