@chaibuilder/sdk 4.0.0-beta.49 → 4.0.0-beta.51
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/README.md +35 -52
- package/dist/{2SSKDMRQ-CjvuNdPo.cjs → 2SSKDMRQ-BSYe_xPq.cjs} +1 -1
- package/dist/{2SSKDMRQ-Dvf9zadl.js → 2SSKDMRQ-Dv-C_YAA.js} +3 -3
- package/dist/{AP7HFJJL-DYFttFoI.cjs → AP7HFJJL-BJolKJBt.cjs} +1 -1
- package/dist/{AP7HFJJL-q4dJdyFs.js → AP7HFJJL-DhdVstVC.js} +1 -1
- package/dist/{IconPicker-Bf163F7t.js → IconPicker-BBkl0T8b.js} +13 -13
- package/dist/{IconPicker-JWhYq2Gp.cjs → IconPicker-C0WWlb8t.cjs} +1 -1
- package/dist/{WDYDFRGG-O9GIrtX0.js → WDYDFRGG-CJs2MxSq.js} +4 -4
- package/dist/{WDYDFRGG-BEksfGMC.cjs → WDYDFRGG-DRt6Zg7Q.cjs} +1 -1
- package/dist/{actions-registery-BHbZHkE3.cjs → actions-registery-CLL3KrNv.cjs} +2 -2
- package/dist/{actions-registery-gJb_wq2F.js → actions-registery-CrGIlqUX.js} +88 -88
- package/dist/actions.cjs +1 -1
- package/dist/actions.js +2 -2
- package/dist/{add-new-language-page-BfUp5Ua2.cjs → add-new-language-page-ByMSfRcN.cjs} +1 -1
- package/dist/{add-new-language-page-CRR93tLq.js → add-new-language-page-DtVoDNfI.js} +35 -35
- package/dist/{add-new-page-B8NGK6WS.cjs → add-new-page-CnuChfJz.cjs} +1 -1
- package/dist/add-new-page-DanzzvYo.js +31 -0
- package/dist/{ai-panel-default-lang-BXYQye3N.js → ai-panel-default-lang-BaPz2d_6.js} +35 -35
- package/dist/{ai-panel-default-lang-VhgmHFoQ.cjs → ai-panel-default-lang-CoIQSz_Y.cjs} +2 -2
- package/dist/{ai-panel-other-lang-DaCf-cq4.js → ai-panel-other-lang--i-5z4e2.js} +22 -22
- package/dist/{ai-panel-other-lang-Ds0EXeUC.cjs → ai-panel-other-lang-ChlMVodg.cjs} +1 -1
- package/dist/{ai-prompt-input-7iWk72w5.js → ai-prompt-input-BQi0VDJC.js} +77 -77
- package/dist/{ai-prompt-input-nZ5_Dm7X.cjs → ai-prompt-input-BT5426AB.cjs} +1 -1
- package/dist/{ai-translation-prompt-1OUs1P7n.js → ai-translation-prompt-BN78s33t.js} +8 -8
- package/dist/{ai-translation-prompt-B16cK-1Q.cjs → ai-translation-prompt-BQPaekp3.cjs} +1 -1
- package/dist/{apply-binding-CBSjMYSk.cjs → apply-binding-Cjh1kqMO.cjs} +1 -1
- package/dist/{apply-binding-vAuN-TGV.js → apply-binding-v_W4uR3U.js} +28 -28
- package/dist/{plugin-BSjgGgwo.js → chai-theme-helpers-BEf2rwE4.js} +83 -83
- package/dist/chai-theme-helpers-q3nwoNht.cjs +22 -0
- package/dist/{change-password-modal-D5eXjiYq.cjs → change-password-modal-DHUrrKw7.cjs} +1 -1
- package/dist/{change-password-modal-CdvJR1Ln.js → change-password-modal-pEp-nMNb.js} +30 -30
- package/dist/{code-display-DdWcOQ_i.js → code-display-BaLKScgW.js} +5 -5
- package/dist/{code-display-BR-gij5j.cjs → code-display-i7jb2kmw.cjs} +1 -1
- package/dist/{code-editor-CyLjDiEp.js → code-editor-CRoniyP0.js} +12 -12
- package/dist/{code-editor-SWbfFj1E.cjs → code-editor-gwFRjQ2_.cjs} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +0 -5
- package/dist/core.js +49 -49
- package/dist/{css-import-modal-Be47CBJn.js → css-import-modal-B3qxX9Iv.js} +14 -14
- package/dist/{css-import-modal-Bdwgd05S.cjs → css-import-modal-nAB5FSwn.cjs} +2 -2
- package/dist/{delete-page-C99K2qzS.js → delete-page-DbawNFf7.js} +13 -13
- package/dist/{delete-page-DLohaU-U.cjs → delete-page-YP1HEAoD.cjs} +1 -1
- package/dist/{digital-asset-manager-BZMb6sC7.js → digital-asset-manager-DTD5mf24.js} +388 -357
- package/dist/digital-asset-manager-kJnuMqpw.cjs +1 -0
- package/dist/{duplicate-page-D5Gtvqdv.cjs → duplicate-page-CxqW_EO7.cjs} +1 -1
- package/dist/{duplicate-page-CDc2X0eW.js → duplicate-page-DnRb1y6K.js} +19 -19
- package/dist/{dynamic-page-selector-DZHhX008.cjs → dynamic-page-selector-2EqJhUrB.cjs} +1 -1
- package/dist/{dynamic-page-selector-DvNBXo6o.js → dynamic-page-selector-D6VLDIN9.js} +17 -17
- package/dist/{get-chai-builder-tailwind-config-7CxFxEYL.cjs → get-chai-builder-tailwind-config-DNp8Vhme.cjs} +1 -1
- package/dist/{get-chai-builder-tailwind-config-DC4sDOYK.js → get-chai-builder-tailwind-config-k8l5sdcw.js} +3 -3
- package/dist/{get-chai-builder-theme-BpuwSLeS.js → get-chai-builder-theme-DLpviqPJ.js} +1 -1
- package/dist/get-chai-builder-theme-Du4ARJlw.cjs +1 -0
- package/dist/{image-editor-DwhTYkVR.cjs → image-editor-BQcOGsli.cjs} +1 -1
- package/dist/{image-editor-BBvvi9Vm.js → image-editor-CMf731xL.js} +15 -15
- package/dist/index-BYrRPW_c.cjs +5 -0
- package/dist/index-D-r_K4yA.cjs +160 -0
- package/dist/{index-OuHV9Ann.js → index-DPV6NiJ-.js} +5894 -6049
- package/dist/index-DqzFD1CG.js +4861 -0
- package/dist/{mark-as-template-CP_F9ZQ4.js → mark-as-template-D7jqSCXw.js} +28 -28
- package/dist/{mark-as-template-B9yLcasI.cjs → mark-as-template-DyB56HzI.cjs} +1 -1
- package/dist/{nested-path-selector-content-DmtCI3q9.js → nested-path-selector-content-dwSikrsV.js} +2 -2
- package/dist/{nested-path-selector-content-aTdu-o0e.cjs → nested-path-selector-content-g9_Tq_sR.cjs} +1 -1
- package/dist/no-language-page-content-BRITuyfN.js +43 -0
- package/dist/{no-language-page-content-C-MCdPXt.cjs → no-language-page-content-ZvMNVY-Y.cjs} +1 -1
- package/dist/{no-language-page-dialog-D4QIAHnE.cjs → no-language-page-dialog-Cndq8xRP.cjs} +1 -1
- package/dist/no-language-page-dialog-D7L9nVb9.js +10 -0
- package/dist/page-creator-BAIbU14q.js +652 -0
- package/dist/page-creator-qL3-M8g3.cjs +1 -0
- package/dist/{page-manager-new-ah6QYar2.cjs → page-manager-new-By3eGO3i.cjs} +1 -1
- package/dist/{page-manager-new-ttsrxdW9.js → page-manager-new-YRG89y4f.js} +63 -63
- package/dist/page-manager-search-and-filter-BbdgOU9V.cjs +1 -0
- package/dist/page-manager-search-and-filter-Cllju4CV.js +184 -0
- package/dist/pages.cjs +1 -1
- package/dist/pages.d.ts +0 -15
- package/dist/pages.js +20 -21
- package/dist/{publish-pages-content-KZVMHT6V.js → publish-pages-content-CG5LBUnY.js} +48 -48
- package/dist/{publish-pages-content-BrajJUcP.cjs → publish-pages-content-DxMiBxNU.cjs} +1 -1
- package/dist/{register-chai-top-bar-DyW9GPzV.cjs → register-chai-top-bar-CCssW5dL.cjs} +1 -1
- package/dist/{register-chai-top-bar-D6GjnauV.js → register-chai-top-bar-DWmJ2efT.js} +11 -11
- package/dist/render.cjs +1 -1
- package/dist/render.js +54 -54
- package/dist/{rte-widget-modal-CiTwsXTr.cjs → rte-widget-modal-CsTqFJc_.cjs} +1 -1
- package/dist/{rte-widget-modal-IU8JzPuZ.js → rte-widget-modal-DoeTMRtX.js} +2 -2
- package/dist/runtime-client.cjs +1 -1
- package/dist/runtime-client.js +1 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +1 -1
- package/dist/sdk.css +1 -1
- package/dist/{selected-block-display-CidmQ-wz.js → selected-block-display-Ck1kkNEi.js} +17 -28
- package/dist/{selected-block-display-CAFEOrLV.cjs → selected-block-display-DSow6N4b.cjs} +1 -1
- package/dist/seo-panel---mYZmLD.js +559 -0
- package/dist/seo-panel-mfX63fua.cjs +1 -0
- package/dist/{shared-json-ld-uvMmwCYp.js → shared-json-ld-B3I_RLE2.js} +46 -46
- package/dist/{shared-json-ld-CMH-eRUq.cjs → shared-json-ld-CGgwUOlW.cjs} +1 -1
- package/dist/{slug-input-DLWTMTsO.js → slug-input-DQ4t3-Tt.js} +5 -5
- package/dist/{slug-input-CiHC5l3r.cjs → slug-input-DaNbl597.cjs} +1 -1
- package/dist/supabase-actions.cjs +1 -1
- package/dist/supabase-actions.js +2 -2
- package/dist/types.d.ts +0 -96
- package/dist/{unmark-as-template-F7TdgWjI.cjs → unmark-as-template-CZ65AE4v.cjs} +1 -1
- package/dist/{unmark-as-template-C5ovsEBP.js → unmark-as-template-DvmoTbVu.js} +11 -11
- package/dist/unpublish-page-3--vO5b0.js +28 -0
- package/dist/{unpublish-page-CUr8Xub6.cjs → unpublish-page-B46TiWlU.cjs} +1 -1
- package/dist/{unpublished-partials-modal-BhNAub_z.js → unpublished-partials-modal-DVMz3q83.js} +18 -15
- package/dist/{unpublished-partials-modal-Cv5R9-hi.cjs → unpublished-partials-modal-U5lKBOSR.cjs} +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +2 -2
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.js +2 -2
- package/dist/{web-preview-D9pXonAv.js → web-preview-D5o5XQo0.js} +2 -2
- package/dist/{web-preview-CuMYekVJ.cjs → web-preview-Da3RhcjQ.cjs} +1 -1
- package/package.json +1 -1
- package/dist/active-in-another-tab-B4Ur0JP7.js +0 -35
- package/dist/active-in-another-tab-BPdx4lWh.cjs +0 -1
- package/dist/add-new-page-Ppy5-y5j.js +0 -31
- package/dist/continue-editing-in-this-client-BrSvK-Ay.js +0 -25
- package/dist/continue-editing-in-this-client-Cmi-GkYZ.cjs +0 -1
- package/dist/design-token-usage-D1lWCJ3L.js +0 -114
- package/dist/design-token-usage-eY2wQ0l3.cjs +0 -1
- package/dist/digital-asset-manager-Z5aJxkq0.cjs +0 -1
- package/dist/get-chai-builder-theme-B5RkBTsB.cjs +0 -1
- package/dist/image-compression-DPFITwOL.js +0 -37
- package/dist/image-compression-UaU7Bwqe.cjs +0 -1
- package/dist/index-BVwFJWDq.cjs +0 -5
- package/dist/index-DCJDQs1a.cjs +0 -160
- package/dist/index-LBTm1Jmk.js +0 -5199
- package/dist/json-diff-viewer-Cb1CmRqP.cjs +0 -8
- package/dist/json-diff-viewer-DG6qMOBS.js +0 -261
- package/dist/lang-panel-B3USOxGq.js +0 -216
- package/dist/lang-panel-DxoJ0v4y.cjs +0 -1
- package/dist/manage-design-tokens-6YGIctip.js +0 -446
- package/dist/manage-design-tokens-modal-BSSCXH8Y.cjs +0 -1
- package/dist/manage-design-tokens-modal-CzsnN49F.js +0 -161
- package/dist/manage-design-tokens-udLBvkHA.cjs +0 -1
- package/dist/no-language-page-content-D8t5dfgh.js +0 -43
- package/dist/no-language-page-dialog-C_fHI2zI.js +0 -10
- package/dist/page-creator-Cz_ah-qE.cjs +0 -1
- package/dist/page-creator-DKEkuGCO.js +0 -796
- package/dist/page-lock-CwZKJ4IE.js +0 -30
- package/dist/page-lock-DdCvtA-I.cjs +0 -1
- package/dist/page-locked-dialog-CrTDBoC4.cjs +0 -1
- package/dist/page-locked-dialog-DqLlooUz.js +0 -136
- package/dist/page-manager-search-and-filter-D7AupT6_.cjs +0 -1
- package/dist/page-manager-search-and-filter-bsqZ6wnI.js +0 -210
- package/dist/page-revisions-content-B6hsIla7.cjs +0 -1
- package/dist/page-revisions-content-C5O8_Fms.js +0 -459
- package/dist/plugin-DHpuZZXz.cjs +0 -22
- package/dist/save-to-lib-DMnv7ENo.js +0 -429
- package/dist/save-to-lib-Dc700Aop.cjs +0 -1
- package/dist/seo-panel-Br8gxDxu.js +0 -789
- package/dist/seo-panel-CMY-adM-.cjs +0 -2
- package/dist/take-over-request-IRLgF1dG.cjs +0 -1
- package/dist/take-over-request-KdR1_h_K.js +0 -64
- package/dist/translation-warning-modal-CLZ9tC1F.cjs +0 -1
- package/dist/translation-warning-modal-CzNt6LDO.js +0 -27
- package/dist/unpublish-page-0fR1o0b7.js +0 -28
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import { jsx as e, jsxs as i } from "react/jsx-runtime";
|
|
2
|
-
import { B as b, z as L } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
|
-
import { aF as ne, c as M, X as ie, Y as oe, P as le, aG as ce, ax as de, aH as ue, p as P } from "./index-OuHV9Ann.js";
|
|
4
|
-
import { aq as D, ar as G, A as _, ax as me } from "./index-LBTm1Jmk.js";
|
|
5
|
-
import { useQuery as K, useMutation as A, useQueryClient as pe } from "@tanstack/react-query";
|
|
6
|
-
import { useSetAtom as fe } from "jotai";
|
|
7
|
-
import { toast as N } from "sonner";
|
|
8
|
-
import { Trash2 as Y, Plus as he, ImageIcon as ge, X as be, AlertCircle as ye } from "lucide-react";
|
|
9
|
-
import { useState as h, useRef as V, useMemo as S, useEffect as w, useCallback as ke } from "react";
|
|
10
|
-
import { c as ve } from "./image-compression-DPFITwOL.js";
|
|
11
|
-
import { isEmpty as Ne, set as Be, has as Ce } from "lodash-es";
|
|
12
|
-
const Ie = (r) => {
|
|
13
|
-
const a = D(), o = G();
|
|
14
|
-
return A({
|
|
15
|
-
mutationFn: async (t) => o(a, {
|
|
16
|
-
action: _.UPSERT_LIBRARY_ITEM,
|
|
17
|
-
data: t
|
|
18
|
-
}),
|
|
19
|
-
onSuccess: (t) => {
|
|
20
|
-
r ? r(t) : N.success("Block saved successfully");
|
|
21
|
-
},
|
|
22
|
-
onError: (t) => {
|
|
23
|
-
console.error("Error saving block:", t), N.error("Failed to save block", {
|
|
24
|
-
description: t instanceof Error ? t.message : "Unknown error"
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}, we = (r) => {
|
|
29
|
-
const a = D(), o = G();
|
|
30
|
-
return K({
|
|
31
|
-
staleTime: "static",
|
|
32
|
-
queryKey: [_.GET_LIBRARY_ITEM, r],
|
|
33
|
-
enabled: !!r,
|
|
34
|
-
// Only run query if blockId is provided
|
|
35
|
-
queryFn: async () => {
|
|
36
|
-
if (!r) return null;
|
|
37
|
-
try {
|
|
38
|
-
return await o(a, {
|
|
39
|
-
action: _.GET_LIBRARY_ITEM,
|
|
40
|
-
data: { id: r }
|
|
41
|
-
});
|
|
42
|
-
} catch (t) {
|
|
43
|
-
throw console.error(t), new Error("The block could not be found on the server. It may have been deleted.");
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
retry: !1
|
|
47
|
-
});
|
|
48
|
-
}, Ee = (r) => {
|
|
49
|
-
const a = D(), o = G(), t = fe(ne);
|
|
50
|
-
return A({
|
|
51
|
-
mutationFn: async (l) => o(a, {
|
|
52
|
-
action: _.DELETE_LIBRARY_ITEM,
|
|
53
|
-
data: { id: l }
|
|
54
|
-
}),
|
|
55
|
-
onSuccess: () => {
|
|
56
|
-
t((l) => {
|
|
57
|
-
const m = { ...l };
|
|
58
|
-
return Object.keys(m).forEach((u) => {
|
|
59
|
-
m[u] = { loading: "idle", blocks: [], error: !1 };
|
|
60
|
-
}), m;
|
|
61
|
-
}), r ? r() : N.success("Block deleted successfully");
|
|
62
|
-
},
|
|
63
|
-
onError: (l) => {
|
|
64
|
-
console.error("Error deleting block:", l), N.error("Failed to delete block", {
|
|
65
|
-
description: l instanceof Error ? l.message : "Unknown error"
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}, xe = ({
|
|
70
|
-
blockId: r,
|
|
71
|
-
libBlockId: a,
|
|
72
|
-
isOpen: o,
|
|
73
|
-
onClose: t,
|
|
74
|
-
blockName: l,
|
|
75
|
-
trigger: m
|
|
76
|
-
}) => {
|
|
77
|
-
const [u, c] = h(!1), d = M(), y = Ee(() => {
|
|
78
|
-
d([r], { _libBlockId: void 0 }), N.success("Block deleted successfully"), c(!1), t();
|
|
79
|
-
});
|
|
80
|
-
return /* @__PURE__ */ i(ie, { open: o, onOpenChange: (p) => !p && t(), children: [
|
|
81
|
-
/* @__PURE__ */ e(oe, { asChild: !0, children: m || /* @__PURE__ */ i(b, { type: "button", variant: "destructive", size: "sm", onClick: (p) => p.preventDefault(), disabled: u, children: [
|
|
82
|
-
/* @__PURE__ */ e(Y, { className: "mr-2 h-4 w-4" }),
|
|
83
|
-
"Delete"
|
|
84
|
-
] }) }),
|
|
85
|
-
/* @__PURE__ */ e(
|
|
86
|
-
le,
|
|
87
|
-
{
|
|
88
|
-
className: "z-[9999] w-72 p-4",
|
|
89
|
-
sideOffset: 5,
|
|
90
|
-
align: "center",
|
|
91
|
-
children: /* @__PURE__ */ i("div", { className: "space-y-3", children: [
|
|
92
|
-
/* @__PURE__ */ e("h4", { className: "font-medium", children: "Delete Block" }),
|
|
93
|
-
/* @__PURE__ */ i("p", { className: "text-sm", children: [
|
|
94
|
-
"Are you sure you want to delete the block",
|
|
95
|
-
/* @__PURE__ */ i("span", { className: "font-medium", children: [
|
|
96
|
-
' "',
|
|
97
|
-
l,
|
|
98
|
-
'"'
|
|
99
|
-
] }),
|
|
100
|
-
"?"
|
|
101
|
-
] }),
|
|
102
|
-
/* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: "This block will be permanently removed from the library. This action cannot be undone." }),
|
|
103
|
-
/* @__PURE__ */ i("div", { className: "flex justify-end gap-2 pt-2", children: [
|
|
104
|
-
/* @__PURE__ */ e(b, { type: "button", variant: "outline", size: "sm", onClick: t, disabled: u, children: "Cancel" }),
|
|
105
|
-
/* @__PURE__ */ e(b, { type: "button", variant: "destructive", size: "sm", onClick: () => {
|
|
106
|
-
c(!0), y.mutate(a);
|
|
107
|
-
}, disabled: u, children: u ? "Deleting..." : "Delete" })
|
|
108
|
-
] })
|
|
109
|
-
] })
|
|
110
|
-
}
|
|
111
|
-
)
|
|
112
|
-
] });
|
|
113
|
-
}, Pe = ({
|
|
114
|
-
blockId: r,
|
|
115
|
-
libBlockId: a,
|
|
116
|
-
blockName: o,
|
|
117
|
-
size: t = "sm",
|
|
118
|
-
className: l = "",
|
|
119
|
-
close: m
|
|
120
|
-
}) => {
|
|
121
|
-
const [u, c] = h(!1);
|
|
122
|
-
return /* @__PURE__ */ e(
|
|
123
|
-
xe,
|
|
124
|
-
{
|
|
125
|
-
blockId: r,
|
|
126
|
-
libBlockId: a,
|
|
127
|
-
isOpen: u,
|
|
128
|
-
onClose: () => {
|
|
129
|
-
c(!1), m();
|
|
130
|
-
},
|
|
131
|
-
blockName: o,
|
|
132
|
-
trigger: /* @__PURE__ */ i(
|
|
133
|
-
b,
|
|
134
|
-
{
|
|
135
|
-
type: "button",
|
|
136
|
-
variant: "destructive",
|
|
137
|
-
size: t,
|
|
138
|
-
className: l,
|
|
139
|
-
onClick: () => c(!0),
|
|
140
|
-
children: [
|
|
141
|
-
/* @__PURE__ */ e(Y, { className: "mr-2 h-4 w-4" }),
|
|
142
|
-
"Delete"
|
|
143
|
-
]
|
|
144
|
-
}
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
}, Le = () => {
|
|
149
|
-
const r = D(), a = G(), o = pe(), {
|
|
150
|
-
data: t = [],
|
|
151
|
-
isLoading: l,
|
|
152
|
-
error: m
|
|
153
|
-
} = K({
|
|
154
|
-
queryKey: ["library-groups"],
|
|
155
|
-
staleTime: "static",
|
|
156
|
-
placeholderData: [],
|
|
157
|
-
queryFn: async () => {
|
|
158
|
-
try {
|
|
159
|
-
return await a(r, {
|
|
160
|
-
action: "GET_LIBRARY_GROUPS"
|
|
161
|
-
}) || [];
|
|
162
|
-
} catch (d) {
|
|
163
|
-
return console.error("Error fetching library groups:", d), [];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}), { mutateAsync: u, isPending: c } = A({
|
|
167
|
-
mutationFn: async (d) => {
|
|
168
|
-
if (!d.trim())
|
|
169
|
-
throw new Error("Group name is required");
|
|
170
|
-
return a(r, {
|
|
171
|
-
action: "CREATE_BLOCK_GROUP",
|
|
172
|
-
data: { name: d }
|
|
173
|
-
});
|
|
174
|
-
},
|
|
175
|
-
onSuccess: () => {
|
|
176
|
-
o.invalidateQueries({
|
|
177
|
-
queryKey: ["library-groups"]
|
|
178
|
-
}), N.success("Group created successfully");
|
|
179
|
-
},
|
|
180
|
-
onError: (d) => {
|
|
181
|
-
console.error("Error creating group:", d), N.error("Failed to create group", {
|
|
182
|
-
description: d instanceof Error ? d.message : "Unknown error"
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
return {
|
|
187
|
-
groups: t,
|
|
188
|
-
isLoading: l,
|
|
189
|
-
error: m,
|
|
190
|
-
createGroup: u,
|
|
191
|
-
isCreating: c
|
|
192
|
-
};
|
|
193
|
-
}, _e = ({ value: r, onChange: a }) => {
|
|
194
|
-
const [o, t] = h(!1), [l, m] = h(""), u = V(null), { groups: c } = Le(), [d, y] = h([
|
|
195
|
-
{ id: "hero", name: "Hero" },
|
|
196
|
-
{ id: "feature", name: "Feature" },
|
|
197
|
-
{ id: "footer", name: "Footer" },
|
|
198
|
-
{ id: "content", name: "Content" },
|
|
199
|
-
{ id: "testimonial", name: "Testimonial" },
|
|
200
|
-
{ id: "pricing", name: "Pricing" },
|
|
201
|
-
{ id: "login", name: "Login" },
|
|
202
|
-
{ id: "logos", name: "Logos" },
|
|
203
|
-
{ id: "about", name: "About" },
|
|
204
|
-
{ id: "banner", name: "Banner" },
|
|
205
|
-
{ id: "blog", name: "Blog" },
|
|
206
|
-
{ id: "careers", name: "Careers" },
|
|
207
|
-
{ id: "casestudy", name: "Casestudy" },
|
|
208
|
-
{ id: "changelog", name: "Changelog" },
|
|
209
|
-
{ id: "compare", name: "Compare" },
|
|
210
|
-
{ id: "contact", name: "Contact" },
|
|
211
|
-
{ id: "cta", name: "Cta" },
|
|
212
|
-
{ id: "faq", name: "Faq" },
|
|
213
|
-
{ id: "gallery", name: "Gallery" },
|
|
214
|
-
{ id: "integration", name: "Integration" },
|
|
215
|
-
{ id: "list", name: "List" },
|
|
216
|
-
{ id: "navbar", name: "Navbar" },
|
|
217
|
-
{ id: "product", name: "Product" },
|
|
218
|
-
{ id: "signup", name: "Signup" },
|
|
219
|
-
{ id: "stats", name: "Stats" },
|
|
220
|
-
{ id: "team", name: "Team" },
|
|
221
|
-
{ id: "timeline", name: "Timeline" }
|
|
222
|
-
]), f = S(
|
|
223
|
-
() => [
|
|
224
|
-
...c,
|
|
225
|
-
...d.filter((s) => !c.some((B) => B.id === s.id))
|
|
226
|
-
],
|
|
227
|
-
[c, d]
|
|
228
|
-
), g = () => {
|
|
229
|
-
const s = l.trim();
|
|
230
|
-
if (!s) return;
|
|
231
|
-
const B = { id: s, name: s };
|
|
232
|
-
y((E) => [...E, B]), a(B.id), m(""), t(!1);
|
|
233
|
-
};
|
|
234
|
-
w(() => {
|
|
235
|
-
o && u.current && u.current.focus();
|
|
236
|
-
}, [o]);
|
|
237
|
-
const p = (s) => {
|
|
238
|
-
s.key === "Enter" && (s.preventDefault(), g());
|
|
239
|
-
};
|
|
240
|
-
return w(() => {
|
|
241
|
-
r && !f.some((s) => s.id === r) && a("");
|
|
242
|
-
}, [r, f, a]), o ? /* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
243
|
-
/* @__PURE__ */ e(
|
|
244
|
-
L,
|
|
245
|
-
{
|
|
246
|
-
ref: u,
|
|
247
|
-
placeholder: "Enter new group name",
|
|
248
|
-
value: l,
|
|
249
|
-
onChange: (s) => m(s.target.value),
|
|
250
|
-
onKeyDown: p
|
|
251
|
-
}
|
|
252
|
-
),
|
|
253
|
-
/* @__PURE__ */ i("div", { className: "flex justify-end gap-2", children: [
|
|
254
|
-
/* @__PURE__ */ e(b, { variant: "outline", size: "sm", onClick: () => t(!1), children: "Cancel" }),
|
|
255
|
-
/* @__PURE__ */ e(b, { size: "sm", onClick: g, children: "Create" })
|
|
256
|
-
] })
|
|
257
|
-
] }) : /* @__PURE__ */ i("div", { className: "flex gap-2", children: [
|
|
258
|
-
/* @__PURE__ */ i(
|
|
259
|
-
"select",
|
|
260
|
-
{
|
|
261
|
-
className: "w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
262
|
-
value: r,
|
|
263
|
-
onChange: (s) => a(s.target.value),
|
|
264
|
-
children: [
|
|
265
|
-
/* @__PURE__ */ e("option", { value: "", children: "Select a group" }),
|
|
266
|
-
c.length > 0 && /* @__PURE__ */ e("optgroup", { label: "Library Groups", children: c.map((s) => /* @__PURE__ */ e("option", { value: s.id, children: s.name }, `lib-${s.id}`)) }),
|
|
267
|
-
d.length > 0 && /* @__PURE__ */ e("optgroup", { label: "Predefined Groups", children: d.filter((s) => !c.some((B) => B.id === s.id)).map((s) => /* @__PURE__ */ e("option", { value: s.id, children: s.name }, `local-${s.id}`)) })
|
|
268
|
-
]
|
|
269
|
-
}
|
|
270
|
-
),
|
|
271
|
-
/* @__PURE__ */ e(b, { type: "button", size: "icon", variant: "outline", onClick: () => t(!0), children: /* @__PURE__ */ e(he, { className: "h-4 w-4" }) })
|
|
272
|
-
] });
|
|
273
|
-
}, De = ({ value: r, onChange: a }) => {
|
|
274
|
-
const [o, t] = h(!1), l = V(null), m = ke(
|
|
275
|
-
async (d) => {
|
|
276
|
-
var f;
|
|
277
|
-
const y = (f = d.target.files) == null ? void 0 : f[0];
|
|
278
|
-
if (y)
|
|
279
|
-
try {
|
|
280
|
-
t(!0);
|
|
281
|
-
let g = y;
|
|
282
|
-
y.type.startsWith("image/") && (g = await ve(y));
|
|
283
|
-
const p = new FileReader();
|
|
284
|
-
p.onloadend = () => {
|
|
285
|
-
a(p.result), t(!1);
|
|
286
|
-
}, p.readAsDataURL(g);
|
|
287
|
-
} catch (g) {
|
|
288
|
-
console.error("Error reading file:", g), t(!1), N.error("Failed to process image", {
|
|
289
|
-
description: g instanceof Error ? g.message : "Unknown error"
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
[a]
|
|
294
|
-
);
|
|
295
|
-
return /* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
296
|
-
/* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
|
|
297
|
-
/* @__PURE__ */ e(L, { type: "file", ref: l, onChange: m, accept: "image/*", className: "hidden" }),
|
|
298
|
-
/* @__PURE__ */ e(b, { type: "button", variant: "outline", onClick: () => {
|
|
299
|
-
var d;
|
|
300
|
-
(d = l.current) == null || d.click();
|
|
301
|
-
}, disabled: o, className: "w-full", children: o ? /* @__PURE__ */ i("span", { className: "flex items-center gap-2", children: [
|
|
302
|
-
/* @__PURE__ */ e("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" }),
|
|
303
|
-
"Uploading..."
|
|
304
|
-
] }) : /* @__PURE__ */ i("span", { className: "flex items-center gap-2", children: [
|
|
305
|
-
/* @__PURE__ */ e(ge, { className: "h-4 w-4" }),
|
|
306
|
-
"Select image"
|
|
307
|
-
] }) }),
|
|
308
|
-
r && /* @__PURE__ */ e(b, { type: "button", variant: "outline", size: "icon", onClick: () => {
|
|
309
|
-
a(""), l.current && (l.current.value = "");
|
|
310
|
-
}, children: /* @__PURE__ */ e(be, { className: "h-4 w-4" }) })
|
|
311
|
-
] }),
|
|
312
|
-
r && /* @__PURE__ */ e("div", { className: "aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border", children: /* @__PURE__ */ e("img", { src: r, alt: "Preview", className: "h-full w-full object-contain" }) })
|
|
313
|
-
] });
|
|
314
|
-
}, Me = (r) => {
|
|
315
|
-
const { blocks: a, close: o, blockId: t } = r, { getPartialBlocks: l } = ce(), m = a.find((n) => n._id === t), u = m == null ? void 0 : m._libBlockId, c = !!u, d = S(() => a.some((n) => n._type === "PartialBlock" || n._type === "GlobalBlock"), [a]), y = S(() => {
|
|
316
|
-
let n = [];
|
|
317
|
-
for (const k of a)
|
|
318
|
-
if (k._type === "PartialBlock" || k._type === "GlobalBlock") {
|
|
319
|
-
let v = l(k.partialBlockId);
|
|
320
|
-
k._parent && (v == null ? void 0 : v.length) > 0 && (v = v.map((R) => (Ne(R._parent) && Be(R, "_parent", k._parent), R))), n = [...n, ...v];
|
|
321
|
-
} else
|
|
322
|
-
n.push(k);
|
|
323
|
-
return n;
|
|
324
|
-
}, [a, l]), [f, g] = h(""), [p, s] = h(""), [B, E] = h(""), [x, U] = h(""), [C, W] = h({}), [Q, $] = h(!1), [H, q] = h(c), [X, J] = h(!1), { hasPermission: Z } = de(), ee = Z(me.DELETE_LIBRARY_BLOCK), O = M(), te = () => {
|
|
325
|
-
O([t], { _libBlockId: void 0 }), N.success("Block delinked from library"), o();
|
|
326
|
-
}, {
|
|
327
|
-
data: I,
|
|
328
|
-
isLoading: F,
|
|
329
|
-
isError: j
|
|
330
|
-
} = we(u);
|
|
331
|
-
w(() => {
|
|
332
|
-
j && c && (J(!0), q(!1));
|
|
333
|
-
}, [j, c]), w(() => {
|
|
334
|
-
I && !F && (g(I.name || ""), s(I.group || ""), E(I.description || ""), U(I.preview || ""), q(!1));
|
|
335
|
-
}, [I, F]), w(() => {
|
|
336
|
-
const n = f.trim().length >= 2, k = p.trim() !== "";
|
|
337
|
-
$(n && k);
|
|
338
|
-
}, [f, p]);
|
|
339
|
-
const re = () => {
|
|
340
|
-
const n = {};
|
|
341
|
-
return f.trim() ? f.length < 2 && (n.name = "Name must be at least 2 characters") : n.name = "Name is required", p || (n.group = "Group is required"), W(n), Object.keys(n).length === 0;
|
|
342
|
-
}, { resetLibrary: ae } = ue({ id: "" }), z = Ie((n) => {
|
|
343
|
-
c || O([t], { _libBlockId: n.id }), N.success(`Block ${c ? "updated" : "saved"} successfully`), ae(n.library), o();
|
|
344
|
-
}), se = async (n) => {
|
|
345
|
-
if (n.preventDefault(), !re()) return;
|
|
346
|
-
const k = y.map((v) => (Ce(v, "_libBlockId") && delete v._libBlockId, v));
|
|
347
|
-
z.mutate({
|
|
348
|
-
name: f.trim(),
|
|
349
|
-
group: p,
|
|
350
|
-
blocks: k,
|
|
351
|
-
description: B.trim(),
|
|
352
|
-
// Only include previewImage if it exists and is a base64 image
|
|
353
|
-
...x && x.startsWith("data:") ? { previewImage: x } : {},
|
|
354
|
-
// Include id if in edit mode
|
|
355
|
-
...c ? { id: u } : {}
|
|
356
|
-
});
|
|
357
|
-
}, T = z.isPending;
|
|
358
|
-
return H || F ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center p-8", children: /* @__PURE__ */ e("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" }) }) : X ? /* @__PURE__ */ i("div", { className: "space-y-4 p-6", children: [
|
|
359
|
-
/* @__PURE__ */ e("div", { className: "font-medium text-destructive", children: "Block Not Found" }),
|
|
360
|
-
/* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "This block could not be found on the server. It may have been deleted." }),
|
|
361
|
-
/* @__PURE__ */ i("div", { className: "flex justify-end gap-2 pt-4", children: [
|
|
362
|
-
/* @__PURE__ */ e(b, { type: "button", variant: "outline", onClick: o, children: "Cancel" }),
|
|
363
|
-
/* @__PURE__ */ e(b, { onClick: te, variant: "destructive", children: "Delink Block" })
|
|
364
|
-
] })
|
|
365
|
-
] }) : /* @__PURE__ */ i("div", { children: [
|
|
366
|
-
d && /* @__PURE__ */ i("div", { className: "mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive", children: [
|
|
367
|
-
/* @__PURE__ */ e(ye, { className: "mt-0.5 h-5 w-5 flex-shrink-0" }),
|
|
368
|
-
/* @__PURE__ */ i("div", { children: [
|
|
369
|
-
/* @__PURE__ */ e("p", { className: "font-medium", children: "Partial Blocks Detected" }),
|
|
370
|
-
/* @__PURE__ */ e("p", { className: "mt-1 text-xs", children: "This block contains one or more Partial Blocks. Partial blocks will be merged into the library block" })
|
|
371
|
-
] })
|
|
372
|
-
] }),
|
|
373
|
-
/* @__PURE__ */ i("form", { onSubmit: se, className: "space-y-4", children: [
|
|
374
|
-
/* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
375
|
-
/* @__PURE__ */ e(P, { htmlFor: "name", className: C.name ? "text-destructive" : "", children: "Name" }),
|
|
376
|
-
/* @__PURE__ */ e(
|
|
377
|
-
L,
|
|
378
|
-
{
|
|
379
|
-
id: "name",
|
|
380
|
-
placeholder: "Enter block name",
|
|
381
|
-
value: f,
|
|
382
|
-
onChange: (n) => g(n.target.value),
|
|
383
|
-
className: C.name ? "border-destructive" : ""
|
|
384
|
-
}
|
|
385
|
-
),
|
|
386
|
-
C.name && /* @__PURE__ */ e("p", { className: "text-xs text-destructive", children: C.name })
|
|
387
|
-
] }),
|
|
388
|
-
/* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
389
|
-
/* @__PURE__ */ e(P, { htmlFor: "group", className: C.group ? "text-destructive" : "", children: "Group" }),
|
|
390
|
-
/* @__PURE__ */ e(_e, { value: p, onChange: s }),
|
|
391
|
-
C.group && /* @__PURE__ */ e("p", { className: "text-xs text-destructive", children: C.group })
|
|
392
|
-
] }),
|
|
393
|
-
/* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
394
|
-
/* @__PURE__ */ e(P, { htmlFor: "description", children: "Description (optional)" }),
|
|
395
|
-
/* @__PURE__ */ e(
|
|
396
|
-
L,
|
|
397
|
-
{
|
|
398
|
-
id: "description",
|
|
399
|
-
placeholder: "Enter a brief description",
|
|
400
|
-
className: "resize-none",
|
|
401
|
-
value: B,
|
|
402
|
-
onChange: (n) => E(n.target.value)
|
|
403
|
-
}
|
|
404
|
-
)
|
|
405
|
-
] }),
|
|
406
|
-
/* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
407
|
-
/* @__PURE__ */ e(P, { htmlFor: "previewImage", children: "Preview Image (optional)" }),
|
|
408
|
-
/* @__PURE__ */ e(De, { value: x, onChange: U })
|
|
409
|
-
] }),
|
|
410
|
-
/* @__PURE__ */ i("div", { className: "flex justify-end gap-2 pt-2", children: [
|
|
411
|
-
c && ee && /* @__PURE__ */ e(
|
|
412
|
-
Pe,
|
|
413
|
-
{
|
|
414
|
-
blockId: t,
|
|
415
|
-
libBlockId: u,
|
|
416
|
-
blockName: f,
|
|
417
|
-
className: "mr-auto",
|
|
418
|
-
close: o
|
|
419
|
-
}
|
|
420
|
-
),
|
|
421
|
-
/* @__PURE__ */ e(b, { type: "button", variant: "outline", onClick: o, disabled: T, children: "Cancel" }),
|
|
422
|
-
/* @__PURE__ */ e(b, { type: "submit", disabled: T || !Q, children: T ? "Saving..." : c ? "Update Block" : "Save Block" })
|
|
423
|
-
] })
|
|
424
|
-
] })
|
|
425
|
-
] });
|
|
426
|
-
};
|
|
427
|
-
export {
|
|
428
|
-
Me as default
|
|
429
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./register-chai-top-bar-DyW9GPzV.cjs"),x=require("./index-DCJDQs1a.cjs"),b=require("./index-BVwFJWDq.cjs"),C=require("@tanstack/react-query"),X=require("jotai"),j=require("sonner"),E=require("lucide-react"),i=require("react"),J=require("./image-compression-UaU7Bwqe.cjs"),R=require("lodash-es"),Z=s=>{const r=b.useApiUrl(),l=b.useFetch();return C.useMutation({mutationFn:async t=>l(r,{action:b.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{s?s(t):j.toast.success("Block saved successfully")},onError:t=>{console.error("Error saving block:",t),j.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},ee=s=>{const r=b.useApiUrl(),l=b.useFetch();return C.useQuery({staleTime:"static",queryKey:[b.ACTIONS.GET_LIBRARY_ITEM,s],enabled:!!s,queryFn:async()=>{if(!s)return null;try{return await l(r,{action:b.ACTIONS.GET_LIBRARY_ITEM,data:{id:s}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},te=s=>{const r=b.useApiUrl(),l=b.useFetch(),t=X.useSetAtom(x.libraryBlocksAtom);return C.useMutation({mutationFn:async c=>l(r,{action:b.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:c}}),onSuccess:()=>{t(c=>{const m={...c};return Object.keys(m).forEach(u=>{m[u]={loading:"idle",blocks:[],error:!1}}),m}),s?s():j.toast.success("Block deleted successfully")},onError:c=>{console.error("Error deleting block:",c),j.toast.error("Failed to delete block",{description:c instanceof Error?c.message:"Unknown error"})}})},se=({blockId:s,libBlockId:r,isOpen:l,onClose:t,blockName:c,trigger:m})=>{const[u,o]=i.useState(!1),d=x.useUpdateBlocksPropsRealtime(),y=te(()=>{d([s],{_libBlockId:void 0}),j.toast.success("Block deleted successfully"),o(!1),t()}),h=()=>{o(!0),y.mutate(r)},g=e.jsxs(p.Button,{type:"button",variant:"destructive",size:"sm",onClick:f=>f.preventDefault(),disabled:u,children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]});return e.jsxs(x.Popover,{open:l,onOpenChange:f=>!f&&t(),children:[e.jsx(x.PopoverTrigger,{asChild:!0,children:m||g}),e.jsx(x.PopoverContent,{className:"z-[9999] w-72 p-4",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',c,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(p.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(p.Button,{type:"button",variant:"destructive",size:"sm",onClick:h,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},re=({blockId:s,libBlockId:r,blockName:l,size:t="sm",className:c="",close:m})=>{const[u,o]=i.useState(!1);return e.jsx(se,{blockId:s,libBlockId:r,isOpen:u,onClose:()=>{o(!1),m()},blockName:l,trigger:e.jsxs(p.Button,{type:"button",variant:"destructive",size:t,className:c,onClick:()=>o(!0),children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})},ne=()=>{const s=b.useApiUrl(),r=b.useFetch(),l=C.useQueryClient(),{data:t=[],isLoading:c,error:m}=C.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await r(s,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=C.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return r(s,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),j.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),j.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:c,error:m,createGroup:u,isCreating:o}},ae=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),[c,m]=i.useState(""),u=i.useRef(null),{groups:o}=ne(),[d,y]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),h=i.useMemo(()=>[...o,...d.filter(n=>!o.some(B=>B.id===n.id))],[o,d]),g=()=>{const n=c.trim();if(!n)return;const B={id:n,name:n};y(w=>[...w,B]),r(B.id),m(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const f=n=>{n.key==="Enter"&&(n.preventDefault(),g())};return i.useEffect(()=>{s&&!h.some(n=>n.id===s)&&r("")},[s,h,r]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(p.Input,{ref:u,placeholder:"Enter new group name",value:c,onChange:n=>m(n.target.value),onKeyDown:f}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(p.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(p.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:s,onChange:n=>r(n.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(n=>e.jsx("option",{value:n.id,children:n.name},`lib-${n.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(n=>!o.some(B=>B.id===n.id)).map(n=>e.jsx("option",{value:n.id,children:n.name},`local-${n.id}`))})]}),e.jsx(p.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(E.Plus,{className:"h-4 w-4"})})]})},oe=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),c=i.useRef(null),m=i.useCallback(async d=>{var h;const y=(h=d.target.files)==null?void 0:h[0];if(y)try{t(!0);let g=y;y.type.startsWith("image/")&&(g=await J.compressImageIfNeeded(y));const f=new FileReader;f.onloadend=()=>{r(f.result),t(!1)},f.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),j.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[r]),u=()=>{r(""),c.current&&(c.current.value="")},o=()=>{var d;(d=c.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p.Input,{type:"file",ref:c,onChange:m,accept:"image/*",className:"hidden"}),e.jsx(p.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(E.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),s&&e.jsx(p.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(E.X,{className:"h-4 w-4"})})]}),s&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:s,alt:"Preview",className:"h-full w-full object-contain"})})]})},ie=s=>{const{blocks:r,close:l,blockId:t}=s,{getPartialBlocks:c}=x.usePartialBlocksStore(),m=r.find(a=>a._id===t),u=m==null?void 0:m._libBlockId,o=!!u,d=i.useMemo(()=>r.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[r]),y=i.useMemo(()=>{let a=[];for(const k of r)if(k._type==="PartialBlock"||k._type==="GlobalBlock"){let v=c(k.partialBlockId);k._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",k._parent),T))),a=[...a,...v]}else a.push(k);return a},[r,c]),[h,g]=i.useState(""),[f,n]=i.useState(""),[B,w]=i.useState(""),[S,_]=i.useState(""),[N,U]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=x.usePermissions(),Q=Y(b.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=x.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),j.toast.success("Block delinked from library"),l()},{data:I,isLoading:P,isError:G}=ee(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{I&&!P&&(g(I.name||""),n(I.group||""),w(I.description||""),_(I.preview||""),F(!1))},[I,P]),i.useEffect(()=>{const a=h.trim().length>=2,k=f.trim()!=="";M(a&&k)},[h,f]);const W=()=>{const a={};return h.trim()?h.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",f||(a.group="Group is required"),U(a),Object.keys(a).length===0},{resetLibrary:$}=x.useLibraryBlocks({id:""}),A=Z(a=>{o||D([t],{_libBlockId:a.id}),j.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const k=y.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));A.mutate({name:h.trim(),group:f,blocks:k,description:B.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=A.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(p.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(p.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(E.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(p.Input,{id:"name",placeholder:"Enter block name",value:h,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ae,{value:f,onChange:n}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(p.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:B,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(oe,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(re,{blockId:t,libBlockId:u,blockName:h,className:"mr-auto",close:l}),e.jsx(p.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(p.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=ie;
|