@hanzo/ui 5.4.1 → 5.6.0
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/bin/create-registry.js +0 -0
- package/bin/npx-registry-mcp.js +0 -0
- package/bin/registry-mcp-wrapper.sh +0 -0
- package/bin/registry-mcp.js +0 -0
- package/bin/start-mcp-server.sh +0 -0
- package/bin/test-mcp.sh +0 -0
- package/dist/auth/index.js +3 -0
- package/dist/auth/index.mjs +3 -0
- package/dist/dash/crud.js +2 -0
- package/dist/dash/crud.mjs +2 -0
- package/dist/dash/form.js +2 -0
- package/dist/dash/form.mjs +2 -0
- package/dist/dash/{dash-header.js → header.js} +1 -1
- package/dist/dash/{dash-header.mjs → header.mjs} +1 -1
- package/dist/dash/index.js +2 -2
- package/dist/dash/index.mjs +2 -2
- package/dist/dash/{dash-layout.js → layout.js} +1 -1
- package/dist/dash/{dash-layout.mjs → layout.mjs} +1 -1
- package/dist/dash/sidebar.js +3 -0
- package/dist/dash/sidebar.mjs +3 -0
- package/dist/dash/{dash-data-table.js → table.js} +1 -1
- package/dist/dash/{dash-data-table.mjs → table.mjs} +1 -1
- package/dist/src/dash/{dash-crud.d.ts → crud.d.ts} +9 -9
- package/dist/src/dash/crud.d.ts.map +1 -0
- package/dist/src/dash/{dash-crud.js → crud.js} +5 -5
- package/dist/src/dash/{dash-form.d.ts → form.d.ts} +9 -9
- package/dist/src/dash/form.d.ts.map +1 -0
- package/dist/src/dash/{dash-form.js → form.js} +1 -1
- package/dist/src/dash/{dash-header.d.ts → header.d.ts} +3 -3
- package/dist/src/dash/header.d.ts.map +1 -0
- package/dist/src/dash/{dash-header.js → header.js} +1 -1
- package/dist/src/dash/index.d.ts +12 -12
- package/dist/src/dash/index.d.ts.map +1 -1
- package/dist/src/dash/index.js +6 -6
- package/dist/src/dash/{dash-layout.d.ts → layout.d.ts} +5 -5
- package/dist/src/dash/layout.d.ts.map +1 -0
- package/dist/src/dash/{dash-layout.js → layout.js} +1 -1
- package/dist/src/dash/{dash-sidebar.d.ts → sidebar.d.ts} +3 -3
- package/dist/src/dash/sidebar.d.ts.map +1 -0
- package/dist/src/dash/{dash-sidebar.js → sidebar.js} +1 -1
- package/dist/src/dash/{dash-data-table.d.ts → table.d.ts} +5 -5
- package/dist/src/dash/table.d.ts.map +1 -0
- package/dist/src/dash/{dash-data-table.js → table.js} +1 -1
- package/package.json +75 -74
- package/dist/dash/dash-crud.js +0 -2
- package/dist/dash/dash-crud.mjs +0 -2
- package/dist/dash/dash-form.js +0 -2
- package/dist/dash/dash-form.mjs +0 -2
- package/dist/dash/dash-sidebar.js +0 -3
- package/dist/dash/dash-sidebar.mjs +0 -3
- package/dist/src/dash/dash-crud.d.ts.map +0 -1
- package/dist/src/dash/dash-data-table.d.ts.map +0 -1
- package/dist/src/dash/dash-form.d.ts.map +0 -1
- package/dist/src/dash/dash-header.d.ts.map +0 -1
- package/dist/src/dash/dash-layout.d.ts.map +0 -1
- package/dist/src/dash/dash-sidebar.d.ts.map +0 -1
package/bin/create-registry.js
CHANGED
|
File without changes
|
package/bin/npx-registry-mcp.js
CHANGED
|
File without changes
|
|
File without changes
|
package/bin/registry-mcp.js
CHANGED
|
File without changes
|
package/bin/start-mcp-server.sh
CHANGED
|
File without changes
|
package/bin/test-mcp.sh
CHANGED
|
File without changes
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var j=Object.defineProperty;var n=(t,e)=>j(t,"name",{value:e,configurable:true});function Y({iamUrl:t="https://hanzo.id",clientId:e,redirectUri:o,label:r="Sign in with Hanzo",className:l="",variant:s="default"}){let[c,i]=react.useState(false),u=react.useCallback(()=>{i(true);let a=o||`${window.location.origin}/auth/callback`,m=crypto.randomUUID(),h=new URL(`${t}/login/oauth/authorize`);h.searchParams.set("client_id",e),h.searchParams.set("response_type","code"),h.searchParams.set("redirect_uri",a),h.searchParams.set("scope","openid profile email"),h.searchParams.set("state",m),window.location.href=h.toString();},[t,e,o]);return jsxRuntime.jsxs("button",{type:"button",className:`inline-flex items-center justify-center gap-2 rounded-md px-4 py-2.5 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 ${s==="outline"?"border border-[#333] bg-transparent text-white hover:bg-[#1a1a1f]":"bg-white text-black hover:bg-[#e5e5e5]"} ${l}`,onClick:u,disabled:c,children:[jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 32 32",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("text",{x:"4",y:"26",fontFamily:"-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif",fontSize:"28",fontWeight:"700",fill:"currentColor",children:"H"})}),c?"Redirecting...":r]})}n(Y,"IAMLoginButton");var E="hanzo-auth-token",S="hanzo-user",$="hanzo-auth-expires",V="https://iam.hanzo.ai",X={hanzo:{name:"Hanzo AI",slug:"hanzo"},lux:{name:"Lux Network",slug:"lux"},zoo:{name:"Zoo Labs",slug:"zoo"},pars:{name:"Pars",slug:"pars"}};function A(){let[t,e]=react.useState(void 0),[o,r]=react.useState([]),[l,s]=react.useState(void 0),[c,i]=react.useState(null),[u,f]=react.useState(true),g=react.useCallback(async()=>{try{let h=localStorage.getItem(E),H=localStorage.getItem($);if(!h||H&&Date.now()>Number(H)){f(!1);return}i(h);let R=localStorage.getItem(S);if(R)try{let p=JSON.parse(R);p?.email&&e({id:p.id,name:p.displayName||p.name,email:p.email,avatar:p.avatar});}catch{}let U=await fetch(`${V}/api/userinfo`,{headers:{Authorization:`Bearer ${h}`}});if(U.ok){let p=await U.json(),B={id:p.sub||p.id,name:p.name||p.displayName,email:p.email,avatar:p.picture||p.avatar};e(B),localStorage.setItem(S,JSON.stringify(p));let x=(p.groups||[]).map(G=>{let D=G.toLowerCase().replace(/^\//,""),k=X[D];return k?{id:D,name:k.name,slug:k.slug}:null}).filter(Boolean);x.length===0&&B.email&&x.push({id:"personal",name:"Personal",slug:"personal"}),r(x),s(x[0]?.id);}}catch{}finally{f(false);}},[]);react.useEffect(()=>{g();},[g]);let a=react.useCallback(()=>{localStorage.removeItem(E),localStorage.removeItem(S),localStorage.removeItem($),window.location.href="https://hanzo.id";},[]),m=react.useCallback(h=>{s(h);},[]);return {user:t,organizations:o,currentOrgId:l,token:c,loading:u,signOut:a,switchOrg:m}}n(A,"useHanzoAuth");function Q({loginUrl:t,clientId:e,fallback:o,children:r}){let{user:l,loading:s}=A();return react.useEffect(()=>{if(!s&&!l)if(t)window.location.href=t;else if(e){let c=`${window.location.origin}/auth/callback`,i=new URL("https://hanzo.id/login/oauth/authorize");i.searchParams.set("client_id",e),i.searchParams.set("response_type","code"),i.searchParams.set("redirect_uri",c),i.searchParams.set("scope","openid profile email"),window.location.href=i.toString();}else window.location.href="https://hanzo.id";},[s,l,t,e]),s?jsxRuntime.jsx(jsxRuntime.Fragment,{children:o??jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",minHeight:"100vh",background:"#09090b",color:"#888"},children:"Loading..."})}):l?jsxRuntime.jsx(jsxRuntime.Fragment,{children:r}):null}n(Q,"AuthGuard");var O={hanzo:{id:"hanzo",iam:"https://hanzo.id",billing:"https://billing.hanzo.ai",console:"https://console.hanzo.ai",cloud:"https://cloud.hanzo.ai",chat:"https://hanzo.chat",flow:"https://flow.hanzo.ai",bot:"https://hanzo.bot",o11y:"https://o11y.hanzo.ai",sentry:"https://sentry.hanzo.ai",insights:"https://insights.hanzo.ai",analytics:"https://analytics.hanzo.ai",platform:"https://platform.hanzo.ai",storage:"https://s3.hanzo.ai",s3:"https://s3.hanzo.ai",kms:"https://kms.hanzo.ai",dns:"https://dns.hanzo.ai",registry:"https://registry.hanzo.ai",commerce:"https://commerce.hanzo.ai",base:"https://base.hanzo.ai",search:"https://search.hanzo.ai",auto:"https://auto.hanzo.ai",team:"https://hanzo.team",sign:"https://sign.hanzo.ai",dataroom:"https://dataroom.hanzo.ai",captable:"https://captable.hanzo.ai",docs:"https://docs.hanzo.ai",status:"https://status.hanzo.ai"},lux:{id:"lux",iam:"https://lux.id",billing:"https://billing.lux.network",console:"https://console.lux.network",cloud:"https://cloud.lux.network",chat:"https://lux.chat",flow:"https://flow.lux.network",bot:"https://bot.lux.network",o11y:"https://o11y.lux.network",sentry:"https://sentry.lux.network",insights:"https://insights.lux.network",analytics:"https://analytics.lux.network",platform:"https://platform.lux.network",storage:"https://s3.lux.network",s3:"https://s3.lux.network",kms:"https://kms.lux.network",dns:"https://dns.lux.network",registry:"https://registry.lux.network",commerce:"https://commerce.lux.network",base:"https://base.lux.network",search:"https://search.lux.network",auto:"https://auto.lux.network",team:"https://team.lux.network",sign:"https://sign.lux.network",dataroom:"https://dataroom.lux.network",captable:"https://captable.lux.network",docs:"https://docs.lux.network",status:"https://status.lux.network"},zoo:{id:"zoo",iam:"https://zoo.id",billing:"https://billing.zoo.ngo",console:"https://console.zoo.ngo",cloud:"https://cloud.zoo.network",chat:"https://chat.zoo.ngo",flow:"https://flow.zoo.ngo",bot:"https://bot.zoo.ngo",o11y:"https://o11y.zoo.network",sentry:"https://sentry.zoo.network",insights:"https://insights.zoo.ngo",analytics:"https://analytics.zoo.ngo",platform:"https://platform.zoo.ngo",storage:"https://s3.zoo.ngo",s3:"https://s3.zoo.ngo",kms:"https://kms.zoo.network",dns:"https://dns.zoo.ngo",registry:"https://registry.zoo.ngo",commerce:"https://commerce.zoo.ngo",base:"https://base.zoo.ngo",search:"https://search.zoo.ngo",auto:"https://auto.zoo.ngo",team:"https://team.zoo.ngo",sign:"https://sign.zoo.ngo",dataroom:"https://dataroom.zoo.ngo",captable:"https://captable.zoo.ngo",docs:"https://docs.zoo.ngo",status:"https://status.zoo.network"},pars:{id:"pars",iam:"https://pars.id",billing:"https://billing.pars.network",console:"https://console.pars.network",cloud:"https://cloud.pars.network",chat:"https://chat.pars.network",flow:"https://flow.pars.network",bot:"https://bot.pars.network",o11y:"https://o11y.pars.network",sentry:"https://sentry.pars.network",insights:"https://insights.pars.network",analytics:"https://analytics.pars.network",platform:"https://platform.pars.network",storage:"https://s3.pars.network",s3:"https://s3.pars.network",kms:"https://kms.pars.network",dns:"https://dns.pars.network",registry:"https://registry.pars.network",commerce:"https://commerce.pars.network",base:"https://base.pars.network",search:"https://search.pars.network",auto:"https://auto.pars.network",team:"https://team.pars.network",sign:"https://sign.pars.network",dataroom:"https://dataroom.pars.network",captable:"https://captable.pars.network",docs:"https://docs.pars.network",status:"https://status.pars.network"}};var tt=["#0A0310","#49007E","#FF005B","#FF7D10","#FFB238"];function et(t){let e=0;for(let o=0;o<t.length;o++)e=(e<<5)-e+t.charCodeAt(o)|0;return Math.abs(e)}n(et,"hashStr");function y(t,e,o){return t%(e*(o+1))%e}n(y,"getUnit");function ot(t,e){return y(t,2,e)===0}n(ot,"getBoolean");function F(t,e,o){return o[y(t,o.length,e)]}n(F,"getRandomColor");function st(t){let e=parseInt(t.slice(1,3),16),o=parseInt(t.slice(3,5),16),r=parseInt(t.slice(5,7),16);return e*.299+o*.587+r*.114>128?"#000":"#fff"}n(st,"getContrast");function T({name:t,size:e=40,colors:o=tt,className:r,square:l=false}){let s=et(t),c=F(s,0,o),i=st(c),u=ot(s,2),f=y(s,3,7),g=y(s,5,8),a=y(s,10,9),m=a>6?a-10:a,h=y(s,5,10)>3?y(s,5,10)-5:y(s,5,10);return jsxRuntime.jsxs("svg",{viewBox:"0 0 36 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",width:e,height:e,className:r,style:l?void 0:{borderRadius:"50%"},children:[jsxRuntime.jsx("mask",{id:`beam-${s}`,maskUnits:"userSpaceOnUse",x:0,y:0,width:36,height:36,children:jsxRuntime.jsx("rect",{width:36,height:36,rx:l?void 0:72,fill:"#fff"})}),jsxRuntime.jsxs("g",{mask:`url(#beam-${s})`,children:[jsxRuntime.jsx("rect",{width:36,height:36,fill:c}),jsxRuntime.jsx("rect",{x:0,y:0,width:36,height:36,transform:`translate(${m} ${h}) rotate(${a} 18 18)`,fill:F(s,1,o),rx:6}),jsxRuntime.jsxs("g",{transform:`translate(${m} ${h}) rotate(${a} 18 18)`,children:[u?jsxRuntime.jsx("path",{d:`M15 ${19+f}c2 1 4 1 6 0`,stroke:i,fill:"none",strokeLinecap:"round"}):jsxRuntime.jsx("path",{d:`M13 ${19+f}a1 .75 0 0 0 10 0`,fill:i}),jsxRuntime.jsx("rect",{x:14-g,y:14,width:1.5,height:2,rx:1,fill:i}),jsxRuntime.jsx("rect",{x:20+g,y:14,width:1.5,height:2,rx:1,fill:i})]})]})]})}n(T,"BeamAvatar");async function rt(t){let o=new TextEncoder().encode(t),r=await crypto.subtle.digest("SHA-256",o);return Array.from(new Uint8Array(r)).map(l=>l.toString(16).padStart(2,"0")).join("")}n(rt,"sha256");function nt(t,e){let[o,r]=react.useState(null);return react.useMemo(()=>{if(!t){r(null);return}let l=t.trim().toLowerCase();rt(l).then(s=>{r(`https://www.gravatar.com/avatar/${s}?s=${e||80}&d=404`);});},[t,e]),o}n(nt,"useGravatarUrl");function _({src:t,email:e,name:o,size:r=40,colors:l,className:s}){let[c,i]=react.useState(false),[u,f]=react.useState(false),g=nt(e,r*2),a=`rounded-full object-cover ${s||""}`,m={width:r,height:r};return t&&!c?jsxRuntime.jsx("img",{src:t,alt:o||e||"avatar",className:a,style:m,onError:()=>i(true)}):g&&!u?jsxRuntime.jsx("img",{src:g,alt:o||e||"avatar",className:a,style:m,onError:()=>f(true)}):jsxRuntime.jsx(T,{name:o||e||"user",size:r,colors:l,className:s})}n(_,"UserAvatar");function ht({user:t,organizations:e=[],currentOrgId:o,onOrgSwitch:r,onSignOut:l}){let[s,c]=react.useState(false),i=react.useRef(null);if(react.useEffect(()=>{let a=n(m=>{i.current&&!i.current.contains(m.target)&&c(false);},"handler");return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[]),!t)return null;let u=e.find(a=>a.id===o),f=u?.slug||"hanzo",g=O[f]||O.hanzo;return jsxRuntime.jsxs("div",{ref:i,className:"relative",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>c(a=>!a),className:"flex items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-white/[0.06] transition-colors",children:[jsxRuntime.jsx(_,{src:t.avatar,email:t.email,name:t.name,size:28}),jsxRuntime.jsxs("div",{className:"hidden flex-col items-start sm:flex",children:[t.name&&jsxRuntime.jsx("span",{className:"text-[12px] font-medium text-white/70 leading-none",children:t.name}),jsxRuntime.jsx("span",{className:"text-[11px] text-white/30 leading-none mt-0.5",children:t.email})]}),jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-white/30 hidden sm:block",children:jsxRuntime.jsx("path",{d:"M6 9l6 6 6-6"})})]}),s&&jsxRuntime.jsxs("div",{className:"absolute right-0 top-10 z-50 w-64 rounded-xl border border-white/[0.08] bg-[#0e0e13] shadow-2xl",children:[jsxRuntime.jsxs("div",{className:"border-b border-white/[0.06] px-4 py-3",children:[jsxRuntime.jsx("p",{className:"text-[13px] font-medium text-white/80",children:t.name||"User"}),jsxRuntime.jsx("p",{className:"text-[11px] text-white/40",children:t.email}),u&&jsxRuntime.jsx("p",{className:"mt-0.5 text-[10px] font-medium text-white/25 uppercase tracking-wider",children:u.name})]}),e.length>0&&jsxRuntime.jsxs("div",{className:"border-b border-white/[0.06] p-2",children:[jsxRuntime.jsx("p",{className:"px-2 pb-1 pt-0.5 text-[10px] font-medium uppercase tracking-wider text-white/30",children:"Organizations"}),e.map(a=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{r?.(a.id),c(false);},className:"flex w-full items-center justify-between rounded-lg px-3 py-2 text-left hover:bg-white/[0.06] transition-colors",children:[jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-[13px] text-white/70",children:a.name}),a.role&&jsxRuntime.jsx("span",{className:"text-[10px] text-white/25 capitalize",children:a.role})]}),a.id===o&&jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-white/50",children:jsxRuntime.jsx("polyline",{points:"20 6 9 17 4 12"})})]},a.id))]}),jsxRuntime.jsxs("div",{className:"p-2",children:[jsxRuntime.jsx("a",{href:`${g.iam}/account`,className:"flex items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] text-white/60 hover:bg-white/[0.06] hover:text-white/80 transition-colors",onClick:()=>c(false),children:"Account settings"}),jsxRuntime.jsx("a",{href:g.billing,className:"flex items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] text-white/60 hover:bg-white/[0.06] hover:text-white/80 transition-colors",onClick:()=>c(false),children:"Billing"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{c(false),l?.();},className:"flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] text-white/40 hover:bg-white/[0.06] hover:text-red-400/70 transition-colors",children:"Sign out"})]})]})]})}n(ht,"UserOrgDropdown");
|
|
3
|
+
exports.AuthGuard=Q;exports.IAMLoginButton=Y;exports.UserOrgDropdown=ht;exports.useHanzoAuth=A;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {useState,useCallback,useEffect,useRef,useMemo}from'react';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var j=Object.defineProperty;var n=(t,e)=>j(t,"name",{value:e,configurable:true});function Y({iamUrl:t="https://hanzo.id",clientId:e,redirectUri:o,label:r="Sign in with Hanzo",className:l="",variant:s="default"}){let[c,i]=useState(false),u=useCallback(()=>{i(true);let a=o||`${window.location.origin}/auth/callback`,m=crypto.randomUUID(),h=new URL(`${t}/login/oauth/authorize`);h.searchParams.set("client_id",e),h.searchParams.set("response_type","code"),h.searchParams.set("redirect_uri",a),h.searchParams.set("scope","openid profile email"),h.searchParams.set("state",m),window.location.href=h.toString();},[t,e,o]);return jsxs("button",{type:"button",className:`inline-flex items-center justify-center gap-2 rounded-md px-4 py-2.5 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 ${s==="outline"?"border border-[#333] bg-transparent text-white hover:bg-[#1a1a1f]":"bg-white text-black hover:bg-[#e5e5e5]"} ${l}`,onClick:u,disabled:c,children:[jsx("svg",{width:"16",height:"16",viewBox:"0 0 32 32",xmlns:"http://www.w3.org/2000/svg",children:jsx("text",{x:"4",y:"26",fontFamily:"-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif",fontSize:"28",fontWeight:"700",fill:"currentColor",children:"H"})}),c?"Redirecting...":r]})}n(Y,"IAMLoginButton");var E="hanzo-auth-token",S="hanzo-user",$="hanzo-auth-expires",V="https://iam.hanzo.ai",X={hanzo:{name:"Hanzo AI",slug:"hanzo"},lux:{name:"Lux Network",slug:"lux"},zoo:{name:"Zoo Labs",slug:"zoo"},pars:{name:"Pars",slug:"pars"}};function A(){let[t,e]=useState(void 0),[o,r]=useState([]),[l,s]=useState(void 0),[c,i]=useState(null),[u,f]=useState(true),g=useCallback(async()=>{try{let h=localStorage.getItem(E),H=localStorage.getItem($);if(!h||H&&Date.now()>Number(H)){f(!1);return}i(h);let R=localStorage.getItem(S);if(R)try{let p=JSON.parse(R);p?.email&&e({id:p.id,name:p.displayName||p.name,email:p.email,avatar:p.avatar});}catch{}let U=await fetch(`${V}/api/userinfo`,{headers:{Authorization:`Bearer ${h}`}});if(U.ok){let p=await U.json(),B={id:p.sub||p.id,name:p.name||p.displayName,email:p.email,avatar:p.picture||p.avatar};e(B),localStorage.setItem(S,JSON.stringify(p));let x=(p.groups||[]).map(G=>{let D=G.toLowerCase().replace(/^\//,""),k=X[D];return k?{id:D,name:k.name,slug:k.slug}:null}).filter(Boolean);x.length===0&&B.email&&x.push({id:"personal",name:"Personal",slug:"personal"}),r(x),s(x[0]?.id);}}catch{}finally{f(false);}},[]);useEffect(()=>{g();},[g]);let a=useCallback(()=>{localStorage.removeItem(E),localStorage.removeItem(S),localStorage.removeItem($),window.location.href="https://hanzo.id";},[]),m=useCallback(h=>{s(h);},[]);return {user:t,organizations:o,currentOrgId:l,token:c,loading:u,signOut:a,switchOrg:m}}n(A,"useHanzoAuth");function Q({loginUrl:t,clientId:e,fallback:o,children:r}){let{user:l,loading:s}=A();return useEffect(()=>{if(!s&&!l)if(t)window.location.href=t;else if(e){let c=`${window.location.origin}/auth/callback`,i=new URL("https://hanzo.id/login/oauth/authorize");i.searchParams.set("client_id",e),i.searchParams.set("response_type","code"),i.searchParams.set("redirect_uri",c),i.searchParams.set("scope","openid profile email"),window.location.href=i.toString();}else window.location.href="https://hanzo.id";},[s,l,t,e]),s?jsx(Fragment,{children:o??jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",minHeight:"100vh",background:"#09090b",color:"#888"},children:"Loading..."})}):l?jsx(Fragment,{children:r}):null}n(Q,"AuthGuard");var O={hanzo:{id:"hanzo",iam:"https://hanzo.id",billing:"https://billing.hanzo.ai",console:"https://console.hanzo.ai",cloud:"https://cloud.hanzo.ai",chat:"https://hanzo.chat",flow:"https://flow.hanzo.ai",bot:"https://hanzo.bot",o11y:"https://o11y.hanzo.ai",sentry:"https://sentry.hanzo.ai",insights:"https://insights.hanzo.ai",analytics:"https://analytics.hanzo.ai",platform:"https://platform.hanzo.ai",storage:"https://s3.hanzo.ai",s3:"https://s3.hanzo.ai",kms:"https://kms.hanzo.ai",dns:"https://dns.hanzo.ai",registry:"https://registry.hanzo.ai",commerce:"https://commerce.hanzo.ai",base:"https://base.hanzo.ai",search:"https://search.hanzo.ai",auto:"https://auto.hanzo.ai",team:"https://hanzo.team",sign:"https://sign.hanzo.ai",dataroom:"https://dataroom.hanzo.ai",captable:"https://captable.hanzo.ai",docs:"https://docs.hanzo.ai",status:"https://status.hanzo.ai"},lux:{id:"lux",iam:"https://lux.id",billing:"https://billing.lux.network",console:"https://console.lux.network",cloud:"https://cloud.lux.network",chat:"https://lux.chat",flow:"https://flow.lux.network",bot:"https://bot.lux.network",o11y:"https://o11y.lux.network",sentry:"https://sentry.lux.network",insights:"https://insights.lux.network",analytics:"https://analytics.lux.network",platform:"https://platform.lux.network",storage:"https://s3.lux.network",s3:"https://s3.lux.network",kms:"https://kms.lux.network",dns:"https://dns.lux.network",registry:"https://registry.lux.network",commerce:"https://commerce.lux.network",base:"https://base.lux.network",search:"https://search.lux.network",auto:"https://auto.lux.network",team:"https://team.lux.network",sign:"https://sign.lux.network",dataroom:"https://dataroom.lux.network",captable:"https://captable.lux.network",docs:"https://docs.lux.network",status:"https://status.lux.network"},zoo:{id:"zoo",iam:"https://zoo.id",billing:"https://billing.zoo.ngo",console:"https://console.zoo.ngo",cloud:"https://cloud.zoo.network",chat:"https://chat.zoo.ngo",flow:"https://flow.zoo.ngo",bot:"https://bot.zoo.ngo",o11y:"https://o11y.zoo.network",sentry:"https://sentry.zoo.network",insights:"https://insights.zoo.ngo",analytics:"https://analytics.zoo.ngo",platform:"https://platform.zoo.ngo",storage:"https://s3.zoo.ngo",s3:"https://s3.zoo.ngo",kms:"https://kms.zoo.network",dns:"https://dns.zoo.ngo",registry:"https://registry.zoo.ngo",commerce:"https://commerce.zoo.ngo",base:"https://base.zoo.ngo",search:"https://search.zoo.ngo",auto:"https://auto.zoo.ngo",team:"https://team.zoo.ngo",sign:"https://sign.zoo.ngo",dataroom:"https://dataroom.zoo.ngo",captable:"https://captable.zoo.ngo",docs:"https://docs.zoo.ngo",status:"https://status.zoo.network"},pars:{id:"pars",iam:"https://pars.id",billing:"https://billing.pars.network",console:"https://console.pars.network",cloud:"https://cloud.pars.network",chat:"https://chat.pars.network",flow:"https://flow.pars.network",bot:"https://bot.pars.network",o11y:"https://o11y.pars.network",sentry:"https://sentry.pars.network",insights:"https://insights.pars.network",analytics:"https://analytics.pars.network",platform:"https://platform.pars.network",storage:"https://s3.pars.network",s3:"https://s3.pars.network",kms:"https://kms.pars.network",dns:"https://dns.pars.network",registry:"https://registry.pars.network",commerce:"https://commerce.pars.network",base:"https://base.pars.network",search:"https://search.pars.network",auto:"https://auto.pars.network",team:"https://team.pars.network",sign:"https://sign.pars.network",dataroom:"https://dataroom.pars.network",captable:"https://captable.pars.network",docs:"https://docs.pars.network",status:"https://status.pars.network"}};var tt=["#0A0310","#49007E","#FF005B","#FF7D10","#FFB238"];function et(t){let e=0;for(let o=0;o<t.length;o++)e=(e<<5)-e+t.charCodeAt(o)|0;return Math.abs(e)}n(et,"hashStr");function y(t,e,o){return t%(e*(o+1))%e}n(y,"getUnit");function ot(t,e){return y(t,2,e)===0}n(ot,"getBoolean");function F(t,e,o){return o[y(t,o.length,e)]}n(F,"getRandomColor");function st(t){let e=parseInt(t.slice(1,3),16),o=parseInt(t.slice(3,5),16),r=parseInt(t.slice(5,7),16);return e*.299+o*.587+r*.114>128?"#000":"#fff"}n(st,"getContrast");function T({name:t,size:e=40,colors:o=tt,className:r,square:l=false}){let s=et(t),c=F(s,0,o),i=st(c),u=ot(s,2),f=y(s,3,7),g=y(s,5,8),a=y(s,10,9),m=a>6?a-10:a,h=y(s,5,10)>3?y(s,5,10)-5:y(s,5,10);return jsxs("svg",{viewBox:"0 0 36 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",width:e,height:e,className:r,style:l?void 0:{borderRadius:"50%"},children:[jsx("mask",{id:`beam-${s}`,maskUnits:"userSpaceOnUse",x:0,y:0,width:36,height:36,children:jsx("rect",{width:36,height:36,rx:l?void 0:72,fill:"#fff"})}),jsxs("g",{mask:`url(#beam-${s})`,children:[jsx("rect",{width:36,height:36,fill:c}),jsx("rect",{x:0,y:0,width:36,height:36,transform:`translate(${m} ${h}) rotate(${a} 18 18)`,fill:F(s,1,o),rx:6}),jsxs("g",{transform:`translate(${m} ${h}) rotate(${a} 18 18)`,children:[u?jsx("path",{d:`M15 ${19+f}c2 1 4 1 6 0`,stroke:i,fill:"none",strokeLinecap:"round"}):jsx("path",{d:`M13 ${19+f}a1 .75 0 0 0 10 0`,fill:i}),jsx("rect",{x:14-g,y:14,width:1.5,height:2,rx:1,fill:i}),jsx("rect",{x:20+g,y:14,width:1.5,height:2,rx:1,fill:i})]})]})]})}n(T,"BeamAvatar");async function rt(t){let o=new TextEncoder().encode(t),r=await crypto.subtle.digest("SHA-256",o);return Array.from(new Uint8Array(r)).map(l=>l.toString(16).padStart(2,"0")).join("")}n(rt,"sha256");function nt(t,e){let[o,r]=useState(null);return useMemo(()=>{if(!t){r(null);return}let l=t.trim().toLowerCase();rt(l).then(s=>{r(`https://www.gravatar.com/avatar/${s}?s=${e||80}&d=404`);});},[t,e]),o}n(nt,"useGravatarUrl");function _({src:t,email:e,name:o,size:r=40,colors:l,className:s}){let[c,i]=useState(false),[u,f]=useState(false),g=nt(e,r*2),a=`rounded-full object-cover ${s||""}`,m={width:r,height:r};return t&&!c?jsx("img",{src:t,alt:o||e||"avatar",className:a,style:m,onError:()=>i(true)}):g&&!u?jsx("img",{src:g,alt:o||e||"avatar",className:a,style:m,onError:()=>f(true)}):jsx(T,{name:o||e||"user",size:r,colors:l,className:s})}n(_,"UserAvatar");function ht({user:t,organizations:e=[],currentOrgId:o,onOrgSwitch:r,onSignOut:l}){let[s,c]=useState(false),i=useRef(null);if(useEffect(()=>{let a=n(m=>{i.current&&!i.current.contains(m.target)&&c(false);},"handler");return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[]),!t)return null;let u=e.find(a=>a.id===o),f=u?.slug||"hanzo",g=O[f]||O.hanzo;return jsxs("div",{ref:i,className:"relative",children:[jsxs("button",{type:"button",onClick:()=>c(a=>!a),className:"flex items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-white/[0.06] transition-colors",children:[jsx(_,{src:t.avatar,email:t.email,name:t.name,size:28}),jsxs("div",{className:"hidden flex-col items-start sm:flex",children:[t.name&&jsx("span",{className:"text-[12px] font-medium text-white/70 leading-none",children:t.name}),jsx("span",{className:"text-[11px] text-white/30 leading-none mt-0.5",children:t.email})]}),jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-white/30 hidden sm:block",children:jsx("path",{d:"M6 9l6 6 6-6"})})]}),s&&jsxs("div",{className:"absolute right-0 top-10 z-50 w-64 rounded-xl border border-white/[0.08] bg-[#0e0e13] shadow-2xl",children:[jsxs("div",{className:"border-b border-white/[0.06] px-4 py-3",children:[jsx("p",{className:"text-[13px] font-medium text-white/80",children:t.name||"User"}),jsx("p",{className:"text-[11px] text-white/40",children:t.email}),u&&jsx("p",{className:"mt-0.5 text-[10px] font-medium text-white/25 uppercase tracking-wider",children:u.name})]}),e.length>0&&jsxs("div",{className:"border-b border-white/[0.06] p-2",children:[jsx("p",{className:"px-2 pb-1 pt-0.5 text-[10px] font-medium uppercase tracking-wider text-white/30",children:"Organizations"}),e.map(a=>jsxs("button",{type:"button",onClick:()=>{r?.(a.id),c(false);},className:"flex w-full items-center justify-between rounded-lg px-3 py-2 text-left hover:bg-white/[0.06] transition-colors",children:[jsxs("div",{className:"flex flex-col",children:[jsx("span",{className:"text-[13px] text-white/70",children:a.name}),a.role&&jsx("span",{className:"text-[10px] text-white/25 capitalize",children:a.role})]}),a.id===o&&jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-white/50",children:jsx("polyline",{points:"20 6 9 17 4 12"})})]},a.id))]}),jsxs("div",{className:"p-2",children:[jsx("a",{href:`${g.iam}/account`,className:"flex items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] text-white/60 hover:bg-white/[0.06] hover:text-white/80 transition-colors",onClick:()=>c(false),children:"Account settings"}),jsx("a",{href:g.billing,className:"flex items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] text-white/60 hover:bg-white/[0.06] hover:text-white/80 transition-colors",onClick:()=>c(false),children:"Billing"}),jsx("button",{type:"button",onClick:()=>{c(false),l?.();},className:"flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] text-white/40 hover:bg-white/[0.06] hover:text-red-400/70 transition-colors",children:"Sign out"})]})]})]})}n(ht,"UserOrgDropdown");
|
|
3
|
+
export{Q as AuthGuard,Y as IAMLoginButton,ht as UserOrgDropdown,A as useHanzoAuth};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';var $=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var $__namespace=/*#__PURE__*/_interopNamespace($);var I=Object.defineProperty;var c=(e,r)=>I(e,"name",{value:r,configurable:true});function n(...e){return tailwindMerge.twMerge(clsx.clsx(e))}c(n,"cn");function Z({columns:e,data:r,rowKey:h,selectable:i=false,selectedKeys:m,onSelectionChange:p,searchable:y=false,searchPlaceholder:b="Search...",totalRows:o,page:u=0,pageSize:P=20,onPageChange:F,onPageSizeChange:D,actions:V,loading:q=false,emptyMessage:d="No data",className:l}){let[a,g]=$__namespace.useState(""),[w,K]=$__namespace.useState(null),z=$__namespace.useMemo(()=>{if(!a)return r;let t=a.toLowerCase();return r.filter(f=>e.some(M=>(M.cell?"":String(f[M.id]??"")).toLowerCase().includes(t)))},[r,a,e]),j=$__namespace.useMemo(()=>{if(!w)return z;let{column:t,direction:f}=w;return [...z].sort((M,T)=>{let H=M[t],Q=T[t];if(H==null&&Q==null)return 0;if(H==null)return 1;if(Q==null)return -1;let Y=String(H).localeCompare(String(Q),void 0,{numeric:true});return f==="asc"?Y:-Y})},[z,w]),O=o??j.length,E=Math.max(1,Math.ceil(O/P)),L=F?j:j.slice(u*P,(u+1)*P),C=m??new Set,W=L.length>0&&L.every(t=>C.has(h(t)));function _(){p&&p(W?new Set:new Set(L.map(h)));}c(_,"toggleAll");function A(t){if(!p)return;let f=new Set(C);f.has(t)?f.delete(t):f.add(t),p(f);}c(A,"toggleRow");function G(t){K(f=>f?.column===t?f.direction==="asc"?{column:t,direction:"desc"}:null:{column:t,direction:"asc"});}c(G,"handleSort");let x=V?[...e,{id:"__actions",header:"",width:"auto"}]:e;return jsxRuntime.jsxs("div",{className:n("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)]",l),children:[(y||i)&&jsxRuntime.jsxs("div",{className:"flex items-center gap-3 border-b border-[var(--dash-border)] px-4 py-3",children:[y&&jsxRuntime.jsx("input",{type:"text",placeholder:b,value:a,onChange:t=>g(t.target.value),className:n("h-8 w-64 max-w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]")}),i&&C.size>0&&jsxRuntime.jsxs("span",{className:"text-xs text-[var(--dash-text-muted)]",children:[C.size," selected"]})]}),jsxRuntime.jsx("div",{className:"overflow-x-auto",children:jsxRuntime.jsxs("table",{className:"w-full text-sm",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"border-b border-[var(--dash-border)]",children:[i&&jsxRuntime.jsx("th",{className:"w-10 px-4 py-2.5",children:jsxRuntime.jsx("input",{type:"checkbox",checked:W,onChange:_,className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),x.map(t=>jsxRuntime.jsx("th",{style:t.width?{width:t.width}:void 0,className:n("px-4 py-2.5 text-[var(--dash-text-dim)] font-medium",t.align==="center"&&"text-center",t.align==="right"&&"text-right",!t.align&&"text-left",t.sortable&&"cursor-pointer select-none hover:text-[var(--dash-text-muted)]"),onClick:t.sortable?()=>G(t.id):void 0,children:jsxRuntime.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.header,t.sortable&&w?.column===t.id&&jsxRuntime.jsx("span",{className:"text-[10px]",children:w.direction==="asc"?"\u2191":"\u2193"})]})},t.id))]})}),jsxRuntime.jsx("tbody",{children:q?jsxRuntime.jsx("tr",{children:jsxRuntime.jsx("td",{colSpan:x.length+(i?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:"Loading..."})}):L.length===0?jsxRuntime.jsx("tr",{children:jsxRuntime.jsx("td",{colSpan:x.length+(i?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:d})}):L.map(t=>{let f=h(t),M=C.has(f);return jsxRuntime.jsxs("tr",{className:n("border-b border-[var(--dash-border)] transition-colors",M?"bg-[var(--dash-surface-active)]":"hover:bg-[var(--dash-surface-hover)]"),children:[i&&jsxRuntime.jsx("td",{className:"w-10 px-4 py-2.5",children:jsxRuntime.jsx("input",{type:"checkbox",checked:M,onChange:()=>A(f),className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),e.map(T=>jsxRuntime.jsx("td",{className:n("px-4 py-2.5",T.align==="center"&&"text-center",T.align==="right"&&"text-right"),children:T.cell?T.cell(t):String(t[T.id]??"")},T.id)),V&&jsxRuntime.jsx("td",{className:"px-4 py-2.5 text-right",children:V(t)})]},f)})})]})}),E>1&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-[var(--dash-border)] px-4 py-2.5 text-xs text-[var(--dash-text-muted)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{children:"Rows per page"}),jsxRuntime.jsx("select",{value:P,onChange:t=>D?.(Number(t.target.value)),className:"h-7 rounded border border-[var(--dash-border)] bg-[var(--dash-bg)] px-2 text-xs text-[var(--dash-text)] focus:outline-none",children:[10,20,50,100].map(t=>jsxRuntime.jsx("option",{value:t,children:t},t))})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("span",{children:["Page ",u+1," of ",E]}),jsxRuntime.jsx("button",{type:"button",disabled:u===0,onClick:()=>F?.(u-1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsxRuntime.jsx("button",{type:"button",disabled:u>=E-1,onClick:()=>F?.(u+1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})]})}c(Z,"Table");function U({title:e,fields:r,values:h,onSubmit:i,onCancel:m,submitLabel:p="Save",cancelLabel:y="Cancel",loading:b=false,className:o}){let[u,P]=$__namespace.useState(()=>{let d={};for(let l of r)d[l.name]=h?.[l.name]??l.defaultValue??(l.type==="toggle"?false:"");return d}),[F,D]=$__namespace.useState({});function V(d,l){P(a=>({...a,[d]:l})),D(a=>{if(!a[d])return a;let g={...a};return delete g[d],g});}c(V,"setValue");async function q(d){d.preventDefault();let l={};for(let a of r){let g=u[a.name];if(a.required&&(g===""||g===null||g===void 0)&&(l[a.name]=`${a.label} is required`),a.validate){let w=a.validate(g);w&&(l[a.name]=w);}}if(Object.keys(l).length>0){D(l);return}await i(u);}return c(q,"handleSubmit"),jsxRuntime.jsxs("form",{onSubmit:q,className:n("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6",o),children:[e&&jsxRuntime.jsx("h3",{className:"mb-4 text-lg font-semibold text-[var(--dash-text)]",children:e}),jsxRuntime.jsx("div",{className:"space-y-4",children:r.map(d=>jsxRuntime.jsx(re,{field:d,value:u[d.name],error:F[d.name],onChange:l=>V(d.name,l)},d.name))}),jsxRuntime.jsxs("div",{className:"mt-6 flex items-center gap-3",children:[jsxRuntime.jsx("button",{type:"submit",disabled:b,className:n("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]","disabled:opacity-50 disabled:cursor-not-allowed"),children:b?"Saving...":p}),m&&jsxRuntime.jsx("button",{type:"button",onClick:m,disabled:b,className:n("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:y})]})]})}c(U,"Form");var J=n("w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 py-2 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors");function re({field:e,value:r,error:h,onChange:i}){let m=`dash-field-${e.name}`,p=jsxRuntime.jsxs("label",{htmlFor:m,className:"mb-1 block text-sm font-medium text-[var(--dash-text)]",children:[e.label,e.required&&jsxRuntime.jsx("span",{className:"ml-0.5 text-[var(--dash-error)]",children:"*"})]}),y=e.description?jsxRuntime.jsx("p",{className:"mt-1 text-xs text-[var(--dash-text-dim)]",children:e.description}):null,b=h?jsxRuntime.jsx("p",{className:"mt-1 text-xs text-[var(--dash-error)]",children:h}):null;switch(e.type){case "text":case "email":case "password":case "number":return jsxRuntime.jsxs("div",{children:[p,jsxRuntime.jsx("input",{id:m,type:e.type,value:String(r??""),placeholder:e.placeholder,disabled:e.disabled,onChange:o=>i(e.type==="number"?Number(o.target.value):o.target.value),className:n(J,h&&"border-[var(--dash-error)]")}),y,b]});case "textarea":return jsxRuntime.jsxs("div",{children:[p,jsxRuntime.jsx("textarea",{id:m,value:String(r??""),placeholder:e.placeholder,disabled:e.disabled,rows:e.rows??3,onChange:o=>i(o.target.value),className:n(J,"resize-y",h&&"border-[var(--dash-error)]")}),y,b]});case "select":case "relation":return jsxRuntime.jsxs("div",{children:[p,jsxRuntime.jsxs("select",{id:m,value:String(r??""),disabled:e.disabled,onChange:o=>i(o.target.value),className:n(J,h&&"border-[var(--dash-error)]"),children:[jsxRuntime.jsx("option",{value:"",children:e.placeholder??"Select..."}),(e.options??[]).map(o=>jsxRuntime.jsx("option",{value:o.value,children:o.label},o.value))]}),y,b]});case "toggle":return jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("button",{id:m,type:"button",role:"switch","aria-checked":!!r,disabled:e.disabled,onClick:()=>i(!r),className:n("relative inline-flex h-5 w-9 flex-shrink-0 rounded-full transition-colors","focus:outline-none focus:ring-2 focus:ring-[var(--dash-primary)] focus:ring-offset-2 focus:ring-offset-[var(--dash-surface)]",r?"bg-[var(--dash-primary)]":"bg-[var(--dash-border)]",e.disabled&&"opacity-50 cursor-not-allowed"),children:jsxRuntime.jsx("span",{className:n("pointer-events-none inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",r?"translate-x-4":"translate-x-0.5","mt-0.5")})}),jsxRuntime.jsx("label",{htmlFor:m,className:"text-sm text-[var(--dash-text)]",children:e.label}),y,b]});case "json":return jsxRuntime.jsxs("div",{children:[p,jsxRuntime.jsx("textarea",{id:m,value:typeof r=="string"?r:JSON.stringify(r,null,2),placeholder:e.placeholder??"{}",disabled:e.disabled,rows:e.rows??6,onChange:o=>{try{i(JSON.parse(o.target.value));}catch{i(o.target.value);}},className:n(J,"font-mono text-xs resize-y",h&&"border-[var(--dash-error)]")}),y,b]});case "file":return jsxRuntime.jsxs("div",{children:[p,jsxRuntime.jsx("input",{id:m,type:"file",accept:e.accept,disabled:e.disabled,onChange:o=>{let u=o.target.files?.[0];u&&i(u);},className:n("w-full text-sm text-[var(--dash-text-muted)]","file:mr-3 file:rounded-[var(--dash-radius-sm)] file:border-0 file:bg-[var(--dash-primary)] file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-[var(--dash-primary-text)]","file:cursor-pointer hover:file:bg-[var(--dash-primary-hover)]")}),y,b]});default:return null}}c(re,"FieldRenderer");function we({resourceName:e,resourceNamePlural:r,columns:h,data:i,rowKey:m,fields:p,rowToValues:y,onCreate:b,onUpdate:o,onDelete:u,canCreate:P=true,canEdit:F=true,canDelete:D=true,tableProps:V,loading:q=false,className:d}){let l=r??`${e}s`,[a,g]=$__namespace.useState("list"),[w,K]=$__namespace.useState(null),[z,j]=$__namespace.useState({}),[O,E]=$__namespace.useState(null),[L,C]=$__namespace.useState(false);function W(x){let t=m(x);K(t),j(y?y(x):x),g("edit");}c(W,"handleEdit");function _(x){E(m(x));}c(_,"handleDeleteConfirm");async function A(){if(!(!O||!u)){C(true);try{await u(O);}finally{C(false),E(null);}}}c(A,"confirmDelete");function G(x){return jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1",children:[F&&o&&jsxRuntime.jsx("button",{type:"button",onClick:()=>W(x),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-text-muted)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors",children:"Edit"}),D&&u&&jsxRuntime.jsx("button",{type:"button",onClick:()=>_(x),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-error)] hover:bg-[var(--dash-error-dim)] transition-colors",children:"Delete"})]})}return c(G,"actionsRenderer"),a==="list"?jsxRuntime.jsxs("div",{className:n("space-y-4",d),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("h2",{className:"text-xl font-semibold text-[var(--dash-text)]",children:l}),P&&b&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{K(null),j({}),g("create");},className:n("rounded-[var(--dash-radius)] px-3 py-1.5 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]"),children:["Create ",e]})]}),jsxRuntime.jsx(Z,{columns:h,data:i,rowKey:m,actions:F||D?G:void 0,loading:q,searchable:true,emptyMessage:`No ${l.toLowerCase()} found`,...V}),O!==null&&jsxRuntime.jsx(ae,{resourceName:e,loading:L,onConfirm:A,onCancel:()=>E(null)})]}):jsxRuntime.jsxs("div",{className:n("space-y-4",d),children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>g("list"),className:"inline-flex items-center gap-1 text-sm text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),"Back to ",l]}),jsxRuntime.jsx(U,{title:a==="create"?`Create ${e}`:`Edit ${e}`,fields:p,values:a==="edit"?z:void 0,loading:L,submitLabel:a==="create"?"Create":"Save changes",onCancel:()=>g("list"),onSubmit:async x=>{C(true);try{a==="create"&&b?await b(x):a==="edit"&&w&&o&&await o(w,x),g("list");}finally{C(false);}}})]})}c(we,"Crud");function ae({resourceName:e,loading:r,onConfirm:h,onCancel:i}){return jsxRuntime.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",children:jsxRuntime.jsxs("div",{className:"w-full max-w-sm rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6 shadow-lg",children:[jsxRuntime.jsxs("h3",{className:"text-lg font-semibold text-[var(--dash-text)]",children:["Delete ",e,"?"]}),jsxRuntime.jsxs("p",{className:"mt-2 text-sm text-[var(--dash-text-muted)]",children:["This action cannot be undone. The ",e.toLowerCase()," will be permanently removed."]}),jsxRuntime.jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[jsxRuntime.jsx("button",{type:"button",onClick:i,disabled:r,className:n("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:h,disabled:r,className:n("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-error)] text-white","hover:bg-red-600","disabled:opacity-50 disabled:cursor-not-allowed"),children:r?"Deleting...":"Delete"})]})]})})}c(ae,"DeleteDialog");exports.Crud=we;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import*as $ from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsxs,jsx}from'react/jsx-runtime';var I=Object.defineProperty;var c=(e,r)=>I(e,"name",{value:r,configurable:true});function n(...e){return twMerge(clsx(e))}c(n,"cn");function Z({columns:e,data:r,rowKey:h,selectable:i=false,selectedKeys:m,onSelectionChange:p,searchable:y=false,searchPlaceholder:b="Search...",totalRows:o,page:u=0,pageSize:P=20,onPageChange:F,onPageSizeChange:D,actions:V,loading:q=false,emptyMessage:d="No data",className:l}){let[a,g]=$.useState(""),[w,K]=$.useState(null),z=$.useMemo(()=>{if(!a)return r;let t=a.toLowerCase();return r.filter(f=>e.some(M=>(M.cell?"":String(f[M.id]??"")).toLowerCase().includes(t)))},[r,a,e]),j=$.useMemo(()=>{if(!w)return z;let{column:t,direction:f}=w;return [...z].sort((M,T)=>{let H=M[t],Q=T[t];if(H==null&&Q==null)return 0;if(H==null)return 1;if(Q==null)return -1;let Y=String(H).localeCompare(String(Q),void 0,{numeric:true});return f==="asc"?Y:-Y})},[z,w]),O=o??j.length,E=Math.max(1,Math.ceil(O/P)),L=F?j:j.slice(u*P,(u+1)*P),C=m??new Set,W=L.length>0&&L.every(t=>C.has(h(t)));function _(){p&&p(W?new Set:new Set(L.map(h)));}c(_,"toggleAll");function A(t){if(!p)return;let f=new Set(C);f.has(t)?f.delete(t):f.add(t),p(f);}c(A,"toggleRow");function G(t){K(f=>f?.column===t?f.direction==="asc"?{column:t,direction:"desc"}:null:{column:t,direction:"asc"});}c(G,"handleSort");let x=V?[...e,{id:"__actions",header:"",width:"auto"}]:e;return jsxs("div",{className:n("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)]",l),children:[(y||i)&&jsxs("div",{className:"flex items-center gap-3 border-b border-[var(--dash-border)] px-4 py-3",children:[y&&jsx("input",{type:"text",placeholder:b,value:a,onChange:t=>g(t.target.value),className:n("h-8 w-64 max-w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]")}),i&&C.size>0&&jsxs("span",{className:"text-xs text-[var(--dash-text-muted)]",children:[C.size," selected"]})]}),jsx("div",{className:"overflow-x-auto",children:jsxs("table",{className:"w-full text-sm",children:[jsx("thead",{children:jsxs("tr",{className:"border-b border-[var(--dash-border)]",children:[i&&jsx("th",{className:"w-10 px-4 py-2.5",children:jsx("input",{type:"checkbox",checked:W,onChange:_,className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),x.map(t=>jsx("th",{style:t.width?{width:t.width}:void 0,className:n("px-4 py-2.5 text-[var(--dash-text-dim)] font-medium",t.align==="center"&&"text-center",t.align==="right"&&"text-right",!t.align&&"text-left",t.sortable&&"cursor-pointer select-none hover:text-[var(--dash-text-muted)]"),onClick:t.sortable?()=>G(t.id):void 0,children:jsxs("span",{className:"inline-flex items-center gap-1",children:[t.header,t.sortable&&w?.column===t.id&&jsx("span",{className:"text-[10px]",children:w.direction==="asc"?"\u2191":"\u2193"})]})},t.id))]})}),jsx("tbody",{children:q?jsx("tr",{children:jsx("td",{colSpan:x.length+(i?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:"Loading..."})}):L.length===0?jsx("tr",{children:jsx("td",{colSpan:x.length+(i?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:d})}):L.map(t=>{let f=h(t),M=C.has(f);return jsxs("tr",{className:n("border-b border-[var(--dash-border)] transition-colors",M?"bg-[var(--dash-surface-active)]":"hover:bg-[var(--dash-surface-hover)]"),children:[i&&jsx("td",{className:"w-10 px-4 py-2.5",children:jsx("input",{type:"checkbox",checked:M,onChange:()=>A(f),className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),e.map(T=>jsx("td",{className:n("px-4 py-2.5",T.align==="center"&&"text-center",T.align==="right"&&"text-right"),children:T.cell?T.cell(t):String(t[T.id]??"")},T.id)),V&&jsx("td",{className:"px-4 py-2.5 text-right",children:V(t)})]},f)})})]})}),E>1&&jsxs("div",{className:"flex items-center justify-between border-t border-[var(--dash-border)] px-4 py-2.5 text-xs text-[var(--dash-text-muted)]",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{children:"Rows per page"}),jsx("select",{value:P,onChange:t=>D?.(Number(t.target.value)),className:"h-7 rounded border border-[var(--dash-border)] bg-[var(--dash-bg)] px-2 text-xs text-[var(--dash-text)] focus:outline-none",children:[10,20,50,100].map(t=>jsx("option",{value:t,children:t},t))})]}),jsxs("div",{className:"flex items-center gap-2",children:[jsxs("span",{children:["Page ",u+1," of ",E]}),jsx("button",{type:"button",disabled:u===0,onClick:()=>F?.(u-1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("button",{type:"button",disabled:u>=E-1,onClick:()=>F?.(u+1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})]})}c(Z,"Table");function U({title:e,fields:r,values:h,onSubmit:i,onCancel:m,submitLabel:p="Save",cancelLabel:y="Cancel",loading:b=false,className:o}){let[u,P]=$.useState(()=>{let d={};for(let l of r)d[l.name]=h?.[l.name]??l.defaultValue??(l.type==="toggle"?false:"");return d}),[F,D]=$.useState({});function V(d,l){P(a=>({...a,[d]:l})),D(a=>{if(!a[d])return a;let g={...a};return delete g[d],g});}c(V,"setValue");async function q(d){d.preventDefault();let l={};for(let a of r){let g=u[a.name];if(a.required&&(g===""||g===null||g===void 0)&&(l[a.name]=`${a.label} is required`),a.validate){let w=a.validate(g);w&&(l[a.name]=w);}}if(Object.keys(l).length>0){D(l);return}await i(u);}return c(q,"handleSubmit"),jsxs("form",{onSubmit:q,className:n("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6",o),children:[e&&jsx("h3",{className:"mb-4 text-lg font-semibold text-[var(--dash-text)]",children:e}),jsx("div",{className:"space-y-4",children:r.map(d=>jsx(re,{field:d,value:u[d.name],error:F[d.name],onChange:l=>V(d.name,l)},d.name))}),jsxs("div",{className:"mt-6 flex items-center gap-3",children:[jsx("button",{type:"submit",disabled:b,className:n("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]","disabled:opacity-50 disabled:cursor-not-allowed"),children:b?"Saving...":p}),m&&jsx("button",{type:"button",onClick:m,disabled:b,className:n("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:y})]})]})}c(U,"Form");var J=n("w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 py-2 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors");function re({field:e,value:r,error:h,onChange:i}){let m=`dash-field-${e.name}`,p=jsxs("label",{htmlFor:m,className:"mb-1 block text-sm font-medium text-[var(--dash-text)]",children:[e.label,e.required&&jsx("span",{className:"ml-0.5 text-[var(--dash-error)]",children:"*"})]}),y=e.description?jsx("p",{className:"mt-1 text-xs text-[var(--dash-text-dim)]",children:e.description}):null,b=h?jsx("p",{className:"mt-1 text-xs text-[var(--dash-error)]",children:h}):null;switch(e.type){case "text":case "email":case "password":case "number":return jsxs("div",{children:[p,jsx("input",{id:m,type:e.type,value:String(r??""),placeholder:e.placeholder,disabled:e.disabled,onChange:o=>i(e.type==="number"?Number(o.target.value):o.target.value),className:n(J,h&&"border-[var(--dash-error)]")}),y,b]});case "textarea":return jsxs("div",{children:[p,jsx("textarea",{id:m,value:String(r??""),placeholder:e.placeholder,disabled:e.disabled,rows:e.rows??3,onChange:o=>i(o.target.value),className:n(J,"resize-y",h&&"border-[var(--dash-error)]")}),y,b]});case "select":case "relation":return jsxs("div",{children:[p,jsxs("select",{id:m,value:String(r??""),disabled:e.disabled,onChange:o=>i(o.target.value),className:n(J,h&&"border-[var(--dash-error)]"),children:[jsx("option",{value:"",children:e.placeholder??"Select..."}),(e.options??[]).map(o=>jsx("option",{value:o.value,children:o.label},o.value))]}),y,b]});case "toggle":return jsxs("div",{className:"flex items-center gap-3",children:[jsx("button",{id:m,type:"button",role:"switch","aria-checked":!!r,disabled:e.disabled,onClick:()=>i(!r),className:n("relative inline-flex h-5 w-9 flex-shrink-0 rounded-full transition-colors","focus:outline-none focus:ring-2 focus:ring-[var(--dash-primary)] focus:ring-offset-2 focus:ring-offset-[var(--dash-surface)]",r?"bg-[var(--dash-primary)]":"bg-[var(--dash-border)]",e.disabled&&"opacity-50 cursor-not-allowed"),children:jsx("span",{className:n("pointer-events-none inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",r?"translate-x-4":"translate-x-0.5","mt-0.5")})}),jsx("label",{htmlFor:m,className:"text-sm text-[var(--dash-text)]",children:e.label}),y,b]});case "json":return jsxs("div",{children:[p,jsx("textarea",{id:m,value:typeof r=="string"?r:JSON.stringify(r,null,2),placeholder:e.placeholder??"{}",disabled:e.disabled,rows:e.rows??6,onChange:o=>{try{i(JSON.parse(o.target.value));}catch{i(o.target.value);}},className:n(J,"font-mono text-xs resize-y",h&&"border-[var(--dash-error)]")}),y,b]});case "file":return jsxs("div",{children:[p,jsx("input",{id:m,type:"file",accept:e.accept,disabled:e.disabled,onChange:o=>{let u=o.target.files?.[0];u&&i(u);},className:n("w-full text-sm text-[var(--dash-text-muted)]","file:mr-3 file:rounded-[var(--dash-radius-sm)] file:border-0 file:bg-[var(--dash-primary)] file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-[var(--dash-primary-text)]","file:cursor-pointer hover:file:bg-[var(--dash-primary-hover)]")}),y,b]});default:return null}}c(re,"FieldRenderer");function we({resourceName:e,resourceNamePlural:r,columns:h,data:i,rowKey:m,fields:p,rowToValues:y,onCreate:b,onUpdate:o,onDelete:u,canCreate:P=true,canEdit:F=true,canDelete:D=true,tableProps:V,loading:q=false,className:d}){let l=r??`${e}s`,[a,g]=$.useState("list"),[w,K]=$.useState(null),[z,j]=$.useState({}),[O,E]=$.useState(null),[L,C]=$.useState(false);function W(x){let t=m(x);K(t),j(y?y(x):x),g("edit");}c(W,"handleEdit");function _(x){E(m(x));}c(_,"handleDeleteConfirm");async function A(){if(!(!O||!u)){C(true);try{await u(O);}finally{C(false),E(null);}}}c(A,"confirmDelete");function G(x){return jsxs("div",{className:"flex items-center justify-end gap-1",children:[F&&o&&jsx("button",{type:"button",onClick:()=>W(x),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-text-muted)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors",children:"Edit"}),D&&u&&jsx("button",{type:"button",onClick:()=>_(x),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-error)] hover:bg-[var(--dash-error-dim)] transition-colors",children:"Delete"})]})}return c(G,"actionsRenderer"),a==="list"?jsxs("div",{className:n("space-y-4",d),children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("h2",{className:"text-xl font-semibold text-[var(--dash-text)]",children:l}),P&&b&&jsxs("button",{type:"button",onClick:()=>{K(null),j({}),g("create");},className:n("rounded-[var(--dash-radius)] px-3 py-1.5 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]"),children:["Create ",e]})]}),jsx(Z,{columns:h,data:i,rowKey:m,actions:F||D?G:void 0,loading:q,searchable:true,emptyMessage:`No ${l.toLowerCase()} found`,...V}),O!==null&&jsx(ae,{resourceName:e,loading:L,onConfirm:A,onCancel:()=>E(null)})]}):jsxs("div",{className:n("space-y-4",d),children:[jsxs("button",{type:"button",onClick:()=>g("list"),className:"inline-flex items-center gap-1 text-sm text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),"Back to ",l]}),jsx(U,{title:a==="create"?`Create ${e}`:`Edit ${e}`,fields:p,values:a==="edit"?z:void 0,loading:L,submitLabel:a==="create"?"Create":"Save changes",onCancel:()=>g("list"),onSubmit:async x=>{C(true);try{a==="create"&&b?await b(x):a==="edit"&&w&&o&&await o(w,x),g("list");}finally{C(false);}}})]})}c(we,"Crud");function ae({resourceName:e,loading:r,onConfirm:h,onCancel:i}){return jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",children:jsxs("div",{className:"w-full max-w-sm rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6 shadow-lg",children:[jsxs("h3",{className:"text-lg font-semibold text-[var(--dash-text)]",children:["Delete ",e,"?"]}),jsxs("p",{className:"mt-2 text-sm text-[var(--dash-text-muted)]",children:["This action cannot be undone. The ",e.toLowerCase()," will be permanently removed."]}),jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[jsx("button",{type:"button",onClick:i,disabled:r,className:n("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:"Cancel"}),jsx("button",{type:"button",onClick:h,disabled:r,className:n("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-error)] text-white","hover:bg-red-600","disabled:opacity-50 disabled:cursor-not-allowed"),children:r?"Deleting...":"Delete"})]})]})})}c(ae,"DeleteDialog");export{we as Crud};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';var f=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var f__namespace=/*#__PURE__*/_interopNamespace(f);var R=Object.defineProperty;var h=(e,a)=>R(e,"name",{value:a,configurable:true});function i(...e){return tailwindMerge.twMerge(clsx.clsx(e))}h(i,"cn");function J({title:e,fields:a,values:m,onSubmit:u,onCancel:l,submitLabel:b="Save",cancelLabel:p="Cancel",loading:d=false,className:r}){let[g,N]=f__namespace.useState(()=>{let s={};for(let o of a)s[o.name]=m?.[o.name]??o.defaultValue??(o.type==="toggle"?false:"");return s}),[k,y]=f__namespace.useState({});function F(s,o){N(n=>({...n,[s]:o})),y(n=>{if(!n[s])return n;let v={...n};return delete v[s],v});}h(F,"setValue");async function S(s){s.preventDefault();let o={};for(let n of a){let v=g[n.name];if(n.required&&(v===""||v===null||v===void 0)&&(o[n.name]=`${n.label} is required`),n.validate){let w=n.validate(v);w&&(o[n.name]=w);}}if(Object.keys(o).length>0){y(o);return}await u(g);}return h(S,"handleSubmit"),jsxRuntime.jsxs("form",{onSubmit:S,className:i("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6",r),children:[e&&jsxRuntime.jsx("h3",{className:"mb-4 text-lg font-semibold text-[var(--dash-text)]",children:e}),jsxRuntime.jsx("div",{className:"space-y-4",children:a.map(s=>jsxRuntime.jsx(E,{field:s,value:g[s.name],error:k[s.name],onChange:o=>F(s.name,o)},s.name))}),jsxRuntime.jsxs("div",{className:"mt-6 flex items-center gap-3",children:[jsxRuntime.jsx("button",{type:"submit",disabled:d,className:i("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]","disabled:opacity-50 disabled:cursor-not-allowed"),children:d?"Saving...":b}),l&&jsxRuntime.jsx("button",{type:"button",onClick:l,disabled:d,className:i("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:p})]})]})}h(J,"Form");var x=i("w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 py-2 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors");function E({field:e,value:a,error:m,onChange:u}){let l=`dash-field-${e.name}`,b=jsxRuntime.jsxs("label",{htmlFor:l,className:"mb-1 block text-sm font-medium text-[var(--dash-text)]",children:[e.label,e.required&&jsxRuntime.jsx("span",{className:"ml-0.5 text-[var(--dash-error)]",children:"*"})]}),p=e.description?jsxRuntime.jsx("p",{className:"mt-1 text-xs text-[var(--dash-text-dim)]",children:e.description}):null,d=m?jsxRuntime.jsx("p",{className:"mt-1 text-xs text-[var(--dash-error)]",children:m}):null;switch(e.type){case "text":case "email":case "password":case "number":return jsxRuntime.jsxs("div",{children:[b,jsxRuntime.jsx("input",{id:l,type:e.type,value:String(a??""),placeholder:e.placeholder,disabled:e.disabled,onChange:r=>u(e.type==="number"?Number(r.target.value):r.target.value),className:i(x,m&&"border-[var(--dash-error)]")}),p,d]});case "textarea":return jsxRuntime.jsxs("div",{children:[b,jsxRuntime.jsx("textarea",{id:l,value:String(a??""),placeholder:e.placeholder,disabled:e.disabled,rows:e.rows??3,onChange:r=>u(r.target.value),className:i(x,"resize-y",m&&"border-[var(--dash-error)]")}),p,d]});case "select":case "relation":return jsxRuntime.jsxs("div",{children:[b,jsxRuntime.jsxs("select",{id:l,value:String(a??""),disabled:e.disabled,onChange:r=>u(r.target.value),className:i(x,m&&"border-[var(--dash-error)]"),children:[jsxRuntime.jsx("option",{value:"",children:e.placeholder??"Select..."}),(e.options??[]).map(r=>jsxRuntime.jsx("option",{value:r.value,children:r.label},r.value))]}),p,d]});case "toggle":return jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("button",{id:l,type:"button",role:"switch","aria-checked":!!a,disabled:e.disabled,onClick:()=>u(!a),className:i("relative inline-flex h-5 w-9 flex-shrink-0 rounded-full transition-colors","focus:outline-none focus:ring-2 focus:ring-[var(--dash-primary)] focus:ring-offset-2 focus:ring-offset-[var(--dash-surface)]",a?"bg-[var(--dash-primary)]":"bg-[var(--dash-border)]",e.disabled&&"opacity-50 cursor-not-allowed"),children:jsxRuntime.jsx("span",{className:i("pointer-events-none inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",a?"translate-x-4":"translate-x-0.5","mt-0.5")})}),jsxRuntime.jsx("label",{htmlFor:l,className:"text-sm text-[var(--dash-text)]",children:e.label}),p,d]});case "json":return jsxRuntime.jsxs("div",{children:[b,jsxRuntime.jsx("textarea",{id:l,value:typeof a=="string"?a:JSON.stringify(a,null,2),placeholder:e.placeholder??"{}",disabled:e.disabled,rows:e.rows??6,onChange:r=>{try{u(JSON.parse(r.target.value));}catch{u(r.target.value);}},className:i(x,"font-mono text-xs resize-y",m&&"border-[var(--dash-error)]")}),p,d]});case "file":return jsxRuntime.jsxs("div",{children:[b,jsxRuntime.jsx("input",{id:l,type:"file",accept:e.accept,disabled:e.disabled,onChange:r=>{let g=r.target.files?.[0];g&&u(g);},className:i("w-full text-sm text-[var(--dash-text-muted)]","file:mr-3 file:rounded-[var(--dash-radius-sm)] file:border-0 file:bg-[var(--dash-primary)] file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-[var(--dash-primary-text)]","file:cursor-pointer hover:file:bg-[var(--dash-primary-hover)]")}),p,d]});default:return null}}h(E,"FieldRenderer");exports.Form=J;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import*as f from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsxs,jsx}from'react/jsx-runtime';var R=Object.defineProperty;var h=(e,a)=>R(e,"name",{value:a,configurable:true});function i(...e){return twMerge(clsx(e))}h(i,"cn");function J({title:e,fields:a,values:m,onSubmit:u,onCancel:l,submitLabel:b="Save",cancelLabel:p="Cancel",loading:d=false,className:r}){let[g,N]=f.useState(()=>{let s={};for(let o of a)s[o.name]=m?.[o.name]??o.defaultValue??(o.type==="toggle"?false:"");return s}),[k,y]=f.useState({});function F(s,o){N(n=>({...n,[s]:o})),y(n=>{if(!n[s])return n;let v={...n};return delete v[s],v});}h(F,"setValue");async function S(s){s.preventDefault();let o={};for(let n of a){let v=g[n.name];if(n.required&&(v===""||v===null||v===void 0)&&(o[n.name]=`${n.label} is required`),n.validate){let w=n.validate(v);w&&(o[n.name]=w);}}if(Object.keys(o).length>0){y(o);return}await u(g);}return h(S,"handleSubmit"),jsxs("form",{onSubmit:S,className:i("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6",r),children:[e&&jsx("h3",{className:"mb-4 text-lg font-semibold text-[var(--dash-text)]",children:e}),jsx("div",{className:"space-y-4",children:a.map(s=>jsx(E,{field:s,value:g[s.name],error:k[s.name],onChange:o=>F(s.name,o)},s.name))}),jsxs("div",{className:"mt-6 flex items-center gap-3",children:[jsx("button",{type:"submit",disabled:d,className:i("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]","disabled:opacity-50 disabled:cursor-not-allowed"),children:d?"Saving...":b}),l&&jsx("button",{type:"button",onClick:l,disabled:d,className:i("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:p})]})]})}h(J,"Form");var x=i("w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 py-2 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors");function E({field:e,value:a,error:m,onChange:u}){let l=`dash-field-${e.name}`,b=jsxs("label",{htmlFor:l,className:"mb-1 block text-sm font-medium text-[var(--dash-text)]",children:[e.label,e.required&&jsx("span",{className:"ml-0.5 text-[var(--dash-error)]",children:"*"})]}),p=e.description?jsx("p",{className:"mt-1 text-xs text-[var(--dash-text-dim)]",children:e.description}):null,d=m?jsx("p",{className:"mt-1 text-xs text-[var(--dash-error)]",children:m}):null;switch(e.type){case "text":case "email":case "password":case "number":return jsxs("div",{children:[b,jsx("input",{id:l,type:e.type,value:String(a??""),placeholder:e.placeholder,disabled:e.disabled,onChange:r=>u(e.type==="number"?Number(r.target.value):r.target.value),className:i(x,m&&"border-[var(--dash-error)]")}),p,d]});case "textarea":return jsxs("div",{children:[b,jsx("textarea",{id:l,value:String(a??""),placeholder:e.placeholder,disabled:e.disabled,rows:e.rows??3,onChange:r=>u(r.target.value),className:i(x,"resize-y",m&&"border-[var(--dash-error)]")}),p,d]});case "select":case "relation":return jsxs("div",{children:[b,jsxs("select",{id:l,value:String(a??""),disabled:e.disabled,onChange:r=>u(r.target.value),className:i(x,m&&"border-[var(--dash-error)]"),children:[jsx("option",{value:"",children:e.placeholder??"Select..."}),(e.options??[]).map(r=>jsx("option",{value:r.value,children:r.label},r.value))]}),p,d]});case "toggle":return jsxs("div",{className:"flex items-center gap-3",children:[jsx("button",{id:l,type:"button",role:"switch","aria-checked":!!a,disabled:e.disabled,onClick:()=>u(!a),className:i("relative inline-flex h-5 w-9 flex-shrink-0 rounded-full transition-colors","focus:outline-none focus:ring-2 focus:ring-[var(--dash-primary)] focus:ring-offset-2 focus:ring-offset-[var(--dash-surface)]",a?"bg-[var(--dash-primary)]":"bg-[var(--dash-border)]",e.disabled&&"opacity-50 cursor-not-allowed"),children:jsx("span",{className:i("pointer-events-none inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",a?"translate-x-4":"translate-x-0.5","mt-0.5")})}),jsx("label",{htmlFor:l,className:"text-sm text-[var(--dash-text)]",children:e.label}),p,d]});case "json":return jsxs("div",{children:[b,jsx("textarea",{id:l,value:typeof a=="string"?a:JSON.stringify(a,null,2),placeholder:e.placeholder??"{}",disabled:e.disabled,rows:e.rows??6,onChange:r=>{try{u(JSON.parse(r.target.value));}catch{u(r.target.value);}},className:i(x,"font-mono text-xs resize-y",m&&"border-[var(--dash-error)]")}),p,d]});case "file":return jsxs("div",{children:[b,jsx("input",{id:l,type:"file",accept:e.accept,disabled:e.disabled,onChange:r=>{let g=r.target.files?.[0];g&&u(g);},className:i("w-full text-sm text-[var(--dash-text-muted)]","file:mr-3 file:rounded-[var(--dash-radius-sm)] file:border-0 file:bg-[var(--dash-primary)] file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-[var(--dash-primary-text)]","file:cursor-pointer hover:file:bg-[var(--dash-primary-hover)]")}),p,d]});default:return null}}h(E,"FieldRenderer");export{J as Form};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
'use strict';var r=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var r__namespace=/*#__PURE__*/_interopNamespace(r);var k=Object.defineProperty;var o=(a,n)=>k(a,"name",{value:n,configurable:true});function v(...a){return tailwindMerge.twMerge(clsx.clsx(a))}o(v,"cn");function
|
|
2
|
+
'use strict';var r=require('react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var r__namespace=/*#__PURE__*/_interopNamespace(r);var k=Object.defineProperty;var o=(a,n)=>k(a,"name",{value:n,configurable:true});function v(...a){return tailwindMerge.twMerge(clsx.clsx(a))}o(v,"cn");function W({breadcrumbs:a,searchPlaceholder:n="Search...",onSearch:u,avatarUrl:i,userName:l,userDropdown:m,onToggleTheme:p,theme:f="dark",actions:g,className:b}){let[c,x]=r__namespace.useState(false),h=r__namespace.useRef(null);return r__namespace.useEffect(()=>{if(!c)return;function t(d){h.current&&!h.current.contains(d.target)&&x(false);}return o(t,"handleClick"),document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[c]),jsxRuntime.jsxs("div",{className:v("flex h-[var(--dash-header-height)] items-center gap-4 px-4","bg-[var(--dash-surface)] text-[var(--dash-text)]",b),children:[a&&a.length>0&&jsxRuntime.jsx("nav",{className:"flex items-center gap-1 text-sm","aria-label":"Breadcrumb",children:a.map((t,d)=>jsxRuntime.jsxs(r__namespace.Fragment,{children:[d>0&&jsxRuntime.jsx("span",{className:"text-[var(--dash-text-dim)]",children:"/"}),t.href?jsxRuntime.jsx("a",{href:t.href,className:"text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:t.label}):jsxRuntime.jsx("span",{className:"text-[var(--dash-text)]",children:t.label})]},d))}),jsxRuntime.jsx("div",{className:"flex-1"}),u&&jsxRuntime.jsxs("div",{className:"relative hidden sm:block",children:[jsxRuntime.jsxs("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-[var(--dash-text-dim)]",width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[jsxRuntime.jsx("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M11 11l3 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),jsxRuntime.jsx("input",{type:"text",placeholder:n,onChange:t=>u(t.target.value),className:v("h-8 w-56 rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] pl-8 pr-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","transition-colors")})]}),g,p&&jsxRuntime.jsx("button",{type:"button",onClick:p,className:"rounded-[var(--dash-radius-sm)] p-1.5 text-[var(--dash-text-dim)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors","aria-label":`Switch to ${f==="dark"?"light":"dark"} mode`,children:f==="dark"?jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[jsxRuntime.jsx("circle",{cx:"8",cy:"8",r:"3.5",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M8 1v2M8 13v2M1 8h2M13 8h2M3.05 3.05l1.41 1.41M11.54 11.54l1.41 1.41M3.05 12.95l1.41-1.41M11.54 4.46l1.41-1.41",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M14 9.5A6.5 6.5 0 016.5 2 5.5 5.5 0 1014 9.5z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(i||l)&&jsxRuntime.jsxs("div",{className:"relative",ref:h,children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>x(t=>!t),className:"flex items-center gap-2 rounded-[var(--dash-radius-sm)] p-1 hover:bg-[var(--dash-surface-hover)] transition-colors",children:i?jsxRuntime.jsx("img",{src:i,alt:l??"User",className:"h-7 w-7 rounded-full object-cover"}):jsxRuntime.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-[var(--dash-primary)] text-xs font-medium text-[var(--dash-primary-text)]",children:(l??"?")[0].toUpperCase()})}),c&&m&&jsxRuntime.jsx("div",{className:"absolute right-0 top-full z-50 mt-1 min-w-48 rounded-[var(--dash-radius)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-1 shadow-lg",children:m})]})]})}o(W,"Header");exports.Header=W;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import*as r from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsxs,jsx}from'react/jsx-runtime';var k=Object.defineProperty;var o=(a,n)=>k(a,"name",{value:n,configurable:true});function v(...a){return twMerge(clsx(a))}o(v,"cn");function
|
|
2
|
+
import*as r from'react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsxs,jsx}from'react/jsx-runtime';var k=Object.defineProperty;var o=(a,n)=>k(a,"name",{value:n,configurable:true});function v(...a){return twMerge(clsx(a))}o(v,"cn");function W({breadcrumbs:a,searchPlaceholder:n="Search...",onSearch:u,avatarUrl:i,userName:l,userDropdown:m,onToggleTheme:p,theme:f="dark",actions:g,className:b}){let[c,x]=r.useState(false),h=r.useRef(null);return r.useEffect(()=>{if(!c)return;function t(d){h.current&&!h.current.contains(d.target)&&x(false);}return o(t,"handleClick"),document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[c]),jsxs("div",{className:v("flex h-[var(--dash-header-height)] items-center gap-4 px-4","bg-[var(--dash-surface)] text-[var(--dash-text)]",b),children:[a&&a.length>0&&jsx("nav",{className:"flex items-center gap-1 text-sm","aria-label":"Breadcrumb",children:a.map((t,d)=>jsxs(r.Fragment,{children:[d>0&&jsx("span",{className:"text-[var(--dash-text-dim)]",children:"/"}),t.href?jsx("a",{href:t.href,className:"text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:t.label}):jsx("span",{className:"text-[var(--dash-text)]",children:t.label})]},d))}),jsx("div",{className:"flex-1"}),u&&jsxs("div",{className:"relative hidden sm:block",children:[jsxs("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-[var(--dash-text-dim)]",width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[jsx("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M11 11l3 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),jsx("input",{type:"text",placeholder:n,onChange:t=>u(t.target.value),className:v("h-8 w-56 rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] pl-8 pr-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","transition-colors")})]}),g,p&&jsx("button",{type:"button",onClick:p,className:"rounded-[var(--dash-radius-sm)] p-1.5 text-[var(--dash-text-dim)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors","aria-label":`Switch to ${f==="dark"?"light":"dark"} mode`,children:f==="dark"?jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[jsx("circle",{cx:"8",cy:"8",r:"3.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M8 1v2M8 13v2M1 8h2M13 8h2M3.05 3.05l1.41 1.41M11.54 11.54l1.41 1.41M3.05 12.95l1.41-1.41M11.54 4.46l1.41-1.41",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M14 9.5A6.5 6.5 0 016.5 2 5.5 5.5 0 1014 9.5z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(i||l)&&jsxs("div",{className:"relative",ref:h,children:[jsx("button",{type:"button",onClick:()=>x(t=>!t),className:"flex items-center gap-2 rounded-[var(--dash-radius-sm)] p-1 hover:bg-[var(--dash-surface-hover)] transition-colors",children:i?jsx("img",{src:i,alt:l??"User",className:"h-7 w-7 rounded-full object-cover"}):jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-[var(--dash-primary)] text-xs font-medium text-[var(--dash-primary-text)]",children:(l??"?")[0].toUpperCase()})}),c&&m&&jsx("div",{className:"absolute right-0 top-full z-50 mt-1 min-w-48 rounded-[var(--dash-radius)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-1 shadow-lg",children:m})]})]})}o(W,"Header");export{W as Header};
|
package/dist/dash/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime'),q=require('react');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var q__namespace=/*#__PURE__*/_interopNamespace(q);var ie=Object.defineProperty;var i=(e,a)=>ie(e,"name",{value:a,configurable:true});function r(...e){return tailwindMerge.twMerge(clsx.clsx(e))}i(r,"cn");function ce({sidebar:e,header:a,children:l,sidebarCollapsed:s=false,onSidebarCollapse:n,className:c}){return jsxRuntime.jsxs("div",{className:r("flex h-screen overflow-hidden","bg-[var(--dash-bg)] text-[var(--dash-text)]",c),children:[jsxRuntime.jsx("aside",{className:r("flex-shrink-0 overflow-y-auto overflow-x-hidden transition-[width] duration-200","border-r border-[var(--dash-border)] bg-[var(--dash-surface)]",s?"w-[var(--dash-sidebar-collapsed-width)]":"w-[var(--dash-sidebar-width)]"),children:e}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[a&&jsxRuntime.jsx("header",{className:"flex-shrink-0 border-b border-[var(--dash-border)] bg-[var(--dash-surface)]",children:a}),jsxRuntime.jsx("main",{className:"flex-1 overflow-y-auto p-6",children:l})]}),!s&&jsxRuntime.jsx("div",{className:"fixed inset-0 z-40 bg-black/60 lg:hidden",onClick:()=>n?.(true)})]})}i(ce,"DashLayout");function ue({size:e=28}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{d:"M4 4h4v6h8V4h4v16h-4v-6H8v6H4V4z",fill:"currentColor"})})}i(ue,"HanzoMark");function he({logo:e,groups:a,userMenu:l,collapsed:s=false,onToggleCollapse:n,onNavigate:c,className:o}){return jsxRuntime.jsxs("nav",{className:r("flex h-full flex-col","bg-[var(--dash-surface)] text-[var(--dash-text)]",o),children:[jsxRuntime.jsxs("div",{className:r("flex h-[var(--dash-header-height)] items-center border-b border-[var(--dash-border)]",s?"justify-center px-2":"px-4"),children:[e??jsxRuntime.jsx(ue,{}),!s&&n&&jsxRuntime.jsx("button",{type:"button",onClick:n,className:"ml-auto rounded p-1 text-[var(--dash-text-dim)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]","aria-label":"Collapse sidebar",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),s&&n&&jsxRuntime.jsx("button",{type:"button",onClick:n,className:"absolute -right-3 top-4 z-50 hidden rounded-full border border-[var(--dash-border)] bg-[var(--dash-surface)] p-1 text-[var(--dash-text-dim)] hover:text-[var(--dash-text)] lg:flex","aria-label":"Expand sidebar",children:jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto py-2",children:a.map((m,d)=>jsxRuntime.jsx(me,{group:m,collapsed:s,onNavigate:c},d))}),l&&jsxRuntime.jsx("div",{className:"border-t border-[var(--dash-border)] p-2",children:l})]})}i(he,"DashSidebar");function me({group:e,collapsed:a,onNavigate:l}){let[s,n]=q__namespace.useState(e.defaultOpen!==false),c=e.collapsible!==false&&!!e.title;return jsxRuntime.jsxs("div",{className:"mb-1",children:[e.title&&!a&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>c&&n(o=>!o),className:r("flex w-full items-center px-4 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-[var(--dash-text-dim)]",c&&"cursor-pointer hover:text-[var(--dash-text-muted)]"),children:[jsxRuntime.jsx("span",{className:"flex-1 text-left",children:e.title}),c&&jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",className:r("transition-transform",s?"rotate-0":"-rotate-90"),children:jsxRuntime.jsx("path",{d:"M4 6l4 4 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),(s||a)&&jsxRuntime.jsx("ul",{className:"space-y-0.5 px-2",children:e.items.map(o=>jsxRuntime.jsx("li",{children:jsxRuntime.jsxs("button",{type:"button",onClick:()=>l?.(o.href),title:a?o.label:void 0,className:r("flex w-full items-center gap-2 rounded-[var(--dash-radius-sm)] px-2 py-1.5 text-sm transition-colors",o.active?"bg-[var(--dash-primary)] text-[var(--dash-primary-text)]":"text-[var(--dash-text-muted)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]",a&&"justify-center px-0"),children:[o.icon&&jsxRuntime.jsx("span",{className:"flex h-5 w-5 items-center justify-center flex-shrink-0",children:o.icon}),!a&&jsxRuntime.jsx("span",{className:"flex-1 truncate text-left",children:o.label}),!a&&o.badge!==void 0&&jsxRuntime.jsx("span",{className:"ml-auto rounded-full bg-[var(--dash-primary)] px-1.5 py-0.5 text-[10px] font-medium text-[var(--dash-primary-text)]",children:o.badge})]})},o.href))})]})}i(me,"SidebarGroup");function ve({breadcrumbs:e,searchPlaceholder:a="Search...",onSearch:l,avatarUrl:s,userName:n,userDropdown:c,onToggleTheme:o,theme:m="dark",actions:d,className:v}){let[D,C]=q__namespace.useState(false),R=q__namespace.useRef(null);return q__namespace.useEffect(()=>{if(!D)return;function b(P){R.current&&!R.current.contains(P.target)&&C(false);}return i(b,"handleClick"),document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[D]),jsxRuntime.jsxs("div",{className:r("flex h-[var(--dash-header-height)] items-center gap-4 px-4","bg-[var(--dash-surface)] text-[var(--dash-text)]",v),children:[e&&e.length>0&&jsxRuntime.jsx("nav",{className:"flex items-center gap-1 text-sm","aria-label":"Breadcrumb",children:e.map((b,P)=>jsxRuntime.jsxs(q__namespace.Fragment,{children:[P>0&&jsxRuntime.jsx("span",{className:"text-[var(--dash-text-dim)]",children:"/"}),b.href?jsxRuntime.jsx("a",{href:b.href,className:"text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:b.label}):jsxRuntime.jsx("span",{className:"text-[var(--dash-text)]",children:b.label})]},P))}),jsxRuntime.jsx("div",{className:"flex-1"}),l&&jsxRuntime.jsxs("div",{className:"relative hidden sm:block",children:[jsxRuntime.jsxs("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-[var(--dash-text-dim)]",width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[jsxRuntime.jsx("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M11 11l3 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),jsxRuntime.jsx("input",{type:"text",placeholder:a,onChange:b=>l(b.target.value),className:r("h-8 w-56 rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] pl-8 pr-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","transition-colors")})]}),d,o&&jsxRuntime.jsx("button",{type:"button",onClick:o,className:"rounded-[var(--dash-radius-sm)] p-1.5 text-[var(--dash-text-dim)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors","aria-label":`Switch to ${m==="dark"?"light":"dark"} mode`,children:m==="dark"?jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[jsxRuntime.jsx("circle",{cx:"8",cy:"8",r:"3.5",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M8 1v2M8 13v2M1 8h2M13 8h2M3.05 3.05l1.41 1.41M11.54 11.54l1.41 1.41M3.05 12.95l1.41-1.41M11.54 4.46l1.41-1.41",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M14 9.5A6.5 6.5 0 016.5 2 5.5 5.5 0 1014 9.5z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(s||n)&&jsxRuntime.jsxs("div",{className:"relative",ref:R,children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>C(b=>!b),className:"flex items-center gap-2 rounded-[var(--dash-radius-sm)] p-1 hover:bg-[var(--dash-surface-hover)] transition-colors",children:s?jsxRuntime.jsx("img",{src:s,alt:n??"User",className:"h-7 w-7 rounded-full object-cover"}):jsxRuntime.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-[var(--dash-primary)] text-xs font-medium text-[var(--dash-primary-text)]",children:(n??"?")[0].toUpperCase()})}),D&&c&&jsxRuntime.jsx("div",{className:"absolute right-0 top-full z-50 mt-1 min-w-48 rounded-[var(--dash-radius)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-1 shadow-lg",children:c})]})]})}i(ve,"DashHeader");function te({columns:e,data:a,rowKey:l,selectable:s=false,selectedKeys:n,onSelectionChange:c,searchable:o=false,searchPlaceholder:m="Search...",totalRows:d,page:v=0,pageSize:D=20,onPageChange:C,onPageSizeChange:R,actions:b,loading:P=false,emptyMessage:f="No data",className:x}){let[u,w]=q__namespace.useState(""),[S,A]=q__namespace.useState(null),G=q__namespace.useMemo(()=>{if(!u)return a;let t=u.toLowerCase();return a.filter(k=>e.some(O=>(O.cell?"":String(k[O.id]??"")).toLowerCase().includes(t)))},[a,u,e]),W=q__namespace.useMemo(()=>{if(!S)return G;let{column:t,direction:k}=S;return [...G].sort((O,E)=>{let Z=O[t],ee=E[t];if(Z==null&&ee==null)return 0;if(Z==null)return 1;if(ee==null)return -1;let se=String(Z).localeCompare(String(ee),void 0,{numeric:true});return k==="asc"?se:-se})},[G,S]),I=d??W.length,z=Math.max(1,Math.ceil(I/D)),j=C?W:W.slice(v*D,(v+1)*D),M=n??new Set,J=j.length>0&&j.every(t=>M.has(l(t)));function U(){c&&c(J?new Set:new Set(j.map(l)));}i(U,"toggleAll");function X(t){if(!c)return;let k=new Set(M);k.has(t)?k.delete(t):k.add(t),c(k);}i(X,"toggleRow");function Y(t){A(k=>k?.column===t?k.direction==="asc"?{column:t,direction:"desc"}:null:{column:t,direction:"asc"});}i(Y,"handleSort");let N=b?[...e,{id:"__actions",header:"",width:"auto"}]:e;return jsxRuntime.jsxs("div",{className:r("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)]",x),children:[(o||s)&&jsxRuntime.jsxs("div",{className:"flex items-center gap-3 border-b border-[var(--dash-border)] px-4 py-3",children:[o&&jsxRuntime.jsx("input",{type:"text",placeholder:m,value:u,onChange:t=>w(t.target.value),className:r("h-8 w-64 max-w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]")}),s&&M.size>0&&jsxRuntime.jsxs("span",{className:"text-xs text-[var(--dash-text-muted)]",children:[M.size," selected"]})]}),jsxRuntime.jsx("div",{className:"overflow-x-auto",children:jsxRuntime.jsxs("table",{className:"w-full text-sm",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"border-b border-[var(--dash-border)]",children:[s&&jsxRuntime.jsx("th",{className:"w-10 px-4 py-2.5",children:jsxRuntime.jsx("input",{type:"checkbox",checked:J,onChange:U,className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),N.map(t=>jsxRuntime.jsx("th",{style:t.width?{width:t.width}:void 0,className:r("px-4 py-2.5 text-[var(--dash-text-dim)] font-medium",t.align==="center"&&"text-center",t.align==="right"&&"text-right",!t.align&&"text-left",t.sortable&&"cursor-pointer select-none hover:text-[var(--dash-text-muted)]"),onClick:t.sortable?()=>Y(t.id):void 0,children:jsxRuntime.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.header,t.sortable&&S?.column===t.id&&jsxRuntime.jsx("span",{className:"text-[10px]",children:S.direction==="asc"?"\u2191":"\u2193"})]})},t.id))]})}),jsxRuntime.jsx("tbody",{children:P?jsxRuntime.jsx("tr",{children:jsxRuntime.jsx("td",{colSpan:N.length+(s?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:"Loading..."})}):j.length===0?jsxRuntime.jsx("tr",{children:jsxRuntime.jsx("td",{colSpan:N.length+(s?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:f})}):j.map(t=>{let k=l(t),O=M.has(k);return jsxRuntime.jsxs("tr",{className:r("border-b border-[var(--dash-border)] transition-colors",O?"bg-[var(--dash-surface-active)]":"hover:bg-[var(--dash-surface-hover)]"),children:[s&&jsxRuntime.jsx("td",{className:"w-10 px-4 py-2.5",children:jsxRuntime.jsx("input",{type:"checkbox",checked:O,onChange:()=>X(k),className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),e.map(E=>jsxRuntime.jsx("td",{className:r("px-4 py-2.5",E.align==="center"&&"text-center",E.align==="right"&&"text-right"),children:E.cell?E.cell(t):String(t[E.id]??"")},E.id)),b&&jsxRuntime.jsx("td",{className:"px-4 py-2.5 text-right",children:b(t)})]},k)})})]})}),z>1&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-[var(--dash-border)] px-4 py-2.5 text-xs text-[var(--dash-text-muted)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{children:"Rows per page"}),jsxRuntime.jsx("select",{value:D,onChange:t=>R?.(Number(t.target.value)),className:"h-7 rounded border border-[var(--dash-border)] bg-[var(--dash-bg)] px-2 text-xs text-[var(--dash-text)] focus:outline-none",children:[10,20,50,100].map(t=>jsxRuntime.jsx("option",{value:t,children:t},t))})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("span",{children:["Page ",v+1," of ",z]}),jsxRuntime.jsx("button",{type:"button",disabled:v===0,onClick:()=>C?.(v-1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsxRuntime.jsx("button",{type:"button",disabled:v>=z-1,onClick:()=>C?.(v+1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})]})}i(te,"DashDataTable");function re({title:e,fields:a,values:l,onSubmit:s,onCancel:n,submitLabel:c="Save",cancelLabel:o="Cancel",loading:m=false,className:d}){let[v,D]=q__namespace.useState(()=>{let f={};for(let x of a)f[x.name]=l?.[x.name]??x.defaultValue??(x.type==="toggle"?false:"");return f}),[C,R]=q__namespace.useState({});function b(f,x){D(u=>({...u,[f]:x})),R(u=>{if(!u[f])return u;let w={...u};return delete w[f],w});}i(b,"setValue");async function P(f){f.preventDefault();let x={};for(let u of a){let w=v[u.name];if(u.required&&(w===""||w===null||w===void 0)&&(x[u.name]=`${u.label} is required`),u.validate){let S=u.validate(w);S&&(x[u.name]=S);}}if(Object.keys(x).length>0){R(x);return}await s(v);}return i(P,"handleSubmit"),jsxRuntime.jsxs("form",{onSubmit:P,className:r("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6",d),children:[e&&jsxRuntime.jsx("h3",{className:"mb-4 text-lg font-semibold text-[var(--dash-text)]",children:e}),jsxRuntime.jsx("div",{className:"space-y-4",children:a.map(f=>jsxRuntime.jsx(pe,{field:f,value:v[f.name],error:C[f.name],onChange:x=>b(f.name,x)},f.name))}),jsxRuntime.jsxs("div",{className:"mt-6 flex items-center gap-3",children:[jsxRuntime.jsx("button",{type:"submit",disabled:m,className:r("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]","disabled:opacity-50 disabled:cursor-not-allowed"),children:m?"Saving...":c}),n&&jsxRuntime.jsx("button",{type:"button",onClick:n,disabled:m,className:r("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:o})]})]})}i(re,"DashForm");var Q=r("w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 py-2 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors");function pe({field:e,value:a,error:l,onChange:s}){let n=`dash-field-${e.name}`,c=jsxRuntime.jsxs("label",{htmlFor:n,className:"mb-1 block text-sm font-medium text-[var(--dash-text)]",children:[e.label,e.required&&jsxRuntime.jsx("span",{className:"ml-0.5 text-[var(--dash-error)]",children:"*"})]}),o=e.description?jsxRuntime.jsx("p",{className:"mt-1 text-xs text-[var(--dash-text-dim)]",children:e.description}):null,m=l?jsxRuntime.jsx("p",{className:"mt-1 text-xs text-[var(--dash-error)]",children:l}):null;switch(e.type){case "text":case "email":case "password":case "number":return jsxRuntime.jsxs("div",{children:[c,jsxRuntime.jsx("input",{id:n,type:e.type,value:String(a??""),placeholder:e.placeholder,disabled:e.disabled,onChange:d=>s(e.type==="number"?Number(d.target.value):d.target.value),className:r(Q,l&&"border-[var(--dash-error)]")}),o,m]});case "textarea":return jsxRuntime.jsxs("div",{children:[c,jsxRuntime.jsx("textarea",{id:n,value:String(a??""),placeholder:e.placeholder,disabled:e.disabled,rows:e.rows??3,onChange:d=>s(d.target.value),className:r(Q,"resize-y",l&&"border-[var(--dash-error)]")}),o,m]});case "select":case "relation":return jsxRuntime.jsxs("div",{children:[c,jsxRuntime.jsxs("select",{id:n,value:String(a??""),disabled:e.disabled,onChange:d=>s(d.target.value),className:r(Q,l&&"border-[var(--dash-error)]"),children:[jsxRuntime.jsx("option",{value:"",children:e.placeholder??"Select..."}),(e.options??[]).map(d=>jsxRuntime.jsx("option",{value:d.value,children:d.label},d.value))]}),o,m]});case "toggle":return jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("button",{id:n,type:"button",role:"switch","aria-checked":!!a,disabled:e.disabled,onClick:()=>s(!a),className:r("relative inline-flex h-5 w-9 flex-shrink-0 rounded-full transition-colors","focus:outline-none focus:ring-2 focus:ring-[var(--dash-primary)] focus:ring-offset-2 focus:ring-offset-[var(--dash-surface)]",a?"bg-[var(--dash-primary)]":"bg-[var(--dash-border)]",e.disabled&&"opacity-50 cursor-not-allowed"),children:jsxRuntime.jsx("span",{className:r("pointer-events-none inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",a?"translate-x-4":"translate-x-0.5","mt-0.5")})}),jsxRuntime.jsx("label",{htmlFor:n,className:"text-sm text-[var(--dash-text)]",children:e.label}),o,m]});case "json":return jsxRuntime.jsxs("div",{children:[c,jsxRuntime.jsx("textarea",{id:n,value:typeof a=="string"?a:JSON.stringify(a,null,2),placeholder:e.placeholder??"{}",disabled:e.disabled,rows:e.rows??6,onChange:d=>{try{s(JSON.parse(d.target.value));}catch{s(d.target.value);}},className:r(Q,"font-mono text-xs resize-y",l&&"border-[var(--dash-error)]")}),o,m]});case "file":return jsxRuntime.jsxs("div",{children:[c,jsxRuntime.jsx("input",{id:n,type:"file",accept:e.accept,disabled:e.disabled,onChange:d=>{let v=d.target.files?.[0];v&&s(v);},className:r("w-full text-sm text-[var(--dash-text-muted)]","file:mr-3 file:rounded-[var(--dash-radius-sm)] file:border-0 file:bg-[var(--dash-primary)] file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-[var(--dash-primary-text)]","file:cursor-pointer hover:file:bg-[var(--dash-primary-hover)]")}),o,m]});default:return null}}i(pe,"FieldRenderer");function be({resourceName:e,resourceNamePlural:a,columns:l,data:s,rowKey:n,fields:c,rowToValues:o,onCreate:m,onUpdate:d,onDelete:v,canCreate:D=true,canEdit:C=true,canDelete:R=true,tableProps:b,loading:P=false,className:f}){let x=a??`${e}s`,[u,w]=q__namespace.useState("list"),[S,A]=q__namespace.useState(null),[G,W]=q__namespace.useState({}),[I,z]=q__namespace.useState(null),[j,M]=q__namespace.useState(false);function J(N){let t=n(N);A(t),W(o?o(N):N),w("edit");}i(J,"handleEdit");function U(N){z(n(N));}i(U,"handleDeleteConfirm");async function X(){if(!(!I||!v)){M(true);try{await v(I);}finally{M(false),z(null);}}}i(X,"confirmDelete");function Y(N){return jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1",children:[C&&d&&jsxRuntime.jsx("button",{type:"button",onClick:()=>J(N),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-text-muted)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors",children:"Edit"}),R&&v&&jsxRuntime.jsx("button",{type:"button",onClick:()=>U(N),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-error)] hover:bg-[var(--dash-error-dim)] transition-colors",children:"Delete"})]})}return i(Y,"actionsRenderer"),u==="list"?jsxRuntime.jsxs("div",{className:r("space-y-4",f),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("h2",{className:"text-xl font-semibold text-[var(--dash-text)]",children:x}),D&&m&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{A(null),W({}),w("create");},className:r("rounded-[var(--dash-radius)] px-3 py-1.5 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]"),children:["Create ",e]})]}),jsxRuntime.jsx(te,{columns:l,data:s,rowKey:n,actions:C||R?Y:void 0,loading:P,searchable:true,emptyMessage:`No ${x.toLowerCase()} found`,...b}),I!==null&&jsxRuntime.jsx(fe,{resourceName:e,loading:j,onConfirm:X,onCancel:()=>z(null)})]}):jsxRuntime.jsxs("div",{className:r("space-y-4",f),children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>w("list"),className:"inline-flex items-center gap-1 text-sm text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),"Back to ",x]}),jsxRuntime.jsx(re,{title:u==="create"?`Create ${e}`:`Edit ${e}`,fields:c,values:u==="edit"?G:void 0,loading:j,submitLabel:u==="create"?"Create":"Save changes",onCancel:()=>w("list"),onSubmit:async N=>{M(true);try{u==="create"&&m?await m(N):u==="edit"&&S&&d&&await d(S,N),w("list");}finally{M(false);}}})]})}i(be,"DashCrud");function fe({resourceName:e,loading:a,onConfirm:l,onCancel:s}){return jsxRuntime.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",children:jsxRuntime.jsxs("div",{className:"w-full max-w-sm rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6 shadow-lg",children:[jsxRuntime.jsxs("h3",{className:"text-lg font-semibold text-[var(--dash-text)]",children:["Delete ",e,"?"]}),jsxRuntime.jsxs("p",{className:"mt-2 text-sm text-[var(--dash-text-muted)]",children:["This action cannot be undone. The ",e.toLowerCase()," will be permanently removed."]}),jsxRuntime.jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[jsxRuntime.jsx("button",{type:"button",onClick:s,disabled:a,className:r("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:l,disabled:a,className:r("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-error)] text-white","hover:bg-red-600","disabled:opacity-50 disabled:cursor-not-allowed"),children:a?"Deleting...":"Delete"})]})]})})}i(fe,"DeleteDialog");
|
|
3
|
-
exports.
|
|
2
|
+
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime'),q=require('react');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var q__namespace=/*#__PURE__*/_interopNamespace(q);var ie=Object.defineProperty;var i=(e,r)=>ie(e,"name",{value:r,configurable:true});function a(...e){return tailwindMerge.twMerge(clsx.clsx(e))}i(a,"cn");function ce({sidebar:e,header:r,children:l,sidebarCollapsed:s=false,onSidebarCollapse:n,className:c}){return jsxRuntime.jsxs("div",{className:a("flex h-screen overflow-hidden","bg-[var(--dash-bg)] text-[var(--dash-text)]",c),children:[jsxRuntime.jsx("aside",{className:a("flex-shrink-0 overflow-y-auto overflow-x-hidden transition-[width] duration-200","border-r border-[var(--dash-border)] bg-[var(--dash-surface)]",s?"w-[var(--dash-sidebar-collapsed-width)]":"w-[var(--dash-sidebar-width)]"),children:e}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[r&&jsxRuntime.jsx("header",{className:"flex-shrink-0 border-b border-[var(--dash-border)] bg-[var(--dash-surface)]",children:r}),jsxRuntime.jsx("main",{className:"flex-1 overflow-y-auto p-6",children:l})]}),!s&&jsxRuntime.jsx("div",{className:"fixed inset-0 z-40 bg-black/60 lg:hidden",onClick:()=>n?.(true)})]})}i(ce,"Layout");function ue({size:e=28}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{d:"M4 4h4v6h8V4h4v16h-4v-6H8v6H4V4z",fill:"currentColor"})})}i(ue,"HanzoMark");function he({logo:e,groups:r,userMenu:l,collapsed:s=false,onToggleCollapse:n,onNavigate:c,className:o}){return jsxRuntime.jsxs("nav",{className:a("flex h-full flex-col","bg-[var(--dash-surface)] text-[var(--dash-text)]",o),children:[jsxRuntime.jsxs("div",{className:a("flex h-[var(--dash-header-height)] items-center border-b border-[var(--dash-border)]",s?"justify-center px-2":"px-4"),children:[e??jsxRuntime.jsx(ue,{}),!s&&n&&jsxRuntime.jsx("button",{type:"button",onClick:n,className:"ml-auto rounded p-1 text-[var(--dash-text-dim)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]","aria-label":"Collapse sidebar",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),s&&n&&jsxRuntime.jsx("button",{type:"button",onClick:n,className:"absolute -right-3 top-4 z-50 hidden rounded-full border border-[var(--dash-border)] bg-[var(--dash-surface)] p-1 text-[var(--dash-text-dim)] hover:text-[var(--dash-text)] lg:flex","aria-label":"Expand sidebar",children:jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto py-2",children:r.map((m,d)=>jsxRuntime.jsx(me,{group:m,collapsed:s,onNavigate:c},d))}),l&&jsxRuntime.jsx("div",{className:"border-t border-[var(--dash-border)] p-2",children:l})]})}i(he,"Sidebar");function me({group:e,collapsed:r,onNavigate:l}){let[s,n]=q__namespace.useState(e.defaultOpen!==false),c=e.collapsible!==false&&!!e.title;return jsxRuntime.jsxs("div",{className:"mb-1",children:[e.title&&!r&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>c&&n(o=>!o),className:a("flex w-full items-center px-4 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-[var(--dash-text-dim)]",c&&"cursor-pointer hover:text-[var(--dash-text-muted)]"),children:[jsxRuntime.jsx("span",{className:"flex-1 text-left",children:e.title}),c&&jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",className:a("transition-transform",s?"rotate-0":"-rotate-90"),children:jsxRuntime.jsx("path",{d:"M4 6l4 4 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),(s||r)&&jsxRuntime.jsx("ul",{className:"space-y-0.5 px-2",children:e.items.map(o=>jsxRuntime.jsx("li",{children:jsxRuntime.jsxs("button",{type:"button",onClick:()=>l?.(o.href),title:r?o.label:void 0,className:a("flex w-full items-center gap-2 rounded-[var(--dash-radius-sm)] px-2 py-1.5 text-sm transition-colors",o.active?"bg-[var(--dash-primary)] text-[var(--dash-primary-text)]":"text-[var(--dash-text-muted)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]",r&&"justify-center px-0"),children:[o.icon&&jsxRuntime.jsx("span",{className:"flex h-5 w-5 items-center justify-center flex-shrink-0",children:o.icon}),!r&&jsxRuntime.jsx("span",{className:"flex-1 truncate text-left",children:o.label}),!r&&o.badge!==void 0&&jsxRuntime.jsx("span",{className:"ml-auto rounded-full bg-[var(--dash-primary)] px-1.5 py-0.5 text-[10px] font-medium text-[var(--dash-primary-text)]",children:o.badge})]})},o.href))})]})}i(me,"SidebarGroup");function ve({breadcrumbs:e,searchPlaceholder:r="Search...",onSearch:l,avatarUrl:s,userName:n,userDropdown:c,onToggleTheme:o,theme:m="dark",actions:d,className:v}){let[C,R]=q__namespace.useState(false),S=q__namespace.useRef(null);return q__namespace.useEffect(()=>{if(!C)return;function b(M){S.current&&!S.current.contains(M.target)&&R(false);}return i(b,"handleClick"),document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[C]),jsxRuntime.jsxs("div",{className:a("flex h-[var(--dash-header-height)] items-center gap-4 px-4","bg-[var(--dash-surface)] text-[var(--dash-text)]",v),children:[e&&e.length>0&&jsxRuntime.jsx("nav",{className:"flex items-center gap-1 text-sm","aria-label":"Breadcrumb",children:e.map((b,M)=>jsxRuntime.jsxs(q__namespace.Fragment,{children:[M>0&&jsxRuntime.jsx("span",{className:"text-[var(--dash-text-dim)]",children:"/"}),b.href?jsxRuntime.jsx("a",{href:b.href,className:"text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:b.label}):jsxRuntime.jsx("span",{className:"text-[var(--dash-text)]",children:b.label})]},M))}),jsxRuntime.jsx("div",{className:"flex-1"}),l&&jsxRuntime.jsxs("div",{className:"relative hidden sm:block",children:[jsxRuntime.jsxs("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-[var(--dash-text-dim)]",width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[jsxRuntime.jsx("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M11 11l3 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),jsxRuntime.jsx("input",{type:"text",placeholder:r,onChange:b=>l(b.target.value),className:a("h-8 w-56 rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] pl-8 pr-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","transition-colors")})]}),d,o&&jsxRuntime.jsx("button",{type:"button",onClick:o,className:"rounded-[var(--dash-radius-sm)] p-1.5 text-[var(--dash-text-dim)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors","aria-label":`Switch to ${m==="dark"?"light":"dark"} mode`,children:m==="dark"?jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[jsxRuntime.jsx("circle",{cx:"8",cy:"8",r:"3.5",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M8 1v2M8 13v2M1 8h2M13 8h2M3.05 3.05l1.41 1.41M11.54 11.54l1.41 1.41M3.05 12.95l1.41-1.41M11.54 4.46l1.41-1.41",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M14 9.5A6.5 6.5 0 016.5 2 5.5 5.5 0 1014 9.5z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(s||n)&&jsxRuntime.jsxs("div",{className:"relative",ref:S,children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>R(b=>!b),className:"flex items-center gap-2 rounded-[var(--dash-radius-sm)] p-1 hover:bg-[var(--dash-surface-hover)] transition-colors",children:s?jsxRuntime.jsx("img",{src:s,alt:n??"User",className:"h-7 w-7 rounded-full object-cover"}):jsxRuntime.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-[var(--dash-primary)] text-xs font-medium text-[var(--dash-primary-text)]",children:(n??"?")[0].toUpperCase()})}),C&&c&&jsxRuntime.jsx("div",{className:"absolute right-0 top-full z-50 mt-1 min-w-48 rounded-[var(--dash-radius)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-1 shadow-lg",children:c})]})]})}i(ve,"Header");function te({columns:e,data:r,rowKey:l,selectable:s=false,selectedKeys:n,onSelectionChange:c,searchable:o=false,searchPlaceholder:m="Search...",totalRows:d,page:v=0,pageSize:C=20,onPageChange:R,onPageSizeChange:S,actions:b,loading:M=false,emptyMessage:f="No data",className:x}){let[u,w]=q__namespace.useState(""),[L,A]=q__namespace.useState(null),G=q__namespace.useMemo(()=>{if(!u)return r;let t=u.toLowerCase();return r.filter(k=>e.some(O=>(O.cell?"":String(k[O.id]??"")).toLowerCase().includes(t)))},[r,u,e]),W=q__namespace.useMemo(()=>{if(!L)return G;let{column:t,direction:k}=L;return [...G].sort((O,E)=>{let Z=O[t],ee=E[t];if(Z==null&&ee==null)return 0;if(Z==null)return 1;if(ee==null)return -1;let se=String(Z).localeCompare(String(ee),void 0,{numeric:true});return k==="asc"?se:-se})},[G,L]),I=d??W.length,z=Math.max(1,Math.ceil(I/C)),j=R?W:W.slice(v*C,(v+1)*C),F=n??new Set,J=j.length>0&&j.every(t=>F.has(l(t)));function U(){c&&c(J?new Set:new Set(j.map(l)));}i(U,"toggleAll");function X(t){if(!c)return;let k=new Set(F);k.has(t)?k.delete(t):k.add(t),c(k);}i(X,"toggleRow");function Y(t){A(k=>k?.column===t?k.direction==="asc"?{column:t,direction:"desc"}:null:{column:t,direction:"asc"});}i(Y,"handleSort");let N=b?[...e,{id:"__actions",header:"",width:"auto"}]:e;return jsxRuntime.jsxs("div",{className:a("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)]",x),children:[(o||s)&&jsxRuntime.jsxs("div",{className:"flex items-center gap-3 border-b border-[var(--dash-border)] px-4 py-3",children:[o&&jsxRuntime.jsx("input",{type:"text",placeholder:m,value:u,onChange:t=>w(t.target.value),className:a("h-8 w-64 max-w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]")}),s&&F.size>0&&jsxRuntime.jsxs("span",{className:"text-xs text-[var(--dash-text-muted)]",children:[F.size," selected"]})]}),jsxRuntime.jsx("div",{className:"overflow-x-auto",children:jsxRuntime.jsxs("table",{className:"w-full text-sm",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"border-b border-[var(--dash-border)]",children:[s&&jsxRuntime.jsx("th",{className:"w-10 px-4 py-2.5",children:jsxRuntime.jsx("input",{type:"checkbox",checked:J,onChange:U,className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),N.map(t=>jsxRuntime.jsx("th",{style:t.width?{width:t.width}:void 0,className:a("px-4 py-2.5 text-[var(--dash-text-dim)] font-medium",t.align==="center"&&"text-center",t.align==="right"&&"text-right",!t.align&&"text-left",t.sortable&&"cursor-pointer select-none hover:text-[var(--dash-text-muted)]"),onClick:t.sortable?()=>Y(t.id):void 0,children:jsxRuntime.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.header,t.sortable&&L?.column===t.id&&jsxRuntime.jsx("span",{className:"text-[10px]",children:L.direction==="asc"?"\u2191":"\u2193"})]})},t.id))]})}),jsxRuntime.jsx("tbody",{children:M?jsxRuntime.jsx("tr",{children:jsxRuntime.jsx("td",{colSpan:N.length+(s?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:"Loading..."})}):j.length===0?jsxRuntime.jsx("tr",{children:jsxRuntime.jsx("td",{colSpan:N.length+(s?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:f})}):j.map(t=>{let k=l(t),O=F.has(k);return jsxRuntime.jsxs("tr",{className:a("border-b border-[var(--dash-border)] transition-colors",O?"bg-[var(--dash-surface-active)]":"hover:bg-[var(--dash-surface-hover)]"),children:[s&&jsxRuntime.jsx("td",{className:"w-10 px-4 py-2.5",children:jsxRuntime.jsx("input",{type:"checkbox",checked:O,onChange:()=>X(k),className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),e.map(E=>jsxRuntime.jsx("td",{className:a("px-4 py-2.5",E.align==="center"&&"text-center",E.align==="right"&&"text-right"),children:E.cell?E.cell(t):String(t[E.id]??"")},E.id)),b&&jsxRuntime.jsx("td",{className:"px-4 py-2.5 text-right",children:b(t)})]},k)})})]})}),z>1&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-[var(--dash-border)] px-4 py-2.5 text-xs text-[var(--dash-text-muted)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{children:"Rows per page"}),jsxRuntime.jsx("select",{value:C,onChange:t=>S?.(Number(t.target.value)),className:"h-7 rounded border border-[var(--dash-border)] bg-[var(--dash-bg)] px-2 text-xs text-[var(--dash-text)] focus:outline-none",children:[10,20,50,100].map(t=>jsxRuntime.jsx("option",{value:t,children:t},t))})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("span",{children:["Page ",v+1," of ",z]}),jsxRuntime.jsx("button",{type:"button",disabled:v===0,onClick:()=>R?.(v-1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsxRuntime.jsx("button",{type:"button",disabled:v>=z-1,onClick:()=>R?.(v+1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})]})}i(te,"Table");function ae({title:e,fields:r,values:l,onSubmit:s,onCancel:n,submitLabel:c="Save",cancelLabel:o="Cancel",loading:m=false,className:d}){let[v,C]=q__namespace.useState(()=>{let f={};for(let x of r)f[x.name]=l?.[x.name]??x.defaultValue??(x.type==="toggle"?false:"");return f}),[R,S]=q__namespace.useState({});function b(f,x){C(u=>({...u,[f]:x})),S(u=>{if(!u[f])return u;let w={...u};return delete w[f],w});}i(b,"setValue");async function M(f){f.preventDefault();let x={};for(let u of r){let w=v[u.name];if(u.required&&(w===""||w===null||w===void 0)&&(x[u.name]=`${u.label} is required`),u.validate){let L=u.validate(w);L&&(x[u.name]=L);}}if(Object.keys(x).length>0){S(x);return}await s(v);}return i(M,"handleSubmit"),jsxRuntime.jsxs("form",{onSubmit:M,className:a("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6",d),children:[e&&jsxRuntime.jsx("h3",{className:"mb-4 text-lg font-semibold text-[var(--dash-text)]",children:e}),jsxRuntime.jsx("div",{className:"space-y-4",children:r.map(f=>jsxRuntime.jsx(pe,{field:f,value:v[f.name],error:R[f.name],onChange:x=>b(f.name,x)},f.name))}),jsxRuntime.jsxs("div",{className:"mt-6 flex items-center gap-3",children:[jsxRuntime.jsx("button",{type:"submit",disabled:m,className:a("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]","disabled:opacity-50 disabled:cursor-not-allowed"),children:m?"Saving...":c}),n&&jsxRuntime.jsx("button",{type:"button",onClick:n,disabled:m,className:a("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:o})]})]})}i(ae,"Form");var Q=a("w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 py-2 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors");function pe({field:e,value:r,error:l,onChange:s}){let n=`dash-field-${e.name}`,c=jsxRuntime.jsxs("label",{htmlFor:n,className:"mb-1 block text-sm font-medium text-[var(--dash-text)]",children:[e.label,e.required&&jsxRuntime.jsx("span",{className:"ml-0.5 text-[var(--dash-error)]",children:"*"})]}),o=e.description?jsxRuntime.jsx("p",{className:"mt-1 text-xs text-[var(--dash-text-dim)]",children:e.description}):null,m=l?jsxRuntime.jsx("p",{className:"mt-1 text-xs text-[var(--dash-error)]",children:l}):null;switch(e.type){case "text":case "email":case "password":case "number":return jsxRuntime.jsxs("div",{children:[c,jsxRuntime.jsx("input",{id:n,type:e.type,value:String(r??""),placeholder:e.placeholder,disabled:e.disabled,onChange:d=>s(e.type==="number"?Number(d.target.value):d.target.value),className:a(Q,l&&"border-[var(--dash-error)]")}),o,m]});case "textarea":return jsxRuntime.jsxs("div",{children:[c,jsxRuntime.jsx("textarea",{id:n,value:String(r??""),placeholder:e.placeholder,disabled:e.disabled,rows:e.rows??3,onChange:d=>s(d.target.value),className:a(Q,"resize-y",l&&"border-[var(--dash-error)]")}),o,m]});case "select":case "relation":return jsxRuntime.jsxs("div",{children:[c,jsxRuntime.jsxs("select",{id:n,value:String(r??""),disabled:e.disabled,onChange:d=>s(d.target.value),className:a(Q,l&&"border-[var(--dash-error)]"),children:[jsxRuntime.jsx("option",{value:"",children:e.placeholder??"Select..."}),(e.options??[]).map(d=>jsxRuntime.jsx("option",{value:d.value,children:d.label},d.value))]}),o,m]});case "toggle":return jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("button",{id:n,type:"button",role:"switch","aria-checked":!!r,disabled:e.disabled,onClick:()=>s(!r),className:a("relative inline-flex h-5 w-9 flex-shrink-0 rounded-full transition-colors","focus:outline-none focus:ring-2 focus:ring-[var(--dash-primary)] focus:ring-offset-2 focus:ring-offset-[var(--dash-surface)]",r?"bg-[var(--dash-primary)]":"bg-[var(--dash-border)]",e.disabled&&"opacity-50 cursor-not-allowed"),children:jsxRuntime.jsx("span",{className:a("pointer-events-none inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",r?"translate-x-4":"translate-x-0.5","mt-0.5")})}),jsxRuntime.jsx("label",{htmlFor:n,className:"text-sm text-[var(--dash-text)]",children:e.label}),o,m]});case "json":return jsxRuntime.jsxs("div",{children:[c,jsxRuntime.jsx("textarea",{id:n,value:typeof r=="string"?r:JSON.stringify(r,null,2),placeholder:e.placeholder??"{}",disabled:e.disabled,rows:e.rows??6,onChange:d=>{try{s(JSON.parse(d.target.value));}catch{s(d.target.value);}},className:a(Q,"font-mono text-xs resize-y",l&&"border-[var(--dash-error)]")}),o,m]});case "file":return jsxRuntime.jsxs("div",{children:[c,jsxRuntime.jsx("input",{id:n,type:"file",accept:e.accept,disabled:e.disabled,onChange:d=>{let v=d.target.files?.[0];v&&s(v);},className:a("w-full text-sm text-[var(--dash-text-muted)]","file:mr-3 file:rounded-[var(--dash-radius-sm)] file:border-0 file:bg-[var(--dash-primary)] file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-[var(--dash-primary-text)]","file:cursor-pointer hover:file:bg-[var(--dash-primary-hover)]")}),o,m]});default:return null}}i(pe,"FieldRenderer");function be({resourceName:e,resourceNamePlural:r,columns:l,data:s,rowKey:n,fields:c,rowToValues:o,onCreate:m,onUpdate:d,onDelete:v,canCreate:C=true,canEdit:R=true,canDelete:S=true,tableProps:b,loading:M=false,className:f}){let x=r??`${e}s`,[u,w]=q__namespace.useState("list"),[L,A]=q__namespace.useState(null),[G,W]=q__namespace.useState({}),[I,z]=q__namespace.useState(null),[j,F]=q__namespace.useState(false);function J(N){let t=n(N);A(t),W(o?o(N):N),w("edit");}i(J,"handleEdit");function U(N){z(n(N));}i(U,"handleDeleteConfirm");async function X(){if(!(!I||!v)){F(true);try{await v(I);}finally{F(false),z(null);}}}i(X,"confirmDelete");function Y(N){return jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1",children:[R&&d&&jsxRuntime.jsx("button",{type:"button",onClick:()=>J(N),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-text-muted)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors",children:"Edit"}),S&&v&&jsxRuntime.jsx("button",{type:"button",onClick:()=>U(N),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-error)] hover:bg-[var(--dash-error-dim)] transition-colors",children:"Delete"})]})}return i(Y,"actionsRenderer"),u==="list"?jsxRuntime.jsxs("div",{className:a("space-y-4",f),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("h2",{className:"text-xl font-semibold text-[var(--dash-text)]",children:x}),C&&m&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{A(null),W({}),w("create");},className:a("rounded-[var(--dash-radius)] px-3 py-1.5 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]"),children:["Create ",e]})]}),jsxRuntime.jsx(te,{columns:l,data:s,rowKey:n,actions:R||S?Y:void 0,loading:M,searchable:true,emptyMessage:`No ${x.toLowerCase()} found`,...b}),I!==null&&jsxRuntime.jsx(fe,{resourceName:e,loading:j,onConfirm:X,onCancel:()=>z(null)})]}):jsxRuntime.jsxs("div",{className:a("space-y-4",f),children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>w("list"),className:"inline-flex items-center gap-1 text-sm text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),"Back to ",x]}),jsxRuntime.jsx(ae,{title:u==="create"?`Create ${e}`:`Edit ${e}`,fields:c,values:u==="edit"?G:void 0,loading:j,submitLabel:u==="create"?"Create":"Save changes",onCancel:()=>w("list"),onSubmit:async N=>{F(true);try{u==="create"&&m?await m(N):u==="edit"&&L&&d&&await d(L,N),w("list");}finally{F(false);}}})]})}i(be,"Crud");function fe({resourceName:e,loading:r,onConfirm:l,onCancel:s}){return jsxRuntime.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",children:jsxRuntime.jsxs("div",{className:"w-full max-w-sm rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6 shadow-lg",children:[jsxRuntime.jsxs("h3",{className:"text-lg font-semibold text-[var(--dash-text)]",children:["Delete ",e,"?"]}),jsxRuntime.jsxs("p",{className:"mt-2 text-sm text-[var(--dash-text-muted)]",children:["This action cannot be undone. The ",e.toLowerCase()," will be permanently removed."]}),jsxRuntime.jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[jsxRuntime.jsx("button",{type:"button",onClick:s,disabled:r,className:a("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:l,disabled:r,className:a("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-error)] text-white","hover:bg-red-600","disabled:opacity-50 disabled:cursor-not-allowed"),children:r?"Deleting...":"Delete"})]})]})})}i(fe,"DeleteDialog");
|
|
3
|
+
exports.Crud=be;exports.Form=ae;exports.Header=ve;exports.Layout=ce;exports.Sidebar=he;exports.Table=te;
|
package/dist/dash/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsxs,jsx}from'react/jsx-runtime';import*as q from'react';var ie=Object.defineProperty;var i=(e,a)=>ie(e,"name",{value:a,configurable:true});function r(...e){return twMerge(clsx(e))}i(r,"cn");function ce({sidebar:e,header:a,children:l,sidebarCollapsed:s=false,onSidebarCollapse:n,className:c}){return jsxs("div",{className:r("flex h-screen overflow-hidden","bg-[var(--dash-bg)] text-[var(--dash-text)]",c),children:[jsx("aside",{className:r("flex-shrink-0 overflow-y-auto overflow-x-hidden transition-[width] duration-200","border-r border-[var(--dash-border)] bg-[var(--dash-surface)]",s?"w-[var(--dash-sidebar-collapsed-width)]":"w-[var(--dash-sidebar-width)]"),children:e}),jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[a&&jsx("header",{className:"flex-shrink-0 border-b border-[var(--dash-border)] bg-[var(--dash-surface)]",children:a}),jsx("main",{className:"flex-1 overflow-y-auto p-6",children:l})]}),!s&&jsx("div",{className:"fixed inset-0 z-40 bg-black/60 lg:hidden",onClick:()=>n?.(true)})]})}i(ce,"DashLayout");function ue({size:e=28}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M4 4h4v6h8V4h4v16h-4v-6H8v6H4V4z",fill:"currentColor"})})}i(ue,"HanzoMark");function he({logo:e,groups:a,userMenu:l,collapsed:s=false,onToggleCollapse:n,onNavigate:c,className:o}){return jsxs("nav",{className:r("flex h-full flex-col","bg-[var(--dash-surface)] text-[var(--dash-text)]",o),children:[jsxs("div",{className:r("flex h-[var(--dash-header-height)] items-center border-b border-[var(--dash-border)]",s?"justify-center px-2":"px-4"),children:[e??jsx(ue,{}),!s&&n&&jsx("button",{type:"button",onClick:n,className:"ml-auto rounded p-1 text-[var(--dash-text-dim)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]","aria-label":"Collapse sidebar",children:jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),s&&n&&jsx("button",{type:"button",onClick:n,className:"absolute -right-3 top-4 z-50 hidden rounded-full border border-[var(--dash-border)] bg-[var(--dash-surface)] p-1 text-[var(--dash-text-dim)] hover:text-[var(--dash-text)] lg:flex","aria-label":"Expand sidebar",children:jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),jsx("div",{className:"flex-1 overflow-y-auto py-2",children:a.map((m,d)=>jsx(me,{group:m,collapsed:s,onNavigate:c},d))}),l&&jsx("div",{className:"border-t border-[var(--dash-border)] p-2",children:l})]})}i(he,"DashSidebar");function me({group:e,collapsed:a,onNavigate:l}){let[s,n]=q.useState(e.defaultOpen!==false),c=e.collapsible!==false&&!!e.title;return jsxs("div",{className:"mb-1",children:[e.title&&!a&&jsxs("button",{type:"button",onClick:()=>c&&n(o=>!o),className:r("flex w-full items-center px-4 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-[var(--dash-text-dim)]",c&&"cursor-pointer hover:text-[var(--dash-text-muted)]"),children:[jsx("span",{className:"flex-1 text-left",children:e.title}),c&&jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",className:r("transition-transform",s?"rotate-0":"-rotate-90"),children:jsx("path",{d:"M4 6l4 4 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),(s||a)&&jsx("ul",{className:"space-y-0.5 px-2",children:e.items.map(o=>jsx("li",{children:jsxs("button",{type:"button",onClick:()=>l?.(o.href),title:a?o.label:void 0,className:r("flex w-full items-center gap-2 rounded-[var(--dash-radius-sm)] px-2 py-1.5 text-sm transition-colors",o.active?"bg-[var(--dash-primary)] text-[var(--dash-primary-text)]":"text-[var(--dash-text-muted)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]",a&&"justify-center px-0"),children:[o.icon&&jsx("span",{className:"flex h-5 w-5 items-center justify-center flex-shrink-0",children:o.icon}),!a&&jsx("span",{className:"flex-1 truncate text-left",children:o.label}),!a&&o.badge!==void 0&&jsx("span",{className:"ml-auto rounded-full bg-[var(--dash-primary)] px-1.5 py-0.5 text-[10px] font-medium text-[var(--dash-primary-text)]",children:o.badge})]})},o.href))})]})}i(me,"SidebarGroup");function ve({breadcrumbs:e,searchPlaceholder:a="Search...",onSearch:l,avatarUrl:s,userName:n,userDropdown:c,onToggleTheme:o,theme:m="dark",actions:d,className:v}){let[D,C]=q.useState(false),R=q.useRef(null);return q.useEffect(()=>{if(!D)return;function b(P){R.current&&!R.current.contains(P.target)&&C(false);}return i(b,"handleClick"),document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[D]),jsxs("div",{className:r("flex h-[var(--dash-header-height)] items-center gap-4 px-4","bg-[var(--dash-surface)] text-[var(--dash-text)]",v),children:[e&&e.length>0&&jsx("nav",{className:"flex items-center gap-1 text-sm","aria-label":"Breadcrumb",children:e.map((b,P)=>jsxs(q.Fragment,{children:[P>0&&jsx("span",{className:"text-[var(--dash-text-dim)]",children:"/"}),b.href?jsx("a",{href:b.href,className:"text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:b.label}):jsx("span",{className:"text-[var(--dash-text)]",children:b.label})]},P))}),jsx("div",{className:"flex-1"}),l&&jsxs("div",{className:"relative hidden sm:block",children:[jsxs("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-[var(--dash-text-dim)]",width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[jsx("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M11 11l3 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),jsx("input",{type:"text",placeholder:a,onChange:b=>l(b.target.value),className:r("h-8 w-56 rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] pl-8 pr-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","transition-colors")})]}),d,o&&jsx("button",{type:"button",onClick:o,className:"rounded-[var(--dash-radius-sm)] p-1.5 text-[var(--dash-text-dim)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors","aria-label":`Switch to ${m==="dark"?"light":"dark"} mode`,children:m==="dark"?jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[jsx("circle",{cx:"8",cy:"8",r:"3.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M8 1v2M8 13v2M1 8h2M13 8h2M3.05 3.05l1.41 1.41M11.54 11.54l1.41 1.41M3.05 12.95l1.41-1.41M11.54 4.46l1.41-1.41",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M14 9.5A6.5 6.5 0 016.5 2 5.5 5.5 0 1014 9.5z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(s||n)&&jsxs("div",{className:"relative",ref:R,children:[jsx("button",{type:"button",onClick:()=>C(b=>!b),className:"flex items-center gap-2 rounded-[var(--dash-radius-sm)] p-1 hover:bg-[var(--dash-surface-hover)] transition-colors",children:s?jsx("img",{src:s,alt:n??"User",className:"h-7 w-7 rounded-full object-cover"}):jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-[var(--dash-primary)] text-xs font-medium text-[var(--dash-primary-text)]",children:(n??"?")[0].toUpperCase()})}),D&&c&&jsx("div",{className:"absolute right-0 top-full z-50 mt-1 min-w-48 rounded-[var(--dash-radius)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-1 shadow-lg",children:c})]})]})}i(ve,"DashHeader");function te({columns:e,data:a,rowKey:l,selectable:s=false,selectedKeys:n,onSelectionChange:c,searchable:o=false,searchPlaceholder:m="Search...",totalRows:d,page:v=0,pageSize:D=20,onPageChange:C,onPageSizeChange:R,actions:b,loading:P=false,emptyMessage:f="No data",className:x}){let[u,w]=q.useState(""),[S,A]=q.useState(null),G=q.useMemo(()=>{if(!u)return a;let t=u.toLowerCase();return a.filter(k=>e.some(O=>(O.cell?"":String(k[O.id]??"")).toLowerCase().includes(t)))},[a,u,e]),W=q.useMemo(()=>{if(!S)return G;let{column:t,direction:k}=S;return [...G].sort((O,E)=>{let Z=O[t],ee=E[t];if(Z==null&&ee==null)return 0;if(Z==null)return 1;if(ee==null)return -1;let se=String(Z).localeCompare(String(ee),void 0,{numeric:true});return k==="asc"?se:-se})},[G,S]),I=d??W.length,z=Math.max(1,Math.ceil(I/D)),j=C?W:W.slice(v*D,(v+1)*D),M=n??new Set,J=j.length>0&&j.every(t=>M.has(l(t)));function U(){c&&c(J?new Set:new Set(j.map(l)));}i(U,"toggleAll");function X(t){if(!c)return;let k=new Set(M);k.has(t)?k.delete(t):k.add(t),c(k);}i(X,"toggleRow");function Y(t){A(k=>k?.column===t?k.direction==="asc"?{column:t,direction:"desc"}:null:{column:t,direction:"asc"});}i(Y,"handleSort");let N=b?[...e,{id:"__actions",header:"",width:"auto"}]:e;return jsxs("div",{className:r("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)]",x),children:[(o||s)&&jsxs("div",{className:"flex items-center gap-3 border-b border-[var(--dash-border)] px-4 py-3",children:[o&&jsx("input",{type:"text",placeholder:m,value:u,onChange:t=>w(t.target.value),className:r("h-8 w-64 max-w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]")}),s&&M.size>0&&jsxs("span",{className:"text-xs text-[var(--dash-text-muted)]",children:[M.size," selected"]})]}),jsx("div",{className:"overflow-x-auto",children:jsxs("table",{className:"w-full text-sm",children:[jsx("thead",{children:jsxs("tr",{className:"border-b border-[var(--dash-border)]",children:[s&&jsx("th",{className:"w-10 px-4 py-2.5",children:jsx("input",{type:"checkbox",checked:J,onChange:U,className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),N.map(t=>jsx("th",{style:t.width?{width:t.width}:void 0,className:r("px-4 py-2.5 text-[var(--dash-text-dim)] font-medium",t.align==="center"&&"text-center",t.align==="right"&&"text-right",!t.align&&"text-left",t.sortable&&"cursor-pointer select-none hover:text-[var(--dash-text-muted)]"),onClick:t.sortable?()=>Y(t.id):void 0,children:jsxs("span",{className:"inline-flex items-center gap-1",children:[t.header,t.sortable&&S?.column===t.id&&jsx("span",{className:"text-[10px]",children:S.direction==="asc"?"\u2191":"\u2193"})]})},t.id))]})}),jsx("tbody",{children:P?jsx("tr",{children:jsx("td",{colSpan:N.length+(s?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:"Loading..."})}):j.length===0?jsx("tr",{children:jsx("td",{colSpan:N.length+(s?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:f})}):j.map(t=>{let k=l(t),O=M.has(k);return jsxs("tr",{className:r("border-b border-[var(--dash-border)] transition-colors",O?"bg-[var(--dash-surface-active)]":"hover:bg-[var(--dash-surface-hover)]"),children:[s&&jsx("td",{className:"w-10 px-4 py-2.5",children:jsx("input",{type:"checkbox",checked:O,onChange:()=>X(k),className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),e.map(E=>jsx("td",{className:r("px-4 py-2.5",E.align==="center"&&"text-center",E.align==="right"&&"text-right"),children:E.cell?E.cell(t):String(t[E.id]??"")},E.id)),b&&jsx("td",{className:"px-4 py-2.5 text-right",children:b(t)})]},k)})})]})}),z>1&&jsxs("div",{className:"flex items-center justify-between border-t border-[var(--dash-border)] px-4 py-2.5 text-xs text-[var(--dash-text-muted)]",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{children:"Rows per page"}),jsx("select",{value:D,onChange:t=>R?.(Number(t.target.value)),className:"h-7 rounded border border-[var(--dash-border)] bg-[var(--dash-bg)] px-2 text-xs text-[var(--dash-text)] focus:outline-none",children:[10,20,50,100].map(t=>jsx("option",{value:t,children:t},t))})]}),jsxs("div",{className:"flex items-center gap-2",children:[jsxs("span",{children:["Page ",v+1," of ",z]}),jsx("button",{type:"button",disabled:v===0,onClick:()=>C?.(v-1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("button",{type:"button",disabled:v>=z-1,onClick:()=>C?.(v+1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})]})}i(te,"DashDataTable");function re({title:e,fields:a,values:l,onSubmit:s,onCancel:n,submitLabel:c="Save",cancelLabel:o="Cancel",loading:m=false,className:d}){let[v,D]=q.useState(()=>{let f={};for(let x of a)f[x.name]=l?.[x.name]??x.defaultValue??(x.type==="toggle"?false:"");return f}),[C,R]=q.useState({});function b(f,x){D(u=>({...u,[f]:x})),R(u=>{if(!u[f])return u;let w={...u};return delete w[f],w});}i(b,"setValue");async function P(f){f.preventDefault();let x={};for(let u of a){let w=v[u.name];if(u.required&&(w===""||w===null||w===void 0)&&(x[u.name]=`${u.label} is required`),u.validate){let S=u.validate(w);S&&(x[u.name]=S);}}if(Object.keys(x).length>0){R(x);return}await s(v);}return i(P,"handleSubmit"),jsxs("form",{onSubmit:P,className:r("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6",d),children:[e&&jsx("h3",{className:"mb-4 text-lg font-semibold text-[var(--dash-text)]",children:e}),jsx("div",{className:"space-y-4",children:a.map(f=>jsx(pe,{field:f,value:v[f.name],error:C[f.name],onChange:x=>b(f.name,x)},f.name))}),jsxs("div",{className:"mt-6 flex items-center gap-3",children:[jsx("button",{type:"submit",disabled:m,className:r("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]","disabled:opacity-50 disabled:cursor-not-allowed"),children:m?"Saving...":c}),n&&jsx("button",{type:"button",onClick:n,disabled:m,className:r("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:o})]})]})}i(re,"DashForm");var Q=r("w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 py-2 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors");function pe({field:e,value:a,error:l,onChange:s}){let n=`dash-field-${e.name}`,c=jsxs("label",{htmlFor:n,className:"mb-1 block text-sm font-medium text-[var(--dash-text)]",children:[e.label,e.required&&jsx("span",{className:"ml-0.5 text-[var(--dash-error)]",children:"*"})]}),o=e.description?jsx("p",{className:"mt-1 text-xs text-[var(--dash-text-dim)]",children:e.description}):null,m=l?jsx("p",{className:"mt-1 text-xs text-[var(--dash-error)]",children:l}):null;switch(e.type){case "text":case "email":case "password":case "number":return jsxs("div",{children:[c,jsx("input",{id:n,type:e.type,value:String(a??""),placeholder:e.placeholder,disabled:e.disabled,onChange:d=>s(e.type==="number"?Number(d.target.value):d.target.value),className:r(Q,l&&"border-[var(--dash-error)]")}),o,m]});case "textarea":return jsxs("div",{children:[c,jsx("textarea",{id:n,value:String(a??""),placeholder:e.placeholder,disabled:e.disabled,rows:e.rows??3,onChange:d=>s(d.target.value),className:r(Q,"resize-y",l&&"border-[var(--dash-error)]")}),o,m]});case "select":case "relation":return jsxs("div",{children:[c,jsxs("select",{id:n,value:String(a??""),disabled:e.disabled,onChange:d=>s(d.target.value),className:r(Q,l&&"border-[var(--dash-error)]"),children:[jsx("option",{value:"",children:e.placeholder??"Select..."}),(e.options??[]).map(d=>jsx("option",{value:d.value,children:d.label},d.value))]}),o,m]});case "toggle":return jsxs("div",{className:"flex items-center gap-3",children:[jsx("button",{id:n,type:"button",role:"switch","aria-checked":!!a,disabled:e.disabled,onClick:()=>s(!a),className:r("relative inline-flex h-5 w-9 flex-shrink-0 rounded-full transition-colors","focus:outline-none focus:ring-2 focus:ring-[var(--dash-primary)] focus:ring-offset-2 focus:ring-offset-[var(--dash-surface)]",a?"bg-[var(--dash-primary)]":"bg-[var(--dash-border)]",e.disabled&&"opacity-50 cursor-not-allowed"),children:jsx("span",{className:r("pointer-events-none inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",a?"translate-x-4":"translate-x-0.5","mt-0.5")})}),jsx("label",{htmlFor:n,className:"text-sm text-[var(--dash-text)]",children:e.label}),o,m]});case "json":return jsxs("div",{children:[c,jsx("textarea",{id:n,value:typeof a=="string"?a:JSON.stringify(a,null,2),placeholder:e.placeholder??"{}",disabled:e.disabled,rows:e.rows??6,onChange:d=>{try{s(JSON.parse(d.target.value));}catch{s(d.target.value);}},className:r(Q,"font-mono text-xs resize-y",l&&"border-[var(--dash-error)]")}),o,m]});case "file":return jsxs("div",{children:[c,jsx("input",{id:n,type:"file",accept:e.accept,disabled:e.disabled,onChange:d=>{let v=d.target.files?.[0];v&&s(v);},className:r("w-full text-sm text-[var(--dash-text-muted)]","file:mr-3 file:rounded-[var(--dash-radius-sm)] file:border-0 file:bg-[var(--dash-primary)] file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-[var(--dash-primary-text)]","file:cursor-pointer hover:file:bg-[var(--dash-primary-hover)]")}),o,m]});default:return null}}i(pe,"FieldRenderer");function be({resourceName:e,resourceNamePlural:a,columns:l,data:s,rowKey:n,fields:c,rowToValues:o,onCreate:m,onUpdate:d,onDelete:v,canCreate:D=true,canEdit:C=true,canDelete:R=true,tableProps:b,loading:P=false,className:f}){let x=a??`${e}s`,[u,w]=q.useState("list"),[S,A]=q.useState(null),[G,W]=q.useState({}),[I,z]=q.useState(null),[j,M]=q.useState(false);function J(N){let t=n(N);A(t),W(o?o(N):N),w("edit");}i(J,"handleEdit");function U(N){z(n(N));}i(U,"handleDeleteConfirm");async function X(){if(!(!I||!v)){M(true);try{await v(I);}finally{M(false),z(null);}}}i(X,"confirmDelete");function Y(N){return jsxs("div",{className:"flex items-center justify-end gap-1",children:[C&&d&&jsx("button",{type:"button",onClick:()=>J(N),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-text-muted)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors",children:"Edit"}),R&&v&&jsx("button",{type:"button",onClick:()=>U(N),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-error)] hover:bg-[var(--dash-error-dim)] transition-colors",children:"Delete"})]})}return i(Y,"actionsRenderer"),u==="list"?jsxs("div",{className:r("space-y-4",f),children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("h2",{className:"text-xl font-semibold text-[var(--dash-text)]",children:x}),D&&m&&jsxs("button",{type:"button",onClick:()=>{A(null),W({}),w("create");},className:r("rounded-[var(--dash-radius)] px-3 py-1.5 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]"),children:["Create ",e]})]}),jsx(te,{columns:l,data:s,rowKey:n,actions:C||R?Y:void 0,loading:P,searchable:true,emptyMessage:`No ${x.toLowerCase()} found`,...b}),I!==null&&jsx(fe,{resourceName:e,loading:j,onConfirm:X,onCancel:()=>z(null)})]}):jsxs("div",{className:r("space-y-4",f),children:[jsxs("button",{type:"button",onClick:()=>w("list"),className:"inline-flex items-center gap-1 text-sm text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),"Back to ",x]}),jsx(re,{title:u==="create"?`Create ${e}`:`Edit ${e}`,fields:c,values:u==="edit"?G:void 0,loading:j,submitLabel:u==="create"?"Create":"Save changes",onCancel:()=>w("list"),onSubmit:async N=>{M(true);try{u==="create"&&m?await m(N):u==="edit"&&S&&d&&await d(S,N),w("list");}finally{M(false);}}})]})}i(be,"DashCrud");function fe({resourceName:e,loading:a,onConfirm:l,onCancel:s}){return jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",children:jsxs("div",{className:"w-full max-w-sm rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6 shadow-lg",children:[jsxs("h3",{className:"text-lg font-semibold text-[var(--dash-text)]",children:["Delete ",e,"?"]}),jsxs("p",{className:"mt-2 text-sm text-[var(--dash-text-muted)]",children:["This action cannot be undone. The ",e.toLowerCase()," will be permanently removed."]}),jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[jsx("button",{type:"button",onClick:s,disabled:a,className:r("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:"Cancel"}),jsx("button",{type:"button",onClick:l,disabled:a,className:r("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-error)] text-white","hover:bg-red-600","disabled:opacity-50 disabled:cursor-not-allowed"),children:a?"Deleting...":"Delete"})]})]})})}i(fe,"DeleteDialog");
|
|
3
|
-
export{be as
|
|
2
|
+
import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsxs,jsx}from'react/jsx-runtime';import*as q from'react';var ie=Object.defineProperty;var i=(e,r)=>ie(e,"name",{value:r,configurable:true});function a(...e){return twMerge(clsx(e))}i(a,"cn");function ce({sidebar:e,header:r,children:l,sidebarCollapsed:s=false,onSidebarCollapse:n,className:c}){return jsxs("div",{className:a("flex h-screen overflow-hidden","bg-[var(--dash-bg)] text-[var(--dash-text)]",c),children:[jsx("aside",{className:a("flex-shrink-0 overflow-y-auto overflow-x-hidden transition-[width] duration-200","border-r border-[var(--dash-border)] bg-[var(--dash-surface)]",s?"w-[var(--dash-sidebar-collapsed-width)]":"w-[var(--dash-sidebar-width)]"),children:e}),jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[r&&jsx("header",{className:"flex-shrink-0 border-b border-[var(--dash-border)] bg-[var(--dash-surface)]",children:r}),jsx("main",{className:"flex-1 overflow-y-auto p-6",children:l})]}),!s&&jsx("div",{className:"fixed inset-0 z-40 bg-black/60 lg:hidden",onClick:()=>n?.(true)})]})}i(ce,"Layout");function ue({size:e=28}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M4 4h4v6h8V4h4v16h-4v-6H8v6H4V4z",fill:"currentColor"})})}i(ue,"HanzoMark");function he({logo:e,groups:r,userMenu:l,collapsed:s=false,onToggleCollapse:n,onNavigate:c,className:o}){return jsxs("nav",{className:a("flex h-full flex-col","bg-[var(--dash-surface)] text-[var(--dash-text)]",o),children:[jsxs("div",{className:a("flex h-[var(--dash-header-height)] items-center border-b border-[var(--dash-border)]",s?"justify-center px-2":"px-4"),children:[e??jsx(ue,{}),!s&&n&&jsx("button",{type:"button",onClick:n,className:"ml-auto rounded p-1 text-[var(--dash-text-dim)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]","aria-label":"Collapse sidebar",children:jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),s&&n&&jsx("button",{type:"button",onClick:n,className:"absolute -right-3 top-4 z-50 hidden rounded-full border border-[var(--dash-border)] bg-[var(--dash-surface)] p-1 text-[var(--dash-text-dim)] hover:text-[var(--dash-text)] lg:flex","aria-label":"Expand sidebar",children:jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),jsx("div",{className:"flex-1 overflow-y-auto py-2",children:r.map((m,d)=>jsx(me,{group:m,collapsed:s,onNavigate:c},d))}),l&&jsx("div",{className:"border-t border-[var(--dash-border)] p-2",children:l})]})}i(he,"Sidebar");function me({group:e,collapsed:r,onNavigate:l}){let[s,n]=q.useState(e.defaultOpen!==false),c=e.collapsible!==false&&!!e.title;return jsxs("div",{className:"mb-1",children:[e.title&&!r&&jsxs("button",{type:"button",onClick:()=>c&&n(o=>!o),className:a("flex w-full items-center px-4 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-[var(--dash-text-dim)]",c&&"cursor-pointer hover:text-[var(--dash-text-muted)]"),children:[jsx("span",{className:"flex-1 text-left",children:e.title}),c&&jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",className:a("transition-transform",s?"rotate-0":"-rotate-90"),children:jsx("path",{d:"M4 6l4 4 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),(s||r)&&jsx("ul",{className:"space-y-0.5 px-2",children:e.items.map(o=>jsx("li",{children:jsxs("button",{type:"button",onClick:()=>l?.(o.href),title:r?o.label:void 0,className:a("flex w-full items-center gap-2 rounded-[var(--dash-radius-sm)] px-2 py-1.5 text-sm transition-colors",o.active?"bg-[var(--dash-primary)] text-[var(--dash-primary-text)]":"text-[var(--dash-text-muted)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]",r&&"justify-center px-0"),children:[o.icon&&jsx("span",{className:"flex h-5 w-5 items-center justify-center flex-shrink-0",children:o.icon}),!r&&jsx("span",{className:"flex-1 truncate text-left",children:o.label}),!r&&o.badge!==void 0&&jsx("span",{className:"ml-auto rounded-full bg-[var(--dash-primary)] px-1.5 py-0.5 text-[10px] font-medium text-[var(--dash-primary-text)]",children:o.badge})]})},o.href))})]})}i(me,"SidebarGroup");function ve({breadcrumbs:e,searchPlaceholder:r="Search...",onSearch:l,avatarUrl:s,userName:n,userDropdown:c,onToggleTheme:o,theme:m="dark",actions:d,className:v}){let[C,R]=q.useState(false),S=q.useRef(null);return q.useEffect(()=>{if(!C)return;function b(M){S.current&&!S.current.contains(M.target)&&R(false);}return i(b,"handleClick"),document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[C]),jsxs("div",{className:a("flex h-[var(--dash-header-height)] items-center gap-4 px-4","bg-[var(--dash-surface)] text-[var(--dash-text)]",v),children:[e&&e.length>0&&jsx("nav",{className:"flex items-center gap-1 text-sm","aria-label":"Breadcrumb",children:e.map((b,M)=>jsxs(q.Fragment,{children:[M>0&&jsx("span",{className:"text-[var(--dash-text-dim)]",children:"/"}),b.href?jsx("a",{href:b.href,className:"text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:b.label}):jsx("span",{className:"text-[var(--dash-text)]",children:b.label})]},M))}),jsx("div",{className:"flex-1"}),l&&jsxs("div",{className:"relative hidden sm:block",children:[jsxs("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-[var(--dash-text-dim)]",width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[jsx("circle",{cx:"7",cy:"7",r:"5.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M11 11l3 3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),jsx("input",{type:"text",placeholder:r,onChange:b=>l(b.target.value),className:a("h-8 w-56 rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] pl-8 pr-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","transition-colors")})]}),d,o&&jsx("button",{type:"button",onClick:o,className:"rounded-[var(--dash-radius-sm)] p-1.5 text-[var(--dash-text-dim)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors","aria-label":`Switch to ${m==="dark"?"light":"dark"} mode`,children:m==="dark"?jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[jsx("circle",{cx:"8",cy:"8",r:"3.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M8 1v2M8 13v2M1 8h2M13 8h2M3.05 3.05l1.41 1.41M11.54 11.54l1.41 1.41M3.05 12.95l1.41-1.41M11.54 4.46l1.41-1.41",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M14 9.5A6.5 6.5 0 016.5 2 5.5 5.5 0 1014 9.5z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(s||n)&&jsxs("div",{className:"relative",ref:S,children:[jsx("button",{type:"button",onClick:()=>R(b=>!b),className:"flex items-center gap-2 rounded-[var(--dash-radius-sm)] p-1 hover:bg-[var(--dash-surface-hover)] transition-colors",children:s?jsx("img",{src:s,alt:n??"User",className:"h-7 w-7 rounded-full object-cover"}):jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-[var(--dash-primary)] text-xs font-medium text-[var(--dash-primary-text)]",children:(n??"?")[0].toUpperCase()})}),C&&c&&jsx("div",{className:"absolute right-0 top-full z-50 mt-1 min-w-48 rounded-[var(--dash-radius)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-1 shadow-lg",children:c})]})]})}i(ve,"Header");function te({columns:e,data:r,rowKey:l,selectable:s=false,selectedKeys:n,onSelectionChange:c,searchable:o=false,searchPlaceholder:m="Search...",totalRows:d,page:v=0,pageSize:C=20,onPageChange:R,onPageSizeChange:S,actions:b,loading:M=false,emptyMessage:f="No data",className:x}){let[u,w]=q.useState(""),[L,A]=q.useState(null),G=q.useMemo(()=>{if(!u)return r;let t=u.toLowerCase();return r.filter(k=>e.some(O=>(O.cell?"":String(k[O.id]??"")).toLowerCase().includes(t)))},[r,u,e]),W=q.useMemo(()=>{if(!L)return G;let{column:t,direction:k}=L;return [...G].sort((O,E)=>{let Z=O[t],ee=E[t];if(Z==null&&ee==null)return 0;if(Z==null)return 1;if(ee==null)return -1;let se=String(Z).localeCompare(String(ee),void 0,{numeric:true});return k==="asc"?se:-se})},[G,L]),I=d??W.length,z=Math.max(1,Math.ceil(I/C)),j=R?W:W.slice(v*C,(v+1)*C),F=n??new Set,J=j.length>0&&j.every(t=>F.has(l(t)));function U(){c&&c(J?new Set:new Set(j.map(l)));}i(U,"toggleAll");function X(t){if(!c)return;let k=new Set(F);k.has(t)?k.delete(t):k.add(t),c(k);}i(X,"toggleRow");function Y(t){A(k=>k?.column===t?k.direction==="asc"?{column:t,direction:"desc"}:null:{column:t,direction:"asc"});}i(Y,"handleSort");let N=b?[...e,{id:"__actions",header:"",width:"auto"}]:e;return jsxs("div",{className:a("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)]",x),children:[(o||s)&&jsxs("div",{className:"flex items-center gap-3 border-b border-[var(--dash-border)] px-4 py-3",children:[o&&jsx("input",{type:"text",placeholder:m,value:u,onChange:t=>w(t.target.value),className:a("h-8 w-64 max-w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]")}),s&&F.size>0&&jsxs("span",{className:"text-xs text-[var(--dash-text-muted)]",children:[F.size," selected"]})]}),jsx("div",{className:"overflow-x-auto",children:jsxs("table",{className:"w-full text-sm",children:[jsx("thead",{children:jsxs("tr",{className:"border-b border-[var(--dash-border)]",children:[s&&jsx("th",{className:"w-10 px-4 py-2.5",children:jsx("input",{type:"checkbox",checked:J,onChange:U,className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),N.map(t=>jsx("th",{style:t.width?{width:t.width}:void 0,className:a("px-4 py-2.5 text-[var(--dash-text-dim)] font-medium",t.align==="center"&&"text-center",t.align==="right"&&"text-right",!t.align&&"text-left",t.sortable&&"cursor-pointer select-none hover:text-[var(--dash-text-muted)]"),onClick:t.sortable?()=>Y(t.id):void 0,children:jsxs("span",{className:"inline-flex items-center gap-1",children:[t.header,t.sortable&&L?.column===t.id&&jsx("span",{className:"text-[10px]",children:L.direction==="asc"?"\u2191":"\u2193"})]})},t.id))]})}),jsx("tbody",{children:M?jsx("tr",{children:jsx("td",{colSpan:N.length+(s?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:"Loading..."})}):j.length===0?jsx("tr",{children:jsx("td",{colSpan:N.length+(s?1:0),className:"px-4 py-8 text-center text-[var(--dash-text-dim)]",children:f})}):j.map(t=>{let k=l(t),O=F.has(k);return jsxs("tr",{className:a("border-b border-[var(--dash-border)] transition-colors",O?"bg-[var(--dash-surface-active)]":"hover:bg-[var(--dash-surface-hover)]"),children:[s&&jsx("td",{className:"w-10 px-4 py-2.5",children:jsx("input",{type:"checkbox",checked:O,onChange:()=>X(k),className:"h-4 w-4 rounded border-[var(--dash-border)] accent-[var(--dash-primary)]"})}),e.map(E=>jsx("td",{className:a("px-4 py-2.5",E.align==="center"&&"text-center",E.align==="right"&&"text-right"),children:E.cell?E.cell(t):String(t[E.id]??"")},E.id)),b&&jsx("td",{className:"px-4 py-2.5 text-right",children:b(t)})]},k)})})]})}),z>1&&jsxs("div",{className:"flex items-center justify-between border-t border-[var(--dash-border)] px-4 py-2.5 text-xs text-[var(--dash-text-muted)]",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{children:"Rows per page"}),jsx("select",{value:C,onChange:t=>S?.(Number(t.target.value)),className:"h-7 rounded border border-[var(--dash-border)] bg-[var(--dash-bg)] px-2 text-xs text-[var(--dash-text)] focus:outline-none",children:[10,20,50,100].map(t=>jsx("option",{value:t,children:t},t))})]}),jsxs("div",{className:"flex items-center gap-2",children:[jsxs("span",{children:["Page ",v+1," of ",z]}),jsx("button",{type:"button",disabled:v===0,onClick:()=>R?.(v-1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("button",{type:"button",disabled:v>=z-1,onClick:()=>R?.(v+1),className:"rounded p-1 hover:bg-[var(--dash-surface-hover)] disabled:opacity-30 disabled:cursor-not-allowed",children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M6 4l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})]})}i(te,"Table");function ae({title:e,fields:r,values:l,onSubmit:s,onCancel:n,submitLabel:c="Save",cancelLabel:o="Cancel",loading:m=false,className:d}){let[v,C]=q.useState(()=>{let f={};for(let x of r)f[x.name]=l?.[x.name]??x.defaultValue??(x.type==="toggle"?false:"");return f}),[R,S]=q.useState({});function b(f,x){C(u=>({...u,[f]:x})),S(u=>{if(!u[f])return u;let w={...u};return delete w[f],w});}i(b,"setValue");async function M(f){f.preventDefault();let x={};for(let u of r){let w=v[u.name];if(u.required&&(w===""||w===null||w===void 0)&&(x[u.name]=`${u.label} is required`),u.validate){let L=u.validate(w);L&&(x[u.name]=L);}}if(Object.keys(x).length>0){S(x);return}await s(v);}return i(M,"handleSubmit"),jsxs("form",{onSubmit:M,className:a("rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6",d),children:[e&&jsx("h3",{className:"mb-4 text-lg font-semibold text-[var(--dash-text)]",children:e}),jsx("div",{className:"space-y-4",children:r.map(f=>jsx(pe,{field:f,value:v[f.name],error:R[f.name],onChange:x=>b(f.name,x)},f.name))}),jsxs("div",{className:"mt-6 flex items-center gap-3",children:[jsx("button",{type:"submit",disabled:m,className:a("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]","disabled:opacity-50 disabled:cursor-not-allowed"),children:m?"Saving...":c}),n&&jsx("button",{type:"button",onClick:n,disabled:m,className:a("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:o})]})]})}i(ae,"Form");var Q=a("w-full rounded-[var(--dash-radius-sm)] border border-[var(--dash-border)] bg-[var(--dash-bg)] px-3 py-2 text-sm text-[var(--dash-text)]","placeholder:text-[var(--dash-text-dim)]","focus:border-[var(--dash-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--dash-primary)]","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors");function pe({field:e,value:r,error:l,onChange:s}){let n=`dash-field-${e.name}`,c=jsxs("label",{htmlFor:n,className:"mb-1 block text-sm font-medium text-[var(--dash-text)]",children:[e.label,e.required&&jsx("span",{className:"ml-0.5 text-[var(--dash-error)]",children:"*"})]}),o=e.description?jsx("p",{className:"mt-1 text-xs text-[var(--dash-text-dim)]",children:e.description}):null,m=l?jsx("p",{className:"mt-1 text-xs text-[var(--dash-error)]",children:l}):null;switch(e.type){case "text":case "email":case "password":case "number":return jsxs("div",{children:[c,jsx("input",{id:n,type:e.type,value:String(r??""),placeholder:e.placeholder,disabled:e.disabled,onChange:d=>s(e.type==="number"?Number(d.target.value):d.target.value),className:a(Q,l&&"border-[var(--dash-error)]")}),o,m]});case "textarea":return jsxs("div",{children:[c,jsx("textarea",{id:n,value:String(r??""),placeholder:e.placeholder,disabled:e.disabled,rows:e.rows??3,onChange:d=>s(d.target.value),className:a(Q,"resize-y",l&&"border-[var(--dash-error)]")}),o,m]});case "select":case "relation":return jsxs("div",{children:[c,jsxs("select",{id:n,value:String(r??""),disabled:e.disabled,onChange:d=>s(d.target.value),className:a(Q,l&&"border-[var(--dash-error)]"),children:[jsx("option",{value:"",children:e.placeholder??"Select..."}),(e.options??[]).map(d=>jsx("option",{value:d.value,children:d.label},d.value))]}),o,m]});case "toggle":return jsxs("div",{className:"flex items-center gap-3",children:[jsx("button",{id:n,type:"button",role:"switch","aria-checked":!!r,disabled:e.disabled,onClick:()=>s(!r),className:a("relative inline-flex h-5 w-9 flex-shrink-0 rounded-full transition-colors","focus:outline-none focus:ring-2 focus:ring-[var(--dash-primary)] focus:ring-offset-2 focus:ring-offset-[var(--dash-surface)]",r?"bg-[var(--dash-primary)]":"bg-[var(--dash-border)]",e.disabled&&"opacity-50 cursor-not-allowed"),children:jsx("span",{className:a("pointer-events-none inline-block h-4 w-4 rounded-full bg-white shadow transition-transform",r?"translate-x-4":"translate-x-0.5","mt-0.5")})}),jsx("label",{htmlFor:n,className:"text-sm text-[var(--dash-text)]",children:e.label}),o,m]});case "json":return jsxs("div",{children:[c,jsx("textarea",{id:n,value:typeof r=="string"?r:JSON.stringify(r,null,2),placeholder:e.placeholder??"{}",disabled:e.disabled,rows:e.rows??6,onChange:d=>{try{s(JSON.parse(d.target.value));}catch{s(d.target.value);}},className:a(Q,"font-mono text-xs resize-y",l&&"border-[var(--dash-error)]")}),o,m]});case "file":return jsxs("div",{children:[c,jsx("input",{id:n,type:"file",accept:e.accept,disabled:e.disabled,onChange:d=>{let v=d.target.files?.[0];v&&s(v);},className:a("w-full text-sm text-[var(--dash-text-muted)]","file:mr-3 file:rounded-[var(--dash-radius-sm)] file:border-0 file:bg-[var(--dash-primary)] file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-[var(--dash-primary-text)]","file:cursor-pointer hover:file:bg-[var(--dash-primary-hover)]")}),o,m]});default:return null}}i(pe,"FieldRenderer");function be({resourceName:e,resourceNamePlural:r,columns:l,data:s,rowKey:n,fields:c,rowToValues:o,onCreate:m,onUpdate:d,onDelete:v,canCreate:C=true,canEdit:R=true,canDelete:S=true,tableProps:b,loading:M=false,className:f}){let x=r??`${e}s`,[u,w]=q.useState("list"),[L,A]=q.useState(null),[G,W]=q.useState({}),[I,z]=q.useState(null),[j,F]=q.useState(false);function J(N){let t=n(N);A(t),W(o?o(N):N),w("edit");}i(J,"handleEdit");function U(N){z(n(N));}i(U,"handleDeleteConfirm");async function X(){if(!(!I||!v)){F(true);try{await v(I);}finally{F(false),z(null);}}}i(X,"confirmDelete");function Y(N){return jsxs("div",{className:"flex items-center justify-end gap-1",children:[R&&d&&jsx("button",{type:"button",onClick:()=>J(N),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-text-muted)] hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)] transition-colors",children:"Edit"}),S&&v&&jsx("button",{type:"button",onClick:()=>U(N),className:"rounded-[var(--dash-radius-sm)] px-2 py-1 text-xs text-[var(--dash-error)] hover:bg-[var(--dash-error-dim)] transition-colors",children:"Delete"})]})}return i(Y,"actionsRenderer"),u==="list"?jsxs("div",{className:a("space-y-4",f),children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("h2",{className:"text-xl font-semibold text-[var(--dash-text)]",children:x}),C&&m&&jsxs("button",{type:"button",onClick:()=>{A(null),W({}),w("create");},className:a("rounded-[var(--dash-radius)] px-3 py-1.5 text-sm font-medium transition-colors","bg-[var(--dash-primary)] text-[var(--dash-primary-text)]","hover:bg-[var(--dash-primary-hover)]"),children:["Create ",e]})]}),jsx(te,{columns:l,data:s,rowKey:n,actions:R||S?Y:void 0,loading:M,searchable:true,emptyMessage:`No ${x.toLowerCase()} found`,...b}),I!==null&&jsx(fe,{resourceName:e,loading:j,onConfirm:X,onCancel:()=>z(null)})]}):jsxs("div",{className:a("space-y-4",f),children:[jsxs("button",{type:"button",onClick:()=>w("list"),className:"inline-flex items-center gap-1 text-sm text-[var(--dash-text-muted)] hover:text-[var(--dash-text)] transition-colors",children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:jsx("path",{d:"M10 4L6 8l4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),"Back to ",x]}),jsx(ae,{title:u==="create"?`Create ${e}`:`Edit ${e}`,fields:c,values:u==="edit"?G:void 0,loading:j,submitLabel:u==="create"?"Create":"Save changes",onCancel:()=>w("list"),onSubmit:async N=>{F(true);try{u==="create"&&m?await m(N):u==="edit"&&L&&d&&await d(L,N),w("list");}finally{F(false);}}})]})}i(be,"Crud");function fe({resourceName:e,loading:r,onConfirm:l,onCancel:s}){return jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",children:jsxs("div",{className:"w-full max-w-sm rounded-[var(--dash-radius-lg)] border border-[var(--dash-border)] bg-[var(--dash-surface)] p-6 shadow-lg",children:[jsxs("h3",{className:"text-lg font-semibold text-[var(--dash-text)]",children:["Delete ",e,"?"]}),jsxs("p",{className:"mt-2 text-sm text-[var(--dash-text-muted)]",children:["This action cannot be undone. The ",e.toLowerCase()," will be permanently removed."]}),jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[jsx("button",{type:"button",onClick:s,disabled:r,className:a("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","border border-[var(--dash-border)] text-[var(--dash-text-muted)]","hover:bg-[var(--dash-surface-hover)] hover:text-[var(--dash-text)]"),children:"Cancel"}),jsx("button",{type:"button",onClick:l,disabled:r,className:a("rounded-[var(--dash-radius)] px-4 py-2 text-sm font-medium transition-colors","bg-[var(--dash-error)] text-white","hover:bg-red-600","disabled:opacity-50 disabled:cursor-not-allowed"),children:r?"Deleting...":"Delete"})]})]})})}i(fe,"DeleteDialog");
|
|
3
|
+
export{be as Crud,ae as Form,ve as Header,ce as Layout,he as Sidebar,te as Table};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');var n=Object.defineProperty;var r=(e,a)=>n(e,"name",{value:a,configurable:true});function
|
|
2
|
+
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');var n=Object.defineProperty;var r=(e,a)=>n(e,"name",{value:a,configurable:true});function d(...e){return tailwindMerge.twMerge(clsx.clsx(e))}r(d,"cn");function N({sidebar:e,header:a,children:t,sidebarCollapsed:s=false,onSidebarCollapse:i,className:c}){return jsxRuntime.jsxs("div",{className:d("flex h-screen overflow-hidden","bg-[var(--dash-bg)] text-[var(--dash-text)]",c),children:[jsxRuntime.jsx("aside",{className:d("flex-shrink-0 overflow-y-auto overflow-x-hidden transition-[width] duration-200","border-r border-[var(--dash-border)] bg-[var(--dash-surface)]",s?"w-[var(--dash-sidebar-collapsed-width)]":"w-[var(--dash-sidebar-width)]"),children:e}),jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[a&&jsxRuntime.jsx("header",{className:"flex-shrink-0 border-b border-[var(--dash-border)] bg-[var(--dash-surface)]",children:a}),jsxRuntime.jsx("main",{className:"flex-1 overflow-y-auto p-6",children:t})]}),!s&&jsxRuntime.jsx("div",{className:"fixed inset-0 z-40 bg-black/60 lg:hidden",onClick:()=>i?.(true)})]})}r(N,"Layout");exports.Layout=N;
|