@promptowl/contextnest-community 1.24.0 → 1.26.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.
Files changed (125) hide show
  1. package/API.md +177 -14
  2. package/CONFIGURATION.md +577 -116
  3. package/README.md +4 -3
  4. package/STEWARDSHIP.md +24 -0
  5. package/dist/{chunk-XUIWAWDO.js → chunk-2QOJE7A5.js} +4 -4
  6. package/dist/{chunk-2TPQTN4Y.js → chunk-DGPTJXIV.js} +47 -15
  7. package/dist/chunk-I5EDEZBQ.js +523 -0
  8. package/dist/{chunk-ZTT4U4NE.js → chunk-IEAWRHMV.js} +99 -12
  9. package/dist/{chunk-YVMSM7LS.js → chunk-LHWOJPFE.js} +7 -0
  10. package/dist/{chunk-5EZOPA47.js → chunk-M6PGYMBD.js} +20 -11
  11. package/dist/{chunk-F66VCBLA.js → chunk-PICUHQEM.js} +51 -2
  12. package/dist/{chunk-I3CSD6CK.js → chunk-RPGFHESR.js} +2 -2
  13. package/dist/{chunk-KIAAEHWL.js → chunk-SWA5M5XX.js} +88 -546
  14. package/dist/{chunk-LA3VTQ22.js → chunk-TRSGPS27.js} +81 -14
  15. package/dist/{engine-S3QBQ7LH.js → engine-QNMFDIBV.js} +4 -3
  16. package/dist/{external-edit-service-6FNFPOJJ.js → external-edit-service-4MEGPT4D.js} +5 -4
  17. package/dist/{grants-service-UT3EQ3R7.js → grants-service-24GLUBY4.js} +3 -3
  18. package/dist/index.js +1739 -583
  19. package/dist/invited-user-AM6A3WGO.js +12 -0
  20. package/dist/{migrations.postgres-AIQ7WSU7.js → migrations.postgres-HGSQ7IA5.js} +16 -2
  21. package/dist/{review-service-HHGOTO6P.js → review-service-2EWN7WWO.js} +8 -7
  22. package/dist/{stewardship-service-4DHNRULG.js → stewardship-service-TDZUC2Q6.js} +7 -4
  23. package/dist/{version-service-KIOQME6U.js → version-service-C3JTZLJH.js} +5 -4
  24. package/dist/web3/assets/ActivityTracePage-DzwWIjjx.js +1 -0
  25. package/dist/web3/assets/{AgentDocsPage-CIiaBqMy.js → AgentDocsPage-ixP2UdAE.js} +1 -1
  26. package/dist/web3/assets/CollaboratorManager-C9VAXZ0h.js +1 -0
  27. package/dist/web3/assets/CollaboratorsTab-tq4ZTexH.js +1 -0
  28. package/dist/web3/assets/DocumentEditor-C2CP2fiE.js +36 -0
  29. package/dist/web3/assets/DocumentsTab-Mh7KxUoB.js +6 -0
  30. package/dist/web3/assets/ExternalEditsTab-B_CWKXZ_.js +1 -0
  31. package/dist/web3/assets/MarkdownEditor-CKh4WSn-.js +653 -0
  32. package/dist/web3/assets/MarkdownEditor-ndtIx5x0.css +1 -0
  33. package/dist/web3/assets/NestPageHeader-Cizo8nUi.js +1 -0
  34. package/dist/web3/assets/NestView-EW-sraEb.js +73 -0
  35. package/dist/web3/assets/OverviewTab-CjidsMX_.js +6 -0
  36. package/dist/web3/assets/PersonCombobox-BKI7dff4.js +1 -0
  37. package/dist/web3/assets/{ReviewActions-OfOdqzCn.js → ReviewActions-CS8JXgXF.js} +2 -2
  38. package/dist/web3/assets/ReviewTab-CwVrXzw5.js +1 -0
  39. package/dist/web3/assets/StewardsTab-C-iP6gnh.js +1 -0
  40. package/dist/web3/assets/SubmitForReviewModal-Biq3m79i.js +1 -0
  41. package/dist/web3/assets/{alert-dialog-DTozKlmV.js → alert-dialog-BvF3NFr7.js} +2 -2
  42. package/dist/web3/assets/{arrow-left-BCKt4CwQ.js → arrow-left-CWIsv-sG.js} +1 -1
  43. package/dist/web3/assets/backlinks-Cqcn7n1J.js +19 -0
  44. package/dist/web3/assets/boxes-ClbgQqG2.js +6 -0
  45. package/dist/web3/assets/{chevron-left-BPwUT9DS.js → chevron-left-CK_ZPFm9.js} +1 -1
  46. package/dist/web3/assets/{circle-check-DI8IBGeo.js → circle-check-Bw_aTXiH.js} +1 -1
  47. package/dist/web3/assets/{circle-x-VKVhC88W.js → circle-x-DkIG68H7.js} +1 -1
  48. package/dist/web3/assets/client-attribution-BraarYaP.js +1 -0
  49. package/dist/web3/assets/{code-xml-CMabYZvH.js → code-xml-BlR7EN6l.js} +1 -1
  50. package/dist/web3/assets/{corner-down-right-BGxwK6wH.js → corner-down-right-DSVxK3tf.js} +1 -1
  51. package/dist/web3/assets/count-skeleton-DToLM74B.js +1 -0
  52. package/dist/web3/assets/{earth-BEp1EKTo.js → earth-BXhVPvCR.js} +1 -1
  53. package/dist/web3/assets/{file-exclamation-point-r8qZGIjP.js → file-exclamation-point-BevGZgtj.js} +1 -1
  54. package/dist/web3/assets/{folder-input-Cmtx1Jhk.js → folder-input-m8UBV4fA.js} +1 -1
  55. package/dist/web3/assets/{index-C1wTSjfP.js → index-BOVYgMvj.js} +1 -1
  56. package/dist/web3/assets/index-DVnaYqj9.css +1 -0
  57. package/dist/web3/assets/index-WYDmEOfO.js +404 -0
  58. package/dist/web3/assets/page-B6pkc9cd.js +2 -0
  59. package/dist/web3/assets/page-BJrFCKXB.js +1 -0
  60. package/dist/web3/assets/page-Bgy9Ng9p.js +1 -0
  61. package/dist/web3/assets/page-C2zoxumw.js +1 -0
  62. package/dist/web3/assets/page-CJWO06dN.js +1 -0
  63. package/dist/web3/assets/page-CptuAPJc.js +6 -0
  64. package/dist/web3/assets/page-DPY01SOj.js +1 -0
  65. package/dist/web3/assets/page-Dea2SblF.js +9 -0
  66. package/dist/web3/assets/page-Deq6IKiN.js +6 -0
  67. package/dist/web3/assets/page-Dfjg8p7Z.js +1 -0
  68. package/dist/web3/assets/{page-ByyVLDVo.js → page-Dh57L0RG.js} +5 -5
  69. package/dist/web3/assets/page-Dwbp4Seu.js +6 -0
  70. package/dist/web3/assets/{page-CHb0F5hV.js → page-DzKwP5Ds.js} +3 -3
  71. package/dist/web3/assets/page-YxjrE5b5.js +45 -0
  72. package/dist/web3/assets/{page-title-ClvvBsIo.js → page-title-DVq4qvMR.js} +1 -1
  73. package/dist/web3/assets/{play-C5YNKpAH.js → play-CXhS6Pgq.js} +1 -1
  74. package/dist/web3/assets/{send-0CHvmluT.js → send-DdfwnIrj.js} +1 -1
  75. package/dist/web3/assets/{settings-CeeF4LEb.js → settings-DKX0Q4gO.js} +1 -1
  76. package/dist/web3/assets/{share-2-CMnOlOt-.js → share-2-CxmXRt58.js} +1 -1
  77. package/dist/web3/assets/{tag-DQ_6J5Gv.js → tag-DeYC_mRv.js} +1 -1
  78. package/dist/web3/assets/{trash-2-HBi-Pslz.js → trash-2-B0HyPTnI.js} +1 -1
  79. package/dist/web3/assets/{user-plus-CvBNcpn4.js → user-plus-Ckm_Isyc.js} +1 -1
  80. package/dist/web3/assets/{x-By7piikG.js → x-mNtADYHc.js} +1 -1
  81. package/dist/web3/assets/zap-D2ifcnYb.js +16 -0
  82. package/dist/web3/index.html +2 -2
  83. package/package.json +3 -2
  84. package/dist/client-KEY4PYJH.js +0 -11
  85. package/dist/keys-CTOGAG3W.js +0 -20
  86. package/dist/web3/assets/ActivityTracePage-BOZHgJ8S.js +0 -1
  87. package/dist/web3/assets/CollaboratorManager-By91wrIr.js +0 -1
  88. package/dist/web3/assets/CollaboratorsTab-D1EE64Fs.js +0 -1
  89. package/dist/web3/assets/DocumentEditor-DrQfrW3d.js +0 -36
  90. package/dist/web3/assets/DocumentsTab-Vba-AzBv.js +0 -6
  91. package/dist/web3/assets/ExternalEditsTab-BSzAQIGM.js +0 -1
  92. package/dist/web3/assets/MarkdownEditor-74N_naNQ.css +0 -1
  93. package/dist/web3/assets/MarkdownEditor-C9zqZjC5.js +0 -643
  94. package/dist/web3/assets/NestPageHeader-CoLUV1Oz.js +0 -1
  95. package/dist/web3/assets/NestView-CTZ55tXD.js +0 -63
  96. package/dist/web3/assets/OverviewTab-Dxi-Hu-N.js +0 -1
  97. package/dist/web3/assets/PersonCombobox-CPOlNs6G.js +0 -1
  98. package/dist/web3/assets/ReasonDialog-DgLxfRWv.js +0 -1
  99. package/dist/web3/assets/ReviewTab-CyX8yxd3.js +0 -1
  100. package/dist/web3/assets/StewardsTab-DBEEfAQI.js +0 -1
  101. package/dist/web3/assets/SubmitForReviewModal-Ci2DdWs0.js +0 -1
  102. package/dist/web3/assets/backlinks-CYd4xENL.js +0 -24
  103. package/dist/web3/assets/card-XG2dP5Xf.js +0 -1
  104. package/dist/web3/assets/count-skeleton-DMbdpscX.js +0 -1
  105. package/dist/web3/assets/dates-BCxbm4_q.js +0 -1
  106. package/dist/web3/assets/index-BM-h3DwI.css +0 -1
  107. package/dist/web3/assets/index-EaX2yql0.js +0 -389
  108. package/dist/web3/assets/page-B3yvQvHy.js +0 -1
  109. package/dist/web3/assets/page-BExMvttJ.js +0 -1
  110. package/dist/web3/assets/page-BUOADv2X.js +0 -1
  111. package/dist/web3/assets/page-BYUFhYWZ.js +0 -1
  112. package/dist/web3/assets/page-Bicf02Cz.js +0 -1
  113. package/dist/web3/assets/page-BsPMDm5d.js +0 -45
  114. package/dist/web3/assets/page-CC0NJi8v.js +0 -1
  115. package/dist/web3/assets/page-CPjWQNKx.js +0 -11
  116. package/dist/web3/assets/page-CQt3ZGbf.js +0 -2
  117. package/dist/web3/assets/page-Cj1NetQ-.js +0 -1
  118. package/dist/web3/assets/page-CtaW65El.js +0 -1
  119. package/dist/web3/assets/page-DGOL9l8i.js +0 -6
  120. package/dist/web3/assets/refresh-cw-BhHzSH9m.js +0 -6
  121. package/dist/web3/assets/scroll-area-dRWncRqa.css +0 -1
  122. package/dist/web3/assets/scroll-area-hz-xtayP.js +0 -1
  123. package/dist/web3/assets/select-DBFTrUmI.js +0 -6
  124. package/dist/web3/assets/triangle-alert-CDy8-7sv.js +0 -6
  125. package/dist/web3/assets/zap-C2T8riBp.js +0 -11
@@ -0,0 +1,6 @@
1
+ import{c as Gs,j as e,e as Ye,w as Et,u as Qs,Y as He,l as ke,r as n,co as Ys,b_ as Js,b$ as Xs,c1 as Zs,bJ as ea,I as Ie,ah as ee,ai as te,aj as se,ak as ae,al as f,c_ as ta,c2 as sa,bK as Rt,aK as Vt,a5 as We,B as j,a_ as Bt,L as Ke,am as H,bN as aa,D as Ot,z as qt,G as zt,H as Ht,K as It,eh as ra,ag as Ue,a9 as la,i as b,m as oa,y as na,ei as ia,aq as Wt,an as Kt,aL as ca,ej as da,c5 as ua,aB as ma,aC as ha,as as pa,at as xa,av as ga,ax as I,ay as fa}from"./index-WYDmEOfO.js";import{e as va,f as ya,S as ja,P as ba,i as Na,V as wa,n as Ca,A as Sa,H as Ut}from"./backlinks-Cqcn7n1J.js";import{j as ka,z as Da,n as Ge,U as Ta,F as Fa,E as $a}from"./MarkdownEditor-CKh4WSn-.js";import{S as Ma}from"./SubmitForReviewModal-Biq3m79i.js";import{F as Pa}from"./file-exclamation-point-BevGZgtj.js";import{C as _a}from"./circle-x-DkIG68H7.js";import{C as Je}from"./circle-check-Bw_aTXiH.js";import{C as La,g as Aa,h as Gt,i as S,S as Qt,T as Yt,D as Jt,F as Ea,N as Xt,t as Ra}from"./NestView-EW-sraEb.js";import{f as Va}from"./folder-target-CUSWqImF.js";import{X as de}from"./x-mNtADYHc.js";import{F as De}from"./folder-input-m8UBV4fA.js";import{S as Zt}from"./share-2-CxmXRt58.js";import{T as ue}from"./trash-2-B0HyPTnI.js";import{S as es}from"./send-DdfwnIrj.js";import"./client-attribution-BraarYaP.js";import"./arrow-left-CWIsv-sG.js";import"./zap-D2ifcnYb.js";import"./index-BOVYgMvj.js";import"./chevron-left-CK_ZPFm9.js";import"./alert-dialog-BvF3NFr7.js";import"./NestPageHeader-Cizo8nUi.js";import"./count-skeleton-DToLM74B.js";import"./PersonCombobox-BKI7dff4.js";import"./tag-DeYC_mRv.js";import"./user-plus-Ckm_Isyc.js";import"./ReviewActions-CS8JXgXF.js";import"./settings-DKX0Q4gO.js";/**
2
+ * @license lucide-react v0.577.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 Ba=[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]],Oa=Gs("file-pen",Ba),ts={draft:{label:"Draft",icon:Oa,className:"bg-gray-100 text-gray-700 border-gray-200"},pending_review:{label:"Pending Review",icon:La,className:"bg-amber-100 text-amber-700 border-amber-200"},approved:{label:"Approved",icon:Je,className:"bg-green-100 text-green-700 border-green-200"},published:{label:"Published",icon:Je,className:"bg-green-100 text-green-700 border-green-200"},rejected:{label:"Rejected",icon:_a,className:"bg-red-100 text-red-700 border-red-200"},external_edit_pending:{label:"External Edit",icon:Pa,className:"bg-orange-100 text-orange-700 border-orange-200"}};function qa({status:a,approvedVersion:m,currentVersion:l,showIcon:h=!0,size:v="default",className:i}){const u=ts[a]||ts.draft,w=u.icon,D=(a==="approved"||a==="published")&&m&&l&&m<l;return e.jsxs(Ye,{variant:"outline",className:Et("!rounded-sm",u.className,v==="sm"&&"text-[10px] px-1.5 py-0",i),children:[h&&e.jsx(w,{className:Et("mr-1",v==="sm"?"h-3 w-3":"h-3.5 w-3.5")}),u.label,D&&e.jsxs("span",{className:"ml-1 text-[10px] opacity-75",children:["(v",m,")"]})]})}function ss(a){return a.replace(/^#/,"").toLowerCase()}function as(a,m){var D;const{search:l,status:h,tags:v,author:i,updatedAfter:u,type:w}=m;if(h&&h!=="all"&&a.status!==h||w&&w!=="all"&&(a.type||"document")!==w||i&&i!=="all"&&(a.author??"").toLowerCase()!==i.toLowerCase())return!1;if(u!=null){const T=a.updated_at?Date.parse(a.updated_at):NaN;if(Number.isNaN(T)||T<u)return!1}if(l){const T=l.toLowerCase(),re=((D=a.title)==null?void 0:D.toLowerCase().includes(T))??!1,me=Array.isArray(a.tags)?a.tags.some(Te=>Te.toLowerCase().includes(T)):!1;if(!re&&!me)return!1}if(v&&v.length>0){const T=new Set((a.tags??[]).map(ss));if(!v.every(re=>T.has(ss(re))))return!1}return!0}function za(a){const m=a.startsWith("nodes/")?a.slice(6):a,l=m.lastIndexOf("/");return l>0?m.slice(0,l):""}function ls(a){return!!a.search||a.status!=="all"||a.type!=="all"||a.tags.length>0||a.author!=="all"||a.datePreset!=="any"}function Ha(a){return(ls({search:a.search,status:a.status,type:a.type,author:a.author,tags:a.tags,datePreset:a.updatedAfter?"on":"any"})?a.fullNodes??a.levelNodes:a.levelNodes).filter(h=>{if(a.folderFilter!==null){const v=za(h.id||"");if(v!==a.folderFilter&&!v.startsWith(`${a.folderFilter}/`))return!1}return as(h,{status:a.status,tags:a.tags,author:a.author,updatedAfter:a.updatedAfter,type:a.type})?a.search?as(h,{search:a.search})||a.contentHits.has(h.id):!0:!1})}function Ia(a){return a.visibleCount>0?!1:a.filtering||a.folderCount===0}const Wa=3;function Ka(a,m=Wa){const l=new Map;for(const i of a)for(const u of new Set(i.tags??[]))l.set(u,(l.get(u)??0)+1);const h=[...l.entries()].sort((i,u)=>u[1]-i[1]||i[0].localeCompare(u[0])).map(([i,u])=>({tag:i,count:u})),v=a.filter(i=>i.updated_at).sort((i,u)=>String(u.updated_at).localeCompare(String(i.updated_at))).slice(0,m).map(i=>({id:i.id,title:i.title??i.id,type:i.type||"document",updated_at:i.updated_at}));return{tags:h,recent:v}}function rs(a,m){const l=a||"",h=m||"";return l>h?l:h}function Ua(a){const m=new Set,l=[];let h=!1;for(const i of a)for(const u of va(i.content??"")){h=!0;const w=ka(a,u);w?w.id!==i.id&&m.add(w.id):l.push({sourceId:i.id,sourceTitle:i.title,target:u})}return{orphans:h?a.filter(i=>!m.has(i.id)).map(i=>({id:i.id,title:i.title})):[],broken:l}}const Ga={"7d":7,"30d":30,"90d":90,"1y":365};function Qa(a,m){if(!(!a||a==="any"))return m-Ga[a]*24*60*60*1e3}function Ya(a,m){const l=m.name.toLowerCase();return[...a.filter(h=>h.name.toLowerCase()!==l),m]}function Ja(a,m){const l=m.toLowerCase();return a.filter(h=>h.name.toLowerCase()!==l)}function Xa(a){if(!a)return[];try{const m=JSON.parse(a);return Array.isArray(m)?m.filter(l=>l&&typeof l.name=="string"&&l.name.trim()).map(l=>({name:String(l.name),search:typeof l.search=="string"?l.search:void 0,status:typeof l.status=="string"?l.status:void 0,tags:Array.isArray(l.tags)?l.tags.filter(h=>typeof h=="string"):void 0,author:typeof l.author=="string"?l.author:void 0,datePreset:typeof l.datePreset=="string"?l.datePreset:void 0})):[]}catch{return[]}}function Za(a){return JSON.stringify(a)}const Qe={search:"",tags:[],status:"all",type:"all",author:"all",datePreset:"any"};function Fr({nestId:a,initialSearch:m,initialTags:l,initialLoad:h,loading:v,nodes:i,census:u,knownFolders:w,folderFilter:D,setFolderFilter:T,expandedFolders:re,loadingFolders:me,toggleFolderExpanded:Te,expandFolder:os,caps:ns,isAdmin:is,isOwner:Xe,roles:cs,permission:er,currentEmail:le,myStewards:ds,stewardshipEnabled:Fe,allowSelfApprove:us,primeTags:ms,visibility:tr,hasRoleOnNode:hs,canReviewNode:ps,reviewQueue:xs,reviewableQueue:gs,deletionRequests:W,stats:fs,onOpenDocument:A,onReview:Ze,onRefresh:vs,onWithdrawDeletion:et,importInputRef:ys}){var kt,Dt,Tt,Ft;const{canManage:g,collabCanWrite:js,canEditDocs:he,isReadOnly:tt}=ns,bs=Qs(),K=((kt=He(ke.commentCounts(a)).data)==null?void 0:kt.counts)??{},E=vs,[oe,st]=n.useState(null),[U,at]=n.useState(null),Ns=He({...ke.nodes(a),enabled:!!U}),ws=U?ya(((Dt=Ns.data)==null?void 0:Dt.nodes)??[],U).length:0,[M,rt]=n.useState(null),[$e,lt]=n.useState(null),Me=n.useMemo(()=>{const s=new Map;for(const t of W)(t.targetType??"document")==="document"&&!s.has(t.nodeId)&&s.set(t.nodeId,t);return s},[W]),Cs=n.useMemo(()=>new Set(W.filter(s=>s.targetType==="folder"&&s.status==="pending").map(s=>s.nodeId)),[W]),ot=s=>Cs.has(s),Ss=n.useMemo(()=>{const s=new Map;for(const t of W)t.targetType==="folder"&&t.status==="pending"&&!s.has(t.nodeId)&&s.set(t.nodeId,t);return s},[W]),[pe,nt]=n.useState(null),[P,xe]=n.useState(null),[_,it]=n.useState(null),[ks,Ds]=n.useState({versions:[],approvedVersion:null,currentVersion:0}),Ts=s=>{const t=i.find(r=>{const d=S(r.id||"");return d===s||d.startsWith(`${s}/`)});return Va(s,(t==null?void 0:t.id)??null)},ct=async(s,t)=>{if(S(s)===t)return!0;const r=t?H(t):"nest root",d=b.loading(`Moving to ${r}…`);try{const{node:x,previousId:y}=await Kt(a,s,t),L=S(y);return b.success(t?`Moved to ${r}`:"Moved to nest root",{id:d,action:{label:"Undo",onClick:async()=>{try{await Kt(a,x.id,L),b.success("Move undone"),E()}catch(c){console.error("[NestView] undo move failed",a,x.id,c),b.error((c==null?void 0:c.message)||"Undo failed")}}},duration:6e3}),E(),!0}catch(x){return console.error("[NestView] moveNode failed",a,s,t,x),b.error((x==null?void 0:x.message)||"Move failed",{id:d}),!1}},[R,ge]=n.useState(null),[Pe,dt]=n.useState(""),[fe,ut]=n.useState(!1),[G,ve]=n.useState(null),V=Aa(G??""),mt=G===null?Pe:V.path,Fs=n.useMemo(()=>((u==null?void 0:u.folders)??[]).map(s=>s.path).sort(Gt),[u]),ht=new Map;for(const s of xs)ht.set(s.nodeId,s.requestedBy.toLowerCase());const ye=s=>s?s.myGrant==="write"?!0:tt?!1:g||js?!0:ds.some(t=>{if(t.role!=="editor")return!1;if(t.scope==="nest")return!0;if(t.scope==="document")return t.nodePattern===s.id;if(t.scope==="tag"){const r=(t.tagName||"").toLowerCase().replace(/^#+/,"");return(s.tags||[]).map(d=>d.toLowerCase().replace(/^#+/,"")).includes(r)}return!1}):!1,$s=new Set(gs.map(s=>s.nodeId)),je=async s=>{it(s);try{const t=await bs.fetchQuery(ke.nodeVersions(a,s.id));Ds(t)}catch(t){console.error("[NestView] getNodeVersions failed",a,s==null?void 0:s.id,t)}},Ms=async(s,t)=>{if(P)try{await ca(a,P.id,s,t),b.success("Submitted for review"),xe(null),E()}catch(r){console.error("[NestView] submitForReview failed",a,P==null?void 0:P.id,r),b.error((r==null?void 0:r.message)||"Submit failed")}},Ps=async()=>{const s=U;try{await ma(a,s.id),E()}catch(t){throw console.error("[NestView] deleteNode failed",a,s==null?void 0:s.id,t),t}},_s=async s=>{await ha(a,oe.id,s),b.success("Deletion requested — a nest admin will review it"),E()},Ls=async s=>{const t=M;if(g){const{deleted:r}=await da(a,t.path);b.success(r===0?`Deleted ${t.label}`:`Deleted ${t.label} — ${r} document${r===1?"":"s"}`)}else await ua(a,"folder",t.path,s),b.success("Deletion requested — a nest admin will review it");E()},k=D??"",As=k?k.split("/").length:0,[_e,Es]=n.useState(!1),pt=He({...ke.nodes(a),enabled:_e}),Q=_e?((Tt=pt.data)==null?void 0:Tt.nodes)??null:null,Rs=_e&&pt.isLoading,Le=n.useCallback(()=>Es(!0),[]),[o,be]=n.useState({...Qe,search:m??"",tags:l??[]}),C=(s,t)=>be(r=>({...r,[s]:t})),xt=s=>be(t=>({...t,tags:t.tags.includes(s)?t.tags.filter(r=>r!==s):[...t.tags,s]})),[Ne,Vs]=n.useState("activity"),[B,gt]=n.useState(()=>{try{return localStorage.getItem("nest:viewMode")==="cards"?"cards":"list"}catch{return"list"}});n.useEffect(()=>{try{localStorage.setItem("nest:viewMode",B)}catch{}},[B]);const Ae=`nest:${a}:savedFilters`,[we,Ee]=n.useState([]);n.useEffect(()=>{try{Ee(Xa(localStorage.getItem(Ae)))}catch{Ee([])}},[Ae]);const ft=s=>{Ee(s);try{localStorage.setItem(Ae,Za(s))}catch{}},[Bs,Ce]=n.useState(!1),[Re,vt]=n.useState(""),yt=()=>{const s=Re.trim();s&&(ft(Ya(we,{name:s,search:o.search||void 0,status:o.status!=="all"?o.status:void 0,tags:o.tags.length?o.tags:void 0,author:o.author!=="all"?o.author:void 0,datePreset:o.datePreset!=="any"?o.datePreset:void 0,type:o.type!=="all"?o.type:void 0})),vt(""),Ce(!1))},Os=({name:s,...t})=>be({...Qe,...Object.fromEntries(Object.entries(t).filter(([,r])=>r!==void 0))}),[qs,jt]=n.useState(new Set);n.useEffect(()=>{const s=o.search.trim();if(s.length<2){jt(new Set);return}let t=!1;const r=setTimeout(async()=>{try{const{nodes:d}=await Ys(a,s);t||jt(new Set(d.map(x=>x.id)))}catch{}},300);return()=>{t=!0,clearTimeout(r)}},[a,o.search]);const O=ls(o);n.useEffect(()=>{O&&Le()},[O,Le]);const zs=Qa(o.datePreset,Date.now()),ne=Ha({...o,levelNodes:i,fullNodes:Q,folderFilter:D,updatedAfter:zs,contentHits:qs}),Y=[...ne];Ne==="activity"?Y.sort((s,t)=>{var r,d;return rs(t.updated_at,(r=K[t.id])==null?void 0:r.lastAt).localeCompare(rs(s.updated_at,(d=K[s.id])==null?void 0:d.lastAt))}):Ne==="edited"?Y.sort((s,t)=>String(t.updated_at||"").localeCompare(String(s.updated_at||""))):Ne==="comments"?Y.sort((s,t)=>{var L,c,N,X;const r=((L=K[t.id])==null?void 0:L.count)||0,d=((c=K[s.id])==null?void 0:c.count)||0;if(r!==d)return r-d;const x=((N=K[t.id])==null?void 0:N.lastAt)||"",y=((X=K[s.id])==null?void 0:X.lastAt)||"";return x!==y?String(x).localeCompare(String(y)):String(s.title||"").localeCompare(String(t.title||""))}):Y.sort((s,t)=>String(s.title||"").localeCompare(String(t.title||"")));const Hs=(()=>{const s=new Map;for(const t of Y){const r=S(t.id||"");s.has(r)||s.set(r,[]),s.get(r).push(t)}return[...s.entries()].map(([t,r])=>({folder:t,depth:t?t.split("/").length-As:0,items:r})).sort((t,r)=>t.folder===""?-1:r.folder===""?1:Gt(t.folder,r.folder))})(),Is=Ia({visibleCount:ne.length,folderCount:w.length,filtering:O}),F=n.useMemo(()=>Q?Ua(Q):{orphans:[],broken:[]},[Q]),bt=(u==null?void 0:u.authors)??[],Nt=n.useMemo(()=>Object.keys((u==null?void 0:u.types)??{}).sort((s,t)=>s.localeCompare(t)),[u]),Ws=()=>{be({...Qe})},J=[];o.search&&J.push({label:`Search: ${o.search}`,clear:()=>C("search","")}),o.status!=="all"&&J.push({label:`Status: ${Qt[o.status]??o.status}`,clear:()=>C("status","all")}),o.type!=="all"&&J.push({label:`Type: ${Yt[o.type]??o.type}`,clear:()=>C("type","all")}),o.author!=="all"&&J.push({label:`Author: ${o.author}`,clear:()=>C("author","all")}),o.datePreset!=="any"&&J.push({label:`Edited: ${Jt[o.datePreset]??o.datePreset}`,clear:()=>C("datePreset","any")});const wt=n.useMemo(()=>Ka(ne),[ne]),Se=wt.tags,Ct=wt.recent,[$,Ve]=n.useState(null),[St,q]=n.useState(null),ie=n.useRef(null),ce=()=>{ie.current&&(clearTimeout(ie.current),ie.current=null)};n.useEffect(()=>ce,[]);const Ks=s=>{ce(),ie.current=setTimeout(()=>{ie.current=null,os(s)},600)},Be=s=>{const t=$;Ve(null),q(null),ce(),t&&setTimeout(()=>void ct(t,s),0)};return e.jsxs(e.Fragment,{children:[e.jsxs(Js,{children:[e.jsx(Xs,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Zs,{className:"text-lg",children:"Documents"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 w-full",children:[e.jsxs("div",{className:"relative flex-1 min-w-[12rem] sm:flex-none sm:w-80",children:[e.jsx(ea,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none"}),e.jsx(Ie,{placeholder:"Search title, tags, content…",value:o.search,onChange:s=>C("search",s.target.value),className:"pl-9 pr-12 w-full h-8"}),e.jsx("kbd",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground border rounded px-1 pointer-events-none",title:"Quick open",children:"⌘K"})]}),Fe&&e.jsxs(ee,{value:o.status,onValueChange:s=>C("status",s),children:[e.jsx(te,{className:"w-[140px] h-8",children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(f,{value:"all",children:"All Status"}),Object.entries(Qt).map(([s,t])=>e.jsx(f,{value:s,children:t},s))]})]}),Nt.length>1&&e.jsxs(ee,{value:o.type,onValueChange:s=>C("type",s),children:[e.jsx(te,{className:"w-[130px] h-8",title:"Filter by type",children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(f,{value:"all",children:"All types"}),Nt.map(s=>e.jsx(f,{value:s,children:Yt[s]??s},s))]})]}),bt.length>1&&e.jsxs(ee,{value:o.author,onValueChange:s=>C("author",s),children:[e.jsx(te,{className:"w-[150px] h-8",title:"Filter by author",children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(f,{value:"all",children:"All authors"}),bt.map(s=>e.jsx(f,{value:s,children:s},s))]})]}),e.jsxs(ee,{value:o.datePreset,onValueChange:s=>C("datePreset",s),children:[e.jsx(te,{className:"w-[140px] h-8",title:"Filter by last edited",children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(f,{value:"any",children:"Any time"}),Object.entries(Jt).map(([s,t])=>e.jsx(f,{value:s,children:t},s))]})]}),e.jsxs(ee,{value:Ne,onValueChange:s=>Vs(s),children:[e.jsx(te,{className:"w-[150px] h-8",title:"Sort documents",children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(f,{value:"activity",children:"Recent activity"}),e.jsx(f,{value:"name",children:"Name (A–Z)"}),e.jsx(f,{value:"edited",children:"Recently edited"}),e.jsx(f,{value:"comments",children:"Most comments"})]})]}),e.jsxs("div",{className:"flex items-center rounded-md border h-8",children:[e.jsx("button",{type:"button",title:"List view","aria-pressed":B==="list",className:`px-2 h-full rounded-l-md ${B==="list"?"bg-muted":"hover:bg-muted/50"}`,onClick:()=>gt("list"),children:e.jsx(Da,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",title:"Card view","aria-pressed":B==="cards",className:`px-2 h-full rounded-r-md ${B==="cards"?"bg-muted":"hover:bg-muted/50"}`,onClick:()=>gt("cards"),children:e.jsx(ta,{className:"h-4 w-4"})})]})]})]})}),e.jsxs(sa,{children:[D!==null&&e.jsxs("div",{className:"flex items-center flex-wrap gap-1 mb-3 text-sm",children:[e.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:()=>T(null),children:"All documents"}),D.split("/").map((s,t,r)=>{const d=r.slice(0,t+1).join("/"),x=t===r.length-1;return e.jsxs(n.Fragment,{children:[e.jsx(Rt,{className:"h-3.5 w-3.5 text-muted-foreground/50"}),x?e.jsxs("span",{className:"font-medium flex items-center gap-1",children:[e.jsx(Vt,{className:"h-4 w-4 text-blue-500"}),We(s)]}):e.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:()=>T(d),children:We(s)})]},d)}),e.jsx(Ye,{variant:"secondary",className:"ml-1 text-[10px] px-1.5 py-0 h-5",children:ne.length}),he&&e.jsxs(j,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs text-muted-foreground ml-1",onClick:()=>A("new",{folder:D}),title:"New document in this folder",children:[e.jsx(Bt,{className:"h-3.5 w-3.5 mr-1"})," New here"]})]}),we.length>0&&e.jsxs("div",{className:"flex items-center flex-wrap gap-1.5 mb-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Saved:"}),we.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border px-2 py-0.5 hover:bg-muted",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1",onClick:()=>Os(s),title:`Apply saved filter "${s.name}"`,children:[e.jsx(Ge,{className:"h-3 w-3 text-amber-500"}),s.name]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>ft(Ja(we,s.name)),title:`Delete saved filter "${s.name}"`,children:e.jsx(de,{className:"h-3 w-3"})})]},s.name))]}),O&&e.jsxs("div",{className:"flex items-center flex-wrap gap-1.5 mb-3 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Active filters:"}),J.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-muted px-2 py-0.5",children:[s.label,e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:s.clear,title:"Remove this filter",children:e.jsx(de,{className:"h-3 w-3"})})]},s.label)),o.tags.length>0&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-muted px-2 py-0.5",children:["Tags: ",o.tags.join(", "),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>C("tags",[]),title:"Remove tag filters",children:e.jsx(de,{className:"h-3 w-3"})})]}),e.jsxs(j,{variant:"outline",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>Ce(!0),children:[e.jsx(Ge,{className:"h-3 w-3 mr-1"}),"Save filter"]}),e.jsx(j,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs text-muted-foreground",onClick:Ws,children:"Clear all"})]}),Se.length>0&&e.jsxs("div",{className:"flex items-center flex-wrap gap-1.5 mb-3 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Tags:"}),Se.slice(0,14).map(({tag:s,count:t})=>{const r=o.tags.includes(s);return e.jsxs("button",{type:"button",className:`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 transition-colors ${r?"bg-primary text-primary-foreground border-primary":"text-foreground/80 hover:bg-muted"}`,onClick:()=>xt(s),title:r?`Remove filter ${s}`:`Filter by ${s}`,children:[s,e.jsx("span",{className:r?"text-primary-foreground/80":"text-muted-foreground",children:r?"×":t})]},s)}),Se.length>14&&e.jsxs("span",{className:"text-muted-foreground",children:["+",Se.length-14," more"]}),o.tags.length>0&&e.jsx("button",{type:"button",className:"text-muted-foreground hover:underline ml-1",onClick:()=>C("tags",[]),children:"clear"})]}),Ct.length>0&&e.jsxs("div",{className:"flex items-center flex-wrap gap-1.5 mb-3 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Recently edited:"}),Ct.map(s=>e.jsxs("button",{type:"button",className:`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 hover:bg-muted truncate max-w-[180px] ${s.type==="artifact"?"border-amber-300 text-amber-700 dark:text-amber-300":"text-primary"}`,onClick:()=>A(s.id),children:[s.type==="artifact"&&e.jsx(Ea,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:s.title})]},s.id))]}),h||me.has(k)?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Ke,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):Is?O||!he?e.jsx("div",{className:"text-center py-8 text-sm text-muted-foreground",children:O?"No matching documents":"No documents yet"}):e.jsxs("button",{type:"button",onClick:()=>{var s;return(s=ys.current)==null?void 0:s.click()},className:"w-full flex flex-col items-center gap-2 rounded-lg border-2 border-dashed border-border py-10 text-muted-foreground hover:border-primary hover:text-primary transition-colors",children:[e.jsx(Ta,{className:"h-7 w-7"}),e.jsx("div",{className:"text-sm font-medium",children:"Drag files here, or click to import"}),e.jsx("div",{className:"text-xs",children:".md → document · .html → hosted artifact"})]}):(()=>{const s=(t,r=0)=>{var Lt,At;const d=B==="cards",x=t.type||"document",y=Ra(x),L=Fe&&t.status==="draft"&&ye(t),c=$s.has(t.id)?!0:t.status==="pending_review"&&ps(t)&&(ht.get(t.id)!==le||Xe&&us),N=t.status!=="pending_review"&&ye(t),X=!!t.author&&!!le&&t.author.toLowerCase()===le,Z=g||X,z=Me.get(t.id),$t=(z==null?void 0:z.status)==="pending",Mt=!tt&&(Z||ye(t))&&(Z||!$t),Pt=()=>Z?at(t):st(t),Oe=ye(t)&&Ca(x)&&(t.status!=="pending_review"||Xe||is||cs.includes("admin")||hs(t,"reviewer")),_t=()=>{dt(S(t.id)),ve(null),ge(t)},qe=()=>!d&&!!$&&$!==t.id&&S($)!==S(t.id),Us=e.jsx("div",{onClick:p=>p.stopPropagation(),children:e.jsxs(pa,{modal:!1,children:[e.jsx(xa,{asChild:!0,children:e.jsx(j,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 flex-shrink-0",title:"Actions",children:e.jsx($a,{className:"h-4 w-4"})})}),e.jsxs(ga,{align:"end",className:"min-w-40",children:[N&&e.jsxs(I,{onSelect:()=>A(t.id),children:[e.jsx(Wt,{className:"h-3.5 w-3.5 mr-2"}),"Edit"]}),Oe&&e.jsxs(I,{onSelect:_t,children:[e.jsx(De,{className:"h-3.5 w-3.5 mr-2"}),"Move to folder"]}),L&&e.jsxs(I,{onSelect:()=>xe(t),children:[e.jsx(es,{className:"h-3.5 w-3.5 mr-2"}),"Submit for review"]}),c&&e.jsxs(I,{onSelect:()=>Ze(t),children:[e.jsx(Je,{className:"h-3.5 w-3.5 mr-2"}),"Review"]}),e.jsxs(I,{onSelect:()=>je(t),children:[e.jsx(Ut,{className:"h-3.5 w-3.5 mr-2"}),"History"]}),g&&e.jsxs(I,{onSelect:()=>nt(t),children:[e.jsx(Zt,{className:"h-3.5 w-3.5 mr-2"}),"Publish"]}),e.jsx(fa,{}),Mt&&e.jsxs(I,{onSelect:Pt,className:Z?"text-destructive focus:text-destructive":void 0,children:[e.jsx(ue,{className:"h-3.5 w-3.5 mr-2"}),"Delete"]})]})]})});return e.jsxs("div",{onClick:()=>A(t.id),className:`${d?"flex flex-col gap-2":"flex items-center gap-3"} p-3 rounded-lg border hover:bg-muted/50 transition-colors group cursor-pointer ${$===t.id?"opacity-40":""}`,style:!d&&r?{marginLeft:`${r*1.25}rem`}:void 0,draggable:!d&&Oe,onDragStart:p=>{p.dataTransfer.setData("text/plain",t.id),p.dataTransfer.effectAllowed="move",Ve(t.id)},onDragEnd:()=>{Ve(null),q(null),ce()},onDragOver:p=>{qe()&&(p.preventDefault(),p.dataTransfer.dropEffect="move")},onDragEnter:()=>{qe()&&q(S(t.id))},onDrop:p=>{qe()&&(p.preventDefault(),p.stopPropagation(),Be(S(t.id)))},"data-testid":`document-row-${t.id}`,children:[!d&&e.jsx(Xt,{type:t.type,className:"h-5 w-5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d&&e.jsx(Xt,{type:t.type,className:"h-4 w-4"}),e.jsx("span",{className:"font-medium truncate min-w-0",title:t.title,children:t.title}),y&&e.jsx("span",{className:`shrink-0 rounded px-1.5 py-px text-[10px] font-semibold uppercase tracking-wide ${y.cls}`,title:y.title,children:y.label}),e.jsx(qa,{status:t.status||"draft",size:"sm",className:"shrink-0 whitespace-nowrap"}),Fe&&ia(t,ms)&&e.jsxs("span",{className:"shrink-0 inline-flex items-center gap-1 rounded px-1.5 py-px text-[10px] font-semibold uppercase tracking-wide border bg-amber-50 text-amber-700 border-amber-200 dark:bg-amber-500/10 dark:text-amber-400 dark:border-amber-500/30",title:typeof t.prime=="boolean"?"Prime: flagged on this document. Always requires steward approval.":"Prime: inherited from a prime tag. Always requires steward approval.","data-testid":`prime-badge-${t.id}`,children:[e.jsx(Ge,{className:"h-3 w-3"}),"Prime"]}),$t&&(()=>{const p=z.requestedBy.toLowerCase()===le;return e.jsxs("span",{className:`shrink-0 inline-flex items-center gap-1 rounded px-1.5 py-px text-[10px] font-semibold uppercase tracking-wide border bg-red-50 text-red-700 border-red-200 ${p?"cursor-pointer hover:bg-red-100":""}`,title:p?"Click to withdraw your deletion request":`${z.requestedBy} asked for this to be deleted: "${z.reason}". A nest admin decides.`,"data-testid":`deletion-flag-${t.id}`,onClick:p?ze=>{ze.stopPropagation(),et(z)}:void 0,children:[e.jsx(ue,{className:"h-3 w-3"}),"Deletion requested",p&&e.jsx(de,{className:"h-3 w-3 ml-0.5"})]})})(),d&&e.jsx("div",{className:"ml-auto",children:Us})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mt-1",children:[e.jsxs("span",{children:["v",t.version||1]}),((Lt=t.tags)==null?void 0:Lt.length)>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("span",{className:"flex items-center gap-1 truncate",children:t.tags.slice(0,3).map(p=>e.jsx("button",{type:"button",title:o.tags.includes(p)?`Remove filter ${p}`:`Filter by ${p}`,className:`rounded-full border px-1.5 py-px transition-colors ${o.tags.includes(p)?"bg-primary text-primary-foreground border-primary":"hover:bg-muted"}`,onClick:ze=>{ze.stopPropagation(),xt(p)},children:p},p))})]}),(t.author||((At=t.collaborators)==null?void 0:At.length)>0)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx(Sa,{author:t.author,collaborators:t.collaborators})]})]})]}),!d&&e.jsxs("div",{className:"flex items-center gap-1 transition-opacity opacity-0 group-hover:opacity-100",onClick:p=>p.stopPropagation(),children:[L&&e.jsxs(j,{variant:"outline",size:"sm",onClick:()=>xe(t),children:[e.jsx(es,{className:"h-3.5 w-3.5 mr-1"}),"Submit"]}),c&&e.jsx(j,{variant:"outline",size:"sm",onClick:()=>Ze(t),className:"border-green-200 text-green-700 hover:bg-green-50",children:"Review"}),N&&e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>A(t.id),title:"Edit",children:e.jsx(Wt,{className:"h-3.5 w-3.5"})}),Oe&&e.jsx(j,{variant:"ghost",size:"sm",onClick:_t,title:"Move to folder","data-testid":`move-node-${t.id}`,children:e.jsx(De,{className:"h-3.5 w-3.5"})}),e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>je(t),title:"History",children:e.jsx(Ut,{className:"h-3.5 w-3.5"})}),Mt&&e.jsx(j,{variant:"ghost",size:"sm",onClick:Pt,title:Z?"Delete":"Delete (needs admin approval)","data-testid":`delete-node-${t.id}`,className:Z?"text-destructive hover:text-destructive hover:bg-destructive/10":void 0,children:e.jsx(ue,{className:"h-3.5 w-3.5"})})]})]},t.id)};return B==="cards"?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2",children:Y.map(t=>s(t))}):e.jsxs("div",{className:"space-y-1",children:[$&&S($)!==k&&e.jsxs("div",{className:`flex items-center gap-2 rounded-md border-2 border-dashed px-3 py-2 text-sm ${St===k?"border-primary bg-primary/10 text-primary":"border-border text-muted-foreground"}`,onDragOver:t=>{t.preventDefault(),t.dataTransfer.dropEffect="move"},onDragEnter:()=>q(k),onDragLeave:()=>q(t=>t===k?null:t),onDrop:t=>{t.preventDefault(),Be(k)},children:[e.jsx(De,{className:"h-4 w-4"}),"Move to ",k?H(k):"nest root"]}),e.jsx(aa,{className:"space-y-1",groups:Hs,baseFolder:k,known:O?void 0:w,isCollapsed:t=>O?!1:!re.has(t),renderFolder:(t,{collapsed:r})=>{const d=!!$&&S($)!==t.path,x=d&&St===t.path,y=t.total>0,L=me.has(t.path);return e.jsxs("div",{className:`group/fh flex items-center gap-1.5 py-1.5 px-2 rounded-md select-none transition-colors ${y?"cursor-pointer":""} ${x?"bg-primary/10 ring-1 ring-primary":"hover:bg-muted/50"}`,onClick:y?()=>Te(t.path):void 0,onDragOver:c=>{d&&(c.preventDefault(),c.dataTransfer.dropEffect="move")},onDragEnter:c=>{c.currentTarget.contains(c.relatedTarget)||($&&y&&r&&Ks(t.path),d&&q(t.path))},onDragLeave:c=>{c.currentTarget.contains(c.relatedTarget)||(q(N=>N===t.path?null:N),ce())},onDrop:c=>{d&&(c.preventDefault(),Be(t.path))},"data-testid":`folder-header-${t.path}`,children:[L?e.jsx(Ke,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}):y?e.jsx(Rt,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${r?"":"rotate-90"}`}):e.jsx("span",{className:"h-3.5 w-3.5 shrink-0"}),e.jsx(Vt,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium",children:t.label}),t.total>0&&e.jsx(Ye,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-5",title:t.count!==t.total?`${t.count} here · ${t.total} in this folder`:void 0,children:t.total}),he&&e.jsx("button",{type:"button",className:"ml-1 rounded p-0.5 text-muted-foreground opacity-0 group-hover/fh:opacity-100 hover:text-primary hover:bg-primary/10",title:`New document in ${H(t.path)}`,onClick:c=>{c.stopPropagation(),A("new",{folder:t.path})},children:e.jsx(Bt,{className:"h-3.5 w-3.5"})}),g&&e.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground opacity-0 group-hover/fh:opacity-100 hover:text-primary hover:bg-primary/10",title:`Share ${H(t.path)} with someone`,"data-testid":`share-folder-${t.path}`,onClick:c=>{c.stopPropagation(),lt({path:Ts(t.path),label:t.label||We(t.name)})},children:e.jsx(Zt,{className:"h-3.5 w-3.5"})}),(g||he)&&(g||!ot(t.path))&&e.jsx("button",{type:"button",className:`rounded p-0.5 ${t.total===0?"":"opacity-0"} group-hover/fh:opacity-100 focus-visible:opacity-100 ${g?"text-muted-foreground hover:text-destructive hover:bg-destructive/10":"text-muted-foreground hover:text-primary hover:bg-primary/10"}`,title:g?`Delete ${H(t.path)} and everything in it`:"Delete (needs admin approval)","data-testid":`delete-folder-${t.path}`,onClick:c=>{c.stopPropagation(),rt({path:t.path,label:H(t.path),total:t.total})},children:e.jsx(ue,{className:"h-3.5 w-3.5"})}),ot(t.path)&&(()=>{const c=Ss.get(t.path),N=(c==null?void 0:c.requestedBy.toLowerCase())===le;return e.jsxs("span",{className:`inline-flex items-center gap-1 rounded px-1.5 py-px text-[10px] font-semibold uppercase tracking-wide bg-red-50 text-red-700 border border-red-200 ${N?"cursor-pointer hover:bg-red-100":""}`,title:N?"Click to withdraw your deletion request":"Someone asked for this folder to be deleted. A nest admin decides.",onClick:N&&c?X=>{X.stopPropagation(),et(c)}:void 0,children:[e.jsx(ue,{className:"h-3 w-3"}),"Deletion requested",N&&e.jsx(de,{className:"h-3 w-3 ml-0.5"})]})})()]})},renderDoc:t=>s(t,0)})]})})(),!v&&fs.total>0&&e.jsxs("details",{className:"mt-4 text-xs text-muted-foreground",onToggle:s=>{s.currentTarget.open&&Le()},children:[e.jsx("summary",{className:"cursor-pointer select-none",children:Rs?"Link health: checking the whole nest…":Q?`Link health: ${F.broken.length} broken link${F.broken.length!==1?"s":""} · ${F.orphans.length} orphan doc${F.orphans.length!==1?"s":""}`:"Link health — check the whole nest"}),e.jsxs("div",{className:"mt-2 space-y-2 pl-1",children:[Q&&F.broken.length===0&&F.orphans.length===0&&e.jsx("div",{children:"No broken links or orphan documents."}),F.broken.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"font-medium mb-1",children:"Broken links (target doesn't exist):"}),F.broken.slice(0,10).map((s,t)=>e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:()=>A(s.sourceId),children:s.sourceTitle})," ","→ [[",s.target,"]]"]},t))]}),F.orphans.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"font-medium mb-1",children:"Orphans (nothing links to them):"}),e.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-1",children:F.orphans.slice(0,15).map(s=>e.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:()=>A(s.id),children:s.title},s.id))})]})]})]})]})]}),e.jsx(Ot,{open:Bs,onOpenChange:Ce,children:e.jsxs(qt,{className:"max-w-md",children:[e.jsx(zt,{children:e.jsx(Ht,{children:"Save this filter"})}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Saved filters remember your current search, tags, status, author and date range. Pick one from the ",e.jsx("strong",{children:"Saved"})," row to re-apply the whole set in one click — handy for views you return to, like “My drafts” or “Edited this week”."]}),e.jsx(Ie,{autoFocus:!0,placeholder:"Filter name (e.g. My drafts)",value:Re,onChange:s=>vt(s.target.value),onKeyDown:s=>{s.key==="Enter"&&yt()}}),e.jsxs(It,{children:[e.jsx(j,{variant:"ghost",onClick:()=>Ce(!1),children:"Cancel"}),e.jsx(j,{onClick:yt,disabled:!Re.trim(),children:"Save filter"})]})]})}),$e&&e.jsx(ja,{nestId:a,targetType:"folder",target:$e.path,label:$e.label,onClose:()=>lt(null)}),e.jsx(Ot,{open:!!R,onOpenChange:s=>{!s&&!fe&&ge(null)},children:e.jsxs(qt,{className:"max-w-md",children:[e.jsx(zt,{children:e.jsx(Ht,{children:"Move to folder"})}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Move ",e.jsx("strong",{children:R==null?void 0:R.title})," to another folder. Version history, review state, and [[wiki links]] follow the document."]}),e.jsxs(ee,{value:G!==null?"__new__":Pe===""?"__root__":Pe,onValueChange:s=>{if(s==="__new__"){ve("");return}ve(null),dt(s==="__root__"?"":s)},children:[e.jsx(te,{"data-testid":"move-folder-select",children:e.jsx(se,{placeholder:"Choose a folder"})}),e.jsxs(ae,{children:[e.jsx(f,{value:"__root__",children:"Nest root"}),Fs.map(s=>e.jsx(f,{value:s,children:H(s)},s)),e.jsx(ra,{}),e.jsx(f,{value:"__new__",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Fa,{className:"h-3.5 w-3.5"}),"New folder…"]})})]})]}),G!==null&&e.jsxs(e.Fragment,{children:[e.jsx(Ie,{autoFocus:!0,value:G,onChange:s=>ve(s.target.value),placeholder:"e.g. gtm/deals",className:"font-mono","data-testid":"move-folder-new-path"}),V.error?e.jsx("p",{className:"text-xs text-destructive",children:V.error}):V.rewritten&&V.path?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Will be created as"," ",e.jsx("code",{className:"font-mono",children:V.path})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"The folder is created by the move — nest it with a slash."})]}),e.jsxs(It,{children:[e.jsx(j,{variant:"ghost",disabled:fe,onClick:()=>ge(null),children:"Cancel"}),e.jsxs(j,{disabled:fe||!R||S(R.id)===mt||G!==null&&(!V.path||!!V.error),onClick:async()=>{if(!R)return;ut(!0);const s=await ct(R.id,mt);ut(!1),s&&ge(null)},"data-testid":"move-folder-confirm",children:[fe?e.jsx(Ke,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(De,{className:"h-4 w-4 mr-2"}),"Move"]})]})]})}),P&&e.jsx(Ma,{isOpen:!!P,onClose:()=>xe(null),documentTitle:P.title,currentVersion:P.version||1,onSubmit:Ms}),pe&&e.jsx(ba,{nestId:a,nodeId:pe.id,nodeTitle:pe.title||pe.id,onClose:()=>nt(null)}),M&&e.jsx(Ue,{open:!0,onOpenChange:s=>!s&&rt(null),title:g?`Delete "${M.label}"?`:`Request deletion of "${M.label}"`,description:M.total===0?g?"This folder is empty — deleting it just removes it from the tree.":"A nest admin reviews this. The folder is empty, so nothing else is removed.":g?`This deletes all ${M.total} document${M.total===1?"":"s"} in this folder and its subfolders, with their history, comments and annotations. It cannot be undone.`:`A nest admin reviews this. Honouring it deletes all ${M.total} document${M.total===1?"":"s"} in this folder. Nothing is removed yet.`,label:g?void 0:"Why should it be deleted?",placeholder:"e.g. superseded by the new API docs",confirmLabel:g?"Delete folder":"Request deletion",destructive:g,onConfirm:Ls}),U&&e.jsx(Ue,{open:!0,onOpenChange:s=>!s&&at(null),title:`Delete "${U.title}"?`,description:"This removes the document, its version history, comments and annotations. It cannot be undone.",warning:Na(ws),confirmLabel:"Delete document",destructive:!0,onConfirm:Ps}),oe&&e.jsx(Ue,{open:!0,onOpenChange:s=>!s&&st(null),title:`Request deletion of "${oe.title}"`,description:"A nest admin reviews this and either deletes the document or rejects with a note. Nothing is removed yet.",label:"Why should it be deleted?",placeholder:"e.g. superseded by the new runbook",confirmLabel:"Request deletion",priorDecline:((Ft=Me.get(oe.id))==null?void 0:Ft.status)==="declined"?Me.get(oe.id):null,onConfirm:_s}),_&&e.jsx(wa,{open:!0,onClose:()=>it(null),title:_.title,versionData:ks,onLoadContent:async s=>(await na(a,_.id,s)).content,onRestore:async s=>{if(_)try{await oa(a,_.id,s),b.success(`Reverted to version ${s}`),await je(_),E()}catch(t){b.error((t==null?void 0:t.message)||"Revert failed")}},onDiscard:async()=>{if(_)try{const{version:s}=await la(a,_.id);b.success(`Draft discarded — back to version ${s}`),await je(_),E()}catch(s){b.error((s==null?void 0:s.message)||"Discard failed")}}})]})}export{Fr as DocumentsTab};
@@ -0,0 +1 @@
1
+ import{u as j,r as g,j as e,b_ as N,b$ as E,c1 as v,c0 as C,B as w,L as o,R as b,c2 as y,e as k,f as _,Y as F,l as T,ee as B,ac as L}from"./index-WYDmEOfO.js";import{F as d}from"./file-exclamation-point-BevGZgtj.js";import{C as Q}from"./circle-check-Bw_aTXiH.js";import{C as R}from"./NestView-EW-sraEb.js";import"./MarkdownEditor-CKh4WSn-.js";import"./zap-D2ifcnYb.js";import"./index-BOVYgMvj.js";import"./arrow-left-CWIsv-sG.js";import"./trash-2-B0HyPTnI.js";import"./x-mNtADYHc.js";import"./chevron-left-CK_ZPFm9.js";import"./alert-dialog-BvF3NFr7.js";import"./NestPageHeader-Cizo8nUi.js";import"./count-skeleton-DToLM74B.js";import"./folder-input-m8UBV4fA.js";import"./PersonCombobox-BKI7dff4.js";import"./tag-DeYC_mRv.js";import"./user-plus-Ckm_Isyc.js";import"./ReviewActions-CS8JXgXF.js";import"./circle-x-DkIG68H7.js";import"./settings-DKX0Q4gO.js";function S(t,a=!0){return F({...T.externalEdits(t),enabled:a})}function te({nestId:t,enabled:a,onOpenDocument:m,titleOf:x}){var l;const p=j(),i=S(t,a),r=((l=i.data)==null?void 0:l.entries)??[],[u,n]=g.useState(!1),h=async()=>{n(!0);try{await B(t).catch(s=>(console.error("[ExternalEditsTab] scanExternalEdits failed",t,s),null)),await p.invalidateQueries({queryKey:L.externalEdits(t)})}finally{n(!1)}},c=u||i.isFetching;return e.jsxs(N,{children:[e.jsx(E,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(v,{className:"text-lg flex items-center gap-2",children:[e.jsx(d,{className:"h-4 w-4 text-orange-600"}),"External Edits"]}),e.jsx(C,{children:"Files edited directly on disk, awaiting your approval."})]}),e.jsx(w,{variant:"ghost",size:"icon",onClick:h,disabled:c,className:"h-8 w-8","data-testid":"external-edits-refresh",children:c?e.jsx(o,{className:"h-4 w-4 animate-spin"}):e.jsx(b,{className:"h-4 w-4"})})]})}),e.jsx(y,{children:i.isLoading?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(o,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):r.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Q,{className:"h-10 w-10 text-green-500 mb-3"}),e.jsx("p",{className:"text-sm font-medium",children:"No pending external edits"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"All files on disk match their last approved state."})]}):e.jsx("div",{className:"space-y-2",children:r.map(s=>{const f=x(s.document_id)||s.document_id.split("/").pop();return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border hover:bg-muted/50 cursor-pointer transition-colors",onClick:()=>m(s.document_id),"data-testid":`external-edit-row-${s.suggestion_id}`,children:[e.jsx(d,{className:"h-5 w-5 text-orange-600 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate",children:f}),e.jsx(k,{variant:"secondary",className:"text-[10px] px-1.5 py-0 bg-orange-100 text-orange-700",children:s.source})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mt-1",children:[e.jsx(R,{className:"h-3 w-3"}),e.jsx("span",{children:_(s.detected_at)}),e.jsx("span",{children:"•"}),e.jsxs("span",{children:["by ",s.actor]})]})]})]},s.suggestion_id)})})})]})}export{te as ExternalEditsTab,S as useExternalEdits};