@novaprose/core 0.7.0 → 0.8.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 +15 -2
- package/dist/a11y.cjs +314 -0
- package/dist/a11y.cjs.map +1 -0
- package/dist/a11y.d.cts +51 -0
- package/dist/a11y.d.ts +51 -0
- package/dist/a11y.js +11 -0
- package/dist/a11y.js.map +1 -0
- package/dist/a11ychecker-7KQU7DD3.js +449 -0
- package/dist/a11ychecker-7KQU7DD3.js.map +1 -0
- package/dist/accordion-ui-FGN3I5UF.js +201 -0
- package/dist/accordion-ui-FGN3I5UF.js.map +1 -0
- package/dist/advcode-65Z2ELUB.js +51 -0
- package/dist/advcode-65Z2ELUB.js.map +1 -0
- package/dist/advcode-editor-WIOCY552.js +257 -0
- package/dist/advcode-editor-WIOCY552.js.map +1 -0
- package/dist/{advlist-5FNKPLUX.js → advlist-CEHE6YXS.js} +10 -7
- package/dist/advlist-CEHE6YXS.js.map +1 -0
- package/dist/advtable-ui-5CBOPTHW.js +364 -0
- package/dist/advtable-ui-5CBOPTHW.js.map +1 -0
- package/dist/ai-IRQYZHRK.js +1485 -0
- package/dist/ai-IRQYZHRK.js.map +1 -0
- package/dist/anchor-ui-NWIIRKGY.js +81 -0
- package/dist/anchor-ui-NWIIRKGY.js.map +1 -0
- package/dist/autocorrect-6GFLVDPC.js +851 -0
- package/dist/autocorrect-6GFLVDPC.js.map +1 -0
- package/dist/{autolink-45LTODWB.js → autolink-N427KVQO.js} +11 -8
- package/dist/autolink-N427KVQO.js.map +1 -0
- package/dist/{autoresize-UB3GOA6D.js → autoresize-YRZAVCNO.js} +2 -2
- package/dist/autoresize-YRZAVCNO.js.map +1 -0
- package/dist/{autosave-GMWJ5BPE.js → autosave-L7OZ3KLK.js} +7 -7
- package/dist/autosave-L7OZ3KLK.js.map +1 -0
- package/dist/casechange-5G6RAJ7K.js +201 -0
- package/dist/casechange-5G6RAJ7K.js.map +1 -0
- package/dist/{charmap-2GC7LF7G.js → charmap-5CBBDWOP.js} +7 -7
- package/dist/charmap-5CBBDWOP.js.map +1 -0
- package/dist/checklist-HM4VXZKY.js +189 -0
- package/dist/checklist-HM4VXZKY.js.map +1 -0
- package/dist/chunk-23ZLVT5D.js +163 -0
- package/dist/chunk-23ZLVT5D.js.map +1 -0
- package/dist/{chunk-ND2CWNVG.js → chunk-3BOK3S3T.js} +2 -27
- package/dist/chunk-3BOK3S3T.js.map +1 -0
- package/dist/chunk-4I4AYH2K.js +101 -0
- package/dist/chunk-4I4AYH2K.js.map +1 -0
- package/dist/{chunk-PVFKXRID.js → chunk-4VPDY3LF.js} +1 -1
- package/dist/chunk-4VPDY3LF.js.map +1 -0
- package/dist/chunk-53AY5NAF.js +214 -0
- package/dist/chunk-53AY5NAF.js.map +1 -0
- package/dist/chunk-5VCESSQB.js +137 -0
- package/dist/chunk-5VCESSQB.js.map +1 -0
- package/dist/chunk-66INZHZ2.js +79 -0
- package/dist/chunk-66INZHZ2.js.map +1 -0
- package/dist/chunk-6LQM7G4V.js +159 -0
- package/dist/chunk-6LQM7G4V.js.map +1 -0
- package/dist/chunk-6YSQGFV7.js +893 -0
- package/dist/chunk-6YSQGFV7.js.map +1 -0
- package/dist/{chunk-T3GY6IVK.js → chunk-AC3YCAX4.js} +71 -9
- package/dist/chunk-AC3YCAX4.js.map +1 -0
- package/dist/{chunk-5AW2HHG6.js → chunk-ADRPQLZ2.js} +47 -3
- package/dist/chunk-ADRPQLZ2.js.map +1 -0
- package/dist/chunk-ANE5ASXG.js +26 -0
- package/dist/chunk-ANE5ASXG.js.map +1 -0
- package/dist/{chunk-Z3ELZ77W.js → chunk-AP2PJFLB.js} +5 -2
- package/dist/chunk-AP2PJFLB.js.map +1 -0
- package/dist/chunk-AQV6FIKK.js +259 -0
- package/dist/chunk-AQV6FIKK.js.map +1 -0
- package/dist/chunk-AUQSATWL.js +322 -0
- package/dist/chunk-AUQSATWL.js.map +1 -0
- package/dist/chunk-C326LHHU.js +143 -0
- package/dist/chunk-C326LHHU.js.map +1 -0
- package/dist/{chunk-R2UMUCVI.js → chunk-DEYYVZ7O.js} +50 -8
- package/dist/chunk-DEYYVZ7O.js.map +1 -0
- package/dist/chunk-EOJ5XHKA.js +160 -0
- package/dist/chunk-EOJ5XHKA.js.map +1 -0
- package/dist/chunk-EXX2S352.js +3642 -0
- package/dist/chunk-EXX2S352.js.map +1 -0
- package/dist/chunk-FTEA6L2Q.js +47 -0
- package/dist/chunk-FTEA6L2Q.js.map +1 -0
- package/dist/chunk-G74HNSB6.js +9 -0
- package/dist/chunk-G74HNSB6.js.map +1 -0
- package/dist/{chunk-KWXFL4WS.js → chunk-GHVB6SV4.js} +8 -5
- package/dist/chunk-GHVB6SV4.js.map +1 -0
- package/dist/chunk-GTLE2HEW.js +108 -0
- package/dist/chunk-GTLE2HEW.js.map +1 -0
- package/dist/chunk-GXXXLPDQ.js +67 -0
- package/dist/chunk-GXXXLPDQ.js.map +1 -0
- package/dist/chunk-HC6RMBAD.js +163 -0
- package/dist/chunk-HC6RMBAD.js.map +1 -0
- package/dist/chunk-HNEAVVBC.js +98 -0
- package/dist/chunk-HNEAVVBC.js.map +1 -0
- package/dist/chunk-I7Y4KSM2.js +165 -0
- package/dist/chunk-I7Y4KSM2.js.map +1 -0
- package/dist/chunk-IG2BL4ON.js +127 -0
- package/dist/chunk-IG2BL4ON.js.map +1 -0
- package/dist/{chunk-KPE3QRPB.js → chunk-J6W2CDRF.js} +16 -315
- package/dist/chunk-J6W2CDRF.js.map +1 -0
- package/dist/chunk-LVEQBNLX.js +207 -0
- package/dist/chunk-LVEQBNLX.js.map +1 -0
- package/dist/chunk-MZGNOHSY.js +176 -0
- package/dist/chunk-MZGNOHSY.js.map +1 -0
- package/dist/chunk-N32H37AJ.js +373 -0
- package/dist/chunk-N32H37AJ.js.map +1 -0
- package/dist/chunk-NTGEKGXU.js +263 -0
- package/dist/chunk-NTGEKGXU.js.map +1 -0
- package/dist/chunk-OFHGXYG3.js +140 -0
- package/dist/chunk-OFHGXYG3.js.map +1 -0
- package/dist/chunk-OOVNE6MB.js +28 -0
- package/dist/chunk-OOVNE6MB.js.map +1 -0
- package/dist/chunk-OQMMHWMZ.js +7 -0
- package/dist/chunk-OQMMHWMZ.js.map +1 -0
- package/dist/chunk-P2UU2NLT.js +1149 -0
- package/dist/chunk-P2UU2NLT.js.map +1 -0
- package/dist/{chunk-JPJVTB45.js → chunk-QU3KXMYT.js} +8 -2
- package/dist/chunk-QU3KXMYT.js.map +1 -0
- package/dist/chunk-S2XZRKHA.js +29 -0
- package/dist/chunk-S2XZRKHA.js.map +1 -0
- package/dist/chunk-SCIRO4XK.js +144 -0
- package/dist/chunk-SCIRO4XK.js.map +1 -0
- package/dist/chunk-T3IRLTKK.js +158 -0
- package/dist/chunk-T3IRLTKK.js.map +1 -0
- package/dist/chunk-TABIUD2L.js +66 -0
- package/dist/chunk-TABIUD2L.js.map +1 -0
- package/dist/{chunk-FCMZ7TUQ.js → chunk-TAM2FHKG.js} +172 -43
- package/dist/chunk-TAM2FHKG.js.map +1 -0
- package/dist/chunk-UTMS2P2K.js +288 -0
- package/dist/chunk-UTMS2P2K.js.map +1 -0
- package/dist/{chunk-HPLT3XRZ.js → chunk-V7WUHUHM.js} +13 -1
- package/dist/chunk-V7WUHUHM.js.map +1 -0
- package/dist/{table-SSNABG5W.js → chunk-VK6YF2AA.js} +119 -61
- package/dist/chunk-VK6YF2AA.js.map +1 -0
- package/dist/chunk-WAOU5NGN.js +430 -0
- package/dist/chunk-WAOU5NGN.js.map +1 -0
- package/dist/chunk-XIH4SCO6.js +112 -0
- package/dist/chunk-XIH4SCO6.js.map +1 -0
- package/dist/chunk-XR7CY4NI.js +11 -0
- package/dist/chunk-XR7CY4NI.js.map +1 -0
- package/dist/chunk-YDF55N6Z.js +164 -0
- package/dist/chunk-YDF55N6Z.js.map +1 -0
- package/dist/chunk-YDPZCVXS.js +923 -0
- package/dist/chunk-YDPZCVXS.js.map +1 -0
- package/dist/chunk-YG5V7POU.js +137 -0
- package/dist/chunk-YG5V7POU.js.map +1 -0
- package/dist/chunk-YVSUR7E5.js +151 -0
- package/dist/chunk-YVSUR7E5.js.map +1 -0
- package/dist/codesample-GHWIC7PT.js +546 -0
- package/dist/codesample-GHWIC7PT.js.map +1 -0
- package/dist/{comments-panel-HXMWSRAW.js → comments-panel-SOLBZ46Q.js} +9 -5
- package/dist/comments-panel-SOLBZ46Q.js.map +1 -0
- package/dist/{directionality-5JLWQGP2.js → directionality-EGQKGDZA.js} +13 -10
- package/dist/directionality-EGQKGDZA.js.map +1 -0
- package/dist/document-0ft41E6d.d.ts +39 -0
- package/dist/document-IQqDDT4v.d.cts +39 -0
- package/dist/docx.cjs +23518 -0
- package/dist/docx.cjs.map +1 -0
- package/dist/docx.d.cts +83 -0
- package/dist/docx.d.ts +83 -0
- package/dist/docx.js +1821 -0
- package/dist/docx.js.map +1 -0
- package/dist/draghandle-U6CYZHPA.js +389 -0
- package/dist/draghandle-U6CYZHPA.js.map +1 -0
- package/dist/editimage-5EWPSM22.js +683 -0
- package/dist/editimage-5EWPSM22.js.map +1 -0
- package/dist/editor-BCMxe1M4.d.cts +2888 -0
- package/dist/editor-Dmtwjw2u.d.ts +2888 -0
- package/dist/email-ELNMEQ6E.js +177 -0
- package/dist/email-ELNMEQ6E.js.map +1 -0
- package/dist/email.cjs +588 -0
- package/dist/email.cjs.map +1 -0
- package/dist/email.d.cts +7 -0
- package/dist/email.d.ts +7 -0
- package/dist/email.js +21 -0
- package/dist/email.js.map +1 -0
- package/dist/{emoticons-ZD6ZRIWG.js → emoticons-EGHNZKSA.js} +7 -7
- package/dist/emoticons-EGHNZKSA.js.map +1 -0
- package/dist/exportpdf-4P7X3NY2.js +91 -0
- package/dist/exportpdf-4P7X3NY2.js.map +1 -0
- package/dist/exportword-JFJ3KTYZ.js +16 -0
- package/dist/exportword-JFJ3KTYZ.js.map +1 -0
- package/dist/footnotes-ui-FV6QRGDA.js +449 -0
- package/dist/footnotes-ui-FV6QRGDA.js.map +1 -0
- package/dist/form-dialog-SNWFPM2K.js +379 -0
- package/dist/form-dialog-SNWFPM2K.js.map +1 -0
- package/dist/formatpainter-IEXX27OJ.js +209 -0
- package/dist/formatpainter-IEXX27OJ.js.map +1 -0
- package/dist/fullpagehtml-ui-RE4C2NO5.js +220 -0
- package/dist/fullpagehtml-ui-RE4C2NO5.js.map +1 -0
- package/dist/html-rules-api-BLDDW9MO.d.cts +42 -0
- package/dist/html-rules-api-BLDDW9MO.d.ts +42 -0
- package/dist/html-rules.cjs +19 -17
- package/dist/html-rules.cjs.map +1 -1
- package/dist/html-rules.d.cts +37 -35
- package/dist/html-rules.d.ts +37 -35
- package/dist/html-rules.js +24 -20
- package/dist/html-rules.js.map +1 -1
- package/dist/i18n/de.cjs +346 -0
- package/dist/i18n/de.cjs.map +1 -1
- package/dist/i18n/de.d.cts +1 -1
- package/dist/i18n/de.d.ts +1 -1
- package/dist/i18n/de.js +346 -0
- package/dist/i18n/de.js.map +1 -1
- package/dist/i18n/es.cjs +346 -0
- package/dist/i18n/es.cjs.map +1 -1
- package/dist/i18n/es.d.cts +1 -1
- package/dist/i18n/es.d.ts +1 -1
- package/dist/i18n/es.js +346 -0
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/fr.cjs +346 -0
- package/dist/i18n/fr.cjs.map +1 -1
- package/dist/i18n/fr.d.cts +1 -1
- package/dist/i18n/fr.d.ts +1 -1
- package/dist/i18n/fr.js +346 -0
- package/dist/i18n/fr.js.map +1 -1
- package/dist/i18n/it.cjs +346 -0
- package/dist/i18n/it.cjs.map +1 -1
- package/dist/i18n/it.d.cts +1 -1
- package/dist/i18n/it.d.ts +1 -1
- package/dist/i18n/it.js +346 -0
- package/dist/i18n/it.js.map +1 -1
- package/dist/i18n/pt-BR.cjs +346 -0
- package/dist/i18n/pt-BR.cjs.map +1 -1
- package/dist/i18n/pt-BR.d.cts +1 -1
- package/dist/i18n/pt-BR.d.ts +1 -1
- package/dist/i18n/pt-BR.js +346 -0
- package/dist/i18n/pt-BR.js.map +1 -1
- package/dist/i18n/ru.cjs +346 -0
- package/dist/i18n/ru.cjs.map +1 -1
- package/dist/i18n/ru.d.cts +3 -3
- package/dist/i18n/ru.d.ts +3 -3
- package/dist/i18n/ru.js +346 -0
- package/dist/i18n/ru.js.map +1 -1
- package/dist/importcss-JLNIRKGH.js +127 -0
- package/dist/importcss-JLNIRKGH.js.map +1 -0
- package/dist/importword-D7Z6RXGQ.js +73 -0
- package/dist/importword-D7Z6RXGQ.js.map +1 -0
- package/dist/{index-C603bU6r.d.ts → index-CZ9yDvmQ.d.cts} +36 -17
- package/dist/{index-C603bU6r.d.cts → index-CZ9yDvmQ.d.ts} +36 -17
- package/dist/index.cjs +28858 -10442
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +138 -64
- package/dist/index.d.ts +138 -64
- package/dist/index.js +199 -1411
- package/dist/index.js.map +1 -1
- package/dist/{insertdatetime-CRO7TJAQ.js → insertdatetime-YW2VHYZH.js} +7 -7
- package/dist/insertdatetime-YW2VHYZH.js.map +1 -0
- package/dist/linkchecker-3S3MCPOS.js +287 -0
- package/dist/linkchecker-3S3MCPOS.js.map +1 -0
- package/dist/markdown-26O3N3T2.js +136 -0
- package/dist/markdown-26O3N3T2.js.map +1 -0
- package/dist/markdown.cjs +94 -11
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +12 -10
- package/dist/markdown.d.ts +12 -10
- package/dist/markdown.js +4 -235
- package/dist/markdown.js.map +1 -1
- package/dist/math-ui-RUTCHTRY.js +157 -0
- package/dist/math-ui-RUTCHTRY.js.map +1 -0
- package/dist/media-ui-36TE3CJD.js +123 -0
- package/dist/media-ui-36TE3CJD.js.map +1 -0
- package/dist/mediaembed-ui-ZNTGZ2SQ.js +207 -0
- package/dist/mediaembed-ui-ZNTGZ2SQ.js.map +1 -0
- package/dist/mentions-ui-O4IPWQT4.js +58 -0
- package/dist/mentions-ui-O4IPWQT4.js.map +1 -0
- package/dist/mergetags-ui-HS3Q2R36.js +73 -0
- package/dist/mergetags-ui-HS3Q2R36.js.map +1 -0
- package/dist/{nonbreaking-66LFZV2W.js → nonbreaking-GYRUH4UO.js} +7 -7
- package/dist/nonbreaking-GYRUH4UO.js.map +1 -0
- package/dist/pagebreak-ui-I4ZPYK3U.js +50 -0
- package/dist/pagebreak-ui-I4ZPYK3U.js.map +1 -0
- package/dist/pageembed-ui-WOY6VWRJ.js +172 -0
- package/dist/pageembed-ui-WOY6VWRJ.js.map +1 -0
- package/dist/pagelayout-ui-Y2IM7FJQ.js +236 -0
- package/dist/pagelayout-ui-Y2IM7FJQ.js.map +1 -0
- package/dist/{paste-office-F3QW4WWO.js → paste-office-3A6KWKCV.js} +82 -2
- package/dist/paste-office-3A6KWKCV.js.map +1 -0
- package/dist/permanentpen-6D5LLKFX.js +206 -0
- package/dist/permanentpen-6D5LLKFX.js.map +1 -0
- package/dist/print-MZMLQIQX.js +178 -0
- package/dist/print-MZMLQIQX.js.map +1 -0
- package/dist/{quickbars-7E2QRS7J.js → quickbars-UZ2Q67TX.js} +20 -12
- package/dist/quickbars-UZ2Q67TX.js.map +1 -0
- package/dist/{revisionhistory-DXE7KU4R.js → revisionhistory-ACRB23HL.js} +42 -153
- package/dist/revisionhistory-ACRB23HL.js.map +1 -0
- package/dist/save-72ZLF6AO.js +120 -0
- package/dist/save-72ZLF6AO.js.map +1 -0
- package/dist/search-bar-HTZQNPD3.js +212 -0
- package/dist/search-bar-HTZQNPD3.js.map +1 -0
- package/dist/spellchecker-DJ7SP5JY.js +474 -0
- package/dist/spellchecker-DJ7SP5JY.js.map +1 -0
- package/dist/suggestions-panel-RJXC4LCM.js +596 -0
- package/dist/suggestions-panel-RJXC4LCM.js.map +1 -0
- package/dist/suggestions-ui-PODMNH7D.js +395 -0
- package/dist/suggestions-ui-PODMNH7D.js.map +1 -0
- package/dist/table-OBHE465Y.js +54 -0
- package/dist/table-OBHE465Y.js.map +1 -0
- package/dist/table-dialogs-UMIIZQYE.js +119 -0
- package/dist/table-dialogs-UMIIZQYE.js.map +1 -0
- package/dist/tableofcontents-ui-U2PYNPX6.js +167 -0
- package/dist/tableofcontents-ui-U2PYNPX6.js.map +1 -0
- package/dist/template-YYC2MGVH.js +278 -0
- package/dist/template-YYC2MGVH.js.map +1 -0
- package/dist/typography-EQUXUXIN.js +399 -0
- package/dist/typography-EQUXUXIN.js.map +1 -0
- package/dist/upload.cjs +160 -0
- package/dist/upload.cjs.map +1 -0
- package/dist/upload.d.cts +72 -0
- package/dist/upload.d.ts +72 -0
- package/dist/upload.js +132 -0
- package/dist/upload.js.map +1 -0
- package/dist/{visualblocks-6DLBXYOA.js → visualblocks-O5QW7ZDT.js} +7 -7
- package/dist/visualblocks-O5QW7ZDT.js.map +1 -0
- package/dist/visualchars-UQFRWQPE.js +134 -0
- package/dist/visualchars-UQFRWQPE.js.map +1 -0
- package/package.json +53 -3
- package/src/style.css +320 -544
- package/dist/advlist-5FNKPLUX.js.map +0 -1
- package/dist/autolink-45LTODWB.js.map +0 -1
- package/dist/autoresize-UB3GOA6D.js.map +0 -1
- package/dist/autosave-GMWJ5BPE.js.map +0 -1
- package/dist/charmap-2GC7LF7G.js.map +0 -1
- package/dist/chunk-5AW2HHG6.js.map +0 -1
- package/dist/chunk-DWZLSZDG.js +0 -5664
- package/dist/chunk-DWZLSZDG.js.map +0 -1
- package/dist/chunk-FCMZ7TUQ.js.map +0 -1
- package/dist/chunk-HPLT3XRZ.js.map +0 -1
- package/dist/chunk-JPJVTB45.js.map +0 -1
- package/dist/chunk-KPE3QRPB.js.map +0 -1
- package/dist/chunk-KWXFL4WS.js.map +0 -1
- package/dist/chunk-ND2CWNVG.js.map +0 -1
- package/dist/chunk-PVFKXRID.js.map +0 -1
- package/dist/chunk-R2UMUCVI.js.map +0 -1
- package/dist/chunk-T3GY6IVK.js.map +0 -1
- package/dist/chunk-Z3ELZ77W.js.map +0 -1
- package/dist/comments-panel-HXMWSRAW.js.map +0 -1
- package/dist/directionality-5JLWQGP2.js.map +0 -1
- package/dist/editor-CXkltf1R.d.ts +0 -1886
- package/dist/editor-CgSBFTke.d.cts +0 -1886
- package/dist/emoticons-ZD6ZRIWG.js.map +0 -1
- package/dist/form-dialog-QH6KAERD.js +0 -180
- package/dist/form-dialog-QH6KAERD.js.map +0 -1
- package/dist/html-rules-api-D3fKQi-R.d.cts +0 -40
- package/dist/html-rules-api-D3fKQi-R.d.ts +0 -40
- package/dist/insertdatetime-CRO7TJAQ.js.map +0 -1
- package/dist/nonbreaking-66LFZV2W.js.map +0 -1
- package/dist/paste-office-F3QW4WWO.js.map +0 -1
- package/dist/quickbars-7E2QRS7J.js.map +0 -1
- package/dist/revisionhistory-DXE7KU4R.js.map +0 -1
- package/dist/table-SSNABG5W.js.map +0 -1
- package/dist/visualblocks-6DLBXYOA.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugins/comments.ts"],"sourcesContent":["import { icons } from '../ui/icons';\nimport type { Mark, Node as PMNode } from 'prosemirror-model';\nimport { Plugin, PluginKey, type EditorState } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport { keymap } from 'prosemirror-keymap';\nimport {\n COMMENT_ID_RE,\n COMMENT_MAX_LENGTH,\n COMMENT_NAME_MAX_LENGTH,\n createCommentStore,\n newCommentId,\n type Comment,\n type CommentAuthor,\n type CommentStore,\n type CommentThread,\n} from '../comments';\nimport type { Editor } from '../editor';\nimport { definePlugin } from '../plugins';\nimport { findMentionUsers, type MentionUser, type MentionsOptions } from './mentions';\nimport { pickLabels } from './shared';\n\n/**\n * The comments plugin: discussions about parts of the text (like comments in Google Docs or Word).\n * `plugins: ['comments']`, options in `pluginOptions.comments` ({@link CommentsOptions}).\n * Buttons (TinyMCE names): `addcomment`, `showcomments`. Ctrl+Alt+M comments on the selection.\n *\n * A mark in the schema, so the plugin is set up right away; the discussion panel loads lazily when opened.\n */\n\nexport interface CommentsOptions {\n /** Who is commenting. Default: \"Guest\". */\n author?: CommentAuthor;\n /** Where threads are stored. Default: in memory, with `threads` and `onChange`. */\n store?: CommentStore;\n /** Previously saved threads (for the default store). */\n threads?: readonly CommentThread[];\n /** The threads changed — save them (for the default store). */\n onChange?: (threads: readonly CommentThread[]) => void;\n /** Whether a comment can be edited and deleted. Default: only by its author. */\n canEdit?: (comment: Comment, author: CommentAuthor) => boolean;\n /**\n * Finding people for \"@\" in comments. Default: `pluginOptions.mentions.fetch` (the mentions plugin).\n */\n mentions?: MentionsOptions['fetch'];\n /** Someone was mentioned in a new comment — send them a notification. */\n onMention?: (event: { threadId: string; comment: Comment; users: CommentAuthor[] }) => void;\n}\n\nexport const LABELS = {\n en: {\n add: 'Add comment',\n show: 'Comments',\n panel: 'Comments',\n guest: 'Guest',\n newComment: 'New comment',\n placeholder: 'Add a comment…',\n replyPlaceholder: 'Reply…',\n comment: 'Comment',\n reply: 'Reply',\n cancel: 'Cancel',\n save: 'Save',\n edit: 'Edit',\n remove: 'Delete',\n resolve: 'Resolve',\n reopen: 'Reopen',\n deleteThread: 'Delete thread',\n close: 'Close comments',\n showResolved: 'Show resolved',\n resolvedBy: 'Resolved by {name}',\n orphan: 'The commented text was deleted',\n empty: 'No comments yet. Select text and press “Add comment” ({shortcut}).',\n people: 'People',\n noPeople: 'No matches',\n edited: 'edited',\n you: 'you',\n count: '{count} comments',\n },\n};\n\nexport type CommentsLabels = typeof LABELS.en;\n\nconst ICON_ADD = icons.commentAdd;\nconst ICON_SHOW = icons.comments;\n\nconst SHORTCUT = 'Mod-Alt-m';\n\ninterface PluginState {\n /** The selection a new comment is being written for (not saved yet, so no mark in the text). */\n pending: { from: number; to: number } | null;\n active: string | null;\n}\n\ntype Meta = Partial<PluginState> & { refresh?: true };\n\nexport const commentsKey = new PluginKey<PluginState>('nova-comments');\n\n/** Controls the editor's comments: one object shared by the plugin and the lazy panel. */\nexport interface CommentsController {\n readonly editor: Editor;\n readonly store: CommentStore;\n readonly author: CommentAuthor;\n readonly labels: CommentsLabels;\n readonly shortcut: string;\n pending(): PluginState['pending'];\n active(): string | null;\n setActive(id: string | null, scroll?: boolean): void;\n /** Start a comment on the selection: highlight it and open the panel with an input. */\n startComment(): boolean;\n cancelPending(): void;\n /** Save a new comment on the pending selection. Returns the thread ID. */\n submitPending(text: string, mentions?: CommentAuthor[]): string | null;\n reply(threadId: string, text: string, mentions?: CommentAuthor[]): void;\n /** Finding people for \"@\" (null when no source is set up and mentions in comments are off). */\n findUsers: ((query: string) => Promise<MentionUser[]>) | null;\n /** Text fragments of a thread (empty when the text was deleted). */\n ranges(id: string): { from: number; to: number }[];\n quote(id: string): string;\n /** Threads in the order of their place in the document. */\n positionOf(id: string): number;\n deleteThread(id: string): void;\n setResolved(id: string, resolved: boolean): void;\n canEdit(comment: Comment): boolean;\n isPanelOpen(): boolean;\n openPanel(): Promise<void>;\n closePanel(): void;\n}\n\nconst controllers = new WeakMap<Editor, CommentsController>();\n\n/** The editor's comments controller (when the comments plugin is active). */\nexport function getComments(editor: Editor): CommentsController | undefined {\n return controllers.get(editor);\n}\n\n/** Every commented fragment: id → ranges. */\nfunction collectRanges(doc: PMNode): Map<string, { from: number; to: number }[]> {\n const result = new Map<string, { from: number; to: number }[]>();\n doc.descendants((node, pos) => {\n if (!node.isInline) return;\n for (const mark of node.marks) {\n if (mark.type.name !== 'comment') continue;\n const id = mark.attrs.id as string;\n const list = result.get(id) ?? [];\n const last = list[list.length - 1];\n // Adjacent text nodes (different formatting) form one continuous fragment.\n if (last && last.to === pos) last.to = pos + node.nodeSize;\n else list.push({ from: pos, to: pos + node.nodeSize });\n result.set(id, list);\n }\n });\n return result;\n}\n\nfunction commentIdsAt(state: EditorState): string[] {\n const { $from, empty } = state.selection;\n const marks: readonly Mark[] = empty\n ? [...($from.nodeBefore?.marks ?? []), ...($from.nodeAfter?.marks ?? [])]\n : ($from.nodeAfter?.marks ?? []);\n return marks.filter((m) => m.type.name === 'comment').map((m) => m.attrs.id as string);\n}\n\nexport default definePlugin({\n name: 'comments',\n toolbar: 'addcomment showcomments',\n marks: {\n comment: {\n attrs: { id: {} },\n // Typing at the edge of a fragment doesn't extend it; different threads may overlap.\n inclusive: false,\n excludes: '',\n parseDOM: [\n {\n tag: 'span[data-comment]',\n getAttrs: (dom) => {\n const id = (dom as HTMLElement).getAttribute('data-comment') ?? '';\n return COMMENT_ID_RE.test(id) ? { id } : false;\n },\n },\n ],\n toDOM: (mark) => [\n 'span',\n { 'data-comment': COMMENT_ID_RE.test(mark.attrs.id as string) ? mark.attrs.id : null },\n 0,\n ],\n },\n },\n\n prosemirrorPlugins: (editor) => {\n // The highlight cache: recomputed only when the document, the threads or the active thread change.\n let cache: { doc: PMNode; threads: unknown; state: PluginState; set: DecorationSet } | null =\n null;\n return [\n keymap({\n [SHORTCUT]: () => getComments(editor)?.startComment() ?? false,\n }),\n new Plugin<PluginState>({\n key: commentsKey,\n state: {\n init: () => ({ pending: null, active: null }),\n apply(tr, value) {\n const meta = tr.getMeta(commentsKey) as Meta | undefined;\n let next = value;\n if (tr.docChanged && next.pending) {\n const from = tr.mapping.map(next.pending.from, 1);\n const to = tr.mapping.map(next.pending.to, -1);\n next = { ...next, pending: from < to ? { from, to } : null };\n }\n if (meta && ('pending' in meta || 'active' in meta)) next = { ...next, ...meta };\n return next;\n },\n },\n props: {\n decorations(state) {\n const controller = getComments(editor);\n const pluginState = commentsKey.getState(state)!;\n const threads = controller?.store.threads();\n if (\n cache &&\n cache.doc === state.doc &&\n cache.threads === threads &&\n cache.state === pluginState\n ) {\n return cache.set;\n }\n const open = new Set((threads ?? []).filter((t) => !t.resolved).map((t) => t.id));\n const decorations: Decoration[] = [];\n for (const [id, ranges] of collectRanges(state.doc)) {\n if (!open.has(id)) continue;\n const className =\n id === pluginState.active ? 'nova-comment is-active' : 'nova-comment';\n for (const { from, to } of ranges) {\n decorations.push(Decoration.inline(from, to, { class: className }));\n }\n }\n if (pluginState.pending) {\n const { from, to } = pluginState.pending;\n decorations.push(\n Decoration.inline(from, to, { class: 'nova-comment is-active is-pending' }),\n );\n }\n const set = DecorationSet.create(state.doc, decorations);\n cache = { doc: state.doc, threads, state: pluginState, set };\n return set;\n },\n },\n view: () => ({\n update(view, prev) {\n // The cursor entered commented text: show its thread.\n // Only on cursor moves (a click, arrows): the panel isn't pushed while typing.\n if (prev.selection.eq(view.state.selection) || prev.doc !== view.state.doc) return;\n const controller = getComments(editor);\n if (!controller || commentsKey.getState(view.state)!.pending) return;\n const open = new Set(\n controller.store\n .threads()\n .filter((t) => !t.resolved)\n .map((t) => t.id),\n );\n const id = commentIdsAt(view.state).find((candidate) => open.has(candidate));\n if (id && (id !== controller.active() || !controller.isPanelOpen())) {\n queueMicrotask(() => {\n controller.setActive(id);\n void controller.openPanel();\n });\n }\n },\n }),\n }),\n ];\n },\n\n setup(editor) {\n const labels = pickLabels(editor, 'comments', LABELS);\n const options = (editor.options.pluginOptions?.comments ?? {}) as CommentsOptions;\n const store = options.store ?? createCommentStore(options.threads ?? [], options.onChange);\n const author: CommentAuthor = {\n id: String(options.author?.id ?? 'guest').slice(0, 128),\n name: String(options.author?.name || labels.guest).slice(0, COMMENT_NAME_MAX_LENGTH),\n };\n const markType = () => editor.schema.marks.comment!;\n const userSource =\n options.mentions ??\n (editor.options.pluginOptions?.mentions as MentionsOptions | undefined)?.fetch;\n /** Mentioned people whose \"@Name\" is still in the text (picked from the list, then erased: no notification). */\n const keepMentions = (text: string, mentions: CommentAuthor[] = []) => {\n const unique = new Map(mentions.map((m) => [m.id, m]));\n return [...unique.values()].filter((m) => text.includes(`@${m.name}`));\n };\n const makeComment = (text: string, mentions?: CommentAuthor[]): Comment => {\n const kept = keepMentions(text, mentions);\n return {\n id: newCommentId(),\n author,\n text,\n createdAt: Date.now(),\n ...(kept.length ? { mentions: kept } : {}),\n };\n };\n const notify = (threadId: string, comment: Comment) => {\n if (comment.mentions?.length) {\n options.onMention?.({ threadId, comment, users: comment.mentions });\n }\n };\n const pluginState = () => commentsKey.getState(editor.view.state)!;\n const dispatchMeta = (meta: Meta) =>\n editor.view.dispatch(editor.view.state.tr.setMeta(commentsKey, meta));\n\n let panel: { el: HTMLElement; render(): void; focusComposer(): void; destroy(): void } | null =\n null;\n let panelOpen = false;\n\n // The panel is the editor's shared sidebar (editor.ui.sidebar): one open at a time, next to the\n // text, under it on a narrow screen. The panel draws its own header with the title and the close button.\n editor.ui.registry.addSidebar('comments', {\n title: labels.panel,\n button: false,\n header: false,\n render: async (container) => {\n const { createCommentsPanel } = await import('./comments-panel');\n panel = createCommentsPanel(controller);\n container.append(panel.el);\n return () => panel?.destroy();\n },\n onShow: () => {\n panelOpen = true;\n // hidden on the panel itself is for compatibility with styles and tests; the sidebar controls visibility.\n if (panel) panel.el.hidden = false;\n editor.root.classList.add('nova-comments-open');\n panel?.render();\n },\n onHide: () => {\n panelOpen = false;\n if (panel) panel.el.hidden = true;\n editor.root.classList.remove('nova-comments-open');\n if (pluginState().pending) dispatchMeta({ pending: null });\n },\n });\n\n const controller: CommentsController = {\n editor,\n store,\n author,\n labels,\n shortcut: SHORTCUT,\n pending: () => pluginState().pending,\n active: () => pluginState().active,\n setActive(id, scroll = false) {\n if (pluginState().active !== id) dispatchMeta({ active: id });\n panel?.render();\n const range = id ? controller.ranges(id)[0] : undefined;\n if (scroll && range) {\n const { node } = editor.view.domAtPos(range.from);\n const el = node instanceof Element ? node : node.parentElement;\n el?.scrollIntoView({ block: 'nearest' });\n }\n },\n startComment() {\n const { selection } = editor.view.state;\n if (selection.empty || !editor.isEditable()) return false;\n dispatchMeta({ pending: { from: selection.from, to: selection.to }, active: null });\n void controller.openPanel().then(() => {\n // The panel may already be open: redraw it so the new comment field appears.\n panel?.render();\n panel?.focusComposer();\n });\n return true;\n },\n cancelPending() {\n dispatchMeta({ pending: null });\n panel?.render();\n editor.focus();\n },\n findUsers: userSource ? (query) => findMentionUsers(userSource, query) : null,\n submitPending(text, mentions) {\n const pending = pluginState().pending;\n const value = text.trim().slice(0, COMMENT_MAX_LENGTH);\n if (!pending || !value) return null;\n const id = newCommentId('t');\n const comment = makeComment(value, mentions);\n store.createThread({\n id,\n createdAt: comment.createdAt,\n comments: [comment],\n resolved: null,\n });\n const { state } = editor.view;\n editor.view.dispatch(\n state.tr\n .addMark(pending.from, pending.to, markType().create({ id }))\n .setMeta(commentsKey, { pending: null, active: id } satisfies Meta)\n // A comment isn't a text edit: Ctrl+Z must not remove it.\n .setMeta('addToHistory', false),\n );\n panel?.render();\n notify(id, comment);\n return id;\n },\n reply(threadId, text, mentions) {\n const value = text.trim().slice(0, COMMENT_MAX_LENGTH);\n if (!value) return;\n const comment = makeComment(value, mentions);\n store.reply(threadId, comment);\n notify(threadId, comment);\n },\n ranges: (id) => collectRanges(editor.view.state.doc).get(id) ?? [],\n quote(id) {\n const { doc } = editor.view.state;\n return controller\n .ranges(id)\n .map(({ from, to }) => doc.textBetween(from, to, ' '))\n .join(' … ');\n },\n positionOf: (id) => controller.ranges(id)[0]?.from ?? Number.MAX_SAFE_INTEGER,\n deleteThread(id) {\n const { state } = editor.view;\n const tr = state.tr;\n for (const { from, to } of controller.ranges(id)) {\n tr.removeMark(from, to, markType().create({ id }));\n }\n if (pluginState().active === id) tr.setMeta(commentsKey, { active: null } satisfies Meta);\n if (tr.docChanged || tr.getMeta(commentsKey)) {\n editor.view.dispatch(tr.setMeta('addToHistory', false));\n }\n store.deleteThread(id);\n },\n setResolved(id, resolved) {\n store.setResolved(id, resolved ? { by: author, at: Date.now() } : null);\n if (resolved && pluginState().active === id) dispatchMeta({ active: null });\n },\n canEdit: (comment) =>\n options.canEdit ? options.canEdit(comment, author) : comment.author.id === author.id,\n isPanelOpen: () => panelOpen,\n openPanel: () => editor.ui.sidebar.show('comments'),\n closePanel() {\n if (!panelOpen) return;\n editor.ui.sidebar.hide({ restoreFocus: false });\n editor.focus();\n },\n };\n controllers.set(editor, controller);\n\n // Thread changes (your own, from the backend, from other participants) redraw the highlight and the panel.\n const unsubscribe = store.subscribe(() => {\n if (editor.view.isDestroyed) return;\n dispatchMeta({ refresh: true });\n panel?.render();\n });\n\n const add = () => controller.startComment();\n const toggle = () =>\n controller.isPanelOpen() ? controller.closePanel() : void controller.openPanel();\n const canAdd = (e: Editor) => e.isEditable() && !e.view.state.selection.empty;\n\n editor.ui.registry.addButton('addcomment', {\n icon: ICON_ADD,\n tooltip: labels.add,\n shortcut: SHORTCUT,\n isEnabled: canAdd,\n onAction: add,\n });\n editor.ui.registry.addToggleButton('showcomments', {\n icon: ICON_SHOW,\n tooltip: labels.show,\n isActive: () => panelOpen,\n onAction: toggle,\n });\n editor.ui.registry.addMenuItem('addcomment', {\n text: labels.add,\n icon: ICON_ADD,\n shortcut: SHORTCUT,\n isEnabled: canAdd,\n onAction: add,\n });\n editor.ui.registry.addMenuItem('showcomments', {\n text: labels.show,\n icon: ICON_SHOW,\n isActive: () => panelOpen,\n onAction: toggle,\n });\n\n return () => {\n unsubscribe();\n // editor.ui.sidebar destroys the panel (the cleanup from render).\n controllers.delete(editor);\n };\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,QAAQ,iBAAmC;AACpD,SAAS,YAAY,qBAAqB;AAC1C,SAAS,cAAc;AA4ChB,IAAM,SAAS;AAAA,EACpB,IAAI;AAAA,IACF,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,kBAAkB;AAAA,IAClB,SAAS;AAAA,IACT,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,cAAc;AAAA,IACd,OAAO;AAAA,IACP,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,KAAK;AAAA,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B,gBAAgB;AAAA,MACjD,MAAM;AAAA,MACN,SAAS,OAAO;AAAA,MAChB,UAAU,MAAM;AAAA,MAChB,UAAU;AAAA,IACZ,CAAC;AACD,WAAO,GAAG,SAAS,YAAY,cAAc;AAAA,MAC3C,MAAM,OAAO;AAAA,MACb,MAAM;AAAA,MACN,UAAU;AAAA,MACV,WAAW;AAAA,MACX,UAAU;AAAA,IACZ,CAAC;AACD,WAAO,GAAG,SAAS,YAAY,gBAAgB;AAAA,MAC7C,MAAM,OAAO;AAAA,MACb,MAAM;AAAA,MACN,UAAU,MAAM;AAAA,MAChB,UAAU;AAAA,IACZ,CAAC;AAED,WAAO,MAAM;AACX,kBAAY;AAEZ,kBAAY,OAAO,MAAM;AAAA,IAC3B;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import {
|
|
2
|
+
imageSize
|
|
3
|
+
} from "./chunk-TAM2FHKG.js";
|
|
4
|
+
import {
|
|
5
|
+
definePlugin
|
|
6
|
+
} from "./chunk-V7WUHUHM.js";
|
|
7
|
+
import {
|
|
8
|
+
h
|
|
9
|
+
} from "./chunk-QU3KXMYT.js";
|
|
10
|
+
|
|
11
|
+
// src/plugins/pageembed.ts
|
|
12
|
+
import { Plugin } from "prosemirror-state";
|
|
13
|
+
var DEFAULT_SANDBOX = "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation";
|
|
14
|
+
var DEFAULT_SIZES = ["21by9", "16by9", "4by3", "1by1"].map((ratio) => ({
|
|
15
|
+
value: `nova-pageembed--${ratio}`
|
|
16
|
+
}));
|
|
17
|
+
var FIXED = { width: 350, height: 260 };
|
|
18
|
+
var CLASS_RE = /^[\w-]{1,60}$/;
|
|
19
|
+
var RATIO_RE = /--(\d{1,3})by(\d{1,3})$/;
|
|
20
|
+
function pageEmbedOptions(context) {
|
|
21
|
+
const raw = context.options.pluginOptions?.pageembed ?? {};
|
|
22
|
+
const sizes = Array.isArray(raw.sizes) ? raw.sizes.filter(
|
|
23
|
+
(size) => !!size && typeof size.value === "string" && CLASS_RE.test(size.value)
|
|
24
|
+
) : DEFAULT_SIZES;
|
|
25
|
+
const sandbox = raw.sandbox === false ? false : typeof raw.sandbox === "string" ? raw.sandbox.split(/\s+/).filter((word) => /^allow-[a-z-]{1,40}$/.test(word)).join(" ") : DEFAULT_SANDBOX;
|
|
26
|
+
return {
|
|
27
|
+
sizes,
|
|
28
|
+
inlineStyles: raw.inlineStyles !== false,
|
|
29
|
+
className: typeof raw.className === "string" && CLASS_RE.test(raw.className) ? raw.className : "nova-pageembed",
|
|
30
|
+
sandbox,
|
|
31
|
+
allowUrl: typeof raw.allowUrl === "function" ? raw.allowUrl : void 0
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function ratioOf(value) {
|
|
35
|
+
const match = RATIO_RE.exec(value);
|
|
36
|
+
if (!match) return null;
|
|
37
|
+
const width = Number(match[1]);
|
|
38
|
+
const height = Number(match[2]);
|
|
39
|
+
return width > 0 && height > 0 ? [width, height] : null;
|
|
40
|
+
}
|
|
41
|
+
function embeddableUrl(url, allowUrl) {
|
|
42
|
+
if (typeof url !== "string") return null;
|
|
43
|
+
const value = url.trim();
|
|
44
|
+
if (value.length > 2e3 || !/^https?:\/\/[^\s/?#]/i.test(value)) return null;
|
|
45
|
+
let parsed;
|
|
46
|
+
try {
|
|
47
|
+
parsed = new URL(value);
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
|
|
52
|
+
if (parsed.username || parsed.password) return null;
|
|
53
|
+
try {
|
|
54
|
+
if (allowUrl && !allowUrl(parsed.href)) return null;
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
function frameTitle(title, src) {
|
|
61
|
+
if (typeof title === "string" && title.trim()) return title.trim().slice(0, 300);
|
|
62
|
+
try {
|
|
63
|
+
return new URL(src).hostname;
|
|
64
|
+
} catch {
|
|
65
|
+
return src;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function sizeOf(value, settings) {
|
|
69
|
+
return typeof value === "string" && settings.sizes.some((size) => size.value === value) ? value : "";
|
|
70
|
+
}
|
|
71
|
+
function sizeFromClasses(classes, settings) {
|
|
72
|
+
const own = classes.find((name) => settings.sizes.some((size) => size.value === name));
|
|
73
|
+
if (own) return own;
|
|
74
|
+
for (const name of classes) {
|
|
75
|
+
const ratio = /^(?:nova|tiny)-pageembed--/.test(name) ? ratioOf(name) : null;
|
|
76
|
+
if (!ratio) continue;
|
|
77
|
+
const same = settings.sizes.find((size) => {
|
|
78
|
+
const other = ratioOf(size.value);
|
|
79
|
+
return !!other && other[0] * ratio[1] === other[1] * ratio[0];
|
|
80
|
+
});
|
|
81
|
+
if (same) return same.value;
|
|
82
|
+
}
|
|
83
|
+
return "";
|
|
84
|
+
}
|
|
85
|
+
function isWrapper(classes, settings) {
|
|
86
|
+
return classes.some(
|
|
87
|
+
(name) => name === settings.className || /^(?:nova|tiny)-pageembed(?:--[\w-]+)?$/.test(name) || settings.sizes.some((size) => size.value === name)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
function frameAttrs(node, src, settings) {
|
|
91
|
+
return {
|
|
92
|
+
src,
|
|
93
|
+
title: frameTitle(node.attrs.title, src),
|
|
94
|
+
sandbox: settings.sandbox === false ? null : settings.sandbox,
|
|
95
|
+
allow: "fullscreen",
|
|
96
|
+
allowfullscreen: "",
|
|
97
|
+
loading: "lazy",
|
|
98
|
+
referrerpolicy: "strict-origin-when-cross-origin",
|
|
99
|
+
frameborder: node.attrs.border === true ? "1" : "0",
|
|
100
|
+
scrolling: node.attrs.scrolling === false ? "no" : null
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function buildNodes(context) {
|
|
104
|
+
const settings = pageEmbedOptions(context);
|
|
105
|
+
return {
|
|
106
|
+
pageembed: {
|
|
107
|
+
group: "block",
|
|
108
|
+
atom: true,
|
|
109
|
+
selectable: true,
|
|
110
|
+
draggable: true,
|
|
111
|
+
attrs: {
|
|
112
|
+
src: { default: "" },
|
|
113
|
+
size: { default: "" },
|
|
114
|
+
width: { default: FIXED.width },
|
|
115
|
+
height: { default: FIXED.height },
|
|
116
|
+
title: { default: "" },
|
|
117
|
+
border: { default: false },
|
|
118
|
+
scrolling: { default: true }
|
|
119
|
+
},
|
|
120
|
+
parseDOM: [
|
|
121
|
+
{
|
|
122
|
+
tag: "div",
|
|
123
|
+
// Before element rules (extendedValidElements: 'div[*]') and plain blocks.
|
|
124
|
+
priority: 70,
|
|
125
|
+
getAttrs: (dom) => {
|
|
126
|
+
const el = dom;
|
|
127
|
+
const classes = [...el.classList];
|
|
128
|
+
if (!isWrapper(classes, settings)) return false;
|
|
129
|
+
const frame = el.querySelector("iframe");
|
|
130
|
+
const src = embeddableUrl(frame?.getAttribute("src"), settings.allowUrl);
|
|
131
|
+
if (!frame || !src) return false;
|
|
132
|
+
const border = frame.getAttribute("frameborder");
|
|
133
|
+
return {
|
|
134
|
+
src,
|
|
135
|
+
size: sizeFromClasses(classes, settings),
|
|
136
|
+
width: imageSize(frame.getAttribute("width")) ?? FIXED.width,
|
|
137
|
+
height: imageSize(frame.getAttribute("height")) ?? FIXED.height,
|
|
138
|
+
title: (frame.getAttribute("title") ?? "").trim().slice(0, 300),
|
|
139
|
+
border: border !== null && border !== "0" && border.toLowerCase() !== "no",
|
|
140
|
+
scrolling: frame.getAttribute("scrolling")?.toLowerCase() !== "no"
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
toDOM: (node) => {
|
|
146
|
+
const src = embeddableUrl(node.attrs.src, settings.allowUrl);
|
|
147
|
+
if (!src) return ["div", { class: settings.className }];
|
|
148
|
+
const attrs = frameAttrs(node, src, settings);
|
|
149
|
+
const size = sizeOf(node.attrs.size, settings);
|
|
150
|
+
if (!size) {
|
|
151
|
+
attrs.width = String(imageSize(node.attrs.width) ?? FIXED.width);
|
|
152
|
+
attrs.height = String(imageSize(node.attrs.height) ?? FIXED.height);
|
|
153
|
+
return ["div", { class: settings.className }, ["iframe", attrs]];
|
|
154
|
+
}
|
|
155
|
+
const ratio = settings.inlineStyles ? ratioOf(size) : null;
|
|
156
|
+
if (ratio) {
|
|
157
|
+
const percent = Math.round(ratio[1] / ratio[0] * 1e6) / 1e4;
|
|
158
|
+
attrs.style = `position: absolute; top: 0; left: 0; width: 100%; height: 100%${node.attrs.border === true ? "" : "; border: 0"}`;
|
|
159
|
+
return [
|
|
160
|
+
"div",
|
|
161
|
+
{
|
|
162
|
+
class: `${settings.className} ${size}`,
|
|
163
|
+
style: `position: relative; width: 100%; padding-top: ${percent}%; overflow: hidden`
|
|
164
|
+
},
|
|
165
|
+
["iframe", attrs]
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
return ["div", { class: `${settings.className} ${size}` }, ["iframe", attrs]];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function pageEmbedView(node, settings) {
|
|
174
|
+
const dom = h("div", { className: "nova-media nova-pageembed-view", contenteditable: "false" });
|
|
175
|
+
const overlay = h("div", { className: "nova-media-overlay", "aria-hidden": "true" });
|
|
176
|
+
let frame = null;
|
|
177
|
+
let shown = null;
|
|
178
|
+
const render = (current) => {
|
|
179
|
+
const src = embeddableUrl(current.attrs.src, settings.allowUrl);
|
|
180
|
+
const size = sizeOf(current.attrs.size, settings);
|
|
181
|
+
const ratio = size ? ratioOf(size) : null;
|
|
182
|
+
dom.classList.toggle("is-responsive", !!size);
|
|
183
|
+
dom.classList.toggle("has-border", current.attrs.border === true);
|
|
184
|
+
if (!src) {
|
|
185
|
+
frame?.remove();
|
|
186
|
+
frame = null;
|
|
187
|
+
shown = null;
|
|
188
|
+
dom.replaceChildren(
|
|
189
|
+
h(
|
|
190
|
+
"div",
|
|
191
|
+
{ className: "nova-pageembed-missing" },
|
|
192
|
+
typeof current.attrs.src === "string" ? current.attrs.src : ""
|
|
193
|
+
),
|
|
194
|
+
overlay
|
|
195
|
+
);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!frame || shown !== src) {
|
|
199
|
+
const attrs = frameAttrs(current, src, settings);
|
|
200
|
+
frame = h("iframe", {
|
|
201
|
+
src,
|
|
202
|
+
title: attrs.title,
|
|
203
|
+
...attrs.sandbox === null ? {} : { sandbox: attrs.sandbox },
|
|
204
|
+
allow: "fullscreen",
|
|
205
|
+
loading: "lazy",
|
|
206
|
+
referrerpolicy: "strict-origin-when-cross-origin",
|
|
207
|
+
// Tab stays in the text: the page in the frame is not a stop while editing.
|
|
208
|
+
tabindex: "-1"
|
|
209
|
+
});
|
|
210
|
+
shown = src;
|
|
211
|
+
dom.replaceChildren(frame, overlay);
|
|
212
|
+
}
|
|
213
|
+
frame.title = frameTitle(current.attrs.title, src);
|
|
214
|
+
if (current.attrs.scrolling === false) frame.setAttribute("scrolling", "no");
|
|
215
|
+
else frame.removeAttribute("scrolling");
|
|
216
|
+
if (size) {
|
|
217
|
+
frame.removeAttribute("width");
|
|
218
|
+
frame.removeAttribute("height");
|
|
219
|
+
frame.style.aspectRatio = ratio ? `${ratio[0]} / ${ratio[1]}` : "16 / 9";
|
|
220
|
+
} else {
|
|
221
|
+
frame.style.aspectRatio = "";
|
|
222
|
+
frame.setAttribute("width", String(imageSize(current.attrs.width) ?? FIXED.width));
|
|
223
|
+
frame.setAttribute("height", String(imageSize(current.attrs.height) ?? FIXED.height));
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
render(node);
|
|
227
|
+
return {
|
|
228
|
+
dom,
|
|
229
|
+
update(next) {
|
|
230
|
+
if (next.type !== node.type) return false;
|
|
231
|
+
node = next;
|
|
232
|
+
render(next);
|
|
233
|
+
return true;
|
|
234
|
+
},
|
|
235
|
+
ignoreMutation: () => true,
|
|
236
|
+
stopEvent: () => false
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
var pageembed_default = definePlugin({
|
|
240
|
+
name: "pageembed",
|
|
241
|
+
toolbar: "pageembed",
|
|
242
|
+
nodes: buildNodes,
|
|
243
|
+
prosemirrorPlugins: (editor) => {
|
|
244
|
+
const settings = pageEmbedOptions(editor);
|
|
245
|
+
return [
|
|
246
|
+
new Plugin({
|
|
247
|
+
props: {
|
|
248
|
+
nodeViews: { pageembed: (node) => pageEmbedView(node, settings) }
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
];
|
|
252
|
+
},
|
|
253
|
+
load: () => import("./pageembed-ui-WOY6VWRJ.js")
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
export {
|
|
257
|
+
FIXED,
|
|
258
|
+
pageEmbedOptions,
|
|
259
|
+
ratioOf,
|
|
260
|
+
embeddableUrl,
|
|
261
|
+
pageembed_default
|
|
262
|
+
};
|
|
263
|
+
//# sourceMappingURL=chunk-NTGEKGXU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugins/pageembed.ts"],"sourcesContent":["import type { Node as PMNode, NodeSpec } from 'prosemirror-model';\nimport { Plugin } from 'prosemirror-state';\nimport type { Editor } from '../editor';\nimport { definePlugin } from '../plugins';\nimport { imageSize } from '../schema';\nimport { h } from '../ui/dom';\n\n/**\n * The pageembed plugin: a web page shown in the document, in a frame. `plugins: ['pageembed']`.\n * Here are the node and its view in the editor; the dialog and the button are in pageembed-ui.ts.\n *\n * An embed is a wrapper with a frame: `<div class=\"nova-pageembed …\"><iframe …></iframe></div>`. A\n * sized one (`nova-pageembed--16by9`) fills the width and keeps the ratio, a fixed one has its own\n * width and height.\n *\n * Security: only absolute http(s) addresses are embedded, without a name and password in them,\n * when parsing and on output (a document can come as JSON); `allowUrl` narrows them to your list.\n * An <iframe> on its own isn't embedded, so a pasted web page doesn't bring its frames along. The\n * frame is sandboxed: the page runs its own scripts, forms and popups, but can't navigate the page\n * it is shown on, and gets no camera, microphone or location.\n */\n\nexport interface PageEmbedSize {\n /** The name in the dialog (\"Full width, 16:9\" when left out). */\n text?: string;\n /** The class it adds to the wrapper; \"…--16by9\" fills the width with that ratio. */\n value: string;\n}\n\nexport interface PageEmbedOptions {\n /** The sizes offered besides a fixed one. An empty list: only a fixed size. */\n sizes?: PageEmbedSize[];\n /** Sizes also as inline styles, so the page that shows the HTML needs no CSS for them (yes). */\n inlineStyles?: boolean;\n /** The wrapper's class ('nova-pageembed'). */\n className?: string;\n /** The frame's sandbox (`allow-*` words); false: no sandbox. */\n sandbox?: string | false;\n /** Which addresses may be embedded: every http(s) one by default. */\n allowUrl?: (url: string) => boolean;\n}\n\nexport const DEFAULT_SANDBOX =\n 'allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation';\n\nconst DEFAULT_SIZES: PageEmbedSize[] = ['21by9', '16by9', '4by3', '1by1'].map((ratio) => ({\n value: `nova-pageembed--${ratio}`,\n}));\n\n/** The width and height of a fixed size when the HTML doesn't say. */\nexport const FIXED = { width: 350, height: 260 };\n\nconst CLASS_RE = /^[\\w-]{1,60}$/;\nconst RATIO_RE = /--(\\d{1,3})by(\\d{1,3})$/;\n\n/** The plugin's settings, checked: what is wrong in them falls back to the default. */\nexport function pageEmbedOptions(context: { options: Editor['options'] }): Required<\n Omit<PageEmbedOptions, 'allowUrl'>\n> & {\n allowUrl?: (url: string) => boolean;\n} {\n const raw = (context.options.pluginOptions?.pageembed ?? {}) as PageEmbedOptions;\n const sizes = Array.isArray(raw.sizes)\n ? raw.sizes.filter(\n (size): size is PageEmbedSize =>\n !!size && typeof size.value === 'string' && CLASS_RE.test(size.value),\n )\n : DEFAULT_SIZES;\n const sandbox =\n raw.sandbox === false\n ? false\n : typeof raw.sandbox === 'string'\n ? raw.sandbox\n .split(/\\s+/)\n .filter((word) => /^allow-[a-z-]{1,40}$/.test(word))\n .join(' ')\n : DEFAULT_SANDBOX;\n return {\n sizes,\n inlineStyles: raw.inlineStyles !== false,\n className:\n typeof raw.className === 'string' && CLASS_RE.test(raw.className)\n ? raw.className\n : 'nova-pageembed',\n sandbox,\n allowUrl: typeof raw.allowUrl === 'function' ? raw.allowUrl : undefined,\n };\n}\n\n/** The ratio a size class keeps ([16, 9] for \"…--16by9\"), or null. */\nexport function ratioOf(value: string): [number, number] | null {\n const match = RATIO_RE.exec(value);\n if (!match) return null;\n const width = Number(match[1]);\n const height = Number(match[2]);\n return width > 0 && height > 0 ? [width, height] : null;\n}\n\n/** The address if it may be embedded: absolute http(s), no credentials, allowed by `allowUrl`. */\nexport function embeddableUrl(url: unknown, allowUrl?: (url: string) => boolean): string | null {\n if (typeof url !== 'string') return null;\n const value = url.trim();\n if (value.length > 2000 || !/^https?:\\/\\/[^\\s/?#]/i.test(value)) return null;\n let parsed: URL;\n try {\n parsed = new URL(value);\n } catch {\n return null;\n }\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return null;\n if (parsed.username || parsed.password) return null;\n try {\n if (allowUrl && !allowUrl(parsed.href)) return null;\n } catch {\n return null;\n }\n return value;\n}\n\n/** A name for screen readers: the title, or the site's name. */\nfunction frameTitle(title: unknown, src: string): string {\n if (typeof title === 'string' && title.trim()) return title.trim().slice(0, 300);\n try {\n return new URL(src).hostname;\n } catch {\n return src;\n }\n}\n\ntype Settings = ReturnType<typeof pageEmbedOptions>;\n\n/** The size of a node: one of the configured classes, or '' (fixed). */\nfunction sizeOf(value: unknown, settings: Settings): string {\n return typeof value === 'string' && settings.sizes.some((size) => size.value === value)\n ? value\n : '';\n}\n\n/** The size of a wrapper's classes: a configured class, or one with the same ratio (another editor's). */\nfunction sizeFromClasses(classes: string[], settings: Settings): string {\n const own = classes.find((name) => settings.sizes.some((size) => size.value === name));\n if (own) return own;\n for (const name of classes) {\n const ratio = /^(?:nova|tiny)-pageembed--/.test(name) ? ratioOf(name) : null;\n if (!ratio) continue;\n const same = settings.sizes.find((size) => {\n const other = ratioOf(size.value);\n return !!other && other[0] * ratio[1] === other[1] * ratio[0];\n });\n if (same) return same.value;\n }\n return '';\n}\n\nfunction isWrapper(classes: string[], settings: Settings): boolean {\n return classes.some(\n (name) =>\n name === settings.className ||\n /^(?:nova|tiny)-pageembed(?:--[\\w-]+)?$/.test(name) ||\n settings.sizes.some((size) => size.value === name),\n );\n}\n\nfunction frameAttrs(node: PMNode, src: string, settings: Settings): Record<string, string | null> {\n return {\n src,\n title: frameTitle(node.attrs.title, src),\n sandbox: settings.sandbox === false ? null : settings.sandbox,\n allow: 'fullscreen',\n allowfullscreen: '',\n loading: 'lazy',\n referrerpolicy: 'strict-origin-when-cross-origin',\n frameborder: node.attrs.border === true ? '1' : '0',\n scrolling: node.attrs.scrolling === false ? 'no' : null,\n };\n}\n\nfunction buildNodes(context: { options: Editor['options'] }): Record<string, NodeSpec> {\n const settings = pageEmbedOptions(context);\n return {\n pageembed: {\n group: 'block',\n atom: true,\n selectable: true,\n draggable: true,\n attrs: {\n src: { default: '' },\n size: { default: '' },\n width: { default: FIXED.width },\n height: { default: FIXED.height },\n title: { default: '' },\n border: { default: false },\n scrolling: { default: true },\n },\n parseDOM: [\n {\n tag: 'div',\n // Before element rules (extendedValidElements: 'div[*]') and plain blocks.\n priority: 70,\n getAttrs: (dom) => {\n const el = dom as HTMLElement;\n const classes = [...el.classList];\n if (!isWrapper(classes, settings)) return false;\n const frame = el.querySelector('iframe');\n const src = embeddableUrl(frame?.getAttribute('src'), settings.allowUrl);\n if (!frame || !src) return false;\n const border = frame.getAttribute('frameborder');\n return {\n src,\n size: sizeFromClasses(classes, settings),\n width: imageSize(frame.getAttribute('width')) ?? FIXED.width,\n height: imageSize(frame.getAttribute('height')) ?? FIXED.height,\n title: (frame.getAttribute('title') ?? '').trim().slice(0, 300),\n border: border !== null && border !== '0' && border.toLowerCase() !== 'no',\n scrolling: frame.getAttribute('scrolling')?.toLowerCase() !== 'no',\n };\n },\n },\n ],\n toDOM: (node) => {\n // The document may come from JSON: the address is checked again.\n const src = embeddableUrl(node.attrs.src, settings.allowUrl);\n if (!src) return ['div', { class: settings.className }];\n const attrs = frameAttrs(node, src, settings);\n const size = sizeOf(node.attrs.size, settings);\n if (!size) {\n attrs.width = String(imageSize(node.attrs.width) ?? FIXED.width);\n attrs.height = String(imageSize(node.attrs.height) ?? FIXED.height);\n return ['div', { class: settings.className }, ['iframe', attrs]];\n }\n const ratio = settings.inlineStyles ? ratioOf(size) : null;\n if (ratio) {\n const percent = Math.round((ratio[1] / ratio[0]) * 1e6) / 1e4;\n attrs.style = `position: absolute; top: 0; left: 0; width: 100%; height: 100%${\n node.attrs.border === true ? '' : '; border: 0'\n }`;\n return [\n 'div',\n {\n class: `${settings.className} ${size}`,\n style: `position: relative; width: 100%; padding-top: ${percent}%; overflow: hidden`,\n },\n ['iframe', attrs],\n ];\n }\n return ['div', { class: `${settings.className} ${size}` }, ['iframe', attrs]];\n },\n },\n };\n}\n\n/** The view in the editor: the page in its frame under a layer, so a click selects the block. */\nfunction pageEmbedView(node: PMNode, settings: Settings) {\n const dom = h('div', { className: 'nova-media nova-pageembed-view', contenteditable: 'false' });\n const overlay = h('div', { className: 'nova-media-overlay', 'aria-hidden': 'true' });\n let frame: HTMLIFrameElement | null = null;\n let shown: string | null = null;\n\n const render = (current: PMNode) => {\n const src = embeddableUrl(current.attrs.src, settings.allowUrl);\n const size = sizeOf(current.attrs.size, settings);\n const ratio = size ? ratioOf(size) : null;\n dom.classList.toggle('is-responsive', !!size);\n dom.classList.toggle('has-border', current.attrs.border === true);\n if (!src) {\n frame?.remove();\n frame = null;\n shown = null;\n dom.replaceChildren(\n h(\n 'div',\n { className: 'nova-pageembed-missing' },\n typeof current.attrs.src === 'string' ? current.attrs.src : '',\n ),\n overlay,\n );\n return;\n }\n // The same address: the frame stays (it would load the page again otherwise).\n if (!frame || shown !== src) {\n const attrs = frameAttrs(current, src, settings);\n frame = h('iframe', {\n src,\n title: attrs.title!,\n ...(attrs.sandbox === null ? {} : { sandbox: attrs.sandbox }),\n allow: 'fullscreen',\n loading: 'lazy',\n referrerpolicy: 'strict-origin-when-cross-origin',\n // Tab stays in the text: the page in the frame is not a stop while editing.\n tabindex: '-1',\n }) as HTMLIFrameElement;\n shown = src;\n dom.replaceChildren(frame, overlay);\n }\n frame.title = frameTitle(current.attrs.title, src);\n if (current.attrs.scrolling === false) frame.setAttribute('scrolling', 'no');\n else frame.removeAttribute('scrolling');\n if (size) {\n frame.removeAttribute('width');\n frame.removeAttribute('height');\n frame.style.aspectRatio = ratio ? `${ratio[0]} / ${ratio[1]}` : '16 / 9';\n } else {\n frame.style.aspectRatio = '';\n frame.setAttribute('width', String(imageSize(current.attrs.width) ?? FIXED.width));\n frame.setAttribute('height', String(imageSize(current.attrs.height) ?? FIXED.height));\n }\n };\n render(node);\n\n return {\n dom,\n update(next: PMNode) {\n if (next.type !== node.type) return false;\n node = next;\n render(next);\n return true;\n },\n ignoreMutation: () => true,\n stopEvent: () => false,\n };\n}\n\nexport default definePlugin({\n name: 'pageembed',\n toolbar: 'pageembed',\n nodes: buildNodes,\n prosemirrorPlugins: (editor) => {\n const settings = pageEmbedOptions(editor);\n return [\n new Plugin({\n props: {\n nodeViews: { pageembed: (node) => pageEmbedView(node, settings) },\n },\n }),\n ];\n },\n load: () => import('./pageembed-ui'),\n});\n"],"mappings":";;;;;;;;;;;AACA,SAAS,cAAc;AAyChB,IAAM,kBACX;AAEF,IAAM,gBAAiC,CAAC,SAAS,SAAS,QAAQ,MAAM,EAAE,IAAI,CAAC,WAAW;AAAA,EACxF,OAAO,mBAAmB,KAAK;AACjC,EAAE;AAGK,IAAM,QAAQ,EAAE,OAAO,KAAK,QAAQ,IAAI;AAE/C,IAAM,WAAW;AACjB,IAAM,WAAW;AAGV,SAAS,iBAAiB,SAI/B;AACA,QAAM,MAAO,QAAQ,QAAQ,eAAe,aAAa,CAAC;AAC1D,QAAM,QAAQ,MAAM,QAAQ,IAAI,KAAK,IACjC,IAAI,MAAM;AAAA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tE,OAAM,gBAAgB,WAAW;AACtC,QAAI,MAAM;AACR,YAAM,gBAAgB,OAAO;AAC7B,YAAM,gBAAgB,QAAQ;AAC9B,YAAM,MAAM,cAAc,QAAQ,GAAG,MAAM,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,KAAK;AAAA,IAClE,OAAO;AACL,YAAM,MAAM,cAAc;AAC1B,YAAM,aAAa,SAAS,OAAO,UAAU,QAAQ,MAAM,KAAK,KAAK,MAAM,KAAK,CAAC;AACjF,YAAM,aAAa,UAAU,OAAO,UAAU,QAAQ,MAAM,MAAM,KAAK,MAAM,MAAM,CAAC;AAAA,IACtF;AAAA,EACF;AACA,SAAO,IAAI;AAEX,SAAO;AAAA,IACL;AAAA,IACA,OAAO,MAAc;AACnB,UAAI,KAAK,SAAS,KAAK,KAAM,QAAO;AACpC,aAAO;AACP,aAAO,IAAI;AACX,aAAO;AAAA,IACT;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,WAAW,MAAM;AAAA,EACnB;AACF;AAEA,IAAO,oBAAQ,aAAa;AAAA,EAC1B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,oBAAoB,CAAC,WAAW;AAC9B,UAAM,WAAW,iBAAiB,MAAM;AACxC,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,QACT,OAAO;AAAA,UACL,WAAW,EAAE,WAAW,CAAC,SAAS,cAAc,MAAM,QAAQ,EAAE;AAAA,QAClE;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EACA,MAAM,MAAM,OAAO,4BAAgB;AACrC,CAAC;","names":[]}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
definePlugin
|
|
3
|
+
} from "./chunk-V7WUHUHM.js";
|
|
4
|
+
|
|
5
|
+
// nova-raw-css:/home/runner/work/novaprose/novaprose/packages/core/src/plugins/pagelayout.css?raw
|
|
6
|
+
var pagelayout_default = ".nova-pages{--nova-desk: #e6e9ed}[data-theme=dark] .nova-pages{--nova-desk: #010409}@media(prefers-color-scheme:dark){.nova-pages:not([data-theme=light] *){--nova-desk: #010409}}.nova-pages .nova-content{position:relative;padding:24px 12px 32px;background:var(--nova-desk)}.nova-pages .nova-prosemirror{box-sizing:border-box;width:var(--nova-page-width);max-width:100%;min-height:max(var(--nova-page-height),var(--nova-pages-height, 0px));margin:0 auto;padding:var(--nova-page-margins);background:var(--nova-bg);color:var(--nova-fg);box-shadow:0 1px 3px #0000002e,0 8px 24px #00000014}@media(max-width:600px){.nova-pages .nova-content{padding:0}.nova-pages .nova-prosemirror{padding:16px;box-shadow:none}}";
|
|
7
|
+
|
|
8
|
+
// src/plugins/pagelayout.ts
|
|
9
|
+
var PAGE_SIZES = {
|
|
10
|
+
A3: [297, 420],
|
|
11
|
+
A4: [210, 297],
|
|
12
|
+
A5: [148, 210],
|
|
13
|
+
A6: [105, 148],
|
|
14
|
+
Letter: [215.9, 279.4],
|
|
15
|
+
Legal: [215.9, 355.6]
|
|
16
|
+
};
|
|
17
|
+
var DEFAULT_MARGIN = 20;
|
|
18
|
+
function millimetres(value, min, max, fallback) {
|
|
19
|
+
const n = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
|
|
20
|
+
return Number.isFinite(n) ? Math.min(max, Math.max(min, Math.round(n * 10) / 10)) : fallback;
|
|
21
|
+
}
|
|
22
|
+
function bandText(value) {
|
|
23
|
+
return typeof value === "string" ? value.replace(/\s+/g, " ").trim().slice(0, 200) : "";
|
|
24
|
+
}
|
|
25
|
+
function resolveBand(value) {
|
|
26
|
+
let parts = null;
|
|
27
|
+
if (typeof value === "string") parts = { left: "", center: bandText(value), right: "" };
|
|
28
|
+
else if (typeof value === "object" && value !== null) {
|
|
29
|
+
const given = value;
|
|
30
|
+
parts = {
|
|
31
|
+
left: bandText(given.left),
|
|
32
|
+
center: bandText(given.center),
|
|
33
|
+
right: bandText(given.right)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return parts && (parts.left || parts.center || parts.right) ? parts : null;
|
|
37
|
+
}
|
|
38
|
+
function fillBand(text, page, pages) {
|
|
39
|
+
return text.replace(/\{page\}/g, String(page)).replace(/\{pages\}/g, String(pages));
|
|
40
|
+
}
|
|
41
|
+
function resolvePageLayout(options = {}) {
|
|
42
|
+
const custom = typeof options.size === "object" && options.size !== null;
|
|
43
|
+
const name = !custom && typeof options.size === "string" && options.size in PAGE_SIZES ? options.size : "A4";
|
|
44
|
+
const given = options.size;
|
|
45
|
+
let [width, height] = custom ? [millimetres(given?.width, 30, 2e3, 210), millimetres(given?.height, 30, 2e3, 297)] : PAGE_SIZES[name];
|
|
46
|
+
if (options.orientation === "landscape" || options.orientation === "portrait") {
|
|
47
|
+
const landscape = options.orientation === "landscape";
|
|
48
|
+
const wide = width > height;
|
|
49
|
+
if (landscape !== wide) [width, height] = [height, width];
|
|
50
|
+
}
|
|
51
|
+
const limit = Math.min(width, height) / 3;
|
|
52
|
+
const raw = options.margins;
|
|
53
|
+
const side = (key) => millimetres(
|
|
54
|
+
typeof raw === "object" && raw !== null ? raw[key] : raw,
|
|
55
|
+
0,
|
|
56
|
+
limit,
|
|
57
|
+
Math.min(DEFAULT_MARGIN, limit)
|
|
58
|
+
);
|
|
59
|
+
return {
|
|
60
|
+
size: custom ? "custom" : name,
|
|
61
|
+
orientation: width > height ? "landscape" : "portrait",
|
|
62
|
+
width,
|
|
63
|
+
height,
|
|
64
|
+
margins: { top: side("top"), right: side("right"), bottom: side("bottom"), left: side("left") },
|
|
65
|
+
header: resolveBand(options.header),
|
|
66
|
+
footer: resolveBand(options.footer),
|
|
67
|
+
differentFirstPage: options.differentFirstPage === true
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
var states = /* @__PURE__ */ new WeakMap();
|
|
71
|
+
function notify(state) {
|
|
72
|
+
for (const listener of [...state.listeners]) {
|
|
73
|
+
try {
|
|
74
|
+
listener();
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error("[nova] pagelayout: listener failed", error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function applyLayout(editor, layout) {
|
|
81
|
+
const { style } = editor.root;
|
|
82
|
+
const { top, right, bottom, left } = layout.margins;
|
|
83
|
+
style.setProperty("--nova-page-width", `${layout.width}mm`);
|
|
84
|
+
style.setProperty("--nova-page-height", `${layout.height}mm`);
|
|
85
|
+
style.setProperty("--nova-page-margins", `${top}mm ${right}mm ${bottom}mm ${left}mm`);
|
|
86
|
+
}
|
|
87
|
+
function pageLayout(editor) {
|
|
88
|
+
const state = states.get(editor);
|
|
89
|
+
if (!state) return void 0;
|
|
90
|
+
return {
|
|
91
|
+
get layout() {
|
|
92
|
+
return state.layout;
|
|
93
|
+
},
|
|
94
|
+
get pages() {
|
|
95
|
+
return state.pages;
|
|
96
|
+
},
|
|
97
|
+
set(options) {
|
|
98
|
+
state.options = { ...state.options, ...options };
|
|
99
|
+
state.layout = resolvePageLayout(state.options);
|
|
100
|
+
applyLayout(editor, state.layout);
|
|
101
|
+
notify(state);
|
|
102
|
+
},
|
|
103
|
+
onChange(listener) {
|
|
104
|
+
state.listeners.add(listener);
|
|
105
|
+
return () => state.listeners.delete(listener);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function setPageCount(editor, pages) {
|
|
110
|
+
const state = states.get(editor);
|
|
111
|
+
if (!state || state.pages === pages) return;
|
|
112
|
+
state.pages = pages;
|
|
113
|
+
notify(state);
|
|
114
|
+
}
|
|
115
|
+
var pagelayout_default2 = definePlugin({
|
|
116
|
+
name: "pagelayout",
|
|
117
|
+
setup(editor) {
|
|
118
|
+
const options = editor.options.pluginOptions?.pagelayout ?? {};
|
|
119
|
+
const layout = resolvePageLayout(options);
|
|
120
|
+
states.set(editor, { options, layout, pages: null, listeners: /* @__PURE__ */ new Set() });
|
|
121
|
+
editor.ui.addStyles("nova-pagelayout", pagelayout_default);
|
|
122
|
+
editor.root.classList.add("nova-pages");
|
|
123
|
+
applyLayout(editor, layout);
|
|
124
|
+
return () => {
|
|
125
|
+
states.delete(editor);
|
|
126
|
+
editor.root.classList.remove("nova-pages");
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
load: () => import("./pagelayout-ui-Y2IM7FJQ.js")
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export {
|
|
133
|
+
PAGE_SIZES,
|
|
134
|
+
fillBand,
|
|
135
|
+
resolvePageLayout,
|
|
136
|
+
pageLayout,
|
|
137
|
+
setPageCount,
|
|
138
|
+
pagelayout_default2 as pagelayout_default
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=chunk-OFHGXYG3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["nova-raw-css:/home/runner/work/novaprose/novaprose/packages/core/src/plugins/pagelayout.css?raw","../src/plugins/pagelayout.ts"],"sourcesContent":[".nova-pages{--nova-desk: #e6e9ed}[data-theme=dark] .nova-pages{--nova-desk: #010409}@media(prefers-color-scheme:dark){.nova-pages:not([data-theme=light] *){--nova-desk: #010409}}.nova-pages .nova-content{position:relative;padding:24px 12px 32px;background:var(--nova-desk)}.nova-pages .nova-prosemirror{box-sizing:border-box;width:var(--nova-page-width);max-width:100%;min-height:max(var(--nova-page-height),var(--nova-pages-height, 0px));margin:0 auto;padding:var(--nova-page-margins);background:var(--nova-bg);color:var(--nova-fg);box-shadow:0 1px 3px #0000002e,0 8px 24px #00000014}@media(max-width:600px){.nova-pages .nova-content{padding:0}.nova-pages .nova-prosemirror{padding:16px;box-shadow:none}}","import type { Editor } from '../editor';\nimport { definePlugin } from '../plugins';\nimport css from './pagelayout.css?raw';\n\n/**\n * The pagelayout plugin: page layout. The text sits on a sheet of the exact size with margins, as\n * when printed; page boundaries show right in the text; printing and export use the same sizes.\n *\n * plugins: ['pagelayout'],\n * pluginOptions: { pagelayout: { size: 'A4', orientation: 'portrait', margins: 20 } }\n *\n * This part is the sheet itself (needed from the first frame: a sheet appearing later would shift\n * the whole text) and the settings with pageLayout(editor). Page boundaries are computed in the lazy part, pagelayout-ui.ts.\n */\n\nexport type PageSizeName = 'A3' | 'A4' | 'A5' | 'A6' | 'Letter' | 'Legal';\n\nexport interface PageMargins {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\n/** Text in a page margin: one string (centered), or parts at the left, the center and the right. */\nexport type PageBand = string | { left?: string; center?: string; right?: string };\n\nexport interface PageLayoutOptions {\n /** Sheet size: 'A4' (default), 'A3', 'A5', 'A6', 'Letter', 'Legal' or { width, height } in mm. */\n size?: PageSizeName | { width: number; height: number };\n /** Orientation; without it, portrait for standard sizes and as given for your own size. */\n orientation?: 'portrait' | 'landscape';\n /** Margins in mm: one number for all sides, or per side. Default 20. */\n margins?: number | Partial<PageMargins>;\n /**\n * Text in the top margin of every page: one string (centered) or { left, center, right }.\n * `{page}` and `{pages}` become the page number and the number of pages: 'Page {page} of {pages}'.\n */\n header?: PageBand;\n /** Text in the bottom margin of every page, like `header`. */\n footer?: PageBand;\n /** The first page without header and footer (a title page), as \"Different first page\" in Word. */\n differentFirstPage?: boolean;\n}\n\n/** A header or footer: its three parts, '' where there is nothing. */\nexport interface PageBandParts {\n left: string;\n center: string;\n right: string;\n}\n\n/** The sheet in mm (orientation already applied), the margins and the header and footer. */\nexport interface PageLayout {\n size: PageSizeName | 'custom';\n orientation: 'portrait' | 'landscape';\n width: number;\n height: number;\n margins: PageMargins;\n /** null when there is none. */\n header: PageBandParts | null;\n footer: PageBandParts | null;\n differentFirstPage: boolean;\n}\n\n/** Sheet sizes in mm (portrait). */\nexport const PAGE_SIZES: Readonly<Record<PageSizeName, readonly [number, number]>> = {\n A3: [297, 420],\n A4: [210, 297],\n A5: [148, 210],\n A6: [105, 148],\n Letter: [215.9, 279.4],\n Legal: [215.9, 355.6],\n};\n\nconst DEFAULT_MARGIN = 20;\n\nfunction millimetres(value: unknown, min: number, max: number, fallback: number): number {\n const n = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : NaN;\n return Number.isFinite(n) ? Math.min(max, Math.max(min, Math.round(n * 10) / 10)) : fallback;\n}\n\n/** One line of plain text, at most 200 characters; anything but a string gives ''. */\nfunction bandText(value: unknown): string {\n return typeof value === 'string' ? value.replace(/\\s+/g, ' ').trim().slice(0, 200) : '';\n}\n\n/** A header or footer setting → its parts; null when it has no text. */\nexport function resolveBand(value: unknown): PageBandParts | null {\n let parts: PageBandParts | null = null;\n if (typeof value === 'string') parts = { left: '', center: bandText(value), right: '' };\n else if (typeof value === 'object' && value !== null) {\n const given = value as Record<string, unknown>;\n parts = {\n left: bandText(given.left),\n center: bandText(given.center),\n right: bandText(given.right),\n };\n }\n return parts && (parts.left || parts.center || parts.right) ? parts : null;\n}\n\n/** `{page}` and `{pages}` in a header or footer replaced with numbers (for the screen and for Word previews). */\nexport function fillBand(text: string, page: number, pages: number): string {\n return text.replace(/\\{page\\}/g, String(page)).replace(/\\{pages\\}/g, String(pages));\n}\n\n/** Settings → the sheet. Garbage from the config gets the defaults; a margin is at most a third of the sheet. */\nexport function resolvePageLayout(options: PageLayoutOptions = {}): PageLayout {\n const custom = typeof options.size === 'object' && options.size !== null;\n const name: PageSizeName =\n !custom && typeof options.size === 'string' && options.size in PAGE_SIZES\n ? (options.size as PageSizeName)\n : 'A4';\n const given = options.size as { width?: unknown; height?: unknown } | undefined;\n let [width, height] = custom\n ? [millimetres(given?.width, 30, 2000, 210), millimetres(given?.height, 30, 2000, 297)]\n : PAGE_SIZES[name];\n if (options.orientation === 'landscape' || options.orientation === 'portrait') {\n const landscape = options.orientation === 'landscape';\n const wide = width > height;\n if (landscape !== wide) [width, height] = [height, width];\n }\n const limit = Math.min(width, height) / 3;\n const raw = options.margins;\n const side = (key: keyof PageMargins) =>\n millimetres(\n typeof raw === 'object' && raw !== null ? raw[key] : raw,\n 0,\n limit,\n Math.min(DEFAULT_MARGIN, limit),\n );\n return {\n size: custom ? 'custom' : name,\n orientation: width > height ? 'landscape' : 'portrait',\n width,\n height,\n margins: { top: side('top'), right: side('right'), bottom: side('bottom'), left: side('left') },\n header: resolveBand(options.header),\n footer: resolveBand(options.footer),\n differentFirstPage: options.differentFirstPage === true,\n };\n}\n\nexport interface PageLayoutController {\n /** The current sheet (mm). */\n readonly layout: PageLayout;\n /**\n * How many pages the document has. null — not counted yet, or the sheet is narrower than the page\n * (a narrow screen: lines wrap differently than in print).\n */\n readonly pages: number | null;\n /** Change the size, orientation or margins (the rest stays). */\n set(options: PageLayoutOptions): void;\n /** The sheet or the page count changed. Returns an unsubscribe function. */\n onChange(listener: () => void): () => void;\n}\n\ninterface State {\n options: PageLayoutOptions;\n layout: PageLayout;\n pages: number | null;\n listeners: Set<() => void>;\n}\n\nconst states = new WeakMap<Editor, State>();\n\nfunction notify(state: State): void {\n for (const listener of [...state.listeners]) {\n try {\n listener();\n } catch (error) {\n console.error('[nova] pagelayout: listener failed', error);\n }\n }\n}\n\nfunction applyLayout(editor: Editor, layout: PageLayout): void {\n const { style } = editor.root;\n const { top, right, bottom, left } = layout.margins;\n style.setProperty('--nova-page-width', `${layout.width}mm`);\n style.setProperty('--nova-page-height', `${layout.height}mm`);\n style.setProperty('--nova-page-margins', `${top}mm ${right}mm ${bottom}mm ${left}mm`);\n}\n\n/** The editor's page layout (the pagelayout plugin); undefined when the plugin isn't active. */\nexport function pageLayout(editor: Editor): PageLayoutController | undefined {\n const state = states.get(editor);\n if (!state) return undefined;\n return {\n get layout() {\n return state.layout;\n },\n get pages() {\n return state.pages;\n },\n set(options) {\n state.options = { ...state.options, ...options };\n state.layout = resolvePageLayout(state.options);\n applyLayout(editor, state.layout);\n notify(state);\n },\n onChange(listener) {\n state.listeners.add(listener);\n return () => state.listeners.delete(listener);\n },\n };\n}\n\n/** For the lazy part: the number of pages has been computed. */\nexport function setPageCount(editor: Editor, pages: number | null): void {\n const state = states.get(editor);\n if (!state || state.pages === pages) return;\n state.pages = pages;\n notify(state);\n}\n\nexport default definePlugin({\n name: 'pagelayout',\n setup(editor) {\n const options = (editor.options.pluginOptions?.pagelayout ?? {}) as PageLayoutOptions;\n const layout = resolvePageLayout(options);\n states.set(editor, { options, layout, pages: null, listeners: new Set() });\n editor.ui.addStyles('nova-pagelayout', css);\n editor.root.classList.add('nova-pages');\n applyLayout(editor, layout);\n return () => {\n states.delete(editor);\n editor.root.classList.remove('nova-pages');\n };\n },\n load: () => import('./pagelayout-ui'),\n});\n"],"mappings":";;;;;AAAA;;;ACkEO,IAAM,aAAwE;AAAA,EACnF,IAAI,CAAC,KAAK,GAAG;AAAA,EACb,IAAI,CAAC,KAAK,GAAG;AAAA,EACb,IAAI,CAAC,KAAK,GAAG;AAAA,EACb,IAAI,CAAC,KAAK,GAAG;AAAA,EACb,QAAQ,CAAC,OAAO,KAAK;AAAA,EACrB,OAAO,CAAC,OAAO,KAAK;AACtB;AAEA,IAAM,iBAAiB;AAEvB,SAAS,YAAY,OAAgB,KAAa,KAAa,UAA0B;AACvF,QAAM,IAAI,OAAO,UAAU,WAAW,QAAQ,OAAO,UAAU,WAAW,OAAO,KAAK,IAAI;AAC1F,SAAO,OAAO,SAAS,CAAC,IAAI,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,MAAM,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI;AACtF;AAGA,SAAS,SAAS,OAAwB;AACxC,SAAO,OAAO,UAAU,WAAW,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,IAAI;AACvF;AAGO,SAAS,YAAY,OAAsC;AAChE,MAAI,QAA8B;AAClC,MAAI,OAAO,UAAU,SAAU,SAAQ,EAAE,MAAM,IAAI,QAAQ,SAAS,KAAK,GAAG,OAAO,GAAG;AAAA,WAC7E,OAAO,UAAU,YAAY,UAAU,MAAM;AACpD,UAAM,QAAQ;AACd,YAAQ;AAAA,MACN,MAAM,SAAS,MAAM,IAAI;AAAA,MACzB,QAAQ,SAAS,MAAM,MAAM;AAAA,MAC7B,OAAO,SAAS,MAAM,KAAK;AAAA,IA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Q,OAAO,IAAI,MAAM;AAC/B,MAAI,CAAC,SAAS,MAAM,UAAU,MAAO;AACrC,QAAM,QAAQ;AACd,SAAO,KAAK;AACd;AAEA,IAAOA,sBAAQ,aAAa;AAAA,EAC1B,MAAM;AAAA,EACN,MAAM,QAAQ;AACZ,UAAM,UAAW,OAAO,QAAQ,eAAe,cAAc,CAAC;AAC9D,UAAM,SAAS,kBAAkB,OAAO;AACxC,WAAO,IAAI,QAAQ,EAAE,SAAS,QAAQ,OAAO,MAAM,WAAW,oBAAI,IAAI,EAAE,CAAC;AACzE,WAAO,GAAG,UAAU,mBAAmB,kBAAG;AAC1C,WAAO,KAAK,UAAU,IAAI,YAAY;AACtC,gBAAY,QAAQ,MAAM;AAC1B,WAAO,MAAM;AACX,aAAO,OAAO,MAAM;AACpB,aAAO,KAAK,UAAU,OAAO,YAAY;AAAA,IAC3C;AAAA,EACF;AAAA,EACA,MAAM,MAAM,OAAO,6BAAiB;AACtC,CAAC;","names":["pagelayout_default"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/html-rules-api.ts
|
|
2
|
+
var OWN_STYLE = "data-nova-own-style";
|
|
3
|
+
var registered = null;
|
|
4
|
+
function registerHtmlRules(module) {
|
|
5
|
+
registered = module;
|
|
6
|
+
}
|
|
7
|
+
var warned = false;
|
|
8
|
+
function htmlRulesFor(options) {
|
|
9
|
+
const needed = !!options.extendedValidElements || !!options.customElements || /\[/.test(options.validElements ?? "");
|
|
10
|
+
if (!needed) return null;
|
|
11
|
+
if (!registered) {
|
|
12
|
+
if (!warned) {
|
|
13
|
+
warned = true;
|
|
14
|
+
console.warn(
|
|
15
|
+
"[nova] attribute lists, extendedValidElements and customElements need: import { htmlRules } from '@novaprose/core/html-rules'; registerHtmlRules(htmlRules);"
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return registered.create(options);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
OWN_STYLE,
|
|
25
|
+
registerHtmlRules,
|
|
26
|
+
htmlRulesFor
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=chunk-OOVNE6MB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/html-rules-api.ts"],"sourcesContent":["import type { MarkSpec, NodeSpec, Schema } from 'prosemirror-model';\n\n/**\n * The hook for element and attribute rules. The implementation is a separate import,\n * `@novaprose/core/html-rules` (~3 KB gzip): few need it, so it isn't part of the first load.\n *\n * import { registerHtmlRules } from '@novaprose/core';\n * import { htmlRules } from '@novaprose/core/html-rules';\n * registerHtmlRules(htmlRules);\n */\n\nexport interface HtmlRulesOptions {\n /** Only these elements are allowed; attributes in [...] are the complete list for the element. */\n validElements?: string;\n /** More elements and attributes: 'div[class],h2[id],i[class],a[href|rel|data-*]'. */\n extendedValidElements?: string;\n /** Disallowed elements. */\n invalidElements?: string;\n /** Your own elements: 'my-widget,~my-chip' (~ — inline, like span; without ~ — a block, like div). */\n customElements?: string;\n}\n\n/** The node and mark specs the document schema is built from; HTML rules change them before that. */\nexport interface SchemaSpecs {\n nodes: Record<string, NodeSpec>;\n marks: Record<string, MarkSpec>;\n}\n\n/** The rules of one editor: they change the schema specs. */\nexport interface HtmlRulesInstance {\n /** Whether the rules allow class on a built-in element (then classes are kept). */\n readonly classOnBuiltIn: boolean;\n /** Specs with the rules applied; after the schema is created, store it in `ref.schema`. */\n apply(specs: SchemaSpecs, ref: { schema?: Schema }): SchemaSpecs;\n}\n\nexport interface HtmlRulesModule {\n create(options: HtmlRulesOptions): HtmlRulesInstance | null;\n}\n\n/** A service attribute: the parser moves the own style of new elements (div, abbr…) here. */\nexport const OWN_STYLE = 'data-nova-own-style';\n\nlet registered: HtmlRulesModule | null = null;\n\n/** Install the element and attribute rules (once per page). */\nexport function registerHtmlRules(module: HtmlRulesModule): void {\n registered = module;\n}\n\nlet warned = false;\n\n/** Rules for the editor's options, or null (the options need no rules / the module isn't attached). */\nexport function htmlRulesFor(options: HtmlRulesOptions): HtmlRulesInstance | null {\n const needed =\n !!options.extendedValidElements ||\n !!options.customElements ||\n /\\[/.test(options.validElements ?? '');\n if (!needed) return null;\n if (!registered) {\n if (!warned) {\n warned = true;\n console.warn(\n \"[nova] attribute lists, extendedValidElements and customElements need: import { htmlRules } from '@novaprose/core/html-rules'; registerHtmlRules(htmlRules);\",\n );\n }\n return null;\n }\n return registered.create(options);\n}\n"],"mappings":";AAyCO,IAAM,YAAY;AAEzB,IAAI,aAAqC;AAGlC,SAAS,kBAAkB,QAA+B;AAC/D,eAAa;AACf;AAEA,IAAI,SAAS;AAGN,SAAS,aAAa,SAAqD;AAChF,QAAM,SACJ,CAAC,CAAC,QAAQ,yBACV,CAAC,CAAC,QAAQ,kBACV,KAAK,KAAK,QAAQ,iBAAiB,EAAE;AACvC,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,CAAC,YAAY;AACf,QAAI,CAAC,QAAQ;AACX,eAAS;AACT,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO,WAAW,OAAO,OAAO;AAClC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/meta.ts"],"sourcesContent":["/**\n * Transaction markers shared by the editor and first-load plugins. A module of its own, so a plugin\n * can read them without importing the editor (and everything it brings) into the server's imports.\n */\n\n/** setContent: a document is loaded, not edited (suggesting mode doesn't track it). */\nexport const SET_CONTENT_META = 'nova:set-content';\n"],"mappings":";AAMO,IAAM,mBAAmB;","names":[]}
|