@doist/typist 10.0.0-next.1 → 10.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/dist/components/typist-editor.d.ts +126 -123
  2. package/dist/components/typist-editor.d.ts.map +1 -1
  3. package/dist/components/typist-editor.helper.d.ts +8 -11
  4. package/dist/components/typist-editor.helper.d.ts.map +1 -1
  5. package/dist/components/typist-editor.helper.js +21 -19
  6. package/dist/components/typist-editor.helper.js.map +1 -0
  7. package/dist/components/typist-editor.js +133 -135
  8. package/dist/components/typist-editor.js.map +1 -0
  9. package/dist/constants/common.js +9 -5
  10. package/dist/constants/common.js.map +1 -0
  11. package/dist/constants/extension-priorities.d.ts +3 -1
  12. package/dist/constants/extension-priorities.d.ts.map +1 -1
  13. package/dist/constants/extension-priorities.js +34 -30
  14. package/dist/constants/extension-priorities.js.map +1 -0
  15. package/dist/constants/regular-expressions.js +14 -10
  16. package/dist/constants/regular-expressions.js.map +1 -0
  17. package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.d.ts +12 -9
  18. package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.d.ts.map +1 -1
  19. package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.js +16 -19
  20. package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.js.map +1 -0
  21. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.d.ts +12 -9
  22. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.d.ts.map +1 -1
  23. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.js +25 -28
  24. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.js.map +1 -0
  25. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.d.ts +24 -22
  26. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.d.ts.map +1 -1
  27. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js +34 -36
  28. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js.map +1 -0
  29. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts +23 -20
  30. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts.map +1 -1
  31. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.js +15 -8
  32. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.js.map +1 -0
  33. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.js +22 -18
  34. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.js.map +1 -0
  35. package/dist/extensions/core/view-event-handlers.d.ts +14 -13
  36. package/dist/extensions/core/view-event-handlers.d.ts.map +1 -1
  37. package/dist/extensions/core/view-event-handlers.js +33 -31
  38. package/dist/extensions/core/view-event-handlers.js.map +1 -0
  39. package/dist/extensions/plain-text/paste-multiline-text.js +45 -59
  40. package/dist/extensions/plain-text/paste-multiline-text.js.map +1 -0
  41. package/dist/extensions/plain-text/plain-text-document.d.ts +7 -7
  42. package/dist/extensions/plain-text/plain-text-document.d.ts.map +1 -1
  43. package/dist/extensions/plain-text/plain-text-document.js +14 -13
  44. package/dist/extensions/plain-text/plain-text-document.js.map +1 -0
  45. package/dist/extensions/plain-text/plain-text-kit.d.ts +35 -33
  46. package/dist/extensions/plain-text/plain-text-kit.d.ts.map +1 -1
  47. package/dist/extensions/plain-text/plain-text-kit.js +33 -48
  48. package/dist/extensions/plain-text/plain-text-kit.js.map +1 -0
  49. package/dist/extensions/plain-text/plain-text-paragraph.d.ts +2 -9
  50. package/dist/extensions/plain-text/plain-text-paragraph.js +11 -11
  51. package/dist/extensions/plain-text/plain-text-paragraph.js.map +1 -0
  52. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.js +37 -81
  53. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.js.map +1 -0
  54. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.js +32 -42
  55. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.js.map +1 -0
  56. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.js +24 -37
  57. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.js.map +1 -0
  58. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.js +21 -13
  59. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.js.map +1 -0
  60. package/dist/extensions/rich-text/bold-and-italics.js +42 -40
  61. package/dist/extensions/rich-text/bold-and-italics.js.map +1 -0
  62. package/dist/extensions/rich-text/curvenote-codemark.js +16 -14
  63. package/dist/extensions/rich-text/curvenote-codemark.js.map +1 -0
  64. package/dist/extensions/rich-text/paste-emojis.js +20 -22
  65. package/dist/extensions/rich-text/paste-emojis.js.map +1 -0
  66. package/dist/extensions/rich-text/paste-markdown.js +46 -86
  67. package/dist/extensions/rich-text/paste-markdown.js.map +1 -0
  68. package/dist/extensions/rich-text/rich-text-bullet-list.d.ts +10 -9
  69. package/dist/extensions/rich-text/rich-text-bullet-list.d.ts.map +1 -1
  70. package/dist/extensions/rich-text/rich-text-bullet-list.js +42 -56
  71. package/dist/extensions/rich-text/rich-text-bullet-list.js.map +1 -0
  72. package/dist/extensions/rich-text/rich-text-code.js +34 -34
  73. package/dist/extensions/rich-text/rich-text-code.js.map +1 -0
  74. package/dist/extensions/rich-text/rich-text-document.d.ts +7 -7
  75. package/dist/extensions/rich-text/rich-text-document.d.ts.map +1 -1
  76. package/dist/extensions/rich-text/rich-text-document.js +14 -13
  77. package/dist/extensions/rich-text/rich-text-document.js.map +1 -0
  78. package/dist/extensions/rich-text/rich-text-heading.d.ts +5 -4
  79. package/dist/extensions/rich-text/rich-text-heading.d.ts.map +1 -1
  80. package/dist/extensions/rich-text/rich-text-heading.js +25 -25
  81. package/dist/extensions/rich-text/rich-text-heading.js.map +1 -0
  82. package/dist/extensions/rich-text/rich-text-image.d.ts +53 -52
  83. package/dist/extensions/rich-text/rich-text-image.d.ts.map +1 -1
  84. package/dist/extensions/rich-text/rich-text-image.js +88 -105
  85. package/dist/extensions/rich-text/rich-text-image.js.map +1 -0
  86. package/dist/extensions/rich-text/rich-text-kit.d.ts +127 -125
  87. package/dist/extensions/rich-text/rich-text-kit.d.ts.map +1 -1
  88. package/dist/extensions/rich-text/rich-text-kit.js +73 -135
  89. package/dist/extensions/rich-text/rich-text-kit.js.map +1 -0
  90. package/dist/extensions/rich-text/rich-text-link.d.ts +5 -4
  91. package/dist/extensions/rich-text/rich-text-link.d.ts.map +1 -1
  92. package/dist/extensions/rich-text/rich-text-link.js +82 -90
  93. package/dist/extensions/rich-text/rich-text-link.js.map +1 -0
  94. package/dist/extensions/rich-text/rich-text-ordered-list.d.ts +10 -9
  95. package/dist/extensions/rich-text/rich-text-ordered-list.d.ts.map +1 -1
  96. package/dist/extensions/rich-text/rich-text-ordered-list.js +42 -56
  97. package/dist/extensions/rich-text/rich-text-ordered-list.js.map +1 -0
  98. package/dist/extensions/rich-text/rich-text-strikethrough.d.ts +5 -4
  99. package/dist/extensions/rich-text/rich-text-strikethrough.d.ts.map +1 -1
  100. package/dist/extensions/rich-text/rich-text-strikethrough.js +10 -10
  101. package/dist/extensions/rich-text/rich-text-strikethrough.js.map +1 -0
  102. package/dist/extensions/shared/copy-markdown-source.js +22 -31
  103. package/dist/extensions/shared/copy-markdown-source.js.map +1 -0
  104. package/dist/extensions/shared/paste-html-table-as-string.js +47 -60
  105. package/dist/extensions/shared/paste-html-table-as-string.js.map +1 -0
  106. package/dist/extensions/shared/paste-singleline-text.js +31 -39
  107. package/dist/extensions/shared/paste-singleline-text.js.map +1 -0
  108. package/dist/factories/create-suggestion-extension.d.ts +74 -74
  109. package/dist/factories/create-suggestion-extension.d.ts.map +1 -1
  110. package/dist/factories/create-suggestion-extension.js +139 -161
  111. package/dist/factories/create-suggestion-extension.js.map +1 -0
  112. package/dist/helpers/dom.js +9 -5
  113. package/dist/helpers/dom.js.map +1 -0
  114. package/dist/helpers/schema.d.ts +5 -3
  115. package/dist/helpers/schema.d.ts.map +1 -1
  116. package/dist/helpers/schema.js +25 -21
  117. package/dist/helpers/schema.js.map +1 -0
  118. package/dist/helpers/serializer.js +24 -28
  119. package/dist/helpers/serializer.js.map +1 -0
  120. package/dist/helpers/unified.js +24 -17
  121. package/dist/helpers/unified.js.map +1 -0
  122. package/dist/hooks/use-editor.js +50 -53
  123. package/dist/hooks/use-editor.js.map +1 -0
  124. package/dist/index.d.ts +25 -31
  125. package/dist/index.js +24 -24
  126. package/dist/serializers/html/html.d.ts +12 -10
  127. package/dist/serializers/html/html.d.ts.map +1 -1
  128. package/dist/serializers/html/html.js +67 -127
  129. package/dist/serializers/html/html.js.map +1 -0
  130. package/dist/serializers/html/plugins/rehype-code-block.js +17 -17
  131. package/dist/serializers/html/plugins/rehype-code-block.js.map +1 -0
  132. package/dist/serializers/html/plugins/rehype-image.js +20 -30
  133. package/dist/serializers/html/plugins/rehype-image.js.map +1 -0
  134. package/dist/serializers/html/plugins/rehype-suggestions.js +31 -32
  135. package/dist/serializers/html/plugins/rehype-suggestions.js.map +1 -0
  136. package/dist/serializers/html/plugins/rehype-task-list.js +31 -32
  137. package/dist/serializers/html/plugins/rehype-task-list.js.map +1 -0
  138. package/dist/serializers/html/plugins/remark-autolink-literal.d.ts +4 -1
  139. package/dist/serializers/html/plugins/remark-autolink-literal.d.ts.map +1 -1
  140. package/dist/serializers/html/plugins/remark-autolink-literal.js +25 -21
  141. package/dist/serializers/html/plugins/remark-autolink-literal.js.map +1 -0
  142. package/dist/serializers/html/plugins/remark-disable-constructs.js +21 -41
  143. package/dist/serializers/html/plugins/remark-disable-constructs.js.map +1 -0
  144. package/dist/serializers/html/plugins/remark-strikethrough.d.ts +5 -2
  145. package/dist/serializers/html/plugins/remark-strikethrough.d.ts.map +1 -1
  146. package/dist/serializers/html/plugins/remark-strikethrough.js +25 -21
  147. package/dist/serializers/html/plugins/remark-strikethrough.js.map +1 -0
  148. package/dist/serializers/markdown/markdown.d.ts +13 -12
  149. package/dist/serializers/markdown/markdown.d.ts.map +1 -1
  150. package/dist/serializers/markdown/markdown.js +78 -154
  151. package/dist/serializers/markdown/markdown.js.map +1 -0
  152. package/dist/serializers/markdown/plugins/image.js +27 -24
  153. package/dist/serializers/markdown/plugins/image.js.map +1 -0
  154. package/dist/serializers/markdown/plugins/list-item.js +32 -37
  155. package/dist/serializers/markdown/plugins/list-item.js.map +1 -0
  156. package/dist/serializers/markdown/plugins/paragraph.js +19 -19
  157. package/dist/serializers/markdown/plugins/paragraph.js.map +1 -0
  158. package/dist/serializers/markdown/plugins/strikethrough.js +23 -19
  159. package/dist/serializers/markdown/plugins/strikethrough.js.map +1 -0
  160. package/dist/serializers/markdown/plugins/suggestion.js +21 -19
  161. package/dist/serializers/markdown/plugins/suggestion.js.map +1 -0
  162. package/dist/serializers/markdown/plugins/task-item.js +31 -35
  163. package/dist/serializers/markdown/plugins/task-item.js.map +1 -0
  164. package/dist/utilities/can-insert-node-at.d.ts +12 -5
  165. package/dist/utilities/can-insert-node-at.d.ts.map +1 -1
  166. package/dist/utilities/can-insert-node-at.js +10 -8
  167. package/dist/utilities/can-insert-node-at.js.map +1 -0
  168. package/dist/utilities/can-insert-suggestion.d.ts +11 -5
  169. package/dist/utilities/can-insert-suggestion.d.ts.map +1 -1
  170. package/dist/utilities/can-insert-suggestion.js +15 -12
  171. package/dist/utilities/can-insert-suggestion.js.map +1 -0
  172. package/package.json +4 -3
  173. package/dist/constants/common.d.ts +0 -10
  174. package/dist/constants/common.d.ts.map +0 -1
  175. package/dist/constants/regular-expressions.d.ts +0 -18
  176. package/dist/constants/regular-expressions.d.ts.map +0 -1
  177. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.d.ts +0 -9
  178. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.d.ts.map +0 -1
  179. package/dist/extensions/plain-text/paste-multiline-text.d.ts +0 -10
  180. package/dist/extensions/plain-text/paste-multiline-text.d.ts.map +0 -1
  181. package/dist/extensions/plain-text/plain-text-paragraph.d.ts.map +0 -1
  182. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.d.ts +0 -9
  183. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.d.ts.map +0 -1
  184. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.d.ts +0 -9
  185. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.d.ts.map +0 -1
  186. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.d.ts +0 -9
  187. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.d.ts.map +0 -1
  188. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.d.ts +0 -8
  189. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.d.ts.map +0 -1
  190. package/dist/extensions/rich-text/bold-and-italics.d.ts +0 -8
  191. package/dist/extensions/rich-text/bold-and-italics.d.ts.map +0 -1
  192. package/dist/extensions/rich-text/curvenote-codemark.d.ts +0 -11
  193. package/dist/extensions/rich-text/curvenote-codemark.d.ts.map +0 -1
  194. package/dist/extensions/rich-text/paste-emojis.d.ts +0 -9
  195. package/dist/extensions/rich-text/paste-emojis.d.ts.map +0 -1
  196. package/dist/extensions/rich-text/paste-markdown.d.ts +0 -11
  197. package/dist/extensions/rich-text/paste-markdown.d.ts.map +0 -1
  198. package/dist/extensions/rich-text/rich-text-code.d.ts +0 -17
  199. package/dist/extensions/rich-text/rich-text-code.d.ts.map +0 -1
  200. package/dist/extensions/shared/copy-markdown-source.d.ts +0 -20
  201. package/dist/extensions/shared/copy-markdown-source.d.ts.map +0 -1
  202. package/dist/extensions/shared/paste-html-table-as-string.d.ts +0 -20
  203. package/dist/extensions/shared/paste-html-table-as-string.d.ts.map +0 -1
  204. package/dist/extensions/shared/paste-singleline-text.d.ts +0 -10
  205. package/dist/extensions/shared/paste-singleline-text.d.ts.map +0 -1
  206. package/dist/helpers/dom.d.ts +0 -8
  207. package/dist/helpers/dom.d.ts.map +0 -1
  208. package/dist/helpers/serializer.d.ts +0 -21
  209. package/dist/helpers/serializer.d.ts.map +0 -1
  210. package/dist/helpers/unified.d.ts +0 -21
  211. package/dist/helpers/unified.d.ts.map +0 -1
  212. package/dist/hooks/use-editor.d.ts +0 -19
  213. package/dist/hooks/use-editor.d.ts.map +0 -1
  214. package/dist/index.d.ts.map +0 -1
  215. package/dist/serializers/html/plugins/rehype-code-block.d.ts +0 -10
  216. package/dist/serializers/html/plugins/rehype-code-block.d.ts.map +0 -1
  217. package/dist/serializers/html/plugins/rehype-image.d.ts +0 -11
  218. package/dist/serializers/html/plugins/rehype-image.d.ts.map +0 -1
  219. package/dist/serializers/html/plugins/rehype-suggestions.d.ts +0 -10
  220. package/dist/serializers/html/plugins/rehype-suggestions.d.ts.map +0 -1
  221. package/dist/serializers/html/plugins/rehype-task-list.d.ts +0 -7
  222. package/dist/serializers/html/plugins/rehype-task-list.d.ts.map +0 -1
  223. package/dist/serializers/html/plugins/remark-disable-constructs.d.ts +0 -11
  224. package/dist/serializers/html/plugins/remark-disable-constructs.d.ts.map +0 -1
  225. package/dist/serializers/markdown/plugins/image.d.ts +0 -12
  226. package/dist/serializers/markdown/plugins/image.d.ts.map +0 -1
  227. package/dist/serializers/markdown/plugins/list-item.d.ts +0 -14
  228. package/dist/serializers/markdown/plugins/list-item.d.ts.map +0 -1
  229. package/dist/serializers/markdown/plugins/paragraph.d.ts +0 -13
  230. package/dist/serializers/markdown/plugins/paragraph.d.ts.map +0 -1
  231. package/dist/serializers/markdown/plugins/strikethrough.d.ts +0 -13
  232. package/dist/serializers/markdown/plugins/strikethrough.d.ts.map +0 -1
  233. package/dist/serializers/markdown/plugins/suggestion.d.ts +0 -11
  234. package/dist/serializers/markdown/plugins/suggestion.d.ts.map +0 -1
  235. package/dist/serializers/markdown/plugins/task-item.d.ts +0 -14
  236. package/dist/serializers/markdown/plugins/task-item.d.ts.map +0 -1
@@ -1,164 +1,142 @@
1
- import { mergeAttributes, Node } from '@tiptap/core';
2
- import { PluginKey } from '@tiptap/pm/state';
3
- import { Suggestion as TiptapSuggestion } from '@tiptap/suggestion';
4
- import { camelCase, kebabCase } from 'lodash-es';
5
- import { SUGGESTION_EXTENSION_PRIORITY } from '../constants/extension-priorities';
6
- import { canInsertNodeAt } from '../utilities/can-insert-node-at';
7
- import { canInsertSuggestion } from '../utilities/can-insert-suggestion';
1
+ import { SUGGESTION_EXTENSION_PRIORITY } from "../constants/extension-priorities.js";
2
+ import { canInsertNodeAt } from "../utilities/can-insert-node-at.js";
3
+ import { canInsertSuggestion } from "../utilities/can-insert-suggestion.js";
4
+ import { Node, mergeAttributes } from "@tiptap/core";
5
+ import { PluginKey } from "@tiptap/pm/state";
6
+ import { camelCase, kebabCase } from "lodash-es";
7
+ import { Suggestion } from "@tiptap/suggestion";
8
+ //#region src/factories/create-suggestion-extension.ts
8
9
  /**
9
- * A factory function responsible for creating different types of suggestion extensions with
10
- * flexibility and customizability in mind.
11
- *
12
- * Extensions created by this factory function render editor nodes with internal `data-id` and
13
- * `data-label` attributes (as a way to save and restore the editor nodes data) based on properties
14
- * of the same name (minus the `data-` prefix) from the source item type. However, in the event of
15
- * unmatched properties between the internal attributes and the source item type, you should
16
- * specify the source item type, and use the optional `attributesMapping` option to map the
17
- * source properties to the internal `data-id` and `data-label` attributes.
18
- *
19
- * This factory function also stores the suggestion items internally in the editor storage (as-is,
20
- * and indexed by an identifier), as a way to make sure that if a previously referenced suggestion
21
- * changes its label, the editor will always render the most up-to-date label for the suggestion by
22
- * reading it from the storage. An example use case for this is when a user mention is added to the
23
- * editor, and the user changed its name afterwards, the editor will always render the most
24
- * up-to-date user name for the mention.
25
- *
26
- * @param type A unique identifier for the suggestion extension type.
27
- * @param items An array of suggestion items to be stored in the editor storage.
28
- * @param attributesMapping An object to map the `data-id` and `data-label` attributes with the
29
- * source item type properties.
30
- *
31
- * @returns A new suggestion extension tailored to a specific use case.
32
- */
33
- function createSuggestionExtension(type, items = [],
34
- // This type makes sure that if a generic type variable is specified, the `attributesMapping`
35
- // is also defined (and vice versa) along with making sure that at least one attribute is
36
- // specified, and that all constraints are satisfied.
37
- ...attributesMapping) {
38
- // Normalize the node type and add the `Suggestion` suffix so that it can be easily identified
39
- // when parsing the editor schema programatically (useful for Markdown/HTML serialization)
40
- const nodeType = `${camelCase(type)}Suggestion`;
41
- // Normalize the node type to kebab-case to be used as a `data-*` HTML attribute
42
- const attributeType = kebabCase(type);
43
- // Get the specified attributes, if available, or use the defaults
44
- const idAttribute = String(attributesMapping[0]?.id ?? 'id');
45
- const labelAttribute = String(attributesMapping[0]?.label ?? 'label');
46
- // Create a personalized suggestion extension
47
- return Node.create({
48
- name: nodeType,
49
- priority: SUGGESTION_EXTENSION_PRIORITY,
50
- inline: true,
51
- group: 'inline',
52
- selectable: false,
53
- atom: true,
54
- addOptions() {
55
- return {
56
- triggerChar: '@',
57
- // Disable option by default until the following Tiptap issue is fixed:
58
- // https://github.com/ueberdosis/tiptap/issues/2159
59
- allowSpaces: false,
60
- allowedPrefixes: [' '],
61
- startOfLine: false,
62
- };
63
- },
64
- addStorage() {
65
- return {
66
- items,
67
- itemsById: items.reduce((acc, item) => ({ ...acc, [String(item[idAttribute])]: item }), {}),
68
- };
69
- },
70
- addAttributes() {
71
- return {
72
- id: {
73
- default: null,
74
- parseHTML: (element) => element.getAttribute('data-id'),
75
- renderHTML: (attributes) => ({
76
- 'data-id': String(attributes.id),
77
- }),
78
- },
79
- label: {
80
- default: null,
81
- parseHTML: (element) => {
82
- const id = String(element.getAttribute('data-id'));
83
- const item = this.storage.itemsById[id];
84
- // Attempt to read the item label from the storage first (as a way to make
85
- // sure that a previously referenced suggestion always renders the most
86
- // up-to-date label for the suggestion), and fallback to the `data-label`
87
- // attribute if the item is not found in the storage
88
- const labelValue = item?.[labelAttribute] ?? element.getAttribute('data-label');
89
- return typeof labelValue === 'string' ? labelValue : '';
90
- },
91
- renderHTML: (attributes) => ({
92
- 'data-label': String(attributes.label),
93
- }),
94
- },
95
- };
96
- },
97
- parseHTML() {
98
- return [{ tag: `span[data-${attributeType}]` }];
99
- },
100
- renderHTML({ node, HTMLAttributes }) {
101
- return [
102
- 'span',
103
- mergeAttributes({
104
- [`data-${attributeType}`]: '',
105
- 'aria-label': this.options.renderAriaLabel?.({
106
- id: String(node.attrs.id),
107
- label: String(node.attrs.label),
108
- }),
109
- }, HTMLAttributes),
110
- `${String(this.options.triggerChar)}${String(node.attrs.label)}`,
111
- ];
112
- },
113
- renderText({ node }) {
114
- return `${String(this.options.triggerChar)}${String(node.attrs.label)}`;
115
- },
116
- addProseMirrorPlugins() {
117
- const { options: { triggerChar, allowSpaces, allowedPrefixes, startOfLine, onSearchChange, onItemSelect, dropdownRenderFn, }, storage, } = this;
118
- return [
119
- TiptapSuggestion({
120
- pluginKey: new PluginKey(nodeType),
121
- editor: this.editor,
122
- char: triggerChar,
123
- allowedPrefixes,
124
- allowSpaces,
125
- startOfLine,
126
- items({ query, editor }) {
127
- return (onSearchChange?.(query, editor.storage[nodeType]) || []);
128
- },
129
- allow({ editor, range, state }) {
130
- return (canInsertNodeAt({ editor, nodeType, range }) &&
131
- canInsertSuggestion({ editor, state }));
132
- },
133
- command({ editor, range, props }) {
134
- const nodeAfter = editor.view.state.selection.$to.nodeAfter;
135
- const overrideSpace = nodeAfter?.text?.startsWith(' ');
136
- if (overrideSpace) {
137
- range.to += 1;
138
- }
139
- editor
140
- .chain()
141
- .focus()
142
- .insertContentAt(range, [
143
- {
144
- type: nodeType,
145
- attrs: props,
146
- },
147
- {
148
- type: 'text',
149
- text: ' ',
150
- },
151
- ])
152
- .run();
153
- const item = storage.itemsById[props.id];
154
- if (item) {
155
- onItemSelect?.(item);
156
- }
157
- },
158
- render: dropdownRenderFn,
159
- }),
160
- ];
161
- },
162
- });
10
+ * A factory function responsible for creating different types of suggestion extensions with
11
+ * flexibility and customizability in mind.
12
+ *
13
+ * Extensions created by this factory function render editor nodes with internal `data-id` and
14
+ * `data-label` attributes (as a way to save and restore the editor nodes data) based on properties
15
+ * of the same name (minus the `data-` prefix) from the source item type. However, in the event of
16
+ * unmatched properties between the internal attributes and the source item type, you should
17
+ * specify the source item type, and use the optional `attributesMapping` option to map the
18
+ * source properties to the internal `data-id` and `data-label` attributes.
19
+ *
20
+ * This factory function also stores the suggestion items internally in the editor storage (as-is,
21
+ * and indexed by an identifier), as a way to make sure that if a previously referenced suggestion
22
+ * changes its label, the editor will always render the most up-to-date label for the suggestion by
23
+ * reading it from the storage. An example use case for this is when a user mention is added to the
24
+ * editor, and the user changed its name afterwards, the editor will always render the most
25
+ * up-to-date user name for the mention.
26
+ *
27
+ * @param type A unique identifier for the suggestion extension type.
28
+ * @param items An array of suggestion items to be stored in the editor storage.
29
+ * @param attributesMapping An object to map the `data-id` and `data-label` attributes with the
30
+ * source item type properties.
31
+ *
32
+ * @returns A new suggestion extension tailored to a specific use case.
33
+ */
34
+ function createSuggestionExtension(type, items = [], ...attributesMapping) {
35
+ const nodeType = `${camelCase(type)}Suggestion`;
36
+ const attributeType = kebabCase(type);
37
+ const idAttribute = String(attributesMapping[0]?.id ?? "id");
38
+ const labelAttribute = String(attributesMapping[0]?.label ?? "label");
39
+ return Node.create({
40
+ name: nodeType,
41
+ priority: SUGGESTION_EXTENSION_PRIORITY,
42
+ inline: true,
43
+ group: "inline",
44
+ selectable: false,
45
+ atom: true,
46
+ addOptions() {
47
+ return {
48
+ triggerChar: "@",
49
+ allowSpaces: false,
50
+ allowedPrefixes: [" "],
51
+ startOfLine: false
52
+ };
53
+ },
54
+ addStorage() {
55
+ return {
56
+ items,
57
+ itemsById: items.reduce((acc, item) => ({
58
+ ...acc,
59
+ [String(item[idAttribute])]: item
60
+ }), {})
61
+ };
62
+ },
63
+ addAttributes() {
64
+ return {
65
+ id: {
66
+ default: null,
67
+ parseHTML: (element) => element.getAttribute("data-id"),
68
+ renderHTML: (attributes) => ({ "data-id": String(attributes.id) })
69
+ },
70
+ label: {
71
+ default: null,
72
+ parseHTML: (element) => {
73
+ const id = String(element.getAttribute("data-id"));
74
+ const labelValue = this.storage.itemsById[id]?.[labelAttribute] ?? element.getAttribute("data-label");
75
+ return typeof labelValue === "string" ? labelValue : "";
76
+ },
77
+ renderHTML: (attributes) => ({ "data-label": String(attributes.label) })
78
+ }
79
+ };
80
+ },
81
+ parseHTML() {
82
+ return [{ tag: `span[data-${attributeType}]` }];
83
+ },
84
+ renderHTML({ node, HTMLAttributes }) {
85
+ return [
86
+ "span",
87
+ mergeAttributes({
88
+ [`data-${attributeType}`]: "",
89
+ "aria-label": this.options.renderAriaLabel?.({
90
+ id: String(node.attrs.id),
91
+ label: String(node.attrs.label)
92
+ })
93
+ }, HTMLAttributes),
94
+ `${String(this.options.triggerChar)}${String(node.attrs.label)}`
95
+ ];
96
+ },
97
+ renderText({ node }) {
98
+ return `${String(this.options.triggerChar)}${String(node.attrs.label)}`;
99
+ },
100
+ addProseMirrorPlugins() {
101
+ const { options: { triggerChar, allowSpaces, allowedPrefixes, startOfLine, onSearchChange, onItemSelect, dropdownRenderFn }, storage } = this;
102
+ return [Suggestion({
103
+ pluginKey: new PluginKey(nodeType),
104
+ editor: this.editor,
105
+ char: triggerChar,
106
+ allowedPrefixes,
107
+ allowSpaces,
108
+ startOfLine,
109
+ items({ query, editor }) {
110
+ return onSearchChange?.(query, editor.storage[nodeType]) || [];
111
+ },
112
+ allow({ editor, range, state }) {
113
+ return canInsertNodeAt({
114
+ editor,
115
+ nodeType,
116
+ range
117
+ }) && canInsertSuggestion({
118
+ editor,
119
+ state
120
+ });
121
+ },
122
+ command({ editor, range, props }) {
123
+ if (editor.view.state.selection.$to.nodeAfter?.text?.startsWith(" ")) range.to += 1;
124
+ editor.chain().focus().insertContentAt(range, [{
125
+ type: nodeType,
126
+ attrs: props
127
+ }, {
128
+ type: "text",
129
+ text: " "
130
+ }]).run();
131
+ const item = storage.itemsById[props.id];
132
+ if (item) onItemSelect?.(item);
133
+ },
134
+ render: dropdownRenderFn
135
+ })];
136
+ }
137
+ });
163
138
  }
139
+ //#endregion
164
140
  export { createSuggestionExtension };
141
+
142
+ //# sourceMappingURL=create-suggestion-extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-suggestion-extension.js","names":["TiptapSuggestion"],"sources":["../../src/factories/create-suggestion-extension.ts"],"sourcesContent":["import { mergeAttributes, Node } from '@tiptap/core'\nimport { PluginKey } from '@tiptap/pm/state'\nimport { Suggestion as TiptapSuggestion } from '@tiptap/suggestion'\nimport { camelCase, kebabCase } from 'lodash-es'\n\nimport { SUGGESTION_EXTENSION_PRIORITY } from '../constants/extension-priorities'\nimport { canInsertNodeAt } from '../utilities/can-insert-node-at'\nimport { canInsertSuggestion } from '../utilities/can-insert-suggestion'\n\nimport type {\n SuggestionKeyDownProps as CoreSuggestionKeyDownProps,\n SuggestionOptions as CoreSuggestionOptions,\n SuggestionProps as CoreSuggestionProps,\n} from '@tiptap/suggestion'\nimport type { ConditionalKeys, RequireAtLeastOne } from 'type-fest'\n\n/**\n * A type that describes the suggestion node attributes.\n */\ntype SuggestionNodeAttributes = {\n /**\n * The suggestion node unique identifier to be rendered by the editor as a `data-id` attribute.\n */\n id: number | string\n\n /**\n * The suggestion node label to be rendered by the editor as a `data-label` attribute and the\n * display text itself.\n */\n label: string\n}\n\n/**\n * A type that describes the minimal props that an autocomplete dropdown must receive.\n */\ntype SuggestionRendererProps<TSuggestionItem> = {\n /**\n * The list of suggestion items to be rendered by the autocomplete dropdown.\n */\n items: CoreSuggestionProps<TSuggestionItem>['items']\n\n /**\n * The function that must be invoked when a suggestion item is selected.\n */\n command: CoreSuggestionProps<TSuggestionItem, SuggestionNodeAttributes>['command']\n}\n\n/**\n * A type that describes the forwarded ref that an autocomplete dropdown must implement with\n * `useImperativeHandle` to handle `keydown` events in the dropdown render function.\n */\ntype SuggestionRendererRef = {\n onKeyDown: (props: CoreSuggestionKeyDownProps) => boolean\n}\n\n/**\n * The options available to customize the extension created by the factory function.\n */\ntype SuggestionOptions<TSuggestionItem> = {\n /**\n * The character that triggers the autocomplete dropdown.\n */\n triggerChar: string\n\n /**\n * Allows or disallows spaces in suggested items.\n */\n allowSpaces: CoreSuggestionOptions['allowSpaces']\n\n /**\n * The prefix characters that are allowed to trigger a suggestion.\n */\n allowedPrefixes: CoreSuggestionOptions['allowedPrefixes']\n\n /**\n * Trigger the autocomplete dropdown at the start of a line only.\n */\n startOfLine: CoreSuggestionOptions['startOfLine']\n\n /**\n * Define how the suggestion item `aria-label` attribute should be rendered.\n */\n renderAriaLabel?: (attrs: SuggestionNodeAttributes) => string\n\n /**\n * A render function for the autocomplete dropdown.\n */\n dropdownRenderFn?: CoreSuggestionOptions<TSuggestionItem>['render']\n\n /**\n * The event handler that is fired when the search string has changed.\n */\n onSearchChange?: (\n query: string,\n storage: SuggestionStorage<TSuggestionItem>,\n ) => TSuggestionItem[] | Promise<TSuggestionItem[]>\n\n /**\n * The event handler that is fired when a suggestion item is selected.\n */\n onItemSelect?: (item: TSuggestionItem) => void\n}\n\n/**\n * The storage holding the suggestion items original array, and a collection indexed by the item id.\n */\ntype SuggestionStorage<TSuggestionItem> = Readonly<{\n /**\n * The original array of suggestion items.\n */\n items: TSuggestionItem[]\n\n /**\n * A collection of suggestion items indexed by the item id.\n */\n itemsById: { readonly [id: SuggestionNodeAttributes['id']]: TSuggestionItem | undefined }\n}>\n\n/**\n * The return type for a suggestion extension created by the factory function.\n */\ntype SuggestionExtensionResult<TSuggestionItem> = Node<SuggestionOptions<TSuggestionItem>>\n\n/**\n * A factory function responsible for creating different types of suggestion extensions with\n * flexibility and customizability in mind.\n *\n * Extensions created by this factory function render editor nodes with internal `data-id` and\n * `data-label` attributes (as a way to save and restore the editor nodes data) based on properties\n * of the same name (minus the `data-` prefix) from the source item type. However, in the event of\n * unmatched properties between the internal attributes and the source item type, you should\n * specify the source item type, and use the optional `attributesMapping` option to map the\n * source properties to the internal `data-id` and `data-label` attributes.\n *\n * This factory function also stores the suggestion items internally in the editor storage (as-is,\n * and indexed by an identifier), as a way to make sure that if a previously referenced suggestion\n * changes its label, the editor will always render the most up-to-date label for the suggestion by\n * reading it from the storage. An example use case for this is when a user mention is added to the\n * editor, and the user changed its name afterwards, the editor will always render the most\n * up-to-date user name for the mention.\n *\n * @param type A unique identifier for the suggestion extension type.\n * @param items An array of suggestion items to be stored in the editor storage.\n * @param attributesMapping An object to map the `data-id` and `data-label` attributes with the\n * source item type properties.\n *\n * @returns A new suggestion extension tailored to a specific use case.\n */\nfunction createSuggestionExtension<\n TSuggestionItem extends {\n [id: SuggestionNodeAttributes['id']]: unknown\n } = SuggestionNodeAttributes,\n>(\n type: string,\n items: TSuggestionItem[] = [],\n\n // This type makes sure that if a generic type variable is specified, the `attributesMapping`\n // is also defined (and vice versa) along with making sure that at least one attribute is\n // specified, and that all constraints are satisfied.\n ...attributesMapping: TSuggestionItem extends SuggestionNodeAttributes\n ? []\n : [\n RequireAtLeastOne<{\n id: ConditionalKeys<TSuggestionItem, SuggestionNodeAttributes['id']>\n label: ConditionalKeys<TSuggestionItem, SuggestionNodeAttributes['label']>\n }>,\n ]\n): SuggestionExtensionResult<TSuggestionItem> {\n // Normalize the node type and add the `Suggestion` suffix so that it can be easily identified\n // when parsing the editor schema programatically (useful for Markdown/HTML serialization)\n const nodeType = `${camelCase(type)}Suggestion`\n\n // Normalize the node type to kebab-case to be used as a `data-*` HTML attribute\n const attributeType = kebabCase(type)\n\n // Get the specified attributes, if available, or use the defaults\n const idAttribute = String(attributesMapping[0]?.id ?? 'id')\n const labelAttribute = String(attributesMapping[0]?.label ?? 'label')\n\n // Create a personalized suggestion extension\n return Node.create<SuggestionOptions<TSuggestionItem>, SuggestionStorage<TSuggestionItem>>({\n name: nodeType,\n priority: SUGGESTION_EXTENSION_PRIORITY,\n inline: true,\n group: 'inline',\n selectable: false,\n atom: true,\n addOptions() {\n return {\n triggerChar: '@',\n // Disable option by default until the following Tiptap issue is fixed:\n // https://github.com/ueberdosis/tiptap/issues/2159\n allowSpaces: false,\n allowedPrefixes: [' '],\n startOfLine: false,\n }\n },\n addStorage() {\n return {\n items,\n itemsById: items.reduce(\n (acc, item) => ({ ...acc, [String(item[idAttribute])]: item }),\n {},\n ),\n }\n },\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: (element) => element.getAttribute('data-id'),\n renderHTML: (attributes) => ({\n 'data-id': String(attributes.id),\n }),\n },\n label: {\n default: null,\n parseHTML: (element: Element) => {\n const id = String(element.getAttribute('data-id'))\n const item = this.storage.itemsById[id]\n\n // Attempt to read the item label from the storage first (as a way to make\n // sure that a previously referenced suggestion always renders the most\n // up-to-date label for the suggestion), and fallback to the `data-label`\n // attribute if the item is not found in the storage\n const labelValue =\n item?.[labelAttribute] ?? element.getAttribute('data-label')\n return typeof labelValue === 'string' ? labelValue : ''\n },\n renderHTML: (attributes) => ({\n 'data-label': String(attributes.label),\n }),\n },\n }\n },\n parseHTML() {\n return [{ tag: `span[data-${attributeType}]` }]\n },\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'span',\n mergeAttributes(\n {\n [`data-${attributeType}`]: '',\n 'aria-label': this.options.renderAriaLabel?.({\n id: String(node.attrs.id),\n label: String(node.attrs.label),\n }),\n },\n HTMLAttributes,\n ),\n `${String(this.options.triggerChar)}${String(node.attrs.label)}`,\n ]\n },\n renderText({ node }) {\n return `${String(this.options.triggerChar)}${String(node.attrs.label)}`\n },\n addProseMirrorPlugins() {\n const {\n options: {\n triggerChar,\n allowSpaces,\n allowedPrefixes,\n startOfLine,\n onSearchChange,\n onItemSelect,\n dropdownRenderFn,\n },\n storage,\n } = this\n\n return [\n TiptapSuggestion<TSuggestionItem, SuggestionNodeAttributes>({\n pluginKey: new PluginKey(nodeType),\n editor: this.editor,\n char: triggerChar,\n allowedPrefixes,\n allowSpaces,\n startOfLine,\n items({ query, editor }) {\n return (\n onSearchChange?.(\n query,\n editor.storage[nodeType] as SuggestionStorage<TSuggestionItem>,\n ) || []\n )\n },\n allow({ editor, range, state }) {\n return (\n canInsertNodeAt({ editor, nodeType, range }) &&\n canInsertSuggestion({ editor, state })\n )\n },\n command({ editor, range, props }) {\n const nodeAfter = editor.view.state.selection.$to.nodeAfter\n const overrideSpace = nodeAfter?.text?.startsWith(' ')\n\n if (overrideSpace) {\n range.to += 1\n }\n\n editor\n .chain()\n .focus()\n .insertContentAt(range, [\n {\n type: nodeType,\n attrs: props,\n },\n {\n type: 'text',\n text: ' ',\n },\n ])\n .run()\n\n const item = storage.itemsById[props.id]\n\n if (item) {\n onItemSelect?.(item)\n }\n },\n render: dropdownRenderFn,\n }),\n ]\n },\n })\n}\n\nexport { createSuggestionExtension }\n\nexport type {\n SuggestionExtensionResult,\n SuggestionOptions,\n SuggestionRendererProps,\n SuggestionRendererRef,\n SuggestionStorage,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoJA,SAAS,0BAKL,MACA,QAA2B,EAAE,EAK7B,GAAG,mBAQuC;CAG1C,MAAM,WAAW,GAAG,UAAU,KAAK,CAAC;CAGpC,MAAM,gBAAgB,UAAU,KAAK;CAGrC,MAAM,cAAc,OAAO,kBAAkB,IAAI,MAAM,KAAK;CAC5D,MAAM,iBAAiB,OAAO,kBAAkB,IAAI,SAAS,QAAQ;AAGrE,QAAO,KAAK,OAA+E;EACvF,MAAM;EACN,UAAU;EACV,QAAQ;EACR,OAAO;EACP,YAAY;EACZ,MAAM;EACN,aAAa;AACT,UAAO;IACH,aAAa;IAGb,aAAa;IACb,iBAAiB,CAAC,IAAI;IACtB,aAAa;IAChB;;EAEL,aAAa;AACT,UAAO;IACH;IACA,WAAW,MAAM,QACZ,KAAK,UAAU;KAAE,GAAG;MAAM,OAAO,KAAK,aAAa,GAAG;KAAM,GAC7D,EAAE,CACL;IACJ;;EAEL,gBAAgB;AACZ,UAAO;IACH,IAAI;KACA,SAAS;KACT,YAAY,YAAY,QAAQ,aAAa,UAAU;KACvD,aAAa,gBAAgB,EACzB,WAAW,OAAO,WAAW,GAAG,EACnC;KACJ;IACD,OAAO;KACH,SAAS;KACT,YAAY,YAAqB;MAC7B,MAAM,KAAK,OAAO,QAAQ,aAAa,UAAU,CAAC;MAOlD,MAAM,aANO,KAAK,QAAQ,UAAU,MAOzB,mBAAmB,QAAQ,aAAa,aAAa;AAChE,aAAO,OAAO,eAAe,WAAW,aAAa;;KAEzD,aAAa,gBAAgB,EACzB,cAAc,OAAO,WAAW,MAAM,EACzC;KACJ;IACJ;;EAEL,YAAY;AACR,UAAO,CAAC,EAAE,KAAK,aAAa,cAAc,IAAI,CAAC;;EAEnD,WAAW,EAAE,MAAM,kBAAkB;AACjC,UAAO;IACH;IACA,gBACI;MACK,QAAQ,kBAAkB;KAC3B,cAAc,KAAK,QAAQ,kBAAkB;MACzC,IAAI,OAAO,KAAK,MAAM,GAAG;MACzB,OAAO,OAAO,KAAK,MAAM,MAAM;MAClC,CAAC;KACL,EACD,eACH;IACD,GAAG,OAAO,KAAK,QAAQ,YAAY,GAAG,OAAO,KAAK,MAAM,MAAM;IACjE;;EAEL,WAAW,EAAE,QAAQ;AACjB,UAAO,GAAG,OAAO,KAAK,QAAQ,YAAY,GAAG,OAAO,KAAK,MAAM,MAAM;;EAEzE,wBAAwB;GACpB,MAAM,EACF,SAAS,EACL,aACA,aACA,iBACA,aACA,gBACA,cACA,oBAEJ,YACA;AAEJ,UAAO,CACHA,WAA4D;IACxD,WAAW,IAAI,UAAU,SAAS;IAClC,QAAQ,KAAK;IACb,MAAM;IACN;IACA;IACA;IACA,MAAM,EAAE,OAAO,UAAU;AACrB,YACI,iBACI,OACA,OAAO,QAAQ,UAClB,IAAI,EAAE;;IAGf,MAAM,EAAE,QAAQ,OAAO,SAAS;AAC5B,YACI,gBAAgB;MAAE;MAAQ;MAAU;MAAO,CAAC,IAC5C,oBAAoB;MAAE;MAAQ;MAAO,CAAC;;IAG9C,QAAQ,EAAE,QAAQ,OAAO,SAAS;AAI9B,SAHkB,OAAO,KAAK,MAAM,UAAU,IAAI,WACjB,MAAM,WAAW,IAAI,CAGlD,OAAM,MAAM;AAGhB,YACK,OAAO,CACP,OAAO,CACP,gBAAgB,OAAO,CACpB;MACI,MAAM;MACN,OAAO;MACV,EACD;MACI,MAAM;MACN,MAAM;MACT,CACJ,CAAC,CACD,KAAK;KAEV,MAAM,OAAO,QAAQ,UAAU,MAAM;AAErC,SAAI,KACA,gBAAe,KAAK;;IAG5B,QAAQ;IACX,CAAC,CACL;;EAER,CAAC"}
@@ -1,9 +1,13 @@
1
+ //#region src/helpers/dom.ts
1
2
  /**
2
- * Parse a given HTML string and returns the `HTMLElement` for the document body.
3
- *
4
- * @param html The HTML string to parse.
5
- */
3
+ * Parse a given HTML string and returns the `HTMLElement` for the document body.
4
+ *
5
+ * @param html The HTML string to parse.
6
+ */
6
7
  function parseHtmlToElement(html) {
7
- return new DOMParser().parseFromString(html, 'text/html').body;
8
+ return new DOMParser().parseFromString(html, "text/html").body;
8
9
  }
10
+ //#endregion
9
11
  export { parseHtmlToElement };
12
+
13
+ //# sourceMappingURL=dom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.js","names":[],"sources":["../../src/helpers/dom.ts"],"sourcesContent":["/**\n * Parse a given HTML string and returns the `HTMLElement` for the document body.\n *\n * @param html The HTML string to parse.\n */\nfunction parseHtmlToElement(html: string) {\n return new DOMParser().parseFromString(html, 'text/html').body\n}\n\nexport { parseHtmlToElement }\n"],"mappings":";;;;;;AAKA,SAAS,mBAAmB,MAAc;AACtC,QAAO,IAAI,WAAW,CAAC,gBAAgB,MAAM,YAAY,CAAC"}
@@ -1,4 +1,6 @@
1
- import type { Schema } from '@tiptap/pm/model';
1
+ import { Schema } from "@tiptap/pm/model";
2
+
3
+ //#region src/helpers/schema.d.ts
2
4
  /**
3
5
  * Check if the document schema accepts multiple lines of input.
4
6
  *
@@ -22,6 +24,6 @@ declare function isPlainTextDocument(schema: Schema): boolean;
22
24
  *
23
25
  * @returns A string ID matching the editor schema.
24
26
  */
25
- declare function computeSchemaId(schema: Schema): string;
26
- export { computeSchemaId, isMultilineDocument, isPlainTextDocument };
27
+ //#endregion
28
+ export { isMultilineDocument, isPlainTextDocument };
27
29
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/helpers/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAE9C;;;;;;GAMG;AACH,iBAAS,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,iBAAS,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,iBAAS,eAAe,CAAC,MAAM,EAAE,MAAM,UAEtC;AAED,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,CAAA"}
1
+ {"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/helpers/schema.ts"],"mappings":";;;;;AAA8C;;;;;iBASrC,mBAAA,CAAoB,MAAA,EAAQ,MAAA;;;;;;;;iBAW5B,mBAAA,CAAoB,MAAA,EAAQ,MAAA"}
@@ -1,31 +1,35 @@
1
+ //#region src/helpers/schema.ts
1
2
  /**
2
- * Check if the document schema accepts multiple lines of input.
3
- *
4
- * @param schema The current editor document schema.
5
- *
6
- * @returns True if the schema accepts multiple lines of input, false otherwise.
7
- */
3
+ * Check if the document schema accepts multiple lines of input.
4
+ *
5
+ * @param schema The current editor document schema.
6
+ *
7
+ * @returns True if the schema accepts multiple lines of input, false otherwise.
8
+ */
8
9
  function isMultilineDocument(schema) {
9
- return /(?:\+|\*)$/.test(schema.topNodeType.spec.content || '');
10
+ return /(?:\+|\*)$/.test(schema.topNodeType.spec.content || "");
10
11
  }
11
12
  /**
12
- * Check if a document schema contains a plain-text document top node.
13
- *
14
- * @param schema The current editor document schema.
15
- *
16
- * @returns True if the schema contains a plain-text document, false otherwise.
17
- */
13
+ * Check if a document schema contains a plain-text document top node.
14
+ *
15
+ * @param schema The current editor document schema.
16
+ *
17
+ * @returns True if the schema contains a plain-text document, false otherwise.
18
+ */
18
19
  function isPlainTextDocument(schema) {
19
- return Boolean(schema.topNodeType.spec.content?.startsWith('paragraph'));
20
+ return Boolean(schema.topNodeType.spec.content?.startsWith("paragraph"));
20
21
  }
21
22
  /**
22
- * Computes a string ID that identifies a given editor schema which can be used for object mapping.
23
- *
24
- * @param schema The current editor document schema.
25
- *
26
- * @returns A string ID matching the editor schema.
27
- */
23
+ * Computes a string ID that identifies a given editor schema which can be used for object mapping.
24
+ *
25
+ * @param schema The current editor document schema.
26
+ *
27
+ * @returns A string ID matching the editor schema.
28
+ */
28
29
  function computeSchemaId(schema) {
29
- return [...Object.keys(schema.marks), ...Object.keys(schema.nodes)].join();
30
+ return [...Object.keys(schema.marks), ...Object.keys(schema.nodes)].join();
30
31
  }
32
+ //#endregion
31
33
  export { computeSchemaId, isMultilineDocument, isPlainTextDocument };
34
+
35
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../../src/helpers/schema.ts"],"sourcesContent":["import type { Schema } from '@tiptap/pm/model'\n\n/**\n * Check if the document schema accepts multiple lines of input.\n *\n * @param schema The current editor document schema.\n *\n * @returns True if the schema accepts multiple lines of input, false otherwise.\n */\nfunction isMultilineDocument(schema: Schema): boolean {\n return /(?:\\+|\\*)$/.test(schema.topNodeType.spec.content || '')\n}\n\n/**\n * Check if a document schema contains a plain-text document top node.\n *\n * @param schema The current editor document schema.\n *\n * @returns True if the schema contains a plain-text document, false otherwise.\n */\nfunction isPlainTextDocument(schema: Schema): boolean {\n return Boolean(schema.topNodeType.spec.content?.startsWith('paragraph'))\n}\n\n/**\n * Computes a string ID that identifies a given editor schema which can be used for object mapping.\n *\n * @param schema The current editor document schema.\n *\n * @returns A string ID matching the editor schema.\n */\nfunction computeSchemaId(schema: Schema) {\n return [...Object.keys(schema.marks), ...Object.keys(schema.nodes)].join()\n}\n\nexport { computeSchemaId, isMultilineDocument, isPlainTextDocument }\n"],"mappings":";;;;;;;;AASA,SAAS,oBAAoB,QAAyB;AAClD,QAAO,aAAa,KAAK,OAAO,YAAY,KAAK,WAAW,GAAG;;;;;;;;;AAUnE,SAAS,oBAAoB,QAAyB;AAClD,QAAO,QAAQ,OAAO,YAAY,KAAK,SAAS,WAAW,YAAY,CAAC;;;;;;;;;AAU5E,SAAS,gBAAgB,QAAgB;AACrC,QAAO,CAAC,GAAG,OAAO,KAAK,OAAO,MAAM,EAAE,GAAG,OAAO,KAAK,OAAO,MAAM,CAAC,CAAC,MAAM"}
@@ -1,35 +1,31 @@
1
- import { kebabCase } from 'lodash-es';
1
+ import { kebabCase } from "lodash-es";
2
+ //#region src/helpers/serializer.ts
2
3
  /**
3
- * Builds a partial regular expression that includes valid URL schemas used by all the available
4
- * suggestion nodes from the given editor schema.
5
- *
6
- * @param schema The editor schema to be used for suggestion nodes detection.
7
- *
8
- * @returns A partial regular expression with valid URL schemas for the available suggestion nodes,
9
- * `null` if there are no suggestion nodes in the editor schema.
10
- */
4
+ * Builds a partial regular expression that includes valid URL schemas used by all the available
5
+ * suggestion nodes from the given editor schema.
6
+ *
7
+ * @param schema The editor schema to be used for suggestion nodes detection.
8
+ *
9
+ * @returns A partial regular expression with valid URL schemas for the available suggestion nodes,
10
+ * `null` if there are no suggestion nodes in the editor schema.
11
+ */
11
12
  function buildSuggestionSchemaPartialRegex(schema) {
12
- const suggestionNodes = Object.values(schema.nodes).filter((node) => node.name.endsWith('Suggestion'));
13
- if (suggestionNodes.length === 0) {
14
- return null;
15
- }
16
- return `(?:${suggestionNodes
17
- .map((suggestionNode) => kebabCase(suggestionNode.name.replace(/Suggestion$/, '')))
18
- .join('|')})://`;
13
+ const suggestionNodes = Object.values(schema.nodes).filter((node) => node.name.endsWith("Suggestion"));
14
+ if (suggestionNodes.length === 0) return null;
15
+ return `(?:${suggestionNodes.map((suggestionNode) => kebabCase(suggestionNode.name.replace(/Suggestion$/, ""))).join("|")})://`;
19
16
  }
20
17
  /**
21
- * Extract all tags from the given parse rules argument, and returns an array of said tags.
22
- *
23
- * @param parseRules The parse rules for a DOM node or inline style.
24
- *
25
- * @returns An array of tags extracted from the parse rules.
26
- */
18
+ * Extract all tags from the given parse rules argument, and returns an array of said tags.
19
+ *
20
+ * @param parseRules The parse rules for a DOM node or inline style.
21
+ *
22
+ * @returns An array of tags extracted from the parse rules.
23
+ */
27
24
  function extractTagsFromParseRules(parseRules) {
28
- if (!parseRules || parseRules.length === 0) {
29
- return [];
30
- }
31
- return parseRules
32
- .filter((rule) => rule.tag)
33
- .map((rule) => rule.tag);
25
+ if (!parseRules || parseRules.length === 0) return [];
26
+ return parseRules.filter((rule) => rule.tag).map((rule) => rule.tag);
34
27
  }
28
+ //#endregion
35
29
  export { buildSuggestionSchemaPartialRegex, extractTagsFromParseRules };
30
+
31
+ //# sourceMappingURL=serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializer.js","names":[],"sources":["../../src/helpers/serializer.ts"],"sourcesContent":["import { kebabCase } from 'lodash-es'\n\nimport type { ParseRule, Schema } from '@tiptap/pm/model'\n\n/**\n * Builds a partial regular expression that includes valid URL schemas used by all the available\n * suggestion nodes from the given editor schema.\n *\n * @param schema The editor schema to be used for suggestion nodes detection.\n *\n * @returns A partial regular expression with valid URL schemas for the available suggestion nodes,\n * `null` if there are no suggestion nodes in the editor schema.\n */\nfunction buildSuggestionSchemaPartialRegex(schema: Schema) {\n const suggestionNodes = Object.values(schema.nodes).filter((node) =>\n node.name.endsWith('Suggestion'),\n )\n\n if (suggestionNodes.length === 0) {\n return null\n }\n\n return `(?:${suggestionNodes\n .map((suggestionNode) => kebabCase(suggestionNode.name.replace(/Suggestion$/, '')))\n .join('|')})://`\n}\n\n/**\n * Extract all tags from the given parse rules argument, and returns an array of said tags.\n *\n * @param parseRules The parse rules for a DOM node or inline style.\n *\n * @returns An array of tags extracted from the parse rules.\n */\nfunction extractTagsFromParseRules(\n parseRules?: readonly ParseRule[],\n): (keyof HTMLElementTagNameMap)[] {\n if (!parseRules || parseRules.length === 0) {\n return []\n }\n\n return parseRules\n .filter((rule) => rule.tag)\n .map((rule) => rule.tag as keyof HTMLElementTagNameMap)\n}\n\nexport { buildSuggestionSchemaPartialRegex, extractTagsFromParseRules }\n"],"mappings":";;;;;;;;;;;AAaA,SAAS,kCAAkC,QAAgB;CACvD,MAAM,kBAAkB,OAAO,OAAO,OAAO,MAAM,CAAC,QAAQ,SACxD,KAAK,KAAK,SAAS,aAAa,CACnC;AAED,KAAI,gBAAgB,WAAW,EAC3B,QAAO;AAGX,QAAO,MAAM,gBACR,KAAK,mBAAmB,UAAU,eAAe,KAAK,QAAQ,eAAe,GAAG,CAAC,CAAC,CAClF,KAAK,IAAI,CAAC;;;;;;;;;AAUnB,SAAS,0BACL,YAC+B;AAC/B,KAAI,CAAC,cAAc,WAAW,WAAW,EACrC,QAAO,EAAE;AAGb,QAAO,WACF,QAAQ,SAAS,KAAK,IAAI,CAC1B,KAAK,SAAS,KAAK,IAAmC"}
@@ -1,24 +1,31 @@
1
- import { is } from 'unist-util-is';
1
+ import { is } from "unist-util-is";
2
+ //#region src/helpers/unified.ts
2
3
  /**
3
- * Determines whether a given hast node is an element node with a specific tag name.
4
- *
5
- * @param node The hast node to check.
6
- * @param tagName The tag name to check for.
7
- *
8
- * @returns `true` if the hast node is an element node with the specified tag name, `false`
9
- * otherwise.
10
- */
4
+ * Determines whether a given hast node is an element node with a specific tag name.
5
+ *
6
+ * @param node The hast node to check.
7
+ * @param tagName The tag name to check for.
8
+ *
9
+ * @returns `true` if the hast node is an element node with the specified tag name, `false`
10
+ * otherwise.
11
+ */
11
12
  function isHastElementNode(node, tagName) {
12
- return is(node, { type: 'element', tagName });
13
+ return is(node, {
14
+ type: "element",
15
+ tagName
16
+ });
13
17
  }
14
18
  /**
15
- * Determines whether a given hast node is a text node.
16
- *
17
- * @param node The hast node to check.
18
- *
19
- * @returns `true` if the hast node is a text node, `false` otherwise.
20
- */
19
+ * Determines whether a given hast node is a text node.
20
+ *
21
+ * @param node The hast node to check.
22
+ *
23
+ * @returns `true` if the hast node is a text node, `false` otherwise.
24
+ */
21
25
  function isHastTextNode(node) {
22
- return is(node, { type: 'text' });
26
+ return is(node, { type: "text" });
23
27
  }
28
+ //#endregion
24
29
  export { isHastElementNode, isHastTextNode };
30
+
31
+ //# sourceMappingURL=unified.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unified.js","names":[],"sources":["../../src/helpers/unified.ts"],"sourcesContent":["import { is } from 'unist-util-is'\n\nimport type { Element, Node as HastNode, Text } from 'hast'\n\n/**\n * Determines whether a given hast node is an element node with a specific tag name.\n *\n * @param node The hast node to check.\n * @param tagName The tag name to check for.\n *\n * @returns `true` if the hast node is an element node with the specified tag name, `false`\n * otherwise.\n */\nfunction isHastElementNode(node: HastNode, tagName: Element['tagName']): node is Element {\n return is(node, { type: 'element', tagName })\n}\n\n/**\n * Determines whether a given hast node is a text node.\n *\n * @param node The hast node to check.\n *\n * @returns `true` if the hast node is a text node, `false` otherwise.\n */\nfunction isHastTextNode(node: HastNode): node is Text {\n return is(node, { type: 'text' })\n}\n\nexport { isHastElementNode, isHastTextNode }\n"],"mappings":";;;;;;;;;;;AAaA,SAAS,kBAAkB,MAAgB,SAA8C;AACrF,QAAO,GAAG,MAAM;EAAE,MAAM;EAAW;EAAS,CAAC;;;;;;;;;AAUjD,SAAS,eAAe,MAA8B;AAClD,QAAO,GAAG,MAAM,EAAE,MAAM,QAAQ,CAAC"}