@chaibuilder/pages 0.15.21 → 0.15.22

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 (64) hide show
  1. package/dist/{2AITGKQY-JdTvsit7.js → 2AITGKQY-BQI4o1xG.js} +2 -2
  2. package/dist/{2AITGKQY-CuxhppUA.cjs → 2AITGKQY-DXm3iqhg.cjs} +1 -1
  3. package/dist/{NCMVHL6D-CTrkJrNW.js → NCMVHL6D-B3kd8MpE.js} +2 -2
  4. package/dist/{NCMVHL6D-rzEn9a-Z.cjs → NCMVHL6D-C0TW9XJH.cjs} +1 -1
  5. package/dist/{ZDWCUMSJ-DZa1ZX5H.cjs → ZDWCUMSJ-DzyqbIEt.cjs} +1 -1
  6. package/dist/{ZDWCUMSJ-DIAJ5hj-.js → ZDWCUMSJ-IN3g-SXd.js} +1 -1
  7. package/dist/{add-new-language-page-3fFJlIi4.js → add-new-language-page-NXyJYXG-.js} +2 -2
  8. package/dist/{add-new-language-page-DPbVVRnt.cjs → add-new-language-page-zZoQgh6M.cjs} +1 -1
  9. package/dist/{add-new-page-C-DdGfOJ.js → add-new-page-C7Kw3sZO.js} +1 -1
  10. package/dist/{add-new-page-CgsPADOI.cjs → add-new-page-Cf_zoJPL.cjs} +1 -1
  11. package/dist/ai-panel-content-BXnMSm-N.js +614 -0
  12. package/dist/ai-panel-content-xcOgRnxG.cjs +142 -0
  13. package/dist/{delete-page-X6KE9Snl.js → delete-page-CyqJ6iqb.js} +1 -1
  14. package/dist/{delete-page-ftu1i43t.cjs → delete-page-qrzBuLu5.cjs} +1 -1
  15. package/dist/{digital-asset-manager-zEPka3BT.cjs → digital-asset-manager-BfDE0iUu.cjs} +1 -1
  16. package/dist/{digital-asset-manager-CWneIIcn.js → digital-asset-manager-BxM02CBp.js} +1 -1
  17. package/dist/{duplicate-page-Bwp0RTTE.js → duplicate-page-BGXDNCfU.js} +2 -2
  18. package/dist/{duplicate-page-D-2tkgsd.cjs → duplicate-page-CGKrJ-pm.cjs} +1 -1
  19. package/dist/{dynamic-page-selector-DDyEyh7e.cjs → dynamic-page-selector-C1ENQo3c.cjs} +1 -1
  20. package/dist/{dynamic-page-selector-Vl0aOeHK.js → dynamic-page-selector-D0H0U30o.js} +1 -1
  21. package/dist/index-CZxeSGRk.cjs +5 -0
  22. package/dist/{index-DHfaX2M6.js → index-D2g32O6h.js} +850 -842
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +1 -1
  25. package/dist/{json-diff-viewer-CM1kUeoR.cjs → json-diff-viewer-D03TdwEh.cjs} +1 -1
  26. package/dist/{json-diff-viewer-BCtaXLmG.js → json-diff-viewer-XF3MMhkA.js} +1 -1
  27. package/dist/{lang-panel-CaOkz8d3.js → lang-panel-8pMYi4Fn.js} +2 -2
  28. package/dist/{lang-panel-DNQEDZ5D.cjs → lang-panel-BQiWaq2_.cjs} +1 -1
  29. package/dist/{mark-as-template-XIeQkqPw.js → mark-as-template-BGe_QmNY.js} +1 -1
  30. package/dist/{mark-as-template-CD1bYgow.cjs → mark-as-template-DwgrP1Vj.cjs} +1 -1
  31. package/dist/{no-language-page-content-BHacGf6H.cjs → no-language-page-content-BiiD91y6.cjs} +1 -1
  32. package/dist/{no-language-page-content-CtN5VB9K.js → no-language-page-content-Cr6wq4o8.js} +1 -1
  33. package/dist/{page-creator-C7j6rkr2.cjs → page-creator-Di9A1gxS.cjs} +1 -1
  34. package/dist/{page-creator-Ci3yqsDv.js → page-creator-PSrGtRIm.js} +2 -2
  35. package/dist/{page-lock-request-01G9AeVF.js → page-lock-request-DQT5Ur0g.js} +1 -1
  36. package/dist/{page-lock-request-BNS3-biN.cjs → page-lock-request-Reyb6vZo.cjs} +1 -1
  37. package/dist/{page-locked-by-dialog-Cei-v0MT.cjs → page-locked-by-dialog-DF1_jPao.cjs} +1 -1
  38. package/dist/{page-locked-by-dialog-BQV9X0UF.js → page-locked-by-dialog-DgIr4-Gd.js} +1 -1
  39. package/dist/{page-manager-new-DE_2H_ow.js → page-manager-new-BuLz6042.js} +2 -2
  40. package/dist/{page-manager-new-XGKr4mup.cjs → page-manager-new-COui-em5.cjs} +1 -1
  41. package/dist/{page-manager-search-and-filter-BDw2AYXn.cjs → page-manager-search-and-filter-6_CVqZc_.cjs} +1 -1
  42. package/dist/{page-manager-search-and-filter-B8zCpxug.js → page-manager-search-and-filter-DxqVJw_A.js} +1 -1
  43. package/dist/{page-revisions-content-BIdaOcUx.cjs → page-revisions-content-BlM1X20k.cjs} +1 -1
  44. package/dist/{page-revisions-content-mih9gx3J.js → page-revisions-content-DagDCr7w.js} +2 -2
  45. package/dist/{publish-pages-content-1knN5SPM.cjs → publish-pages-content-6L8onxVt.cjs} +1 -1
  46. package/dist/{publish-pages-content-jYi-Q1Vl.js → publish-pages-content-eAcMLyLi.js} +2 -2
  47. package/dist/{save-to-lib-B56XAto8.cjs → save-to-lib-BUen2a0-.cjs} +1 -1
  48. package/dist/{save-to-lib-CpFEdU_R.js → save-to-lib-C43iGfOH.js} +1 -1
  49. package/dist/{seo-panel-DRb3uTUp.cjs → seo-panel-BseSTxFf.cjs} +1 -1
  50. package/dist/{seo-panel-D3bp2i90.js → seo-panel-DdE8DfMt.js} +1 -1
  51. package/dist/{shared-json-ld-pNjN-zzY.cjs → shared-json-ld-D-S-SwbU.cjs} +1 -1
  52. package/dist/{shared-json-ld-C4Kjka5m.js → shared-json-ld-OwSauSop.js} +1 -1
  53. package/dist/{slug-input-CKIckRno.js → slug-input-Bh4d19p2.js} +1 -1
  54. package/dist/{slug-input-BeepGXWz.cjs → slug-input-DYne39yC.cjs} +1 -1
  55. package/dist/{theme-panel-footer-DscF7mar.js → theme-panel-footer-BnxQBiM2.js} +1 -1
  56. package/dist/{theme-panel-footer-B0NRCfkL.cjs → theme-panel-footer-DLSf7QAN.cjs} +1 -1
  57. package/dist/{unmark-as-template-Dezq0GEM.js → unmark-as-template-B9xuxdYK.js} +1 -1
  58. package/dist/{unmark-as-template-9-wHwCPl.cjs → unmark-as-template-BTY-g4LE.cjs} +1 -1
  59. package/dist/{unpublish-page-COPOrCk_.js → unpublish-page-CYmJyQH9.js} +1 -1
  60. package/dist/{unpublish-page-DU3jKAJ5.cjs → unpublish-page-D0FunHFp.cjs} +1 -1
  61. package/dist/{web-preview-DBBTePPU.cjs → web-preview-DDnJlhVc.cjs} +1 -1
  62. package/dist/{web-preview-sSS97N-o.js → web-preview-y7dB2S91.js} +1 -1
  63. package/package.json +4 -3
  64. package/dist/index-DOlBrCPx.cjs +0 -5
@@ -0,0 +1,614 @@
1
+ import { jsxs as d, Fragment as K, jsx as r } from "react/jsx-runtime";
2
+ import { mergeClasses as ne, useAddBlock as oe, useRemoveBlocks as ae, useSelectedBlock as se, useBlocksStore as ie, useLanguages as le, getBlocksFromHTML as ce } from "@chaibuilder/sdk";
3
+ import { Button as de } from "@chaibuilder/sdk/ui";
4
+ import { find as Q, get as P, map as ue } from "lodash-es";
5
+ import { ChevronsUpDown as me, Plus as pe, Bot as ge, CheckCircle as he, X as fe, Paperclip as be, Square as ye, Send as xe, Loader as Y } from "lucide-react";
6
+ import { useState as N, useRef as D, useEffect as X } from "react";
7
+ import { toast as $ } from "sonner";
8
+ import { L as ve } from "./index-D2g32O6h.js";
9
+ const J = [
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 we(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 Te(t) {
45
+ if (!t) return "";
46
+ const e = we(t);
47
+ return e.length === 0 || !e.includes("<") || !e.includes(">") ? "" : e;
48
+ }
49
+ const Ne = (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
+ return l || null;
56
+ }, Se = (t, e) => {
57
+ var x;
58
+ const n = Ne(t);
59
+ if (!n) return { position: 0, currentHTML: "" };
60
+ n.style.opacity = "0.4";
61
+ const l = ((x = n == null ? void 0 : n.parentNode) == null ? void 0 : x.childNodes) || [], a = Array.from(l).indexOf(n), p = n.outerHTML, u = new DOMParser().parseFromString(p, "text/html");
62
+ return u.querySelectorAll("[data-block-id]").forEach((s) => {
63
+ const v = s.getAttribute("data-block-id"), c = Q(e, { _id: v }), S = c == null ? void 0 : c._type;
64
+ if (J.includes(S)) {
65
+ const m = JSON.stringify(c);
66
+ if (m != null && m.includes("{{") && (m != null && m.includes("}}"))) {
67
+ const w = Object.keys(c).filter((k) => {
68
+ const o = c[k], f = typeof o == "string" ? o : JSON.stringify(o);
69
+ return f.includes("{{") && f.includes("}}");
70
+ });
71
+ w.length > 0 && (s.setAttribute("data-binding-key", w[0]), s.innerHTML = P(c, w[0], ""));
72
+ }
73
+ 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");
74
+ } else
75
+ s.innerHTML = S;
76
+ }), { position: a, currentHTML: u.body.innerHTML };
77
+ };
78
+ function V() {
79
+ return `You are an expert HTML/CSS developer specializing in Tailwind CSS and shadcn/ui design patterns.
80
+
81
+ Create pure HTML code only. Make it fully responsive using Tailwind CSS v3 classes exclusively - no custom CSS or classes allowed. Implement container queries (@container) where appropriate for enhanced responsive behavior.
82
+
83
+ ### CRITICAL REQUIREMENTS:
84
+ 1. Return ONLY the HTML code without any markdown formatting, code blocks, or explanations
85
+ 2. Use ONLY Tailwind CSS v3+ utility classes - absolutely no custom CSS or classes
86
+ 3. Use shadcn/ui design system theming and styling patterns (neutral colors, proper spacing, modern aesthetics)
87
+ 4. Apply semantic HTML structure with proper accessibility attributes (ARIA labels, alt texts, proper heading hierarchy)
88
+ 5. Add 'chai-name' attributes to parent containers only - use concise, descriptive labels that clearly indicate content purpose (e.g., "Navigation", "Hero Section", "Footer", "Product Grid", "Testimonials"). These help identify sections during editing and AI-assisted modifications.
89
+ 6. Ensure mobile-first responsive design approach
90
+ 7. Implement container queries using @container classes where appropriate for enhanced responsive behavior
91
+ 8. Do NOT include <!DOCTYPE>, <html>, <head>, or <body> tags - only the content HTML
92
+ 9. Use proper contrast ratios for accessibility
93
+ 10. Keep the code clean, well-structured, and semantic
94
+ 11. Think about UI randomly. Do not generate the same layout every time.
95
+ 12. For accordion style ui, use html details and summary tags. eg: accordions, mobile menu etc.
96
+ 13. If UI generated based on provided image, make sure to make it responsive for all screens.
97
+ 14. In Tailwindcss, '@container' is not valid class. Use tailwindcss classes only
98
+
99
+ ### HTML Tags (EXTREMELY IMPORTANT):
100
+ - For mobile menu (<details><summary>) visible only on smaller screen:
101
+ * Hamburger icon in summary (proper SVG with width/height)
102
+ * Menu overlay example: 'absolute right-1 mt-2 min-w-64 bg-card border border-border rounded-lg shadow-lg z-50 p-4'
103
+ * Vertical menu items example: 'block py-2 px-4 hover:bg-accent rounded-md transition-colors'
104
+ * Proper spacing and touch targets (min 44px height)
105
+ - For accordion, faq style ui, use html details and summary tags.
106
+ - For nested menu, use html details and summary tags with dropdown style menu items.
107
+ - For SVG, always add tailwind class with width and height. eg: 'w-6 h-6'
108
+ - For summary add list-none where not needed, like mobile-menu summary.
109
+ - For input tags, add bg-background if want to make it look like shadcn/ui input.
110
+
111
+ ## THEME RULES (MANDATORY - SHADCN + TAILWIND ONLY) [EXTREMELY IMPORTANT]
112
+ - MANDATORY: Use ONLY ShadCN semantic tokens + Tailwind utilities for ALL colors.
113
+ * COLOR TOKENS (Light Mode Reference):
114
+ - bg-background (#ffffff) + text-foreground (#0a0a0a) - Default page
115
+ - bg-card (#ffffff) + text-card-foreground (#0a0a0a) - Elevated containers
116
+ - bg-primary (#171717) + text-primary-foreground (#fafafa) - Primary actions
117
+ - bg-secondary (#f5f5f5) + text-secondary-foreground (#171717) - Secondary actions
118
+ - bg-muted (#f5f5f5) + text-muted-foreground (#737373) - Subdued elements
119
+ - bg-accent (#f5f5f5) + text-accent-foreground (#171717) - Hover/focus states
120
+ - bg-destructive (#e7000b) + text-destructive-foreground (#ffffff) - Errors/warnings
121
+ - border-border (#e5e5e5), border-input (#e5e5e5) - Borders
122
+ - ring-ring (#a1a1a1) - Focus rings
123
+
124
+ * CONTRAST RULES (CRITICAL):
125
+ - ALWAYS pair background with correct foreground token
126
+ - bg-background → text-foreground (NOT text-card-foreground)
127
+ - bg-card → text-card-foreground (NOT text-foreground)
128
+ - bg-primary → text-primary-foreground (NOT text-foreground)
129
+ - bg-accent → text-accent-foreground
130
+ - NEVER use same token family for bg and text (e.g., bg-primary + text-primary)
131
+
132
+ * HOVER STATE RULES:
133
+ - Primary buttons: bg-primary hover:bg-primary/90 text-primary-foreground (NO hover text change)
134
+ - Card hovers: hover:bg-accent hover:text-accent-foreground transition-colors
135
+ - Link hovers: text-muted-foreground hover:text-foreground transition-colors
136
+ - Nav links: text-foreground/80 hover:text-foreground transition-colors
137
+ - NEVER use hover:text-primary-foreground on bg-primary (already same color)
138
+ - Hover text must be visibly different and contrast well
139
+
140
+ * USAGE EXAMPLES:
141
+ ✓ bg-background text-foreground
142
+ ✓ bg-card text-card-foreground border-border
143
+ ✓ bg-primary text-primary-foreground hover:bg-primary/90
144
+ ✓ bg-accent text-accent-foreground
145
+ ✓ text-muted-foreground hover:text-foreground transition-colors
146
+
147
+ * STRICTLY AVOID:
148
+ ✗ bg-muted text-muted (low contrast)
149
+ ✗ bg-primary hover:text-primary-foreground (redundant, no visible change)
150
+ ✗ Arbitrary colors (bg-blue-500, text-red-600, etc.)
151
+ ✗ Same token for bg and text (bg-foreground text-foreground)
152
+
153
+ # MOBILE-FIRST APPROACH:
154
+ - Mobile-first design with proper breakpoints (sm:640px, md:768px, lg:1024px, xl:1280px)
155
+ - Smooth responsive transitions between breakpoints
156
+ - MD breakpoint (768px-1023px) needs special attention:
157
+ * Reduce grid columns gracefully (lg:4 → md:2 → sm:1)
158
+ * Adjust padding/spacing for tablet view
159
+ * Test navigation menu behavior at md breakpoint
160
+ * Ensure cards don't break layout at md size
161
+
162
+ IMAGE USAGE RULES:
163
+ - VERY IMPORTANT*: Do not use broken or non available images
164
+ - Use royalty-free or non-copyrighted images from Unsplash or picsum photos
165
+ - Choose images that are relevant to the content context
166
+ - Always include descriptive alt text for accessibility
167
+ - Use appropriate image dimensions (e.g., w=1200 for hero images, w=800 for cards, w=400 for thumbnails)
168
+
169
+ OUTPUT
170
+ - The final output should be clean, semantic HTML that works across all devices and screen sizes.
171
+ - Return the complete updated HTML (not just modified parts)
172
+ - Focus only on the user's request without adding extra features or elements or sections
173
+ - Do not add any comments in the code
174
+ - Keep the output simple, minimal and precisely targeted to the request
175
+ - NO EXPLANATION - JUST HTML!`.trim();
176
+ }
177
+ function Ee({
178
+ userInput: t,
179
+ language: e = "en",
180
+ currentHtml: n
181
+ }) {
182
+ const l = ve[e] || "English";
183
+ return n && n.trim().length > 0 ? `
184
+ MODE: EDIT
185
+ CURRENT HTML:
186
+ ${n}
187
+
188
+ USER REQUEST: ${t}
189
+
190
+ EDIT MODE INSTRUCTIONS:
191
+ - Modify the existing HTML based on the user's request
192
+ - IMPORTANT: If asked for updating content, do not change layout just update same HTML with updated content
193
+ - CRITICAL: THINGS TO PREVENT
194
+ - Preserve ALL data binding placeholders in format '{{dataBindingId}}' - never remove or modify these dynamic content markers
195
+ - Preserve html tag with attributes data-block-type="PartialBlock" or data-block-type="CustomBlock" - never remove or modify these tag
196
+ - Preserve the overall structure unless specifically asked to change it
197
+ - Update content, styling, or layout as requested
198
+ - Maintain responsive design and accessibility
199
+ - Keep using shadcn/ui theme classes and Tailwind CSS
200
+ - Ensure all chai-name attributes remain descriptive and accurate
201
+ - Generate content in specified language: ${l}
202
+ - Apply the same design principles from the system prompt
203
+ - Make sure the edited HTML is clean and semantic`.trim() : `
204
+ USER REQUEST: ${t}
205
+
206
+ CREATE MODE INSTRUCTIONS:
207
+ - Generate complete HTML structure based on user request
208
+ - Use creative, modern, and responsive design
209
+ - Apply Tailwind CSS v3+ classes exclusively
210
+ - Follow shadcn/ui design patterns and theming
211
+ - Include proper accessibility attributes
212
+ - Add chai-name attributes to all wrapper/container elements
213
+ - Use semantic HTML structure
214
+ - Generate contextually appropriate content in ${l}
215
+ - Make each element unique and meaningful
216
+ - Create realistic, professional content that fits the request
217
+ - Avoid generic placeholder text
218
+ - Use strategic image placement where appropriate
219
+ - Ensure mobile-first responsive design
220
+ - Apply proper hover and focus states
221
+
222
+ DESIGN REQUIREMENTS:
223
+ - Choose creative layout patterns that are visually striking
224
+ - Apply modern spacing and typography
225
+ - Use proper color contrast with shadcn/ui theme classes
226
+ - Make it responsive across all device sizes
227
+ - Include interactive elements with proper states
228
+ - Ensure accessibility compliance`.trim();
229
+ }
230
+ const ke = [
231
+ {
232
+ label: "Navbar",
233
+ prompt: "Create stunning, fully responsive navbar with"
234
+ },
235
+ {
236
+ label: "Hero section",
237
+ prompt: "Create visually compelling hero section with"
238
+ },
239
+ {
240
+ label: "Features grid",
241
+ prompt: "Create comprehensive features section with"
242
+ },
243
+ {
244
+ label: "Contact form",
245
+ prompt: "Create professional contact form with"
246
+ },
247
+ {
248
+ label: "Testimonials",
249
+ prompt: "Create engaging testimonials section with"
250
+ },
251
+ {
252
+ label: "Pricing table",
253
+ prompt: "Create modern pricing table with"
254
+ },
255
+ {
256
+ label: "FAQ section",
257
+ prompt: "Create informative FAQ section with"
258
+ },
259
+ {
260
+ label: "Footer",
261
+ prompt: "Create comprehensive footer section with"
262
+ },
263
+ {
264
+ label: "Call to action",
265
+ prompt: "Create compelling call to action section with"
266
+ },
267
+ {
268
+ label: "Team section",
269
+ prompt: "Create professional team section with"
270
+ },
271
+ {
272
+ label: "Blog grid",
273
+ prompt: "Create attractive blog grid section with"
274
+ },
275
+ {
276
+ label: "Stats section",
277
+ prompt: "Create impactful statistics section with"
278
+ }
279
+ ], Ce = [
280
+ {
281
+ label: "Update styles",
282
+ prompt: "Update styles"
283
+ },
284
+ {
285
+ label: "Update content",
286
+ prompt: "Update text content"
287
+ },
288
+ {
289
+ label: "Update layout",
290
+ prompt: "Update layout"
291
+ },
292
+ {
293
+ label: "Improve content",
294
+ prompt: "Improve text content grammar and spelling"
295
+ },
296
+ {
297
+ label: "Make content longer",
298
+ prompt: "Make text content longer"
299
+ },
300
+ {
301
+ label: "Make content shorter",
302
+ prompt: "Make text content shorter"
303
+ },
304
+ {
305
+ label: "Fix grammar",
306
+ prompt: "Fix grammar of the text content"
307
+ }
308
+ ], Ae = ({ onSelect: t, currentBlock: e, selectedImage: n }) => {
309
+ const [l, a] = N(!1), p = e ? Ce : ke;
310
+ return /* @__PURE__ */ d(K, { children: [
311
+ /* @__PURE__ */ d(
312
+ "div",
313
+ {
314
+ onClick: () => a(!l),
315
+ className: ne(
316
+ "flex h-6 w-full cursor-pointer items-center justify-between gap-2 px-2",
317
+ e ? "bg-green-50/80 text-green-500 hover:bg-green-50" : "text-primary hover:bg-primary/5"
318
+ ),
319
+ children: [
320
+ /* @__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" }),
321
+ /* @__PURE__ */ r(me, { className: "h-3 w-3" })
322
+ ]
323
+ }
324
+ ),
325
+ l && /* @__PURE__ */ r("div", { className: "max-h-60 w-full overflow-y-auto bg-white px-1 pb-1", children: p.map((y, u) => /* @__PURE__ */ r(
326
+ "div",
327
+ {
328
+ className: "flex cursor-pointer items-center gap-x-1 p-1 text-xs leading-none hover:text-blue-700",
329
+ onClick: () => {
330
+ t(`${n || e ? "Update" : "Add New"} ${y.label}`, y.prompt), a(!1);
331
+ },
332
+ children: /* @__PURE__ */ d("span", { className: "truncate whitespace-nowrap", children: [
333
+ e ? null : /* @__PURE__ */ r("span", { className: "font-thin text-muted-foreground", children: "Add New" }),
334
+ " ",
335
+ y.label
336
+ ] })
337
+ },
338
+ u
339
+ )) })
340
+ ] });
341
+ }, Me = ({ message: t }) => {
342
+ var e;
343
+ 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__ */ d("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: [
344
+ /* @__PURE__ */ r(Y, { className: "h-3 w-3 animate-spin" }),
345
+ " Processing"
346
+ ] }) }) : /* @__PURE__ */ r("div", { className: "relative z-50 mb-3 flex w-full flex-col gap-2 overflow-hidden", children: /* @__PURE__ */ d("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: [
347
+ /* @__PURE__ */ r(Y, { className: "h-3 w-3 animate-spin" }),
348
+ " Generating"
349
+ ] }) });
350
+ }, 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(
351
+ "div",
352
+ {
353
+ 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",
354
+ children: t.userMessage
355
+ }
356
+ ) }) : n ? /* @__PURE__ */ r(Me, { message: t }) : /* @__PURE__ */ r(
357
+ "div",
358
+ {
359
+ className: `relative mb-3 flex w-full overflow-hidden ${e ? "justify-end" : n ? "max-h-48 min-h-24 justify-start" : "max-h-16"}`,
360
+ children: /* @__PURE__ */ d("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: [
361
+ /* @__PURE__ */ r(he, { className: "h-3 w-3" }),
362
+ " Completed"
363
+ ] })
364
+ }
365
+ ), Le = ({
366
+ input: t,
367
+ setInput: e,
368
+ onSend: n,
369
+ onStop: l,
370
+ isLoading: a,
371
+ disabled: p,
372
+ currentBlock: y
373
+ }) => {
374
+ const u = D(null), x = D(null), [s, v] = N(null), c = (o) => {
375
+ o.key === "Enter" && !o.shiftKey && (o.preventDefault(), t.trim() && !a && (n(t == null ? void 0 : t.trim(), void 0, s || void 0), v(null)));
376
+ }, S = () => {
377
+ const o = u.current;
378
+ o && (o.style.height = "auto", o.style.height = Math.min(o.scrollHeight, 120) + "px");
379
+ }, m = (o) => {
380
+ var T;
381
+ const f = (T = o.target.files) == null ? void 0 : T[0];
382
+ if (f && f.type.startsWith("image/")) {
383
+ const C = new FileReader();
384
+ C.onload = (L) => {
385
+ var i, g;
386
+ const R = (i = L.target) == null ? void 0 : i.result;
387
+ v(R), e("Generate UI based on given image "), (g = u.current) == null || g.focus();
388
+ }, C.readAsDataURL(f);
389
+ }
390
+ o.target.value = "";
391
+ }, w = () => {
392
+ var o;
393
+ (o = x.current) == null || o.click();
394
+ }, k = () => {
395
+ n(t == null ? void 0 : t.trim(), void 0, s || void 0), v(null);
396
+ };
397
+ return X(() => {
398
+ S();
399
+ }, [t]), /* @__PURE__ */ d("div", { children: [
400
+ !s && /* @__PURE__ */ r(
401
+ "div",
402
+ {
403
+ 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" : ""}`,
404
+ children: /* @__PURE__ */ r(
405
+ Ae,
406
+ {
407
+ currentBlock: y,
408
+ selectedImage: s,
409
+ onSelect: (o, f) => {
410
+ var T;
411
+ e(f + " "), (T = u.current) == null || T.focus();
412
+ }
413
+ }
414
+ )
415
+ }
416
+ ),
417
+ /* @__PURE__ */ d("div", { className: "rounded-lg border border-gray-200 bg-white", children: [
418
+ s && /* @__PURE__ */ d("div", { className: "relative flex w-max items-center justify-start gap-x-2 px-2 pt-2", children: [
419
+ /* @__PURE__ */ r("img", { src: s, alt: "Selected attachment", className: "max-h-16 max-w-full rounded-md border" }),
420
+ /* @__PURE__ */ r(
421
+ "button",
422
+ {
423
+ onClick: () => v(null),
424
+ className: "absolute -right-0 -top-0 flex items-center rounded-full bg-red-400 p-1 text-xs text-white hover:bg-red-500",
425
+ title: "Remove image",
426
+ children: /* @__PURE__ */ r(fe, { className: "h-2 w-2" })
427
+ }
428
+ )
429
+ ] }),
430
+ /* @__PURE__ */ r(
431
+ "textarea",
432
+ {
433
+ ref: u,
434
+ value: t,
435
+ onChange: (o) => e(o.target.value),
436
+ onKeyDown: c,
437
+ placeholder: "Ask me anything...",
438
+ 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" : ""}`,
439
+ rows: 3,
440
+ disabled: a
441
+ }
442
+ ),
443
+ /* @__PURE__ */ d("div", { className: "flex items-center justify-between p-2", children: [
444
+ /* @__PURE__ */ r(
445
+ "button",
446
+ {
447
+ disabled: a,
448
+ onClick: w,
449
+ className: `p-1.5 text-gray-400 hover:text-gray-500 ${a ? "cursor-not-allowed opacity-50" : ""}`,
450
+ title: "Attach Image",
451
+ children: /* @__PURE__ */ r(be, { size: 16 })
452
+ }
453
+ ),
454
+ /* @__PURE__ */ r(
455
+ "input",
456
+ {
457
+ disabled: a,
458
+ ref: x,
459
+ type: "file",
460
+ accept: "image/*",
461
+ onChange: m,
462
+ className: "hidden"
463
+ }
464
+ ),
465
+ a ? /* @__PURE__ */ r(
466
+ "button",
467
+ {
468
+ onClick: l,
469
+ className: "z-50 rounded-md bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",
470
+ title: "Stop generation",
471
+ children: /* @__PURE__ */ r(ye, { size: 16 })
472
+ }
473
+ ) : /* @__PURE__ */ r(
474
+ "button",
475
+ {
476
+ onClick: k,
477
+ disabled: !t.trim() || p,
478
+ className: `rounded-md bg-blue-500 p-1.5 text-white transition-colors hover:bg-blue-600 ${!t.trim() || p ? "cursor-not-allowed opacity-50" : ""}`,
479
+ children: /* @__PURE__ */ r(xe, { size: 16 })
480
+ }
481
+ )
482
+ ] })
483
+ ] })
484
+ ] });
485
+ }, je = () => {
486
+ const [t, e] = N(""), [n, l] = N([{ role: "system", content: V(), id: "system" }]), [a, p] = N(!1), [y, u] = N(null), x = D(null), { addPredefinedBlock: s } = oe(), v = ae(), c = se(), [S, m] = N(null), [w] = ie(), { selectedLang: k, fallbackLang: o } = le(), f = k || o, T = () => {
487
+ var i;
488
+ (i = x.current) == null || i.scrollIntoView({ behavior: "smooth" });
489
+ };
490
+ X(() => {
491
+ T();
492
+ }, [n, a]);
493
+ const C = () => {
494
+ y && (y.abort(), u(null)), p(!1), e(""), m(null), l((i) => {
495
+ const g = i[i.length - 1];
496
+ return g && g.role === "assistant" && !g.content.trim() ? i.slice(0, -1) : i;
497
+ }), $.info("Generation stopped");
498
+ }, L = async (i, g, F) => {
499
+ var q;
500
+ if (!i || a) return;
501
+ const b = c;
502
+ m(c);
503
+ const { position: W, currentHTML: B } = Se((c == null ? void 0 : c._id) || "", w);
504
+ if (c && !B) {
505
+ $.error("Something went wrong. Please try again.");
506
+ return;
507
+ }
508
+ const j = {
509
+ id: Date.now().toString(),
510
+ role: "user",
511
+ content: Ee({
512
+ userInput: g || i,
513
+ language: f,
514
+ currentHtml: c ? B : ""
515
+ }),
516
+ userMessage: i
517
+ }, _ = { id: Date.now().toString(), role: "assistant", content: "" };
518
+ l((E) => [...E, j, _]), p(!0);
519
+ const G = new AbortController();
520
+ u(G);
521
+ try {
522
+ const E = {
523
+ messages: [...n, j].map((h) => ({
524
+ role: h.role,
525
+ content: h.content
526
+ }))
527
+ };
528
+ F && (E.image = F);
529
+ const A = await fetch("/chai/api/chat", {
530
+ method: "POST",
531
+ headers: { "Content-Type": "application/json" },
532
+ body: JSON.stringify(E),
533
+ signal: G.signal
534
+ });
535
+ if (!A.ok)
536
+ throw new Error("Failed to get AI response");
537
+ const M = (q = A.body) == null ? void 0 : q.getReader(), Z = new TextDecoder();
538
+ let U = "";
539
+ if (!M) throw new Error("Response body is not readable");
540
+ for (; ; ) {
541
+ const { done: h, value: I } = await M.read();
542
+ if (h) break;
543
+ const O = Z.decode(I, { stream: !0 });
544
+ U += O, l(
545
+ (z) => z.map((H) => H.id === _.id ? { ...H, content: U } : H)
546
+ );
547
+ }
548
+ const ee = Te(U), te = ce(ee), re = ue(te, (h) => {
549
+ const I = P(h, "styles_attrs.data-block-type");
550
+ if (I && !J.includes(I)) {
551
+ const O = P(h, "styles_attrs.data-block-id");
552
+ return { ...Q(w, { _id: O }), _parent: h == null ? void 0 : h._parent };
553
+ }
554
+ return h;
555
+ });
556
+ b != null && b._id && v([b == null ? void 0 : b._id]), s([...re], b == null ? void 0 : b._parent, b ? W : -1);
557
+ } catch (E) {
558
+ if (E.name !== "AbortError") {
559
+ const A = {
560
+ id: (Date.now() + 1).toString(),
561
+ role: "assistant",
562
+ content: "Sorry, I encountered an error. Please try again."
563
+ };
564
+ l((M) => [...M, A]);
565
+ }
566
+ } finally {
567
+ e(""), p(!1), m(null), u(null);
568
+ }
569
+ }, R = () => {
570
+ l([{ role: "system", content: V(), id: "system" }]), e(""), m(null), u(null), p(!1);
571
+ };
572
+ return /* @__PURE__ */ d(K, { children: [
573
+ 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" }),
574
+ /* @__PURE__ */ d("div", { className: "flex h-full w-full flex-col bg-white", children: [
575
+ /* @__PURE__ */ d("div", { className: "flex w-full items-center justify-between", children: [
576
+ /* @__PURE__ */ r("p", { className: "text-xs text-gray-500", children: "Your conversation will not be saved" }),
577
+ (n == null ? void 0 : n.length) > 1 && /* @__PURE__ */ r(de, { variant: "outline", size: "icon", onClick: R, className: "h-6 w-6", children: /* @__PURE__ */ r(pe, {}) })
578
+ ] }),
579
+ /* @__PURE__ */ d("div", { className: "flex-1 space-y-3 overflow-y-auto py-4", children: [
580
+ n.length === 1 && /* @__PURE__ */ r("div", { className: "flex-1 space-y-3 overflow-y-auto py-4", children: /* @__PURE__ */ d("div", { className: "mx-auto mt-8 text-center text-gray-500", children: [
581
+ /* @__PURE__ */ r(ge, { size: 48, className: "mx-auto mb-4 text-gray-300" }),
582
+ /* @__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" })
583
+ ] }) }),
584
+ n.map(
585
+ (i, g) => i.role !== "system" && /* @__PURE__ */ r(
586
+ Ie,
587
+ {
588
+ message: i,
589
+ isUser: i.role === "user",
590
+ isLoading: i.role === "assistant" && a && g === n.length - 1
591
+ },
592
+ g
593
+ )
594
+ ),
595
+ /* @__PURE__ */ r("div", { ref: x })
596
+ ] }),
597
+ /* @__PURE__ */ r("div", { className: "border-gray-200 pb-2", children: /* @__PURE__ */ r(
598
+ Le,
599
+ {
600
+ input: t,
601
+ setInput: e,
602
+ onSend: L,
603
+ onStop: C,
604
+ isLoading: a,
605
+ currentBlock: c || S,
606
+ disabled: (t == null ? void 0 : t.length) === 0
607
+ }
608
+ ) })
609
+ ] })
610
+ ] });
611
+ };
612
+ export {
613
+ je as default
614
+ };