@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
|
@@ -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,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
|
|
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) =>
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
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:
|
|
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
|
|
@@ -936,291 +1099,8 @@
|
|
|
936
1099
|
throw result.error;
|
|
937
1100
|
}
|
|
938
1101
|
|
|
939
|
-
//
|
|
940
|
-
var
|
|
941
|
-
var DragAndDropApi = class {
|
|
942
|
-
/**
|
|
943
|
-
* Creates the drag-and-drop API from bridged SDK dependencies.
|
|
944
|
-
*/
|
|
945
|
-
constructor(dependencies) {
|
|
946
|
-
this.state = dependencies.state;
|
|
947
|
-
this.context = dependencies.context;
|
|
948
|
-
this.design = dependencies.design;
|
|
949
|
-
this.upload = dependencies.upload;
|
|
950
|
-
}
|
|
951
|
-
/**
|
|
952
|
-
* Handles the extension-side `dragstart` event and attaches a one-time
|
|
953
|
-
* `dragend` listener that completes the Kittl drop flow.
|
|
954
|
-
*/
|
|
955
|
-
startDragImageEvent(input) {
|
|
956
|
-
const metrics = this.captureDragMetrics(input);
|
|
957
|
-
this.applyNativeDragSetup(input.event.dataTransfer, input.img, metrics);
|
|
958
|
-
const handleDragEnd = (event) => {
|
|
959
|
-
void this.handleManagedDragEnd(metrics, event);
|
|
960
|
-
};
|
|
961
|
-
input.img.addEventListener("dragend", handleDragEnd, { once: true });
|
|
962
|
-
}
|
|
963
|
-
/**
|
|
964
|
-
* Inserts the dropped image at the computed drop position. When
|
|
965
|
-
* `input.persistImage === true`, fetches `src`, uploads it, and replaces
|
|
966
|
-
* the inserted object with the uploaded asset.
|
|
967
|
-
*/
|
|
968
|
-
async dropImage(input) {
|
|
969
|
-
let objectId = null;
|
|
970
|
-
try {
|
|
971
|
-
const offset = unwrapResult(await this.context.get()).dragAndDrop.offset;
|
|
972
|
-
const params = this.buildDropImageParams(input, offset);
|
|
973
|
-
objectId = await this.addDroppedImage(params);
|
|
974
|
-
if (input.persistImage) {
|
|
975
|
-
await this.persistDroppedImage({
|
|
976
|
-
objectId,
|
|
977
|
-
src: input.src
|
|
978
|
-
});
|
|
979
|
-
}
|
|
980
|
-
} catch {
|
|
981
|
-
}
|
|
982
|
-
return objectId;
|
|
983
|
-
}
|
|
984
|
-
/**
|
|
985
|
-
* Adds the dropped image to the design and returns the inserted object id.
|
|
986
|
-
*/
|
|
987
|
-
async addDroppedImage(params) {
|
|
988
|
-
const result = await this.design.image.addImage(params);
|
|
989
|
-
const insertedImage = unwrapResult(result);
|
|
990
|
-
if (!insertedImage?.id) {
|
|
991
|
-
throw new Error("Failed to add dropped image");
|
|
992
|
-
}
|
|
993
|
-
return insertedImage.id;
|
|
994
|
-
}
|
|
995
|
-
/**
|
|
996
|
-
* Fetches `src`, uploads the bytes, and replaces the inserted object with
|
|
997
|
-
* the uploaded Kittl asset when persistence succeeds.
|
|
998
|
-
*/
|
|
999
|
-
async persistDroppedImage(input) {
|
|
1000
|
-
const response = await fetch(input.src);
|
|
1001
|
-
if (!response.ok) {
|
|
1002
|
-
throw new Error(`Failed to fetch dropped image: ${response.status}`);
|
|
1003
|
-
}
|
|
1004
|
-
const blob = await response.blob();
|
|
1005
|
-
const uploadResult = await this.upload.image.upload({ blob });
|
|
1006
|
-
const uploadedFiles = unwrapResult(uploadResult);
|
|
1007
|
-
if (uploadedFiles.length === 0) {
|
|
1008
|
-
throw new Error("Failed to upload dropped image");
|
|
1009
|
-
}
|
|
1010
|
-
await this.replaceWithUploadedImage({
|
|
1011
|
-
objectId: input.objectId,
|
|
1012
|
-
objectName: uploadedFiles[0].objectName
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Replaces the inserted image with the uploaded asset if the object still
|
|
1017
|
-
* exists.
|
|
1018
|
-
*/
|
|
1019
|
-
async replaceWithUploadedImage(input) {
|
|
1020
|
-
const objectResult = await this.design.object.getObject({
|
|
1021
|
-
id: input.objectId
|
|
1022
|
-
});
|
|
1023
|
-
if (!objectResult.isOk) {
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
await this.design.image.updateImage({
|
|
1027
|
-
id: input.objectId,
|
|
1028
|
-
objectName: input.objectName
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
|
-
/**
|
|
1032
|
-
* Converts iframe drag coordinates into `addImage(...)` params, applying host
|
|
1033
|
-
* offsets, grab offsets, and optional rendered size.
|
|
1034
|
-
*/
|
|
1035
|
-
buildDropImageParams(input, offset) {
|
|
1036
|
-
const grabOffsetX = input.grabOffsetX ?? 0;
|
|
1037
|
-
const grabOffsetY = input.grabOffsetY ?? 0;
|
|
1038
|
-
const baseX = input.x + offset.left;
|
|
1039
|
-
const baseY = input.y + offset.top;
|
|
1040
|
-
const dropX = Math.floor(baseX - grabOffsetX);
|
|
1041
|
-
const dropY = Math.floor(baseY - grabOffsetY);
|
|
1042
|
-
const baseParams = {
|
|
1043
|
-
src: input.src.trim(),
|
|
1044
|
-
position: {
|
|
1045
|
-
relative: {
|
|
1046
|
-
to: "screen",
|
|
1047
|
-
coordinates: {
|
|
1048
|
-
x: dropX,
|
|
1049
|
-
y: dropY
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
};
|
|
1054
|
-
const { imgWidth, imgHeight } = input;
|
|
1055
|
-
if (typeof imgWidth !== "number" || typeof imgHeight !== "number") {
|
|
1056
|
-
return baseParams;
|
|
1057
|
-
}
|
|
1058
|
-
return {
|
|
1059
|
-
...baseParams,
|
|
1060
|
-
size: {
|
|
1061
|
-
width: imgWidth,
|
|
1062
|
-
height: imgHeight,
|
|
1063
|
-
applyViewportScale: true
|
|
1064
|
-
}
|
|
1065
|
-
};
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* Captures the rendered image size and pointer grab point at drag start so
|
|
1069
|
-
* the native drag preview and drop placement stay aligned.
|
|
1070
|
-
*/
|
|
1071
|
-
captureDragMetrics(input) {
|
|
1072
|
-
const rect = input.img.getBoundingClientRect();
|
|
1073
|
-
const displayWidth = Math.floor(rect.width);
|
|
1074
|
-
const displayHeight = Math.floor(rect.height);
|
|
1075
|
-
const grabOffsetX = this.getGrabOffset(
|
|
1076
|
-
input.event.clientX - rect.left,
|
|
1077
|
-
displayWidth
|
|
1078
|
-
);
|
|
1079
|
-
const grabOffsetY = this.getGrabOffset(
|
|
1080
|
-
input.event.clientY - rect.top,
|
|
1081
|
-
displayHeight
|
|
1082
|
-
);
|
|
1083
|
-
return {
|
|
1084
|
-
displayWidth,
|
|
1085
|
-
displayHeight,
|
|
1086
|
-
grabOffsetX,
|
|
1087
|
-
grabOffsetY,
|
|
1088
|
-
src: input.img.src,
|
|
1089
|
-
persistImage: input.persistImage === true
|
|
1090
|
-
};
|
|
1091
|
-
}
|
|
1092
|
-
/**
|
|
1093
|
-
* Clamps a raw pointer offset into the rendered image bounds.
|
|
1094
|
-
*/
|
|
1095
|
-
getGrabOffset(rawOffset, displaySize) {
|
|
1096
|
-
return this.clampFloor(rawOffset, 0, displaySize);
|
|
1097
|
-
}
|
|
1098
|
-
/**
|
|
1099
|
-
* Floors a number and clamps it into the provided inclusive range.
|
|
1100
|
-
*/
|
|
1101
|
-
clampFloor(value, min, max) {
|
|
1102
|
-
return Math.min(Math.max(Math.floor(value), min), max);
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Configures the browser drag payload and drag preview image for the current
|
|
1106
|
-
* drag operation.
|
|
1107
|
-
*/
|
|
1108
|
-
applyNativeDragSetup(dataTransfer, img, metrics) {
|
|
1109
|
-
if (!dataTransfer) {
|
|
1110
|
-
return;
|
|
1111
|
-
}
|
|
1112
|
-
const { displayWidth, displayHeight, grabOffsetX, grabOffsetY, src } = metrics;
|
|
1113
|
-
dataTransfer.setData("text/plain", src);
|
|
1114
|
-
dataTransfer.effectAllowed = "copy";
|
|
1115
|
-
const previewCanvas = this.getOrCreateDragPreviewCanvas();
|
|
1116
|
-
if (previewCanvas.canvas && previewCanvas.context) {
|
|
1117
|
-
previewCanvas.canvas.width = displayWidth;
|
|
1118
|
-
previewCanvas.canvas.height = displayHeight;
|
|
1119
|
-
previewCanvas.canvas.style.width = `${displayWidth}px`;
|
|
1120
|
-
previewCanvas.canvas.style.height = `${displayHeight}px`;
|
|
1121
|
-
previewCanvas.context.clearRect(0, 0, displayWidth, displayHeight);
|
|
1122
|
-
previewCanvas.context.drawImage(img, 0, 0, displayWidth, displayHeight);
|
|
1123
|
-
dataTransfer.setDragImage(previewCanvas.canvas, grabOffsetX, grabOffsetY);
|
|
1124
|
-
return;
|
|
1125
|
-
}
|
|
1126
|
-
dataTransfer.setDragImage(img, grabOffsetX, grabOffsetY);
|
|
1127
|
-
}
|
|
1128
|
-
/**
|
|
1129
|
-
* Creates and reuses the hidden canvas used as the native drag preview.
|
|
1130
|
-
* Reuse one canvas as a native drag image so we can control preview size exactly.
|
|
1131
|
-
* Browsers may auto-scale element drag ghosts, which shifts perceived cursor alignment.
|
|
1132
|
-
* Must be in the DOM - Chrome ignores setDragImage on detached elements and falls back
|
|
1133
|
-
* to a scaled ghost. Position it off-screen so it's invisible.
|
|
1134
|
-
*/
|
|
1135
|
-
getOrCreateDragPreviewCanvas() {
|
|
1136
|
-
if (typeof document === "undefined" || !document.body) {
|
|
1137
|
-
return {
|
|
1138
|
-
canvas: null,
|
|
1139
|
-
context: null
|
|
1140
|
-
};
|
|
1141
|
-
}
|
|
1142
|
-
if (!this.dragPreviewCanvas) {
|
|
1143
|
-
this.dragPreviewCanvas = document.createElement("canvas");
|
|
1144
|
-
this.dragPreviewCanvas.style.position = "fixed";
|
|
1145
|
-
this.dragPreviewCanvas.style.left = HIDDEN_DRAG_PREVIEW_OFFSET_PX;
|
|
1146
|
-
this.dragPreviewCanvas.style.top = HIDDEN_DRAG_PREVIEW_OFFSET_PX;
|
|
1147
|
-
this.dragPreviewCanvas.style.pointerEvents = "none";
|
|
1148
|
-
}
|
|
1149
|
-
if (!this.dragPreviewCanvas.isConnected) {
|
|
1150
|
-
document.body.appendChild(this.dragPreviewCanvas);
|
|
1151
|
-
}
|
|
1152
|
-
if (this.dragPreviewCtx === void 0) {
|
|
1153
|
-
this.dragPreviewCtx = this.dragPreviewCanvas.getContext("2d");
|
|
1154
|
-
}
|
|
1155
|
-
return {
|
|
1156
|
-
canvas: this.dragPreviewCanvas,
|
|
1157
|
-
context: this.dragPreviewCtx ?? null
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
|
-
/**
|
|
1161
|
-
* Completes the managed drag on `dragend` by ignoring cancelled/internal
|
|
1162
|
-
* drops, forwarding valid drops to `dropImage(...)`, and selecting the inserted
|
|
1163
|
-
* object when available.
|
|
1164
|
-
*/
|
|
1165
|
-
async handleManagedDragEnd(metrics, event) {
|
|
1166
|
-
const dropInput = {
|
|
1167
|
-
x: event.clientX,
|
|
1168
|
-
y: event.clientY,
|
|
1169
|
-
src: metrics.src,
|
|
1170
|
-
imgWidth: metrics.displayWidth,
|
|
1171
|
-
imgHeight: metrics.displayHeight,
|
|
1172
|
-
grabOffsetX: metrics.grabOffsetX,
|
|
1173
|
-
grabOffsetY: metrics.grabOffsetY,
|
|
1174
|
-
persistImage: metrics.persistImage
|
|
1175
|
-
};
|
|
1176
|
-
try {
|
|
1177
|
-
if (event.clientX === 0 && event.clientY === 0) {
|
|
1178
|
-
return;
|
|
1179
|
-
}
|
|
1180
|
-
if (this.isInsideIframeViewport(event.clientX, event.clientY)) {
|
|
1181
|
-
return;
|
|
1182
|
-
}
|
|
1183
|
-
const objectId = await this.dropImage(dropInput);
|
|
1184
|
-
if (!objectId) {
|
|
1185
|
-
return;
|
|
1186
|
-
}
|
|
1187
|
-
await this.state.setSelectedObjectsIds([objectId]);
|
|
1188
|
-
} catch {
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Returns true when the final pointer position is still inside the iframe
|
|
1193
|
-
* viewport.
|
|
1194
|
-
*/
|
|
1195
|
-
isInsideIframeViewport(x, y) {
|
|
1196
|
-
return x >= 0 && y >= 0 && x <= window.innerWidth && y <= window.innerHeight;
|
|
1197
|
-
}
|
|
1198
|
-
};
|
|
1199
|
-
|
|
1200
|
-
// src/createEditorSDKAPIs.ts
|
|
1201
|
-
function createEditorSDKAPIs() {
|
|
1202
|
-
return {
|
|
1203
|
-
ai: bridgeHandlers.ai,
|
|
1204
|
-
data: bridgeHandlers.data,
|
|
1205
|
-
design: bridgeHandlers.design,
|
|
1206
|
-
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,
|
|
1217
|
-
auth: bridgeHandlers.auth,
|
|
1218
|
-
upload: bridgeHandlers.upload,
|
|
1219
|
-
stateless: bridgeHandlers.stateless,
|
|
1220
|
-
font: bridgeHandlers.font,
|
|
1221
|
-
createBatch: bridgeHandlers.createBatch
|
|
1222
|
-
};
|
|
1223
|
-
}
|
|
1102
|
+
// package.json
|
|
1103
|
+
var version = "1.0.0";
|
|
1224
1104
|
|
|
1225
1105
|
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
1226
1106
|
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
@@ -1262,12 +1142,17 @@
|
|
|
1262
1142
|
handleIncomingMessage(event);
|
|
1263
1143
|
}
|
|
1264
1144
|
);
|
|
1265
|
-
|
|
1145
|
+
const { context } = apis;
|
|
1146
|
+
const themeSynced = context?.get && context.subscribe ? syncHtmlDataThemeFromHostContext({
|
|
1147
|
+
context
|
|
1148
|
+
}) : Promise.resolve();
|
|
1149
|
+
void themeSynced.catch(() => void 0).then(() => {
|
|
1266
1150
|
kittl2.onLoadedCallback?.();
|
|
1267
1151
|
sendLoaded();
|
|
1268
1152
|
});
|
|
1269
1153
|
};
|
|
1270
1154
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
1155
|
+
setSDKVersion(version);
|
|
1271
1156
|
window.kittl = kittl2;
|
|
1272
1157
|
if (document.readyState === "loading") {
|
|
1273
1158
|
document.addEventListener("DOMContentLoaded", initSdk);
|
|
@@ -1278,9 +1163,14 @@
|
|
|
1278
1163
|
return kittl2;
|
|
1279
1164
|
}
|
|
1280
1165
|
|
|
1281
|
-
// src/
|
|
1166
|
+
// src/dashboardStandalonePage.ts
|
|
1282
1167
|
var kittl = createKittlSDK({
|
|
1283
|
-
|
|
1168
|
+
auth: bridgeHandlers.auth,
|
|
1169
|
+
context: bridgeHandlers.context,
|
|
1170
|
+
upload: bridgeHandlers.upload,
|
|
1171
|
+
brandKit: bridgeHandlers.brandKit,
|
|
1172
|
+
openMicroEditor: bridgeHandlers.openMicroEditor,
|
|
1173
|
+
openMainEditor: bridgeHandlers.openMainEditor,
|
|
1284
1174
|
fileBrowser: bridgeHandlers.fileBrowser
|
|
1285
1175
|
});
|
|
1286
1176
|
})();
|