@panphora/clayjs 1.25.0 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/dist/all.js +1 -1
  2. package/dist/clay-dom.js +1 -1
  3. package/dist/clay-events.js +1 -1
  4. package/dist/clay-internals.js +1 -1
  5. package/dist/clay-options.js +1 -1
  6. package/dist/clay-router.js +1 -1
  7. package/dist/clay-ui.js +1 -1
  8. package/dist/clay-utils.js +1 -1
  9. package/dist/clay.js +1 -1
  10. package/dist/clay.standalone.js +5570 -4173
  11. package/dist/m/attrs/{save-freeze-MH3AOD56.js → save-freeze-PUYX32AK.js} +1 -1
  12. package/dist/m/{c-BOMQIQ3V.js → c-2EFMJYGJ.js} +1 -1
  13. package/dist/m/c-2EPHRF47.js +1 -0
  14. package/dist/m/{c-JD2VFAYG.js → c-2SUFMUZX.js} +2 -2
  15. package/dist/m/{c-CITLTVQ4.js → c-2TJCFPX4.js} +1 -1
  16. package/dist/m/c-33SS5A4Y.js +1 -0
  17. package/dist/m/{c-V2FPBRO6.js → c-34J5HC7N.js} +1 -1
  18. package/dist/m/c-3F3AADKG.js +1 -0
  19. package/dist/m/{c-TCFVG3I4.js → c-3S3647J6.js} +1 -1
  20. package/dist/m/{c-GY4BREDT.js → c-3S5TNRZA.js} +1 -1
  21. package/dist/m/{c-GDNZEOOZ.js → c-3WX5FABT.js} +1 -1
  22. package/dist/m/{c-AI3H6ETU.js → c-3XGLJAS7.js} +2 -2
  23. package/dist/m/c-42WBOKFM.js +1 -0
  24. package/dist/m/c-47M4QHCK.js +1 -0
  25. package/dist/m/{c-UOUUI265.js → c-4M2T676V.js} +1 -1
  26. package/dist/m/{c-GEAG5XAK.js → c-4TP3UXBT.js} +1 -1
  27. package/dist/m/{c-IESDKFO6.js → c-5ELELG2F.js} +1 -1
  28. package/dist/m/{c-X3V4RWMA.js → c-5ZYLTN3Q.js} +1 -1
  29. package/dist/m/{c-5PZYDWTW.js → c-67TBU56I.js} +1 -1
  30. package/dist/m/{c-WNOLMHI2.js → c-6BGJAJ67.js} +1 -1
  31. package/dist/m/{c-4Q6QIODW.js → c-755ZOHOM.js} +1 -1
  32. package/dist/m/c-7Q4XYDF4.js +1 -0
  33. package/dist/m/c-7RHOMAMR.js +1 -0
  34. package/dist/m/c-A5LASUEZ.js +1 -0
  35. package/dist/m/{c-IL5IVTOG.js → c-ABOBD7F3.js} +1 -1
  36. package/dist/m/c-AQVQKFKB.js +1 -0
  37. package/dist/m/{c-QDVG4NAZ.js → c-ARO6CPMA.js} +1 -1
  38. package/dist/m/{c-ORLPQFNU.js → c-AZM34SPO.js} +1 -1
  39. package/dist/m/{c-XUZMRQ7O.js → c-BCS3AZQZ.js} +1 -1
  40. package/dist/m/c-BOS7GONO.js +1 -0
  41. package/dist/m/{c-SUAC5RSG.js → c-C5UGNOC2.js} +1 -1
  42. package/dist/m/c-C6DXZIXD.js +1 -0
  43. package/dist/m/{c-WSTUCBHV.js → c-CPRGR2II.js} +1 -1
  44. package/dist/m/{c-NICICT4P.js → c-DEYHCYJB.js} +1 -1
  45. package/dist/m/{c-WGQVSKKC.js → c-DYTBSJBI.js} +1 -1
  46. package/dist/m/{c-DT7E76Z2.js → c-DZT6W2NG.js} +1 -1
  47. package/dist/m/{c-O2QZDVZ2.js → c-EEWPNUM2.js} +1 -1
  48. package/dist/m/{c-MFB74XVN.js → c-EHAR4RJJ.js} +2 -2
  49. package/dist/m/c-EHJWIGWN.js +1 -0
  50. package/dist/m/c-EIDZHQHZ.js +1 -0
  51. package/dist/m/{c-V2V5FKXX.js → c-EIUKME3W.js} +1 -1
  52. package/dist/m/c-ELXMSEN5.js +1 -0
  53. package/dist/m/c-EXZOA6XY.js +7 -0
  54. package/dist/m/{c-FKTALXNV.js → c-EYFMAR3M.js} +1 -1
  55. package/dist/m/c-FC5RUFPR.js +1 -0
  56. package/dist/m/{c-FBOO2UY3.js → c-FUN6AKFE.js} +1 -1
  57. package/dist/m/{c-V4B3RUWB.js → c-GFASNR55.js} +1 -1
  58. package/dist/m/{c-XMIDHEKF.js → c-GY36NO7C.js} +1 -1
  59. package/dist/m/{c-UD4VDBGJ.js → c-H3M6UDNV.js} +1 -1
  60. package/dist/m/{c-SFZRY6RT.js → c-H47C6PJZ.js} +1 -1
  61. package/dist/m/{c-MUM53J5J.js → c-H4M2T4A6.js} +1 -1
  62. package/dist/m/{c-U7F66I64.js → c-HYNM5U6B.js} +1 -1
  63. package/dist/m/c-J2YYLEVM.js +1 -0
  64. package/dist/m/c-J2ZW4HMR.js +1 -0
  65. package/dist/m/{c-WCG6AKA7.js → c-JC4RZW4E.js} +1 -1
  66. package/dist/m/c-K2ZHQMPF.js +1 -0
  67. package/dist/m/c-KD2ME5UN.js +2 -0
  68. package/dist/m/{c-Z2OZFX3N.js → c-L6KVXPBO.js} +1 -1
  69. package/dist/m/{c-GO635CRU.js → c-LAKBBJOU.js} +2 -2
  70. package/dist/m/{c-4AE2A2LK.js → c-LETPPG2F.js} +1 -1
  71. package/dist/m/{c-SFYTKRU7.js → c-MKAUC6DB.js} +1 -1
  72. package/dist/m/{c-WDFQ7PBU.js → c-MMEVDN6D.js} +1 -1
  73. package/dist/m/{c-LS7IVQVW.js → c-MMV5JULA.js} +1 -1
  74. package/dist/m/{c-NEQRFC4O.js → c-MVVEIJUU.js} +1 -1
  75. package/dist/m/{c-SXZYVXD6.js → c-N362HNGO.js} +1 -1
  76. package/dist/m/{c-7K4SCQB7.js → c-ND3W7D5U.js} +1 -1
  77. package/dist/m/{c-3E2IK5HU.js → c-NNHNXD6M.js} +1 -1
  78. package/dist/m/{c-D62HRSZK.js → c-NYJ577NL.js} +1 -1
  79. package/dist/m/{c-YFO6ZJLQ.js → c-O3DPFZCE.js} +1 -1
  80. package/dist/m/c-OZOACVUD.js +1 -0
  81. package/dist/m/{c-MV7TEUTD.js → c-OZVK3TFI.js} +1 -1
  82. package/dist/m/{c-ZEA3DCG3.js → c-PWILUN4T.js} +1 -1
  83. package/dist/m/{c-BCWYEG6P.js → c-QA3Q3MDI.js} +1 -1
  84. package/dist/m/{c-XHZIKRCV.js → c-QKOKMQXA.js} +1 -1
  85. package/dist/m/{c-TGIMBAWE.js → c-RBWVF4N5.js} +1 -1
  86. package/dist/m/c-RES2S5Q3.js +1 -0
  87. package/dist/m/c-RFGELYEU.js +2 -0
  88. package/dist/m/c-RGFPLQGV.js +1 -0
  89. package/dist/m/{c-RGAALCDU.js → c-SPOEDIMP.js} +1 -1
  90. package/dist/m/{c-YX2MC7YL.js → c-SRW5OBCF.js} +1 -1
  91. package/dist/m/{c-C6YZNU6E.js → c-SYOA4T7V.js} +1 -1
  92. package/dist/m/c-SYVF6ZMF.js +1 -0
  93. package/dist/m/{c-NADLYVAH.js → c-TJ5PFOJ2.js} +1 -1
  94. package/dist/m/{c-KYTVZT4D.js → c-TKV273YU.js} +1 -1
  95. package/dist/m/c-U35T5NAY.js +1 -0
  96. package/dist/m/{c-PRZNJUYZ.js → c-UEKJWXCB.js} +2 -2
  97. package/dist/m/c-UW6MMZ4V.js +1 -0
  98. package/dist/m/{c-XQTERKQA.js → c-V4DBV5ZV.js} +1 -1
  99. package/dist/m/c-VGG3UR7I.js +1 -0
  100. package/dist/m/c-VU4WEWPH.js +4 -0
  101. package/dist/m/{c-5Q5XBN56.js → c-W7LWCJHD.js} +1 -1
  102. package/dist/m/c-WHMZCRQD.js +6 -0
  103. package/dist/m/{c-WMRJKQ2V.js → c-WHQUZM2V.js} +1 -1
  104. package/dist/m/c-WOJ2RTV4.js +1 -0
  105. package/dist/m/{c-ZJG6C2WL.js → c-WOWGGNCJ.js} +1 -1
  106. package/dist/m/{c-ZORVIXUR.js → c-XHD7XJTE.js} +1 -1
  107. package/dist/m/c-XONFK3WC.js +1 -0
  108. package/dist/m/{c-HGG7M2S3.js → c-Y3J5LDKB.js} +1 -1
  109. package/dist/m/{c-JB5YU57S.js → c-Y3MPVURA.js} +1 -1
  110. package/dist/m/c-Y6HH7LTM.js +1 -0
  111. package/dist/m/{c-52OC3OH3.js → c-YRDKVEGR.js} +1 -1
  112. package/dist/m/c-YYIN4NAF.js +30 -0
  113. package/dist/m/{c-WVCT3ITX.js → c-YZGWSCMT.js} +1 -1
  114. package/dist/m/c-ZFAPQQIB.js +1 -0
  115. package/dist/m/core/{admin-attrs-ZI6K6UGM.js → admin-attrs-43JBA6JB.js} +1 -1
  116. package/dist/m/core/{autosave-BSM2ABJL.js → autosave-HD7Y7UNV.js} +1 -1
  117. package/dist/m/core/{conflict-notice-7EQLDYPA.js → conflict-notice-UNDOD4BL.js} +1 -1
  118. package/dist/m/core/{persist-2SZO3PCE.js → persist-MX3VYVBN.js} +1 -1
  119. package/dist/m/core/{save-K6Q47J2X.js → save-JZ7R4ET2.js} +1 -1
  120. package/dist/m/core/{save-core-U3Z44XBO.js → save-core-I4N6S4ED.js} +1 -1
  121. package/dist/m/core/site-edits-C22O53GS.js +1 -0
  122. package/dist/m/core/{snapshot-PWCHYFL6.js → snapshot-N5MKDGNI.js} +1 -1
  123. package/dist/m/core/{unsaved-warning-2WRZLJH5.js → unsaved-warning-BP6ZY3PG.js} +1 -1
  124. package/dist/m/internals/{index-FSLC4M7J.js → index-3LAVREAU.js} +1 -1
  125. package/dist/m/loader-DCKCZKY6.js +1 -0
  126. package/dist/m/manifest-7954CBE3.js +1 -0
  127. package/dist/m/manifest-edit-93AA79D7.js +1 -0
  128. package/dist/m/manifest.json +1240 -1179
  129. package/dist/m/page/{editor-PKSPJ2XJ.js → editor-UF3CIA6V.js} +5 -5
  130. package/dist/m/plugins/{ai-edit-3LG6MGS3.js → ai-edit-WDV2GLDU.js} +2 -2
  131. package/dist/m/plugins/{cms-T2HLI7JG.js → cms-KG6TCTR3.js} +9 -9
  132. package/dist/m/plugins/{derive-7DR5TUDH.js → derive-R4USHZ7P.js} +1 -1
  133. package/dist/m/plugins/{indicator-CTKX4EY7.js → indicator-OLPZ4WFI.js} +1 -1
  134. package/dist/m/plugins/{live-IFLL6YN5.js → live-DF5YS5AH.js} +1 -1
  135. package/dist/m/plugins/{menu-YJZ3JWBC.js → menu-ESEFQARM.js} +1 -1
  136. package/dist/m/plugins/page-GZSU77JS.js +2 -0
  137. package/dist/m/plugins/{page-view-NMCCU6MF.js → page-view-7MM3FEAR.js} +1 -1
  138. package/dist/m/plugins/{people-6WIWCZEG.js → people-EBWE337I.js} +1 -1
  139. package/dist/m/plugins/quickcrop-UHURKA2F.js +26 -0
  140. package/dist/m/plugins/richclay-MXH2GFAZ.js +549 -0
  141. package/dist/m/plugins/sortable-BAG3MSWS.js +1 -0
  142. package/dist/m/plugins/{source-7LSGOV46.js → source-OYHDXKTB.js} +1 -1
  143. package/dist/m/plugins/undo-KLHAGV75.js +1 -0
  144. package/dist/m/plugins/{upgrade-MMPZUCDM.js → upgrade-SZQJYEQQ.js} +1 -1
  145. package/dist/m/plugins/{visitor-drafts-V5YB7XDH.js → visitor-drafts-ZE6PCAFP.js} +2 -2
  146. package/dist/m/plugins/{visitor-menu-QDV2MYJN.js → visitor-menu-5XY57JQA.js} +1 -1
  147. package/dist/m/plugins/{wire-3YGUO3GE.js → wire-S5ATC4QI.js} +1 -1
  148. package/dist/m/reader-core-AHOAP5DH.js +77 -0
  149. package/dist/m/sync/{live-sync-XMXXZS3G.js → live-sync-RZQSDMZW.js} +1 -1
  150. package/dist/m/ui/index-G7ZJXNMG.js +1 -0
  151. package/dist/m/vendor/{sap-core.vendor-JANUQULT.js → sap-core.vendor-5TWOJYVM.js} +4 -4
  152. package/dist/offline-manifest.json +780 -750
  153. package/dist/server/core.cjs +4245 -2614
  154. package/dist/server/markdown.cjs +1 -0
  155. package/dist/server/markdown.mjs +7 -0
  156. package/docs/guide.md +26 -37
  157. package/entries/clay-data.js +1 -1
  158. package/entries/sap.js +5 -5
  159. package/package.json +6 -2
  160. package/packed-contract.json +3 -0
  161. package/src/attrs/save-freeze.js +1 -1
  162. package/src/core/admin-contenteditable.js +1 -1
  163. package/src/core/admin-inputs.js +1 -1
  164. package/src/core/admin-onclick.js +1 -1
  165. package/src/core/admin-resources.js +5 -2
  166. package/src/core/conflict-notice-ui.js +59 -34
  167. package/src/core/save.js +9 -9
  168. package/src/core/site-edits.js +1 -1
  169. package/src/core/snapshot.js +56 -43
  170. package/src/core/stale-host-notice.js +20 -7
  171. package/src/loader-logic.js +0 -13
  172. package/src/page/boot-pack.js +1 -0
  173. package/src/page/editor.js +10 -4
  174. package/src/page/history-intent.js +111 -4
  175. package/src/page/import-markdown.js +22 -8
  176. package/src/page/save-projection.js +1 -1
  177. package/src/page/ybind/bridge.js +14 -7
  178. package/src/page/ybind/moves.js +437 -3
  179. package/src/page/ybind/origins.js +1 -1
  180. package/src/page/ybind/recovery.js +1 -1
  181. package/src/plugins/page.js +48 -4
  182. package/src/plugins/quickcrop.js +128 -69
  183. package/src/plugins/richclay.js +136 -0
  184. package/src/plugins/sortable.js +25 -9
  185. package/src/plugins/undo.js +169 -7
  186. package/src/recovery/undo.js +14 -7
  187. package/src/server/markdown/index.js +23 -0
  188. package/src/sync/conflicts.js +3 -1
  189. package/src/sync/data-guard-notice.js +137 -18
  190. package/src/sync/live-sync.js +24 -0
  191. package/src/ui/bevel-controls.js +4 -1
  192. package/src/ui/dialogs.js +11 -7
  193. package/src/ui/modal.js +9 -7
  194. package/src/ui/toast.js +67 -32
  195. package/src/ui/vendor-skin.js +9 -4
  196. package/src/vendor/hyper-html-api-data.vendor.js +1 -1
  197. package/src/vendor/hyper-html-api-upgrade.vendor.js +2 -2
  198. package/src/vendor/hyper-undo.vendor.js +1 -1
  199. package/src/vendor/hypercms.vendor.js +7 -7
  200. package/src/vendor/richclay.vendor.js +16 -16
  201. package/src/vendor/sap-core.vendor.js +4 -4
  202. package/tool-generation/context.md +69 -0
  203. package/tool-generation/system.md +1 -1
  204. package/dist/m/c-277QP5ET.js +0 -1
  205. package/dist/m/c-5SZ6KFR5.js +0 -1
  206. package/dist/m/c-CU33V6RW.js +0 -4
  207. package/dist/m/c-CVSWLX3X.js +0 -1
  208. package/dist/m/c-DXPOFLEJ.js +0 -1
  209. package/dist/m/c-EODTTNVA.js +0 -1
  210. package/dist/m/c-ESK4S67I.js +0 -1
  211. package/dist/m/c-FDWR3FL7.js +0 -1
  212. package/dist/m/c-FJDTDGDA.js +0 -1
  213. package/dist/m/c-FYDKYW6E.js +0 -1
  214. package/dist/m/c-HKSLOVU4.js +0 -1
  215. package/dist/m/c-IJHF4IO6.js +0 -1
  216. package/dist/m/c-IUL7PU4P.js +0 -1
  217. package/dist/m/c-JWW6BHWD.js +0 -6
  218. package/dist/m/c-K4M76VPM.js +0 -7
  219. package/dist/m/c-M7ITYKMF.js +0 -1
  220. package/dist/m/c-MR75YPRT.js +0 -1
  221. package/dist/m/c-NFQFV7OP.js +0 -2
  222. package/dist/m/c-NHXOBD6A.js +0 -1
  223. package/dist/m/c-NVU3DORS.js +0 -1
  224. package/dist/m/c-PNZIJFG7.js +0 -1
  225. package/dist/m/c-QWB53KRW.js +0 -1
  226. package/dist/m/c-RHPHMTF2.js +0 -2
  227. package/dist/m/c-RWJ3OSCP.js +0 -1
  228. package/dist/m/c-SEVOS4UE.js +0 -1
  229. package/dist/m/c-SGG6MUXW.js +0 -1
  230. package/dist/m/c-SXNSSHPP.js +0 -1
  231. package/dist/m/c-TFLRT5JX.js +0 -1
  232. package/dist/m/c-TLQINES7.js +0 -30
  233. package/dist/m/c-U65PREMC.js +0 -1
  234. package/dist/m/c-V5L6HWVL.js +0 -1
  235. package/dist/m/c-VMXCX52Q.js +0 -1
  236. package/dist/m/c-YYGUHSZR.js +0 -1
  237. package/dist/m/core/site-edits-CFMF6GHD.js +0 -1
  238. package/dist/m/loader-RC54UV7H.js +0 -1
  239. package/dist/m/manifest-3B84C829.js +0 -1
  240. package/dist/m/manifest-edit-1CB79AD4.js +0 -1
  241. package/dist/m/plugins/page-GTDPYGE4.js +0 -2
  242. package/dist/m/plugins/quickcrop-X5MRIBAP.js +0 -26
  243. package/dist/m/plugins/richclay-L3BZMX4I.js +0 -549
  244. package/dist/m/plugins/sortable-365SRRL3.js +0 -1
  245. package/dist/m/plugins/undo-UES4KS7B.js +0 -1
  246. package/dist/m/reader-core-VR7EL4WV.js +0 -77
  247. package/dist/m/ui/index-MGTWOW2C.js +0 -1
  248. /package/dist/m/{c-QTTJYJMA.js → c-FILLTJA7.js} +0 -0
  249. /package/dist/m/plugins/{quickcrop-X5MRIBAP.js.LEGAL.txt → quickcrop-UHURKA2F.js.LEGAL.txt} +0 -0
  250. /package/dist/m/plugins/{richclay-L3BZMX4I.js.LEGAL.txt → richclay-MXH2GFAZ.js.LEGAL.txt} +0 -0
@@ -0,0 +1 @@
1
+ import{a as j}from"./c-XQXZAO7N.js";import{e as Y}from"./c-S7LK4KUE.js";import{c as $}from"./c-MOP5KBWZ.js";import{b as D,i as I,o as F}from"./c-HA6INT6J.js";import{c as L,h as w,j as A,k as _,n as C,o as z}from"./c-ICMAOOGK.js";var U=[],W=[],T=new WeakMap,g=null,B=null,M=0;function Se(){return M}function Z(e){return T.get(e)||null}var O=new WeakMap,h=null;function Ce(){return h}function xe(e){h&&e&&(h.artifact=e)}var R=null,x=new Map;function we(e){R=e}function Ae(e){return e==null?null:x.get(e)??null}function Te(e){return e&&O.get(e)||null}function ee(e){e&&(O.delete(e),x.delete(e.captureId))}function te(e){let t=r=>{if(r.hasAttribute("onbeforesave")||r.hasAttribute("onbeforesnapshot"))return!0;let n=r.localName==="template"&&r.content?r.content:r;for(let o of n.children)if(t(o))return!0;return!1};return e.nodeType===1?t(e):!1}function u(e){for(let t of e.querySelectorAll(z))t.remove()}function m(e,t){for(let r of e.querySelectorAll(`[${t}]`))if(u(e),!(r!==e&&!e.contains(r)))try{new Function(r.getAttribute(t)).call(r)}catch(n){console.error(`[${t}] handler failed:`,n)}}var K=new WeakSet,k=new WeakSet;function re(e,t,r){if(k.has(t)||typeof r?.code=="string")throw r;K.has(t)||(K.add(t),console.error(`clayjs: a ${e} callback threw; the save goes on without it`,r))}function V(e,t,r,n){let o=typeof MutationObserver=="function"?new MutationObserver(()=>{}):null;o?.observe(r,{subtree:!0,childList:!0,attributes:!0,characterData:!0});try{n()}catch(c){if(!o||o.takeRecords().length>0)throw c;re(e,t,c)}finally{o?.disconnect()}}function i(e){for(let t of W)u(e),V("addDocumentTransform",t,e,()=>t(e))}var H=null;function ge(e){H=e}function Re(e){return H?.(e),e}function be(e,{required:t=!1}={}){U.push(e),t&&k.add(e)}function Ee(e,{steps:t=null}={}){g=e,B=t}var G="http://www.w3.org/1999/xhtml";function P(e){let t=X(e);if(!t.length)return"<!DOCTYPE html>"+e.outerHTML;let r=J(t),n;try{n="<!DOCTYPE html>"+e.outerHTML}finally{for(let[o,c]of t)o.replaceChildren(...c)}for(let[o,c]of r)n=n.split(o).join(c);return n}function X(e){let t=[],r=n=>{for(let o of n.childNodes)if(o.nodeType===1){if(o.localName==="noscript"&&o.namespaceURI===G){let c=Array.from(o.childNodes);c.length&&c.every(a=>a.nodeType===3)&&t.push([o,c]);continue}r(o.localName==="template"&&o.content?o.content:o)}};return r(e),t}function _e(e){let t=[],r=n=>{for(let o of n.childNodes)if(o.nodeType===1){if(o.localName==="noscript"&&o.namespaceURI===G){o.firstChild&&t.push(o);continue}r(o.localName==="template"&&o.content?o.content:o)}};r(e.documentElement??e);for(let n of t)n.replaceChildren(n.ownerDocument.createTextNode(n.innerHTML));return e}function J(e){let t=Math.random().toString(36).slice(2);return e.map(([r,n],o)=>{let c=`\uE000clay-noscript-${t}-${o}\uE000`;return r.replaceChildren(r.ownerDocument.createTextNode(c)),[c,n.map(a=>a.data).join("")]})}function Q(e,t){let r=h;h=e;try{return t()}finally{h=r}}function N(e,t=null){if(t&&R){let n=null;try{n=R(e)}catch{}n&&x.set(t.captureId,n)}let r=P(e);if(!g)return r;try{return Q(t,()=>g(e,r))}catch(n){return console.error("clayjs: save renderer failed, sending the full serialization",n),r}}function Me(e,{required:t=!1}={}){W.push(e),t&&k.add(e)}function d(e,t=!0){let r=window.__preventOnclone;window.__preventOnclone=!0;try{return e.cloneNode(t)}finally{window.__preventOnclone=r}}function b(e,t){let r=T.get(e);r&&T.set(t,r);let n=e.children,o=t.children;for(let c=0;c<n.length;c++)b(n[c],o[c])}function f({flushUndo:e=!0,authored:t=!0,forSave:r=!1,requestRefresh:n=!1,context:o=null}={}){e&&typeof window<"u"&&window.clay?.undo?.flush&&window.clay.undo.flush();let a=j(document.documentElement,{capability:"snapshot",provenance:T}).root;for(let s of U)u(a),V("onSnapshot",s,a,()=>s(a,{original:Z,forSave:r,requestRefresh:n}));return Y(a),H?.(a),u(a),o&&(o.authoredHandlers=te(a)),t&&m(a,"onbeforesnapshot"),u(a),L(a),F(a),D(a),a}function E(e,{authored:t=!0}={}){u(e),t&&m(e,"onbeforesave"),i(e),u(e);for(let r of e.querySelectorAll(w))r.remove();return q(e),e}function q(e){for(let t of e.querySelectorAll("[sap-error]"))t.removeAttribute("sap-error")}function oe({flushUndo:e=!0,authored:t=!0}={}){return E(f({flushUndo:e,authored:t}),{authored:t})}var ne=["style","class"];function ce(e){$(e);for(let t of ne){e.getAttribute(t)===""&&e.removeAttribute(t);for(let r of e.querySelectorAll(`[${t}=""]`))r.removeAttribute(t)}}function y(e){return ce(e),"<!DOCTYPE html>"+e.outerHTML}function Oe({flushUndo:e=!0}={}){let t=f({flushUndo:e});m(t,"onbeforesave");for(let r of t.querySelectorAll(A))r.remove();return i(t),u(t),y(t)}function ke({flushUndo:e=!0}={}){let t=f({flushUndo:e});m(t,"onbeforesave");for(let r of t.querySelectorAll(C))r.remove();return i(t),u(t),y(t)}function He({flushUndo:e=!0}={}){let t=f({flushUndo:e});m(t,"onbeforesave");let r=t.querySelector(_)?d(t):null;r&&b(t,r);for(let c of t.querySelectorAll(A))c.remove();i(t),u(t);let n=y(t),o=n;if(r){for(let c of r.querySelectorAll(C))c.remove();i(r),u(r),o=y(r)}return{forComparison:n,forDirty:o}}function ae({emitForSync:e=!0,flushUndo:t=!0,requestRefresh:r=!1,forRequest:n=!1,pageFormatMarker:o=null,sliced:c=!1}={}){if(!Number.isSafeInteger(M+1))throw new Error("Save capture identity exhausted");let a=++M,s=n?{captureId:a,authoredHandlers:!1,artifact:null}:null,l=f({flushUndo:t,forSave:e,requestRefresh:r,context:s});e&&document.dispatchEvent(new CustomEvent("clay:snapshot-ready",{detail:{documentElement:l,forSave:!0,captureId:a,sliced:c}})),m(l,"onbeforesave");let v=d(l);b(l,v);let p=l.querySelector(_)?d(l):null;p&&b(l,p),i(l),u(l);for(let S of l.querySelectorAll(w))S.remove();q(l);for(let S of v.querySelectorAll(A))S.remove();if(i(v),u(v),p){for(let S of p.querySelectorAll(C))S.remove();i(p),u(p)}return{captureId:a,context:s,pageFormatMarker:o,clone:l,compareClone:v,dirtyClone:p,renderer:g,rendererSteps:B,pageStateReader:R,result:null}}function le(e){if(!e.context||!e.pageStateReader)return;let t=null;try{t=e.pageStateReader(e.clone)}catch{}t&&x.set(e.captureId,t)}function ue(e,{forSave:t,forComparison:r,forDirty:n}){let o={forSave:t,forComparison:r,forDirty:n,captureId:e.captureId};return e.context&&e.context.artifact&&O.set(o,e.context.artifact),e.result=o,o}function se(e){ee(e.result),x.delete(e.captureId),e.context&&(e.context.artifact=null),e.clone=e.compareClone=e.dirtyClone=null,e.result=null}function Pe(e={}){let t=ae(e);try{le(t);let r=P(t.clone),n=t.compareClone?y(t.compareClone):null,o=t.dirtyClone?y(t.dirtyClone):n,c=t.renderer?Q(t.context,()=>t.renderer(t.clone,r)):r;return ue(t,{forSave:c,forComparison:n,forDirty:o})}catch(r){throw se(t),r}}function Ne(){let e=f({flushUndo:!1});m(e,"onbeforesave");let t=d(e),r=new WeakMap;(function n(o,c){r.set(o,c);let a=o.children,s=c.children;for(let l=0;l<a.length;l++)n(a[l],s[l])})(t,e),i(e),u(e);for(let n of e.querySelectorAll(w))n.remove();q(e);for(let n of t.querySelectorAll(C))n.remove();return i(t),u(t),{saveClone:e,compareClone:t,pairMap:r}}function ie({emitForSync:e=!0}={}){let t=f();return e&&document.dispatchEvent(new CustomEvent("clay:snapshot-ready",{detail:{documentElement:t}})),N(E(t))}function qe(e){let t=d(e,!1);for(let s of I)t.removeAttribute(s);let r=t.outerHTML,n=`</${t.localName}>`,o=X(e),c=o.length?J(o):[],a;try{a=e.innerHTML}finally{for(let[s,l]of o)s.replaceChildren(...l)}for(let[s,l]of c)a=a.split(s).join(l);return"<!DOCTYPE html>"+r.slice(0,r.length-n.length)+a+n}function De(e){return d(e)}function Ie(){return f().querySelector("body").innerHTML}function Fe({transform:e=null,flushUndo:t=!0}={}){if(!e&&t)return ie({emitForSync:!1});let r=f({flushUndo:t});if(e){let n=e(r);if(n&&typeof n.then=="function")throw new TypeError("getHTML: the transform must be synchronous")}return N(E(r))}function Le(e,{prepared:t=!1}={}){let r=d(e);return P(t?r:E(r,{authored:!1}))}function ze(){return N(oe({flushUndo:!1,authored:!1}))}export{Se as a,Z as b,Ce as c,xe as d,we as e,Ae as f,Te as g,ee as h,ge as i,Re as j,be as k,Ee as l,P as m,X as n,_e as o,J as p,Q as q,Me as r,d as s,f as t,oe as u,ce as v,y as w,Oe as x,ke as y,He as z,ae as A,le as B,ue as C,se as D,Pe as E,Ne as F,ie as G,qe as H,De as I,Ie as J,Fe as K,Le as L,ze as M};
@@ -1,4 +1,4 @@
1
- import{c as p}from"./c-H3FNLBHN.js";import{w as u}from"./c-JWW6BHWD.js";import"./c-GO635CRU.js";import"./c-V2V5FKXX.js";import"./c-DT7E76Z2.js";import"./c-C6YZNU6E.js";import"./c-7K4SCQB7.js";import"./c-WMRJKQ2V.js";import"./c-AI3H6ETU.js";import{d as h}from"./c-OH2FPYSY.js";import{a as n,b as r}from"./c-Q26XHBLQ.js";import"./c-FSQXFG5T.js";import"./c-RETTCOWO.js";import"./c-WCG6AKA7.js";import"./c-3LDGIBMN.js";import"./c-57XDY6HC.js";import"./c-VHNSBD2M.js";var m=`
1
+ import{c as p}from"./c-H3FNLBHN.js";import{x as u}from"./c-WHMZCRQD.js";import"./c-LAKBBJOU.js";import"./c-EIUKME3W.js";import"./c-DZT6W2NG.js";import"./c-SYOA4T7V.js";import"./c-ND3W7D5U.js";import"./c-WHQUZM2V.js";import"./c-3XGLJAS7.js";import{d as h}from"./c-OH2FPYSY.js";import{a as n,b as r}from"./c-Q26XHBLQ.js";import"./c-FSQXFG5T.js";import"./c-RETTCOWO.js";import"./c-JC4RZW4E.js";import"./c-3LDGIBMN.js";import"./c-57XDY6HC.js";import"./c-VHNSBD2M.js";var m=`
2
2
  .blockeditor-tool-block { position: relative; min-height: 48px; border: 1px solid var(--blockeditor-rule); border-radius: 8px; padding: 12px; }
3
3
  .blockeditor-tool-settings { position: absolute; top: 4px; inset-inline-end: 4px; border: 0; border-radius: 5px; background: var(--blockeditor-pop-bg); color: var(--blockeditor-ink-soft); font: 12px var(--blockeditor-font); padding: 5px 8px; cursor: pointer; opacity: 0; }
4
4
  .blockeditor-tool-block:hover .blockeditor-tool-settings, .blockeditor-tool-block:focus-within .blockeditor-tool-settings { opacity: 1; }
@@ -0,0 +1 @@
1
+ import{a,b,c,d}from"./c-Y6HH7LTM.js";import"./c-VHNSBD2M.js";export{c as applyData,d as default,a as engine,b as extractData};
@@ -0,0 +1,4 @@
1
+ import{a as ee}from"./c-755ZOHOM.js";import{b as Q}from"./c-3G2DGZUP.js";import{p as K,q as Z}from"./c-EHAR4RJJ.js";import"./c-LD6UVV5R.js";import"./c-PGSBXHUE.js";import{a as B,h as X}from"./c-KU3PX7LL.js";import"./c-EQ5NBOGA.js";import"./c-IJUK2GPW.js";import"./c-C7SUMNMI.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-UW6MMZ4V.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-MOP5KBWZ.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var We=Object.defineProperty,Ve=(e,t)=>{for(var r in t)We(e,r,{get:t[r],enumerable:!0})},Fe=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],ze=new Set(Fe),_e=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),he=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),te=new Set(["checked","selected","disabled","readOnly","paused"]);function Je(e,t){return t==null?te.has(e)?!1:"":te.has(e)?t==="false"?!1:!!t:t}var Ye={};Ve(Ye,{CodecRefused:()=>et,EmptyListInsert:()=>R,MAX_RULE_DEPTH:()=>L,MaxRuleDepthExceeded:()=>G,NoRulesTag:()=>Ze,RuleTargetReadOnly:()=>ge,RulesParseError:()=>$,ShapeMismatch:()=>ye,UnknownCodec:()=>we,UnknownRulesVersion:()=>me,WriteNotRoundTripped:()=>Ke,WriteRefused:()=>Ge,WriteRejected:()=>Qe});var $=class extends Error{constructor(e,t){super(e),this.name="RulesParseError",this.cause=t}},me=class extends Error{constructor(e){super(`unknown rules version: ${e}. Library supports "1" and "2".`),this.name="UnknownRulesVersion",this.version=e}},L=20,G=class extends Error{constructor(e){super(`rule depth exceeded ${L} at path: ${e.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=e}},ye=class extends Error{constructor(e){super(`shape mismatch: ${e.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=e}},R=class extends Error{constructor(e,t){super(t?`cannot add items to empty list at "${e.join(".")}" \u2014 ${t}`:`cannot add items to empty list at "${e.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=e}},ge=class extends Error{constructor(e){super(`cannot write to read-only DOM property "${e}"`),this.name="RuleTargetReadOnly",this.target=e}},Ge=class extends Error{constructor(e){super(`write refused: ${e.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=e}};function Xe(e){return e.reduce((t,r)=>typeof r=="number"?`${t}[${r}]`:t?`${t}.${r}`:String(r),"")||"(root)"}var Ke=class extends Error{constructor(e){super(`write did not round-trip at "${Xe(e)}"`),this.name="WriteNotRoundTripped",this.path=e}},Ze=class extends Error{constructor(e){super(`no <script data-rules-name~="${e}"> rules tag in this document`),this.name="NoRulesTag",this.token=e}},Qe=class extends Error{constructor(e,t){super(`write rejected: ${e.length} unknown key(s), ${t.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=e,this.unmatched=t}},we=class extends Error{constructor(e){super(`unknown codec "${e}": no codec by that name is given to this call`),this.name="UnknownCodec",this.code="unknown-codec",this.codec=e}},et=class extends Error{constructor(e,t){super(t),this.name="CodecRefused",this.code=e}};function M(e){let t=0,r=null,l=-1;for(let n=0;n<e.length;n++){let o=e[n];o==="\\"?n++:r?o===r&&(r=null):o==='"'||o==="'"?r=o:o==="["||o==="("?t++:o==="]"||o===")"?t>0&&t--:o==="@"&&t===0&&(l=n)}return l}var re="[*]";function j(e){let t=M(e),r=t===-1?e:e.slice(0,t),l=r.endsWith(re),n={selector:l?r.slice(0,-re.length):r,prop:t===-1?null:e.slice(t+1)||null};return l&&(n.all=!0),n}function ve(e){let t=0,r=null,l=-1,n=!1;for(let o=0;o<e.length;o++){let i=e[o];i==="\\"?o++:r?i===r&&(r=null):i==='"'||i==="'"?r=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:t===0&&i===">"?l=o:t===0&&i===","&&(n=!0)}return n||l===-1||!tt(e,l+1)?null:e.slice(0,l).trim()||null}function tt(e,t){let r=t,l=e.replace(/\s+$/,"").length;for(;r<l&&/\s/.test(e[r]);)r++;let n=0,o=null;for(;r<l;r++){let i=e[r];if(i==="\\")r++;else if(o)i===o&&(o=null);else if(i==='"'||i==="'")o=i;else if(i==="["||i==="(")n++;else if(i==="]"||i===")")n>0&&n--;else if(n===0&&(i==="+"||i==="~"||/\s/.test(i)))return!1}return!0}var rt=/^codec\(([a-z][a-z0-9-]*)\)$/;function P(e){if(typeof e!="string")return null;let t=M(e);if(t===-1)return null;let r=rt.exec(e.slice(t+1));if(!r)return null;let{selector:l,all:n}=j(e);if(n)throw new $("A @codec(name) rule cannot use [*].");return{selector:l,name:r[1]}}var nt=/^--[A-Za-z0-9_-]+$/;function be(e){return typeof e=="string"&&nt.test(e)}function xe(e){let t=[],r=[],l=null,n=0;for(let o=0;o<e.length;o++){let i=e[o];if(l){i==="\\"?o++:i===l&&(l=null);continue}if(i==="/"&&e[o+1]==="*"){let a=e.indexOf("*/",o+2);o=a===-1?e.length:a+1;continue}i==='"'||i==="'"?l=i:i==="("?r.push(")"):i==="["?r.push("]"):i==="{"?r.push("}"):(i===")"||i==="]"||i==="}")&&r[r.length-1]===i?r.pop():i===";"&&r.length===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t}function lt(e){let t="",r=null;for(let l=0;l<e.length;l++){let n=e[l];if(r){t+=n,n==="\\"&&l+1<e.length?t+=e[++l]:n===r&&(r=null);continue}if(n==="/"&&e[l+1]==="*"){let o=e.indexOf("*/",l+2);l=o===-1?e.length:o+1,t+=" ";continue}(n==='"'||n==="'")&&(r=n),t+=n}return t}function Ae(e){e=lt(e);let t=e.indexOf(":");if(t===-1)return null;let r=e.slice(0,t).trim(),l=e.slice(t+1).trim(),n=/!\s*important\s*$/i.exec(l);return n&&(l=l.slice(0,n.index).trim()),{name:r,value:l,important:!!n}}function Te(e,t){if(e==null)return null;let r=null;for(let l of xe(String(e))){let n=Ae(l);!n||n.name!==t||(!r||n.important||!r.important)&&(r=n)}return r?r.value:null}function ot(e,t,r){let l=e==null?"":String(e),n=r==null||r==="",o=xe(l),i=o.map(Ae),a=i.some(u=>u&&u.name===t&&u.important),s=[],c=!1;o.forEach((u,d)=>{let m=i[d];if(!m||m.name!==t){s.push(u);return}if(n||c)return;let p=/^\s*/.exec(u)[0];s.push(`${p}${t}: ${r}${a?" !important":""}`),c=!0});let f=s.join(";");if(!n&&!c){let u=f.trimEnd();f=u===""?`${t}: ${r}`:`${u}${u.endsWith(";")?" ":"; "}${t}: ${r}`}return f.trim()===""?null:f}function it(e,t,r,l){let n=e.attr(t,"style");if((Te(n,r)??"")===l)return;let o=ot(n,r,l);o==null?e.removeAttr(t,"style"):e.attr(t,"style",o)}var at='The @codec(name) rule form needs a rules tag with data-rules-version="2".',st="A @codec(name) rule must be the value of a top level key.";function Oe(e,t){let r=P(e);return r?{...r,codec:t.codecs[r.name]}:null}function Ee(e,t={}){let r=t.version??"1",l=t.codecs??{};n(e,0);function n(o,i){if(!(i>L)){if(typeof o=="string"){let a=P(o);if(!a)return;if(r!=="2")throw new $(at);if(i!==1)throw new $(st);if(!Object.prototype.hasOwnProperty.call(l,a.name))throw new we(a.name);return}if(Array.isArray(o)){n(o[1],i+1);return}if(o&&typeof o=="object")for(let a of Object.values(o))n(a,i+1)}}}function ke(e,t,r,l={}){if(Object.prototype.hasOwnProperty.call(l,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return Ee(r,l),V(e,t,r,{depth:0,path:[]},l)}function V(e,t,r,l,n){if(l.depth>L)throw new G(l.path);if(typeof r=="string")return ut(e,t,r,l,n);if(Array.isArray(r)){let[o,i]=r,a=e.find(t,o,n);return Ne(n,l,a),a.map((s,c)=>V(e,s,i,{depth:l.depth+1,path:[...l.path,c]},n))}if(typeof r=="object"&&r!==null){let o={};for(let[i,a]of Object.entries(r))o[i]=V(e,t,a,{depth:l.depth+1,path:[...l.path,i]},n);return o}return null}function ut(e,t,r,l,n){if(r.endsWith("[]")){let f=r.slice(0,-2),u=e.find(t,f,n);return Ne(n,l,u),u.map(d=>e.text(d))}let o=Oe(r,n);if(o)return ct(e,t,o,n);if(r.startsWith("@"))return W(e,t,r.slice(1));let i=M(r);if(i!==-1){let{selector:f,all:u}=j(r),d=r.slice(i+1),m=f?e.find(t,f,n):[t];return u&&n.allMatches?m.map(p=>W(e,p,d)):m.length===0?null:W(e,m[0],d)}if(r===".")return e.text(t);let{selector:a,all:s}=j(r),c=e.find(t,a,n);return s&&n.allMatches?c.map(f=>e.text(f)):c.length===0?null:e.text(c[0])}function ct(e,t,{selector:r,codec:l},n){let o=r?e.find(t,r,n):[t];return o.length===0?null:l.read(e,o[0],{query:n.query,view:n.view,region:n.region})}function Ne(e,t,r){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),r)}catch(l){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,l)}}function W(e,t,r){if(be(r))return Te(e.attr(t,"style"),r);if(ze.has(r)){let n=e.prop(t,r);return n==null?null:String(n)}return e.attr(t,r)??null}function ft(e,t,r,l){let n=e.length,o=t.length,i=new Array(n).fill(-1);if(l){let h=new Set;for(let y=0;y<n;y++){let g=l[y];!(g>=0&&g<o)||h.has(g)||(i[y]=g,h.add(g))}}if(n===0||o===0)return i;let a=e.map(h=>ne(h,r)),s=t.map(h=>ne(h,r)),c=new Array(o).fill(!1);for(let h of i)h>=0&&(c[h]=!0);let f=new Map;s.forEach((h,y)=>{c[y]||f.set(h,f.has(h)?-1:y)});let u=new Map;a.forEach((h,y)=>{i[y]>=0||u.set(h,(u.get(h)||0)+1)}),a.forEach((h,y)=>{if(i[y]>=0||u.get(h)!==1)return;let g=f.get(h);g===void 0||g===-1||c[g]||(i[y]=g,c[g]=!0)});let d=[];for(let h=0;h<n;h++)i[h]<0&&d.push(h);let m=[];for(let h=0;h<o;h++)c[h]||m.push(h);if(d.length===0||m.length===0)return i;let p=n*o+1,w=dt(e,t,r),v=(h,y)=>w(h,y)*p+Math.abs(h-y);for(let[h,y]of pt(d,m,v))i[h]=y;return i}var Se=e=>typeof e=="object"&&e!==null;function ne(e,t){if(!Se(t))return e==null?" null":String(e);let r=Object.keys(t);return JSON.stringify(r.map(l=>{let n=JSON.stringify(e?.[l]);return n===void 0?" undef":n}))}function dt(e,t,r){if(!Se(r))return(a,s)=>e[a]===t[s]?0:1;let l=Object.keys(r),n=a=>l.map(s=>JSON.stringify(a?.[s])),o=e.map(n),i=t.map(n);return(a,s)=>{let c=o[a],f=i[s],u=0;for(let d=0;d<l.length;d++)c[d]!==f[d]&&u++;return u}}function pt(e,t,r){return e.length<=t.length?le(e,t,r,!1):le(t,e,(l,n)=>r(n,l),!0)}function le(e,t,r,l){let n=e.length,o=t.length,i=[];for(let u=0;u<=n;u++)i.push(new Float64Array(o+1).fill(1/0));let a=[];for(let u=0;u<=n;u++)a.push(new Uint8Array(o+1));for(let u=0;u<=o;u++)i[n][u]=0;for(let u=n-1;u>=0;u--)for(let d=o-1;d>=0;d--){let m=r(e[u],t[d])+i[u+1][d+1],p=i[u][d+1];m<=p?(i[u][d]=m,a[u][d]=1):i[u][d]=p}let s=[],c=0,f=0;for(;c<n&&f<o;)a[c][f]&&(s.push(l?[t[f],e[c]]:[e[c],t[f]]),c++),f++;return s}function Re(e,t,r,l,n,o,i,a={}){let s=e.find(t,r,a);if(n.length===0){s.forEach(A=>e.remove(A)),F(a,"onRowsApplied",o.path,[]);return}let c=n.length>s.length,f=s[0]||null;if(c&&!f&&(f=gt(e,t,r,a),!f))throw new R(o.path);let u=s.map(A=>yt(e,A,l,a)),d=null;if(c&&f){d=e.clone(f);let A=a.templateAttr&&e.attr(f,a.templateAttr)!=null;a.templateAttr&&e.removeAttr(d,a.templateAttr),A&&e.removeAttr(d,"hidden");let T=e.stripIds(d);T>0&&console.warn(`[hyper-html-api] stripped ${T} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let m=ft(n,u,l,ht(e,s,n,o,a)),p=s.length>0?e.parent(s[0]):xt(e,t,r,f,o,a),w=s.length>0?$e(e,p,s[0]):0,v=Ot(e,s),h=new Set,y=[],g=n.map((A,T)=>{let k=m[T];if(k>=0)return h.add(k),y.push(!1),s[k];y.push(!0);let O=e.clone(d);return e.stripIds(O),O});s.forEach((A,T)=>{h.has(T)||e.remove(A)}),v?Tt(e,p,w,g,y):Et(e,g,y,p,w),mt(e,g,l,n,o,i,a),F(a,"onRowsApplied",o.path,g)}function F(e,t,r,l){if(typeof e[t]=="function")try{return e[t](r.slice(),l)}catch(n){console.warn(`[hyper-html-api] ${t} threw at "${r.join(".")||"(root)"}"`,n);return}}function ht(e,t,r,l,n){let o=F(n,"identifyRows",l.path,r);if(!Array.isArray(o))return null;let i=new Array(r.length).fill(-1),a=new Set,s=new Map(t.map((c,f)=>[e.identity(c),f]));for(let c=0;c<r.length;c++){if(!o[c])continue;let f=s.get(e.identity(o[c]));f===void 0||a.has(f)||(i[c]=f,a.add(f))}return i}function mt(e,t,r,l,n,o,i){t.forEach((a,s)=>{if(r===null){let c=l[s],f=c==null?"":String(c);e.text(a)!==f&&e.text(a,f)}else{let c=o(e,a,r,l[s],{depth:n.depth+1,path:[...n.path,s]},i);c&&c!==a&&(t[s]=c)}})}function yt(e,t,r,l){return r===null?e.text(t):ke(e,t,r,l.onRowsRead?{...l,onRowsRead:void 0}:l)}function $e(e,t,r){let l=e.children(t);for(let n=0;n<l.length;n++)if(e.sameNode(l[n],r))return n;return-1}function gt(e,t,r,l){if(!l.templateAttr)return null;let n=/^\s*:scope\s*>\s*/.test(r),o=new RegExp(":not\\(\\["+l.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),i=r.replace(/^\s*:scope\s*>\s*/,"").replace(o,""),a=n?wt(i):0,s=ve(i),c=t;for(;c;){let f=e.find(c,i,{includeRulesTag:!1,templateAttr:null});for(let u of f)if(e.attr(u,l.templateAttr)!=null&&!(n&&!bt(e,t,u,a))&&!(s&&!e.matches(e.parent(u),s)))return u;c=e.parent(c)}return null}function wt(e){let t=0,r=null,l=1;for(let n=0;n<e.length;n++){let o=e[n];if(o==="\\")n++;else if(r)o===r&&(r=null);else if(o==='"'||o==="'")r=o;else if(o==="["||o==="(")t++;else if(o==="]"||o===")")t>0&&t--;else if(t===0&&o===">")l++;else{if(t===0&&(o==="+"||o==="~"))return null;if(t===0&&/\s/.test(o)){if(!vt(e,n))return null;for(;n+1<e.length&&/\s/.test(e[n+1]);)n++}}}return l}function vt(e,t){let r=t;for(;r<e.length&&/\s/.test(e[r]);)r++;let l=t>0?e[t-1]:"",n=r<e.length?e[r]:"";return oe(l)||oe(n)}function oe(e){return e===">"||e==="+"||e==="~"}function bt(e,t,r,l){if(l===null)return!0;let n=r;for(let s=0;s<l;s++)if(n=e.parent(n),!n)return!1;let o=e.prop(t,"tagName");if(!o)return!0;let i=e.prop(n,"tagName");if(!i||String(i).toLowerCase()!==String(o).toLowerCase())return!1;let a=new Set(ie(e,n));return ie(e,t).every(s=>a.has(s))}function ie(e,t){let r=e.attr(t,"class");return r?String(r).split(/\s+/).filter(Boolean):[]}function xt(e,t,r,l,n,o){let i=e.parent(l);if(i&&At(e,t,i)&&!se(e,i,o))return i;let a=ve(r);if(!a)throw new R(n.path,`the list selector "${r}" names no container to hold the new rows \u2014 write it as "container > row" (for example "ol.comments > li") so the cloned row lands in the list`);let s=(a===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,a,o)).filter(c=>!se(e,c,o));if(s.length===0)throw new R(n.path,`no container matching "${a}" inside this context to hold the new rows`);if(s.length>1)throw new R(n.path,`"${a}" matches ${s.length} containers inside this context, so the new rows have no single destination`);return s[0]}function At(e,t,r){let l=r;for(;l;){if(e.sameNode(l,t))return!0;l=e.parent(l)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(n=>e.sameNode(n,r))}var ae=["no-data","editor-ui"];function se(e,t,r){let l=t;for(;l;){if(r.templateAttr&&e.attr(l,r.templateAttr)!=null||ae.some(o=>e.attr(l,o)!=null))return!0;let n=e.attr(l,"clay");if(n&&n.split(/\s+/).some(o=>ae.includes(o)))return!0;l=e.parent(l)}return!1}function Tt(e,t,r,l,n){let o=e.children(t),i=o.map(s=>e.identity(s)),a=!1;l.forEach((s,c)=>{let f=e.identity(s),u=r+c;if(i[u]===f)return;if(!n[c]){let m=i.indexOf(f);m!==-1&&(i.splice(m,1),o.splice(m,1))}let d=Math.min(u,o.length);d<o.length?e.insertBefore(o[d],s):o.length?a?e.insertAfter(o[o.length-1],s):(e.insertAt(t,s,u),a=!0):e.insertAt(t,s,0),i.splice(d,0,f),o.splice(d,0,s)})}function Ot(e,t){if(t.length<=1)return!0;let r=e.parent(t[0]);if(!r)return!1;let l=new Map(e.children(r).map((o,i)=>[e.identity(o),i])),n=[];for(let o of t){let i=l.get(e.identity(o));if(i===void 0)return!1;n.push(i)}return n.sort((o,i)=>o-i),n[n.length-1]-n[0]===n.length-1}function Et(e,t,r,l,n){let o=null,i=n;for(let a=0;a<t.length;a++){if(!r[a]){o=t[a];continue}let s=o?e.parent(o):l;if(!s)continue;let c=o?$e(e,s,o)+1:i++;e.insertAt(s,t[a],c),o=t[a]}}function kt(e,t,r,l,n={}){if(Object.prototype.hasOwnProperty.call(n,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");Ee(r,n);let o=[];if(z(r,l,[],o),o.length)throw new ye(o);I(e,t,r,l,{depth:0,path:[]},n)}function I(e,t,r,l,n,o={}){if(n.depth>L)throw new G(n.path);if(l===void 0)return t;if(typeof r=="string")return Nt(e,t,r,l,n,o);if(Array.isArray(r)){let[i,a]=r;return Re(e,t,i,a,l,n,I,o),t}if(typeof r=="object"&&r!==null){for(let[i,a]of Object.entries(r)){let s=I(e,t,a,l==null?l:l[i],{depth:n.depth+1,path:[...n.path,i]},o);s&&s!==t&&(t=s)}return t}return t}function Nt(e,t,r,l,n,o){if(r.endsWith("[]")){let u=r.slice(0,-2);return Re(e,t,u,null,l,n,I,o),t}let i=Oe(r,o);if(i){let u=i.selector?e.find(t,i.selector,o):[t];return u.length&&i.codec.write(e,u[0],l,{query:o.query}),t}if(r.startsWith("@"))return ce(e,t,r.slice(1),l);let a=M(r);if(a!==-1){let{selector:u,all:d}=j(r),m=r.slice(a+1),p=u?e.find(t,u,o):[t];for(let w of d?p:p.slice(0,1))ce(e,w,m,l);return t}if(r===".")return ue(e,t,l),t;let{selector:s,all:c}=j(r),f=e.find(t,s,o);for(let u of c?f:f.slice(0,1))ue(e,u,l);return t}function ue(e,t,r){let l=r==null?"":String(r);e.text(t)!==l&&e.text(t,l)}function St(e,t,r,l){if(e.styleVar){e.styleVar(t,r,l);return}it(e,t,r,l)}function ce(e,t,r,l){if(be(r))return St(e,t,r,l==null?"":String(l).trim()),t;if(he.has(r)){let n=e.prop(t,r);if(n===l||n!=null&&l!=null&&String(n)===String(l))return t;throw new ge(r)}if(r==="outerHTML"){let n=l==null?"":String(l);return e.replaceWith(t,n)}if(_e.has(r)){let n=Je(r,l);return e.prop(t,r)!==n&&e.prop(t,r,n),t}if(l==null)e.attr(t,r)!=null&&e.removeAttr(t,r);else{let n=String(l);e.attr(t,r)!==n&&e.attr(t,r,n)}return t}function z(e,t,r,l){if(t!==void 0){if(typeof e=="string"){if(P(e))return;if(e.endsWith("[]")){Array.isArray(t)?t.forEach((n,o)=>{typeof n=="object"&&n!==null&&l.push({path:S([...r,o]),expected:"scalar",got:N(n)})}):l.push({path:S(r),expected:"array",got:N(t)});return}t!==null&&typeof t=="object"&&l.push({path:S(r),expected:"scalar",got:N(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){l.push({path:S(r),expected:"array",got:N(t)});return}let n=e[1];t.forEach((o,i)=>z(n,o,[...r,i],l));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){l.push({path:S(r),expected:"object",got:N(t)});return}for(let[n,o]of Object.entries(e))z(o,t[n],[...r,n],l)}}}function N(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function S(e){return e.join(".")}function Rt(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function r(n){let o=[],i=0;for(;i<n.length;){let a=n[i];if(/\s/.test(a)){i++;continue}if("{}".includes(a)){o.push({type:a,value:a}),i++;continue}if(a==="["){let u=!1,d=i+1;for(;d<n.length&&/\s/.test(n[d]);)d++;if(d<n.length&&/[a-zA-Z_]/.test(n[d])&&(u=!0),!u){o.push({type:a,value:a}),i++;continue}}if(a==="]"){o.push({type:a,value:a}),i++;continue}if(a===":"){o.push({type:t.COLON,value:a}),i++;continue}if(a===","){o.push({type:t.COMMA,value:a}),i++;continue}if(a==='"'||a==="'"){let u=a,d=i+1;for(;d<n.length&&n[d]!==u;)n[d]==="\\"&&d++,d++;o.push({type:t.STRING,value:n.substring(i+1,d),quoted:!0,sourceQuote:u}),i=d+1;continue}let s=i,c;for(;s<n.length&&!/[{},]/.test(n[s]);)if(n[s]===":"){let u=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let m of u){let p=m.substring(1);if(n.substring(s+1,s+1+p.length)===p){d=!0,s+=p.length;break}}if(!d)break}else if(n[s]==="["){for(s++;s<n.length&&n[s]!=="]";){if(n[s]==='"'||n[s]==="'"){let u=n[s];for(s++;s<n.length&&n[s]!==u;)n[s]==="\\"&&s++,s++}s++}s<n.length&&n[s]==="]"&&s++}else s++;c=n.substring(i,s);let f=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(c)?f=t.NUMBER:c==="true"||c==="false"||c==="null"?f=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(c)&&(f=t.SELECTOR),o.push({type:f,value:c,quoted:!1}),i=s}return o}function l(n){let o="";for(let i=0;i<n.length;i++){let a=n[i];if("{}".includes(a.type)||"[]".includes(a.type)){o+=a.value;continue}if(a.type===t.COLON){o+=a.value;continue}if(a.type===t.COMMA){let s=n[i+1];if(s&&(s.type==="}"||s.type==="]"))continue;o+=a.value;continue}if(a.type===t.STRING&&a.quoted){let s=a.value;a.sourceQuote==="'"&&(s=s.replace(/\\'/g,"'"),s=s.replace(/(\\*)"/g,(c,f)=>f.length%2===0?f+'\\"':c)),o+=`"${s}"`;continue}if(a.type===t.NUMBER||a.type===t.BOOLEAN){o+=a.value;continue}if(a.type===t.SELECTOR||a.type===t.IDENTIFIER){o+=`"${a.value}"`;continue}o+=`"${a.value}"`}return o}try{let n=r(e),o=l(n);return JSON.parse(o)}catch(n){throw new $("Invalid extraction rules syntax: "+n.message,n)}}var $t=["1","2"];var Ar=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),Tr=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),jt=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);var Or=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...jt],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"],customPropertyValues:Object.freeze({maxLength:200,refusedCharacters:[";","{","}","<",">","\\"],refusedFunctions:["url","src","image","image-set","-webkit-image-set","cross-fade","element","expression","paint"]})});function Ct(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Lt(e){return e?(e.nodeType===9||e.nodeType,e):null}function fe(e,t,r){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=r===null?"":r:t==="checked"&&e.tagName==="INPUT"?e.checked=r!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=r!==null))}function Mt(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function Ut(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let r of t)if(r.tagName==="TEXTAREA")r.value=r.defaultValue;else if(r.tagName==="INPUT"){let l=r.type;l!=="file"&&l!=="checkbox"&&l!=="radio"&&(r.value=r.defaultValue),r.checked=r.defaultChecked}else r.tagName==="OPTION"&&(r.selected=r.defaultSelected)}var It={semanticExclude:!0,find(e,t,r={}){let l=Lt(e);if(!l||!l.querySelectorAll)return[];let n=Array.from(l.querySelectorAll(t));r.includeRulesTag||(n=n.filter(a=>!Ct(a)));let o=[];r.skip&&o.push(r.skip);let i=r.templateAttr===null?null:r.templateAttr||"cms-template";if(i&&o.push("["+i+"]"),o.length){let a=o.join(", ");n=n.filter(s=>!s.closest||!s.closest(a))}return n},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},matches(e,t){return!!(e&&e.matches)&&e.matches(t)},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t,Mt(e,t)},attr(e,t,r){if(r===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,r),fe(e,t,r)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),fe(e,t,null)},prop(e,t,r){if(r===void 0){let l=e?e[t]:void 0;return l!==void 0?l:null}e[t]=r},clone(e){let t=e.cloneNode(!0);return Ut(t),t},insertAt(e,t,r){let l=e.children[r]||null;e.insertBefore(t,l)},insertBefore(e,t){e.parentNode.insertBefore(t,e)},insertAfter(e,t){e.parentNode.insertBefore(t,e.nextSibling)},identity(e){return e||null},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let r=e.ownerDocument.createElement("template");r.innerHTML=t;let l=r.content.firstElementChild;if(!l)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(l,e),l},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(r=>{r.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};var U=It;var Pt="hha:upgrade-check:";function b(e,t){let r=e.querySelector(`meta[name="${t}"]`),l=r?r.getAttribute("content"):null;return l&&l.trim()?l.trim():null}function de(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Dt(e,t){let r=de(e),l=de(t);if(!r||!l)return!1;let n=Math.max(r.length,l.length);for(let o=0;o<n;o++){let i=r[o]||0,a=l[o]||0;if(i!==a)return i>a}return!1}function qt(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Ht(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Bt({force:e=!1,doc:t,loc:r,fetchFn:l,now:n,ttlMs:o=864e5}={}){if(t=t||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),l=l||(d=>fetch(d)),n=n??Date.now(),!t)return null;let i=b(t,"hyper-source");if(!i)return null;let a=b(t,"hyper-version"),s;try{s=new URL(i,r?r.href:void 0)}catch{return null}if(r&&s.origin===r.origin&&s.pathname===r.pathname)return null;let c=`${Pt}${s.href}:${a||"none"}`,f,u=e?null:qt(c);if(u&&typeof u.checkedAt=="number"&&n-u.checkedAt<o)f=u.sourceVersion;else{try{let d=await l(s.href);if(!d.ok)throw new Error(`HTTP ${d.status}`);let m=await d.text(),p=new DOMParser().parseFromString(m,"text/html");f=b(p,"hyper-version")}catch{f=null}Ht(c,{checkedAt:n,sourceVersion:f})}return f?{available:Dt(f,a||"0.0.0"),currentVersion:a,sourceVersion:f,sourceUrl:s.href}:null}var Wt="script[data-rules-name]";function Vt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function je(e,t){let r=e.find(t,Wt,{includeRulesTag:!0}),l=new Set,n=[];for(let o of r){let i=Vt(e.attr(o,"data-rules-name"));if(!i)continue;if(l.has(i)){console.warn(`hyper-html-api: duplicate rules tag name "${i}"; using the first.`);continue}let a=e.attr(o,"data-rules-version");if(!$t.includes(a))throw new me(a);l.add(i),n.push({name:i,rules:Rt(e.text(o)),version:a})}return n}function Ce(e,t){if(t!=="2"||!e||typeof e!="object"||Array.isArray(e))return{rules:e,carried:[]};let r={},l=[];for(let[n,o]of Object.entries(e)){let i=P(o);i?l.push({key:n,selector:i.selector}):r[n]=o}return{rules:r,carried:l}}function Le(e,t,r){return e.find(t,r)[0]||null}function Me(e,t){let r={};for(let{name:l,rules:n,version:o}of je(e,t)){let{rules:i,carried:a}=Ce(n,o),s=ke(e,t,i,{version:o});for(let{key:c,selector:f}of a){let u=Le(e,t,f);s[c]=u?e.prop(u,"innerHTML"):null}r[l]=s}return r}function Ft(e){let t=e||document,r=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Me(U,t),version:b(r,"hyper-version")}}var pe=class extends Error{constructor(e,t){super(`could not fetch upgrade source: ${e}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=e,this.cause=t}},zt=class extends Error{constructor(e){super(`upgrade source has no rules tags; refusing to drop all existing data: ${e}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=e}},_=class extends Error{constructor(e,t){super(e),this.name="UpgradeTransformInvalid",this.cause=t}},_t=class extends Error{constructor(e){super(`found ${e} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=e}},Jt="text/hyper-upgrade";function Yt(e,t){let r=e.find(t,`script[type="${Jt}"]`);if(r.length===0)return null;if(r.length>1)throw new _t(r.length);return e.text(r[0])||null}var Gt=new Function("url","return import(url)");async function Xt(e){let t=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(t),l;try{l=await Gt(r)}catch(n){throw new _(`transform failed to load: ${n&&n.message?n.message:n}`,n)}finally{URL.revokeObjectURL(r)}if(typeof l.default!="function")throw new _("transform must `export default` a function");return l.default}function Ue(e,t){let r={carriedOver:0,discarded:0,listItems:0},l=J(t,e,r);return Y(t,e,r),{data:l,summary:r}}function J(e,t,r,l=!1){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(r.listItems+=t.length,r.carriedOver+=t.length,t):l?[]:void 0:t==null||typeof t=="object"?l&&!Kt(e)?null:void 0:(r.carriedOver++,t);if(Array.isArray(e)){let[,n]=e;return Array.isArray(t)?(r.listItems+=t.length,t.map(o=>J(n,o,r,!0))):l?[]:void 0}if(typeof e=="object"&&e!==null){let n={};for(let[o,i]of Object.entries(e)){let a=J(i,t?.[o],r,l);a!==void 0&&(n[o]=a)}return n}}function Kt(e){let t=M(e);return t!==-1&&he.has(e.slice(t+1))}function Y(e,t,r){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let l=new Set(Object.keys(e));for(let n of Object.keys(t))l.has(n)?Y(e[n],t[n],r):r.discarded+=C(t[n]);return}if(Array.isArray(e)&&Array.isArray(t)){let l=e[1];t.forEach(n=>Y(l,n,r));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(r.discarded+=C(t))}}function C(e){return e==null?0:Array.isArray(e)?e.reduce((t,r)=>t+C(r),0):typeof e=="object"?Object.values(e).reduce((t,r)=>t+C(r),0):1}function Zt(e,t,r){let l=je(e,t),n={carriedOver:0,discarded:0,listItems:0},o={},i=new Set;for(let{name:a,rules:s,version:c}of l){if(i.add(a),!Object.prototype.hasOwnProperty.call(r,a)){o[a]={carriedOver:0,discarded:0,listItems:0};continue}let{rules:f,carried:u}=Ce(s,c),d=r[a],{data:m,summary:p}=Ue(Qt(d,u),f);kt(e,t,f,m,{templateAttr:"cms-template"});for(let{key:w,selector:v}of u){let h=Ie(d)?d[w]:void 0;if(h==null)continue;let y=Le(e,t,v);typeof h=="string"&&y?(e.prop(y,"innerHTML",h),p.carriedOver+=1):p.discarded+=1}o[a]=p,n.carriedOver+=p.carriedOver,n.discarded+=p.discarded,n.listItems+=p.listItems}for(let a of Object.keys(r))i.has(a)||(n.discarded+=C(r[a]));return{totals:n,byName:o,rulesTagCount:l.length}}function Ie(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Qt(e,t){if(!t.length||!Ie(e))return e;let r={...e};for(let{key:l}of t)delete r[l];return r}async function er({sourceUrl:e,dataByName:t,fromVersion:r,doc:l,loc:n,fetchFn:o}={}){if(l=l||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(h=>fetch(h)),!l)throw new Error("upgrade.run requires a document context");if(e=e||b(l,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let i=new URL(e,n?n.href:void 0);r=r!==void 0?r:b(l,"hyper-version"),t=t||Me(U,l);let a;try{a=await o(i.href)}catch(h){throw new pe(i.href,h)}if(!a.ok)throw new pe(i.href,new Error(`HTTP ${a.status}`));let s=await a.text(),c=new DOMParser().parseFromString(s,"text/html"),f=b(c,"hyper-version"),u=t,d=!1,m=Yt(U,c);if(m){let h=await(await Xt(m))(u,{fromVersion:r,toVersion:f});if(!h||typeof h!="object"||Array.isArray(h))throw new _("transform must return a plain object map of { rulesName: data }");u=h,d=!0}let{totals:p,byName:w,rulesTagCount:v}=Zt(U,c,u);if(v===0&&Object.keys(u).length>0)throw new zt(i.href);return{html:rr(c),fromVersion:r,toVersion:f,summary:{transformApplied:d,totals:p,byName:w}}}function tr(e){for(let t of e.querySelectorAll("input")){let r=(t.getAttribute("type")||"").toLowerCase();r!=="file"&&(r==="checkbox"||r==="radio"?t.checked!==t.hasAttribute("checked")&&t.toggleAttribute("checked",t.checked):t.value!==(t.getAttribute("value")??"")&&t.setAttribute("value",t.value))}for(let t of e.querySelectorAll("textarea"))t.value!==t.textContent&&(t.textContent=t.value);for(let t of e.querySelectorAll("select")){let r=[...t.options];if(!t.multiple){let l=r.findIndex(n=>n.hasAttribute("selected"));if(t.selectedIndex===l||l===-1&&t.selectedIndex<=0)continue}for(let l of r)l.selected!==l.hasAttribute("selected")&&l.toggleAttribute("selected",l.selected)}}function rr(e){return tr(e),`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
2
+ `+e.documentElement.outerHTML}var D={checkForUpdate:Bt,run:er,extractAll:Ft,shapeMatch:Ue};var x="The new version could not be downloaded. Nothing was changed.",q="The upgrade could not be saved. Nothing was changed.",qe="This document changed somewhere else. Reload and try again.",nr="Something else is changing this document. Nothing was changed.",lr="This document does not say which parts are its data, so it cannot be upgraded safely. Nothing was changed.",or="The new version has no place for this page's content. Nothing was changed.";async function ir(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;let r=await t.digest("SHA-256",e);return[...new Uint8Array(r)].map(l=>l.toString(16).padStart(2,"0")).join("")}async function Pe(e,t){try{let r=await e(t,{credentials:"omit"});return!r||!r.ok?null:r}catch{return null}}function ar(e,t,r){if(e&&typeof e.latestUrl=="string"&&e.latestUrl)return e.latestUrl;let l=b(t,"hyper-source");if(!l)return null;try{let n=new URL(l,r?r.href:void 0);return n.pathname=n.pathname.replace(/\.html$/,".json"),n.href}catch{return null}}function sr(e){let t=b(e,"clay-template");if(!t)return null;let[r,l]=t.split(/\s+/);return r&&l?{id:r,variant:l}:null}function H(e,t="",r=[]){if(Array.isArray(e)){for(let l of e)H(l,`${t}[]`,r);return r}if(e&&typeof e=="object"){for(let[l,n]of Object.entries(e))H(n,t?`${t}.${l}`:l,r);return r}return e!=null&&r.push({path:t,value:e}),r}function ur(e,t){let r=[e];for(let l of String(t).split(".")){let n=l.endsWith("[]"),o=n?l.slice(0,-2):l,i=[];for(let a of r){let s=o?a?.[o]:a;n?Array.isArray(s)&&i.push(...s):i.push(s)}r=i}return r}function cr(e,t,r={}){let l=new Map;for(let{path:o,value:i}of H(t)){let a=`${o}\0${String(i)}`;l.set(a,(l.get(a)||0)+1)}let n=[];for(let{path:o,value:i}of H(e)){let a=`${o}\0${String(i)}`;if(l.get(a)>0){l.set(a,l.get(a)-1);continue}let s=r[o];typeof s=="string"&&ur(t,s).some(c=>c===i)||n.push({path:o,value:i})}return n}async function fr(e){let t=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(t);try{return await new Function("url","return import(url)")(r)}finally{URL.revokeObjectURL(r)}}async function dr(e){let r=new DOMParser().parseFromString(e,"text/html").querySelector('script[type="text/hyper-upgrade"]');if(!r)return{};let l=await fr(r.textContent||"");return l&&l.renames&&typeof l.renames=="object"?l.renames:{}}var De='script[clay~="live"][merge]';function pr(e,t,r){let l=t.querySelector("article[data-blockeditor]");if(!l)return null;l.replaceWith(t.importNode(r,!0));for(let o of e.querySelectorAll(De)){let i=o.getAttribute("merge");if(i!=="blockeditor"&&!i.startsWith("blockeditor."))continue;let a=t.importNode(o,!0),s=[...t.querySelectorAll(De)].find(c=>c.getAttribute("merge")===i);s?s.replaceWith(a):t.querySelector("article[data-blockeditor]").after(a)}return(t.doctype?`<!DOCTYPE ${t.doctype.name}>
3
+ `:"")+t.documentElement.outerHTML}async function He(e,{doc:t=document,loc:r=location,fetchFn:l=(n,o)=>fetch(n,o)}={}){if((typeof window<"u"&&window.clay||{}).isDraftMode)return{ok:!1,code:"draft"};if(!e||typeof e.version!="string")return{ok:!1,code:"unavailable",message:x};let o=ar(e,t,r);if(!o)return{ok:!1,code:"unavailable",message:x};let i=await Pe(l,o);if(!i)return{ok:!1,code:"unavailable",message:x};let a;try{a=await i.json()}catch{return{ok:!1,code:"unavailable",message:x}}if(!a||typeof a!="object")return{ok:!1,code:"unavailable",message:x};let s=sr(t);if(!s||a.id!==s.id||a.variant!==s.variant)return{ok:!1,code:"template",message:"This upgrade is for a different document."};let c=b(t,"hyper-version");if(!c||typeof a.version!="string"||!Q(a.version,c))return{ok:!1,code:"not-newer",message:"There is no newer version to install."};if(typeof a.html!="string"||!a.html)return{ok:!1,code:"unavailable",message:x};let f;try{f=new URL(a.html,o).href}catch{return{ok:!1,code:"unavailable",message:x}}if(!/^https:\/\/hyperclay\.com\/templates\//.test(f))return{ok:!1,code:"source",message:"This upgrade is not from the template host."};let u=await Pe(l,f);if(!u)return{ok:!1,code:"unavailable",message:x};let d;try{d=await u.text()}catch{return{ok:!1,code:"unavailable",message:x}}let m=await ir(new TextEncoder().encode(d));if(!m||m!==String(a.sha256||"").toLowerCase())return{ok:!1,code:"unavailable",message:x};let p,w;try{w=await dr(d),p=await D.run({sourceUrl:f,doc:t,loc:r,fromVersion:c,fetchFn:async()=>({ok:!0,status:200,text:async()=>d})})}catch(O){return{ok:!1,code:"transform",message:O&&O.message?O.message:x}}let v=new DOMParser().parseFromString(p.html,"text/html"),h=D.extractAll(t).dataByName,y=t.querySelector("article[data-blockeditor]");if(!y&&!Object.keys(h||{}).length)return{ok:!1,code:"undeclared",message:lr};let g=p.html;if(y){let O=pr(t,v,y);if(!O)return{ok:!1,code:"lost",lost:[],discarded:0,message:or};g=O}let A=D.extractAll(v).dataByName,T=cr(h,A,w),k=p.summary&&p.summary.totals&&p.summary.totals.discarded||0;return T.length||k>0?{ok:!1,code:"lost",lost:T,discarded:k,message:hr(T,k)}:{ok:!0,html:g,version:p.toVersion||a.version}}function hr(e,t){let r=e.slice(0,5).map(({path:n})=>n),l=e.length>r.length?` and ${e.length-r.length} more`:"";return r.length?`This upgrade would lose data: ${r.join(", ")}${l}. Nothing was changed.`:`This upgrade would lose ${t} value${t===1?"":"s"}. Nothing was changed.`}function mr(e){let t=e&&e.state;if(t==="conflict")return{ok:!1,code:"conflict",message:qe};let r=e&&e.message?e.message:"The document could not be saved.";return{ok:!1,code:"flush",state:t||"failed",message:r}}async function Be(e,{doc:t=document,loc:r=location,fetchFn:l=(s,c)=>fetch(s,c),clay:n=typeof window<"u"?window.clay:null,reload:o=()=>window.location.reload(),replace:i=null,etag:a}={}){if((n||{}).isDraftMode)return{ok:!1,code:"draft"};let c=K("upgrade");if(!c)return{ok:!1,code:"busy",message:nr};try{return await yr(e,{doc:t,loc:r,fetchFn:l,clay:n,reload:o,replace:i,etag:a})}finally{Z(c)}}async function yr(e,{doc:t,loc:r,fetchFn:l,clay:n,reload:o,replace:i,etag:a}){let s=n||{};if(s.isEditMode&&s.save&&typeof s.save.flush=="function"){let p;try{p=await s.save.flush()}catch(w){return mr(w)}if(p&&typeof p.state=="string"&&p.state!=="saved"&&p.state!=="clean"&&p.state!=="view")return{ok:!1,code:"flush",state:p.state,message:"This document has changes that could not be saved. Nothing was changed."}}if(a===void 0&&!B())try{await X()}catch{}let c=a!==void 0?a:B(),f=t;if(s.isEditMode&&typeof s.getHTML=="function")try{f=new DOMParser().parseFromString(await s.getHTML(),"text/html")}catch{return{ok:!1,code:"failed",message:q}}else f=new DOMParser().parseFromString(`<!DOCTYPE html>
4
+ `+t.documentElement.outerHTML,"text/html");let u=await He(e,{doc:f,loc:r,fetchFn:l});if(!u.ok)return u;let d=typeof i=="function"?i:s.save&&typeof s.save.replace=="function"?s.save.replace:ee,m;try{m=await d(u.html,{etag:c})}catch{return{ok:!1,code:"failed",message:q}}if(!m||!m.ok){let p=m&&m.code?m.code:"failed";return p==="conflict"?{ok:!1,code:p,message:qe}:p==="forbidden"?{ok:!1,code:p,message:"You are not allowed to save this document."}:p==="unsupported"?{ok:!1,code:p,message:"This host cannot save the upgrade."}:{ok:!1,code:p,message:q}}return o(),{ok:!0,html:u.html,version:u.version,etag:m.etag}}function E(e,t,r={}){let l=e.createElement(t);l.setAttribute("clay","editor-ui");for(let[n,o]of Object.entries(r))n==="style"?l.setAttribute("style",o):n==="text"?l.textContent=o:l.setAttribute(n,o);return l}function gr(e){let r=(e&&e.pathname?e.pathname:"/").split("/").filter(Boolean).pop()||"page.html";try{r=decodeURIComponent(r)}catch{}return/\.html?$/i.test(r)?r:`${r}.html`}async function wr(e,{loc:t=location,fetchFn:r=(l,n)=>fetch(l,n)}={}){if(typeof e.getHTML=="function")return e.getHTML();let l=await r(t.href,{cache:"no-store",credentials:"same-origin"});if(!l.ok)throw new Error(`copy fetch ${l.status}`);return l.text()}async function vr({clay:e,doc:t=document,loc:r=location,fetchFn:l}={}){if(typeof URL>"u"||typeof URL.createObjectURL!="function")return!1;try{let n=await wr(e,{loc:r,fetchFn:l});if(typeof n=="string"&&/clay|data-paid-only/i.test(n)){let{stripCopyContent:a}=await import("./c-C4IIQZGJ.js");n=a(n)}let o=URL.createObjectURL(new Blob([n],{type:"text/html"})),i=t.createElement("a");return i.setAttribute("clay","editor-ui"),i.href=o,i.download=gr(r),i.style.setProperty("display","none","important"),t.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(o),4e4),!0}catch{return!1}}async function br(e){let t=e&&e.host;if(!t||!t.versions)return!1;try{return await t.versions===!0}catch{return!1}}async function xr(e,t={}){let r=t.doc||document,l=t.clay||(typeof window<"u"?window.clay:null)||{};if(l.isDraftMode||!e||typeof e.version!="string")return null;let n=await br(l),o=E(r,"div",{role:"dialog","aria-modal":"true","data-clay-upgrade":"",style:"position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:16px;background:rgba(15,17,21,.42);font-family:system-ui,-apple-system,'Segoe UI',sans-serif;"}),i=E(r,"div",{style:"width:min(460px,100%);padding:20px;border-radius:14px;background:var(--clay-ui-bg,#fff);color:var(--clay-ui-fg,#1f2328);box-shadow:0 18px 48px -16px rgba(0,0,0,.55);font-size:14px;line-height:1.5;"}),a=E(r,"h2",{text:`Upgrade to version ${e.version}`,style:"margin:0 0 8px;font-size:16px;"}),s=E(r,"p",{text:`Your data moves into version ${e.version}. The page's layout and code are replaced; your current version stays in this document's history.`,style:"margin:0 0 16px;"}),c=E(r,"p",{role:"status",style:"margin:0 0 12px;min-height:1.5em;"}),f=E(r,"div",{style:"display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end;"}),u="padding:7px 12px;border-radius:8px;border:1px solid rgba(23,28,36,.2);background:transparent;color:inherit;font:inherit;cursor:pointer;",d=E(r,"button",{type:"button",text:"Cancel",style:u}),m=n?null:E(r,"button",{type:"button",text:"Download a copy first",style:u}),p=E(r,"button",{type:"button",text:"Upgrade",style:`${u}border-color:transparent;background:#2f6fed;color:#fff;font-weight:600;`});n||(p.disabled=!0),m&&f.append(m),f.append(d,p),i.append(a,s,c,f),o.append(i),r.body.appendChild(o);let w=!1,v=()=>{w||(w=!0,o.remove())};m&&m.addEventListener("click",async()=>{await vr({clay:l,doc:r,loc:t.loc,fetchFn:t.fetchFn})?(p.disabled=!1,c.textContent="Your copy was downloaded."):c.textContent="The copy could not be downloaded. Nothing was changed."}),d.addEventListener("click",v);let h,y=new Promise(g=>{h=g});return p.addEventListener("click",async()=>{p.disabled=!0,m&&(m.disabled=!0),c.textContent=`Upgrading to version ${e.version}\u2026`;let g=await Be(e,t);if(g.ok){v(),h(g);return}c.textContent=g.message||q,p.disabled=!1,m&&(m.disabled=!1),h(g)}),{root:o,title:a,body:s,status:c,cancel:d,download:m,upgrade:p,close:v,done:y}}export{Be as apply,He as prepare,xr as start};
@@ -1 +1 @@
1
- import{l as ne}from"./c-U4TWEIKZ.js";import"./c-VHNSBD2M.js";function J(e){let r=e?.name||"";return r==="QuotaExceededError"||r==="NS_ERROR_DOM_QUOTA_REACHED"?"quota":r==="VersionError"?"unknown-schema":r==="DataCloneError"?"uncloneable":r==="AbortError"||r==="TransactionInactiveError"||r==="InvalidStateError"?"aborted":r==="SecurityError"||r==="UnknownError"||r==="NotSupportedError"?"unavailable":"error"}var Te="clay-visitor-drafts",Ie=1,V="records",Q="parts",xe=2e3;function _(e,r){let d=new Error(`visitor-drafts: the draft database failed (${e})`);return d.code=e,r!==void 0&&(d.cause=r),d}function me(e,r){return new Promise((d,h)=>{let m=[],l=e.openCursor(r);l.onerror=()=>h(l.error),l.onsuccess=()=>{let s=l.result;if(!s)return d(m);m.push([s.key,s.value]),s.continue()}})}function ve({factory:e=globalThis.indexedDB,keyRange:r=globalThis.IDBKeyRange,name:d=Te,timeout:h=xe}={}){return new Promise((m,l)=>{if(!e||typeof e.open!="function"||!r)return l(_("unavailable"));let s;try{s=e.open(d,Ie)}catch(n){return l(_(J(n),n))}let b=!1,E=(n,k)=>b?!1:(b=!0,clearTimeout(a),n(k),!0),a=setTimeout(()=>E(l,_("blocked")),h);s.onupgradeneeded=()=>{let n=s.result;n.objectStoreNames.contains(V)||n.createObjectStore(V),n.objectStoreNames.contains(Q)||n.createObjectStore(Q)},s.onsuccess=()=>{let n=s.result;E(m,Ne(n,r))||n.close()},s.onerror=()=>E(l,_(J(s.error),s.error)),s.onblocked=()=>E(l,_("blocked"))})}function Ne(e,r){let d=!1;e.onversionchange=()=>{d=!0;try{e.close()}catch{}};function h(a,n){if(d)throw _("closed");try{return e.transaction(a,n)}catch(k){throw _(J(k),k)}}async function m(a){let n=h(V,"readonly"),k=r.bound(a,a+":\uFFFF");try{let v=await me(n.objectStore(V),k);return new Map(v.filter(([u])=>u===a||u.startsWith(a+":")))}catch(v){throw _(J(v),v)}}async function l(a,n){let k=h(Q,"readonly"),v=r.bound([a,n],[a,n,[]]);try{let u=await me(k.objectStore(Q),v);return new Map(u.map(([I,o])=>[I[2],o]))}catch(u){throw _(J(u),u)}}function s(a,n,{timeout:k=0,recovery:v=!1}={}){return new Promise((u,I)=>{let o;try{o=h([V,Q],"readwrite")}catch(i){return I(i)}let f=null,P,y=!1,D,C=(i,g)=>{y||(y=!0,clearTimeout(D),i(g))};k>0&&(D=setTimeout(()=>{f=_("blocked");try{o.abort()}catch{}C(I,f)},k)),o.oncomplete=()=>C(u,P),o.onabort=()=>C(I,f||_(o.error?J(o.error):"aborted",o.error));try{let i=o.objectStore(V),g=r.bound(a+":op:",a+":op:\uFFFF"),w={record:i.get(a),meta:i.get(a+":meta"),v1base:i.get(a+":v1base"),names:i.getAllKeys(g),values:i.getAll(g)},S=v?r.bound(a+":recovery:",a+":recovery:\uFFFF"):null;S&&(w.copyNames=i.getAllKeys(S),w.copyValues=i.getAll(S)),(w.copyValues??w.values).onsuccess=()=>{if(!y)try{let A={record:w.record.result??null,meta:w.meta.result??null,v1base:w.v1base.result??null,rows:w.names.result.map((N,R)=>[N,w.values.result[R]]),...S&&{recovery:w.copyNames.result.map((N,R)=>[N,w.copyValues.result[R]])}},M=n(A);for(let[N,R]of M.puts)i.put(R,N);for(let N of M.deletes)i.delete(N);P=M.result}catch(A){f=_(J(A),A);try{o.abort()}catch{}}}}catch(i){f=_(J(i),i);try{o.abort()}catch{}}})}function b(a,n){return new Promise((k,v)=>{if(!/:op:[^:]+$/.test(a))return v(_("bad-op"));let u;try{u=h(V,"readwrite"),u.objectStore(V).put(n,a),u.commit?.()}catch(I){return v(I instanceof Error&&I.code?I:_(J(I),I))}u.oncomplete=()=>k(),u.onabort=()=>v(_(u.error?J(u.error):"aborted",u.error))})}function E(){d=!0;try{e.close()}catch{}}return{readAll:m,readParts:l,change:s,putRow:b,close:E}}var x=e=>e===void 0?void 0:JSON.parse(JSON.stringify(e)),K=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Re=e=>e+":meta",ce=(e,r)=>`${e}:op:${r}`,ge=(e,r)=>r===void 0?e+":conflict":`${e}:conflict:${r}`,oe=(e,r)=>`${e}:recovery:${r}`,X=e=>K(e)&&e.v===1&&e.w===void 0&&K(e.data),L=e=>typeof e.id=="string"?e.id:"at:"+e.savedAt,we=(e,r)=>`${e}~${r}`;function Z(e){let r=/^(\d+)~/.exec(e??"");return r?Number(r[1]):null}function _e(e,r,d){let h={...e},m={...e};for(let[l,s]of Object.entries(r))"b"in s?h[l]=s.b:delete h[l],"m"in s?m[l]=s.m:delete m[l];return d(h,m,e)}var G=e=>K(e)&&typeof e.tab=="string"&&typeof e.reset=="string"&&Array.isArray(e.ops),$=e=>G(e)?`op:${e.tab}:${e.ops.at(-1)?.seq??e.acked??0}`:L(e);function se(e,r){if(K(e)&&e.v===1&&K(e.data))return x(e);if(!G(e)||!e.ops.length)return null;let d=x(r),h=null;for(let m of e.ops){for(let[l,s]of Object.entries(m.keys??{}))"m"in s?Object.defineProperty(d,l,{value:x(s.m),enumerable:!0,writable:!0,configurable:!0}):delete d[l];m.unit!==void 0&&(h=m.unit.to)}return{v:1,savedAt:e.ops.at(-1).savedAt,data:d,...h&&{live:x(h.live),blockeditor:x(h.blockeditor)}}}function fe(e,r){if(K(e)&&r.recovery?.includes($(e)))return!0;if(!G(e))return!1;let d=Math.max(e.acked??0,e.reset===r.reset?r.tabs[e.tab]?.seq??0:0);return e.ops.every(h=>h.seq<=d)}function ue(e=null){return{gen:Z(e)??1,rev:0,reset:e??"",tabs:{},foreign:null,unit:null}}var q=e=>e&&e.blockeditor?{live:e.live,blockeditor:e.blockeditor}:null;function ae(e,r,d){let h=[...e,r?.id,...r?.ancestry??[]].filter(m=>typeof m=="string");return h.length?h.slice(0,32):["root:"+d.reset]}function Me(e,{record:r,seen:d,direct:h,v1base:m,meta:l}){let s=K(d)&&d.v===1&&K(d.data)&&d.w?.reset===l.reset?d:null,b=a=>a&&typeof a.id=="string"?e.indexOf(a.id):-1,E=[[r,b(r)],[s,s&&h?0:b(s)],[m,b(m)]].filter(([,a])=>a>=0);return E.length?E.reduce((a,n)=>n[1]<a[1]?n:a)[0]:null}function De(e,{seed:r,newId:d,now:h,merge3:m,same:l,unitMark:s,marker:b=null,resets:E=[],chains:a=[],local:n=null,seen:k=null,direct:v=!1,recovery:u=null,copies:I=[]}){let o=e.meta?x(e.meta):ue(b);!e.meta&&Number.isInteger(n?.w?.rev)&&(o.rev=n.w.rev);let f=e.record?x(e.record):null,P=e.v1base?x(e.v1base):null,y={conflicts:[],recovered:[],released:[],dropped:[],stale:[],applied:{},changed:!e.meta};function D(i,g=[]){let w=$(i);if(o.recovery?.includes(w))return;y.recovered.push(x(i));let S=[w,...(o.recovery??[]).filter(A=>A!==w&&!g.includes(A))].slice(0,8);return y.dropped=[...new Set([...y.dropped,...o.recovery??[]])].filter(A=>!S.includes(A)),o.recovery=S,y.changed=!0,!0}let C=[...E];b&&b!==o.reset&&C.push({ends:Z(b)===null?null:Z(b)-1,marker:b});for(let i of C){if(i.marker===o.reset||o.ended?.includes(i.marker)||i.ends!==null&&i.ends<o.gen)continue;i.ends!==o.gen&&f&&D(f);let g=typeof n?.reset=="string"?n.reset===i.marker:i.ends===null||Array.isArray(n?.ancestry)&&n.ancestry.includes("root:"+i.marker);X(n)&&L(n)!==o.foreign&&!g&&(D(n),o.foreign=L(n)),o.ended=[...o.ended??[],o.reset].slice(-32),Object.assign(o,{gen:o.gen+1,reset:i.marker,tabs:{},unit:null}),o.rev++,f=null,P=null,y.changed=!0}if(!e.meta&&!f&&K(n)&&n.v===1&&K(n.data)&&(n.w===void 0||n.w.reset===o.reset)){let{w:i,...g}=n;f=x(g),i===void 0&&(P=x(g),o.foreign=L(n),o.rev++)}if(e.meta||(o.unit=s(q(f))),e.meta&&X(n)&&L(n)!==o.foreign){let i=L(n),g=Array.isArray(n.ancestry)?n.ancestry:[],w=f?Me(g,{record:f,seen:k,direct:v,v1base:P,meta:o}):null;if(typeof n.reset=="string"&&o.ended?.includes(n.reset))D(n,g)&&y.released.push(x(n));else if(!f)f=x(n),P=x(n),o.unit=s(q(f)),o.rev++;else if(w){let S=m(w.data,n.data,f.data),A=q(n),M=!!A&&s(A)!==s(q(w)),N=M&&q(f)&&s(q(w))!==o.unit;(S.conflict||N)&&y.conflicts.push(x(f));let R=M?A:q(f);f={v:1,savedAt:n.savedAt??new Date(h).toISOString(),id:d(),ancestry:ae(typeof n.id=="string"?[n.id]:[],f,o),data:S.value,...R&&{live:R.live,blockeditor:R.blockeditor}},M&&(o.unit=s(R)),P=x(n),o.rev++}else D(n,g)&&y.released.push(x(n));o.foreign=i,y.changed=!0}for(let i of a){if(!G(i))continue;if(i.reset!==o.reset){let S=i.reset===e.meta?.reset?e.meta.tabs[i.tab]?.seq??0:0;i.ops.some(A=>A.seq>Math.max(S,i.acked??0))&&D(i),y.stale.includes(i.tab)||y.stale.push(i.tab);continue}let g=o.tabs[i.tab]?.seq??0,w=Math.max(g,Number.isInteger(i.acked)?i.acked:0);for(let S of i.ops){if(S.seq<=w)continue;if(S.seq!==w+1)break;let A=_e(f?f.data:r,S.keys??{},m),M=S.unit!==void 0&&f&&q(f)&&S.unit.seen!==o.unit;f&&(A.conflict||M)&&y.conflicts.push(x(f));let N=S.unit!==void 0?S.unit.to:q(f),R=d();f={v:1,savedAt:S.savedAt??new Date(h).toISOString(),id:R,ancestry:ae([],f,o),data:A.value,...N&&{live:N.live,blockeditor:N.blockeditor}},S.unit!==void 0&&(o.unit=s(N)),o.rev++,w=S.seq,y.changed=!0}(w!==g||o.tabs[i.tab])&&(o.tabs[i.tab]={seq:w,at:h},y.changed=!0),y.applied[i.tab]=w}if(u){let i=I.find(([g])=>g===u.mark);if(!i)throw new Error("That draft is no longer available. Open the list again.");if(u.type==="remove")o.recovery=(o.recovery??[]).filter(g=>g!==u.mark),y.dropped.push(u.mark),y.removedMark=u.mark,y.changed=!0;else if(u.type==="restore"&&u.reset===o.reset){let g=se(i[1],r);if(!g)throw new Error("This draft cannot be restored by this version.");o.recovery?.includes(u.mark)&&(o.recovery=[u.mark,...o.recovery.filter(S=>S!==u.mark)]);let w=f&&I.some(([S,A])=>{if(!o.recovery?.includes(S))return!1;let M=se(A,r);return M&&l(f.data,M.data)&&l(q(f),q(M))});f&&!w&&D(f),f={v:1,savedAt:new Date(h).toISOString(),id:d(),ancestry:ae([],f,o),data:g.data,...g.blockeditor&&{live:g.live,blockeditor:g.blockeditor}},o.unit=s(q(f)),o.rev++,y.changed=!0,y.restoredCopy=!0}}for(let[i,g]of Object.entries(o.tabs))h-(g.at??0)>2592e6&&(delete o.tabs[i],y.changed=!0);return{meta:o,record:f,v1base:P,...y}}var z=e=>{if(e==null)return null;try{return JSON.parse(e)}catch{return null}};function ye(e,r,d,h){return e.change(r,m=>{let l={meta:z(m.meta),record:z(m.record),v1base:z(m.v1base)},s=m.rows.map(([v,u])=>[v,z(u)]),b=d(l),E=(m.recovery??[]).map(([v,u])=>[v.slice((r+":recovery:").length),z(u)]),a=De(l,{...b,copies:E,chains:[...s.map(([,v])=>v),...b.chains??[]]}),n=[],k=[];a.changed&&(n.push([Re(r),JSON.stringify(a.meta)]),a.record?n.push([r,JSON.stringify(a.record)]):l.record&&k.push(r),a.v1base?n.push([r+":v1base",JSON.stringify(a.v1base)]):l.v1base&&k.push(r+":v1base"));for(let v of a.conflicts)n.push([ge(r,L(v)),JSON.stringify(v)]);a.conflicts.length&&n.push([ge(r),JSON.stringify(a.conflicts[a.conflicts.length-1])]);for(let v of a.recovered)n.push([oe(r,$(v)),JSON.stringify(v)]);for(let v of a.dropped)k.push(oe(r,v));for(let[v,u]of s)(fe(u,a.meta)||a.removedMark&&G(u)&&$(u)===a.removedMark)&&k.push(v);return{puts:n,deletes:k,result:a}},h)}var Pe=256*1024,qe=2*1024,Je=new Set(["v","savedAt","id","ancestry","reset","data"]),Ce=10*1e3,Ke=1500,be=2e3,Le="This draft was started over in another tab.",Ve="This draft was started over in another tab. The earlier draft was kept aside in this browser.",$e="A tab that was open before an update saved another copy of this draft. That copy was kept aside, and this draft was not changed. Reload that tab to go on from this draft.",U=e=>{if(e==null)return null;try{return JSON.parse(e)}catch{return null}};function je(e,r){let d={},h=Object.keys(e).every(m=>Je.has(m));for(let[m,l]of Object.entries(e.data))JSON.stringify(l).length<qe?d[m]=l:h=!1;return JSON.stringify({v:2,savedAt:e.savedAt,id:e.id,ancestry:e.ancestry,idb:!0,...h&&{full:!0},data:d,w:r})}async function Qe({store:e,storage:r,doc:d=document,now:h=()=>Date.now(),reload:m=()=>window.location.reload()}){let l=await ve(),{key:s}=e,b=s+":reset",E=t=>{try{return r?.getItem(t)??null}catch{return null}},a=t=>{try{r?.removeItem(t)}catch{}},n=s+":started-over",k=s+":recovery-notice";try{window.sessionStorage.getItem(n)&&(window.sessionStorage.removeItem(n),window.sessionStorage.getItem(k)||import("./c-NVU3DORS.js").then(t=>t.toastPersistent(Le,"info")).catch(()=>{}))}catch{}let v=null,u="",I=null,o=null,f=null,P=0,y=!1,D=!1,C=e.held()?.id,i=null,g=null,w=new Set;try{let t=window.sessionStorage.getItem(k);if(t){window.sessionStorage.removeItem(k);let c=U(t);le({id:c?.mark??t},!!c?.reset)}}catch{}function S(t){try{window.sessionStorage.setItem(k,JSON.stringify({mark:t,reset:!0}))}catch{}}function A(t){try{window.sessionStorage.setItem(s+":generation",JSON.stringify({marker:u,reset:t}))}catch{}}function M(){let t=E(b);u=t??"";let c=e.journalSlots().filter(T=>T!==e.slotKey).map(T=>U(E(T)));f=e.stopped()?null:o,P=e.chain().ops.at(-1)?.seq??0;let p=e.held();p?.v===1&&p.w!==void 0&&(i=p);let O=f?[f]:[];return{seed:e.seed(),newId:e.newId,merge3:e.merge3,same:e.same,unitMark:e.unitMark,now:h(),marker:t,resets:O,local:p,seen:i,direct:g!==null&&E(s)===g,chains:e.pending()?[...c,e.chain()]:c}}function N(t,c){let p=h();for(let O of e.journalSlots()){if(O===e.slotKey)continue;let T=U(E(O));(c&&G(T)&&$(T)===c||fe(T,t)&&p-(T?.at??0)>Ce)&&a(O)}}function R({meta:t,record:c}){let p=e.held();if(X(p)&&L(p)!==t.foreign)return void setTimeout(Y,0);if((E(b)??"")!==t.reset)return;if(!c)return void(p&&a(s));if(p?.w&&p.w.reset===t.reset&&p.w.rev>=t.rev)return;let O={rev:t.rev,reset:t.reset},T=JSON.stringify({...c,w:O});try{if(T.length<=Pe){r.setItem(s,T),i={...c,w:O};return}}catch{}try{r.setItem(s,je(c,O))}catch{}}async function de(){if(e.stop({keepPending:!0}),e.unsafe()){try{await l.putRow(ce(s,e.tab),JSON.stringify(e.chain()))}catch(t){throw e.failed(t)}e.acknowledge(e.chain().ops.at(-1)?.seq??0)}}async function ie(t){try{e.captureLate()}catch(W){throw e.failed(W)}y=!0;let c=e.chain(),p=$(c),O=c.ops.some(W=>W.seq>P)||t.meta.recovery?.includes(p)?p:t.meta.recovery?.includes(C)?C:null;e.acknowledge(P),await de(),R(t),O&&S(O);let T=e.held();T?.w&&T.w.reset!==t.meta.reset&&a(s);try{window.sessionStorage.setItem(n,"1")}catch{}return A(t.meta.reset),y=!1,m(),t}async function Se(){let t=e.generation(),c=()=>{e.stop(),ne(!1)},p=()=>(E(b)??"")!==t&&(I===null||(E(b)??"")!==u);if(p())return c();let O=I??Z(t);if(O===null){let F=await re.catch(()=>l.change(s,({meta:H})=>({puts:[],deletes:[],result:{meta:U(H)??ue(t)}}),{timeout:be}));if(p())return c();if(O=F.meta.gen,F.meta.reset!==t){o={ends:null,marker:t};let H=await te();if(e.stopped())return c();O=H.meta.gen}}let T=we(O+1,e.newId());o={ends:O,marker:T};let W=E(s);e.held()?.w&&a(s);try{r.setItem(b,T)}catch{}let he;try{let F=te();E(b)!==T?await F:await Promise.race([F.catch(()=>{}),new Promise(H=>{he=setTimeout(H,Ke)})]),c()}catch(F){if(o=null,W!==null&&E(s)===null&&(E(b)??"")===t)try{r.setItem(s,W)}catch{}throw F}finally{clearTimeout(he)}}function le(t,c=!1){console.warn(c?"visitor-drafts: the draft was started over; the earlier draft was kept in this browser's draft database under":"visitor-drafts: a tab on an earlier ClayJS saved a copy that could not be merged exactly; it was kept in this browser's draft database under",oe(s,$(t))),!w.has(c)&&(w.add(c),import("./c-NVU3DORS.js").then(p=>p.toastPersistent(c?Ve:$e,"warning")).catch(()=>{}))}function Ee(t){let{meta:c,record:p}=t;if(u!==c.reset&&(E(b)??"")===u)try{r.setItem(b,c.reset)}catch{}if(f&&f===o&&c.reset!==e.generation()&&(f.marker===c.reset&&A(c.reset),e.stop(),ne(!1)),f===o&&(o=null),e.stopped())return y?ie(t):(R(t),t);if(t.conflicts.length&&console.warn("visitor-drafts: another tab changed the same thing; its copy was kept in this browser's draft database under",s+":conflict"),t.stale.includes(e.tab))return ie(t);if(c.reset!==e.generation()){if(!e.fresh())return ie(t);e.enter(c.reset)}t.released.length&&le(t.released[0]),I=c.gen,A(c.reset);let O=e.acknowledge(c.tabs[e.tab]?.seq??0);if(N(c,t.removedMark),R(t),e.pending()||(O&&(ne(!1),d.dispatchEvent(new CustomEvent("clay:drafts-saved",{detail:{data:p.data}}))),D))return t;if(!e.shown())return v=c.rev,t;e.changed()||(p&&c.rev!==v&&e.take(p.data),C=p?.id,v=c.rev);let T=e.externalUnit(p);return T&&d.dispatchEvent(new CustomEvent("clay:drafts-blockeditor-external",{detail:{live:T.live,adopted:()=>e.adoptedUnit(T)}})),t}let j=null,B=null;function ee(t,c=null){return j=ye(l,s,()=>{if(c?.type==="restore"){if(e.stopped())throw new Error("This page has started over. Reload it before restoring a draft.");e.captureNow()}return{...M(),recovery:c}},t).then(Ee,O=>{throw e.pending()?e.failed(O):O}).finally(()=>{j=null}),j}function te(){return B||(j?(B=j.then(()=>{},()=>{}).then(()=>(B=null,ee())),B):ee())}async function pe(t){for(;j||B;)await(B??j).catch(()=>{});return ee({recovery:!0},t)}async function ke(t){if(D)throw new Error("A draft is already being restored.");D=!0;try{if(e.stopped())throw new Error("This page has started over. Reload it before restoring a draft.");e.captureNow();let c;do if(c=await pe({type:"restore",mark:t,reset:e.generation()}),!c.restoredCopy||e.stopped())throw new Error("This page has started over. Reload it before restoring a draft.");while(e.pending());try{e.captureLate("restored:"+e.tab)}catch(p){throw e.failed(p)}return await de(),m(),c}finally{D=!1}}async function Oe(){await re.catch(()=>{});let t=s+":recovery:";return[...await l.readAll(s)].filter(([p])=>p.startsWith(t)).map(([p,O])=>({mark:p.slice(t.length),copy:U(O)}))}let Y=()=>{te().catch(()=>{})};function Ae(){e.unsafe()&&l.putRow(ce(s,e.tab),JSON.stringify(e.chain())).catch(()=>{}),e.pending()&&Y()}window.addEventListener("storage",t=>{if(t.key===s){let[c,p]=[U(t.oldValue),U(t.newValue)];p?.v===1&&p.w!==void 0?i=p:X(p)&&c?.v===1&&c.w!==void 0&&([i,g]=[c,t.newValue])}(t.key===null||t.key===s||t.key===b)&&Y()}),window.addEventListener("pageshow",t=>{t.persisted&&Y()}),d.addEventListener("clay:drafts-blockeditor-listening",Y);let re=ee({timeout:be});return re.catch(()=>{}),{first:re,sync:te,hide:Ae,startOver:Se,listRecovery:Oe,restoreRecovery:ke,recoveryRecord:t=>se(t,e.seed()),removeRecovery:t=>pe({type:"remove",mark:t})}}export{Pe as FULL_COPY_LIMIT,Qe as openSession};
1
+ import{l as ne}from"./c-U4TWEIKZ.js";import"./c-VHNSBD2M.js";function J(e){let r=e?.name||"";return r==="QuotaExceededError"||r==="NS_ERROR_DOM_QUOTA_REACHED"?"quota":r==="VersionError"?"unknown-schema":r==="DataCloneError"?"uncloneable":r==="AbortError"||r==="TransactionInactiveError"||r==="InvalidStateError"?"aborted":r==="SecurityError"||r==="UnknownError"||r==="NotSupportedError"?"unavailable":"error"}var Te="clay-visitor-drafts",Ie=1,V="records",Q="parts",xe=2e3;function _(e,r){let d=new Error(`visitor-drafts: the draft database failed (${e})`);return d.code=e,r!==void 0&&(d.cause=r),d}function me(e,r){return new Promise((d,h)=>{let m=[],l=e.openCursor(r);l.onerror=()=>h(l.error),l.onsuccess=()=>{let s=l.result;if(!s)return d(m);m.push([s.key,s.value]),s.continue()}})}function ve({factory:e=globalThis.indexedDB,keyRange:r=globalThis.IDBKeyRange,name:d=Te,timeout:h=xe}={}){return new Promise((m,l)=>{if(!e||typeof e.open!="function"||!r)return l(_("unavailable"));let s;try{s=e.open(d,Ie)}catch(n){return l(_(J(n),n))}let b=!1,E=(n,k)=>b?!1:(b=!0,clearTimeout(a),n(k),!0),a=setTimeout(()=>E(l,_("blocked")),h);s.onupgradeneeded=()=>{let n=s.result;n.objectStoreNames.contains(V)||n.createObjectStore(V),n.objectStoreNames.contains(Q)||n.createObjectStore(Q)},s.onsuccess=()=>{let n=s.result;E(m,Ne(n,r))||n.close()},s.onerror=()=>E(l,_(J(s.error),s.error)),s.onblocked=()=>E(l,_("blocked"))})}function Ne(e,r){let d=!1;e.onversionchange=()=>{d=!0;try{e.close()}catch{}};function h(a,n){if(d)throw _("closed");try{return e.transaction(a,n)}catch(k){throw _(J(k),k)}}async function m(a){let n=h(V,"readonly"),k=r.bound(a,a+":\uFFFF");try{let v=await me(n.objectStore(V),k);return new Map(v.filter(([u])=>u===a||u.startsWith(a+":")))}catch(v){throw _(J(v),v)}}async function l(a,n){let k=h(Q,"readonly"),v=r.bound([a,n],[a,n,[]]);try{let u=await me(k.objectStore(Q),v);return new Map(u.map(([I,o])=>[I[2],o]))}catch(u){throw _(J(u),u)}}function s(a,n,{timeout:k=0,recovery:v=!1}={}){return new Promise((u,I)=>{let o;try{o=h([V,Q],"readwrite")}catch(i){return I(i)}let f=null,P,y=!1,D,C=(i,g)=>{y||(y=!0,clearTimeout(D),i(g))};k>0&&(D=setTimeout(()=>{f=_("blocked");try{o.abort()}catch{}C(I,f)},k)),o.oncomplete=()=>C(u,P),o.onabort=()=>C(I,f||_(o.error?J(o.error):"aborted",o.error));try{let i=o.objectStore(V),g=r.bound(a+":op:",a+":op:\uFFFF"),w={record:i.get(a),meta:i.get(a+":meta"),v1base:i.get(a+":v1base"),names:i.getAllKeys(g),values:i.getAll(g)},S=v?r.bound(a+":recovery:",a+":recovery:\uFFFF"):null;S&&(w.copyNames=i.getAllKeys(S),w.copyValues=i.getAll(S)),(w.copyValues??w.values).onsuccess=()=>{if(!y)try{let A={record:w.record.result??null,meta:w.meta.result??null,v1base:w.v1base.result??null,rows:w.names.result.map((N,R)=>[N,w.values.result[R]]),...S&&{recovery:w.copyNames.result.map((N,R)=>[N,w.copyValues.result[R]])}},M=n(A);for(let[N,R]of M.puts)i.put(R,N);for(let N of M.deletes)i.delete(N);P=M.result}catch(A){f=_(J(A),A);try{o.abort()}catch{}}}}catch(i){f=_(J(i),i);try{o.abort()}catch{}}})}function b(a,n){return new Promise((k,v)=>{if(!/:op:[^:]+$/.test(a))return v(_("bad-op"));let u;try{u=h(V,"readwrite"),u.objectStore(V).put(n,a),u.commit?.()}catch(I){return v(I instanceof Error&&I.code?I:_(J(I),I))}u.oncomplete=()=>k(),u.onabort=()=>v(_(u.error?J(u.error):"aborted",u.error))})}function E(){d=!0;try{e.close()}catch{}}return{readAll:m,readParts:l,change:s,putRow:b,close:E}}var x=e=>e===void 0?void 0:JSON.parse(JSON.stringify(e)),K=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Re=e=>e+":meta",ce=(e,r)=>`${e}:op:${r}`,ge=(e,r)=>r===void 0?e+":conflict":`${e}:conflict:${r}`,oe=(e,r)=>`${e}:recovery:${r}`,X=e=>K(e)&&e.v===1&&e.w===void 0&&K(e.data),L=e=>typeof e.id=="string"?e.id:"at:"+e.savedAt,we=(e,r)=>`${e}~${r}`;function Z(e){let r=/^(\d+)~/.exec(e??"");return r?Number(r[1]):null}function _e(e,r,d){let h={...e},m={...e};for(let[l,s]of Object.entries(r))"b"in s?h[l]=s.b:delete h[l],"m"in s?m[l]=s.m:delete m[l];return d(h,m,e)}var G=e=>K(e)&&typeof e.tab=="string"&&typeof e.reset=="string"&&Array.isArray(e.ops),$=e=>G(e)?`op:${e.tab}:${e.ops.at(-1)?.seq??e.acked??0}`:L(e);function se(e,r){if(K(e)&&e.v===1&&K(e.data))return x(e);if(!G(e)||!e.ops.length)return null;let d=x(r),h=null;for(let m of e.ops){for(let[l,s]of Object.entries(m.keys??{}))"m"in s?Object.defineProperty(d,l,{value:x(s.m),enumerable:!0,writable:!0,configurable:!0}):delete d[l];m.unit!==void 0&&(h=m.unit.to)}return{v:1,savedAt:e.ops.at(-1).savedAt,data:d,...h&&{live:x(h.live),blockeditor:x(h.blockeditor)}}}function fe(e,r){if(K(e)&&r.recovery?.includes($(e)))return!0;if(!G(e))return!1;let d=Math.max(e.acked??0,e.reset===r.reset?r.tabs[e.tab]?.seq??0:0);return e.ops.every(h=>h.seq<=d)}function ue(e=null){return{gen:Z(e)??1,rev:0,reset:e??"",tabs:{},foreign:null,unit:null}}var q=e=>e&&e.blockeditor?{live:e.live,blockeditor:e.blockeditor}:null;function ae(e,r,d){let h=[...e,r?.id,...r?.ancestry??[]].filter(m=>typeof m=="string");return h.length?h.slice(0,32):["root:"+d.reset]}function Me(e,{record:r,seen:d,direct:h,v1base:m,meta:l}){let s=K(d)&&d.v===1&&K(d.data)&&d.w?.reset===l.reset?d:null,b=a=>a&&typeof a.id=="string"?e.indexOf(a.id):-1,E=[[r,b(r)],[s,s&&h?0:b(s)],[m,b(m)]].filter(([,a])=>a>=0);return E.length?E.reduce((a,n)=>n[1]<a[1]?n:a)[0]:null}function De(e,{seed:r,newId:d,now:h,merge3:m,same:l,unitMark:s,marker:b=null,resets:E=[],chains:a=[],local:n=null,seen:k=null,direct:v=!1,recovery:u=null,copies:I=[]}){let o=e.meta?x(e.meta):ue(b);!e.meta&&Number.isInteger(n?.w?.rev)&&(o.rev=n.w.rev);let f=e.record?x(e.record):null,P=e.v1base?x(e.v1base):null,y={conflicts:[],recovered:[],released:[],dropped:[],stale:[],applied:{},changed:!e.meta};function D(i,g=[]){let w=$(i);if(o.recovery?.includes(w))return;y.recovered.push(x(i));let S=[w,...(o.recovery??[]).filter(A=>A!==w&&!g.includes(A))].slice(0,8);return y.dropped=[...new Set([...y.dropped,...o.recovery??[]])].filter(A=>!S.includes(A)),o.recovery=S,y.changed=!0,!0}let C=[...E];b&&b!==o.reset&&C.push({ends:Z(b)===null?null:Z(b)-1,marker:b});for(let i of C){if(i.marker===o.reset||o.ended?.includes(i.marker)||i.ends!==null&&i.ends<o.gen)continue;i.ends!==o.gen&&f&&D(f);let g=typeof n?.reset=="string"?n.reset===i.marker:i.ends===null||Array.isArray(n?.ancestry)&&n.ancestry.includes("root:"+i.marker);X(n)&&L(n)!==o.foreign&&!g&&(D(n),o.foreign=L(n)),o.ended=[...o.ended??[],o.reset].slice(-32),Object.assign(o,{gen:o.gen+1,reset:i.marker,tabs:{},unit:null}),o.rev++,f=null,P=null,y.changed=!0}if(!e.meta&&!f&&K(n)&&n.v===1&&K(n.data)&&(n.w===void 0||n.w.reset===o.reset)){let{w:i,...g}=n;f=x(g),i===void 0&&(P=x(g),o.foreign=L(n),o.rev++)}if(e.meta||(o.unit=s(q(f))),e.meta&&X(n)&&L(n)!==o.foreign){let i=L(n),g=Array.isArray(n.ancestry)?n.ancestry:[],w=f?Me(g,{record:f,seen:k,direct:v,v1base:P,meta:o}):null;if(typeof n.reset=="string"&&o.ended?.includes(n.reset))D(n,g)&&y.released.push(x(n));else if(!f)f=x(n),P=x(n),o.unit=s(q(f)),o.rev++;else if(w){let S=m(w.data,n.data,f.data),A=q(n),M=!!A&&s(A)!==s(q(w)),N=M&&q(f)&&s(q(w))!==o.unit;(S.conflict||N)&&y.conflicts.push(x(f));let R=M?A:q(f);f={v:1,savedAt:n.savedAt??new Date(h).toISOString(),id:d(),ancestry:ae(typeof n.id=="string"?[n.id]:[],f,o),data:S.value,...R&&{live:R.live,blockeditor:R.blockeditor}},M&&(o.unit=s(R)),P=x(n),o.rev++}else D(n,g)&&y.released.push(x(n));o.foreign=i,y.changed=!0}for(let i of a){if(!G(i))continue;if(i.reset!==o.reset){let S=i.reset===e.meta?.reset?e.meta.tabs[i.tab]?.seq??0:0;i.ops.some(A=>A.seq>Math.max(S,i.acked??0))&&D(i),y.stale.includes(i.tab)||y.stale.push(i.tab);continue}let g=o.tabs[i.tab]?.seq??0,w=Math.max(g,Number.isInteger(i.acked)?i.acked:0);for(let S of i.ops){if(S.seq<=w)continue;if(S.seq!==w+1)break;let A=_e(f?f.data:r,S.keys??{},m),M=S.unit!==void 0&&f&&q(f)&&S.unit.seen!==o.unit;f&&(A.conflict||M)&&y.conflicts.push(x(f));let N=S.unit!==void 0?S.unit.to:q(f),R=d();f={v:1,savedAt:S.savedAt??new Date(h).toISOString(),id:R,ancestry:ae([],f,o),data:A.value,...N&&{live:N.live,blockeditor:N.blockeditor}},S.unit!==void 0&&(o.unit=s(N)),o.rev++,w=S.seq,y.changed=!0}(w!==g||o.tabs[i.tab])&&(o.tabs[i.tab]={seq:w,at:h},y.changed=!0),y.applied[i.tab]=w}if(u){let i=I.find(([g])=>g===u.mark);if(!i)throw new Error("That draft is no longer available. Open the list again.");if(u.type==="remove")o.recovery=(o.recovery??[]).filter(g=>g!==u.mark),y.dropped.push(u.mark),y.removedMark=u.mark,y.changed=!0;else if(u.type==="restore"&&u.reset===o.reset){let g=se(i[1],r);if(!g)throw new Error("This draft cannot be restored by this version.");o.recovery?.includes(u.mark)&&(o.recovery=[u.mark,...o.recovery.filter(S=>S!==u.mark)]);let w=f&&I.some(([S,A])=>{if(!o.recovery?.includes(S))return!1;let M=se(A,r);return M&&l(f.data,M.data)&&l(q(f),q(M))});f&&!w&&D(f),f={v:1,savedAt:new Date(h).toISOString(),id:d(),ancestry:ae([],f,o),data:g.data,...g.blockeditor&&{live:g.live,blockeditor:g.blockeditor}},o.unit=s(q(f)),o.rev++,y.changed=!0,y.restoredCopy=!0}}for(let[i,g]of Object.entries(o.tabs))h-(g.at??0)>2592e6&&(delete o.tabs[i],y.changed=!0);return{meta:o,record:f,v1base:P,...y}}var z=e=>{if(e==null)return null;try{return JSON.parse(e)}catch{return null}};function ye(e,r,d,h){return e.change(r,m=>{let l={meta:z(m.meta),record:z(m.record),v1base:z(m.v1base)},s=m.rows.map(([v,u])=>[v,z(u)]),b=d(l),E=(m.recovery??[]).map(([v,u])=>[v.slice((r+":recovery:").length),z(u)]),a=De(l,{...b,copies:E,chains:[...s.map(([,v])=>v),...b.chains??[]]}),n=[],k=[];a.changed&&(n.push([Re(r),JSON.stringify(a.meta)]),a.record?n.push([r,JSON.stringify(a.record)]):l.record&&k.push(r),a.v1base?n.push([r+":v1base",JSON.stringify(a.v1base)]):l.v1base&&k.push(r+":v1base"));for(let v of a.conflicts)n.push([ge(r,L(v)),JSON.stringify(v)]);a.conflicts.length&&n.push([ge(r),JSON.stringify(a.conflicts[a.conflicts.length-1])]);for(let v of a.recovered)n.push([oe(r,$(v)),JSON.stringify(v)]);for(let v of a.dropped)k.push(oe(r,v));for(let[v,u]of s)(fe(u,a.meta)||a.removedMark&&G(u)&&$(u)===a.removedMark)&&k.push(v);return{puts:n,deletes:k,result:a}},h)}var Pe=256*1024,qe=2*1024,Je=new Set(["v","savedAt","id","ancestry","reset","data"]),Ce=10*1e3,Ke=1500,be=2e3,Le="This draft was started over in another tab.",Ve="This draft was started over in another tab. The earlier draft was kept aside in this browser.",$e="A tab that was open before an update saved another copy of this draft. That copy was kept aside, and this draft was not changed. Reload that tab to go on from this draft.",U=e=>{if(e==null)return null;try{return JSON.parse(e)}catch{return null}};function je(e,r){let d={},h=Object.keys(e).every(m=>Je.has(m));for(let[m,l]of Object.entries(e.data))JSON.stringify(l).length<qe?d[m]=l:h=!1;return JSON.stringify({v:2,savedAt:e.savedAt,id:e.id,ancestry:e.ancestry,idb:!0,...h&&{full:!0},data:d,w:r})}async function Qe({store:e,storage:r,doc:d=document,now:h=()=>Date.now(),reload:m=()=>window.location.reload()}){let l=await ve(),{key:s}=e,b=s+":reset",E=t=>{try{return r?.getItem(t)??null}catch{return null}},a=t=>{try{r?.removeItem(t)}catch{}},n=s+":started-over",k=s+":recovery-notice";try{window.sessionStorage.getItem(n)&&(window.sessionStorage.removeItem(n),window.sessionStorage.getItem(k)||import("./c-C6DXZIXD.js").then(t=>t.toastPersistent(Le,"info")).catch(()=>{}))}catch{}let v=null,u="",I=null,o=null,f=null,P=0,y=!1,D=!1,C=e.held()?.id,i=null,g=null,w=new Set;try{let t=window.sessionStorage.getItem(k);if(t){window.sessionStorage.removeItem(k);let c=U(t);le({id:c?.mark??t},!!c?.reset)}}catch{}function S(t){try{window.sessionStorage.setItem(k,JSON.stringify({mark:t,reset:!0}))}catch{}}function A(t){try{window.sessionStorage.setItem(s+":generation",JSON.stringify({marker:u,reset:t}))}catch{}}function M(){let t=E(b);u=t??"";let c=e.journalSlots().filter(T=>T!==e.slotKey).map(T=>U(E(T)));f=e.stopped()?null:o,P=e.chain().ops.at(-1)?.seq??0;let p=e.held();p?.v===1&&p.w!==void 0&&(i=p);let O=f?[f]:[];return{seed:e.seed(),newId:e.newId,merge3:e.merge3,same:e.same,unitMark:e.unitMark,now:h(),marker:t,resets:O,local:p,seen:i,direct:g!==null&&E(s)===g,chains:e.pending()?[...c,e.chain()]:c}}function N(t,c){let p=h();for(let O of e.journalSlots()){if(O===e.slotKey)continue;let T=U(E(O));(c&&G(T)&&$(T)===c||fe(T,t)&&p-(T?.at??0)>Ce)&&a(O)}}function R({meta:t,record:c}){let p=e.held();if(X(p)&&L(p)!==t.foreign)return void setTimeout(Y,0);if((E(b)??"")!==t.reset)return;if(!c)return void(p&&a(s));if(p?.w&&p.w.reset===t.reset&&p.w.rev>=t.rev)return;let O={rev:t.rev,reset:t.reset},T=JSON.stringify({...c,w:O});try{if(T.length<=Pe){r.setItem(s,T),i={...c,w:O};return}}catch{}try{r.setItem(s,je(c,O))}catch{}}async function de(){if(e.stop({keepPending:!0}),e.unsafe()){try{await l.putRow(ce(s,e.tab),JSON.stringify(e.chain()))}catch(t){throw e.failed(t)}e.acknowledge(e.chain().ops.at(-1)?.seq??0)}}async function ie(t){try{e.captureLate()}catch(W){throw e.failed(W)}y=!0;let c=e.chain(),p=$(c),O=c.ops.some(W=>W.seq>P)||t.meta.recovery?.includes(p)?p:t.meta.recovery?.includes(C)?C:null;e.acknowledge(P),await de(),R(t),O&&S(O);let T=e.held();T?.w&&T.w.reset!==t.meta.reset&&a(s);try{window.sessionStorage.setItem(n,"1")}catch{}return A(t.meta.reset),y=!1,m(),t}async function Se(){let t=e.generation(),c=()=>{e.stop(),ne(!1)},p=()=>(E(b)??"")!==t&&(I===null||(E(b)??"")!==u);if(p())return c();let O=I??Z(t);if(O===null){let F=await re.catch(()=>l.change(s,({meta:H})=>({puts:[],deletes:[],result:{meta:U(H)??ue(t)}}),{timeout:be}));if(p())return c();if(O=F.meta.gen,F.meta.reset!==t){o={ends:null,marker:t};let H=await te();if(e.stopped())return c();O=H.meta.gen}}let T=we(O+1,e.newId());o={ends:O,marker:T};let W=E(s);e.held()?.w&&a(s);try{r.setItem(b,T)}catch{}let he;try{let F=te();E(b)!==T?await F:await Promise.race([F.catch(()=>{}),new Promise(H=>{he=setTimeout(H,Ke)})]),c()}catch(F){if(o=null,W!==null&&E(s)===null&&(E(b)??"")===t)try{r.setItem(s,W)}catch{}throw F}finally{clearTimeout(he)}}function le(t,c=!1){console.warn(c?"visitor-drafts: the draft was started over; the earlier draft was kept in this browser's draft database under":"visitor-drafts: a tab on an earlier ClayJS saved a copy that could not be merged exactly; it was kept in this browser's draft database under",oe(s,$(t))),!w.has(c)&&(w.add(c),import("./c-C6DXZIXD.js").then(p=>p.toastPersistent(c?Ve:$e,"warning")).catch(()=>{}))}function Ee(t){let{meta:c,record:p}=t;if(u!==c.reset&&(E(b)??"")===u)try{r.setItem(b,c.reset)}catch{}if(f&&f===o&&c.reset!==e.generation()&&(f.marker===c.reset&&A(c.reset),e.stop(),ne(!1)),f===o&&(o=null),e.stopped())return y?ie(t):(R(t),t);if(t.conflicts.length&&console.warn("visitor-drafts: another tab changed the same thing; its copy was kept in this browser's draft database under",s+":conflict"),t.stale.includes(e.tab))return ie(t);if(c.reset!==e.generation()){if(!e.fresh())return ie(t);e.enter(c.reset)}t.released.length&&le(t.released[0]),I=c.gen,A(c.reset);let O=e.acknowledge(c.tabs[e.tab]?.seq??0);if(N(c,t.removedMark),R(t),e.pending()||(O&&(ne(!1),d.dispatchEvent(new CustomEvent("clay:drafts-saved",{detail:{data:p.data}}))),D))return t;if(!e.shown())return v=c.rev,t;e.changed()||(p&&c.rev!==v&&e.take(p.data),C=p?.id,v=c.rev);let T=e.externalUnit(p);return T&&d.dispatchEvent(new CustomEvent("clay:drafts-blockeditor-external",{detail:{live:T.live,adopted:()=>e.adoptedUnit(T)}})),t}let j=null,B=null;function ee(t,c=null){return j=ye(l,s,()=>{if(c?.type==="restore"){if(e.stopped())throw new Error("This page has started over. Reload it before restoring a draft.");e.captureNow()}return{...M(),recovery:c}},t).then(Ee,O=>{throw e.pending()?e.failed(O):O}).finally(()=>{j=null}),j}function te(){return B||(j?(B=j.then(()=>{},()=>{}).then(()=>(B=null,ee())),B):ee())}async function pe(t){for(;j||B;)await(B??j).catch(()=>{});return ee({recovery:!0},t)}async function ke(t){if(D)throw new Error("A draft is already being restored.");D=!0;try{if(e.stopped())throw new Error("This page has started over. Reload it before restoring a draft.");e.captureNow();let c;do if(c=await pe({type:"restore",mark:t,reset:e.generation()}),!c.restoredCopy||e.stopped())throw new Error("This page has started over. Reload it before restoring a draft.");while(e.pending());try{e.captureLate("restored:"+e.tab)}catch(p){throw e.failed(p)}return await de(),m(),c}finally{D=!1}}async function Oe(){await re.catch(()=>{});let t=s+":recovery:";return[...await l.readAll(s)].filter(([p])=>p.startsWith(t)).map(([p,O])=>({mark:p.slice(t.length),copy:U(O)}))}let Y=()=>{te().catch(()=>{})};function Ae(){e.unsafe()&&l.putRow(ce(s,e.tab),JSON.stringify(e.chain())).catch(()=>{}),e.pending()&&Y()}window.addEventListener("storage",t=>{if(t.key===s){let[c,p]=[U(t.oldValue),U(t.newValue)];p?.v===1&&p.w!==void 0?i=p:X(p)&&c?.v===1&&c.w!==void 0&&([i,g]=[c,t.newValue])}(t.key===null||t.key===s||t.key===b)&&Y()}),window.addEventListener("pageshow",t=>{t.persisted&&Y()}),d.addEventListener("clay:drafts-blockeditor-listening",Y);let re=ee({timeout:be});return re.catch(()=>{}),{first:re,sync:te,hide:Ae,startOver:Se,listRecovery:Oe,restoreRecovery:ke,recoveryRecord:t=>se(t,e.seed()),removeRecovery:t=>pe({type:"remove",mark:t})}}export{Pe as FULL_COPY_LIMIT,Qe as openSession};
@@ -0,0 +1,6 @@
1
+ import{J as yt,O as it,T as ze,s as Re,w as Ne,x as kt,y as He}from"./c-LAKBBJOU.js";import{a as _e,d as bt,g as Be,h as Pe}from"./c-EIUKME3W.js";import{f as Ve,o as je}from"./c-DZT6W2NG.js";import{a as xt,c as Ke}from"./c-SYOA4T7V.js";import{C as S,D as Wt,E as Ze,F as Ut,G as tn,H as en,a as Fe,d as R,e as T,f as We,h as Q,i as Ue,m as Ge,p as F,s as qt,u as Ye,v as Je,y as Xe,z as Qe}from"./c-3XGLJAS7.js";import{A as x,B as mt,C as ve,F as X,K as $e,L as gt,M as jt,N as Ie,O as Le,P as De,a as Te,c as Ee,d as b,fa as rt,g as Ce,h as Ae,u as ft,v as Oe,w as H,x as v,y as z,z as I}from"./c-OH2FPYSY.js";import{b as qe}from"./c-FSQXFG5T.js";import{b as O,d as Kt,f as pt,g as Se,h as Vt}from"./c-RETTCOWO.js";import{a as N}from"./c-JC4RZW4E.js";var nn=new WeakMap;function on(n){let t=nn.get(n);if(t)return t;t={};for(let[e,o]of I(n.attrs.cols).entries()){let s=[];n.forEach(r=>{e<r.childCount&&s.push(r.child(e).textContent.trim())}),t[o]=Le(n.attrs.cols[o].kind,s)}return nn.set(n,t),t}var Ps=Object.freeze({text:"Aa",number:"#",date:"\u{1F4C5}"}),Rs=Object.freeze({text:"Text",number:"Number",date:"Date"});var Gt=(n,t,e)=>{let o=n.attrs.get(t.baseId),s={};for(let r of Be(e))s[r]=o&&o.has(r)?o.get(r):Pe(e,r);return e.name==="board"&&Object.assign(s,Ne(n.boardFields,t.baseId)),e.name==="table"&&Object.assign(s,Re(n.tableFields,t.baseId,{cols:s.cols,rows:s.rows})),s},sn=n=>n===void 0?n:JSON.parse(JSON.stringify(n)),Qn=(n,t)=>{let e={},o=n.attrs.get(t.baseId);return o&&o.forEach((s,r)=>{r!=="pos"&&(e[r]=sn(s))}),e.t=t.t,e};function qs(n,t,e=null){let o=d=>{if(d.opaque){let a=d.recovered?{...sn(d.fields??{})}:Qn(n,d);return{b:d,type:b.nodes.opaque_block,fields:a,opaque:!0}}let u=b.nodes[d.t]??b.nodes.paragraph;return{b:d,type:u,fields:{...d.fields??Gt(n,d,u)}}},s=t.visible.map(d=>{let u=e?.get(d);return u?{b:d,node:u}:o(d)}),r=new Map(s.map((d,u)=>[d.b.id,u])),i=d=>s[d].node?s[d].node.attrs.parent:s[d].fields.parent,l=d=>(d.b.recovered?n.gone._map.get(yt(d.b.sourceKey,"parent")):n.attrs.get(d.b.baseId)?._map.get("parent"))?.id??{clock:-1,client:-1};for(let d of r.keys()){let u=new Map,a=[],h=d;for(;r.has(h)&&!u.has(h);)u.set(h,a.length),a.push(h),h=i(r.get(h));if(!u.has(h))continue;let f=a.slice(u.get(h)).reduce((g,k)=>{let w=l(s[r.get(g)]),A=l(s[r.get(k)]);return w.clock<A.clock||w.clock===A.clock&&w.client<A.client?g:k}),m=r.get(f);s[m].node&&(s[m]=o(s[m].b)),s[m].fields.parent=null}let c=s.map(({b:d,node:u,type:a,fields:h,opaque:p})=>{if(u)return u;if(p){let g=[];for(let k of d.runs)k.hole||(k.br?g.push(b.nodes.hard_break.create()):g.push(b.text(k.text,k.marks)));return a.create({id:d.id,pos:null,raw:h},g)}let f={id:d.id,pos:null,...h};if(a.name==="table"&&Object.keys(f.rows??{}).length&&Object.keys(f.cols??{}).length)return X(b,d.id,{t:"table",...f});if(!a.isTextblock)return a.create(f);let m=[];for(let g of d.runs)g.hole||(g.br?m.push(b.nodes.hard_break.create()):m.push(b.text(g.text,g.marks)));return a.create(f,m)});return c.length?b.nodes.doc.create(null,c):b.nodes.doc.createAndFill()}var C=n=>({status:"refused",code:n}),Mt=n=>JSON.parse(JSON.stringify(n)),Zn=["title","owner","due"],to=/^\d{4}-\d{2}-\d{2}$/,wt=(n,t)=>n==="title"?typeof t=="string":n==="due"?t===null||typeof t=="string"&&to.test(t):t===null||typeof t=="string"&&t.length>0,eo=n=>n!==null&&typeof n=="object"&&!Array.isArray(n);function rn(n,t){let e=t>0?n[t-1]:null,o=n.slice(t).find(r=>e===null||r>e)??null,s=r=>(e===null||r>e)&&(o===null||r<o);for(let[r,i]of[[e,o],[null,o],[e,null]]){if(r!==null&&!H(r)||i!==null&&!H(i)||r!==null&&i!==null&&r>=i)continue;let l=v(r,i);if(s(l))return l}return`${n.reduce((r,i)=>i>r?i:r,"")}V`}function Yt(n,t,e){let o=n.map(t),s=e>0?o[e-1]:null,r=e;for(;s!==null&&r<o.length&&o[r]===s;)r++;if(r===e)return{pos:rn(o,e),rekey:[]};let i=o.slice(r).find(c=>c>s)??null,l=[];for(let c=e,d=s;c<=r;c++)l.push(d=rn(i===null?[d]:[d,i],1));return{pos:l[0],rekey:n.slice(e,r).map((c,d)=>[c,l[d+1]])}}var St=(n,t,e)=>{let{pos:o,rekey:s}=Yt(t,r=>n[r].pos,e);for(let[r,i]of s)n[r]={...n[r],pos:i};return o};function er({pd:n,um:t=null,origins:e=null,render:o=()=>{}}){let s=u=>{if(typeof u!="string")return null;let a=ze(n,e).visible.find(p=>p.id===u);if(!a||a.t!=="board")return null;let h=a.fields??Gt(n,a,b.nodes.board);return{columns:Mt(h.columns??{}),cards:Mt(h.cards??{})}},r=(u,a,h,p)=>{let f=it(u);return t?.stopCapturing(),n.ydoc.transact(()=>{if(!f)He(n,u,a,h);else for(let m of["columns","cards"])rt(a[m])!==rt(h[m])&&n.gone.set(yt(f,m),Mt(h[m]))},_e),t?.stopCapturing(),o(),p},i=(u,a,h=null)=>I(Object.fromEntries(Object.entries(u.cards).filter(([p,f])=>f.col===a&&p!==h))),l=(u,a)=>a===void 0?u.length:a===null?0:u.indexOf(a)+1,c=(u,a)=>a!=null&&!u.includes(a),d=(u,a)=>{let h=s(u);return h?a(h,Mt(h)):C("missing-board")};return{read:u=>s(u),removed(u){return s(u)?it(u)?{columns:{},cards:{}}:kt(n.boardFields,u):null},createColumn:(u,{name:a="",afterId:h}={})=>d(u,(p,f)=>{if(typeof a!="string")return C("invalid-value");let m=I(p.columns);if(c(m,h))return C("missing-destination");let g=x("c");return f.columns[g]={pos:St(f.columns,m,l(m,h)),name:a},r(u,p,f,{status:"created",id:g})}),renameColumn:(u,a,h)=>d(u,(p,f)=>Object.hasOwn(p.columns,a)?typeof h!="string"?C("invalid-value"):p.columns[a].name===h?{status:"unchanged"}:(f.columns[a].name=h,r(u,p,f,{status:"changed"})):C("missing-column")),moveColumn:(u,a,{afterId:h=null}={})=>d(u,(p,f)=>{if(!Object.hasOwn(p.columns,a))return C("missing-column");let m=I(p.columns).filter(w=>w!==a);if(c(m,h))return C("missing-destination");let g=l(m,h),k=I(p.columns);return[...m.slice(0,g),a,...m.slice(g)].every((w,A)=>w===k[A])?{status:"unchanged"}:(f.columns[a].pos=St(f.columns,m,g),r(u,p,f,{status:"moved"}))}),removeColumn:(u,a)=>d(u,(h,p)=>Object.hasOwn(h.columns,a)?(delete p.columns[a],r(u,h,p,{status:"removed",cards:i(h,a).length})):C("missing-column")),restoreColumn:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.columns,a))return{status:"unchanged"};let f=it(u)?null:kt(n.boardFields,u).columns[a];return f?(p.columns[a]=f,r(u,h,p,{status:"restored"})):C("missing-column")}),createCard:(u,{columnId:a,title:h="",owner:p=null,due:f=null,afterId:m}={})=>d(u,(g,k)=>{if(!Object.hasOwn(g.columns,a))return C("missing-column");if(!wt("title",h)||!wt("owner",p)||!wt("due",f))return C("invalid-value");let w=i(g,a);if(c(w,m))return C("missing-destination");let A=x("k");return k.cards[A]={pos:St(k.cards,w,l(w,m)),col:a,title:h,...p!==null?{owner:p}:{},...f!==null?{due:f}:{}},r(u,g,k,{status:"created",id:A})}),editCard:(u,a,h)=>d(u,(p,f)=>{if(!Object.hasOwn(p.cards,a))return C("missing-card");if(!eo(h)||!Object.keys(h).length||Object.keys(h).some(g=>!Zn.includes(g)))return C("invalid-field");if(Object.entries(h).some(([g,k])=>!wt(g,k)))return C("invalid-value");let m={...p.cards[a]};for(let[g,k]of Object.entries(h))k===null?delete m[g]:m[g]=k;return rt(m)===rt(p.cards[a])?{status:"unchanged"}:(f.cards[a]=m,r(u,p,f,{status:"changed"}))}),moveCard:(u,a,{columnId:h,afterId:p=null}={})=>d(u,(f,m)=>{if(!Object.hasOwn(f.cards,a))return C("missing-card");if(!Object.hasOwn(f.columns,h))return C("missing-column");let g=i(f,h,a);if(c(g,p))return C("missing-destination");let k=l(g,p),w=f.cards[a];if(w.col===h){let A=i(f,h);if([...g.slice(0,k),a,...g.slice(k)].every((P,Y)=>P===A[Y]))return{status:"unchanged"}}return m.cards[a]={...w,col:h,pos:St(m.cards,g,k)},r(u,f,m,{status:"moved"})}),removeCard:(u,a)=>d(u,(h,p)=>Object.hasOwn(h.cards,a)?(delete p.cards[a],r(u,h,p,{status:"removed"})):C("missing-card")),restoreCard:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.cards,a))return{status:"unchanged"};let f=it(u)?null:kt(n.boardFields,u).cards[a];return f?(p.cards[a]=f,r(u,h,p,{status:"restored"})):C("missing-card")})}}var Tt="blockeditor-history-intent",no=500,oo=(n,t)=>{let e=n.resolve(t);return e.depth?e.node(1).attrs.id:null},so=n=>(n.storedMarks??n.selection.$from.marks()).map(t=>`${t.type.name}:${JSON.stringify(t.attrs)}`).sort().join(","),ro=/[.?!]["'\u201D\u2019)\]]*$/,io=(n,t,e)=>{if(!/\s$/.test(e))return!1;let o=n.doc.resolve(t),s=o.parent.textBetween(0,o.parentOffset)+e.replace(/\s+$/,"");return!/\s$/.test(s)&&ro.test(s)};function Xt(n,t,e,o){return{kind:"insert",blockId:oo(n.doc,t),from:t,end:t+o.length,replaced:t!==e,text:o,marks:so(n),breakAfter:io(n,t,o),at:Date.now()}}function rr(n,t){return!n||!t||n.kind!==t.kind?!1:t.kind==="compose"?n.id===t.id:n.blockId!==t.blockId||t.at-n.at>no?!1:t.kind==="insert"?!n.breakAfter&&!t.replaced&&t.from===n.end&&t.marks===n.marks:t.direction===n.direction&&(t.direction<0?t.to===n.from:t.from===n.from)}var lo={deleteContentBackward:-1,deleteContentForward:1},Jt=new WeakMap,co=1e3,Qt="blockeditor-derived";function ao(n){let t=Jt.get(n)??null;return Jt.delete(n),t}function uo(n,t){if(!t||n.before!==t.doc||Date.now()-t.at>co||n.getMeta(We)||n.steps.length!==1)return null;let e=n.steps[0];if(e.slice?.size!==0||e.from===e.to)return null;let o=n.before.resolve(e.from),s=n.before.resolve(e.to);return!o.parent.isTextblock||!o.sameParent(s)?null:{kind:"delete",blockId:o.depth?o.node(1).attrs.id:null,direction:t.direction,from:e.from,to:e.to,at:t.at}}function ir(n,t=null){let e=t?ao(t):null,o=n.filter(i=>!i.getMeta(Qt));if(o.length!==1)return null;let s=o[0],r=s.getMeta("composition");return r!=null?{kind:"compose",id:r,at:Date.now()}:s.getMeta(Tt)??uo(s,e)}function lr(){return new O.Plugin({props:{handleTextInput(n,t,e,o,s){return n.dispatch(s().setMeta(Tt,Xt(n.state,t,e,o))),!0},handleDOMEvents:{beforeinput(n,t){let e=lo[t.inputType];return e&&Jt.set(n,{direction:e,at:Date.now(),doc:n.state.doc}),!1}}}})}function cr({um:n,undo:t,redo:e,article:o,focus:s}){let r=()=>window.clay?.undo,i=Math.random().toString(36).slice(2),l=0,c=!1,d=!1,u=!1,a=(g,k)=>{let w=k==="undo"?"undoStack":"redoStack",A=k==="undo"?"redoStack":"undoStack",P=n[w],Y=n[A],zt=P.indexOf(g.item);if(zt<0)throw new Error("blockeditor: history item is no longer available");let dt=P.filter((Ds,Xn)=>Xn!==zt),st=[...Y,...dt],Ft=st.length;n[w]=[g.item],n[A]=st,c=!0;let we,ht;try{we=k==="undo"?t():e()}finally{ht=st.slice(Ft),n[w]=dt,n[A]=[...Y,...ht],c=!1,n.stopCapturing()}if(!we||!ht.length)throw g.item=null,new Error("blockeditor: history item was emptied by another edit");g.item=ht[0],g.applied=k==="redo"},h=g=>{if(c||g.origin===n||g.type!=="undo"||r()?.pageHistory!==!0)return;let k={item:g.stackItem,applied:!0},w=`${i}:${++l}`,A=`${w}:undone`,P=`${w}:applied`,Y={kind:"value",target:o,prop:`blockeditor-step:${w}`,oldValue:A,newValue:P,read:()=>!u&&k.item&&(k.applied?n.undoStack:n.redoStack).includes(k.item)?k.applied?P:A:null,write:(zt,dt)=>{let st=!!document.activeElement?.closest?.('[contenteditable]:not([contenteditable="false"])'),Ft=o.textContent;a(k,dt===A?"undo":"redo"),st&&o.textContent!==Ft&&typeof s=="function"&&s()}};d=!0;try{try{r().recordStep("Edit",Y)}catch{r().record(Y)}}finally{d=!1}},p=()=>{d||n.stopCapturing()};n.on("stack-item-added",h);let f=null,m=()=>{let g=r()?.pageHistory===!0?r():null;g!==f&&(f?.off?.("commit",p),f=g,f?.on?.("commit",p))};return m(),document.addEventListener("clay:undo-session",m),{dispose(){u=!0,n.off("stack-item-added",h),f?.off?.("commit",p),document.removeEventListener("clay:undo-session",m)}}}function ho(n,t){if(!n||!/<table[\s>]/i.test(n))return null;let e=t.defaultView?.DOMParser??globalThis.DOMParser;if(!e)return null;let o=new e().parseFromString(n,"text/html").body,s=[...o.querySelectorAll("table")].filter(d=>!d.parentElement.closest("table"));if(s.length!==1)return null;let r=o.cloneNode(!0);for(let d of r.querySelectorAll("table, style, script, template, meta, title"))d.remove();if(r.textContent.trim())return null;let i=s[0];return{grid:[...i.querySelectorAll("tr")].filter(d=>d.closest("table")===i).map(d=>[...d.children].filter(u=>u.tagName==="TD"||u.tagName==="TH").map(u=>mt(Xe.parse(u,{topNode:b.nodes.table_cell.create()})))).filter(d=>d.length),own:!!i.querySelector("td[data-col]")}}function po(n){if(!n||!n.includes(" "))return null;let{header:t,rows:e}=gt(n.replace(/\r?\n$/,""),{delimiter:" "});return{grid:[t,...e],own:!1}}function ln(n,t,e=globalThis.document){let o=null;try{o=ho(n,e)}catch{o=null}if(!o&&!/<table[\s>]/i.test(n||""))try{o=po(t)}catch{o=null}if(!o||!o.grid.length)return null;let s=Math.max(...o.grid.map(r=>r.length));for(let r of o.grid)for(;r.length<s;)r.push("");return{...o,width:s,height:o.grid.length}}function Et(n,{header:t=n.length>1}={}){let e=Math.max(0,...n.map(a=>a.length));if(!e)return null;let o=t?n[0]:[],s=t?n.slice(1):n,r=Array.from({length:e},()=>x("c")),i=z(null,null,e),l=Object.fromEntries(r.map((a,h)=>[a,{pos:i[h],name:ft(o[h]??"").replace(/\s+/g," ").trim()||`Column ${h+1}`}])),c=s.length?s:[[]],d=z(null,null,c.length),u=Object.fromEntries(c.map((a,h)=>[x("r"),{pos:d[h],cells:Object.fromEntries(r.map((p,f)=>[p,a[f]??""]))}]));return X(b,x(),{t:"table",pos:null,cols:l,rows:u})}var{Plugin:fo,TextSelection:mo}=O,Zt=b.nodes;var dn=(n,t)=>{let e=null;return n.forEach((o,s)=>{!e&&o.type===Zt.table&&o.attrs.id===t&&(e={node:o,pos:s})}),e};function j(n,t){if(!t)return null;let e=dn(n,t.table);if(!e)return null;let o=[];e.node.forEach(p=>o.push(p.attrs.id));let s=I(e.node.attrs.cols),r=[o.indexOf(t.anchor[0]),o.indexOf(t.head[0])],i=[s.indexOf(t.anchor[1]),s.indexOf(t.head[1])];if(r.includes(-1)||i.includes(-1))return null;let l=Math.min(...r),c=Math.max(...r),d=Math.min(...i),u=Math.max(...i),a=[],h=e.pos+1;return e.node.forEach((p,f,m)=>{if(m>=l&&m<=c){let g=[],k=h+1;p.forEach((w,A,P)=>{P>=d&&P<=u&&g.push({cell:w,pos:k}),k+=w.nodeSize}),a.push(g)}h+=p.nodeSize}),{...e,top:l,bottom:c,left:d,right:u,cells:a}}var lt=(n,t)=>{let e=n.resolve(t);for(let o=e.depth;o>0;o--)if(e.node(o).type===Zt.table_cell&&o>=3)return{table:e.node(o-2).attrs.id,row:e.node(o-1).attrs.id,col:e.node(o).attrs.col,start:e.start(o)};return null};function Ct(n,t,e){let o=lt(n.state.doc,t),s=lt(n.state.doc,e);if(!o||!s||o.table!==s.table)return!1;let r={table:o.table,anchor:[o.row,o.col],head:[s.row,s.col]},i=n.state.tr.setSelection(mo.create(n.state.doc,s.start)).setMeta(T,r);n.dispatch(i);let l=j(n.state.doc,r),c=l?(l.bottom-l.top+1)*(l.right-l.left+1):0;return R(n,`${c} ${c===1?"cell":"cells"} selected`),!0}function Er(n,t,e,o){let s=n.state.doc.nodeAt(t);if(s?.type!==Zt.table||!s.childCount)return!1;let r=s.childCount-1,i=s.child(0).childCount-1,l=(c,d)=>{let u=t+1;for(let a=0;a<c;a++)u+=s.child(a).nodeSize;u++;for(let a=0;a<d;a++)u+=s.child(c).child(a).nodeSize;return u+1};return e==="row"?Ct(n,l(o,0),l(o,i)):Ct(n,l(0,o),l(r,o))}var go=new Set(["Shift","Control","Alt","Meta","CapsLock"]),bo=n=>/[\t\n\r"]/.test(n)?`"${n.replace(/"/g,'""')}"`:n;function ko(n,t){let e=n.cells.map(r=>r.map(({cell:i})=>bo(ft(mt(i)))).join(" ")).join(`
2
+ `),o=t.createElement("table"),s=o.appendChild(t.createElement("tbody"));for(let r of n.cells){let i=s.appendChild(t.createElement("tr"));for(let{cell:l}of r){let c=i.appendChild(t.createElement("td"));c.dataset.col=l.attrs.col,c.append(Qe.serializeFragment(l.content,{document:t}))}}return{text:e,html:o.outerHTML}}function cn(n,t){let e=j(n.doc,T.getState(n));if(!e)return!1;if(t){let o=n.tr;for(let s of[...e.cells].reverse())for(let{cell:r,pos:i}of[...s].reverse())r.content.size&&o.delete(i+1,i+r.nodeSize-1);o.setMeta(T,T.getState(n)),t(S(o))}return!0}var an=(n,t,e)=>{let{text:o,html:s}=ko(t,e.dom.ownerDocument);n.clipboardData.setData("text/plain",o),n.clipboardData.setData("text/html",s),n.preventDefault()},yo=(n,t)=>(e,o,s)=>{let r=T.getState(e),i=j(e.doc,r);if(!i||!s)return!1;let l=[],c=I(i.node.attrs.cols);i.node.forEach(a=>l.push(a.attrs.id));let d=Math.max(0,Math.min(l.length-1,l.indexOf(r.head[0])+n)),u=Math.max(0,Math.min(c.length-1,c.indexOf(r.head[1])+t));return o&&o(e.tr.setMeta(T,{...r,head:[l[d],c[u]]})),!0},un=(n,t)=>{let e=t.target?.closest?.("td");if(!e||!n.dom.contains(e))return null;try{return n.posAtDOM(e,0)}catch{return null}};function Cr(){let n=null;return new fo({key:T,state:{init:()=>null,apply(t,e,o,s){let r=t.getMeta(T);return r!==void 0?r:!e||t.selectionSet||t.docChanged&&!t.getMeta(bt)?null:j(s.doc,e)?e:null}},props:{attributes:t=>T.getState(t)?{class:"has-cell-rect"}:{},createSelectionBetween:t=>T.getState(t.state)?t.state.selection:null,decorations(t){let e=j(t.doc,T.getState(t));return e?Kt.DecorationSet.create(t.doc,e.cells.flat().map(({cell:o,pos:s})=>Kt.Decoration.node(s,s+o.nodeSize,{class:"is-cell-selected"}))):null},handleKeyDown(t,e){let o=t.state;if(!T.getState(o))return!1;if(e.key==="Escape")return t.dispatch(o.tr.setMeta(T,null)),!0;if(e.key==="Backspace"||e.key==="Delete")return cn(o,t.dispatch);if(e.shiftKey){let s={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(s)return yo(...s)(o,t.dispatch,t)}return go.has(e.key)||(e.metaKey||e.ctrlKey)&&(e.key==="a"||e.key==="c"||e.key==="x"||e.key==="v")||t.dispatch(o.tr.setMeta(T,null)),!1},handleDOMEvents:{mousedown(t,e){if(e.button!==0)return!1;!e.shiftKey&&T.getState(t.state)&&t.dispatch(t.state.tr.setMeta(T,null));let o=un(t,e);if(o===null)return!1;if(e.shiftKey){let c=T.getState(t.state),d=(c&&xo(t.state.doc,c))??t.state.selection.$anchor.pos;return lt(t.state.doc,d)?(e.preventDefault(),Ct(t,d,o)):!1}let s=t.dom.ownerDocument,r=o,i=c=>{let d=un(t,c);if(d===null)return;let u=lt(t.state.doc,r),a=lt(t.state.doc,d);if(!u||!a||u.table!==a.table)return;let h=T.getState(t.state);u.row===a.row&&u.col===a.col&&!h||h&&h.head[0]===a.row&&h.head[1]===a.col||(c.preventDefault(),Ct(t,r,d))},l=()=>{s.removeEventListener("mouseover",i),s.removeEventListener("mouseup",l),n=null};return n?.(),n=l,s.addEventListener("mouseover",i),s.addEventListener("mouseup",l),!1},copy(t,e){let o=j(t.state.doc,T.getState(t.state));return!o||!e.clipboardData?!1:(an(e,o,t),!0)},cut(t,e){let o=j(t.state.doc,T.getState(t.state));return!o||!e.clipboardData?!1:(an(e,o,t),cn(t.state,t.dispatch),!0)}}},view:()=>({destroy:()=>n?.()})})}function xo(n,t){let e=dn(n,t.table),o=null;return e?.node.forEach((s,r)=>{if(s.attrs.id!==t.anchor[0])return;let i=e.pos+1+r+1;s.forEach(l=>{l.attrs.col===t.anchor[1]&&(o=i+1),i+=l.nodeSize})}),o}var hn=n=>{let t=j(n.doc,T.getState(n));return t?{row:t.top,cell:t.left,rows:t.bottom-t.top+1,cols:t.right-t.left+1}:null};var te=new WeakMap;var{Plugin:Mo,TextSelection:q}=O,E=b.nodes,ne=256*1024,B=n=>I(n.attrs.cols),pn=n=>{let t=n.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type===E.table){let o=t.node(e),s=e<t.depth?t.index(e):0,r=e+1<t.depth?t.index(e+1):0;return{table:o,pos:t.before(e),row:s,cell:r}}return null},ct=(n,t,e,o)=>{let s=n.nodeAt(t);if(!s||!s.childCount)return null;e=Math.max(0,Math.min(e,s.childCount-1)),o=Math.max(0,Math.min(o,s.child(e).childCount-1));let r=t+1;for(let i=0;i<e;i++)r+=s.child(i).nodeSize;r++;for(let i=0;i<o;i++)r+=s.child(e).child(i).nodeSize;return r+1},At=(n,t=v())=>E.table_row.create({id:x("r"),pos:t},n.map(e=>E.table_cell.create({col:e}))),L=(n,t,e)=>E.table.create({...n.attrs,...t},e);function D(n,t,e){let o=pn(n);if(!o)return!1;let s=e(o.table,o);if(!s)return!1;if(t){let{table:r,row:i=o.row,cell:l=o.cell}=s,c=n.tr.replaceWith(o.pos,o.pos+o.table.nodeSize,r),d=ct(c.doc,o.pos,i,l);d!==null&&c.setSelection(q.create(c.doc,d)),t(S(c))}return!0}function K(n,t,e,o=null,s=null,r=null){r??=o?n.doc.resolve(o.from).index(0):n.selection.$head.index(0);let i=n.doc.child(r),l=0;for(let h=0;h<r;h++)l+=n.doc.child(h).nodeSize;let c=i.isTextblock&&(i.content.size===0||o?.from===l+1&&o?.to===l+i.nodeSize-1),d=n.doc.maybeChild(r+1),u=c?i.attrs.pos:v(i.attrs.pos,d?.attrs.pos??null),a=e.type.create({...e.attrs,pos:u,parent:i.attrs.parent??null},e.content);if(t){let h=n.tr;o&&h.delete(o.from,o.to);let p=h.mapping.map(l),f=h.doc.child(r),m=c?p:p+f.nodeSize;if(h.replaceWith(m,c?p+f.nodeSize:m,a),s){let g=s.type.create({...s.attrs,pos:v(u,d?.attrs.pos??null),parent:i.attrs.parent??null},s.content);h.insert(m+a.nodeSize,g)}h.setSelection(q.create(h.doc,ct(h.doc,m,0,0))),t(S(h).scrollIntoView())}return!0}function fn(n=3,t=3){if(!Number.isInteger(n)||!Number.isInteger(t)||n<1||t<1)return null;let e=Array.from({length:t},()=>x("c")),o=z(null,null,t),s=Object.fromEntries(e.map((l,c)=>[l,{pos:o[c],name:`Column ${c+1}`}])),i=z(null,null,n).map(l=>At(e,l));return E.table.create({id:x(),cols:s},i)}var oe=n=>(t,e)=>{let o=pn(t);if(!o||t.selection.$head.parent.type!==E.table_cell)return!1;let s=o.table.child(o.row).childCount,r=o.row,i=o.cell;return n==="down"?r++:(i+=n,i>=s&&(r++,i=0),i<0&&(r--,i=s-1)),r<0?!0:r>=o.table.childCount?n===-1?!0:wo(t,e,o,i):(e&&e(t.tr.setSelection(q.create(t.doc,ct(t.doc,o.pos,r,i))).scrollIntoView()),!0)};function wo(n,t,e,o){let s=[...e.table.content.content];if(s.push(At(B(e.table),v(s.at(-1).attrs.pos,null))),t){let r=n.tr.replaceWith(e.pos,e.pos+e.table.nodeSize,L(e.table,{sort:null},s));r.setSelection(q.create(r.doc,ct(r.doc,e.pos,s.length-1,o))),t(S(r).scrollIntoView())}return!0}var So=oe(1),To=oe(-1),Eo=oe("down"),Co=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=[...o.content.content],i=s.row+(n?1:0),l=v(r[i-1]?.attrs.pos??null,r[i]?.attrs.pos??null);return r.splice(i,0,At(B(o),l)),{table:L(o,{sort:null},r),row:i}}),Kr=(n,t)=>D(n,t,(e,o)=>{let s=[...e.content.content];if(s.length===1){let r=s[0];s[0]=E.table_row.create(r.attrs,B(e).map(i=>E.table_cell.create({col:i})))}else s.splice(o.row,1);return{table:L(e,{sort:null},s),row:Math.min(o.row,s.length-1)}}),mn=(n,t,e,o,s)=>{let{pos:r,rekey:i}=Yt(t,c=>n[c]?.pos??"",e),l={...n,[o]:{...s,pos:r}};for(let[c,d]of i)l[c]={...l[c],pos:d};return l},Vr=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+(n?1:0),l=x("c"),c=mn(o.attrs.cols,r,i,l,{name:`Column ${r.length+1}`}),d=o.content.content.map(u=>{let a=[...u.content.content];return a.splice(i,0,E.table_cell.create({col:l})),E.table_row.create(u.attrs,a)});return{table:L(o,{cols:c},d),cell:i}}),jr=(n,t)=>D(n,t,(e,o)=>{let s=B(e);if(s.length<=1)return null;let r={...e.attrs.cols};delete r[s[o.cell]];let i=e.content.content.map(l=>E.table_row.create(l.attrs,l.content.content.filter((c,d)=>d!==o.cell)));return{table:L(e,{cols:r,sort:e.attrs.sort?.col===s[o.cell]?null:e.attrs.sort},i),cell:Math.min(o.cell,s.length-2)}}),qr=n=>(t,e)=>D(t,e,(o,s)=>{let r=s.row+n;if(r<0||r>=o.childCount)return null;let i=[...o.content.content],[l]=i.splice(s.row,1);i.splice(r,0,l);let c=v(i[r-1]?.attrs.pos??null,i[r+1]?.attrs.pos??null);return i[r]=E.table_row.create({...l.attrs,pos:c},l.content),{table:L(o,{sort:null},i),row:r}}),Wr=n=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+n;if(i<0||i>=r.length)return null;let l=[...r],[c]=l.splice(s.cell,1);l.splice(i,0,c);let d=mn(o.attrs.cols,l.filter(a=>a!==c),i,c,o.attrs.cols[c]),u=o.content.content.map(a=>{let h=[...a.content.content],[p]=h.splice(s.cell,1);return h.splice(i,0,p),E.table_row.create(a.attrs,h)});return{table:L(o,{cols:d},u),cell:i}}),Ao=48,Oo=1200,Ur=160,gn=n=>Number.isFinite(n)&&n>0?Math.round(Math.min(Oo,Math.max(Ao,n))):null,Gr=n=>(t,e)=>D(t,e,o=>{let s=B(o);if(!s.some(i=>o.attrs.cols[i].width))return null;let r={};for(let i of s){let{width:l,...c}=o.attrs.cols[i];r[i]=c}return{table:L(o,{cols:r},o.content),cell:Math.max(0,s.indexOf(n))}}),Yr=(n,t)=>(e,o)=>D(e,o,s=>{let r={...s.attrs.cols},i=!1;for(let[l,c]of Object.entries(n)){let d=gn(c);!r[l]||d===null||r[l].width===d||(r[l]={...r[l],width:d},i=!0)}return i?{table:L(s,{cols:r},s.content),cell:B(s).indexOf(t)}:null}),Jr=(n,t)=>(e,o)=>D(e,o,s=>{let r=s.attrs.cols[n];if(!r)return null;let i=t===null?null:gn(t);if(t!==null&&i===null||(r.width??null)===i)return null;let{width:l,...c}=r,d={...s.attrs.cols,[n]:i===null?c:{...r,width:i}};return{table:L(s,{cols:d},s.content),cell:B(s).indexOf(n)}}),Xr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!String(t).trim())return null;let r={...s.attrs.cols,[n]:{...s.attrs.cols[n],name:String(t).trim()}};return{table:L(s,{cols:r},s.content)}}),Qr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!(t==="auto"||Ie.includes(t)))return null;let{kind:r,...i}=s.attrs.cols[n],l={...s.attrs.cols,[n]:t==="auto"?i:{...s.attrs.cols[n],kind:t}};return{table:L(s,{cols:l,sort:s.attrs.sort?.col===n?null:s.attrs.sort},s.content)}}),Zr=(n,t="asc")=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!["asc","desc"].includes(t))return null;let r=B(s).indexOf(n),i=on(s)[n],l=[...s.content.content].map((u,a)=>({row:u,previous:a,text:u.child(r).textContent.trim()}));l.sort((u,a)=>{if(!u.text||!a.text)return!u.text&&!a.text?u.previous-a.previous:u.text?-1:1;let h=i==="number"?jt(u.text):u.text,p=i==="number"?jt(a.text):a.text;if(h==null||p==null)return h==null&&p==null?u.previous-a.previous:h==null?1:-1;let f=i==="number"?h-p:i==="date"?h<p?-1:h>p?1:0:h.localeCompare(p,void 0,{numeric:!0,sensitivity:"base"});return f?t==="asc"?f:-f:u.previous-a.previous});let c=z(null,null,l.length),d=l.map(({row:u},a)=>E.table_row.create({...u.attrs,pos:c[a]},u.content));return{table:L(s,{sort:{col:n,dir:t}},d)}}),ee=(n,t=null)=>(e,o)=>D(e,o,(s,r)=>{let i=B(s),l=t?.row??r.row,c=t?.cell??r.cell,d=[...s.content.content];n.forEach((a,h)=>{let p=l+h;p>=d.length&&d.push(At(i,v(d.at(-1).attrs.pos,null)));let f=[...d[p].content.content];a.forEach((m,g)=>{c+g<i.length&&(f[c+g]=E.table_cell.create({col:i[c+g]},ve(b,m)))}),d[p]=E.table_row.create(d[p].attrs,f)});let u=Math.max(1,...n.map(a=>a.length));return{table:L(s,{sort:null},d),row:l+n.length-1,cell:Math.min(c+u-1,i.length-1)}}),vo=n=>new TextEncoder().encode(JSON.stringify(n.toJSON())).length;function $o(n,t){let e=t.clipboardData;if(!e||e.files?.length)return!1;let o=n.state;if(o.selection.$from.parent.type.spec.code)return!1;let s=hn(o),r=e.getData("text/plain").replace(/\r?\n$/,""),i=ln(e.getData("text/html"),e.getData("text/plain"),n.dom.ownerDocument)??(s&&r&&!/[\r\n]/.test(r)?{grid:[[r]],width:1,height:1,own:!1}:null);if(!i)return!1;if(s&&s.rows*s.cols>1&&i.width*i.height===1)return ee(Array.from({length:s.rows},()=>Array(s.cols).fill(i.grid[0][0])),{row:s.row,cell:s.cell})(o,n.dispatch);if(s)return ee(i.grid,{row:s.row,cell:s.cell})(o,n.dispatch);if(o.selection.$head.parent.type===E.table_cell)return i.width*i.height<2?!1:ee(i.grid)(o,n.dispatch);if(i.width*i.height<2||i.own||i.height<2&&!/<table[\s>]/i.test(e.getData("text/html")))return!1;let l=Et(i.grid,{header:i.height>1});if(!l)return!1;if(vo(l)>ne)return N("This paste is too large for one table.","error"),!0;let{from:c,to:d,empty:u,$from:a,$to:h}=o.selection;if(!u&&a.index(0)!==h.index(0)){let p=o.tr.deleteSelection();return K(o.apply(p),f=>{for(let m of f.steps)p.step(m);p.setSelection(q.create(p.doc,f.selection.from)),n.dispatch(S(p).scrollIntoView())},l)}return K(o,n.dispatch,l,u?null:{from:c,to:d})}var ti=pt.keymap({Tab:So,"Shift-Tab":To,Enter:Eo,"Mod-Enter":Co(!0)});function Io(n,t){let e=te.get(t.target),o=e?.getPos();if(o==null||t.button||t.shiftKey||!n.editable)return!1;t.preventDefault();let s=t.clientX<e.contentDOM.getBoundingClientRect().left;return n.dispatch(n.state.tr.setSelection(q.create(n.state.doc,o+1+(s?0:e.node.content.size)))),n.focus(),e.openDate(),!0}function ei(){return new Mo({props:{handlePaste:$o,handleDOMEvents:{mousedown:Io},handleClickOn(n,t,e,o,s,r){if(e.type!==E.table_cell||!r||s.button)return!1;let i=n.nodeDOM(o),l=i&&te.get(i);return l&&l.openDate(),!1}},appendTransaction(n,t,e){if(!n.some(r=>r.docChanged&&!r.getMeta(bt)))return null;let o=new Map;t.doc.forEach(r=>{r.type===E.table&&o.set(r.attrs.id,r)});let s=e.tr;return e.doc.forEach((r,i)=>{if(r.type!==E.table||!r.attrs.sort)return;let l=o.get(r.attrs.id),c=r.attrs.sort.col;if(!l)return;let d=h=>Object.fromEntries(h.content.content.map(p=>[p.attrs.id,p.content.content.find(f=>f.attrs.col===c)?.textContent])),u=d(l),a=d(r);(Object.keys(u).length!==Object.keys(a).length||Object.keys(u).some(h=>u[h]!==a[h]||!Object.hasOwn(a,h)))&&s.setNodeMarkup(i,null,{...r.attrs,sort:null})}),s.docChanged?s.setMeta(Qt,!0):null}})}function ni(n,t,e){let o=n.state.doc.nodeAt(t);if(o?.type!==E.table_cell)return!1;let s=n.state.tr.replaceWith(t+1,t+o.nodeSize-1,e?b.text(e):[]);return n.dispatch(s.setSelection(q.create(s.doc,t+1+e.length))),!0}function oi(n,t,e,o){let s=ct(n.state.doc,t,e,o);return s===null?!1:(n.dispatch(n.state.tr.setSelection(q.create(n.state.doc,s))),!0)}var{TextSelection:Lo}=O,se=b.nodes,Do=Object.freeze(["To do","In progress","Done"]),bn=(n,t)=>H(n)&&(t===null||H(t)&&n<t)?v(n,t):null;function re(n=Do){let t=z(null,null,n.length),e=Object.fromEntries(n.map((o,s)=>[x("c"),{pos:t[s],name:o}]));return se.board.create({id:x(),columns:e,cards:{}})}function kn(n,t,e=re(),o=null,s=null){let r=n.tr;o&&r.delete(o.from,o.to),s??=r.doc.resolve(r.mapping.map(n.selection.head)).index(0);let i=Q(r.doc),l=r.doc.child(s),c=l.isTextblock&&l.content.size===0,d=c?s:i[s].subEnd,u=c?i[s].at:i[d].end,a=i[d+1]?.node.attrs.pos??null,h=l.attrs.parent??null,p=c?l.attrs.pos:bn(i[d].node.attrs.pos,a),f=se.board.create({...e.attrs,pos:p,parent:h}),m=se.paragraph.create({id:x(),pos:bn(p,a),parent:h});return r.replaceWith(u,c?i[s].end:u,[f,m]),r.setSelection(Lo.create(r.doc,u+f.nodeSize+1)),t&&t(S(r).scrollIntoView()),!0}function yn(n){let t=[];return n.forEach(e=>{e.type===b.nodes.table&&I(e.attrs.cols).length>1&&t.push(e)}),t}function pi(n,t){let e="",o=0,s=null;return n.forEach(r=>{s===null&&(r.type===b.nodes.heading&&(e=r.textContent),r.type===b.nodes.table&&(o+=1,r.attrs.id===t&&(s=e||`Table ${o}`),e=""))}),s}var xn=new Set(["blockeditor-format-unsupported","unsupported-host"]),_o="This host can't store that yet, so nothing was added.",Bo="That didn't go through. Try again.",Po="That couldn't be added here.";function Mn(n,t){let e=t?.status==="upgrade-required"&&t.message?t.message:xn.has(t?.code)||xn.has(t?.status)?_o:t?.retry===!0?Bo:Po;n.isDestroyed||(R(n,e),N(e,"error"))}async function Ot(n,t){if(typeof n.runFormatCommand!="function")return Mn(n,{code:"blockeditor-format-unsupported"}),{ok:!1,code:"blockeditor-format-unsupported"};let e=await n.runFormatCommand(t);return e?.status==="applied"?e.result:(Mn(n,e),{ok:!1,code:e?.code??e?.status??"blockeditor-format-refused",retry:e?.retry===!0})}var{TextSelection:at}=O,$=b.nodes,W=[{key:"text",label:"Text",description:"Plain writing",icon:"T",type:"paragraph",aliases:["p","paragraph","plain"]},{key:"h1",label:"Heading 1",description:"Big section heading",icon:"H1",type:"heading",attrs:{level:1},hint:"#",aliases:["h1","title"]},{key:"h2",label:"Heading 2",description:"Medium section heading",icon:"H2",type:"heading",attrs:{level:2},hint:"##",aliases:["h2","subtitle"]},{key:"h3",label:"Heading 3",description:"Small section heading",icon:"H3",type:"heading",attrs:{level:3},hint:"###",aliases:["h3"]},{key:"bullet",label:"Bulleted list",description:"A simple list",icon:"\u2022",type:"list_item",attrs:{kind:"bullet"},hint:"-",aliases:["ul","bullet","list","unordered"]},{key:"ordered",label:"Numbered list",description:"A list with numbers",icon:"1.",type:"list_item",attrs:{kind:"ordered"},hint:"1.",aliases:["ol","num","numbered","ordered"]},{key:"check",label:"Checklist",description:"Tasks to tick off",icon:"\u2610",type:"list_item",attrs:{kind:"check"},hint:"[]",aliases:["todo","to-do","task","check","checkbox"]},{key:"toggle",label:"Toggle",description:"Hide details under a line",icon:"\u25B8",type:"toggle",attrs:{open:!0},hint:">",aliases:["collapse","details","fold"]},{key:"toggle-h1",label:"Toggle heading 1",description:"Collapsible heading",icon:"H1",type:"toggle",attrs:{open:!0,level:1},aliases:["toggle heading"]},{key:"toggle-h2",label:"Toggle heading 2",description:"Collapsible heading",icon:"H2",type:"toggle",attrs:{open:!0,level:2},aliases:["toggle heading"]},{key:"toggle-h3",label:"Toggle heading 3",description:"Collapsible heading",icon:"H3",type:"toggle",attrs:{open:!0,level:3},aliases:["toggle heading"]},{key:"callout",label:"Callout",description:"Make a note stand out",icon:"!",type:"callout",aliases:["note","aside","info"]},{key:"quote",label:"Quote",description:"Set text apart as a quotation",icon:"\u201C",type:"quote",hint:'"',aliases:["blockquote","quotation","cite"]},{key:"code",label:"Code",description:"Code with highlighting",icon:"</>",type:"code_block",hint:"```",aliases:["pre","snippet"]}],Ro=[{key:"divider",label:"Divider",description:"A line between sections",icon:"\u2014",hint:"---",aliases:["hr","line","separator","rule"],insert:"divider"},{key:"toc",label:"Table of contents",description:"Links to this page's headings",icon:"\u2261",aliases:["toc","contents","outline","index"],insert:"toc"},{key:"image",label:"Image",description:"Upload or paste a picture",icon:"\u25A3",aliases:["img","picture","photo"],insert:"image"},{key:"file",label:"File",description:"Attach any file",icon:"\u2398",aliases:["upload","attachment","pdf"],insert:"file"},{key:"table",label:"Table",description:"Rows and columns, paste from a spreadsheet",icon:"\u25A6",aliases:["grid","spreadsheet"],insert:"table"},{key:"csv",label:"Import CSV\u2026",description:"Turn a CSV file into a table",icon:"\u21E7",aliases:["comma separated","import"],insert:"csv"},{key:"board",label:"Board",description:"Cards in columns, like a kanban",icon:"\u25A5",aliases:["kanban","cards","columns","status"],insert:"board"},{key:"mention",label:"Mention",description:"Name someone on the page",icon:"@",aliases:["person","people","assign"],command:"mentions"},{key:"date",label:"Date",description:"Today, tomorrow or a calendar day",icon:"\u25A7",aliases:["calendar","today","tomorrow","due"],command:"dates"},{key:"emoji",label:"Emoji",description:"Insert one glyph",icon:"\u263A",aliases:["smiley","glyph","symbol"],command:"emoji"},{key:"import-markdown",label:"Import Markdown\u2026",description:"Turn a Markdown file into blocks",icon:"M\u2193",aliases:["md","markdown","import"],command:"importMarkdown"}],No={key:"chart",label:"Chart",description:"A bar or line chart from a table",icon:"\u{1F4CA}",aliases:["graph","plot","bar","line"],insert:"chart"},ie=n=>(qe.get(n)?.ensure("chart")??Promise.resolve()).catch(()=>{}).then(()=>n.isDestroyed?null:import("./c-BOS7GONO.js")),It=[...W,...Ro],Sn=(n,t=It)=>yn(n.doc).length?[...t,No]:t;function Lt(n){let t=n.type.name;return W.find(e=>e.type===t&&(!e.attrs||(t==="heading"||t==="toggle"?(e.attrs.level??null)===(n.attrs.level??null):t==="list_item"?e.attrs.kind===n.attrs.kind:!0)))??W[0]}var le=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e};function J(n,t,e){let o=le(n.doc,t),s=n.doc.child(t),r={id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent};return s.type===$.list_item&&e.type==="list_item"&&(r.indent=s.attrs.indent),n.setBlockType(o+1,o+s.nodeSize-1,$[e.type],{...r,...e.attrs||{}})}var Tn=Object.freeze({status:"refused",code:"unsupported-format"}),Ho=Ae([]).type,zo=n=>{let t=!1;return n.forEach(e=>{!t&&e.marks.some(Ce)&&(t=!0)}),t};function tt(n,t){return!n.isTextblock||n.type===$.opaque_block?!1:!zo(n)||$[t.type].allowsMarkType(Ho)}var En=n=>n.type==="toggle"&&n.attrs?.level!=null,vt=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e},ce={ok:!1,code:"stale-target"};function Cn(n,t,e){let o=()=>e.map(r=>vt(n.state.doc,r)),s=()=>{let r=o();if(r.includes(-1))return ce;if(r.some(l=>!tt(n.state.doc.child(l),t)))return Tn;let i=n.state.tr;for(let l of r)J(i,l,t);return n.dispatch(S(i).scrollIntoView()),n.focus(),{ok:!0}};return En(t)?Ot(n,s):t.type==="quote"?import("./c-3S3647J6.js").then(r=>n.isDestroyed?!1:r.gateTurn(n,s)):s()}function An(n,t,e=n.tr){let o=Q(e.doc),{to:s}=Ue(o,t),r=e.doc.child(t);return e.insert(s,$.paragraph.create({parent:r.attrs.parent??null})),e.setSelection(at.create(e.doc,s+1))}var Z=(n,t)=>H(n)&&(t===null||H(t)&&n<t)?v(n,t):null;function ae(n,t){let e=le(n.doc,t),o=n.doc.child(t),s=n.doc.maybeChild(t+1),{id:r,pos:i,parent:l}=o.attrs;return n.replaceWith(e,e+o.nodeSize,[$.divider.create({id:r,pos:i,parent:l}),$.paragraph.create({id:x(),pos:Z(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(at.create(n.doc,e+2))}function Fo(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===$.paragraph&&o.content.size===0)return ae(e,t);let s=Q(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=Z(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[$.divider.create({id:x(),pos:c,parent:d}),$.paragraph.create({id:x(),pos:Z(c,l),parent:d})]),e.setSelection(at.create(e.doc,i+2))}function Ko(n,t){let e=le(n.doc,t),o=n.doc.child(t),s=n.doc.maybeChild(t+1),{id:r,pos:i,parent:l}=o.attrs;return n.replaceWith(e,e+o.nodeSize,[$.toc.create({id:r,pos:i,parent:l,maxLevel:3}),$.paragraph.create({id:x(),pos:Z(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(at.create(n.doc,e+2))}function Vo(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===$.paragraph&&o.content.size===0)return Ko(e,t);let s=Q(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=Z(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[$.toc.create({id:x(),pos:c,parent:d,maxLevel:3}),$.paragraph.create({id:x(),pos:Z(c,l),parent:d})]),e.setSelection(at.create(e.doc,i+2))}function jo(n,t){if(n.length<2||n.length>32)return 1/0;let e=-1,o=0;for(let s of n){let r=t.indexOf(s,e+1);if(r<0)return 1/0;o+=r-e-1,e=r}return o}function On(n,t){let e=t.trim().toLowerCase();if(!e)return n;let o=s=>{let r=s.label.toLowerCase(),i=[s.key,...s.aliases||[],...s.hint?[s.hint]:[]].map(c=>c.toLowerCase());if(r===e||i.includes(e))return[0,0];if(r.startsWith(e))return[1,0];if([...r.split(/\s+/),...i].some(c=>c.startsWith(e)))return[2,0];if([r,...i].some(c=>c.includes(e)))return[3,0];if(e.length>=3&&s.description&&s.description.toLowerCase().split(/[^a-z0-9]+/).some(c=>c.startsWith(e)))return[4,0];let l=Math.min(...[r,s.key,...s.aliases||[]].map(c=>jo(e,c.toLowerCase())));return l===1/0?null:[5,l]};return n.map((s,r)=>({it:s,order:r,rank:o(s)})).filter(s=>s.rank).sort((s,r)=>s.rank[0]-r.rank[0]||s.rank[1]-r.rank[1]||s.order-r.order).map(s=>s.it)}function wn(n,t,e,o){let s=n.state,r=s.tr;o&&r.delete(o.from,o.to);let i=r.doc.child(e);return i.isTextblock&&i.content.size===0&&!tt(i,t)?Tn:(t.insert==="divider"?r=Fo(s,e,r):i.isTextblock&&i.content.size===0?r=J(r,e,t):(r=An(s,e,r),r=J(r,r.doc.resolve(r.selection.head).index(0),t)),n.dispatch(S(r).scrollIntoView()),n.focus(),!0)}function qo(n,t,e=null){let o=n.state,s=o.doc.maybeChild(t)?.attrs.id??null,r=e&&{...e,text:o.doc.textBetween(e.from,e.to)};return Ot(n,()=>{let i=n.state;if((s===null?-1:vt(i.doc,s))<0||r&&i.doc.textBetween(r.from,r.to)!==r.text)return ce;let c=r?i.tr.delete(r.from,r.to):i.tr;return c=Vo(i,vt(c.doc,s),c),n.dispatch(S(c).scrollIntoView()),n.focus(),{ok:!0}})}var et=(n,t,e)=>import("./page/editor-UF3CIA6V.js").then(({runPageCommand:o})=>n.isDestroyed?{ok:!1,code:"not-editing"}:o(n,t,e));function Wo(n,t,e){return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),et(n,t,{})}function vn(n,t,e,o=null){let s=n.state;if(t.insert==="image"||t.insert==="file")return je(n,t.insert==="image"?"image/*":"",Ve(s,e),o);if(t.insert==="csv")return $t(n,o);if(t.insert==="table")return K(s,n.dispatch,fn(),o,null,e);if(t.insert==="board")return kn(s,n.dispatch,re(),o,e);if(t.insert==="chart")return ie(n).then(l=>l&&!n.isDestroyed?l.chartFromSlash(n,e,o):!1);if(t.insert==="toc")return qo(n,e,o);if(t.command)return Wo(n,t.command,o);if(!En(t)&&t.type!=="quote")return wn(n,t,e,o);let r=s.doc.maybeChild(e)?.attrs.id??null,i=o&&{...o,text:s.doc.textBetween(o.from,o.to)};return Ot(n,()=>{let l=n.state,c=r===null?-1:vt(l.doc,r);return c<0||i&&l.doc.textBetween(i.from,i.to)!==i.text?ce:wn(n,t,c,i)})}var{InputRule:he}=Vt,U=b.nodes,Dt=(n,t,e)=>n.doc.rangeHasMark(t,e,b.marks.code)||!!b.marks.code.isInSet(n.storedMarks||n.selection.$from.marks()),nt=(n,t,e=["paragraph"],o=!1)=>new he(n,(s,r,i,l)=>{let c=s.doc.resolve(i);return!s.selection.empty||c.depth!==1||c.parentOffset!==0||!e.includes(c.parent.type.name)||o&&l!==c.end()||Dt(s,i,l)?null:S(J(s.tr.delete(i,l),c.index(0),typeof t=="function"?t(r):t))}),Uo=new he(/^---$/,(n,t,e,o)=>{let s=n.doc.resolve(e);return!n.selection.empty||s.depth!==1||s.parent.type!==U.paragraph||s.parentOffset!==0||s.parent.content.size!==o-e||Dt(n,e,o)?null:S(ae(n.tr,s.index(0)))}),pe=`\\s\\(\\[\\{'\u2018\u201C"`,Go=new RegExp(`[${pe}]`),ue=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),$n=n=>`([^\\s${n}](?:[\\s\\S]*?[^\\s${n}])?)`,_t=(n,t)=>!!n?.isComposing||n?.keyCode===229||!!t?.composing,In=n=>{let t=0;for(let e=n.length-1;e>=0&&n[e]==="\\";e--)t++;return t},Yo=(n,t)=>{let e=n.doc.resolve(t);return!e.parent.inlineContent||In(e.parent.textBetween(0,e.parentOffset,null,"\uFFFC"))%2?!1:e.parentOffset===0||Go.test(e.parent.textBetween(e.parentOffset-1,e.parentOffset))},Jo=(n,t,e,o,s)=>{let r=s(t);if(!r||!n.selection.empty||e<0||e>o||o>n.doc.content.size)return null;let i=n.doc.resolve(e),l=n.doc.resolve(o);if(!i.sameParent(l)||!i.parent.inlineContent)return null;let[c,d,u,a]=t;if(Dt(n,e,o))return null;let h=c.slice(d.length,c.length-u.length-a.length),p=e+d.length;if(!Yo(n,p)||In(c.slice(0,c.length-a.length))%2)return null;let f=c.length-(o-e);if(f<0)return null;let m=n.tr;f&&m.insertText(c.slice(-f),o,o);let g=p+h.length,k=g+u.length;return m.delete(k,e+c.length),m.delete(p,g),m.addMark(p,p+u.length,r),m.removeStoredMark(r.type),S(m)},Ln=(n,t)=>new he(n,(e,o,s,r)=>Jo(e,o,s,r,t),{inCodeMark:!1}),ot=(n,t,e)=>Ln(new RegExp(`(^|[${pe}])${ue(n)}${$n(ue(t))}(${ue(t)})$`),()=>e.create()),Xo=Ln(new RegExp(`(^|[${pe}])\\[${$n("\\[\\]")}(\\]\\([^()\\s]*\\))$`),n=>{let t=Te(n[3].slice(2,-1));return t?b.marks.link.create({href:t}):null}),Qo=[ot("**","**",b.marks.strong),ot("__","__",b.marks.strong),ot("*","*",b.marks.em),ot("_","_",b.marks.em),ot("`","`",b.marks.code),ot("~~","~~",b.marks.strike),Xo],de=["paragraph","list_item"],Zo=[nt(/^(#{1,3})\s$/,n=>({type:"heading",attrs:{level:n[1].length}})),nt(/^[-*+]\s$/,{type:"list_item",attrs:{kind:"bullet"}},de),nt(/^\d+[.)]\s$/,{type:"list_item",attrs:{kind:"ordered"}},de),nt(/^\[( |x|X)?\]\s$/,n=>({type:"list_item",attrs:{kind:"check",checked:!!n[1]&&n[1]!==" "}}),de),nt(/^>\s$/,{type:"toggle",attrs:{open:!0}}),nt(/^```$/,{type:"code_block"},["paragraph"],!0),Uo,...Qo];function ts(n,t,e,o,s){if(s!==" "||e!==o)return!1;let r=t.state,i=r.doc.resolve(e),l=i.parent;if(i.depth!==1||l.type!==U.paragraph||i.parentOffset!==1||l.textContent!=='"'||!t.editable||typeof t.runFormatCommand!="function")return!1;let c=()=>{t.isDestroyed||t.state.doc!==r.doc||t.dispatch(t.state.tr.insertText(" ",e,o))},d=i.before(1);return import("./c-3S3647J6.js").then(({quoteFromSpace:u})=>u(n,t,{at:d,from:e,to:o},c),c),!0}var Hi=()=>{let n=Vt.inputRules({rules:Zo}),t=n.props.handleTextInput;return n.props.handleTextInput=(e,o,s,r)=>ts(n,e,o,s,r)||t(e,o,s,r),n},es=/^\s*\|(.*)\|\s*$/;function ns(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parent.type!==U.paragraph||e.parentOffset!==e.parent.content.size||Dt(n,e.start(),e.end()))return!1;let s=es.exec(e.parent.textContent);if(!s)return!1;let r=s[1].split("|").map(l=>l.trim());if(!r.some(Boolean))return!1;let i=Et([r,r.map(()=>"")],{header:!0});return K(n,t,i,{from:e.start(),to:e.end()})}var zi=()=>pt.keymap({Enter:(n,t,e)=>!_t(null,e)&&ns(n,t)});function Fi(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parentOffset!==0)return!1;let s=e.parent;return s.type===U.heading||s.type===U.callout||s.type===U.quote||s.type===U.code_block&&s.content.size===0?(t&&t(S(n.tr.setNodeMarkup(e.before(),U.paragraph,{id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent}))),!0):!1}var{Plugin:Rn,PluginKey:Nn,TextSelection:Rt,NodeSelection:os}=O,Hn=b.marks,G=b.nodes,Pt=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"\u2318":"Ctrl+",zn=n=>{let t=xt(n.doc),{lo:e,hi:o}=n.selection.span(n.doc);return t.slice(e,o+1).filter(s=>s.up===t[e].up)},Bt=(n,t)=>n.state.doc.child(t).attrs.id,ss=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e},Dn=["aria-haspopup","aria-controls","aria-activedescendant"],rs="That block is no longer available.",ke="This block holds content from a newer version, so it can't be converted here.";function fe(n){let t=n.visualViewport;return t?{left:t.offsetLeft,top:t.offsetTop,width:t.width,height:t.height}:{left:0,top:0,width:n.innerWidth,height:n.innerHeight}}function is(n,t,e,o=0){let s=_,r=Math.min(t,Math.max(0,n.width-s*2));return{left:n.left+(n.width-r)/2,top:Math.max(n.top+s,n.top+n.height-e-o-s),width:r}}function ls(n,t=globalThis.location){return`${t.origin}${t.pathname}${t.search}#${encodeURIComponent(n)}`}function cs(n){if(!n)return;let t=()=>N("Link copied"),e=()=>N("Could not copy the link.","error");if(!globalThis.navigator?.clipboard?.writeText){e();return}globalThis.navigator.clipboard.writeText(ls(n)).then(t,e)}var Fn=[{key:"up",label:"Move up",icon:"up",hint:`${Pt}\u21E7\u2191`,run:n=>qt(-1)(n.state,n.dispatch)},{key:"down",label:"Move down",icon:"down",hint:`${Pt}\u21E7\u2193`,run:n=>qt(1)(n.state,n.dispatch)},{key:"indent",label:"Indent",icon:"indent",hint:"Tab",run:n=>{let t=n.state.doc;Ye(n.state,n.dispatch),n.state.doc===t&&(R(n,"Indent works on list items and inside toggles."),N("Indent works on list items and inside toggles."))}},{key:"outdent",label:"Outdent",icon:"outdent",hint:"\u21E7Tab",run:n=>Je(n.state,n.dispatch)},{key:"duplicate",label:"Duplicate",icon:"duplicate",hint:`${Pt}D`,run:n=>tn(n.state,n.dispatch)},{key:"delete",label:"Delete",icon:"trash",hint:"Del",run:n=>Ut(n.state,n.dispatch)},{key:"turn",label:"Turn into",icon:"turn",hint:"\u203A",only:"text",run:(n,t)=>t.openMenu("turn",t.plus)},{key:"link",label:"Copy link",icon:"link",run:(n,t,e)=>cs(n.state.doc.child(e).attrs.id)},{key:"alt",label:"Alt text\u2026",icon:"alt",only:"image",focus:!1,run:(n,t,e)=>{let o=Bt(n,e);return import("./c-5ELELG2F.js").then(s=>s.openAltEditor(n,o))}},{key:"small",label:"Small",icon:"small",only:"image",run:(n,t,e)=>{let o=Bt(n,e);return import("./c-5ELELG2F.js").then(s=>s.setImageAttrs(n,o,{width:240}))}},{key:"medium",label:"Medium",icon:"medium",only:"image",run:(n,t,e)=>{let o=Bt(n,e);return import("./c-5ELELG2F.js").then(s=>s.setImageAttrs(n,o,{width:480}))}},{key:"full",label:"Full width",icon:"full",only:"image",run:(n,t,e)=>{let o=Bt(n,e);return import("./c-5ELELG2F.js").then(s=>s.setImageAttrs(n,o,{width:null}))}},{key:"chart",label:"Chart this table",icon:"chart",only:"table",run:(n,t,e)=>{let o=ss(n.state.doc,e);return ie(n).then(({insertChartAfterTable:s})=>s(n,o))}},{key:"csv",label:"Import CSV\u2026",icon:"csv",only:"table",focus:!1,run:(n,t,e)=>$t(n,null,n.state.doc.child(e).attrs.id)}],as=n=>{if(!(n.selection instanceof F))return[];let t=zn(n),e=t.every(r=>r.node.isTextblock),o=t.length===1&&t[0].node.type===G.image,s=t.length===1&&t[0].node.type===G.table;return Fn.filter(r=>r.only==="text"?e:r.only==="image"?o:r.only==="table"?s:!0)},M=n=>`<svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,V={plus:M('<path d="M8 3.5v9M3.5 8h9"/>'),grip:M('<path stroke-width="2.2" d="M6 3.5h.01M10 3.5h.01M6 8h.01M10 8h.01M6 12.5h.01M10 12.5h.01"/>'),strong:M('<path d="M5 3h4a2.5 2.5 0 0 1 0 5H5zM5 8h4.6a2.5 2.5 0 0 1 0 5H5z"/>'),em:M('<path d="M10 3H6.5M9.5 13H6M9 3l-2 10"/>'),strike:M('<path d="M3 8h10M10.8 5.2C10.5 4 9.4 3.2 8 3.2c-1.7 0-2.8.9-2.8 2.1M5.2 10.8c.3 1.2 1.4 2 2.8 2 1.7 0 2.8-.9 2.8-2.1"/>'),code:M('<path d="M6 4.5 2.5 8 6 11.5M10 4.5 13.5 8 10 11.5"/>'),link:M('<path d="M7 9a2.5 2.5 0 0 0 3.5 0l2-2A2.5 2.5 0 0 0 9 3.5l-.7.7M9 7a2.5 2.5 0 0 0-3.5 0l-2 2A2.5 2.5 0 0 0 7 12.5l.7-.7"/>'),bullet:M('<path d="M6.5 4.5h7M6.5 8h7M6.5 11.5h7"/><path stroke-width="2.4" d="M3 4.5h.01M3 8h.01M3 11.5h.01"/>'),ordered:M('<path d="M7 4.5h6.5M7 8h6.5M7 11.5h6.5M2.5 3.5l1-.5v3M2.5 9.3c.2-.5.6-.8 1.1-.8.6 0 1 .4 1 .9 0 .9-2.1 1.4-2.1 2.6h2.1"/>'),check:M('<rect x="2.5" y="2.5" width="11" height="11" rx="2.5"/><path d="M5.5 8.2l1.8 1.8 3.4-4"/>'),more:M('<path stroke-width="2.2" d="M3 8h.01M8 8h.01M13 8h.01"/>'),gear:M('<g transform="scale(0.6667)" stroke-width="2.25"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g>'),close:M('<path d="M4 4l8 8M12 4l-8 8"/>'),up:M('<path d="M8 13V3.5M4 7.5 8 3.5l4 4"/>'),down:M('<path d="M8 3v9.5M4 8.5l4 4 4-4"/>'),indent:M('<path d="M2.5 3.5h11M7 8h6.5M2.5 12.5h11M2.5 6l2.5 2-2.5 2"/>'),outdent:M('<path d="M2.5 3.5h11M7 8h6.5M2.5 12.5h11M5 6 2.5 8 5 10"/>'),duplicate:M('<rect x="5.5" y="5.5" width="8" height="8" rx="1.5"/><path d="M10.5 3.5v-.5A1.5 1.5 0 0 0 9 1.5H4A1.5 1.5 0 0 0 2.5 3v5A1.5 1.5 0 0 0 4 9.5h.5"/>'),trash:M('<path d="M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5"/>'),turn:M('<path d="M3 5.5h9.5M10 3l2.5 2.5L10 8M13 10.5H3.5M6 8l-2.5 2.5L6 13"/>'),chart:M('<path d="M3 13V3M3 13h10.5M6 10.5V8M9 10.5V5.5M12 10.5V7"/>'),csv:M('<path d="M4 1.5h5L12.5 5v9.5h-8.5zM9 1.5V5h3.5M8 7.5v5M6 10.5l2 2 2-2"/>'),alt:M('<path d="M2.5 12.5 5.5 4l3 8.5M3.6 9.5h3.8M10 12.5V7.5M10 8.5c.4-.7 1.1-1 2-1h.5"/>'),small:M('<rect x="5" y="5" width="6" height="6" rx="1"/>'),medium:M('<rect x="3.5" y="3.5" width="9" height="9" rx="1.2"/>'),full:M('<rect x="1.5" y="3.5" width="13" height="9" rx="1.2"/>')},me=[["strong","Bold"],["em","Italic"],["strike","Strikethrough"],["link","Link"],["bullet","Bulleted list"],["ordered","Numbered list"],["check","Checklist"],["code","Code"]],Kn=new Set(["strong","em","link"]),us=new Set(["up","down","indent","outdent"]),ds=204,hs=52,_=8,Vn=new Set(["bullet","ordered","check"]),ps=[["assignees","Checklist assignees"],["dates","Checklist due dates"]],fs=new Set(["paragraph","heading","list_item"]),ut=n=>{let t=n.selection;if(t instanceof F)return zn(n).map(l=>l.i);let{$from:e,$to:o,empty:s}=t,r=Math.min(!s&&o.depth===0?o.index(0)-1:o.index(0),n.doc.childCount-1),i=[];for(let l=e.index(0);l<=r;l++)i.push(l);return i},jn=n=>ut(n).filter(t=>{let e=n.doc.child(t);return e.isTextblock&&e.type!==G.code_block}),qn=(n,t)=>n.type===G.list_item&&n.attrs.kind===t,Wn=(n,t)=>{let e=jn(n);return e.length>0&&e.every(o=>qn(n.doc.child(o),t))},ms=n=>{let t="";return n.forEach(e=>{t+=e.isText?e.text:e.type===G.hard_break?`
3
+ `:""}),t};function gs(n){let{$from:t,$to:e,empty:o}=n.selection;if(o||!(n.selection instanceof Rt)||t.depth!==1||e.depth!==1||t.parentOffset!==0||e.parentOffset!==e.parent.content.size)return null;let s=ut(n);return s.every(r=>fs.has(n.doc.child(r).type.name))?s:null}function bs(n,t){let e=n.doc.child(t[0]),o=n.selection.$from.before(1),s=n.selection.$to.after(1),r=t.map(u=>ms(n.doc.child(u))).join(`
4
+ `),{id:i,pos:l,parent:c}=e.attrs,d=n.tr.replaceWith(o,s,G.code_block.create({id:i,pos:l,parent:c},r?b.text(r):null));return d.setSelection(Rt.create(d.doc,o+1,o+1+r.length))}function ks(n,t){let e=n.tr,o=n.doc.resolve(n.selection.from).before(1),s=0;for(let r of[...t].reverse()){let i=0;for(let h=0;h<r;h++)i+=n.doc.child(h).nodeSize;let l=n.doc.child(r),{id:c,pos:d,parent:u}=l.attrs,a=l.textContent.split(`
5
+ `).map((h,p)=>G.paragraph.create(p===0?{id:c,pos:d,parent:u}:{parent:u},h?b.text(h):null));e.replaceWith(i,i+l.nodeSize,a),s||(s=i+a.reduce((h,p)=>h+p.nodeSize,0))}return s=e.mapping.slice(1).map(s),e.setSelection(Rt.create(e.doc,o+1,s-1))}var Un=n=>{let t=ut(n);return t.length>0&&t.every(e=>n.doc.child(e).type===G.code_block)?t:null};function _n(n,t){if(Vn.has(t))return Wn(n,t);if(t==="code"&&Un(n))return!0;let e=Hn[t],{from:o,to:s,empty:r,$from:i}=n.selection;return r?!!e.isInSet(n.storedMarks||i.marks()):n.doc.rangeHasMark(o,s,e)}function ys(n,t){let e=n.state,o=Wn(e,t),s=W.find(l=>l.key===(o?"text":t)),r=jn(e).filter(l=>o||!qn(e.doc.child(l),t));if(r.some(l=>!tt(e.doc.child(l),s))){R(n,ke);return}let i=e.tr;for(let l of r)J(i,l,s);i.docChanged&&n.dispatch(S(i))}var ge=(n,t,e)=>import("./c-3S3647J6.js").then(o=>o.nativeMenu(n,e,t.pickedFrom??t.more));function Bn(n,t){if(t==="link")return Fe(n);let e=n.state,o=t==="code"?Un(e):null,s=t==="code"&&!o?gs(e):null;Vn.has(t)?ys(n,t):o?n.dispatch(S(ks(e,o)).scrollIntoView()):s&&s.some(r=>!tt(e.doc.child(r),W.find(i=>i.key==="code")))?R(n,ke):s?n.dispatch(S(bs(e,s)).scrollIntoView()):Se.toggleMark(Hn[t])(e,n.dispatch),n.focus()}var y=(n,t,e={})=>{let o=document.createElement(n);t&&(o.className=t);for(let[s,r]of Object.entries(e))o.setAttribute(s,r);return o};function Pn(n,t){let e=y("button",`blockeditor-tool${Kn.has(n)?" blockeditor-tool-primary":" blockeditor-tool-desk"}`,{type:"button","data-cmd":n,"aria-label":t,title:t});return e.innerHTML=V[n],e}var xs=1600,Ms=0,ws=new Nn("blockeditor-chrome"),ye=new WeakMap,Nt=new Nn("blockeditor-slash-range"),Ss={init:()=>null,apply(n,t){let e=t;if(e&&n.docChanged){let s=n.mapping.map(e.from,1),r=n.mapping.map(e.to,-1);e=s<=r&&n.doc.textBetween(s,r)===e.text?{...e,from:s,to:r}:null}let o=n.getMeta(Nt);return o!==void 0&&(e=o),e}},il=()=>new Rn({key:Nt,state:Ss}),Gn=(n,t)=>{let e=t?n.state.doc.textBetween(t.from,t.to):null;n.dispatch(n.state.tr.setMeta(Nt,t?{...t,text:e}:null))},Yn=n=>{let t=Nt.getState(n);return t?{from:t.from,to:t.to}:null};function ll(n,t,e,{persist:o=!1}={}){let s=ye.get(n);return s?(s.openMenu("external",t),s.menu.externalItems=e,s.menu.persist=o,s.renderMenu(),!0):!1}function cl(n,t,e){let o=ye.get(n),s=o?.menu;return!s||s.anchor!==t||!e||e===t?!1:(s.anchor=e,e.setAttribute("aria-expanded","true"),n.dom.setAttribute("aria-controls",o.menuId),!0)}var be=class{constructor(t,e,o){this.view=t,this.onAiTool=e,this.mediaNote=o,this.shell=t.dom.parentElement,this.menu=null,this.priorAria=null,this.movedTimer=0,this.hover=null,this.pendingHover=null,this.win=t.dom.ownerDocument.defaultView??globalThis,this.frame=null,this.destroyed=!1,this.probe=null,this.roving=null,this.remote=!1,this.dock=y("div","blockeditor-dock",{role:"toolbar","aria-label":"Formatting"}),this.turn=y("button","blockeditor-tool blockeditor-tool-turn blockeditor-tool-desk",{type:"button","aria-haspopup":"menu"}),this.more=y("button","blockeditor-tool blockeditor-tool-primary blockeditor-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.more.innerHTML=V.more,this.settingsBtn=y("button","blockeditor-tool blockeditor-tool-desk blockeditor-tool-settings",{type:"button","aria-label":"Document settings",title:"Document settings","aria-haspopup":"dialog","aria-expanded":"false"}),this.settingsBtn.innerHTML=V.gear,this.settingsEl=null,this.settingsOpen=!1,this.settingsAnchor=null,this.settingSwitches={},this.dock.append(this.turn,y("span","blockeditor-tool-sep blockeditor-tool-desk"),...me.map(([i,l])=>Pn(i,l)),this.more),this.dock.insertBefore(this.settingsBtn,this.more),this.settingsBtn.hidden=!this.settingsAPI,this.plus=y("button","blockeditor-plus",{type:"button","aria-label":"Add a block",title:"Add a block"}),this.plus.innerHTML=V.plus,this.grip=y("button","blockeditor-grip",{type:"button","aria-label":"Block actions",title:"Drag to move, click for actions","aria-haspopup":"menu"}),this.grip.innerHTML=V.grip,this.bubble=y("div","blockeditor-bubble",{role:"toolbar","aria-label":"Selection",hidden:""}),this.bubbleTurn=y("button","blockeditor-tool blockeditor-tool-turn",{type:"button","aria-haspopup":"menu"}),this.bubbleMore=y("button","blockeditor-tool blockeditor-tool-primary blockeditor-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.bubbleMore.innerHTML=V.more,this.bubble.append(this.bubbleTurn,y("span","blockeditor-tool-sep"),...me.map(([i,l])=>Pn(i,l)),this.bubbleMore),this.menuId=`blockeditor-menu-${++Ms}`,this.menuEl=y("div","blockeditor-menu",{role:"menu",id:this.menuId,hidden:""}),this.scrim=y("div","blockeditor-scrim",{hidden:""}),this.shell.insertBefore(this.dock,t.dom),this.shell.append(this.plus,this.grip,this.bubble,this.scrim,this.menuEl);let s=i=>i.preventDefault();for(let i of[this.dock,this.plus,this.grip,this.bubble,this.menuEl])i.addEventListener("mousedown",s);for(let i of[this.dock,this.bubble])i.addEventListener("click",l=>{let c=l.target.closest("[data-cmd]");c&&Bn(this.view,c.dataset.cmd)});this.turn.addEventListener("click",()=>this.toggleMenu("turn",this.turn)),this.more.addEventListener("click",()=>this.toggleMenu("more",this.more)),this.settingsBtn.addEventListener("click",()=>this.toggleSettings()),this.bubbleTurn.addEventListener("click",()=>this.toggleMenu("turn",this.bubbleTurn)),this.bubbleMore.addEventListener("click",()=>this.toggleMenu("more",this.bubbleMore)),this.dock.addEventListener("keydown",i=>this.dockKey(i)),this.plus.addEventListener("click",()=>this.fromPlus()),this.grip.addEventListener("click",i=>{i.detail===0&&this.gripAction(this.gutterIndex())}),this.drag=new Ke(t,this.grip,{index:()=>this.gutterIndex(),onClick:i=>this.gripAction(i)});let r=!1;this.scrim.addEventListener("pointerdown",()=>{r=!0}),this.scrim.addEventListener("click",()=>{r&&this.closeMenu(),r=!1}),this.menuEl.addEventListener("click",i=>{let l=i.target.closest(".blockeditor-menu-item");l&&this.pick(Number(l.dataset.index))}),this.menuEl.addEventListener("keydown",i=>{this.key(i)&&i.preventDefault()}),this.onMove=i=>{this.shell.classList.add("is-moved"),clearTimeout(this.movedTimer),this.movedTimer=setTimeout(()=>this.shell.classList.remove("is-moved"),xs),this.trackHover(i)},this.onKey=()=>{clearTimeout(this.movedTimer),this.shell.classList.remove("is-moved"),this.pendingHover=null,this.setHover(null)},this.onLeave=()=>{this.pendingHover=null,this.setHover(null)},this.onResize=()=>{this.scheduleLayout(),this.placeSettings()},this.onDocDown=i=>{this.settingsOpen&&![this.settingsEl,this.settingsAnchor].some(l=>l?.contains(i.target))&&this.closeSettings(),this.menu&&([this.menuEl,this.plus,this.grip,this.turn,this.bubbleTurn,this.bubbleMore].some(l=>l.contains(i.target))||this.closeMenu())},this.onSettingsKey=i=>{i.key!=="Escape"||!this.settingsOpen||(i.preventDefault(),i.stopPropagation(),this.closeSettings(!0))},document.addEventListener("mousedown",this.onDocDown,!0),document.addEventListener("keydown",this.onSettingsKey,!0),this.shell.addEventListener("mousemove",this.onMove),this.shell.addEventListener("mouseleave",this.onLeave),this.shell.addEventListener("keydown",this.onKey),this.win.addEventListener("resize",this.onResize),this.win.addEventListener("scroll",this.onResize,!0),this.win.visualViewport?.addEventListener("resize",this.onResize),this.win.visualViewport?.addEventListener("scroll",this.onResize),this.update(t,null)}blockIndex(){let t=this.view.state,e=t.selection,o=e instanceof F||e instanceof os?e.from:e.head;return Math.min(t.doc.resolve(o).index(0),t.doc.childCount-1)}isPhone(){return!!this.win?.matchMedia?.("(max-width: 560px)").matches}gutterIndex(){return this.isPhone()?this.blockIndex():(this.settleHover(),Math.min(this.hover??this.blockIndex(),this.view.state.doc.childCount-1))}dockControls(){let t=[...this.dock.querySelectorAll("button")].filter(e=>this.rendered(e));return this.isPhone()?t.filter(e=>e.classList.contains("blockeditor-tool-primary")):t}inRoving(t){return!t||!this.dock.contains(t)||this.isPhone()&&!t.classList.contains("blockeditor-tool-primary")?!1:this.rendered(t)}rendered(t){if(t.hidden)return!1;let e=this.win?.getComputedStyle?.(t);return!e||e.display!=="none"}setRoving(t){this.roving=t;let e=new Set(this.dockControls());for(let o of this.dock.querySelectorAll("button"))o.tabIndex=o===t&&e.has(o)?0:-1}leaveToToolbar(){queueMicrotask(()=>{this.view.isDestroyed||this.focusToolbar()})}focusToolbar(){let[t]=this.dockControls();return t?(this.setRoving(t),t.focus(),!0):!1}dockKey(t){if(t.key==="Escape"){t.preventDefault(),this.view.focus();return}if(t.key!=="ArrowRight"&&t.key!=="ArrowLeft")return;let e=this.dockControls(),o=e.indexOf(t.target);if(o<0)return;t.preventDefault();let s=e[(o+(t.key==="ArrowRight"?1:-1)+e.length)%e.length];this.setRoving(s),s.focus()}selectionIds(){let t=this.view.state;return ut(t).map(e=>t.doc.child(e).attrs.id)}idIndex(t){let e=-1;return this.view.state.doc.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e}invoker(){let t=this.menu;if(!t||t.slashAt!==null)return this.view.dom;let e=t.anchor;return e&&e!==this.view.dom&&e.isConnected&&(e.tagName==="BUTTON"||e.hasAttribute("tabindex"))?e:this.view.dom}selectCaretBlock(t=null){let e=this.view.state;if(e.selection instanceof F)return;let o=(t??[]).map(r=>this.idIndex(r)).filter(r=>r>=0),s=o.length?o[0]:this.blockIndex();this.view.dispatch(e.tr.setSelection(Wt(e.doc,s,o.length?o[o.length-1]:s)))}gripAction(t){this.menu?this.closeMenu():this.openActions(this.grip,t)}trackHover(t){this.menu||this.drag.state||[this.plus,this.grip,this.dock,this.bubble].some(e=>e.contains(t.target))||(this.pendingHover={clientY:t.clientY},this.scheduleLayout())}hoverAt(t){let e=this.view,o=e.posAtCoords({left:e.dom.getBoundingClientRect().left+2,top:t});if(!o)return;let s=e.state.doc,r=xt(s),i=Math.min(s.resolve(o.inside>=0?o.inside:o.pos).index(0),r.length-1);for(;i>0&&r[i].hidden;)i--;this.hover=i}setHover(t){t!==this.hover&&(this.hover=t,this.scheduleLayout())}settleHover(){if(!this.pendingHover)return;let{clientY:t}=this.pendingHover;this.pendingHover=null,this.hoverAt(t)}fromPlus(){this.view.focus();let t=this.gutterIndex();this.openMenu("insert",this.plus,null,null,this.view.state.doc.child(t).attrs.id)}buildSettings(){if(this.settingsEl)return this.settingsEl;let t=y("div","blockeditor-settings",{role:"dialog","aria-label":"Document settings",hidden:""}),e=y("div","blockeditor-settings-head"),o=y("span","blockeditor-settings-title");o.textContent="Document settings";let s=y("button","blockeditor-settings-close",{type:"button","aria-label":"Close settings"});s.innerHTML=V.close,s.addEventListener("click",()=>this.closeSettings(!0)),e.append(o,s);let r=ps.map(([l,c])=>{let d=y("div","blockeditor-settings-row"),u=y("span","blockeditor-settings-name",{id:`${this.menuId}-set-${l}`});u.textContent=c;let a=y("button","blockeditor-settings-switch",{type:"button",role:"switch","aria-checked":"true","aria-labelledby":u.id,"data-setting":l});return a.append(y("span","blockeditor-settings-knob")),a.addEventListener("click",()=>this.flipSetting(l)),this.settingSwitches[l]=a,d.append(u,a),d}),i=y("div","blockeditor-settings-note");return i.textContent="Hidden values stay saved and come back when turned on.",t.append(e,...r,i),this.settingsEl=t,this.shell.append(t),t}flipSetting(t){let e=this.settingSwitches[t],o=e.getAttribute("aria-checked")!=="true";e.setAttribute("aria-checked",String(o)),Promise.resolve().then(()=>this.settingsAPI.set(t,o)).catch(()=>{e.setAttribute("aria-checked",String(!o)),N("That setting could not be saved.","error")})}openSettings(t=this.settingsBtn){if(!this.settingsAPI)return;this.menu&&this.closeMenu();let e=this.buildSettings(),o=this.settingsAPI.read();for(let[s,r]of Object.entries(this.settingSwitches))r.setAttribute("aria-checked",String(o[s]!==!1));this.settingsOpen=!0,this.settingsAnchor=t,t.setAttribute("aria-expanded","true"),e.hidden=!1,this.placeSettings(),e.querySelector(".blockeditor-settings-close")?.focus({preventScroll:!0})}closeSettings(t=!1){if(!this.settingsOpen)return;let e=this.settingsAnchor;this.settingsOpen=!1,this.settingsAnchor=null,this.settingsEl&&(this.settingsEl.hidden=!0),e?.setAttribute("aria-expanded","false"),t&&e?.isConnected&&e.focus({preventScroll:!0})}toggleSettings(){this.settingsOpen?this.closeSettings(!0):this.openSettings(this.settingsBtn)}placeSettings(){let t=this.settingsEl;if(!t||t.hidden||!this.settingsAnchor)return;let e=this.settingsAnchor.getBoundingClientRect(),o=t.offsetWidth||264,s=t.offsetHeight||0;if(this.isPhone()){let c=fe(this.win),d=Math.max(c.left+_,Math.min(e.right-o,c.left+c.width-_-o)),u=e.top-6-s;u<c.top+_&&(u=Math.min(e.bottom+6,c.top+c.height-_-s)),t.style.setProperty("--blockeditor-pop-x",`${d}px`),t.style.setProperty("--blockeditor-pop-y",`${Math.max(c.top+_,u)}px`);return}let r=this.shell.getBoundingClientRect(),i=Math.max(8,Math.min(e.right-r.left-o,Math.max(8,r.width-o-8))),l=e.bottom-r.top+6;l+s>this.win.innerHeight-8&&e.top-r.top-6-s>=8&&(l=e.top-r.top-6-s),t.style.setProperty("--blockeditor-pop-x",`${i}px`),t.style.setProperty("--blockeditor-pop-y",`${l}px`)}toggleMenu(t,e){this.menu?this.closeMenu():this.openMenu(t,e)}slashKey(t){let e=this.view.state.doc.resolve(t);return`${e.parent.attrs.id}\0${this.view.state.doc.textBetween(e.start(),t-1)}`}openMenu(t,e,o=null,s=null,r=null){this.closeSettings(),this.menu={mode:t,anchor:e,slashAt:o,anchorId:r,ids:s??(t==="insert"?[]:this.selectionIds()),query:"",active:0,items:[],persist:!1},e.setAttribute("aria-expanded","true"),o!==null?(this.priorAria||(this.priorAria=Dn.map(i=>[i,this.view.dom.getAttribute(i)])),this.view.dom.setAttribute("aria-haspopup","listbox")):this.view.dom.setAttribute("aria-haspopup","menu"),this.view.dom.setAttribute("aria-controls",this.menuId),this.renderMenu()}closeMenu(){if(this.menu?.anchor.setAttribute("aria-expanded","false"),this.menu=null,this.menuEl.hidden=!0,this.scrim.hidden=!0,this.priorAria){for(let[t,e]of this.priorAria)e===null?this.view.dom.removeAttribute(t):this.view.dom.setAttribute(t,e);this.priorAria=null}else for(let t of Dn)this.view.dom.removeAttribute(t)}moreItems(){let t=this.isPhone(),e=t?me.filter(([s])=>!Kn.has(s)).map(([s,r])=>({key:s,label:r,icon:s,run:i=>Bn(i,s)})):[],o=Fn.filter(s=>us.has(s.key)).map(s=>({...s,blocks:!0}));return[...e,{key:"underline",label:"Underline",icon:"U",hint:`${Pt}u`,run:(s,r)=>ge(s,r,"underline")},{key:"text_color",label:"Text color",icon:"A",hint:"\u203A",run:(s,r)=>ge(s,r,"text_color")},{key:"highlight",label:"Highlight",icon:"\u25A0",hint:"\u203A",run:(s,r)=>ge(s,r,"highlight")},...t?[{key:"turn",label:"Turn into",icon:"turn",run:(s,r)=>r.openMenu("turn",r.more)}]:[],{key:"insert",label:"Insert",icon:"+",run:(s,r)=>r.openMenu("insert",r.pickedFrom??r.more,null,null,s.state.doc.child(r.blockIndex()).attrs.id)},...o,...t&&this.settingsAPI?[{key:"settings",label:"Document settings",icon:"gear",focus:!1,run:(s,r)=>r.openSettings(r.more)}]:[],{key:"titleIcon",label:"Page icon",icon:"\u263A",run:s=>et(s,"titleIcon")},...this.mediaNote?[]:[{key:"titleCover",label:"Add cover",icon:"\u25A4",run:s=>et(s,"titleCover")}],{key:"exportHtml",label:"Export reading copy",icon:"\u21E9",run:s=>et(s,"exportHtml")},{key:"exportMarkdown",label:"Export as Markdown",icon:"M\u21E9",run:s=>et(s,"exportMarkdown")}]}menuItems(t){if(t.mode==="external")return t.externalItems||[];if(t.mode==="actions")return as(this.view.state);if(t.mode==="more")return this.moreItems();let e=this.onAiTool?[...It,{key:"ai",label:"Make a tool with AI\u2026",icon:"\u2726",aliases:["tool","generate"],insert:"ai"}]:It,o=this.mediaNote?e.filter(r=>r.key!=="image"&&r.key!=="file"):e,s=t.mode==="turn"?W:Sn(this.view.state,o);return On(s,t.query)}currentTypes(){let t=this.view.state;return new Set(ut(t).map(e=>Lt(t.doc.child(e)).key))}openActions(t=this.plus,e=null){let o=this.view.state,s=xt(o.doc),r=o.selection,i=e!==null&&r instanceof F&&r.span(o.doc).lo<=e&&e<=r.span(o.doc).hi,{lo:l,hi:c}=e===null||i?Ze(o,s):Ge(s,e,e);this.view.dispatch(o.tr.setSelection(Wt(o.doc,l,c,s)));let d=[];for(let u=l;u<=c;u++)d.push(o.doc.child(u).attrs.id);this.openMenu("actions",t,null,d)}renderMenu(){let t=this.menu;t.items=this.menuItems(t),t.active=Math.min(t.active,Math.max(0,t.items.length-1));let e=t.slashAt!==null,o=t.mode==="turn"?this.currentTypes():null;this.menuEl.setAttribute("role",e?"listbox":"menu");let s=[];if(t.mode==="turn"){let r=y("div","blockeditor-menu-title");r.textContent=t.query?`Turn into \u201C${t.query}\u201D`:"Turn into",s.push(r)}if(!t.items.length){let r=y("div","blockeditor-menu-empty");r.textContent="No matching blocks",s.push(r)}if(t.items.forEach((r,i)=>{let l=i===t.active,c=o?o.size===1&&r.key===[...o][0]:typeof r.checked=="boolean"?r.checked:null,d=t.mode==="turn"?"menuitemradio":typeof c=="boolean"?"menuitemcheckbox":e?"option":"menuitem",u=y("button",`blockeditor-menu-item${l?" is-active":""}`,{type:"button",role:d,tabindex:!e&&l?"0":"-1",id:`${this.menuId}-${i}`,"data-index":String(i),...d==="menuitemradio"?{}:{"aria-selected":l?"true":"false"},...typeof c=="boolean"?{"aria-checked":String(c)}:{}}),a=y("span","blockeditor-menu-icon");V[r.icon]?a.innerHTML=V[r.icon]:a.textContent=r.icon||"";let h=y("span","blockeditor-menu-label");if(h.textContent=r.label,r.description){let p=y("span","blockeditor-menu-text"),f=y("span","blockeditor-menu-desc");f.textContent=r.description,p.append(h,f),u.append(a,p)}else u.append(a,h);if(r.hint){let p=y("span","blockeditor-menu-hint");p.textContent=r.hint,u.append(p)}s.push(u)}),this.mediaNote&&t.mode!=="turn"&&t.mode!=="actions"&&t.mode!=="more"&&t.mode!=="external"){let r=y("div","blockeditor-menu-note",{role:"note"});r.textContent=this.mediaNote,s.push(r)}this.menuEl.replaceChildren(...s),e&&t.items.length?this.view.dom.setAttribute("aria-activedescendant",`${this.menuId}-${t.active}`):this.view.dom.removeAttribute("aria-activedescendant"),this.menuEl.hidden=!1,this.scrim.hidden=!1,this.scheduleLayout(),e||this.menuEl.querySelectorAll("button")[t.active]?.focus({preventScroll:!0})}pick(t){let e=this.menu,o=e?.items[t];if(!o)return;let s=this.view.state,r=e.slashAt!==null&&s.selection.head>=e.slashAt?{from:e.slashAt-1,to:s.selection.head}:null,i=e.mode==="insert"?e.anchorId?[e.anchorId]:[]:e.ids,l=i.some(d=>!d||this.idIndex(d)<0),c=i.length?this.idIndex(i[0]):-1;if(this.pickedFrom=e.anchor,this.closeMenu(),l&&e.mode!=="external"){R(this.view,rs),this.view.focus();return}if(e.mode==="turn"){if(i.some(d=>!tt(s.doc.child(this.idIndex(d)),o))){R(this.view,ke),this.view.focus();return}Cn(this.view,o,i)}else e.mode==="actions"||e.mode==="more"||e.mode==="external"?(o.blocks&&this.selectCaretBlock(i),o.run(this.view,this,c>=0?c:this.blockIndex()),!this.menu&&o.focus!==!1&&this.view.focus()):o.insert==="ai"?this.onAiTool(this.view,r):vn(this.view,o,c>=0?c:this.blockIndex(),r)}key(t){if(_t(t,this.view))return!1;let e=this.menu;if(!e)return t.key==="Escape"&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&this.view.state.selection instanceof F&&this.leaveToToolbar(),!1;if((t.key==="Backspace"||t.key==="Delete")&&e.mode==="actions"&&this.view.state.selection instanceof F)return this.closeMenu(),this.view.focus(),Ut(this.view.state,this.view.dispatch),!0;if(t.key==="ArrowDown"||t.key==="ArrowUp")return e.items.length&&(e.active=(e.active+(t.key==="ArrowDown"?1:-1)+e.items.length)%e.items.length,this.renderMenu()),!0;if(t.key==="Enter")return e.items.length&&this.pick(e.active),!0;if(t.key==="Tab"&&e.slashAt===null)return this.closeMenu(),!1;if(t.key==="Escape"){let o=this.invoker();return e.slashAt!==null&&(this.dismissedSlash=this.slashKey(e.slashAt)),this.closeMenu(),o===this.view.dom?this.view.focus():o?.focus?.(),!0}return!1}slashQuery(){let t=this.menu;if(!t||t.slashAt===null)return;let{$head:e}=this.view.state.selection,o=e.start();if(e.pos<t.slashAt||t.slashAt<o||this.view.state.doc.textBetween(t.slashAt-1,t.slashAt)!=="/")return this.closeMenu();if(t.query=this.view.state.doc.textBetween(t.slashAt,e.pos),t.active=0,/\s$/.test(t.query)&&!this.menuItems(t).length)return this.closeMenu();this.renderMenu()}scheduleLayout(){this.frame!==null||this.destroyed||(this.frame=this.win.requestAnimationFrame(()=>{if(this.frame=null,this.destroyed)return;let t=this.measureLayout();this.paintLayout(t)}))}safeBottom(){return this.probe||(this.probe=y("div","blockeditor-safe-probe"),this.shell.append(this.probe)),parseFloat(this.win.getComputedStyle(this.probe).paddingBottom)||0}menuBox(t){let e=fe(this.win),o=Math.max(0,e.height-_*2),s=Math.min(280,Math.max(0,e.width-_*2)),r=this.menuEl.style.getPropertyValue("--blockeditor-pop-max");this.menuEl.style.removeProperty("--blockeditor-pop-max");let i=this.menuEl.offsetHeight||0;r&&this.menuEl.style.setProperty("--blockeditor-pop-max",r);let l=Math.min(i,o),c=Math.max(e.left+_,Math.min(t.left,e.left+e.width-_-s)),d=t.top-6-l;return d<e.top+_&&(d=Math.min(t.top+t.height+6,e.top+e.height-_-l)),{left:c,top:d,width:s,maxHeight:o}}measureLayout(){let t=this.view,e=t.state;this.settleHover();let o=this.shell.getBoundingClientRect(),s=t.dom.getBoundingClientRect(),r=this.gutterIndex(),i=0;for(let a=0;a<r;a++)i+=e.doc.child(a).nodeSize;let l=t.nodeDOM(i),c={textLeft:s.left-o.left,gutter:null,bubble:null,menu:null,bar:null,desk:!1};if(l&&l.getBoundingClientRect){let a=l.getBoundingClientRect(),h=parseFloat(getComputedStyle(l).lineHeight)||a.height;c.gutter={top:a.top-o.top+Math.min(a.height,h)/2,left:a.left-o.left}}let d=this.isPhone();if(d){let a=fe(this.win),h=this.dock.offsetHeight||hs;c.bar={...is(a,this.dock.offsetWidth||ds,h,this.safeBottom()),height:h}}else c.desk=!!this.dock.style.left;let u=e.selection;if(!this.bubble.hidden&&!d){let a=t.coordsAtPos(u.from),h=t.coordsAtPos(u.to,-1),p=(Math.min(a.left,h.left)+Math.max(a.right,h.right))/2;c.bubble={x:p-o.left,y:Math.min(a.top,h.top)-o.top}}if(this.menu&&d){let a=this.menuBox(c.bar);c.menu={x:a.left,y:a.top,width:a.width,maxHeight:a.maxHeight}}else if(this.menu){let a=this.menu,h,p;if(a.slashAt!==null){let f=t.coordsAtPos(a.slashAt-1);h=f.left,p=f.bottom+6;let m=this.menuEl.offsetHeight;p+m>this.win.innerHeight-8&&f.top-6-m>=8&&(p=f.top-6-m)}else{let f=a.anchor===this.plus?l?.getBoundingClientRect?.()??s:a.anchor.getBoundingClientRect();h=f.left,p=f.bottom+6;let m=this.menuEl.offsetHeight;p+m>this.win.innerHeight-8&&f.top-6-m>=8&&(p=f.top-6-m)}c.menu={x:Math.max(8,Math.min(h-o.left,o.width-280)),y:p-o.top}}return c}paintLayout(t){if(t.bar)this.dock.style.left=`${t.bar.left}px`,this.dock.style.top=`${t.bar.top}px`,this.dock.style.width=`${t.bar.width}px`,this.grip.style.setProperty("--blockeditor-grip-lift",`${t.bar.height}px`);else{if(t.desk)for(let e of["left","top","width"])this.dock.style.removeProperty(e);this.grip.style.removeProperty("--blockeditor-grip-lift")}if(t.gutter)for(let e of[this.plus,this.grip])e.style.setProperty("--blockeditor-plus-top",`${t.gutter.top}px`),e.style.setProperty("--blockeditor-plus-left",`${t.gutter.left}px`);this.plus.style.setProperty("--blockeditor-text-left",`${t.textLeft}px`),t.bubble&&(this.bubble.style.setProperty("--blockeditor-pop-x",`${t.bubble.x}px`),this.bubble.style.setProperty("--blockeditor-pop-y",`${t.bubble.y}px`)),t.menu&&(this.menuEl.style.setProperty("--blockeditor-pop-x",`${t.menu.x}px`),this.menuEl.style.setProperty("--blockeditor-pop-y",`${t.menu.y}px`),t.menu.width!==void 0&&(this.menuEl.style.setProperty("--blockeditor-pop-width",`${t.menu.width}px`),this.menuEl.style.setProperty("--blockeditor-pop-max",`${t.menu.maxHeight}px`)))}get settingsAPI(){return globalThis.clay?.blockeditor?.settings??null}update(t,e){let o=!this.settingsAPI;if(this.settingsBtn.hidden!==o&&(this.settingsBtn.hidden=o),this.view=t,this.menu&&this.menu.slashAt===null&&e&&e.doc!==t.state.doc)if(this.menu.persist&&this.menu.anchor?.isConnected)this.scheduleLayout();else{let c=this.menuEl.contains(document.activeElement);this.closeMenu(),c&&t.focus()}let s=t.state,r=s.doc.child(this.blockIndex());this.turn.textContent=`${Lt(r).label} \u25BE`,this.bubbleTurn.textContent=this.turn.textContent;for(let c of this.dock.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(_n(s,c.dataset.cmd)));let l=!!this.menu&&[this.bubbleTurn,this.bubbleMore].includes(this.menu.anchor)||!s.selection.empty&&s.selection instanceof Rt&&t.hasFocus();if(this.bubble.hidden=!l,l)for(let c of this.bubble.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(_n(s,c.dataset.cmd)));if(this.grip.classList.toggle("is-on",s.selection instanceof F),this.inRoving(this.roving)||this.setRoving(this.dockControls()[0]),!this.menu&&e&&e.doc!==s.doc&&!this.remote&&t.hasFocus()&&s.selection.empty){let c=s.selection.$head;if(c.depth===1&&c.parent.isTextblock&&!c.parent.type.spec.code){let d=s.doc.textBetween(c.start(),c.pos),u=/(?:^|\s)\/([a-z]*)$/i.exec(d),a=u?c.start()+u.index+u[0].indexOf("/")+1:null;u&&this.slashKey(a)!==this.dismissedSlash&&this.openMenu("insert",this.plus,a,null,c.parent.attrs.id)}}this.slashQuery(),this.scheduleLayout()}destroy(){this.destroyed=!0,this.frame!==null&&this.win.cancelAnimationFrame(this.frame),this.frame=null,clearTimeout(this.movedTimer),this.drag.destroy(),this.shell.removeEventListener("mousemove",this.onMove),this.shell.removeEventListener("mouseleave",this.onLeave),this.shell.removeEventListener("keydown",this.onKey),this.win.removeEventListener("resize",this.onResize),this.win.removeEventListener("scroll",this.onResize,!0),this.win.visualViewport?.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("scroll",this.onResize),document.removeEventListener("mousedown",this.onDocDown,!0),document.removeEventListener("keydown",this.onSettingsKey,!0);for(let t of[this.dock,this.plus,this.grip,this.bubble,this.scrim,this.menuEl,this.settingsEl,this.probe])t?.remove()}};function al({onAiTool:n=null,mediaNote:t=null}={}){let e=null;return new Rn({key:ws,view(o){return e=new be(o,n,t),ye.set(o,e),e},filterTransaction(o){return e&&o.docChanged&&(e.remote=!!o.getMeta(Oe)),!0},props:{handleKeyDown(o,s){return e?s.key==="/"&&(s.metaKey||s.ctrlKey)&&!s.altKey&&!e.menu?(s.preventDefault(),e.openActions(),!0):e.key(s):!1},handleTextInput(o,s,r,i){if(i!=="/"||!e)return!1;let l=en(o,i);l&&(s=o.state.selection.from-1);let c=o.state.doc.resolve(s);if(c.depth!==1||!c.parent.isTextblock||c.parent.type.spec.code||c.parentOffset>0&&!/\s/.test(o.state.doc.textBetween(s-1,s,"",`
6
+ `)))return l;l||o.dispatch(o.state.tr.insertText("/",s,r).setMeta(Tt,Xt(o.state,s,r,"/")));let d=Math.min(o.state.doc.resolve(s).index(0),o.state.doc.childCount-1);return e.openMenu("insert",e.plus,s+1,null,o.state.doc.child(d).attrs.id),!0},handleDOMEvents:{keydown(o,s){return _t(s,o)},blur(o){return e&&!(e.menu&&[e.bubbleTurn,e.bubbleMore].includes(e.menu.anchor))&&(e.bubble.hidden=!0),!1}}}})}var{Plugin:Ts}=O,Me=new WeakMap,Es=n=>typeof n.text=="function"?n.text():new Promise((t,e)=>{let o=new FileReader;o.onload=()=>t(o.result),o.onerror=()=>e(o.error),o.readAsText(n)});function Ht(n,t){let e=n.dom.ownerDocument,o=n.dom.parentElement.querySelector(".blockeditor-csv-error");o||(o=e.createElement("div"),o.className="blockeditor-csv-error",o.setAttribute("role","alert"),n.dom.parentElement.append(o)),o.textContent=t}function Cs(n){let t=0,e=De(n,{maxBytes:ne,newId:()=>x(t++<n.header.length?"c":"r")});if(!Object.keys(e.cols).length)return null;if(!Object.keys(e.rows).length){let o=Object.fromEntries(Object.keys(e.cols).map(s=>[s,""]));e.rows[x("r")]={pos:v(),cells:o}}return{node:X(b,x(),{t:"table",pos:null,cols:e.cols,rows:e.rows}),truncated:e.truncated}}async function As({kept:n,total:t}){let e=`This file has ${t} rows. The first ${n} fit in a table.`,o=globalThis.clay?.confirm,s=globalThis.clay?.modal;o||(o=(await import("./c-47M4QHCK.js")).consent,s=(await import("./c-J2YYLEVM.js")).default);let r=o(e);s&&(s.yes=`Insert first ${n} rows and attach the file`);try{return await r,!0}catch{return!1}}var Os=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{e<0&&o.type===b.nodes.table&&o.attrs.id===t&&(e=r)}),e},vs=n=>{let t=!0;return n.descendants(e=>(e.isText&&(t=!1),t)),t};function $s(n,t,e,o){let s=n.state,r=Os(s.doc,e);if(r<0)return K(s,n.dispatch,t,null,o);let i=0;for(let u=0;u<r;u++)i+=s.doc.child(u).nodeSize;let l=s.doc.child(r);if(!vs(l)||o){let u=s.doc.maybeChild(r+1),a=l.attrs.parent??null,h=v(l.attrs.pos,u?.attrs.pos??null),p=t.type.create({...t.attrs,pos:h,parent:a},t.content),f=i+l.nodeSize,m=s.tr.insert(f,p);return o&&m.insert(f+p.nodeSize,o.type.create({...o.attrs,pos:v(h,u?.attrs.pos??null),parent:a},o.content)),m.setSelection(O.TextSelection.create(m.doc,f+3)),n.dispatch(S(m).scrollIntoView()),!0}let c=t.type.create({...t.attrs,id:l.attrs.id,pos:l.attrs.pos,parent:l.attrs.parent},t.content),d=s.tr.replaceWith(i,i+l.nodeSize,c);return d.setSelection(O.TextSelection.create(d.doc,i+3)),n.dispatch(S(d).scrollIntoView()),!0}async function xe(n,t,{upload:e,remove:o=null,table:s=null}={}){try{n.dom.parentElement.querySelector(".blockeditor-csv-error")?.remove();let r=gt(await Es(t)),i=Cs(r);if(!i)return Ht(n,"Couldn't read this CSV: no columns."),!1;let l=null;if(i.truncated){if(!await As(i.truncated))return!1;let u=await e?.(t),a=Ee(u?.uploads?.[0]?.url);if(!u?.ok||!a)return Ht(n,"Couldn't attach the original CSV."),!1;l=b.nodes.file.create({id:x(),src:a,name:t.name,size:t.size??null,mime:t.type||"text/csv"})}if(n.isDestroyed)return!1;if(s)return $s(n,i.node,s,l);let c=o?Yn(n.state):null;return o&&!c&&Ls(n,o.block),K(n.state,n.dispatch,i.node,c,l)}catch(r){return r instanceof $e?Ht(n,`Couldn't read this CSV: unclosed quote on line ${r.line}.`):Ht(n,"Couldn't read this CSV."),!1}}function $t(n,t=null,e=null){let o=Me.get(n);return o?(t&&Gn(n,t),o._remove=t?{...t,block:Is(n.state.doc,t.from)}:null,o._table=e,o.click(),!0):!1}var Is=(n,t)=>n.child(n.resolve(Math.max(0,Math.min(t,n.content.size))).index(0)).attrs.id;function Ls(n,t){let e=n.state,o=null;return e.doc.forEach((s,r)=>{o===null&&s.attrs.id===t&&(o=r)}),o===null?!1:(n.dispatch(e.tr.setSelection(O.TextSelection.near(e.doc.resolve(o)))),!0)}var Jn=n=>[...n].filter(t=>/\.csv$/i.test(t.name||"")||/^(text\/csv|application\/csv)$/i.test(t.type||""));function xl({upload:n}){return new Ts({view(t){let e=t.dom.ownerDocument.createElement("input");return e.type="file",e.accept=".csv,text/csv",e.hidden=!0,e.className="blockeditor-csv-input",t.dom.parentElement.append(e),Me.set(t,e),e.addEventListener("change",()=>{let o=e.files?.[0];o&&xe(t,o,{upload:n,remove:e._remove,table:e._table}),e._remove=null,e._table=null,e.value=""}),{destroy(){Me.delete(t),e.remove()}}},props:{handlePaste(t,e){let o=Jn(e.clipboardData?.files||[]);return o.length?(e.preventDefault(),xe(t,o[0],{upload:n}),!0):!1},handleDrop(t,e,o,s){let r=Jn(e.dataTransfer?.files||[]);if(s||!r.length)return!1;e.preventDefault();let i=t.posAtCoords({left:e.clientX,top:e.clientY});return i&&t.dispatch(t.state.tr.setSelection(O.TextSelection.near(t.state.doc.resolve(i.pos)))),xe(t,r[0],{upload:n}),!0}}})}export{qs as a,er as b,on as c,Ps as d,Rs as e,xl as f,yn as g,pi as h,Ot as i,_t as j,Hi as k,zi as l,Fi as m,Er as n,Cr as o,rr as p,ir as q,lr as r,cr as s,ie as t,il as u,Gn as v,Yn as w,ll as x,cl as y,al as z,te as A,Co as B,Kr as C,Vr as D,jr as E,qr as F,Wr as G,Ao as H,Oo as I,Ur as J,Gr as K,Yr as L,Jr as M,Xr as N,Qr as O,Zr as P,ti as Q,ei as R,ni as S,oi as T};