@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.
- package/dist/all.js +1 -1
- package/dist/clay-dom.js +1 -1
- package/dist/clay-events.js +1 -1
- package/dist/clay-internals.js +1 -1
- package/dist/clay-options.js +1 -1
- package/dist/clay-router.js +1 -1
- package/dist/clay-ui.js +1 -1
- package/dist/clay-utils.js +1 -1
- package/dist/clay.js +1 -1
- package/dist/clay.standalone.js +5570 -4173
- package/dist/m/attrs/{save-freeze-MH3AOD56.js → save-freeze-PUYX32AK.js} +1 -1
- package/dist/m/{c-BOMQIQ3V.js → c-2EFMJYGJ.js} +1 -1
- package/dist/m/c-2EPHRF47.js +1 -0
- package/dist/m/{c-JD2VFAYG.js → c-2SUFMUZX.js} +2 -2
- package/dist/m/{c-CITLTVQ4.js → c-2TJCFPX4.js} +1 -1
- package/dist/m/c-33SS5A4Y.js +1 -0
- package/dist/m/{c-V2FPBRO6.js → c-34J5HC7N.js} +1 -1
- package/dist/m/c-3F3AADKG.js +1 -0
- package/dist/m/{c-TCFVG3I4.js → c-3S3647J6.js} +1 -1
- package/dist/m/{c-GY4BREDT.js → c-3S5TNRZA.js} +1 -1
- package/dist/m/{c-GDNZEOOZ.js → c-3WX5FABT.js} +1 -1
- package/dist/m/{c-AI3H6ETU.js → c-3XGLJAS7.js} +2 -2
- package/dist/m/c-42WBOKFM.js +1 -0
- package/dist/m/c-47M4QHCK.js +1 -0
- package/dist/m/{c-UOUUI265.js → c-4M2T676V.js} +1 -1
- package/dist/m/{c-GEAG5XAK.js → c-4TP3UXBT.js} +1 -1
- package/dist/m/{c-IESDKFO6.js → c-5ELELG2F.js} +1 -1
- package/dist/m/{c-X3V4RWMA.js → c-5ZYLTN3Q.js} +1 -1
- package/dist/m/{c-5PZYDWTW.js → c-67TBU56I.js} +1 -1
- package/dist/m/{c-WNOLMHI2.js → c-6BGJAJ67.js} +1 -1
- package/dist/m/{c-4Q6QIODW.js → c-755ZOHOM.js} +1 -1
- package/dist/m/c-7Q4XYDF4.js +1 -0
- package/dist/m/c-7RHOMAMR.js +1 -0
- package/dist/m/c-A5LASUEZ.js +1 -0
- package/dist/m/{c-IL5IVTOG.js → c-ABOBD7F3.js} +1 -1
- package/dist/m/c-AQVQKFKB.js +1 -0
- package/dist/m/{c-QDVG4NAZ.js → c-ARO6CPMA.js} +1 -1
- package/dist/m/{c-ORLPQFNU.js → c-AZM34SPO.js} +1 -1
- package/dist/m/{c-XUZMRQ7O.js → c-BCS3AZQZ.js} +1 -1
- package/dist/m/c-BOS7GONO.js +1 -0
- package/dist/m/{c-SUAC5RSG.js → c-C5UGNOC2.js} +1 -1
- package/dist/m/c-C6DXZIXD.js +1 -0
- package/dist/m/{c-WSTUCBHV.js → c-CPRGR2II.js} +1 -1
- package/dist/m/{c-NICICT4P.js → c-DEYHCYJB.js} +1 -1
- package/dist/m/{c-WGQVSKKC.js → c-DYTBSJBI.js} +1 -1
- package/dist/m/{c-DT7E76Z2.js → c-DZT6W2NG.js} +1 -1
- package/dist/m/{c-O2QZDVZ2.js → c-EEWPNUM2.js} +1 -1
- package/dist/m/{c-MFB74XVN.js → c-EHAR4RJJ.js} +2 -2
- package/dist/m/c-EHJWIGWN.js +1 -0
- package/dist/m/c-EIDZHQHZ.js +1 -0
- package/dist/m/{c-V2V5FKXX.js → c-EIUKME3W.js} +1 -1
- package/dist/m/c-ELXMSEN5.js +1 -0
- package/dist/m/c-EXZOA6XY.js +7 -0
- package/dist/m/{c-FKTALXNV.js → c-EYFMAR3M.js} +1 -1
- package/dist/m/c-FC5RUFPR.js +1 -0
- package/dist/m/{c-FBOO2UY3.js → c-FUN6AKFE.js} +1 -1
- package/dist/m/{c-V4B3RUWB.js → c-GFASNR55.js} +1 -1
- package/dist/m/{c-XMIDHEKF.js → c-GY36NO7C.js} +1 -1
- package/dist/m/{c-UD4VDBGJ.js → c-H3M6UDNV.js} +1 -1
- package/dist/m/{c-SFZRY6RT.js → c-H47C6PJZ.js} +1 -1
- package/dist/m/{c-MUM53J5J.js → c-H4M2T4A6.js} +1 -1
- package/dist/m/{c-U7F66I64.js → c-HYNM5U6B.js} +1 -1
- package/dist/m/c-J2YYLEVM.js +1 -0
- package/dist/m/c-J2ZW4HMR.js +1 -0
- package/dist/m/{c-WCG6AKA7.js → c-JC4RZW4E.js} +1 -1
- package/dist/m/c-K2ZHQMPF.js +1 -0
- package/dist/m/c-KD2ME5UN.js +2 -0
- package/dist/m/{c-Z2OZFX3N.js → c-L6KVXPBO.js} +1 -1
- package/dist/m/{c-GO635CRU.js → c-LAKBBJOU.js} +2 -2
- package/dist/m/{c-4AE2A2LK.js → c-LETPPG2F.js} +1 -1
- package/dist/m/{c-SFYTKRU7.js → c-MKAUC6DB.js} +1 -1
- package/dist/m/{c-WDFQ7PBU.js → c-MMEVDN6D.js} +1 -1
- package/dist/m/{c-LS7IVQVW.js → c-MMV5JULA.js} +1 -1
- package/dist/m/{c-NEQRFC4O.js → c-MVVEIJUU.js} +1 -1
- package/dist/m/{c-SXZYVXD6.js → c-N362HNGO.js} +1 -1
- package/dist/m/{c-7K4SCQB7.js → c-ND3W7D5U.js} +1 -1
- package/dist/m/{c-3E2IK5HU.js → c-NNHNXD6M.js} +1 -1
- package/dist/m/{c-D62HRSZK.js → c-NYJ577NL.js} +1 -1
- package/dist/m/{c-YFO6ZJLQ.js → c-O3DPFZCE.js} +1 -1
- package/dist/m/c-OZOACVUD.js +1 -0
- package/dist/m/{c-MV7TEUTD.js → c-OZVK3TFI.js} +1 -1
- package/dist/m/{c-ZEA3DCG3.js → c-PWILUN4T.js} +1 -1
- package/dist/m/{c-BCWYEG6P.js → c-QA3Q3MDI.js} +1 -1
- package/dist/m/{c-XHZIKRCV.js → c-QKOKMQXA.js} +1 -1
- package/dist/m/{c-TGIMBAWE.js → c-RBWVF4N5.js} +1 -1
- package/dist/m/c-RES2S5Q3.js +1 -0
- package/dist/m/c-RFGELYEU.js +2 -0
- package/dist/m/c-RGFPLQGV.js +1 -0
- package/dist/m/{c-RGAALCDU.js → c-SPOEDIMP.js} +1 -1
- package/dist/m/{c-YX2MC7YL.js → c-SRW5OBCF.js} +1 -1
- package/dist/m/{c-C6YZNU6E.js → c-SYOA4T7V.js} +1 -1
- package/dist/m/c-SYVF6ZMF.js +1 -0
- package/dist/m/{c-NADLYVAH.js → c-TJ5PFOJ2.js} +1 -1
- package/dist/m/{c-KYTVZT4D.js → c-TKV273YU.js} +1 -1
- package/dist/m/c-U35T5NAY.js +1 -0
- package/dist/m/{c-PRZNJUYZ.js → c-UEKJWXCB.js} +2 -2
- package/dist/m/c-UW6MMZ4V.js +1 -0
- package/dist/m/{c-XQTERKQA.js → c-V4DBV5ZV.js} +1 -1
- package/dist/m/c-VGG3UR7I.js +1 -0
- package/dist/m/c-VU4WEWPH.js +4 -0
- package/dist/m/{c-5Q5XBN56.js → c-W7LWCJHD.js} +1 -1
- package/dist/m/c-WHMZCRQD.js +6 -0
- package/dist/m/{c-WMRJKQ2V.js → c-WHQUZM2V.js} +1 -1
- package/dist/m/c-WOJ2RTV4.js +1 -0
- package/dist/m/{c-ZJG6C2WL.js → c-WOWGGNCJ.js} +1 -1
- package/dist/m/{c-ZORVIXUR.js → c-XHD7XJTE.js} +1 -1
- package/dist/m/c-XONFK3WC.js +1 -0
- package/dist/m/{c-HGG7M2S3.js → c-Y3J5LDKB.js} +1 -1
- package/dist/m/{c-JB5YU57S.js → c-Y3MPVURA.js} +1 -1
- package/dist/m/c-Y6HH7LTM.js +1 -0
- package/dist/m/{c-52OC3OH3.js → c-YRDKVEGR.js} +1 -1
- package/dist/m/c-YYIN4NAF.js +30 -0
- package/dist/m/{c-WVCT3ITX.js → c-YZGWSCMT.js} +1 -1
- package/dist/m/c-ZFAPQQIB.js +1 -0
- package/dist/m/core/{admin-attrs-ZI6K6UGM.js → admin-attrs-43JBA6JB.js} +1 -1
- package/dist/m/core/{autosave-BSM2ABJL.js → autosave-HD7Y7UNV.js} +1 -1
- package/dist/m/core/{conflict-notice-7EQLDYPA.js → conflict-notice-UNDOD4BL.js} +1 -1
- package/dist/m/core/{persist-2SZO3PCE.js → persist-MX3VYVBN.js} +1 -1
- package/dist/m/core/{save-K6Q47J2X.js → save-JZ7R4ET2.js} +1 -1
- package/dist/m/core/{save-core-U3Z44XBO.js → save-core-I4N6S4ED.js} +1 -1
- package/dist/m/core/site-edits-C22O53GS.js +1 -0
- package/dist/m/core/{snapshot-PWCHYFL6.js → snapshot-N5MKDGNI.js} +1 -1
- package/dist/m/core/{unsaved-warning-2WRZLJH5.js → unsaved-warning-BP6ZY3PG.js} +1 -1
- package/dist/m/internals/{index-FSLC4M7J.js → index-3LAVREAU.js} +1 -1
- package/dist/m/loader-DCKCZKY6.js +1 -0
- package/dist/m/manifest-7954CBE3.js +1 -0
- package/dist/m/manifest-edit-93AA79D7.js +1 -0
- package/dist/m/manifest.json +1240 -1179
- package/dist/m/page/{editor-PKSPJ2XJ.js → editor-UF3CIA6V.js} +5 -5
- package/dist/m/plugins/{ai-edit-3LG6MGS3.js → ai-edit-WDV2GLDU.js} +2 -2
- package/dist/m/plugins/{cms-T2HLI7JG.js → cms-KG6TCTR3.js} +9 -9
- package/dist/m/plugins/{derive-7DR5TUDH.js → derive-R4USHZ7P.js} +1 -1
- package/dist/m/plugins/{indicator-CTKX4EY7.js → indicator-OLPZ4WFI.js} +1 -1
- package/dist/m/plugins/{live-IFLL6YN5.js → live-DF5YS5AH.js} +1 -1
- package/dist/m/plugins/{menu-YJZ3JWBC.js → menu-ESEFQARM.js} +1 -1
- package/dist/m/plugins/page-GZSU77JS.js +2 -0
- package/dist/m/plugins/{page-view-NMCCU6MF.js → page-view-7MM3FEAR.js} +1 -1
- package/dist/m/plugins/{people-6WIWCZEG.js → people-EBWE337I.js} +1 -1
- package/dist/m/plugins/quickcrop-UHURKA2F.js +26 -0
- package/dist/m/plugins/richclay-MXH2GFAZ.js +549 -0
- package/dist/m/plugins/sortable-BAG3MSWS.js +1 -0
- package/dist/m/plugins/{source-7LSGOV46.js → source-OYHDXKTB.js} +1 -1
- package/dist/m/plugins/undo-KLHAGV75.js +1 -0
- package/dist/m/plugins/{upgrade-MMPZUCDM.js → upgrade-SZQJYEQQ.js} +1 -1
- package/dist/m/plugins/{visitor-drafts-V5YB7XDH.js → visitor-drafts-ZE6PCAFP.js} +2 -2
- package/dist/m/plugins/{visitor-menu-QDV2MYJN.js → visitor-menu-5XY57JQA.js} +1 -1
- package/dist/m/plugins/{wire-3YGUO3GE.js → wire-S5ATC4QI.js} +1 -1
- package/dist/m/reader-core-AHOAP5DH.js +77 -0
- package/dist/m/sync/{live-sync-XMXXZS3G.js → live-sync-RZQSDMZW.js} +1 -1
- package/dist/m/ui/index-G7ZJXNMG.js +1 -0
- package/dist/m/vendor/{sap-core.vendor-JANUQULT.js → sap-core.vendor-5TWOJYVM.js} +4 -4
- package/dist/offline-manifest.json +780 -750
- package/dist/server/core.cjs +4245 -2614
- package/dist/server/markdown.cjs +1 -0
- package/dist/server/markdown.mjs +7 -0
- package/docs/guide.md +26 -37
- package/entries/clay-data.js +1 -1
- package/entries/sap.js +5 -5
- package/package.json +6 -2
- package/packed-contract.json +3 -0
- package/src/attrs/save-freeze.js +1 -1
- package/src/core/admin-contenteditable.js +1 -1
- package/src/core/admin-inputs.js +1 -1
- package/src/core/admin-onclick.js +1 -1
- package/src/core/admin-resources.js +5 -2
- package/src/core/conflict-notice-ui.js +59 -34
- package/src/core/save.js +9 -9
- package/src/core/site-edits.js +1 -1
- package/src/core/snapshot.js +56 -43
- package/src/core/stale-host-notice.js +20 -7
- package/src/loader-logic.js +0 -13
- package/src/page/boot-pack.js +1 -0
- package/src/page/editor.js +10 -4
- package/src/page/history-intent.js +111 -4
- package/src/page/import-markdown.js +22 -8
- package/src/page/save-projection.js +1 -1
- package/src/page/ybind/bridge.js +14 -7
- package/src/page/ybind/moves.js +437 -3
- package/src/page/ybind/origins.js +1 -1
- package/src/page/ybind/recovery.js +1 -1
- package/src/plugins/page.js +48 -4
- package/src/plugins/quickcrop.js +128 -69
- package/src/plugins/richclay.js +136 -0
- package/src/plugins/sortable.js +25 -9
- package/src/plugins/undo.js +169 -7
- package/src/recovery/undo.js +14 -7
- package/src/server/markdown/index.js +23 -0
- package/src/sync/conflicts.js +3 -1
- package/src/sync/data-guard-notice.js +137 -18
- package/src/sync/live-sync.js +24 -0
- package/src/ui/bevel-controls.js +4 -1
- package/src/ui/dialogs.js +11 -7
- package/src/ui/modal.js +9 -7
- package/src/ui/toast.js +67 -32
- package/src/ui/vendor-skin.js +9 -4
- package/src/vendor/hyper-html-api-data.vendor.js +1 -1
- package/src/vendor/hyper-html-api-upgrade.vendor.js +2 -2
- package/src/vendor/hyper-undo.vendor.js +1 -1
- package/src/vendor/hypercms.vendor.js +7 -7
- package/src/vendor/richclay.vendor.js +16 -16
- package/src/vendor/sap-core.vendor.js +4 -4
- package/tool-generation/context.md +69 -0
- package/tool-generation/system.md +1 -1
- package/dist/m/c-277QP5ET.js +0 -1
- package/dist/m/c-5SZ6KFR5.js +0 -1
- package/dist/m/c-CU33V6RW.js +0 -4
- package/dist/m/c-CVSWLX3X.js +0 -1
- package/dist/m/c-DXPOFLEJ.js +0 -1
- package/dist/m/c-EODTTNVA.js +0 -1
- package/dist/m/c-ESK4S67I.js +0 -1
- package/dist/m/c-FDWR3FL7.js +0 -1
- package/dist/m/c-FJDTDGDA.js +0 -1
- package/dist/m/c-FYDKYW6E.js +0 -1
- package/dist/m/c-HKSLOVU4.js +0 -1
- package/dist/m/c-IJHF4IO6.js +0 -1
- package/dist/m/c-IUL7PU4P.js +0 -1
- package/dist/m/c-JWW6BHWD.js +0 -6
- package/dist/m/c-K4M76VPM.js +0 -7
- package/dist/m/c-M7ITYKMF.js +0 -1
- package/dist/m/c-MR75YPRT.js +0 -1
- package/dist/m/c-NFQFV7OP.js +0 -2
- package/dist/m/c-NHXOBD6A.js +0 -1
- package/dist/m/c-NVU3DORS.js +0 -1
- package/dist/m/c-PNZIJFG7.js +0 -1
- package/dist/m/c-QWB53KRW.js +0 -1
- package/dist/m/c-RHPHMTF2.js +0 -2
- package/dist/m/c-RWJ3OSCP.js +0 -1
- package/dist/m/c-SEVOS4UE.js +0 -1
- package/dist/m/c-SGG6MUXW.js +0 -1
- package/dist/m/c-SXNSSHPP.js +0 -1
- package/dist/m/c-TFLRT5JX.js +0 -1
- package/dist/m/c-TLQINES7.js +0 -30
- package/dist/m/c-U65PREMC.js +0 -1
- package/dist/m/c-V5L6HWVL.js +0 -1
- package/dist/m/c-VMXCX52Q.js +0 -1
- package/dist/m/c-YYGUHSZR.js +0 -1
- package/dist/m/core/site-edits-CFMF6GHD.js +0 -1
- package/dist/m/loader-RC54UV7H.js +0 -1
- package/dist/m/manifest-3B84C829.js +0 -1
- package/dist/m/manifest-edit-1CB79AD4.js +0 -1
- package/dist/m/plugins/page-GTDPYGE4.js +0 -2
- package/dist/m/plugins/quickcrop-X5MRIBAP.js +0 -26
- package/dist/m/plugins/richclay-L3BZMX4I.js +0 -549
- package/dist/m/plugins/sortable-365SRRL3.js +0 -1
- package/dist/m/plugins/undo-UES4KS7B.js +0 -1
- package/dist/m/reader-core-VR7EL4WV.js +0 -77
- package/dist/m/ui/index-MGTWOW2C.js +0 -1
- /package/dist/m/{c-QTTJYJMA.js → c-FILLTJA7.js} +0 -0
- /package/dist/m/plugins/{quickcrop-X5MRIBAP.js.LEGAL.txt → quickcrop-UHURKA2F.js.LEGAL.txt} +0 -0
- /package/dist/m/plugins/{richclay-L3BZMX4I.js.LEGAL.txt → richclay-MXH2GFAZ.js.LEGAL.txt} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as J}from"./c-AI3H6ETU.js";import{d as F}from"./c-OH2FPYSY.js";import{c as z}from"./c-FSQXFG5T.js";import{d as _}from"./c-RETTCOWO.js";import"./c-VHNSBD2M.js";var{Decoration:tt,DecorationSet:et}=_,a=(e,o,n,t={},r=null)=>{let l=e.createElement(o);n&&(l.className=n);for(let[s,i]of Object.entries(t))i!=null&&i!==!1&&l.setAttribute(s,i===!0?"":String(i));return r!==null&&(l.textContent=r),l},ot=(e,o)=>a(e,"span","blockeditor-board-face",{"aria-hidden":"true"},([...String(o).trim()][0]??"?").toUpperCase());function I(e,o){let n=null;return e.state.doc.forEach((t,r)=>{t.attrs.id===o&&t.type===F.nodes.list_item&&t.attrs.kind==="check"&&(n={node:t,pos:r})}),n}function X(e,o,n,t){let r=I(e,o);r&&e.dispatch(J(e.state.tr.setNodeMarkup(r.pos,null,{...r.node.attrs,[n]:t||null})))}var L={person:'<circle cx="8" cy="5.4" r="2.3"/><path d="M3.6 13.2c.6-2.1 2.2-3.3 4.4-3.3s3.8 1.2 4.4 3.3"/>',calendar:'<rect x="2.5" y="3.5" width="11" height="10"/><path d="M2.5 6.8h11M5.5 2v2.4M10.5 2v2.4"/>',clock:'<circle cx="8" cy="8" r="5.5"/><path d="M8 4.8v3.4l2.3 1.4"/>',tick:'<path d="M3.5 8.3l3 3 6-6.2"/>',plus:'<path d="M8 3.5v9M3.5 8h9"/>',clear:'<path d="M4.8 4.8l6.4 6.4M11.2 4.8l-6.4 6.4"/>',"chevron-left":'<path d="M9.8 3.6L5.4 8l4.4 4.4"/>',"chevron-right":'<path d="M6.2 3.6L10.6 8l-4.4 4.4"/>'};function q(e,o){let n=e.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("viewBox","0 0 16 16"),n.setAttribute("width","14"),n.setAttribute("height","14"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","1.5"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),n.setAttribute("aria-hidden","true"),n.innerHTML=o,n}var Z=e=>String(e).padStart(2,"0"),B=/^\d{4}-\d{2}-\d{2}$/,S=(e=new Date)=>`${e.getFullYear()}-${Z(e.getMonth()+1)}-${Z(e.getDate())}`,nt=e=>{let o=new Date(`${e}T00:00:00Z`);return o.setUTCDate(o.getUTCDate()+1),o.toISOString().slice(0,10)};function rt(e,o){if(!e)return"No date";if(!B.test(e))return e;if(e===o)return"Today";if(e===nt(o))return"Tomorrow";let n=e.slice(0,4)===o.slice(0,4);return new Date(`${e}T00:00:00Z`).toLocaleDateString("en-US",{month:"short",day:"numeric",...n?{}:{year:"numeric"},timeZone:"UTC"})}function j(e,{name:o,paths:n,label:t,aria:r,filled:l,overdue:s=!1}){let i=a(e,"button","blockeditor-check-chip",{type:"button","data-check":o,"data-filled":String(l),"data-overdue":s?"true":null,"aria-expanded":"false","aria-label":r});return i.append(q(e,n),a(e,"span","blockeditor-check-chip-label",{},t)),i}var N=null;function G(e,o,{className:n,label:t,check:r,onKey:l=null}){let s=o.ownerDocument,i=s.defaultView;N&&N.close();for(let d of s.querySelectorAll(".blockeditor-check-popup"))d.remove();let y=e.dom.parentNode,h=["relative","absolute","fixed","sticky"].includes(i?.getComputedStyle?.(y)?.position??""),k=y&&h?y:s.body,f=a(s,"div",`blockeditor-check-popup ${n}`,{role:"dialog","aria-label":t,"data-check":r}),A=!1,E=()=>{let d=o.getBoundingClientRect(),c=k===s.body?{top:-(i?.scrollY??0),left:-(i?.scrollX??0)}:k.getBoundingClientRect(),p=f.getBoundingClientRect(),u=p.width||Math.min(264,(i?.innerWidth||292)-28),b=(i?.innerHeight??0)-d.bottom-2,g=p.height>0&&b<p.height;f.style.left=`${Math.round(d.right-u-c.left)}px`,f.style.top=`${Math.round((g?d.top-p.height-2:d.bottom+2)-c.top)}px`},C=d=>{if(!f.isConnected)return w();f.contains(d.target)||o.contains(d.target)||w()},w=({focusAnchor:d=!1}={})=>{if(A)return;A=!0,s.removeEventListener("mousedown",C,!0),i?.removeEventListener("resize",E),i?.removeEventListener("scroll",E,!0),N?.panel===f&&(N=null),f.remove(),o.setAttribute("aria-expanded","false");let c=o.dataset.fromKeys==="true";delete o.dataset.fromKeys,d&&c?e.focus():d&&o.focus()};return f.addEventListener("keydown",d=>{if(d.stopPropagation(),d.key==="Escape"){d.preventDefault(),w({focusAnchor:!0});return}l?.(d,f)}),k.append(f),o.setAttribute("aria-expanded","true"),N={panel:f,close:()=>w()},s.addEventListener("mousedown",C,!0),i?.addEventListener("resize",E),i?.addEventListener("scroll",E,!0),{panel:f,close:w,place:E}}function ct(e,o){let n=new Map;e.state.doc.forEach(t=>{if(t.type!==F.nodes.list_item||t.attrs.kind!=="check")return;let r=String(t.attrs.owner??"").trim();if(!r)return;let l=r.toLowerCase(),s=n.get(l)??{name:r,count:0};s.count+=1,n.set(l,s)});for(let t of o??[]){let r=String((typeof t=="string"?t:t?.name)??"").trim();r&&!n.has(r.toLowerCase())&&n.set(r.toLowerCase(),{name:r,count:0})}return[...n.values()].sort((t,r)=>t.name.localeCompare(r.name))}function at(e,o,n){let t=n.ownerDocument,r=I(e,o)?.node.attrs.owner||"",{panel:l,close:s,place:i}=G(e,n,{className:"blockeditor-check-owner",label:"Assignee",check:"owner-panel",onKey:(c,p)=>{if(c.key!=="ArrowDown"&&c.key!=="ArrowUp")return;c.preventDefault();let u=[...p.querySelectorAll("input, button:not([disabled])")],b=u.indexOf(t.activeElement),g=c.key==="ArrowDown"?1:-1;(b<0?g>0?u[0]:u[u.length-1]:u[(b+g+u.length)%u.length])?.focus()}}),y=a(t,"input","blockeditor-check-search",{type:"text",placeholder:"Find or type a name","aria-label":"Find or type a name"}),h=a(t,"div","blockeditor-check-people"),k=a(t,"button","blockeditor-check-person blockeditor-check-danger",{type:"button","data-check":"clear-owner"});k.append(q(t,L.clear),a(t,"span","blockeditor-check-person-name",{},"Remove assignee")),k.disabled=!r,k.addEventListener("click",()=>A(null)),l.append(y,a(t,"div","blockeditor-check-subhead",{},"People in this document"),h,a(t,"div","blockeditor-check-divider"),k);let f=[],A=c=>{s(),X(e,o,"owner",c)},E=(c,p)=>{let u=c.toLowerCase()===String(r).toLowerCase(),b=a(t,"button","blockeditor-check-person",{type:"button","data-check":"owner-option","data-name":c,"aria-pressed":String(u)});return b.append(ot(t,c),a(t,"span","blockeditor-check-person-name",{},c),a(t,"span","blockeditor-check-person-meta",{},`${p} ${p===1?"item":"items"}`)),u&&b.append(q(t,L.tick)),b.addEventListener("click",()=>A(c)),b},C=c=>{let p=a(t,"button","blockeditor-check-person",{type:"button","data-check":"owner-new","data-name":c}),u=a(t,"span","blockeditor-check-person-name",{},"Assign to ");return u.append(a(t,"strong",null,{},c)),p.append(q(t,L.plus),u,a(t,"span","blockeditor-check-person-meta",{},"New")),p.addEventListener("click",()=>A(c)),p},w=()=>{let c=y.value.trim(),p=c.toLowerCase(),u=ct(e,f),b=[];c&&!u.some(g=>g.name.toLowerCase()===p)&&b.push(C(c));for(let g of u)p&&!g.name.toLowerCase().includes(p)||b.push(E(g.name,g.count));h.replaceChildren(...b)};y.addEventListener("keydown",c=>{if(c.stopPropagation(),c.key==="Escape"){c.preventDefault(),s({focusAnchor:!0});return}c.key==="Enter"&&(c.preventDefault(),h.querySelector("button[data-check]")?.click())}),y.addEventListener("input",w),w(),i(),y.focus();let d=globalThis.clay?.people?.available;d&&Promise.resolve().then(()=>d()).then(c=>{!N||N.panel!==l||(f=Array.isArray(c)?c:[],w())}).catch(()=>{})}var st=["January","February","March","April","May","June","July","August","September","October","November","December"],$=(e,o,n)=>new Date(e,o,n),it=e=>e.toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"}),lt=e=>e.toLocaleDateString("en-US",{weekday:"long",month:"long",day:"numeric",year:"numeric"}),W=e=>{if(!e||!B.test(e))return null;let[o,n,t]=e.split("-").map(Number);return $(o,n-1,t)};function dt(e,o,n){let t=n.ownerDocument,r=I(e,o)?.node.attrs.due||null,l=S(),s=new Date,i=$(s.getFullYear(),s.getMonth(),s.getDate()),y=W(r)??i,h=y.getFullYear(),k=y.getMonth(),{panel:f,close:A,place:E}=G(e,n,{className:"blockeditor-check-date",label:"Due date",check:"date-panel",onKey:(m,D)=>Q(m,D)}),C=m=>{A(),X(e,o,"due",m)},w=a(t,"div","blockeditor-check-quick"),d=(m,D)=>{let M=$(i.getFullYear(),i.getMonth(),i.getDate()+D),x=a(t,"button","blockeditor-check-quick-row",{type:"button","data-check":"date-quick","data-date":S(M)});return x.append(q(t,L.calendar),a(t,"span","blockeditor-check-quick-label",{},m),a(t,"span","blockeditor-check-quick-meta",{},it(M))),x.addEventListener("click",()=>C(S(M))),x};w.append(d("Today",0),d("Tomorrow",1),d("Next week",7));let c=a(t,"div","blockeditor-check-cal"),p=a(t,"div","blockeditor-check-cal-head"),u=a(t,"span","blockeditor-check-cal-month"),b=a(t,"span","blockeditor-check-cal-nav"),g=m=>{let D=$(h,k+m,1);h=D.getFullYear(),k=D.getMonth(),H()},U=a(t,"button","blockeditor-check-cal-btn",{type:"button","aria-label":"Previous month"}),O=a(t,"button","blockeditor-check-cal-btn",{type:"button","aria-label":"Next month"});U.append(q(t,L["chevron-left"])),O.append(q(t,L["chevron-right"])),U.addEventListener("click",()=>g(-1)),O.addEventListener("click",()=>g(1)),b.append(U,O),p.append(u,b);let Y=a(t,"div","blockeditor-check-cal-grid");c.append(p,Y);let H=()=>{u.replaceChildren(a(t,"span",null,{},`${st[k]} `),a(t,"span","blockeditor-check-cal-year",{},String(h)));let m=$(h,k,1),D=$(h,k+1,0).getDate(),M=Math.ceil((m.getDay()+D)/7)*7,x=["S","M","T","W","T","F","S"].map(v=>a(t,"span","blockeditor-check-cal-dow",{},v)),T=[];for(let v=0;v<M;v+=1){let P=$(h,k,1-m.getDay()+v),R=S(P),V=a(t,"button","blockeditor-check-cal-day",{type:"button","data-check":"date-day","data-date":R,"data-outside":String(P.getMonth()!==k),"data-today":String(R===l),"aria-pressed":String(R===r),"aria-label":lt(P)},String(P.getDate()));V.addEventListener("click",()=>C(R)),T.push(V)}Y.replaceChildren(...x,...T)},Q=(m,D)=>{let M=t.activeElement?.closest?.('[data-check="date-day"]');if(!M)return;if(m.key==="Enter"||m.key===" "){m.preventDefault(),M.click();return}let x={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[m.key];if(!x)return;m.preventDefault();let T=W(M.dataset.date),v=$(T.getFullYear(),T.getMonth(),T.getDate()+x);(v.getMonth()!==k||v.getFullYear()!==h)&&(h=v.getFullYear(),k=v.getMonth(),H()),D.querySelector(`[data-check="date-day"][data-date="${S(v)}"]`)?.focus()},K=a(t,"button","blockeditor-check-quick-row blockeditor-check-danger",{type:"button","data-check":"clear-date"});K.append(q(t,L.clear),a(t,"span","blockeditor-check-quick-label",{},"Clear date")),K.disabled=!r,K.addEventListener("click",()=>C(null)),f.append(w,c,a(t,"div","blockeditor-check-divider"),K),H(),E(),(Y.querySelector('[data-check="date-day"][aria-pressed="true"]')??Y.querySelector('[data-check="date-day"][data-today="true"]'))?.focus()}function ut(e,o){let n=e.dom.ownerDocument,t=n.createElement("span");t.className="blockeditor-check-controls",t.contentEditable="false",t.dataset.empty=String(!o.attrs.owner&&!o.attrs.due);let r=S(),l=o.attrs.owner||"Unassigned",s=j(n,{name:"owner",paths:L.person,label:l,aria:`Assignee: ${l}`,filled:!!o.attrs.owner}),i=rt(o.attrs.due,r),y=!!o.attrs.due&&!o.attrs.checked&&B.test(o.attrs.due)&&o.attrs.due<r,h=j(n,{name:"date",paths:y?L.clock:L.calendar,label:i,aria:`Due date: ${i}`,filled:!!o.attrs.due,overdue:y});return s.addEventListener("click",()=>at(e,o.attrs.id,s)),h.addEventListener("click",()=>dt(e,o.attrs.id,h)),t.append(s,h),t}function pt(e,o){let n=e.state.selection.$head;if(n.depth!==1||n.parent.type!==F.nodes.list_item||n.parent.attrs.kind!=="check")return!1;let t=n.parent.attrs.id,l=[...e.dom.querySelectorAll(".blockeditor-check-controls")].find(s=>s.dataset.item===t)?.querySelector(`[data-check="${o}"]`);return l?(l.dataset.fromKeys="true",l.click(),!0):!1}function ht(e){let o=[],n=S();return e.doc.forEach((t,r)=>{t.type!==F.nodes.list_item||t.attrs.kind!=="check"||o.push(tt.widget(r+t.nodeSize-1,l=>{let s=ut(l,t);return s.dataset.item=t.attrs.id,s},{key:`${t.attrs.id}:${t.attrs.owner}:${t.attrs.due}:${t.attrs.checked}:${n}`,side:-1,stopEvent:l=>!!l.target.closest?.(".blockeditor-check-chip, .blockeditor-check-popup"),ignoreSelection:!0}))}),et.create(e.doc,o)}function kt(e){let o=S(),n=()=>{e.isDestroyed||S()===o||(o=S(),e.dispatch(e.state.tr.setMeta("addToHistory",!1)))},t=e.dom.ownerDocument.defaultView,r=t.setInterval(n,6e4);return t.document.addEventListener("visibilitychange",n),()=>{t.clearInterval(r),t.document.removeEventListener("visibilitychange",n)}}function gt({view:e=null}={}){let o=e?z(e,{decorations:ht,focusControl:pt}):()=>{},n=e?kt(e):()=>{};return e&&!e.isDestroyed&&e.dispatch(e.state.tr.setMeta("addToHistory",!1)),{id:"checklist",dispose(){o(),n()}}}export{gt as createFeature,ht as decorations,pt as focusControl};
|
|
1
|
+
import{C as J}from"./c-3XGLJAS7.js";import{d as F}from"./c-OH2FPYSY.js";import{c as z}from"./c-FSQXFG5T.js";import{d as _}from"./c-RETTCOWO.js";import"./c-VHNSBD2M.js";var{Decoration:tt,DecorationSet:et}=_,a=(e,o,n,t={},r=null)=>{let l=e.createElement(o);n&&(l.className=n);for(let[s,i]of Object.entries(t))i!=null&&i!==!1&&l.setAttribute(s,i===!0?"":String(i));return r!==null&&(l.textContent=r),l},ot=(e,o)=>a(e,"span","blockeditor-board-face",{"aria-hidden":"true"},([...String(o).trim()][0]??"?").toUpperCase());function I(e,o){let n=null;return e.state.doc.forEach((t,r)=>{t.attrs.id===o&&t.type===F.nodes.list_item&&t.attrs.kind==="check"&&(n={node:t,pos:r})}),n}function X(e,o,n,t){let r=I(e,o);r&&e.dispatch(J(e.state.tr.setNodeMarkup(r.pos,null,{...r.node.attrs,[n]:t||null})))}var L={person:'<circle cx="8" cy="5.4" r="2.3"/><path d="M3.6 13.2c.6-2.1 2.2-3.3 4.4-3.3s3.8 1.2 4.4 3.3"/>',calendar:'<rect x="2.5" y="3.5" width="11" height="10"/><path d="M2.5 6.8h11M5.5 2v2.4M10.5 2v2.4"/>',clock:'<circle cx="8" cy="8" r="5.5"/><path d="M8 4.8v3.4l2.3 1.4"/>',tick:'<path d="M3.5 8.3l3 3 6-6.2"/>',plus:'<path d="M8 3.5v9M3.5 8h9"/>',clear:'<path d="M4.8 4.8l6.4 6.4M11.2 4.8l-6.4 6.4"/>',"chevron-left":'<path d="M9.8 3.6L5.4 8l4.4 4.4"/>',"chevron-right":'<path d="M6.2 3.6L10.6 8l-4.4 4.4"/>'};function q(e,o){let n=e.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("viewBox","0 0 16 16"),n.setAttribute("width","14"),n.setAttribute("height","14"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","1.5"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round"),n.setAttribute("aria-hidden","true"),n.innerHTML=o,n}var Z=e=>String(e).padStart(2,"0"),B=/^\d{4}-\d{2}-\d{2}$/,S=(e=new Date)=>`${e.getFullYear()}-${Z(e.getMonth()+1)}-${Z(e.getDate())}`,nt=e=>{let o=new Date(`${e}T00:00:00Z`);return o.setUTCDate(o.getUTCDate()+1),o.toISOString().slice(0,10)};function rt(e,o){if(!e)return"No date";if(!B.test(e))return e;if(e===o)return"Today";if(e===nt(o))return"Tomorrow";let n=e.slice(0,4)===o.slice(0,4);return new Date(`${e}T00:00:00Z`).toLocaleDateString("en-US",{month:"short",day:"numeric",...n?{}:{year:"numeric"},timeZone:"UTC"})}function j(e,{name:o,paths:n,label:t,aria:r,filled:l,overdue:s=!1}){let i=a(e,"button","blockeditor-check-chip",{type:"button","data-check":o,"data-filled":String(l),"data-overdue":s?"true":null,"aria-expanded":"false","aria-label":r});return i.append(q(e,n),a(e,"span","blockeditor-check-chip-label",{},t)),i}var N=null;function G(e,o,{className:n,label:t,check:r,onKey:l=null}){let s=o.ownerDocument,i=s.defaultView;N&&N.close();for(let d of s.querySelectorAll(".blockeditor-check-popup"))d.remove();let y=e.dom.parentNode,h=["relative","absolute","fixed","sticky"].includes(i?.getComputedStyle?.(y)?.position??""),k=y&&h?y:s.body,f=a(s,"div",`blockeditor-check-popup ${n}`,{role:"dialog","aria-label":t,"data-check":r}),A=!1,E=()=>{let d=o.getBoundingClientRect(),c=k===s.body?{top:-(i?.scrollY??0),left:-(i?.scrollX??0)}:k.getBoundingClientRect(),p=f.getBoundingClientRect(),u=p.width||Math.min(264,(i?.innerWidth||292)-28),b=(i?.innerHeight??0)-d.bottom-2,g=p.height>0&&b<p.height;f.style.left=`${Math.round(d.right-u-c.left)}px`,f.style.top=`${Math.round((g?d.top-p.height-2:d.bottom+2)-c.top)}px`},C=d=>{if(!f.isConnected)return w();f.contains(d.target)||o.contains(d.target)||w()},w=({focusAnchor:d=!1}={})=>{if(A)return;A=!0,s.removeEventListener("mousedown",C,!0),i?.removeEventListener("resize",E),i?.removeEventListener("scroll",E,!0),N?.panel===f&&(N=null),f.remove(),o.setAttribute("aria-expanded","false");let c=o.dataset.fromKeys==="true";delete o.dataset.fromKeys,d&&c?e.focus():d&&o.focus()};return f.addEventListener("keydown",d=>{if(d.stopPropagation(),d.key==="Escape"){d.preventDefault(),w({focusAnchor:!0});return}l?.(d,f)}),k.append(f),o.setAttribute("aria-expanded","true"),N={panel:f,close:()=>w()},s.addEventListener("mousedown",C,!0),i?.addEventListener("resize",E),i?.addEventListener("scroll",E,!0),{panel:f,close:w,place:E}}function ct(e,o){let n=new Map;e.state.doc.forEach(t=>{if(t.type!==F.nodes.list_item||t.attrs.kind!=="check")return;let r=String(t.attrs.owner??"").trim();if(!r)return;let l=r.toLowerCase(),s=n.get(l)??{name:r,count:0};s.count+=1,n.set(l,s)});for(let t of o??[]){let r=String((typeof t=="string"?t:t?.name)??"").trim();r&&!n.has(r.toLowerCase())&&n.set(r.toLowerCase(),{name:r,count:0})}return[...n.values()].sort((t,r)=>t.name.localeCompare(r.name))}function at(e,o,n){let t=n.ownerDocument,r=I(e,o)?.node.attrs.owner||"",{panel:l,close:s,place:i}=G(e,n,{className:"blockeditor-check-owner",label:"Assignee",check:"owner-panel",onKey:(c,p)=>{if(c.key!=="ArrowDown"&&c.key!=="ArrowUp")return;c.preventDefault();let u=[...p.querySelectorAll("input, button:not([disabled])")],b=u.indexOf(t.activeElement),g=c.key==="ArrowDown"?1:-1;(b<0?g>0?u[0]:u[u.length-1]:u[(b+g+u.length)%u.length])?.focus()}}),y=a(t,"input","blockeditor-check-search",{type:"text",placeholder:"Find or type a name","aria-label":"Find or type a name"}),h=a(t,"div","blockeditor-check-people"),k=a(t,"button","blockeditor-check-person blockeditor-check-danger",{type:"button","data-check":"clear-owner"});k.append(q(t,L.clear),a(t,"span","blockeditor-check-person-name",{},"Remove assignee")),k.disabled=!r,k.addEventListener("click",()=>A(null)),l.append(y,a(t,"div","blockeditor-check-subhead",{},"People in this document"),h,a(t,"div","blockeditor-check-divider"),k);let f=[],A=c=>{s(),X(e,o,"owner",c)},E=(c,p)=>{let u=c.toLowerCase()===String(r).toLowerCase(),b=a(t,"button","blockeditor-check-person",{type:"button","data-check":"owner-option","data-name":c,"aria-pressed":String(u)});return b.append(ot(t,c),a(t,"span","blockeditor-check-person-name",{},c),a(t,"span","blockeditor-check-person-meta",{},`${p} ${p===1?"item":"items"}`)),u&&b.append(q(t,L.tick)),b.addEventListener("click",()=>A(c)),b},C=c=>{let p=a(t,"button","blockeditor-check-person",{type:"button","data-check":"owner-new","data-name":c}),u=a(t,"span","blockeditor-check-person-name",{},"Assign to ");return u.append(a(t,"strong",null,{},c)),p.append(q(t,L.plus),u,a(t,"span","blockeditor-check-person-meta",{},"New")),p.addEventListener("click",()=>A(c)),p},w=()=>{let c=y.value.trim(),p=c.toLowerCase(),u=ct(e,f),b=[];c&&!u.some(g=>g.name.toLowerCase()===p)&&b.push(C(c));for(let g of u)p&&!g.name.toLowerCase().includes(p)||b.push(E(g.name,g.count));h.replaceChildren(...b)};y.addEventListener("keydown",c=>{if(c.stopPropagation(),c.key==="Escape"){c.preventDefault(),s({focusAnchor:!0});return}c.key==="Enter"&&(c.preventDefault(),h.querySelector("button[data-check]")?.click())}),y.addEventListener("input",w),w(),i(),y.focus();let d=globalThis.clay?.people?.available;d&&Promise.resolve().then(()=>d()).then(c=>{!N||N.panel!==l||(f=Array.isArray(c)?c:[],w())}).catch(()=>{})}var st=["January","February","March","April","May","June","July","August","September","October","November","December"],$=(e,o,n)=>new Date(e,o,n),it=e=>e.toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"}),lt=e=>e.toLocaleDateString("en-US",{weekday:"long",month:"long",day:"numeric",year:"numeric"}),W=e=>{if(!e||!B.test(e))return null;let[o,n,t]=e.split("-").map(Number);return $(o,n-1,t)};function dt(e,o,n){let t=n.ownerDocument,r=I(e,o)?.node.attrs.due||null,l=S(),s=new Date,i=$(s.getFullYear(),s.getMonth(),s.getDate()),y=W(r)??i,h=y.getFullYear(),k=y.getMonth(),{panel:f,close:A,place:E}=G(e,n,{className:"blockeditor-check-date",label:"Due date",check:"date-panel",onKey:(m,D)=>Q(m,D)}),C=m=>{A(),X(e,o,"due",m)},w=a(t,"div","blockeditor-check-quick"),d=(m,D)=>{let M=$(i.getFullYear(),i.getMonth(),i.getDate()+D),x=a(t,"button","blockeditor-check-quick-row",{type:"button","data-check":"date-quick","data-date":S(M)});return x.append(q(t,L.calendar),a(t,"span","blockeditor-check-quick-label",{},m),a(t,"span","blockeditor-check-quick-meta",{},it(M))),x.addEventListener("click",()=>C(S(M))),x};w.append(d("Today",0),d("Tomorrow",1),d("Next week",7));let c=a(t,"div","blockeditor-check-cal"),p=a(t,"div","blockeditor-check-cal-head"),u=a(t,"span","blockeditor-check-cal-month"),b=a(t,"span","blockeditor-check-cal-nav"),g=m=>{let D=$(h,k+m,1);h=D.getFullYear(),k=D.getMonth(),H()},U=a(t,"button","blockeditor-check-cal-btn",{type:"button","aria-label":"Previous month"}),O=a(t,"button","blockeditor-check-cal-btn",{type:"button","aria-label":"Next month"});U.append(q(t,L["chevron-left"])),O.append(q(t,L["chevron-right"])),U.addEventListener("click",()=>g(-1)),O.addEventListener("click",()=>g(1)),b.append(U,O),p.append(u,b);let Y=a(t,"div","blockeditor-check-cal-grid");c.append(p,Y);let H=()=>{u.replaceChildren(a(t,"span",null,{},`${st[k]} `),a(t,"span","blockeditor-check-cal-year",{},String(h)));let m=$(h,k,1),D=$(h,k+1,0).getDate(),M=Math.ceil((m.getDay()+D)/7)*7,x=["S","M","T","W","T","F","S"].map(v=>a(t,"span","blockeditor-check-cal-dow",{},v)),T=[];for(let v=0;v<M;v+=1){let P=$(h,k,1-m.getDay()+v),R=S(P),V=a(t,"button","blockeditor-check-cal-day",{type:"button","data-check":"date-day","data-date":R,"data-outside":String(P.getMonth()!==k),"data-today":String(R===l),"aria-pressed":String(R===r),"aria-label":lt(P)},String(P.getDate()));V.addEventListener("click",()=>C(R)),T.push(V)}Y.replaceChildren(...x,...T)},Q=(m,D)=>{let M=t.activeElement?.closest?.('[data-check="date-day"]');if(!M)return;if(m.key==="Enter"||m.key===" "){m.preventDefault(),M.click();return}let x={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[m.key];if(!x)return;m.preventDefault();let T=W(M.dataset.date),v=$(T.getFullYear(),T.getMonth(),T.getDate()+x);(v.getMonth()!==k||v.getFullYear()!==h)&&(h=v.getFullYear(),k=v.getMonth(),H()),D.querySelector(`[data-check="date-day"][data-date="${S(v)}"]`)?.focus()},K=a(t,"button","blockeditor-check-quick-row blockeditor-check-danger",{type:"button","data-check":"clear-date"});K.append(q(t,L.clear),a(t,"span","blockeditor-check-quick-label",{},"Clear date")),K.disabled=!r,K.addEventListener("click",()=>C(null)),f.append(w,c,a(t,"div","blockeditor-check-divider"),K),H(),E(),(Y.querySelector('[data-check="date-day"][aria-pressed="true"]')??Y.querySelector('[data-check="date-day"][data-today="true"]'))?.focus()}function ut(e,o){let n=e.dom.ownerDocument,t=n.createElement("span");t.className="blockeditor-check-controls",t.contentEditable="false",t.dataset.empty=String(!o.attrs.owner&&!o.attrs.due);let r=S(),l=o.attrs.owner||"Unassigned",s=j(n,{name:"owner",paths:L.person,label:l,aria:`Assignee: ${l}`,filled:!!o.attrs.owner}),i=rt(o.attrs.due,r),y=!!o.attrs.due&&!o.attrs.checked&&B.test(o.attrs.due)&&o.attrs.due<r,h=j(n,{name:"date",paths:y?L.clock:L.calendar,label:i,aria:`Due date: ${i}`,filled:!!o.attrs.due,overdue:y});return s.addEventListener("click",()=>at(e,o.attrs.id,s)),h.addEventListener("click",()=>dt(e,o.attrs.id,h)),t.append(s,h),t}function pt(e,o){let n=e.state.selection.$head;if(n.depth!==1||n.parent.type!==F.nodes.list_item||n.parent.attrs.kind!=="check")return!1;let t=n.parent.attrs.id,l=[...e.dom.querySelectorAll(".blockeditor-check-controls")].find(s=>s.dataset.item===t)?.querySelector(`[data-check="${o}"]`);return l?(l.dataset.fromKeys="true",l.click(),!0):!1}function ht(e){let o=[],n=S();return e.doc.forEach((t,r)=>{t.type!==F.nodes.list_item||t.attrs.kind!=="check"||o.push(tt.widget(r+t.nodeSize-1,l=>{let s=ut(l,t);return s.dataset.item=t.attrs.id,s},{key:`${t.attrs.id}:${t.attrs.owner}:${t.attrs.due}:${t.attrs.checked}:${n}`,side:-1,stopEvent:l=>!!l.target.closest?.(".blockeditor-check-chip, .blockeditor-check-popup"),ignoreSelection:!0}))}),et.create(e.doc,o)}function kt(e){let o=S(),n=()=>{e.isDestroyed||S()===o||(o=S(),e.dispatch(e.state.tr.setMeta("addToHistory",!1)))},t=e.dom.ownerDocument.defaultView,r=t.setInterval(n,6e4);return t.document.addEventListener("visibilitychange",n),()=>{t.clearInterval(r),t.document.removeEventListener("visibilitychange",n)}}function gt({view:e=null}={}){let o=e?z(e,{decorations:ht,focusControl:pt}):()=>{},n=e?kt(e):()=>{};return e&&!e.isDestroyed&&e.dispatch(e.state.tr.setMeta("addToHistory",!1)),{id:"checklist",dispose(){o(),n()}}}export{gt as createFeature,ht as decorations,pt as focusControl};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as A}from"./c-Q6BG3ZLO.js";import{j as b}from"./c-
|
|
1
|
+
import{c as A}from"./c-Q6BG3ZLO.js";import{j as b}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 as x}from"./c-3XGLJAS7.js";import"./c-OH2FPYSY.js";import"./c-FSQXFG5T.js";import{b as h}from"./c-RETTCOWO.js";import"./c-JC4RZW4E.js";import"./c-57XDY6HC.js";import"./c-VHNSBD2M.js";function S(o){let s=String(o??""),n=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter("en",{granularity:"grapheme"}):null;return n?[...n.segment(s)].map(a=>a.segment):[...s]}var I=o=>S(o).length===1&&!/^\s*$/.test(String(o??""));function L(o){let s=[];for(let[n,a]of Object.entries(o??{}))for(let u of Array.isArray(a)?a:[]){let[f,m,d=""]=u??[];typeof f!="string"||typeof m!="string"||s.push({id:`${n}:${m}`,char:f,name:`${f} ${m}`,keywords:`${m} ${d}`})}return s}var P=(o,s)=>{let n=String(s??"").trim().toLowerCase();return n?o.filter(a=>a.char===n||a.keywords.toLowerCase().includes(n)):o};function T(o=()=>import("./c-SZGYW5HT.js")){let s=null;return()=>(s??=Promise.resolve().then(()=>o()).then(n=>L(n.EMOJI)).catch(n=>{throw s=null,n}),s)}function w({view:o=null,load:s=()=>import("./c-SZGYW5HT.js")}={}){if(!o)return{run:()=>({ok:!1,code:"not-editing"}),dispose(){}};let n=o.dom.ownerDocument,a=T(s),u=null;function f(t){let e=o.state,r=e.selection;if(r.from!==t.from||r.to!==t.to||t.from<0||t.to>e.doc.content.size)return null;let c=e.doc.resolve(t.from),i=e.doc.resolve(t.to);return!c.parent.isTextblock||c.parent!==i.parent?null:{from:t.from,to:t.to}}function m(t){try{let e=o.dom.parentElement?.getBoundingClientRect?.()??{left:0,top:0},r=o.coordsAtPos(t.from);return{x:Math.max(8,r.left-e.left),y:r.bottom+6-e.top}}catch{return null}}function d(t){let e=t.picker.activeId();e?o.dom.setAttribute("aria-activedescendant",e):o.dom.getAttribute("aria-activedescendant")?.startsWith(t.picker.el.id)&&o.dom.removeAttribute("aria-activedescendant")}function l(){let t=u;if(t){u=null;for(let[e,r,c,i]of t.listen)e.removeEventListener(r,c,i);o.dom.getAttribute("aria-activedescendant")?.startsWith(`${t.picker.el.id}-`)&&o.dom.removeAttribute("aria-activedescendant"),t.picker.destroy()}}function j(t,e){let r=o.state.tr.insertText(e,t.from,t.to);return r.setSelection(h.TextSelection.create(r.doc,t.from+e.length)),o.dispatch(x(r)),o.focus(),{ok:!0,emoji:e}}function p(t){let e=u;if(!e)return{ok:!1,code:"not-editing"};let r=e.picker.personAt(t),c=f(e);return!r||c===null||!I(r.char)?(l(),r?c===null?{ok:!1,code:"stale-target"}:{ok:!1,code:"invalid-emoji"}:{ok:!1,code:"no-emoji"}):(l(),j(c,r.char))}function E(t){let e=u;if(!e||b(t,o))return;let r=()=>{t.preventDefault(),t.stopPropagation()};t.key==="ArrowDown"||t.key==="ArrowUp"?(r(),e.picker.move(t.key==="ArrowDown"?1:-1),d(e)):t.key==="Enter"?(r(),p(e.picker.index())):(t.key==="Escape"||t.key==="Tab")&&(r(),l())}async function $(t={}){l();let e={from:o.state.selection.from,to:o.state.selection.to,picker:null,listen:[]};e.picker=A({document:n,label:"Insert an emoji",empty:"No emoji found",onPick:i=>p(i)}),u=e;let r=(i,k,g,y)=>{i.addEventListener(k,g,y),e.listen.push([i,k,g,y])};r(n,"keydown",i=>E(i),!0),r(o.dom,"input",()=>l()),r(n,"mousedown",i=>{e.picker.el.contains(i.target)||l()},!0),(o.dom.parentElement??n.body).appendChild(e.picker.el);let c;try{c=await a()}catch(i){return l(),{ok:!1,code:"unavailable",error:i}}return u!==e?{ok:!1,code:"not-editing"}:f(e)===null?(l(),{ok:!1,code:"stale-target"}):(e.picker.show(P(c,t?.query),m(e)),d(e),{ok:!0,picker:!0})}return{async run(t){return $(t)},dispose(){l()}}}export{w as createFeature,L as emojiEntries,T as emojiLibrary,P as filterEmoji,S as graphemes,I as isEmojiText};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as K}from"./c-NEQRFC4O.js";import{e as te,f as ne,g as oe}from"./c-JRKY44DK.js";import{d as N,e as L,f as R,h as ie,l as se}from"./c-GO635CRU.js";import{b as M}from"./c-V2V5FKXX.js";import{a as T,b as re,f as $,g as O,h as G,i as P,r as I,s as B}from"./c-WMRJKQ2V.js";import{c as _}from"./c-57XDY6HC.js";import{a as ee}from"./c-I2SCCUEW.js";function F(e){let t=new Set;for(let[,n]of _(e?.y??{}))try{for(let o of P(I(re(n))).keys())t.add(o)}catch{}return t}function Ae(e,t){let n=F(e),o=F(t);if(!n.size||!o.size||[...o].some(r=>n.has(r)))return!0;let i=new Map(_(e?.y??{}));return _(t?.y??{}).some(([r,s])=>i.get(r)===s)}function ae(e,t){return!e||!t||!e.generation||!t.generation?!1:e.generation===t.generation&&e.baseDigest===t.baseDigest}async function ce(e,t){let n=t instanceof Uint8Array?t:new Uint8Array(0);return{generation:e,baseDigest:await L(n),baseVector:n.length?I(n):new Uint8Array(0)}}function le(e,t){let n=F(e),o=F(t);return!n.size||!o.size?!1:Ae(e,t)}var Se="page.yjs",Ie=1,Ue=64,Ve=1024*1024,Ye=e=>B(e),W=class extends Error{constructor(t,n){super(n),this.name="PageReplayError",this.code=t}},y=(e,t)=>{throw new W(e,t)},m=e=>typeof e=="string"?e:JSON.stringify(e),U=e=>e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):null,Oe=(e,t)=>m(e)===m(t);function z(e){let t=e.map(U).filter(n=>n&&n.length);return t.length?t.length===1?t[0].slice():B(t):new Uint8Array(0)}function H({capsule:e,batches:t=[]}={}){(!e||e.kind!=="binary"||!e.payload)&&y("invalid-capsule","Replay needs a binary capsule"),e.version!==void 0&&e.version!==1&&y("unknown-version",`Unknown page recovery capsule version: ${e.version}`);let n=[e.payload.dependencies],o=[e.payload.owned],i=new Set;for(let r of t){if((!r||r.kind!=="binary-batch"||!r.payload)&&y("invalid-batch","Replay reads binary batches only"),r.capsuleId!==void 0&&!Oe(r.capsuleId,e.id)&&y("foreign-batch","A batch belongs to another capsule"),r.id!==void 0){if(i.has(m(r.id)))continue;i.add(m(r.id))}r.origin==="dependency"?n.push(r.payload):o.push(r.payload)}return{id:e.id,context:e.context??null,revision:e.revision??0,acknowledged:e.acknowledged??null,base:z([e.payload.base]),dependencies:z(n),owned:z(o)}}function Pe({capsule:e,batches:t=[]}={}){let n=H({capsule:e,batches:t}),o=new $;try{for(let i of[n.base,n.dependencies,n.owned])i.length&&O(o,i,M);return(o.store.pendingStructs||o.store.pendingDs)&&y("unresolved-update","The capsule's updates are missing a prerequisite"),{v:1,g:0,y:{seed:T(G(o))}}}finally{o.destroy()}}function Ee({capsule:e,batches:t=[]}={}){return K(Pe({capsule:e,batches:t}))}function _e({capsule:e,batches:t=[],current:n}={}){let o=H({capsule:e,batches:t});o.context?.authority||y("missing-identity","A capsule with no authority is never replayed"),n?.context?.authority||y("missing-identity","Replay needs the page's own authority"),oe(o.context.authority,n.context.authority)||y("foreign-authority","This journal belongs to another document or account"),ae(o.context.lineage,n.context.lineage)||y("foreign-generation","This journal belongs to another generation of this page");let i=R(n.state);o.base.length&&!N(i,o.base)&&y("missing-base","The page no longer contains the journal's base"),o.owned.length||y("nothing-owned","This capsule owns no local work");let r=z([o.base,o.dependencies,o.owned]);return le(n.state,{v:1,g:0,y:{seed:T(r)}})||y("foreign-lineage","This journal shares no ancestry with this page"),o}function he(e=[]){let t=new Map,n=new Map;for(let o of e||[]){if(!o||o.supported===!1)continue;if(o.kind==="binary"){t.set(m(o.id),o);continue}if(o.kind!=="binary-batch"||o.capsuleId===void 0)continue;let i=m(o.capsuleId),r=n.get(i)??[];r.push(o),n.set(i,r)}return[...t.entries()].map(([o,i])=>({capsule:i,batches:n.get(o)??[]}))}function Te(e,t){for(let n of[t.base,t.dependencies,t.owned])n&&n.length&&O(e,n,se)}function Be(e,t){try{let{owned:n}=H({capsule:e.capsule,batches:e.batches});return n.length>0&&N(R(t.state),n)}catch{return!1}}function Me({records:e=[],current:t,into:n}={}){let o=[],i=[];for(let r of he(e)){let s;try{s=_e({capsule:r.capsule,batches:r.batches,current:t})}catch(l){if(l?.code==="nothing-owned"||l?.code==="foreign-generation"&&Be(r,t))continue;i.push({capsule:r.capsule,batches:r.batches,code:l?.code??"invalid-capsule",message:l?.message??"This journal cannot be replayed"});continue}Te(n,s),o.push({id:r.capsule.id,revision:s.revision,owned:s.owned.length})}return{replayed:o,review:i}}async function Ne({authority:e,generation:t=null,base:n=null,formatFloor:o=0}={}){let i=U(n)??new Uint8Array(0),r=typeof t=="string"&&t?t:await L(i);return{authority:e,lineage:await ce(r,i),formatFloor:o}}function Le({meta:e=null,location:t=globalThis.location,root:n=globalThis.document?.documentElement}={}){let o=t?.origin??"";if(!o)return null;let i=te(n),r=i?"host":"path",s=i?.identity??ne(t?.pathname??"/").identity;if(!s)return null;let l=e?.document?.people,u=l&&typeof l=="object"?l.me?.id??null:s;return u?{host:o,documentId:s,principalId:u,scope:r}:null}var ue=e=>typeof e=="string"?e:JSON.stringify(e);function Re(e,t){if(!t.length)return!0;let n=P(I(t)),o=P(I(e));for(let[i,r]of n)if((o.get(i)??0)<r)return!1;return!0}function de(e,t){let n=U(t);return!n||!n.length?new Uint8Array(0):N(e,n)?new Uint8Array(0):n}var wt=e=>R(e),fe=new WeakMap;function Fe(e){if(!e)return null;let t=fe.get(e);if(t)return t;let n=e.register({channel:Se,version:Ie,validateCheckpoint:ie,merge:Ye});return fe.set(e,n),n}function ze({channel:e,key:t,context:n,base:o=null,onChange:i=()=>{}}){let r=new Map,s=[],l=[],u=new Set,d=U(o)??new Uint8Array(0),f=null,k=null,b=0,S=0,g=!1,C=!0,E=!1,D=Promise.resolve(null),V=null,x=!1,v={channel:e,key:t,onChange:i,context:()=>ke.then(()=>f),local:a=>Z(a,"local"),dependency:a=>{g&&Z(a,"dependency")},records:()=>[...r.values()],names:J,next:()=>new Promise(a=>{l.push(a)}),covers:(a,c)=>{let p=[...r.values()].map(A=>A.update).filter(A=>A&&A.byteLength),h={kind:"binary",version:1,id:"journal",revision:0,payload:{base:d,dependencies:new Uint8Array(0),owned:p.length?B(p):new Uint8Array(0)}};return we([h],a,c)},pending:()=>u.size+(E?s.length:0)+(k?1:0),get failure(){return k},retire:q,rebase:be,compact:X,acknowledged:()=>x||!f||!r.size||typeof e.markAcknowledged!="function"?Promise.resolve(null):Promise.resolve(e.markAcknowledged({records:J(),authority:f.authority})).catch(()=>null),close:()=>{x=!0,s.length=0,Y(null)}},ke=Promise.resolve().then(()=>typeof n=="function"?n(d):n).catch(()=>null).then(a=>{if(f=a&&a.authority?a:null,!f)return x=!0,k="unavailable",s.length=0,v.onChange(),null;for(let c of s.splice(0))c(f);return f});function Y(a){for(let c of l.splice(0))c(a)}function q(a){for(let c of a||[]){let p=ue(c?.id),h=r.get(p);h&&(r.delete(p),b=Math.max(0,b-1),S=Math.max(0,S-(h.update?.byteLength??0)))}}function be(a){return D=D.then(()=>xe(U(a))).catch(()=>null),D}async function xe(a){if(x||!f||!a||!a.length||!Re(a,d))return null;E=!0;try{for(;u.size&&!x;)await v.next();if(x)return null;let c=typeof n=="function"?await n(a):n;if(!c||!c.authority)return null;if(g){let p=typeof e.rebase=="function"?await e.rebase({key:t,context:c,rebuild:h=>({base:a,dependencies:de(a,h.dependencies),owned:de(a,h.owned)})}):null;if(p?.code==="missing")C=!0;else if(!p?.ok)return null}d=a,f=c;for(let p of r.values())p.context=c;return c}finally{if(E=!1,f)for(let c of s.splice(0))c(f)}}function J(){return[...r.values()].map(({id:a,revision:c})=>({id:a,revision:c}))}function X(){if(V||x||!r.size||typeof e.compact!="function")return V;let a=J();return V=Promise.resolve().then(()=>e.compact({records:a})).then(c=>(c?.ok&&q(c.retired),c)).catch(()=>null).then(c=>(V=null,v.onChange(),c)),V}function ve(a,c,p,h){let A;try{A=e.append({key:t,context:a,update:c,origin:p,base:h?d:null})}catch{k="error",Y(null),v.onChange();return}let j={};u.add(j),Promise.resolve(A).then(w=>{if(u.delete(j),!w||w.ok!==!0){k=w?.code??"error",Y(null),v.onChange();return}k=null,w.skipped||(r.set(ue(w.id),{id:w.id,revision:w.revision,update:c,context:a}),b+=1,S+=c.byteLength),v.onChange(),Y({id:w.id,revision:w.revision}),(b>=Ue||S>=Ve)&&X()},()=>{u.delete(j),k="error",Y(null),v.onChange()})}function Q(a,c,p){let h=C;C=!1,ve(a,c,p,h)}function Z(a,c){x||!a||!a.byteLength||typeof e.append!="function"||(g=!0,f&&!E?Q(f,a,c):s.push(p=>Q(p,a,c)))}return v}function kt({meta:e=null,service:t=null,base:n=null,onChange:o=()=>{},location:i,root:r}={}){let s=Le({meta:e,location:i,root:r});if(!s)return null;let l=Fe(t);if(!l)return null;let u=e?.document?.blockeditorState?.generation??null,d=Array.isArray(e?.extensions)&&e.extensions.includes("blockeditor-format-v1")?1:0;return ze({channel:l,key:[s.host,s.documentId].join(":"),context:f=>Ne({authority:s,generation:u,base:f,formatFloor:d}),base:n,onChange:o})}function bt({journal:e,store:t=null,reduce:n=()=>null,onState:o=()=>{},onUnavailable:i=()=>{}}={}){if(!e)return{checkpoint(){},state:()=>null,dispose(){}};let r={acknowledged:!1,checkpointed:!1},s=null,l=()=>{let g=e.failure??null,C=e.records().length;return n({unavailable:!!g,pending:g?0:e.pending(),journaled:r.acknowledged?0:C,acknowledged:r.acknowledged?C:0,checkpointed:r.checkpointed&&!C})},u=()=>{let g=l();return!g||g===s?s:(s=g,g==="unavailable"?i(e.failure):o(g),g)},d=e.onChange;e.onChange=()=>{d?.(),u()};let f=t?.onLocal?.(()=>{r.acknowledged=!1,r.checkpointed=!1,u()}),k=t?.onConfirm?.(()=>{r.acknowledged=!0,u()}),b=()=>!!e.failure,S=ee({id:"page:journal",isPending:()=>!b()&&e.pending()>0,flush:async()=>{if(b())return{ok:!0};for(;!b()&&e.pending()>0&&await e.next(););return await Promise.resolve(e.channel?.flush?.()).catch(()=>null),{ok:b()||e.pending()===0}}});return u(),{checkpoint(){r.checkpointed=!0,u()},state:l,dispose(){e.onChange=d,f?.(),k?.(),S.dispose()}}}async function xt({journal:e,state:t,into:n}={}){if(!e)return{replayed:[],review:[]};let o=await e.context();if(!o)return{replayed:[],review:[]};let i=await e.channel.list();return i?.ok?Me({records:i.records,current:{context:o,state:t},into:n}):{replayed:[],review:[]}}var pe=e=>typeof e?.pos=="string"?e.pos:"",He=e=>Object.keys(e).sort((t,n)=>{let o=pe(e[t]),i=pe(e[n]);return o!==i?o<i?-1:1:t<n?-1:t>n?1:0});function me(e){if(typeof e?.c=="string")return e.c;if(!e?.rows)return"";let t=[];for(let n of Object.values(e.rows))for(let o of Object.values(n?.cells??{})){let i=typeof o=="string"?o:typeof o?.c=="string"?o.c:"";i&&t.push(i)}return t.join(" ")}function De(e=[]){let t=new $;try{for(let n of he(e)){let o;try{o=H(n)}catch{continue}for(let i of[o.base,o.dependencies,o.owned])i.length&&O(t,i,M)}for(let n of e||[]){let o=U(n?.update);o&&o.length&&O(t,o,M)}return K({v:1,g:0,y:{seed:T(G(t))}})}catch{return null}finally{t.destroy()}}function Je({capsule:e,batches:t=[]}={}){let n;try{n=Ee({capsule:e,batches:t})}catch{return""}let o=[];for(let i of He(n)){let r=me(n[i]);r&&o.push(r)}return o.join(`
|
|
1
|
+
import{a as K}from"./c-MVVEIJUU.js";import{e as te,f as ne,g as oe}from"./c-JRKY44DK.js";import{e as N,f as L,g as R,i as ie,m as se}from"./c-LAKBBJOU.js";import{b as M}from"./c-EIUKME3W.js";import{a as T,b as re,i as $,j as O,k as G,l as P,v as I,w as B}from"./c-WHQUZM2V.js";import{c as _}from"./c-57XDY6HC.js";import{a as ee}from"./c-I2SCCUEW.js";function F(e){let t=new Set;for(let[,n]of _(e?.y??{}))try{for(let o of P(I(re(n))).keys())t.add(o)}catch{}return t}function Ae(e,t){let n=F(e),o=F(t);if(!n.size||!o.size||[...o].some(r=>n.has(r)))return!0;let i=new Map(_(e?.y??{}));return _(t?.y??{}).some(([r,s])=>i.get(r)===s)}function ae(e,t){return!e||!t||!e.generation||!t.generation?!1:e.generation===t.generation&&e.baseDigest===t.baseDigest}async function ce(e,t){let n=t instanceof Uint8Array?t:new Uint8Array(0);return{generation:e,baseDigest:await L(n),baseVector:n.length?I(n):new Uint8Array(0)}}function le(e,t){let n=F(e),o=F(t);return!n.size||!o.size?!1:Ae(e,t)}var Se="page.yjs",Ie=1,Ue=64,Ve=1024*1024,Ye=e=>B(e),W=class extends Error{constructor(t,n){super(n),this.name="PageReplayError",this.code=t}},y=(e,t)=>{throw new W(e,t)},m=e=>typeof e=="string"?e:JSON.stringify(e),U=e=>e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):null,Oe=(e,t)=>m(e)===m(t);function z(e){let t=e.map(U).filter(n=>n&&n.length);return t.length?t.length===1?t[0].slice():B(t):new Uint8Array(0)}function H({capsule:e,batches:t=[]}={}){(!e||e.kind!=="binary"||!e.payload)&&y("invalid-capsule","Replay needs a binary capsule"),e.version!==void 0&&e.version!==1&&y("unknown-version",`Unknown page recovery capsule version: ${e.version}`);let n=[e.payload.dependencies],o=[e.payload.owned],i=new Set;for(let r of t){if((!r||r.kind!=="binary-batch"||!r.payload)&&y("invalid-batch","Replay reads binary batches only"),r.capsuleId!==void 0&&!Oe(r.capsuleId,e.id)&&y("foreign-batch","A batch belongs to another capsule"),r.id!==void 0){if(i.has(m(r.id)))continue;i.add(m(r.id))}r.origin==="dependency"?n.push(r.payload):o.push(r.payload)}return{id:e.id,context:e.context??null,revision:e.revision??0,acknowledged:e.acknowledged??null,base:z([e.payload.base]),dependencies:z(n),owned:z(o)}}function Pe({capsule:e,batches:t=[]}={}){let n=H({capsule:e,batches:t}),o=new $;try{for(let i of[n.base,n.dependencies,n.owned])i.length&&O(o,i,M);return(o.store.pendingStructs||o.store.pendingDs)&&y("unresolved-update","The capsule's updates are missing a prerequisite"),{v:1,g:0,y:{seed:T(G(o))}}}finally{o.destroy()}}function Ee({capsule:e,batches:t=[]}={}){return K(Pe({capsule:e,batches:t}))}function _e({capsule:e,batches:t=[],current:n}={}){let o=H({capsule:e,batches:t});o.context?.authority||y("missing-identity","A capsule with no authority is never replayed"),n?.context?.authority||y("missing-identity","Replay needs the page's own authority"),oe(o.context.authority,n.context.authority)||y("foreign-authority","This journal belongs to another document or account"),ae(o.context.lineage,n.context.lineage)||y("foreign-generation","This journal belongs to another generation of this page");let i=R(n.state);o.base.length&&!N(i,o.base)&&y("missing-base","The page no longer contains the journal's base"),o.owned.length||y("nothing-owned","This capsule owns no local work");let r=z([o.base,o.dependencies,o.owned]);return le(n.state,{v:1,g:0,y:{seed:T(r)}})||y("foreign-lineage","This journal shares no ancestry with this page"),o}function he(e=[]){let t=new Map,n=new Map;for(let o of e||[]){if(!o||o.supported===!1)continue;if(o.kind==="binary"){t.set(m(o.id),o);continue}if(o.kind!=="binary-batch"||o.capsuleId===void 0)continue;let i=m(o.capsuleId),r=n.get(i)??[];r.push(o),n.set(i,r)}return[...t.entries()].map(([o,i])=>({capsule:i,batches:n.get(o)??[]}))}function Te(e,t){for(let n of[t.base,t.dependencies,t.owned])n&&n.length&&O(e,n,se)}function Be(e,t){try{let{owned:n}=H({capsule:e.capsule,batches:e.batches});return n.length>0&&N(R(t.state),n)}catch{return!1}}function Me({records:e=[],current:t,into:n}={}){let o=[],i=[];for(let r of he(e)){let s;try{s=_e({capsule:r.capsule,batches:r.batches,current:t})}catch(l){if(l?.code==="nothing-owned"||l?.code==="foreign-generation"&&Be(r,t))continue;i.push({capsule:r.capsule,batches:r.batches,code:l?.code??"invalid-capsule",message:l?.message??"This journal cannot be replayed"});continue}Te(n,s),o.push({id:r.capsule.id,revision:s.revision,owned:s.owned.length})}return{replayed:o,review:i}}async function Ne({authority:e,generation:t=null,base:n=null,formatFloor:o=0}={}){let i=U(n)??new Uint8Array(0),r=typeof t=="string"&&t?t:await L(i);return{authority:e,lineage:await ce(r,i),formatFloor:o}}function Le({meta:e=null,location:t=globalThis.location,root:n=globalThis.document?.documentElement}={}){let o=t?.origin??"";if(!o)return null;let i=te(n),r=i?"host":"path",s=i?.identity??ne(t?.pathname??"/").identity;if(!s)return null;let l=e?.document?.people,u=l&&typeof l=="object"?l.me?.id??null:s;return u?{host:o,documentId:s,principalId:u,scope:r}:null}var ue=e=>typeof e=="string"?e:JSON.stringify(e);function Re(e,t){if(!t.length)return!0;let n=P(I(t)),o=P(I(e));for(let[i,r]of n)if((o.get(i)??0)<r)return!1;return!0}function de(e,t){let n=U(t);return!n||!n.length?new Uint8Array(0):N(e,n)?new Uint8Array(0):n}var wt=e=>R(e),fe=new WeakMap;function Fe(e){if(!e)return null;let t=fe.get(e);if(t)return t;let n=e.register({channel:Se,version:Ie,validateCheckpoint:ie,merge:Ye});return fe.set(e,n),n}function ze({channel:e,key:t,context:n,base:o=null,onChange:i=()=>{}}){let r=new Map,s=[],l=[],u=new Set,d=U(o)??new Uint8Array(0),f=null,k=null,b=0,S=0,g=!1,C=!0,E=!1,D=Promise.resolve(null),V=null,x=!1,v={channel:e,key:t,onChange:i,context:()=>ke.then(()=>f),local:a=>Z(a,"local"),dependency:a=>{g&&Z(a,"dependency")},records:()=>[...r.values()],names:J,next:()=>new Promise(a=>{l.push(a)}),covers:(a,c)=>{let p=[...r.values()].map(A=>A.update).filter(A=>A&&A.byteLength),h={kind:"binary",version:1,id:"journal",revision:0,payload:{base:d,dependencies:new Uint8Array(0),owned:p.length?B(p):new Uint8Array(0)}};return we([h],a,c)},pending:()=>u.size+(E?s.length:0)+(k?1:0),get failure(){return k},retire:q,rebase:be,compact:X,acknowledged:()=>x||!f||!r.size||typeof e.markAcknowledged!="function"?Promise.resolve(null):Promise.resolve(e.markAcknowledged({records:J(),authority:f.authority})).catch(()=>null),close:()=>{x=!0,s.length=0,Y(null)}},ke=Promise.resolve().then(()=>typeof n=="function"?n(d):n).catch(()=>null).then(a=>{if(f=a&&a.authority?a:null,!f)return x=!0,k="unavailable",s.length=0,v.onChange(),null;for(let c of s.splice(0))c(f);return f});function Y(a){for(let c of l.splice(0))c(a)}function q(a){for(let c of a||[]){let p=ue(c?.id),h=r.get(p);h&&(r.delete(p),b=Math.max(0,b-1),S=Math.max(0,S-(h.update?.byteLength??0)))}}function be(a){return D=D.then(()=>xe(U(a))).catch(()=>null),D}async function xe(a){if(x||!f||!a||!a.length||!Re(a,d))return null;E=!0;try{for(;u.size&&!x;)await v.next();if(x)return null;let c=typeof n=="function"?await n(a):n;if(!c||!c.authority)return null;if(g){let p=typeof e.rebase=="function"?await e.rebase({key:t,context:c,rebuild:h=>({base:a,dependencies:de(a,h.dependencies),owned:de(a,h.owned)})}):null;if(p?.code==="missing")C=!0;else if(!p?.ok)return null}d=a,f=c;for(let p of r.values())p.context=c;return c}finally{if(E=!1,f)for(let c of s.splice(0))c(f)}}function J(){return[...r.values()].map(({id:a,revision:c})=>({id:a,revision:c}))}function X(){if(V||x||!r.size||typeof e.compact!="function")return V;let a=J();return V=Promise.resolve().then(()=>e.compact({records:a})).then(c=>(c?.ok&&q(c.retired),c)).catch(()=>null).then(c=>(V=null,v.onChange(),c)),V}function ve(a,c,p,h){let A;try{A=e.append({key:t,context:a,update:c,origin:p,base:h?d:null})}catch{k="error",Y(null),v.onChange();return}let j={};u.add(j),Promise.resolve(A).then(w=>{if(u.delete(j),!w||w.ok!==!0){k=w?.code??"error",Y(null),v.onChange();return}k=null,w.skipped||(r.set(ue(w.id),{id:w.id,revision:w.revision,update:c,context:a}),b+=1,S+=c.byteLength),v.onChange(),Y({id:w.id,revision:w.revision}),(b>=Ue||S>=Ve)&&X()},()=>{u.delete(j),k="error",Y(null),v.onChange()})}function Q(a,c,p){let h=C;C=!1,ve(a,c,p,h)}function Z(a,c){x||!a||!a.byteLength||typeof e.append!="function"||(g=!0,f&&!E?Q(f,a,c):s.push(p=>Q(p,a,c)))}return v}function kt({meta:e=null,service:t=null,base:n=null,onChange:o=()=>{},location:i,root:r}={}){let s=Le({meta:e,location:i,root:r});if(!s)return null;let l=Fe(t);if(!l)return null;let u=e?.document?.blockeditorState?.generation??null,d=Array.isArray(e?.extensions)&&e.extensions.includes("blockeditor-format-v1")?1:0;return ze({channel:l,key:[s.host,s.documentId].join(":"),context:f=>Ne({authority:s,generation:u,base:f,formatFloor:d}),base:n,onChange:o})}function bt({journal:e,store:t=null,reduce:n=()=>null,onState:o=()=>{},onUnavailable:i=()=>{}}={}){if(!e)return{checkpoint(){},state:()=>null,dispose(){}};let r={acknowledged:!1,checkpointed:!1},s=null,l=()=>{let g=e.failure??null,C=e.records().length;return n({unavailable:!!g,pending:g?0:e.pending(),journaled:r.acknowledged?0:C,acknowledged:r.acknowledged?C:0,checkpointed:r.checkpointed&&!C})},u=()=>{let g=l();return!g||g===s?s:(s=g,g==="unavailable"?i(e.failure):o(g),g)},d=e.onChange;e.onChange=()=>{d?.(),u()};let f=t?.onLocal?.(()=>{r.acknowledged=!1,r.checkpointed=!1,u()}),k=t?.onConfirm?.(()=>{r.acknowledged=!0,u()}),b=()=>!!e.failure,S=ee({id:"page:journal",isPending:()=>!b()&&e.pending()>0,flush:async()=>{if(b())return{ok:!0};for(;!b()&&e.pending()>0&&await e.next(););return await Promise.resolve(e.channel?.flush?.()).catch(()=>null),{ok:b()||e.pending()===0}}});return u(),{checkpoint(){r.checkpointed=!0,u()},state:l,dispose(){e.onChange=d,f?.(),k?.(),S.dispose()}}}async function xt({journal:e,state:t,into:n}={}){if(!e)return{replayed:[],review:[]};let o=await e.context();if(!o)return{replayed:[],review:[]};let i=await e.channel.list();return i?.ok?Me({records:i.records,current:{context:o,state:t},into:n}):{replayed:[],review:[]}}var pe=e=>typeof e?.pos=="string"?e.pos:"",He=e=>Object.keys(e).sort((t,n)=>{let o=pe(e[t]),i=pe(e[n]);return o!==i?o<i?-1:1:t<n?-1:t>n?1:0});function me(e){if(typeof e?.c=="string")return e.c;if(!e?.rows)return"";let t=[];for(let n of Object.values(e.rows))for(let o of Object.values(n?.cells??{})){let i=typeof o=="string"?o:typeof o?.c=="string"?o.c:"";i&&t.push(i)}return t.join(" ")}function De(e=[]){let t=new $;try{for(let n of he(e)){let o;try{o=H(n)}catch{continue}for(let i of[o.base,o.dependencies,o.owned])i.length&&O(t,i,M)}for(let n of e||[]){let o=U(n?.update);o&&o.length&&O(t,o,M)}return K({v:1,g:0,y:{seed:T(G(t))}})}catch{return null}finally{t.destroy()}}function Je({capsule:e,batches:t=[]}={}){let n;try{n=Ee({capsule:e,batches:t})}catch{return""}let o=[];for(let i of He(n)){let r=me(n[i]);r&&o.push(r)}return o.join(`
|
|
2
2
|
`)}function vt(e=[]){return(e||[]).map(t=>({id:t?.capsule?.id,revision:t?.capsule?.revision??0,code:t?.code??"invalid-capsule",message:t?.message??"This journal cannot be replayed",text:Je({capsule:t?.capsule,batches:t?.batches??[]}),capsule:t?.capsule??null,batches:t?.batches??[]}))}function we(e=[],t=null,n=""){let o=t==null?"":String(t),i=typeof n=="string"?n:"";if(!o||!i)return!1;let r=De(e);return!!(r&&r[o]&&me(r[o])===i)}var je="page.copy",$e=1,ge=new WeakMap;function Ct(e){if(!e)return null;let t=ge.get(e);if(t)return t;let n=e.register({channel:je,version:$e});return ge.set(e,n),n}var Ge=e=>`copy:${e?.key??""}:${m(e?.id)}`;function Ke({records:e=[],source:t=null}={}){if(!t||t.id===void 0)return null;for(let n of e||[]){let o=n?.payload;if(!(!o?.source||!o?.destination)&&o.source.key===t.key&&m(o.source.id)===m(t.id))return{record:n,source:o.source,destination:o.destination}}return null}function We({marker:e=null,records:t=[]}={}){if(!e?.destination)return"open";let n=e.destination.id;return(t||[]).some(i=>i&&m(i.id)===m(n))?"copied":"covered"}async function At({channel:e,copies:t,source:n,insert:o}={}){if(!e||!t||!n||typeof o!="function")return{ok:!1,code:"unavailable"};let i,r;try{[i,r]=await Promise.all([e.list(),t.list()])}catch{return{ok:!1,code:"unavailable"}}let s=Ke({records:r?.ok?r.records:[],source:n});if(s){let d=We({marker:s,records:i?.ok?i.records:[]});if(d==="copied")return{ok:!1,code:"already-copied",marker:s};if(d==="covered")return{ok:!1,code:"covered",marker:s}}let l;try{l=await o()}catch{return{ok:!1,code:"insert-failed"}}if(!l||l.revision===void 0||l.id===void 0)return{ok:!1,code:"insert-failed"};t.stage({key:Ge(n),kind:"text",payload:{source:{key:n.key??"",id:n.id,revision:n.revision??0},destination:{key:l.key??"",id:l.id,revision:l.revision}}});let u=await t.flush();return u?.ok?{ok:!0,destination:l}:{ok:!1,code:u?.code||"error",destination:l}}var qe="page.ime",Xe=1,Qe="composing:",ye=new WeakMap;function St(e){if(!e)return null;let t=ye.get(e);if(t)return t;let n=e.register({channel:qe,version:Xe});return ye.set(e,n),n}function It({channel:e=null,key:t=""}={}){if(!e)return null;async function n(o){let i;try{i=await e.list()}catch{return 0}if(!i?.ok)return 0;let r=0;for(let s of i.records)if(s?.payload?.blockId===o)try{(await e.dismiss(s.id,{revision:s.revision}))?.ok&&(r+=1)}catch{}return r}return{key:t,channel:e,keep({blockId:o=null,text:i=""}={}){let r=o==null?"":String(o),s=typeof i=="string"?i:"";return!r||!s?null:e.stage({key:`${Qe}${r}`,kind:"text",payload:{blockId:r,text:s}})},async clear({blockId:o=null,text:i="",covered:r=null,records:s=[]}={}){let l=o==null?"":String(o);if(!l)return{ok:!1,code:"invalid"};if(!(typeof r=="boolean"?r:we(s,l,i)))return{ok:!1,code:"not-covered"};let d=await n(l);return d?{ok:!0,retired:d}:{ok:!1,code:"not-covered"}},async list(){return e.list()},dispose(){return e.flush()}}}function Ut(e=[]){let t=[];for(let n of e||[]){if(!n||n.supported===!1)continue;let o=n.payload;!o||typeof o.text!="string"||!o.text||typeof o.blockId!="string"||!o.blockId||t.push({id:n.id,revision:n.revision,blockId:o.blockId,text:o.text})}return t}export{Se as a,Ie as b,Ue as c,Ve as d,Ye as e,W as f,H as g,Pe as h,Ee as i,_e as j,he as k,Te as l,Me as m,Ne as n,Le as o,wt as p,Fe as q,ze as r,kt as s,bt as t,xt as u,Je as v,vt as w,we as x,je as y,$e as z,Ct as A,Ke as B,We as C,At as D,qe as E,Xe as F,St as G,It as H,Ut as I};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c}from"./c-OZOACVUD.js";import"./c-J2ZW4HMR.js";import"./c-A5LASUEZ.js";import"./c-4JZDZFF6.js";import"./c-5RZNFTWD.js";import"./c-PKCCHJ5X.js";import"./c-NUHP2XDB.js";import"./c-VHNSBD2M.js";export{c as bevelDialog,a as dismissOf,b as keepFocusIn};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as g}from"./c-2TJCFPX4.js";import{a as F,b as i}from"./c-4M2T676V.js";import"./c-Y6HH7LTM.js";import"./c-RHMPKZZ7.js";import"./c-OZOACVUD.js";import{d as P}from"./c-QHWJ5ZIJ.js";import{c as C,f as s,j as m,m as c}from"./c-J2ZW4HMR.js";import"./c-A5LASUEZ.js";import"./c-4JZDZFF6.js";import{c as $}from"./c-5RZNFTWD.js";import"./c-PKCCHJ5X.js";import"./c-46XYM55L.js";import"./c-NUHP2XDB.js";import"./c-VHNSBD2M.js";function U(a,v){let u=0,e=async()=>{let l=++u;try{let n=await v(),d=n?await n.list():[];if(l!==u)return;if(!d.length)return a.removeItem("clay.earlier-drafts");a.addItem({id:"clay.earlier-drafts",label:g.label,run:()=>I(n,{refresh:e,anchor:a.goo}).catch(()=>a.note("The drafts could not be opened. Try again."))})}catch{l===u&&a.removeItem("clay.earlier-drafts")}};return a.beforeOpen.push(e),e(),e}async function I(a,{refresh:v=()=>{},anchor:u=document.activeElement}={}){let e=P(),l=s("div",["display:flex","flex-direction:column","gap:16px"],{theme:e,parts:["dialog.content"]});l.dataset.draftCopies="",l.append(m("p",["display:block","margin:0"],g.intro,{theme:e}));let n=m("p",["display:block","margin:0"],"",{theme:e});n.setAttribute("role","status");let d=s("ol",["display:flex","flex-direction:column","gap:16px","padding:0","margin:0","list-style:none"],{theme:e});l.append(n,d);let A=!1;async function T(){let S=await a.list();d.replaceChildren(),S.length||(n.textContent="No earlier drafts are kept.");for(let r of S){let h=s("li",["display:flex","flex-direction:column","gap:8px"],{theme:e});h.dataset.draftMark=r.mark;let D=new Date(r.savedAt),k=Number.isNaN(D.getTime())?"Time unavailable":D.toLocaleString(),q=m("time",["display:block",`font-family:${$}`],k,{theme:e});r.savedAt&&(q.dateTime=r.savedAt),h.append(q,m("p",["display:block","margin:0"],`${r.fields} saved ${r.fields===1?"field":"fields"}`,{theme:e,role:"mutedText"}));let E=s("div",["display:flex","flex-wrap:wrap","gap:8px"],{theme:e}),f=s("div",["display:block"],{theme:e});c(f,!1);let b=s("div",["display:flex","flex-wrap:wrap","gap:8px","align-items:center"],{theme:e});c(b,!1);let y=(o,w,p={})=>{let t=C(o,{small:!0,theme:e,...p,onClick:async()=>{if(!A){A=!0,t.setDisabled(!0),n.textContent="";try{await w(t)}catch(H){n.textContent=H.message||"That did not work. Try again."}finally{A=!1,t.setDisabled(!1)}}}});return t.setAttribute("aria-label",`${o}: ${k}`),t},x=y("Preview",()=>{if(!f.hidden){c(f,!1),x.setAttribute("aria-expanded","false");return}let o=new DOMParser().parseFromString(a.html(r.copy),"text/html");for(let t of o.querySelectorAll('script, meta[http-equiv="refresh" i]'))t.remove();for(let t of o.querySelectorAll("input, textarea, select, button"))t.disabled=!0;for(let t of o.querySelectorAll("[contenteditable]"))t.removeAttribute("contenteditable");for(let t of o.querySelectorAll("a, area"))t.removeAttribute("href"),t.removeAttributeNS("http://www.w3.org/1999/xlink","href"),t.removeAttribute("xlink:href");let w=o.createElement("meta");w.httpEquiv="Content-Security-Policy",w.content="default-src 'none'; style-src 'unsafe-inline'; img-src data: blob:; form-action 'none'",o.head.prepend(w);let p=s("iframe",["display:block","width:100%","height:45vh","border:0"],{theme:e});p.title=`Draft preview: ${k}`,p.setAttribute("sandbox",""),p.srcdoc=`<!DOCTYPE html>
|
|
2
|
+
`+o.documentElement.outerHTML,f.replaceChildren(p),c(f,!0),x.setAttribute("aria-expanded","true")});x.setAttribute("aria-expanded","false");let N=y("Restore",async()=>{await a.restore(r.mark),n.textContent="Draft restored. Reloading the page.",await v()}),R=y("Download",()=>a.download(r.copy));for(let o of[x,N,R])o.setDisabled(!r.available);let O=y("Remove",()=>{c(b,!0,"flex"),M.focus()}),M=C("Keep draft",{small:!0,theme:e,onClick:()=>{c(b,!1),O.focus()}});b.append(m("p",["margin:0"],"Remove this saved draft?",{theme:e}),M,y("Remove draft",async()=>{await a.remove(r.mark),await T(),await v(),d.querySelector("button")?.focus()},{variant:"danger"})),E.append(x,N,R,O),h.append(E,b,f),d.append(h)}}return await T(),i.title=g.label,i.html=l,i.width="720px",i[F]=e,i.closeHtml="x",i.no="Close",i.onNo(()=>u?.focus()),i.open(),l}export{U as attachRecoveryMenu,I as openRecovery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as d,b as c,c as o,d as n}from"./c-QCDVDZIR.js";import{a as u}from"./c-VKEDWYDF.js";import{f as a}from"./c-C7SUMNMI.js";import{b as l,r as b}from"./c-UW6MMZ4V.js";var r="[editmode\\:contenteditable]";function m(){b(e=>{e.querySelectorAll(r).forEach(t=>{n(t),o(t,l(t)??t)})},{required:!0})}function s(){a&&u(()=>{p()})}function p(e=document){e.querySelectorAll(r).forEach(t=>{d(t);let i=t.getAttribute("inert-contenteditable")??t.getAttribute("contenteditable")??c(t,"inert-contenteditable")??"true",f=i.toLowerCase();t.setAttribute("contenteditable",["","true","false","plaintext-only"].includes(f)?i:"true"),t.removeAttribute("inert-contenteditable")})}function y(){document.querySelectorAll(r).forEach(e=>{n(e),o(e)})}function S(){m(),s()}export{r as a,p as b,y as c,S as d};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{A as
|
|
1
|
+
import{A as Z,B as k,C as P,D as g,E as T,F as y,G as A,H as E,I as z,J as x,K as O,L as tt,M as et,N as ot,O as B,P as D,S as it,T as K,c as M,d as L,e as f,n as J,t as $,x as v,y as Q}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 as Y,d as N}from"./c-3XGLJAS7.js";import{N as G,d as V,z as X}from"./c-OH2FPYSY.js";import"./c-FSQXFG5T.js";import"./c-RETTCOWO.js";import"./c-JC4RZW4E.js";import"./c-57XDY6HC.js";import{a as j}from"./c-I2SCCUEW.js";import"./c-VHNSBD2M.js";var nt=`
|
|
2
2
|
.blockeditor-editor .blockeditor-table { position: relative; }
|
|
3
3
|
.blockeditor-table td { position: relative; }
|
|
4
4
|
.blockeditor-table th { position: relative; }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Tt,c as Rt,d as Pt,e as $t,f as be,g as Ct}from"./c-JKZJIUIP.js";import{a as ee}from"./c-TCCA5BZN.js";import{a as T,b as Fe,c as Ye,d as Be,e as ke,f as Mt,g as ze,h as Lt,i as G,j as Ae,k as R,l as _t,m as qt,n as Ve,o as ue}from"./c-3LDGIBMN.js";import{d as jt}from"./c-57XDY6HC.js";import{e as Ot}from"./c-LZJPNR2W.js";import{F as Je,K as Ue,g as Et,r as Ie}from"./c-VMXCX52Q.js";import{a as We}from"./c-I2SCCUEW.js";import{f as De,g as He,k as kt,l as At,m as St,y as xt}from"./c-MFB74XVN.js";import{a as vt}from"./c-LD6UVV5R.js";import{a as Ne}from"./c-PGSBXHUE.js";import{a as je,c as bt}from"./c-KU3PX7LL.js";import{e as we,k as wt}from"./c-EQ5NBOGA.js";import{b as mt,f as Z}from"./c-C7SUMNMI.js";import{f as gt,k as yt}from"./c-PNZIJFG7.js";var gn=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),yn=/^(0|[1-9]\d*)$/,U=e=>e!==null&&typeof e=="object",te=e=>Array.isArray(e)?"a list":"an object";function J(e,t){let r=e;for(let o of t){if(!U(r))return;Array.isArray(r)?r=r[Number(o)]:r=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0}return r}var Se=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),vn=(e,t)=>R(e)===R(t);function Nt(e,t){let r=[];try{for(let o of t){let n=Mt(e,o);n&&(r.push(n),e=n.root)}return r}catch{return Ke(r),null}}function Ke(e){let t;for(let r=e.length-1;r>=0;r--)t=ze(e[r]);return t}function wn(e,t,r){let o=[];for(let n of e){if(n.at===null||Array.isArray(n.at))return null;let s=o.find(a=>a.path.length===n.path.length&&G(a.path,n.path));if(s){if(s.removed&&n.kind!=="remove")return null;n.kind==="remove"&&(s.removed=!0);continue}if(o.some(a=>G(a.path,n.path)))return null;o.push({path:n.path,at:n.at,key:n.key,had:n.kind!=="add",old:n.old,removed:n.kind==="remove"})}for(let n of o){if(n.has=Se(n.at,n.key),n.had&&n.has&&n.removed||(n.into=J(r,n.path.slice(0,-1)),!U(n.into)||Array.isArray(n.into)||Se(n.into,n.key)!==n.had))return null;let s=n.path.slice(0,-1);for(let a of t){let i=a.op.path;if(G(n.path,i)||a.op.op==="del"&&i.length<=n.path.length&&G(i.slice(0,-1),n.path)&&Array.isArray(J(r,i.slice(0,-1))))return null;if(!n.had&&n.has&&i.length>s.length&&G(s,i)){let c=i[s.length];if(i.length===s.length+1&&a.op.op==="del"||!Se(n.at,String(c)))return null}}}return o}function bn(e,t){if(t.op==="set"){let r=J(e,t.path);if(U(r)&&U(t.value)&&Array.isArray(r)===Array.isArray(t.value)){Ae(r,T(t.value));return}}Be(e,t)}function Ge({name:e,value:t,ephemeral:r=!1}){if(!U(t))throw new TypeError(`clay.live("${e}"): the tag must hold a JSON object or list`);let o=T(t),n=null,s=T(t),a=!0,i=[],c=1,d=null,h="file",w=new Set,A=new Set,b=new Set,x=new Set,E=new Set,v=new WeakMap;function O(l,u){let f={source:l,ops:u};for(let g of[...w])try{g(f)}catch(S){console.error(`clay.live("${e}"): a change listener threw`,S)}}function I(){let l=T(o),u=[];for(let f of i)try{Ye(l,f.op),l=Be(l,f.op),u.push(f)}catch{}i=u,Ae(s,l),a=!0}function N(l){for(let u of[...b])try{u(l)}catch(f){console.error(`clay.live("${e}"): a rebase listener threw`,f)}}function se(l,{source:u="remote",confirmed:f=0,through:g,drop:S,dropIds:$,frame:K=null,room:L=null,cause:ce=null}={}){if(!U(l)||te(l)!==te(s))return console.warn(`clay.live("${e}"): ignored an incoming value that is not ${te(s)}`),!1;L&&(n=L);let me=T(s),ge=o;if(o=T(l),S)i=i.filter(_=>_.id<S[0]||_.id>S[1]);else if($){let _=new Set($);i=i.filter(ye=>!_.has(ye.id))}else i=g===void 0?i.slice(f):i.filter(_=>_.id>g);return I(),N({source:u,frame:K,room:L,cause:ce,prev:ge,before:_=>J(ge,_),next:o}),_t(me,s)||O(u,null),!0}function ie(l){let u=T(o);for(let f=l.length-1;f>=0;f--){let g=l[f];ze({...g,at:J(u,g.path.slice(0,-1))})}return u}function ae(l){for(let u of[...A])try{u(l)}catch(f){console.error(`clay.live("${e}"): a transport threw`,f)}O("local",l)}function C(l){let u=l.map(Fe);for(let f of u)if(f.path.length===0&&te(f.value)!==te(s))throw new TypeError(`clay.live("${e}"): the whole value must stay ${te(s)}`);u.length===1?Ye(s,u[0]):ke(T(s),u);for(let f of u)bn(s,f);i.push(...u.map(f=>({id:c++,op:f}))),d?d.push(...u):ae(u)}function B(l,u){let f=v.get(l);f||v.set(l,f=new Map);let g=JSON.stringify(u),S=f.get(g);return S||(S=new Proxy(l,Ce(u)),f.set(g,S)),S}function Ce(l){return{get(u,f){if(Array.isArray(u)&&gn.has(f))return(...S)=>{let $=T(u),K=Array.prototype[f].apply($,S);return C([{op:"set",path:l,value:$}]),K===$?B(u,l):K};let g=u[f];return typeof f=="symbol"||!U(g)||!Object.prototype.hasOwnProperty.call(u,f)?g:B(g,[...l,Array.isArray(u)?Number(f):f])},set(u,f,g){if(typeof f=="symbol")throw new TypeError(`clay.live("${e}"): symbol keys are not JSON`);if(Array.isArray(u)){if(f==="length"){let S=T(u);return S.length=g,C([{op:"set",path:l,value:S}]),!0}if(!yn.test(f))throw new TypeError(`clay.live("${e}"): "${f}" is not a list index`);return C([{op:"set",path:[...l,Number(f)],value:g}]),!0}return C([{op:"set",path:[...l,f],value:g}]),!0},deleteProperty(u,f){if(typeof f=="symbol")return!0;if(Array.isArray(u))throw new TypeError(`clay.live("${e}"): remove a list item with splice`);return C([{op:"del",path:[...l,f]}]),!0},defineProperty(){throw new TypeError(`clay.live("${e}"): assign values instead of defining properties`)},setPrototypeOf(){return!1},preventExtensions(){return!1}}}let le=B(s,[]),Q,Me=new Promise(l=>{Q=l}),y=Object.freeze({name:e,ephemeral:r,ready:Me,get data(){return le},get status(){return{mode:h}},set(l,u){C([{op:"set",path:l,value:u}])},delete(l){C([{op:"del",path:l}])},add(l,u=1){C([{op:"add",path:l,n:u}])},update(l){if(typeof l!="function")throw new TypeError(`clay.live("${e}"): update() takes a function`);if(d)return l(le);d=[];let u=i.length,f=c,g;try{if(g=l(le),g&&typeof g.then=="function")throw new TypeError(`clay.live("${e}"): update() runs synchronously; do async work before calling it`)}catch($){throw d=null,i.length=u,c=f,I(),$}let S=Lt(d);return d=null,i.length=u,c=f,i.push(...S.map($=>({id:c++,op:$}))),S.length&&ae(S),g},on(l,u){if(l!=="change")throw new TypeError(`clay.live("${e}"): the only event is "change"`);if(typeof u!="function")throw new TypeError(`clay.live("${e}"): on() takes a function`);return w.add(u),()=>w.delete(u)},off(l,u){w.delete(u)},toJSON(){return T(s)}});return Q(y),{handle:y,name:e,ephemeral:r,get value(){return s},get authoritative(){return o},get room(){return n},get pending(){return i.map(l=>l.op)},pendingEntries(){return i.map(l=>({id:l.id,op:l.op}))},get mark(){return c-1},setMode(l){h=l,l!=="fast"&&(n=null)},onLocal(l){return A.add(l),()=>A.delete(l)},confirm(l){let u=i.filter(f=>f.id<=l);if(u.length){try{o=ke(T(o),u.map(f=>f.op))}catch{o=T(s),a=!1}i=i.filter(f=>f.id>l);for(let f of[...x])try{f({through:l})}catch(g){console.error(`clay.live("${e}"): a confirmation listener threw`,g)}}},onConfirm(l){return x.add(l),()=>x.delete(l)},rebase:se,checkOps(l){let u;try{u=l.map(Fe)}catch{return null}let f=Nt(o,u);return f?(Ke(f),u):null},rebaseOps(l,{source:u="remote",confirmed:f=0,through:g,frame:S=null,room:$=null,cause:K=null}={}){let L=Nt(o,l);if(!L)return!1;let ce=g===void 0?i.slice(f):i.filter(k=>k.id>g),me=i.length-ce.length,ge=L.some(k=>k.at===null),_=a&&!ge&&me===l.length&&l.every((k,D)=>vn(k,i[D].op)),ye=a&&!_&&me===0?wn(L,ce,s):null;if(!_&&!ye)return Ke(L),se(ke(T(o),l),{source:u,confirmed:f,through:g,frame:S,room:$,cause:K});i=ce;let Le=!1;for(let k of ye??[]){let D=k.into;if(k.has){let ht=k.at[k.key];(!k.had||R(k.old)!==R(ht))&&(Le=!0);let qe=k.had?D[k.key]:void 0,ve=T(ht),mn=U(qe)&&U(ve)&&Array.isArray(qe)===Array.isArray(ve);Object.defineProperty(D,k.key,{value:mn?Ae(qe,ve):ve,enumerable:!0,writable:!0,configurable:!0})}else k.had&&(Le=!0,delete D[k.key])}let dn=null,_e=()=>dn??=ie(L),pn=L.some(k=>Array.isArray(k.at)&&k.kind!=="put"),hn=k=>{if(pn)return J(_e(),k);for(let D of L)if(G(D.path,k))return D.path.length>k.length?J(_e(),k):J(D.old,k.slice(D.path.length));return J(o,k)};return $&&(n=$),N({source:u,frame:S,room:$,cause:K,get prev(){return _e()},before:hn,next:o}),Le&&O(u,null),!0},onRebase(l){return b.add(l),()=>b.delete(l)},onDelivery(l){return E.add(l),()=>E.delete(l)},deliver(l){for(let u of[...E])try{u(l)}catch(f){console.error(`clay.live("${e}"): a delivery listener threw`,f)}}}}function Dt({needsSave:e,blocked:t,save:r,saveNow:o,now:n=()=>Date.now(),setTimer:s=setTimeout,clearTimer:a=clearTimeout}){let i=null,c=null,d=!1,h=!1,w=0;function A(v){let O=v&&!v.ok&&v.msgType==="skipped";return w=v?.ok||O?0:n()+8e3,O?1e3:8e3}function b(v){i=v,c!==null&&a(c),c=s(E,Math.max(0,v-n()))}function x(){c!==null&&a(c),c=null,i=null}async function E(){if(c=null,i=null,!e())return;if(t()){b(n()+1e3);return}d=!0;let v=null;try{v=await r()}catch{v=null}finally{d=!1}let O=A(v);e()&&b(n()+O)}return{changed(){i===null&&!d&&b(n()+8e3)},flush(){d||!e()||t()||(x(),d=!0,h=!0,Promise.resolve().then(o).catch(()=>null).then(v=>{d=!1,h=!1;let O=A(v);e()&&b(n()+O)}))},soon(){if(d)return;let v=Math.max(n(),w);(i===null||v<i)&&b(v)},within(v){if(d)return;let O=Math.max(n()+v,w);(i===null||O<i)&&b(O)},get flushing(){return h},get deadline(){return i}}}var ne=[0,1e4,3e4],kn=6e3,An=2;async function Sn(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;try{let r=new TextEncoder().encode(String(e)),o=await t.digest("SHA-256",r),n=new Uint8Array(o),s="";for(let a=0;a<n.length;a+=1)s+=n[a].toString(16).padStart(2,"0");return s}catch{return null}}function xn(e){let t=[];for(let r of e||[]){let o=r&&r.saveId;if(typeof o=="string"&&o&&!t.includes(o)&&t.push(o),t.length>=An)break}return t}function En(e,t,r){return!!(e&&typeof e=="object"&&e.saveId===t&&e.requestHash===r&&e.status==="applied")}function Ht({query:e,digest:t=Sn,now:r=()=>Date.now(),setTimer:o=setTimeout,clearTimer:n=clearTimeout}={}){function s({captureId:a,html:i,attempts:c,initialOutcome:d,startedAt:h,onApplied:w,onUnknown:A}){let b=h+45e3,x=xn(c),E=new Set,v=new Set,O=i,I=null,N=!1;function se(y,l){try{typeof y=="function"&&y(l)}catch(u){console.error("clayjs: save-history callback failed:",u)}}function ie(){N=!0,O=null;for(let y of E)n(y);E.clear();for(let y of v)y.abort();v.clear()}function ae(y,l){N||(ie(),se(w,{captureId:a,saveId:y,requestHash:l}))}function C(y){N||(ie(),se(A,{captureId:a,reason:y}))}function B(y,l){let u=null;return u=o(()=>{u!==null&&E.delete(u),y()},Math.max(0,l)),E.add(u),u}function Ce(y){y!==null&&(n(y),E.delete(y))}async function le(y){if(N)return;let l=b-r();if(l<=0)return;let u=new AbortController;v.add(u);let f=B(()=>u.abort(),Math.min(kn,l)),g=null;try{g=await e({saveId:y,requestHash:I,signal:u.signal})}catch{g=null}finally{Ce(f),v.delete(u)}N||En(g,y,I)&&ae(y,I)}function Q(){if(!N&&!(r()>=b))for(let y of x)le(y)}async function Me(){let y=null;try{y=await t(O)}catch{y=null}if(O=null,N)return;if(typeof y!="string"||!y){C("unavailable");return}if(I=y,d&&typeof d=="object"&&d.status==="applied"&&d.requestHash===I&&x.includes(d.saveId)){ae(d.saveId,I);return}let l=r()-h;if(l>=45e3){C("expired");return}let u=-1;for(let f=0;f<ne.length;f+=1)ne[f]<=l&&(u=f);if(u<0){for(let f=0;f<ne.length;f+=1)B(Q,h+ne[f]-r());return}Q();for(let f=u+1;f<ne.length;f+=1)B(Q,h+ne[f]-r())}return B(()=>C("expired"),b-r()),Me(),{cancel(){ie()}}}return{start:s}}var On="/_/sync/data";function It(){return new URL(On,window.location.origin)}async function Tn(e,t){let r=It();r.searchParams.set("client-id",e);try{let o=await fetch(r.href,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","Document-URL":window.location.href,[Ne]:String(1)},body:JSON.stringify(t)}),n=null;try{n=await o.json()}catch{}let s=Number(o.headers?.get?.("Retry-After"))||0;return{status:o.status,body:n,retryAfter:s}}catch{return{status:0,body:null,retryAfter:0}}}async function Rn(e,t=null,{signal:r}={}){let o=It();e&&o.searchParams.set("client-id",e),t&&typeof t.epoch=="string"&&Number.isInteger(t.seq)&&o.searchParams.set("since",`${t.epoch}:${t.seq}`),o.searchParams.set("compaction","1");try{let n=await fetch(o.href,{credentials:"same-origin",cache:"no-store",headers:{"Document-URL":window.location.href,[Ne]:String(1)},signal:r});if(!n.ok){let a=null;try{a=await n.json()}catch{}return{status:n.status,code:a?.code??null,retryAfter:Number(n.headers?.get?.("Retry-After"))||0}}let s=await n.json();return s&&typeof s.epoch=="string"&&s.conn===null?null:s}catch{return null}}function Jt(){return{start(e){return Ot({open(t){t.lane==="live"&&e.open(t)},close:()=>e.close(),event(t,r){t==="data"?e.frame(r):t==="data-state"?e.state(r):t==="data-writer"&&e.writer(r)}})},send:Tn,fetchState:Rn}}var $n=()=>Promise.all([import("./c-IXO7EI2Q.js"),import("./c-XUZMRQ7O.js")]).then(([e,t])=>({createFastLane:e.createFastLane,localTransport:t.localTransport,localLaneSupported:t.localLaneSupported})),Cn=/^[A-Za-z0-9_.:-]{1,64}$/,m=new Map,Gt="save_"+[...crypto.getRandomValues(new Uint32Array(4))].map(e=>e.toString(16).padStart(8,"0")).join(""),Qe=0,Mn=0,Ln=45e3;function rt(e){let t=ue(e.getAttribute("live-at"));if(!t||t.hash!==Zn(e.textContent))return null;let r=e.getAttribute("live-by"),o=r===null?null:be(r);return r!==null&&!o?null:o&&o.v!==2?{disk:!0}:{epoch:t.epoch,seq:t.seq,frames:Pt(o),ancestors:$t(o)}}function _n(e,t){let r=e.leftAt;if(!r||r.disk)return null;let o=p?.pendingFrames(e.store.name,r,{reserve:t})??{frames:[],complete:!0};if(!o.complete)return null;let n=Tt(r.frames??[],o.frames),s=r.ancestors??[],a=R(e.store.value),i=JSON.stringify([r.epoch,r.seq,n,s,e.store.mark,a]);if(e.capture?.key===i)return e.capture.value;let c={v:2,frames:n,ancestors:s,capture:[Gt,Qe+1]},d=Ct(c),h=d?{at:Ve(r.epoch,r.seq,a),by:d}:null;return e.capture={key:i,value:h},h}var V=new Map,F=null,q=null,H=null,qn=Ht({query:e=>wt?.(e)??null}),j=new Map;function Xt(e){if(!e.captureOps.size)return;let t=new Set(e.store.pendingEntries().map(r=>r.id));for(let[r,o]of e.captureOps)o.ids=o.ids.filter(n=>t.has(n)),o.ids.length||e.captureOps.delete(r);[...e.captureOps.values()].some(r=>r.ended)||pe(e)}var Qt=(e,t)=>F===null||!He()?!1:V.get(F)?.get(e)?.key===t;function fe(e){let t=m.get(e);if(!t||!t.captureOps.size)return[];let r=new Set(t.store.pendingEntries().map(n=>n.id)),o=new Set;for(let[n,s]of t.captureOps)if(!(!s.ended&&!Qt(e,n)))for(let a of s.ids)r.has(a)&&o.add(a);return[...o]}function ot(e){for(let[t,r]of e.captureOps)if(r.ended)return[t,r];return null}We({id:"live:held",isPending:()=>[...m.values()].some(e=>ot(e))});var Ut=e=>[...e.captureOps].some(([t,r])=>!r.ended&&Qt(e.store.name,t));function jn({op:e,path:t,n:r,value:o}){let n=t.length?t.join("."):"the whole value",s=e==="add"?`${n} + ${r}`:e==="del"?`${n} removed`:`${n} = ${JSON.stringify(o)}`;return s.length>60?`${s.slice(0,57)}...`:s}function st(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,re(e)},Ln)}function pe(e){clearTimeout(e.timer),e.timer=null}function re(e,{read:t=!0}={}){let r=e.store.name,o=fe(r);if(pe(e),e.withheld=!1,e.reading=!1,tn(e),o.length){let n=e.store.pendingEntries().filter(c=>o.includes(c.id)).map(c=>c.op);e.store.handle.status.mode==="file"&&(e.leftAt=null),e.store.rebase(e.store.authoritative,{source:"state",dropIds:o});let s=n.slice(0,5).map(jn).join("; "),a=n.length>5?` and ${n.length-5} more`:"",i=`A save of "${r}" ended without an answer, so ${n.length===1?"this edit was":"these edits were"} not sent again: ${s}${a}. Check the value, and redo ${n.length===1?"it":"any"} if missing.`;console.warn(`clay.live("${r}"): ${i}`,n),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-uncertain",ops:n,message:i}}))}t&&p?.release(r,{read:p.roomBound(r)})}function de(e){Xt(e);let t=e.store.name;if(e.recovery&&!Dn(e)&&tn(e),!(!e.withheld||e.reading||fe(t).length)){if(!p?.roomBound(t)){e.withheld=!1,pe(e);return}e.reading=!0,st(e),p.release(t,{read:!0})}}function Nn(e){let t=m.get(e);t&&(it(t),!(!t.withheld&&!t.reading)&&(t.withheld=!1,t.reading=!1,[...t.captureOps.values()].some(r=>r.ended)||pe(t)))}function Zt(){for(let e of m.values())if(e.recovery||e.historicalRefreshPending)return!0;return!1}function Dn(e){let t=new Set(e.store.pendingEntries().map(o=>o.id));return e.recovery.targets.find(({name:o})=>o===e.store.name)?.ids.some(o=>t.has(o))??!1}function Hn(e){if(!H||H.captureId!==e||typeof H.html!="string")return null;let t=[];for(let[r,o]of H.qualified)!m.get(r)||!o.length||t.push({name:r,ids:[...o],saved:H.saved.get(r)});return t.length?{captureId:e,html:H.html,targets:t}:null}function Ee(){H&&(H.html=null)}function Wn(e,t){en(e);let r=e.store.name;e.refreshTimer=setTimeout(()=>{if(e.refreshTimer=null,!e.historicalRefreshPending)return;let o=`The save of "${r}" that ended without an answer did happen, but the value the file holds now must load before newer edits can be saved.`;console.warn(`clay.live("${r}"): ${o}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-history-refresh-required",message:o}}))},Math.max(0,t-Date.now()))}function it(e){e.historicalRefreshPending&&(e.historicalRefreshPending=!1,en(e))}function en(e){e.refreshTimer!==null&&(clearTimeout(e.refreshTimer),e.refreshTimer=null)}function tn(e){let t=e.recovery;t&&(e.recovery=null,!t.targets.some(r=>m.get(r.name)?.recovery===t)&&(j.delete(t.captureId),t.run?.cancel()))}function nn(e){if(e==null)return;let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);o&&o.recovery===t&&(o.recovery=null)}t.run?.cancel()}}function In(e,{result:t,attempts:r,startedAt:o}){let{captureId:n,html:s}=e,a={captureId:n,deadline:o+45e3,targets:e.targets,run:null};j.set(n,a);for(let i of e.targets){let c=m.get(i.name);pe(c),c.recovery=a}we("save-history").then(i=>{if(j.get(n)===a){if(e.html=null,!i)return Ft(n);a.run=qn.start({captureId:n,html:s,attempts:r,initialOutcome:t?.saveOutcome??null,startedAt:o,onApplied:({saveId:c,requestHash:d})=>Jn(n,c,d),onUnknown:({reason:c})=>Un(n,c)})}},()=>{e.html=null,Ft(n)})}function Jn(e,t,r){let o=j.get(e);if(o){j.delete(e);for(let n of o.targets){let s=m.get(n.name);if(!s||s.recovery!==o)continue;s.recovery=null,s.historicalRefreshPending=!0;let a=new Set(s.store.pendingEntries().map(c=>c.id)),i=n.ids.filter(c=>a.has(c));if(s.store.rebase(JSON.parse(n.saved),{source:"state",dropIds:i}),!p){it(s);continue}p.release(s.store.name,{read:!0}),Wn(s,o.deadline)}}}function Ft(e){let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);if(!(!o||o.recovery!==t)){if(o.recovery=null,!p?.roomBound(o.store.name)){re(o,{read:!1});continue}o.withheld=!0,o.reading=!0,st(o),p.release(o.store.name,{read:!0})}}}}function Un(e,t){let r=j.get(e);if(r){j.delete(e);for(let o of r.targets){let n=m.get(o.name);!n||n.recovery!==r||(n.recovery=null,re(n))}}}function Fn(e,t,r){let o=e.captureOps.get(t),n=e.store.name;if(!o){e.store.handle.status.mode==="file"&&(e.leftAt=null);return}if(o.ended=!0,r?.has(n)){e.withheld=!0,e.reading=!0;return}if(!p?.roomBound(n)){re(e,{read:!1});return}e.withheld=!0,e.reading=!0,st(e),p.release(n,{read:!0})}function Ze(e){if(Array.isArray(e))return e.map(Ze);if(e===null||typeof e!="object")return e;let t={};for(let r of Object.keys(e).sort())t[r]=Ze(e[r]);return t}function at(e){try{return JSON.stringify(Ze(ee(e)))}catch{return null}}var P=null,he=()=>!P||P.admitted;function Yn(){if(!Z||!he())return!1;for(let e of m.values())if(!e.store.ephemeral){if(e.store.handle.status.mode==="fast"){if(p?.isWriter()&&e.landed<e.last)return!0}else if(e.store.pending.length>0)return!0}return!1}var et=new Set;function rn(){for(let e of[...et])e()}var M=Dt({needsSave:Yn,blocked:()=>!he()||!Ue()||Ie()||Et()||Zt(),save:()=>Je().finally(rn),saveNow:()=>De(!0,()=>Je())}),p=null,tt=!1,xe=0,Oe=null,lt=!1,W=null,ct=!1;function Re(){return[...m.values()].filter(e=>!e.store.ephemeral)}function on(){if(!P||P.admitted||!p||p.status.stopped)return!1;for(let e of Re())if(e.store.handle.status.mode==="fast"&&e.store.pending.length>0)return!0;return!1}async function sn({timeoutMs:e=5e3}={}){let t=Date.now()+e,r=()=>{for(let o of Re())o.store.handle.status.mode==="fast"&&o.store.pending.length>0&&p?.release(o.store.name)};for(r();on();){if(Date.now()>=t)return{ok:!1,code:"timeout"};await new Promise(o=>setTimeout(o,5)),r()}return{ok:!0}}We({id:"live:writer",isPending:on,flush:sn});function Bn(){for(let e of m.values()){e.framesSince=!1;let t=e.store.pendingEntries().map(r=>r.id);t.length&&e.store.rebase(e.store.authoritative,{source:"state",dropIds:t})}}function zn(){let e=p;p=null,tt=!1,xe++,Oe=null,W=null,lt=!1,Te=null,ut=null,X=null,z=null,e?.stop()}function $r(){return{id:"clay:live",order:200,prepare(e={}){if(e.initial===!0)return P||(P={admitted:!0}),Bt(P,{adopted:!0});an();let t={admitted:!1,wantsLane:!0};return P=t,Bn(),Pe(),Bt(t)}}}function Yt(){for(let e of Re())e.store.pending.length>0&&p?.release(e.store.name)}function Bt(e,{adopted:t=!1}={}){return{enable(){t||P!==e||(e.admitted=!0,Pe(),Yt())},quiesce(){if(P===e)return e.admitted=!1,sn()},resume(){P===e&&(e.admitted=!0,Yt())},dispose(){P===e&&(P=null,zn())}}}var Te=null,ut=null,X=null,z=null;function an(){Te=new Promise(e=>{X=e}),ut=new Promise(e=>{z=e})}function ft(){return Te||an(),{laneReady:Te,writerReady:ut}}function Cr(){return ft().laneReady}function Mr(){return ft().writerReady}function zt(){for(let e of m.values())if(!e.store.ephemeral&&e.store.handle.status.mode==="fast"&&e.landed===-1){M.soon();return}M.changed()}function Xe(e,t){e.store.rebase(e.store.authoritative,{source:"state",through:t})}function dt(e,t,r=null){if(e)for(let[o,n]of e){let s=m.get(o);!s||n.mode!=="file"||(t||n.maybeLanded?Fn(s,n.key,r):(s.captureOps.delete(n.key),de(s)),s.store.handle.status.mode==="fast"&&p?.release(o))}}function oe(e){let t=V.get(e);return V.delete(e),F===e&&(F=null),q===e&&(q=null),t}function ln(e,t=null){let r=t??F??q;r!==null&&dt(oe(r),e)}function Vn(e,t){if(e?.code==="draft-storage"||e?.code==="draft-not-ready")return!1;let r=e?.code,o=r==="blockeditor-converting"||r==="blockeditor-capacity";return r==="save-already-applied"||e?.hadTimeout===!0||t!==!1&&!o&&!(e?.status>=400&&e?.status<500)}function Vt(e){return{transport:e,entries:m,onWriter:()=>{M.changed(),p&&p.status.writer!==null&&z?.(p)},onApplied:zt,onLanded:()=>{zt(),rn()},onCheckpoint:()=>M.soon(),onLeave:(t,r)=>{let o=m.get(t);o?.store.handle.status.mode==="fast"&&(o.leftAt={...r,frames:[],ancestors:[]})},held:t=>fe(t).length>0,heldIds:fe,hold:t=>{let r=m.get(t);return r?r.recovery?!0:Ut(r)?(r.withheld=!0,!0):(re(r,{read:!1}),!1):!1},taken:Nn,onStop:()=>{for(let t of m.values())it(t),!t.recovery&&(Ut(t)||re(t,{read:!1}))}}}function Kn(){let e=new Map;for(let[t,r]of Y(document,{warn:!1})){let o=m.get(t);if(o){e.set(t,{value:o.store.authoritative,ephemeral:o.store.ephemeral});continue}try{let n=ee(r.element.textContent);n!==null&&typeof n=="object"&&e.set(t,{value:n,ephemeral:r.ephemeral})}catch{}}for(let[t,r]of m)r.staged||e.set(t,{value:r.store.authoritative,ephemeral:r.store.ephemeral});return e}function Pe(){if(ft(),tt||!(P?P.admitted||P.wantsLane:Z))return;if(tt=!0,mt){X?.(null),z?.(null);return}let e=++xe;we("live-data").then(async t=>{let r=t&&await we("live-provenance");if(e!==xe)return;Oe=t,lt=r;let o=await $n().catch(()=>null);if(e===xe){if(!o){X?.(null),z?.(null);return}if(t)p=o.createFastLane(Vt(Jt()));else if(o.localLaneSupported())W=o.localTransport({seed:Kn,rooms:!0,floor:document.querySelector('meta[name="clay-blockeditor-format"]')?.getAttribute("content")}),p=o.createFastLane(Vt(W));else{X?.(null),z?.(null);return}for(let n of Y(document,{warn:!1}).keys())if(!m.has(n))try{un(n)}catch{}for(let[n,s]of m)s.historicalRefreshPending&&p.release(n,{read:!0});p.start(),X?.(p),p.status.writer!==null&&z?.(p)}}).catch(()=>{X?.(null),z?.(null)})}function Gn(e){let t=(e||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Y(e=document,{warn:t=!0}={}){let r=new Map,o=new Set;for(let n of e.querySelectorAll('script[merge][clay~="live"]')){if(n.hasAttribute("src")||!Gn(n.getAttribute("type")))continue;let s=n.getAttribute("merge");if(Cn.test(s)){if(r.has(s)){o.add(s);continue}r.set(s,{name:s,ephemeral:n.getAttribute("clay").split(/\s+/).includes("ephemeral"),element:n})}}for(let n of o)t&&console.warn(`clay.live: more than one live tag is named "${n}", so none of them is live`),r.delete(n);return r}function $e(e){return new DOMParser().parseFromString(e,"text/html")}function Xn(e){let t=e.store.handle.status.mode==="fast",r=t?e.store.authoritative:e.store.value,o=t&&/^blockeditor(\.[0-9]+)?$/.test(e.store.name)?jt(r):r;return e.layout==="lines"?Qn(o):e.layout==="pretty"?JSON.stringify(o,null,2).replace(/</g,"\\u003c"):R(o)}var Kt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Qn(e){return Kt(e)?`{${Object.entries(e).map(([r,o])=>!Kt(o)||!Object.keys(o).length?`${R(r)}:${R(o)}`:`${R(r)}:{
|
|
1
|
+
import{a as Tt,c as Rt,d as Pt,e as $t,f as be,g as Ct}from"./c-JKZJIUIP.js";import{a as ee}from"./c-TCCA5BZN.js";import{a as T,b as Fe,c as Ye,d as Be,e as ke,f as Mt,g as ze,h as Lt,i as G,j as Ae,k as R,l as _t,m as qt,n as Ve,o as ue}from"./c-3LDGIBMN.js";import{d as jt}from"./c-57XDY6HC.js";import{e as Ot}from"./c-LZJPNR2W.js";import{F as Je,K as Ue,g as Et,r as Ie}from"./c-FC5RUFPR.js";import{a as We}from"./c-I2SCCUEW.js";import{f as De,g as He,k as kt,l as At,m as St,y as xt}from"./c-EHAR4RJJ.js";import{a as vt}from"./c-LD6UVV5R.js";import{a as Ne}from"./c-PGSBXHUE.js";import{a as je,c as bt}from"./c-KU3PX7LL.js";import{e as we,k as wt}from"./c-EQ5NBOGA.js";import{b as mt,f as Z}from"./c-C7SUMNMI.js";import{f as gt,k as yt}from"./c-UW6MMZ4V.js";var gn=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),yn=/^(0|[1-9]\d*)$/,U=e=>e!==null&&typeof e=="object",te=e=>Array.isArray(e)?"a list":"an object";function J(e,t){let r=e;for(let o of t){if(!U(r))return;Array.isArray(r)?r=r[Number(o)]:r=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0}return r}var Se=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),vn=(e,t)=>R(e)===R(t);function Nt(e,t){let r=[];try{for(let o of t){let n=Mt(e,o);n&&(r.push(n),e=n.root)}return r}catch{return Ke(r),null}}function Ke(e){let t;for(let r=e.length-1;r>=0;r--)t=ze(e[r]);return t}function wn(e,t,r){let o=[];for(let n of e){if(n.at===null||Array.isArray(n.at))return null;let s=o.find(a=>a.path.length===n.path.length&&G(a.path,n.path));if(s){if(s.removed&&n.kind!=="remove")return null;n.kind==="remove"&&(s.removed=!0);continue}if(o.some(a=>G(a.path,n.path)))return null;o.push({path:n.path,at:n.at,key:n.key,had:n.kind!=="add",old:n.old,removed:n.kind==="remove"})}for(let n of o){if(n.has=Se(n.at,n.key),n.had&&n.has&&n.removed||(n.into=J(r,n.path.slice(0,-1)),!U(n.into)||Array.isArray(n.into)||Se(n.into,n.key)!==n.had))return null;let s=n.path.slice(0,-1);for(let a of t){let i=a.op.path;if(G(n.path,i)||a.op.op==="del"&&i.length<=n.path.length&&G(i.slice(0,-1),n.path)&&Array.isArray(J(r,i.slice(0,-1))))return null;if(!n.had&&n.has&&i.length>s.length&&G(s,i)){let c=i[s.length];if(i.length===s.length+1&&a.op.op==="del"||!Se(n.at,String(c)))return null}}}return o}function bn(e,t){if(t.op==="set"){let r=J(e,t.path);if(U(r)&&U(t.value)&&Array.isArray(r)===Array.isArray(t.value)){Ae(r,T(t.value));return}}Be(e,t)}function Ge({name:e,value:t,ephemeral:r=!1}){if(!U(t))throw new TypeError(`clay.live("${e}"): the tag must hold a JSON object or list`);let o=T(t),n=null,s=T(t),a=!0,i=[],c=1,d=null,h="file",w=new Set,A=new Set,b=new Set,x=new Set,E=new Set,v=new WeakMap;function O(l,u){let f={source:l,ops:u};for(let g of[...w])try{g(f)}catch(S){console.error(`clay.live("${e}"): a change listener threw`,S)}}function I(){let l=T(o),u=[];for(let f of i)try{Ye(l,f.op),l=Be(l,f.op),u.push(f)}catch{}i=u,Ae(s,l),a=!0}function N(l){for(let u of[...b])try{u(l)}catch(f){console.error(`clay.live("${e}"): a rebase listener threw`,f)}}function se(l,{source:u="remote",confirmed:f=0,through:g,drop:S,dropIds:$,frame:K=null,room:L=null,cause:ce=null}={}){if(!U(l)||te(l)!==te(s))return console.warn(`clay.live("${e}"): ignored an incoming value that is not ${te(s)}`),!1;L&&(n=L);let me=T(s),ge=o;if(o=T(l),S)i=i.filter(_=>_.id<S[0]||_.id>S[1]);else if($){let _=new Set($);i=i.filter(ye=>!_.has(ye.id))}else i=g===void 0?i.slice(f):i.filter(_=>_.id>g);return I(),N({source:u,frame:K,room:L,cause:ce,prev:ge,before:_=>J(ge,_),next:o}),_t(me,s)||O(u,null),!0}function ie(l){let u=T(o);for(let f=l.length-1;f>=0;f--){let g=l[f];ze({...g,at:J(u,g.path.slice(0,-1))})}return u}function ae(l){for(let u of[...A])try{u(l)}catch(f){console.error(`clay.live("${e}"): a transport threw`,f)}O("local",l)}function C(l){let u=l.map(Fe);for(let f of u)if(f.path.length===0&&te(f.value)!==te(s))throw new TypeError(`clay.live("${e}"): the whole value must stay ${te(s)}`);u.length===1?Ye(s,u[0]):ke(T(s),u);for(let f of u)bn(s,f);i.push(...u.map(f=>({id:c++,op:f}))),d?d.push(...u):ae(u)}function B(l,u){let f=v.get(l);f||v.set(l,f=new Map);let g=JSON.stringify(u),S=f.get(g);return S||(S=new Proxy(l,Ce(u)),f.set(g,S)),S}function Ce(l){return{get(u,f){if(Array.isArray(u)&&gn.has(f))return(...S)=>{let $=T(u),K=Array.prototype[f].apply($,S);return C([{op:"set",path:l,value:$}]),K===$?B(u,l):K};let g=u[f];return typeof f=="symbol"||!U(g)||!Object.prototype.hasOwnProperty.call(u,f)?g:B(g,[...l,Array.isArray(u)?Number(f):f])},set(u,f,g){if(typeof f=="symbol")throw new TypeError(`clay.live("${e}"): symbol keys are not JSON`);if(Array.isArray(u)){if(f==="length"){let S=T(u);return S.length=g,C([{op:"set",path:l,value:S}]),!0}if(!yn.test(f))throw new TypeError(`clay.live("${e}"): "${f}" is not a list index`);return C([{op:"set",path:[...l,Number(f)],value:g}]),!0}return C([{op:"set",path:[...l,f],value:g}]),!0},deleteProperty(u,f){if(typeof f=="symbol")return!0;if(Array.isArray(u))throw new TypeError(`clay.live("${e}"): remove a list item with splice`);return C([{op:"del",path:[...l,f]}]),!0},defineProperty(){throw new TypeError(`clay.live("${e}"): assign values instead of defining properties`)},setPrototypeOf(){return!1},preventExtensions(){return!1}}}let le=B(s,[]),Q,Me=new Promise(l=>{Q=l}),y=Object.freeze({name:e,ephemeral:r,ready:Me,get data(){return le},get status(){return{mode:h}},set(l,u){C([{op:"set",path:l,value:u}])},delete(l){C([{op:"del",path:l}])},add(l,u=1){C([{op:"add",path:l,n:u}])},update(l){if(typeof l!="function")throw new TypeError(`clay.live("${e}"): update() takes a function`);if(d)return l(le);d=[];let u=i.length,f=c,g;try{if(g=l(le),g&&typeof g.then=="function")throw new TypeError(`clay.live("${e}"): update() runs synchronously; do async work before calling it`)}catch($){throw d=null,i.length=u,c=f,I(),$}let S=Lt(d);return d=null,i.length=u,c=f,i.push(...S.map($=>({id:c++,op:$}))),S.length&&ae(S),g},on(l,u){if(l!=="change")throw new TypeError(`clay.live("${e}"): the only event is "change"`);if(typeof u!="function")throw new TypeError(`clay.live("${e}"): on() takes a function`);return w.add(u),()=>w.delete(u)},off(l,u){w.delete(u)},toJSON(){return T(s)}});return Q(y),{handle:y,name:e,ephemeral:r,get value(){return s},get authoritative(){return o},get room(){return n},get pending(){return i.map(l=>l.op)},pendingEntries(){return i.map(l=>({id:l.id,op:l.op}))},get mark(){return c-1},setMode(l){h=l,l!=="fast"&&(n=null)},onLocal(l){return A.add(l),()=>A.delete(l)},confirm(l){let u=i.filter(f=>f.id<=l);if(u.length){try{o=ke(T(o),u.map(f=>f.op))}catch{o=T(s),a=!1}i=i.filter(f=>f.id>l);for(let f of[...x])try{f({through:l})}catch(g){console.error(`clay.live("${e}"): a confirmation listener threw`,g)}}},onConfirm(l){return x.add(l),()=>x.delete(l)},rebase:se,checkOps(l){let u;try{u=l.map(Fe)}catch{return null}let f=Nt(o,u);return f?(Ke(f),u):null},rebaseOps(l,{source:u="remote",confirmed:f=0,through:g,frame:S=null,room:$=null,cause:K=null}={}){let L=Nt(o,l);if(!L)return!1;let ce=g===void 0?i.slice(f):i.filter(k=>k.id>g),me=i.length-ce.length,ge=L.some(k=>k.at===null),_=a&&!ge&&me===l.length&&l.every((k,D)=>vn(k,i[D].op)),ye=a&&!_&&me===0?wn(L,ce,s):null;if(!_&&!ye)return Ke(L),se(ke(T(o),l),{source:u,confirmed:f,through:g,frame:S,room:$,cause:K});i=ce;let Le=!1;for(let k of ye??[]){let D=k.into;if(k.has){let ht=k.at[k.key];(!k.had||R(k.old)!==R(ht))&&(Le=!0);let qe=k.had?D[k.key]:void 0,ve=T(ht),mn=U(qe)&&U(ve)&&Array.isArray(qe)===Array.isArray(ve);Object.defineProperty(D,k.key,{value:mn?Ae(qe,ve):ve,enumerable:!0,writable:!0,configurable:!0})}else k.had&&(Le=!0,delete D[k.key])}let dn=null,_e=()=>dn??=ie(L),pn=L.some(k=>Array.isArray(k.at)&&k.kind!=="put"),hn=k=>{if(pn)return J(_e(),k);for(let D of L)if(G(D.path,k))return D.path.length>k.length?J(_e(),k):J(D.old,k.slice(D.path.length));return J(o,k)};return $&&(n=$),N({source:u,frame:S,room:$,cause:K,get prev(){return _e()},before:hn,next:o}),Le&&O(u,null),!0},onRebase(l){return b.add(l),()=>b.delete(l)},onDelivery(l){return E.add(l),()=>E.delete(l)},deliver(l){for(let u of[...E])try{u(l)}catch(f){console.error(`clay.live("${e}"): a delivery listener threw`,f)}}}}function Dt({needsSave:e,blocked:t,save:r,saveNow:o,now:n=()=>Date.now(),setTimer:s=setTimeout,clearTimer:a=clearTimeout}){let i=null,c=null,d=!1,h=!1,w=0;function A(v){let O=v&&!v.ok&&v.msgType==="skipped";return w=v?.ok||O?0:n()+8e3,O?1e3:8e3}function b(v){i=v,c!==null&&a(c),c=s(E,Math.max(0,v-n()))}function x(){c!==null&&a(c),c=null,i=null}async function E(){if(c=null,i=null,!e())return;if(t()){b(n()+1e3);return}d=!0;let v=null;try{v=await r()}catch{v=null}finally{d=!1}let O=A(v);e()&&b(n()+O)}return{changed(){i===null&&!d&&b(n()+8e3)},flush(){d||!e()||t()||(x(),d=!0,h=!0,Promise.resolve().then(o).catch(()=>null).then(v=>{d=!1,h=!1;let O=A(v);e()&&b(n()+O)}))},soon(){if(d)return;let v=Math.max(n(),w);(i===null||v<i)&&b(v)},within(v){if(d)return;let O=Math.max(n()+v,w);(i===null||O<i)&&b(O)},get flushing(){return h},get deadline(){return i}}}var ne=[0,1e4,3e4],kn=6e3,An=2;async function Sn(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;try{let r=new TextEncoder().encode(String(e)),o=await t.digest("SHA-256",r),n=new Uint8Array(o),s="";for(let a=0;a<n.length;a+=1)s+=n[a].toString(16).padStart(2,"0");return s}catch{return null}}function xn(e){let t=[];for(let r of e||[]){let o=r&&r.saveId;if(typeof o=="string"&&o&&!t.includes(o)&&t.push(o),t.length>=An)break}return t}function En(e,t,r){return!!(e&&typeof e=="object"&&e.saveId===t&&e.requestHash===r&&e.status==="applied")}function Ht({query:e,digest:t=Sn,now:r=()=>Date.now(),setTimer:o=setTimeout,clearTimer:n=clearTimeout}={}){function s({captureId:a,html:i,attempts:c,initialOutcome:d,startedAt:h,onApplied:w,onUnknown:A}){let b=h+45e3,x=xn(c),E=new Set,v=new Set,O=i,I=null,N=!1;function se(y,l){try{typeof y=="function"&&y(l)}catch(u){console.error("clayjs: save-history callback failed:",u)}}function ie(){N=!0,O=null;for(let y of E)n(y);E.clear();for(let y of v)y.abort();v.clear()}function ae(y,l){N||(ie(),se(w,{captureId:a,saveId:y,requestHash:l}))}function C(y){N||(ie(),se(A,{captureId:a,reason:y}))}function B(y,l){let u=null;return u=o(()=>{u!==null&&E.delete(u),y()},Math.max(0,l)),E.add(u),u}function Ce(y){y!==null&&(n(y),E.delete(y))}async function le(y){if(N)return;let l=b-r();if(l<=0)return;let u=new AbortController;v.add(u);let f=B(()=>u.abort(),Math.min(kn,l)),g=null;try{g=await e({saveId:y,requestHash:I,signal:u.signal})}catch{g=null}finally{Ce(f),v.delete(u)}N||En(g,y,I)&&ae(y,I)}function Q(){if(!N&&!(r()>=b))for(let y of x)le(y)}async function Me(){let y=null;try{y=await t(O)}catch{y=null}if(O=null,N)return;if(typeof y!="string"||!y){C("unavailable");return}if(I=y,d&&typeof d=="object"&&d.status==="applied"&&d.requestHash===I&&x.includes(d.saveId)){ae(d.saveId,I);return}let l=r()-h;if(l>=45e3){C("expired");return}let u=-1;for(let f=0;f<ne.length;f+=1)ne[f]<=l&&(u=f);if(u<0){for(let f=0;f<ne.length;f+=1)B(Q,h+ne[f]-r());return}Q();for(let f=u+1;f<ne.length;f+=1)B(Q,h+ne[f]-r())}return B(()=>C("expired"),b-r()),Me(),{cancel(){ie()}}}return{start:s}}var On="/_/sync/data";function It(){return new URL(On,window.location.origin)}async function Tn(e,t){let r=It();r.searchParams.set("client-id",e);try{let o=await fetch(r.href,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","Document-URL":window.location.href,[Ne]:String(1)},body:JSON.stringify(t)}),n=null;try{n=await o.json()}catch{}let s=Number(o.headers?.get?.("Retry-After"))||0;return{status:o.status,body:n,retryAfter:s}}catch{return{status:0,body:null,retryAfter:0}}}async function Rn(e,t=null,{signal:r}={}){let o=It();e&&o.searchParams.set("client-id",e),t&&typeof t.epoch=="string"&&Number.isInteger(t.seq)&&o.searchParams.set("since",`${t.epoch}:${t.seq}`),o.searchParams.set("compaction","1");try{let n=await fetch(o.href,{credentials:"same-origin",cache:"no-store",headers:{"Document-URL":window.location.href,[Ne]:String(1)},signal:r});if(!n.ok){let a=null;try{a=await n.json()}catch{}return{status:n.status,code:a?.code??null,retryAfter:Number(n.headers?.get?.("Retry-After"))||0}}let s=await n.json();return s&&typeof s.epoch=="string"&&s.conn===null?null:s}catch{return null}}function Jt(){return{start(e){return Ot({open(t){t.lane==="live"&&e.open(t)},close:()=>e.close(),event(t,r){t==="data"?e.frame(r):t==="data-state"?e.state(r):t==="data-writer"&&e.writer(r)}})},send:Tn,fetchState:Rn}}var $n=()=>Promise.all([import("./c-IXO7EI2Q.js"),import("./c-BCS3AZQZ.js")]).then(([e,t])=>({createFastLane:e.createFastLane,localTransport:t.localTransport,localLaneSupported:t.localLaneSupported})),Cn=/^[A-Za-z0-9_.:-]{1,64}$/,m=new Map,Gt="save_"+[...crypto.getRandomValues(new Uint32Array(4))].map(e=>e.toString(16).padStart(8,"0")).join(""),Qe=0,Mn=0,Ln=45e3;function rt(e){let t=ue(e.getAttribute("live-at"));if(!t||t.hash!==Zn(e.textContent))return null;let r=e.getAttribute("live-by"),o=r===null?null:be(r);return r!==null&&!o?null:o&&o.v!==2?{disk:!0}:{epoch:t.epoch,seq:t.seq,frames:Pt(o),ancestors:$t(o)}}function _n(e,t){let r=e.leftAt;if(!r||r.disk)return null;let o=p?.pendingFrames(e.store.name,r,{reserve:t})??{frames:[],complete:!0};if(!o.complete)return null;let n=Tt(r.frames??[],o.frames),s=r.ancestors??[],a=R(e.store.value),i=JSON.stringify([r.epoch,r.seq,n,s,e.store.mark,a]);if(e.capture?.key===i)return e.capture.value;let c={v:2,frames:n,ancestors:s,capture:[Gt,Qe+1]},d=Ct(c),h=d?{at:Ve(r.epoch,r.seq,a),by:d}:null;return e.capture={key:i,value:h},h}var V=new Map,F=null,q=null,H=null,qn=Ht({query:e=>wt?.(e)??null}),j=new Map;function Xt(e){if(!e.captureOps.size)return;let t=new Set(e.store.pendingEntries().map(r=>r.id));for(let[r,o]of e.captureOps)o.ids=o.ids.filter(n=>t.has(n)),o.ids.length||e.captureOps.delete(r);[...e.captureOps.values()].some(r=>r.ended)||pe(e)}var Qt=(e,t)=>F===null||!He()?!1:V.get(F)?.get(e)?.key===t;function fe(e){let t=m.get(e);if(!t||!t.captureOps.size)return[];let r=new Set(t.store.pendingEntries().map(n=>n.id)),o=new Set;for(let[n,s]of t.captureOps)if(!(!s.ended&&!Qt(e,n)))for(let a of s.ids)r.has(a)&&o.add(a);return[...o]}function ot(e){for(let[t,r]of e.captureOps)if(r.ended)return[t,r];return null}We({id:"live:held",isPending:()=>[...m.values()].some(e=>ot(e))});var Ut=e=>[...e.captureOps].some(([t,r])=>!r.ended&&Qt(e.store.name,t));function jn({op:e,path:t,n:r,value:o}){let n=t.length?t.join("."):"the whole value",s=e==="add"?`${n} + ${r}`:e==="del"?`${n} removed`:`${n} = ${JSON.stringify(o)}`;return s.length>60?`${s.slice(0,57)}...`:s}function st(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,re(e)},Ln)}function pe(e){clearTimeout(e.timer),e.timer=null}function re(e,{read:t=!0}={}){let r=e.store.name,o=fe(r);if(pe(e),e.withheld=!1,e.reading=!1,tn(e),o.length){let n=e.store.pendingEntries().filter(c=>o.includes(c.id)).map(c=>c.op);e.store.handle.status.mode==="file"&&(e.leftAt=null),e.store.rebase(e.store.authoritative,{source:"state",dropIds:o});let s=n.slice(0,5).map(jn).join("; "),a=n.length>5?` and ${n.length-5} more`:"",i=`A save of "${r}" ended without an answer, so ${n.length===1?"this edit was":"these edits were"} not sent again: ${s}${a}. Check the value, and redo ${n.length===1?"it":"any"} if missing.`;console.warn(`clay.live("${r}"): ${i}`,n),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-uncertain",ops:n,message:i}}))}t&&p?.release(r,{read:p.roomBound(r)})}function de(e){Xt(e);let t=e.store.name;if(e.recovery&&!Dn(e)&&tn(e),!(!e.withheld||e.reading||fe(t).length)){if(!p?.roomBound(t)){e.withheld=!1,pe(e);return}e.reading=!0,st(e),p.release(t,{read:!0})}}function Nn(e){let t=m.get(e);t&&(it(t),!(!t.withheld&&!t.reading)&&(t.withheld=!1,t.reading=!1,[...t.captureOps.values()].some(r=>r.ended)||pe(t)))}function Zt(){for(let e of m.values())if(e.recovery||e.historicalRefreshPending)return!0;return!1}function Dn(e){let t=new Set(e.store.pendingEntries().map(o=>o.id));return e.recovery.targets.find(({name:o})=>o===e.store.name)?.ids.some(o=>t.has(o))??!1}function Hn(e){if(!H||H.captureId!==e||typeof H.html!="string")return null;let t=[];for(let[r,o]of H.qualified)!m.get(r)||!o.length||t.push({name:r,ids:[...o],saved:H.saved.get(r)});return t.length?{captureId:e,html:H.html,targets:t}:null}function Ee(){H&&(H.html=null)}function Wn(e,t){en(e);let r=e.store.name;e.refreshTimer=setTimeout(()=>{if(e.refreshTimer=null,!e.historicalRefreshPending)return;let o=`The save of "${r}" that ended without an answer did happen, but the value the file holds now must load before newer edits can be saved.`;console.warn(`clay.live("${r}"): ${o}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-history-refresh-required",message:o}}))},Math.max(0,t-Date.now()))}function it(e){e.historicalRefreshPending&&(e.historicalRefreshPending=!1,en(e))}function en(e){e.refreshTimer!==null&&(clearTimeout(e.refreshTimer),e.refreshTimer=null)}function tn(e){let t=e.recovery;t&&(e.recovery=null,!t.targets.some(r=>m.get(r.name)?.recovery===t)&&(j.delete(t.captureId),t.run?.cancel()))}function nn(e){if(e==null)return;let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);o&&o.recovery===t&&(o.recovery=null)}t.run?.cancel()}}function In(e,{result:t,attempts:r,startedAt:o}){let{captureId:n,html:s}=e,a={captureId:n,deadline:o+45e3,targets:e.targets,run:null};j.set(n,a);for(let i of e.targets){let c=m.get(i.name);pe(c),c.recovery=a}we("save-history").then(i=>{if(j.get(n)===a){if(e.html=null,!i)return Ft(n);a.run=qn.start({captureId:n,html:s,attempts:r,initialOutcome:t?.saveOutcome??null,startedAt:o,onApplied:({saveId:c,requestHash:d})=>Jn(n,c,d),onUnknown:({reason:c})=>Un(n,c)})}},()=>{e.html=null,Ft(n)})}function Jn(e,t,r){let o=j.get(e);if(o){j.delete(e);for(let n of o.targets){let s=m.get(n.name);if(!s||s.recovery!==o)continue;s.recovery=null,s.historicalRefreshPending=!0;let a=new Set(s.store.pendingEntries().map(c=>c.id)),i=n.ids.filter(c=>a.has(c));if(s.store.rebase(JSON.parse(n.saved),{source:"state",dropIds:i}),!p){it(s);continue}p.release(s.store.name,{read:!0}),Wn(s,o.deadline)}}}function Ft(e){let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);if(!(!o||o.recovery!==t)){if(o.recovery=null,!p?.roomBound(o.store.name)){re(o,{read:!1});continue}o.withheld=!0,o.reading=!0,st(o),p.release(o.store.name,{read:!0})}}}}function Un(e,t){let r=j.get(e);if(r){j.delete(e);for(let o of r.targets){let n=m.get(o.name);!n||n.recovery!==r||(n.recovery=null,re(n))}}}function Fn(e,t,r){let o=e.captureOps.get(t),n=e.store.name;if(!o){e.store.handle.status.mode==="file"&&(e.leftAt=null);return}if(o.ended=!0,r?.has(n)){e.withheld=!0,e.reading=!0;return}if(!p?.roomBound(n)){re(e,{read:!1});return}e.withheld=!0,e.reading=!0,st(e),p.release(n,{read:!0})}function Ze(e){if(Array.isArray(e))return e.map(Ze);if(e===null||typeof e!="object")return e;let t={};for(let r of Object.keys(e).sort())t[r]=Ze(e[r]);return t}function at(e){try{return JSON.stringify(Ze(ee(e)))}catch{return null}}var P=null,he=()=>!P||P.admitted;function Yn(){if(!Z||!he())return!1;for(let e of m.values())if(!e.store.ephemeral){if(e.store.handle.status.mode==="fast"){if(p?.isWriter()&&e.landed<e.last)return!0}else if(e.store.pending.length>0)return!0}return!1}var et=new Set;function rn(){for(let e of[...et])e()}var M=Dt({needsSave:Yn,blocked:()=>!he()||!Ue()||Ie()||Et()||Zt(),save:()=>Je().finally(rn),saveNow:()=>De(!0,()=>Je())}),p=null,tt=!1,xe=0,Oe=null,lt=!1,W=null,ct=!1;function Re(){return[...m.values()].filter(e=>!e.store.ephemeral)}function on(){if(!P||P.admitted||!p||p.status.stopped)return!1;for(let e of Re())if(e.store.handle.status.mode==="fast"&&e.store.pending.length>0)return!0;return!1}async function sn({timeoutMs:e=5e3}={}){let t=Date.now()+e,r=()=>{for(let o of Re())o.store.handle.status.mode==="fast"&&o.store.pending.length>0&&p?.release(o.store.name)};for(r();on();){if(Date.now()>=t)return{ok:!1,code:"timeout"};await new Promise(o=>setTimeout(o,5)),r()}return{ok:!0}}We({id:"live:writer",isPending:on,flush:sn});function Bn(){for(let e of m.values()){e.framesSince=!1;let t=e.store.pendingEntries().map(r=>r.id);t.length&&e.store.rebase(e.store.authoritative,{source:"state",dropIds:t})}}function zn(){let e=p;p=null,tt=!1,xe++,Oe=null,W=null,lt=!1,Te=null,ut=null,X=null,z=null,e?.stop()}function $r(){return{id:"clay:live",order:200,prepare(e={}){if(e.initial===!0)return P||(P={admitted:!0}),Bt(P,{adopted:!0});an();let t={admitted:!1,wantsLane:!0};return P=t,Bn(),Pe(),Bt(t)}}}function Yt(){for(let e of Re())e.store.pending.length>0&&p?.release(e.store.name)}function Bt(e,{adopted:t=!1}={}){return{enable(){t||P!==e||(e.admitted=!0,Pe(),Yt())},quiesce(){if(P===e)return e.admitted=!1,sn()},resume(){P===e&&(e.admitted=!0,Yt())},dispose(){P===e&&(P=null,zn())}}}var Te=null,ut=null,X=null,z=null;function an(){Te=new Promise(e=>{X=e}),ut=new Promise(e=>{z=e})}function ft(){return Te||an(),{laneReady:Te,writerReady:ut}}function Cr(){return ft().laneReady}function Mr(){return ft().writerReady}function zt(){for(let e of m.values())if(!e.store.ephemeral&&e.store.handle.status.mode==="fast"&&e.landed===-1){M.soon();return}M.changed()}function Xe(e,t){e.store.rebase(e.store.authoritative,{source:"state",through:t})}function dt(e,t,r=null){if(e)for(let[o,n]of e){let s=m.get(o);!s||n.mode!=="file"||(t||n.maybeLanded?Fn(s,n.key,r):(s.captureOps.delete(n.key),de(s)),s.store.handle.status.mode==="fast"&&p?.release(o))}}function oe(e){let t=V.get(e);return V.delete(e),F===e&&(F=null),q===e&&(q=null),t}function ln(e,t=null){let r=t??F??q;r!==null&&dt(oe(r),e)}function Vn(e,t){if(e?.code==="draft-storage"||e?.code==="draft-not-ready")return!1;let r=e?.code,o=r==="blockeditor-converting"||r==="blockeditor-capacity";return r==="save-already-applied"||e?.hadTimeout===!0||t!==!1&&!o&&!(e?.status>=400&&e?.status<500)}function Vt(e){return{transport:e,entries:m,onWriter:()=>{M.changed(),p&&p.status.writer!==null&&z?.(p)},onApplied:zt,onLanded:()=>{zt(),rn()},onCheckpoint:()=>M.soon(),onLeave:(t,r)=>{let o=m.get(t);o?.store.handle.status.mode==="fast"&&(o.leftAt={...r,frames:[],ancestors:[]})},held:t=>fe(t).length>0,heldIds:fe,hold:t=>{let r=m.get(t);return r?r.recovery?!0:Ut(r)?(r.withheld=!0,!0):(re(r,{read:!1}),!1):!1},taken:Nn,onStop:()=>{for(let t of m.values())it(t),!t.recovery&&(Ut(t)||re(t,{read:!1}))}}}function Kn(){let e=new Map;for(let[t,r]of Y(document,{warn:!1})){let o=m.get(t);if(o){e.set(t,{value:o.store.authoritative,ephemeral:o.store.ephemeral});continue}try{let n=ee(r.element.textContent);n!==null&&typeof n=="object"&&e.set(t,{value:n,ephemeral:r.ephemeral})}catch{}}for(let[t,r]of m)r.staged||e.set(t,{value:r.store.authoritative,ephemeral:r.store.ephemeral});return e}function Pe(){if(ft(),tt||!(P?P.admitted||P.wantsLane:Z))return;if(tt=!0,mt){X?.(null),z?.(null);return}let e=++xe;we("live-data").then(async t=>{let r=t&&await we("live-provenance");if(e!==xe)return;Oe=t,lt=r;let o=await $n().catch(()=>null);if(e===xe){if(!o){X?.(null),z?.(null);return}if(t)p=o.createFastLane(Vt(Jt()));else if(o.localLaneSupported())W=o.localTransport({seed:Kn,rooms:!0,floor:document.querySelector('meta[name="clay-blockeditor-format"]')?.getAttribute("content")}),p=o.createFastLane(Vt(W));else{X?.(null),z?.(null);return}for(let n of Y(document,{warn:!1}).keys())if(!m.has(n))try{un(n)}catch{}for(let[n,s]of m)s.historicalRefreshPending&&p.release(n,{read:!0});p.start(),X?.(p),p.status.writer!==null&&z?.(p)}}).catch(()=>{X?.(null),z?.(null)})}function Gn(e){let t=(e||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Y(e=document,{warn:t=!0}={}){let r=new Map,o=new Set;for(let n of e.querySelectorAll('script[merge][clay~="live"]')){if(n.hasAttribute("src")||!Gn(n.getAttribute("type")))continue;let s=n.getAttribute("merge");if(Cn.test(s)){if(r.has(s)){o.add(s);continue}r.set(s,{name:s,ephemeral:n.getAttribute("clay").split(/\s+/).includes("ephemeral"),element:n})}}for(let n of o)t&&console.warn(`clay.live: more than one live tag is named "${n}", so none of them is live`),r.delete(n);return r}function $e(e){return new DOMParser().parseFromString(e,"text/html")}function Xn(e){let t=e.store.handle.status.mode==="fast",r=t?e.store.authoritative:e.store.value,o=t&&/^blockeditor(\.[0-9]+)?$/.test(e.store.name)?jt(r):r;return e.layout==="lines"?Qn(o):e.layout==="pretty"?JSON.stringify(o,null,2).replace(/</g,"\\u003c"):R(o)}var Kt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Qn(e){return Kt(e)?`{${Object.entries(e).map(([r,o])=>!Kt(o)||!Object.keys(o).length?`${R(r)}:${R(o)}`:`${R(r)}:{
|
|
2
2
|
${Object.entries(o).map(([n,s])=>`${R(n)}:${R(s)}`).join(`,
|
|
3
3
|
`)}
|
|
4
4
|
}`).join(`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as H,D as X,d as M,g as L,h as O,j as D,m as I,n as R,o as k,p as C,q as A,r as N,t as $}from"./c-
|
|
1
|
+
import{C as H,D as X,d as M,g as L,h as O,j as D,m as I,n as R,o as k,p as C,q as A,r as N,t as $}from"./c-3XGLJAS7.js";import{d as B}from"./c-OH2FPYSY.js";var _=new WeakMap;function g(s){let t=_.get(s);return t||_.set(s,t=O(s)),t}var F=B.nodes,w=s=>s.type===F.list_item,S=s=>s.type===F.toggle,y=s=>s.attrs.parent??null;function J(s,t,e){if(e<0)return[null];let n=[],i=s[e].node;S(i)&&i.attrs.open&&!s[e].hidden&&n.unshift(i.attrs.id);for(let r=y(i);r!==null&&!n.includes(r);){let c=s[t.get(r)];if(!c)break;n.unshift(r),r=y(c.node)}let o=[null];for(let r of n){let c=s[t.get(r)];if(!c.node.attrs.open||c.hidden)break;o.push(r)}return o}function Y(s,t,e,n){let i=y(s[t].node),o=w(s[t].node)?n.indent-s[t].node.attrs.indent:0;return r=>r.i<t||r.i>e||y(r.node)!==i?null:w(r.node)?{parent:n.parent,indent:r.node.attrs.indent+o}:{parent:n.parent}}function Q(s,t){let e=null;s.doc.forEach((n,i)=>{n.attrs.id===t&&S(n)&&(e={n,off:i})}),e&&!e.n.attrs.open&&s.setNodeMarkup(e.off,null,{...e.n.attrs,open:!0})}function P(s,t,e,n,i,o=null){let r=Y(t,e,n,i),c=t[e].at,d=t[n].end,h=o??new C(s.doc.resolve(c),s.doc.resolve(d)),a;if(i.at===c||i.at===d){a=s.tr;for(let l=e;l<=n;l++){let p=r(t[l]);p&&a.setNodeMarkup(t[l].at,null,{...t[l].node.attrs,...p})}a.setSelection(h.map(a.doc,a.mapping)),a.setMeta(L,A(t,e,n,i.at,r))}else a=N(s,t,e,n,i.at,r,h);if(i.open){Q(a,i.open);let l=a.getMeta(L);l&&a.setMeta(L,{...l,attrs:{...l.attrs,[i.open]:{open:!0}}})}return a}function K(s,t,e,n,i){if(i.parent!=null&&t.slice(e,n+1).some(a=>a.node.attrs.id===i.parent))return!1;let o=t[n].end-t[e].at,r=Y(t,e,n,i);for(let a=e;a<=n;a++)if(w(t[a].node)&&(r(t[a])?.indent??t[a].node.attrs.indent)>$)return!1;let c=P(s,t,e,n,i),h=i.at===t[e].at||i.at===t[n].end?t[e].at:i.at>t[e].at?i.at-o:i.at;return D(c.doc,s.doc).every(a=>a.at>=h&&a.at<h+o)}function U(s,t,e,n,i){let o=new Map;t.forEach(l=>{S(l.node)&&l.node.attrs.id&&o.set(l.node.attrs.id,l.i)});let r=i<0?s.doc.content.size:t[i].at;if(r>t[e].at&&r<t[n].end)return[];let c=(i<0?t.length:i)-1,d=J(t,o,c),h=d.indexOf(i<0?null:y(t[i].node)),a=[];for(let l of d.slice(Math.max(0,h))){let p=l===null?0:t[o.get(l)].depth+1,E=c>=0&&w(t[c].node)&&y(t[c].node)===l?t[c].node:null,f=w(t[e].node)&&E?E.attrs.indent+1:0;for(let u=0;u<=f;u++){let m={at:r,parent:l,indent:u,depth:p+(w(t[e].node)?u:0)};K(s,t,e,n,m)&&a.push(m)}}return a}function q(s,t,e,n,i){let o=t[i];if(!o||!S(o.node)||o.node.attrs.open||o.hidden||i>=e&&i<=n||o.at>t[e].at&&o.at<t[n].end)return null;let r=o.node.attrs.id,c={at:t[o.subEnd].end,parent:r,indent:0,depth:o.depth+1,open:r};return K(s,t,e,n,c)?c:null}function z(s,t){let e=null;for(let n of s)(!e||Math.abs(n.depth-t)<Math.abs(e.depth-t))&&(e=n);return e}var Z=4,tt=250,V=8,b=56,W=18;function et(s){for(let t=s.parentElement;t;t=t.parentElement){let e=getComputedStyle(t).overflowY;if((e==="auto"||e==="scroll")&&t.scrollHeight>t.clientHeight)return t}return s.ownerDocument.scrollingElement}var j=new WeakMap;function nt(s,t){let e=j.get(s);if(!e){e=[];for(let n of s){if(n.hidden)continue;let i=t.nodeDOM(n.at);i?.getBoundingClientRect&&e.push({i:n.i,dom:i})}j.set(s,e)}return e}function it(s,t){let e=0,n=s.length;for(;e<n;){let i=e+n>>1,o=s[i].dom.getBoundingClientRect();t<o.top+o.height/2?n=i:e=i+1}return e<s.length?e:-1}var G=class{constructor(t,e,{index:n,onClick:i}){this.view=t,this.grip=e,this.index=n,this.onClick=i,this.shell=t.dom.parentElement,this.line=document.createElement("div"),this.line.className="blockeditor-drop",this.line.hidden=!0,this.line.setAttribute("aria-hidden","true"),this.shell.append(this.line),this.state=null,this.onMove=o=>this.move(o),this.onUp=o=>this.end(o),this.onCancel=o=>{o.pointerId===this.state?.pointer&&this.cancel()},this.onKey=o=>{o.key==="Escape"&&this.state?.active&&(o.preventDefault(),o.stopPropagation(),this.cancel())},this.onOther=o=>{this.state&&o.pointerId!==this.state.pointer&&this.cancel()},this.onBlur=()=>this.cancel(),this.onScroll=()=>{this.state&&!this.state.active&&this.stop()},e.addEventListener("pointerdown",o=>this.start(o))}start(t){if(t.button!==0||this.state)return;let e=this.view.state,n=g(e.doc),i=e.selection,o=Math.min(this.index(),n.length-1),r=i instanceof C&&n[o].at>=i.from&&n[o].end<=i.to,{lo:c,hi:d}=r?i.span(e.doc):I(n,o,o);if(this.state={index:o,span:R(n,c,d),touch:t.pointerType==="touch",pointer:t.pointerId,x0:t.clientX,y0:t.clientY,x:t.clientX,y:t.clientY,hold:0,active:!1,raf:0,gap:void 0,targets:[],target:null},this.grip.setPointerCapture?.(t.pointerId),this.grip.addEventListener("pointermove",this.onMove),this.grip.addEventListener("pointerup",this.onUp),this.grip.addEventListener("pointercancel",this.onCancel),this.grip.addEventListener("lostpointercapture",this.onCancel),this.state.touch){let h=this.state;h.hold=setTimeout(()=>this.held(h),tt),window.addEventListener("pointerdown",this.onOther,!0),window.addEventListener("blur",this.onBlur),window.addEventListener("scroll",this.onScroll,!0)}t.preventDefault()}held(t){if(!(this.state!==t||t.active)){if(t.hold=0,Math.hypot(t.x-t.x0,t.y-t.y0)>V||!this.view.editable)return this.stop();this.begin()}}move(t){let e=this.state;if(!(!e||t.pointerId!==e.pointer)){if(e.x=t.clientX,e.y=t.clientY,e.touch&&!this.view.editable)return e.active?this.cancel():this.stop();if(!e.active){let n=Math.hypot(e.x-e.x0,e.y-e.y0);if(e.touch){n>V&&this.stop();return}if(n<=Z)return;this.begin()}this.track()}}begin(){let t=this.state;if(!t||t.active)return;let e=this.view.state,n=g(e.doc),i=k(n,t.span);if(!i)return this.cancel();t.active=!0,this.view.dispatch(e.tr.setSelection(X(e.doc,i.lo,i.hi))),this.shell.classList.add("is-dragging");let o=this.shell.appendChild(document.createElement("div"));o.style.cssText="position:absolute;visibility:hidden;width:var(--blockeditor-indent)",this.indentPx=o.getBoundingClientRect().width||27,o.remove(),this.scroller=et(this.view.dom),window.addEventListener("keydown",this.onKey,!0),this.loop(),this.track()}track(){let t=this.state,e=this.view,n=e.state;if(!t)return;let i=g(n.doc),o=k(i,t.span);if(!o)return this.cancel();let{lo:r,hi:c}=o,d=nt(i,e),h=it(d,t.y),a=-1,l=null,p=null,E=h<0?d.length:h+1;for(let x=Math.max(0,E-2);x<E;x++){let v=d[x].dom.getBoundingClientRect();t.y>=v.top+v.height/4&&t.y<=v.bottom-v.height/4&&(p={i:d[x].i,bottom:v.bottom}),l=v.bottom+2}h>=0&&(a=d[h].i,l=d[h].dom.getBoundingClientRect().top-2);let f=r<0?null:p&&q(n,i,r,c,p.i),u=f?`summary:${p.i}`:a;(u!==t.gap||n.doc!==t.doc)&&(t.gap=u,t.doc=n.doc,t.targets=r<0?[]:f?[f]:U(n,i,r,c,a)),f&&(l=p.bottom+2);let m=e.dom.getBoundingClientRect().left;t.target=z(t.targets,(t.x-m)/this.indentPx);let T=this.shell.getBoundingClientRect();if(!t.target||l===null){this.line.hidden=!0,this.shell.dataset.drop="none";return}this.shell.dataset.drop="ok",this.line.hidden=!1,this.line.style.setProperty("--blockeditor-drop-y",`${l-T.top}px`),this.line.style.setProperty("--blockeditor-drop-x",`${m-T.left+t.target.depth*this.indentPx}px`),this.line.style.setProperty("--blockeditor-drop-w",`${e.dom.getBoundingClientRect().right-m-t.target.depth*this.indentPx}px`)}loop(){let t=()=>{let e=this.state;if(!e?.active)return;if(e.touch&&!this.view.editable)return this.cancel();let n=this.scroller,i=n===n.ownerDocument.scrollingElement?{top:0,bottom:window.innerHeight}:n.getBoundingClientRect(),o=0;e.y<i.top+b?o=-W*Math.min(1,(i.top+b-e.y)/b):e.y>i.bottom-b&&(o=W*Math.min(1,(e.y-(i.bottom-b))/b)),o&&(n.scrollTop+=o,this.track()),e.raf=requestAnimationFrame(t)};this.state.raf=requestAnimationFrame(t)}end(t){let e=this.state;if(!e||t.pointerId!==e.pointer)return;if(!e.active){if(this.stop(),t.type==="pointerup"){let l=g(this.view.state.doc),p=k(l,e.span);p&&this.onClick(p.lo)}return}if(this.track(),this.state!==e)return;let n=e.target,i=this.view.state,o=g(i.doc),r=k(o,e.span);if(this.stop(),!n||!r)return;let{lo:c,hi:d}=r;if(!n.open&&(n.at===o[c].at||n.at===o[d].end)&&n.parent===(o[c].node.attrs.parent??null)&&(o[c].node.type.name!=="list_item"||n.indent===o[c].node.attrs.indent))return;if(this.view.dispatch(H(P(i,o,c,d,n)).scrollIntoView()),this.view.state.doc===i.doc)return M(this.view,"Move cancelled");let a=d-c+1;M(this.view,`Moved ${a} ${a===1?"block":"blocks"}`),this.view.focus()}cancel(){this.stop(),M(this.view,"Move cancelled")}stop(){let t=this.state;t&&(this.state=null,clearTimeout(t.hold),cancelAnimationFrame(t.raf),this.grip.removeEventListener("pointermove",this.onMove),this.grip.removeEventListener("pointerup",this.onUp),this.grip.removeEventListener("pointercancel",this.onCancel),this.grip.removeEventListener("lostpointercapture",this.onCancel),this.grip.releasePointerCapture?.(t.pointer),window.removeEventListener("pointerdown",this.onOther,!0),window.removeEventListener("blur",this.onBlur),window.removeEventListener("scroll",this.onScroll,!0),window.removeEventListener("keydown",this.onKey,!0),this.shell.classList.remove("is-dragging"),delete this.shell.dataset.drop,this.line.hidden=!0)}destroy(){this.stop(),this.line.remove()}};export{g as a,et as b,G as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h as u}from"./c-J2ZW4HMR.js";import"./c-A5LASUEZ.js";import{a as d}from"./c-4JZDZFF6.js";import{b as c,e as n}from"./c-5RZNFTWD.js";import{b as s}from"./c-PKCCHJ5X.js";import{a as l,b as f}from"./c-5KXDKC5G.js";import{a,b as i}from"./c-NUHP2XDB.js";import"./c-VHNSBD2M.js";var p={error:"Couldn't save",offline:"Offline, will retry",blocked:"Can't save here",unavailable:"Can't store changes: download a copy"},x=new Set(["saving","pending","acknowledged"]),b=new Set(["saved","checkpointed"]),h=[`background:${n["ox-soft"]}`,`color:${n.ox}`,`border-color:color-mix(in srgb, ${n.ox} 28%, ${n["ox-soft"]})`],e=null;function g(){if(e&&e.isConnected)return e;let o=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;return e=u("div",["position:fixed","right:16px","bottom:16px","z-index:2147483000","padding:4px 12px",`font:500 13px/1.6 ${c}`,"opacity:0",`transition:${o?"none":"opacity .25s"}`,"pointer-events:none",`color-scheme:${d()}`]),e.setAttribute("data-clay-indicator",""),e.setAttribute("role","status"),document.body.appendChild(e),e}function r(){e&&(i(e,"opacity","0"),e.textContent="",delete e.dataset.state)}function C(){r()}function S(o,m){if(x.has(o))return;if(b.has(o))return r();if(o==="retrying"){e?.dataset.state==="error"&&r();return}if(!p[o]||o==="error"&&m?.[f])return;if(l.toasts&&o!=="blocked"){r();return}let t=g();t.textContent=p[o],t.dataset.state=o,a(t,h),s(t,{background:null}),i(t,"opacity","1")}function k(){e?.remove(),e=null}export{k as remove,S as show,C as standDown};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d}from"./c-BKM46LUJ.js";import{d as h,h as p,w as g}from"./c-
|
|
1
|
+
import{a as d}from"./c-BKM46LUJ.js";import{d as h,h as p,w as g}from"./c-3XGLJAS7.js";import{E as u,X as c,d as m,ea as f}from"./c-OH2FPYSY.js";import{b as l}from"./c-RETTCOWO.js";import"./c-VHNSBD2M.js";var{TextSelection:b}=l;function T(r,t){let e=p(r.state.doc),n=e.findIndex(o=>o.node.attrs.id===t);if(n<0)return h(r,"That link's block is gone"),null;let s=[];for(let o=e[n].up;o>=0;o=e[o].up)e[o].node.type===m.nodes.toggle&&!e[o].open&&s.push(e[o].node.attrs.id);let i=r.state.tr.setSelection(b.create(r.state.doc,e[n].at+1)).setMeta("addToHistory",!1);return r.dispatch(g(i,s).scrollIntoView()),e[n]}var a=class{constructor(t,e){this.node=t,this.view=e,this.doc=e.state.doc;let n=e.dom.ownerDocument;this.dom=n.createElement("div"),this.dom.className="blockeditor-toc",this.dom.contentEditable="false",this.dom.setAttribute("role","group"),this.dom.setAttribute("aria-label","Table of contents"),this.dom.addEventListener("mousedown",s=>{s.target.closest?.("a")&&s.preventDefault()}),this.dom.addEventListener("click",s=>{let i=s.target.closest?.("a");if(!i)return;s.preventDefault();let o=d(i.getAttribute("href"));o!==null&&T(this.view,o)}),this.render()}update(t){return this.node=t,this.view.state.doc!==this.doc&&(this.doc=this.view.state.doc,this.render()),!0}render(){let t=c(this.node.attrs,f(u(this.doc)));this.dom.innerHTML!==t&&(this.dom.innerHTML=t)}stopEvent(t){return!!t.target.closest?.("a")}ignoreMutation(){return!0}};function I(){return{id:"toc",nodeViews:{toc:(r,t)=>new a(r,t)},css:null,dispose(){}}}export{a as TocView,I as createFeature,T as followTocLink};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as M,g as _,h as A,w as q}from"./c-JWW6BHWD.js";import{C as G}from"./c-AI3H6ETU.js";import{A as B,D as R,Q as j,R as U,d as p,ea as F,u as O,x as $,z as y}from"./c-OH2FPYSY.js";import{b as z}from"./c-RETTCOWO.js";import{a as x}from"./c-WCG6AKA7.js";import{a as K}from"./c-I2SCCUEW.js";var{TextSelection:J}=z,S=new WeakMap,D=new Set;function k(n,t){let e=null;return n.forEach(s=>{s.type===p.nodes.table&&s.attrs.id===t&&(e=s)}),e}function N(n){return n?F({[n.attrs.id]:R(n)})[0]:null}function Q(n,t,e){let s=y(n.attrs.cols);if(!s.length)return null;let i=M(n),o=s.filter(a=>a!==s[0]&&i[a]==="number");return o.length?{id:B(),pos:t,parent:e,source:n.attrs.id,kind:"bar",x:s[0],series:o,title:"",highlight:null}:null}function gt(n,t){let e=n.state.doc,s=e.nodeAt(t);if(s?.type!==p.nodes.table)return!1;let i=t+s.nodeSize,o=e.maybeChild(e.resolve(i).index(0)),a=Q(s,$(s.attrs.pos,o?.attrs.pos??null),s.attrs.parent);return a?(D.add(a.id),n.dispatch(n.state.tr.insert(i,p.nodes.chart.create(a))),!0):(x("This table has no number column to chart yet."),!0)}function W(n,t,e,s){let i=n.state.tr;if(s&&i.delete(s.from,s.to),!k(i.doc,e.attrs.id)||t>=i.doc.childCount)return!1;let o=0;for(let b=0;b<t;b++)o+=i.doc.child(b).nodeSize;let a=i.doc.child(t),c=a.isTextblock&&a.content.size===0,h=i.doc.maybeChild(t+1),f=c?a.attrs.pos:$(a.attrs.pos,h?.attrs.pos??null),d=Q(e,f,a.attrs.parent??null);if(!d)return s&&n.dispatch(n.state.tr.delete(s.from,s.to)),x("This table has no number column to chart yet."),!0;let g=p.nodes.chart.create(d);return i=c?i.replaceWith(o,o+a.nodeSize,g):i.insert(o+a.nodeSize,g),D.add(d.id),n.dispatch(i.scrollIntoView()),!0}var X=n=>y(n.attrs.cols).map(t=>n.attrs.cols[t].name||"Untitled").join(", ");function wt(n,t,e=null){let s=_(n.state.doc);if(!s.length)return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),x("Add a table first: a chart plots the numbers in a table on this page."),!0;if(s.length===1)return W(n,t,s[0],e);let i=n.state.doc,o=n.nodeDOM(i.resolve(n.state.selection.head).before(1))??n.dom;return q(n,o,s.map(a=>({label:A(i,a.attrs.id)??"",description:`${a.childCount} ${a.childCount===1?"row":"rows"} \xB7 ${X(a)}`,icon:"\u25A6",run:()=>W(n,t,a,e)})))}var V=n=>`<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,Z=V('<rect x="2.5" y="3" width="11" height="10" rx="1.5"/><path d="M2.5 6.5h11M6 6.5V13"/>'),tt=V('<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>'),et=V('<path d="M2.75 4.5h10.5M6.25 4.5V2.75h3.5V4.5M4.25 4.5l.6 8.75h6.3l.6-8.75"/>'),st=[["bar","Bar"],["line","Line"],["pie","Pie"]],it="Untitled chart";function nt(n,t){let e=null;return n.forEach((s,i)=>{e===null&&s.type===p.nodes.table&&s.attrs.id===t&&(e=i)}),e}function E(n){let t=[];return n.forEach(e=>{e.type===p.nodes.table&&y(e.attrs.cols).length>1&&t.push(e)}),t.map(e=>({id:e.attrs.id,name:A(n,e.attrs.id),rows:e.childCount}))}function ot(n){let t=y(n.attrs.cols);if(!t.length)return null;let e=M(n),s=t.find(o=>e[o]!=="number")??t[0],i=t.filter(o=>o!==s&&e[o]==="number");return{x:s,series:i.length?i:t.filter(o=>o!==s).slice(0,1)}}function l(n,t,e,s=null){let i=n.createElement(t);return e&&(i.className=e),s!==null&&(i.textContent=s),i}function C(n,t,e,s=!1){let i=l(n,"option","",e);return i.value=t,i.selected=s,i}function T(n,t,e){let s=l(n,"select","blockeditor-chart-select");return s.dataset.field=t,s.setAttribute("aria-label",e),s}var Y=class{constructor(t,e,s){this.node=t,this.view=e,this.getPos=s,this.source=void 0,this.tables=null,this.frame=null,this.unsaved=null,this.titleInput=null;let i=e.dom.ownerDocument;this.doc=i,this.dom=i.createElement("figure"),this.dom.className="blockeditor-chart",this.dom.dataset.id=t.attrs.id??"",this.dom.dataset.type="chart",this.head=l(i,"div","blockeditor-chart-head"),this.head.contentEditable="false",this.title=l(i,"span","blockeditor-chart-title"),this.chip=l(i,"button","blockeditor-chart-source"),this.chip.type="button",this.chip.contentEditable="false",this.chip.setAttribute("aria-label","Go to source table"),this.chip.innerHTML=Z,this.chipName=l(i,"span","blockeditor-chart-source-name"),this.chip.append(this.chipName),this.chip.addEventListener("click",()=>this.goToSource()),this.edit=l(i,"button","blockeditor-chart-edit"),this.edit.type="button",this.edit.contentEditable="false",this.edit.setAttribute("aria-haspopup","dialog"),this.edit.setAttribute("aria-expanded","false"),this.edit.innerHTML=tt,this.edit.append("Edit chart"),this.edit.addEventListener("click",()=>this.panel.isConnected?this.closePanel(!0):this.openPanel()),this.head.append(this.title,this.chip,this.edit),this.plot=l(i,"div","blockeditor-chart-plot"),this.broken=l(i,"div","blockeditor-chart-broken"),this.broken.hidden=!0,this.broken.contentEditable="false",this.brokenKey=null,this.brokenSelect=null,this.broken.addEventListener("click",o=>this.brokenClick(o)),this.panel=l(i,"div","blockeditor-chart-panel"),this.panel.tabIndex=-1,this.panel.contentEditable="false",this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-label","Chart settings"),this.panel.addEventListener("click",o=>this.panelClick(o)),this.panel.addEventListener("change",o=>this.panelChange(o)),this.panel.addEventListener("mousedown",o=>{o.target.closest?.("button")&&o.preventDefault()}),this.outside=o=>{!this.panel.isConnected||this.dom.contains(o.target)||(this.commitTitle(),this.closePanel())},this.escape=o=>{!this.panel.isConnected||o.key!=="Escape"||(o.preventDefault(),o.stopPropagation(),this.closePanel(!0))},i.addEventListener("mousedown",this.outside,!0),i.addEventListener("keydown",this.escape,!0),this.dom.append(this.head,this.plot,this.broken),S.has(e)||S.set(e,new Set),S.get(e).add(this),this.refresh(),D.delete(t.attrs.id)&&this.openSoon()}refresh(){this.renderHead(),this.panel.isConnected&&this.panelKey()!==this.renderedKey&&this.redrawPanel();let t=this.view.state.doc,e=k(t,this.node.attrs.source),s=E(t).map(i=>`${i.id}:${i.name}:${i.rows}`).join("|");e===this.source&&s===this.tables||(this.source=e,this.tables=s,this.schedule())}schedule(){if(this.frame!==null)return;let t=this.dom.ownerDocument.defaultView,e=t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0));this.frame=e(()=>{this.frame=null,this.draw()})}draw(){let t=this.node.attrs,e=j({id:t.id,type:t.kind,x:t.x,series:t.series,title:t.title,highlight:t.highlight},N(this.source));this.plot.innerHTML=U(e,{width:640,height:320,narrow:this.dom.getBoundingClientRect().width<480}),this.renderBroken(e)}renderBroken(t){let e=t.state==="missing"&&t.reason==="table";if(this.plot.hidden=e,this.broken.hidden=!e,!e){this.brokenKey!==null&&(this.broken.textContent="",this.brokenKey=null,this.brokenSelect=null);return}let s=E(this.view.state.doc),i=s.map(h=>`${h.id}:${h.name}:${h.rows}`).join("|");if(this.brokenKey===i)return;this.brokenKey=i,this.brokenSelect=null;let o=this.doc;this.broken.textContent="",this.broken.append(l(o,"div","blockeditor-chart-broken-head","This chart's table was deleted"),l(o,"p","blockeditor-chart-broken-text","Pick another table in this document, or delete the chart. Undo brings the table back."));let a=l(o,"div","blockeditor-chart-broken-actions");if(s.length){let h=T(o,"rescue","Source table");for(let d of s)h.append(C(o,d.id,`${d.name} (${d.rows} ${d.rows===1?"row":"rows"})`));this.brokenSelect=h;let f=l(o,"button","blockeditor-chart-use","Use this table");f.type="button",f.dataset.action="use",a.append(h,f)}let c=l(o,"button","blockeditor-chart-delete","Delete chart");c.type="button",c.dataset.action="delete",a.append(c),this.broken.append(a)}brokenClick(t){let e=t.target.closest?.("button[data-action]");e&&(e.dataset.action==="delete"?this.removeChart():e.dataset.action==="use"&&this.switchSource(this.brokenSelect?.value??""))}openSoon(){let t=this.dom.ownerDocument.defaultView;(t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0)))(()=>{!this.view.isDestroyed&&this.dom.isConnected&&this.openPanel()})}renderHead(){let t=this.node.attrs,e=A(this.view.state.doc,t.source),s=!k(this.view.state.doc,t.source);this.title.textContent=t.title||it,this.title.classList.toggle("is-empty",!t.title),this.chipName.textContent=s?"No table":e??"",this.chip.disabled=s}setAttrs(t){let e=this.getPos();if(e==null)return;let s=this.view.state.doc.nodeAt(e);s?.type===p.nodes.chart&&this.view.dispatch(this.view.state.tr.setNodeMarkup(e,null,{...s.attrs,...t}))}row(t,...e){let s=l(this.doc,"div","blockeditor-chart-row");return t&&s.append(l(this.doc,"span","blockeditor-chart-label",t)),s.append(...e),s}panelKey(){let t=this.view.state.doc,e=E(t).map(s=>`${s.id}:${s.name}:${s.rows}`).join("|");return JSON.stringify([this.node.attrs,e,N(k(t,this.node.attrs.source))])}redrawPanel(){let t=this.doc.activeElement,e=t&&this.panel.contains(t)?t.dataset??{}:null,s=this.titleInput,i=s&&s.value!==this.renderedTitle?{value:s.value,start:s.selectionStart,end:s.selectionEnd}:null;if(this.renderPanel(),i&&this.titleInput&&(this.titleInput.value=i.value),!e)return;let o=[...this.panel.querySelectorAll("button, input, select")].find(a=>["field","kind","col","action"].every(c=>a.dataset[c]===e[c]));if(!o)return this.panel.focus();o.focus(),i&&o===this.titleInput&&o.setSelectionRange?.(i.start,i.end)}renderPanel(){let t=this.doc;this.renderedKey=this.panelKey(),this.renderedTitle=this.node.attrs.title??"";let e=this.node.attrs,s=N(this.source),i=s?.cols??[],o=s?.rows??[],a=e.kind==="pie";this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.textContent="";let c=l(t,"div","blockeditor-chart-types");for(let[r,P]of st){let m=l(t,"button","blockeditor-chart-type",P);m.type="button",m.dataset.kind=r,m.setAttribute("aria-pressed",String(e.kind===r)),c.append(m)}this.panel.append(this.row("Chart type",c));let h=T(t,"source","Source table");for(let r of E(this.view.state.doc))h.append(C(t,r.id,`${r.name} (${r.rows} ${r.rows===1?"row":"rows"})`,r.id===e.source));this.panel.append(this.row("Source table",h));let f=T(t,"labels","Labels column");for(let r of i)f.append(C(t,r.id,r.name||r.id,r.id===e.x));this.panel.append(this.row("Labels column",f));let d=l(t,"div","blockeditor-chart-values");i.filter(r=>r.id!==e.x).forEach((r,P)=>{let m=l(t,"label","blockeditor-chart-value"),v=l(t,"input");v.type="checkbox",v.dataset.field="series",v.dataset.col=r.id,v.checked=e.series.includes(r.id);let I=l(t,"span","blockeditor-chart-swatch");I.style.background=`var(--chart-${P%6+1})`,I.setAttribute("aria-hidden","true"),m.append(v,I,l(t,"span","blockeditor-chart-value-name",r.name||r.id)),d.append(m)});let g=this.row(a?"Value column":"Value columns",d);a&&g.append(l(t,"span","blockeditor-chart-hint","Pie charts plot the first value column across rows.")),this.panel.append(g);let b=T(t,"highlight","Highlight row");b.append(C(t,"","None",!e.highlight));for(let r of o)b.append(C(t,r.id,O(r.cells?.[e.x])||r.id,r.id===e.highlight));this.panel.append(this.row("Highlight row",b));let u=l(t,"input","blockeditor-chart-title-input");u.type="text",u.dataset.field="title",u.setAttribute("aria-label","Chart title"),u.value=e.title??"",u.addEventListener("keydown",r=>{r.isComposing||r.keyCode===229||r.key==="Enter"&&(r.preventDefault(),r.stopPropagation(),this.commitTitle())}),u.addEventListener("change",()=>this.commitTitle()),u.addEventListener("blur",()=>this.commitTitle()),this.titleInput=u,this.panel.append(this.row("Chart title",u));let H=l(t,"div","blockeditor-chart-foot"),w=l(t,"button","blockeditor-chart-remove");w.type="button",w.dataset.action="remove",w.innerHTML=et,w.append("Remove");let L=l(t,"button","blockeditor-chart-done","Done");L.type="button",L.dataset.action="done",H.append(w,L),this.panel.append(H),this.unsaved=K({id:"chart-title",isPending:()=>u.isConnected&&u.value!==(this.node.attrs.title??"")})}openPanel(){this.panel.isConnected||(this.renderPanel(),this.dom.append(this.panel),this.edit.setAttribute("aria-expanded","true"),this.panel.focus())}closePanel(t=!1){this.panel.isConnected&&(this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.remove(),this.edit.setAttribute("aria-expanded","false"),t&&this.edit.focus())}panelClick(t){let e=t.target.closest?.("button");e&&(e.dataset.action==="done"?(this.commitTitle(),this.closePanel(!0)):e.dataset.action==="remove"?this.removeChart():e.dataset.kind&&this.setAttrs({kind:e.dataset.kind}))}panelChange(t){let e=t.target;if(e?.dataset){if(e.dataset.field==="source")this.switchSource(e.value);else if(e.dataset.field==="labels")this.setAttrs({x:e.value,series:this.node.attrs.series.filter(s=>s!==e.value)});else if(e.dataset.field==="highlight")this.setAttrs({highlight:e.value||null});else if(e.dataset.field==="series"){let s=this.node.attrs.series.filter(i=>i!==e.dataset.col);this.setAttrs({series:e.checked?[...s,e.dataset.col]:s})}}}switchSource(t){let e=k(this.view.state.doc,t),s=e?ot(e):null;s&&this.setAttrs({source:t,x:s.x,series:s.series})}commitTitle(){let t=this.titleInput;!t||t.value===(this.node.attrs.title??"")||this.setAttrs({title:t.value})}goToSource(){let t=this.view.state.doc,e=nt(t,this.node.attrs.source),s=e===null?null:t.nodeAt(e);if(!s?.childCount||!s.child(0).childCount)return;let i=e+3;this.view.dispatch(this.view.state.tr.setSelection(J.create(t,i)).scrollIntoView()),this.view.focus?.()}removeChart(){let t=this.getPos();if(t==null)return;let e=this.view.state.doc.nodeAt(t);if(e?.type!==p.nodes.chart)return;this.closePanel();let s=this.view.state.tr.delete(t,t+e.nodeSize);s.setSelection(J.near(s.doc.resolve(Math.min(t,s.doc.content.size)),-1)),this.view.dispatch(G(s).scrollIntoView())}update(t){if(t.type!==p.nodes.chart)return!1;let e=!t.sameMarkup(this.node);return this.node=t,this.dom.dataset.id=t.attrs.id??"",e&&(this.source=k(this.view.state.doc,t.attrs.source),this.renderHead(),this.schedule()),!0}stopEvent(t){return!!t.target.closest?.(".blockeditor-chart-head, .blockeditor-chart-panel")}destroy(){if(this.unsaved?.dispose(),this.unsaved=null,this.doc.removeEventListener("mousedown",this.outside,!0),this.doc.removeEventListener("keydown",this.escape,!0),S.get(this.view)?.delete(this),this.frame!==null){let t=this.dom.ownerDocument.defaultView;t.cancelAnimationFrame?t.cancelAnimationFrame(this.frame):t.clearTimeout(this.frame)}}};function vt(n){for(let t of S.get(n)??[])t.refresh()}export{gt as a,X as b,wt as c,Y as d,vt as e};
|
|
1
|
+
import{c as M,g as _,h as A,x as q}from"./c-WHMZCRQD.js";import{C as G}from"./c-3XGLJAS7.js";import{A as B,D as R,Q as j,R as U,d as p,ea as F,u as O,x as $,z as y}from"./c-OH2FPYSY.js";import{b as z}from"./c-RETTCOWO.js";import{a as x}from"./c-JC4RZW4E.js";import{a as K}from"./c-I2SCCUEW.js";var{TextSelection:J}=z,S=new WeakMap,D=new Set;function k(n,t){let e=null;return n.forEach(s=>{s.type===p.nodes.table&&s.attrs.id===t&&(e=s)}),e}function N(n){return n?F({[n.attrs.id]:R(n)})[0]:null}function Q(n,t,e){let s=y(n.attrs.cols);if(!s.length)return null;let i=M(n),o=s.filter(a=>a!==s[0]&&i[a]==="number");return o.length?{id:B(),pos:t,parent:e,source:n.attrs.id,kind:"bar",x:s[0],series:o,title:"",highlight:null}:null}function gt(n,t){let e=n.state.doc,s=e.nodeAt(t);if(s?.type!==p.nodes.table)return!1;let i=t+s.nodeSize,o=e.maybeChild(e.resolve(i).index(0)),a=Q(s,$(s.attrs.pos,o?.attrs.pos??null),s.attrs.parent);return a?(D.add(a.id),n.dispatch(n.state.tr.insert(i,p.nodes.chart.create(a))),!0):(x("This table has no number column to chart yet."),!0)}function W(n,t,e,s){let i=n.state.tr;if(s&&i.delete(s.from,s.to),!k(i.doc,e.attrs.id)||t>=i.doc.childCount)return!1;let o=0;for(let b=0;b<t;b++)o+=i.doc.child(b).nodeSize;let a=i.doc.child(t),c=a.isTextblock&&a.content.size===0,h=i.doc.maybeChild(t+1),f=c?a.attrs.pos:$(a.attrs.pos,h?.attrs.pos??null),d=Q(e,f,a.attrs.parent??null);if(!d)return s&&n.dispatch(n.state.tr.delete(s.from,s.to)),x("This table has no number column to chart yet."),!0;let g=p.nodes.chart.create(d);return i=c?i.replaceWith(o,o+a.nodeSize,g):i.insert(o+a.nodeSize,g),D.add(d.id),n.dispatch(i.scrollIntoView()),!0}var X=n=>y(n.attrs.cols).map(t=>n.attrs.cols[t].name||"Untitled").join(", ");function wt(n,t,e=null){let s=_(n.state.doc);if(!s.length)return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),x("Add a table first: a chart plots the numbers in a table on this page."),!0;if(s.length===1)return W(n,t,s[0],e);let i=n.state.doc,o=n.nodeDOM(i.resolve(n.state.selection.head).before(1))??n.dom;return q(n,o,s.map(a=>({label:A(i,a.attrs.id)??"",description:`${a.childCount} ${a.childCount===1?"row":"rows"} \xB7 ${X(a)}`,icon:"\u25A6",run:()=>W(n,t,a,e)})))}var V=n=>`<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,Z=V('<rect x="2.5" y="3" width="11" height="10" rx="1.5"/><path d="M2.5 6.5h11M6 6.5V13"/>'),tt=V('<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>'),et=V('<path d="M2.75 4.5h10.5M6.25 4.5V2.75h3.5V4.5M4.25 4.5l.6 8.75h6.3l.6-8.75"/>'),st=[["bar","Bar"],["line","Line"],["pie","Pie"]],it="Untitled chart";function nt(n,t){let e=null;return n.forEach((s,i)=>{e===null&&s.type===p.nodes.table&&s.attrs.id===t&&(e=i)}),e}function E(n){let t=[];return n.forEach(e=>{e.type===p.nodes.table&&y(e.attrs.cols).length>1&&t.push(e)}),t.map(e=>({id:e.attrs.id,name:A(n,e.attrs.id),rows:e.childCount}))}function ot(n){let t=y(n.attrs.cols);if(!t.length)return null;let e=M(n),s=t.find(o=>e[o]!=="number")??t[0],i=t.filter(o=>o!==s&&e[o]==="number");return{x:s,series:i.length?i:t.filter(o=>o!==s).slice(0,1)}}function l(n,t,e,s=null){let i=n.createElement(t);return e&&(i.className=e),s!==null&&(i.textContent=s),i}function C(n,t,e,s=!1){let i=l(n,"option","",e);return i.value=t,i.selected=s,i}function T(n,t,e){let s=l(n,"select","blockeditor-chart-select");return s.dataset.field=t,s.setAttribute("aria-label",e),s}var Y=class{constructor(t,e,s){this.node=t,this.view=e,this.getPos=s,this.source=void 0,this.tables=null,this.frame=null,this.unsaved=null,this.titleInput=null;let i=e.dom.ownerDocument;this.doc=i,this.dom=i.createElement("figure"),this.dom.className="blockeditor-chart",this.dom.dataset.id=t.attrs.id??"",this.dom.dataset.type="chart",this.head=l(i,"div","blockeditor-chart-head"),this.head.contentEditable="false",this.title=l(i,"span","blockeditor-chart-title"),this.chip=l(i,"button","blockeditor-chart-source"),this.chip.type="button",this.chip.contentEditable="false",this.chip.setAttribute("aria-label","Go to source table"),this.chip.innerHTML=Z,this.chipName=l(i,"span","blockeditor-chart-source-name"),this.chip.append(this.chipName),this.chip.addEventListener("click",()=>this.goToSource()),this.edit=l(i,"button","blockeditor-chart-edit"),this.edit.type="button",this.edit.contentEditable="false",this.edit.setAttribute("aria-haspopup","dialog"),this.edit.setAttribute("aria-expanded","false"),this.edit.innerHTML=tt,this.edit.append("Edit chart"),this.edit.addEventListener("click",()=>this.panel.isConnected?this.closePanel(!0):this.openPanel()),this.head.append(this.title,this.chip,this.edit),this.plot=l(i,"div","blockeditor-chart-plot"),this.broken=l(i,"div","blockeditor-chart-broken"),this.broken.hidden=!0,this.broken.contentEditable="false",this.brokenKey=null,this.brokenSelect=null,this.broken.addEventListener("click",o=>this.brokenClick(o)),this.panel=l(i,"div","blockeditor-chart-panel"),this.panel.tabIndex=-1,this.panel.contentEditable="false",this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-label","Chart settings"),this.panel.addEventListener("click",o=>this.panelClick(o)),this.panel.addEventListener("change",o=>this.panelChange(o)),this.panel.addEventListener("mousedown",o=>{o.target.closest?.("button")&&o.preventDefault()}),this.outside=o=>{!this.panel.isConnected||this.dom.contains(o.target)||(this.commitTitle(),this.closePanel())},this.escape=o=>{!this.panel.isConnected||o.key!=="Escape"||(o.preventDefault(),o.stopPropagation(),this.closePanel(!0))},i.addEventListener("mousedown",this.outside,!0),i.addEventListener("keydown",this.escape,!0),this.dom.append(this.head,this.plot,this.broken),S.has(e)||S.set(e,new Set),S.get(e).add(this),this.refresh(),D.delete(t.attrs.id)&&this.openSoon()}refresh(){this.renderHead(),this.panel.isConnected&&this.panelKey()!==this.renderedKey&&this.redrawPanel();let t=this.view.state.doc,e=k(t,this.node.attrs.source),s=E(t).map(i=>`${i.id}:${i.name}:${i.rows}`).join("|");e===this.source&&s===this.tables||(this.source=e,this.tables=s,this.schedule())}schedule(){if(this.frame!==null)return;let t=this.dom.ownerDocument.defaultView,e=t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0));this.frame=e(()=>{this.frame=null,this.draw()})}draw(){let t=this.node.attrs,e=j({id:t.id,type:t.kind,x:t.x,series:t.series,title:t.title,highlight:t.highlight},N(this.source));this.plot.innerHTML=U(e,{width:640,height:320,narrow:this.dom.getBoundingClientRect().width<480}),this.renderBroken(e)}renderBroken(t){let e=t.state==="missing"&&t.reason==="table";if(this.plot.hidden=e,this.broken.hidden=!e,!e){this.brokenKey!==null&&(this.broken.textContent="",this.brokenKey=null,this.brokenSelect=null);return}let s=E(this.view.state.doc),i=s.map(h=>`${h.id}:${h.name}:${h.rows}`).join("|");if(this.brokenKey===i)return;this.brokenKey=i,this.brokenSelect=null;let o=this.doc;this.broken.textContent="",this.broken.append(l(o,"div","blockeditor-chart-broken-head","This chart's table was deleted"),l(o,"p","blockeditor-chart-broken-text","Pick another table in this document, or delete the chart. Undo brings the table back."));let a=l(o,"div","blockeditor-chart-broken-actions");if(s.length){let h=T(o,"rescue","Source table");for(let d of s)h.append(C(o,d.id,`${d.name} (${d.rows} ${d.rows===1?"row":"rows"})`));this.brokenSelect=h;let f=l(o,"button","blockeditor-chart-use","Use this table");f.type="button",f.dataset.action="use",a.append(h,f)}let c=l(o,"button","blockeditor-chart-delete","Delete chart");c.type="button",c.dataset.action="delete",a.append(c),this.broken.append(a)}brokenClick(t){let e=t.target.closest?.("button[data-action]");e&&(e.dataset.action==="delete"?this.removeChart():e.dataset.action==="use"&&this.switchSource(this.brokenSelect?.value??""))}openSoon(){let t=this.dom.ownerDocument.defaultView;(t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0)))(()=>{!this.view.isDestroyed&&this.dom.isConnected&&this.openPanel()})}renderHead(){let t=this.node.attrs,e=A(this.view.state.doc,t.source),s=!k(this.view.state.doc,t.source);this.title.textContent=t.title||it,this.title.classList.toggle("is-empty",!t.title),this.chipName.textContent=s?"No table":e??"",this.chip.disabled=s}setAttrs(t){let e=this.getPos();if(e==null)return;let s=this.view.state.doc.nodeAt(e);s?.type===p.nodes.chart&&this.view.dispatch(this.view.state.tr.setNodeMarkup(e,null,{...s.attrs,...t}))}row(t,...e){let s=l(this.doc,"div","blockeditor-chart-row");return t&&s.append(l(this.doc,"span","blockeditor-chart-label",t)),s.append(...e),s}panelKey(){let t=this.view.state.doc,e=E(t).map(s=>`${s.id}:${s.name}:${s.rows}`).join("|");return JSON.stringify([this.node.attrs,e,N(k(t,this.node.attrs.source))])}redrawPanel(){let t=this.doc.activeElement,e=t&&this.panel.contains(t)?t.dataset??{}:null,s=this.titleInput,i=s&&s.value!==this.renderedTitle?{value:s.value,start:s.selectionStart,end:s.selectionEnd}:null;if(this.renderPanel(),i&&this.titleInput&&(this.titleInput.value=i.value),!e)return;let o=[...this.panel.querySelectorAll("button, input, select")].find(a=>["field","kind","col","action"].every(c=>a.dataset[c]===e[c]));if(!o)return this.panel.focus();o.focus(),i&&o===this.titleInput&&o.setSelectionRange?.(i.start,i.end)}renderPanel(){let t=this.doc;this.renderedKey=this.panelKey(),this.renderedTitle=this.node.attrs.title??"";let e=this.node.attrs,s=N(this.source),i=s?.cols??[],o=s?.rows??[],a=e.kind==="pie";this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.textContent="";let c=l(t,"div","blockeditor-chart-types");for(let[r,P]of st){let m=l(t,"button","blockeditor-chart-type",P);m.type="button",m.dataset.kind=r,m.setAttribute("aria-pressed",String(e.kind===r)),c.append(m)}this.panel.append(this.row("Chart type",c));let h=T(t,"source","Source table");for(let r of E(this.view.state.doc))h.append(C(t,r.id,`${r.name} (${r.rows} ${r.rows===1?"row":"rows"})`,r.id===e.source));this.panel.append(this.row("Source table",h));let f=T(t,"labels","Labels column");for(let r of i)f.append(C(t,r.id,r.name||r.id,r.id===e.x));this.panel.append(this.row("Labels column",f));let d=l(t,"div","blockeditor-chart-values");i.filter(r=>r.id!==e.x).forEach((r,P)=>{let m=l(t,"label","blockeditor-chart-value"),v=l(t,"input");v.type="checkbox",v.dataset.field="series",v.dataset.col=r.id,v.checked=e.series.includes(r.id);let I=l(t,"span","blockeditor-chart-swatch");I.style.background=`var(--chart-${P%6+1})`,I.setAttribute("aria-hidden","true"),m.append(v,I,l(t,"span","blockeditor-chart-value-name",r.name||r.id)),d.append(m)});let g=this.row(a?"Value column":"Value columns",d);a&&g.append(l(t,"span","blockeditor-chart-hint","Pie charts plot the first value column across rows.")),this.panel.append(g);let b=T(t,"highlight","Highlight row");b.append(C(t,"","None",!e.highlight));for(let r of o)b.append(C(t,r.id,O(r.cells?.[e.x])||r.id,r.id===e.highlight));this.panel.append(this.row("Highlight row",b));let u=l(t,"input","blockeditor-chart-title-input");u.type="text",u.dataset.field="title",u.setAttribute("aria-label","Chart title"),u.value=e.title??"",u.addEventListener("keydown",r=>{r.isComposing||r.keyCode===229||r.key==="Enter"&&(r.preventDefault(),r.stopPropagation(),this.commitTitle())}),u.addEventListener("change",()=>this.commitTitle()),u.addEventListener("blur",()=>this.commitTitle()),this.titleInput=u,this.panel.append(this.row("Chart title",u));let H=l(t,"div","blockeditor-chart-foot"),w=l(t,"button","blockeditor-chart-remove");w.type="button",w.dataset.action="remove",w.innerHTML=et,w.append("Remove");let L=l(t,"button","blockeditor-chart-done","Done");L.type="button",L.dataset.action="done",H.append(w,L),this.panel.append(H),this.unsaved=K({id:"chart-title",isPending:()=>u.isConnected&&u.value!==(this.node.attrs.title??"")})}openPanel(){this.panel.isConnected||(this.renderPanel(),this.dom.append(this.panel),this.edit.setAttribute("aria-expanded","true"),this.panel.focus())}closePanel(t=!1){this.panel.isConnected&&(this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.remove(),this.edit.setAttribute("aria-expanded","false"),t&&this.edit.focus())}panelClick(t){let e=t.target.closest?.("button");e&&(e.dataset.action==="done"?(this.commitTitle(),this.closePanel(!0)):e.dataset.action==="remove"?this.removeChart():e.dataset.kind&&this.setAttrs({kind:e.dataset.kind}))}panelChange(t){let e=t.target;if(e?.dataset){if(e.dataset.field==="source")this.switchSource(e.value);else if(e.dataset.field==="labels")this.setAttrs({x:e.value,series:this.node.attrs.series.filter(s=>s!==e.value)});else if(e.dataset.field==="highlight")this.setAttrs({highlight:e.value||null});else if(e.dataset.field==="series"){let s=this.node.attrs.series.filter(i=>i!==e.dataset.col);this.setAttrs({series:e.checked?[...s,e.dataset.col]:s})}}}switchSource(t){let e=k(this.view.state.doc,t),s=e?ot(e):null;s&&this.setAttrs({source:t,x:s.x,series:s.series})}commitTitle(){let t=this.titleInput;!t||t.value===(this.node.attrs.title??"")||this.setAttrs({title:t.value})}goToSource(){let t=this.view.state.doc,e=nt(t,this.node.attrs.source),s=e===null?null:t.nodeAt(e);if(!s?.childCount||!s.child(0).childCount)return;let i=e+3;this.view.dispatch(this.view.state.tr.setSelection(J.create(t,i)).scrollIntoView()),this.view.focus?.()}removeChart(){let t=this.getPos();if(t==null)return;let e=this.view.state.doc.nodeAt(t);if(e?.type!==p.nodes.chart)return;this.closePanel();let s=this.view.state.tr.delete(t,t+e.nodeSize);s.setSelection(J.near(s.doc.resolve(Math.min(t,s.doc.content.size)),-1)),this.view.dispatch(G(s).scrollIntoView())}update(t){if(t.type!==p.nodes.chart)return!1;let e=!t.sameMarkup(this.node);return this.node=t,this.dom.dataset.id=t.attrs.id??"",e&&(this.source=k(this.view.state.doc,t.attrs.source),this.renderHead(),this.schedule()),!0}stopEvent(t){return!!t.target.closest?.(".blockeditor-chart-head, .blockeditor-chart-panel")}destroy(){if(this.unsaved?.dispose(),this.unsaved=null,this.doc.removeEventListener("mousedown",this.outside,!0),this.doc.removeEventListener("keydown",this.escape,!0),S.get(this.view)?.delete(this),this.frame!==null){let t=this.dom.ownerDocument.defaultView;t.cancelAnimationFrame?t.cancelAnimationFrame(this.frame):t.clearTimeout(this.frame)}}};function vt(n){for(let t of S.get(n)??[])t.refresh()}export{gt as a,X as b,wt as c,Y as d,vt as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as A,b as a,c as n}from"./c-QCDVDZIR.js";import{a as c}from"./c-VKEDWYDF.js";import{f as i}from"./c-C7SUMNMI.js";import{b as l,r as d}from"./c-UW6MMZ4V.js";var m="[editmode\\:onclick]";function b(){d(o=>{o.querySelectorAll(m).forEach(e=>{let t=e.getAttribute("onclick");t!==null&&(e.setAttribute("inert-onclick",t),e.removeAttribute("onclick"),n(e,l(e)??e))})},{required:!0})}function p(){i&&c(()=>{E()})}function E(o=document){o.querySelectorAll(m).forEach(e=>{let t=e.getAttribute("inert-onclick");t&&(e.setAttribute("onclick",t),e.removeAttribute("inert-onclick"))})}function C(){document.querySelectorAll(m).forEach(o=>{let e=o.getAttribute("onclick");e&&(o.setAttribute("inert-onclick",e),o.removeAttribute("onclick")),n(o)})}function D(){b(),p()}var O="[viewmode\\:disabled]",S="[viewmode\\:readonly]",f=[[O,"disabled"],[S,"readonly"]];function k(){d(o=>{for(let[e,t]of f)o.querySelectorAll(e).forEach(r=>{if(r.hasAttribute(t))return;let u=l(r),s=u?a(u,t):null;r.setAttribute(t,s===null?"":s),n(r,u??r)})},{required:!0})}function h(){i&&c(()=>{x()})}function x(o=document){for(let[e,t]of f)o.querySelectorAll(e).forEach(r=>{A(r),r.removeAttribute(t)})}function M(){for(let[o,e]of f)document.querySelectorAll(o).forEach(t=>{let r=a(t,e);r===null?t.removeAttribute(e):t.setAttribute(e,r),n(t)})}function P(){k(),h()}export{m as a,E as b,C as c,D as d,O as e,S as f,x as g,M as h,P as i};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as me,b as pe,c as he}from"./c-SIM7Z3U7.js";import{a as de,b as fe}from"./c-OYW5MFPZ.js";import{a as F,b as U,c as ue}from"./c-H3FNLBHN.js";import{C as X,E as le,h as z,l as ce,m as Y}from"./c-AI3H6ETU.js";import{A as se,d as N,x as oe}from"./c-OH2FPYSY.js";import"./c-VPXCXBDT.js";import{b as $,c as ae,d as R}from"./c-Z6MROEQ4.js";import{b as ie}from"./c-Q26XHBLQ.js";import{a as H,b as V}from"./c-RETTCOWO.js";import{a as re}from"./c-3LDGIBMN.js";import"./c-VHNSBD2M.js";var ge=16384,we=i=>new TextEncoder().encode(JSON.stringify(i)).length,G=class extends Error{constructor(n,t=n){super(t),this.name="ToolRequestError",this.code=n}};function Oe(i){let n=re(i);for(Array.isArray(n.tables)||(n.tables=[]),Array.isArray(n.outline)||(n.outline=[]);we(n)>ge;){let t=[...n.tables].reverse().find(r=>Array.isArray(r.rows)&&r.rows.length);if(t)t.rows.pop();else if(n.outline.length)n.outline.pop();else break}if(we(n)>ge)throw new G("context-too-large");return n}var Me=()=>globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;function ve({transport:i,newId:n=Me}){let t=null,r=s=>{!s||s.discarded||s.done||(s.discarded=!0,t===s&&(t=null),i.cancel(s.requestId),s.resolve({requestId:s.requestId,code:"discarded",message:"Candidate discarded"}))};return{request(s,a,v=null,h=null){let o=Oe(a);t&&r(t);let m=n(),l={requestId:m,discarded:!1,done:!1};l.promise=new Promise(u=>{l.resolve=u}),t=l;let e={protocol:"blockeditor-tool/1",requestId:m,prompt:s,context:o,target:v,current:h};l.request=e;let f=u=>{if(!(l.discarded||l.done||u?.requestId!==m))if(l.done=!0,t===l&&(t=null),u?.artifact!==void 0){let g=F(u.artifact),d=U(u.state),p=g.ok?d.ok?null:d:g;l.resolve(p?{requestId:m,code:p.code,message:p.code}:u)}else l.resolve(typeof u?.code=="string"?u:{requestId:m,code:"invalid-result",message:"invalid-result"})};try{let u=g=>f({requestId:m,code:typeof g?.code=="string"?g.code:"transport-error",message:String(g?.message??g)});Promise.resolve(i.request(e)).then(f,u)}catch(u){f({requestId:m,code:typeof u?.code=="string"?u.code:"transport-error",message:String(u?.message??u)})}return l},discard:r,async wait(s,{signal:a}={}){if(a?.aborted)throw new DOMException("Aborted","AbortError");let v,h=await(a?Promise.race([s.promise,new Promise((o,m)=>{v=()=>m(new DOMException("Aborted","AbortError")),a.addEventListener("abort",v,{once:!0})})]).finally(()=>a.removeEventListener("abort",v)):s.promise);if(h?.code)throw new G(h.code,h.message);return h}}}var J=class extends Error{constructor(n){super(n),this.name="ToolTransportError",this.code=n}};function ye({getWire:i=()=>globalThis.window?.clay?.wire??null}={}){let n=new Map;return{request(t,{onStatus:r=null}={}){let s=i();if(!s||typeof s.send!="function")return Promise.reject(new J("no-wire"));let a=t?.requestId,v;try{v=s.send(t,{helper:"blockeditor-tool",document:"none",id:a,onStatus:r})}catch{return Promise.reject(new J("no-wire"))}return n.set(a,v),Promise.resolve(v.done).then(h=>{if(n.get(a)===v&&n.delete(a),h?.state==="done"){let o=h.result??{};return{requestId:typeof o.requestId=="string"?o.requestId:a,artifact:o.artifact,state:o.state,model:o.model}}return{requestId:a,code:h?.errorCode||(h?.state==="cancelled"?"cancelled":"transport-error"),message:h?.error||"the helper reported an error"}},()=>({requestId:a,code:"transport-error",message:"the helper reported an error"}))},cancel(t){let r=n.get(t);n.delete(t),r?.cancel?.()}}}var{Selection:Be}=V,W="This page is not open for editing any more.",Ie="AI tool making isn't available on this page right now.",Te="This document can't save tool data.",K="The place for this tool moved. Close this and run /ai where you want the tool.",be="This tool changed while you were revising, so nothing was replaced. Ask again.",Q="AI did not make a usable tool. Try again.",Ne="The tool data from AI is too large or not usable. Try again.",xe="This tool's data changed while AI was working, so it was not replaced. Ask again to include the latest data.",Ae="The tool could not be saved, so it was not added. Try again.",Re="Your tool is in the document, but saving failed. It will be saved with your next edit.";function _(i,n){let t=null;return i.forEach((r,s,a)=>{r.attrs.id===n&&(t={node:r,at:s,index:a})}),t}function Pe(i,n){let t=i.selection.$head,r=Math.min(Math.max(t.index(0),0),i.doc.childCount-1);return{hostId:i.doc.child(r)?.attrs.id??null,slashText:n?i.doc.textBetween(n.from,n.to):null,slashOffset:n&&t.depth?n.from-t.before(1)-1:null}}function Z(i,n){let t=n?.hostId?_(i.doc,n.hostId):null;if(!t)return null;let r=i.doc.maybeChild(t.index+1),s=t.node.isTextblock&&(t.node.content.size===0||t.node.textContent===n.slashText);return{...t,replace:s,pos:s?t.node.attrs.pos:oe(t.node.attrs.pos,r?.attrs.pos??null),insertAt:s?t.at:t.at+t.node.nodeSize}}function _e(i,n,t){let r=i.state,s=Z(r,t);if(!s)return!1;let{node:a,at:v,insertAt:h,replace:o}=s,m=N.nodes.tool.create({id:n.id,pos:s.pos,parent:a.attrs.parent??null,artifact:n.artifact,rev:n.rev,state:n.state}),l=r.tr;if(!o&&t?.hostId===a.attrs.id&&t.slashText&&t.slashOffset>=0){let f=v+1+t.slashOffset,u=f+t.slashText.length;u<=v+a.nodeSize-1&&r.doc.textBetween(f,u)===t.slashText&&l.delete(f,u)}let e=l.mapping.map(h);return l.replaceWith(e,o?l.mapping.map(v+a.nodeSize):e,m),l.setSelection(Be.near(l.doc.resolve(Math.min(e+m.nodeSize,l.doc.content.size)))),i.dispatch(X(l).scrollIntoView()),!0}var Se=()=>({x:0,y:0,left:0,top:0,right:0,bottom:0,width:0,height:0});function Ee({getView:i,store:n=()=>null,acceptState:t=()=>globalThis.clay?.save?.flush?.(),newId:r=se,transport:s=ye()}={}){let a=()=>{let e=i();return e&&!e.isDestroyed?e:null},v=()=>typeof n=="function"?n():n,h=(e,f)=>{let u=v()?.data?.[e]?.[f];return u===void 0?{}:u},o=new Map,m=e=>Array.isArray(e)?`[${e.map(m).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).sort().map(u=>`${JSON.stringify(u)}:${m(e[u])}`).join(",")}}`:JSON.stringify(e)??"null";function l(e=null,f=null){let u=a(),g=e||!u?null:Pe(u.state,f),d=null,p=ve({transport:{request:c=>s.request(c,{onStatus:T=>d?.(T)}),cancel:c=>s.cancel(c)}}),b=null,w=null,y=null,M=!1,k=null,O=null,C=()=>{y?.host?.dispose(),y=null},L=()=>{let c=a();return c&&e?ie.get(c)?.get(e)??null:null},j=()=>L()?.suspend(),B=()=>L()?.resume(),q=c=>{M=!1;let T=a();return C(),T&&R(T),B(),{status:"failed",message:c}},ne={aiTarget:!0,label:e?"This tool":"New tool",ref:e?[e]:[],placeholder:e?"What should change?":"Describe the tool",get isConnected(){let c=a();return c?e?!!_(c.state.doc,e):!0:!1},getBoundingClientRect(){let c=a();if(!c)return Se();if(y)return y.dom.getBoundingClientRect();let T=e??g?.hostId,A=T?_(c.state.doc,T):null,E=A?c.nodeDOM(A.at):null;return E&&typeof E.getBoundingClientRect=="function"?E.getBoundingClientRect():Se()},async start(c){w=null,M=!1;let T=a();if(!T)return{status:"refused",code:"gone",message:W};if(!globalThis.window?.clay?.wire)return{status:"refused",code:"no-wire",message:Ie};let A=null,E=null;if(e){let x=_(T.state.doc,e);if(x?.node.type!==N.nodes.tool)return{status:"refused",code:"gone",message:W};k=x.node.attrs.rev,A={toolId:e,rev:k},j(),E={artifact:x.node.attrs.artifact,state:h(e,k)},O=m(E.state)}return b=p.request(c,fe(T.state.doc,T.dom.ownerDocument.title),A,E),{status:"ok",id:b.requestId,send:(x={})=>(d=typeof x.onStatus=="function"?x.onStatus:null,{done:p.wait(b).then(S=>(w={id:e,rev:null,artifact:S.artifact,state:S.state},{state:"done",result:S}),S=>(B(),{state:"error",error:S?.message||S?.code||"the helper reported an error",code:S?.code??null})),cancel:()=>{B(),p.discard(b)}})}},async propose(c){let T=a();if(!T||!c)return{status:"refused",message:W};if(!F(c.artifact).ok)return{status:"refused",message:Q};if(!U(c.state).ok)return{status:"refused",message:Ne};w={id:e,rev:null,artifact:c.artifact,state:c.state};let x=De(T);return x.status!=="ready"&&(w=null),x},async keep(){if(!w||M)return q(be);let c=a();if(!c)return q(W);let T=v();if(!T)return q(Te);let A=()=>e&&O!==null&&m(h(e,k))!==O;if(A())return q(xe);M=!0;let E=w.id??r("b"),x=r("rev"),I={...w,id:E,rev:x};try{await T.set([E,x],I.state)}catch(D){return q(D?.message??Te)}let S=null;try{S=await t()}catch{return q(Ae)}if(S?.ok!==!0&&!["saved","clean"].includes(S?.state))return q(S?.msg??S?.message??Ae);if(e){let D=_(c.state.doc,e);if(D?.node.type!==N.nodes.tool||D.node.attrs.rev!==k)return q(be)}else if(!Z(c.state,g))return q(K);if(A())return q(xe);if(C(),R(c),e){let D=_(c.state.doc,e);c.dispatch(X(c.state.tr.setNodeMarkup(D.at,null,{...D.node.attrs,artifact:I.artifact,rev:I.rev})))}else if(!_e(c,I,g))return q(K);let P=!1;for(let D=0;D<2&&!P;D++)try{P=(await t())?.ok!==!1}catch{P=!1}return P?(o.delete(e??"new"),{status:"kept"}):{status:"failed",message:Re}},discard(){C();let c=a();c&&R(c),p.discard(b),B(),o.delete(e??"new")}};function De(c){C();let T=ue({mode:"view",tables:()=>de(c.state.doc).map(({id:I,cols:S,rows:P})=>({id:I,cols:S,rows:P}))}),A=c.dom.ownerDocument.createElement("div");A.className="blockeditor-ai-preview";let E=null;try{E=T.mount(A,{id:"preview",rev:"preview",artifact:w.artifact,seed:w.state})}catch{return T.dispose(),{status:"refused",message:Q}}if(E.failed)return T.dispose(),{status:"refused",message:Q};if(y={host:T,dom:A},e)return $(c,{ids:[e],dom:A}),{status:"ready"};let x=Z(c.state,g);return x?(x.replace?$(c,{ids:[x.node.attrs.id],dom:A}):ae(c,{at:x.insertAt,dom:A}),{status:"ready"}):(C(),{status:"refused",message:K})}return e&&o.set(e,ne),ne}return{newTool(e=null){return l(null,e)},reviseTool(e){let f=o.get(e);return f?.isConnected?f:(o.delete(e),l(e))}}}var{TextSelection:$e}=V,ze="ai-edit",Le="page area",je="This section is too large for AI editing. Select a smaller part.",Ce="Someone changed this area while AI was working, so nothing was changed.",Ve="This page is not open for editing any more.",Fe="AI editing isn't available on this page right now.",Ue=0;function te(i,n){let t=null;return i.forEach((r,s)=>{r.attrs?.id===n&&(t={node:r,at:s})}),t}var qe=(i,n)=>te(i,n)?.node?.type===N.nodes.tool,ee=(i,n,t)=>i.slice(n,t+1).map(r=>r.node.attrs.id).filter(Boolean),Ge=()=>globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,ke=()=>({x:0,y:0,left:0,top:0,right:0,bottom:0,width:0,height:0});function Je(i){if(!i.length)return ke();let n=Math.min(...i.map(a=>a.left)),t=Math.min(...i.map(a=>a.top)),r=Math.max(...i.map(a=>a.right)),s=Math.max(...i.map(a=>a.bottom));return{x:n,y:t,left:n,top:t,right:r,bottom:s,width:r-n,height:s-t}}function We(i,n,t){let r=i.selection;if(!(r instanceof $e)||r.empty)return null;let[s,a]=ce(i.doc,r,n);if(s!==a||t.lo!==s||t.hi!==s)return null;let v=n[s];if(r.from<v.at||r.to>v.end)return null;let h=i.doc.textBetween(r.from,r.to," ");if(!h.trim())return null;let o=i.doc.textBetween(v.at+1,r.from," ").length;return{text:h,start:o,end:o+h.length}}function Tt({getView:i,store:n=()=>null,acceptState:t}={}){let r=()=>{let o=i();return o&&!o.isDestroyed?o:null},s=new Map,a=Ee({getView:r,store:n,acceptState:t}),v=o=>a.reviseTool(o);function h(o,{quote:m=null,label:l=null}={}){for(let[d,p]of s)p.isConnected||s.delete(d);let e=s.get(o.join(","));if(e)return e.quote=m??void 0,e;let f=null,u=null,g={aiTarget:!0,label:l??(o.length===1?"This block":`${o.length} blocks`),ref:[...o],get isConnected(){let d=r();return!!d&&o.some(p=>te(d.state.doc,p))},getBoundingClientRect(){let d=r();if(!d)return ke();let p=d.dom.querySelector(".blockeditor-ai-preview");if(p)return p.getBoundingClientRect();let w=[g.ref[0],g.ref[g.ref.length-1]].map(y=>te(d.state.doc,y)).map(y=>y?d.nodeDOM(y.at):null).filter(y=>y&&typeof y.getBoundingClientRect=="function").map(y=>y.getBoundingClientRect());return Je(w)},async start(d,p){let b=r();if(!b)return{status:"refused",code:"gone",message:Ve};let w=window.clay?.wire;if(!w)return{status:"refused",code:"no-wire",message:Fe};let{captureArea:y,AREA_GUIDE:M}=await import("./c-SFZRY6RT.js"),k=y(b.state.doc,g.ref);if(f=null,u=null,k.status!=="ok")return{status:"refused",code:k.code,message:k.message};let O=p??g.quote,C={id:"req-"+Date.now().toString(36)+"-"+ ++Ue,editId:Le,tag:"div",elementHTML:k.capture.html,comment:d+`
|
|
1
|
+
import{a as me,b as pe,c as he}from"./c-SIM7Z3U7.js";import{a as de,b as fe}from"./c-OYW5MFPZ.js";import{a as F,b as U,c as ue}from"./c-H3FNLBHN.js";import{C as X,E as le,h as z,l as ce,m as Y}from"./c-3XGLJAS7.js";import{A as se,d as N,x as oe}from"./c-OH2FPYSY.js";import"./c-VPXCXBDT.js";import{b as $,c as ae,d as R}from"./c-Z6MROEQ4.js";import{b as ie}from"./c-Q26XHBLQ.js";import{a as H,b as V}from"./c-RETTCOWO.js";import{a as re}from"./c-3LDGIBMN.js";import"./c-VHNSBD2M.js";var ge=16384,we=i=>new TextEncoder().encode(JSON.stringify(i)).length,G=class extends Error{constructor(n,t=n){super(t),this.name="ToolRequestError",this.code=n}};function Oe(i){let n=re(i);for(Array.isArray(n.tables)||(n.tables=[]),Array.isArray(n.outline)||(n.outline=[]);we(n)>ge;){let t=[...n.tables].reverse().find(r=>Array.isArray(r.rows)&&r.rows.length);if(t)t.rows.pop();else if(n.outline.length)n.outline.pop();else break}if(we(n)>ge)throw new G("context-too-large");return n}var Me=()=>globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;function ve({transport:i,newId:n=Me}){let t=null,r=s=>{!s||s.discarded||s.done||(s.discarded=!0,t===s&&(t=null),i.cancel(s.requestId),s.resolve({requestId:s.requestId,code:"discarded",message:"Candidate discarded"}))};return{request(s,a,v=null,h=null){let o=Oe(a);t&&r(t);let m=n(),l={requestId:m,discarded:!1,done:!1};l.promise=new Promise(u=>{l.resolve=u}),t=l;let e={protocol:"blockeditor-tool/1",requestId:m,prompt:s,context:o,target:v,current:h};l.request=e;let f=u=>{if(!(l.discarded||l.done||u?.requestId!==m))if(l.done=!0,t===l&&(t=null),u?.artifact!==void 0){let g=F(u.artifact),d=U(u.state),p=g.ok?d.ok?null:d:g;l.resolve(p?{requestId:m,code:p.code,message:p.code}:u)}else l.resolve(typeof u?.code=="string"?u:{requestId:m,code:"invalid-result",message:"invalid-result"})};try{let u=g=>f({requestId:m,code:typeof g?.code=="string"?g.code:"transport-error",message:String(g?.message??g)});Promise.resolve(i.request(e)).then(f,u)}catch(u){f({requestId:m,code:typeof u?.code=="string"?u.code:"transport-error",message:String(u?.message??u)})}return l},discard:r,async wait(s,{signal:a}={}){if(a?.aborted)throw new DOMException("Aborted","AbortError");let v,h=await(a?Promise.race([s.promise,new Promise((o,m)=>{v=()=>m(new DOMException("Aborted","AbortError")),a.addEventListener("abort",v,{once:!0})})]).finally(()=>a.removeEventListener("abort",v)):s.promise);if(h?.code)throw new G(h.code,h.message);return h}}}var J=class extends Error{constructor(n){super(n),this.name="ToolTransportError",this.code=n}};function ye({getWire:i=()=>globalThis.window?.clay?.wire??null}={}){let n=new Map;return{request(t,{onStatus:r=null}={}){let s=i();if(!s||typeof s.send!="function")return Promise.reject(new J("no-wire"));let a=t?.requestId,v;try{v=s.send(t,{helper:"blockeditor-tool",document:"none",id:a,onStatus:r})}catch{return Promise.reject(new J("no-wire"))}return n.set(a,v),Promise.resolve(v.done).then(h=>{if(n.get(a)===v&&n.delete(a),h?.state==="done"){let o=h.result??{};return{requestId:typeof o.requestId=="string"?o.requestId:a,artifact:o.artifact,state:o.state,model:o.model}}return{requestId:a,code:h?.errorCode||(h?.state==="cancelled"?"cancelled":"transport-error"),message:h?.error||"the helper reported an error"}},()=>({requestId:a,code:"transport-error",message:"the helper reported an error"}))},cancel(t){let r=n.get(t);n.delete(t),r?.cancel?.()}}}var{Selection:Be}=V,W="This page is not open for editing any more.",Ie="AI tool making isn't available on this page right now.",Te="This document can't save tool data.",K="The place for this tool moved. Close this and run /ai where you want the tool.",be="This tool changed while you were revising, so nothing was replaced. Ask again.",Q="AI did not make a usable tool. Try again.",Ne="The tool data from AI is too large or not usable. Try again.",xe="This tool's data changed while AI was working, so it was not replaced. Ask again to include the latest data.",Ae="The tool could not be saved, so it was not added. Try again.",Re="Your tool is in the document, but saving failed. It will be saved with your next edit.";function _(i,n){let t=null;return i.forEach((r,s,a)=>{r.attrs.id===n&&(t={node:r,at:s,index:a})}),t}function Pe(i,n){let t=i.selection.$head,r=Math.min(Math.max(t.index(0),0),i.doc.childCount-1);return{hostId:i.doc.child(r)?.attrs.id??null,slashText:n?i.doc.textBetween(n.from,n.to):null,slashOffset:n&&t.depth?n.from-t.before(1)-1:null}}function Z(i,n){let t=n?.hostId?_(i.doc,n.hostId):null;if(!t)return null;let r=i.doc.maybeChild(t.index+1),s=t.node.isTextblock&&(t.node.content.size===0||t.node.textContent===n.slashText);return{...t,replace:s,pos:s?t.node.attrs.pos:oe(t.node.attrs.pos,r?.attrs.pos??null),insertAt:s?t.at:t.at+t.node.nodeSize}}function _e(i,n,t){let r=i.state,s=Z(r,t);if(!s)return!1;let{node:a,at:v,insertAt:h,replace:o}=s,m=N.nodes.tool.create({id:n.id,pos:s.pos,parent:a.attrs.parent??null,artifact:n.artifact,rev:n.rev,state:n.state}),l=r.tr;if(!o&&t?.hostId===a.attrs.id&&t.slashText&&t.slashOffset>=0){let f=v+1+t.slashOffset,u=f+t.slashText.length;u<=v+a.nodeSize-1&&r.doc.textBetween(f,u)===t.slashText&&l.delete(f,u)}let e=l.mapping.map(h);return l.replaceWith(e,o?l.mapping.map(v+a.nodeSize):e,m),l.setSelection(Be.near(l.doc.resolve(Math.min(e+m.nodeSize,l.doc.content.size)))),i.dispatch(X(l).scrollIntoView()),!0}var Se=()=>({x:0,y:0,left:0,top:0,right:0,bottom:0,width:0,height:0});function Ee({getView:i,store:n=()=>null,acceptState:t=()=>globalThis.clay?.save?.flush?.(),newId:r=se,transport:s=ye()}={}){let a=()=>{let e=i();return e&&!e.isDestroyed?e:null},v=()=>typeof n=="function"?n():n,h=(e,f)=>{let u=v()?.data?.[e]?.[f];return u===void 0?{}:u},o=new Map,m=e=>Array.isArray(e)?`[${e.map(m).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).sort().map(u=>`${JSON.stringify(u)}:${m(e[u])}`).join(",")}}`:JSON.stringify(e)??"null";function l(e=null,f=null){let u=a(),g=e||!u?null:Pe(u.state,f),d=null,p=ve({transport:{request:c=>s.request(c,{onStatus:T=>d?.(T)}),cancel:c=>s.cancel(c)}}),b=null,w=null,y=null,M=!1,k=null,O=null,C=()=>{y?.host?.dispose(),y=null},L=()=>{let c=a();return c&&e?ie.get(c)?.get(e)??null:null},j=()=>L()?.suspend(),B=()=>L()?.resume(),q=c=>{M=!1;let T=a();return C(),T&&R(T),B(),{status:"failed",message:c}},ne={aiTarget:!0,label:e?"This tool":"New tool",ref:e?[e]:[],placeholder:e?"What should change?":"Describe the tool",get isConnected(){let c=a();return c?e?!!_(c.state.doc,e):!0:!1},getBoundingClientRect(){let c=a();if(!c)return Se();if(y)return y.dom.getBoundingClientRect();let T=e??g?.hostId,A=T?_(c.state.doc,T):null,E=A?c.nodeDOM(A.at):null;return E&&typeof E.getBoundingClientRect=="function"?E.getBoundingClientRect():Se()},async start(c){w=null,M=!1;let T=a();if(!T)return{status:"refused",code:"gone",message:W};if(!globalThis.window?.clay?.wire)return{status:"refused",code:"no-wire",message:Ie};let A=null,E=null;if(e){let x=_(T.state.doc,e);if(x?.node.type!==N.nodes.tool)return{status:"refused",code:"gone",message:W};k=x.node.attrs.rev,A={toolId:e,rev:k},j(),E={artifact:x.node.attrs.artifact,state:h(e,k)},O=m(E.state)}return b=p.request(c,fe(T.state.doc,T.dom.ownerDocument.title),A,E),{status:"ok",id:b.requestId,send:(x={})=>(d=typeof x.onStatus=="function"?x.onStatus:null,{done:p.wait(b).then(S=>(w={id:e,rev:null,artifact:S.artifact,state:S.state},{state:"done",result:S}),S=>(B(),{state:"error",error:S?.message||S?.code||"the helper reported an error",code:S?.code??null})),cancel:()=>{B(),p.discard(b)}})}},async propose(c){let T=a();if(!T||!c)return{status:"refused",message:W};if(!F(c.artifact).ok)return{status:"refused",message:Q};if(!U(c.state).ok)return{status:"refused",message:Ne};w={id:e,rev:null,artifact:c.artifact,state:c.state};let x=De(T);return x.status!=="ready"&&(w=null),x},async keep(){if(!w||M)return q(be);let c=a();if(!c)return q(W);let T=v();if(!T)return q(Te);let A=()=>e&&O!==null&&m(h(e,k))!==O;if(A())return q(xe);M=!0;let E=w.id??r("b"),x=r("rev"),I={...w,id:E,rev:x};try{await T.set([E,x],I.state)}catch(D){return q(D?.message??Te)}let S=null;try{S=await t()}catch{return q(Ae)}if(S?.ok!==!0&&!["saved","clean"].includes(S?.state))return q(S?.msg??S?.message??Ae);if(e){let D=_(c.state.doc,e);if(D?.node.type!==N.nodes.tool||D.node.attrs.rev!==k)return q(be)}else if(!Z(c.state,g))return q(K);if(A())return q(xe);if(C(),R(c),e){let D=_(c.state.doc,e);c.dispatch(X(c.state.tr.setNodeMarkup(D.at,null,{...D.node.attrs,artifact:I.artifact,rev:I.rev})))}else if(!_e(c,I,g))return q(K);let P=!1;for(let D=0;D<2&&!P;D++)try{P=(await t())?.ok!==!1}catch{P=!1}return P?(o.delete(e??"new"),{status:"kept"}):{status:"failed",message:Re}},discard(){C();let c=a();c&&R(c),p.discard(b),B(),o.delete(e??"new")}};function De(c){C();let T=ue({mode:"view",tables:()=>de(c.state.doc).map(({id:I,cols:S,rows:P})=>({id:I,cols:S,rows:P}))}),A=c.dom.ownerDocument.createElement("div");A.className="blockeditor-ai-preview";let E=null;try{E=T.mount(A,{id:"preview",rev:"preview",artifact:w.artifact,seed:w.state})}catch{return T.dispose(),{status:"refused",message:Q}}if(E.failed)return T.dispose(),{status:"refused",message:Q};if(y={host:T,dom:A},e)return $(c,{ids:[e],dom:A}),{status:"ready"};let x=Z(c.state,g);return x?(x.replace?$(c,{ids:[x.node.attrs.id],dom:A}):ae(c,{at:x.insertAt,dom:A}),{status:"ready"}):(C(),{status:"refused",message:K})}return e&&o.set(e,ne),ne}return{newTool(e=null){return l(null,e)},reviseTool(e){let f=o.get(e);return f?.isConnected?f:(o.delete(e),l(e))}}}var{TextSelection:$e}=V,ze="ai-edit",Le="page area",je="This section is too large for AI editing. Select a smaller part.",Ce="Someone changed this area while AI was working, so nothing was changed.",Ve="This page is not open for editing any more.",Fe="AI editing isn't available on this page right now.",Ue=0;function te(i,n){let t=null;return i.forEach((r,s)=>{r.attrs?.id===n&&(t={node:r,at:s})}),t}var qe=(i,n)=>te(i,n)?.node?.type===N.nodes.tool,ee=(i,n,t)=>i.slice(n,t+1).map(r=>r.node.attrs.id).filter(Boolean),Ge=()=>globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,ke=()=>({x:0,y:0,left:0,top:0,right:0,bottom:0,width:0,height:0});function Je(i){if(!i.length)return ke();let n=Math.min(...i.map(a=>a.left)),t=Math.min(...i.map(a=>a.top)),r=Math.max(...i.map(a=>a.right)),s=Math.max(...i.map(a=>a.bottom));return{x:n,y:t,left:n,top:t,right:r,bottom:s,width:r-n,height:s-t}}function We(i,n,t){let r=i.selection;if(!(r instanceof $e)||r.empty)return null;let[s,a]=ce(i.doc,r,n);if(s!==a||t.lo!==s||t.hi!==s)return null;let v=n[s];if(r.from<v.at||r.to>v.end)return null;let h=i.doc.textBetween(r.from,r.to," ");if(!h.trim())return null;let o=i.doc.textBetween(v.at+1,r.from," ").length;return{text:h,start:o,end:o+h.length}}function Tt({getView:i,store:n=()=>null,acceptState:t}={}){let r=()=>{let o=i();return o&&!o.isDestroyed?o:null},s=new Map,a=Ee({getView:r,store:n,acceptState:t}),v=o=>a.reviseTool(o);function h(o,{quote:m=null,label:l=null}={}){for(let[d,p]of s)p.isConnected||s.delete(d);let e=s.get(o.join(","));if(e)return e.quote=m??void 0,e;let f=null,u=null,g={aiTarget:!0,label:l??(o.length===1?"This block":`${o.length} blocks`),ref:[...o],get isConnected(){let d=r();return!!d&&o.some(p=>te(d.state.doc,p))},getBoundingClientRect(){let d=r();if(!d)return ke();let p=d.dom.querySelector(".blockeditor-ai-preview");if(p)return p.getBoundingClientRect();let w=[g.ref[0],g.ref[g.ref.length-1]].map(y=>te(d.state.doc,y)).map(y=>y?d.nodeDOM(y.at):null).filter(y=>y&&typeof y.getBoundingClientRect=="function").map(y=>y.getBoundingClientRect());return Je(w)},async start(d,p){let b=r();if(!b)return{status:"refused",code:"gone",message:Ve};let w=window.clay?.wire;if(!w)return{status:"refused",code:"no-wire",message:Fe};let{captureArea:y,AREA_GUIDE:M}=await import("./c-H47C6PJZ.js"),k=y(b.state.doc,g.ref);if(f=null,u=null,k.status!=="ok")return{status:"refused",code:k.code,message:k.message};let O=p??g.quote,C={id:"req-"+Date.now().toString(36)+"-"+ ++Ue,editId:Le,tag:"div",elementHTML:k.capture.html,comment:d+`
|
|
2
2
|
|
|
3
|
-
`+M,contextRefs:pe(d)};return O&&(C.quote=O.text,Number.isInteger(O.start)&&(C.selection={start:O.start,end:O.end})),he(d)&&(C.page=!0),new Blob([JSON.stringify(C)]).size>921600?{status:"refused",code:"too-large",message:je}:(f=k.capture,{status:"ok",id:C.id,send:(L={})=>{let j=!0,B=null;return{done:(async()=>(C.page&&await window.clay?.save?.(),j?(B=w.send(C,{helper:ze,onStatus:L.onStatus}),B.done):{state:"cancelled"}))(),cancel(){j=!1,B?.cancel()}}}})},async propose(d){let p=r();if(!p||!f)return{status:"refused",message:"This area is no longer open for AI editing."};let{proposeArea:b}=await import("./c-
|
|
3
|
+
`+M,contextRefs:pe(d)};return O&&(C.quote=O.text,Number.isInteger(O.start)&&(C.selection={start:O.start,end:O.end})),he(d)&&(C.page=!0),new Blob([JSON.stringify(C)]).size>921600?{status:"refused",code:"too-large",message:je}:(f=k.capture,{status:"ok",id:C.id,send:(L={})=>{let j=!0,B=null;return{done:(async()=>(C.page&&await window.clay?.save?.(),j?(B=w.send(C,{helper:ze,onStatus:L.onStatus}),B.done):{state:"cancelled"}))(),cancel(){j=!1,B?.cancel()}}}})},async propose(d){let p=r();if(!p||!f)return{status:"refused",message:"This area is no longer open for AI editing."};let{proposeArea:b}=await import("./c-H47C6PJZ.js"),w=b(p.state,f,d?.html??"",{seed:Ge()});if(w.status!=="ready")return{status:"refused",message:w.message};u=w;let y=p.dom.ownerDocument.createElement("div");y.className="blockeditor-ai-preview";let M=H.DOMSerializer.fromSchema(N);return y.appendChild(M.serializeFragment(H.Fragment.from(w.nodes),{document:p.dom.ownerDocument})),$(p,{ids:f.ids,dom:y}),{status:"ready"}},async keep(){let d=r();if(!d||!f||!u)return{status:"failed",message:Ce};let{keepAreaTransaction:p}=await import("./c-H47C6PJZ.js"),b=p(d.state,f,u);if(R(d),b.status!=="ok")return{status:"failed",message:Ce};d.dispatch(b.tr),d.dom.isConnected&&d.focus();try{await window.clay?.save?.flush?.()}catch{return{status:"failed",message:"Your change is in the document, but saving failed. It will be saved with your next edit."}}return{status:"kept"}},discard(){let d=r();d&&(R(d),d.dom.isConnected&&d.focus())}};return g.quote=m??void 0,s.set(o.join(","),g),g}return{active:()=>!!r(),targetFromSelection(){let o=r();if(!o)return null;let m=z(o.state.doc);if(!m.length)return null;let l=le(o.state,m),e=ee(m,l.lo,l.hi);return e.length?e.length===1&&qe(o.state.doc,e[0])?v(e[0]):h(e,{quote:We(o.state,m,l)}):null},targetAt(o,m){let l=r();if(!l)return null;let e=l.posAtCoords({left:o,top:m});if(!e)return null;let f=z(l.state.doc);if(!f.length)return null;let u=e.inside>=0?e.inside:e.pos,g=f.findIndex(y=>y.node.type===N.nodes.tool&&y.end===u),d=g>=0?g:Math.min(Math.max(l.state.doc.resolve(u).index(0),0),f.length-1),{lo:p,hi:b}=Y(f,d,d),w=ee(f,p,b);return w.length?w.length===1&&qe(l.state.doc,w[0])?v(w[0]):h(w):null},between(o,m){let l=r();if(!l)return null;let e=z(l.state.doc),f=[...o?.ref??[],...m?.ref??[]].map(p=>e.findIndex(b=>b.node.attrs.id===p)).filter(p=>p>=0);if(!f.length)return null;let{lo:u,hi:g}=Y(e,Math.min(...f),Math.max(...f)),d=ee(e,u,g);return d.length?h(d):null},wholePage(){let o=r(),m=o?z(o.state.doc).map(l=>l.node.attrs.id).filter(Boolean):[];return h(m,{label:"This page"})},newTool(o){return a.newTool(o??null)},reviseTool(o){return a.reviseTool(o)}}}export{Tt as createPageAi};
|