@chaibuilder/pages 0.15.24 → 0.16.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 (84) hide show
  1. package/dist/{2AITGKQY-wLnL_T-W.cjs → 2AITGKQY-CD9A6oc6.cjs} +1 -1
  2. package/dist/{2AITGKQY-B6ojx8vV.js → 2AITGKQY-Z1XcJ6Q7.js} +2 -2
  3. package/dist/{NCMVHL6D-DGH2CRR6.cjs → NCMVHL6D-CkpM-3og.cjs} +1 -1
  4. package/dist/{NCMVHL6D-vsNnIwmV.js → NCMVHL6D-DoK0XoIo.js} +4 -4
  5. package/dist/{ZDWCUMSJ-3BnFdOH2.cjs → ZDWCUMSJ-D32swpGV.cjs} +1 -1
  6. package/dist/{ZDWCUMSJ-CoYx1TP5.js → ZDWCUMSJ-hGXNxbOK.js} +1 -1
  7. package/dist/{add-new-language-page-d0-cAxlt.js → add-new-language-page-BZPoqdX-.js} +2 -2
  8. package/dist/{add-new-language-page-VDZSKD95.cjs → add-new-language-page-D65TpIwK.cjs} +1 -1
  9. package/dist/{add-new-page-D4IkZL8h.cjs → add-new-page-CQ0aj4RJ.cjs} +1 -1
  10. package/dist/{add-new-page-Bcoxw6U5.js → add-new-page-DK25Y0zS.js} +1 -1
  11. package/dist/ai-panel-content-BSGJqnTM.cjs +1 -0
  12. package/dist/ai-panel-content-DYRZnMgV.js +52 -0
  13. package/dist/ai-panel-default-lang-BOZrL5Xe.cjs +1 -0
  14. package/dist/ai-panel-default-lang-DZUqC79y.js +173 -0
  15. package/dist/ai-panel-message-bubble-Bl-aUeU4.cjs +1 -0
  16. package/dist/ai-panel-message-bubble-DPAaAMAZ.js +38 -0
  17. package/dist/ai-panel-other-lang-CCyiE6ha.js +145 -0
  18. package/dist/ai-panel-other-lang-CNtlT5dM.cjs +1 -0
  19. package/dist/ai-panel-quick-prompts-DeS7L1f0.cjs +1 -0
  20. package/dist/ai-panel-quick-prompts-Ds0Ndz7g.js +46 -0
  21. package/dist/ai-prompt-input-Ch_PLEPN.js +133 -0
  22. package/dist/ai-prompt-input-Zg6lN1Lo.cjs +1 -0
  23. package/dist/ai-translation-prompt-BUFjo_om.cjs +1 -0
  24. package/dist/ai-translation-prompt-BiJ5B_an.js +28 -0
  25. package/dist/{delete-page-KS6p6b8f.js → delete-page-B95T2Prd.js} +1 -1
  26. package/dist/{delete-page-DeKAD4Ld.cjs → delete-page-BSop1jNg.cjs} +1 -1
  27. package/dist/{digital-asset-manager-Dfe9SS09.js → digital-asset-manager-BQNSwfKs.js} +1 -1
  28. package/dist/{digital-asset-manager-C9gYL2SF.cjs → digital-asset-manager-Bn58WzM6.cjs} +1 -1
  29. package/dist/{duplicate-page-CKr-HNs-.cjs → duplicate-page-BLxkSiug.cjs} +1 -1
  30. package/dist/{duplicate-page-vCgYnw4H.js → duplicate-page-CrzzObAj.js} +9 -9
  31. package/dist/{dynamic-page-selector-A4fqWqZZ.js → dynamic-page-selector-D6wQnNfH.js} +1 -1
  32. package/dist/{dynamic-page-selector-C7w3TOdK.cjs → dynamic-page-selector-D8UZ63LW.cjs} +1 -1
  33. package/dist/index-W0r4o5Ro.cjs +5 -0
  34. package/dist/{index-NSqs69Op.js → index-yhKyIbgs.js} +1035 -1031
  35. package/dist/index.cjs +1 -1
  36. package/dist/index.d.ts +5 -3
  37. package/dist/index.js +7 -7
  38. package/dist/{json-diff-viewer-7TGemUrn.js → json-diff-viewer-ISJS7lHK.js} +1 -1
  39. package/dist/{json-diff-viewer-nLLX6kJK.cjs → json-diff-viewer-ZeJ3Rp2y.cjs} +1 -1
  40. package/dist/{lang-panel-C6KxjKn_.js → lang-panel-Bj11IL7k.js} +33 -33
  41. package/dist/{lang-panel-dc9uBMtE.cjs → lang-panel-DqN_J3vz.cjs} +1 -1
  42. package/dist/{mark-as-template-CJ9SiEBl.cjs → mark-as-template-CcwAAdrd.cjs} +1 -1
  43. package/dist/{mark-as-template-CRUOQ_FZ.js → mark-as-template-CmCCMaQg.js} +1 -1
  44. package/dist/{no-language-page-content--8a37nsW.cjs → no-language-page-content-BXm1k1Aa.cjs} +1 -1
  45. package/dist/{no-language-page-content-ByHFQjkV.js → no-language-page-content-Cme-zo4R.js} +1 -1
  46. package/dist/{page-creator-CzUQicdh.cjs → page-creator-ByhjXyHP.cjs} +1 -1
  47. package/dist/{page-creator-J_CNgdj5.js → page-creator-Zbv4d4H8.js} +2 -2
  48. package/dist/{page-lock-request-BE9-Oego.cjs → page-lock-request-Cln-EE6Z.cjs} +1 -1
  49. package/dist/{page-lock-request-CD93n5pq.js → page-lock-request-DDQJb8IA.js} +10 -10
  50. package/dist/{page-locked-by-dialog-1Lm9dcT6.cjs → page-locked-by-dialog-BIXYITEu.cjs} +1 -1
  51. package/dist/{page-locked-by-dialog-noDLCQWF.js → page-locked-by-dialog-Csn56a3n.js} +1 -1
  52. package/dist/{page-manager-new-BoTBCqZF.cjs → page-manager-new-BJaTBpih.cjs} +1 -1
  53. package/dist/{page-manager-new-D-U4B9y9.js → page-manager-new-BrRxZDfT.js} +67 -67
  54. package/dist/{page-manager-search-and-filter-BJmETYq-.cjs → page-manager-search-and-filter-Bk3PUjha.cjs} +1 -1
  55. package/dist/{page-manager-search-and-filter-h-YzJVcH.js → page-manager-search-and-filter-_Hvk3bU3.js} +1 -1
  56. package/dist/{page-revisions-content-C7DXjFls.js → page-revisions-content-B6fRCBX_.js} +10 -10
  57. package/dist/{page-revisions-content-BNBb2qYh.cjs → page-revisions-content-C_Ha3tFu.cjs} +1 -1
  58. package/dist/prompt-helper-Csgu8Rfb.js +187 -0
  59. package/dist/prompt-helper-DgI1lgGV.cjs +51 -0
  60. package/dist/{publish-pages-content-DAKh_sSW.js → publish-pages-content-CFEIxKQD.js} +2 -2
  61. package/dist/{publish-pages-content-DsOVOiBD.cjs → publish-pages-content-DQDNxwHD.cjs} +1 -1
  62. package/dist/{save-to-lib-BR1Qhw3Q.cjs → save-to-lib-Bl22umTa.cjs} +1 -1
  63. package/dist/{save-to-lib-BPR_--qN.js → save-to-lib-YyYkF6c6.js} +1 -1
  64. package/dist/{seo-panel-C7XC-XRg.js → seo-panel-BZlMea1L.js} +1 -1
  65. package/dist/{seo-panel-CUqtdGoF.cjs → seo-panel-BhxikAkG.cjs} +1 -1
  66. package/dist/server.cjs +241 -1
  67. package/dist/server.d.ts +50 -6
  68. package/dist/server.js +10327 -290
  69. package/dist/{shared-json-ld-CDffP4G3.cjs → shared-json-ld-BfkH76U3.cjs} +1 -1
  70. package/dist/{shared-json-ld-0JD8sokD.js → shared-json-ld-E4Ckwlbr.js} +41 -41
  71. package/dist/{slug-input-BYH90lv1.cjs → slug-input--VmQG0S1.cjs} +1 -1
  72. package/dist/{slug-input-CvIDihGn.js → slug-input-CKKkqGj4.js} +1 -1
  73. package/dist/{theme-panel-footer-DPpLzCDu.js → theme-panel-footer-2ERfMsET.js} +1 -1
  74. package/dist/{theme-panel-footer-CUSfduTK.cjs → theme-panel-footer-CagxEZEO.cjs} +1 -1
  75. package/dist/{unmark-as-template-CjqRfFDL.js → unmark-as-template-BJ5CTNAe.js} +1 -1
  76. package/dist/{unmark-as-template-Bxw4t_Xi.cjs → unmark-as-template-CeWpo9wD.cjs} +1 -1
  77. package/dist/{unpublish-page-BjiB3d7l.cjs → unpublish-page-DmZSVxFj.cjs} +1 -1
  78. package/dist/{unpublish-page-CKKU1St1.js → unpublish-page-DvOWVBIf.js} +1 -1
  79. package/dist/{web-preview-D0OpieXz.js → web-preview-DTkIggV7.js} +1 -1
  80. package/dist/{web-preview-CNMYCWxW.cjs → web-preview-DlSKpPUZ.cjs} +1 -1
  81. package/package.json +3 -3
  82. package/dist/ai-panel-content-Cn3SA_Sr.cjs +0 -46
  83. package/dist/ai-panel-content-qmOJKjkE.js +0 -524
  84. package/dist/index-LfuCMBwI.cjs +0 -5
@@ -1,524 +0,0 @@
1
- import { jsxs as m, Fragment as V, jsx as r } from "react/jsx-runtime";
2
- import { mergeClasses as ae, useAddBlock as oe, useRemoveBlocks as se, useSelectedBlock as le, useBlocksStore as ie, useLanguages as ce, getBlocksFromHTML as de } from "@chaibuilder/sdk";
3
- import { Button as me } from "@chaibuilder/sdk/ui";
4
- import { find as J, get as B, map as ue } from "lodash-es";
5
- import { ChevronsUpDown as pe, Plus as he, Bot as fe, CheckCircle as ge, X as be, Paperclip as xe, Square as ye, Send as ve, Loader as Q } from "lucide-react";
6
- import { useState as C, useRef as O, useEffect as W } from "react";
7
- import { toast as K } from "sonner";
8
- import { L as we } from "./index-NSqs69Op.js";
9
- const X = [
10
- "Box",
11
- "Button",
12
- "Heading",
13
- "Paragraph",
14
- "Text",
15
- "Span",
16
- "Link",
17
- "Image",
18
- "Video",
19
- "Icon",
20
- "List",
21
- "ListItem",
22
- "Row",
23
- "Column",
24
- "Form",
25
- "Input",
26
- "FormButton",
27
- "Checkbox",
28
- "Radio",
29
- "Select",
30
- "TextArea",
31
- "Label",
32
- "RichText",
33
- "Divider",
34
- "EmptyBox",
35
- "LineBreak",
36
- "Table",
37
- "EmptySlot"
38
- ];
39
- function Ne(t) {
40
- if (!t) return "";
41
- let e = t.trim();
42
- return e = e.replace(/^```html\n?/i, ""), e = e.replace(/^```\n?/, ""), e = e.replace(/\n?```$/, ""), e = e.trim(), e;
43
- }
44
- function Ce(t) {
45
- if (!t) return "";
46
- const e = Ne(t);
47
- return e.length === 0 || !e.includes("<") || !e.includes(">") ? "" : e;
48
- }
49
- const Y = (t) => {
50
- const e = document.getElementById("canvas-iframe");
51
- if (!e) return null;
52
- const n = e == null ? void 0 : e.contentDocument;
53
- if (!n) return null;
54
- const l = n.querySelector(`[data-block-id="${t}"]`);
55
- if (!l) return null;
56
- if (t === "canvas") {
57
- const a = n.createElement("div");
58
- return a.style.height = "100vh", l.appendChild(a), a;
59
- }
60
- return l;
61
- }, Se = (t, e) => {
62
- var y;
63
- const n = Y(t);
64
- if (!n) return { position: 0, currentHTML: "" };
65
- n.style.opacity = "0.9";
66
- const l = ((y = n == null ? void 0 : n.parentNode) == null ? void 0 : y.childNodes) || [], a = Array.from(l).indexOf(n), h = n.outerHTML, u = new DOMParser().parseFromString(h, "text/html");
67
- return u.querySelectorAll("[data-block-id]").forEach((s) => {
68
- const v = s.getAttribute("data-block-id"), c = J(e, { _id: v }), S = c == null ? void 0 : c._type;
69
- if (X.includes(S)) {
70
- const p = JSON.stringify(c);
71
- if (p != null && p.includes("{{") && (p != null && p.includes("}}"))) {
72
- const w = Object.keys(c).filter((k) => {
73
- const o = c[k], b = typeof o == "string" ? o : JSON.stringify(o);
74
- return b.includes("{{") && b.includes("}}");
75
- });
76
- w.length > 0 && (s.setAttribute("data-binding-key", w[0]), s.innerHTML = B(c, w[0], ""));
77
- }
78
- s.removeAttribute("data-block-type"), s.removeAttribute("data-style-prop"), s.removeAttribute("data-block-parent"), s.removeAttribute("data-style-id"), s.removeAttribute("data-block-id"), s.removeAttribute("data-block-index"), s.removeAttribute("data-highlighted");
79
- } else
80
- s.innerHTML = S;
81
- }), { position: a, currentHTML: u.body.innerHTML };
82
- };
83
- function Te({
84
- userInput: t,
85
- language: e = "en",
86
- currentHtml: n
87
- }) {
88
- const l = we[e] || "English";
89
- return n && n.trim().length > 0 ? `
90
- MODE: EDIT
91
- CURRENT HTML:
92
- ${n}
93
-
94
- USER REQUEST: ${t}
95
-
96
- EDIT MODE INSTRUCTIONS:
97
- - Modify the existing HTML based on the user's request
98
- - IMPORTANT: If asked for updating content, do not change layout just update same HTML with updated content
99
- - CRITICAL: THINGS TO PREVENT
100
- - Preserve ALL data binding placeholders in format '{{dataBindingId}}' - never remove or modify these dynamic content markers
101
- - Preserve html tag with attributes data-block-type="PartialBlock" or data-block-type="CustomBlock" - never remove or modify these tag
102
- - Preserve the overall structure unless specifically asked to change it
103
- - Update content, styling, or layout as requested
104
- - Maintain responsive design and accessibility
105
- - Keep using shadcn/ui theme classes and Tailwind CSS
106
- - Ensure all chai-name attributes remain descriptive and accurate
107
- - Generate content in specified language: ${l}
108
- - Apply the same design principles from the system prompt
109
- - Make sure the edited HTML is clean and semantic`.trim() : `
110
- USER REQUEST: ${t}
111
-
112
- CREATE MODE INSTRUCTIONS:
113
- - Generate complete HTML structure based on user request
114
- - Use creative, modern, and responsive design
115
- - Apply Tailwind CSS v3+ classes exclusively
116
- - Follow shadcn/ui design patterns and theming
117
- - Include proper accessibility attributes
118
- - Add chai-name attributes to all wrapper/container elements
119
- - Use semantic HTML structure
120
- - Generate contextually appropriate content in ${l}
121
- - Make each element unique and meaningful
122
- - Create realistic, professional content that fits the request
123
- - Avoid generic placeholder text
124
- - Use strategic image placement where appropriate
125
- - Ensure mobile-first responsive design
126
- - Apply proper hover and focus states
127
-
128
- DESIGN REQUIREMENTS:
129
- - Choose creative layout patterns that are visually striking
130
- - Apply modern spacing and typography
131
- - Use proper color contrast with shadcn/ui theme classes
132
- - Make it responsive across all device sizes
133
- - Include interactive elements with proper states
134
- - Ensure accessibility compliance`.trim();
135
- }
136
- const ke = [
137
- {
138
- label: "Navbar",
139
- prompt: "Create stunning, fully responsive navbar with"
140
- },
141
- {
142
- label: "Hero section",
143
- prompt: "Create visually compelling hero section with"
144
- },
145
- {
146
- label: "Features grid",
147
- prompt: "Create comprehensive features section with"
148
- },
149
- {
150
- label: "Contact form",
151
- prompt: "Create professional contact form with"
152
- },
153
- {
154
- label: "Testimonials",
155
- prompt: "Create engaging testimonials section with"
156
- },
157
- {
158
- label: "Pricing table",
159
- prompt: "Create modern pricing table with"
160
- },
161
- {
162
- label: "FAQ section",
163
- prompt: "Create informative FAQ section with"
164
- },
165
- {
166
- label: "Footer",
167
- prompt: "Create comprehensive footer section with"
168
- },
169
- {
170
- label: "Call to action",
171
- prompt: "Create compelling call to action section with"
172
- },
173
- {
174
- label: "Team section",
175
- prompt: "Create professional team section with"
176
- },
177
- {
178
- label: "Blog grid",
179
- prompt: "Create attractive blog grid section with"
180
- },
181
- {
182
- label: "Stats section",
183
- prompt: "Create impactful statistics section with"
184
- }
185
- ], Ee = [
186
- {
187
- label: "Update styles",
188
- prompt: "Update styles"
189
- },
190
- {
191
- label: "Update content",
192
- prompt: "Update text content"
193
- },
194
- {
195
- label: "Update layout",
196
- prompt: "Update layout"
197
- },
198
- {
199
- label: "Improve content",
200
- prompt: "Improve text content grammar and spelling"
201
- },
202
- {
203
- label: "Make content longer",
204
- prompt: "Make text content longer"
205
- },
206
- {
207
- label: "Make content shorter",
208
- prompt: "Make text content shorter"
209
- },
210
- {
211
- label: "Fix grammar",
212
- prompt: "Fix grammar of the text content"
213
- }
214
- ], Me = ({ onSelect: t, currentBlock: e, selectedImage: n }) => {
215
- const [l, a] = C(!1), h = e ? Ee : ke;
216
- return /* @__PURE__ */ m(V, { children: [
217
- /* @__PURE__ */ m(
218
- "div",
219
- {
220
- onClick: () => a(!l),
221
- className: ae(
222
- "flex h-6 w-full cursor-pointer items-center justify-between gap-2 px-2",
223
- e ? "bg-green-50/80 text-green-500 hover:bg-green-50" : "text-primary hover:bg-primary/5"
224
- ),
225
- children: [
226
- /* @__PURE__ */ r("span", { className: "truncate whitespace-nowrap text-xs font-medium leading-none", children: n ? "Image actions" : e ? "Edit : " + (e._name || e._type) : "Quick Prompts" }),
227
- /* @__PURE__ */ r(pe, { className: "h-3 w-3" })
228
- ]
229
- }
230
- ),
231
- l && /* @__PURE__ */ r("div", { className: "max-h-60 w-full overflow-y-auto bg-white px-1 pb-1", children: h.map((x, u) => /* @__PURE__ */ r(
232
- "div",
233
- {
234
- className: "flex cursor-pointer items-center gap-x-1 p-1 text-xs leading-none hover:text-blue-700",
235
- onClick: () => {
236
- t(`${n || e ? "Update" : "Add New"} ${x.label}`, x.prompt), a(!1);
237
- },
238
- children: /* @__PURE__ */ m("span", { className: "truncate whitespace-nowrap", children: [
239
- e ? null : /* @__PURE__ */ r("span", { className: "font-thin text-muted-foreground", children: "Add New" }),
240
- " ",
241
- x.label
242
- ] })
243
- },
244
- u
245
- )) })
246
- ] });
247
- }, Ae = ({ message: t }) => {
248
- var e;
249
- return ((e = t == null ? void 0 : t.content) == null ? void 0 : e.length) < 100 ? /* @__PURE__ */ r("div", { className: "relative z-50 mb-3 flex w-full flex-col gap-2 overflow-hidden", children: /* @__PURE__ */ m("div", { className: "flex w-max items-center justify-center gap-1 rounded-md p-1 px-2 text-xs font-medium text-blue-500", children: [
250
- /* @__PURE__ */ r(Q, { className: "h-3 w-3 animate-spin" }),
251
- " Processing"
252
- ] }) }) : /* @__PURE__ */ r("div", { className: "relative z-50 mb-3 flex w-full flex-col gap-2 overflow-hidden", children: /* @__PURE__ */ m("div", { className: "flex w-max items-center justify-center gap-1 rounded-md p-1 px-2 text-xs font-medium text-blue-500", children: [
253
- /* @__PURE__ */ r(Q, { className: "h-3 w-3 animate-spin" }),
254
- " Generating"
255
- ] }) });
256
- }, Ie = ({ message: t, isUser: e, isLoading: n }) => e ? /* @__PURE__ */ r("div", { className: "relative mb-3 flex w-full justify-end overflow-hidden", children: /* @__PURE__ */ r(
257
- "div",
258
- {
259
- className: "flex max-w-[95%] flex-row-reverse rounded-lg rounded-br-sm bg-blue-500 px-2 py-1.5 text-xs text-white",
260
- children: t.userMessage
261
- }
262
- ) }) : n ? /* @__PURE__ */ r(Ae, { message: t }) : /* @__PURE__ */ r(
263
- "div",
264
- {
265
- className: `relative mb-3 flex w-full overflow-hidden ${e ? "justify-end" : n ? "max-h-48 min-h-24 justify-start" : "max-h-16"}`,
266
- children: /* @__PURE__ */ m("div", { className: "flex w-max items-center justify-center gap-1 rounded-md p-1 px-2 text-xs font-medium text-green-500", children: [
267
- /* @__PURE__ */ r(ge, { className: "h-3 w-3" }),
268
- " Completed"
269
- ] })
270
- }
271
- ), Re = ({
272
- input: t,
273
- setInput: e,
274
- onSend: n,
275
- onStop: l,
276
- isLoading: a,
277
- disabled: h,
278
- currentBlock: x
279
- }) => {
280
- const u = O(null), y = O(null), [s, v] = C(null), c = (o) => {
281
- o.key === "Enter" && !o.shiftKey && (o.preventDefault(), t.trim() && !a && (n(t == null ? void 0 : t.trim(), void 0, s || void 0), v(null)));
282
- }, S = () => {
283
- const o = u.current;
284
- o && (o.style.height = "auto", o.style.height = Math.min(o.scrollHeight, 120) + "px");
285
- }, p = (o) => {
286
- var N;
287
- const b = (N = o.target.files) == null ? void 0 : N[0];
288
- if (b && b.type.startsWith("image/")) {
289
- const M = new FileReader();
290
- M.onload = (U) => {
291
- var i, f;
292
- const H = (i = U.target) == null ? void 0 : i.result;
293
- v(H), e("Generate UI based on given image "), (f = u.current) == null || f.focus();
294
- }, M.readAsDataURL(b);
295
- }
296
- o.target.value = "";
297
- }, w = () => {
298
- var o;
299
- (o = y.current) == null || o.click();
300
- }, k = () => {
301
- n(t == null ? void 0 : t.trim(), void 0, s || void 0), v(null);
302
- };
303
- return W(() => {
304
- S();
305
- }, [t]), /* @__PURE__ */ m("div", { children: [
306
- !s && /* @__PURE__ */ r(
307
- "div",
308
- {
309
- className: `mx-auto flex w-full max-w-[95%] flex-col items-center overflow-hidden rounded-t-md border-x border-t border-gray-200 bg-gray-100 ${a ? "pointer-events-none opacity-50" : ""}`,
310
- children: /* @__PURE__ */ r(
311
- Me,
312
- {
313
- currentBlock: x,
314
- selectedImage: s,
315
- onSelect: (o, b) => {
316
- var N;
317
- e(b + " "), (N = u.current) == null || N.focus();
318
- }
319
- }
320
- )
321
- }
322
- ),
323
- /* @__PURE__ */ m("div", { className: "rounded-lg border border-gray-200 bg-white", children: [
324
- s && /* @__PURE__ */ m("div", { className: "relative flex w-max items-center justify-start gap-x-2 px-2 pt-2", children: [
325
- /* @__PURE__ */ r("img", { src: s, alt: "Selected attachment", className: "max-h-16 max-w-full rounded-md border" }),
326
- /* @__PURE__ */ r(
327
- "button",
328
- {
329
- onClick: () => v(null),
330
- className: "absolute -right-0 -top-0 flex items-center rounded-full bg-red-400 p-1 text-xs text-white hover:bg-red-500",
331
- title: "Remove image",
332
- children: /* @__PURE__ */ r(be, { className: "h-2 w-2" })
333
- }
334
- )
335
- ] }),
336
- /* @__PURE__ */ r(
337
- "textarea",
338
- {
339
- ref: u,
340
- value: t,
341
- onChange: (o) => e(o.target.value),
342
- onKeyDown: c,
343
- placeholder: "Ask me anything...",
344
- className: `max-h-[200px] min-h-[60px] w-full resize-none rounded-lg border-none px-3 py-2 text-sm outline-none ${a ? "cursor-not-allowed opacity-50" : ""}`,
345
- rows: 3,
346
- disabled: a
347
- }
348
- ),
349
- /* @__PURE__ */ m("div", { className: "flex items-center justify-between p-2", children: [
350
- /* @__PURE__ */ r(
351
- "button",
352
- {
353
- disabled: a,
354
- onClick: w,
355
- className: `p-1.5 text-gray-400 hover:text-gray-500 ${a ? "cursor-not-allowed opacity-50" : ""}`,
356
- title: "Attach Image",
357
- children: /* @__PURE__ */ r(xe, { size: 16 })
358
- }
359
- ),
360
- /* @__PURE__ */ r(
361
- "input",
362
- {
363
- disabled: a,
364
- ref: y,
365
- type: "file",
366
- accept: "image/*",
367
- onChange: p,
368
- className: "hidden"
369
- }
370
- ),
371
- a ? /* @__PURE__ */ r(
372
- "button",
373
- {
374
- onClick: l,
375
- className: "z-50 rounded-md bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",
376
- title: "Stop generation",
377
- children: /* @__PURE__ */ r(ye, { size: 16 })
378
- }
379
- ) : /* @__PURE__ */ r(
380
- "button",
381
- {
382
- onClick: k,
383
- disabled: !t.trim() || h,
384
- className: `rounded-md bg-blue-500 p-1.5 text-white transition-colors hover:bg-blue-600 ${!t.trim() || h ? "cursor-not-allowed opacity-50" : ""}`,
385
- children: /* @__PURE__ */ r(ve, { size: 16 })
386
- }
387
- )
388
- ] })
389
- ] })
390
- ] });
391
- }, je = () => {
392
- const [t, e] = C(""), [n, l] = C([]), [a, h] = C(!1), [x, u] = C(null), y = O(null), { addPredefinedBlock: s } = oe(), v = se(), c = le(), [S, p] = C(null), [w] = ie(), { selectedLang: k, fallbackLang: o } = ce(), b = k || o, N = () => {
393
- var i;
394
- (i = y.current) == null || i.scrollIntoView({ behavior: "smooth" });
395
- };
396
- W(() => {
397
- N();
398
- }, [n, a]);
399
- const M = () => {
400
- x && (x.abort(), u(null)), h(!1), e(""), p(null), l((i) => {
401
- const f = i[i.length - 1];
402
- return f && f.role === "assistant" && !f.content.trim() ? i.slice(0, -1) : i;
403
- }), K.info("Generation stopped");
404
- }, U = async (i, f, _) => {
405
- var q;
406
- if (!i || a) return;
407
- const d = c;
408
- p(c);
409
- const { position: Z, currentHTML: j } = Se((c == null ? void 0 : c._id) || "", w);
410
- if (c && !j) {
411
- K.error("Something went wrong. Please try again.");
412
- return;
413
- }
414
- const F = {
415
- id: Date.now().toString(),
416
- role: "user",
417
- content: Te({
418
- userInput: f || i,
419
- language: b,
420
- currentHtml: c ? j : ""
421
- }),
422
- userMessage: i
423
- }, $ = { id: Date.now().toString(), role: "assistant", content: "" };
424
- l((T) => [...T, F, $]), h(!0);
425
- const z = new AbortController();
426
- u(z);
427
- try {
428
- const T = {
429
- messages: [...n, F].map((g) => ({
430
- role: g.role,
431
- content: g.content
432
- }))
433
- };
434
- _ && (T.image = _);
435
- const A = await fetch("/chai/api/chat", {
436
- method: "POST",
437
- headers: { "Content-Type": "application/json" },
438
- body: JSON.stringify(T),
439
- signal: z.signal
440
- });
441
- if (!A.ok)
442
- throw new Error("Failed to get AI response");
443
- const I = (q = A.body) == null ? void 0 : q.getReader(), ee = new TextDecoder();
444
- let R = "";
445
- if (!I) throw new Error("Response body is not readable");
446
- const E = Y(d ? d == null ? void 0 : d._id : "canvas");
447
- for (; ; ) {
448
- const { done: g, value: L } = await I.read();
449
- if (g) {
450
- E && !d && E.remove();
451
- break;
452
- }
453
- const P = ee.decode(L, { stream: !0 });
454
- R += P, E && (E.innerHTML = R, E.scrollIntoView({ behavior: "smooth", block: "start" })), l(
455
- (G) => G.map((D) => D.id === $.id ? { ...D, content: R } : D)
456
- );
457
- }
458
- const te = Ce(R), re = de(te), ne = ue(re, (g) => {
459
- const L = B(g, "styles_attrs.data-block-type");
460
- if (L && !X.includes(L)) {
461
- const P = B(g, "styles_attrs.data-block-id");
462
- return { ...J(w, { _id: P }), _parent: g == null ? void 0 : g._parent };
463
- }
464
- return g;
465
- });
466
- d != null && d._id && v([d == null ? void 0 : d._id]), s([...ne], d == null ? void 0 : d._parent, d ? Z : -1);
467
- } catch (T) {
468
- if (T.name !== "AbortError") {
469
- const A = {
470
- id: (Date.now() + 1).toString(),
471
- role: "assistant",
472
- content: "Sorry, I encountered an error. Please try again."
473
- };
474
- l((I) => [...I, A]);
475
- }
476
- } finally {
477
- e(""), h(!1), p(null), u(null);
478
- }
479
- }, H = () => {
480
- l([]), e(""), p(null), u(null), h(!1);
481
- };
482
- return /* @__PURE__ */ m(V, { children: [
483
- a && /* @__PURE__ */ r("div", { className: "fixed inset-0 left-0 top-0 z-40 flex h-screen w-screen flex-col items-center justify-center bg-transparent" }),
484
- /* @__PURE__ */ m("div", { className: "flex h-full w-full flex-col bg-white", children: [
485
- /* @__PURE__ */ m("div", { className: "flex w-full items-center justify-between", children: [
486
- /* @__PURE__ */ r("p", { className: "text-xs text-gray-500", children: "Your conversation will not be saved" }),
487
- (n == null ? void 0 : n.length) > 0 && /* @__PURE__ */ r(me, { variant: "outline", size: "icon", onClick: H, className: "h-6 w-6", children: /* @__PURE__ */ r(he, {}) })
488
- ] }),
489
- /* @__PURE__ */ m("div", { className: "flex-1 space-y-3 overflow-y-auto py-4", children: [
490
- n.length === 0 && /* @__PURE__ */ r("div", { className: "flex-1 space-y-3 overflow-y-auto py-4", children: /* @__PURE__ */ m("div", { className: "mx-auto mt-8 text-center text-gray-500", children: [
491
- /* @__PURE__ */ r(fe, { size: 48, className: "mx-auto mb-4 text-gray-300" }),
492
- /* @__PURE__ */ r("p", { className: "mx-auto max-w-[75%] text-sm", children: "Start a conversation with the AI assistant to generate and update your sections" })
493
- ] }) }),
494
- n.map(
495
- (i, f) => i.role !== "system" && /* @__PURE__ */ r(
496
- Ie,
497
- {
498
- message: i,
499
- isUser: i.role === "user",
500
- isLoading: i.role === "assistant" && a && f === n.length - 1
501
- },
502
- f
503
- )
504
- ),
505
- /* @__PURE__ */ r("div", { ref: y })
506
- ] }),
507
- /* @__PURE__ */ r("div", { className: "border-gray-200 pb-2", children: /* @__PURE__ */ r(
508
- Re,
509
- {
510
- input: t,
511
- setInput: e,
512
- onSend: U,
513
- onStop: M,
514
- isLoading: a,
515
- currentBlock: c || S,
516
- disabled: (t == null ? void 0 : t.length) === 0
517
- }
518
- ) })
519
- ] })
520
- ] });
521
- };
522
- export {
523
- je as default
524
- };