wizards 0.3.5 → 0.3.7
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/apps/runtime/dist/agents/studio-assistant.js +285 -31
- package/apps/runtime/dist/agents/website.js +256 -34
- package/apps/runtime/dist/db/schema.js +1 -1
- package/apps/runtime/dist/docs/user/test-and-share.md +21 -11
- package/apps/runtime/dist/documents/parse.js +14 -0
- package/apps/runtime/dist/engine/steps.js +42 -6
- package/apps/runtime/dist/engine/template.js +50 -3
- package/apps/runtime/dist/film/project.js +54 -4
- package/apps/runtime/dist/routes/studio.js +52 -3
- package/apps/runtime/dist/services/brand.js +6 -3
- package/apps/runtime/dist/services/project-files.js +59 -3
- package/apps/runtime/dist/services/projects.js +150 -2
- package/apps/runtime/dist/services/wizards.js +25 -0
- package/apps/web/dist/assets/AboutDialog-C0dN86zd.js +1 -0
- package/apps/web/dist/assets/{ChangelogDialog-VEBTlC3f.js → ChangelogDialog-Cv81t7tj.js} +1 -1
- package/apps/web/dist/assets/ChatView-uogJ3nht.js +10 -0
- package/apps/web/dist/assets/EditorPage-n8YuTh6j.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-86xWWfdk.js → FlowPreview-D4dp1MWS.js} +1 -1
- package/apps/web/dist/assets/{Harness-CF6H2TYJ.js → Harness-v7r0e6vK.js} +2 -2
- package/apps/web/dist/assets/NewWizardChannels-Be-7VhBi.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-C8hPvrK8.js +7 -0
- package/apps/web/dist/assets/ProjectPage-B686ArYy.js +1 -0
- package/apps/web/dist/assets/PublicRunner-DeCpVfZP.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-mhKW496R.js → ReadOnly-B-UCgnqW.js} +1 -1
- package/apps/web/dist/assets/RunDrawer-C6pzi8AJ.js +4 -0
- package/apps/web/dist/assets/{RunnerView-CTRFgyu5.js → RunnerView-Deenymq0.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-CK6L0yEe.js +1 -0
- package/apps/web/dist/assets/SetupPage-9CH3qXdH.js +1 -0
- package/apps/web/dist/assets/SharePage-B778xUFo.js +1 -0
- package/apps/web/dist/assets/changelog-DCJo2mbx.js +1 -0
- package/apps/web/dist/assets/{circle-alert-CYs622_r.js → circle-alert-DLvC9ePT.js} +1 -1
- package/apps/web/dist/assets/{esm-B52LIMhP.js → esm-BJskogLD.js} +1 -1
- package/apps/web/dist/assets/index-D6hUM8NU.css +1 -0
- package/apps/web/dist/assets/index-Df6UxElH.js +12 -0
- package/apps/web/dist/assets/{lock-BvSWZOin.js → lock-DR7NakPn.js} +1 -1
- package/apps/web/dist/assets/{phone-CI2Flerg.js → phone-BORh3jfv.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-BOOPxcJH.js → settings-menu-DV5D91TD.js} +1 -1
- package/apps/web/dist/assets/{ui-CMdSOoUZ.js → ui-BOCXzzHi.js} +1 -1
- package/apps/web/dist/assets/{upload-Cz9HgBT9.js → upload-B3yv8gsk.js} +1 -1
- package/apps/web/dist/index.html +3 -8
- package/apps/web/dist/mcp/flow.html +2 -2
- package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +3 -3
- package/node_modules/@engenty-wizards/shared/dist/changes.d.ts +22 -0
- package/node_modules/@engenty-wizards/shared/dist/changes.js +61 -0
- package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +8 -8
- package/node_modules/@engenty-wizards/shared/dist/marketplace.d.ts +1 -1
- package/node_modules/@engenty-wizards/shared/dist/projects.d.ts +138 -3
- package/node_modules/@engenty-wizards/shared/dist/projects.js +153 -4
- package/node_modules/@engenty-wizards/shared/dist/wizard-package.d.ts +1 -1
- package/package.json +1 -1
- package/apps/web/dist/assets/AboutDialog-D1N4-3FE.js +0 -1
- package/apps/web/dist/assets/ChatView-DSRUEpb6.js +0 -10
- package/apps/web/dist/assets/EditorPage-UkaHDklX.js +0 -3
- package/apps/web/dist/assets/Marketplace-C-Vz3yEk.js +0 -2
- package/apps/web/dist/assets/NewWizardChannels-Cc7gDitg.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-sY5q-l99.js +0 -7
- package/apps/web/dist/assets/ProjectPage-iSdpJAZS.js +0 -2
- package/apps/web/dist/assets/PublicRunner-BgRXMUxS.js +0 -1
- package/apps/web/dist/assets/RunDrawer-B0gJzdxH.js +0 -4
- package/apps/web/dist/assets/SettingsPage-CBF8i6j6.js +0 -1
- package/apps/web/dist/assets/SetupPage-Fpz9aSLN.js +0 -1
- package/apps/web/dist/assets/SharePage-Dv3Csh4A.js +0 -1
- package/apps/web/dist/assets/brand-BamUjXVr.js +0 -2
- package/apps/web/dist/assets/changelog-ViHoNW7e.js +0 -1
- package/apps/web/dist/assets/index-Bdx1Qity.js +0 -11
- package/apps/web/dist/assets/index-CDdJDojq.css +0 -1
- package/apps/web/dist/assets/session-BEHF6g4Y.js +0 -1
- package/apps/web/dist/assets/useMutation-DKyQXgyj.js +0 -1
- package/apps/web/dist/assets/volume-2-CyQuz1nn.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,r as i}from"./logo-C4V2_3Ar.js";import{Bt as a,Ct as o,Dt as s,It as c,Jt as l,Nt as u,Qt as d,Rt as f,St as p,T as m,Tt as h,Vt as g,Wt as _,Xt as v,Yt as y,Zt as b,an as x,bn as S,bt as C,dn as w,dt as T,en as ee,ft as E,gt as D,hn as O,ht as k,kt as A,l as j,lt as M,mt as N,pt as P,sn as F,ut as I,vn as te,wt as ne,xn as re,xt as L,yn as ie,yt as R}from"./ui-BOCXzzHi.js";import{_ as ae,a as oe,b as z,c as se,d as ce,f as B,g as le,h as ue,i as de,l as fe,m as pe,n as V,o as me,p as he,s as ge,u as _e,v as ve,x as H,y as U}from"./RunDrawer-C6pzi8AJ.js";import{t as W}from"./phone-BORh3jfv.js";import{n as ye,r as be,t as xe}from"./ReadOnly-B-UCgnqW.js";import{t as G}from"./upload-B3yv8gsk.js";import{$ as Se,At as Ce,B as we,G as K,H as Te,I as q,J as Ee,K as De,Kt as Oe,L as J,Ot as ke,Q as Ae,R as je,U as Y,V as Me,Vt as Ne,W as Pe,Wt as Fe,X as Ie,Xt as Le,Y as Re,Yt as ze,Z as X,Zt as Be,_ as Ve,an as He,at as Ue,ct as We,d as Ge,dn as Ke,et as qe,f as Je,g as Ye,it as Xe,kt as Ze,l as Qe,mt as $e,nt as et,on as tt,ot as nt,p as rt,q as it,rt as at,s as ot,st,tt as ct,u as lt,v as ut,yn as dt,z as ft}from"./index-Df6UxElH.js";import{a as Z,c as pt,f as mt,i as ht,n as gt,o as _t,r as vt,s as yt,t as bt,u as xt}from"./settings-menu-DV5D91TD.js";import{t as St}from"./RunnerView-Deenymq0.js";var Ct={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};Ct.node;var wt=w(Ct),Tt={name:`box`,size:24,node:[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]};Tt.node;var Et=w(Tt),Dt={name:`case-upper`,size:24,node:[[`path`,{d:`M15 11h4.5a1 1 0 0 1 0 5h-4a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h3a1 1 0 0 1 0 5`,key:`nxs35`}],[`path`,{d:`m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16`,key:`d5nyq2`}],[`path`,{d:`M3.304 13h6.392`,key:`1q3zxz`}]]};Dt.node;var Ot=w(Dt),kt={name:`folder-plus`,size:24,node:[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]};kt.node;var At=w(kt),jt={name:`grid-2x2`,size:24,node:[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]],aliases:[`grid-2-x-2`]};jt.node;var Mt=w(jt),Nt={name:`layers`,size:24,node:[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]],aliases:[`layers-3`]};Nt.node;var Pt=w(Nt),Ft={name:`layout-grid`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]};Ft.node;var It=w(Ft),Lt={name:`link`,size:24,node:[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]};Lt.node;var Rt=w(Lt),zt={name:`list`,size:24,node:[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]};zt.node;var Bt=w(zt),Vt={name:`music`,size:24,node:[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]};Vt.node;var Ht=w(Vt),Q=e(t(),1),$=e(n(),1),Ut={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function Wt({file:e,actions:t}){let[n,r]=(0,Q.useState)(e.description),i=(0,Q.useRef)(e.description),a=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,Q.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let o=e.status===`pending`&&!n;return t.readOnly?n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,$.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:A(o?`project.describing`:`project.description`),onChange:e=>r(e.target.value),onBlur:()=>{n.trim()!==e.description&&(i.current=n.trim(),t.describe(e.id,n.trim()))},className:`-mx-1 block w-[calc(100%+0.5rem)] resize-none overflow-hidden rounded-md bg-transparent px-1 py-0.5 text-[0.8125rem] text-ink-2 leading-snug outline-none transition placeholder:text-ink-4 hover:bg-paper-2 focus:bg-card focus:text-ink focus:ring-1 focus:ring-border`})}function Gt(e,t){confirm(A(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function Kt({projectId:e,file:t,small:n}){let r=Xe(e,t.id);if(t.mime.startsWith(`image/`))return(0,$.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:h(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)});if(t.mime.startsWith(`video/`))return(0,$.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`});if(t.mime.startsWith(`font/`))return(0,$.jsx)(qt,{src:r,small:n});let i=n?`size-5`:`size-7`;return(0,$.jsxs)(`div`,{className:`flex size-full flex-col items-center justify-center gap-1.5 text-ink-3`,children:[t.mime.startsWith(`audio/`)?(0,$.jsx)(Ht,{className:i}):t.mime===`application/pdf`?(0,$.jsx)(v,{className:i}):t.mime===`application/json`?(0,$.jsx)(c,{className:i}):t.mime.startsWith(`model/`)?(0,$.jsx)(Et,{className:i}):(0,$.jsx)(y,{className:i}),n?null:(0,$.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wide`,children:t.mime===`application/json`?`Lottie / JSON`:t.mime.split(`/`).pop()})]})}function qt({src:e,small:t}){let[n,r]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{let t=`asset-${e.split(`/`).slice(-2,-1)[0]}`;new FontFace(t,`url("${e}")`).load().then(e=>{document.fonts.add(e),r(t)}).catch(()=>r(null))},[e]),(0,$.jsx)(`div`,{className:h(`flex size-full items-center justify-center text-ink`,t?`text-[1.25rem]`:`text-[2.75rem]`),style:n?{fontFamily:`"${n}"`}:void 0,children:`Aa`})}var Jt=`application/x-wizards-logo`;function Yt({projectId:e,kind:t,files:n,actions:r,accept:i,addLabel:o,onUpload:s,onPreview:c,mainId:l,onMakeMain:d,moveTo:f,onRemove:p}){let m=e=>p?p(e):Gt(e,r);return(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map(n=>(0,$.jsxs)(`div`,{draggable:f&&!r.readOnly?!0:void 0,onDragStart:e=>e.dataTransfer.setData(Jt,n.id),className:`group relative flex flex-col gap-1.5 rounded-lg bg-paper p-2 pb-2.5 ring-1 ring-border-soft`,children:[n.id===l?(0,$.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,$.jsx)(T,{tone:`ember`,children:A(`project.logoMain`)})}):null,(0,$.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?Ut:void 0,children:[c&&n.mime.startsWith(`image/`)?(0,$.jsx)(`button`,{type:`button`,"aria-label":`${A(`project.preview`)}: ${n.name}`,onClick:()=>c(n),className:`block size-full cursor-zoom-in`,children:(0,$.jsx)(Kt,{projectId:e,file:n})}):(0,$.jsx)(Kt,{projectId:e,file:n}),(0,$.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[c?(0,$.jsx)(N,{label:A(`project.preview`),onClick:()=>c(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(Ke,{className:`size-4`})}):null,d&&n.id!==l&&!r.readOnly?(0,$.jsx)(N,{label:A(`project.logoMakeMain`),onClick:()=>d(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(Oe,{className:`size-4`})}):null,f&&!r.readOnly?(0,$.jsx)(we,{options:f.options,value:f.current(n),onChange:e=>f.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,$.jsx)(N,{label:A(`project.remove`),onClick:()=>m(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,$.jsx)(u,{className:`size-4`})})]})]}),t===`asset`?(0,$.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:n.name,children:n.name}):null,(0,$.jsx)(Wt,{file:n,actions:r})]},n.id)),o&&!r.readOnly?(0,$.jsxs)(je,{accept:i,multiple:!1,onFiles:e=>s?s(e):r.upload(t,e),className:`min-h-28 flex-col p-3`,children:[r.busy?(0,$.jsx)(C,{className:`size-5`}):(0,$.jsx)(a,{className:`size-5`}),o]}):null]})}function Xt({kind:e,fetchUrl:t,onAdded:n,onClose:r}){let[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),m=async()=>{s(!0),l(null);try{let a=await t(i.trim());a.file?(n([a.file]),r()):a.candidates?.length?(d(a.candidates),p([a.candidates[0].url])):l(A(e===`logo`?`project.logoNoneFound`:`project.assetNoneFound`))}catch(e){l(e.message)}s(!1)},g=async()=>{s(!0),l(null);let e=[];try{for(let n of f){let r=await t(n);r.file&&e.push(r.file)}}catch(e){l(e.message)}s(!1),e.length&&n(e),e.length===f.length&&r()};return(0,$.jsx)(E,{open:!0,onClose:r,wide:u?!0:void 0,title:A(u?e===`logo`?`project.logoFound`:`project.assetFound`:e===`logo`?`project.logoFromUrl`:`project.assetFromUrl`),children:u?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:A(e===`logo`?`project.logoFoundHint`:`project.assetFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-3`,children:u.map(t=>{let n=f.includes(t.url);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>p(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:h(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:Ut,children:[(0,$.jsx)(`img`,{src:t.url,alt:``,className:h(`size-full`,e===`logo`?`object-contain p-3`:`object-cover`)}),n?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(x,{className:`size-3.5`})}):null]},t.url)})}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(M,{variant:`ghost`,onClick:()=>d(null),children:A(`run.back`)}),(0,$.jsx)(M,{busy:o,disabled:!f.length,onClick:()=>void g(),children:f.length>1?A(`project.addMany`,{n:f.length}):A(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.logoUrl`)}),(0,$.jsx)(k,{autoFocus:!0,value:i,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>a(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:A(e===`logo`?`project.logoUrlHint`:`project.assetUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(M,{variant:`ghost`,onClick:r,children:A(`common.cancel`)}),(0,$.jsx)(M,{type:`submit`,busy:o,disabled:!i.trim(),children:A(`run.next`)})]})]})})}function Zt(e,t,n){return i({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>j.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function Qt(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var $t=e=>[Qt(e),e.pages?A(`project.pages`,{n:e.pages}):null,at(e.size)].filter(Boolean).join(` · `),en=2e5;function tn({projectId:e,fileId:t,readOnly:n,onGone:i}){let a=r(),o=We(e),s=pe(e),c=nt(e,n),l=o.data?.files.find(e=>e.id===t),d=l?l.mime===`application/pdf`||l.mime.startsWith(`image/`):!1,[p,m]=(0,Q.useState)(null);if(!l)return o.isLoading?(0,$.jsx)(C,{className:`mx-auto text-ink-3`}):null;let g=p??(d?`original`:`text`),_=s.data?.items.find(e=>e.key===`f:${l.id}`),v=Xe(e,l.id),y=(e,t)=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":g===e,onClick:()=>m(e),className:h(`rounded-full px-3 py-1 text-[0.8125rem] transition`,g===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,$.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:l.name}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:$t(l)}),(0,$.jsx)(`a`,{href:v,target:`_blank`,rel:`noreferrer`,"aria-label":A(`project.openOriginal`),title:A(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(b,{className:`size-4`})}),n?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{label:A(`project.reindex`),onClick:async()=>{await c.reindex(l.id),await a.invalidateQueries({queryKey:[`knowledge`,e]})},children:(0,$.jsx)(f,{className:`size-4`})}),(0,$.jsx)(N,{label:A(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(A(`data.confirmDelete`,{title:l.name}))&&(await c.remove(l.id),await a.invalidateQueries({queryKey:[`knowledge`,e]}),i())},children:(0,$.jsx)(u,{className:`size-4`})})]})]}),(0,$.jsx)(B,{projectId:e,itemKey:`f:${l.id}`,has:_?.categories??[],originLabel:_?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,$.jsx)(`div`,{className:`px-1`,children:(0,$.jsx)(Wt,{file:l,actions:c})}),l.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:l.error}):null,(0,$.jsxs)(I,{className:`flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[d?y(`original`,A(`project.original`)):null,y(`text`,A(`project.readText`))]}),g===`original`?l.mime===`application/pdf`?(0,$.jsx)(`iframe`,{src:v,title:l.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,$.jsx)(`img`,{src:v,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,$.jsx)(nn,{projectId:e,file:l})]})]})}function nn({projectId:e,file:t}){let n=Zt(e,t,en);return n.isLoading||t.status===`pending`?(0,$.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,$.jsx)(C,{})}):n.data?.text?(0,$.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,$.jsx)(m,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:A(`project.textCut`,{shown:n.data.text.length.toLocaleString(),total:n.data.chars.toLocaleString()})}):null]}):(0,$.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:A(`project.noText`)})}var rn=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,an=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),at(e.size)].filter(Boolean).join(` · `);function on({projectId:e,file:t,actions:n,onClose:r}){let i=Xe(e,t.id);return(0,$.jsxs)(E,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,$.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:an(t)}),(0,$.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":A(`project.openOriginal`),title:A(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(b,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:Ut,children:(0,$.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,$.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,$.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(Wt,{file:t,actions:n})})]})}function sn({projectId:e,file:t,actions:n,moveTo:r,onPreview:i,onRemove:a}){return(0,$.jsxs)(`li`,{className:`group/row flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`${A(`project.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,$.jsx)(Kt,{projectId:e,file:t,small:!0})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:an(t)})]}),(0,$.jsx)(Wt,{file:t,actions:n})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start opacity-0 transition focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:[(0,$.jsx)(N,{label:A(`project.preview`),onClick:i,children:(0,$.jsx)(Ke,{className:`size-4`})}),r&&!n.readOnly?(0,$.jsx)(we,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,$.jsx)(N,{label:A(`project.remove`),onClick:a,className:`hover:text-rose`,children:(0,$.jsx)(u,{className:`size-4`})})]})]})}function cn({section:e,onSave:t,onRemove:n,onClose:r}){let[i,a]=(0,Q.useState)(e?.title??``);return(0,$.jsx)(E,{open:!0,onClose:r,title:A(e?`project.assetSectionRename`:`project.assetSectionAdd`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&(t(i.trim()),r())},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.assetSectionName`)}),(0,$.jsx)(k,{autoFocus:!0,value:i,maxLength:80,placeholder:A(`project.assetSectionTitle`),onChange:e=>a(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,$.jsx)(M,{variant:`danger`,onClick:n,children:A(`project.sectionRemove`)}):null,(0,$.jsx)(`span`,{className:`flex-1`}),(0,$.jsx)(M,{variant:`ghost`,onClick:r,children:A(`common.cancel`)}),(0,$.jsx)(M,{type:`submit`,disabled:!i.trim(),children:A(e?`settings.save`:`project.add`)})]})]})})}function ln({projectId:e,data:t,readOnly:n,sections:r,save:i}){let a=nt(e,n),[s,c]=st(`assets`,`cards`),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(r),[h,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(!1),S=(0,Q.useRef)(null),w=Ue({assetSections:p},i),T=t.files.filter(e=>e.kind===`asset`),ee=new Map(T.map(e=>[e.id,e])),E=new Set(p.flatMap(e=>e.assets)),D=p.find(e=>e.id===h)??null,O=D?D.assets.map(e=>ee.get(e)).filter(e=>!!e):T.filter(e=>!E.has(e.id)),k=T.find(e=>e.id===d),j=l.trim().toLowerCase(),M=j?O.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(j)):O,P=(e,t)=>m(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),F=async e=>{let t=D?.id??null;for(let n of await a.upload(`asset`,e))P(n.id,t)},I=e=>{confirm(A(`project.removeConfirm`,{name:e.name}))&&(a.remove(e.id),P(e.id,null))},te=p.length?{options:[{value:``,label:A(`project.assetsGeneral`)},...p.map(e=>({value:e.id,label:e.title||A(`project.sectionUntitled`)}))],current:e=>p.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>P(e.id,t||null)}:void 0,ne=[{label:A(`project.assetUpload`),icon:(0,$.jsx)(G,{className:`size-4 shrink-0`}),onPick:()=>S.current?.click()},{label:A(`project.assetFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>x(!0)},...p.length<X.logoSections?[{label:A(`project.assetSectionAdd`),icon:(0,$.jsx)(At,{className:`size-4 shrink-0`}),onPick:()=>y(`new`)}]:[]],re=p.length||T.length?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`-mx-1 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto px-1 pb-0.5`,children:[p.length?(0,$.jsx)(o,{value:h,onChange:e=>{_(e),u(``)},label:A(`project.assets`),options:[{id:``,label:A(`project.assetsGeneral`)},...p.map(e=>({id:e.id,label:e.title||A(`project.sectionUntitled`)}))]}):null,D&&!n?(0,$.jsx)(N,{label:A(`project.assetSectionRename`),onClick:()=>y(`current`),children:(0,$.jsx)(g,{className:`size-4`})}):null]}),O.length?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,$.jsx)(Te,{value:l,onChange:u,placeholder:A(`project.assetSearch`)})}),(0,$.jsx)(N,{label:A(s===`list`?`project.viewCards`:`project.viewList`),onClick:c,children:s===`list`?(0,$.jsx)(It,{className:`size-4`}):(0,$.jsx)(Bt,{className:`size-4`})})]}):null]}):null;return(0,$.jsxs)(Y,{title:A(`project.assets`),hint:A(`project.assetsHint`),save:w,tabs:re,action:n?null:(0,$.jsx)(q,{entries:ne}),children:[(0,$.jsx)(`input`,{ref:S,type:`file`,multiple:!0,accept:rn,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&F(t)}}),M.length?s===`cards`?(0,$.jsx)(Yt,{projectId:e,kind:`asset`,files:M,actions:a,moveTo:te,onRemove:I,onPreview:e=>f(e.id)}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2`,children:M.map(t=>(0,$.jsx)(sn,{projectId:e,file:t,actions:a,moveTo:te,onPreview:()=>f(t.id),onRemove:()=>I(t)},t.id))}):O.length?null:n?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:A(`project.staysLocal`)}):(0,$.jsxs)(je,{accept:rn,onFiles:e=>void F(e),className:`h-16 w-full`,children:[a.busy?(0,$.jsx)(C,{className:`size-4`}):(0,$.jsx)(G,{className:`size-4`}),A(`project.drop`),` `,(0,$.jsx)(`span`,{className:`underline`,children:A(`project.assetAdd`)})]}),a.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:a.error}):null,k?(0,$.jsx)(on,{projectId:e,file:k,actions:a,onClose:()=>f(null)}):null,v?(0,$.jsx)(cn,{section:v===`current`?D:null,onClose:()=>y(null),onSave:e=>{if(v===`current`&&D)m(t=>t.map(t=>t.id===D.id?{...t,title:e}:t));else{let t=K();m(n=>[...n,{id:t,title:e,assets:[]}]),_(t)}},onRemove:v===`current`&&D?()=>{(!D.assets.length||confirm(A(`project.assetSectionRemoveConfirm`,{name:D.title})))&&(m(e=>e.filter(e=>e.id!==D.id)),_(``),y(null))}:void 0}):null,b?(0,$.jsx)(Xt,{kind:`asset`,onClose:()=>x(!1),fetchUrl:e=>a.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)P(t.id,D?.id??null)}}):null]})}var un=/^#[0-9a-fA-F]{6}$/;async function dn(e,t){let[n,r]=[1920,1080],i=document.createElement(`canvas`);i.width=n,i.height=r;let a=i.getContext(`2d`);if(!a)return;let o=e.angle*Math.PI/180,s;if(e.type===`radial`)s=a.createRadialGradient(n/2,r/2,0,n/2,r/2,Math.hypot(n,r)/2);else if(e.type===`conic`)s=a.createConicGradient(o-Math.PI/2,n/2,r/2);else{let e=Math.abs(n*Math.sin(o))+Math.abs(r*Math.cos(o)),[t,i]=[Math.sin(o)*e/2,-Math.cos(o)*e/2];s=a.createLinearGradient(n/2-t,r/2-i,n/2+t,r/2+i)}for(let t of[...e.stops].sort((e,t)=>e.at-t.at))s.addColorStop(Math.min(1,Math.max(0,t.at/100)),t.color);a.fillStyle=s,a.fillRect(0,0,n,r);let c=await new Promise(e=>i.toBlob(e,`image/png`));if(c){let e=document.createElement(`a`);e.href=URL.createObjectURL(c),e.download=`${t||`gradient`}.png`,e.click(),setTimeout(()=>URL.revokeObjectURL(e.href),5e3)}}var fn={linear:`project.gradientLinear`,radial:`project.gradientRadial`,conic:`project.gradientConic`};function pn({gradient:e,brand:t,onSave:n,onClose:r}){let[i,o]=(0,Q.useState)(e),[s,c]=(0,Q.useState)(qe(e)),[l,d]=(0,Q.useState)(!1),f=e=>{o(e),c(qe(e)),d(!1)},p=(e,t)=>f({...i,stops:i.stops.map((n,r)=>r===e?{...n,...t}:n)}),m=e=>{let t=[...i.stops].sort((e,t)=>e.at-t.at),n=50,r=-1;for(let e=0;e<t.length-1;e++)t[e+1].at-t[e].at>r&&(r=t[e+1].at-t[e].at,n=Math.round((t[e].at+t[e+1].at)/2));f({...i,stops:[...i.stops,{color:e??t[0]?.color??`#888888`,at:n}]})};return(0,$.jsx)(E,{open:!0,onClose:r,wide:!0,title:A(`project.gradientEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:qe(i)}}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,$.jsxs)(`div`,{className:`min-w-48 flex-1`,children:[(0,$.jsx)(D,{children:A(`project.gradientName`)}),(0,$.jsx)(k,{value:i.name,maxLength:80,placeholder:A(`project.gradientNamePlaceholder`),onChange:e=>o({...i,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.gradientType`)}),(0,$.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:Ie.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":i.type===e,onClick:()=>f({...i,type:e}),className:h(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,i.type===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:A(fn[e])},e))})]}),i.type===`radial`?null:(0,$.jsxs)(`div`,{className:`min-w-56`,children:[(0,$.jsx)(D,{children:A(`project.gradientAngle`)}),(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(`input`,{type:`range`,min:0,max:360,value:i.angle,"aria-label":A(`project.gradientAngle`),onChange:e=>f({...i,angle:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-12 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(i.angle),`°`]})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.gradientStops`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:i.stops.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(L,{value:un.test(e.color)?e.color:`#888888`,onChange:e=>p(t,{color:e.target.value})}),(0,$.jsx)(k,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();un.test(n)&&p(t,{color:n.toLowerCase()})},className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsx)(`input`,{type:`range`,min:0,max:100,value:e.at,"aria-label":A(`project.gradientAt`),onChange:e=>p(t,{at:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-10 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(e.at),`%`]}),(0,$.jsx)(N,{label:A(`project.remove`),disabled:i.stops.length<=2,onClick:()=>f({...i,stops:i.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,$.jsx)(u,{className:`size-4`})})]},t))}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[i.stops.length<12?(0,$.jsxs)(M,{variant:`secondary`,size:`sm`,onClick:()=>m(),children:[(0,$.jsx)(a,{className:`size-4`}),` `,A(`project.gradientStopAdd`)]}):null,t.length&&i.stops.length<12?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:A(`project.gradientFromBrand`)}),t.slice(0,10).map(e=>(0,$.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>m(e.value),className:`size-6 rounded-full ring-1 ring-border transition hover:scale-110`,style:{background:e.value}},e.value))]}):null]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:`CSS`}),(0,$.jsx)(k,{value:s,spellCheck:!1,onChange:e=>{c(e.target.value);let t=et(e.target.value);d(!t),t&&o({...i,...t})},className:`font-mono text-[0.8125rem]`}),(0,$.jsx)(`p`,{className:h(`mt-1.5 text-[0.8125rem]`,l?`text-rose`:`text-ink-3`),children:A(l?`project.gradientCssError`:`project.gradientCssHint`)})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(M,{variant:`ghost`,onClick:r,children:A(`common.cancel`)}),(0,$.jsx)(M,{onClick:()=>{n(i),r()},children:A(`settings.save`)})]})]})})}var mn=`flex shrink-0 opacity-0 transition focus-within:opacity-100 group-hover/card:opacity-100 coarse:opacity-100`;function hn({gradient:e,readOnly:t,onEdit:n,onRename:r,onRemove:i}){let a=qe(e),[o,s]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:t,"aria-label":A(`project.gradientEdit`),onClick:n,className:`h-28 rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:{background:a}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-0.5`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:t?(0,$.jsx)(`span`,{className:`text-[0.875rem]`,children:e.name}):(0,$.jsx)(ft,{value:e.name,label:A(`project.gradientName`),placeholder:A(`project.gradientName`),maxLength:80,onChange:r,className:`font-medium text-[0.875rem]`})}),(0,$.jsxs)(`div`,{className:mn,children:[(0,$.jsx)(N,{label:A(o?`project.gradientCopied`:`project.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),s(!0),setTimeout(()=>s(!1),1500)},className:`size-8`,children:(0,$.jsx)(ee,{className:`size-4`})}),(0,$.jsx)(N,{label:A(`project.download`),onClick:()=>void dn(e,e.name),className:`size-8`,children:(0,$.jsx)(d,{className:`size-4`})}),t?null:(0,$.jsx)(N,{label:A(`project.remove`),onClick:i,className:`size-8 hover:text-rose`,children:(0,$.jsx)(u,{className:`size-4`})})]})]})]})}function gn({projectId:e,pattern:t,fileName:n,readOnly:r,onChange:i,onRemove:a}){let o=Xe(e,t.file);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`div`,{className:`h-28 rounded-md ring-1 ring-border-soft`,style:{backgroundImage:`url("${o}")`,backgroundSize:t.tile?`64px`:`cover`,backgroundRepeat:t.tile?`repeat`:`no-repeat`,backgroundPosition:`center`}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-0.5`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:r?(0,$.jsx)(`span`,{className:`text-[0.875rem]`,children:t.name||n}):(0,$.jsx)(ft,{value:t.name,label:A(`project.patternName`),placeholder:n,maxLength:80,onChange:e=>i({name:e}),className:`font-medium text-[0.875rem]`})}),(0,$.jsxs)(`div`,{className:mn,children:[r?null:(0,$.jsx)(N,{label:t.tile?A(`project.patternFill`):A(`project.patternTile`),"aria-pressed":!!t.tile,onClick:()=>i({tile:!t.tile}),className:h(`size-8`,t.tile&&`bg-paper-2 text-ink`),children:(0,$.jsx)(Mt,{className:`size-4`})}),(0,$.jsx)(`a`,{href:o,download:n,"aria-label":A(`project.download`),title:A(`project.download`),className:`inline-flex size-8 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(d,{className:`size-4`})}),r?null:(0,$.jsx)(N,{label:A(`project.remove`),onClick:a,className:`size-8 hover:text-rose`,children:(0,$.jsx)(u,{className:`size-4`})})]})]})]})}var _n=/^#[0-9a-fA-F]{6}$/;function vn({sections:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(`#e0531b`),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),l=_n.test(r);return(0,$.jsx)(E,{open:!0,onClose:n,title:A(`project.colorAddTitle`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),l&&(t({name:a.trim(),value:r.toLowerCase(),...s?{section:s}:{}}),n())},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.colorValue`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(L,{value:l?r:`#888888`,onChange:e=>i(e.target.value)}),(0,$.jsx)(k,{value:r,placeholder:`#e0531b`,spellCheck:!1,onChange:e=>i(e.target.value.trim()),className:`font-mono text-[0.875rem]`})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.colorUseLabel`)}),(0,$.jsx)(k,{autoFocus:!0,value:a,maxLength:120,placeholder:A(`project.colorName`),onChange:e=>o(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:A(`project.colorUse`)})]}),e.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.colorSectionLabel`)}),(0,$.jsx)(R,{value:s,onChange:c,options:[{value:``,label:A(`project.sectionStandard`)},...e.map(e=>({value:e.id,label:e.title||A(`project.sectionUntitled`)}))]})]}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(M,{variant:`ghost`,onClick:n,children:A(`common.cancel`)}),(0,$.jsx)(M,{type:`submit`,disabled:!l,children:A(`project.add`)})]})]})})}function yn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)([]),p=async()=>{o(!0),c(null);try{let{colors:t}=await j.post(`/api/studio/projects/${e}/colors/scan`,{url:r.trim()});t.length?(u(t),f([])):c(A(`project.colorsNoneFound`))}catch(e){c(e.message)}o(!1)};return(0,$.jsx)(E,{open:!0,onClose:n,wide:l?!0:void 0,title:A(l?`project.colorsFound`:`project.colorsFromUrl`),children:l?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:A(`project.colorsFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3`,children:l.map(e=>{let t=d.includes(e.value);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>f(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:h(`relative flex flex-col overflow-hidden rounded-lg text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`h-16`,style:{background:e.value}}),(0,$.jsxs)(`span`,{className:`flex flex-col px-2.5 py-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-2`,children:e.name||`—`}),(0,$.jsx)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:e.value})]}),t?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(x,{className:`size-3.5`})}):null]},e.value)})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(M,{variant:`ghost`,onClick:()=>u(null),children:A(`run.back`)}),(0,$.jsx)(M,{disabled:!d.length,onClick:()=>{t(l.filter(e=>d.includes(e.value))),n()},children:d.length>1?A(`project.addMany`,{n:d.length}):A(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.logoUrl`)}),(0,$.jsx)(k,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:A(`project.colorsUrlHint`)})]}),s?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(M,{variant:`ghost`,onClick:n,children:A(`common.cancel`)}),(0,$.jsx)(M,{type:`submit`,busy:a,disabled:!r.trim(),children:A(`run.next`)})]})]})})}function bn({projectId:e,data:t,colors:n,sections:r,gradients:i,patterns:o,rules:s,save:c,readOnly:l}){let[d,f]=(0,Q.useState)(()=>n.map(e=>({...e,id:K()}))),[p,m]=(0,Q.useState)(r),[h,g]=(0,Q.useState)(i),[_,v]=(0,Q.useState)(o),[y,b]=(0,Q.useState)(null),x=nt(e,l),S=De(s),[w,ee]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),[O,j]=(0,Q.useState)(!1),M=Ue({colors:d.filter(e=>_n.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:p,gradients:h,patterns:_,colorRules:S.rules},c),P=p.filter(e=>(e.kind??`colors`)===`colors`),I=e=>P.some(t=>t.id===e.section),te=d.filter(e=>!I(e)),ne=(te[0]??d[0])?.id,re=(e,t)=>f(n=>n.map(n=>n.id===e?{...n,...t}:n)),ie=e=>f(t=>[...t,...e.map(e=>({...e,id:K()}))].slice(0,X.colors)),R=[{value:``,label:A(`project.sectionStandard`)},...P.map(e=>({value:e.id,label:e.title||A(`project.sectionUntitled`)}))],ae=(e,t)=>{let n=K();ee(n),m(r=>[...r,{id:n,title:t,description:``,...e===`colors`?{}:{kind:e}}])},oe=e=>({id:K(),name:``,section:e,type:`linear`,angle:90,stops:[{color:d[0]?.value&&_n.test(d[0].value)?d[0].value:`#4b73ff`,at:0},{color:d[1]?.value&&_n.test(d[1].value)?d[1].value:`#ff6d1b`,at:100}]}),z=async(e,t)=>{let n=await x.upload(`pattern`,t);v(t=>[...t,...n.map(t=>({id:K(),name:t.name.replace(/\.[^.]+$/,``),section:e,file:t.id}))])},se=[...d.length<X.colors?[{label:A(`project.colorNew`),icon:(0,$.jsx)(a,{className:`size-4 shrink-0`}),onPick:()=>D(!0)},{label:A(`project.colorsFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>j(!0)}]:[],...p.length<X.logoSections?[{label:A(`project.colorSectionAdd`),icon:(0,$.jsx)(At,{className:`size-4 shrink-0`}),onPick:()=>ae(`colors`,``)},{label:A(`project.gradientSectionAdd`),icon:(0,$.jsx)(wt,{className:`size-4 shrink-0`}),onPick:()=>ae(`gradients`,A(`project.gradientSectionTitle`))},{label:A(`project.patternSectionAdd`),icon:(0,$.jsx)(Mt,{className:`size-4 shrink-0`}),onPick:()=>ae(`patterns`,A(`project.patternSectionTitle`))}]:[],...S.full?[]:[{label:A(`project.ruleNew`),icon:(0,$.jsx)(tt,{className:`size-4 shrink-0`}),onPick:()=>S.add()}]],ce=e=>(0,$.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,$.jsx)(L,{value:_n.test(e.value)?e.value:`#888888`,onChange:t=>re(e.id,{value:t.target.value})}),(0,$.jsx)(k,{value:e.name,placeholder:A(`project.colorName`),maxLength:120,onChange:t=>re(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,$.jsx)(k,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>re(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsxs)(`div`,{className:`flex w-28 shrink-0 items-center justify-end max-sm:w-auto`,children:[e.id===ne?(0,$.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,$.jsx)(T,{tone:`ember`,children:A(`project.colorAccent`)})}):l?null:(0,$.jsx)(N,{label:A(`project.colorFirst`),onClick:()=>f(t=>[{...e,section:void 0},...t.filter(t=>t.id!==e.id)]),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:(0,$.jsx)(F,{className:`size-4`})}),l||!p.length?null:(0,$.jsx)(we,{options:R,value:I(e)?e.section??``:``,onChange:t=>re(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),l?null:(0,$.jsx)(N,{label:A(`project.remove`),onClick:()=>f(t=>t.filter(t=>t.id!==e.id)),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(u,{className:`size-4`})})]})]},e.id);return(0,$.jsxs)(Y,{title:A(`project.colors`),hint:A(`project.colorsHint`),save:M,locked:l,action:l?null:(0,$.jsx)(q,{entries:se}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[te.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:te.map(ce)}),l?null:(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:A(`project.colorUse`)})]}):d.length?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:A(`project.colorsEmpty`)}),p.map(n=>{let r=n.kind??`colors`,i=d.filter(e=>e.section===n.id),o=h.filter(e=>e.section===n.id),s=_.filter(e=>e.section===n.id),c=r===`gradients`?o.length:r===`patterns`?s.length:i.length;return(0,$.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,$.jsx)(Pe,{title:n.title,description:n.description,titlePlaceholder:A(r===`gradients`?`project.gradientSectionTitlePlaceholder`:r===`patterns`?`project.patternSectionTitlePlaceholder`:`project.colorSectionTitle`),descriptionPlaceholder:A(`project.colorSectionUse`),autoFocus:w===n.id,readOnly:l,onChange:e=>m(t=>t.map(t=>t.id===n.id?{...t,...e}:t)),onRemove:()=>{if(!c||confirm(A(r===`colors`?`project.colorSectionRemoveConfirm`:`project.fillSectionRemoveConfirm`,{name:n.title||A(`project.sectionUntitled`)}))){m(e=>e.filter(e=>e.id!==n.id)),f(e=>e.map(e=>e.section===n.id?{...e,section:void 0}:e)),g(e=>e.filter(e=>e.section!==n.id));for(let e of s)x.remove(e.file);v(e=>e.filter(e=>e.section!==n.id))}}}),r===`gradients`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[o.map(e=>(0,$.jsx)(hn,{gradient:e,readOnly:l,onEdit:()=>b(e),onRename:t=>g(n=>n.map(n=>n.id===e.id?{...n,name:t}:n)),onRemove:()=>g(t=>t.filter(t=>t.id!==e.id))},e.id)),l||h.length>=X.gradients?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>b(oe(n.id)),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(a,{className:`size-5`}),A(`project.gradientAdd`)]})]}):r===`patterns`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[s.map(n=>(0,$.jsx)(gn,{projectId:e,pattern:n,fileName:t.files.find(e=>e.id===n.file)?.name??`pattern`,readOnly:l,onChange:e=>v(t=>t.map(t=>t.id===n.id?{...t,...e}:t)),onRemove:()=>{x.remove(n.file),v(e=>e.filter(e=>e.id!==n.id))}},n.id)),l?null:(0,$.jsxs)(je,{accept:`image/*`,onFiles:e=>void z(n.id,e),className:`min-h-28 flex-col p-3`,children:[x.busy?(0,$.jsx)(C,{className:`size-5`}):(0,$.jsx)(a,{className:`size-5`}),A(`project.patternAdd`)]})]}):i.length?(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:i.map(ce)}):null]},n.id)}),(0,$.jsx)(Me,{rules:S,placeholder:A(`project.colorRulePlaceholder`),readOnly:l})]}),x.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:x.error}):null,E?(0,$.jsx)(vn,{sections:P,onClose:()=>D(!1),onAdd:e=>ie([e])}):null,y?(0,$.jsx)(pn,{gradient:y,brand:d.filter(e=>_n.test(e.value)),onClose:()=>b(null),onSave:e=>g(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,O?(0,$.jsx)(yn,{projectId:e,onClose:()=>j(!1),onAdd:ie}):null]})}var xn=e=>/^(ja|yes|true)$/i.test(e.trim()),Sn={text:Fe,longtext:be,number:z,date:H,url:l,email:He,phone:W,boolean:U};function Cn({type:e,detected:t,onChange:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!r)return;let e=e=>{s.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]);let c=Sn[e??t],l=`${A(`project.factType`)}: ${A(`project.type.${e??t}`)}`,u=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink`,d=e=>{n(e),i(!1)};return(0,$.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:l,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{o(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),i(e=>!e)},className:h(`inline-flex size-11 items-center justify-center rounded-lg transition hover:bg-accent hover:text-ink`,r?`bg-accent text-ink`:e?`text-ink-2`:`text-ink-4`),children:(0,$.jsx)(c,{className:`size-4`})}),r?(0,$.jsxs)(`div`,{role:`menu`,className:h(`absolute right-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,a?`bottom-12`:`top-12`),children:[(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:u,onClick:()=>d(void 0),children:[(0,$.jsx)(Ne,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:A(`project.factAuto`)}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:A(`project.type.${t}`)}),(0,$.jsx)(x,{className:h(`size-4 shrink-0`,e&&`invisible`)})]}),(0,$.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),Ee.map(t=>{let n=Sn[t];return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:u,onClick:()=>d(t),children:[(0,$.jsx)(n,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:A(`project.type.${t}`)}),(0,$.jsx)(x,{className:h(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function wn({facts:e,save:t,readOnly:n}){let r=(0,Q.useRef)(0),i=(0,Q.useRef)(null),[o,c]=(0,Q.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),l=Ue(o.filter(e=>e.key&&e.label.trim()).map(({key:e,label:t,value:n,type:r})=>({key:e,label:t.trim(),value:n,...r?{type:r}:{}})),t),d=(e,t)=>c(n=>n.map(n=>n.id===e?{...n,...t}:n)),f=(e,t,n=!1)=>{let a=`f${r.current++}`;i.current=`${a}:${t}`;let o={id:a,key:``,label:``,value:``,...e};c(e=>n?[o,...e]:[...e,o])},m=e=>t=>{t&&i.current===e&&(i.current=null,t.focus())},h=it.filter(e=>!o.some(t=>t.key===e.key));return(0,$.jsxs)(Y,{title:A(`project.facts`),hint:A(`project.factsHint`),save:l,locked:n,action:o.length<X.facts&&!n?(0,$.jsxs)(M,{variant:`secondary`,size:`sm`,onClick:()=>f({},`label`,!0),children:[(0,$.jsx)(a,{className:`size-4`}),` `,A(`project.factAdd`)]}):null,children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:o.map(e=>{let t=Ae(e.value),r=e.type??t;return(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto_auto] items-start gap-x-1 gap-y-2 sm:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_auto_auto]`,children:[(0,$.jsx)(k,{ref:m(`${e.id}:label`),value:e.label,placeholder:A(`project.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>d(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&d(e.id,{key:Se(e.label,o.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(p,{checked:xn(e.value),label:e.label,onChange:t=>d(e.id,{value:A(t?`project.yes`:`project.no`)})}),(0,$.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:xn(e.value)?A(`project.yes`):A(`project.no`)})]}):(0,$.jsx)(ne,{ref:m(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:A(`project.factValue`),onChange:t=>d(e.id,{value:t.target.value}),className:`min-h-11`}),(0,$.jsx)(Cn,{type:e.type,detected:t,onChange:t=>d(e.id,{type:t})}),n?null:(0,$.jsx)(N,{label:A(`project.remove`),onClick:()=>c(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,$.jsx)(u,{className:`size-4`})})]},e.id)})}),o.length<X.facts&&!n?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${o.length?`mt-4`:``}`,children:[(0,$.jsxs)(M,{variant:`secondary`,size:`sm`,onClick:()=>f({},`label`),children:[(0,$.jsx)(a,{className:`size-4`}),` `,A(`project.factAdd`)]}),h.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f({key:e.key,label:s===`en`?e.en:e.de},`value`),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,$.jsx)(a,{className:`size-3.5`}),` `,s===`en`?e.en:e.de]},e.key))]}):null]})}function Tn({onLogo:e,children:t,className:n}){let[r,i]=(0,Q.useState)(!1);return e?(0,$.jsx)(`div`,{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-wizards-logo`)&&(e.preventDefault(),i(!0))},onDragLeave:()=>i(!1),onDrop:t=>{let n=t.dataTransfer.getData(Jt);i(!1),n&&(t.preventDefault(),e(n))},className:h(`-m-2 rounded-xl p-2 transition`,r&&`bg-paper-2 ring-1 ring-focus`,n),children:t}):(0,$.jsx)(`div`,{className:n,children:t})}function En({projectId:e,data:t,readOnly:n,sections:r,rules:i,save:a}){let o=nt(e,n),[s,c]=(0,Q.useState)(r),l=De(i),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!1),m=(0,Q.useRef)(null),h=Ue({logoSections:s,logoRules:l.rules},a),g=t.files.filter(e=>e.kind===`logo`),_=new Map(g.map(e=>[e.id,e])),v=new Set(s.flatMap(e=>e.logos)),y=g.filter(e=>!v.has(e.id)),b=ct(g,s)?.id,x=(e,t)=>c(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),S=(e,t)=>c(n=>n.map(n=>n.id===e?{...n,...t}:n)),C=async(e,t)=>{let n=await o.upload(`logo`,e);for(let e of n)x(e.id,t)},w=s.length?{options:[{value:``,label:A(`project.sectionStandard`)},...s.map(e=>({value:e.id,label:e.title||A(`project.sectionUntitled`)}))],current:e=>s.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>x(e.id,t||null)}:void 0,T=(t,n,r)=>(0,$.jsx)(Yt,{projectId:e,kind:`logo`,files:t,actions:o,accept:`image/*`,addLabel:r?A(`project.logoAdd`):void 0,onUpload:e=>void C(e,n),mainId:b,onMakeMain:e=>{x(e.id,null),o.order(`logo`,[e.id,...g.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:w,onRemove:e=>{confirm(A(`project.removeConfirm`,{name:e.name}))&&(o.remove(e.id),x(e.id,null))}}),ee=n?void 0:e=>t=>x(t,e),E=[{label:A(`project.logoUpload`),icon:(0,$.jsx)(G,{className:`size-4 shrink-0`}),onPick:()=>m.current?.click()},{label:A(`project.logoFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>p(!0)},...s.length<X.logoSections?[{label:A(`project.logoSectionAdd`),icon:(0,$.jsx)(At,{className:`size-4 shrink-0`}),onPick:()=>{let e=K();d(e),c(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...l.full?[]:[{label:A(`project.ruleNew`),icon:(0,$.jsx)(tt,{className:`size-4 shrink-0`}),onPick:()=>l.add()}]];return(0,$.jsxs)(Y,{title:A(`project.logos`),hint:A(`project.logosHint`),save:h,action:n?null:(0,$.jsx)(q,{entries:E}),children:[(0,$.jsx)(`input`,{ref:m,type:`file`,accept:`image/*`,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&C(t,null)}}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(Tn,{onLogo:ee?.(null),children:T(y,null,!0)}),s.map(e=>(0,$.jsx)(`div`,{className:`group/section`,children:(0,$.jsxs)(Tn,{onLogo:ee?.(e.id),className:`flex flex-col gap-3`,children:[(0,$.jsx)(Pe,{title:e.title,description:e.description,titlePlaceholder:A(`project.logoSectionTitle`),descriptionPlaceholder:A(`project.logoSectionUse`),autoFocus:u===e.id,readOnly:n,onChange:t=>S(e.id,t),onRemove:()=>{(!e.logos.length||confirm(A(`project.logoSectionRemoveConfirm`,{name:e.title||A(`project.sectionUntitled`)})))&&c(t=>t.filter(t=>t.id!==e.id))}}),T(e.logos.map(e=>_.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),(0,$.jsx)(Me,{rules:l,placeholder:A(`project.logoRulePlaceholder`),readOnly:n})]}),o.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error}):null,f?(0,$.jsx)(Xt,{kind:`logo`,onClose:()=>p(!1),fetchUrl:e=>o.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)x(t.id,null)}}):null]})}var Dn=new Set;function On(e){(0,Q.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||Dn.has(t))return;Dn.add(t);let n=document.createElement(`link`);n.rel=`stylesheet`,n.href=`https://fonts.bunny.net/css?family=${encodeURIComponent(t)}:${Re.join(`,`)}&display=swap`,document.head.append(n)},[e])}var kn=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function An({unit:e,label:t,...n}){return(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3`,title:t,children:[(0,$.jsx)(`input`,{type:`number`,"aria-label":t,className:`h-8 w-14 rounded-md border border-input bg-card px-1.5 text-right text-[0.8125rem] text-ink tabular-nums outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,...n}),e]})}var jn=`h-8 rounded-md border border-input bg-card px-1.5 text-[0.8125rem] text-ink outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`;function Mn({font:e,first:t,readOnly:n,autoFocus:r,onChange:i,onRemove:a}){return On(e.family),(0,$.jsxs)(`div`,{className:`group/font relative flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`flex h-28 items-end justify-between overflow-hidden rounded-md bg-card px-4 pb-3 ring-1 ring-border-soft`,style:{fontFamily:kn(e.family)},children:[(0,$.jsx)(`span`,{className:`text-[3.5rem] text-ink leading-none`,children:`Aa`}),(0,$.jsx)(`span`,{className:`truncate pl-3 text-[0.875rem] text-ink-3`,children:`ABCDEFG abcdefg 0123456789`})]}),n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:e.family}),e.role?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:e.role}):null]}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(ft,{value:e.family,label:A(`project.fontFamily`),placeholder:A(`project.fontFamily`),maxLength:80,autoFocus:r,onChange:e=>i({family:e}),className:`font-medium text-[0.9375rem]`}),(0,$.jsx)(ft,{value:e.role,label:A(`project.fontRole`),placeholder:A(t?`project.fontRoleFirst`:`project.fontRole`),maxLength:200,onChange:e=>i({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Re.map(t=>{let r=e.weights.includes(t);return(0,$.jsx)(`button`,{type:`button`,disabled:n,"aria-pressed":r,onClick:()=>i({weights:r?e.weights.filter(e=>e!==t):[...e.weights,t].sort((e,t)=>e-t)}),style:{fontFamily:kn(e.family),fontWeight:t},className:h(`h-7 rounded-full px-2.5 text-[0.8125rem] tabular-nums transition`,r?`bg-ink text-paper`:`bg-paper-2 text-ink-3 hover:text-ink`,n&&!r&&`hidden`),children:t},t)})}),n?null:(0,$.jsx)(N,{label:A(`project.remove`),onClick:a,className:`absolute top-4 right-4 size-8 bg-card opacity-0 shadow-soft transition focus:opacity-100 group-hover/font:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(u,{className:`size-4`})})]})}function Nn({style:e,fonts:t,sample:n,readOnly:r,autoFocus:i,onChange:a,onRemove:o}){let s=t.find(t=>t.id===e.font)??t[0],c={fontFamily:kn(s?.family),fontWeight:e.weight,fontSize:`${Math.min(e.size,56)}px`,lineHeight:`${e.lineHeight}%`,letterSpacing:`${e.tracking/100}em`,textTransform:e.uppercase?`uppercase`:void 0};return(0,$.jsxs)(`li`,{className:`group/row flex flex-col gap-2 border-border-soft border-b py-4 first:pt-1 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`truncate text-ink`,style:c,children:n}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[r?(0,$.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`,children:e.name}):(0,$.jsx)(`div`,{className:`w-40`,children:(0,$.jsx)(ft,{value:e.name,label:A(`project.styleName`),placeholder:A(`project.styleName`),maxLength:60,autoFocus:i,onChange:e=>a({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,$.jsxs)(`fieldset`,{disabled:r,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,$.jsx)(`select`,{"aria-label":A(`project.styleFont`),value:s?.id??``,onChange:e=>a({font:e.target.value}),className:h(jn,`max-w-40`),children:t.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.family||A(`project.fontFamily`)},e.id))}):null,(0,$.jsx)(`select`,{"aria-label":A(`project.styleWeight`),value:e.weight,onChange:e=>a({weight:Number(e.target.value)}),className:jn,children:[...new Set([...Re,e.weight])].sort().map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))}),(0,$.jsx)(An,{unit:`px`,label:A(`project.styleSize`),min:6,max:400,value:e.size,onChange:e=>a({size:Number(e.target.value)||16})}),(0,$.jsx)(An,{unit:A(`project.styleLine`),label:A(`project.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>a({lineHeight:Number(e.target.value)||100})}),(0,$.jsx)(An,{unit:A(`project.styleTracking`),label:A(`project.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>a({tracking:Number(e.target.value)||0})}),(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:A(`project.styleUpper`),"aria-label":A(`project.styleUpper`),onClick:()=>a({uppercase:!e.uppercase}),className:h(`grid size-8 place-items-center rounded-md transition`,e.uppercase?`bg-ink text-paper`:`text-ink-3 hover:bg-paper-2 hover:text-ink`),children:(0,$.jsx)(Ot,{className:`size-4`})})]}),r?null:(0,$.jsx)(N,{label:A(`project.remove`),onClick:o,className:`ml-auto size-8 opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(u,{className:`size-4`})})]})]})}function Pn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)([]),p=async()=>{o(!0),c(null);try{let{fonts:t}=await j.post(`/api/studio/projects/${e}/fonts/scan`,{url:r.trim()});t.length?(u(t),f(t.slice(0,2).map(e=>e.family))):c(A(`project.fontsNoneFound`))}catch(e){c(e.message)}o(!1)};return(0,$.jsx)(E,{open:!0,onClose:n,wide:l?!0:void 0,title:A(l?`project.fontsFound`:`project.fontsFromUrl`),children:l?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:A(`project.fontsFoundHint`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>(0,$.jsx)(Fn,{font:e,on:d.includes(e.family),onToggle:()=>f(t=>t.includes(e.family)?t.filter(t=>t!==e.family):[...t,e.family])},e.family))}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(M,{variant:`ghost`,onClick:()=>u(null),children:A(`run.back`)}),(0,$.jsx)(M,{disabled:!d.length,onClick:()=>{t(l.filter(e=>d.includes(e.family))),n()},children:d.length>1?A(`project.addMany`,{n:d.length}):A(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.logoUrl`)}),(0,$.jsx)(k,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:A(`project.fontsUrlHint`)})]}),s?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(M,{variant:`ghost`,onClick:n,children:A(`common.cancel`)}),(0,$.jsx)(M,{type:`submit`,busy:a,disabled:!r.trim(),children:A(`run.next`)})]})]})})}function Fn({font:e,on:t,onToggle:n}){return On(e.family),(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:h(`flex items-center gap-4 rounded-lg px-4 py-3 text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`text-[2rem] text-ink leading-none`,style:{fontFamily:kn(e.family)},children:`Aa`}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.family}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:e.weights.length?e.weights.join(` · `):A(`project.fontWeightsUnknown`)})]}),t?(0,$.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(x,{className:`size-3.5`})}):null]})}function In({projectId:e,fonts:t,styles:n,rules:r,sample:i,save:o,readOnly:s}){let[c,l]=(0,Q.useState)(t),[u,d]=(0,Q.useState)(n),f=De(r),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),_=Ue({fonts:c,textStyles:u,typeRules:f.rules},o),v=(e,t=!1)=>{let n=e.map(e=>({id:K(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&m(n[0].id),l(e=>[...e,...n].slice(0,X.fonts))},y=()=>{let e=K();m(e),d(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},b=[...c.length<X.fonts?[{label:A(`project.fontNew`),icon:(0,$.jsx)(a,{className:`size-4 shrink-0`}),onPick:()=>v([{family:``,weights:[400,700]}],!0)},{label:A(`project.fontsFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>g(!0)}]:[],...u.length<X.textStyles?[{label:A(`project.styleNew`),icon:(0,$.jsx)(Le,{className:`size-4 shrink-0`}),onPick:y}]:[],...f.full?[]:[{label:A(`project.ruleNew`),icon:(0,$.jsx)(tt,{className:`size-4 shrink-0`}),onPick:()=>f.add()}]];return(0,$.jsxs)(Y,{title:A(`project.typography`),hint:A(`project.typographyHint`),save:_,action:s?null:(0,$.jsx)(q,{entries:b}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[c.length?(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:c.map((e,t)=>(0,$.jsx)(Mn,{font:e,first:t===0,readOnly:s,autoFocus:p===e.id,onChange:t=>l(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>l(t=>t.filter(t=>t.id!==e.id))},e.id))}):(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:A(`project.fontsEmpty`)}),u.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:A(`project.styles`)}),s?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:A(`project.stylesHint`)}),(0,$.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:u.map(e=>(0,$.jsx)(Nn,{style:e,fonts:c,sample:i,readOnly:s,autoFocus:p===e.id,onChange:t=>d(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>d(t=>t.filter(t=>t.id!==e.id))},e.id))})]}):null,(0,$.jsx)(Me,{rules:f,placeholder:A(`project.typeRulePlaceholder`),readOnly:s})]}),h?(0,$.jsx)(Pn,{projectId:e,onClose:()=>g(!1),onAdd:e=>v(e)}):null]})}function Ln({project:e,save:t}){let[n,r]=(0,Q.useState)(e.brand.name??``),[i,a]=(0,Q.useState)(e.brand.about??``),o=Ue({name:n.trim(),about:i.trim()},e=>t({brand:e}));return(0,$.jsx)(Y,{title:A(`project.base`),hint:A(`project.baseHint`),save:o,locked:e.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.title`)}),(0,$.jsx)(k,{value:n,maxLength:120,onChange:e=>r(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:A(`project.titleHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(D,{children:A(`project.about`)}),(0,$.jsx)(ne,{minRows:4,value:i,onChange:e=>a(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:A(`project.aboutHint`)})]})]})})}function Rn({project:e,group:t,children:n}){let i=r(),a=We(e.id),[o,s]=(0,Q.useState)(0),c=async t=>{await j.patch(`/api/studio/projects/${e.id}`,t),await i.invalidateQueries({queryKey:[`projects`]})},l=dt({mutationFn:()=>j.del(`/api/studio/projects/${e.id}`),onSuccess:()=>i.invalidateQueries({queryKey:[`projects`]})}),u=Ce(),d=Ze(),f=a.data??{files:[],embeddings:!0},p=`${e.id}:${o}`,m=e.readOnly,h=t===`knowledge`;return $e(m?{}:{title:A(h?`project.assistantTitleKnowledge`:`project.assistantTitle`),hello:A(h?`project.assistantHelloKnowledge`:`project.assistantHello`),placeholder:A(h?`project.assistantComposerKnowledge`:`project.assistantComposer`),suggestions:h?[{label:A(`assistant.suggest.knowledgeHow`)},{label:A(`assistant.suggest.knowledgeSite`),fill:!0},{label:A(`assistant.suggest.knowledgeCategories`)}]:[{label:A(`assistant.suggest.readSite`),fill:!0},{label:A(`assistant.suggest.missing`)},{label:A(`assistant.suggest.facts`)}],summary:h?void 0:[e.brand.name?`title "${e.brand.name}"`:`no title`,`${e.facts.length} facts`,`${e.brand.colors?.length??0} colours`,`${f.files.filter(e=>e.kind===`logo`).length} logos`].join(` · `),onChanged:()=>s(e=>e+1)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[m?(0,$.jsx)(xe,{children:ye(e)}):null,t===`info`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(J,{id:`base`,children:(0,$.jsx)(Ln,{project:e,save:c},`base:${p}`)}),(0,$.jsx)(J,{id:`facts`,children:(0,$.jsx)(wn,{facts:e.facts,save:e=>c({facts:e}),readOnly:m},`facts:${p}`)}),(0,$.jsx)(J,{id:`logos`,children:(0,$.jsx)(En,{projectId:e.id,data:f,readOnly:m,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],save:e=>c({brand:e})},`logos:${p}`)}),(0,$.jsx)(J,{id:`colors`,children:(0,$.jsx)(bn,{projectId:e.id,data:f,colors:e.brand.colors??[],sections:e.brand.colorSections??[],gradients:e.brand.gradients??[],patterns:e.brand.patterns??[],rules:e.brand.colorRules??[],save:e=>c({brand:e}),readOnly:m},`colors:${p}`)}),(0,$.jsx)(J,{id:`typography`,children:(0,$.jsx)(In,{projectId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],sample:e.brand.name||A(`project.typeSample`),save:e=>c({brand:e}),readOnly:m},`typography:${p}`)}),(0,$.jsx)(J,{id:`assets`,children:(0,$.jsx)(ln,{projectId:e.id,data:f,readOnly:m,sections:e.brand.assetSections??[],save:e=>c({brand:e})},`assets:${p}`)})]}):null,n,t===`info`&&u&&!m&&d?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(M,{variant:`danger`,busy:l.isPending,onClick:()=>confirm(`${A(`settings.delete`)}?`)&&l.mutate(),children:A(`settings.delete`)}),l.error?(0,$.jsx)(`p`,{className:`mt-2 text-[0.875rem] text-rose`,children:l.error.message}):null]}):null]})}var zn={q:``,mode:``,days:0};function Bn(e,t,n){let r=new URLSearchParams;t&&r.set(`wizard`,t),n.q.trim()&&r.set(`q`,n.q.trim()),n.mode&&r.set(`mode`,n.mode),n.days&&r.set(`days`,String(n.days));let a=r.toString();return i({queryKey:[`results`,e,a],queryFn:()=>j.get(`/api/studio/projects/${e}/results${a&&`?${a}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function Vn({filter:e,onFilter:t}){let[n,r]=(0,Q.useState)(e.q);return(0,Q.useEffect)(()=>{if(n===e.q)return;let r=setTimeout(()=>t({...e,q:n}),250);return()=>clearTimeout(r)},[n,e,t]),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,$.jsx)(ze,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,$.jsx)(k,{type:`search`,value:n,onChange:e=>r(e.target.value),placeholder:A(`space.resultsSearch`),"aria-label":A(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,$.jsx)(R,{value:e.mode,onChange:n=>t({...e,mode:n}),options:[{value:``,label:A(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,$.jsx)(R,{value:String(e.days),onChange:n=>t({...e,days:Number(n)}),options:[{value:`0`,label:A(`space.resultsAnyTime`)},{value:`1`,label:A(`space.resultsDay`)},{value:`7`,label:A(`space.resultsDays`,{n:7})},{value:`30`,label:A(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function Hn({data:e,wizardId:t,filter:n,onFilter:r}){let[i,a]=(0,Q.useState)(null),o=t=>e.wizards.find(e=>e.id===t)?.title??``,c=new Intl.DateTimeFormat(s,{dateStyle:`medium`,timeStyle:`short`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Y,{title:t?o(t):A(`space.resultsAll`),hint:A(`space.resultsHint`),plain:!0,children:[(0,$.jsx)(Vn,{filter:n,onFilter:r}),e.runs.length?(0,$.jsx)(I,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>a(e),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?c.format(new Date(e.doneAt)):o(e.wizardId)}),(0,$.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${c.format(new Date(e.doneAt))} · `,A(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:A(`space.resultFiles`,{n:e.assets}),children:[(0,$.jsx)(_,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,$.jsx)(T,{children:`Test`}):(0,$.jsxs)(T,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,$.jsx)(I,{children:(0,$.jsx)(P,{children:n.q.trim()||n.mode||n.days?A(`space.resultsNone`):A(`space.resultsEmpty`)})})]}),i?(0,$.jsx)(V,{header:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:o(i.wizardId)}),i.mode===`test`?(0,$.jsx)(T,{children:`Test`}):(0,$.jsxs)(T,{tone:`live`,children:[`Live v`,i.version]})]}),onClose:()=>a(null),children:(0,$.jsx)(St,{runId:i.id,compact:!0},i.id)}):null]})}function Un({project:e,save:t}){let[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(e.name),o=dt({mutationFn:()=>t({name:i.trim()}),onSuccess:()=>r(!1)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{label:A(`project.rename`),onClick:()=>{a(e.name),r(!0)},children:(0,$.jsx)(g,{className:`size-4`})}),(0,$.jsx)(E,{open:n,onClose:()=>r(!1),title:A(`project.rename`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&o.mutate()},children:[(0,$.jsx)(k,{"data-autofocus":!0,value:i,maxLength:80,onChange:e=>a(e.target.value)}),o.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(M,{variant:`ghost`,onClick:()=>r(!1),children:A(`common.cancel`)}),(0,$.jsx)(M,{type:`submit`,busy:o.isPending,disabled:!i.trim(),children:A(`settings.save`)})]})]})})]})}function Wn({project:e}){let t=r();return(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(ut,{}),e.readOnly?null:(0,$.jsx)(Un,{project:e,save:async n=>{await j.patch(`/api/studio/projects/${e.id}`,n),await t.invalidateQueries({queryKey:[`projects`]})}})]})}function Gn(e){let t=e.join(` `),[n,r]=(0,Q.useState)(e[0]);return(0,Q.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=Ye(),i=t.scrollTop>0&&t.clientHeight+t.scrollTop>=t.scrollHeight-4,a=(t===document.documentElement?0:t.getBoundingClientRect().top)+Math.max(120,t.clientHeight/3),o=e[0];for(let t of e){let e=document.getElementById(t)?.getBoundingClientRect().top;e!==void 0&&e<=a&&(o=t)}r(i?e.at(-1):o)},a=()=>{n||=requestAnimationFrame(i)};return i(),window.addEventListener(`scroll`,a,{passive:!0,capture:!0}),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(n),window.removeEventListener(`scroll`,a,{capture:!0}),window.removeEventListener(`resize`,a)}},[t]),n}function Kn(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function qn({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,$.jsx)(Z,{icon:e.icon??Be,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,$.jsx)(ht,{label:e.label,children:r},e.plugin):(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function Jn(){let{group:e}=S(),[t,n]=re(),r=ie(),i=te(),{hash:a}=i,{project:o,loading:s}=ke(),c=Ce(),l=Qe(),u=xt(),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),v=Ge(e)?e:void 0,y=i.state?.parts===!0,b=rt().map(e=>({...e,to:`/space/${e.id}`})),x=b.find(e=>e.id===v),C=t.get(`show`),w=v?C?2:1:0,T=u?Math.min(w,1):v&&g!==v&&!y?1:0,ee=mt(T),E=mt(w),D=(0,Q.useMemo)(()=>({slot:d,narrow:u,setDetail:m}),[d,u]),k=o?o.brand.name?.trim()||o.name:A(`nav.project`),j=v&&v!==`results`?Je(v,l):[],M=v?Je(v,l).filter(e=>e.plugin):[],N=Gn([...j,...v===`results`?M:[]].flatMap(e=>e.sections.map(e=>e.id))),F=v===`results`&&C&&C!==`all`?C:null,[I,ne]=(0,Q.useState)(zn),L=Bn(v===`results`?o?.id:void 0,F,I),R=L.data?.wizards.find(e=>e.id===F)?.title,z=v===`data`&&C&&C!==`all`||v===`knowledge`&&C&&/^[ptfcvs]:/.test(C)?C:null,B=z?.startsWith(`s:`)?l.spaceSections.find(e=>e.id===z.slice(2)):void 0,V=v===`knowledge`&&z&&/^[ptf]:/.test(z)?z:null,H=se(v===`data`?o?.id:void 0),U=pe(v===`knowledge`?o?.id:void 0),W=ve(z?.startsWith(`v:`)?z.slice(2):``),ye=U.data?.categories.find(e=>e.id===(z?.startsWith(`c:`)?z.slice(2):W.data?.category.id)),be=v===`knowledge`?B?B.label():z?.startsWith(`v:`)?W.data&&`${W.data.category.name}: ${W.data.value}`:z?.startsWith(`c:`)?ye?.name:U.data?.items.find(e=>e.key===z)?.title:H.data?ge(H.data).flatMap(e=>e.items).find(e=>e.key===z)?.title:void 0;Ve([{label:A(`nav.project`),to:`/space`},...x?[{label:x.label,to:`/space/${x.id}`}]:[],...x&&(p??R??be)?[{label:p??R??be}]:[]]);let xe={p:`page`,t:`table`,f:`file`,c:`kategorie`,v:`kategorie value`,s:`plugin section`};$e({...v===`data`||v===`results`?{compact:!0}:{},...v===`data`?{suggestions:[{label:A(`assistant.suggest.dataWhat`)},{label:A(`assistant.suggest.dataWho`)},{label:A(`assistant.suggest.dataEdit`)}]}:v===`results`?{suggestions:[{label:A(`assistant.suggest.resultsFailed`)},{label:A(`assistant.suggest.resultsCost`)},{label:A(`assistant.suggest.resultsShare`)}]}:{},...z&&be?{open:{kind:xe[z[0]]??`item`,id:z.slice(2),label:be}}:F&&R?{open:{kind:`wizard`,id:F,label:R}}:{}});let G=v===`results`||v===`data`||z?a.slice(1):C||a.slice(1),Se=(0,Q.useRef)(``);if((0,Q.useEffect)(()=>{let e=`${v}#${G}`;G&&Se.current!==e&&document.getElementById(G)&&(Se.current=e,requestAnimationFrame(()=>Kn(G,!1)))},[v,G,o?.id,l.spaceSections]),!v){let t=a.slice(1),n=t?lt(t,l):null;if(n===`knowledge`&&l.spaceSections.some(e=>e.id===t))return(0,$.jsx)(O,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,$.jsx)(O,{to:u?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if(t&&l.status!==`ready`)return null;if(e!==void 0||!u)return(0,$.jsx)(O,{to:`/space/info`,replace:!0,state:{parts:!0}})}if(v===`knowledge`&&!C&&l.spaceSections.some(e=>e.id===a.slice(1)))return(0,$.jsx)(O,{to:`/space/knowledge?show=s:${a.slice(1)}`,replace:!0});let we=e=>{if(u){r({search:`?show=${e}`});return}Se.current=`${v}#${e}`,Kn(e,!0),r({search:``,hash:e},{replace:!0})},K=e=>u?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),Te=e=>e.flatMap(e=>e.sections).map(e=>l.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,$.jsx)(J,{id:e.id,children:(0,$.jsx)(Y,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,$.jsx)(ot,{of:e,children:(0,$.jsx)(e.component,{})})})},e.serial)),q=u?void 0:N;return(0,$.jsx)(_t.Provider,{value:D,children:(0,$.jsx)(`div`,{className:`animate-rise`,children:(0,$.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-[13.5rem_minmax(0,1fr)] md:gap-8 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`,children:[(0,$.jsxs)(`aside`,{className:h(`min-w-0 md:sticky md:top-6 md:self-start`,u&&w===2&&`hidden`,u&&E===`back`&&pt(`back`)),children:[(0,$.jsx)(gt,{title:k,open:T===1?x??null:null,onBack:()=>u?r(`/space`):_(v??null)}),(0,$.jsx)(`div`,{className:h(pt(ee)),children:T===0?(0,$.jsx)(vt,{entries:b,current:u?void 0:x,onPick:()=>_(null)}):(0,$.jsx)(`div`,{ref:f})},T)]}),v?(0,$.jsxs)(`div`,{className:h(`min-w-0`,u&&w<2&&`hidden`,u&&E===`deeper`&&pt(`deeper`)),children:[u?(0,$.jsx)(`div`,{className:`mb-3`,children:(0,$.jsx)(bt,{label:x?.label??k,onBack:()=>r(`/space/${v}`)})}):null,c&&o?(0,$.jsx)(`div`,{className:`mb-6`,children:(0,$.jsx)(Wn,{project:o})}):null,v===`results`?(0,$.jsxs)(yt,{children:[(0,$.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(Z,{icon:Pt,label:A(`space.resultsAll`),selected:!u&&!F,onPick:()=>K(`all`)}),L.data?.wizards.filter(e=>e.results||e.id===F).map(e=>(0,$.jsx)(Z,{icon:Ne,label:e.title,badge:e.results?(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.results}):null,selected:!u&&e.id===F,onPick:()=>K(e.id)},e.id))]}),(0,$.jsx)(qn,{groups:M,current:q,onPick:we})]}):v===`data`?(0,$.jsxs)(yt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(Z,{icon:It,label:A(`data.all`),selected:!u&&!z,onPick:()=>K(`all`)})}),H.data?ge(H.data).map(e=>(0,$.jsx)(ht,{label:e.label,children:e.items.map(e=>(0,$.jsx)(Z,{icon:oe[e.kind],label:e.title,selected:!u&&e.key===z,onPick:()=>K(e.key)},e.key))},e.key)):null,(0,$.jsx)(qn,{groups:M,current:q,onPick:we})]}):v===`knowledge`?(0,$.jsxs)(yt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(Z,{icon:It,label:A(`know.all`),selected:!(u||z),onPick:()=>K(`all`)})}),U.data?.categories.length?(0,$.jsx)(ht,{label:A(`know.categories`),children:U.data.categories.map(e=>(0,$.jsx)(Z,{icon:ue[e.type],label:e.name,badge:(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!u&&(z===`c:${e.id}`||W.data?.category.id===e.id),onPick:()=>K(`c:${e.id}`)},e.id))}):null,(0,$.jsx)(qn,{groups:M,current:u?void 0:B?.id,onPick:e=>K(`s:${e}`)})]}):(0,$.jsx)(yt,{children:(0,$.jsx)(qn,{groups:j,current:q,onPick:we})}),o&&(v===`info`||v===`knowledge`)?(0,$.jsxs)(Rn,{project:o,group:v,children:[v===`knowledge`?V?V.startsWith(`p:`)?(0,$.jsx)(fe,{pageId:V.slice(2),onGone:()=>K(`all`),onOpen:K},V):V.startsWith(`t:`)?(0,$.jsx)(de,{tableId:V.slice(2),onGone:()=>K(`all`)},V):(0,$.jsx)(tn,{projectId:o.id,fileId:V.slice(2),readOnly:o.readOnly,onGone:()=>K(`all`)},V):U.data?B?(0,$.jsx)(Y,{title:B.label(),hint:B.hint?.(),plain:!0,children:(0,$.jsx)(ot,{of:B,children:(0,$.jsx)(B.component,{})})},z):z?.startsWith(`c:`)?ye?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(le,{projectId:o.id,category:ye,readOnly:o.readOnly,onOpen:K,onGone:()=>K(`all`)}),ye.type===`choice`?null:(0,$.jsx)(_e,{projectId:o.id,category:ye,categories:U.data.categories,onOpen:K})]},z):null:z?.startsWith(`v:`)?W.data?(0,$.jsx)(ae,{value:W.data,readOnly:o.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[W.data.items.length?(0,$.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:W.data.items.map(e=>(0,$.jsx)(ce,{item:e,categories:U.data.categories.filter(e=>e.id!==W.data?.category.id),onOpen:K},e.key))}):null,W.data.rows.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>K(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:A(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},z):null:(0,$.jsx)(J,{id:`documents`,children:(0,$.jsx)(he,{projectId:o.id,data:U.data,readOnly:o.readOnly,onOpen:K})}):null:null,v===`info`?Te(M):null]},o.id):null,o&&v===`data`?(0,$.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:z?.startsWith(`t:`)?(0,$.jsx)(de,{tableId:z.slice(2),onGone:()=>K(`all`)},z):z?.startsWith(`p:`)?(0,$.jsx)(fe,{pageId:z.slice(2),onGone:()=>K(`all`)},z):(0,$.jsxs)($.Fragment,{children:[H.data?(0,$.jsx)(me,{projectId:o.id,data:H.data,readOnly:o.readOnly,onOpen:K}):null,Te(M)]})}):null,o&&v===`results`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[L.data?(0,$.jsx)(Hn,{data:L.data,wizardId:F,filter:I,onFilter:ne}):null,L.isError?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:L.error.message}):null,Te(M)]}):null,o||s?null:(0,$.jsx)(P,{children:A(`settings.noProject`)})]}):null]})})})}export{Jn as ProjectPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{r}from"./logo-C4V2_3Ar.js";import{Tt as i,bn as a,bt as o,cn as s,ct as c,dn as l,hn as u,jt as d,kt as f,l as p,lt as m,mt as h,p as g,v as _,yn as v}from"./ui-BOCXzzHi.js";import{a as y,i as b,n as x,o as S,r as C,s as w,t as T}from"./ChatView-uogJ3nht.js";import{Bt as ee,Ft as E,It as D,Lt as O,a as k,n as A,o as j}from"./index-Df6UxElH.js";import{t as M}from"./RunnerView-Deenymq0.js";var N={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};N.node;var te=l(N),P={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};P.node;var F=l(P),I={name:`square-plus`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]],aliases:[`plus-square`]};I.node;var L=l(I),R=e(t(),1);function ne(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`||e===`popout`?e:null}var z=ne(),re=z?new URLSearchParams(window.location.search).get(`page`):null,B=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),ie=()=>B(`close`);function ae(e){(0,R.useEffect)(()=>{if(z===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>B(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(z===`modal`||z===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&B(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var V=e(n(),1);function H(e){(0,R.useEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`--raw-primary`,e),()=>{t.style.removeProperty(`--raw-primary`)}},[e])}function U(e,t){(0,R.useEffect)(()=>{if(!e||!t)return;let n=_(`/api/public/wizards/${e}`),r=[{rel:`manifest`,href:`${n}/manifest.webmanifest`},{rel:`apple-touch-icon`,href:`${n}/icons/apple-touch-icon.png`},{rel:`icon`,href:`${n}/icons/favicon.png`,type:`image/png`}].flatMap(({rel:e,href:t,type:n})=>{let r=document.querySelector(`link[rel="${e}"]`);if(!r)return[];let i={href:r.getAttribute(`href`),type:r.getAttribute(`type`)};return r.setAttribute(`href`,t),n&&r.setAttribute(`type`,n),[{link:r,before:i}]}),i=document.createElement(`meta`);return i.name=`apple-mobile-web-app-title`,i.content=t,document.head.appendChild(i),()=>{for(let{link:e,before:t}of r)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);i.remove()}},[e,t])}var W=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,G=W||/Android/.test(navigator.userAgent);function K(){let[e,t]=(0,R.useState)(()=>window.wizardInstall??null),[n,r]=(0,R.useState)(!1);if((0,R.useEffect)(()=>{let e=()=>t(window.wizardInstall??null);return window.addEventListener(`wizard-install`,e),()=>window.removeEventListener(`wizard-install`,e)},[]),window.matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0||G&&!e&&!W)return null;let i=/Mac/.test(navigator.platform),a=f(G?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,V.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{G&&e?(e.prompt(),window.wizardInstall=null,t(null)):r(e=>!e)},className:`inline-flex items-center gap-1.5 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[G?(0,V.jsx)(L,{className:`size-4`}):(0,V.jsx)(te,{className:`size-4`}),f(G?`install.add`:`install.bookmark`)]}),n?(0,V.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function q({brand:e,toggle:t=!0}){return(0,V.jsx)(`header`,{className:`safe-top`,children:(0,V.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[e.logoUrl?(0,V.jsx)(`img`,{src:_(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,V.jsx)(`span`,{className:`max-w-[60%] truncate font-display font-semibold text-[0.9375rem] text-ink-2 tracking-tight`,children:e.name}):null,t?(0,V.jsx)(`div`,{className:`absolute right-3`,children:(0,V.jsx)(O,{})}):null]})})}function J({siteKey:e,onToken:t}){let n=(0,R.useRef)(null);return(0,R.useEffect)(()=>{let r=()=>{n.current&&window.turnstile&&!n.current.childElementCount&&window.turnstile.render(n.current,{sitekey:e,callback:t,appearance:`interaction-only`})};if(window.turnstile){r();return}let i=document.createElement(`script`);i.src=`https://challenges.cloudflare.com/turnstile/v0/api.js`,i.async=!0,i.onload=r,document.head.appendChild(i)},[e,t]),(0,V.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function oe({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||A||z?null:(0,V.jsxs)(`a`,{href:k(`${window.location.origin}${g}/w/${e}`),className:`mt-3 inline-flex items-center gap-1.5 text-[0.8125rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[(0,V.jsx)(F,{className:`size-4`}),` `,f(`install.app`)]})}var Y=e=>`wz.run.${e}`,X=A&&new URLSearchParams(window.location.search).get(`start`)===`1`,Z=z===`inline`?`min-h-80`:`min-h-dvh`;function Q(e,t){let n=v(),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(null),l=(()=>{try{return localStorage.getItem(Y(e.token))}catch{return null}})();return{busy:r,error:a,captcha:s,setCaptcha:c,start:async()=>{i(!0),o(null);try{let{runId:r}=await p.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:s??void 0,embedded:z!==null,origin:re??void 0});try{localStorage.setItem(Y(e.token),r)}catch{}n(`${t}/${r}`,{replace:X})}catch(e){o(e.message),i(!1)}},resume:l?()=>n(`${t}/${l}`):null}}function se({wizard:e}){let{busy:t,error:n,captcha:r,setCaptcha:i,start:a,resume:c}=Q(e,`/w/${e.token}`),l=X&&e.available&&!e.turnstileSiteKey,u=(0,R.useRef)(!1);return(0,R.useEffect)(()=>{l&&!u.current&&(u.current=!0,a())},[l]),l&&!n?(0,V.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,V.jsx)(o,{})}):(0,V.jsxs)(`div`,{className:`mx-auto flex max-w-lg animate-rise flex-col items-center px-6 pt-6 pb-12 text-center sm:pt-16 sm:pb-16`,children:[(0,V.jsx)(D,{kind:e.avatar,size:190,fluffy:!0}),(0,V.jsx)(`h1`,{className:`mt-2 text-balance font-display font-semibold text-[1.875rem] leading-[1.1] tracking-tight sm:text-[2.125rem]`,children:e.title}),e.description?(0,V.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,e.available?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(m,{size:`lg`,className:`mt-10 min-w-48`,busy:t,disabled:!!e.turnstileSiteKey&&!r,onClick:a,children:[f(`run.start`),` `,(0,V.jsx)(s,{className:`size-4`})]}),e.turnstileSiteKey?(0,V.jsx)(J,{siteKey:e.turnstileSiteKey,onToken:i}):null,c?(0,V.jsx)(`button`,{type:`button`,onClick:c,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:f(`run.resume`)}):null,(0,V.jsx)(ce,{wizard:e,current:`steps`}),z||A?null:(0,V.jsx)(K,{}),(0,V.jsx)(oe,{token:e.token})]}):(0,V.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??f(`run.unavailable`)}),n?(0,V.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:n}):null]})}function ce({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,V.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,V.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:f(`run.orAs`,{label:e.label})},e.id))}):null}function le({wizard:e}){let t=w();return(0,V.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,V.jsxs)(`div`,{className:`mx-auto flex h-16 w-full max-w-[760px] items-center gap-3 pr-2 pl-4 sm:pr-4 sm:pl-6`,children:[(0,V.jsx)(`span`,{className:i(t?.speaking&&`animate-breathe`),children:(0,V.jsx)(D,{kind:e.avatar,size:38})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,V.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null]}),e.brand.logoUrl&&z!==`popout`?(0,V.jsx)(`img`,{src:_(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,z?null:(0,V.jsx)(O,{}),z===`popout`?(0,V.jsx)(h,{label:f(`common.close`),onClick:ie,children:(0,V.jsx)(d,{className:`size-5`})}):null]})})}function $({door:e,wizard:t,header:n,footer:r}){let{busy:i,error:a,captcha:o,setCaptcha:c,start:l,resume:u}=Q(t,`/w/${t.token}/${e}`),d=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&d.push({key:e,who:`bot`,node:f(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||d.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??f(`run.unavailable`)}),a&&d.push({key:`error`,who:`bot`,node:a,tone:`error`}),t.available&&d.push(S(`start`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(b,{primary:!0,busy:i,disabled:!!t.turnstileSiteKey&&!o,onClick:()=>void l(),children:[f(`run.start`),` `,(0,V.jsx)(s,{className:`size-4`})]}),u?(0,V.jsx)(b,{onClick:u,children:f(`run.resume`)}):null,t.turnstileSiteKey?(0,V.jsx)(J,{siteKey:t.turnstileSiteKey,onToken:c}):null]}))),(0,V.jsxs)(x,{header:n,footer:r,children:[(0,V.jsx)(y,{avatar:t.avatar,lines:d}),(0,V.jsx)(C,{})]})}function ue({className:e}){return(0,V.jsx)(`footer`,{className:i(`text-center text-ink-4`,e),children:(0,V.jsx)(`a`,{href:`${g}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:f(`run.madeWith`).replace(`engenty wizards`,E.name)})})}function de({chat:e=!1,steps:t=!1,talk:n=!1,video:s=!1}){let{token:l,runId:d}=a(),h=v(),_=r({queryKey:[`public`,l],queryFn:()=>p.get(`/api/public/wizards/${l}`),retry:(e,t)=>c(t)&&e<3}),y=_.data?.runners??[],b=!_.data||y.some(e=>e.id===`talk`),x=!_.data||y.some(e=>e.id===`video`),S=!_.data||y.some(e=>e.id===`chat`)||n&&b||s&&x,C=y[0]?.id,w=e||z===`popout`||!t&&!d&&S&&(C===`chat`||C===`talk`||C===`video`),O=s&&x||!t&&!e&&!n&&C===`video`,k=!O&&(n&&b||!t&&!e&&C===`talk`),N=O?`video`:k?`talk`:`chat`;if(H(_.data?.brand.accent),ee(_.data?.avatar),U(l,_.data?.title),ae(w),(0,R.useEffect)(()=>{_.data&&(document.title=_.data.title)},[_.data]),(0,R.useEffect)(()=>{l&&d&&j(`run`,{token:l,runId:d})},[l,d]),_.isLoading)return(0,V.jsx)(`div`,{className:i(`flex items-center justify-center text-ink-4`,Z),children:(0,V.jsx)(o,{})});if(e&&_.data&&!S||n&&_.data&&!b||s&&_.data&&!x)return(0,V.jsx)(u,{to:`/w/${l}`,replace:!0});if(!_.data){let e=c(_.error);return(0,V.jsxs)(`div`,{className:i(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Z),children:[(0,V.jsx)(D,{kind:`pebble`,size:80}),(0,V.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:f(e?`common.offline`:`run.notFound`)}),e?(0,V.jsx)(m,{variant:`secondary`,onClick:()=>void _.refetch(),children:f(`common.retry`)}):null]})}if(w){let e=(0,V.jsx)(le,{wizard:_.data}),t=A?(0,V.jsx)(`div`,{className:`safe-bottom`}):(0,V.jsx)(ue,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,V.jsx)(`div`,{className:`flex h-dvh flex-col`,children:d?(0,V.jsx)(T,{runId:d,talk:k,call:O?`video`:k?`audio`:!1,onRestart:()=>h(`/w/${l}/${N}`),header:O||k?void 0:e,footer:t}):(0,V.jsx)($,{wizard:_.data,header:e,footer:t,door:N})})}return(0,V.jsxs)(`div`,{className:i(`flex flex-col`,Z),children:[z===`inline`||A?null:(0,V.jsx)(q,{brand:_.data.brand,toggle:!z}),(0,V.jsx)(`div`,{className:`flex-1`,children:d?(0,V.jsx)(M,{runId:d,onRestart:()=>h(`/w/${l}`)}):(0,V.jsx)(se,{wizard:_.data})}),A?(0,V.jsx)(`div`,{className:`safe-bottom`}):(0,V.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,V.jsx)(`a`,{href:`${g}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:f(`run.madeWith`).replace(`engenty wizards`,E.name)})})]})}export{q as BrandHeader,de as PublicRunner,H as useBrandAccent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{dn as n,kt as r}from"./ui-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{dn as n,kt as r}from"./ui-BOCXzzHi.js";import{t as i}from"./lock-DR7NakPn.js";var a={name:`text-align-start`,size:24,node:[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]],aliases:[`text`,`align-left`]};a.node;var o=n(a),s=e(t(),1);function c(e){return r(e.origin===`local`?`readonly.project`:`readonly.server`)}function l({children:e}){return(0,s.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-paper-2 px-4 py-3 text-[0.875rem] text-ink-2 leading-relaxed`,children:[(0,s.jsx)(i,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,s.jsx)(`p`,{className:`min-w-0`,children:e})]})}export{c as n,o as r,l as t};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,r as i}from"./logo-C4V2_3Ar.js";import{Bt as a,Dt as o,Nt as s,Rt as c,St as l,T as u,Tt as d,Wt as f,Xt as p,an as m,bt as h,dn as g,dt as _,ft as v,gt as y,ht as b,in as x,jt as S,kt as C,l as w,lt as T,mt as E,nn as D,pt as O,qt as k,st as A,ut as j,vt as M,wt as N,yt as P}from"./ui-BOCXzzHi.js";import{t as ee}from"./upload-B3yv8gsk.js";import{Gt as te,H as ne,R as re,U as F,Wt as ie,at as ae,it as I,ot as oe,tn as se,yn as L}from"./index-Df6UxElH.js";var R={name:`calendar`,size:24,node:[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};R.node;var ce=g(R),le={name:`files`,size:24,node:[[`path`,{d:`M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8`,key:`14sh0y`}],[`path`,{d:`M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z`,key:`1970lx`}],[`path`,{d:`M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1`,key:`l4dndm`}]]};le.node;var ue=g(le),de={name:`hash`,size:24,node:[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]};de.node;var z=g(de),B={name:`list-ordered`,size:24,node:[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]};B.node;var fe=g(B),V={name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]};V.node;var H=g(V),pe={name:`tags`,size:24,node:[[`path`,{d:`M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z`,key:`16rjxf`}],[`path`,{d:`M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193`,key:`178nd4`}],[`circle`,{cx:`10.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`12ikhr`}]]};pe.node;var me=g(pe),he={name:`toggle-left`,size:24,node:[[`circle`,{cx:`9`,cy:`12`,r:`3`,key:`u3jwor`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`7`,key:`g7kal2`}]]};he.node;var ge=g(he),U=e(t(),1),W=e(n(),1),G={choice:me,date:ce,number:z,text:ie,boolean:ge},K=e=>[`knowledge`,e];function _e(e){return e===1?C(`know.item`):C(`know.items`,{n:e})}function q(e,t){if(e.type===`boolean`||typeof t==`boolean`)return C(t?`know.yes`:`know.no`);if(e.type===`date`&&typeof t==`string`){let[e,n]=t.split(` `),r=new Date(`${e}T00:00:00`),i=Number.isNaN(r.getTime())?t:r.toLocaleDateString(o,{day:`2-digit`,month:`2-digit`,year:`numeric`});return n?`${i} ${n}`:i}return e.type===`number`&&typeof t==`number`?`${t.toLocaleString(o)}${e.unit?` ${e.unit}`:``}`:String(t)}function ve(e,t){return e.flatMap(e=>{let n=t.find(t=>t.categoryId===e.id);return n?e.type===`boolean`?n.values[0]===!0?[e.name]:[]:[n.values.map(t=>q(e,t)).join(`, `)]:[]}).join(` · `)}function ye({trigger:e,open:t,onOpen:n,children:r}){let i=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!t)return;let e=e=>{i.current?.contains(e.target)||n(!1)},r=e=>e.key===`Escape`&&n(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,r),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,r)}},[t,n]),(0,W.jsxs)(`div`,{ref:i,className:`relative inline-flex`,children:[e,t?(0,W.jsx)(`div`,{className:`absolute top-full left-0 z-30 mt-1.5 w-72 max-w-[calc(100vw-32px)] rounded-xl bg-card p-3 shadow-overlay ring-1 ring-border-soft`,children:r}):null]})}function be({category:e,current:t,onSave:n}){let[r,i]=(0,U.useState)(t[0]===void 0?``:String(t[0]));if(e.type===`choice`){let o=t.map(String);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[e.values.length?(0,W.jsx)(M,{multi:!0,value:o,options:e.values.map(e=>e.value),onChange:t=>n(e.multiple?t:t.filter(e=>!o.includes(e)).slice(0,1))}):null,(0,W.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),r.trim()&&n(e.multiple?[...o,r.trim()]:[r.trim()])},children:[(0,W.jsx)(b,{"data-autofocus":!0,value:o.includes(r)?``:r,placeholder:C(`know.addValue`),onChange:e=>i(e.target.value),className:`h-9`}),(0,W.jsx)(E,{label:C(`know.addValue`),type:`submit`,children:(0,W.jsx)(a,{className:`size-4`})})]})]})}return e.type===`boolean`?(0,W.jsx)(M,{value:t[0]===!0?C(`know.yes`):t[0]===!1?C(`know.no`):``,options:[C(`know.yes`),C(`know.no`)],onChange:e=>n([e===C(`know.yes`)])}):(0,W.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),n(r.trim()?[e.type===`number`?Number(r.replace(`,`,`.`)):r.trim()]:[])},children:[(0,W.jsx)(b,{"data-autofocus":!0,type:e.type===`date`?`date`:e.type===`number`?`number`:`text`,step:`any`,value:e.type===`date`?r.slice(0,10):r,onChange:e=>i(e.target.value),className:`h-9`}),(0,W.jsx)(T,{type:`submit`,size:`sm`,children:`OK`})]})}function xe({projectId:e,itemKey:t,has:n,categories:i,readOnly:o}){let s=r(),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(n);(0,U.useEffect)(()=>d(n),[n]);let f=L({mutationFn:({categoryId:n,next:r})=>w.put(`/api/studio/projects/${e}/items/${t}/categories/${n}`,{values:r}),onSuccess:()=>s.invalidateQueries({queryKey:K(e)})}),p=i.filter(e=>!(e.proposed||e.tableId)),m=(e,t)=>{d(n=>[...n.filter(t=>t.categoryId!==e.id),...t.length?[{categoryId:e.id,values:t,by:`person`}]:[]]),f.mutate({categoryId:e.id,next:t}),l(null)},h=p.filter(e=>u.some(t=>t.categoryId===e.id)),g=p.filter(e=>!u.some(t=>t.categoryId===e.id));return p.length?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[h.map(e=>{let t=u.find(t=>t.categoryId===e.id),n=G[e.type],r=(0,W.jsxs)(`button`,{type:`button`,disabled:o,title:`${e.name} · ${C(`know.by.${t.by}`)}`,onClick:()=>l(c===e.id?null:e.id),className:`inline-flex h-7 items-center gap-1.5 rounded-full bg-paper-2 px-2.5 text-[0.75rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink disabled:pointer-events-none`,children:[(0,W.jsx)(n,{className:`size-3.5 text-ink-3`}),(0,W.jsx)(`span`,{className:`text-ink-3`,children:e.name}),(0,W.jsx)(`span`,{className:`font-medium`,children:t.values.map(t=>q(e,t)).join(`, `)})]},e.id);return o?(0,W.jsx)(`span`,{children:r},e.id):(0,W.jsxs)(ye,{trigger:r,open:c===e.id,onOpen:t=>l(t?e.id:null),children:[(0,W.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-[0.8125rem]`,children:e.name}),(0,W.jsx)(E,{label:C(`know.remove`),onClick:()=>m(e,[]),className:`size-7`,children:(0,W.jsx)(S,{className:`size-3.5`})})]}),(0,W.jsx)(be,{category:e,current:t.values,onSave:t=>m(e,t)})]},e.id)}),o||!g.length?null:(0,W.jsx)(ye,{open:c===`+`,onOpen:e=>l(e?`+`:null),trigger:(0,W.jsxs)(`button`,{type:`button`,onClick:()=>l(c===`+`?null:`+`),className:`inline-flex h-7 items-center gap-1 rounded-full px-2 text-[0.75rem] text-ink-3 ring-1 ring-border-soft transition hover:text-ink hover:ring-border`,children:[(0,W.jsx)(a,{className:`size-3.5`}),` `,C(`know.category`)]}),children:(0,W.jsx)(Se,{categories:g,onSave:m})})]}):null}function Se({categories:e,onSave:t}){let[n,r]=(0,U.useState)(e[0]?.id??``),i=e.find(e=>e.id===n);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,W.jsx)(P,{value:n,onChange:r,options:e.map(e=>({value:e.id,label:e.name}))}),i?(0,W.jsx)(be,{category:i,current:[],onSave:e=>t(i,e)},i.id):null]})}function Ce({projectId:e,open:t,onClose:n,onMade:i}){let a=r(),[o,s]=(0,U.useState)(``),[c,u]=(0,U.useState)(`choice`),[d,f]=(0,U.useState)(``),[p,m]=(0,U.useState)(!1),[h,g]=(0,U.useState)(!1),[_,x]=(0,U.useState)(``),[S,E]=(0,U.useState)(``),D=L({mutationFn:()=>w.post(`/api/studio/projects/${e}/categories`,{name:o.trim(),type:c,unit:c===`number`&&d.trim()||null,multiple:c===`choice`&&p,ordered:c===`choice`&&h,hint:S.trim()||null,values:c===`choice`?_.split(`
|
|
2
|
+
`).map(e=>e.trim()).filter(Boolean):void 0}),onSuccess:async({id:t})=>{await a.invalidateQueries({queryKey:K(e)}),s(``),x(``),E(``),i(t)}});return(0,W.jsx)(v,{open:t,onClose:n,title:C(`know.newCategory`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o.trim()&&D.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{children:C(`know.name`)}),(0,W.jsx)(b,{"data-autofocus":!0,value:o,maxLength:80,onChange:e=>s(e.target.value)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{children:C(`know.type`)}),(0,W.jsx)(P,{value:c,onChange:e=>u(e),options:[`choice`,`date`,`number`,`text`,`boolean`].map(e=>({value:e,label:C(`know.type.${e}`)}))})]}),c===`number`?(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{hint:C(`know.unitHint`),children:C(`know.unit`)}),(0,W.jsx)(b,{value:d,maxLength:20,onChange:e=>f(e.target.value)})]}):null,c===`choice`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{hint:C(`know.valuesHint`),children:C(`know.values`)}),(0,W.jsx)(N,{minRows:3,value:_,onChange:e=>x(e.target.value)})]}),(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[C(`know.multiple`),(0,W.jsx)(l,{checked:p,onChange:m})]}),(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[C(`know.ordered`),(0,W.jsx)(l,{checked:h,onChange:g})]})]}):null,(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{hint:C(`know.hintFieldHint`),children:C(`know.hintField`)}),(0,W.jsx)(b,{value:S,maxLength:120,onChange:e=>E(e.target.value)})]}),D.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:D.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(T,{variant:`ghost`,onClick:n,children:C(`common.cancel`)}),(0,W.jsx)(T,{type:`submit`,busy:D.isPending,disabled:!o.trim(),children:C(`know.create`)})]})]})})}function we({projectId:e,category:t,readOnly:n,onOpen:i,onGone:o}){let c=r(),l=()=>c.invalidateQueries({queryKey:K(e)}),[u,d]=(0,U.useState)(``),f=L({mutationFn:e=>e(),onSuccess:l}),p=G[t.type],m=new Map(t.values.map(e=>[e.id,e]));return(0,W.jsxs)(F,{title:t.name,hint:[C(`know.type.${t.type}`),t.unit,t.hint].filter(Boolean).join(` · `),plain:!0,action:n?null:(0,W.jsx)(E,{label:C(`know.deleteCategory`),className:`hover:text-rose`,onClick:()=>confirm(C(`know.confirmCategory`,{name:t.name}))&&f.mutate(async()=>{await w.del(`/api/studio/categories/${t.id}`),o()}),children:(0,W.jsx)(s,{className:`size-4`})}),children:[t.proposed&&!n?(0,W.jsxs)(j,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,W.jsx)(_,{tone:`ember`,children:C(`know.proposed`)}),(0,W.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:C(`know.proposedHint`)}),(0,W.jsx)(T,{size:`sm`,onClick:()=>f.mutate(()=>w.patch(`/api/studio/categories/${t.id}`,{proposed:!1})),children:C(`know.accept`)})]}):null,t.alike.map(([e,t])=>{let r=m.get(e),i=m.get(t);if(!(r&&i))return null;let[a,o]=r.count<i.count?[r,i]:[i,r];return(0,W.jsxs)(j,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,W.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:C(`know.alike`,{a:a.value,b:o.value})}),n?null:(0,W.jsx)(T,{size:`sm`,variant:`secondary`,busy:f.isPending,onClick:()=>f.mutate(()=>w.post(`/api/studio/values/${a.id}/merge`,{into:o.id})),children:C(`know.merge`)})]},`${e}:${t}`)}),(0,W.jsxs)(j,{className:`flex flex-col p-1.5`,children:[t.type===`choice`?t.values.length?t.values.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i(`v:${e.id}`),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,W.jsx)(p,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.value}),e.summary?(0,W.jsx)(_,{children:C(`know.summary`)}):null,(0,W.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:_e(e.count)})]},e.id)):(0,W.jsx)(O,{children:C(`know.empty`)}):(0,W.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5 text-[0.875rem]`,children:[(0,W.jsx)(p,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`flex-1 text-ink-2`,children:t.range?C(`know.range`,{min:q(t,t.range.min),max:q(t,t.range.max)}):C(`know.unset`)}),(0,W.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:_e(t.count)})]}),t.type===`choice`&&!n?(0,W.jsxs)(`form`,{className:`flex gap-2 border-border-soft border-t p-2`,onSubmit:e=>{e.preventDefault();let n=u.trim();n&&(d(``),f.mutate(()=>w.post(`/api/studio/categories/${t.id}/values`,{value:n})))},children:[(0,W.jsx)(b,{value:u,placeholder:C(`know.addValue`),onChange:e=>d(e.target.value),className:`h-9`}),(0,W.jsx)(E,{label:C(`know.addValue`),type:`submit`,children:(0,W.jsx)(a,{className:`size-4`})})]}):null]}),f.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:f.error.message}):null]})}function Te(e){return i({queryKey:[`knowledge-value`,e],queryFn:()=>w.get(`/api/studio/values/${e}`),enabled:!!e})}function Ee({value:e,readOnly:t,children:n}){let i=r(),a=L({mutationFn:()=>w.post(`/api/studio/values/${e.id}/summary`),onSuccess:()=>i.invalidateQueries({queryKey:[`knowledge-value`,e.id]})});return(0,W.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,W.jsx)(F,{title:C(`know.summary`),hint:C(`know.summaryHint`),plain:!0,action:t?null:(0,W.jsxs)(T,{variant:`secondary`,size:`sm`,busy:a.isPending,onClick:()=>a.mutate(),children:[e.summary?(0,W.jsx)(c,{className:`size-4`}):null,e.summary?C(`know.summaryAgain`):C(`know.summaryWrite`)]}),children:(0,W.jsxs)(j,{className:`p-4 sm:p-5`,children:[a.isPending?(0,W.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,W.jsx)(h,{})}):e.summary?(0,W.jsx)(u,{text:e.summary,className:`text-[0.875rem]`}):(0,W.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:C(`know.summaryEmpty`)}),a.error?(0,W.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:a.error.message}):null]})}),(0,W.jsx)(F,{title:C(`know.toc`),plain:!0,children:n})]})}function De(e){return i({queryKey:[`knowledge`,e],queryFn:()=>w.get(`/api/studio/projects/${e}/knowledge`),enabled:!!e,refetchInterval:e=>e.state.data?.items.some(e=>e.status===`pending`)?2e3:!1})}function Oe(e){return e.kind===`table`?e.format===`faq`?H:te:e.kind===`file`?f:e.children?ue:p}function J({item:e,categories:t,onOpen:n}){let r=Oe(e),i=[ve(t,e.categories),e.children?e.children===1?C(`know.oneSub`):C(`know.sub`,{n:e.children}):``,e.rows===null?``:e.rows===1?C(`know.row`):C(`know.rows`,{n:e.rows}),e.originLabel??``].filter(Boolean).join(` · `);return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(e.key),disabled:e.status===`pending`,className:`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,W.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`span`,{className:`block truncate text-[0.875rem]`,children:e.title}),i?(0,W.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:i}):null]}),e.status===`pending`?(0,W.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[(0,W.jsx)(h,{className:`size-3`}),` `,C(`know.reading`)]}):e.review?(0,W.jsx)(_,{tone:`warn`,title:e.review,children:C(`know.review`)}):null]})}function Y({projectId:e,itemKey:t,has:n,originLabel:r,kept:i,review:a,file:o,readOnly:s,onReviewed:c}){let l=De(e),u=[r?C(i?`know.kept`:`know.from`,{label:r}):``].filter(Boolean);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[l.data?(0,W.jsx)(xe,{projectId:e,itemKey:t,has:n,categories:l.data.categories,readOnly:s}):null,u.length||o||a?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.8125rem] text-ink-3`,children:[u.map(e=>(0,W.jsx)(`span`,{children:e},e)),o?(0,W.jsxs)(`a`,{href:I(e,o.id),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 underline-offset-2 hover:text-ink hover:underline`,children:[(0,W.jsx)(f,{className:`size-3.5`}),` `,C(`know.original`),`: `,o.name]}):null,a?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,W.jsx)(_,{tone:`warn`,children:C(`know.review`)}),(0,W.jsx)(`span`,{children:a}),s?null:(0,W.jsx)(`button`,{type:`button`,onClick:c,className:`underline hover:text-ink`,children:C(`know.reviewed`)})]}):null]}):null]})}function ke(e){let t=e.filter(Number.isFinite).sort((e,t)=>e-t);if(new Set(t).size<=4)return[];let n=t[0],r=t.at(-1),i=e=>e.slice(0,-1).map((t,n)=>({lo:t,hi:e[n+1]})).filter(e=>t.some(t=>t>=e.lo&&t<e.hi));if(n>0&&r/n>=30){let e=Math.floor(Math.log10(n)),t=Math.floor(Math.log10(r))+1;for(let a of[[1,2,5],[1,3],[1]]){let o=[];for(let n=e;n<=t;n++)for(let e of a)o.push(e*10**n);let s=i(o.filter((e,t)=>e<=n||o[t-1]<=r));if(s.length<=7)return s}}let a=(r-n)/5,o=10**Math.floor(Math.log10(a)),s=([1,2,2.5,5,10].map(e=>e*o).find(e=>e>=a)??a)||1,c=[];for(let e=Math.floor(n/s)*s;e<=r;e+=s)c.push(e);return c.push(c.at(-1)+s),i(c)}function Ae({projectId:e,category:t,categories:n,onOpen:r}){let a=i({queryKey:[`knowledge`,e,`category`,t.id],queryFn:()=>w.get(`/api/studio/categories/${t.id}/items`)});if(!a.data)return a.isLoading?(0,W.jsx)(h,{className:`mx-auto size-4 text-ink-3`}):null;let s=e=>e.categories.find(e=>e.categoryId===t.id)?.values[0],c=[...a.data.items].sort((e,t)=>{let n=s(e),r=s(t);return typeof n==`number`&&typeof r==`number`?n-r:String(r??``).localeCompare(String(n??``),o)}),l=t.type===`number`?ke(c.map(s).filter(e=>typeof e==`number`)):[],u=new Intl.NumberFormat(o,{notation:`compact`,maximumFractionDigits:1}),d=t.unit?` ${t.unit}`:``,f=new Map;for(let e of c){let n=s(e),r=typeof n==`number`?l.find(e=>n>=e.lo&&n<e.hi):void 0,i=n===void 0?``:t.type===`date`?new Date(`${String(n).slice(0,7)}-01T00:00:00`).toLocaleDateString(o,{month:`long`,year:`numeric`}):r?C(`know.range`,{min:`${u.format(r.lo)}${d}`,max:`${u.format(r.hi)}${d}`}):q(t,n);f.set(i,[...f.get(i)??[],e])}return(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[[...f].map(([e,t])=>(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[e?(0,W.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e}):null,(0,W.jsx)(j,{className:`flex flex-col p-1.5`,children:t.map(e=>(0,W.jsx)(J,{item:e,categories:n,onOpen:r},e.key))})]},e)),a.data.rows.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>r(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:C(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})}function je(e,t,n){return Array.isArray(n)?t.some(e=>n.map(String).includes(String(e))):typeof n==`object`&&n?t.some(t=>{if(e.type===`number`&&typeof t==`number`)return(n.gte===void 0||t>=n.gte)&&(n.lte===void 0||t<=n.lte);if(e.type===`date`){let e=String(t).slice(0,10);return(!n.after||e>=n.after)&&(!n.before||e<=n.before)}return!n.contains||String(t).toLowerCase().includes(n.contains.toLowerCase())}):t.some(e=>e===n)}function Me(e,t){if(Array.isArray(t))return t.map(String).join(`, `);if(typeof t==`boolean`)return C(t?`know.yes`:`know.no`);if(typeof t==`object`&&t){let n=t.gte??t.after,r=t.lte??t.before;return t.contains?`${C(`know.contains`)} ${t.contains}`:[n===void 0?``:`${C(`know.minimum`)} ${q(e,n)}`,r===void 0?``:`${C(`know.maximum`)} ${q(e,r)}`].filter(Boolean).join(` `)}return String(t)}function Ne({category:e,value:t,onChange:n}){let[r,i]=(0,U.useState)(!1),a=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!r)return;let e=e=>!a.current?.contains(e.target)&&i(!1);return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[r]);let o=G[e.type],s=typeof t==`object`&&t&&!Array.isArray(t)?t:{},c=(t,r)=>{let i={...s,[t]:r===``?void 0:e.type===`number`?Number(r):r},a=Object.fromEntries(Object.entries(i).filter(([,e])=>e!==void 0));n(Object.keys(a).length?a:void 0)};return(0,W.jsxs)(`div`,{ref:a,className:`relative`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:d(`inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-[0.8125rem] transition`,t===void 0?`text-ink-2 ring-1 ring-border-soft hover:ring-border`:`bg-ember-tint text-ink ring-1 ring-ember/30`),children:[(0,W.jsx)(o,{className:`size-3.5 text-ink-3`}),e.name,t===void 0?null:(0,W.jsxs)(`span`,{className:`font-medium`,children:[`: `,Me(e,t)]}),(0,W.jsx)(x,{className:`size-3.5 text-ink-3`})]}),r?(0,W.jsxs)(`div`,{className:`absolute top-full left-0 z-30 mt-1.5 w-72 max-w-[calc(100vw-32px)] rounded-xl bg-card p-3 shadow-overlay ring-1 ring-border-soft`,children:[e.type===`choice`?(0,W.jsx)(M,{multi:!0,value:Array.isArray(t)?t.map(String):[],options:e.values.map(e=>e.value),onChange:e=>n(e.length?e:void 0)}):e.type===`boolean`?(0,W.jsx)(M,{value:t===!0?C(`know.yes`):t===!1?C(`know.no`):``,options:[C(`know.yes`),C(`know.no`)],onChange:e=>n(e===C(`know.yes`))}):e.type===`text`?(0,W.jsx)(b,{"data-autofocus":!0,value:s.contains??``,placeholder:C(`know.contains`),onChange:e=>n(e.target.value?{contains:e.target.value}:void 0),className:`h-9`}):(0,W.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:(e.type===`number`?[`gte`,`lte`]:[`after`,`before`]).map((t,n)=>(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{children:C(n===0?`know.minimum`:`know.maximum`)}),(0,W.jsx)(b,{type:e.type===`number`?`number`:`date`,step:`any`,value:String(s[t]??``),placeholder:e.range?String(n===0?e.range.min:e.range.max):``,onChange:e=>c(t,e.target.value),className:`h-9`})]},t))}),t===void 0?null:(0,W.jsx)(`button`,{type:`button`,onClick:()=>{n(void 0),i(!1)},className:`mt-3 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:C(`know.clear`)})]}):null]})}function Pe({found:e,onOpen:t}){return e.hits.length?(0,W.jsxs)(`div`,{className:`flex flex-col`,children:[(0,W.jsx)(`p`,{className:`px-3 pt-1 pb-2 text-[0.75rem] text-ink-3`,children:e.checked?C(`know.searchStats`,{candidates:e.candidates,hits:e.hits.length}):C(`know.searchUnchecked`,{hits:e.hits.length})}),e.hits.map(e=>{let n=e.open;return(0,W.jsxs)(`button`,{type:`button`,disabled:!n,onClick:()=>n&&t(n),className:`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`span`,{className:`block truncate text-[0.875rem]`,children:[e.title,e.heading&&e.heading!==e.title?(0,W.jsxs)(`span`,{className:`text-ink-3`,children:[` › `,e.heading]}):null]}),(0,W.jsx)(`span`,{className:`line-clamp-2 text-[0.8125rem] text-ink-3`,children:e.text})]}),e.relevance===null?null:(0,W.jsx)(`span`,{className:`shrink-0 font-medium text-[0.75rem] text-moss tabular-nums`,children:e.relevance.toLocaleString(o,{minimumFractionDigits:2})})]},`${e.key}:${e.heading}`)})]}):(0,W.jsx)(`p`,{className:`px-3 py-4 text-[0.875rem] text-ink-3`,children:C(`know.searchNone`)})}function Fe({kind:e,projectId:t,onClose:n,onMade:i}){let a=r(),[o,s]=(0,U.useState)(``),[c,u]=(0,U.useState)(!1),d=L({mutationFn:()=>w.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:o.trim(),...e===`table`&&c?{format:`faq`}:{}}),onSuccess:async({id:n})=>{await a.invalidateQueries({queryKey:[`knowledge`,t]}),i(`${e===`table`?`t`:`p`}:${n}`),s(``),u(!1)}});return(0,W.jsx)(v,{open:e!==null,onClose:n,title:C(e===`table`?`know.newTable`:`know.newPage`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o.trim()&&d.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{children:C(`data.title`)}),(0,W.jsx)(b,{"data-autofocus":!0,value:o,maxLength:120,onChange:e=>s(e.target.value)})]}),e===`table`?(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[C(`know.asFaq`),(0,W.jsx)(l,{checked:c,onChange:u})]}):null,d.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(T,{variant:`ghost`,onClick:n,children:C(`common.cancel`)}),(0,W.jsx)(T,{type:`submit`,busy:d.isPending,disabled:!o.trim(),children:C(`know.create`)})]})]})})}function Ie({projectId:e,data:t,readOnly:n,onOpen:i}){let o=r(),s=oe(e,n),[c,l]=(0,U.useState)({}),[u,d]=(0,U.useState)(``),[f,p]=(0,U.useState)(null),[m,g]=(0,U.useState)(!1),[v,y]=(0,U.useState)(null),b=t.categories.filter(e=>!e.proposed&&e.count>0),x=t.categories.filter(e=>e.proposed),S=t.items.filter(e=>Object.entries(c).every(([n,r])=>{let i=t.categories.find(e=>e.name===n),a=e.categories.find(e=>e.categoryId===i?.id);return i&&a?je(i,a.values,r):!1})),E=async()=>{if(!u.trim()){p(null);return}g(!0);try{p(await w.post(`/api/studio/projects/${e}/search`,{query:u,...Object.keys(c).length?{where:c}:{}}))}catch{p({hits:[],candidates:0,checked:!1,filtered:null})}finally{g(!1)}},D=L({mutationFn:({id:e,keep:t})=>t?w.patch(`/api/studio/categories/${e}`,{proposed:!1}):w.del(`/api/studio/categories/${e}`),onSuccess:()=>o.invalidateQueries({queryKey:[`knowledge`,e]})});return(0,W.jsxs)(F,{title:C(`know.title`),hint:C(`know.hint`),plain:!0,action:n?null:(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,W.jsxs)(T,{variant:`secondary`,size:`sm`,onClick:()=>y(`page`),children:[(0,W.jsx)(a,{className:`size-4`}),` `,C(`know.page`)]}),(0,W.jsxs)(T,{variant:`secondary`,size:`sm`,onClick:()=>y(`table`),children:[(0,W.jsx)(a,{className:`size-4`}),` `,C(`know.table`)]}),(0,W.jsxs)(T,{variant:`secondary`,size:`sm`,onClick:()=>y(`category`),children:[(0,W.jsx)(a,{className:`size-4`}),` `,C(`know.category`)]})]}),children:[x.length&&!n?(0,W.jsx)(j,{className:`flex flex-col gap-2 p-4`,children:x.map(e=>{let t=G[e.type];return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,W.jsx)(_,{tone:`ember`,children:C(`know.proposed`)}),(0,W.jsx)(t,{className:`size-4 text-ink-3`}),(0,W.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:e.name}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink-3`,children:[C(`know.type.${e.type}`),e.hint].filter(Boolean).join(` · `)}),(0,W.jsx)(T,{size:`sm`,variant:`ghost`,onClick:()=>D.mutate({id:e.id,keep:!1}),children:C(`know.dismiss`)}),(0,W.jsx)(T,{size:`sm`,onClick:()=>D.mutate({id:e.id,keep:!0}),children:C(`know.accept`)})]},e.id)})}):null,t.items.length?(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,W.jsx)(ne,{value:u,placeholder:C(`know.search`),busy:m,onEnter:()=>void E(),onChange:e=>{d(e),e.trim()||p(null)}}),b.length?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[b.map(e=>(0,W.jsx)(Ne,{category:e,value:c[e.name],onChange:t=>{p(null),l(n=>{let r={...n};return t===void 0?delete r[e.name]:r[e.name]=t,r})}},e.id)),Object.keys(c).length?(0,W.jsx)(`button`,{type:`button`,onClick:()=>l({}),className:`px-2 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:C(`know.clear`)}):null]}):null]}):null,(0,W.jsx)(j,{className:`flex flex-col p-1.5`,children:f?(0,W.jsx)(Pe,{found:f,onOpen:i}):S.length?S.map(e=>(0,W.jsx)(J,{item:e,categories:t.categories,onOpen:i},e.key)):(0,W.jsx)(O,{children:C(`know.empty`)})}),n?null:(0,W.jsxs)(re,{accept:`.pdf,.docx,.doc,.xlsx,.csv,.tsv,.txt,.md,.json,.html,.eml,image/*`,onFiles:async t=>{await s.upload(`document`,t),await o.invalidateQueries({queryKey:[`knowledge`,e]})},className:`h-14 w-full`,children:[s.busy?(0,W.jsx)(h,{className:`size-4`}):(0,W.jsx)(ee,{className:`size-4`}),C(`know.drop`),` `,(0,W.jsx)(`span`,{className:`underline`,children:C(`know.pick`)})]}),s.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error}):null,t.items.length&&!(t.checked&&t.embeddings)?(0,W.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:[t.embeddings?``:C(`know.keywordsOnly`),t.checked?``:C(`know.unchecked`)].filter(Boolean).join(` `)}):null,(0,W.jsx)(Fe,{kind:v===`page`||v===`table`?v:null,projectId:e,onClose:()=>y(null),onMade:e=>{y(null),i(e)}}),(0,W.jsx)(Ce,{projectId:e,open:v===`category`,onClose:()=>y(null),onMade:e=>{y(null),i(`c:${e}`)}})]})}function Le({page:e,onGone:t,onOpen:n}){let i=r(),[o,c]=(0,U.useState)(e.title),[l,f]=(0,U.useState)(e.markdown),[g,_]=(0,U.useState)(e.markdown?`read`:`write`),v=e.knowledge,y=async()=>{await i.invalidateQueries({queryKey:[`space-data`,e.projectId]}),await i.invalidateQueries({queryKey:[`knowledge`,e.projectId]})},b=ae({title:o.trim()||e.title,markdown:l},async t=>{await w.patch(`/api/studio/pages/${e.id}`,t),i.setQueryData([`space-page`,e.id],e=>e&&{...e,...t}),t.title!==e.title&&await y()}),x=L({mutationFn:()=>w.del(`/api/studio/pages/${e.id}`),onSuccess:async()=>{await y(),t()}}),S=L({mutationFn:()=>w.post(`/api/studio/projects/${e.projectId}/pages`,{title:C(`know.addSub`),parentId:e.id}),onSuccess:async({id:e})=>{await y(),n?.(`p:${e}`)}}),O=L({mutationFn:()=>w.patch(`/api/studio/pages/${e.id}`,{review:null}),onSuccess:()=>i.invalidateQueries({queryKey:[`space-page`,e.id]})}),k=async t=>{let r=t.target.closest(`a`)?.getAttribute(`href`);if(!(r?.startsWith(`pages/`)&&n))return;t.preventDefault();let i=await w.get(`/api/studio/projects/${e.projectId}/resolve?path=${encodeURIComponent(r)}`).catch(()=>null);i?.kind===`page`&&n(`p:${i.id}`)},A=e.readOnly,M=v?.file&&(v.file.mime===`application/pdf`||v.file.mime.startsWith(`image/`))?v.file:null,N=(e,t)=>(0,W.jsx)(`button`,{type:`button`,"aria-pressed":g===e,onClick:()=>_(e),className:d(`rounded-full px-3 py-1 text-[0.8125rem] transition`,g===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,W.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[v?.parents.length&&n?(0,W.jsx)(`nav`,{className:`-mb-1.5 flex flex-wrap items-center gap-1 px-1 text-[0.8125rem] text-ink-3`,children:v.parents.map(e=>(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`hover:text-ink`,children:e.title}),(0,W.jsx)(D,{className:`size-3.5`})]},e.id))}):null,(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,W.jsx)(`input`,{value:o,disabled:A,maxLength:200,onChange:e=>c(e.target.value),"aria-label":C(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),b.state===`saving`?(0,W.jsx)(h,{className:`size-3.5 text-ink-3`}):b.state===`saved`?(0,W.jsx)(m,{className:`size-4 text-moss`,"aria-label":C(`settings.saved`)}):null,A?null:(0,W.jsx)(E,{label:C(`data.deletePage`),onClick:()=>confirm(C(`data.confirmDelete`,{title:e.title}))&&x.mutate(),className:`hover:text-rose`,children:(0,W.jsx)(s,{className:`size-4`})})]}),v?(0,W.jsx)(Y,{projectId:e.projectId,itemKey:`p:${e.id}`,has:v.categories,originLabel:v.originLabel,kept:v.kept,review:v.review,file:M?null:v.file,readOnly:A,onReviewed:()=>O.mutate()}):null,(0,W.jsxs)(j,{className:`flex flex-col`,children:[A&&!M?null:(0,W.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[A?null:N(`write`,C(`data.write`)),N(`read`,C(`data.preview`)),M?N(`original`,C(`know.original`)):null,(0,W.jsx)(`span`,{className:`ml-auto truncate px-2 text-[0.75rem] text-ink-4 max-sm:hidden`,children:g===`original`&&M?M.name:C(`data.markdownHint`)})]}),g===`original`&&M?M.mime===`application/pdf`?(0,W.jsx)(`iframe`,{src:I(e.projectId,M.id),title:M.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,W.jsx)(`img`,{src:I(e.projectId,M.id),alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):g===`write`&&!A?(0,W.jsx)(`textarea`,{value:l,onChange:e=>f(e.target.value),"aria-label":e.title,placeholder:C(`data.pageEmpty`),className:`field-sizing-content min-h-[50vh] w-full resize-none bg-transparent p-4 font-mono text-[0.8125rem] leading-relaxed outline-none placeholder:text-ink-4 sm:p-5`}):(0,W.jsx)(`div`,{className:`min-h-40 p-4 sm:p-5`,onClick:k,children:l.trim()?(0,W.jsx)(u,{text:l}):(0,W.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:C(`data.pageEmpty`)})})]}),b.state===`error`&&b.error?(0,W.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:b.error}):null,v&&n&&(v.children.length||!A)?(0,W.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-1`,children:[(0,W.jsx)(`p`,{className:`font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:v.children.length?C(`know.subPages`):null}),A?null:(0,W.jsxs)(T,{variant:`ghost`,size:`sm`,busy:S.isPending,onClick:()=>S.mutate(),children:[(0,W.jsx)(a,{className:`size-4`}),` `,C(`know.addSub`)]})]}),v.children.length?(0,W.jsx)(j,{className:`flex flex-col p-1.5`,children:v.children.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`flex items-center gap-3 rounded-lg px-3 py-2 text-left transition hover:bg-accent`,children:[(0,W.jsx)(p,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title})]},e.id))}):null]}):null]})}function Re({pageId:e,onGone:t,onOpen:n}){let r=i({queryKey:[`space-page`,e],queryFn:()=>w.get(`/api/studio/pages/${e}`),refetchOnWindowFocus:!1});return r.data?(0,W.jsx)(Le,{page:r.data,onGone:t,onOpen:n},r.data.id):r.isError?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:r.error.message}):null}function ze(e){return i({queryKey:[`space-data`,e],queryFn:()=>w.get(`/api/studio/projects/${e}/data`),enabled:!!e})}function Be(e){let t=t=>[...e.tables.filter(e=>e.wizardId===t).map(e=>({key:`t:${e.id}`,kind:`table`,title:e.title,rows:e.rows})),...e.pages.filter(e=>e.wizardId===t).map(e=>({key:`p:${e.id}`,kind:`page`,title:e.title}))];return[{key:`own`,label:C(`data.own`),items:t(null)},...e.wizards.map(e=>({key:e.id,label:e.title,items:t(e.id)}))].filter(e=>e.items.length)}var Ve={table:te,page:p};function He({kind:e,projectId:t,data:n,onClose:i,onMade:a}){let o=r(),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(``),d=L({mutationFn:()=>w.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:s.trim(),wizardId:l||null}),onSuccess:async({id:n})=>{await o.invalidateQueries({queryKey:[`space-data`,t]}),a(`${e===`table`?`t`:`p`}:${n}`),c(``),u(``)}});return(0,W.jsx)(v,{open:e!==null,onClose:i,title:C(e===`table`?`data.newTable`:`data.newPage`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),s.trim()&&d.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{children:C(`data.title`)}),(0,W.jsx)(b,{"data-autofocus":!0,value:s,maxLength:120,onChange:e=>c(e.target.value)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{children:C(`data.owner`)}),(0,W.jsx)(P,{value:l,onChange:u,options:[{value:``,label:C(`data.own`)},...n.wizards.map(e=>({value:e.id,label:e.title}))]})]}),d.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(T,{variant:`ghost`,onClick:i,children:C(`common.cancel`)}),(0,W.jsx)(T,{type:`submit`,busy:d.isPending,disabled:!s.trim(),children:C(`data.create`)})]})]})})}function Ue({projectId:e,data:t,readOnly:n,onOpen:r}){let[i,s]=(0,U.useState)(null),c=Be(t),l=new Map([...t.tables.map(e=>[`t:${e.id}`,e.updatedAt]),...t.pages.map(e=>[`p:${e.id}`,e.updatedAt])]),u=new Intl.DateTimeFormat(o,{dateStyle:`medium`});return(0,W.jsxs)(F,{title:C(`space.data`),hint:C(`data.hint`),plain:!0,action:n?null:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(T,{variant:`secondary`,size:`sm`,onClick:()=>s(`table`),children:[(0,W.jsx)(a,{className:`size-4`}),` `,C(`data.table`)]}),(0,W.jsxs)(T,{variant:`secondary`,size:`sm`,onClick:()=>s(`page`),children:[(0,W.jsx)(a,{className:`size-4`}),` `,C(`data.page`)]})]}),children:[c.length?(0,W.jsx)(`div`,{className:`flex flex-col gap-5`,children:c.map(e=>(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e.label}),(0,W.jsx)(j,{className:`flex flex-col p-1.5`,children:e.items.map(e=>{let t=Ve[e.kind];return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>r(e.key),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,W.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title}),(0,W.jsxs)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:[e.kind===`table`?`${C(`data.rows`,{n:e.rows??0})} · `:``,u.format(new Date(l.get(e.key)??Date.now()))]})]},e.key)})})]},e.key))}):(0,W.jsx)(j,{children:(0,W.jsx)(O,{children:C(`data.empty`)})}),(0,W.jsx)(He,{kind:i,projectId:e,data:t,onClose:()=>s(null),onMade:e=>{s(null),r(e)}})]})}function We(e,t){let n=e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).replace(/^[^a-z]+/,``).slice(0,48)||`column`,r=n,i=2;for(;t.includes(r);)r=`${n}_${i++}`;return r}var Ge={milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5},Ke=[`text`,`number`,`date`,`duration`,`select`,`boolean`];function qe(e,t){if(t==null)return``;if(e.type===`duration`&&typeof t==`number`)return String(t/Ge[e.format.inputUnit]);if(e.type===`date`&&e.format.kind===`datetime`&&typeof t==`string`){let e=new Date(t);return new Date(e.getTime()-e.getTimezoneOffset()*6e4).toISOString().slice(0,16)}return String(t)}function Je(e,t){return t.trim()===``?null:e.type===`date`&&e.format.kind===`datetime`?new Date(t).toISOString():t}var X=`w-full min-w-0 rounded-md bg-transparent px-2 py-1.5 text-[0.875rem] outline-none transition placeholder:text-ink-4 hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`;function Ye({column:e,value:t,readOnly:n,invalid:r,onSave:i}){let a=qe(e,t),[o,s]=(0,U.useState)(a);(0,U.useEffect)(()=>s(a),[a]);let c=(t=o)=>{t!==a&&i(Je(e,t))};if(e.type===`boolean`)return(0,W.jsx)(`div`,{className:`px-2 py-1.5`,children:(0,W.jsx)(`input`,{type:`checkbox`,checked:t===!0,disabled:n,onChange:e=>i(e.target.checked),"aria-label":e.name,className:`size-4 accent-[var(--ember)]`})});if(e.type===`select`&&e.format.multiple){let r=Array.isArray(t)?t:[],a=t=>e.format.options.find(e=>e.id===t)?.label??t;return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-2 py-1`,children:[r.map(e=>(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-paper-2 py-0.5 pr-1 pl-2 text-[0.75rem]`,children:[a(e),n?null:(0,W.jsx)(`button`,{type:`button`,"aria-label":C(`data.removeOption`),onClick:()=>i(r.filter(t=>t!==e)),className:`rounded-full text-ink-3 hover:text-ink`,children:(0,W.jsx)(S,{className:`size-3`})})]},e)),n?null:(0,W.jsxs)(`select`,{value:``,onChange:e=>e.target.value&&i([...r,e.target.value]),"aria-label":e.name,className:`h-7 rounded-md bg-transparent px-1 text-[0.75rem] text-ink-3 outline-none hover:bg-accent`,children:[(0,W.jsx)(`option`,{value:``,children:`+`}),e.format.options.filter(e=>!r.includes(e.id)).map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})}if(e.type===`select`)return(0,W.jsxs)(`select`,{value:typeof t==`string`?t:``,disabled:n,onChange:e=>i(e.target.value||null),"aria-label":e.name,className:X,children:[(0,W.jsx)(`option`,{value:``}),e.format.options.map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]});if(e.type===`text`&&e.format?.style&&e.format.style!==`single`)return(0,W.jsx)(`textarea`,{value:o,rows:1,disabled:n,onChange:e=>s(e.target.value),onBlur:()=>c(),"aria-label":e.name,className:d(X,`field-sizing-content max-h-40 resize-none`)});let l=e.type===`date`?{date:`date`,datetime:`datetime-local`,time:`time`}[e.format.kind]:`text`;return(0,W.jsx)(`input`,{type:l,inputMode:e.type===`number`||e.type===`duration`?`decimal`:void 0,value:o,disabled:n,onChange:t=>{s(t.target.value),e.type===`date`&&c(t.target.value)},onBlur:()=>e.type!==`date`&&c(),onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&s(a)},"aria-label":e.name,className:d(X,(e.type===`number`||e.type===`duration`)&&`text-right tabular-nums`,r&&`ring-1 ring-rose`)})}function Xe(e){return e.type===`number`&&e.format.style===`currency`?e.format.currency??null:e.type===`number`&&e.format.style===`percent`?`%`:e.type===`duration`?C(`data.unit.${e.format.inputUnit}`):null}function Ze(e){return{name:e?.name??``,type:e?.type??`text`,required:e?.required??!1,textStyle:e?.type===`text`&&(e.format?.style??`single`)!==`single`?`multiline`:`single`,numberStyle:e?.type===`number`?e.format.style:`decimal`,currency:e?.type===`number`?e.format.currency??`EUR`:`EUR`,dateKind:e?.type===`date`?e.format.kind:`date`,unit:e?.type===`duration`&&[`minutes`,`hours`,`days`].includes(e.format.inputUnit)?e.format.inputUnit:`minutes`,options:e?.type===`select`?e.format.options.map(e=>e.label).join(`
|
|
3
|
+
`):``,multiple:e?.type===`select`&&!!e.format.multiple}}function Qe(e,t,n){let r={id:t,name:e.name.trim(),...e.required?{required:!0}:{}};switch(e.type){case`number`:return{...r,type:`number`,format:e.numberStyle===`currency`?{style:`currency`,currency:e.currency.trim().toUpperCase()}:{style:e.numberStyle}};case`date`:return{...r,type:`date`,format:{kind:e.dateKind}};case`duration`:return{...r,type:`duration`,format:{inputUnit:e.unit,display:`hms`}};case`select`:{let t=n?.type===`select`?n.format.options:[],i=[],a=e.options.split(`
|
|
4
|
+
`).map(e=>e.trim()).filter(Boolean).map(e=>{let n=t.find(t=>t.label===e)?.id??We(e,i);return i.push(n),{id:n,label:e}});return{...r,type:`select`,format:{allowCustom:!1,options:a,...e.multiple?{multiple:!0}:{}}}}case`boolean`:return{...r,type:`boolean`};default:return{...r,type:`text`,...e.textStyle===`multiline`?{format:{style:`multiline`}}:{}}}}function $e({open:e,column:t,columns:n,onClose:r,onSave:i}){let[a,o]=(0,U.useState)(()=>Ze(t)),[s,c]=(0,U.useState)(null),[u,d]=(0,U.useState)(!1);(0,U.useEffect)(()=>{e&&(o(Ze(t)),c(null))},[e,t]);let f=e=>o(t=>({...t,...e})),p=async e=>{d(!0),c(null);try{await i(e),r()}catch(e){c(e.message)}finally{d(!1)}},m=()=>{let e=t?.id??We(a.name,n.map(e=>e.id)),r=Qe(a,e,t);return p(t?n.map(e=>e.id===t.id?r:e):[...n,r])};return(0,W.jsx)(v,{open:e,onClose:r,title:t?t.name:C(`data.newColumn`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.name.trim()&&m()},children:[(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{children:C(`data.columnName`)}),(0,W.jsx)(b,{"data-autofocus":!0,value:a.name,maxLength:128,onChange:e=>f({name:e.target.value})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{children:C(`data.columnType`)}),(0,W.jsx)(P,{value:a.type,onChange:e=>f({type:e}),options:Ke.map(e=>({value:e,label:C(`data.type.${e}`)}))})]})]}),a.type===`text`?(0,W.jsx)(P,{value:a.textStyle,onChange:e=>f({textStyle:e}),options:[{value:`single`,label:C(`data.text.single`)},{value:`multiline`,label:C(`data.text.multiline`)}]}):null,a.type===`number`?(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsx)(P,{value:a.numberStyle,onChange:e=>f({numberStyle:e}),options:[`integer`,`decimal`,`percent`,`currency`].map(e=>({value:e,label:C(`data.number.${e}`)}))}),a.numberStyle===`currency`?(0,W.jsx)(b,{value:a.currency,maxLength:3,"aria-label":C(`data.currency`),placeholder:`EUR`,onChange:e=>f({currency:e.target.value})}):null]}):null,a.type===`date`?(0,W.jsx)(P,{value:a.dateKind,onChange:e=>f({dateKind:e}),options:[`date`,`datetime`,`time`].map(e=>({value:e,label:C(`data.date.${e}`)}))}):null,a.type===`duration`?(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{children:C(`data.unit`)}),(0,W.jsx)(P,{value:a.unit,onChange:e=>f({unit:e}),options:[`minutes`,`hours`,`days`].map(e=>({value:e,label:C(`data.unit.${e}`)}))})]}):null,a.type===`select`?(0,W.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(y,{children:C(`data.options`)}),(0,W.jsx)(N,{minRows:3,value:a.options,onChange:e=>f({options:e.target.value})})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,W.jsx)(l,{checked:a.multiple,onChange:e=>f({multiple:e})}),C(`data.multiple`)]})]}):null,(0,W.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,W.jsx)(l,{checked:a.required,onChange:e=>f({required:e})}),C(`data.required`)]}),s?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&n.length>1?(0,W.jsx)(T,{variant:`ghost`,className:`text-rose`,disabled:u,onClick:()=>confirm(C(`data.confirmDelete`,{title:t.name}))&&void p(n.filter(e=>e.id!==t.id)),children:C(`data.deleteColumn`)}):null,(0,W.jsx)(`span`,{className:`flex-1`}),(0,W.jsx)(T,{variant:`ghost`,onClick:r,children:C(`common.cancel`)}),(0,W.jsx)(T,{type:`submit`,busy:u,disabled:!a.name.trim(),children:C(`settings.save`)})]})]})})}function et({tableId:e,onGone:t}){let n=r(),o=[`space-table`,e],c=i({queryKey:o,queryFn:()=>w.get(`/api/studio/tables/${e}`)}),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)(null),[p,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(``);(0,U.useEffect)(()=>g(c.data?.title??``),[c.data?.title]);let _=async()=>{await n.invalidateQueries({queryKey:[`space-data`,c.data?.projectId]}),await n.invalidateQueries({queryKey:[`knowledge`,c.data?.projectId]})},v=e=>n.setQueryData(o,t=>t&&{...t,rows:e(t.rows)}),y=e=>{f(e.message),c.refetch()},b=async t=>{await w.patch(`/api/studio/tables/${e}`,t),await c.refetch(),await _()},x=L({mutationFn:({row:t,column:n,value:r})=>w.patch(`/api/studio/tables/${e}/rows/${t}`,{cells:{[n]:r}}),onSuccess:(e,{row:t,column:n})=>{f(null),m(e=>e===`${t}:${n}`?null:e),v(t=>t.map(t=>t.id===e.id?{...t,cells:e.cells}:t))},onError:(e,{row:t,column:n})=>{if(e instanceof A&&e.body?.column===n){let e=c.data?.columns.find(e=>e.id===n)?.name??n;m(`${t}:${n}`),f(C(`data.badCell`,{column:e}));return}y(e)}}),S=L({mutationFn:()=>w.post(`/api/studio/tables/${e}/rows`,{}),onSuccess:async e=>{v(t=>[...t,{...e,updatedAt:new Date().toISOString()}]),await _()},onError:y}),D=L({mutationFn:t=>w.post(`/api/studio/tables/${e}/rows/delete`,{ids:[t]}),onSuccess:async(e,t)=>{v(e=>e.filter(e=>e.id!==t)),await _()},onError:y}),O=L({mutationFn:()=>w.del(`/api/studio/tables/${e}`),onSuccess:async()=>{await _(),t()}});if(!c.data)return c.isError?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c.error.message}):null;let{columns:k,rows:M,readOnly:N}=c.data,P=!!c.data.list;return(0,W.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,W.jsx)(`input`,{value:h,disabled:N,maxLength:120,onChange:e=>g(e.target.value),onBlur:()=>h.trim()&&h!==c.data?.title&&void b({title:h}).catch(y),onKeyDown:e=>e.key===`Enter`&&e.target.blur(),"aria-label":C(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),N?null:(0,W.jsx)(E,{label:C(`data.deleteTable`),onClick:()=>confirm(C(`data.confirmDelete`,{title:c.data.title}))&&O.mutate(),className:`hover:text-rose`,children:(0,W.jsx)(s,{className:`size-4`})})]}),P?(0,W.jsx)(`p`,{className:`-mt-1.5 px-1 text-[0.8125rem] text-ink-3`,children:C(`data.fromList`)}):null,c.data.knowledge?(0,W.jsx)(Y,{projectId:c.data.projectId,itemKey:`t:${c.data.id}`,has:c.data.knowledge.categories,originLabel:c.data.knowledge.originLabel,kept:c.data.knowledge.kept,review:c.data.knowledge.review,file:c.data.knowledge.file,readOnly:N,onReviewed:()=>void w.patch(`/api/studio/tables/${e}`,{review:null}).then(()=>c.refetch()).catch(y)}):null,(0,W.jsxs)(j,{className:`overflow-hidden`,children:[(0,W.jsx)(`div`,{className:`overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full border-collapse text-left`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{className:`border-border-soft border-b`,children:[k.map(e=>(0,W.jsx)(`th`,{className:`min-w-36 border-border-soft border-l p-1 font-medium first:border-l-0`,children:(0,W.jsxs)(`button`,{type:`button`,disabled:N||P,onClick:()=>u(e),className:`flex w-full items-center gap-1 rounded-md px-2 py-1.5 text-left text-[0.8125rem] text-ink-2 transition hover:bg-accent hover:text-ink disabled:hover:bg-transparent`,children:[(0,W.jsx)(`span`,{className:`truncate`,children:e.name}),e.required?(0,W.jsx)(`span`,{className:`text-ember`,children:`*`}):null,Xe(e)?(0,W.jsx)(`span`,{className:`font-normal text-ink-4`,children:Xe(e)}):null]})},e.id)),(0,W.jsx)(`th`,{className:`w-10 p-1`,children:N||P?null:(0,W.jsx)(E,{label:C(`data.newColumn`),onClick:()=>u(`new`),className:`size-8`,children:(0,W.jsx)(a,{className:`size-4`})})})]})}),(0,W.jsx)(`tbody`,{children:M.map(e=>(0,W.jsxs)(`tr`,{className:`group border-border-soft border-b last:border-b-0`,children:[k.map(t=>(0,W.jsx)(`td`,{className:`border-border-soft border-l p-1 align-top first:border-l-0`,children:(0,W.jsx)(Ye,{column:t,value:e.cells[t.id],readOnly:N,invalid:p===`${e.id}:${t.id}`,onSave:n=>x.mutate({row:e.id,column:t.id,value:n})})},t.id)),(0,W.jsx)(`td`,{className:`w-10 p-1 align-top`,children:N?null:(0,W.jsx)(E,{label:C(`data.deleteRow`),onClick:()=>D.mutate(e.id),className:`size-8 opacity-0 hover:text-rose focus:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:(0,W.jsx)(s,{className:`size-3.5`})})})]},e.id))})]})}),M.length?null:(0,W.jsx)(`p`,{className:`px-4 py-6 text-center text-[0.875rem] text-ink-3`,children:C(`data.noRows`)}),N?null:(0,W.jsx)(`div`,{className:`border-border-soft border-t p-1.5`,children:(0,W.jsxs)(T,{variant:`ghost`,size:`sm`,busy:S.isPending,onClick:()=>S.mutate(),children:[(0,W.jsx)(a,{className:`size-4`}),` `,C(`data.addRow`)]})})]}),d?(0,W.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:d}):null,(0,W.jsx)($e,{open:l!==null,column:l===`new`?null:l,columns:k,onClose:()=>u(null),onSave:e=>b({columns:e})})]})}var tt=`wizards.runDrawer.width`,nt=`wizards.runDrawer.wide`,rt=`wizards.runDrawer.look`,it=680,Z=400,at=()=>Math.max(Z,window.innerWidth-120);function Q(e){try{return localStorage.getItem(e)}catch{return null}}function $(e,t){try{localStorage.setItem(e,t)}catch{}}function ot(){let[e,t]=(0,U.useState)(()=>{let e=Number(Q(tt));return e?Math.min(Math.max(e,Z),at()):it}),[n,r]=(0,U.useState)(()=>Q(nt)===`1`),i=(0,U.useCallback)(e=>{let n=Math.round(Math.min(Math.max(e,Z),at()));t(n),$(tt,String(n))},[]);return{width:e,wide:n,toggleWide:()=>{r(!n),$(nt,n?`0`:`1`)},onPointerDown:t=>{t.preventDefault();let n=t.clientX,r=e,a=e=>i(r+n-e.clientX),o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`)};document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o)},onKeyDown:t=>{let n=t.shiftKey?64:16;t.key===`ArrowLeft`?(t.preventDefault(),i(e+n)):t.key===`ArrowRight`&&(t.preventDefault(),i(e-n))},reset:()=>i(it)}}function st(){let[e,t]=(0,U.useState)(()=>Q(rt)===`chat`?`chat`:`steps`);return[e,e=>{t(e),$(rt,e)}]}function ct({look:e,onChange:t}){let n=[{id:`steps`,label:C(`chat.steps`),Icon:fe},{id:`chat`,label:C(`chat.chat`),Icon:H}];return(0,W.jsx)(`fieldset`,{"aria-label":C(`chat.view`),className:`m-0 flex min-w-0 rounded-full border-0 bg-paper-2 p-0.5`,children:n.map(({id:n,label:r,Icon:i})=>(0,W.jsxs)(`button`,{type:`button`,"aria-pressed":e===n,title:r,onClick:()=>t(n),className:d(`inline-flex h-7 items-center gap-1.5 rounded-full px-2.5 font-medium text-[0.75rem] transition coarse:h-9`,e===n?`bg-card text-ink shadow-soft`:`text-ink-3 hover:text-ink`),children:[(0,W.jsx)(i,{className:`size-3.5`}),(0,W.jsx)(`span`,{className:`max-sm:hidden`,children:r})]},n))})}function lt({header:e,actions:t,onClose:n,children:r}){let i=ot();return(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 flex justify-end bg-[oklch(20%_0.01_60/0.22)] backdrop-blur-[1px]`,onClick:n,children:(0,W.jsxs)(`div`,{className:d(`relative flex h-full w-full animate-rise flex-col bg-background shadow-overlay`,!i.wide&&`sm:w-[var(--drawer)]`),style:{"--drawer":`${i.width}px`},onClick:e=>e.stopPropagation(),children:[i.wide?null:(0,W.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":C(`editor.resize`),"aria-valuenow":i.width,tabIndex:0,title:C(`editor.resize`),onPointerDown:i.onPointerDown,onKeyDown:i.onKeyDown,onDoubleClick:i.reset,className:`group -left-2.5 absolute inset-y-0 z-10 hidden w-5 cursor-col-resize outline-none sm:block`,children:(0,W.jsx)(`span`,{className:`-translate-y-1/2 absolute top-1/2 left-[7px] h-12 w-1.5 rounded-full bg-ink-4/40 transition group-hover:bg-ember/70 group-focus-visible:bg-ember group-active:h-16 group-active:bg-ember`})}),(0,W.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4`,children:[(0,W.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:e}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t,(0,W.jsx)(E,{label:C(i.wide?`runDrawer.shrink`:`runDrawer.expand`),onClick:i.toggleWide,className:`max-sm:hidden`,children:i.wide?(0,W.jsx)(se,{className:`size-4`}):(0,W.jsx)(k,{className:`size-4`})}),(0,W.jsx)(E,{label:C(`editor.close`),onClick:n,children:(0,W.jsx)(S,{className:`size-5`})})]})]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:r})]})})}export{Ee as _,Ve as a,z as b,ze as c,J as d,Y as f,we as g,G as h,et as i,Re as l,De as m,lt as n,Ue as o,Ie as p,st as r,Be as s,ct as t,Ae as u,Te as v,ce as x,ge as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{l as r,st as i,v as a,y as o}from"./ui-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{l as r,st as i,v as a,y as o}from"./ui-BOCXzzHi.js";import{i as s,r as c}from"./index-Df6UxElH.js";var l=e(t(),1),u=e(n(),1),d=[`classifier`,`standard`],f=12e3;function p(e){s(`think`)&&r.post(`/api/runs/${e}/device`,{think:{classes:d,maxChars:f}}).catch(()=>void 0)}async function m(e,t){if(t.kind!==`think`)return;let n;try{let e=await c(`think`,{system:t.system,prompt:t.prompt,schema:t.schema});n={text:String(e?.text??``)}}catch(e){n={error:e.message.slice(0,500)}}await r.post(`/api/runs/${e}/device/${t.id}`,n).catch(()=>void 0)}var h=45e3;function g(e){let[t,n]=(0,l.useState)(null),[o,s]=(0,l.useState)(null),[c,u]=(0,l.useState)(!1),[d,f]=(0,l.useState)(!1),[g,_]=(0,l.useState)({});(0,l.useEffect)(()=>{if(n(null),u(!1),!e)return;let t=!1,o=0,s,c=null,l=Date.now(),d=()=>{t=!0,c?.close(),u(!0)},f=async()=>{try{let i=await r.get(`/api/runs/${e}`);t||n(i)}catch(e){e instanceof i&&e.status===404&&d()}},g=()=>{if(clearTimeout(s),c?.close(),t)return;let r=new EventSource(a(`/api/runs/${e}/stream`),{withCredentials:!0});c=r,l=Date.now(),p(e),r.addEventListener(`device`,t=>{l=Date.now(),m(e,JSON.parse(t.data))}),r.addEventListener(`view`,e=>{o=0,l=Date.now(),n(JSON.parse(e.data))}),r.addEventListener(`ping`,()=>{l=Date.now()}),r.onerror=()=>{r.close(),!(t||c!==r)&&(c=null,f(),o=Math.min(o+1,6),s=setTimeout(g,500*2**o))}},_=()=>{t||document.visibilityState!==`visible`||(!c||c.readyState===EventSource.CLOSED||Date.now()-l>h?(o=0,g()):f())},v=setInterval(()=>{!t&&c&&Date.now()-l>h&&(o=0,g())},15e3);return g(),document.addEventListener(`visibilitychange`,_),window.addEventListener(`pageshow`,_),window.addEventListener(`online`,_),()=>{t=!0,clearTimeout(s),clearInterval(v),document.removeEventListener(`visibilitychange`,_),window.removeEventListener(`pageshow`,_),window.removeEventListener(`online`,_),c?.close()}},[e]);let v=(0,l.useCallback)(async(t,n)=>{if(!e)return!1;f(!0),s(null),_({});try{return await r.post(`/api/runs/${e}/${t}`,n),!0}catch(e){return e instanceof i&&e.status===422&&Array.isArray(e.body?.fields)&&_(Object.fromEntries(e.body.fields.map(e=>[e.field,e.message]))),s(e.message),!1}finally{f(!1)}},[e]);return{view:t,notFound:c,error:o,busy:d,fieldErrors:g,submitPage:(e,t)=>v(`pages/${e}`,{values:t}),accept:(e,t)=>v(`reviews/${e}`,{type:`accept`,edits:t}),regenerate:(e,t,n,r)=>v(`reviews/${e}`,{type:`regenerate`,target:t,note:n,items:r?.length?r:void 0}),back:()=>v(`back`),retry:()=>v(`retry`)}}function _({runId:e,...t}){let n=g(e);return(0,u.jsx)(o,{run:n,...t})}export{g as n,_ as t};
|