@adhese/sdk-devtools 0.11.6 → 0.12.0
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/CHANGELOG.md +14 -0
- package/dist/AdheseContext.js +19 -0
- package/dist/AdheseContext.js.map +1 -0
- package/dist/Devtools.hooks.js +24 -0
- package/dist/Devtools.hooks.js.map +1 -0
- package/dist/Devtools.js +79 -0
- package/dist/Devtools.js.map +1 -0
- package/dist/cjs/AdheseContext.cjs +19 -0
- package/dist/cjs/AdheseContext.cjs.map +1 -0
- package/dist/cjs/Devtools.cjs +79 -0
- package/dist/cjs/Devtools.cjs.map +1 -0
- package/dist/cjs/Devtools.hooks.cjs +24 -0
- package/dist/cjs/Devtools.hooks.cjs.map +1 -0
- package/dist/cjs/components/badge.cjs +27 -0
- package/dist/cjs/components/badge.cjs.map +1 -0
- package/dist/cjs/components/button.cjs +49 -0
- package/dist/cjs/components/button.cjs.map +1 -0
- package/dist/cjs/components/editSlot.cjs +110 -0
- package/dist/cjs/components/editSlot.cjs.map +1 -0
- package/dist/cjs/components/form.cjs +110 -0
- package/dist/cjs/components/form.cjs.map +1 -0
- package/dist/cjs/components/fronttailSettings.cjs +94 -0
- package/dist/cjs/components/fronttailSettings.cjs.map +1 -0
- package/dist/cjs/components/input.cjs +22 -0
- package/dist/cjs/components/input.cjs.map +1 -0
- package/dist/cjs/components/label.cjs +38 -0
- package/dist/cjs/components/label.cjs.map +1 -0
- package/dist/cjs/components/logTable.cjs +67 -0
- package/dist/cjs/components/logTable.cjs.map +1 -0
- package/dist/cjs/components/parametersTable.cjs +40 -0
- package/dist/cjs/components/parametersTable.cjs.map +1 -0
- package/dist/cjs/components/previewButton.cjs +19 -0
- package/dist/cjs/components/previewButton.cjs.map +1 -0
- package/dist/cjs/components/settings.cjs +10 -0
- package/dist/cjs/components/settings.cjs.map +1 -0
- package/dist/cjs/components/sheet.cjs +118 -0
- package/dist/cjs/components/sheet.cjs.map +1 -0
- package/dist/cjs/components/slotsTable.cjs +230 -0
- package/dist/cjs/components/slotsTable.cjs.map +1 -0
- package/dist/cjs/components/switch.cjs +45 -0
- package/dist/cjs/components/switch.cjs.map +1 -0
- package/dist/cjs/components/table.cjs +91 -0
- package/dist/cjs/components/table.cjs.map +1 -0
- package/dist/cjs/components/tabs.cjs +65 -0
- package/dist/cjs/components/tabs.cjs.map +1 -0
- package/dist/cjs/devtools.composables.cjs +116 -0
- package/dist/cjs/devtools.composables.cjs.map +1 -0
- package/dist/cjs/main.cjs +16 -0
- package/dist/cjs/main.cjs.map +1 -0
- package/dist/cjs/modifiedSlots.store.cjs +63 -0
- package/dist/cjs/modifiedSlots.store.cjs.map +1 -0
- package/dist/cjs/package.json.cjs +7 -0
- package/dist/cjs/package.json.cjs.map +1 -0
- package/dist/cjs/sdkDevtools.cjs +17 -0
- package/dist/cjs/sdkDevtools.cjs.map +1 -0
- package/dist/cjs/utils.cjs +9 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/components/badge.js +27 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/button.js +49 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/editSlot.js +110 -0
- package/dist/components/editSlot.js.map +1 -0
- package/dist/components/form.js +110 -0
- package/dist/components/form.js.map +1 -0
- package/dist/components/fronttailSettings.js +94 -0
- package/dist/components/fronttailSettings.js.map +1 -0
- package/dist/components/input.js +22 -0
- package/dist/components/input.js.map +1 -0
- package/dist/components/label.js +21 -0
- package/dist/components/label.js.map +1 -0
- package/dist/components/logTable.js +67 -0
- package/dist/components/logTable.js.map +1 -0
- package/dist/components/parametersTable.js +40 -0
- package/dist/components/parametersTable.js.map +1 -0
- package/dist/components/previewButton.js +19 -0
- package/dist/components/previewButton.js.map +1 -0
- package/dist/components/settings.js +10 -0
- package/dist/components/settings.js.map +1 -0
- package/dist/components/sheet.js +101 -0
- package/dist/components/sheet.js.map +1 -0
- package/dist/components/slotsTable.js +230 -0
- package/dist/components/slotsTable.js.map +1 -0
- package/dist/components/switch.js +28 -0
- package/dist/components/switch.js.map +1 -0
- package/dist/components/table.js +91 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/tabs.js +48 -0
- package/dist/components/tabs.js.map +1 -0
- package/dist/devtools.composables.js +116 -0
- package/dist/devtools.composables.js.map +1 -0
- package/dist/main.js +16 -0
- package/dist/main.js.map +1 -0
- package/dist/modifiedSlots.store.js +63 -0
- package/dist/modifiedSlots.store.js.map +1 -0
- package/dist/package.json.js +7 -0
- package/dist/package.json.js.map +1 -0
- package/dist/sdkDevtools.js +17 -0
- package/dist/sdkDevtools.js.map +1 -0
- package/dist/utils.js +9 -0
- package/dist/utils.js.map +1 -0
- package/package.json +11 -8
- package/dist/devtools-Cbms1xWf.cjs +0 -816
- package/dist/devtools-Cbms1xWf.cjs.map +0 -1
- package/dist/devtools-CjRcI3Xd.js +0 -797
- package/dist/devtools-CjRcI3Xd.js.map +0 -1
- package/dist/index.cjs +0 -47
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -47
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.cjs","sources":["../../../src/components/tabs.tsx"],"sourcesContent":["/* eslint-disable ts/naming-convention */\n\nimport * as TabsPrimitive from '@radix-ui/react-tabs';\nimport { type ComponentPropsWithoutRef, type ElementRef, forwardRef } from 'react';\nimport { cn } from '../utils';\n\nconst Tabs = TabsPrimitive.Root;\n\nconst TabsList = forwardRef<\n ElementRef<typeof TabsPrimitive.List>,\n ComponentPropsWithoutRef<typeof TabsPrimitive.List>\n>(({ className, ...props }, ref) => (\n <TabsPrimitive.List\n ref={ref}\n className={cn(\n 'inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground',\n className,\n )}\n {...props}\n />\n));\nTabsList.displayName = TabsPrimitive.List.displayName;\n\nconst TabsTrigger = forwardRef<\n ElementRef<typeof TabsPrimitive.Trigger>,\n ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>\n>(({ className, ...props }, ref) => (\n <TabsPrimitive.Trigger\n ref={ref}\n className={cn(\n 'inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow',\n className,\n )}\n {...props}\n />\n));\nTabsTrigger.displayName = TabsPrimitive.Trigger.displayName;\n\nconst TabsContent = forwardRef<\n ElementRef<typeof TabsPrimitive.Content>,\n ComponentPropsWithoutRef<typeof TabsPrimitive.Content>\n>(({ className, ...props }, ref) => (\n <TabsPrimitive.Content\n ref={ref}\n className={cn(\n 'mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',\n className,\n )}\n {...props}\n />\n));\nTabsContent.displayName = TabsPrimitive.Content.displayName;\n\nexport { Tabs, TabsList, TabsTrigger, TabsContent };\n"],"names":["TabsPrimitive","forwardRef","jsx","cn"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,OAAOA,yBAAc;AAErB,MAAA,WAAWC,iBAGf,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1BC,2BAAA;AAAA,EAACF,yBAAc;AAAA,EAAd;AAAA,IACC;AAAA,IACA,WAAWG,MAAA;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,IACC,GAAG;AAAA,EAAA;AACN,CACD;AACD,SAAS,cAAcH,yBAAc,KAAK;AAEpC,MAAA,cAAcC,iBAGlB,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1BC,2BAAA;AAAA,EAACF,yBAAc;AAAA,EAAd;AAAA,IACC;AAAA,IACA,WAAWG,MAAA;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,IACC,GAAG;AAAA,EAAA;AACN,CACD;AACD,YAAY,cAAcH,yBAAc,QAAQ;AAE1C,MAAA,cAAcC,iBAGlB,CAAC,EAAE,WAAW,GAAG,MAAA,GAAS,QAC1BC,2BAAA;AAAA,EAACF,yBAAc;AAAA,EAAd;AAAA,IACC;AAAA,IACA,WAAWG,MAAA;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,IACC,GAAG;AAAA,EAAA;AACN,CACD;AACD,YAAY,cAAcH,yBAAc,QAAQ;;;;;"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const sdkShared = require("@adhese/sdk-shared");
|
|
4
|
+
function useDevtoolsUi(context, { onInit, onDispose }) {
|
|
5
|
+
const wrapperElement = document.createElement("div");
|
|
6
|
+
let unmount;
|
|
7
|
+
async function initDevtools() {
|
|
8
|
+
const main = await Promise.resolve().then(() => require("./main.cjs"));
|
|
9
|
+
if (!unmount) {
|
|
10
|
+
document.body.appendChild(wrapperElement);
|
|
11
|
+
unmount = main.createAdheseDevtools(wrapperElement, context);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
onInit(() => {
|
|
15
|
+
sdkShared.watch(() => [context.debug, context.isDisposed], async ([debug, isDisposed]) => {
|
|
16
|
+
if (debug && !isDisposed) {
|
|
17
|
+
await initDevtools();
|
|
18
|
+
if (context.isDisposed)
|
|
19
|
+
dispose();
|
|
20
|
+
} else {
|
|
21
|
+
dispose();
|
|
22
|
+
}
|
|
23
|
+
}, {
|
|
24
|
+
immediate: true
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
function dispose() {
|
|
28
|
+
unmount == null ? void 0 : unmount();
|
|
29
|
+
unmount = void 0;
|
|
30
|
+
if (wrapperElement.parentElement)
|
|
31
|
+
wrapperElement.outerHTML = "";
|
|
32
|
+
}
|
|
33
|
+
onDispose(dispose);
|
|
34
|
+
}
|
|
35
|
+
function useModifiedSlotsHijack(context, { onSlotCreate }, logger) {
|
|
36
|
+
async function initStore() {
|
|
37
|
+
const { modifiedSlotsStore: store } = await Promise.resolve().then(() => require("./modifiedSlots.store.cjs"));
|
|
38
|
+
return store;
|
|
39
|
+
}
|
|
40
|
+
onSlotCreate(
|
|
41
|
+
(slot) => ({
|
|
42
|
+
...slot,
|
|
43
|
+
setup(slotContext, slotHooks) {
|
|
44
|
+
var _a;
|
|
45
|
+
(_a = slot.setup) == null ? void 0 : _a.call(slot, slotContext, slotHooks);
|
|
46
|
+
let store;
|
|
47
|
+
const state = sdkShared.ref(null);
|
|
48
|
+
const hijackSlot = sdkShared.ref(null);
|
|
49
|
+
const hijackSlotOptions = sdkShared.computed(() => {
|
|
50
|
+
var _a2, _b;
|
|
51
|
+
return (_b = state.value ?? (store == null ? void 0 : store.getState())) == null ? void 0 : _b.slots.get(((_a2 = slotContext.value) == null ? void 0 : _a2.name) ?? "");
|
|
52
|
+
});
|
|
53
|
+
let disposeSub;
|
|
54
|
+
async function createHijack() {
|
|
55
|
+
var _a2, _b, _c, _d, _e;
|
|
56
|
+
if (context.debug && slotContext.value && slotContext.value.element) {
|
|
57
|
+
(_a2 = hijackSlot.value) == null ? void 0 : _a2.dispose();
|
|
58
|
+
if (hijackSlotOptions.value) {
|
|
59
|
+
slotContext.value.renderMode = "none";
|
|
60
|
+
hijackSlot.value = ((_b = context.addSlot) == null ? void 0 : _b.call(context, {
|
|
61
|
+
...sdkShared.omit(slotContext.value.options, ["setup"]),
|
|
62
|
+
...hijackSlotOptions.value,
|
|
63
|
+
containingElement: slotContext.value.element,
|
|
64
|
+
lazyLoading: false,
|
|
65
|
+
lazyLoadingOptions: void 0,
|
|
66
|
+
pluginOptions: {
|
|
67
|
+
devtools: {
|
|
68
|
+
hijackedSlot: slotContext.value.name
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
})) ?? null;
|
|
72
|
+
logger.value.debug(`Hijacking slot ${slotContext.value.name} with new slot ${(_c = hijackSlot.value) == null ? void 0 : _c.name}`);
|
|
73
|
+
await ((_d = hijackSlot.value) == null ? void 0 : _d.render());
|
|
74
|
+
} else {
|
|
75
|
+
slotContext.value.renderMode = slotContext.value.options.renderMode ?? "iframe";
|
|
76
|
+
(_e = hijackSlot.value) == null ? void 0 : _e.dispose();
|
|
77
|
+
hijackSlot.value = null;
|
|
78
|
+
await slotContext.value.render();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
slotHooks.onInit(async () => {
|
|
83
|
+
if (context.debug && slotContext.value) {
|
|
84
|
+
store = await initStore();
|
|
85
|
+
disposeSub = store.subscribe((newState) => {
|
|
86
|
+
state.value = newState;
|
|
87
|
+
});
|
|
88
|
+
state.value = store.getState();
|
|
89
|
+
await createHijack();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
slotHooks.onRender(async () => {
|
|
93
|
+
if (hijackSlot.value) {
|
|
94
|
+
await hijackSlot.value.render();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
sdkShared.watch(state, async () => {
|
|
98
|
+
await createHijack();
|
|
99
|
+
}, { immediate: true });
|
|
100
|
+
sdkShared.watch(() => context.debug, async (debug) => {
|
|
101
|
+
var _a2;
|
|
102
|
+
if (!debug)
|
|
103
|
+
(_a2 = hijackSlot.value) == null ? void 0 : _a2.dispose();
|
|
104
|
+
});
|
|
105
|
+
slotHooks.onDispose(() => {
|
|
106
|
+
var _a2;
|
|
107
|
+
disposeSub == null ? void 0 : disposeSub();
|
|
108
|
+
(_a2 = hijackSlot.value) == null ? void 0 : _a2.dispose();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
exports.useDevtoolsUi = useDevtoolsUi;
|
|
115
|
+
exports.useModifiedSlotsHijack = useModifiedSlotsHijack;
|
|
116
|
+
//# sourceMappingURL=devtools.composables.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools.composables.cjs","sources":["../../src/devtools.composables.ts"],"sourcesContent":["import type { AdheseContext, AdhesePlugin, AdheseSlot } from '@adhese/sdk';\nimport { computed, omit, ref, type useLogger, watch } from '@adhese/sdk-shared';\nimport type { ModifiedSlotsStore, modifiedSlotsStore } from './modifiedSlots.store';\n\nexport type DevtoolsSlotPluginOptions = {\n hijackedSlot?: string;\n};\n\nexport function useDevtoolsUi(context: AdheseContext, { onInit, onDispose }: Parameters<AdhesePlugin>[1]['hooks']): void {\n const wrapperElement = document.createElement('div');\n let unmount: (() => void) | undefined;\n\n async function initDevtools(): Promise<void> {\n const main = await import('./main');\n\n if (!unmount) {\n document.body.appendChild(wrapperElement);\n\n unmount = main.createAdheseDevtools(wrapperElement, context);\n }\n }\n\n onInit(() => {\n watch(() => [context.debug, context.isDisposed], async ([debug, isDisposed]) => {\n if (debug && !isDisposed) {\n await initDevtools();\n\n if (context.isDisposed)\n dispose();\n }\n else {\n dispose();\n }\n }, {\n immediate: true,\n });\n });\n\n function dispose(): void {\n unmount?.();\n unmount = undefined;\n if (wrapperElement.parentElement)\n wrapperElement.outerHTML = '';\n }\n\n onDispose(dispose);\n}\n\nexport function useModifiedSlotsHijack(\n context: AdheseContext,\n { onSlotCreate }: Parameters<AdhesePlugin>[1]['hooks'],\n logger: ReturnType<typeof useLogger>,\n): void {\n async function initStore(): Promise<typeof modifiedSlotsStore> {\n const { modifiedSlotsStore: store } = await import('./modifiedSlots.store');\n\n return store;\n }\n\n onSlotCreate(slot =>\n ({\n ...slot,\n setup(slotContext, slotHooks): void {\n slot.setup?.(slotContext, slotHooks);\n\n let store: typeof modifiedSlotsStore | undefined;\n const state = ref<ModifiedSlotsStore | null>(null);\n const hijackSlot = ref<AdheseSlot | null>(null);\n\n const hijackSlotOptions = computed(() => (state.value ?? store?.getState())?.slots.get(slotContext.value?.name ?? ''));\n\n let disposeSub: (() => void) | undefined;\n\n async function createHijack(): Promise<void> {\n if (context.debug && slotContext.value && slotContext.value.element) {\n hijackSlot.value?.dispose();\n\n if (hijackSlotOptions.value) {\n slotContext.value.renderMode = 'none';\n\n hijackSlot.value = context.addSlot?.({\n ...omit(slotContext.value.options, ['setup']),\n ...hijackSlotOptions.value,\n containingElement: slotContext.value.element,\n lazyLoading: false,\n lazyLoadingOptions: undefined,\n pluginOptions: {\n devtools: {\n hijackedSlot: slotContext.value.name,\n } satisfies DevtoolsSlotPluginOptions,\n },\n }) ?? null;\n\n logger.value.debug(`Hijacking slot ${slotContext.value.name} with new slot ${hijackSlot.value?.name}`);\n\n await hijackSlot.value?.render();\n }\n else {\n slotContext.value.renderMode = slotContext.value.options.renderMode ?? 'iframe';\n\n hijackSlot.value?.dispose();\n hijackSlot.value = null;\n\n await slotContext.value.render();\n }\n }\n }\n\n slotHooks.onInit(async () => {\n if (context.debug && slotContext.value) {\n store = await initStore();\n\n disposeSub = store.subscribe((newState) => {\n state.value = newState;\n });\n\n state.value = store.getState();\n\n await createHijack();\n }\n });\n\n slotHooks.onRender(async () => {\n if (hijackSlot.value) {\n await hijackSlot.value.render();\n }\n });\n\n watch(state, async () => {\n await createHijack();\n }, { immediate: true });\n\n watch(() => context.debug, async (debug) => {\n if (!debug)\n hijackSlot.value?.dispose();\n });\n\n slotHooks.onDispose(() => {\n disposeSub?.();\n hijackSlot.value?.dispose();\n });\n },\n }),\n );\n}\n"],"names":["watch","ref","computed","_a","omit"],"mappings":";;;AAQO,SAAS,cAAc,SAAwB,EAAE,QAAQ,aAAyD;AACjH,QAAA,iBAAiB,SAAS,cAAc,KAAK;AAC/C,MAAA;AAEJ,iBAAe,eAA8B;AACrC,UAAA,OAAO,MAAM,QAAO,QAAA,EAAA,KAAA,MAAA,QAAA,YAAQ;AAElC,QAAI,CAAC,SAAS;AACH,eAAA,KAAK,YAAY,cAAc;AAE9B,gBAAA,KAAK,qBAAqB,gBAAgB,OAAO;AAAA,IAC7D;AAAA,EACF;AAEA,SAAO,MAAM;AACLA,oBAAA,MAAM,CAAC,QAAQ,OAAO,QAAQ,UAAU,GA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
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const client = require("react-dom/client");
|
|
5
|
+
const react = require("react");
|
|
6
|
+
const Devtools = require("./Devtools.cjs");
|
|
7
|
+
const AdheseContext = require("./AdheseContext.cjs");
|
|
8
|
+
function createAdheseDevtools(element, context) {
|
|
9
|
+
const root = client.createRoot(element);
|
|
10
|
+
root.render(/* @__PURE__ */ jsxRuntime.jsx(react.StrictMode, { children: /* @__PURE__ */ jsxRuntime.jsx(AdheseContext.AdheseProvider, { adhese: context, children: /* @__PURE__ */ jsxRuntime.jsx(Devtools.Devtools, {}) }) }));
|
|
11
|
+
return () => {
|
|
12
|
+
root.unmount();
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.createAdheseDevtools = createAdheseDevtools;
|
|
16
|
+
//# sourceMappingURL=main.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.cjs","sources":["../../src/main.tsx"],"sourcesContent":["import { createRoot } from 'react-dom/client';\nimport type { AdheseContext } from '@adhese/sdk';\nimport { StrictMode } from 'react';\nimport { Devtools } from './Devtools';\nimport { AdheseProvider } from './AdheseContext';\n\nexport function createAdheseDevtools(element: HTMLElement, context: AdheseContext): () => void {\n const root = createRoot(element);\n\n root.render((\n <StrictMode>\n <AdheseProvider adhese={context}>\n <Devtools />\n </AdheseProvider>\n </StrictMode>\n ));\n\n return () => {\n root.unmount();\n };\n}\n"],"names":["createRoot","jsx","StrictMode","AdheseProvider","Devtools"],"mappings":";;;;;;;AAMgB,SAAA,qBAAqB,SAAsB,SAAoC;AACvF,QAAA,OAAOA,kBAAW,OAAO;AAE1B,OAAA,OACFC,+BAAAC,MAAAA,YAAA,EACC,UAACD,2BAAA,IAAAE,8BAAA,EAAe,QAAQ,SACtB,UAACF,+BAAAG,SAAAA,UAAA,CAAA,CAAS,EACZ,CAAA,EACF,CAAA,CACD;AAED,SAAO,MAAM;AACX,SAAK,QAAQ;AAAA,EAAA;AAEjB;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const vanilla = require("zustand/vanilla");
|
|
4
|
+
const zustand = require("zustand");
|
|
5
|
+
const middleware = require("zustand/middleware");
|
|
6
|
+
const _package = require("./package.json.cjs");
|
|
7
|
+
const storeName = `${_package.name}/modifiedSlots`;
|
|
8
|
+
const modifiedSlotsStore = vanilla.createStore(middleware.persist(
|
|
9
|
+
(set) => ({
|
|
10
|
+
slots: /* @__PURE__ */ new Map(),
|
|
11
|
+
set(name, slot) {
|
|
12
|
+
set((state) => {
|
|
13
|
+
state.slots.set(name, slot);
|
|
14
|
+
return {
|
|
15
|
+
slots: new Map(state.slots)
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
return name;
|
|
19
|
+
},
|
|
20
|
+
remove(id) {
|
|
21
|
+
set((state) => {
|
|
22
|
+
state.slots.delete(id);
|
|
23
|
+
return {
|
|
24
|
+
slots: new Map(state.slots)
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
{
|
|
30
|
+
name: storeName,
|
|
31
|
+
version: Number(_package.version.split(".")[0]),
|
|
32
|
+
storage: {
|
|
33
|
+
getItem(key) {
|
|
34
|
+
const data = JSON.parse(localStorage.getItem(key) ?? "");
|
|
35
|
+
if (!data) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
state: {
|
|
40
|
+
...data.state,
|
|
41
|
+
slots: new Map(data.state.slots)
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
setItem(key, newValue) {
|
|
46
|
+
const str = JSON.stringify({
|
|
47
|
+
state: {
|
|
48
|
+
...newValue.state,
|
|
49
|
+
slots: Array.from(newValue.state.slots.entries())
|
|
50
|
+
}
|
|
51
|
+
}, null);
|
|
52
|
+
localStorage.setItem(key, str);
|
|
53
|
+
},
|
|
54
|
+
removeItem(key) {
|
|
55
|
+
localStorage.removeItem(key);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
));
|
|
60
|
+
const useModifiedSlots = () => zustand.useStore(modifiedSlotsStore);
|
|
61
|
+
exports.modifiedSlotsStore = modifiedSlotsStore;
|
|
62
|
+
exports.useModifiedSlots = useModifiedSlots;
|
|
63
|
+
//# sourceMappingURL=modifiedSlots.store.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modifiedSlots.store.cjs","sources":["../../src/modifiedSlots.store.ts"],"sourcesContent":["import { createStore } from 'zustand/vanilla';\nimport { useStore } from 'zustand';\nimport { type StorageValue, persist } from 'zustand/middleware';\nimport { name as packageName, version } from '../package.json';\n\ntype SlotOptions = {\n format: string;\n slot?: string;\n};\n\nexport type ModifiedSlotsStore = {\n slots: Map<string, SlotOptions>;\n set(name: string, slot: SlotOptions): string;\n remove(id: string): void;\n};\n\nconst storeName = `${packageName}/modifiedSlots`;\n\nexport const modifiedSlotsStore = createStore(persist<ModifiedSlotsStore>(\n set => ({\n slots: new Map(),\n set(name: string, slot: SlotOptions): string {\n set((state) => {\n state.slots.set(name, slot);\n\n return {\n slots: new Map(state.slots),\n };\n });\n\n return name;\n },\n remove(id: string): void {\n set((state) => {\n state.slots.delete(id);\n\n return {\n slots: new Map(state.slots),\n };\n });\n },\n }),\n {\n name: storeName,\n version: Number(version.split('.')[0]),\n storage: {\n getItem(key) {\n const data = JSON.parse(localStorage.getItem(key) ?? '') as StorageValue<ModifiedSlotsStore> | null;\n\n if (!data) {\n return null;\n }\n\n return {\n state: {\n ...data.state,\n slots: new Map(data.state.slots),\n },\n };\n },\n setItem(key, newValue) {\n const str = JSON.stringify({\n state: {\n ...newValue.state,\n slots: Array.from(newValue.state.slots.entries()),\n },\n }, null);\n localStorage.setItem(key, str);\n },\n removeItem(key) {\n localStorage.removeItem(key);\n },\n },\n },\n));\n\nexport const useModifiedSlots = (): ModifiedSlotsStore => useStore(modifiedSlotsStore);\n"],"names":["packageName","createStore","persist","version","useStore"],"mappings":";;;;;;AAgBA,MAAM,YAAY,GAAGA,aAAW;AAEzB,MAAM,qBAAqBC,QAAY,YAAAC,WAAA;AAAA,EAC5C,CAAQ,SAAA;AAAA,IACN,2BAAW,IAAI;AAAA,IACf,IAAI,MAAc,MAA2B;AAC3C,UAAI,CAAC,UAAU;AACP,cAAA,MAAM,IAAI,MAAM,IAAI;AAEnB,eAAA;AAAA,UACL,OAAO,IAAI,IAAI,MAAM,KAAK;AAAA,QAAA;AAAA,MAC5B,CACD;AAEM,aAAA;AAAA,IACT;AAAA,IACA,OAAO,IAAkB;AACvB,UAAI,CAAC,UAAU;AACP,cAAA,MAAM,OAAO,EAAE;AAEd,eAAA;AAAA,UACL,OAAO,IAAI,IAAI,MAAM,KAAK;AAAA,QAAA;AAAA,MAC5B,CACD;AAAA,IACH;AAAA,EAAA;AAAA,EAEF;AAAA,IACE,MAAM;AAAA,IACN,SAAS,OAAOC,SAAA,QAAQ,MAAM,GAAG,EAAE,CAAC,CAAC;AAAA,IACrC,SAAS;AAAA,MACP,QAAQ,KAAK;AACX,cAAM,OAAO,KAAK,MAAM,aAAa,QAAQ,GAAG,KAAK,EAAE;AAEvD,YAAI,CAAC,MAAM;AACF,iBAAA;AAAA,QACT;AAEO,eAAA;AAAA,UACL,OAAO;AAAA,YACL,GAAG,KAAK;AAAA,YACR,OAAO,IAAI,IAAI,KAAK,MAAM,KAAK;AAAA,UACjC;AAAA,QAAA;AAAA,MAEJ;AAAA,MACA,QAAQ,KAAK,UAAU;AACf,cAAA,MAAM,KAAK,UAAU;AAAA,UACzB,OAAO;AAAA,YACL,GAAG,SAAS;AAAA,YACZ,OAAO,MAAM,KAAK,SAAS,MAAM,MAAM,SAAS;AAAA,UAClD;AAAA,WACC,IAAI;AACM,qBAAA,QAAQ,KAAK,GAAG;AAAA,MAC/B;AAAA,MACA,WAAW,KAAK;AACd,qBAAa,WAAW,GAAG;AAAA,MAC7B;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAEY,MAAA,mBAAmB,MAA0BC,QAAAA,SAAS,kBAAkB;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.json.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const sdkShared = require("@adhese/sdk-shared");
|
|
4
|
+
const _package = require("./package.json.cjs");
|
|
5
|
+
const devtools_composables = require("./devtools.composables.cjs");
|
|
6
|
+
const devtoolsPlugin = (context, plugin) => {
|
|
7
|
+
const logger = sdkShared.useLogger({
|
|
8
|
+
scope: `${_package.name}@${_package.version}`
|
|
9
|
+
}, { context, plugin });
|
|
10
|
+
devtools_composables.useDevtoolsUi(context, plugin.hooks);
|
|
11
|
+
devtools_composables.useModifiedSlotsHijack(context, plugin.hooks, logger);
|
|
12
|
+
return {
|
|
13
|
+
name: "devtools"
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.devtoolsPlugin = devtoolsPlugin;
|
|
17
|
+
//# sourceMappingURL=sdkDevtools.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkDevtools.cjs","sources":["../../src/sdkDevtools.ts"],"sourcesContent":["import type { AdhesePlugin } from '@adhese/sdk';\nimport { useLogger } from '@adhese/sdk-shared';\nimport { name, version } from '../package.json';\nimport { useDevtoolsUi, useModifiedSlotsHijack } from './devtools.composables';\n\nexport type { DevtoolsSlotPluginOptions } from './devtools.composables';\n\nexport const devtoolsPlugin: AdhesePlugin<{\n name: 'devtools';\n}> = (context, plugin) => {\n const logger = useLogger({\n scope: `${name}@${version}`,\n }, { context, plugin });\n\n useDevtoolsUi(context, plugin.hooks);\n\n useModifiedSlotsHijack(context, plugin.hooks, logger);\n\n return {\n name: 'devtools',\n };\n};\n"],"names":["useLogger","name","version","useDevtoolsUi","useModifiedSlotsHijack"],"mappings":";;;;;AAOa,MAAA,iBAER,CAAC,SAAS,WAAW;AACxB,QAAM,SAASA,UAAAA,UAAU;AAAA,IACvB,OAAO,GAAGC,SAAAA,IAAI,IAAIC,SAAO,OAAA;AAAA,EAAA,GACxB,EAAE,SAAS,OAAA,CAAQ;AAERC,uBAAAA,cAAA,SAAS,OAAO,KAAK;AAEZC,uBAAAA,uBAAA,SAAS,OAAO,OAAO,MAAM;AAE7C,SAAA;AAAA,IACL,MAAM;AAAA,EAAA;AAEV;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const clsx = require("clsx");
|
|
4
|
+
const tailwindMerge = require("tailwind-merge");
|
|
5
|
+
function cn(...inputs) {
|
|
6
|
+
return tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
7
|
+
}
|
|
8
|
+
exports.cn = cn;
|
|
9
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: Array<ClassValue>): string {\n return twMerge(clsx(inputs));\n}\n"],"names":["twMerge","clsx"],"mappings":";;;;AAGO,SAAS,MAAM,QAAmC;AAChD,SAAAA,sBAAQC,KAAAA,KAAK,MAAM,CAAC;AAC7B;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cva } from "class-variance-authority";
|
|
3
|
+
import { cn } from "../utils.js";
|
|
4
|
+
const badgeVariants = cva(
|
|
5
|
+
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
6
|
+
{
|
|
7
|
+
variants: {
|
|
8
|
+
variant: {
|
|
9
|
+
default: "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
|
|
10
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
11
|
+
destructive: "border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
|
|
12
|
+
outline: "text-foreground"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
defaultVariants: {
|
|
16
|
+
variant: "default"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
function Badge({ className, variant, ...props }) {
|
|
21
|
+
return /* @__PURE__ */ jsx("div", { className: cn(badgeVariants({ variant }), className), ...props });
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
Badge,
|
|
25
|
+
badgeVariants
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=badge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badge.js","sources":["../../src/components/badge.tsx"],"sourcesContent":["import { type VariantProps, cva } from 'class-variance-authority';\nimport type { HTMLAttributes, ReactElement } from 'react';\nimport { cn } from '../utils';\n\nconst badgeVariants = cva(\n 'inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',\n {\n variants: {\n variant: {\n default:\n 'border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80',\n secondary:\n 'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80',\n destructive:\n 'border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80',\n outline: 'text-foreground',\n },\n },\n defaultVariants: {\n variant: 'default',\n },\n },\n);\n\nexport interface BadgeProps\n extends HTMLAttributes<HTMLDivElement>,\n VariantProps<typeof badgeVariants> {}\n\n// eslint-disable-next-line ts/naming-convention\nfunction Badge({ className, variant, ...props }: BadgeProps): ReactElement {\n return (\n <div className={cn(badgeVariants({ variant }), className)} {...props} />\n );\n}\n\nexport { Badge, badgeVariants };\n"],"names":[],"mappings":";;;AAIA,MAAM,gBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SACE;AAAA,QACF,WACE;AAAA,QACF,aACE;AAAA,QACF,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,SAAS;AAAA,IACX;AAAA,EACF;AACF;AAOA,SAAS,MAAM,EAAE,WAAW,SAAS,GAAG,SAAmC;AACzE,SACG,oBAAA,OAAA,EAAI,WAAW,GAAG,cAAc,EAAE,QAAQ,CAAC,GAAG,SAAS,GAAI,GAAG,MAAO,CAAA;AAE1E;"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
3
|
+
import { cva } from "class-variance-authority";
|
|
4
|
+
import { forwardRef } from "react";
|
|
5
|
+
import { cn } from "../utils.js";
|
|
6
|
+
const buttonVariants = cva(
|
|
7
|
+
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
12
|
+
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
|
13
|
+
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
14
|
+
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
|
15
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
16
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
17
|
+
},
|
|
18
|
+
size: {
|
|
19
|
+
default: "h-9 px-4 py-2",
|
|
20
|
+
sm: "h-6 rounded-md px-3 text-xs",
|
|
21
|
+
lg: "h-10 rounded-md px-8",
|
|
22
|
+
icon: "h-9 w-9"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
defaultVariants: {
|
|
26
|
+
variant: "default",
|
|
27
|
+
size: "default"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
const Button = forwardRef(
|
|
32
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
33
|
+
const Component = asChild ? Slot : "button";
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
Component,
|
|
36
|
+
{
|
|
37
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
38
|
+
ref,
|
|
39
|
+
...props
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
Button.displayName = "Button";
|
|
45
|
+
export {
|
|
46
|
+
Button,
|
|
47
|
+
buttonVariants
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.js","sources":["../../src/components/button.tsx"],"sourcesContent":["import { Slot } from '@radix-ui/react-slot';\nimport { type VariantProps, cva } from 'class-variance-authority';\nimport { type ButtonHTMLAttributes, forwardRef } from 'react';\nimport { cn } from '../utils';\n\nconst buttonVariants = cva(\n 'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50',\n {\n variants: {\n variant: {\n default:\n 'bg-primary text-primary-foreground shadow hover:bg-primary/90',\n destructive:\n 'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90',\n outline:\n 'border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground',\n secondary:\n 'bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80',\n ghost: 'hover:bg-accent hover:text-accent-foreground',\n link: 'text-primary underline-offset-4 hover:underline',\n },\n size: {\n default: 'h-9 px-4 py-2',\n sm: 'h-6 rounded-md px-3 text-xs',\n lg: 'h-10 rounded-md px-8',\n icon: 'h-9 w-9',\n },\n },\n defaultVariants: {\n variant: 'default',\n size: 'default',\n },\n },\n);\n\nexport interface ButtonProps\n extends ButtonHTMLAttributes<HTMLButtonElement>,\n VariantProps<typeof buttonVariants> {\n asChild?: boolean;\n}\n\n// eslint-disable-next-line ts/naming-convention\nconst Button = forwardRef<HTMLButtonElement, ButtonProps>(\n ({ className, variant, size, asChild = false, ...props }, ref) => {\n // eslint-disable-next-line ts/naming-convention\n const Component = asChild ? Slot : 'button';\n return (\n <Component\n className={cn(buttonVariants({ variant, size, className }))}\n ref={ref}\n {...props}\n />\n );\n },\n);\nButton.displayName = 'Button';\n\nexport { Button, buttonVariants };\n"],"names":[],"mappings":";;;;;AAKA,MAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,SAAS;AAAA,QACP,SACE;AAAA,QACF,aACE;AAAA,QACF,SACE;AAAA,QACF,WACE;AAAA,QACF,OAAO;AAAA,QACP,MAAM;AAAA,MACR;AAAA,MACA,MAAM;AAAA,QACJ,SAAS;AAAA,QACT,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AACF;AASA,MAAM,SAAS;AAAA,EACb,CAAC,EAAE,WAAW,SAAS,MAAM,UAAU,OAAO,GAAG,MAAM,GAAG,QAAQ;AAE1D,UAAA,YAAY,UAAU,OAAO;AAEjC,WAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAW,GAAG,eAAe,EAAE,SAAS,MAAM,UAAA,CAAW,CAAC;AAAA,QAC1D;AAAA,QACC,GAAG;AAAA,MAAA;AAAA,IAAA;AAAA,EAGV;AACF;AACA,OAAO,cAAc;"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState, useEffect } from "react";
|
|
3
|
+
import { pick, watch } from "@adhese/sdk-shared";
|
|
4
|
+
import { object, string } from "@adhese/sdk-shared/validators";
|
|
5
|
+
import { useForm } from "react-hook-form";
|
|
6
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
7
|
+
import { Pencil1Icon } from "@radix-ui/react-icons";
|
|
8
|
+
import { useAdheseContext } from "../AdheseContext.js";
|
|
9
|
+
import { useModifiedSlots } from "../modifiedSlots.store.js";
|
|
10
|
+
import { Sheet, SheetTrigger, SheetContent, SheetHeader, SheetTitle, SheetDescription } from "./sheet.js";
|
|
11
|
+
import { Form, FormField, FormItem, FormLabel, FormDescription, FormControl, FormMessage } from "./form.js";
|
|
12
|
+
import { Input } from "./input.js";
|
|
13
|
+
import { buttonVariants, Button } from "./button.js";
|
|
14
|
+
const slotSchema = object({
|
|
15
|
+
format: string().min(1),
|
|
16
|
+
slot: string().optional()
|
|
17
|
+
});
|
|
18
|
+
function EditSlot({
|
|
19
|
+
id
|
|
20
|
+
}) {
|
|
21
|
+
const slot = useSlot(id);
|
|
22
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [
|
|
23
|
+
/* @__PURE__ */ jsx(
|
|
24
|
+
SheetTrigger,
|
|
25
|
+
{
|
|
26
|
+
"aria-label": "Edit slot",
|
|
27
|
+
className: buttonVariants({
|
|
28
|
+
variant: "ghost",
|
|
29
|
+
size: "sm"
|
|
30
|
+
}),
|
|
31
|
+
children: /* @__PURE__ */ jsx(Pencil1Icon, {})
|
|
32
|
+
}
|
|
33
|
+
),
|
|
34
|
+
/* @__PURE__ */ jsx(SheetContent, { children: slot && /* @__PURE__ */ jsx(EditSlotForm, { slot }) })
|
|
35
|
+
] });
|
|
36
|
+
}
|
|
37
|
+
function EditSlotForm({
|
|
38
|
+
slot
|
|
39
|
+
}) {
|
|
40
|
+
const modifiedSlots = useModifiedSlots();
|
|
41
|
+
const modifiedSlot = useMemo(() => modifiedSlots.slots.get((slot == null ? void 0 : slot.name) ?? ""), [modifiedSlots, slot]);
|
|
42
|
+
const defaultValues = useMemo(() => pick(modifiedSlot ?? {
|
|
43
|
+
format: slot.format,
|
|
44
|
+
slot: slot.slot ?? ""
|
|
45
|
+
}, ["format", "slot"]), [slot, modifiedSlot]);
|
|
46
|
+
const form = useForm({
|
|
47
|
+
resolver: zodResolver(slotSchema),
|
|
48
|
+
defaultValues
|
|
49
|
+
});
|
|
50
|
+
const onSubmit = (data) => {
|
|
51
|
+
modifiedSlots.set(slot.name, pick({
|
|
52
|
+
...slot,
|
|
53
|
+
...data
|
|
54
|
+
}, ["format", "slot"]));
|
|
55
|
+
};
|
|
56
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
57
|
+
/* @__PURE__ */ jsxs(SheetHeader, { className: "mb-8", children: [
|
|
58
|
+
/* @__PURE__ */ jsx(SheetTitle, { children: "Edit slot" }),
|
|
59
|
+
/* @__PURE__ */ jsx(SheetDescription, { children: slot.name })
|
|
60
|
+
] }),
|
|
61
|
+
/* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs("form", { onSubmit: form.handleSubmit(onSubmit), children: [
|
|
62
|
+
/* @__PURE__ */ jsx(
|
|
63
|
+
FormField,
|
|
64
|
+
{
|
|
65
|
+
control: form.control,
|
|
66
|
+
name: "format",
|
|
67
|
+
render: ({ field }) => /* @__PURE__ */ jsx(SlotFormItem, { label: "Format", children: /* @__PURE__ */ jsx(Input, { ...field }) })
|
|
68
|
+
}
|
|
69
|
+
),
|
|
70
|
+
/* @__PURE__ */ jsx(
|
|
71
|
+
FormField,
|
|
72
|
+
{
|
|
73
|
+
control: form.control,
|
|
74
|
+
name: "slot",
|
|
75
|
+
render: ({ field }) => /* @__PURE__ */ jsx(SlotFormItem, { label: "Slot", children: /* @__PURE__ */ jsx(Input, { ...field }) })
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
/* @__PURE__ */ jsx(Button, { className: "w-full mt-10", children: "Edit" })
|
|
79
|
+
] }) })
|
|
80
|
+
] });
|
|
81
|
+
}
|
|
82
|
+
function SlotFormItem({
|
|
83
|
+
label,
|
|
84
|
+
description,
|
|
85
|
+
children
|
|
86
|
+
}) {
|
|
87
|
+
return /* @__PURE__ */ jsxs(FormItem, { className: "mb-3", children: [
|
|
88
|
+
/* @__PURE__ */ jsx(FormLabel, { children: label }),
|
|
89
|
+
description && /* @__PURE__ */ jsx(FormDescription, { children: description }),
|
|
90
|
+
/* @__PURE__ */ jsx(FormControl, { children }),
|
|
91
|
+
/* @__PURE__ */ jsx(FormMessage, {})
|
|
92
|
+
] });
|
|
93
|
+
}
|
|
94
|
+
function useSlot(id) {
|
|
95
|
+
const adheseContext = useAdheseContext();
|
|
96
|
+
const [slot, setSlot] = useState(adheseContext == null ? void 0 : adheseContext.slots.get(id));
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (!adheseContext) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
return watch(() => adheseContext.slots, (slots) => {
|
|
102
|
+
setSlot(slots.get(id));
|
|
103
|
+
}, { immediate: true, deep: true });
|
|
104
|
+
}, [adheseContext, id]);
|
|
105
|
+
return slot;
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
EditSlot
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=editSlot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editSlot.js","sources":["../../src/components/editSlot.tsx"],"sourcesContent":["import { type PropsWithChildren, type ReactElement, useEffect, useMemo, useState } from 'react';\nimport { pick, watch } from '@adhese/sdk-shared';\nimport type { AdheseSlot } from '@adhese/sdk';\nimport { type TypeOf, object, string } from '@adhese/sdk-shared/validators';\nimport { type SubmitHandler, useForm } from 'react-hook-form';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { Pencil1Icon } from '@radix-ui/react-icons';\nimport { useAdheseContext } from '../AdheseContext';\nimport { useModifiedSlots } from '../modifiedSlots.store';\nimport { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger } from './sheet';\nimport { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from './form';\nimport { Input } from './input';\nimport { Button, buttonVariants } from './button';\n\nconst slotSchema = object({\n format: string().min(1),\n slot: string().optional(),\n});\n\ntype SlotSchema = TypeOf<typeof slotSchema>;\n\n// eslint-disable-next-line ts/naming-convention\nexport function EditSlot({\n id,\n}: {\n id: string;\n}): ReactElement {\n const slot = useSlot(id);\n\n return (\n <Sheet>\n <SheetTrigger\n aria-label=\"Edit slot\"\n className={buttonVariants({\n variant: 'ghost',\n size: 'sm',\n })}\n >\n <Pencil1Icon />\n </SheetTrigger>\n <SheetContent>\n {slot && <EditSlotForm slot={slot} />}\n </SheetContent>\n </Sheet>\n );\n}\n\n// eslint-disable-next-line ts/naming-convention\nfunction EditSlotForm({\n slot,\n}: {\n slot: AdheseSlot;\n}): ReactElement {\n const modifiedSlots = useModifiedSlots();\n const modifiedSlot = useMemo(() => modifiedSlots.slots.get(slot?.name ?? ''), [modifiedSlots, slot]);\n\n const defaultValues = useMemo(() => pick(modifiedSlot ?? {\n format: slot.format,\n slot: slot.slot ?? '',\n }, ['format', 'slot']), [slot, modifiedSlot]);\n\n const form = useForm<SlotSchema>({\n resolver: zodResolver(slotSchema),\n defaultValues,\n });\n\n const onSubmit: SubmitHandler<SlotSchema> = (data) => {\n modifiedSlots.set(slot.name, pick({\n ...slot,\n ...data,\n }, ['format', 'slot']));\n };\n\n return (\n <>\n <SheetHeader className=\"mb-8\">\n <SheetTitle>\n Edit slot\n </SheetTitle>\n <SheetDescription>\n {slot.name}\n </SheetDescription>\n </SheetHeader>\n\n <Form {...form}>\n {/* eslint-disable-next-line ts/no-misused-promises */}\n <form onSubmit={form.handleSubmit(onSubmit)}>\n <FormField\n control={form.control}\n name=\"format\"\n render={({ field }) => (\n <SlotFormItem label=\"Format\">\n <Input {...field} />\n </SlotFormItem>\n )}\n />\n <FormField\n control={form.control}\n name=\"slot\"\n render={({ field }) => (\n <SlotFormItem label=\"Slot\">\n <Input {...field} />\n </SlotFormItem>\n )}\n />\n\n <Button className=\"w-full mt-10\">\n Edit\n </Button>\n </form>\n </Form>\n </>\n );\n}\n\n// eslint-disable-next-line ts/naming-convention\nfunction SlotFormItem({\n label,\n description,\n children,\n}: PropsWithChildren<{\n label: string;\n description?: string;\n}>): ReactElement {\n return (\n <FormItem className=\"mb-3\">\n <FormLabel>{label}</FormLabel>\n {description && <FormDescription>{description}</FormDescription>}\n <FormControl>\n {children}\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n}\n\nfunction useSlot(id: string): AdheseSlot | undefined {\n const adheseContext = useAdheseContext();\n const [slot, setSlot] = useState(adheseContext?.slots.get(id));\n\n useEffect(() => {\n if (!adheseContext) {\n return;\n }\n\n return watch(() => adheseContext.slots, (slots) => {\n setSlot(slots.get(id));\n }, { immediate: true, deep: true });\n }, [adheseContext, id]);\n return slot;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAcA,MAAM,aAAa,OAAO;AAAA,EACxB,QAAQ,OAAA,EAAS,IAAI,CAAC;AAAA,EACtB,MAAM,OAAO,EAAE,SAAS;AAC1B,CAAC;AAKM,SAAS,SAAS;AAAA,EACvB;AACF,GAEiB;AACT,QAAA,OAAO,QAAQ,EAAE;AAEvB,8BACG,OACC,EAAA,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,cAAW;AAAA,QACX,WAAW,eAAe;AAAA,UACxB,SAAS;AAAA,UACT,MAAM;AAAA,QAAA,CACP;AAAA,QAED,8BAAC,aAAY,EAAA;AAAA,MAAA;AAAA,IACf;AAAA,wBACC,cACE,EAAA,UAAA,QAAS,oBAAA,cAAA,EAAa,KAAY,CAAA,GACrC;AAAA,EACF,EAA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AAA,MACT,oBAAC,cAAa,EAAA,OAAM,QAClB,UAAA,oBAAC,OAAO,EAAA,GAAG,OAAO,EACpB,CAAA;AAAA,QAAA;AAAA,MAEJ;AAAA,MAEC,oBAAA,QAAA,EAAO,WAAU,gBAAe,UAEjC,QAAA;AAAA,IAAA,EAAA,CACF,EACF,CAAA;AAAA,EACF,EAAA,CAAA;AAEJ;AAGA,SAAS,aAAa;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACF,GAGkB;AAEd,SAAA,qBAAC,UAAS,EAAA,WAAU,QAClB,UAAA;AAAA,IAAA,oBAAC,aAAW,UAAM,MAAA,CAAA;AAAA,IACjB,eAAgB,oBAAA,iBAAA,EAAiB,UAAY,YAAA,CAAA;AAAA,IAC9C,oBAAC,eACE,UACH;AAAA,wBACC,aAAY,EAAA;AAAA,EACf,EAAA,CAAA;AAEJ;AAEA,SAAS,QAAQ,IAAoC;AACnD,QAAM,gBAAgB;AAChB,QAAA,CAAC,MAAM,OAAO,IAAI,SAAS,+CAAe,MAAM,IAAI,GAAG;AAE7D,YAAU,MAAM;AACd,QAAI,CAAC,eAAe;AAClB;AAAA,IACF;AAEA,WAAO,MAAM,MAAM,cAAc,OAAO,CAAC,UAAU;AACzC,cAAA,MAAM,IAAI,EAAE,CAAC;AAAA,OACpB,EAAE,WAAW,MAAM,MAAM,KAAM,CAAA;AAAA,EAAA,GACjC,CAAC,eAAe,EAAE,CAAC;AACf,SAAA;AACT;"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
3
|
+
import { useFormContext, FormProvider, Controller } from "react-hook-form";
|
|
4
|
+
import { createContext, forwardRef, useId, useContext } from "react";
|
|
5
|
+
import { cn } from "../utils.js";
|
|
6
|
+
import { Label } from "./label.js";
|
|
7
|
+
const Form = FormProvider;
|
|
8
|
+
const FormFieldContext = createContext(
|
|
9
|
+
{}
|
|
10
|
+
);
|
|
11
|
+
function FormField({
|
|
12
|
+
...props
|
|
13
|
+
}) {
|
|
14
|
+
return /* @__PURE__ */ jsx(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ jsx(Controller, { ...props }) });
|
|
15
|
+
}
|
|
16
|
+
const FormItemContext = createContext(
|
|
17
|
+
{}
|
|
18
|
+
);
|
|
19
|
+
function useFormField() {
|
|
20
|
+
const fieldContext = useContext(FormFieldContext);
|
|
21
|
+
const itemContext = useContext(FormItemContext);
|
|
22
|
+
const { getFieldState, formState } = useFormContext();
|
|
23
|
+
const fieldState = getFieldState(fieldContext.name, formState);
|
|
24
|
+
if (!fieldContext) {
|
|
25
|
+
throw new Error("useFormField should be used within <FormField>");
|
|
26
|
+
}
|
|
27
|
+
const { id } = itemContext;
|
|
28
|
+
return {
|
|
29
|
+
id,
|
|
30
|
+
name: fieldContext.name,
|
|
31
|
+
formItemId: `${id}-form-item`,
|
|
32
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
33
|
+
formMessageId: `${id}-form-item-message`,
|
|
34
|
+
...fieldState
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const FormItem = forwardRef(({ className, ...props }, ref) => {
|
|
38
|
+
const id = useId();
|
|
39
|
+
return /* @__PURE__ */ jsx(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsx("div", { ref, className: cn("space-y-2", className), ...props }) });
|
|
40
|
+
});
|
|
41
|
+
FormItem.displayName = "FormItem";
|
|
42
|
+
const FormLabel = forwardRef(({ className, ...props }, ref) => {
|
|
43
|
+
const { error, formItemId } = useFormField();
|
|
44
|
+
return /* @__PURE__ */ jsx(
|
|
45
|
+
Label,
|
|
46
|
+
{
|
|
47
|
+
ref,
|
|
48
|
+
className: cn(error && "text-destructive", className),
|
|
49
|
+
htmlFor: formItemId,
|
|
50
|
+
...props
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
FormLabel.displayName = "FormLabel";
|
|
55
|
+
const FormControl = forwardRef(({ ...props }, ref) => {
|
|
56
|
+
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
|
57
|
+
return /* @__PURE__ */ jsx(
|
|
58
|
+
Slot,
|
|
59
|
+
{
|
|
60
|
+
ref,
|
|
61
|
+
id: formItemId,
|
|
62
|
+
"aria-describedby": error ? `${formDescriptionId} ${formMessageId}` : `${formDescriptionId}`,
|
|
63
|
+
"aria-invalid": !!error,
|
|
64
|
+
...props
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
FormControl.displayName = "FormControl";
|
|
69
|
+
const FormDescription = forwardRef(({ className, ...props }, ref) => {
|
|
70
|
+
const { formDescriptionId } = useFormField();
|
|
71
|
+
return /* @__PURE__ */ jsx(
|
|
72
|
+
"p",
|
|
73
|
+
{
|
|
74
|
+
ref,
|
|
75
|
+
id: formDescriptionId,
|
|
76
|
+
className: cn("text-[0.8rem] text-muted-foreground", className),
|
|
77
|
+
...props
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
FormDescription.displayName = "FormDescription";
|
|
82
|
+
const FormMessage = forwardRef(({ className, children, ...props }, ref) => {
|
|
83
|
+
const { error, formMessageId } = useFormField();
|
|
84
|
+
const body = error ? String(error == null ? void 0 : error.message) : children;
|
|
85
|
+
if (!body) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return /* @__PURE__ */ jsx(
|
|
89
|
+
"p",
|
|
90
|
+
{
|
|
91
|
+
ref,
|
|
92
|
+
id: formMessageId,
|
|
93
|
+
className: cn("text-[0.8rem] font-medium text-destructive", className),
|
|
94
|
+
...props,
|
|
95
|
+
children: body
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
FormMessage.displayName = "FormMessage";
|
|
100
|
+
export {
|
|
101
|
+
Form,
|
|
102
|
+
FormControl,
|
|
103
|
+
FormDescription,
|
|
104
|
+
FormField,
|
|
105
|
+
FormItem,
|
|
106
|
+
FormLabel,
|
|
107
|
+
FormMessage,
|
|
108
|
+
useFormField
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=form.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.js","sources":["../../src/components/form.tsx"],"sourcesContent":["// eslint-disable-next-line ts/naming-convention\nimport type * as LabelPrimitive from '@radix-ui/react-label';\nimport { Slot } from '@radix-ui/react-slot';\nimport {\n Controller,\n type ControllerProps,\n type FieldPath,\n type FieldValues,\n FormProvider,\n useFormContext,\n} from 'react-hook-form';\n\nimport {\n type ComponentPropsWithoutRef,\n type ElementRef,\n type HTMLAttributes,\n createContext,\n forwardRef,\n useContext,\n useId,\n} from 'react';\nimport { cn } from '../utils';\nimport { Label } from './label';\n\n// eslint-disable-next-line ts/naming-convention\nconst Form = FormProvider;\n\ntype FormFieldContextValue<\n T extends FieldValues = FieldValues,\n U extends FieldPath<T> = FieldPath<T>,\n> = {\n name: U;\n};\n\n// eslint-disable-next-line ts/naming-convention\nconst FormFieldContext = createContext<FormFieldContextValue>(\n {} as FormFieldContextValue,\n);\n\n// eslint-disable-next-line ts/naming-convention,ts/explicit-function-return-type,ts/explicit-module-boundary-types\nfunction FormField<\n T extends FieldValues = FieldValues,\n U extends FieldPath<T> = FieldPath<T>,\n>({\n ...props\n}: ControllerProps<T, U>) {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n );\n}\n\ntype FormItemContextValue = {\n id: string;\n};\n\n// eslint-disable-next-line ts/naming-convention\nconst FormItemContext = createContext<FormItemContextValue>(\n {} as FormItemContextValue,\n);\n\n// eslint-disable-next-line ts/explicit-function-return-type,ts/explicit-module-boundary-types\nfunction useFormField() {\n const fieldContext = useContext(FormFieldContext);\n const itemContext = useContext(FormItemContext);\n const { getFieldState, formState } = useFormContext();\n\n const fieldState = getFieldState(fieldContext.name, formState);\n\n if (!fieldContext) {\n throw new Error('useFormField should be used within <FormField>');\n }\n\n const { id } = itemContext;\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-form-item`,\n formDescriptionId: `${id}-form-item-description`,\n formMessageId: `${id}-form-item-message`,\n ...fieldState,\n };\n}\n\n// eslint-disable-next-line ts/naming-convention\nconst FormItem = forwardRef<\n HTMLDivElement,\n HTMLAttributes<HTMLDivElement>\n>(({ className, ...props }, ref) => {\n const id = useId();\n\n return (\n <FormItemContext.Provider value={{ id }}>\n <div ref={ref} className={cn('space-y-2', className)} {...props} />\n </FormItemContext.Provider>\n );\n});\nFormItem.displayName = 'FormItem';\n\n// eslint-disable-next-line ts/naming-convention\nconst FormLabel = forwardRef<\n ElementRef<typeof LabelPrimitive.Root>,\n ComponentPropsWithoutRef<typeof LabelPrimitive.Root>\n>(({ className, ...props }, ref) => {\n const { error, formItemId } = useFormField();\n\n return (\n <Label\n ref={ref}\n className={cn(error && 'text-destructive', className)}\n htmlFor={formItemId}\n {...props}\n />\n );\n});\nFormLabel.displayName = 'FormLabel';\n\n// eslint-disable-next-line ts/naming-convention\nconst FormControl = forwardRef<\n ElementRef<typeof Slot>,\n ComponentPropsWithoutRef<typeof Slot>\n>(({ ...props }, ref) => {\n const { error, formItemId, formDescriptionId, formMessageId } = useFormField();\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={\n error ? `${formDescriptionId} ${formMessageId}` : `${formDescriptionId}`\n }\n aria-invalid={!!error}\n {...props}\n />\n );\n});\nFormControl.displayName = 'FormControl';\n\n// eslint-disable-next-line ts/naming-convention\nconst FormDescription = forwardRef<\n HTMLParagraphElement,\n HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\n const { formDescriptionId } = useFormField();\n\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn('text-[0.8rem] text-muted-foreground', className)}\n {...props}\n />\n );\n});\nFormDescription.displayName = 'FormDescription';\n\n// eslint-disable-next-line ts/naming-convention\nconst FormMessage = forwardRef<\n HTMLParagraphElement,\n HTMLAttributes<HTMLParagraphElement>\n>(({ className, children, ...props }, ref) => {\n const { error, formMessageId } = useFormField();\n const body = error ? String(error?.message) : children;\n\n if (!body) {\n return null;\n }\n\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn('text-[0.8rem] font-medium text-destructive', className)}\n {...props}\n >\n {body}\n </p>\n );\n});\nFormMessage.displayName = 'FormMessage';\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,\n FormDescription,\n FormMessage,\n FormField,\n};\n"],"names":[],"mappings":";;;;;;AAyBA,MAAM,OAAO;AAUb,MAAM,mBAAmB;AAAA,EACvB,CAAC;AACH;AAGA,SAAS,UAGP;AAAA,EACA,GAAG;AACL,GAA0B;AACxB,SACG,oBAAA,iBAAiB,UAAjB,EAA0B,OAAO,EAAE,MAAM,MAAM,KAAA,GAC9C,UAAA,oBAAC,YAAY,EAAA,GAAG,OAAO,EACzB,CAAA;AAEJ;AAOA,MAAM,kBAAkB;AAAA,EACtB,CAAC;AACH;AAGA,SAAS,eAAe;AAChB,QAAA,eAAe,WAAW,gBAAgB;AAC1C,QAAA,cAAc,WAAW,eAAe;AAC9C,QAAM,EAAE,eAAe,UAAU,IAAI,eAAe;AAEpD,QAAM,aAAa,cAAc,aAAa,MAAM,SAAS;AAE7D,MAAI,CAAC,cAAc;AACX,UAAA,IAAI,MAAM,gDAAgD;AAAA,EAClE;AAEM,QAAA,EAAE,GAAO,IAAA;AAER,SAAA;AAAA,IACL;AAAA,IACA,MAAM,aAAa;AAAA,IACnB,YAAY,GAAG,EAAE;AAAA,IACjB,mBAAmB,GAAG,EAAE;AAAA,IACxB,eAAe,GAAG,EAAE;AAAA,IACpB,GAAG;AAAA,EAAA;AAEP;AAGM,MAAA,WAAW,WAGf,CAAC,EAAE,WAAW,GAAG,SAAS,QAAQ;AAClC,QAAM,KAAK;AAEX,6BACG,gBAAgB,UAAhB,EAAyB,OAAO,EAAE,MACjC,UAAA,oBAAC,OAAI,EAAA,KAAU,WAAW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