rivet-design 0.18.4 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/mcpServe.d.ts.map +1 -1
- package/dist/cli/commands/mcpServe.js +27 -2
- package/dist/cli/commands/mcpServe.js.map +1 -1
- package/dist/cli/commands/profile.d.ts.map +1 -1
- package/dist/cli/commands/profile.js +15 -1
- package/dist/cli/commands/profile.js.map +1 -1
- package/dist/cli/router.d.ts.map +1 -1
- package/dist/cli/router.js +2 -1
- package/dist/cli/router.js.map +1 -1
- package/dist/routes/library/profiles.d.ts.map +1 -1
- package/dist/routes/library/profiles.js +46 -0
- package/dist/routes/library/profiles.js.map +1 -1
- package/dist/routes/referenceProfiles.d.ts +2 -0
- package/dist/routes/referenceProfiles.d.ts.map +1 -0
- package/dist/routes/referenceProfiles.js +79 -0
- package/dist/routes/referenceProfiles.js.map +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -1
- package/dist/services/TelemetryService.d.ts +1 -1
- package/dist/services/TelemetryService.d.ts.map +1 -1
- package/dist/services/TelemetryService.js.map +1 -1
- package/dist/services/profiles/DesignProfiles.d.ts +18 -0
- package/dist/services/profiles/DesignProfiles.d.ts.map +1 -1
- package/dist/services/profiles/DesignProfiles.js +129 -0
- package/dist/services/profiles/DesignProfiles.js.map +1 -1
- package/dist/services/profiles/ProfileMedia.d.ts +1 -0
- package/dist/services/profiles/ProfileMedia.d.ts.map +1 -1
- package/dist/services/profiles/ProfileMedia.js +5 -1
- package/dist/services/profiles/ProfileMedia.js.map +1 -1
- package/dist/storage/profiles/ProfileRecords.d.ts +2 -0
- package/dist/storage/profiles/ProfileRecords.d.ts.map +1 -1
- package/dist/storage/profiles/ProfileRecords.js +34 -0
- package/dist/storage/profiles/ProfileRecords.js.map +1 -1
- package/dist/types/design-library.d.ts +50 -0
- package/dist/types/design-library.d.ts.map +1 -0
- package/dist/types/design-library.js +32 -0
- package/dist/types/design-library.js.map +1 -0
- package/dist/types/reference-onboarding.d.ts +2 -2
- package/dist/utils/skills/cli-guidance.d.ts +1 -1
- package/dist/utils/skills/cli-guidance.d.ts.map +1 -1
- package/dist/utils/skills/cli-guidance.js +3 -1
- package/dist/utils/skills/cli-guidance.js.map +1 -1
- package/package.json +1 -1
- package/src/ui/dist/assets/LibraryApp-B4ztVk52.js +36 -0
- package/src/ui/dist/assets/main-CAPEQf84.js +438 -0
- package/src/ui/dist/assets/main-Ky91HHF_.css +1 -0
- package/src/ui/dist/index.html +2 -2
- package/src/ui/dist/assets/LibraryApp-Cxdyy4oV.js +0 -21
- package/src/ui/dist/assets/main-B-LY2LQB.css +0 -1
- package/src/ui/dist/assets/main-CPHvvBUN.js +0 -438
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var $e=s=>{throw TypeError(s)};var ke=(s,t,r)=>t.has(s)||$e("Cannot "+r);var d=(s,t,r)=>(ke(s,t,"read from private field"),r?r.call(s):t.get(s)),T=(s,t,r)=>t.has(s)?$e("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,r),P=(s,t,r,i)=>(ke(s,t,"write to private field"),i?i.call(s,r):t.set(s,r),r),L=(s,t,r)=>(ke(s,t,"access private method"),r);import{S as Je,s as Xe,h as qe,g as St,n as de,r as Rt,Q as Ze,u as ge,a as It,b as Et,c as h,e as Pt,d as Ot,f as Mt,i as et,j as Fe,k as At,l as Lt,m as Tt,o as re,p as oe,q as Dt,t as e,B as U,v as Ne,R as zt,T as $t,P as qt,C as Ft,w as Kt,X as tt,D as st,x as rt,y as it,z as nt,A as at,E as ot,F as lt,G as Ht,H as Ut,I as Qt,J as Bt,K as ie,L as ve,M as Vt,N as ct,O as dt,U as Wt,V as Gt,W as Yt,Y as Jt,Z as Xt,_ as Zt,$ as F,a0 as es,a1 as Ke,a2 as ts,a3 as ss,a4 as rs,a5 as is,a6 as ns}from"./main-CAPEQf84.js";var G,X,z,Y,W,le,_e,Ge,as=(Ge=class extends Je{constructor(t,r){super();T(this,W);T(this,G);T(this,X);T(this,z);T(this,Y);P(this,G,t),this.setOptions(r),this.bindMethods(),L(this,W,le).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var i;const r=this.options;this.options=d(this,G).defaultMutationOptions(t),Xe(this.options,r)||d(this,G).getMutationCache().notify({type:"observerOptionsUpdated",mutation:d(this,z),observer:this}),r!=null&&r.mutationKey&&this.options.mutationKey&&qe(r.mutationKey)!==qe(this.options.mutationKey)?this.reset():((i=d(this,z))==null?void 0:i.state.status)==="pending"&&d(this,z).setOptions(this.options)}onSubscribe(){this.listeners.size===1&&d(this,z)&&(d(this,z).addObserver(this),L(this,W,le).call(this))}onUnsubscribe(){var t;this.hasListeners()||(t=d(this,z))==null||t.removeObserver(this)}onMutationUpdate(t){L(this,W,le).call(this),L(this,W,_e).call(this,t)}getCurrentResult(){return d(this,X)}reset(){var t;(t=d(this,z))==null||t.removeObserver(this),P(this,z,void 0),L(this,W,le).call(this),L(this,W,_e).call(this)}mutate(t,r){var i;return P(this,Y,r),(i=d(this,z))==null||i.removeObserver(this),P(this,z,d(this,G).getMutationCache().build(d(this,G),this.options)),d(this,z).addObserver(this),d(this,z).execute(t)}},G=new WeakMap,X=new WeakMap,z=new WeakMap,Y=new WeakMap,W=new WeakSet,le=function(){var r;const t=((r=d(this,z))==null?void 0:r.state)??St();P(this,X,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},_e=function(t){de.batch(()=>{var r,i,a,o,n,c,p,w;if(d(this,Y)&&this.hasListeners()){const x=d(this,X).variables,u=d(this,X).context,f={client:d(this,G),meta:this.options.meta,mutationKey:this.options.mutationKey};if((t==null?void 0:t.type)==="success"){try{(i=(r=d(this,Y)).onSuccess)==null||i.call(r,t.data,x,u,f)}catch(b){Promise.reject(b)}try{(o=(a=d(this,Y)).onSettled)==null||o.call(a,t.data,null,x,u,f)}catch(b){Promise.reject(b)}}else if((t==null?void 0:t.type)==="error"){try{(c=(n=d(this,Y)).onError)==null||c.call(n,t.error,x,u,f)}catch(b){Promise.reject(b)}try{(w=(p=d(this,Y)).onSettled)==null||w.call(p,void 0,t.error,x,u,f)}catch(b){Promise.reject(b)}}}this.listeners.forEach(x=>{x(d(this,X))})})},Ge);function He(s,t){const r=new Set(t);return s.filter(i=>!r.has(i))}var ne,q,ae,te,H,se,ue,he,me,pe,M,Ce,Se,ut,Re,Ie,Ee,Ye,os=(Ye=class extends Je{constructor(t,r,i){super();T(this,M);T(this,ne);T(this,q);T(this,ae);T(this,te);T(this,H);T(this,se);T(this,ue);T(this,he);T(this,me);T(this,pe,[]);P(this,ne,t),P(this,te,i),P(this,ae,[]),P(this,H,[]),P(this,q,[]),this.setQueries(r)}onSubscribe(){this.listeners.size===1&&d(this,H).forEach(t=>{t.subscribe(r=>{L(this,M,Ie).call(this,t,r)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,d(this,H).forEach(t=>{t.destroy()})}setQueries(t,r){P(this,ae,t),P(this,te,r),de.batch(()=>{const i=d(this,H),a=L(this,M,Re).call(this,d(this,ae));a.forEach(u=>u.observer.setOptions(u.defaultedQueryOptions));const o=a.map(u=>u.observer),n=o.map(u=>u.getCurrentResult()),c=i.length!==o.length,p=o.some((u,f)=>u!==i[f]),w=c||p,x=w?!0:n.some((u,f)=>{const b=d(this,q)[f];return!b||!Xe(u,b)});!w&&!x||(w&&(P(this,pe,a),P(this,H,o)),P(this,q,n),this.hasListeners()&&(w&&(He(i,o).forEach(u=>{u.destroy()}),He(o,i).forEach(u=>{u.subscribe(f=>{L(this,M,Ie).call(this,u,f)})})),L(this,M,Ee).call(this)))})}getCurrentResult(){return d(this,q)}getQueries(){return d(this,H).map(t=>t.getCurrentQuery())}getObservers(){return d(this,H)}getOptimisticResult(t,r){const i=L(this,M,Re).call(this,t),a=i.map(n=>n.observer.getOptimisticResult(n.defaultedQueryOptions)),o=i.map(n=>n.defaultedQueryOptions.queryHash);return[a,n=>L(this,M,Se).call(this,n??a,r,o),()=>L(this,M,Ce).call(this,a,i)]}},ne=new WeakMap,q=new WeakMap,ae=new WeakMap,te=new WeakMap,H=new WeakMap,se=new WeakMap,ue=new WeakMap,he=new WeakMap,me=new WeakMap,pe=new WeakMap,M=new WeakSet,Ce=function(t,r){const i=new Set;return r.map((a,o)=>{const n=t[o];return a.defaultedQueryOptions.notifyOnChangeProps?n:a.observer.trackResult(n,c=>{i.has(c)||(i.add(c),r.forEach(p=>{p.observer.trackProp(c)}))})})},Se=function(t,r,i){if(r){const a=d(this,me),o=i!==void 0&&a!==void 0&&(a.length!==i.length||i.some((n,c)=>n!==a[c]));return(d(this,q)!==d(this,he)||o||r!==d(this,ue))&&(P(this,ue,r),P(this,he,d(this,q)),i!==void 0&&P(this,me,i),P(this,se,Rt(d(this,se),r(t)))),d(this,se)}return t},ut=function(){var t;return!((t=d(this,te))!=null&&t.combine)||d(this,H).some((r,i)=>{var a;return r.options.suspense&&((a=d(this,q)[i])==null?void 0:a.data)===void 0})},Re=function(t){const r=new Map;d(this,H).forEach(a=>{const o=a.options.queryHash;if(!o)return;const n=r.get(o);n?n.push(a):r.set(o,[a])});const i=[];return t.forEach(a=>{var c;const o=d(this,ne).defaultQueryOptions(a),n=((c=r.get(o.queryHash))==null?void 0:c.shift())??new Ze(d(this,ne),o);i.push({defaultedQueryOptions:o,observer:n})}),i},Ie=function(t,r){const i=d(this,H).indexOf(t);i!==-1&&(P(this,q,d(this,q).slice()),d(this,q)[i]=r,L(this,M,Ee).call(this))},Ee=function(){var t;if(this.hasListeners()){const r=L(this,M,ut).call(this),i=d(this,se),a=r?i:L(this,M,Se).call(this,L(this,M,Ce).call(this,d(this,q),d(this,pe)),(t=d(this,te))==null?void 0:t.combine);(r||i!==a)&&de.batch(()=>{this.listeners.forEach(o=>{o(d(this,q))})})}},Ye);function ls({queries:s,...t},r){const i=ge(),a=It(),o=Et(),n=t.subscribed!==!1,c=h.useMemo(()=>s.map(_=>{const j=i.defaultQueryOptions(_);return j._optimisticResults=a?"isRestoring":n?"optimistic":void 0,j}),[s,i,a,n]);c.forEach(_=>{Pt(_);const j=i.getQueryCache().get(_.queryHash);Ot(_,o,j)}),Mt(o);const[p]=h.useState(()=>new os(i,c,t)),[w,x,u]=p.getOptimisticResult(c,t.combine),f=!a&&n;h.useSyncExternalStore(h.useCallback(_=>f?p.subscribe(de.batchCalls(_)):et,[p,f]),()=>p.getCurrentResult(),()=>p.getCurrentResult()),h.useEffect(()=>{p.setQueries(c,t)},[c,t,p]);const b=w.some((_,j)=>Fe(c[j],_))?w.flatMap((_,j)=>{const k=c[j];if(k&&Fe(k,_)){const K=new Ze(i,k);return At(k,K,o)}return[]}):[];if(b.length>0)throw Promise.all(b);const N=w.find((_,j)=>{const k=c[j];return k&&Lt({result:_,errorResetBoundary:o,throwOnError:k.throwOnError,query:i.getQueryCache().get(k.queryHash),suspense:k.suspense})});if(N)throw N.error;return x(u())}function ce(s,t){const r=ge(),[i]=h.useState(()=>new as(r,s));h.useEffect(()=>{i.setOptions(s)},[i,s]);const a=h.useSyncExternalStore(h.useCallback(n=>i.subscribe(de.batchCalls(n)),[i]),()=>i.getCurrentResult(),()=>i.getCurrentResult()),o=h.useCallback((...n)=>{i.mutate(n[0],n[1]).catch(et)},[i]);if(a.error&&Tt(i.options.throwOnError,[a.error]))throw a.error;return{...a,mutate:o,mutateAsync:a.mutate}}/**
|
|
2
|
+
* @license lucide-react v1.48.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const ht={name:"arrow-up-right",size:24,node:[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]]};ht.node;const mt=re(ht);/**
|
|
7
|
+
* @license lucide-react v1.48.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const pt={name:"clipboard-copy",size:24,node:[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]};pt.node;const cs=re(pt);/**
|
|
12
|
+
* @license lucide-react v1.48.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const xt={name:"ellipsis",size:24,node:[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],aliases:["more-horizontal"]};xt.node;const ds=re(xt);/**
|
|
17
|
+
* @license lucide-react v1.48.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const ft={name:"folder-open",size:24,node:[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]};ft.node;const Ue=re(ft);/**
|
|
22
|
+
* @license lucide-react v1.48.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const bt={name:"image-off",size:24,node:[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M10.41 10.41a2 2 0 1 1-2.83-2.83",key:"1bzlo9"}],["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21",key:"1q0aeu"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15",key:"5mozeu"}],["path",{d:"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59",key:"mmje98"}],["path",{d:"M21 15V5a2 2 0 0 0-2-2H9",key:"43el77"}]]};bt.node;const us=re(bt);/**
|
|
27
|
+
* @license lucide-react v1.48.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const yt={name:"images",size:24,node:[["path",{d:"m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16",key:"9kzy35"}],["path",{d:"M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2",key:"1t0f0t"}],["circle",{cx:"13",cy:"7",r:"1",fill:"currentColor",key:"1obus6"}],["rect",{x:"8",y:"2",width:"14",height:"14",rx:"2",key:"1gvhby"}]]};yt.node;const hs=re(yt);/**
|
|
32
|
+
* @license lucide-react v1.48.0 - ISC
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the ISC license.
|
|
35
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
+
*/const vt={name:"loader-circle",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],aliases:["loader-2"]};vt.node;const ms=re(vt),ps=200,xs=({project:s,onRename:t,onRemove:r,onSetPinned:i})=>{const a=oe(),o=h.useRef(null),n=h.useRef(null),c=h.useRef(null),[p,w]=h.useState(!1),[x,u]=h.useState(!1),f=!!s.pinnedAt,[b,N]=h.useState(null),[_,j]=h.useState(s.name),[k,K]=h.useState(!1),[g,R]=h.useState(null),{containerRef:A,onKeyDown:m}=Dt();let S=b==="rename"?"Save name":"Remove from projects";k&&(S="Saving…"),h.useEffect(()=>{var $;if(x||!c.current)return;const y=c.current==="button"?n:o;c.current=null,($=y.current)==null||$.focus()},[x]);const O=y=>{w(y),a==null||a.capture(y?"library_project_menu_opened":"library_project_menu_closed")},I=async y=>{if(!x){c.current=y,u(!0),a==null||a.capture("library_project_pin_clicked",{is_pinning:!f,method:y});try{await i(s.id,!f)}catch($){lt.error($ instanceof Error?$.message:"Could not save pin. Try again.")}finally{u(!1)}}},Q=y=>{O(!1),j(s.name),R(null),N(y),a==null||a.capture("library_project_action_opened",{action:y})},B=y=>{a==null||a.capture("library_project_action_closed",{action:b,outcome:y}),N(null)},C=async()=>{if(!(k||!b||b==="rename"&&!_.trim())){K(!0),R(null);try{b==="rename"?await t(s.id,_.trim()):await r(s.id),B("completed")}catch(y){R(y instanceof Error?y.message:"Could not save changes. Try again.")}finally{K(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center gap-0.5 group-hover/project:pointer-events-auto group-hover/project:opacity-100 has-[:focus-visible]:pointer-events-auto has-[:focus-visible]:opacity-100 [@media(hover:none)]:pointer-events-auto [@media(hover:none)]:opacity-100 ${p?"pointer-events-auto opacity-100":"pointer-events-none opacity-0"}`,children:[e.jsx(U,{ref:n,type:"button",variant:"ghost",size:"icon-compact",title:f?"Unpin project":"Pin project","aria-label":`${f?"Unpin":"Pin"} ${s.name}`,"aria-pressed":f,disabled:x,onClick:()=>{I("button")},children:e.jsx(Ne,{weight:f?"fill":"bold",size:16,"aria-hidden":!0})}),e.jsxs(zt,{open:p,onOpenChange:O,children:[e.jsx($t,{asChild:!0,children:e.jsx(U,{ref:o,type:"button",variant:"ghost",size:"icon-compact","aria-label":`Actions for ${s.name}`,children:e.jsx(ds,{size:16,"aria-hidden":!0})})}),e.jsx(qt,{children:e.jsxs(Ft,{"data-rivet-private":!0,ref:A,onKeyDown:m,role:"menu","aria-label":"Project actions",align:"start",sideOffset:4,onCloseAutoFocus:y=>{b&&y.preventDefault()},className:"ph-no-capture bg-surface-2 text-content z-ui-primary min-w-44 rounded-lg p-1 shadow-lg",children:[e.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,disabled:x,onClick:()=>{O(!1),I("menu")},className:"hover:bg-hover focus:bg-hover flex w-full items-center gap-2 rounded-md px-3 py-2 text-xs focus:outline-none disabled:opacity-50",children:[e.jsx(Ne,{size:14,weight:f?"fill":"bold","aria-hidden":!0}),f?"Unpin":"Pin"]}),e.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>Q("rename"),className:"hover:bg-hover focus:bg-hover flex w-full items-center gap-2 rounded-md px-3 py-2 text-xs focus:outline-none",children:[e.jsx(Kt,{size:14,"aria-hidden":!0}),"Rename"]}),e.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>Q("remove"),className:"hover:bg-hover focus:bg-hover flex w-full items-center gap-2 rounded-md px-3 py-2 text-xs focus:outline-none",children:[e.jsx(tt,{size:14,"aria-hidden":!0}),"Remove from projects"]})]})})]})]}),e.jsx(st,{open:b!==null,onOpenChange:y=>{!y&&!k&&B("cancelled")},children:e.jsxs(rt,{children:[e.jsx(it,{className:"z-modal fixed inset-0 bg-black/60"}),e.jsxs(nt,{"data-rivet-private":!0,onCloseAutoFocus:y=>{var $;y.preventDefault(),($=o.current)==null||$.focus()},className:"ph-no-capture bg-surface-2 text-content z-ui-secondary fixed top-1/2 left-1/2 w-[calc(100%-2rem)] max-w-sm -translate-x-1/2 -translate-y-1/2 rounded-xl p-6 shadow-lg",children:[e.jsx(at,{className:"text-base font-medium break-words",children:b==="rename"?"Rename project":`Remove “${s.name}” from projects?`}),e.jsx(ot,{className:"mt-2 text-sm leading-6 text-white/60",children:b==="rename"?"Choose a display name for this project. Its folder name will stay the same.":"Your folders and saved variants will remain on this computer. Open the project again to restore it."}),e.jsxs("form",{onSubmit:y=>{y.preventDefault(),C()},children:[b==="rename"?e.jsxs("label",{className:"mt-5 block text-xs text-white/70",children:["Project name",e.jsx("input",{autoFocus:!0,value:_,onChange:y=>j(y.target.value),maxLength:ps,disabled:k,className:"mt-2 w-full rounded-lg border border-white/15 bg-white/5 px-3 py-2 text-sm text-white outline-none focus:border-white/50"})]}):null,g?e.jsx("p",{role:"alert",className:"mt-4 text-xs text-red-300",children:g}):null,e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(U,{type:"button",variant:"ghost",disabled:k,onClick:()=>B("cancelled"),children:"Cancel"}),e.jsx(U,{type:"submit",variant:"secondary",disabled:k||b==="rename"&&!_.trim(),children:S})]})]})]})]})})]})},gt=6e4,wt=60*gt,we=24*wt,fs=7*we,bs=30*we,ys=365*we,vs=[["year",ys],["month",bs],["week",fs],["day",we],["hour",wt],["minute",gt]],gs=new Intl.RelativeTimeFormat("en",{numeric:"always"}),ws=s=>{const t=new Map;for(const r of s??[]){const i=Date.parse(r.createdAt);if(!Number.isFinite(i))continue;const a=t.get(r.projectId);(a===void 0||i>a)&&t.set(r.projectId,i)}return t},js=({projects:s,latestEdits:t})=>[...s].sort((r,i)=>{if(r.pinnedAt&&!i.pinnedAt)return-1;if(i.pinnedAt&&!r.pinnedAt)return 1;if(r.pinnedAt&&i.pinnedAt)return r.pinnedAt.localeCompare(i.pinnedAt)||r.id.localeCompare(i.id);const a=t.get(r.id),o=t.get(i.id);return a===void 0&&o!==void 0?1:o===void 0&&a!==void 0?-1:(o??0)-(a??0)||r.name.localeCompare(i.name)||r.id.localeCompare(i.id)}),ks=({editedAt:s,now:t})=>{const r=Math.max(0,t-s);for(const[i,a]of vs)if(r>=a)return`Edited ${gs.format(-Math.floor(r/a),i)}`;return"Edited just now"},jt=h.createContext(null),Ns=({navigation:s,onBrowseProjects:t,controls:r,isHeaderVisible:i=!0,children:a})=>{const[o,n]=h.useState(null);return e.jsxs(jt.Provider,{value:o,children:[i?e.jsxs("div",{className:"grid shrink-0 grid-cols-[auto_minmax(0,1fr)] items-center gap-4 px-10 py-5 max-sm:px-5 sm:grid-cols-[auto_minmax(0,1fr)_auto]",children:[e.jsx("button",{onClick:t,"aria-label":"Projects",className:"flex items-center",children:e.jsx("img",{src:Ht,alt:"","aria-hidden":!0,draggable:!1,className:"h-8 w-8"})}),e.jsx("div",{ref:n,className:"col-span-2 row-start-2 flex min-w-0 items-center gap-3 sm:col-span-1 sm:col-start-2 sm:row-start-1",children:r}),e.jsx("div",{className:"col-start-2 row-start-1 justify-self-end sm:col-start-3",children:s})]}):null,a]})},kt=({children:s})=>{const t=h.useContext(jt);return t?Ut.createPortal(s,t):null},Pe=({label:s,value:t,onChange:r,onBlur:i,isDisabled:a=!1})=>e.jsxs("label",{className:"flex w-64 min-w-0 items-center gap-2 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2.5 text-white/35 max-sm:flex-1",children:[e.jsx(Qt,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsx("input",{type:"search","aria-label":s,placeholder:`${s}…`,value:t,onChange:o=>r==null?void 0:r(o.target.value),onBlur:i,disabled:a,className:"min-w-0 flex-1 bg-transparent text-xs text-white outline-none placeholder:text-white/30 disabled:opacity-40 [&::-webkit-search-cancel-button]:hidden"})]}),_s=({projects:s,variants:t,historyError:r,onRetryHistory:i,projectPreviews:a={},selectedProjectId:o,onSelectProject:n,onBrowseLibrary:c,onOpenProject:p,onRenameProject:w,onRemoveProject:x,onSetProjectPinned:u,isOpeningProject:f=!1,projectOpenError:b,onSearchCompleted:N,accountMenu:_,navigation:j,view:k="library",children:K})=>{const[g,R]=h.useState(""),A=o===null||K===void 0,m=h.useRef(null),S=ws(t),O=Date.now(),I=s.find(C=>C.id===o),Q=new Map;if(t)for(const C of s)C.historyIssue||Q.set(C.id,0);for(const{projectId:C}of t??[]){const y=Q.get(C);y!==void 0&&Q.set(C,y+1)}const B=js({projects:s.filter(C=>C.name.toLowerCase().includes(g.toLowerCase())),latestEdits:S});return e.jsx("div",{className:"ph-no-capture bg-background text-foreground flex h-screen min-h-0","data-rivet-private":!0,children:e.jsx("main",{className:"relative flex min-w-0 flex-1 flex-col overflow-hidden",children:e.jsxs(Ns,{navigation:j,onBrowseProjects:c,isHeaderVisible:A,controls:k==="library"?e.jsx(Pe,{label:"Search projects",value:g,onChange:R,onBlur:()=>N==null?void 0:N(g.length)}):null,children:[b?e.jsx("p",{role:"alert",className:"px-10 pt-5 text-xs text-red-200",children:b}):null,K!==void 0?K:e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-10 pb-10 max-sm:px-5",children:[e.jsx("h1",{ref:m,tabIndex:-1,className:"sr-only",children:"Projects"}),e.jsx("div",{className:"mb-9 flex items-center justify-end",children:e.jsx(U,{onClick:()=>p(),variant:"secondary",disabled:f,leadingIcon:Ue,className:"shrink-0",children:"Open project…"})}),r?e.jsxs("div",{role:"alert",className:"mb-6 flex items-center gap-3 text-xs text-white/60",children:[e.jsx("span",{children:r}),e.jsx("button",{onClick:i,className:"shrink-0 underline underline-offset-4",children:"Retry history"})]}):null,I!=null&&I.issue?e.jsx("p",{role:"alert",className:"mb-6 rounded-lg border border-amber-200/10 bg-amber-200/[0.03] p-4 text-xs leading-6 text-white/70",children:I.issue}):null,I&&!I.isAvailable?e.jsxs("div",{className:"mb-6 flex items-center justify-between gap-4 rounded-lg border border-amber-200/10 bg-amber-200/[0.03] p-4 text-xs text-white/60",children:[e.jsxs("span",{children:["Locate ",I.name,"’s working folder to open its workspace."]}),e.jsx("button",{disabled:f,onClick:()=>p(I.id),className:"shrink-0 text-white underline decoration-white/30 underline-offset-4",children:"Locate folder"})]}):null,e.jsxs("div",{className:"grid items-start gap-x-6 gap-y-8 sm:grid-cols-2",children:[B.map(C=>{const y=Q.get(C.id);let $="Loading variants…";y!==void 0?$=`${y.toLocaleString()} ${y===1?"variant":"variants"}`:(r||C.historyIssue)&&($="Variants unavailable");const Z=S.get(C.id);let ee="No edits yet";r||C.historyIssue?ee="Edit history unavailable":t===void 0?ee="Loading edits…":y&&(ee="Edit date unavailable");const J=a[C.id];return e.jsxs("div",{className:"group/project grid min-w-0",children:[e.jsxs("button",{onClick:()=>{R(""),n(C.id)},className:"group col-start-1 row-span-2 row-start-1 -m-2 grid w-[calc(100%+1rem)] min-w-0 grid-rows-subgrid rounded-2xl p-2 text-left hover:bg-white/[0.06] focus-visible:bg-white/[0.06] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-white/60",children:[e.jsx("span",{className:"group-hover:border-border relative block aspect-video overflow-hidden rounded-xl border border-white/[0.08] bg-white/[0.02]",children:J?e.jsx("img",{src:J.dataUrl,alt:`${C.name} — ${J.label}`,draggable:!1,className:"h-full w-full object-cover object-top"}):null}),e.jsxs("span",{className:"mt-3 block pr-16",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-sm font-medium",children:[C.pinnedAt?e.jsx(Ne,{size:12,weight:"fill","aria-hidden":!0,className:"text-content-muted shrink-0"}):null,e.jsx("span",{className:"truncate",children:C.name})]}),e.jsxs("span",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-xs text-white/40 group-hover:text-white/65 group-focus-visible:text-white/65",children:[Z!==void 0?e.jsx("time",{dateTime:new Date(Z).toISOString(),title:new Date(Z).toLocaleString(),children:ks({editedAt:Z,now:O})}):e.jsx("span",{children:ee}),e.jsx("span",{className:"shrink-0",children:$})]}),C.isAvailable?null:e.jsx("span",{className:"mt-2 block text-xs text-amber-200/65",children:"Folder unavailable"})]})]}),e.jsx("div",{className:"z-content col-start-1 row-start-2 mt-3 self-center justify-self-end",children:e.jsx(xs,{project:C,onRename:w,onSetPinned:u,onRemove:async xe=>{var fe;await x(xe),(fe=m.current)==null||fe.focus()}})})]},C.id)}),B.length===0?e.jsxs("div",{className:"col-span-full flex min-h-80 flex-col items-center justify-center rounded-xl border border-dashed border-white/10 px-8 text-center",children:[e.jsx(Ue,{size:26,className:"mb-5 text-white/25"}),e.jsx("h2",{className:"text-sm font-medium",children:g?"No matching projects":"Add your projects"}),e.jsx("p",{className:"mt-2 max-w-sm text-xs leading-6 text-white/40",children:g?"Try another project name.":"Open an existing project to add it as a project here"}),g?null:e.jsx(U,{onClick:()=>p(),variant:"secondary",disabled:f,className:"mt-5",children:"Open project"})]}):null]})]}),A&&_?e.jsx("footer",{className:"border-main-border bg-main-light shrink-0 border-t px-2.5 py-2.5",children:_}):null]})})})},Nt=8,Qe=1,Cs=({children:s})=>e.jsx("ul",{className:"grid grid-cols-1 items-start gap-x-5 min-[400px]:grid-cols-2 md:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5",style:{gridAutoRows:`${Nt}px`},children:s}),Ss=({children:s})=>{const[t,r]=h.useState(Qe),i=h.useRef(null),a=h.useCallback(o=>{var c;if((c=i.current)==null||c.disconnect(),!o)return;const n=()=>r(Math.max(Qe,Math.ceil(o.getBoundingClientRect().height/Nt)));n(),i.current=new ResizeObserver(n),i.current.observe(o)},[]);return e.jsx("li",{className:"min-w-0",style:{gridRowEnd:`span ${t}`},children:e.jsx("div",{ref:a,className:"relative pb-8",children:s})})},Rs=async({profileId:s,referenceId:t,hash:r,signal:i})=>{const a=await fetch(`/api/library/profile/references/${encodeURIComponent(t)}/media/${r}?${new URLSearchParams({profileId:s})}`,{headers:{Authorization:Bt()},signal:i});if(!a.ok)throw new Error("Image unavailable");return a.blob()},Is="200px",_t=({profileId:s,referenceId:t,hash:r,title:i,isDetail:a=!1})=>{const[o,n]=h.useState(!1),[c,p]=h.useState(!1),w=h.useRef(null),x=h.useCallback(b=>{var N;(N=w.current)==null||N.disconnect(),b&&(w.current=new IntersectionObserver(_=>{var j;_.some(k=>k.isIntersecting)&&(n(!0),(j=w.current)==null||j.disconnect())},{rootMargin:Is}),w.current.observe(b))},[]),u=ie({queryKey:["design-library-image",s,t,r],queryFn:async({signal:b})=>{const N=await Rs({profileId:s,referenceId:t,hash:r,signal:b});return new Promise((_,j)=>{const k=new FileReader;k.onload=()=>typeof k.result=="string"?_(k.result):j(new Error("Image unavailable")),k.onerror=()=>j(new Error("Image unavailable")),k.readAsDataURL(N)})},enabled:o,staleTime:1/0,gcTime:0,retry:!1}),f=!!u.data&&!c;return e.jsxs("div",{ref:x,className:ve("flex items-center justify-center overflow-hidden bg-white/[0.025]",a?"min-h-32":null,!a&&!f?"aspect-[4/3]":null),children:[u.isError||c?e.jsxs("span",{className:"flex items-center gap-2 p-5 text-xs text-white/35",children:[e.jsx(us,{size:16,"aria-hidden":!0}),"Image unavailable"]}):null,u.data&&!c?e.jsx("img",{src:u.data,alt:i,onError:()=>p(!0),className:a?"max-h-[65vh] w-full object-contain":"block h-auto w-full"}):null,!u.data&&!u.isError?e.jsx("span",{className:"text-xs text-white/25",children:"Loading image…"}):null]})},Es={arena:"Are.na",cosmos:"Cosmos",pinterest:"Pinterest",x:"X",image:"Uploaded image",text:"Saved text",variant:"Saved direction",pdf:"PDF"},Ps=({provider:s})=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s==="arena"||s==="cosmos"||s==="pinterest"||s==="x"?e.jsx(Vt,{provider:s,className:"h-3.5 w-3.5"}):null,Es[s]]}),Os=({label:s,onCopy:t,referenceCount:r=1})=>{const i=oe(),[a,o]=h.useState("idle"),n=async()=>{o("copying");try{await t(),o("copied"),i==null||i.capture("library_reference_copy_completed",{reference_count:r,copy_kind:"agent"})}catch{o("failed"),lt.error("Could not copy. Check clipboard access and try again."),i==null||i.capture("library_reference_copy_failed",{reference_count:r,copy_kind:"agent"})}},c=a==="copied"?ct:cs,p=a==="copied"?"Copied":s;return e.jsxs(e.Fragment,{children:[e.jsx(U,{variant:"secondary",size:"compact",leadingIcon:c,disabled:a==="copying",onClick:()=>void n(),"aria-label":p,"aria-live":"polite",children:e.jsxs("span",{className:"grid whitespace-nowrap",children:[e.jsx("span",{"aria-hidden":!0,className:"invisible col-start-1 row-start-1",children:s}),e.jsx("span",{className:"col-start-1 row-start-1",children:p})]})}),a==="failed"?e.jsx("span",{role:"alert",className:"sr-only",children:"Could not copy. Check clipboard access and try again."}):null]})},Ct=50,Be=12,Ms=dt().regex(/^[a-f0-9]{12,64}@[1-9][0-9]*$/).refine(s=>Number.isSafeInteger(Number(s.split("@")[1])),"Invalid reference revision"),As=Wt({profileId:dt().uuid(),keys:Yt(Ms).min(1).max(Ct),isDetailed:Gt().default(!1)}),Ls=s=>{const t=new Map;for(const r of s){const i=r.id.slice(0,Be);t.set(i,(t.get(i)??0)+1)}return new Map(s.map(r=>{const i=r.id.slice(0,Be),a=t.get(i)===1?i:r.id;return[r.id,`${a}@${r.revision}`]}))},Ts=({profileId:s,referenceKeys:t})=>{const r=As.parse({profileId:s,keys:t});return["rivet","profile","reference",r.profileId,...r.keys].join(" ")},Oe=s=>{const t=s.referenceKeys.length===1?"Copy to agent":`Copy ${s.referenceKeys.length} to agent`;return e.jsx(Os,{label:t,referenceCount:s.referenceKeys.length,onCopy:()=>navigator.clipboard.writeText(Ts(s))})},Ds=({profileId:s,reference:t,sources:r,referenceKey:i,children:a})=>{var p,w;const o=oe(),n=t.title||"Untitled reference",c=t.url&&/^https?:\/\//i.test(t.url)?t.url:void 0;return e.jsxs(st,{onOpenChange:x=>o==null?void 0:o.capture(x?"library_reference_opened":"library_reference_closed",{provider:t.provider,media_count:t.media.length}),children:[e.jsx(Jt,{asChild:!0,children:a}),e.jsxs(rt,{children:[e.jsx(it,{className:"fixed inset-0 z-50 bg-black/55"}),e.jsxs(nt,{className:"ph-no-capture bg-background text-foreground fixed inset-y-0 right-0 z-50 flex w-full max-w-2xl flex-col border-l border-white/10 shadow-2xl outline-none","data-rivet-private":!0,children:[e.jsxs("header",{className:"flex items-start justify-between gap-6 border-b border-white/[0.07] px-7 py-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(ot,{className:"mb-2 text-xs text-white/40",children:e.jsx(Ps,{provider:t.provider})}),e.jsx(at,{className:"text-lg leading-snug font-medium tracking-tight break-words",children:n})]}),e.jsx(Xt,{asChild:!0,children:e.jsx(U,{variant:"ghost",size:"icon-compact","aria-label":"Close reference",children:e.jsx(tt,{size:18})})})]}),e.jsx("div",{className:"border-b border-white/[0.07] px-7 py-4",children:e.jsx(Oe,{profileId:s,referenceKeys:[i]},t.revision)}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-7 overflow-y-auto px-7 py-6",children:[t.media.map(x=>e.jsx(_t,{profileId:s,referenceId:t.id,hash:x.hash,title:n,isDetail:!0},x.hash)),t.text?e.jsx("p",{className:"text-sm leading-7 break-words whitespace-pre-wrap text-white/70",children:t.text}):null,t.note?e.jsxs("section",{children:[e.jsx("h3",{className:"mb-2 text-xs font-medium text-white/45",children:"Your note"}),e.jsx("p",{className:"text-sm leading-7 break-words whitespace-pre-wrap text-white/75",children:t.note})]}):null,e.jsxs("section",{children:[e.jsx("h3",{className:"mb-2 text-xs font-medium text-white/45",children:((p=t.observation)==null?void 0:p.evidence)==="preference"?"Your preference":"Rivet’s analysis"}),e.jsx("p",{className:"text-sm leading-7 break-words whitespace-pre-wrap text-white/75",children:((w=t.observation)==null?void 0:w.description)??t.unsupportedReason??"No analysis saved yet."})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"mb-3 text-xs font-medium text-white/45",children:"Saved in"}),e.jsx("ul",{className:"space-y-2",children:r.filter(x=>t.sourceIds.includes(x.id)).map(x=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md bg-white/[0.035] px-3 py-2.5 text-xs",children:[e.jsx("span",{children:x.title}),x.isIncluded?null:e.jsx("span",{className:"text-white/35",children:"Excluded from generation"})]},x.id))})]}),c?e.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",onClick:()=>o==null?void 0:o.capture("library_reference_original_opened",{provider:t.provider}),className:"inline-flex items-center gap-1 text-xs text-white/70 underline-offset-4 hover:underline",children:["Open original",e.jsx(mt,{size:14,"aria-hidden":!0})]}):null]})]})]})]})},Ve="opacity-0 group-hover/card:opacity-100 group-focus-within/card:opacity-100 [@media(hover:none)]:opacity-100",zs="pointer-events-none group-hover/card:pointer-events-auto group-focus-within/card:pointer-events-auto [@media(hover:none)]:pointer-events-auto",$s=({profileId:s,reference:t,sources:r,referenceKey:i,isSelected:a,isSelectionDisabled:o,onSelect:n})=>{const c=t.title||"Untitled reference",p=t.media[0];return p?e.jsxs("div",{className:"group/card relative",children:[e.jsx(Ds,{profileId:s,reference:t,sources:r,referenceKey:i,children:e.jsx("button",{"aria-label":`Inspect ${c}`,className:"focus-visible:ring-offset-background block w-full overflow-hidden text-left outline-none focus-visible:ring-2 focus-visible:ring-white/50 focus-visible:ring-offset-4",children:e.jsx(_t,{profileId:s,referenceId:t.id,hash:p.hash,title:c},p.hash)})}),e.jsx("div",{"aria-hidden":!0,className:ve("pointer-events-none absolute inset-0 bg-black/40",Ve)}),e.jsxs("div",{className:ve("absolute inset-x-0 bottom-0 z-10 flex items-center justify-between gap-2 p-2",a?null:Ve,a?null:zs),children:[e.jsxs("label",{className:"relative shrink-0 cursor-pointer",title:a?"Deselect":"Select",children:[e.jsx("input",{type:"checkbox","aria-label":`Select ${c}`,checked:a,disabled:o,onChange:n,className:"peer absolute inset-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-default"}),e.jsx("span",{className:ve("flex h-7 w-7 items-center justify-center rounded-full border shadow-sm peer-focus-visible:ring-2 peer-focus-visible:ring-white peer-focus-visible:ring-offset-2 peer-disabled:opacity-40",a?"border-orange-400 bg-orange-500 text-white":"border-white/35 bg-black/60 text-white/70"),children:e.jsx(ct,{size:14,"aria-hidden":!0})})]}),e.jsx(Oe,{profileId:s,referenceKeys:[i]},t.revision)]})]}):null},be=24,qs="200px",Fs=({snapshot:s})=>{const t=oe(),[r,i]=h.useState(""),[a,o]=h.useState(""),[n,c]=h.useState(be),[p,w]=h.useState([]),x=h.useRef(null),u=Ls(s.references),f=s.references.filter(m=>m.media.length>0),b=f.filter(m=>p.includes(m.id)),N=b.flatMap(m=>{const S=u.get(m.id);return S?[S]:[]}),_=r.trim().toLowerCase(),j=f.filter(m=>{var S;return(!a||m.sourceIds.includes(a))&&[m.title,m.text,m.note,(S=m.observation)==null?void 0:S.description].some(O=>O==null?void 0:O.toLowerCase().includes(_))}),k=f.length>0,K=j.length,g=s.references.length>0?"No images yet":"Your library starts here",R=h.useCallback(m=>{var S;(S=x.current)==null||S.disconnect(),m&&(x.current=new IntersectionObserver(O=>{var I;O.some(Q=>Q.isIntersecting)&&((I=x.current)==null||I.disconnect(),c(Math.min(n+be,K)))},{root:m.parentElement,rootMargin:qs}),x.current.observe(m))},[n,K]),A=m=>{const S=b.map(I=>I.id),O=S.includes(m)?S.filter(I=>I!==m):[...S,m];w(O),t==null||t.capture("library_reference_selection_changed",{selected_count:O.length})};return e.jsxs("div",{className:"ph-no-capture flex min-h-0 flex-1 flex-col","data-rivet-private":!0,children:[e.jsx(kt,{children:e.jsx(Pe,{label:"Search references",value:r,onChange:m=>{i(m),c(be)},onBlur:()=>t==null?void 0:t.capture("library_reference_search_completed",{query_length:r.length,result_count:j.length})})}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-10 pb-10 max-sm:px-5",children:[!s.isEnabled&&k?e.jsx("p",{className:"mb-5 text-xs text-white/40",children:"Automatic use is paused. Your saved references are still here."}):null,k?e.jsx("div",{className:"mb-7 flex flex-wrap items-center gap-3",children:e.jsxs("select",{"aria-label":"Source",value:a,onChange:m=>{o(m.target.value),c(be),t==null||t.capture("library_reference_source_filtered",{is_filtered:!!m.target.value})},className:"bg-background max-w-64 rounded-lg border border-white/[0.08] px-3 py-2.5 text-xs text-white/60 focus-visible:outline-2",children:[e.jsx("option",{value:"",children:"All sources"}),s.sources.map(m=>e.jsx("option",{value:m.id,children:m.title},m.id))]})}):null,N.length?e.jsxs("div",{className:"bg-background sticky top-0 z-20 mb-6 flex flex-wrap items-center gap-3 rounded-lg border border-white/10 p-3 shadow-lg",children:[e.jsxs("span",{className:"text-xs text-white/50",children:[N.length," selected"]}),e.jsx(Oe,{profileId:s.profileId,referenceKeys:N},N.join(" ")),e.jsx(U,{variant:"ghost",size:"compact",onClick:()=>{w([]),t==null||t.capture("library_reference_selection_changed",{selected_count:0})},children:"Clear selection"})]}):null,j.length?e.jsx(Cs,{children:j.slice(0,n).map(m=>{const S=u.get(m.id);return S?e.jsx(Ss,{children:e.jsx($s,{profileId:s.profileId,reference:m,sources:s.sources,referenceKey:S,isSelected:p.includes(m.id),isSelectionDisabled:!p.includes(m.id)&&N.length>=Ct,onSelect:()=>A(m.id)})},m.id):null})}):e.jsxs("div",{className:"flex min-h-72 flex-col items-center justify-center rounded-xl border border-dashed border-white/[0.08] px-6 text-center",children:[e.jsx(hs,{size:28,strokeWidth:1,className:"mb-5 text-white/25","aria-hidden":!0}),e.jsx("h2",{className:"text-sm text-white/75",children:k?"No references found":g}),e.jsx("p",{className:"mt-2 max-w-sm text-xs leading-6 text-white/35",children:k?"Try another search or choose a different source.":"Ask your agent to save a design reference with an image to your library. It will appear here, ready to browse."})]}),j.length>n?e.jsx("div",{ref:R,role:"status",className:"py-8 text-center text-xs text-white/35",children:"Loading more references…"}):null]})]})},Ks=1e4,Hs=({onBrowseProjects:s})=>{var n,c;const t=Zt(),r=oe(),i=ie({queryKey:["design-library",(n=t.data)==null?void 0:n.userId,(c=t.data)==null?void 0:c.isAuthenticated],queryFn:({signal:p})=>F("/profile/library",{signal:p}),enabled:!t.isPending,refetchInterval:Ks,gcTime:0,retry:!1}),a=()=>{r==null||r.capture("library_reference_retry"),i.refetch()},o=e.jsx(kt,{children:e.jsx(Pe,{label:"Search references",value:"",isDisabled:!0})});return i.isError&&!i.data?e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[o,e.jsxs("div",{className:"m-auto max-w-md px-8 text-center",children:[e.jsx("h1",{className:"mb-3 text-lg font-medium",children:"References"}),e.jsx("p",{role:"alert",className:"text-sm text-white/50",children:i.error.message}),e.jsxs("div",{className:"mt-5 flex justify-center gap-3",children:[e.jsx(U,{variant:"secondary",onClick:a,children:"Try again"}),e.jsx(U,{variant:"ghost",onClick:s,children:"Projects"})]})]})]}):i.data?e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[i.isError?e.jsxs("div",{role:"alert",className:"flex items-center justify-between gap-4 border-b border-white/10 px-8 py-3 text-xs text-white/50",children:[e.jsx("span",{children:"Could not refresh. Showing the last saved results."}),e.jsx(U,{variant:"ghost",onClick:a,children:"Try again"})]}):null,e.jsx(Fs,{snapshot:i.data},i.data.profileId)]}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[o,e.jsx("p",{role:"status",className:"m-auto text-xs text-white/40",children:"Loading references…"})]})},Us=({view:s,onNavigate:t})=>e.jsx("nav",{"aria-label":"Library",className:"flex items-center gap-1 rounded-lg bg-white/[0.03] p-1",children:["library","references"].map(r=>e.jsx("a",{href:r==="library"?"/rivet/library":"/rivet/library/references","aria-current":s===r?"page":void 0,onClick:i=>{i.metaKey||i.ctrlKey||i.shiftKey||i.altKey||(i.preventDefault(),t(r))},className:es("rounded-md px-3 py-2 text-xs focus-visible:outline-2 focus-visible:outline-offset-2",s===r?"bg-white/[0.08] text-white":"text-white/45 hover:text-white/80"),children:r==="library"?"Projects":"References"},r))}),Qs=()=>{const s=ge(),t=async o=>{await s.cancelQueries({queryKey:["project-library"]}),s.setQueryData(["project-library","projects"],n=>n&&{projects:o(n.projects)}),s.setQueriesData({queryKey:["project-library","history"]},n=>{if(!n)return n;const c=o(n.projects),p=new Set(c.map(({id:w})=>w));return{projects:c,variants:n.variants.filter(({projectId:w})=>p.has(w))}}),s.invalidateQueries({queryKey:["project-library"]})},r=ce({mutationFn:({projectId:o,name:n})=>F(`/projects/${encodeURIComponent(o)}`,{method:"PATCH",body:{name:n}}),onSuccess:({project:o})=>t(n=>n.map(c=>c.id===o.id?{...c,name:o.name}:c))}),i=ce({mutationFn:({projectId:o,isPinned:n})=>F(`/projects/${encodeURIComponent(o)}/pin`,{method:n?"PUT":"DELETE"}),onSuccess:({project:o})=>t(n=>n.map(c=>c.id===o.id?{...c,pinnedAt:o.pinnedAt}:c))}),a=ce({mutationFn:o=>F(`/projects/${encodeURIComponent(o)}`,{method:"DELETE"}),onSuccess:async(o,n)=>{await t(c=>c.filter(({id:p})=>p!==n)),await s.cancelQueries({queryKey:["library-project-preview",n]}),s.removeQueries({queryKey:["library-project-preview",n]})}});return{setProjectPinned:async(o,n)=>{await i.mutateAsync({projectId:o,isPinned:n})},renameProject:async(o,n)=>{await r.mutateAsync({projectId:o,name:n})},removeProject:async o=>{await a.mutateAsync(o)}}},We=2500,Bs=500,Vs=6e4,Ws=[],Gs=[],ye=({error:s,retry:t})=>e.jsxs("div",{className:"m-auto max-w-md px-8 text-center",children:[e.jsx("p",{className:"text-sm text-white/70",children:s.message}),e.jsx("button",{onClick:t,className:"mt-5 rounded-lg border border-white/15 px-4 py-2 text-xs text-white/70",children:"Try again"})]}),Xs=()=>{var Me,Ae,Le,Te,De,ze;const s=oe(),t=ge(),{renameProject:r,removeProject:i,setProjectPinned:a}=Qs(),o=h.useRef(),[n,c]=h.useState(()=>Ke(new URL(window.location.href))),[p]=h.useState(()=>crypto.randomUUID()),w=h.useRef(0),x=h.useRef(null),u=ie({queryKey:["project-library","projects"],queryFn:({signal:l})=>F("/projects",{signal:l}),refetchInterval:We,retry:!1}),f=((Me=u.data)==null?void 0:Me.projects)??Ws,b=f.map(({id:l,projectPath:v})=>({id:l,projectPath:v})).sort((l,v)=>l.id.localeCompare(v.id)),N=ie({queryKey:["project-library","history",b],queryFn:({signal:l})=>F("",{signal:l}),placeholderData:l=>{if(!l)return;const v=new Map(l.projects.map(({id:D,projectPath:V})=>[D,V]));if(!f.every(({id:D,projectPath:V})=>v.get(D)===V))return;const E=new Set(f.map(({id:D})=>D));return{projects:l.projects.filter(({id:D})=>E.has(D)),variants:l.variants.filter(({projectId:D})=>E.has(D))}},enabled:f.length>0,refetchInterval:We,retry:!1}),_=new Map((Ae=N.data)==null?void 0:Ae.projects.map(l=>[l.id,l])),j=f.map(l=>{const v=_.get(l.id);return{...l,issue:v?v.issue:l.issue,historyIssue:v?v.historyIssue:l.historyIssue}}),k=((Le=N.data)==null?void 0:Le.variants)??Gs,K=ls({queries:j.map(l=>({queryKey:["library-project-preview",l.id,l.projectPath],queryFn:({signal:v})=>F(`/projects/${l.id}/thumbnail`,{signal:v}),enabled:n.kind==="library",refetchInterval:Vs,retry:!1}))}),g=j.find(l=>l.id===n.projectId),R=k.find(l=>l.projectId===n.projectId&&l.sessionId===n.sessionId&&l.variantId===n.variantId),A=h.useCallback(l=>{window.history.pushState(null,"",ts(l)),c(l)},[]);h.useEffect(()=>{g?o.current=g.id:u.isSuccess&&!u.isFetching&&n.projectId===o.current&&n.projectId&&(o.current=void 0,A({kind:"library"}))},[g,n.projectId,u.isSuccess,u.isFetching,A]),h.useEffect(()=>{const l=()=>c(Ke(new URL(window.location.href)));return window.addEventListener("popstate",l),()=>window.removeEventListener("popstate",l)},[]),h.useEffect(()=>{const l=new AbortController;let v;const E=async()=>{try{const D=await F(`/views/${p}`,{method:"PUT",body:{isFocused:document.visibilityState==="visible"&&document.hasFocus()},signal:l.signal});for(const V of D.navigations){if(l.signal.aborted)return;if(V.sequence>w.current){let je="library";V.projectId&&(je="workspace"),V.variantId&&(je="preview"),A({...V,kind:je}),w.current=V.sequence}await F(`/views/${p}/acknowledgements`,{method:"POST",body:{sequence:V.sequence},signal:l.signal})}}catch{}l.signal.aborted||(v=setTimeout(()=>{E()},Bs))};return E(),()=>{l.abort(),clearTimeout(v)}},[p,A]);const m=ie({queryKey:["library-workspace",n.projectId],queryFn:()=>F(`/projects/${n.projectId}/runtime`,{method:"POST"}),enabled:n.kind==="workspace"&&!!n.projectId&&(g==null?void 0:g.isAvailable)===!0,retry:!1,refetchOnWindowFocus:!1}),S=m.data?new URL(m.data.editorUrl).origin:null;h.useEffect(()=>{if(n.kind!=="workspace"||!S)return;const l=v=>{!x.current||v.source!==x.current.contentWindow||v.origin!==S||v.data!==ns||(s==null||s.capture("library_view_changed",{view:"projects"}),A({kind:"library"}))};return window.addEventListener("message",l),()=>window.removeEventListener("message",l)},[n.kind,S,A,s]);const O=ie({queryKey:["library-preview",n.projectId,n.sessionId,n.variantId],queryFn:()=>F(`/projects/${n.projectId}/variants/${n.sessionId}/${n.variantId}/preview`,{method:"POST"}),enabled:n.kind==="preview"&&!!(R!=null&&R.hasStaticPreview),retry:!1,refetchOnWindowFocus:!1}),I=ce({mutationFn:l=>F(`/projects/${n.projectId}/variants/${n.sessionId}/${n.variantId}`,{method:"PATCH",body:{label:l}}),onSuccess:()=>t.invalidateQueries({queryKey:["project-library"]})}),Q=l=>{const v=j.find(E=>E.id===l);s==null||s.capture("library_project_selected",{project_id:l,workspace_available:(v==null?void 0:v.isAvailable)??!1}),A({kind:"workspace",projectId:l})},B=ce({mutationFn:async l=>{const{projectPath:v}=await F("/folder-selections",{method:"POST"});return v===null?null:F(l?`/projects/${l}/workspace`:"/projects",{method:l?"PATCH":"POST",body:{projectPath:v}})},onSuccess:l=>{l&&(t.invalidateQueries({queryKey:["project-library"]}),s==null||s.capture("library_project_selected",{project_id:l.project.id,workspace_available:l.project.isAvailable}),A({kind:"workspace",projectId:l.project.id}))},onSettled:(l,v,E)=>{s==null||s.capture("library_open_project_closed",{is_relink:!!E})}}),C=l=>{B.isPending||(s==null||s.capture("library_open_project_opened",{is_relink:!!l}),B.mutate(l))},y=()=>{s==null||s.capture("library_view_changed",{view:"projects"}),A({kind:"library"})},$=()=>{s==null||s.capture("library_view_changed",{view:"workspace"}),A({...n,kind:"workspace"})},Z=()=>{s==null||s.capture("library_history_retry"),N.refetch()};let ee;if(n.kind==="workspace"&&(g==null?void 0:g.isAvailable)!==!1||n.kind==="preview"){let l=!1,v=e.jsxs("div",{className:"m-auto flex items-center gap-2 text-xs text-white/40",children:[e.jsx(ms,{size:14,className:"animate-spin"}),"Opening ",(g==null?void 0:g.name)??"project","…"]});if(u.data&&!g||N.data&&n.variantId&&!R)v=e.jsx("div",{className:"m-auto text-sm text-white/60",children:"This project or direction is no longer in your library."});else if(n.kind==="preview"&&N.error&&!N.data)v=e.jsx(ye,{error:N.error,retry:Z});else if(n.kind==="workspace"&&m.error)v=e.jsx(ye,{error:m.error,retry:()=>{m.refetch()}});else if(n.kind==="workspace"&&m.data){l=!0;const E=new URL(m.data.editorUrl);E.searchParams.set("library","1"),E.searchParams.set("libraryOrigin",window.location.origin),n.sessionId&&n.variantId&&(E.searchParams.set("historySession",n.sessionId),E.searchParams.set("historyVariant",n.variantId)),v=e.jsx("iframe",{ref:x,title:`${(g==null?void 0:g.name)??"Project"} workspace`,src:E.toString(),className:"min-h-0 w-full flex-1 border-0",allow:"clipboard-write"},E.toString())}else n.kind==="preview"&&O.error?v=e.jsx(ye,{error:O.error,retry:()=>{O.refetch()}}):n.kind==="preview"&&O.data?v=e.jsx("iframe",{title:`${(R==null?void 0:R.label)??"Saved direction"} preview`,src:O.data.url,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",className:"min-h-0 w-full flex-1 border-0 bg-white"}):n.kind==="preview"&&R&&!R.hasStaticPreview&&(v=e.jsxs("div",{className:"m-auto max-w-sm text-center",children:[e.jsx("p",{className:"text-sm",children:R.hasInteractivePreview?"Open this direction in its workspace":"This direction contains saved code changes"}),e.jsx("p",{className:"mt-2 text-xs leading-6 text-white/40",children:R.hasInteractivePreview?"Rivet will start the preview with this project’s dependencies and configuration.":"Open the project to continue working with its saved history."}),e.jsx("button",{onClick:$,disabled:(g==null?void 0:g.isAvailable)===!1,className:"mt-5 rounded-lg bg-white px-4 py-2.5 text-xs font-medium text-black disabled:opacity-30",children:"Open workspace"})]}));ee=e.jsxs(e.Fragment,{children:[n.kind==="preview"?e.jsxs("header",{className:"flex h-14 shrink-0 items-center gap-3 border-b border-white/[0.07] px-5",children:[e.jsx("button",{"aria-label":"Back to projects",onClick:y,className:"rounded p-1.5 text-white/45 hover:bg-white/5",children:e.jsx(ss,{size:15})}),e.jsx("span",{className:"text-xs text-white/40",children:g==null?void 0:g.name}),R?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/20",children:"/"}),e.jsxs("form",{onSubmit:E=>{E.preventDefault();const D=new FormData(E.currentTarget);I.mutate(String(D.get("label")))},className:"flex min-w-0 flex-1 gap-2",children:[e.jsx("input",{name:"label","aria-label":"Direction name",defaultValue:R.label,className:"max-w-xs min-w-0 flex-1 bg-transparent text-xs text-white/80 outline-none"}),e.jsx("button",{disabled:I.isPending,className:"text-[10px] text-white/30 hover:text-white",children:"Rename"})]},`${R.projectId}:${R.variantId}`)]}):e.jsx("span",{className:"flex-1"}),n.kind==="preview"?e.jsxs("button",{onClick:$,disabled:(g==null?void 0:g.isAvailable)===!1,className:"flex items-center gap-1.5 rounded-md border border-white/10 px-3 py-1.5 text-[11px] text-white/70 disabled:opacity-30",children:["Edit in project",e.jsx(mt,{size:12})]}):null]}):null,n.kind==="workspace"&&!l?e.jsx("button",{onClick:y,className:"absolute top-5 left-5 rounded px-2 py-1 text-xs text-white/50 hover:bg-white/5 hover:text-white",children:"Projects"}):null,I.error?e.jsx("p",{role:"alert",className:"px-5 py-2 text-xs text-red-200",children:I.error.message}):null,v]})}let J=ee;u.error&&!u.data?J=e.jsx(ye,{error:u.error,retry:()=>{u.refetch()}}):u.isPending&&(J=e.jsx("div",{role:"status",className:"m-auto text-xs text-white/40",children:"Loading projects…"}));const xe=n.kind==="references"?"references":"library",fe=e.jsx(Us,{view:xe,onNavigate:l=>{s==null||s.capture("library_view_changed",{view:l==="references"?"references":"projects"}),A({kind:l})}});return n.kind==="references"&&(J=e.jsx(Hs,{onBrowseProjects:y})),e.jsxs(e.Fragment,{children:[e.jsx(_s,{projects:j,variants:(Te=N.data)==null?void 0:Te.variants,historyError:(De=N.error)==null?void 0:De.message,onRetryHistory:Z,projectPreviews:Object.fromEntries(j.map((l,v)=>{var E,D;return[l.id,(D=(E=K[v])==null?void 0:E.data)==null?void 0:D.preview]})),selectedProjectId:n.projectId??null,onSelectProject:Q,onBrowseLibrary:y,navigation:fe,view:xe,onOpenProject:C,onRenameProject:r,onRemoveProject:i,onSetProjectPinned:a,accountMenu:e.jsx(rs,{side:"top",align:"start"}),isOpeningProject:B.isPending,projectOpenError:(ze=B.error)==null?void 0:ze.message,onSearchCompleted:l=>s==null?void 0:s.capture("library_search_completed",{query_length:l}),children:J}),e.jsx(is,{position:"bottom-right",theme:"dark"})]})};export{Xs as default};
|