@openparachute/app 0.22.5

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 (64) hide show
  1. package/CHANGELOG.md +3473 -0
  2. package/LICENSE +661 -0
  3. package/README.md +68 -0
  4. package/dist/.parachute/info +8 -0
  5. package/dist/apple-touch-icon-180x180.png +0 -0
  6. package/dist/assets/Account-BhmA30V5.js +1 -0
  7. package/dist/assets/Activity-BgJa7Woi.js +1 -0
  8. package/dist/assets/AddVault-BWa_-QjM.js +1 -0
  9. package/dist/assets/AddVaultChooser-B3ElIlza.js +1 -0
  10. package/dist/assets/AddVaultCreate-DKJfYFJ1.js +1 -0
  11. package/dist/assets/Calendar-DUwSvnCY.js +1 -0
  12. package/dist/assets/CheckEmail-BQYQLTLL.js +1 -0
  13. package/dist/assets/ConnectAI-DCtARp-w.js +1 -0
  14. package/dist/assets/DayView-nficJMEc.js +1 -0
  15. package/dist/assets/Export-DNAoKjAn.js +1 -0
  16. package/dist/assets/Import-CoFeXNMx.js +20 -0
  17. package/dist/assets/NoteEditor-DtrdRbqx.js +1 -0
  18. package/dist/assets/NoteNew-C0DMe5Q8.js +8 -0
  19. package/dist/assets/NoteRenderer-Dl9X9uRt.js +37 -0
  20. package/dist/assets/NoteView-B2QH25fP.js +3 -0
  21. package/dist/assets/OAuthCallback-Dj26N8oJ.js +1 -0
  22. package/dist/assets/PinArchiveButtons-BXZFiW-i.js +1 -0
  23. package/dist/assets/Settings-BuXl91ig.js +1 -0
  24. package/dist/assets/TagPage-q7PgbEHn.js +1 -0
  25. package/dist/assets/TagSchemaEditor-DIHppYmj.js +1 -0
  26. package/dist/assets/Tags-BqJ9vWM5.js +1 -0
  27. package/dist/assets/VaultGraph-CaiNmEtX.js +3 -0
  28. package/dist/assets/Vaults-CTsUsDH8.js +1 -0
  29. package/dist/assets/ViewNew-BegTqdOq.js +1 -0
  30. package/dist/assets/ViewSurface-ClCtZW0N.js +1 -0
  31. package/dist/assets/Welcome-CN4Zh9jP.js +1 -0
  32. package/dist/assets/WizardShell-ZqrzQKxp.js +1 -0
  33. package/dist/assets/attachment-upload-l7qA8_xw.js +2 -0
  34. package/dist/assets/editor-mode-D9fveTEx.js +1 -0
  35. package/dist/assets/figtree-latin-ext-wght-normal-DCwSJGxG.woff2 +0 -0
  36. package/dist/assets/figtree-latin-wght-normal-D_ZTVpCC.woff2 +0 -0
  37. package/dist/assets/fraunces-latin-ext-opsz-italic-CGbN9UgK.woff2 +0 -0
  38. package/dist/assets/fraunces-latin-ext-opsz-normal-CJcjJNj7.woff2 +0 -0
  39. package/dist/assets/fraunces-latin-opsz-italic-lSdLDfvT.woff2 +0 -0
  40. package/dist/assets/fraunces-latin-opsz-normal-DihXLNYH.woff2 +0 -0
  41. package/dist/assets/fraunces-vietnamese-opsz-italic-DxWqP7Ku.woff2 +0 -0
  42. package/dist/assets/fraunces-vietnamese-opsz-normal-Czevyj-6.woff2 +0 -0
  43. package/dist/assets/history-ByMClxJV.js +1 -0
  44. package/dist/assets/index-CaleIHD8.css +1 -0
  45. package/dist/assets/index-Dwo2xe8_.js +66 -0
  46. package/dist/assets/provenance-B6WFYTWW.js +1 -0
  47. package/dist/assets/react-force-graph-2d-BMU3lxLC.js +44 -0
  48. package/dist/assets/transcribe-default-LVAxyzpn.js +1 -0
  49. package/dist/assets/types-BaJkUfo6.js +1 -0
  50. package/dist/assets/url-QSQwrjSV.js +1 -0
  51. package/dist/assets/useAttachmentUploader-C3UnTg01.js +30 -0
  52. package/dist/assets/workbox-window.prod.es5-BBnX5xw4.js +2 -0
  53. package/dist/favicon.ico +0 -0
  54. package/dist/icon.svg +21 -0
  55. package/dist/index.html +31 -0
  56. package/dist/manifest.webmanifest +1 -0
  57. package/dist/maskable-icon-512x512.png +0 -0
  58. package/dist/pwa-192x192.png +0 -0
  59. package/dist/pwa-512x512.png +0 -0
  60. package/dist/pwa-64x64.png +0 -0
  61. package/dist/sw.js +1 -0
  62. package/dist/workbox-9c191d2f.js +1 -0
  63. package/meta.json +20 -0
  64. package/package.json +83 -0
@@ -0,0 +1 @@
1
+ import{r as n,j as e,a6 as H,ad as oe,V as I,a7 as le,ae as ce,a as K,af as de,N as ue,L as $,E as me,w as fe,b as he,ag as q,ah as xe,ai as pe,aj as ge,ak as be,a8 as ve,al as T,am as je,an as Ne,x as F,ao as we}from"./index-Dwo2xe8_.js";import{A as ye}from"./attachment-upload-l7qA8_xw.js";import{u as Se,C as ke,A as Ce,a as Ee}from"./useAttachmentUploader-C3UnTg01.js";import{P as Re,D as Ae}from"./PinArchiveButtons-BXZFiW-i.js";import{b as De,N as Te}from"./NoteRenderer-Dl9X9uRt.js";import{r as Pe}from"./editor-mode-D9fveTEx.js";const Ie=250;function $e({noteId:t,attachment:a}){const[r,l]=n.useState(!1),x=Le(a);return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>l(!0),"aria-label":`Remove attachment ${x}`,className:"shrink-0 rounded border border-transparent px-1.5 py-0.5 text-fg-dim hover:border-red-500/40 hover:text-red-400",children:"✕"}),r?e.jsx(Fe,{noteId:t,attachment:a,label:x,onClose:()=>l(!1)}):null]})}function Fe({noteId:t,attachment:a,label:r,onClose:l}){const x=H(o=>o.push),i=oe(),[u,m]=n.useState(!1),[f,N]=n.useState(null),d=n.useRef(null);n.useEffect(()=>{const o=setTimeout(()=>m(!0),Ie);return()=>clearTimeout(o)},[]),n.useEffect(()=>{var o;(o=d.current)==null||o.focus()},[]),n.useEffect(()=>{const o=k=>{k.key==="Escape"&&l()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[l]);const g=n.useCallback(()=>{!u||i.isPending||(N(null),i.mutate({noteId:t,attachmentId:a.id},{onSuccess:()=>{x(`Removed ${r}`,"success"),l()},onError:o=>{if(o instanceof I){N("Session expired. Reconnect to remove attachments.");return}if(o instanceof le){x(`Already removed ${r}`,"info"),l();return}N(o instanceof Error?o.message:"Remove failed")}}))},[u,a.id,r,i,t,l,x]);return e.jsx("dialog",{open:!0,"aria-labelledby":"confirm-remove-attachment-title",className:"fixed inset-0 z-40 m-0 flex h-full max-h-full w-full max-w-full items-center justify-center bg-black/60 p-4",onMouseDown:o=>{o.target===o.currentTarget&&l()},children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-border bg-card p-6 shadow-lift",children:[e.jsx("h2",{id:"confirm-remove-attachment-title",className:"mb-2 font-serif text-lg text-red-400",children:"Remove attachment?"}),e.jsxs("p",{className:"mb-3 text-sm text-fg-muted",children:[e.jsx("span",{className:"rounded bg-bg/60 px-1 py-0.5 font-mono text-xs text-fg",children:r})," ","will be detached from this note. If no other note references the file, it will also be deleted from storage. Markdown referencing it will show a broken link until you update it."]}),f?e.jsx("p",{role:"alert",className:"mb-3 text-sm text-red-400",children:f}):null,e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{ref:d,type:"button",onClick:l,className:"min-h-11 rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-fg-muted hover:text-fg",children:"Cancel"}),e.jsx("button",{type:"button",onClick:g,disabled:!u||i.isPending,className:"btn btn-danger-solid btn-touch",children:i.isPending?"Removing…":"Remove"})]})]})})}function Le(t){if(t.filename)return t.filename;if(t.path){const a=t.path.split("/").pop();return a||t.path}return t.id}function Ge(){const{id:t}=ce(),a=K(l=>l.getActiveVault()),r=de(t);return a?e.jsxs("div",{className:"page",children:[e.jsx("nav",{className:"mb-6 text-sm text-fg-dim",children:e.jsx($,{to:t?`/n/${encodeURIComponent(t)}`:"/",className:"focus-ring hover:text-accent",children:"← Back to note"})}),r.isPending?e.jsx(Ve,{}):r.isError?e.jsx(_e,{error:r.error}):r.data?e.jsx(Be,{note:r.data}):e.jsx(Oe,{id:t??""})]}):e.jsx(ue,{to:"/",replace:!0})}function S(t){return{content:t.content??"",path:t.path??"",tags:[...t.tags??[]]}}function Be({note:t}){const a=he(),r=H(s=>s.push),l=q(s=>s.on),x=q(s=>s.setOn),i=n.useRef(K.getState().activeVaultId).current,u=n.useRef(Pe()).current,m=n.useMemo(()=>De(t),[t]),[f,N]=n.useState(()=>S(t)),[d,g]=n.useState(()=>S(t)),[o,k]=n.useState(()=>{if(!i)return null;const s=xe(i,t.id);return!s||pe(s.body,S(t))?null:s}),[Z,L]=n.useState(""),[B,C]=n.useState(null),[M,E]=n.useState(null),[U,V]=n.useState(!1),w=n.useRef(null);n.useEffect(()=>()=>{w.current!==null&&window.clearTimeout(w.current)},[]);const[R,G]=n.useState("edit"),j=ge(t.id),A=n.useRef(t),P=n.useRef(null),O=n.useRef(null),v=Se({noteId:t.id,onInsert:s=>{P.current?P.current.insertAtCursor(s):g(c=>({...c,content:`${c.content}${s}`}))},onLinked:()=>{r("Attachment added","success")},onError:s=>r(s,"error")});n.useEffect(()=>{A.current=t},[t]);const h=d.content!==f.content||d.path!==f.path||!We(d.tags,f.tags);be(i,t.id,d,h);const y=v.uploads.some(s=>s.status==="uploading"||s.status==="linking"),D=n.useCallback(({navigateToView:s})=>{if(!h||j.isPending||y)return;const c={};d.content!==f.content&&(c.content=d.content),d.path!==f.path&&(c.path=d.path);const b=ze(f.tags,d.tags);(b.add.length||b.remove.length)&&(c.tags=b);const z=A.current.updatedAt??A.current.createdAt;z&&(c.if_updated_at=z),E(null),C(null),j.mutate(c,{onSuccess:p=>{N(S(p)),g(S(p)),A.current=p,i&&T(i,t.id),s?a(`/n/${encodeURIComponent(p.id)}`,{replace:!0}):p.id!==t.id&&a(`/n/${encodeURIComponent(p.id)}/edit`,{replace:!0}),s||(V(!0),w.current!==null&&window.clearTimeout(w.current),w.current=window.setTimeout(()=>V(!1),1500))},onError:p=>{p instanceof ve?C(p):p instanceof I?E("Session expired. Reconnect to save."):E(p instanceof Error?p.message:"Save failed")}})},[f,d,h,j,a,t.id,y,i]),Q=n.useCallback(()=>{o&&g(o.body),k(null)},[o]),X=n.useCallback(()=>{i&&T(i,t.id),k(null)},[i,t.id]),ee=n.useCallback(()=>D({navigateToView:!0}),[D]),te=n.useCallback(()=>D({navigateToView:!1}),[D]),se=n.useCallback(()=>{h&&confirm("Discard all edits and revert to last saved version?")&&(g(f),C(null),E(null))},[f,h]),_=n.useCallback(()=>{h&&!confirm("Discard unsaved changes?")||(i&&T(i,t.id),a(`/n/${encodeURIComponent(t.id)}`))},[h,a,t.id,i]);n.useEffect(()=>{if(!h)return;const s=c=>{c.preventDefault(),c.returnValue=""};return window.addEventListener("beforeunload",s),()=>window.removeEventListener("beforeunload",s)},[h]);const ne=d.path!==f.path,ae=s=>{const c=we(s);c&&(d.tags.includes(c)||(g(b=>({...b,tags:[...b.tags,c]})),L("")))},re=s=>{g(c=>({...c,tags:c.tags.filter(b=>b!==s)}))},ie=d.content,W=l?"h-[85dvh]":"h-[60dvh]";return e.jsxs("article",{children:[l?e.jsx("div",{className:"glass-panel enter-fade fixed top-4 left-4 z-30 rounded-full border border-border px-3 py-1.5 text-xs shadow-lift",style:{marginTop:"env(safe-area-inset-top)"},children:e.jsx(Y,{isDirty:h,justSaved:U,updatedAt:t.updatedAt})}):e.jsxs("header",{className:"card mb-6 p-5 shadow-soft md:p-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"eyebrow",children:"Editing"}),e.jsx(Y,{isDirty:h,justSaved:U,updatedAt:t.updatedAt})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Re,{note:t}),e.jsx(Ae,{note:t}),e.jsxs("button",{type:"button",onClick:()=>x(!0),className:"btn btn-ghost btn-touch",title:"Focus (⌘.)",children:[e.jsx(je,{width:16,height:16}),"Focus"]}),e.jsx("span",{className:"mx-1 h-5 w-px bg-border","aria-hidden":"true"}),e.jsx("button",{type:"button",onClick:se,disabled:!h||j.isPending,className:"btn btn-secondary btn-touch",children:"Revert"}),e.jsx("button",{type:"button",onClick:_,className:"btn btn-secondary btn-touch",children:"Cancel"}),e.jsx("button",{type:"button",onClick:ee,disabled:!h||j.isPending||y,className:"btn btn-primary btn-touch",title:y?"Waiting for upload…":"Save (⌘S)","aria-label":y?"Save — waiting for upload…":"Save",children:j.isPending?"Saving…":"Save"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Ne,{tags:d.tags,input:Z,onInputChange:L,onAdd:ae,onRemove:re})}),e.jsxs("div",{className:"mt-4 flex items-center gap-2 text-fg-dim",children:[e.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-xs",children:"Path"}),e.jsx("input",{type:"text",value:d.path,onChange:s=>g(c=>({...c,path:s.target.value})),className:"focus-ring w-full min-w-0 truncate rounded border-0 bg-transparent font-mono text-xs text-fg-dim outline-none transition-colors hover:text-fg-muted focus:text-fg placeholder:text-fg-dim","aria-label":"Note path",placeholder:"(no path)",title:d.path||void 0})]}),ne?e.jsx("p",{className:"mt-1 text-xs text-accent",children:"Renaming moves the note — its id may change."}):null]}),o?e.jsxs("div",{role:"status","data-testid":"draft-offer",className:"mb-4 flex flex-wrap items-center justify-between gap-2 rounded-xl border border-accent/30 bg-accent/5 px-3 py-2 text-sm",children:[e.jsxs("span",{className:"text-fg-muted",children:["You have an unsaved draft from ",F(o.savedAt),"."]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:Q,className:"focus-ring font-medium text-accent hover:underline",children:"Restore"}),e.jsx("button",{type:"button",onClick:X,className:"focus-ring text-fg-dim hover:text-danger",children:"Discard"})]})]}):null,B?e.jsx(Ue,{conflict:B,onReload:()=>{i&&T(i,t.id),window.location.reload()},onDismiss:()=>C(null)}):null,M?e.jsx("div",{className:"mb-4 rounded-xl border border-danger-border bg-danger-soft p-3 text-sm text-danger",children:M}):null,u?null:e.jsx("div",{role:"tablist","aria-label":"Editor view",className:"mb-3 inline-flex rounded-lg border border-border bg-card p-0.5 text-sm lg:hidden",children:["edit","preview"].map(s=>e.jsx("button",{type:"button",role:"tab","aria-selected":R===s,onClick:()=>G(s),className:`rounded-sm px-3 py-1.5 capitalize ${R===s?"bg-accent text-on-accent":"text-fg-muted hover:text-accent"}`,children:s},s))}),e.jsxs("div",{className:`grid ${l?"min-h-[85dvh]":"min-h-[60dvh]"} gap-4 ${u?"":"lg:grid-cols-2"}`,children:[e.jsx(ye,{onDropFiles:v.start,className:`card min-h-0 ${W} min-w-0 ${u||R==="edit"?"":"hidden lg:block"}`,hint:J,children:e.jsx(ke,{ref:P,value:d.content,onChange:s=>g(c=>({...c,content:s})),onSave:te,onCancel:_,onPasteFile:s=>(v.start(s),!0),onRequestAttachment:()=>{var s;return(s=O.current)==null?void 0:s.open()},livePreview:u})}),u?null:e.jsx("div",{className:`card min-h-0 ${W} min-w-0 overflow-auto p-4 ${R==="preview"?"":"hidden lg:block"}`,children:e.jsx(Te,{note:{path:d.path,content:ie},resolve:m})})]}),e.jsx(Me,{noteId:t.id,pickerRef:O,attachments:t.attachments??[],uploads:v.uploads,onPickFiles:v.start,onCancel:v.cancel,onDismiss:v.dismiss})]})}const J=e.jsxs(e.Fragment,{children:["Images, audio, webm video."," ",e.jsx("a",{href:"https://github.com/ParachuteComputer/parachute-vault/issues/127",target:"_blank",rel:"noreferrer",className:"text-accent hover:underline",children:"PDF + mp4 coming"})]});function Me({noteId:t,pickerRef:a,attachments:r,uploads:l,onPickFiles:x,onCancel:i,onDismiss:u}){return e.jsxs("section",{className:"mt-6 border-t border-border pt-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("h2",{className:"font-serif text-xl",children:"Attachments"}),e.jsx(Ce,{ref:a,onPickFiles:x})]}),e.jsxs("p",{className:"mb-3 text-xs text-fg-dim",children:["Drop or paste files into the editor. Max 100 MB each. ",J,"."]}),e.jsx(Ee,{uploads:l,onCancel:i,onDismiss:u}),r.length>0?e.jsx("ul",{className:"mt-3 space-y-1 text-sm",children:r.map(m=>e.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-lg border border-border bg-card/50 px-3 py-1.5 font-mono text-xs",children:[e.jsx("span",{className:"truncate",title:m.path??m.id,children:m.filename??m.path??m.id}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[m.mimeType?e.jsx("span",{className:"text-fg-dim",children:m.mimeType}):null,e.jsx($e,{noteId:t,attachment:m})]})]},m.id))}):null]})}function Ue({conflict:t,onReload:a,onDismiss:r}){return e.jsxs("div",{className:"mb-4 rounded-xl border border-warning bg-warning-soft p-4",children:[e.jsx("p",{className:"mb-1 font-medium text-warning",children:"This note was edited elsewhere."}),e.jsxs("p",{className:"mb-3 text-sm text-fg-muted",children:["Your save was rejected to avoid overwriting the other edit.",t.currentUpdatedAt?` Latest update ${F(t.currentUpdatedAt)}.`:""]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:a,className:"btn btn-primary btn-touch",children:"Reload latest (discard my edits)"}),e.jsx("button",{type:"button",onClick:r,className:"btn btn-secondary btn-touch",children:"Keep editing"})]})]})}function Ve(){return e.jsxs("div",{className:"grid min-h-[60dvh] gap-4 lg:grid-cols-2","aria-busy":"true",children:[e.jsx("div",{className:"card animate-pulse"}),e.jsx("div",{className:"card animate-pulse"})]})}function Oe({id:t}){return e.jsx(fe,{title:e.jsx("span",{className:"font-serif text-xl text-fg",children:"Note not found"}),description:e.jsxs(e.Fragment,{children:["No note with id ",e.jsx("span",{className:"font-mono",children:t})," in this vault."]}),action:e.jsx($,{to:"/notes",className:"text-sm text-accent hover:underline",children:"Back to all notes"})})}function Y({isDirty:t,justSaved:a,updatedAt:r}){return t?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-accent","aria-label":"unsaved changes",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-accent"}),"unsaved"]}):a?e.jsx("span",{className:"text-xs text-accent","aria-label":"saved",children:"Saved ✓"}):e.jsxs("span",{className:"text-xs text-fg-dim",children:["saved ",F(r)]})}function _e({error:t}){const a=t instanceof I;return e.jsx(me,{title:a?"Session expired":"Could not load note",message:t.message,action:a?e.jsx($,{to:"/add",className:"btn btn-primary",children:"Reconnect vault"}):void 0})}function We(t,a){if(t.length!==a.length)return!1;const r=new Set(t);for(const l of a)if(!r.has(l))return!1;return!0}function ze(t,a){const r=new Set(t),l=new Set(a),x=a.filter(u=>!r.has(u)),i=t.filter(u=>!l.has(u));return{add:x,remove:i}}export{Ge as NoteEditor};
@@ -0,0 +1,8 @@
1
+ import{ap as Me,r as o,aq as $e,ar as _e,as as ge,a as Le,b as Ue,a6 as qe,at as Fe,au as Ve,av as Oe,aw as Be,a1 as Ge,a5 as We,ax as He,ah as ze,ay as Qe,y as Ye,ak as Je,j as e,N as Ke,az as Ze,aA as xe,V as Xe,al as B,aB as et,aC as tt,aD as Z,aE as st,aF as nt,aG as at,aH as P,L as rt,an as ot,x as it,aI as ct,ao as lt}from"./index-Dwo2xe8_.js";import{v as dt,A as ut}from"./attachment-upload-l7qA8_xw.js";import{u as mt,C as pt,A as ft,a as ht}from"./useAttachmentUploader-C3UnTg01.js";import{b as gt,N as xt}from"./NoteRenderer-Dl9X9uRt.js";import{l as be,u as bt,a as vt,b as yt}from"./transcribe-default-LVAxyzpn.js";import{r as jt}from"./editor-mode-D9fveTEx.js";import"./types-BaJkUfo6.js";const kt=10*6e4;function wt(t){const c=t.segmentMs??kt,l=t.setTimer??((n,w)=>setTimeout(n,w)),x=t.clearTimer??(n=>clearTimeout(n)),k=t.makeRecorder??(n=>Me({...n})),g=[];let a=null,d=null,p="idle",u=0;const h=()=>{for(const n of t.stream.getTracks())n.stop()},y=()=>{d!==null&&(x(d),d=null)},f=()=>{d=l(()=>{d=null,m()},c)},i=()=>{a=k({stream:t.stream,mimeType:t.mimeType,releaseStreamOnStop:!1,now:t.now,MediaRecorderCtor:t.MediaRecorderCtor}),a.start(),u+=1,f()},m=()=>{var n;p!=="recording"||!a||(g.push(a.stop()),i(),(n=t.onRoll)==null||n.call(t,u))};return{get state(){return p},get activePart(){return u},start(){if(p!=="idle")throw new Error(`Cannot start from ${p}`);p="recording",i()},async stop(){if(p!=="recording"||!a)throw new Error(`Cannot stop from ${p}`);p="stopped",y(),g.push(a.stop()),a=null;const n=await Promise.all(g);return h(),n},cancel(){y(),a&&a.cancel(),a=null,p="stopped",h()}}}function Rt(){const[t,c]=o.useState({kind:"idle"}),[l,x]=o.useState(0),[k,g]=o.useState(0),a=o.useRef(null),d=o.useRef(null);o.useEffect(()=>{if(t.kind!=="recording")return;const f=setInterval(()=>x(Date.now()-t.startedAt),250);return()=>clearInterval(f)},[t]),o.useEffect(()=>()=>{d.current&&URL.revokeObjectURL(d.current),a.current&&a.current.state==="recording"&&a.current.cancel()},[]);const p=o.useCallback(async()=>{if(!(t.kind==="recording"||t.kind==="requesting")){c({kind:"requesting"});try{const f=$e();if(!f){c({kind:"denied",message:"This browser can't record audio in a format we can save."});return}const i=await _e(),m=wt({stream:i,mimeType:f,onRoll:n=>g(n)});a.current=m,m.start(),x(0),g(m.activePart),c({kind:"recording",startedAt:Date.now()})}catch(f){const i=f,m=i.kind==="permission-denied"?"Microphone access was denied. Update your browser's site settings to record.":i.kind==="no-device"?"No microphone was found on this device.":i instanceof Error?i.message:"Microphone is not available in this browser.";c({kind:"denied",message:m})}}},[t]),u=o.useCallback(async()=>{var i;const f=a.current;if(!(!f||t.kind!=="recording"))try{const m=await f.stop();a.current=null,g(0);const n=((i=m[0])==null?void 0:i.mimeType)??"",w=m.reduce((G,L)=>G+L.durationMs,0),T=m[0],D=T?URL.createObjectURL(new Blob([T.data],{type:T.mimeType})):"";d.current&&URL.revokeObjectURL(d.current),d.current=D||null,c({kind:"have-audio",segments:m,mimeType:n,url:D,durationMs:w})}catch(m){console.warn(m instanceof Error?`Recording failed: ${m.message}`:"Recording failed."),g(0),c({kind:"idle"})}},[t]),h=o.useCallback(()=>{d.current&&(URL.revokeObjectURL(d.current),d.current=null),c({kind:"idle"}),x(0),g(0)},[]),y=o.useCallback(()=>{h()},[h]);return{phase:t,elapsedMs:l,parts:k,startRecording:p,stopRecording:u,discardAudio:h,reset:y}}function Nt(t){const{segments:c,mimeType:l,recordedAt:x,willTranscribe:k}=t,g=c.length>1,a=t.typedText.trim(),d=c.map((y,f)=>({filename:g?ge(l,x,f+1):ge(l,x),transcribe:k,...k&&g?{metadata:{segment_index:f}}:{}})),p=k?g?c.map((y,f)=>`_Transcript pending (part ${f+1})._`).join(`
2
+
3
+ `):"_Transcript pending._":"",u=d.map(y=>`![[${y.filename}]]`).join(`
4
+
5
+ `),h=[];return a&&h.push(a),p&&h.push(p),h.push(u),{body:`${h.join(`
6
+
7
+ `)}
8
+ `,segments:d}}const ve={content:"",path:"",tags:[]};function _t(){const t=Le(s=>s.getActiveVault()),c=Ue(),l=qe(s=>s.push),x=Fe(),k=Ve(),g=Oe(),{db:a,blobStore:d,engine:p}=Be(),{roles:u}=Ge((t==null?void 0:t.id)??null),h=We(),y=o.useRef(He()),f=o.useRef(jt()).current,i=o.useRef((t==null?void 0:t.id)??null).current,m=o.useRef(null),[n,w]=o.useState(()=>{if(i){const s=ze(i,P);if(s)return m.current=s.savedAt,s.body}return{...ve,path:y.current}}),[T,D]=o.useState(()=>m.current),[G,L]=o.useState(""),[ee,C]=o.useState(null),[U,je]=o.useState([]),[ke,te]=o.useState(!1),W=o.useRef(null),se=o.useRef(null),b=Rt(),I=Qe(),R=I.capability,ne=b.phase.kind==="requesting"||b.phase.kind==="recording"||b.phase.kind==="have-audio",we=(R==null?void 0:R.enabled)===!1&&!ne,H=typeof(R==null?void 0:R.minutes_remaining)=="number"?R.minutes_remaining:void 0,z=H!==void 0&&H<=0,[Q,ae]=o.useState(()=>i?be(i):!0),Re=(R==null?void 0:R.enabled)!==!1,re=o.useRef(b.phase.kind);o.useEffect(()=>{const s=re.current,r=b.phase.kind;re.current=r,r==="idle"&&s!=="idle"&&i&&ae(be(i))},[b.phase.kind,i]);const[Ne]=Ye(),oe=Ne.has("voice"),ie=o.useRef(!1);o.useEffect(()=>{var s;!oe||ie.current||I.settled&&((s=I.capability)==null?void 0:s.enabled)!==!1&&(ie.current=!0,b.startRecording())},[oe,I.settled,I.capability,b.startRecording]);const S=mt({noteId:null,onInsert:s=>{W.current?W.current.insertAtCursor(s):w(r=>({...r,content:`${r.content}${s}`}))},onStaged:s=>je(r=>[...r,s]),onError:s=>l(s,"error")}),M=o.useRef(m.current!==null),q=o.useRef(null);o.useEffect(()=>{M.current||(w(s=>{const r=q.current?s.tags.filter(E=>E!==q.current):s.tags,v=r.includes(u.captureText)?r:[...r,u.captureText];return v===s.tags?s:{...s,tags:v}}),q.current=u.captureText)},[u.captureText]);const ce=!M.current&&(n.tags.length===0||n.tags.length===1&&n.tags[0]===u.captureText),Te=n.content.trim().length>0||!ce||n.path.trim().length>0&&n.path!==y.current;if(Je(i,P,n,Te),!t)return e.jsx(Ke,{to:"/",replace:!0});const F=b.phase.kind==="have-audio",Y=n.content.trim().length>0,V=n.content.length>0||n.path!==y.current||!ce||F,$=n.path.trim().length>0&&(Y||F),A=x.isPending||ke,le=o.useCallback(()=>{if(!$||A)return;const s=Ze({content:n.content,path:n.path,tags:n.tags});h&&xe(t.id,h),C(null),x.mutate(s,{onSuccess:async r=>{for(const v of U)try{await k.mutateAsync({noteId:r.id,path:v.path,mimeType:v.mimeType})}catch(E){const J=E instanceof Error?E.message:"Link failed";l(`Failed to attach ${v.filename}: ${J}`,"error")}i&&B(i,P),l(`Created ${r.path??r.id}`,"success"),c(`/n/${encodeURIComponent(r.id)}`,{replace:!0})},onError:r=>{r instanceof Xe?C("Session expired. Reconnect to save."):C(r instanceof Error?`${r.message} — if the path is taken, try a different one.`:"Create failed")}})},[t,i,h,n,$,k,x,c,A,l,U]),de=o.useCallback(async()=>{if(!$||A||b.phase.kind!=="have-audio")return;if(!a||!d){l("Sync queue not ready — try again in a moment.","error");return}C(null);const s=b.phase,r=s.segments,v=s.mimeType,E=n.path.trim(),J=n.tags,Pe=et(n.content),pe=Array.from(new Set([u.captureVoice,...J,...Pe].filter(j=>j.length>0)));Y&&pe.push(u.captureText);const fe=Array.from(new Set(pe)),De=new Date,_=tt(),Ie=!z&&Q,O=Nt({segments:r,mimeType:v,typedText:n.content,recordedAt:De,willTranscribe:Ie});for(let j=0;j<r.length;j++){const N=dt(new File([r[j].data],O.segments[j].filename,{type:v}));if(N){l(N,"error"),C(N);return}}te(!0),h&&xe(t.id,h);const he={content:O.body,path:E,metadata:{source:"voice"},...fe.length?{tags:fe}:{}};try{await Z(a,{kind:"create-note",localId:_,payload:he},{vaultId:t.id});for(let j=0;j<O.segments.length;j++){const N=O.segments[j],K=st();await d.put(K,r[j].data,v,t.id),await Z(a,{kind:"upload-attachment",blobId:K,filename:N.filename,mimeType:v},{vaultId:t.id}),await Z(a,{kind:"link-attachment",noteId:_,pathRef:nt(K),mimeType:v,transcribe:N.transcribe,...N.metadata?{metadata:N.metadata}:{}},{vaultId:t.id})}p==null||p.runOnce(),g.setQueryData(["note",t.id,_],at(he,_)),i&&B(i,P),l("Captured — syncing audio.","success"),b.discardAudio(),c(`/n/${encodeURIComponent(_)}`,{replace:!0})}catch(j){l(j instanceof Error?`Capture failed: ${j.message}`:"Capture failed.","error"),C(j instanceof Error?j.message:"Capture failed")}finally{te(!1)}},[t,i,d,h,a,n,p,Y,$,c,z,A,l,g,u.captureText,u.captureVoice,Q,b]),ue=o.useCallback(()=>{F?de():le()},[F,le,de]),me=o.useCallback(()=>{V&&!confirm("Discard this draft?")||(i&&B(i,P),b.discardAudio(),c("/"))},[i,V,c,b]),Ce=o.useCallback(()=>{i&&B(i,P),M.current=!1,q.current=u.captureText,w({...ve,path:y.current,tags:[u.captureText]}),b.discardAudio(),D(null)},[i,b,u.captureText]);o.useEffect(()=>{if(!V)return;const s=r=>{r.preventDefault(),r.returnValue=""};return window.addEventListener("beforeunload",s),()=>window.removeEventListener("beforeunload",s)},[V]);const Se=s=>{const r=lt(s);!r||n.tags.includes(r)||(M.current=!0,w(v=>({...v,tags:[...v.tags,r]})),L(""))},Ae=s=>{M.current=!0,w(r=>({...r,tags:r.tags.filter(v=>v!==s)}))},Ee=gt({id:"__new__",createdAt:new Date().toISOString()});return e.jsxs("div",{className:"page",children:[e.jsx("nav",{className:"mb-6 text-sm text-fg-dim",children:e.jsx(rt,{to:"/notes",className:"hover:text-accent",children:"← All notes"})}),e.jsxs("article",{children:[e.jsxs("header",{className:"composer mb-6 p-5 md:p-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("span",{className:"eyebrow",children:"New note"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:me,className:"btn btn-secondary btn-touch",children:"Cancel"}),e.jsx("button",{type:"button",onClick:ue,disabled:!$||A,className:"btn btn-primary btn-touch",title:"Create (⌘S)",children:A?"Creating…":"Create"})]})]}),e.jsx("input",{type:"text",value:n.path,onChange:s=>w(r=>({...r,path:s.target.value})),className:n.path===y.current?"mt-4 w-full border-0 bg-transparent font-sans text-sm text-fg-dim outline-none placeholder:text-fg-dim":"mt-4 w-full border-0 bg-transparent font-serif text-2xl text-fg outline-none placeholder:text-fg-dim md:text-3xl","aria-label":"Note path",placeholder:"Name your note — or just start writing"}),e.jsx("div",{className:"mt-4",children:e.jsx(ot,{tags:n.tags,input:G,onInputChange:L,onAdd:Se,onRemove:Ae})})]}),T?e.jsxs("div",{role:"status","data-testid":"draft-restored",className:"mb-4 flex flex-wrap items-center justify-between gap-2 rounded-xl border border-accent/30 bg-accent/5 px-3 py-2 text-sm",children:[e.jsxs("span",{className:"text-fg-muted",children:["Unsaved draft restored from ",it(T),"."]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:Ce,className:"text-fg-dim hover:text-danger",children:"Discard draft"}),e.jsx("button",{type:"button",onClick:()=>D(null),"aria-label":"Dismiss draft-restored notice",className:"text-fg-dim hover:text-accent",children:"✕"})]})]}):null,ee?e.jsx("div",{role:"alert",className:"mb-4 rounded-xl border border-danger-border bg-danger-soft p-3 text-sm text-danger",children:ee}):null,we?e.jsx(ct,{capability:R}):e.jsxs(e.Fragment,{children:[e.jsx(St,{voice:b,minutesRemaining:H,outOfMinutes:z,transcribe:Q,onTranscribeChange:ae,showTranscribeToggle:Re}),e.jsx(Tt,{vaultId:t.id,captureEngaged:ne})]}),e.jsxs("div",{className:`grid min-h-[60dvh] gap-4 ${f?"":"lg:grid-cols-2"}`,children:[e.jsx(ut,{onDropFiles:S.start,className:"card min-h-0 h-[60dvh] min-w-0",hint:"Images, audio, webm video",children:e.jsx(pt,{ref:W,value:n.content,onChange:s=>w(r=>({...r,content:s})),onSave:ue,onCancel:me,placeholder:"Start writing…",onPasteFile:s=>(S.start(s),!0),onRequestAttachment:()=>{var s;return(s=se.current)==null?void 0:s.open()},livePreview:f})}),f?null:e.jsx("div",{className:"card min-w-0 overflow-auto p-4 lg:h-[60dvh] lg:min-h-0",children:n.content.trim()?e.jsx(xt,{note:{path:n.path,content:n.content},resolve:Ee}):e.jsx("p",{className:"text-sm text-fg-dim",children:"Preview appears here as you type."})})]}),e.jsxs("section",{className:"mt-6 border-t border-border pt-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("h2",{className:"font-serif text-xl",children:"Attachments"}),e.jsx(ft,{ref:se,onPickFiles:S.start})]}),e.jsxs("p",{className:"mb-3 text-xs text-fg-dim",children:["Drop or paste files into the editor. Attachments link to the note when you save. Max 100 MB each. Images, audio, webm video."," ",e.jsx("a",{href:"https://github.com/ParachuteComputer/parachute-vault/issues/127",target:"_blank",rel:"noreferrer",className:"text-accent hover:underline",children:"PDF + mp4 coming"}),"."]}),e.jsx(ht,{uploads:S.uploads,onCancel:S.cancel,onDismiss:S.dismiss}),U.length>0?e.jsx("ul",{className:"mt-3 space-y-1 text-sm",children:U.map(s=>e.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-lg border border-border bg-card/50 px-3 py-1.5 font-mono text-xs text-fg-muted",children:[e.jsx("span",{className:"truncate",children:s.filename}),e.jsx("span",{className:"shrink-0 text-fg-dim",children:"staged"})]},s.path))}):null]})]})]})}function Tt({vaultId:t,captureEngaged:c}){const l=bt(),x=vt(),{made:k,markMade:g}=yt(t),[a,d]=o.useState(null);if(!(c&&!k&&l.supported&&l.value==="keep"))return null;const u=h=>{d(null),x.mutate(h,{onSuccess:()=>g(),onError:()=>d("Couldn't save that choice — this recording is kept (the vault default). We'll ask again next time; you can also set it in Settings.")})};return e.jsxs("div",{"data-testid":"retention-choice",className:"mb-4 flex flex-col gap-2 rounded-xl border border-border bg-card/60 p-3",children:[e.jsx("p",{className:"text-xs text-fg-muted",children:"First voice note here — should this vault keep your audio files after transcribing?"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>u("keep"),disabled:x.isPending,className:"btn btn-secondary btn-touch",children:"Keep my recordings"}),e.jsx("button",{type:"button",onClick:()=>u("until_transcribed"),disabled:x.isPending,className:"btn btn-secondary btn-touch",children:"Just keep the words"}),e.jsx("span",{className:"text-xs text-fg-dim",children:"(audio deleted after transcribing)"})]}),e.jsx("p",{className:"text-xs text-fg-dim",children:"Either way your capture saves now. Change this anytime in Settings."}),a?e.jsx("p",{className:"text-xs text-danger","data-testid":"retention-choice-error",children:a}):null]})}const Ct=30;function ye({checked:t,disabled:c,onChange:l}){return e.jsxs("div",{className:"flex basis-full items-center justify-between gap-3",children:[e.jsx("span",{className:"text-xs text-fg-dim",children:"Transcribe this recording"}),e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":"Transcribe this recording","data-testid":"transcribe-toggle",disabled:c,onClick:()=>l(!t),className:`relative h-7 w-12 shrink-0 rounded-full transition-colors disabled:opacity-40 ${t?"bg-accent":"bg-border"}`,children:e.jsx("span",{className:`absolute top-0.5 h-6 w-6 rounded-full bg-card shadow-sm transition-transform ${t?"translate-x-5":"translate-x-0.5"}`})})]})}function St({voice:t,minutesRemaining:c,outOfMinutes:l,transcribe:x,onTranscribeChange:k,showTranscribeToggle:g}){const{phase:a,elapsedMs:d,parts:p,startRecording:u,stopRecording:h,discardAudio:y}=t,f=a.kind==="recording",i=a.kind==="requesting",m=!l&&x,n=typeof c=="number"&&c<=Ct;return a.kind==="have-audio"?e.jsxs("div",{className:"mb-4 flex flex-col gap-2 rounded-xl border border-accent/30 bg-accent/5 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"text-sm text-fg-muted",children:["🎙 Recorded ",X(a.durationMs),a.segments.length>1?` · ${a.segments.length} parts`:""]}),e.jsx("button",{type:"button",onClick:y,className:"text-xs text-fg-dim hover:text-danger",children:"Discard"})]}),e.jsx("audio",{controls:!0,src:a.url,className:"w-full",children:e.jsx("track",{kind:"captions"})}),g?e.jsx(ye,{checked:m,disabled:l,onChange:k}):null,e.jsx("p",{className:"text-xs text-fg-dim",children:l?"Saved as audio-only — you're out of transcription minutes this month.":m?"Transcript will be appended once your vault processes it. Save to commit.":"Saved as audio-only — transcription is off for this recording."})]}):e.jsxs("div",{className:"mb-4 flex flex-wrap items-center justify-between gap-3 rounded-xl border border-border bg-card/60 p-3",children:[e.jsx("div",{className:"text-xs text-fg-dim",children:f?p>1?`Recording — tap Stop to finish. (part ${p})`:"Recording — tap Stop to finish.":i?"Requesting microphone…":l?"You're out of transcription minutes this month — this saves as audio-only.":m?"Add a voice memo to this note. Audio gets transcribed and appended.":"Add a voice memo to this note. Saved as audio-only — transcription is off for this recording."}),f?e.jsxs("button",{type:"button",onClick:()=>void h(),"aria-label":`Recording — ${X(d)} — stop`,"aria-pressed":"true",className:"flex min-h-11 items-center gap-2 rounded-full border border-danger-border bg-danger-soft px-4 py-2 text-sm font-medium text-danger",children:[e.jsx("span",{"aria-hidden":"true",className:"animate-pulse",children:"🎙"}),e.jsxs("span",{children:["Stop ",X(d)]})]}):e.jsxs("button",{type:"button",onClick:()=>void u(),"aria-label":"Record voice memo",disabled:i,className:"flex min-h-11 items-center gap-2 rounded-full border border-accent/30 bg-accent/10 px-4 py-2 text-sm font-medium text-accent hover:bg-accent/15 disabled:opacity-40",children:[e.jsx("span",{"aria-hidden":"true",children:"🎙"}),e.jsx("span",{children:i?"Requesting…":"Record"})]}),g?e.jsx(ye,{checked:m,disabled:l,onChange:k}):null,n&&!l?e.jsxs("p",{className:"basis-full text-xs text-fg-dim","data-testid":"voice-minutes-left",children:["About ",Math.round(c)," min of transcription left this month."]}):null,a.kind==="denied"?e.jsx("p",{className:"basis-full rounded-xl border border-danger-border bg-danger-soft px-3 py-2 text-xs text-danger",children:a.message}):null]})}function X(t){const c=Math.floor(t/1e3),l=Math.floor(c/60),x=c%60;return`${String(l).padStart(2,"0")}:${String(x).padStart(2,"0")}`}export{_t as NoteNew};