ocean-brain 0.3.3 → 0.3.4

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 (34) hide show
  1. package/dist/mcp.js +151 -37
  2. package/package.json +1 -1
  3. package/server/client/dist/assets/{Calendar-DyXzs5M3.js → Calendar-Kjy1PX6L.js} +1 -1
  4. package/server/client/dist/assets/{Graph-C8K4PJOn.js → Graph-Bl5K2qUw.js} +1 -1
  5. package/server/client/dist/assets/{Image.es-CFTbON7k.js → Image.es-BQfyKc2-.js} +1 -1
  6. package/server/client/dist/assets/{ModalActionRow-Hg6MY61u.js → ModalActionRow-DyOb58KJ.js} +1 -1
  7. package/server/client/dist/assets/Note-BfGma2Qc.css +1 -0
  8. package/server/client/dist/assets/Note-DN_ko2M3.js +1 -0
  9. package/server/client/dist/assets/{Reminders-jFhljND4.js → Reminders-BK-Uv9Ps.js} +1 -1
  10. package/server/client/dist/assets/{Search-X6QIR_m2.js → Search-ClHeWvmI.js} +1 -1
  11. package/server/client/dist/assets/{SurfaceCard-BV6y4bCo.js → SurfaceCard-nZNf9lyE.js} +1 -1
  12. package/server/client/dist/assets/{Tag-Ba2Dw4gH.js → Tag-Dph4V_kl.js} +1 -1
  13. package/server/client/dist/assets/{TagNotes-BRJv6sDI.js → TagNotes-CxP5qHZj.js} +1 -1
  14. package/server/client/dist/assets/{Trash.es-CPtRLE0y.js → Trash.es-BGoN5q9L.js} +1 -1
  15. package/server/client/dist/assets/{image.api-Dsrx9S-G.js → image.api-0mMkElZk.js} +1 -1
  16. package/server/client/dist/assets/{index-DpqKngJz.js → index-6lIw6jYW.js} +1 -1
  17. package/server/client/dist/assets/{index-BglnLSet.js → index-Ba2XPRI8.js} +30 -30
  18. package/server/client/dist/assets/{index-CD2bFEqK.css → index-DL7pUwq2.css} +1 -1
  19. package/server/client/dist/assets/manage-image-Br_kKxbb.js +1 -0
  20. package/server/client/dist/assets/{manage-image-detail-Dv3xofpe.js → manage-image-detail-9DzqbiqI.js} +1 -1
  21. package/server/client/dist/assets/{mcp-BijQkpfY.js → mcp-C_So91eX.js} +1 -1
  22. package/server/client/dist/assets/{placeholder-MNsco0AT.js → placeholder-i-uNe71U.js} +2 -2
  23. package/server/client/dist/assets/{trash-CiFJm_PK.js → trash-Cg3nJ1m5.js} +1 -1
  24. package/server/client/dist/assets/{useReminderMutate-yJak8FzP.js → useReminderMutate-tNMwwRnx.js} +1 -1
  25. package/server/client/dist/index.html +2 -2
  26. package/server/dist/modules/blocknote.js +91 -19
  27. package/server/dist/modules/blocknote.js.map +1 -1
  28. package/server/dist/modules/note-tag-filter.js +22 -0
  29. package/server/dist/modules/note-tag-filter.js.map +1 -0
  30. package/server/dist/schema/note/index.js +31 -0
  31. package/server/dist/schema/note/index.js.map +1 -1
  32. package/server/client/dist/assets/Note-BbgZvrC3.js +0 -1
  33. package/server/client/dist/assets/Note-PEevDKBh.css +0 -1
  34. package/server/client/dist/assets/manage-image-C6Y_0M5H.js +0 -1
@@ -0,0 +1 @@
1
+ import{j as e}from"./note-vendor-BofYbzmZ.js";import{t as v,q as x,ak as w,K as E,A as b,U as A,Q as T,P as o,E as _,L as G,al as M,T as R,B as S,l as P,i as l,j as k,ad as q}from"./index-Ba2XPRI8.js";import"./graph-vendor-CUxe67Lr.js";import{I as D}from"./Image-ZxF459sC.js";import{S as f}from"./SurfaceCard-nZNf9lyE.js";import{f as K,d as L}from"./image.api-0mMkElZk.js";import{c as Q,n as C}from"./Trash.es-BGoN5q9L.js";import"./note-core-BCgMq5QA.js";const U=r=>{const{data:d}=v({queryKey:x.images.list(r.searchParams),async queryFn(){const i=await K({offset:r.searchParams.offset,limit:r.searchParams.limit});if(i.type==="error")throw i;return i.allImages}});return r.render(d)},W=240,B=20,F=4,m=192,g=k(q),Z=()=>{const r=w(),d=E(),i=g.useNavigate(),{page:c}=g.useSearch(),{containerRef:p,limit:n}=b({minItemWidth:W,gap:B,rows:F}),j=A({mutationFn:L,onSuccess:s=>{if(s.type==="error")throw s;d.invalidateQueries({queryKey:x.images.listAll(),exact:!1})}}),y=async s=>{await r("Delete this image? It is not referenced by any notes.")&&j.mutate(s)},I=s=>s===1?"1 reference":`${s} references`;return e.jsx("div",{ref:p,children:e.jsx(T,{fallback:e.jsx(o,{title:"Images",variant:"default",heading:e.jsx(l,{width:136,height:24,className:"rounded-full"}),description:e.jsx(l,{width:232,height:16,className:"rounded-full"}),children:e.jsx("div",{className:"flex flex-col gap-4",children:e.jsx("div",{className:"grid-auto-cards grid gap-4",children:Array.from({length:3},(s,t)=>e.jsxs(f,{flush:!0,children:[e.jsx("div",{className:"flex items-center justify-center bg-muted/25 p-3",style:{height:m},children:e.jsx(l,{width:"100%",height:m-24,className:"rounded-[12px]"})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-border-subtle px-3 py-2.5",children:[e.jsx(l,{width:92,height:14,className:"rounded-full"}),e.jsx(l,{width:32,height:32,className:"rounded-[12px]"})]})]},t))})})}),errorTitle:"Failed to load images",errorDescription:"Retry loading uploaded image metadata",resetKeys:[c,n],children:e.jsx(U,{searchParams:{offset:(c-1)*n,limit:n},render:({images:s,totalCount:t})=>{const u=t>0?`Images (${t})`:void 0,h="Review and manage the images you uploaded inside notes";return s.length===0?e.jsx(o,{title:"Images",variant:"default",heading:u,description:h,children:e.jsx(_,{title:"There are no images",description:"Upload an image in any note and it will appear here"})}):e.jsx(o,{title:"Images",variant:"default",heading:u,description:h,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"grid-auto-cards grid gap-4",children:s.map(a=>e.jsxs(f,{flush:!0,children:[e.jsx(G,{to:M,params:{id:a.id},className:"focus-ring-soft block overflow-hidden rounded-t-[18px] outline-none",children:e.jsx("div",{className:"flex items-center justify-center bg-muted/25 p-3",style:{height:m},children:e.jsx(D,{className:"h-full w-full rounded-[12px] object-contain transition-transform duration-200 hover:scale-[1.02]",src:a.url,alt:a.id})})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-border-subtle px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-fg-secondary",children:[e.jsx(Q,{className:"h-3.5 w-3.5 shrink-0 text-fg-tertiary"}),e.jsx(R,{as:"span",variant:"meta",weight:"medium",tone:"secondary",className:"truncate",children:I(a.referenceCount)})]}),e.jsx(S,{variant:"ghost",size:"icon-sm",disabled:a.referenceCount>0,onClick:()=>y(a.id),children:e.jsx(C,{className:"h-4 w-4"})})]})]},a.id))}),t&&n<t&&e.jsx(P,{page:c,last:Math.ceil(t/n),onChange:a=>{i({search:N=>({...N,page:a})})}})]})})}})})})};export{Z as default};
@@ -1 +1 @@
1
- import{j as e}from"./note-vendor-BofYbzmZ.js";import{p as F,T as r,am as D,L as p,N as R,G as _,an as Z,ad as E,f as q,Q as B,j as G,al as L,ak as z,J as H,K,t as b,q as x,ao as O,U as v,ap as Q,aq as U,B as w,i as l}from"./index-BglnLSet.js";import{a as t}from"./graph-vendor-CUxe67Lr.js";import{I as P}from"./Image-ZxF459sC.js";import{S as g}from"./SurfaceCard-BV6y4bCo.js";import{a as $,d as J}from"./image.api-Dsrx9S-G.js";import{c as V,n as W}from"./Trash.es-CPtRLE0y.js";import{I as X}from"./Image.es-CFTbON7k.js";import"./note-core-BCgMq5QA.js";const Y=new Map([["bold",t.createElement(t.Fragment,null,t.createElement("path",{d:"M178,36c-20.09,0-37.92,7.93-50,21.56C115.92,43.93,98.09,36,78,36a66.08,66.08,0,0,0-66,66c0,72.34,105.81,130.14,110.31,132.57a12,12,0,0,0,11.38,0C138.19,232.14,244,174.34,244,102A66.08,66.08,0,0,0,178,36Zm-5.49,142.36A328.69,328.69,0,0,1,128,210.16a328.69,328.69,0,0,1-44.51-31.8C61.82,159.77,36,131.42,36,102A42,42,0,0,1,78,60c17.8,0,32.7,9.4,38.89,24.54a12,12,0,0,0,22.22,0C145.3,69.4,160.2,60,178,60a42,42,0,0,1,42,42C220,131.42,194.18,159.77,172.51,178.36Z"}))],["duotone",t.createElement(t.Fragment,null,t.createElement("path",{d:"M232,102c0,66-104,122-104,122S24,168,24,102A54,54,0,0,1,78,48c22.59,0,41.94,12.31,50,32,8.06-19.69,27.41-32,50-32A54,54,0,0,1,232,102Z",opacity:"0.2"}),t.createElement("path",{d:"M178,40c-20.65,0-38.73,8.88-50,23.89C116.73,48.88,98.65,40,78,40a62.07,62.07,0,0,0-62,62c0,70,103.79,126.66,108.21,129a8,8,0,0,0,7.58,0C136.21,228.66,240,172,240,102A62.07,62.07,0,0,0,178,40ZM128,214.8C109.74,204.16,32,155.69,32,102A46.06,46.06,0,0,1,78,56c19.45,0,35.78,10.36,42.6,27a8,8,0,0,0,14.8,0c6.82-16.67,23.15-27,42.6-27a46.06,46.06,0,0,1,46,46C224,155.61,146.24,204.15,128,214.8Z"}))],["fill",t.createElement(t.Fragment,null,t.createElement("path",{d:"M240,102c0,70-103.79,126.66-108.21,129a8,8,0,0,1-7.58,0C119.79,228.66,16,172,16,102A62.07,62.07,0,0,1,78,40c20.65,0,38.73,8.88,50,23.89C139.27,48.88,157.35,40,178,40A62.07,62.07,0,0,1,240,102Z"}))],["light",t.createElement(t.Fragment,null,t.createElement("path",{d:"M178,42c-21,0-39.26,9.47-50,25.34C117.26,51.47,99,42,78,42a60.07,60.07,0,0,0-60,60c0,29.2,18.2,59.59,54.1,90.31a334.68,334.68,0,0,0,53.06,37,6,6,0,0,0,5.68,0,334.68,334.68,0,0,0,53.06-37C219.8,161.59,238,131.2,238,102A60.07,60.07,0,0,0,178,42ZM128,217.11C111.59,207.64,30,157.72,30,102A48.05,48.05,0,0,1,78,54c20.28,0,37.31,10.83,44.45,28.27a6,6,0,0,0,11.1,0C140.69,64.83,157.72,54,178,54a48.05,48.05,0,0,1,48,48C226,157.72,144.41,207.64,128,217.11Z"}))],["regular",t.createElement(t.Fragment,null,t.createElement("path",{d:"M178,40c-20.65,0-38.73,8.88-50,23.89C116.73,48.88,98.65,40,78,40a62.07,62.07,0,0,0-62,62c0,70,103.79,126.66,108.21,129a8,8,0,0,0,7.58,0C136.21,228.66,240,172,240,102A62.07,62.07,0,0,0,178,40ZM128,214.8C109.74,204.16,32,155.69,32,102A46.06,46.06,0,0,1,78,56c19.45,0,35.78,10.36,42.6,27a8,8,0,0,0,14.8,0c6.82-16.67,23.15-27,42.6-27a46.06,46.06,0,0,1,46,46C224,155.61,146.24,204.15,128,214.8Z"}))],["thin",t.createElement(t.Fragment,null,t.createElement("path",{d:"M178,44c-21.44,0-39.92,10.19-50,27.07C117.92,54.19,99.44,44,78,44a58.07,58.07,0,0,0-58,58c0,28.59,18,58.47,53.4,88.79a333.81,333.81,0,0,0,52.7,36.73,4,4,0,0,0,3.8,0,333.81,333.81,0,0,0,52.7-36.73C218,160.47,236,130.59,236,102A58.07,58.07,0,0,0,178,44ZM128,219.42c-14-8-100-59.35-100-117.42A50.06,50.06,0,0,1,78,52c21.11,0,38.85,11.31,46.3,29.51a4,4,0,0,0,7.4,0C139.15,63.31,156.89,52,178,52a50.06,50.06,0,0,1,50,50C228,160,142,211.46,128,219.42Z"}))]]),A=t.forwardRef((a,n)=>t.createElement(F,{ref:n,...a,weights:Y}));A.displayName="HeartIcon";const ee=A;function ae({name:a}){return e.jsx(r,{as:"div",variant:"label",weight:"medium",tone:"secondary",className:"inline-flex items-center rounded-full border border-border-subtle bg-hover-subtle px-2.5 py-1",children:a})}function se({id:a,title:n,tags:i,createdAt:u,updatedAt:d}){const o=new Date(Number(u)),m=D(Number(d));return e.jsx("div",{className:"border-b-2 border-dashed border-border-subtle last:border-b-0",children:e.jsxs("div",{className:"py-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(r,{variant:"label",weight:"medium",tone:"tertiary",children:m}),e.jsxs(r,{variant:"label",tone:"placeholder",children:["(",o.toDateString(),")"]})]}),e.jsx(r,{as:"div",variant:"body",weight:"bold",tracking:"tight",children:e.jsx(p,{className:"transition-colors hover:text-accent-primary",to:R,params:{id:a},children:n||"Untitled"})}),i&&i.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:i.map(c=>e.jsx(p,{to:_,params:{id:c.id},search:{page:1},children:e.jsx(ae,{name:c.name})},c.id))})]})})}const I=G(L),j=352,te="mb-4 inline-flex items-center gap-1 text-fg-secondary transition-colors hover:text-fg-default",T="flex items-center justify-center bg-muted/25 p-3",re="h-full w-full rounded-[12px] object-contain",M="mb-3 flex flex-wrap items-start justify-between gap-3 border-b border-border-subtle pb-3",S="space-y-1",ne=a=>a===1?"1 reference":`${a} references`,C=(a,n)=>typeof a=="object"&&a!==null&&"errors"in a&&Array.isArray(a.errors)&&typeof a.errors[0]?.message=="string"?a.errors[0].message:a instanceof Error&&a.message?a.message:n,ie=()=>e.jsxs("div",{className:"flex flex-col gap-6 lg:flex-row",children:[e.jsx("div",{className:"w-full lg:w-[400px] lg:flex-shrink-0",children:e.jsxs(g,{flush:!0,children:[e.jsx("div",{className:T,style:{height:j},children:e.jsx(l,{width:"100%",height:j-24,className:"rounded-[12px]"})}),e.jsxs("div",{className:"flex flex-col gap-4 border-t border-border-subtle p-4",children:[e.jsx(l,{width:96,height:14,className:"rounded-full"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(l,{height:32,className:"flex-1 rounded-[12px]"}),e.jsx(l,{height:32,className:"flex-1 rounded-[12px]"})]})]})]})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs(g,{children:[e.jsxs("div",{className:M,children:[e.jsxs("div",{className:S,children:[e.jsx(l,{width:140,height:18}),e.jsx(l,{width:220,height:14,className:"rounded-full"})]}),e.jsx(l,{width:84,height:14,className:"rounded-full"})]}),e.jsx("div",{className:"flex flex-col gap-3",children:Array.from({length:3},(a,n)=>e.jsx(l,{height:72,className:"rounded-[16px]"},n))})]})})]}),le=({id:a})=>{const n=z(),i=H(),u=I.useNavigate(),d=K(),{data:o}=b({queryKey:x.images.detail(a),queryFn:async()=>{const s=await $(a);if(s.type==="error")throw s;return s.image}}),{data:m}=b({queryKey:x.images.notes(a),queryFn:async()=>{const s=await O(o.url);if(s.type==="error")throw s;return s.imageNotes}}),c=m.length,y=ne(c),h=c===0,f=v({mutationFn:async()=>{const s=await J(a);if(s.type==="error")throw s;if(!s.deleteImage)throw new Error("Failed to delete image");return s.deleteImage},onSuccess:async()=>{await d.invalidateQueries({queryKey:x.images.listAll(),exact:!1}),i("Image deleted"),u({to:E,search:{page:1}})},onError:s=>{i(C(s,"Failed to delete image"))}}),N=v({mutationFn:async()=>{const s=await Q("heroBanner",o.url);if(s.type==="error")throw s;return s.cache.value},onSuccess:async()=>{await d.invalidateQueries({queryKey:x.ui.heroBanner(),exact:!0}),i("Hero banner updated")},onError:s=>{i(C(s,"Failed to update hero banner"))}}),k=async()=>{!h||f.isPending||await n("Are you really sure?")&&f.mutate()};return e.jsxs("div",{className:"flex flex-col gap-6 lg:flex-row",children:[e.jsx("div",{className:"w-full lg:w-[400px] lg:flex-shrink-0",children:e.jsxs(g,{flush:!0,children:[e.jsx("div",{className:T,style:{height:j},children:e.jsx(P,{className:re,src:o.url,alt:`Image ${o.id}`})}),e.jsxs("div",{className:"flex flex-col gap-4 border-t border-border-subtle p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(V,{size:14,className:"text-fg-tertiary"}),e.jsx(r,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:y})]}),e.jsx(r,{as:"p",variant:"meta",tone:"tertiary",children:h?"Delete is available because no notes reference this image":"Remove this image from notes before deleting it"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{content:h?"Delete this image":"Cannot delete while referenced by notes",side:"bottom",children:e.jsxs(w,{variant:"soft-danger",size:"sm",className:"flex-1",disabled:!h,isLoading:f.isPending,onClick:k,children:[e.jsx(W,{size:16}),"Delete"]})}),e.jsxs(w,{variant:"primary",size:"sm",className:"flex-1",isLoading:N.isPending,onClick:()=>N.mutate(),children:[e.jsx(ee,{size:16}),"Set hero banner"]})]})]})]})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs(g,{children:[e.jsxs("div",{className:M,children:[e.jsxs("div",{className:S,children:[e.jsx(r,{as:"h2",variant:"subheading",weight:"medium",tracking:"tight",children:"Referenced Notes"}),e.jsx(r,{as:"p",variant:"meta",tone:"secondary",children:"Notes currently using this image"})]}),e.jsx(r,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:y})]}),c>0?e.jsx("ul",{className:"flex flex-col",children:m.map(s=>e.jsx("li",{children:e.jsx(se,{...s})},s.id))}):e.jsxs("div",{className:"flex items-start gap-3 py-1",children:[e.jsx("div",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-[10px] bg-muted/25 text-fg-disabled",children:e.jsx(X,{size:18})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(r,{as:"p",variant:"body",weight:"medium",tone:"secondary",children:"No notes reference this image"}),e.jsx(r,{as:"p",variant:"meta",tone:"secondary",children:"This image can be deleted or reused in another note"})]})]})]})})]})},pe=()=>{const{id:a}=I.useParams();return e.jsxs(e.Fragment,{children:[e.jsx(Z,{children:e.jsx("title",{children:"Image Detail | Ocean Brain"})}),e.jsxs(p,{to:E,search:{page:1},className:te,children:[e.jsx(q,{size:16}),e.jsx(r,{as:"span",variant:"meta",weight:"medium",className:"text-current",children:"Back to Images"})]}),e.jsx(r,{as:"h1",variant:"heading",weight:"bold",tracking:"tighter",className:"sr-only",children:"Image Detail"}),e.jsx(B,{fallback:e.jsx(ie,{}),errorTitle:"Failed to load image detail",errorDescription:"Retry loading the image preview and its referenced notes",resetKeys:[a],children:e.jsx(le,{id:a})})]})};export{pe as default};
1
+ import{j as e}from"./note-vendor-BofYbzmZ.js";import{p as D,T as r,am as F,L as p,N as R,G as _,an as Z,ad as E,f as q,Q as B,j as G,al as L,ak as z,J as H,K,t as b,q as x,ao as O,U as v,ap as Q,aq as U,B as w,i as l}from"./index-Ba2XPRI8.js";import{a as t}from"./graph-vendor-CUxe67Lr.js";import{I as P}from"./Image-ZxF459sC.js";import{S as g}from"./SurfaceCard-nZNf9lyE.js";import{a as $,d as J}from"./image.api-0mMkElZk.js";import{c as V,n as W}from"./Trash.es-BGoN5q9L.js";import{I as X}from"./Image.es-BQfyKc2-.js";import"./note-core-BCgMq5QA.js";const Y=new Map([["bold",t.createElement(t.Fragment,null,t.createElement("path",{d:"M178,36c-20.09,0-37.92,7.93-50,21.56C115.92,43.93,98.09,36,78,36a66.08,66.08,0,0,0-66,66c0,72.34,105.81,130.14,110.31,132.57a12,12,0,0,0,11.38,0C138.19,232.14,244,174.34,244,102A66.08,66.08,0,0,0,178,36Zm-5.49,142.36A328.69,328.69,0,0,1,128,210.16a328.69,328.69,0,0,1-44.51-31.8C61.82,159.77,36,131.42,36,102A42,42,0,0,1,78,60c17.8,0,32.7,9.4,38.89,24.54a12,12,0,0,0,22.22,0C145.3,69.4,160.2,60,178,60a42,42,0,0,1,42,42C220,131.42,194.18,159.77,172.51,178.36Z"}))],["duotone",t.createElement(t.Fragment,null,t.createElement("path",{d:"M232,102c0,66-104,122-104,122S24,168,24,102A54,54,0,0,1,78,48c22.59,0,41.94,12.31,50,32,8.06-19.69,27.41-32,50-32A54,54,0,0,1,232,102Z",opacity:"0.2"}),t.createElement("path",{d:"M178,40c-20.65,0-38.73,8.88-50,23.89C116.73,48.88,98.65,40,78,40a62.07,62.07,0,0,0-62,62c0,70,103.79,126.66,108.21,129a8,8,0,0,0,7.58,0C136.21,228.66,240,172,240,102A62.07,62.07,0,0,0,178,40ZM128,214.8C109.74,204.16,32,155.69,32,102A46.06,46.06,0,0,1,78,56c19.45,0,35.78,10.36,42.6,27a8,8,0,0,0,14.8,0c6.82-16.67,23.15-27,42.6-27a46.06,46.06,0,0,1,46,46C224,155.61,146.24,204.15,128,214.8Z"}))],["fill",t.createElement(t.Fragment,null,t.createElement("path",{d:"M240,102c0,70-103.79,126.66-108.21,129a8,8,0,0,1-7.58,0C119.79,228.66,16,172,16,102A62.07,62.07,0,0,1,78,40c20.65,0,38.73,8.88,50,23.89C139.27,48.88,157.35,40,178,40A62.07,62.07,0,0,1,240,102Z"}))],["light",t.createElement(t.Fragment,null,t.createElement("path",{d:"M178,42c-21,0-39.26,9.47-50,25.34C117.26,51.47,99,42,78,42a60.07,60.07,0,0,0-60,60c0,29.2,18.2,59.59,54.1,90.31a334.68,334.68,0,0,0,53.06,37,6,6,0,0,0,5.68,0,334.68,334.68,0,0,0,53.06-37C219.8,161.59,238,131.2,238,102A60.07,60.07,0,0,0,178,42ZM128,217.11C111.59,207.64,30,157.72,30,102A48.05,48.05,0,0,1,78,54c20.28,0,37.31,10.83,44.45,28.27a6,6,0,0,0,11.1,0C140.69,64.83,157.72,54,178,54a48.05,48.05,0,0,1,48,48C226,157.72,144.41,207.64,128,217.11Z"}))],["regular",t.createElement(t.Fragment,null,t.createElement("path",{d:"M178,40c-20.65,0-38.73,8.88-50,23.89C116.73,48.88,98.65,40,78,40a62.07,62.07,0,0,0-62,62c0,70,103.79,126.66,108.21,129a8,8,0,0,0,7.58,0C136.21,228.66,240,172,240,102A62.07,62.07,0,0,0,178,40ZM128,214.8C109.74,204.16,32,155.69,32,102A46.06,46.06,0,0,1,78,56c19.45,0,35.78,10.36,42.6,27a8,8,0,0,0,14.8,0c6.82-16.67,23.15-27,42.6-27a46.06,46.06,0,0,1,46,46C224,155.61,146.24,204.15,128,214.8Z"}))],["thin",t.createElement(t.Fragment,null,t.createElement("path",{d:"M178,44c-21.44,0-39.92,10.19-50,27.07C117.92,54.19,99.44,44,78,44a58.07,58.07,0,0,0-58,58c0,28.59,18,58.47,53.4,88.79a333.81,333.81,0,0,0,52.7,36.73,4,4,0,0,0,3.8,0,333.81,333.81,0,0,0,52.7-36.73C218,160.47,236,130.59,236,102A58.07,58.07,0,0,0,178,44ZM128,219.42c-14-8-100-59.35-100-117.42A50.06,50.06,0,0,1,78,52c21.11,0,38.85,11.31,46.3,29.51a4,4,0,0,0,7.4,0C139.15,63.31,156.89,52,178,52a50.06,50.06,0,0,1,50,50C228,160,142,211.46,128,219.42Z"}))]]),A=t.forwardRef((a,n)=>t.createElement(D,{ref:n,...a,weights:Y}));A.displayName="HeartIcon";const ee=A;function ae({name:a}){return e.jsx(r,{as:"div",variant:"label",weight:"medium",tone:"secondary",className:"inline-flex items-center rounded-full border border-border-subtle bg-hover-subtle px-2.5 py-1",children:a})}function se({id:a,title:n,tags:i,createdAt:u,updatedAt:d}){const o=new Date(Number(u)),m=F(Number(d));return e.jsx("div",{className:"border-b-2 border-dashed border-border-subtle last:border-b-0",children:e.jsxs("div",{className:"py-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(r,{variant:"label",weight:"medium",tone:"tertiary",children:m}),e.jsxs(r,{variant:"label",tone:"placeholder",children:["(",o.toDateString(),")"]})]}),e.jsx(r,{as:"div",variant:"body",weight:"bold",tracking:"tight",children:e.jsx(p,{className:"transition-colors hover:text-accent-primary",to:R,params:{id:a},children:n||"Untitled"})}),i&&i.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:i.map(c=>e.jsx(p,{to:_,params:{id:c.id},search:{page:1},children:e.jsx(ae,{name:c.name})},c.id))})]})})}const I=G(L),j=352,te="mb-4 inline-flex items-center gap-1 text-fg-secondary transition-colors hover:text-fg-default",T="flex items-center justify-center bg-muted/25 p-3",re="h-full w-full rounded-[12px] object-contain",M="mb-3 flex flex-wrap items-start justify-between gap-3 border-b border-border-subtle pb-3",S="space-y-1",ne=a=>a===1?"1 reference":`${a} references`,C=(a,n)=>typeof a=="object"&&a!==null&&"errors"in a&&Array.isArray(a.errors)&&typeof a.errors[0]?.message=="string"?a.errors[0].message:a instanceof Error&&a.message?a.message:n,ie=()=>e.jsxs("div",{className:"flex flex-col gap-6 lg:flex-row",children:[e.jsx("div",{className:"w-full lg:w-[400px] lg:flex-shrink-0",children:e.jsxs(g,{flush:!0,children:[e.jsx("div",{className:T,style:{height:j},children:e.jsx(l,{width:"100%",height:j-24,className:"rounded-[12px]"})}),e.jsxs("div",{className:"flex flex-col gap-4 border-t border-border-subtle p-4",children:[e.jsx(l,{width:96,height:14,className:"rounded-full"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(l,{height:32,className:"flex-1 rounded-[12px]"}),e.jsx(l,{height:32,className:"flex-1 rounded-[12px]"})]})]})]})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs(g,{children:[e.jsxs("div",{className:M,children:[e.jsxs("div",{className:S,children:[e.jsx(l,{width:140,height:18}),e.jsx(l,{width:220,height:14,className:"rounded-full"})]}),e.jsx(l,{width:84,height:14,className:"rounded-full"})]}),e.jsx("div",{className:"flex flex-col gap-3",children:Array.from({length:3},(a,n)=>e.jsx(l,{height:72,className:"rounded-[16px]"},n))})]})})]}),le=({id:a})=>{const n=z(),i=H(),u=I.useNavigate(),d=K(),{data:o}=b({queryKey:x.images.detail(a),queryFn:async()=>{const s=await $(a);if(s.type==="error")throw s;return s.image}}),{data:m}=b({queryKey:x.images.notes(a),queryFn:async()=>{const s=await O(o.url);if(s.type==="error")throw s;return s.imageNotes}}),c=m.length,y=ne(c),h=c===0,f=v({mutationFn:async()=>{const s=await J(a);if(s.type==="error")throw s;if(!s.deleteImage)throw new Error("Failed to delete image");return s.deleteImage},onSuccess:async()=>{await d.invalidateQueries({queryKey:x.images.listAll(),exact:!1}),i("Image deleted"),u({to:E,search:{page:1}})},onError:s=>{i(C(s,"Failed to delete image"))}}),N=v({mutationFn:async()=>{const s=await Q("heroBanner",o.url);if(s.type==="error")throw s;return s.cache.value},onSuccess:async()=>{await d.invalidateQueries({queryKey:x.ui.heroBanner(),exact:!0}),i("Hero banner updated")},onError:s=>{i(C(s,"Failed to update hero banner"))}}),k=async()=>{!h||f.isPending||await n("Delete this image? It is not referenced by any notes.")&&f.mutate()};return e.jsxs("div",{className:"flex flex-col gap-6 lg:flex-row",children:[e.jsx("div",{className:"w-full lg:w-[400px] lg:flex-shrink-0",children:e.jsxs(g,{flush:!0,children:[e.jsx("div",{className:T,style:{height:j},children:e.jsx(P,{className:re,src:o.url,alt:`Image ${o.id}`})}),e.jsxs("div",{className:"flex flex-col gap-4 border-t border-border-subtle p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(V,{size:14,className:"text-fg-tertiary"}),e.jsx(r,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:y})]}),e.jsx(r,{as:"p",variant:"meta",tone:"tertiary",children:h?"Delete is available because no notes reference this image":"Remove this image from notes before deleting it"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{content:h?"Delete this image":"Cannot delete while referenced by notes",side:"bottom",children:e.jsxs(w,{variant:"soft-danger",size:"sm",className:"flex-1",disabled:!h,isLoading:f.isPending,onClick:k,children:[e.jsx(W,{size:16}),"Delete"]})}),e.jsxs(w,{variant:"primary",size:"sm",className:"flex-1",isLoading:N.isPending,onClick:()=>N.mutate(),children:[e.jsx(ee,{size:16}),"Set hero banner"]})]})]})]})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs(g,{children:[e.jsxs("div",{className:M,children:[e.jsxs("div",{className:S,children:[e.jsx(r,{as:"h2",variant:"subheading",weight:"medium",tracking:"tight",children:"Referenced Notes"}),e.jsx(r,{as:"p",variant:"meta",tone:"secondary",children:"Notes currently using this image"})]}),e.jsx(r,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:y})]}),c>0?e.jsx("ul",{className:"flex flex-col",children:m.map(s=>e.jsx("li",{children:e.jsx(se,{...s})},s.id))}):e.jsxs("div",{className:"flex items-start gap-3 py-1",children:[e.jsx("div",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-[10px] bg-muted/25 text-fg-disabled",children:e.jsx(X,{size:18})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(r,{as:"p",variant:"body",weight:"medium",tone:"secondary",children:"No notes reference this image"}),e.jsx(r,{as:"p",variant:"meta",tone:"secondary",children:"This image can be deleted or reused in another note"})]})]})]})})]})},pe=()=>{const{id:a}=I.useParams();return e.jsxs(e.Fragment,{children:[e.jsx(Z,{children:e.jsx("title",{children:"Image Detail | Ocean Brain"})}),e.jsxs(p,{to:E,search:{page:1},className:te,children:[e.jsx(q,{size:16}),e.jsx(r,{as:"span",variant:"meta",weight:"medium",className:"text-current",children:"Back to Images"})]}),e.jsx(r,{as:"h1",variant:"heading",weight:"bold",tracking:"tighter",className:"sr-only",children:"Image Detail"}),e.jsx(B,{fallback:e.jsx(ie,{}),errorTitle:"Failed to load image detail",errorDescription:"Retry loading the image preview and its referenced notes",resetKeys:[a],children:e.jsx(le,{id:a})})]})};export{pe as default};
@@ -1 +1 @@
1
- import{j as e}from"./note-vendor-BofYbzmZ.js";import{ag as r,J as R,K as B,u as E,U as p,P as G,T as t,ah as J,B as M,_ as T,a0 as K,$ as U,a1 as O,a2 as w}from"./index-BglnLSet.js";import{a as h}from"./graph-vendor-CUxe67Lr.js";import{S as x}from"./SurfaceCard-BV6y4bCo.js";import"./note-core-BCgMq5QA.js";const D=async()=>{const{data:s}=await r.get("/api/mcp-admin/status");return s},z=async s=>{const{data:n}=await r.post("/api/mcp-admin/enabled",{enabled:s});return n},V=async()=>{const{data:s}=await r.post("/api/mcp-admin/token/rotate");return s},_=async()=>{const{data:s}=await r.post("/api/mcp-admin/token/revoke");return s},o=["mcp-admin","status"],$=s=>JSON.stringify({mcpServers:{"ocean-brain":{command:"npx",args:["-y","ocean-brain","mcp","--server",s,"--token-file","/path/to/token.txt"]}}},null,2),H=s=>JSON.stringify({mcpServers:{"ocean-brain":{command:"npx",args:["-y","ocean-brain","mcp","--server",s,"--token","your-token-here"]}}},null,2),se=()=>{const s=R(),n=B(),[c,S]=h.useState(()=>window.location.origin),[v,g]=h.useState(""),[k,P]=h.useState("token-file"),{data:y,isLoading:A}=E({queryKey:o,queryFn:D}),b=p({mutationFn:z,onSuccess:a=>{n.setQueryData(o,a),s(a.enabled?"MCP access enabled.":"MCP access disabled.")}}),j=p({mutationFn:V,onSuccess:async({token:a})=>{g(a),s("A new MCP token has been issued."),await n.invalidateQueries({queryKey:o})}}),f=p({mutationFn:_,onSuccess:a=>{g(""),n.setQueryData(o,a),s("The active MCP token has been revoked.")}}),l=y?.enabled??!1,d=y?.hasActiveToken??!1,F=!A&&!b.isPending,i="space-y-1",N="space-y-4.5",I="inline-flex items-center gap-3 rounded-[14px] border border-border-subtle bg-muted px-3 py-2",L="rounded-full border border-border-subtle bg-hover-subtle px-2.5 py-1",q="space-y-3 rounded-[16px] border border-border-subtle bg-surface px-4 py-3",Q="overflow-x-auto rounded-[14px] border border-border-subtle bg-surface px-4 py-3 text-xs text-fg-secondary",u={variant:"subheading",weight:"medium",tracking:"tight"},C="font-medium text-fg-tertiary",m=k==="token-file"?{title:"Token file",description:"Recommended. Keeps the token out of config.",snippet:$(c)}:{title:"Inline token",description:"Useful for quick local testing.",snippet:H(c)};return e.jsx(G,{title:"MCP",variant:"default",description:"Manage MCP access, tokens, and connection details",children:e.jsxs("div",{className:"grid grid-cols-1 gap-4",children:[e.jsx(x,{tone:"elevated",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:i,children:[e.jsx(t,{as:"h2",...u,children:"MCP Access"}),e.jsx(t,{as:"p",variant:"meta",tone:"secondary",children:"Allow or block MCP requests at the server level."})]}),e.jsxs("div",{className:I,children:[e.jsx(t,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:l?"Enabled":"Disabled"}),e.jsx(J,{"aria-label":"Allow MCP access",checked:l,disabled:!F,onCheckedChange:()=>{b.mutate(!l)}})]})]})}),e.jsx(x,{tone:"elevated",children:e.jsxs("div",{className:N,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:i,children:[e.jsx(t,{as:"h2",...u,children:"Token Management"}),e.jsx(t,{as:"p",variant:"meta",tone:"secondary",className:"max-w-[64ch]",children:"Ocean Brain supports one active MCP token at a time. Rotating immediately invalidates the previous one."})]}),e.jsx(t,{as:"span",variant:"meta",weight:"medium",tone:d?"secondary":"tertiary",className:L,children:d?"1 active token":"No active token"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[e.jsx(M,{onClick:()=>j.mutate(void 0),isLoading:j.isPending,children:"Rotate token"}),e.jsx(M,{variant:"soft-danger",onClick:()=>f.mutate(),isLoading:f.isPending,disabled:!d,children:"Revoke token"})]}),v&&e.jsxs("div",{className:"space-y-2.5",children:[e.jsx(T,{htmlFor:"issued-mcp-token",className:C,children:"Issued token"}),e.jsx(K,{id:"issued-mcp-token",rows:3,readOnly:!0,value:v})]})]})}),e.jsx(x,{tone:"elevated",children:e.jsxs("div",{className:N,children:[e.jsxs("div",{className:i,children:[e.jsx(t,{as:"h2",...u,children:"Connection Guide"}),e.jsx(t,{as:"p",variant:"meta",tone:"secondary",children:"Connect your MCP client with either a token file or an inline token."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"mcp-server-url",className:C,children:"Server URL"}),e.jsx(U,{id:"mcp-server-url",value:c,onChange:a=>S(a.target.value)})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(O,{type:"single",variant:"pills",size:"sm",value:k,onValueChange:a=>{(a==="token-file"||a==="inline-token")&&P(a)},children:[e.jsx(w,{value:"token-file",children:"Token file"}),e.jsx(w,{value:"inline-token",children:"Inline token"})]}),e.jsxs("div",{className:q,children:[e.jsxs("div",{className:i,children:[e.jsx(t,{as:"p",variant:"meta",weight:"semibold",children:m.title}),e.jsx(t,{as:"p",variant:"meta",tone:"secondary",children:m.description})]}),e.jsx("pre",{className:Q,children:m.snippet})]})]})]})})]})})};export{se as default};
1
+ import{j as e}from"./note-vendor-BofYbzmZ.js";import{ag as r,J as R,K as B,u as E,U as p,P as G,T as t,ah as J,B as M,_ as T,a0 as K,$ as U,a1 as O,a2 as w}from"./index-Ba2XPRI8.js";import{a as h}from"./graph-vendor-CUxe67Lr.js";import{S as x}from"./SurfaceCard-nZNf9lyE.js";import"./note-core-BCgMq5QA.js";const D=async()=>{const{data:s}=await r.get("/api/mcp-admin/status");return s},z=async s=>{const{data:n}=await r.post("/api/mcp-admin/enabled",{enabled:s});return n},V=async()=>{const{data:s}=await r.post("/api/mcp-admin/token/rotate");return s},_=async()=>{const{data:s}=await r.post("/api/mcp-admin/token/revoke");return s},o=["mcp-admin","status"],$=s=>JSON.stringify({mcpServers:{"ocean-brain":{command:"npx",args:["-y","ocean-brain","mcp","--server",s,"--token-file","/path/to/token.txt"]}}},null,2),H=s=>JSON.stringify({mcpServers:{"ocean-brain":{command:"npx",args:["-y","ocean-brain","mcp","--server",s,"--token","your-token-here"]}}},null,2),se=()=>{const s=R(),n=B(),[c,S]=h.useState(()=>window.location.origin),[v,g]=h.useState(""),[k,P]=h.useState("token-file"),{data:y,isLoading:A}=E({queryKey:o,queryFn:D}),b=p({mutationFn:z,onSuccess:a=>{n.setQueryData(o,a),s(a.enabled?"MCP access enabled.":"MCP access disabled.")}}),j=p({mutationFn:V,onSuccess:async({token:a})=>{g(a),s("A new MCP token has been issued."),await n.invalidateQueries({queryKey:o})}}),f=p({mutationFn:_,onSuccess:a=>{g(""),n.setQueryData(o,a),s("The active MCP token has been revoked.")}}),l=y?.enabled??!1,d=y?.hasActiveToken??!1,F=!A&&!b.isPending,i="space-y-1",N="space-y-4.5",I="inline-flex items-center gap-3 rounded-[14px] border border-border-subtle bg-muted px-3 py-2",L="rounded-full border border-border-subtle bg-hover-subtle px-2.5 py-1",q="space-y-3 rounded-[16px] border border-border-subtle bg-surface px-4 py-3",Q="overflow-x-auto rounded-[14px] border border-border-subtle bg-surface px-4 py-3 text-xs text-fg-secondary",u={variant:"subheading",weight:"medium",tracking:"tight"},C="font-medium text-fg-tertiary",m=k==="token-file"?{title:"Token file",description:"Recommended. Keeps the token out of config.",snippet:$(c)}:{title:"Inline token",description:"Useful for quick local testing.",snippet:H(c)};return e.jsx(G,{title:"MCP",variant:"default",description:"Manage MCP access, tokens, and connection details",children:e.jsxs("div",{className:"grid grid-cols-1 gap-4",children:[e.jsx(x,{tone:"elevated",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:i,children:[e.jsx(t,{as:"h2",...u,children:"MCP Access"}),e.jsx(t,{as:"p",variant:"meta",tone:"secondary",children:"Allow or block MCP requests at the server level."})]}),e.jsxs("div",{className:I,children:[e.jsx(t,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:l?"Enabled":"Disabled"}),e.jsx(J,{"aria-label":"Allow MCP access",checked:l,disabled:!F,onCheckedChange:()=>{b.mutate(!l)}})]})]})}),e.jsx(x,{tone:"elevated",children:e.jsxs("div",{className:N,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:i,children:[e.jsx(t,{as:"h2",...u,children:"Token Management"}),e.jsx(t,{as:"p",variant:"meta",tone:"secondary",className:"max-w-[64ch]",children:"Ocean Brain supports one active MCP token at a time. Rotating immediately invalidates the previous one."})]}),e.jsx(t,{as:"span",variant:"meta",weight:"medium",tone:d?"secondary":"tertiary",className:L,children:d?"1 active token":"No active token"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[e.jsx(M,{onClick:()=>j.mutate(void 0),isLoading:j.isPending,children:"Rotate token"}),e.jsx(M,{variant:"soft-danger",onClick:()=>f.mutate(),isLoading:f.isPending,disabled:!d,children:"Revoke token"})]}),v&&e.jsxs("div",{className:"space-y-2.5",children:[e.jsx(T,{htmlFor:"issued-mcp-token",className:C,children:"Issued token"}),e.jsx(K,{id:"issued-mcp-token",rows:3,readOnly:!0,value:v})]})]})}),e.jsx(x,{tone:"elevated",children:e.jsxs("div",{className:N,children:[e.jsxs("div",{className:i,children:[e.jsx(t,{as:"h2",...u,children:"Connection Guide"}),e.jsx(t,{as:"p",variant:"meta",tone:"secondary",children:"Connect your MCP client with either a token file or an inline token."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"mcp-server-url",className:C,children:"Server URL"}),e.jsx(U,{id:"mcp-server-url",value:c,onChange:a=>S(a.target.value)})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(O,{type:"single",variant:"pills",size:"sm",value:k,onValueChange:a=>{(a==="token-file"||a==="inline-token")&&P(a)},children:[e.jsx(w,{value:"token-file",children:"Token file"}),e.jsx(w,{value:"inline-token",children:"Inline token"})]}),e.jsxs("div",{className:q,children:[e.jsxs("div",{className:i,children:[e.jsx(t,{as:"p",variant:"meta",weight:"semibold",children:m.title}),e.jsx(t,{as:"p",variant:"meta",tone:"secondary",children:m.description})]}),e.jsx("pre",{className:Q,children:m.snippet})]})]})]})})]})})};export{se as default};
@@ -1,4 +1,4 @@
1
- import{j as e}from"./note-vendor-BofYbzmZ.js";import{p as Y,h as E,J as V,K as W,q as v,ar as ee,u as ae,U as M,P as te,T as s,a3 as se,as as j,at as N,B as C,w as le,M as m,_ as w,$ as b,F as ne,l as re,i as $,j as ce,ae as ie}from"./index-BglnLSet.js";import{a}from"./graph-vendor-CUxe67Lr.js";import{n as oe,M as de}from"./ModalActionRow-Hg6MY61u.js";import{S as D}from"./SurfaceCard-BV6y4bCo.js";import"./note-core-BCgMq5QA.js";const me=new Map([["bold",a.createElement(a.Fragment,null,a.createElement("path",{d:"M216.49,168.49a12,12,0,0,1-17,0L128,97,56.49,168.49a12,12,0,0,1-17-17l80-80a12,12,0,0,1,17,0l80,80A12,12,0,0,1,216.49,168.49Z"}))],["duotone",a.createElement(a.Fragment,null,a.createElement("path",{d:"M208,160H48l80-80Z",opacity:"0.2"}),a.createElement("path",{d:"M213.66,154.34l-80-80a8,8,0,0,0-11.32,0l-80,80A8,8,0,0,0,48,168H208a8,8,0,0,0,5.66-13.66ZM67.31,152,128,91.31,188.69,152Z"}))],["fill",a.createElement(a.Fragment,null,a.createElement("path",{d:"M215.39,163.06A8,8,0,0,1,208,168H48a8,8,0,0,1-5.66-13.66l80-80a8,8,0,0,1,11.32,0l80,80A8,8,0,0,1,215.39,163.06Z"}))],["light",a.createElement(a.Fragment,null,a.createElement("path",{d:"M212.24,164.24a6,6,0,0,1-8.48,0L128,88.49,52.24,164.24a6,6,0,0,1-8.48-8.48l80-80a6,6,0,0,1,8.48,0l80,80A6,6,0,0,1,212.24,164.24Z"}))],["regular",a.createElement(a.Fragment,null,a.createElement("path",{d:"M213.66,165.66a8,8,0,0,1-11.32,0L128,91.31,53.66,165.66a8,8,0,0,1-11.32-11.32l80-80a8,8,0,0,1,11.32,0l80,80A8,8,0,0,1,213.66,165.66Z"}))],["thin",a.createElement(a.Fragment,null,a.createElement("path",{d:"M210.83,162.83a4,4,0,0,1-5.66,0L128,85.66,50.83,162.83a4,4,0,0,1-5.66-5.66l80-80a4,4,0,0,1,5.66,0l80,80A4,4,0,0,1,210.83,162.83Z"}))]]),O=a.forwardRef((l,c)=>a.createElement(Y,{ref:c,...l,weights:me}));O.displayName="CaretUpIcon";const he=O,k=["id","name","template","replacement","createdAt","updatedAt"],ue=new Set(k),pe=`query FetchPlaceholders(
1
+ import{j as e}from"./note-vendor-BofYbzmZ.js";import{p as Y,h as E,J as V,K as W,q as v,ar as ee,u as ae,U as M,P as te,T as s,a3 as se,as as j,at as N,B as C,w as le,M as m,_ as w,$ as b,F as ne,l as re,i as $,j as ce,ae as ie}from"./index-Ba2XPRI8.js";import{a}from"./graph-vendor-CUxe67Lr.js";import{n as oe,M as de}from"./ModalActionRow-DyOb58KJ.js";import{S as D}from"./SurfaceCard-nZNf9lyE.js";import"./note-core-BCgMq5QA.js";const me=new Map([["bold",a.createElement(a.Fragment,null,a.createElement("path",{d:"M216.49,168.49a12,12,0,0,1-17,0L128,97,56.49,168.49a12,12,0,0,1-17-17l80-80a12,12,0,0,1,17,0l80,80A12,12,0,0,1,216.49,168.49Z"}))],["duotone",a.createElement(a.Fragment,null,a.createElement("path",{d:"M208,160H48l80-80Z",opacity:"0.2"}),a.createElement("path",{d:"M213.66,154.34l-80-80a8,8,0,0,0-11.32,0l-80,80A8,8,0,0,0,48,168H208a8,8,0,0,0,5.66-13.66ZM67.31,152,128,91.31,188.69,152Z"}))],["fill",a.createElement(a.Fragment,null,a.createElement("path",{d:"M215.39,163.06A8,8,0,0,1,208,168H48a8,8,0,0,1-5.66-13.66l80-80a8,8,0,0,1,11.32,0l80,80A8,8,0,0,1,215.39,163.06Z"}))],["light",a.createElement(a.Fragment,null,a.createElement("path",{d:"M212.24,164.24a6,6,0,0,1-8.48,0L128,88.49,52.24,164.24a6,6,0,0,1-8.48-8.48l80-80a6,6,0,0,1,8.48,0l80,80A6,6,0,0,1,212.24,164.24Z"}))],["regular",a.createElement(a.Fragment,null,a.createElement("path",{d:"M213.66,165.66a8,8,0,0,1-11.32,0L128,91.31,53.66,165.66a8,8,0,0,1-11.32-11.32l80-80a8,8,0,0,1,11.32,0l80,80A8,8,0,0,1,213.66,165.66Z"}))],["thin",a.createElement(a.Fragment,null,a.createElement("path",{d:"M210.83,162.83a4,4,0,0,1-5.66,0L128,85.66,50.83,162.83a4,4,0,0,1-5.66-5.66l80-80a4,4,0,0,1,5.66,0l80,80A4,4,0,0,1,210.83,162.83Z"}))]]),O=a.forwardRef((l,c)=>a.createElement(Y,{ref:c,...l,weights:me}));O.displayName="CaretUpIcon";const he=O,k=["id","name","template","replacement","createdAt","updatedAt"],ue=new Set(k),pe=`query FetchPlaceholders(
2
2
  $searchFilter: SearchFilterInput,
3
3
  $pagination: PaginationInput
4
4
  ) {
@@ -31,4 +31,4 @@ __PLACEHOLDER_FIELDS__ }
31
31
  }
32
32
  }`,l),fe=l=>E(`mutation DeletePlaceholder($id: ID!) {
33
33
  deletePlaceholder(id: $id)
34
- }`,{id:l}),I=ce(ie),Pe=()=>{const l=V(),c=W(),h=I.useNavigate(),{page:r}=I.useSearch(),[g,i]=a.useState(!1),[y,H]=a.useState(!0),[n,u]=a.useState({name:"",template:"",replacement:""}),o=25,T=v.placeholders.list({limit:o,offset:(r-1)*o}),[P]=a.useState(ee),{data:d,isLoading:p}=ae({queryKey:T,queryFn:async()=>{const t=await ge({offset:(r-1)*o,limit:o});if(t.type==="error")throw t;return t.allPlaceholders}}),F=M({mutationFn:ye,onSuccess:async()=>{l("Placeholder added successfully"),i(!1),u({name:"",template:"",replacement:""}),await c.invalidateQueries({queryKey:v.placeholders.listAll(),exact:!1})}}),q=M({mutationFn:fe,onSuccess:async()=>{l("Placeholder deleted successfully"),await c.invalidateQueries({queryKey:v.placeholders.listAll(),exact:!1})}}),B=P.length,x=d?.totalCount??0,Z=d?.placeholders??[],f="font-medium text-fg-tertiary",L="leading-[1.2]",A="break-all leading-[1.2]",S="leading-[1.2]",_="flex flex-col gap-px",R="space-y-px",Q="focus-ring-soft inline-flex items-center gap-2 rounded-[12px] border border-transparent px-2.5 py-1.5 text-fg-tertiary outline-none transition-colors hover:bg-hover-subtle hover:text-fg-default",K="relative",U="absolute right-2 top-2",G="focus-ring-soft surface-base group flex flex-col items-center justify-center gap-0.5 px-4 py-4 text-center text-fg-secondary outline-none transition-colors hover:bg-hover-subtle hover:text-fg-default",X="inline-flex h-[34px] w-[34px] items-center justify-center rounded-full border border-border-subtle bg-surface text-current transition-colors group-hover:border-border-secondary/70",z=x>0?`Placeholders (${x})`:void 0;return e.jsxs(te,{title:"Placeholders",variant:"default",heading:p?e.jsx($,{width:244,height:24,className:"rounded-full"}):z,description:p?e.jsx($,{width:260,height:16,className:"rounded-full"}):"Create tokens that get replaced with values when you clone a note",children:[e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs("section",{className:"space-y-3 border-b border-border-subtle/80 pb-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s,{as:"p",variant:"body",weight:"medium",children:"System placeholders"}),e.jsx(s,{as:"p",variant:"meta",tone:"secondary",children:"Built-in tokens for date and time that are always available when cloning notes"})]}),e.jsxs("button",{type:"button",onClick:()=>H(!y),className:Q,children:[e.jsxs(s,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:[B," items"]}),y?e.jsx(he,{className:"h-4 w-4"}):e.jsx(se,{className:"h-4 w-4"})]})]}),y&&e.jsx("div",{className:"grid-auto-cards grid gap-5",children:P.map(t=>e.jsx(D,{children:e.jsxs("div",{className:_,children:[e.jsx(s,{as:"div",variant:"body",weight:"medium",className:L,children:t.name}),e.jsxs("div",{className:R,children:[e.jsxs(s,{as:"div",variant:"meta",weight:"medium",tone:"secondary",className:A,children:[j,t.template,N]}),e.jsxs(s,{as:"div",variant:"label",weight:"medium",tone:"tertiary",className:S,children:["Current value: ",t.replacement]})]})]})},t.name))})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s,{as:"p",variant:"body",weight:"medium",children:"Custom placeholders"}),e.jsx(s,{as:"p",variant:"meta",tone:"secondary",children:"Custom tokens you define once and reuse whenever you clone a note"})]}),!p&&e.jsx(s,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:x===1?"1 item":`${x} items`})]}),!p&&e.jsxs("div",{className:"grid-auto-cards grid gap-5",children:[Z.map(t=>e.jsxs(D,{className:K,children:[e.jsx(C,{variant:"ghost",size:"icon-sm",className:U,onClick:()=>q.mutate(t.id.toString()),children:e.jsx(le,{className:"h-4 w-4"})}),e.jsxs("div",{className:_,children:[e.jsx(s,{as:"div",variant:"body",weight:"medium",className:`min-w-0 pr-8 ${L}`,children:t.name}),e.jsxs("div",{className:R,children:[e.jsxs(s,{as:"div",variant:"meta",weight:"medium",tone:"secondary",className:A,children:[j,t.template,N]}),e.jsxs(s,{as:"div",variant:"label",weight:"medium",tone:"tertiary",className:S,children:["Replaces with: ",t.replacement]})]})]})]},t.id)),e.jsxs("button",{type:"button",onClick:()=>i(!0),className:G,children:[e.jsx("span",{className:X,children:e.jsx(oe,{className:"h-4.5 w-4.5"})}),e.jsx(s,{as:"div",variant:"meta",weight:"medium",tone:"secondary",className:"text-current",children:"New custom"})]})]})]})]}),e.jsxs(m,{isOpen:g,onClose:()=>i(!1),children:[e.jsx(m.Header,{title:"Add Placeholder",onClose:()=>i(!1)}),e.jsxs(m.Body,{children:[e.jsx(m.Description,{className:"mb-4",children:"Create a token that swaps in a value when you clone a note"}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"name",className:f,children:"Name"}),e.jsx(b,{id:"name",type:"text",value:n.name,onChange:t=>u({...n,name:t.target.value}),placeholder:"Description of this placeholder"}),e.jsx(s,{as:"p",variant:"meta",tone:"secondary",children:"A readable label so you can find this placeholder later"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"template",className:f,children:"Placeholder"}),e.jsx(b,{id:"template",type:"text",value:n.template,onChange:t=>u({...n,template:t.target.value}),placeholder:"note_app"}),e.jsxs(s,{as:"p",variant:"meta",tone:"secondary",children:["Use it in a note as ",j,"your_placeholder",N]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"replacement",className:f,children:"Replacement"}),e.jsx(b,{id:"replacement",type:"text",value:n.replacement,onChange:t=>u({...n,replacement:t.target.value}),placeholder:"Ocean Brain"}),e.jsx(s,{as:"p",variant:"meta",tone:"secondary",children:"This value is inserted when the placeholder is replaced during cloning"})]})]})]}),e.jsx(m.Footer,{children:e.jsxs(de,{children:[e.jsx(C,{variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),e.jsx(C,{variant:"primary",isLoading:F.isPending,onClick:()=>{if(!n.name||!n.template||!n.replacement){l("All fields are required");return}F.mutate({name:n.name,template:n.template,replacement:n.replacement})},children:"Add"})]})})]}),e.jsx(ne,{fallback:null,children:d?.totalCount&&o<d.totalCount&&e.jsx(re,{page:r,last:Math.ceil(d.totalCount/o),onChange:t=>{h({search:J=>({...J,page:t})})}})})]})};export{Pe as default};
34
+ }`,{id:l}),I=ce(ie),Pe=()=>{const l=V(),c=W(),h=I.useNavigate(),{page:r}=I.useSearch(),[g,i]=a.useState(!1),[y,H]=a.useState(!0),[n,u]=a.useState({name:"",template:"",replacement:""}),o=25,T=v.placeholders.list({limit:o,offset:(r-1)*o}),[P]=a.useState(ee),{data:d,isLoading:p}=ae({queryKey:T,queryFn:async()=>{const t=await ge({offset:(r-1)*o,limit:o});if(t.type==="error")throw t;return t.allPlaceholders}}),F=M({mutationFn:ye,onSuccess:async()=>{l("Placeholder added successfully"),i(!1),u({name:"",template:"",replacement:""}),await c.invalidateQueries({queryKey:v.placeholders.listAll(),exact:!1})}}),q=M({mutationFn:fe,onSuccess:async()=>{l("Placeholder deleted successfully"),await c.invalidateQueries({queryKey:v.placeholders.listAll(),exact:!1})}}),B=P.length,x=d?.totalCount??0,Z=d?.placeholders??[],f="font-medium text-fg-tertiary",L="leading-[1.2]",A="break-all leading-[1.2]",S="leading-[1.2]",_="flex flex-col gap-px",R="space-y-px",Q="focus-ring-soft inline-flex items-center gap-2 rounded-[12px] border border-transparent px-2.5 py-1.5 text-fg-tertiary outline-none transition-colors hover:bg-hover-subtle hover:text-fg-default",K="relative",U="absolute right-2 top-2",G="focus-ring-soft surface-base group flex flex-col items-center justify-center gap-0.5 px-4 py-4 text-center text-fg-secondary outline-none transition-colors hover:bg-hover-subtle hover:text-fg-default",X="inline-flex h-[34px] w-[34px] items-center justify-center rounded-full border border-border-subtle bg-surface text-current transition-colors group-hover:border-border-secondary/70",z=x>0?`Placeholders (${x})`:void 0;return e.jsxs(te,{title:"Placeholders",variant:"default",heading:p?e.jsx($,{width:244,height:24,className:"rounded-full"}):z,description:p?e.jsx($,{width:260,height:16,className:"rounded-full"}):"Create tokens that get replaced with values when you clone a note",children:[e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs("section",{className:"space-y-3 border-b border-border-subtle/80 pb-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s,{as:"p",variant:"body",weight:"medium",children:"System placeholders"}),e.jsx(s,{as:"p",variant:"meta",tone:"secondary",children:"Built-in tokens for date and time that are always available when cloning notes"})]}),e.jsxs("button",{type:"button",onClick:()=>H(!y),className:Q,children:[e.jsxs(s,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:[B," items"]}),y?e.jsx(he,{className:"h-4 w-4"}):e.jsx(se,{className:"h-4 w-4"})]})]}),y&&e.jsx("div",{className:"grid-auto-cards grid gap-5",children:P.map(t=>e.jsx(D,{children:e.jsxs("div",{className:_,children:[e.jsx(s,{as:"div",variant:"body",weight:"medium",className:L,children:t.name}),e.jsxs("div",{className:R,children:[e.jsxs(s,{as:"div",variant:"meta",weight:"medium",tone:"secondary",className:A,children:[j,t.template,N]}),e.jsxs(s,{as:"div",variant:"label",weight:"medium",tone:"tertiary",className:S,children:["Current value: ",t.replacement]})]})]})},t.name))})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s,{as:"p",variant:"body",weight:"medium",children:"Custom placeholders"}),e.jsx(s,{as:"p",variant:"meta",tone:"secondary",children:"Custom tokens you define once and reuse whenever you clone a note"})]}),!p&&e.jsx(s,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:x===1?"1 item":`${x} items`})]}),!p&&e.jsxs("div",{className:"grid-auto-cards grid gap-5",children:[Z.map(t=>e.jsxs(D,{className:K,children:[e.jsx(C,{variant:"ghost",size:"icon-sm",className:U,onClick:()=>q.mutate(t.id.toString()),children:e.jsx(le,{className:"h-4 w-4"})}),e.jsxs("div",{className:_,children:[e.jsx(s,{as:"div",variant:"body",weight:"medium",className:`min-w-0 pr-8 ${L}`,children:t.name}),e.jsxs("div",{className:R,children:[e.jsxs(s,{as:"div",variant:"meta",weight:"medium",tone:"secondary",className:A,children:[j,t.template,N]}),e.jsxs(s,{as:"div",variant:"label",weight:"medium",tone:"tertiary",className:S,children:["Replaces with: ",t.replacement]})]})]})]},t.id)),e.jsxs("button",{type:"button",onClick:()=>i(!0),className:G,children:[e.jsx("span",{className:X,children:e.jsx(oe,{className:"h-4.5 w-4.5"})}),e.jsx(s,{as:"div",variant:"meta",weight:"medium",tone:"secondary",className:"text-current",children:"New custom"})]})]})]})]}),e.jsxs(m,{isOpen:g,onClose:()=>i(!1),variant:"form",children:[e.jsx(m.Header,{title:"Add Placeholder",onClose:()=>i(!1)}),e.jsxs(m.Body,{children:[e.jsx(m.Description,{className:"mb-4",children:"Create a token that swaps in a value when you clone a note"}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"name",className:f,children:"Name"}),e.jsx(b,{id:"name",type:"text",value:n.name,onChange:t=>u({...n,name:t.target.value}),placeholder:"Description of this placeholder"}),e.jsx(s,{as:"p",variant:"meta",tone:"secondary",children:"A readable label so you can find this placeholder later"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"template",className:f,children:"Placeholder"}),e.jsx(b,{id:"template",type:"text",value:n.template,onChange:t=>u({...n,template:t.target.value}),placeholder:"note_app"}),e.jsxs(s,{as:"p",variant:"meta",tone:"secondary",children:["Use it in a note as ",j,"your_placeholder",N]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"replacement",className:f,children:"Replacement"}),e.jsx(b,{id:"replacement",type:"text",value:n.replacement,onChange:t=>u({...n,replacement:t.target.value}),placeholder:"Ocean Brain"}),e.jsx(s,{as:"p",variant:"meta",tone:"secondary",children:"This value is inserted when the placeholder is replaced during cloning"})]})]})]}),e.jsx(m.Footer,{children:e.jsxs(de,{children:[e.jsx(C,{variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),e.jsx(C,{variant:"primary",isLoading:F.isPending,onClick:()=>{if(!n.name||!n.template||!n.replacement){l("All fields are required");return}F.mutate({name:n.name,template:n.template,replacement:n.replacement})},children:"Add"})]})})]}),e.jsx(ne,{fallback:null,children:d?.totalCount&&o<d.totalCount&&e.jsx(re,{page:r,last:Math.ceil(d.totalCount/o),onChange:t=>{h({search:J=>({...J,page:t})})}})})]})};export{Pe as default};
@@ -1 +1 @@
1
- import{j as e}from"./note-vendor-BofYbzmZ.js";import{Q as j,j as N,a7 as v,K as w,J as T,t as b,ai as S,q as n,U as E,aj as C,N as R,P as m,E as q,T as h,a8 as D,B as K,l as P,i as t,d as Q}from"./index-BglnLSet.js";import"./graph-vendor-CUxe67Lr.js";import{S as g}from"./SurfaceCard-BV6y4bCo.js";import"./note-core-BCgMq5QA.js";const i=25,u=N(v),y=30,p=`Deleted notes stay here for ${y} days before permanent removal`,A=a=>Q(a).format("YYYY-MM-DD HH:mm"),_=()=>e.jsx(m,{title:"Trash",variant:"default",heading:e.jsx(t,{width:118,height:24,className:"rounded-full"}),description:e.jsx(t,{width:352,height:16,className:"rounded-full"}),children:e.jsx("div",{className:"grid gap-3",children:Array.from({length:3},(a,d)=>e.jsx(g,{padding:"compact",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsx(t,{width:"40%",height:18,className:"rounded-full"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(t,{width:168,height:14,className:"rounded-full"}),e.jsx(t,{width:176,height:14,className:"rounded-full"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(t,{width:56,height:24,className:"rounded-full"}),e.jsx(t,{width:72,height:24,className:"rounded-full"})]})]}),e.jsx(t,{width:92,height:32,className:"rounded-[12px]"})]})},d))})}),k=()=>{const{page:a}=u.useSearch(),d=u.useNavigate(),l=w(),x=T(),{data:r}=b({queryKey:n.notes.trash({limit:i,offset:(a-1)*i}),queryFn:async()=>{const s=await S({limit:i,offset:(a-1)*i});if(s.type==="error")throw s;return s.trashedNotes}}),c=E({mutationFn:C,onSuccess:async s=>{if(s.type==="error")throw s;await Promise.all([l.invalidateQueries({queryKey:n.notes.all(),exact:!1}),l.invalidateQueries({queryKey:n.tags.all(),exact:!1}),l.invalidateQueries({queryKey:n.reminders.all(),exact:!1}),l.invalidateQueries({queryKey:n.images.all(),exact:!1}),l.invalidateQueries({queryKey:["calendar"],exact:!1})]),x("The note has been restored."),d({to:R,params:{id:s.restoreTrashedNote.id}})},onError:()=>{x("Failed to restore the note.")}}),f=r.totalCount>0?`Trash (${r.totalCount})`:void 0;return r.notes.length===0?e.jsx(m,{title:"Trash",variant:"default",heading:f,description:p,children:e.jsx(q,{title:"Trash is empty",description:`Delete a note and you can restore it here for ${y} days before permanent removal`})}):e.jsx(m,{title:"Trash",variant:"default",heading:f,description:p,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"grid gap-3",children:r.notes.map(s=>e.jsx(g,{padding:"compact",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[e.jsx(h,{as:"h2",variant:"body",weight:"medium",className:"min-w-0 flex-1 break-words leading-[1.25]",children:s.title||"Untitled note"}),s.pinned&&e.jsx("span",{title:"Pinned",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center text-fg-tertiary",children:e.jsx(D,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1",children:e.jsxs(h,{as:"div",variant:"meta",weight:"medium",tone:"secondary",children:["Deleted ",A(s.deletedAt)]})}),s.tagNames.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:s.tagNames.map(o=>e.jsx(h,{as:"span",variant:"label",weight:"medium",tone:"tertiary",className:"rounded-full border border-border-subtle bg-hover-subtle px-2 py-0.5",children:o},`${s.id}-${o}`))})]}),e.jsx(K,{variant:"subtle",size:"sm",className:"self-start",isLoading:c.isPending&&c.variables===s.id,onClick:()=>c.mutate(s.id),children:"Restore"})]})},s.id))}),r.totalCount>i&&e.jsx(P,{page:a,last:Math.ceil(r.totalCount/i),onChange:s=>{d({search:o=>({...o,page:s})})}})]})})},F=()=>{const{page:a}=u.useSearch();return e.jsx(j,{fallback:e.jsx(_,{}),errorTitle:"Failed to load trash",errorDescription:"Retry loading deleted notes",resetKeys:[a],children:e.jsx(k,{})})};export{F as default};
1
+ import{j as e}from"./note-vendor-BofYbzmZ.js";import{Q as j,j as N,a7 as v,K as w,J as T,t as b,ai as S,q as n,U as E,aj as C,N as R,P as m,E as q,T as h,a8 as D,B as K,l as P,i as t,d as Q}from"./index-Ba2XPRI8.js";import"./graph-vendor-CUxe67Lr.js";import{S as g}from"./SurfaceCard-nZNf9lyE.js";import"./note-core-BCgMq5QA.js";const i=25,u=N(v),y=30,p=`Deleted notes stay here for ${y} days before permanent removal`,A=a=>Q(a).format("YYYY-MM-DD HH:mm"),_=()=>e.jsx(m,{title:"Trash",variant:"default",heading:e.jsx(t,{width:118,height:24,className:"rounded-full"}),description:e.jsx(t,{width:352,height:16,className:"rounded-full"}),children:e.jsx("div",{className:"grid gap-3",children:Array.from({length:3},(a,d)=>e.jsx(g,{padding:"compact",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsx(t,{width:"40%",height:18,className:"rounded-full"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(t,{width:168,height:14,className:"rounded-full"}),e.jsx(t,{width:176,height:14,className:"rounded-full"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(t,{width:56,height:24,className:"rounded-full"}),e.jsx(t,{width:72,height:24,className:"rounded-full"})]})]}),e.jsx(t,{width:92,height:32,className:"rounded-[12px]"})]})},d))})}),k=()=>{const{page:a}=u.useSearch(),d=u.useNavigate(),l=w(),x=T(),{data:r}=b({queryKey:n.notes.trash({limit:i,offset:(a-1)*i}),queryFn:async()=>{const s=await S({limit:i,offset:(a-1)*i});if(s.type==="error")throw s;return s.trashedNotes}}),c=E({mutationFn:C,onSuccess:async s=>{if(s.type==="error")throw s;await Promise.all([l.invalidateQueries({queryKey:n.notes.all(),exact:!1}),l.invalidateQueries({queryKey:n.tags.all(),exact:!1}),l.invalidateQueries({queryKey:n.reminders.all(),exact:!1}),l.invalidateQueries({queryKey:n.images.all(),exact:!1}),l.invalidateQueries({queryKey:["calendar"],exact:!1})]),x("The note has been restored."),d({to:R,params:{id:s.restoreTrashedNote.id}})},onError:()=>{x("Failed to restore the note.")}}),f=r.totalCount>0?`Trash (${r.totalCount})`:void 0;return r.notes.length===0?e.jsx(m,{title:"Trash",variant:"default",heading:f,description:p,children:e.jsx(q,{title:"Trash is empty",description:`Delete a note and you can restore it here for ${y} days before permanent removal`})}):e.jsx(m,{title:"Trash",variant:"default",heading:f,description:p,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"grid gap-3",children:r.notes.map(s=>e.jsx(g,{padding:"compact",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[e.jsx(h,{as:"h2",variant:"body",weight:"medium",className:"min-w-0 flex-1 break-words leading-[1.25]",children:s.title||"Untitled note"}),s.pinned&&e.jsx("span",{title:"Pinned",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center text-fg-tertiary",children:e.jsx(D,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1",children:e.jsxs(h,{as:"div",variant:"meta",weight:"medium",tone:"secondary",children:["Deleted ",A(s.deletedAt)]})}),s.tagNames.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:s.tagNames.map(o=>e.jsx(h,{as:"span",variant:"label",weight:"medium",tone:"tertiary",className:"rounded-full border border-border-subtle bg-hover-subtle px-2 py-0.5",children:o},`${s.id}-${o}`))})]}),e.jsx(K,{variant:"subtle",size:"sm",className:"self-start",isLoading:c.isPending&&c.variables===s.id,onClick:()=>c.mutate(s.id),children:"Restore"})]})},s.id))}),r.totalCount>i&&e.jsx(P,{page:a,last:Math.ceil(r.totalCount/i),onChange:s=>{d({search:o=>({...o,page:s})})}})]})})},F=()=>{const{page:a}=u.useSearch();return e.jsx(j,{fallback:e.jsx(_,{}),errorTitle:"Failed to load trash",errorDescription:"Retry loading deleted notes",resetKeys:[a],children:e.jsx(k,{})})};export{F as default};
@@ -1,4 +1,4 @@
1
- import{j as y}from"./note-vendor-BofYbzmZ.js";import{h as u,t as f,q as n,J as R,K as $}from"./index-BglnLSet.js";import{a as l}from"./graph-vendor-CUxe67Lr.js";const g=(e={})=>({limit:e.limit??10,offset:e.offset??0}),D=async(e,t)=>u(`
1
+ import{j as y}from"./note-vendor-BofYbzmZ.js";import{h as u,t as f,q as n,J as R,K as $}from"./index-Ba2XPRI8.js";import{a as l}from"./graph-vendor-CUxe67Lr.js";const g=(e={})=>({limit:e.limit??10,offset:e.offset??0}),D=async(e,t)=>u(`
2
2
  query FetchNoteReminders($noteId: ID!, $pagination: PaginationInput) {
3
3
  noteReminders(noteId: $noteId, pagination: $pagination) {
4
4
  totalCount
@@ -6,11 +6,11 @@
6
6
  <link rel="icon" type="image/png" href="/icon.png" />
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
8
  <title>Ocean Brain</title>
9
- <script type="module" crossorigin src="/assets/index-BglnLSet.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-Ba2XPRI8.js"></script>
10
10
  <link rel="modulepreload" crossorigin href="/assets/graph-vendor-CUxe67Lr.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/note-core-BCgMq5QA.js">
12
12
  <link rel="modulepreload" crossorigin href="/assets/note-vendor-BofYbzmZ.js">
13
- <link rel="stylesheet" crossorigin href="/assets/index-CD2bFEqK.css">
13
+ <link rel="stylesheet" crossorigin href="/assets/index-DL7pUwq2.css">
14
14
  </head>
15
15
 
16
16
  <body>
@@ -33,10 +33,87 @@ function stripUnsupportedMarkdownBlocks(blocks) {
33
33
  function createTagPlaceholder(index) {
34
34
  return `${TAG_PLACEHOLDER_PREFIX}${index}${TAG_PLACEHOLDER_SUFFIX}`;
35
35
  }
36
- function preprocessCustomInlineContent(blocks, placeholderToTag, nextPlaceholderIndex) {
36
+ function isTableContent(content) {
37
+ return !Array.isArray(content) && content?.type === "tableContent";
38
+ }
39
+ function mapBlockContent(content, mapInline) {
40
+ if (Array.isArray(content)) {
41
+ return content.map(mapInline);
42
+ }
43
+ if (!isTableContent(content)) {
44
+ return content;
45
+ }
46
+ return {
47
+ ...content,
48
+ rows: content.rows?.map((row) => ({
49
+ ...row,
50
+ cells: row.cells?.map((cell) => ({
51
+ ...cell,
52
+ content: cell.content?.map(mapInline)
53
+ }))
54
+ }))
55
+ };
56
+ }
57
+ async function mapBlockContentAsync(content, mapInline) {
58
+ if (Array.isArray(content)) {
59
+ return (await Promise.all(content.map(mapInline))).flat();
60
+ }
61
+ if (!isTableContent(content)) {
62
+ return content;
63
+ }
64
+ return {
65
+ ...content,
66
+ rows: await Promise.all(
67
+ (content.rows ?? []).map(async (row) => ({
68
+ ...row,
69
+ cells: await Promise.all(
70
+ (row.cells ?? []).map(async (cell) => ({
71
+ ...cell,
72
+ content: cell.content ? (await Promise.all(cell.content.map(mapInline))).flat() : cell.content
73
+ }))
74
+ )
75
+ }))
76
+ )
77
+ };
78
+ }
79
+ function visitBlockContent(content, visitInline) {
80
+ if (Array.isArray(content)) {
81
+ for (const inline of content) {
82
+ visitInline(inline);
83
+ }
84
+ return;
85
+ }
86
+ if (!isTableContent(content)) {
87
+ return;
88
+ }
89
+ for (const row of content.rows ?? []) {
90
+ for (const cell of row.cells ?? []) {
91
+ for (const inline of cell.content ?? []) {
92
+ visitInline(inline);
93
+ }
94
+ }
95
+ }
96
+ }
97
+ function mapBlocks(blocks, mapContent) {
37
98
  return blocks.map((block) => ({
38
99
  ...block,
39
- content: Array.isArray(block.content) ? block.content.map((inline) => {
100
+ content: mapContent(block.content),
101
+ children: block.children?.length ? mapBlocks(block.children, mapContent) : []
102
+ }));
103
+ }
104
+ async function mapBlocksAsync(blocks, mapContent) {
105
+ return Promise.all(
106
+ blocks.map(async (block) => ({
107
+ ...block,
108
+ content: await mapContent(block.content),
109
+ children: block.children?.length ? await mapBlocksAsync(block.children, mapContent) : []
110
+ }))
111
+ );
112
+ }
113
+ function preprocessCustomInlineContent(blocks, placeholderToTag, nextPlaceholderIndex) {
114
+ return mapBlocks(
115
+ blocks,
116
+ (content) => mapBlockContent(content, (inline) => {
40
117
  if (inline.type === "reference") {
41
118
  return {
42
119
  type: "text",
@@ -55,9 +132,8 @@ function preprocessCustomInlineContent(blocks, placeholderToTag, nextPlaceholder
55
132
  };
56
133
  }
57
134
  return inline;
58
- }) : block.content,
59
- children: block.children?.length ? preprocessCustomInlineContent(block.children, placeholderToTag, nextPlaceholderIndex) : []
60
- }));
135
+ })
136
+ );
61
137
  }
62
138
  function restoreTagPlaceholdersInMarkdown(markdown, placeholderToTag) {
63
139
  let restoredMarkdown = markdown;
@@ -91,9 +167,9 @@ function findTagPlaceholderAtCursor(text, cursor, placeholderToTag) {
91
167
  return null;
92
168
  }
93
169
  function restoreRemainingTagPlaceholders(blocks, placeholderToTag) {
94
- return blocks.map((block) => ({
95
- ...block,
96
- content: Array.isArray(block.content) ? block.content.map((inline) => {
170
+ return mapBlocks(
171
+ blocks,
172
+ (content) => mapBlockContent(content, (inline) => {
97
173
  if (inline.type !== "text" || typeof inline.text !== "string") {
98
174
  return inline;
99
175
  }
@@ -105,9 +181,8 @@ function restoreRemainingTagPlaceholders(blocks, placeholderToTag) {
105
181
  ...inline,
106
182
  text
107
183
  };
108
- }) : block.content,
109
- children: block.children?.length ? restoreRemainingTagPlaceholders(block.children, placeholderToTag) : []
110
- }));
184
+ })
185
+ );
111
186
  }
112
187
  function createTextInline(text, styles = {}) {
113
188
  return {
@@ -199,23 +274,20 @@ async function restoreCustomInlineContent(blocks, deps, placeholderToTag) {
199
274
  }
200
275
  return restored;
201
276
  };
202
- return Promise.all(
203
- blocks.map(async (block) => ({
204
- ...block,
205
- content: block.content ? (await Promise.all(block.content.map((inline) => restoreTextInline(inline)))).flat() : void 0,
206
- children: block.children?.length ? await restoreCustomInlineContent(block.children, deps, placeholderToTag) : []
207
- }))
277
+ return mapBlocksAsync(
278
+ blocks,
279
+ (content) => mapBlockContentAsync(content, restoreTextInline)
208
280
  );
209
281
  }
210
282
  function collectTagIds(blocks) {
211
283
  const tagIds = /* @__PURE__ */ new Set();
212
284
  const visit = (items) => {
213
285
  for (const block of items) {
214
- for (const inline of block.content ?? []) {
286
+ visitBlockContent(block.content, (inline) => {
215
287
  if (inline.type === "tag" && typeof inline.props?.id === "string") {
216
288
  tagIds.add(inline.props.id);
217
289
  }
218
- }
290
+ });
219
291
  if (block.children?.length) {
220
292
  visit(block.children);
221
293
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/modules/blocknote.ts"],"sourcesContent":["import { ServerBlockNoteEditor } from '@blocknote/server-util';\n\nimport models from '~/models.js';\nimport { ensureTagByName } from './tag-organization.js';\n\ninterface BlockNote {\n id?: string;\n type: string;\n props?: Record<string, unknown>;\n content?: BlockNoteInline[];\n children?: BlockNote[];\n text?: string;\n styles?: Record<string, unknown>;\n}\n\ninterface BlockNoteInline {\n type: string;\n props?: Record<string, unknown>;\n text?: string;\n styles?: Record<string, unknown>;\n}\n\ninterface MarkdownImportDeps {\n ensureTag: (name: string) => Promise<\n | {\n id: string;\n name: string;\n }\n | {\n tag: {\n id: string;\n name: string;\n };\n }\n >;\n findNotesByTitle: (title: string) => Promise<Array<{\n id: string;\n title: string;\n }>>;\n}\n\nconst UNSUPPORTED_MARKDOWN_BLOCK_TYPES = new Set([\n 'tableOfContents'\n]);\nconst TAG_PLACEHOLDER_PREFIX = 'OCEAN_BRAIN_TAG_';\nconst TAG_PLACEHOLDER_SUFFIX = '_TOKEN';\n\nconst defaultMarkdownImportDeps: MarkdownImportDeps = {\n ensureTag: async (name) => ensureTagByName(name),\n findNotesByTitle: async (title) => {\n const notes = await models.note.findMany({\n select: {\n id: true,\n title: true\n },\n where: { title },\n orderBy: { createdAt: 'asc' },\n take: 2\n });\n\n return notes.map((note) => ({\n id: String(note.id),\n title: note.title\n }));\n }\n};\n\nfunction stripUnsupportedMarkdownBlocks(blocks: BlockNote[]): BlockNote[] {\n return blocks\n .filter((block) => !UNSUPPORTED_MARKDOWN_BLOCK_TYPES.has(block.type))\n .map((block) => ({\n ...block,\n children: block.children?.length\n ? stripUnsupportedMarkdownBlocks(block.children)\n : []\n }));\n}\n\nfunction createTagPlaceholder(index: number) {\n return `${TAG_PLACEHOLDER_PREFIX}${index}${TAG_PLACEHOLDER_SUFFIX}`;\n}\n\nfunction preprocessCustomInlineContent(\n blocks: BlockNote[],\n placeholderToTag: Map<string, string>,\n nextPlaceholderIndex: { value: number }\n): BlockNote[] {\n return blocks.map((block) => ({\n ...block,\n content: Array.isArray(block.content)\n ? block.content.map((inline) => {\n if (inline.type === 'reference') {\n return {\n type: 'text',\n text: `[[${inline.props?.title || inline.props?.id || ''}]]`,\n styles: {}\n };\n }\n if (inline.type === 'tag') {\n const tag = (inline.props?.tag as string) || '';\n const placeholder = createTagPlaceholder(nextPlaceholderIndex.value++);\n placeholderToTag.set(placeholder, tag);\n return {\n type: 'text',\n text: placeholder,\n styles: {}\n };\n }\n return inline;\n })\n : block.content,\n children: block.children?.length\n ? preprocessCustomInlineContent(block.children, placeholderToTag, nextPlaceholderIndex)\n : []\n }));\n}\n\nfunction restoreTagPlaceholdersInMarkdown(markdown: string, placeholderToTag: Map<string, string>) {\n let restoredMarkdown = markdown;\n\n for (const [placeholder, tag] of placeholderToTag.entries()) {\n restoredMarkdown = restoredMarkdown.split(placeholder).join(`[${tag}]`);\n }\n\n return restoredMarkdown;\n}\n\nfunction preprocessMarkdownExplicitTags(markdown: string) {\n const placeholderToTag = new Map<string, string>();\n let nextPlaceholderIndex = 0;\n const preprocessedMarkdown = markdown.replace(/\\[([@#][^\\s[\\]]+)\\]/g, (_match, tagToken: string) => {\n const placeholder = createTagPlaceholder(nextPlaceholderIndex++);\n placeholderToTag.set(placeholder, tagToken);\n return placeholder;\n });\n\n return {\n markdown: preprocessedMarkdown,\n placeholderToTag\n };\n}\n\nfunction findTagPlaceholderAtCursor(\n text: string,\n cursor: number,\n placeholderToTag: Map<string, string>\n) {\n for (const [placeholder, tagToken] of placeholderToTag.entries()) {\n if (text.startsWith(placeholder, cursor)) {\n return {\n placeholder,\n tagToken\n };\n }\n }\n\n return null;\n}\n\nfunction restoreRemainingTagPlaceholders(\n blocks: BlockNote[],\n placeholderToTag: Map<string, string>\n): BlockNote[] {\n return blocks.map((block) => ({\n ...block,\n content: Array.isArray(block.content)\n ? block.content.map((inline) => {\n if (inline.type !== 'text' || typeof inline.text !== 'string') {\n return inline;\n }\n\n let text = inline.text;\n\n for (const [placeholder, tagToken] of placeholderToTag.entries()) {\n text = text.split(placeholder).join(`[${tagToken}]`);\n }\n\n return {\n ...inline,\n text\n };\n })\n : block.content,\n children: block.children?.length\n ? restoreRemainingTagPlaceholders(block.children, placeholderToTag)\n : []\n }));\n}\n\nfunction createTextInline(text: string, styles: Record<string, unknown> = {}): BlockNoteInline {\n return {\n type: 'text',\n text,\n styles\n };\n}\n\nfunction appendInline(target: BlockNoteInline[], inline: BlockNoteInline) {\n const previous = target.at(-1);\n\n if (\n previous?.type === 'text' &&\n inline.type === 'text' &&\n previous.text !== undefined &&\n inline.text !== undefined &&\n JSON.stringify(previous.styles ?? {}) === JSON.stringify(inline.styles ?? {})\n ) {\n previous.text += inline.text;\n return;\n }\n\n target.push(inline);\n}\n\nasync function restoreCustomInlineContent(\n blocks: BlockNote[],\n deps: MarkdownImportDeps,\n placeholderToTag: Map<string, string>\n): Promise<BlockNote[]> {\n const tagCache = new Map<string, Promise<{ id: string; tag: string }>>();\n const noteCache = new Map<string, Promise<Array<{ id: string; title: string }>>>();\n\n const getTag = (token: string) => {\n const normalizedToken = token.startsWith('#')\n ? `@${token.slice(1)}`\n : token;\n let existing = tagCache.get(normalizedToken);\n\n if (!existing) {\n existing = deps.ensureTag(normalizedToken.slice(1)).then((result) => ({\n id: 'tag' in result ? result.tag.id : result.id,\n tag: 'tag' in result ? result.tag.name : result.name\n }));\n tagCache.set(normalizedToken, existing);\n }\n\n return existing;\n };\n\n const getNotesByTitle = (title: string) => {\n let existing = noteCache.get(title);\n\n if (!existing) {\n existing = deps.findNotesByTitle(title);\n noteCache.set(title, existing);\n }\n\n return existing;\n };\n\n const restoreTextInline = async (inline: BlockNoteInline): Promise<BlockNoteInline[]> => {\n if (\n inline.type !== 'text' ||\n typeof inline.text !== 'string' ||\n !inline.text ||\n inline.styles?.code === true\n ) {\n return [inline];\n }\n\n const restored: BlockNoteInline[] = [];\n const styles = inline.styles ?? {};\n let cursor = 0;\n\n while (cursor < inline.text.length) {\n if (inline.text.startsWith('[[', cursor)) {\n const closeIndex = inline.text.indexOf(']]', cursor + 2);\n\n if (closeIndex !== -1) {\n const title = inline.text.slice(cursor + 2, closeIndex);\n const matchingNotes = await getNotesByTitle(title);\n\n if (matchingNotes.length === 1) {\n appendInline(restored, {\n type: 'reference',\n props: {\n id: matchingNotes[0].id,\n title: matchingNotes[0].title\n }\n });\n cursor = closeIndex + 2;\n continue;\n }\n }\n }\n\n const tagPlaceholderMatch = findTagPlaceholderAtCursor(inline.text, cursor, placeholderToTag);\n\n if (tagPlaceholderMatch) {\n const tag = await getTag(tagPlaceholderMatch.tagToken);\n appendInline(restored, {\n type: 'tag',\n props: tag\n });\n cursor += tagPlaceholderMatch.placeholder.length;\n continue;\n }\n\n let nextCursor = inline.text.length;\n\n const nextReferenceCursor = inline.text.indexOf('[[', cursor + 1);\n\n if (nextReferenceCursor !== -1) {\n nextCursor = Math.min(nextCursor, nextReferenceCursor);\n }\n\n for (const placeholder of placeholderToTag.keys()) {\n const nextPlaceholderCursor = inline.text.indexOf(placeholder, cursor + 1);\n\n if (nextPlaceholderCursor !== -1) {\n nextCursor = Math.min(nextCursor, nextPlaceholderCursor);\n }\n }\n\n appendInline(restored, createTextInline(inline.text.slice(cursor, nextCursor), styles));\n cursor = nextCursor;\n }\n\n return restored;\n };\n\n return Promise.all(\n blocks.map(async (block) => ({\n ...block,\n content: block.content\n ? (await Promise.all(block.content.map((inline) => restoreTextInline(inline)))).flat()\n : undefined,\n children: block.children?.length\n ? await restoreCustomInlineContent(block.children, deps, placeholderToTag)\n : []\n }))\n );\n}\n\nfunction collectTagIds(blocks: BlockNote[]): string[] {\n const tagIds = new Set<string>();\n\n const visit = (items: BlockNote[]) => {\n for (const block of items) {\n for (const inline of block.content ?? []) {\n if (inline.type === 'tag' && typeof inline.props?.id === 'string') {\n tagIds.add(inline.props.id);\n }\n }\n\n if (block.children?.length) {\n visit(block.children);\n }\n }\n };\n\n visit(blocks);\n return [...tagIds];\n}\n\nlet editorInstance: ServerBlockNoteEditor | null = null;\n\nfunction getEditor(): ServerBlockNoteEditor {\n if (!editorInstance) {\n editorInstance = ServerBlockNoteEditor.create();\n }\n return editorInstance;\n}\n\nexport async function blocksToMarkdown(contentJson: string): Promise<string> {\n try {\n const blocks = JSON.parse(contentJson);\n const supportedBlocks = stripUnsupportedMarkdownBlocks(blocks);\n const placeholderToTag = new Map<string, string>();\n const processed = preprocessCustomInlineContent(\n supportedBlocks,\n placeholderToTag,\n { value: 0 }\n );\n const editor = getEditor();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const markdown = await editor.blocksToMarkdownLossy(processed as any);\n return restoreTagPlaceholdersInMarkdown(markdown, placeholderToTag);\n } catch {\n return '';\n }\n}\n\nexport async function markdownToBlocksJson(\n markdown: string,\n deps: MarkdownImportDeps = defaultMarkdownImportDeps\n): Promise<string> {\n const editor = getEditor();\n const preprocessedMarkdown = preprocessMarkdownExplicitTags(markdown);\n const blocks = await editor.tryParseMarkdownToBlocks(preprocessedMarkdown.markdown);\n const restoredBlocks = await restoreCustomInlineContent(\n blocks as BlockNote[],\n deps,\n preprocessedMarkdown.placeholderToTag\n );\n return JSON.stringify(\n restoreRemainingTagPlaceholders(restoredBlocks, preprocessedMarkdown.placeholderToTag)\n );\n}\n\nexport function extractTagIdsFromContentJson(contentJson: string): string[] {\n const blocks = JSON.parse(contentJson) as BlockNote[];\n return collectTagIds(blocks);\n}\n"],"mappings":"AAAA,SAAS,6BAA6B;AAEtC,OAAO,YAAY;AACnB,SAAS,uBAAuB;AAsChC,MAAM,mCAAmC,oBAAI,IAAI;AAAA,EAC7C;AACJ,CAAC;AACD,MAAM,yBAAyB;AAC/B,MAAM,yBAAyB;AAE/B,MAAM,4BAAgD;AAAA,EAClD,WAAW,OAAO,SAAS,gBAAgB,IAAI;AAAA,EAC/C,kBAAkB,OAAO,UAAU;AAC/B,UAAM,QAAQ,MAAM,OAAO,KAAK,SAAS;AAAA,MACrC,QAAQ;AAAA,QACJ,IAAI;AAAA,QACJ,OAAO;AAAA,MACX;AAAA,MACA,OAAO,EAAE,MAAM;AAAA,MACf,SAAS,EAAE,WAAW,MAAM;AAAA,MAC5B,MAAM;AAAA,IACV,CAAC;AAED,WAAO,MAAM,IAAI,CAAC,UAAU;AAAA,MACxB,IAAI,OAAO,KAAK,EAAE;AAAA,MAClB,OAAO,KAAK;AAAA,IAChB,EAAE;AAAA,EACN;AACJ;AAEA,SAAS,+BAA+B,QAAkC;AACtE,SAAO,OACF,OAAO,CAAC,UAAU,CAAC,iCAAiC,IAAI,MAAM,IAAI,CAAC,EACnE,IAAI,CAAC,WAAW;AAAA,IACb,GAAG;AAAA,IACH,UAAU,MAAM,UAAU,SACpB,+BAA+B,MAAM,QAAQ,IAC7C,CAAC;AAAA,EACX,EAAE;AACV;AAEA,SAAS,qBAAqB,OAAe;AACzC,SAAO,GAAG,sBAAsB,GAAG,KAAK,GAAG,sBAAsB;AACrE;AAEA,SAAS,8BACL,QACA,k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KAAK;AAAA,IACR,gCAAgC,gBAAgB,qBAAqB,gBAAgB;AAAA,EACzF;AACJ;AAEO,SAAS,6BAA6B,aAA+B;AACxE,QAAM,SAAS,KAAK,MAAM,WAAW;AACrC,SAAO,cAAc,MAAM;AAC/B;","names":[]}
1
+ {"version":3,"sources":["../../src/modules/blocknote.ts"],"sourcesContent":["import { ServerBlockNoteEditor } from '@blocknote/server-util';\n\nimport models from '~/models.js';\nimport { ensureTagByName } from './tag-organization.js';\n\ninterface BlockNote {\n id?: string;\n type: string;\n props?: Record<string, unknown>;\n content?: BlockNoteContent;\n children?: BlockNote[];\n text?: string;\n styles?: Record<string, unknown>;\n}\n\ninterface BlockNoteInline {\n type: string;\n props?: Record<string, unknown>;\n text?: string;\n styles?: Record<string, unknown>;\n}\n\ninterface BlockNoteTableCell {\n type: 'tableCell';\n props?: Record<string, unknown>;\n content?: BlockNoteInline[];\n}\n\ninterface BlockNoteTableRow {\n cells?: BlockNoteTableCell[];\n}\n\ninterface BlockNoteTableContent {\n type: 'tableContent';\n columnWidths?: Array<number | null>;\n headerRows?: number;\n rows?: BlockNoteTableRow[];\n}\n\ntype BlockNoteContent = BlockNoteInline[] | BlockNoteTableContent;\n\ninterface MarkdownImportDeps {\n ensureTag: (name: string) => Promise<\n | {\n id: string;\n name: string;\n }\n | {\n tag: {\n id: string;\n name: string;\n };\n }\n >;\n findNotesByTitle: (title: string) => Promise<Array<{\n id: string;\n title: string;\n }>>;\n}\n\nconst UNSUPPORTED_MARKDOWN_BLOCK_TYPES = new Set([\n 'tableOfContents'\n]);\nconst TAG_PLACEHOLDER_PREFIX = 'OCEAN_BRAIN_TAG_';\nconst TAG_PLACEHOLDER_SUFFIX = '_TOKEN';\n\nconst defaultMarkdownImportDeps: MarkdownImportDeps = {\n ensureTag: async (name) => ensureTagByName(name),\n findNotesByTitle: async (title) => {\n const notes = await models.note.findMany({\n select: {\n id: true,\n title: true\n },\n where: { title },\n orderBy: { createdAt: 'asc' },\n take: 2\n });\n\n return notes.map((note) => ({\n id: String(note.id),\n title: note.title\n }));\n }\n};\n\nfunction stripUnsupportedMarkdownBlocks(blocks: BlockNote[]): BlockNote[] {\n return blocks\n .filter((block) => !UNSUPPORTED_MARKDOWN_BLOCK_TYPES.has(block.type))\n .map((block) => ({\n ...block,\n children: block.children?.length\n ? stripUnsupportedMarkdownBlocks(block.children)\n : []\n }));\n}\n\nfunction createTagPlaceholder(index: number) {\n return `${TAG_PLACEHOLDER_PREFIX}${index}${TAG_PLACEHOLDER_SUFFIX}`;\n}\n\nfunction isTableContent(content: BlockNoteContent | undefined): content is BlockNoteTableContent {\n return !Array.isArray(content) && content?.type === 'tableContent';\n}\n\nfunction mapBlockContent(\n content: BlockNoteContent | undefined,\n mapInline: (inline: BlockNoteInline) => BlockNoteInline\n): BlockNoteContent | undefined {\n if (Array.isArray(content)) {\n return content.map(mapInline);\n }\n\n if (!isTableContent(content)) {\n return content;\n }\n\n return {\n ...content,\n rows: content.rows?.map((row) => ({\n ...row,\n cells: row.cells?.map((cell) => ({\n ...cell,\n content: cell.content?.map(mapInline)\n }))\n }))\n };\n}\n\nasync function mapBlockContentAsync(\n content: BlockNoteContent | undefined,\n mapInline: (inline: BlockNoteInline) => Promise<BlockNoteInline[]>\n): Promise<BlockNoteContent | undefined> {\n if (Array.isArray(content)) {\n return (await Promise.all(content.map(mapInline))).flat();\n }\n\n if (!isTableContent(content)) {\n return content;\n }\n\n return {\n ...content,\n rows: await Promise.all(\n (content.rows ?? []).map(async (row) => ({\n ...row,\n cells: await Promise.all(\n (row.cells ?? []).map(async (cell) => ({\n ...cell,\n content: cell.content\n ? (await Promise.all(cell.content.map(mapInline))).flat()\n : cell.content\n }))\n )\n }))\n )\n };\n}\n\nfunction visitBlockContent(\n content: BlockNoteContent | undefined,\n visitInline: (inline: BlockNoteInline) => void\n) {\n if (Array.isArray(content)) {\n for (const inline of content) {\n visitInline(inline);\n }\n return;\n }\n\n if (!isTableContent(content)) {\n return;\n }\n\n for (const row of content.rows ?? []) {\n for (const cell of row.cells ?? []) {\n for (const inline of cell.content ?? []) {\n visitInline(inline);\n }\n }\n }\n}\n\nfunction mapBlocks(\n blocks: BlockNote[],\n mapContent: (content: BlockNoteContent | undefined) => BlockNoteContent | undefined\n): BlockNote[] {\n return blocks.map((block) => ({\n ...block,\n content: mapContent(block.content),\n children: block.children?.length\n ? mapBlocks(block.children, mapContent)\n : []\n }));\n}\n\nasync function mapBlocksAsync(\n blocks: BlockNote[],\n mapContent: (content: BlockNoteContent | undefined) => Promise<BlockNoteContent | undefined>\n): Promise<BlockNote[]> {\n return Promise.all(\n blocks.map(async (block) => ({\n ...block,\n content: await mapContent(block.content),\n children: block.children?.length\n ? await mapBlocksAsync(block.children, mapContent)\n : []\n }))\n );\n}\n\nfunction preprocessCustomInlineContent(\n blocks: BlockNote[],\n placeholderToTag: Map<string, string>,\n nextPlaceholderIndex: { value: number }\n): BlockNote[] {\n return mapBlocks(\n blocks,\n (content) => mapBlockContent(content, (inline) => {\n if (inline.type === 'reference') {\n return {\n type: 'text',\n text: `[[${inline.props?.title || inline.props?.id || ''}]]`,\n styles: {}\n };\n }\n if (inline.type === 'tag') {\n const tag = (inline.props?.tag as string) || '';\n const placeholder = createTagPlaceholder(nextPlaceholderIndex.value++);\n placeholderToTag.set(placeholder, tag);\n return {\n type: 'text',\n text: placeholder,\n styles: {}\n };\n }\n return inline;\n })\n );\n}\n\nfunction restoreTagPlaceholdersInMarkdown(markdown: string, placeholderToTag: Map<string, string>) {\n let restoredMarkdown = markdown;\n\n for (const [placeholder, tag] of placeholderToTag.entries()) {\n restoredMarkdown = restoredMarkdown.split(placeholder).join(`[${tag}]`);\n }\n\n return restoredMarkdown;\n}\n\nfunction preprocessMarkdownExplicitTags(markdown: string) {\n const placeholderToTag = new Map<string, string>();\n let nextPlaceholderIndex = 0;\n const preprocessedMarkdown = markdown.replace(/\\[([@#][^\\s[\\]]+)\\]/g, (_match, tagToken: string) => {\n const placeholder = createTagPlaceholder(nextPlaceholderIndex++);\n placeholderToTag.set(placeholder, tagToken);\n return placeholder;\n });\n\n return {\n markdown: preprocessedMarkdown,\n placeholderToTag\n };\n}\n\nfunction findTagPlaceholderAtCursor(\n text: string,\n cursor: number,\n placeholderToTag: Map<string, string>\n) {\n for (const [placeholder, tagToken] of placeholderToTag.entries()) {\n if (text.startsWith(placeholder, cursor)) {\n return {\n placeholder,\n tagToken\n };\n }\n }\n\n return null;\n}\n\nfunction restoreRemainingTagPlaceholders(\n blocks: BlockNote[],\n placeholderToTag: Map<string, string>\n): BlockNote[] {\n return mapBlocks(\n blocks,\n (content) => mapBlockContent(content, (inline) => {\n if (inline.type !== 'text' || typeof inline.text !== 'string') {\n return inline;\n }\n\n let text = inline.text;\n\n for (const [placeholder, tagToken] of placeholderToTag.entries()) {\n text = text.split(placeholder).join(`[${tagToken}]`);\n }\n\n return {\n ...inline,\n text\n };\n })\n );\n}\n\nfunction createTextInline(text: string, styles: Record<string, unknown> = {}): BlockNoteInline {\n return {\n type: 'text',\n text,\n styles\n };\n}\n\nfunction appendInline(target: BlockNoteInline[], inline: BlockNoteInline) {\n const previous = target.at(-1);\n\n if (\n previous?.type === 'text' &&\n inline.type === 'text' &&\n previous.text !== undefined &&\n inline.text !== undefined &&\n JSON.stringify(previous.styles ?? {}) === JSON.stringify(inline.styles ?? {})\n ) {\n previous.text += inline.text;\n return;\n }\n\n target.push(inline);\n}\n\nasync function restoreCustomInlineContent(\n blocks: BlockNote[],\n deps: MarkdownImportDeps,\n placeholderToTag: Map<string, string>\n): Promise<BlockNote[]> {\n const tagCache = new Map<string, Promise<{ id: string; tag: string }>>();\n const noteCache = new Map<string, Promise<Array<{ id: string; title: string }>>>();\n\n const getTag = (token: string) => {\n const normalizedToken = token.startsWith('#')\n ? `@${token.slice(1)}`\n : token;\n let existing = tagCache.get(normalizedToken);\n\n if (!existing) {\n existing = deps.ensureTag(normalizedToken.slice(1)).then((result) => ({\n id: 'tag' in result ? result.tag.id : result.id,\n tag: 'tag' in result ? result.tag.name : result.name\n }));\n tagCache.set(normalizedToken, existing);\n }\n\n return existing;\n };\n\n const getNotesByTitle = (title: string) => {\n let existing = noteCache.get(title);\n\n if (!existing) {\n existing = deps.findNotesByTitle(title);\n noteCache.set(title, existing);\n }\n\n return existing;\n };\n\n const restoreTextInline = async (inline: BlockNoteInline): Promise<BlockNoteInline[]> => {\n if (\n inline.type !== 'text' ||\n typeof inline.text !== 'string' ||\n !inline.text ||\n inline.styles?.code === true\n ) {\n return [inline];\n }\n\n const restored: BlockNoteInline[] = [];\n const styles = inline.styles ?? {};\n let cursor = 0;\n\n while (cursor < inline.text.length) {\n if (inline.text.startsWith('[[', cursor)) {\n const closeIndex = inline.text.indexOf(']]', cursor + 2);\n\n if (closeIndex !== -1) {\n const title = inline.text.slice(cursor + 2, closeIndex);\n const matchingNotes = await getNotesByTitle(title);\n\n if (matchingNotes.length === 1) {\n appendInline(restored, {\n type: 'reference',\n props: {\n id: matchingNotes[0].id,\n title: matchingNotes[0].title\n }\n });\n cursor = closeIndex + 2;\n continue;\n }\n }\n }\n\n const tagPlaceholderMatch = findTagPlaceholderAtCursor(inline.text, cursor, placeholderToTag);\n\n if (tagPlaceholderMatch) {\n const tag = await getTag(tagPlaceholderMatch.tagToken);\n appendInline(restored, {\n type: 'tag',\n props: tag\n });\n cursor += tagPlaceholderMatch.placeholder.length;\n continue;\n }\n\n let nextCursor = inline.text.length;\n\n const nextReferenceCursor = inline.text.indexOf('[[', cursor + 1);\n\n if (nextReferenceCursor !== -1) {\n nextCursor = Math.min(nextCursor, nextReferenceCursor);\n }\n\n for (const placeholder of placeholderToTag.keys()) {\n const nextPlaceholderCursor = inline.text.indexOf(placeholder, cursor + 1);\n\n if (nextPlaceholderCursor !== -1) {\n nextCursor = Math.min(nextCursor, nextPlaceholderCursor);\n }\n }\n\n appendInline(restored, createTextInline(inline.text.slice(cursor, nextCursor), styles));\n cursor = nextCursor;\n }\n\n return restored;\n };\n\n return mapBlocksAsync(\n blocks,\n (content) => mapBlockContentAsync(content, restoreTextInline)\n );\n}\n\nfunction collectTagIds(blocks: BlockNote[]): string[] {\n const tagIds = new Set<string>();\n\n const visit = (items: BlockNote[]) => {\n for (const block of items) {\n visitBlockContent(block.content, (inline) => {\n if (inline.type === 'tag' && typeof inline.props?.id === 'string') {\n tagIds.add(inline.props.id);\n }\n });\n\n if (block.children?.length) {\n visit(block.children);\n }\n }\n };\n\n visit(blocks);\n return [...tagIds];\n}\n\nlet editorInstance: ServerBlockNoteEditor | null = null;\n\nfunction getEditor(): ServerBlockNoteEditor {\n if (!editorInstance) {\n editorInstance = ServerBlockNoteEditor.create();\n }\n return editorInstance;\n}\n\nexport async function blocksToMarkdown(contentJson: string): Promise<string> {\n try {\n const blocks = JSON.parse(contentJson);\n const supportedBlocks = stripUnsupportedMarkdownBlocks(blocks);\n const placeholderToTag = new Map<string, string>();\n const processed = preprocessCustomInlineContent(\n supportedBlocks,\n placeholderToTag,\n { value: 0 }\n );\n const editor = getEditor();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const markdown = await editor.blocksToMarkdownLossy(processed as any);\n return restoreTagPlaceholdersInMarkdown(markdown, placeholderToTag);\n } catch {\n return '';\n }\n}\n\nexport async function markdownToBlocksJson(\n markdown: string,\n deps: MarkdownImportDeps = defaultMarkdownImportDeps\n): Promise<string> {\n const editor = getEditor();\n const preprocessedMarkdown = preprocessMarkdownExplicitTags(markdown);\n const blocks = await editor.tryParseMarkdownToBlocks(preprocessedMarkdown.markdown);\n const restoredBlocks = await restoreCustomInlineContent(\n blocks as BlockNote[],\n deps,\n preprocessedMarkdown.placeholderToTag\n );\n return JSON.stringify(\n restoreRemainingTagPlaceholders(restoredBlocks, preprocessedMarkdown.placeholderToTag)\n );\n}\n\nexport function extractTagIdsFromContentJson(contentJson: string): string[] {\n const blocks = JSON.parse(contentJson) as BlockNote[];\n return collectTagIds(blocks);\n}\n"],"mappings":"AAAA,SAAS,6BAA6B;AAEtC,OAAO,YAAY;AACnB,S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AACrC,SAAO,cAAc,MAAM;AAC/B;","names":[]}
@@ -0,0 +1,22 @@
1
+ const normalizeNoteTagNames = (tagNames) => {
2
+ return Array.from(
3
+ new Set(
4
+ tagNames.map((tagName) => tagName.trim()).filter(Boolean)
5
+ )
6
+ );
7
+ };
8
+ const buildNoteTagNamesWhere = (tagNames, mode) => {
9
+ const normalizedTagNames = normalizeNoteTagNames(tagNames);
10
+ if (normalizedTagNames.length === 0) {
11
+ return { id: -1 };
12
+ }
13
+ if (mode === "or") {
14
+ return { tags: { some: { name: { in: normalizedTagNames } } } };
15
+ }
16
+ return { AND: normalizedTagNames.map((tagName) => ({ tags: { some: { name: tagName } } })) };
17
+ };
18
+ export {
19
+ buildNoteTagNamesWhere,
20
+ normalizeNoteTagNames
21
+ };
22
+ //# sourceMappingURL=note-tag-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/modules/note-tag-filter.ts"],"sourcesContent":["import type { Prisma } from '~/models.js';\n\nexport type NoteTagMatchMode = 'and' | 'or';\n\nexport const normalizeNoteTagNames = (tagNames: string[]) => {\n return Array.from(\n new Set(\n tagNames\n .map((tagName) => tagName.trim())\n .filter(Boolean)\n )\n );\n};\n\nexport const buildNoteTagNamesWhere = (\n tagNames: string[],\n mode: NoteTagMatchMode\n): Prisma.NoteWhereInput => {\n const normalizedTagNames = normalizeNoteTagNames(tagNames);\n\n if (normalizedTagNames.length === 0) {\n return { id: -1 };\n }\n\n if (mode === 'or') {\n return { tags: { some: { name: { in: normalizedTagNames } } } };\n }\n\n return { AND: normalizedTagNames.map((tagName) => ({ tags: { some: { name: tagName } } })) };\n};\n"],"mappings":"AAIO,MAAM,wBAAwB,CAAC,aAAuB;AACzD,SAAO,MAAM;AAAA,IACT,IAAI;AAAA,MACA,SACK,IAAI,CAAC,YAAY,QAAQ,KAAK,CAAC,EAC/B,OAAO,OAAO;AAAA,IACvB;AAAA,EACJ;AACJ;AAEO,MAAM,yBAAyB,CAClC,UACA,SACwB;AACxB,QAAM,qBAAqB,sBAAsB,QAAQ;AAEzD,MAAI,mBAAmB,WAAW,GAAG;AACjC,WAAO,EAAE,IAAI,GAAG;AAAA,EACpB;AAEA,MAAI,SAAS,MAAM;AACf,WAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,mBAAmB,EAAE,EAAE,EAAE;AAAA,EAClE;AAEA,SAAO,EAAE,KAAK,mBAAmB,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,EAAE,EAAE,EAAE,EAAE;AAC/F;","names":[]}
@@ -15,6 +15,7 @@ import {
15
15
  restoreTrashedNoteById,
16
16
  trashNoteById
17
17
  } from "../../modules/note-trash.js";
18
+ import { buildNoteTagNamesWhere, normalizeNoteTagNames } from "../../modules/note-tag-filter.js";
18
19
  const noteType = gql`
19
20
  input PaginationInput {
20
21
  limit: Int!
@@ -39,6 +40,11 @@ const noteType = gql`
39
40
  full
40
41
  }
41
42
 
43
+ enum TagMatchMode {
44
+ and
45
+ or
46
+ }
47
+
42
48
  input NoteInput {
43
49
  title: String
44
50
  content: String
@@ -156,6 +162,7 @@ const noteQuery = gql`
156
162
  type Query {
157
163
  allNotes(searchFilter: SearchFilterInput, pagination: PaginationInput): Notes!
158
164
  tagNotes(searchFilter: SearchFilterInput, pagination: PaginationInput): Notes!
165
+ notesByTagNames(tagNames: [String!]!, mode: TagMatchMode!, pagination: PaginationInput): Notes!
159
166
  notesInDateRange(dateRange: DateRangeInput): [Note!]!
160
167
  pinnedNotes: [Note!]!
161
168
  imageNotes(src: String!): [Note!]!
@@ -292,6 +299,30 @@ const noteResolvers = {
292
299
  notes: $notes
293
300
  };
294
301
  },
302
+ notesByTagNames: async (_, {
303
+ tagNames,
304
+ mode,
305
+ pagination
306
+ }) => {
307
+ const normalizedTagNames = normalizeNoteTagNames(tagNames);
308
+ if (normalizedTagNames.length === 0) {
309
+ return {
310
+ totalCount: 0,
311
+ notes: []
312
+ };
313
+ }
314
+ const where = buildNoteTagNamesWhere(normalizedTagNames, mode);
315
+ const $notes = models.note.findMany({
316
+ orderBy: { updatedAt: "desc" },
317
+ where,
318
+ take: Number(pagination.limit),
319
+ skip: Number(pagination.offset)
320
+ });
321
+ return {
322
+ totalCount: models.note.count({ where }),
323
+ notes: $notes
324
+ };
325
+ },
295
326
  pinnedNotes: async () => models.note.findMany({
296
327
  orderBy: [
297
328
  { order: "asc" },