@kittl/sdk 0.0.3 → 0.0.4
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/kittl-sdk.esm.js +77 -3
- package/dist/kittl-sdk.js +77 -3
- package/dist/sdk.d.ts +8 -1
- package/package.json +1 -1
package/dist/kittl-sdk.esm.js
CHANGED
|
@@ -18,6 +18,9 @@ var isDesignStateUpdatePushMessage = (data) => {
|
|
|
18
18
|
var isAppStateUpdatePushMessage = (data) => {
|
|
19
19
|
return typeof data === "object" && data !== null && "command" in data && data.command === "app-state-update" && "updates" in data && Array.isArray(data.updates);
|
|
20
20
|
};
|
|
21
|
+
var isContextUpdatePushMessage = (data) => {
|
|
22
|
+
return typeof data === "object" && data !== null && "command" in data && data.command === "context-update" && "subscriptionId" in data && typeof data.subscriptionId === "string" && "context" in data && typeof data.context === "object" && data.context !== null;
|
|
23
|
+
};
|
|
21
24
|
|
|
22
25
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/shared/createApiProxyCore.js
|
|
23
26
|
var buildMethodPath = (rootPrefix, pathSegments) => {
|
|
@@ -486,6 +489,53 @@ var createBatch = async () => {
|
|
|
486
489
|
return buildNode([]);
|
|
487
490
|
};
|
|
488
491
|
|
|
492
|
+
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/context/contextBridge.js
|
|
493
|
+
var createContextBridgeApi = () => {
|
|
494
|
+
const contextProxy = createApiProxy("context");
|
|
495
|
+
const subscriptionCallbacks = /* @__PURE__ */ new Map();
|
|
496
|
+
const dispatch = (message) => {
|
|
497
|
+
const cb = subscriptionCallbacks.get(message.subscriptionId);
|
|
498
|
+
cb?.(message.context);
|
|
499
|
+
};
|
|
500
|
+
const subscribeImpl = async (callback) => {
|
|
501
|
+
const subscriptionId = generateMessageId();
|
|
502
|
+
const messageId = generateMessageId();
|
|
503
|
+
subscriptionCallbacks.set(subscriptionId, callback);
|
|
504
|
+
let response;
|
|
505
|
+
try {
|
|
506
|
+
response = await sendMessage({
|
|
507
|
+
command: "context-subscribe",
|
|
508
|
+
messageId,
|
|
509
|
+
subscriptionId
|
|
510
|
+
});
|
|
511
|
+
} catch (error) {
|
|
512
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
513
|
+
throw error;
|
|
514
|
+
}
|
|
515
|
+
if (!response.isOk) {
|
|
516
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
517
|
+
throw new Error(`context-subscribe failed: ${response.error.message}`);
|
|
518
|
+
}
|
|
519
|
+
return () => {
|
|
520
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
521
|
+
const message = {
|
|
522
|
+
command: "context-unsubscribe",
|
|
523
|
+
subscriptionId
|
|
524
|
+
};
|
|
525
|
+
postMessageToParent(message);
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
const api = new Proxy(contextProxy, {
|
|
529
|
+
get(target, prop, receiver) {
|
|
530
|
+
if (prop === "subscribe") {
|
|
531
|
+
return subscribeImpl;
|
|
532
|
+
}
|
|
533
|
+
return Reflect.get(target, prop, receiver);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
return { api, dispatch };
|
|
537
|
+
};
|
|
538
|
+
|
|
489
539
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/designState/index.js
|
|
490
540
|
var sendUnsubscribe2 = (selectorIds) => {
|
|
491
541
|
const message = {
|
|
@@ -607,6 +657,7 @@ var createStatelessBridgeApi = () => {
|
|
|
607
657
|
var statelessApi = createStatelessBridgeApi();
|
|
608
658
|
var designStateApi = createDesignStateBridgeApi();
|
|
609
659
|
var appStateApi = createAppStateBridgeApi();
|
|
660
|
+
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
610
661
|
var handleIncomingMessage = (event) => {
|
|
611
662
|
const parent = window.parent;
|
|
612
663
|
if (!parent || parent === window) {
|
|
@@ -641,10 +692,13 @@ var handleIncomingMessage = (event) => {
|
|
|
641
692
|
appStateApi.dispatch(data.updates);
|
|
642
693
|
return;
|
|
643
694
|
}
|
|
695
|
+
if (isContextUpdatePushMessage(data)) {
|
|
696
|
+
dispatchContextUpdate(data);
|
|
697
|
+
}
|
|
644
698
|
};
|
|
645
699
|
var bridgeHandlers = {
|
|
646
700
|
ai: createAIApiProxy(),
|
|
647
|
-
context:
|
|
701
|
+
context: contextApi,
|
|
648
702
|
design: createApiProxy("design"),
|
|
649
703
|
designStore: designStateApi,
|
|
650
704
|
appStore: appStateApi,
|
|
@@ -925,6 +979,24 @@ var DragAndDropApi = class {
|
|
|
925
979
|
}
|
|
926
980
|
};
|
|
927
981
|
|
|
982
|
+
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
983
|
+
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
984
|
+
if (typeof document === "undefined") {
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
const parent = window.parent;
|
|
988
|
+
if (!parent || parent === window) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
const contextResponse = await kittl2.context.get();
|
|
992
|
+
if (contextResponse.isOk) {
|
|
993
|
+
document.documentElement.dataset.theme = contextResponse.result.colorScheme;
|
|
994
|
+
}
|
|
995
|
+
await kittl2.context.subscribe((ctx) => {
|
|
996
|
+
document.documentElement.dataset.theme = ctx.colorScheme;
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
|
|
928
1000
|
// src/index.ts
|
|
929
1001
|
var kittl = {
|
|
930
1002
|
onLoadedCallback: null,
|
|
@@ -952,8 +1024,10 @@ var initSdk = () => {
|
|
|
952
1024
|
handleIncomingMessage(event);
|
|
953
1025
|
}
|
|
954
1026
|
);
|
|
955
|
-
kittl.
|
|
956
|
-
|
|
1027
|
+
void syncHtmlDataThemeFromHostContext(kittl).then(() => {
|
|
1028
|
+
kittl.onLoadedCallback?.();
|
|
1029
|
+
sendLoaded();
|
|
1030
|
+
});
|
|
957
1031
|
};
|
|
958
1032
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
959
1033
|
window.kittl = kittl;
|
package/dist/kittl-sdk.js
CHANGED
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
var isAppStateUpdatePushMessage = (data) => {
|
|
20
20
|
return typeof data === "object" && data !== null && "command" in data && data.command === "app-state-update" && "updates" in data && Array.isArray(data.updates);
|
|
21
21
|
};
|
|
22
|
+
var isContextUpdatePushMessage = (data) => {
|
|
23
|
+
return typeof data === "object" && data !== null && "command" in data && data.command === "context-update" && "subscriptionId" in data && typeof data.subscriptionId === "string" && "context" in data && typeof data.context === "object" && data.context !== null;
|
|
24
|
+
};
|
|
22
25
|
|
|
23
26
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/shared/createApiProxyCore.js
|
|
24
27
|
var buildMethodPath = (rootPrefix, pathSegments) => {
|
|
@@ -487,6 +490,53 @@
|
|
|
487
490
|
return buildNode([]);
|
|
488
491
|
};
|
|
489
492
|
|
|
493
|
+
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/context/contextBridge.js
|
|
494
|
+
var createContextBridgeApi = () => {
|
|
495
|
+
const contextProxy = createApiProxy("context");
|
|
496
|
+
const subscriptionCallbacks = /* @__PURE__ */ new Map();
|
|
497
|
+
const dispatch = (message) => {
|
|
498
|
+
const cb = subscriptionCallbacks.get(message.subscriptionId);
|
|
499
|
+
cb?.(message.context);
|
|
500
|
+
};
|
|
501
|
+
const subscribeImpl = async (callback) => {
|
|
502
|
+
const subscriptionId = generateMessageId();
|
|
503
|
+
const messageId = generateMessageId();
|
|
504
|
+
subscriptionCallbacks.set(subscriptionId, callback);
|
|
505
|
+
let response;
|
|
506
|
+
try {
|
|
507
|
+
response = await sendMessage({
|
|
508
|
+
command: "context-subscribe",
|
|
509
|
+
messageId,
|
|
510
|
+
subscriptionId
|
|
511
|
+
});
|
|
512
|
+
} catch (error) {
|
|
513
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
516
|
+
if (!response.isOk) {
|
|
517
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
518
|
+
throw new Error(`context-subscribe failed: ${response.error.message}`);
|
|
519
|
+
}
|
|
520
|
+
return () => {
|
|
521
|
+
subscriptionCallbacks.delete(subscriptionId);
|
|
522
|
+
const message = {
|
|
523
|
+
command: "context-unsubscribe",
|
|
524
|
+
subscriptionId
|
|
525
|
+
};
|
|
526
|
+
postMessageToParent(message);
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
const api = new Proxy(contextProxy, {
|
|
530
|
+
get(target, prop, receiver) {
|
|
531
|
+
if (prop === "subscribe") {
|
|
532
|
+
return subscribeImpl;
|
|
533
|
+
}
|
|
534
|
+
return Reflect.get(target, prop, receiver);
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
return { api, dispatch };
|
|
538
|
+
};
|
|
539
|
+
|
|
490
540
|
// ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/designState/index.js
|
|
491
541
|
var sendUnsubscribe2 = (selectorIds) => {
|
|
492
542
|
const message = {
|
|
@@ -608,6 +658,7 @@
|
|
|
608
658
|
var statelessApi = createStatelessBridgeApi();
|
|
609
659
|
var designStateApi = createDesignStateBridgeApi();
|
|
610
660
|
var appStateApi = createAppStateBridgeApi();
|
|
661
|
+
var { api: contextApi, dispatch: dispatchContextUpdate } = createContextBridgeApi();
|
|
611
662
|
var handleIncomingMessage = (event) => {
|
|
612
663
|
const parent = window.parent;
|
|
613
664
|
if (!parent || parent === window) {
|
|
@@ -642,10 +693,13 @@
|
|
|
642
693
|
appStateApi.dispatch(data.updates);
|
|
643
694
|
return;
|
|
644
695
|
}
|
|
696
|
+
if (isContextUpdatePushMessage(data)) {
|
|
697
|
+
dispatchContextUpdate(data);
|
|
698
|
+
}
|
|
645
699
|
};
|
|
646
700
|
var bridgeHandlers = {
|
|
647
701
|
ai: createAIApiProxy(),
|
|
648
|
-
context:
|
|
702
|
+
context: contextApi,
|
|
649
703
|
design: createApiProxy("design"),
|
|
650
704
|
designStore: designStateApi,
|
|
651
705
|
appStore: appStateApi,
|
|
@@ -926,6 +980,24 @@
|
|
|
926
980
|
}
|
|
927
981
|
};
|
|
928
982
|
|
|
983
|
+
// src/utils/syncHtmlDataThemeFromHostContext.ts
|
|
984
|
+
async function syncHtmlDataThemeFromHostContext(kittl2) {
|
|
985
|
+
if (typeof document === "undefined") {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
const parent = window.parent;
|
|
989
|
+
if (!parent || parent === window) {
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
const contextResponse = await kittl2.context.get();
|
|
993
|
+
if (contextResponse.isOk) {
|
|
994
|
+
document.documentElement.dataset.theme = contextResponse.result.colorScheme;
|
|
995
|
+
}
|
|
996
|
+
await kittl2.context.subscribe((ctx) => {
|
|
997
|
+
document.documentElement.dataset.theme = ctx.colorScheme;
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
|
|
929
1001
|
// src/index.ts
|
|
930
1002
|
var kittl = {
|
|
931
1003
|
onLoadedCallback: null,
|
|
@@ -953,8 +1025,10 @@
|
|
|
953
1025
|
handleIncomingMessage(event);
|
|
954
1026
|
}
|
|
955
1027
|
);
|
|
956
|
-
kittl.
|
|
957
|
-
|
|
1028
|
+
void syncHtmlDataThemeFromHostContext(kittl).then(() => {
|
|
1029
|
+
kittl.onLoadedCallback?.();
|
|
1030
|
+
sendLoaded();
|
|
1031
|
+
});
|
|
958
1032
|
};
|
|
959
1033
|
if (typeof document !== "undefined" && typeof window !== "undefined") {
|
|
960
1034
|
window.kittl = kittl;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -567,6 +567,7 @@ export interface AppStateAPI {
|
|
|
567
567
|
setCanvasMode(mode: AppState["canvasMode"], origin?: Origin): void;
|
|
568
568
|
getActiveTool(): ActiveTool | null;
|
|
569
569
|
setActiveTool(tool: ActiveTool | null): void;
|
|
570
|
+
getIsDragPanning(): boolean;
|
|
570
571
|
viewport: ViewportAPI;
|
|
571
572
|
getHighlightedObjectId(): string | null;
|
|
572
573
|
setHighlightedObjectId(id: string | null): void;
|
|
@@ -617,7 +618,8 @@ export interface AsyncAuthAPI {
|
|
|
617
618
|
export interface AsyncBatchDesignAPI extends AsyncDesignAPI {
|
|
618
619
|
commit: () => Promise<void>;
|
|
619
620
|
}
|
|
620
|
-
export interface AsyncContextAPI extends WithAsync<ContextAPI> {
|
|
621
|
+
export interface AsyncContextAPI extends Omit<WithAsync<ContextAPI>, "subscribe"> {
|
|
622
|
+
subscribe(callback: ContextSubscriptionCallback): Promise<() => void>;
|
|
621
623
|
}
|
|
622
624
|
export interface AsyncDesignAPI extends WithAsync<WithOptsRemoved<DesignAPI>> {
|
|
623
625
|
}
|
|
@@ -762,6 +764,7 @@ export interface ConfigAPI {
|
|
|
762
764
|
}
|
|
763
765
|
export interface ContextAPI {
|
|
764
766
|
get(input?: ContextGetInput): KittlContext;
|
|
767
|
+
subscribe(callback: ContextSubscriptionCallback): () => void;
|
|
765
768
|
}
|
|
766
769
|
export interface ContextGetInput {
|
|
767
770
|
iframe?: Pick<HTMLIFrameElement, "getBoundingClientRect">;
|
|
@@ -1267,6 +1270,8 @@ export type ActiveTool = {
|
|
|
1267
1270
|
type: "artboard";
|
|
1268
1271
|
} | {
|
|
1269
1272
|
type: "move";
|
|
1273
|
+
} | {
|
|
1274
|
+
type: "hand";
|
|
1270
1275
|
} | {
|
|
1271
1276
|
type: "pen";
|
|
1272
1277
|
} | {
|
|
@@ -1349,6 +1354,7 @@ export type AppState = {
|
|
|
1349
1354
|
canvasMode: CanvasMode | string;
|
|
1350
1355
|
activeTool: ActiveTool | null;
|
|
1351
1356
|
viewport: Viewport;
|
|
1357
|
+
isDragPanning: boolean;
|
|
1352
1358
|
highlightedObjectId: string | null;
|
|
1353
1359
|
};
|
|
1354
1360
|
/**
|
|
@@ -1409,6 +1415,7 @@ export type CombinedShapeSerializedObject = Omit<typeof DEFAULT_VALUES, "shapes"
|
|
|
1409
1415
|
export type ConnectedArtboardOptions<T extends ArtboardLikeType = ArtboardLikeType> = BaseStandardArtboardOptions<T> & {
|
|
1410
1416
|
inputBoardIds?: string[];
|
|
1411
1417
|
};
|
|
1418
|
+
export type ContextSubscriptionCallback = (context: KittlContext) => void;
|
|
1412
1419
|
export type ConvertShapeToMaskInput = {
|
|
1413
1420
|
id: NormalizedBasicShapeObject["id"];
|
|
1414
1421
|
};
|