db-studio 1.7.11 → 1.7.12

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.
Files changed (25) hide show
  1. package/dist/core-dist/assets/_pathlessLayout-XL9BaZh5.js +2 -0
  2. package/dist/core-dist/assets/{_queryId-BuwY4WmY.js → _queryId-CAjVLs-F.js} +1 -1
  3. package/dist/core-dist/assets/{_table-D8MYcfMf.js → _table-BI_XiC1K.js} +1 -1
  4. package/dist/core-dist/assets/_table-DKnSwqFc.js +10 -0
  5. package/dist/core-dist/assets/{cdoe-editor-DT99U124.js → cdoe-editor-Lwkji0wU.js} +1 -1
  6. package/dist/core-dist/assets/{chat-sidebar-_z_c1b34.js → chat-sidebar-DTwB3fym.js} +2 -2
  7. package/dist/core-dist/assets/{dist-lZgQTehN.js → dist-C6mIPWhR.js} +1 -1
  8. package/dist/core-dist/assets/{dist-DZQDOYlI.js → dist-UBwYqP_w.js} +1 -1
  9. package/dist/core-dist/assets/index-B8u-3J3b.js +57 -0
  10. package/dist/core-dist/assets/index-Bv_0Afnk.css +2 -0
  11. package/dist/core-dist/assets/{queries.store-D-hvraJW.js → queries.store-BTgqNNws.js} +1 -1
  12. package/dist/core-dist/assets/{runner-D2QKCRKR.js → runner-CJikZjx7.js} +1 -1
  13. package/dist/core-dist/assets/{runner-tab-BgDrAAsO.js → runner-tab-CSDL4L8O.js} +3 -3
  14. package/dist/core-dist/assets/{scroll-area-XVOss7Ty.js → scroll-area-CnrU1Pgb.js} +1 -1
  15. package/dist/core-dist/assets/{tooltip-CFEia1PZ.js → tooltip-DttVuH4f.js} +1 -1
  16. package/dist/core-dist/assets/{use-delete-column-B78zy_1_.js → use-delete-column-CA96Lesz.js} +1 -1
  17. package/dist/core-dist/assets/{use-rate-limit-FcN06qzk.js → use-rate-limit-B1ivFudi.js} +1 -1
  18. package/dist/core-dist/index.html +2 -2
  19. package/dist/index.js +1 -1
  20. package/dist/index.js.map +1 -1
  21. package/package.json +1 -1
  22. package/dist/core-dist/assets/_pathlessLayout-DtaYfYwJ.js +0 -2
  23. package/dist/core-dist/assets/_table-dqCYe5jr.js +0 -10
  24. package/dist/core-dist/assets/index-D9Wxg2ot.js +0 -57
  25. package/dist/core-dist/assets/index-fMzwkmHJ.css +0 -2
@@ -1,2 +1,2 @@
1
- import{r as ge}from"./rolldown-runtime-Bnw7wDfq.js";import{o as xe,s as ve}from"./tanstack-CJpNvQIy.js";import{G as Te,N as be,Y as je,b as Se,c as Ce,m as ye,nt as we,t as Ne,tt as ke}from"./icons-BywMJ5og.js";import{Ct as J,F as Re,I as Ee,Ot as Ae,P as Le,Tt as Be}from"./radix-ui-C0u6gLux.js";import{Dt as y,G as De,J as Ie,K as Pe,Tt as H,q as _e,st as ze,ut as Me,vt as Fe,x as Ue}from"./index-D9Wxg2ot.js";import{r as ee}from"./chunk-BO2N2NFS-BWASkQ7r.js";import{n as Oe,t as qe}from"./scroll-area-XVOss7Ty.js";import{i as Ge,n as He,t as We}from"./tooltip-CFEia1PZ.js";import{t as te}from"./use-rate-limit-FcN06qzk.js";var Ke=["Show me all tables in my database","What columns are in the users table?","Write a query to find all active users","How many orders were placed last month?","Find top 5 customers by total spend","Write a JOIN between users and orders","Users who haven't made any purchase yet","Generate monthly revenue summary query","Suggest useful indexes for better performance","Show schema of the products / inventory table","Latest 20 orders with customer names","Help me write a safe UPDATE query"],s=ge(we(),1),Je={damping:.7,stiffness:.05,mass:1.25},Ve=70,Xe=1e3/60,Ye=350,F=!1;globalThis.document?.addEventListener("mousedown",()=>{F=!0});globalThis.document?.addEventListener("mouseup",()=>{F=!1});globalThis.document?.addEventListener("click",()=>{F=!1});var $e=(r={})=>{const[n,o]=(0,s.useState)(!1),[l,a]=(0,s.useState)(r.initial!==!1),[m,h]=(0,s.useState)(!1),g=(0,s.useRef)(null);g.current=r;const v=(0,s.useCallback)(()=>{if(!F)return!1;const c=window.getSelection();if(!c||!c.rangeCount)return!1;const d=c.getRangeAt(0);return d.commonAncestorContainer.contains(i.current)||i.current?.contains(d.commonAncestorContainer)},[]),x=(0,s.useCallback)(c=>{e.isAtBottom=c,a(c)},[]),S=(0,s.useCallback)(c=>{e.escapedFromLock=c,o(c)},[]),e=(0,s.useMemo)(()=>{let c;return{escapedFromLock:n,isAtBottom:l,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return i.current?.scrollTop??0},set scrollTop(d){i.current&&(i.current.scrollTop=d,e.ignoreScrollToTop=i.current.scrollTop)},get targetScrollTop(){return!i.current||!j.current?0:i.current.scrollHeight-1-i.current.clientHeight},get calculatedTargetScrollTop(){if(!i.current||!j.current)return 0;const{targetScrollTop:d}=this;if(!r.targetScrollTop)return d;if(c?.targetScrollTop===d)return c.calculatedScrollTop;const f=Math.max(Math.min(r.targetScrollTop(d,{scrollElement:i.current,contentElement:j.current}),d),0);return c={targetScrollTop:d,calculatedScrollTop:f},requestAnimationFrame(()=>{c=void 0}),f},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=Ve}}},[]),u=(0,s.useCallback)((c={})=>{typeof c=="string"&&(c={animation:c}),c.preserveScrollPosition||x(!0);const d=Date.now()+(Number(c.wait)||0),f=G(g.current,c.animation),{ignoreEscapes:R=!1}=c;let L,B=e.calculatedTargetScrollTop;c.duration instanceof Promise?c.duration.finally(()=>{L=Date.now()}):L=d+(c.duration??0);const E=async()=>{const _=new Promise(requestAnimationFrame).then(()=>{if(!e.isAtBottom)return e.animation=void 0,!1;const{scrollTop:D}=e,P=performance.now(),U=(P-(e.lastTick??P))/Xe;if(e.animation||(e.animation={behavior:f,promise:_,ignoreEscapes:R}),e.animation.behavior===f&&(e.lastTick=P),v()||d>Date.now())return E();if(D<Math.min(B,e.calculatedTargetScrollTop)){if(e.animation?.behavior===f){if(f==="instant")return e.scrollTop=e.calculatedTargetScrollTop,E();e.velocity=(f.damping*e.velocity+f.stiffness*e.scrollDifference)/f.mass,e.accumulated+=e.velocity*U,e.scrollTop+=e.accumulated,e.scrollTop!==D&&(e.accumulated=0)}return E()}return L>Date.now()?(B=e.calculatedTargetScrollTop,E()):(e.animation=void 0,e.scrollTop<e.calculatedTargetScrollTop?u({animation:G(g.current,g.current.resize),ignoreEscapes:R,duration:Math.max(0,L-Date.now())||void 0}):e.isAtBottom)});return _.then(D=>(requestAnimationFrame(()=>{e.animation||(e.lastTick=void 0,e.velocity=0)}),D))};return c.wait!==!0&&(e.animation=void 0),e.animation?.behavior===f?e.animation.promise:E()},[x,v,e]),w=(0,s.useCallback)(()=>{S(!0),x(!1)},[S,x]),N=(0,s.useCallback)(({target:c})=>{if(c!==i.current)return;const{scrollTop:d,ignoreScrollToTop:f}=e;let{lastScrollTop:R=d}=e;e.lastScrollTop=d,e.ignoreScrollToTop=void 0,f&&f>d&&(R=f),h(e.isNearBottom),setTimeout(()=>{if(e.resizeDifference||d===f)return;if(v()){S(!0),x(!1);return}const L=d>R,B=d<R;if(e.animation?.ignoreEscapes){e.scrollTop=R;return}B&&(S(!0),x(!1)),L&&S(!1),!e.escapedFromLock&&e.isNearBottom&&x(!0)},1)},[S,x,v,e]),k=(0,s.useCallback)(({target:c,deltaY:d})=>{let f=c;for(;!["scroll","auto"].includes(getComputedStyle(f).overflow);){if(!f.parentElement)return;f=f.parentElement}f===i.current&&d<0&&i.current.scrollHeight>i.current.clientHeight&&!e.animation?.ignoreEscapes&&(S(!0),x(!1))},[S,x,e]),i=V(c=>{i.current?.removeEventListener("scroll",N),i.current?.removeEventListener("wheel",k),c?.addEventListener("scroll",N,{passive:!0}),c?.addEventListener("wheel",k,{passive:!0})},[]),j=V(c=>{if(e.resizeObserver?.disconnect(),!c)return;let d;e.resizeObserver=new ResizeObserver(([f])=>{const{height:R}=f.contentRect,L=R-(d??R);if(e.resizeDifference=L,e.scrollTop>e.targetScrollTop&&(e.scrollTop=e.targetScrollTop),h(e.isNearBottom),L>=0){const B=G(g.current,d?g.current.resize:g.current.initial);u({animation:B,wait:!0,preserveScrollPosition:!0,duration:B==="instant"?void 0:Ye})}else e.isNearBottom&&(S(!1),x(!0));d=R,requestAnimationFrame(()=>{setTimeout(()=>{e.resizeDifference===L&&(e.resizeDifference=0)},1)})}),e.resizeObserver?.observe(c)},[]);return{contentRef:j,scrollRef:i,scrollToBottom:u,stopScroll:w,isAtBottom:l||m,isNearBottom:m,escapedFromLock:n,state:e}};function V(r,n){const o=(0,s.useCallback)(l=>(o.current=l,r(l)),n);return o}var q=new Map;function G(...r){const n={...Je};let o=!1;for(const a of r){if(a==="instant"){o=!0;continue}typeof a=="object"&&(o=!1,n.damping=a.damping??n.damping,n.stiffness=a.stiffness??n.stiffness,n.mass=a.mass??n.mass)}const l=JSON.stringify(n);return q.has(l)||q.set(l,Object.freeze(n)),o?"instant":q.get(l)}var t=Ae(),re=(0,s.createContext)(null),Qe=typeof window<"u"?s.useLayoutEffect:s.useEffect;function M({instance:r,children:n,resize:o,initial:l,mass:a,damping:m,stiffness:h,targetScrollTop:g,contextRef:v,...x}){const S=(0,s.useRef)(null),e=$e({mass:a,damping:m,stiffness:h,resize:o,initial:l,targetScrollTop:s.useCallback((f,R)=>(d?.targetScrollTop??g)?.(f,R)??f,[g])}),{scrollRef:u,contentRef:w,scrollToBottom:N,stopScroll:k,isAtBottom:i,escapedFromLock:j,state:c}=r??e,d=(0,s.useMemo)(()=>({scrollToBottom:N,stopScroll:k,scrollRef:u,isAtBottom:i,escapedFromLock:j,contentRef:w,state:c,get targetScrollTop(){return S.current},set targetScrollTop(f){S.current=f}}),[N,i,w,u,k,j,c]);return(0,s.useImperativeHandle)(v,()=>d,[d]),Qe(()=>{u.current&&getComputedStyle(u.current).overflow==="visible"&&(u.current.style.overflow="auto")},[]),(0,t.jsx)(re.Provider,{value:d,children:(0,t.jsx)("div",{...x,children:typeof n=="function"?n(d):n})})}(function(r){function n({children:o,...l}){const a=ne();return(0,t.jsx)("div",{ref:a.scrollRef,style:{height:"100%",width:"100%"},children:(0,t.jsx)("div",{...l,ref:a.contentRef,children:typeof o=="function"?o(a):o})})}r.Content=n})(M||(M={}));function ne(){const r=(0,s.useContext)(re);if(!r)throw new Error("use-stick-to-bottom component context must be used within a StickToBottom component");return r}var Ze=({className:r,...n})=>(0,t.jsx)(M,{className:y("relative flex-1 overflow-y-hidden",r),initial:"smooth",resize:"smooth",role:"log",...n}),et=({className:r,...n})=>(0,t.jsx)(M.Content,{className:y("flex flex-col gap-8 p-4",r),...n}),tt=({className:r,...n})=>{const{isAtBottom:o,scrollToBottom:l}=ne(),a=(0,s.useCallback)(()=>{l()},[l]);return!o&&(0,t.jsx)(H,{className:y("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",r),onClick:a,size:"icon",type:"button",variant:"outline",...n,children:(0,t.jsx)(ke,{className:"size-4"})})},X=[{variant:"shine",component:({children:r,className:n,...o})=>(0,t.jsx)("span",{...o,className:y("bg-[linear-gradient(110deg,#bfbfbf,35%,#000,50%,#bfbfbf,75%,#bfbfbf)] dark:bg-[linear-gradient(110deg,#404040,35%,#fff,50%,#404040,75%,#404040)]","bg-size-[200%_100%] bg-clip-text text-transparent","animate-shine",n),children:r})}];function rt({variant:r="shine",className:n,...o}){const l=X.find(a=>a.variant===r)?.component||X[0].component;return(0,t.jsx)(Be,{className:y("font-medium text-sm"),children:(0,t.jsx)(l,{...o,className:n})})}var Y=({className:r,from:n,...o})=>(0,t.jsx)("div",{className:y("group flex w-full max-w-[95%] flex-col gap-2",n==="user"?"is-user ml-auto justify-end":"is-assistant",r),...o}),$=({children:r,className:n,...o})=>(0,t.jsx)("div",{className:y("is-user:dark flex w-fit max-w-full min-w-0 flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",n),...o,children:r}),se=(0,s.createContext)(null),nt=()=>{const r=(0,s.useContext)(se);if(!r)throw new Error("MessageBranch components must be used within MessageBranch");return r},Q=({defaultBranch:r=0,onBranchChange:n,className:o,...l})=>{const[a,m]=(0,s.useState)(r),[h,g]=(0,s.useState)([]),v=u=>{m(u),n?.(u)},x=()=>{v(a>0?a-1:h.length-1)},S=()=>{v(a<h.length-1?a+1:0)},e={currentBranch:a,totalBranches:h.length,goToPrevious:x,goToNext:S,branches:h,setBranches:g};return(0,t.jsx)(se.Provider,{value:e,children:(0,t.jsx)("div",{className:y("grid w-full gap-2 [&>div]:pb-0",o),...l})})},Z=({children:r,...n})=>{const{currentBranch:o,setBranches:l,branches:a}=nt(),m=Array.isArray(r)?r:[r];return(0,s.useEffect)(()=>{a.length!==m.length&&l(m)},[m,a,l]),m.map((h,g)=>(0,t.jsx)("div",{className:y("grid gap-2 overflow-hidden [&>div]:pb-0",g===o?"block":"hidden"),...n,children:h},h.key))},oe=(0,s.memo)(({className:r,...n})=>(0,t.jsx)(ee,{className:y("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",r),...n}),(r,n)=>r.children===n.children);oe.displayName="MessageResponse";var st="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",ot=(r=21)=>{let n="",o=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)n+=st[o[r]&63];return n},at=(0,s.createContext)(null),it=(0,s.createContext)(null),ae=()=>(0,s.useContext)(at),lt=()=>(0,s.useContext)(it),ie=(0,s.createContext)(null),ct=()=>{const r=lt(),n=(0,s.useContext)(ie),o=r??n;if(!o)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return o},ut=({className:r,accept:n,multiple:o,globalDrop:l,syncHiddenInput:a,maxFiles:m,maxFileSize:h,onError:g,onSubmit:v,children:x,...S})=>{const e=ae(),u=!!e,w=(0,s.useRef)(null),N=(0,s.useRef)(null),[k,i]=(0,s.useState)([]),j=u?e.attachments.files:k,c=(0,s.useRef)(j);c.current=j;const d=(0,s.useCallback)(()=>{w.current?.click()},[]),f=(0,s.useCallback)(p=>!n||n.trim()===""?!0:n.split(",").map(T=>T.trim()).filter(Boolean).some(T=>{if(T.endsWith("/*")){const b=T.slice(0,-1);return p.type.startsWith(b)}return p.type===T}),[n]),R=(0,s.useCallback)(p=>{const T=Array.from(p),b=T.filter(I=>f(I));if(T.length&&b.length===0){g?.({code:"accept",message:"No files match the accepted types."});return}const C=I=>h?I.size<=h:!0,A=b.filter(C);if(b.length>0&&A.length===0){g?.({code:"max_file_size",message:"All files exceed the maximum size."});return}i(I=>{const z=typeof m=="number"?Math.max(0,m-I.length):void 0,he=typeof z=="number"?A.slice(0,z):A;typeof z=="number"&&A.length>z&&g?.({code:"max_files",message:"Too many files. Some were not added."});const K=[];for(const O of he)K.push({id:ot(),type:"file",url:URL.createObjectURL(O),mediaType:O.type,filename:O.name});return I.concat(K)})},[f,m,h,g]),L=(0,s.useCallback)(p=>i(T=>{const b=T.find(C=>C.id===p);return b?.url&&URL.revokeObjectURL(b.url),T.filter(C=>C.id!==p)}),[]),B=(0,s.useCallback)(()=>i(p=>{for(const T of p)T.url&&URL.revokeObjectURL(T.url);return[]}),[]),E=u?e.attachments.add:R,_=u?e.attachments.remove:L,D=u?e.attachments.clear:B,P=u?e.attachments.openFileDialog:d;(0,s.useEffect)(()=>{u&&e.__registerFileInput(w,()=>w.current?.click())},[u,e]),(0,s.useEffect)(()=>{a&&w.current&&j.length===0&&(w.current.value="")},[j,a]),(0,s.useEffect)(()=>{const p=N.current;if(!p||l)return;const T=C=>{C.dataTransfer?.types?.includes("Files")&&C.preventDefault()},b=C=>{C.dataTransfer?.types?.includes("Files")&&C.preventDefault(),C.dataTransfer?.files&&C.dataTransfer.files.length>0&&E(C.dataTransfer.files)};return p.addEventListener("dragover",T),p.addEventListener("drop",b),()=>{p.removeEventListener("dragover",T),p.removeEventListener("drop",b)}},[E,l]),(0,s.useEffect)(()=>{if(!l)return;const p=b=>{b.dataTransfer?.types?.includes("Files")&&b.preventDefault()},T=b=>{b.dataTransfer?.types?.includes("Files")&&b.preventDefault(),b.dataTransfer?.files&&b.dataTransfer.files.length>0&&E(b.dataTransfer.files)};return document.addEventListener("dragover",p),document.addEventListener("drop",T),()=>{document.removeEventListener("dragover",p),document.removeEventListener("drop",T)}},[E,l]),(0,s.useEffect)(()=>()=>{if(!u)for(const p of c.current)p.url&&URL.revokeObjectURL(p.url)},[u]);const U=p=>{p.currentTarget.files&&E(p.currentTarget.files),p.currentTarget.value=""},me=async p=>{try{const T=await(await fetch(p)).blob();return new Promise(b=>{const C=new FileReader;C.onloadend=()=>b(C.result),C.onerror=()=>b(null),C.readAsDataURL(T)})}catch{return null}},de=(0,s.useMemo)(()=>({files:j.map(p=>({...p,id:p.id})),add:E,remove:_,clear:D,openFileDialog:P,fileInputRef:w}),[j,E,_,D,P]),pe=p=>{p.preventDefault();const T=p.currentTarget,b=u?e.textInput.value:new FormData(T).get("message")||"";u||T.reset(),Promise.all(j.map(async({id:C,...A})=>{if(A.url?.startsWith("blob:")){const I=await me(A.url);return{...A,url:I??A.url}}return A})).then(C=>{try{const A=v({text:b,files:C},p);A instanceof Promise?A.then(()=>{D(),u&&e.textInput.clear()}).catch(()=>{}):(D(),u&&e.textInput.clear())}catch{}}).catch(()=>{})},W=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("input",{accept:n,"aria-label":"Upload files",className:"hidden",multiple:o,onChange:U,ref:w,title:"Upload files",type:"file"}),(0,t.jsx)("form",{className:y("w-full",r),onSubmit:pe,ref:N,...S,children:(0,t.jsx)(De,{className:"overflow-hidden",children:x})})]});return u?W:(0,t.jsx)(ie.Provider,{value:de,children:W})},ft=({className:r,...n})=>(0,t.jsx)("div",{className:y("contents",r),...n}),mt=({onChange:r,className:n,placeholder:o="What would you like to know?",...l})=>{const a=ae(),m=ct(),[h,g]=(0,s.useState)(!1),v=e=>{if(e.key==="Enter"){if(h||e.nativeEvent.isComposing||e.shiftKey)return;e.preventDefault();const u=e.currentTarget.form;if(u?.querySelector('button[type="submit"]')?.disabled)return;u?.requestSubmit()}if(e.key==="Backspace"&&e.currentTarget.value===""&&m.files.length>0){e.preventDefault();const u=m.files.at(-1);u&&m.remove(u.id)}},x=e=>{const u=e.clipboardData?.items;if(!u)return;const w=[];for(const N of u)if(N.kind==="file"){const k=N.getAsFile();k&&w.push(k)}w.length>0&&(e.preventDefault(),m.add(w))},S=a?{value:a.textInput.value,onChange:e=>{a.textInput.setInput(e.currentTarget.value),r?.(e)}}:{onChange:r};return(0,t.jsx)(Ie,{className:y("field-sizing-content max-h-48 min-h-16",n),name:"message",onCompositionEnd:()=>g(!1),onCompositionStart:()=>g(!0),onKeyDown:v,onPaste:x,placeholder:o,...l,...S})},dt=({className:r,...n})=>(0,t.jsx)(Pe,{align:"block-end",className:y("justify-between justify-end gap-1",r),...n}),pt=({className:r,variant:n="default",size:o="icon-sm",status:l,children:a,...m})=>{let h=(0,t.jsx)(be,{className:"size-4"});return l==="submitted"?h=(0,t.jsx)(Se,{className:"size-4 animate-spin"}):l==="streaming"?h=(0,t.jsx)(Ce,{className:"size-4"}):l==="error"&&(h=(0,t.jsx)(Ne,{className:"size-4"})),(0,t.jsx)(_e,{"aria-label":"Submit",className:y(r),size:o,type:"submit",variant:n,...m,children:a??h})};function ht({...r}){return(0,t.jsx)(Re,{"data-slot":"collapsible",...r})}function gt({...r}){return(0,t.jsx)(Ee,{"data-slot":"collapsible-trigger",...r})}function xt({...r}){return(0,t.jsx)(Le,{"data-slot":"collapsible-content",...r})}var vt=({children:r,as:n="p",className:o,duration:l=2,spread:a=2})=>{const m=(0,s.useMemo)(()=>(r?.length??0)*a,[r,a]);return(0,t.jsx)(n,{className:y("relative inline-block bg-size-[250%_100%,auto] bg-clip-text text-transparent","[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]","animate-shimmer",o),style:{"--spread":`${m}px`,"--duration":`${l}s`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},children:r})},Tt=(0,s.memo)(vt),le=(0,s.createContext)(null),bt=()=>{const r=(0,s.useContext)(le);if(!r)throw new Error("Reasoning components must be used within Reasoning");return r},jt=1e3,St=1e3,ce=(0,s.memo)(({className:r,isStreaming:n=!1,open:o,defaultOpen:l=!0,onOpenChange:a,duration:m,children:h,...g})=>{const[v,x]=J({prop:o,defaultProp:l,onChange:a}),[S,e]=J({prop:m,defaultProp:void 0}),[u,w]=(0,s.useState)(!1),[N,k]=(0,s.useState)(null);(0,s.useEffect)(()=>{n?N===null&&k(Date.now()):N!==null&&(e(Math.ceil((Date.now()-N)/St)),k(null))},[n,N,e]),(0,s.useEffect)(()=>{if(l&&!n&&v&&!u){const j=setTimeout(()=>{x(!1),w(!0)},jt);return()=>clearTimeout(j)}},[n,v,l,x,u]);const i=j=>{x(j)};return(0,t.jsx)(le.Provider,{value:{isStreaming:n,isOpen:v,setIsOpen:x,duration:S},children:(0,t.jsx)(ht,{className:y("not-prose mb-4",r),onOpenChange:i,open:v,...g,children:h})})}),Ct=(r,n)=>r||n===0?(0,t.jsx)(Tt,{duration:1,children:"Thinking..."}):n===void 0?(0,t.jsx)("p",{children:"Thought for a few seconds"}):(0,t.jsxs)("p",{children:["Thought for ",n," seconds"]}),ue=(0,s.memo)(({className:r,children:n,getThinkingMessage:o=Ct,...l})=>{const{isStreaming:a,isOpen:m,duration:h}=bt();return(0,t.jsx)(gt,{className:y("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",r),...l,children:n??(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(je,{className:"size-4"}),o(a,h),(0,t.jsx)(Te,{className:y("size-4 transition-transform",m?"rotate-180":"rotate-0")})]})})}),fe=(0,s.memo)(({className:r,children:n,...o})=>(0,t.jsx)(xt,{className:y("mt-4 text-sm","data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",r),...o,children:(0,t.jsx)(ee,{children:n})}));ce.displayName="Reasoning";ue.displayName="ReasoningTrigger";fe.displayName="ReasoningContent";var yt=({className:r,children:n,...o})=>(0,t.jsxs)(qe,{className:"w-full overflow-x-auto whitespace-nowrap",...o,children:[(0,t.jsx)("div",{className:y("flex w-max flex-nowrap items-center gap-2",r),children:n}),(0,t.jsx)(Oe,{className:"hidden",orientation:"horizontal"})]}),wt=({suggestion:r,onClick:n,className:o,variant:l="outline",size:a="sm",children:m,...h})=>{const g=()=>{n?.(r)};return(0,t.jsx)(H,{className:y("cursor-pointer rounded-full px-4",o),onClick:g,size:a,type:"button",variant:l,...h,children:m||r})},Nt=({db:r,onRateLimitRefetch:n,onControllerReady:o})=>{const[l,a]=(0,s.useState)(""),{rateLimit:m}=te(),{remaining:h}=m??{remaining:0,limit:0},{messages:g,sendMessage:v,isLoading:x,clear:S,stop:e}=xe({connection:ve(`${Me.BASE_URL}/chat`),body:{db:r},onError:i=>console.error("Error:",i.message),onResponse:i=>console.log("Response:",i),onFinish:i=>{console.log("Finish:",i),n()}});(0,s.useEffect)(()=>{o({clear:()=>{S(),a("")},isLoading:x})},[S,x,o]);const u=i=>{const j=!!i.text,c=!!i.files?.length;!(j||c)||x||(v(i.text),a(""))},w=i=>{v(i),a("")},N=()=>{e(),a("")},k=x?"streaming":"ready";return(0,t.jsxs)("div",{className:"relative flex size-full flex-col divide-y overflow-hidden",children:[(0,t.jsxs)(Ze,{children:[(0,t.jsx)(et,{children:g.length===0?(0,t.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,t.jsxs)("div",{className:"text-center space-y-2",children:[(0,t.jsx)("p",{className:"text-lg font-medium",children:"Start a new conversation"}),(0,t.jsx)("p",{className:"text-sm",children:"Ask me anything to get started"})]})}):(0,t.jsxs)(t.Fragment,{children:[g.map(i=>{const j=i.parts.filter(f=>f.type==="thinking"),c=i.parts.filter(f=>f.type==="text").map(f=>f.content).join(""),d=j.length>0;return(0,t.jsx)(Q,{defaultBranch:0,children:(0,t.jsx)(Z,{children:(0,t.jsx)(Y,{from:i.role==="user"?"user":"assistant",children:(0,t.jsxs)("div",{children:[d&&i.role==="assistant"&&(0,t.jsxs)(ce,{duration:0,children:[(0,t.jsx)(ue,{}),(0,t.jsx)(fe,{children:j.map(f=>f.content).join(`
2
- `)})]}),(0,t.jsx)($,{children:(0,t.jsx)(oe,{children:c})})]})})})},i.id)}),x&&(0,t.jsx)(Q,{defaultBranch:0,children:(0,t.jsx)(Z,{children:(0,t.jsx)(Y,{from:"assistant",children:(0,t.jsx)($,{children:(0,t.jsx)(rt,{children:"Thinking..."})})})})})]})}),(0,t.jsx)(tt,{})]}),(0,t.jsxs)("div",{className:"grid shrink-0 gap-4 pt-3",children:[g.length===0&&h>0&&(0,t.jsx)(yt,{className:"px-4",children:Ke.map(i=>(0,t.jsx)(wt,{onClick:()=>w(i),suggestion:i,size:"lg",children:i},i))}),(0,t.jsx)("div",{className:"w-full px-4 pb-4",children:(0,t.jsxs)(ut,{globalDrop:!0,multiple:!0,onSubmit:u,children:[(0,t.jsx)(ft,{children:(0,t.jsx)(mt,{onChange:i=>a(i.target.value),value:l,placeholder:"Type a message..."})}),(0,t.jsx)(dt,{children:(0,t.jsx)(pt,{className:"h-8!",status:k,onClick:x?N:void 0,disabled:m&&m.remaining===0})})]})})]})]})},_t=()=>{const{rateLimit:r,refetchRateLimit:n}=te(),{isSheetOpen:o,closeSheet:l}=Fe(),{selectedDatabase:a}=ze(),[m,h]=(0,s.useState)(null),g=(0,s.useRef)(v=>h(v));return(0,t.jsx)(Ue,{title:"AI Assistant",cta:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[r&&(0,t.jsxs)(We,{children:[(0,t.jsx)(Ge,{asChild:!0,children:(0,t.jsxs)("span",{className:"text-xs px-2 py-1 cursor-default text-muted-foreground",children:[r.remaining,"/",r.limit]})}),(0,t.jsx)(He,{side:"bottom",children:(0,t.jsxs)("p",{children:[r.remaining," messages remaining"]})})]}),a&&m&&(0,t.jsxs)(H,{type:"button",variant:"outline",size:"lg",onClick:m.clear,disabled:m.isLoading,children:[(0,t.jsx)(ye,{className:"h-4 w-4 mr-1"}),"New Chat"]})]}),closeButton:!1,open:o("ai-assistant"),size:"max-w-2xl!",contentClassName:"p-0 flex flex-col h-[calc(100vh-4rem)] flex-1",onOpenChange:v=>{v||l("ai-assistant")},children:a?(0,t.jsx)(Nt,{db:a,onRateLimitRefetch:n,onControllerReady:g.current},a):(0,t.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground p-8",children:(0,t.jsxs)("div",{className:"text-center space-y-2",children:[(0,t.jsx)("p",{className:"text-lg font-medium",children:"No database selected"}),(0,t.jsx)("p",{className:"text-sm",children:"Select a database from the sidebar to start chatting."})]})})})};export{_t as ChatSidebar};
1
+ import{r as ge}from"./rolldown-runtime-Bnw7wDfq.js";import{o as xe,s as ve}from"./tanstack-CJpNvQIy.js";import{G as Te,N as be,Y as je,b as Se,c as Ce,m as ye,nt as we,t as Ne,tt as ke}from"./icons-BywMJ5og.js";import{Ct as V,F as Ee,I as Re,Ot as Ae,P as Le,Tt as Be}from"./radix-ui-C0u6gLux.js";import{Et as y,G as De,K as Ie,W as Pe,_t as _e,b as ze,lt as Me,ot as Fe,q as Ue,wt as H}from"./index-B8u-3J3b.js";import{r as ee}from"./chunk-BO2N2NFS-BWASkQ7r.js";import{n as Oe,t as qe}from"./scroll-area-CnrU1Pgb.js";import{i as Ge,n as He,t as We}from"./tooltip-DttVuH4f.js";import{t as te}from"./use-rate-limit-B1ivFudi.js";var Ke=["Show me all tables in my database","What columns are in the users table?","Write a query to find all active users","How many orders were placed last month?","Find top 5 customers by total spend","Write a JOIN between users and orders","Users who haven't made any purchase yet","Generate monthly revenue summary query","Suggest useful indexes for better performance","Show schema of the products / inventory table","Latest 20 orders with customer names","Help me write a safe UPDATE query"],s=ge(we(),1),Ve={damping:.7,stiffness:.05,mass:1.25},Xe=70,Ye=1e3/60,Je=350,F=!1;globalThis.document?.addEventListener("mousedown",()=>{F=!0});globalThis.document?.addEventListener("mouseup",()=>{F=!1});globalThis.document?.addEventListener("click",()=>{F=!1});var $e=(r={})=>{const[n,o]=(0,s.useState)(!1),[l,a]=(0,s.useState)(r.initial!==!1),[m,h]=(0,s.useState)(!1),g=(0,s.useRef)(null);g.current=r;const v=(0,s.useCallback)(()=>{if(!F)return!1;const c=window.getSelection();if(!c||!c.rangeCount)return!1;const d=c.getRangeAt(0);return d.commonAncestorContainer.contains(i.current)||i.current?.contains(d.commonAncestorContainer)},[]),x=(0,s.useCallback)(c=>{e.isAtBottom=c,a(c)},[]),S=(0,s.useCallback)(c=>{e.escapedFromLock=c,o(c)},[]),e=(0,s.useMemo)(()=>{let c;return{escapedFromLock:n,isAtBottom:l,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return i.current?.scrollTop??0},set scrollTop(d){i.current&&(i.current.scrollTop=d,e.ignoreScrollToTop=i.current.scrollTop)},get targetScrollTop(){return!i.current||!j.current?0:i.current.scrollHeight-1-i.current.clientHeight},get calculatedTargetScrollTop(){if(!i.current||!j.current)return 0;const{targetScrollTop:d}=this;if(!r.targetScrollTop)return d;if(c?.targetScrollTop===d)return c.calculatedScrollTop;const f=Math.max(Math.min(r.targetScrollTop(d,{scrollElement:i.current,contentElement:j.current}),d),0);return c={targetScrollTop:d,calculatedScrollTop:f},requestAnimationFrame(()=>{c=void 0}),f},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=Xe}}},[]),u=(0,s.useCallback)((c={})=>{typeof c=="string"&&(c={animation:c}),c.preserveScrollPosition||x(!0);const d=Date.now()+(Number(c.wait)||0),f=G(g.current,c.animation),{ignoreEscapes:E=!1}=c;let L,B=e.calculatedTargetScrollTop;c.duration instanceof Promise?c.duration.finally(()=>{L=Date.now()}):L=d+(c.duration??0);const R=async()=>{const _=new Promise(requestAnimationFrame).then(()=>{if(!e.isAtBottom)return e.animation=void 0,!1;const{scrollTop:D}=e,P=performance.now(),U=(P-(e.lastTick??P))/Ye;if(e.animation||(e.animation={behavior:f,promise:_,ignoreEscapes:E}),e.animation.behavior===f&&(e.lastTick=P),v()||d>Date.now())return R();if(D<Math.min(B,e.calculatedTargetScrollTop)){if(e.animation?.behavior===f){if(f==="instant")return e.scrollTop=e.calculatedTargetScrollTop,R();e.velocity=(f.damping*e.velocity+f.stiffness*e.scrollDifference)/f.mass,e.accumulated+=e.velocity*U,e.scrollTop+=e.accumulated,e.scrollTop!==D&&(e.accumulated=0)}return R()}return L>Date.now()?(B=e.calculatedTargetScrollTop,R()):(e.animation=void 0,e.scrollTop<e.calculatedTargetScrollTop?u({animation:G(g.current,g.current.resize),ignoreEscapes:E,duration:Math.max(0,L-Date.now())||void 0}):e.isAtBottom)});return _.then(D=>(requestAnimationFrame(()=>{e.animation||(e.lastTick=void 0,e.velocity=0)}),D))};return c.wait!==!0&&(e.animation=void 0),e.animation?.behavior===f?e.animation.promise:R()},[x,v,e]),w=(0,s.useCallback)(()=>{S(!0),x(!1)},[S,x]),N=(0,s.useCallback)(({target:c})=>{if(c!==i.current)return;const{scrollTop:d,ignoreScrollToTop:f}=e;let{lastScrollTop:E=d}=e;e.lastScrollTop=d,e.ignoreScrollToTop=void 0,f&&f>d&&(E=f),h(e.isNearBottom),setTimeout(()=>{if(e.resizeDifference||d===f)return;if(v()){S(!0),x(!1);return}const L=d>E,B=d<E;if(e.animation?.ignoreEscapes){e.scrollTop=E;return}B&&(S(!0),x(!1)),L&&S(!1),!e.escapedFromLock&&e.isNearBottom&&x(!0)},1)},[S,x,v,e]),k=(0,s.useCallback)(({target:c,deltaY:d})=>{let f=c;for(;!["scroll","auto"].includes(getComputedStyle(f).overflow);){if(!f.parentElement)return;f=f.parentElement}f===i.current&&d<0&&i.current.scrollHeight>i.current.clientHeight&&!e.animation?.ignoreEscapes&&(S(!0),x(!1))},[S,x,e]),i=X(c=>{i.current?.removeEventListener("scroll",N),i.current?.removeEventListener("wheel",k),c?.addEventListener("scroll",N,{passive:!0}),c?.addEventListener("wheel",k,{passive:!0})},[]),j=X(c=>{if(e.resizeObserver?.disconnect(),!c)return;let d;e.resizeObserver=new ResizeObserver(([f])=>{const{height:E}=f.contentRect,L=E-(d??E);if(e.resizeDifference=L,e.scrollTop>e.targetScrollTop&&(e.scrollTop=e.targetScrollTop),h(e.isNearBottom),L>=0){const B=G(g.current,d?g.current.resize:g.current.initial);u({animation:B,wait:!0,preserveScrollPosition:!0,duration:B==="instant"?void 0:Je})}else e.isNearBottom&&(S(!1),x(!0));d=E,requestAnimationFrame(()=>{setTimeout(()=>{e.resizeDifference===L&&(e.resizeDifference=0)},1)})}),e.resizeObserver?.observe(c)},[]);return{contentRef:j,scrollRef:i,scrollToBottom:u,stopScroll:w,isAtBottom:l||m,isNearBottom:m,escapedFromLock:n,state:e}};function X(r,n){const o=(0,s.useCallback)(l=>(o.current=l,r(l)),n);return o}var q=new Map;function G(...r){const n={...Ve};let o=!1;for(const a of r){if(a==="instant"){o=!0;continue}typeof a=="object"&&(o=!1,n.damping=a.damping??n.damping,n.stiffness=a.stiffness??n.stiffness,n.mass=a.mass??n.mass)}const l=JSON.stringify(n);return q.has(l)||q.set(l,Object.freeze(n)),o?"instant":q.get(l)}var t=Ae(),re=(0,s.createContext)(null),Qe=typeof window<"u"?s.useLayoutEffect:s.useEffect;function M({instance:r,children:n,resize:o,initial:l,mass:a,damping:m,stiffness:h,targetScrollTop:g,contextRef:v,...x}){const S=(0,s.useRef)(null),e=$e({mass:a,damping:m,stiffness:h,resize:o,initial:l,targetScrollTop:s.useCallback((f,E)=>(d?.targetScrollTop??g)?.(f,E)??f,[g])}),{scrollRef:u,contentRef:w,scrollToBottom:N,stopScroll:k,isAtBottom:i,escapedFromLock:j,state:c}=r??e,d=(0,s.useMemo)(()=>({scrollToBottom:N,stopScroll:k,scrollRef:u,isAtBottom:i,escapedFromLock:j,contentRef:w,state:c,get targetScrollTop(){return S.current},set targetScrollTop(f){S.current=f}}),[N,i,w,u,k,j,c]);return(0,s.useImperativeHandle)(v,()=>d,[d]),Qe(()=>{u.current&&getComputedStyle(u.current).overflow==="visible"&&(u.current.style.overflow="auto")},[]),(0,t.jsx)(re.Provider,{value:d,children:(0,t.jsx)("div",{...x,children:typeof n=="function"?n(d):n})})}(function(r){function n({children:o,...l}){const a=ne();return(0,t.jsx)("div",{ref:a.scrollRef,style:{height:"100%",width:"100%"},children:(0,t.jsx)("div",{...l,ref:a.contentRef,children:typeof o=="function"?o(a):o})})}r.Content=n})(M||(M={}));function ne(){const r=(0,s.useContext)(re);if(!r)throw new Error("use-stick-to-bottom component context must be used within a StickToBottom component");return r}var Ze=({className:r,...n})=>(0,t.jsx)(M,{className:y("relative flex-1 overflow-y-hidden",r),initial:"smooth",resize:"smooth",role:"log",...n}),et=({className:r,...n})=>(0,t.jsx)(M.Content,{className:y("flex flex-col gap-8 p-4",r),...n}),tt=({className:r,...n})=>{const{isAtBottom:o,scrollToBottom:l}=ne(),a=(0,s.useCallback)(()=>{l()},[l]);return!o&&(0,t.jsx)(H,{className:y("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",r),onClick:a,size:"icon",type:"button",variant:"outline",...n,children:(0,t.jsx)(ke,{className:"size-4"})})},Y=[{variant:"shine",component:({children:r,className:n,...o})=>(0,t.jsx)("span",{...o,className:y("bg-[linear-gradient(110deg,#bfbfbf,35%,#000,50%,#bfbfbf,75%,#bfbfbf)] dark:bg-[linear-gradient(110deg,#404040,35%,#fff,50%,#404040,75%,#404040)]","bg-size-[200%_100%] bg-clip-text text-transparent","animate-shine",n),children:r})}];function rt({variant:r="shine",className:n,...o}){const l=Y.find(a=>a.variant===r)?.component||Y[0].component;return(0,t.jsx)(Be,{className:y("font-medium text-sm"),children:(0,t.jsx)(l,{...o,className:n})})}var J=({className:r,from:n,...o})=>(0,t.jsx)("div",{className:y("group flex w-full max-w-[95%] flex-col gap-2",n==="user"?"is-user ml-auto justify-end":"is-assistant",r),...o}),$=({children:r,className:n,...o})=>(0,t.jsx)("div",{className:y("is-user:dark flex w-fit max-w-full min-w-0 flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",n),...o,children:r}),se=(0,s.createContext)(null),nt=()=>{const r=(0,s.useContext)(se);if(!r)throw new Error("MessageBranch components must be used within MessageBranch");return r},Q=({defaultBranch:r=0,onBranchChange:n,className:o,...l})=>{const[a,m]=(0,s.useState)(r),[h,g]=(0,s.useState)([]),v=u=>{m(u),n?.(u)},x=()=>{v(a>0?a-1:h.length-1)},S=()=>{v(a<h.length-1?a+1:0)},e={currentBranch:a,totalBranches:h.length,goToPrevious:x,goToNext:S,branches:h,setBranches:g};return(0,t.jsx)(se.Provider,{value:e,children:(0,t.jsx)("div",{className:y("grid w-full gap-2 [&>div]:pb-0",o),...l})})},Z=({children:r,...n})=>{const{currentBranch:o,setBranches:l,branches:a}=nt(),m=Array.isArray(r)?r:[r];return(0,s.useEffect)(()=>{a.length!==m.length&&l(m)},[m,a,l]),m.map((h,g)=>(0,t.jsx)("div",{className:y("grid gap-2 overflow-hidden [&>div]:pb-0",g===o?"block":"hidden"),...n,children:h},h.key))},oe=(0,s.memo)(({className:r,...n})=>(0,t.jsx)(ee,{className:y("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",r),...n}),(r,n)=>r.children===n.children);oe.displayName="MessageResponse";var st="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",ot=(r=21)=>{let n="",o=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)n+=st[o[r]&63];return n},at=(0,s.createContext)(null),it=(0,s.createContext)(null),ae=()=>(0,s.useContext)(at),lt=()=>(0,s.useContext)(it),ie=(0,s.createContext)(null),ct=()=>{const r=lt(),n=(0,s.useContext)(ie),o=r??n;if(!o)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return o},ut=({className:r,accept:n,multiple:o,globalDrop:l,syncHiddenInput:a,maxFiles:m,maxFileSize:h,onError:g,onSubmit:v,children:x,...S})=>{const e=ae(),u=!!e,w=(0,s.useRef)(null),N=(0,s.useRef)(null),[k,i]=(0,s.useState)([]),j=u?e.attachments.files:k,c=(0,s.useRef)(j);c.current=j;const d=(0,s.useCallback)(()=>{w.current?.click()},[]),f=(0,s.useCallback)(p=>!n||n.trim()===""?!0:n.split(",").map(T=>T.trim()).filter(Boolean).some(T=>{if(T.endsWith("/*")){const b=T.slice(0,-1);return p.type.startsWith(b)}return p.type===T}),[n]),E=(0,s.useCallback)(p=>{const T=Array.from(p),b=T.filter(I=>f(I));if(T.length&&b.length===0){g?.({code:"accept",message:"No files match the accepted types."});return}const C=I=>h?I.size<=h:!0,A=b.filter(C);if(b.length>0&&A.length===0){g?.({code:"max_file_size",message:"All files exceed the maximum size."});return}i(I=>{const z=typeof m=="number"?Math.max(0,m-I.length):void 0,he=typeof z=="number"?A.slice(0,z):A;typeof z=="number"&&A.length>z&&g?.({code:"max_files",message:"Too many files. Some were not added."});const K=[];for(const O of he)K.push({id:ot(),type:"file",url:URL.createObjectURL(O),mediaType:O.type,filename:O.name});return I.concat(K)})},[f,m,h,g]),L=(0,s.useCallback)(p=>i(T=>{const b=T.find(C=>C.id===p);return b?.url&&URL.revokeObjectURL(b.url),T.filter(C=>C.id!==p)}),[]),B=(0,s.useCallback)(()=>i(p=>{for(const T of p)T.url&&URL.revokeObjectURL(T.url);return[]}),[]),R=u?e.attachments.add:E,_=u?e.attachments.remove:L,D=u?e.attachments.clear:B,P=u?e.attachments.openFileDialog:d;(0,s.useEffect)(()=>{u&&e.__registerFileInput(w,()=>w.current?.click())},[u,e]),(0,s.useEffect)(()=>{a&&w.current&&j.length===0&&(w.current.value="")},[j,a]),(0,s.useEffect)(()=>{const p=N.current;if(!p||l)return;const T=C=>{C.dataTransfer?.types?.includes("Files")&&C.preventDefault()},b=C=>{C.dataTransfer?.types?.includes("Files")&&C.preventDefault(),C.dataTransfer?.files&&C.dataTransfer.files.length>0&&R(C.dataTransfer.files)};return p.addEventListener("dragover",T),p.addEventListener("drop",b),()=>{p.removeEventListener("dragover",T),p.removeEventListener("drop",b)}},[R,l]),(0,s.useEffect)(()=>{if(!l)return;const p=b=>{b.dataTransfer?.types?.includes("Files")&&b.preventDefault()},T=b=>{b.dataTransfer?.types?.includes("Files")&&b.preventDefault(),b.dataTransfer?.files&&b.dataTransfer.files.length>0&&R(b.dataTransfer.files)};return document.addEventListener("dragover",p),document.addEventListener("drop",T),()=>{document.removeEventListener("dragover",p),document.removeEventListener("drop",T)}},[R,l]),(0,s.useEffect)(()=>()=>{if(!u)for(const p of c.current)p.url&&URL.revokeObjectURL(p.url)},[u]);const U=p=>{p.currentTarget.files&&R(p.currentTarget.files),p.currentTarget.value=""},me=async p=>{try{const T=await(await fetch(p)).blob();return new Promise(b=>{const C=new FileReader;C.onloadend=()=>b(C.result),C.onerror=()=>b(null),C.readAsDataURL(T)})}catch{return null}},de=(0,s.useMemo)(()=>({files:j.map(p=>({...p,id:p.id})),add:R,remove:_,clear:D,openFileDialog:P,fileInputRef:w}),[j,R,_,D,P]),pe=p=>{p.preventDefault();const T=p.currentTarget,b=u?e.textInput.value:new FormData(T).get("message")||"";u||T.reset(),Promise.all(j.map(async({id:C,...A})=>{if(A.url?.startsWith("blob:")){const I=await me(A.url);return{...A,url:I??A.url}}return A})).then(C=>{try{const A=v({text:b,files:C},p);A instanceof Promise?A.then(()=>{D(),u&&e.textInput.clear()}).catch(()=>{}):(D(),u&&e.textInput.clear())}catch{}}).catch(()=>{})},W=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("input",{accept:n,"aria-label":"Upload files",className:"hidden",multiple:o,onChange:U,ref:w,title:"Upload files",type:"file"}),(0,t.jsx)("form",{className:y("w-full",r),onSubmit:pe,ref:N,...S,children:(0,t.jsx)(Pe,{className:"overflow-hidden",children:x})})]});return u?W:(0,t.jsx)(ie.Provider,{value:de,children:W})},ft=({className:r,...n})=>(0,t.jsx)("div",{className:y("contents",r),...n}),mt=({onChange:r,className:n,placeholder:o="What would you like to know?",...l})=>{const a=ae(),m=ct(),[h,g]=(0,s.useState)(!1),v=e=>{if(e.key==="Enter"){if(h||e.nativeEvent.isComposing||e.shiftKey)return;e.preventDefault();const u=e.currentTarget.form;if(u?.querySelector('button[type="submit"]')?.disabled)return;u?.requestSubmit()}if(e.key==="Backspace"&&e.currentTarget.value===""&&m.files.length>0){e.preventDefault();const u=m.files.at(-1);u&&m.remove(u.id)}},x=e=>{const u=e.clipboardData?.items;if(!u)return;const w=[];for(const N of u)if(N.kind==="file"){const k=N.getAsFile();k&&w.push(k)}w.length>0&&(e.preventDefault(),m.add(w))},S=a?{value:a.textInput.value,onChange:e=>{a.textInput.setInput(e.currentTarget.value),r?.(e)}}:{onChange:r};return(0,t.jsx)(Ue,{className:y("field-sizing-content max-h-48 min-h-16",n),name:"message",onCompositionEnd:()=>g(!1),onCompositionStart:()=>g(!0),onKeyDown:v,onPaste:x,placeholder:o,...l,...S})},dt=({className:r,...n})=>(0,t.jsx)(De,{align:"block-end",className:y("justify-between justify-end gap-1",r),...n}),pt=({className:r,variant:n="default",size:o="icon-sm",status:l,children:a,...m})=>{let h=(0,t.jsx)(be,{className:"size-4"});return l==="submitted"?h=(0,t.jsx)(Se,{className:"size-4 animate-spin"}):l==="streaming"?h=(0,t.jsx)(Ce,{className:"size-4"}):l==="error"&&(h=(0,t.jsx)(Ne,{className:"size-4"})),(0,t.jsx)(Ie,{"aria-label":"Submit",className:y(r),size:o,type:"submit",variant:n,...m,children:a??h})};function ht({...r}){return(0,t.jsx)(Ee,{"data-slot":"collapsible",...r})}function gt({...r}){return(0,t.jsx)(Re,{"data-slot":"collapsible-trigger",...r})}function xt({...r}){return(0,t.jsx)(Le,{"data-slot":"collapsible-content",...r})}var vt=({children:r,as:n="p",className:o,duration:l=2,spread:a=2})=>{const m=(0,s.useMemo)(()=>(r?.length??0)*a,[r,a]);return(0,t.jsx)(n,{className:y("relative inline-block bg-size-[250%_100%,auto] bg-clip-text text-transparent","[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]","animate-shimmer",o),style:{"--spread":`${m}px`,"--duration":`${l}s`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},children:r})},Tt=(0,s.memo)(vt),le=(0,s.createContext)(null),bt=()=>{const r=(0,s.useContext)(le);if(!r)throw new Error("Reasoning components must be used within Reasoning");return r},jt=1e3,St=1e3,ce=(0,s.memo)(({className:r,isStreaming:n=!1,open:o,defaultOpen:l=!0,onOpenChange:a,duration:m,children:h,...g})=>{const[v,x]=V({prop:o,defaultProp:l,onChange:a}),[S,e]=V({prop:m,defaultProp:void 0}),[u,w]=(0,s.useState)(!1),[N,k]=(0,s.useState)(null);(0,s.useEffect)(()=>{n?N===null&&k(Date.now()):N!==null&&(e(Math.ceil((Date.now()-N)/St)),k(null))},[n,N,e]),(0,s.useEffect)(()=>{if(l&&!n&&v&&!u){const j=setTimeout(()=>{x(!1),w(!0)},jt);return()=>clearTimeout(j)}},[n,v,l,x,u]);const i=j=>{x(j)};return(0,t.jsx)(le.Provider,{value:{isStreaming:n,isOpen:v,setIsOpen:x,duration:S},children:(0,t.jsx)(ht,{className:y("not-prose mb-4",r),onOpenChange:i,open:v,...g,children:h})})}),Ct=(r,n)=>r||n===0?(0,t.jsx)(Tt,{duration:1,children:"Thinking..."}):n===void 0?(0,t.jsx)("p",{children:"Thought for a few seconds"}):(0,t.jsxs)("p",{children:["Thought for ",n," seconds"]}),ue=(0,s.memo)(({className:r,children:n,getThinkingMessage:o=Ct,...l})=>{const{isStreaming:a,isOpen:m,duration:h}=bt();return(0,t.jsx)(gt,{className:y("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",r),...l,children:n??(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(je,{className:"size-4"}),o(a,h),(0,t.jsx)(Te,{className:y("size-4 transition-transform",m?"rotate-180":"rotate-0")})]})})}),fe=(0,s.memo)(({className:r,children:n,...o})=>(0,t.jsx)(xt,{className:y("mt-4 text-sm","data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",r),...o,children:(0,t.jsx)(ee,{children:n})}));ce.displayName="Reasoning";ue.displayName="ReasoningTrigger";fe.displayName="ReasoningContent";var yt=({className:r,children:n,...o})=>(0,t.jsxs)(qe,{className:"w-full overflow-x-auto whitespace-nowrap",...o,children:[(0,t.jsx)("div",{className:y("flex w-max flex-nowrap items-center gap-2",r),children:n}),(0,t.jsx)(Oe,{className:"hidden",orientation:"horizontal"})]}),wt=({suggestion:r,onClick:n,className:o,variant:l="outline",size:a="sm",children:m,...h})=>{const g=()=>{n?.(r)};return(0,t.jsx)(H,{className:y("cursor-pointer rounded-full px-4",o),onClick:g,size:a,type:"button",variant:l,...h,children:m||r})},Nt=({db:r,onRateLimitRefetch:n,onControllerReady:o})=>{const[l,a]=(0,s.useState)(""),{rateLimit:m}=te(),{remaining:h}=m??{remaining:0,limit:0},{messages:g,sendMessage:v,isLoading:x,clear:S,stop:e}=xe({connection:ve(`${Me.BASE_URL}/chat`),body:{db:r},onError:i=>console.error("Error:",i.message),onResponse:i=>console.log("Response:",i),onFinish:i=>{console.log("Finish:",i),n()}});(0,s.useEffect)(()=>{o({clear:()=>{S(),a("")},isLoading:x})},[S,x,o]);const u=i=>{const j=!!i.text,c=!!i.files?.length;!(j||c)||x||(v(i.text),a(""))},w=i=>{v(i),a("")},N=()=>{e(),a("")},k=x?"streaming":"ready";return(0,t.jsxs)("div",{className:"relative flex size-full flex-col divide-y overflow-hidden",children:[(0,t.jsxs)(Ze,{children:[(0,t.jsx)(et,{children:g.length===0?(0,t.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,t.jsxs)("div",{className:"text-center space-y-2",children:[(0,t.jsx)("p",{className:"text-lg font-medium",children:"Start a new conversation"}),(0,t.jsx)("p",{className:"text-sm",children:"Ask me anything to get started"})]})}):(0,t.jsxs)(t.Fragment,{children:[g.map(i=>{const j=i.parts.filter(f=>f.type==="thinking"),c=i.parts.filter(f=>f.type==="text").map(f=>f.content).join(""),d=j.length>0;return(0,t.jsx)(Q,{defaultBranch:0,children:(0,t.jsx)(Z,{children:(0,t.jsx)(J,{from:i.role==="user"?"user":"assistant",children:(0,t.jsxs)("div",{children:[d&&i.role==="assistant"&&(0,t.jsxs)(ce,{duration:0,children:[(0,t.jsx)(ue,{}),(0,t.jsx)(fe,{children:j.map(f=>f.content).join(`
2
+ `)})]}),(0,t.jsx)($,{children:(0,t.jsx)(oe,{children:c})})]})})})},i.id)}),x&&(0,t.jsx)(Q,{defaultBranch:0,children:(0,t.jsx)(Z,{children:(0,t.jsx)(J,{from:"assistant",children:(0,t.jsx)($,{children:(0,t.jsx)(rt,{children:"Thinking..."})})})})})]})}),(0,t.jsx)(tt,{})]}),(0,t.jsxs)("div",{className:"grid shrink-0 gap-4 pt-3",children:[g.length===0&&h>0&&(0,t.jsx)(yt,{className:"px-4",children:Ke.map(i=>(0,t.jsx)(wt,{onClick:()=>w(i),suggestion:i,size:"lg",children:i},i))}),(0,t.jsx)("div",{className:"w-full px-4 pb-4",children:(0,t.jsxs)(ut,{globalDrop:!0,multiple:!0,onSubmit:u,children:[(0,t.jsx)(ft,{children:(0,t.jsx)(mt,{onChange:i=>a(i.target.value),value:l,placeholder:"Type a message..."})}),(0,t.jsx)(dt,{children:(0,t.jsx)(pt,{className:"h-8!",status:k,onClick:x?N:void 0,disabled:m&&m.remaining===0})})]})})]})]})},_t=()=>{const{rateLimit:r,refetchRateLimit:n}=te(),{isSheetOpen:o,closeSheet:l}=_e(),{selectedDatabase:a}=Fe(),[m,h]=(0,s.useState)(null),g=(0,s.useRef)(v=>h(v));return(0,t.jsx)(ze,{title:"AI Assistant",cta:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[r&&(0,t.jsxs)(We,{children:[(0,t.jsx)(Ge,{asChild:!0,children:(0,t.jsxs)("span",{className:"text-xs px-2 py-1 cursor-default text-muted-foreground",children:[r.remaining,"/",r.limit]})}),(0,t.jsx)(He,{side:"bottom",children:(0,t.jsxs)("p",{children:[r.remaining," messages remaining"]})})]}),a&&m&&(0,t.jsxs)(H,{type:"button",variant:"outline",size:"lg",onClick:m.clear,disabled:m.isLoading,children:[(0,t.jsx)(ye,{className:"h-4 w-4 mr-1"}),"New Chat"]})]}),closeButton:!1,open:o("ai-assistant"),size:"max-w-2xl!",contentClassName:"p-0 flex flex-col h-[calc(100vh-4rem)] flex-1",onOpenChange:v=>{v||l("ai-assistant")},children:a?(0,t.jsx)(Nt,{db:a,onRateLimitRefetch:n,onControllerReady:g.current},a):(0,t.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground p-8",children:(0,t.jsxs)("div",{className:"text-center space-y-2",children:[(0,t.jsx)("p",{className:"text-lg font-medium",children:"No database selected"}),(0,t.jsx)("p",{className:"text-sm",children:"Select a database from the sidebar to start chatting."})]})})})};export{_t as ChatSidebar};
@@ -1 +1 @@
1
- import{r as Z}from"./rolldown-runtime-Bnw7wDfq.js";import{nt as k}from"./icons-BywMJ5og.js";import{Bt as L,Gt as ee,Ht as U,It as te,Kt as re,Lt as se,Rt as Q,Ut as ne,Vt as ae,Wt as ue,qt as oe,zt as G}from"./index-D9Wxg2ot.js";var h=Z(k(),1);function X(e,t,r){try{return e(t)}catch(n){return oe("[nuqs] Error while parsing value `%s`: %O"+(r?" (for key `%s`)":""),t,n,r),null}}function g(e){function t(r){if(typeof r>"u")return null;let n="";if(Array.isArray(r)){if(r[0]===void 0)return null;n=r[0]}return typeof r=="string"&&(n=r),X(e.parse,n)}return{type:"single",eq:(r,n)=>r===n,...e,parseServerSide:t,withDefault(r){return{...this,defaultValue:r,parseServerSide(n){return t(n)??r}}},withOptions(r){return{...this,...r}}}}var de=g({parse:e=>e,serialize:String}),pe=g({parse:e=>{const t=parseInt(e);return t==t?t:null},serialize:e=>""+Math.round(e)}),he=g({parse:e=>{const t=parseInt(e);return t==t?t-1:null},serialize:e=>""+Math.round(e+1)}),Oe=g({parse:e=>{const t=parseInt(e,16);return t==t?t:null},serialize:e=>{const t=Math.round(e).toString(16);return(t.length&1?"0":"")+t}}),be=g({parse:e=>{const t=parseFloat(e);return t==t?t:null},serialize:String}),Se=g({parse:e=>e.toLowerCase()==="true",serialize:String});function B(e,t){return e.valueOf()===t.valueOf()}var ge=g({parse:e=>{const t=parseInt(e);return t==t?new Date(t):null},serialize:e=>""+e.valueOf(),eq:B}),je=g({parse:e=>{const t=new Date(e);return t.valueOf()==t.valueOf()?t:null},serialize:e=>e.toISOString(),eq:B}),ve=g({parse:e=>{const t=new Date(e.slice(0,10));return t.valueOf()==t.valueOf()?t:null},serialize:e=>e.toISOString().slice(0,10),eq:B});function ye(e){return g({parse:t=>{try{const r=JSON.parse(t);if("~standard"in e){const n=e["~standard"].validate(r);if(n instanceof Promise)throw new Error("[nuqs] Only synchronous Standard Schemas are supported in parseAsJson.");return n.issues?null:n.value}return e(r)}catch{return null}},serialize:t=>JSON.stringify(t),eq(t,r){return t===r||JSON.stringify(t)===JSON.stringify(r)}})}var _=se(),le={};function ie(e,t={}){const r=(0,h.useId)(),n=ee(),O=re(),{history:q="replace",scroll:j=n?.scroll??!1,shallow:z=n?.shallow??!0,throttleMs:m=G.timeMs,limitUrlUpdates:u=n?.limitUrlUpdates,clearOnDefault:f=n?.clearOnDefault??!0,startTransition:p,urlKeys:b=le}=t,i=Object.keys(e).join(","),o=(0,h.useMemo)(()=>Object.fromEntries(Object.keys(e).map(s=>[s,b[s]??s])),[i,JSON.stringify(b)]),w=ue(Object.values(o)),v=w.searchParams,I=(0,h.useRef)({}),C=(0,h.useMemo)(()=>Object.fromEntries(Object.keys(e).map(s=>[s,e[s].defaultValue??null])),[Object.values(e).map(({defaultValue:s})=>s).join(",")]),E=Q.useQueuedQueries(Object.values(o)),[M,N]=(0,h.useState)(()=>$(e,b,v??new URLSearchParams,E).state),d=(0,h.useRef)(M);if(U("[nuq+ %s `%s`] render - state: %O, iSP: %s",r,i,M,v),Object.keys(I.current).join("&")!==Object.values(o).join("&")){const{state:s,hasChanged:a}=$(e,b,v,E,I.current,d.current);a&&(U("[nuq+ %s `%s`] State changed: %O",r,i,{state:s,initialSearchParams:v,queuedQueries:E,queryRef:I.current,stateRef:d.current}),d.current=s,N(s)),I.current=Object.fromEntries(Object.entries(o).map(([l,S])=>[S,e[l]?.type==="multi"?v?.getAll(S):v?.get(S)??null]))}(0,h.useEffect)(()=>{const{state:s,hasChanged:a}=$(e,b,v,E,I.current,d.current);a&&(U("[nuq+ %s `%s`] State changed: %O",r,i,{state:s,initialSearchParams:v,queuedQueries:E,queryRef:I.current,stateRef:d.current}),d.current=s,N(s))},[Object.values(o).map(s=>`${s}=${v?.getAll(s)}`).join("&"),JSON.stringify(E)]),(0,h.useEffect)(()=>{const s=Object.keys(e).reduce((a,l)=>(a[l]=({state:S,query:T})=>{N(V=>{const{defaultValue:P}=e[l],R=o[l],J=S??P??null,A=V[l]??P??null;return Object.is(A,J)?(U("[nuq+ %s `%s`] Cross-hook key sync %s: %O (default: %O). no change, skipping, resolved: %O",r,i,R,S,P,d.current),V):(d.current={...d.current,[l]:J},I.current[R]=T,U("[nuq+ %s `%s`] Cross-hook key sync %s: %O (default: %O). updateInternalState, resolved: %O",r,i,R,S,P,d.current),d.current)})},a),{});for(const a of Object.keys(e)){const l=o[a];U("[nuq+ %s `%s`] Subscribing to sync for `%s`",r,l,i),_.on(l,s[a])}return()=>{for(const a of Object.keys(e)){const l=o[a];U("[nuq+ %s `%s`] Unsubscribing to sync for `%s`",r,l,i),_.off(l,s[a])}}},[i,o]);const Y=(0,h.useCallback)((s,a={})=>{const l=Object.fromEntries(Object.keys(e).map(A=>[A,null])),S=typeof s=="function"?s(W(d.current,C))??l:s??l;U("[nuq+ %s `%s`] setState: %O",r,i,S);let T,V=0,P=!1;const R=[];for(let[A,y]of Object.entries(S)){const c=e[A],x=o[A];if(!c||y===void 0)continue;(a.clearOnDefault??c.clearOnDefault??f)&&y!==null&&c.defaultValue!==void 0&&(c.eq??((D,K)=>D===K))(y,c.defaultValue)&&(y=null);const H=y===null?null:(c.serialize??String)(y);_.emit(x,{state:y,query:H});const F={key:x,query:H,options:{history:a.history??c.history??q,shallow:a.shallow??c.shallow??z,scroll:a.scroll??c.scroll??j,startTransition:a.startTransition??c.startTransition??p}};if(a?.limitUrlUpdates?.method==="debounce"||u?.method==="debounce"||c.limitUrlUpdates?.method==="debounce"){F.options.shallow===!0&&console.warn(ne(422));const D=a?.limitUrlUpdates?.timeMs??u?.timeMs??c.limitUrlUpdates?.timeMs??G.timeMs,K=Q.push(F,D,w,O);V<D&&(T=K,V=D)}else{const D=a?.limitUrlUpdates?.timeMs??c?.limitUrlUpdates?.timeMs??u?.timeMs??a.throttleMs??c.throttleMs??m;R.push(Q.abort(x)),L.push(F,D),P=!0}}const J=R.reduce((A,y)=>y(A),P?L.flush(w,O):L.getPendingPromise(w));return T??J},[i,q,z,j,m,u?.method,u?.timeMs,p,o,w.updateUrl,w.getSearchParamsSnapshot,w.rateLimitFactor,O,C]);return[(0,h.useMemo)(()=>W(M,C),[M,C]),Y]}function $(e,t,r,n,O,q){let j=!1;const z=Object.entries(e).reduce((m,[u,f])=>{const p=t?.[u]??u,b=n[p],i=f.type==="multi"?[]:null,o=b===void 0?(f.type==="multi"?r?.getAll(p):r?.get(p))??i:b;return O&&q&&te(O[p]??i,o)?(m[u]=q[u]??null,m):(j=!0,m[u]=(ae(o)?null:X(f.parse,o,p))??null,O&&(O[p]=o),m)},{});if(!j){const m=Object.keys(e),u=Object.keys(q??{});j=m.length!==u.length||m.some(f=>!u.includes(f))}return{state:z,hasChanged:j}}function W(e,t){return Object.fromEntries(Object.keys(e).map(r=>[r,e[r]??t[r]??null]))}function qe(e,t={}){const{parse:r,type:n,serialize:O,eq:q,defaultValue:j,...z}=t,[{[e]:m},u]=ie({[e]:{parse:r??(f=>f),type:n,serialize:O,eq:q,defaultValue:j}},z);return[m,(0,h.useCallback)((f,p={})=>u(b=>({[e]:typeof f=="function"?f(b[e]):f}),p),[e,u])]}export{qe as n,ye as t};
1
+ import{r as Z}from"./rolldown-runtime-Bnw7wDfq.js";import{nt as k}from"./icons-BywMJ5og.js";import{Bt as L,Gt as ee,Ht as U,It as te,Kt as re,Lt as se,Rt as Q,Ut as ne,Vt as ae,Wt as ue,qt as oe,zt as G}from"./index-B8u-3J3b.js";var h=Z(k(),1);function X(e,t,r){try{return e(t)}catch(n){return oe("[nuqs] Error while parsing value `%s`: %O"+(r?" (for key `%s`)":""),t,n,r),null}}function g(e){function t(r){if(typeof r>"u")return null;let n="";if(Array.isArray(r)){if(r[0]===void 0)return null;n=r[0]}return typeof r=="string"&&(n=r),X(e.parse,n)}return{type:"single",eq:(r,n)=>r===n,...e,parseServerSide:t,withDefault(r){return{...this,defaultValue:r,parseServerSide(n){return t(n)??r}}},withOptions(r){return{...this,...r}}}}var de=g({parse:e=>e,serialize:String}),pe=g({parse:e=>{const t=parseInt(e);return t==t?t:null},serialize:e=>""+Math.round(e)}),he=g({parse:e=>{const t=parseInt(e);return t==t?t-1:null},serialize:e=>""+Math.round(e+1)}),Oe=g({parse:e=>{const t=parseInt(e,16);return t==t?t:null},serialize:e=>{const t=Math.round(e).toString(16);return(t.length&1?"0":"")+t}}),be=g({parse:e=>{const t=parseFloat(e);return t==t?t:null},serialize:String}),Se=g({parse:e=>e.toLowerCase()==="true",serialize:String});function B(e,t){return e.valueOf()===t.valueOf()}var ge=g({parse:e=>{const t=parseInt(e);return t==t?new Date(t):null},serialize:e=>""+e.valueOf(),eq:B}),je=g({parse:e=>{const t=new Date(e);return t.valueOf()==t.valueOf()?t:null},serialize:e=>e.toISOString(),eq:B}),ve=g({parse:e=>{const t=new Date(e.slice(0,10));return t.valueOf()==t.valueOf()?t:null},serialize:e=>e.toISOString().slice(0,10),eq:B});function ye(e){return g({parse:t=>{try{const r=JSON.parse(t);if("~standard"in e){const n=e["~standard"].validate(r);if(n instanceof Promise)throw new Error("[nuqs] Only synchronous Standard Schemas are supported in parseAsJson.");return n.issues?null:n.value}return e(r)}catch{return null}},serialize:t=>JSON.stringify(t),eq(t,r){return t===r||JSON.stringify(t)===JSON.stringify(r)}})}var _=se(),le={};function ie(e,t={}){const r=(0,h.useId)(),n=ee(),O=re(),{history:q="replace",scroll:j=n?.scroll??!1,shallow:z=n?.shallow??!0,throttleMs:m=G.timeMs,limitUrlUpdates:u=n?.limitUrlUpdates,clearOnDefault:f=n?.clearOnDefault??!0,startTransition:p,urlKeys:b=le}=t,i=Object.keys(e).join(","),o=(0,h.useMemo)(()=>Object.fromEntries(Object.keys(e).map(s=>[s,b[s]??s])),[i,JSON.stringify(b)]),w=ue(Object.values(o)),v=w.searchParams,I=(0,h.useRef)({}),C=(0,h.useMemo)(()=>Object.fromEntries(Object.keys(e).map(s=>[s,e[s].defaultValue??null])),[Object.values(e).map(({defaultValue:s})=>s).join(",")]),E=Q.useQueuedQueries(Object.values(o)),[M,N]=(0,h.useState)(()=>$(e,b,v??new URLSearchParams,E).state),d=(0,h.useRef)(M);if(U("[nuq+ %s `%s`] render - state: %O, iSP: %s",r,i,M,v),Object.keys(I.current).join("&")!==Object.values(o).join("&")){const{state:s,hasChanged:a}=$(e,b,v,E,I.current,d.current);a&&(U("[nuq+ %s `%s`] State changed: %O",r,i,{state:s,initialSearchParams:v,queuedQueries:E,queryRef:I.current,stateRef:d.current}),d.current=s,N(s)),I.current=Object.fromEntries(Object.entries(o).map(([l,S])=>[S,e[l]?.type==="multi"?v?.getAll(S):v?.get(S)??null]))}(0,h.useEffect)(()=>{const{state:s,hasChanged:a}=$(e,b,v,E,I.current,d.current);a&&(U("[nuq+ %s `%s`] State changed: %O",r,i,{state:s,initialSearchParams:v,queuedQueries:E,queryRef:I.current,stateRef:d.current}),d.current=s,N(s))},[Object.values(o).map(s=>`${s}=${v?.getAll(s)}`).join("&"),JSON.stringify(E)]),(0,h.useEffect)(()=>{const s=Object.keys(e).reduce((a,l)=>(a[l]=({state:S,query:T})=>{N(V=>{const{defaultValue:P}=e[l],R=o[l],J=S??P??null,A=V[l]??P??null;return Object.is(A,J)?(U("[nuq+ %s `%s`] Cross-hook key sync %s: %O (default: %O). no change, skipping, resolved: %O",r,i,R,S,P,d.current),V):(d.current={...d.current,[l]:J},I.current[R]=T,U("[nuq+ %s `%s`] Cross-hook key sync %s: %O (default: %O). updateInternalState, resolved: %O",r,i,R,S,P,d.current),d.current)})},a),{});for(const a of Object.keys(e)){const l=o[a];U("[nuq+ %s `%s`] Subscribing to sync for `%s`",r,l,i),_.on(l,s[a])}return()=>{for(const a of Object.keys(e)){const l=o[a];U("[nuq+ %s `%s`] Unsubscribing to sync for `%s`",r,l,i),_.off(l,s[a])}}},[i,o]);const Y=(0,h.useCallback)((s,a={})=>{const l=Object.fromEntries(Object.keys(e).map(A=>[A,null])),S=typeof s=="function"?s(W(d.current,C))??l:s??l;U("[nuq+ %s `%s`] setState: %O",r,i,S);let T,V=0,P=!1;const R=[];for(let[A,y]of Object.entries(S)){const c=e[A],x=o[A];if(!c||y===void 0)continue;(a.clearOnDefault??c.clearOnDefault??f)&&y!==null&&c.defaultValue!==void 0&&(c.eq??((D,K)=>D===K))(y,c.defaultValue)&&(y=null);const H=y===null?null:(c.serialize??String)(y);_.emit(x,{state:y,query:H});const F={key:x,query:H,options:{history:a.history??c.history??q,shallow:a.shallow??c.shallow??z,scroll:a.scroll??c.scroll??j,startTransition:a.startTransition??c.startTransition??p}};if(a?.limitUrlUpdates?.method==="debounce"||u?.method==="debounce"||c.limitUrlUpdates?.method==="debounce"){F.options.shallow===!0&&console.warn(ne(422));const D=a?.limitUrlUpdates?.timeMs??u?.timeMs??c.limitUrlUpdates?.timeMs??G.timeMs,K=Q.push(F,D,w,O);V<D&&(T=K,V=D)}else{const D=a?.limitUrlUpdates?.timeMs??c?.limitUrlUpdates?.timeMs??u?.timeMs??a.throttleMs??c.throttleMs??m;R.push(Q.abort(x)),L.push(F,D),P=!0}}const J=R.reduce((A,y)=>y(A),P?L.flush(w,O):L.getPendingPromise(w));return T??J},[i,q,z,j,m,u?.method,u?.timeMs,p,o,w.updateUrl,w.getSearchParamsSnapshot,w.rateLimitFactor,O,C]);return[(0,h.useMemo)(()=>W(M,C),[M,C]),Y]}function $(e,t,r,n,O,q){let j=!1;const z=Object.entries(e).reduce((m,[u,f])=>{const p=t?.[u]??u,b=n[p],i=f.type==="multi"?[]:null,o=b===void 0?(f.type==="multi"?r?.getAll(p):r?.get(p))??i:b;return O&&q&&te(O[p]??i,o)?(m[u]=q[u]??null,m):(j=!0,m[u]=(ae(o)?null:X(f.parse,o,p))??null,O&&(O[p]=o),m)},{});if(!j){const m=Object.keys(e),u=Object.keys(q??{});j=m.length!==u.length||m.some(f=>!u.includes(f))}return{state:z,hasChanged:j}}function W(e,t){return Object.fromEntries(Object.keys(e).map(r=>[r,e[r]??t[r]??null]))}function qe(e,t={}){const{parse:r,type:n,serialize:O,eq:q,defaultValue:j,...z}=t,[{[e]:m},u]=ie({[e]:{parse:r??(f=>f),type:n,serialize:O,eq:q,defaultValue:j}},z);return[m,(0,h.useCallback)((f,p={})=>u(b=>({[e]:typeof f=="function"?f(b[e]):f}),p),[e,u])]}export{qe as n,ye as t};
@@ -1 +1 @@
1
- import{r as $}from"./rolldown-runtime-Bnw7wDfq.js";import{nt as F}from"./icons-BywMJ5og.js";import{Ot as W,S as I,_ as Q,b as U,g as V,h as X,v as Y,x as Z,y as B}from"./radix-ui-C0u6gLux.js";import{Dt as w,Tt as O}from"./index-D9Wxg2ot.js";var d=W();function ve({...e}){return(0,d.jsx)(Z,{"data-slot":"alert-dialog",...e})}function G({...e}){return(0,d.jsx)(U,{"data-slot":"alert-dialog-portal",...e})}function J({className:e,...t}){return(0,d.jsx)(B,{"data-slot":"alert-dialog-overlay",className:w("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/80 duration-100 supports-backdrop-filter:backdrop-blur-xs fixed inset-0 z-50",e),...t})}function ke({className:e,size:t="default",...a}){return(0,d.jsxs)(G,{children:[(0,d.jsx)(J,{}),(0,d.jsx)(Q,{"data-slot":"alert-dialog-content","data-size":t,className:w("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 bg-background ring-foreground/10 gap-3 rounded-xl p-4 ring-1 duration-100 data-[size=default]:max-w-xs data-[size=sm]:max-w-64 data-[size=default]:sm:max-w-sm group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 outline-none",e),...a})]})}function we({className:e,...t}){return(0,d.jsx)("div",{"data-slot":"alert-dialog-header",className:w("grid grid-rows-[auto_1fr] place-items-center gap-1 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function be({className:e,...t}){return(0,d.jsx)("div",{"data-slot":"alert-dialog-footer",className:w("flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",e),...t})}function Ce({className:e,...t}){return(0,d.jsx)(I,{"data-slot":"alert-dialog-title",className:w("text-sm font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function Le({className:e,...t}){return(0,d.jsx)(Y,{"data-slot":"alert-dialog-description",className:w("text-muted-foreground *:[a]:hover:text-foreground text-xs/relaxed text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3",e),...t})}function Ae({className:e,variant:t="default",size:a="default",...i}){return(0,d.jsx)(O,{variant:t,size:a,asChild:!0,children:(0,d.jsx)(X,{"data-slot":"alert-dialog-action",className:w(e),...i})})}function je({className:e,variant:t="outline",size:a="default",...i}){return(0,d.jsx)(O,{variant:t,size:a,asChild:!0,children:(0,d.jsx)(V,{"data-slot":"alert-dialog-cancel",className:w(e),...i})})}function Se({className:e,...t}){return(0,d.jsx)("kbd",{"data-slot":"kbd",className:w("bg-muted text-muted-foreground border [[data-slot=tooltip-content]_&]:bg-background/20 [[data-slot=tooltip-content]_&]:text-background dark:[[data-slot=tooltip-content]_&]:bg-background/10 h-5 w-fit min-w-5 gap-1 rounded-xs px-1 font-sans text-[0.625rem] font-medium [&_svg:not([class*='size-'])]:size-3 pointer-events-none inline-flex items-center justify-center select-none",e),...t})}var m=$(F(),1),R=["shift","alt","meta","mod","ctrl","control"],ee={esc:"escape",return:"enter",left:"arrowleft",right:"arrowright",up:"arrowup",down:"arrowdown",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",OSLeft:"meta",OSRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function b(e){return(ee[e.trim()]||e.trim()).toLowerCase().replace(/key|digit|numpad/,"")}function q(e){return R.includes(e)}function S(e,t=","){return e.toLowerCase().split(t)}function E(e,t="+",a=">",i=!1,s,u){let n=[],p=!1;e=e.trim(),e.includes(a)?(p=!0,n=e.toLocaleLowerCase().split(a).map(f=>b(f))):n=e.toLocaleLowerCase().split(t).map(f=>b(f));const l={alt:n.includes("alt"),ctrl:n.includes("ctrl")||n.includes("control"),shift:n.includes("shift"),meta:n.includes("meta"),mod:n.includes("mod"),useKey:i},L=n.filter(f=>!R.includes(f));return{...l,keys:L,description:s,isSequence:p,hotkey:e,metadata:u}}typeof document<"u"&&(document.addEventListener("keydown",e=>{e.code!==void 0&&H([b(e.code)])}),document.addEventListener("keyup",e=>{e.code!==void 0&&P([b(e.code)])})),typeof window<"u"&&(window.addEventListener("blur",()=>{k.clear()}),window.addEventListener("contextmenu",()=>{setTimeout(()=>{k.clear()},0)}));var k=new Set;function K(e){return Array.isArray(e)}function te(e,t=","){return(K(e)?e:e.split(t)).every(a=>k.has(a.trim().toLowerCase()))}function H(e){const t=Array.isArray(e)?e:[e];k.has("meta")&&k.forEach(a=>{q(a)||k.delete(a.toLowerCase())}),t.forEach(a=>{k.add(a.toLowerCase())})}function P(e){e==="meta"?k.clear():(Array.isArray(e)?e:[e]).forEach(t=>{k.delete(t.toLowerCase())})}function ae(e,t,a){(typeof a=="function"&&a(e,t)||a===!0)&&e.preventDefault()}function oe(e,t,a){return typeof a=="function"?a(e,t):a===!0||a===void 0}var re=["input","textarea","select","searchbox","slider","spinbutton","menuitem","menuitemcheckbox","menuitemradio","option","radio","textbox"];function ne(e){return T(e,re)}function T(e,t=!1){const{target:a,composed:i}=e;let s,u;return ie(a)&&i?(s=e.composedPath()[0]&&e.composedPath()[0].tagName,u=e.composedPath()[0]&&e.composedPath()[0].role):(s=a&&a.tagName,u=a&&a.role),K(t)?!!(s&&t&&t.some(n=>n.toLowerCase()===s.toLowerCase()||n===u)):!!(s&&t&&t)}function ie(e){return!!e.tagName&&!e.tagName.startsWith("-")&&e.tagName.includes("-")}function se(e,t){return e.length===0&&t?!1:t?e.some(a=>t.includes(a))||e.includes("*"):!0}var le=(e,t,a=!1)=>{const{alt:i,meta:s,mod:u,shift:n,ctrl:p,keys:l,useKey:L}=t,{code:f,key:o,ctrlKey:C,metaKey:x,shiftKey:g,altKey:y}=e,c=b(f);if(L){if(l?.length===1&&l.includes(o.toLowerCase())){if(!a){if(i!==y||n!==g)return!1;if(u){if(!x&&!C)return!1}else if(s!==x||p!==C)return!1}return!0}return!1}if(!l?.includes(c)&&!["ctrl","control","unknown","meta","alt","shift","os"].includes(c))return!1;if(!a){if(i!==y&&c!=="alt"||n!==g&&c!=="shift")return!1;if(u){if(!x&&!C)return!1}else if(s!==x&&c!=="meta"&&c!=="os"||p!==C&&c!=="ctrl"&&c!=="control")return!1}return l&&l.length===1&&l.includes(c)?!0:l&&l.length>0?l.includes(c)?te(l):!1:!l||l.length===0},de=(0,m.createContext)(void 0),ce=()=>(0,m.useContext)(de);function M(e,t){return e&&t&&typeof e=="object"&&typeof t=="object"?Object.keys(e).length===Object.keys(t).length&&Object.keys(e).reduce((a,i)=>a&&M(e[i],t[i]),!0):e===t}var ue=(0,m.createContext)({hotkeys:[],activeScopes:[],toggleScope:()=>{},enableScope:()=>{},disableScope:()=>{}}),fe=()=>(0,m.useContext)(ue);function me(e){const t=(0,m.useRef)(void 0);return M(t.current,e)||(t.current=e),t.current}var N=e=>{e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},pe=typeof window<"u"?m.useLayoutEffect:m.useEffect;function Ee(e,t,a,i){const s=(0,m.useRef)(null),u=(0,m.useRef)(!1),n=Array.isArray(a)?Array.isArray(i)?void 0:i:a,p=K(e)?e.join(n?.delimiter):e,l=Array.isArray(a)?a:Array.isArray(i)?i:void 0,L=(0,m.useCallback)(t,l??[]),f=(0,m.useRef)(L);l?f.current=L:f.current=t;const o=me(n),{activeScopes:C}=fe(),x=ce();return pe(()=>{if(o?.enabled===!1||!se(C,o?.scopes))return;let g=[],y;const c=(r,z=!1)=>{if(!(ne(r)&&!T(r,o?.enableOnFormTags))){if(s.current!==null){const v=s.current.getRootNode();if((v instanceof Document||v instanceof ShadowRoot)&&v.activeElement!==s.current&&!s.current.contains(v.activeElement)){N(r);return}}r.target?.isContentEditable&&!o?.enableOnContentEditable||S(p,o?.delimiter).forEach(v=>{if(v.includes(o?.splitKey??"+")&&v.includes(o?.sequenceSplitKey??">")){console.warn(`Hotkey ${v} contains both ${o?.splitKey??"+"} and ${o?.sequenceSplitKey??">"} which is not supported.`);return}const h=E(v,o?.splitKey,o?.sequenceSplitKey,o?.useKey,o?.description,o?.metadata);if(h.isSequence){y=setTimeout(()=>{g=[]},o?.sequenceTimeoutMs??1e3);const j=h.useKey?r.key:b(r.code);if(q(j.toLowerCase()))return;if(g.push(j),j!==h.keys?.[g.length-1]){g=[],y&&clearTimeout(y);return}g.length===h.keys?.length&&(f.current(r,h),y&&clearTimeout(y),g=[])}else if(le(r,h,o?.ignoreModifiers)||h.keys?.includes("*")){if(o?.ignoreEventWhen?.(r)||z&&u.current)return;if(ae(r,h,o?.preventDefault),!oe(r,h,o?.enabled)){N(r);return}f.current(r,h),z||(u.current=!0)}})}},D=r=>{r.code!==void 0&&(H(b(r.code)),(o?.keydown===void 0&&o?.keyup!==!0||o?.keydown)&&c(r))},_=r=>{r.code!==void 0&&(P(b(r.code)),u.current=!1,o?.keyup&&c(r,!0))},A=s.current||n?.document||document;return A.addEventListener("keyup",_,n?.eventListenerOptions),A.addEventListener("keydown",D,n?.eventListenerOptions),x&&S(p,o?.delimiter).forEach(r=>{x.addHotkey(E(r,o?.splitKey,o?.sequenceSplitKey,o?.useKey,o?.description,o?.metadata))}),()=>{A.removeEventListener("keyup",_,n?.eventListenerOptions),A.removeEventListener("keydown",D,n?.eventListenerOptions),x&&S(p,o?.delimiter).forEach(r=>{x.removeHotkey(E(r,o?.splitKey,o?.sequenceSplitKey,o?.useKey,o?.description,o?.metadata))}),g=[],y&&clearTimeout(y)}},[p,o,C]),s}export{je as a,be as c,Ae as i,we as l,Se as n,ke as o,ve as r,Le as s,Ee as t,Ce as u};
1
+ import{r as $}from"./rolldown-runtime-Bnw7wDfq.js";import{nt as F}from"./icons-BywMJ5og.js";import{Ot as W,S as I,_ as Q,b as U,g as V,h as X,v as Y,x as Z,y as B}from"./radix-ui-C0u6gLux.js";import{Et as w,wt as O}from"./index-B8u-3J3b.js";var d=W();function ve({...e}){return(0,d.jsx)(Z,{"data-slot":"alert-dialog",...e})}function G({...e}){return(0,d.jsx)(U,{"data-slot":"alert-dialog-portal",...e})}function J({className:e,...t}){return(0,d.jsx)(B,{"data-slot":"alert-dialog-overlay",className:w("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/80 duration-100 supports-backdrop-filter:backdrop-blur-xs fixed inset-0 z-50",e),...t})}function ke({className:e,size:t="default",...a}){return(0,d.jsxs)(G,{children:[(0,d.jsx)(J,{}),(0,d.jsx)(Q,{"data-slot":"alert-dialog-content","data-size":t,className:w("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 bg-background ring-foreground/10 gap-3 rounded-xl p-4 ring-1 duration-100 data-[size=default]:max-w-xs data-[size=sm]:max-w-64 data-[size=default]:sm:max-w-sm group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 outline-none",e),...a})]})}function we({className:e,...t}){return(0,d.jsx)("div",{"data-slot":"alert-dialog-header",className:w("grid grid-rows-[auto_1fr] place-items-center gap-1 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function be({className:e,...t}){return(0,d.jsx)("div",{"data-slot":"alert-dialog-footer",className:w("flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",e),...t})}function Ce({className:e,...t}){return(0,d.jsx)(I,{"data-slot":"alert-dialog-title",className:w("text-sm font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function Le({className:e,...t}){return(0,d.jsx)(Y,{"data-slot":"alert-dialog-description",className:w("text-muted-foreground *:[a]:hover:text-foreground text-xs/relaxed text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3",e),...t})}function Ae({className:e,variant:t="default",size:a="default",...i}){return(0,d.jsx)(O,{variant:t,size:a,asChild:!0,children:(0,d.jsx)(X,{"data-slot":"alert-dialog-action",className:w(e),...i})})}function je({className:e,variant:t="outline",size:a="default",...i}){return(0,d.jsx)(O,{variant:t,size:a,asChild:!0,children:(0,d.jsx)(V,{"data-slot":"alert-dialog-cancel",className:w(e),...i})})}function Se({className:e,...t}){return(0,d.jsx)("kbd",{"data-slot":"kbd",className:w("bg-muted text-muted-foreground border [[data-slot=tooltip-content]_&]:bg-background/20 [[data-slot=tooltip-content]_&]:text-background dark:[[data-slot=tooltip-content]_&]:bg-background/10 h-5 w-fit min-w-5 gap-1 rounded-xs px-1 font-sans text-[0.625rem] font-medium [&_svg:not([class*='size-'])]:size-3 pointer-events-none inline-flex items-center justify-center select-none",e),...t})}var m=$(F(),1),R=["shift","alt","meta","mod","ctrl","control"],ee={esc:"escape",return:"enter",left:"arrowleft",right:"arrowright",up:"arrowup",down:"arrowdown",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",OSLeft:"meta",OSRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function b(e){return(ee[e.trim()]||e.trim()).toLowerCase().replace(/key|digit|numpad/,"")}function q(e){return R.includes(e)}function S(e,t=","){return e.toLowerCase().split(t)}function E(e,t="+",a=">",i=!1,s,u){let n=[],p=!1;e=e.trim(),e.includes(a)?(p=!0,n=e.toLocaleLowerCase().split(a).map(f=>b(f))):n=e.toLocaleLowerCase().split(t).map(f=>b(f));const l={alt:n.includes("alt"),ctrl:n.includes("ctrl")||n.includes("control"),shift:n.includes("shift"),meta:n.includes("meta"),mod:n.includes("mod"),useKey:i},L=n.filter(f=>!R.includes(f));return{...l,keys:L,description:s,isSequence:p,hotkey:e,metadata:u}}typeof document<"u"&&(document.addEventListener("keydown",e=>{e.code!==void 0&&H([b(e.code)])}),document.addEventListener("keyup",e=>{e.code!==void 0&&P([b(e.code)])})),typeof window<"u"&&(window.addEventListener("blur",()=>{k.clear()}),window.addEventListener("contextmenu",()=>{setTimeout(()=>{k.clear()},0)}));var k=new Set;function K(e){return Array.isArray(e)}function te(e,t=","){return(K(e)?e:e.split(t)).every(a=>k.has(a.trim().toLowerCase()))}function H(e){const t=Array.isArray(e)?e:[e];k.has("meta")&&k.forEach(a=>{q(a)||k.delete(a.toLowerCase())}),t.forEach(a=>{k.add(a.toLowerCase())})}function P(e){e==="meta"?k.clear():(Array.isArray(e)?e:[e]).forEach(t=>{k.delete(t.toLowerCase())})}function ae(e,t,a){(typeof a=="function"&&a(e,t)||a===!0)&&e.preventDefault()}function oe(e,t,a){return typeof a=="function"?a(e,t):a===!0||a===void 0}var re=["input","textarea","select","searchbox","slider","spinbutton","menuitem","menuitemcheckbox","menuitemradio","option","radio","textbox"];function ne(e){return T(e,re)}function T(e,t=!1){const{target:a,composed:i}=e;let s,u;return ie(a)&&i?(s=e.composedPath()[0]&&e.composedPath()[0].tagName,u=e.composedPath()[0]&&e.composedPath()[0].role):(s=a&&a.tagName,u=a&&a.role),K(t)?!!(s&&t&&t.some(n=>n.toLowerCase()===s.toLowerCase()||n===u)):!!(s&&t&&t)}function ie(e){return!!e.tagName&&!e.tagName.startsWith("-")&&e.tagName.includes("-")}function se(e,t){return e.length===0&&t?!1:t?e.some(a=>t.includes(a))||e.includes("*"):!0}var le=(e,t,a=!1)=>{const{alt:i,meta:s,mod:u,shift:n,ctrl:p,keys:l,useKey:L}=t,{code:f,key:o,ctrlKey:C,metaKey:x,shiftKey:g,altKey:y}=e,c=b(f);if(L){if(l?.length===1&&l.includes(o.toLowerCase())){if(!a){if(i!==y||n!==g)return!1;if(u){if(!x&&!C)return!1}else if(s!==x||p!==C)return!1}return!0}return!1}if(!l?.includes(c)&&!["ctrl","control","unknown","meta","alt","shift","os"].includes(c))return!1;if(!a){if(i!==y&&c!=="alt"||n!==g&&c!=="shift")return!1;if(u){if(!x&&!C)return!1}else if(s!==x&&c!=="meta"&&c!=="os"||p!==C&&c!=="ctrl"&&c!=="control")return!1}return l&&l.length===1&&l.includes(c)?!0:l&&l.length>0?l.includes(c)?te(l):!1:!l||l.length===0},de=(0,m.createContext)(void 0),ce=()=>(0,m.useContext)(de);function M(e,t){return e&&t&&typeof e=="object"&&typeof t=="object"?Object.keys(e).length===Object.keys(t).length&&Object.keys(e).reduce((a,i)=>a&&M(e[i],t[i]),!0):e===t}var ue=(0,m.createContext)({hotkeys:[],activeScopes:[],toggleScope:()=>{},enableScope:()=>{},disableScope:()=>{}}),fe=()=>(0,m.useContext)(ue);function me(e){const t=(0,m.useRef)(void 0);return M(t.current,e)||(t.current=e),t.current}var N=e=>{e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},pe=typeof window<"u"?m.useLayoutEffect:m.useEffect;function Ee(e,t,a,i){const s=(0,m.useRef)(null),u=(0,m.useRef)(!1),n=Array.isArray(a)?Array.isArray(i)?void 0:i:a,p=K(e)?e.join(n?.delimiter):e,l=Array.isArray(a)?a:Array.isArray(i)?i:void 0,L=(0,m.useCallback)(t,l??[]),f=(0,m.useRef)(L);l?f.current=L:f.current=t;const o=me(n),{activeScopes:C}=fe(),x=ce();return pe(()=>{if(o?.enabled===!1||!se(C,o?.scopes))return;let g=[],y;const c=(r,z=!1)=>{if(!(ne(r)&&!T(r,o?.enableOnFormTags))){if(s.current!==null){const v=s.current.getRootNode();if((v instanceof Document||v instanceof ShadowRoot)&&v.activeElement!==s.current&&!s.current.contains(v.activeElement)){N(r);return}}r.target?.isContentEditable&&!o?.enableOnContentEditable||S(p,o?.delimiter).forEach(v=>{if(v.includes(o?.splitKey??"+")&&v.includes(o?.sequenceSplitKey??">")){console.warn(`Hotkey ${v} contains both ${o?.splitKey??"+"} and ${o?.sequenceSplitKey??">"} which is not supported.`);return}const h=E(v,o?.splitKey,o?.sequenceSplitKey,o?.useKey,o?.description,o?.metadata);if(h.isSequence){y=setTimeout(()=>{g=[]},o?.sequenceTimeoutMs??1e3);const j=h.useKey?r.key:b(r.code);if(q(j.toLowerCase()))return;if(g.push(j),j!==h.keys?.[g.length-1]){g=[],y&&clearTimeout(y);return}g.length===h.keys?.length&&(f.current(r,h),y&&clearTimeout(y),g=[])}else if(le(r,h,o?.ignoreModifiers)||h.keys?.includes("*")){if(o?.ignoreEventWhen?.(r)||z&&u.current)return;if(ae(r,h,o?.preventDefault),!oe(r,h,o?.enabled)){N(r);return}f.current(r,h),z||(u.current=!0)}})}},_=r=>{r.code!==void 0&&(H(b(r.code)),(o?.keydown===void 0&&o?.keyup!==!0||o?.keydown)&&c(r))},D=r=>{r.code!==void 0&&(P(b(r.code)),u.current=!1,o?.keyup&&c(r,!0))},A=s.current||n?.document||document;return A.addEventListener("keyup",D,n?.eventListenerOptions),A.addEventListener("keydown",_,n?.eventListenerOptions),x&&S(p,o?.delimiter).forEach(r=>{x.addHotkey(E(r,o?.splitKey,o?.sequenceSplitKey,o?.useKey,o?.description,o?.metadata))}),()=>{A.removeEventListener("keyup",D,n?.eventListenerOptions),A.removeEventListener("keydown",_,n?.eventListenerOptions),x&&S(p,o?.delimiter).forEach(r=>{x.removeHotkey(E(r,o?.splitKey,o?.sequenceSplitKey,o?.useKey,o?.description,o?.metadata))}),g=[],y&&clearTimeout(y)}},[p,o,C]),s}export{je as a,be as c,Ae as i,we as l,Se as n,ke as o,ve as r,Le as s,Ee as t,Ce as u};