@chaibuilder/pages 0.4.6-beta.1 → 0.4.6-beta.3

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.
@@ -7390,7 +7390,7 @@ var Ed = (e, t = !1) => {
7390
7390
  const t = oa(() => {
7391
7391
  const n = this, [s] = R(this, yt), [a] = R(this, vt), [i] = R(this, Et), [l] = R(this, bt), [o] = R(this, gt);
7392
7392
  let c;
7393
- return R(this, wt) ? c = R(this, wt) : (c = ia(() => import("./HO4MOOFI-SiC6h0G4.js")), ee(this, wt, c)), Ca(R(this, Yt), R(this, pt)), ra(c, aa({
7393
+ return R(this, wt) ? c = R(this, wt) : (c = ia(() => import("./HO4MOOFI-oec0xpE4.js")), ee(this, wt, c)), Ca(R(this, Yt), R(this, pt)), ra(c, aa({
7394
7394
  get queryFlavor() {
7395
7395
  return R(n, zt);
7396
7396
  },
@@ -7484,7 +7484,7 @@ var Ed = (e, t = !1) => {
7484
7484
  const t = oa(() => {
7485
7485
  const n = this, [s] = R(this, At), [a] = R(this, xt), [i] = R(this, Tt), [l] = R(this, Ct), [o] = R(this, St), [c] = R(this, Pt);
7486
7486
  let h;
7487
- return R(this, _t) ? h = R(this, _t) : (h = ia(() => import("./HUY7CZI3-Ew2voVO9.js")), ee(this, _t, h)), Ca(R(this, en), R(this, Nt)), ra(h, aa({
7487
+ return R(this, _t) ? h = R(this, _t) : (h = ia(() => import("./HUY7CZI3-CPhM1Xo9.js")), ee(this, _t, h)), Ca(R(this, en), R(this, Nt)), ra(h, aa({
7488
7488
  get queryFlavor() {
7489
7489
  return R(n, Zt);
7490
7490
  },
@@ -7602,7 +7602,7 @@ var Iu = process.env.NODE_ENV !== "development" ? function() {
7602
7602
  } : Pu;
7603
7603
  process.env.NODE_ENV;
7604
7604
  const ku = Qa(
7605
- () => import("./digital-asset-manager-Dh6jIXs5.js")
7605
+ () => import("./digital-asset-manager-DPEusw_C.js")
7606
7606
  );
7607
7607
  ul();
7608
7608
  ec();
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-Ce2dcOYb.cjs"),t=require("@chaibuilder/sdk");exports.PermissionChecker=e.PermissionChecker;exports.default=e.ChaiBuilderPages;exports.registerChaiLoginComponent=e.registerLoginComponent;exports.useChaiUserInfo=e.useChaiUserInfo;exports.useCurrentPage=e.useCurrentPage;exports.useFetch=e.useFetch;exports.useFetchUpload=e.useFetchUpload;exports.useLanguagePages=e.useLanguagePages;exports.useUserPermissions=e.useUserRoleAndPermissions;exports.useWebsitePages=e.useWebsitePages;exports.useWebsiteSetting=e.useWebsiteSetting;Object.keys(t).forEach(s=>{s!=="default"&&!Object.prototype.hasOwnProperty.call(exports,s)&&Object.defineProperty(exports,s,{enumerable:!0,get:()=>t[s]})});
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-BosOek7g.cjs"),t=require("@chaibuilder/sdk");exports.PermissionChecker=e.PermissionChecker;exports.default=e.ChaiBuilderPages;exports.registerChaiLoginComponent=e.registerLoginComponent;exports.useChaiUserInfo=e.useChaiUserInfo;exports.useCurrentPage=e.useCurrentPage;exports.useFetch=e.useFetch;exports.useFetchUpload=e.useFetchUpload;exports.useLanguagePages=e.useLanguagePages;exports.useUserPermissions=e.useUserRoleAndPermissions;exports.useWebsitePages=e.useWebsitePages;exports.useWebsiteSetting=e.useWebsiteSetting;Object.keys(t).forEach(s=>{s!=="default"&&!Object.prototype.hasOwnProperty.call(exports,s)&&Object.defineProperty(exports,s,{enumerable:!0,get:()=>t[s]})});
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a0 as a, _ as r, a1 as t, a8 as i, a2 as o, X as u, a7 as n, a3 as g, a6 as h, a4 as m, a5 as C } from "./index-CG2G27hJ.js";
1
+ import { a0 as a, _ as r, a1 as t, a8 as i, a2 as o, X as u, a7 as n, a3 as g, a6 as h, a4 as m, a5 as C } from "./index-CHnFBKHF.js";
2
2
  export * from "@chaibuilder/sdk";
3
3
  export {
4
4
  a as PermissionChecker,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Suraj Air",
4
4
  "license": "Private",
5
5
  "homepage": "https://chaibuilder.com",
6
- "version": "0.4.6-beta.1",
6
+ "version": "0.4.6-beta.3",
7
7
  "type": "module",
8
8
  "files": [
9
9
  "dist"
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),O=require("@chaibuilder/sdk"),i=require("@chaibuilder/sdk/ui"),z=require("lodash-es"),g=require("lucide-react"),Z=require("react-dropzone"),v=require("@tanstack/react-query"),S=require("sonner"),n=require("./index-Ce2dcOYb.cjs"),$=()=>{const t=n.useAssetsApiUrl(),c=v.useQueryClient(),d=n.useFetch();return v.useMutation({mutationFn:async({file:o,folderId:u,name:l})=>d(t,{action:n.ACTIONS.UPLOAD_ASSET,data:{file:o,folderId:u,name:l}}),onSuccess:()=>{c.invalidateQueries({queryKey:[n.ACTIONS.GET_ASSETS]}),S.toast.success("Asset uploaded successfully")},onError:()=>{S.toast.error("Failed to upload asset")}})},ee=()=>{const t=n.useAssetsApiUrl(),c=v.useQueryClient(),d=n.useFetch();return v.useMutation({mutationFn:async o=>d(t,{action:n.ACTIONS.DELETE_ASSET,data:{id:o}}),onSuccess:()=>{c.invalidateQueries({queryKey:[n.ACTIONS.GET_ASSETS]}),S.toast.success("Asset deleted successfully")},onError:()=>{S.toast.error("Failed to delete asset")}})},se=()=>{const t=n.useAssetsApiUrl(),c=v.useQueryClient(),d=n.useFetch();return v.useMutation({mutationFn:async o=>d(t,{action:n.ACTIONS.UPDATE_ASSET,data:o}),onSuccess:()=>{c.invalidateQueries({queryKey:[n.ACTIONS.GET_ASSETS]}),S.toast.success("Asset updated successfully")},onError:()=>{S.toast.error("Failed to update asset")}})},te=(t={})=>{const c=n.useAssetsApiUrl(),d=n.useFetch(),{search:o,limit:u=10}=t;return v.useInfiniteQuery({queryKey:[n.QUERY_KEY_BASE,n.ACTIONS.GET_ASSETS,{search:o,limit:u}],queryFn:async({pageParam:l=1})=>(await d(c,{action:n.ACTIONS.GET_ASSETS,data:{search:o,page:l,limit:u}})).data,initialPageParam:1,getNextPageParam:l=>l.page*l.pageSize<l.total?l.page+1:void 0,getPreviousPageParam:l=>l.page>1?l.page-1:void 0,retry:1})};function ae(){const[c,d]=r.useState([]),[o,u]=r.useState({query:"",pageSize:10}),l=z.debounce(()=>o.query,300)(),{data:m,isLoading:A,fetchNextPage:b,hasNextPage:h,isFetchingNextPage:j}=te({search:(l==null?void 0:l.toLowerCase().trim())||"",limit:o.pageSize}),q=(m==null?void 0:m.pages.flatMap(f=>f.assets))||[],{mutate:y,isPaused:p}=se(),{mutate:w,isPending:N}=$(),{mutate:C,isPending:E}=ee(),F=r.useCallback(()=>{h&&!j&&b()},[b,h,j]),T=r.useCallback(f=>{u(x=>({...x,query:f}))},[]),U=r.useCallback(f=>{d(x=>z.find(x,{id:f.id})?[]:[f])},[!1]),I=r.useCallback(()=>{d([])},[]);return{query:(o==null?void 0:o.query)||"",selectedAssets:c,assets:q,hasNextPage:h,isFetchingNextPage:j,uploadAsset:w,updateAsset:y,deleteAsset:C,loadMoreAssets:F,updateSearchQuery:T,clearSelectedAssets:I,updateSelectedAssets:U,isLoadingAssets:A,isUploadingAsset:N,isUpdatingAsset:p,isDeletingAsset:E}}const le=r.lazy(()=>Promise.resolve().then(()=>require("./asset-metadata-editor-YXDey62L.cjs"))),re=r.lazy(()=>Promise.resolve().then(()=>require("./image-editor-BKUmqgv0.cjs")));function ne({close:t,onSelect:c,mode:d="image"}){const u=r.useMemo(()=>[d],[d]),[l,m]=r.useState("browse"),[A,b]=r.useState(null),[h,j]=r.useState({show:!1,file:"",name:""}),{query:q,assets:y,selectedAssets:p,hasNextPage:w,isFetchingNextPage:N,uploadAsset:C,updateAsset:E,deleteAsset:F,loadMoreAssets:T,updateSearchQuery:U,clearSelectedAssets:I,updateSelectedAssets:f,isLoadingAssets:x,isUploadingAsset:D,isUpdatingAsset:Q}=ae(),L=r.useRef(null);r.useEffect(()=>{const s=L.current;if(!s)return;const a=()=>{s.scrollHeight-s.scrollTop<=s.clientHeight*1.5&&!x&&w&&!N&&T()};return s.addEventListener("scroll",a),()=>s.removeEventListener("scroll",a)},[x,T,w,N]);const _=r.useCallback(async s=>new Promise((a,M)=>{const B=s[0],P=new FileReader;P.readAsDataURL(B),P.onload=async()=>{const k=await C({file:P.result,folderId:null,name:B.name});m("browse"),a(k)},P.onerror=k=>M(k)}),[C]),{getRootProps:R,getInputProps:G,isDragActive:K}=Z.useDropzone({onDrop:_,accept:{"image/*":u.includes("image")?[]:[],"video/*":u.includes("video")?[]:[]},maxSize:10*1024*1024}),Y=()=>{c([p[0].url]),t()},H=async s=>{await F(s.id)},V=s=>{b(s)},J=async(s,a)=>{await E(z.merge(s,a)),t()},W=s=>{U(s.target.value)},X=async(s,a)=>{try{a?await C({file:s,folderId:null,name:h.name}):await E({id:h.id,file:s}),j({show:!1,file:"",name:""}),m("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:l,onValueChange:s=>m(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:[p.length>0&&e.jsx(e.Fragment,{children:e.jsx(i.Button,{variant:"outline",size:"sm",onClick:()=>I(),title:"Clear selection",children:"Clear"})}),e.jsx(i.Button,{size:"sm",onClick:Y,disabled:p.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:q,onChange:W,className:"pl-8"})]})}),x&&y.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"})]}):y.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:()=>m("upload"),children:"Upload Assets"})})]}):e.jsxs("div",{ref:L,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:[y.map(s=>e.jsx(i.Card,{className:O.mergeClasses("cursor-pointer overflow-hidden transition-all",p.some(a=>a.id===s.id)?"ring-2 ring-primary":"hover:ring-2 hover:ring-primary/20"),onClick:()=>f(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(),V(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(),j({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(),H(s)},children:e.jsx(g.Trash2,{className:"h-4 w-4"})})]}),p.some(a=>a.id===s.id)&&e.jsx("div",{className:"absolute top-2 left-2",children:e.jsx("input",{type:"checkbox",checked:p.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:ie((s==null?void 0:s.size)||0)}),e.jsx("span",{children:oe(s.createdAt)})]})]})]})},s.id)),x&&y.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"})}),!x&&w&&e.jsx("div",{className:"col-span-full flex justify-center py-4",children:e.jsxs(i.Button,{variant:"outline",onClick:()=>T(),disabled:N,className:"flex items-center gap-2",children:[N?e.jsx(g.Loader2,{className:"h-4 w-4 animate-spin"}):null,"Load More"]})})]})]}),e.jsx(i.TabsContent,{value:"upload",className:"flex-1 ",children:e.jsxs("div",{...R(),className:O.mergeClasses("border-2 border-dashed rounded-lg h-[380px] flex flex-col items-center justify-center text-center cursor-pointer hover:bg-gray-50",K?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...G()}),Q||D?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"]})]})]})]})})]})]}),A&&e.jsx(r.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(le,{asset:A,onSave:s=>J(A,s),onCancel:()=>{b(null)}})}),h.show&&e.jsx(r.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(re,{imageUrl:h.file,onSave:X,onClose:()=>j({show:!1,file:"",name:""}),defaultSavedImageName:h.name,isEditing:!!h.id})})]})}function ie(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 oe(t){const c=new Date(t);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(c)}exports.default=ne;
@@ -1,471 +0,0 @@
1
- import { jsxs as s, Fragment as j, jsx as e } from "react/jsx-runtime";
2
- import W, { useState as T, useCallback as C, useMemo as ne, useRef as oe, useEffect as ce, Suspense as Y } from "react";
3
- import { mergeClasses as O } from "@chaibuilder/sdk";
4
- import { Tabs as de, TabsList as ue, TabsTrigger as H, Button as v, TabsContent as V, Input as me, Card as he, CardContent as pe } from "@chaibuilder/sdk/ui";
5
- import { debounce as ge, find as fe, merge as ve } from "lodash-es";
6
- import { Search as xe, Film as ye, ImageIcon as Ne, Edit as Se, Trash2 as we, Loader2 as _, Upload as Ae } from "lucide-react";
7
- import { useDropzone as be } from "react-dropzone";
8
- import { useQueryClient as B, useMutation as Q, useInfiniteQuery as Ee } from "@tanstack/react-query";
9
- import { toast as N } from "sonner";
10
- import { W as F, X as z, Y as g, Z as Ce } from "./index-CG2G27hJ.js";
11
- const Te = () => {
12
- const t = F(), n = B(), o = z();
13
- return Q({
14
- mutationFn: async ({
15
- file: r,
16
- folderId: c,
17
- name: i
18
- }) => o(t, {
19
- action: g.UPLOAD_ASSET,
20
- data: { file: r, folderId: c, name: i }
21
- }),
22
- onSuccess: () => {
23
- n.invalidateQueries({
24
- queryKey: [g.GET_ASSETS]
25
- }), N.success("Asset uploaded successfully");
26
- },
27
- onError: () => {
28
- N.error("Failed to upload asset");
29
- }
30
- });
31
- }, Pe = () => {
32
- const t = F(), n = B(), o = z();
33
- return Q({
34
- mutationFn: async (r) => o(t, {
35
- action: g.DELETE_ASSET,
36
- data: { id: r }
37
- }),
38
- onSuccess: () => {
39
- n.invalidateQueries({
40
- queryKey: [g.GET_ASSETS]
41
- }), N.success("Asset deleted successfully");
42
- },
43
- onError: () => {
44
- N.error("Failed to delete asset");
45
- }
46
- });
47
- }, Ue = () => {
48
- const t = F(), n = B(), o = z();
49
- return Q({
50
- mutationFn: async (r) => o(t, {
51
- action: g.UPDATE_ASSET,
52
- data: r
53
- }),
54
- onSuccess: () => {
55
- n.invalidateQueries({
56
- queryKey: [g.GET_ASSETS]
57
- }), N.success("Asset updated successfully");
58
- },
59
- onError: () => {
60
- N.error("Failed to update asset");
61
- }
62
- });
63
- }, Fe = (t = {}) => {
64
- const n = F(), o = z(), { search: r, limit: c = 10 } = t;
65
- return Ee({
66
- queryKey: [Ce, g.GET_ASSETS, { search: r, limit: c }],
67
- queryFn: async ({ pageParam: i = 1 }) => (await o(n, {
68
- action: g.GET_ASSETS,
69
- data: {
70
- search: r,
71
- page: i,
72
- limit: c
73
- }
74
- })).data,
75
- initialPageParam: 1,
76
- getNextPageParam: (i) => i.page * i.pageSize < i.total ? i.page + 1 : void 0,
77
- getPreviousPageParam: (i) => i.page > 1 ? i.page - 1 : void 0,
78
- retry: 1
79
- });
80
- };
81
- function ze() {
82
- const [n, o] = T([]), [r, c] = T({
83
- query: "",
84
- pageSize: 10
85
- }), i = ge(() => r.query, 300)(), {
86
- data: d,
87
- isLoading: S,
88
- fetchNextPage: w,
89
- hasNextPage: u,
90
- isFetchingNextPage: f
91
- } = Fe({
92
- search: (i == null ? void 0 : i.toLowerCase().trim()) || "",
93
- limit: r.pageSize
94
- }), M = (d == null ? void 0 : d.pages.flatMap((p) => p.assets)) || [], { mutate: x, isPaused: h } = Ue(), { mutate: A, isPending: y } = Te(), { mutate: b, isPending: P } = Pe(), D = C(() => {
95
- u && !f && w();
96
- }, [w, u, f]), E = C((p) => {
97
- c((m) => ({
98
- ...m,
99
- query: p
100
- }));
101
- }, []), I = C(
102
- (p) => {
103
- o((m) => fe(m, { id: p.id }) ? [] : [p]);
104
- },
105
- [!1]
106
- ), k = C(() => {
107
- o([]);
108
- }, []);
109
- return {
110
- // Data
111
- query: (r == null ? void 0 : r.query) || "",
112
- selectedAssets: n,
113
- assets: M,
114
- hasNextPage: u,
115
- isFetchingNextPage: f,
116
- // Mutations
117
- uploadAsset: A,
118
- updateAsset: x,
119
- deleteAsset: b,
120
- loadMoreAssets: D,
121
- updateSearchQuery: E,
122
- clearSelectedAssets: k,
123
- updateSelectedAssets: I,
124
- // Loading
125
- isLoadingAssets: S,
126
- isUploadingAsset: y,
127
- isUpdatingAsset: h,
128
- isDeletingAsset: P
129
- };
130
- }
131
- const Me = W.lazy(() => import("./asset-metadata-editor-CEFwXx62.js")), De = W.lazy(() => import("./image-editor-BQ6_F-iv.js"));
132
- function Oe({
133
- close: t,
134
- onSelect: n,
135
- mode: o = "image"
136
- }) {
137
- const c = ne(() => [o], [o]), [i, d] = T("browse"), [S, w] = T(null), [u, f] = T({ show: !1, file: "", name: "" }), {
138
- // Data
139
- query: M,
140
- assets: x,
141
- selectedAssets: h,
142
- hasNextPage: A,
143
- isFetchingNextPage: y,
144
- // Mutations
145
- uploadAsset: b,
146
- updateAsset: P,
147
- deleteAsset: D,
148
- loadMoreAssets: E,
149
- updateSearchQuery: I,
150
- clearSelectedAssets: k,
151
- updateSelectedAssets: p,
152
- // Loading
153
- isLoadingAssets: m,
154
- isUploadingAsset: R,
155
- isUpdatingAsset: X
156
- // isDeletingAsset,
157
- } = ze(), G = oe(null);
158
- ce(() => {
159
- const a = G.current;
160
- if (!a) return;
161
- const l = () => {
162
- a.scrollHeight - a.scrollTop <= a.clientHeight * 1.5 && !m && A && !y && E();
163
- };
164
- return a.addEventListener("scroll", l), () => a.removeEventListener("scroll", l);
165
- }, [m, E, A, y]);
166
- const Z = C(
167
- async (a) => new Promise((l, q) => {
168
- const K = a[0], U = new FileReader();
169
- U.readAsDataURL(K), U.onload = async () => {
170
- const L = await b({
171
- file: U.result,
172
- folderId: null,
173
- name: K.name
174
- });
175
- d("browse"), l(L);
176
- }, U.onerror = (L) => q(L);
177
- }),
178
- [b]
179
- ), { getRootProps: J, getInputProps: $, isDragActive: ee } = be({
180
- onDrop: Z,
181
- accept: {
182
- "image/*": c.includes("image") ? [] : [],
183
- "video/*": c.includes("video") ? [] : []
184
- },
185
- maxSize: 10 * 1024 * 1024
186
- }), ae = () => {
187
- n([h[0].url]), t();
188
- }, se = async (a) => {
189
- await D(a.id);
190
- }, te = (a) => {
191
- w(a);
192
- }, le = async (a, l) => {
193
- await P(ve(a, l)), t();
194
- }, ie = (a) => {
195
- I(a.target.value);
196
- }, re = async (a, l) => {
197
- try {
198
- l ? await b({
199
- file: a,
200
- folderId: null,
201
- name: u.name
202
- }) : await P({ id: u.id, file: a }), f({ show: !1, file: "", name: "" }), d("browse");
203
- } catch (q) {
204
- console.error("Error saving edited image:", q);
205
- }
206
- };
207
- return /* @__PURE__ */ s(j, { children: [
208
- /* @__PURE__ */ s("div", { className: "min-w-[700px] min-h-[600px] w-[900px] max-w-[900px]", children: [
209
- /* @__PURE__ */ e("h1", { className: "text-lg font-medium pb-4", children: "Digital Asset Manager" }),
210
- /* @__PURE__ */ s(
211
- de,
212
- {
213
- value: i,
214
- onValueChange: (a) => d(a),
215
- className: "flex-1 flex flex-col h-full",
216
- children: [
217
- /* @__PURE__ */ s("div", { className: "flex justify-between items-center mb-2", children: [
218
- /* @__PURE__ */ s(ue, { children: [
219
- /* @__PURE__ */ e(H, { value: "browse", children: "Browse Assets" }),
220
- /* @__PURE__ */ e(H, { value: "upload", children: "Upload" })
221
- ] }),
222
- /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
223
- h.length > 0 && /* @__PURE__ */ e(j, { children: /* @__PURE__ */ e(
224
- v,
225
- {
226
- variant: "outline",
227
- size: "sm",
228
- onClick: () => k(),
229
- title: "Clear selection",
230
- children: "Clear"
231
- }
232
- ) }),
233
- /* @__PURE__ */ e(
234
- v,
235
- {
236
- size: "sm",
237
- onClick: ae,
238
- disabled: h.length === 0,
239
- children: "Select Asset"
240
- }
241
- )
242
- ] })
243
- ] }),
244
- /* @__PURE__ */ s(V, { value: "browse", className: "flex-1 flex flex-col", children: [
245
- /* @__PURE__ */ e("div", { className: "flex items-center gap-2 mb-2", children: /* @__PURE__ */ s("div", { className: "relative w-full", children: [
246
- /* @__PURE__ */ e(xe, { className: "absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" }),
247
- /* @__PURE__ */ e(
248
- me,
249
- {
250
- placeholder: "Search assets...",
251
- value: M,
252
- onChange: ie,
253
- className: "pl-8"
254
- }
255
- )
256
- ] }) }),
257
- m && x.length === 0 ? /* @__PURE__ */ s("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: [
258
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
259
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
260
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
261
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
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
- ] }) : x.length === 0 ? /* @__PURE__ */ s("div", { className: "flex flex-col items-center justify-center h-full text-center p-12 h-[380px]", children: [
269
- /* @__PURE__ */ s("div", { className: "text-muted-foreground mb-2", children: [
270
- /* @__PURE__ */ e("h3", { className: "text-gray-800 font-medium", children: "No assets to display" }),
271
- /* @__PURE__ */ e("p", { className: "text-sm", children: "You haven't uploaded any assets yet. Start by uploading your first asset." })
272
- ] }),
273
- /* @__PURE__ */ e("div", { className: "flex gap-2 pt-4", children: /* @__PURE__ */ e(v, { size: "lg", onClick: () => d("upload"), children: "Upload Assets" }) })
274
- ] }) : /* @__PURE__ */ s(
275
- "div",
276
- {
277
- ref: G,
278
- 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",
279
- children: [
280
- x.map((a) => /* @__PURE__ */ e(
281
- he,
282
- {
283
- className: O(
284
- "cursor-pointer overflow-hidden transition-all",
285
- h.some((l) => l.id === a.id) ? "ring-2 ring-primary" : "hover:ring-2 hover:ring-primary/20"
286
- ),
287
- onClick: () => p(a),
288
- children: /* @__PURE__ */ s(pe, { className: "p-0 relative group", children: [
289
- /* @__PURE__ */ s("div", { className: "aspect-square relative overflow-hidden bg-muted", children: [
290
- a.type === "image" ? /* @__PURE__ */ e(
291
- "img",
292
- {
293
- src: a.url || "/placeholder.svg",
294
- alt: a.name,
295
- className: "object-cover w-full h-full"
296
- }
297
- ) : /* @__PURE__ */ s("div", { className: "flex items-center justify-center h-full", children: [
298
- /* @__PURE__ */ e(ye, { className: "h-12 w-12 text-muted-foreground" }),
299
- a.thumbnailUrl && /* @__PURE__ */ e(
300
- "img",
301
- {
302
- src: a.thumbnailUrl || "/placeholder.svg",
303
- alt: a.name,
304
- className: "absolute inset-0 object-cover w-full h-full"
305
- }
306
- )
307
- ] }),
308
- /* @__PURE__ */ s("div", { className: "absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2", children: [
309
- /* @__PURE__ */ e(
310
- v,
311
- {
312
- variant: "secondary",
313
- size: "icon",
314
- className: "h-8 w-8",
315
- onClick: (l) => {
316
- l.stopPropagation(), te(a);
317
- },
318
- children: /* @__PURE__ */ e(Ne, { className: "h-4 w-4" })
319
- }
320
- ),
321
- /* @__PURE__ */ e(
322
- v,
323
- {
324
- variant: "secondary",
325
- size: "icon",
326
- className: "h-8 w-8",
327
- onClick: (l) => {
328
- l.stopPropagation(), f({
329
- id: a.id,
330
- show: !0,
331
- file: a.url,
332
- name: a.name
333
- });
334
- },
335
- children: /* @__PURE__ */ e(Se, { className: "h-4 w-4" })
336
- }
337
- ),
338
- /* @__PURE__ */ e(
339
- v,
340
- {
341
- variant: "destructive",
342
- size: "icon",
343
- className: "h-8 w-8",
344
- onClick: (l) => {
345
- l.stopPropagation(), se(a);
346
- },
347
- children: /* @__PURE__ */ e(we, { className: "h-4 w-4" })
348
- }
349
- )
350
- ] }),
351
- h.some((l) => l.id === a.id) && /* @__PURE__ */ e("div", { className: "absolute top-2 left-2", children: /* @__PURE__ */ e(
352
- "input",
353
- {
354
- type: "checkbox",
355
- checked: h.some(
356
- (l) => l.id === a.id
357
- ),
358
- readOnly: !0,
359
- className: "rounded-full"
360
- }
361
- ) })
362
- ] }),
363
- /* @__PURE__ */ s("div", { className: "p-2", children: [
364
- /* @__PURE__ */ e(
365
- "div",
366
- {
367
- className: "text-sm font-medium truncate",
368
- title: a.name,
369
- children: a.name
370
- }
371
- ),
372
- /* @__PURE__ */ s("div", { className: "text-xs text-muted-foreground flex items-center justify-between", children: [
373
- /* @__PURE__ */ e("span", { children: Ie((a == null ? void 0 : a.size) || 0) }),
374
- /* @__PURE__ */ e("span", { children: ke(a.createdAt) })
375
- ] })
376
- ] })
377
- ] })
378
- },
379
- a.id
380
- )),
381
- m && x.length > 0 && /* @__PURE__ */ e("div", { className: "col-span-full flex justify-center py-4", children: /* @__PURE__ */ e(_, { className: "h-6 w-6 animate-spin text-muted-foreground" }) }),
382
- !m && A && /* @__PURE__ */ e("div", { className: "col-span-full flex justify-center py-4", children: /* @__PURE__ */ s(
383
- v,
384
- {
385
- variant: "outline",
386
- onClick: () => E(),
387
- disabled: y,
388
- className: "flex items-center gap-2",
389
- children: [
390
- y ? /* @__PURE__ */ e(_, { className: "h-4 w-4 animate-spin" }) : null,
391
- "Load More"
392
- ]
393
- }
394
- ) })
395
- ]
396
- }
397
- )
398
- ] }),
399
- /* @__PURE__ */ e(V, { value: "upload", className: "flex-1 ", children: /* @__PURE__ */ s(
400
- "div",
401
- {
402
- ...J(),
403
- className: O(
404
- "border-2 border-dashed rounded-lg h-[380px] flex flex-col items-center justify-center text-center cursor-pointer hover:bg-gray-50",
405
- ee ? "border-primary bg-primary/5" : "border-muted-foreground/20"
406
- ),
407
- children: [
408
- /* @__PURE__ */ e("input", { ...$() }),
409
- X || R ? /* @__PURE__ */ s("div", { className: "flex flex-col items-center", children: [
410
- /* @__PURE__ */ e(_, { className: "h-12 w-12 text-primary animate-spin mb-4" }),
411
- /* @__PURE__ */ e("h3", { className: "text-lg font-medium mb-1", children: "Uploading files..." }),
412
- /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "Please wait while your files are being processed." })
413
- ] }) : /* @__PURE__ */ s(j, { children: [
414
- /* @__PURE__ */ e(Ae, { className: "h-12 w-12 text-muted-foreground mb-4" }),
415
- /* @__PURE__ */ e("h3", { className: "text-lg font-medium mb-1", children: "Drag & drop files here" }),
416
- /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground mb-4", children: "or click to browse your files" }),
417
- /* @__PURE__ */ s("div", { className: "text-xs text-muted-foreground", children: [
418
- /* @__PURE__ */ s("p", { children: [
419
- "Accepted file types: ",
420
- c.join(", ")
421
- ] }),
422
- /* @__PURE__ */ s("p", { children: [
423
- "Maximum file size: ",
424
- 10,
425
- "MB"
426
- ] })
427
- ] })
428
- ] })
429
- ]
430
- }
431
- ) })
432
- ]
433
- }
434
- )
435
- ] }),
436
- S && /* @__PURE__ */ e(Y, { fallback: /* @__PURE__ */ e("div", { children: "Loading..." }), children: /* @__PURE__ */ e(
437
- Me,
438
- {
439
- asset: S,
440
- onSave: (a) => le(S, a),
441
- onCancel: () => {
442
- w(null);
443
- }
444
- }
445
- ) }),
446
- u.show && /* @__PURE__ */ e(Y, { fallback: /* @__PURE__ */ e("div", { children: "Loading..." }), children: /* @__PURE__ */ e(
447
- De,
448
- {
449
- imageUrl: u.file,
450
- onSave: re,
451
- onClose: () => f({ show: !1, file: "", name: "" }),
452
- defaultSavedImageName: u.name,
453
- isEditing: !!u.id
454
- }
455
- ) })
456
- ] });
457
- }
458
- function Ie(t) {
459
- 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";
460
- }
461
- function ke(t) {
462
- const n = new Date(t);
463
- return new Intl.DateTimeFormat("en-US", {
464
- month: "short",
465
- day: "numeric",
466
- year: "numeric"
467
- }).format(n);
468
- }
469
- export {
470
- Oe as default
471
- };