@prosekit/extensions 0.14.0 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/dist/{drop-indicator-B_oMfeVP.js → drop-indicator-DJq8pF92.js} +1 -1
  2. package/dist/{drop-indicator-B_oMfeVP.js.map → drop-indicator-DJq8pF92.js.map} +1 -1
  3. package/dist/{file-iLVR0eM0.js → file-upload-I9m1EJAM.js} +1 -1
  4. package/dist/file-upload-I9m1EJAM.js.map +1 -0
  5. package/dist/{index-cp1u4e0e.d.ts → file-upload-dr3IXUty.d.ts} +1 -1
  6. package/dist/file-upload-dr3IXUty.d.ts.map +1 -0
  7. package/dist/{paste-rule-BaDghcaU.js → mark-paste-rule--F1QPUcU.js} +2 -2
  8. package/dist/mark-paste-rule--F1QPUcU.js.map +1 -0
  9. package/dist/{mark-rule-CYe8zk4q.js → mark-rule-Bqdm49Eq.js} +2 -2
  10. package/dist/mark-rule-Bqdm49Eq.js.map +1 -0
  11. package/dist/prosekit-extensions-autocomplete.d.ts +1 -1
  12. package/dist/prosekit-extensions-autocomplete.js +17 -17
  13. package/dist/prosekit-extensions-autocomplete.js.map +1 -1
  14. package/dist/prosekit-extensions-background-color.d.ts +1 -1
  15. package/dist/prosekit-extensions-background-color.js.map +1 -1
  16. package/dist/prosekit-extensions-blockquote.d.ts +13 -13
  17. package/dist/prosekit-extensions-blockquote.d.ts.map +1 -1
  18. package/dist/prosekit-extensions-blockquote.js +6 -5
  19. package/dist/prosekit-extensions-blockquote.js.map +1 -1
  20. package/dist/prosekit-extensions-bold.d.ts +12 -12
  21. package/dist/prosekit-extensions-bold.d.ts.map +1 -1
  22. package/dist/prosekit-extensions-bold.js +1 -1
  23. package/dist/prosekit-extensions-bold.js.map +1 -1
  24. package/dist/prosekit-extensions-code-block.d.ts +53 -36
  25. package/dist/prosekit-extensions-code-block.d.ts.map +1 -1
  26. package/dist/prosekit-extensions-code-block.js +78 -72
  27. package/dist/prosekit-extensions-code-block.js.map +1 -1
  28. package/dist/prosekit-extensions-code.d.ts +12 -12
  29. package/dist/prosekit-extensions-code.d.ts.map +1 -1
  30. package/dist/prosekit-extensions-code.js +1 -1
  31. package/dist/prosekit-extensions-code.js.map +1 -1
  32. package/dist/prosekit-extensions-commit.d.ts +1 -1
  33. package/dist/prosekit-extensions-commit.js +1 -1
  34. package/dist/prosekit-extensions-drop-indicator.js +1 -1
  35. package/dist/prosekit-extensions-enter-rule.d.ts +6 -78
  36. package/dist/prosekit-extensions-enter-rule.d.ts.map +1 -1
  37. package/dist/prosekit-extensions-enter-rule.js +37 -2
  38. package/dist/prosekit-extensions-enter-rule.js.map +1 -0
  39. package/dist/prosekit-extensions-file.d.ts +2 -2
  40. package/dist/prosekit-extensions-file.js +1 -1
  41. package/dist/prosekit-extensions-hard-break.d.ts +7 -7
  42. package/dist/prosekit-extensions-hard-break.d.ts.map +1 -1
  43. package/dist/prosekit-extensions-hard-break.js.map +1 -1
  44. package/dist/prosekit-extensions-heading.d.ts +15 -15
  45. package/dist/prosekit-extensions-heading.d.ts.map +1 -1
  46. package/dist/prosekit-extensions-heading.js +1 -1
  47. package/dist/prosekit-extensions-heading.js.map +1 -1
  48. package/dist/prosekit-extensions-horizontal-rule.d.ts +7 -7
  49. package/dist/prosekit-extensions-horizontal-rule.d.ts.map +1 -1
  50. package/dist/prosekit-extensions-horizontal-rule.js +11 -10
  51. package/dist/prosekit-extensions-horizontal-rule.js.map +1 -1
  52. package/dist/prosekit-extensions-image.d.ts +13 -12
  53. package/dist/prosekit-extensions-image.d.ts.map +1 -1
  54. package/dist/prosekit-extensions-image.js +10 -10
  55. package/dist/prosekit-extensions-image.js.map +1 -1
  56. package/dist/prosekit-extensions-input-rule.js +89 -2
  57. package/dist/prosekit-extensions-input-rule.js.map +1 -0
  58. package/dist/prosekit-extensions-italic.d.ts +12 -12
  59. package/dist/prosekit-extensions-italic.d.ts.map +1 -1
  60. package/dist/prosekit-extensions-italic.js +1 -1
  61. package/dist/prosekit-extensions-italic.js.map +1 -1
  62. package/dist/prosekit-extensions-link.js +4 -4
  63. package/dist/prosekit-extensions-link.js.map +1 -1
  64. package/dist/prosekit-extensions-list.d.ts +26 -26
  65. package/dist/prosekit-extensions-list.d.ts.map +1 -1
  66. package/dist/prosekit-extensions-list.js +27 -27
  67. package/dist/prosekit-extensions-list.js.map +1 -1
  68. package/dist/prosekit-extensions-loro.d.ts +16 -16
  69. package/dist/prosekit-extensions-loro.d.ts.map +1 -1
  70. package/dist/prosekit-extensions-loro.js.map +1 -1
  71. package/dist/prosekit-extensions-mark-rule.js +1 -1
  72. package/dist/prosekit-extensions-math.d.ts +154 -0
  73. package/dist/prosekit-extensions-math.d.ts.map +1 -0
  74. package/dist/prosekit-extensions-math.js +108 -0
  75. package/dist/prosekit-extensions-math.js.map +1 -0
  76. package/dist/prosekit-extensions-mod-click-prevention.js +1 -1
  77. package/dist/prosekit-extensions-paragraph.d.ts +7 -7
  78. package/dist/prosekit-extensions-paragraph.d.ts.map +1 -1
  79. package/dist/prosekit-extensions-paragraph.js.map +1 -1
  80. package/dist/prosekit-extensions-paste-rule.js +1 -1
  81. package/dist/prosekit-extensions-placeholder.d.ts +1 -1
  82. package/dist/prosekit-extensions-placeholder.js +2 -2
  83. package/dist/prosekit-extensions-placeholder.js.map +1 -1
  84. package/dist/prosekit-extensions-readonly.js +1 -1
  85. package/dist/prosekit-extensions-strike.js +1 -1
  86. package/dist/prosekit-extensions-strike.js.map +1 -1
  87. package/dist/prosekit-extensions-table.d.ts +47 -47
  88. package/dist/prosekit-extensions-table.d.ts.map +1 -1
  89. package/dist/prosekit-extensions-table.js +1 -1
  90. package/dist/prosekit-extensions-text-align.d.ts +1 -1
  91. package/dist/prosekit-extensions-text-color.d.ts +1 -1
  92. package/dist/prosekit-extensions-text-color.js.map +1 -1
  93. package/dist/prosekit-extensions-virtual-selection.js +1 -1
  94. package/dist/prosekit-extensions-yjs.d.ts +3 -3
  95. package/dist/prosekit-extensions-yjs.d.ts.map +1 -1
  96. package/dist/prosekit-extensions-yjs.js.map +1 -1
  97. package/dist/shiki-highlighter-chunk.d.ts +19 -2
  98. package/dist/shiki-highlighter-chunk.d.ts.map +1 -0
  99. package/dist/{table-4oHfV-Ql.js → table-B81i9oH9.js} +29 -29
  100. package/dist/table-B81i9oH9.js.map +1 -0
  101. package/package.json +22 -10
  102. package/src/autocomplete/autocomplete-helpers.ts +1 -1
  103. package/src/autocomplete/autocomplete-plugin.ts +2 -2
  104. package/src/autocomplete/autocomplete-rule.ts +1 -1
  105. package/src/autocomplete/autocomplete.spec.ts +4 -4
  106. package/src/autocomplete/autocomplete.ts +2 -2
  107. package/src/autocomplete/index.ts +2 -2
  108. package/src/background-color/background-color-commands.spec.ts +1 -1
  109. package/src/background-color/background-color-commands.ts +1 -1
  110. package/src/background-color/background-color-spec.spec.ts +1 -1
  111. package/src/background-color/background-color.ts +2 -2
  112. package/src/background-color/index.ts +3 -3
  113. package/src/blockquote/blockquote-input-rule.ts +1 -1
  114. package/src/blockquote/blockquote-keymap.spec.ts +1 -1
  115. package/src/blockquote/blockquote-keymap.ts +9 -7
  116. package/src/blockquote/blockquote.ts +4 -4
  117. package/src/blockquote/index.ts +5 -5
  118. package/src/bold/bold-input-rule.spec.ts +2 -2
  119. package/src/bold/bold-input-rule.ts +1 -1
  120. package/src/bold/bold.ts +4 -4
  121. package/src/bold/index.ts +5 -5
  122. package/src/code/code-input-rule.ts +1 -1
  123. package/src/code/code.ts +4 -4
  124. package/src/code/index.ts +5 -5
  125. package/src/code-block/code-block-commands.ts +1 -1
  126. package/src/code-block/code-block-highlight.ts +11 -1
  127. package/src/code-block/code-block-input-rule.ts +3 -3
  128. package/src/code-block/code-block-shiki.ts +13 -5
  129. package/src/code-block/code-block-spec.spec.ts +2 -2
  130. package/src/code-block/code-block-spec.ts +1 -1
  131. package/src/code-block/code-block.ts +4 -4
  132. package/src/code-block/index.ts +9 -9
  133. package/src/code-block/shiki-highlighter.ts +2 -2
  134. package/src/code-block/shiki-parser.ts +2 -2
  135. package/src/drop-cursor/index.ts +1 -1
  136. package/src/drop-indicator/drop-indicator.ts +1 -1
  137. package/src/drop-indicator/index.ts +1 -1
  138. package/src/enter-rule/index.ts +18 -191
  139. package/src/file/file-drop-handler.ts +1 -1
  140. package/src/file/file-paste-handler.spec.ts +3 -3
  141. package/src/file/file-paste-handler.ts +1 -1
  142. package/src/file/index.ts +3 -3
  143. package/src/gap-cursor/index.ts +1 -1
  144. package/src/hard-break/hard-break-keymap.spec.ts +2 -2
  145. package/src/hard-break/hard-break-keymap.ts +1 -1
  146. package/src/hard-break/hard-break.ts +3 -3
  147. package/src/hard-break/index.ts +4 -4
  148. package/src/heading/heading-commands.ts +1 -1
  149. package/src/heading/heading-input-rule.ts +2 -2
  150. package/src/heading/heading-keymap.spec.ts +1 -1
  151. package/src/heading/heading-spec.ts +1 -1
  152. package/src/heading/heading.ts +4 -4
  153. package/src/heading/index.ts +6 -6
  154. package/src/horizontal-rule/horizontal-rule-commands.spec.ts +1 -1
  155. package/src/horizontal-rule/horizontal-rule-commands.ts +13 -11
  156. package/src/horizontal-rule/horizontal-rule-input-rule.spec.ts +2 -2
  157. package/src/horizontal-rule/horizontal-rule-input-rule.ts +1 -1
  158. package/src/horizontal-rule/horizontal-rule.ts +3 -3
  159. package/src/horizontal-rule/index.ts +4 -4
  160. package/src/image/image-commands/insert-image.ts +1 -1
  161. package/src/image/image-commands/upload-image.spec.ts +4 -4
  162. package/src/image/image-commands/upload-image.ts +2 -2
  163. package/src/image/image-commands.ts +3 -3
  164. package/src/image/image-upload-handler.ts +2 -2
  165. package/src/image/image.ts +2 -2
  166. package/src/image/index.ts +6 -6
  167. package/src/italic/index.ts +5 -5
  168. package/src/italic/italic-commands.spec.ts +4 -4
  169. package/src/italic/italic-input-rule.spec.ts +2 -2
  170. package/src/italic/italic-input-rule.ts +1 -1
  171. package/src/italic/italic.ts +4 -4
  172. package/src/link/index.spec.ts +2 -2
  173. package/src/link/index.ts +6 -6
  174. package/src/link/link-paste-rule.spec.ts +2 -2
  175. package/src/link/link-paste-rule.ts +3 -3
  176. package/src/link/link-regex.spec.ts +1 -1
  177. package/src/list/index.ts +8 -8
  178. package/src/list/list-drop-indicator.ts +2 -2
  179. package/src/list/list-input-rules.ts +1 -1
  180. package/src/list/list-keymap.spec.ts +1 -1
  181. package/src/list/list-spec.ts +1 -1
  182. package/src/list/list-types.spec.ts +2 -2
  183. package/src/list/list.spec.ts +6 -6
  184. package/src/list/list.ts +7 -7
  185. package/src/loro/index.ts +6 -6
  186. package/src/loro/loro.ts +5 -5
  187. package/src/mark-rule/apply.ts +2 -2
  188. package/src/mark-rule/index.ts +2 -2
  189. package/src/mark-rule/mark-rule.spec.ts +4 -4
  190. package/src/mark-rule/mark-rule.ts +2 -2
  191. package/src/math/index.ts +22 -0
  192. package/src/math/math-block.ts +96 -0
  193. package/src/math/math-inline.ts +89 -0
  194. package/src/math/math-plugin.ts +8 -0
  195. package/src/math/math.ts +39 -0
  196. package/src/paragraph/index.ts +7 -7
  197. package/src/paragraph/paragraph-keymap.ts +1 -1
  198. package/src/paragraph/paragraph.ts +3 -3
  199. package/src/paste-rule/index.ts +2 -2
  200. package/src/paste-rule/mark-paste-rule.spec.ts +8 -8
  201. package/src/paste-rule/mark-paste-rule.ts +2 -2
  202. package/src/paste-rule/paste-rule.spec.ts +2 -2
  203. package/src/paste-rule/paste-rule.ts +1 -1
  204. package/src/paste-rule/split-text-by-regex.spec.ts +1 -1
  205. package/src/placeholder/index.ts +1 -1
  206. package/src/strike/index.ts +1 -1
  207. package/src/table/index.ts +14 -14
  208. package/src/table/table-commands/delete-cell-selection.spec.ts +3 -3
  209. package/src/table/table-commands/exit-table.spec.ts +2 -2
  210. package/src/table/table-commands/insert-table.spec.ts +1 -1
  211. package/src/table/table-commands/move-table-column.spec.ts +2 -2
  212. package/src/table/table-commands/move-table-row.spec.ts +2 -2
  213. package/src/table/table-commands/select-table-cell.spec.ts +3 -3
  214. package/src/table/table-commands/select-table-cell.ts +1 -1
  215. package/src/table/table-commands/select-table-column.spec.ts +2 -2
  216. package/src/table/table-commands/select-table-column.ts +1 -1
  217. package/src/table/table-commands/select-table-row.spec.ts +2 -2
  218. package/src/table/table-commands/select-table-row.ts +1 -1
  219. package/src/table/table-commands/select-table.spec.ts +2 -2
  220. package/src/table/table-commands/select-table.ts +1 -1
  221. package/src/table/table-commands.ts +9 -9
  222. package/src/table/table-drop-indicator.ts +2 -2
  223. package/src/table/table-spec.spec.ts +4 -4
  224. package/src/table/table.ts +4 -4
  225. package/src/table/test-utils.ts +1 -1
  226. package/src/testing/index.ts +25 -22
  227. package/src/testing/katex.ts +9 -0
  228. package/src/text-color/index.ts +3 -3
  229. package/src/text-color/text-color-commands.spec.ts +1 -1
  230. package/src/text-color/text-color-commands.ts +1 -1
  231. package/src/text-color/text-color-spec.spec.ts +1 -1
  232. package/src/text-color/text-color.ts +2 -2
  233. package/src/yjs/index.ts +7 -7
  234. package/src/yjs/yjs-cursor-plugin.ts +1 -1
  235. package/src/yjs/yjs-types.ts +0 -2
  236. package/src/yjs/yjs-undo-plugin.ts +3 -2
  237. package/src/yjs/yjs.ts +6 -6
  238. package/dist/enter-rule-D-p4ykfv.js +0 -96
  239. package/dist/enter-rule-D-p4ykfv.js.map +0 -1
  240. package/dist/file-iLVR0eM0.js.map +0 -1
  241. package/dist/index-cp1u4e0e.d.ts.map +0 -1
  242. package/dist/input-rule-COGr_GBb.js +0 -90
  243. package/dist/input-rule-COGr_GBb.js.map +0 -1
  244. package/dist/mark-rule-CYe8zk4q.js.map +0 -1
  245. package/dist/paste-rule-BaDghcaU.js.map +0 -1
  246. package/dist/shiki-highlighter-chunk-DNNm2Vow.d.ts +0 -19
  247. package/dist/shiki-highlighter-chunk-DNNm2Vow.d.ts.map +0 -1
  248. package/dist/table-4oHfV-Ql.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { r as ShikiHighlighterOptions } from "./shiki-highlighter-chunk-DNNm2Vow.js";
1
+ import { ShikiHighlighterOptions } from "./shiki-highlighter-chunk.js";
2
2
  import { Extension, PlainExtension, Union } from "@prosekit/core";
3
3
  import { Parser } from "prosemirror-highlight";
4
4
  import { BundledLanguage as ShikiBundledLanguage, BundledLanguageInfo as ShikiBundledLanguageInfo, BundledTheme as ShikiBundledTheme, BundledThemeInfo as ShikiBundledThemeInfo, SpecialLanguage, bundledLanguagesInfo as shikiBundledLanguagesInfo, bundledThemesInfo as shikiBundledThemesInfo } from "shiki";
@@ -32,40 +32,6 @@ type CodeBlockCommandsExtension = Extension<{
32
32
  */
33
33
  declare function defineCodeBlockCommands(): CodeBlockCommandsExtension;
34
34
  //#endregion
35
- //#region src/code-block/code-block-spec.d.ts
36
- /**
37
- * @internal
38
- */
39
- type CodeBlockSpecExtension = Extension<{
40
- Nodes: {
41
- codeBlock: CodeBlockAttrs;
42
- };
43
- }>;
44
- /**
45
- * Defines the `codeBlock` node spec.
46
- *
47
- * @public
48
- */
49
- declare function defineCodeBlockSpec(): CodeBlockSpecExtension;
50
- //#endregion
51
- //#region src/code-block/code-block.d.ts
52
- /**
53
- * @internal
54
- */
55
- type CodeBlockExtension = Union<[CodeBlockSpecExtension, CodeBlockCommandsExtension]>;
56
- /**
57
- * Adds `codeBlock` nodes to the editor. This includes the following extensions:
58
- *
59
- * - {@link defineCodeBlockSpec}
60
- * - {@link defineCodeBlockInputRule}
61
- * - {@link defineCodeBlockEnterRule}
62
- * - {@link defineCodeBlockKeymap}
63
- * - {@link defineCodeBlockCommands}.
64
- *
65
- * @public
66
- */
67
- declare function defineCodeBlock(): CodeBlockExtension;
68
- //#endregion
69
35
  //#region src/code-block/code-block-highlight.d.ts
70
36
  /**
71
37
  * @public
@@ -77,7 +43,16 @@ type HighlightParser = Parser;
77
43
  * @public
78
44
  */
79
45
  type CodeBlockHighlightOptions = {
46
+ /**
47
+ * A parser instance from the `prosemirror-highlight` package.
48
+ */
80
49
  parser: HighlightParser;
50
+ /**
51
+ * ProseMirror node types to highlight.
52
+ *
53
+ * @default ['codeBlock', 'mathBlock']
54
+ */
55
+ nodeTypes?: string[];
81
56
  };
82
57
  /**
83
58
  * Adds syntax highlighting to code blocks. This function requires a `Parser`
@@ -90,7 +65,8 @@ type CodeBlockHighlightOptions = {
90
65
  * @public
91
66
  */
92
67
  declare function defineCodeBlockHighlight({
93
- parser
68
+ parser,
69
+ nodeTypes
94
70
  }: CodeBlockHighlightOptions): Extension;
95
71
  //#endregion
96
72
  //#region src/code-block/code-block-input-rule.d.ts
@@ -120,6 +96,12 @@ declare function defineCodeBlockKeymap(): PlainExtension;
120
96
  * @public
121
97
  */
122
98
  interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {
99
+ /**
100
+ * ProseMirror node types to highlight.
101
+ *
102
+ * @default ['codeBlock', 'mathBlock']
103
+ */
104
+ nodeTypes?: string[];
123
105
  /**
124
106
  * A list of Shiki themes to pre-load. The first theme in the list will be
125
107
  * used to render the code block.
@@ -151,10 +133,45 @@ interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' |
151
133
  * @public
152
134
  */
153
135
  declare function defineCodeBlockShiki({
136
+ nodeTypes,
154
137
  themes,
155
138
  langs,
156
139
  ...rest
157
140
  }?: CodeBlockShikiOptions): Extension;
158
141
  //#endregion
142
+ //#region src/code-block/code-block-spec.d.ts
143
+ /**
144
+ * @internal
145
+ */
146
+ type CodeBlockSpecExtension = Extension<{
147
+ Nodes: {
148
+ codeBlock: CodeBlockAttrs;
149
+ };
150
+ }>;
151
+ /**
152
+ * Defines the `codeBlock` node spec.
153
+ *
154
+ * @public
155
+ */
156
+ declare function defineCodeBlockSpec(): CodeBlockSpecExtension;
157
+ //#endregion
158
+ //#region src/code-block/code-block.d.ts
159
+ /**
160
+ * @internal
161
+ */
162
+ type CodeBlockExtension = Union<[CodeBlockSpecExtension, CodeBlockCommandsExtension]>;
163
+ /**
164
+ * Adds `codeBlock` nodes to the editor. This includes the following extensions:
165
+ *
166
+ * - {@link defineCodeBlockSpec}
167
+ * - {@link defineCodeBlockInputRule}
168
+ * - {@link defineCodeBlockEnterRule}
169
+ * - {@link defineCodeBlockKeymap}
170
+ * - {@link defineCodeBlockCommands}.
171
+ *
172
+ * @public
173
+ */
174
+ declare function defineCodeBlock(): CodeBlockExtension;
175
+ //#endregion
159
176
  export { type CodeBlockAttrs, type CodeBlockCommandsExtension, type CodeBlockExtension, type CodeBlockHighlightOptions, type CodeBlockSpecExtension, type HighlightParser, type ShikiBundledLanguage, type ShikiBundledLanguageInfo, type ShikiBundledTheme, type ShikiBundledThemeInfo, defineCodeBlock, defineCodeBlockCommands, defineCodeBlockEnterRule, defineCodeBlockHighlight, defineCodeBlockInputRule, defineCodeBlockKeymap, defineCodeBlockShiki, defineCodeBlockSpec, shikiBundledLanguagesInfo, shikiBundledThemesInfo };
160
177
  //# sourceMappingURL=prosekit-extensions-code-block.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-code-block.d.ts","names":[],"sources":["../src/code-block/code-block-types.ts","../src/code-block/code-block-commands.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts","../src/code-block/code-block-highlight.ts","../src/code-block/code-block-input-rule.ts","../src/code-block/code-block-keymap.ts","../src/code-block/code-block-shiki.ts"],"mappings":";;;;;;;;;;;UAKiB,cAAA;EACf,QAAA;AAAA;;;;;;KCCU,0BAAA,GAA6B,SAAA;EACvC,QAAA;IACE,YAAA,GAAe,KAAA,GAAQ,cAAA;IACvB,eAAA,GAAkB,KAAA,GAAQ,cAAA;IAC1B,eAAA,GAAkB,KAAA,GAAQ,cAAA;IAC1B,iBAAA,GAAoB,KAAA,EAAO,cAAA;EAAA;AAAA;;AAL/B;;;;iBAcgB,uBAAA,CAAA,GAA2B,0BAAA;;;;;;KCd/B,sBAAA,GAAyB,SAAA;EACnC,KAAA;IACE,SAAA,EAAW,cAAA;EAAA;AAAA;;;;;ADFf;iBCWgB,mBAAA,CAAA,GAAuB,sBAAA;;;;;;KCR3B,kBAAA,GAAqB,KAAA,EAC9B,sBAAA,EAAwB,0BAAA;;;;;AFJ3B;;;;;;;iBEkBgB,eAAA,CAAA,GAAmB,kBAAA;;;;;;;AHpBnC;KIGY,eAAA,GAAkB,MAAA;;;;KAKlB,yBAAA;EACV,MAAA,EAAQ,eAAA;AAAA;AHPV;;;;;;;;;;AAAA,iBGoBgB,wBAAA,CAAA;EACd;AAAA,GACC,yBAAA,GAA4B,SAAA;;;;;;;;iBCjBf,wBAAA,CAAA,GAA4B,cAAA;;;;;;iBAa5B,wBAAA,CAAA,GAA4B,cAAA;;;;;;iBCnB5B,qBAAA,CAAA,GAAyB,cAAA;;;;;ANDzC;;;UOQiB,qBAAA,SAA8B,IAAA,CAAK,uBAAA;EPP1C;;;;ACCV;;EMaE,MAAA,GAAS,iBAAA;ENXgB;;;;;EMkBzB,KAAA,IAAS,oBAAA,GAAuB,eAAA;ENpBgB;;;EMyBhD,MAAA,GAAS,uBAAA;AAAA;;;;;;;;;;;;;iBAeK,oBAAA,CAAA;EACd,MAAA;EACA,KAAA;EAAA,GACG;AAAA,IACF,qBAAA,GAA6B,SAAA"}
1
+ {"version":3,"file":"prosekit-extensions-code-block.d.ts","names":[],"sources":["../src/code-block/code-block-types.ts","../src/code-block/code-block-commands.ts","../src/code-block/code-block-highlight.ts","../src/code-block/code-block-input-rule.ts","../src/code-block/code-block-keymap.ts","../src/code-block/code-block-shiki.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts"],"mappings":";;;;;;;;;;;UAKiB,cAAA;EACf,QAAA;AAAA;;;;;;KCCU,0BAAA,GAA6B,SAAA;EACvC,QAAA;IACE,YAAA,GAAe,KAAA,GAAQ,cAAA;IACvB,eAAA,GAAkB,KAAA,GAAQ,cAAA;IAC1B,eAAA,GAAkB,KAAA,GAAQ,cAAA;IAC1B,iBAAA,GAAoB,KAAA,EAAO,cAAA;EAAA;AAAA;;AAL/B;;;;iBAcgB,uBAAA,CAAA,GAA2B,0BAAA;;;;;;;ADhB3C;KEGY,eAAA,GAAkB,MAAA;;;;KAKlB,yBAAA;;;ADNZ;ECUE,MAAA,EAAQ,eAAA;;;;;;EAMR,SAAA;AAAA;;;;;;;;;;;iBAac,wBAAA,CAAA;EACd,MAAA;EACA;AAAA,GACC,yBAAA,GAA4B,SAAA;;;;;;;;iBC3Bf,wBAAA,CAAA,GAA4B,cAAA;;;;;;iBAa5B,wBAAA,CAAA,GAA4B,cAAA;;;;;;iBCnB5B,qBAAA,CAAA,GAAyB,cAAA;;;;;AJDzC;;;UKQiB,qBAAA,SAA8B,IAAA,CAAK,uBAAA;ELP1C;;;;ACCV;EIYE,SAAA;;;;;;;EAQA,MAAA,GAAS,iBAAA;EJpBuC;;;;;EI2BhD,KAAA,IAAS,oBAAA,GAAuB,eAAA;EJxB9B;;;EI6BF,MAAA,GAAS,uBAAA;AAAA;;;;;;;AJlBX;;;;;;iBIiCgB,oBAAA,CAAA;EACd,SAAA;EACA,MAAA;EACA,KAAA;EAAA,GACG;AAAA,IACF,qBAAA,GAA6B,SAAA;;;;;;KCpDpB,sBAAA,GAAyB,SAAA;EACnC,KAAA;IACE,SAAA,EAAW,cAAA;EAAA;AAAA;;;;;ALFf;iBKWgB,mBAAA,CAAA,GAAuB,sBAAA;;;;;;KCR3B,kBAAA,GAAqB,KAAA,EAC9B,sBAAA,EAAwB,0BAAA;;;;;ANJ3B;;;;;;;iBMkBgB,eAAA,CAAA,GAAmB,kBAAA"}
@@ -1,7 +1,7 @@
1
- import { i as defineTextBlockInputRule } from "./input-rule-COGr_GBb.js";
2
- import { n as defineTextBlockEnterRule } from "./enter-rule-D-p4ykfv.js";
3
- import { defaultBlockAt, defineCommands, defineKeymap, defineNodeSpec, definePlugin, insertNode, setBlockType, setNodeAttrs, toggleNode, union } from "@prosekit/core";
1
+ import { defineTextBlockInputRule } from "./prosekit-extensions-input-rule.js";
2
+ import { defineTextBlockEnterRule } from "./prosekit-extensions-enter-rule.js";
4
3
  import { TextSelection } from "@prosekit/pm/state";
4
+ import { defaultBlockAt, defineCommands, defineKeymap, defineNodeSpec, definePlugin, insertNode, setBlockType, setNodeAttrs, toggleNode, union } from "@prosekit/core";
5
5
  import { createHighlightPlugin } from "prosemirror-highlight";
6
6
  import { createParser } from "prosemirror-highlight/shiki";
7
7
  import { bundledLanguagesInfo as shikiBundledLanguagesInfo, bundledThemesInfo as shikiBundledThemesInfo } from "shiki";
@@ -41,6 +41,25 @@ function defineCodeBlockCommands() {
41
41
  });
42
42
  }
43
43
 
44
+ //#endregion
45
+ //#region src/code-block/code-block-highlight.ts
46
+ /**
47
+ * Adds syntax highlighting to code blocks. This function requires a `Parser`
48
+ * instance from the `prosemirror-highlight` package. See the
49
+ * [documentation](https://github.com/ocavue/prosemirror-highlight) for more
50
+ * information.
51
+ *
52
+ * @param options
53
+ *
54
+ * @public
55
+ */
56
+ function defineCodeBlockHighlight({ parser, nodeTypes = ["codeBlock", "mathBlock"] }) {
57
+ return definePlugin(createHighlightPlugin({
58
+ parser,
59
+ nodeTypes
60
+ }));
61
+ }
62
+
44
63
  //#endregion
45
64
  //#region src/code-block/code-block-input-rule.ts
46
65
  /**
@@ -108,6 +127,62 @@ const existCodeBlock = (state, dispatch) => {
108
127
  return false;
109
128
  };
110
129
 
130
+ //#endregion
131
+ //#region src/code-block/shiki-highlighter.ts
132
+ let loaded;
133
+ async function load() {
134
+ const { createOrGetHighlighter } = await import("./shiki-highlighter-chunk.js");
135
+ loaded = createOrGetHighlighter;
136
+ }
137
+ function createOrGetHighlighter(options) {
138
+ if (!loaded) return { promise: load() };
139
+ return loaded(options);
140
+ }
141
+
142
+ //#endregion
143
+ //#region src/code-block/shiki-parser.ts
144
+ /**
145
+ * @internal
146
+ */
147
+ function createLazyParser(highlighterOptions) {
148
+ let parser;
149
+ return function lazyParser(options) {
150
+ const language = options.language || "";
151
+ const { highlighter, promise } = createOrGetHighlighter({
152
+ ...highlighterOptions,
153
+ langs: [language]
154
+ });
155
+ if (!highlighter) return promise;
156
+ if (!parser) parser = createParser(highlighter, { theme: highlighterOptions.themes[0] });
157
+ return parser(options);
158
+ };
159
+ }
160
+
161
+ //#endregion
162
+ //#region src/code-block/code-block-shiki.ts
163
+ /**
164
+ * Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.
165
+ *
166
+ * It will set two CSS variables on the code block elements:
167
+ *
168
+ * - `--prosemirror-highlight`: sets text color
169
+ * - `--prosemirror-highlight-bg`: sets background color
170
+ *
171
+ * @param options - The options to configure the Shiki highlighter.
172
+ *
173
+ * @public
174
+ */
175
+ function defineCodeBlockShiki({ nodeTypes, themes = ["one-dark-pro"], langs = ["text"], ...rest } = {}) {
176
+ return defineCodeBlockHighlight({
177
+ parser: createLazyParser({
178
+ themes,
179
+ langs,
180
+ ...rest
181
+ }),
182
+ nodeTypes
183
+ });
184
+ }
185
+
111
186
  //#endregion
112
187
  //#region src/code-block/code-block-spec.ts
113
188
  /**
@@ -174,75 +249,6 @@ function defineCodeBlock() {
174
249
  return union(defineCodeBlockSpec(), defineCodeBlockInputRule(), defineCodeBlockEnterRule(), defineCodeBlockKeymap(), defineCodeBlockCommands());
175
250
  }
176
251
 
177
- //#endregion
178
- //#region src/code-block/code-block-highlight.ts
179
- /**
180
- * Adds syntax highlighting to code blocks. This function requires a `Parser`
181
- * instance from the `prosemirror-highlight` package. See the
182
- * [documentation](https://github.com/ocavue/prosemirror-highlight) for more
183
- * information.
184
- *
185
- * @param options
186
- *
187
- * @public
188
- */
189
- function defineCodeBlockHighlight({ parser }) {
190
- return definePlugin(createHighlightPlugin({ parser }));
191
- }
192
-
193
- //#endregion
194
- //#region src/code-block/shiki-highlighter.ts
195
- let loaded;
196
- async function load() {
197
- const { createOrGetHighlighter } = await import("./shiki-highlighter-chunk.js");
198
- loaded = createOrGetHighlighter;
199
- }
200
- function createOrGetHighlighter(options) {
201
- if (!loaded) return { promise: load() };
202
- return loaded(options);
203
- }
204
-
205
- //#endregion
206
- //#region src/code-block/shiki-parser.ts
207
- /**
208
- * @internal
209
- */
210
- function createLazyParser(highlighterOptions) {
211
- let parser;
212
- return function lazyParser(options) {
213
- const language = options.language || "";
214
- const { highlighter, promise } = createOrGetHighlighter({
215
- ...highlighterOptions,
216
- langs: [language]
217
- });
218
- if (!highlighter) return promise;
219
- if (!parser) parser = createParser(highlighter, { theme: highlighterOptions.themes[0] });
220
- return parser(options);
221
- };
222
- }
223
-
224
- //#endregion
225
- //#region src/code-block/code-block-shiki.ts
226
- /**
227
- * Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.
228
- *
229
- * It will set two CSS variables on the code block elements:
230
- *
231
- * - `--prosemirror-highlight`: sets text color
232
- * - `--prosemirror-highlight-bg`: sets background color
233
- *
234
- * @param options - The options to configure the Shiki highlighter.
235
- *
236
- * @public
237
- */
238
- function defineCodeBlockShiki({ themes = ["one-dark-pro"], langs = ["text"], ...rest } = {}) {
239
- return defineCodeBlockHighlight({ parser: createLazyParser({
240
- themes,
241
- langs,
242
- ...rest
243
- }) });
244
- }
245
-
246
252
  //#endregion
247
253
  export { defineCodeBlock, defineCodeBlockCommands, defineCodeBlockEnterRule, defineCodeBlockHighlight, defineCodeBlockInputRule, defineCodeBlockKeymap, defineCodeBlockShiki, defineCodeBlockSpec, shikiBundledLanguagesInfo, shikiBundledThemesInfo };
248
254
  //# sourceMappingURL=prosekit-extensions-code-block.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-code-block.js","names":[],"sources":["../src/code-block/code-block-commands.ts","../src/code-block/code-block-input-rule.ts","../src/code-block/code-block-keymap.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts","../src/code-block/code-block-highlight.ts","../src/code-block/shiki-highlighter.ts","../src/code-block/shiki-parser.ts","../src/code-block/code-block-shiki.ts"],"sourcesContent":["import { defineCommands, insertNode, setBlockType, setNodeAttrs, toggleNode, type Extension } from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * @internal\n */\nexport type CodeBlockCommandsExtension = Extension<{\n Commands: {\n setCodeBlock: [attrs?: CodeBlockAttrs]\n insertCodeBlock: [attrs?: CodeBlockAttrs]\n toggleCodeBlock: [attrs?: CodeBlockAttrs]\n setCodeBlockAttrs: [attrs: CodeBlockAttrs]\n }\n}>\n\n/**\n * Adds commands for working with `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockCommands(): CodeBlockCommandsExtension {\n return defineCommands({\n setCodeBlock: (attrs?: CodeBlockAttrs) => {\n return setBlockType({ type: 'codeBlock', attrs })\n },\n insertCodeBlock: (attrs?: CodeBlockAttrs) => {\n return insertNode({ type: 'codeBlock', attrs })\n },\n toggleCodeBlock: (attrs?: CodeBlockAttrs) => {\n return toggleNode({ type: 'codeBlock', attrs })\n },\n setCodeBlockAttrs: (attrs: CodeBlockAttrs) => {\n return setNodeAttrs({ type: 'codeBlock', attrs })\n },\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineTextBlockEnterRule } from '../enter-rule'\nimport { defineTextBlockInputRule } from '../input-rule'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * Adds input rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockInputRule(): PlainExtension {\n return defineTextBlockInputRule({\n regex: /^```(\\S*)\\s$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\n/**\n * Adds enter rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockEnterRule(): PlainExtension {\n return defineTextBlockEnterRule({\n regex: /^```(\\S*)$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\nfunction getAttrs(match: RegExpMatchArray): CodeBlockAttrs {\n return { language: match[1] || '' }\n}\n","import { defaultBlockAt, defineKeymap, type PlainExtension } from '@prosekit/core'\nimport { TextSelection, type Command } from '@prosekit/pm/state'\n\n/**\n * Defines the keymap for code blocks.\n */\nexport function defineCodeBlockKeymap(): PlainExtension {\n return defineKeymap({\n Enter: existCodeBlock,\n })\n}\n\n/**\n * Exit a code block and insert a default block below if the cursor is at the\n * end of the code block and the code block is ended with two new lines.\n */\nconst existCodeBlock: Command = (state, dispatch) => {\n if (!state.selection.empty) {\n return false\n }\n\n const { $head } = state.selection\n const parent = $head.parent\n if (\n parent.isTextblock\n && parent.type.spec.code\n && $head.parentOffset === parent.content.size\n && parent.textContent.endsWith('\\n\\n')\n ) {\n const grandParent = $head.node(-1)\n const insertIndex = $head.indexAfter(-1)\n const type = defaultBlockAt(grandParent.contentMatchAt(insertIndex))\n\n if (!type || !grandParent.canReplaceWith(insertIndex, insertIndex, type)) {\n return false\n }\n\n if (dispatch) {\n const { tr } = state\n tr.delete($head.pos - 2, $head.pos)\n const pos = tr.selection.$head.after()\n const node = type.createAndFill()\n if (node) {\n tr.replaceWith(pos, pos, node)\n tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1))\n dispatch(tr.scrollIntoView())\n }\n }\n\n return true\n }\n\n return false\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types'\n\n/**\n * @internal\n */\nexport type CodeBlockSpecExtension = Extension<{\n Nodes: {\n codeBlock: CodeBlockAttrs\n }\n}>\n\n/**\n * Defines the `codeBlock` node spec.\n *\n * @public\n */\nexport function defineCodeBlockSpec(): CodeBlockSpecExtension {\n return defineNodeSpec({\n name: 'codeBlock',\n content: 'text*',\n group: 'block',\n code: true,\n defining: true,\n marks: '',\n attrs: { language: { default: '', validate: 'string' } },\n parseDOM: [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n getAttrs: (node): CodeBlockAttrs => {\n const language = extractLanguageFromElement(node)\n || extractLanguageFromElement(node.querySelector('code'))\n return { language }\n },\n },\n ],\n toDOM(node) {\n const { language } = node.attrs as CodeBlockAttrs\n return [\n 'pre',\n { 'data-language': language || undefined },\n // `class: language-${language}` is used by remark-rehype to highlight the code block\n ['code', { class: language ? `language-${language}` : undefined }, 0],\n ]\n },\n })\n}\n\nfunction extractLanguageFromElement(element: HTMLElement | null | undefined): string {\n if (!element) {\n return ''\n }\n\n const attr = element.getAttribute('data-language')\n if (attr) {\n return attr\n }\n\n const className = element.className\n const match = className.match(/language-(\\w+)/)\n if (match) {\n return match[1]\n }\n\n return ''\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineCodeBlockCommands, type CodeBlockCommandsExtension } from './code-block-commands'\nimport { defineCodeBlockEnterRule, defineCodeBlockInputRule } from './code-block-input-rule'\nimport { defineCodeBlockKeymap } from './code-block-keymap'\nimport { defineCodeBlockSpec, type CodeBlockSpecExtension } from './code-block-spec'\n\n/**\n * @internal\n */\nexport type CodeBlockExtension = Union<\n [CodeBlockSpecExtension, CodeBlockCommandsExtension]\n>\n\n/**\n * Adds `codeBlock` nodes to the editor. This includes the following extensions:\n *\n * - {@link defineCodeBlockSpec}\n * - {@link defineCodeBlockInputRule}\n * - {@link defineCodeBlockEnterRule}\n * - {@link defineCodeBlockKeymap}\n * - {@link defineCodeBlockCommands}.\n *\n * @public\n */\nexport function defineCodeBlock(): CodeBlockExtension {\n return union(\n defineCodeBlockSpec(),\n defineCodeBlockInputRule(),\n defineCodeBlockEnterRule(),\n defineCodeBlockKeymap(),\n defineCodeBlockCommands(),\n )\n}\n","import { definePlugin, type Extension } from '@prosekit/core'\nimport { createHighlightPlugin, type Parser } from 'prosemirror-highlight'\n\n/**\n * @public\n *\n * An alias for the `Parser` type from the `prosemirror-highlight` package.\n */\nexport type HighlightParser = Parser\n\n/**\n * @public\n */\nexport type CodeBlockHighlightOptions = {\n parser: HighlightParser\n}\n\n/**\n * Adds syntax highlighting to code blocks. This function requires a `Parser`\n * instance from the `prosemirror-highlight` package. See the\n * [documentation](https://github.com/ocavue/prosemirror-highlight) for more\n * information.\n *\n * @param options\n *\n * @public\n */\nexport function defineCodeBlockHighlight({\n parser,\n}: CodeBlockHighlightOptions): Extension {\n return definePlugin(\n createHighlightPlugin({ parser }),\n )\n}\n","import type { HighlighterOptions, HighlighterResult } from './shiki-highlighter-chunk'\n\nlet loaded: ((options: HighlighterOptions) => HighlighterResult) | undefined\n\nasync function load() {\n const { createOrGetHighlighter } = await import('./shiki-highlighter-chunk')\n loaded = createOrGetHighlighter\n}\n\nexport function createOrGetHighlighter(\n options: HighlighterOptions,\n): HighlighterResult {\n if (!loaded) {\n return { promise: load() }\n }\n return loaded(options)\n}\n\nexport type { HighlighterOptions }\n","import type { Parser } from 'prosemirror-highlight'\nimport { createParser } from 'prosemirror-highlight/shiki'\n\nimport type { ShikiBundledLanguage } from './shiki-bundle'\nimport { createOrGetHighlighter, type HighlighterOptions } from './shiki-highlighter'\n\n/**\n * @internal\n */\nexport function createLazyParser(\n highlighterOptions: HighlighterOptions,\n): Parser {\n let parser: Parser | undefined\n\n return function lazyParser(options) {\n const language = (options.language || '') as ShikiBundledLanguage\n const { highlighter, promise } = createOrGetHighlighter({\n ...highlighterOptions,\n langs: [language],\n })\n\n if (!highlighter) {\n return promise\n }\n\n if (!parser) {\n parser = createParser(highlighter, {\n theme: highlighterOptions.themes[0],\n })\n }\n return parser(options)\n }\n}\n","import type { Extension } from '@prosekit/core'\nimport type { SpecialLanguage } from 'shiki'\n\nimport { defineCodeBlockHighlight } from './code-block-highlight'\nimport type { ShikiBundledLanguage, ShikiBundledTheme } from './shiki-bundle'\nimport type { ShikiHighlighterOptions } from './shiki-highlighter-chunk'\nimport { createLazyParser } from './shiki-parser'\n\n/**\n * The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {\n /**\n * A list of Shiki themes to pre-load. The first theme in the list will be\n * used to render the code block.\n *\n * @default ['one-dark-pro']\n */\n themes?: ShikiBundledTheme[]\n\n /**\n * A list of Shiki languages to pre-load.\n *\n * @default ['text']\n */\n langs?: (ShikiBundledLanguage | SpecialLanguage)[]\n\n /**\n * The RegExp engine to use. By default, the JavaScript engine is used.\n */\n engine?: ShikiHighlighterOptions['engine']\n}\n\n/**\n * Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.\n *\n * It will set two CSS variables on the code block elements:\n *\n * - `--prosemirror-highlight`: sets text color\n * - `--prosemirror-highlight-bg`: sets background color\n *\n * @param options - The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport function defineCodeBlockShiki({\n themes = ['one-dark-pro'],\n langs = ['text'],\n ...rest\n}: CodeBlockShikiOptions = {}): Extension {\n const parser = createLazyParser({ themes, langs, ...rest })\n return defineCodeBlockHighlight({ parser })\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"prosekit-extensions-code-block.js","names":[],"sources":["../src/code-block/code-block-commands.ts","../src/code-block/code-block-highlight.ts","../src/code-block/code-block-input-rule.ts","../src/code-block/code-block-keymap.ts","../src/code-block/shiki-highlighter.ts","../src/code-block/shiki-parser.ts","../src/code-block/code-block-shiki.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts"],"sourcesContent":["import { defineCommands, insertNode, setBlockType, setNodeAttrs, toggleNode, type Extension } from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types.ts'\n\n/**\n * @internal\n */\nexport type CodeBlockCommandsExtension = Extension<{\n Commands: {\n setCodeBlock: [attrs?: CodeBlockAttrs]\n insertCodeBlock: [attrs?: CodeBlockAttrs]\n toggleCodeBlock: [attrs?: CodeBlockAttrs]\n setCodeBlockAttrs: [attrs: CodeBlockAttrs]\n }\n}>\n\n/**\n * Adds commands for working with `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockCommands(): CodeBlockCommandsExtension {\n return defineCommands({\n setCodeBlock: (attrs?: CodeBlockAttrs) => {\n return setBlockType({ type: 'codeBlock', attrs })\n },\n insertCodeBlock: (attrs?: CodeBlockAttrs) => {\n return insertNode({ type: 'codeBlock', attrs })\n },\n toggleCodeBlock: (attrs?: CodeBlockAttrs) => {\n return toggleNode({ type: 'codeBlock', attrs })\n },\n setCodeBlockAttrs: (attrs: CodeBlockAttrs) => {\n return setNodeAttrs({ type: 'codeBlock', attrs })\n },\n })\n}\n","import { definePlugin, type Extension } from '@prosekit/core'\nimport { createHighlightPlugin, type Parser } from 'prosemirror-highlight'\n\n/**\n * @public\n *\n * An alias for the `Parser` type from the `prosemirror-highlight` package.\n */\nexport type HighlightParser = Parser\n\n/**\n * @public\n */\nexport type CodeBlockHighlightOptions = {\n /**\n * A parser instance from the `prosemirror-highlight` package.\n */\n parser: HighlightParser\n /**\n * ProseMirror node types to highlight.\n *\n * @default ['codeBlock', 'mathBlock']\n */\n nodeTypes?: string[]\n}\n\n/**\n * Adds syntax highlighting to code blocks. This function requires a `Parser`\n * instance from the `prosemirror-highlight` package. See the\n * [documentation](https://github.com/ocavue/prosemirror-highlight) for more\n * information.\n *\n * @param options\n *\n * @public\n */\nexport function defineCodeBlockHighlight({\n parser,\n nodeTypes = ['codeBlock', 'mathBlock'],\n}: CodeBlockHighlightOptions): Extension {\n return definePlugin(\n createHighlightPlugin({ parser, nodeTypes }),\n )\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineTextBlockEnterRule } from '../enter-rule/index.ts'\nimport { defineTextBlockInputRule } from '../input-rule/index.ts'\n\nimport type { CodeBlockAttrs } from './code-block-types.ts'\n\n/**\n * Adds input rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockInputRule(): PlainExtension {\n return defineTextBlockInputRule({\n regex: /^```(\\S*)\\s$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\n/**\n * Adds enter rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockEnterRule(): PlainExtension {\n return defineTextBlockEnterRule({\n regex: /^```(\\S*)$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\nfunction getAttrs(match: RegExpMatchArray): CodeBlockAttrs {\n return { language: match[1] || '' }\n}\n","import { defaultBlockAt, defineKeymap, type PlainExtension } from '@prosekit/core'\nimport { TextSelection, type Command } from '@prosekit/pm/state'\n\n/**\n * Defines the keymap for code blocks.\n */\nexport function defineCodeBlockKeymap(): PlainExtension {\n return defineKeymap({\n Enter: existCodeBlock,\n })\n}\n\n/**\n * Exit a code block and insert a default block below if the cursor is at the\n * end of the code block and the code block is ended with two new lines.\n */\nconst existCodeBlock: Command = (state, dispatch) => {\n if (!state.selection.empty) {\n return false\n }\n\n const { $head } = state.selection\n const parent = $head.parent\n if (\n parent.isTextblock\n && parent.type.spec.code\n && $head.parentOffset === parent.content.size\n && parent.textContent.endsWith('\\n\\n')\n ) {\n const grandParent = $head.node(-1)\n const insertIndex = $head.indexAfter(-1)\n const type = defaultBlockAt(grandParent.contentMatchAt(insertIndex))\n\n if (!type || !grandParent.canReplaceWith(insertIndex, insertIndex, type)) {\n return false\n }\n\n if (dispatch) {\n const { tr } = state\n tr.delete($head.pos - 2, $head.pos)\n const pos = tr.selection.$head.after()\n const node = type.createAndFill()\n if (node) {\n tr.replaceWith(pos, pos, node)\n tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1))\n dispatch(tr.scrollIntoView())\n }\n }\n\n return true\n }\n\n return false\n}\n","import type { HighlighterOptions, HighlighterResult } from './shiki-highlighter-chunk.ts'\n\nlet loaded: ((options: HighlighterOptions) => HighlighterResult) | undefined\n\nasync function load() {\n const { createOrGetHighlighter } = await import('./shiki-highlighter-chunk.ts')\n loaded = createOrGetHighlighter\n}\n\nexport function createOrGetHighlighter(\n options: HighlighterOptions,\n): HighlighterResult {\n if (!loaded) {\n return { promise: load() }\n }\n return loaded(options)\n}\n\nexport type { HighlighterOptions }\n","import type { Parser } from 'prosemirror-highlight'\nimport { createParser } from 'prosemirror-highlight/shiki'\n\nimport type { ShikiBundledLanguage } from './shiki-bundle.ts'\nimport { createOrGetHighlighter, type HighlighterOptions } from './shiki-highlighter.ts'\n\n/**\n * @internal\n */\nexport function createLazyParser(\n highlighterOptions: HighlighterOptions,\n): Parser {\n let parser: Parser | undefined\n\n return function lazyParser(options) {\n const language = (options.language || '') as ShikiBundledLanguage\n const { highlighter, promise } = createOrGetHighlighter({\n ...highlighterOptions,\n langs: [language],\n })\n\n if (!highlighter) {\n return promise\n }\n\n if (!parser) {\n parser = createParser(highlighter, {\n theme: highlighterOptions.themes[0],\n })\n }\n return parser(options)\n }\n}\n","import type { Extension } from '@prosekit/core'\nimport type { SpecialLanguage } from 'shiki'\n\nimport { defineCodeBlockHighlight } from './code-block-highlight.ts'\nimport type { ShikiBundledLanguage, ShikiBundledTheme } from './shiki-bundle.ts'\nimport type { ShikiHighlighterOptions } from './shiki-highlighter-chunk.ts'\nimport { createLazyParser } from './shiki-parser.ts'\n\n/**\n * The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {\n /**\n * ProseMirror node types to highlight.\n *\n * @default ['codeBlock', 'mathBlock']\n */\n nodeTypes?: string[]\n\n /**\n * A list of Shiki themes to pre-load. The first theme in the list will be\n * used to render the code block.\n *\n * @default ['one-dark-pro']\n */\n themes?: ShikiBundledTheme[]\n\n /**\n * A list of Shiki languages to pre-load.\n *\n * @default ['text']\n */\n langs?: (ShikiBundledLanguage | SpecialLanguage)[]\n\n /**\n * The RegExp engine to use. By default, the JavaScript engine is used.\n */\n engine?: ShikiHighlighterOptions['engine']\n}\n\n/**\n * Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.\n *\n * It will set two CSS variables on the code block elements:\n *\n * - `--prosemirror-highlight`: sets text color\n * - `--prosemirror-highlight-bg`: sets background color\n *\n * @param options - The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport function defineCodeBlockShiki({\n nodeTypes,\n themes = ['one-dark-pro'],\n langs = ['text'],\n ...rest\n}: CodeBlockShikiOptions = {}): Extension {\n const parser = createLazyParser({ themes, langs, ...rest })\n return defineCodeBlockHighlight({ parser, nodeTypes })\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types.ts'\n\n/**\n * @internal\n */\nexport type CodeBlockSpecExtension = Extension<{\n Nodes: {\n codeBlock: CodeBlockAttrs\n }\n}>\n\n/**\n * Defines the `codeBlock` node spec.\n *\n * @public\n */\nexport function defineCodeBlockSpec(): CodeBlockSpecExtension {\n return defineNodeSpec({\n name: 'codeBlock',\n content: 'text*',\n group: 'block',\n code: true,\n defining: true,\n marks: '',\n attrs: { language: { default: '', validate: 'string' } },\n parseDOM: [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n getAttrs: (node): CodeBlockAttrs => {\n const language = extractLanguageFromElement(node)\n || extractLanguageFromElement(node.querySelector('code'))\n return { language }\n },\n },\n ],\n toDOM(node) {\n const { language } = node.attrs as CodeBlockAttrs\n return [\n 'pre',\n { 'data-language': language || undefined },\n // `class: language-${language}` is used by remark-rehype to highlight the code block\n ['code', { class: language ? `language-${language}` : undefined }, 0],\n ]\n },\n })\n}\n\nfunction extractLanguageFromElement(element: HTMLElement | null | undefined): string {\n if (!element) {\n return ''\n }\n\n const attr = element.getAttribute('data-language')\n if (attr) {\n return attr\n }\n\n const className = element.className\n const match = className.match(/language-(\\w+)/)\n if (match) {\n return match[1]\n }\n\n return ''\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineCodeBlockCommands, type CodeBlockCommandsExtension } from './code-block-commands.ts'\nimport { defineCodeBlockEnterRule, defineCodeBlockInputRule } from './code-block-input-rule.ts'\nimport { defineCodeBlockKeymap } from './code-block-keymap.ts'\nimport { defineCodeBlockSpec, type CodeBlockSpecExtension } from './code-block-spec.ts'\n\n/**\n * @internal\n */\nexport type CodeBlockExtension = Union<\n [CodeBlockSpecExtension, CodeBlockCommandsExtension]\n>\n\n/**\n * Adds `codeBlock` nodes to the editor. This includes the following extensions:\n *\n * - {@link defineCodeBlockSpec}\n * - {@link defineCodeBlockInputRule}\n * - {@link defineCodeBlockEnterRule}\n * - {@link defineCodeBlockKeymap}\n * - {@link defineCodeBlockCommands}.\n *\n * @public\n */\nexport function defineCodeBlock(): CodeBlockExtension {\n return union(\n defineCodeBlockSpec(),\n defineCodeBlockInputRule(),\n defineCodeBlockEnterRule(),\n defineCodeBlockKeymap(),\n defineCodeBlockCommands(),\n )\n}\n"],"mappings":"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"}
@@ -15,6 +15,18 @@ type CodeCommandsExtension = Extension<{
15
15
  */
16
16
  declare function defineCodeCommands(): CodeCommandsExtension;
17
17
  //#endregion
18
+ //#region src/code/code-input-rule.d.ts
19
+ /**
20
+ * @internal
21
+ */
22
+ declare function defineCodeInputRule(): PlainExtension;
23
+ //#endregion
24
+ //#region src/code/code-keymap.d.ts
25
+ /**
26
+ * @internal
27
+ */
28
+ declare function defineCodeKeymap(): PlainExtension;
29
+ //#endregion
18
30
  //#region src/code/code-spec.d.ts
19
31
  /**
20
32
  * @internal
@@ -39,17 +51,5 @@ type CodeExtension = Union<[CodeSpecExtension, CodeCommandsExtension]>;
39
51
  */
40
52
  declare function defineCode(): CodeExtension;
41
53
  //#endregion
42
- //#region src/code/code-input-rule.d.ts
43
- /**
44
- * @internal
45
- */
46
- declare function defineCodeInputRule(): PlainExtension;
47
- //#endregion
48
- //#region src/code/code-keymap.d.ts
49
- /**
50
- * @internal
51
- */
52
- declare function defineCodeKeymap(): PlainExtension;
53
- //#endregion
54
54
  export { type CodeCommandsExtension, type CodeExtension, type CodeSpecExtension, defineCode, defineCodeCommands, defineCodeInputRule, defineCodeKeymap, defineCodeSpec };
55
55
  //# sourceMappingURL=prosekit-extensions-code.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-code.d.ts","names":[],"sources":["../src/code/code-commands.ts","../src/code/code-spec.ts","../src/code/code.ts","../src/code/code-input-rule.ts","../src/code/code-keymap.ts"],"mappings":";;;;;;;KAKY,qBAAA,GAAwB,SAAA;EAClC,QAAA;IACE,UAAA;EAAA;AAAA;;;;iBAOY,kBAAA,CAAA,GAAsB,qBAAA;;;;;AATtC;KCCY,iBAAA,GAAoB,SAAA;EAC9B,KAAA;IACE,IAAA,EAAM,KAAA;EAAA;AAAA;;;;iBAOM,cAAA,CAAA,GAAkB,iBAAA;;;;ADVlC;;KEKY,aAAA,GAAgB,KAAA,EAAO,iBAAA,EAAmB,qBAAA;;;;iBAKtC,UAAA,CAAA,GAAc,aAAA;;;;;;iBCRd,mBAAA,CAAA,GAAuB,cAAA;;;;;;iBCFvB,gBAAA,CAAA,GAAoB,cAAA"}
1
+ {"version":3,"file":"prosekit-extensions-code.d.ts","names":[],"sources":["../src/code/code-commands.ts","../src/code/code-input-rule.ts","../src/code/code-keymap.ts","../src/code/code-spec.ts","../src/code/code.ts"],"mappings":";;;;;;;KAKY,qBAAA,GAAwB,SAAA;EAClC,QAAA;IACE,UAAA;EAAA;AAAA;;;;iBAOY,kBAAA,CAAA,GAAsB,qBAAA;;;;;;iBCPtB,mBAAA,CAAA,GAAuB,cAAA;;;;;;iBCFvB,gBAAA,CAAA,GAAoB,cAAA;;;;;AFApC;KGCY,iBAAA,GAAoB,SAAA;EAC9B,KAAA;IACE,IAAA,EAAM,KAAA;EAAA;AAAA;;;;iBAOM,cAAA,CAAA,GAAkB,iBAAA;;;;AHVlC;;KIKY,aAAA,GAAgB,KAAA,EAAO,iBAAA,EAAmB,qBAAA;;;;iBAKtC,UAAA,CAAA,GAAc,aAAA"}
@@ -1,4 +1,4 @@
1
- import { r as defineMarkInputRule } from "./input-rule-COGr_GBb.js";
1
+ import { defineMarkInputRule } from "./prosekit-extensions-input-rule.js";
2
2
  import { canUseRegexLookbehind, defineCommands, defineKeymap, defineMarkSpec, toggleMark, union } from "@prosekit/core";
3
3
 
4
4
  //#region src/code/code-commands.ts
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-code.js","names":[],"sources":["../src/code/code-commands.ts","../src/code/code-input-rule.ts","../src/code/code-keymap.ts","../src/code/code-spec.ts","../src/code/code.ts"],"sourcesContent":["import { defineCommands, toggleMark, type Extension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport type CodeCommandsExtension = Extension<{\n Commands: {\n toggleCode: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineCodeCommands(): CodeCommandsExtension {\n return defineCommands({\n toggleCode: () => toggleMark({ type: 'code' }),\n })\n}\n","import { canUseRegexLookbehind, type PlainExtension } from '@prosekit/core'\n\nimport { defineMarkInputRule } from '../input-rule'\n\n/**\n * @internal\n */\nexport function defineCodeInputRule(): PlainExtension {\n return defineMarkInputRule({\n regex: canUseRegexLookbehind()\n ? /(?<=\\s|^)`([^\\s`]|[^\\s`][^`]*[^\\s`])`$/\n : /`([^\\s`]|[^\\s`][^`]*[^\\s`])`$/,\n type: 'code',\n })\n}\n","import { defineKeymap, toggleMark, type PlainExtension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function defineCodeKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-e': toggleMark({ type: 'code' }),\n })\n}\n","import { defineMarkSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\n/**\n * @internal\n */\nexport type CodeSpecExtension = Extension<{\n Marks: {\n code: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineCodeSpec(): CodeSpecExtension {\n return defineMarkSpec({\n name: 'code',\n parseDOM: [{ tag: 'code' }],\n code: true,\n toDOM() {\n return ['code', 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineCodeCommands, type CodeCommandsExtension } from './code-commands'\nimport { defineCodeInputRule } from './code-input-rule'\nimport { defineCodeKeymap } from './code-keymap'\nimport { defineCodeSpec, type CodeSpecExtension } from './code-spec'\n\n/**\n * @internal\n */\nexport type CodeExtension = Union<[CodeSpecExtension, CodeCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineCode(): CodeExtension {\n return union(\n defineCodeSpec(),\n defineCodeCommands(),\n defineCodeKeymap(),\n defineCodeInputRule(),\n )\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,qBAA4C;AAC1D,QAAO,eAAe,EACpB,kBAAkB,WAAW,EAAE,MAAM,QAAQ,CAAC,EAC/C,CAAC;;;;;;;;ACVJ,SAAgB,sBAAsC;AACpD,QAAO,oBAAoB;EACzB,OAAO,uBAAuB,GAC1B,2CACA;EACJ,MAAM;EACP,CAAC;;;;;;;;ACRJ,SAAgB,mBAAmC;AACjD,QAAO,aAAa,EAClB,SAAS,WAAW,EAAE,MAAM,QAAQ,CAAC,EACtC,CAAC;;;;;;;;ACOJ,SAAgB,iBAAoC;AAClD,QAAO,eAAe;EACpB,MAAM;EACN,UAAU,CAAC,EAAE,KAAK,QAAQ,CAAC;EAC3B,MAAM;EACN,QAAQ;AACN,UAAO,CAAC,QAAQ,EAAE;;EAErB,CAAC;;;;;;;;ACRJ,SAAgB,aAA4B;AAC1C,QAAO,MACL,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,CACtB"}
1
+ {"version":3,"file":"prosekit-extensions-code.js","names":[],"sources":["../src/code/code-commands.ts","../src/code/code-input-rule.ts","../src/code/code-keymap.ts","../src/code/code-spec.ts","../src/code/code.ts"],"sourcesContent":["import { defineCommands, toggleMark, type Extension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport type CodeCommandsExtension = Extension<{\n Commands: {\n toggleCode: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineCodeCommands(): CodeCommandsExtension {\n return defineCommands({\n toggleCode: () => toggleMark({ type: 'code' }),\n })\n}\n","import { canUseRegexLookbehind, type PlainExtension } from '@prosekit/core'\n\nimport { defineMarkInputRule } from '../input-rule/index.ts'\n\n/**\n * @internal\n */\nexport function defineCodeInputRule(): PlainExtension {\n return defineMarkInputRule({\n regex: canUseRegexLookbehind()\n ? /(?<=\\s|^)`([^\\s`]|[^\\s`][^`]*[^\\s`])`$/\n : /`([^\\s`]|[^\\s`][^`]*[^\\s`])`$/,\n type: 'code',\n })\n}\n","import { defineKeymap, toggleMark, type PlainExtension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function defineCodeKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-e': toggleMark({ type: 'code' }),\n })\n}\n","import { defineMarkSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\n/**\n * @internal\n */\nexport type CodeSpecExtension = Extension<{\n Marks: {\n code: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineCodeSpec(): CodeSpecExtension {\n return defineMarkSpec({\n name: 'code',\n parseDOM: [{ tag: 'code' }],\n code: true,\n toDOM() {\n return ['code', 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineCodeCommands, type CodeCommandsExtension } from './code-commands.ts'\nimport { defineCodeInputRule } from './code-input-rule.ts'\nimport { defineCodeKeymap } from './code-keymap.ts'\nimport { defineCodeSpec, type CodeSpecExtension } from './code-spec.ts'\n\n/**\n * @internal\n */\nexport type CodeExtension = Union<[CodeSpecExtension, CodeCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineCode(): CodeExtension {\n return union(\n defineCodeSpec(),\n defineCodeCommands(),\n defineCodeKeymap(),\n defineCodeInputRule(),\n )\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,qBAA4C;AAC1D,QAAO,eAAe,EACpB,kBAAkB,WAAW,EAAE,MAAM,QAAQ,CAAC,EAC/C,CAAC;;;;;;;;ACVJ,SAAgB,sBAAsC;AACpD,QAAO,oBAAoB;EACzB,OAAO,uBAAuB,GAC1B,2CACA;EACJ,MAAM;EACP,CAAC;;;;;;;;ACRJ,SAAgB,mBAAmC;AACjD,QAAO,aAAa,EAClB,SAAS,WAAW,EAAE,MAAM,QAAQ,CAAC,EACtC,CAAC;;;;;;;;ACOJ,SAAgB,iBAAoC;AAClD,QAAO,eAAe;EACpB,MAAM;EACN,UAAU,CAAC,EAAE,KAAK,QAAQ,CAAC;EAC3B,MAAM;EACN,QAAQ;AACN,UAAO,CAAC,QAAQ,EAAE;;EAErB,CAAC;;;;;;;;ACRJ,SAAgB,aAA4B;AAC1C,QAAO,MACL,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,CACtB"}
@@ -1,5 +1,5 @@
1
- import { NodeJSON, PlainExtension, StepJSON } from "@prosekit/core";
2
1
  import { Transaction } from "@prosekit/pm/state";
2
+ import { NodeJSON, PlainExtension, StepJSON } from "@prosekit/core";
3
3
  import { ProseMirrorNode } from "@prosekit/pm/model";
4
4
 
5
5
  //#region src/commit/index.d.ts
@@ -1,5 +1,5 @@
1
- import { defineDefaultState, definePlugin, jsonFromNode, union } from "@prosekit/core";
2
1
  import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
2
+ import { defineDefaultState, definePlugin, jsonFromNode, union } from "@prosekit/core";
3
3
  import { Decoration, DecorationSet } from "@prosekit/pm/view";
4
4
  import { DOMSerializer, Fragment, Slice } from "@prosekit/pm/model";
5
5
  import { Step } from "@prosekit/pm/transform";
@@ -1,3 +1,3 @@
1
- import { t as defineDropIndicator } from "./drop-indicator-B_oMfeVP.js";
1
+ import { t as defineDropIndicator } from "./drop-indicator-DJq8pF92.js";
2
2
 
3
3
  export { defineDropIndicator };
@@ -1,82 +1,19 @@
1
1
  import { PlainExtension } from "@prosekit/core";
2
- import { EditorState, Transaction } from "@prosekit/pm/state";
3
- import { Attrs, NodeType } from "@prosekit/pm/model";
2
+ import { EnterRule, EnterRuleHandler, EnterRuleHandlerOptions, TextBlockEnterRuleOptions as TextBlockEnterRuleOptions$1 } from "prosemirror-enter-rules";
4
3
 
5
4
  //#region src/enter-rule/index.d.ts
6
- /**
7
- * @public
8
- *
9
- * Options for {@link EnterRuleHandler}.
10
- */
11
- interface EnterRuleHandlerOptions {
12
- /**
13
- * The current editor state.
14
- */
15
- state: EditorState;
16
- /**
17
- * The start position of the matched text.
18
- */
19
- from: number;
20
- /**
21
- * The end position of the matched text.
22
- */
23
- to: number;
24
- /**
25
- * The matched result from the regular expression.
26
- */
27
- match: RegExpExecArray;
28
- }
29
- /**
30
- * @public
31
- */
32
- type EnterRuleHandler = (options: EnterRuleHandlerOptions) => Transaction | null;
33
5
  /**
34
6
  * Options for {@link defineEnterRule}.
35
7
  *
36
8
  * @public
37
9
  */
38
- type EnterRuleOptions = {
39
- /**
40
- * The regular expression to match against. It should end with `$`.
41
- */
42
- regex: RegExp;
43
- /**
44
- * A function to be called when an enter rule is triggered.
45
- */
46
- handler: EnterRuleHandler;
47
- /**
48
- * Whether to stop further handlers from being called if this rule is triggered.
49
- *
50
- * @default false
51
- */
52
- stop?: boolean;
53
- };
10
+ interface EnterRuleOptions extends EnterRule {}
54
11
  /**
55
12
  * Options for {@link defineTextBlockEnterRule}.
56
13
  *
57
14
  * @public
58
15
  */
59
- interface TextBlockEnterRuleOptions {
60
- /**
61
- * The regular expression to match against. It should end with `$`.
62
- */
63
- regex: RegExp;
64
- /**
65
- * The node type to replace the matched text with.
66
- */
67
- type: string | NodeType;
68
- /**
69
- * Attributes to set on the node. If a function is provided, it will be called
70
- * with the matched result from the regular expression.
71
- */
72
- attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
73
- /**
74
- * Whether to stop further handlers from being called if this rule is triggered.
75
- *
76
- * @default true
77
- */
78
- stop?: boolean;
79
- }
16
+ interface TextBlockEnterRuleOptions extends TextBlockEnterRuleOptions$1 {}
80
17
  /**
81
18
  * Defines an enter rule. An enter rule applies when the text directly in front of
82
19
  * the cursor matches `regex` and user presses Enter. The `regex` should end
@@ -86,11 +23,7 @@ interface TextBlockEnterRuleOptions {
86
23
  *
87
24
  * @public
88
25
  */
89
- declare function defineEnterRule({
90
- regex,
91
- handler,
92
- stop
93
- }: EnterRuleOptions): PlainExtension;
26
+ declare function defineEnterRule(options: EnterRuleOptions): PlainExtension;
94
27
  /**
95
28
  * Defines an enter rule that replaces the matched text with a block node.
96
29
  *
@@ -100,12 +33,7 @@ declare function defineEnterRule({
100
33
  *
101
34
  * @public
102
35
  */
103
- declare function defineTextBlockEnterRule({
104
- regex,
105
- type,
106
- attrs,
107
- stop
108
- }: TextBlockEnterRuleOptions): PlainExtension;
36
+ declare function defineTextBlockEnterRule(options: TextBlockEnterRuleOptions): PlainExtension;
109
37
  //#endregion
110
- export { EnterRuleHandler, EnterRuleHandlerOptions, EnterRuleOptions, TextBlockEnterRuleOptions, defineEnterRule, defineTextBlockEnterRule };
38
+ export { type EnterRuleHandler, type EnterRuleHandlerOptions, EnterRuleOptions, TextBlockEnterRuleOptions, defineEnterRule, defineTextBlockEnterRule };
111
39
  //# sourceMappingURL=prosekit-extensions-enter-rule.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-enter-rule.d.ts","names":[],"sources":["../src/enter-rule/index.ts"],"mappings":";;;;;;;AAqBA;;;UAAiB,uBAAA;EAIf;;;EAAA,KAAA,EAAO,WAAA;EAeP;;;EAVA,IAAA;EAgBU;;;EAXV,EAAA;EAWuC;;;EANvC,KAAA,EAAO,eAAA;AAAA;AAaT;;;AAAA,KAPY,gBAAA,IAAoB,OAAA,EAAS,uBAAA,KAA4B,WAAA;;;;;;KAOzD,gBAAA;EAgBN;AAQN;;EApBE,KAAA,EAAO,MAAA;EAwBA;;;EAnBP,OAAA,EAAS,gBAAA;EA8B4C;;;;;EAvBrD,IAAA;AAAA;;;;;;UAQe,yBAAA;EAsBX;;AAYN;EA9BE,KAAA,EAAO,MAAA;;;;EAKP,IAAA,WAAe,QAAA;EA6Bd;;;;EAvBD,KAAA,GAAQ,KAAA,YAAiB,KAAA,EAAO,gBAAA,KAAqB,KAAA;EAoBrD;;;;;EAbA,IAAA;AAAA;;;AA8BF;;;;;;;iBAlBgB,eAAA,CAAA;EACd,KAAA;EACA,OAAA;EACA;AAAA,GACC,gBAAA,GAAmB,cAAA;;;;;;;;;;iBAcN,wBAAA,CAAA;EACd,KAAA;EACA,IAAA;EACA,KAAA;EACA;AAAA,GACC,yBAAA,GAA4B,cAAA"}
1
+ {"version":3,"file":"prosekit-extensions-enter-rule.d.ts","names":[],"sources":["../src/enter-rule/index.ts"],"mappings":";;;;;AAiBA;;;;UAAiB,gBAAA,SAAyB,SAAA;;;;;AAkB1C;UAXiB,yBAAA,SAAkC,2BAAA;;;;;;;AAwBnD;;;iBAbgB,eAAA,CAAgB,OAAA,EAAS,gBAAA,GAAmB,cAAA;;;;;;;;;;iBAa5C,wBAAA,CAAyB,OAAA,EAAS,yBAAA,GAA4B,cAAA"}
@@ -1,3 +1,38 @@
1
- import { n as defineTextBlockEnterRule, t as defineEnterRule } from "./enter-rule-D-p4ykfv.js";
1
+ import { defineFacet, defineFacetPayload, pluginFacet } from "@prosekit/core";
2
+ import { createEnterRulePlugin, createTextBlockEnterRule } from "prosemirror-enter-rules";
2
3
 
3
- export { defineEnterRule, defineTextBlockEnterRule };
4
+ //#region src/enter-rule/index.ts
5
+ /**
6
+ * Defines an enter rule. An enter rule applies when the text directly in front of
7
+ * the cursor matches `regex` and user presses Enter. The `regex` should end
8
+ * with `$`.
9
+ *
10
+ * @param options
11
+ *
12
+ * @public
13
+ */
14
+ function defineEnterRule(options) {
15
+ return defineFacetPayload(enterRuleFacet, [options]);
16
+ }
17
+ /**
18
+ * Defines an enter rule that replaces the matched text with a block node.
19
+ *
20
+ * See also {@link defineEnterRule}.
21
+ *
22
+ * @param options
23
+ *
24
+ * @public
25
+ */
26
+ function defineTextBlockEnterRule(options) {
27
+ return defineEnterRule(createTextBlockEnterRule(options));
28
+ }
29
+ const enterRuleFacet = defineFacet({
30
+ reducer: (rules) => {
31
+ return createEnterRulePlugin({ rules });
32
+ },
33
+ parent: pluginFacet
34
+ });
35
+
36
+ //#endregion
37
+ export { defineEnterRule, defineTextBlockEnterRule };
38
+ //# sourceMappingURL=prosekit-extensions-enter-rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prosekit-extensions-enter-rule.js","names":[],"sources":["../src/enter-rule/index.ts"],"sourcesContent":["import { defineFacet, defineFacetPayload, pluginFacet, type PlainExtension, type PluginPayload } from '@prosekit/core'\nimport {\n createEnterRulePlugin,\n createTextBlockEnterRule,\n type EnterRule,\n type EnterRuleHandler,\n type EnterRuleHandlerOptions,\n type TextBlockEnterRuleOptions as TextBlockEnterRuleOptionsBase,\n} from 'prosemirror-enter-rules'\n\nexport type { EnterRuleHandler, EnterRuleHandlerOptions }\n\n/**\n * Options for {@link defineEnterRule}.\n *\n * @public\n */\nexport interface EnterRuleOptions extends EnterRule {}\n\n/**\n * Options for {@link defineTextBlockEnterRule}.\n *\n * @public\n */\nexport interface TextBlockEnterRuleOptions extends TextBlockEnterRuleOptionsBase {}\n\n/**\n * Defines an enter rule. An enter rule applies when the text directly in front of\n * the cursor matches `regex` and user presses Enter. The `regex` should end\n * with `$`.\n *\n * @param options\n *\n * @public\n */\nexport function defineEnterRule(options: EnterRuleOptions): PlainExtension {\n return defineFacetPayload(enterRuleFacet, [options]) as PlainExtension\n}\n\n/**\n * Defines an enter rule that replaces the matched text with a block node.\n *\n * See also {@link defineEnterRule}.\n *\n * @param options\n *\n * @public\n */\nexport function defineTextBlockEnterRule(options: TextBlockEnterRuleOptions): PlainExtension {\n return defineEnterRule(createTextBlockEnterRule(options))\n}\n\nconst enterRuleFacet = defineFacet<EnterRule, PluginPayload>({\n reducer: (rules: EnterRule[]): PluginPayload => {\n return createEnterRulePlugin({ rules })\n },\n\n parent: pluginFacet,\n})\n"],"mappings":";;;;;;;;;;;;;AAmCA,SAAgB,gBAAgB,SAA2C;AACzE,QAAO,mBAAmB,gBAAgB,CAAC,QAAQ,CAAC;;;;;;;;;;;AAYtD,SAAgB,yBAAyB,SAAoD;AAC3F,QAAO,gBAAgB,yBAAyB,QAAQ,CAAC;;AAG3D,MAAM,iBAAiB,YAAsC;CAC3D,UAAU,UAAsC;AAC9C,SAAO,sBAAsB,EAAE,OAAO,CAAC;;CAGzC,QAAQ;CACT,CAAC"}
@@ -1,2 +1,2 @@
1
- import { a as FilePasteHandler, c as FileDropHandler, i as UploaderOptions, l as FileDropHandlerOptions, n as UploadTask, o as FilePasteHandlerOptions, r as Uploader, s as defineFilePasteHandler, t as UploadProgress, u as defineFileDropHandler } from "./index-cp1u4e0e.js";
2
- export { FileDropHandler, FileDropHandlerOptions, FilePasteHandler, FilePasteHandlerOptions, UploadProgress, UploadTask, Uploader, UploaderOptions, defineFileDropHandler, defineFilePasteHandler };
1
+ import { a as FilePasteHandler, c as FileDropHandler, i as UploaderOptions, l as FileDropHandlerOptions, n as UploadTask, o as FilePasteHandlerOptions, r as Uploader, s as defineFilePasteHandler, t as UploadProgress, u as defineFileDropHandler } from "./file-upload-dr3IXUty.js";
2
+ export { type FileDropHandler, type FileDropHandlerOptions, type FilePasteHandler, type FilePasteHandlerOptions, type UploadProgress, UploadTask, type Uploader, type UploaderOptions, defineFileDropHandler, defineFilePasteHandler };