@prosekit/extensions 0.16.0-beta.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/dist/{prosekit-extensions-autocomplete.d.ts → autocomplete.d.ts} +1 -6
  2. package/dist/autocomplete.d.ts.map +1 -0
  3. package/dist/{prosekit-extensions-autocomplete.js → autocomplete.js} +1 -9
  4. package/dist/autocomplete.js.map +1 -0
  5. package/dist/{prosekit-extensions-background-color.d.ts → background-color.d.ts} +1 -8
  6. package/dist/background-color.d.ts.map +1 -0
  7. package/dist/{prosekit-extensions-background-color.js → background-color.js} +1 -7
  8. package/dist/background-color.js.map +1 -0
  9. package/dist/{prosekit-extensions-blockquote.d.ts → blockquote.d.ts} +1 -12
  10. package/dist/blockquote.d.ts.map +1 -0
  11. package/dist/{prosekit-extensions-blockquote.js → blockquote.js} +2 -12
  12. package/dist/blockquote.js.map +1 -0
  13. package/dist/{prosekit-extensions-bold.d.ts → bold.d.ts} +1 -12
  14. package/dist/bold.d.ts.map +1 -0
  15. package/dist/{prosekit-extensions-bold.js → bold.js} +2 -12
  16. package/dist/bold.js.map +1 -0
  17. package/dist/{prosekit-extensions-code-block.d.ts → code-block.d.ts} +1 -20
  18. package/dist/code-block.d.ts.map +1 -0
  19. package/dist/{prosekit-extensions-code-block.js → code-block.js} +3 -21
  20. package/dist/code-block.js.map +1 -0
  21. package/dist/{prosekit-extensions-code.d.ts → code.d.ts} +1 -12
  22. package/dist/code.d.ts.map +1 -0
  23. package/dist/{prosekit-extensions-code.js → code.js} +2 -12
  24. package/dist/code.js.map +1 -0
  25. package/dist/{prosekit-extensions-commit.d.ts → commit.d.ts} +1 -4
  26. package/dist/commit.d.ts.map +1 -0
  27. package/dist/{prosekit-extensions-commit.js → commit.js} +1 -3
  28. package/dist/commit.js.map +1 -0
  29. package/dist/{prosekit-extensions-doc.d.ts → doc.d.ts} +1 -4
  30. package/dist/doc.d.ts.map +1 -0
  31. package/dist/{prosekit-extensions-doc.js → doc.js} +1 -3
  32. package/dist/doc.js.map +1 -0
  33. package/dist/{prosekit-extensions-drop-cursor.d.ts → drop-cursor.d.ts} +1 -4
  34. package/dist/drop-cursor.d.ts.map +1 -0
  35. package/dist/{prosekit-extensions-drop-cursor.js → drop-cursor.js} +1 -3
  36. package/dist/drop-cursor.js.map +1 -0
  37. package/dist/{prosekit-extensions-drop-indicator.d.ts → drop-indicator.d.ts} +1 -4
  38. package/dist/drop-indicator.d.ts.map +1 -0
  39. package/dist/drop-indicator.js +2 -57
  40. package/dist/drop-indicator2.js +53 -0
  41. package/dist/drop-indicator2.js.map +1 -0
  42. package/dist/{prosekit-extensions-enter-rule.d.ts → enter-rule.d.ts} +1 -4
  43. package/dist/enter-rule.d.ts.map +1 -0
  44. package/dist/{prosekit-extensions-enter-rule.js → enter-rule.js} +1 -3
  45. package/dist/enter-rule.js.map +1 -0
  46. package/dist/file.js +2 -128
  47. package/dist/file2.js +120 -0
  48. package/dist/file2.js.map +1 -0
  49. package/dist/{prosekit-extensions-gap-cursor.d.ts → gap-cursor.d.ts} +1 -4
  50. package/dist/gap-cursor.d.ts.map +1 -0
  51. package/dist/{prosekit-extensions-gap-cursor.js → gap-cursor.js} +1 -3
  52. package/dist/gap-cursor.js.map +1 -0
  53. package/dist/{prosekit-extensions-hard-break.d.ts → hard-break.d.ts} +1 -10
  54. package/dist/hard-break.d.ts.map +1 -0
  55. package/dist/{prosekit-extensions-hard-break.js → hard-break.js} +1 -9
  56. package/dist/hard-break.js.map +1 -0
  57. package/dist/{prosekit-extensions-heading.d.ts → heading.d.ts} +1 -14
  58. package/dist/heading.d.ts.map +1 -0
  59. package/dist/{prosekit-extensions-heading.js → heading.js} +2 -12
  60. package/dist/heading.js.map +1 -0
  61. package/dist/{prosekit-extensions-horizontal-rule.d.ts → horizontal-rule.d.ts} +1 -10
  62. package/dist/horizontal-rule.d.ts.map +1 -0
  63. package/dist/{prosekit-extensions-horizontal-rule.js → horizontal-rule.js} +2 -10
  64. package/dist/horizontal-rule.js.map +1 -0
  65. package/dist/{prosekit-extensions-image.d.ts → image.d.ts} +1 -14
  66. package/dist/image.d.ts.map +1 -0
  67. package/dist/{prosekit-extensions-image.js → image.js} +2 -14
  68. package/dist/image.js.map +1 -0
  69. package/dist/index.d.ts +0 -7
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/{prosekit-extensions-input-rule.d.ts → input-rule.d.ts} +1 -4
  72. package/dist/input-rule.d.ts.map +1 -0
  73. package/dist/{prosekit-extensions-input-rule.js → input-rule.js} +1 -3
  74. package/dist/input-rule.js.map +1 -0
  75. package/dist/{prosekit-extensions-italic.d.ts → italic.d.ts} +1 -12
  76. package/dist/italic.d.ts.map +1 -0
  77. package/dist/{prosekit-extensions-italic.js → italic.js} +2 -12
  78. package/dist/italic.js.map +1 -0
  79. package/dist/{prosekit-extensions-link.d.ts → link.d.ts} +1 -8
  80. package/dist/link.d.ts.map +1 -0
  81. package/dist/{prosekit-extensions-link.js → link.js} +5 -11
  82. package/dist/link.js.map +1 -0
  83. package/dist/{prosekit-extensions-list.d.ts → list.d.ts} +1 -18
  84. package/dist/list.d.ts.map +1 -0
  85. package/dist/{prosekit-extensions-list.js → list.js} +3 -19
  86. package/dist/list.js.map +1 -0
  87. package/dist/{prosekit-extensions-loro.d.ts → loro.d.ts} +1 -14
  88. package/dist/loro.d.ts.map +1 -0
  89. package/dist/{prosekit-extensions-loro.js → loro.js} +1 -13
  90. package/dist/loro.js.map +1 -0
  91. package/dist/{prosekit-extensions-mark-rule.d.ts → mark-rule.d.ts} +1 -6
  92. package/dist/mark-rule.d.ts.map +1 -0
  93. package/dist/mark-rule.js +2 -157
  94. package/dist/mark-rule2.js +151 -0
  95. package/dist/mark-rule2.js.map +1 -0
  96. package/dist/{prosekit-extensions-math.d.ts → math.d.ts} +1 -10
  97. package/dist/math.d.ts.map +1 -0
  98. package/dist/{prosekit-extensions-math.js → math.js} +3 -11
  99. package/dist/math.js.map +1 -0
  100. package/dist/{prosekit-extensions-mention.d.ts → mention.d.ts} +1 -4
  101. package/dist/mention.d.ts.map +1 -0
  102. package/dist/{prosekit-extensions-mention.js → mention.js} +1 -3
  103. package/dist/mention.js.map +1 -0
  104. package/dist/{prosekit-extensions-mod-click-prevention.d.ts → mod-click-prevention.d.ts} +1 -4
  105. package/dist/mod-click-prevention.d.ts.map +1 -0
  106. package/dist/{prosekit-extensions-mod-click-prevention.js → mod-click-prevention.js} +1 -3
  107. package/dist/mod-click-prevention.js.map +1 -0
  108. package/dist/{prosekit-extensions-page.d.ts → page.d.ts} +1 -12
  109. package/dist/page.d.ts.map +1 -0
  110. package/dist/{prosekit-extensions-page.js → page.js} +3 -15
  111. package/dist/page.js.map +1 -0
  112. package/dist/{prosekit-extensions-paragraph.d.ts → paragraph.d.ts} +1 -10
  113. package/dist/paragraph.d.ts.map +1 -0
  114. package/dist/{prosekit-extensions-paragraph.js → paragraph.js} +1 -9
  115. package/dist/paragraph.js.map +1 -0
  116. package/dist/{prosekit-extensions-paste-rule.d.ts → paste-rule.d.ts} +1 -6
  117. package/dist/paste-rule.d.ts.map +1 -0
  118. package/dist/paste-rule.js +2 -158
  119. package/dist/paste-rule2.js +150 -0
  120. package/dist/paste-rule2.js.map +1 -0
  121. package/dist/{prosekit-extensions-placeholder.d.ts → placeholder.d.ts} +1 -4
  122. package/dist/placeholder.d.ts.map +1 -0
  123. package/dist/{prosekit-extensions-placeholder.js → placeholder.js} +2 -4
  124. package/dist/placeholder.js.map +1 -0
  125. package/dist/{prosekit-extensions-readonly.d.ts → readonly.d.ts} +1 -4
  126. package/dist/readonly.d.ts.map +1 -0
  127. package/dist/{prosekit-extensions-readonly.js → readonly.js} +6 -3
  128. package/dist/readonly.js.map +1 -0
  129. package/dist/{prosekit-extensions-search.d.ts → search.d.ts} +1 -4
  130. package/dist/search.d.ts.map +1 -0
  131. package/dist/{prosekit-extensions-search.js → search.js} +1 -3
  132. package/dist/search.js.map +1 -0
  133. package/dist/shiki-highlighter-chunk.js +0 -2
  134. package/dist/shiki-highlighter-chunk.js.map +1 -1
  135. package/dist/{prosekit-extensions-strike.d.ts → strike.d.ts} +1 -4
  136. package/dist/strike.d.ts.map +1 -0
  137. package/dist/{prosekit-extensions-strike.js → strike.js} +2 -4
  138. package/dist/strike.js.map +1 -0
  139. package/dist/{prosekit-extensions-table.d.ts → table.d.ts} +1 -26
  140. package/dist/table.d.ts.map +1 -0
  141. package/dist/table.js +2 -276
  142. package/dist/table2.js +252 -0
  143. package/dist/table2.js.map +1 -0
  144. package/dist/{prosekit-extensions-text-align.d.ts → text-align.d.ts} +1 -4
  145. package/dist/text-align.d.ts.map +1 -0
  146. package/dist/{prosekit-extensions-text-align.js → text-align.js} +1 -3
  147. package/dist/text-align.js.map +1 -0
  148. package/dist/{prosekit-extensions-text-color.d.ts → text-color.d.ts} +1 -8
  149. package/dist/text-color.d.ts.map +1 -0
  150. package/dist/{prosekit-extensions-text-color.js → text-color.js} +1 -7
  151. package/dist/text-color.js.map +1 -0
  152. package/dist/{prosekit-extensions-text.d.ts → text.d.ts} +1 -4
  153. package/dist/text.d.ts.map +1 -0
  154. package/dist/{prosekit-extensions-text.js → text.js} +1 -3
  155. package/dist/text.js.map +1 -0
  156. package/dist/{prosekit-extensions-underline.d.ts → underline.d.ts} +1 -4
  157. package/dist/underline.d.ts.map +1 -0
  158. package/dist/{prosekit-extensions-underline.js → underline.js} +1 -3
  159. package/dist/underline.js.map +1 -0
  160. package/dist/{prosekit-extensions-virtual-selection.d.ts → virtual-selection.d.ts} +1 -4
  161. package/dist/virtual-selection.d.ts.map +1 -0
  162. package/dist/{prosekit-extensions-virtual-selection.js → virtual-selection.js} +1 -3
  163. package/dist/virtual-selection.js.map +1 -0
  164. package/dist/{prosekit-extensions-yjs.d.ts → yjs.d.ts} +1 -16
  165. package/dist/yjs.d.ts.map +1 -0
  166. package/dist/{prosekit-extensions-yjs.js → yjs.js} +1 -13
  167. package/dist/yjs.js.map +1 -0
  168. package/package.json +136 -194
  169. package/src/page/page-element.ts +2 -2
  170. package/src/readonly/index.ts +6 -0
  171. package/dist/drop-indicator.js.map +0 -1
  172. package/dist/file.js.map +0 -1
  173. package/dist/mark-rule.js.map +0 -1
  174. package/dist/paste-rule.js.map +0 -1
  175. package/dist/prosekit-extensions-autocomplete.d.ts.map +0 -1
  176. package/dist/prosekit-extensions-autocomplete.js.map +0 -1
  177. package/dist/prosekit-extensions-background-color.d.ts.map +0 -1
  178. package/dist/prosekit-extensions-background-color.js.map +0 -1
  179. package/dist/prosekit-extensions-blockquote.d.ts.map +0 -1
  180. package/dist/prosekit-extensions-blockquote.js.map +0 -1
  181. package/dist/prosekit-extensions-bold.d.ts.map +0 -1
  182. package/dist/prosekit-extensions-bold.js.map +0 -1
  183. package/dist/prosekit-extensions-code-block.d.ts.map +0 -1
  184. package/dist/prosekit-extensions-code-block.js.map +0 -1
  185. package/dist/prosekit-extensions-code.d.ts.map +0 -1
  186. package/dist/prosekit-extensions-code.js.map +0 -1
  187. package/dist/prosekit-extensions-commit.d.ts.map +0 -1
  188. package/dist/prosekit-extensions-commit.js.map +0 -1
  189. package/dist/prosekit-extensions-doc.d.ts.map +0 -1
  190. package/dist/prosekit-extensions-doc.js.map +0 -1
  191. package/dist/prosekit-extensions-drop-cursor.d.ts.map +0 -1
  192. package/dist/prosekit-extensions-drop-cursor.js.map +0 -1
  193. package/dist/prosekit-extensions-drop-indicator.d.ts.map +0 -1
  194. package/dist/prosekit-extensions-drop-indicator.js +0 -2
  195. package/dist/prosekit-extensions-enter-rule.d.ts.map +0 -1
  196. package/dist/prosekit-extensions-enter-rule.js.map +0 -1
  197. package/dist/prosekit-extensions-file.js +0 -2
  198. package/dist/prosekit-extensions-gap-cursor.d.ts.map +0 -1
  199. package/dist/prosekit-extensions-gap-cursor.js.map +0 -1
  200. package/dist/prosekit-extensions-hard-break.d.ts.map +0 -1
  201. package/dist/prosekit-extensions-hard-break.js.map +0 -1
  202. package/dist/prosekit-extensions-heading.d.ts.map +0 -1
  203. package/dist/prosekit-extensions-heading.js.map +0 -1
  204. package/dist/prosekit-extensions-horizontal-rule.d.ts.map +0 -1
  205. package/dist/prosekit-extensions-horizontal-rule.js.map +0 -1
  206. package/dist/prosekit-extensions-image.d.ts.map +0 -1
  207. package/dist/prosekit-extensions-image.js.map +0 -1
  208. package/dist/prosekit-extensions-input-rule.d.ts.map +0 -1
  209. package/dist/prosekit-extensions-input-rule.js.map +0 -1
  210. package/dist/prosekit-extensions-italic.d.ts.map +0 -1
  211. package/dist/prosekit-extensions-italic.js.map +0 -1
  212. package/dist/prosekit-extensions-link.d.ts.map +0 -1
  213. package/dist/prosekit-extensions-link.js.map +0 -1
  214. package/dist/prosekit-extensions-list.d.ts.map +0 -1
  215. package/dist/prosekit-extensions-list.js.map +0 -1
  216. package/dist/prosekit-extensions-loro.d.ts.map +0 -1
  217. package/dist/prosekit-extensions-loro.js.map +0 -1
  218. package/dist/prosekit-extensions-mark-rule.d.ts.map +0 -1
  219. package/dist/prosekit-extensions-mark-rule.js +0 -2
  220. package/dist/prosekit-extensions-math.d.ts.map +0 -1
  221. package/dist/prosekit-extensions-math.js.map +0 -1
  222. package/dist/prosekit-extensions-mention.d.ts.map +0 -1
  223. package/dist/prosekit-extensions-mention.js.map +0 -1
  224. package/dist/prosekit-extensions-mod-click-prevention.d.ts.map +0 -1
  225. package/dist/prosekit-extensions-mod-click-prevention.js.map +0 -1
  226. package/dist/prosekit-extensions-page.d.ts.map +0 -1
  227. package/dist/prosekit-extensions-page.js.map +0 -1
  228. package/dist/prosekit-extensions-paragraph.d.ts.map +0 -1
  229. package/dist/prosekit-extensions-paragraph.js.map +0 -1
  230. package/dist/prosekit-extensions-paste-rule.d.ts.map +0 -1
  231. package/dist/prosekit-extensions-paste-rule.js +0 -2
  232. package/dist/prosekit-extensions-placeholder.d.ts.map +0 -1
  233. package/dist/prosekit-extensions-placeholder.js.map +0 -1
  234. package/dist/prosekit-extensions-readonly.d.ts.map +0 -1
  235. package/dist/prosekit-extensions-readonly.js.map +0 -1
  236. package/dist/prosekit-extensions-search.d.ts.map +0 -1
  237. package/dist/prosekit-extensions-search.js.map +0 -1
  238. package/dist/prosekit-extensions-strike.d.ts.map +0 -1
  239. package/dist/prosekit-extensions-strike.js.map +0 -1
  240. package/dist/prosekit-extensions-table.d.ts.map +0 -1
  241. package/dist/prosekit-extensions-table.js +0 -2
  242. package/dist/prosekit-extensions-text-align.d.ts.map +0 -1
  243. package/dist/prosekit-extensions-text-align.js.map +0 -1
  244. package/dist/prosekit-extensions-text-color.d.ts.map +0 -1
  245. package/dist/prosekit-extensions-text-color.js.map +0 -1
  246. package/dist/prosekit-extensions-text.d.ts.map +0 -1
  247. package/dist/prosekit-extensions-text.js.map +0 -1
  248. package/dist/prosekit-extensions-underline.d.ts.map +0 -1
  249. package/dist/prosekit-extensions-underline.js.map +0 -1
  250. package/dist/prosekit-extensions-virtual-selection.d.ts.map +0 -1
  251. package/dist/prosekit-extensions-virtual-selection.js.map +0 -1
  252. package/dist/prosekit-extensions-yjs.d.ts.map +0 -1
  253. package/dist/prosekit-extensions-yjs.js.map +0 -1
  254. package/dist/table.js.map +0 -1
  255. /package/dist/{prosekit-extensions-file.d.ts → file.d.ts} +0 -0
  256. /package/dist/{prosekit-extensions.js → index.js} +0 -0
  257. /package/dist/{prosekit-extensions.d.ts → index2.d.ts} +0 -0
@@ -1,7 +1,5 @@
1
1
  import { EditorState } from "@prosekit/pm/state";
2
2
  import { Extension } from "@prosekit/core";
3
-
4
- //#region src/autocomplete/autocomplete-rule.d.ts
5
3
  /**
6
4
  * Options for the {@link MatchHandler} callback.
7
5
  */
@@ -98,8 +96,6 @@ declare class AutocompleteRule {
98
96
  }) => boolean;
99
97
  constructor(options: AutocompleteRuleOptions);
100
98
  }
101
- //#endregion
102
- //#region src/autocomplete/autocomplete.d.ts
103
99
  /**
104
100
  * Defines an autocomplete extension that executes logic when the text before
105
101
  * the cursor matches the given regular expression.
@@ -109,6 +105,5 @@ declare class AutocompleteRule {
109
105
  * attribute containing the full matched string.
110
106
  */
111
107
  declare function defineAutocomplete(rule: AutocompleteRule): Extension;
112
- //#endregion
113
108
  export { AutocompleteRule, type AutocompleteRuleOptions, type CanMatchOptions, type CanMatchPredicate, type MatchHandler, type MatchHandlerOptions, defineAutocomplete };
114
- //# sourceMappingURL=prosekit-extensions-autocomplete.d.ts.map
109
+ //# sourceMappingURL=autocomplete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autocomplete.d.ts","names":[],"sources":["../src/autocomplete/autocomplete-rule.ts","../src/autocomplete/autocomplete.ts"],"mappings":";;;;AAOA;UAAiB,mBAAA;;;;EAIf,KAAA,EAAO,WAAA;EAKP;;;EAAA,KAAA,EAAO,eAAA;EAgBP;;;EAXA,IAAA;EAyBU;;;EApBV,EAAA;EAoBsD;AAKxD;;;EAnBE,WAAA;EAuBkB;AAMpB;;;;EAtBE,WAAA;AAAA;;;;;KAOU,YAAA,IAAgB,OAAA,EAAS,mBAAA;;;;UAKpB,eAAA;EAuBR;;;EAnBP,KAAA,EAAO,WAAA;AAAA;;;;KAMG,iBAAA,IAAqB,OAAA,EAAS,eAAA;AAuC1C;;;AAAA,UAlCiB,uBAAA;EAsCG;;;;;;;EA9BlB,KAAA,EAAO,MAAA;EA8BE;;;;EAxBT,OAAA,EAAS,YAAA;EA4BsB;;;EAvB/B,OAAA,GAAU,YAAA;EAyBW;;;;;EAlBrB,QAAA,GAAW,iBAAA;AAAA;;;;;;cAQA,gBAAA;ECvFwD;EAAA,SDyF1D,KAAA,EAAO,MAAA;;WAEP,OAAA,EAAS,YAAA;;WAET,OAAA,GAAU,YAAA;;WAEV,QAAA,GAAW,OAAA;IAAW,KAAA,EAAO,WAAA;EAAA;cAE1B,OAAA,EAAS,uBAAA;AAAA;;AAvGvB;;;;;;;iBCMgB,kBAAA,CAAmB,IAAA,EAAM,gBAAA,GAAmB,SAAA"}
@@ -1,7 +1,6 @@
1
1
  import { Plugin, PluginKey } from "@prosekit/pm/state";
2
2
  import { OBJECT_REPLACEMENT_CHARACTER, defineFacet, defineFacetPayload, pluginFacet } from "@prosekit/core";
3
3
  import { Decoration, DecorationSet } from "@prosekit/pm/view";
4
- //#region src/autocomplete/autocomplete-helpers.ts
5
4
  function defaultCanMatch({ state }) {
6
5
  const $pos = state.selection.$from;
7
6
  return !isInsideCodeBlock($pos) && !isInsideCodeMark($pos);
@@ -24,8 +23,6 @@ function setTrMeta(tr, meta) {
24
23
  return tr.setMeta(pluginKey, meta);
25
24
  }
26
25
  const pluginKey = new PluginKey("prosekit-autocomplete");
27
- //#endregion
28
- //#region src/autocomplete/autocomplete-rule.ts
29
26
  /**
30
27
  * An autocomplete rule that can be used to create an autocomplete extension.
31
28
  *
@@ -39,8 +36,6 @@ var AutocompleteRule = class {
39
36
  this.canMatch = options.canMatch ?? defaultCanMatch;
40
37
  }
41
38
  };
42
- //#endregion
43
- //#region src/autocomplete/autocomplete-plugin.ts
44
39
  /**
45
40
  * Creates a plugin that handles autocomplete functionality.
46
41
  *
@@ -223,8 +218,6 @@ function mapMatching(matching, mapping) {
223
218
  to: mapping.map(matching.to, -1)
224
219
  };
225
220
  }
226
- //#endregion
227
- //#region src/autocomplete/autocomplete.ts
228
221
  /**
229
222
  * Defines an autocomplete extension that executes logic when the text before
230
223
  * the cursor matches the given regular expression.
@@ -249,7 +242,6 @@ const autocompleteFacet = defineFacet({
249
242
  parent: pluginFacet,
250
243
  singleton: true
251
244
  });
252
- //#endregion
253
245
  export { AutocompleteRule, defineAutocomplete };
254
246
 
255
- //# sourceMappingURL=prosekit-extensions-autocomplete.js.map
247
+ //# sourceMappingURL=autocomplete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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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AAQ;AAC9B,WAAQ;AACR,UAAO;;;CAGX,QAAQ;CACR,WAAW;CACZ,CAAC"}
@@ -1,7 +1,5 @@
1
1
  import { Command } from "@prosekit/pm/state";
2
2
  import { Extension, Union } from "@prosekit/core";
3
-
4
- //#region src/background-color/background-color-spec.d.ts
5
3
  /**
6
4
  * Attributes for the `backgroundColor` mark.
7
5
  *
@@ -22,8 +20,6 @@ type BackgroundColorSpecExtension = Extension<{
22
20
  * @internal
23
21
  */
24
22
  declare function defineBackgroundColorSpec(): BackgroundColorSpecExtension;
25
- //#endregion
26
- //#region src/background-color/background-color-commands.d.ts
27
23
  /**
28
24
  * @internal
29
25
  */
@@ -45,8 +41,6 @@ type BackgroundColorCommandsExtension = Extension<{
45
41
  * @internal
46
42
  */
47
43
  declare function defineBackgroundColorCommands(): BackgroundColorCommandsExtension;
48
- //#endregion
49
- //#region src/background-color/background-color.d.ts
50
44
  /**
51
45
  * @internal
52
46
  */
@@ -57,6 +51,5 @@ type BackgroundColorExtension = Union<[BackgroundColorSpecExtension, BackgroundC
57
51
  * @public
58
52
  */
59
53
  declare function defineBackgroundColor(): BackgroundColorExtension;
60
- //#endregion
61
54
  export { type BackgroundColorAttrs, type BackgroundColorCommandsExtension, type BackgroundColorExtension, type BackgroundColorSpecExtension, addBackgroundColor, defineBackgroundColor, defineBackgroundColorCommands, defineBackgroundColorSpec, removeBackgroundColor };
62
- //# sourceMappingURL=prosekit-extensions-background-color.d.ts.map
55
+ //# sourceMappingURL=background-color.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"background-color.d.ts","names":[],"sources":["../src/background-color/background-color-spec.ts","../src/background-color/background-color-commands.ts","../src/background-color/background-color.ts"],"mappings":";;;;AAOA;;;UAAiB,oBAAA;EACf,KAAA;AAAA;;;;KAMU,4BAAA,GAA+B,SAAA;EACzC,KAAA;IACE,eAAA,EAAiB,oBAAA;EAAA;AAAA;;AAOrB;;iBAAgB,yBAAA,CAAA,GAA6B,4BAAA;AAhB7C;;;AAAA,iBCCgB,kBAAA,CAAmB,KAAA,EAAO,oBAAA,GAAuB,OAAA;;ADMjE;;iBCCgB,qBAAA,CAAA,GAAyB,OAAA;;;;KAO7B,gCAAA,GAAmC,SAAA;EAC7C,QAAA;IACE,kBAAA,GAAqB,KAAA,EAAO,oBAAA;IAC5B,qBAAA;EAAA;AAAA;;;;iBAOY,6BAAA,CAAA,GAAiC,gCAAA;ADzBjD;;;AAAA,KECY,wBAAA,GAA2B,KAAA,EAAO,4BAAA,EAA8B,gCAAA;;AFM5E;;;;iBECgB,qBAAA,CAAA,GAAyB,wBAAA"}
@@ -1,5 +1,4 @@
1
1
  import { addMark, defineCommands, defineMarkSpec, removeMark, union } from "@prosekit/core";
2
- //#region src/background-color/background-color-commands.ts
3
2
  /**
4
3
  * @internal
5
4
  */
@@ -24,8 +23,6 @@ function defineBackgroundColorCommands() {
24
23
  removeBackgroundColor
25
24
  });
26
25
  }
27
- //#endregion
28
- //#region src/background-color/background-color-spec.ts
29
26
  /**
30
27
  * @internal
31
28
  */
@@ -57,8 +54,6 @@ function defineBackgroundColorSpec() {
57
54
  }
58
55
  });
59
56
  }
60
- //#endregion
61
- //#region src/background-color/background-color.ts
62
57
  /**
63
58
  * Defines the `backgroundColor` mark and some commands for it.
64
59
  *
@@ -67,7 +62,6 @@ function defineBackgroundColorSpec() {
67
62
  function defineBackgroundColor() {
68
63
  return union(defineBackgroundColorSpec(), defineBackgroundColorCommands());
69
64
  }
70
- //#endregion
71
65
  export { addBackgroundColor, defineBackgroundColor, defineBackgroundColorCommands, defineBackgroundColorSpec, removeBackgroundColor };
72
66
 
73
- //# sourceMappingURL=prosekit-extensions-background-color.js.map
67
+ //# sourceMappingURL=background-color.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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"}
@@ -1,7 +1,5 @@
1
1
  import { Extension, PlainExtension, Union } from "@prosekit/core";
2
2
  import { Attrs } from "@prosekit/pm/model";
3
-
4
- //#region src/blockquote/blockquote-commands.d.ts
5
3
  type BlockquoteCommandsExtension = Extension<{
6
4
  Commands: {
7
5
  setBlockquote: [];
@@ -13,29 +11,21 @@ type BlockquoteCommandsExtension = Extension<{
13
11
  * @internal
14
12
  */
15
13
  declare function defineBlockquoteCommands(): BlockquoteCommandsExtension;
16
- //#endregion
17
- //#region src/blockquote/blockquote-input-rule.d.ts
18
14
  /**
19
15
  * Wraps the text block in a blockquote when `>` is typed at the start of a new
20
16
  * line followed by a space.
21
17
  */
22
18
  declare function defineBlockquoteInputRule(): PlainExtension;
23
- //#endregion
24
- //#region src/blockquote/blockquote-keymap.d.ts
25
19
  /**
26
20
  * @internal
27
21
  */
28
22
  declare function defineBlockquoteKeymap(): PlainExtension;
29
- //#endregion
30
- //#region src/blockquote/blockquote-spec.d.ts
31
23
  type BlockquoteSpecExtension = Extension<{
32
24
  Nodes: {
33
25
  blockquote: Attrs;
34
26
  };
35
27
  }>;
36
28
  declare function defineBlockquoteSpec(): BlockquoteSpecExtension;
37
- //#endregion
38
- //#region src/blockquote/blockquote.d.ts
39
29
  /**
40
30
  * @internal
41
31
  */
@@ -44,6 +34,5 @@ type BlockquoteExtension = Union<[BlockquoteSpecExtension, BlockquoteCommandsExt
44
34
  * @public
45
35
  */
46
36
  declare function defineBlockquote(): BlockquoteExtension;
47
- //#endregion
48
37
  export { type BlockquoteCommandsExtension, type BlockquoteExtension, type BlockquoteSpecExtension, defineBlockquote, defineBlockquoteCommands, defineBlockquoteInputRule, defineBlockquoteKeymap, defineBlockquoteSpec };
49
- //# sourceMappingURL=prosekit-extensions-blockquote.d.ts.map
38
+ //# sourceMappingURL=blockquote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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;;;ADN7C;iBEoBgB,sBAAA,CAAA,GAA0B,cAAA;AAAA,KCnB9B,uBAAA,GAA0B,SAAA;EACpC,KAAA;IACE,UAAA,EAAY,KAAA;EAAA;AAAA;AAAA,iBAIA,oBAAA,CAAA,GAAwB,uBAAA;AHPxC;;;AAAA,KIQY,mBAAA,GAAsB,KAAA,EAC/B,uBAAA,EAAyB,2BAAA;;;;iBAMZ,gBAAA,CAAA,GAAoB,mBAAA"}
@@ -1,7 +1,6 @@
1
- import { defineWrappingInputRule } from "./prosekit-extensions-input-rule.js";
1
+ import { defineWrappingInputRule } from "./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
- //#region src/blockquote/blockquote-commands.ts
5
4
  /**
6
5
  * @internal
7
6
  */
@@ -18,8 +17,6 @@ function defineBlockquoteCommands() {
18
17
  }
19
18
  });
20
19
  }
21
- //#endregion
22
- //#region src/blockquote/blockquote-input-rule.ts
23
20
  /**
24
21
  * Wraps the text block in a blockquote when `>` is typed at the start of a new
25
22
  * line followed by a space.
@@ -30,8 +27,6 @@ function defineBlockquoteInputRule() {
30
27
  type: "blockquote"
31
28
  });
32
29
  }
33
- //#endregion
34
- //#region src/blockquote/blockquote-keymap.ts
35
30
  function toggleBlockquoteKeybinding() {
36
31
  return toggleWrap({ type: "blockquote" });
37
32
  }
@@ -51,8 +46,6 @@ function defineBlockquoteKeymap() {
51
46
  "Backspace": backspaceUnsetBlockquote()
52
47
  });
53
48
  }
54
- //#endregion
55
- //#region src/blockquote/blockquote-spec.ts
56
49
  function defineBlockquoteSpec() {
57
50
  return defineNodeSpec({
58
51
  name: "blockquote",
@@ -65,15 +58,12 @@ function defineBlockquoteSpec() {
65
58
  }
66
59
  });
67
60
  }
68
- //#endregion
69
- //#region src/blockquote/blockquote.ts
70
61
  /**
71
62
  * @public
72
63
  */
73
64
  function defineBlockquote() {
74
65
  return union(defineBlockquoteSpec(), defineBlockquoteInputRule(), defineBlockquoteCommands(), defineBlockquoteKeymap());
75
66
  }
76
- //#endregion
77
67
  export { defineBlockquote, defineBlockquoteCommands, defineBlockquoteInputRule, defineBlockquoteKeymap, defineBlockquoteSpec };
78
68
 
79
- //# sourceMappingURL=prosekit-extensions-blockquote.js.map
69
+ //# sourceMappingURL=blockquote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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,KAC3B,EAAE,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"}
@@ -1,7 +1,5 @@
1
1
  import { Extension, PlainExtension, Union } from "@prosekit/core";
2
2
  import { Attrs } from "@prosekit/pm/model";
3
-
4
- //#region src/bold/bold-commands.d.ts
5
3
  /**
6
4
  * @internal
7
5
  */
@@ -14,20 +12,14 @@ type BoldCommandsExtension = Extension<{
14
12
  * @internal
15
13
  */
16
14
  declare function defineBoldCommands(): BoldCommandsExtension;
17
- //#endregion
18
- //#region src/bold/bold-input-rule.d.ts
19
15
  /**
20
16
  * @internal
21
17
  */
22
18
  declare function defineBoldInputRule(): PlainExtension;
23
- //#endregion
24
- //#region src/bold/bold-keymap.d.ts
25
19
  /**
26
20
  * @internal
27
21
  */
28
22
  declare function defineBoldKeymap(): PlainExtension;
29
- //#endregion
30
- //#region src/bold/bold-spec.d.ts
31
23
  /**
32
24
  * @internal
33
25
  */
@@ -40,8 +32,6 @@ type BoldSpecExtension = Extension<{
40
32
  * @internal
41
33
  */
42
34
  declare function defineBoldSpec(): BoldSpecExtension;
43
- //#endregion
44
- //#region src/bold/bold.d.ts
45
35
  /**
46
36
  * @internal
47
37
  */
@@ -50,6 +40,5 @@ type BoldExtension = Union<[BoldSpecExtension, BoldCommandsExtension]>;
50
40
  * @public
51
41
  */
52
42
  declare function defineBold(): BoldExtension;
53
- //#endregion
54
43
  export { type BoldCommandsExtension, type BoldExtension, type BoldSpecExtension, defineBold, defineBoldCommands, defineBoldInputRule, defineBoldKeymap, defineBoldSpec };
55
- //# sourceMappingURL=prosekit-extensions-bold.d.ts.map
44
+ //# sourceMappingURL=bold.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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":";;;;AAKA;KAAY,qBAAA,GAAwB,SAAA;EAClC,QAAA;IACE,UAAA;EAAA;AAAA;;;;iBAOY,kBAAA,CAAA,GAAsB,qBAAA;;;AATtC;iBCEgB,mBAAA,CAAA,GAAuB,cAAA;;;ADFvC;iBEAgB,gBAAA,CAAA,GAAoB,cAAA;;AFApC;;KGCY,iBAAA,GAAoB,SAAA;EAC9B,KAAA;IACE,IAAA,EAAM,KAAA;EAAA;AAAA;;;AHMV;iBGCgB,cAAA,CAAA,GAAkB,iBAAA;AHVlC;;;AAAA,KIKY,aAAA,GAAgB,KAAA,EAAO,iBAAA,EAAmB,qBAAA;;;;iBAKtC,UAAA,CAAA,GAAc,aAAA"}
@@ -1,14 +1,11 @@
1
- import { defineMarkInputRule } from "./prosekit-extensions-input-rule.js";
1
+ import { defineMarkInputRule } from "./input-rule.js";
2
2
  import { canUseRegexLookbehind, defineCommands, defineKeymap, defineMarkSpec, toggleMark, union } from "@prosekit/core";
3
- //#region src/bold/bold-commands.ts
4
3
  /**
5
4
  * @internal
6
5
  */
7
6
  function defineBoldCommands() {
8
7
  return defineCommands({ toggleBold: () => toggleMark({ type: "bold" }) });
9
8
  }
10
- //#endregion
11
- //#region src/bold/bold-input-rule.ts
12
9
  /**
13
10
  * @internal
14
11
  */
@@ -18,16 +15,12 @@ function defineBoldInputRule() {
18
15
  type: "bold"
19
16
  });
20
17
  }
21
- //#endregion
22
- //#region src/bold/bold-keymap.ts
23
18
  /**
24
19
  * @internal
25
20
  */
26
21
  function defineBoldKeymap() {
27
22
  return defineKeymap({ "Mod-b": toggleMark({ type: "bold" }) });
28
23
  }
29
- //#endregion
30
- //#region src/bold/bold-spec.ts
31
24
  /**
32
25
  * @internal
33
26
  */
@@ -58,15 +51,12 @@ function defineBoldSpec() {
58
51
  }
59
52
  });
60
53
  }
61
- //#endregion
62
- //#region src/bold/bold.ts
63
54
  /**
64
55
  * @public
65
56
  */
66
57
  function defineBold() {
67
58
  return union(defineBoldSpec(), defineBoldCommands(), defineBoldKeymap(), defineBoldInputRule());
68
59
  }
69
- //#endregion
70
60
  export { defineBold, defineBoldCommands, defineBoldInputRule, defineBoldKeymap, defineBoldSpec };
71
61
 
72
- //# sourceMappingURL=prosekit-extensions-bold.js.map
62
+ //# sourceMappingURL=bold.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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,8 +1,6 @@
1
1
  import { Extension, PlainExtension, Union } from "@prosekit/core";
2
2
  import { Parser } from "prosemirror-highlight";
3
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";
4
-
5
- //#region src/code-block/code-block-types.d.ts
6
4
  /**
7
5
  * The attributes for the `codeBlock` node.
8
6
  *
@@ -11,8 +9,6 @@ import { BundledHighlighterOptions, BundledLanguage, BundledLanguage as ShikiBun
11
9
  interface CodeBlockAttrs {
12
10
  language: string;
13
11
  }
14
- //#endregion
15
- //#region src/code-block/code-block-commands.d.ts
16
12
  /**
17
13
  * @internal
18
14
  */
@@ -30,8 +26,6 @@ type CodeBlockCommandsExtension = Extension<{
30
26
  * @public
31
27
  */
32
28
  declare function defineCodeBlockCommands(): CodeBlockCommandsExtension;
33
- //#endregion
34
- //#region src/code-block/code-block-highlight.d.ts
35
29
  /**
36
30
  * @public
37
31
  *
@@ -67,8 +61,6 @@ declare function defineCodeBlockHighlight({
67
61
  parser,
68
62
  nodeTypes
69
63
  }: CodeBlockHighlightOptions): Extension;
70
- //#endregion
71
- //#region src/code-block/code-block-input-rule.d.ts
72
64
  /**
73
65
  * Adds input rules for `codeBlock` nodes.
74
66
  *
@@ -81,17 +73,11 @@ declare function defineCodeBlockInputRule(): PlainExtension;
81
73
  * @public
82
74
  */
83
75
  declare function defineCodeBlockEnterRule(): PlainExtension;
84
- //#endregion
85
- //#region src/code-block/code-block-keymap.d.ts
86
76
  /**
87
77
  * Defines the keymap for code blocks.
88
78
  */
89
79
  declare function defineCodeBlockKeymap(): PlainExtension;
90
- //#endregion
91
- //#region src/code-block/shiki-highlighter-chunk.d.ts
92
80
  interface ShikiHighlighterOptions extends BundledHighlighterOptions<BundledLanguage, BundledTheme> {}
93
- //#endregion
94
- //#region src/code-block/code-block-shiki.d.ts
95
81
  /**
96
82
  * The options to configure the Shiki highlighter.
97
83
  *
@@ -140,8 +126,6 @@ declare function defineCodeBlockShiki({
140
126
  langs,
141
127
  ...rest
142
128
  }?: CodeBlockShikiOptions): Extension;
143
- //#endregion
144
- //#region src/code-block/code-block-spec.d.ts
145
129
  /**
146
130
  * @internal
147
131
  */
@@ -156,8 +140,6 @@ type CodeBlockSpecExtension = Extension<{
156
140
  * @public
157
141
  */
158
142
  declare function defineCodeBlockSpec(): CodeBlockSpecExtension;
159
- //#endregion
160
- //#region src/code-block/code-block.d.ts
161
143
  /**
162
144
  * @internal
163
145
  */
@@ -174,6 +156,5 @@ type CodeBlockExtension = Union<[CodeBlockSpecExtension, CodeBlockCommandsExtens
174
156
  * @public
175
157
  */
176
158
  declare function defineCodeBlock(): CodeBlockExtension;
177
- //#endregion
178
159
  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 };
179
- //# sourceMappingURL=prosekit-extensions-code-block.d.ts.map
160
+ //# sourceMappingURL=code-block.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts"],"mappings":";;;;;;;AAKA;UAAiB,cAAA;EACf,QAAA;AAAA;;;AADF;KCEY,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;;;;;;iBASf,uBAAA,CAAA,GAA2B,0BAAA;;;ADhB3C;;;KEGY,eAAA,GAAkB,MAAA;;;ADD9B;KCMY,yBAAA;;;;EAIV,MAAA,EAAQ,eAAA;EDLqB;;;;;ECW7B,SAAA;AAAA;;;;;;;;;;;iBAac,wBAAA,CAAA;EACd,MAAA;EACA;AAAA,GACC,yBAAA,GAA4B,SAAA;;;;AFlC/B;;iBGOgB,wBAAA,CAAA,GAA4B,cAAA;;;;AFL5C;;iBEkBgB,wBAAA,CAAA,GAA4B,cAAA;;;;iBCnB5B,qBAAA,CAAA,GAAyB,cAAA;AAAA,UCGxB,uBAAA,SAAgC,yBAAA,CAA0B,eAAA,EAAiB,YAAA;ALJ5F;;;;;AAAA,UMQiB,qBAAA,SAA8B,IAAA,CAAK,uBAAA;ELNxC;;;;;EKYV,SAAA;ELP6B;;;;;;EKe7B,MAAA,GAAS,iBAAA;ELlBQ;;;;;EKyBjB,KAAA,IAAS,oBAAA,GAAuB,eAAA;ELvBZ;;;EK4BpB,MAAA,GAAS,uBAAA;AAAA;;;ALlBX;;;;;;ACbA;;;;iBI8CgB,oBAAA,CAAA;EACd,SAAA;EACA,MAAA;EACA,KAAA;EAAA,GACG;AAAA,IACF,qBAAA,GAA6B,SAAA;;;ANtDhC;KOEY,sBAAA,GAAyB,SAAA;EACnC,KAAA;IACE,SAAA,EAAW,cAAA;EAAA;AAAA;ANFf;;;;;AAAA,iBMWgB,mBAAA,CAAA,GAAuB,sBAAA;;APbvC;;KQKY,kBAAA,GAAqB,KAAA,EAC9B,sBAAA,EAAwB,0BAAA;APJ3B;;;;;;;;;;;AAAA,iBOkBgB,eAAA,CAAA,GAAmB,kBAAA"}
@@ -1,11 +1,10 @@
1
- import { defineTextBlockInputRule } from "./prosekit-extensions-input-rule.js";
2
- import { defineTextBlockEnterRule } from "./prosekit-extensions-enter-rule.js";
1
+ import { defineTextBlockInputRule } from "./input-rule.js";
2
+ import { defineTextBlockEnterRule } from "./enter-rule.js";
3
3
  import { TextSelection } from "@prosekit/pm/state";
4
4
  import { defaultBlockAt, defineCommands, defineKeymap, defineNodeSpec, definePlugin, insertNode, setBlockType, setNodeAttrs, toggleNode, union } from "@prosekit/core";
5
5
  import { createHighlightPlugin } from "prosemirror-highlight";
6
6
  import { createParser } from "prosemirror-highlight/shiki";
7
7
  import { bundledLanguagesInfo as shikiBundledLanguagesInfo, bundledThemesInfo as shikiBundledThemesInfo } from "shiki";
8
- //#region src/code-block/code-block-commands.ts
9
8
  /**
10
9
  * Adds commands for working with `codeBlock` nodes.
11
10
  *
@@ -39,8 +38,6 @@ function defineCodeBlockCommands() {
39
38
  }
40
39
  });
41
40
  }
42
- //#endregion
43
- //#region src/code-block/code-block-highlight.ts
44
41
  /**
45
42
  * Adds syntax highlighting to code blocks. This function requires a `Parser`
46
43
  * instance from the `prosemirror-highlight` package. See the
@@ -57,8 +54,6 @@ function defineCodeBlockHighlight({ parser, nodeTypes = ["codeBlock", "mathBlock
57
54
  nodeTypes
58
55
  }));
59
56
  }
60
- //#endregion
61
- //#region src/code-block/code-block-input-rule.ts
62
57
  /**
63
58
  * Adds input rules for `codeBlock` nodes.
64
59
  *
@@ -86,8 +81,6 @@ function defineCodeBlockEnterRule() {
86
81
  function getAttrs(match) {
87
82
  return { language: match[1] || "" };
88
83
  }
89
- //#endregion
90
- //#region src/code-block/code-block-keymap.ts
91
84
  /**
92
85
  * Defines the keymap for code blocks.
93
86
  */
@@ -122,8 +115,6 @@ const existCodeBlock = (state, dispatch) => {
122
115
  }
123
116
  return false;
124
117
  };
125
- //#endregion
126
- //#region src/code-block/shiki-highlighter.ts
127
118
  let loaded;
128
119
  async function load() {
129
120
  const { createOrGetHighlighter } = await import("./shiki-highlighter-chunk.js");
@@ -133,8 +124,6 @@ function createOrGetHighlighter(options) {
133
124
  if (!loaded) return { promise: load() };
134
125
  return loaded(options);
135
126
  }
136
- //#endregion
137
- //#region src/code-block/shiki-parser.ts
138
127
  /**
139
128
  * @internal
140
129
  */
@@ -151,8 +140,6 @@ function createLazyParser(highlighterOptions) {
151
140
  return parser(options);
152
141
  };
153
142
  }
154
- //#endregion
155
- //#region src/code-block/code-block-shiki.ts
156
143
  /**
157
144
  * Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.
158
145
  *
@@ -175,8 +162,6 @@ function defineCodeBlockShiki({ nodeTypes, themes = ["one-dark-pro"], langs = ["
175
162
  nodeTypes
176
163
  });
177
164
  }
178
- //#endregion
179
- //#region src/code-block/code-block-spec.ts
180
165
  /**
181
166
  * Defines the `codeBlock` node spec.
182
167
  *
@@ -223,8 +208,6 @@ function extractLanguageFromElement(element) {
223
208
  if (match) return match[1];
224
209
  return "";
225
210
  }
226
- //#endregion
227
- //#region src/code-block/code-block.ts
228
211
  /**
229
212
  * Adds `codeBlock` nodes to the editor. This includes the following extensions:
230
213
  *
@@ -239,7 +222,6 @@ function extractLanguageFromElement(element) {
239
222
  function defineCodeBlock() {
240
223
  return union(defineCodeBlockSpec(), defineCodeBlockInputRule(), defineCodeBlockEnterRule(), defineCodeBlockKeymap(), defineCodeBlockCommands());
241
224
  }
242
- //#endregion
243
225
  export { defineCodeBlock, defineCodeBlockCommands, defineCodeBlockEnterRule, defineCodeBlockHighlight, defineCodeBlockInputRule, defineCodeBlockKeymap, defineCodeBlockShiki, defineCodeBlockSpec, shikiBundledLanguagesInfo, shikiBundledThemesInfo };
244
226
 
245
- //# sourceMappingURL=prosekit-extensions-code-block.js.map
227
+ //# sourceMappingURL=code-block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-block.js","names":[],"sources":["../src/code-block/code-block-commands.ts","../src/code-block/code-block-highlight.ts","../src/code-block/code-block-input-rule.ts","../src/code-block/code-block-keymap.ts","../src/code-block/shiki-highlighter.ts","../src/code-block/shiki-parser.ts","../src/code-block/code-block-shiki.ts","../src/code-block/code-block-spec.ts","../src/code-block/code-block.ts"],"sourcesContent":["import { defineCommands, insertNode, setBlockType, setNodeAttrs, toggleNode, type Extension } from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types.ts'\n\n/**\n * @internal\n */\nexport type CodeBlockCommandsExtension = Extension<{\n Commands: {\n setCodeBlock: [attrs?: CodeBlockAttrs]\n insertCodeBlock: [attrs?: CodeBlockAttrs]\n toggleCodeBlock: [attrs?: CodeBlockAttrs]\n setCodeBlockAttrs: [attrs: CodeBlockAttrs]\n }\n}>\n\n/**\n * Adds commands for working with `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockCommands(): CodeBlockCommandsExtension {\n return defineCommands({\n setCodeBlock: (attrs?: CodeBlockAttrs) => {\n return setBlockType({ type: 'codeBlock', attrs })\n },\n insertCodeBlock: (attrs?: CodeBlockAttrs) => {\n return insertNode({ type: 'codeBlock', attrs })\n },\n toggleCodeBlock: (attrs?: CodeBlockAttrs) => {\n return toggleNode({ type: 'codeBlock', attrs })\n },\n setCodeBlockAttrs: (attrs: CodeBlockAttrs) => {\n return setNodeAttrs({ type: 'codeBlock', attrs })\n },\n })\n}\n","import { definePlugin, type Extension } from '@prosekit/core'\nimport { createHighlightPlugin, type Parser } from 'prosemirror-highlight'\n\n/**\n * @public\n *\n * An alias for the `Parser` type from the `prosemirror-highlight` package.\n */\nexport type HighlightParser = Parser\n\n/**\n * @public\n */\nexport type CodeBlockHighlightOptions = {\n /**\n * A parser instance from the `prosemirror-highlight` package.\n */\n parser: HighlightParser\n /**\n * ProseMirror node types to highlight.\n *\n * @default ['codeBlock', 'mathBlock']\n */\n nodeTypes?: string[]\n}\n\n/**\n * Adds syntax highlighting to code blocks. This function requires a `Parser`\n * instance from the `prosemirror-highlight` package. See the\n * [documentation](https://github.com/ocavue/prosemirror-highlight) for more\n * information.\n *\n * @param options\n *\n * @public\n */\nexport function defineCodeBlockHighlight({\n parser,\n nodeTypes = ['codeBlock', 'mathBlock'],\n}: CodeBlockHighlightOptions): Extension {\n return definePlugin(\n createHighlightPlugin({ parser, nodeTypes }),\n )\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport { defineTextBlockEnterRule } from '../enter-rule/index.ts'\nimport { defineTextBlockInputRule } from '../input-rule/index.ts'\n\nimport type { CodeBlockAttrs } from './code-block-types.ts'\n\n/**\n * Adds input rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockInputRule(): PlainExtension {\n return defineTextBlockInputRule({\n regex: /^```(\\S*)\\s$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\n/**\n * Adds enter rules for `codeBlock` nodes.\n *\n * @public\n */\nexport function defineCodeBlockEnterRule(): PlainExtension {\n return defineTextBlockEnterRule({\n regex: /^```(\\S*)$/,\n type: 'codeBlock',\n attrs: getAttrs,\n })\n}\n\nfunction getAttrs(match: RegExpMatchArray): CodeBlockAttrs {\n return { language: match[1] || '' }\n}\n","import { defaultBlockAt, defineKeymap, type PlainExtension } from '@prosekit/core'\nimport { TextSelection, type Command } from '@prosekit/pm/state'\n\n/**\n * Defines the keymap for code blocks.\n */\nexport function defineCodeBlockKeymap(): PlainExtension {\n return defineKeymap({\n Enter: existCodeBlock,\n })\n}\n\n/**\n * Exit a code block and insert a default block below if the cursor is at the\n * end of the code block and the code block is ended with two new lines.\n */\nconst existCodeBlock: Command = (state, dispatch) => {\n if (!state.selection.empty) {\n return false\n }\n\n const { $head } = state.selection\n const parent = $head.parent\n if (\n parent.isTextblock\n && parent.type.spec.code\n && $head.parentOffset === parent.content.size\n && parent.textContent.endsWith('\\n\\n')\n ) {\n const grandParent = $head.node(-1)\n const insertIndex = $head.indexAfter(-1)\n const type = defaultBlockAt(grandParent.contentMatchAt(insertIndex))\n\n if (!type || !grandParent.canReplaceWith(insertIndex, insertIndex, type)) {\n return false\n }\n\n if (dispatch) {\n const { tr } = state\n tr.delete($head.pos - 2, $head.pos)\n const pos = tr.selection.$head.after()\n const node = type.createAndFill()\n if (node) {\n tr.replaceWith(pos, pos, node)\n tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1))\n dispatch(tr.scrollIntoView())\n }\n }\n\n return true\n }\n\n return false\n}\n","import type { HighlighterOptions, HighlighterResult } from './shiki-highlighter-chunk.ts'\n\nlet loaded: ((options: HighlighterOptions) => HighlighterResult) | undefined\n\nasync function load() {\n const { createOrGetHighlighter } = await import('./shiki-highlighter-chunk.ts')\n loaded = createOrGetHighlighter\n}\n\nexport function createOrGetHighlighter(\n options: HighlighterOptions,\n): HighlighterResult {\n if (!loaded) {\n return { promise: load() }\n }\n return loaded(options)\n}\n\nexport type { HighlighterOptions }\n","import type { Parser } from 'prosemirror-highlight'\nimport { createParser } from 'prosemirror-highlight/shiki'\n\nimport type { ShikiBundledLanguage } from './shiki-bundle.ts'\nimport { createOrGetHighlighter, type HighlighterOptions } from './shiki-highlighter.ts'\n\n/**\n * @internal\n */\nexport function createLazyParser(\n highlighterOptions: HighlighterOptions,\n): Parser {\n let parser: Parser | undefined\n\n return function lazyParser(options) {\n const language = (options.language || '') as ShikiBundledLanguage\n const { highlighter, promise } = createOrGetHighlighter({\n ...highlighterOptions,\n langs: [language],\n })\n\n if (!highlighter) {\n return promise\n }\n\n if (!parser) {\n parser = createParser(highlighter, {\n theme: highlighterOptions.themes[0],\n })\n }\n return parser(options)\n }\n}\n","import type { Extension } from '@prosekit/core'\nimport type { SpecialLanguage } from 'shiki'\n\nimport { defineCodeBlockHighlight } from './code-block-highlight.ts'\nimport type { ShikiBundledLanguage, ShikiBundledTheme } from './shiki-bundle.ts'\nimport type { ShikiHighlighterOptions } from './shiki-highlighter-chunk.ts'\nimport { createLazyParser } from './shiki-parser.ts'\n\n/**\n * The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport interface CodeBlockShikiOptions extends Omit<ShikiHighlighterOptions, 'themes' | 'langs' | 'engine'> {\n /**\n * ProseMirror node types to highlight.\n *\n * @default ['codeBlock', 'mathBlock']\n */\n nodeTypes?: string[]\n\n /**\n * A list of Shiki themes to pre-load. The first theme in the list will be\n * used to render the code block.\n *\n * @default ['one-dark-pro']\n */\n themes?: ShikiBundledTheme[]\n\n /**\n * A list of Shiki languages to pre-load.\n *\n * @default ['text']\n */\n langs?: (ShikiBundledLanguage | SpecialLanguage)[]\n\n /**\n * The RegExp engine to use. By default, the JavaScript engine is used.\n */\n engine?: ShikiHighlighterOptions['engine']\n}\n\n/**\n * Adds syntax highlighting to code blocks using the [Shiki](https://github.com/shikijs/shiki) package.\n *\n * It will set two CSS variables on the code block elements:\n *\n * - `--prosemirror-highlight`: sets text color\n * - `--prosemirror-highlight-bg`: sets background color\n *\n * @param options - The options to configure the Shiki highlighter.\n *\n * @public\n */\nexport function defineCodeBlockShiki({\n nodeTypes,\n themes = ['one-dark-pro'],\n langs = ['text'],\n ...rest\n}: CodeBlockShikiOptions = {}): Extension {\n const parser = createLazyParser({ themes, langs, ...rest })\n return defineCodeBlockHighlight({ parser, nodeTypes })\n}\n","import { defineNodeSpec, type Extension } from '@prosekit/core'\n\nimport type { CodeBlockAttrs } from './code-block-types.ts'\n\n/**\n * @internal\n */\nexport type CodeBlockSpecExtension = Extension<{\n Nodes: {\n codeBlock: CodeBlockAttrs\n }\n}>\n\n/**\n * Defines the `codeBlock` node spec.\n *\n * @public\n */\nexport function defineCodeBlockSpec(): CodeBlockSpecExtension {\n return defineNodeSpec({\n name: 'codeBlock',\n content: 'text*',\n group: 'block',\n code: true,\n defining: true,\n marks: '',\n attrs: { language: { default: '', validate: 'string' } },\n parseDOM: [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n getAttrs: (node): CodeBlockAttrs => {\n const language = extractLanguageFromElement(node)\n || extractLanguageFromElement(node.querySelector('code'))\n return { language }\n },\n },\n ],\n toDOM(node) {\n const { language } = node.attrs as CodeBlockAttrs\n return [\n 'pre',\n { 'data-language': language || undefined },\n // `class: language-${language}` is used by remark-rehype to highlight the code block\n ['code', { class: language ? `language-${language}` : undefined }, 0],\n ]\n },\n })\n}\n\nfunction extractLanguageFromElement(element: HTMLElement | null | undefined): string {\n if (!element) {\n return ''\n }\n\n const attr = element.getAttribute('data-language')\n if (attr) {\n return attr\n }\n\n const className = element.className\n const match = className.match(/language-(\\w+)/)\n if (match) {\n return match[1]\n }\n\n return ''\n}\n","import { union, type Union } from '@prosekit/core'\n\nimport { defineCodeBlockCommands, type CodeBlockCommandsExtension } from './code-block-commands.ts'\nimport { defineCodeBlockEnterRule, defineCodeBlockInputRule } from './code-block-input-rule.ts'\nimport { defineCodeBlockKeymap } from './code-block-keymap.ts'\nimport { defineCodeBlockSpec, type CodeBlockSpecExtension } from './code-block-spec.ts'\n\n/**\n * @internal\n */\nexport type CodeBlockExtension = Union<\n [CodeBlockSpecExtension, CodeBlockCommandsExtension]\n>\n\n/**\n * Adds `codeBlock` nodes to the editor. This includes the following extensions:\n *\n * - {@link defineCodeBlockSpec}\n * - {@link defineCodeBlockInputRule}\n * - {@link defineCodeBlockEnterRule}\n * - {@link defineCodeBlockKeymap}\n * - {@link defineCodeBlockCommands}.\n *\n * @public\n */\nexport function defineCodeBlock(): CodeBlockExtension {\n return union(\n defineCodeBlockSpec(),\n defineCodeBlockInputRule(),\n defineCodeBlockEnterRule(),\n defineCodeBlockKeymap(),\n defineCodeBlockCommands(),\n )\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,SAAgB,0BAAsD;AACpE,QAAO,eAAe;EACpB,eAAe,UAA2B;AACxC,UAAO,aAAa;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEnD,kBAAkB,UAA2B;AAC3C,UAAO,WAAW;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEjD,kBAAkB,UAA2B;AAC3C,UAAO,WAAW;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEjD,oBAAoB,UAA0B;AAC5C,UAAO,aAAa;IAAE,MAAM;IAAa;IAAO,CAAC;;EAEpD,CAAC;;;;;;;;;;;;ACCJ,SAAgB,yBAAyB,EACvC,QACA,YAAY,CAAC,aAAa,YAAY,IACC;AACvC,QAAO,aACL,sBAA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