1import{o as qe,r as Oe}from"./rolldown-runtime-BNNRdYrd.js";import{b as Ue,r as Ve}from"./react-vendor-BqQF_9sx.js";import{t as Ke}from"./activity-DQtLE5Oy.js";import{n as Fe,t as We}from"./message-square-plus-BVwzhj9c.js";import{t as we}from"./bookmark-CDPCxjmx.js";import{t as de}from"./circle-check-DnG-FWXS.js";import{t as Je}from"./clock-3-DnV2tYUU.js";import{t as Ye}from"./file-exclamation-point-PCuloQTv.js";import{t as He}from"./git-branch-Co3Od1SO.js";import{t as Ge}from"./link-2-BMM81MrN.js";import{t as Qe}from"./list-tree-BaLxgvqI.js";import{t as Xe}from"./message-square-text-ClE_ZpzB.js";import{t as Ze}from"./pause-j99UWzYo.js";import{t as et}from"./pin-BztDI4mx.js";import{t as be}from"./play-BcIyVBhO.js";import{t as ke}from"./plus-C2wgNVCw.js";import{t as tt}from"./rotate-ccw-clock-CD7vCvcS.js";import{t as at}from"./rotate-ccw-DMz9bzj3.js";import{t as Ne}from"./save-DmK8ZpsA.js";import{t as st}from"./sliders-horizontal-CoOEoS-G.js";import{t as rt}from"./square-D53yantK.js";import{t as nt}from"./tags-CVudHV0A.js";import{t as Se}from"./trash-Dc9VhwyJ.js";import{t as it}from"./triangle-alert-DLjvSumf.js";import{t as lt}from"./users-Dg8w5wT0.js";import{t as ot}from"./volume-2-Bt2XfctO.js";import{s as ct,u as dt}from"./plan-entitlements-D-LMrELD.js";import{Dt as pt,Ft as ut,Ht as Ce,It as pe,Lt as xt,Y as Q}from"./index-BQuIkJiK.js";import{i as mt,l as bt,n as he,t as ht}from"./note-trust-Y3C29qxz.js";import{r as ft,t as gt}from"./semantic-links-BmhOhVmH.js";import{h as yt,r as U}from"./db-Dgd9zlNH.js";import{a as vt,g as jt,h as wt,i as kt,n as G,t as Nt}from"./metadata-sync-BmUSMven.js";import"./AuthContext-DMnfLAt3.js";import{t as St}from"./CelebratorySuccess-F94Vs5ss.js";import{t as fe}from"./ContextualHelpTooltip-AM2aubqn.js";import{t as Ct}from"./FeedbackDialog-UYDzWNCa.js";import{t as $t}from"./note-search-DHyAoanw.js";import{l as It,n as Tt,u as le}from"./trust-ledger-w7gz1vFb.js";import{n as Pt,r as _t,t as Rt}from"./noteOutline-BxqXRUzS.js";import{n as M}from"./workspace-permissions-DneGli5K.js";import{n as Mt,t as At}from"./metadata-indexer-CRp5uNlr.js";import{n as Bt}from"./vault-storage-BuQgWwNV.js";import{a as Dt,c as Et,i as Lt,l as zt,n as qt,r as Ot,s as Ut,t as Vt,u as Kt}from"./blueprints-C0RCLNxU.js";import{t as Ft}from"./ContextualActionBar-0rYL1GVR.js";var $e={name:"braces",size:24,node:[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],aliases:["curly-braces"]};$e.node;var ce=Ce($e),Ie={name:"panel-right-close",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]]};Ie.node;var Wt=Ce(Ie),c=qe(Ue(),1),Jt="/api/collaboration";async function A(t,s={}){const r=await fetch(`${Jt}${t}`,{credentials:"include",...s,headers:{"Content-Type":"application/json",...s.headers||{}}}),n=r.status===204?{}:await r.json().catch(()=>({}));if(!r.ok)throw new Error(n.error||"Collaboration request failed.");return n}function ee(t){const s=new URLSearchParams;return Object.entries(t).forEach(([r,n])=>{n!==""&&n!==void 0&&n!==null&&s.set(r,String(n))}),s.toString()}function Te(t="collaboration"){return`${t}:${globalThis.crypto?.randomUUID?.()||`${Date.now()}-${Math.random().toString(36).slice(2)}`}`}async function Yt({workspaceId:t,notePath:s,status:r="",limit:n=100}){return A(`/threads?${ee({workspaceId:t,notePath:s,status:r,limit:n})}`)}async function Ht(t){const s=t.idempotencyKey||Te("thread");return A("/threads",{method:"POST",headers:{"Idempotency-Key":s},body:JSON.stringify({...t,idempotencyKey:s})})}async function Gt(t,s){const r=s.idempotencyKey||Te("comment");return A(`/threads/${encodeURIComponent(t)}/comments`,{method:"POST",headers:{"Idempotency-Key":r},body:JSON.stringify({...s,idempotencyKey:r})})}async function Qt(t,s){return A(`/threads/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(s)})}async function Xt({workspaceId:t,unreadOnly:s=!1,limit:r=100}){return A(`/mentions?${ee({workspaceId:t,unreadOnly:s,limit:r})}`)}async function Zt(t,s){return A(`/mentions/${encodeURIComponent(t)}/read`,{method:"POST",body:JSON.stringify({workspaceId:s})})}async function ea({workspaceId:t,notePath:s="",since:r=0,limit:n=100}){return A(`/activity?${ee({workspaceId:t,notePath:s,since:r,limit:n})}`)}async function ta({workspaceId:t}){return A(`/blocks?${ee({workspaceId:t})}`)}async function aa(t,s){return A(`/blocks/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify({workspaceId:s})})}
1async function sa(t,s){return A(`/blocks/${encodeURIComponent(t)}`,{method:"DELETE",body:JSON.stringify({workspaceId:s})})}async function ra(t){const s=await fetch(`/api/workspaces/${encodeURIComponent(t)}/members`,{credentials:"include"}),r=await s.json().catch(()=>({}));if(!s.ok)throw new Error(r.error||"Unable to load workspace members.");return r}function Pe(t=[],s=""){const r=t.findIndex(u=>u.id===s);if(r<0)return[];const n=t[r],b=[n.text];let i=n.level;for(let u=r-1;u>=0&&i>1;u-=1){const l=t[u];l.level<i&&(b.unshift(l.text),i=l.level)}return b}function na(t="",s=[],r=""){const n=s.findIndex(u=>u.id===r);if(n<0)return"";const b=s[n],i=s.slice(n+1).find(u=>u.level<=b.level);return String(t).split(/\r?\n/).slice(b.line-1,i?i.line-1:void 0).join(` 2`).trim()}function _e(t="",s=""){const r=String(s||"").trim().replace(/^\^/,"");if(!r)return"";const n=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),b=new RegExp(`(?:^|\\s)\\^${n}(?:\\s|$)`),i=String(t).split(/\r?\n/),u=i.findIndex(x=>b.test(x));if(u<0)return"";if(i[u].replace(b," ").trim())return i[u].trim();let l=u-1;for(;l>=0&&i[l].trim()&&!/^#{1,6}\s/.test(i[l]);)l-=1;return i.slice(l+1,u+1).join(` 3`).trim()}async function Re({notePath:t,noteContent:s="",outline:r=[],headingId:n="",blockId:b=""}){const i=String(b||"").trim().replace(/^\^/,""),u=Pe(r,n),l=i?"block":u.length?"heading":"note",x=i?_e(s,i):u.length?na(s,r,n):String(s);if(i&&!x)throw new Error(`Portable block ^${i} was not found in this note.`);const p=x.slice(0,1e3),h=await bt({path:t,type:l,blockId:i||null,headingPath:u,content:x});return{blockId:i||void 0,headingPath:u,quote:p,fingerprint:h}}async function ia({anchor:t,noteContent:s="",outline:r=[]}){if(!t)return"";let n="";if(t.headingPath?.length){const b=t.headingPath.at(-1);if(n=r.find(i=>i.text===b&&Pe(r,i.id).join("�")===t.headingPath.join("�"))?.id||"",!n)return""}return t.blockId&&!_e(s,t.blockId)?"":(await Re({notePath:t.path,noteContent:s,outline:r,headingId:n,blockId:t.blockId||""})).fingerprint}var e=Ve(),z="w-full rounded-lg border border-white/10 bg-basalt-950 px-2.5 py-2 text-[10px] text-white outline-none focus:border-cyan-300/40",X="rounded-lg border border-white/10 px-2 py-1.5 text-[9px] text-basalt-300 hover:text-white disabled:opacity-40";function ge({userId:t,name:s,threadId:r,commentId:n,currentUserId:b,onReport:i,onBlock:u}){return!t||t===b?null:(0,e.jsxs)("div",{className:"mt-2 flex flex-wrap gap-2",children:[(0,e.jsx)("button",{type:"button",className:X,onClick:()=>i({userId:t,threadId:r,commentId:n}),children:"Report content or user"}),(0,e.jsx)("button",{type:"button",className:X,onClick:()=>u({user_id:t,name:s}),children:"Block user"})]})}function Z(t){return t.name||t.email||t.user_id}function Me({members:t,currentUserId:s,selected:r,onChange:n}){const b=t.filter(i=>i.user_id!==s);return b.length?(0,e.jsx)("div",{className:"flex flex-wrap gap-1.5",children:b.map(i=>{const u=r.includes(i.user_id);return(0,e.jsxs)("button",{type:"button",onClick:()=>n(u?r.filter(l=>l!==i.user_id):[...r,i.user_id]),className:`rounded-full border px-2 py-1 text-[8px] ${u?"border-cyan-300/30 bg-cyan-300/10 text-cyan-100":"border-white/[.07] text-basalt-500"}`,children:["@",Z(i)]},i.user_id)})}):(0,e.jsx)("p",{className:"text-[9px] text-basalt-600",children:"Invite teammates in Settings to mention them here."})}function la(t){return String(t||"").replaceAll("."," ").replaceAll("_"," ")}function oa({thread:t,workspaceId:s,members:r,currentUserId:n,onSaved:b}){const[i,u]=(0,c.useState)(""),[l,x]=(0,c.useState)([]),[p,h]=(0,c.useState)(""),y=async j=>{j.preventDefault(),h("Sendingâ¦");try{await Gt(t.id,{workspaceId:s,body:i,mentionUserIds:l.filter(C=>r.some(g=>g.user_id===C))}),u(""),x([]),h(""),await b()}catch(C){h(C.message)}};return(0,e.jsxs)("form",{onSubmit:y,className:"mt-3 border-t border-white/[.06] pt-3",children:[(0,e.jsx)("textarea",{required:!0,maxLength:5e3,rows:2,value:i,onChange:j=>u(j.target.value),placeholder:"Reply with durable contextâ¦",className:z}),(0,e.jsx)("div",{className:"mt-2",children:(0,e.jsx)(Me,{members:r,currentUserId:n,selected:l,onChange:x})}),(0,e.jsxs)("div",{className:"mt-2 flex items-center justify-between gap-2",children:[(0,e.jsx)("span",{className:"text-[8px] text-red-300","aria-live":"polite",children:p}),(0,e.jsx)("button",{className:"rounded-lg border border-cyan-300/20 px-2.5 py-1.5 text-[9px] font-semibold text-cyan-200",children:"Reply"})]})]})}function ca({thread:t,anchorState:s,workspaceId:r,members:n,currentUserId:b,onSaved:i,onReport:u,onBlock:l}){const[x,p]=(0,c.useState)(""),h=n.find(m=>m.user_id===b)?.role,y=M(h,"discussion.assign"),j=M(h,"discussion.comment"),C=y||M(h,"discussion.resolve-own")&&t.createdByUserId===b,g=M(h,"review.manage")||M(h,"review.complete-assigned")&&t.assigneeUserId===b,k=async m=>{p("Savingâ¦");try{await Qt(t.id,{workspaceId:r,...m}),p(""),await i()}catch(f){p(f.message)}},w=t.anchor.headingPath?.join(" ⺠")||t.anchor.blockId||"Whole note";return(0,e.jsxs)("article",{className:"rounded-xl border border-white/[.07] bg-black/20 p-3",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[(0,e.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[(0,e.jsx)("span",{className:`rounded-full border px-1.5 py-0.5 text-[7px] font-bold uppercase ${t.kind==="review"?"border-violet-300/20 text-violet-200":"border-cyan-300/20 text-cyan-200"}`,children:t.kind}),(0,e.jsx)("span",{className:"rounded-full border border-white/[.07] px-1.5 py-0.5 text-[7px] uppercase text-basalt-500",children:t.status}),t.kind==="review"?(0,e.jsx)("span",{className:"rounded-full border border-amber-300/15 px-1.5 py-0.5 text-[7px] uppercase text-amber-200",children:t.reviewState.replaceAll("_"," ")}
3):null,s!=="current"?(0,e.jsx)("span",{className:"rounded-full border border-red-300/20 bg-red-300/[.06] px-1.5 py-0.5 text-[7px] uppercase text-red-200",children:s==="missing"?"anchor missing":"anchor changed"}):null]}),(0,e.jsx)("h4",{className:"mt-2 truncate text-[11px] font-semibold text-basalt-100",children:t.subject}),(0,e.jsx)("p",{className:"mt-1 truncate font-mono text-[8px] text-basalt-600",title:w,children:w})]}),(0,e.jsx)("span",{className:"text-[8px] text-basalt-600",children:new Date(t.updatedAt).toLocaleDateString()})]}),(0,e.jsx)(ge,{userId:t.createdByUserId,name:t.createdByName,threadId:t.id,currentUserId:b,onReport:u,onBlock:l}),(0,e.jsx)("div",{className:"mt-3 space-y-2",children:t.comments.map(m=>(0,e.jsxs)("div",{className:"rounded-lg border border-white/[.05] bg-white/[.02] p-2",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2 text-[8px] text-basalt-600",children:[(0,e.jsx)("span",{className:"font-semibold text-basalt-400",children:m.name}),(0,e.jsx)("span",{children:new Date(m.createdAt).toLocaleString()})]}),(0,e.jsx)("p",{className:"mt-1 whitespace-pre-wrap text-[10px] leading-4 text-basalt-300",children:m.body}),m.mentions?.length?(0,e.jsx)("p",{className:"mt-1 text-[8px] text-cyan-300/70",children:m.mentions.map(f=>`@${f.name}`).join(" ")}):null,(0,e.jsx)(ge,{userId:m.userId,name:m.name,threadId:t.id,commentId:m.id,currentUserId:b,onReport:u,onBlock:l})]},m.id))}),t.kind==="review"&&g&&t.status==="open"?(0,e.jsx)("div",{className:"mt-3 flex flex-wrap gap-1.5",children:["requested","changes_requested","approved"].map(m=>(0,e.jsx)("button",{type:"button",disabled:t.reviewState===m,onClick:()=>k({reviewState:m}),className:"rounded-lg border border-violet-300/15 px-2 py-1 text-[8px] text-violet-200 disabled:opacity-40",children:m.replaceAll("_"," ")},m))}):null,y&&t.kind==="review"&&t.status==="open"?(0,e.jsxs)("label",{className:"mt-3 block text-[8px] font-bold uppercase tracking-wider text-basalt-600",children:["Assignee",(0,e.jsxs)("select",{value:t.assigneeUserId||"",onChange:m=>k({assigneeUserId:m.target.value||null}),className:`${z} mt-1 normal-case tracking-normal`,children:[(0,e.jsx)("option",{value:"",children:"Unassigned"}),n.filter(m=>M(m.role,"review.complete-assigned")).map(m=>(0,e.jsx)("option",{value:m.user_id,children:Z(m)},m.user_id))]})]}):null,(0,e.jsxs)("div",{className:"mt-3 flex items-center justify-between gap-2",children:[C?(0,e.jsxs)("button",{type:"button",onClick:()=>k({status:t.status==="open"?"resolved":"open"}),className:"inline-flex items-center gap-1 rounded-lg border border-emerald-300/15 px-2 py-1 text-[8px] text-emerald-200",children:[(0,e.jsx)(de,{size:9}),t.status==="open"?"Resolve":"Reopen"]}):(0,e.jsx)("span",{}),(0,e.jsx)("span",{className:"text-[8px] text-red-300","aria-live":"polite",children:x})]}),t.status==="open"&&j?(0,e.jsx)(oa,{thread:t,workspaceId:r,members:n,currentUserId:b,onSaved:i}):null]})}function da({workspaceId:t,currentUserId:s,notePath:r,noteContent:n,outline:b,onNavigate:i}){const[u,l]=(0,c.useState)([]),[x,p]=(0,c.useState)([]),[h,y]=(0,c.useState)([]),[j,C]=(0,c.useState)([]),[g,k]=(0,c.useState)([]),[w,m]=(0,c.useState)(null),[f,N]=(0,c.useState)(!1),[d,v]=(0,c.useState)({}),[S,T]=(0,c.useState)(!1),[R,te]=(0,c.useState)("discussion"),[F,W]=(0,c.useState)(""),[J,Y]=(0,c.useState)(""),[a,I]=(0,c.useState)(""),[B,E]=(0,c.useState)(""),[P,q]=(0,c.useState)([]),[H,L]=(0,c.useState)(""),[V,D]=(0,c.useState)(""),ae=(0,c.useRef)(0),se=(0,c.useRef)(t);se.current=t;const O=(0,c.useCallback)(async()=>{if(!t||!r)return;const o=++ae.current,[$,_,ie,Le,ze]=await Promise.all([Yt({workspaceId:t,notePath:r}),Xt({workspaceId:t,unreadOnly:!0,limit:20}),ea({workspaceId:t,notePath:r,limit:20}),ra(t),ta({workspaceId:t})]);o===ae.current&&(l($.threads||[]),p(_.mentions||[]),y(ie.activity||[]),C(Le.members||[]),k(ze.blocks||[]))},[t,r]);(0,c.useEffect)(()=>(l([]),p([]),y([]),C([]),k([]),m(null),v({}),D(""),O().catch(o=>D(o.message)),()=>{ae.current+=1}),[O]),(0,c.useEffect)(()=>{let o=!0;return Promise.all(u.map(async $=>{const _=await ia({anchor:$.anchor,noteContent:n,outline:b});return[$.id,_?_===$.anchor.fingerprint?"current":"changed":"missing"]})).then($=>{o&&v(Object.fromEntries($))}),()=>{o=!1}},[u,n,b]);const re=(0,c.useMemo)(()=>j.find(o=>o.user_id===s),[j,s]),K=(0,c.useMemo)(()=>new Set(g.map(o=>o.userId)),[g]),ne=(0,c.useMemo)(()=>j.filter(o=>
3!K.has(o.user_id)),[j,K]),ue=(0,c.useMemo)(()=>{const o=j.filter($=>$.user_id!==s);return[...o,...g.filter($=>!o.some(_=>_.user_id===$.userId)).map($=>({user_id:$.userId,name:$.name}))]},[j,g,s]),Be=M(re?.role,"discussion.assign"),xe=M(re?.role,"discussion.create"),De=async o=>{o.preventDefault(),D("Creatingâ¦");try{const $=await Re({notePath:r,noteContent:n,outline:b,headingId:a,blockId:B});await Ht({workspaceId:t,notePath:r,anchor:$,subject:F,body:J,kind:R,mentionUserIds:P,assigneeUserId:H||void 0}),W(""),Y(""),I(""),E(""),q([]),L(""),T(!1),D(""),await O()}catch($){D($.message)}},Ee=async o=>{try{await Zt(o.id,t),i?.(o.notePath),await O()}catch($){D($.message)}},me=async(o,$=!1)=>{N(!0),D("");try{if(await($?sa:aa)(o.user_id,t),se.current!==t)return;$||(q(_=>_.filter(ie=>ie!==o.user_id)),L(_=>_===o.user_id?"":_)),window.dispatchEvent(new CustomEvent("notification-center-refresh")),await O()}catch(_){se.current===t&&D(_.message)}finally{N(!1)}};return(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsxs)("details",{className:"rounded-xl border border-white/10 p-3",children:[(0,e.jsx)("summary",{className:"cursor-pointer text-[10px] font-semibold text-basalt-200",children:"Report or block a user"}),(0,e.jsx)("p",{className:"mt-2 text-[10px] leading-4 text-basalt-400",children:"Blocking hides this personâs discussions, comments, and mentions from you in this workspace and prevents directed mentions, replies to each otherâs discussions, and review assignments. Shared notes and workspace roles stay available. Reports go to Phasoric for review."}),(0,e.jsx)("div",{className:"mt-2 space-y-2",children:ue.length?ue.map(o=>(0,e.jsxs)("div",{className:"rounded-lg border border-white/[.06] p-2",children:[(0,e.jsxs)("p",{className:"text-[10px] text-basalt-300",children:[Z(o),K.has(o.user_id)?" · Blocked":""]}),(0,e.jsxs)("div",{className:"mt-2 flex flex-wrap gap-2",children:[(0,e.jsx)("button",{type:"button",className:X,onClick:()=>m({userId:o.user_id}),children:"Report user"}),(0,e.jsx)("button",{type:"button",disabled:f,className:X,onClick:()=>me(o,K.has(o.user_id)),children:K.has(o.user_id)?"Unblock user":"Block user"})]})]},o.user_id)):(0,e.jsx)("p",{className:"text-[10px] text-basalt-500",children:"No other workspace members."})})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-cyan-300/10 bg-cyan-300/[.025] p-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-cyan-100",children:[(0,e.jsx)(pe,{size:11}),"Anchored team context"]}),(0,e.jsx)("p",{className:"mt-1 text-[8px] leading-4 text-basalt-600",children:"Comments and reviews are durable. Writable live editor presence is limited to Editors and above."})]}),(0,e.jsx)("button",{type:"button",onClick:()=>O().catch(o=>D(o.message)),"aria-label":"Refresh collaboration",className:"rounded-lg border border-white/[.07] p-1.5 text-basalt-500 hover:text-white",children:(0,e.jsx)(xt,{size:10})})]}),(0,e.jsxs)("div",{className:"mt-3 flex gap-2",children:[xe?(0,e.jsxs)("button",{type:"button",onClick:()=>T(o=>!o),className:"inline-flex items-center gap-1 rounded-lg border border-cyan-300/20 px-2.5 py-1.5 text-[9px] font-semibold text-cyan-200",children:[(0,e.jsx)(We,{size:10}),"New discussion"]}):(0,e.jsx)("span",{className:"rounded-lg border border-white/[.07] px-2 py-1 text-[8px] text-basalt-600",children:"Read-only role"}),(0,e.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-lg border border-white/[.07] px-2 py-1 text-[8px] text-basalt-500",children:[(0,e.jsx)(Fe,{size:9}),x.length," unread"]})]})]}),S&&xe?(0,e.jsxs)("form",{onSubmit:De,className:"space-y-2 rounded-xl border border-white/[.07] bg-black/20 p-3",children:[(0,e.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,e.jsxs)("select",{value:R,onChange:o=>te(o.target.value),className:z,children:[(0,e.jsx)("option",{value:"discussion",children:"Discussion"}),M(re?.role,"review.request")?(0,e.jsx)("option",{value:"review",children:"Review"}):null]}),(0,e.jsxs)("select",{value:a,onChange:o=>I(o.target.value),className:z,children:[(0,e.jsx)("option",{value:"",children:"Whole note"}),b.map(o=>(0,e.jsxs)("option",{value:o.id,children:[", ".repeat(Math.max(0,o.level-1))," ",o.text]},o.id))]})]}),(0,e.jsx)("input",{required:!0,maxLength:240,value:F,onChange:o=>W(o.target.value),placeholder:"Subject",className:z}),(0,e.jsx)("textarea",{required:!0,maxLength:5e3,rows:3,value:J,onChange:o=>Y(o.target.value),placeholder:"Add context, a question, or review criteriaâ¦",className:z}),(0,e.jsx)("input",{value:B,onChange:o=>E(o.target.value),placeholder:"Portable block ID (optional)",className:z}),(0,e.jsx)(Me,{members:ne,currentUserId:s,selected:P,onChange:q}),R==="review"?(0,e.jsxs)("label",{className:"block text-[8px] font-bold uppercase tracking-wider text-basalt-600",children:["Reviewer",(0,e.jsxs)("select",{value:H,onChange:o=>L(o.target.value),className:`${z} mt-1 normal-case tracking-normal`,children:[(0,e.jsx)("option",{value:"",children:"Unassigned"}),ne.filter(o=>M(o.role,"review.complete-assigned")&&(Be||o.user_id===s)).map(o=>(0,e.jsx)("option",{value:o.user_id,children:Z(o)}
3,o.user_id))]})]}):null,(0,e.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,e.jsx)("button",{type:"button",onClick:()=>T(!1),className:"rounded-lg border border-white/[.07] px-2.5 py-1.5 text-[9px] text-basalt-500",children:"Cancel"}),(0,e.jsx)("button",{className:"rounded-lg bg-cyan-200 px-2.5 py-1.5 text-[9px] font-bold text-black",children:"Create"})]})]}):null,x.length?(0,e.jsxs)("details",{className:"rounded-xl border border-amber-300/10 p-3",children:[(0,e.jsx)("summary",{className:"cursor-pointer text-[9px] font-semibold text-amber-200",children:"Unread mentions"}),(0,e.jsx)("div",{className:"mt-2 space-y-2",children:x.map(o=>(0,e.jsxs)("button",{type:"button",onClick:()=>Ee(o),className:"w-full rounded-lg border border-white/[.05] p-2 text-left",children:[(0,e.jsxs)("span",{className:"block truncate text-[9px] text-basalt-300",children:[o.actorName," · ",o.subject]}),(0,e.jsx)("span",{className:"mt-1 block truncate font-mono text-[8px] text-basalt-700",children:o.notePath}),(0,e.jsx)("span",{className:"mt-1 block truncate text-[8px] text-basalt-600",children:o.body})]},o.id))})]}):null,(0,e.jsx)("div",{className:"space-y-2",children:u.length?u.map(o=>(0,e.jsx)(ca,{thread:o,anchorState:d[o.id]||"current",workspaceId:t,members:ne,currentUserId:s,onSaved:O,onReport:m,onBlock:me},o.id)):(0,e.jsx)("p",{className:"rounded-xl border border-dashed border-white/[.08] p-4 text-center text-[9px] text-basalt-600",children:"No anchored discussions for this note."})}),h.length?(0,e.jsxs)("details",{className:"rounded-xl border border-white/[.06] p-3",children:[(0,e.jsxs)("summary",{className:"flex cursor-pointer items-center gap-1.5 text-[9px] font-semibold text-basalt-400",children:[(0,e.jsx)(Ke,{size:10}),"Recent note activity"]}),(0,e.jsx)("div",{className:"mt-2 space-y-1.5",children:h.slice(0,10).map(o=>(0,e.jsxs)("div",{className:"text-[8px] text-basalt-600",children:[(0,e.jsx)("span",{className:"text-basalt-400",children:o.actorName})," · ",la(o.type)," · ",new Date(o.createdAt).toLocaleString()]},o.id))})]}):null,V?(0,e.jsx)("p",{className:"text-[9px] text-red-300","aria-live":"polite",children:V}):null,w?(0,e.jsx)(Ct,{open:!0,onClose:()=>m(null),defaultKind:"other",title:"Report content or user",intro:"Describe the content or behavior you want Phasoric to review. Note text and diagnostics are not included automatically.",defaultMessage:`Workspace: ${t} 4User: ${w.userId}${w.threadId?` 5Discussion: ${w.threadId}`:""}${w.commentId?` 6Comment: ${w.commentId}`:""} 7 8Describe the problem: 9`},`${t}:${w.userId}:${w.commentId||w.threadId||""}`):null]})}function pa({noteTitle:t,onNavigate:s,onIndexRequired:r}){const[n,b]=(0,c.useState)([]),[i,u]=(0,c.useState)([]);(0,c.useEffect)(()=>{if(!t)return;async function x(){const p=await At(t),h=await Mt(t);b(p),u(h)}return x(),window.addEventListener("metadata-index-updated",x),()=>window.removeEventListener("metadata-index-updated",x)},[t]);const l=async x=>{const p=t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),h=new RegExp(`(?<!\\[\\[)(${p})(?!\\]\\])`,"gi"),y=x.content.replace(h,`[[${t}]]`);await yt(x.path,{content:y,updatedAt:Date.now()}),r&&await r(x.path,y)};return(0,e.jsxs)("div",{className:"space-y-6 font-mono text-xs",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"text-accent-cyan font-bold uppercase tracking-wider mb-2 border-b border-basalt-800/40 pb-1 flex justify-between",children:[(0,e.jsx)("span",{children:"Linked Mentions"}),(0,e.jsxs)("span",{className:"text-basalt-500 font-normal",children:["(",n.length,")"]})]}),n.length===0?(0,e.jsx)("div",{className:"text-basalt-600 italic",children:"No notes link here yet."}):(0,e.jsx)("ul",{className:"space-y-1.5",children:n.map(x=>(0,e.jsx)("li",{children:(0,e.jsx)("button",{onClick:()=>s(x.title),className:"w-full text-left p-2 rounded border border-basalt-800 bg-basalt-900/30 hover:border-accent-cyan hover:bg-accent-cyan/5 transition-all text-basalt-300 hover:text-white",children:x.title})},x.path))})]}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"text-accent-purple font-bold uppercase tracking-wider mb-2 border-b border-basalt-800/40 pb-1 flex justify-between",children:[(0,e.jsx)("span",{children:"Unlinked Mentions"}),(0,e.jsxs)("span",{className:"text-basalt-500 font-normal",children:["(",i.length,")"]})]}),i.length===0?(0,e.jsx)("div",{className:"text-basalt-600 italic",children:"No unlinked mentions foun
9d."}):(0,e.jsx)("ul",{className:"space-y-2",children:i.map(x=>(0,e.jsx)("li",{className:"p-2 rounded border border-basalt-800 bg-basalt-900/30 flex flex-col gap-2",children:(0,e.jsxs)("div",{className:"flex justify-between items-center",children:[(0,e.jsx)("span",{className:"text-basalt-400 font-bold",children:x.title}),(0,e.jsx)("button",{onClick:()=>l(x),className:"px-2 py-0.5 rounded border border-accent-purple/40 text-accent-purple hover:bg-accent-purple/10 transition-all font-bold text-[9px] hover:scale-105 active:scale-95",children:"Link note"})]})},x.path))})]})]})}var ua={draft:"border-slate-300/20 text-slate-300",reviewed:"border-cyan-300/20 text-cyan-200",verified:"border-emerald-300/20 text-emerald-200",changed:"border-amber-300/20 text-amber-200",stale:"border-orange-300/20 text-orange-200",superseded:"border-basalt-700 text-basalt-500"};function xa(){return new Date(Date.now()+7776e6).toISOString().slice(0,10)}function oe(t){const s=new Date(`${t}T12:00:00`).getTime();if(!Number.isSafeInteger(s))throw new Error("Choose a valid review date.");return s}function ma({note:t,content:s,user:r}){const[n,b]=(0,c.useState)(null),[i,u]=(0,c.useState)(xa),[l,x]=(0,c.useState)(""),[p,h]=(0,c.useState)(""),y=(0,c.useMemo)(()=>({id:`person:${String(r?.id||"local").replace(/[^a-zA-Z0-9._:/-]/g,"-").slice(0,200)}`,kind:"person",displayName:r?.name||r?.email||"Local reviewer"}),[r?.email,r?.id,r?.name]);(0,c.useEffect)(()=>{let N=!0;const d=async()=>{const v=await mt(t,U);N&&(b(v||null),v?.reviewDueAt&&u(new Date(v.reviewDueAt).toISOString().slice(0,10)))};return d(),window.addEventListener("trust-records-updated",d),()=>{N=!1,window.removeEventListener("trust-records-updated",d)}},[t.id,t.path]);const j=async(N,d)=>{x(N),h("");try{const v=await d();b(v.record),h(N)}catch(v){h(v.message)}finally{x("")}},C=()=>j("Tracking started in Draft.",async()=>Tt({workspaceId:String(Q()||"workspace:local"),target:he(t),fingerprint:await ht({...t,content:s}),provenance:{kind:t.provenance?.kind||"local-note",sourceId:t.provenance?.sourceId||t.id||t.path},origin:{kind:"note-inspector",actorId:y.id}})),g=()=>j("Current fingerprint reviewed.",()=>le(n,"reviewed",{reviewer:y,actorId:y.id,reviewDueAt:oe(i),reason:n.state==="changed"?"A person reviewed the changed note fingerprint.":"A person reviewed the current note fingerprint.",origin:{kind:"note-inspector",actorId:y.id}})),k=()=>j("Evidence verified.",()=>le(n,"verified",{reviewer:y,actorId:y.id,reviewDueAt:oe(i),evidence:[{kind:"source-note",source:he(t),fingerprint:n.fingerprint,summary:"Reviewer verified the current canonical note.",capturedAt:Date.now()}],reason:"A person explicitly verified the current note and evidence.",origin:{kind:"note-inspector",actorId:y.id}})),w=()=>j("Verified knowledge reaffirmed.",()=>It(n,{reviewer:y,actorId:y.id,reviewDueAt:oe(i),reason:"A person reaffirmed the verified note.",origin:{kind:"note-inspector",actorId:y.id}})),m=async()=>{const N=window.prompt("Path of the note that replaces this knowledge:");N?.trim()&&await j("Record superseded with a durable replacement link.",()=>le(n,"superseded",{actorId:y.id,supersededBy:{type:"note",id:N.trim(),path:N.trim()},reason:`Superseded by ${N.trim()}.`,origin:{kind:"note-inspector",actorId:y.id}}))};if(!n)return(0,e.jsxs)("div",{className:"rounded-xl border border-dashed border-violet-300/20 bg-violet-300/[.025] p-3",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-[10px] font-semibold text-violet-200",children:[(0,e.jsx)(pe,{size:12}),"Not tracked"]}),(0,e.jsx)("p",{className:"mt-2 text-[9px] leading-4 text-basalt-500",children:"Start a separate trust record for this note. Editing remains portable Markdown and never implies verification."}),(0,e.jsx)("button",{type:"button",disabled:!!l,onClick:C,className:"mt-3 rounded-lg border border-violet-300/20 px-3 py-2 text-[9px] text-violet-200 disabled:opacity-40",children:"Track as Draft"}),p&&(0,e.jsx)("p",{className:"mt-2 text-[8px] text-amber-200",children:p})]});const f=[...n.history||[]].reverse().slice(0,6);return(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsxs)("div",{className:"rounded-xl border border-white/[.07] bg-white/[.02] p-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsx)("span",{className:`rounded border px-2 py-1 text-[8px] font-bold uppercase tracking-wider ${ua[n.state]}`,children:n.state}),(0,e.jsxs)("span",{className:"font-mono text-[7px] text-basalt-700",title:n.fingerprint,children:[n.fingerprint.slice(0,17),"â¦"]})]}),n.state==="changed"&&(0,e.jsxs)("p",{className:"mt-2 flex items-center gap-1.5 text-[9px] leading-4 text-amber-200",children:[(0,e.jsx)(Ye,{size:11}),"The note or fingerprinted source changed after its prior review."]}),n.state==="stale"&&(0,e.jsxs)("p",{className:"mt-2 flex items-center gap-1.5 text-[9px] leading-4 text-orange-200",children:[(0,e.jsx)(Je,{size:11}),"The scheduled review date passed."]}),(0,e.jsxs)("label",{className:"mt-3 block text-[8px] font-bold uppercase tracking-wider text-basalt-600",children:["Next review",(0,e.jsx)("input",{type:"date",value:i,onChange:N=>u(N.target.value),className:"mt-1 w-full rounded-lg border border-basalt-800 bg-black/20 px-2 py-1.5 text-[9px] font-normal text-white"})]}),(0,e.jsxs)("div",{className:"mt-3 flex flex-wrap gap-2",children:[["draft","changed","stale"].includes(n.state)&&(0,e.jsx)("button",{type:"button",disabled:!!l,onClick:g,className:"rounded-lg border border-cyan-300/20 px-2.5 py-1.5 text-[8px] text-cyan-200",children:"Review current"}),n.state==="reviewed"&&(0,e.jsxs)("button",{type:"button",disabled:!!l,onClick:k,className:"rounded-lg border border-emerald-300/20 px-2.5 py-1.5 text-[8px] text-emerald-200",children:[(0,e.jsx)(de,{size:9,className:"mr-1 inline"}),"Verify evidence"]}),n.state==="verified"&&(0,e.jsx)("button",{type:"button",disabled:!!l,onClick:w,className:"rounded-lg border border-emerald-300/20 px-2.5 py-1.5 text-[8px] text-emerald-200",children:"Reaffirm"}),n.state!=="superseded"&&(0,e.jsx)("button",{type:"button",disabled:!!l,onClick:m,className:"rounded-lg border border-white/10 px-2.5 py-1.5 text-[8px] text-basalt-500",children:"Supersede"})]}),p&&(0,e.jsx)("p",{role:"status",className:"mt-2 text-[8px] text-violet-200",children:p})]}),(0,e.jsxs)("details",{children:[(0,e.jsxs)("summary",{className:"flex cursor-pointer items-center gap-1.5 text-[8px] font-bold uppercase tracking-wider text-basalt-600",children:[(0,e.jsx)(tt,{size:10}),n.history?.length||0," lifecycle events"]}),(0,e.jsx)("ol",{className:"mt-2 space-y-2 border-l border-basalt-800 pl-3",children:f.map(N=>(0,e.jsxs)("li",{className:"text-[8px] leading-4 text-basalt-500",children:[(0,e.jsx)("strong",{className:"uppercase text-basalt-300",children:N.state}
9)," · ",new Date(N.at).toLocaleString(),N.reason?(0,e.jsx)("span",{className:"block",children:N.reason}):null]},N.id))})]})]})}var ye=()=>({id:crypto.randomUUID(),key:"",value:""});function ba({targetType:t,targetPath:s,inheritedProperties:r={},inheritedTags:n=[],onSaved:b}){const[i,u]=(0,c.useState)(""),[l,x]=(0,c.useState)([]),[p,h]=(0,c.useState)(""),[y,j]=(0,c.useState)("");(0,c.useEffect)(()=>{let g=!0;return h(""),j(""),vt(t,s).then(k=>{g&&(u((k?.tags||[]).join(", ")),x(Object.entries(k?.properties||{}).map(([w,m])=>({id:crypto.randomUUID(),key:w,value:String(m??"")}))))}),()=>{g=!1}},[s,t]);const C=async g=>{g?.preventDefault();try{const k={};for(const m of l){const f=m.key.trim();if(f){if(Object.prototype.hasOwnProperty.call(k,f))throw new Error(`Property "${f}" is duplicated.`);k[f]=m.value}}const w=await jt(t,s,{tags:i.split(",").map(m=>m.trim()),properties:k});j("Metadata saved locally and queued for cloud sync!"),h("Metadata saved locally and queued for cloud sync."),b?.(w)}catch(k){h(k.message)}};return(0,e.jsxs)("form",{onSubmit:C,className:"space-y-4 font-mono text-[10px]",children:[y&&(0,e.jsx)(St,{message:y,onClose:()=>j("")}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center gap-1.5 font-bold uppercase tracking-[0.12em] text-basalt-500",children:[(0,e.jsx)("label",{htmlFor:`tags-input-${s}`,children:"Tags"}),(0,e.jsx)(fe,{title:"Metadata Tags",content:"Commas separate inline & structural tags. These allow hierarchical query filtering across the vault."})]}),(0,e.jsx)("input",{id:`tags-input-${s}`,value:i,onChange:g=>u(g.target.value),"aria-label":`Tags for ${s}`,placeholder:"research, project/active",className:"mt-2 w-full rounded-lg border border-basalt-800 bg-black/20 px-3 py-2 text-xs text-white outline-none focus:border-cyan-300/50"}),n.length>0&&(0,e.jsxs)("p",{className:"mt-1.5 text-[9px] text-basalt-600",children:["Detected in note: ",n.map(g=>`#${g}`).join(", ")]})]}),Object.keys(r).length>0&&(0,e.jsxs)("div",{className:"rounded-lg border border-basalt-800 bg-white/[0.02] p-3",children:[(0,e.jsx)("div",{className:"mb-2 font-bold uppercase tracking-[0.12em] text-basalt-600",children:"Markdown frontmatter"}),(0,e.jsx)("dl",{className:"space-y-1.5",children:Object.entries(r).map(([g,k])=>(0,e.jsxs)("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)] gap-2",children:[(0,e.jsx)("dt",{className:"truncate text-violet-300",children:g}),(0,e.jsx)("dd",{className:"truncate text-basalt-400",children:String(k)})]},g))}),(0,e.jsx)("p",{className:"mt-2 text-[8px] leading-4 text-basalt-700",children:"Frontmatter remains in the local Markdown file. Synced properties below can supplement it without uploading the note body."})]}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("div",{className:"flex items-center gap-1 font-bold uppercase tracking-[0.12em] text-basalt-500",children:[(0,e.jsx)("span",{children:"Synced properties"}),(0,e.jsx)(fe,{title:"Database Property Pairs",content:"Key-value pairs synced independently from the raw text body."})]}),(0,e.jsxs)("button",{type:"button",onClick:()=>x(g=>[...g,ye()]),className:"active-press flex min-h-[32px] items-center gap-1 rounded-md px-2 py-1 text-cyan-300 hover:bg-cyan-300/10",children:[(0,e.jsx)(ke,{size:11}),"Property"]})]}),(0,e.jsxs)("div",{className:"mt-2 space-y-2",children:[l.length===0&&(0,e.jsx)("button",{type:"button",onClick:()=>x([ye()]),className:"active-press min-h-[44px] w-full rounded-lg border border-dashed border-basalt-800 px-3 py-3 text-left text-basalt-600 hover:border-basalt-700 hover:text-basalt-400",children:"Add a property such as status, owner, or due date."}),l.map(g=>(0,e.jsxs)("div",{className:"grid grid-cols-[minmax(0,0.8fr)_minmax(0,1.2fr)_36px] gap-1.5 items-center",children:[(0,e.jsx)("input",{value:g.key,onChange:k=>x(w=>w.map(m=>m.id===g.id?{...m,key:k.target.value}:m)),"aria-label":"Property name",placeholder:"Property",className:"min-w-0 rounded-md border border-basalt-800 bg-black/20 px-2 py-1.5 text-white outline-none focus:border-cyan-300/50"}),(0,e.jsx)("input",{value:g.value,onChange:k=>x(w=>w.map(m=>m.id===g.id?{...m,value:k.target.value}:m)),"aria-label":"Property value",placeholder:"Value",className:"min-w-0 rounded-md border border-basalt-800 bg-black/20 px-2 py-1.5 text-white outline-none focus:border-cyan-300/50"}),(0,e.jsx)("button",{type:"button",onClick:()=>x(k=>k.filter(w=>w.id!==g.id)),"aria-label":`Delete property ${g.key||"row"}`,className:"active-press flex h-8 w-8 min-h-[36px] min-w-[36px] items-center justify-center rounded-md text-basalt-600 hover:bg-red-500/10 hover:text-red-300",children:(0,e.jsx)(Se,{size:13})})]},g.id))]})]}),p&&!y&&(0,e.jsx)("p",{className:"text-[9px] leading-4 text-cyan-300",children:p}),(0,e.jsxs)("button",{type:"submit",className:"active-press flex min-h-[44px] w-full items-center justify-center gap-2 rounded-lg bg-cyan-300 px-3 py-2 text-xs font-bold text-black shadow-md",children:[(0,e.jsx)(Ne,{size:14}),"Save metadata"]})]})}function ha({markdown:t,noteKey:s}){const r=typeof window<"u"&&"speechSynthesis"in window&&"SpeechSynthesisUtterance"in window,[n,b]=(0,c.useState)([]),[i,u]=(0,c.useState)(()=>localStorage.getItem("basalt_tts_voice")||""),[l,x]=(0,c.useState)(()=>Number(localStorage.getItem("basalt_tts_rate")||1)),[p,h]=(0,c.useState)("idle"),[y,j]=(0,c.useState)({current:0,total:0}),C=(0,c.useRef)(0),g=(0,c.useMemo)(()=>Pt(t),[t]);(0,c.useEffect)(()=>
9{if(!r)return;const f=()=>b(window.speechSynthesis.getVoices());return f(),window.speechSynthesis.addEventListener("voiceschanged",f),()=>window.speechSynthesis.removeEventListener("voiceschanged",f)},[r]),(0,c.useEffect)(()=>()=>{C.current+=1,r&&window.speechSynthesis.cancel()},[s,r]);const k=()=>{C.current+=1,window.speechSynthesis.cancel(),h("idle"),j({current:0,total:0})},w=()=>{if(!r||!g)return;k();const f=_t(g),N=C.current,d=n.find(S=>S.name===i);h("speaking"),j({current:1,total:f.length});const v=S=>{if(C.current!==N||S>=f.length){C.current===N&&(h("idle"),j({current:f.length,total:f.length}));return}const T=new SpeechSynthesisUtterance(f[S]);T.rate=l,d&&(T.voice=d),T.onstart=()=>j({current:S+1,total:f.length}),T.onend=()=>v(S+1),T.onerror=R=>{R.error!=="canceled"&&R.error!=="interrupted"&&h("error")},window.speechSynthesis.speak(T)};v(0)},m=()=>{p==="paused"?(window.speechSynthesis.resume(),h("speaking")):(window.speechSynthesis.pause(),h("paused"))};return r?(0,e.jsxs)("div",{className:"space-y-3 font-mono text-[10px]",children:[(0,e.jsxs)("div",{className:"grid grid-cols-[1fr_80px] gap-2",children:[(0,e.jsxs)("label",{className:"text-basalt-600",children:["Voice",(0,e.jsxs)("select",{value:i,onChange:f=>{u(f.target.value),localStorage.setItem("basalt_tts_voice",f.target.value)},className:"mt-1 w-full rounded-md border border-basalt-800 bg-black/20 px-2 py-1.5 text-basalt-300 outline-none",children:[(0,e.jsx)("option",{value:"",children:"System default"}),n.map(f=>(0,e.jsxs)("option",{value:f.name,children:[f.name," (",f.lang,")"]},`${f.name}:${f.lang}`))]})]}),(0,e.jsxs)("label",{className:"text-basalt-600",children:["Speed",(0,e.jsx)("select",{value:l,onChange:f=>{const N=Number(f.target.value);x(N),localStorage.setItem("basalt_tts_rate",String(N))},className:"mt-1 w-full rounded-md border border-basalt-800 bg-black/20 px-2 py-1.5 text-basalt-300 outline-none",children:[.75,1,1.25,1.5,2].map(f=>(0,e.jsxs)("option",{value:f,children:[f,"x"]},f))})]})]}),(0,e.jsxs)("div",{className:"flex gap-2",children:[(0,e.jsxs)("button",{type:"button",onClick:w,disabled:!g,className:"flex flex-1 items-center justify-center gap-1.5 rounded-md bg-cyan-300 px-2 py-2 font-bold text-black disabled:opacity-40",children:[p==="idle"?(0,e.jsx)(be,{size:12}):(0,e.jsx)(at,{size:12}),p==="idle"?"Read note":"Restart"]}),(p==="speaking"||p==="paused")&&(0,e.jsx)("button",{type:"button",onClick:m,className:"rounded-md border border-basalt-700 px-3 text-basalt-300 hover:text-white","aria-label":p==="paused"?"Resume reading":"Pause reading",children:p==="paused"?(0,e.jsx)(be,{size:12}):(0,e.jsx)(Ze,{size:12})}),p!=="idle"&&(0,e.jsx)("button",{type:"button",onClick:k,className:"rounded-md border border-basalt-700 px-3 text-basalt-300 hover:text-white","aria-label":"Stop reading",children:(0,e.jsx)(rt,{size:11})})]}),y.total>0&&(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{className:"h-1 overflow-hidden rounded-full bg-basalt-900",children:(0,e.jsx)("div",{className:"h-full bg-cyan-300 transition-[width]",style:{width:`${y.current/y.total*100}%`}})}),(0,e.jsxs)("p",{className:"mt-1.5 text-[8px] text-basalt-700",children:["Reading segment ",Math.min(y.current,y.total)," of ",y.total,". Speech stays on this device."]})]}),p==="error"&&(0,e.jsx)("p",{className:"text-red-300",children:"The selected voice could not read this note."})]}):(0,e.jsx)("p",{className:"text-[9px] leading-4 text-basalt-600",children:"Text-to-speech is not available in this browser or native WebView."})}var ve={name:"",type:"",description:"",properties:"status:enum:required:active|complete",allowedTags:"",rename:"",templateId:"",quarryViewId:"",recipeId:"",skillId:"",forgeAction:""},je={kind:"internal",type:"decision",id:"",provider:"github",objectType:"issue",label:"",url:""};function fa(t){return String(t||"").split(/\r?\n/).map(s=>s.trim()).filter(Boolean).map(s=>{const[r,n="string",b="",i=""]=s.split(":");if(!Vt.includes(n))throw new Error(`Unsupported type â${n}â for ${r}.`);return{key:r,type:n,required:b==="required",recommended:b==="recommended",options:i.split("|").filter(
9Boolean)}})}function ga({note:t,content:s,onNavigate:r}){const[n,b]=(0,c.useState)([]),[i,u]=(0,c.useState)(""),[l,x]=(0,c.useState)(ve),[p,h]=(0,c.useState)(je),[y,j]=(0,c.useState)({templates:[],quarries:[],recipes:[],skills:[]}),[C,g]=(0,c.useState)({internal:[],external:[]}),[k,w]=(0,c.useState)(""),[m,f]=(0,c.useState)(""),N=(0,c.useMemo)(()=>{try{return Et(s)}catch(a){return{namespace:{},error:a}}},[s]),d=(0,c.useMemo)(()=>n.find(a=>a.id===i)||null,[n,i]),v=(0,c.useMemo)(()=>d?Kt(s,d):null,[s,d]),S=(0,c.useMemo)(()=>{try{return d?Ut(s,d):null}catch{return null}},[s,d]),T=(0,c.useCallback)(async()=>{const[a,I,B,E,P,q]=await Promise.all([Dt(),U.templates.toArray(),U.quarryViews.toArray(),U.promptRecipes.toArray(),U.compiledDomains.toArray(),ft({...t,content:s},{database:U})]);b(a),j({templates:I,quarries:B,recipes:E,skills:P.filter(L=>L.isSkillActive)}),g(q);const H=N.namespace?.blueprint;u(L=>a.some(V=>V.id===L)?L:a.find(V=>V.id===H)?.id||a[0]?.id||"")},[s,N.namespace?.blueprint,t]);(0,c.useEffect)(()=>{T().catch(a=>w(a.message))},[T]);const R=async(a,I)=>{f("write");try{await Bt.writeNote({...t,content:a}),w(I)}catch(B){w(B.message)}finally{f("")}},te=()=>d&&R(Ot(s,d),`${d.name} v${d.schemaVersion} applied to canonical frontmatter.`),F=()=>S?.changed&&R(S.markdown,`Migrated Blueprint metadata from v${S.fromVersion} to v${S.toVersion}.`),W=async a=>{a.preventDefault(),f("blueprint");try{const I=n.find(P=>P.type===l.type&&!P.builtin),B=l.rename.split(",").map(P=>P.trim()).filter(Boolean).map(P=>P.split(">").map(q=>q.trim())).filter(P=>P.length===2&&P.every(Boolean)),E=await zt({id:I?.id||`custom.${l.type}`,type:l.type,name:l.name,description:l.description,properties:fa(l.properties),allowedTags:l.allowedTags.split(",").map(P=>P.trim()),behaviors:{templateId:l.templateId,quarryViewId:l.quarryViewId,recipeId:l.recipeId,skillId:l.skillId,forgeAction:l.forgeAction},migrations:I&&B.length?[...I.migrations||[],{fromVersion:I.schemaVersion,toVersion:I.schemaVersion+1,renames:Object.fromEntries(B),defaults:{}}]:I?.migrations||[]});x(ve),w(`${E.name} v${E.schemaVersion} saved. Markdown notes migrate only after preview.`),await T(),u(E.id)}catch(I){w(I.message)}finally{f("")}},J=async a=>{a.preventDefault();try{const I=p.kind==="external"?{kind:"external",provider:p.provider,objectType:p.objectType,id:p.id,label:p.label,url:p.url}:{kind:"internal",type:p.type,id:p.id,label:p.label};await R(qt(s,I),`${p.kind==="external"?"External reference":"Internal entity link"} added to portable frontmatter.`),h(je)}catch(I){w(I.message)}},Y=async a=>{window.confirm(`Delete custom Blueprint â${a.name}â? Existing Markdown keeps its readable type metadata.`)&&(await Lt(a.id),await T())};return(0,e.jsxs)("div",{className:"space-y-4 text-[10px]",children:[(0,e.jsxs)("div",{className:"rounded-xl border border-white/[.07] bg-white/[.02] p-3",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-[9px] font-bold uppercase tracking-wider text-cyan-200",children:[(0,e.jsx)(ce,{size:12}),"Portable typed Markdown"]}),(0,e.jsxs)("p",{className:"mt-2 text-[9px] leading-4 text-basalt-500",children:["Blueprints validate canonical YAML without rewriting invalid values. Phasoric metadata is nested under ",(0,e.jsx)("code",{children:"basalt:"})," and remains readable in any Markdown tool."]}),(0,e.jsx)("select",{value:i,onChange:a=>u(a.target.value),className:"mt-3 w-full rounded-lg border border-white/10 bg-black/20 px-2 py-2 text-[10px] text-white",children:n.map(a=>(0,e.jsxs)("option",{value:a.id,children:[a.name," · v",a.schemaVersion,a.builtin?" built-in":""]},a.id))}),d&&(0,e.jsxs)("div",{className:"mt-3 flex flex-wrap gap-2",children:[(0,e.jsx)("button",{type:"button",disabled:!!m,onClick:te,className:"rounded-lg bg-cyan-200 px-3 py-2 text-[9px] font-bold text-black",children:"Apply type"}),S?.changed&&(0,e.jsxs)("button",{type:"button",disabled:!!m,onClick:F,className:"rounded-lg border border-violet-300/20 px-3 py-2 text-[9px] text-violet-200",children:[(0,e.jsx)(He,{size:10,className:"mr-1 inline"}),"Previewed migration v",S.fromVersion,"âv",S.toVersion]}),!d.builtin&&(0,e.jsx)("button",{type:"button",onClick:()=>Y(d),className:"rounded-lg border border-white/10 px-2 text-basalt-600",children:(0,e.jsx)(Se,{size:11})})]})]}),v&&(0,e.jsxs)("div",{className:`rounded-xl border p-3 ${v.valid?"border-emerald-300/15 bg-emerald-300/[.03]":"border-amber-300/15 bg-amber-300/[.03]"}`,children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-[9px] font-bold uppercase tracking-wider",children:[v.valid?(0,e.jsx)(de,{size:11,className:"text-emerald-300"}):(0,e.jsx)(it,{size:11,className:"text-amber-300"}),v.valid?"Typed values valid":`${v.errors.length} validation error${v.errors.length===1?"":"s"}`]}),[...v.errors,...v.warnings].length?(0,e.jsx)("ul",{className:"mt-2 space-y-1 text-[9px] text-basalt-500",children:[...v.errors,...v.warnings].map((a,I)=>(0,e.jsxs)("li",{children:[(0,e.jsx)("code",{children:a.field})," · ",a.message]},`${a.field}:${I}`))}):null]}),(0,e.jsxs)("form",{onSubmit:J,className:"rounded-xl border border-white/[.07] p-3",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-[9px] font-bold uppercase tracking-wider text-violet-200",children:[(0,e.jsx)(Ge,{size:11}),"Semantic links"]}),(0,e.jsxs)("div",{className:"mt-2 grid grid-cols-2 gap-2",children:[(0,e.jsxs)("select",{value:p.kind,onChange:a=>h({...p,kind:a.target.value}),className:"capture-workflow-input",children:[(0,e.jsx)("option",{value:"internal",children:"Internal entity"}
9),(0,e.jsx)("option",{value:"external",children:"External reference"})]}),p.kind==="internal"?(0,e.jsx)("select",{value:p.type,onChange:a=>h({...p,type:a.target.value}),className:"capture-workflow-input",children:gt.map(a=>(0,e.jsx)("option",{value:a,children:a},a))}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("input",{value:p.provider,onChange:a=>h({...p,provider:a.target.value}),placeholder:"provider",className:"capture-workflow-input"}),(0,e.jsx)("input",{value:p.objectType,onChange:a=>h({...p,objectType:a.target.value}),placeholder:"object type",className:"capture-workflow-input"})]}),(0,e.jsx)("input",{required:!0,value:p.id,onChange:a=>h({...p,id:a.target.value}),placeholder:"Stable entity/object ID",className:"capture-workflow-input"}),(0,e.jsx)("input",{value:p.label,onChange:a=>h({...p,label:a.target.value}),placeholder:"Readable label",className:"capture-workflow-input"}),p.kind==="external"&&(0,e.jsx)("input",{type:"url",value:p.url,onChange:a=>h({...p,url:a.target.value}),placeholder:"Optional display URL",className:"capture-workflow-input col-span-2"}),(0,e.jsxs)("button",{disabled:!!m,className:"col-span-2 rounded-lg border border-violet-300/20 py-2 text-[9px] text-violet-200",children:[(0,e.jsx)(ke,{size:10,className:"mr-1 inline"}),"Add reference"]})]}),(0,e.jsxs)("div",{className:"mt-3 space-y-1",children:[C.internal.map(a=>(0,e.jsxs)("button",{type:"button",disabled:!a.entity?.sourcePath,onClick:()=>a.entity?.sourcePath&&r?.(a.entity.sourcePath),className:"block w-full truncate text-left text-[8px] text-basalt-500",children:[a.status==="resolved"?"â":"â"," ",a.link.type,":",a.link.id]},`${a.link.type}:${a.link.id}`)),C.external.map(a=>(0,e.jsxs)("div",{className:"truncate text-[8px] text-basalt-500",children:["â ",a.reference.provider,":",a.reference.object_type,":",a.reference.id]},`${a.reference.provider}:${a.reference.id}`))]})]}),(0,e.jsxs)("details",{className:"rounded-xl border border-white/[.07] p-3",children:[(0,e.jsx)("summary",{className:"cursor-pointer text-[9px] font-bold uppercase tracking-wider text-basalt-400",children:"Define or version a custom Blueprint"}),(0,e.jsxs)("form",{onSubmit:W,className:"mt-3 grid grid-cols-2 gap-2",children:[(0,e.jsx)("input",{required:!0,value:l.name,onChange:a=>x({...l,name:a.target.value}),placeholder:"Blueprint name",className:"capture-workflow-input"}),(0,e.jsx)("input",{required:!0,value:l.type,onChange:a=>x({...l,type:a.target.value.toLowerCase()}),placeholder:"custom type",className:"capture-workflow-input"}),(0,e.jsx)("textarea",{value:l.description,onChange:a=>x({...l,description:a.target.value}),placeholder:"Description",className:"capture-workflow-input col-span-2 min-h-14"}),(0,e.jsx)("textarea",{value:l.properties,onChange:a=>x({...l,properties:a.target.value}),placeholder:"One per line: key:type:required:option|option",className:"capture-workflow-input col-span-2 min-h-20"}),(0,e.jsx)("input",{value:l.allowedTags,onChange:a=>x({...l,allowedTags:a.target.value}),placeholder:"Allowed tag roots",className:"capture-workflow-input"}),(0,e.jsx)("input",{value:l.rename,onChange:a=>x({...l,rename:a.target.value}),placeholder:"Version rename: old>new",className:"capture-workflow-input"}),(0,e.jsxs)("select",{value:l.templateId,onChange:a=>x({...l,templateId:a.target.value}),className:"capture-workflow-input",children:[(0,e.jsx)("option",{value:"",children:"No template behavior"}),y.templates.map(a=>(0,e.jsx)("option",{value:a.id,children:a.title},a.id))]}),(0,e.jsxs)("select",{value:l.quarryViewId,onChange:a=>x({...l,quarryViewId:a.target.value}),className:"capture-workflow-input",children:[(0,e.jsx)("option",{value:"",children:"No Quarry behavior"}),y.quarries.map(a=>(0,e.jsx)("option",{value:a.id,children:a.name},a.id))]}),(0,e.jsxs)("select",{value:l.recipeId,onChange:a=>x({...l,recipeId:a.target.value}),className:"capture-workflow-input",children:[(0,e.jsx)("option",{value:"",children:"No Recipe behavior"}),y.recipes.map(a=>(0,e.jsx)("option",{value:a.id,children:a.name},a.id))]}),(0,e.jsxs)("select",{value:l.skillId,onChange:a=>x({...l,skillId:a.target.value}),className:"capture-workflow-input",children:[(0,e.jsx)("option",{value:"",children:"No Skill behavior"}),y.skills.map(a=>(0,e.jsx)("option",{value:a.id,children:a.name||a.id},a.id))]}),(0,e.jsx)("input",{value:l.forgeAction,onChange:a=>x({...l,forgeAction:a.target.value}),placeholder:"Forge action ID",className:"capture-workflow-input col-span-2"}),(0,e.jsxs)("button",{disabled:m==="blueprint",className:"col-span-2 inline-flex items-center justify-center gap-2 rounded-lg bg-white px-3 py-2 text-[9px] font-bold text-black",children:[(0,e.jsx)(Ne,{size:11}),"Save version"]})]})]}
9),k&&(0,e.jsx)("p",{role:"status",className:"text-[9px] leading-4 text-cyan-200",children:k})]})}var us=Oe({NoteInspector:()=>ja}),Ae="basalt_note_drawer_pins_v1";function ya(){try{const t=JSON.parse(localStorage.getItem(`${Ae}:${Q()}`)||"null");return Array.isArray(t)?t:["outline"]}catch{return["outline"]}}function va({outline:t,activeNote:s,bookmarkIds:r,onRevealLine:n,onToggleBookmark:b}){return t.length?(0,e.jsx)("ol",{className:"space-y-0.5",children:t.map(i=>{const u=G("section",s.path,i.text);return(0,e.jsxs)("li",{className:"group/line flex items-center gap-1",style:{paddingLeft:`${(i.level-1)*10}px`},children:[(0,e.jsx)("button",{type:"button",onClick:()=>n(i.line),className:"min-w-0 flex-1 truncate rounded px-2 py-1.5 text-left font-mono text-[10px] text-basalt-400 hover:bg-white/5 hover:text-cyan-200",title:`Line ${i.line}: ${i.text}`,children:i.text}),(0,e.jsx)("button",{type:"button",onClick:()=>b(i.text),"aria-label":r.has(u)?`Remove bookmark for ${i.text}`:`Bookmark section ${i.text}`,className:`rounded p-1 opacity-0 transition group-hover/line:opacity-100 focus:opacity-100 ${r.has(u)?"text-amber-300 opacity-100":"text-basalt-700 hover:text-amber-300"}`,children:(0,e.jsx)(we,{size:10,fill:r.has(u)?"currentColor":"none"})})]},i.id)})}):(0,e.jsx)("p",{className:"font-mono text-[9px] text-basalt-600",children:"Add Markdown headings to build this outline."})}function ja({activeNote:t,noteContent:s,onNavigate:r,onRevealLine:n,onClose:b}){const{user:i}=pt(),u=(0,c.useMemo)(()=>Rt(s),[s]),l=(0,c.useMemo)(()=>$t(s),[s]),x=!!(i&&!i.localOnly&&(i.entitlementLevel||dt(i.tier))==="team"),p=x?Q():"",[h,y]=(0,c.useState)(new Set),[j,C]=(0,c.useState)(ya),[g,k]=(0,c.useState)("");(0,c.useEffect)(()=>{let d=!0;const v=async()=>{const S=await U.bookmarks.where("targetPath").equals(t.path).toArray();d&&y(new Set(S.map(T=>T.id)))};return v(),window.addEventListener("basalt-metadata-updated",v),()=>{d=!1,window.removeEventListener("basalt-metadata-updated",v)}},[t.path]);const w=async(d="")=>{const v=G(d?"section":"note",t.path,d);h.has(v)?await kt(Nt.bookmark,v):await wt({targetType:d?"section":"note",targetPath:t.path,heading:d,title:d||t.title,vault:t.path.split("/")[0]})},m=[{id:"intelligence",label:"Intelligence Actions",shortLabel:"Actions",icon:ce,content:(0,e.jsx)(Ft,{linksOnly:!0,capabilities:{knowledgeCompilation:ct(i?.tier).knowledgeCompilation},targets:[{resourceType:"note",id:t.id,path:t.path}]})},{id:"outline",label:`Outline (${u.length})`,shortLabel:"Outline",icon:Qe,content:(0,e.jsx)(va,{outline:u,activeNote:t,bookmarkIds:h,onRevealLine:n,onToggleBookmark:w})},{id:"read-aloud",label:"Read aloud",shortLabel:"Read",icon:ot,content:(0,e.jsx)(ha,{markdown:s,noteKey:t.path})},{id:"properties",label:"Tags & properties",shortLabel:"Properties",icon:st,content:(0,e.jsx)(ba,{targetType:"note",targetPath:t.path,inheritedProperties:t.frontmatter||{},inheritedTags:l})},{id:"tags",label:"Detected tags",shortLabel:"Tags",icon:nt,content:l.length?(0,e.jsx)("div",{className:"flex flex-wrap gap-1.5",children:l.map(d=>(0,e.jsxs)("span",{className:"rounded-full border border-amber-300/15 bg-amber-300/5 px-2 py-1 font-mono text-[9px] text-amber-200",children:["#",d]},d))}):(0,e.jsx)("p",{className:"font-mono text-[9px] text-basalt-600",children:"No inline tags in this note."})},{id:"connections",label:"Connections",shortLabel:"Links",icon:Xe,content:(0,e.jsx)(pa,{noteTitle:t.title,onNavigate:r})},{id:"blueprint",label:"Blueprint & semantic links",shortLabel:"Blueprint",icon:ce,content:(0,e.jsx)(ga,{note:t,content:s,onNavigate:r})},{id:"trust",label:"Trust lifecycle",shortLabel:"Trust",icon:pe,content:(0,e.jsx)(ma,{note:t,content:s,user:i})},...x?[{id:"discussions",label:"Team discussions",shortLabel:"Discuss",icon:lt,content:(0,e.jsx)(da,{workspaceId:p,currentUserId:i.id,notePath:t.path,noteContent:s,outline:u,onNavigate:r})}]:[]],f=d=>{const v=j.includes(d)?j.filter(S=>S!==d):[...j,d];C(v),localStorage.setItem(`${Ae}:${Q()}`,JSON.stringify(v)),g===d&&k("")},N=m.filter(d=>j.includes(d.id)||d.id===g);return(0,e.jsxs)("aside",{className:"flex h-full bg-basalt-950 text-white","aria-label":"Note tools",children:[(0,e.jsxs)("nav",{className:"flex w-14 shrink-0 flex-col items-center gap-1 border-r border-basalt-800 py-3","aria-label":"Note tool drawers",children:[m.map(d=>{const v=d.icon,S=g===d.id||j.includes(d.id);return(0,e.jsxs)("button",{type:"button",onClick:()=>
9k(T=>T===d.id?"":d.id),"aria-label":`Open ${d.label} drawer`,"aria-pressed":S,title:d.label,className:`flex w-12 flex-col items-center gap-0.5 rounded-lg py-2 text-[7px] transition ${S?"bg-cyan-300/10 text-cyan-200":"text-basalt-600 hover:bg-white/5 hover:text-white"}`,children:[(0,e.jsx)(v,{size:14}),(0,e.jsx)("span",{className:"max-w-11 truncate",children:d.shortLabel})]},d.id)}),b&&(0,e.jsx)("button",{type:"button",onClick:b,"aria-label":"Close note tools",title:"Close note tools",className:"mt-auto rounded-lg p-2 text-basalt-600 hover:bg-white/5 hover:text-white",children:(0,e.jsx)(Wt,{size:15})})]}),(0,e.jsxs)("div",{className:"min-w-0 flex-1 overflow-y-auto",children:[(0,e.jsxs)("div",{className:"sticky top-0 z-10 flex items-center justify-between border-b border-basalt-800 bg-basalt-950 px-4 py-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{className:"font-outfit text-xs font-semibold",children:"Note tools"}),(0,e.jsx)("div",{className:"mt-0.5 max-w-44 truncate font-mono text-[8px] text-basalt-700",children:t.path})]}),(0,e.jsx)("button",{type:"button",onClick:()=>w(),"aria-label":h.has(G("note",t.path))?"Remove note bookmark":"Bookmark note",className:`rounded-lg border p-2 ${h.has(G("note",t.path))?"border-amber-300/30 bg-amber-300/10 text-amber-300":"border-basalt-800 text-basalt-600 hover:text-white"}`,children:(0,e.jsx)(we,{size:13,fill:"currentColor"})})]}),(0,e.jsx)("div",{className:"p-3",children:N.length?(0,e.jsx)("div",{className:"space-y-3",children:N.map(d=>{const v=d.icon,S=j.includes(d.id);return(0,e.jsxs)("section",{className:"rounded-xl border border-basalt-800 bg-white/[.015]","aria-label":d.label,children:[(0,e.jsxs)("header",{className:"flex items-center gap-2 border-b border-basalt-800/70 px-3 py-2.5",children:[(0,e.jsx)(v,{size:12,className:"text-cyan-300"}),(0,e.jsx)("h2",{className:"min-w-0 flex-1 truncate text-[9px] font-bold uppercase tracking-[.12em] text-basalt-400",children:d.label}),(0,e.jsx)("button",{type:"button",onClick:()=>f(d.id),"aria-label":`${S?"Unpin":"Pin"} ${d.label} drawer`,title:S?"Keep closed by default":"Keep open in the side panel",className:S?"text-amber-300":"text-basalt-700 hover:text-white",children:(0,e.jsx)(et,{size:11,fill:S?"currentColor":"none"})}),!S&&(0,e.jsx)("button",{type:"button",onClick:()=>k(""),"aria-label":`Close ${d.label} drawer`,className:"text-basalt-700 hover:text-white",children:(0,e.jsx)(ut,{size:12})})]}),(0,e.jsx)("div",{className:"p-3",children:d.content})]},d.id)})}):(0,e.jsx)("div",{className:"rounded-xl border border-dashed border-basalt-800 p-5 text-center text-[9px] leading-5 text-basalt-600",children:"Choose a tool from the rail. Pin the tools you want to keep open here."})})]})]})}export{us as n,ba as r,ja as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.