@panphora/clayjs 1.15.1 → 1.16.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/README.md +4 -5
- package/THIRD-PARTY-NOTICES.md +16 -0
- package/compat/highlight-11.9.0.min.js +1213 -0
- package/compat/highlight-LICENSE +29 -0
- package/compat/journal-assets.lock.json +22 -0
- package/compat/overtype-2.6.1.min.js +116 -0
- package/compat/overtype-LICENSE +21 -0
- package/dist/all.js +90 -0
- package/dist/clay-dom.js +84 -0
- package/dist/clay-events.js +103 -0
- package/dist/clay-internals.js +85 -0
- package/dist/clay-options.js +93 -0
- package/dist/clay-router.js +98 -0
- package/dist/clay-ui.js +95 -0
- package/dist/clay-utils.js +84 -0
- package/dist/clay.js +146 -0
- package/dist/clay.standalone.js +83090 -58706
- package/dist/m/attrs/add-from-T5LJXFFI.js +1 -0
- package/dist/m/attrs/onaftersave-OKSWEJQF.js +1 -0
- package/dist/m/attrs/refetch-on-save-NWPPXOCZ.js +1 -0
- package/dist/m/attrs/save-freeze-FUP4Q4X3.js +1 -0
- package/dist/m/c-2AZDZWCK.js +1 -0
- package/dist/m/c-2JL6E75N.js +1 -0
- package/dist/m/c-2M73252O.js +1 -0
- package/dist/m/c-2SPVQSHC.js +1 -0
- package/dist/m/c-33HUYEDI.js +1 -0
- package/dist/m/c-33JJ6CBX.js +2 -0
- package/dist/m/c-35NBGMZB.js +1 -0
- package/dist/m/c-3GJ4SDE2.js +1 -0
- package/dist/m/c-3IQRECYS.js +1 -0
- package/dist/m/c-3OWDMNJR.js +2 -0
- package/dist/m/c-46XYM55L.js +1 -0
- package/dist/m/c-4B6H4G5V.js +1 -0
- package/dist/m/c-4DRMS4QG.js +9 -0
- package/dist/m/c-4FFHZM32.js +1 -0
- package/dist/m/c-4JZDZFF6.js +1 -0
- package/dist/m/c-4L3BTFRK.js +1 -0
- package/dist/m/c-4Q2XTQ2N.js +2 -0
- package/dist/m/c-4WKFKEKF.js +1 -0
- package/dist/m/c-4YSCRICO.js +1 -0
- package/dist/m/c-54RCDCBU.js +1 -0
- package/dist/m/c-5M4YEKCX.js +4 -0
- package/dist/m/c-5R4PTRG2.js +1 -0
- package/dist/m/c-5V3MOVJT.js +1 -0
- package/dist/m/c-5VYOWDTI.js +1 -0
- package/dist/m/c-5Y6TNX5W.js +34 -0
- package/dist/m/c-5YIHJ3TJ.js +1 -0
- package/dist/m/c-66O32MV3.js +28 -0
- package/dist/m/c-6HMB24EV.js +1 -0
- package/dist/m/c-7DJDKPGL.js +1 -0
- package/dist/m/c-7O6AFR65.js +1 -0
- package/dist/m/c-7SWMYKAI.js +1 -0
- package/dist/m/c-7VGZ7RU5.js +1 -0
- package/dist/m/c-A7LS5UZW.js +1 -0
- package/dist/m/c-ANQTJ3B5.js +2 -0
- package/dist/m/c-AQLFEATB.js +1 -0
- package/dist/m/c-AYVOREBE.js +1 -0
- package/dist/m/c-B2ZXPOS3.js +3 -0
- package/dist/m/c-BBVGTQG7.js +1 -0
- package/dist/m/c-BMIZKMPV.js +1 -0
- package/dist/m/c-BTDI4Y23.js +1 -0
- package/dist/m/c-BWFVSBDF.js +1 -0
- package/dist/m/c-BYTKL6UX.js +1 -0
- package/dist/m/c-CFHW5AMY.js +6 -0
- package/dist/m/c-CJZSLMVQ.js +1 -0
- package/dist/m/c-CYWLPPUS.js +1 -0
- package/dist/m/c-CZUSOB7V.js +1 -0
- package/dist/m/c-DBE6ORSI.js +1 -0
- package/dist/m/c-DCFSEJZG.js +1 -0
- package/dist/m/c-DNZ5IFM6.js +1 -0
- package/dist/m/c-EDHUR4MX.js +1 -0
- package/dist/m/c-EJTGYSLN.js +1 -0
- package/dist/m/c-EY6UOM54.js +1 -0
- package/dist/m/c-F3CKJTJS.js +1 -0
- package/dist/m/c-F7Y6FLPY.js +1 -0
- package/dist/m/c-FA4DZVTC.js +1 -0
- package/dist/m/c-FILLTJA7.js +1 -0
- package/dist/m/c-G2BUZITR.js +1 -0
- package/dist/m/c-GB3JTV6E.js +1 -0
- package/dist/m/c-GBGWXTX4.js +1 -0
- package/dist/m/c-GHBCCVG4.js +1 -0
- package/dist/m/c-GJAEGGXY.js +1 -0
- package/dist/m/c-GOWBDM6J.js +1 -0
- package/dist/m/c-GQ6F6IDK.js +1 -0
- package/dist/m/c-H4LG442Q.js +1 -0
- package/dist/m/c-HA6INT6J.js +1 -0
- package/dist/m/c-HPURYVZS.js +2 -0
- package/dist/m/c-HRDCD3WN.js +67 -0
- package/dist/m/c-HT33EQRN.js +1 -0
- package/dist/m/c-HVYXIS72.js +1 -0
- package/dist/m/c-IB52R237.js +1 -0
- package/dist/m/c-IJUK2GPW.js +1 -0
- package/dist/m/c-IKWNE4R4.js +1 -0
- package/dist/m/c-IU3IYEU6.js +1 -0
- package/dist/m/c-IZ2EBRAJ.js +1 -0
- package/dist/m/c-J7CA54IP.js +1 -0
- package/dist/m/c-JAX2667S.js +6 -0
- package/dist/m/c-KI7M4AY3.js +1 -0
- package/dist/m/c-KIPQJX4B.js +1 -0
- package/dist/m/c-KKWLDOPM.js +1 -0
- package/dist/m/c-KR4UW4KW.js +1 -0
- package/dist/m/c-KY3VJGUA.js +8 -0
- package/dist/m/c-L4WQSC27.js +1 -0
- package/dist/m/c-LFPHCXY3.js +1 -0
- package/dist/m/c-LR4CGEPT.js +91 -0
- package/dist/m/c-LRPUO2MX.js +1 -0
- package/dist/m/c-LTGMXXKO.js +1 -0
- package/dist/m/c-LXENEBV7.js +1 -0
- package/dist/m/c-LZJPNR2W.js +1 -0
- package/dist/m/c-MMUIUUZG.js +2 -0
- package/dist/m/c-MTQHWQC3.js +1 -0
- package/dist/m/c-N326R2JD.js +1 -0
- package/dist/m/c-N7JPUPGC.js +1 -0
- package/dist/m/c-NMJRXKPC.js +8 -0
- package/dist/m/c-NRPJEVJS.js +1 -0
- package/dist/m/c-NUHP2XDB.js +1 -0
- package/dist/m/c-NZMNXVF6.js +1 -0
- package/dist/m/c-OCSZ4QGN.js +1 -0
- package/dist/m/c-OIBUTDXI.js +1 -0
- package/dist/m/c-OIDRZKAF.js +1 -0
- package/dist/m/c-OYTFP5QN.js +1 -0
- package/dist/m/c-P7KNDG34.js +1 -0
- package/dist/m/c-PPOSCAQD.js +1 -0
- package/dist/m/c-PQ5LK6QE.js +993 -0
- package/dist/m/c-PZ4XEPUP.js +2 -0
- package/dist/m/c-QHIWXHRO.js +1 -0
- package/dist/m/c-QHWJ5ZIJ.js +1 -0
- package/dist/m/c-QIX5BJYN.js +1 -0
- package/dist/m/c-QNKREOL6.js +1 -0
- package/dist/m/c-QQHEX6HA.js +1 -0
- package/dist/m/c-R7RMANJI.js +9 -0
- package/dist/m/c-RI4NT75Y.js +1 -0
- package/dist/m/c-RM7J7BV2.js +1 -0
- package/dist/m/c-RUJKSUQW.js +1 -0
- package/dist/m/c-RVMWGXEJ.js +1 -0
- package/dist/m/c-S7H2DRCB.js +1 -0
- package/dist/m/c-S7LK4KUE.js +1 -0
- package/dist/m/c-SGCCC4FW.js +25 -0
- package/dist/m/c-SGIA4IEQ.js +188 -0
- package/dist/m/c-SWRJFCNN.js +1 -0
- package/dist/m/c-T4VO4OCB.js +1 -0
- package/dist/m/c-TCCA5BZN.js +2 -0
- package/dist/m/c-TQEMVJCS.js +1 -0
- package/dist/m/c-TQZ2JYHD.js +1 -0
- package/dist/m/c-TR6RMDQ7.js +3 -0
- package/dist/m/c-TRS6TM6O.js +1 -0
- package/dist/m/c-UGHH4MB3.js +1 -0
- package/dist/m/c-UKHTLWUW.js +1 -0
- package/dist/m/c-UL2YUY52.js +1 -0
- package/dist/m/c-UNN7LWCT.js +1 -0
- package/dist/m/c-UXBMRDZB.js +235 -0
- package/dist/m/c-V7PZZRG7.js +1 -0
- package/dist/m/c-VAK7SG37.js +1 -0
- package/dist/m/c-VDSS4K3Z.js +1 -0
- package/dist/m/c-VFX45IZQ.js +1 -0
- package/dist/m/c-VHNSBD2M.js +1 -0
- package/dist/m/c-VKEDWYDF.js +1 -0
- package/dist/m/c-VL52ADDR.js +1 -0
- package/dist/m/c-WN5AY3OZ.js +1 -0
- package/dist/m/c-WNYBLIOZ.js +1 -0
- package/dist/m/c-WRBKEJD4.js +1 -0
- package/dist/m/c-WWDBYXLK.js +1 -0
- package/dist/m/c-WYFDLITL.js +1 -0
- package/dist/m/c-XN6MBKI6.js +67 -0
- package/dist/m/c-XNNW2CWK.js +1 -0
- package/dist/m/c-XPELB6E5.js +1 -0
- package/dist/m/c-XQXZAO7N.js +1 -0
- package/dist/m/c-Y6USGTS5.js +5 -0
- package/dist/m/c-YDH7Q3NY.js +1 -0
- package/dist/m/c-YG2NJYS6.js +135 -0
- package/dist/m/c-Z36J63PP.js +1 -0
- package/dist/m/c-Z4VRC7GU.js +7 -0
- package/dist/m/c-Z6K52OLP.js +19 -0
- package/dist/m/c-ZDY2MDAA.js +21 -0
- package/dist/m/c-ZE46QDIH.js +1 -0
- package/dist/m/c-ZUCOKOHT.js +1 -0
- package/dist/m/core/admin-attrs-VGNLAUDK.js +1 -0
- package/dist/m/core/autosave-E4PEFPZ6.js +1 -0
- package/dist/m/core/conflict-notice-VQ6Y64PH.js +1 -0
- package/dist/m/core/draft-mode-WSQAT67S.js +1 -0
- package/dist/m/core/host-permission-XN3K2IW3.js +1 -0
- package/dist/m/core/is-edit-mode-JXHDVGUL.js +1 -0
- package/dist/m/core/persist-HKHA66IY.js +3 -0
- package/dist/m/core/recovery-TBBSICE2.js +1 -0
- package/dist/m/core/save-WUCHTQBE.js +1 -0
- package/dist/m/core/save-core-FJVHT5M3.js +1 -0
- package/dist/m/core/snapshot-F3SWDZMM.js +1 -0
- package/dist/m/core/unsaved-warning-STKBHE6G.js +1 -0
- package/dist/m/dom/all-APS5ZSKP.js +1 -0
- package/dist/m/dom/dom-helpers-L7OSR6S4.js +1 -0
- package/dist/m/events/index-23DPTUT4.js +1 -0
- package/dist/m/internals/index-WOVAP3RU.js +1 -0
- package/dist/m/lib/cache-bust-CGWT6ZJI.js +1 -0
- package/dist/m/lib/region-policy-SB2AWVG5.js +1 -0
- package/dist/m/loader-HXX6YNH5.js +1 -0
- package/dist/m/manifest-F22DEDAC.js +1 -0
- package/dist/m/manifest-edit-C3C7376B.js +1 -0
- package/dist/m/manifest.json +3491 -0
- package/dist/m/options/options-2LH76JQ3.js +1 -0
- package/dist/m/page/editor-XUTB2HB2.js +189 -0
- package/dist/m/plugins/ai-edit-ZQ4CGWIP.js +6 -0
- package/dist/m/plugins/bind-text-NX46N5UV.js +1 -0
- package/dist/m/plugins/cms-HP3LSTPN.js +2293 -0
- package/dist/m/plugins/demo-ZIBFAA3R.js +1 -0
- package/dist/m/plugins/derive-UAAA4V4S.js +1 -0
- package/dist/m/plugins/indicator-PV4YW2ID.js +1 -0
- package/dist/m/plugins/live-NUTTXSBS.js +1 -0
- package/dist/m/plugins/menu-HCKO3DSP.js +138 -0
- package/dist/m/plugins/message-LQ6EDH4V.js +1 -0
- package/dist/m/plugins/page-KSUH7G6J.js +2 -0
- package/dist/m/plugins/page-view-W73OW7WI.js +1 -0
- package/dist/m/plugins/people-AJJ32YCG.js +1 -0
- package/dist/m/plugins/quickcrop-QNY3PKLD.js +26 -0
- package/dist/m/plugins/quickcrop-QNY3PKLD.js.LEGAL.txt +7 -0
- package/dist/m/plugins/richclay-RC3L2F6X.js +517 -0
- package/dist/m/plugins/richclay-RC3L2F6X.js.LEGAL.txt +1 -0
- package/dist/m/plugins/sortable-YRMQX3ZU.js +1 -0
- package/dist/m/plugins/source-KHK5UUSK.js +1 -0
- package/dist/m/plugins/undo-OF2L3CXU.js +1 -0
- package/dist/m/plugins/unsent-HJFLQJ2O.js +1 -0
- package/dist/m/plugins/upgrade-ZNYODP5Y.js +1 -0
- package/dist/m/plugins/upload-XSGNILUY.js +1 -0
- package/dist/m/plugins/visitor-drafts-XK5GW55Q.js +21 -0
- package/dist/m/plugins/visitor-drafts-owner-KSSH75EV.js +1 -0
- package/dist/m/plugins/wire-ZWVWKF76.js +1 -0
- package/dist/m/reader-core-ILWLXVMP.js +68 -0
- package/dist/m/route/route-KOCZSEGN.js +1 -0
- package/dist/m/sync/live-sync-4AUVXVJU.js +1 -0
- package/dist/m/ui/index-EVHKMKBL.js +1 -0
- package/dist/m/utils/index-4TJCVLT7.js +1 -0
- package/dist/m/vendor/Sortable.vendor-A755ITLN.js +3 -0
- package/dist/m/vendor/Sortable.vendor-A755ITLN.js.LEGAL.txt +1 -0
- package/dist/m/vendor/sap-core.vendor-A7BMUYZT.js +6 -0
- package/dist/offline-manifest.json +3800 -0
- package/dist/page/themes/light-1.css +406 -0
- package/dist/server/core.cjs +23662 -22860
- package/dist/server/offline-runtime.cjs +4954 -0
- package/dist/server/offline-runtime.mjs +4923 -0
- package/dist/server/rooms.mjs +9 -0
- package/docs/guide.md +1078 -669
- package/entries/all.js +2 -0
- package/entries/clay-data.js +1 -1
- package/entries/clay-dom.js +2 -0
- package/entries/clay-events.js +2 -0
- package/entries/clay-internals.js +2 -0
- package/entries/clay-options.js +2 -0
- package/entries/clay-router.js +2 -0
- package/entries/clay-ui.js +2 -0
- package/entries/clay-utils.js +2 -0
- package/entries/clay.js +2 -0
- package/entries/sap.js +6 -6
- package/fonts/ibm-plex-mono-LICENSE +93 -0
- package/fonts/ibm-plex-mono-latin-300-normal.woff2 +0 -0
- package/fonts/ibm-plex-mono-latin-400-italic.woff2 +0 -0
- package/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/fonts/ibm-plex-mono-latin-600-normal.woff2 +0 -0
- package/fonts/ibm-plex-sans-LICENSE +93 -0
- package/fonts/ibm-plex-sans-latin-400-normal.woff2 +0 -0
- package/fonts/ibm-plex-sans-latin-500-normal.woff2 +0 -0
- package/fonts/ibm-plex-sans-latin-600-normal.woff2 +0 -0
- package/fonts/ibm-plex.css +71 -0
- package/fonts/inter-LICENSE +93 -0
- package/fonts/inter-cyrillic-ext-wght-normal.woff2 +0 -0
- package/fonts/inter-cyrillic-wght-normal.woff2 +0 -0
- package/fonts/inter-greek-ext-wght-normal.woff2 +0 -0
- package/fonts/inter-greek-wght-normal.woff2 +0 -0
- package/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
- package/fonts/inter-latin-wght-normal.woff2 +0 -0
- package/fonts/inter-vietnamese-wght-normal.woff2 +0 -0
- package/fonts/inter.css +62 -0
- package/fonts/newsreader-LICENSE +93 -0
- package/fonts/newsreader-latin-ext-opsz-normal.woff2 +0 -0
- package/fonts/newsreader-latin-opsz-normal.woff2 +0 -0
- package/fonts/newsreader-vietnamese-opsz-normal.woff2 +0 -0
- package/fonts/newsreader.css +26 -0
- package/fonts/work-sans-LICENSE +93 -0
- package/fonts/work-sans-latin-wght-normal.woff2 +0 -0
- package/fonts/work-sans.css +8 -0
- package/package.json +20 -3
- package/packed-contract.json +1 -0
- package/src/attrs/add-from.js +27 -4
- package/src/attrs/save-freeze.js +7 -52
- package/src/core/admin-attrs.js +119 -12
- package/src/core/admin-contenteditable.js +12 -10
- package/src/core/admin-inputs.js +14 -15
- package/src/core/admin-onclick.js +2 -0
- package/src/core/autosave.js +74 -21
- package/src/core/conflict-download.js +22 -0
- package/src/core/conflict-notice-ui.js +1173 -0
- package/src/core/conflict-notice.js +140 -697
- package/src/core/edit-mode.js +147 -14
- package/src/core/etag.js +30 -12
- package/src/core/host-meta.js +72 -8
- package/src/core/host-permission.js +29 -0
- package/src/core/is-edit-mode.js +145 -12
- package/src/core/mode-key.js +125 -0
- package/src/core/mode-lifecycle.js +544 -0
- package/src/core/mode-receipt.js +30 -0
- package/src/core/mode-refusal.js +13 -0
- package/src/core/mode-resources.js +52 -0
- package/src/core/mode-support.js +82 -0
- package/src/core/mode-switch.js +259 -0
- package/src/core/mode-transition.js +112 -0
- package/src/core/page-data-write.js +305 -0
- package/src/core/page-data.js +26 -227
- package/src/core/page-format-wire.js +4 -0
- package/src/core/page-format.js +58 -0
- package/src/core/persist.js +37 -9
- package/src/core/preserve-authored.js +114 -0
- package/src/core/recovery.js +772 -0
- package/src/core/runtime-url.js +105 -0
- package/src/core/save-core.js +109 -12
- package/src/core/save-replace.js +72 -0
- package/src/core/save-size-notice.js +134 -0
- package/src/core/save-size.js +140 -0
- package/src/core/save.js +805 -118
- package/src/core/snapshot.js +121 -11
- package/src/core/source-map.js +157 -9
- package/src/core/unsaved-warning.js +14 -4
- package/src/core/upgrade-run.js +408 -0
- package/src/core/version.js +18 -0
- package/src/lib/assets.js +30 -0
- package/src/lib/autosave-debug-gate.js +50 -0
- package/src/lib/autosave-scheduler.js +141 -0
- package/src/lib/boot-imports.js +8 -0
- package/src/lib/derived.js +3 -1
- package/src/lib/dirty-gate.js +15 -0
- package/src/lib/doc-storage.js +33 -0
- package/src/lib/effect.js +9 -4
- package/src/lib/mutation.js +4 -2
- package/src/lib/offline-runtime.js +226 -0
- package/src/lib/preload.js +48 -0
- package/src/lib/root-attrs.js +1 -1
- package/src/lib/trash.js +18 -0
- package/src/lib/undo/capture-move.js +152 -0
- package/src/live/local-channel.js +61 -0
- package/src/live/local-lane.js +60 -9
- package/src/live/server-lane.js +6 -3
- package/src/loader-logic.js +76 -15
- package/src/loader.js +218 -30
- package/src/page/adopt-boot.js +76 -22
- package/src/page/adopt.js +25 -4
- package/src/page/awareness.js +230 -0
- package/src/page/blocks.js +79 -5
- package/src/page/blocksel.js +20 -4
- package/src/page/board-face.js +13 -0
- package/src/page/board-panel.js +5 -17
- package/src/page/board-style.js +2 -13
- package/src/page/board-view.js +1 -11
- package/src/page/board-views.js +17 -0
- package/src/page/board.js +2 -2
- package/src/page/boot-pack.js +26 -0
- package/src/page/boot.js +237 -0
- package/src/page/checklist.js +1 -1
- package/src/page/chrome.js +411 -61
- package/src/page/csv-import.js +17 -2
- package/src/page/document-title-dom.js +40 -0
- package/src/page/document-title-runtime.js +76 -0
- package/src/page/document-title.js +9 -0
- package/src/page/drag.js +48 -13
- package/src/page/drop.js +2 -1
- package/src/page/editor.js +330 -86
- package/src/page/feature-loader.js +72 -0
- package/src/page/features/board.js +12 -0
- package/src/page/features/code.js +13 -0
- package/src/page/features/media.js +290 -0
- package/src/page/features/registry.js +23 -0
- package/src/page/features/table.js +383 -0
- package/src/page/{tool-view.js → features/tool.js} +33 -2
- package/src/page/format-codec.js +215 -0
- package/src/page/format-gate.js +179 -0
- package/src/page/format-level.js +157 -0
- package/src/page/highlight-slot.js +23 -0
- package/src/page/highlight.js +30 -16
- package/src/page/history-intent.js +78 -0
- package/src/page/inline.js +18 -25
- package/src/page/items.js +52 -11
- package/src/page/link.js +1 -0
- package/src/page/markdown.js +86 -1
- package/src/page/media-views.js +3 -0
- package/src/page/media.js +33 -245
- package/src/page/outline-cache.js +11 -0
- package/src/page/placeholder.js +27 -7
- package/src/page/projection.js +196 -50
- package/src/page/reader-patch.js +306 -0
- package/src/page/recover.js +1 -1
- package/src/page/rich/page-tool.js +1 -4
- package/src/page/runtime-owner.js +27 -0
- package/src/page/save-projection.js +7 -4
- package/src/page/schema.js +14 -0
- package/src/page/table-rect-key.js +3 -0
- package/src/page/table-select.js +4 -3
- package/src/page/table-style.js +1 -1
- package/src/page/table-views.js +3 -0
- package/src/page/table.js +8 -293
- package/src/page/themes/light-1.css +139 -2
- package/src/page/themes/light-1.source.css +269 -0
- package/src/page/tool-capability.js +3 -0
- package/src/page/tool-views.js +3 -0
- package/src/page/view.js +390 -107
- package/src/page/ybind/awareness.js +172 -0
- package/src/page/ybind/binding.js +9 -1
- package/src/page/ybind/bridge.js +50 -47
- package/src/page/ybind/decode.js +52 -19
- package/src/page/ybind/doc.js +27 -2
- package/src/page/ybind/group.js +12 -3
- package/src/page/ybind/index.js +2 -0
- package/src/page/ybind/lineage.js +71 -0
- package/src/page/ybind/marks.js +25 -1
- package/src/page/ybind/migrate.js +48 -13
- package/src/page/ybind/moves.js +32 -21
- package/src/page/ybind/positions.js +50 -0
- package/src/page/ybind/provider.js +84 -22
- package/src/page/ybind/recovery-proof.js +191 -0
- package/src/page/ybind/recovery-replay.js +130 -0
- package/src/page/ybind/tokens.js +15 -6
- package/src/page/ybind/walk.js +10 -3
- package/src/page/ybind/writer.js +48 -4
- package/src/plugins/ai-edit.js +167 -32
- package/src/plugins/bind-text.js +218 -0
- package/src/plugins/cms.js +93 -0
- package/src/plugins/indicator.js +57 -5
- package/src/plugins/live.js +282 -34
- package/src/plugins/menu/claygoo.svg.js +1 -0
- package/src/plugins/menu/seo-head.js +323 -0
- package/src/plugins/menu/seo.js +849 -0
- package/src/plugins/menu.js +425 -0
- package/src/plugins/page-view.js +131 -0
- package/src/plugins/page.js +1022 -275
- package/src/plugins/people.js +158 -31
- package/src/plugins/richclay.js +119 -9
- package/src/plugins/sortable.js +370 -60
- package/src/plugins/source.js +189 -366
- package/src/plugins/undo.js +289 -19
- package/src/plugins/unsent.js +132 -0
- package/src/plugins/upgrade-run.js +1 -0
- package/src/plugins/upgrade.js +210 -0
- package/src/plugins/upload-task.js +571 -0
- package/src/plugins/upload-ui.js +265 -0
- package/src/plugins/upload.js +34 -153
- package/src/plugins/visitor-drafts/inert.js +32 -0
- package/src/plugins/visitor-drafts/owner-chip.js +3 -0
- package/src/plugins/visitor-drafts/prompt.js +2 -2
- package/src/plugins/visitor-drafts-owner.js +85 -0
- package/src/plugins/visitor-drafts.js +31 -42
- package/src/plugins/wire.js +82 -1
- package/src/reader-core.js +26 -0
- package/src/recovery/conflicts.js +287 -0
- package/src/recovery/identity.js +154 -0
- package/src/recovery/store.js +792 -0
- package/src/recovery/undo.js +257 -0
- package/src/server/checkpoint/index.js +68 -4
- package/src/server/offline-runtime/index.js +214 -0
- package/src/server/rooms/index.js +2 -1
- package/src/server/rooms/live-data-rooms.js +2 -2
- package/src/server/rooms/page-admission.js +33 -0
- package/src/server/rooms/page-lineage.js +56 -0
- package/src/server/rooms/page-rebase.js +11 -5
- package/src/server/rooms/page-state.js +2 -0
- package/src/server/rooms/page-write-admission.js +9 -3
- package/src/source/session.js +705 -0
- package/src/sync/conflict-revert.js +5 -4
- package/src/sync/conflicts-edit.js +119 -0
- package/src/sync/conflicts-facade.js +49 -0
- package/src/sync/conflicts.js +99 -1
- package/src/sync/editing-marker.js +37 -6
- package/src/sync/editing-sender.js +8 -1
- package/src/sync/live-sync-edit.js +63 -0
- package/src/sync/live-sync.js +364 -119
- package/src/sync/local-presence.js +187 -0
- package/src/sync/merge-declarations.js +10 -0
- package/src/sync/merge-engine.js +12 -0
- package/src/sync/presence-store.js +412 -0
- package/src/sync/presence-target.js +243 -0
- package/src/sync/presence.js +72 -41
- package/src/sync/saved-handoff.js +200 -0
- package/src/sync/saved-stream.js +535 -0
- package/src/sync/version-guard.js +92 -0
- package/src/sync/wire-profile.js +81 -0
- package/src/ui/bevel-controls.js +2 -8
- package/src/ui/page-scheme.js +7 -0
- package/src/ui/skins/cms.js +1 -1
- package/src/ui/theme-config.js +150 -0
- package/src/ui/theme.js +6 -138
- package/src/ui/toast-lazy.js +11 -0
- package/src/vendor/LICENSES-optional.md +253 -0
- package/src/vendor/highlight.vendor.js +3 -0
- package/src/vendor/hljs-bash.vendor.js +2 -0
- package/src/vendor/hljs-css.vendor.js +2 -0
- package/src/vendor/hljs-javascript.vendor.js +2 -0
- package/src/vendor/hljs-json.vendor.js +2 -0
- package/src/vendor/hljs-python.vendor.js +2 -0
- package/src/vendor/hljs-xml.vendor.js +2 -0
- package/src/vendor/hyper-html-api-data.vendor.js +1 -1
- package/src/vendor/hyper-html-api-upgrade.vendor.js +5 -0
- package/src/vendor/hyper-morph-identity.vendor.js +2 -0
- package/src/vendor/hyper-morph-json.vendor.js +3 -0
- package/src/vendor/hyper-morph.vendor.js +6 -6
- package/src/vendor/hyper-undo.vendor.js +1 -1
- package/src/vendor/hypercms.vendor.js +169 -84
- package/src/vendor/marked.vendor.js +68 -0
- package/src/vendor/overtype.vendor.js +994 -0
- package/src/vendor/richclay.vendor.js +17 -17
- package/src/vendor/sap-core.vendor.js +5 -5
- package/src/vendor/sap-ownership.vendor.js +11 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./c-VHNSBD2M.js";function z(e){let a=e.regex,s={},i={begin:/\$\{/,end:/\}/,contains:["self",{begin:/:-/,contains:[s]}]};Object.assign(s,{className:"variable",variants:[{begin:a.concat(/\$[\w\d#@][\w\d_]*/,"(?![\\w\\d])(?![$])")},i]});let t={className:"subst",begin:/\$\(/,end:/\)/,contains:[e.BACKSLASH_ESCAPE]},c={begin:/<<-?\s*(?=\w+)/,starts:{contains:[e.END_SAME_AS_BEGIN({begin:/(\w+)/,end:/(\w+)/,className:"string"})]}},n={className:"string",begin:/"/,end:/"/,contains:[e.BACKSLASH_ESCAPE,s,t]};t.contains.push(n);let o={match:/\\"/},r={className:"string",begin:/'/,end:/'/},l={match:/\\'/},m={begin:/\$?\(\(/,end:/\)\)/,contains:[{begin:/\d+#[0-9a-f]+/,className:"number"},e.NUMBER_MODE,s]},d=["fish","bash","zsh","sh","csh","ksh","tcsh","dash","scsh"],p=e.SHEBANG({binary:`(${d.join("|")})`,relevance:10}),h={className:"function",begin:/\w[\w\d_]*\s*\(\s*\)\s*\{/,returnBegin:!0,contains:[e.inherit(e.TITLE_MODE,{begin:/\w[\w\d_]*/})],relevance:0},u=["if","then","else","elif","fi","for","while","until","in","do","done","case","esac","function","select"],b=["true","false"],f={match:/(\/[a-z._-]+)+/},g=["break","cd","continue","eval","exec","exit","export","getopts","hash","pwd","readonly","return","shift","test","times","trap","umask","unset"],w=["alias","bind","builtin","caller","command","declare","echo","enable","help","let","local","logout","mapfile","printf","read","readarray","source","type","typeset","ulimit","unalias"],y=["autoload","bg","bindkey","bye","cap","chdir","clone","comparguments","compcall","compctl","compdescribe","compfiles","compgroups","compquote","comptags","comptry","compvalues","dirs","disable","disown","echotc","echoti","emulate","fc","fg","float","functions","getcap","getln","history","integer","jobs","kill","limit","log","noglob","popd","print","pushd","pushln","rehash","sched","setcap","setopt","stat","suspend","ttyctl","unfunction","unhash","unlimit","unsetopt","vared","wait","whence","where","which","zcompile","zformat","zftp","zle","zmodload","zparseopts","zprof","zpty","zregexparse","zsocket","zstyle","ztcp"],k=["chcon","chgrp","chown","chmod","cp","dd","df","dir","dircolors","ln","ls","mkdir","mkfifo","mknod","mktemp","mv","realpath","rm","rmdir","shred","sync","touch","truncate","vdir","b2sum","base32","base64","cat","cksum","comm","csplit","cut","expand","fmt","fold","head","join","md5sum","nl","numfmt","od","paste","ptx","pr","sha1sum","sha224sum","sha256sum","sha384sum","sha512sum","shuf","sort","split","sum","tac","tail","tr","tsort","unexpand","uniq","wc","arch","basename","chroot","date","dirname","du","echo","env","expr","factor","groups","hostid","id","link","logname","nice","nohup","nproc","pathchk","pinky","printenv","printf","pwd","readlink","runcon","seq","sleep","stat","stdbuf","stty","tee","test","timeout","tty","uname","unlink","uptime","users","who","whoami","yes"];return{name:"Bash",aliases:["sh"],keywords:{$pattern:/\b[a-z][a-z0-9._-]+\b/,keyword:u,literal:b,built_in:[...g,...w,"set","shopt",...y,...k]},contains:[p,e.SHEBANG(),h,m,e.HASH_COMMENT_MODE,c,f,n,o,r,l,s]}}export{z as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as R}from"./c-QHWJ5ZIJ.js";import{a as Y,c as j}from"./c-LFPHCXY3.js";import{g as P,q as k}from"./c-OIBUTDXI.js";import{b as H}from"./c-NUHP2XDB.js";var z=Symbol("clay.surfaceTheme"),L=(()=>{"use strict";let r=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'];class d{constructor({targetModal:e,triggers:t=[],onShow:n=()=>{},onClose:u=()=>{},openTrigger:o="data-micromodal-trigger",closeTrigger:x="data-micromodal-close",openClass:F="is-open",disableScroll:E=!1,disableFocus:M=!1,awaitCloseAnimation:C=!1,awaitOpenAnimation:c=!1,debugMode:p=!1}){this.modal=typeof e=="string"?document.getElementById(e):e,this.config={debugMode:p,disableScroll:E,openTrigger:o,closeTrigger:x,openClass:F,onShow:n,onClose:u,awaitCloseAnimation:C,awaitOpenAnimation:c,disableFocus:M},t.length>0&&this.registerTriggers(...t),this.onClick=this.onClick.bind(this),this.onKeydown=this.onKeydown.bind(this)}registerTriggers(...e){e.filter(Boolean).forEach(t=>{t.addEventListener("click",n=>this.showModal(n))})}showModal(e=null){if(this.activeElement=document.activeElement,this.modal.setAttribute("aria-hidden","false"),this.scrollBehaviour("disable"),this.addEventListeners(),this.config.awaitOpenAnimation){let t=()=>{this.modal.removeEventListener("animationend",t,!1),this.setFocusToFirstNode()};this.modal.addEventListener("animationend",t,!1)}else this.setFocusToFirstNode();this.config.onShow(this.modal,this.activeElement,e)}closeModal(e=null){this.modal.setAttribute("aria-hidden","true"),this.removeEventListeners(),this.scrollBehaviour("enable"),this.config.onClose(this.modal,this.activeElement,e)}scrollBehaviour(e){if(!this.config.disableScroll)return;let t=document.querySelector("body");switch(e){case"enable":Object.assign(t.style,{overflow:""});break;case"disable":Object.assign(t.style,{overflow:"hidden"});break;default:}}addEventListeners(){this.modal.addEventListener("touchstart",this.onClick),this.modal.addEventListener("click",this.onClick),document.addEventListener("keydown",this.onKeydown)}removeEventListeners(){this.modal&&(this.modal.removeEventListener("touchstart",this.onClick),this.modal.removeEventListener("click",this.onClick)),document.removeEventListener("keydown",this.onKeydown)}onClick(e){(e.target.hasAttribute(this.config.closeTrigger)||e.target.parentNode.hasAttribute(this.config.closeTrigger))&&(e.preventDefault(),e.stopPropagation(),this.closeModal(e))}onKeydown(e){e.keyCode===27&&this.closeModal(e),e.keyCode===9&&this.retainFocus(e)}getFocusableNodes(){let e=this.modal.querySelectorAll(r);return Array(...e)}setFocusToFirstNode(){if(this.config.disableFocus)return;let e=this.getFocusableNodes();if(e.length===0)return;let t=e.filter(n=>!n.hasAttribute(this.config.closeTrigger));t.length>0&&t[0].focus(),t.length===0&&e[0].focus()}retainFocus(e){let t=this.getFocusableNodes();if(t.length!==0)if(t=t.filter(n=>n.offsetParent!==null),!this.modal.contains(document.activeElement))t[0].focus();else{let n=t.indexOf(document.activeElement);e.shiftKey&&n===0&&(t[t.length-1].focus(),e.preventDefault()),!e.shiftKey&&t.length>0&&n===t.length-1&&(t[0].focus(),e.preventDefault())}}}let l=null,g=(i,e)=>{let t=[];return i.forEach(n=>{let u=n.attributes[e].value;t[u]===void 0&&(t[u]=[]),t[u].push(n)}),t},f=i=>{if(!document.getElementById(i))return console.warn(`MicroModal: \u2757Seems like you have missed %c'${i}'`,"background-color: #f8f9fa;color: #50596c;font-weight: bold;","ID somewhere in your code. Refer example below to resolve it."),console.warn("%cExample:","background-color: #f8f9fa;color: #50596c;font-weight: bold;",`<div class="modal" id="${i}"></div>`),!1},a=i=>{if(i.length<=0)return console.warn("MicroModal: \u2757Please specify at least one %c'micromodal-trigger'","background-color: #f8f9fa;color: #50596c;font-weight: bold;","data attribute."),console.warn("%cExample:","background-color: #f8f9fa;color: #50596c;font-weight: bold;",'<a href="#" data-micromodal-trigger="my-modal"></a>'),!1},m=(i,e)=>{if(a(i),!e)return!0;for(let t in e)f(t);return!0};return{init:i=>{let e=Object.assign({},{openTrigger:"data-micromodal-trigger"},i),t=[...document.querySelectorAll(`[${e.openTrigger}]`)],n=g(t,e.openTrigger);if(!(e.debugMode===!0&&m(t,n)===!1))for(let u in n){let o=n[u];e.targetModal=u,e.triggers=[...o],l=new d(e)}},show:(i,e)=>{let t=e||{};t.targetModal=i,!(t.debugMode===!0&&f(i)===!1)&&(l&&l.removeEventListeners(),l=new d(t),l.showModal())},close:()=>{l&&(l.closeModal(),l=null)}}})(),G=(()=>{let r="",d="",l="",g="100",f="",a="",m="",b,T=!0,v=!0,i=!1,e=[],t=[],n=[];return{isShowing:!1,open(){let o=e,x=t,F=n;e=[],t=[],n=[];let E=!1,M=()=>{E||(E=!0,x.forEach(s=>s()))};(this.isShowing||document.querySelector("[data-clay-modal]"))&&(this._dismiss?.(),this._cleanupListeners?.(),document.querySelectorAll("[data-clay-modal]").forEach(s=>{Y.get(s)?.(),s.remove()}),this.isShowing=!1,document.body.style.overflow=""),this._dismiss=M;let C=b===void 0?R():b,c=j({zIndex:g,closable:!!f,titled:!!a,...m?{width:m}:{},theme:C}),p=c.root,q=c.overlay,N=c.panel,O=c.body,A=c.footer,$=c.close,D={theme:C,parts:["dialog.button"],labelParts:["dialog.buttonLabel"]},y=P("",D),w=P("",{variant:"primary",...D});w.type="submit",A.append(y,w);let S=(s,h)=>{h instanceof Node?s.append(h):s.innerHTML=h};S(O,r),S(w.firstChild,d),S(y.firstChild,l),a&&S(c.heading,a),a&&N.setAttribute("aria-label",c.heading.textContent.trim()),k(O,!(r===""||r==null),"block"),(r===""||r==null)&&a&&H(A,"border-top","0"),document.body.prepend(p);let B=!1;function I(s){B=q.contains(s.target)&&!N.contains(s.target)}function _(s){(y.contains(s.target)||$?.contains(s.target)||T&&B&&!N.contains(s.target)&&q.contains(s.target))&&L.close(),B=!1}function K(s){if(p.contains(s.target)){s.preventDefault();let h=!0;for(let V of o)try{if(V()===!1){h=!1;break}}catch{h=!1;break}h&&(E=!0,L.close())}}document.addEventListener("mousedown",I),document.addEventListener("click",_),document.addEventListener("submit",K),this._cleanupListeners=()=>{document.removeEventListener("mousedown",I),document.removeEventListener("click",_),document.removeEventListener("submit",K)};function U(){k(A,!!(d||l),"flex"),k(w,!!d,"inline-flex"),k(y,!!l,"inline-flex")}if(U(),L.show(p,{disableScroll:v,disableFocus:!0,onClose:s=>{M(),p.remove(),r="",d="",l="",g="100",f="",a="",m="",b=void 0,T=!0,v=!0,i=!1,this.isShowing=!1,document.removeEventListener("mousedown",I),document.removeEventListener("click",_),document.removeEventListener("submit",K),this._cleanupListeners=null,this._dismiss=null}}),this.isShowing=!0,F.forEach(s=>s()),!i){let s=O.querySelector(":is(input,textarea,button):not([hidden])")||[w,y].find(h=>!h.hidden);s?.focus(),s?.setSelectionRange?.(-1,-1)}},close(){L.close()},get html(){return r},set html(o){r=o},get closeHtml(){return f},set closeHtml(o){f=o},get title(){return a},set title(o){a=o},get width(){return m},set width(o){m=o},get[z](){return b},set[z](o){b=o},get yes(){return d},set yes(o){d=o},get no(){return l},set no(o){l=o},get zIndex(){return g},set zIndex(o){g=o},get disableFocus(){return i},set disableFocus(o){i=o},get disableScroll(){return v},set disableScroll(o){v=o},get onYes(){return o=>{e.push(o)}},set onYes(o){e=[o]},get onNo(){return o=>{t.push(o)}},set onNo(o){t=[o]},get onOpen(){return o=>{n.push(o)}},set onOpen(o){n=[o]}}})(),ee=G;export{z as a,ee as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as r}from"./c-VKEDWYDF.js";import{i as o}from"./c-7O6AFR65.js";import{k as c}from"./c-35NBGMZB.js";var l="[editmode\\:resource]:is(style, link, script)",u='[editmode\\:resource]:is(style, link, script)[type^="inert/"]',i="inert/";function s(e){let t=e.getAttribute("type");return t&&t.startsWith(i)?!1:(e.setAttribute("type",i+(t||"")),!0)}function m(e){let t=e.getAttribute("type").slice(i.length);t?e.setAttribute("type",t):e.removeAttribute("type")}function d(){c(e=>{e.querySelectorAll(l).forEach(s)})}function f(){o&&r(()=>{a()})}function a(e=document){let t=(e.ownerDocument||e)===document;e.querySelectorAll(u).forEach(n=>{m(n),t&&n.replaceWith(n.cloneNode(!0))})}function R(){document.querySelectorAll(l).forEach(e=>{s(e)&&e.replaceWith(e.cloneNode(!0))})}function b(){d(),f()}export{l as a,a as b,R as c,b as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as Ge,b as oe,d as he,e as ce,f as We}from"./c-Z36J63PP.js";import{a as $e,b as je,c as ae,d as ze}from"./c-LZJPNR2W.js";import{a as C,b as W}from"./c-FILLTJA7.js";import{b as Ue}from"./c-5VYOWDTI.js";import{b as se,c as re,d as E,f as le,h as Oe}from"./c-7VGZ7RU5.js";import{a as A}from"./c-HT33EQRN.js";import{a as Ne}from"./c-TQEMVJCS.js";import{a as te,b as Me,c as P,d as ne,e as ie,h as Be}from"./c-3IQRECYS.js";import{e as Pe}from"./c-AYVOREBE.js";import{d as Ae}from"./c-IJUK2GPW.js";import{a as De,i as G,m as Q}from"./c-7O6AFR65.js";import{b as k,h as ee,l as F,p as Fe,q as z,r as qe,t as q}from"./c-35NBGMZB.js";import{b as He,c as Ce,d as Re,f as $,h as j,i as Z}from"./c-GHBCCVG4.js";import{m as ke,n as xe}from"./c-HA6INT6J.js";import{a as Ie,b as be,l as Te,m as Le}from"./c-DCFSEJZG.js";function Ye(s){let e=new WeakMap,t=0,n=r=>e.get(r)||null,i=r=>{let a=e.get(r);return a||(a=`${s}:${++t}`,e.set(r,a)),a};return{idOf:n,ensure:i,adopt:(r,a)=>{r&&typeof a=="string"&&a&&e.set(r,a)},exportMap:(r,a)=>{let l={},h=[],c=[],d=(f,y)=>{let m=a(f);m&&(l[y]=i(m));let w=f.children;h.push(w.length),c.push(f.tagName.toLowerCase());for(let p=0;p<w.length;p++)d(w[p],y===""?String(p):`${y}.${p}`)};return d(r,""),l["~"]=h.join(","),l["^"]=c.join(","),l}}}function at(s){return e=>{for(let t of s){let n=t(e);if(typeof n=="string"&&n!=="")return n}return null}}var Et=at([s=>s.getAttribute("data-id"),s=>s.getAttribute("id")]);var ot={"merge-tokens":"tokens","merge-max":"max"};function Je(s,e){if(!e.startsWith("data-")||e==="data-id"||!s?.closest)return null;for(let[t,n]of Object.entries(ot)){let i=s.closest(`[${t}]`);if(i&&i.getAttribute(t).split(/\s+/).includes(e))return n}return null}var _=null,Ve=null,M=new Map;function Y(){return Ve??=Promise.all([import("./c-UKHTLWUW.js"),import("./c-EJTGYSLN.js")]).then(([s,e])=>{_={...s,beginLineageCapture:e.beginLineageCapture};for(let t of[...M.keys()])M.set(t,s.registerContext(t));return _}),Ve}var Xe=()=>_,x={get size(){return _?_.conflicts.size:0},list(){return _?_.conflicts.list():[]},get(s){return _?_.conflicts.get(s):null},acknowledge(s,e={}){if(_)return _.conflicts.acknowledge(s,e);if(!Array.isArray(s))throw new TypeError("clay.conflicts.acknowledge needs an array of ids");return{removedIds:[],remainingIds:[]}},claim(s,e={}){if(_)return _.conflicts.claim(s,e);if(!e.owner)throw new TypeError("clay.conflicts.claim needs an owner");return{release(){}}},registerContext(s){if(_)return _.conflicts.registerContext(s);if(typeof s!="function")throw new TypeError("clay.conflicts.registerContext needs a resolver function");return M.set(s,null),()=>{let e=M.get(s);M.delete(s),e&&e()}},contextFor(s,e){return _?_.conflicts.contextFor(s,e):null},recoveryOf(s){return _?_.conflicts.recoveryOf(s):null},hasPendingApply(){return _?_.conflicts.hasPendingApply():!1}};var u=null,de=null;function R(){return de??=new Promise(s=>setTimeout(s,0)).then(()=>import("./c-IU3IYEU6.js")).then(s=>u=s).catch(s=>{throw de=null,s}),de}var _e=null,ue=null;function ct(){return ue??=import("./c-G2BUZITR.js").then(s=>_e=s.presence).catch(s=>{throw ue=null,s}),ue}var Ze=Q().phase==="entering";G&&!Ze&&R().catch(()=>{});G&&Y().catch(()=>{});var D=null,fe=null,V=[];function et(s){D.presence.update(s),D.editingMarker.update(s)}function dt(){return fe??=Promise.all([import("./c-V7PZZRG7.js"),import("./c-LXENEBV7.js")]).then(([s,e])=>{D={presence:s.presence,editingMarker:e.editingMarker};let t=V;V=[];for(let n of t)et(n);return D}).catch(s=>{throw fe=null,s}),fe}function ut(s){if(D){et(s);return}V.push(s),dt().catch(()=>{})}var Ke=Object.freeze({bytes:null,etag:null,seq:null}),ft=()=>({msg:"Not in edit mode",msgType:"skipped",code:null,etag:null}),tt=["[editor-ui]",'[clay~="editor-ui"]',"[save-ignore]","[snapshot-remove]","[no-snapshot]","[no-save]","[save-remove]","[freeze] *","[save-freeze] *",'[clay~="no-save"]','[clay~="no-snapshot"]','[clay~="freeze"] *',Te,Ie].join(","),nt='[clay~="freeze"], [freeze], [save-freeze]';function J(s){for(let e of s.querySelectorAll(nt))e.replaceChildren();return j()&&Re(s),s}function Qe(s){if(s==null)return s;let e=typeof s=="string"?new DOMParser().parseFromString(s,"text/html"):s;return ee(e),J(e),e}var pt=[Le,'[clay~="no-watch"]',"[no-watch]","[mutations-ignore]"].join(","),_t=(s,e,t)=>ke(s,e,t)||be.test(e.toLowerCase()),it=s=>s.getAttribute("data-id")||s.getAttribute("id")||null;function gt(s){let e=new Map,t=i=>{if(i.matches(tt))return;let r=it(i);r&&e.set(r,(e.get(r)||0)+1);let a=i.localName==="template"&&i.content?i.content.children:i.children;for(let l of a)t(l)},n=s.nodeType===9?[s.documentElement]:s.nodeType===11?s.children:[s];for(let i of n)i&&i.nodeType===1&&t(i);return e}var yt=s=>e=>{let t=it(e);if(!t)return null;let n=e.getRootNode(),i=s.get(n);return i||s.set(n,i=gt(n)),i.get(t)===1?t:null},pe=s=>!!s&&typeof s=="object"&&!Array.isArray(s);function mt(s){return typeof s!="string"||s===""?null:new DOMParser().parseFromString(s,"text/html").documentElement?.getAttribute("documentetag")||null}function vt(s,e){e!=="live"||!s||!u||(u.enableContentEditable(s),u.enableOnClick(s),u.enableAdminInputs(s),u.enableAdminResources(s))}function St(){let{forComparison:s,forDirty:e}=Fe({flushUndo:!1});return[s,e]}var ge=class{constructor(){this.sse=null,this.currentFile=null,this.lastHtml=null,this._diskBase=null,this._diskBaseTicket=0,this._agreeSeq=0,this._saveTicket=0,this._peerBaseTicket=0,this._acceptedSaveTicket=0,this._morphTicket=0,this.clientId=this.generateClientId(),this.resumeId=null,this._savedSnapshot=null,this._sendInFlight=!1,this._queuedSend=null,this._profile=null,this._profilePromise=null,this._sharedData=!1,this._sharedSync=!1,this._liveData=!1,this._editing=null,this._presenceLease=null,this._ready=null,this._startGen=0,this.isPaused=!1,this.isDestroyed=!1,this.debug=!1,this._lane=G?"live":"saved",this._laneChosen=!1,this._snapshotHandler=null,this.lastSeenSeq=0,this._pendingHtml=null,this._pendingSeq=null,this._pendingIdentityMap=null,this._pendingEtag=null,this._pendingBy=null,this._morphInFlight=!1,this._rafHandle=null,this._represented=Ke,this._handoff=null,this._handoffHeld=!1,this._pendingExternal=null,this._lastExternalSeq=0,this._saveEpoch=0,this._saveSavedHandler=null,this._saveConflictHandler=null,this._settledHandler=null,this._lastIdentityMap=null,this._applyGen=0,this._holdRetryPeer=null,this._holdRetryExt=null,this._servedFetchId=0,this._startupRetry=null,this._engineRetry=null,this._heldLive=!1,this._heldExt=!1,this.identity=Ye(this.clientId),this.onConnect=null,this.onDisconnect=null,this.onUpdate=null,this.onError=null,this.onNotification=null}get unresolvedConflicts(){return x.list().filter(e=>e.kind!=="apply-incomplete")}_log(e,t=null){if(!this.debug)return;let n=`[LiveSync ${new Date().toISOString()}]`;t!==null?console.log(n,e,t):console.log(n,e)}generateClientId(){return Math.random().toString(36).slice(2,11)+Date.now().toString(36)}generateResumeId(){try{let e=new Uint8Array(16);return(globalThis.crypto||window.crypto).getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}catch{return Math.random().toString(36).slice(2)+Date.now().toString(36)}}_seedBases(){if(E())return;let e=F({flushUndo:!1});this._setPeerBase(q(e),this.identity.exportMap(e,k),this._ticket()),this._setDiskBase(z({emitForSync:!1}).forSave,this._ticket())}get lane(){return this._lane}set lane(e){this._lane=e,this._laneChosen=!0}start(e=null,{lane:t,represented:n}={}){if(this.isDestroyed=!1,(this.sse||this._snapshotHandler)&&this.cleanup(),this.currentFile=e||this.detectCurrentFile(),!this.currentFile){console.warn("[LiveSync] No file detected");return}let i=Q().mode==="edit"?"live":"saved",r=this.lane==="live";this._lane=t||(this._laneChosen?this._lane:i),this.lastHtml=null,this._lastIdentityMap=null,this._peerBaseTicket=this._ticket(),this._diskBase=null,this._diskBaseTicket=this._ticket(),this._saveTicket=0,this._savedSnapshot=null,this._applyGen++,this.lastSeenSeq=0,this._lastExternalSeq=0,this._represented=n?Object.freeze({bytes:n.bytes??null,etag:n.etag??null,seq:n.seq??null}):Ke,this._acquireEmptySaved=r&&this.lane==="saved"&&this._represented.bytes===null,this._pendingExternal=null,this.resumeId=this.generateResumeId(),this.lane==="live"&&this._seedBases(),this.lane==="live"&&Y().catch(()=>{}),console.log(`[LiveSync] Starting for: ${this.currentFile} (lane=${this.lane})`);let a=++this._startGen;if(this.lane==="live"&&!(u&&u.baselineSettled())){let l=this._applyGen,h=this._morphTicket,c=this._saveEpoch,d=this.lastHtml,f=this._diskBaseTicket,y=this._diskBase!==null;this._settledHandler=()=>{if(this._settledHandler=null,!(this.isDestroyed||this._startGen!==a)&&!Ae()&&!E()&&this._saveTicket===0&&this._morphTicket===h){if(d!==null&&this._applyGen===l&&this._saveEpoch===c&&this.lastHtml===d){let m=F({flushUndo:!1});this._setPeerBase(q(m),this.identity.exportMap(m,k),this._ticket())}y&&this._diskBaseTicket===f&&this._setDiskBase(z({emitForSync:!1}).forSave,this._ticket())}},document.addEventListener("clay:baseline-settled",this._settledHandler,{once:!0})}this._ready=Promise.all([this.lane==="live"?R():null,this._resolveProfile()]).then(()=>{this.isDestroyed||this._startGen!==a||this.connect()}),this.lane==="live"&&(this.listenForSnapshots(),ct().then(l=>this._startPresence(l,a),()=>{}),this._saveSavedHandler=()=>{this._saveEpoch++;let l=this._saveTicket||this._ticket();this._saveTicket=0,l>this._acceptedSaveTicket&&(this._acceptedSaveTicket=l);let h=u?u.getLastSavedBytes():null;h!=null&&this._setDiskBase(h,l),this._relayCommit()},document.addEventListener("clay:save-saved",this._saveSavedHandler),this._saveConflictHandler=l=>{let h=l.detail&&l.detail.etag;h&&queueMicrotask(()=>{this.isDestroyed||h===te()&&(u?.conflictResolvedBySync(h),this._saveAfterMerge(E(),!1))})},document.addEventListener("clay:save-conflict",this._saveConflictHandler))}cleanup(){this.sse&&(this.sse.close(),this.sse=null),ae(),V=[],D&&(D.presence.clear(),D.editingMarker.clear()),this._editing&&(this._editing.stop(),this._editing=null),this._presenceLease&&(this._presenceLease.detach(),this._presenceLease=null),this._lastRoster=null,this._snapshotHandler&&(document.removeEventListener("clay:snapshot-ready",this._snapshotHandler),this._snapshotHandler=null),this._saveSavedHandler&&(document.removeEventListener("clay:save-saved",this._saveSavedHandler),this._saveSavedHandler=null),this._saveConflictHandler&&(document.removeEventListener("clay:save-conflict",this._saveConflictHandler),this._saveConflictHandler=null),this._settledHandler&&(document.removeEventListener("clay:baseline-settled",this._settledHandler),this._settledHandler=null),this._queuedSend=null,this._rafHandle!=null&&(this._cancelFrame(this._rafHandle),this._rafHandle=null),this._pendingHtml=null,this._pendingSeq=null,this._pendingIdentityMap=null,this._pendingBy=null,this._pendingExternal=null,this._handoff=null,this._handoffHeld=!1,clearTimeout(this._holdRetryPeer),clearTimeout(this._holdRetryExt),this._holdRetryPeer=null,this._holdRetryExt=null,clearTimeout(this._startupRetry),this._startupRetry=null,clearTimeout(this._engineRetry),this._engineRetry=null,this._servedFetchId++}detectCurrentFile(){let e=window.location.pathname;if(e==="/")return"index.html";e=e.replace(/^\//,"");let t=e.match(/^(.*?\.html(?:clay)?)/);return t?t[1]:e}_resolveProfile(){return this._profilePromise||(this._profilePromise=We().then(e=>(this._sharedData=e.sharedData,this._sharedSync=e.sharedSync,this._liveData=e.liveData,this._profile=e.profile,this._log(`Wire profile: ${e.profile.name}`),e.profile))),this._profilePromise}_setHeld(e,t,n){let i=e==="live"?"_heldLive":"_heldExt";this[i]!==t&&(this[i]=t,!t&&!this._heldLive&&!this._heldExt&&Be({fresh:!0,clearIfMissing:!1}),document.dispatchEvent(new CustomEvent(t?"clay:sync-held":"clay:sync-resumed",{detail:{lane:e,el:n||null}})))}_applyEtagFrame(e){return typeof e.etag!="string"||typeof e.html=="string"?!1:(this._log("Dropping a stamp that arrived with no document: nothing proves this tab holds those bytes"),!0)}connect(){if(this.isDestroyed)return;let t=(this._profile||ce.legacy).streamPath(window.location.href,this.lane,this.resumeId,this.clientId);this.sse=new Ge(new URL(t,window.location.origin).href,{shared:this._sharedSync,sharedData:this._sharedData,documentURL:window.location.href,lane:this.lane,clientId:this.clientId,keepAliveWhenHidden:this._liveData&&this.lane==="live",startupCheck:!!De}),this._acquireEmptySaved&&(this._acquireEmptySaved=!1,this._fetchServedDocument(void 0,{repair:!0})),this.sse.onopen=()=>{console.log("[LiveSync] Connected"),this._editing&&this._editing.reconnected(),_e&&_e.reconnect(),this.onConnect&&this.onConnect()},this.sse.addEventListener("open",()=>je({clientId:this.clientId,lane:this.lane})),this.sse.addEventListener("error",()=>ae());for(let n of $e)this.sse.addEventListener(n,i=>{let r;try{r=JSON.parse(i.data)}catch{return}ze(n,r)});this.sse.addEventListener("cursor",n=>{let i;try{i=JSON.parse(n.data)}catch{return}if(!i||i.resync!==!0&&i.startup!==!0)return;let r=i.resync===!0,a=i.startup===!0&&!r;console.log(r?"[LiveSync] Server could not replay everything; refetching the document":"[LiveSync] Checking the served document against the version this tab was served"),this._fetchServedDocument(typeof i.seq=="number"?i.seq:void 0,{repair:r,startup:a})}),this.sse.addEventListener("presence",n=>{let i;try{i=JSON.parse(n.data)}catch{return}ut(i),this._lastRoster=i,this._editing&&this._editing.roster(i)}),this.sse.onmessage=n=>{let i=JSON.parse(n.data),{seq:r}=i;if(typeof r=="number"&&r<=this.lastSeenSeq){this._log(`Dropping stale message: seq=${r}, lastSeen=${this.lastSeenSeq}`);return}if(typeof r=="number"&&(this.lastSeenSeq=r),i.type==="notification"){if(this._maybeAcceptExternalChange(i))return;this.handleNotification(i);return}if(i.error){console.error("[LiveSync] Server error:",i.error),this.onError&&this.onError(new Error(i.error));return}if(this._applyEtagFrame(i))return;let{html:a,sender:l,identityMap:h}=i;if(l===this.clientId){this._log("Ignoring own message (sender matches clientId)");return}if(typeof a!="string"){console.error("[LiveSync] Received invalid html, ignoring");return}let c=typeof i.etag=="string"&&i.etag?i.etag:null;if(this.lane==="live"&&!c&&Me()){this._log(`Dropping an unstamped live frame on a stamping host (seq=${r})`);return}if(this.lane==="saved"&&a===this._represented.bytes){this._represented=Object.freeze({bytes:a,etag:c||null,seq:r??null}),P(c);return}if(c&&a===this.lastHtml){this._log(`Taking the stamp from a peer save of content already applied (seq=${r})`),P(c),u&&u.isSaveConflicted()&&(u.conflictResolvedBySync(c),this._saveAfterMerge(E(),!1));return}this._log(`Received update from: ${l} (my clientId: ${this.clientId}, seq=${r})`),this.applyUpdate(a,r,h,c,i.by),this.onUpdate&&this.onUpdate({html:a,sender:l,seq:r,identityMap:h,etag:c})},this.sse.onerror=()=>{this.sse.readyState===EventSource.CONNECTING?console.log("[LiveSync] Reconnecting..."):this.sse.readyState===EventSource.CLOSED&&(console.log("[LiveSync] Connection closed"),this.onError&&this.onError(new Error("Connection closed"))),this.onDisconnect&&this.onDisconnect()}}listenForSnapshots(){this._snapshotHandler=e=>{if(!e.detail||e.detail.forSave!==!0)return;this._saveTicket=this._ticket();let{documentElement:t}=e.detail;if(!t)return;this._log("snapshot-ready received, preparing to send");let n=q(t),i=this.identity.exportMap(t,k);this._savedSnapshot={html:n,identityMap:i,ticket:this._saveTicket}},document.addEventListener("clay:snapshot-ready",this._snapshotHandler)}_enqueueSend(e,t,n=null){if(!this._profile){this._queuedSend={html:e,identityMap:t,etag:n},this._resolveProfile().then(()=>this._flushQueuedSend());return}if(this._sendInFlight){this._queuedSend={html:e,identityMap:t,etag:n};return}this._postUpdate(e,t,n)}_flushQueuedSend(){if(this.isDestroyed||this._sendInFlight)return;let e=this._queuedSend;e&&(this._queuedSend=null,this._postUpdate(e.html,e.identityMap,e.etag))}_relayCommit(){if(this.isDestroyed)return;let e=te(),t=this._savedSnapshot;if(this._savedSnapshot=null,!t||typeof t.html!="string")return;let n=!e&&t.html===this.lastHtml;if(this._setPeerBase(t.html,t.identityMap,t.ticket),n){this._log("Skipping send - HTML unchanged");return}this._enqueueSend(t.html,t.identityMap,e||null)}_postUpdate(e,t,n=null,i=0){this._log(`Sending update (HTML length: ${e.length})`),this._sendInFlight=!0;let r=!1,a=this._profile||ce.legacy;fetch(new URL(a.relayPath,window.location.origin).href,{method:"POST",headers:{"Content-Type":"application/json",[a.documentHeader]:window.location.href,[Ne]:String(1)},body:JSON.stringify({[a.snapshotKey]:e,sender:this.clientId,identityMap:t,...n?{etag:n}:{}})}).then(l=>{l.ok||(console.warn("[LiveSync] Save returned status:",l.status),r=l.status>=500||l.status===408||l.status===429)}).catch(l=>{console.error("[LiveSync] Save failed:",l),this.onError&&this.onError(l),r=!0}).finally(()=>{this._sendInFlight=!1;let l=this._queuedSend;if(this._queuedSend=null,l){this._postUpdate(l.html,l.identityMap,l.etag);return}!r||!n||i>=3||this.isDestroyed||(this._sendInFlight=!0,setTimeout(()=>{if(this._sendInFlight=!1,this.isDestroyed)return;let h=this._queuedSend;this._queuedSend=null,h?this._postUpdate(h.html,h.identityMap,h.etag):this._postUpdate(e,t,n,i+1)},500*2**i))})}_startPresence(e,t){return this.isDestroyed||this._startGen!==t||this._presenceLease?null:e.connect({send:n=>this._postPresence(n)}).then(n=>this.isDestroyed||this._startGen!==t?(n?.detach(),null):(this._presenceLease=n||null,Pe("presence-editing")),()=>!1).then(n=>{if(!(!n||this.isDestroyed||this._startGen!==t||this._editing))return R().then(i=>{this.isDestroyed||this._startGen!==t||this._editing||(this._editing=new i.EditingSender({}),this._editing.start(),this._editing.roster(this._lastRoster))})})}_postPresence(e){let t=new URL("/_/presence",window.location.origin);return t.searchParams.set("client-id",this.clientId),fetch(t.href,{method:"POST",headers:{"Content-Type":"application/json","Document-URL":window.location.href},body:JSON.stringify(e)}).then(n=>n.ok,()=>!1)}_maybeAcceptExternalChange(e){if(this.lane!=="live")return!1;let t=e.data;return t&&t.kind==="external-change"?(typeof t.html=="string"?this._enqueueExternal(t.html,e.seq,t.etag,t.by):this._fetchExternalChange(e.seq),!0):typeof e.msg=="string"&&e.msg.endsWith("changed on disk outside this tab")?(this._fetchExternalChange(e.seq),!0):!1}_enqueueExternal(e,t,n,i){if(typeof t=="number"){if(t<=this._lastExternalSeq){this._log(`Dropping replayed external change: seq=${t}`);return}this._lastExternalSeq=t}this._pendingExternal={html:e,seq:t,saveEpoch:this._saveEpoch,etag:typeof n=="string"&&n?n:null,by:i??null},this._scheduleNextFrame()}_fetchExternalChange(e){if(typeof e=="number"){if(e<=this._lastExternalSeq)return;this._lastExternalSeq=e}this._fetchServedDocument(e)}_fetchServedDocument(e,{attempt:t=0,repair:n=!1,startup:i=!1}={}){if(i&&(this._morphInFlight||this._pendingHtml!=null||this._pendingExternal!=null)){this._retryStartup(t);return}let r=this._saveEpoch,a=this._startGen,l=this.lastSeenSeq,h=this._applyGen,c=++this._servedFetchId;n&&typeof e!="number"&&(e=this._lastExternalSeq),fetch(new URL(window.location.href),{cache:"no-store"}).then(d=>d.ok?d.text():null).then(d=>{if(this.isDestroyed||d==null||this._startGen!==a)return;let f=mt(d),y=i||n&&!!f;if(y){if(c!==this._servedFetchId){n&&this._retryStartup(t+1,{repair:n,startup:i},typeof e=="number"?Math.max(e,this._lastExternalSeq):e);return}if(r!==this._saveEpoch||l!==this.lastSeenSeq||h!==this._applyGen||this._morphInFlight||this._pendingHtml!=null||this._pendingExternal!=null){this._retryStartup(t+1,{repair:n,startup:i},e);return}if(f){if(f===ne()){(n||i)&&this.lane==="saved"&&(this._represented=Object.freeze({bytes:d,etag:f,seq:e??null}));return}}else if(!n)return}else if(typeof e=="number"&&e<this._lastExternalSeq){n&&t<3&&this._fetchServedDocument(this._lastExternalSeq,{attempt:t+1,repair:n,startup:i});return}else if(this._saveEpoch>r){t<3&&(console.log("[LiveSync] Refetching external change: own save landed mid-fetch"),this._fetchServedDocument(e,{attempt:t+1,repair:n,startup:i}));return}this._pendingExternal={html:d,seq:e,saveEpoch:r,etag:f,by:null,fetchOptions:{repair:n,startup:i,attempt:t,versionCheck:y},startGen:a,seenSeq:l,applyGen:h,fetchId:c},this._scheduleNextFrame()}).catch(d=>{this._log("External-change fetch failed",d),typeof e=="number"&&this._lastExternalSeq===e&&(this._lastExternalSeq=e-1)})}_retryStartup(e=0,t={startup:!0},n){this.isDestroyed||e>3||(clearTimeout(this._startupRetry),this._startupRetry=setTimeout(()=>{if(this._startupRetry=null,!this.isDestroyed){if(this._morphInFlight||this._pendingHtml!=null||this._pendingExternal!=null){this._retryStartup(e,t,n);return}this._fetchServedDocument(n,{...t,attempt:e})}},16))}applyUpdate(e,t,n,i,r){this.isDestroyed||(this._pendingHtml=e,this._pendingSeq=t,this._pendingIdentityMap=n,this._pendingEtag=i??null,this._pendingBy=r??null,this._scheduleNextFrame())}prepareHandoff(e={}){return this._handoff?Promise.resolve(this._handoff):this.isDestroyed?Promise.reject(new Error("LiveSync: stopped")):(this._handoffHeld=!0,this._rafHandle!=null&&(this._cancelFrame(this._rafHandle),this._rafHandle=null),import("./c-J7CA54IP.js").then(({engineHandoff:t})=>t(this,e)).then(t=>this._handoff=t))}_scheduleNextFrame(){this.isDestroyed||this._handoffHeld||this._rafHandle==null&&(this._morphInFlight||(this._rafHandle=this._requestFrame(()=>this._runPending())))}async _runPending(){if(this._rafHandle=null,this.isDestroyed)return;if(!C()){this._morphInFlight=!0;try{await W()}catch(r){this._log("Merge engine failed to load",r),this._engineRetry=setTimeout(()=>this._scheduleNextFrame(),2e3);return}finally{this._morphInFlight=!1}if(this.isDestroyed)return}let e=this._pendingExternal,t=e?.fetchOptions||null,n=!!(t?.startup||t?.versionCheck),i=!1;if(e!=null&&(n&&this._pendingHtml!=null?i=!1:this._pendingHtml==null?i=!0:i=!(typeof e.seq=="number"&&typeof this._pendingSeq=="number"&&this._pendingSeq<e.seq)),i)if(this._pendingExternal=null,typeof e.seq=="number"&&e.seq<this._lastExternalSeq)n&&t?.repair?this._retryStartup((t.attempt||0)+1,t,this._lastExternalSeq):this._log("Dropping superseded external change at drain");else if(n&&e.startGen!==this._startGen)this._log("Dropping superseded startup check at drain");else if(n&&e.fetchId!==this._servedFetchId)t?.repair?this._retryStartup((t.attempt||0)+1,t,this._lastExternalSeq):this._log("Dropping superseded startup check at drain");else if(n&&(e.saveEpoch!==this._saveEpoch||e.seenSeq!==this.lastSeenSeq||e.applyGen!==this._applyGen))this._retryStartup((t.attempt||0)+1,t,e.seq);else if(n&&e.etag!=null&&e.etag===ne())this._log("Startup check found the same version: nothing to apply");else if(!n&&e.saveEpoch!==this._saveEpoch)console.log("[LiveSync] Refetching external change: own save landed after queue"),this._fetchServedDocument(e.seq,t||{});else{this._morphInFlight=!0;try{await this._doApplyExternal(e.html,e.seq,e.etag,e.by,t)}catch(r){console.error("[LiveSync] applyExternal failed:",r)}finally{this._morphInFlight=!1}}else{let r=this._pendingHtml,a=this._pendingSeq,l=this._pendingIdentityMap,h=this._pendingEtag,c=this._pendingBy;if(this._pendingHtml=null,this._pendingSeq=null,this._pendingIdentityMap=null,this._pendingEtag=null,this._pendingBy=null,r==null)return;this._morphInFlight=!0;try{await this._doApplyUpdate(r,a,l,h,c)}catch(d){console.error("[LiveSync] applyUpdate failed:",d)}finally{this._morphInFlight=!1}}!this.isDestroyed&&(this._pendingHtml!=null||this._pendingExternal!=null)&&this._scheduleNextFrame()}_ticket(){return++this._agreeSeq}_setDiskBase(e,t){t<=this._diskBaseTicket||(this._diskBase=e,this._diskBaseTicket=t)}_setPeerBase(e,t,n){return n<this._peerBaseTicket?!1:(this._peerBaseTicket=n,this.lastHtml=e,this._lastIdentityMap=t&&typeof t=="object"&&!Array.isArray(t)?t:null,!0)}_requestFrame(e){return typeof window<"u"&&typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame(e):setTimeout(e,16)}_cancelFrame(e){if(typeof window<"u"&&typeof window.cancelAnimationFrame=="function"){window.cancelAnimationFrame(e);return}clearTimeout(e)}async _mergeIncoming(e,t,{base:n,baseIdentityMap:i=null,captureLocal:r,synthetic:a,source:l="peer",seq:h=null,etag:c=null,extra:d={}}){C()||await W();let{beginApply:f,completeApply:y,failApply:m,beginLineageCapture:w}=Xe()||await Y(),p,v=o=>{p=w(x.list());try{let g=C().HyperMorph.mergeDocument({...o,lineage:p.lineage});return p.returned(),g}catch(g){throw p.invalidate(x.list()),p.finish(x.list()),g}},b=this.identity,st=xe,T=yt(new WeakMap),B=o=>pe(o)?{first:T,map:o,then:T}:T,N=a?o=>T(o)||b.idOf(k(o)||o)||null:T,I=e,me=new Map;if(pe(t)){I=new DOMParser().parseFromString(e,"text/html"),ee(I);let o=C().HyperMorph.importMap(I.documentElement,t);for(let g of I.querySelectorAll("[data-id], [id]")){let S=T(g),we=S&&o.get(g);we&&me.set(S,we)}}I=Qe(I);let X={live:document,remote:I,ignore:o=>o.matches(tt),opaque:o=>o.matches(nt)||j()&&Ce(o),remoteWins:o=>o.matches(pt),ignoreAttribute:(o,g,S)=>_t(o,g,S)||j()&&He(S||o,g),attributeMerge:Je,protectFocusedValue:!0,keepLiveOnly:l==="peer",scripts:{mergeTags:C().mergeTagRecognizers},hooks:{beforeAttributeUpdated:st},...d},ve=this.lane==="live"&&E(),Se=le(),O,K=null,L=null;if(n==null)O=v({...X,base:null,local:{root:J(r()),toLive:k},identity:{local:N,remote:B(t)}});else if(ve){let o=r(),g=o.cloneNode(!0);K=J(o),L=f({source:l,seq:h,etag:c,root:K,recoveryRoot:g,domain:l==="disk"?"save":"sync"});try{O=v({...X,base:Qe(n),local:{root:K,toLive:k},identity:{base:B(i),local:N,remote:B(t)}})}catch(S){throw m(L,S),S}}else{let o=J(r()),g=o.ownerDocument;g.documentElement!==o&&g.replaceChild(o,g.documentElement),O=v({...X,base:g,local:{root:o,toLive:k},fastPath:!0,identity:{base:N,local:N,remote:B(t)}})}let U=this._ticket();this._morphTicket=U;let H;try{H=await O}catch(o){p.invalidate(x.list());try{L&&m(L,o,{ticket:U})}finally{p.finish(x.list())}throw o}let rt=le().gen!==Se.gen,Ee;try{p.prepareComplete(H,x.list()),Ee=L?y(L,H.conflicts,{ticket:U}):[]}finally{p.finish(x.list())}ve&&!H.localDiverged&&Oe(Se);let lt=new Set(pe(t)?Object.values(t):[]);for(let[o,g]of H.identities){let S=lt.has(g)?g:me.get(g);S&&b.adopt(o,S)}return{report:H,ticket:U,typedDuringWait:rt,conflictIds:Ee}}_saveAfterMerge(e,t){(e||t)&&Ue()&&(u?u.savePageThrottled():ft())}async _doApplyUpdate(e,t,n,i,r=null){if(oe(e)){await he();return}this.lane==="live"&&!u&&await R(),this._log("applyUpdate - pausing mutations and morphing"),this.isPaused=!0;let a=window.scrollX,l=window.scrollY;A.pause(),se();let h=!1,c=!1,d=!1;try{if(this.lane==="live"&&E()&&this.lastHtml===null){console.log("[LiveSync] Holding incoming update: unsaved local edits and no baseline to merge against"),this._setHeld("live",!0,null);let p=this._saveEpoch,v=this.lastSeenSeq;clearTimeout(this._holdRetryPeer),this._holdRetryPeer=setTimeout(()=>{this._holdRetryPeer=null,!(this.isDestroyed||this._pendingHtml!=null)&&this._saveEpoch===p&&this.lastSeenSeq===v&&(this._pendingHtml=e,this._pendingSeq=t,this._pendingIdentityMap=n,this._pendingBy=r,this._scheduleNextFrame())},3e3);return}this._setHeld("live",!1);let{report:f,ticket:y,typedDuringWait:m,conflictIds:w}=await this._mergeIncoming(e,n,{base:this.lastHtml,baseIdentityMap:this._lastIdentityMap,captureLocal:()=>F({flushUndo:!1}),synthetic:!0,source:"peer",seq:t,etag:i});if(h=f.localDiverged,c=m,Z(),window.scrollTo(a,l),this._setPeerBase(e,n,y),this._applyGen++,this._acceptedSaveTicket>y||(typeof i=="string"&&i?(P(i),d=!0):ie()),this.lane==="live"&&!h&&!E()){let{forSave:p,forComparison:v,forDirty:b}=z({emitForSync:!1,flushUndo:!1});u.setLastSavedBaselines(v,b),this._setDiskBase(p,this._ticket())}this.lane==="saved"&&(this._represented=Object.freeze({bytes:e,etag:i||null,seq:t??null})),document.dispatchEvent(new CustomEvent("clay:sync-applied",{detail:{seq:t,source:this.lane==="saved"?"disk":"peer",lane:this.lane,by:r||null,html:e,report:f,unresolved:this.unresolvedConflicts,conflictIds:w}}))}finally{this._log("applyUpdate - morph complete, resuming mutations"),A.resume(),re(),await new Promise(f=>setTimeout(f,0)),this.isPaused=!1}d&&u?.conflictResolvedBySync(i),this._saveAfterMerge(h,c)}async _doApplyExternal(e,t,n=null,i=null,r=null){if(oe(e)){await he();return}this.lane==="live"&&!u&&await R();let a=this._diskBase;this._log(`applyExternal - external disk change (seq=${t})`),this.isPaused=!0;let l=window.scrollX,h=window.scrollY;A.pause(),se();let c=!1,d=!1,f=!1;try{if(this.lane==="live"&&E()&&this._diskBase===null){if(console.log("[LiveSync] Holding external change: unsaved local edits and no baseline to merge against"),this._setHeld("external",!0,null),r?.startup||r?.versionCheck){clearTimeout(this._holdRetryExt),this._holdRetryExt=setTimeout(()=>{if(this._holdRetryExt=null,this.isDestroyed)return;let b=typeof t=="number"?Math.max(t,this._lastExternalSeq):t;this._retryStartup(0,r,b)},3e3);return}let v=this._saveEpoch;clearTimeout(this._holdRetryExt),this._holdRetryExt=setTimeout(()=>{this._holdRetryExt=null,!(this.isDestroyed||this._pendingExternal!=null)&&(this._pendingExternal={html:e,seq:t,saveEpoch:v,etag:n,by:i},this._scheduleNextFrame())},3e3);return}this._setHeld("external",!1);let{report:y,ticket:m,typedDuringWait:w,conflictIds:p}=await this._mergeIncoming(e,null,{base:this._diskBase,captureLocal:()=>qe().saveClone,synthetic:!1,source:"disk",seq:t,etag:n,extra:{beforeApply:v=>vt(v.documentElement,this.lane)}});if(c=y.localDiverged,d=w,Z(),this._setDiskBase(e,m),window.scrollTo(l,h),this._acceptedSaveTicket>m||(typeof n=="string"&&n?(P(n),f=!0):ie()),this.lane==="live"&&!c&&!E()){u.setLastSavedBaselines(...St()),u.setUnsavedChanges(!1);let v=F({flushUndo:!1});this._setPeerBase(q(v),this.identity.exportMap(v,k),m),this._applyGen++}this.lane==="saved"&&(this._represented=Object.freeze({bytes:e,etag:n||null,seq:t??null})),document.dispatchEvent(new CustomEvent("clay:sync-applied",{detail:{seq:t,source:"disk",etag:typeof n=="string"&&n?n:null,by:i||null,html:e,report:y,conflictIds:p,unresolved:this.unresolvedConflicts}}))}finally{this._log("applyExternal - morph complete, resuming mutations"),A.resume(),re(),await new Promise(y=>setTimeout(y,0)),this.isPaused=!1}f&&u?.conflictResolvedBySync(n),this._saveAfterMerge(c,d),a!=null&&$(a)===$(e)&&u&&u.schedulePaintHeal(()=>this._diskBase==null?null:$(this._diskBase))}handleNotification({msgType:e,msg:t,action:n,persistent:i,data:r}){this._log(`Notification received: ${e} - ${t}`),e==="data-loss"||(i&&window.toastPersistent?window.toastPersistent(t,e):window.toast?window.toast(t,e):console.log(`[LiveSync] Notification: ${t}`)),document.dispatchEvent(new CustomEvent("clay:notification",{detail:{msgType:e,msg:t,action:n,persistent:i,data:r}})),this.onNotification&&this.onNotification({msgType:e,msg:t,action:n,persistent:i,data:r})}stop(){this.cleanup(),this.isDestroyed=!0,console.log("[LiveSync] Stopped")}editParticipant(){return R().then(e=>e.syncParticipant(this))}},ye=new ge;typeof window<"u"&&!Ze&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>ye.start()):ye.start());var Yt=(s,e,t)=>W().then(({morph:n})=>n(s,e,t));var Jt=ye;export{x as a,tt as b,pt as c,ge as d,ye as e,Yt as f,Jt as g};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{A as Ae,D as Yt,E as Vt,F as oe,G as ht,H as se,P as jo,R as Bo,S as Ee,T as Ro,a as To,b as $o,c as Do,d as kn,e as _o,f as bn,g as Se,h as Oe,i as Zt,j as Me,o as te,q as No,r as ee,t as st,u as wn,v as Ct,w as Ce,x as Lo,y as ne}from"./c-Y6USGTS5.js";import{a as Ie,c as Zo}from"./c-EDHUR4MX.js";import{c as Go,e as Xo,f as Te,g as Qo}from"./c-54RCDCBU.js";import{A as F,B as vn,C as qo,D as Sn,E as Jo,F as Wo,a as Ko,c as Po,e as re,f as zo,i as Fo,l as wt,o as xn,q as Yo,r as Vo,t as Ho,u as Uo,y as _t,z as Y}from"./c-TR6RMDQ7.js";import{$ as yn,A as kt,B as V,C as bt,D as X,E as R,F as xe,G as ko,H as bo,J as Ft,O as wo,P as ve,Q as gn,R as xo,S as vo,T as So,U as Oo,V as Mo,W as Co,X as Ao,b as q,d as hn,da as Eo,f as we,g as fo,ga as Io,h as mn,ha as tt,j as po,l as ho,m as S,o as mo,p as go,t as yo,y as Dt}from"./c-66O32MV3.js";import{a as ie}from"./c-4L3BTFRK.js";import{a as Qt,b as uo,c as ot,d as be}from"./c-5V3MOVJT.js";var Cn="page-origins",Cr="page-undo-overlap-repair",ts=(e,t)=>JSON.stringify(["span",e,t]),An=(e,t)=>JSON.stringify(["alias",e,t]),es=(e,t)=>JSON.stringify(["boundary",e,t]),Ar=["copy","removed","restore"],ns=/^(?:0|[1-9]\d*)$/,Nt=(e,t)=>`${e}.${t}`,H=e=>Number.isSafeInteger(e)&&e>=0,Er=e=>Number.isSafeInteger(e)&&e>0,Ir=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),$e=e=>new Error(`Conflicting immutable origin record: ${e}`),Tr=e=>{if(typeof e!="string")return!1;let t=e.indexOf(".");if(t<1||t===e.length-1)return!1;let n=e.slice(0,t),o=e.slice(t+1);return ns.test(n)&&ns.test(o)&&H(Number(n))&&H(Number(o))},On=e=>{if(!Ir(e))return null;for(let t of Object.keys(e))if(t!=="blockId"&&t!=="kind"&&t!=="recoveryOf")return null;return typeof e.blockId!="string"||!e.blockId||!Ar.includes(e.kind)||e.recoveryOf!==void 0&&!Tr(e.recoveryOf)?null:e.recoveryOf===void 0?{blockId:e.blockId,kind:e.kind}:{blockId:e.blockId,kind:e.kind,recoveryOf:e.recoveryOf}},$r=(e,t)=>e.blockId===t.blockId&&e.kind===t.kind&&e.recoveryOf===t.recoveryOf,Dr=e=>{if(typeof e!="string"||e.charCodeAt(0)!==91)return null;let t;try{t=JSON.parse(e)}catch{return null}return!Array.isArray(t)||t.length!==3||t[0]!=="span"&&t[0]!=="alias"&&t[0]!=="boundary"?null:H(t[1])&&H(t[2])?t:null};function ce(e){let t=new Map,n=new Map,o=new Map,s=(p,m)=>{let g=0,y=p.length;for(;g<y;){let x=g+y>>1;p[x].clock<m?g=x+1:y=x}return g},r=(p,m)=>{let g=Dr(p);if(!g)return;let[y,x,C]=g;if(y==="alias"){m&&H(m.sourceClient)&&H(m.sourceClock)?n.set(Nt(x,C),{client:m.sourceClient,clock:m.sourceClock}):n.delete(Nt(x,C));return}if(y==="boundary"){let A=On(m);A?o.set(Nt(x,C),A):o.delete(Nt(x,C));return}let T=t.get(x)??[],L=s(T,C);T[L]?.clock===C&&T.splice(L,1),m&&Er(m.length)&&H(m.sourceClient)&&H(m.sourceClock)&&T.splice(s(T,C),0,{client:x,clock:C,length:m.length,sourceClient:m.sourceClient,sourceClock:m.sourceClock}),T.length?t.set(x,T):t.delete(x)};for(let[p,m]of e)r(p,m);let i=p=>{for(let m of p.keysChanged)r(m,e.get(m))};e.observe(i);let c=p=>{let m=n.get(Nt(p.client,p.clock));if(m)return{client:m.client,clock:m.clock};let g=t.get(p.client);if(!g)return{client:p.client,clock:p.clock};let y=0,x=g.length-1,C=-1;for(;y<=x;){let A=y+x>>1;g[A].clock<=p.clock?(C=A,y=A+1):x=A-1}if(C<0)return{client:p.client,clock:p.clock};let T=g[C],L=p.clock-T.clock;return L>=T.length?{client:p.client,clock:p.clock}:{client:T.sourceClient,clock:T.sourceClock+L}},f=p=>{if(!p||!H(p.client)||!H(p.clock))return null;let m=Nt(p.client,p.clock),g=new Set;for(;!g.has(m);){g.add(m);let x=n.get(m);if(!x)break;m=Nt(x.client,x.clock)}if(g.has(m)&&n.has(m))return null;let y=o.get(m);return y?{...y}:null},h=(p,m,g)=>{let y=ts(p,m),x=e.get(y);if(x!==void 0&&(x.length!==g.length||x.sourceClient!==g.sourceClient||x.sourceClock!==g.sourceClock))throw $e(y);let C=t.get(p)??[],T=s(C,m);for(let L of[C[T-1],C[T]])if(L&&L.clock!==m&&L.clock<m+g.length&&m<L.clock+L.length)throw $e(y);x===void 0&&e.set(y,g)};return{origins:e,resolve:c,recordSpans:p=>{let m=[],g=()=>{if(!m.length)return;let y=m[0],x={length:m.length,sourceClient:y.source.client,sourceClock:y.source.clock};if(!H(x.sourceClock+x.length-1))throw new Error(`Unsafe origin span: ${ts(y.dest.client,y.dest.clock)}`);h(y.dest.client,y.dest.clock,x),m.length=0};for(let y of p){if(!y?.dest||!y?.source)throw new Error("Invalid origin destination");let x=y.dest,C=y.source;if(!H(x.client)||!H(x.clock)||!H(C.client)||!H(C.clock))throw new Error("Invalid origin destination");let T=c(C),L=m[m.length-1];L&&L.dest.client===x.client&&L.dest.clock+1===x.clock&&L.source.client===T.client&&L.source.clock+1===T.clock?m.push({dest:x,source:T}):(g(),m.push({dest:x,source:T}))}g()},recordAlias:(p,m)=>{if(!p||!m||!H(p.client)||!H(p.clock)||!H(m.client)||!H(m.clock))throw new Error("Invalid origin destination");let g=c(m),y=An(p.client,p.clock),x=e.get(y);if(x!==void 0&&(x.sourceClient!==g.client||x.sourceClock!==g.clock))throw $e(y);x===void 0&&e.set(y,{sourceClient:g.client,sourceClock:g.clock})},recordBoundary:(p,m)=>{if(!p||!H(p.client)||!H(p.clock))throw new Error("Invalid origin destination");let g=On(m);if(!g)throw new Error(`Invalid boundary record: ${es(p.client,p.clock)}`);let y=es(p.client,p.clock),x=e.get(y);if(x===void 0){e.set(y,g);return}let C=On(x);if(!C||!$r(C,g))throw $e(y)},boundaryOf:f,get size(){return e.size},dispose(){e.unobserve(i)}}}function Pc(e,t,n){let o=[],s=0;for(let r=e._start;r&&s<n;r=r.right){if(r.deleted||!r.countable)continue;let i=s;if(s+=r.length,s<=t)continue;let c=Math.max(0,t-i),f=Math.min(r.length,n-i);for(let h=c;h<f;h++)o.push({client:r.id.client,clock:r.id.clock+h})}return o}var _r=(e,t,n)=>e.some(o=>o.actor===t||o.client!==n.client||n.clock<o.clock||n.clock>=o.clock+o.length?!1:o.sv.some(([s,r])=>s===n.client&&r>n.clock)),Nr=(e,t)=>{let n=0;for(let o=e._start;o;o=o.right)if(!(o.deleted||!o.countable)){if(o.id.client===t.client&&o.id.clock<=t.clock&&t.clock<o.id.clock+o.length)return n+t.clock-o.id.clock;n+=o.length}return null},Lr=(e,t)=>{let n=[];for(let s of t){let r=Nr(e.flow,s);r!==null&&n.push(r)}n.sort((s,r)=>s-r);let o=[];for(let s of n){let r=o[o.length-1];r&&s<=r[1]?r[1]=Math.max(r[1],s+1):o.push([s,s+1])}for(let s=o.length-1;s>=0;s--){let[r,i]=o[s];i>r&&e.flow.delete(r,i-r)}};function zc(e,t,n=ce(e.origins),o=()=>[]){let s=r=>{if(r.origin!==t||!t.currStackItem)return;let i=[],c=[],f=[],h=o(e.gone);Do(r,t.currStackItem.deletions,a=>{if(!(a instanceof Ce)||a.parent!==e.flow||!a.countable||!a.redone)return;let l=a.content instanceof st&&a.content.embed?.b!==void 0;for(let u=0;u<a.length;u++){let p={client:a.id.client,clock:a.id.clock+u},m=n.resolve(p),g={client:a.redone.client,clock:a.redone.clock+u},y=te(e.ydoc.store,g);for(;y instanceof Ce&&y.redone;)g={client:y.redone.client,clock:y.redone.clock+g.clock-y.id.clock},y=te(e.ydoc.store,g);if(!(!(y instanceof Ce)||y.deleted)&&!(g.clock<(r.beforeState.get(g.client)??0))){if(!l&&_r(h,e.ydoc.clientID,p)){f.push(g);continue}(l?c:i).push({dest:g,source:m})}}}),(i.length||c.length)&&e.ydoc.transact(()=>{i.length&&n.recordSpans(i);for(let a of c)n.recordAlias(a.dest,a.source)},Cn),f.length&&e.ydoc.transact(()=>Lr(e,f),Cr)};return e.ydoc.on("beforeObserverCalls",s),()=>e.ydoc.off("beforeObserverCalls",s)}var Hc=typeof TextEncoder=="function"?new TextEncoder:null;var jr=(e,t)=>e.length===t.length&&e.every((n,o)=>n===t[o]);function os(e,t,n=null){let o=n?.mergeUpdatesV2??ee,s=o([e]);return jr(s,o([s,t]))}var En=e=>To(e),At=e=>$o(e),De=12*1024,_e=e=>Qt.exec(e)?.[1]??e;function Qc(e){return{v:1,g:0,y:{seed:En(Oe(e))}}}var Q=class extends Error{constructor(t,n){super(n),this.name="YDecodeError",this.code=t}};function Rr(e){if(e?.v!==1||!e.y||typeof e.y!="object"||Array.isArray(e.y))throw new Q("invalid-value","Expected a version 1 Yjs page value");let t=new Map,n=new Set;for(let[o,s]of Object.entries(e.y)){if(typeof s!="string")throw new Q("invalid-update",`Invalid Yjs update: ${o}`);let r=Qt.exec(o);if(!r){n.add(o);continue}let i=Number(r[2]),c=Number(r[3]);if(!Number.isSafeInteger(i)||!Number.isSafeInteger(c)||c<1||i>=c)throw new Q("invalid-update",`Invalid Yjs update part: ${o}`);let f=t.get(r[1])??{count:c,indices:new Set};if(f.count!==c||f.indices.has(i))throw new Q("invalid-update",`Conflicting Yjs update parts: ${r[1]}`);f.indices.add(i),t.set(r[1],f)}for(let[o,s]of t){if(n.has(o))throw new Q("invalid-update",`Conflicting Yjs update forms: ${o}`);if(s.indices.size!==s.count)throw new Q("incomplete-update",`Incomplete Yjs update: ${o}`)}return ot(e.y)}function Br(e,{strict:t=!1}={}){let n=t?Rr(e):ot(e.y),o=new bn;try{for(let[s,r]of n){let i=t?r.replace(/[\t\n\f\r ]/g,""):r;if(t&&!uo.test(i))throw new Q("invalid-update",`Invalid base64 in Yjs update: ${s}`);Se(o,At(i),ne)}if(t&&(o.store.pendingStructs||o.store.pendingDs))throw new Q("unresolved-update","Yjs page updates have missing prerequisites");return o}catch(s){throw o.destroy(),t&&!(s instanceof Q)?new Q("invalid-update",`Invalid Yjs page update: ${s.message}`):s}}var ss=typeof TextEncoder=="function"?new TextEncoder:null,Kr=e=>ss?ss.encode(e).length:e.length*2,Pr=(e,t)=>_o(kn(e.store),kn(t.store)),zr=(e,t)=>{if(e.size!==t.size)return!1;for(let[n,o]of e)if(t.get(n)!==o)return!1;return!0};function Zc({store:e,ydoc:t,compact:n={},setTimer:o=setTimeout,clearTimer:s=clearTimeout,onStopped:r=()=>{},stats:i={applied:0,offered:0,compactions:0}}){let c=ot(e.value.y),f=new Set,h=null,a=w=>{h||(h=w,r(w))},l=!c.some(([w])=>w[0]==="m"),u=0,p=t.clientID.toString(36),m=w=>`${w}${p}-${(u++).toString(36)}`,g=null,y=e.value.g,x=new Set,C=(w,v)=>{if(v.length<=De)return[[w,v]];let D=Math.ceil(v.length/De);return Array.from({length:D},(E,d)=>[`${w}.${d}.${D}`,v.slice(d*De,(d+1)*De)])},T=(w,v)=>{l=!0,f.add(w),x.add(w);let D=C(w,En(v));e.handle.update(E=>{for(let[d,k]of D)E.y[d]=k})};for(let[w]of c)f.add(w);let L=(w,v)=>{h||v===ne||v===Cn||T(m("u"),w)};t.on("updateV2",L);let A=(w,v)=>{h||f.has(w)||(l=!0,f.add(w),i.applied++,Se(t,At(v),ne))},_=!1,P=!1,G=(w,v)=>{_||=w,P||=v,!g&&(g=o(()=>{g=null,_&&ct(),zt()},0))},Z=()=>{ct(),zt()};function ct(){if(h)return!1;let w=e.value.y,v=new bn;for(let[,b]of ot(w))Se(v,At(b),ne);let D=Me(v),E=Zt(Me(t)),d=Zt(D);if(zr(E,d)&&Pr(t,v))return v.destroy(),_=!1,P=!1,!1;let k=Oe(t,D);return v.destroy(),i.offered++,T(m("r"),k),_=!1,P=!1,!0}let pt={keys:32,room:3840*1024,...n},$=null,Ot=0,j=256,et=new Map,lt=w=>e.handle.update(v=>{for(let D of w)delete v.y[D]}),Jt=(w,v)=>Object.keys(w).filter(D=>v.has(_e(D))),Mt=(w,v)=>{let D=e.value.y??{};lt(v.filter(E=>E in D&&D[E]===w[E]))};function gt(){let w=e.authoritative.y??{},v=e.value.y??{};for(let k of x)k in v||x.delete(k);let D=$?[...$.parts.map(([k])=>k),...$.inputs.keys()]:[],E=new Set([...Object.keys(w),...x,...D]);for(let k of f)E.has(k)||f.delete(k);let d=new Map(ot(w));for(let[k,b]of et)(!E.has(k)||d.get(k)!==b.value)&&et.delete(k)}function Pt(w,v,D,E){let d=et.get(w);return d&&d.value!==v&&(et.delete(w),d=null),d||(et.size>=j&&et.delete(et.keys().next().value),d={value:v,folds:new Map},et.set(w,d)),d.folds.has(D)||d.folds.set(D,os(E,At(v))),d.folds.get(D)}let ye=(w,v)=>{for(let[D,E]of v.held)if(w[D]!==void 0&&w[D]!==E)return!1;return!0},ke=w=>{let v=At(w.merged);for(let[D,E]of w.inputs)if(E!==null&&!Pt(D,E,w.key,v))return!1;return!0};function un(w){let v=$,D=be({v:1,y:w}).y,E=v.parts.filter(([d,k])=>w[d]===k&&D[d]===k);return E.length!==v.parts.length?e.pending.length?!1:($=null,E.length&&Mt(w,E.map(([d])=>d)),Ot=ot(w).length+pt.keys,gt(),!0):e.pending.length||!ye(w,v)||!ke(v)?!1:($=null,Mt(w,Jt(w,v.inputs)),gt(),!0)}function dn(w,v,D){let E=v.filter(([O])=>O[0]==="m"),d=new Map(v),k=new Map(E),b=O=>{let B=k.get(O);return typeof B=="string"&&k.set(O,ee([At(B)])),k.get(O)},M=(O,B,N)=>Pt(O,B,N,b(N)),I=new Set;for(let[O,B]of v)if(!(!D&&O[0]!=="m")){for(let[N]of E)if(!(N===O||I.has(N)||!M(O,B,N))&&!(O[0]==="m"&&O<N&&M(N,d.get(N),O))){I.add(O);break}}return I.size?(Mt(w,Jt(w,I)),!0):!1}function zt(){if(h||!l||e.value.g!==y)return!1;let w=e.authoritative.y;if($)return un(w);let v=ot(w),D=v.length>Math.max(pt.keys,Ot);if(!D&&v.filter(([N])=>N[0]==="m").length<2)return!1;if(dn(w,v,D))return gt(),!0;if(!D)return!1;let E=En(ee(v.map(([,N])=>At(N)))),d=m("m"),k=C(d,E),b={...e.value,y:{...e.value.y}};for(let[N,yt]of k)b.y[N]=yt;if(Kr(JSON.stringify(b))>pt.room)return Ot=v.length+pt.keys,!1;let M=be({v:1,y:w}).y,I=Object.keys(w).filter(N=>!(N in M)).map(_e).filter(N=>N[0]==="m"),O=new Map(v);for(let N of I)O.set(N,null);let B=new Map;for(let N of Jt(w,O))O.get(_e(N))!==null&&B.set(N,M[N]??w[N]);return $={key:d,parts:k,merged:E,inputs:O,held:B},f.add(d),e.handle.update(N=>{for(let[yt,z]of k)N.y[yt]=z}),i.compactions++,!0}let at=w=>{let v=new Set;for(let[,D]of ot(w??{}))for(let E of Zt(No(At(D))).keys())v.add(E);return v},fn=new Map(c),Wt=w=>{let v=at(w),D=[...Zt(Me(t)).keys()];return!v.size||!D.length||D.some(E=>v.has(E))?!0:ot(w??{}).some(([E,d])=>fn.get(E)===d)},Gt=e.onRebase(w=>{if(h)return;let v=w.source==="remote"&&w.frame?w.frame.ops:null,D=v&&v.every(E=>E.path[0]==="y"&&E.path.length===2&&!Qt.test(E.path[1]));if(!D&&w.cause!=="refused"&&!Wt(w.next.y)){a("lineage");return}if(D)for(let E of v)E.op==="set"&&A(E.path[1],E.value);else for(let[E,d]of ot(w.next.y??{}))A(E,d);gt(),G(w.source!=="remote"||!v,w.source!=="remote")}),Xt=e.onDelivery(w=>{if(w.phase!=="refused")return;if(w.code!=="too-large"||h){gt();return}a("too-large");let v=e.authoritative.y??{},D=be({v:1,y:v}).y,E=Object.keys(e.value.y??{}).filter(k=>!(k in v)),d=Object.keys(v).filter(k=>Qt.test(k)&&!(k in D)&&_e(k).slice(1).startsWith(`${p}-`));(E.length||d.length)&<([...E,...d]),gt()});return{known:f,stats:i,settle:Z,reconcile:ct,get reconcilePending(){return P},get stopped(){return h},_diagnostics:()=>({known:f.size,cover:et.size,fold:$?$.parts.length:0,generation:y}),compact:zt,dispose(){Gt(),Xt(),t.off("updateV2",L),g&&s(g)}}}var rs=new WeakMap;function Ne(e){let t=rs.get(e);if(t)return t;t={};for(let[n,o]of X(e.attrs.cols).entries()){let s=[];e.forEach(r=>{n<r.childCount&&s.push(r.child(n).textContent.trim())}),t[o]=vo(e.attrs.cols[o].kind,s)}return rs.set(e,t),t}var sl=Object.freeze({text:"Aa",number:"#",date:"\u{1F4C5}"}),rl=Object.freeze({text:"Text",number:"Number",date:"Date"});var Le="page-history-intent",Fr=500,Yr=(e,t)=>{let n=e.resolve(t);return n.depth?n.node(1).attrs.id:null},Vr=e=>(e.storedMarks??e.selection.$from.marks()).map(t=>`${t.type.name}:${JSON.stringify(t.attrs)}`).sort().join(",");function Tn(e,t,n,o){return{kind:"insert",blockId:Yr(e.doc,t),from:t,end:t+o.length,replaced:t!==n,text:o,marks:Vr(e),at:Date.now()}}function al(e,t){return!e||!t||e.kind!==t.kind?!1:t.kind==="compose"?e.id===t.id:e.blockId!==t.blockId||t.at-e.at>Fr?!1:t.kind==="insert"?!t.replaced&&t.from===e.end&&t.marks===e.marks&&!(/\s$/.test(e.text)&&/^\S/.test(t.text)):t.direction===e.direction&&(t.direction<0?t.to===e.from:t.from===e.from)}var Hr={deleteContentBackward:-1,deleteContentForward:1},In=new WeakMap,Ur=1e3,$n="page-derived";function qr(e){let t=In.get(e)??null;return In.delete(e),t}function Jr(e,t){if(!t||e.before!==t.doc||Date.now()-t.at>Ur||e.getMeta(Po)||e.steps.length!==1)return null;let n=e.steps[0];if(n.slice?.size!==0||n.from===n.to)return null;let o=e.before.resolve(n.from),s=e.before.resolve(n.to);return!o.parent.isTextblock||!o.sameParent(s)?null:{kind:"delete",blockId:o.depth?o.node(1).attrs.id:null,direction:t.direction,from:n.from,to:n.to,at:t.at}}function ul(e,t=null){let n=t?qr(t):null,o=e.filter(i=>!i.getMeta($n));if(o.length!==1)return null;let s=o[0],r=s.getMeta("composition");return r!=null?{kind:"compose",id:r,at:Date.now()}:s.getMeta(Le)??Jr(s,n)}function dl(){return new q.Plugin({props:{handleTextInput(e,t,n,o,s){return e.dispatch(s().setMeta(Le,Tn(e.state,t,n,o))),!0},handleDOMEvents:{beforeinput(e,t){let n=Hr[t.inputType];return n&&In.set(e,{direction:n,at:Date.now(),doc:e.state.doc}),!1}}}})}var{Plugin:Wr,TextSelection:Gr}=q,Dn=S.nodes;var as=(e,t)=>{let n=null;return e.forEach((o,s)=>{!n&&o.type===Dn.table&&o.attrs.id===t&&(n={node:o,pos:s})}),n};function Et(e,t){if(!t)return null;let n=as(e,t.table);if(!n)return null;let o=[];n.node.forEach(p=>o.push(p.attrs.id));let s=X(n.node.attrs.cols),r=[o.indexOf(t.anchor[0]),o.indexOf(t.head[0])],i=[s.indexOf(t.anchor[1]),s.indexOf(t.head[1])];if(r.includes(-1)||i.includes(-1))return null;let c=Math.min(...r),f=Math.max(...r),h=Math.min(...i),a=Math.max(...i),l=[],u=n.pos+1;return n.node.forEach((p,m,g)=>{if(g>=c&&g<=f){let y=[],x=u+1;p.forEach((C,T,L)=>{L>=h&&L<=a&&y.push({cell:C,pos:x}),x+=C.nodeSize}),l.push(y)}u+=p.nodeSize}),{...n,top:c,bottom:f,left:h,right:a,cells:l}}var le=(e,t)=>{let n=e.resolve(t);for(let o=n.depth;o>0;o--)if(n.node(o).type===Dn.table_cell&&o>=3)return{table:n.node(o-2).attrs.id,row:n.node(o-1).attrs.id,col:n.node(o).attrs.col,start:n.start(o)};return null};function je(e,t,n){let o=le(e.state.doc,t),s=le(e.state.doc,n);if(!o||!s||o.table!==s.table)return!1;let r={table:o.table,anchor:[o.row,o.col],head:[s.row,s.col]},i=e.state.tr.setSelection(Gr.create(e.state.doc,s.start)).setMeta(Y,r);e.dispatch(i);let c=Et(e.state.doc,r),f=c?(c.bottom-c.top+1)*(c.right-c.left+1):0;return _t(e,`${f} ${f===1?"cell":"cells"} selected`),!0}function vl(e,t,n,o){let s=e.state.doc.nodeAt(t);if(s?.type!==Dn.table||!s.childCount)return!1;let r=s.childCount-1,i=s.child(0).childCount-1,c=(f,h)=>{let a=t+1;for(let l=0;l<f;l++)a+=s.child(l).nodeSize;a++;for(let l=0;l<h;l++)a+=s.child(f).child(l).nodeSize;return a+1};return n==="row"?je(e,c(o,0),c(o,i)):je(e,c(0,o),c(r,o))}var Xr=new Set(["Shift","Control","Alt","Meta","CapsLock"]),Qr=e=>/[\t\n\r"]/.test(e)?`"${e.replace(/"/g,'""')}"`:e;function Zr(e,t){let n=e.cells.map(r=>r.map(({cell:i})=>Qr(Dt(xe(i)))).join(" ")).join(`
|
|
2
|
+
`),o=t.createElement("table"),s=o.appendChild(t.createElement("tbody"));for(let r of e.cells){let i=s.appendChild(t.createElement("tr"));for(let{cell:c}of r){let f=i.appendChild(t.createElement("td"));f.dataset.col=c.attrs.col,f.append(Uo.serializeFragment(c.content,{document:t}))}}return{text:n,html:o.outerHTML}}function is(e,t){let n=Et(e.doc,Y.getState(e));if(!n)return!1;if(t){let o=e.tr;for(let s of[...n.cells].reverse())for(let{cell:r,pos:i}of[...s].reverse())r.content.size&&o.delete(i+1,i+r.nodeSize-1);o.setMeta(Y,Y.getState(e)),t(F(o))}return!0}var cs=(e,t,n)=>{let{text:o,html:s}=Zr(t,n.dom.ownerDocument);e.clipboardData.setData("text/plain",o),e.clipboardData.setData("text/html",s),e.preventDefault()},ti=(e,t)=>(n,o,s)=>{let r=Y.getState(n),i=Et(n.doc,r);if(!i||!s)return!1;let c=[],f=X(i.node.attrs.cols);i.node.forEach(l=>c.push(l.attrs.id));let h=Math.max(0,Math.min(c.length-1,c.indexOf(r.head[0])+e)),a=Math.max(0,Math.min(f.length-1,f.indexOf(r.head[1])+t));return o&&o(n.tr.setMeta(Y,{...r,head:[c[h],f[a]]})),!0},ls=(e,t)=>{let n=t.target?.closest?.("td");if(!n||!e.dom.contains(n))return null;try{return e.posAtDOM(n,0)}catch{return null}};function Sl(){let e=null;return new Wr({key:Y,state:{init:()=>null,apply(t,n,o,s){let r=t.getMeta(Y);return r!==void 0?r:!n||t.selectionSet||t.docChanged&&!t.getMeta(Ae)?null:Et(s.doc,n)?n:null}},props:{attributes:t=>Y.getState(t)?{class:"has-cell-rect"}:{},createSelectionBetween:t=>Y.getState(t.state)?t.state.selection:null,decorations(t){let n=Et(t.doc,Y.getState(t));return n?hn.DecorationSet.create(t.doc,n.cells.flat().map(({cell:o,pos:s})=>hn.Decoration.node(s,s+o.nodeSize,{class:"is-cell-selected"}))):null},handleKeyDown(t,n){let o=t.state;if(!Y.getState(o))return!1;if(n.key==="Escape")return t.dispatch(o.tr.setMeta(Y,null)),!0;if(n.key==="Backspace"||n.key==="Delete")return is(o,t.dispatch);if(n.shiftKey){let s={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[n.key];if(s)return ti(...s)(o,t.dispatch,t)}return Xr.has(n.key)||(n.metaKey||n.ctrlKey)&&(n.key==="a"||n.key==="c"||n.key==="x"||n.key==="v")||t.dispatch(o.tr.setMeta(Y,null)),!1},handleDOMEvents:{mousedown(t,n){if(n.button!==0)return!1;!n.shiftKey&&Y.getState(t.state)&&t.dispatch(t.state.tr.setMeta(Y,null));let o=ls(t,n);if(o===null)return!1;if(n.shiftKey){let f=Y.getState(t.state),h=(f&&ei(t.state.doc,f))??t.state.selection.$anchor.pos;return le(t.state.doc,h)?(n.preventDefault(),je(t,h,o)):!1}let s=t.dom.ownerDocument,r=o,i=f=>{let h=ls(t,f);if(h===null)return;let a=le(t.state.doc,r),l=le(t.state.doc,h);if(!a||!l||a.table!==l.table)return;let u=Y.getState(t.state);a.row===l.row&&a.col===l.col&&!u||u&&u.head[0]===l.row&&u.head[1]===l.col||(f.preventDefault(),je(t,r,h))},c=()=>{s.removeEventListener("mouseover",i),s.removeEventListener("mouseup",c),e=null};return e?.(),e=c,s.addEventListener("mouseover",i),s.addEventListener("mouseup",c),!1},copy(t,n){let o=Et(t.state.doc,Y.getState(t.state));return!o||!n.clipboardData?!1:(cs(n,o,t),!0)},cut(t,n){let o=Et(t.state.doc,Y.getState(t.state));return!o||!n.clipboardData?!1:(cs(n,o,t),is(t.state,t.dispatch),!0)}}},view:()=>({destroy:()=>e?.()})})}function ei(e,t){let n=as(e,t.table),o=null;return n?.node.forEach((s,r)=>{if(s.attrs.id!==t.anchor[0])return;let i=n.pos+1+r+1;s.forEach(c=>{c.attrs.col===t.anchor[1]&&(o=i+1),i+=c.nodeSize})}),o}var us=e=>{let t=Et(e.doc,Y.getState(e));return t?{row:t.top,cell:t.left,rows:t.bottom-t.top+1,cols:t.right-t.left+1}:null};var ds=new WeakMap;var fs=Object.freeze({row:Object.freeze(["alive","pos"]),col:Object.freeze(["alive","name","kind","width","pos"])}),hs=["name","kind","width","pos"],ni=new Set(["kind","width"]),Lt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),_n=e=>typeof e=="string"&&e.length>0&&!["__proto__","constructor","prototype"].includes(e),ae=e=>{throw new Q("unsupported-content",`Unsupported table field: ${e}`)},ms=e=>e===null||typeof e!="object"?e:JSON.parse(JSON.stringify(e)),xt=(e,t,n,o)=>JSON.stringify([e,t,n,o]);function oi(e){if(typeof e=="string")return!0;if(!Lt(e)||Object.keys(e).sort().join(",")!=="c,m"||typeof e.c!="string"||!Array.isArray(e.m)||!e.m.every(Array.isArray))return!1;let t=Eo(e.m,e.c.length);return t?t.every((n,o)=>{if(typeof n!="string")return!1;if(n.startsWith("@"))return n===Ao&&e.c[o]===Co;try{return yo(S,n),!0}catch{return!1}}):!1}var si=(e,t)=>e==="alive"?typeof t=="boolean":e==="width"?t===null||typeof t=="number"&&Number.isFinite(t)&&t>0:e==="kind"&&t===null||typeof t=="string";function ps(e,t){if(Object.keys(e).length)return;let[n]=Object.keys(t).sort((o,s)=>{let r=t[o].pos??"",i=t[s].pos??"";return r!==i?r<i?-1:1:o<s?-1:o>s?1:0});n&&(e[n]=t[n])}function Re(e,t=null,n=null){let o=new Map,s=new Map,r=new Map;for(let[a,l]of e){let u;try{u=JSON.parse(a)}catch{ae(a)}(!Array.isArray(u)||u.length!==4)&&ae(a);let[p,m,g,y]=u;if((!_n(p)||!_n(g))&&ae(a),m==="cell"?(!_n(y)||!oi(l))&&ae(a):(!Object.hasOwn(fs,m)||!fs[m].includes(y)||!si(y,l))&&ae(a),p!==t)continue;if(m==="cell"){let T=r.get(g)??new Map;T.set(y,l),r.set(g,T);continue}let x=m==="row"?o:s,C=x.get(g)??{};C[y]=l,x.set(g,C)}let i={...Lt(n?.cols)?n.cols:{}},c={...Lt(n?.rows)?n.rows:{}},f={},h={};for(let[a,l]of s){let u=Lt(i[a])?{...i[a]}:{};Object.hasOwn(u,"pos")||(u.pos=""),Object.hasOwn(u,"name")||(u.name="");for(let p of hs)Object.hasOwn(l,p)&&(l[p]===null?delete u[p]:u[p]=l[p]);if(l.alive===!1||!Object.hasOwn(i,a)&&l.alive!==!0){l.alive===!1&&(f[a]=u),delete i[a];continue}i[a]=u}for(let a of new Set([...o.keys(),...r.keys()])){let l=o.get(a)??{},u={pos:"",cells:{},...Lt(c[a])?c[a]:{}};Object.hasOwn(l,"pos")&&(u.pos=l.pos);let p=r.get(a);if(p&&(u.cells={...Lt(u.cells)?u.cells:{},...Object.fromEntries([...p].map(([m,g])=>[m,ms(g)]))}),l.alive===!1||!Object.hasOwn(c,a)&&l.alive!==!0){l.alive===!1&&(h[a]=u),delete c[a];continue}c[a]=u}return ps(i,f),ps(c,h),{cols:i,rows:c}}var Be=(e,t)=>e?.[t]??(ni.has(t)?null:"");function ri(e,t,n,o,s){let r=[],i=(u,p)=>t.has(u)?t.get(u):p,c=(u,p)=>r.push([u,ms(p)]),f=o?.cols??{},h=s?.cols??{},a=o?.rows??{},l=s?.rows??{};for(let u of new Set([...Object.keys(f),...Object.keys(h)])){let p=f[u],m=h[u];if(!m){p&&c(xt(e,"col",u,"alive"),!1);continue}(!p||i(xt(e,"col",u,"alive"),!0)===!1)&&c(xt(e,"col",u,"alive"),!0);for(let g of hs){let y=xt(e,"col",u,g),x=p?Be(p,g):i(y,Be(n?.cols?.[u],g));tt(x)!==tt(Be(m,g))&&c(y,Be(m,g))}}for(let u of new Set([...Object.keys(a),...Object.keys(l)])){let p=a[u],m=l[u];if(!m){p&&c(xt(e,"row",u,"alive"),!1);continue}(!p||i(xt(e,"row",u,"alive"),!0)===!1)&&c(xt(e,"row",u,"alive"),!0);let g=xt(e,"row",u,"pos"),y=m.pos??"";i(g,n?.rows?.[u]?.pos??"")!==y&&c(g,y);let x=Lt(m.cells)?m.cells:{};for(let C of Object.keys(h)){let T=xt(e,"cell",u,C),L=x[C]??"",A=p&&f[C]?p.cells?.[C]??"":i(T,n?.rows?.[u]?.cells?.[C]??"");tt(A)!==tt(L)&&c(T,L)}}return r}function ii(e,t){let n=e.attrs.get(t);return{cols:n?.get("cols")??{},rows:n?.get("rows")??{}}}function $l(e,t,n,o){let s=ii(e,t);for(let[r,i]of ri(t,e.tableFields,s,n,o))e.tableFields.set(r,i)}var Ln=Object.freeze({column:Object.freeze(["alive","name","pos"]),card:Object.freeze(["alive","title","owner","due","placement"])}),gs={column:new Set(Ln.column),card:new Set(Ln.card)},ci=[["column","columns"],["card","cards"]],jn=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),ys=e=>typeof e=="string"&&e.length>0&&!["__proto__","constructor","prototype"].includes(e),Ke=e=>{throw new Q("unsupported-content",`Unsupported board field: ${e}`)},li=e=>e===null||typeof e!="object"?e:JSON.parse(JSON.stringify(e)),Nn=(e,t,n,o)=>JSON.stringify([e,t,n,o]);function bs(e,t){let n=new Map;for(let[o,s]of e){let r;try{r=JSON.parse(o)}catch{Ke(o)}(!Array.isArray(r)||r.length!==4)&&Ke(o);let[i,c,f,h]=r;if((!ys(i)||!ys(f)||!Object.hasOwn(gs,c)||!gs[c].has(h))&&Ke(o),(h==="alive"?typeof s!="boolean":h==="placement"?!jn(s)||Object.keys(s).sort().join(",")!=="columnId,pos"||typeof s.columnId!="string"||typeof s.pos!="string":h==="owner"||h==="due"?s!==null&&typeof s!="string":typeof s!="string")&&Ke(o),i!==t)continue;let a=n.get(c)??new Map,l=a.get(f)??{};l[h]=s,a.set(f,l),n.set(c,a)}return n}var ws=e=>({pos:e.pos??"",name:e.name??""}),xs=e=>({pos:e.placement?.pos??"",col:e.placement?.columnId??"",title:e.title??"",...e.owner!=null?{owner:e.owner}:{},...e.due!=null?{due:e.due}:{}}),Pe=(e,t,n,o)=>Object.fromEntries([...e.get(t)??[]].filter(([,s])=>s.alive!==!1===o).map(([s,r])=>[s,n(r)]));function ze(e,t=null){let n=bs(e,t),o=Pe(n,"column",ws,!0),s=Pe(n,"card",xs,!0),r=yn(o),i=[...new Set(Object.values(s).map(f=>f.col))].filter(f=>!Object.hasOwn(o,f)).sort(),c=[...r,...i].flatMap(f=>yn(Object.fromEntries(Object.entries(s).filter(([,h])=>h.col===f))));return{columns:Object.fromEntries(r.map(f=>[f,o[f]])),cards:Object.fromEntries(c.map(f=>[f,s[f]]))}}function Fe(e,t){let n=bs(e,t);return{columns:Pe(n,"column",ws,!1),cards:Pe(n,"card",xs,!1)}}var vs={name:"",pos:"",title:"",owner:null,due:null,placement:{columnId:"",pos:""}},ks=(e,t,n)=>e==="card"&&n==="placement"?{columnId:t.col??"",pos:t.pos??""}:t[n]??vs[n];function ai(e,t,n,o){let s=[];for(let[r,i]of ci){let c=jn(n?.[i])?n[i]:{},f=jn(o?.[i])?o[i]:{};for(let h of new Set([...Object.keys(c),...Object.keys(f)])){let a=c[h],l=f[h];if(!l){a&&s.push([Nn(e,r,h,"alive"),!1]);continue}a||s.push([Nn(e,r,h,"alive"),!0]);for(let u of Ln[r]){if(u==="alive")continue;let p=Nn(e,r,h,u),m=ks(r,l,u),g=a?ks(r,a,u):t.has(p)?t.get(p):vs[u];tt(g)!==tt(m)&&s.push([p,li(m)])}}}return s}function Ss(e,t,n,o){for(let[s,r]of ai(t,e.boardFields,n,o))e.boardFields.set(s,r)}var Rn="remove",Ts="restore",Kn="copy-active",He="copy-lost",$s="attr",Ds="text-delete",Ye=class extends Error{constructor(t){super(t),this.name="RecoveryError"}},K=e=>{throw new Ye(e)},It=e=>Number.isSafeInteger(e)&&e>=0,ui=e=>Number.isSafeInteger(e)&&e>0,Os=/^(?:0|[1-9]\d*)$/,_s=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),rt=e=>e===null||typeof e!="object"?e:JSON.parse(JSON.stringify(e)),de=(e,t)=>e<t?-1:e>t?1:0,Ns=e=>[...e].sort(de),Ms=e=>`${e.client}.${e.clock}`,di=e=>JSON.stringify(["author",e]),Vl=(e,t)=>JSON.stringify([Rn,e,t]),Hl=(e,t)=>JSON.stringify([Ts,e,t]),Ls=e=>JSON.stringify([Kn,e]),js=e=>JSON.stringify([He,e]),Ul=(e,t,n)=>JSON.stringify([Ds,e,t,n]),Ue=(e,t)=>JSON.stringify([$s,e,t]);function ut(e){if(typeof e!="string")return null;let t=e.indexOf(".");if(t<1||t===e.length-1)return null;let n=e.slice(0,t),o=e.slice(t+1);if(!Os.test(n)||!Os.test(o))return null;let s=Number(n),r=Number(o);return It(s)&&It(r)?{client:s,clock:r}:null}var ue=(e,t,n)=>{_s(e)||K(`Invalid gone record: ${n}`);for(let o of Object.keys(e))t.includes(o)||K(`Unsupported gone field ${o} in ${n}`)},Cs=(e,t)=>{Array.isArray(e)||K(`Invalid state vector in ${t}`);let n=[],o=-1;for(let s of e){(!Array.isArray(s)||s.length!==2)&&K(`Invalid state vector in ${t}`);let[r,i]=s;(!It(r)||!It(i)||r<=o)&&K(`Invalid state vector in ${t}`),o=r,n.push([r,i])}return n},fi=e=>{if(typeof e!="string")return!1;if(e.charCodeAt(0)!==91)return ut(e)!==null;let t;try{t=JSON.parse(e)}catch{return!1}return!Array.isArray(t)||!ut(t[1])?!1:t[0]===Rn?t.length===3&&typeof t[2]=="string"&&t[2]!=="":(t[0]===Kn||t[0]===He)&&t.length===2},pi=(e,t,n)=>{if(t.charCodeAt(0)===91){let r=null;try{r=JSON.parse(t)}catch{K(`Malformed gone key: ${t}`)}if((!Array.isArray(r)||typeof r[0]!="string")&&K(`Malformed gone key: ${t}`),r[0]===Rn){(r.length!==3||typeof r[2]!="string"||!r[2])&&K(`Malformed gone key: ${t}`);let i=ut(r[1]);i||K(`Malformed gone key: ${t}`),ue(e,["blockId","end","sv"],t),(typeof e.blockId!="string"||!e.blockId)&&K(`Invalid removal record: ${t}`);let c=e.end??null;c!==null&&!ut(c)&&K(`Invalid removal record: ${t}`),n.removals.push({key:t,sourceKey:r[1],source:i,operationId:r[2],blockId:e.blockId,end:c,sv:Cs(e.sv,t),legacy:!1});return}if(r[0]===Ts){(r.length!==3||typeof r[2]!="string"||!r[2])&&K(`Malformed gone key: ${t}`),ut(r[1])||K(`Malformed gone key: ${t}`),ue(e,["covers","baseline"],t),(!Array.isArray(e.covers)||e.covers.some(c=>!fi(c)))&&K(`Invalid restore record: ${t}`);let i=e.baseline??{};ue(i,["type","attrs"],t),(typeof i.type!="string"||!_s(i.attrs))&&K(`Invalid restore record: ${t}`),n.restores.push({key:t,sourceKey:r[1],operationId:r[2],covers:Ns(e.covers),baseline:{type:i.type,attrs:rt(i.attrs)}});return}if(r[0]===Kn){(r.length!==2||!ut(r[1]))&&K(`Malformed gone key: ${t}`),e!==!0&&K(`Invalid copy-active record: ${t}`),n.copyActive.add(r[1]);return}if(r[0]===Ds){(r.length!==4||!It(r[1])||!It(r[2])||typeof r[3]!="string"||!r[3])&&K(`Malformed gone key: ${t}`),ue(e,["length","actor","sv"],t),(!ui(e.length)||!It(r[2]+e.length-1))&&K(`Invalid text-delete record: ${t}`),It(e.actor)||K(`Invalid text-delete record: ${t}`),n.textDeletes.push({key:t,client:r[1],clock:r[2],length:e.length,actor:e.actor,sv:Cs(e.sv,t)});return}if(r[0]===$s){(r.length!==3||!ut(r[1])||typeof r[2]!="string"||!r[2])&&K(`Malformed gone key: ${t}`),e===void 0&&K(`Invalid attribute override: ${t}`);let i=n.attrs.get(r[1])??new Map;i.set(r[2],rt(e)),n.attrs.set(r[1],i);return}K(`Unsupported gone record: ${t}`)}let o=ut(t);o||K(`Malformed gone key: ${t}`),ue(e,["b","e"],t),(typeof e.b!="string"||!e.b)&&K(`Invalid gone record: ${t}`);let s=e.e??null;s!==null&&!ut(s)&&K(`Invalid gone record: ${t}`),n.removals.push({key:t,sourceKey:t,source:o,operationId:null,blockId:e.b,end:s,sv:[],legacy:!0})};function Pn(e,{strict:t=!1}={}){let n={removals:[],restores:[],copyActive:new Set,attrs:new Map,textDeletes:[]};return e.forEach((o,s)=>{try{pi(o,s,n)}catch(r){if(t||!(r instanceof Ye))throw r}}),n}var Bn=e=>{if(Array.isArray(e))return e.map(Bn);if(e!==null&&typeof e=="object"){let t={};for(let n of Object.keys(e).sort())t[n]=Bn(e[n]);return t}return e},hi=e=>JSON.stringify(Bn(e)),Ve=e=>S.nodes[e]??S.nodes.paragraph,mi=(e,t,n=null)=>{let o=e.attrs.get(t),s=n?.get("t"),r=o&&o.get("t")||"paragraph",i=typeof s=="string"&&S.nodes[s]?s:r,c=Ve(i),f={};for(let h of Yt(c))f[h]=rt(o&&o.has(h)?o.get(h):Vt(c,h));if(i==="table"&&Object.assign(f,rt(Re(e.tableFields,t,{cols:f.cols,rows:f.rows}))),i==="board"&&Object.assign(f,rt(ze(e.boardFields,t))),n)for(let[h,a]of n)h!=="t"&&Object.hasOwn(f,h)&&(f[h]=rt(a));return{id:t,type:i,attrs:f}},gi=e=>{let t={};if(!e)return t;for(let n of[...e.keys()].sort())t[n]=rt(e.get(n));return t},As="recovered:",jt=e=>typeof e=="string"&&e.startsWith(As)?e.slice(As.length):null;function zn(e,t,n){let o=new Set(t.map(l=>l.key)),s=null;for(let l of n.restores){if(l.sourceKey!==e)continue;let u=l.covers.reduce((p,m)=>p+(o.has(m)?1:0),0);(!s||u>s.count||u===s.count&&de(l.key,s.restore.key)<0)&&(s={restore:l,count:u})}if(!s)return null;let r=n.attrs.get(e),i=r?.get("t"),c=S.nodes[s.restore.baseline.type]?s.restore.baseline.type:"paragraph",f=typeof i=="string"&&S.nodes[i]?i:c,h=Ve(f),a={};for(let l of Yt(h))r&&r.has(l)?a[l]=rt(r.get(l)):Object.hasOwn(s.restore.baseline.attrs,l)?a[l]=rt(s.restore.baseline.attrs[l]):a[l]=rt(Vt(h,l));return{type:f,attrs:a,key:s.restore.key}}var yi=e=>{let t={};for(let n of Object.keys(e).sort())t[n]=rt(e[n]);return t},ki=(e,t)=>t.some(n=>e.clock>=(n.get(e.client)??0)),bi=(e,t)=>{let n=e[e.length-1];if(n&&t<=n.end){t===n.end&&(n.end=t+1);return}e.push({start:t,end:t+1})},wi=e=>{let t=[];for(let n of[...e].sort(de))bi(t,n);return t},xi=(e,t)=>{let n=0,o=e.length-1;for(;n<=o;){let s=n+o>>1,r=e[s];if(t<r.start)o=s-1;else if(t>=r.end)n=s+1;else return!0}return!1},vi=(e,t,n)=>{let o=Ro(t,e.length).physicalRanges(0,t.tokens),s=new Map,r=(h,a,l)=>{for(let u=a;u<l;u++){let p=n.resolve({client:h.id.client,clock:h.id.clock+u}),m=s.get(p.client);m?m.push(p.clock):s.set(p.client,[p.clock])}},i=0,c=0;for(let h=e._start;h&&c<o.length;h=h.right){if(h.deleted||!h.countable)continue;let a=i;i+=h.length;let l=h.content,u=l instanceof Ct;if(!u&&!(l instanceof st)||!u&&l.embed.b!==void 0)continue;for(;c<o.length&&o[c][1]<=a;)c++;let p=c;for(;p<o.length&&o[p][0]<i&&(r(h,Math.max(a,o[p][0])-a,Math.min(i,o[p][1])-a),!(o[p][1]>=i));)p++;c=p}let f=new Map;for(let[h,a]of s)f.set(h,wi(a));return(h,a)=>{let l=f.get(h);return l?xi(l,a):!1}},Es=(e,t,n,o,s)=>{let r=e.resolve({client:t.client,clock:t.clock}),i=t.kind==="text"?jo(Ee(t.raw,o)):{},c=!ki(t,n);return{client:t.client,clock:t.clock,length:t.length,sourceClient:r.client,sourceClock:r.clock,baseline:c,displaced:!c&&!s(r.client,r.clock),kind:t.kind,text:t.kind==="text"?t.text:null,marks:i,raw:yi(t.raw)}},Is=(e,t)=>{let n=e[e.length-1];if(n&&n.kind===t.kind&&n.baseline===t.baseline&&n.displaced===t.displaced&&n.client===t.client&&n.clock+n.length===t.clock&&n.sourceClient===t.sourceClient&&n.sourceClock+n.length===t.sourceClock&&oe(n.marks,t.marks)&&oe(n.raw,t.raw)){n.length+=t.length,n.kind==="text"&&(n.text+=t.text);return}e.push(t)},Si=(e,t)=>({id:Ms(e),length:e.length,source:Ms({client:e.sourceClient,clock:e.sourceClock}),baseline:e.baseline,displaced:e.displaced,kind:e.kind,...e.kind==="text"?{text:e.text}:{},marks:e.marks,raw:e.raw,author:t(e.sourceClient)});function Oi(e,t,n,o,s,r,i,c){let f=(A,_,P=null)=>{let G=t.boundaryOf(_);if(!G||G.blockId!==A||!G.recoveryOf)return mi(e,A,P);let Z=zn(G.recoveryOf,c.get(G.recoveryOf)??[],r),ct=typeof P?.get("t")=="string"&&S.nodes[P.get("t")]?P.get("t"):Z?.type??"paragraph",pt={};for(let $ of Yt(Ve(ct)))pt[$]=rt(P?.has($)?P.get($):Z&&Object.hasOwn(Z.attrs,$)?Z.attrs[$]:Vt(Ve(ct),$));return{id:A,type:ct,attrs:pt}},h=A=>{let _=e.origins.get(di(A));return typeof _=="string"&&_?_:null},a=[...o].sort((A,_)=>de(A.key,_.key)),l=a[0].blockId,u=r.attrs.get(n),p=gi(u),m=f(l,a[0].source,u),g=new Map(a.map(A=>[A.key,new Map(A.sv)])),y=new Map;for(let A of a){let _=s.get(A.key);if(!_)continue;let P=g.get(A.key);for(let G of _.items){let Z=y.get(G.id);Z?Z.vectors.push(P):y.set(G.id,{item:G,vectors:[P]})}}let x=[...y.values()].sort((A,_)=>A.item.at-_.item.at),C=[{...m,author:h(t.resolve(a[0].source).client),runs:[]}],T=C[0];for(let A of x){let _=A.item;if(_.kind==="marker"){if(t.boundaryOf({client:_.client,clock:_.clock})?.kind==="restore"||!_.blockId||_.blockId===T.id)continue;T={...f(_.blockId,{client:_.client,clock:_.clock}),author:h(t.resolve({client:_.client,clock:_.clock}).client),runs:[]},C.push(T);continue}if(_.kind==="text")for(let P=0;P<_.length;P++)Is(T.runs,Es(t,{..._,clock:_.clock+P,length:1,text:_.text[P]},A.vectors,T.type,i));else Is(T.runs,Es(t,_,A.vectors,T.type,i))}let L={source:n,blockId:l,type:m.type,attrs:m.attrs,author:C[0].author,blocks:C.map(A=>({id:A.id,type:A.type,attrs:A.attrs,author:A.author,runs:A.runs.map(_=>Si(_,h))})),removals:a.map(A=>({key:A.key,operationId:A.operationId,end:A.end,sv:A.sv})),restores:r.restores.filter(A=>A.covers.some(_=>a.some(P=>P.key===_))).sort((A,_)=>de(A.key,_.key)).map(A=>({key:A.key,covers:Ns(A.covers)})),copyActive:r.copyActive.has(n),overrides:p,recoverable:C.some(A=>A.runs.some(_=>_.displaced))};return{...L,revision:hi(L)}}function ql(e,t={}){let n=t.index??ce(e.origins);try{let o=t.walked??qe(e,n),s=t.intents??Pn(e.gone,{strict:t.strict===!0}),r=new Map;for(let l of o.hidden??[])r.set(l.key,l);let i=new Map;for(let l of o.removals??s.removals){let u=i.get(l.sourceKey);u?u.push(l):i.set(l.sourceKey,[l])}let c=null,f=(l,u)=>(c||(c=vi(e.flow,o,n)),c(l,u)),h=new Map;for(let[l,u]of i)h.set(l,Oi(e,n,l,u,r,s,f,i));let a=[...h.values()].sort((l,u)=>{let p=ut(l.source),m=ut(u.source);return p.client-m.client||p.clock-m.clock});return{sources:h,list:a,intents:s}}finally{t.index||n.dispose()}}var Bs=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)},Mi=(e,t)=>e.id.client===t.client&&t.clock>=e.id.clock&&t.clock<e.id.clock+e.length,Ci=e=>{if(typeof e!="string"||e.charCodeAt(0)!==91)return null;let t;try{t=JSON.parse(e)}catch{return null}return Array.isArray(t)&&t.length===2&&t[0]===He&&typeof t[1]=="string"?t[1]:null},Ai=e=>e.reduce((t,n)=>n.brk.client<t.brk.client||n.brk.client===t.brk.client&&n.brk.clock<t.brk.clock?n:t);function qe(e,t=null){let n=t?null:ce(e.origins);try{return Ei(e,n??t)}finally{n&&n.dispose()}}function Ei(e,t){let n=e.ydoc.store,o=Pn(e.gone),s=new Map,r=new Map;for(let d=e.flow._start;d;d=d.right){if(d.deleted||!(d.content instanceof st)||d.content.embed.b===void 0)continue;r.set(d.content.embed.b,(r.get(d.content.embed.b)??0)+1);let k=ht(t.resolve(d.id)),b=s.get(k);(!b||d.id.client<b.id.client||d.id.client===b.id.client&&d.id.clock<b.id.clock)&&s.set(k,d)}let i=new Set(s.keys()),c=new Set,f=[],h=new Map;for(let d of e.origins.keys()){let k;try{k=JSON.parse(d)}catch{continue}if(!Array.isArray(k)||k.length!==3||k[0]!=="boundary"&&k[0]!=="alias")continue;let[,b,M]=k;if(!Number.isSafeInteger(b)||b<0||!Number.isSafeInteger(M)||M<0)continue;if(k[0]==="boundary"){let O=`${b}.${M}`,B=t.boundaryOf({client:b,clock:M});B&&B.kind==="copy"&&(o.copyActive.has(O)?B.recoveryOf&&c.add(B.recoveryOf):i.has(O)&&f.push({key:Ls(O),sourceKey:O,source:{client:b,clock:M},operationId:null,blockId:B.blockId,end:null,sv:[],legacy:!1,implicit:!0}))}(h.get(b)??h.set(b,new Set).get(b)).add(M)}let a=[],l=new Set(f.map(d=>d.key));for(let d of o.restores)for(let k of d.covers){let b=Ci(k);b===null||l.has(k)||!s.has(b)||(l.add(k),a.push({key:k,sourceKey:b,source:se(b),operationId:null,blockId:s.get(b).content.embed.b,end:null,sv:[],legacy:!1,implicit:!0}))}let u=f.length||a.length?[...o.removals,...f,...a]:o.removals,p=new Map,m=new Map,g=new Map;for(let d of u){(g.get(d.sourceKey)??g.set(d.sourceKey,[]).get(d.sourceKey)).push(d);let b=null;if(d.implicit)b=s.get(d.sourceKey);else try{b=te(n,d.source)}catch{b=null}let M=ht(t.resolve(d.source)),I=s.get(M);if((!b||b.deleted)&&I?.content.embed.b===d.blockId&&(b=I),!b)continue;if(d.legacy){!b.deleted&&b.content instanceof st&&b.content.embed.b===d.blockId&&ht(t.resolve(b.id))===M&&p.set(b,{key:d.key,blockId:d.blockId,end:d.end?se(d.end):null});continue}(m.get(b)??m.set(b,[]).get(b)).push(d)}let y=new Map,x=new Set(o.restores.map(d=>d.sourceKey)),C=(d,k)=>{let b=jt(k);if(b===null)return null;let M=t.boundaryOf({client:d.id.client,clock:d.id.clock});return M&&M.blockId===k&&M.recoveryOf===b?M:null},T=(d,k)=>{let b=C(d,k);return b&&b.kind==="restore"?b.recoveryOf:null},L=(d,k)=>{let b=C(d,k);return b&&b.kind==="copy"?b.recoveryOf:null},A=(d,k)=>{let b=T(d,k);return b!==null&&x.has(b)&&g.has(b)?b:null};for(let d of o.restores){let k=y.get(d.sourceKey)??y.set(d.sourceKey,new Set).get(d.sourceKey);for(let b of d.covers)k.add(b)}let _=new Map;for(let d=e.flow._start;d;d=d.right){if(d.deleted)continue;let k=d.content instanceof st?A(d,d.content.embed&&d.content.embed.b):null;if(k===null)continue;(_.get(k)??_.set(k,[]).get(k)).push(d)}let P=d=>{let k=g.get(d);if(!k||!k.length)return!1;let b=y.get(d);if(!b)return!1;for(let M of k)if(!b.has(M.key))return!1;return(_.get(d)?.length??0)>0||c.has(d)},G=[],Z=[],ct=[],pt=[],$=null,Ot="start",j=null,et=0,lt={},Jt=d=>{let k=e.attrs.get(d);return k&&k.get("t")||"paragraph"},Mt=d=>{d&&($&&!$.atom?$.runs.push({hole:d}):G.push({kind:"h",len:d,key:null}))},gt=(d,k,b=!1)=>{let M=zn(d,g.get(d)??[],o),I=`recovered:${d}`,O=M?M.type:"paragraph",B=!Object.hasOwn(S.nodes,O);$={kind:"b",id:I,baseId:I,brk:{client:k.id.client,clock:k.id.clock},implicit:!1,runs:[],len:1,atom:!B&&!S.nodes[O]?.isTextblock,opaque:B,recovered:!0,restored:!b,sourceKey:d,t:O,fields:M?M.attrs:null},G.push($),Ot=I},Pt=(d,k,b)=>{$={kind:"b",id:d,baseId:d,brk:k,implicit:b,runs:[],len:b?0:1,atom:!1,items:!b&&(r.get(d)??0)>1?[]:null},b?$.t="paragraph":($.t=Jt(d),$.opaque=!Object.hasOwn(S.nodes,$.t),$.atom=!$.opaque&&!S.nodes[$.t]?.isTextblock),G.push($),Ot=d},ye=()=>{j&&(j.len&&(j.resume?j.resume.runs.push({hole:j.len}):G.push({kind:"h",len:j.len,key:j.active[0]?.key})),$=j.resume,j=null)},ke=d=>{d.legacy&&d.text&&Z.push({key:d.key,id:d.blockId,text:d.text,h:Bs(d.text)}),ct.push({key:d.key,sourceKey:d.sourceKey,blockId:d.blockId,end:d.end,sv:d.sv,at:d.at,live:d.live,items:d.items})},un=(d,k)=>Mi(d,k)?!0:zt(d).some(b=>{if(!e.origins.has(An(b.client,b.clock)))return!1;let M=t.resolve(b);return M.client===k.client&&M.clock===k.clock}),dn=new Map([...h].map(([d,k])=>[d,[...k].sort((b,M)=>b-M)])),zt=d=>{let k=dn.get(d.id.client)??[],b=0,M=k.length;for(;b<M;){let O=b+M>>1;k[O]<d.id.clock?b=O+1:M=O}let I=[];for(let O=b;O<k.length&&k[O]<d.id.clock+d.length;O++)I.push({client:d.id.client,clock:k[O]});return I},at=[],fn=d=>({blockId:d.blockId,end:d.end?se(d.end):null,implicit:d.implicit===!0,sourceKey:d.sourceKey});for(let d=e.flow._start;d;d=d.right){let k=et;if(!d.deleted&&d.countable&&(et+=d.length),j||at.length){let O=!d.deleted&&d.content instanceof st?d.content.embed.b:void 0,B=O!==void 0&&T(d,O)===null,N=d.deleted?zt(d).flatMap(z=>{let nt=ht(t.resolve(z)),pn=t.boundaryOf(z);return!pn||pn.kind!=="removed"||i.has(nt)?[]:[{blockId:pn.blockId,sourceKey:nt}]}):[],yt=z=>z.end?un(d,z.end):z.implicit?B||N.some(nt=>nt.sourceKey!==z.sourceKey):B&&O!==z.blockId||N.some(nt=>nt.blockId!==z.blockId);if(j){let z=[];for(let nt of j.active)yt(nt)?ke(nt):z.push(nt);j.active=z,z.length||ye()}for(let z=at.length-1;z>=0;z--)at[z].active=at[z].active.filter(nt=>!yt(nt)),at[z].active.length||at.splice(z,1)}let b=m.get(d);if(b){if(!j&&P(b[0].sourceKey)){d.deleted||Mt(d.length),at.push({active:b.map(fn),sourceKey:b[0].sourceKey,root:null});continue}!j&&d.deleted&&pt.push({client:d.id.client,clock:d.id.clock});for(let O of b){let B={legacy:!1,implicit:O.implicit===!0,key:O.key,sourceKey:O.sourceKey,blockId:O.blockId,end:O.end?se(O.end):null,sv:O.sv,at:k,live:!d.deleted,items:[]};j?j.active.push(B):j={active:[B],len:0,resume:$}}d.deleted||(j.len+=d.length);continue}let M=p.get(d);if(M){if(!j&&P(M.key)){d.deleted||Mt(d.length),at.push({active:[{blockId:M.blockId,end:M.end}],sourceKey:M.key,root:null});continue}let O={legacy:!0,key:M.key,sourceKey:M.key,blockId:M.blockId,end:M.end,sv:[],at:k,live:!0,items:[],text:""};j?j.active.push(O):j={active:[O],len:0,resume:$},j.len+=1;continue}if(d.deleted)continue;let I=d.content;if(I instanceof wn){I.value===null?delete lt[I.key]:lt[I.key]=I.value;continue}if(j){if(I instanceof Ct||I instanceof st){let O=I instanceof Ct?I.str:I.embed.b!==void 0?"\xB6":`
|
|
3
|
+
`,B={...lt};for(let N of j.active)N.legacy&&(N.text+=O),N.items.push({at:k,id:ht(d.id),client:d.id.client,clock:d.id.clock,length:d.length,kind:I instanceof Ct?"text":I.embed.b!==void 0?"marker":"br",text:I instanceof Ct?I.str:null,blockId:I instanceof st&&I.embed.b!==void 0?I.embed.b:null,raw:B});j.len+=d.length}continue}if(I instanceof wn){I.value===null?delete lt[I.key]:lt[I.key]=I.value;continue}if(I instanceof st){let O=A(d,I.embed.b);if(O!==null){let yt=at.find(z=>z.sourceKey===O&&!z.root);yt&&!c.has(O)?(gt(O,d),yt.root=$):Mt(d.length);continue}if(T(d,I.embed.b)!==null){Mt(d.length);continue}let B=L(d,I.embed.b);if(B!==null){gt(B,d,!0);continue}let N=I.embed;N.b!==void 0?Pt(N.b,{client:d.id.client,clock:d.id.clock},!1):((!$||$.atom)&&Pt(`~${Ot}`,null,!0),$.runs.push({br:!0}),$.items&&$.items.push({at:k,id:ht(d.id),client:d.id.client,clock:d.id.clock,length:d.length,kind:"br",text:null,blockId:null,raw:{...lt}}),$.len+=1);continue}if(I instanceof Ct){(!$||$.atom)&&Pt(`~${Ot}`,null,!0);let O=Ee(lt,$.t);$.runs.push({text:I.str,marks:O,mk:Bo(O)}),$.items&&$.items.push({at:k,id:ht(d.id),client:d.id.client,clock:d.id.clock,length:d.length,kind:"text",text:I.str,blockId:null,raw:{...lt}}),$.len+=I.str.length}}if(j){for(let d of j.active)ke(d);ye()}let Wt=new Map;for(let d of G)d.kind!=="b"||d.implicit||(Wt.get(d.baseId)??Wt.set(d.baseId,[]).get(d.baseId)).push(d);let Gt=d=>d.runs.map(k=>k.br?`
|
|
4
|
+
`:k.hole?"":k.text).join(""),Xt=new Map,w=[];for(let[d,k]of Wt){if(k.length<2)continue;let b=Ai(k);for(let M of k)if(M!==b&&(M.hide=!0,(Xt.get(d)??Xt.set(d,[]).get(d)).push(ht(M.brk)),!(oe(M.runs,b.runs)&&M.t===b.t)&&Gt(M)&&(Z.push({key:`d${M.brk.client}.${M.brk.clock}`,id:d,text:Gt(M),h:Bs(Gt(M)),copy:!0}),M.items?.length))){let I=ht(t.resolve(M.brk)),O=js(I);w.push({key:O,sourceKey:I,source:{client:M.brk.client,clock:M.brk.clock},operationId:null,blockId:d,end:null,sv:[],legacy:!1,implicit:!0}),ct.push({key:O,sourceKey:I,blockId:d,end:null,sv:[],at:M.items[0].at,live:!0,items:M.items})}}let v=[],D=[],E=0;for(let d of G){if(d.kind==="h"){D.push({at:E,len:d.len});continue}if(d.hide){D.push({at:E,len:d.len+d.runs.reduce((b,M)=>b+(M.hole??0),0)});continue}v.push(d);let k=d.implicit?0:1;for(let b of d.runs)b.hole?D.push({at:E+k,len:b.hole}):k+=b.br?1:b.text.length;E+=d.len}return{visible:v,holes:D,orphans:Z,tokens:E,copies:Xt,hidden:ct,removals:w.length?[...u,...w]:u,fences:pt}}var Fn=(e,t,n)=>{let o=e.attrs.get(t.baseId),s={};for(let r of Yt(n))s[r]=o&&o.has(r)?o.get(r):Vt(n,r);return n.name==="board"&&Object.assign(s,ze(e.boardFields,t.baseId)),n.name==="table"&&Object.assign(s,Re(e.tableFields,t.baseId,{cols:s.cols,rows:s.rows})),s},Rs=e=>e===void 0?e:JSON.parse(JSON.stringify(e)),Ii=(e,t)=>{let n={},o=e.attrs.get(t.baseId);return o&&o.forEach((s,r)=>{r!=="pos"&&(n[r]=Rs(s))}),n.t=t.t,n};function ca(e,t){let n=t.visible.map(i=>{if(i.opaque){let f=i.recovered?{...Rs(i.fields??{})}:Ii(e,i);return{b:i,type:S.nodes.opaque_block,fields:f,opaque:!0}}let c=S.nodes[i.t]??S.nodes.paragraph;return{b:i,type:c,fields:{...i.fields??Fn(e,i,c)}}}),o=new Map(n.map(i=>[i.b.id,i])),s=i=>(i.b.recovered?e.gone._map.get(Ue(i.b.sourceKey,"parent")):e.attrs.get(i.b.baseId)?._map.get("parent"))?.id??{clock:-1,client:-1};for(let i of o.keys()){let c=new Map,f=[],h=i;for(;o.has(h)&&!c.has(h);)c.set(h,f.length),f.push(h),h=o.get(h).fields.parent;if(!c.has(h))continue;let l=f.slice(c.get(h)).reduce((u,p)=>{let m=s(o.get(u)),g=s(o.get(p));return m.clock<g.clock||m.clock===g.clock&&m.client<g.client?u:p});o.get(l).fields.parent=null}let r=n.map(({b:i,type:c,fields:f,opaque:h})=>{if(h){let u=[];for(let p of i.runs)p.hole||(p.br?u.push(S.nodes.hard_break.create()):u.push(S.text(p.text,p.marks)));return c.create({id:i.id,pos:null,raw:f},u)}let a={id:i.id,pos:null,...f};if(c.name==="table"&&Object.keys(a.rows??{}).length&&Object.keys(a.cols??{}).length)return Ft(S,i.id,{t:"table",...a});if(!c.isTextblock)return c.create(a);let l=[];for(let u of i.runs)u.hole||(u.br?l.push(S.nodes.hard_break.create()):l.push(S.text(u.text,u.marks)));return c.create(a,l)});return r.length?S.nodes.doc.create(null,r):S.nodes.doc.createAndFill()}var J=e=>({status:"refused",code:e}),Je=e=>JSON.parse(JSON.stringify(e)),Ti=["title","owner","due"],$i=/^\d{4}-\d{2}-\d{2}$/,We=(e,t)=>e==="title"?typeof t=="string":e==="due"?t===null||typeof t=="string"&&$i.test(t):t===null||typeof t=="string"&&t.length>0,Di=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Ks(e,t){let n=t>0?e[t-1]:null,o=e.slice(t).find(r=>n===null||r>n)??null,s=r=>(n===null||r>n)&&(o===null||r<o);for(let[r,i]of[[n,o],[null,o],[n,null]]){if(r!==null&&!kt(r)||i!==null&&!kt(i)||r!==null&&i!==null&&r>=i)continue;let c=V(r,i);if(s(c))return c}return`${e.reduce((r,i)=>i>r?i:r,"")}V`}function Yn(e,t,n){let o=e.map(t),s=n>0?o[n-1]:null,r=n;for(;s!==null&&r<o.length&&o[r]===s;)r++;if(r===n)return{pos:Ks(o,n),rekey:[]};let i=o.slice(r).find(f=>f>s)??null,c=[];for(let f=n,h=s;f<=r;f++)c.push(h=Ks(i===null?[h]:[h,i],1));return{pos:c[0],rekey:e.slice(n,r).map((f,h)=>[f,c[h+1]])}}var Ge=(e,t,n)=>{let{pos:o,rekey:s}=Yn(t,r=>e[r].pos,n);for(let[r,i]of s)e[r]={...e[r],pos:i};return o};function ya({pd:e,um:t=null,origins:n=null,render:o=()=>{}}){let s=a=>{if(typeof a!="string")return null;let l=qe(e,n).visible.find(p=>p.id===a);if(!l||l.t!=="board")return null;let u=l.fields??Fn(e,l,S.nodes.board);return{columns:Je(u.columns??{}),cards:Je(u.cards??{})}},r=(a,l,u,p)=>{let m=jt(a);return t?.stopCapturing(),e.ydoc.transact(()=>{if(!m)Ss(e,a,l,u);else for(let g of["columns","cards"])tt(l[g])!==tt(u[g])&&e.gone.set(Ue(m,g),Je(u[g]))},Lo),t?.stopCapturing(),o(),p},i=(a,l,u=null)=>X(Object.fromEntries(Object.entries(a.cards).filter(([p,m])=>m.col===l&&p!==u))),c=(a,l)=>l===void 0?a.length:l===null?0:a.indexOf(l)+1,f=(a,l)=>l!=null&&!a.includes(l),h=(a,l)=>{let u=s(a);return u?l(u,Je(u)):J("missing-board")};return{read:a=>s(a),removed(a){return s(a)?jt(a)?{columns:{},cards:{}}:Fe(e.boardFields,a):null},createColumn:(a,{name:l="",afterId:u}={})=>h(a,(p,m)=>{if(typeof l!="string")return J("invalid-value");let g=X(p.columns);if(f(g,u))return J("missing-destination");let y=R("c");return m.columns[y]={pos:Ge(m.columns,g,c(g,u)),name:l},r(a,p,m,{status:"created",id:y})}),renameColumn:(a,l,u)=>h(a,(p,m)=>Object.hasOwn(p.columns,l)?typeof u!="string"?J("invalid-value"):p.columns[l].name===u?{status:"unchanged"}:(m.columns[l].name=u,r(a,p,m,{status:"changed"})):J("missing-column")),moveColumn:(a,l,{afterId:u=null}={})=>h(a,(p,m)=>{if(!Object.hasOwn(p.columns,l))return J("missing-column");let g=X(p.columns).filter(C=>C!==l);if(f(g,u))return J("missing-destination");let y=c(g,u),x=X(p.columns);return[...g.slice(0,y),l,...g.slice(y)].every((C,T)=>C===x[T])?{status:"unchanged"}:(m.columns[l].pos=Ge(m.columns,g,y),r(a,p,m,{status:"moved"}))}),removeColumn:(a,l)=>h(a,(u,p)=>Object.hasOwn(u.columns,l)?(delete p.columns[l],r(a,u,p,{status:"removed",cards:i(u,l).length})):J("missing-column")),restoreColumn:(a,l)=>h(a,(u,p)=>{if(Object.hasOwn(u.columns,l))return{status:"unchanged"};let m=jt(a)?null:Fe(e.boardFields,a).columns[l];return m?(p.columns[l]=m,r(a,u,p,{status:"restored"})):J("missing-column")}),createCard:(a,{columnId:l,title:u="",owner:p=null,due:m=null,afterId:g}={})=>h(a,(y,x)=>{if(!Object.hasOwn(y.columns,l))return J("missing-column");if(!We("title",u)||!We("owner",p)||!We("due",m))return J("invalid-value");let C=i(y,l);if(f(C,g))return J("missing-destination");let T=R("k");return x.cards[T]={pos:Ge(x.cards,C,c(C,g)),col:l,title:u,...p!==null?{owner:p}:{},...m!==null?{due:m}:{}},r(a,y,x,{status:"created",id:T})}),editCard:(a,l,u)=>h(a,(p,m)=>{if(!Object.hasOwn(p.cards,l))return J("missing-card");if(!Di(u)||!Object.keys(u).length||Object.keys(u).some(y=>!Ti.includes(y)))return J("invalid-field");if(Object.entries(u).some(([y,x])=>!We(y,x)))return J("invalid-value");let g={...p.cards[l]};for(let[y,x]of Object.entries(u))x===null?delete g[y]:g[y]=x;return tt(g)===tt(p.cards[l])?{status:"unchanged"}:(m.cards[l]=g,r(a,p,m,{status:"changed"}))}),moveCard:(a,l,{columnId:u,afterId:p=null}={})=>h(a,(m,g)=>{if(!Object.hasOwn(m.cards,l))return J("missing-card");if(!Object.hasOwn(m.columns,u))return J("missing-column");let y=i(m,u,l);if(f(y,p))return J("missing-destination");let x=c(y,p),C=m.cards[l];if(C.col===u){let T=i(m,u);if([...y.slice(0,x),l,...y.slice(x)].every((L,A)=>L===T[A]))return{status:"unchanged"}}return g.cards[l]={...C,col:u,pos:Ge(g.cards,y,x)},r(a,m,g,{status:"moved"})}),removeCard:(a,l)=>h(a,(u,p)=>Object.hasOwn(u.cards,l)?(delete p.cards[l],r(a,u,p,{status:"removed"})):J("missing-card")),restoreCard:(a,l)=>h(a,(u,p)=>{if(Object.hasOwn(u.cards,l))return{status:"unchanged"};let m=jt(a)?null:Fe(e.boardFields,a).cards[l];return m?(p.cards[l]=m,r(a,u,p,{status:"restored"})):J("missing-card")})}}function _i(e,t){if(!e||!/<table[\s>]/i.test(e))return null;let n=t.defaultView?.DOMParser??globalThis.DOMParser;if(!n)return null;let o=new n().parseFromString(e,"text/html").body,s=[...o.querySelectorAll("table")].filter(h=>!h.parentElement.closest("table"));if(s.length!==1)return null;let r=o.cloneNode(!0);for(let h of r.querySelectorAll("table, style, script, template, meta, title"))h.remove();if(r.textContent.trim())return null;let i=s[0];return{grid:[...i.querySelectorAll("tr")].filter(h=>h.closest("table")===i).map(h=>[...h.children].filter(a=>a.tagName==="TD"||a.tagName==="TH").map(a=>xe(Ho.parse(a,{topNode:S.nodes.table_cell.create()})))).filter(h=>h.length),own:!!i.querySelector("td[data-col]")}}function Ni(e){if(!e||!e.includes(" "))return null;let{header:t,rows:n}=ve(e.replace(/\r?\n$/,""),{delimiter:" "});return{grid:[t,...n],own:!1}}function Ps(e,t,n=globalThis.document){let o=null;try{o=_i(e,n)}catch{o=null}if(!o)try{o=Ni(t)}catch{o=null}if(!o||!o.grid.length)return null;let s=Math.max(...o.grid.map(r=>r.length));for(let r of o.grid)for(;r.length<s;)r.push("");return{...o,width:s,height:o.grid.length}}function Xe(e,{header:t=e.length>1}={}){let n=Math.max(0,...e.map(l=>l.length));if(!n)return null;let o=t?e[0]:[],s=t?e.slice(1):e,r=Array.from({length:n},()=>R("c")),i=bt(null,null,n),c=Object.fromEntries(r.map((l,u)=>[l,{pos:i[u],name:Dt(o[u]??"").replace(/\s+/g," ").trim()||`Column ${u+1}`}])),f=s.length?s:[[]],h=bt(null,null,f.length),a=Object.fromEntries(f.map((l,u)=>[R("r"),{pos:h[u],cells:Object.fromEntries(r.map((p,m)=>[p,l[m]??""]))}]));return Ft(S,R(),{t:"table",pos:null,cols:c,rows:a})}var{Plugin:Li,TextSelection:Bt}=q,U=S.nodes,Hn=256*1024,St=e=>X(e.attrs.cols),zs=e=>{let t=e.selection.$head;for(let n=t.depth;n>0;n--)if(t.node(n).type===U.table){let o=t.node(n),s=n<t.depth?t.index(n):0,r=n+1<t.depth?t.index(n+1):0;return{table:o,pos:t.before(n),row:s,cell:r}}return null},fe=(e,t,n,o)=>{let s=e.nodeAt(t);if(!s||!s.childCount)return null;n=Math.max(0,Math.min(n,s.childCount-1)),o=Math.max(0,Math.min(o,s.child(n).childCount-1));let r=t+1;for(let i=0;i<n;i++)r+=s.child(i).nodeSize;r++;for(let i=0;i<o;i++)r+=s.child(n).child(i).nodeSize;return r+1},Qe=(e,t=V())=>U.table_row.create({id:R("r"),pos:t},e.map(n=>U.table_cell.create({col:n}))),it=(e,t,n)=>U.table.create({...e.attrs,...t},n);function dt(e,t,n){let o=zs(e);if(!o)return!1;let s=n(o.table,o);if(!s)return!1;if(t){let{table:r,row:i=o.row,cell:c=o.cell}=s,f=e.tr.replaceWith(o.pos,o.pos+o.table.nodeSize,r),h=fe(f.doc,o.pos,i,c);h!==null&&f.setSelection(Bt.create(f.doc,h)),t(F(f))}return!0}function vt(e,t,n,o=null,s=null,r=null){r??=o?e.doc.resolve(o.from).index(0):e.selection.$head.index(0);let i=e.doc.child(r),c=0;for(let u=0;u<r;u++)c+=e.doc.child(u).nodeSize;let f=i.isTextblock&&(i.content.size===0||o?.from===c+1&&o?.to===c+i.nodeSize-1),h=e.doc.maybeChild(r+1),a=f?i.attrs.pos:V(i.attrs.pos,h?.attrs.pos??null),l=n.type.create({...n.attrs,pos:a,parent:i.attrs.parent??null},n.content);if(t){let u=e.tr;o&&u.delete(o.from,o.to);let p=u.mapping.map(c),m=u.doc.child(r),g=f?p:p+m.nodeSize;if(u.replaceWith(g,f?p+m.nodeSize:g,l),s){let y=s.type.create({...s.attrs,pos:V(a,h?.attrs.pos??null),parent:i.attrs.parent??null},s.content);u.insert(g+l.nodeSize,y)}u.setSelection(Bt.create(u.doc,fe(u.doc,g,0,0))),t(F(u).scrollIntoView())}return!0}function Fs(e=3,t=3){if(!Number.isInteger(e)||!Number.isInteger(t)||e<1||t<1)return null;let n=Array.from({length:t},()=>R("c")),o=bt(null,null,t),s=Object.fromEntries(n.map((c,f)=>[c,{pos:o[f],name:`Column ${f+1}`}])),i=bt(null,null,e).map(c=>Qe(n,c));return U.table.create({id:R(),cols:s},i)}var Un=e=>(t,n)=>{let o=zs(t);if(!o||t.selection.$head.parent.type!==U.table_cell)return!1;let s=o.table.child(o.row).childCount,r=o.row,i=o.cell;return e==="down"?r++:(i+=e,i>=s&&(r++,i=0),i<0&&(r--,i=s-1)),r<0?!0:r>=o.table.childCount?e===-1?!0:ji(t,n,o,i):(n&&n(t.tr.setSelection(Bt.create(t.doc,fe(t.doc,o.pos,r,i))).scrollIntoView()),!0)};function ji(e,t,n,o){let s=[...n.table.content.content];if(s.push(Qe(St(n.table),V(s.at(-1).attrs.pos,null))),t){let r=e.tr.replaceWith(n.pos,n.pos+n.table.nodeSize,it(n.table,{sort:null},s));r.setSelection(Bt.create(r.doc,fe(r.doc,n.pos,s.length-1,o))),t(F(r).scrollIntoView())}return!0}var Bi=Un(1),Ri=Un(-1),Ki=Un("down"),Pi=(e=!0)=>(t,n)=>dt(t,n,(o,s)=>{let r=[...o.content.content],i=s.row+(e?1:0),c=V(r[i-1]?.attrs.pos??null,r[i]?.attrs.pos??null);return r.splice(i,0,Qe(St(o),c)),{table:it(o,{sort:null},r),row:i}}),Ra=(e,t)=>dt(e,t,(n,o)=>{let s=[...n.content.content];if(s.length===1){let r=s[0];s[0]=U.table_row.create(r.attrs,St(n).map(i=>U.table_cell.create({col:i})))}else s.splice(o.row,1);return{table:it(n,{sort:null},s),row:Math.min(o.row,s.length-1)}}),Ys=(e,t,n,o,s)=>{let{pos:r,rekey:i}=Yn(t,f=>e[f]?.pos??"",n),c={...e,[o]:{...s,pos:r}};for(let[f,h]of i)c[f]={...c[f],pos:h};return c},Ka=(e=!0)=>(t,n)=>dt(t,n,(o,s)=>{let r=St(o),i=s.cell+(e?1:0),c=R("c"),f=Ys(o.attrs.cols,r,i,c,{name:`Column ${r.length+1}`}),h=o.content.content.map(a=>{let l=[...a.content.content];return l.splice(i,0,U.table_cell.create({col:c})),U.table_row.create(a.attrs,l)});return{table:it(o,{cols:f},h),cell:i}}),Pa=(e,t)=>dt(e,t,(n,o)=>{let s=St(n);if(s.length<=1)return null;let r={...n.attrs.cols};delete r[s[o.cell]];let i=n.content.content.map(c=>U.table_row.create(c.attrs,c.content.content.filter((f,h)=>h!==o.cell)));return{table:it(n,{cols:r,sort:n.attrs.sort?.col===s[o.cell]?null:n.attrs.sort},i),cell:Math.min(o.cell,s.length-2)}}),za=e=>(t,n)=>dt(t,n,(o,s)=>{let r=s.row+e;if(r<0||r>=o.childCount)return null;let i=[...o.content.content],[c]=i.splice(s.row,1);i.splice(r,0,c);let f=V(i[r-1]?.attrs.pos??null,i[r+1]?.attrs.pos??null);return i[r]=U.table_row.create({...c.attrs,pos:f},c.content),{table:it(o,{sort:null},i),row:r}}),Fa=e=>(t,n)=>dt(t,n,(o,s)=>{let r=St(o),i=s.cell+e;if(i<0||i>=r.length)return null;let c=[...r],[f]=c.splice(s.cell,1);c.splice(i,0,f);let h=Ys(o.attrs.cols,c.filter(l=>l!==f),i,f,o.attrs.cols[f]),a=o.content.content.map(l=>{let u=[...l.content.content],[p]=u.splice(s.cell,1);return u.splice(i,0,p),U.table_row.create(l.attrs,u)});return{table:it(o,{cols:h},a),cell:i}}),zi=48,Fi=1200,Ya=160,Yi=e=>Number.isFinite(e)&&e>0?Math.round(Math.min(Fi,Math.max(zi,e))):null,Va=(e,t)=>(n,o)=>dt(n,o,s=>{let r=s.attrs.cols[e];if(!r)return null;let i=t===null?null:Yi(t);if(t!==null&&i===null||(r.width??null)===i)return null;let{width:c,...f}=r,h={...s.attrs.cols,[e]:i===null?f:{...r,width:i}};return{table:it(s,{cols:h},s.content),cell:St(s).indexOf(e)}}),Ha=(e,t)=>(n,o)=>dt(n,o,s=>{if(!s.attrs.cols[e]||!String(t).trim())return null;let r={...s.attrs.cols,[e]:{...s.attrs.cols[e],name:String(t).trim()}};return{table:it(s,{cols:r},s.content)}}),Ua=(e,t)=>(n,o)=>dt(n,o,s=>{if(!s.attrs.cols[e]||!(t==="auto"||xo.includes(t)))return null;let{kind:r,...i}=s.attrs.cols[e],c={...s.attrs.cols,[e]:t==="auto"?i:{...s.attrs.cols[e],kind:t}};return{table:it(s,{cols:c,sort:s.attrs.sort?.col===e?null:s.attrs.sort},s.content)}}),qa=(e,t="asc")=>(n,o)=>dt(n,o,s=>{if(!s.attrs.cols[e]||!["asc","desc"].includes(t))return null;let r=St(s).indexOf(e),i=Ne(s)[e],c=[...s.content.content].map((a,l)=>({row:a,previous:l,text:a.child(r).textContent.trim()}));c.sort((a,l)=>{if(!a.text||!l.text)return!a.text&&!l.text?a.previous-l.previous:a.text?-1:1;let u=i==="number"?gn(a.text):a.text,p=i==="number"?gn(l.text):l.text;if(u==null||p==null)return u==null&&p==null?a.previous-l.previous:u==null?1:-1;let m=i==="number"?u-p:i==="date"?u<p?-1:u>p?1:0:u.localeCompare(p,void 0,{numeric:!0,sensitivity:"base"});return m?t==="asc"?m:-m:a.previous-l.previous});let f=bt(null,null,c.length),h=c.map(({row:a},l)=>U.table_row.create({...a.attrs,pos:f[l]},a.content));return{table:it(s,{sort:{col:e,dir:t}},h)}}),Vn=(e,t=null)=>(n,o)=>dt(n,o,(s,r)=>{let i=St(s),c=t?.row??r.row,f=t?.cell??r.cell,h=[...s.content.content];e.forEach((l,u)=>{let p=c+u;p>=h.length&&h.push(Qe(i,V(h.at(-1).attrs.pos,null)));let m=[...h[p].content.content];l.forEach((g,y)=>{f+y<i.length&&(m[f+y]=U.table_cell.create({col:i[f+y]},ko(S,g)))}),h[p]=U.table_row.create(h[p].attrs,m)});let a=Math.max(1,...e.map(l=>l.length));return{table:it(s,{sort:null},h),row:c+e.length-1,cell:Math.min(f+a-1,i.length-1)}}),Vi=e=>new TextEncoder().encode(JSON.stringify(e.toJSON())).length;function Hi(e,t){let n=t.clipboardData;if(!n||n.files?.length)return!1;let o=e.state;if(o.selection.$from.parent.type.spec.code)return!1;let s=us(o),r=n.getData("text/plain").replace(/\r?\n$/,""),i=Ps(n.getData("text/html"),n.getData("text/plain"),e.dom.ownerDocument)??(s&&r&&!/[\r\n]/.test(r)?{grid:[[r]],width:1,height:1,own:!1}:null);if(!i)return!1;if(s&&s.rows*s.cols>1&&i.width*i.height===1)return Vn(Array.from({length:s.rows},()=>Array(s.cols).fill(i.grid[0][0])),{row:s.row,cell:s.cell})(o,e.dispatch);if(s)return Vn(i.grid,{row:s.row,cell:s.cell})(o,e.dispatch);if(o.selection.$head.parent.type===U.table_cell)return i.width*i.height<2?!1:Vn(i.grid)(o,e.dispatch);if(i.width*i.height<2||i.height<2&&!/<table[\s>]/i.test(n.getData("text/html")))return!1;let c=Xe(i.grid,{header:!i.own&&i.height>1});if(!c)return!1;if(Vi(c)>Hn)return ie("This paste is too large for one table.","error"),!0;let{from:f,to:h,empty:a,$from:l,$to:u}=o.selection;if(!a&&l.index(0)!==u.index(0)){let p=o.tr.deleteSelection();return vt(o.apply(p),m=>{for(let g of m.steps)p.step(g);p.setSelection(Bt.create(p.doc,m.selection.from)),e.dispatch(F(p).scrollIntoView())},c)}return vt(o,e.dispatch,c,a?null:{from:f,to:h})}var Ja=we.keymap({Tab:Bi,"Shift-Tab":Ri,Enter:Ki,"Mod-Enter":Pi(!0)});function Wa(){return new Li({props:{handlePaste:Hi,handleClickOn(e,t,n,o,s,r){if(n.type!==U.table_cell||!r||s.button)return!1;let i=e.nodeDOM(o),c=i&&ds.get(i);return c&&c.openDate(),!1}},appendTransaction(e,t,n){if(!e.some(r=>r.docChanged&&!r.getMeta(Ae)))return null;let o=new Map;t.doc.forEach(r=>{r.type===U.table&&o.set(r.attrs.id,r)});let s=n.tr;return n.doc.forEach((r,i)=>{if(r.type!==U.table||!r.attrs.sort)return;let c=o.get(r.attrs.id),f=r.attrs.sort.col;if(!c)return;let h=u=>Object.fromEntries(u.content.content.map(p=>[p.attrs.id,p.content.content.find(m=>m.attrs.col===f)?.textContent])),a=h(c),l=h(r);(Object.keys(a).length!==Object.keys(l).length||Object.keys(a).some(u=>a[u]!==l[u]||!Object.hasOwn(l,u)))&&s.setNodeMarkup(i,null,{...r.attrs,sort:null})}),s.docChanged?s.setMeta($n,!0):null}})}function Ga(e,t,n){let o=e.state.doc.nodeAt(t);if(o?.type!==U.table_cell)return!1;let s=e.state.tr.replaceWith(t+1,t+o.nodeSize-1,n?S.text(n):[]);return e.dispatch(s.setSelection(Bt.create(s.doc,t+1+n.length))),!0}function Xa(e,t,n,o){let s=fe(e.state.doc,t,n,o);return s===null?!1:(e.dispatch(e.state.tr.setSelection(Bt.create(e.state.doc,s))),!0)}var{TextSelection:Ui}=q,qn=S.nodes,qi=Object.freeze(["To do","In progress","Done"]),Vs=(e,t)=>kt(e)&&(t===null||kt(t)&&e<t)?V(e,t):null;function Jn(e=qi){let t=bt(null,null,e.length),n=Object.fromEntries(e.map((o,s)=>[R("c"),{pos:t[s],name:o}]));return qn.board.create({id:R(),columns:n,cards:{}})}function Hs(e,t,n=Jn(),o=null,s=null){let r=e.tr;o&&r.delete(o.from,o.to),s??=r.doc.resolve(r.mapping.map(e.selection.head)).index(0);let i=re(r.doc),c=r.doc.child(s),f=c.isTextblock&&c.content.size===0,h=f?s:i[s].subEnd,a=f?i[s].at:i[h].end,l=i[h+1]?.node.attrs.pos??null,u=c.attrs.parent??null,p=f?c.attrs.pos:Vs(i[h].node.attrs.pos,l),m=qn.board.create({...n.attrs,pos:p,parent:u}),g=qn.paragraph.create({id:R(),pos:Vs(p,l),parent:u});return r.replaceWith(a,f?i[s].end:a,[m,g]),r.setSelection(Ui.create(r.doc,a+m.nodeSize+1)),t&&t(F(r).scrollIntoView()),!0}var pe=new WeakMap;function Ze(e,t){let n=null;return e.forEach(o=>{o.type===S.nodes.table&&o.attrs.id===t&&(n=o)}),n}function Us(e){return e?Io({[e.attrs.id]:bo(e)})[0]:null}function Ws(e,t,n){let o=X(e.attrs.cols);if(!o.length)return null;let s=Ne(e),r=o.filter(i=>i!==o[0]&&s[i]==="number");return{id:R(),pos:t,parent:n,source:e.attrs.id,kind:"bar",x:o[0],series:r.length?r:o[1]?[o[1]]:[],title:"",highlight:null}}function Gs(e,t){let n=e.state.doc,o=n.nodeAt(t);if(o?.type!==S.nodes.table)return!1;let s=t+o.nodeSize,r=n.maybeChild(n.resolve(s).index(0)),i=Ws(o,V(o.attrs.pos,r?.attrs.pos??null),o.attrs.parent);return i?(e.dispatch(e.state.tr.insert(s,S.nodes.chart.create(i))),!0):!1}function Wn(e){let t=[];return e.forEach(n=>{n.type===S.nodes.table&&X(n.attrs.cols).length&&t.push(n)}),t}function qs(e,t,n,o){let s=e.state.tr;if(o&&s.delete(o.from,o.to),!Ze(s.doc,n.attrs.id)||t>=s.doc.childCount)return!1;let r=0;for(let u=0;u<t;u++)r+=s.doc.child(u).nodeSize;let i=s.doc.child(t),c=i.isTextblock&&i.content.size===0,f=s.doc.maybeChild(t+1),h=c?i.attrs.pos:V(i.attrs.pos,f?.attrs.pos??null),a=Ws(n,h,i.attrs.parent??null);if(!a)return!1;let l=S.nodes.chart.create(a);return s=c?s.replaceWith(r,r+i.nodeSize,l):s.insert(r+i.nodeSize,l),e.dispatch(s.scrollIntoView()),!0}var Ji=e=>X(e.attrs.cols).map(t=>e.attrs.cols[t].name||"Untitled").join(", ");function Xs(e,t,n=null){let o=Wn(e.state.doc);if(!o.length)return!1;if(o.length===1)return qs(e,t,o[0],n);let s=e.nodeDOM(e.state.doc.resolve(e.state.selection.head).before(1))??e.dom;return Gn(e,s,o.map((r,i)=>({label:`Table ${i+1}`,description:Ji(r),icon:"\u25A6",run:()=>qs(e,t,r,n)})))}var Js=class{constructor(t,n,o){this.node=t,this.view=n,this.getPos=o,this.source=void 0,this.frame=null;let s=n.dom.ownerDocument;this.dom=s.createElement("figure"),this.dom.className="page-chart",this.dom.dataset.id=t.attrs.id??"",this.dom.dataset.type="chart",this.plot=s.createElement("div"),this.plot.className="page-chart-plot",this.caption=s.createElement("figcaption"),this.settings=s.createElement("button"),this.settings.type="button",this.settings.className="page-chart-settings",this.settings.textContent="Chart settings",this.settings.setAttribute("aria-label","Chart settings"),this.settings.contentEditable="false",this.settings.addEventListener("click",()=>this.openSettings()),this.dom.append(this.plot,this.caption,this.settings),pe.has(n)||pe.set(n,new Set),pe.get(n).add(this),this.refresh()}refresh(){let t=Ze(this.view.state.doc,this.node.attrs.source);t!==this.source&&(this.source=t,this.schedule())}schedule(){if(this.frame!==null)return;let t=this.dom.ownerDocument.defaultView,n=t.requestAnimationFrame?.bind(t)??(o=>t.setTimeout(o,0));this.frame=n(()=>{this.frame=null,this.draw()})}draw(){let t=this.node.attrs,n=Oo({id:t.id,type:t.kind,x:t.x,series:t.series,title:t.title,highlight:t.highlight},Us(this.source));this.plot.innerHTML=Mo(n,{width:640,height:320,narrow:this.dom.getBoundingClientRect().width<480}),this.caption.textContent=t.title}setAttrs(t){let n=this.getPos();if(n==null)return;let o=this.view.state.doc.nodeAt(n);o?.type===S.nodes.chart&&this.view.dispatch(this.view.state.tr.setNodeMarkup(n,null,{...o.attrs,...t}))}submenu(t){Gn(this.view,this.settings,t)}openSettings(){let t=this.node.attrs,n=Us(Ze(this.view.state.doc,t.source)),o=n?.cols??[],s=n?.rows??[];this.submenu([{label:"Line",icon:t.kind==="line"?"\u2713":"",run:()=>this.setAttrs({kind:"line"})},{label:"Bar",icon:t.kind==="bar"?"\u2713":"",run:()=>this.setAttrs({kind:"bar"})},{label:"X column \u25B8",focus:!1,run:()=>this.submenu(o.map(r=>({label:r.name||r.id,icon:t.x===r.id?"\u2713":"",run:()=>this.setAttrs({x:r.id,series:t.series.filter(i=>i!==r.id)})})))},{label:"Series \u25B8",focus:!1,run:()=>this.submenu(o.filter(r=>r.id!==t.x).map(r=>({label:r.name||r.id,icon:t.series.includes(r.id)?"\u2713":"",checked:t.series.includes(r.id),run:()=>this.setAttrs({series:t.series.includes(r.id)?t.series.filter(i=>i!==r.id):[...t.series,r.id]})})))},{label:"Highlight row \u25B8",focus:!1,run:()=>this.submenu([{label:"None",icon:t.highlight?"":"\u2713",run:()=>this.setAttrs({highlight:null})},...s.map(r=>({label:Dt(r.cells[t.x])||r.id,icon:t.highlight===r.id?"\u2713":"",run:()=>this.setAttrs({highlight:r.id})}))])},{label:"Edit title",focus:!1,run:()=>this.editTitle()}])}editTitle(){let t=this.dom.ownerDocument.createElement("input");t.type="text",t.className="page-chart-title-input",t.setAttribute("aria-label","Chart title"),t.value=this.node.attrs.title??"";let n=o=>{t.remove(),this.caption.hidden=!1,o?this.setAttrs({title:t.value}):this.settings.focus()};t.addEventListener("keydown",o=>{(o.key==="Enter"||o.key==="Escape")&&(o.preventDefault(),o.stopPropagation(),n(o.key==="Enter"))}),this.caption.hidden=!0,this.caption.after(t),t.focus(),t.select()}update(t){if(t.type!==S.nodes.chart)return!1;let n=!t.sameMarkup(this.node);return this.node=t,this.dom.dataset.id=t.attrs.id??"",n&&(this.source=Ze(this.view.state.doc,t.attrs.source),this.schedule()),!0}stopEvent(t){return!!t.target.closest?.(".page-chart-settings, .page-chart-title-input")}destroy(){if(pe.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 pu(){return new q.Plugin({view:()=>({update(e){for(let t of pe.get(e)??[])t.refresh()}})})}var{TextSelection:Qn}=q,mt=S.nodes,Tt=[{key:"text",label:"Text",description:"Plain writing",icon:"T",type:"paragraph",aliases:["p","paragraph","plain"]},{key:"h1",label:"Heading 1",description:"Big section heading",icon:"H1",type:"heading",attrs:{level:1},hint:"#",aliases:["h1","title"]},{key:"h2",label:"Heading 2",description:"Medium section heading",icon:"H2",type:"heading",attrs:{level:2},hint:"##",aliases:["h2","subtitle"]},{key:"h3",label:"Heading 3",description:"Small section heading",icon:"H3",type:"heading",attrs:{level:3},hint:"###",aliases:["h3"]},{key:"bullet",label:"Bulleted list",description:"A simple list",icon:"\u2022",type:"list_item",attrs:{kind:"bullet"},hint:"-",aliases:["ul","bullet","list","unordered"]},{key:"ordered",label:"Numbered list",description:"A list with numbers",icon:"1.",type:"list_item",attrs:{kind:"ordered"},hint:"1.",aliases:["ol","num","numbered","ordered"]},{key:"check",label:"Checklist",description:"Tasks to tick off",icon:"\u2610",type:"list_item",attrs:{kind:"check"},hint:"[]",aliases:["todo","to-do","task","check","checkbox"]},{key:"toggle",label:"Toggle",description:"Hide details under a line",icon:"\u25B8",type:"toggle",attrs:{open:!0},hint:">",aliases:["collapse","details","fold"]},{key:"callout",label:"Callout",description:"Make a note stand out",icon:"!",type:"callout",aliases:["note","aside","info"]},{key:"code",label:"Code",description:"Code with highlighting",icon:"</>",type:"code_block",hint:"```",aliases:["pre","snippet"]}],Wi=[{key:"divider",label:"Divider",description:"A line between sections",icon:"\u2014",hint:"---",aliases:["hr","line","separator","rule"],insert:"divider"},{key:"image",label:"Image",description:"Upload or paste a picture",icon:"\u25A3",aliases:["img","picture","photo"],insert:"image"},{key:"file",label:"File",description:"Attach any file",icon:"\u2398",aliases:["upload","attachment","pdf"],insert:"file"},{key:"table",label:"Table",description:"Rows and columns, paste from a spreadsheet",icon:"\u25A6",aliases:["grid","spreadsheet"],insert:"table"},{key:"csv",label:"Import CSV\u2026",description:"Turn a CSV file into a table",icon:"\u21E7",aliases:["comma separated","import"],insert:"csv"},{key:"board",label:"Board",description:"Cards in columns, like a kanban",icon:"\u25A5",aliases:["kanban","cards","columns","status"],insert:"board"}],Gi={key:"chart",label:"Chart",description:"A bar or line chart from a table",icon:"\u{1F4CA}",aliases:["graph","plot","bar","line"],insert:"chart"},en=[...Tt,...Wi],Qs=(e,t=en)=>Wn(e.doc).length?[...t,Gi]:t;function nn(e){let t=e.type.name;return Tt.find(n=>n.type===t&&(!n.attrs||(t==="heading"?n.attrs.level===e.attrs.level:t==="list_item"?n.attrs.kind===e.attrs.kind:!0)))??Tt[0]}var Zs=(e,t)=>{let n=0;for(let o=0;o<t;o++)n+=e.child(o).nodeSize;return n};function Rt(e,t,n){let o=Zs(e.doc,t),s=e.doc.child(t),r={id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent};return s.type===mt.list_item&&n.type==="list_item"&&(r.indent=s.attrs.indent),e.setBlockType(o+1,o+s.nodeSize-1,mt[n.type],{...r,...n.attrs||{}})}var Xi=Object.freeze({status:"refused",code:"unsupported-format"}),Qi=go([]).type,Zi=e=>{let t=!1;return e.forEach(n=>{!t&&n.marks.some(mo)&&(t=!0)}),t};function he(e,t){return!e.isTextblock||e.type===mt.opaque_block?!1:!Zi(e)||mt[t.type].allowsMarkType(Qi)}function tr(e,t,n=e.tr){let o=re(n.doc),{to:s}=zo(o,t),r=n.doc.child(t);return n.insert(s,mt.paragraph.create({parent:r.attrs.parent??null})),n.setSelection(Qn.create(n.doc,s+1))}var Xn=(e,t)=>kt(e)&&(t===null||kt(t)&&e<t)?V(e,t):null;function Zn(e,t){let n=Zs(e.doc,t),o=e.doc.child(t),s=e.doc.maybeChild(t+1),{id:r,pos:i,parent:c}=o.attrs;return e.replaceWith(n,n+o.nodeSize,[mt.divider.create({id:r,pos:i,parent:c}),mt.paragraph.create({id:R(),pos:Xn(i,s?s.attrs.pos:null),parent:c})]),e.setSelection(Qn.create(e.doc,n+2))}function tc(e,t,n=e.tr){let o=n.doc.child(t);if(o.type===mt.paragraph&&o.content.size===0)return Zn(n,t);let s=re(n.doc),r=s[t].subEnd,i=s[r].end,c=s[r+1]?.node.attrs.pos??null,f=Xn(s[r].node.attrs.pos,c),h=o.attrs.parent??null;return n.insert(i,[mt.divider.create({id:R(),pos:f,parent:h}),mt.paragraph.create({id:R(),pos:Xn(f,c),parent:h})]),n.setSelection(Qn.create(n.doc,i+2))}function ec(e,t){if(e.length<2||e.length>32)return 1/0;let n=-1,o=0;for(let s of e){let r=t.indexOf(s,n+1);if(r<0)return 1/0;o+=r-n-1,n=r}return o}function er(e,t){let n=t.trim().toLowerCase();if(!n)return e;let o=s=>{let r=s.label.toLowerCase(),i=[s.key,...s.aliases||[],...s.hint?[s.hint]:[]].map(f=>f.toLowerCase());if(r===n||i.includes(n))return[0,0];if(r.startsWith(n))return[1,0];if([...r.split(/\s+/),...i].some(f=>f.startsWith(n)))return[2,0];if([r,...i].some(f=>f.includes(n)))return[3,0];if(n.length>=3&&s.description&&s.description.toLowerCase().split(/[^a-z0-9]+/).some(f=>f.startsWith(n)))return[4,0];let c=Math.min(...[r,s.key,...s.aliases||[]].map(f=>ec(n,f.toLowerCase())));return c===1/0?null:[5,c]};return e.map((s,r)=>({it:s,order:r,rank:o(s)})).filter(s=>s.rank).sort((s,r)=>s.rank[0]-r.rank[0]||s.rank[1]-r.rank[1]||s.order-r.order).map(s=>s.it)}function nr(e,t,n,o=null){let s=e.state;if(t.insert==="image"||t.insert==="file")return Xo(e,t.insert==="image"?"image/*":"",Go(s,n),o);if(t.insert==="csv")return tn(e,o);if(t.insert==="table")return vt(s,e.dispatch,Fs(),o,null,n);if(t.insert==="board")return Hs(s,e.dispatch,Jn(),o,n);if(t.insert==="chart")return Xs(e,n,o);let r=s.tr;o&&r.delete(o.from,o.to);let i=r.doc.child(n);return i.isTextblock&&i.content.size===0&&!he(i,t)?Xi:(t.insert==="divider"?r=tc(s,n,r):i.isTextblock&&i.content.size===0?r=Rt(r,n,t):(r=tr(s,n,r),r=Rt(r,r.doc.resolve(r.selection.head).index(0),t)),e.dispatch(F(r).scrollIntoView()),e.focus(),!0)}var{InputRule:no}=mn,qt=S.nodes,on=(e,t,n)=>e.doc.rangeHasMark(t,n,S.marks.code)||!!S.marks.code.isInSet(e.storedMarks||e.selection.$from.marks()),Ht=(e,t,n=["paragraph"],o=!1)=>new no(e,(s,r,i,c)=>{let f=s.doc.resolve(i);return!s.selection.empty||f.depth!==1||f.parentOffset!==0||!n.includes(f.parent.type.name)||o&&c!==f.end()||on(s,i,c)?null:F(Rt(s.tr.delete(i,c),f.index(0),typeof t=="function"?t(r):t))}),nc=new no(/^---$/,(e,t,n,o)=>{let s=e.doc.resolve(n);return!e.selection.empty||s.depth!==1||s.parent.type!==qt.paragraph||s.parentOffset!==0||s.parent.content.size!==o-n||on(e,n,o)?null:F(Zn(e.tr,s.index(0)))}),oo=`\\s\\(\\[\\{'\u2018\u201C"`,oc=new RegExp(`[${oo}]`),to=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),or=e=>`([^\\s${e}](?:[\\s\\S]*?[^\\s${e}])?)`,sn=(e,t)=>!!e?.isComposing||e?.keyCode===229||!!t?.composing,sr=e=>{let t=0;for(let n=e.length-1;n>=0&&e[n]==="\\";n--)t++;return t},sc=(e,t)=>{let n=e.doc.resolve(t);return!n.parent.inlineContent||sr(n.parent.textBetween(0,n.parentOffset,null,"\uFFFC"))%2?!1:n.parentOffset===0||oc.test(n.parent.textBetween(n.parentOffset-1,n.parentOffset))},rc=(e,t,n,o,s)=>{let r=s(t);if(!r||!e.selection.empty||n<0||n>o||o>e.doc.content.size)return null;let i=e.doc.resolve(n),c=e.doc.resolve(o);if(!i.sameParent(c)||!i.parent.inlineContent)return null;let[f,h,a,l]=t;if(on(e,n,o))return null;let u=f.slice(h.length,f.length-a.length-l.length),p=n+h.length;if(!sc(e,p)||sr(f.slice(0,f.length-l.length))%2)return null;let m=f.length-(o-n);if(m<0)return null;let g=e.tr;m&&g.insertText(f.slice(-m),o,o);let y=p+u.length,x=y+a.length;return g.delete(x,n+f.length),g.delete(p,y),g.addMark(p,p+a.length,r),g.removeStoredMark(r.type),F(g)},rr=(e,t)=>new no(e,(n,o,s,r)=>rc(n,o,s,r,t),{inCodeMark:!1}),Ut=(e,t,n)=>rr(new RegExp(`(^|[${oo}])${to(e)}${or(to(t))}(${to(t)})$`),()=>n.create()),ic=rr(new RegExp(`(^|[${oo}])\\[${or("\\[\\]")}(\\]\\([^()\\s]*\\))$`),e=>{let t=po(e[3].slice(2,-1));return t?S.marks.link.create({href:t}):null}),cc=[Ut("**","**",S.marks.strong),Ut("__","__",S.marks.strong),Ut("*","*",S.marks.em),Ut("_","_",S.marks.em),Ut("`","`",S.marks.code),Ut("~~","~~",S.marks.strike),ic],eo=["paragraph","list_item"],lc=[Ht(/^(#{1,3})\s$/,e=>({type:"heading",attrs:{level:e[1].length}})),Ht(/^[-*+]\s$/,{type:"list_item",attrs:{kind:"bullet"}},eo),Ht(/^\d+[.)]\s$/,{type:"list_item",attrs:{kind:"ordered"}},eo),Ht(/^\[( |x|X)?\]\s$/,e=>({type:"list_item",attrs:{kind:"check",checked:!!e[1]&&e[1]!==" "}}),eo),Ht(/^>\s$/,{type:"toggle",attrs:{open:!0}}),Ht(/^```$/,{type:"code_block"},["paragraph"],!0),nc,...cc],Nu=()=>mn.inputRules({rules:lc}),ac=/^\s*\|(.*)\|\s*$/;function uc(e,t){let{$from:n,empty:o}=e.selection;if(!o||n.depth!==1||n.parent.type!==qt.paragraph||n.parentOffset!==n.parent.content.size||on(e,n.start(),n.end()))return!1;let s=ac.exec(n.parent.textContent);if(!s)return!1;let r=s[1].split("|").map(c=>c.trim());if(!r.some(Boolean))return!1;let i=Xe([r,r.map(()=>"")],{header:!0});return vt(e,t,i,{from:n.start(),to:n.end()})}var Lu=()=>we.keymap({Enter:(e,t,n)=>!sn(null,n)&&uc(e,t)});function ju(e,t){let{$from:n,empty:o}=e.selection;if(!o||n.depth!==1||n.parentOffset!==0)return!1;let s=n.parent;return s.type===qt.heading||s.type===qt.callout||s.type===qt.code_block&&s.content.size===0?(t&&t(F(e.tr.setNodeMarkup(n.before(),qt.paragraph,{id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent}))),!0):!1}var{Plugin:dr,PluginKey:fr,TextSelection:cn,NodeSelection:dc}=q,pr=S.marks,$t=S.nodes,so=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"\u2318":"Ctrl+",hr=e=>{let t=Ie(e.doc),{lo:n,hi:o}=e.selection.span(e.doc);return t.slice(n,o+1).filter(s=>s.up===t[n].up)},rn=(e,t)=>e.state.doc.child(t).attrs.id,fc=(e,t)=>{let n=0;for(let o=0;o<t;o++)n+=e.child(o).nodeSize;return n},ir=["aria-haspopup","aria-controls","aria-activedescendant"],pc="That block is no longer available.",co="This block holds content from a newer version, so it can't be converted here.";function cr(e){let t=e.visualViewport;return t?{left:t.offsetLeft,top:t.offsetTop,width:t.width,height:t.height}:{left:0,top:0,width:e.innerWidth,height:e.innerHeight}}function hc(e,t,n,o=0){let s=Kt,r=Math.min(t,Math.max(0,e.width-s*2));return{left:e.left+(e.width-r)/2,top:Math.max(e.top+s,e.top+e.height-n-o-s),width:r}}function mc(e,t=globalThis.location){return`${t.origin}${t.pathname}${t.search}#${encodeURIComponent(e)}`}function gc(e){if(!e)return;let t=()=>ie("Link copied"),n=()=>ie("Could not copy the link.","error");if(!globalThis.navigator?.clipboard?.writeText){n();return}globalThis.navigator.clipboard.writeText(mc(e)).then(t,n)}var mr=[{key:"up",label:"Move up",icon:"\u2191",hint:`${so}\u21E7\u2191`,run:e=>xn(-1)(e.state,e.dispatch)},{key:"down",label:"Move down",icon:"\u2193",hint:`${so}\u21E7\u2193`,run:e=>xn(1)(e.state,e.dispatch)},{key:"indent",label:"Indent",icon:"\u2192",hint:"Tab",run:e=>Yo(e.state,e.dispatch)},{key:"outdent",label:"Outdent",icon:"\u2190",hint:"\u21E7Tab",run:e=>Vo(e.state,e.dispatch)},{key:"duplicate",label:"Duplicate",icon:"\u29C9",hint:`${so}D`,run:e=>Jo(e.state,e.dispatch)},{key:"delete",label:"Delete",icon:"\xD7",hint:"Del",run:e=>Sn(e.state,e.dispatch)},{key:"turn",label:"Turn into",icon:"\u21BB",hint:"\u203A",only:"text",run:(e,t)=>t.openMenu("turn",t.plus)},{key:"link",label:"Copy link",icon:"\u{1F517}",run:(e,t,n)=>gc(e.state.doc.child(n).attrs.id)},{key:"alt",label:"Alt text\u2026",icon:"Aa",only:"image",focus:!1,run:(e,t,n)=>Qo(e,rn(e,n))},{key:"small",label:"Small",icon:"\u25AB",only:"image",run:(e,t,n)=>Te(e,rn(e,n),{width:240})},{key:"medium",label:"Medium",icon:"\u25FB",only:"image",run:(e,t,n)=>Te(e,rn(e,n),{width:480})},{key:"full",label:"Full width",icon:"\u2B1C",only:"image",run:(e,t,n)=>Te(e,rn(e,n),{width:null})},{key:"chart",label:"Chart this table",icon:"\u{1F4CA}",only:"table",run:(e,t,n)=>Gs(e,fc(e.state.doc,n))},{key:"csv",label:"Import CSV\u2026",icon:"\u21E7",only:"table",focus:!1,run:(e,t,n)=>tn(e,null,e.state.doc.child(n).attrs.id)}],yc=e=>{if(!(e.selection instanceof wt))return[];let t=hr(e),n=t.every(r=>r.node.isTextblock),o=t.length===1&&t[0].node.type===$t.image,s=t.length===1&&t[0].node.type===$t.table;return mr.filter(r=>r.only==="text"?n:r.only==="image"?o:r.only==="table"?s:!0)},ft=e=>`<svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`,me={plus:ft('<path d="M8 3.5v9M3.5 8h9"/>'),grip:ft('<path stroke-width="2.2" d="M6 3.5h.01M10 3.5h.01M6 8h.01M10 8h.01M6 12.5h.01M10 12.5h.01"/>'),strong:ft('<path d="M5 3h4a2.5 2.5 0 0 1 0 5H5zM5 8h4.6a2.5 2.5 0 0 1 0 5H5z"/>'),em:ft('<path d="M10 3H6.5M9.5 13H6M9 3l-2 10"/>'),strike:ft('<path d="M3 8h10M10.8 5.2C10.5 4 9.4 3.2 8 3.2c-1.7 0-2.8.9-2.8 2.1M5.2 10.8c.3 1.2 1.4 2 2.8 2 1.7 0 2.8-.9 2.8-2.1"/>'),code:ft('<path d="M6 4.5 2.5 8 6 11.5M10 4.5 13.5 8 10 11.5"/>'),link:ft('<path d="M7 9a2.5 2.5 0 0 0 3.5 0l2-2A2.5 2.5 0 0 0 9 3.5l-.7.7M9 7a2.5 2.5 0 0 0-3.5 0l-2 2A2.5 2.5 0 0 0 7 12.5l.7-.7"/>'),bullet:ft('<path d="M6.5 4.5h7M6.5 8h7M6.5 11.5h7"/><path stroke-width="2.4" d="M3 4.5h.01M3 8h.01M3 11.5h.01"/>'),ordered:ft('<path d="M7 4.5h6.5M7 8h6.5M7 11.5h6.5M2.5 3.5l1-.5v3M2.5 9.3c.2-.5.6-.8 1.1-.8.6 0 1 .4 1 .9 0 .9-2.1 1.4-2.1 2.6h2.1"/>'),check:ft('<rect x="2.5" y="2.5" width="11" height="11" rx="2.5"/><path d="M5.5 8.2l1.8 1.8 3.4-4"/>'),more:ft('<path stroke-width="2.2" d="M3 8h.01M8 8h.01M13 8h.01"/>')},ro=[["strong","Bold"],["em","Italic"],["strike","Strikethrough"],["link","Link"],["bullet","Bulleted list"],["ordered","Numbered list"],["check","Checklist"],["code","Code"]],gr=new Set(["strong","em","link"]),kc=new Set(["up","down","indent","outdent"]),bc=204,wc=52,Kt=8,yr=new Set(["bullet","ordered","check"]),xc=new Set(["paragraph","heading","list_item"]),ge=e=>{let t=e.selection;if(t instanceof wt)return hr(e).map(c=>c.i);let{$from:n,$to:o,empty:s}=t,r=Math.min(!s&&o.depth===0?o.index(0)-1:o.index(0),e.doc.childCount-1),i=[];for(let c=n.index(0);c<=r;c++)i.push(c);return i},kr=e=>ge(e).filter(t=>{let n=e.doc.child(t);return n.isTextblock&&n.type!==$t.code_block}),br=(e,t)=>e.type===$t.list_item&&e.attrs.kind===t,wr=(e,t)=>{let n=kr(e);return n.length>0&&n.every(o=>br(e.doc.child(o),t))},vc=e=>{let t="";return e.forEach(n=>{t+=n.isText?n.text:n.type===$t.hard_break?`
|
|
5
|
+
`:""}),t};function Sc(e){let{$from:t,$to:n,empty:o}=e.selection;if(o||!(e.selection instanceof cn)||t.depth!==1||n.depth!==1||t.parentOffset!==0||n.parentOffset!==n.parent.content.size)return null;let s=ge(e);return s.every(r=>xc.has(e.doc.child(r).type.name))?s:null}function Oc(e,t){let n=e.doc.child(t[0]),o=e.selection.$from.before(1),s=e.selection.$to.after(1),r=t.map(a=>vc(e.doc.child(a))).join(`
|
|
6
|
+
`),{id:i,pos:c,parent:f}=n.attrs,h=e.tr.replaceWith(o,s,$t.code_block.create({id:i,pos:c,parent:f},r?S.text(r):null));return h.setSelection(cn.create(h.doc,o+1,o+1+r.length))}function Mc(e,t){let n=e.tr,o=e.doc.resolve(e.selection.from).before(1),s=0;for(let r of[...t].reverse()){let i=0;for(let u=0;u<r;u++)i+=e.doc.child(u).nodeSize;let c=e.doc.child(r),{id:f,pos:h,parent:a}=c.attrs,l=c.textContent.split(`
|
|
7
|
+
`).map((u,p)=>$t.paragraph.create(p===0?{id:f,pos:h,parent:a}:{parent:a},u?S.text(u):null));n.replaceWith(i,i+c.nodeSize,l),s||(s=i+l.reduce((u,p)=>u+p.nodeSize,0))}return s=n.mapping.slice(1).map(s),n.setSelection(cn.create(n.doc,o+1,s-1))}var xr=e=>{let t=ge(e);return t.length>0&&t.every(n=>e.doc.child(n).type===$t.code_block)?t:null};function lr(e,t){if(yr.has(t))return wr(e,t);if(t==="code"&&xr(e))return!0;let n=pr[t],{from:o,to:s,empty:r,$from:i}=e.selection;return r?!!n.isInSet(e.storedMarks||i.marks()):e.doc.rangeHasMark(o,s,n)}function Cc(e,t){let n=e.state,o=wr(n,t),s=Tt.find(c=>c.key===(o?"text":t)),r=kr(n).filter(c=>o||!br(n.doc.child(c),t));if(r.some(c=>!he(n.doc.child(c),s))){_t(e,co);return}let i=n.tr;for(let c of r)Rt(i,c,s);i.docChanged&&e.dispatch(F(i))}function ar(e,t){if(t==="link")return Ko(e);let n=e.state,o=t==="code"?xr(n):null,s=t==="code"&&!o?Sc(n):null;yr.has(t)?Cc(e,t):o?e.dispatch(F(Mc(n,o)).scrollIntoView()):s&&s.some(r=>!he(n.doc.child(r),Tt.find(i=>i.key==="code")))?_t(e,co):s?e.dispatch(F(Oc(n,s)).scrollIntoView()):fo.toggleMark(pr[t])(n,e.dispatch),e.focus()}var W=(e,t,n={})=>{let o=document.createElement(e);t&&(o.className=t);for(let[s,r]of Object.entries(n))o.setAttribute(s,r);return o};function ur(e,t){let n=W("button",`page-tool${gr.has(e)?" page-tool-primary":" page-tool-desk"}`,{type:"button","data-cmd":e,"aria-label":t,title:t});return n.innerHTML=me[e],n}var Ac=1600,Ec=0,Ic=new fr("page-chrome"),vr=new WeakMap,ln=new fr("page-slash-range"),Tc={init:()=>null,apply(e,t){let n=t;if(n&&e.docChanged){let s=e.mapping.map(n.from,1),r=e.mapping.map(n.to,-1);n=s<=r&&e.doc.textBetween(s,r)===n.text?{...n,from:s,to:r}:null}let o=e.getMeta(ln);return o!==void 0&&(n=o),n}},nd=()=>new dr({key:ln,state:Tc}),Sr=(e,t)=>{let n=t?e.state.doc.textBetween(t.from,t.to):null;e.dispatch(e.state.tr.setMeta(ln,t?{...t,text:n}:null))},Or=e=>{let t=ln.getState(e);return t?{from:t.from,to:t.to}:null};function Gn(e,t,n){let o=vr.get(e);return o?(o.openMenu("external",t),o.menu.externalItems=n,o.renderMenu(),!0):!1}var io=class{constructor(t,n){this.view=t,this.onAiTool=n,this.shell=t.dom.parentElement,this.menu=null,this.priorAria=null,this.movedTimer=0,this.hover=null,this.pendingHover=null,this.win=t.dom.ownerDocument.defaultView??globalThis,this.frame=null,this.destroyed=!1,this.probe=null,this.roving=null,this.dock=W("div","page-dock",{role:"toolbar","aria-label":"Formatting"}),this.turn=W("button","page-tool page-tool-turn page-tool-desk",{type:"button","aria-haspopup":"menu"}),this.more=W("button","page-tool page-tool-primary page-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.more.innerHTML=me.more,this.dock.append(this.turn,W("span","page-tool-sep page-tool-desk"),...ro.map(([s,r])=>ur(s,r)),this.more),this.plus=W("button","page-plus",{type:"button","aria-label":"Add a block",title:"Add a block"}),this.plus.innerHTML=me.plus,this.grip=W("button","page-grip",{type:"button","aria-label":"Block actions",title:"Drag to move, click for actions","aria-haspopup":"menu"}),this.grip.innerHTML=me.grip,this.bubble=W("div","page-bubble",{role:"toolbar","aria-label":"Selection",hidden:""}),this.bubble.append(...ro.map(([s,r])=>ur(s,r))),this.menuId=`page-menu-${++Ec}`,this.menuEl=W("div","page-menu",{role:"menu",id:this.menuId,hidden:""}),this.scrim=W("div","page-scrim",{hidden:""}),this.shell.insertBefore(this.dock,t.dom),this.shell.append(this.plus,this.grip,this.bubble,this.scrim,this.menuEl);let o=s=>s.preventDefault();for(let s of[this.dock,this.plus,this.grip,this.bubble,this.menuEl])s.addEventListener("mousedown",o);for(let s of[this.dock,this.bubble])s.addEventListener("click",r=>{let i=r.target.closest("[data-cmd]");i&&ar(this.view,i.dataset.cmd)});this.turn.addEventListener("click",()=>this.toggleMenu("turn",this.turn)),this.more.addEventListener("click",()=>this.toggleMenu("more",this.more)),this.dock.addEventListener("keydown",s=>this.dockKey(s)),this.plus.addEventListener("click",()=>this.fromPlus()),this.grip.addEventListener("click",s=>{s.detail===0&&this.gripAction(this.gutterIndex())}),this.drag=new Zo(t,this.grip,{index:()=>this.gutterIndex(),onClick:s=>this.gripAction(s)}),this.scrim.addEventListener("click",()=>this.closeMenu()),this.menuEl.addEventListener("click",s=>{let r=s.target.closest(".page-menu-item");r&&this.pick(Number(r.dataset.index))}),this.menuEl.addEventListener("keydown",s=>{this.key(s)&&s.preventDefault()}),this.onMove=s=>{this.shell.classList.add("is-moved"),clearTimeout(this.movedTimer),this.movedTimer=setTimeout(()=>this.shell.classList.remove("is-moved"),Ac),this.trackHover(s)},this.onKey=()=>{clearTimeout(this.movedTimer),this.shell.classList.remove("is-moved"),this.pendingHover=null,this.setHover(null)},this.onLeave=()=>{this.pendingHover=null,this.setHover(null)},this.onResize=()=>this.scheduleLayout(),this.onDocDown=s=>{this.menu&&([this.menuEl,this.plus,this.grip,this.turn].some(r=>r.contains(s.target))||this.closeMenu())},document.addEventListener("mousedown",this.onDocDown,!0),this.shell.addEventListener("mousemove",this.onMove),this.shell.addEventListener("mouseleave",this.onLeave),this.shell.addEventListener("keydown",this.onKey),this.win.addEventListener("resize",this.onResize),this.win.addEventListener("scroll",this.onResize,!0),this.win.visualViewport?.addEventListener("resize",this.onResize),this.win.visualViewport?.addEventListener("scroll",this.onResize),this.update(t,null)}blockIndex(){let t=this.view.state,n=t.selection,o=n instanceof wt||n instanceof dc?n.from:n.head;return Math.min(t.doc.resolve(o).index(0),t.doc.childCount-1)}isPhone(){return!!this.win?.matchMedia?.("(max-width: 560px)").matches}gutterIndex(){return this.isPhone()?this.blockIndex():(this.settleHover(),Math.min(this.hover??this.blockIndex(),this.view.state.doc.childCount-1))}dockControls(){let t=[...this.dock.querySelectorAll("button")].filter(n=>this.rendered(n));return this.isPhone()?t.filter(n=>n.classList.contains("page-tool-primary")):t}inRoving(t){return!t||!this.dock.contains(t)||this.isPhone()&&!t.classList.contains("page-tool-primary")?!1:this.rendered(t)}rendered(t){if(t.hidden)return!1;let n=this.win?.getComputedStyle?.(t);return!n||n.display!=="none"}setRoving(t){this.roving=t;let n=new Set(this.dockControls());for(let o of this.dock.querySelectorAll("button"))o.tabIndex=o===t&&n.has(o)?0:-1}leaveToToolbar(){queueMicrotask(()=>{this.view.isDestroyed||this.focusToolbar()})}focusToolbar(){let[t]=this.dockControls();return t?(this.setRoving(t),t.focus(),!0):!1}dockKey(t){if(t.key==="Escape"){t.preventDefault(),this.view.focus();return}if(t.key!=="ArrowRight"&&t.key!=="ArrowLeft")return;let n=this.dockControls(),o=n.indexOf(t.target);if(o<0)return;t.preventDefault();let s=n[(o+(t.key==="ArrowRight"?1:-1)+n.length)%n.length];this.setRoving(s),s.focus()}selectionIds(){let t=this.view.state;return ge(t).map(n=>t.doc.child(n).attrs.id)}idIndex(t){let n=-1;return this.view.state.doc.forEach((o,s,r)=>{o.attrs.id===t&&(n=r)}),n}invoker(){let t=this.menu;if(!t||t.slashAt!==null)return this.view.dom;let n=t.anchor;return n&&n!==this.view.dom&&(n.tagName==="BUTTON"||n.hasAttribute("tabindex"))?n:this.view.dom}selectCaretBlock(t=null){let n=this.view.state;if(n.selection instanceof wt)return;let o=(t??[]).map(r=>this.idIndex(r)).filter(r=>r>=0),s=o.length?o[0]:this.blockIndex();this.view.dispatch(n.tr.setSelection(vn(n.doc,s,o.length?o[o.length-1]:s)))}gripAction(t){this.menu?this.closeMenu():this.openActions(this.grip,t)}trackHover(t){this.menu||this.drag.state||[this.plus,this.grip,this.dock,this.bubble].some(n=>n.contains(t.target))||(this.pendingHover={clientY:t.clientY},this.scheduleLayout())}hoverAt(t){let n=this.view,o=n.posAtCoords({left:n.dom.getBoundingClientRect().left+2,top:t});if(!o)return;let s=n.state.doc,r=Ie(s),i=Math.min(s.resolve(o.inside>=0?o.inside:o.pos).index(0),r.length-1);for(;i>0&&r[i].hidden;)i--;this.hover=i}setHover(t){t!==this.hover&&(this.hover=t,this.scheduleLayout())}settleHover(){if(!this.pendingHover)return;let{clientY:t}=this.pendingHover;this.pendingHover=null,this.hoverAt(t)}fromPlus(){this.view.focus();let t=this.gutterIndex();this.openMenu("insert",this.plus,null,null,this.view.state.doc.child(t).attrs.id)}toggleMenu(t,n){this.menu?this.closeMenu():this.openMenu(t,n)}openMenu(t,n,o=null,s=null,r=null){this.menu={mode:t,anchor:n,slashAt:o,anchorId:r,ids:s??(t==="insert"?[]:this.selectionIds()),query:"",active:0,items:[]},n.setAttribute("aria-expanded","true"),o!==null?(this.priorAria||(this.priorAria=ir.map(i=>[i,this.view.dom.getAttribute(i)])),this.view.dom.setAttribute("aria-haspopup","listbox")):this.view.dom.setAttribute("aria-haspopup","menu"),this.view.dom.setAttribute("aria-controls",this.menuId),this.renderMenu()}closeMenu(){if(this.menu?.anchor.setAttribute("aria-expanded","false"),this.menu=null,this.menuEl.hidden=!0,this.scrim.hidden=!0,this.priorAria){for(let[t,n]of this.priorAria)n===null?this.view.dom.removeAttribute(t):this.view.dom.setAttribute(t,n);this.priorAria=null}else for(let t of ir)this.view.dom.removeAttribute(t)}moreItems(){let t=ro.filter(([o])=>!gr.has(o)).map(([o,s])=>({key:o,label:s,icon:me[o],run:r=>ar(r,o)})),n=mr.filter(o=>kc.has(o.key)).map(o=>({...o,blocks:!0}));return[...t,{key:"turn",label:"Turn into",icon:"\u21BB",run:(o,s)=>s.openMenu("turn",s.more)},{key:"insert",label:"Insert",icon:"+",run:(o,s)=>s.openMenu("insert",s.more,null,null,o.state.doc.child(s.blockIndex()).attrs.id)},...n]}menuItems(t){if(t.mode==="external")return t.externalItems||[];if(t.mode==="actions")return yc(this.view.state);if(t.mode==="more")return this.moreItems();let n=t.mode==="turn"?Tt:Qs(this.view.state,this.onAiTool?[...en,{key:"ai",label:"Make a tool with AI\u2026",icon:"\u2726",aliases:["tool","generate"],insert:"ai"}]:en);return er(n,t.query)}currentTypes(){let t=this.view.state;return new Set(ge(t).map(n=>nn(t.doc.child(n)).key))}openActions(t=this.plus,n=null){let o=this.view.state,s=Ie(o.doc),r=o.selection,i=n!==null&&r instanceof wt&&r.span(o.doc).lo<=n&&n<=r.span(o.doc).hi,{lo:c,hi:f}=n===null||i?qo(o,s):Fo(s,n,n);this.view.dispatch(o.tr.setSelection(vn(o.doc,c,f,s)));let h=[];for(let a=c;a<=f;a++)h.push(o.doc.child(a).attrs.id);this.openMenu("actions",t,null,h)}renderMenu(){let t=this.menu;t.items=this.menuItems(t),t.active=Math.min(t.active,Math.max(0,t.items.length-1));let n=t.slashAt!==null,o=t.mode==="turn"?this.currentTypes():null;this.menuEl.setAttribute("role",n?"listbox":"menu");let s=[];if(t.mode==="turn"){let r=W("div","page-menu-title");r.textContent=t.query?`Turn into \u201C${t.query}\u201D`:"Turn into",s.push(r)}if(!t.items.length){let r=W("div","page-menu-empty");r.textContent="No matching blocks",s.push(r)}t.items.forEach((r,i)=>{let c=i===t.active,f=o?o.size===1&&r.key===[...o][0]:typeof r.checked=="boolean"?r.checked:null,h=t.mode==="turn"?"menuitemradio":typeof f=="boolean"?"menuitemcheckbox":n?"option":"menuitem",a=W("button",`page-menu-item${c?" is-active":""}`,{type:"button",role:h,tabindex:!n&&c?"0":"-1",id:`${this.menuId}-${i}`,"data-index":String(i),...h==="menuitemradio"?{}:{"aria-selected":c?"true":"false"},...typeof f=="boolean"?{"aria-checked":String(f)}:{}}),l=W("span","page-menu-icon");l.textContent=r.icon||"";let u=W("span","page-menu-label");if(u.textContent=r.label,r.description){let p=W("span","page-menu-text"),m=W("span","page-menu-desc");m.textContent=r.description,p.append(u,m),a.append(l,p)}else a.append(l,u);if(r.hint){let p=W("span","page-menu-hint");p.textContent=r.hint,a.append(p)}s.push(a)}),this.menuEl.replaceChildren(...s),n&&t.items.length?this.view.dom.setAttribute("aria-activedescendant",`${this.menuId}-${t.active}`):this.view.dom.removeAttribute("aria-activedescendant"),this.menuEl.hidden=!1,this.scrim.hidden=!1,this.scheduleLayout(),n||this.menuEl.querySelectorAll("button")[t.active]?.focus()}pick(t){let n=this.menu,o=n?.items[t];if(!o)return;let s=this.view.state,r=n.slashAt!==null&&s.selection.head>=n.slashAt?{from:n.slashAt-1,to:s.selection.head}:null,i=n.mode==="insert"?n.anchorId?[n.anchorId]:[]:n.ids,c=i.some(h=>!h||this.idIndex(h)<0),f=i.length?this.idIndex(i[0]):-1;if(this.closeMenu(),c&&n.mode!=="external"){_t(this.view,pc),this.view.focus();return}if(n.mode==="turn"){if(i.some(a=>!he(s.doc.child(this.idIndex(a)),o))){_t(this.view,co),this.view.focus();return}let h=s.tr;for(let a of i)Rt(h,this.idIndex(a),o);this.view.dispatch(F(h).scrollIntoView()),this.view.focus()}else n.mode==="actions"||n.mode==="more"||n.mode==="external"?(o.blocks&&this.selectCaretBlock(i),o.run(this.view,this,f>=0?f:this.blockIndex()),!this.menu&&o.focus!==!1&&this.view.focus()):o.insert==="ai"?this.onAiTool(this.view,r):nr(this.view,o,f>=0?f:this.blockIndex(),r)}key(t){if(sn(t,this.view))return!1;let n=this.menu;if(!n)return t.key==="Escape"&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&this.view.state.selection instanceof wt&&this.leaveToToolbar(),!1;if((t.key==="Backspace"||t.key==="Delete")&&n.mode==="actions"&&this.view.state.selection instanceof wt)return this.closeMenu(),this.view.focus(),Sn(this.view.state,this.view.dispatch),!0;if(t.key==="ArrowDown"||t.key==="ArrowUp")return n.items.length&&(n.active=(n.active+(t.key==="ArrowDown"?1:-1)+n.items.length)%n.items.length,this.renderMenu()),!0;if(t.key==="Enter")return n.items.length&&this.pick(n.active),!0;if(t.key==="Escape"){let o=this.invoker();return this.closeMenu(),o===this.view.dom?this.view.focus():o?.focus?.(),!0}return!1}slashQuery(){let t=this.menu;if(!t||t.slashAt===null)return;let{$head:n}=this.view.state.selection,o=n.start();if(n.pos<t.slashAt||t.slashAt<o||this.view.state.doc.textBetween(t.slashAt-1,t.slashAt)!=="/")return this.closeMenu();if(t.query=this.view.state.doc.textBetween(t.slashAt,n.pos),t.active=0,/\s$/.test(t.query)&&!this.menuItems(t).length)return this.closeMenu();this.renderMenu()}scheduleLayout(){this.frame!==null||this.destroyed||(this.frame=this.win.requestAnimationFrame(()=>{if(this.frame=null,this.destroyed)return;let t=this.measureLayout();this.paintLayout(t)}))}safeBottom(){return this.probe||(this.probe=W("div","page-safe-probe"),this.shell.append(this.probe)),parseFloat(this.win.getComputedStyle(this.probe).paddingBottom)||0}menuBox(t){let n=cr(this.win),o=Math.max(0,n.height-Kt*2),s=Math.min(280,Math.max(0,n.width-Kt*2)),r=this.menuEl.style.getPropertyValue("--page-pop-max");this.menuEl.style.removeProperty("--page-pop-max");let i=this.menuEl.offsetHeight||0;r&&this.menuEl.style.setProperty("--page-pop-max",r);let c=Math.min(i,o),f=Math.max(n.left+Kt,Math.min(t.left,n.left+n.width-Kt-s)),h=t.top-6-c;return h<n.top+Kt&&(h=Math.min(t.top+t.height+6,n.top+n.height-Kt-c)),{left:f,top:h,width:s,maxHeight:o}}measureLayout(){let t=this.view,n=t.state;this.settleHover();let o=this.shell.getBoundingClientRect(),s=t.dom.getBoundingClientRect(),r=this.gutterIndex(),i=0;for(let l=0;l<r;l++)i+=n.doc.child(l).nodeSize;let c=t.nodeDOM(i),f={textLeft:s.left-o.left,gutter:null,bubble:null,menu:null,bar:null,desk:!1};if(c&&c.getBoundingClientRect){let l=c.getBoundingClientRect(),u=parseFloat(getComputedStyle(c).lineHeight)||l.height;f.gutter={top:l.top-o.top+Math.min(l.height,u)/2,left:l.left-o.left}}let h=this.isPhone();if(h){let l=cr(this.win),u=this.dock.offsetHeight||wc;f.bar={...hc(l,this.dock.offsetWidth||bc,u,this.safeBottom()),height:u}}else f.desk=!!this.dock.style.left;let a=n.selection;if(!this.bubble.hidden&&!h){let l=t.coordsAtPos(a.from),u=t.coordsAtPos(a.to,-1),p=(Math.min(l.left,u.left)+Math.max(l.right,u.right))/2;f.bubble={x:p-o.left,y:Math.min(l.top,u.top)-o.top}}if(this.menu&&h){let l=this.menuBox(f.bar);f.menu={x:l.left,y:l.top,width:l.width,maxHeight:l.maxHeight}}else if(this.menu){let l=this.menu,u,p;if(l.slashAt!==null){let m=t.coordsAtPos(l.slashAt-1);u=m.left,p=m.bottom+6;let g=this.menuEl.offsetHeight;p+g>this.win.innerHeight-8&&m.top-6-g>=8&&(p=m.top-6-g)}else{let m=l.anchor===this.plus?c?.getBoundingClientRect?.()??s:l.anchor.getBoundingClientRect();u=m.left,p=m.bottom+6}f.menu={x:Math.max(8,Math.min(u-o.left,o.width-280)),y:p-o.top}}return f}paintLayout(t){if(t.bar)this.dock.style.left=`${t.bar.left}px`,this.dock.style.top=`${t.bar.top}px`,this.dock.style.width=`${t.bar.width}px`,this.grip.style.setProperty("--page-grip-lift",`${t.bar.height}px`);else{if(t.desk)for(let n of["left","top","width"])this.dock.style.removeProperty(n);this.grip.style.removeProperty("--page-grip-lift")}if(t.gutter)for(let n of[this.plus,this.grip])n.style.setProperty("--page-plus-top",`${t.gutter.top}px`),n.style.setProperty("--page-plus-left",`${t.gutter.left}px`);this.plus.style.setProperty("--page-text-left",`${t.textLeft}px`),t.bubble&&(this.bubble.style.setProperty("--page-pop-x",`${t.bubble.x}px`),this.bubble.style.setProperty("--page-pop-y",`${t.bubble.y}px`)),t.menu&&(this.menuEl.style.setProperty("--page-pop-x",`${t.menu.x}px`),this.menuEl.style.setProperty("--page-pop-y",`${t.menu.y}px`),t.menu.width!==void 0&&(this.menuEl.style.setProperty("--page-pop-width",`${t.menu.width}px`),this.menuEl.style.setProperty("--page-pop-max",`${t.menu.maxHeight}px`)))}update(t,n){if(this.view=t,this.menu&&this.menu.slashAt===null&&n&&n.doc!==t.state.doc){let i=this.menuEl.contains(document.activeElement);this.closeMenu(),i&&t.focus()}let o=t.state,s=o.doc.child(this.blockIndex());this.turn.textContent=`${nn(s).label} \u25BE`;for(let i of this.dock.querySelectorAll("[data-cmd]"))i.setAttribute("aria-pressed",String(lr(o,i.dataset.cmd)));let r=!o.selection.empty&&o.selection instanceof cn&&t.hasFocus();if(this.bubble.hidden=!r,r)for(let i of this.bubble.querySelectorAll("[data-cmd]"))i.setAttribute("aria-pressed",String(lr(o,i.dataset.cmd)));this.grip.classList.toggle("is-on",o.selection instanceof wt),this.inRoving(this.roving)||this.setRoving(this.dockControls()[0]),this.slashQuery(),this.scheduleLayout()}destroy(){this.destroyed=!0,this.frame!==null&&this.win.cancelAnimationFrame(this.frame),this.frame=null,clearTimeout(this.movedTimer),this.drag.destroy(),this.shell.removeEventListener("mousemove",this.onMove),this.shell.removeEventListener("mouseleave",this.onLeave),this.shell.removeEventListener("keydown",this.onKey),this.win.removeEventListener("resize",this.onResize),this.win.removeEventListener("scroll",this.onResize,!0),this.win.visualViewport?.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("scroll",this.onResize),document.removeEventListener("mousedown",this.onDocDown,!0);for(let t of[this.dock,this.plus,this.grip,this.bubble,this.scrim,this.menuEl,this.probe])t?.remove()}};function od({onAiTool:e=null}={}){let t=null;return new dr({key:Ic,view(n){return t=new io(n,e),vr.set(n,t),t},props:{handleKeyDown(n,o){return t?o.key==="/"&&(o.metaKey||o.ctrlKey)&&!o.altKey&&!t.menu?(o.preventDefault(),t.openActions(),!0):t.key(o):!1},handleTextInput(n,o,s,r){if(r!=="/"||!t)return!1;let i=Wo(n,r);i&&(o=n.state.selection.from-1);let c=n.state.doc.resolve(o);if(c.depth!==1||!c.parent.isTextblock||c.parent.type.spec.code||c.parentOffset>0&&!/\s/.test(n.state.doc.textBetween(o-1,o,"",`
|
|
8
|
+
`)))return i;i||n.dispatch(n.state.tr.insertText("/",o,s).setMeta(Le,Tn(n.state,o,s,"/")));let f=Math.min(n.state.doc.resolve(o).index(0),n.state.doc.childCount-1);return t.openMenu("insert",t.plus,o+1,null,n.state.doc.child(f).attrs.id),!0},handleDOMEvents:{keydown(n,o){return sn(o,n)},blur(n){return t&&(t.bubble.hidden=!0),!1}}}})}var{Plugin:$c}=q,ao=new WeakMap,Dc=e=>typeof e.text=="function"?e.text():new Promise((t,n)=>{let o=new FileReader;o.onload=()=>t(o.result),o.onerror=()=>n(o.error),o.readAsText(e)});function an(e,t){let n=e.dom.ownerDocument,o=e.dom.parentElement.querySelector(".page-csv-error");o||(o=n.createElement("div"),o.className="page-csv-error",o.setAttribute("role","alert"),e.dom.parentElement.append(o)),o.textContent=t}function _c(e){let t=0,n=So(e,{maxBytes:Hn,newId:()=>R(t++<e.header.length?"c":"r")});if(!Object.keys(n.cols).length)return null;if(!Object.keys(n.rows).length){let o=Object.fromEntries(Object.keys(n.cols).map(s=>[s,""]));n.rows[R("r")]={pos:V(),cells:o}}return{node:Ft(S,R(),{t:"table",pos:null,cols:n.cols,rows:n.rows}),truncated:n.truncated}}async function Nc({kept:e,total:t}){let n=`This file has ${t} rows. The first ${e} fit in a table.`,o=globalThis.clay?.confirm,s=globalThis.clay?.modal;o||(o=(await import("./c-F3CKJTJS.js")).consent,s=(await import("./c-RM7J7BV2.js")).default);let r=o(n);s&&(s.yes=`Insert first ${e} rows and attach the file`);try{return await r,!0}catch{return!1}}var Lc=(e,t)=>{let n=-1;return e.forEach((o,s,r)=>{n<0&&o.type===S.nodes.table&&o.attrs.id===t&&(n=r)}),n},jc=e=>{let t=!0;return e.descendants(n=>(n.isText&&(t=!1),t)),t};function Bc(e,t,n,o){let s=e.state,r=Lc(s.doc,n);if(r<0)return vt(s,e.dispatch,t,null,o);let i=0;for(let a=0;a<r;a++)i+=s.doc.child(a).nodeSize;let c=s.doc.child(r);if(!jc(c)||o){let a=s.doc.maybeChild(r+1),l=c.attrs.parent??null,u=V(c.attrs.pos,a?.attrs.pos??null),p=t.type.create({...t.attrs,pos:u,parent:l},t.content),m=i+c.nodeSize,g=s.tr.insert(m,p);return o&&g.insert(m+p.nodeSize,o.type.create({...o.attrs,pos:V(u,a?.attrs.pos??null),parent:l},o.content)),g.setSelection(q.TextSelection.create(g.doc,m+3)),e.dispatch(F(g).scrollIntoView()),!0}let f=t.type.create({...t.attrs,id:c.attrs.id,pos:c.attrs.pos,parent:c.attrs.parent},t.content),h=s.tr.replaceWith(i,i+c.nodeSize,f);return h.setSelection(q.TextSelection.create(h.doc,i+3)),e.dispatch(F(h).scrollIntoView()),!0}async function lo(e,t,{upload:n,remove:o=null,table:s=null}={}){try{e.dom.parentElement.querySelector(".page-csv-error")?.remove();let r=ve(await Dc(t)),i=_c(r);if(!i)return an(e,"Couldn't read this CSV: no columns."),!1;let c=null;if(i.truncated){if(!await Nc(i.truncated))return!1;let a=await n?.(t),l=ho(a?.uploads?.[0]?.url);if(!a?.ok||!l)return an(e,"Couldn't attach the original CSV."),!1;c=S.nodes.file.create({id:R(),src:l,name:t.name,size:t.size??null,mime:t.type||"text/csv"})}if(e.isDestroyed)return!1;if(s)return Bc(e,i.node,s,c);let f=o?Or(e.state):null;return o&&!f&&Kc(e,o.block),vt(e.state,e.dispatch,i.node,f,c)}catch(r){return r instanceof wo?an(e,`Couldn't read this CSV: unclosed quote on line ${r.line}.`):an(e,"Couldn't read this CSV."),!1}}function tn(e,t=null,n=null){let o=ao.get(e);return o?(t&&Sr(e,t),o._remove=t?{...t,block:Rc(e.state.doc,t.from)}:null,o._table=n,o.click(),!0):!1}var Rc=(e,t)=>e.child(e.resolve(Math.max(0,Math.min(t,e.content.size))).index(0)).attrs.id;function Kc(e,t){let n=e.state,o=null;return n.doc.forEach((s,r)=>{o===null&&s.attrs.id===t&&(o=r)}),o===null?!1:(e.dispatch(n.tr.setSelection(q.TextSelection.near(n.doc.resolve(o)))),!0)}var Mr=e=>[...e].filter(t=>/\.csv$/i.test(t.name||"")||/^(text\/csv|application\/csv)$/i.test(t.type||""));function hd({upload:e}){return new $c({view(t){let n=t.dom.ownerDocument.createElement("input");return n.type="file",n.accept=".csv,text/csv",n.hidden=!0,n.className="page-csv-input",t.dom.parentElement.append(n),ao.set(t,n),n.addEventListener("change",()=>{let o=n.files?.[0];o&&lo(t,o,{upload:e,remove:n._remove,table:n._table}),n._remove=null,n._table=null,n.value=""}),{destroy(){ao.delete(t),n.remove()}}},props:{handlePaste(t,n){let o=Mr(n.clipboardData?.files||[]);return o.length?(n.preventDefault(),lo(t,o[0],{upload:e}),!0):!1},handleDrop(t,n,o,s){let r=Mr(n.dataTransfer?.files||[]);if(s||!r.length)return!1;n.preventDefault();let i=t.posAtCoords({left:n.clientX,top:n.clientY});return i&&t.dispatch(t.state.tr.setSelection(q.TextSelection.near(t.state.doc.resolve(i.pos)))),lo(t,r[0],{upload:e}),!0}}})}export{ce as a,Pc as b,zc as c,En as d,At as e,De as f,Qc as g,Q as h,Br as i,Zc as j,Re as k,ii as l,$l as m,Nn as n,ze as o,Ss as p,Ye as q,Ms as r,di as s,Vl as t,Hl as u,Ls as v,Ul as w,Ue as x,ut as y,Pn as z,hi as A,As as B,jt as C,zn as D,ql as E,qe as F,ca as G,ya as H,Ne as I,sl as J,rl as K,al as L,ul as M,dl as N,vl as O,Sl as P,ds as Q,Pi as R,Ra as S,Ka as T,Pa as U,za as V,Fa as W,zi as X,Fi as Y,Ya as Z,Va as _,Ha as $,Ua as aa,qa as ba,Ja as ca,Wa as da,Ga as ea,Xa as fa,hd as ga,Gs as ha,Js as ia,pu as ja,sn as ka,Nu as la,Lu as ma,ju as na,nd as oa,Sr as pa,Or as qa,Gn as ra,od as sa};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var n=new WeakMap;function a(e,r){if(!e||e.nodeType!==1)throw new TypeError("clayjs: claim needs an element to own");if(n.has(e))throw new Error(`clayjs: the article already has a ${n.get(e).kind} runtime`);let t={kind:String(r??"runtime"),active:!0};return n.set(e,t),function(){return t.active?(t.active=!1,n.get(e)===t&&n.delete(e),!0):!1}}export{a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as m,b as N,c as E,d as L,f as k,j as v,k as T,l as D,n as w}from"./c-OIBUTDXI.js";import{a as O}from"./c-4JZDZFF6.js";import{b as F,e as g,f as I,g as f}from"./c-VAK7SG37.js";import{a as C,b as c}from"./c-NUHP2XDB.js";var M=new WeakMap,H='a[href], input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [contenteditable], [tabindex]:not([tabindex^="-"])';function U(u,l){let t=[...u.querySelectorAll(H)].filter(r=>r.offsetParent!==null);if(!t.length)return;let d=t.indexOf(document.activeElement);d===-1?(t[0].focus(),l.preventDefault()):l.shiftKey&&d===0?(t[t.length-1].focus(),l.preventDefault()):!l.shiftKey&&d===t.length-1&&(t[0].focus(),l.preventDefault())}var P=`1px solid ${g["line-2"]}`;function B(u,l,t=null,d=[],r=[]){let x=f.dialogCloseHover[0].slice(11),b=["position:absolute","top:-1px","right:-1px","z-index:2","display:grid","place-items:center",l?"height:calc(100% + 1px)":"height:62px","margin:0","padding:0","border:0",...f.dialogClose,...l?[]:[`border-bottom:${P}`],"cursor:pointer","outline:none"],e=v("button",b);if(e.type="button",e.setAttribute("aria-label",u),e.title=u,e.innerHTML=I.dialogClose,!m(t))return k(e.firstElementChild,16),e.addEventListener("pointerenter",()=>c(e,"background",x)),e.addEventListener("pointerleave",()=>c(e,"background",g.face)),e.addEventListener("focus",()=>{c(e,"outline",`2px solid ${g.brass}`),c(e,"outline-offset","-4px")}),e.addEventListener("blur",()=>c(e,"outline","none")),e;let n=["close",...d],s=["icon",...r];L(e,t,n),L(e.firstElementChild,t,s);let o={hover:!1,focus:!1,pressed:!1},a=()=>{let i={hover:o.hover,active:o.pressed,focus:o.focus},p=e.firstElementChild;p.style.cssText="",k(p,16),C(p,E(t,s,i)),T(e,[...b,...o.hover?[`background:${x}`]:[],...o.focus?[`outline:2px solid ${g.brass}`,"outline-offset:-4px"]:[],...N(t,"close",i),...E(t,n,i)])};return e.addEventListener("pointerenter",()=>{o.hover=!0,a()}),e.addEventListener("pointerleave",()=>{o.hover=!1,o.pressed=!1,a()}),e.addEventListener("pointerdown",i=>{i.button!==void 0&&i.button!==0||(o.pressed=!0,a())}),e.addEventListener("pointerup",()=>{o.pressed=!1,a()}),e.addEventListener("focus",()=>{o.focus=!0,a()}),e.addEventListener("blur",()=>{o.focus=!1,o.pressed=!1,a()}),a(),e}function q({zIndex:u="100",width:l="600px",closable:t=!1,titled:d=!1,theme:r=null,surface:x="modal"}={}){let b=m(r),e=b?r.tokens:{},n=e.spacing,s=y=>x==="modal"?[`dialog.${y}`]:[`dialog.${y}`,`${x}.${y}`],o=v("div",["display:block"],{theme:r,parts:s("root")});o.setAttribute("data-clay-modal",""),b&&o.setAttribute("data-clay-ui",x),o.setAttribute("aria-hidden","true"),c(o,"color-scheme",b?r.scheme:O());let a=v("div",["position:fixed","inset:0",`z-index:${u}`,"overflow:auto","display:flex","align-items:flex-start","justify-content:center","padding:min(96px, 10vh) 16px 16px",`background:color-mix(in srgb, ${g.ground} 72%, transparent)`],{theme:r,parts:s("overlay"),role:"overlay"});a.tabIndex=-1;let i=D("form",["position:relative","display:flex","flex-direction:column","margin:0",`width:min(${l}, 100%)`,"max-height:calc(100dvh - min(96px, 10vh) - 16px)",...f.dialogPanel],{theme:r,parts:s("panel")});i.setAttribute("role","dialog"),i.setAttribute("aria-modal","true");let p=null,$=null;d&&(p=v("div",["position:relative","display:block","flex:none",`padding:20px ${t?"68px":"22px"} 16px 22px`,...f.dialogHeader,...e.border?[`border-bottom-color:${e.border}`]:[],...n?[`padding:${n} ${t?`calc(${n} + 46px)`:n} calc(${n} * .7) ${n}`]:[]],{theme:r,parts:s("header")}),$=w("div",["display:block",...f.dialogHeading,"overflow-wrap:anywhere"],void 0,{theme:r,parts:s("title"),role:"heading"}),$.setAttribute("role","heading"),$.setAttribute("aria-level","2"),p.append($),i.append(p));let A=w("div",["display:block","flex:1 1 auto","min-height:0","overflow-y:auto","overflow-x:hidden",`padding:20px ${t&&!d?"84px":"22px"} 20px 22px`,"overflow-wrap:anywhere",`font:14.5px/1.55 ${F}`,...n?[`padding:${n} ${t&&!d?`calc(${n} + 62px)`:n} ${n} ${n}`]:[]],void 0,{theme:r,parts:s("body")}),S=v("div",["display:flex","flex:none","flex-wrap:wrap","justify-content:flex-end","align-items:center",...f.dialogFooter,...e.border?[`border-top-color:${e.border}`]:[],...n?[`padding:calc(${n} * .65) ${n}`,`gap:calc(${n} / 2)`]:[]],{theme:r,parts:[...s("footer"),...s("actions")]});i.append(A,S);let h=t?B("Close",d,r,s("close"),s("closeIcon")):null;return h&&(p||i).append(h),a.append(i),o.append(a),{root:o,overlay:a,panel:i,header:p,heading:$,body:A,footer:S,close:h,theme:r}}export{M as a,U as b,q as c};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import{a as h}from"./c-VFX45IZQ.js";import"./c-2SPVQSHC.js";import"./c-AYVOREBE.js";import"./c-7O6AFR65.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var A=`.clay-upload {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-wrap: wrap;
|
|
4
|
+
align-items: center;
|
|
5
|
+
gap: var(--clay-upload-gap, 8px);
|
|
6
|
+
padding: var(--clay-upload-padding, 8px 10px);
|
|
7
|
+
font-family: var(--clay-upload-font, inherit);
|
|
8
|
+
font-size: var(--clay-upload-font-size, 13px);
|
|
9
|
+
line-height: var(--clay-upload-line-height, 1.4);
|
|
10
|
+
color: var(--clay-upload-ink, #171A1F);
|
|
11
|
+
text-align: left;
|
|
12
|
+
background: var(--clay-upload-bg, transparent);
|
|
13
|
+
border: var(--clay-upload-border-width, 0) solid var(--clay-upload-border, #D8D8DE);
|
|
14
|
+
border-radius: var(--clay-upload-radius, 6px);
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
max-width: 100%;
|
|
17
|
+
}
|
|
18
|
+
.clay-upload *, .clay-upload *::before, .clay-upload *::after { box-sizing: border-box; }
|
|
19
|
+
.clay-upload__name {
|
|
20
|
+
flex: 1 1 8em;
|
|
21
|
+
min-width: 0;
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
text-overflow: ellipsis;
|
|
24
|
+
white-space: nowrap;
|
|
25
|
+
font-weight: var(--clay-upload-name-weight, 500);
|
|
26
|
+
color: var(--clay-upload-ink, #171A1F);
|
|
27
|
+
}
|
|
28
|
+
.clay-upload__progress {
|
|
29
|
+
flex: 2 1 6em;
|
|
30
|
+
width: auto;
|
|
31
|
+
height: var(--clay-upload-progress-height, 6px);
|
|
32
|
+
margin: 0;
|
|
33
|
+
appearance: none;
|
|
34
|
+
-webkit-appearance: none;
|
|
35
|
+
border: 0;
|
|
36
|
+
border-radius: calc(var(--clay-upload-progress-height, 6px) / 2);
|
|
37
|
+
background: var(--clay-upload-track, rgba(23, 26, 31, .14));
|
|
38
|
+
overflow: hidden;
|
|
39
|
+
}
|
|
40
|
+
.clay-upload__progress::-webkit-progress-bar { background: var(--clay-upload-track, rgba(23, 26, 31, .14)); }
|
|
41
|
+
.clay-upload__progress::-webkit-progress-value { background: var(--clay-upload-fill, #2F6FEB); }
|
|
42
|
+
.clay-upload__progress::-moz-progress-bar { background: var(--clay-upload-fill, #2F6FEB); }
|
|
43
|
+
.clay-upload__label {
|
|
44
|
+
flex: 0 1 auto;
|
|
45
|
+
font-variant-numeric: tabular-nums;
|
|
46
|
+
color: var(--clay-upload-muted, #5C6069);
|
|
47
|
+
}
|
|
48
|
+
.clay-upload__status {
|
|
49
|
+
position: absolute;
|
|
50
|
+
width: 1px;
|
|
51
|
+
height: 1px;
|
|
52
|
+
margin: -1px;
|
|
53
|
+
padding: 0;
|
|
54
|
+
overflow: hidden;
|
|
55
|
+
clip-path: inset(50%);
|
|
56
|
+
white-space: nowrap;
|
|
57
|
+
border: 0;
|
|
58
|
+
}
|
|
59
|
+
.clay-upload__actions { display: flex; flex: none; align-items: center; gap: var(--clay-upload-action-gap, 4px); }
|
|
60
|
+
.clay-upload__button {
|
|
61
|
+
min-height: var(--clay-upload-button-height, 28px);
|
|
62
|
+
padding: var(--clay-upload-button-padding, 4px 10px);
|
|
63
|
+
font: inherit;
|
|
64
|
+
font-weight: var(--clay-upload-button-weight, 500);
|
|
65
|
+
color: var(--clay-upload-button-ink, #2F6FEB);
|
|
66
|
+
background: var(--clay-upload-button-bg, transparent);
|
|
67
|
+
border: 1px solid var(--clay-upload-button-border, transparent);
|
|
68
|
+
border-radius: var(--clay-upload-button-radius, 4px);
|
|
69
|
+
cursor: pointer;
|
|
70
|
+
white-space: nowrap;
|
|
71
|
+
}
|
|
72
|
+
.clay-upload__button:hover { background: var(--clay-upload-button-bg-hover, rgba(47, 111, 235, .1)); }
|
|
73
|
+
.clay-upload__button:focus-visible { outline: 2px solid var(--clay-upload-fill, #2F6FEB); outline-offset: 2px; }
|
|
74
|
+
.clay-upload__button[hidden] { display: none; }
|
|
75
|
+
.clay-upload[data-clay-upload-state="failed"] .clay-upload__label { color: var(--clay-upload-failure-ink, #B3261E); }
|
|
76
|
+
@media (pointer: coarse) {
|
|
77
|
+
.clay-upload__button { min-height: var(--clay-upload-button-height, 44px); }
|
|
78
|
+
}
|
|
79
|
+
@media (prefers-reduced-motion: reduce) {
|
|
80
|
+
.clay-upload__progress { transition: none; }
|
|
81
|
+
}
|
|
82
|
+
@media (prefers-color-scheme: dark) {
|
|
83
|
+
.clay-upload { color: var(--clay-upload-ink, #E9E9EC); border-color: var(--clay-upload-border, #3A3D45); }
|
|
84
|
+
.clay-upload__name { color: var(--clay-upload-ink, #E9E9EC); }
|
|
85
|
+
.clay-upload__label { color: var(--clay-upload-muted, #A2A6AE); }
|
|
86
|
+
.clay-upload__progress { background: var(--clay-upload-track, rgba(233, 233, 236, .2)); }
|
|
87
|
+
.clay-upload__progress::-webkit-progress-bar { background: var(--clay-upload-track, rgba(233, 233, 236, .2)); }
|
|
88
|
+
.clay-upload__button { color: var(--clay-upload-button-ink, #8AB4FF); }
|
|
89
|
+
.clay-upload[data-clay-upload-state="failed"] .clay-upload__label { color: var(--clay-upload-failure-ink, #FFB4AB); }
|
|
90
|
+
}
|
|
91
|
+
@media print { .clay-upload { display: none; } }`;function F(){if(document.getElementById("clay-upload-style"))return;let e=document.createElement("style");e.id="clay-upload-style",e.setAttribute("clay","editor-ui"),e.textContent=A,document.head.append(e)}function C({loaded:e,total:r,percent:n}){return typeof n=="number"?n:typeof r=="number"&&r>0?Math.round(e/r*100):null}function S(e,r){if(!e||typeof e.subscribe!="function")throw new TypeError("clay.upload.mount needs an upload task");let n=typeof r=="string"?document.querySelector(r):r;if(!n||n.nodeType!==1)throw new TypeError("clay.upload.mount needs a container");F();let d=e.file?.name||"File",a=document.createElement("div");a.className="clay-upload",a.setAttribute("clay","editor-ui"),a.setAttribute("data-clay-upload-state","uploading"),a.innerHTML='<span class="clay-upload__name"></span><progress class="clay-upload__progress"></progress><span class="clay-upload__label"></span><span class="clay-upload__status" role="status" aria-live="polite" aria-atomic="true"></span><span class="clay-upload__actions"><button type="button" class="clay-upload__button clay-upload__cancel">Cancel</button><button type="button" class="clay-upload__button clay-upload__retry" hidden>Retry</button><button type="button" class="clay-upload__button clay-upload__dismiss">Dismiss</button></span>';let x=a.querySelector(".clay-upload__name"),l=a.querySelector(".clay-upload__progress"),b=a.querySelector(".clay-upload__label"),w=a.querySelector(".clay-upload__status"),g=a.querySelector(".clay-upload__cancel"),u=a.querySelector(".clay-upload__retry"),_=a.querySelector(".clay-upload__dismiss");x.textContent=d,l.setAttribute("aria-label",`Upload progress for ${d}`);let f=null,c=null;function p(o){o!==f&&(f=o,w.textContent=o)}function E(o){let{state:t}=o,s=t==="uploading",i=C(o),v=s&&i!==null&&i>=100;if(a.setAttribute("data-clay-upload-state",t),s)l.hidden=!1,c=null,i===null?(l.removeAttribute("value"),l.removeAttribute("max"),b.textContent="Uploading"):(l.setAttribute("max","100"),l.setAttribute("value",String(i)),b.textContent=v?"Finishing upload":`${i}%`),p(v?`Finishing upload of ${d}`:`Uploading ${d}`);else{let y=o.result?.msg||(t==="succeeded"?"Uploaded":t==="cancelled"?"Upload cancelled":"Upload failed");t==="succeeded"?(l.setAttribute("max","100"),l.setAttribute("value","100")):(l.removeAttribute("value"),l.removeAttribute("max")),l.hidden=t!=="succeeded",b.textContent=y,t==="failed"?(c=y,p(y)):t==="cancelled"?(c=null,p("Upload cancelled")):p(y)}g.hidden=!s,_.hidden=s,u.hidden=!h(o),u.hidden||u.setAttribute("aria-label",c?`Retry ${d}: ${c}`:`Retry ${d}`)}function m(){k(),a.remove()}g.addEventListener("click",()=>{g.hidden||e.cancel()}),u.addEventListener("click",()=>{u.hidden||(u.hidden=!0,e.retry())}),_.addEventListener("click",()=>{_.hidden||m()});let k=e.subscribe(E);return n.append(a),{unmount:m}}var q=S;export{q as default,S as mount};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var O=/^(0|[1-9]\d*)$/,E=new Set(["set","del","add"]),s=e=>e!==null&&typeof e=="object",y=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);function f(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function j(e){if(Array.isArray(e)){for(let t of e)T(t);return e.slice()}if(typeof e!="string")throw new TypeError("clay.live: a path is a dotted string or an array of keys");return e===""?[]:e.split(".").map(t=>O.test(t)?Number(t):t)}function T(e){if(typeof e!="string"&&!(Number.isInteger(e)&&e>=0))throw new TypeError(`clay.live: path segment ${String(e)} is not a string or a non-negative integer`)}function a(e,t=new Set){if(e===null||typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number"){if(!Number.isFinite(e))throw new TypeError("clay.live: numbers must be finite");return e}if(typeof e!="object")throw new TypeError(`clay.live: a ${typeof e} is not JSON`);if(t.has(e))throw new TypeError("clay.live: the value contains a cycle");t.add(e);let n;if(Array.isArray(e)){n=[];for(let r=0;r<e.length;r++){if(!(r in e))throw new TypeError("clay.live: sparse arrays are not JSON");n.push(a(e[r],t))}}else{let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw new TypeError("clay.live: only plain objects and arrays are JSON");n={};for(let i of Object.keys(e))f(n,i,a(e[i],t))}return t.delete(e),n}function C(e){if(!s(e)||!E.has(e.op))throw new TypeError('clay.live: an op is { op: "set" | "del" | "add", path, ... }');let t=j(e.path);if(e.op==="set"){if(e.value===void 0)throw new TypeError("clay.live: set needs a value; use delete to remove");let n=a(e.value);if(t.length===0&&!s(n))throw new TypeError("clay.live: the whole value must be an object or an array");return{op:"set",path:t,value:n}}if(t.length===0)throw new TypeError(`clay.live: ${e.op} needs a path`);if(e.op==="add"){if(typeof e.n!="number"||!Number.isFinite(e.n))throw new TypeError("clay.live: add needs a finite number");return{op:"add",path:t,n:e.n}}return{op:"del",path:t}}function p(e,t){return typeof t=="number"?t:O.test(t)?Number(t):-1}function d(e,t){if(Array.isArray(e)){let r=p(e,t);return r>=0&&r<e.length?e[r]:void 0}let n=String(t);return y(e,n)?e[n]:void 0}function x(e,t){if(t.path.length===0){if(t.op==="set"&&(!s(t.value)||Array.isArray(t.value)!==Array.isArray(e)))throw new TypeError(`clay.live: the whole value must stay ${Array.isArray(e)?"a list":"an object"}`);return}let n=e;for(let r=0;r<t.path.length;r++){let i=t.path[r],o=r===t.path.length-1;if(!s(n)){if(t.op==="del")return;for(let l=r;l<t.path.length;l++)if(typeof t.path[l]=="number"&&t.path[l]!==0)throw new RangeError(`clay.live: index ${t.path[l]} would leave holes in a new list at ${t.path.slice(0,l).join(".")||"the root"}`);return}if(Array.isArray(n)){let l=p(n,i);if(l<0)throw new TypeError(`clay.live: "${i}" is not an index of the list at ${t.path.slice(0,r).join(".")||"the root"}`);let u=o&&t.op!=="del"?n.length:n.length-1;if(l>u&&!(o&&t.op==="del"))throw new RangeError(`clay.live: index ${l} is past the end of the list at ${t.path.slice(0,r).join(".")||"the root"}`)}if(o)return;n=d(n,i)}}function A(e,t,n){Array.isArray(e)?e[p(e,t)]=n:f(e,String(t),n)}function S(e,t){let{path:n}=t;if(n.length===0)return a(t.value);let r=e;for(let o=0;o<n.length-1;o++){let l=d(r,n[o]);if(!s(l)){if(t.op==="del")return e;l=typeof n[o+1]=="number"?[]:{},A(r,n[o],l)}r=l}let i=n[n.length-1];if(t.op==="set")A(r,i,a(t.value));else if(t.op==="add"){let o=d(r,i);A(r,i,(typeof o=="number"&&Number.isFinite(o)?o:0)+t.n)}else if(Array.isArray(r)){let o=p(r,i);o>=0&&o<r.length&&r.splice(o,1)}else delete r[String(i)];return e}function F(e,t){let n=e;for(let r of t)x(n,r),n=S(n,r);return n}function M(e,t){x(e,t);let{path:n}=t;if(n.length===0)return{root:a(t.value),at:null,key:null,kind:"put",old:e,path:[],size:0,keys:null,empty:!1};let r=e,i=n.length-1;for(let c=0;c<n.length-1;c++){let k=d(r,n[c]);if(!s(k)){if(t.op==="del")return null;i=c;break}r=k}let o=Array.isArray(r),l=o?p(r,n[i]):String(n[i]),u=o?r.length:0,g=o?l<u:y(r,l);if(t.op==="del"&&!g)return null;let w=t.op==="del"?"remove":g?"put":"add",m={root:e,at:r,key:l,kind:w,old:g?r[l]:void 0,path:n.slice(0,i+1),size:u,keys:null,empty:!1};return!o&&w==="remove"&&(m.keys=Object.keys(r)),!o&&w==="add"&&(m.empty=$(r)),S(e,t),m}function $(e){for(let t in e)if(y(e,t))return!1;return!0}function D(e){let{at:t,key:n,kind:r,old:i}=e;if(t===null)return i;if(Array.isArray(t))r==="put"?t[n]=i:r==="add"?t.length=e.size:t.splice(n,0,i);else if(r==="put")f(t,n,i);else if(r==="add")delete t[n];else if(e.keys[e.keys.length-1]===n)f(t,n,i);else{let o=e.keys.map(l=>l===n?i:t[l]);for(let l of e.keys)l!==n&&delete t[l];e.keys.forEach((l,u)=>f(t,l,o[u]))}return e.root}var N=(e,t)=>e.length===t.length&&e.every((n,r)=>String(n)===String(t[r]));function I(e){let t=[];for(let n of e){let r=t[t.length-1];if(!r||r.op==="del"||!N(r.path,n.path)){t.push(n);continue}if(n.op==="del"&&n.path.length>1)t.push(n);else if(n.op==="set"||n.op==="del")t[t.length-1]=n;else if(r.op==="add")t[t.length-1]={op:"add",path:r.path,n:r.n+n.n};else{let i=typeof r.value=="number"?r.value:0;t[t.length-1]={op:"set",path:r.path,value:i+n.n}}}return t}function R(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(String(e[r])!==String(t[r]))return!1;return!0}function P(e,t){if(Array.isArray(e)){for(let i=0;i<t.length;i++)e[i]=b(i<e.length?e[i]:void 0,t[i]);return e.length=t.length,e}let n=Object.keys(t),r=n.map(i=>b(y(e,i)?e[i]:void 0,t[i]));for(let i of Object.keys(e))delete e[i];return n.forEach((i,o)=>f(e,i,r[o])),e}function b(e,t){return s(e)&&s(t)&&Array.isArray(e)===Array.isArray(t)?P(e,t):t}function h(e){return JSON.stringify(e).replace(/</g,"\\u003c")}var J=/^([A-Za-z0-9-]{1,64}):(0|[1-9]\d*):([0-9a-f]{8})$/;function z(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t.toString(16).padStart(8,"0")}function q(e,t,n){return`${e}:${t}:${z(n)}`}function H(e){let t=typeof e=="string"?J.exec(e):null;return t?{epoch:t[1],seq:Number(t[2]),hash:t[3]}:null}function v(e,t,n=[]){if(!s(e)||!s(t)||Array.isArray(e)!==Array.isArray(t))return[{op:"set",path:n,value:a(t)}];if(Array.isArray(e)){if(e.length!==t.length)return[{op:"set",path:n,value:a(t)}];let i=[];for(let o=0;o<t.length;o++)h(e[o])!==h(t[o])&&i.push(...v(e[o],t[o],[...n,o]));return i}let r=[];for(let i of Object.keys(e))y(t,i)||r.push({op:"del",path:[...n,i]});for(let i of Object.keys(t))y(e,i)?h(e[i])!==h(t[i])&&r.push(...v(e[i],t[i],[...n,i])):r.push({op:"set",path:[...n,i],value:a(t[i])});return r}export{a,C as b,x as c,S as d,F as e,M as f,D as g,I as h,R as i,P as j,h as k,z as l,q as m,H as n,v as o};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{e as c,f as s}from"./c-QIX5BJYN.js";import{i as g,k as u}from"./c-35NBGMZB.js";import{i as l}from"./c-DCFSEJZG.js";var p={debug:!1};function t(...n){p.debug&&console.log("[save-freeze]",...n)}var f=new WeakMap;function m(n,o){f=new WeakMap;let e=n.querySelectorAll(l);t("freezing clone:",e.length);for(let r of e){let a=o.original(r);if(!a)continue;let i=c(a);i!==void 0&&(f.set(r,i),r.innerHTML!==i&&(t("restoring original"),r.innerHTML=i))}}function d(n){for(let o of n.querySelectorAll(l)){let e=f.get(o);e!==void 0&&o.innerHTML!==e&&(t("re-restoring original after prepare-phase change"),o.innerHTML=e)}}function E(){t("init"),s(),g(m),u(d)}E();var h=p;export{h as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as _,d as v}from"./c-BWFVSBDF.js";import{b as c}from"./c-RVMWGXEJ.js";import{b as u,c as s}from"./c-NUHP2XDB.js";import{e as b}from"./c-AYVOREBE.js";import"./c-7O6AFR65.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var d="#FFFCF6",l=["all:initial","color-scheme:inherit","direction:ltr","unicode-bidi:isolate"],y=18,h=3,p=null,f=null;function C(){return f??=Promise.all([import("./c-6HMB24EV.js"),import("./c-ZE46QDIH.js")]).then(([i,e])=>p={RUNTIME_ONLY:i.RUNTIME_ONLY,CHIP_FONT:`600 11px/16px ${e.FONT_MONO}`}).catch(i=>{throw f=null,i}),f}var $=()=>C().then(()=>!0,()=>!1);function a(i){return i.setAttribute("clay",p.RUNTIME_ONLY),i}function A(i){let e=i&&Array.isArray(i.people)?i.people:[],o=[];for(let t of e){if(!t||t.you===!0||typeof t.id!="string"||!t.id||typeof t.editing!="string"||!_.test(t.editing))continue;let n=typeof t.name=="string"&&t.name.trim()?t.name.trim():"Someone";o.push({id:t.id,name:n,path:t.editing})}return o}var m=class{constructor(){this.editors=[],this.root=null,this._gate=null,this._frame=0,this._following=!1,this._onMove=()=>this.schedule()}supported(){return this._gate||(this._gate=b("presence").then(e=>e===!0,()=>!1)),this._gate}async update(e){this.editors=A(e),await this.supported()&&await this.render()}clear(){this.editors=[],this.follow(!1),this._frame&&cancelAnimationFrame(this._frame),this._frame=0,this.root&&this.root.remove(),this.root=null}schedule(){this._frame||(this._frame=requestAnimationFrame(()=>{this._frame=0,this.render()}))}render(){return p?(this.paint(),Promise.resolve()):$().then(e=>{e&&this.paint()})}paint(){let e=new Map;for(let t of this.editors){let n=v(t.path);n&&(e.has(n)||e.set(n,[]),e.get(n).push(t))}let o=[];for(let[t,n]of e){let r=this.box(t,n);r&&o.push(r)}if(!o.length){this.root&&(this.root.textContent="",u(this.root,"display","none")),this.follow(this.editors.length>0);return}this.build()&&(this.root.textContent="",this.root.append(...o),u(this.root,"display","block"),this.follow(!0))}box(e,o){let t=e.getBoundingClientRect();if(!(t.width||t.height))return null;let n=c(o[0].id),r=a(s("div",[...l,"position:fixed","box-sizing:border-box","pointer-events:none",`top:${Math.round(t.top-h)}px`,`left:${Math.round(t.left-h)}px`,`width:${Math.round(t.width+h*2)}px`,`height:${Math.round(t.height+h*2)}px`,`border:2px solid ${n}`,`box-shadow:0 0 0 1px ${d}, inset 0 0 0 1px ${d}`]));r.setAttribute("data-clay-editing-marker","");let M=t.top-h>=y+2,x=a(s("div",[...l,"position:absolute","left:-2px",M?"bottom:100%":"top:100%","display:flex","gap:2px","pointer-events:none"]));for(let g of o){let w=a(s("span",[...l,"box-sizing:border-box",`height:${y}px`,"padding:1px 6px",`font:${p.CHIP_FONT}`,"letter-spacing:.02em","white-space:nowrap","max-width:180px","overflow:hidden","text-overflow:ellipsis",`background-color:${c(g.id)}`,`color:${d}`,`box-shadow:0 0 0 1px ${d}`],g.name));w.setAttribute("data-clay-editing-chip",""),x.appendChild(w)}return r.appendChild(x),r}build(){return this.root&&this.root.isConnected?!0:typeof document>"u"||!document.body?!1:(this.root=a(s("div",[...l,"position:fixed","top:0","left:0","width:0","height:0","overflow:visible","z-index:2147482999","pointer-events:none","display:none"])),this.root.setAttribute("data-clay-editing",""),document.body.appendChild(this.root),!0)}follow(e){if(typeof window>"u"||!!e===this._following)return;this._following=!!e;let o=e?"addEventListener":"removeEventListener";window[o]("scroll",this._onMove,{capture:!0,passive:!0}),window[o]("resize",this._onMove,{passive:!0}),document[o]("input",this._onMove),document[o]("clay:sync-applied",this._onMove)}},N=new m;var O=N;export{m as EditingMarker,O as default,N as editingMarker};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.freeze(["data","data-state","data-writer"]),n=new Set,t=null;function o(e,...r){for(let a of n)try{a[e]?.(...r)}catch(c){console.error("clay.live: stream handler failed:",c)}}function i({clientId:e,lane:r}){t={clientId:e,lane:r},o("open",t)}function s(){t&&(t=null,o("close"))}function u(e,r){l.includes(e)&&o("event",e,r)}function f(e){if(n.add(e),t)try{e.open?.(t)}catch(r){console.error("clay.live: stream handler failed:",r)}return()=>n.delete(e)}export{l as a,i as b,s as c,u as d,f as e};
|