@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,95 @@
1
+ import React, { useMemo, useRef, useState } from "react";
2
+ import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
3
+ import { EditorContext } from "../contexts/EditorContext.js";
4
+ import { EditorStateContext } from "../contexts/EditorStateContext.js";
5
+ import { NodeViewContext } from "../contexts/NodeViewContext.js";
6
+ import { RenderStoreContext } from "../contexts/RenderStoreContext.js";
7
+ import { computeDocDeco } from "../decorations/computeDocDeco.js";
8
+ import { viewDecorations } from "../decorations/viewDecorations.js";
9
+ import { useEditor } from "../hooks/useEditor.js";
10
+ import { EditorStateSelectorsProvider, EditorStateSelectorsRegistrar } from "./EditorStateSelectorsProvider.js";
11
+ import { LayoutGroup } from "./LayoutGroup.js";
12
+ import { DocNodeViewContext } from "./ProseMirrorDoc.js";
13
+ function getPos() {
14
+ return -1;
15
+ }
16
+ const rootChildDescriptionsContextValue = {
17
+ parentRef: {
18
+ current: undefined
19
+ },
20
+ siblingsRef: {
21
+ current: []
22
+ }
23
+ };
24
+ function ProseMirrorInner(param) {
25
+ let { children, nodeViewComponents, markViewComponents, ...props } = param;
26
+ const [mount, setMount] = useState(null);
27
+ const { editor, state, renderStore } = useEditor(mount, props);
28
+ const nodeViewConstructors = editor.view.nodeViews;
29
+ const nodeViewContextValue = useMemo(()=>{
30
+ return {
31
+ components: {
32
+ ...nodeViewComponents,
33
+ ...markViewComponents
34
+ },
35
+ constructors: nodeViewConstructors
36
+ };
37
+ }, [
38
+ markViewComponents,
39
+ nodeViewComponents,
40
+ nodeViewConstructors
41
+ ]);
42
+ const node = state.doc;
43
+ const decorations = computeDocDeco(editor.view);
44
+ const innerDecorations = viewDecorations(editor.view);
45
+ const docNodeViewContextValue = useMemo(()=>({
46
+ setMount,
47
+ node,
48
+ getPos,
49
+ decorations,
50
+ innerDecorations
51
+ }), [
52
+ node,
53
+ decorations,
54
+ innerDecorations
55
+ ]);
56
+ // An announced render keeps the previous context values: the consumers
57
+ // re-render through the store in this pass anyway. The flag is consumed
58
+ // here, so that a render the announcement did not cover (a transaction
59
+ // dispatched from a layout effect, say) changes the contexts again.
60
+ const contextValuesRef = useRef({
61
+ state,
62
+ doc: docNodeViewContextValue
63
+ });
64
+ if (renderStore) {
65
+ renderStore.state = state;
66
+ renderStore.doc = docNodeViewContextValue;
67
+ if (!renderStore.announced) {
68
+ contextValuesRef.current = {
69
+ state,
70
+ doc: docNodeViewContextValue
71
+ };
72
+ }
73
+ renderStore.announced = false;
74
+ }
75
+ const contextValues = renderStore ? contextValuesRef.current : {
76
+ state,
77
+ doc: docNodeViewContextValue
78
+ };
79
+ return /*#__PURE__*/ React.createElement(EditorContext.Provider, {
80
+ value: editor
81
+ }, /*#__PURE__*/ React.createElement(RenderStoreContext.Provider, {
82
+ value: renderStore
83
+ }, /*#__PURE__*/ React.createElement(EditorStateContext.Provider, {
84
+ value: contextValues.state
85
+ }, /*#__PURE__*/ React.createElement(EditorStateSelectorsProvider, null, /*#__PURE__*/ React.createElement(NodeViewContext.Provider, {
86
+ value: nodeViewContextValue
87
+ }, /*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
88
+ value: rootChildDescriptionsContextValue
89
+ }, /*#__PURE__*/ React.createElement(DocNodeViewContext.Provider, {
90
+ value: contextValues.doc
91
+ }, children)))))));
92
+ }
93
+ export function ProseMirror(props) {
94
+ return /*#__PURE__*/ React.createElement(LayoutGroup, null, /*#__PURE__*/ React.createElement(EditorStateSelectorsRegistrar, null, /*#__PURE__*/ React.createElement(ProseMirrorInner, props)));
95
+ }
@@ -0,0 +1,15 @@
1
+ import React, { createContext, forwardRef, useContext } from "react";
2
+ import { useRenderStore } from "../contexts/RenderStoreContext.js";
3
+ import { DocNodeView } from "./nodes/DocNodeView.js";
4
+ export const DocNodeViewContext = /*#__PURE__*/ createContext(null);
5
+ export const ProseMirrorDoc = /*#__PURE__*/ forwardRef(function ProseMirrorDoc(param, ref) {
6
+ let { as, ...props } = param;
7
+ const docProps = useContext(DocNodeViewContext);
8
+ const store = useRenderStore();
9
+ return /*#__PURE__*/ React.createElement(DocNodeView, {
10
+ ref: ref,
11
+ ...props,
12
+ ...store?.doc ?? docProps,
13
+ as: as
14
+ });
15
+ });
@@ -0,0 +1,48 @@
1
+ import React, { useContext, useRef, useState } from "react";
2
+ import { browser } from "../browser.js";
3
+ import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
4
+ import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
5
+ import { TrailingHackViewDesc, placeViewDesc } from "../viewdesc.js";
6
+ export function SeparatorHackView(param) {
7
+ let { getPos } = param;
8
+ const { siblingsRef, parentRef } = useContext(ChildDescriptionsContext);
9
+ const viewDescRef = useRef(null);
10
+ const ref = useRef(null);
11
+ const [shouldRender, setShouldRender] = useState(false);
12
+ useClientLayoutEffect(()=>{
13
+ const siblings = siblingsRef.current;
14
+ return ()=>{
15
+ if (!viewDescRef.current) return;
16
+ if (siblings.includes(viewDescRef.current)) {
17
+ const index = siblings.indexOf(viewDescRef.current);
18
+ siblings.splice(index, 1);
19
+ }
20
+ };
21
+ }, [
22
+ siblingsRef
23
+ ]);
24
+ // There's no risk of an infinite loop here, because
25
+ // we call setShouldRender conditionally
26
+ // eslint-disable-next-line react-hooks/exhaustive-deps
27
+ useClientLayoutEffect(()=>{
28
+ const nonHackSiblings = siblingsRef.current.filter((viewdesc)=>!(viewdesc instanceof TrailingHackViewDesc));
29
+ const lastSibling = nonHackSiblings[nonHackSiblings.length - 1];
30
+ if (!shouldRender && (browser.safari || browser.chrome) && lastSibling?.dom?.contentEditable == "false") {
31
+ setShouldRender(true);
32
+ return;
33
+ }
34
+ if (!ref.current) return;
35
+ if (!viewDescRef.current) {
36
+ viewDescRef.current = new TrailingHackViewDesc(parentRef.current, [], getPos, ref.current, null);
37
+ } else {
38
+ viewDescRef.current.parent = parentRef.current;
39
+ viewDescRef.current.dom = ref.current;
40
+ }
41
+ placeViewDesc(siblingsRef.current, viewDescRef.current);
42
+ });
43
+ return shouldRender ? /*#__PURE__*/ React.createElement("img", {
44
+ ref: ref,
45
+ className: "ProseMirror-separator",
46
+ alt: ""
47
+ }) : null;
48
+ }
@@ -0,0 +1,103 @@
1
+ import { DecorationSet } from "prosemirror-view";
2
+ import { Component, createRef } from "react";
3
+ import { ReactEditorView } from "../ReactEditorView.js";
4
+ import { findDOMNode } from "../findDOMNode.js";
5
+ import { TextViewDesc, placeViewDesc } from "../viewdesc.js";
6
+ import { wrapInDeco } from "./ChildNodeViews.js";
7
+ function shallowEqual(objA, objB) {
8
+ if (objA === objB) {
9
+ return true;
10
+ }
11
+ if (!objA || !objB) {
12
+ return false;
13
+ }
14
+ const aKeys = Object.keys(objA);
15
+ const bKeys = Object.keys(objB);
16
+ const len = aKeys.length;
17
+ if (bKeys.length !== len) {
18
+ return false;
19
+ }
20
+ for(let i = 0; i < len; i++){
21
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22
+ const key = aKeys[i];
23
+ if (objA[key] !== objB[key] || !Object.prototype.hasOwnProperty.call(objB, key)) {
24
+ return false;
25
+ }
26
+ }
27
+ return true;
28
+ }
29
+ export class TextNodeView extends Component {
30
+ viewDescRef = createMutRef();
31
+ create() {
32
+ const { view, decorations, siblingsRef, parentRef, getPos, node } = this.props;
33
+ const dom = findDOMNode(this);
34
+ if (!dom && !view.composing) return null;
35
+ let textNode = dom;
36
+ while(textNode?.firstChild){
37
+ textNode = textNode.firstChild;
38
+ }
39
+ if (!(textNode instanceof Text)) {
40
+ textNode = null;
41
+ }
42
+ if (!dom || !textNode) return null;
43
+ const viewDesc = new TextViewDesc(parentRef.current, [], getPos, node, decorations, DecorationSet.empty, dom, textNode);
44
+ placeViewDesc(siblingsRef.current, viewDesc);
45
+ return viewDesc;
46
+ }
47
+ update() {
48
+ const { view, node, decorations } = this.props;
49
+ if (!(view instanceof ReactEditorView)) return false;
50
+ const viewDesc = this.viewDescRef.current;
51
+ if (!viewDesc) return false;
52
+ const dom = findDOMNode(this);
53
+ if (!dom || dom !== viewDesc.dom) return false;
54
+ if (!dom.contains(viewDesc.nodeDOM)) return false;
55
+ return viewDesc.matchesNode(node, decorations, DecorationSet.empty) || viewDesc.update(node, decorations, DecorationSet.empty, view);
56
+ }
57
+ destroy() {
58
+ const viewDesc = this.viewDescRef.current;
59
+ if (!viewDesc) return;
60
+ viewDesc.destroy();
61
+ const siblings = this.props.siblingsRef.current;
62
+ if (siblings.includes(viewDesc)) {
63
+ const index = siblings.indexOf(viewDesc);
64
+ siblings.splice(index, 1);
65
+ }
66
+ }
67
+ updateEffect() {
68
+ if (!this.update()) {
69
+ this.destroy();
70
+ this.viewDescRef.current = this.create();
71
+ }
72
+ }
73
+ shouldComponentUpdate(nextProps) {
74
+ return !shallowEqual(this.props, nextProps);
75
+ }
76
+ constructor(props){
77
+ super(props);
78
+ this.viewDescRef.current = null;
79
+ }
80
+ componentDidMount() {
81
+ this.viewDescRef.current = this.create();
82
+ this.updateEffect();
83
+ }
84
+ componentDidUpdate() {
85
+ this.updateEffect();
86
+ const { view } = this.props;
87
+ if (!(view instanceof ReactEditorView)) return;
88
+ }
89
+ componentWillUnmount() {
90
+ this.destroy();
91
+ }
92
+ render() {
93
+ const { node, decorations } = this.props;
94
+ return decorations.reduce(wrapInDeco, node.text);
95
+ }
96
+ }
97
+ /**
98
+ * createRef returns a RefObject, even though the docs
99
+ * say that it's acceptible to manage the ref's value
100
+ * yourself.
101
+ */ function createMutRef() {
102
+ return /*#__PURE__*/ createRef();
103
+ }
@@ -0,0 +1,36 @@
1
+ import React, { useContext, useRef } from "react";
2
+ import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
3
+ import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
4
+ import { TrailingHackViewDesc, placeViewDesc } from "../viewdesc.js";
5
+ export function TrailingHackView(param) {
6
+ let { getPos } = param;
7
+ const { siblingsRef, parentRef } = useContext(ChildDescriptionsContext);
8
+ const viewDescRef = useRef(null);
9
+ const ref = useRef(null);
10
+ useClientLayoutEffect(()=>{
11
+ const siblings = siblingsRef.current;
12
+ return ()=>{
13
+ if (!viewDescRef.current) return;
14
+ if (siblings.includes(viewDescRef.current)) {
15
+ const index = siblings.indexOf(viewDescRef.current);
16
+ siblings.splice(index, 1);
17
+ }
18
+ };
19
+ }, [
20
+ siblingsRef
21
+ ]);
22
+ useClientLayoutEffect(()=>{
23
+ if (!ref.current) return;
24
+ if (!viewDescRef.current) {
25
+ viewDescRef.current = new TrailingHackViewDesc(parentRef.current, [], getPos, ref.current, null);
26
+ } else {
27
+ viewDescRef.current.parent = parentRef.current;
28
+ viewDescRef.current.dom = ref.current;
29
+ }
30
+ placeViewDesc(siblingsRef.current, viewDescRef.current);
31
+ });
32
+ return /*#__PURE__*/ React.createElement("br", {
33
+ ref: ref,
34
+ className: "ProseMirror-trailingBreak"
35
+ });
36
+ }
@@ -0,0 +1,43 @@
1
+ import React, { useContext, useRef } from "react";
2
+ import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
3
+ import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
4
+ import { WidgetViewDesc, placeViewDesc } from "../viewdesc.js";
5
+ export function WidgetView(param) {
6
+ let { widget, getPos } = param;
7
+ const { siblingsRef, parentRef } = useContext(ChildDescriptionsContext);
8
+ const viewDescRef = useRef(null);
9
+ const domRef = useRef(null);
10
+ useClientLayoutEffect(()=>{
11
+ const siblings = siblingsRef.current;
12
+ return ()=>{
13
+ if (!viewDescRef.current) return;
14
+ if (siblings.includes(viewDescRef.current)) {
15
+ const index = siblings.indexOf(viewDescRef.current);
16
+ siblings.splice(index, 1);
17
+ }
18
+ };
19
+ }, [
20
+ siblingsRef
21
+ ]);
22
+ useClientLayoutEffect(()=>{
23
+ if (!domRef.current) return;
24
+ if (!viewDescRef.current) {
25
+ viewDescRef.current = new WidgetViewDesc(parentRef.current, getPos, widget, domRef.current);
26
+ } else {
27
+ viewDescRef.current.parent = parentRef.current;
28
+ viewDescRef.current.widget = widget;
29
+ viewDescRef.current.dom = domRef.current;
30
+ viewDescRef.current.dom.pmViewDesc = viewDescRef.current;
31
+ }
32
+ placeViewDesc(siblingsRef.current, viewDescRef.current);
33
+ });
34
+ const { Component } = widget.type;
35
+ return Component && /*#__PURE__*/ React.createElement(Component, {
36
+ ref: domRef,
37
+ widget: widget,
38
+ getPos: getPos,
39
+ ...!widget.type.spec.raw && {
40
+ contentEditable: false
41
+ }
42
+ });
43
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,19 @@
1
+ import React, { forwardRef, useMemo } from "react";
2
+ import { OutputSpec } from "../OutputSpec.js";
3
+ export const DefaultMarkView = /*#__PURE__*/ forwardRef(function DefaultMarkView(param, ref) {
4
+ let { markProps: { mark, inline, contentDOMRef }, children, ...props } = param;
5
+ const spec = useMemo(()=>mark.type.spec.toDOM?.(mark, inline), [
6
+ mark,
7
+ inline
8
+ ]);
9
+ if (!spec) {
10
+ throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
11
+ }
12
+ return /*#__PURE__*/ React.createElement(OutputSpec, {
13
+ ...props,
14
+ outputSpec: spec,
15
+ contentDOMRef: contentDOMRef,
16
+ ref: ref,
17
+ isMark: true
18
+ }, children);
19
+ });
@@ -0,0 +1,34 @@
1
+ import React, { memo, useContext, useMemo } from "react";
2
+ import { NodeViewContext } from "../../contexts/NodeViewContext.js";
3
+ import { DefaultMarkView } from "./DefaultMarkView.js";
4
+ import { MarkViewConstructorView } from "./MarkViewConstructorView.js";
5
+ import { ReactMarkView } from "./ReactMarkView.js";
6
+ export const MarkView = /*#__PURE__*/ memo(function MarkView(props) {
7
+ const { components, constructors } = useContext(NodeViewContext);
8
+ const component = components[props.mark.type.name] ?? DefaultMarkView;
9
+ const constructor = constructors[props.mark.type.name];
10
+ // Construct a wrapper component so that the mark view remounts when either
11
+ // its component or constructor changes. A React mark view would remount
12
+ // if its underlying component changed without this wrapper, but a custom
13
+ // mark view otherwise uses the same React components for all custom mark views.
14
+ const Component = useMemo(()=>{
15
+ if (constructor) {
16
+ return function MarkView(props) {
17
+ return /*#__PURE__*/ React.createElement(MarkViewConstructorView, {
18
+ constructor: constructor,
19
+ ...props
20
+ });
21
+ };
22
+ }
23
+ return function NodeView(props) {
24
+ return /*#__PURE__*/ React.createElement(ReactMarkView, {
25
+ component: component,
26
+ ...props
27
+ });
28
+ };
29
+ }, [
30
+ component,
31
+ constructor
32
+ ]);
33
+ return /*#__PURE__*/ React.createElement(Component, props);
34
+ });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,65 @@
1
+ import { DOMSerializer } from "prosemirror-model";
2
+ import React, { memo, useMemo, useRef } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { ChildDescriptionsContext } from "../../contexts/ChildDescriptionsContext.js";
5
+ import { useForceUpdate } from "../../hooks/useForceUpdate.js";
6
+ import { useMarkViewDescription } from "../../hooks/useMarkViewDescription.js";
7
+ export const MarkViewConstructorView = /*#__PURE__*/ memo(function MarkViewConstructorView(param) {
8
+ let { constructor, mark, inline, getPos, children } = param;
9
+ const ref = useRef(null);
10
+ const innerRef = useRef(null);
11
+ const forceUpdate = useForceUpdate();
12
+ const markProps = useMemo(()=>({
13
+ mark,
14
+ inline,
15
+ getPos,
16
+ contentDOMRef: {
17
+ current: null
18
+ }
19
+ }), [
20
+ mark,
21
+ inline,
22
+ getPos
23
+ ]);
24
+ const createMarkView = function() {
25
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
26
+ args[_key] = arguments[_key];
27
+ }
28
+ const markView = constructor(...args);
29
+ if (!markView || !markView.dom) {
30
+ const spec = mark.type.spec.toDOM?.(mark, inline);
31
+ if (!spec) {
32
+ throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
33
+ }
34
+ return DOMSerializer.renderSpec(document, spec, null);
35
+ }
36
+ return markView;
37
+ };
38
+ const { childContextValue, contentDOM } = useMarkViewDescription(()=>ref.current, (markView)=>markView?.contentDOM ?? null, function() {
39
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
40
+ args[_key] = arguments[_key];
41
+ }
42
+ const markView = createMarkView(...args);
43
+ const dom = markView.dom;
44
+ const wrapperDOM = innerRef.current ?? ref.current;
45
+ wrapperDOM.appendChild(dom);
46
+ // Force a re-render so that we properly create
47
+ // a portal into the contentDOM/dom
48
+ forceUpdate();
49
+ return {
50
+ ...markView,
51
+ destroy () {
52
+ markView.destroy?.();
53
+ wrapperDOM.removeChild(dom);
54
+ },
55
+ ignoreMutation: markView.ignoreMutation
56
+ };
57
+ }, markProps);
58
+ const Component = inline ? "span" : "div";
59
+ const props = {
60
+ ref: innerRef
61
+ };
62
+ return /*#__PURE__*/ React.createElement(Component, props, contentDOM ? /*#__PURE__*/ createPortal(/*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
63
+ value: childContextValue
64
+ }, children), contentDOM) : null);
65
+ });
@@ -0,0 +1,58 @@
1
+ import React, { memo, useCallback, useMemo, useRef } from "react";
2
+ import { ChildDescriptionsContext } from "../../contexts/ChildDescriptionsContext.js";
3
+ import { IgnoreMutationContext } from "../../contexts/IgnoreMutationContext.js";
4
+ import { useMarkViewDescription } from "../../hooks/useMarkViewDescription.js";
5
+ import { useSetDom } from "../../hooks/useSetDom.js";
6
+ export const ReactMarkView = /*#__PURE__*/ memo(function ReactMarkView(param) {
7
+ let { component: Component, mark, inline, getPos, children } = param;
8
+ const ref = useRef(null);
9
+ const contentDOMRef = useRef(null);
10
+ const ignoreMutationRef = useRef(null);
11
+ const setIgnoreMutation = useCallback((handler)=>{
12
+ ignoreMutationRef.current = handler;
13
+ return ()=>{
14
+ ignoreMutationRef.current = null;
15
+ return ()=>{
16
+ ignoreMutationRef.current = null;
17
+ };
18
+ };
19
+ }, []);
20
+ const markViewDescProps = useMemo(()=>({
21
+ mark,
22
+ getPos,
23
+ inline
24
+ }), [
25
+ getPos,
26
+ inline,
27
+ mark
28
+ ]);
29
+ const { childContextValue, refUpdated } = useMarkViewDescription(()=>ref.current, ()=>contentDOMRef.current ?? ref.current, ()=>({
30
+ dom: ref.current,
31
+ contentDOM: contentDOMRef.current ?? ref.current,
32
+ ignoreMutation (mutation) {
33
+ const ignoreMutation = ignoreMutationRef.current;
34
+ if (ignoreMutation) {
35
+ return ignoreMutation.call(this, mutation);
36
+ }
37
+ return false;
38
+ }
39
+ }), markViewDescProps);
40
+ const setDOM = useSetDom(ref, refUpdated);
41
+ const setContentDOM = useSetDom(contentDOMRef, refUpdated);
42
+ const markProps = useMemo(()=>({
43
+ ...markViewDescProps,
44
+ contentDOMRef: setContentDOM
45
+ }), [
46
+ markViewDescProps,
47
+ setContentDOM
48
+ ]);
49
+ const props = {
50
+ markProps,
51
+ ref: setDOM
52
+ };
53
+ return /*#__PURE__*/ React.createElement(IgnoreMutationContext.Provider, {
54
+ value: setIgnoreMutation
55
+ }, /*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
56
+ value: childContextValue
57
+ }, /*#__PURE__*/ React.createElement(Component, props, children)));
58
+ });
@@ -0,0 +1,17 @@
1
+ import React, { forwardRef, useMemo } from "react";
2
+ import { OutputSpec } from "../OutputSpec.js";
3
+ export const DefaultNodeView = /*#__PURE__*/ forwardRef(function DefaultNodeView(param, ref) {
4
+ let { nodeProps: { node, contentDOMRef }, children, ...props } = param;
5
+ const spec = useMemo(()=>node.type.spec.toDOM?.(node), [
6
+ node
7
+ ]);
8
+ if (!spec) {
9
+ throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
10
+ }
11
+ return /*#__PURE__*/ React.createElement(OutputSpec, {
12
+ ...props,
13
+ outputSpec: spec,
14
+ ref: ref,
15
+ contentDOMRef: contentDOMRef
16
+ }, children);
17
+ });
@@ -0,0 +1,46 @@
1
+ import React, { createElement, forwardRef, memo, useImperativeHandle, useMemo, useRef } from "react";
2
+ import { ChildDescriptionsContext } from "../../contexts/ChildDescriptionsContext.js";
3
+ import { useNodeViewDescription } from "../../hooks/useNodeViewDescription.js";
4
+ import { ChildNodeViews, wrapInDeco } from "../ChildNodeViews.js";
5
+ export const DocNodeView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function DocNodeView(param, ref) {
6
+ let { as, node, getPos, decorations, innerDecorations, setMount, ...elementProps } = param;
7
+ const innerRef = useRef(null);
8
+ useImperativeHandle(ref, ()=>innerRef.current);
9
+ useImperativeHandle(setMount, ()=>innerRef.current);
10
+ const nodeProps = useMemo(()=>({
11
+ node,
12
+ getPos,
13
+ decorations,
14
+ innerDecorations,
15
+ contentDOMRef: innerRef
16
+ }), [
17
+ node,
18
+ getPos,
19
+ decorations,
20
+ innerDecorations
21
+ ]);
22
+ const { childContextValue } = useNodeViewDescription(()=>innerRef.current, ()=>innerRef.current, ()=>{
23
+ const dom = innerRef.current;
24
+ return {
25
+ dom,
26
+ contentDOM: dom,
27
+ update () {
28
+ return true;
29
+ }
30
+ };
31
+ }, nodeProps);
32
+ const children = /*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
33
+ value: childContextValue
34
+ }, /*#__PURE__*/ React.createElement(ChildNodeViews, {
35
+ getPos: getPos,
36
+ node: node,
37
+ innerDecorations: innerDecorations
38
+ }));
39
+ const props = {
40
+ ...elementProps,
41
+ suppressContentEditableWarning: true,
42
+ ref: innerRef
43
+ };
44
+ const element = as ? /*#__PURE__*/ createElement(as, props, children) : /*#__PURE__*/ createElement("div", props, children);
45
+ return nodeProps.decorations.reduce(wrapInDeco, element);
46
+ }));
@@ -0,0 +1,67 @@
1
+ import React, { createContext, memo, useContext, useLayoutEffect, useMemo, useReducer, useRef } from "react";
2
+ import { NodeViewContext } from "../../contexts/NodeViewContext.js";
3
+ import { useEditorStateSelector } from "../../hooks/useEditorStateSelector.js";
4
+ import { reactKeysPluginKey } from "../../plugins/reactKeys.js";
5
+ import { DefaultNodeView } from "./DefaultNodeView.js";
6
+ import { NodeViewConstructorView } from "./NodeViewConstructorView.js";
7
+ import { ReactNodeView } from "./ReactNodeView.js";
8
+ export const NodeView = /*#__PURE__*/ memo(function NodeView(param) {
9
+ let { forceRemount, ...props } = param;
10
+ const renderRef = useRef(null);
11
+ const frozen = useEditorStateSelector((state)=>reactKeysPluginKey.getState(state)?.freezeFrom === props.getPos());
12
+ const { components, constructors } = useContext(NodeViewContext);
13
+ const committedFrozenRef = useRef(false);
14
+ const component = components[props.node.type.name] ?? DefaultNodeView;
15
+ const constructor = constructors[props.node.type.name];
16
+ // Construct a wrapper component so that the node view remounts when either
17
+ // its component or constructor changes. A React node view would remount if
18
+ // its underlying component changed without this wrapper, but a custom node
19
+ // view otherwise uses the same React components for all custom node views.
20
+ const Component = useMemo(()=>{
21
+ if (constructor) {
22
+ return function NodeView(props) {
23
+ return /*#__PURE__*/ React.createElement(NodeViewConstructorView, {
24
+ constructor: constructor,
25
+ ...props
26
+ });
27
+ };
28
+ } else {
29
+ return function NodeView(props) {
30
+ return /*#__PURE__*/ React.createElement(ReactNodeView, {
31
+ component: component,
32
+ ...props
33
+ });
34
+ };
35
+ }
36
+ }, [
37
+ constructor,
38
+ component
39
+ ]);
40
+ // Protect content while frozen, and also through the single render where we
41
+ // leave the frozen state: `committedFrozenRef` still reflects the previous
42
+ // commit, so we keep returning the exact same cached element reference.
43
+ const protecting = (frozen || committedFrozenRef.current) && renderRef.current != null;
44
+ if (!protecting) {
45
+ renderRef.current = /*#__PURE__*/ React.createElement(GetPosContext.Provider, {
46
+ value: props.getPos
47
+ }, /*#__PURE__*/ React.createElement(Component, props));
48
+ }
49
+ useLayoutEffect(()=>{
50
+ const wasFrozen = committedFrozenRef.current;
51
+ committedFrozenRef.current = frozen;
52
+ if (wasFrozen && !frozen) forceRemount();
53
+ }, [
54
+ frozen,
55
+ forceRemount
56
+ ]);
57
+ return renderRef.current;
58
+ });
59
+ export const GetPosContext = /*#__PURE__*/ createContext(null);
60
+ export function RemountableNodeView(props) {
61
+ const [key, forceRemount] = useReducer((x)=>x + 1, 0);
62
+ return /*#__PURE__*/ React.createElement(NodeView, {
63
+ key: key.toString(),
64
+ ...props,
65
+ forceRemount: forceRemount
66
+ });
67
+ }
@@ -0,0 +1 @@
1
+ export { };