@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.
- package/dist/{2AITGKQY-JdTvsit7.js → 2AITGKQY-BQI4o1xG.js} +2 -2
- package/dist/{2AITGKQY-CuxhppUA.cjs → 2AITGKQY-DXm3iqhg.cjs} +1 -1
- package/dist/{NCMVHL6D-CTrkJrNW.js → NCMVHL6D-B3kd8MpE.js} +2 -2
- package/dist/{NCMVHL6D-rzEn9a-Z.cjs → NCMVHL6D-C0TW9XJH.cjs} +1 -1
- package/dist/{ZDWCUMSJ-DZa1ZX5H.cjs → ZDWCUMSJ-DzyqbIEt.cjs} +1 -1
- package/dist/{ZDWCUMSJ-DIAJ5hj-.js → ZDWCUMSJ-IN3g-SXd.js} +1 -1
- package/dist/{add-new-language-page-3fFJlIi4.js → add-new-language-page-NXyJYXG-.js} +2 -2
- package/dist/{add-new-language-page-DPbVVRnt.cjs → add-new-language-page-zZoQgh6M.cjs} +1 -1
- package/dist/{add-new-page-C-DdGfOJ.js → add-new-page-C7Kw3sZO.js} +1 -1
- package/dist/{add-new-page-CgsPADOI.cjs → add-new-page-Cf_zoJPL.cjs} +1 -1
- package/dist/ai-panel-content-BXnMSm-N.js +614 -0
- package/dist/ai-panel-content-xcOgRnxG.cjs +142 -0
- package/dist/{delete-page-X6KE9Snl.js → delete-page-CyqJ6iqb.js} +1 -1
- package/dist/{delete-page-ftu1i43t.cjs → delete-page-qrzBuLu5.cjs} +1 -1
- package/dist/{digital-asset-manager-zEPka3BT.cjs → digital-asset-manager-BfDE0iUu.cjs} +1 -1
- package/dist/{digital-asset-manager-CWneIIcn.js → digital-asset-manager-BxM02CBp.js} +1 -1
- package/dist/{duplicate-page-Bwp0RTTE.js → duplicate-page-BGXDNCfU.js} +2 -2
- package/dist/{duplicate-page-D-2tkgsd.cjs → duplicate-page-CGKrJ-pm.cjs} +1 -1
- package/dist/{dynamic-page-selector-DDyEyh7e.cjs → dynamic-page-selector-C1ENQo3c.cjs} +1 -1
- package/dist/{dynamic-page-selector-Vl0aOeHK.js → dynamic-page-selector-D0H0U30o.js} +1 -1
- package/dist/index-CZxeSGRk.cjs +5 -0
- package/dist/{index-DHfaX2M6.js → index-D2g32O6h.js} +850 -842
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{json-diff-viewer-CM1kUeoR.cjs → json-diff-viewer-D03TdwEh.cjs} +1 -1
- package/dist/{json-diff-viewer-BCtaXLmG.js → json-diff-viewer-XF3MMhkA.js} +1 -1
- package/dist/{lang-panel-CaOkz8d3.js → lang-panel-8pMYi4Fn.js} +2 -2
- package/dist/{lang-panel-DNQEDZ5D.cjs → lang-panel-BQiWaq2_.cjs} +1 -1
- package/dist/{mark-as-template-XIeQkqPw.js → mark-as-template-BGe_QmNY.js} +1 -1
- package/dist/{mark-as-template-CD1bYgow.cjs → mark-as-template-DwgrP1Vj.cjs} +1 -1
- package/dist/{no-language-page-content-BHacGf6H.cjs → no-language-page-content-BiiD91y6.cjs} +1 -1
- package/dist/{no-language-page-content-CtN5VB9K.js → no-language-page-content-Cr6wq4o8.js} +1 -1
- package/dist/{page-creator-C7j6rkr2.cjs → page-creator-Di9A1gxS.cjs} +1 -1
- package/dist/{page-creator-Ci3yqsDv.js → page-creator-PSrGtRIm.js} +2 -2
- package/dist/{page-lock-request-01G9AeVF.js → page-lock-request-DQT5Ur0g.js} +1 -1
- package/dist/{page-lock-request-BNS3-biN.cjs → page-lock-request-Reyb6vZo.cjs} +1 -1
- package/dist/{page-locked-by-dialog-Cei-v0MT.cjs → page-locked-by-dialog-DF1_jPao.cjs} +1 -1
- package/dist/{page-locked-by-dialog-BQV9X0UF.js → page-locked-by-dialog-DgIr4-Gd.js} +1 -1
- package/dist/{page-manager-new-DE_2H_ow.js → page-manager-new-BuLz6042.js} +2 -2
- package/dist/{page-manager-new-XGKr4mup.cjs → page-manager-new-COui-em5.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-BDw2AYXn.cjs → page-manager-search-and-filter-6_CVqZc_.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-B8zCpxug.js → page-manager-search-and-filter-DxqVJw_A.js} +1 -1
- package/dist/{page-revisions-content-BIdaOcUx.cjs → page-revisions-content-BlM1X20k.cjs} +1 -1
- package/dist/{page-revisions-content-mih9gx3J.js → page-revisions-content-DagDCr7w.js} +2 -2
- package/dist/{publish-pages-content-1knN5SPM.cjs → publish-pages-content-6L8onxVt.cjs} +1 -1
- package/dist/{publish-pages-content-jYi-Q1Vl.js → publish-pages-content-eAcMLyLi.js} +2 -2
- package/dist/{save-to-lib-B56XAto8.cjs → save-to-lib-BUen2a0-.cjs} +1 -1
- package/dist/{save-to-lib-CpFEdU_R.js → save-to-lib-C43iGfOH.js} +1 -1
- package/dist/{seo-panel-DRb3uTUp.cjs → seo-panel-BseSTxFf.cjs} +1 -1
- package/dist/{seo-panel-D3bp2i90.js → seo-panel-DdE8DfMt.js} +1 -1
- package/dist/{shared-json-ld-pNjN-zzY.cjs → shared-json-ld-D-S-SwbU.cjs} +1 -1
- package/dist/{shared-json-ld-C4Kjka5m.js → shared-json-ld-OwSauSop.js} +1 -1
- package/dist/{slug-input-CKIckRno.js → slug-input-Bh4d19p2.js} +1 -1
- package/dist/{slug-input-BeepGXWz.cjs → slug-input-DYne39yC.cjs} +1 -1
- package/dist/{theme-panel-footer-DscF7mar.js → theme-panel-footer-BnxQBiM2.js} +1 -1
- package/dist/{theme-panel-footer-B0NRCfkL.cjs → theme-panel-footer-DLSf7QAN.cjs} +1 -1
- package/dist/{unmark-as-template-Dezq0GEM.js → unmark-as-template-B9xuxdYK.js} +1 -1
- package/dist/{unmark-as-template-9-wHwCPl.cjs → unmark-as-template-BTY-g4LE.cjs} +1 -1
- package/dist/{unpublish-page-COPOrCk_.js → unpublish-page-CYmJyQH9.js} +1 -1
- package/dist/{unpublish-page-DU3jKAJ5.cjs → unpublish-page-D0FunHFp.cjs} +1 -1
- package/dist/{web-preview-DBBTePPU.cjs → web-preview-DDnJlhVc.cjs} +1 -1
- package/dist/{web-preview-sSS97N-o.js → web-preview-y7dB2S91.js} +1 -1
- package/package.json +4 -3
- package/dist/index-DOlBrCPx.cjs +0 -5
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),N=require("@chaibuilder/sdk"),Z=require("@chaibuilder/sdk/ui"),C=require("lodash-es"),b=require("lucide-react"),m=require("react"),Y=require("sonner"),ee=require("./index-CZxeSGRk.cjs"),V=["Box","Button","Heading","Paragraph","Text","Span","Link","Image","Video","Icon","List","ListItem","Row","Column","Form","Input","FormButton","Checkbox","Radio","Select","TextArea","Label","RichText","Divider","EmptyBox","LineBreak","Table","EmptySlot"];function te(r){if(!r)return"";let t=r.trim();return t=t.replace(/^```html\n?/i,""),t=t.replace(/^```\n?/,""),t=t.replace(/\n?```$/,""),t=t.trim(),t}function re(r){if(!r)return"";const t=te(r);return t.length===0||!t.includes("<")||!t.includes(">")?"":t}const ne=r=>{const t=document.getElementById("canvas-iframe");if(!t)return null;const n=t==null?void 0:t.contentDocument;if(!n)return null;const l=n.querySelector(`[data-block-id="${r}"]`);return l||null},se=(r,t)=>{var v;const n=ne(r);if(!n)return{position:0,currentHTML:""};n.style.opacity="0.4";const l=((v=n==null?void 0:n.parentNode)==null?void 0:v.childNodes)||[],o=Array.from(l).indexOf(n),p=n.outerHTML,d=new DOMParser().parseFromString(p,"text/html");return d.querySelectorAll("[data-block-id]").forEach(a=>{const w=a.getAttribute("data-block-id"),c=C.find(t,{_id:w}),E=c==null?void 0:c._type;if(V.includes(E)){const u=JSON.stringify(c);if(u!=null&&u.includes("{{")&&(u!=null&&u.includes("}}"))){const T=Object.keys(c).filter(A=>{const s=c[A],f=typeof s=="string"?s:JSON.stringify(s);return f.includes("{{")&&f.includes("}}")});T.length>0&&(a.setAttribute("data-binding-key",T[0]),a.innerHTML=C.get(c,T[0],""))}a.removeAttribute("data-block-type"),a.removeAttribute("data-style-prop"),a.removeAttribute("data-block-parent"),a.removeAttribute("data-style-id"),a.removeAttribute("data-block-id"),a.removeAttribute("data-block-index"),a.removeAttribute("data-highlighted")}else a.innerHTML=E}),{position:o,currentHTML:d.body.innerHTML}};function $(){return`You are an expert HTML/CSS developer specializing in Tailwind CSS and shadcn/ui design patterns.
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
### CRITICAL REQUIREMENTS:
|
|
6
|
+
1. Return ONLY the HTML code without any markdown formatting, code blocks, or explanations
|
|
7
|
+
2. Use ONLY Tailwind CSS v3+ utility classes - absolutely no custom CSS or classes
|
|
8
|
+
3. Use shadcn/ui design system theming and styling patterns (neutral colors, proper spacing, modern aesthetics)
|
|
9
|
+
4. Apply semantic HTML structure with proper accessibility attributes (ARIA labels, alt texts, proper heading hierarchy)
|
|
10
|
+
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.
|
|
11
|
+
6. Ensure mobile-first responsive design approach
|
|
12
|
+
7. Implement container queries using @container classes where appropriate for enhanced responsive behavior
|
|
13
|
+
8. Do NOT include <!DOCTYPE>, <html>, <head>, or <body> tags - only the content HTML
|
|
14
|
+
9. Use proper contrast ratios for accessibility
|
|
15
|
+
10. Keep the code clean, well-structured, and semantic
|
|
16
|
+
11. Think about UI randomly. Do not generate the same layout every time.
|
|
17
|
+
12. For accordion style ui, use html details and summary tags. eg: accordions, mobile menu etc.
|
|
18
|
+
13. If UI generated based on provided image, make sure to make it responsive for all screens.
|
|
19
|
+
14. In Tailwindcss, '@container' is not valid class. Use tailwindcss classes only
|
|
20
|
+
|
|
21
|
+
### HTML Tags (EXTREMELY IMPORTANT):
|
|
22
|
+
- For mobile menu (<details><summary>) visible only on smaller screen:
|
|
23
|
+
* Hamburger icon in summary (proper SVG with width/height)
|
|
24
|
+
* Menu overlay example: 'absolute right-1 mt-2 min-w-64 bg-card border border-border rounded-lg shadow-lg z-50 p-4'
|
|
25
|
+
* Vertical menu items example: 'block py-2 px-4 hover:bg-accent rounded-md transition-colors'
|
|
26
|
+
* Proper spacing and touch targets (min 44px height)
|
|
27
|
+
- For accordion, faq style ui, use html details and summary tags.
|
|
28
|
+
- For nested menu, use html details and summary tags with dropdown style menu items.
|
|
29
|
+
- For SVG, always add tailwind class with width and height. eg: 'w-6 h-6'
|
|
30
|
+
- For summary add list-none where not needed, like mobile-menu summary.
|
|
31
|
+
- For input tags, add bg-background if want to make it look like shadcn/ui input.
|
|
32
|
+
|
|
33
|
+
## THEME RULES (MANDATORY - SHADCN + TAILWIND ONLY) [EXTREMELY IMPORTANT]
|
|
34
|
+
- MANDATORY: Use ONLY ShadCN semantic tokens + Tailwind utilities for ALL colors.
|
|
35
|
+
* COLOR TOKENS (Light Mode Reference):
|
|
36
|
+
- bg-background (#ffffff) + text-foreground (#0a0a0a) - Default page
|
|
37
|
+
- bg-card (#ffffff) + text-card-foreground (#0a0a0a) - Elevated containers
|
|
38
|
+
- bg-primary (#171717) + text-primary-foreground (#fafafa) - Primary actions
|
|
39
|
+
- bg-secondary (#f5f5f5) + text-secondary-foreground (#171717) - Secondary actions
|
|
40
|
+
- bg-muted (#f5f5f5) + text-muted-foreground (#737373) - Subdued elements
|
|
41
|
+
- bg-accent (#f5f5f5) + text-accent-foreground (#171717) - Hover/focus states
|
|
42
|
+
- bg-destructive (#e7000b) + text-destructive-foreground (#ffffff) - Errors/warnings
|
|
43
|
+
- border-border (#e5e5e5), border-input (#e5e5e5) - Borders
|
|
44
|
+
- ring-ring (#a1a1a1) - Focus rings
|
|
45
|
+
|
|
46
|
+
* CONTRAST RULES (CRITICAL):
|
|
47
|
+
- ALWAYS pair background with correct foreground token
|
|
48
|
+
- bg-background → text-foreground (NOT text-card-foreground)
|
|
49
|
+
- bg-card → text-card-foreground (NOT text-foreground)
|
|
50
|
+
- bg-primary → text-primary-foreground (NOT text-foreground)
|
|
51
|
+
- bg-accent → text-accent-foreground
|
|
52
|
+
- NEVER use same token family for bg and text (e.g., bg-primary + text-primary)
|
|
53
|
+
|
|
54
|
+
* HOVER STATE RULES:
|
|
55
|
+
- Primary buttons: bg-primary hover:bg-primary/90 text-primary-foreground (NO hover text change)
|
|
56
|
+
- Card hovers: hover:bg-accent hover:text-accent-foreground transition-colors
|
|
57
|
+
- Link hovers: text-muted-foreground hover:text-foreground transition-colors
|
|
58
|
+
- Nav links: text-foreground/80 hover:text-foreground transition-colors
|
|
59
|
+
- NEVER use hover:text-primary-foreground on bg-primary (already same color)
|
|
60
|
+
- Hover text must be visibly different and contrast well
|
|
61
|
+
|
|
62
|
+
* USAGE EXAMPLES:
|
|
63
|
+
✓ bg-background text-foreground
|
|
64
|
+
✓ bg-card text-card-foreground border-border
|
|
65
|
+
✓ bg-primary text-primary-foreground hover:bg-primary/90
|
|
66
|
+
✓ bg-accent text-accent-foreground
|
|
67
|
+
✓ text-muted-foreground hover:text-foreground transition-colors
|
|
68
|
+
|
|
69
|
+
* STRICTLY AVOID:
|
|
70
|
+
✗ bg-muted text-muted (low contrast)
|
|
71
|
+
✗ bg-primary hover:text-primary-foreground (redundant, no visible change)
|
|
72
|
+
✗ Arbitrary colors (bg-blue-500, text-red-600, etc.)
|
|
73
|
+
✗ Same token for bg and text (bg-foreground text-foreground)
|
|
74
|
+
|
|
75
|
+
# MOBILE-FIRST APPROACH:
|
|
76
|
+
- Mobile-first design with proper breakpoints (sm:640px, md:768px, lg:1024px, xl:1280px)
|
|
77
|
+
- Smooth responsive transitions between breakpoints
|
|
78
|
+
- MD breakpoint (768px-1023px) needs special attention:
|
|
79
|
+
* Reduce grid columns gracefully (lg:4 → md:2 → sm:1)
|
|
80
|
+
* Adjust padding/spacing for tablet view
|
|
81
|
+
* Test navigation menu behavior at md breakpoint
|
|
82
|
+
* Ensure cards don't break layout at md size
|
|
83
|
+
|
|
84
|
+
IMAGE USAGE RULES:
|
|
85
|
+
- VERY IMPORTANT*: Do not use broken or non available images
|
|
86
|
+
- Use royalty-free or non-copyrighted images from Unsplash or picsum photos
|
|
87
|
+
- Choose images that are relevant to the content context
|
|
88
|
+
- Always include descriptive alt text for accessibility
|
|
89
|
+
- Use appropriate image dimensions (e.g., w=1200 for hero images, w=800 for cards, w=400 for thumbnails)
|
|
90
|
+
|
|
91
|
+
OUTPUT
|
|
92
|
+
- The final output should be clean, semantic HTML that works across all devices and screen sizes.
|
|
93
|
+
- Return the complete updated HTML (not just modified parts)
|
|
94
|
+
- Focus only on the user's request without adding extra features or elements or sections
|
|
95
|
+
- Do not add any comments in the code
|
|
96
|
+
- Keep the output simple, minimal and precisely targeted to the request
|
|
97
|
+
- NO EXPLANATION - JUST HTML!`.trim()}function oe({userInput:r,language:t="en",currentHtml:n}){const l=ee.LANGUAGES[t]||"English";return n&&n.trim().length>0?`
|
|
98
|
+
MODE: EDIT
|
|
99
|
+
CURRENT HTML:
|
|
100
|
+
${n}
|
|
101
|
+
|
|
102
|
+
USER REQUEST: ${r}
|
|
103
|
+
|
|
104
|
+
EDIT MODE INSTRUCTIONS:
|
|
105
|
+
- Modify the existing HTML based on the user's request
|
|
106
|
+
- IMPORTANT: If asked for updating content, do not change layout just update same HTML with updated content
|
|
107
|
+
- CRITICAL: THINGS TO PREVENT
|
|
108
|
+
- Preserve ALL data binding placeholders in format '{{dataBindingId}}' - never remove or modify these dynamic content markers
|
|
109
|
+
- Preserve html tag with attributes data-block-type="PartialBlock" or data-block-type="CustomBlock" - never remove or modify these tag
|
|
110
|
+
- Preserve the overall structure unless specifically asked to change it
|
|
111
|
+
- Update content, styling, or layout as requested
|
|
112
|
+
- Maintain responsive design and accessibility
|
|
113
|
+
- Keep using shadcn/ui theme classes and Tailwind CSS
|
|
114
|
+
- Ensure all chai-name attributes remain descriptive and accurate
|
|
115
|
+
- Generate content in specified language: ${l}
|
|
116
|
+
- Apply the same design principles from the system prompt
|
|
117
|
+
- Make sure the edited HTML is clean and semantic`.trim():`
|
|
118
|
+
USER REQUEST: ${r}
|
|
119
|
+
|
|
120
|
+
CREATE MODE INSTRUCTIONS:
|
|
121
|
+
- Generate complete HTML structure based on user request
|
|
122
|
+
- Use creative, modern, and responsive design
|
|
123
|
+
- Apply Tailwind CSS v3+ classes exclusively
|
|
124
|
+
- Follow shadcn/ui design patterns and theming
|
|
125
|
+
- Include proper accessibility attributes
|
|
126
|
+
- Add chai-name attributes to all wrapper/container elements
|
|
127
|
+
- Use semantic HTML structure
|
|
128
|
+
- Generate contextually appropriate content in ${l}
|
|
129
|
+
- Make each element unique and meaningful
|
|
130
|
+
- Create realistic, professional content that fits the request
|
|
131
|
+
- Avoid generic placeholder text
|
|
132
|
+
- Use strategic image placement where appropriate
|
|
133
|
+
- Ensure mobile-first responsive design
|
|
134
|
+
- Apply proper hover and focus states
|
|
135
|
+
|
|
136
|
+
DESIGN REQUIREMENTS:
|
|
137
|
+
- Choose creative layout patterns that are visually striking
|
|
138
|
+
- Apply modern spacing and typography
|
|
139
|
+
- Use proper color contrast with shadcn/ui theme classes
|
|
140
|
+
- Make it responsive across all device sizes
|
|
141
|
+
- Include interactive elements with proper states
|
|
142
|
+
- Ensure accessibility compliance`.trim()}const ae=[{label:"Navbar",prompt:"Create stunning, fully responsive navbar with"},{label:"Hero section",prompt:"Create visually compelling hero section with"},{label:"Features grid",prompt:"Create comprehensive features section with"},{label:"Contact form",prompt:"Create professional contact form with"},{label:"Testimonials",prompt:"Create engaging testimonials section with"},{label:"Pricing table",prompt:"Create modern pricing table with"},{label:"FAQ section",prompt:"Create informative FAQ section with"},{label:"Footer",prompt:"Create comprehensive footer section with"},{label:"Call to action",prompt:"Create compelling call to action section with"},{label:"Team section",prompt:"Create professional team section with"},{label:"Blog grid",prompt:"Create attractive blog grid section with"},{label:"Stats section",prompt:"Create impactful statistics section with"}],ie=[{label:"Update styles",prompt:"Update styles"},{label:"Update content",prompt:"Update text content"},{label:"Update layout",prompt:"Update layout"},{label:"Improve content",prompt:"Improve text content grammar and spelling"},{label:"Make content longer",prompt:"Make text content longer"},{label:"Make content shorter",prompt:"Make text content shorter"},{label:"Fix grammar",prompt:"Fix grammar of the text content"}],le=({onSelect:r,currentBlock:t,selectedImage:n})=>{const[l,o]=m.useState(!1),p=t?ie:ae;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:()=>o(!l),className:N.mergeClasses("flex h-6 w-full cursor-pointer items-center justify-between gap-2 px-2",t?"bg-green-50/80 text-green-500 hover:bg-green-50":"text-primary hover:bg-primary/5"),children:[e.jsx("span",{className:"truncate whitespace-nowrap text-xs font-medium leading-none",children:n?"Image actions":t?"Edit : "+(t._name||t._type):"Quick Prompts"}),e.jsx(b.ChevronsUpDown,{className:"h-3 w-3"})]}),l&&e.jsx("div",{className:"max-h-60 w-full overflow-y-auto bg-white px-1 pb-1",children:p.map((y,d)=>e.jsx("div",{className:"flex cursor-pointer items-center gap-x-1 p-1 text-xs leading-none hover:text-blue-700",onClick:()=>{r(`${n||t?"Update":"Add New"} ${y.label}`,y.prompt),o(!1)},children:e.jsxs("span",{className:"truncate whitespace-nowrap",children:[t?null:e.jsx("span",{className:"font-thin text-muted-foreground",children:"Add New"})," ",y.label]})},d))})]})},ce=({message:r})=>{var t;return((t=r==null?void 0:r.content)==null?void 0:t.length)<100?e.jsx("div",{className:"relative z-50 mb-3 flex w-full flex-col gap-2 overflow-hidden",children:e.jsxs("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:[e.jsx(b.Loader,{className:"h-3 w-3 animate-spin"})," Processing"]})}):e.jsx("div",{className:"relative z-50 mb-3 flex w-full flex-col gap-2 overflow-hidden",children:e.jsxs("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:[e.jsx(b.Loader,{className:"h-3 w-3 animate-spin"})," Generating"]})})},de=({message:r,isUser:t,isLoading:n})=>t?e.jsx("div",{className:"relative mb-3 flex w-full justify-end overflow-hidden",children:e.jsx("div",{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",children:r.userMessage})}):n?e.jsx(ce,{message:r}):e.jsx("div",{className:`relative mb-3 flex w-full overflow-hidden ${t?"justify-end":n?"max-h-48 min-h-24 justify-start":"max-h-16"}`,children:e.jsxs("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:[e.jsx(b.CheckCircle,{className:"h-3 w-3"})," Completed"]})}),ue=({input:r,setInput:t,onSend:n,onStop:l,isLoading:o,disabled:p,currentBlock:y})=>{const d=m.useRef(null),v=m.useRef(null),[a,w]=m.useState(null),c=s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),r.trim()&&!o&&(n(r==null?void 0:r.trim(),void 0,a||void 0),w(null)))},E=()=>{const s=d.current;s&&(s.style.height="auto",s.style.height=Math.min(s.scrollHeight,120)+"px")},u=s=>{var S;const f=(S=s.target.files)==null?void 0:S[0];if(f&&f.type.startsWith("image/")){const j=new FileReader;j.onload=L=>{var i,g;const O=(i=L.target)==null?void 0:i.result;w(O),t("Generate UI based on given image "),(g=d.current)==null||g.focus()},j.readAsDataURL(f)}s.target.value=""},T=()=>{var s;(s=v.current)==null||s.click()},A=()=>{n(r==null?void 0:r.trim(),void 0,a||void 0),w(null)};return m.useEffect(()=>{E()},[r]),e.jsxs("div",{children:[!a&&e.jsx("div",{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 ${o?"pointer-events-none opacity-50":""}`,children:e.jsx(le,{currentBlock:y,selectedImage:a,onSelect:(s,f)=>{var S;t(f+" "),(S=d.current)==null||S.focus()}})}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white",children:[a&&e.jsxs("div",{className:"relative flex w-max items-center justify-start gap-x-2 px-2 pt-2",children:[e.jsx("img",{src:a,alt:"Selected attachment",className:"max-h-16 max-w-full rounded-md border"}),e.jsx("button",{onClick:()=>w(null),className:"absolute -right-0 -top-0 flex items-center rounded-full bg-red-400 p-1 text-xs text-white hover:bg-red-500",title:"Remove image",children:e.jsx(b.X,{className:"h-2 w-2"})})]}),e.jsx("textarea",{ref:d,value:r,onChange:s=>t(s.target.value),onKeyDown:c,placeholder:"Ask me anything...",className:`max-h-[200px] min-h-[60px] w-full resize-none rounded-lg border-none px-3 py-2 text-sm outline-none ${o?"cursor-not-allowed opacity-50":""}`,rows:3,disabled:o}),e.jsxs("div",{className:"flex items-center justify-between p-2",children:[e.jsx("button",{disabled:o,onClick:T,className:`p-1.5 text-gray-400 hover:text-gray-500 ${o?"cursor-not-allowed opacity-50":""}`,title:"Attach Image",children:e.jsx(b.Paperclip,{size:16})}),e.jsx("input",{disabled:o,ref:v,type:"file",accept:"image/*",onChange:u,className:"hidden"}),o?e.jsx("button",{onClick:l,className:"z-50 rounded-md bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:"Stop generation",children:e.jsx(b.Square,{size:16})}):e.jsx("button",{onClick:A,disabled:!r.trim()||p,className:`rounded-md bg-blue-500 p-1.5 text-white transition-colors hover:bg-blue-600 ${!r.trim()||p?"cursor-not-allowed opacity-50":""}`,children:e.jsx(b.Send,{size:16})})]})]})]})},me=()=>{const[r,t]=m.useState(""),[n,l]=m.useState([{role:"system",content:$(),id:"system"}]),[o,p]=m.useState(!1),[y,d]=m.useState(null),v=m.useRef(null),{addPredefinedBlock:a}=N.useAddBlock(),w=N.useRemoveBlocks(),c=N.useSelectedBlock(),[E,u]=m.useState(null),[T]=N.useBlocksStore(),{selectedLang:A,fallbackLang:s}=N.useLanguages(),f=A||s,S=()=>{var i;(i=v.current)==null||i.scrollIntoView({behavior:"smooth"})};m.useEffect(()=>{S()},[n,o]);const j=()=>{y&&(y.abort(),d(null)),p(!1),t(""),u(null),l(i=>{const g=i[i.length-1];return g&&g.role==="assistant"&&!g.content.trim()?i.slice(0,-1):i}),Y.toast.info("Generation stopped")},L=async(i,g,D)=>{var G;if(!i||o)return;const x=c;u(c);const{position:K,currentHTML:F}=se((c==null?void 0:c._id)||"",T);if(c&&!F){Y.toast.error("Something went wrong. Please try again.");return}const B={id:Date.now().toString(),role:"user",content:oe({userInput:g||i,language:f,currentHtml:c?F:""}),userMessage:i},q={id:Date.now().toString(),role:"assistant",content:""};l(k=>[...k,B,q]),p(!0);const _=new AbortController;d(_);try{const k={messages:[...n,B].map(h=>({role:h.role,content:h.content}))};D&&(k.image=D);const M=await fetch("/chai/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k),signal:_.signal});if(!M.ok)throw new Error("Failed to get AI response");const R=(G=M.body)==null?void 0:G.getReader(),Q=new TextDecoder;let U="";if(!R)throw new Error("Response body is not readable");for(;;){const{done:h,value:I}=await R.read();if(h)break;const H=Q.decode(I,{stream:!0});U+=H,l(z=>z.map(P=>P.id===q.id?{...P,content:U}:P))}const X=re(U),J=N.getBlocksFromHTML(X),W=C.map(J,h=>{const I=C.get(h,"styles_attrs.data-block-type");if(I&&!V.includes(I)){const H=C.get(h,"styles_attrs.data-block-id");return{...C.find(T,{_id:H}),_parent:h==null?void 0:h._parent}}return h});x!=null&&x._id&&w([x==null?void 0:x._id]),a([...W],x==null?void 0:x._parent,x?K:-1)}catch(k){if(k.name!=="AbortError"){const M={id:(Date.now()+1).toString(),role:"assistant",content:"Sorry, I encountered an error. Please try again."};l(R=>[...R,M])}}finally{t(""),p(!1),u(null),d(null)}},O=()=>{l([{role:"system",content:$(),id:"system"}]),t(""),u(null),d(null),p(!1)};return e.jsxs(e.Fragment,{children:[o&&e.jsx("div",{className:"fixed inset-0 left-0 top-0 z-40 flex h-screen w-screen flex-col items-center justify-center bg-transparent"}),e.jsxs("div",{className:"flex h-full w-full flex-col bg-white",children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("p",{className:"text-xs text-gray-500",children:"Your conversation will not be saved"}),(n==null?void 0:n.length)>1&&e.jsx(Z.Button,{variant:"outline",size:"icon",onClick:O,className:"h-6 w-6",children:e.jsx(b.Plus,{})})]}),e.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:[n.length===1&&e.jsx("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:e.jsxs("div",{className:"mx-auto mt-8 text-center text-gray-500",children:[e.jsx(b.Bot,{size:48,className:"mx-auto mb-4 text-gray-300"}),e.jsx("p",{className:"mx-auto max-w-[75%] text-sm",children:"Start a conversation with the AI assistant to generate and update your sections"})]})}),n.map((i,g)=>i.role!=="system"&&e.jsx(de,{message:i,isUser:i.role==="user",isLoading:i.role==="assistant"&&o&&g===n.length-1},g)),e.jsx("div",{ref:v})]}),e.jsx("div",{className:"border-gray-200 pb-2",children:e.jsx(ue,{input:r,setInput:t,onSend:L,onStop:j,isLoading:o,currentBlock:c||E,disabled:(r==null?void 0:r.length)===0})})]})]})};exports.default=me;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as i, jsxs as r } from "react/jsx-runtime";
|
|
2
|
-
import { i as f, m as w, h as y, L as S } from "./index-
|
|
2
|
+
import { i as f, m as w, h as y, L as S } from "./index-D2g32O6h.js";
|
|
3
3
|
import { useTranslation as v, useLanguages as L, useSidebarActivePanel as x } from "@chaibuilder/sdk";
|
|
4
4
|
import { Dialog as A, DialogContent as k, DialogHeader as C, DialogTitle as N, DialogDescription as g, DialogFooter as E, Button as c } from "@chaibuilder/sdk/ui";
|
|
5
5
|
import { get as U } from "lodash-es";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("./index-CZxeSGRk.cjs"),c=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),y=require("lodash-es");function S({page:e,onClose:l}){const{t}=c.useTranslation(),[,d]=r.useSearchParams(),{mutate:u,isPending:a}=r.useDeletePage(),{data:o}=r.usePageTypes(),{setSelectedLang:h,fallbackLang:m}=c.useLanguages(),[,x]=c.useSidebarActivePanel(),P=()=>{a||u(e,{onSuccess:()=>{e!=null&&e.primaryPage?(window.history.replaceState({},"",`/?page=${e.primaryPage}`),d(new URLSearchParams({page:e.primaryPage}))):(window.history.replaceState({},"","/"),d(new URLSearchParams)),window.dispatchEvent(new PopStateEvent("popstate")),h(m),x("outline"),l()}})},i=o==null?void 0:o.find(D=>D.key===(e==null?void 0:e.pageType));return n.jsx(s.Dialog,{open:!!e,onOpenChange:l,children:n.jsxs(s.DialogContent,{children:[n.jsxs(s.DialogHeader,{children:[n.jsx(s.DialogTitle,{children:t("Confirm Deletion")}),n.jsxs(s.DialogDescription,{className:"py-4 text-slate-500",children:[n.jsxs("div",{children:[t("Are you sure you want to remove")," ",n.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)})," ",i!=null&&i.hasSlug?(i==null?void 0:i.name)+"?":`${t("page?")} ${e!=null&&e.primaryPage?"":t("This will also delete all associated language pages.")}`]}),e.lang&&n.jsxs("div",{className:"py-2 text-sm",children:[t("Language"),": ",n.jsx("span",{className:"font-medium text-gray-500",children:y.get(r.LANGUAGES,e.lang,e.lang)})]})]})]}),n.jsxs(s.DialogFooter,{children:[n.jsx(s.Button,{variant:"outline",onClick:l,children:t("Cancel")}),n.jsx(s.Button,{variant:"destructive",disabled:a,onClick:P,children:t(a?"Deleting...":"Delete")})]})]})})}exports.default=S;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),F=require("lodash-es"),f=require("lucide-react"),u=require("react"),fe=require("react-dropzone"),g=require("./index-DOlBrCPx.cjs"),w=require("sonner"),Y=require("./image-compression-DZ9WMmyn.cjs"),z=require("@tanstack/react-query"),pe=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>{const o=i.map(async l=>x(n,{action:g.ACTIONS.UPLOAD_ASSET,data:l}));return await Promise.all(o)},onSuccess:i=>{var o;if(i!=null&&i.some(s=>s.error))throw new Error(((o=i==null?void 0:i.find(s=>s.error))==null?void 0:o.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]});const s=i==null?void 0:i.length;w.toast.success(`${s===1?"Asset":s+" Assets"} uploaded successfully`)}},onError:()=>{w.toast.error("Failed to upload asset")}})},ge=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.DELETE_ASSET,data:{id:i}}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},je=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.UPDATE_ASSET,data:i}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),i!=null&&i.id&&r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSET,i.id]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})};function ve({currentPage:n,totalPages:r,onPageChange:x,pageRangeDisplayed:i=3,showPageInput:o=!0,className:s=""}){const[l,E]=u.useState(String(n)),N=u.useMemo(()=>{const c=Math.floor(i/2);let m=Math.max(1,n-c),d=Math.min(r,n+c);d-m+1<i&&(m===1?d=Math.min(r,m+i-1):d===r&&(m=Math.max(1,d-i+1)));const p=[];m>1&&(p.push(1),m>2&&p.push("..."));for(let y=m;y<=d;y++)p.push(y);return d<r&&(d<r-1&&p.push("..."),p.push(r)),p},[n,r,i]),v=c=>{c!==n&&c>=1&&c<=r&&(x(c),E(String(c)))},j=()=>{n>1&&v(n-1)},b=()=>{n<r&&v(n+1)},C=()=>{const c=Number(l);!isNaN(c)&&c>=1&&c<=r&&v(c)},A=c=>{c.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${s}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:j,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((c,m)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const d=c,p=d===n;return e.jsx(a.Button,{variant:p?"default":"outline",size:"sm",onClick:()=>v(d),className:p?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:d},d)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:b,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),o&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:l,onChange:c=>{const m=c.target.value.replace(/[^\d]/g,"");E(m)},onKeyDown:A,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:l===""||Number(l)<1||Number(l)>r,children:"Go"})]})]})}const ye=(n={})=>{const r=g.useAssetsApiUrl(),x=g.useFetch(),{search:i,page:o=1,limit:s=30}=n;return z.useQuery({queryKey:[g.ACTIONS.GET_ASSETS,i,o,s],queryFn:async()=>{const l=await x(r,{action:g.ACTIONS.GET_ASSETS,data:{search:i,page:o,limit:s}});return l.page=o,l.limit=s,l},staleTime:1/0,retry:1})},Ne=n=>{const r=g.useAssetsApiUrl(),x=g.useFetch();return z.useQuery({queryKey:[g.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await x(r,{action:g.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function be(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function Z(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function J(n,r){let x=n,i=r==null?void 0:r.description;return(!i||typeof i!="string")&&(i=""),(!x||typeof x!="string")&&(x=""),x!==i}const we=({assetId:n,onBack:r,onEdit:x,onSave:i,isSaving:o})=>{var c,m;const{t:s}=M.useTranslation(),{data:l,isLoading:E,isError:N}=Ne(n||""),[v,j]=u.useState(""),[b,C]=u.useState(!1);u.useEffect(()=>{const d=new Image;return d.src=(l==null?void 0:l.url)||"",d.onload=()=>C(!0),()=>{d.onload=null}},[l]);const A=async(d,p)=>{try{await navigator.clipboard.writeText(d),w.toast.success(s("{{type}} copied to clipboard",{type:p}))}catch(y){w.toast.error(s("Failed to copy {{type}}",{type:p}),{description:y==null?void 0:y.message})}};return u.useEffect(()=>{l!=null&&l.description&&j(l.description)},[l]),E||!b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):N||!(l!=null&&l.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(f.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:s("No Asset Found")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:s(N?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed.")}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:s("Back to Assets")}),N&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:s("Try Again")})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:o,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),s("Back to Assets")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:o,children:s("Cancel")}),e.jsxs(a.Button,{variant:"outline",onClick:()=>A(l.url,s("Asset URL")),disabled:o,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),s("Copy URL")]}),e.jsxs(a.Button,{variant:"default",onClick:()=>x(l),disabled:o,children:[e.jsx(f.Pencil,{className:"h-4 w-4"}),s("Edit Image")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:l.url,alt:l.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Details")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:s("File Name"),value:l.name},{label:s("Type"),value:l.type,capitalize:!0},{label:s("Format"),value:((c=l.metadata)==null?void 0:c.format)||l.type,capitalize:!0},{label:s("Size"),value:be(l.size)},{label:s("Dimensions"),value:`${l.width||0} × ${l.height||0}`},{label:s("Created"),value:Z(l.createdAt)},{label:s("Updated"),value:Z(((m=l.metadata)==null?void 0:m.updatedAt)||(l==null?void 0:l.updatedAt)||l.createdAt)},{label:s("URL"),value:l.url,copyable:!0}].map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:d.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(d.capitalize?" capitalize":""),children:d.value}),d.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(d.value,d.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},d.label))})]}),l.usedOn&&l.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:s("Used On")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:l.usedOn.map((d,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:d.name}),e.jsxs("div",{className:"text-gray-500",children:["(",d.slug,")"]})]},p))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Description")}),e.jsx(a.Textarea,{id:"description",value:v,placeholder:s("Enter a description for the asset"),onChange:d=>j(d.target.value),rows:3,disabled:o,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>i(v),disabled:o||!J(v,l),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o||!J(v,l)?"opacity-50 cursor-not-allowed":""}`,children:o?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),s("Saving...")]}):s("Save")})})]})]})]})]})},Ce=u.lazy(()=>Promise.resolve().then(()=>require("./image-editor-CnDnY97s.cjs"))),Ae=25*1024*1024,Se=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:x,isUploadingAsset:i,onUploaded:o})=>{const{t:s}=M.useTranslation(),[l,E]=u.useState(()=>{const c=localStorage.getItem("chai_optimize_images");return c!==null?c==="true":!0});u.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const N=n||i,v=u.useCallback(async c=>{try{const m=c;if(!m.every(S=>S.type.startsWith("image/")))return w.toast.error(s("Invalid file type. Please upload a valid file.")),Promise.reject(new Error("Invalid file type"));const d=m.map(async S=>{let U=S;return S.type.startsWith("image/")&&(U=await Y.compressImageIfNeeded(S)),new Promise((_,B)=>{const L=new FileReader;L.readAsDataURL(U),L.onload=async()=>{_({file:L.result,folderId:void 0,name:S.name,optimize:l})},L.onerror=()=>B(null)})}),p=await Promise.all(d),y=await x(p);return(y==null?void 0:y.length)===1&&o(y[0]),y}catch(m){return Promise.reject(m)}},[x,l,o,s]),j=c=>{const m=[];let d=0;return c.forEach(p=>{p.size>Ae?d++:m.push(p)}),d>0&&w.toast.error(`${d===1&&c.length===1?s("File"):d+s(d===1?" file":" files")} ${s("exceed the maximum size limit of 10MB.")}`),F.isEmpty(m)?[]:v(m)},{getRootProps:b,getInputProps:C,isDragActive:A}=fe.useDropzone({onDrop:j,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||i,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${N?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...b(),className:M.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",N?"items-start":"items-center",A?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...C()}),N?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(f.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:s(n?"Updating file...":"Uploading file...")}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:[s("Please wait while we")," ",s(n?"update":"upload")," ",s("your file...")]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(f.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:[s("Drop your file here or")," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:s("browse")})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:[s("Accepted file types:")," ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:[s("Optimization:")," "," ",e.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:s(l?"On":"Off")})]}),e.jsx(a.Switch,{checked:l,onCheckedChange:c=>{E(c)},onClick:c=>{c.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${l?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsx("p",{className:"text-xs text-white",children:s("Warning: Unoptimized images may affect performance and page load times")})})]})})]})]})]})})};function Te({close:n,onSelect:r,mode:x="image",assetId:i}){const{t:o}=M.useTranslation(),s=!1,l=10,E=u.useMemo(()=>[x],[x]),[N,v]=u.useState(null),[j,b]=u.useState(null),[C,A]=u.useState(null),[c,m]=u.useState({show:!1,file:""}),[d,p]=u.useState(!1),[y,S]=u.useState(i?"details":"grid"),[U,_]=u.useState(""),[B,L]=u.useState(""),[P,Q]=u.useState(1),[R]=u.useState(30),[T,G]=u.useState([]);u.useEffect(()=>{i&&(v(i),S("details"))},[i]),u.useEffect(()=>{const t=setTimeout(()=>{_(B),Q(1)},300);return()=>clearTimeout(t)},[B]);const{data:q,isLoading:$,refetch:ee}=ye({search:U.toLowerCase().trim(),page:P,limit:R}),D=(q==null?void 0:q.assets)||[],te=(q==null?void 0:q.total)||0,I=Math.ceil(te/R);u.useEffect(()=>{$||I<=0||Q(t=>t>I?I:t<1?1:t)},[$,I]);const se=(D==null?void 0:D.length)>0,{mutate:ie}=ge(),{mutateAsync:K,isPending:le}=pe(),{mutateAsync:W,isPending:ae}=je(),V=u.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,I));h!==P&&Q(h)},[I,P]),re=t=>{L(t.target.value)},ne=u.useCallback(t=>{G(h=>F.find(h,{id:t.id})?[]:[t])},[s]),oe=u.useCallback(()=>{G([])},[]),H=t=>{(t==null?void 0:t.length)!==0&&(r(F.pick(F.first(t||T),["id","url","width","height","description"])),n())},ce=async t=>{b(t)},de=async()=>{j&&(A(j==null?void 0:j.id),await ie(j.id,{onSuccess:()=>{A(null),b(null)},onError:()=>{A(null)}}),b(null))},ue=t=>{v(t.id),S("details")},me=async(t,h)=>{try{const O=localStorage.getItem("chai_optimize_images")!=="false";if(h){const k=await K([{file:t,folderId:void 0,name:c.name||"",optimize:O}]);if((k==null?void 0:k.length)>0){const X=k[0];r({...F.pick(X,["id","width","height","description"]),url:X.url})}}else{const k=await W({id:c.id||"",file:t});k&&r({...F.pick(k,["id","width","height","description"]),url:k.url})}m({show:!1,file:""}),n()}catch(O){console.error(o("Error saving edited image:"),O)}},he=u.useCallback(t=>{G([t])},[]),xe=u.useCallback(t=>{V(t)},[V]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:o("Digital Asset Manager")}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{maxFileSize:l,allowedTypes:E,uploadAssets:K,isUpdatingAsset:ae,isUploadingAsset:le,onUploaded:he}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:o("Search assets..."),onChange:re,value:B,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>oe(),title:o("Clear selection"),children:o("Clear")})}),e.jsx(a.Button,{size:"sm",onClick:()=>H(T),disabled:T.length===0,children:o("Select Asset")})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>ee(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:$?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!$&&!se?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(f.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:o("No assets found")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:U.length>0?o("No assets found for your search: {{query}}",{query:U}):o("Start uploading assets to get started")}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:D==null?void 0:D.map(t=>e.jsxs("div",{className:M.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",C&&(j==null?void 0:j.id)===t.id?"pointer-events-none opacity-50":"",C===t.id?"pointer-events-none opacity-50":""),onClick:()=>ne(t),onDoubleClick:()=>H([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[C===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(f.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Y.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ue(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("View Details")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),w.toast.success(o("Asset URL copied to clipboard"))},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Copy URL")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),m({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Edit Image")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Delete Asset")})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(f.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),I>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(g.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:o("Error loading pagination")}),children:e.jsx(ve,{currentPage:P,totalPages:I,onPageChange:xe,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(we,{assetId:N||i||"",onBack:()=>{S("grid"),v(null)},onEdit:t=>{m({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(N){p(!0);try{const h=D.find(O=>O.id===N);h&&await W(F.merge(h,{description:t}))}finally{p(!1)}}},isSaving:d})]}),c.show&&e.jsx(u.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ce,{imageUrl:c.file,onSave:me,onClose:()=>m({show:!1,file:""}),defaultSavedImageName:c.name,isEditing:!!c.id})}),j&&e.jsx(a.Dialog,{open:!!j,onOpenChange:()=>b(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:o("Delete Asset")}),e.jsx(a.DialogDescription,{children:o('Are you sure you want to delete "{{name}}"? This action cannot be undone.',{name:j.name})})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>b(null),children:o("Cancel")}),e.jsx(a.Button,{variant:"destructive",onClick:de,children:o("Delete")})]})]})})]})}exports.default=Te;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),F=require("lodash-es"),f=require("lucide-react"),u=require("react"),fe=require("react-dropzone"),g=require("./index-CZxeSGRk.cjs"),w=require("sonner"),Y=require("./image-compression-DZ9WMmyn.cjs"),z=require("@tanstack/react-query"),pe=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>{const o=i.map(async l=>x(n,{action:g.ACTIONS.UPLOAD_ASSET,data:l}));return await Promise.all(o)},onSuccess:i=>{var o;if(i!=null&&i.some(s=>s.error))throw new Error(((o=i==null?void 0:i.find(s=>s.error))==null?void 0:o.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]});const s=i==null?void 0:i.length;w.toast.success(`${s===1?"Asset":s+" Assets"} uploaded successfully`)}},onError:()=>{w.toast.error("Failed to upload asset")}})},ge=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.DELETE_ASSET,data:{id:i}}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},je=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.UPDATE_ASSET,data:i}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),i!=null&&i.id&&r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSET,i.id]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})};function ve({currentPage:n,totalPages:r,onPageChange:x,pageRangeDisplayed:i=3,showPageInput:o=!0,className:s=""}){const[l,E]=u.useState(String(n)),N=u.useMemo(()=>{const c=Math.floor(i/2);let m=Math.max(1,n-c),d=Math.min(r,n+c);d-m+1<i&&(m===1?d=Math.min(r,m+i-1):d===r&&(m=Math.max(1,d-i+1)));const p=[];m>1&&(p.push(1),m>2&&p.push("..."));for(let y=m;y<=d;y++)p.push(y);return d<r&&(d<r-1&&p.push("..."),p.push(r)),p},[n,r,i]),v=c=>{c!==n&&c>=1&&c<=r&&(x(c),E(String(c)))},j=()=>{n>1&&v(n-1)},b=()=>{n<r&&v(n+1)},C=()=>{const c=Number(l);!isNaN(c)&&c>=1&&c<=r&&v(c)},A=c=>{c.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${s}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:j,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((c,m)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const d=c,p=d===n;return e.jsx(a.Button,{variant:p?"default":"outline",size:"sm",onClick:()=>v(d),className:p?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:d},d)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:b,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),o&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:l,onChange:c=>{const m=c.target.value.replace(/[^\d]/g,"");E(m)},onKeyDown:A,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:l===""||Number(l)<1||Number(l)>r,children:"Go"})]})]})}const ye=(n={})=>{const r=g.useAssetsApiUrl(),x=g.useFetch(),{search:i,page:o=1,limit:s=30}=n;return z.useQuery({queryKey:[g.ACTIONS.GET_ASSETS,i,o,s],queryFn:async()=>{const l=await x(r,{action:g.ACTIONS.GET_ASSETS,data:{search:i,page:o,limit:s}});return l.page=o,l.limit=s,l},staleTime:1/0,retry:1})},Ne=n=>{const r=g.useAssetsApiUrl(),x=g.useFetch();return z.useQuery({queryKey:[g.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await x(r,{action:g.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function be(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function Z(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function J(n,r){let x=n,i=r==null?void 0:r.description;return(!i||typeof i!="string")&&(i=""),(!x||typeof x!="string")&&(x=""),x!==i}const we=({assetId:n,onBack:r,onEdit:x,onSave:i,isSaving:o})=>{var c,m;const{t:s}=M.useTranslation(),{data:l,isLoading:E,isError:N}=Ne(n||""),[v,j]=u.useState(""),[b,C]=u.useState(!1);u.useEffect(()=>{const d=new Image;return d.src=(l==null?void 0:l.url)||"",d.onload=()=>C(!0),()=>{d.onload=null}},[l]);const A=async(d,p)=>{try{await navigator.clipboard.writeText(d),w.toast.success(s("{{type}} copied to clipboard",{type:p}))}catch(y){w.toast.error(s("Failed to copy {{type}}",{type:p}),{description:y==null?void 0:y.message})}};return u.useEffect(()=>{l!=null&&l.description&&j(l.description)},[l]),E||!b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):N||!(l!=null&&l.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(f.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:s("No Asset Found")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:s(N?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed.")}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:s("Back to Assets")}),N&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:s("Try Again")})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:o,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),s("Back to Assets")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:o,children:s("Cancel")}),e.jsxs(a.Button,{variant:"outline",onClick:()=>A(l.url,s("Asset URL")),disabled:o,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),s("Copy URL")]}),e.jsxs(a.Button,{variant:"default",onClick:()=>x(l),disabled:o,children:[e.jsx(f.Pencil,{className:"h-4 w-4"}),s("Edit Image")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:l.url,alt:l.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Details")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:s("File Name"),value:l.name},{label:s("Type"),value:l.type,capitalize:!0},{label:s("Format"),value:((c=l.metadata)==null?void 0:c.format)||l.type,capitalize:!0},{label:s("Size"),value:be(l.size)},{label:s("Dimensions"),value:`${l.width||0} × ${l.height||0}`},{label:s("Created"),value:Z(l.createdAt)},{label:s("Updated"),value:Z(((m=l.metadata)==null?void 0:m.updatedAt)||(l==null?void 0:l.updatedAt)||l.createdAt)},{label:s("URL"),value:l.url,copyable:!0}].map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:d.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(d.capitalize?" capitalize":""),children:d.value}),d.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(d.value,d.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},d.label))})]}),l.usedOn&&l.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:s("Used On")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:l.usedOn.map((d,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:d.name}),e.jsxs("div",{className:"text-gray-500",children:["(",d.slug,")"]})]},p))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Description")}),e.jsx(a.Textarea,{id:"description",value:v,placeholder:s("Enter a description for the asset"),onChange:d=>j(d.target.value),rows:3,disabled:o,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>i(v),disabled:o||!J(v,l),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o||!J(v,l)?"opacity-50 cursor-not-allowed":""}`,children:o?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),s("Saving...")]}):s("Save")})})]})]})]})]})},Ce=u.lazy(()=>Promise.resolve().then(()=>require("./image-editor-CnDnY97s.cjs"))),Ae=25*1024*1024,Se=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:x,isUploadingAsset:i,onUploaded:o})=>{const{t:s}=M.useTranslation(),[l,E]=u.useState(()=>{const c=localStorage.getItem("chai_optimize_images");return c!==null?c==="true":!0});u.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const N=n||i,v=u.useCallback(async c=>{try{const m=c;if(!m.every(S=>S.type.startsWith("image/")))return w.toast.error(s("Invalid file type. Please upload a valid file.")),Promise.reject(new Error("Invalid file type"));const d=m.map(async S=>{let U=S;return S.type.startsWith("image/")&&(U=await Y.compressImageIfNeeded(S)),new Promise((_,B)=>{const L=new FileReader;L.readAsDataURL(U),L.onload=async()=>{_({file:L.result,folderId:void 0,name:S.name,optimize:l})},L.onerror=()=>B(null)})}),p=await Promise.all(d),y=await x(p);return(y==null?void 0:y.length)===1&&o(y[0]),y}catch(m){return Promise.reject(m)}},[x,l,o,s]),j=c=>{const m=[];let d=0;return c.forEach(p=>{p.size>Ae?d++:m.push(p)}),d>0&&w.toast.error(`${d===1&&c.length===1?s("File"):d+s(d===1?" file":" files")} ${s("exceed the maximum size limit of 10MB.")}`),F.isEmpty(m)?[]:v(m)},{getRootProps:b,getInputProps:C,isDragActive:A}=fe.useDropzone({onDrop:j,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||i,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${N?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...b(),className:M.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",N?"items-start":"items-center",A?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...C()}),N?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(f.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:s(n?"Updating file...":"Uploading file...")}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:[s("Please wait while we")," ",s(n?"update":"upload")," ",s("your file...")]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(f.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:[s("Drop your file here or")," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:s("browse")})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:[s("Accepted file types:")," ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:[s("Optimization:")," "," ",e.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:s(l?"On":"Off")})]}),e.jsx(a.Switch,{checked:l,onCheckedChange:c=>{E(c)},onClick:c=>{c.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${l?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsx("p",{className:"text-xs text-white",children:s("Warning: Unoptimized images may affect performance and page load times")})})]})})]})]})]})})};function Te({close:n,onSelect:r,mode:x="image",assetId:i}){const{t:o}=M.useTranslation(),s=!1,l=10,E=u.useMemo(()=>[x],[x]),[N,v]=u.useState(null),[j,b]=u.useState(null),[C,A]=u.useState(null),[c,m]=u.useState({show:!1,file:""}),[d,p]=u.useState(!1),[y,S]=u.useState(i?"details":"grid"),[U,_]=u.useState(""),[B,L]=u.useState(""),[P,Q]=u.useState(1),[R]=u.useState(30),[T,G]=u.useState([]);u.useEffect(()=>{i&&(v(i),S("details"))},[i]),u.useEffect(()=>{const t=setTimeout(()=>{_(B),Q(1)},300);return()=>clearTimeout(t)},[B]);const{data:q,isLoading:$,refetch:ee}=ye({search:U.toLowerCase().trim(),page:P,limit:R}),D=(q==null?void 0:q.assets)||[],te=(q==null?void 0:q.total)||0,I=Math.ceil(te/R);u.useEffect(()=>{$||I<=0||Q(t=>t>I?I:t<1?1:t)},[$,I]);const se=(D==null?void 0:D.length)>0,{mutate:ie}=ge(),{mutateAsync:K,isPending:le}=pe(),{mutateAsync:W,isPending:ae}=je(),V=u.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,I));h!==P&&Q(h)},[I,P]),re=t=>{L(t.target.value)},ne=u.useCallback(t=>{G(h=>F.find(h,{id:t.id})?[]:[t])},[s]),oe=u.useCallback(()=>{G([])},[]),H=t=>{(t==null?void 0:t.length)!==0&&(r(F.pick(F.first(t||T),["id","url","width","height","description"])),n())},ce=async t=>{b(t)},de=async()=>{j&&(A(j==null?void 0:j.id),await ie(j.id,{onSuccess:()=>{A(null),b(null)},onError:()=>{A(null)}}),b(null))},ue=t=>{v(t.id),S("details")},me=async(t,h)=>{try{const O=localStorage.getItem("chai_optimize_images")!=="false";if(h){const k=await K([{file:t,folderId:void 0,name:c.name||"",optimize:O}]);if((k==null?void 0:k.length)>0){const X=k[0];r({...F.pick(X,["id","width","height","description"]),url:X.url})}}else{const k=await W({id:c.id||"",file:t});k&&r({...F.pick(k,["id","width","height","description"]),url:k.url})}m({show:!1,file:""}),n()}catch(O){console.error(o("Error saving edited image:"),O)}},he=u.useCallback(t=>{G([t])},[]),xe=u.useCallback(t=>{V(t)},[V]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:o("Digital Asset Manager")}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{maxFileSize:l,allowedTypes:E,uploadAssets:K,isUpdatingAsset:ae,isUploadingAsset:le,onUploaded:he}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:o("Search assets..."),onChange:re,value:B,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>oe(),title:o("Clear selection"),children:o("Clear")})}),e.jsx(a.Button,{size:"sm",onClick:()=>H(T),disabled:T.length===0,children:o("Select Asset")})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>ee(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:$?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!$&&!se?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(f.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:o("No assets found")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:U.length>0?o("No assets found for your search: {{query}}",{query:U}):o("Start uploading assets to get started")}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:D==null?void 0:D.map(t=>e.jsxs("div",{className:M.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",C&&(j==null?void 0:j.id)===t.id?"pointer-events-none opacity-50":"",C===t.id?"pointer-events-none opacity-50":""),onClick:()=>ne(t),onDoubleClick:()=>H([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[C===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(f.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Y.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ue(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("View Details")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),w.toast.success(o("Asset URL copied to clipboard"))},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Copy URL")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),m({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Edit Image")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Delete Asset")})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(f.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),I>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(g.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:o("Error loading pagination")}),children:e.jsx(ve,{currentPage:P,totalPages:I,onPageChange:xe,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(we,{assetId:N||i||"",onBack:()=>{S("grid"),v(null)},onEdit:t=>{m({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(N){p(!0);try{const h=D.find(O=>O.id===N);h&&await W(F.merge(h,{description:t}))}finally{p(!1)}}},isSaving:d})]}),c.show&&e.jsx(u.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ce,{imageUrl:c.file,onSave:me,onClose:()=>m({show:!1,file:""}),defaultSavedImageName:c.name,isEditing:!!c.id})}),j&&e.jsx(a.Dialog,{open:!!j,onOpenChange:()=>b(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:o("Delete Asset")}),e.jsx(a.DialogDescription,{children:o('Are you sure you want to delete "{{name}}"? This action cannot be undone.',{name:j.name})})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>b(null),children:o("Cancel")}),e.jsx(a.Button,{variant:"destructive",onClick:de,children:o("Delete")})]})]})})]})}exports.default=Te;
|
|
@@ -5,7 +5,7 @@ import { find as Ge, merge as Oe, pick as Y, first as Be, isEmpty as Ke } from "
|
|
|
5
5
|
import { ChevronLeft as he, ChevronRight as Qe, Loader as B, AlertCircle as Re, Copy as fe, Pencil as We, Link as Ve, Search as He, RefreshCwIcon as Xe, Archive as Ze, Film as Je, ImageIcon as Ye, Edit as et, Trash2 as tt, Check as it, Upload as lt, AlertTriangle as at } from "lucide-react";
|
|
6
6
|
import pe, { useState as y, useMemo as ge, useEffect as O, useCallback as M, Suspense as rt } from "react";
|
|
7
7
|
import { useDropzone as nt } from "react-dropzone";
|
|
8
|
-
import { aL as K, al as Q, A as b, aM as st } from "./index-
|
|
8
|
+
import { aL as K, al as Q, A as b, aM as st } from "./index-D2g32O6h.js";
|
|
9
9
|
import { toast as A } from "sonner";
|
|
10
10
|
import { f as ct, c as ot } from "./image-compression-DsZ1oqpb.js";
|
|
11
11
|
import { useQueryClient as te, useMutation as ie, useQuery as xe } from "@tanstack/react-query";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as t, jsxs as a } from "react/jsx-runtime";
|
|
2
|
-
import { ak as C, al as A, A as T, am as w } from "./index-
|
|
2
|
+
import { ak as C, al as A, A as T, am as w } from "./index-D2g32O6h.js";
|
|
3
3
|
import { useQueryClient as F, useMutation as _ } from "@tanstack/react-query";
|
|
4
4
|
import { toast as v } from "sonner";
|
|
5
5
|
import { useTranslation as q } from "@chaibuilder/sdk";
|
|
@@ -7,7 +7,7 @@ import { Dialog as G, DialogContent as L, DialogHeader as U, DialogTitle as j, D
|
|
|
7
7
|
import { isEmpty as B, initial as M } from "lodash-es";
|
|
8
8
|
import { AlertCircle as Q } from "lucide-react";
|
|
9
9
|
import { useState as p } from "react";
|
|
10
|
-
import { S as V } from "./slug-input-
|
|
10
|
+
import { S as V } from "./slug-input-Bh4d19p2.js";
|
|
11
11
|
const H = () => {
|
|
12
12
|
const s = C(), o = F(), g = A();
|
|
13
13
|
return _({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-CZxeSGRk.cjs"),N=require("@tanstack/react-query"),v=require("sonner"),E=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),P=require("lodash-es"),C=require("lucide-react"),g=require("react"),A=require("./slug-input-DYne39yC.cjs"),T=()=>{const t=p.useApiUrl(),u=N.useQueryClient(),h=p.useFetch();return N.useMutation({mutationFn:async({pageId:s,name:x,slug:r})=>{const o={pageId:s,name:x};return r&&(o.slug=r),await h(t,{action:"DUPLICATE_PAGE",data:o})},onSuccess:()=>{u.invalidateQueries({queryKey:[p.ACTIONS.GET_WEBSITE_PAGES]}),v.toast.success("Page duplicated successfully")},onError:s=>{v.toast.error("Failed to duplicate page",{description:s.message||"An error occurred while duplicating the page"})}})},w=({page:t,onClose:u,closePanel:h=()=>{}})=>{const{t:s}=E.useTranslation(),{mutate:x,isPending:r}=T(),[o,i]=g.useState(null),[d,D]=g.useState(`${t.name} (Copy)`),b=p.useChangePage(),n=P.isEmpty(t.slug),[m,I]=g.useState(n?"":`${t.slug.split("/").pop()}-copy`),f=n?"":P.initial(t.slug.split("/")).join("/"),[y,j]=g.useState(!1),q=l=>{if(l.preventDefault(),!d.trim()){i(s("Name is required"));return}if(!n&&!m.trim()){i(s("Slug is required"));return}i(null),j(!0);const S={pageId:t.id,name:d};n||(S.slug=`${f}/${m}`),x(S,{onSuccess:c=>{j(!1),u(),b(c.id,h)},onError:c=>{j(!1),c.code==="SLUG_EXISTS"?i(s("A page with this slug already exists. Please choose a different slug.")):c.code==="INVALID_SLUG"?i(s("The slug format is invalid. Please use only lowercase letters, numbers, and hyphens.")):c.code==="PERMISSION_DENIED"?i(s("You don't have permission to duplicate this page.")):i(c.message||s("Failed to duplicate page. Please try again later."))}})};return e.jsx(a.Dialog,{open:!!t,onOpenChange:u,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:s("Duplicate Page")}),e.jsx(a.DialogDescription,{children:s("Create a copy of the page with a new name and slug")})]}),e.jsxs("div",{className:"mb-4 rounded-md bg-gray-50 p-3",children:[e.jsxs("h3",{className:"mb-1 text-sm font-medium",children:[s("Duplicating:"),":"]}),e.jsxs("div",{className:"flex flex-col gap-1 text-sm text-gray-700",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Name"),":"]})," ",t.name]}),!n&&e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Slug"),":"]})," ",t.slug]}),e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Type"),":"]})," ",t.pageType]})]})]}),e.jsxs("form",{onSubmit:q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:s("Name")}),e.jsx(a.Input,{id:"name",value:d,onChange:l=>D(l.target.value),required:!0})]}),!n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-sm",children:s("Slug")}),e.jsx(A.SlugInput,{value:m,onChange:l=>I(l),parentSlug:f,onValidationChange:l=>{i(l?null:s("Invalid slug"))}})]}),o&&e.jsxs(a.Alert,{variant:"destructive",className:"py-2",children:[e.jsx(C.AlertCircle,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:o})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(a.Button,{type:"button",variant:"outline",onClick:u,disabled:r,children:s("Cancel")}),e.jsx(a.Button,{type:"submit",disabled:!d.trim()||!n&&!m.trim()||r||y,children:s(r||y?"Duplicating...":"Duplicate")})]})]})]})})};exports.default=w;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-CZxeSGRk.cjs"),f=({isDefaultLang:r,searchQuery:l,setSearchQuery:c})=>e.jsx(a.Input,{type:"text",autoFocus:!0,value:r?l:"",onChange:t=>c(t.target.value),placeholder:r?"Search pages...":"To search select default language",disabled:!r,onKeyDown:t=>t.stopPropagation()}),m=({dynamicPage:r,setDynamicPage:l,searchQuery:c,setSearchQuery:t,dynamicPages:n})=>{const{selectedLang:o,fallbackLang:i}=x.useLanguages(),u=(o==null?void 0:o.length)===0;return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",className:"w-max focus:outline-none focus:ring-0 border-[0px] rounded-md py-1 text-sm h-max border border-gray-200 hover:bg-gray-100 pl-4",children:[r?h.get(r,"name"):"Select Page",e.jsx(p.ChevronDown,{className:"ml-2 h-4 w-4"})]})}),e.jsxs(a.DropdownMenuContent,{className:"w-96 divide-y shadow-xl p-0 max-h-[75vh]",children:[e.jsx("div",{className:"p-1.5 bg-gray-50/30",children:e.jsx(f,{isDefaultLang:u,searchQuery:c,setSearchQuery:t})}),(n==null?void 0:n.length)===0?e.jsx("div",{className:"h-24 text-xs flex items-center justify-center",children:"No pages found"}):n==null?void 0:n.map(s=>e.jsx(a.DropdownMenuItem,{onClick:()=>l(s),disabled:u?i!==s.lang:o!==s.lang,className:`flex flex-col justify-start cursor-pointer overflow-x-auto whitespace-nowrap no-scrollbar ${s.id===(r==null?void 0:r.id)?"bg-blue-50":"hover:bg-gray-50"}`,children:e.jsx("div",{className:"w-full text-xs whitespace-nowrap px-2 py-[2px]",children:e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:"font-mono font-medium text-gray-500 text-xs rounded-full px-2 py-[1px] border border-gray-300 truncate",children:s.slug})]})})},s.id))]})]})},j=()=>{const{dynamicPage:r,dynamicPages:l,allLangPages:c,selectedLang:t,searchQuery:n,updateDynamicPage:o,updateSearchQuery:i,onChangeLanguage:u}=g.useDynamicPageSelector(),s=d.useRef(void 0);return d.useEffect(()=>{s.current!==t&&r&&(u(),s.current=t)},[t,l]),e.jsx("div",{className:"relative",children:e.jsx(m,{dynamicPage:r,setDynamicPage:o,searchQuery:n,setSearchQuery:i,dynamicPages:c})})};exports.default=j;
|
|
@@ -4,7 +4,7 @@ import { DropdownMenu as h, DropdownMenuTrigger as p, Button as m, DropdownMenuC
|
|
|
4
4
|
import { get as v } from "lodash-es";
|
|
5
5
|
import { ChevronDown as w } from "lucide-react";
|
|
6
6
|
import { useRef as b, useEffect as N } from "react";
|
|
7
|
-
import { k as y } from "./index-
|
|
7
|
+
import { k as y } from "./index-D2g32O6h.js";
|
|
8
8
|
const D = ({
|
|
9
9
|
isDefaultLang: e,
|
|
10
10
|
searchQuery: l,
|