@chaibuilder/pages 0.4.2 → 0.4.5

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.
@@ -1,5 +1,5 @@
1
- import { c, T as l, P as m, a as u, D as v, Q as i } from "./B4MFY5CR-BXvzaHSP.js";
2
- import { g as d, c as f, a as e } from "./index-CCJ78lC0.js";
1
+ import { c, T as l, P as m, a as u, D as v, Q as i } from "./B4MFY5CR-BpF1oV0W.js";
2
+ import { g as d, c as f, a as e } from "./index-xGrIPO1U.js";
3
3
  var p = (a) => {
4
4
  const [r, t] = c({
5
5
  prefix: "TanstackQueryDevtools"
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR-QXzLG027.cjs"),t=require("./index-DeyUfJ0E.cjs");var s=c=>{const[r,o]=e.createLocalStorage({prefix:"TanstackQueryDevtools"}),l=t.getPreferredColorScheme(),a=t.createMemo(()=>{const n=r.theme_preference||e.THEME_PREFERENCE;return n!=="system"?n:l()});return t.createComponent(e.QueryDevtoolsContext.Provider,{value:c,get children(){return t.createComponent(e.PiPProvider,{localStore:r,setLocalStore:o,get children(){return t.createComponent(e.ThemeContext.Provider,{value:a,get children(){return t.createComponent(e.Devtools,{localStore:r,setLocalStore:o})}})}})}})},u=s;exports.default=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR-Eeaqj2pE.cjs"),t=require("./index-BH25LDvP.cjs");var s=c=>{const[r,o]=e.createLocalStorage({prefix:"TanstackQueryDevtools"}),l=t.getPreferredColorScheme(),a=t.createMemo(()=>{const n=r.theme_preference||e.THEME_PREFERENCE;return n!=="system"?n:l()});return t.createComponent(e.QueryDevtoolsContext.Provider,{value:c,get children(){return t.createComponent(e.PiPProvider,{localStore:r,setLocalStore:o,get children(){return t.createComponent(e.ThemeContext.Provider,{value:a,get children(){return t.createComponent(e.Devtools,{localStore:r,setLocalStore:o})}})}})}})},u=s;exports.default=u;
@@ -1,5 +1,5 @@
1
- import { c as s, T as c, P as u, a as i, b as m, C as P, Q as d } from "./B4MFY5CR-BXvzaHSP.js";
2
- import { g as v, c as C, a as e } from "./index-CCJ78lC0.js";
1
+ import { c as s, T as c, P as u, a as i, b as m, C as P, Q as d } from "./B4MFY5CR-BpF1oV0W.js";
2
+ import { g as v, c as C, a as e } from "./index-xGrIPO1U.js";
3
3
  var h = (t) => {
4
4
  const [r, o] = s({
5
5
  prefix: "TanstackQueryDevtools"
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR-QXzLG027.cjs"),t=require("./index-DeyUfJ0E.cjs");var u=o=>{const[r,n]=e.createLocalStorage({prefix:"TanstackQueryDevtools"}),c=t.getPreferredColorScheme(),a=t.createMemo(()=>{const l=r.theme_preference||e.THEME_PREFERENCE;return l!=="system"?l:c()});return t.createComponent(e.QueryDevtoolsContext.Provider,{value:o,get children(){return t.createComponent(e.PiPProvider,{disabled:!0,localStore:r,setLocalStore:n,get children(){return t.createComponent(e.ThemeContext.Provider,{value:a,get children(){return t.createComponent(e.ParentPanel,{get children(){return t.createComponent(e.ContentView,{localStore:r,setLocalStore:n,get onClose(){return o.onClose},showPanelViewOnly:!0})}})}})}})}})},i=u;exports.default=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR-Eeaqj2pE.cjs"),t=require("./index-BH25LDvP.cjs");var u=o=>{const[r,n]=e.createLocalStorage({prefix:"TanstackQueryDevtools"}),c=t.getPreferredColorScheme(),a=t.createMemo(()=>{const l=r.theme_preference||e.THEME_PREFERENCE;return l!=="system"?l:c()});return t.createComponent(e.QueryDevtoolsContext.Provider,{value:o,get children(){return t.createComponent(e.PiPProvider,{disabled:!0,localStore:r,setLocalStore:n,get children(){return t.createComponent(e.ThemeContext.Provider,{value:a,get children(){return t.createComponent(e.ParentPanel,{get children(){return t.createComponent(e.ContentView,{localStore:r,setLocalStore:n,get onClose(){return o.onClose},showPanelViewOnly:!0})}})}})}})}})},i=u;exports.default=i;
@@ -0,0 +1,91 @@
1
+ import { jsx as a, jsxs as t } from "react/jsx-runtime";
2
+ import { useState as l } from "react";
3
+ import { Dialog as b, DialogContent as w, DialogHeader as F, DialogTitle as C, Label as d, Input as S, Textarea as y, DialogFooter as A, Button as g } from "@chaibuilder/sdk/ui";
4
+ function E({
5
+ asset: e,
6
+ onSave: r,
7
+ onCancel: o
8
+ }) {
9
+ const i = e.name.lastIndexOf("."), f = i > 0 ? e.name.substring(0, i) : e.name, c = i > 0 ? e.name.substring(i) : "", [m, x] = l(f), [s, v] = l(e.description || ""), [u, h] = l(!1), N = async () => {
10
+ h(!0);
11
+ try {
12
+ const D = {
13
+ name: m + c,
14
+ description: s || void 0
15
+ };
16
+ await r(D);
17
+ } finally {
18
+ h(!1);
19
+ }
20
+ };
21
+ return /* @__PURE__ */ a(b, { open: !0, onOpenChange: () => o(), children: /* @__PURE__ */ t(w, { className: "sm:max-w-[500px]", children: [
22
+ /* @__PURE__ */ a(F, { children: /* @__PURE__ */ a(C, { children: "Edit Asset Details" }) }),
23
+ /* @__PURE__ */ t("div", { className: "grid gap-3 py-2", children: [
24
+ /* @__PURE__ */ t("div", { className: "grid gap-2", children: [
25
+ /* @__PURE__ */ a(d, { htmlFor: "name", children: "Name" }),
26
+ /* @__PURE__ */ t("div", { className: "flex", children: [
27
+ /* @__PURE__ */ a(
28
+ S,
29
+ {
30
+ id: "name",
31
+ value: m,
32
+ onChange: (n) => x(n.target.value),
33
+ className: "rounded-r-none"
34
+ }
35
+ ),
36
+ /* @__PURE__ */ a("div", { className: "px-3 py-1 text-sm font-medium bg-muted text-muted-foreground rounded-r-md border border-l-0 flex items-center", children: c || "" })
37
+ ] }),
38
+ /* @__PURE__ */ a("p", { className: "text-xs text-muted-foreground", children: "Only the file name can be changed, not the extension." })
39
+ ] }),
40
+ /* @__PURE__ */ t("div", { className: "grid gap-2", children: [
41
+ /* @__PURE__ */ a(d, { htmlFor: "description", children: "Description" }),
42
+ /* @__PURE__ */ a(
43
+ y,
44
+ {
45
+ id: "description",
46
+ value: s,
47
+ placeholder: "Enter a description for the asset",
48
+ onChange: (n) => v(n.target.value),
49
+ rows: 3
50
+ }
51
+ )
52
+ ] }),
53
+ /* @__PURE__ */ a("div", { className: "grid grid-cols-1 gap-2 text-sm border rounded-md p-2", children: [
54
+ { label: "Type", value: e.type },
55
+ { label: "Format", value: e.format },
56
+ { label: "Size", value: B(e.size) },
57
+ {
58
+ label: "Dimensions",
59
+ value: `${e.width} × ${e.height}`
60
+ },
61
+ { label: "Created", value: p(e.createdAt) },
62
+ { label: "Updated", value: p((e == null ? void 0 : e.updatedAt) || "") }
63
+ ].map((n) => /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
64
+ /* @__PURE__ */ a(d, { className: "w-max text-left px-2 w-1/4 font-normal text-gray-700", children: n.label }),
65
+ ":",
66
+ /* @__PURE__ */ a("div", { className: "w-max text-left font-medium text-gray-900 capitalize", children: n.value })
67
+ ] })) })
68
+ ] }),
69
+ /* @__PURE__ */ t(A, { children: [
70
+ /* @__PURE__ */ a(g, { variant: "outline", onClick: o, children: "Cancel" }),
71
+ /* @__PURE__ */ a(g, { onClick: N, disabled: u, children: u ? "Saving..." : "Save Changes" })
72
+ ] })
73
+ ] }) });
74
+ }
75
+ function B(e) {
76
+ return e < 1024 ? e + " B" : e < 1024 * 1024 ? (e / 1024).toFixed(1) + " KB" : e < 1024 * 1024 * 1024 ? (e / (1024 * 1024)).toFixed(1) + " MB" : (e / (1024 * 1024 * 1024)).toFixed(1) + " GB";
77
+ }
78
+ function p(e) {
79
+ if (!e) return "N/A";
80
+ const r = new Date(e);
81
+ return new Intl.DateTimeFormat("en-US", {
82
+ month: "short",
83
+ day: "numeric",
84
+ year: "numeric",
85
+ hour: "2-digit",
86
+ minute: "2-digit"
87
+ }).format(r);
88
+ }
89
+ export {
90
+ E as default
91
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),l=require("react"),a=require("@chaibuilder/sdk/ui");function j({asset:e,onSave:r,onCancel:d}){const i=e.name.lastIndexOf("."),h=i>0?e.name.substring(0,i):e.name,o=i>0?e.name.substring(i):"",[s,g]=l.useState(h),[c,f]=l.useState(e.description||""),[m,u]=l.useState(!1),p=async()=>{u(!0);try{const v={name:s+o,description:c||void 0};await r(v)}finally{u(!1)}};return t.jsx(a.Dialog,{open:!0,onOpenChange:()=>d(),children:t.jsxs(a.DialogContent,{className:"sm:max-w-[500px]",children:[t.jsx(a.DialogHeader,{children:t.jsx(a.DialogTitle,{children:"Edit Asset Details"})}),t.jsxs("div",{className:"grid gap-3 py-2",children:[t.jsxs("div",{className:"grid gap-2",children:[t.jsx(a.Label,{htmlFor:"name",children:"Name"}),t.jsxs("div",{className:"flex",children:[t.jsx(a.Input,{id:"name",value:s,onChange:n=>g(n.target.value),className:"rounded-r-none"}),t.jsx("div",{className:"px-3 py-1 text-sm font-medium bg-muted text-muted-foreground rounded-r-md border border-l-0 flex items-center",children:o||""})]}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Only the file name can be changed, not the extension."})]}),t.jsxs("div",{className:"grid gap-2",children:[t.jsx(a.Label,{htmlFor:"description",children:"Description"}),t.jsx(a.Textarea,{id:"description",value:c,placeholder:"Enter a description for the asset",onChange:n=>f(n.target.value),rows:3})]}),t.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:[{label:"Type",value:e.type},{label:"Format",value:e.format},{label:"Size",value:N(e.size)},{label:"Dimensions",value:`${e.width} × ${e.height}`},{label:"Created",value:x(e.createdAt)},{label:"Updated",value:x((e==null?void 0:e.updatedAt)||"")}].map(n=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:n.label}),":",t.jsx("div",{className:"w-max text-left font-medium text-gray-900 capitalize",children:n.value})]}))})]}),t.jsxs(a.DialogFooter,{children:[t.jsx(a.Button,{variant:"outline",onClick:d,children:"Cancel"}),t.jsx(a.Button,{onClick:p,disabled:m,children:m?"Saving...":"Save Changes"})]})]})})}function N(e){return e<1024?e+" B":e<1024*1024?(e/1024).toFixed(1)+" KB":e<1024*1024*1024?(e/(1024*1024)).toFixed(1)+" MB":(e/(1024*1024*1024)).toFixed(1)+" GB"}function x(e){if(!e)return"N/A";const r=new Date(e);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}exports.default=j;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),W=require("react-dropzone"),g=require("lucide-react"),i=require("@chaibuilder/sdk/ui"),z=require("lodash-es"),D=require("@chaibuilder/sdk"),x=require("@tanstack/react-query"),c=require("./index-BH25LDvP.cjs"),j=require("sonner"),X=(t={})=>{c.useApiUrl(),c.useFetch();const{search:n,page:o=1,limit:l=10}=t;return x.useQuery({queryKey:[c.ACTIONS.GET_ASSETS,{search:n,page:o,limit:l}],queryFn:async()=>{const u=localStorage.getItem("assets")||"[]";return JSON.parse(u)},retry:1})},Z=()=>{c.useApiUrl();const t=x.useQueryClient();return c.useFetch(),x.useMutation({mutationFn:async n=>{const o=localStorage.getItem("assets")||"[]";return localStorage.setItem("assets",JSON.stringify([...JSON.parse(o)||[],{id:Math.random().toString(36).substring(2,15),name:"123",url:n,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),type:"image",size:Math.random()*1e3}])),!0},onSuccess:()=>{t.invalidateQueries({queryKey:[c.ACTIONS.GET_ASSETS]}),j.toast.success("Asset uploaded successfully")},onError:()=>{j.toast.error("Failed to upload asset")}})},$=()=>{c.useApiUrl();const t=x.useQueryClient();return c.useFetch(),x.useMutation({mutationFn:async n=>{const o=localStorage.getItem("assets")||"[]";return localStorage.setItem("assets",JSON.stringify((JSON.parse(o)||[]).filter(l=>l.id!==n))),!0},onSuccess:()=>{t.invalidateQueries({queryKey:[c.ACTIONS.GET_ASSETS]}),j.toast.success("Asset deleted successfully")},onError:()=>{j.toast.error("Failed to delete asset")}})},ee=()=>{c.useApiUrl();const t=x.useQueryClient();return c.useFetch(),x.useMutation({mutationFn:async n=>{const o=localStorage.getItem("assets")||"[]";return localStorage.setItem("assets",JSON.stringify((JSON.parse(o)||[]).map(l=>l.id===n.id?{...l,url:n.file}:l))),!0},onSuccess:()=>{t.invalidateQueries({queryKey:[c.ACTIONS.GET_ASSETS]}),j.toast.success("Asset updated successfully")},onError:()=>{j.toast.error("Failed to update asset")}})};function se(){const[n,o]=r.useState([]),[l,u]=r.useState({query:"",page:1,pageSize:10}),y=z.debounce(()=>l.query,300)(),{data:p,isLoading:v}=X({search:(y==null?void 0:y.toLowerCase().trim())||"",page:l.page,limit:l.pageSize}),{mutate:w,isPaused:h}=ee(),{mutate:S,isPending:E}=Z(),{mutate:f,isPending:m}=$(),N=r.useCallback(()=>{u(d=>({...d,page:d.page+1}))},[]),A=r.useCallback(d=>{u(b=>({...b,query:d}))},[]),F=r.useCallback(d=>{o(b=>z.find(b,{id:d.id})?[]:[d])},[!1]),C=r.useCallback(()=>{o([])},[]);return{query:(l==null?void 0:l.query)||"",selectedAssets:n,assets:p||[],uploadAsset:S,updateAsset:w,deleteAsset:f,loadMoreAssets:N,updateSearchQuery:A,clearSelectedAssets:C,updateSelectedAssets:F,isLoadingAssets:v,isUploadingAsset:E,isUpdatingAsset:h,isDeletingAsset:m}}const te=r.lazy(()=>Promise.resolve().then(()=>require("./asset-metadata-editor-YXDey62L.cjs"))),ae=r.lazy(()=>Promise.resolve().then(()=>require("./image-editor-D8wu5UNM.cjs")));function re({close:t,onSelect:n,mode:o="image"}){const u=r.useMemo(()=>[o],[o]),[y,p]=r.useState("browse"),[v,w]=r.useState(null),[h,S]=r.useState({show:!1,file:""}),{query:E,assets:f,selectedAssets:m,uploadAsset:N,updateAsset:A,deleteAsset:F,loadMoreAssets:C,updateSearchQuery:d,clearSelectedAssets:b,updateSelectedAssets:k,isLoadingAssets:T,isUploadingAsset:O,isUpdatingAsset:B}=se(),U=r.useRef(null);r.useEffect(()=>{const s=U.current;if(!s)return;const a=()=>{s.scrollHeight-s.scrollTop<=s.clientHeight*1.5&&!T&&C()};return s.addEventListener("scroll",a),()=>s.removeEventListener("scroll",a)},[T,C]);const P=r.useCallback(async s=>new Promise((a,M)=>{const Y=s[0],q=new FileReader;q.readAsDataURL(Y),q.onload=async()=>{const I=await N(q.result);p("browse"),a(I)},q.onerror=I=>M(I)}),[N]),{getRootProps:L,getInputProps:Q,isDragActive:R}=W.useDropzone({onDrop:P,accept:{"image/*":u.includes("image")?[]:[],"video/*":u.includes("video")?[]:[]},maxSize:10*1024*1024}),J=()=>{n([m[0].url]),t()},G=async s=>{await F(s.id)},K=s=>{w(s)},_=async(s,a)=>{await A(z.merge(s,a)),t()},H=s=>{d(s.target.value)},V=async(s,a)=>{try{a?await N(s):await A({id:h.id,file:s}),S({show:!1,file:""}),p("browse")}catch(M){console.error("Error saving edited image:",M)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"min-w-[700px] min-h-[600px] w-[900px] max-w-[900px]",children:[e.jsx("h1",{className:"text-lg font-medium pb-4",children:"Digital Asset Manager"}),e.jsxs(i.Tabs,{value:y,onValueChange:s=>p(s),className:"flex-1 flex flex-col h-full",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs(i.TabsList,{children:[e.jsx(i.TabsTrigger,{value:"browse",children:"Browse Assets"}),e.jsx(i.TabsTrigger,{value:"upload",children:"Upload"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[m.length>0&&e.jsx(e.Fragment,{children:e.jsx(i.Button,{variant:"outline",size:"sm",onClick:()=>b(),title:"Clear selection",children:"Clear"})}),e.jsx(i.Button,{size:"sm",onClick:J,disabled:m.length===0,children:"Select Asset"})]})]}),e.jsxs(i.TabsContent,{value:"browse",className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsxs("div",{className:"relative w-full",children:[e.jsx(g.Search,{className:"absolute left-2 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(i.Input,{placeholder:"Search assets...",value:E,onChange:H,className:"pl-8"})]})}),T&&f.length===0?e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[550px] p-1",children:[e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"})]}):f.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center p-12 h-[380px]",children:[e.jsxs("div",{className:"text-muted-foreground mb-2",children:[e.jsx("h3",{className:"text-gray-800 font-medium",children:"No assets to display"}),e.jsx("p",{className:"text-sm",children:"You haven't uploaded any assets yet. Start by uploading your first asset."})]}),e.jsx("div",{className:"flex gap-2 pt-4",children:e.jsx(i.Button,{size:"lg",onClick:()=>p("upload"),children:"Upload Assets"})})]}):e.jsxs("div",{ref:U,className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[550px] p-1",children:[f.map(s=>e.jsx(i.Card,{className:D.mergeClasses("cursor-pointer overflow-hidden transition-all",m.some(a=>a.id===s.id)?"ring-2 ring-primary":"hover:ring-2 hover:ring-primary/20"),onClick:()=>k(s),children:e.jsxs(i.CardContent,{className:"p-0 relative group",children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden bg-muted",children:[s.type==="image"?e.jsx("img",{src:s.url||"/placeholder.svg",alt:s.name,className:"object-cover w-full h-full"}):e.jsxs("div",{className:"flex items-center justify-center h-full",children:[e.jsx(g.Film,{className:"h-12 w-12 text-muted-foreground"}),s.thumbnailUrl&&e.jsx("img",{src:s.thumbnailUrl||"/placeholder.svg",alt:s.name,className:"absolute inset-0 object-cover w-full h-full"})]}),e.jsxs("div",{className:"absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2",children:[e.jsx(i.Button,{variant:"secondary",size:"icon",className:"h-8 w-8",onClick:a=>{a.stopPropagation(),K(s)},children:e.jsx(g.ImageIcon,{className:"h-4 w-4"})}),e.jsx(i.Button,{variant:"secondary",size:"icon",className:"h-8 w-8",onClick:a=>{a.stopPropagation(),S({id:s.id,show:!0,file:s.url,name:s.name})},children:e.jsx(g.Edit,{className:"h-4 w-4"})}),e.jsx(i.Button,{variant:"destructive",size:"icon",className:"h-8 w-8",onClick:a=>{a.stopPropagation(),G(s)},children:e.jsx(g.Trash2,{className:"h-4 w-4"})})]}),m.some(a=>a.id===s.id)&&e.jsx("div",{className:"absolute top-2 left-2",children:e.jsx("input",{type:"checkbox",checked:m.some(a=>a.id===s.id),readOnly:!0,className:"rounded-full"})})]}),e.jsxs("div",{className:"p-2",children:[e.jsx("div",{className:"text-sm font-medium truncate",title:s.name,children:s.name}),e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center justify-between",children:[e.jsx("span",{children:le((s==null?void 0:s.size)||0)}),e.jsx("span",{children:ie(s.createdAt)})]})]})]})},s.id)),T&&f.length>0&&e.jsx("div",{className:"col-span-full flex justify-center py-4",children:e.jsx(g.Loader2,{className:"h-6 w-6 animate-spin text-muted-foreground"})})]})]}),e.jsx(i.TabsContent,{value:"upload",className:"flex-1 ",children:e.jsxs("div",{...L(),className:D.mergeClasses("border-2 border-dashed rounded-lg h-[380px] flex flex-col items-center justify-center text-center cursor-pointer hover:bg-gray-50",R?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...Q()}),B||O?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(g.Loader2,{className:"h-12 w-12 text-primary animate-spin mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-1",children:"Uploading files..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait while your files are being processed."})]}):e.jsxs(e.Fragment,{children:[e.jsx(g.Upload,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-1",children:"Drag & drop files here"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"or click to browse your files"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("p",{children:["Accepted file types: ",u.join(", ")]}),e.jsxs("p",{children:["Maximum file size: ",10,"MB"]})]})]})]})})]})]}),v&&e.jsx(r.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(te,{asset:v,onSave:s=>_(v,s),onCancel:()=>{w(null)}})}),h.show&&e.jsx(r.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(ae,{imageUrl:h.file,onSave:V,onClose:()=>S({show:!1,file:""}),defaultSavedImageName:h.name,isEditing:!!h.id})})]})}function le(t){return t<1024?t+" B":t<1024*1024?(t/1024).toFixed(1)+" KB":t<1024*1024*1024?(t/(1024*1024)).toFixed(1)+" MB":(t/(1024*1024*1024)).toFixed(1)+" GB"}function ie(t){const n=new Date(t);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(n)}exports.default=re;
@@ -0,0 +1,462 @@
1
+ import { jsxs as t, Fragment as q, jsx as e } from "react/jsx-runtime";
2
+ import G, { useState as w, useCallback as N, useMemo as le, useRef as ie, useEffect as ne, Suspense as B } from "react";
3
+ import { useDropzone as oe } from "react-dropzone";
4
+ import { Search as ce, Film as de, ImageIcon as ue, Edit as me, Trash2 as ge, Loader2 as J, Upload as he } from "lucide-react";
5
+ import { Tabs as pe, TabsList as fe, TabsTrigger as _, Button as h, TabsContent as Q, Input as ye, Card as ve, CardContent as Se } from "@chaibuilder/sdk/ui";
6
+ import { debounce as xe, find as Ne, merge as we } from "lodash-es";
7
+ import { mergeClasses as R } from "@chaibuilder/sdk";
8
+ import { useQuery as be, useQueryClient as j, useMutation as L } from "@tanstack/react-query";
9
+ import { W as z, X as F, Y as M } from "./index-xGrIPO1U.js";
10
+ import { toast as p } from "sonner";
11
+ const Ae = (a = {}) => {
12
+ z(), F();
13
+ const { search: i, page: n = 1, limit: l = 10 } = a;
14
+ return be({
15
+ queryKey: [M.GET_ASSETS, { search: i, page: n, limit: l }],
16
+ queryFn: async () => {
17
+ const c = localStorage.getItem("assets") || "[]";
18
+ return JSON.parse(c);
19
+ },
20
+ retry: 1
21
+ });
22
+ }, Ce = () => {
23
+ z();
24
+ const a = j();
25
+ return F(), L({
26
+ mutationFn: async (i) => {
27
+ const n = localStorage.getItem("assets") || "[]";
28
+ return localStorage.setItem(
29
+ "assets",
30
+ JSON.stringify([
31
+ ...JSON.parse(n) || [],
32
+ {
33
+ id: Math.random().toString(36).substring(2, 15),
34
+ name: "123",
35
+ url: i,
36
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
37
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
38
+ type: "image",
39
+ size: Math.random() * 1e3
40
+ }
41
+ ])
42
+ ), !0;
43
+ },
44
+ onSuccess: () => {
45
+ a.invalidateQueries({
46
+ queryKey: [M.GET_ASSETS]
47
+ }), p.success("Asset uploaded successfully");
48
+ },
49
+ onError: () => {
50
+ p.error("Failed to upload asset");
51
+ }
52
+ });
53
+ }, Ee = () => {
54
+ z();
55
+ const a = j();
56
+ return F(), L({
57
+ mutationFn: async (i) => {
58
+ const n = localStorage.getItem("assets") || "[]";
59
+ return localStorage.setItem(
60
+ "assets",
61
+ JSON.stringify(
62
+ (JSON.parse(n) || []).filter((l) => l.id !== i)
63
+ )
64
+ ), !0;
65
+ },
66
+ onSuccess: () => {
67
+ a.invalidateQueries({
68
+ queryKey: [M.GET_ASSETS]
69
+ }), p.success("Asset deleted successfully");
70
+ },
71
+ onError: () => {
72
+ p.error("Failed to delete asset");
73
+ }
74
+ });
75
+ }, Te = () => {
76
+ z();
77
+ const a = j();
78
+ return F(), L({
79
+ mutationFn: async (i) => {
80
+ const n = localStorage.getItem("assets") || "[]";
81
+ return localStorage.setItem(
82
+ "assets",
83
+ JSON.stringify(
84
+ (JSON.parse(n) || []).map((l) => l.id === i.id ? { ...l, url: i.file } : l)
85
+ )
86
+ ), !0;
87
+ },
88
+ onSuccess: () => {
89
+ a.invalidateQueries({
90
+ queryKey: [M.GET_ASSETS]
91
+ }), p.success("Asset updated successfully");
92
+ },
93
+ onError: () => {
94
+ p.error("Failed to update asset");
95
+ }
96
+ });
97
+ };
98
+ function ze() {
99
+ const [i, n] = w([]), [l, c] = w({
100
+ query: "",
101
+ page: 1,
102
+ pageSize: 10
103
+ }), f = xe(() => l.query, 300)(), { data: m, isLoading: y } = Ae({
104
+ search: (f == null ? void 0 : f.toLowerCase().trim()) || "",
105
+ page: l.page,
106
+ limit: l.pageSize
107
+ }), { mutate: b, isPaused: u } = Te(), { mutate: v, isPending: I } = Ce(), { mutate: g, isPending: d } = Ee(), S = N(() => {
108
+ c((o) => ({
109
+ ...o,
110
+ page: o.page + 1
111
+ }));
112
+ }, []), A = N((o) => {
113
+ c((x) => ({
114
+ ...x,
115
+ query: o
116
+ }));
117
+ }, []), D = N(
118
+ (o) => {
119
+ n((x) => Ne(x, { id: o.id }) ? [] : [o]);
120
+ },
121
+ [!1]
122
+ ), C = N(() => {
123
+ n([]);
124
+ }, []);
125
+ return {
126
+ // Data
127
+ query: (l == null ? void 0 : l.query) || "",
128
+ selectedAssets: i,
129
+ assets: m || [],
130
+ // Mutations
131
+ uploadAsset: v,
132
+ updateAsset: b,
133
+ deleteAsset: g,
134
+ loadMoreAssets: S,
135
+ updateSearchQuery: A,
136
+ clearSelectedAssets: C,
137
+ updateSelectedAssets: D,
138
+ // Loading
139
+ isLoadingAssets: y,
140
+ isUploadingAsset: I,
141
+ isUpdatingAsset: u,
142
+ isDeletingAsset: d
143
+ };
144
+ }
145
+ const Fe = G.lazy(() => import("./asset-metadata-editor-CEFwXx62.js")), Me = G.lazy(() => import("./image-editor-CwVua57o.js"));
146
+ function Qe({
147
+ close: a,
148
+ onSelect: i,
149
+ mode: n = "image"
150
+ }) {
151
+ const c = le(() => [n], [n]), [f, m] = w("browse"), [y, b] = w(null), [u, v] = w({ show: !1, file: "" }), {
152
+ // Data
153
+ query: I,
154
+ assets: g,
155
+ selectedAssets: d,
156
+ // Mutations
157
+ uploadAsset: S,
158
+ updateAsset: A,
159
+ deleteAsset: D,
160
+ loadMoreAssets: C,
161
+ updateSearchQuery: o,
162
+ clearSelectedAssets: x,
163
+ updateSelectedAssets: O,
164
+ // Loading
165
+ isLoadingAssets: E,
166
+ isUploadingAsset: K,
167
+ isUpdatingAsset: H
168
+ // isDeletingAsset,
169
+ } = ze(), P = ie(null);
170
+ ne(() => {
171
+ const s = P.current;
172
+ if (!s) return;
173
+ const r = () => {
174
+ s.scrollHeight - s.scrollTop <= s.clientHeight * 1.5 && !E && C();
175
+ };
176
+ return s.addEventListener("scroll", r), () => s.removeEventListener("scroll", r);
177
+ }, [E, C]);
178
+ const Y = N(
179
+ async (s) => new Promise((r, U) => {
180
+ const re = s[0], T = new FileReader();
181
+ T.readAsDataURL(re), T.onload = async () => {
182
+ const k = await S(T.result);
183
+ m("browse"), r(k);
184
+ }, T.onerror = (k) => U(k);
185
+ }),
186
+ [S]
187
+ ), { getRootProps: V, getInputProps: W, isDragActive: X } = oe({
188
+ onDrop: Y,
189
+ accept: {
190
+ "image/*": c.includes("image") ? [] : [],
191
+ "video/*": c.includes("video") ? [] : []
192
+ },
193
+ maxSize: 10 * 1024 * 1024
194
+ }), Z = () => {
195
+ i([d[0].url]), a();
196
+ }, $ = async (s) => {
197
+ await D(s.id);
198
+ }, ee = (s) => {
199
+ b(s);
200
+ }, se = async (s, r) => {
201
+ await A(we(s, r)), a();
202
+ }, te = (s) => {
203
+ o(s.target.value);
204
+ }, ae = async (s, r) => {
205
+ try {
206
+ r ? await S(s) : await A({ id: u.id, file: s }), v({ show: !1, file: "" }), m("browse");
207
+ } catch (U) {
208
+ console.error("Error saving edited image:", U);
209
+ }
210
+ };
211
+ return /* @__PURE__ */ t(q, { children: [
212
+ /* @__PURE__ */ t("div", { className: "min-w-[700px] min-h-[600px] w-[900px] max-w-[900px]", children: [
213
+ /* @__PURE__ */ e("h1", { className: "text-lg font-medium pb-4", children: "Digital Asset Manager" }),
214
+ /* @__PURE__ */ t(
215
+ pe,
216
+ {
217
+ value: f,
218
+ onValueChange: (s) => m(s),
219
+ className: "flex-1 flex flex-col h-full",
220
+ children: [
221
+ /* @__PURE__ */ t("div", { className: "flex justify-between items-center mb-2", children: [
222
+ /* @__PURE__ */ t(fe, { children: [
223
+ /* @__PURE__ */ e(_, { value: "browse", children: "Browse Assets" }),
224
+ /* @__PURE__ */ e(_, { value: "upload", children: "Upload" })
225
+ ] }),
226
+ /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
227
+ d.length > 0 && /* @__PURE__ */ e(q, { children: /* @__PURE__ */ e(
228
+ h,
229
+ {
230
+ variant: "outline",
231
+ size: "sm",
232
+ onClick: () => x(),
233
+ title: "Clear selection",
234
+ children: "Clear"
235
+ }
236
+ ) }),
237
+ /* @__PURE__ */ e(
238
+ h,
239
+ {
240
+ size: "sm",
241
+ onClick: Z,
242
+ disabled: d.length === 0,
243
+ children: "Select Asset"
244
+ }
245
+ )
246
+ ] })
247
+ ] }),
248
+ /* @__PURE__ */ t(Q, { value: "browse", className: "flex-1 flex flex-col", children: [
249
+ /* @__PURE__ */ e("div", { className: "flex items-center gap-2 mb-2", children: /* @__PURE__ */ t("div", { className: "relative w-full", children: [
250
+ /* @__PURE__ */ e(ce, { className: "absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" }),
251
+ /* @__PURE__ */ e(
252
+ ye,
253
+ {
254
+ placeholder: "Search assets...",
255
+ value: I,
256
+ onChange: te,
257
+ className: "pl-8"
258
+ }
259
+ )
260
+ ] }) }),
261
+ E && g.length === 0 ? /* @__PURE__ */ t("div", { className: "grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[550px] p-1", children: [
262
+ /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
263
+ /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
264
+ /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
265
+ /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
266
+ /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
267
+ /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
268
+ /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
269
+ /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
270
+ /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
271
+ /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" })
272
+ ] }) : g.length === 0 ? /* @__PURE__ */ t("div", { className: "flex flex-col items-center justify-center h-full text-center p-12 h-[380px]", children: [
273
+ /* @__PURE__ */ t("div", { className: "text-muted-foreground mb-2", children: [
274
+ /* @__PURE__ */ e("h3", { className: "text-gray-800 font-medium", children: "No assets to display" }),
275
+ /* @__PURE__ */ e("p", { className: "text-sm", children: "You haven't uploaded any assets yet. Start by uploading your first asset." })
276
+ ] }),
277
+ /* @__PURE__ */ e("div", { className: "flex gap-2 pt-4", children: /* @__PURE__ */ e(h, { size: "lg", onClick: () => m("upload"), children: "Upload Assets" }) })
278
+ ] }) : /* @__PURE__ */ t(
279
+ "div",
280
+ {
281
+ ref: P,
282
+ className: "grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[550px] p-1",
283
+ children: [
284
+ g.map((s) => /* @__PURE__ */ e(
285
+ ve,
286
+ {
287
+ className: R(
288
+ "cursor-pointer overflow-hidden transition-all",
289
+ d.some((r) => r.id === s.id) ? "ring-2 ring-primary" : "hover:ring-2 hover:ring-primary/20"
290
+ ),
291
+ onClick: () => O(s),
292
+ children: /* @__PURE__ */ t(Se, { className: "p-0 relative group", children: [
293
+ /* @__PURE__ */ t("div", { className: "aspect-square relative overflow-hidden bg-muted", children: [
294
+ s.type === "image" ? /* @__PURE__ */ e(
295
+ "img",
296
+ {
297
+ src: s.url || "/placeholder.svg",
298
+ alt: s.name,
299
+ className: "object-cover w-full h-full"
300
+ }
301
+ ) : /* @__PURE__ */ t("div", { className: "flex items-center justify-center h-full", children: [
302
+ /* @__PURE__ */ e(de, { className: "h-12 w-12 text-muted-foreground" }),
303
+ s.thumbnailUrl && /* @__PURE__ */ e(
304
+ "img",
305
+ {
306
+ src: s.thumbnailUrl || "/placeholder.svg",
307
+ alt: s.name,
308
+ className: "absolute inset-0 object-cover w-full h-full"
309
+ }
310
+ )
311
+ ] }),
312
+ /* @__PURE__ */ t("div", { className: "absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2", children: [
313
+ /* @__PURE__ */ e(
314
+ h,
315
+ {
316
+ variant: "secondary",
317
+ size: "icon",
318
+ className: "h-8 w-8",
319
+ onClick: (r) => {
320
+ r.stopPropagation(), ee(s);
321
+ },
322
+ children: /* @__PURE__ */ e(ue, { className: "h-4 w-4" })
323
+ }
324
+ ),
325
+ /* @__PURE__ */ e(
326
+ h,
327
+ {
328
+ variant: "secondary",
329
+ size: "icon",
330
+ className: "h-8 w-8",
331
+ onClick: (r) => {
332
+ r.stopPropagation(), v({
333
+ id: s.id,
334
+ show: !0,
335
+ file: s.url,
336
+ name: s.name
337
+ });
338
+ },
339
+ children: /* @__PURE__ */ e(me, { className: "h-4 w-4" })
340
+ }
341
+ ),
342
+ /* @__PURE__ */ e(
343
+ h,
344
+ {
345
+ variant: "destructive",
346
+ size: "icon",
347
+ className: "h-8 w-8",
348
+ onClick: (r) => {
349
+ r.stopPropagation(), $(s);
350
+ },
351
+ children: /* @__PURE__ */ e(ge, { className: "h-4 w-4" })
352
+ }
353
+ )
354
+ ] }),
355
+ d.some((r) => r.id === s.id) && /* @__PURE__ */ e("div", { className: "absolute top-2 left-2", children: /* @__PURE__ */ e(
356
+ "input",
357
+ {
358
+ type: "checkbox",
359
+ checked: d.some(
360
+ (r) => r.id === s.id
361
+ ),
362
+ readOnly: !0,
363
+ className: "rounded-full"
364
+ }
365
+ ) })
366
+ ] }),
367
+ /* @__PURE__ */ t("div", { className: "p-2", children: [
368
+ /* @__PURE__ */ e(
369
+ "div",
370
+ {
371
+ className: "text-sm font-medium truncate",
372
+ title: s.name,
373
+ children: s.name
374
+ }
375
+ ),
376
+ /* @__PURE__ */ t("div", { className: "text-xs text-muted-foreground flex items-center justify-between", children: [
377
+ /* @__PURE__ */ e("span", { children: Ie((s == null ? void 0 : s.size) || 0) }),
378
+ /* @__PURE__ */ e("span", { children: De(s.createdAt) })
379
+ ] })
380
+ ] })
381
+ ] })
382
+ },
383
+ s.id
384
+ )),
385
+ E && g.length > 0 && /* @__PURE__ */ e("div", { className: "col-span-full flex justify-center py-4", children: /* @__PURE__ */ e(J, { className: "h-6 w-6 animate-spin text-muted-foreground" }) })
386
+ ]
387
+ }
388
+ )
389
+ ] }),
390
+ /* @__PURE__ */ e(Q, { value: "upload", className: "flex-1 ", children: /* @__PURE__ */ t(
391
+ "div",
392
+ {
393
+ ...V(),
394
+ className: R(
395
+ "border-2 border-dashed rounded-lg h-[380px] flex flex-col items-center justify-center text-center cursor-pointer hover:bg-gray-50",
396
+ X ? "border-primary bg-primary/5" : "border-muted-foreground/20"
397
+ ),
398
+ children: [
399
+ /* @__PURE__ */ e("input", { ...W() }),
400
+ H || K ? /* @__PURE__ */ t("div", { className: "flex flex-col items-center", children: [
401
+ /* @__PURE__ */ e(J, { className: "h-12 w-12 text-primary animate-spin mb-4" }),
402
+ /* @__PURE__ */ e("h3", { className: "text-lg font-medium mb-1", children: "Uploading files..." }),
403
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "Please wait while your files are being processed." })
404
+ ] }) : /* @__PURE__ */ t(q, { children: [
405
+ /* @__PURE__ */ e(he, { className: "h-12 w-12 text-muted-foreground mb-4" }),
406
+ /* @__PURE__ */ e("h3", { className: "text-lg font-medium mb-1", children: "Drag & drop files here" }),
407
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground mb-4", children: "or click to browse your files" }),
408
+ /* @__PURE__ */ t("div", { className: "text-xs text-muted-foreground", children: [
409
+ /* @__PURE__ */ t("p", { children: [
410
+ "Accepted file types: ",
411
+ c.join(", ")
412
+ ] }),
413
+ /* @__PURE__ */ t("p", { children: [
414
+ "Maximum file size: ",
415
+ 10,
416
+ "MB"
417
+ ] })
418
+ ] })
419
+ ] })
420
+ ]
421
+ }
422
+ ) })
423
+ ]
424
+ }
425
+ )
426
+ ] }),
427
+ y && /* @__PURE__ */ e(B, { fallback: /* @__PURE__ */ e("div", { children: "Loading..." }), children: /* @__PURE__ */ e(
428
+ Fe,
429
+ {
430
+ asset: y,
431
+ onSave: (s) => se(y, s),
432
+ onCancel: () => {
433
+ b(null);
434
+ }
435
+ }
436
+ ) }),
437
+ u.show && /* @__PURE__ */ e(B, { fallback: /* @__PURE__ */ e("div", { children: "Loading..." }), children: /* @__PURE__ */ e(
438
+ Me,
439
+ {
440
+ imageUrl: u.file,
441
+ onSave: ae,
442
+ onClose: () => v({ show: !1, file: "" }),
443
+ defaultSavedImageName: u.name,
444
+ isEditing: !!u.id
445
+ }
446
+ ) })
447
+ ] });
448
+ }
449
+ function Ie(a) {
450
+ return a < 1024 ? a + " B" : a < 1024 * 1024 ? (a / 1024).toFixed(1) + " KB" : a < 1024 * 1024 * 1024 ? (a / (1024 * 1024)).toFixed(1) + " MB" : (a / (1024 * 1024 * 1024)).toFixed(1) + " GB";
451
+ }
452
+ function De(a) {
453
+ const i = new Date(a);
454
+ return new Intl.DateTimeFormat("en-US", {
455
+ month: "short",
456
+ day: "numeric",
457
+ year: "numeric"
458
+ }).format(i);
459
+ }
460
+ export {
461
+ Qe as default
462
+ };