@novaprose/core 0.6.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 +20 -4
- 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-K2U3VPH2.js → advlist-CEHE6YXS.js} +14 -20
- 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-XWDTLY37.js → autolink-N427KVQO.js} +13 -7
- 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-MWNRUNU3.js → autosave-L7OZ3KLK.js} +9 -13
- 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-ADLYOIB3.js → charmap-5CBBDWOP.js} +9 -14
- 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-3BOK3S3T.js +26 -0
- 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-4VPDY3LF.js +27 -0
- 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-GHEFKKRC.js → chunk-AC3YCAX4.js} +108 -29
- package/dist/chunk-AC3YCAX4.js.map +1 -0
- package/dist/{chunk-NPKAIW34.js → chunk-ADRPQLZ2.js} +50 -1
- 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-DEYYVZ7O.js +393 -0
- 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-GHVB6SV4.js +177 -0
- 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-J6W2CDRF.js +425 -0
- 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-HZRIBOPW.js → chunk-QU3KXMYT.js} +45 -3
- 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-7ON7PR5R.js → chunk-TAM2FHKG.js} +374 -52
- 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/chunk-VK6YF2AA.js +359 -0
- 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-FYJE3U64.js → comments-panel-SOLBZ46Q.js} +12 -6
- package/dist/comments-panel-SOLBZ46Q.js.map +1 -0
- package/dist/{directionality-XOHJFSL6.js → directionality-EGQKGDZA.js} +16 -11
- 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-TP4N4ZGY.js → emoticons-EGHNZKSA.js} +9 -14
- 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 +482 -0
- package/dist/html-rules.cjs.map +1 -0
- package/dist/html-rules.d.cts +89 -0
- package/dist/html-rules.d.ts +89 -0
- package/dist/html-rules.js +417 -0
- package/dist/html-rules.js.map +1 -0
- package/dist/i18n/de.cjs +670 -0
- package/dist/i18n/de.cjs.map +1 -0
- package/dist/i18n/de.d.cts +9 -0
- package/dist/i18n/de.d.ts +9 -0
- package/dist/i18n/de.js +649 -0
- package/dist/i18n/de.js.map +1 -0
- package/dist/i18n/es.cjs +670 -0
- package/dist/i18n/es.cjs.map +1 -0
- package/dist/i18n/es.d.cts +9 -0
- package/dist/i18n/es.d.ts +9 -0
- package/dist/i18n/es.js +649 -0
- package/dist/i18n/es.js.map +1 -0
- package/dist/i18n/fr.cjs +670 -0
- package/dist/i18n/fr.cjs.map +1 -0
- package/dist/i18n/fr.d.cts +9 -0
- package/dist/i18n/fr.d.ts +9 -0
- package/dist/i18n/fr.js +649 -0
- package/dist/i18n/fr.js.map +1 -0
- package/dist/i18n/it.cjs +670 -0
- package/dist/i18n/it.cjs.map +1 -0
- package/dist/i18n/it.d.cts +9 -0
- package/dist/i18n/it.d.ts +9 -0
- package/dist/i18n/it.js +649 -0
- package/dist/i18n/it.js.map +1 -0
- package/dist/i18n/pt-BR.cjs +670 -0
- package/dist/i18n/pt-BR.cjs.map +1 -0
- package/dist/i18n/pt-BR.d.cts +9 -0
- package/dist/i18n/pt-BR.d.ts +9 -0
- package/dist/i18n/pt-BR.js +649 -0
- package/dist/i18n/pt-BR.js.map +1 -0
- package/dist/i18n/ru.cjs +670 -0
- package/dist/i18n/ru.cjs.map +1 -0
- package/dist/i18n/ru.d.cts +10 -0
- package/dist/i18n/ru.d.ts +10 -0
- package/dist/i18n/ru.js +649 -0
- package/dist/i18n/ru.js.map +1 -0
- 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-CZ9yDvmQ.d.cts +235 -0
- package/dist/index-CZ9yDvmQ.d.ts +235 -0
- package/dist/index.cjs +29531 -10134
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +160 -1828
- package/dist/index.d.ts +160 -1828
- package/dist/index.js +212 -1480
- package/dist/index.js.map +1 -1
- package/dist/{insertdatetime-T4SEMQWP.js → insertdatetime-YW2VHYZH.js} +10 -16
- 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 +356 -0
- package/dist/markdown.cjs.map +1 -0
- package/dist/markdown.d.cts +25 -0
- package/dist/markdown.d.ts +25 -0
- package/dist/markdown.js +10 -0
- package/dist/markdown.js.map +1 -0
- 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-HG5HV6AL.js → nonbreaking-GYRUH4UO.js} +10 -9
- 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-3A6KWKCV.js +520 -0
- 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-4NU4SIPL.js → quickbars-UZ2Q67TX.js} +24 -12
- package/dist/quickbars-UZ2Q67TX.js.map +1 -0
- package/dist/{revisionhistory-3YQPLPLM.js → revisionhistory-ACRB23HL.js} +48 -173
- 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-RTAYJOGR.js → visualblocks-O5QW7ZDT.js} +10 -9
- 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 +96 -6
- package/src/style.css +440 -508
- package/dist/advlist-K2U3VPH2.js.map +0 -1
- package/dist/autolink-XWDTLY37.js.map +0 -1
- package/dist/autoresize-UB3GOA6D.js.map +0 -1
- package/dist/autosave-MWNRUNU3.js.map +0 -1
- package/dist/charmap-ADLYOIB3.js.map +0 -1
- package/dist/chunk-435CRWKA.js +0 -983
- package/dist/chunk-435CRWKA.js.map +0 -1
- package/dist/chunk-46RIM5KP.js +0 -5949
- package/dist/chunk-46RIM5KP.js.map +0 -1
- package/dist/chunk-6RJENZXT.js +0 -104
- package/dist/chunk-6RJENZXT.js.map +0 -1
- package/dist/chunk-7ON7PR5R.js.map +0 -1
- package/dist/chunk-GHEFKKRC.js.map +0 -1
- package/dist/chunk-HPLT3XRZ.js.map +0 -1
- package/dist/chunk-HZRIBOPW.js.map +0 -1
- package/dist/chunk-NPKAIW34.js.map +0 -1
- package/dist/chunk-Z3ELZ77W.js.map +0 -1
- package/dist/comments-panel-FYJE3U64.js.map +0 -1
- package/dist/directionality-XOHJFSL6.js.map +0 -1
- package/dist/emoticons-TP4N4ZGY.js.map +0 -1
- package/dist/insertdatetime-T4SEMQWP.js.map +0 -1
- package/dist/nonbreaking-HG5HV6AL.js.map +0 -1
- package/dist/quickbars-4NU4SIPL.js.map +0 -1
- package/dist/revisionhistory-3YQPLPLM.js.map +0 -1
- package/dist/visualblocks-RTAYJOGR.js.map +0 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {
|
|
2
|
+
convertList,
|
|
3
|
+
findParentList,
|
|
4
|
+
nodesOf
|
|
5
|
+
} from "./chunk-AC3YCAX4.js";
|
|
6
|
+
import "./chunk-HNEAVVBC.js";
|
|
7
|
+
import "./chunk-TAM2FHKG.js";
|
|
8
|
+
import "./chunk-XR7CY4NI.js";
|
|
9
|
+
import {
|
|
10
|
+
icons
|
|
11
|
+
} from "./chunk-ADRPQLZ2.js";
|
|
12
|
+
import {
|
|
13
|
+
pickLabels
|
|
14
|
+
} from "./chunk-DEYYVZ7O.js";
|
|
15
|
+
import {
|
|
16
|
+
definePlugin
|
|
17
|
+
} from "./chunk-V7WUHUHM.js";
|
|
18
|
+
import "./chunk-QU3KXMYT.js";
|
|
19
|
+
import "./chunk-G74HNSB6.js";
|
|
20
|
+
import "./chunk-4VPDY3LF.js";
|
|
21
|
+
|
|
22
|
+
// src/plugins/checklist.ts
|
|
23
|
+
import { InputRule, inputRules } from "prosemirror-inputrules";
|
|
24
|
+
import { keymap } from "prosemirror-keymap";
|
|
25
|
+
import { liftListItem, wrapInList } from "prosemirror-schema-list";
|
|
26
|
+
import { Plugin, PluginKey } from "prosemirror-state";
|
|
27
|
+
import { findWrapping } from "prosemirror-transform";
|
|
28
|
+
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
29
|
+
|
|
30
|
+
// nova-raw-css:/home/runner/work/novaprose/novaprose/packages/core/src/plugins/checklist.css?raw
|
|
31
|
+
var checklist_default = '.nova-prosemirror ul[data-type=taskList]{padding-inline-start:.25em;list-style:none}.nova-prosemirror li[data-type=taskItem]{position:relative;padding-inline-start:1.6em}.nova-check{display:inline-flex;position:absolute;top:.22em;inset-inline-start:0;align-items:center;justify-content:center;box-sizing:border-box;width:1.1em;height:1.1em;border:1.5px solid var(--nova-border-strong);border-radius:4px;background:var(--nova-bg);cursor:pointer;user-select:none}.nova-check:hover{border-color:var(--nova-accent)}.nova-check[aria-checked=true]{border-color:var(--nova-accent-strong);background:var(--nova-accent-strong)}.nova-check[aria-checked=true]:after{content:"";width:.28em;height:.55em;margin-top:-.12em;border:solid var(--nova-accent-fg);border-width:0 2px 2px 0;transform:rotate(45deg)}.nova-prosemirror li[data-checked=true]>p{color:var(--nova-muted);text-decoration:line-through}.nova-disabled .nova-check,.nova-readonly .nova-check{cursor:default}';
|
|
32
|
+
|
|
33
|
+
// src/plugins/checklist.ts
|
|
34
|
+
var LABELS = { en: { checklist: "Checklist", done: "Done" } };
|
|
35
|
+
var SHORTCUT = "Mod-Enter";
|
|
36
|
+
function checklistItemAt(state) {
|
|
37
|
+
const { $from } = state.selection;
|
|
38
|
+
const nodes = nodesOf(state);
|
|
39
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
40
|
+
const node = $from.node(depth);
|
|
41
|
+
if (node.type === nodes.list_item && typeof node.attrs.checked === "boolean") {
|
|
42
|
+
return { node, pos: $from.before(depth) };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
function isChecklistActive(state) {
|
|
48
|
+
return findParentList(state)?.node.attrs.checklist === true;
|
|
49
|
+
}
|
|
50
|
+
var toggleChecklist = (state, dispatch) => {
|
|
51
|
+
const nodes = nodesOf(state);
|
|
52
|
+
const list = findParentList(state);
|
|
53
|
+
if (list?.node.attrs.checklist === true) return liftListItem(nodes.list_item)(state, dispatch);
|
|
54
|
+
if (list) {
|
|
55
|
+
if (dispatch) dispatch(convertList(state.tr, list, nodes.bullet_list, true).scrollIntoView());
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return wrapInList(nodes.bullet_list, { checklist: true })(
|
|
59
|
+
state,
|
|
60
|
+
dispatch && ((tr) => {
|
|
61
|
+
const $pos = tr.doc.resolve(tr.mapping.map(state.selection.from));
|
|
62
|
+
for (let depth = $pos.depth; depth > 0; depth--) {
|
|
63
|
+
const node = $pos.node(depth);
|
|
64
|
+
if (node.type === nodes.bullet_list && node.attrs.checklist === true) {
|
|
65
|
+
convertList(tr, { node, pos: $pos.before(depth) }, nodes.bullet_list, true);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
dispatch(tr.scrollIntoView());
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
var toggleChecklistItem = (state, dispatch) => {
|
|
74
|
+
const item = checklistItemAt(state);
|
|
75
|
+
if (!item) return false;
|
|
76
|
+
dispatch?.(
|
|
77
|
+
state.tr.setNodeMarkup(item.pos, void 0, {
|
|
78
|
+
...item.node.attrs,
|
|
79
|
+
checked: !item.node.attrs.checked
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
return true;
|
|
83
|
+
};
|
|
84
|
+
function checklistInputRule() {
|
|
85
|
+
return new InputRule(/^\s*\[([ xX]?)\]\s$/, (state, match, start, end) => {
|
|
86
|
+
const nodes = nodesOf(state);
|
|
87
|
+
const checked = match[1].toLowerCase() === "x";
|
|
88
|
+
const tr = state.tr.delete(start, end);
|
|
89
|
+
const $start = tr.doc.resolve(start);
|
|
90
|
+
const itemDepth = $start.depth - 1;
|
|
91
|
+
if (itemDepth > 0 && $start.node(itemDepth).type === nodes.list_item) {
|
|
92
|
+
if ($start.index(itemDepth) !== 0) return null;
|
|
93
|
+
const list = { node: $start.node(itemDepth - 1), pos: $start.before(itemDepth - 1) };
|
|
94
|
+
if (list.node.type !== nodes.bullet_list && list.node.type !== nodes.ordered_list)
|
|
95
|
+
return null;
|
|
96
|
+
convertList(tr, list, nodes.bullet_list, true);
|
|
97
|
+
const itemPos = $start.before(itemDepth);
|
|
98
|
+
tr.setNodeMarkup(itemPos, void 0, { ...tr.doc.nodeAt(itemPos).attrs, checked });
|
|
99
|
+
return tr;
|
|
100
|
+
}
|
|
101
|
+
const range = $start.blockRange();
|
|
102
|
+
const wrapping = range && findWrapping(range, nodes.bullet_list, { checklist: true }, void 0);
|
|
103
|
+
if (!range || !wrapping) return null;
|
|
104
|
+
wrapping[1] = { type: nodes.list_item, attrs: { checked } };
|
|
105
|
+
tr.wrap(range, wrapping);
|
|
106
|
+
const listPos = range.start;
|
|
107
|
+
const before = tr.doc.resolve(listPos).nodeBefore;
|
|
108
|
+
if (before?.type === nodes.bullet_list && before.attrs.checklist === true) tr.join(listPos);
|
|
109
|
+
return tr;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function checkboxes(editor, label) {
|
|
113
|
+
const key = new PluginKey("nova-checklist");
|
|
114
|
+
const build = (doc) => {
|
|
115
|
+
const decorations = [];
|
|
116
|
+
doc.descendants((node, pos) => {
|
|
117
|
+
if (node.isTextblock) return false;
|
|
118
|
+
if (node.type.name === "list_item" && typeof node.attrs.checked === "boolean") {
|
|
119
|
+
const checked = node.attrs.checked;
|
|
120
|
+
decorations.push(
|
|
121
|
+
Decoration.widget(pos + 1, (view, getPos) => checkbox(view, getPos, checked), {
|
|
122
|
+
side: -1,
|
|
123
|
+
key: `nova-check-${checked}`,
|
|
124
|
+
ignoreSelection: true,
|
|
125
|
+
stopEvent: () => true
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
});
|
|
131
|
+
return DecorationSet.create(doc, decorations);
|
|
132
|
+
};
|
|
133
|
+
const checkbox = (view, getPos, checked) => {
|
|
134
|
+
const box = document.createElement("span");
|
|
135
|
+
box.className = "nova-check";
|
|
136
|
+
box.contentEditable = "false";
|
|
137
|
+
box.setAttribute("role", "checkbox");
|
|
138
|
+
box.setAttribute("aria-checked", String(checked));
|
|
139
|
+
box.setAttribute("aria-label", label);
|
|
140
|
+
box.addEventListener("click", () => {
|
|
141
|
+
if (!editor.isEditable()) return;
|
|
142
|
+
const at = getPos();
|
|
143
|
+
if (at === void 0) return;
|
|
144
|
+
const itemPos = at - 1;
|
|
145
|
+
const node = view.state.doc.nodeAt(itemPos);
|
|
146
|
+
if (node?.type.name !== "list_item" || typeof node.attrs.checked !== "boolean") return;
|
|
147
|
+
view.dispatch(
|
|
148
|
+
view.state.tr.setNodeMarkup(itemPos, void 0, { ...node.attrs, checked: !checked })
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
return box;
|
|
152
|
+
};
|
|
153
|
+
return new Plugin({
|
|
154
|
+
key,
|
|
155
|
+
state: {
|
|
156
|
+
init: (_, state) => build(state.doc),
|
|
157
|
+
apply: (tr, set) => tr.docChanged ? build(tr.doc) : set
|
|
158
|
+
},
|
|
159
|
+
props: { decorations: (state) => key.getState(state) }
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
var checklist_default2 = definePlugin({
|
|
163
|
+
name: "checklist",
|
|
164
|
+
toolbar: "checklist",
|
|
165
|
+
prosemirrorPlugins: (editor) => [
|
|
166
|
+
checkboxes(editor, pickLabels(editor, "checklist", LABELS).done),
|
|
167
|
+
keymap({ [SHORTCUT]: toggleChecklistItem }),
|
|
168
|
+
inputRules({ rules: [checklistInputRule()] })
|
|
169
|
+
],
|
|
170
|
+
setup(editor) {
|
|
171
|
+
editor.ui.addStyles("nova-checklist", checklist_default);
|
|
172
|
+
const labels = pickLabels(editor, "checklist", LABELS);
|
|
173
|
+
editor.ui.registry.addToggleButton("checklist", {
|
|
174
|
+
icon: icons.checklist,
|
|
175
|
+
tooltip: labels.checklist,
|
|
176
|
+
isEnabled: (e) => e.isEditable() && e.isAllowed("checklist"),
|
|
177
|
+
isActive: (e) => isChecklistActive(e.view.state),
|
|
178
|
+
onAction: (e) => e.exec(toggleChecklist)
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
export {
|
|
183
|
+
LABELS,
|
|
184
|
+
checklist_default2 as default,
|
|
185
|
+
isChecklistActive,
|
|
186
|
+
toggleChecklist,
|
|
187
|
+
toggleChecklistItem
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=checklist-HM4VXZKY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugins/checklist.ts","nova-raw-css:/home/runner/work/novaprose/novaprose/packages/core/src/plugins/checklist.css?raw"],"sourcesContent":["import { InputRule, inputRules } from 'prosemirror-inputrules';\nimport { keymap } from 'prosemirror-keymap';\nimport type { Node as PMNode } from 'prosemirror-model';\nimport { liftListItem, wrapInList } from 'prosemirror-schema-list';\nimport { Plugin, PluginKey, type Command, type EditorState } from 'prosemirror-state';\nimport { findWrapping } from 'prosemirror-transform';\nimport { Decoration, DecorationSet, type EditorView } from 'prosemirror-view';\nimport { convertList, findParentList, nodesOf } from '../commands';\nimport type { Editor } from '../editor';\nimport { definePlugin } from '../plugins';\nimport { icons } from '../ui/icons';\nimport css from './checklist.css?raw';\nimport { pickLabels } from './shared';\n\n/**\n * The checklist plugin: task lists with checkboxes. `plugins: ['checklist']`, the `checklist` button\n * (as in TinyMCE). The checklist itself is a bulleted list with a flag (the core schema), so Enter, Tab,\n * indents, paste and Markdown work as with regular lists; the plugin adds the checkboxes,\n * Ctrl/Cmd+Enter, typing `[ ]` / `[x]` at the start of a line, and the styles.\n */\n\nexport const LABELS = { en: { checklist: 'Checklist', done: 'Done' } };\n\nconst SHORTCUT = 'Mod-Enter';\n\n/** The checklist item under the cursor. */\nfunction checklistItemAt(state: EditorState): { node: PMNode; pos: number } | null {\n const { $from } = state.selection;\n const nodes = nodesOf(state);\n for (let depth = $from.depth; depth > 0; depth--) {\n const node = $from.node(depth);\n if (node.type === nodes.list_item && typeof node.attrs.checked === 'boolean') {\n return { node, pos: $from.before(depth) };\n }\n }\n return null;\n}\n\n/** The cursor is in a checklist (to highlight the button). */\nexport function isChecklistActive(state: EditorState): boolean {\n return findParentList(state)?.node.attrs.checklist === true;\n}\n\n/**\n * The \"Checklist\" button: inside a checklist it removes the list; in another list it turns it into a checklist;\n * in text it wraps it into a new checklist.\n */\nexport const toggleChecklist: Command = (state, dispatch) => {\n const nodes = nodesOf(state);\n const list = findParentList(state);\n if (list?.node.attrs.checklist === true) return liftListItem(nodes.list_item)(state, dispatch);\n if (list) {\n if (dispatch) dispatch(convertList(state.tr, list, nodes.bullet_list, true).scrollIntoView());\n return true;\n }\n return wrapInList(nodes.bullet_list, { checklist: true })(\n state,\n dispatch &&\n ((tr) => {\n // New items get checked: false (a list item's default is null).\n const $pos = tr.doc.resolve(tr.mapping.map(state.selection.from));\n for (let depth = $pos.depth; depth > 0; depth--) {\n const node = $pos.node(depth);\n if (node.type === nodes.bullet_list && node.attrs.checklist === true) {\n convertList(tr, { node, pos: $pos.before(depth) }, nodes.bullet_list, true);\n break;\n }\n }\n dispatch(tr.scrollIntoView());\n }),\n );\n};\n\n/** Checks or unchecks the item under the cursor (Ctrl/Cmd+Enter). */\nexport const toggleChecklistItem: Command = (state, dispatch) => {\n const item = checklistItemAt(state);\n if (!item) return false;\n dispatch?.(\n state.tr.setNodeMarkup(item.pos, undefined, {\n ...item.node.attrs,\n checked: !item.node.attrs.checked,\n }),\n );\n return true;\n};\n\n/** `[ ] ` or `[x] ` at the start of a line makes a checklist item (in a regular list the whole list becomes one). */\nfunction checklistInputRule(): InputRule {\n return new InputRule(/^\\s*\\[([ xX]?)\\]\\s$/, (state, match, start, end) => {\n const nodes = nodesOf(state);\n const checked = match[1]!.toLowerCase() === 'x';\n const tr = state.tr.delete(start, end);\n const $start = tr.doc.resolve(start);\n const itemDepth = $start.depth - 1;\n if (itemDepth > 0 && $start.node(itemDepth).type === nodes.list_item) {\n // Only in the item's first line; the list and the item are already in the document after \"[ ] \" is removed.\n if ($start.index(itemDepth) !== 0) return null;\n const list = { node: $start.node(itemDepth - 1), pos: $start.before(itemDepth - 1) };\n if (list.node.type !== nodes.bullet_list && list.node.type !== nodes.ordered_list)\n return null;\n convertList(tr, list, nodes.bullet_list, true);\n const itemPos = $start.before(itemDepth);\n tr.setNodeMarkup(itemPos, undefined, { ...tr.doc.nodeAt(itemPos)!.attrs, checked });\n return tr;\n }\n const range = $start.blockRange();\n const wrapping =\n range && findWrapping(range, nodes.bullet_list, { checklist: true }, undefined);\n if (!range || !wrapping) return null;\n wrapping[1] = { type: nodes.list_item, attrs: { checked } };\n tr.wrap(range, wrapping);\n // Right after another checklist: continue it instead of starting a new one.\n const listPos = range.start;\n const before = tr.doc.resolve(listPos).nodeBefore;\n if (before?.type === nodes.bullet_list && before.attrs.checklist === true) tr.join(listPos);\n return tr;\n });\n}\n\n/** Checkboxes on checklist items: a widget at the start of the item, checked on click. */\nfunction checkboxes(editor: Editor, label: string): Plugin {\n const key = new PluginKey<DecorationSet>('nova-checklist');\n const build = (doc: PMNode): DecorationSet => {\n const decorations: Decoration[] = [];\n doc.descendants((node, pos) => {\n if (node.isTextblock) return false;\n if (node.type.name === 'list_item' && typeof node.attrs.checked === 'boolean') {\n const checked = node.attrs.checked;\n decorations.push(\n Decoration.widget(pos + 1, (view, getPos) => checkbox(view, getPos, checked), {\n side: -1,\n key: `nova-check-${checked}`,\n ignoreSelection: true,\n stopEvent: () => true,\n }),\n );\n }\n return true;\n });\n return DecorationSet.create(doc, decorations);\n };\n const checkbox = (view: EditorView, getPos: () => number | undefined, checked: boolean) => {\n const box = document.createElement('span');\n box.className = 'nova-check';\n box.contentEditable = 'false';\n box.setAttribute('role', 'checkbox');\n box.setAttribute('aria-checked', String(checked));\n box.setAttribute('aria-label', label);\n // On click, without preventDefault on mousedown: cancelling the press confused WebKit, and the next click\n // in the text put the cursor at the start of the document (found by e2e).\n box.addEventListener('click', () => {\n if (!editor.isEditable()) return;\n const at = getPos();\n if (at === undefined) return;\n const itemPos = at - 1;\n const node = view.state.doc.nodeAt(itemPos);\n if (node?.type.name !== 'list_item' || typeof node.attrs.checked !== 'boolean') return;\n view.dispatch(\n view.state.tr.setNodeMarkup(itemPos, undefined, { ...node.attrs, checked: !checked }),\n );\n });\n return box;\n };\n return new Plugin<DecorationSet>({\n key,\n state: {\n init: (_, state) => build(state.doc),\n apply: (tr, set) => (tr.docChanged ? build(tr.doc) : set),\n },\n props: { decorations: (state) => key.getState(state) },\n });\n}\n\nexport default definePlugin({\n name: 'checklist',\n toolbar: 'checklist',\n prosemirrorPlugins: (editor) => [\n checkboxes(editor, pickLabels(editor, 'checklist', LABELS).done),\n keymap({ [SHORTCUT]: toggleChecklistItem }),\n inputRules({ rules: [checklistInputRule()] }),\n ],\n setup(editor) {\n editor.ui.addStyles('nova-checklist', css);\n const labels = pickLabels(editor, 'checklist', LABELS);\n editor.ui.registry.addToggleButton('checklist', {\n icon: icons.checklist,\n tooltip: labels.checklist,\n isEnabled: (e) => e.isEditable() && e.isAllowed('checklist'),\n isActive: (e) => isChecklistActive(e.view.state),\n onAction: (e) => e.exec(toggleChecklist),\n });\n },\n});\n",".nova-prosemirror ul[data-type=taskList]{padding-inline-start:.25em;list-style:none}.nova-prosemirror li[data-type=taskItem]{position:relative;padding-inline-start:1.6em}.nova-check{display:inline-flex;position:absolute;top:.22em;inset-inline-start:0;align-items:center;justify-content:center;box-sizing:border-box;width:1.1em;height:1.1em;border:1.5px solid var(--nova-border-strong);border-radius:4px;background:var(--nova-bg);cursor:pointer;user-select:none}.nova-check:hover{border-color:var(--nova-accent)}.nova-check[aria-checked=true]{border-color:var(--nova-accent-strong);background:var(--nova-accent-strong)}.nova-check[aria-checked=true]:after{content:\"\";width:.28em;height:.55em;margin-top:-.12em;border:solid var(--nova-accent-fg);border-width:0 2px 2px 0;transform:rotate(45deg)}.nova-prosemirror li[data-checked=true]>p{color:var(--nova-muted);text-decoration:line-through}.nova-disabled .nova-check,.nova-readonly .nova-check{cursor:default}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,WAAW,kBAAkB;AACtC,SAAS,cAAc;AAEvB,SAAS,cAAc,kBAAkB;AACzC,SAAS,QAAQ,iBAAiD;AAClE,SAAS,oBAAoB;AAC7B,SAAS,YAAY,qBAAsC;;;ACN3D;;;ADqBO,IAAM,SAAS,EAAE,IAAI,EAAE,WAAW,aAAa,MAAM,OAAO,EAAE;AAErE,IAAM,WAAW;AAGjB,SAAS,gBA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AAA,EACH;AACF,CAAC;","names":["checklist_default"]}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatShortcut,
|
|
3
|
+
h
|
|
4
|
+
} from "./chunk-QU3KXMYT.js";
|
|
5
|
+
|
|
6
|
+
// src/page.ts
|
|
7
|
+
var pages = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
function sourceHTML(editor) {
|
|
9
|
+
return editor.getHTML({ fullPage: pages.get(editor)?.inSource !== false });
|
|
10
|
+
}
|
|
11
|
+
function setSourceHTML(editor, html) {
|
|
12
|
+
editor.setContent(html, { fullPage: pages.get(editor)?.inSource !== false });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/ui/views.ts
|
|
16
|
+
import { DOMSerializer } from "prosemirror-model";
|
|
17
|
+
function isFullscreen(editor) {
|
|
18
|
+
return editor.root.classList.contains("nova-fullscreen");
|
|
19
|
+
}
|
|
20
|
+
function toggleFullscreen(editor, value = !isFullscreen(editor)) {
|
|
21
|
+
editor.root.classList.toggle("nova-fullscreen", value);
|
|
22
|
+
document.documentElement.classList.toggle("nova-fullscreen-lock", value);
|
|
23
|
+
editor.ui.closePopover();
|
|
24
|
+
editor.updateUI();
|
|
25
|
+
editor.focus();
|
|
26
|
+
}
|
|
27
|
+
function openPreview(editor, { doc = editor.view.state.doc, title } = {}) {
|
|
28
|
+
const { t } = editor.ui;
|
|
29
|
+
const content = h("div", { className: "nova-prosemirror nova-preview" });
|
|
30
|
+
content.append(DOMSerializer.fromSchema(editor.schema).serializeFragment(doc.content));
|
|
31
|
+
content.querySelectorAll("a[href]").forEach((a) => {
|
|
32
|
+
a.setAttribute("target", "_blank");
|
|
33
|
+
a.setAttribute("rel", "noopener noreferrer");
|
|
34
|
+
});
|
|
35
|
+
editor.ui.openDialog({
|
|
36
|
+
title: title ?? t("preview"),
|
|
37
|
+
body: content,
|
|
38
|
+
size: "large",
|
|
39
|
+
cancelLabel: t("dialog.close")
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function formatHTML(html) {
|
|
43
|
+
return html.replace(/(<\/(p|h[1-6]|ul|ol|li|blockquote|pre|table|tbody|tr)>|<hr>)/g, "$1\n").replace(/(<(ul|ol|table|tbody|tr|blockquote)( [^>]*)?>)/g, "$1\n").replace(/\n{2,}/g, "\n").trim();
|
|
44
|
+
}
|
|
45
|
+
function openSourceCode(editor) {
|
|
46
|
+
const { t } = editor.ui;
|
|
47
|
+
const original = formatHTML(sourceHTML(editor));
|
|
48
|
+
const textarea = h("textarea", {
|
|
49
|
+
className: "nova-input nova-source",
|
|
50
|
+
spellcheck: "false",
|
|
51
|
+
"aria-label": t("sourceCode"),
|
|
52
|
+
autocomplete: "off",
|
|
53
|
+
rows: "18"
|
|
54
|
+
});
|
|
55
|
+
textarea.value = original;
|
|
56
|
+
editor.ui.openDialog({
|
|
57
|
+
title: t("sourceCode"),
|
|
58
|
+
body: textarea,
|
|
59
|
+
size: "large",
|
|
60
|
+
submitLabel: t("dialog.save"),
|
|
61
|
+
initialFocus: textarea,
|
|
62
|
+
onSubmit: () => {
|
|
63
|
+
if (textarea.value !== original) setSourceHTML(editor, textarea.value);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
var SHORTCUTS = [
|
|
69
|
+
{
|
|
70
|
+
group: "help.formatting",
|
|
71
|
+
rows: [
|
|
72
|
+
{ label: "bold", keys: "Mod-b" },
|
|
73
|
+
{ label: "italic", keys: "Mod-i" },
|
|
74
|
+
{ label: "underline", keys: "Mod-u" },
|
|
75
|
+
{ label: "strike", keys: "Mod-Shift-x" },
|
|
76
|
+
{ label: "code", keys: "Mod-e" },
|
|
77
|
+
{ label: "superscript", keys: "Mod-." },
|
|
78
|
+
{ label: "subscript", keys: "Mod-," },
|
|
79
|
+
{ label: "link", keys: "Mod-k" },
|
|
80
|
+
{ label: "clearFormatting", keys: "Mod-\\" }
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
group: "help.blocks",
|
|
85
|
+
rows: [
|
|
86
|
+
{ label: "paragraph", keys: "Mod-Alt-0" },
|
|
87
|
+
{ label: "h1", keys: "Mod-Alt-1" },
|
|
88
|
+
{ label: "h2", keys: "Mod-Alt-2" },
|
|
89
|
+
{ label: "h3", keys: "Mod-Alt-3" },
|
|
90
|
+
{ label: "bulletList", keys: "Mod-Shift-8" },
|
|
91
|
+
{ label: "orderedList", keys: "Mod-Shift-7" },
|
|
92
|
+
{ label: "alignCenter", keys: "Mod-Shift-e" },
|
|
93
|
+
{ label: "indent", keys: "Mod-]" },
|
|
94
|
+
{ label: "outdent", keys: "Mod-[" }
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
group: "help.editing",
|
|
99
|
+
rows: [
|
|
100
|
+
{ label: "undo", keys: "Mod-z" },
|
|
101
|
+
{ label: "redo", keys: "Mod-Shift-z" },
|
|
102
|
+
{ label: "search.title", keys: "Mod-f" },
|
|
103
|
+
{ label: "pasteAsText", keys: "Mod-Shift-v" },
|
|
104
|
+
{ label: "fullscreen", keys: "Mod-Shift-f" },
|
|
105
|
+
{ label: "help.slash", keys: "/" },
|
|
106
|
+
{ label: "moveBlockUp", keys: "Alt-Shift-ArrowUp" },
|
|
107
|
+
{ label: "moveBlockDown", keys: "Alt-Shift-ArrowDown" }
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
group: "help.navigation",
|
|
112
|
+
rows: [
|
|
113
|
+
{ label: "help.toMenubar", keys: "Alt-F9" },
|
|
114
|
+
{ label: "help.toToolbar", keys: "Alt-F10" },
|
|
115
|
+
{ label: "help.toContextToolbar", keys: "Ctrl-F9" },
|
|
116
|
+
{ label: "help.toEditor", keys: "Escape" },
|
|
117
|
+
{ label: "help.nextCell", keys: "Tab" },
|
|
118
|
+
{ label: "help", keys: "Alt-0" }
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
];
|
|
122
|
+
function openHelp(editor) {
|
|
123
|
+
const { t } = editor.ui;
|
|
124
|
+
const body = h("div", { className: "nova-help" });
|
|
125
|
+
for (const { group, rows } of SHORTCUTS) {
|
|
126
|
+
body.append(
|
|
127
|
+
h(
|
|
128
|
+
"section",
|
|
129
|
+
{},
|
|
130
|
+
h("h3", {}, t(group)),
|
|
131
|
+
// A list, not a table: a screen reader reads each line as "Bold Ctrl+B" instead of naming the
|
|
132
|
+
// row and column of every cell.
|
|
133
|
+
h(
|
|
134
|
+
"ul",
|
|
135
|
+
{ className: "nova-help-list" },
|
|
136
|
+
rows.map(
|
|
137
|
+
({ label, keys }) => h(
|
|
138
|
+
"li",
|
|
139
|
+
{},
|
|
140
|
+
h("span", {}, t(label)),
|
|
141
|
+
" ",
|
|
142
|
+
h("kbd", {}, keys.length === 1 ? keys : formatShortcut(keys))
|
|
143
|
+
)
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
editor.ui.openDialog({ title: t("help"), body, size: "large", cancelLabel: t("dialog.close") });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export {
|
|
153
|
+
pages,
|
|
154
|
+
sourceHTML,
|
|
155
|
+
setSourceHTML,
|
|
156
|
+
isFullscreen,
|
|
157
|
+
toggleFullscreen,
|
|
158
|
+
openPreview,
|
|
159
|
+
formatHTML,
|
|
160
|
+
openSourceCode,
|
|
161
|
+
openHelp
|
|
162
|
+
};
|
|
163
|
+
//# sourceMappingURL=chunk-23ZLVT5D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/page.ts","../src/ui/views.ts"],"sourcesContent":["import type { Editor } from './editor';\nimport type { PageHandler } from './plugins';\n\n/** Each editor's page handler (fullpagehtml): getHTML, setContent and the source code view use it. */\nexport const pages = new WeakMap<Editor, PageHandler>();\n\n/**\n * The HTML the source code view shows: the whole page, or only the content when the page handler\n * says so (fullpagehtml's hideInSourceView).\n */\nexport function sourceHTML(editor: Editor): string {\n return editor.getHTML({ fullPage: pages.get(editor)?.inSource !== false });\n}\n\n/** Takes the source code view's HTML back, the same way it was shown. */\nexport function setSourceHTML(editor: Editor, html: string): void {\n editor.setContent(html, { fullPage: pages.get(editor)?.inSource !== false });\n}\n","import { DOMSerializer, type Node as PMNode } from 'prosemirror-model';\nimport type { Editor } from '../editor';\nimport type { MessageKey } from '../i18n';\nimport { setSourceHTML, sourceHTML } from '../page';\nimport { formatShortcut, h } from './dom';\n\n// ---------- fullscreen ----------\n\nexport function isFullscreen(editor: Editor): boolean {\n return editor.root.classList.contains('nova-fullscreen');\n}\n\n/** The editor on the whole screen; the page under it doesn't scroll. */\nexport function toggleFullscreen(editor: Editor, value = !isFullscreen(editor)): void {\n editor.root.classList.toggle('nova-fullscreen', value);\n document.documentElement.classList.toggle('nova-fullscreen-lock', value);\n editor.ui.closePopover();\n editor.updateUI();\n editor.focus();\n}\n\n// ---------- preview ----------\n\n/**\n * A preview of the result. The DOM is built by the schema's serializer (no HTML string parsing), in\n * a container with the same content styles, without editing. `doc` and `title`: another document\n * to show (for example, the text with every suggestion accepted) under its own title.\n */\nexport function openPreview(\n editor: Editor,\n { doc = editor.view.state.doc, title }: { doc?: PMNode; title?: string } = {},\n): void {\n const { t } = editor.ui;\n const content = h('div', { className: 'nova-prosemirror nova-preview' });\n content.append(DOMSerializer.fromSchema(editor.schema).serializeFragment(doc.content));\n // Links in the preview open in a new tab, so you don't leave the page with unsaved text.\n content.querySelectorAll('a[href]').forEach((a) => {\n a.setAttribute('target', '_blank');\n a.setAttribute('rel', 'noopener noreferrer');\n });\n editor.ui.openDialog({\n title: title ?? t('preview'),\n body: content,\n size: 'large',\n cancelLabel: t('dialog.close'),\n });\n}\n\n// ---------- HTML source ----------\n\n/** Line breaks after block tags, so the HTML is easy to read and edit. */\nexport function formatHTML(html: string): string {\n return html\n .replace(/(<\\/(p|h[1-6]|ul|ol|li|blockquote|pre|table|tbody|tr)>|<hr>)/g, '$1\\n')\n .replace(/(<(ul|ol|table|tbody|tr|blockquote)( [^>]*)?>)/g, '$1\\n')\n .replace(/\\n{2,}/g, '\\n')\n .trim();\n}\n\n/** View and edit the HTML (the code plugin). Saving goes through the schema, with the same cleanup. */\nexport function openSourceCode(editor: Editor): void {\n const { t } = editor.ui;\n const original = formatHTML(sourceHTML(editor));\n const textarea = h('textarea', {\n className: 'nova-input nova-source',\n spellcheck: 'false',\n 'aria-label': t('sourceCode'),\n autocomplete: 'off',\n rows: '18',\n });\n textarea.value = original;\n editor.ui.openDialog({\n title: t('sourceCode'),\n body: textarea,\n size: 'large',\n submitLabel: t('dialog.save'),\n initialFocus: textarea,\n onSubmit: () => {\n if (textarea.value !== original) setSourceHTML(editor, textarea.value);\n return true;\n },\n });\n // Enter in a textarea is a line break, not a form submit (the textarea default).\n}\n\n// ---------- keyboard shortcuts help ----------\n\ninterface ShortcutRow {\n label: MessageKey;\n keys: string;\n}\n\nconst SHORTCUTS: { group: MessageKey; rows: ShortcutRow[] }[] = [\n {\n group: 'help.formatting',\n rows: [\n { label: 'bold', keys: 'Mod-b' },\n { label: 'italic', keys: 'Mod-i' },\n { label: 'underline', keys: 'Mod-u' },\n { label: 'strike', keys: 'Mod-Shift-x' },\n { label: 'code', keys: 'Mod-e' },\n { label: 'superscript', keys: 'Mod-.' },\n { label: 'subscript', keys: 'Mod-,' },\n { label: 'link', keys: 'Mod-k' },\n { label: 'clearFormatting', keys: 'Mod-\\\\' },\n ],\n },\n {\n group: 'help.blocks',\n rows: [\n { label: 'paragraph', keys: 'Mod-Alt-0' },\n { label: 'h1', keys: 'Mod-Alt-1' },\n { label: 'h2', keys: 'Mod-Alt-2' },\n { label: 'h3', keys: 'Mod-Alt-3' },\n { label: 'bulletList', keys: 'Mod-Shift-8' },\n { label: 'orderedList', keys: 'Mod-Shift-7' },\n { label: 'alignCenter', keys: 'Mod-Shift-e' },\n { label: 'indent', keys: 'Mod-]' },\n { label: 'outdent', keys: 'Mod-[' },\n ],\n },\n {\n group: 'help.editing',\n rows: [\n { label: 'undo', keys: 'Mod-z' },\n { label: 'redo', keys: 'Mod-Shift-z' },\n { label: 'search.title', keys: 'Mod-f' },\n { label: 'pasteAsText', keys: 'Mod-Shift-v' },\n { label: 'fullscreen', keys: 'Mod-Shift-f' },\n { label: 'help.slash', keys: '/' },\n { label: 'moveBlockUp', keys: 'Alt-Shift-ArrowUp' },\n { label: 'moveBlockDown', keys: 'Alt-Shift-ArrowDown' },\n ],\n },\n {\n group: 'help.navigation',\n rows: [\n { label: 'help.toMenubar', keys: 'Alt-F9' },\n { label: 'help.toToolbar', keys: 'Alt-F10' },\n { label: 'help.toContextToolbar', keys: 'Ctrl-F9' },\n { label: 'help.toEditor', keys: 'Escape' },\n { label: 'help.nextCell', keys: 'Tab' },\n { label: 'help', keys: 'Alt-0' },\n ],\n },\n];\n\nexport function openHelp(editor: Editor): void {\n const { t } = editor.ui;\n const body = h('div', { className: 'nova-help' });\n for (const { group, rows } of SHORTCUTS) {\n body.append(\n h(\n 'section',\n {},\n h('h3', {}, t(group)),\n // A list, not a table: a screen reader reads each line as \"Bold Ctrl+B\" instead of naming the\n // row and column of every cell.\n h(\n 'ul',\n { className: 'nova-help-list' },\n rows.map(({ label, keys }) =>\n h(\n 'li',\n {},\n h('span', {}, t(label)),\n ' ',\n h('kbd', {}, keys.length === 1 ? keys : formatShortcut(keys)),\n ),\n ),\n ),\n ),\n );\n }\n editor.ui.openDialog({ title: t('help'), body, size: 'large', cancelLabel: t('dialog.close') });\n}\n"],"mappings":";;;;;;AAIO,IAAM,QAAQ,oBAAI,QAA6B;AAM/C,SAAS,WAAW,QAAwB;AACjD,SAAO,OAAO,QAAQ,EAAE,UAAU,MAAM,IAAI,MAAM,GAAG,aAAa,MAAM,CAAC;AAC3E;AAGO,SAAS,cAAc,QAAgB,MAAoB;AAChE,SAAO,WAAW,MAAM,EAAE,UAAU,MAAM,IAAI,MAAM,GAAG,aAAa,MAAM,CAAC;AAC7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;AAAA,cACtB;AAAA,cACA,EAAE,OAAO,CAAC,GAAG,KAAK,WAAW,IAAI,OAAO,eAAe,IAAI,CAAC;AAAA,YAC9D;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO,GAAG,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,MAAM,SAAS,aAAa,EAAE,cAAc,EAAE,CAAC;AAChG;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isSafeImageUrl,
|
|
3
|
+
isSafeLinkUrl
|
|
4
|
+
} from "./chunk-4VPDY3LF.js";
|
|
5
|
+
|
|
6
|
+
// src/safe-attr.ts
|
|
7
|
+
var LINK_ATTRS = /* @__PURE__ */ new Set(["href", "xlink:href", "action", "formaction", "cite"]);
|
|
8
|
+
var RESOURCE_ATTRS = /* @__PURE__ */ new Set(["src", "poster", "data", "background"]);
|
|
9
|
+
var UNSAFE_CSS = /url\s*\(|expression\s*\(|javascript:|@import|behavior\s*:|-moz-binding/i;
|
|
10
|
+
function safeAttr(name, value) {
|
|
11
|
+
const lower = name.toLowerCase();
|
|
12
|
+
if (lower.startsWith("on")) return null;
|
|
13
|
+
if (LINK_ATTRS.has(lower)) return isSafeLinkUrl(value) ? value : null;
|
|
14
|
+
if (RESOURCE_ATTRS.has(lower)) return isSafeImageUrl(value) ? value : null;
|
|
15
|
+
if (lower === "srcset") {
|
|
16
|
+
const urls = value.split(",").map((part) => part.trim().split(/\s+/)[0] ?? "");
|
|
17
|
+
return urls.every((url) => isSafeImageUrl(url)) ? value : null;
|
|
18
|
+
}
|
|
19
|
+
if (lower === "style") return UNSAFE_CSS.test(value) ? null : value;
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
safeAttr
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-3BOK3S3T.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/safe-attr.ts"],"sourcesContent":["import { isSafeImageUrl, isSafeLinkUrl } from './url';\n\n/**\n * Checks an attribute value on output: the last line of defense before HTML goes to the server.\n * Shared by the serializer and the attribute rules (@novaprose/core/html-rules).\n */\nconst LINK_ATTRS = new Set(['href', 'xlink:href', 'action', 'formaction', 'cite']);\nconst RESOURCE_ATTRS = new Set(['src', 'poster', 'data', 'background']);\nconst UNSAFE_CSS = /url\\s*\\(|expression\\s*\\(|javascript:|@import|behavior\\s*:|-moz-binding/i;\n\n/** The attribute value if it is safe, otherwise null (the attribute isn't output). */\nexport function safeAttr(name: string, value: string): string | null {\n const lower = name.toLowerCase();\n if (lower.startsWith('on')) return null;\n if (LINK_ATTRS.has(lower)) return isSafeLinkUrl(value) ? value : null;\n if (RESOURCE_ATTRS.has(lower)) return isSafeImageUrl(value) ? value : null;\n if (lower === 'srcset') {\n const urls = value.split(',').map((part) => part.trim().split(/\\s+/)[0] ?? '');\n return urls.every((url) => isSafeImageUrl(url)) ? value : null;\n }\n if (lower === 'style') return UNSAFE_CSS.test(value) ? null : value;\n return value;\n}\n"],"mappings":";;;;;;AAMA,IAAM,aAAa,oBAAI,IAAI,CAAC,QAAQ,cAAc,UAAU,cAAc,MAAM,CAAC;AACjF,IAAM,iBAAiB,oBAAI,IAAI,CAAC,OAAO,UAAU,QAAQ,YAAY,CAAC;AACtE,IAAM,aAAa;AAGZ,SAAS,SAAS,MAAc,OAA8B;AACnE,QAAM,QAAQ,KAAK,YAAY;AAC/B,MAAI,MAAM,WAAW,IAAI,EAAG,QAAO;AACnC,MAAI,WAAW,IAAI,KAAK,EAAG,QAAO,cAAc,KAAK,IAAI,QAAQ;AACjE,MAAI,eAAe,IAAI,KAAK,EAAG,QAAO,eAAe,KAAK,IAAI,QAAQ;AACtE,MAAI,UAAU,UAAU;AACtB,UAAM,OAAO,MAAM,MAAM,GAAG,EAAE,IAAI,CAAC,SAAS,KAAK,KAAK,EAAE,MAAM,KAAK,EAAE,CAAC,KAAK,EAAE;AAC7E,WAAO,KAAK,MAAM,CAAC,QAAQ,eAAe,GAAG,CAAC,IAAI,QAAQ;AAAA,EAC5D;AACA,MAAI,UAAU,QAAS,QAAO,WAAW,KAAK,KAAK,IAAI,OAAO;AAC9D,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
icons
|
|
3
|
+
} from "./chunk-ADRPQLZ2.js";
|
|
4
|
+
import {
|
|
5
|
+
activeElement,
|
|
6
|
+
formatShortcut,
|
|
7
|
+
h,
|
|
8
|
+
icon
|
|
9
|
+
} from "./chunk-QU3KXMYT.js";
|
|
10
|
+
|
|
11
|
+
// src/ui/menu.ts
|
|
12
|
+
function createMenu(entries, onDone, label) {
|
|
13
|
+
const items = [];
|
|
14
|
+
const menu = h("div", { className: "nova-menu", role: "menu", "aria-label": label });
|
|
15
|
+
const hasChecks = entries.some(
|
|
16
|
+
(e) => (e.type === void 0 || e.type === "item") && e.active !== void 0
|
|
17
|
+
);
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
if (entry.type === "separator") {
|
|
20
|
+
menu.append(h("div", { className: "nova-menu-sep", role: "separator" }));
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (entry.type === "heading") {
|
|
24
|
+
menu.append(h("div", { className: "nova-menu-heading", role: "presentation" }, entry.label));
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const labelEl = h("span", { className: "nova-menu-label" }, entry.label);
|
|
28
|
+
if (entry.labelStyle) labelEl.setAttribute("style", entry.labelStyle);
|
|
29
|
+
const button = h(
|
|
30
|
+
"button",
|
|
31
|
+
{
|
|
32
|
+
type: "button",
|
|
33
|
+
className: "nova-menu-item",
|
|
34
|
+
role: entry.active === void 0 ? "menuitem" : entry.checkbox ? "menuitemcheckbox" : "menuitemradio",
|
|
35
|
+
tabindex: "-1",
|
|
36
|
+
"data-id": entry.id,
|
|
37
|
+
disabled: entry.disabled ?? false,
|
|
38
|
+
...entry.active !== void 0 ? { "aria-checked": String(entry.active) } : {}
|
|
39
|
+
},
|
|
40
|
+
hasChecks ? h("span", { className: "nova-menu-check" }, entry.active ? icon(icons.check) : null) : null,
|
|
41
|
+
entry.icon ? icon(entry.icon) : null,
|
|
42
|
+
labelEl,
|
|
43
|
+
entry.shortcut ? h("kbd", { className: "nova-menu-shortcut" }, formatShortcut(entry.shortcut)) : null
|
|
44
|
+
);
|
|
45
|
+
button.addEventListener("click", () => {
|
|
46
|
+
onDone();
|
|
47
|
+
entry.onSelect();
|
|
48
|
+
});
|
|
49
|
+
items.push(button);
|
|
50
|
+
menu.append(button);
|
|
51
|
+
}
|
|
52
|
+
const enabled = () => items.filter((b) => !b.disabled);
|
|
53
|
+
const focusAt = (index) => {
|
|
54
|
+
const list = enabled();
|
|
55
|
+
if (!list.length) return;
|
|
56
|
+
list[(index + list.length) % list.length].focus();
|
|
57
|
+
};
|
|
58
|
+
menu.addEventListener("keydown", (event) => {
|
|
59
|
+
const list = enabled();
|
|
60
|
+
const current = list.indexOf(activeElement(menu));
|
|
61
|
+
switch (event.key) {
|
|
62
|
+
case "ArrowDown":
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
focusAt(current + 1);
|
|
65
|
+
break;
|
|
66
|
+
case "ArrowUp":
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
focusAt(current - 1);
|
|
69
|
+
break;
|
|
70
|
+
case "Home":
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
focusAt(0);
|
|
73
|
+
break;
|
|
74
|
+
case "End":
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
focusAt(list.length - 1);
|
|
77
|
+
break;
|
|
78
|
+
case "Tab":
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
if (event.key.length === 1 && /\S/.test(event.key)) {
|
|
83
|
+
const char = event.key.toLowerCase();
|
|
84
|
+
const start = current + 1;
|
|
85
|
+
const ordered = [...list.slice(start), ...list.slice(0, start)];
|
|
86
|
+
ordered.find((b) => b.textContent?.trim().toLowerCase().startsWith(char))?.focus();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return menu;
|
|
91
|
+
}
|
|
92
|
+
function focusMenu(menu) {
|
|
93
|
+
const target = menu.querySelector('[aria-checked="true"]:not(:disabled)') ?? menu.querySelector(".nova-menu-item:not(:disabled)");
|
|
94
|
+
target?.focus();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export {
|
|
98
|
+
createMenu,
|
|
99
|
+
focusMenu
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=chunk-4I4AYH2K.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ui/menu.ts"],"sourcesContent":["import { activeElement, formatShortcut, h, icon } from './dom';\nimport { icons } from './icons';\n\nexport interface MenuItem {\n type?: 'item';\n id: string;\n label: string;\n icon?: string;\n shortcut?: string;\n /** Checked (radio/checkbox): a check mark is shown. */\n active?: boolean;\n /** An independent toggle (bold, superscript): menuitemcheckbox rather than radio. */\n checkbox?: boolean;\n disabled?: boolean;\n /** Style of the label, to preview fonts and headings right in the menu. */\n labelStyle?: string;\n onSelect: () => void;\n}\n\nexport interface MenuSeparator {\n type: 'separator';\n}\n\n/** A heading of a group of items (not clickable). */\nexport interface MenuHeading {\n type: 'heading';\n label: string;\n}\n\nexport type MenuEntry = MenuItem | MenuSeparator | MenuHeading;\n\n/**\n * A menu with keyboard navigation per WAI-ARIA: arrows, Home/End, Enter/Space,\n * search by the first letter. The parent Popover handles Escape.\n */\nexport function createMenu(entries: MenuEntry[], onDone: () => void, label: string): HTMLElement {\n const items: HTMLButtonElement[] = [];\n const menu = h('div', { className: 'nova-menu', role: 'menu', 'aria-label': label });\n const hasChecks = entries.some(\n (e) => (e.type === undefined || e.type === 'item') && e.active !== undefined,\n );\n\n for (const entry of entries) {\n if (entry.type === 'separator') {\n menu.append(h('div', { className: 'nova-menu-sep', role: 'separator' }));\n continue;\n }\n if (entry.type === 'heading') {\n menu.append(h('div', { className: 'nova-menu-heading', role: 'presentation' }, entry.label));\n continue;\n }\n const labelEl = h('span', { className: 'nova-menu-label' }, entry.label);\n if (entry.labelStyle) labelEl.setAttribute('style', entry.labelStyle);\n const button = h(\n 'button',\n {\n type: 'button',\n className: 'nova-menu-item',\n role:\n entry.active === undefined\n ? 'menuitem'\n : entry.checkbox\n ? 'menuitemcheckbox'\n : 'menuitemradio',\n tabindex: '-1',\n 'data-id': entry.id,\n disabled: entry.disabled ?? false,\n ...(entry.active !== undefined ? { 'aria-checked': String(entry.active) } : {}),\n },\n hasChecks\n ? h('span', { className: 'nova-menu-check' }, entry.active ? icon(icons.check) : null)\n : null,\n entry.icon ? icon(entry.icon) : null,\n labelEl,\n entry.shortcut\n ? h('kbd', { className: 'nova-menu-shortcut' }, formatShortcut(entry.shortcut))\n : null,\n );\n button.addEventListener('click', () => {\n onDone();\n entry.onSelect();\n });\n items.push(button);\n menu.append(button);\n }\n\n const enabled = () => items.filter((b) => !b.disabled);\n const focusAt = (index: number) => {\n const list = enabled();\n if (!list.length) return;\n list[(index + list.length) % list.length]!.focus();\n };\n\n menu.addEventListener('keydown', (event) => {\n const list = enabled();\n const current = list.indexOf(activeElement(menu) as HTMLButtonElement);\n switch (event.key) {\n case 'ArrowDown':\n event.preventDefault();\n focusAt(current + 1);\n break;\n case 'ArrowUp':\n event.preventDefault();\n focusAt(current - 1);\n break;\n case 'Home':\n event.preventDefault();\n focusAt(0);\n break;\n case 'End':\n event.preventDefault();\n focusAt(list.length - 1);\n break;\n case 'Tab':\n event.preventDefault();\n break;\n default:\n if (event.key.length === 1 && /\\S/.test(event.key)) {\n const char = event.key.toLowerCase();\n const start = current + 1;\n const ordered = [...list.slice(start), ...list.slice(0, start)];\n ordered.find((b) => b.textContent?.trim().toLowerCase().startsWith(char))?.focus();\n }\n }\n });\n\n return menu;\n}\n\n/** Focuses the checked item or the first available one. */\nexport function focusMenu(menu: HTMLElement): void {\n const target =\n menu.querySelector<HTMLButtonElement>('[aria-checked=\"true\"]:not(:disabled)') ??\n menu.querySelector<HTMLButtonElement>('.nova-menu-item:not(:disabled)');\n target?.focus();\n}\n"],"mappings":";;;;;;;;;;;AAmCO,SAAS,WAAW,SAAsB,QAAoB,OAA4B;AAC/F,QAAM,QAA6B,CAAC;AACpC,QAAM,OAAO,EAAE,OAAO,EAAE,WAAW,aAAa,MAAM,QAAQ,cAAc,MAAM,CAAC;AACnF,QAAM,YAAY,QAAQ;AAAA,IACxB,CAAC,OAAO,EAAE,SAAS,UAAa,EAAE,SAAS,WAAW,EAAE,WAAW;AAAA,EACrE;AAEA,aAAW,SAAS,SAAS;AAC3B,QAAI,MAAM,SAAS,aAAa;AAC9B,WAAK,OAAO,EAAE,OAAO,EAAE,WAAW,iBAAiB,MAAM,YAAY,CAAC,CAAC;AACvE;AAAA,IACF;AACA,QAAI,MAAM,SAAS,WAAW;AAC5B,WAAK,OAAO,EAAE,OAAO,EAAE,WAAW,qBAAqB,MAAM,eAAe,GAAG,MAAM,KAAK,CAAC;AAC3F;AAAA,IACF;AACA,UAAM,UAAU,EAAE,QAAQ,EAAE,WAAW,kBAAkB,GAAG,MAAM,KAAK;AACvE,QAAI,MAAM,WAAY,SAAQ,aAAa,SAAS,MAAM,UAAU;AACpE,UAAM,SAAS;AAAA,MACb;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,WAAW;AAAA,QACX,MACE,MAAM,WAAW,SACb,aACA,MAAM,WACJ,qBACA;AAAA,QACR,UAAU;AAAA,QACV,WAAW,MAAM;AAAA,QACjB,UAAU,MAAM,YAAY;AAAA,QAC5B,GAAI,MAAM,WAAW,SAAY,EAAE,gBAAgB,OAAO,MAAM,MAAM,EAAE,IAAI,CAAC;AAAA,MAC/E;AAAA,MACA,YACI,EAAE,QAAQ,EAAE,WAAW,kBAAkB,GAAG,MAAM,SAAS,KAAK,MAAM,KAAK,IAAI,IAAI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C,MAAM,EAAE,aAAa,KAAK,EAAE,YAAY,EAAE,WAAW,IAAI,CAAC,GAAG,MAAM;AAAA,QACnF;AAAA,IACJ;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAGO,SAAS,UAAU,MAAyB;AACjD,QAAM,SACJ,KAAK,cAAiC,sCAAsC,KAC5E,KAAK,cAAiC,gCAAgC;AACxE,UAAQ,MAAM;AAChB;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/url.ts
|
|
2
|
+
var SAFE_LINK_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]);
|
|
3
|
+
var SAFE_IMAGE_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "blob:"]);
|
|
4
|
+
var SAFE_DATA_IMAGE = /^data:image\/(png|jpe?g|gif|webp|avif|bmp);base64,/i;
|
|
5
|
+
function protocolOf(url) {
|
|
6
|
+
if (typeof url !== "string") return null;
|
|
7
|
+
const cleaned = url.replace(/[\u0000- \u007f-\u009f]/g, "");
|
|
8
|
+
const match = cleaned.match(/^([a-z][a-z0-9+.-]*):/i);
|
|
9
|
+
return match ? `${match[1].toLowerCase()}:` : null;
|
|
10
|
+
}
|
|
11
|
+
function isSafeLinkUrl(url) {
|
|
12
|
+
if (typeof url !== "string") return false;
|
|
13
|
+
const protocol = protocolOf(url);
|
|
14
|
+
return protocol === null || SAFE_LINK_PROTOCOLS.has(protocol);
|
|
15
|
+
}
|
|
16
|
+
function isSafeImageUrl(url) {
|
|
17
|
+
if (typeof url !== "string") return false;
|
|
18
|
+
if (SAFE_DATA_IMAGE.test(url.trim())) return true;
|
|
19
|
+
const protocol = protocolOf(url);
|
|
20
|
+
return protocol === null || SAFE_IMAGE_PROTOCOLS.has(protocol);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
isSafeLinkUrl,
|
|
25
|
+
isSafeImageUrl
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-4VPDY3LF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/url.ts"],"sourcesContent":["/**\n * URL checks against XSS (javascript:, vbscript:, data:text/html and the like).\n * Relative addresses and anchors are allowed.\n */\nconst SAFE_LINK_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'tel:']);\nconst SAFE_IMAGE_PROTOCOLS = new Set(['http:', 'https:', 'blob:']);\nconst SAFE_DATA_IMAGE = /^data:image\\/(png|jpe?g|gif|webp|avif|bmp);base64,/i;\n\nfunction protocolOf(url: string): string | null {\n // The document may come from JSON: a number or null instead of a string.\n if (typeof url !== 'string') return null;\n // Strip the control characters and spaces used to disguise \"java\\tscript:\".\n // eslint-disable-next-line no-control-regex\n const cleaned = url.replace(/[\\u0000- \\u007f-\\u009f]/g, '');\n const match = cleaned.match(/^([a-z][a-z0-9+.-]*):/i);\n return match ? `${match[1]!.toLowerCase()}:` : null;\n}\n\nexport function isSafeLinkUrl(url: string): boolean {\n if (typeof url !== 'string') return false;\n const protocol = protocolOf(url);\n return protocol === null || SAFE_LINK_PROTOCOLS.has(protocol);\n}\n\nexport function isSafeImageUrl(url: string): boolean {\n if (typeof url !== 'string') return false;\n if (SAFE_DATA_IMAGE.test(url.trim())) return true;\n const protocol = protocolOf(url);\n return protocol === null || SAFE_IMAGE_PROTOCOLS.has(protocol);\n}\n"],"mappings":";AAIA,IAAM,sBAAsB,oBAAI,IAAI,CAAC,SAAS,UAAU,WAAW,MAAM,CAAC;AAC1E,IAAM,uBAAuB,oBAAI,IAAI,CAAC,SAAS,UAAU,OAAO,CAAC;AACjE,IAAM,kBAAkB;AAExB,SAAS,WAAW,KAA4B;AAE9C,MAAI,OAAO,QAAQ,SAAU,QAAO;AAGpC,QAAM,UAAU,IAAI,QAAQ,4BAA4B,EAAE;AAC1D,QAAM,QAAQ,QAAQ,MAAM,wBAAwB;AACpD,SAAO,QAAQ,GAAG,MAAM,CAAC,EAAG,YAAY,CAAC,MAAM;AACjD;AAEO,SAAS,cAAc,KAAsB;AAClD,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,QAAM,WAAW,WAAW,GAAG;AAC/B,SAAO,aAAa,QAAQ,oBAAoB,IAAI,QAAQ;AAC9D;AAEO,SAAS,eAAe,KAAsB;AACnD,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,MAAI,gBAAgB,KAAK,IAAI,KAAK,CAAC,EAAG,QAAO;AAC7C,QAAM,WAAW,WAAW,GAAG;AAC/B,SAAO,aAAa,QAAQ,qBAAqB,IAAI,QAAQ;AAC/D;","names":[]}
|