@chaibuilder/pages 0.13.4 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/{2AITGKQY-Dx_Cte-P.js → 2AITGKQY-Cti4x7QE.js} +5 -5
  2. package/dist/{2AITGKQY-DpAgk_u8.cjs → 2AITGKQY-PHs1xUsz.cjs} +1 -1
  3. package/dist/{NCMVHL6D-B6lv7Umq.cjs → NCMVHL6D-BChQ0wDN.cjs} +1 -1
  4. package/dist/{NCMVHL6D-CT2qHOTS.js → NCMVHL6D-fAWarBw8.js} +4 -4
  5. package/dist/{ZDWCUMSJ-C1vrgsti.cjs → ZDWCUMSJ-CwWfQqyn.cjs} +1 -1
  6. package/dist/{ZDWCUMSJ-W9xywtZH.js → ZDWCUMSJ-DRWuu_nE.js} +1 -1
  7. package/dist/add-new-language-page-CcBqDtYv.js +390 -0
  8. package/dist/add-new-language-page-Dt9DWunK.cjs +1 -0
  9. package/dist/add-new-page-BN3z9rSq.cjs +1 -0
  10. package/dist/add-new-page-CTUiEKzv.js +30 -0
  11. package/dist/confetti.module-BuUnQuWk.cjs +2 -0
  12. package/dist/confetti.module-DCmCkDyV.js +409 -0
  13. package/dist/delete-page-8MnGZ_mz.js +38 -0
  14. package/dist/delete-page-jELwTpGY.cjs +1 -0
  15. package/dist/digital-asset-manager-BJhwyEdT.js +976 -0
  16. package/dist/digital-asset-manager-ZyQJP6AO.cjs +1 -0
  17. package/dist/duplicate-page-BGYZLkco.js +120 -0
  18. package/dist/duplicate-page-BRjKFpBP.cjs +1 -0
  19. package/dist/dynamic-page-selector-CR-ZpSJ8.cjs +1 -0
  20. package/dist/dynamic-page-selector-CrbujoYg.js +86 -0
  21. package/dist/get-seo-defaults-9zHebckY.js +65 -0
  22. package/dist/get-seo-defaults-Cw7vFt-B.cjs +1 -0
  23. package/dist/image-compression-DZ9WMmyn.cjs +1 -0
  24. package/dist/image-compression-DsZ1oqpb.js +37 -0
  25. package/dist/index-Byi6-4u1.js +5164 -0
  26. package/dist/index-DSUpSpeI.cjs +5 -0
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.d.ts +4 -22
  29. package/dist/index.js +18 -19
  30. package/dist/json-diff-viewer-DKlC7yl6.cjs +8 -0
  31. package/dist/json-diff-viewer-De2bStRw.js +258 -0
  32. package/dist/lang-panel-B3bC1gKq.cjs +1 -0
  33. package/dist/lang-panel-G7RoMOP7.js +218 -0
  34. package/dist/mark-as-template-B1TpGPms.js +146 -0
  35. package/dist/mark-as-template-OgR8I38n.cjs +1 -0
  36. package/dist/nested-path-selector-content-D_iF9Sm3.cjs +1 -0
  37. package/dist/nested-path-selector-content-DvIL_EoN.js +87 -0
  38. package/dist/no-language-page-content-CqH4FMNy.js +35 -0
  39. package/dist/no-language-page-content-iZo2ztXp.cjs +1 -0
  40. package/dist/page-creator-Chnj3W4j.js +796 -0
  41. package/dist/page-creator-DUXzx-zg.cjs +1 -0
  42. package/dist/page-lock-request-D3gmV8Yq.cjs +1 -0
  43. package/dist/page-lock-request-Dc-JkLEZ.js +64 -0
  44. package/dist/page-locked-by-dialog-B9pGi6zb.cjs +1 -0
  45. package/dist/page-locked-by-dialog-DC8UKy9e.js +63 -0
  46. package/dist/page-manager-new-CFtYUNbS.cjs +1 -0
  47. package/dist/page-manager-new-DYYWpxWy.js +354 -0
  48. package/dist/page-manager-search-and-filter-B4xo9IJO.js +197 -0
  49. package/dist/page-manager-search-and-filter-DT9V9AoS.cjs +1 -0
  50. package/dist/page-revisions-content-BjIECUPY.cjs +1 -0
  51. package/dist/page-revisions-content-KJGhm9Pl.js +446 -0
  52. package/dist/publish-pages-content-BWLQZGjd.js +178 -0
  53. package/dist/publish-pages-content-CTduLNtg.cjs +1 -0
  54. package/dist/save-to-lib-B07GbG4I.js +476 -0
  55. package/dist/save-to-lib-CsrSeusU.cjs +1 -0
  56. package/dist/seo-panel-B20DCgo0.js +667 -0
  57. package/dist/seo-panel-QphuqXT2.cjs +1 -0
  58. package/dist/shared-json-ld-C_vIO-Qk.cjs +1 -0
  59. package/dist/shared-json-ld-CkOQRUEw.js +337 -0
  60. package/dist/slug-input-71BuN79c.cjs +1 -0
  61. package/dist/slug-input-rAe3mMkd.js +87 -0
  62. package/dist/theme-panel-footer-DFUfCqKP.js +25 -0
  63. package/dist/theme-panel-footer-DHRs6ag2.cjs +1 -0
  64. package/dist/translation-warning-modal-DalBhNQy.js +26 -0
  65. package/dist/translation-warning-modal-Kctu12rQ.cjs +1 -0
  66. package/dist/unmark-as-template-Cx0CqrpM.cjs +1 -0
  67. package/dist/unmark-as-template-_VyWoVNk.js +38 -0
  68. package/dist/unpublish-page-CuSJRr5c.js +26 -0
  69. package/dist/unpublish-page-D3NM8b3u.cjs +1 -0
  70. package/dist/use-page-expand-manager-MjYZ3CDZ.cjs +1 -0
  71. package/dist/use-page-expand-manager-_msrWd0a.js +85 -0
  72. package/dist/web-preview-BL-vsgoa.js +73 -0
  73. package/dist/web-preview-CI3Vz7Yp.cjs +1 -0
  74. package/package.json +1 -1
  75. package/dist/index-C4j31Yhz.js +0 -11471
  76. package/dist/index-DnjETHks.cjs +0 -6
  77. package/dist/page-revisions-content-Gx-Qf_91.cjs +0 -8
  78. 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 { ak as L, al as G, A as _, aw as ie } from "./index-Byi6-4u1.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 I, 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
+ }, we = (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
+ }, Ie = ({
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 = we(() => {
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
+ Ie,
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
+ I(() => {
261
+ o && d.current && d.current.focus();
262
+ }, [o]);
263
+ const m = (n) => {
264
+ n.key === "Enter" && (n.preventDefault(), g());
265
+ };
266
+ return I(() => {
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
+ }, Me = (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), M = K(), te = () => {
372
+ M([t], { _libBlockId: void 0 }), B.success("Block delinked from library"), o();
373
+ }, {
374
+ data: w,
375
+ isLoading: T,
376
+ isError: O
377
+ } = Ce(d);
378
+ I(() => {
379
+ O && l && (J(!0), q(!1));
380
+ }, [O, l]), I(() => {
381
+ w && !T && (g(w.name || ""), n(w.group || ""), E(w.description || ""), A(w.preview || ""), q(!1));
382
+ }, [w, T]), I(() => {
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: "" }), j = Be((s) => {
390
+ l || M([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
+ j.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 = j.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
+ Me 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-DSUpSpeI.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;