ocean-brain 0.3.4 → 0.4.1

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 (255) hide show
  1. package/dist/index.js +5 -0
  2. package/package.json +6 -5
  3. package/scripts/postinstall-prisma.mjs +3 -2
  4. package/server/client/dist/assets/Calendar-D4KkvcU8.js +25 -0
  5. package/server/client/dist/assets/Callout-CaSzc-1y.js +1 -0
  6. package/server/client/dist/assets/Graph-C8pBdJzV.js +1 -0
  7. package/server/client/dist/assets/{Image-ZxF459sC.js → Image-DlJ4MDo3.js} +1 -1
  8. package/server/client/dist/assets/{Image.es-BQfyKc2-.js → Image.es-C8g5NwNt.js} +1 -1
  9. package/server/client/dist/assets/Note-ODOESft3.js +21 -0
  10. package/server/client/dist/assets/Note-W4f6H9K0.css +1 -0
  11. package/server/client/dist/assets/Plus.es-Bkl1ZXE0.js +1 -0
  12. package/server/client/dist/assets/Reminders-FrTR9ny8.js +1 -0
  13. package/server/client/dist/assets/Search-BPf2LO1Y.js +1 -0
  14. package/server/client/dist/assets/{SurfaceCard-nZNf9lyE.js → SurfaceCard-WSk7zWeM.js} +1 -1
  15. package/server/client/dist/assets/Tag-uArdLjo1.js +1 -0
  16. package/server/client/dist/assets/TagNotes-DDvXHB9I.js +1 -0
  17. package/server/client/dist/assets/{Trash.es-BGoN5q9L.js → Trash.es-DumPfiUz.js} +1 -1
  18. package/server/client/dist/assets/ViewNotes-BVu9lEs-.js +1 -0
  19. package/server/client/dist/assets/Views-D4LGh30P.js +1 -0
  20. package/server/client/dist/assets/{image.api-0mMkElZk.js → image.api-D3Ei3fbf.js} +1 -1
  21. package/server/client/dist/assets/index-46ZUXbW5.js +232 -0
  22. package/server/client/dist/assets/index-C7YGbIuA.js +1 -0
  23. package/server/client/dist/assets/{index-DL7pUwq2.css → index-D2gRB1ig.css} +1 -1
  24. package/server/client/dist/assets/manage-image-DiuREdeE.js +1 -0
  25. package/server/client/dist/assets/manage-image-detail-D8Eorq3u.js +1 -0
  26. package/server/client/dist/assets/mcp-CvCGaYSz.js +1 -0
  27. package/server/client/dist/assets/{note-core-BCgMq5QA.js → note-core-GgFcksAF.js} +1 -1
  28. package/server/client/dist/assets/{note-vendor-BofYbzmZ.js → note-vendor-B0t5F04o.js} +5 -5
  29. package/server/client/dist/assets/{placeholder-i-uNe71U.js → placeholder-znZDfNAE.js} +2 -2
  30. package/server/client/dist/assets/trash-R0sww0ur.js +1 -0
  31. package/server/client/dist/assets/{useReminderMutate-tNMwwRnx.js → useReminderMutate-Bkj-oIm4.js} +2 -2
  32. package/server/client/dist/assets/view-dashboard-ClpF_qLM.js +90 -0
  33. package/server/client/dist/index.html +4 -4
  34. package/server/dist/app.js +8 -84
  35. package/server/dist/app.js.map +1 -1
  36. package/server/dist/features/auth/http/api.js +40 -0
  37. package/server/dist/features/auth/http/api.js.map +1 -0
  38. package/server/dist/features/auth/http/login-page.js +28 -0
  39. package/server/dist/features/auth/http/login-page.js.map +1 -0
  40. package/server/dist/features/auth/http/pages.js +50 -0
  41. package/server/dist/features/auth/http/pages.js.map +1 -0
  42. package/server/dist/features/auth/service.js +63 -0
  43. package/server/dist/features/auth/service.js.map +1 -0
  44. package/server/dist/features/cache/graphql/cache.field.resolver.js +5 -0
  45. package/server/dist/features/cache/graphql/cache.field.resolver.js.map +1 -0
  46. package/server/dist/features/cache/graphql/cache.mutation.resolver.js +49 -0
  47. package/server/dist/features/cache/graphql/cache.mutation.resolver.js.map +1 -0
  48. package/server/dist/features/cache/graphql/cache.query.resolver.js +21 -0
  49. package/server/dist/features/cache/graphql/cache.query.resolver.js.map +1 -0
  50. package/server/dist/features/cache/graphql/cache.resolver.js +12 -0
  51. package/server/dist/features/cache/graphql/cache.resolver.js.map +1 -0
  52. package/server/dist/features/cache/graphql/cache.type-defs.js +32 -0
  53. package/server/dist/features/cache/graphql/cache.type-defs.js.map +1 -0
  54. package/server/dist/features/cache/graphql/index.js +21 -0
  55. package/server/dist/features/cache/graphql/index.js.map +1 -0
  56. package/server/dist/features/image/graphql/image.field.resolver.js +14 -0
  57. package/server/dist/features/image/graphql/image.field.resolver.js.map +1 -0
  58. package/server/dist/features/image/graphql/image.mutation.resolver.js +21 -0
  59. package/server/dist/features/image/graphql/image.mutation.resolver.js.map +1 -0
  60. package/server/dist/features/image/graphql/image.query.resolver.js +40 -0
  61. package/server/dist/features/image/graphql/image.query.resolver.js.map +1 -0
  62. package/server/dist/features/image/graphql/image.resolver.js +12 -0
  63. package/server/dist/features/image/graphql/image.resolver.js.map +1 -0
  64. package/server/dist/features/image/graphql/image.type-defs.js +31 -0
  65. package/server/dist/features/image/graphql/image.type-defs.js.map +1 -0
  66. package/server/dist/features/image/graphql/index.js +16 -0
  67. package/server/dist/features/image/graphql/index.js.map +1 -0
  68. package/server/dist/features/image/http/upload.js +48 -0
  69. package/server/dist/features/image/http/upload.js.map +1 -0
  70. package/server/dist/features/image/services/delete.js +52 -0
  71. package/server/dist/features/image/services/delete.js.map +1 -0
  72. package/server/dist/{modules/remote-image.js → features/image/services/remote-fetch.js} +1 -1
  73. package/server/dist/features/image/services/remote-fetch.js.map +1 -0
  74. package/server/dist/{modules/image-upload.js → features/image/services/upload.js} +4 -8
  75. package/server/dist/features/image/services/upload.js.map +1 -0
  76. package/server/dist/{views/mcp-admin.js → features/mcp-admin/http/handlers.js} +3 -3
  77. package/server/dist/features/mcp-admin/http/handlers.js.map +1 -0
  78. package/server/dist/{modules/mcp-admin.js → features/mcp-admin/service.js} +3 -3
  79. package/server/dist/features/mcp-admin/service.js.map +1 -0
  80. package/server/dist/features/note/graphql/index.js +8 -0
  81. package/server/dist/features/note/graphql/index.js.map +1 -0
  82. package/server/dist/features/note/graphql/note.field.resolver.js +12 -0
  83. package/server/dist/features/note/graphql/note.field.resolver.js.map +1 -0
  84. package/server/dist/features/note/graphql/note.graphql.shared.js +23 -0
  85. package/server/dist/features/note/graphql/note.graphql.shared.js.map +1 -0
  86. package/server/dist/features/note/graphql/note.mutation.resolver.js +140 -0
  87. package/server/dist/features/note/graphql/note.mutation.resolver.js.map +1 -0
  88. package/server/dist/features/note/graphql/note.query.resolver.js +385 -0
  89. package/server/dist/features/note/graphql/note.query.resolver.js.map +1 -0
  90. package/server/dist/features/note/graphql/note.resolver.js +14 -0
  91. package/server/dist/features/note/graphql/note.resolver.js.map +1 -0
  92. package/server/dist/features/note/graphql/note.type-defs.js +187 -0
  93. package/server/dist/features/note/graphql/note.type-defs.js.map +1 -0
  94. package/server/dist/{views/note.js → features/note/http/mcp.js} +27 -15
  95. package/server/dist/features/note/http/mcp.js.map +1 -0
  96. package/server/dist/{modules/note-authoring.js → features/note/services/authoring.js} +25 -7
  97. package/server/dist/features/note/services/authoring.js.map +1 -0
  98. package/server/dist/{modules/note-cleanup.js → features/note/services/cleanup.js} +14 -23
  99. package/server/dist/features/note/services/cleanup.js.map +1 -0
  100. package/server/dist/features/note/services/search-backfill.js +84 -0
  101. package/server/dist/features/note/services/search-backfill.js.map +1 -0
  102. package/server/dist/features/note/services/search.js +197 -0
  103. package/server/dist/features/note/services/search.js.map +1 -0
  104. package/server/dist/{modules/note-snapshot.js → features/note/services/snapshot.js} +51 -49
  105. package/server/dist/features/note/services/snapshot.js.map +1 -0
  106. package/server/dist/{modules/note-tag-filter.js → features/note/services/tag-filter.js} +2 -6
  107. package/server/dist/features/note/services/tag-filter.js.map +1 -0
  108. package/server/dist/{modules/note-trash.js → features/note/services/trash.js} +64 -34
  109. package/server/dist/features/note/services/trash.js.map +1 -0
  110. package/server/dist/features/placeholder/graphql/index.js +27 -0
  111. package/server/dist/features/placeholder/graphql/index.js.map +1 -0
  112. package/server/dist/features/placeholder/graphql/placeholder.field.resolver.js +5 -0
  113. package/server/dist/features/placeholder/graphql/placeholder.field.resolver.js.map +1 -0
  114. package/server/dist/features/placeholder/graphql/placeholder.mutation.resolver.js +72 -0
  115. package/server/dist/features/placeholder/graphql/placeholder.mutation.resolver.js.map +1 -0
  116. package/server/dist/features/placeholder/graphql/placeholder.query.resolver.js +36 -0
  117. package/server/dist/features/placeholder/graphql/placeholder.query.resolver.js.map +1 -0
  118. package/server/dist/features/placeholder/graphql/placeholder.resolver.js +12 -0
  119. package/server/dist/features/placeholder/graphql/placeholder.resolver.js.map +1 -0
  120. package/server/dist/features/placeholder/graphql/placeholder.type-defs.js +50 -0
  121. package/server/dist/features/placeholder/graphql/placeholder.type-defs.js.map +1 -0
  122. package/server/dist/features/reminder/graphql/index.js +27 -0
  123. package/server/dist/features/reminder/graphql/index.js.map +1 -0
  124. package/server/dist/features/reminder/graphql/reminder.field.resolver.js +10 -0
  125. package/server/dist/features/reminder/graphql/reminder.field.resolver.js.map +1 -0
  126. package/server/dist/features/reminder/graphql/reminder.mutation.resolver.js +59 -0
  127. package/server/dist/features/reminder/graphql/reminder.mutation.resolver.js.map +1 -0
  128. package/server/dist/features/reminder/graphql/reminder.query.resolver.js +79 -0
  129. package/server/dist/features/reminder/graphql/reminder.query.resolver.js.map +1 -0
  130. package/server/dist/features/reminder/graphql/reminder.resolver.js +12 -0
  131. package/server/dist/features/reminder/graphql/reminder.resolver.js.map +1 -0
  132. package/server/dist/features/reminder/graphql/reminder.type-defs.js +51 -0
  133. package/server/dist/features/reminder/graphql/reminder.type-defs.js.map +1 -0
  134. package/server/dist/features/tag/graphql/index.js +14 -0
  135. package/server/dist/features/tag/graphql/index.js.map +1 -0
  136. package/server/dist/features/tag/graphql/tag.field.resolver.js +10 -0
  137. package/server/dist/features/tag/graphql/tag.field.resolver.js.map +1 -0
  138. package/server/dist/features/tag/graphql/tag.mutation.resolver.js +15 -0
  139. package/server/dist/features/tag/graphql/tag.mutation.resolver.js.map +1 -0
  140. package/server/dist/features/tag/graphql/tag.query.resolver.js +26 -0
  141. package/server/dist/features/tag/graphql/tag.query.resolver.js.map +1 -0
  142. package/server/dist/features/tag/graphql/tag.resolver.js +12 -0
  143. package/server/dist/features/tag/graphql/tag.resolver.js.map +1 -0
  144. package/server/dist/features/tag/graphql/tag.type-defs.js +46 -0
  145. package/server/dist/features/tag/graphql/tag.type-defs.js.map +1 -0
  146. package/server/dist/{views/tag.js → features/tag/http/mcp.js} +3 -3
  147. package/server/dist/features/tag/http/mcp.js.map +1 -0
  148. package/server/dist/{modules/tag-organization.js → features/tag/services/organization.js} +38 -8
  149. package/server/dist/features/tag/services/organization.js.map +1 -0
  150. package/server/dist/features/view/graphql/index.js +11 -0
  151. package/server/dist/features/view/graphql/index.js.map +1 -0
  152. package/server/dist/features/view/graphql/view.mutation.resolver.js +53 -0
  153. package/server/dist/features/view/graphql/view.mutation.resolver.js.map +1 -0
  154. package/server/dist/features/view/graphql/view.query.resolver.js +29 -0
  155. package/server/dist/features/view/graphql/view.query.resolver.js.map +1 -0
  156. package/server/dist/features/view/graphql/view.resolver.js +10 -0
  157. package/server/dist/features/view/graphql/view.resolver.js.map +1 -0
  158. package/server/dist/features/view/graphql/view.type-defs.js +63 -0
  159. package/server/dist/features/view/graphql/view.type-defs.js.map +1 -0
  160. package/server/dist/features/view/services/workspace.js +432 -0
  161. package/server/dist/features/view/services/workspace.js.map +1 -0
  162. package/server/dist/main.js +14 -0
  163. package/server/dist/main.js.map +1 -1
  164. package/server/dist/modules/auth-guard.js +16 -21
  165. package/server/dist/modules/auth-guard.js.map +1 -1
  166. package/server/dist/modules/auth-mode.js +16 -41
  167. package/server/dist/modules/auth-mode.js.map +1 -1
  168. package/server/dist/modules/blocknote.js +8 -17
  169. package/server/dist/modules/blocknote.js.map +1 -1
  170. package/server/dist/modules/data-maintenance.js +75 -0
  171. package/server/dist/modules/data-maintenance.js.map +1 -0
  172. package/server/dist/modules/error-handler.js.map +1 -1
  173. package/server/dist/modules/logger.js +5 -23
  174. package/server/dist/modules/logger.js.map +1 -1
  175. package/server/dist/modules/mcp-auth.js +4 -5
  176. package/server/dist/modules/mcp-auth.js.map +1 -1
  177. package/server/dist/modules/mcp-token.js.map +1 -1
  178. package/server/dist/modules/prisma-runtime.js +2 -7
  179. package/server/dist/modules/prisma-runtime.js.map +1 -1
  180. package/server/dist/modules/recovery-retention.js +1 -1
  181. package/server/dist/modules/recovery-retention.js.map +1 -1
  182. package/server/dist/modules/server-events-handler.js +34 -0
  183. package/server/dist/modules/server-events-handler.js.map +1 -0
  184. package/server/dist/modules/server-events.js +32 -0
  185. package/server/dist/modules/server-events.js.map +1 -0
  186. package/server/dist/modules/use-async.js.map +1 -1
  187. package/server/dist/paths.js.map +1 -1
  188. package/server/dist/routes/api.js +34 -0
  189. package/server/dist/routes/api.js.map +1 -0
  190. package/server/dist/routes/auth-pages.js +11 -0
  191. package/server/dist/routes/auth-pages.js.map +1 -0
  192. package/server/dist/routes/client.js +27 -0
  193. package/server/dist/routes/client.js.map +1 -0
  194. package/server/dist/routes/graphql.js +33 -0
  195. package/server/dist/routes/graphql.js.map +1 -0
  196. package/server/dist/routes/index.js +11 -0
  197. package/server/dist/routes/index.js.map +1 -0
  198. package/server/dist/routes/mcp.js +30 -0
  199. package/server/dist/routes/mcp.js.map +1 -0
  200. package/server/dist/schema/index.js +11 -8
  201. package/server/dist/schema/index.js.map +1 -1
  202. package/server/dist/types/index.js.map +1 -1
  203. package/server/prisma/migrations/20260413143000_0014_tag_name_unique/migration.sql +32 -0
  204. package/server/prisma/migrations/20260414143000_0015_note_searchable_text/migration.sql +5 -0
  205. package/server/prisma/migrations/20260416090000_0016_view_workspace/migration.sql +50 -0
  206. package/server/prisma/schema.prisma +66 -12
  207. package/server/client/dist/assets/Calendar-Kjy1PX6L.js +0 -25
  208. package/server/client/dist/assets/Graph-Bl5K2qUw.js +0 -1
  209. package/server/client/dist/assets/ModalActionRow-DyOb58KJ.js +0 -1
  210. package/server/client/dist/assets/Note-BfGma2Qc.css +0 -1
  211. package/server/client/dist/assets/Note-DN_ko2M3.js +0 -1
  212. package/server/client/dist/assets/Reminders-BK-Uv9Ps.js +0 -1
  213. package/server/client/dist/assets/Search-ClHeWvmI.js +0 -1
  214. package/server/client/dist/assets/Tag-Dph4V_kl.js +0 -1
  215. package/server/client/dist/assets/TagNotes-CxP5qHZj.js +0 -1
  216. package/server/client/dist/assets/index-6lIw6jYW.js +0 -1
  217. package/server/client/dist/assets/index-Ba2XPRI8.js +0 -205
  218. package/server/client/dist/assets/manage-image-Br_kKxbb.js +0 -1
  219. package/server/client/dist/assets/manage-image-detail-9DzqbiqI.js +0 -1
  220. package/server/client/dist/assets/mcp-C_So91eX.js +0 -1
  221. package/server/client/dist/assets/trash-Cg3nJ1m5.js +0 -1
  222. package/server/dist/modules/auth.js +0 -25
  223. package/server/dist/modules/auth.js.map +0 -1
  224. package/server/dist/modules/image-upload.js.map +0 -1
  225. package/server/dist/modules/mcp-admin.js.map +0 -1
  226. package/server/dist/modules/note-authoring.js.map +0 -1
  227. package/server/dist/modules/note-cleanup.js.map +0 -1
  228. package/server/dist/modules/note-snapshot.js.map +0 -1
  229. package/server/dist/modules/note-tag-filter.js.map +0 -1
  230. package/server/dist/modules/note-trash.js.map +0 -1
  231. package/server/dist/modules/remote-image.js.map +0 -1
  232. package/server/dist/modules/tag-organization.js.map +0 -1
  233. package/server/dist/schema/cache/index.js +0 -58
  234. package/server/dist/schema/cache/index.js.map +0 -1
  235. package/server/dist/schema/image/index.js +0 -88
  236. package/server/dist/schema/image/index.js.map +0 -1
  237. package/server/dist/schema/note/index.js +0 -582
  238. package/server/dist/schema/note/index.js.map +0 -1
  239. package/server/dist/schema/placeholder/index.js +0 -105
  240. package/server/dist/schema/placeholder/index.js.map +0 -1
  241. package/server/dist/schema/reminder/index.js +0 -161
  242. package/server/dist/schema/reminder/index.js.map +0 -1
  243. package/server/dist/schema/tag/index.js +0 -81
  244. package/server/dist/schema/tag/index.js.map +0 -1
  245. package/server/dist/urls.js +0 -9
  246. package/server/dist/urls.js.map +0 -1
  247. package/server/dist/views/auth.js +0 -305
  248. package/server/dist/views/auth.js.map +0 -1
  249. package/server/dist/views/image.js +0 -44
  250. package/server/dist/views/image.js.map +0 -1
  251. package/server/dist/views/index.js +0 -6
  252. package/server/dist/views/index.js.map +0 -1
  253. package/server/dist/views/mcp-admin.js.map +0 -1
  254. package/server/dist/views/note.js.map +0 -1
  255. package/server/dist/views/tag.js.map +0 -1
@@ -0,0 +1 @@
1
+ import{j as e}from"./note-vendor-B0t5F04o.js";import{a5 as v,q as x,v as w,w as E,aa as b,af as A,$ as T,P as o,F as _,L as G,aH as M,T as R,B as S,a0 as P,i as l,j as k,ax as q}from"./index-46ZUXbW5.js";import{f as D,d as L}from"./image.api-D3Ei3fbf.js";import"./graph-vendor-CUxe67Lr.js";import{I as C}from"./Image-DlJ4MDo3.js";import{S as f}from"./SurfaceCard-WSk7zWeM.js";import{c as F,n as H}from"./Trash.es-DumPfiUz.js";import"./note-core-GgFcksAF.js";const K=r=>{const{data:d}=v({queryKey:x.images.list(r.searchParams),async queryFn(){const i=await D({offset:r.searchParams.offset,limit:r.searchParams.limit});if(i.type==="error")throw i;return i.allImages}});return r.render(d)},Q=240,W=20,B=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:Q,gap:W,rows:B}),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(K,{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(C,{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(F,{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(H,{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};
@@ -0,0 +1 @@
1
+ import{j as e}from"./note-vendor-B0t5F04o.js";import{p as F,T as r,t as k,L as p,N as R,ac as _,aI as Z,ax as E,f as q,$ as B,j as L,aH as G,v as H,w as z,a5 as b,q as x,aJ as K,af as v,aK as O,aL as P,B as w,i as l,W as Q}from"./index-46ZUXbW5.js";import{a as U,d as $}from"./image.api-D3Ei3fbf.js";import{a as t}from"./graph-vendor-CUxe67Lr.js";import{I as W}from"./Image-DlJ4MDo3.js";import{S as g}from"./SurfaceCard-WSk7zWeM.js";import{c as J,n as V}from"./Trash.es-DumPfiUz.js";import{I as X}from"./Image.es-C8g5NwNt.js";import"./note-core-GgFcksAF.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=k(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=L(G),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=H(),i=Q(),u=I.useNavigate(),d=z(),{data:o}=b({queryKey:x.images.detail(a),queryFn:async()=>{const s=await U(a);if(s.type==="error")throw s;return s.image}}),{data:m}=b({queryKey:x.images.notes(a),queryFn:async()=>{const s=await K(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 $(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 O("heroBanner",o.url);if(s.type==="error")throw s},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"))}}),D=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(W,{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(J,{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(P,{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:D,children:[e.jsx(V,{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};
@@ -0,0 +1 @@
1
+ import{j as e}from"./note-vendor-B0t5F04o.js";import{aA as r,w as Q,u as R,af as p,P as E,T as t,aB as G,B as M,l as w,m as J,I as K,n as O,o as T,W as U}from"./index-46ZUXbW5.js";import{a as h}from"./graph-vendor-CUxe67Lr.js";import{S as x}from"./SurfaceCard-WSk7zWeM.js";import"./note-core-GgFcksAF.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},W=async()=>{const{data:s}=await r.post("/api/mcp-admin/token/revoke");return s},o=["mcp-admin","status"],H=s=>JSON.stringify({mcpServers:{"ocean-brain":{command:"npx",args:["-y","ocean-brain","mcp","--server",s,"--token-file","/path/to/token.txt"]}}},null,2),X=s=>JSON.stringify({mcpServers:{"ocean-brain":{command:"npx",args:["-y","ocean-brain","mcp","--server",s,"--token","your-token-here"]}}},null,2),se=()=>{const s=U(),n=Q(),[c,S]=h.useState(()=>window.location.origin),[v,g]=h.useState(""),[k,P]=h.useState("token-file"),{data:y,isLoading:A}=R({queryKey:o,queryFn:D}),b=p({mutationFn:z,onSuccess:a=>{n.setQueryData(o,a),s(a.enabled?"MCP access enabled.":"MCP access disabled.")}}),f=p({mutationFn:V,onSuccess:async({token:a})=>{g(a),s("A new MCP token has been issued."),await n.invalidateQueries({queryKey:o})}}),j=p({mutationFn:W,onSuccess:a=>{g(""),n.setQueryData(o,a),s("The active MCP token has been revoked.")}}),l=y?.enabled??!1,d=y?.hasActiveToken??!1,I=!A&&!b.isPending,i="space-y-1",N="space-y-4.5",F="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",B="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:H(c)}:{title:"Inline token",description:"Useful for quick local testing.",snippet:X(c)};return e.jsx(E,{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:F,children:[e.jsx(t,{as:"span",variant:"meta",weight:"medium",tone:"secondary",children:l?"Enabled":"Disabled"}),e.jsx(G,{"aria-label":"Allow MCP access",checked:l,disabled:!I,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:()=>f.mutate(void 0),isLoading:f.isPending,children:"Rotate token"}),e.jsx(M,{variant:"soft-danger",onClick:()=>j.mutate(),isLoading:j.isPending,disabled:!d,children:"Revoke token"})]}),v&&e.jsxs("div",{className:"space-y-2.5",children:[e.jsx(w,{htmlFor:"issued-mcp-token",className:C,children:"Issued token"}),e.jsx(J,{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(w,{htmlFor:"mcp-server-url",className:C,children:"Server URL"}),e.jsx(K,{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(T,{value:"token-file",children:"Token file"}),e.jsx(T,{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:B,children:m.snippet})]})]})]})})]})})};export{se as default};
@@ -175,4 +175,4 @@ ${n.toString()}`)};class jM{constructor(e){this.patterns=[],this.$state=e}if(e,n
175
175
  \f\r "&'<=>\``.split("")]],single:[["&'".split(""),"\"&'`".split("")],["\0&'".split(""),"\0\"&'`".split("")]],double:[['"&'.split(""),"\"&'`".split("")],['\0"&'.split(""),"\0\"&'`".split("")]]};function Cz(t,e,n,r){const i=r.schema,s=i.space==="svg"?!1:r.settings.omitOptionalTags;let o=i.space==="svg"?r.settings.closeEmptyElements:r.settings.voids.includes(t.tagName.toLowerCase());const a=[];let l;i.space==="html"&&t.tagName==="svg"&&(r.schema=ma);const c=Sz(r,t.properties),u=r.all(i.space==="html"&&t.tagName==="template"?t.content:t);return r.schema=i,u&&(o=!1),(c||!s||!gz(t,e,n))&&(a.push("<",t.tagName,c?" "+c:""),o&&(i.space==="svg"||r.settings.closeSelfClosing)&&(l=c.charAt(c.length-1),(!r.settings.tightSelfClosing||l==="/"||l&&l!=='"'&&l!=="'")&&a.push(" "),a.push("/")),a.push(">")),a.push(u),!o&&(!s||!gm(t,e,n))&&a.push("</"+t.tagName+">"),a.join("")}function Sz(t,e){const n=[];let r=-1,i;if(e){for(i in e)if(e[i]!==null&&e[i]!==void 0){const s=wz(t,i,e[i]);s&&n.push(s)}}for(;++r<n.length;){const s=t.settings.tightAttributes?n[r].charAt(n[r].length-1):void 0;r!==n.length-1&&s!=='"'&&s!=="'"&&(n[r]+=" ")}return n.join("")}function wz(t,e,n){const r=Bp(t.schema,e),i=t.settings.allowParseErrors&&t.schema.space==="html"?0:1,s=t.settings.allowDangerousCharacters?0:1;let o=t.quote,a;if(r.overloadedBoolean&&(n===r.attribute||n==="")?n=!0:(r.boolean||r.overloadedBoolean)&&(typeof n!="string"||n===r.attribute||n==="")&&(n=!!n),n==null||n===!1||typeof n=="number"&&Number.isNaN(n))return"";const l=us(r.attribute,Object.assign({},t.settings.characterReferences,{subset:el.name[i][s]}));return n===!0||(n=Array.isArray(n)?(r.commaSeparated?UR:zR)(n,{padLeft:!t.settings.tightCommaSeparatedLists}):String(n),t.settings.collapseEmptyAttributes&&!n)?l:(t.settings.preferUnquoted&&(a=us(n,Object.assign({},t.settings.characterReferences,{attribute:!0,subset:el.unquoted[i][s]}))),a!==n&&(t.settings.quoteSmart&&ic(n,o)>ic(n,t.alternative)&&(o=t.alternative),a=o+us(n,Object.assign({},t.settings.characterReferences,{subset:(o==="'"?el.single:el.double)[i][s],attribute:!0}))+o),l+(a&&"="+a))}const xz=["<","&"];function Nw(t,e,n,r){return n&&n.type==="element"&&(n.tagName==="script"||n.tagName==="style")?t.value:us(t.value,Object.assign({},r.settings.characterReferences,{subset:xz}))}function Az(t,e,n,r){return r.settings.allowDangerousHtml?t.value:Nw(t,e,n,r)}function _z(t,e,n,r){return r.all(t)}const Nz=pS("type",{invalid:Iz,unknown:Oz,handlers:{comment:ez,doctype:tz,element:Cz,raw:Az,root:_z,text:Nw}});function Iz(t){throw new Error("Expected node, not `"+t+"`")}function Oz(t){const e=t;throw new Error("Cannot compile unknown node `"+e.type+"`")}const Mz={},Dz={},vz=[];function Lz(t,e){const n=e||Mz,r=n.quote||'"',i=r==='"'?"'":'"';if(r!=='"'&&r!=="'")throw new Error("Invalid quote `"+r+"`, expected `'` or `\"`");return{one:Rz,all:Pz,settings:{omitOptionalTags:n.omitOptionalTags||!1,allowParseErrors:n.allowParseErrors||!1,allowDangerousCharacters:n.allowDangerousCharacters||!1,quoteSmart:n.quoteSmart||!1,preferUnquoted:n.preferUnquoted||!1,tightAttributes:n.tightAttributes||!1,upperDoctype:n.upperDoctype||!1,tightDoctype:n.tightDoctype||!1,bogusComments:n.bogusComments||!1,tightCommaSeparatedLists:n.tightCommaSeparatedLists||!1,tightSelfClosing:n.tightSelfClosing||!1,collapseEmptyAttributes:n.collapseEmptyAttributes||!1,allowDangerousHtml:n.allowDangerousHtml||!1,voids:n.voids||L$,characterReferences:n.characterReferences||Dz,closeSelfClosing:n.closeSelfClosing||!1,closeEmptyElements:n.closeEmptyElements||!1},schema:n.space==="svg"?ma:pu,quote:r,alternative:i}.one(Array.isArray(t)?{type:"root",children:t}:t,void 0,void 0)}function Rz(t,e,n){return Nz(t,e,n,this)}function Pz(t){const e=[],n=t&&t.children||vz;let r=-1;for(;++r<n.length;)e[r]=this.one(n[r],r,t);return e.join("")}function Bz(t){const e=this,n={...e.data("settings"),...t};e.compiler=r;function r(i){return Lz(i,n)}}var Fz=Object.defineProperty,Hz=(t,e,n)=>e in t?Fz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,he=(t,e,n)=>Hz(t,typeof e!="symbol"?e+"":e,n);function Uj(t,e){const n=[{tag:`[data-inline-content-type="${t.type}"]`,contentElement:r=>{const i=r;return i.matches("[data-editable]")?i:i.querySelector("[data-editable]")||i}}];return e&&n.push({tag:"*",getAttrs(r){if(typeof r=="string")return!1;const i=e?.(r);return i===void 0?!1:i}}),n}function Uz(t,e,n,r="before"){const i=typeof n=="string"?n:n.id,s=He(t),o=e.map(c=>Ii(c,s)),a=Vt(i,t.doc);if(!a)throw new Error(`Block with ID ${i} not found`);let l=a.posBeforeNode;return r==="after"&&(l+=a.node.nodeSize),t.step(new ze(l,l,new F(M.from(o),0,0))),o.map(c=>ve(c,s))}function df(t){if(!t||t.type.name!=="column")throw new Error("Invalid columnPos: does not point to column node.");const e=t.firstChild;if(!e)throw new Error("Invalid column: does not have child node.");const n=e.firstChild;if(!n)throw new Error("Invalid blockContainer: does not have child node.");return t.childCount===1&&e.childCount===1&&n.type.name==="paragraph"&&n.content.content.length===0}function $z(t,e){const n=t.doc.resolve(e),r=n.nodeAfter;if(!r||r.type.name!=="columnList")throw new Error("Invalid columnListPos: does not point to columnList node.");for(let i=r.childCount-1;i>=0;i--){const s=t.doc.resolve(n.pos+1).posAtIndex(i),o=t.doc.resolve(s).nodeAfter;if(!o||o.type.name!=="column")throw new Error("Invalid columnPos: does not point to column node.");df(o)&&t.delete(s,s+o.nodeSize)}}function hf(t,e){$z(t,e);const n=t.doc.resolve(e).nodeAfter;if(!n||n.type.name!=="columnList")throw new Error("Invalid columnListPos: does not point to columnList node.");if(n.childCount>2)return;if(n.childCount<2)throw new Error("Invalid columnList: contains fewer than two children.");const r=e+1,i=t.doc.resolve(r).nodeAfter,s=e+n.nodeSize-1,o=t.doc.resolve(s).nodeBefore;if(!i||!o)throw new Error("Invalid columnList: does not contain children.");const a=df(i),l=df(o);if(a&&l){t.delete(e,e+n.nodeSize);return}if(a){t.step(new Fe(e,e+n.nodeSize,s-o.nodeSize+1,s-1,F.empty,0,!1));return}if(l){t.step(new Fe(e,e+n.nodeSize,r+1,r+i.nodeSize-1,F.empty,0,!1));return}}function S1(t,e,n){const r=He(t),i=n.map(u=>Ii(u,r)),s=new Set(e.map(u=>typeof u=="string"?u:u.id)),o=[],a=new Set,l=typeof e[0]=="string"?e[0]:e[0].id;let c=0;if(t.doc.descendants((u,d)=>{if(s.size===0)return!1;if(!u.type.isInGroup("bnBlock")||!s.has(u.attrs.id))return!0;if(o.push(ve(u,r)),s.delete(u.attrs.id),n.length>0&&u.attrs.id===l){const g=t.doc.nodeSize;t.insert(d,i);const b=t.doc.nodeSize;c+=g-b}const h=t.doc.nodeSize,f=t.doc.resolve(d-c);f.node().type.name==="column"?a.add(f.before(-1)):f.node().type.name==="columnList"&&a.add(f.before()),f.node().type.name==="blockGroup"&&f.node(f.depth-1).type.name!=="doc"&&f.node().childCount===1?t.delete(f.before(),f.after()):t.delete(d-c,d-c+u.nodeSize);const p=t.doc.nodeSize;return c+=h-p,!1}),s.size>0){const u=[...s].join(`
176
176
  `);throw Error("Blocks with the following IDs could not be found in the editor: "+u)}return a.forEach(u=>hf(t,u)),{insertedBlocks:i.map(u=>ve(u,r)),removedBlocks:o}}function zz(t,e,n,r,i){let s;if(e)if(typeof e=="string")s=bn([e],t.pmSchema,r);else if(Array.isArray(e))s=bn(e,t.pmSchema,r);else if(e.type==="tableContent")s=Jc(e,t.pmSchema);else throw new Pn(e.type);else throw new Error("blockContent is required");const o=(i?.document??document).createDocumentFragment();for(const a of s)if(a.type.name!=="text"&&t.schema.inlineContentSchema[a.type.name]){const l=t.schema.inlineContentSpecs[a.type.name].implementation;if(l){const c=Qf(a,t.schema.inlineContentSchema,t.schema.styleSchema),u=l.render.call({renderType:"dom",props:void 0},c,()=>{},t);if(u){if(o.appendChild(u.dom),u.contentDOM){const d=n.serializeFragment(a.content,i);u.contentDOM.dataset.editable="",u.contentDOM.appendChild(d)}continue}}}else if(a.type.name==="text"){let l=document.createTextNode(a.textContent);for(const c of a.marks.toReversed())if(c.type.name in t.schema.styleSpecs){const u=t.schema.styleSpecs[c.type.name].implementation.render(c.attrs.stringValue,t);u.contentDOM.appendChild(l),l=u.dom}else{const u=c.type.spec.toDOM(c,!0),d=zt.renderSpec(document,u);d.contentDOM.appendChild(l),l=d.dom}o.appendChild(l)}else{const l=n.serializeFragment(M.from([a]),i);o.appendChild(l)}return o}function Vz(t,e,n,r){var i,s,o,a,l;const c=t.pmSchema.nodes.blockContainer,u=e.props||{};for(const[p,g]of Object.entries(t.schema.blockSchema[e.type].propSchema))!(p in u)&&g.default!==void 0&&(u[p]=g.default);const d=e.children||[],h=t.blockImplementations[e.type].implementation.render.call({renderType:"dom",props:void 0},{...e,props:u,children:d},t);if(h.contentDOM&&e.content){const p=zz(t,e.content,n,e.type,r);h.contentDOM.appendChild(p)}if(t.pmSchema.nodes[e.type].isInGroup("bnBlock")){if(e.children&&e.children.length>0){const p=Iw(t,e.children,n,r);(i=h.contentDOM)==null||i.append(p)}return h.dom}const f=(o=(s=c.spec)==null?void 0:s.toDOM)==null?void 0:o.call(s,c.create({id:e.id,...u}));return(a=f.contentDOM)==null||a.appendChild(h.dom),e.children&&e.children.length>0&&((l=f.contentDOM)==null||l.appendChild(Ow(t,e.children,n,r))),f.dom}function Iw(t,e,n,r){const i=(r?.document??document).createDocumentFragment();for(const s of e){const o=Vz(t,s,n,r);i.appendChild(o)}return i}const Ow=(t,e,n,r)=>{var i;const s=t.pmSchema.nodes.blockGroup,o=s.spec.toDOM(s.create({})),a=Iw(t,e,n,r);return(i=o.contentDOM)==null||i.appendChild(a),o.dom},jz=t=>(t.querySelectorAll('[data-content-type="numberedListItem"]').forEach(e=>{var n,r;const i=(r=(n=e.closest(".bn-block-outer"))==null?void 0:n.previousElementSibling)==null?void 0:r.querySelector('[data-content-type="numberedListItem"]');if(!i)e.setAttribute("data-index",e.getAttribute("data-start")||"1");else{const s=i.getAttribute("data-index");e.setAttribute("data-index",(parseInt(s||"0")+1).toString())}}),t),qz=t=>(t.querySelectorAll('[data-content-type="checkListItem"] input').forEach(e=>{e.disabled=!0}),t),Wz=t=>(t.querySelectorAll('.bn-toggle-wrapper[data-show-children="false"]').forEach(e=>{e.setAttribute("data-show-children","true")}),t),Yz=t=>(t.querySelectorAll('[data-content-type="table"] table').forEach(e=>{e.setAttribute("style",`--default-cell-min-width: ${Lp}px;`),e.setAttribute("data-show-children","true")}),t),Kz=t=>(t.querySelectorAll('[data-content-type="table"] table').forEach(e=>{var n;const r=document.createElement("div");r.className="tableWrapper";const i=document.createElement("div");i.className="tableWrapper-inner",r.appendChild(i),(n=e.parentElement)==null||n.appendChild(r),r.appendChild(e)}),t),Gz=t=>(t.querySelectorAll(".bn-inline-content:empty").forEach(e=>{const n=document.createElement("span");n.className="ProseMirror-trailingBreak",n.setAttribute("style","display: inline-block;"),e.appendChild(n)}),t),Qz=(t,e)=>{const n=zt.fromSchema(t),r=[jz,qz,Wz,Yz,Kz,Gz];return{serializeBlocks:(i,s)=>{let o=Ow(e,i,n,s);for(const a of r)o=a(o);return o.outerHTML}}};function Jz(t){return t.transact(e=>{const n=Rr(e.doc,e.selection.anchor);if(e.selection instanceof be)return{type:"cell",anchorBlockId:n.node.attrs.id,anchorCellOffset:e.selection.$anchorCell.pos-n.posBeforeNode,headCellOffset:e.selection.$headCell.pos-n.posBeforeNode};if(e.selection instanceof W)return{type:"node",anchorBlockId:n.node.attrs.id};{const r=Rr(e.doc,e.selection.head);return{type:"text",anchorBlockId:n.node.attrs.id,headBlockId:r.node.attrs.id,anchorOffset:e.selection.anchor-n.posBeforeNode,headOffset:e.selection.head-r.posBeforeNode}}})}function Xz(t,e){var n,r;const i=(n=Vt(e.anchorBlockId,t.doc))==null?void 0:n.posBeforeNode;if(i===void 0)throw new Error(`Could not find block with ID ${e.anchorBlockId} to update selection`);let s;if(e.type==="cell")s=be.create(t.doc,i+e.anchorCellOffset,i+e.headCellOffset);else if(e.type==="node")s=W.create(t.doc,i+1);else{const o=(r=Vt(e.headBlockId,t.doc))==null?void 0:r.posBeforeNode;if(o===void 0)throw new Error(`Could not find block with ID ${e.headBlockId} to update selection`);s=j.create(t.doc,i+e.anchorOffset,o+e.headOffset)}t.setSelection(s)}function ff(t){return t.map(e=>e.type==="columnList"?e.children.map(n=>ff(n.children)).flat():{...e,children:ff(e.children)}).flat()}function Mw(t,e,n){t.transact(r=>{var i;const s=((i=t.getSelection())==null?void 0:i.blocks)||[t.getTextCursorPosition().block],o=Jz(t);t.removeBlocks(s),t.insertBlocks(ff(s),e,n),Xz(r,o)})}function Dw(t){return!t||t.type!=="columnList"}function vw(t,e,n){let r,i;if(e?e.children.length>0?(r=e.children[e.children.length-1],i="after"):(r=e,i="before"):n&&(r=n,i="before"),!r||!i)return;const s=t.getParentBlock(r);return Dw(s)?{referenceBlock:r,placement:i}:vw(t,i==="after"?r:t.getPrevBlock(r),s)}function Lw(t,e,n){let r,i;if(e?e.children.length>0?(r=e.children[0],i="before"):(r=e,i="after"):n&&(r=n,i="after"),!r||!i)return;const s=t.getParentBlock(r);return Dw(s)?{referenceBlock:r,placement:i}:Lw(t,i==="before"?r:t.getNextBlock(r),s)}function Zz(t){t.transact(()=>{const e=t.getSelection(),n=e?.blocks[0]||t.getTextCursorPosition().block,r=vw(t,t.getPrevBlock(n),t.getParentBlock(n));r&&Mw(t,r.referenceBlock,r.placement)})}function eV(t){t.transact(()=>{const e=t.getSelection(),n=e?.blocks[e?.blocks.length-1]||t.getTextCursorPosition().block,r=Lw(t,t.getNextBlock(n),t.getParentBlock(n));r&&Mw(t,r.referenceBlock,r.placement)})}function tV(t,e,n){const{$from:r,$to:i}=t.selection,s=r.blockRange(i,f=>f.childCount>0&&(f.type.name==="blockGroup"||f.type.name==="column"));if(!s)return!1;const o=s.startIndex;if(o===0)return!1;const a=s.parent.child(o-1);if(a.type!==e)return!1;const l=a.lastChild&&a.lastChild.type===n,c=M.from(l?e.create():null),u=new F(M.from(e.create(null,M.from(n.create(null,c)))),l?3:1,0),d=s.start,h=s.end;return t.step(new Fe(d-(l?3:1),h,d,h,u,1,!0)).scrollIntoView(),!0}function Rw(t){return t.transact(e=>tV(e,t.pmSchema.nodes.blockContainer,t.pmSchema.nodes.blockGroup))}function nV(t){t._tiptapEditor.commands.liftListItem("blockContainer")}function rV(t){return t.transact(e=>{const{bnBlock:n}=sa(e);return e.doc.resolve(n.beforePos).nodeBefore!==null})}function iV(t){return t.transact(e=>{const{bnBlock:n}=sa(e);return e.doc.resolve(n.beforePos).depth>1})}function sV(t,e){const n=typeof e=="string"?e:e.id,r=He(t),i=Vt(n,t);if(i)return ve(i.node,r)}function oV(t,e){const n=typeof e=="string"?e:e.id,r=Vt(n,t),i=He(t);if(!r)return;const s=t.resolve(r.posBeforeNode).nodeBefore;if(s)return ve(s,i)}function aV(t,e){const n=typeof e=="string"?e:e.id,r=Vt(n,t),i=He(t);if(!r)return;const s=t.resolve(r.posBeforeNode+r.node.nodeSize).nodeAfter;if(s)return ve(s,i)}function lV(t,e){const n=typeof e=="string"?e:e.id,r=He(t),i=Vt(n,t);if(!i)return;const s=t.resolve(i.posBeforeNode),o=s.node(),a=s.node(-1),l=a.type.name!=="doc"?o.type.name==="blockGroup"?a:o:void 0;if(l)return ve(l,r)}class cV{constructor(e){this.editor=e}get document(){return this.editor.transact(e=>iI(e.doc,this.editor.pmSchema))}getBlock(e){return this.editor.transact(n=>sV(n.doc,e))}getPrevBlock(e){return this.editor.transact(n=>oV(n.doc,e))}getNextBlock(e){return this.editor.transact(n=>aV(n.doc,e))}getParentBlock(e){return this.editor.transact(n=>lV(n.doc,e))}forEachBlock(e,n=!1){const r=this.document.slice();n&&r.reverse();function i(s){for(const o of s){if(e(o)===!1)return!1;const a=n?o.children.slice().reverse():o.children;if(!i(a))return!1}return!0}i(r)}insertBlocks(e,n,r="before"){return this.editor.transact(i=>Uz(i,e,n,r))}updateBlock(e,n){return this.editor.transact(r=>oL(r,e,n))}removeBlocks(e){return this.editor.transact(n=>S1(n,e,[]).removedBlocks)}replaceBlocks(e,n){return this.editor.transact(r=>S1(r,e,n))}canNestBlock(){return rV(this.editor)}nestBlock(){Rw(this.editor)}canUnnestBlock(){return iV(this.editor)}unnestBlock(){nV(this.editor)}moveBlocksUp(){return Zz(this.editor)}moveBlocksDown(){return eV(this.editor)}}class uV extends aw{constructor(e){super(),this.editor=e,e.on("create",()=>{e._tiptapEditor.on("update",({transaction:n,appendedTransactions:r})=>{this.emit("onChange",{editor:e,transaction:n,appendedTransactions:r})}),e._tiptapEditor.on("selectionUpdate",({transaction:n})=>{this.emit("onSelectionChange",{editor:e,transaction:n})}),e._tiptapEditor.on("mount",()=>{this.emit("onMount",{editor:e})}),e._tiptapEditor.on("unmount",()=>{this.emit("onUnmount",{editor:e})})})}onChange(e,n=!0){const r=({transaction:i,appendedTransactions:s})=>{!n&&w1(i)||e(this.editor,{getChanges(){return ZS(i,s)}})};return this.on("onChange",r),()=>{this.off("onChange",r)}}onSelectionChange(e,n=!1){const r=i=>{!n&&w1(i.transaction)||e(this.editor)};return this.on("onSelectionChange",r),()=>{this.off("onSelectionChange",r)}}onMount(e){return this.on("onMount",e),()=>{this.off("onMount",e)}}onUnmount(e){return this.on("onUnmount",e),()=>{this.off("onUnmount",e)}}}function w1(t){return!!t.getMeta("y-sync$")}function dV(t){return Array.prototype.indexOf.call(t.parentElement.childNodes,t)}function hV(t){return t.nodeType===3&&!/\S/.test(t.nodeValue||"")}function fV(t){t.querySelectorAll("li > ul, li > ol").forEach(e=>{const n=dV(e),r=e.parentElement,i=Array.from(r.childNodes).slice(n+1);e.remove(),i.forEach(s=>{s.remove()}),r.insertAdjacentElement("afterend",e),i.reverse().forEach(s=>{if(hV(s))return;const o=document.createElement("li");o.append(s),e.insertAdjacentElement("afterend",o)}),r.childNodes.length===0&&r.remove()})}function pV(t){t.querySelectorAll("li + ul, li + ol").forEach(e=>{var n,r;const i=e.previousElementSibling,s=document.createElement("div");i.insertAdjacentElement("afterend",s),s.append(i);const o=document.createElement("div");for(o.setAttribute("data-node-type","blockGroup"),s.append(o);((n=s.nextElementSibling)==null?void 0:n.nodeName)==="UL"||((r=s.nextElementSibling)==null?void 0:r.nodeName)==="OL";)o.append(s.nextElementSibling)})}let x1=null;function mV(){return x1||(x1=document.implementation.createHTMLDocument("title"))}function gV(t){if(typeof t=="string"){const e=mV().createElement("div");e.innerHTML=t,t=e}return fV(t),pV(t),t}function Pw(t,e){const n=gV(t),r=mn.fromSchema(e).parse(n,{topNode:e.nodes.blockGroup.create()}),i=[];for(let s=0;s<r.childCount;s++)i.push(ve(r.child(s),e));return i}function bV(t,e){const n=e.value?e.value:"",r={};e.lang&&(r["data-language"]=e.lang);let i={type:"element",tagName:"code",properties:r,children:[{type:"text",value:n}]};return e.meta&&(i.data={meta:e.meta}),t.patch(e,i),i=t.applyData(e,i),i={type:"element",tagName:"pre",properties:{},children:[i]},t.patch(e,i),i}function yV(t,e){var n;const r=String(e?.url||""),i=e!=null&&e.title?String(e.title):void 0;let s={type:"element",tagName:"video",properties:{src:r,"data-name":i,"data-url":r,controls:!0},children:[]};return(n=t.patch)==null||n.call(t,e,s),s=t.applyData?t.applyData(e,s):s,s}function Bw(t){return YS().use(X7).use(WS).use(v$,{handlers:{...lf,image:(e,n)=>{const r=String(n?.url||"");return Gv(r)?yV(e,n):lf.image(e,n)},code:bV,blockquote:(e,n)=>{const r={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(n),!1)};return e.patch(n,r),e.applyData(n,r)}}}).use(Bz).processSync(t).value}function EV(t,e){const n=Bw(t);return Pw(n,e)}class kV{constructor(e){this.editor=e}blocksToHTMLLossy(e=this.editor.document){return Au(this.editor.pmSchema,this.editor).exportBlocks(e,{})}blocksToFullHTML(e=this.editor.document){return Qz(this.editor.pmSchema,this.editor).serializeBlocks(e,{})}tryParseHTMLToBlocks(e){return Pw(e,this.editor.pmSchema)}blocksToMarkdownLossy(e=this.editor.document){return hU(e,this.editor.pmSchema,this.editor,{})}tryParseMarkdownToBlocks(e){return EV(e,this.editor.pmSchema)}pasteHTML(e,n=!1){var r;let i=e;if(!n){const s=this.tryParseHTMLToBlocks(e);i=this.blocksToFullHTML(s)}i&&((r=this.editor.prosemirrorView)==null||r.pasteHTML(i))}pasteText(e){var n;return(n=this.editor.prosemirrorView)==null?void 0:n.pasteText(e)}pasteMarkdown(e){const n=Bw(e);return this.pasteHTML(n)}}const bm=["vscode-editor-data","blocknote/html","text/markdown","text/html","text/plain","Files"];function TV(t,e){if(!t.startsWith(".")||!e.startsWith("."))throw new Error("The strings provided are not valid file extensions.");return t===e}function CV(t,e){const n=t.split("/"),r=e.split("/");if(n.length!==2)throw new Error(`The string ${t} is not a valid MIME type.`);if(r.length!==2)throw new Error(`The string ${e} is not a valid MIME type.`);return n[1]==="*"||r[1]==="*"?n[0]===r[0]:(n[0]==="*"||r[0]==="*"||n[0]===r[0])&&n[1]===r[1]}function A1(t,e,n,r="after"){let i;return Array.isArray(e.content)&&e.content.length===0?i=t.updateBlock(e,n).id:i=t.insertBlocks([n],e,r)[0].id,i}async function Fw(t,e){var n;if(!e.uploadFile){console.warn("Attempted ot insert file, but uploadFile is not set in the BlockNote editor options");return}const r="dataTransfer"in t?t.dataTransfer:t.clipboardData;if(r===null)return;let i=null;for(const o of bm)if(r.types.includes(o)){i=o;break}if(i!=="Files")return;const s=r.items;if(s){t.preventDefault();for(let o=0;o<s.length;o++){let a="file";for(const c of Object.values(e.schema.blockSpecs))for(const u of((n=c.implementation.meta)==null?void 0:n.fileBlockAccept)||[]){const d=u.startsWith("."),h=s[o].getAsFile();if(h&&(!d&&h.type&&CV(s[o].type,u)||d&&TV("."+h.name.split(".").pop(),u))){a=c.config.type;break}}const l=s[o].getAsFile();if(l){const c={type:a,props:{name:l.name}};let u;if(t.type==="paste"){const f=e.getTextCursorPosition().block;u=A1(e,f,c)}else if(t.type==="drop"){const f={left:t.clientX,top:t.clientY},p=e.prosemirrorView.posAtCoords(f);if(!p)return;u=e.transact(g=>{var b;const y=Rr(g.doc,p.pos),T=(b=e.domElement)==null?void 0:b.querySelector(`[data-id="${y.node.attrs.id}"]`),S=T?.getBoundingClientRect();return A1(e,e.getBlock(y.node.attrs.id),c,S&&(S.top+S.bottom)/2>f.top?"before":"after")})}else return;const d=await e.uploadFile(l,u),h=typeof d=="string"?{props:{url:d}}:{...d};e.updateBlock(u,h)}}}}const SV=t=>Le.create({name:"dropFile",addProseMirrorPlugins(){return[new te({props:{handleDOMEvents:{drop(e,n){if(!t.isEditable)return;let r=null;for(const i of bm)if(n.dataTransfer.types.includes(i)){r=i;break}return r===null?!0:r==="Files"?(Fw(n,t),!0):!1}}}})]}}),wV=/(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/,xV=/(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/,AV=/\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/,_V=/(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/,NV=/(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/,IV=/(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/,OV=/\n{2} {0,3}-{2,48}\n{2}/,MV=/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/,DV=/(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/,vV=/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/,LV=/^\s*\|(.+\|)+\s*$/m,RV=/^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m,PV=/^\s*\|(.+\|)+\s*$/m,BV=t=>wV.test(t)||xV.test(t)||AV.test(t)||_V.test(t)||NV.test(t)||IV.test(t)||OV.test(t)||MV.test(t)||DV.test(t)||vV.test(t)||LV.test(t)||RV.test(t)||PV.test(t);async function FV(t,e){const{schema:n}=e.state;if(!t.clipboardData)return!1;const r=t.clipboardData.getData("text/plain");if(!r)return!1;if(!n.nodes.codeBlock)return e.pasteText(r),!0;const i=t.clipboardData.getData("vscode-editor-data"),s=i?JSON.parse(i):void 0,o=s?.mode;return o?(e.pasteHTML(`<pre><code class="language-${o}">${r.replace(/\r\n?/g,`
177
177
  `)}</code></pre>`),!0):!1}function HV({event:t,editor:e,prioritizeMarkdownOverHTML:n,plainTextAsMarkdown:r}){var i;if(e.transact(a=>a.selection.$from.parent.type.spec.code&&a.selection.$to.parent.type.spec.code)){const a=(i=t.clipboardData)==null?void 0:i.getData("text/plain");if(a)return e.pasteText(a),!0}let s;for(const a of bm)if(t.clipboardData.types.includes(a)){s=a;break}if(!s)return!0;if(s==="vscode-editor-data")return FV(t,e.prosemirrorView),!0;if(s==="Files")return Fw(t,e),!0;const o=t.clipboardData.getData(s);if(s==="blocknote/html")return e.pasteHTML(o,!0),!0;if(s==="text/markdown")return e.pasteMarkdown(o),!0;if(n){const a=t.clipboardData.getData("text/plain");if(BV(a))return e.pasteMarkdown(a),!0}return s==="text/html"?(e.pasteHTML(o),!0):r?(e.pasteMarkdown(o),!0):(e.pasteText(o),!0)}const UV=(t,e)=>Le.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new te({props:{handleDOMEvents:{paste(n,r){if(r.preventDefault(),!!t.isEditable)return e({event:r,editor:t,defaultPasteHandler:({prioritizeMarkdownOverHTML:i=!0,plainTextAsMarkdown:s=!0}={})=>HV({event:r,editor:t,prioritizeMarkdownOverHTML:i,plainTextAsMarkdown:s})})}}}})]}});function $V(t,e,n){var r;let i=!1;const s=t.state.selection instanceof be;if(!s){const l=t.state.doc.slice(t.state.selection.from,t.state.selection.to,!1).content,c=[];for(let u=0;u<l.childCount;u++)c.push(l.child(u));i=c.find(u=>u.type.isInGroup("bnBlock")||u.type.name==="blockGroup"||u.type.spec.group==="blockContent")===void 0,i&&(e=l)}let o;const a=Au(t.state.schema,n);if(s){((r=e.firstChild)==null?void 0:r.type.name)==="table"&&(e=e.firstChild.content);const l=VE(e,n.schema.inlineContentSchema,n.schema.styleSchema);o=`<table>${a.exportInlineContent(l,{})}</table>`}else if(i){const l=Qc(e,n.schema.inlineContentSchema,n.schema.styleSchema);o=a.exportInlineContent(l,{})}else{const l=rw(e);o=a.exportBlocks(l,{})}return o}function Hw(t,e){"node"in t.state.selection&&t.state.selection.node.type.spec.group==="blockContent"&&e.transact(o=>o.setSelection(new W(o.doc.resolve(t.state.selection.from-1))));const n=t.serializeForClipboard(t.state.selection.content()).dom.innerHTML,r=t.state.selection.content().content,i=$V(t,r,e),s=sm(i);return{clipboardHTML:n,externalHTML:i,markdown:s}}const _1=()=>{const t=window.getSelection();if(!t||t.isCollapsed)return!0;let e=t.focusNode;for(;e;){if(e instanceof HTMLElement&&e.getAttribute("contenteditable")==="false")return!0;e=e.parentElement}return!1},N1=(t,e,n)=>{n.preventDefault(),n.clipboardData.clearData();const{clipboardHTML:r,externalHTML:i,markdown:s}=Hw(e,t);n.clipboardData.setData("blocknote/html",r),n.clipboardData.setData("text/html",i),n.clipboardData.setData("text/plain",s)},zV=t=>Le.create({name:"copyToClipboard",addProseMirrorPlugins(){return[new te({props:{handleDOMEvents:{copy(e,n){return _1()||N1(t,e,n),!0},cut(e,n){return _1()||(N1(t,e,n),e.editable&&e.dispatch(e.state.tr.deleteSelection())),!0},dragstart(e,n){if(!("node"in e.state.selection)||e.state.selection.node.type.spec.group!=="blockContent")return;t.transact(o=>o.setSelection(new W(o.doc.resolve(e.state.selection.from-1)))),n.preventDefault(),n.dataTransfer.clearData();const{clipboardHTML:r,externalHTML:i,markdown:s}=Hw(e,t);return n.dataTransfer.setData("blocknote/html",r),n.dataTransfer.setData("text/html",i),n.dataTransfer.setData("text/plain",s),!0}}}})]}}),VV=Le.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["tableCell","tableHeader"],attributes:{backgroundColor:cL()}}]}}),jV=Cn.create({name:"hardBreak",inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,priority:10,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:t}){return["br",sn(this.options.HTMLAttributes,t)]},renderText(){return`
178
- `}}),pf=(t,e)=>{const n=t.resolve(e),r=n.index();if(r===0)return;const i=n.posAtIndex(r-1);return Gc(t.resolve(i))},Uw=(t,e)=>{for(;e.childContainer;){const n=e.childContainer.node,r=t.resolve(e.childContainer.beforePos+1).posAtIndex(n.childCount-1);e=Gc(t.resolve(r))}return e},qV=(t,e)=>t.isBlockContainer&&t.blockContent.node.type.spec.content==="inline*"&&t.blockContent.node.childCount>0&&e.isBlockContainer&&e.blockContent.node.type.spec.content==="inline*",WV=(t,e,n,r)=>{if(!r.isBlockContainer)throw new Error(`Attempted to merge block at position ${r.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but next block is not a block container`);if(r.childContainer){const i=t.doc.resolve(r.childContainer.beforePos+1),s=t.doc.resolve(r.childContainer.afterPos-1),o=i.blockRange(s);if(e){const a=t.doc.resolve(r.bnBlock.beforePos);t.tr.lift(o,a.depth)}}if(e){if(!n.isBlockContainer)throw new Error(`Attempted to merge block at position ${r.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but previous block is not a block container`);e(t.tr.delete(n.blockContent.afterPos-1,r.blockContent.beforePos+1))}return!0},I1=t=>({state:e,dispatch:n})=>{const r=e.doc.resolve(t),i=Gc(r),s=pf(e.doc,i.bnBlock.beforePos);if(!s)return!1;const o=Uw(e.doc,s);return qV(o,i)?WV(e,n,o,i):!1},YV=Le.create({priority:50,addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({chain:r,commands:i})=>[()=>i.deleteSelection(),()=>i.undoInputRule(),()=>i.command(({state:s})=>{const o=xt(s);if(!o.isBlockContainer)return!1;const a=s.selection.from===o.blockContent.beforePos+1,l=o.blockContent.node.type.name==="paragraph";return a&&!l?i.command(iL(o.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>i.command(({state:s})=>{const o=xt(s);if(!o.isBlockContainer)return!1;const{blockContent:a}=o;return s.selection.from===a.beforePos+1?i.liftListItem("blockContainer"):!1}),()=>i.command(({state:s})=>{const o=xt(s);if(!o.isBlockContainer)return!1;const{bnBlock:a,blockContent:l}=o,c=s.selection.from===l.beforePos+1,u=s.selection.empty,d=a.beforePos;return c&&u?r().command(I1(d)).scrollIntoView().run():!1}),()=>i.command(({state:s,tr:o,dispatch:a})=>{const l=xt(s);if(!l.isBlockContainer||o.selection.from!==l.blockContent.beforePos+1)return!1;const c=o.doc.resolve(l.bnBlock.beforePos);if(c.nodeBefore||c.node().type.name!=="column")return!1;const u=o.doc.resolve(l.bnBlock.beforePos),d=o.doc.resolve(u.before()),h=d.before();if(a){const f=o.doc.slice(l.bnBlock.beforePos,l.bnBlock.afterPos).content;o.delete(l.bnBlock.beforePos,l.bnBlock.afterPos),d.index()===0?(hf(o,h),o.insert(h,f),o.setSelection(j.near(o.doc.resolve(h)))):(o.insert(d.pos-1,f),o.setSelection(j.near(o.doc.resolve(d.pos-1))),hf(o,h))}return!0}),()=>i.command(({state:s})=>{const o=xt(s);if(!o.isBlockContainer)return!1;if(o.blockContent.node.childCount===0&&o.blockContent.node.type.spec.content==="inline*"){const a=pf(s.doc,o.bnBlock.beforePos);if(!a||!a.isBlockContainer)return!1;let l=r();if(a.blockContent.node.type.spec.content==="tableRow+"){const c=o.bnBlock.beforePos-1-1-1-1-1;l=l.setTextSelection(c)}else if(a.blockContent.node.type.spec.content===""){const c=a.blockContent.afterPos-a.blockContent.node.nodeSize;l=l.setNodeSelection(c)}else{const c=a.blockContent.afterPos-a.blockContent.node.nodeSize;l=l.setTextSelection(c)}return l.deleteRange({from:o.bnBlock.beforePos,to:o.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>i.command(({state:s})=>{const o=xt(s);if(!o.isBlockContainer)throw new Error("todo");const a=s.selection.from===o.blockContent.beforePos+1,l=s.selection.empty,c=pf(s.doc,o.bnBlock.beforePos);if(c&&a&&l){const u=Uw(s.doc,c);if(!u.isBlockContainer)throw new Error("todo");if(u.blockContent.node.type.spec.content===""||u.blockContent.node.type.spec.content==="inline*"&&u.blockContent.node.childCount===0)return r().cut({from:o.bnBlock.beforePos,to:o.bnBlock.afterPos},u.bnBlock.afterPos).deleteRange({from:u.bnBlock.beforePos,to:u.bnBlock.afterPos}).run()}return!1})]),e=()=>this.editor.commands.first(({commands:r})=>[()=>r.deleteSelection(),()=>r.command(({state:i})=>{const s=xt(i);if(!s.isBlockContainer)return!1;const{bnBlock:o,blockContent:a,childContainer:l}=s,{depth:c}=i.doc.resolve(o.beforePos),u=o.afterPos===i.doc.nodeSize-3,d=i.selection.from===a.afterPos-1,h=i.selection.empty;if(!u&&d&&h&&l===void 0){let f=c,p=o.afterPos+1,g=i.doc.resolve(p).depth;for(;g<f;)f=g,p+=2,g=i.doc.resolve(p).depth;return r.command(I1(p-1))}return!1})]),n=(r=!1)=>this.editor.commands.first(({commands:i,tr:s})=>[()=>i.command(({state:o})=>{const a=xt(o);if(!a.isBlockContainer)return!1;const{bnBlock:l,blockContent:c}=a,{depth:u}=o.doc.resolve(l.beforePos),d=o.selection.$anchor.parentOffset===0,h=o.selection.anchor===o.selection.head,f=c.node.childCount===0,p=u>1;return d&&h&&f&&p?i.liftListItem("blockContainer"):!1}),()=>i.command(({state:o})=>{var a;const l=xt(o),c=((a=this.options.editor.schema.blockSchema[l.blockNoteType].meta)==null?void 0:a.hardBreakShortcut)??"shift+enter";if(c==="none")return!1;if(c==="shift+enter"&&r||c==="enter"){const u=s.storedMarks||s.selection.$head.marks().filter(d=>this.editor.extensionManager.splittableMarks.includes(d.type.name));return s.insert(s.selection.head,s.doc.type.schema.nodes.hardBreak.create()).ensureMarks(u),!0}return!1}),()=>i.command(({state:o,dispatch:a})=>{const l=xt(o);if(!l.isBlockContainer)return!1;const{bnBlock:c,blockContent:u}=l,d=o.selection.$anchor.parentOffset===0,h=o.selection.anchor===o.selection.head,f=u.node.childCount===0;if(d&&h&&f){const p=c.afterPos,g=p+2;if(a){const b=o.schema.nodes.blockContainer.createAndFill();o.tr.insert(p,b).scrollIntoView(),o.tr.setSelection(new j(o.doc.resolve(g)))}return!0}return!1}),()=>i.command(({state:o,chain:a})=>{const l=xt(o);if(!l.isBlockContainer)return!1;const{blockContent:c}=l,u=o.selection.$anchor.parentOffset===0;return c.node.childCount===0?!1:(a().deleteSelection().command(FL(o.selection.from,u,u)).run(),!0)})]);return{Backspace:t,Delete:e,Enter:()=>n(),"Shift-Enter":()=>n(!0),Tab:()=>{var r,i;return this.options.tabBehavior!=="prefer-indent"&&((r=this.options.editor.getExtension(Jh))!=null&&r.store.state||((i=this.options.editor.getExtension(Ir))==null?void 0:i.store.state)!==void 0)?!1:Rw(this.options.editor)},"Shift-Tab":()=>{var r,i;return this.options.tabBehavior!=="prefer-indent"&&((r=this.options.editor.getExtension(Jh))!=null&&r.store.state||((i=this.options.editor.getExtension(Ir))==null?void 0:i.store.state)!==void 0)?!1:this.editor.commands.liftListItem("blockContainer")},"Shift-Mod-ArrowUp":()=>(this.options.editor.moveBlocksUp(),!0),"Shift-Mod-ArrowDown":()=>(this.options.editor.moveBlocksDown(),!0),"Mod-z":()=>this.options.editor.undo(),"Mod-y":()=>this.options.editor.redo(),"Shift-Mod-z":()=>this.options.editor.redo()}}}),KV=Tn.create({name:"insertion",inclusive:!1,excludes:"deletion modification insertion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(t){return t.name!=="insertion"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(e,n){return["ins",{"data-id":String(e.attrs.id),"data-inline":String(n),...!n&&{style:"display: contents"}},0]},parseDOM:[{tag:"ins",getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10)}:!1}}]}}}),GV=Tn.create({name:"deletion",inclusive:!1,excludes:"insertion modification deletion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(t){return t.name!=="deletion"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(e,n){return["del",{"data-id":String(e.attrs.id),"data-inline":String(n),...!n&&{style:"display: contents"}},0]},parseDOM:[{tag:"del",getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10)}:!1}}]}}}),QV=Tn.create({name:"modification",inclusive:!1,excludes:"deletion insertion",addAttributes(){return{id:{default:null,validate:"number"},type:{validate:"string"},attrName:{default:null,validate:"string|null"},previousValue:{default:null},newValue:{default:null}}},extendMarkSchema(t){return t.name!=="modification"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(e,n){return[n?"span":"div",{"data-type":"modification","data-id":String(e.attrs.id),"data-mod-type":e.attrs.type,"data-mod-prev-val":JSON.stringify(e.attrs.previousValue),"data-mod-new-val":JSON.stringify(e.attrs.newValue)},0]},parseDOM:[{tag:"span[data-type='modification']",getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal,newValue:e.dataset.modNewVal}:!1}},{tag:"div[data-type='modification']",getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal}:!1}}]}}}),JV=Le.create({name:"textAlignment",addGlobalAttributes(){return[{types:["tableCell","tableHeader"],attributes:{textAlignment:{default:"left",parseHTML:t=>t.getAttribute("data-text-alignment"),renderHTML:t=>t.textAlignment==="left"?{}:{"data-text-alignment":t.textAlignment}}}}]}}),XV=Le.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["table","tableCell","tableHeader"],attributes:{textColor:uL()}}]}}),ZV={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},ej=Cn.create({name:"blockContainer",group:"blockGroupChild bnBlock",content:"blockContent blockGroup?",priority:50,defining:!0,marks:"insertion modification deletion",parseHTML(){return[{tag:"div[data-node-type="+this.name+"]",getAttrs:t=>{if(typeof t=="string")return!1;const e={};for(const[n,r]of Object.entries(ZV))t.getAttribute(r)&&(e[n]=t.getAttribute(r));return e}},{tag:'div[data-node-type="blockOuter"]',skip:!0}]},renderHTML({HTMLAttributes:t}){var e;const n=document.createElement("div");n.className="bn-block-outer",n.setAttribute("data-node-type","blockOuter");for(const[s,o]of Object.entries(t))s!=="class"&&n.setAttribute(s,o);const r={...((e=this.options.domAttributes)==null?void 0:e.block)||{},...t},i=document.createElement("div");i.className=Ur("bn-block",r.class),i.setAttribute("data-node-type",this.name);for(const[s,o]of Object.entries(r))s!=="class"&&i.setAttribute(s,o);return n.appendChild(i),{dom:n,contentDOM:i}}}),tj=Cn.create({name:"blockGroup",group:"childContainer",content:"blockGroupChild+",marks:"deletion insertion modification",parseHTML(){return[{tag:"div",getAttrs:t=>typeof t=="string"?!1:t.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:t}){var e;const n={...((e=this.options.domAttributes)==null?void 0:e.blockGroup)||{},...t},r=document.createElement("div");r.className=Ur("bn-block-group",n.class),r.setAttribute("data-node-type","blockGroup");for(const[i,s]of Object.entries(n))i!=="class"&&r.setAttribute(i,s);return{dom:r,contentDOM:r}}}),nj=Cn.create({name:"doc",topNode:!0,content:"blockGroup",marks:"insertion modification deletion"}),rj=pe(({options:t})=>({key:"collaboration",blockNoteExtensions:[KH(t),Qh(t),yl(t),El(),JH(t)]}));let O1=!1;function ij(t,e){const n=[Wi.ClipboardTextSerializer,Wi.Commands,Wi.Editable,Wi.FocusEvents,Wi.Tabindex,KU,Kc.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),jV,k7,KV,GV,QV,E7.extend({inclusive:!1}).configure({defaultProtocol:nU,protocols:O1?[]:tU}),...Object.values(t.schema.styleSpecs).map(r=>r.implementation.mark.configure({editor:t})),XV,VV,JV,Le.create({name:"OverrideEscape",addKeyboardShortcuts:()=>({Escape:()=>{var r;return(r=t.getExtension(Rp))!=null&&r.shown()?!1:(t.blur(),!0)}})}),nj,ej.configure({editor:t,domAttributes:e.domAttributes}),YV.configure({editor:t,tabBehavior:e.tabBehavior}),tj.configure({domAttributes:e.domAttributes}),...Object.values(t.schema.inlineContentSpecs).filter(r=>r.config!=="link"&&r.config!=="text").map(r=>r.implementation.node.configure({editor:t})),...Object.values(t.schema.blockSpecs).flatMap(r=>[..."node"in r.implementation?[r.implementation.node.configure({editor:t,domAttributes:e.domAttributes})]:[]]),zV(t),UV(t,e.pasteHandler||(r=>r.defaultPasteHandler())),SV(t)];return O1=!0,n}function sj(t,e){const n=[ew(),XH(e),Ir(e),Jh(e),eU(e),iU(),oU(e),T7(e),yU(e),Rp(e),...e.trailingBlock!==!1?[wU()]:[]];return e.collaboration?n.push(rj(e.collaboration)):n.push(ZH()),"table"in t.schema.blockSpecs&&n.push(SU(e)),e.animations!==!1&&n.push(lU()),n}class oj{constructor(e,n){he(this,"disabledExtensions",new Set),he(this,"extensions",[]),he(this,"abortMap",new Map),he(this,"extensionFactories",new Map),he(this,"extensionPlugins",new Map),this.editor=e,this.options=n,e.onMount(()=>{for(const r of this.extensions)if(r.mount){const i=new window.AbortController,s=r.mount({dom:e.prosemirrorView.dom,root:e.prosemirrorView.root,signal:i.signal});s&&i.signal.addEventListener("abort",()=>{s()}),this.abortMap.set(r,i)}}),e.onUnmount(()=>{for(const[r,i]of this.abortMap.entries())this.abortMap.delete(r),i.abort()}),this.disabledExtensions=new Set(n.disableExtensions||[]);for(const r of sj(this.editor,this.options))this.addExtension(r);for(const r of this.options.extensions??[])this.addExtension(r);for(const r of Object.values(this.editor.schema.blockSpecs))for(const i of r.extensions??[])this.addExtension(i)}registerExtension(e){var n;const r=[].concat(e).filter(Boolean);if(!r.length){console.warn("No extensions found to register",e);return}const i=r.map(o=>this.addExtension(o)).filter(Boolean),s=new Set;for(const o of i)o!=null&&o.tiptapExtensions&&console.warn(`Extension ${o.key} has tiptap extensions, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`,o),(n=o?.inputRules)!=null&&n.length&&console.warn(`Extension ${o.key} has input rules, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`,o),this.getProsemirrorPluginsFromExtension(o).plugins.forEach(a=>{s.add(a)});this.updatePlugins(o=>[...o,...s])}addExtension(e){let n;if(typeof e=="function"?n=e({editor:this.editor}):n=e,!(!n||this.disabledExtensions.has(n.key))){if(typeof e=="function"){const r=n[Dh];typeof r=="function"&&this.extensionFactories.set(r,n)}if(this.extensions.push(n),n.blockNoteExtensions)for(const r of n.blockNoteExtensions)this.addExtension(r);return n}}resolveExtensions(e){const n=[];if(typeof e=="function"){const r=this.extensionFactories.get(e);r&&n.push(r)}else if(Array.isArray(e))for(const r of e)n.push(...this.resolveExtensions(r));else if(typeof e=="object"&&"key"in e)n.push(e);else if(typeof e=="string"){const r=this.extensions.find(i=>i.key===e);r&&n.push(r)}return n}unregisterExtension(e){var n;const r=this.resolveExtensions(e);if(!r.length){console.warn("No extensions found to unregister",e);return}let i=!1;const s=new Set;for(const o of r){this.extensions=this.extensions.filter(l=>l!==o),this.extensionFactories.forEach((l,c)=>{l===o&&this.extensionFactories.delete(c)}),(n=this.abortMap.get(o))==null||n.abort(),this.abortMap.delete(o);const a=this.extensionPlugins.get(o);a?.forEach(l=>{s.add(l)}),this.extensionPlugins.delete(o),o.tiptapExtensions&&!i&&(i=!0,console.warn(`Extension ${o.key} has tiptap extensions, but they will not be removed. Please separate the extension into multiple extensions if you want to remove them, or re-initialize the editor.`,e))}this.updatePlugins(o=>o.filter(a=>!s.has(a)))}updatePlugins(e){const n=this.editor.prosemirrorState,r=n.reconfigure({plugins:e(n.plugins.slice())});this.editor.prosemirrorView.updateState(r)}getTiptapExtensions(){var e;const n=ij(this.editor,this.options).filter(s=>!this.disabledExtensions.has(s.name)),r=sw(this.extensions),i=new Map;for(const s of this.extensions){s.tiptapExtensions&&n.push(...s.tiptapExtensions);const o=r(s.key),{plugins:a,inputRules:l}=this.getProsemirrorPluginsFromExtension(s);a.length&&n.push(Le.create({name:s.key,priority:o,addProseMirrorPlugins:()=>a})),l.length&&(i.has(o)||i.set(o,[]),i.get(o).push(...l))}n.push(Le.create({name:"blocknote-input-rules",addProseMirrorPlugins(){const s=[];return Array.from(i.keys()).sort().reverse().forEach(o=>{s.push(...i.get(o))}),[UU({rules:s})]}}));for(const s of((e=this.options._tiptapOptions)==null?void 0:e.extensions)??[])n.push(s);return n}getProsemirrorPluginsFromExtension(e){var n,r,i;const s=[...e.prosemirrorPlugins??[]],o=[];return!((n=e.prosemirrorPlugins)!=null&&n.length)&&!Object.keys(e.keyboardShortcuts||{}).length&&!((r=e.inputRules)!=null&&r.length)?{plugins:s,inputRules:o}:(this.extensionPlugins.set(e,s),(i=e.inputRules)!=null&&i.length&&o.push(...e.inputRules.map(a=>new Ri(a.find,(l,c,u,d)=>{const h=a.replace({match:c,range:{from:u,to:d},editor:this.editor});if(h){const f=this.editor.getTextCursorPosition();if(this.editor.schema.blockSchema[f.block.type].content!=="inline")return null;const p=sa(l.tr),g=l.tr.deleteRange(u,d);return uu(g,p.bnBlock.beforePos,h),g}return null}))),Object.keys(e.keyboardShortcuts||{}).length&&s.push(oE(Object.fromEntries(Object.entries(e.keyboardShortcuts).map(([a,l])=>[a,()=>l({editor:this.editor})])))),{plugins:s,inputRules:o})}getExtensions(){return new Map(this.extensions.map(e=>[e.key,e]))}getExtension(e){if(typeof e=="string")return this.extensions.find(r=>r.key===e)||void 0;if(typeof e=="function")return this.extensionFactories.get(e)||void 0;throw new Error(`Invalid extension type: ${typeof e}`)}hasExtension(e){return typeof e=="string"?this.extensions.some(n=>n.key===e):typeof e=="object"&&"key"in e?this.extensions.some(n=>n.key===e.key):typeof e=="function"?this.extensionFactories.has(e):!1}}function aj(t,e){let{$from:n,$to:r}=e;if(n.pos>n.start()&&n.pos<t.content.size){const i=t.textBetween(n.pos,n.pos+1);if(/^[\w\p{P}]$/u.test(i)){const s=t.textBetween(n.start(),n.pos).match(/[\w\p{P}]+$/u);s&&(n=t.resolve(n.pos-s[0].length))}}if(r.pos<r.end()&&r.pos>0){const i=t.textBetween(r.pos-1,r.pos);if(/^[\w\p{P}]$/u.test(i)){const s=t.textBetween(r.pos,r.end()).match(/^[\w\p{P}]+/u);s&&(r=t.resolve(r.pos+s[0].length))}}return{$from:n,$to:r,from:n.pos,to:r.pos}}function lj(t){const e=He(t);if(t.selection.empty||"node"in t.selection)return;const n=t.doc.resolve(Rr(t.doc,t.selection.from).posBeforeNode),r=t.doc.resolve(Rr(t.doc,t.selection.to).posBeforeNode),i=(c,u)=>{const d=n.posAtIndex(c,u),h=t.doc.resolve(d).nodeAfter;if(!h)throw new Error(`Error getting selection - node not found at position ${d}`);return ve(h,e)},s=[],o=n.sharedDepth(r.pos),a=n.index(o),l=r.index(o);if(n.depth>o){s.push(ve(n.nodeAfter,e));for(let c=n.depth;c>o;c--)if(n.node(c).type.isInGroup("childContainer")){const u=n.index(c)+1,d=n.node(c).childCount;for(let h=u;h<d;h++)s.push(i(h,c))}}else s.push(i(a,o));for(let c=a+1;c<=l;c++)s.push(i(c,o));if(s.length===0)throw new Error(`Error getting selection - selection doesn't span any blocks (${t.selection})`);return{blocks:s}}function cj(t,e,n){const r=typeof e=="string"?e:e.id,i=typeof n=="string"?n:n.id,s=He(t),o=oa(s);if(r===i)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${r})`);const a=Vt(r,t.doc);if(!a)throw new Error(`Block with ID ${r} not found`);const l=Vt(i,t.doc);if(!l)throw new Error(`Block with ID ${i} not found`);const c=Pr(a),u=Pr(l),d=o.blockSchema[c.blockNoteType],h=o.blockSchema[u.blockNoteType];if(!c.isBlockContainer||d.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);if(!u.isBlockContainer||h.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${i})`);let f,p;if(d.content==="table"){const g=Ae.get(c.blockContent.node);f=c.blockContent.beforePos+g.positionAt(0,0,c.blockContent.node)+1+2}else f=c.blockContent.beforePos+1;if(h.content==="table"){const g=Ae.get(u.blockContent.node),b=u.blockContent.beforePos+g.positionAt(g.height-1,g.width-1,u.blockContent.node)+1,y=t.doc.resolve(b).nodeAfter.nodeSize;p=b+y-2}else p=u.blockContent.afterPos-1;t.setSelection(j.create(t.doc,f,p))}function uj(t,e=!1){const n=He(t),r=e?aj(t.doc,t.selection):t.selection;let i=r.$from,s=r.$to;for(;s.parentOffset>=s.parent.nodeSize-2&&s.depth>0;)s=t.doc.resolve(s.pos+1);for(;s.parentOffset===0&&s.depth>0;)s=t.doc.resolve(s.pos-1);for(;i.parentOffset===0&&i.depth>0;)i=t.doc.resolve(i.pos-1);for(;i.parentOffset>=i.parent.nodeSize-2&&i.depth>0;)i=t.doc.resolve(i.pos+1);const o=sI(t.doc.slice(i.pos,s.pos,!0),n);return{_meta:{startPos:i.pos,endPos:s.pos},...o}}function dj(t){const{bnBlock:e}=sa(t),n=He(t.doc),r=t.doc.resolve(e.beforePos),i=r.nodeBefore,s=t.doc.resolve(e.afterPos).nodeAfter;let o;return r.depth>1&&(o=r.node(),o.type.isInGroup("bnBlock")||(o=r.node(r.depth-1))),{block:ve(e.node,n),prevBlock:i===null?void 0:ve(i,n),nextBlock:s===null?void 0:ve(s,n),parentBlock:o===void 0?void 0:ve(o,n)}}function $w(t,e,n="start"){const r=typeof e=="string"?e:e.id,i=He(t.doc),s=oa(i),o=Vt(r,t.doc);if(!o)throw new Error(`Block with ID ${r} not found`);const a=Pr(o),l=s.blockSchema[a.blockNoteType].content;if(a.isBlockContainer){const c=a.blockContent;if(l==="none"){t.setSelection(W.create(t.doc,c.beforePos));return}if(l==="inline")n==="start"?t.setSelection(j.create(t.doc,c.beforePos+1)):t.setSelection(j.create(t.doc,c.afterPos-1));else if(l==="table")n==="start"?t.setSelection(j.create(t.doc,c.beforePos+4)):t.setSelection(j.create(t.doc,c.afterPos-4));else throw new Pn(l)}else{const c=n==="start"?a.childContainer.node.firstChild:a.childContainer.node.lastChild;$w(t,c.attrs.id,n)}}class hj{constructor(e){this.editor=e}getSelection(){return this.editor.transact(e=>lj(e))}getSelectionCutBlocks(e=!1){return this.editor.transact(n=>uj(n,e))}setSelection(e,n){return this.editor.transact(r=>cj(r,e,n))}getTextCursorPosition(){return this.editor.transact(e=>dj(e))}setTextCursorPosition(e,n="start"){return this.editor.transact(r=>$w(r,e,n))}getSelectionBoundingBox(){if(!this.editor.prosemirrorView)return;const{selection:e}=this.editor.prosemirrorState,{ranges:n}=e,r=Math.min(...n.map(s=>s.$from.pos)),i=Math.max(...n.map(s=>s.$to.pos));if(rN(e)){const s=this.editor.prosemirrorView.nodeDOM(r);if(s)return s.getBoundingClientRect()}return wE(this.editor.prosemirrorView,r,i).toJSON()}}class fj{constructor(e){he(this,"activeTransaction",null),he(this,"isInCan",!1),this.editor=e}can(e){try{return this.isInCan=!0,e()}finally{this.isInCan=!1}}exec(e){if(this.activeTransaction)throw new Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");if(this.isInCan)return this.canExec(e);const n=this.prosemirrorState,r=this.prosemirrorView;return e(n,i=>this.prosemirrorView.dispatch(i),r)}canExec(e){if(this.activeTransaction)throw new Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");const n=this.prosemirrorState,r=this.prosemirrorView;return e(n,void 0,r)}transact(e){if(this.activeTransaction)return e(this.activeTransaction);try{this.activeTransaction=this.editor._tiptapEditor.state.tr;const n=e(this.activeTransaction),r=this.activeTransaction;return this.activeTransaction=null,r&&(r.docChanged||r.selectionSet||r.scrolledIntoView||r.storedMarksSet||!r.isGeneric)&&this.prosemirrorView.dispatch(r),n}finally{this.activeTransaction=null}}get prosemirrorState(){if(this.activeTransaction)throw new Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");return this.editor._tiptapEditor.state}get prosemirrorView(){return this.editor._tiptapEditor.view}isFocused(){var e;return((e=this.prosemirrorView)==null?void 0:e.hasFocus())||!1}focus(){var e;(e=this.prosemirrorView)==null||e.focus()}get isEditable(){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw new Error("no editor, but also not headless?");return!1}return this.editor._tiptapEditor.isEditable===void 0?!0:this.editor._tiptapEditor.isEditable}set isEditable(e){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw new Error("no editor, but also not headless?");return}this.editor._tiptapEditor.options.editable!==e&&this.editor._tiptapEditor.setEditable(e)}undo(){const e=this.editor.getExtension("yUndo");if(e)return this.exec(e.undoCommand);const n=this.editor.getExtension("history");if(n)return this.exec(n.undoCommand);throw new Error("No undo plugin found")}redo(){const e=this.editor.getExtension("yUndo");if(e)return this.exec(e.redoCommand);const n=this.editor.getExtension("history");if(n)return this.exec(n.redoCommand);throw new Error("No redo plugin found")}}function pj(t,e,n,r={updateSelection:!0}){let{from:i,to:s}=typeof e=="number"?{from:e,to:e}:{from:e.from,to:e.to},o=!0,a=!0,l="";if(n.forEach(c=>{c.check(),o&&c.isText&&c.marks.length===0?l+=c.text:o=!1,a=a?c.isBlock:!1}),i===s&&a){const{parent:c}=t.doc.resolve(i);c.isTextblock&&!c.type.spec.code&&!c.childCount&&(i-=1,s+=1)}return o?t.insertText(l,i,s):t.replaceWith(i,s,n),r.updateSelection&&hE(t,t.steps.length-1,-1),!0}class mj{constructor(e){this.editor=e}insertInlineContent(e,{updateSelection:n=!1}={}){const r=bn(e,this.editor.pmSchema);this.editor.transact(i=>{pj(i,{from:i.selection.from,to:i.selection.to},r,{updateSelection:n})})}getActiveStyles(){return this.editor.transact(e=>{const n={},r=e.selection.$to.marks();for(const i of r){const s=this.editor.schema.styleSchema[i.type.name];if(!s){i.type.name!=="link"&&!i.type.spec.blocknoteIgnore&&console.warn("mark not found in styleschema",i.type.name);continue}s.propSchema==="boolean"?n[s.type]=!0:n[s.type]=i.attrs.stringValue}return n})}addStyles(e){for(const[n,r]of Object.entries(e)){const i=this.editor.schema.styleSchema[n];if(!i)throw new Error(`style ${n} not found in styleSchema`);if(i.propSchema==="boolean")this.editor._tiptapEditor.commands.setMark(n);else if(i.propSchema==="string")this.editor._tiptapEditor.commands.setMark(n,{stringValue:r});else throw new Pn(i.propSchema)}}removeStyles(e){for(const n of Object.keys(e))this.editor._tiptapEditor.commands.unsetMark(n)}toggleStyles(e){for(const[n,r]of Object.entries(e)){const i=this.editor.schema.styleSchema[n];if(!i)throw new Error(`style ${n} not found in styleSchema`);if(i.propSchema==="boolean")this.editor._tiptapEditor.commands.toggleMark(n);else if(i.propSchema==="string")this.editor._tiptapEditor.commands.toggleMark(n,{stringValue:r});else throw new Pn(i.propSchema)}}getSelectedText(){return this.editor.transact(e=>e.doc.textBetween(e.selection.from,e.selection.to))}getSelectedLinkUrl(){return this.editor._tiptapEditor.getAttributes("link").href}createLink(e,n){if(e==="")return;const r=this.editor.pmSchema.mark("link",{href:e});this.editor.transact(i=>{const{from:s,to:o}=i.selection;n?i.insertText(n,s,o).addMark(s,s+n.length,r):i.setSelection(j.create(i.doc,o)).addMark(s,o,r)})}}function gj(t,e){const n=[];return t.forEach((r,i,s)=>{s!==e&&n.push(r)}),M.from(n)}function bj(t,e){const n=[];for(let r=0;r<t.childCount;r++)if(t.child(r).type.name==="tableRow")if(n.length>0&&n[n.length-1].type.name==="table"){const i=n[n.length-1],s=i.copy(i.content.addToEnd(t.child(r)));n[n.length-1]=s}else{const i=e.nodes.table.createChecked(void 0,t.child(r));n.push(i)}else n.push(t.child(r));return t=M.from(n),t}function yj(t,e){let n=M.from(t.content);if(n=bj(n,e.state.schema),!Ej(n,e))return new F(n,t.openStart,t.openEnd);for(let r=0;r<n.childCount;r++)if(n.child(r).type.spec.group==="blockContent"){const i=[n.child(r)];if(r+1<n.childCount&&n.child(r+1).type.name==="blockGroup"){const o=n.child(r+1).child(0).child(0);(o.type.name==="bulletListItem"||o.type.name==="numberedListItem"||o.type.name==="checkListItem")&&(i.push(n.child(r+1)),n=gj(n,r+1))}const s=e.state.schema.nodes.blockContainer.createChecked(void 0,i);n=n.replaceChild(r,s)}return new F(n,t.openStart,t.openEnd)}function Ej(t,e){var n,r;const i=t.childCount===1,s=((n=t.firstChild)==null?void 0:n.type.spec.content)==="inline*",o=((r=t.firstChild)==null?void 0:r.type.spec.content)==="tableRow+";if(i){if(s)return!1;if(o){const a=xt(e.state);if(a.isBlockContainer)return a.blockContent.node.type.spec.content!=="tableRow+"}}return!0}const kj={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class zw extends aw{constructor(e){var n,r,i,s,o,a,l,c,u,d;super(),he(this,"pmSchema"),he(this,"_tiptapEditor"),he(this,"elementRenderer",null),he(this,"blockCache",new WeakMap),he(this,"dictionary"),he(this,"schema"),he(this,"blockImplementations"),he(this,"inlineContentImplementations"),he(this,"styleImplementations"),he(this,"uploadFile"),he(this,"onUploadStartCallbacks",[]),he(this,"onUploadEndCallbacks",[]),he(this,"resolveFileUrl"),he(this,"settings"),he(this,"_blockManager"),he(this,"_eventManager"),he(this,"_exportManager"),he(this,"_extensionManager"),he(this,"_selectionManager"),he(this,"_stateManager"),he(this,"_styleManager"),he(this,"unregisterExtension",(...T)=>this._extensionManager.unregisterExtension(...T)),he(this,"registerExtension",(...T)=>this._extensionManager.registerExtension(...T)),he(this,"getExtension",(...T)=>this._extensionManager.getExtension(...T)),he(this,"mount",T=>{this._tiptapEditor.mount({mount:T})}),he(this,"unmount",()=>{this._tiptapEditor.unmount()}),this.options=e,this.dictionary=e.dictionary||BU,this.settings={tables:{splitCells:((n=e?.tables)==null?void 0:n.splitCells)??!1,cellBackgroundColor:((r=e?.tables)==null?void 0:r.cellBackgroundColor)??!1,cellTextColor:((i=e?.tables)==null?void 0:i.cellTextColor)??!1,headers:((s=e?.tables)==null?void 0:s.headers)??!1}};const h={defaultStyles:!0,schema:e.schema||vU.create(),...e,placeholders:{...this.dictionary.placeholders,...e.placeholders}};if(this.schema=h.schema,this.blockImplementations=h.schema.blockSpecs,this.inlineContentImplementations=h.schema.inlineContentSpecs,this.styleImplementations=h.schema.styleSpecs,h.uploadFile){const T=h.uploadFile;this.uploadFile=async(S,D)=>{this.onUploadStartCallbacks.forEach(I=>I.apply(this,[D]));try{return await T(S,D)}finally{this.onUploadEndCallbacks.forEach(I=>I.apply(this,[D]))}}}this.resolveFileUrl=h.resolveFileUrl,this._eventManager=new uV(this),this._extensionManager=new oj(this,h);const f=this._extensionManager.getTiptapExtensions(),p=this._extensionManager.hasExtension("ySync")||this._extensionManager.hasExtension("liveblocksExtension");p&&h.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const g={...kj,...h._tiptapOptions,element:null,autofocus:h.autofocus??!1,extensions:f,editorProps:{...(o=h._tiptapOptions)==null?void 0:o.editorProps,attributes:{tabIndex:"0",...(l=(a=h._tiptapOptions)==null?void 0:a.editorProps)==null?void 0:l.attributes,...(c=h.domAttributes)==null?void 0:c.editor,class:Ur("bn-editor",h.defaultStyles?"bn-default-styles":"",((d=(u=h.domAttributes)==null?void 0:u.editor)==null?void 0:d.class)||"")},transformPasted:yj}};try{const T=h.initialContent||(p?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:Kc.options.generateID()}]);if(!Array.isArray(T)||T.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+T);const S=Q_(g.extensions),D=T.map(A=>Ii(A,S,this.schema.styleSchema).toJSON()),I=vl({type:"doc",content:[{type:"blockGroup",content:D}]},S,g.parseOptions);this._tiptapEditor=new $N({...g,content:I.toJSON()}),this.pmSchema=this._tiptapEditor.schema}catch(T){throw new Error("Error creating document from blocks passed as `initialContent`",{cause:T})}let b;const y=this.pmSchema.nodes.doc.createAndFill;this.pmSchema.nodes.doc.createAndFill=(...T)=>{if(b)return b;const S=y.apply(this.pmSchema.nodes.doc,T),D=JSON.parse(JSON.stringify(S.toJSON()));return D.content[0].content[0].attrs.id="initialBlockId",b=Zt.fromJSON(this.pmSchema,D),b},this.pmSchema.cached.blockNoteEditor=this,this._blockManager=new cV(this),this._exportManager=new kV(this),this._selectionManager=new hj(this),this._stateManager=new fj(this),this._styleManager=new mj(this),this.emit("create")}static create(e){return new zw(e??{})}get extensions(){return this._extensionManager.getExtensions()}exec(e){return this._stateManager.exec(e)}canExec(e){return this._stateManager.canExec(e)}transact(e){return this._stateManager.transact(e)}get prosemirrorState(){return this._stateManager.prosemirrorState}get prosemirrorView(){return this._stateManager.prosemirrorView}get domElement(){var e;if(!this.headless)return(e=this.prosemirrorView)==null?void 0:e.dom}isFocused(){var e;return this.headless?!1:((e=this.prosemirrorView)==null?void 0:e.hasFocus())||!1}get headless(){return!this._tiptapEditor.isInitialized}focus(){this.headless||this.prosemirrorView.focus()}blur(){var e;this.headless||(e=this.domElement)==null||e.blur()}onUploadStart(e){return this.onUploadStartCallbacks.push(e),()=>{const n=this.onUploadStartCallbacks.indexOf(e);n>-1&&this.onUploadStartCallbacks.splice(n,1)}}onUploadEnd(e){return this.onUploadEndCallbacks.push(e),()=>{const n=this.onUploadEndCallbacks.indexOf(e);n>-1&&this.onUploadEndCallbacks.splice(n,1)}}get topLevelBlocks(){return this.document}get document(){return this._blockManager.document}getBlock(e){return this._blockManager.getBlock(e)}getPrevBlock(e){return this._blockManager.getPrevBlock(e)}getNextBlock(e){return this._blockManager.getNextBlock(e)}getParentBlock(e){return this._blockManager.getParentBlock(e)}forEachBlock(e,n=!1){this._blockManager.forEachBlock(e,n)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}onEditorSelectionChange(e){this._tiptapEditor.on("selectionUpdate",e)}onBeforeChange(e){return this._extensionManager.getExtension(ew).subscribe(e)}getTextCursorPosition(){return this._selectionManager.getTextCursorPosition()}setTextCursorPosition(e,n="start"){return this._selectionManager.setTextCursorPosition(e,n)}getSelection(){return this._selectionManager.getSelection()}getSelectionCutBlocks(e=!1){return this._selectionManager.getSelectionCutBlocks(e)}setSelection(e,n){return this._selectionManager.setSelection(e,n)}get isEditable(){return this._stateManager.isEditable}set isEditable(e){this._stateManager.isEditable=e}insertBlocks(e,n,r="before"){return this._blockManager.insertBlocks(e,n,r)}updateBlock(e,n){return this._blockManager.updateBlock(e,n)}removeBlocks(e){return this._blockManager.removeBlocks(e)}replaceBlocks(e,n){return this._blockManager.replaceBlocks(e,n)}undo(){return this._stateManager.undo()}redo(){return this._stateManager.redo()}insertInlineContent(e,{updateSelection:n=!1}={}){this._styleManager.insertInlineContent(e,{updateSelection:n})}getActiveStyles(){return this._styleManager.getActiveStyles()}addStyles(e){this._styleManager.addStyles(e)}removeStyles(e){this._styleManager.removeStyles(e)}toggleStyles(e){this._styleManager.toggleStyles(e)}getSelectedText(){return this._styleManager.getSelectedText()}getSelectedLinkUrl(){return this._styleManager.getSelectedLinkUrl()}createLink(e,n){this._styleManager.createLink(e,n)}canNestBlock(){return this._blockManager.canNestBlock()}nestBlock(){this._blockManager.nestBlock()}canUnnestBlock(){return this._blockManager.canUnnestBlock()}unnestBlock(){this._blockManager.unnestBlock()}moveBlocksUp(){return this._blockManager.moveBlocksUp()}moveBlocksDown(){return this._blockManager.moveBlocksDown()}blocksToHTMLLossy(e=this.document){return this._exportManager.blocksToHTMLLossy(e)}blocksToFullHTML(e=this.document){return this._exportManager.blocksToFullHTML(e)}tryParseHTMLToBlocks(e){return this._exportManager.tryParseHTMLToBlocks(e)}blocksToMarkdownLossy(e=this.document){return this._exportManager.blocksToMarkdownLossy(e)}tryParseMarkdownToBlocks(e){return this._exportManager.tryParseMarkdownToBlocks(e)}onChange(e,n){return this._eventManager.onChange(e,n)}onSelectionChange(e,n){return this._eventManager.onSelectionChange(e,n)}onMount(e){this._eventManager.onMount(e)}onUnmount(e){this._eventManager.onUnmount(e)}getSelectionBoundingBox(){return this._selectionManager.getSelectionBoundingBox()}get isEmpty(){const e=this.document;return e.length===0||e.length===1&&e[0].type==="paragraph"&&e[0].content.length===0}pasteHTML(e,n=!1){this._exportManager.pasteHTML(e,n)}pasteText(e){return this._exportManager.pasteText(e)}pasteMarkdown(e){return this._exportManager.pasteMarkdown(e)}}export{Jl as $,Bj as A,Pj as B,Qv as C,ce as D,tU as E,nU as F,Vt as G,Fj as H,Ir as I,Po as J,Uj as K,zw as L,Tn as M,xj as N,sh as O,me as P,Lp as Q,Lj as R,ih as S,v0 as T,qf as U,vU as V,$T as W,GL as X,Jv as Y,bn as Z,Rp as _,pe as a,Aj as a0,Ij as a1,gR as a2,zT as a3,te as b,T7 as c,Ee as d,aw as e,Mi as f,_h as g,Ll as h,Ur as i,Cn as j,Mj as k,Dj as l,sn as m,Rj as n,ye as o,Jh as p,wE as q,Ye as r,SU as s,dr as t,eU as u,yU as v,Qf as w,vj as x,Ie as y,Oj as z};
178
+ `}}),pf=(t,e)=>{const n=t.resolve(e),r=n.index();if(r===0)return;const i=n.posAtIndex(r-1);return Gc(t.resolve(i))},Uw=(t,e)=>{for(;e.childContainer;){const n=e.childContainer.node,r=t.resolve(e.childContainer.beforePos+1).posAtIndex(n.childCount-1);e=Gc(t.resolve(r))}return e},qV=(t,e)=>t.isBlockContainer&&t.blockContent.node.type.spec.content==="inline*"&&t.blockContent.node.childCount>0&&e.isBlockContainer&&e.blockContent.node.type.spec.content==="inline*",WV=(t,e,n,r)=>{if(!r.isBlockContainer)throw new Error(`Attempted to merge block at position ${r.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but next block is not a block container`);if(r.childContainer){const i=t.doc.resolve(r.childContainer.beforePos+1),s=t.doc.resolve(r.childContainer.afterPos-1),o=i.blockRange(s);if(e){const a=t.doc.resolve(r.bnBlock.beforePos);t.tr.lift(o,a.depth)}}if(e){if(!n.isBlockContainer)throw new Error(`Attempted to merge block at position ${r.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but previous block is not a block container`);e(t.tr.delete(n.blockContent.afterPos-1,r.blockContent.beforePos+1))}return!0},I1=t=>({state:e,dispatch:n})=>{const r=e.doc.resolve(t),i=Gc(r),s=pf(e.doc,i.bnBlock.beforePos);if(!s)return!1;const o=Uw(e.doc,s);return qV(o,i)?WV(e,n,o,i):!1},YV=Le.create({priority:50,addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({chain:r,commands:i})=>[()=>i.deleteSelection(),()=>i.undoInputRule(),()=>i.command(({state:s})=>{const o=xt(s);if(!o.isBlockContainer)return!1;const a=s.selection.from===o.blockContent.beforePos+1,l=o.blockContent.node.type.name==="paragraph";return a&&!l?i.command(iL(o.bnBlock.beforePos,{type:"paragraph",props:{}})):!1}),()=>i.command(({state:s})=>{const o=xt(s);if(!o.isBlockContainer)return!1;const{blockContent:a}=o;return s.selection.from===a.beforePos+1?i.liftListItem("blockContainer"):!1}),()=>i.command(({state:s})=>{const o=xt(s);if(!o.isBlockContainer)return!1;const{bnBlock:a,blockContent:l}=o,c=s.selection.from===l.beforePos+1,u=s.selection.empty,d=a.beforePos;return c&&u?r().command(I1(d)).scrollIntoView().run():!1}),()=>i.command(({state:s,tr:o,dispatch:a})=>{const l=xt(s);if(!l.isBlockContainer||o.selection.from!==l.blockContent.beforePos+1)return!1;const c=o.doc.resolve(l.bnBlock.beforePos);if(c.nodeBefore||c.node().type.name!=="column")return!1;const u=o.doc.resolve(l.bnBlock.beforePos),d=o.doc.resolve(u.before()),h=d.before();if(a){const f=o.doc.slice(l.bnBlock.beforePos,l.bnBlock.afterPos).content;o.delete(l.bnBlock.beforePos,l.bnBlock.afterPos),d.index()===0?(hf(o,h),o.insert(h,f),o.setSelection(j.near(o.doc.resolve(h)))):(o.insert(d.pos-1,f),o.setSelection(j.near(o.doc.resolve(d.pos-1))),hf(o,h))}return!0}),()=>i.command(({state:s})=>{const o=xt(s);if(!o.isBlockContainer)return!1;if(o.blockContent.node.childCount===0&&o.blockContent.node.type.spec.content==="inline*"){const a=pf(s.doc,o.bnBlock.beforePos);if(!a||!a.isBlockContainer)return!1;let l=r();if(a.blockContent.node.type.spec.content==="tableRow+"){const c=o.bnBlock.beforePos-1-1-1-1-1;l=l.setTextSelection(c)}else if(a.blockContent.node.type.spec.content===""){const c=a.blockContent.afterPos-a.blockContent.node.nodeSize;l=l.setNodeSelection(c)}else{const c=a.blockContent.afterPos-a.blockContent.node.nodeSize;l=l.setTextSelection(c)}return l.deleteRange({from:o.bnBlock.beforePos,to:o.bnBlock.afterPos}).scrollIntoView().run()}return!1}),()=>i.command(({state:s})=>{const o=xt(s);if(!o.isBlockContainer)throw new Error("todo");const a=s.selection.from===o.blockContent.beforePos+1,l=s.selection.empty,c=pf(s.doc,o.bnBlock.beforePos);if(c&&a&&l){const u=Uw(s.doc,c);if(!u.isBlockContainer)throw new Error("todo");if(u.blockContent.node.type.spec.content===""||u.blockContent.node.type.spec.content==="inline*"&&u.blockContent.node.childCount===0)return r().cut({from:o.bnBlock.beforePos,to:o.bnBlock.afterPos},u.bnBlock.afterPos).deleteRange({from:u.bnBlock.beforePos,to:u.bnBlock.afterPos}).run()}return!1})]),e=()=>this.editor.commands.first(({commands:r})=>[()=>r.deleteSelection(),()=>r.command(({state:i})=>{const s=xt(i);if(!s.isBlockContainer)return!1;const{bnBlock:o,blockContent:a,childContainer:l}=s,{depth:c}=i.doc.resolve(o.beforePos),u=o.afterPos===i.doc.nodeSize-3,d=i.selection.from===a.afterPos-1,h=i.selection.empty;if(!u&&d&&h&&l===void 0){let f=c,p=o.afterPos+1,g=i.doc.resolve(p).depth;for(;g<f;)f=g,p+=2,g=i.doc.resolve(p).depth;return r.command(I1(p-1))}return!1})]),n=(r=!1)=>this.editor.commands.first(({commands:i,tr:s})=>[()=>i.command(({state:o})=>{const a=xt(o);if(!a.isBlockContainer)return!1;const{bnBlock:l,blockContent:c}=a,{depth:u}=o.doc.resolve(l.beforePos),d=o.selection.$anchor.parentOffset===0,h=o.selection.anchor===o.selection.head,f=c.node.childCount===0,p=u>1;return d&&h&&f&&p?i.liftListItem("blockContainer"):!1}),()=>i.command(({state:o})=>{var a;const l=xt(o),c=((a=this.options.editor.schema.blockSchema[l.blockNoteType].meta)==null?void 0:a.hardBreakShortcut)??"shift+enter";if(c==="none")return!1;if(c==="shift+enter"&&r||c==="enter"){const u=s.storedMarks||s.selection.$head.marks().filter(d=>this.editor.extensionManager.splittableMarks.includes(d.type.name));return s.insert(s.selection.head,s.doc.type.schema.nodes.hardBreak.create()).ensureMarks(u),!0}return!1}),()=>i.command(({state:o,dispatch:a})=>{const l=xt(o);if(!l.isBlockContainer)return!1;const{bnBlock:c,blockContent:u}=l,d=o.selection.$anchor.parentOffset===0,h=o.selection.anchor===o.selection.head,f=u.node.childCount===0;if(d&&h&&f){const p=c.afterPos,g=p+2;if(a){const b=o.schema.nodes.blockContainer.createAndFill();o.tr.insert(p,b).scrollIntoView(),o.tr.setSelection(new j(o.doc.resolve(g)))}return!0}return!1}),()=>i.command(({state:o,chain:a})=>{const l=xt(o);if(!l.isBlockContainer)return!1;const{blockContent:c}=l,u=o.selection.$anchor.parentOffset===0;return c.node.childCount===0?!1:(a().deleteSelection().command(FL(o.selection.from,u,u)).run(),!0)})]);return{Backspace:t,Delete:e,Enter:()=>n(),"Shift-Enter":()=>n(!0),Tab:()=>{var r,i;return this.options.tabBehavior!=="prefer-indent"&&((r=this.options.editor.getExtension(Jh))!=null&&r.store.state||((i=this.options.editor.getExtension(Ir))==null?void 0:i.store.state)!==void 0)?!1:Rw(this.options.editor)},"Shift-Tab":()=>{var r,i;return this.options.tabBehavior!=="prefer-indent"&&((r=this.options.editor.getExtension(Jh))!=null&&r.store.state||((i=this.options.editor.getExtension(Ir))==null?void 0:i.store.state)!==void 0)?!1:this.editor.commands.liftListItem("blockContainer")},"Shift-Mod-ArrowUp":()=>(this.options.editor.moveBlocksUp(),!0),"Shift-Mod-ArrowDown":()=>(this.options.editor.moveBlocksDown(),!0),"Mod-z":()=>this.options.editor.undo(),"Mod-y":()=>this.options.editor.redo(),"Shift-Mod-z":()=>this.options.editor.redo()}}}),KV=Tn.create({name:"insertion",inclusive:!1,excludes:"deletion modification insertion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(t){return t.name!=="insertion"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(e,n){return["ins",{"data-id":String(e.attrs.id),"data-inline":String(n),...!n&&{style:"display: contents"}},0]},parseDOM:[{tag:"ins",getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10)}:!1}}]}}}),GV=Tn.create({name:"deletion",inclusive:!1,excludes:"insertion modification deletion",addAttributes(){return{id:{default:null,validate:"number"}}},extendMarkSchema(t){return t.name!=="deletion"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(e,n){return["del",{"data-id":String(e.attrs.id),"data-inline":String(n),...!n&&{style:"display: contents"}},0]},parseDOM:[{tag:"del",getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10)}:!1}}]}}}),QV=Tn.create({name:"modification",inclusive:!1,excludes:"deletion insertion",addAttributes(){return{id:{default:null,validate:"number"},type:{validate:"string"},attrName:{default:null,validate:"string|null"},previousValue:{default:null},newValue:{default:null}}},extendMarkSchema(t){return t.name!=="modification"?{}:{blocknoteIgnore:!0,inclusive:!1,toDOM(e,n){return[n?"span":"div",{"data-type":"modification","data-id":String(e.attrs.id),"data-mod-type":e.attrs.type,"data-mod-prev-val":JSON.stringify(e.attrs.previousValue),"data-mod-new-val":JSON.stringify(e.attrs.newValue)},0]},parseDOM:[{tag:"span[data-type='modification']",getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal,newValue:e.dataset.modNewVal}:!1}},{tag:"div[data-type='modification']",getAttrs(e){return e.dataset.id?{id:parseInt(e.dataset.id,10),type:e.dataset.modType,previousValue:e.dataset.modPrevVal}:!1}}]}}}),JV=Le.create({name:"textAlignment",addGlobalAttributes(){return[{types:["tableCell","tableHeader"],attributes:{textAlignment:{default:"left",parseHTML:t=>t.getAttribute("data-text-alignment"),renderHTML:t=>t.textAlignment==="left"?{}:{"data-text-alignment":t.textAlignment}}}}]}}),XV=Le.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["table","tableCell","tableHeader"],attributes:{textColor:uL()}}]}}),ZV={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},ej=Cn.create({name:"blockContainer",group:"blockGroupChild bnBlock",content:"blockContent blockGroup?",priority:50,defining:!0,marks:"insertion modification deletion",parseHTML(){return[{tag:"div[data-node-type="+this.name+"]",getAttrs:t=>{if(typeof t=="string")return!1;const e={};for(const[n,r]of Object.entries(ZV))t.getAttribute(r)&&(e[n]=t.getAttribute(r));return e}},{tag:'div[data-node-type="blockOuter"]',skip:!0}]},renderHTML({HTMLAttributes:t}){var e;const n=document.createElement("div");n.className="bn-block-outer",n.setAttribute("data-node-type","blockOuter");for(const[s,o]of Object.entries(t))s!=="class"&&n.setAttribute(s,o);const r={...((e=this.options.domAttributes)==null?void 0:e.block)||{},...t},i=document.createElement("div");i.className=Ur("bn-block",r.class),i.setAttribute("data-node-type",this.name);for(const[s,o]of Object.entries(r))s!=="class"&&i.setAttribute(s,o);return n.appendChild(i),{dom:n,contentDOM:i}}}),tj=Cn.create({name:"blockGroup",group:"childContainer",content:"blockGroupChild+",marks:"deletion insertion modification",parseHTML(){return[{tag:"div",getAttrs:t=>typeof t=="string"?!1:t.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:t}){var e;const n={...((e=this.options.domAttributes)==null?void 0:e.blockGroup)||{},...t},r=document.createElement("div");r.className=Ur("bn-block-group",n.class),r.setAttribute("data-node-type","blockGroup");for(const[i,s]of Object.entries(n))i!=="class"&&r.setAttribute(i,s);return{dom:r,contentDOM:r}}}),nj=Cn.create({name:"doc",topNode:!0,content:"blockGroup",marks:"insertion modification deletion"}),rj=pe(({options:t})=>({key:"collaboration",blockNoteExtensions:[KH(t),Qh(t),yl(t),El(),JH(t)]}));let O1=!1;function ij(t,e){const n=[Wi.ClipboardTextSerializer,Wi.Commands,Wi.Editable,Wi.FocusEvents,Wi.Tabindex,KU,Kc.configure({types:["blockContainer","columnList","column"],setIdAttribute:e.setIdAttribute}),jV,k7,KV,GV,QV,E7.extend({inclusive:!1}).configure({defaultProtocol:nU,protocols:O1?[]:tU}),...Object.values(t.schema.styleSpecs).map(r=>r.implementation.mark.configure({editor:t})),XV,VV,JV,Le.create({name:"OverrideEscape",addKeyboardShortcuts:()=>({Escape:()=>{var r;return(r=t.getExtension(Rp))!=null&&r.shown()?!1:(t.blur(),!0)}})}),nj,ej.configure({editor:t,domAttributes:e.domAttributes}),YV.configure({editor:t,tabBehavior:e.tabBehavior}),tj.configure({domAttributes:e.domAttributes}),...Object.values(t.schema.inlineContentSpecs).filter(r=>r.config!=="link"&&r.config!=="text").map(r=>r.implementation.node.configure({editor:t})),...Object.values(t.schema.blockSpecs).flatMap(r=>[..."node"in r.implementation?[r.implementation.node.configure({editor:t,domAttributes:e.domAttributes})]:[]]),zV(t),UV(t,e.pasteHandler||(r=>r.defaultPasteHandler())),SV(t)];return O1=!0,n}function sj(t,e){const n=[ew(),XH(e),Ir(e),Jh(e),eU(e),iU(),oU(e),T7(e),yU(e),Rp(e),...e.trailingBlock!==!1?[wU()]:[]];return e.collaboration?n.push(rj(e.collaboration)):n.push(ZH()),"table"in t.schema.blockSpecs&&n.push(SU(e)),e.animations!==!1&&n.push(lU()),n}class oj{constructor(e,n){he(this,"disabledExtensions",new Set),he(this,"extensions",[]),he(this,"abortMap",new Map),he(this,"extensionFactories",new Map),he(this,"extensionPlugins",new Map),this.editor=e,this.options=n,e.onMount(()=>{for(const r of this.extensions)if(r.mount){const i=new window.AbortController,s=r.mount({dom:e.prosemirrorView.dom,root:e.prosemirrorView.root,signal:i.signal});s&&i.signal.addEventListener("abort",()=>{s()}),this.abortMap.set(r,i)}}),e.onUnmount(()=>{for(const[r,i]of this.abortMap.entries())this.abortMap.delete(r),i.abort()}),this.disabledExtensions=new Set(n.disableExtensions||[]);for(const r of sj(this.editor,this.options))this.addExtension(r);for(const r of this.options.extensions??[])this.addExtension(r);for(const r of Object.values(this.editor.schema.blockSpecs))for(const i of r.extensions??[])this.addExtension(i)}registerExtension(e){var n;const r=[].concat(e).filter(Boolean);if(!r.length){console.warn("No extensions found to register",e);return}const i=r.map(o=>this.addExtension(o)).filter(Boolean),s=new Set;for(const o of i)o!=null&&o.tiptapExtensions&&console.warn(`Extension ${o.key} has tiptap extensions, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`,o),(n=o?.inputRules)!=null&&n.length&&console.warn(`Extension ${o.key} has input rules, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`,o),this.getProsemirrorPluginsFromExtension(o).plugins.forEach(a=>{s.add(a)});this.updatePlugins(o=>[...o,...s])}addExtension(e){let n;if(typeof e=="function"?n=e({editor:this.editor}):n=e,!(!n||this.disabledExtensions.has(n.key))){if(typeof e=="function"){const r=n[Dh];typeof r=="function"&&this.extensionFactories.set(r,n)}if(this.extensions.push(n),n.blockNoteExtensions)for(const r of n.blockNoteExtensions)this.addExtension(r);return n}}resolveExtensions(e){const n=[];if(typeof e=="function"){const r=this.extensionFactories.get(e);r&&n.push(r)}else if(Array.isArray(e))for(const r of e)n.push(...this.resolveExtensions(r));else if(typeof e=="object"&&"key"in e)n.push(e);else if(typeof e=="string"){const r=this.extensions.find(i=>i.key===e);r&&n.push(r)}return n}unregisterExtension(e){var n;const r=this.resolveExtensions(e);if(!r.length){console.warn("No extensions found to unregister",e);return}let i=!1;const s=new Set;for(const o of r){this.extensions=this.extensions.filter(l=>l!==o),this.extensionFactories.forEach((l,c)=>{l===o&&this.extensionFactories.delete(c)}),(n=this.abortMap.get(o))==null||n.abort(),this.abortMap.delete(o);const a=this.extensionPlugins.get(o);a?.forEach(l=>{s.add(l)}),this.extensionPlugins.delete(o),o.tiptapExtensions&&!i&&(i=!0,console.warn(`Extension ${o.key} has tiptap extensions, but they will not be removed. Please separate the extension into multiple extensions if you want to remove them, or re-initialize the editor.`,e))}this.updatePlugins(o=>o.filter(a=>!s.has(a)))}updatePlugins(e){const n=this.editor.prosemirrorState,r=n.reconfigure({plugins:e(n.plugins.slice())});this.editor.prosemirrorView.updateState(r)}getTiptapExtensions(){var e;const n=ij(this.editor,this.options).filter(s=>!this.disabledExtensions.has(s.name)),r=sw(this.extensions),i=new Map;for(const s of this.extensions){s.tiptapExtensions&&n.push(...s.tiptapExtensions);const o=r(s.key),{plugins:a,inputRules:l}=this.getProsemirrorPluginsFromExtension(s);a.length&&n.push(Le.create({name:s.key,priority:o,addProseMirrorPlugins:()=>a})),l.length&&(i.has(o)||i.set(o,[]),i.get(o).push(...l))}n.push(Le.create({name:"blocknote-input-rules",addProseMirrorPlugins(){const s=[];return Array.from(i.keys()).sort().reverse().forEach(o=>{s.push(...i.get(o))}),[UU({rules:s})]}}));for(const s of((e=this.options._tiptapOptions)==null?void 0:e.extensions)??[])n.push(s);return n}getProsemirrorPluginsFromExtension(e){var n,r,i;const s=[...e.prosemirrorPlugins??[]],o=[];return!((n=e.prosemirrorPlugins)!=null&&n.length)&&!Object.keys(e.keyboardShortcuts||{}).length&&!((r=e.inputRules)!=null&&r.length)?{plugins:s,inputRules:o}:(this.extensionPlugins.set(e,s),(i=e.inputRules)!=null&&i.length&&o.push(...e.inputRules.map(a=>new Ri(a.find,(l,c,u,d)=>{const h=a.replace({match:c,range:{from:u,to:d},editor:this.editor});if(h){const f=this.editor.getTextCursorPosition();if(this.editor.schema.blockSchema[f.block.type].content!=="inline")return null;const p=sa(l.tr),g=l.tr.deleteRange(u,d);return uu(g,p.bnBlock.beforePos,h),g}return null}))),Object.keys(e.keyboardShortcuts||{}).length&&s.push(oE(Object.fromEntries(Object.entries(e.keyboardShortcuts).map(([a,l])=>[a,()=>l({editor:this.editor})])))),{plugins:s,inputRules:o})}getExtensions(){return new Map(this.extensions.map(e=>[e.key,e]))}getExtension(e){if(typeof e=="string")return this.extensions.find(r=>r.key===e)||void 0;if(typeof e=="function")return this.extensionFactories.get(e)||void 0;throw new Error(`Invalid extension type: ${typeof e}`)}hasExtension(e){return typeof e=="string"?this.extensions.some(n=>n.key===e):typeof e=="object"&&"key"in e?this.extensions.some(n=>n.key===e.key):typeof e=="function"?this.extensionFactories.has(e):!1}}function aj(t,e){let{$from:n,$to:r}=e;if(n.pos>n.start()&&n.pos<t.content.size){const i=t.textBetween(n.pos,n.pos+1);if(/^[\w\p{P}]$/u.test(i)){const s=t.textBetween(n.start(),n.pos).match(/[\w\p{P}]+$/u);s&&(n=t.resolve(n.pos-s[0].length))}}if(r.pos<r.end()&&r.pos>0){const i=t.textBetween(r.pos-1,r.pos);if(/^[\w\p{P}]$/u.test(i)){const s=t.textBetween(r.pos,r.end()).match(/^[\w\p{P}]+/u);s&&(r=t.resolve(r.pos+s[0].length))}}return{$from:n,$to:r,from:n.pos,to:r.pos}}function lj(t){const e=He(t);if(t.selection.empty||"node"in t.selection)return;const n=t.doc.resolve(Rr(t.doc,t.selection.from).posBeforeNode),r=t.doc.resolve(Rr(t.doc,t.selection.to).posBeforeNode),i=(c,u)=>{const d=n.posAtIndex(c,u),h=t.doc.resolve(d).nodeAfter;if(!h)throw new Error(`Error getting selection - node not found at position ${d}`);return ve(h,e)},s=[],o=n.sharedDepth(r.pos),a=n.index(o),l=r.index(o);if(n.depth>o){s.push(ve(n.nodeAfter,e));for(let c=n.depth;c>o;c--)if(n.node(c).type.isInGroup("childContainer")){const u=n.index(c)+1,d=n.node(c).childCount;for(let h=u;h<d;h++)s.push(i(h,c))}}else s.push(i(a,o));for(let c=a+1;c<=l;c++)s.push(i(c,o));if(s.length===0)throw new Error(`Error getting selection - selection doesn't span any blocks (${t.selection})`);return{blocks:s}}function cj(t,e,n){const r=typeof e=="string"?e:e.id,i=typeof n=="string"?n:n.id,s=He(t),o=oa(s);if(r===i)throw new Error(`Attempting to set selection with the same anchor and head blocks (id ${r})`);const a=Vt(r,t.doc);if(!a)throw new Error(`Block with ID ${r} not found`);const l=Vt(i,t.doc);if(!l)throw new Error(`Block with ID ${i} not found`);const c=Pr(a),u=Pr(l),d=o.blockSchema[c.blockNoteType],h=o.blockSchema[u.blockNoteType];if(!c.isBlockContainer||d.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${r})`);if(!u.isBlockContainer||h.content==="none")throw new Error(`Attempting to set selection anchor in block without content (id ${i})`);let f,p;if(d.content==="table"){const g=Ae.get(c.blockContent.node);f=c.blockContent.beforePos+g.positionAt(0,0,c.blockContent.node)+1+2}else f=c.blockContent.beforePos+1;if(h.content==="table"){const g=Ae.get(u.blockContent.node),b=u.blockContent.beforePos+g.positionAt(g.height-1,g.width-1,u.blockContent.node)+1,y=t.doc.resolve(b).nodeAfter.nodeSize;p=b+y-2}else p=u.blockContent.afterPos-1;t.setSelection(j.create(t.doc,f,p))}function uj(t,e=!1){const n=He(t),r=e?aj(t.doc,t.selection):t.selection;let i=r.$from,s=r.$to;for(;s.parentOffset>=s.parent.nodeSize-2&&s.depth>0;)s=t.doc.resolve(s.pos+1);for(;s.parentOffset===0&&s.depth>0;)s=t.doc.resolve(s.pos-1);for(;i.parentOffset===0&&i.depth>0;)i=t.doc.resolve(i.pos-1);for(;i.parentOffset>=i.parent.nodeSize-2&&i.depth>0;)i=t.doc.resolve(i.pos+1);const o=sI(t.doc.slice(i.pos,s.pos,!0),n);return{_meta:{startPos:i.pos,endPos:s.pos},...o}}function dj(t){const{bnBlock:e}=sa(t),n=He(t.doc),r=t.doc.resolve(e.beforePos),i=r.nodeBefore,s=t.doc.resolve(e.afterPos).nodeAfter;let o;return r.depth>1&&(o=r.node(),o.type.isInGroup("bnBlock")||(o=r.node(r.depth-1))),{block:ve(e.node,n),prevBlock:i===null?void 0:ve(i,n),nextBlock:s===null?void 0:ve(s,n),parentBlock:o===void 0?void 0:ve(o,n)}}function $w(t,e,n="start"){const r=typeof e=="string"?e:e.id,i=He(t.doc),s=oa(i),o=Vt(r,t.doc);if(!o)throw new Error(`Block with ID ${r} not found`);const a=Pr(o),l=s.blockSchema[a.blockNoteType].content;if(a.isBlockContainer){const c=a.blockContent;if(l==="none"){t.setSelection(W.create(t.doc,c.beforePos));return}if(l==="inline")n==="start"?t.setSelection(j.create(t.doc,c.beforePos+1)):t.setSelection(j.create(t.doc,c.afterPos-1));else if(l==="table")n==="start"?t.setSelection(j.create(t.doc,c.beforePos+4)):t.setSelection(j.create(t.doc,c.afterPos-4));else throw new Pn(l)}else{const c=n==="start"?a.childContainer.node.firstChild:a.childContainer.node.lastChild;$w(t,c.attrs.id,n)}}class hj{constructor(e){this.editor=e}getSelection(){return this.editor.transact(e=>lj(e))}getSelectionCutBlocks(e=!1){return this.editor.transact(n=>uj(n,e))}setSelection(e,n){return this.editor.transact(r=>cj(r,e,n))}getTextCursorPosition(){return this.editor.transact(e=>dj(e))}setTextCursorPosition(e,n="start"){return this.editor.transact(r=>$w(r,e,n))}getSelectionBoundingBox(){if(!this.editor.prosemirrorView)return;const{selection:e}=this.editor.prosemirrorState,{ranges:n}=e,r=Math.min(...n.map(s=>s.$from.pos)),i=Math.max(...n.map(s=>s.$to.pos));if(rN(e)){const s=this.editor.prosemirrorView.nodeDOM(r);if(s)return s.getBoundingClientRect()}return wE(this.editor.prosemirrorView,r,i).toJSON()}}class fj{constructor(e){he(this,"activeTransaction",null),he(this,"isInCan",!1),this.editor=e}can(e){try{return this.isInCan=!0,e()}finally{this.isInCan=!1}}exec(e){if(this.activeTransaction)throw new Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");if(this.isInCan)return this.canExec(e);const n=this.prosemirrorState,r=this.prosemirrorView;return e(n,i=>this.prosemirrorView.dispatch(i),r)}canExec(e){if(this.activeTransaction)throw new Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");const n=this.prosemirrorState,r=this.prosemirrorView;return e(n,void 0,r)}transact(e){if(this.activeTransaction)return e(this.activeTransaction);try{this.activeTransaction=this.editor._tiptapEditor.state.tr;const n=e(this.activeTransaction),r=this.activeTransaction;return this.activeTransaction=null,r&&(r.docChanged||r.selectionSet||r.scrolledIntoView||r.storedMarksSet||!r.isGeneric)&&this.prosemirrorView.dispatch(r),n}finally{this.activeTransaction=null}}get prosemirrorState(){if(this.activeTransaction)throw new Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");return this.editor._tiptapEditor.state}get prosemirrorView(){return this.editor._tiptapEditor.view}isFocused(){var e;return((e=this.prosemirrorView)==null?void 0:e.hasFocus())||!1}focus(){var e;(e=this.prosemirrorView)==null||e.focus()}get isEditable(){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw new Error("no editor, but also not headless?");return!1}return this.editor._tiptapEditor.isEditable===void 0?!0:this.editor._tiptapEditor.isEditable}set isEditable(e){if(!this.editor._tiptapEditor){if(!this.editor.headless)throw new Error("no editor, but also not headless?");return}this.editor._tiptapEditor.options.editable!==e&&this.editor._tiptapEditor.setEditable(e)}undo(){const e=this.editor.getExtension("yUndo");if(e)return this.exec(e.undoCommand);const n=this.editor.getExtension("history");if(n)return this.exec(n.undoCommand);throw new Error("No undo plugin found")}redo(){const e=this.editor.getExtension("yUndo");if(e)return this.exec(e.redoCommand);const n=this.editor.getExtension("history");if(n)return this.exec(n.redoCommand);throw new Error("No redo plugin found")}}function pj(t,e,n,r={updateSelection:!0}){let{from:i,to:s}=typeof e=="number"?{from:e,to:e}:{from:e.from,to:e.to},o=!0,a=!0,l="";if(n.forEach(c=>{c.check(),o&&c.isText&&c.marks.length===0?l+=c.text:o=!1,a=a?c.isBlock:!1}),i===s&&a){const{parent:c}=t.doc.resolve(i);c.isTextblock&&!c.type.spec.code&&!c.childCount&&(i-=1,s+=1)}return o?t.insertText(l,i,s):t.replaceWith(i,s,n),r.updateSelection&&hE(t,t.steps.length-1,-1),!0}class mj{constructor(e){this.editor=e}insertInlineContent(e,{updateSelection:n=!1}={}){const r=bn(e,this.editor.pmSchema);this.editor.transact(i=>{pj(i,{from:i.selection.from,to:i.selection.to},r,{updateSelection:n})})}getActiveStyles(){return this.editor.transact(e=>{const n={},r=e.selection.$to.marks();for(const i of r){const s=this.editor.schema.styleSchema[i.type.name];if(!s){i.type.name!=="link"&&!i.type.spec.blocknoteIgnore&&console.warn("mark not found in styleschema",i.type.name);continue}s.propSchema==="boolean"?n[s.type]=!0:n[s.type]=i.attrs.stringValue}return n})}addStyles(e){for(const[n,r]of Object.entries(e)){const i=this.editor.schema.styleSchema[n];if(!i)throw new Error(`style ${n} not found in styleSchema`);if(i.propSchema==="boolean")this.editor._tiptapEditor.commands.setMark(n);else if(i.propSchema==="string")this.editor._tiptapEditor.commands.setMark(n,{stringValue:r});else throw new Pn(i.propSchema)}}removeStyles(e){for(const n of Object.keys(e))this.editor._tiptapEditor.commands.unsetMark(n)}toggleStyles(e){for(const[n,r]of Object.entries(e)){const i=this.editor.schema.styleSchema[n];if(!i)throw new Error(`style ${n} not found in styleSchema`);if(i.propSchema==="boolean")this.editor._tiptapEditor.commands.toggleMark(n);else if(i.propSchema==="string")this.editor._tiptapEditor.commands.toggleMark(n,{stringValue:r});else throw new Pn(i.propSchema)}}getSelectedText(){return this.editor.transact(e=>e.doc.textBetween(e.selection.from,e.selection.to))}getSelectedLinkUrl(){return this.editor._tiptapEditor.getAttributes("link").href}createLink(e,n){if(e==="")return;const r=this.editor.pmSchema.mark("link",{href:e});this.editor.transact(i=>{const{from:s,to:o}=i.selection;n?i.insertText(n,s,o).addMark(s,s+n.length,r):i.setSelection(j.create(i.doc,o)).addMark(s,o,r)})}}function gj(t,e){const n=[];return t.forEach((r,i,s)=>{s!==e&&n.push(r)}),M.from(n)}function bj(t,e){const n=[];for(let r=0;r<t.childCount;r++)if(t.child(r).type.name==="tableRow")if(n.length>0&&n[n.length-1].type.name==="table"){const i=n[n.length-1],s=i.copy(i.content.addToEnd(t.child(r)));n[n.length-1]=s}else{const i=e.nodes.table.createChecked(void 0,t.child(r));n.push(i)}else n.push(t.child(r));return t=M.from(n),t}function yj(t,e){let n=M.from(t.content);if(n=bj(n,e.state.schema),!Ej(n,e))return new F(n,t.openStart,t.openEnd);for(let r=0;r<n.childCount;r++)if(n.child(r).type.spec.group==="blockContent"){const i=[n.child(r)];if(r+1<n.childCount&&n.child(r+1).type.name==="blockGroup"){const o=n.child(r+1).child(0).child(0);(o.type.name==="bulletListItem"||o.type.name==="numberedListItem"||o.type.name==="checkListItem")&&(i.push(n.child(r+1)),n=gj(n,r+1))}const s=e.state.schema.nodes.blockContainer.createChecked(void 0,i);n=n.replaceChild(r,s)}return new F(n,t.openStart,t.openEnd)}function Ej(t,e){var n,r;const i=t.childCount===1,s=((n=t.firstChild)==null?void 0:n.type.spec.content)==="inline*",o=((r=t.firstChild)==null?void 0:r.type.spec.content)==="tableRow+";if(i){if(s)return!1;if(o){const a=xt(e.state);if(a.isBlockContainer)return a.blockContent.node.type.spec.content!=="tableRow+"}}return!0}const kj={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class zw extends aw{constructor(e){var n,r,i,s,o,a,l,c,u,d;super(),he(this,"pmSchema"),he(this,"_tiptapEditor"),he(this,"elementRenderer",null),he(this,"blockCache",new WeakMap),he(this,"dictionary"),he(this,"schema"),he(this,"blockImplementations"),he(this,"inlineContentImplementations"),he(this,"styleImplementations"),he(this,"uploadFile"),he(this,"onUploadStartCallbacks",[]),he(this,"onUploadEndCallbacks",[]),he(this,"resolveFileUrl"),he(this,"settings"),he(this,"_blockManager"),he(this,"_eventManager"),he(this,"_exportManager"),he(this,"_extensionManager"),he(this,"_selectionManager"),he(this,"_stateManager"),he(this,"_styleManager"),he(this,"unregisterExtension",(...T)=>this._extensionManager.unregisterExtension(...T)),he(this,"registerExtension",(...T)=>this._extensionManager.registerExtension(...T)),he(this,"getExtension",(...T)=>this._extensionManager.getExtension(...T)),he(this,"mount",T=>{this._tiptapEditor.mount({mount:T})}),he(this,"unmount",()=>{this._tiptapEditor.unmount()}),this.options=e,this.dictionary=e.dictionary||BU,this.settings={tables:{splitCells:((n=e?.tables)==null?void 0:n.splitCells)??!1,cellBackgroundColor:((r=e?.tables)==null?void 0:r.cellBackgroundColor)??!1,cellTextColor:((i=e?.tables)==null?void 0:i.cellTextColor)??!1,headers:((s=e?.tables)==null?void 0:s.headers)??!1}};const h={defaultStyles:!0,schema:e.schema||vU.create(),...e,placeholders:{...this.dictionary.placeholders,...e.placeholders}};if(this.schema=h.schema,this.blockImplementations=h.schema.blockSpecs,this.inlineContentImplementations=h.schema.inlineContentSpecs,this.styleImplementations=h.schema.styleSpecs,h.uploadFile){const T=h.uploadFile;this.uploadFile=async(S,D)=>{this.onUploadStartCallbacks.forEach(I=>I.apply(this,[D]));try{return await T(S,D)}finally{this.onUploadEndCallbacks.forEach(I=>I.apply(this,[D]))}}}this.resolveFileUrl=h.resolveFileUrl,this._eventManager=new uV(this),this._extensionManager=new oj(this,h);const f=this._extensionManager.getTiptapExtensions(),p=this._extensionManager.hasExtension("ySync")||this._extensionManager.hasExtension("liveblocksExtension");p&&h.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const g={...kj,...h._tiptapOptions,element:null,autofocus:h.autofocus??!1,extensions:f,editorProps:{...(o=h._tiptapOptions)==null?void 0:o.editorProps,attributes:{tabIndex:"0",...(l=(a=h._tiptapOptions)==null?void 0:a.editorProps)==null?void 0:l.attributes,...(c=h.domAttributes)==null?void 0:c.editor,class:Ur("bn-editor",h.defaultStyles?"bn-default-styles":"",((d=(u=h.domAttributes)==null?void 0:u.editor)==null?void 0:d.class)||"")},transformPasted:yj}};try{const T=h.initialContent||(p?[{type:"paragraph",id:"initialBlockId"}]:[{type:"paragraph",id:Kc.options.generateID()}]);if(!Array.isArray(T)||T.length===0)throw new Error("initialContent must be a non-empty array of blocks, received: "+T);const S=Q_(g.extensions),D=T.map(A=>Ii(A,S,this.schema.styleSchema).toJSON()),I=vl({type:"doc",content:[{type:"blockGroup",content:D}]},S,g.parseOptions);this._tiptapEditor=new $N({...g,content:I.toJSON()}),this.pmSchema=this._tiptapEditor.schema}catch(T){throw new Error("Error creating document from blocks passed as `initialContent`",{cause:T})}let b;const y=this.pmSchema.nodes.doc.createAndFill;this.pmSchema.nodes.doc.createAndFill=(...T)=>{if(b)return b;const S=y.apply(this.pmSchema.nodes.doc,T),D=JSON.parse(JSON.stringify(S.toJSON()));return D.content[0].content[0].attrs.id="initialBlockId",b=Zt.fromJSON(this.pmSchema,D),b},this.pmSchema.cached.blockNoteEditor=this,this._blockManager=new cV(this),this._exportManager=new kV(this),this._selectionManager=new hj(this),this._stateManager=new fj(this),this._styleManager=new mj(this),this.emit("create")}static create(e){return new zw(e??{})}get extensions(){return this._extensionManager.getExtensions()}exec(e){return this._stateManager.exec(e)}canExec(e){return this._stateManager.canExec(e)}transact(e){return this._stateManager.transact(e)}get prosemirrorState(){return this._stateManager.prosemirrorState}get prosemirrorView(){return this._stateManager.prosemirrorView}get domElement(){var e;if(!this.headless)return(e=this.prosemirrorView)==null?void 0:e.dom}isFocused(){var e;return this.headless?!1:((e=this.prosemirrorView)==null?void 0:e.hasFocus())||!1}get headless(){return!this._tiptapEditor.isInitialized}focus(){this.headless||this.prosemirrorView.focus()}blur(){var e;this.headless||(e=this.domElement)==null||e.blur()}onUploadStart(e){return this.onUploadStartCallbacks.push(e),()=>{const n=this.onUploadStartCallbacks.indexOf(e);n>-1&&this.onUploadStartCallbacks.splice(n,1)}}onUploadEnd(e){return this.onUploadEndCallbacks.push(e),()=>{const n=this.onUploadEndCallbacks.indexOf(e);n>-1&&this.onUploadEndCallbacks.splice(n,1)}}get topLevelBlocks(){return this.document}get document(){return this._blockManager.document}getBlock(e){return this._blockManager.getBlock(e)}getPrevBlock(e){return this._blockManager.getPrevBlock(e)}getNextBlock(e){return this._blockManager.getNextBlock(e)}getParentBlock(e){return this._blockManager.getParentBlock(e)}forEachBlock(e,n=!1){this._blockManager.forEachBlock(e,n)}onEditorContentChange(e){this._tiptapEditor.on("update",e)}onEditorSelectionChange(e){this._tiptapEditor.on("selectionUpdate",e)}onBeforeChange(e){return this._extensionManager.getExtension(ew).subscribe(e)}getTextCursorPosition(){return this._selectionManager.getTextCursorPosition()}setTextCursorPosition(e,n="start"){return this._selectionManager.setTextCursorPosition(e,n)}getSelection(){return this._selectionManager.getSelection()}getSelectionCutBlocks(e=!1){return this._selectionManager.getSelectionCutBlocks(e)}setSelection(e,n){return this._selectionManager.setSelection(e,n)}get isEditable(){return this._stateManager.isEditable}set isEditable(e){this._stateManager.isEditable=e}insertBlocks(e,n,r="before"){return this._blockManager.insertBlocks(e,n,r)}updateBlock(e,n){return this._blockManager.updateBlock(e,n)}removeBlocks(e){return this._blockManager.removeBlocks(e)}replaceBlocks(e,n){return this._blockManager.replaceBlocks(e,n)}undo(){return this._stateManager.undo()}redo(){return this._stateManager.redo()}insertInlineContent(e,{updateSelection:n=!1}={}){this._styleManager.insertInlineContent(e,{updateSelection:n})}getActiveStyles(){return this._styleManager.getActiveStyles()}addStyles(e){this._styleManager.addStyles(e)}removeStyles(e){this._styleManager.removeStyles(e)}toggleStyles(e){this._styleManager.toggleStyles(e)}getSelectedText(){return this._styleManager.getSelectedText()}getSelectedLinkUrl(){return this._styleManager.getSelectedLinkUrl()}createLink(e,n){this._styleManager.createLink(e,n)}canNestBlock(){return this._blockManager.canNestBlock()}nestBlock(){this._blockManager.nestBlock()}canUnnestBlock(){return this._blockManager.canUnnestBlock()}unnestBlock(){this._blockManager.unnestBlock()}moveBlocksUp(){return this._blockManager.moveBlocksUp()}moveBlocksDown(){return this._blockManager.moveBlocksDown()}blocksToHTMLLossy(e=this.document){return this._exportManager.blocksToHTMLLossy(e)}blocksToFullHTML(e=this.document){return this._exportManager.blocksToFullHTML(e)}tryParseHTMLToBlocks(e){return this._exportManager.tryParseHTMLToBlocks(e)}blocksToMarkdownLossy(e=this.document){return this._exportManager.blocksToMarkdownLossy(e)}tryParseMarkdownToBlocks(e){return this._exportManager.tryParseMarkdownToBlocks(e)}onChange(e,n){return this._eventManager.onChange(e,n)}onSelectionChange(e,n){return this._eventManager.onSelectionChange(e,n)}onMount(e){this._eventManager.onMount(e)}onUnmount(e){this._eventManager.onUnmount(e)}getSelectionBoundingBox(){return this._selectionManager.getSelectionBoundingBox()}get isEmpty(){const e=this.document;return e.length===0||e.length===1&&e[0].type==="paragraph"&&e[0].content.length===0}pasteHTML(e,n=!1){this._exportManager.pasteHTML(e,n)}pasteText(e){return this._exportManager.pasteText(e)}pasteMarkdown(e){return this._exportManager.pasteMarkdown(e)}}export{vj as $,Bj as A,Pj as B,tU as C,ce as D,Lj as E,vU as F,$T as G,Fj as H,Ir as I,GL as J,Jv as K,zw as L,Tn as M,xj as N,Jl as O,me as P,Cn as Q,qf as R,ih as S,v0 as T,bn as U,Qf as V,Mj as W,Uj as X,Dj as Y,Qv as Z,Rp as _,pe as a,Aj as a0,Ij as a1,gR as a2,zT as a3,te as b,T7 as c,Ee as d,aw as e,Mi as f,_h as g,Ll as h,Ur as i,Rj as j,ye as k,Jh as l,sn as m,Ye as n,SU as o,wE as p,dr as q,eU as r,yU as s,Oj as t,nU as u,Vt as v,Po as w,sh as x,Ie as y,Lp as z};