@chaibuilder/pages 0.13.4 → 0.14.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/dist/{2AITGKQY-DpAgk_u8.cjs → 2AITGKQY-BLi5HVHf.cjs} +1 -1
- package/dist/{2AITGKQY-Dx_Cte-P.js → 2AITGKQY-iyhQ7kgG.js} +5 -5
- package/dist/{NCMVHL6D-B6lv7Umq.cjs → NCMVHL6D-CKYg8-AM.cjs} +1 -1
- package/dist/{NCMVHL6D-CT2qHOTS.js → NCMVHL6D-PLvSyK5P.js} +2 -2
- package/dist/{ZDWCUMSJ-C1vrgsti.cjs → ZDWCUMSJ-BJZ_Yi-4.cjs} +1 -1
- package/dist/{ZDWCUMSJ-W9xywtZH.js → ZDWCUMSJ-CuLkdxY-.js} +1 -1
- package/dist/add-new-language-page--ah9yzN3.cjs +1 -0
- package/dist/add-new-language-page-WM_Ve2vH.js +390 -0
- package/dist/add-new-page-Bs_NXM9x.js +30 -0
- package/dist/add-new-page-CnUo6xzd.cjs +1 -0
- package/dist/confetti.module-BuUnQuWk.cjs +2 -0
- package/dist/confetti.module-DCmCkDyV.js +409 -0
- package/dist/delete-page-Cf88UkqJ.cjs +1 -0
- package/dist/delete-page-D8xhYESu.js +38 -0
- package/dist/digital-asset-manager-BAFTqxsM.js +976 -0
- package/dist/digital-asset-manager-D_lcprwY.cjs +1 -0
- package/dist/duplicate-page-BX1gOez-.cjs +1 -0
- package/dist/duplicate-page-CqXTGmWt.js +120 -0
- package/dist/dynamic-page-selector-0TiUnfUg.js +86 -0
- package/dist/dynamic-page-selector-9JIQrcq5.cjs +1 -0
- package/dist/get-seo-defaults-9zHebckY.js +65 -0
- package/dist/get-seo-defaults-Cw7vFt-B.cjs +1 -0
- package/dist/image-compression-DZ9WMmyn.cjs +1 -0
- package/dist/image-compression-DsZ1oqpb.js +37 -0
- package/dist/index-D7kegQ3M.js +5153 -0
- package/dist/index-LU0FTfeN.cjs +5 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -22
- package/dist/index.js +20 -21
- package/dist/json-diff-viewer-Be-PVOZN.cjs +8 -0
- package/dist/json-diff-viewer-C2GK_BDh.js +258 -0
- package/dist/lang-panel-CPFS1ssC.js +218 -0
- package/dist/lang-panel-CePltxo2.cjs +1 -0
- package/dist/mark-as-template-DeB23sWR.cjs +1 -0
- package/dist/mark-as-template-jdwcgRIB.js +146 -0
- package/dist/nested-path-selector-content-D_iF9Sm3.cjs +1 -0
- package/dist/nested-path-selector-content-DvIL_EoN.js +87 -0
- package/dist/no-language-page-content-DUM4KxWu.js +35 -0
- package/dist/no-language-page-content-Dsm2H3pc.cjs +1 -0
- package/dist/page-creator-BjuYmKfc.js +796 -0
- package/dist/page-creator-DG0LwvL1.cjs +1 -0
- package/dist/page-lock-request-B9WPmFcd.cjs +1 -0
- package/dist/page-lock-request-BceB1S-X.js +64 -0
- package/dist/page-locked-by-dialog-2MULM3jh.cjs +1 -0
- package/dist/page-locked-by-dialog-BEWfFLSc.js +63 -0
- package/dist/page-manager-new-BONZN4c5.cjs +1 -0
- package/dist/page-manager-new-DV6A9WFv.js +354 -0
- package/dist/page-manager-search-and-filter-3h4URMP_.cjs +1 -0
- package/dist/page-manager-search-and-filter-DIiowi9F.js +197 -0
- package/dist/page-revisions-content-BIxeZeND.js +446 -0
- package/dist/page-revisions-content-CQbt25XX.cjs +1 -0
- package/dist/publish-pages-content-CdKHrfys.js +178 -0
- package/dist/publish-pages-content-im9dPOBM.cjs +1 -0
- package/dist/save-to-lib-DGII9CEP.js +476 -0
- package/dist/save-to-lib-DOh-850u.cjs +1 -0
- package/dist/seo-panel-2VdpoGSg.cjs +1 -0
- package/dist/seo-panel-Bxo4f-a_.js +667 -0
- package/dist/shared-json-ld-C1OewNgp.cjs +1 -0
- package/dist/shared-json-ld-gbnBFljN.js +337 -0
- package/dist/slug-input-BmcGmc_i.js +87 -0
- package/dist/slug-input-CfuQV97Z.cjs +1 -0
- package/dist/theme-panel-footer-D3SwHqGR.js +25 -0
- package/dist/theme-panel-footer-FrY4U8zn.cjs +1 -0
- package/dist/translation-warning-modal-DalBhNQy.js +26 -0
- package/dist/translation-warning-modal-Kctu12rQ.cjs +1 -0
- package/dist/unmark-as-template-CihtTMOb.cjs +1 -0
- package/dist/unmark-as-template-UwmCCn0u.js +38 -0
- package/dist/unpublish-page-CNwIU6AS.js +26 -0
- package/dist/unpublish-page-DzLtZcNw.cjs +1 -0
- package/dist/use-page-expand-manager-B7JtHdg5.cjs +1 -0
- package/dist/use-page-expand-manager-BCFQnVkT.js +85 -0
- package/package.json +1 -1
- package/dist/index-C4j31Yhz.js +0 -11471
- package/dist/index-DnjETHks.cjs +0 -6
- package/dist/page-revisions-content-Gx-Qf_91.cjs +0 -8
- package/dist/page-revisions-content-_-Nd4U11.js +0 -712
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import { jsx as e, jsxs as i } from "react/jsx-runtime";
|
|
2
|
+
import { useMutation as U, useQuery as z, useQueryClient as se } from "@tanstack/react-query";
|
|
3
|
+
import { toast as B } from "sonner";
|
|
4
|
+
import { ai as L, aj as G, A as _, au as ie } from "./index-D7kegQ3M.js";
|
|
5
|
+
import { useUpdateBlocksPropsRealtime as K, usePartailBlocksStore as oe, usePermissions as le, useLibraryBlocks as ce } from "@chaibuilder/sdk";
|
|
6
|
+
import { Button as b, Popover as de, PopoverTrigger as ue, PopoverContent as me, Input as D, Label as P } from "@chaibuilder/sdk/ui";
|
|
7
|
+
import { Trash2 as Y, Plus as pe, ImageIcon as he, X as fe, AlertCircle as ge } from "lucide-react";
|
|
8
|
+
import { useState as f, useRef as V, useMemo as S, useEffect as w, useCallback as be } from "react";
|
|
9
|
+
import { c as ve } from "./image-compression-DsZ1oqpb.js";
|
|
10
|
+
import { isEmpty as ye, set as ke, has as Ne } from "lodash-es";
|
|
11
|
+
const Be = (a) => {
|
|
12
|
+
const r = L(), o = G();
|
|
13
|
+
return U({
|
|
14
|
+
mutationFn: async (t) => o(r, {
|
|
15
|
+
action: _.UPSERT_LIBRARY_ITEM,
|
|
16
|
+
data: t
|
|
17
|
+
}),
|
|
18
|
+
onSuccess: (t) => {
|
|
19
|
+
a(t);
|
|
20
|
+
},
|
|
21
|
+
onError: (t) => {
|
|
22
|
+
console.error("Error saving block:", t), B.error("Failed to save block", {
|
|
23
|
+
description: t instanceof Error ? t.message : "Unknown error"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}, Ce = (a) => {
|
|
28
|
+
const r = L(), o = G();
|
|
29
|
+
return z({
|
|
30
|
+
staleTime: "static",
|
|
31
|
+
queryKey: [_.GET_LIBRARY_ITEM, a],
|
|
32
|
+
enabled: !!a,
|
|
33
|
+
// Only run query if blockId is provided
|
|
34
|
+
queryFn: async () => {
|
|
35
|
+
if (!a) return null;
|
|
36
|
+
try {
|
|
37
|
+
return await o(r, {
|
|
38
|
+
action: _.GET_LIBRARY_ITEM,
|
|
39
|
+
data: { id: a }
|
|
40
|
+
});
|
|
41
|
+
} catch (t) {
|
|
42
|
+
throw console.error(t), new Error("The block could not be found on the server. It may have been deleted.");
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
retry: !1
|
|
46
|
+
});
|
|
47
|
+
}, Ie = (a) => {
|
|
48
|
+
const r = L(), o = G();
|
|
49
|
+
return U({
|
|
50
|
+
mutationFn: async (t) => o(r, {
|
|
51
|
+
action: _.DELETE_LIBRARY_ITEM,
|
|
52
|
+
data: { id: t }
|
|
53
|
+
}),
|
|
54
|
+
onSuccess: () => {
|
|
55
|
+
a();
|
|
56
|
+
},
|
|
57
|
+
onError: (t) => {
|
|
58
|
+
console.error("Error deleting block:", t), B.error("Failed to delete block", {
|
|
59
|
+
description: t instanceof Error ? t.message : "Unknown error"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}, we = ({
|
|
64
|
+
blockId: a,
|
|
65
|
+
libBlockId: r,
|
|
66
|
+
isOpen: o,
|
|
67
|
+
onClose: t,
|
|
68
|
+
blockName: u,
|
|
69
|
+
trigger: p
|
|
70
|
+
}) => {
|
|
71
|
+
const [d, l] = f(!1), c = K(), v = Ie(() => {
|
|
72
|
+
c([a], { _libBlockId: void 0 }), B.success("Block deleted successfully"), l(!1), t();
|
|
73
|
+
});
|
|
74
|
+
return /* @__PURE__ */ i(de, { open: o, onOpenChange: (m) => !m && t(), children: [
|
|
75
|
+
/* @__PURE__ */ e(ue, { asChild: !0, children: p || /* @__PURE__ */ i(
|
|
76
|
+
b,
|
|
77
|
+
{
|
|
78
|
+
type: "button",
|
|
79
|
+
variant: "destructive",
|
|
80
|
+
size: "sm",
|
|
81
|
+
onClick: (m) => m.preventDefault(),
|
|
82
|
+
disabled: d,
|
|
83
|
+
children: [
|
|
84
|
+
/* @__PURE__ */ e(Y, { className: "h-4 w-4 mr-2" }),
|
|
85
|
+
"Delete"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
) }),
|
|
89
|
+
/* @__PURE__ */ e(
|
|
90
|
+
me,
|
|
91
|
+
{
|
|
92
|
+
className: "w-72 p-4 z-[9999]",
|
|
93
|
+
sideOffset: 5,
|
|
94
|
+
align: "center",
|
|
95
|
+
children: /* @__PURE__ */ i("div", { className: "space-y-3", children: [
|
|
96
|
+
/* @__PURE__ */ e("h4", { className: "font-medium", children: "Delete Block" }),
|
|
97
|
+
/* @__PURE__ */ i("p", { className: "text-sm", children: [
|
|
98
|
+
"Are you sure you want to delete the block",
|
|
99
|
+
/* @__PURE__ */ i("span", { className: "font-medium", children: [
|
|
100
|
+
' "',
|
|
101
|
+
u,
|
|
102
|
+
'"'
|
|
103
|
+
] }),
|
|
104
|
+
"?"
|
|
105
|
+
] }),
|
|
106
|
+
/* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: "This block will be permanently removed from the library. This action cannot be undone." }),
|
|
107
|
+
/* @__PURE__ */ i("div", { className: "flex justify-end gap-2 pt-2", children: [
|
|
108
|
+
/* @__PURE__ */ e(
|
|
109
|
+
b,
|
|
110
|
+
{
|
|
111
|
+
type: "button",
|
|
112
|
+
variant: "outline",
|
|
113
|
+
size: "sm",
|
|
114
|
+
onClick: t,
|
|
115
|
+
disabled: d,
|
|
116
|
+
children: "Cancel"
|
|
117
|
+
}
|
|
118
|
+
),
|
|
119
|
+
/* @__PURE__ */ e(
|
|
120
|
+
b,
|
|
121
|
+
{
|
|
122
|
+
type: "button",
|
|
123
|
+
variant: "destructive",
|
|
124
|
+
size: "sm",
|
|
125
|
+
onClick: () => {
|
|
126
|
+
l(!0), v.mutate(r);
|
|
127
|
+
},
|
|
128
|
+
disabled: d,
|
|
129
|
+
children: d ? "Deleting..." : "Delete"
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
] })
|
|
133
|
+
] })
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
] });
|
|
137
|
+
}, Ee = ({
|
|
138
|
+
blockId: a,
|
|
139
|
+
libBlockId: r,
|
|
140
|
+
blockName: o,
|
|
141
|
+
size: t = "sm",
|
|
142
|
+
className: u = "",
|
|
143
|
+
close: p
|
|
144
|
+
}) => {
|
|
145
|
+
const [d, l] = f(!1);
|
|
146
|
+
return /* @__PURE__ */ e(
|
|
147
|
+
we,
|
|
148
|
+
{
|
|
149
|
+
blockId: a,
|
|
150
|
+
libBlockId: r,
|
|
151
|
+
isOpen: d,
|
|
152
|
+
onClose: () => {
|
|
153
|
+
l(!1), p();
|
|
154
|
+
},
|
|
155
|
+
blockName: o,
|
|
156
|
+
trigger: /* @__PURE__ */ i(
|
|
157
|
+
b,
|
|
158
|
+
{
|
|
159
|
+
type: "button",
|
|
160
|
+
variant: "destructive",
|
|
161
|
+
size: t,
|
|
162
|
+
className: u,
|
|
163
|
+
onClick: () => l(!0),
|
|
164
|
+
children: [
|
|
165
|
+
/* @__PURE__ */ e(Y, { className: "h-4 w-4 mr-2" }),
|
|
166
|
+
"Delete"
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
}, xe = () => {
|
|
173
|
+
const a = L(), r = G(), o = se(), {
|
|
174
|
+
data: t = [],
|
|
175
|
+
isLoading: u,
|
|
176
|
+
error: p
|
|
177
|
+
} = z({
|
|
178
|
+
queryKey: ["library-groups"],
|
|
179
|
+
staleTime: "static",
|
|
180
|
+
placeholderData: [],
|
|
181
|
+
queryFn: async () => {
|
|
182
|
+
try {
|
|
183
|
+
return await r(a, {
|
|
184
|
+
action: "GET_LIBRARY_GROUPS"
|
|
185
|
+
}) || [];
|
|
186
|
+
} catch (c) {
|
|
187
|
+
return console.error("Error fetching library groups:", c), [];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}), { mutateAsync: d, isPending: l } = U({
|
|
191
|
+
mutationFn: async (c) => {
|
|
192
|
+
if (!c.trim())
|
|
193
|
+
throw new Error("Group name is required");
|
|
194
|
+
return r(a, {
|
|
195
|
+
action: "CREATE_BLOCK_GROUP",
|
|
196
|
+
data: { name: c }
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
onSuccess: () => {
|
|
200
|
+
o.invalidateQueries({
|
|
201
|
+
queryKey: ["library-groups"]
|
|
202
|
+
}), B.success("Group created successfully");
|
|
203
|
+
},
|
|
204
|
+
onError: (c) => {
|
|
205
|
+
console.error("Error creating group:", c), B.error("Failed to create group", {
|
|
206
|
+
description: c instanceof Error ? c.message : "Unknown error"
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
return {
|
|
211
|
+
groups: t,
|
|
212
|
+
isLoading: u,
|
|
213
|
+
error: p,
|
|
214
|
+
createGroup: d,
|
|
215
|
+
isCreating: l
|
|
216
|
+
};
|
|
217
|
+
}, Pe = ({ value: a, onChange: r }) => {
|
|
218
|
+
const [o, t] = f(!1), [u, p] = f(""), d = V(null), { groups: l } = xe(), [c, v] = f([
|
|
219
|
+
{ id: "hero", name: "Hero" },
|
|
220
|
+
{ id: "feature", name: "Feature" },
|
|
221
|
+
{ id: "footer", name: "Footer" },
|
|
222
|
+
{ id: "content", name: "Content" },
|
|
223
|
+
{ id: "testimonial", name: "Testimonial" },
|
|
224
|
+
{ id: "pricing", name: "Pricing" },
|
|
225
|
+
{ id: "login", name: "Login" },
|
|
226
|
+
{ id: "logos", name: "Logos" },
|
|
227
|
+
{ id: "about", name: "About" },
|
|
228
|
+
{ id: "banner", name: "Banner" },
|
|
229
|
+
{ id: "blog", name: "Blog" },
|
|
230
|
+
{ id: "careers", name: "Careers" },
|
|
231
|
+
{ id: "casestudy", name: "Casestudy" },
|
|
232
|
+
{ id: "changelog", name: "Changelog" },
|
|
233
|
+
{ id: "compare", name: "Compare" },
|
|
234
|
+
{ id: "contact", name: "Contact" },
|
|
235
|
+
{ id: "cta", name: "Cta" },
|
|
236
|
+
{ id: "faq", name: "Faq" },
|
|
237
|
+
{ id: "gallery", name: "Gallery" },
|
|
238
|
+
{ id: "integration", name: "Integration" },
|
|
239
|
+
{ id: "list", name: "List" },
|
|
240
|
+
{ id: "navbar", name: "Navbar" },
|
|
241
|
+
{ id: "product", name: "Product" },
|
|
242
|
+
{ id: "signup", name: "Signup" },
|
|
243
|
+
{ id: "stats", name: "Stats" },
|
|
244
|
+
{ id: "team", name: "Team" },
|
|
245
|
+
{ id: "timeline", name: "Timeline" }
|
|
246
|
+
]), h = S(
|
|
247
|
+
() => [
|
|
248
|
+
...l,
|
|
249
|
+
...c.filter(
|
|
250
|
+
(n) => !l.some((N) => N.id === n.id)
|
|
251
|
+
)
|
|
252
|
+
],
|
|
253
|
+
[l, c]
|
|
254
|
+
), g = () => {
|
|
255
|
+
const n = u.trim();
|
|
256
|
+
if (!n) return;
|
|
257
|
+
const N = { id: n, name: n };
|
|
258
|
+
v((E) => [...E, N]), r(N.id), p(""), t(!1);
|
|
259
|
+
};
|
|
260
|
+
w(() => {
|
|
261
|
+
o && d.current && d.current.focus();
|
|
262
|
+
}, [o]);
|
|
263
|
+
const m = (n) => {
|
|
264
|
+
n.key === "Enter" && (n.preventDefault(), g());
|
|
265
|
+
};
|
|
266
|
+
return w(() => {
|
|
267
|
+
a && !h.some((n) => n.id === a) && r("");
|
|
268
|
+
}, [a, h, r]), o ? /* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
269
|
+
/* @__PURE__ */ e(
|
|
270
|
+
D,
|
|
271
|
+
{
|
|
272
|
+
ref: d,
|
|
273
|
+
placeholder: "Enter new group name",
|
|
274
|
+
value: u,
|
|
275
|
+
onChange: (n) => p(n.target.value),
|
|
276
|
+
onKeyDown: m
|
|
277
|
+
}
|
|
278
|
+
),
|
|
279
|
+
/* @__PURE__ */ i("div", { className: "flex justify-end gap-2", children: [
|
|
280
|
+
/* @__PURE__ */ e(
|
|
281
|
+
b,
|
|
282
|
+
{
|
|
283
|
+
variant: "outline",
|
|
284
|
+
size: "sm",
|
|
285
|
+
onClick: () => t(!1),
|
|
286
|
+
children: "Cancel"
|
|
287
|
+
}
|
|
288
|
+
),
|
|
289
|
+
/* @__PURE__ */ e(b, { size: "sm", onClick: g, children: "Create" })
|
|
290
|
+
] })
|
|
291
|
+
] }) : /* @__PURE__ */ i("div", { className: "flex gap-2", children: [
|
|
292
|
+
/* @__PURE__ */ i(
|
|
293
|
+
"select",
|
|
294
|
+
{
|
|
295
|
+
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",
|
|
296
|
+
value: a,
|
|
297
|
+
onChange: (n) => r(n.target.value),
|
|
298
|
+
children: [
|
|
299
|
+
/* @__PURE__ */ e("option", { value: "", children: "Select a group" }),
|
|
300
|
+
l.length > 0 && /* @__PURE__ */ e("optgroup", { label: "Library Groups", children: l.map((n) => /* @__PURE__ */ e("option", { value: n.id, children: n.name }, `lib-${n.id}`)) }),
|
|
301
|
+
c.length > 0 && /* @__PURE__ */ e("optgroup", { label: "Predefined Groups", children: c.filter(
|
|
302
|
+
(n) => !l.some(
|
|
303
|
+
(N) => N.id === n.id
|
|
304
|
+
)
|
|
305
|
+
).map((n) => /* @__PURE__ */ e("option", { value: n.id, children: n.name }, `local-${n.id}`)) })
|
|
306
|
+
]
|
|
307
|
+
}
|
|
308
|
+
),
|
|
309
|
+
/* @__PURE__ */ e(
|
|
310
|
+
b,
|
|
311
|
+
{
|
|
312
|
+
type: "button",
|
|
313
|
+
size: "icon",
|
|
314
|
+
variant: "outline",
|
|
315
|
+
onClick: () => t(!0),
|
|
316
|
+
children: /* @__PURE__ */ e(pe, { className: "h-4 w-4" })
|
|
317
|
+
}
|
|
318
|
+
)
|
|
319
|
+
] });
|
|
320
|
+
}, _e = ({ value: a, onChange: r }) => {
|
|
321
|
+
const [o, t] = f(!1), u = V(null), p = be(
|
|
322
|
+
async (c) => {
|
|
323
|
+
var h;
|
|
324
|
+
const v = (h = c.target.files) == null ? void 0 : h[0];
|
|
325
|
+
if (v)
|
|
326
|
+
try {
|
|
327
|
+
t(!0);
|
|
328
|
+
let g = v;
|
|
329
|
+
v.type.startsWith("image/") && (g = await ve(v));
|
|
330
|
+
const m = new FileReader();
|
|
331
|
+
m.onloadend = () => {
|
|
332
|
+
r(m.result), t(!1);
|
|
333
|
+
}, m.readAsDataURL(g);
|
|
334
|
+
} catch (g) {
|
|
335
|
+
console.error("Error reading file:", g), t(!1), B.error("Failed to process image", {
|
|
336
|
+
description: g instanceof Error ? g.message : "Unknown error"
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
[r]
|
|
341
|
+
);
|
|
342
|
+
return /* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
343
|
+
/* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
|
|
344
|
+
/* @__PURE__ */ e(D, { type: "file", ref: u, onChange: p, accept: "image/*", className: "hidden" }),
|
|
345
|
+
/* @__PURE__ */ e(b, { type: "button", variant: "outline", onClick: () => {
|
|
346
|
+
var c;
|
|
347
|
+
(c = u.current) == null || c.click();
|
|
348
|
+
}, disabled: o, className: "w-full", children: o ? /* @__PURE__ */ i("span", { className: "flex items-center gap-2", children: [
|
|
349
|
+
/* @__PURE__ */ e("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" }),
|
|
350
|
+
"Uploading..."
|
|
351
|
+
] }) : /* @__PURE__ */ i("span", { className: "flex items-center gap-2", children: [
|
|
352
|
+
/* @__PURE__ */ e(he, { className: "h-4 w-4" }),
|
|
353
|
+
"Select image"
|
|
354
|
+
] }) }),
|
|
355
|
+
a && /* @__PURE__ */ e(b, { type: "button", variant: "outline", size: "icon", onClick: () => {
|
|
356
|
+
r(""), u.current && (u.current.value = "");
|
|
357
|
+
}, children: /* @__PURE__ */ e(fe, { className: "h-4 w-4" }) })
|
|
358
|
+
] }),
|
|
359
|
+
a && /* @__PURE__ */ e("div", { className: "aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border", children: /* @__PURE__ */ e("img", { src: a, alt: "Preview", className: "h-full w-full object-contain" }) })
|
|
360
|
+
] });
|
|
361
|
+
}, je = (a) => {
|
|
362
|
+
const { blocks: r, close: o, blockId: t } = a, { getPartailBlocks: u } = oe(), p = r.find((s) => s._id === t), d = p == null ? void 0 : p._libBlockId, l = !!d, c = S(() => r.some((s) => s._type === "PartialBlock" || s._type === "GlobalBlock"), [r]), v = S(() => {
|
|
363
|
+
let s = [];
|
|
364
|
+
for (const y of r)
|
|
365
|
+
if (y._type === "PartialBlock" || y._type === "GlobalBlock") {
|
|
366
|
+
let k = u(y.partialBlockId);
|
|
367
|
+
y._parent && (k == null ? void 0 : k.length) > 0 && (k = k.map((R) => (ye(R._parent) && ke(R, "_parent", y._parent), R))), s = [...s, ...k];
|
|
368
|
+
} else
|
|
369
|
+
s.push(y);
|
|
370
|
+
return s;
|
|
371
|
+
}, [r, u]), [h, g] = f(""), [m, n] = f(""), [N, E] = f(""), [x, A] = f(""), [C, W] = f({}), [Q, $] = f(!1), [H, q] = f(l), [X, J] = f(!1), { hasPermission: Z } = le(), ee = Z(ie.DELETE_LIBRARY_BLOCK), j = K(), te = () => {
|
|
372
|
+
j([t], { _libBlockId: void 0 }), B.success("Block delinked from library"), o();
|
|
373
|
+
}, {
|
|
374
|
+
data: I,
|
|
375
|
+
isLoading: T,
|
|
376
|
+
isError: M
|
|
377
|
+
} = Ce(d);
|
|
378
|
+
w(() => {
|
|
379
|
+
M && l && (J(!0), q(!1));
|
|
380
|
+
}, [M, l]), w(() => {
|
|
381
|
+
I && !T && (g(I.name || ""), n(I.group || ""), E(I.description || ""), A(I.preview || ""), q(!1));
|
|
382
|
+
}, [I, T]), w(() => {
|
|
383
|
+
const s = h.trim().length >= 2, y = m.trim() !== "";
|
|
384
|
+
$(s && y);
|
|
385
|
+
}, [h, m]);
|
|
386
|
+
const re = () => {
|
|
387
|
+
const s = {};
|
|
388
|
+
return h.trim() ? h.length < 2 && (s.name = "Name must be at least 2 characters") : s.name = "Name is required", m || (s.group = "Group is required"), W(s), Object.keys(s).length === 0;
|
|
389
|
+
}, { resetLibrary: ne } = ce({ id: "" }), O = Be((s) => {
|
|
390
|
+
l || j([t], { _libBlockId: s.id }), B.success(`Block ${l ? "updated" : "saved"} successfully`), ne(s.library), o();
|
|
391
|
+
}), ae = async (s) => {
|
|
392
|
+
if (s.preventDefault(), !re()) return;
|
|
393
|
+
const y = v.map((k) => (Ne(k, "_libBlockId") && delete k._libBlockId, k));
|
|
394
|
+
O.mutate({
|
|
395
|
+
name: h.trim(),
|
|
396
|
+
group: m,
|
|
397
|
+
blocks: y,
|
|
398
|
+
description: N.trim(),
|
|
399
|
+
// Only include previewImage if it exists and is a base64 image
|
|
400
|
+
...x && x.startsWith("data:") ? { previewImage: x } : {},
|
|
401
|
+
// Include id if in edit mode
|
|
402
|
+
...l ? { id: d } : {}
|
|
403
|
+
});
|
|
404
|
+
}, F = O.isPending;
|
|
405
|
+
return H || T ? /* @__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: [
|
|
406
|
+
/* @__PURE__ */ e("div", { className: "font-medium text-destructive", children: "Block Not Found" }),
|
|
407
|
+
/* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "This block could not be found on the server. It may have been deleted." }),
|
|
408
|
+
/* @__PURE__ */ i("div", { className: "flex justify-end gap-2 pt-4", children: [
|
|
409
|
+
/* @__PURE__ */ e(b, { type: "button", variant: "outline", onClick: o, children: "Cancel" }),
|
|
410
|
+
/* @__PURE__ */ e(b, { onClick: te, variant: "destructive", children: "Delink Block" })
|
|
411
|
+
] })
|
|
412
|
+
] }) : /* @__PURE__ */ i("div", { children: [
|
|
413
|
+
c && /* @__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: [
|
|
414
|
+
/* @__PURE__ */ e(ge, { className: "mt-0.5 h-5 w-5 flex-shrink-0" }),
|
|
415
|
+
/* @__PURE__ */ i("div", { children: [
|
|
416
|
+
/* @__PURE__ */ e("p", { className: "font-medium", children: "Partial Blocks Detected" }),
|
|
417
|
+
/* @__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" })
|
|
418
|
+
] })
|
|
419
|
+
] }),
|
|
420
|
+
/* @__PURE__ */ i("form", { onSubmit: ae, className: "space-y-4", children: [
|
|
421
|
+
/* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
422
|
+
/* @__PURE__ */ e(P, { htmlFor: "name", className: C.name ? "text-destructive" : "", children: "Name" }),
|
|
423
|
+
/* @__PURE__ */ e(
|
|
424
|
+
D,
|
|
425
|
+
{
|
|
426
|
+
id: "name",
|
|
427
|
+
placeholder: "Enter block name",
|
|
428
|
+
value: h,
|
|
429
|
+
onChange: (s) => g(s.target.value),
|
|
430
|
+
className: C.name ? "border-destructive" : ""
|
|
431
|
+
}
|
|
432
|
+
),
|
|
433
|
+
C.name && /* @__PURE__ */ e("p", { className: "text-xs text-destructive", children: C.name })
|
|
434
|
+
] }),
|
|
435
|
+
/* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
436
|
+
/* @__PURE__ */ e(P, { htmlFor: "group", className: C.group ? "text-destructive" : "", children: "Group" }),
|
|
437
|
+
/* @__PURE__ */ e(Pe, { value: m, onChange: n }),
|
|
438
|
+
C.group && /* @__PURE__ */ e("p", { className: "text-xs text-destructive", children: C.group })
|
|
439
|
+
] }),
|
|
440
|
+
/* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
441
|
+
/* @__PURE__ */ e(P, { htmlFor: "description", children: "Description (optional)" }),
|
|
442
|
+
/* @__PURE__ */ e(
|
|
443
|
+
D,
|
|
444
|
+
{
|
|
445
|
+
id: "description",
|
|
446
|
+
placeholder: "Enter a brief description",
|
|
447
|
+
className: "resize-none",
|
|
448
|
+
value: N,
|
|
449
|
+
onChange: (s) => E(s.target.value)
|
|
450
|
+
}
|
|
451
|
+
)
|
|
452
|
+
] }),
|
|
453
|
+
/* @__PURE__ */ i("div", { className: "space-y-2", children: [
|
|
454
|
+
/* @__PURE__ */ e(P, { htmlFor: "previewImage", children: "Preview Image (optional)" }),
|
|
455
|
+
/* @__PURE__ */ e(_e, { value: x, onChange: A })
|
|
456
|
+
] }),
|
|
457
|
+
/* @__PURE__ */ i("div", { className: "flex justify-end gap-2 pt-2", children: [
|
|
458
|
+
l && ee && /* @__PURE__ */ e(
|
|
459
|
+
Ee,
|
|
460
|
+
{
|
|
461
|
+
blockId: t,
|
|
462
|
+
libBlockId: d,
|
|
463
|
+
blockName: h,
|
|
464
|
+
className: "mr-auto",
|
|
465
|
+
close: o
|
|
466
|
+
}
|
|
467
|
+
),
|
|
468
|
+
/* @__PURE__ */ e(b, { type: "button", variant: "outline", onClick: o, disabled: F, children: "Cancel" }),
|
|
469
|
+
/* @__PURE__ */ e(b, { type: "submit", disabled: F || !Q, children: F ? "Saving..." : l ? "Update Block" : "Save Block" })
|
|
470
|
+
] })
|
|
471
|
+
] })
|
|
472
|
+
] });
|
|
473
|
+
};
|
|
474
|
+
export {
|
|
475
|
+
je as default
|
|
476
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),I=require("@tanstack/react-query"),k=require("sonner"),x=require("./index-LU0FTfeN.cjs"),E=require("@chaibuilder/sdk"),c=require("@chaibuilder/sdk/ui"),C=require("lucide-react"),i=require("react"),X=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),J=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{n(t)},onError:t=>{console.error("Error saving block:",t),k.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},Z=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useQuery({staleTime:"static",queryKey:[x.ACTIONS.GET_LIBRARY_ITEM,n],enabled:!!n,queryFn:async()=>{if(!n)return null;try{return await l(s,{action:x.ACTIONS.GET_LIBRARY_ITEM,data:{id:n}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},ee=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:t}}),onSuccess:()=>{n()},onError:t=>{console.error("Error deleting block:",t),k.toast.error("Failed to delete block",{description:t instanceof Error?t.message:"Unknown error"})}})},te=({blockId:n,libBlockId:s,isOpen:l,onClose:t,blockName:m,trigger:f})=>{const[u,o]=i.useState(!1),d=E.useUpdateBlocksPropsRealtime(),b=ee(()=>{d([n],{_libBlockId:void 0}),k.toast.success("Block deleted successfully"),o(!1),t()}),p=()=>{o(!0),b.mutate(s)},g=e.jsxs(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:h=>h.preventDefault(),disabled:u,children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]});return e.jsxs(c.Popover,{open:l,onOpenChange:h=>!h&&t(),children:[e.jsx(c.PopoverTrigger,{asChild:!0,children:f||g}),e.jsx(c.PopoverContent,{className:"w-72 p-4 z-[9999]",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:[' "',m,'"']}),"?"]}),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(c.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:p,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},se=({blockId:n,libBlockId:s,blockName:l,size:t="sm",className:m="",close:f})=>{const[u,o]=i.useState(!1);return e.jsx(te,{blockId:n,libBlockId:s,isOpen:u,onClose:()=>{o(!1),f()},blockName:l,trigger:e.jsxs(c.Button,{type:"button",variant:"destructive",size:t,className:m,onClick:()=>o(!0),children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})})},re=()=>{const n=x.useApiUrl(),s=x.useFetch(),l=I.useQueryClient(),{data:t=[],isLoading:m,error:f}=I.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await s(n,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=I.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return s(n,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),k.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),k.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:m,error:f,createGroup:u,isCreating:o}},ne=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),[m,f]=i.useState(""),u=i.useRef(null),{groups:o}=re(),[d,b]=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"}]),p=i.useMemo(()=>[...o,...d.filter(r=>!o.some(j=>j.id===r.id))],[o,d]),g=()=>{const r=m.trim();if(!r)return;const j={id:r,name:r};b(w=>[...w,j]),s(j.id),f(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const h=r=>{r.key==="Enter"&&(r.preventDefault(),g())};return i.useEffect(()=>{n&&!p.some(r=>r.id===n)&&s("")},[n,p,s]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Input,{ref:u,placeholder:"Enter new group name",value:m,onChange:r=>f(r.target.value),onKeyDown:h}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(c.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:n,onChange:r=>s(r.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(r=>e.jsx("option",{value:r.id,children:r.name},`lib-${r.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(r=>!o.some(j=>j.id===r.id)).map(r=>e.jsx("option",{value:r.id,children:r.name},`local-${r.id}`))})]}),e.jsx(c.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(C.Plus,{className:"h-4 w-4"})})]})},ae=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),m=i.useRef(null),f=i.useCallback(async d=>{var p;const b=(p=d.target.files)==null?void 0:p[0];if(b)try{t(!0);let g=b;b.type.startsWith("image/")&&(g=await X.compressImageIfNeeded(b));const h=new FileReader;h.onloadend=()=>{s(h.result),t(!1)},h.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),k.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[s]),u=()=>{s(""),m.current&&(m.current.value="")},o=()=>{var d;(d=m.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(c.Input,{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),e.jsx(c.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(C.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),n&&e.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(C.X,{className:"h-4 w-4"})})]}),n&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:n,alt:"Preview",className:"h-full w-full object-contain"})})]})},oe=n=>{const{blocks:s,close:l,blockId:t}=n,{getPartailBlocks:m}=E.usePartailBlocksStore(),f=s.find(a=>a._id===t),u=f==null?void 0:f._libBlockId,o=!!u,d=i.useMemo(()=>s.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[s]),b=i.useMemo(()=>{let a=[];for(const y of s)if(y._type==="PartialBlock"||y._type==="GlobalBlock"){let v=m(y.partialBlockId);y._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",y._parent),T))),a=[...a,...v]}else a.push(y);return a},[s,m]),[p,g]=i.useState(""),[h,r]=i.useState(""),[j,w]=i.useState(""),[S,_]=i.useState(""),[N,A]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=E.usePermissions(),Q=Y(x.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=E.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),k.toast.success("Block delinked from library"),l()},{data:B,isLoading:P,isError:G}=Z(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{B&&!P&&(g(B.name||""),r(B.group||""),w(B.description||""),_(B.preview||""),F(!1))},[B,P]),i.useEffect(()=>{const a=p.trim().length>=2,y=h.trim()!=="";M(a&&y)},[p,h]);const W=()=>{const a={};return p.trim()?p.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",h||(a.group="Group is required"),A(a),Object.keys(a).length===0},{resetLibrary:$}=E.useLibraryBlocks({id:""}),U=J(a=>{o||D([t],{_libBlockId:a.id}),k.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const y=b.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));U.mutate({name:p.trim(),group:h,blocks:y,description:j.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=U.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(c.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(c.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(C.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(c.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(c.Input,{id:"name",placeholder:"Enter block name",value:p,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(c.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ne,{value:h,onChange:r}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(c.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:j,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(ae,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(se,{blockId:t,libBlockId:u,blockName:p,className:"mr-auto",close:l}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(c.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=oe;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-LU0FTfeN.cjs"),P=require("@chaibuilder/sdk"),d=require("lodash-es"),v=require("react"),a=require("@chaibuilder/sdk/ui"),L=require("sonner"),ce=require("@tanstack/react-query"),K=require("lucide-react"),M=require("./get-seo-defaults-Cw7vFt-B.cjs"),de=()=>{const{selectedLang:t}=P.useLanguages(),{data:x,isFetching:u}=i.useLanguagePages();return{data:v.useMemo(()=>d.find(x,{lang:t||""})||{},[x,t]),isFetching:u}},ue=()=>{var p;const x=(p=document.getElementById("canvas-iframe").contentDocument)==null?void 0:p.body.innerHTML;if(!x)return null;const c=new DOMParser().parseFromString(x,"text/html");c.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(g=>g.remove()),c.querySelectorAll("*").forEach(g=>{Array.from(g.attributes).forEach(m=>g.removeAttribute(m.name))});const r=c.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(r).map(g=>`<${g.tagName.toLowerCase()}>${g.innerHTML}</${g.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},F=({keyword:t,onComplete:x,field:u})=>{const c=i.useFetch(),r=i.useApiUrl(),{selectedLang:N,fallbackLang:p}=P.useLanguages(),{mutate:g,isPending:m}=ce.useMutation({mutationFn:async()=>{const D=ue();return await c(r,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:u,lang:N||p,pageContent:D,keyword:t}})},onSuccess:D=>{x({fieldValue:D.field})},onError:D=>{x({fieldValue:null,error:D.message})}});return e.jsx(a.Button,{disabled:m,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>g(),children:m?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},ge=({isOpen:t,onClose:x,onSave:u,onDiscard:c,isSaving:r=!1,fromLanguage:N,toLanguage:p})=>{const g=i.LANGUAGES[N]||N,m=i.LANGUAGES[p]||p;return e.jsx(a.Dialog,{open:t,onOpenChange:x,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(a.DialogDescription,{children:['You have unsaved changes in the SEO for "',g,'" version. Do you want to save these changes before switching to "',m,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(a.Button,{variant:"outline",onClick:c,disabled:r,children:"Discard Changes"}),e.jsx(a.Button,{onClick:u,disabled:r,children:r?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},he=(t,x)=>{const u=t.selectionStart||0,c=t.selectionEnd||0,r=t.value,N=r.substring(0,u),p=r.substring(c),g=`{{${x}}}`,m=N+""+g+p,D=u+0+g.length;return{value:m,newCursorPos:D}},Q=()=>{const{t}=P.useTranslation(),[,x]=P.useSidebarActivePanel(),{data:u}=i.useCurrentPage(),{data:c}=i.useBuilderPageData(),{data:r,isFetching:N}=de(),p=r==null?void 0:r.seo,g=v.useRef(null),[m,D]=v.useState("seo"),R=u==null?void 0:u.id,W=u==null?void 0:u.pageType,I=i.usePageType(W),{selectedLang:$,fallbackLang:X}=P.useLanguages(),h=$||X,[H,J]=v.useState(!1),[Z,_]=v.useState(!1),[ee,V]=v.useState(!1),[S,U]=v.useState(null),[n,w]=v.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...p}),E=v.useRef({}),{mutate:se,isPending:q}=i.useUpdatePage(),f=q||H||Z,{hasPermission:te}=P.usePermissions(),o=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ae]=i.usePagesProps(),ne=d.get(ae,"features.canResetSeoToDefault",!1),z=!$||n.jsonLD!=="{}";v.useEffect(()=>{if(!N&&p&&R){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...p};w(s),E.current[h]=s}},[N,p,h,R]),v.useEffect(()=>{const s=l=>{const{fromLang:b,toLang:A,switchHandler:y}=l.detail,G=E.current[h];(G?!d.isEqual(G,n):!1)?(U({fromLang:b,toLang:A,switchHandler:y}),V(!0)):y()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[R,n,h]);const oe=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,keyword:d.get(s,"seo.keyword",""),title:d.get(s,"seo.title",""),description:d.get(s,"seo.description",""),cononicalUrl:d.get(s,"seo.canonicalUrl",""),noIndex:d.get(s,"seo.noIndex",!1),noFollow:d.get(s,"seo.noFollow",!1),ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription","")};w(l),L.toast.success(t("SEO fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{J(!1)}},le=async()=>{if(!(!I||!h))try{_(!0);const s=M.getSeoDefaults(I,h),l={...n,jsonLD:d.get(s,"seo.jsonLD","")};w(l),L.toast.success(t("JSON-LD reset to default"))}catch(s){L.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{_(!1)}},re=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription",""),ogImage:d.get(s,"seo.ogImage",""),ogImageId:d.get(s,"seo.ogImageId",""),metaOther:d.get(s,"seo.metaOther","{}")};w(l),L.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{J(!1)}},Y=async()=>{se({id:r==null?void 0:r.id,seo:n,primaryPage:R},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",n),E.current[h]=n,L.toast.success("SEO & JSON-LD updated successfully")}})},O=(s,l)=>{const b=document.getElementById(l);if(b){const{value:A,newCursorPos:y}=he(b,s);g.current={id:l,position:y},b.tagName.toLowerCase()==="input"?(b.value=A,w(C=>({...C,[b.name]:A})),b.focus(),b.setSelectionRange(y,y),[0,10,50,100,200].forEach(C=>{setTimeout(()=>{const B=document.getElementById(l);B&&(B.focus(),B.setSelectionRange(y,y))},C)})):(w(T=>({...T,[b.name]:A})),requestAnimationFrame(()=>{const T=document.getElementById(l);T&&(T.focus(),T.setSelectionRange(y,y),setTimeout(()=>{const C=document.getElementById(l);C&&(C.focus(),C.setSelectionRange(y,y))},50))}))}},j=s=>{const l={...n,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};w(l)},k=s=>l=>{d.isEmpty(l.fieldValue)||j({target:{name:s,value:typeof l.fieldValue=="string"?l.fieldValue.replace(/^"(.*)"$/,"$1"):l.fieldValue}}),l.error&&L.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:l.error})]}))},ie=()=>{const s=d.get(u,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){L.toast.error("Default page JSON-LD is empty");return}j({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!o&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(a.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(a.AlertDescription,{children:t("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),e.jsxs("div",{className:"no-scrollbar flex-grow overflow-y-auto px-2 pb-20",children:[e.jsxs("div",{className:"mb-4 flex w-full items-center justify-between rounded-md bg-gray-100 px-2 py-1 text-left text-sm",children:[e.jsxs("span",{children:[e.jsx("div",{className:"font-medium",children:r==null?void 0:r.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:r==null?void 0:r.slug})]}),e.jsx(i.LanguageSwitcher,{variant:"outline",showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(a.Tabs,{value:m,onValueChange:D,className:"w-full",children:[e.jsxs(a.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(a.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(a.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(a.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:m==="seo"?"":"sr-only",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"keyword")})]}),e.jsx(a.Input,{type:"text",id:"keyword",name:"keyword",value:n.keyword,onChange:j,disabled:f||!o,placeholder:t("Enter keyword"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("title"),field:"title"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"title")})]})]}),e.jsx(a.Input,{type:"text",id:"title",name:"title",value:n.title,onChange:j,disabled:f||!o,placeholder:t("Enter SEO title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("description"),field:"description"}),o&&e.jsx(i.NestedPathSelector,{data:c??{},onSelect:s=>O(s,"description")})]})]}),e.jsx(a.Textarea,{id:"description",name:"description",rows:5,value:n.description,onChange:j,disabled:f||!o,placeholder:t("Enter SEO description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"canonicalUrl")})]}),e.jsx(a.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:j,disabled:f||!o,placeholder:t("Enter Canonical URL"),readOnly:!o})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Index")})]}),e.jsx("p",{className:"mt-0 text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to index this page.")})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Follow")})]}),e.jsx("p",{className:"text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to follow links on this page.")})]})]})}),e.jsx("div",{className:m==="opengraph"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"mb-4 font-semibold text-slate-700",children:t("Open Graph")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogTitle"),field:"ogTitle"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogTitle")})]})]}),e.jsx(a.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:j,disabled:f||!o,placeholder:t("Enter OG title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogDescription"),field:"ogDescription"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogDescription")})]})]}),e.jsx(a.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:n.ogDescription,onChange:j,disabled:f||!o,placeholder:t("Enter OG description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>{w({...n,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:n.ogImageId,assetUrl:n.ogImage,onChange:s=>{w({...n,ogImage:s.url,ogImageId:s.id})},disabled:f||!o,placeholder:t("Select OG image"),className:"mb-2"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:n.metaOther,onChange:s=>{j({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:8,handleFieldInsert:O})]})]})]})})}),e.jsx("div",{className:m==="jsonld"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),z&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(c)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:n.jsonLD,onChange:s=>{j({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:12,handleFieldInsert:O,hasJsonLdForSelectedLang:z,copyJsonLDFromDefaultPage:ie})]})})})]})})]}),o&&e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 flex w-full flex-shrink-0 items-center justify-between border-t bg-background p-4",children:[ne?e.jsx(a.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{m==="jsonld"?le():m==="opengraph"?re():oe()},disabled:f||!o||!I,children:t(H?"Resetting...":`Reset to ${m==="jsonld"?"Default JSON-LD":m==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(a.Button,{onClick:Y,disabled:!me(n==null?void 0:n.jsonLD)||(E.current[h]?d.isEqual(E.current[h],n):!1)||f||!o,children:t(q?"Saving...":"Save")}),e.jsx(a.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>x("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{V(!1),U(null)},onSave:async()=>{S&&(await Y(),S.switchHandler(),V(!1),U(null))},onDiscard:()=>{if(S){const s=E.current[h];s&&w(s),S.switchHandler(),V(!1),U(null)}},isSaving:q,fromLanguage:(S==null?void 0:S.fromLang)||h,toLanguage:(S==null?void 0:S.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;
|