@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,94 @@
1
+ import { DOMSerializer } from "prosemirror-model";
2
+ import React, { cloneElement, 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 { useNodeViewDescription } from "../../hooks/useNodeViewDescription.js";
7
+ import { ChildNodeViews, wrapInDeco } from "../ChildNodeViews.js";
8
+ export const NodeViewConstructorView = /*#__PURE__*/ memo(function NodeViewConstructorView(param) {
9
+ let { constructor, node, getPos, innerDeco, outerDeco } = param;
10
+ const ref = useRef(null);
11
+ const innerRef = useRef(null);
12
+ const forceUpdate = useForceUpdate();
13
+ const nodeProps = useMemo(()=>({
14
+ node,
15
+ getPos,
16
+ decorations: outerDeco,
17
+ innerDecorations: innerDeco,
18
+ contentDOMRef: {
19
+ current: null
20
+ }
21
+ }), [
22
+ node,
23
+ getPos,
24
+ outerDeco,
25
+ innerDeco
26
+ ]);
27
+ const createNodeView = function() {
28
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
29
+ args[_key] = arguments[_key];
30
+ }
31
+ const nodeView = constructor(...args);
32
+ if (!nodeView || !nodeView.dom) {
33
+ const spec = node.type.spec.toDOM?.(node);
34
+ if (!spec) {
35
+ throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
36
+ }
37
+ return DOMSerializer.renderSpec(document, spec, null);
38
+ }
39
+ return nodeView;
40
+ };
41
+ const { childContextValue, contentDOM } = useNodeViewDescription(()=>ref.current, (source)=>source?.contentDOM ?? null, function() {
42
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
43
+ args[_key] = arguments[_key];
44
+ }
45
+ const nodeView = createNodeView(...args);
46
+ const contentDOM = nodeView.contentDOM;
47
+ const nodeDOM = nodeView.dom;
48
+ const wrapperDOM = innerRef.current ?? ref.current;
49
+ wrapperDOM.appendChild(nodeDOM);
50
+ if (!contentDOM && nodeDOM instanceof HTMLElement && nodeDOM.tagName !== "BR") {
51
+ if (!nodeDOM.hasAttribute("contenteditable")) {
52
+ nodeDOM.contentEditable = "false";
53
+ }
54
+ if (node.type.spec.draggable) {
55
+ nodeDOM.draggable = true;
56
+ }
57
+ }
58
+ if (contentDOM) {
59
+ // Force a re-render if we have a contentDOM,
60
+ // so that we properly create a portal into it
61
+ forceUpdate();
62
+ }
63
+ return {
64
+ destroy () {
65
+ if (nodeView.destroy) {
66
+ nodeView.destroy();
67
+ }
68
+ wrapperDOM.removeChild(nodeDOM);
69
+ },
70
+ dom: nodeView.dom,
71
+ contentDOM: nodeView.contentDOM,
72
+ multiType: nodeView.multiType,
73
+ update: nodeView.update?.bind(nodeView),
74
+ selectNode: nodeView.selectNode?.bind(nodeView),
75
+ deselectNode: nodeView.deselectNode?.bind(nodeView),
76
+ stopEvent: nodeView.stopEvent?.bind(nodeView),
77
+ ignoreMutation: nodeView.ignoreMutation?.bind(nodeView)
78
+ };
79
+ }, nodeProps);
80
+ const Component = node.isInline ? "span" : "div";
81
+ const props = {
82
+ ref: innerRef
83
+ };
84
+ const children = !node.isLeaf && contentDOM ? /*#__PURE__*/ createPortal(/*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
85
+ value: childContextValue
86
+ }, /*#__PURE__*/ React.createElement(ChildNodeViews, {
87
+ getPos: getPos,
88
+ node: node,
89
+ innerDecorations: innerDeco
90
+ })), contentDOM) : null;
91
+ return /*#__PURE__*/ cloneElement(outerDeco.reduce(wrapInDeco, /*#__PURE__*/ React.createElement(Component, props, children)), {
92
+ ref
93
+ });
94
+ });
@@ -0,0 +1,138 @@
1
+ import React, { cloneElement, memo, useCallback, useMemo, useRef, useState } from "react";
2
+ import { ChildDescriptionsContext } from "../../contexts/ChildDescriptionsContext.js";
3
+ import { IgnoreMutationContext } from "../../contexts/IgnoreMutationContext.js";
4
+ import { SelectNodeContext } from "../../contexts/SelectNodeContext.js";
5
+ import { StopEventContext } from "../../contexts/StopEventContext.js";
6
+ import { useForceUpdate } from "../../hooks/useForceUpdate.js";
7
+ import { useNodeViewDescription } from "../../hooks/useNodeViewDescription.js";
8
+ import { useSetDom } from "../../hooks/useSetDom.js";
9
+ import { ChildNodeViews, wrapInDeco } from "../ChildNodeViews.js";
10
+ export const ReactNodeView = /*#__PURE__*/ memo(function ReactNodeView(param) {
11
+ let { component: Component, outerDeco, getPos, node, innerDeco } = param;
12
+ const [hasCustomSelectNode, setHasCustomSelectNode] = useState(false);
13
+ const [selected, setSelected] = useState(false);
14
+ const forceUpdate = useForceUpdate();
15
+ const domRef = useRef(null);
16
+ const nodeDOMRef = useRef(null);
17
+ const contentDOMRef = useRef(null);
18
+ const selectNodeRef = useRef(null);
19
+ const deselectNodeRef = useRef(null);
20
+ const stopEventRef = useRef(null);
21
+ const ignoreMutationRef = useRef(null);
22
+ const setSelectNode = useCallback((selectHandler, deselectHandler)=>{
23
+ selectNodeRef.current = selectHandler;
24
+ deselectNodeRef.current = deselectHandler;
25
+ setHasCustomSelectNode(true);
26
+ return ()=>{
27
+ selectNodeRef.current = null;
28
+ deselectNodeRef.current = null;
29
+ setHasCustomSelectNode(false);
30
+ };
31
+ }, []);
32
+ const setStopEvent = useCallback((handler)=>{
33
+ stopEventRef.current = handler;
34
+ return ()=>{
35
+ stopEventRef.current = null;
36
+ };
37
+ }, []);
38
+ const setIgnoreMutation = useCallback((handler)=>{
39
+ ignoreMutationRef.current = handler;
40
+ return ()=>{
41
+ ignoreMutationRef.current = null;
42
+ return ()=>{
43
+ ignoreMutationRef.current = null;
44
+ };
45
+ };
46
+ }, []);
47
+ const nodeViewDescProps = useMemo(()=>({
48
+ node: node,
49
+ getPos: getPos,
50
+ decorations: outerDeco,
51
+ innerDecorations: innerDeco
52
+ }), [
53
+ getPos,
54
+ innerDeco,
55
+ node,
56
+ outerDeco
57
+ ]);
58
+ const { childContextValue, refUpdated, isMounted } = useNodeViewDescription(()=>domRef.current, ()=>contentDOMRef.current, ()=>{
59
+ setSelected(false);
60
+ return {
61
+ dom: nodeDOMRef.current ?? domRef.current,
62
+ contentDOM: contentDOMRef.current,
63
+ update () {
64
+ return true;
65
+ },
66
+ multiType: true,
67
+ selectNode () {
68
+ const selectNode = selectNodeRef.current;
69
+ if (selectNode) {
70
+ selectNode.call(this);
71
+ }
72
+ setSelected(true);
73
+ },
74
+ deselectNode () {
75
+ const deselectNode = deselectNodeRef.current;
76
+ if (deselectNode) {
77
+ deselectNode.call(this);
78
+ }
79
+ setSelected(false);
80
+ },
81
+ stopEvent (event) {
82
+ const stopEvent = stopEventRef.current;
83
+ if (stopEvent) {
84
+ return stopEvent.call(this, event);
85
+ }
86
+ return false;
87
+ },
88
+ ignoreMutation (mutation) {
89
+ const ignoreMutation = ignoreMutationRef.current;
90
+ if (ignoreMutation) {
91
+ return ignoreMutation.call(this, mutation);
92
+ }
93
+ return false;
94
+ }
95
+ };
96
+ }, nodeViewDescProps);
97
+ const setDOM = useSetDom(domRef, refUpdated, isMounted, forceUpdate);
98
+ const setNodeDOM = useSetDom(nodeDOMRef, refUpdated, isMounted, forceUpdate);
99
+ const setContentDOM = useSetDom(contentDOMRef, refUpdated, isMounted, forceUpdate);
100
+ const nodeProps = useMemo(()=>({
101
+ ...nodeViewDescProps,
102
+ contentDOMRef: setContentDOM
103
+ }), [
104
+ nodeViewDescProps,
105
+ setContentDOM
106
+ ]);
107
+ const props = {
108
+ nodeProps,
109
+ ...!contentDOMRef.current && !nodeProps.node.isText && nodeDOMRef.current?.nodeName !== "BR" ? {
110
+ contentEditable: false,
111
+ suppressContentEditableWarning: true
112
+ } : null,
113
+ ...!hasCustomSelectNode && selected ? {
114
+ className: "ProseMirror-selectednode"
115
+ } : null,
116
+ ...!hasCustomSelectNode && selected || !contentDOMRef.current && !nodeProps.node.isText && domRef.current?.nodeName !== "BR" && node.type.spec.draggable ? {
117
+ draggable: true
118
+ } : null,
119
+ ref: setNodeDOM
120
+ };
121
+ const children = !node.isLeaf ? /*#__PURE__*/ React.createElement(ChildNodeViews, {
122
+ getPos: getPos,
123
+ node: node,
124
+ innerDecorations: innerDeco
125
+ }) : null;
126
+ const element = /*#__PURE__*/ cloneElement(outerDeco.reduce(wrapInDeco, /*#__PURE__*/ React.createElement(Component, props, children)), {
127
+ ref: setDOM
128
+ });
129
+ return /*#__PURE__*/ React.createElement(SelectNodeContext.Provider, {
130
+ value: setSelectNode
131
+ }, /*#__PURE__*/ React.createElement(StopEventContext.Provider, {
132
+ value: setStopEvent
133
+ }, /*#__PURE__*/ React.createElement(IgnoreMutationContext.Provider, {
134
+ value: setIgnoreMutation
135
+ }, /*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
136
+ value: childContextValue
137
+ }, element))));
138
+ });
@@ -0,0 +1,15 @@
1
+ import { Schema } from "prosemirror-model";
2
+ import { EditorState } from "prosemirror-state";
3
+ export const EMPTY_SCHEMA = new Schema({
4
+ nodes: {
5
+ doc: {
6
+ content: "text*"
7
+ },
8
+ text: {
9
+ inline: true
10
+ }
11
+ }
12
+ });
13
+ export const EMPTY_STATE = EditorState.create({
14
+ schema: EMPTY_SCHEMA
15
+ });
@@ -0,0 +1,9 @@
1
+ import { createContext } from "react";
2
+ export const ChildDescriptionsContext = createContext({
3
+ parentRef: {
4
+ current: undefined
5
+ },
6
+ siblingsRef: {
7
+ current: []
8
+ }
9
+ });
@@ -0,0 +1,7 @@
1
+ /* Copyright (c) The New York Times Company */ import { createContext } from "react";
2
+ /**
3
+ * Provides the EditorView, as well as the current
4
+ * EditorState. Should not be consumed directly; instead
5
+ * see `useEditorState`, `useEditorViewEvent`, and
6
+ * `useEditorViewLayoutEffect`.
7
+ */ export const EditorContext = createContext(null);
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const EditorStateContext = createContext(null);
@@ -0,0 +1,27 @@
1
+ import { createContext } from "react";
2
+ export function createEditorStateStore() {
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ let state = null;
5
+ let pendingNotify = false;
6
+ const listeners = new Set();
7
+ return {
8
+ getState: ()=>state,
9
+ subscribe: (listener)=>{
10
+ listeners.add(listener);
11
+ return ()=>listeners.delete(listener);
12
+ },
13
+ setState: (newState)=>{
14
+ if (state !== newState) {
15
+ state = newState;
16
+ pendingNotify = true;
17
+ }
18
+ },
19
+ notifyListeners: ()=>{
20
+ if (pendingNotify) {
21
+ pendingNotify = false;
22
+ listeners.forEach((l)=>l());
23
+ }
24
+ }
25
+ };
26
+ }
27
+ export const EditorStateStoreContext = createContext(null);
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const IgnoreMutationContext = createContext(null);
@@ -0,0 +1,2 @@
1
+ /* Copyright (c) The New York Times Company */ import { createContext } from "react";
2
+ export const LayoutGroupContext = /*#__PURE__*/ createContext(null);
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const NodeViewContext = createContext(null);
@@ -0,0 +1,33 @@
1
+ import { createContext, useContext, useSyncExternalStore } from "react";
2
+ export const createRenderStore = ()=>{
3
+ const listeners = new Set();
4
+ let version = 0;
5
+ const store = {
6
+ state: null,
7
+ doc: null,
8
+ announced: false,
9
+ getVersion: ()=>version,
10
+ subscribe: (listener)=>{
11
+ listeners.add(listener);
12
+ return ()=>{
13
+ listeners.delete(listener);
14
+ };
15
+ },
16
+ announce: ()=>{
17
+ // Nobody to re-render through the store: let the contexts change.
18
+ if (!listeners.size) return;
19
+ store.announced = true;
20
+ version++;
21
+ listeners.forEach((listener)=>listener());
22
+ }
23
+ };
24
+ return store;
25
+ };
26
+ export const RenderStoreContext = createContext(null);
27
+ const inertStore = createRenderStore();
28
+ /** Subscribes to announced transactions; null when `stableContexts` is off. */ export const useRenderStore = ()=>{
29
+ const store = useContext(RenderStoreContext);
30
+ const subscribed = store ?? inertStore;
31
+ useSyncExternalStore(subscribed.subscribe, subscribed.getVersion, subscribed.getVersion);
32
+ return store;
33
+ };
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const SelectNodeContext = createContext(null);
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const StopEventContext = createContext(null);
@@ -0,0 +1,40 @@
1
+ import { Decoration } from "prosemirror-view";
2
+ function compareObjs(a, b) {
3
+ if (a == b) return true;
4
+ for(const p in a)if (a[p] !== b[p]) return false;
5
+ for(const p in b)if (!(p in a)) return false;
6
+ return true;
7
+ }
8
+ const noSpec = {
9
+ side: 0
10
+ };
11
+ export class ReactWidgetType {
12
+ Component;
13
+ side;
14
+ spec;
15
+ constructor(Component, spec){
16
+ this.Component = Component;
17
+ this.spec = spec ?? noSpec;
18
+ this.side = this.spec.side ?? 0;
19
+ }
20
+ map(mapping, span, offset, oldOffset) {
21
+ const { pos, deleted } = mapping.mapResult(span.from + oldOffset, this.side < 0 ? -1 : 1);
22
+ // @ts-expect-error The Decoration constructor is private/internal, but
23
+ // we need to use it for our custom widget implementation here.
24
+ return deleted ? null : new Decoration(pos - offset, pos - offset, this);
25
+ }
26
+ valid() {
27
+ return true;
28
+ }
29
+ eq(other) {
30
+ return this == other || other instanceof ReactWidgetType && (this.spec.key && this.spec.key == other.spec.key || this.Component == other.Component && compareObjs(this.spec, other.spec));
31
+ }
32
+ destroy() {
33
+ // Can be implemented with React effect hooks
34
+ }
35
+ }
36
+ export function widget(pos, component, spec) {
37
+ // @ts-expect-error The Decoration constructor is private/internal, but
38
+ // we need to use it for our custom widget implementation here.
39
+ return new Decoration(pos, pos, new ReactWidgetType(component, spec));
40
+ }
@@ -0,0 +1,44 @@
1
+ import { Decoration } from "prosemirror-view";
2
+ const DocDecorationsCache = new WeakMap();
3
+ /**
4
+ * Produces the outer decorations for the doc node, based
5
+ * on the attributes editor prop.
6
+ *
7
+ * The return value of this function is memoized; if it is to
8
+ * return an equivalent value to the last time it was called for
9
+ * a given EditorView, it will return exactly that previous value.
10
+ *
11
+ * This makes it safe to call in a React render function, even
12
+ * if its result is used in a dependencies array for a hook.
13
+ */ export function computeDocDeco(view) {
14
+ const attrs = Object.create(null);
15
+ attrs.class = "ProseMirror";
16
+ attrs.contenteditable = String(view.editable);
17
+ view.someProp("attributes", (value)=>{
18
+ if (typeof value == "function") value = value(view.state);
19
+ if (value) for(const attr in value){
20
+ if (attr == "class") attrs.class += " " + value[attr];
21
+ else if (attr == "style") attrs.style = (attrs.style ? attrs.style + ";" : "") + value[attr];
22
+ else if (!attrs[attr] && attr != "contenteditable" && attr != "nodeName") attrs[attr] = String(value[attr]);
23
+ }
24
+ });
25
+ if (!attrs.translate) attrs.translate = "no";
26
+ const next = [
27
+ Decoration.node(0, view.state.doc.content.size, attrs)
28
+ ];
29
+ const previous = DocDecorationsCache.get(view);
30
+ if (!previous) {
31
+ DocDecorationsCache.set(view, next);
32
+ return next;
33
+ }
34
+ if (previous[0].to !== view.state.doc.content.size) {
35
+ DocDecorationsCache.set(view, next);
36
+ return next;
37
+ }
38
+ // @ts-expect-error Internal property (Decoration.type)
39
+ if (!previous[0].type.eq(next[0].type)) {
40
+ DocDecorationsCache.set(view, next);
41
+ return next;
42
+ }
43
+ return previous;
44
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,85 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { ReactWidgetType } from "./ReactWidgetType.js";
2
+ function compareSide(a, b) {
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ return a.type.side - b.type.side;
5
+ }
6
+ // This function abstracts iterating over the nodes and decorations in
7
+ // a fragment. Calls `onNode` for each node, with its local and child
8
+ // decorations. Splits text nodes when there is a decoration starting
9
+ // or ending inside of them. Calls `onWidget` for each widget.
10
+ export function iterDeco(parent, deco, // Callbacks have been slightly modified to pass
11
+ // the offset, so that we can pass the position as
12
+ // a prop to components
13
+ onWidget, onNode) {
14
+ const locals = deco.locals(parent);
15
+ let offset = 0;
16
+ // Simple, cheap variant for when there are no local decorations
17
+ if (locals.length == 0) {
18
+ for(let i = 0; i < parent.childCount; i++){
19
+ const child = parent.child(i);
20
+ onNode(child, locals, deco.forChild(offset, child), offset, i);
21
+ offset += child.nodeSize;
22
+ }
23
+ return;
24
+ }
25
+ let decoIndex = 0;
26
+ const active = [];
27
+ let restNode = null;
28
+ for(let parentIndex = 0;;){
29
+ if (decoIndex < locals.length && locals[decoIndex].to == offset) {
30
+ let widget;
31
+ let widgets;
32
+ while(decoIndex < locals.length && locals[decoIndex].to == offset){
33
+ const next = locals[decoIndex++];
34
+ if (next.widget || // FORK: Our custom widget type can't report itself as a widget,
35
+ // so we have to explicitly check
36
+ next.type instanceof ReactWidgetType) {
37
+ if (!widget) widget = next;
38
+ else (widgets || (widgets = [
39
+ widget
40
+ ])).push(next);
41
+ }
42
+ }
43
+ if (widget) {
44
+ if (widgets) {
45
+ widgets.sort(compareSide);
46
+ for(let i = 0; i < widgets.length; i++)onWidget(widgets[i], // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ !(widgets[i].type instanceof ReactWidgetType), offset, parentIndex + i, !!restNode);
48
+ } else {
49
+ onWidget(widget, // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ !(widget.type instanceof ReactWidgetType), offset, parentIndex, !!restNode);
51
+ }
52
+ }
53
+ }
54
+ let child, index;
55
+ if (restNode) {
56
+ index = -1;
57
+ child = restNode;
58
+ restNode = null;
59
+ } else if (parentIndex < parent.childCount) {
60
+ index = parentIndex;
61
+ child = parent.child(parentIndex++);
62
+ } else {
63
+ break;
64
+ }
65
+ for(let i = 0; i < active.length; i++)if (active[i].to <= offset) active.splice(i--, 1);
66
+ while(decoIndex < locals.length && locals[decoIndex].from <= offset && locals[decoIndex].to > offset)active.push(locals[decoIndex++]);
67
+ let end = offset + child.nodeSize;
68
+ if (child.isText) {
69
+ let cutAt = end;
70
+ if (decoIndex < locals.length && locals[decoIndex].from < cutAt) cutAt = locals[decoIndex].from;
71
+ for(let i = 0; i < active.length; i++)if (active[i].to < cutAt) cutAt = active[i].to;
72
+ if (cutAt < end) {
73
+ restNode = child.cut(cutAt - offset);
74
+ child = child.cut(0, cutAt - offset);
75
+ end = cutAt;
76
+ index = -1;
77
+ }
78
+ } else {
79
+ while(decoIndex < locals.length && locals[decoIndex].to < end)decoIndex++;
80
+ }
81
+ const outerDeco = child.isInline && !child.isLeaf ? active.filter((d)=>!d.inline) : active.slice();
82
+ onNode(child, outerDeco, deco.forChild(offset, child), offset, index);
83
+ offset = end;
84
+ }
85
+ }