@promptowl/contextnest-community 1.26.0 → 1.27.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/API.md +34 -1
- package/CONFIGURATION.md +32 -1
- package/dist/{chunk-TRSGPS27.js → chunk-H3W72HN3.js} +28 -0
- package/dist/{chunk-DGPTJXIV.js → chunk-MB52DWWP.js} +4 -4
- package/dist/{chunk-IEAWRHMV.js → chunk-NFFUZF2B.js} +23 -2
- package/dist/{chunk-PICUHQEM.js → chunk-O3JEI33N.js} +2 -2
- package/dist/{chunk-SWA5M5XX.js → chunk-QMQDWRHN.js} +128 -22
- package/dist/{chunk-I5EDEZBQ.js → chunk-RXCVXG34.js} +1 -1
- package/dist/{chunk-2QOJE7A5.js → chunk-SE5U4J4T.js} +4 -4
- package/dist/{chunk-RPGFHESR.js → chunk-VHEMGQ3I.js} +1 -1
- package/dist/{chunk-M6PGYMBD.js → chunk-VRLAP4HB.js} +33 -15
- package/dist/{engine-QNMFDIBV.js → engine-HLYQLP5T.js} +3 -3
- package/dist/{external-edit-service-4MEGPT4D.js → external-edit-service-3DFQ4EZZ.js} +4 -4
- package/dist/{grants-service-24GLUBY4.js → grants-service-WICV4Y2J.js} +2 -2
- package/dist/index.js +804 -304
- package/dist/{invited-user-AM6A3WGO.js → invited-user-XEBX6BM4.js} +3 -3
- package/dist/{review-service-2EWN7WWO.js → review-service-GB43UQVH.js} +7 -7
- package/dist/{stewardship-service-TDZUC2Q6.js → stewardship-service-KDBPWRZI.js} +4 -4
- package/dist/{version-service-C3JTZLJH.js → version-service-JYHFPSYP.js} +8 -4
- package/dist/web3/assets/{ActivityTracePage-DzwWIjjx.js → ActivityTracePage-CkRoyIc-.js} +1 -1
- package/dist/web3/assets/AgentDocsPage-BTRXmliv.js +1 -0
- package/dist/web3/assets/CollaboratorManager-CqJIkvs-.js +1 -0
- package/dist/web3/assets/CollaboratorsTab-JcO1P-qm.js +1 -0
- package/dist/web3/assets/DocumentEditor-D1GLeeEP.js +36 -0
- package/dist/web3/assets/DocumentsTab-BAgSxTX1.js +6 -0
- package/dist/web3/assets/ExternalEditsTab-DuuTXZap.js +1 -0
- package/dist/web3/assets/{MarkdownEditor-CKh4WSn-.js → MarkdownEditor-BELFww9q.js} +116 -126
- package/dist/web3/assets/{NestPageHeader-Cizo8nUi.js → NestPageHeader-Bbje2ncY.js} +1 -1
- package/dist/web3/assets/NestView-D4OMXPQ7.js +73 -0
- package/dist/web3/assets/OverviewTab-FIDGjR3Q.js +6 -0
- package/dist/web3/assets/{PersonCombobox-BKI7dff4.js → PersonCombobox-D52m_jhc.js} +1 -1
- package/dist/web3/assets/{ReviewActions-CS8JXgXF.js → ReviewActions-DYqBcWlv.js} +2 -2
- package/dist/web3/assets/ReviewTab-DoxfygOb.js +1 -0
- package/dist/web3/assets/StewardsTab-CFsYjbEn.js +1 -0
- package/dist/web3/assets/{SubmitForReviewModal-Biq3m79i.js → SubmitForReviewModal-AW2OLNAE.js} +1 -1
- package/dist/web3/assets/{alert-dialog-BvF3NFr7.js → alert-dialog-p-fBLSWx.js} +2 -2
- package/dist/web3/assets/{arrow-left-CWIsv-sG.js → arrow-left-CiErCCTG.js} +1 -1
- package/dist/web3/assets/{backlinks-Cqcn7n1J.js → backlinks-DaVSYvhV.js} +2 -2
- package/dist/web3/assets/{boxes-ClbgQqG2.js → boxes-VWrCCMzW.js} +1 -1
- package/dist/web3/assets/{chevron-left-CK_ZPFm9.js → chevron-left-CsD8gZwL.js} +1 -1
- package/dist/web3/assets/{circle-check-Bw_aTXiH.js → circle-check-BBCXd9LI.js} +1 -1
- package/dist/web3/assets/{circle-x-DkIG68H7.js → circle-x-C9LsnORQ.js} +1 -1
- package/dist/web3/assets/{code-xml-BlR7EN6l.js → code-xml-BaoV7HiQ.js} +1 -1
- package/dist/web3/assets/{corner-down-right-DSVxK3tf.js → corner-down-right-DgiTXrtw.js} +1 -1
- package/dist/web3/assets/{count-skeleton-DToLM74B.js → count-skeleton-CnEE4uF-.js} +1 -1
- package/dist/web3/assets/{earth-BXhVPvCR.js → earth-BmMbVt9k.js} +1 -1
- package/dist/web3/assets/{file-exclamation-point-BevGZgtj.js → file-exclamation-point-qJeca9-A.js} +1 -1
- package/dist/web3/assets/{folder-input-m8UBV4fA.js → folder-input-D7R93LJ6.js} +1 -1
- package/dist/web3/assets/index-DNmWTxN7.css +1 -0
- package/dist/web3/assets/index-DvuUIUP6.js +451 -0
- package/dist/web3/assets/{page-DzKwP5Ds.js → page-BJQuaTRW.js} +2 -2
- package/dist/web3/assets/{page-B6pkc9cd.js → page-Bb8xGOPQ.js} +2 -2
- package/dist/web3/assets/{page-Deq6IKiN.js → page-BtM-qDzr.js} +2 -2
- package/dist/web3/assets/{page-DPY01SOj.js → page-Bxd0EG25.js} +1 -1
- package/dist/web3/assets/page-C3QCO6IR.js +1 -0
- package/dist/web3/assets/{page-CptuAPJc.js → page-CfoR0khy.js} +2 -2
- package/dist/web3/assets/page-D7Zr5tAI.js +1 -0
- package/dist/web3/assets/{page-Dwbp4Seu.js → page-DATSlHCW.js} +2 -2
- package/dist/web3/assets/page-DTjPQizZ.js +45 -0
- package/dist/web3/assets/{page-Bgy9Ng9p.js → page-DspptlWr.js} +1 -1
- package/dist/web3/assets/{page-Dh57L0RG.js → page-I6vAFJOj.js} +4 -4
- package/dist/web3/assets/page-QxI4Ud2s.js +9 -0
- package/dist/web3/assets/{page-BJrFCKXB.js → page-YcNNg-dX.js} +1 -1
- package/dist/web3/assets/page-kM7eO5Kj.js +1 -0
- package/dist/web3/assets/{page-title-DVq4qvMR.js → page-title-Dn5jANiU.js} +1 -1
- package/dist/web3/assets/{play-CXhS6Pgq.js → play-B2k_Ix-L.js} +1 -1
- package/dist/web3/assets/{send-DdfwnIrj.js → send-DPNxv3As.js} +1 -1
- package/dist/web3/assets/{settings-DKX0Q4gO.js → settings-DZjq-OQA.js} +1 -1
- package/dist/web3/assets/{share-2-CxmXRt58.js → share-2-C-OnE2ru.js} +1 -1
- package/dist/web3/assets/{tag-DeYC_mRv.js → tag-CwJl7FdI.js} +1 -1
- package/dist/web3/assets/{trash-2-B0HyPTnI.js → trash-2-aljmIff4.js} +1 -1
- package/dist/web3/assets/{user-plus-Ckm_Isyc.js → user-plus-DPerZexX.js} +1 -1
- package/dist/web3/assets/{zap-D2ifcnYb.js → zap-CHZtiN7P.js} +1 -1
- package/dist/web3/index.html +2 -2
- package/package.json +6 -2
- package/dist/web3/assets/AgentDocsPage-ixP2UdAE.js +0 -1
- package/dist/web3/assets/CollaboratorManager-C9VAXZ0h.js +0 -1
- package/dist/web3/assets/CollaboratorsTab-tq4ZTexH.js +0 -1
- package/dist/web3/assets/DocumentEditor-C2CP2fiE.js +0 -36
- package/dist/web3/assets/DocumentsTab-Mh7KxUoB.js +0 -6
- package/dist/web3/assets/ExternalEditsTab-B_CWKXZ_.js +0 -1
- package/dist/web3/assets/NestView-EW-sraEb.js +0 -73
- package/dist/web3/assets/OverviewTab-CjidsMX_.js +0 -6
- package/dist/web3/assets/ReviewTab-CwVrXzw5.js +0 -1
- package/dist/web3/assets/StewardsTab-C-iP6gnh.js +0 -1
- package/dist/web3/assets/index-BOVYgMvj.js +0 -29
- package/dist/web3/assets/index-DVnaYqj9.css +0 -1
- package/dist/web3/assets/index-WYDmEOfO.js +0 -404
- package/dist/web3/assets/page-C2zoxumw.js +0 -1
- package/dist/web3/assets/page-CJWO06dN.js +0 -1
- package/dist/web3/assets/page-Dea2SblF.js +0 -9
- package/dist/web3/assets/page-Dfjg8p7Z.js +0 -1
- package/dist/web3/assets/page-YxjrE5b5.js +0 -45
- package/dist/web3/assets/x-mNtADYHc.js +0 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as ve,j as e,w as le,r as x,
|
|
1
|
+
import{c as ve,j as e,w as le,r as x,cN as ye,c6 as ke,c7 as Ce,c9 as Se,ca as Le,L as A,e as K,B as v,E as He,y as me,eI as Re,bQ as qe,D as Y,G as J,H as Z,J as X,K as ce,M as je,dk as We,u as ze,l as De,A as G,O as oe,a as U,V as Ge,W as Ue,Y as Ee,Z as Ae,ah as Qe,d3 as Ke,N as Q,I as we,T as Ye,C as Je,aD as Te,eJ as Ze,$ as Xe,eK as et,i as tt,eL as st,eM as nt,bU as at,F as it,eN as rt,eO as lt,eP as ot}from"./index-DvuUIUP6.js";import{D as ct,o as dt}from"./MarkdownEditor-BELFww9q.js";import{f as ht}from"./client-attribution-BraarYaP.js";import{T as Oe}from"./trash-2-aljmIff4.js";import{A as ut}from"./arrow-left-CiErCCTG.js";import{C as xe}from"./circle-check-BBCXd9LI.js";import{C as _e}from"./circle-x-C9LsnORQ.js";import{A as mt}from"./folder-input-D7R93LJ6.js";import{S as xt}from"./share-2-C-OnE2ru.js";/**
|
|
2
2
|
* @license lucide-react v0.577.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -16,4 +16,4 @@ import{c as ve,j as e,w as le,r as x,cs as ye,b_ as ke,b$ as Ce,c1 as Se,c2 as L
|
|
|
16
16
|
*/const jt=[["path",{d:"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7",key:"132q7q"}],["rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",key:"izxlao"}]],wt=ve("mail",jt);function vt(s){const t=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(s);return t?{oldStart:Number(t[1]),newStart:Number(t[2])}:null}function bt(s){const t=s.split(/\r?\n/),n=[];let a=0,r=0,d=!1;for(const o of t){if(!d&&(o.startsWith("+++")||o.startsWith("---")||o.startsWith("diff ")||o.startsWith("index ")||o.startsWith("Index: ")||/^=+$/.test(o)))continue;const u=vt(o);if(u){a=u.oldStart,r=u.newStart,d=!0,n.push({kind:"hunk",oldNo:null,newNo:null,text:o});continue}if(o.startsWith("+"))n.push({kind:"add",oldNo:null,newNo:r++,text:o.slice(1)});else if(o.startsWith("-"))n.push({kind:"del",oldNo:a++,newNo:null,text:o.slice(1)});else{const h=o.startsWith(" ")?o.slice(1):o;n.push({kind:"ctx",oldNo:a++,newNo:r++,text:h})}}return n}const $e={add:"bg-green-100 dark:bg-green-950/50",del:"bg-red-100 dark:bg-red-950/50",ctx:"",hunk:"bg-blue-50 dark:bg-blue-950/40 text-blue-700 dark:text-blue-300"},Nt={add:"+",del:"-",ctx:" ",hunk:""},Ie="select-none w-10 shrink-0 px-1 text-right tabular-nums text-[10px] text-muted-foreground/70 border-r border-border/60";function Me({patch:s,className:t}){const n=bt(s);return e.jsx("div",{className:le("rounded-md border bg-background font-mono text-xs leading-relaxed overflow-y-auto max-h-96",t),"data-testid":"diff-viewer",children:n.map((a,r)=>a.kind==="hunk"?e.jsx("div",{className:le("px-3 whitespace-pre-wrap break-words",$e[a.kind]),children:a.text||" "},r):e.jsxs("div",{className:le("flex items-stretch",$e[a.kind]),children:[e.jsx("span",{className:Ie,children:a.oldNo??""}),e.jsx("span",{className:Ie,children:a.newNo??""}),e.jsx("span",{className:le("select-none w-4 shrink-0 text-center",a.kind==="add"&&"text-green-700 dark:text-green-300",a.kind==="del"&&"text-red-700 dark:text-red-300"),children:Nt[a.kind]}),e.jsx("code",{className:"block flex-1 min-w-0 pr-3 whitespace-pre-wrap break-words",children:a.text||" "})]},r))})}function yt(s,t){const n=(s??"").split(`
|
|
17
17
|
`),a=(t??"").split(`
|
|
18
18
|
`),r=n.length,d=a.length,o=Array.from({length:r+1},()=>new Array(d+1).fill(0));for(let f=r-1;f>=0;f--)for(let c=d-1;c>=0;c--)o[f][c]=n[f]===a[c]?o[f+1][c+1]+1:Math.max(o[f+1][c],o[f][c+1]);const u=[];let h=0,m=0;for(;h<r&&m<d;)n[h]===a[m]?(u.push(" "+n[h]),h++,m++):o[h+1][m]>=o[h][m+1]?(u.push("- "+n[h]),h++):(u.push("+ "+a[m]),m++);for(;h<r;)u.push("- "+n[h++]);for(;m<d;)u.push("+ "+a[m++]);return u.join(`
|
|
19
|
-
`)}function kt(s,t){return s||t}const Fe={status:"Never published — no approved version exists yet.",guidance:"Saving keeps this document a draft; Submit for review to publish it."};function fe(s){const t=ze(s);return t?t.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}):""}function Ct(s){return s.length>20?`${s.slice(0,8)}…${s.slice(-7)}`:s}function St(s){var r;if(!s)return{};const t=s.match(/^Restored from version\s+(\d+)/i);if(t)return{restoredFrom:Number(t[1])};const n=s.match(/^External edit (approved|rejected)(?::\s*([\s\S]*))?$/i);if(n){const d=n[1].toLowerCase()==="rejected";return{action:{label:d?"External Edit Rejected":"External Edit Approved",rejected:d},note:((r=n[2])==null?void 0:r.trim())||void 0}}const a=s.match(/^(Approved|Rejected)\s+review\s+request\s+(\S+)/i);if(a){const d=a[1].toLowerCase()==="rejected";return{action:{label:d?"Review Rejected":"Review Approved",rejected:d},requestId:a[2]}}return{note:s}}function Lt({versions:s,currentVersion:t,approvedVersion:n,externalEditVerdicts:a,loading:r=!1,onRestore:d,onDiscard:o,previewAs:u="markdown",onView:h,onLoadContent:m,className:f}){var ae;const[c,p]=x.useState(null),[b,S]=x.useState(null),[N,R]=x.useState(!1),[H,D]=x.useState(!1),[T,w]=x.useState(!1),[g,y]=x.useState("changes"),[V,ee]=x.useState({}),I=ye.useRef(new Set),_=ye.useCallback(i=>{m&&(i in V||I.current.has(i)||(I.current.add(i),m(i).then(L=>ee(k=>({...k,[i]:L}))).catch(()=>ee(L=>({...L,[i]:null}))).finally(()=>I.current.delete(i))))},[m,V]),te=i=>kt(i.content,V[i.version]),q=!!m||!!(c!=null&&c.content),se=i=>{p(i),i.diff?y("changes"):(y("content"),_(i.version))},B=i=>{y(i),c&&(i==="content"&&_(c.version),i==="vs-current"&&(_(c.version),_(t)))},de=async()=>{if(!(!b||!d)){R(!0);try{await d(b),S(null)}finally{R(!1)}}},he=async()=>{if(o){w(!0);try{await o(),D(!1)}finally{w(!1)}}};if(r)return e.jsxs(ke,{className:f,children:[e.jsx(Ce,{className:"pb-3",children:e.jsxs(Se,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Be,{className:"h-4 w-4"}),"Version History"]})}),e.jsx(Le,{children:e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(A,{className:"h-5 w-5 animate-spin text-muted-foreground"})})})]});const M=(a??[]).filter(i=>i.status==="rejected").reverse(),C=(ae=s.find(i=>i.version===t))==null?void 0:ae.status,O=s.find(i=>i.version===t),$=O?te(O):void 0,E=C==="pending_review",ne=!!o&&!E&&n!=null&&t!==n,z=C==="approved"||C==="published"?"bg-green-100 text-green-800 border-green-200":C==="rejected"?"bg-red-100 text-red-800 border-red-200":C==="pending_review"?"bg-amber-100 text-amber-800 border-amber-200":"bg-muted text-muted-foreground";return e.jsxs(ke,{className:f,children:[e.jsxs(Ce,{className:"pb-3",children:[e.jsxs(Se,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Be,{className:"h-4 w-4"}),"Version History",C&&e.jsx(Q,{variant:"outline",className:`text-[10px] capitalize ${z}`,children:C.replace("_"," ")}),e.jsxs(Q,{variant:"secondary",className:"text-[10px] ml-auto",children:["v",t]}),ne&&e.jsxs(v,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs text-muted-foreground hover:text-destructive",title:`Throw away the unreviewed edits and go back to v${n}`,onClick:()=>D(!0),"data-testid":"version-history-discard",children:[e.jsx(Ve,{className:"h-3.5 w-3.5 mr-1"}),"Discard draft"]})]}),C==="draft"&&n==null&&e.jsxs("p",{className:"text-xs text-muted-foreground pt-1",children:[Fe.status,e.jsx("br",{}),Fe.guidance]})]}),e.jsx(Le,{children:c?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs(v,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:()=>{p(null),y("changes")},children:[e.jsx(ut,{className:"h-4 w-4 mr-1"})," Back"]}),e.jsxs("div",{className:"flex items-center gap-1",children:[h&&c.version!==t&&e.jsxs(v,{variant:"outline",size:"sm",className:"h-7",title:"Render this version in the viewer",onClick:()=>h(c.version),children:[e.jsx(He,{className:"h-4 w-4 mr-1"})," View rendered"]}),c.diff&&e.jsx(v,{variant:g==="changes"?"secondary":"outline",size:"sm",className:"h-7",onClick:()=>B("changes"),children:"Changes"}),q&&e.jsx(v,{variant:g==="content"?"secondary":"outline",size:"sm",className:"h-7",onClick:()=>B("content"),children:"Full content"}),q&&c.version!==t&&e.jsx(v,{variant:g==="vs-current"?"secondary":"outline",size:"sm",className:"h-7",onClick:()=>B("vs-current"),children:"vs current"}),d&&c.version!==t&&e.jsxs(v,{size:"sm",className:"h-7",disabled:E,title:E?"Locked while awaiting steward review — resolve the review first":void 0,onClick:()=>{S(c.version),p(null)},children:[e.jsx(me,{className:"h-4 w-4 mr-1"}),E?"Locked — review pending":"Restore"]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-semibold flex items-center gap-2",children:["Version ",c.version,c.version===n&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-green-700",children:[e.jsx(xe,{className:"h-3 w-3"})," AI-active"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[fe(c.editedAt)," · ",c.editedBy,c.changeNote&&` · ${c.changeNote}`]}),c.resolutionNote&&e.jsxs("div",{className:`mt-1 text-xs break-words border-l-2 pl-2 ${c.resolutionStatus==="rejected"?"border-red-300 text-red-800":"border-green-300 text-green-800"}`,children:[c.resolutionStatus==="rejected"?"Rejected by":"Approved by"," ",c.resolvedBy,": ",c.resolutionNote]})]}),e.jsx(Re,{className:"h-[60vh] max-h-[440px] pr-2",children:(()=>{const i=te(c),L=i===void 0;return g==="changes"&&c.diff?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:["Changes in v",c.version," (from v",c.version-1,")"]}),e.jsx(Me,{patch:c.diff,className:"max-h-none"})]}):g==="vs-current"?L||$===void 0?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground p-4",children:[e.jsx(A,{className:"h-4 w-4 animate-spin"})," Loading…"]}):i===null||$===null?e.jsx("div",{className:"text-sm text-muted-foreground p-4",children:"(no content)"}):e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:["Diff: v",c.version," → current (v",t,")"]}),e.jsx(Me,{patch:yt(i,$),className:"max-h-none"})]}):L?q?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground p-4",children:[e.jsx(A,{className:"h-4 w-4 animate-spin"})," Loading…"]}):e.jsx("div",{className:"text-sm text-muted-foreground p-4",children:"(no content)"}):i&&u==="source"?e.jsx("pre",{className:"whitespace-pre-wrap break-words bg-muted/30 rounded px-4 py-3 text-xs font-mono leading-relaxed",children:i}):i?e.jsx(ct,{content:i,className:"min-h-0 max-h-none overflow-visible bg-muted/30 rounded px-4 py-3"}):e.jsx("div",{className:"text-sm text-muted-foreground p-4",children:"(no content)"})})()})]}):s.length===0&&M.length===0?e.jsx("div",{className:"text-center py-4 text-sm text-muted-foreground",children:"No version history"}):e.jsxs(Re,{className:"h-[60vh] max-h-[480px] pr-2",children:[!!M.length&&e.jsxs("div",{className:"mb-3 space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground px-1",children:"Rejected external edits"}),M.map(i=>e.jsxs("div",{className:"p-2 rounded border bg-muted/20 space-y-0.5",children:[e.jsxs("div",{className:"text-xs font-medium flex items-center gap-1 text-red-700",children:[e.jsx(_e,{className:"h-3 w-3"}),"External edit rejected"]}),i.note&&e.jsx("div",{className:"text-xs text-foreground/80 break-words",children:i.note}),e.jsxs("div",{className:"text-xs text-muted-foreground break-words",children:["By:"," ",e.jsx("span",{className:"font-medium text-foreground/80",children:i.actor})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:fe(i.at)})]},i.suggestion_id))]}),e.jsx("div",{className:"space-y-1",children:s.map(i=>{const L=i.version===n,k=St(i.changeNote);return e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>se(i),className:`flex items-center justify-between p-2 rounded hover:bg-muted/50 cursor-pointer group ${L?"bg-green-50 border border-green-200":""}`,children:[e.jsxs("div",{className:"flex-1 min-w-0 space-y-0.5",children:[e.jsxs("div",{className:"text-sm font-medium flex items-center gap-2",children:["Version ",i.version,k.restoredFrom!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-blue-700",children:[e.jsx(me,{className:"h-3 w-3"})," Restored from v",k.restoredFrom]}),L&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-green-700",children:[e.jsx(xe,{className:"h-3 w-3"})," AI-active"]})]}),k.action&&e.jsxs("div",{className:`text-xs font-medium flex items-center gap-1 ${k.action.rejected?"text-red-700":"text-green-700"}`,children:[k.action.rejected?e.jsx(_e,{className:"h-3 w-3"}):e.jsx(xe,{className:"h-3 w-3"}),k.action.label]}),k.note&&e.jsx("div",{className:"text-xs text-foreground/80 break-words",children:k.note}),e.jsxs("div",{className:"text-xs text-muted-foreground break-words",children:["By:"," ",e.jsx("span",{className:"font-medium text-foreground/80",children:i.editedBy})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:fe(i.editedAt)}),i.client&&e.jsxs("div",{className:"text-xs text-muted-foreground break-words",children:["Client:"," ",e.jsx("span",{className:"font-mono text-foreground/70",children:ht(i.client)})]}),i.resolvedBy&&e.jsxs("div",{className:"text-xs text-muted-foreground break-words",children:[i.resolutionStatus==="rejected"?"Rejected by":"Approved by",":"," ",e.jsx("span",{className:"font-medium text-foreground/80",children:i.resolvedBy})]}),i.resolutionNote&&e.jsxs("div",{className:`text-xs break-words border-l-2 pl-2 ${i.resolutionStatus==="rejected"?"border-red-300 text-red-800":"border-green-300 text-green-800"}`,children:[i.resolutionStatus==="rejected"?"Reason":"Reviewer note",": ",i.resolutionNote]}),k.requestId&&e.jsxs("div",{className:"text-xs text-muted-foreground font-mono",children:["Review Request: ",Ct(k.requestId)]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[d&&i.version!==t&&e.jsx(v,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",disabled:E,title:E?"Locked while awaiting steward review — resolve the review first":"Restore this version",onClick:ie=>{ie.stopPropagation(),S(i.version)},children:e.jsx(me,{className:"h-3.5 w-3.5"})}),e.jsx(Oe,{className:"h-4 w-4 text-muted-foreground"})]})]},i.version)})})]})}),e.jsx(X,{open:!!b,onOpenChange:()=>S(null),children:e.jsxs(Y,{children:[e.jsxs(Z,{children:[e.jsxs(J,{children:["Restore Version ",b,"?"]}),e.jsxs(ce,{children:["This will create a new version with the content from version ",b,". Your current content will be saved in the version history."]})]}),e.jsxs(je,{children:[e.jsx(v,{variant:"outline",onClick:()=>S(null),disabled:N,children:"Cancel"}),e.jsx(v,{onClick:de,disabled:N,children:N?"Restoring...":"Restore"})]})]})}),e.jsx(X,{open:H,onOpenChange:()=>D(!1),children:e.jsxs(Y,{children:[e.jsxs(Z,{children:[e.jsx(J,{children:"Discard the draft?"}),e.jsxs(ce,{children:["The document goes back to version ",n," — the last approved one. Every edit made since is thrown away and can't be recovered. Unlike Restore, this adds no version to the history."]})]}),e.jsxs(je,{children:[e.jsx(v,{variant:"outline",onClick:()=>D(!1),disabled:T,children:"Cancel"}),e.jsx(v,{variant:"destructive",onClick:he,disabled:T,children:T?"Discarding...":"Discard draft"})]})]})})]})}function Ot({open:s,onClose:t,title:n,versionData:a,onRestore:r,onDiscard:d,previewAs:o,onView:u,onLoadContent:h}){return e.jsx(X,{open:s,onOpenChange:m=>!m&&t(),children:e.jsxs(Y,{className:"sm:max-w-[860px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsx(Z,{children:e.jsx(J,{children:n})}),a?e.jsx(Lt,{className:"flex-1 min-h-0 overflow-hidden",versions:a.versions,currentVersion:a.currentVersion,approvedVersion:a.approvedVersion,externalEditVerdicts:a.externalEditVerdicts,onRestore:r,onDiscard:d,previewAs:o,onView:u,onLoadContent:h}):e.jsxs("div",{className:"flex items-center justify-center py-12 text-sm text-muted-foreground",children:[e.jsx(A,{className:"h-4 w-4 mr-2 animate-spin"}),"Loading versions…"]})]})})}function zt(s){return s!=="pdf"}function Wt(s){const{isNew:t,canShare:n,isArchived:a,canEditContent:r,isPdf:d=!1,isLocked:o,canRequestDeletion:u,canDeleteDirectly:h,deletionRequested:m,isOwnDeletionRequest:f,includeVersionHistory:c=!0}=s,p=[];!t&&c&&p.push({key:"history",label:"Version history",testId:"document-editor-history"}),t||p.push({key:"copy-link",label:"Copy link",testId:"document-editor-copy-link",separatorBefore:!0}),!t&&r&&!o&&!d&&p.push({key:"move",label:"Move to folder",testId:"document-editor-move"}),n&&!t&&!a&&p.push({key:"share-doc",label:"Share this document",testId:"document-editor-share-doc",separatorBefore:!0}),n&&!t&&!a&&p.push({key:"publish",label:"Publish",testId:"document-editor-publish"});const b=!t&&u&&(h||!m);return b&&p.push({key:h?"delete":"request-deletion",label:"Delete",testId:h?"document-editor-delete":"document-editor-request-deletion",separatorBefore:!0,destructive:h}),!t&&m&&f&&p.push({key:"withdraw-deletion",label:"Withdraw deletion request",testId:"document-editor-withdraw-deletion",separatorBefore:!b}),p}function Pe(s){const t=(s.split("@")[0]||"").trim();if(!t)return"?";const n=t.split(/[._+-]+/).filter(Boolean);return(n.length>=2?n[0][0]+n[1][0]:t.slice(0,2)).toUpperCase()}const Rt={sm:"h-4 w-4 text-[8px]",md:"h-5 w-5 text-[9px]"},W=["bg-teal-500/15 text-teal-700 dark:text-teal-300","bg-amber-500/15 text-amber-700 dark:text-amber-300","bg-violet-500/15 text-violet-700 dark:text-violet-300","bg-rose-500/15 text-rose-700 dark:text-rose-300","bg-sky-500/15 text-sky-700 dark:text-sky-300","bg-emerald-500/15 text-emerald-700 dark:text-emerald-300","bg-orange-500/15 text-orange-700 dark:text-orange-300","bg-fuchsia-500/15 text-fuchsia-700 dark:text-fuchsia-300"];function Dt(s){let t=2166136261;for(let n=0;n<s.length;n++)t^=s.charCodeAt(n),t=Math.imul(t,16777619);return t^=t>>>16,t=Math.imul(t,2246822507),t^=t>>>13,t=Math.imul(t,3266489909),t^=t>>>16,(t>>>0)%W.length}function Et(s){const t=new Set;return s.map(n=>{const a=Dt(n);for(let r=0;r<W.length;r++){const d=(a+r)%W.length;if(!t.has(d))return t.add(d),W[d]}return W[a]})}function pe({label:s,title:t,tint:n,size:a}){return e.jsx("span",{title:t,className:`flex ${Rt[a]} shrink-0 items-center justify-center rounded-full border border-background font-medium leading-none ${n??"bg-muted text-muted-foreground"}`,children:s})}function Gt({author:s,collaborators:t=[],max:n=3,size:a="sm"}){if(!s&&t.length===0)return null;const r=t.slice(0,n),d=t.length-r.length,o=Et(r);return e.jsxs("span",{className:"inline-flex shrink-0 items-center -space-x-1",children:[s&&e.jsx(pe,{label:Pe(s),title:`Created by ${s}`,tint:"bg-primary/15 text-primary",size:a}),r.map((u,h)=>e.jsx(pe,{label:Pe(u),title:u,tint:o[h],size:a},u)),d>0&&e.jsx(pe,{label:`+${d}`,title:t.slice(n).join(", "),size:a})]})}function At(s){return s===null?{blocked:!1,behindDraft:!1}:s.approved===null?{blocked:!0,behindDraft:!1}:{blocked:!1,behindDraft:s.current>s.approved}}const Tt=[{value:"public",label:"Public",hint:"Anyone with the link",icon:Ke},{value:"email",label:"Email",hint:"One-time link by email",icon:wt},{value:"code",label:"Passcode",hint:"One shared code",icon:Qe},{value:"invite",label:"Invite only",hint:"Named people only",icon:dt}];function Ut({nestId:s,nodeId:t,nodeTitle:n,onClose:a}){const[r,d]=x.useState("public"),[o,u]=x.useState(!1),[h,m]=x.useState(!1),[f,c]=x.useState(!1),[p,b]=x.useState(""),[S,N]=x.useState(""),[R,H]=x.useState(""),[D,T]=x.useState(!1),[w,g]=x.useState(null),[y,V]=x.useState(null),[ee,I]=x.useState(!1),[_,te]=x.useState([]),[q,se]=x.useState(!0),[B,de]=x.useState({}),[he,M]=x.useState(null),[C,O]=x.useState(!0),[$,E]=x.useState(null),ne=We();async function z(){se(!0);try{const l=await Ze(s);te(l.publishes.filter(j=>j.node_id===t))}catch(l){g((l==null?void 0:l.message)||"Could not load existing links")}finally{se(!1)}}x.useEffect(()=>{z(),ne.fetchQuery(De.health()).then(l=>O(l.email_configured!==!1)).catch(()=>O(!0)),ne.fetchQuery(De.nodeVersions(s,t)).then(l=>E({approved:l.approvedVersion??null,current:l.currentVersion})).catch(()=>E(null))},[s,t]),x.useEffect(()=>{!C&&(r==="email"||r==="invite")&&d("public")},[C,r]);async function ae(){if(g(null),r==="code"&&!p.trim()){g("A passcode link needs a passcode.");return}const l=S.split(/[\n,]/).map(j=>j.trim()).filter(Boolean);if(r==="invite"&&!l.length){g("An invite-only link needs at least one email address.");return}T(!0);try{const j=await et(s,{node_id:t,access_mode:r,comments_enabled:o,watermark:h,no_download:f,code:r==="code"?p.trim():null,allowlist:r==="invite"?l:[],expires_at:R?new Date(`${R}T23:59:59`).toISOString():null});V(j.link),b(""),N(""),tt.success(`"${n}" published — link ready to share`),await z()}catch(j){g((j==null?void 0:j.message)||"Could not publish this document")}finally{T(!1)}}async function i(l){try{await navigator.clipboard.writeText(l),I(!0),setTimeout(()=>I(!1),1800)}catch{g("Could not copy — select the link and copy it manually.")}}async function L(l){g(null);try{await nt(s,l),await z()}catch(j){g((j==null?void 0:j.message)||"Could not revoke this link")}}async function k(l){M(l);try{const j=await st(s,l);de(F=>({...F,[l]:j.views}))}catch(j){g((j==null?void 0:j.message)||"Could not load the view log")}finally{M(null)}}const ie=l=>l.link||`${window.location.origin}/p/${l.slug}`,{blocked:ue,behindDraft:qe}=At($);return e.jsx(X,{open:!0,onOpenChange:l=>!l&&a(),children:e.jsxs(Y,{className:"sm:max-w-lg max-h-[85vh] overflow-y-auto",children:[e.jsxs(Z,{children:[e.jsxs(J,{children:["Publish “",n,"”"]}),e.jsx(ce,{children:"Host this document as a full-screen page at its own link, with the access gate you choose."})]}),w&&e.jsxs(G,{variant:"destructive",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx(U,{children:w})]}),ue&&e.jsxs(G,{variant:"destructive",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx(U,{children:"This document has never been approved, so a published link would show nothing to whoever opens it. Get it approved first — then publish."})]}),qe&&e.jsxs(G,{className:"border-amber-300 bg-amber-50 text-amber-900",children:[e.jsx(oe,{className:"h-4 w-4 text-amber-600"}),e.jsxs(U,{className:"text-amber-900",children:["Readers get the approved version (v",$.approved,"), not the current draft (v",$.current,"). Newer edits appear on the link once they are approved."]})]}),e.jsxs(Ge,{defaultValue:"new",children:[e.jsxs(Ue,{className:"grid w-full grid-cols-2",children:[e.jsx(Ee,{value:"new",children:"New link"}),e.jsxs(Ee,{value:"links",children:["Links (",_.length,")"]})]}),e.jsxs(Ae,{value:"new",className:"space-y-4 pt-3",children:[e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Tt.map(l=>{const j=l.icon,F=r===l.value,re=(l.value==="email"||l.value==="invite")&&!C;return e.jsxs("button",{type:"button",disabled:re,title:re?"This server has no email set up, so nobody could open the link.":void 0,onClick:()=>d(l.value),className:`flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors ${re?"cursor-not-allowed opacity-50":F?"border-primary bg-primary/5":"hover:bg-muted/50"}`,children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(j,{className:"h-4 w-4"}),l.label]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:re?"Needs email set up":l.hint})]},l.value)})}),!C&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Email and invite links are unavailable: this server has no mail transport configured, so the one-time link they rely on could never be delivered."}),r==="code"&&e.jsxs("div",{children:[e.jsx(K,{htmlFor:"publish-code",children:"Passcode"}),e.jsx(we,{id:"publish-code",value:p,onChange:l=>b(l.target.value),placeholder:"e.g. autumn-summit",className:"mt-1"})]}),r==="invite"&&e.jsxs("div",{children:[e.jsx(K,{htmlFor:"publish-allowlist",children:"Invite these people"}),e.jsx(Xe,{id:"publish-allowlist",value:S,onChange:l=>N(l.target.value),placeholder:"one email per line",className:"mt-1 min-h-20"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Each address gets an email with the link. Only these people can open it."})]}),e.jsxs("div",{children:[e.jsx(K,{htmlFor:"publish-expiry",children:"Expires (optional)"}),e.jsx(we,{id:"publish-expiry",type:"date",value:R,onChange:l=>H(l.target.value),className:"mt-1"})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border p-3",children:[e.jsx(ge,{id:"publish-comments",label:"Allow comments",hint:"Readers must give an email; comments go to the steward queue, never onto the page.",checked:o,onChange:u}),e.jsx(ge,{id:"publish-watermark",label:"Watermark viewer email",hint:"Only possible on the email and invite gates, which identify the reader.",checked:h,onChange:m}),e.jsx(ge,{id:"publish-nodownload",label:"Discourage download and print",hint:"Blocks copy, right-click, drag and printing. Screenshots and developer tools still work — pair it with a watermark if the content matters.",checked:f,onChange:c})]}),y&&e.jsxs("div",{className:"rounded-lg border border-primary/30 bg-primary/5 p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground",children:"Your link"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 truncate text-sm",children:y}),e.jsx(v,{size:"sm",variant:"outline",onClick:()=>i(y),children:ee?e.jsx(Ye,{className:"h-3.5 w-3.5"}):e.jsx(Te,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs(v,{onClick:ae,disabled:D||ue,title:ue?"This document has no approved version to serve.":void 0,className:"w-full",children:[D&&e.jsx(A,{className:"mr-2 h-4 w-4 animate-spin"}),"Publish"]})]}),e.jsx(Ae,{value:"links",className:"space-y-3 pt-3",children:q?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(A,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):_.length?_.map(l=>{const j=!!l.revoked_at;return e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{variant:j?"outline":"secondary",children:l.access_mode}),j&&e.jsx(Q,{variant:"outline",children:"revoked"}),l.expires_at&&!j&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["until ",new Date(l.expires_at).toLocaleDateString()]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 truncate text-xs",children:ie(l)}),e.jsx(v,{size:"sm",variant:"outline",onClick:()=>i(ie(l)),title:"Copy link",children:e.jsx(Te,{className:"h-3.5 w-3.5"})}),e.jsx(v,{size:"sm",variant:"outline",onClick:()=>k(l.id),title:"Who viewed",children:he===l.id?e.jsx(A,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(He,{className:"h-3.5 w-3.5"})}),!j&&e.jsx(v,{size:"sm",variant:"outline",onClick:()=>L(l.id),title:"Revoke",className:"text-destructive",children:e.jsx(pt,{className:"h-3.5 w-3.5"})})]}),B[l.id]&&e.jsx("div",{className:"mt-2 border-t pt-2",children:B[l.id].length?e.jsx("ul",{className:"space-y-1",children:B[l.id].map((F,Ne)=>e.jsxs("li",{className:"flex justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{className:"truncate",children:F.email||"anonymous"}),e.jsx("span",{className:"flex-shrink-0",children:new Date(F.created_at).toLocaleString()})]},Ne))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"No views yet."})})]},l.id)}):e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"This document has no links yet."})})]})]})})}function ge({id:s,label:t,hint:n,checked:a,onChange:r}){return e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(K,{htmlFor:s,className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx(Je,{id:s,checked:a,onCheckedChange:r})]})}function Kt({nestId:s,targetType:t,target:n,label:a,archived:r=!1,onClose:d}){const[o,u]=x.useState([]),[h,m]=x.useState(!0),[f,c]=x.useState(""),[p,b]=x.useState(!1),[S,N]=x.useState(null),R=async()=>{try{const{grants:w}=await rt(s);u(w.filter(g=>g.target_type===t&&g.target===n))}catch(w){N((w==null?void 0:w.message)||"Failed to load who this is shared with")}finally{m(!1)}};x.useEffect(()=>{R()},[s,t,n]);const H=async w=>{if(w.preventDefault(),!f.trim())return;const g=o.find(y=>(y.email??"").toLowerCase()===f.trim().toLowerCase());if(g){N(`This ${t} is already shared with ${g.email} (${g.role==="write"?"can edit":"can view"}).`);return}b(!0),N(null);try{await lt(s,{target_type:t,target:n,email:f.trim(),role:"read"}),c(""),await R()}catch(y){N((y==null?void 0:y.message)||"Failed to share")}finally{b(!1)}},D=async w=>{b(!0),N(null);try{await ot(s,w.id),await R()}catch(g){N((g==null?void 0:g.message)||"Failed to unshare")}finally{b(!1)}},T=t==="folder"?at:it;return e.jsx(X,{open:!0,onOpenChange:d,children:e.jsxs(Y,{className:"sm:max-w-[540px]",children:[e.jsxs(Z,{className:"min-w-0",children:[e.jsxs(J,{className:"flex items-center gap-2 min-w-0",children:[e.jsx(T,{className:"h-4 w-4 shrink-0"}),e.jsxs("span",{className:"truncate",children:["Share ",t==="folder"?"folder":"document",": ",a]})]}),e.jsx(ce,{children:t==="folder"?e.jsxs(e.Fragment,{children:["People you add here can ",e.jsx("strong",{children:"view every document in this folder"})," and its subfolders — nothing else in the nest, and no editing. They do not become stewards."]}):e.jsxs(e.Fragment,{children:["People you add here can ",e.jsx("strong",{children:"view this document"})," — nothing else in the nest, and no editing. They do not become stewards."]})}),e.jsx("code",{className:"mt-1 block rounded bg-muted px-2 py-1 text-[11px] text-muted-foreground break-all",children:n})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[r&&e.jsxs(G,{children:[e.jsx(mt,{className:"h-4 w-4"}),e.jsx(U,{children:"This nest is archived, so sharing is read-only. Restore the nest to change who has access."})]}),S&&e.jsxs(G,{variant:"destructive",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx(U,{children:S})]}),!r&&e.jsxs("form",{onSubmit:H,className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(we,{type:"email",placeholder:"teammate@example.com",value:f,onChange:w=>{c(w.target.value),S&&N(null)},disabled:p,className:"flex-1 min-w-0","data-testid":"share-target-email"}),e.jsx(v,{type:"submit",disabled:p||!f.trim(),className:"shrink-0",children:p?e.jsx(A,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(xt,{className:"h-4 w-4 mr-1"}),"Share"]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"If they don't have an account yet, they'll get access when they register with this email."})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-2 max-h-[40vh] overflow-y-auto",children:[e.jsxs(K,{className:"text-sm font-medium",children:["Shared with",o.length>0?` (${o.length})`:""]}),h?e.jsx(A,{className:"h-4 w-4 animate-spin text-muted-foreground"}):o.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Not shared with anyone yet. Everyone with access to the nest can already see it."}):e.jsx("div",{className:"divide-y divide-border",children:o.map(w=>e.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[e.jsx("span",{className:"flex-1 min-w-0 truncate text-sm",children:w.email??w.user_id}),e.jsx(Q,{variant:"secondary",className:"text-[11px]",children:w.role==="write"?"Can edit":"Can view"}),!r&&e.jsx(v,{variant:"ghost",size:"sm",disabled:p,onClick:()=>D(w),title:"Remove access","data-testid":`unshare-${w.id}`,children:e.jsx(Ve,{className:"h-3.5 w-3.5"})})]},w.id))})]})]}),e.jsx(je,{children:e.jsx(v,{variant:"outline",onClick:d,children:"Done"})})]})})}const be=/\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/g;function P(s){const t=s.lastIndexOf("/");return t>=0?s.slice(t+1):s}function _t(s){const t=[];let n;const a=new RegExp(be.source,"g");for(;(n=a.exec(s??""))!==null;){const r=n[1].trim();r&&t.push(r)}return t}function Qt(s,t){const n=t.id.toLowerCase(),a=(t.title??"").toLowerCase(),r=P(t.id).toLowerCase();if(!a)return[];const d=new RegExp(be.source,"g"),o=[];for(const u of s){if(u.id.toLowerCase()===n)continue;let h;d.lastIndex=0;let m=!1;for(;(h=d.exec(u.content??""))!==null;){const f=(h[1]??"").trim().toLowerCase(),c=(h[2]??"").trim().toLowerCase();if((f===n||P(f).toLowerCase()===r||f===a)&&(f===a||c===a)){m=!0;break}}m&&o.push({id:u.id,title:u.title})}return o}function Xt(s,t){const n=new Map,a=new Map,r=new Map;for(const m of t)n.set(m.id.toLowerCase(),m),a.set(P(m.id).toLowerCase(),m),r.set((m.title??"").toLowerCase(),m);const d=new RegExp(be.source,"g"),o=[],u=new Set;let h;for(;(h=d.exec(s??""))!==null;){const m=(h[1]??"").trim(),f=(h[2]??"").trim();if(!f)continue;const c=m.toLowerCase(),p=n.get(c)||a.get(P(m).toLowerCase())||r.get(c);if(p&&f.toLowerCase()!==(p.title??"").toLowerCase()){if(u.has(p.id))continue;u.add(p.id),o.push({id:p.id,currentTitle:p.title,shownAs:f})}}return o}function Yt(s,t){const n=t.id.toLowerCase(),a=(t.title??"").toLowerCase(),r=P(t.id).toLowerCase(),d=u=>{const h=u.toLowerCase();return h===n||a!==""&&h===a||P(u).toLowerCase()===r},o=[];for(const u of s){if(u.id.toLowerCase()===n)continue;_t(u.content??"").some(d)&&o.push({id:u.id,title:u.title})}return o}function Zt(s){return s===0?"":s===1?"1 document links to this — deleting it will break that link.":`${s} documents link to this — deleting it will break those links.`}export{Gt as A,Me as D,Be as H,Ut as P,Kt as S,Ot as V,Wt as d,_t as e,Yt as f,Zt as i,zt as n,Qt as r,Xt as s,yt as u};
|
|
19
|
+
`)}function kt(s,t){return s||t}const Pe={status:"Never published — no approved version exists yet.",guidance:"Saving keeps this document a draft; Submit for review to publish it."};function fe(s){const t=We(s);return t?t.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}):""}function Ct(s){return s.length>20?`${s.slice(0,8)}…${s.slice(-7)}`:s}function St(s){var r;if(!s)return{};const t=s.match(/^Restored from version\s+(\d+)/i);if(t)return{restoredFrom:Number(t[1])};const n=s.match(/^External edit (approved|rejected)(?::\s*([\s\S]*))?$/i);if(n){const d=n[1].toLowerCase()==="rejected";return{action:{label:d?"External Edit Rejected":"External Edit Approved",rejected:d},note:((r=n[2])==null?void 0:r.trim())||void 0}}const a=s.match(/^(Approved|Rejected)\s+review\s+request\s+(\S+)/i);if(a){const d=a[1].toLowerCase()==="rejected";return{action:{label:d?"Review Rejected":"Review Approved",rejected:d},requestId:a[2]}}return{note:s}}function Lt({versions:s,currentVersion:t,approvedVersion:n,externalEditVerdicts:a,loading:r=!1,onRestore:d,onDiscard:o,previewAs:u="markdown",onView:h,onLoadContent:m,className:f}){var ae;const[c,p]=x.useState(null),[b,S]=x.useState(null),[N,R]=x.useState(!1),[H,D]=x.useState(!1),[T,w]=x.useState(!1),[g,y]=x.useState("changes"),[O,ee]=x.useState({}),I=ye.useRef(new Set),_=ye.useCallback(i=>{m&&(i in O||I.current.has(i)||(I.current.add(i),m(i).then(L=>ee(k=>({...k,[i]:L}))).catch(()=>ee(L=>({...L,[i]:null}))).finally(()=>I.current.delete(i))))},[m,O]),te=i=>kt(i.content,O[i.version]),V=!!m||!!(c!=null&&c.content),se=i=>{p(i),i.diff?y("changes"):(y("content"),_(i.version))},B=i=>{y(i),c&&(i==="content"&&_(c.version),i==="vs-current"&&(_(c.version),_(t)))},de=async()=>{if(!(!b||!d)){R(!0);try{await d(b),S(null)}finally{R(!1)}}},he=async()=>{if(o){w(!0);try{await o(),D(!1)}finally{w(!1)}}};if(r)return e.jsxs(ke,{className:f,children:[e.jsx(Ce,{className:"pb-3",children:e.jsxs(Se,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Be,{className:"h-4 w-4"}),"Version History"]})}),e.jsx(Le,{children:e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(A,{className:"h-5 w-5 animate-spin text-muted-foreground"})})})]});const M=(a??[]).filter(i=>i.status==="rejected").reverse(),C=(ae=s.find(i=>i.version===t))==null?void 0:ae.status,q=s.find(i=>i.version===t),$=q?te(q):void 0,E=C==="pending_review",ne=!!o&&!E&&n!=null&&t!==n,W=C==="approved"||C==="published"?"bg-green-100 text-green-800 border-green-200":C==="rejected"?"bg-red-100 text-red-800 border-red-200":C==="pending_review"?"bg-amber-100 text-amber-800 border-amber-200":"bg-muted text-muted-foreground";return e.jsxs(ke,{className:f,children:[e.jsxs(Ce,{className:"pb-3",children:[e.jsxs(Se,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Be,{className:"h-4 w-4"}),"Version History",C&&e.jsx(K,{variant:"outline",className:`text-[10px] capitalize ${W}`,children:C.replace("_"," ")}),e.jsxs(K,{variant:"secondary",className:"text-[10px] ml-auto",children:["v",t]}),ne&&e.jsxs(v,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs text-muted-foreground hover:text-destructive",title:`Throw away the unreviewed edits and go back to v${n}`,onClick:()=>D(!0),"data-testid":"version-history-discard",children:[e.jsx(Oe,{className:"h-3.5 w-3.5 mr-1"}),"Discard draft"]})]}),C==="draft"&&n==null&&e.jsxs("p",{className:"text-xs text-muted-foreground pt-1",children:[Pe.status,e.jsx("br",{}),Pe.guidance]})]}),e.jsx(Le,{children:c?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs(v,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:()=>{p(null),y("changes")},children:[e.jsx(ut,{className:"h-4 w-4 mr-1"})," Back"]}),e.jsxs("div",{className:"flex items-center gap-1",children:[h&&c.version!==t&&e.jsxs(v,{variant:"outline",size:"sm",className:"h-7",title:"Render this version in the viewer",onClick:()=>h(c.version),children:[e.jsx(He,{className:"h-4 w-4 mr-1"})," View rendered"]}),c.diff&&e.jsx(v,{variant:g==="changes"?"secondary":"outline",size:"sm",className:"h-7",onClick:()=>B("changes"),children:"Changes"}),V&&e.jsx(v,{variant:g==="content"?"secondary":"outline",size:"sm",className:"h-7",onClick:()=>B("content"),children:"Full content"}),V&&c.version!==t&&e.jsx(v,{variant:g==="vs-current"?"secondary":"outline",size:"sm",className:"h-7",onClick:()=>B("vs-current"),children:"vs current"}),d&&c.version!==t&&e.jsxs(v,{size:"sm",className:"h-7",disabled:E,title:E?"Locked while awaiting steward review — resolve the review first":void 0,onClick:()=>{S(c.version),p(null)},children:[e.jsx(me,{className:"h-4 w-4 mr-1"}),E?"Locked — review pending":"Restore"]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-semibold flex items-center gap-2",children:["Version ",c.version,c.version===n&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-green-700",children:[e.jsx(xe,{className:"h-3 w-3"})," AI-active"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[fe(c.editedAt)," · ",c.editedBy,c.changeNote&&` · ${c.changeNote}`]}),c.resolutionNote&&e.jsxs("div",{className:`mt-1 text-xs break-words border-l-2 pl-2 ${c.resolutionStatus==="rejected"?"border-red-300 text-red-800":"border-green-300 text-green-800"}`,children:[c.resolutionStatus==="rejected"?"Rejected by":"Approved by"," ",c.resolvedBy,": ",c.resolutionNote]})]}),e.jsx(Re,{className:"h-[60vh] max-h-[440px] pr-2",children:(()=>{const i=te(c),L=i===void 0;return g==="changes"&&c.diff?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:["Changes in v",c.version," (from v",c.version-1,")"]}),e.jsx(Me,{patch:c.diff,className:"max-h-none"})]}):g==="vs-current"?L||$===void 0?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground p-4",children:[e.jsx(A,{className:"h-4 w-4 animate-spin"})," Loading…"]}):i===null||$===null?e.jsx("div",{className:"text-sm text-muted-foreground p-4",children:"(no content)"}):e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:["Diff: v",c.version," → current (v",t,")"]}),e.jsx(Me,{patch:yt(i,$),className:"max-h-none"})]}):L?V?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground p-4",children:[e.jsx(A,{className:"h-4 w-4 animate-spin"})," Loading…"]}):e.jsx("div",{className:"text-sm text-muted-foreground p-4",children:"(no content)"}):i&&u==="source"?e.jsx("pre",{className:"whitespace-pre-wrap break-words bg-muted/30 rounded px-4 py-3 text-xs font-mono leading-relaxed",children:i}):i?e.jsx(ct,{content:i,className:"min-h-0 max-h-none overflow-visible bg-muted/30 rounded px-4 py-3"}):e.jsx("div",{className:"text-sm text-muted-foreground p-4",children:"(no content)"})})()})]}):s.length===0&&M.length===0?e.jsx("div",{className:"text-center py-4 text-sm text-muted-foreground",children:"No version history"}):e.jsxs(Re,{className:"h-[60vh] max-h-[480px] pr-2",children:[!!M.length&&e.jsxs("div",{className:"mb-3 space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground px-1",children:"Rejected external edits"}),M.map(i=>e.jsxs("div",{className:"p-2 rounded border bg-muted/20 space-y-0.5",children:[e.jsxs("div",{className:"text-xs font-medium flex items-center gap-1 text-red-700",children:[e.jsx(_e,{className:"h-3 w-3"}),"External edit rejected"]}),i.note&&e.jsx("div",{className:"text-xs text-foreground/80 break-words",children:i.note}),e.jsxs("div",{className:"text-xs text-muted-foreground break-words",children:["By:"," ",e.jsx("span",{className:"font-medium text-foreground/80",children:i.actor})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:fe(i.at)})]},i.suggestion_id))]}),e.jsx("div",{className:"space-y-1",children:s.map(i=>{const L=i.version===n,k=St(i.changeNote);return e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>se(i),className:`flex items-center justify-between p-2 rounded hover:bg-muted/50 cursor-pointer group ${L?"bg-green-50 border border-green-200":""}`,children:[e.jsxs("div",{className:"flex-1 min-w-0 space-y-0.5",children:[e.jsxs("div",{className:"text-sm font-medium flex items-center gap-2",children:["Version ",i.version,k.restoredFrom!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-blue-700",children:[e.jsx(me,{className:"h-3 w-3"})," Restored from v",k.restoredFrom]}),L&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-green-700",children:[e.jsx(xe,{className:"h-3 w-3"})," AI-active"]})]}),k.action&&e.jsxs("div",{className:`text-xs font-medium flex items-center gap-1 ${k.action.rejected?"text-red-700":"text-green-700"}`,children:[k.action.rejected?e.jsx(_e,{className:"h-3 w-3"}):e.jsx(xe,{className:"h-3 w-3"}),k.action.label]}),k.note&&e.jsx("div",{className:"text-xs text-foreground/80 break-words",children:k.note}),e.jsxs("div",{className:"text-xs text-muted-foreground break-words",children:["By:"," ",e.jsx("span",{className:"font-medium text-foreground/80",children:i.editedBy})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:fe(i.editedAt)}),i.client&&e.jsxs("div",{className:"text-xs text-muted-foreground break-words",children:["Client:"," ",e.jsx("span",{className:"font-mono text-foreground/70",children:ht(i.client)})]}),i.resolvedBy&&e.jsxs("div",{className:"text-xs text-muted-foreground break-words",children:[i.resolutionStatus==="rejected"?"Rejected by":"Approved by",":"," ",e.jsx("span",{className:"font-medium text-foreground/80",children:i.resolvedBy})]}),i.resolutionNote&&e.jsxs("div",{className:`text-xs break-words border-l-2 pl-2 ${i.resolutionStatus==="rejected"?"border-red-300 text-red-800":"border-green-300 text-green-800"}`,children:[i.resolutionStatus==="rejected"?"Reason":"Reviewer note",": ",i.resolutionNote]}),k.requestId&&e.jsxs("div",{className:"text-xs text-muted-foreground font-mono",children:["Review Request: ",Ct(k.requestId)]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[d&&i.version!==t&&e.jsx(v,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",disabled:E,title:E?"Locked while awaiting steward review — resolve the review first":"Restore this version",onClick:ie=>{ie.stopPropagation(),S(i.version)},children:e.jsx(me,{className:"h-3.5 w-3.5"})}),e.jsx(qe,{className:"h-4 w-4 text-muted-foreground"})]})]},i.version)})})]})}),e.jsx(Y,{open:!!b,onOpenChange:()=>S(null),children:e.jsxs(J,{children:[e.jsxs(Z,{children:[e.jsxs(X,{children:["Restore Version ",b,"?"]}),e.jsxs(ce,{children:["This will create a new version with the content from version ",b,". Your current content will be saved in the version history."]})]}),e.jsxs(je,{children:[e.jsx(v,{variant:"outline",onClick:()=>S(null),disabled:N,children:"Cancel"}),e.jsx(v,{onClick:de,disabled:N,children:N?"Restoring...":"Restore"})]})]})}),e.jsx(Y,{open:H,onOpenChange:()=>D(!1),children:e.jsxs(J,{children:[e.jsxs(Z,{children:[e.jsx(X,{children:"Discard the draft?"}),e.jsxs(ce,{children:["The document goes back to version ",n," — the last approved one. Every edit made since is thrown away and can't be recovered. Unlike Restore, this adds no version to the history."]})]}),e.jsxs(je,{children:[e.jsx(v,{variant:"outline",onClick:()=>D(!1),disabled:T,children:"Cancel"}),e.jsx(v,{variant:"destructive",onClick:he,disabled:T,children:T?"Discarding...":"Discard draft"})]})]})})]})}function qt({open:s,onClose:t,title:n,versionData:a,onRestore:r,onDiscard:d,previewAs:o,onView:u,onLoadContent:h}){return e.jsx(Y,{open:s,onOpenChange:m=>!m&&t(),children:e.jsxs(J,{className:"sm:max-w-[860px] max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsx(Z,{children:e.jsx(X,{children:n})}),a?e.jsx(Lt,{className:"flex-1 min-h-0 overflow-hidden",versions:a.versions,currentVersion:a.currentVersion,approvedVersion:a.approvedVersion,externalEditVerdicts:a.externalEditVerdicts,onRestore:r,onDiscard:d,previewAs:o,onView:u,onLoadContent:h}):e.jsxs("div",{className:"flex items-center justify-center py-12 text-sm text-muted-foreground",children:[e.jsx(A,{className:"h-4 w-4 mr-2 animate-spin"}),"Loading versions…"]})]})})}function Wt(s){return s!=="pdf"}function zt(s){const{isNew:t,canShare:n,isArchived:a,canEditContent:r,isPdf:d=!1,isLocked:o,canRequestDeletion:u,canDeleteDirectly:h,deletionRequested:m,isOwnDeletionRequest:f,includeVersionHistory:c=!0}=s,p=[];!t&&c&&p.push({key:"history",label:"Version history",testId:"document-editor-history"}),t||p.push({key:"copy-link",label:"Copy link",testId:"document-editor-copy-link",separatorBefore:!0}),!t&&r&&!o&&!d&&p.push({key:"move",label:"Move to folder",testId:"document-editor-move"}),n&&!t&&!a&&p.push({key:"share-doc",label:"Share this document",testId:"document-editor-share-doc",separatorBefore:!0}),n&&!t&&!a&&p.push({key:"publish",label:"Publish",testId:"document-editor-publish"});const b=!t&&u&&(h||!m);return b&&p.push({key:h?"delete":"request-deletion",label:"Delete",testId:h?"document-editor-delete":"document-editor-request-deletion",separatorBefore:!0,destructive:h}),!t&&m&&f&&p.push({key:"withdraw-deletion",label:"Withdraw deletion request",testId:"document-editor-withdraw-deletion",separatorBefore:!b}),p}function Fe(s){const t=(s.split("@")[0]||"").trim();if(!t)return"?";const n=t.split(/[._+-]+/).filter(Boolean);return(n.length>=2?n[0][0]+n[1][0]:t.slice(0,2)).toUpperCase()}const Rt={sm:"h-4 w-4 text-[8px]",md:"h-5 w-5 text-[9px]"},z=["bg-teal-500/15 text-teal-700 dark:text-teal-300","bg-amber-500/15 text-amber-700 dark:text-amber-300","bg-violet-500/15 text-violet-700 dark:text-violet-300","bg-rose-500/15 text-rose-700 dark:text-rose-300","bg-sky-500/15 text-sky-700 dark:text-sky-300","bg-emerald-500/15 text-emerald-700 dark:text-emerald-300","bg-orange-500/15 text-orange-700 dark:text-orange-300","bg-fuchsia-500/15 text-fuchsia-700 dark:text-fuchsia-300"];function Dt(s){let t=2166136261;for(let n=0;n<s.length;n++)t^=s.charCodeAt(n),t=Math.imul(t,16777619);return t^=t>>>16,t=Math.imul(t,2246822507),t^=t>>>13,t=Math.imul(t,3266489909),t^=t>>>16,(t>>>0)%z.length}function Et(s){const t=new Set;return s.map(n=>{const a=Dt(n);for(let r=0;r<z.length;r++){const d=(a+r)%z.length;if(!t.has(d))return t.add(d),z[d]}return z[a]})}function pe({label:s,title:t,tint:n,size:a}){return e.jsx("span",{title:t,className:`flex ${Rt[a]} shrink-0 items-center justify-center rounded-full border border-background font-medium leading-none ${n??"bg-muted text-muted-foreground"}`,children:s})}function Gt({author:s,collaborators:t=[],max:n=3,size:a="sm"}){if(!s&&t.length===0)return null;const r=t.slice(0,n),d=t.length-r.length,o=Et(r);return e.jsxs("span",{className:"inline-flex shrink-0 items-center -space-x-1",children:[s&&e.jsx(pe,{label:Fe(s),title:`Created by ${s}`,tint:"bg-primary/15 text-primary",size:a}),r.map((u,h)=>e.jsx(pe,{label:Fe(u),title:u,tint:o[h],size:a},u)),d>0&&e.jsx(pe,{label:`+${d}`,title:t.slice(n).join(", "),size:a})]})}function At(s){return s===null?{blocked:!1,behindDraft:!1}:s.approved===null?{blocked:!0,behindDraft:!1}:{blocked:!1,behindDraft:s.current>s.approved}}const Tt=[{value:"public",label:"Public",hint:"Anyone with the link",icon:Qe},{value:"email",label:"Email",hint:"One-time link by email",icon:wt},{value:"code",label:"Passcode",hint:"One shared code",icon:Ke},{value:"invite",label:"Invite only",hint:"Named people only",icon:dt}];function Ut({nestId:s,nodeId:t,nodeTitle:n,onClose:a}){const[r,d]=x.useState("public"),[o,u]=x.useState(!1),[h,m]=x.useState(!1),[f,c]=x.useState(!1),[p,b]=x.useState(""),[S,N]=x.useState(""),[R,H]=x.useState(""),[D,T]=x.useState(!1),[w,g]=x.useState(null),[y,O]=x.useState(null),[ee,I]=x.useState(!1),[_,te]=x.useState([]),[V,se]=x.useState(!0),[B,de]=x.useState({}),[he,M]=x.useState(null),[C,q]=x.useState(!0),[$,E]=x.useState(null),ne=ze();async function W(){se(!0);try{const l=await Ze(s);te(l.publishes.filter(j=>j.node_id===t))}catch(l){g((l==null?void 0:l.message)||"Could not load existing links")}finally{se(!1)}}x.useEffect(()=>{W(),ne.fetchQuery(De.health()).then(l=>q(l.email_configured!==!1)).catch(()=>q(!0)),ne.fetchQuery(De.nodeVersions(s,t)).then(l=>E({approved:l.approvedVersion??null,current:l.currentVersion})).catch(()=>E(null))},[s,t]),x.useEffect(()=>{!C&&(r==="email"||r==="invite")&&d("public")},[C,r]);async function ae(){if(g(null),r==="code"&&!p.trim()){g("A passcode link needs a passcode.");return}const l=S.split(/[\n,]/).map(j=>j.trim()).filter(Boolean);if(r==="invite"&&!l.length){g("An invite-only link needs at least one email address.");return}T(!0);try{const j=await et(s,{node_id:t,access_mode:r,comments_enabled:o,watermark:h,no_download:f,code:r==="code"?p.trim():null,allowlist:r==="invite"?l:[],expires_at:R?new Date(`${R}T23:59:59`).toISOString():null});O(j.link),b(""),N(""),tt.success(`"${n}" published — link ready to share`),await W()}catch(j){g((j==null?void 0:j.message)||"Could not publish this document")}finally{T(!1)}}async function i(l){try{await navigator.clipboard.writeText(l),I(!0),setTimeout(()=>I(!1),1800)}catch{g("Could not copy — select the link and copy it manually.")}}async function L(l){g(null);try{await nt(s,l),await W()}catch(j){g((j==null?void 0:j.message)||"Could not revoke this link")}}async function k(l){M(l);try{const j=await st(s,l);de(P=>({...P,[l]:j.views}))}catch(j){g((j==null?void 0:j.message)||"Could not load the view log")}finally{M(null)}}const ie=l=>l.link||`${window.location.origin}/p/${l.slug}`,{blocked:ue,behindDraft:Ve}=At($);return e.jsx(Y,{open:!0,onOpenChange:l=>!l&&a(),children:e.jsxs(J,{className:"sm:max-w-lg max-h-[85vh] overflow-y-auto",children:[e.jsxs(Z,{children:[e.jsxs(X,{children:["Publish “",n,"”"]}),e.jsx(ce,{children:"Host this document as a full-screen page at its own link, with the access gate you choose."})]}),w&&e.jsxs(G,{variant:"destructive",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx(U,{children:w})]}),ue&&e.jsxs(G,{variant:"destructive",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx(U,{children:"This document has never been approved, so a published link would show nothing to whoever opens it. Get it approved first — then publish."})]}),Ve&&e.jsxs(G,{className:"border-amber-300 bg-amber-50 text-amber-900",children:[e.jsx(oe,{className:"h-4 w-4 text-amber-600"}),e.jsxs(U,{className:"text-amber-900",children:["Readers get the approved version (v",$.approved,"), not the current draft (v",$.current,"). Newer edits appear on the link once they are approved."]})]}),e.jsxs(Ge,{defaultValue:"new",children:[e.jsxs(Ue,{className:"grid w-full grid-cols-2",children:[e.jsx(Ee,{value:"new",children:"New link"}),e.jsxs(Ee,{value:"links",children:["Links (",_.length,")"]})]}),e.jsxs(Ae,{value:"new",className:"space-y-4 pt-3",children:[e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Tt.map(l=>{const j=l.icon,P=r===l.value,re=(l.value==="email"||l.value==="invite")&&!C;return e.jsxs("button",{type:"button",disabled:re,title:re?"This server has no email set up, so nobody could open the link.":void 0,onClick:()=>d(l.value),className:`flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors ${re?"cursor-not-allowed opacity-50":P?"border-primary bg-primary/5":"hover:bg-muted/50"}`,children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(j,{className:"h-4 w-4"}),l.label]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:re?"Needs email set up":l.hint})]},l.value)})}),!C&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Email and invite links are unavailable: this server has no mail transport configured, so the one-time link they rely on could never be delivered."}),r==="code"&&e.jsxs("div",{children:[e.jsx(Q,{htmlFor:"publish-code",children:"Passcode"}),e.jsx(we,{id:"publish-code",value:p,onChange:l=>b(l.target.value),placeholder:"e.g. autumn-summit",className:"mt-1"})]}),r==="invite"&&e.jsxs("div",{children:[e.jsx(Q,{htmlFor:"publish-allowlist",children:"Invite these people"}),e.jsx(Ye,{id:"publish-allowlist",value:S,onChange:l=>N(l.target.value),placeholder:"one email per line",className:"mt-1 min-h-20"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Each address gets an email with the link. Only these people can open it."})]}),e.jsxs("div",{children:[e.jsx(Q,{htmlFor:"publish-expiry",children:"Expires (optional)"}),e.jsx(we,{id:"publish-expiry",type:"date",value:R,onChange:l=>H(l.target.value),className:"mt-1"})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border p-3",children:[e.jsx(ge,{id:"publish-comments",label:"Allow comments",hint:"Readers must give an email; comments go to the steward queue, never onto the page.",checked:o,onChange:u}),e.jsx(ge,{id:"publish-watermark",label:"Watermark viewer email",hint:"Only possible on the email and invite gates, which identify the reader.",checked:h,onChange:m}),e.jsx(ge,{id:"publish-nodownload",label:"Discourage download and print",hint:"Blocks copy, right-click, drag and printing. Screenshots and developer tools still work — pair it with a watermark if the content matters.",checked:f,onChange:c})]}),y&&e.jsxs("div",{className:"rounded-lg border border-primary/30 bg-primary/5 p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground",children:"Your link"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 truncate text-sm",children:y}),e.jsx(v,{size:"sm",variant:"outline",onClick:()=>i(y),children:ee?e.jsx(Je,{className:"h-3.5 w-3.5"}):e.jsx(Te,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs(v,{onClick:ae,disabled:D||ue,title:ue?"This document has no approved version to serve.":void 0,className:"w-full",children:[D&&e.jsx(A,{className:"mr-2 h-4 w-4 animate-spin"}),"Publish"]})]}),e.jsx(Ae,{value:"links",className:"space-y-3 pt-3",children:V?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(A,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):_.length?_.map(l=>{const j=!!l.revoked_at;return e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{variant:j?"outline":"secondary",children:l.access_mode}),j&&e.jsx(K,{variant:"outline",children:"revoked"}),l.expires_at&&!j&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["until ",new Date(l.expires_at).toLocaleDateString()]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 truncate text-xs",children:ie(l)}),e.jsx(v,{size:"sm",variant:"outline",onClick:()=>i(ie(l)),title:"Copy link",children:e.jsx(Te,{className:"h-3.5 w-3.5"})}),e.jsx(v,{size:"sm",variant:"outline",onClick:()=>k(l.id),title:"Who viewed",children:he===l.id?e.jsx(A,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(He,{className:"h-3.5 w-3.5"})}),!j&&e.jsx(v,{size:"sm",variant:"outline",onClick:()=>L(l.id),title:"Revoke",className:"text-destructive",children:e.jsx(pt,{className:"h-3.5 w-3.5"})})]}),B[l.id]&&e.jsx("div",{className:"mt-2 border-t pt-2",children:B[l.id].length?e.jsx("ul",{className:"space-y-1",children:B[l.id].map((P,Ne)=>e.jsxs("li",{className:"flex justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{className:"truncate",children:P.email||"anonymous"}),e.jsx("span",{className:"flex-shrink-0",children:new Date(P.created_at).toLocaleString()})]},Ne))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"No views yet."})})]},l.id)}):e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"This document has no links yet."})})]})]})})}function ge({id:s,label:t,hint:n,checked:a,onChange:r}){return e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(Q,{htmlFor:s,className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx(Xe,{id:s,checked:a,onCheckedChange:r})]})}function Qt({nestId:s,targetType:t,target:n,label:a,archived:r=!1,onClose:d}){const[o,u]=x.useState([]),[h,m]=x.useState(!0),[f,c]=x.useState(""),[p,b]=x.useState(!1),[S,N]=x.useState(null),R=async()=>{try{const{grants:w}=await rt(s);u(w.filter(g=>g.target_type===t&&g.target===n))}catch(w){N((w==null?void 0:w.message)||"Failed to load who this is shared with")}finally{m(!1)}};x.useEffect(()=>{R()},[s,t,n]);const H=async w=>{if(w.preventDefault(),!f.trim())return;const g=o.find(y=>(y.email??"").toLowerCase()===f.trim().toLowerCase());if(g){N(`This ${t} is already shared with ${g.email} (${g.role==="write"?"can edit":"can view"}).`);return}b(!0),N(null);try{await lt(s,{target_type:t,target:n,email:f.trim(),role:"read"}),c(""),await R()}catch(y){N((y==null?void 0:y.message)||"Failed to share")}finally{b(!1)}},D=async w=>{b(!0),N(null);try{await ot(s,w.id),await R()}catch(g){N((g==null?void 0:g.message)||"Failed to unshare")}finally{b(!1)}},T=t==="folder"?at:it;return e.jsx(Y,{open:!0,onOpenChange:d,children:e.jsxs(J,{className:"sm:max-w-[540px]",children:[e.jsxs(Z,{className:"min-w-0",children:[e.jsxs(X,{className:"flex items-center gap-2 min-w-0",children:[e.jsx(T,{className:"h-4 w-4 shrink-0"}),e.jsxs("span",{className:"truncate",children:["Share ",t==="folder"?"folder":"document",": ",a]})]}),e.jsx(ce,{children:t==="folder"?e.jsxs(e.Fragment,{children:["People you add here can ",e.jsx("strong",{children:"view every document in this folder"})," and its subfolders — nothing else in the nest, and no editing. They do not become stewards."]}):e.jsxs(e.Fragment,{children:["People you add here can ",e.jsx("strong",{children:"view this document"})," — nothing else in the nest, and no editing. They do not become stewards."]})}),e.jsx("code",{className:"mt-1 block rounded bg-muted px-2 py-1 text-[11px] text-muted-foreground break-all",children:n})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[r&&e.jsxs(G,{children:[e.jsx(mt,{className:"h-4 w-4"}),e.jsx(U,{children:"This nest is archived, so sharing is read-only. Restore the nest to change who has access."})]}),S&&e.jsxs(G,{variant:"destructive",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx(U,{children:S})]}),!r&&e.jsxs("form",{onSubmit:H,className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(we,{type:"email",placeholder:"teammate@example.com",value:f,onChange:w=>{c(w.target.value),S&&N(null)},disabled:p,className:"flex-1 min-w-0","data-testid":"share-target-email"}),e.jsx(v,{type:"submit",disabled:p||!f.trim(),className:"shrink-0",children:p?e.jsx(A,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(xt,{className:"h-4 w-4 mr-1"}),"Share"]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"If they don't have an account yet, they'll get access when they register with this email."})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-2 max-h-[40vh] overflow-y-auto",children:[e.jsxs(Q,{className:"text-sm font-medium",children:["Shared with",o.length>0?` (${o.length})`:""]}),h?e.jsx(A,{className:"h-4 w-4 animate-spin text-muted-foreground"}):o.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Not shared with anyone yet. Everyone with access to the nest can already see it."}):e.jsx("div",{className:"divide-y divide-border",children:o.map(w=>e.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[e.jsx("span",{className:"flex-1 min-w-0 truncate text-sm",children:w.email??w.user_id}),e.jsx(K,{variant:"secondary",className:"text-[11px]",children:w.role==="write"?"Can edit":"Can view"}),!r&&e.jsx(v,{variant:"ghost",size:"sm",disabled:p,onClick:()=>D(w),title:"Remove access","data-testid":`unshare-${w.id}`,children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})]},w.id))})]})]}),e.jsx(je,{children:e.jsx(v,{variant:"outline",onClick:d,children:"Done"})})]})})}const be=/\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/g;function F(s){const t=s.lastIndexOf("/");return t>=0?s.slice(t+1):s}function _t(s){const t=[];let n;const a=new RegExp(be.source,"g");for(;(n=a.exec(s??""))!==null;){const r=n[1].trim();r&&t.push(r)}return t}function Kt(s,t){const n=t.id.toLowerCase(),a=(t.title??"").toLowerCase(),r=F(t.id).toLowerCase();if(!a)return[];const d=new RegExp(be.source,"g"),o=[];for(const u of s){if(u.id.toLowerCase()===n)continue;let h;d.lastIndex=0;let m=!1;for(;(h=d.exec(u.content??""))!==null;){const f=(h[1]??"").trim().toLowerCase(),c=(h[2]??"").trim().toLowerCase();if((f===n||F(f).toLowerCase()===r||f===a)&&(f===a||c===a)){m=!0;break}}m&&o.push({id:u.id,title:u.title})}return o}function Yt(s,t){const n=new Map,a=new Map,r=new Map;for(const m of t)n.set(m.id.toLowerCase(),m),a.set(F(m.id).toLowerCase(),m),r.set((m.title??"").toLowerCase(),m);const d=new RegExp(be.source,"g"),o=[],u=new Set;let h;for(;(h=d.exec(s??""))!==null;){const m=(h[1]??"").trim(),f=(h[2]??"").trim();if(!f)continue;const c=m.toLowerCase(),p=n.get(c)||a.get(F(m).toLowerCase())||r.get(c);if(p&&f.toLowerCase()!==(p.title??"").toLowerCase()){if(u.has(p.id))continue;u.add(p.id),o.push({id:p.id,currentTitle:p.title,shownAs:f})}}return o}function Jt(s,t){const n=t.id.toLowerCase(),a=(t.title??"").toLowerCase(),r=F(t.id).toLowerCase(),d=u=>{const h=u.toLowerCase();return h===n||a!==""&&h===a||F(u).toLowerCase()===r},o=[];for(const u of s){if(u.id.toLowerCase()===n)continue;_t(u.content??"").some(d)&&o.push({id:u.id,title:u.title})}return o}function Zt(s){return s===0?"":s===1?"1 document links to this — deleting it will break that link.":`${s} documents link to this — deleting it will break those links.`}export{Gt as A,Me as D,Be as H,Ut as P,Qt as S,qt as V,zt as d,_t as e,Jt as f,Zt as i,Wt as n,Kt as r,Yt as s,yt as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as n,j as e,D as Y,
|
|
1
|
+
import{r as n,j as e,D as Y,G as z,H,J as M,K as P,N as S,I as _,B as w,L as F,M as q,dN as J,dO as U,au as $,T as K,c4 as V,w as W}from"./index-DvuUIUP6.js";import{T as E}from"./trash-2-aljmIff4.js";import{A as X}from"./folder-input-D7R93LJ6.js";const A=100;function Z(t){const r=t.trim();return r?r.length>A?`Nest names are capped at ${A} characters — this one is ${r.length}.`:/<\/?[a-zA-Z][^>]*>/.test(t)?"Nest names are plain text — remove the HTML tags.":/[a-z0-9]/i.test(t)?null:"The URL slug is built from a-z and 0-9, so the name needs at least one of those":"Name is required"}const L=t=>t.trim().replace(/\s+/g," ");function ee({nestId:t,nestName:r,open:l,onOpenChange:d,onDeleted:m,onArchived:u,isImported:x=!1}){const[f,h]=n.useState(""),[g,p]=n.useState(!1),[j,N]=n.useState(!1),[v,i]=n.useState(null),o=g||j;n.useEffect(()=>{l&&(h(""),i(null),p(!1),N(!1))},[l]);const c=async()=>{N(!0),i(null);try{await J(t),u==null||u()}catch(s){console.error("[DeleteNestDialog] archiveNest failed",t,s),i((s==null?void 0:s.message)??"Failed to archive this nest. You may not have permission, or the server may be unreachable."),N(!1)}},b=async()=>{p(!0),i(null);try{await U(t),m()}catch(s){console.error("[DeleteNestDialog] deleteNest failed",t,s),i((s==null?void 0:s.message)??"Failed to delete this nest. You may not have permission, or the server may be unreachable."),p(!1)}};return e.jsx(Y,{open:l,onOpenChange:s=>{!s&&o||d(s)},children:e.jsxs(z,{className:"sm:max-w-[440px]",children:[e.jsxs(H,{children:[e.jsxs(M,{className:"flex items-center gap-2 text-red-700",children:[e.jsx(E,{className:"h-4 w-4"}),"Delete nest"]}),e.jsxs(P,{children:["You're about to permanently delete"," ",e.jsx("strong",{className:"text-foreground",children:r}),". This cannot be undone."]})]}),e.jsxs("div",{className:"rounded-md border border-red-200 bg-red-50 p-3 text-xs text-red-900 space-y-1",children:[e.jsx("p",{className:"font-medium",children:"This will remove:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-0.5",children:[e.jsx("li",{children:"Stewardship assignments and review-queue entries"}),e.jsx("li",{children:"Collaborator access and linked API keys"}),e.jsx("li",{children:"Version history and governance metadata"}),x?e.jsxs(e.Fragment,{children:[e.jsx("li",{children:"All documents and content (the workspace copy)"}),e.jsx("li",{className:"text-foreground",children:"Your original imported folder is not affected — only the copy in this workspace is removed"})]}):e.jsxs(e.Fragment,{children:[e.jsx("li",{children:"All documents and content"}),e.jsx("li",{children:"The nest folder on disk"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(S,{htmlFor:"delete-nest-confirm",className:"text-xs",children:["Type ",e.jsx("strong",{className:"font-mono",children:r})," to confirm:"]}),e.jsx(_,{id:"delete-nest-confirm",value:f,onChange:s=>h(s.target.value),placeholder:r,disabled:o,autoComplete:"off"})]}),u&&e.jsxs("div",{className:"rounded-md border bg-muted/40 p-3 text-xs space-y-2",children:[e.jsxs("p",{className:"text-muted-foreground",children:[e.jsx("strong",{className:"text-foreground",children:"Just want it out of the way?"})," ","Archiving keeps every document, version and steward exactly as they are. The nest leaves your dashboard, stops answering agents and published links, and becomes read-only until you restore it."]}),e.jsx(w,{variant:"outline",size:"sm",onClick:c,disabled:o,"data-testid":"archive-nest",children:j?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"h-3.5 w-3.5 mr-2 animate-spin"}),"Archiving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"h-3.5 w-3.5 mr-2"}),"Archive instead"]})})]}),v&&e.jsx("div",{className:"rounded-md border border-red-200 bg-red-50 p-2 text-xs text-red-900",children:v}),e.jsxs(q,{className:"gap-2",children:[e.jsx(w,{variant:"outline",onClick:()=>d(!1),disabled:o,children:"Cancel"}),e.jsx(w,{variant:"destructive",onClick:b,disabled:o||L(f)!==L(r),children:g?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"h-3.5 w-3.5 mr-2 animate-spin"}),"Deleting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"h-3.5 w-3.5 mr-2"}),"Delete nest"]})})]})]})})}function se({nestId:t,nestName:r,nestDescription:l,open:d,onOpenChange:m,onRenamed:u}){const[x,f]=n.useState(r),[h,g]=n.useState(l??""),[p,j]=n.useState(!1),[N,v]=n.useState(!1),i=n.useRef({name:r,description:l??""}),o=n.useRef(!1),[c,b]=n.useState(!1),[s,y]=n.useState(null);n.useEffect(()=>{d&&!o.current&&(i.current={name:r,description:l??""},f(r),g(l??""),j(!1),v(!1),y(null),b(!1)),o.current=d},[d,r,l]);const k=x.trim(),D=Z(x),T=p&&k!==i.current.name.trim(),C=N&&h.trim()!==i.current.description.trim(),R=T||C,B=async()=>{if(!c){if(D){y(D);return}if(!R){m(!1);return}b(!0),y(null);try{const a={};T&&(a.name=k),C&&(a.description=h.trim()||null);const{nest:G}=await V(t,a);u(G,{nameChanged:T,descChanged:C}),m(!1)}catch(a){console.error("[RenameNestDialog] updateNest failed",t,a),y((a==null?void 0:a.message)??"Failed to rename this nest. You may not have permission, or the server may be unreachable."),b(!1)}}};return e.jsx(Y,{open:d,onOpenChange:a=>{!a&&c||m(a)},children:e.jsx(z,{className:"sm:max-w-[440px]",children:e.jsxs("form",{onSubmit:a=>{a.preventDefault(),B()},className:"space-y-4",children:[e.jsxs(H,{children:[e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx($,{className:"h-4 w-4"}),"Rename nest"]}),e.jsx(P,{children:"Renaming updates the nest's name and URL slug. Documents, sharing, and history are unaffected."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{htmlFor:"rename-nest-name",className:"text-xs",children:"Name"}),e.jsx(_,{id:"rename-nest-name",value:x,onChange:a=>{f(a.target.value),j(!0),y(null)},placeholder:"Nest name",disabled:c,autoComplete:"off",autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(S,{htmlFor:"rename-nest-description",className:"text-xs",children:["Description"," ",e.jsx("span",{className:"text-muted-foreground",children:"(optional)"})]}),e.jsx(K,{id:"rename-nest-description",value:h,onChange:a=>{g(a.target.value),v(!0)},placeholder:"What lives in this nest?",disabled:c,autoComplete:"off",rows:3})]}),s&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-200 bg-red-50 p-2 text-xs text-red-900",children:s}),e.jsxs(q,{className:"gap-2",children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>m(!1),disabled:c,children:"Cancel"}),e.jsx(w,{type:"submit",disabled:c||!!D||!R,children:c?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"h-3.5 w-3.5 mr-2 animate-spin"}),"Saving..."]}):"Save"})]})]})})})}function ae({className:t}){return e.jsx("span",{className:W("inline-block h-6 w-10 rounded bg-muted-foreground/20 animate-pulse align-middle",t),"aria-hidden":!0})}export{ae as C,ee as D,se as R,Z as n};
|