@prosekit/extensions 0.14.1 → 0.15.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.
Files changed (310) hide show
  1. package/dist/commit/style.css +1 -3
  2. package/dist/{drop-indicator-DJq8pF92.js → drop-indicator.js} +2 -4
  3. package/dist/drop-indicator.js.map +1 -0
  4. package/dist/{file-upload-I9m1EJAM.js → file.js} +2 -6
  5. package/dist/file.js.map +1 -0
  6. package/dist/gap-cursor/style.css +5 -8
  7. package/dist/{file-upload-dr3IXUty.d.ts → index.d.ts} +1 -1
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/list/style.css +79 -110
  10. package/dist/loro/style.css +18 -21
  11. package/dist/{mark-rule-CUnXwBuy.js → mark-rule.js} +3 -6
  12. package/dist/mark-rule.js.map +1 -0
  13. package/dist/page/style.css +43 -0
  14. package/dist/{mark-paste-rule-n_2Ehmb5.js → paste-rule.js} +3 -7
  15. package/dist/paste-rule.js.map +1 -0
  16. package/dist/placeholder/style.css +4 -7
  17. package/dist/prosekit-extensions-autocomplete.d.ts +1 -1
  18. package/dist/prosekit-extensions-autocomplete.js +17 -21
  19. package/dist/prosekit-extensions-autocomplete.js.map +1 -1
  20. package/dist/prosekit-extensions-background-color.d.ts +1 -1
  21. package/dist/prosekit-extensions-background-color.js +1 -4
  22. package/dist/prosekit-extensions-background-color.js.map +1 -1
  23. package/dist/prosekit-extensions-blockquote.d.ts +13 -13
  24. package/dist/prosekit-extensions-blockquote.d.ts.map +1 -1
  25. package/dist/prosekit-extensions-blockquote.js +6 -10
  26. package/dist/prosekit-extensions-blockquote.js.map +1 -1
  27. package/dist/prosekit-extensions-bold.d.ts +12 -12
  28. package/dist/prosekit-extensions-bold.d.ts.map +1 -1
  29. package/dist/prosekit-extensions-bold.js +1 -6
  30. package/dist/prosekit-extensions-bold.js.map +1 -1
  31. package/dist/prosekit-extensions-code-block.d.ts +56 -37
  32. package/dist/prosekit-extensions-code-block.d.ts.map +1 -1
  33. package/dist/prosekit-extensions-code-block.js +73 -76
  34. package/dist/prosekit-extensions-code-block.js.map +1 -1
  35. package/dist/prosekit-extensions-code.d.ts +12 -12
  36. package/dist/prosekit-extensions-code.d.ts.map +1 -1
  37. package/dist/prosekit-extensions-code.js +1 -6
  38. package/dist/prosekit-extensions-code.js.map +1 -1
  39. package/dist/prosekit-extensions-commit.d.ts +1 -1
  40. package/dist/prosekit-extensions-commit.js +2 -3
  41. package/dist/prosekit-extensions-commit.js.map +1 -1
  42. package/dist/prosekit-extensions-doc.js +1 -2
  43. package/dist/prosekit-extensions-doc.js.map +1 -1
  44. package/dist/prosekit-extensions-drop-cursor.js +1 -2
  45. package/dist/prosekit-extensions-drop-cursor.js.map +1 -1
  46. package/dist/prosekit-extensions-drop-indicator.js +2 -3
  47. package/dist/prosekit-extensions-enter-rule.d.ts +2 -2
  48. package/dist/prosekit-extensions-enter-rule.d.ts.map +1 -1
  49. package/dist/prosekit-extensions-enter-rule.js +1 -2
  50. package/dist/prosekit-extensions-enter-rule.js.map +1 -1
  51. package/dist/prosekit-extensions-file.d.ts +2 -2
  52. package/dist/prosekit-extensions-file.js +2 -3
  53. package/dist/prosekit-extensions-gap-cursor.js +1 -2
  54. package/dist/prosekit-extensions-gap-cursor.js.map +1 -1
  55. package/dist/prosekit-extensions-hard-break.d.ts +7 -7
  56. package/dist/prosekit-extensions-hard-break.d.ts.map +1 -1
  57. package/dist/prosekit-extensions-hard-break.js +1 -5
  58. package/dist/prosekit-extensions-hard-break.js.map +1 -1
  59. package/dist/prosekit-extensions-heading.d.ts +15 -15
  60. package/dist/prosekit-extensions-heading.d.ts.map +1 -1
  61. package/dist/prosekit-extensions-heading.js +1 -6
  62. package/dist/prosekit-extensions-heading.js.map +1 -1
  63. package/dist/prosekit-extensions-horizontal-rule.d.ts +7 -7
  64. package/dist/prosekit-extensions-horizontal-rule.d.ts.map +1 -1
  65. package/dist/prosekit-extensions-horizontal-rule.js +12 -14
  66. package/dist/prosekit-extensions-horizontal-rule.js.map +1 -1
  67. package/dist/prosekit-extensions-image.d.ts +12 -13
  68. package/dist/prosekit-extensions-image.d.ts.map +1 -1
  69. package/dist/prosekit-extensions-image.js +10 -16
  70. package/dist/prosekit-extensions-image.js.map +1 -1
  71. package/dist/prosekit-extensions-input-rule.js +1 -2
  72. package/dist/prosekit-extensions-input-rule.js.map +1 -1
  73. package/dist/prosekit-extensions-italic.d.ts +12 -12
  74. package/dist/prosekit-extensions-italic.d.ts.map +1 -1
  75. package/dist/prosekit-extensions-italic.js +1 -6
  76. package/dist/prosekit-extensions-italic.js.map +1 -1
  77. package/dist/prosekit-extensions-link.js +3 -6
  78. package/dist/prosekit-extensions-link.js.map +1 -1
  79. package/dist/prosekit-extensions-list.d.ts +26 -26
  80. package/dist/prosekit-extensions-list.d.ts.map +1 -1
  81. package/dist/prosekit-extensions-list.js +26 -34
  82. package/dist/prosekit-extensions-list.js.map +1 -1
  83. package/dist/prosekit-extensions-loro.d.ts +16 -16
  84. package/dist/prosekit-extensions-loro.d.ts.map +1 -1
  85. package/dist/prosekit-extensions-loro.js +3 -9
  86. package/dist/prosekit-extensions-loro.js.map +1 -1
  87. package/dist/prosekit-extensions-mark-rule.js +2 -3
  88. package/dist/prosekit-extensions-math.d.ts +3 -3
  89. package/dist/prosekit-extensions-math.d.ts.map +1 -1
  90. package/dist/prosekit-extensions-math.js +5 -5
  91. package/dist/prosekit-extensions-math.js.map +1 -1
  92. package/dist/prosekit-extensions-mention.js +1 -2
  93. package/dist/prosekit-extensions-mention.js.map +1 -1
  94. package/dist/prosekit-extensions-mod-click-prevention.js +2 -3
  95. package/dist/prosekit-extensions-mod-click-prevention.js.map +1 -1
  96. package/dist/prosekit-extensions-page.d.ts +114 -0
  97. package/dist/prosekit-extensions-page.d.ts.map +1 -0
  98. package/dist/prosekit-extensions-page.js +324 -0
  99. package/dist/prosekit-extensions-page.js.map +1 -0
  100. package/dist/prosekit-extensions-paragraph.d.ts +7 -7
  101. package/dist/prosekit-extensions-paragraph.d.ts.map +1 -1
  102. package/dist/prosekit-extensions-paragraph.js +3 -7
  103. package/dist/prosekit-extensions-paragraph.js.map +1 -1
  104. package/dist/prosekit-extensions-paste-rule.js +2 -3
  105. package/dist/prosekit-extensions-placeholder.d.ts +1 -1
  106. package/dist/prosekit-extensions-placeholder.js +3 -4
  107. package/dist/prosekit-extensions-placeholder.js.map +1 -1
  108. package/dist/prosekit-extensions-readonly.js +2 -3
  109. package/dist/prosekit-extensions-readonly.js.map +1 -1
  110. package/dist/prosekit-extensions-search.js +1 -2
  111. package/dist/prosekit-extensions-search.js.map +1 -1
  112. package/dist/prosekit-extensions-strike.js +1 -2
  113. package/dist/prosekit-extensions-strike.js.map +1 -1
  114. package/dist/prosekit-extensions-table.d.ts +47 -47
  115. package/dist/prosekit-extensions-table.d.ts.map +1 -1
  116. package/dist/prosekit-extensions-table.js +2 -3
  117. package/dist/prosekit-extensions-text-align.d.ts +1 -1
  118. package/dist/prosekit-extensions-text-align.js +1 -2
  119. package/dist/prosekit-extensions-text-align.js.map +1 -1
  120. package/dist/prosekit-extensions-text-color.d.ts +1 -1
  121. package/dist/prosekit-extensions-text-color.js +1 -4
  122. package/dist/prosekit-extensions-text-color.js.map +1 -1
  123. package/dist/prosekit-extensions-text.js +1 -2
  124. package/dist/prosekit-extensions-text.js.map +1 -1
  125. package/dist/prosekit-extensions-underline.js +1 -2
  126. package/dist/prosekit-extensions-underline.js.map +1 -1
  127. package/dist/prosekit-extensions-virtual-selection.js +2 -3
  128. package/dist/prosekit-extensions-virtual-selection.js.map +1 -1
  129. package/dist/prosekit-extensions-yjs.d.ts +3 -3
  130. package/dist/prosekit-extensions-yjs.d.ts.map +1 -1
  131. package/dist/prosekit-extensions-yjs.js +3 -9
  132. package/dist/prosekit-extensions-yjs.js.map +1 -1
  133. package/dist/prosekit-extensions.js +1 -1
  134. package/dist/search/style.css +4 -8
  135. package/dist/shiki-highlighter-chunk.js +1 -2
  136. package/dist/shiki-highlighter-chunk.js.map +1 -1
  137. package/dist/table/style.css +16 -16
  138. package/dist/{table-UJVYsrB7.js → table.js} +29 -41
  139. package/dist/table.js.map +1 -0
  140. package/dist/virtual-selection/style.css +1 -4
  141. package/dist/yjs/style.css +14 -20
  142. package/package.json +30 -16
  143. package/src/autocomplete/autocomplete-helpers.ts +1 -1
  144. package/src/autocomplete/autocomplete-plugin.ts +2 -2
  145. package/src/autocomplete/autocomplete-rule.ts +1 -1
  146. package/src/autocomplete/autocomplete.spec.ts +4 -4
  147. package/src/autocomplete/autocomplete.ts +2 -2
  148. package/src/autocomplete/index.ts +2 -2
  149. package/src/background-color/background-color-commands.spec.ts +1 -1
  150. package/src/background-color/background-color-commands.ts +1 -1
  151. package/src/background-color/background-color-spec.spec.ts +1 -1
  152. package/src/background-color/background-color.ts +2 -2
  153. package/src/background-color/index.ts +3 -3
  154. package/src/blockquote/blockquote-input-rule.ts +1 -1
  155. package/src/blockquote/blockquote-keymap.spec.ts +1 -1
  156. package/src/blockquote/blockquote-keymap.ts +9 -7
  157. package/src/blockquote/blockquote.ts +4 -4
  158. package/src/blockquote/index.ts +5 -5
  159. package/src/bold/bold-input-rule.spec.ts +2 -2
  160. package/src/bold/bold-input-rule.ts +1 -1
  161. package/src/bold/bold.ts +4 -4
  162. package/src/bold/index.ts +5 -5
  163. package/src/code/code-input-rule.ts +1 -1
  164. package/src/code/code.ts +4 -4
  165. package/src/code/index.ts +5 -5
  166. package/src/code-block/code-block-commands.ts +1 -1
  167. package/src/code-block/code-block-highlight.ts +11 -1
  168. package/src/code-block/code-block-input-rule.ts +3 -3
  169. package/src/code-block/code-block-shiki.ts +13 -5
  170. package/src/code-block/code-block-spec.spec.ts +2 -2
  171. package/src/code-block/code-block-spec.ts +1 -1
  172. package/src/code-block/code-block.ts +4 -4
  173. package/src/code-block/index.ts +9 -9
  174. package/src/code-block/shiki-highlighter.ts +2 -2
  175. package/src/code-block/shiki-parser.ts +2 -2
  176. package/src/drop-cursor/index.ts +1 -1
  177. package/src/drop-indicator/drop-indicator.ts +1 -1
  178. package/src/drop-indicator/index.ts +1 -1
  179. package/src/enter-rule/index.ts +3 -3
  180. package/src/file/file-drop-handler.ts +1 -1
  181. package/src/file/file-paste-handler.spec.ts +3 -3
  182. package/src/file/file-paste-handler.ts +1 -1
  183. package/src/file/index.ts +3 -3
  184. package/src/gap-cursor/index.ts +1 -1
  185. package/src/hard-break/hard-break-keymap.spec.ts +2 -2
  186. package/src/hard-break/hard-break-keymap.ts +1 -1
  187. package/src/hard-break/hard-break.ts +3 -3
  188. package/src/hard-break/index.ts +4 -4
  189. package/src/heading/heading-commands.ts +1 -1
  190. package/src/heading/heading-input-rule.ts +2 -2
  191. package/src/heading/heading-keymap.spec.ts +1 -1
  192. package/src/heading/heading-spec.ts +1 -1
  193. package/src/heading/heading.ts +4 -4
  194. package/src/heading/index.ts +6 -6
  195. package/src/horizontal-rule/horizontal-rule-commands.spec.ts +1 -1
  196. package/src/horizontal-rule/horizontal-rule-commands.ts +14 -11
  197. package/src/horizontal-rule/horizontal-rule-input-rule.spec.ts +2 -2
  198. package/src/horizontal-rule/horizontal-rule-input-rule.ts +1 -1
  199. package/src/horizontal-rule/horizontal-rule.ts +3 -3
  200. package/src/horizontal-rule/index.ts +4 -4
  201. package/src/image/image-commands/insert-image.ts +1 -1
  202. package/src/image/image-commands/upload-image.spec.ts +4 -4
  203. package/src/image/image-commands/upload-image.ts +2 -2
  204. package/src/image/image-commands.ts +3 -3
  205. package/src/image/image-upload-handler.ts +2 -2
  206. package/src/image/image.ts +2 -2
  207. package/src/image/index.ts +6 -6
  208. package/src/italic/index.ts +5 -5
  209. package/src/italic/italic-commands.spec.ts +4 -4
  210. package/src/italic/italic-input-rule.spec.ts +2 -2
  211. package/src/italic/italic-input-rule.ts +1 -1
  212. package/src/italic/italic.ts +4 -4
  213. package/src/link/index.spec.ts +2 -2
  214. package/src/link/index.ts +6 -6
  215. package/src/link/link-paste-rule.spec.ts +2 -2
  216. package/src/link/link-paste-rule.ts +3 -3
  217. package/src/link/link-regex.spec.ts +1 -1
  218. package/src/list/index.ts +8 -8
  219. package/src/list/list-drop-indicator.ts +2 -2
  220. package/src/list/list-input-rules.ts +1 -1
  221. package/src/list/list-keymap.spec.ts +1 -1
  222. package/src/list/list-spec.ts +1 -1
  223. package/src/list/list-types.spec.ts +2 -2
  224. package/src/list/list.spec.ts +6 -6
  225. package/src/list/list.ts +7 -7
  226. package/src/loro/index.ts +6 -6
  227. package/src/loro/loro.ts +8 -7
  228. package/src/mark-rule/apply.ts +2 -2
  229. package/src/mark-rule/index.ts +2 -2
  230. package/src/mark-rule/mark-rule.spec.ts +4 -4
  231. package/src/mark-rule/mark-rule.ts +2 -2
  232. package/src/math/index.ts +4 -4
  233. package/src/math/math-block.ts +8 -1
  234. package/src/math/math-inline.ts +1 -1
  235. package/src/math/math.ts +3 -3
  236. package/src/page/index.ts +5 -0
  237. package/src/page/page-break-commands.spec.ts +61 -0
  238. package/src/page/page-break-commands.ts +41 -0
  239. package/src/page/page-break-keymap.ts +17 -0
  240. package/src/page/page-break-spec.ts +33 -0
  241. package/src/page/page-break.ts +23 -0
  242. package/src/page/page-element.ts +246 -0
  243. package/src/page/page-rendering.ts +164 -0
  244. package/src/page/style.css +43 -0
  245. package/src/paragraph/index.ts +7 -7
  246. package/src/paragraph/paragraph-keymap.ts +1 -1
  247. package/src/paragraph/paragraph.ts +6 -5
  248. package/src/paste-rule/index.ts +2 -2
  249. package/src/paste-rule/mark-paste-rule.spec.ts +8 -8
  250. package/src/paste-rule/mark-paste-rule.ts +2 -2
  251. package/src/paste-rule/paste-rule.spec.ts +2 -2
  252. package/src/paste-rule/paste-rule.ts +1 -1
  253. package/src/paste-rule/split-text-by-regex.spec.ts +1 -1
  254. package/src/placeholder/index.ts +1 -1
  255. package/src/strike/index.ts +1 -1
  256. package/src/table/index.ts +14 -14
  257. package/src/table/table-commands/delete-cell-selection.spec.ts +3 -3
  258. package/src/table/table-commands/exit-table.spec.ts +2 -2
  259. package/src/table/table-commands/insert-table.spec.ts +1 -1
  260. package/src/table/table-commands/move-table-column.spec.ts +2 -2
  261. package/src/table/table-commands/move-table-row.spec.ts +2 -2
  262. package/src/table/table-commands/select-table-cell.spec.ts +3 -3
  263. package/src/table/table-commands/select-table-cell.ts +1 -1
  264. package/src/table/table-commands/select-table-column.spec.ts +2 -2
  265. package/src/table/table-commands/select-table-column.ts +1 -1
  266. package/src/table/table-commands/select-table-row.spec.ts +2 -2
  267. package/src/table/table-commands/select-table-row.ts +1 -1
  268. package/src/table/table-commands/select-table.spec.ts +2 -2
  269. package/src/table/table-commands/select-table.ts +1 -1
  270. package/src/table/table-commands.ts +9 -9
  271. package/src/table/table-drop-indicator.ts +2 -2
  272. package/src/table/table-spec.spec.ts +4 -4
  273. package/src/table/table.ts +4 -4
  274. package/src/table/test-utils.ts +1 -1
  275. package/src/testing/index.ts +24 -24
  276. package/src/text-color/index.ts +3 -3
  277. package/src/text-color/text-color-commands.spec.ts +1 -1
  278. package/src/text-color/text-color-commands.ts +1 -1
  279. package/src/text-color/text-color-spec.spec.ts +1 -1
  280. package/src/text-color/text-color.ts +2 -2
  281. package/src/yjs/index.ts +7 -7
  282. package/src/yjs/yjs-cursor-plugin.ts +1 -1
  283. package/src/yjs/yjs-undo-plugin.ts +3 -2
  284. package/src/yjs/yjs.ts +9 -8
  285. package/dist/commit/style.css.map +0 -1
  286. package/dist/commit/style.js +0 -1
  287. package/dist/drop-indicator-DJq8pF92.js.map +0 -1
  288. package/dist/file-upload-I9m1EJAM.js.map +0 -1
  289. package/dist/file-upload-dr3IXUty.d.ts.map +0 -1
  290. package/dist/gap-cursor/style.css.map +0 -1
  291. package/dist/gap-cursor/style.js +0 -1
  292. package/dist/list/style.css.map +0 -1
  293. package/dist/list/style.js +0 -1
  294. package/dist/loro/style.css.map +0 -1
  295. package/dist/loro/style.js +0 -1
  296. package/dist/mark-paste-rule-n_2Ehmb5.js.map +0 -1
  297. package/dist/mark-rule-CUnXwBuy.js.map +0 -1
  298. package/dist/placeholder/style.css.map +0 -1
  299. package/dist/placeholder/style.js +0 -1
  300. package/dist/search/style.css.map +0 -1
  301. package/dist/search/style.js +0 -1
  302. package/dist/shiki-highlighter-chunk.d.ts +0 -19
  303. package/dist/shiki-highlighter-chunk.d.ts.map +0 -1
  304. package/dist/table/style.css.map +0 -1
  305. package/dist/table/style.js +0 -1
  306. package/dist/table-UJVYsrB7.js.map +0 -1
  307. package/dist/virtual-selection/style.css.map +0 -1
  308. package/dist/virtual-selection/style.js +0 -1
  309. package/dist/yjs/style.css.map +0 -1
  310. package/dist/yjs/style.js +0 -1
@@ -1,7 +1,6 @@
1
- import { OBJECT_REPLACEMENT_CHARACTER, defineFacet, defineFacetPayload, pluginFacet } from "@prosekit/core";
2
1
  import { Plugin, PluginKey } from "@prosekit/pm/state";
2
+ import { OBJECT_REPLACEMENT_CHARACTER, defineFacet, defineFacetPayload, pluginFacet } from "@prosekit/core";
3
3
  import { Decoration, DecorationSet } from "@prosekit/pm/view";
4
-
5
4
  //#region src/autocomplete/autocomplete-helpers.ts
6
5
  function defaultCanMatch({ state }) {
7
6
  const $pos = state.selection.$from;
@@ -25,7 +24,21 @@ function setTrMeta(tr, meta) {
25
24
  return tr.setMeta(pluginKey, meta);
26
25
  }
27
26
  const pluginKey = new PluginKey("prosekit-autocomplete");
28
-
27
+ //#endregion
28
+ //#region src/autocomplete/autocomplete-rule.ts
29
+ /**
30
+ * An autocomplete rule that can be used to create an autocomplete extension.
31
+ *
32
+ * @public
33
+ */
34
+ var AutocompleteRule = class {
35
+ constructor(options) {
36
+ this.regex = options.regex;
37
+ this.onMatch = options.onEnter;
38
+ this.onLeave = options.onLeave;
39
+ this.canMatch = options.canMatch ?? defaultCanMatch;
40
+ }
41
+ };
29
42
  //#endregion
30
43
  //#region src/autocomplete/autocomplete-plugin.ts
31
44
  /**
@@ -210,7 +223,6 @@ function mapMatching(matching, mapping) {
210
223
  to: mapping.map(matching.to, -1)
211
224
  };
212
225
  }
213
-
214
226
  //#endregion
215
227
  //#region src/autocomplete/autocomplete.ts
216
228
  /**
@@ -237,23 +249,7 @@ const autocompleteFacet = defineFacet({
237
249
  parent: pluginFacet,
238
250
  singleton: true
239
251
  });
240
-
241
- //#endregion
242
- //#region src/autocomplete/autocomplete-rule.ts
243
- /**
244
- * An autocomplete rule that can be used to create an autocomplete extension.
245
- *
246
- * @public
247
- */
248
- var AutocompleteRule = class {
249
- constructor(options) {
250
- this.regex = options.regex;
251
- this.onMatch = options.onEnter;
252
- this.onLeave = options.onLeave;
253
- this.canMatch = options.canMatch ?? defaultCanMatch;
254
- }
255
- };
256
-
257
252
  //#endregion
258
253
  export { AutocompleteRule, defineAutocomplete };
254
+
259
255
  //# sourceMappingURL=prosekit-extensions-autocomplete.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-autocomplete.js","names":[],"sources":["../src/autocomplete/autocomplete-helpers.ts","../src/autocomplete/autocomplete-plugin.ts","../src/autocomplete/autocomplete.ts","../src/autocomplete/autocomplete-rule.ts"],"sourcesContent":["import type { ResolvedPos } from '@prosekit/pm/model'\nimport { PluginKey, type EditorState, type Transaction } from '@prosekit/pm/state'\n\nimport type { AutocompleteRule } from './autocomplete-rule'\n\nexport function defaultCanMatch({ state }: { state: EditorState }): boolean {\n const $pos = state.selection.$from\n return !isInsideCodeBlock($pos) && !isInsideCodeMark($pos)\n}\n\nfunction isInsideCodeBlock($pos: ResolvedPos): boolean {\n for (let d = $pos.depth; d > 0; d--) {\n if ($pos.node(d).type.spec.code) {\n return true\n }\n }\n return false\n}\n\nfunction isInsideCodeMark($pos: ResolvedPos): boolean {\n for (const mark of $pos.marks()) {\n if (mark.type.spec.code) {\n return true\n }\n }\n return false\n}\n\n/**\n * @internal\n */\nexport interface PredictionPluginMatching {\n rule: AutocompleteRule\n from: number\n to: number\n match: RegExpExecArray\n}\n\n/**\n * @internal\n */\nexport interface PredictionPluginState {\n /**\n * The matching positions that should be ignored.\n */\n ignores: Array<number>\n\n /**\n * The current active matching.\n */\n matching: PredictionPluginMatching | null\n}\n\n/**\n * @internal\n */\nexport type PredictionTransactionMeta = {\n type: 'enter'\n matching: PredictionPluginMatching\n} | {\n type: 'leave'\n}\n\nexport function getPluginState(state: EditorState): PredictionPluginState | undefined {\n return pluginKey.getState(state)\n}\n\nexport function getTrMeta(tr: Transaction): PredictionTransactionMeta | undefined {\n return tr.getMeta(pluginKey) as PredictionTransactionMeta | undefined\n}\n\nexport function setTrMeta(\n tr: Transaction,\n meta: PredictionTransactionMeta,\n): Transaction {\n return tr.setMeta(pluginKey, meta)\n}\n\nexport const pluginKey: PluginKey<PredictionPluginState> = new PluginKey<PredictionPluginState>('prosekit-autocomplete')\n","import { OBJECT_REPLACEMENT_CHARACTER } from '@prosekit/core'\nimport type { ProseMirrorNode, ResolvedPos } from '@prosekit/pm/model'\nimport { Plugin, type EditorState, type Transaction } from '@prosekit/pm/state'\nimport type { Mapping } from '@prosekit/pm/transform'\nimport type { EditorView } from '@prosekit/pm/view'\nimport { Decoration, DecorationSet } from '@prosekit/pm/view'\n\nimport {\n getPluginState,\n getTrMeta,\n pluginKey,\n setTrMeta,\n type PredictionPluginMatching,\n type PredictionPluginState,\n type PredictionTransactionMeta,\n} from './autocomplete-helpers'\nimport type { AutocompleteRule } from './autocomplete-rule'\n\n/**\n * Creates a plugin that handles autocomplete functionality.\n *\n * Workflow:\n *\n * 1. {@link handleTextInput}: called when text is going to be input, but the\n * transaction is not yet created. Injects a new matching as a transaction\n * meta if applicable. This is the only place to create a new matching if\n * there is no existing matching.\n * 2. {@link handleTransaction}: called when a transaction is going to be\n * applied. Updates the plugin state based on the transaction. This step\n * determines if a matching should be created, updated or removed.\n * 3. {@link handleUpdate}: called when the editor state is updated. This is the\n * place to call `onMatch` and register `deleteMatch` and `ignoreMatch`\n * callbacks.\n * 4. {@link getDecorations}: creates the decorations for the current matching.\n */\nexport function createAutocompletePlugin({\n getRules,\n}: {\n getRules: () => AutocompleteRule[]\n}): Plugin {\n return new Plugin<PredictionPluginState>({\n key: pluginKey,\n\n state: {\n init: (): PredictionPluginState => {\n return { ignores: [], matching: null }\n },\n apply: (tr, prevValue, oldState, newState): PredictionPluginState => {\n return handleTransaction(tr, prevValue, oldState, newState, getRules)\n },\n },\n\n view: () => ({\n update: handleUpdate,\n }),\n\n props: {\n handleTextInput: (view, from, to, textAdded, getTr) => {\n const meta = handleTextInput(view, from, to, textAdded, getRules)\n if (meta) {\n const tr = getTr()\n setTrMeta(tr, meta)\n view.dispatch(tr)\n return true\n }\n return false\n },\n decorations: getDecorations,\n },\n })\n}\n\nfunction handleTextInput(\n view: EditorView,\n from: number,\n to: number,\n textAdded: string,\n getRules: () => AutocompleteRule[],\n): PredictionTransactionMeta | undefined {\n // Only handle insertions\n if (from !== to) {\n return\n }\n\n const textBackward = getTextBackward(view.state.doc.resolve(from))\n const textFull = textBackward + textAdded\n const textTo = to + textAdded.length\n const textFrom = textTo - textFull.length\n\n const pluginState = getPluginState(view.state)\n const ignores = pluginState?.ignores ?? []\n\n const currMatching = matchRule(\n view.state,\n getRules(),\n textFull,\n textFrom,\n textTo,\n ignores,\n )\n\n if (currMatching) {\n return { type: 'enter', matching: currMatching }\n }\n}\n\nfunction handleTransaction(\n tr: Transaction,\n prevValue: PredictionPluginState,\n oldState: EditorState,\n newState: EditorState,\n getRules: () => AutocompleteRule[],\n): PredictionPluginState {\n const meta = getTrMeta(tr)\n\n if (\n !meta\n && !tr.docChanged\n && oldState.selection.eq(newState.selection)\n ) {\n // No changes\n return prevValue\n }\n\n // Handle position mapping changes\n const ignoreSet = new Set<number>()\n for (const ignore of prevValue.ignores) {\n const result = tr.mapping.mapResult(ignore)\n if (!result.deletedBefore && !result.deletedAfter) {\n ignoreSet.add(result.pos)\n }\n }\n const ignores = Array.from(ignoreSet)\n\n const prevMatching = prevValue.matching && mapMatching(prevValue.matching, tr.mapping)\n\n // If there is no new matching from `handleTextInput`\n if (!meta) {\n if (!prevMatching) {\n return { matching: null, ignores }\n }\n\n const { selection } = newState\n // If the text selection is before the matching or after the matching,\n // we leave the matching\n if (selection.to < prevMatching.from || selection.from > prevMatching.to) {\n ignores.push(prevMatching.from)\n return { matching: null, ignores }\n }\n\n // Get the text between the existing matching\n const text = getTextBetween(newState.doc, prevMatching.from, prevMatching.to)\n // Check the text again to see if it still matches the rule\n const currMatching = matchRule(\n newState,\n getRules(),\n text,\n prevMatching.from,\n prevMatching.to,\n ignores,\n )\n return { matching: currMatching ?? null, ignores }\n }\n\n // If a new matching is being entered from `handleTextInput`\n if (meta.type === 'enter') {\n // Ignore the previous matching if it is not the same as the new matching\n if (prevMatching && prevMatching.from !== meta.matching.from) {\n ignores.push(prevMatching.from)\n }\n\n // Return the new matching\n return { matching: meta.matching, ignores }\n }\n\n // If a matching is being exited\n if (meta.type === 'leave') {\n if (prevMatching) {\n ignores.push(prevMatching.from)\n }\n return { matching: null, ignores }\n }\n\n throw new Error(`Invalid transaction meta: ${meta satisfies never}`)\n}\n\nfunction handleUpdate(view: EditorView, prevState: EditorState): void {\n const prevValue = getPluginState(prevState)\n const currValue = getPluginState(view.state)\n\n if (!prevValue || !currValue) {\n // Should not happen\n return\n }\n\n const prevMatching = prevValue.matching\n const currMatching = currValue.matching\n\n // Deactivate the previous rule\n if (prevMatching && prevMatching.rule !== currMatching?.rule) {\n prevMatching.rule.onLeave?.()\n }\n\n // Activate the current rule\n if (currMatching) {\n const { from, to, match, rule } = currMatching\n\n const textSnapshot = getTextBetween(view.state.doc, from, to)\n\n const deleteMatch = () => {\n if (getTextBetween(view.state.doc, from, to) === textSnapshot) {\n view.dispatch(view.state.tr.delete(from, to))\n }\n }\n\n const ignoreMatch = () => {\n view.dispatch(\n setTrMeta(view.state.tr, { type: 'leave' }),\n )\n }\n\n rule.onMatch({\n state: view.state,\n match,\n from,\n to,\n deleteMatch,\n ignoreMatch,\n })\n }\n}\n\nfunction getDecorations(state: EditorState): DecorationSet | null {\n const pluginState = getPluginState(state)\n if (pluginState?.matching) {\n const { from, to, match } = pluginState.matching\n const deco = Decoration.inline(from, to, {\n 'class': 'prosekit-autocomplete-match',\n 'data-autocomplete-match-text': match[0],\n })\n return DecorationSet.create(state.doc, [deco])\n }\n return null\n}\n\nconst MAX_MATCH = 200\n\n/** Get the text before the given position at the current block. */\nfunction getTextBackward($pos: ResolvedPos): string {\n const parentOffset: number = $pos.parentOffset\n return getTextBetween(\n $pos.parent,\n Math.max(0, parentOffset - MAX_MATCH),\n parentOffset,\n )\n}\n\nfunction getTextBetween(node: ProseMirrorNode, from: number, to: number): string {\n return node.textBetween(\n from,\n to,\n null,\n OBJECT_REPLACEMENT_CHARACTER,\n )\n}\n\nfunction matchRule(\n state: EditorState,\n rules: AutocompleteRule[],\n text: string,\n textFrom: number,\n textTo: number,\n ignores: Array<number>,\n): PredictionPluginMatching | undefined {\n // Find the rightmost ignore point within the text range\n let maxIgnore = -1\n for (const ignore of ignores) {\n if (ignore >= textFrom && ignore < textTo && ignore > maxIgnore) {\n maxIgnore = ignore\n }\n }\n\n // If an ignore point is within the text range, we ignore the text to the left\n // of the ignore point (including the character right after the ignore point).\n if (maxIgnore >= 0) {\n const cut = maxIgnore + 1 - textFrom\n text = text.slice(cut)\n textFrom += cut\n }\n\n if (textFrom >= textTo || !text) {\n return\n }\n\n for (const rule of rules) {\n if (!rule.canMatch({ state })) {\n continue\n }\n\n rule.regex.lastIndex = 0\n const match = rule.regex.exec(text)\n if (!match) {\n continue\n }\n\n const matchTo = textTo\n const matchFrom = textFrom + match.index\n\n return { rule, match, from: matchFrom, to: matchTo }\n }\n}\n\nfunction mapMatching(matching: PredictionPluginMatching, mapping: Mapping): PredictionPluginMatching {\n return {\n rule: matching.rule,\n match: matching.match,\n from: mapping.map(matching.from),\n to: mapping.map(matching.to, -1),\n }\n}\n","import { defineFacet, defineFacetPayload, pluginFacet, type Extension, type PluginPayload } from '@prosekit/core'\n\nimport { createAutocompletePlugin } from './autocomplete-plugin'\nimport type { AutocompleteRule } from './autocomplete-rule'\n\n/**\n * Defines an autocomplete extension that executes logic when the text before\n * the cursor matches the given regular expression.\n *\n * When a match is found, an inline decoration is applied to the matched text\n * with the class `prosekit-autocomplete-match` and a `data-autocomplete-match-text`\n * attribute containing the full matched string.\n */\nexport function defineAutocomplete(rule: AutocompleteRule): Extension {\n return defineFacetPayload(autocompleteFacet, [rule])\n}\n\nconst autocompleteFacet = defineFacet<AutocompleteRule, PluginPayload>({\n reduce: () => {\n let rules: AutocompleteRule[] = []\n const getRules = () => rules\n const plugin = createAutocompletePlugin({ getRules })\n\n return function reducer(inputs) {\n rules = inputs\n return plugin\n }\n },\n parent: pluginFacet,\n singleton: true,\n})\n","import type { EditorState } from '@prosekit/pm/state'\n\nimport { defaultCanMatch } from './autocomplete-helpers'\n\n/**\n * Options for the {@link MatchHandler} callback.\n */\nexport interface MatchHandlerOptions {\n /**\n * The editor state.\n */\n state: EditorState\n\n /**\n * The result of `RegExp.exec`.\n */\n match: RegExpExecArray\n\n /**\n * The start position of the matched text.\n */\n from: number\n\n /**\n * The end position of the matched text.\n */\n to: number\n\n /**\n * Call this function to ignore the match. You probably want to call this\n * function when the user presses the `Escape` key.\n */\n ignoreMatch: () => void\n\n /**\n * Call this function to delete the matched text. For example, in a slash\n * menu, you might want to delete the matched text first then do something\n * else when the user presses the `Enter` key.\n */\n deleteMatch: () => void\n}\n\n/**\n * A callback that is called when the rule starts to match, and also on\n * subsequent updates while the rule continues to match.\n */\nexport type MatchHandler = (options: MatchHandlerOptions) => void\n\n/**\n * Options for the {@link CanMatchPredicate} callback.\n */\nexport interface CanMatchOptions {\n /**\n * The editor state.\n */\n state: EditorState\n}\n\n/**\n * A predicate to determine if the rule can be applied in the current editor state.\n */\nexport type CanMatchPredicate = (options: CanMatchOptions) => boolean\n\n/**\n * Options for creating an {@link AutocompleteRule}\n */\nexport interface AutocompleteRuleOptions {\n /**\n * The regular expression to match against the text before the cursor. The\n * last match before the cursor is used.\n *\n * For a slash menu, you might use `/(?<!\\S)\\/(\\S.*)?$/u`.\n * For a mention, you might use `/@\\w*$/`\n */\n regex: RegExp\n\n /**\n * A callback that is called when the rule starts to match, and also on\n * subsequent updates while the rule continues to match.\n */\n onEnter: MatchHandler\n\n /**\n * A callback that is called when the rule stops matching.\n */\n onLeave?: VoidFunction\n\n /**\n * A predicate to determine if the rule can be applied in the current editor\n * state. If not provided, it defaults to only allowing matches that are not\n * inside a code block or code mark.\n */\n canMatch?: CanMatchPredicate\n}\n\n/**\n * An autocomplete rule that can be used to create an autocomplete extension.\n *\n * @public\n */\nexport class AutocompleteRule {\n /** @internal */\n readonly regex: RegExp\n /** @internal */\n readonly onMatch: MatchHandler\n /** @internal */\n readonly onLeave?: VoidFunction\n /** @internal */\n readonly canMatch: (options: { state: EditorState }) => boolean\n\n constructor(options: AutocompleteRuleOptions) {\n this.regex = options.regex\n this.onMatch = options.onEnter\n this.onLeave = options.onLeave\n this.canMatch = options.canMatch ?? defaultCanMatch\n }\n}\n"],"mappings":";;;;;AAKA,SAAgB,gBAAgB,EAAE,SAA0C;CAC1E,MAAM,OAAO,MAAM,UAAU;AAC7B,QAAO,CAAC,kBAAkB,KAAK,IAAI,CAAC,iBAAiB,KAAK;;AAG5D,SAAS,kBAAkB,MAA4B;AACrD,MAAK,IAAI,IAAI,KAAK,OAAO,IAAI,GAAG,IAC9B,KAAI,KAAK,KAAK,EAAE,CAAC,KAAK,KAAK,KACzB,QAAO;AAGX,QAAO;;AAGT,SAAS,iBAAiB,MAA4B;AACpD,MAAK,MAAM,QAAQ,KAAK,OAAO,CAC7B,KAAI,KAAK,KAAK,KAAK,KACjB,QAAO;AAGX,QAAO;;AAsCT,SAAgB,eAAe,OAAuD;AACpF,QAAO,UAAU,SAAS,MAAM;;AAGlC,SAAgB,UAAU,IAAwD;AAChF,QAAO,GAAG,QAAQ,UAAU;;AAG9B,SAAgB,UACd,IACA,MACa;AACb,QAAO,GAAG,QAAQ,WAAW,KAAK;;AAGpC,MAAa,YAA8C,IAAI,UAAiC,wBAAwB;;;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EAGF,MAAM,UAAU;AAGhB,SAAO;GAAE;GAAM;GAAO,MAFJ,WAAW,MAAM;GAEI,IAAI;GAAS;;;AAIxD,SAAS,YAAY,UAAoC,SAA4C;AACnG,QAAO;EACL,MAAM,SAAS;EACf,OAAO,SAAS;EAChB,MAAM,QAAQ,IAAI,SAAS,KAAK;EAChC,IAAI,QAAQ,IAAI,SAAS,IAAI,GAAG;EACjC;;;;;;;;;;;;;ACjTH,SAAgB,mBAAmB,MAAmC;AACpE,QAAO,mBAAmB,mBAAmB,CAAC,KAAK,CAAC;;AAGtD,MAAM,oBAAoB,YAA6C;CACrE,cAAc;EACZ,IAAI,QAA4B,EAAE;EAClC,MAAM,iBAAiB;EACvB,MAAM,SAAS,yBAAyB,EAAE,UAAU,CAAC;AAErD,SAAO,SAAS,QAAQ,QAAQ;AAC9B,WAAQ;AACR,UAAO;;;CAGX,QAAQ;CACR,WAAW;CACZ,CAAC;;;;;;;;;ACsEF,IAAa,mBAAb,MAA8B;CAU5B,YAAY,SAAkC;AAC5C,OAAK,QAAQ,QAAQ;AACrB,OAAK,UAAU,QAAQ;AACvB,OAAK,UAAU,QAAQ;AACvB,OAAK,WAAW,QAAQ,YAAY"}
1
+ {"version":3,"file":"prosekit-extensions-autocomplete.js","names":[],"sources":["../src/autocomplete/autocomplete-helpers.ts","../src/autocomplete/autocomplete-rule.ts","../src/autocomplete/autocomplete-plugin.ts","../src/autocomplete/autocomplete.ts"],"sourcesContent":["import type { ResolvedPos } from '@prosekit/pm/model'\nimport { PluginKey, type EditorState, type Transaction } from '@prosekit/pm/state'\n\nimport type { AutocompleteRule } from './autocomplete-rule.ts'\n\nexport function defaultCanMatch({ state }: { state: EditorState }): boolean {\n const $pos = state.selection.$from\n return !isInsideCodeBlock($pos) && !isInsideCodeMark($pos)\n}\n\nfunction isInsideCodeBlock($pos: ResolvedPos): boolean {\n for (let d = $pos.depth; d > 0; d--) {\n if ($pos.node(d).type.spec.code) {\n return true\n }\n }\n return false\n}\n\nfunction isInsideCodeMark($pos: ResolvedPos): boolean {\n for (const mark of $pos.marks()) {\n if (mark.type.spec.code) {\n return true\n }\n }\n return false\n}\n\n/**\n * @internal\n */\nexport interface PredictionPluginMatching {\n rule: AutocompleteRule\n from: number\n to: number\n match: RegExpExecArray\n}\n\n/**\n * @internal\n */\nexport interface PredictionPluginState {\n /**\n * The matching positions that should be ignored.\n */\n ignores: Array<number>\n\n /**\n * The current active matching.\n */\n matching: PredictionPluginMatching | null\n}\n\n/**\n * @internal\n */\nexport type PredictionTransactionMeta = {\n type: 'enter'\n matching: PredictionPluginMatching\n} | {\n type: 'leave'\n}\n\nexport function getPluginState(state: EditorState): PredictionPluginState | undefined {\n return pluginKey.getState(state)\n}\n\nexport function getTrMeta(tr: Transaction): PredictionTransactionMeta | undefined {\n return tr.getMeta(pluginKey) as PredictionTransactionMeta | undefined\n}\n\nexport function setTrMeta(\n tr: Transaction,\n meta: PredictionTransactionMeta,\n): Transaction {\n return tr.setMeta(pluginKey, meta)\n}\n\nexport const pluginKey: PluginKey<PredictionPluginState> = new PluginKey<PredictionPluginState>('prosekit-autocomplete')\n","import type { EditorState } from '@prosekit/pm/state'\n\nimport { defaultCanMatch } from './autocomplete-helpers.ts'\n\n/**\n * Options for the {@link MatchHandler} callback.\n */\nexport interface MatchHandlerOptions {\n /**\n * The editor state.\n */\n state: EditorState\n\n /**\n * The result of `RegExp.exec`.\n */\n match: RegExpExecArray\n\n /**\n * The start position of the matched text.\n */\n from: number\n\n /**\n * The end position of the matched text.\n */\n to: number\n\n /**\n * Call this function to ignore the match. You probably want to call this\n * function when the user presses the `Escape` key.\n */\n ignoreMatch: () => void\n\n /**\n * Call this function to delete the matched text. For example, in a slash\n * menu, you might want to delete the matched text first then do something\n * else when the user presses the `Enter` key.\n */\n deleteMatch: () => void\n}\n\n/**\n * A callback that is called when the rule starts to match, and also on\n * subsequent updates while the rule continues to match.\n */\nexport type MatchHandler = (options: MatchHandlerOptions) => void\n\n/**\n * Options for the {@link CanMatchPredicate} callback.\n */\nexport interface CanMatchOptions {\n /**\n * The editor state.\n */\n state: EditorState\n}\n\n/**\n * A predicate to determine if the rule can be applied in the current editor state.\n */\nexport type CanMatchPredicate = (options: CanMatchOptions) => boolean\n\n/**\n * Options for creating an {@link AutocompleteRule}\n */\nexport interface AutocompleteRuleOptions {\n /**\n * The regular expression to match against the text before the cursor. The\n * last match before the cursor is used.\n *\n * For a slash menu, you might use `/(?<!\\S)\\/(\\S.*)?$/u`.\n * For a mention, you might use `/@\\w*$/`\n */\n regex: RegExp\n\n /**\n * A callback that is called when the rule starts to match, and also on\n * subsequent updates while the rule continues to match.\n */\n onEnter: MatchHandler\n\n /**\n * A callback that is called when the rule stops matching.\n */\n onLeave?: VoidFunction\n\n /**\n * A predicate to determine if the rule can be applied in the current editor\n * state. If not provided, it defaults to only allowing matches that are not\n * inside a code block or code mark.\n */\n canMatch?: CanMatchPredicate\n}\n\n/**\n * An autocomplete rule that can be used to create an autocomplete extension.\n *\n * @public\n */\nexport class AutocompleteRule {\n /** @internal */\n readonly regex: RegExp\n /** @internal */\n readonly onMatch: MatchHandler\n /** @internal */\n readonly onLeave?: VoidFunction\n /** @internal */\n readonly canMatch: (options: { state: EditorState }) => boolean\n\n constructor(options: AutocompleteRuleOptions) {\n this.regex = options.regex\n this.onMatch = options.onEnter\n this.onLeave = options.onLeave\n this.canMatch = options.canMatch ?? defaultCanMatch\n }\n}\n","import { OBJECT_REPLACEMENT_CHARACTER } from '@prosekit/core'\nimport type { ProseMirrorNode, ResolvedPos } from '@prosekit/pm/model'\nimport { Plugin, type EditorState, type Transaction } from '@prosekit/pm/state'\nimport type { Mapping } from '@prosekit/pm/transform'\nimport type { EditorView } from '@prosekit/pm/view'\nimport { Decoration, DecorationSet } from '@prosekit/pm/view'\n\nimport {\n getPluginState,\n getTrMeta,\n pluginKey,\n setTrMeta,\n type PredictionPluginMatching,\n type PredictionPluginState,\n type PredictionTransactionMeta,\n} from './autocomplete-helpers.ts'\nimport type { AutocompleteRule } from './autocomplete-rule.ts'\n\n/**\n * Creates a plugin that handles autocomplete functionality.\n *\n * Workflow:\n *\n * 1. {@link handleTextInput}: called when text is going to be input, but the\n * transaction is not yet created. Injects a new matching as a transaction\n * meta if applicable. This is the only place to create a new matching if\n * there is no existing matching.\n * 2. {@link handleTransaction}: called when a transaction is going to be\n * applied. Updates the plugin state based on the transaction. This step\n * determines if a matching should be created, updated or removed.\n * 3. {@link handleUpdate}: called when the editor state is updated. This is the\n * place to call `onMatch` and register `deleteMatch` and `ignoreMatch`\n * callbacks.\n * 4. {@link getDecorations}: creates the decorations for the current matching.\n */\nexport function createAutocompletePlugin({\n getRules,\n}: {\n getRules: () => AutocompleteRule[]\n}): Plugin {\n return new Plugin<PredictionPluginState>({\n key: pluginKey,\n\n state: {\n init: (): PredictionPluginState => {\n return { ignores: [], matching: null }\n },\n apply: (tr, prevValue, oldState, newState): PredictionPluginState => {\n return handleTransaction(tr, prevValue, oldState, newState, getRules)\n },\n },\n\n view: () => ({\n update: handleUpdate,\n }),\n\n props: {\n handleTextInput: (view, from, to, textAdded, getTr) => {\n const meta = handleTextInput(view, from, to, textAdded, getRules)\n if (meta) {\n const tr = getTr()\n setTrMeta(tr, meta)\n view.dispatch(tr)\n return true\n }\n return false\n },\n decorations: getDecorations,\n },\n })\n}\n\nfunction handleTextInput(\n view: EditorView,\n from: number,\n to: number,\n textAdded: string,\n getRules: () => AutocompleteRule[],\n): PredictionTransactionMeta | undefined {\n // Only handle insertions\n if (from !== to) {\n return\n }\n\n const textBackward = getTextBackward(view.state.doc.resolve(from))\n const textFull = textBackward + textAdded\n const textTo = to + textAdded.length\n const textFrom = textTo - textFull.length\n\n const pluginState = getPluginState(view.state)\n const ignores = pluginState?.ignores ?? []\n\n const currMatching = matchRule(\n view.state,\n getRules(),\n textFull,\n textFrom,\n textTo,\n ignores,\n )\n\n if (currMatching) {\n return { type: 'enter', matching: currMatching }\n }\n}\n\nfunction handleTransaction(\n tr: Transaction,\n prevValue: PredictionPluginState,\n oldState: EditorState,\n newState: EditorState,\n getRules: () => AutocompleteRule[],\n): PredictionPluginState {\n const meta = getTrMeta(tr)\n\n if (\n !meta\n && !tr.docChanged\n && oldState.selection.eq(newState.selection)\n ) {\n // No changes\n return prevValue\n }\n\n // Handle position mapping changes\n const ignoreSet = new Set<number>()\n for (const ignore of prevValue.ignores) {\n const result = tr.mapping.mapResult(ignore)\n if (!result.deletedBefore && !result.deletedAfter) {\n ignoreSet.add(result.pos)\n }\n }\n const ignores = Array.from(ignoreSet)\n\n const prevMatching = prevValue.matching && mapMatching(prevValue.matching, tr.mapping)\n\n // If there is no new matching from `handleTextInput`\n if (!meta) {\n if (!prevMatching) {\n return { matching: null, ignores }\n }\n\n const { selection } = newState\n // If the text selection is before the matching or after the matching,\n // we leave the matching\n if (selection.to < prevMatching.from || selection.from > prevMatching.to) {\n ignores.push(prevMatching.from)\n return { matching: null, ignores }\n }\n\n // Get the text between the existing matching\n const text = getTextBetween(newState.doc, prevMatching.from, prevMatching.to)\n // Check the text again to see if it still matches the rule\n const currMatching = matchRule(\n newState,\n getRules(),\n text,\n prevMatching.from,\n prevMatching.to,\n ignores,\n )\n return { matching: currMatching ?? null, ignores }\n }\n\n // If a new matching is being entered from `handleTextInput`\n if (meta.type === 'enter') {\n // Ignore the previous matching if it is not the same as the new matching\n if (prevMatching && prevMatching.from !== meta.matching.from) {\n ignores.push(prevMatching.from)\n }\n\n // Return the new matching\n return { matching: meta.matching, ignores }\n }\n\n // If a matching is being exited\n if (meta.type === 'leave') {\n if (prevMatching) {\n ignores.push(prevMatching.from)\n }\n return { matching: null, ignores }\n }\n\n throw new Error(`Invalid transaction meta: ${meta satisfies never}`)\n}\n\nfunction handleUpdate(view: EditorView, prevState: EditorState): void {\n const prevValue = getPluginState(prevState)\n const currValue = getPluginState(view.state)\n\n if (!prevValue || !currValue) {\n // Should not happen\n return\n }\n\n const prevMatching = prevValue.matching\n const currMatching = currValue.matching\n\n // Deactivate the previous rule\n if (prevMatching && prevMatching.rule !== currMatching?.rule) {\n prevMatching.rule.onLeave?.()\n }\n\n // Activate the current rule\n if (currMatching) {\n const { from, to, match, rule } = currMatching\n\n const textSnapshot = getTextBetween(view.state.doc, from, to)\n\n const deleteMatch = () => {\n if (getTextBetween(view.state.doc, from, to) === textSnapshot) {\n view.dispatch(view.state.tr.delete(from, to))\n }\n }\n\n const ignoreMatch = () => {\n view.dispatch(\n setTrMeta(view.state.tr, { type: 'leave' }),\n )\n }\n\n rule.onMatch({\n state: view.state,\n match,\n from,\n to,\n deleteMatch,\n ignoreMatch,\n })\n }\n}\n\nfunction getDecorations(state: EditorState): DecorationSet | null {\n const pluginState = getPluginState(state)\n if (pluginState?.matching) {\n const { from, to, match } = pluginState.matching\n const deco = Decoration.inline(from, to, {\n 'class': 'prosekit-autocomplete-match',\n 'data-autocomplete-match-text': match[0],\n })\n return DecorationSet.create(state.doc, [deco])\n }\n return null\n}\n\nconst MAX_MATCH = 200\n\n/** Get the text before the given position at the current block. */\nfunction getTextBackward($pos: ResolvedPos): string {\n const parentOffset: number = $pos.parentOffset\n return getTextBetween(\n $pos.parent,\n Math.max(0, parentOffset - MAX_MATCH),\n parentOffset,\n )\n}\n\nfunction getTextBetween(node: ProseMirrorNode, from: number, to: number): string {\n return node.textBetween(\n from,\n to,\n null,\n OBJECT_REPLACEMENT_CHARACTER,\n )\n}\n\nfunction matchRule(\n state: EditorState,\n rules: AutocompleteRule[],\n text: string,\n textFrom: number,\n textTo: number,\n ignores: Array<number>,\n): PredictionPluginMatching | undefined {\n // Find the rightmost ignore point within the text range\n let maxIgnore = -1\n for (const ignore of ignores) {\n if (ignore >= textFrom && ignore < textTo && ignore > maxIgnore) {\n maxIgnore = ignore\n }\n }\n\n // If an ignore point is within the text range, we ignore the text to the left\n // of the ignore point (including the character right after the ignore point).\n if (maxIgnore >= 0) {\n const cut = maxIgnore + 1 - textFrom\n text = text.slice(cut)\n textFrom += cut\n }\n\n if (textFrom >= textTo || !text) {\n return\n }\n\n for (const rule of rules) {\n if (!rule.canMatch({ state })) {\n continue\n }\n\n rule.regex.lastIndex = 0\n const match = rule.regex.exec(text)\n if (!match) {\n continue\n }\n\n const matchTo = textTo\n const matchFrom = textFrom + match.index\n\n return { rule, match, from: matchFrom, to: matchTo }\n }\n}\n\nfunction mapMatching(matching: PredictionPluginMatching, mapping: Mapping): PredictionPluginMatching {\n return {\n rule: matching.rule,\n match: matching.match,\n from: mapping.map(matching.from),\n to: mapping.map(matching.to, -1),\n }\n}\n","import { defineFacet, defineFacetPayload, pluginFacet, type Extension, type PluginPayload } from '@prosekit/core'\n\nimport { createAutocompletePlugin } from './autocomplete-plugin.ts'\nimport type { AutocompleteRule } from './autocomplete-rule.ts'\n\n/**\n * Defines an autocomplete extension that executes logic when the text before\n * the cursor matches the given regular expression.\n *\n * When a match is found, an inline decoration is applied to the matched text\n * with the class `prosekit-autocomplete-match` and a `data-autocomplete-match-text`\n * attribute containing the full matched string.\n */\nexport function defineAutocomplete(rule: AutocompleteRule): Extension {\n return defineFacetPayload(autocompleteFacet, [rule])\n}\n\nconst autocompleteFacet = defineFacet<AutocompleteRule, PluginPayload>({\n reduce: () => {\n let rules: AutocompleteRule[] = []\n const getRules = () => rules\n const plugin = createAutocompletePlugin({ getRules })\n\n return function reducer(inputs) {\n rules = inputs\n return plugin\n }\n },\n parent: pluginFacet,\n singleton: true,\n})\n"],"mappings":";;;;AAKA,SAAgB,gBAAgB,EAAE,SAA0C;CAC1E,MAAM,OAAO,MAAM,UAAU;AAC7B,QAAO,CAAC,kBAAkB,KAAK,IAAI,CAAC,iBAAiB,KAAK;;AAG5D,SAAS,kBAAkB,MAA4B;AACrD,MAAK,IAAI,IAAI,KAAK,OAAO,IAAI,GAAG,IAC9B,KAAI,KAAK,KAAK,EAAE,CAAC,KAAK,KAAK,KACzB,QAAO;AAGX,QAAO;;AAGT,SAAS,iBAAiB,MAA4B;AACpD,MAAK,MAAM,QAAQ,KAAK,OAAO,CAC7B,KAAI,KA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ACA,OACA,MACA,UACA,QACA,SACsC;CAEtC,IAAI,YAAY;AAChB,MAAK,MAAM,UAAU,QACnB,KAAI,UAAU,YAAY,SAAS,UAAU,SAAS,UACpD,aAAY;AAMhB,KAAI,aAAa,GAAG;EAClB,MAAM,MAAM,YAAY,IAAI;AAC5B,SAAO,KAAK,MAAM,IAAI;AACtB,cAAY;;AAGd,KAAI,YAAY,UAAU,CAAC,KACzB;AAGF,MAAK,MAAM,QAAQ,OAAO;AACxB,MAAI,CAAC,KAAK,SAAS,EAAE,OAAO,CAAC,CAC3B;AAGF,OAAK,MAAM,YAAY;EACvB,MAAM,QAAQ,KAAK,MAAM,KAAK,KAAK;AACnC,MAAI,CAAC,MACH;EAGF,MAAM,UAAU;AAGhB,SAAO;GAAE;GAAM;GAAO,MAFJ,WAAW,MAAM;GAEI,IAAI;GAAS;;;AAIxD,SAAS,YAAY,UAAoC,SAA4C;AACnG,QAAO;EACL,MAAM,SAAS;EACf,OAAO,SAAS;EAChB,MAAM,QAAQ,IAAI,SAAS,KAAK;EAChC,IAAI,QAAQ,IAAI,SAAS,IAAI,GAAG;EACjC;;;;;;;;;;;;ACjTH,SAAgB,mBAAmB,MAAmC;AACpE,QAAO,mBAAmB,mBAAmB,CAAC,KAAK,CAAC;;AAGtD,MAAM,oBAAoB,YAA6C;CACrE,cAAc;EACZ,IAAI,QAA4B,EAAE;EAClC,MAAM,iBAAiB;EACvB,MAAM,SAAS,yBAAyB,EAAE,UAAU,CAAC;AAErD,SAAO,SAAS,QAAQ,QAAQ;AAC9B,WAAQ;AACR,UAAO;;;CAGX,QAAQ;CACR,WAAW;CACZ,CAAC"}
@@ -1,5 +1,5 @@
1
- import { Extension, Union } from "@prosekit/core";
2
1
  import { Command } from "@prosekit/pm/state";
2
+ import { Extension, Union } from "@prosekit/core";
3
3
 
4
4
  //#region src/background-color/background-color-spec.d.ts
5
5
  /**
@@ -1,5 +1,4 @@
1
1
  import { addMark, defineCommands, defineMarkSpec, removeMark, union } from "@prosekit/core";
2
-
3
2
  //#region src/background-color/background-color-commands.ts
4
3
  /**
5
4
  * @internal
@@ -25,7 +24,6 @@ function defineBackgroundColorCommands() {
25
24
  removeBackgroundColor
26
25
  });
27
26
  }
28
-
29
27
  //#endregion
30
28
  //#region src/background-color/background-color-spec.ts
31
29
  /**
@@ -59,7 +57,6 @@ function defineBackgroundColorSpec() {
59
57
  }
60
58
  });
61
59
  }
62
-
63
60
  //#endregion
64
61
  //#region src/background-color/background-color.ts
65
62
  /**
@@ -70,7 +67,7 @@ function defineBackgroundColorSpec() {
70
67
  function defineBackgroundColor() {
71
68
  return union(defineBackgroundColorSpec(), defineBackgroundColorCommands());
72
69
  }
73
-
74
70
  //#endregion
75
71
  export { addBackgroundColor, defineBackgroundColor, defineBackgroundColorCommands, defineBackgroundColorSpec, removeBackgroundColor };
72
+
76
73
  //# sourceMappingURL=prosekit-extensions-background-color.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-background-color.js","names":[],"sources":["../src/background-color/background-color-commands.ts","../src/background-color/background-color-spec.ts","../src/background-color/background-color.ts"],"sourcesContent":["import { addMark, defineCommands, removeMark, type Extension } from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\n\nimport type { BackgroundColorAttrs } from './background-color-spec'\n\n/**\n * @internal\n */\nexport function addBackgroundColor(attrs: BackgroundColorAttrs): Command {\n return addMark({ type: 'backgroundColor', attrs })\n}\n\n/**\n * @internal\n */\nexport function removeBackgroundColor(): Command {\n return removeMark({ type: 'backgroundColor' })\n}\n\n/**\n * @internal\n */\nexport type BackgroundColorCommandsExtension = Extension<{\n Commands: {\n addBackgroundColor: [attrs: BackgroundColorAttrs]\n removeBackgroundColor: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBackgroundColorCommands(): BackgroundColorCommandsExtension {\n return defineCommands({ addBackgroundColor, removeBackgroundColor })\n}\n","import { defineMarkSpec, type Extension } from '@prosekit/core'\n\n/**\n * Attributes for the `backgroundColor` mark.\n *\n * @public\n */\nexport interface BackgroundColorAttrs {\n color: string\n}\n\n/**\n * @internal\n */\nexport type BackgroundColorSpecExtension = Extension<{\n Marks: {\n backgroundColor: BackgroundColorAttrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBackgroundColorSpec(): BackgroundColorSpecExtension {\n return defineMarkSpec<'backgroundColor', BackgroundColorAttrs>({\n name: 'backgroundColor',\n attrs: {\n color: {\n validate: 'string',\n },\n },\n parseDOM: [\n {\n tag: ':where([style*=\"background-color:\"], [data-background-color])',\n getAttrs: (node): BackgroundColorAttrs | false => {\n // When both `data-background-color` and `style=\"background-color\"` are present, we\n // prioritize the `data-background-color` attribute. This avoids the\n // browser's default behavior of changing hex colors to rgba in style\n // attribute.\n const value = node.getAttribute('data-background-color')\n if (value && value !== 'inherit') {\n return { color: value }\n }\n const color = node.style.backgroundColor\n if (color && color !== 'inherit') {\n return { color }\n }\n return false\n },\n consuming: false,\n },\n ],\n toDOM(mark) {\n const color = (mark.attrs as BackgroundColorAttrs).color\n return ['span', { 'style': `background-color: ${color};`, 'data-background-color': color }, 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineBackgroundColorCommands, type BackgroundColorCommandsExtension } from './background-color-commands'\nimport { defineBackgroundColorSpec, type BackgroundColorSpecExtension } from './background-color-spec'\n\n/**\n * @internal\n */\nexport type BackgroundColorExtension = Union<[BackgroundColorSpecExtension, BackgroundColorCommandsExtension]>\n\n/**\n * Defines the `backgroundColor` mark and some commands for it.\n *\n * @public\n */\nexport function defineBackgroundColor(): BackgroundColorExtension {\n return union(\n defineBackgroundColorSpec(),\n defineBackgroundColorCommands(),\n )\n}\n"],"mappings":";;;;;;AAQA,SAAgB,mBAAmB,OAAsC;AACvE,QAAO,QAAQ;EAAE,MAAM;EAAmB;EAAO,CAAC;;;;;AAMpD,SAAgB,wBAAiC;AAC/C,QAAO,WAAW,EAAE,MAAM,mBAAmB,CAAC;;;;;AAgBhD,SAAgB,gCAAkE;AAChF,QAAO,eAAe;EAAE;EAAoB;EAAuB,CAAC;;;;;;;;ACVtE,SAAgB,4BAA0D;AACxE,QAAO,eAAwD;EAC7D,MAAM;EACN,OAAO,EACL,OAAO,EACL,UAAU,UACX,EACF;EACD,UAAU,CACR;GACE,KAAK;GACL,WAAW,SAAuC;IAKhD,MAAM,QAAQ,KAAK,aAAa,wBAAwB;AACxD,QAAI,SAAS,UAAU,UACrB,QAAO,EAAE,OAAO,OAAO;IAEzB,MAAM,QAAQ,KAAK,MAAM;AACzB,QAAI,SAAS,UAAU,UACrB,QAAO,EAAE,OAAO;AAElB,WAAO;;GAET,WAAW;GACZ,CACF;EACD,MAAM,MAAM;GACV,MAAM,QAAS,KAAK,MAA+B;AACnD,UAAO;IAAC;IAAQ;KAAE,SAAS,qBAAqB,MAAM;KAAI,yBAAyB;KAAO;IAAE;IAAE;;EAEjG,CAAC;;;;;;;;;;ACzCJ,SAAgB,wBAAkD;AAChE,QAAO,MACL,2BAA2B,EAC3B,+BAA+B,CAChC"}
1
+ {"version":3,"file":"prosekit-extensions-background-color.js","names":[],"sources":["../src/background-color/background-color-commands.ts","../src/background-color/background-color-spec.ts","../src/background-color/background-color.ts"],"sourcesContent":["import { addMark, defineCommands, removeMark, type Extension } from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\n\nimport type { BackgroundColorAttrs } from './background-color-spec.ts'\n\n/**\n * @internal\n */\nexport function addBackgroundColor(attrs: BackgroundColorAttrs): Command {\n return addMark({ type: 'backgroundColor', attrs })\n}\n\n/**\n * @internal\n */\nexport function removeBackgroundColor(): Command {\n return removeMark({ type: 'backgroundColor' })\n}\n\n/**\n * @internal\n */\nexport type BackgroundColorCommandsExtension = Extension<{\n Commands: {\n addBackgroundColor: [attrs: BackgroundColorAttrs]\n removeBackgroundColor: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBackgroundColorCommands(): BackgroundColorCommandsExtension {\n return defineCommands({ addBackgroundColor, removeBackgroundColor })\n}\n","import { defineMarkSpec, type Extension } from '@prosekit/core'\n\n/**\n * Attributes for the `backgroundColor` mark.\n *\n * @public\n */\nexport interface BackgroundColorAttrs {\n color: string\n}\n\n/**\n * @internal\n */\nexport type BackgroundColorSpecExtension = Extension<{\n Marks: {\n backgroundColor: BackgroundColorAttrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBackgroundColorSpec(): BackgroundColorSpecExtension {\n return defineMarkSpec<'backgroundColor', BackgroundColorAttrs>({\n name: 'backgroundColor',\n attrs: {\n color: {\n validate: 'string',\n },\n },\n parseDOM: [\n {\n tag: ':where([style*=\"background-color:\"], [data-background-color])',\n getAttrs: (node): BackgroundColorAttrs | false => {\n // When both `data-background-color` and `style=\"background-color\"` are present, we\n // prioritize the `data-background-color` attribute. This avoids the\n // browser's default behavior of changing hex colors to rgba in style\n // attribute.\n const value = node.getAttribute('data-background-color')\n if (value && value !== 'inherit') {\n return { color: value }\n }\n const color = node.style.backgroundColor\n if (color && color !== 'inherit') {\n return { color }\n }\n return false\n },\n consuming: false,\n },\n ],\n toDOM(mark) {\n const color = (mark.attrs as BackgroundColorAttrs).color\n return ['span', { 'style': `background-color: ${color};`, 'data-background-color': color }, 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineBackgroundColorCommands, type BackgroundColorCommandsExtension } from './background-color-commands.ts'\nimport { defineBackgroundColorSpec, type BackgroundColorSpecExtension } from './background-color-spec.ts'\n\n/**\n * @internal\n */\nexport type BackgroundColorExtension = Union<[BackgroundColorSpecExtension, BackgroundColorCommandsExtension]>\n\n/**\n * Defines the `backgroundColor` mark and some commands for it.\n *\n * @public\n */\nexport function defineBackgroundColor(): BackgroundColorExtension {\n return union(\n defineBackgroundColorSpec(),\n defineBackgroundColorCommands(),\n )\n}\n"],"mappings":";;;;;AAQA,SAAgB,mBAAmB,OAAsC;AACvE,QAAO,QAAQ;EAAE,MAAM;EAAmB;EAAO,CAAC;;;;;AAMpD,SAAgB,wBAAiC;AAC/C,QAAO,WAAW,EAAE,MAAM,mBAAmB,CAAC;;;;;AAgBhD,SAAgB,gCAAkE;AAChF,QAAO,eAAe;EAAE;EAAoB;EAAuB,CAAC;;;;;;;ACVtE,SAAgB,4BAA0D;AACxE,QAAO,eAAwD;EAC7D,MAAM;EACN,OAAO,EACL,OAAO,EACL,UAAU,UACX,EACF;EACD,UAAU,CACR;GACE,KAAK;GACL,WAAW,SAAuC;IAKhD,MAAM,QAAQ,KAAK,aAAa,wBAAwB;AACxD,QAAI,SAAS,UAAU,UACrB,QAAO,EAAE,OAAO,OAAO;IAEzB,MAAM,QAAQ,KAAK,MAAM;AACzB,QAAI,SAAS,UAAU,UACrB,QAAO,EAAE,OAAO;AAElB,WAAO;;GAET,WAAW;GACZ,CACF;EACD,MAAM,MAAM;GACV,MAAM,QAAS,KAAK,MAA+B;AACnD,UAAO;IAAC;IAAQ;KAAE,SAAS,qBAAqB,MAAM;KAAI,yBAAyB;KAAO;IAAE;IAAE;;EAEjG,CAAC;;;;;;;;;ACzCJ,SAAgB,wBAAkD;AAChE,QAAO,MACL,2BAA2B,EAC3B,+BAA+B,CAChC"}
@@ -14,6 +14,19 @@ type BlockquoteCommandsExtension = Extension<{
14
14
  */
15
15
  declare function defineBlockquoteCommands(): BlockquoteCommandsExtension;
16
16
  //#endregion
17
+ //#region src/blockquote/blockquote-input-rule.d.ts
18
+ /**
19
+ * Wraps the text block in a blockquote when `>` is typed at the start of a new
20
+ * line followed by a space.
21
+ */
22
+ declare function defineBlockquoteInputRule(): PlainExtension;
23
+ //#endregion
24
+ //#region src/blockquote/blockquote-keymap.d.ts
25
+ /**
26
+ * @internal
27
+ */
28
+ declare function defineBlockquoteKeymap(): PlainExtension;
29
+ //#endregion
17
30
  //#region src/blockquote/blockquote-spec.d.ts
18
31
  type BlockquoteSpecExtension = Extension<{
19
32
  Nodes: {
@@ -32,18 +45,5 @@ type BlockquoteExtension = Union<[BlockquoteSpecExtension, BlockquoteCommandsExt
32
45
  */
33
46
  declare function defineBlockquote(): BlockquoteExtension;
34
47
  //#endregion
35
- //#region src/blockquote/blockquote-input-rule.d.ts
36
- /**
37
- * Wraps the text block in a blockquote when `>` is typed at the start of a new
38
- * line followed by a space.
39
- */
40
- declare function defineBlockquoteInputRule(): PlainExtension;
41
- //#endregion
42
- //#region src/blockquote/blockquote-keymap.d.ts
43
- /**
44
- * @internal
45
- */
46
- declare function defineBlockquoteKeymap(): PlainExtension;
47
- //#endregion
48
48
  export { type BlockquoteCommandsExtension, type BlockquoteExtension, type BlockquoteSpecExtension, defineBlockquote, defineBlockquoteCommands, defineBlockquoteInputRule, defineBlockquoteKeymap, defineBlockquoteSpec };
49
49
  //# sourceMappingURL=prosekit-extensions-blockquote.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-blockquote.d.ts","names":[],"sources":["../src/blockquote/blockquote-commands.ts","../src/blockquote/blockquote-spec.ts","../src/blockquote/blockquote.ts","../src/blockquote/blockquote-input-rule.ts","../src/blockquote/blockquote-keymap.ts"],"mappings":";;;;KAEY,2BAAA,GAA8B,SAAA;EACxC,QAAA;IACE,aAAA;IACA,gBAAA;IACA,gBAAA;EAAA;AAAA;;;;iBAOY,wBAAA,CAAA,GAA4B,2BAAA;;;KCVhC,uBAAA,GAA0B,SAAA;EACpC,KAAA;IACE,UAAA,EAAY,KAAA;EAAA;AAAA;AAAA,iBAIA,oBAAA,CAAA,GAAwB,uBAAA;;;;ADPxC;;KEQY,mBAAA,GAAsB,KAAA,EAC/B,uBAAA,EAAyB,2BAAA;;;;iBAMZ,gBAAA,CAAA,GAAoB,mBAAA;;;;;;AFfpC;iBGMgB,yBAAA,CAAA,GAA6B,cAAA;;;;;;iBCY7B,sBAAA,CAAA,GAA0B,cAAA"}
1
+ {"version":3,"file":"prosekit-extensions-blockquote.d.ts","names":[],"sources":["../src/blockquote/blockquote-commands.ts","../src/blockquote/blockquote-input-rule.ts","../src/blockquote/blockquote-keymap.ts","../src/blockquote/blockquote-spec.ts","../src/blockquote/blockquote.ts"],"mappings":";;;;KAEY,2BAAA,GAA8B,SAAA;EACxC,QAAA;IACE,aAAA;IACA,gBAAA;IACA,gBAAA;EAAA;AAAA;;;;iBAOY,wBAAA,CAAA,GAA4B,2BAAA;;;;;;AAX5C;iBCMgB,yBAAA,CAAA,GAA6B,cAAA;;;;;;iBCc7B,sBAAA,CAAA,GAA0B,cAAA;;;KCnB9B,uBAAA,GAA0B,SAAA;EACpC,KAAA;IACE,UAAA,EAAY,KAAA;EAAA;AAAA;AAAA,iBAIA,oBAAA,CAAA,GAAwB,uBAAA;;;;AHPxC;;KIQY,mBAAA,GAAsB,KAAA,EAC/B,uBAAA,EAAyB,2BAAA;;;;iBAMZ,gBAAA,CAAA,GAAoB,mBAAA"}
@@ -1,7 +1,6 @@
1
1
  import { defineWrappingInputRule } from "./prosekit-extensions-input-rule.js";
2
2
  import { defineCommands, defineKeymap, defineNodeSpec, insertNode, isAtBlockStart, toggleWrap, union, wrap } from "@prosekit/core";
3
3
  import { joinBackward } from "@prosekit/pm/commands";
4
-
5
4
  //#region src/blockquote/blockquote-commands.ts
6
5
  /**
7
6
  * @internal
@@ -19,7 +18,6 @@ function defineBlockquoteCommands() {
19
18
  }
20
19
  });
21
20
  }
22
-
23
21
  //#endregion
24
22
  //#region src/blockquote/blockquote-input-rule.ts
25
23
  /**
@@ -32,17 +30,17 @@ function defineBlockquoteInputRule() {
32
30
  type: "blockquote"
33
31
  });
34
32
  }
35
-
36
33
  //#endregion
37
34
  //#region src/blockquote/blockquote-keymap.ts
38
35
  function toggleBlockquoteKeybinding() {
39
36
  return toggleWrap({ type: "blockquote" });
40
37
  }
38
+ const backspaceUnsetBlockquoteCommand = (state, dispatch, view) => {
39
+ if (isAtBlockStart(state, view)?.node(-1).type.name === "blockquote") return joinBackward(state, dispatch, view);
40
+ return false;
41
+ };
41
42
  function backspaceUnsetBlockquote() {
42
- return (state, dispatch, view) => {
43
- if (isAtBlockStart(state, view)?.node(-1).type.name === "blockquote") return joinBackward(state, dispatch, view);
44
- return false;
45
- };
43
+ return backspaceUnsetBlockquoteCommand;
46
44
  }
47
45
  /**
48
46
  * @internal
@@ -53,7 +51,6 @@ function defineBlockquoteKeymap() {
53
51
  "Backspace": backspaceUnsetBlockquote()
54
52
  });
55
53
  }
56
-
57
54
  //#endregion
58
55
  //#region src/blockquote/blockquote-spec.ts
59
56
  function defineBlockquoteSpec() {
@@ -68,7 +65,6 @@ function defineBlockquoteSpec() {
68
65
  }
69
66
  });
70
67
  }
71
-
72
68
  //#endregion
73
69
  //#region src/blockquote/blockquote.ts
74
70
  /**
@@ -77,7 +73,7 @@ function defineBlockquoteSpec() {
77
73
  function defineBlockquote() {
78
74
  return union(defineBlockquoteSpec(), defineBlockquoteInputRule(), defineBlockquoteCommands(), defineBlockquoteKeymap());
79
75
  }
80
-
81
76
  //#endregion
82
77
  export { defineBlockquote, defineBlockquoteCommands, defineBlockquoteInputRule, defineBlockquoteKeymap, defineBlockquoteSpec };
78
+
83
79
  //# sourceMappingURL=prosekit-extensions-blockquote.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-blockquote.js","names":[],"sources":["../src/blockquote/blockquote-commands.ts","../src/blockquote/blockquote-input-rule.ts","../src/blockquote/blockquote-keymap.ts","../src/blockquote/blockquote-spec.ts","../src/blockquote/blockquote.ts"],"sourcesContent":["import { defineCommands, insertNode, toggleWrap, wrap, type Extension } from '@prosekit/core'\n\nexport type BlockquoteCommandsExtension = Extension<{\n Commands: {\n setBlockquote: []\n insertBlockquote: []\n toggleBlockquote: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBlockquoteCommands(): BlockquoteCommandsExtension {\n return defineCommands({\n setBlockquote: () => {\n return wrap({ type: 'blockquote' })\n },\n insertBlockquote: () => {\n return insertNode({ type: 'blockquote' })\n },\n toggleBlockquote: () => {\n return toggleWrap({ type: 'blockquote' })\n },\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineWrappingInputRule } from '../input-rule'\n\n/**\n * Wraps the text block in a blockquote when `>` is typed at the start of a new\n * line followed by a space.\n */\nexport function defineBlockquoteInputRule(): PlainExtension {\n return defineWrappingInputRule({\n regex: /^>\\s/,\n type: 'blockquote',\n })\n}\n","import { defineKeymap, isAtBlockStart, toggleWrap, type PlainExtension } from '@prosekit/core'\nimport { joinBackward } from '@prosekit/pm/commands'\nimport type { Command } from '@prosekit/pm/state'\n\nfunction toggleBlockquoteKeybinding(): Command {\n return toggleWrap({ type: 'blockquote' })\n}\n\nfunction backspaceUnsetBlockquote(): Command {\n return (state, dispatch, view) => {\n const $pos = isAtBlockStart(state, view)\n if ($pos?.node(-1).type.name === 'blockquote') {\n return joinBackward(state, dispatch, view)\n }\n return false\n }\n}\n/**\n * @internal\n */\nexport function defineBlockquoteKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-B': toggleBlockquoteKeybinding(),\n 'Backspace': backspaceUnsetBlockquote(),\n })\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\nexport type BlockquoteSpecExtension = Extension<{\n Nodes: {\n blockquote: Attrs\n }\n}>\n\nexport function defineBlockquoteSpec(): BlockquoteSpecExtension {\n return defineNodeSpec({\n name: 'blockquote',\n content: 'block+',\n group: 'block',\n defining: true,\n parseDOM: [{ tag: 'blockquote' }],\n toDOM() {\n return ['blockquote', 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineBlockquoteCommands, type BlockquoteCommandsExtension } from './blockquote-commands'\nimport { defineBlockquoteInputRule } from './blockquote-input-rule'\nimport { defineBlockquoteKeymap } from './blockquote-keymap'\nimport { defineBlockquoteSpec, type BlockquoteSpecExtension } from './blockquote-spec'\n\n/**\n * @internal\n */\nexport type BlockquoteExtension = Union<\n [BlockquoteSpecExtension, BlockquoteCommandsExtension]\n>\n\n/**\n * @public\n */\nexport function defineBlockquote(): BlockquoteExtension {\n return union(\n defineBlockquoteSpec(),\n defineBlockquoteInputRule(),\n defineBlockquoteCommands(),\n defineBlockquoteKeymap(),\n )\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,2BAAwD;AACtE,QAAO,eAAe;EACpB,qBAAqB;AACnB,UAAO,KAAK,EAAE,MAAM,cAAc,CAAC;;EAErC,wBAAwB;AACtB,UAAO,WAAW,EAAE,MAAM,cAAc,CAAC;;EAE3C,wBAAwB;AACtB,UAAO,WAAW,EAAE,MAAM,cAAc,CAAC;;EAE5C,CAAC;;;;;;;;;AChBJ,SAAgB,4BAA4C;AAC1D,QAAO,wBAAwB;EAC7B,OAAO;EACP,MAAM;EACP,CAAC;;;;;ACRJ,SAAS,6BAAsC;AAC7C,QAAO,WAAW,EAAE,MAAM,cAAc,CAAC;;AAG3C,SAAS,2BAAoC;AAC3C,SAAQ,OAAO,UAAU,SAAS;AAEhC,MADa,eAAe,OAAO,KAAK,EAC9B,KAAK,GAAG,CAAC,KAAK,SAAS,aAC/B,QAAO,aAAa,OAAO,UAAU,KAAK;AAE5C,SAAO;;;;;;AAMX,SAAgB,yBAAyC;AACvD,QAAO,aAAa;EAClB,SAAS,4BAA4B;EACrC,aAAa,0BAA0B;EACxC,CAAC;;;;;ACfJ,SAAgB,uBAAgD;AAC9D,QAAO,eAAe;EACpB,MAAM;EACN,SAAS;EACT,OAAO;EACP,UAAU;EACV,UAAU,CAAC,EAAE,KAAK,cAAc,CAAC;EACjC,QAAQ;AACN,UAAO,CAAC,cAAc,EAAE;;EAE3B,CAAC;;;;;;;;ACFJ,SAAgB,mBAAwC;AACtD,QAAO,MACL,sBAAsB,EACtB,2BAA2B,EAC3B,0BAA0B,EAC1B,wBAAwB,CACzB"}
1
+ {"version":3,"file":"prosekit-extensions-blockquote.js","names":[],"sources":["../src/blockquote/blockquote-commands.ts","../src/blockquote/blockquote-input-rule.ts","../src/blockquote/blockquote-keymap.ts","../src/blockquote/blockquote-spec.ts","../src/blockquote/blockquote.ts"],"sourcesContent":["import { defineCommands, insertNode, toggleWrap, wrap, type Extension } from '@prosekit/core'\n\nexport type BlockquoteCommandsExtension = Extension<{\n Commands: {\n setBlockquote: []\n insertBlockquote: []\n toggleBlockquote: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBlockquoteCommands(): BlockquoteCommandsExtension {\n return defineCommands({\n setBlockquote: () => {\n return wrap({ type: 'blockquote' })\n },\n insertBlockquote: () => {\n return insertNode({ type: 'blockquote' })\n },\n toggleBlockquote: () => {\n return toggleWrap({ type: 'blockquote' })\n },\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineWrappingInputRule } from '../input-rule/index.ts'\n\n/**\n * Wraps the text block in a blockquote when `>` is typed at the start of a new\n * line followed by a space.\n */\nexport function defineBlockquoteInputRule(): PlainExtension {\n return defineWrappingInputRule({\n regex: /^>\\s/,\n type: 'blockquote',\n })\n}\n","import { defineKeymap, isAtBlockStart, toggleWrap, type PlainExtension } from '@prosekit/core'\nimport { joinBackward } from '@prosekit/pm/commands'\nimport type { Command } from '@prosekit/pm/state'\n\nfunction toggleBlockquoteKeybinding(): Command {\n return toggleWrap({ type: 'blockquote' })\n}\n\nconst backspaceUnsetBlockquoteCommand: Command = (state, dispatch, view): boolean => {\n const $pos = isAtBlockStart(state, view)\n if ($pos?.node(-1).type.name === 'blockquote') {\n return joinBackward(state, dispatch, view)\n }\n return false\n}\n\nfunction backspaceUnsetBlockquote(): Command {\n return backspaceUnsetBlockquoteCommand\n}\n/**\n * @internal\n */\nexport function defineBlockquoteKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-B': toggleBlockquoteKeybinding(),\n 'Backspace': backspaceUnsetBlockquote(),\n })\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\nexport type BlockquoteSpecExtension = Extension<{\n Nodes: {\n blockquote: Attrs\n }\n}>\n\nexport function defineBlockquoteSpec(): BlockquoteSpecExtension {\n return defineNodeSpec({\n name: 'blockquote',\n content: 'block+',\n group: 'block',\n defining: true,\n parseDOM: [{ tag: 'blockquote' }],\n toDOM() {\n return ['blockquote', 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineBlockquoteCommands, type BlockquoteCommandsExtension } from './blockquote-commands.ts'\nimport { defineBlockquoteInputRule } from './blockquote-input-rule.ts'\nimport { defineBlockquoteKeymap } from './blockquote-keymap.ts'\nimport { defineBlockquoteSpec, type BlockquoteSpecExtension } from './blockquote-spec.ts'\n\n/**\n * @internal\n */\nexport type BlockquoteExtension = Union<\n [BlockquoteSpecExtension, BlockquoteCommandsExtension]\n>\n\n/**\n * @public\n */\nexport function defineBlockquote(): BlockquoteExtension {\n return union(\n defineBlockquoteSpec(),\n defineBlockquoteInputRule(),\n defineBlockquoteCommands(),\n defineBlockquoteKeymap(),\n )\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,2BAAwD;AACtE,QAAO,eAAe;EACpB,qBAAqB;AACnB,UAAO,KAAK,EAAE,MAAM,cAAc,CAAC;;EAErC,wBAAwB;AACtB,UAAO,WAAW,EAAE,MAAM,cAAc,CAAC;;EAE3C,wBAAwB;AACtB,UAAO,WAAW,EAAE,MAAM,cAAc,CAAC;;EAE5C,CAAC;;;;;;;;AChBJ,SAAgB,4BAA4C;AAC1D,QAAO,wBAAwB;EAC7B,OAAO;EACP,MAAM;EACP,CAAC;;;;ACRJ,SAAS,6BAAsC;AAC7C,QAAO,WAAW,EAAE,MAAM,cAAc,CAAC;;AAG3C,MAAM,mCAA4C,OAAO,UAAU,SAAkB;AAEnF,KADa,eAAe,OAAO,KAAK,EAC9B,KAAK,GAAG,CAAC,KAAK,SAAS,aAC/B,QAAO,aAAa,OAAO,UAAU,KAAK;AAE5C,QAAO;;AAGT,SAAS,2BAAoC;AAC3C,QAAO;;;;;AAKT,SAAgB,yBAAyC;AACvD,QAAO,aAAa;EAClB,SAAS,4BAA4B;EACrC,aAAa,0BAA0B;EACxC,CAAC;;;;ACjBJ,SAAgB,uBAAgD;AAC9D,QAAO,eAAe;EACpB,MAAM;EACN,SAAS;EACT,OAAO;EACP,UAAU;EACV,UAAU,CAAC,EAAE,KAAK,cAAc,CAAC;EACjC,QAAQ;AACN,UAAO,CAAC,cAAc,EAAE;;EAE3B,CAAC;;;;;;;ACFJ,SAAgB,mBAAwC;AACtD,QAAO,MACL,sBAAsB,EACtB,2BAA2B,EAC3B,0BAA0B,EAC1B,wBAAwB,CACzB"}
@@ -15,6 +15,18 @@ type BoldCommandsExtension = Extension<{
15
15
  */
16
16
  declare function defineBoldCommands(): BoldCommandsExtension;
17
17
  //#endregion
18
+ //#region src/bold/bold-input-rule.d.ts
19
+ /**
20
+ * @internal
21
+ */
22
+ declare function defineBoldInputRule(): PlainExtension;
23
+ //#endregion
24
+ //#region src/bold/bold-keymap.d.ts
25
+ /**
26
+ * @internal
27
+ */
28
+ declare function defineBoldKeymap(): PlainExtension;
29
+ //#endregion
18
30
  //#region src/bold/bold-spec.d.ts
19
31
  /**
20
32
  * @internal
@@ -39,17 +51,5 @@ type BoldExtension = Union<[BoldSpecExtension, BoldCommandsExtension]>;
39
51
  */
40
52
  declare function defineBold(): BoldExtension;
41
53
  //#endregion
42
- //#region src/bold/bold-input-rule.d.ts
43
- /**
44
- * @internal
45
- */
46
- declare function defineBoldInputRule(): PlainExtension;
47
- //#endregion
48
- //#region src/bold/bold-keymap.d.ts
49
- /**
50
- * @internal
51
- */
52
- declare function defineBoldKeymap(): PlainExtension;
53
- //#endregion
54
54
  export { type BoldCommandsExtension, type BoldExtension, type BoldSpecExtension, defineBold, defineBoldCommands, defineBoldInputRule, defineBoldKeymap, defineBoldSpec };
55
55
  //# sourceMappingURL=prosekit-extensions-bold.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-bold.d.ts","names":[],"sources":["../src/bold/bold-commands.ts","../src/bold/bold-spec.ts","../src/bold/bold.ts","../src/bold/bold-input-rule.ts","../src/bold/bold-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-bold.d.ts","names":[],"sources":["../src/bold/bold-commands.ts","../src/bold/bold-input-rule.ts","../src/bold/bold-keymap.ts","../src/bold/bold-spec.ts","../src/bold/bold.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,6 +1,5 @@
1
1
  import { defineMarkInputRule } from "./prosekit-extensions-input-rule.js";
2
2
  import { canUseRegexLookbehind, defineCommands, defineKeymap, defineMarkSpec, toggleMark, union } from "@prosekit/core";
3
-
4
3
  //#region src/bold/bold-commands.ts
5
4
  /**
6
5
  * @internal
@@ -8,7 +7,6 @@ import { canUseRegexLookbehind, defineCommands, defineKeymap, defineMarkSpec, to
8
7
  function defineBoldCommands() {
9
8
  return defineCommands({ toggleBold: () => toggleMark({ type: "bold" }) });
10
9
  }
11
-
12
10
  //#endregion
13
11
  //#region src/bold/bold-input-rule.ts
14
12
  /**
@@ -20,7 +18,6 @@ function defineBoldInputRule() {
20
18
  type: "bold"
21
19
  });
22
20
  }
23
-
24
21
  //#endregion
25
22
  //#region src/bold/bold-keymap.ts
26
23
  /**
@@ -29,7 +26,6 @@ function defineBoldInputRule() {
29
26
  function defineBoldKeymap() {
30
27
  return defineKeymap({ "Mod-b": toggleMark({ type: "bold" }) });
31
28
  }
32
-
33
29
  //#endregion
34
30
  //#region src/bold/bold-spec.ts
35
31
  /**
@@ -62,7 +58,6 @@ function defineBoldSpec() {
62
58
  }
63
59
  });
64
60
  }
65
-
66
61
  //#endregion
67
62
  //#region src/bold/bold.ts
68
63
  /**
@@ -71,7 +66,7 @@ function defineBoldSpec() {
71
66
  function defineBold() {
72
67
  return union(defineBoldSpec(), defineBoldCommands(), defineBoldKeymap(), defineBoldInputRule());
73
68
  }
74
-
75
69
  //#endregion
76
70
  export { defineBold, defineBoldCommands, defineBoldInputRule, defineBoldKeymap, defineBoldSpec };
71
+
77
72
  //# sourceMappingURL=prosekit-extensions-bold.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prosekit-extensions-bold.js","names":[],"sources":["../src/bold/bold-commands.ts","../src/bold/bold-input-rule.ts","../src/bold/bold-keymap.ts","../src/bold/bold-spec.ts","../src/bold/bold.ts"],"sourcesContent":["import { defineCommands, toggleMark, type Extension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport type BoldCommandsExtension = Extension<{\n Commands: {\n toggleBold: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBoldCommands(): BoldCommandsExtension {\n return defineCommands({\n toggleBold: () => toggleMark({ type: 'bold' }),\n })\n}\n","import { canUseRegexLookbehind, type PlainExtension } from '@prosekit/core'\n\nimport { defineMarkInputRule } from '../input-rule'\n\n/**\n * @internal\n */\nexport function defineBoldInputRule(): PlainExtension {\n return defineMarkInputRule({\n regex: canUseRegexLookbehind()\n ? /(?<=\\s|^)\\*\\*([^\\s*]|[^\\s*][^*]*[^\\s*])\\*\\*$/\n : /\\*\\*([^\\s*]|[^\\s*][^*]*[^\\s*])\\*\\*$/,\n type: 'bold',\n })\n}\n","import { defineKeymap, toggleMark, type PlainExtension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function defineBoldKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-b': toggleMark({ type: 'bold' }),\n })\n}\n","import { defineMarkSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\n/**\n * @internal\n */\nexport type BoldSpecExtension = Extension<{\n Marks: {\n bold: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBoldSpec(): BoldSpecExtension {\n return defineMarkSpec({\n name: 'bold',\n parseDOM: [\n { tag: 'strong' },\n // This works around a Google Docs misbehavior where\n // pasted content will be inexplicably wrapped in `<b>`\n // tags with a font-weight normal.\n {\n tag: 'b',\n getAttrs: (node: string | HTMLElement): null | false => {\n return (\n typeof node !== 'string'\n && node.style.fontWeight !== 'normal'\n && null\n )\n },\n },\n { style: 'font-weight=400', clearMark: (m) => m.type.name == 'strong' },\n {\n style: 'font-weight',\n getAttrs: (value: string | HTMLElement): null | false => {\n return (\n typeof value === 'string'\n && /^(bold(er)?|[5-9]\\d{2,})$/.test(value)\n && null\n )\n },\n },\n ],\n toDOM() {\n return ['strong', 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineBoldCommands, type BoldCommandsExtension } from './bold-commands'\nimport { defineBoldInputRule } from './bold-input-rule'\nimport { defineBoldKeymap } from './bold-keymap'\nimport { defineBoldSpec, type BoldSpecExtension } from './bold-spec'\n\n/**\n * @internal\n */\nexport type BoldExtension = Union<[BoldSpecExtension, BoldCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineBold(): BoldExtension {\n return union(\n defineBoldSpec(),\n defineBoldCommands(),\n defineBoldKeymap(),\n defineBoldInputRule(),\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,iDACA;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;GACR,EAAE,KAAK,UAAU;GAIjB;IACE,KAAK;IACL,WAAW,SAA6C;AACtD,YACE,OAAO,SAAS,YACb,KAAK,MAAM,eAAe,YAC1B;;IAGR;GACD;IAAE,OAAO;IAAmB,YAAY,MAAM,EAAE,KAAK,QAAQ;IAAU;GACvE;IACE,OAAO;IACP,WAAW,UAA8C;AACvD,YACE,OAAO,UAAU,YACd,4BAA4B,KAAK,MAAM,IACvC;;IAGR;GACF;EACD,QAAQ;AACN,UAAO,CAAC,UAAU,EAAE;;EAEvB,CAAC;;;;;;;;ACjCJ,SAAgB,aAA4B;AAC1C,QAAO,MACL,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,CACtB"}
1
+ {"version":3,"file":"prosekit-extensions-bold.js","names":[],"sources":["../src/bold/bold-commands.ts","../src/bold/bold-input-rule.ts","../src/bold/bold-keymap.ts","../src/bold/bold-spec.ts","../src/bold/bold.ts"],"sourcesContent":["import { defineCommands, toggleMark, type Extension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport type BoldCommandsExtension = Extension<{\n Commands: {\n toggleBold: []\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBoldCommands(): BoldCommandsExtension {\n return defineCommands({\n toggleBold: () => toggleMark({ type: 'bold' }),\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 defineBoldInputRule(): PlainExtension {\n return defineMarkInputRule({\n regex: canUseRegexLookbehind()\n ? /(?<=\\s|^)\\*\\*([^\\s*]|[^\\s*][^*]*[^\\s*])\\*\\*$/\n : /\\*\\*([^\\s*]|[^\\s*][^*]*[^\\s*])\\*\\*$/,\n type: 'bold',\n })\n}\n","import { defineKeymap, toggleMark, type PlainExtension } from '@prosekit/core'\n\n/**\n * @internal\n */\nexport function defineBoldKeymap(): PlainExtension {\n return defineKeymap({\n 'Mod-b': toggleMark({ type: 'bold' }),\n })\n}\n","import { defineMarkSpec, type Extension } from '@prosekit/core'\nimport type { Attrs } from '@prosekit/pm/model'\n\n/**\n * @internal\n */\nexport type BoldSpecExtension = Extension<{\n Marks: {\n bold: Attrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineBoldSpec(): BoldSpecExtension {\n return defineMarkSpec({\n name: 'bold',\n parseDOM: [\n { tag: 'strong' },\n // This works around a Google Docs misbehavior where\n // pasted content will be inexplicably wrapped in `<b>`\n // tags with a font-weight normal.\n {\n tag: 'b',\n getAttrs: (node: string | HTMLElement): null | false => {\n return (\n typeof node !== 'string'\n && node.style.fontWeight !== 'normal'\n && null\n )\n },\n },\n { style: 'font-weight=400', clearMark: (m) => m.type.name == 'strong' },\n {\n style: 'font-weight',\n getAttrs: (value: string | HTMLElement): null | false => {\n return (\n typeof value === 'string'\n && /^(bold(er)?|[5-9]\\d{2,})$/.test(value)\n && null\n )\n },\n },\n ],\n toDOM() {\n return ['strong', 0]\n },\n })\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineBoldCommands, type BoldCommandsExtension } from './bold-commands.ts'\nimport { defineBoldInputRule } from './bold-input-rule.ts'\nimport { defineBoldKeymap } from './bold-keymap.ts'\nimport { defineBoldSpec, type BoldSpecExtension } from './bold-spec.ts'\n\n/**\n * @internal\n */\nexport type BoldExtension = Union<[BoldSpecExtension, BoldCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineBold(): BoldExtension {\n return union(\n defineBoldSpec(),\n defineBoldCommands(),\n defineBoldKeymap(),\n defineBoldInputRule(),\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,iDACA;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;GACR,EAAE,KAAK,UAAU;GAIjB;IACE,KAAK;IACL,WAAW,SAA6C;AACtD,YACE,OAAO,SAAS,YACb,KAAK,MAAM,eAAe,YAC1B;;IAGR;GACD;IAAE,OAAO;IAAmB,YAAY,MAAM,EAAE,KAAK,QAAQ;IAAU;GACvE;IACE,OAAO;IACP,WAAW,UAA8C;AACvD,YACE,OAAO,UAAU,YACd,4BAA4B,KAAK,MAAM,IACvC;;IAGR;GACF;EACD,QAAQ;AACN,UAAO,CAAC,UAAU,EAAE;;EAEvB,CAAC;;;;;;;ACjCJ,SAAgB,aAA4B;AAC1C,QAAO,MACL,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,CACtB"}
@@ -1,7 +1,6 @@
1
- import { ShikiHighlighterOptions } from "./shiki-highlighter-chunk.js";
2
1
  import { Extension, PlainExtension, Union } from "@prosekit/core";
3
2
  import { Parser } from "prosemirror-highlight";
4
- import { BundledLanguage as ShikiBundledLanguage, BundledLanguageInfo as ShikiBundledLanguageInfo, BundledTheme as ShikiBundledTheme, BundledThemeInfo as ShikiBundledThemeInfo, SpecialLanguage, bundledLanguagesInfo as shikiBundledLanguagesInfo, bundledThemesInfo as shikiBundledThemesInfo } from "shiki";
3
+ import { BundledHighlighterOptions, BundledLanguage, BundledLanguage as ShikiBundledLanguage, BundledLanguageInfo as ShikiBundledLanguageInfo, BundledTheme, BundledTheme as ShikiBundledTheme, BundledThemeInfo as ShikiBundledThemeInfo, SpecialLanguage, bundledLanguagesInfo as shikiBundledLanguagesInfo, bundledThemesInfo as shikiBundledThemesInfo } from "shiki";
5
4
 
6
5
  //#region src/code-block/code-block-types.d.ts
7
6
  /**
@@ -32,40 +31,6 @@ type CodeBlockCommandsExtension = Extension<{
32
31
  */
33
32
  declare function defineCodeBlockCommands(): CodeBlockCommandsExtension;
34
33
  //#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
34
  //#region src/code-block/code-block-highlight.d.ts
70
35
  /**
71
36
  * @public
@@ -77,7 +42,16 @@ type HighlightParser = Parser;
77
42
  * @public
78
43
  */
79
44
  type CodeBlockHighlightOptions = {
45
+ /**
46
+ * A parser instance from the `prosemirror-highlight` package.
47
+ */
80
48
  parser: HighlightParser;
49
+ /**
50
+ * ProseMirror node types to highlight.
51
+ *
52
+ * @default ['codeBlock', 'mathBlock']
53
+ */
54
+ nodeTypes?: string[];
81
55
  };
82
56
  /**
83
57
  * Adds syntax highlighting to code blocks. This function requires a `Parser`
@@ -90,7 +64,8 @@ type CodeBlockHighlightOptions = {
90
64
  * @public
91
65
  */
92
66
  declare function defineCodeBlockHighlight({
93
- parser
67
+ parser,
68
+ nodeTypes
94
69
  }: CodeBlockHighlightOptions): Extension;
95
70
  //#endregion
96
71
  //#region src/code-block/code-block-input-rule.d.ts
@@ -113,6 +88,9 @@ declare function defineCodeBlockEnterRule(): PlainExtension;
113
88
  */
114
89
  declare function defineCodeBlockKeymap(): PlainExtension;
115
90
  //#endregion
91
+ //#region src/code-block/shiki-highlighter-chunk.d.ts
92
+ interface ShikiHighlighterOptions extends BundledHighlighterOptions<BundledLanguage, BundledTheme> {}
93
+ //#endregion
116
94
  //#region src/code-block/code-block-shiki.d.ts
117
95
  /**
118
96
  * The options to configure the Shiki highlighter.
@@ -120,6 +98,12 @@ declare function defineCodeBlockKeymap(): PlainExtension;
120
98
  * @public
121
99
  */
122
100
  interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {
101
+ /**
102
+ * ProseMirror node types to highlight.
103
+ *
104
+ * @default ['codeBlock', 'mathBlock']
105
+ */
106
+ nodeTypes?: string[];
123
107
  /**
124
108
  * A list of Shiki themes to pre-load. The first theme in the list will be
125
109
  * used to render the code block.
@@ -151,10 +135,45 @@ interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' |
151
135
  * @public
152
136
  */
153
137
  declare function defineCodeBlockShiki({
138
+ nodeTypes,
154
139
  themes,
155
140
  langs,
156
141
  ...rest
157
142
  }?: CodeBlockShikiOptions): Extension;
158
143
  //#endregion
144
+ //#region src/code-block/code-block-spec.d.ts
145
+ /**
146
+ * @internal
147
+ */
148
+ type CodeBlockSpecExtension = Extension<{
149
+ Nodes: {
150
+ codeBlock: CodeBlockAttrs;
151
+ };
152
+ }>;
153
+ /**
154
+ * Defines the `codeBlock` node spec.
155
+ *
156
+ * @public
157
+ */
158
+ declare function defineCodeBlockSpec(): CodeBlockSpecExtension;
159
+ //#endregion
160
+ //#region src/code-block/code-block.d.ts
161
+ /**
162
+ * @internal
163
+ */
164
+ type CodeBlockExtension = Union<[CodeBlockSpecExtension, CodeBlockCommandsExtension]>;
165
+ /**
166
+ * Adds `codeBlock` nodes to the editor. This includes the following extensions:
167
+ *
168
+ * - {@link defineCodeBlockSpec}
169
+ * - {@link defineCodeBlockInputRule}
170
+ * - {@link defineCodeBlockEnterRule}
171
+ * - {@link defineCodeBlockKeymap}
172
+ * - {@link defineCodeBlockCommands}.
173
+ *
174
+ * @public
175
+ */
176
+ declare function defineCodeBlock(): CodeBlockExtension;
177
+ //#endregion
159
178
  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
179
  //# 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/shiki-highlighter-chunk.ts","../src/code-block/code-block-shiki.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