@stesura/react-prosemirror 3.2.11-stesura.1

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 (296) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +939 -0
  3. package/dist/cjs/AbstractEditorView.js +4 -0
  4. package/dist/cjs/ReactEditorView.js +194 -0
  5. package/dist/cjs/StaticEditorView.js +89 -0
  6. package/dist/cjs/browser.js +53 -0
  7. package/dist/cjs/commands/reorderSiblings.js +72 -0
  8. package/dist/cjs/components/ChildNodeViews.js +418 -0
  9. package/dist/cjs/components/CursorWrapper.js +84 -0
  10. package/dist/cjs/components/EditorStateSelectorsProvider.js +90 -0
  11. package/dist/cjs/components/LayoutGroup.js +112 -0
  12. package/dist/cjs/components/NativeWidgetView.js +108 -0
  13. package/dist/cjs/components/OutputSpec.js +121 -0
  14. package/dist/cjs/components/ProseMirror.js +146 -0
  15. package/dist/cjs/components/ProseMirrorDoc.js +74 -0
  16. package/dist/cjs/components/SeparatorHackView.js +99 -0
  17. package/dist/cjs/components/TextNodeView.js +113 -0
  18. package/dist/cjs/components/TrailingHackView.js +87 -0
  19. package/dist/cjs/components/WidgetView.js +94 -0
  20. package/dist/cjs/components/WidgetViewComponentProps.js +4 -0
  21. package/dist/cjs/components/marks/DefaultMarkView.js +70 -0
  22. package/dist/cjs/components/marks/MarkView.js +85 -0
  23. package/dist/cjs/components/marks/MarkViewComponentProps.js +4 -0
  24. package/dist/cjs/components/marks/MarkViewConstructorView.js +116 -0
  25. package/dist/cjs/components/marks/ReactMarkView.js +109 -0
  26. package/dist/cjs/components/nodes/DefaultNodeView.js +68 -0
  27. package/dist/cjs/components/nodes/DocNodeView.js +97 -0
  28. package/dist/cjs/components/nodes/NodeView.js +129 -0
  29. package/dist/cjs/components/nodes/NodeViewComponentProps.js +4 -0
  30. package/dist/cjs/components/nodes/NodeViewConstructorView.js +145 -0
  31. package/dist/cjs/components/nodes/ReactNodeView.js +189 -0
  32. package/dist/cjs/constants.js +33 -0
  33. package/dist/cjs/contexts/ChildDescriptionsContext.js +19 -0
  34. package/dist/cjs/contexts/EditorContext.js +12 -0
  35. package/dist/cjs/contexts/EditorStateContext.js +12 -0
  36. package/dist/cjs/contexts/EditorStateStoreContext.js +45 -0
  37. package/dist/cjs/contexts/IgnoreMutationContext.js +12 -0
  38. package/dist/cjs/contexts/LayoutGroupContext.js +12 -0
  39. package/dist/cjs/contexts/NodeViewContext.js +12 -0
  40. package/dist/cjs/contexts/RenderStoreContext.js +54 -0
  41. package/dist/cjs/contexts/SelectNodeContext.js +12 -0
  42. package/dist/cjs/contexts/StopEventContext.js +12 -0
  43. package/dist/cjs/decorations/ReactWidgetType.js +58 -0
  44. package/dist/cjs/decorations/computeDocDeco.js +44 -0
  45. package/dist/cjs/decorations/internalTypes.js +4 -0
  46. package/dist/cjs/decorations/iterDeco.js +91 -0
  47. package/dist/cjs/decorations/viewDecorations.js +155 -0
  48. package/dist/cjs/dom.js +147 -0
  49. package/dist/cjs/findDOMNode.js +46 -0
  50. package/dist/cjs/hooks/useClientLayoutEffect.js +19 -0
  51. package/dist/cjs/hooks/useComponentEventListeners.js +72 -0
  52. package/dist/cjs/hooks/useEditor.js +130 -0
  53. package/dist/cjs/hooks/useEditorEffect.js +39 -0
  54. package/dist/cjs/hooks/useEditorEventCallback.js +38 -0
  55. package/dist/cjs/hooks/useEditorEventListener.js +34 -0
  56. package/dist/cjs/hooks/useEditorState.js +18 -0
  57. package/dist/cjs/hooks/useEditorStateSelector.js +17 -0
  58. package/dist/cjs/hooks/useEffectEvent.js +34 -0
  59. package/dist/cjs/hooks/useForceUpdate.js +15 -0
  60. package/dist/cjs/hooks/useIgnoreMutation.js +24 -0
  61. package/dist/cjs/hooks/useIsComposingIn.js +25 -0
  62. package/dist/cjs/hooks/useIsEditorStatic.js +15 -0
  63. package/dist/cjs/hooks/useIsNodeSelected.js +21 -0
  64. package/dist/cjs/hooks/useLayoutGroupEffect.js +20 -0
  65. package/dist/cjs/hooks/useMarkViewDescription.js +134 -0
  66. package/dist/cjs/hooks/useNodePos.js +18 -0
  67. package/dist/cjs/hooks/useNodeViewDescription.js +154 -0
  68. package/dist/cjs/hooks/useReactKeys.js +17 -0
  69. package/dist/cjs/hooks/useSelectNode.js +30 -0
  70. package/dist/cjs/hooks/useSetDom.js +57 -0
  71. package/dist/cjs/hooks/useStopEvent.js +24 -0
  72. package/dist/cjs/index.js +85 -0
  73. package/dist/cjs/package.json +3 -0
  74. package/dist/cjs/plugins/beforeInputPlugin.js +356 -0
  75. package/dist/cjs/plugins/reactKeys.js +121 -0
  76. package/dist/cjs/props.js +283 -0
  77. package/dist/cjs/refs.js +28 -0
  78. package/dist/cjs/testing/editorViewTestHelpers.js +109 -0
  79. package/dist/cjs/testing/setupProseMirrorView.js +94 -0
  80. package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +26 -0
  81. package/dist/cjs/tiptap/TiptapEditor.js +34 -0
  82. package/dist/cjs/tiptap/TiptapEditorContent.js +143 -0
  83. package/dist/cjs/tiptap/TiptapEditorView.js +130 -0
  84. package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +12 -0
  85. package/dist/cjs/tiptap/extensions/ReactProseMirror.js +40 -0
  86. package/dist/cjs/tiptap/extensions/ReactProseMirrorCommands.js +21 -0
  87. package/dist/cjs/tiptap/extensions/commands/updateAttributes.js +104 -0
  88. package/dist/cjs/tiptap/hooks/useEditor.js +318 -0
  89. package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +15 -0
  90. package/dist/cjs/tiptap/hooks/useTiptapEditor.js +35 -0
  91. package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +35 -0
  92. package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +35 -0
  93. package/dist/cjs/tiptap/index.js +48 -0
  94. package/dist/cjs/tiptap/tiptapNodeView.js +245 -0
  95. package/dist/cjs/viewdesc.js +862 -0
  96. package/dist/esm/AbstractEditorView.js +1 -0
  97. package/dist/esm/ReactEditorView.js +194 -0
  98. package/dist/esm/StaticEditorView.js +79 -0
  99. package/dist/esm/browser.js +43 -0
  100. package/dist/esm/commands/reorderSiblings.js +63 -0
  101. package/dist/esm/components/ChildNodeViews.js +359 -0
  102. package/dist/esm/components/CursorWrapper.js +33 -0
  103. package/dist/esm/components/EditorStateSelectorsProvider.js +31 -0
  104. package/dist/esm/components/LayoutGroup.js +67 -0
  105. package/dist/esm/components/NativeWidgetView.js +57 -0
  106. package/dist/esm/components/OutputSpec.js +71 -0
  107. package/dist/esm/components/ProseMirror.js +95 -0
  108. package/dist/esm/components/ProseMirrorDoc.js +15 -0
  109. package/dist/esm/components/SeparatorHackView.js +48 -0
  110. package/dist/esm/components/TextNodeView.js +103 -0
  111. package/dist/esm/components/TrailingHackView.js +36 -0
  112. package/dist/esm/components/WidgetView.js +43 -0
  113. package/dist/esm/components/WidgetViewComponentProps.js +1 -0
  114. package/dist/esm/components/marks/DefaultMarkView.js +19 -0
  115. package/dist/esm/components/marks/MarkView.js +34 -0
  116. package/dist/esm/components/marks/MarkViewComponentProps.js +1 -0
  117. package/dist/esm/components/marks/MarkViewConstructorView.js +65 -0
  118. package/dist/esm/components/marks/ReactMarkView.js +58 -0
  119. package/dist/esm/components/nodes/DefaultNodeView.js +17 -0
  120. package/dist/esm/components/nodes/DocNodeView.js +46 -0
  121. package/dist/esm/components/nodes/NodeView.js +67 -0
  122. package/dist/esm/components/nodes/NodeViewComponentProps.js +1 -0
  123. package/dist/esm/components/nodes/NodeViewConstructorView.js +94 -0
  124. package/dist/esm/components/nodes/ReactNodeView.js +138 -0
  125. package/dist/esm/constants.js +15 -0
  126. package/dist/esm/contexts/ChildDescriptionsContext.js +9 -0
  127. package/dist/esm/contexts/EditorContext.js +7 -0
  128. package/dist/esm/contexts/EditorStateContext.js +2 -0
  129. package/dist/esm/contexts/EditorStateStoreContext.js +27 -0
  130. package/dist/esm/contexts/IgnoreMutationContext.js +2 -0
  131. package/dist/esm/contexts/LayoutGroupContext.js +2 -0
  132. package/dist/esm/contexts/NodeViewContext.js +2 -0
  133. package/dist/esm/contexts/RenderStoreContext.js +33 -0
  134. package/dist/esm/contexts/SelectNodeContext.js +2 -0
  135. package/dist/esm/contexts/StopEventContext.js +2 -0
  136. package/dist/esm/decorations/ReactWidgetType.js +40 -0
  137. package/dist/esm/decorations/computeDocDeco.js +44 -0
  138. package/dist/esm/decorations/internalTypes.js +1 -0
  139. package/dist/esm/decorations/iterDeco.js +85 -0
  140. package/dist/esm/decorations/viewDecorations.js +155 -0
  141. package/dist/esm/dom.js +110 -0
  142. package/dist/esm/findDOMNode.js +31 -0
  143. package/dist/esm/hooks/useClientLayoutEffect.js +9 -0
  144. package/dist/esm/hooks/useComponentEventListeners.js +87 -0
  145. package/dist/esm/hooks/useEditor.js +128 -0
  146. package/dist/esm/hooks/useEditorEffect.js +46 -0
  147. package/dist/esm/hooks/useEditorEventCallback.js +38 -0
  148. package/dist/esm/hooks/useEditorEventListener.js +28 -0
  149. package/dist/esm/hooks/useEditorState.js +10 -0
  150. package/dist/esm/hooks/useEditorStateSelector.js +14 -0
  151. package/dist/esm/hooks/useEffectEvent.js +24 -0
  152. package/dist/esm/hooks/useForceUpdate.js +8 -0
  153. package/dist/esm/hooks/useIgnoreMutation.js +14 -0
  154. package/dist/esm/hooks/useIsComposingIn.js +17 -0
  155. package/dist/esm/hooks/useIsEditorStatic.js +8 -0
  156. package/dist/esm/hooks/useIsNodeSelected.js +11 -0
  157. package/dist/esm/hooks/useLayoutGroupEffect.js +10 -0
  158. package/dist/esm/hooks/useMarkViewDescription.js +124 -0
  159. package/dist/esm/hooks/useNodePos.js +15 -0
  160. package/dist/esm/hooks/useNodeViewDescription.js +144 -0
  161. package/dist/esm/hooks/useReactKeys.js +7 -0
  162. package/dist/esm/hooks/useSelectNode.js +20 -0
  163. package/dist/esm/hooks/useSetDom.js +47 -0
  164. package/dist/esm/hooks/useStopEvent.js +14 -0
  165. package/dist/esm/index.js +19 -0
  166. package/dist/esm/plugins/beforeInputPlugin.js +346 -0
  167. package/dist/esm/plugins/reactKeys.js +106 -0
  168. package/dist/esm/props.js +267 -0
  169. package/dist/esm/refs.js +18 -0
  170. package/dist/esm/testing/editorViewTestHelpers.js +86 -0
  171. package/dist/esm/testing/setupProseMirrorView.js +76 -0
  172. package/dist/esm/tiptap/ReactProseMirrorNodeView.js +22 -0
  173. package/dist/esm/tiptap/TiptapEditor.js +24 -0
  174. package/dist/esm/tiptap/TiptapEditorContent.js +99 -0
  175. package/dist/esm/tiptap/TiptapEditorView.js +76 -0
  176. package/dist/esm/tiptap/contexts/TiptapEditorContext.js +2 -0
  177. package/dist/esm/tiptap/extensions/ReactProseMirror.js +30 -0
  178. package/dist/esm/tiptap/extensions/ReactProseMirrorCommands.js +11 -0
  179. package/dist/esm/tiptap/extensions/commands/updateAttributes.js +96 -0
  180. package/dist/esm/tiptap/hooks/useEditor.js +308 -0
  181. package/dist/esm/tiptap/hooks/useIsInReactProseMirror.js +9 -0
  182. package/dist/esm/tiptap/hooks/useTiptapEditor.js +31 -0
  183. package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +42 -0
  184. package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +35 -0
  185. package/dist/esm/tiptap/index.js +9 -0
  186. package/dist/esm/tiptap/tiptapNodeView.js +211 -0
  187. package/dist/esm/viewdesc.js +844 -0
  188. package/dist/tsconfig.tsbuildinfo +1 -0
  189. package/dist/types/AbstractEditorView.d.ts +28 -0
  190. package/dist/types/ReactEditorView.d.ts +102 -0
  191. package/dist/types/StaticEditorView.d.ts +26 -0
  192. package/dist/types/__tests__/viewdesc.test.d.ts +1 -0
  193. package/dist/types/browser.d.ts +15 -0
  194. package/dist/types/commands/__tests__/reorderSiblings.test.d.ts +1 -0
  195. package/dist/types/commands/reorderSiblings.d.ts +14 -0
  196. package/dist/types/components/ChildNodeViews.d.ts +9 -0
  197. package/dist/types/components/CursorWrapper.d.ts +3 -0
  198. package/dist/types/components/EditorStateSelectorsProvider.d.ts +10 -0
  199. package/dist/types/components/LayoutGroup.d.ts +12 -0
  200. package/dist/types/components/NativeWidgetView.d.ts +8 -0
  201. package/dist/types/components/OutputSpec.d.ts +10 -0
  202. package/dist/types/components/ProseMirror.d.ts +14 -0
  203. package/dist/types/components/ProseMirrorDoc.d.ts +16 -0
  204. package/dist/types/components/SeparatorHackView.d.ts +6 -0
  205. package/dist/types/components/TextNodeView.d.ts +27 -0
  206. package/dist/types/components/TrailingHackView.d.ts +6 -0
  207. package/dist/types/components/WidgetView.d.ts +8 -0
  208. package/dist/types/components/WidgetViewComponentProps.d.ts +7 -0
  209. package/dist/types/components/__tests__/ProseMirror.composition.test.d.ts +17 -0
  210. package/dist/types/components/__tests__/ProseMirror.domchange.test.d.ts +1 -0
  211. package/dist/types/components/__tests__/ProseMirror.draw-decoration.test.d.ts +1 -0
  212. package/dist/types/components/__tests__/ProseMirror.draw.test.d.ts +1 -0
  213. package/dist/types/components/__tests__/ProseMirror.memory-leak.test.d.ts +6 -0
  214. package/dist/types/components/__tests__/ProseMirror.mobile.test.d.ts +1 -0
  215. package/dist/types/components/__tests__/ProseMirror.node-view.test.d.ts +1 -0
  216. package/dist/types/components/__tests__/ProseMirror.selection.test.d.ts +1 -0
  217. package/dist/types/components/__tests__/ProseMirror.test.d.ts +1 -0
  218. package/dist/types/components/__tests__/stableContexts.test.d.ts +10 -0
  219. package/dist/types/components/marks/DefaultMarkView.d.ts +3 -0
  220. package/dist/types/components/marks/MarkView.d.ts +10 -0
  221. package/dist/types/components/marks/MarkViewComponentProps.d.ts +11 -0
  222. package/dist/types/components/marks/MarkViewConstructorView.d.ts +12 -0
  223. package/dist/types/components/marks/ReactMarkView.d.ts +12 -0
  224. package/dist/types/components/nodes/DefaultNodeView.d.ts +3 -0
  225. package/dist/types/components/nodes/DocNodeView.d.ts +12 -0
  226. package/dist/types/components/nodes/NodeView.d.ts +14 -0
  227. package/dist/types/components/nodes/NodeViewComponentProps.d.ts +13 -0
  228. package/dist/types/components/nodes/NodeViewConstructorView.d.ts +12 -0
  229. package/dist/types/components/nodes/ReactNodeView.d.ts +13 -0
  230. package/dist/types/constants.d.ts +4 -0
  231. package/dist/types/contexts/ChildDescriptionsContext.d.ts +7 -0
  232. package/dist/types/contexts/EditorContext.d.ts +18 -0
  233. package/dist/types/contexts/EditorStateContext.d.ts +2 -0
  234. package/dist/types/contexts/EditorStateStoreContext.d.ts +9 -0
  235. package/dist/types/contexts/IgnoreMutationContext.d.ts +5 -0
  236. package/dist/types/contexts/LayoutGroupContext.d.ts +5 -0
  237. package/dist/types/contexts/NodeViewContext.d.ts +9 -0
  238. package/dist/types/contexts/RenderStoreContext.d.ts +24 -0
  239. package/dist/types/contexts/SelectNodeContext.d.ts +5 -0
  240. package/dist/types/contexts/StopEventContext.d.ts +5 -0
  241. package/dist/types/contexts/__tests__/DeferredLayoutEffects.test.d.ts +1 -0
  242. package/dist/types/decorations/ReactWidgetType.d.ts +40 -0
  243. package/dist/types/decorations/computeDocDeco.d.ts +14 -0
  244. package/dist/types/decorations/internalTypes.d.ts +20 -0
  245. package/dist/types/decorations/iterDeco.d.ts +3 -0
  246. package/dist/types/decorations/viewDecorations.d.ts +14 -0
  247. package/dist/types/dom.d.ts +22 -0
  248. package/dist/types/findDOMNode.d.ts +3 -0
  249. package/dist/types/hooks/__tests__/useEditorEffect.test.d.ts +1 -0
  250. package/dist/types/hooks/useClientLayoutEffect.d.ts +2 -0
  251. package/dist/types/hooks/useComponentEventListeners.d.ts +34 -0
  252. package/dist/types/hooks/useEditor.d.ts +37 -0
  253. package/dist/types/hooks/useEditorEffect.d.ts +21 -0
  254. package/dist/types/hooks/useEditorEventCallback.d.ts +13 -0
  255. package/dist/types/hooks/useEditorEventListener.d.ts +8 -0
  256. package/dist/types/hooks/useEditorState.d.ts +5 -0
  257. package/dist/types/hooks/useEditorStateSelector.d.ts +10 -0
  258. package/dist/types/hooks/useEffectEvent.d.ts +1 -0
  259. package/dist/types/hooks/useForceUpdate.d.ts +5 -0
  260. package/dist/types/hooks/useIgnoreMutation.d.ts +2 -0
  261. package/dist/types/hooks/useIsComposingIn.d.ts +4 -0
  262. package/dist/types/hooks/useIsEditorStatic.d.ts +5 -0
  263. package/dist/types/hooks/useIsNodeSelected.d.ts +1 -0
  264. package/dist/types/hooks/useLayoutGroupEffect.d.ts +3 -0
  265. package/dist/types/hooks/useMarkViewDescription.d.ts +15 -0
  266. package/dist/types/hooks/useNodePos.d.ts +9 -0
  267. package/dist/types/hooks/useNodeViewDescription.d.ts +16 -0
  268. package/dist/types/hooks/useReactKeys.d.ts +2 -0
  269. package/dist/types/hooks/useSelectNode.d.ts +2 -0
  270. package/dist/types/hooks/useSetDom.d.ts +2 -0
  271. package/dist/types/hooks/useStopEvent.d.ts +2 -0
  272. package/dist/types/index.d.ts +21 -0
  273. package/dist/types/plugins/__tests__/reactKeys.test.d.ts +1 -0
  274. package/dist/types/plugins/beforeInputPlugin.d.ts +2 -0
  275. package/dist/types/plugins/reactKeys.d.ts +23 -0
  276. package/dist/types/props.d.ts +1173 -0
  277. package/dist/types/refs.d.ts +2 -0
  278. package/dist/types/testing/editorViewTestHelpers.d.ts +24 -0
  279. package/dist/types/testing/setupProseMirrorView.d.ts +2 -0
  280. package/dist/types/tiptap/ReactProseMirrorNodeView.d.ts +15 -0
  281. package/dist/types/tiptap/TiptapEditor.d.ts +6 -0
  282. package/dist/types/tiptap/TiptapEditorContent.d.ts +28 -0
  283. package/dist/types/tiptap/TiptapEditorView.d.ts +16 -0
  284. package/dist/types/tiptap/contexts/TiptapEditorContext.d.ts +6 -0
  285. package/dist/types/tiptap/extensions/ReactProseMirror.d.ts +9 -0
  286. package/dist/types/tiptap/extensions/ReactProseMirrorCommands.d.ts +2 -0
  287. package/dist/types/tiptap/extensions/commands/updateAttributes.d.ts +24 -0
  288. package/dist/types/tiptap/hooks/useEditor.d.ts +38 -0
  289. package/dist/types/tiptap/hooks/useIsInReactProseMirror.d.ts +6 -0
  290. package/dist/types/tiptap/hooks/useTiptapEditor.d.ts +11 -0
  291. package/dist/types/tiptap/hooks/useTiptapEditorEffect.d.ts +21 -0
  292. package/dist/types/tiptap/hooks/useTiptapEditorEventCallback.d.ts +13 -0
  293. package/dist/types/tiptap/index.d.ts +9 -0
  294. package/dist/types/tiptap/tiptapNodeView.d.ts +50 -0
  295. package/dist/types/viewdesc.d.ts +179 -0
  296. package/package.json +167 -0
@@ -0,0 +1,318 @@
1
+ // Forked from Tiptap's useEditor hook, with modifications to support
2
+ // server-side rendering
3
+ "use strict";
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "useEditor", {
8
+ enumerable: true,
9
+ get: function() {
10
+ return useEditor;
11
+ }
12
+ });
13
+ const _core = require("@tiptap/core");
14
+ const _react = require("react");
15
+ const _index = require("use-sync-external-store/shim/index.js");
16
+ const _StaticEditorView = require("../../StaticEditorView.js");
17
+ let ReactEditor = class ReactEditor extends _core.Editor {
18
+ constructor(options){
19
+ super(options);
20
+ // @ts-expect-error Internal property
21
+ this.editorView = new _StaticEditorView.StaticEditorView({
22
+ // @ts-expect-error Internal property
23
+ state: this.editorState.reconfigure({
24
+ plugins: this.extensionManager.plugins
25
+ }),
26
+ ...this.options.editorProps,
27
+ attributes: {
28
+ role: "textbox",
29
+ ...this.options.editorProps.attributes
30
+ }
31
+ });
32
+ }
33
+ };
34
+ /**
35
+ * This class handles the creation, destruction, and re-creation of the editor instance.
36
+ */ let EditorInstanceManager = class EditorInstanceManager {
37
+ /**
38
+ * The current editor instance.
39
+ */ editor = null;
40
+ /**
41
+ * The most recent options to apply to the editor.
42
+ */ options;
43
+ /**
44
+ * The subscriptions to notify when the editor instance
45
+ * has been created or destroyed.
46
+ */ subscriptions = new Set();
47
+ /**
48
+ * A timeout to destroy the editor if it was not mounted within a time frame.
49
+ */ scheduledDestructionTimeout;
50
+ /**
51
+ * Whether the editor has been mounted.
52
+ */ isComponentMounted = false;
53
+ /**
54
+ * The most recent dependencies array.
55
+ */ previousDeps = null;
56
+ /**
57
+ * The unique instance ID. This is used to identify the editor instance. And will be re-generated for each new instance.
58
+ */ instanceId = "";
59
+ constructor(options){
60
+ this.options = options;
61
+ this.subscriptions = new Set();
62
+ this.setEditor(this.createEditor());
63
+ this.scheduleDestroy();
64
+ this.getEditor = this.getEditor.bind(this);
65
+ this.getServerSnapshot = this.getServerSnapshot.bind(this);
66
+ this.subscribe = this.subscribe.bind(this);
67
+ this.refreshEditorInstance = this.refreshEditorInstance.bind(this);
68
+ this.scheduleDestroy = this.scheduleDestroy.bind(this);
69
+ this.onRender = this.onRender.bind(this);
70
+ this.createEditor = this.createEditor.bind(this);
71
+ }
72
+ setEditor(editor) {
73
+ this.editor = editor;
74
+ this.instanceId = Math.random().toString(36).slice(2, 9);
75
+ // Notify all subscribers that the editor instance has been created
76
+ this.subscriptions.forEach((cb)=>cb());
77
+ }
78
+ /**
79
+ * Create a new editor instance. And attach event listeners.
80
+ */ createEditor() {
81
+ var _this = this;
82
+ const optionsToApply = {
83
+ ...this.options.current,
84
+ // Always call the most recent version of the callback function by default
85
+ onBeforeCreate: function() {
86
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
87
+ args[_key] = arguments[_key];
88
+ }
89
+ return _this.options.current.onBeforeCreate?.(...args);
90
+ },
91
+ onBlur: function() {
92
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
93
+ args[_key] = arguments[_key];
94
+ }
95
+ return _this.options.current.onBlur?.(...args);
96
+ },
97
+ onCreate: function() {
98
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
99
+ args[_key] = arguments[_key];
100
+ }
101
+ return _this.options.current.onCreate?.(...args);
102
+ },
103
+ onDestroy: function() {
104
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
105
+ args[_key] = arguments[_key];
106
+ }
107
+ return _this.options.current.onDestroy?.(...args);
108
+ },
109
+ onFocus: function() {
110
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
111
+ args[_key] = arguments[_key];
112
+ }
113
+ return _this.options.current.onFocus?.(...args);
114
+ },
115
+ onSelectionUpdate: function() {
116
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
117
+ args[_key] = arguments[_key];
118
+ }
119
+ return _this.options.current.onSelectionUpdate?.(...args);
120
+ },
121
+ onTransaction: function() {
122
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
123
+ args[_key] = arguments[_key];
124
+ }
125
+ return _this.options.current.onTransaction?.(...args);
126
+ },
127
+ onUpdate: function() {
128
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
129
+ args[_key] = arguments[_key];
130
+ }
131
+ return _this.options.current.onUpdate?.(...args);
132
+ },
133
+ onContentError: function() {
134
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
135
+ args[_key] = arguments[_key];
136
+ }
137
+ return _this.options.current.onContentError?.(...args);
138
+ },
139
+ onDrop: function() {
140
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
141
+ args[_key] = arguments[_key];
142
+ }
143
+ return _this.options.current.onDrop?.(...args);
144
+ },
145
+ onPaste: function() {
146
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
147
+ args[_key] = arguments[_key];
148
+ }
149
+ return _this.options.current.onPaste?.(...args);
150
+ },
151
+ onDelete: function() {
152
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
153
+ args[_key] = arguments[_key];
154
+ }
155
+ return _this.options.current.onDelete?.(...args);
156
+ }
157
+ };
158
+ const editor = new ReactEditor(optionsToApply);
159
+ // no need to keep track of the event listeners, they will be removed when the editor is destroyed
160
+ return editor;
161
+ }
162
+ /**
163
+ * Get the current editor instance.
164
+ */ getEditor() {
165
+ return this.editor;
166
+ }
167
+ // ----- FORKED CHANGES -----
168
+ /**
169
+ * Always disable the editor on the server-side.
170
+ */ getServerSnapshot() {
171
+ // return null;
172
+ // Return editor in SSRm, contrary to Tiptap's implementation
173
+ return this.editor;
174
+ }
175
+ // ----- END FORKED CHANGES -----
176
+ /**
177
+ * Subscribe to the editor instance's changes.
178
+ */ subscribe(onStoreChange) {
179
+ this.subscriptions.add(onStoreChange);
180
+ return ()=>{
181
+ this.subscriptions.delete(onStoreChange);
182
+ };
183
+ }
184
+ static compareOptions(a, b) {
185
+ return Object.keys(a).every((key)=>{
186
+ if ([
187
+ "onCreate",
188
+ "onBeforeCreate",
189
+ "onDestroy",
190
+ "onUpdate",
191
+ "onTransaction",
192
+ "onFocus",
193
+ "onBlur",
194
+ "onSelectionUpdate",
195
+ "onContentError",
196
+ "onDrop",
197
+ "onPaste"
198
+ ].includes(key)) {
199
+ // we don't want to compare callbacks, they are always different and only registered once
200
+ return true;
201
+ }
202
+ // We often encourage putting extensions inlined in the options object, so we will do a slightly deeper comparison here
203
+ if (key === "extensions" && a.extensions && b.extensions) {
204
+ if (a.extensions.length !== b.extensions.length) {
205
+ return false;
206
+ }
207
+ return a.extensions.every((extension, index)=>{
208
+ if (extension !== b.extensions?.[index]) {
209
+ return false;
210
+ }
211
+ return true;
212
+ });
213
+ }
214
+ if (a[key] !== b[key]) {
215
+ // if any of the options have changed, we should update the editor options
216
+ return false;
217
+ }
218
+ return true;
219
+ });
220
+ }
221
+ /**
222
+ * On each render, we will create, update, or destroy the editor instance.
223
+ * @param deps The dependencies to watch for changes
224
+ * @returns A cleanup function
225
+ */ onRender(deps) {
226
+ // The returned callback will run on each render
227
+ return ()=>{
228
+ this.isComponentMounted = true;
229
+ // Cleanup any scheduled destructions, since we are currently rendering
230
+ clearTimeout(this.scheduledDestructionTimeout);
231
+ if (this.editor && !this.editor.isDestroyed && deps.length === 0) {
232
+ // if the editor does exist & deps are empty, we don't need to re-initialize the editor generally
233
+ if (!EditorInstanceManager.compareOptions(this.options.current, this.editor.options)) {
234
+ // But, the options are different, so we need to update the editor options
235
+ // Still, this is faster than re-creating the editor
236
+ this.editor.setOptions({
237
+ ...this.options.current,
238
+ editable: this.editor.isEditable
239
+ });
240
+ }
241
+ } else {
242
+ // When the editor:
243
+ // - does not yet exist
244
+ // - is destroyed
245
+ // - the deps array changes
246
+ // We need to destroy the editor instance and re-initialize it
247
+ this.refreshEditorInstance(deps);
248
+ }
249
+ return ()=>{
250
+ this.isComponentMounted = false;
251
+ this.scheduleDestroy();
252
+ };
253
+ };
254
+ }
255
+ /**
256
+ * Recreate the editor instance if the dependencies have changed.
257
+ */ refreshEditorInstance(deps) {
258
+ if (this.editor && !this.editor.isDestroyed) {
259
+ // Editor instance already exists
260
+ if (this.previousDeps === null) {
261
+ // If lastDeps has not yet been initialized, reuse the current editor instance
262
+ this.previousDeps = deps;
263
+ return;
264
+ }
265
+ const depsAreEqual = this.previousDeps.length === deps.length && this.previousDeps.every((dep, index)=>dep === deps[index]);
266
+ if (depsAreEqual) {
267
+ // deps exist and are equal, no need to recreate
268
+ return;
269
+ }
270
+ }
271
+ if (this.editor && !this.editor.isDestroyed) {
272
+ // Destroy the editor instance if it exists
273
+ this.editor.destroy();
274
+ }
275
+ this.setEditor(this.createEditor());
276
+ // Update the lastDeps to the current deps
277
+ this.previousDeps = deps;
278
+ }
279
+ /**
280
+ * Schedule the destruction of the editor instance.
281
+ * This will only destroy the editor if it was not mounted on the next tick.
282
+ * This is to avoid destroying the editor instance when it's actually still mounted.
283
+ */ scheduleDestroy() {
284
+ const currentInstanceId = this.instanceId;
285
+ const currentEditor = this.editor;
286
+ // Wait two ticks to see if the component is still mounted
287
+ this.scheduledDestructionTimeout = setTimeout(()=>{
288
+ if (this.isComponentMounted && this.instanceId === currentInstanceId) {
289
+ // If still mounted on the following tick, with the same instanceId, do not destroy the editor
290
+ if (currentEditor) {
291
+ // just re-apply options as they might have changed
292
+ currentEditor.setOptions(this.options.current);
293
+ }
294
+ return;
295
+ }
296
+ if (currentEditor && !currentEditor.isDestroyed) {
297
+ currentEditor.destroy();
298
+ if (this.instanceId === currentInstanceId) {
299
+ this.setEditor(null);
300
+ }
301
+ }
302
+ // This allows the effect to run again between ticks
303
+ // which may save us from having to re-create the editor
304
+ }, 1);
305
+ }
306
+ };
307
+ function useEditor() {
308
+ let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, deps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
309
+ const mostRecentOptions = (0, _react.useRef)(options);
310
+ mostRecentOptions.current = options;
311
+ const [instanceManager] = (0, _react.useState)(()=>new EditorInstanceManager(mostRecentOptions));
312
+ const editor = (0, _index.useSyncExternalStore)(instanceManager.subscribe, instanceManager.getEditor, instanceManager.getServerSnapshot);
313
+ (0, _react.useDebugValue)(editor);
314
+ // This effect will handle creating/updating the editor instance
315
+ // eslint-disable-next-line react-hooks/exhaustive-deps
316
+ (0, _react.useEffect)(instanceManager.onRender(deps));
317
+ return editor;
318
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useIsInReactProseMirror", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useIsInReactProseMirror;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const _EditorContext = require("../../contexts/EditorContext.js");
13
+ function useIsInReactProseMirror() {
14
+ return (0, _react.useContext)(_EditorContext.EditorContext) !== null;
15
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useTiptapEditor", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useTiptapEditor;
9
+ }
10
+ });
11
+ const _ReactProseMirror = require("../extensions/ReactProseMirror.js");
12
+ const _ReactProseMirrorCommands = require("../extensions/ReactProseMirrorCommands.js");
13
+ const _useEditor = require("./useEditor.js");
14
+ function useTiptapEditor(options, deps) {
15
+ const extensions = [
16
+ _ReactProseMirror.ReactProseMirror,
17
+ ...options.extensions ?? []
18
+ ];
19
+ // If a consumer explicitly disables core extensions (or the Commands core extension)
20
+ // do not re-add our custom Commands
21
+ if (options.enableCoreExtensions === false || typeof options.enableCoreExtensions === "object" && options?.enableCoreExtensions?.commands === false) {
22
+ // Do nothing
23
+ } else {
24
+ options.enableCoreExtensions = {
25
+ ...typeof options.enableCoreExtensions === "object" ? options.enableCoreExtensions : {},
26
+ commands: false
27
+ };
28
+ extensions.push(_ReactProseMirrorCommands.ReactProseMirrorCommands);
29
+ }
30
+ return (0, _useEditor.useEditor)({
31
+ ...options,
32
+ extensions,
33
+ element: null
34
+ }, deps);
35
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useTiptapEditorEffect", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useTiptapEditorEffect;
9
+ }
10
+ });
11
+ const _react = require("@tiptap/react");
12
+ const _react1 = require("react");
13
+ const _ReactEditorView = require("../../ReactEditorView.js");
14
+ const _EditorContext = require("../../contexts/EditorContext.js");
15
+ const _useEditorEffect = require("../../hooks/useEditorEffect.js");
16
+ const _TiptapEditorContext = require("../contexts/TiptapEditorContext.js");
17
+ function useTiptapEditorEffect(effect, dependencies) {
18
+ const { view } = (0, _react1.useContext)(_EditorContext.EditorContext);
19
+ const { editor } = (0, _react.useCurrentEditor)();
20
+ const { isEditorInitialized } = (0, _react1.useContext)(_TiptapEditorContext.TiptapEditorContext);
21
+ (0, _useEditorEffect.useEditorEffect)(()=>{
22
+ if (editor?.view instanceof _ReactEditorView.ReactEditorView && view instanceof _ReactEditorView.ReactEditorView && isEditorInitialized) {
23
+ return effect(editor);
24
+ }
25
+ // The rules of hooks want to be able to statically
26
+ // verify the dependencies for the effect, but this will
27
+ // have already happened at the call-site.
28
+ // eslint-disable-next-line react-hooks/exhaustive-deps
29
+ }, dependencies && [
30
+ editor,
31
+ view,
32
+ isEditorInitialized,
33
+ ...dependencies
34
+ ]);
35
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useTiptapEditorEventCallback", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useTiptapEditorEventCallback;
9
+ }
10
+ });
11
+ const _react = require("@tiptap/react");
12
+ const _react1 = require("react");
13
+ const _useEditorEffect = require("../../hooks/useEditorEffect.js");
14
+ function assertEditor(editor) {
15
+ if (editor) return;
16
+ throw new DOMException("Tiptap Editor is not initialized", "InvalidStateError");
17
+ }
18
+ function useTiptapEditorEventCallback(callback) {
19
+ const ref = (0, _react1.useRef)(callback);
20
+ const { editor } = (0, _react.useCurrentEditor)();
21
+ (0, _useEditorEffect.useEditorEffect)(()=>{
22
+ ref.current = callback;
23
+ }, [
24
+ callback
25
+ ]);
26
+ return (0, _react1.useCallback)(function() {
27
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
28
+ args[_key] = arguments[_key];
29
+ }
30
+ assertEditor(editor);
31
+ return ref.current(editor, ...args);
32
+ }, [
33
+ editor
34
+ ]);
35
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ ReactProseMirror: function() {
13
+ return _ReactProseMirror.ReactProseMirror;
14
+ },
15
+ TiptapEditor: function() {
16
+ return _TiptapEditor.TiptapEditor;
17
+ },
18
+ TiptapEditorContent: function() {
19
+ return _TiptapEditorContent.TiptapEditorContent;
20
+ },
21
+ TiptapEditorView: function() {
22
+ return _TiptapEditorView.TiptapEditorView;
23
+ },
24
+ tiptapNodeView: function() {
25
+ return _tiptapNodeView.tiptapNodeView;
26
+ },
27
+ useIsInReactProseMirror: function() {
28
+ return _useIsInReactProseMirror.useIsInReactProseMirror;
29
+ },
30
+ useTiptapEditor: function() {
31
+ return _useTiptapEditor.useTiptapEditor;
32
+ },
33
+ useTiptapEditorEffect: function() {
34
+ return _useTiptapEditorEffect.useTiptapEditorEffect;
35
+ },
36
+ useTiptapEditorEventCallback: function() {
37
+ return _useTiptapEditorEventCallback.useTiptapEditorEventCallback;
38
+ }
39
+ });
40
+ const _tiptapNodeView = require("./tiptapNodeView.js");
41
+ const _TiptapEditorView = require("./TiptapEditorView.js");
42
+ const _TiptapEditorContent = require("./TiptapEditorContent.js");
43
+ const _useTiptapEditorEffect = require("./hooks/useTiptapEditorEffect.js");
44
+ const _useIsInReactProseMirror = require("./hooks/useIsInReactProseMirror.js");
45
+ const _useTiptapEditorEventCallback = require("./hooks/useTiptapEditorEventCallback.js");
46
+ const _TiptapEditor = require("./TiptapEditor.js");
47
+ const _useTiptapEditor = require("./hooks/useTiptapEditor.js");
48
+ const _ReactProseMirror = require("./extensions/ReactProseMirror.js");