@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,62 +1,59 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import { Editor } from '@tiptap/react';
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { Editor } from "@tiptap/react";
3
+ //#region src/hooks/use-editor.ts
3
4
  function stateChanger(state) {
4
- return (state + 1) % Number.MAX_SAFE_INTEGER;
5
+ return (state + 1) % Number.MAX_SAFE_INTEGER;
5
6
  }
6
7
  /**
7
- * This is a copy of the `useRerender` hook from `@react-hookz/web`, which is a utility hook that
8
- * returns a function that can be called to force a re-render of the component.
9
- *
10
- * Turns out we don't have the need to use any of the other hooks from `@react-hookz/web`, which is
11
- * a peer dependency that often introduces breaking changes, causing upgrade issues across our
12
- * projects.
13
- */
8
+ * This is a copy of the `useRerender` hook from `@react-hookz/web`, which is a utility hook that
9
+ * returns a function that can be called to force a re-render of the component.
10
+ *
11
+ * Turns out we don't have the need to use any of the other hooks from `@react-hookz/web`, which is
12
+ * a peer dependency that often introduces breaking changes, causing upgrade issues across our
13
+ * projects.
14
+ */
14
15
  function useRerender() {
15
- const [, setState] = useState(0);
16
- return useCallback(() => {
17
- setState(stateChanger);
18
- }, []);
16
+ const [, setState] = useState(0);
17
+ return useCallback(() => {
18
+ setState(stateChanger);
19
+ }, []);
19
20
  }
20
21
  /**
21
- * This is a fork of the official `useEditor` hook with one key difference, which is to prevent a
22
- * `null` Editor object instance from being returned on the first render.
23
- *
24
- * This change was once fixed in the `@tiptap/react` package, but was reverted because it didn't
25
- * have support for server-side rendering ([ref](https://github.com/ueberdosis/tiptap/pull/2282)),
26
- * which is a problem we don't currently have.
27
- *
28
- * @param options The options to configure the editor component with.
29
- * @param dependencies If present, re-create the editor instance if the values in the list change.
30
- *
31
- * @returns A new editor instance with the given options.
32
- */
22
+ * This is a fork of the official `useEditor` hook with one key difference, which is to prevent a
23
+ * `null` Editor object instance from being returned on the first render.
24
+ *
25
+ * This change was once fixed in the `@tiptap/react` package, but was reverted because it didn't
26
+ * have support for server-side rendering ([ref](https://github.com/ueberdosis/tiptap/pull/2282)),
27
+ * which is a problem we don't currently have.
28
+ *
29
+ * @param options The options to configure the editor component with.
30
+ * @param dependencies If present, re-create the editor instance if the values in the list change.
31
+ *
32
+ * @returns A new editor instance with the given options.
33
+ */
33
34
  function useEditor(options = {}, dependencies = []) {
34
- const [editor, setEditor] = useState(() => new Editor(options));
35
- const forceRerender = useRerender();
36
- useEffect(function initializeEditorInstance() {
37
- let instance;
38
- if (editor.isDestroyed) {
39
- instance = new Editor(options);
40
- setEditor(instance);
41
- }
42
- else {
43
- instance = editor;
44
- }
45
- instance.on('transaction', () => {
46
- requestAnimationFrame(() => {
47
- requestAnimationFrame(() => {
48
- if (!instance.isDestroyed) {
49
- forceRerender();
50
- }
51
- });
52
- });
53
- });
54
- return function destroyEditorInstance() {
55
- instance.destroy();
56
- };
57
- },
58
- // eslint-disable-next-line react-hooks/exhaustive-deps
59
- dependencies);
60
- return editor;
35
+ const [editor, setEditor] = useState(() => new Editor(options));
36
+ const forceRerender = useRerender();
37
+ useEffect(function initializeEditorInstance() {
38
+ let instance;
39
+ if (editor.isDestroyed) {
40
+ instance = new Editor(options);
41
+ setEditor(instance);
42
+ } else instance = editor;
43
+ instance.on("transaction", () => {
44
+ requestAnimationFrame(() => {
45
+ requestAnimationFrame(() => {
46
+ if (!instance.isDestroyed) forceRerender();
47
+ });
48
+ });
49
+ });
50
+ return function destroyEditorInstance() {
51
+ instance.destroy();
52
+ };
53
+ }, dependencies);
54
+ return editor;
61
55
  }
56
+ //#endregion
62
57
  export { useEditor };
58
+
59
+ //# sourceMappingURL=use-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-editor.js","names":[],"sources":["../../src/hooks/use-editor.ts"],"sourcesContent":["import { DependencyList, useCallback, useEffect, useState } from 'react'\n\nimport { Editor } from '@tiptap/react'\n\nimport type { EditorOptions } from '@tiptap/core'\n\nfunction stateChanger(state: number) {\n return (state + 1) % Number.MAX_SAFE_INTEGER\n}\n\n/**\n * This is a copy of the `useRerender` hook from `@react-hookz/web`, which is a utility hook that\n * returns a function that can be called to force a re-render of the component.\n *\n * Turns out we don't have the need to use any of the other hooks from `@react-hookz/web`, which is\n * a peer dependency that often introduces breaking changes, causing upgrade issues across our\n * projects.\n */\nfunction useRerender(): () => void {\n const [, setState] = useState(0)\n\n return useCallback(() => {\n setState(stateChanger)\n }, [])\n}\n\n/**\n * This is a fork of the official `useEditor` hook with one key difference, which is to prevent a\n * `null` Editor object instance from being returned on the first render.\n *\n * This change was once fixed in the `@tiptap/react` package, but was reverted because it didn't\n * have support for server-side rendering ([ref](https://github.com/ueberdosis/tiptap/pull/2282)),\n * which is a problem we don't currently have.\n *\n * @param options The options to configure the editor component with.\n * @param dependencies If present, re-create the editor instance if the values in the list change.\n *\n * @returns A new editor instance with the given options.\n */\nfunction useEditor(\n options: Partial<EditorOptions> = {},\n dependencies: DependencyList = [],\n): Editor {\n const [editor, setEditor] = useState<Editor>(() => new Editor(options))\n\n const forceRerender = useRerender()\n\n useEffect(\n function initializeEditorInstance() {\n let instance: Editor\n\n if (editor.isDestroyed) {\n instance = new Editor(options)\n setEditor(instance)\n } else {\n instance = editor\n }\n\n instance.on('transaction', () => {\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n if (!instance.isDestroyed) {\n forceRerender()\n }\n })\n })\n })\n\n return function destroyEditorInstance() {\n instance.destroy()\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n dependencies,\n )\n\n return editor\n}\n\nexport { useEditor }\n"],"mappings":";;;AAMA,SAAS,aAAa,OAAe;AACjC,SAAQ,QAAQ,KAAK,OAAO;;;;;;;;;;AAWhC,SAAS,cAA0B;CAC/B,MAAM,GAAG,YAAY,SAAS,EAAE;AAEhC,QAAO,kBAAkB;AACrB,WAAS,aAAa;IACvB,EAAE,CAAC;;;;;;;;;;;;;;;AAgBV,SAAS,UACL,UAAkC,EAAE,EACpC,eAA+B,EAAE,EAC3B;CACN,MAAM,CAAC,QAAQ,aAAa,eAAuB,IAAI,OAAO,QAAQ,CAAC;CAEvE,MAAM,gBAAgB,aAAa;AAEnC,WACI,SAAS,2BAA2B;EAChC,IAAI;AAEJ,MAAI,OAAO,aAAa;AACpB,cAAW,IAAI,OAAO,QAAQ;AAC9B,aAAU,SAAS;QAEnB,YAAW;AAGf,WAAS,GAAG,qBAAqB;AAC7B,+BAA4B;AACxB,gCAA4B;AACxB,SAAI,CAAC,SAAS,YACV,gBAAe;MAErB;KACJ;IACJ;AAEF,SAAO,SAAS,wBAAwB;AACpC,YAAS,SAAS;;IAI1B,aACH;AAED,QAAO"}
package/dist/index.d.ts CHANGED
@@ -1,31 +1,25 @@
1
- export type { BeforeCreateProps, BlurProps, CreateProps, DestroyProps, FocusProps, SelectionUpdateProps, TransacationProps, TypistEditorProps, TypistEditorRef, UpdateProps, } from './components/typist-editor';
2
- export { TypistEditor } from './components/typist-editor';
3
- export * from './constants/extension-priorities';
4
- export * from './extensions/core/extra-editor-commands/commands/create-paragraph-end';
5
- export * from './extensions/core/extra-editor-commands/commands/extend-word-range';
6
- export * from './extensions/core/extra-editor-commands/commands/insert-markdown-content';
7
- export * from './extensions/core/extra-editor-commands/commands/insert-markdown-content-at';
8
- export { PlainTextKit } from './extensions/plain-text/plain-text-kit';
9
- export type { RichTextImageAttributes, RichTextImageOptions, } from './extensions/rich-text/rich-text-image';
10
- export { RichTextKit } from './extensions/rich-text/rich-text-kit';
11
- export type { SuggestionExtensionResult, SuggestionOptions, SuggestionRendererProps, SuggestionRendererRef, SuggestionStorage, } from './factories/create-suggestion-extension';
12
- export { createSuggestionExtension } from './factories/create-suggestion-extension';
13
- export { isMultilineDocument, isPlainTextDocument } from './helpers/schema';
14
- export { createHTMLSerializer, getHTMLSerializerInstance } from './serializers/html/html';
15
- export { remarkAutolinkLiteral } from './serializers/html/plugins/remark-autolink-literal';
16
- export { remarkStrikethrough } from './serializers/html/plugins/remark-strikethrough';
17
- export { createMarkdownSerializer, getMarkdownSerializerInstance, } from './serializers/markdown/markdown';
18
- export { canInsertNodeAt } from './utilities/can-insert-node-at';
19
- export { canInsertSuggestion } from './utilities/can-insert-suggestion';
20
- export type { AnyConfig, Editor as CoreEditor, EditorEvents, MarkRange, Range } from '@tiptap/core';
21
- export { combineTransactionSteps, defaultBlockAt, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarksBetween, getMarkType, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, mergeAttributes, posToDOMRect, } from '@tiptap/core';
22
- export { Extension, Mark } from '@tiptap/core';
23
- export * from '@tiptap/extension-character-count';
24
- export * as ProseMirrorModel from '@tiptap/pm/model';
25
- export * as ProseMirrorState from '@tiptap/pm/state';
26
- export * as ProseMirrorView from '@tiptap/pm/view';
27
- export type { Editor, NodeViewProps, ReactRendererOptions } from '@tiptap/react';
28
- export { NodeViewWrapper, ReactRenderer } from '@tiptap/react';
29
- export type { SuggestionKeyDownProps, SuggestionOptions as TiptapSuggestionOptions, } from '@tiptap/suggestion';
30
- export { Suggestion } from '@tiptap/suggestion';
31
- //# sourceMappingURL=index.d.ts.map
1
+ import { BeforeCreateProps, BlurProps, CreateProps, DestroyProps, FocusProps, SelectionUpdateProps, TransacationProps, TypistEditor, TypistEditorProps, TypistEditorRef, UpdateProps } from "./components/typist-editor.js";
2
+ import { BLOCKQUOTE_EXTENSION_PRIORITY, CODE_EXTENSION_PRIORITY, PASTE_HTML_TABLE_AS_STRING_EXTENSION_PRIORITY, PASTE_MARKDOWN_EXTENSION_PRIORITY, SMART_MARKDOWN_TYPING_PRIORITY, SUGGESTION_EXTENSION_PRIORITY, VIEW_EVENT_HANDLERS_PRIORITY } from "./constants/extension-priorities.js";
3
+ import { createParagraphEnd } from "./extensions/core/extra-editor-commands/commands/create-paragraph-end.js";
4
+ import { extendWordRange } from "./extensions/core/extra-editor-commands/commands/extend-word-range.js";
5
+ import { insertMarkdownContent } from "./extensions/core/extra-editor-commands/commands/insert-markdown-content.js";
6
+ import { insertMarkdownContentAt } from "./extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js";
7
+ import { PlainTextKit } from "./extensions/plain-text/plain-text-kit.js";
8
+ import { RichTextImageAttributes, RichTextImageOptions } from "./extensions/rich-text/rich-text-image.js";
9
+ import { RichTextKit } from "./extensions/rich-text/rich-text-kit.js";
10
+ import { SuggestionExtensionResult, SuggestionOptions, SuggestionRendererProps, SuggestionRendererRef, SuggestionStorage, createSuggestionExtension } from "./factories/create-suggestion-extension.js";
11
+ import { isMultilineDocument, isPlainTextDocument } from "./helpers/schema.js";
12
+ import { createHTMLSerializer, getHTMLSerializerInstance } from "./serializers/html/html.js";
13
+ import { remarkAutolinkLiteral } from "./serializers/html/plugins/remark-autolink-literal.js";
14
+ import { remarkStrikethrough } from "./serializers/html/plugins/remark-strikethrough.js";
15
+ import { createMarkdownSerializer, getMarkdownSerializerInstance } from "./serializers/markdown/markdown.js";
16
+ import { canInsertNodeAt } from "./utilities/can-insert-node-at.js";
17
+ import { canInsertSuggestion } from "./utilities/can-insert-suggestion.js";
18
+ import { AnyConfig, Editor as CoreEditor, EditorEvents, Extension, Mark, MarkRange, Range, combineTransactionSteps, defaultBlockAt, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, mergeAttributes, posToDOMRect } from "@tiptap/core";
19
+ import { Editor, NodeViewProps, NodeViewWrapper, ReactRenderer, ReactRendererOptions } from "@tiptap/react";
20
+ import * as ProseMirrorState from "@tiptap/pm/state";
21
+ import * as ProseMirrorModel from "@tiptap/pm/model";
22
+ import { Suggestion, SuggestionKeyDownProps, SuggestionOptions as TiptapSuggestionOptions } from "@tiptap/suggestion";
23
+ import * as ProseMirrorView from "@tiptap/pm/view";
24
+ export * from "@tiptap/extension-character-count";
25
+ export { type AnyConfig, BLOCKQUOTE_EXTENSION_PRIORITY, type BeforeCreateProps, type BlurProps, CODE_EXTENSION_PRIORITY, type CoreEditor, type CreateProps, type DestroyProps, type Editor, type EditorEvents, Extension, type FocusProps, Mark, type MarkRange, type NodeViewProps, NodeViewWrapper, PASTE_HTML_TABLE_AS_STRING_EXTENSION_PRIORITY, PASTE_MARKDOWN_EXTENSION_PRIORITY, PlainTextKit, ProseMirrorModel, ProseMirrorState, ProseMirrorView, type Range, ReactRenderer, type ReactRendererOptions, type RichTextImageAttributes, type RichTextImageOptions, RichTextKit, SMART_MARKDOWN_TYPING_PRIORITY, SUGGESTION_EXTENSION_PRIORITY, type SelectionUpdateProps, Suggestion, type SuggestionExtensionResult, type SuggestionKeyDownProps, type SuggestionOptions, type SuggestionRendererProps, type SuggestionRendererRef, type SuggestionStorage, type TiptapSuggestionOptions, type TransacationProps, TypistEditor, type TypistEditorProps, type TypistEditorRef, type UpdateProps, VIEW_EVENT_HANDLERS_PRIORITY, canInsertNodeAt, canInsertSuggestion, combineTransactionSteps, createHTMLSerializer, createMarkdownSerializer, createParagraphEnd, createSuggestionExtension, defaultBlockAt, extendWordRange, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getHTMLSerializerInstance, getMarkAttributes, getMarkRange, getMarkType, getMarkdownSerializerInstance, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, insertMarkdownContent, insertMarkdownContentAt, isActive, isList, isMarkActive, isMultilineDocument, isNodeActive, isNodeEmpty, isNodeSelection, isPlainTextDocument, isTextSelection, mergeAttributes, posToDOMRect, remarkAutolinkLiteral, remarkStrikethrough };
package/dist/index.js CHANGED
@@ -1,24 +1,24 @@
1
- export { TypistEditor } from './components/typist-editor';
2
- export * from './constants/extension-priorities';
3
- export * from './extensions/core/extra-editor-commands/commands/create-paragraph-end';
4
- export * from './extensions/core/extra-editor-commands/commands/extend-word-range';
5
- export * from './extensions/core/extra-editor-commands/commands/insert-markdown-content';
6
- export * from './extensions/core/extra-editor-commands/commands/insert-markdown-content-at';
7
- export { PlainTextKit } from './extensions/plain-text/plain-text-kit';
8
- export { RichTextKit } from './extensions/rich-text/rich-text-kit';
9
- export { createSuggestionExtension } from './factories/create-suggestion-extension';
10
- export { isMultilineDocument, isPlainTextDocument } from './helpers/schema';
11
- export { createHTMLSerializer, getHTMLSerializerInstance } from './serializers/html/html';
12
- export { remarkAutolinkLiteral } from './serializers/html/plugins/remark-autolink-literal';
13
- export { remarkStrikethrough } from './serializers/html/plugins/remark-strikethrough';
14
- export { createMarkdownSerializer, getMarkdownSerializerInstance, } from './serializers/markdown/markdown';
15
- export { canInsertNodeAt } from './utilities/can-insert-node-at';
16
- export { canInsertSuggestion } from './utilities/can-insert-suggestion';
17
- export { combineTransactionSteps, defaultBlockAt, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarksBetween, getMarkType, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, mergeAttributes, posToDOMRect, } from '@tiptap/core';
18
- export { Extension, Mark } from '@tiptap/core';
19
- export * from '@tiptap/extension-character-count';
20
- export * as ProseMirrorModel from '@tiptap/pm/model';
21
- export * as ProseMirrorState from '@tiptap/pm/state';
22
- export * as ProseMirrorView from '@tiptap/pm/view';
23
- export { NodeViewWrapper, ReactRenderer } from '@tiptap/react';
24
- export { Suggestion } from '@tiptap/suggestion';
1
+ import { createParagraphEnd } from "./extensions/core/extra-editor-commands/commands/create-paragraph-end.js";
2
+ import { extendWordRange } from "./extensions/core/extra-editor-commands/commands/extend-word-range.js";
3
+ import { insertMarkdownContent } from "./extensions/core/extra-editor-commands/commands/insert-markdown-content.js";
4
+ import { isMultilineDocument, isPlainTextDocument } from "./helpers/schema.js";
5
+ import { remarkAutolinkLiteral } from "./serializers/html/plugins/remark-autolink-literal.js";
6
+ import { remarkStrikethrough } from "./serializers/html/plugins/remark-strikethrough.js";
7
+ import { createHTMLSerializer, getHTMLSerializerInstance } from "./serializers/html/html.js";
8
+ import { insertMarkdownContentAt } from "./extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js";
9
+ import { BLOCKQUOTE_EXTENSION_PRIORITY, CODE_EXTENSION_PRIORITY, PASTE_HTML_TABLE_AS_STRING_EXTENSION_PRIORITY, PASTE_MARKDOWN_EXTENSION_PRIORITY, SMART_MARKDOWN_TYPING_PRIORITY, SUGGESTION_EXTENSION_PRIORITY, VIEW_EVENT_HANDLERS_PRIORITY } from "./constants/extension-priorities.js";
10
+ import { createMarkdownSerializer, getMarkdownSerializerInstance } from "./serializers/markdown/markdown.js";
11
+ import { TypistEditor } from "./components/typist-editor.js";
12
+ import { PlainTextKit } from "./extensions/plain-text/plain-text-kit.js";
13
+ import { RichTextKit } from "./extensions/rich-text/rich-text-kit.js";
14
+ import { canInsertNodeAt } from "./utilities/can-insert-node-at.js";
15
+ import { canInsertSuggestion } from "./utilities/can-insert-suggestion.js";
16
+ import { createSuggestionExtension } from "./factories/create-suggestion-extension.js";
17
+ import { Extension, Mark, combineTransactionSteps, defaultBlockAt, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, mergeAttributes, posToDOMRect } from "@tiptap/core";
18
+ import { NodeViewWrapper, ReactRenderer } from "@tiptap/react";
19
+ import * as ProseMirrorState from "@tiptap/pm/state";
20
+ import * as ProseMirrorModel from "@tiptap/pm/model";
21
+ import { Suggestion } from "@tiptap/suggestion";
22
+ import * as ProseMirrorView from "@tiptap/pm/view";
23
+ export * from "@tiptap/extension-character-count";
24
+ export { BLOCKQUOTE_EXTENSION_PRIORITY, CODE_EXTENSION_PRIORITY, Extension, Mark, NodeViewWrapper, PASTE_HTML_TABLE_AS_STRING_EXTENSION_PRIORITY, PASTE_MARKDOWN_EXTENSION_PRIORITY, PlainTextKit, ProseMirrorModel, ProseMirrorState, ProseMirrorView, ReactRenderer, RichTextKit, SMART_MARKDOWN_TYPING_PRIORITY, SUGGESTION_EXTENSION_PRIORITY, Suggestion, TypistEditor, VIEW_EVENT_HANDLERS_PRIORITY, canInsertNodeAt, canInsertSuggestion, combineTransactionSteps, createHTMLSerializer, createMarkdownSerializer, createParagraphEnd, createSuggestionExtension, defaultBlockAt, extendWordRange, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getHTMLSerializerInstance, getMarkAttributes, getMarkRange, getMarkType, getMarkdownSerializerInstance, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, insertMarkdownContent, insertMarkdownContentAt, isActive, isList, isMarkActive, isMultilineDocument, isNodeActive, isNodeEmpty, isNodeSelection, isPlainTextDocument, isTextSelection, mergeAttributes, posToDOMRect, remarkAutolinkLiteral, remarkStrikethrough };
@@ -1,16 +1,18 @@
1
- import type { Schema } from '@tiptap/pm/model';
1
+ import { Schema } from "@tiptap/pm/model";
2
+
3
+ //#region src/serializers/html/html.d.ts
2
4
  /**
3
5
  * The return type for the `createHTMLSerializer` function.
4
6
  */
5
7
  type HTMLSerializerReturnType = {
6
- /**
7
- * Serializes an input Markdown string to an output HTML string.
8
- *
9
- * @param markdown The Markdown string to serialize.
10
- *
11
- * @returns The serialized HTML.
12
- */
13
- serialize: (markdown: string) => string;
8
+ /**
9
+ * Serializes an input Markdown string to an output HTML string.
10
+ *
11
+ * @param markdown The Markdown string to serialize.
12
+ *
13
+ * @returns The serialized HTML.
14
+ */
15
+ serialize: (markdown: string) => string;
14
16
  };
15
17
  /**
16
18
  * Create a Markdown to HTML serializer with the unified ecosystem for a rich-text editor, or use a
@@ -30,6 +32,6 @@ declare function createHTMLSerializer(schema: Schema): HTMLSerializerReturnType;
30
32
  * @returns The HTML serializer instance for the given editor schema.
31
33
  */
32
34
  declare function getHTMLSerializerInstance(schema: Schema): HTMLSerializerReturnType;
35
+ //#endregion
33
36
  export { createHTMLSerializer, getHTMLSerializerInstance };
34
- export type { HTMLSerializerReturnType };
35
37
  //# sourceMappingURL=html.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../../src/serializers/html/html.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAE9C;;GAEG;AACH,KAAK,wBAAwB,GAAG;IAC5B;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAA;CAC1C,CAAA;AA0CD;;;;;;;;GAQG;AACH,iBAAS,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,wBAAwB,CAiFtE;AAOD;;;;;;GAMG;AACH,iBAAS,yBAAyB,CAAC,MAAM,EAAE,MAAM,4BAQhD;AAED,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,CAAA;AAE1D,YAAY,EAAE,wBAAwB,EAAE,CAAA"}
1
+ {"version":3,"file":"html.d.ts","names":[],"sources":["../../../src/serializers/html/html.ts"],"mappings":";;;;;AAkB8C;KAKzC,wBAAA;;;;AAQ2B;;;;EAA5B,SAAA,GAAY,QAAA;AAAA;;;;AAoDuD;;;;;;iBAA9D,oBAAA,CAAqB,MAAA,EAAQ,MAAA,GAAS,wBAAA;;;;;;;;iBA+FtC,yBAAA,CAA0B,MAAA,EAAQ,MAAA,GAAM,wBAAA"}
@@ -1,139 +1,79 @@
1
- import { escape, kebabCase } from 'lodash-es';
2
- import rehypeMinifyWhitespace from 'rehype-minify-whitespace';
3
- import rehypeStringify from 'rehype-stringify';
4
- import remarkBreaks from 'remark-breaks';
5
- import remarkParse from 'remark-parse';
6
- import remarkRehype from 'remark-rehype';
7
- import { unified } from 'unified';
8
- import { computeSchemaId, isPlainTextDocument } from '../../helpers/schema';
9
- import { rehypeCodeBlock } from './plugins/rehype-code-block';
10
- import { rehypeImage } from './plugins/rehype-image';
11
- import { rehypeSuggestions } from './plugins/rehype-suggestions';
12
- import { rehypeTaskList } from './plugins/rehype-task-list';
13
- import { remarkAutolinkLiteral } from './plugins/remark-autolink-literal';
14
- import { remarkDisableConstructs } from './plugins/remark-disable-constructs';
15
- import { remarkStrikethrough } from './plugins/remark-strikethrough';
1
+ import { computeSchemaId, isPlainTextDocument } from "../../helpers/schema.js";
2
+ import { rehypeCodeBlock } from "./plugins/rehype-code-block.js";
3
+ import { rehypeImage } from "./plugins/rehype-image.js";
4
+ import { rehypeSuggestions } from "./plugins/rehype-suggestions.js";
5
+ import { rehypeTaskList } from "./plugins/rehype-task-list.js";
6
+ import { remarkAutolinkLiteral } from "./plugins/remark-autolink-literal.js";
7
+ import { remarkDisableConstructs } from "./plugins/remark-disable-constructs.js";
8
+ import { remarkStrikethrough } from "./plugins/remark-strikethrough.js";
9
+ import { escape, kebabCase } from "lodash-es";
10
+ import rehypeMinifyWhitespace from "rehype-minify-whitespace";
11
+ import rehypeStringify from "rehype-stringify";
12
+ import remarkBreaks from "remark-breaks";
13
+ import remarkParse from "remark-parse";
14
+ import remarkRehype from "remark-rehype";
15
+ import { unified } from "unified";
16
+ //#region src/serializers/html/html.ts
16
17
  /**
17
- * Create a custom Markdown to HTML serializer for plain-text editors only.
18
- *
19
- * @param schema The editor schema to be used for nodes and marks detection.
20
- *
21
- * @returns A normalized object for the HTML serializer.
22
- */
18
+ * Create a custom Markdown to HTML serializer for plain-text editors only.
19
+ *
20
+ * @param schema The editor schema to be used for nodes and marks detection.
21
+ *
22
+ * @returns A normalized object for the HTML serializer.
23
+ */
23
24
  function createHTMLSerializerForPlainTextEditor(schema) {
24
- return {
25
- serialize(markdown) {
26
- // Converts special characters (i.e. `&`, `<`, `>`, `"`, and `'`) to their corresponding
27
- // HTML entities because we need to output the full content as valid HTML (i.e. the
28
- // editor should not drop invalid HTML).
29
- let htmlResult = escape(markdown);
30
- // Serialize all suggestion links if any suggestion node exists in the schema
31
- Object.values(schema.nodes)
32
- .filter((node) => node.name.endsWith('Suggestion'))
33
- .forEach((suggestionNode) => {
34
- const linkSchema = kebabCase(suggestionNode.name.replace(/Suggestion$/, ''));
35
- htmlResult = htmlResult.replace(new RegExp(`\\[([^\\[]+)\\]\\((?:${linkSchema}):\\/\\/(\\d+)\\)`, 'gm'), `<span data-${linkSchema} data-id="$2" data-label="$1"></span>`);
36
- });
37
- // Return the serialized HTML with every line wrapped in a paragraph element
38
- return htmlResult.replace(/^([^\n]+)\n?|\n+/gm, `<p>$1</p>`);
39
- },
40
- };
25
+ return { serialize(markdown) {
26
+ let htmlResult = escape(markdown);
27
+ Object.values(schema.nodes).filter((node) => node.name.endsWith("Suggestion")).forEach((suggestionNode) => {
28
+ const linkSchema = kebabCase(suggestionNode.name.replace(/Suggestion$/, ""));
29
+ htmlResult = htmlResult.replace(new RegExp(`\\[([^\\[]+)\\]\\((?:${linkSchema}):\\/\\/(\\d+)\\)`, "gm"), `<span data-${linkSchema} data-id="$2" data-label="$1"></span>`);
30
+ });
31
+ return htmlResult.replace(/^([^\n]+)\n?|\n+/gm, `<p>$1</p>`);
32
+ } };
41
33
  }
42
34
  /**
43
- * Create a Markdown to HTML serializer with the unified ecosystem for a rich-text editor, or use a
44
- * custom serializer for a plain-text editor. The editor schema is used to detect which nodes and
45
- * marks are available in the editor, and only parses the input with the minimal required plugins.
46
- *
47
- * @param schema The editor schema to be used for nodes and marks detection.
48
- *
49
- * @returns A normalized object for the HTML serializer.
50
- */
35
+ * Create a Markdown to HTML serializer with the unified ecosystem for a rich-text editor, or use a
36
+ * custom serializer for a plain-text editor. The editor schema is used to detect which nodes and
37
+ * marks are available in the editor, and only parses the input with the minimal required plugins.
38
+ *
39
+ * @param schema The editor schema to be used for nodes and marks detection.
40
+ *
41
+ * @returns A normalized object for the HTML serializer.
42
+ */
51
43
  function createHTMLSerializer(schema) {
52
- // Returns a custom HTML serializer for plain-text editors
53
- if (isPlainTextDocument(schema)) {
54
- return createHTMLSerializerForPlainTextEditor(schema);
55
- }
56
- // Initialize a unified processor with a remark plugin for parsing Markdown
57
- const unifiedProcessor = unified().use(remarkParse);
58
- // Configure the unified processor to use a custom plugin to disable constructs based on the
59
- // supported extensions that are enabled in the editor schema
60
- unifiedProcessor.use(remarkDisableConstructs, schema);
61
- // Configure the unified processor to use a third-party plugin to turn soft line endings into
62
- // hard breaks (i.e. `<br>`), which will display user content closer to how it was authored
63
- // (although not CommonMark compliant, this resembles the behaviour we always supported)
64
- if (schema.nodes.hardBreak) {
65
- unifiedProcessor.use(remarkBreaks);
66
- }
67
- // Configure the unified processor to use a custom plugin to add support for the strikethrough
68
- // extension from the GitHub Flavored Markdown (GFM) specification
69
- if (schema.marks.strike) {
70
- unifiedProcessor.use(remarkStrikethrough, { singleTilde: false });
71
- }
72
- // Configure the unified processor to use a custom plugin to add support for the autolink
73
- // literals extension from the GitHub Flavored Markdown (GFM) specification
74
- if (schema.marks.link) {
75
- unifiedProcessor.use(remarkAutolinkLiteral);
76
- }
77
- // Configure the unified processor with an official plugin to convert Markdown into HTML to
78
- // support rehype (a tool that transforms HTML with plugins), followed by another official
79
- // plugin to minify whitespace between tags (prevents line feeds from appearing as blank)
80
- unifiedProcessor
81
- .use(remarkRehype, {
82
- // Persist raw HTML (disables support for custom elements/tags)
83
- // ref: https://github.com/Doist/Issues/issues/5689
84
- allowDangerousHtml: true,
85
- })
86
- // This must come before all rehype plugins that transform the HTML output
87
- .use(rehypeMinifyWhitespace, {
88
- // Preserve line breaks when collapsing whitespace (e.g., line feeds)
89
- newlines: true,
90
- });
91
- // Configure the unified processor with a custom plugin to remove the trailing newline from code
92
- // blocks (i.e. the newline between the last code line and `</code></pre>`)
93
- if (schema.nodes.codeBlock) {
94
- unifiedProcessor.use(rehypeCodeBlock);
95
- }
96
- // Configure the unified processor with a custom plugin to remove the wrapping paragraph from
97
- // images and to remove all inline images based on inline images support in the editor schema
98
- if (schema.nodes.paragraph && schema.nodes.image) {
99
- unifiedProcessor.use(rehypeImage, schema);
100
- }
101
- // Configure the unified processor with a custom plugin to add support Tiptap task lists
102
- if (schema.nodes.taskList && schema.nodes.taskItem) {
103
- unifiedProcessor.use(rehypeTaskList);
104
- }
105
- // Configure the unified processor with a custom plugin to add support for suggestions nodes
106
- unifiedProcessor.use(rehypeSuggestions, schema);
107
- // Configure the unified processor with an official plugin that defines how to take a syntax
108
- // tree as input and turn it into serialized HTML
109
- unifiedProcessor.use(rehypeStringify, {
110
- characterReferences: {
111
- // Compatibility with the previous implementation in Marked
112
- useNamedReferences: true,
113
- },
114
- });
115
- return {
116
- serialize(markdown) {
117
- return unifiedProcessor.processSync(markdown).toString();
118
- },
119
- };
44
+ if (isPlainTextDocument(schema)) return createHTMLSerializerForPlainTextEditor(schema);
45
+ const unifiedProcessor = unified().use(remarkParse);
46
+ unifiedProcessor.use(remarkDisableConstructs, schema);
47
+ if (schema.nodes.hardBreak) unifiedProcessor.use(remarkBreaks);
48
+ if (schema.marks.strike) unifiedProcessor.use(remarkStrikethrough, { singleTilde: false });
49
+ if (schema.marks.link) unifiedProcessor.use(remarkAutolinkLiteral);
50
+ unifiedProcessor.use(remarkRehype, { allowDangerousHtml: true }).use(rehypeMinifyWhitespace, { newlines: true });
51
+ if (schema.nodes.codeBlock) unifiedProcessor.use(rehypeCodeBlock);
52
+ if (schema.nodes.paragraph && schema.nodes.image) unifiedProcessor.use(rehypeImage, schema);
53
+ if (schema.nodes.taskList && schema.nodes.taskItem) unifiedProcessor.use(rehypeTaskList);
54
+ unifiedProcessor.use(rehypeSuggestions, schema);
55
+ unifiedProcessor.use(rehypeStringify, { characterReferences: { useNamedReferences: true } });
56
+ return { serialize(markdown) {
57
+ return unifiedProcessor.processSync(markdown).toString();
58
+ } };
120
59
  }
121
60
  /**
122
- * Object that holds multiple HTML serializer instances based on a given ID.
123
- */
61
+ * Object that holds multiple HTML serializer instances based on a given ID.
62
+ */
124
63
  const htmlSerializerInstanceById = {};
125
64
  /**
126
- * Returns a singleton instance of a HTML serializer based on the provided editor schema.
127
- *
128
- * @param schema The editor schema connected to the HTML serializer instance.
129
- *
130
- * @returns The HTML serializer instance for the given editor schema.
131
- */
65
+ * Returns a singleton instance of a HTML serializer based on the provided editor schema.
66
+ *
67
+ * @param schema The editor schema connected to the HTML serializer instance.
68
+ *
69
+ * @returns The HTML serializer instance for the given editor schema.
70
+ */
132
71
  function getHTMLSerializerInstance(schema) {
133
- const id = computeSchemaId(schema);
134
- if (!htmlSerializerInstanceById[id]) {
135
- htmlSerializerInstanceById[id] = createHTMLSerializer(schema);
136
- }
137
- return htmlSerializerInstanceById[id];
72
+ const id = computeSchemaId(schema);
73
+ if (!htmlSerializerInstanceById[id]) htmlSerializerInstanceById[id] = createHTMLSerializer(schema);
74
+ return htmlSerializerInstanceById[id];
138
75
  }
76
+ //#endregion
139
77
  export { createHTMLSerializer, getHTMLSerializerInstance };
78
+
79
+ //# sourceMappingURL=html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.js","names":[],"sources":["../../../src/serializers/html/html.ts"],"sourcesContent":["import { escape, kebabCase } from 'lodash-es'\nimport rehypeMinifyWhitespace from 'rehype-minify-whitespace'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkBreaks from 'remark-breaks'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport { unified } from 'unified'\n\nimport { computeSchemaId, isPlainTextDocument } from '../../helpers/schema'\n\nimport { rehypeCodeBlock } from './plugins/rehype-code-block'\nimport { rehypeImage } from './plugins/rehype-image'\nimport { rehypeSuggestions } from './plugins/rehype-suggestions'\nimport { rehypeTaskList } from './plugins/rehype-task-list'\nimport { remarkAutolinkLiteral } from './plugins/remark-autolink-literal'\nimport { remarkDisableConstructs } from './plugins/remark-disable-constructs'\nimport { remarkStrikethrough } from './plugins/remark-strikethrough'\n\nimport type { Schema } from '@tiptap/pm/model'\n\n/**\n * The return type for the `createHTMLSerializer` function.\n */\ntype HTMLSerializerReturnType = {\n /**\n * Serializes an input Markdown string to an output HTML string.\n *\n * @param markdown The Markdown string to serialize.\n *\n * @returns The serialized HTML.\n */\n serialize: (markdown: string) => string\n}\n\n/**\n * The type for the object that holds multiple HTML serializer instances.\n */\ntype HTMLSerializerInstanceById = {\n [id: string]: HTMLSerializerReturnType\n}\n\n/**\n * Create a custom Markdown to HTML serializer for plain-text editors only.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the HTML serializer.\n */\nfunction createHTMLSerializerForPlainTextEditor(schema: Schema) {\n return {\n serialize(markdown: string) {\n // Converts special characters (i.e. `&`, `<`, `>`, `\"`, and `'`) to their corresponding\n // HTML entities because we need to output the full content as valid HTML (i.e. the\n // editor should not drop invalid HTML).\n let htmlResult = escape(markdown)\n\n // Serialize all suggestion links if any suggestion node exists in the schema\n Object.values(schema.nodes)\n .filter((node) => node.name.endsWith('Suggestion'))\n .forEach((suggestionNode) => {\n const linkSchema = kebabCase(suggestionNode.name.replace(/Suggestion$/, ''))\n\n htmlResult = htmlResult.replace(\n new RegExp(`\\\\[([^\\\\[]+)\\\\]\\\\((?:${linkSchema}):\\\\/\\\\/(\\\\d+)\\\\)`, 'gm'),\n `<span data-${linkSchema} data-id=\"$2\" data-label=\"$1\"></span>`,\n )\n })\n\n // Return the serialized HTML with every line wrapped in a paragraph element\n return htmlResult.replace(/^([^\\n]+)\\n?|\\n+/gm, `<p>$1</p>`)\n },\n }\n}\n\n/**\n * Create a Markdown to HTML serializer with the unified ecosystem for a rich-text editor, or use a\n * custom serializer for a plain-text editor. The editor schema is used to detect which nodes and\n * marks are available in the editor, and only parses the input with the minimal required plugins.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the HTML serializer.\n */\nfunction createHTMLSerializer(schema: Schema): HTMLSerializerReturnType {\n // Returns a custom HTML serializer for plain-text editors\n if (isPlainTextDocument(schema)) {\n return createHTMLSerializerForPlainTextEditor(schema)\n }\n\n // Initialize a unified processor with a remark plugin for parsing Markdown\n const unifiedProcessor = unified().use(remarkParse)\n\n // Configure the unified processor to use a custom plugin to disable constructs based on the\n // supported extensions that are enabled in the editor schema\n unifiedProcessor.use(remarkDisableConstructs, schema)\n\n // Configure the unified processor to use a third-party plugin to turn soft line endings into\n // hard breaks (i.e. `<br>`), which will display user content closer to how it was authored\n // (although not CommonMark compliant, this resembles the behaviour we always supported)\n if (schema.nodes.hardBreak) {\n unifiedProcessor.use(remarkBreaks)\n }\n\n // Configure the unified processor to use a custom plugin to add support for the strikethrough\n // extension from the GitHub Flavored Markdown (GFM) specification\n if (schema.marks.strike) {\n unifiedProcessor.use(remarkStrikethrough, { singleTilde: false })\n }\n\n // Configure the unified processor to use a custom plugin to add support for the autolink\n // literals extension from the GitHub Flavored Markdown (GFM) specification\n if (schema.marks.link) {\n unifiedProcessor.use(remarkAutolinkLiteral)\n }\n\n // Configure the unified processor with an official plugin to convert Markdown into HTML to\n // support rehype (a tool that transforms HTML with plugins), followed by another official\n // plugin to minify whitespace between tags (prevents line feeds from appearing as blank)\n unifiedProcessor\n .use(remarkRehype, {\n // Persist raw HTML (disables support for custom elements/tags)\n // ref: https://github.com/Doist/Issues/issues/5689\n allowDangerousHtml: true,\n })\n // This must come before all rehype plugins that transform the HTML output\n .use(rehypeMinifyWhitespace, {\n // Preserve line breaks when collapsing whitespace (e.g., line feeds)\n newlines: true,\n })\n\n // Configure the unified processor with a custom plugin to remove the trailing newline from code\n // blocks (i.e. the newline between the last code line and `</code></pre>`)\n if (schema.nodes.codeBlock) {\n unifiedProcessor.use(rehypeCodeBlock)\n }\n\n // Configure the unified processor with a custom plugin to remove the wrapping paragraph from\n // images and to remove all inline images based on inline images support in the editor schema\n if (schema.nodes.paragraph && schema.nodes.image) {\n unifiedProcessor.use(rehypeImage, schema)\n }\n\n // Configure the unified processor with a custom plugin to add support Tiptap task lists\n if (schema.nodes.taskList && schema.nodes.taskItem) {\n unifiedProcessor.use(rehypeTaskList)\n }\n\n // Configure the unified processor with a custom plugin to add support for suggestions nodes\n unifiedProcessor.use(rehypeSuggestions, schema)\n\n // Configure the unified processor with an official plugin that defines how to take a syntax\n // tree as input and turn it into serialized HTML\n unifiedProcessor.use(rehypeStringify, {\n characterReferences: {\n // Compatibility with the previous implementation in Marked\n useNamedReferences: true,\n },\n })\n\n return {\n serialize(markdown: string) {\n return unifiedProcessor.processSync(markdown).toString()\n },\n }\n}\n\n/**\n * Object that holds multiple HTML serializer instances based on a given ID.\n */\nconst htmlSerializerInstanceById: HTMLSerializerInstanceById = {}\n\n/**\n * Returns a singleton instance of a HTML serializer based on the provided editor schema.\n *\n * @param schema The editor schema connected to the HTML serializer instance.\n *\n * @returns The HTML serializer instance for the given editor schema.\n */\nfunction getHTMLSerializerInstance(schema: Schema) {\n const id = computeSchemaId(schema)\n\n if (!htmlSerializerInstanceById[id]) {\n htmlSerializerInstanceById[id] = createHTMLSerializer(schema)\n }\n\n return htmlSerializerInstanceById[id]\n}\n\nexport { createHTMLSerializer, getHTMLSerializerInstance }\n\nexport type { HTMLSerializerReturnType }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAS,uCAAuC,QAAgB;AAC5D,QAAO,EACH,UAAU,UAAkB;EAIxB,IAAI,aAAa,OAAO,SAAS;AAGjC,SAAO,OAAO,OAAO,MAAM,CACtB,QAAQ,SAAS,KAAK,KAAK,SAAS,aAAa,CAAC,CAClD,SAAS,mBAAmB;GACzB,MAAM,aAAa,UAAU,eAAe,KAAK,QAAQ,eAAe,GAAG,CAAC;AAE5E,gBAAa,WAAW,QACpB,IAAI,OAAO,wBAAwB,WAAW,oBAAoB,KAAK,EACvE,cAAc,WAAW,uCAC5B;IACH;AAGN,SAAO,WAAW,QAAQ,sBAAsB,YAAY;IAEnE;;;;;;;;;;;AAYL,SAAS,qBAAqB,QAA0C;AAEpE,KAAI,oBAAoB,OAAO,CAC3B,QAAO,uCAAuC,OAAO;CAIzD,MAAM,mBAAmB,SAAS,CAAC,IAAI,YAAY;AAInD,kBAAiB,IAAI,yBAAyB,OAAO;AAKrD,KAAI,OAAO,MAAM,UACb,kBAAiB,IAAI,aAAa;AAKtC,KAAI,OAAO,MAAM,OACb,kBAAiB,IAAI,qBAAqB,EAAE,aAAa,OAAO,CAAC;AAKrE,KAAI,OAAO,MAAM,KACb,kBAAiB,IAAI,sBAAsB;AAM/C,kBACK,IAAI,cAAc,EAGf,oBAAoB,MACvB,CAAC,CAED,IAAI,wBAAwB,EAEzB,UAAU,MACb,CAAC;AAIN,KAAI,OAAO,MAAM,UACb,kBAAiB,IAAI,gBAAgB;AAKzC,KAAI,OAAO,MAAM,aAAa,OAAO,MAAM,MACvC,kBAAiB,IAAI,aAAa,OAAO;AAI7C,KAAI,OAAO,MAAM,YAAY,OAAO,MAAM,SACtC,kBAAiB,IAAI,eAAe;AAIxC,kBAAiB,IAAI,mBAAmB,OAAO;AAI/C,kBAAiB,IAAI,iBAAiB,EAClC,qBAAqB,EAEjB,oBAAoB,MACvB,EACJ,CAAC;AAEF,QAAO,EACH,UAAU,UAAkB;AACxB,SAAO,iBAAiB,YAAY,SAAS,CAAC,UAAU;IAE/D;;;;;AAML,MAAM,6BAAyD,EAAE;;;;;;;;AASjE,SAAS,0BAA0B,QAAgB;CAC/C,MAAM,KAAK,gBAAgB,OAAO;AAElC,KAAI,CAAC,2BAA2B,IAC5B,4BAA2B,MAAM,qBAAqB,OAAO;AAGjE,QAAO,2BAA2B"}
@@ -1,21 +1,21 @@
1
- import { visit } from 'unist-util-visit';
2
- import { isHastElementNode, isHastTextNode } from '../../../helpers/unified';
1
+ import { isHastElementNode, isHastTextNode } from "../../../helpers/unified.js";
2
+ import { visit } from "unist-util-visit";
3
+ //#region src/serializers/html/plugins/rehype-code-block.ts
3
4
  /**
4
- * A rehype plugin to remove the trailing newline from code blocks (i.e. the newline between the
5
- * last code line and `</code></pre>`). Although that newline is part of the CommonMark
6
- * specification, this custom plugin is required to prevent Tiptap from rendering a blank line at
7
- * the end of the code block.
8
- */
5
+ * A rehype plugin to remove the trailing newline from code blocks (i.e. the newline between the
6
+ * last code line and `</code></pre>`). Although that newline is part of the CommonMark
7
+ * specification, this custom plugin is required to prevent Tiptap from rendering a blank line at
8
+ * the end of the code block.
9
+ */
9
10
  function rehypeCodeBlock() {
10
- return (...[tree]) => {
11
- visit(tree, 'element', (node) => {
12
- if (isHastElementNode(node, 'pre') &&
13
- isHastElementNode(node.children[0], 'code') &&
14
- isHastTextNode(node.children[0].children[0])) {
15
- node.children[0].children[0].value = node.children[0].children[0].value.replace(/\n$/, '');
16
- }
17
- });
18
- return tree;
19
- };
11
+ return (...[tree]) => {
12
+ visit(tree, "element", (node) => {
13
+ if (isHastElementNode(node, "pre") && isHastElementNode(node.children[0], "code") && isHastTextNode(node.children[0].children[0])) node.children[0].children[0].value = node.children[0].children[0].value.replace(/\n$/, "");
14
+ });
15
+ return tree;
16
+ };
20
17
  }
18
+ //#endregion
21
19
  export { rehypeCodeBlock };
20
+
21
+ //# sourceMappingURL=rehype-code-block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rehype-code-block.js","names":[],"sources":["../../../../src/serializers/html/plugins/rehype-code-block.ts"],"sourcesContent":["import { visit } from 'unist-util-visit'\n\nimport { isHastElementNode, isHastTextNode } from '../../../helpers/unified'\n\nimport type { Node as HastNode } from 'hast'\nimport type { Transformer } from 'unified'\n\n/**\n * A rehype plugin to remove the trailing newline from code blocks (i.e. the newline between the\n * last code line and `</code></pre>`). Although that newline is part of the CommonMark\n * specification, this custom plugin is required to prevent Tiptap from rendering a blank line at\n * the end of the code block.\n */\nfunction rehypeCodeBlock(): Transformer {\n return (...[tree]: Parameters<Transformer>): ReturnType<Transformer> => {\n visit(tree, 'element', (node: HastNode) => {\n if (\n isHastElementNode(node, 'pre') &&\n isHastElementNode(node.children[0], 'code') &&\n isHastTextNode(node.children[0].children[0])\n ) {\n node.children[0].children[0].value = node.children[0].children[0].value.replace(\n /\\n$/,\n '',\n )\n }\n })\n\n return tree\n }\n}\n\nexport { rehypeCodeBlock }\n"],"mappings":";;;;;;;;;AAaA,SAAS,kBAA+B;AACpC,SAAQ,GAAG,CAAC,UAA4D;AACpE,QAAM,MAAM,YAAY,SAAmB;AACvC,OACI,kBAAkB,MAAM,MAAM,IAC9B,kBAAkB,KAAK,SAAS,IAAI,OAAO,IAC3C,eAAe,KAAK,SAAS,GAAG,SAAS,GAAG,CAE5C,MAAK,SAAS,GAAG,SAAS,GAAG,QAAQ,KAAK,SAAS,GAAG,SAAS,GAAG,MAAM,QACpE,OACA,GACH;IAEP;AAEF,SAAO"}