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