@openway/ui 1.0.2 → 1.0.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.
- package/LICENSE +21 -21
- package/dist/chunk-XM7AABEU.js +3 -0
- package/dist/chunk-XM7AABEU.js.map +1 -0
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +158 -74
- package/dist/index.d.ts +158 -74
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/query.cjs +1 -1
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +13 -5
- package/dist/query.d.ts +13 -5
- package/dist/query.js +1 -1
- package/dist/query.js.map +1 -1
- package/dist/styles.css +424 -0
- package/dist/{useInfiniteScroll-D9AW6cQV.d.cts → useInfiniteScroll-C5t7bvLu.d.cts} +40 -10
- package/dist/{useInfiniteScroll-D9AW6cQV.d.ts → useInfiniteScroll-C5t7bvLu.d.ts} +40 -10
- package/docs/AGENTS.md +0 -2
- package/docs/README.md +0 -1
- package/docs/components/carousel.md +5 -5
- package/docs/components/input.md +0 -6
- package/docs/components/select.md +2 -2
- package/docs/components/slider.md +2 -2
- package/docs/components/table.md +114 -1
- package/docs/hooks/useInfiniteScroll.md +1 -1
- package/docs/hooks/useMutationApp.md +242 -242
- package/docs/hooks/useTableQuery.md +5 -0
- package/package.json +3 -2
- package/dist/chunk-X4LIYOS5.js +0 -3
- package/dist/chunk-X4LIYOS5.js.map +0 -1
package/dist/query.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var ue=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var Le=Object.prototype.hasOwnProperty;var je=(e,t)=>{for(var n in t)ue(e,n,{get:t[n],enumerable:!0})},Ge=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ue(t))!Le.call(e,i)&&i!==n&&ue(e,i,{get:()=>t[i],enumerable:!(r=ze(t,i))||r.enumerable});return e};var qe=e=>Ge(ue({},"__esModule",{value:!0}),e);var Ye={};je(Ye,{extractErrorMessage:()=>we,useMutationApp:()=>Qe,useSelectInfiniteQuery:()=>ke,useTableQuery:()=>Pe});module.exports=qe(Ye);var w=require("react"),oe=require("@tanstack/react-query");var ce=10;function Be(e){if(!e)return[];if(Array.isArray(e))return e;if(typeof e=="object"){let t=e;if(Array.isArray(t.data))return t.data;if(Array.isArray(t.items))return t.items;if(Array.isArray(t.rows))return t.rows;if(Array.isArray(t.results))return t.results}return[]}function _e(e){if(!e)return 0;if(Array.isArray(e))return e.length;if(typeof e=="object"){let t=e,n=t.total??t.rowCount??t.totalCount??t.count;if(typeof n=="number")return n;if(typeof n=="string"){let r=Number(n);if(!isNaN(r))return r}}return 0}function de(e,t){return typeof e=="function"?e(t):e}function Pe(e){let{queryKey:t,queryFn:n,selectData:r=Be,selectRowCount:i=_e,initialPagination:a,initialSorting:o,initialColumnFilters:l,initialGlobalFilter:y,autoResetPageIndex:c=!0,queryOptions:m}=e,[d,x]=(0,w.useState)({pageIndex:a?.pageIndex??0,pageSize:a?.pageSize??ce}),[R,A]=(0,w.useState)(o??[]),[f,p]=(0,w.useState)(l??[]),[v,k]=(0,w.useState)(y??""),P=(0,w.useMemo)(()=>{let T={page:d.pageIndex+1,pageSize:d.pageSize},g=R[0];if(g&&(T.sortBy=g.id,T.sortOrder=g.desc?"desc":"asc"),f.length>0){let ne={};f.forEach(Re=>{ne[Re.id]=Re.value}),T.filters=ne}return T},[d.pageIndex,d.pageSize,R,f]),U=(0,w.useMemo)(()=>[...t,P],[t,P]),D=(0,oe.useQuery)({queryKey:U,queryFn:T=>n(P,T),placeholderData:oe.keepPreviousData,...m}),O=(0,w.useMemo)(()=>D.data?r(D.data):[],[D.data,r]),s=(0,w.useMemo)(()=>D.data?i(D.data):0,[D.data,i]),b=(0,w.useCallback)(T=>{x(g=>de(T,g))},[]),h=(0,w.useCallback)(T=>{A(g=>de(T,g)),c&&x(g=>g.pageIndex===0?g:{...g,pageIndex:0})},[c]),I=(0,w.useCallback)(T=>{p(g=>de(T,g)),c&&x(g=>g.pageIndex===0?g:{...g,pageIndex:0})},[c]),S=(0,w.useCallback)(T=>{k(T),c&&x(g=>g.pageIndex===0?g:{...g,pageIndex:0})},[c]),E=(0,w.useCallback)(()=>{x({pageIndex:a?.pageIndex??0,pageSize:a?.pageSize??ce}),A(o??[]),p(l??[]),k(y??"")},[a,o,l,y]),L=(0,w.useCallback)(T=>{x(g=>({...g,pageIndex:Math.max(0,T-1)}))},[]),C=(0,w.useCallback)(T=>{x({pageIndex:0,pageSize:T})},[]),F=(0,w.useCallback)(T=>{S(T)},[S]),{isLoading:V,isRefetching:M,refetch:u}=D,N=(0,w.useCallback)(()=>{u()},[u]);return{tableProps:(0,w.useMemo)(()=>({data:O,rowCount:s,isLoading:V,isRefresh:M&&!V,onRefresh:N,manualPagination:!0,manualSorting:!0,manualFiltering:!0,pagination:d,onPaginationChange:b,sorting:R,onSortingChange:h,columnFilters:f,onColumnFiltersChange:I,globalFilter:v,onGlobalFilterChange:S}),[O,s,V,M,N,d,b,R,h,f,I,v,S]),query:D,queryParams:P,resetAll:E,setPage:L,setPageSize:C,setGlobalFilter:F,setSorting:A,setColumnFilters:p}}var Q=require("react"),Ae=require("@tanstack/react-query");var j=require("react");function Se({onLoadMore:e,hasMore:t=!0,isLoading:n=!1,disabled:r=!1,rootMargin:i="100px",threshold:a=0,root:o=null}){let[l,y]=(0,j.useState)(!1),[c,m]=(0,j.useState)(null),d=(0,j.useRef)(!1),x=t&&!n&&!r,R=(0,j.useCallback)(()=>{if(!(!x||d.current)){d.current=!0;try{let f=e();f&&typeof f.then=="function"?f.finally(()=>{d.current=!1}):d.current=!1}catch{d.current=!1}}},[x,e]),A=(0,j.useCallback)(f=>{m(f)},[]);return(0,j.useEffect)(()=>{if(!c||r||!t||typeof window>"u"||!("IntersectionObserver"in window))return;let f=o&&typeof o=="object"&&"current"in o?o.current:o,p=new IntersectionObserver(v=>{let[k]=v;if(!k)return;let P=k.isIntersecting;y(P),P&&R()},{root:f,rootMargin:i,threshold:a});return p.observe(c),()=>{p.disconnect(),y(!1)}},[c,o,i,a,r,t,R]),(0,j.useEffect)(()=>{x&&l&&R()},[x,l,R]),{sentinelRef:A,isIntersecting:l}}var ve={pulse:"animate-pulse",wave:"skeleton-wave",none:""},Ce={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",xl:"rounded-xl",full:"rounded-full"};var Ie=require("@tanstack/match-sorter-utils");function G(e,t,n){return e!=null&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:t[n]}var H=e=>e;var ae=require("react/jsx-runtime");function pe({ref:e,variant:t="pulse",shape:n="rectangle",radius:r="md",width:i,height:a="1rem",lines:o=1,gap:l="0.5rem",className:y="",style:c,...m}){let d=G(t,ve,"pulse"),x=n==="circle"?"rounded-full":G(r,Ce,"md"),R={width:H(i),height:H(a),...c},A=["bg-neutral-200",d,x].filter(Boolean).join(" ");return o>1?(0,ae.jsx)("div",{ref:e,role:"status","aria-label":"Loading...",className:["flex flex-col",y].filter(Boolean).join(" "),style:{gap:H(l),...c},...m,children:Array.from({length:o}).map((f,p)=>{let v=p===o-1;return(0,ae.jsx)("div",{className:A,style:{width:v?"60%":H(i)??"100%",height:H(a)}},p)})}):(0,ae.jsx)("div",{ref:e,role:"status","aria-label":"Loading...",className:[A,y].filter(Boolean).join(" "),style:R,...m})}var ee=require("react/jsx-runtime");function fe(e){if(!e)return[];if(Array.isArray(e))return e;if(typeof e!="object")return[];let t=e;return Array.isArray(t.data)?t.data:Array.isArray(t.items)?t.items:Array.isArray(t.options)?t.options:Array.isArray(t.results)?t.results:Array.isArray(t.rows)?t.rows:[]}var Ke={};function ke({queryKey:e,queryFn:t,initialPageParam:n=1,getNextPageParam:r,getPreviousPageParam:i,selectOptions:a,mapOption:o,debounceMs:l=300,initialSearch:y="",initialFilters:c=Ke,initialOptions:m,skeletonLines:d=2,skeletonHeight:x="1.75rem",renderLoadingMore:R,endMessage:A,scrollOptions:f,queryOptions:p}){let[v,k]=(0,Q.useState)(y),[P,U]=(0,Q.useState)(c),D=(0,Q.useMemo)(()=>[...e,{search:v,filters:P}],[e,v,P]),O=(0,Q.useCallback)((C,F,V,M)=>{if(r)return r(C,F,V,M);if(!C||typeof C!="object")return;let u=C;if(typeof u.nextPage=="number"||typeof u.nextPage=="string")return u.nextPage;if(typeof u.next_page=="number"||typeof u.next_page=="string")return u.next_page;if(typeof u.nextCursor=="string"||typeof u.nextCursor=="number")return u.nextCursor;if(typeof u.next_cursor=="string"||typeof u.next_cursor=="number")return u.next_cursor;if(!(u.hasMore===!1||u.has_more===!1||u.hasNextPage===!1)&&typeof V=="number"){if(fe(C).length===0)return;let X=typeof u.total=="number"?u.total:typeof u.totalCount=="number"?u.totalCount:typeof u.count=="number"?u.count:void 0;return X!==void 0&&F.reduce((g,ne)=>g+fe(ne).length,0)>=X?void 0:V+1}},[r]),s=(0,Ae.useInfiniteQuery)({queryKey:D,queryFn:C=>t({pageParam:C.pageParam,search:v,filters:P},C),initialPageParam:n,getNextPageParam:O,getPreviousPageParam:i,...p}),b=(0,Q.useMemo)(()=>{let C=s.data?.pages??[],F=[],V=new Set;if(m&&m.length>0)for(let M of m)V.has(M.value)||(V.add(M.value),F.push(M));for(let M of C){let u=[];if(a)u=a(M);else{let N=fe(M);o?u=N.map((X,T)=>o(X,T)):u=N}for(let N of u)N&&N.value!==void 0&&!V.has(N.value)&&(V.add(N.value),F.push(N))}return F},[s.data?.pages,a,o,m]),{sentinelRef:h}=Se({onLoadMore:()=>{s.hasNextPage&&!s.isFetchingNextPage&&s.fetchNextPage()},hasMore:!!s.hasNextPage,isLoading:s.isFetchingNextPage||s.isLoading,disabled:s.isError,rootMargin:f?.rootMargin??"80px",threshold:f?.threshold??0,root:f?.root}),I=(0,Q.useCallback)((C,F)=>{k(C),U(F)},[]),S=(0,Q.useCallback)(()=>{k(y),U(c)},[y,c]),E=(0,Q.useMemo)(()=>b.length===0?null:s.isFetchingNextPage?(0,ee.jsx)("div",{ref:h,className:"p-1 space-y-1 w-full",children:R?R():(0,ee.jsx)(pe,{lines:d,height:x,gap:"0.25rem",radius:"sm",className:"p-0.5"})}):s.hasNextPage?(0,ee.jsx)("div",{ref:h,className:"h-1 w-full","aria-hidden":"true"}):A?(0,ee.jsx)("div",{className:"py-2 px-1 text-center text-xs text-neutral-400 dark:text-neutral-500",children:A}):null,[b.length,s.isFetchingNextPage,s.hasNextPage,h,R,d,x,A]);return{selectProps:(0,Q.useMemo)(()=>({options:b,isLoading:s.isLoading,searchMode:"server",debounceMs:l,onSearch:I,listFooter:E}),[b,s.isLoading,l,I,E]),query:s,options:b,search:v,setSearch:k,filters:P,setFilters:U,sentinelRef:h,reset:S}}var Me=require("react"),le=require("@tanstack/react-query");var $e=require("sonner");var He=require("react/jsx-runtime");var Ve=require("react"),$=require("sonner");var W=require("react/jsx-runtime");function Z({width:e=20,height:t=20,className:n="",...r}){return(0,W.jsxs)("svg",{width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:n,...r,children:[(0,W.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,W.jsx)("path",{d:"M12 16v-4"}),(0,W.jsx)("path",{d:"M12 8h.01"})]})}var te=require("react/jsx-runtime");function ge({width:e=20,height:t=20,className:n="",...r}){return(0,te.jsxs)("svg",{width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:n,...r,children:[(0,te.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,te.jsx)("path",{d:"m9 12 2 2 4-4"})]})}var Y=require("react/jsx-runtime");function me({width:e=20,height:t=20,className:n="",...r}){return(0,Y.jsxs)("svg",{width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:n,...r,children:[(0,Y.jsx)("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),(0,Y.jsx)("path",{d:"M12 9v4"}),(0,Y.jsx)("path",{d:"M12 17h.01"})]})}var J=require("react/jsx-runtime");function ye({width:e=20,height:t=20,className:n="",...r}){return(0,J.jsxs)("svg",{width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:n,...r,children:[(0,J.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,J.jsx)("path",{d:"M12 8v4"}),(0,J.jsx)("path",{d:"M12 16h.01"})]})}var De={xs:{container:"p-2 gap-2 text-xs",title:"text-xs font-semibold leading-tight",description:"text-[11px] leading-tight",icon:"size-3.5 mt-0.5",closeButton:"size-4 p-0.5 -mr-0.5",closeIcon:"size-3",action:"gap-1.5 text-xs"},sm:{container:"p-2.5 gap-2.5 text-xs",title:"text-sm font-semibold leading-tight",description:"text-xs leading-normal",icon:"size-4 mt-0.5",closeButton:"size-5 p-0.5 -mr-0.5",closeIcon:"size-3.5",action:"gap-1.5 text-xs"},md:{container:"p-3.5 gap-3 text-sm",title:"text-sm font-semibold leading-tight",description:"text-sm leading-normal",icon:"size-5 mt-0.5",closeButton:"size-6 p-1 -mr-1",closeIcon:"size-4",action:"gap-2 text-sm"},lg:{container:"p-4 gap-3.5 text-base",title:"text-base font-semibold leading-snug",description:"text-sm leading-normal",icon:"size-6 mt-0.5",closeButton:"size-7 p-1.5 -mr-1.5",closeIcon:"size-4.5",action:"gap-2.5 text-sm"},xl:{container:"p-5 gap-4 text-lg",title:"text-lg font-semibold leading-snug",description:"text-base leading-normal",icon:"size-7 mt-0.5",closeButton:"size-8 p-1.5 -mr-1.5",closeIcon:"size-5",action:"gap-3 text-base"}},Oe={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",xl:"rounded-xl",full:"rounded-2xl"},Ne={soft:{primary:"bg-primary-50 text-primary-900 border-2 border-primary-200",secondary:"bg-secondary-50 text-secondary-900 border-2 border-secondary-200",neutral:"bg-neutral-100 text-neutral-900 border-2 border-neutral-200",error:"bg-error-50 text-error-900 border-2 border-error-200",success:"bg-success-50 text-success-900 border-2 border-success-200",warning:"bg-warning-50 text-warning-900 border-2 border-warning-200",info:"bg-info-50 text-info-900 border-2 border-info-200"},filled:{primary:"bg-primary-600 text-white border-2 border-primary-600",secondary:"bg-secondary-600 text-white border-2 border-secondary-600",neutral:"bg-neutral-700 text-white border-2 border-neutral-700",error:"bg-error-600 text-white border-2 border-error-600",success:"bg-success-600 text-white border-2 border-success-600",warning:"bg-warning-500 text-neutral-950 border-2 border-warning-500",info:"bg-info-600 text-white border-2 border-info-600"},outline:{primary:"bg-neutral-white text-primary-700 border-2 border-primary-400",secondary:"bg-neutral-white text-secondary-700 border-2 border-secondary-400",neutral:"bg-neutral-white text-neutral-700 border-2 border-neutral-300",error:"bg-neutral-white text-error-700 border-2 border-error-500",success:"bg-neutral-white text-success-700 border-2 border-success-400",warning:"bg-neutral-white text-warning-800 border-2 border-warning-400",info:"bg-neutral-white text-info-700 border-2 border-info-400"},"accent-left":{primary:"bg-primary-50/70 text-primary-900 border-2 border-primary-200 border-l-4 border-l-primary-500",secondary:"bg-secondary-50/70 text-secondary-900 border-2 border-secondary-200 border-l-4 border-l-secondary-500",neutral:"bg-neutral-50/70 text-neutral-900 border-2 border-neutral-200 border-l-4 border-l-neutral-500",error:"bg-error-50/70 text-error-900 border-2 border-error-200 border-l-4 border-l-error-500",success:"bg-success-50/70 text-success-900 border-2 border-success-200 border-l-4 border-l-success-500",warning:"bg-warning-50/70 text-warning-900 border-2 border-warning-200 border-l-4 border-l-warning-500",info:"bg-info-50/70 text-info-900 border-2 border-info-200 border-l-4 border-l-info-500"},ghost:{primary:"bg-transparent text-primary-800 border-2 border-transparent",secondary:"bg-transparent text-secondary-800 border-2 border-transparent",neutral:"bg-transparent text-neutral-800 border-2 border-transparent",error:"bg-transparent text-error-700 border-2 border-transparent",success:"bg-transparent text-success-700 border-2 border-transparent",warning:"bg-transparent text-warning-800 border-2 border-transparent",info:"bg-transparent text-info-800 border-2 border-transparent"}},Fe={soft:{primary:"text-primary-600",secondary:"text-secondary-600",neutral:"text-neutral-600",error:"text-error-600",success:"text-success-600",warning:"text-warning-600",info:"text-info-600"},filled:{primary:"text-white",secondary:"text-white",neutral:"text-white",error:"text-white",success:"text-white",warning:"text-neutral-950",info:"text-white"},outline:{primary:"text-primary-600",secondary:"text-secondary-600",neutral:"text-neutral-600",error:"text-error-600",success:"text-success-600",warning:"text-warning-600",info:"text-info-600"},"accent-left":{primary:"text-primary-600",secondary:"text-secondary-600",neutral:"text-neutral-600",error:"text-error-600",success:"text-success-600",warning:"text-warning-600",info:"text-info-600"},ghost:{primary:"text-primary-600",secondary:"text-secondary-600",neutral:"text-neutral-600",error:"text-error-600",success:"text-success-600",warning:"text-warning-600",info:"text-info-600"}},Ee={primary:Z,secondary:Z,neutral:Z,info:Z,success:ge,warning:me,error:ye};var be=require("react/jsx-runtime");function Te({width:e=14,height:t=14,className:n="",...r}){return(0,be.jsx)("svg",{width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:n,...r,children:(0,be.jsx)("path",{d:"M18 6 6 18M6 6l12 12"})})}var z=require("react/jsx-runtime");function se({size:e,variant:t,color:n,radius:r,title:i,description:a,icon:o=!0,action:l,closable:y=!0,onClose:c,closeAriaLabel:m="\u0110\xF3ng c\u1EA3nh b\xE1o",banner:d=!1,titleClassName:x="",descriptionClassName:R="",actionClassName:A="",iconClassName:f="",closeButtonClassName:p="",className:v="",children:k,role:P,ref:U,...D}){let O=G(e,De,"md"),s=d?"rounded-none border-x-0 w-full":G(r,Oe,"lg"),b=t==="other"?"":G(n,G(t,Ne,"soft"),"info"),h=t==="other"?"":G(n,G(t,Fe,"soft"),"info"),I=y||!!c,S=N=>{N.stopPropagation(),c?.()},L=P||(n==="error"||n==="warning"?"alert":"status"),C=n==="error"||n==="warning"?"assertive":"polite",F=a??k,V=!!F,M=()=>{if(o===!1)return null;if(o!==!0&&o!==void 0)return(0,z.jsx)("span",{className:`inline-flex items-center justify-center shrink-0 leading-none ${O.icon} ${f}`,"aria-hidden":"true",children:o});let N=G(n,Ee,"info");return(0,z.jsx)("span",{className:`inline-flex items-center justify-center shrink-0 leading-none ${O.icon} ${h} ${f}`,"aria-hidden":"true",children:(0,z.jsx)(N,{className:"size-full"})})},u=["relative flex w-full",O.container,s,b,v].filter(Boolean).join(" ");return(0,z.jsxs)("div",{ref:U,role:L,"aria-live":C,className:u,...D,children:[M(),(0,z.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col justify-center",children:[i&&(0,z.jsx)("div",{className:`${O.title} ${x}`,children:i}),V&&(0,z.jsx)("div",{className:`${O.description} ${i?"mt-0.5":""} ${R}`,children:F})]}),l&&(0,z.jsx)("div",{className:`inline-flex items-center shrink-0 ${O.action} ${A}`,children:l}),I&&(0,z.jsx)("button",{type:"button",onClick:S,"aria-label":m,className:`inline-flex items-center justify-center shrink-0 rounded-md transition-colors cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-current opacity-70 hover:opacity-100 ${t==="filled"?"hover:bg-white/20 active:bg-white/30":"hover:bg-black/5 active:bg-black/10"} ${O.closeButton} ${p}`,children:(0,z.jsx)(Te,{className:O.closeIcon})})]})}var re=require("react/jsx-runtime");function xe({width:e=16,height:t=16,className:n="",...r}){return(0,re.jsxs)("svg",{width:e,height:t,className:`animate-[spin_1s_steps(8)_infinite] ${n}`,viewBox:"0 0 25 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r,children:[(0,re.jsx)("path",{d:"M0 0h25v24H0z",fill:"none"}),(0,re.jsx)("path",{fill:"currentColor",d:"M4.818 6.664h-.001a1.847 1.847 0 1 1 1.306-.541a1.77 1.77 0 0 1-1.277.541h-.029zm-2.97 7.182h-.001a1.847 1.847 0 1 1 1.306-.541a1.77 1.77 0 0 1-1.278.541h-.031h.002zM12 3.692a1.847 1.847 0 1 1 1.306-.541a1.77 1.77 0 0 1-1.277.541zM4.818 21.029h-.001a1.847 1.847 0 1 1 1.306-.541a1.77 1.77 0 0 1-1.276.541h-.031zM19.182 7.125a2.308 2.308 0 1 1 0-4.615a2.308 2.308 0 0 1 0 4.615M12 24a1.847 1.847 0 1 1 1.306-.541a1.77 1.77 0 0 1-1.277.541zm10.154-9.231h-.048c-.75 0-1.428-.309-1.913-.807l-.001-.001c-.499-.503-.808-1.196-.808-1.961s.308-1.458.808-1.962a2.66 2.66 0 0 1 1.914-.808h.05h-.003h.048c.75 0 1.427.309 1.913.807l.001.001c.499.503.808 1.196.808 1.961s-.308 1.458-.808 1.962a2.66 2.66 0 0 1-1.915.809h-.049zm-2.971 7.643h-.05a3.1 3.1 0 0 1-2.236-.951l-.001-.001c-.584-.584-.945-1.391-.945-2.283s.361-1.698.945-2.283a3.1 3.1 0 0 1 2.234-.945h.054h-.003h.042c.877 0 1.67.362 2.237.944l.001.001c.588.582.952 1.39.952 2.283s-.364 1.7-.952 2.282a3.1 3.1 0 0 1-2.24.953h-.04z"})]})}var ie=require("react/jsx-runtime");function B(e,t="info",n="soft",r,i={},a){let{duration:o,position:l,onDismiss:y,onAutoClose:c,...m}=i;return $.toast.custom(d=>(0,ie.jsx)(se,{color:t,variant:n,title:e,description:r,closable:m.closable??!0,onClose:()=>{m.onClose?.(),$.toast.dismiss(d)},...m}),{id:a,duration:o??4e3,position:l,onDismiss:y,onAutoClose:c})}function We(e){return typeof e=="object"&&e!==null&&!(0,Ve.isValidElement)(e)&&!Array.isArray(e)&&("title"in e||"description"in e||"color"in e||"variant"in e)}function he(e,t,n){return We(e)?{title:e.title??"",description:e.description,color:e.color??t,variant:e.variant??n}:{title:e,description:void 0,color:t,variant:n}}var q=((e,t,n)=>{let r=n||{};return B(e,r.color||"info",r.variant||"soft",t,r)});q.custom=(e,t={})=>{if(typeof e=="function")return $.toast.custom(l=>e(l),{duration:t.duration??4e3,position:t.position,onDismiss:t.onDismiss,onAutoClose:t.onAutoClose});let{duration:n,position:r,onDismiss:i,onAutoClose:a,...o}=e;return $.toast.custom(l=>(0,ie.jsx)(se,{closable:o.closable??!0,onClose:()=>{o.onClose?.(),$.toast.dismiss(l)},...o}),{duration:n??4e3,position:r,onDismiss:i,onAutoClose:a})};q.success=(e,t,n)=>{let r=n||{};return B(e,r.color||"success",r.variant||"soft",t,r)};q.error=(e,t,n)=>{let r=n||{};return B(e,r.color||"error",r.variant||"soft",t,r)};q.warning=(e,t,n)=>{let r=n||{};return B(e,r.color||"warning",r.variant||"soft",t,r)};q.info=(e,t,n)=>{let r=n||{};return B(e,r.color||"info",r.variant||"soft",t,r)};q.loading=(e,t,n)=>{let r=n||{};return B(e,r.color||"info",r.variant||"soft",t,{...r,icon:r.icon??(0,ie.jsx)(xe,{className:"size-full animate-spin"}),duration:r.duration??1/0,closable:r.closable??!1})};q.promise=async(e,t)=>{let n=typeof e=="function"?e():e,{title:r,description:i}=he(t.loading,"info",t.variant||"soft"),a=q.loading(r,i,{size:t.size,variant:t.variant,radius:t.radius});try{let o=await n,l=typeof t.success=="function"?t.success(o):t.success,{title:y,description:c,color:m,variant:d}=he(l,"success",t.variant||"soft");return B(y,m,d,c,{duration:t.duration??4e3,size:t.size,radius:t.radius},a),o}catch(o){let l=typeof t.error=="function"?t.error(o):t.error,{title:y,description:c,color:m,variant:d}=he(l,"error",t.variant||"soft");throw B(y,m,d,c,{duration:t.duration??4e3,size:t.size,radius:t.radius},a),o}finally{t.finally&&await t.finally()}};q.dismiss=e=>$.toast.dismiss(e);var _=q;function we(e,t="\u0110\xE3 x\u1EA3y ra l\u1ED7i. Vui l\xF2ng th\u1EED l\u1EA1i sau."){if(!e)return t;if(typeof e=="string"&&e.trim())return e;if(typeof e=="object"&&e!==null){let n=e;if(n.response&&typeof n.response=="object"&&n.response!==null){let r=n.response,i=typeof r.status=="number"?r.status:void 0;if(r.data&&typeof r.data=="object"&&r.data!==null){let a=r.data;if(typeof a.message=="string"&&a.message.trim())return a.message;if(typeof a.error=="string"&&a.error.trim())return a.error;if(typeof a.detail=="string"&&a.detail.trim())return a.detail;if(typeof a.title=="string"&&a.title.trim())return a.title;if(Array.isArray(a.message)&&a.message.length>0){let o=a.message[0];if(typeof o=="string")return o}if(Array.isArray(a.errors)&&a.errors.length>0){let o=a.errors[0];if(typeof o=="string")return o;if(typeof o=="object"&&o!==null){let l=o;if(typeof l.message=="string"&&l.message.trim())return l.message}}}if(i)switch(i){case 400:return"D\u1EEF li\u1EC7u y\xEAu c\u1EA7u kh\xF4ng h\u1EE3p l\u1EC7 (400).";case 401:return"Phi\xEAn l\xE0m vi\u1EC7c \u0111\xE3 h\u1EBFt h\u1EA1n ho\u1EB7c ch\u01B0a \u0111\u0103ng nh\u1EADp (401).";case 403:return"B\u1EA1n kh\xF4ng c\xF3 quy\u1EC1n th\u1EF1c hi\u1EC7n thao t\xE1c n\xE0y (403).";case 404:return"Kh\xF4ng t\xECm th\u1EA5y d\u1EEF li\u1EC7u y\xEAu c\u1EA7u (404).";case 409:return"D\u1EEF li\u1EC7u b\u1ECB tr\xF9ng l\u1EB7p ho\u1EB7c xung \u0111\u1ED9t (409).";case 422:return"D\u1EEF li\u1EC7u g\u1EEDi l\xEAn kh\xF4ng \u0111\xFAng \u0111\u1ECBnh d\u1EA1ng (422).";case 500:return"L\u1ED7i m\xE1y ch\u1EE7 n\u1ED9i b\u1ED9. Vui l\xF2ng th\u1EED l\u1EA1i sau (500).";case 502:case 503:case 504:return"Kh\xF4ng th\u1EC3 k\u1EBFt n\u1ED1i \u0111\u1EBFn m\xE1y ch\u1EE7. Vui l\xF2ng th\u1EED l\u1EA1i sau."}}if(typeof n.message=="string"&&n.message.trim())return n.message;if(typeof n.error=="string"&&n.error.trim())return n.error;if(typeof n.detail=="string"&&n.detail.trim())return n.detail}return t}function Ze(e,t){return e?Array.isArray(e)?e.length===0?[]:e.every(r=>Array.isArray(r)||typeof r=="object"&&r!==null&&"queryKey"in r)?e.map(r=>Array.isArray(r)?{filters:{queryKey:r},options:t}:{filters:r,options:t}):[{filters:{queryKey:e},options:t}]:typeof e=="object"&&e!==null&&"queryKey"in e?[{filters:e,options:t}]:[]:[]}function Qe(e){let t=(0,le.useQueryClient)(),n=(0,Me.useRef)([]),{mutationFn:r,invalidateQueries:i,invalidateOptions:a,toast:o=!0,successMessage:l,errorMessage:y,loadingMessage:c,onMutate:m,onSuccess:d,onError:x,onSettled:R,...A}=e,f=o!==!1,p=typeof o=="object"&&o!==null?{...o}:{},v=c??p.loading,k=l??p.success,P=y??p.error??!0,U=p.variant??"soft",D=p.options,O=(0,le.useMutation)({...A,mutationFn:r,onMutate:async(s,b)=>{let h;if(f&&v){let I=typeof v=="function"?v(s):v,S=typeof p.loadingDescription=="function"?p.loadingDescription(s):p.loadingDescription;h=_.loading(I,S,{...D,variant:U}),n.current.push(h)}try{if(m)return await m(s,b)}catch(I){throw h&&(_.dismiss(h),n.current=n.current.filter(S=>S!==h)),I}},onSuccess:async(s,b,h,I)=>{let S=n.current.shift();if(S&&_.dismiss(S),f&&k){let E=typeof k=="function"?k(s,b):k,L=typeof p.successDescription=="function"?p.successDescription(s,b):p.successDescription;_.success(E,L,{...D,variant:U})}if(i){let E=typeof i=="function"?i(s,b):i,L=Ze(E,a);L.length>0&&await Promise.all(L.map(({filters:C,options:F})=>t.invalidateQueries(C,F)))}d&&await d(s,b,h,I)},onError:async(s,b,h,I)=>{let S=n.current.shift();if(S&&_.dismiss(S),f&&P!==!1){let E;typeof P=="function"?E=P(s,b):P===!0?E=we(s):E=P;let L=typeof p.errorDescription=="function"?p.errorDescription(s,b):p.errorDescription;_.error(E,L,{...D,variant:U})}x&&await x(s,b,h,I)},onSettled:async(s,b,h,I,S)=>{R&&await R(s,b,h,I,S)}});return{...O,isLoading:O.isPending}}0&&(module.exports={extractErrorMessage,useMutationApp,useSelectInfiniteQuery,useTableQuery});
|
|
2
|
+
"use strict";var fe=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var We=(e,t)=>{for(var n in t)fe(e,n,{get:t[n],enumerable:!0})},Ye=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of $e(t))!He.call(e,a)&&a!==n&&fe(e,a,{get:()=>t[a],enumerable:!(r=Ke(t,a))||r.enumerable});return e};var Ze=e=>Ye(fe({},"__esModule",{value:!0}),e);var st={};We(st,{extractErrorMessage:()=>ve,useMutationApp:()=>qe,useSelectInfiniteQuery:()=>Ue,useTableQuery:()=>ke});module.exports=Ze(st);var R=require("react"),le=require("@tanstack/react-query");var ge=10;var ie=require("react");function Ee(e,t=300){let[n,r]=(0,ie.useState)(e);return(0,ie.useEffect)(()=>{let a=setTimeout(()=>{r(e)},t);return()=>{clearTimeout(a)}},[e,t]),n}function Xe(e){if(!e)return[];if(Array.isArray(e))return e;if(typeof e=="object"){let t=e;if(Array.isArray(t.data))return t.data;if(Array.isArray(t.items))return t.items;if(Array.isArray(t.rows))return t.rows;if(Array.isArray(t.results))return t.results}return[]}function Je(e){if(!e)return 0;if(Array.isArray(e))return e.length;if(typeof e=="object"){let t=e,n=t.total??t.rowCount??t.totalCount??t.count;if(typeof n=="number")return n;if(typeof n=="string"){let r=Number(n);if(!isNaN(r))return r}}return 0}function me(e,t){return typeof e=="function"?e(t):e}function ke(e){let{queryKey:t,queryFn:n,selectData:r=Xe,selectRowCount:a=Je,initialPagination:s,initialSorting:o,initialColumnFilters:u,initialGlobalFilter:m,autoResetPageIndex:d=!0,debounceMs:p=300,queryOptions:b}=e,[w,y]=(0,R.useState)({pageIndex:s?.pageIndex??0,pageSize:s?.pageSize??ge}),[A,T]=(0,R.useState)(o??[]),[l,v]=(0,R.useState)(u??[]),[D,C]=(0,R.useState)(m??""),[U,G]=(0,R.useState)(l.length),k=l.length<U;l.length!==U&&G(l.length);let i=l.length===0||k?0:p,f=Ee(l,i),x=(0,R.useMemo)(()=>{let S={page:w.pageIndex+1,pageSize:w.pageSize},h=A[0];if(h&&(S.sortBy=h.id,S.sortOrder=h.desc?"desc":"asc"),f.length>0){let De={};f.forEach(Ie=>{De[Ie.id]=Ie.value}),S.filters=De}return S},[w.pageIndex,w.pageSize,A,f]),I=(0,R.useMemo)(()=>[...t,x],[t,x]),g=(0,le.useQuery)({queryKey:I,queryFn:S=>n(x,S),placeholderData:le.keepPreviousData,...b}),O=(0,R.useMemo)(()=>g.data?r(g.data):[],[g.data,r]),V=(0,R.useMemo)(()=>g.data?a(g.data):0,[g.data,a]),P=(0,R.useCallback)(S=>{y(h=>me(S,h))},[]),E=(0,R.useCallback)(S=>{T(h=>me(S,h)),d&&y(h=>h.pageIndex===0?h:{...h,pageIndex:0})},[d]),M=(0,R.useCallback)(S=>{v(h=>me(S,h)),d&&y(h=>h.pageIndex===0?h:{...h,pageIndex:0})},[d]),F=(0,R.useCallback)(S=>{C(S),d&&y(h=>h.pageIndex===0?h:{...h,pageIndex:0})},[d]),c=(0,R.useCallback)(()=>{y({pageIndex:s?.pageIndex??0,pageSize:s?.pageSize??ge}),T(o??[]),v(u??[]),C(m??"")},[s,o,u,m]),N=(0,R.useCallback)(S=>{y(h=>({...h,pageIndex:Math.max(0,S-1)}))},[]),H=(0,R.useCallback)(S=>{y({pageIndex:0,pageSize:S})},[]),oe=(0,R.useCallback)(S=>{F(S)},[F]),{isLoading:ee,isRefetching:se,refetch:Ce}=g,Ae=(0,R.useCallback)(()=>{Ce()},[Ce]);return{tableProps:(0,R.useMemo)(()=>({data:O,rowCount:V,isLoading:ee,isRefresh:se&&!ee,onRefresh:Ae,manualPagination:!0,manualSorting:!0,manualFiltering:!0,debounceMs:p,pagination:w,onPaginationChange:P,sorting:A,onSortingChange:E,columnFilters:l,onColumnFiltersChange:M,globalFilter:D,onGlobalFilterChange:F}),[O,V,ee,se,Ae,p,w,P,A,E,l,M,D,F]),query:g,queryParams:x,resetAll:c,setPage:N,setPageSize:H,setGlobalFilter:oe,setSorting:T,setColumnFilters:v}}var Q=require("react"),Me=require("@tanstack/react-query");var z=require("react");function Oe({onLoadMore:e,hasMore:t=!0,isLoading:n=!1,disabled:r=!1,rootMargin:a="100px",threshold:s=0,root:o=null}){let[u,m]=(0,z.useState)(!1),[d,p]=(0,z.useState)(null),b=(0,z.useRef)(!1),w=t&&!n&&!r,y=(0,z.useCallback)(()=>{if(!(!w||b.current)){b.current=!0;try{let T=e();T&&typeof T.then=="function"?T.finally(()=>{b.current=!1}):b.current=!1}catch{b.current=!1}}},[w,e]),A=(0,z.useCallback)(T=>{p(T)},[]);return(0,z.useEffect)(()=>{if(!d||r||!t||typeof window>"u"||!("IntersectionObserver"in window))return;let T=o&&typeof o=="object"&&"current"in o?o.current:o,l=new IntersectionObserver(v=>{let[D]=v;if(!D)return;let C=D.isIntersecting;m(C),C&&y()},{root:T,rootMargin:a,threshold:s});return l.observe(d),()=>{l.disconnect(),m(!1)}},[d,o,a,s,r,t,y]),(0,z.useEffect)(()=>{w&&u&&y()},[w,u,y]),{sentinelRef:A,isIntersecting:u}}var Fe={pulse:"animate-pulse",wave:"skeleton-wave",none:""},Ne={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",xl:"rounded-xl",full:"rounded-full"};var Ve=require("@tanstack/match-sorter-utils");function j(e,t,n){return e!=null&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:t[n]}var W=e=>e;var ue=require("react/jsx-runtime");function be({ref:e,variant:t="pulse",shape:n="rectangle",radius:r="md",width:a,height:s="1rem",lines:o=1,gap:u="0.5rem",className:m="",style:d,...p}){let b=j(t,Fe,"pulse"),w=n==="circle"?"rounded-full":j(r,Ne,"md"),y={width:W(a),height:W(s),...d},A=["bg-neutral-200",b,w].filter(Boolean).join(" ");return o>1?(0,ue.jsx)("div",{ref:e,role:"status","aria-label":"Loading...",className:["flex flex-col",m].filter(Boolean).join(" "),style:{gap:W(u),...d},...p,children:Array.from({length:o}).map((T,l)=>{let v=l===o-1;return(0,ue.jsx)("div",{className:A,style:{width:v?"60%":W(a)??"100%",height:W(s)}},l)})}):(0,ue.jsx)("div",{ref:e,role:"status","aria-label":"Loading...",className:[A,m].filter(Boolean).join(" "),style:y,...p})}var te=require("react/jsx-runtime");function ye(e){if(!e)return[];if(Array.isArray(e))return e;if(typeof e!="object")return[];let t=e;return Array.isArray(t.data)?t.data:Array.isArray(t.items)?t.items:Array.isArray(t.options)?t.options:Array.isArray(t.results)?t.results:Array.isArray(t.rows)?t.rows:[]}var et={};function Ue({queryKey:e,queryFn:t,initialPageParam:n=1,getNextPageParam:r,getPreviousPageParam:a,selectOptions:s,mapOption:o,debounceMs:u=300,initialSearch:m="",initialFilters:d=et,initialOptions:p,skeletonLines:b=2,skeletonHeight:w="1.75rem",renderLoadingMore:y,endMessage:A,scrollOptions:T,queryOptions:l}){let[v,D]=(0,Q.useState)(m),[C,U]=(0,Q.useState)(d),G=(0,Q.useMemo)(()=>[...e,{search:v,filters:C}],[e,v,C]),k=(0,Q.useCallback)((P,E,M,F)=>{if(r)return r(P,E,M,F);if(!P||typeof P!="object")return;let c=P;if(typeof c.nextPage=="number"||typeof c.nextPage=="string")return c.nextPage;if(typeof c.next_page=="number"||typeof c.next_page=="string")return c.next_page;if(typeof c.nextCursor=="string"||typeof c.nextCursor=="number")return c.nextCursor;if(typeof c.next_cursor=="string"||typeof c.next_cursor=="number")return c.next_cursor;if(!(c.hasMore===!1||c.has_more===!1||c.hasNextPage===!1)&&typeof M=="number"){if(ye(P).length===0)return;let H=typeof c.total=="number"?c.total:typeof c.totalCount=="number"?c.totalCount:typeof c.count=="number"?c.count:void 0;return H!==void 0&&E.reduce((ee,se)=>ee+ye(se).length,0)>=H?void 0:M+1}},[r]),i=(0,Me.useInfiniteQuery)({queryKey:G,queryFn:P=>t({pageParam:P.pageParam,search:v,filters:C},P),initialPageParam:n,getNextPageParam:k,getPreviousPageParam:a,...l}),f=(0,Q.useMemo)(()=>{let P=i.data?.pages??[],E=[],M=new Set;if(p&&p.length>0)for(let F of p)M.has(F.value)||(M.add(F.value),E.push(F));for(let F of P){let c=[];if(s)c=s(F);else{let N=ye(F);o?c=N.map((H,oe)=>o(H,oe)):c=N}for(let N of c)N&&N.value!==void 0&&!M.has(N.value)&&(M.add(N.value),E.push(N))}return E},[i.data?.pages,s,o,p]),{sentinelRef:x}=Oe({onLoadMore:()=>{i.hasNextPage&&!i.isFetchingNextPage&&i.fetchNextPage()},hasMore:!!i.hasNextPage,isLoading:i.isFetchingNextPage||i.isLoading,disabled:i.isError,rootMargin:T?.rootMargin??"80px",threshold:T?.threshold??0,root:T?.root}),I=(0,Q.useCallback)((P,E)=>{D(P),U(E)},[]),g=(0,Q.useCallback)(()=>{D(m),U(d)},[m,d]),O=(0,Q.useMemo)(()=>f.length===0?null:i.isFetchingNextPage?(0,te.jsx)("div",{ref:x,className:"p-1 space-y-1 w-full",children:y?y():(0,te.jsx)(be,{lines:b,height:w,gap:"0.25rem",radius:"sm",className:"p-0.5"})}):i.hasNextPage?(0,te.jsx)("div",{ref:x,className:"h-1 w-full","aria-hidden":"true"}):A?(0,te.jsx)("div",{className:"py-2 px-1 text-center text-xs text-neutral-400",children:A}):null,[f.length,i.isFetchingNextPage,i.hasNextPage,x,y,b,w,A]);return{selectProps:(0,Q.useMemo)(()=>({options:f,isLoading:i.isLoading,searchMode:"server",debounceMs:u,onSearch:I,listFooter:O}),[f,i.isLoading,u,I,O]),query:i,options:f,search:v,setSearch:D,filters:C,setFilters:U,sentinelRef:x,reset:g}}var Be=require("react"),pe=require("@tanstack/react-query");var tt=require("sonner");var rt=require("react/jsx-runtime");var Ge=require("react"),$=require("sonner");var Y=require("react/jsx-runtime");function Z({width:e=20,height:t=20,className:n="",...r}){return(0,Y.jsxs)("svg",{width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:n,...r,children:[(0,Y.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,Y.jsx)("path",{d:"M12 16v-4"}),(0,Y.jsx)("path",{d:"M12 8h.01"})]})}var re=require("react/jsx-runtime");function Te({width:e=20,height:t=20,className:n="",...r}){return(0,re.jsxs)("svg",{width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:n,...r,children:[(0,re.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,re.jsx)("path",{d:"m9 12 2 2 4-4"})]})}var X=require("react/jsx-runtime");function xe({width:e=20,height:t=20,className:n="",...r}){return(0,X.jsxs)("svg",{width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:n,...r,children:[(0,X.jsx)("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),(0,X.jsx)("path",{d:"M12 9v4"}),(0,X.jsx)("path",{d:"M12 17h.01"})]})}var J=require("react/jsx-runtime");function he({width:e=20,height:t=20,className:n="",...r}){return(0,J.jsxs)("svg",{width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:n,...r,children:[(0,J.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,J.jsx)("path",{d:"M12 8v4"}),(0,J.jsx)("path",{d:"M12 16h.01"})]})}var Qe={xs:{container:"p-2 gap-2 text-xs",title:"text-xs font-semibold leading-tight",description:"text-[11px] leading-tight",icon:"size-3.5 mt-0.5",closeButton:"size-4 p-0.5 -mr-0.5",closeIcon:"size-3",action:"gap-1.5 text-xs"},sm:{container:"p-2.5 gap-2.5 text-xs",title:"text-sm font-semibold leading-tight",description:"text-xs leading-normal",icon:"size-4 mt-0.5",closeButton:"size-5 p-0.5 -mr-0.5",closeIcon:"size-3.5",action:"gap-1.5 text-xs"},md:{container:"p-3.5 gap-3 text-sm",title:"text-sm font-semibold leading-tight",description:"text-sm leading-normal",icon:"size-5 mt-0.5",closeButton:"size-6 p-1 -mr-1",closeIcon:"size-4",action:"gap-2 text-sm"},lg:{container:"p-4 gap-3.5 text-base",title:"text-base font-semibold leading-snug",description:"text-sm leading-normal",icon:"size-6 mt-0.5",closeButton:"size-7 p-1.5 -mr-1.5",closeIcon:"size-4.5",action:"gap-2.5 text-sm"},xl:{container:"p-5 gap-4 text-lg",title:"text-lg font-semibold leading-snug",description:"text-base leading-normal",icon:"size-7 mt-0.5",closeButton:"size-8 p-1.5 -mr-1.5",closeIcon:"size-5",action:"gap-3 text-base"}},Le={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",xl:"rounded-xl",full:"rounded-2xl"},ze={soft:{primary:"bg-primary-50 text-primary-900 border-2 border-primary-200",secondary:"bg-secondary-50 text-secondary-900 border-2 border-secondary-200",neutral:"bg-neutral-100 text-neutral-900 border-2 border-neutral-200",error:"bg-error-50 text-error-900 border-2 border-error-200",success:"bg-success-50 text-success-900 border-2 border-success-200",warning:"bg-warning-50 text-warning-900 border-2 border-warning-200",info:"bg-info-50 text-info-900 border-2 border-info-200"},filled:{primary:"bg-primary-600 text-white border-2 border-primary-600",secondary:"bg-secondary-600 text-white border-2 border-secondary-600",neutral:"bg-neutral-700 text-white border-2 border-neutral-700",error:"bg-error-600 text-white border-2 border-error-600",success:"bg-success-600 text-white border-2 border-success-600",warning:"bg-warning-500 text-neutral-950 border-2 border-warning-500",info:"bg-info-600 text-white border-2 border-info-600"},outline:{primary:"bg-neutral-white text-primary-700 border-2 border-primary-400",secondary:"bg-neutral-white text-secondary-700 border-2 border-secondary-400",neutral:"bg-neutral-white text-neutral-700 border-2 border-neutral-300",error:"bg-neutral-white text-error-700 border-2 border-error-500",success:"bg-neutral-white text-success-700 border-2 border-success-400",warning:"bg-neutral-white text-warning-800 border-2 border-warning-400",info:"bg-neutral-white text-info-700 border-2 border-info-400"},"accent-left":{primary:"bg-primary-50/70 text-primary-900 border-2 border-primary-200 border-l-4 border-l-primary-500",secondary:"bg-secondary-50/70 text-secondary-900 border-2 border-secondary-200 border-l-4 border-l-secondary-500",neutral:"bg-neutral-50/70 text-neutral-900 border-2 border-neutral-200 border-l-4 border-l-neutral-500",error:"bg-error-50/70 text-error-900 border-2 border-error-200 border-l-4 border-l-error-500",success:"bg-success-50/70 text-success-900 border-2 border-success-200 border-l-4 border-l-success-500",warning:"bg-warning-50/70 text-warning-900 border-2 border-warning-200 border-l-4 border-l-warning-500",info:"bg-info-50/70 text-info-900 border-2 border-info-200 border-l-4 border-l-info-500"},ghost:{primary:"bg-transparent text-primary-800 border-2 border-transparent",secondary:"bg-transparent text-secondary-800 border-2 border-transparent",neutral:"bg-transparent text-neutral-800 border-2 border-transparent",error:"bg-transparent text-error-700 border-2 border-transparent",success:"bg-transparent text-success-700 border-2 border-transparent",warning:"bg-transparent text-warning-800 border-2 border-transparent",info:"bg-transparent text-info-800 border-2 border-transparent"}},je={soft:{primary:"text-primary-600",secondary:"text-secondary-600",neutral:"text-neutral-600",error:"text-error-600",success:"text-success-600",warning:"text-warning-600",info:"text-info-600"},filled:{primary:"text-white",secondary:"text-white",neutral:"text-white",error:"text-white",success:"text-white",warning:"text-neutral-950",info:"text-white"},outline:{primary:"text-primary-600",secondary:"text-secondary-600",neutral:"text-neutral-600",error:"text-error-600",success:"text-success-600",warning:"text-warning-600",info:"text-info-600"},"accent-left":{primary:"text-primary-600",secondary:"text-secondary-600",neutral:"text-neutral-600",error:"text-error-600",success:"text-success-600",warning:"text-warning-600",info:"text-info-600"},ghost:{primary:"text-primary-600",secondary:"text-secondary-600",neutral:"text-neutral-600",error:"text-error-600",success:"text-success-600",warning:"text-warning-600",info:"text-info-600"}},_e={primary:Z,secondary:Z,neutral:Z,info:Z,success:Te,warning:xe,error:he};var Re=require("react/jsx-runtime");function we({width:e=14,height:t=14,className:n="",...r}){return(0,Re.jsx)("svg",{width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:n,...r,children:(0,Re.jsx)("path",{d:"M18 6 6 18M6 6l12 12"})})}var L=require("react/jsx-runtime");function ce({size:e,variant:t,color:n,radius:r,title:a,description:s,icon:o=!0,action:u,closable:m=!0,onClose:d,closeAriaLabel:p="\u0110\xF3ng c\u1EA3nh b\xE1o",banner:b=!1,titleClassName:w="",descriptionClassName:y="",actionClassName:A="",iconClassName:T="",closeButtonClassName:l="",className:v="",children:D,role:C,ref:U,...G}){let k=j(e,Qe,"md"),i=b?"rounded-none border-x-0 w-full":j(r,Le,"lg"),f=t==="other"?"":j(n,j(t,ze,"soft"),"info"),x=t==="other"?"":j(n,j(t,je,"soft"),"info"),I=m||!!d,g=N=>{N.stopPropagation(),d?.()},V=C||(n==="error"||n==="warning"?"alert":"status"),P=n==="error"||n==="warning"?"assertive":"polite",E=s??D,M=!!E,F=()=>{if(o===!1)return null;if(o!==!0&&o!==void 0)return(0,L.jsx)("span",{className:`inline-flex items-center justify-center shrink-0 leading-none ${k.icon} ${T}`,"aria-hidden":"true",children:o});let N=j(n,_e,"info");return(0,L.jsx)("span",{className:`inline-flex items-center justify-center shrink-0 leading-none ${k.icon} ${x} ${T}`,"aria-hidden":"true",children:(0,L.jsx)(N,{className:"size-full"})})},c=["relative flex w-full",k.container,i,f,v].filter(Boolean).join(" ");return(0,L.jsxs)("div",{ref:U,role:V,"aria-live":P,className:c,...G,children:[F(),(0,L.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col justify-center",children:[a&&(0,L.jsx)("div",{className:`${k.title} ${w}`,children:a}),M&&(0,L.jsx)("div",{className:`${k.description} ${a?"mt-0.5":""} ${y}`,children:E})]}),u&&(0,L.jsx)("div",{className:`inline-flex items-center shrink-0 ${k.action} ${A}`,children:u}),I&&(0,L.jsx)("button",{type:"button",onClick:g,"aria-label":p,className:`inline-flex items-center justify-center shrink-0 rounded-md transition-colors cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-current opacity-70 hover:opacity-100 ${t==="filled"?"hover:bg-white/20 active:bg-white/30":"hover:bg-black/5 active:bg-black/10"} ${k.closeButton} ${l}`,children:(0,L.jsx)(we,{className:k.closeIcon})})]})}var ne=require("react/jsx-runtime");function Pe({width:e=16,height:t=16,className:n="",...r}){return(0,ne.jsxs)("svg",{width:e,height:t,className:`animate-[spin_1s_steps(8)_infinite] ${n}`,viewBox:"0 0 25 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r,children:[(0,ne.jsx)("path",{d:"M0 0h25v24H0z",fill:"none"}),(0,ne.jsx)("path",{fill:"currentColor",d:"M4.818 6.664h-.001a1.847 1.847 0 1 1 1.306-.541a1.77 1.77 0 0 1-1.277.541h-.029zm-2.97 7.182h-.001a1.847 1.847 0 1 1 1.306-.541a1.77 1.77 0 0 1-1.278.541h-.031h.002zM12 3.692a1.847 1.847 0 1 1 1.306-.541a1.77 1.77 0 0 1-1.277.541zM4.818 21.029h-.001a1.847 1.847 0 1 1 1.306-.541a1.77 1.77 0 0 1-1.276.541h-.031zM19.182 7.125a2.308 2.308 0 1 1 0-4.615a2.308 2.308 0 0 1 0 4.615M12 24a1.847 1.847 0 1 1 1.306-.541a1.77 1.77 0 0 1-1.277.541zm10.154-9.231h-.048c-.75 0-1.428-.309-1.913-.807l-.001-.001c-.499-.503-.808-1.196-.808-1.961s.308-1.458.808-1.962a2.66 2.66 0 0 1 1.914-.808h.05h-.003h.048c.75 0 1.427.309 1.913.807l.001.001c.499.503.808 1.196.808 1.961s-.308 1.458-.808 1.962a2.66 2.66 0 0 1-1.915.809h-.049zm-2.971 7.643h-.05a3.1 3.1 0 0 1-2.236-.951l-.001-.001c-.584-.584-.945-1.391-.945-2.283s.361-1.698.945-2.283a3.1 3.1 0 0 1 2.234-.945h.054h-.003h.042c.877 0 1.67.362 2.237.944l.001.001c.588.582.952 1.39.952 2.283s-.364 1.7-.952 2.282a3.1 3.1 0 0 1-2.24.953h-.04z"})]})}var de=require("react/jsx-runtime");function B(e,t="info",n="soft",r,a={},s){let{duration:o,position:u,onDismiss:m,onAutoClose:d,...p}=a;return $.toast.custom(b=>(0,de.jsx)(ce,{color:t,variant:n,title:e,description:r,closable:p.closable??!0,onClose:()=>{p.onClose?.(),$.toast.dismiss(b)},...p}),{id:s,duration:o??4e3,position:u,onDismiss:m,onAutoClose:d})}function nt(e){return typeof e=="object"&&e!==null&&!(0,Ge.isValidElement)(e)&&!Array.isArray(e)&&("title"in e||"description"in e||"color"in e||"variant"in e)}function Se(e,t,n){return nt(e)?{title:e.title??"",description:e.description,color:e.color??t,variant:e.variant??n}:{title:e,description:void 0,color:t,variant:n}}var _=((e,t,n)=>{let r=n||{};return B(e,r.color||"info",r.variant||"soft",t,r)});_.custom=(e,t={})=>{if(typeof e=="function")return $.toast.custom(u=>e(u),{duration:t.duration??4e3,position:t.position,onDismiss:t.onDismiss,onAutoClose:t.onAutoClose});let{duration:n,position:r,onDismiss:a,onAutoClose:s,...o}=e;return $.toast.custom(u=>(0,de.jsx)(ce,{closable:o.closable??!0,onClose:()=>{o.onClose?.(),$.toast.dismiss(u)},...o}),{duration:n??4e3,position:r,onDismiss:a,onAutoClose:s})};_.success=(e,t,n)=>{let r=n||{};return B(e,r.color||"success",r.variant||"soft",t,r)};_.error=(e,t,n)=>{let r=n||{};return B(e,r.color||"error",r.variant||"soft",t,r)};_.warning=(e,t,n)=>{let r=n||{};return B(e,r.color||"warning",r.variant||"soft",t,r)};_.info=(e,t,n)=>{let r=n||{};return B(e,r.color||"info",r.variant||"soft",t,r)};_.loading=(e,t,n)=>{let r=n||{};return B(e,r.color||"info",r.variant||"soft",t,{...r,icon:r.icon??(0,de.jsx)(Pe,{className:"size-full animate-spin"}),duration:r.duration??1/0,closable:r.closable??!1})};_.promise=async(e,t)=>{let n=typeof e=="function"?e():e,{title:r,description:a}=Se(t.loading,"info",t.variant||"soft"),s=_.loading(r,a,{size:t.size,variant:t.variant,radius:t.radius});try{let o=await n,u=typeof t.success=="function"?t.success(o):t.success,{title:m,description:d,color:p,variant:b}=Se(u,"success",t.variant||"soft");return B(m,p,b,d,{duration:t.duration??4e3,size:t.size,radius:t.radius},s),o}catch(o){let u=typeof t.error=="function"?t.error(o):t.error,{title:m,description:d,color:p,variant:b}=Se(u,"error",t.variant||"soft");throw B(m,p,b,d,{duration:t.duration??4e3,size:t.size,radius:t.radius},s),o}finally{t.finally&&await t.finally()}};_.dismiss=e=>$.toast.dismiss(e);var q=_;function ve(e,t="\u0110\xE3 x\u1EA3y ra l\u1ED7i. Vui l\xF2ng th\u1EED l\u1EA1i sau."){if(!e)return t;if(typeof e=="string"&&e.trim())return e;if(typeof e=="object"&&e!==null){let n=e;if(n.response&&typeof n.response=="object"&&n.response!==null){let r=n.response,a=typeof r.status=="number"?r.status:void 0;if(r.data&&typeof r.data=="object"&&r.data!==null){let s=r.data;if(typeof s.message=="string"&&s.message.trim())return s.message;if(typeof s.error=="string"&&s.error.trim())return s.error;if(typeof s.detail=="string"&&s.detail.trim())return s.detail;if(typeof s.title=="string"&&s.title.trim())return s.title;if(Array.isArray(s.message)&&s.message.length>0){let o=s.message[0];if(typeof o=="string")return o}if(Array.isArray(s.errors)&&s.errors.length>0){let o=s.errors[0];if(typeof o=="string")return o;if(typeof o=="object"&&o!==null){let u=o;if(typeof u.message=="string"&&u.message.trim())return u.message}}}if(a)switch(a){case 400:return"D\u1EEF li\u1EC7u y\xEAu c\u1EA7u kh\xF4ng h\u1EE3p l\u1EC7 (400).";case 401:return"Phi\xEAn l\xE0m vi\u1EC7c \u0111\xE3 h\u1EBFt h\u1EA1n ho\u1EB7c ch\u01B0a \u0111\u0103ng nh\u1EADp (401).";case 403:return"B\u1EA1n kh\xF4ng c\xF3 quy\u1EC1n th\u1EF1c hi\u1EC7n thao t\xE1c n\xE0y (403).";case 404:return"Kh\xF4ng t\xECm th\u1EA5y d\u1EEF li\u1EC7u y\xEAu c\u1EA7u (404).";case 409:return"D\u1EEF li\u1EC7u b\u1ECB tr\xF9ng l\u1EB7p ho\u1EB7c xung \u0111\u1ED9t (409).";case 422:return"D\u1EEF li\u1EC7u g\u1EEDi l\xEAn kh\xF4ng \u0111\xFAng \u0111\u1ECBnh d\u1EA1ng (422).";case 500:return"L\u1ED7i m\xE1y ch\u1EE7 n\u1ED9i b\u1ED9. Vui l\xF2ng th\u1EED l\u1EA1i sau (500).";case 502:case 503:case 504:return"Kh\xF4ng th\u1EC3 k\u1EBFt n\u1ED1i \u0111\u1EBFn m\xE1y ch\u1EE7. Vui l\xF2ng th\u1EED l\u1EA1i sau."}}if(typeof n.message=="string"&&n.message.trim())return n.message;if(typeof n.error=="string"&&n.error.trim())return n.error;if(typeof n.detail=="string"&&n.detail.trim())return n.detail}return t}function ot(e,t){return e?Array.isArray(e)?e.length===0?[]:e.every(r=>Array.isArray(r)||typeof r=="object"&&r!==null&&"queryKey"in r)?e.map(r=>Array.isArray(r)?{filters:{queryKey:r},options:t}:{filters:r,options:t}):[{filters:{queryKey:e},options:t}]:typeof e=="object"&&e!==null&&"queryKey"in e?[{filters:e,options:t}]:[]:[]}function qe(e){let t=(0,pe.useQueryClient)(),n=(0,Be.useRef)([]),{mutationFn:r,invalidateQueries:a,invalidateOptions:s,toast:o=!0,successMessage:u,errorMessage:m,loadingMessage:d,onMutate:p,onSuccess:b,onError:w,onSettled:y,...A}=e,T=o!==!1,l=typeof o=="object"&&o!==null?{...o}:{},v=d??l.loading,D=u??l.success,C=m??l.error??!0,U=l.variant??"soft",G=l.options,k=(0,pe.useMutation)({...A,mutationFn:r,onMutate:async(i,f)=>{let x;if(T&&v){let I=typeof v=="function"?v(i):v,g=typeof l.loadingDescription=="function"?l.loadingDescription(i):l.loadingDescription;x=q.loading(I,g,{...G,variant:U}),n.current.push(x)}try{if(p)return await p(i,f)}catch(I){throw x&&(q.dismiss(x),n.current=n.current.filter(g=>g!==x)),I}},onSuccess:async(i,f,x,I)=>{let g=n.current.shift();if(g&&q.dismiss(g),T&&D){let O=typeof D=="function"?D(i,f):D,V=typeof l.successDescription=="function"?l.successDescription(i,f):l.successDescription;q.success(O,V,{...G,variant:U})}if(a){let O=typeof a=="function"?a(i,f):a,V=ot(O,s);V.length>0&&await Promise.all(V.map(({filters:P,options:E})=>t.invalidateQueries(P,E)))}b&&await b(i,f,x,I)},onError:async(i,f,x,I)=>{let g=n.current.shift();if(g&&q.dismiss(g),T&&C!==!1){let O;typeof C=="function"?O=C(i,f):C===!0?O="\u0110\xE3 x\u1EA3y ra l\u1ED7i":O=C;let V=typeof l.errorDescription=="function"?l.errorDescription(i,f):l.errorDescription,P=V!==void 0?V||void 0:ve(i);q.error(O,P,{...G,variant:U})}w&&await w(i,f,x,I)},onSettled:async(i,f,x,I,g)=>{y&&await y(i,f,x,I,g)}});return{...k,isLoading:k.isPending}}0&&(module.exports={extractErrorMessage,useMutationApp,useSelectInfiniteQuery,useTableQuery});
|
|
3
3
|
//# sourceMappingURL=query.cjs.map
|