@handlewithcare/react-prosemirror 2.0.0

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 (209) hide show
  1. package/LICENSE.txt +12 -0
  2. package/README.md +705 -0
  3. package/dist/cjs/browser.js +53 -0
  4. package/dist/cjs/components/ChildNodeViews.js +376 -0
  5. package/dist/cjs/components/CursorWrapper.js +91 -0
  6. package/dist/cjs/components/CustomNodeView.js +79 -0
  7. package/dist/cjs/components/DocNodeView.js +104 -0
  8. package/dist/cjs/components/LayoutGroup.js +111 -0
  9. package/dist/cjs/components/MarkView.js +115 -0
  10. package/dist/cjs/components/NativeWidgetView.js +109 -0
  11. package/dist/cjs/components/NodeView.js +196 -0
  12. package/dist/cjs/components/NodeViewComponentProps.js +4 -0
  13. package/dist/cjs/components/OutputSpec.js +88 -0
  14. package/dist/cjs/components/ProseMirror.js +103 -0
  15. package/dist/cjs/components/ProseMirrorDoc.js +92 -0
  16. package/dist/cjs/components/SeparatorHackView.js +100 -0
  17. package/dist/cjs/components/TextNodeView.js +112 -0
  18. package/dist/cjs/components/TrailingHackView.js +90 -0
  19. package/dist/cjs/components/WidgetView.js +95 -0
  20. package/dist/cjs/components/WidgetViewComponentProps.js +4 -0
  21. package/dist/cjs/components/__tests__/ProseMirror.composition.test.js +398 -0
  22. package/dist/cjs/components/__tests__/ProseMirror.domchange.test.js +270 -0
  23. package/dist/cjs/components/__tests__/ProseMirror.draw-decoration.test.js +1010 -0
  24. package/dist/cjs/components/__tests__/ProseMirror.draw.test.js +337 -0
  25. package/dist/cjs/components/__tests__/ProseMirror.node-view.test.js +315 -0
  26. package/dist/cjs/components/__tests__/ProseMirror.selection.test.js +444 -0
  27. package/dist/cjs/components/__tests__/ProseMirror.test.js +382 -0
  28. package/dist/cjs/contexts/ChildDescriptorsContext.js +19 -0
  29. package/dist/cjs/contexts/EditorContext.js +12 -0
  30. package/dist/cjs/contexts/EditorStateContext.js +12 -0
  31. package/dist/cjs/contexts/LayoutGroupContext.js +12 -0
  32. package/dist/cjs/contexts/NodeViewContext.js +12 -0
  33. package/dist/cjs/contexts/SelectNodeContext.js +12 -0
  34. package/dist/cjs/contexts/StopEventContext.js +12 -0
  35. package/dist/cjs/contexts/__tests__/DeferredLayoutEffects.test.js +141 -0
  36. package/dist/cjs/decorations/ReactWidgetType.js +58 -0
  37. package/dist/cjs/decorations/computeDocDeco.js +44 -0
  38. package/dist/cjs/decorations/internalTypes.js +4 -0
  39. package/dist/cjs/decorations/iterDeco.js +79 -0
  40. package/dist/cjs/decorations/viewDecorations.js +163 -0
  41. package/dist/cjs/dom.js +142 -0
  42. package/dist/cjs/hooks/__tests__/useEditorViewLayoutEffect.test.js +108 -0
  43. package/dist/cjs/hooks/useClientOnly.js +18 -0
  44. package/dist/cjs/hooks/useComponentEventListeners.js +39 -0
  45. package/dist/cjs/hooks/useEditor.js +287 -0
  46. package/dist/cjs/hooks/useEditorEffect.js +35 -0
  47. package/dist/cjs/hooks/useEditorEventCallback.js +33 -0
  48. package/dist/cjs/hooks/useEditorEventListener.js +34 -0
  49. package/dist/cjs/hooks/useEditorState.js +16 -0
  50. package/dist/cjs/hooks/useForceUpdate.js +15 -0
  51. package/dist/cjs/hooks/useLayoutGroupEffect.js +19 -0
  52. package/dist/cjs/hooks/useNodeViewDescriptor.js +115 -0
  53. package/dist/cjs/hooks/useReactKeys.js +17 -0
  54. package/dist/cjs/hooks/useSelectNode.js +28 -0
  55. package/dist/cjs/hooks/useStopEvent.js +24 -0
  56. package/dist/cjs/index.js +53 -0
  57. package/dist/cjs/package.json +3 -0
  58. package/dist/cjs/plugins/__tests__/reactKeys.test.js +81 -0
  59. package/dist/cjs/plugins/beforeInputPlugin.js +143 -0
  60. package/dist/cjs/plugins/componentEventListeners.js +35 -0
  61. package/dist/cjs/plugins/componentEventListenersPlugin.js +35 -0
  62. package/dist/cjs/plugins/reactKeys.js +96 -0
  63. package/dist/cjs/props.js +269 -0
  64. package/dist/cjs/selection/SelectionDOMObserver.js +174 -0
  65. package/dist/cjs/selection/hasFocusAndSelection.js +35 -0
  66. package/dist/cjs/selection/selectionFromDOM.js +77 -0
  67. package/dist/cjs/selection/selectionToDOM.js +226 -0
  68. package/dist/cjs/ssr.js +85 -0
  69. package/dist/cjs/testing/editorViewTestHelpers.js +111 -0
  70. package/dist/cjs/testing/setupProseMirrorView.js +94 -0
  71. package/dist/cjs/viewdesc.js +664 -0
  72. package/dist/esm/browser.js +43 -0
  73. package/dist/esm/components/ChildNodeViews.js +318 -0
  74. package/dist/esm/components/CursorWrapper.js +40 -0
  75. package/dist/esm/components/CustomNodeView.js +28 -0
  76. package/dist/esm/components/DocNodeView.js +53 -0
  77. package/dist/esm/components/LayoutGroup.js +66 -0
  78. package/dist/esm/components/MarkView.js +64 -0
  79. package/dist/esm/components/NativeWidgetView.js +58 -0
  80. package/dist/esm/components/NodeView.js +145 -0
  81. package/dist/esm/components/NodeViewComponentProps.js +1 -0
  82. package/dist/esm/components/OutputSpec.js +38 -0
  83. package/dist/esm/components/ProseMirror.js +52 -0
  84. package/dist/esm/components/ProseMirrorDoc.js +34 -0
  85. package/dist/esm/components/SeparatorHackView.js +49 -0
  86. package/dist/esm/components/TextNodeView.js +102 -0
  87. package/dist/esm/components/TrailingHackView.js +39 -0
  88. package/dist/esm/components/WidgetView.js +44 -0
  89. package/dist/esm/components/WidgetViewComponentProps.js +1 -0
  90. package/dist/esm/components/__tests__/ProseMirror.composition.test.js +395 -0
  91. package/dist/esm/components/__tests__/ProseMirror.domchange.test.js +266 -0
  92. package/dist/esm/components/__tests__/ProseMirror.draw-decoration.test.js +967 -0
  93. package/dist/esm/components/__tests__/ProseMirror.draw.test.js +294 -0
  94. package/dist/esm/components/__tests__/ProseMirror.node-view.test.js +272 -0
  95. package/dist/esm/components/__tests__/ProseMirror.selection.test.js +440 -0
  96. package/dist/esm/components/__tests__/ProseMirror.test.js +339 -0
  97. package/dist/esm/contexts/ChildDescriptorsContext.js +9 -0
  98. package/dist/esm/contexts/EditorContext.js +7 -0
  99. package/dist/esm/contexts/EditorStateContext.js +2 -0
  100. package/dist/esm/contexts/LayoutGroupContext.js +2 -0
  101. package/dist/esm/contexts/NodeViewContext.js +2 -0
  102. package/dist/esm/contexts/SelectNodeContext.js +2 -0
  103. package/dist/esm/contexts/StopEventContext.js +2 -0
  104. package/dist/esm/contexts/__tests__/DeferredLayoutEffects.test.js +98 -0
  105. package/dist/esm/decorations/ReactWidgetType.js +40 -0
  106. package/dist/esm/decorations/computeDocDeco.js +44 -0
  107. package/dist/esm/decorations/internalTypes.js +1 -0
  108. package/dist/esm/decorations/iterDeco.js +73 -0
  109. package/dist/esm/decorations/viewDecorations.js +163 -0
  110. package/dist/esm/dom.js +105 -0
  111. package/dist/esm/hooks/__tests__/useEditorViewLayoutEffect.test.js +99 -0
  112. package/dist/esm/hooks/useClientOnly.js +8 -0
  113. package/dist/esm/hooks/useComponentEventListeners.js +54 -0
  114. package/dist/esm/hooks/useEditor.js +278 -0
  115. package/dist/esm/hooks/useEditorEffect.js +38 -0
  116. package/dist/esm/hooks/useEditorEventCallback.js +35 -0
  117. package/dist/esm/hooks/useEditorEventListener.js +28 -0
  118. package/dist/esm/hooks/useEditorState.js +8 -0
  119. package/dist/esm/hooks/useForceUpdate.js +8 -0
  120. package/dist/esm/hooks/useLayoutGroupEffect.js +9 -0
  121. package/dist/esm/hooks/useNodeViewDescriptor.js +105 -0
  122. package/dist/esm/hooks/useReactKeys.js +7 -0
  123. package/dist/esm/hooks/useSelectNode.js +18 -0
  124. package/dist/esm/hooks/useStopEvent.js +14 -0
  125. package/dist/esm/index.js +11 -0
  126. package/dist/esm/plugins/__tests__/reactKeys.test.js +77 -0
  127. package/dist/esm/plugins/beforeInputPlugin.js +133 -0
  128. package/dist/esm/plugins/componentEventListeners.js +25 -0
  129. package/dist/esm/plugins/componentEventListenersPlugin.js +25 -0
  130. package/dist/esm/plugins/reactKeys.js +81 -0
  131. package/dist/esm/props.js +251 -0
  132. package/dist/esm/selection/SelectionDOMObserver.js +164 -0
  133. package/dist/esm/selection/hasFocusAndSelection.js +17 -0
  134. package/dist/esm/selection/selectionFromDOM.js +59 -0
  135. package/dist/esm/selection/selectionToDOM.js +196 -0
  136. package/dist/esm/ssr.js +82 -0
  137. package/dist/esm/testing/editorViewTestHelpers.js +88 -0
  138. package/dist/esm/testing/setupProseMirrorView.js +76 -0
  139. package/dist/esm/viewdesc.js +654 -0
  140. package/dist/tsconfig.tsbuildinfo +1 -0
  141. package/dist/types/browser.d.ts +15 -0
  142. package/dist/types/components/ChildNodeViews.d.ts +9 -0
  143. package/dist/types/components/CursorWrapper.d.ts +5 -0
  144. package/dist/types/components/CustomNodeView.d.ts +21 -0
  145. package/dist/types/components/DocNodeView.d.ts +20 -0
  146. package/dist/types/components/LayoutGroup.d.ts +12 -0
  147. package/dist/types/components/MarkView.d.ts +9 -0
  148. package/dist/types/components/NativeWidgetView.d.ts +8 -0
  149. package/dist/types/components/NodeView.d.ts +11 -0
  150. package/dist/types/components/NodeViewComponentProps.d.ts +12 -0
  151. package/dist/types/components/OutputSpec.d.ts +8 -0
  152. package/dist/types/components/ProseMirror.d.ts +15 -0
  153. package/dist/types/components/ProseMirrorDoc.d.ts +10 -0
  154. package/dist/types/components/SeparatorHackView.d.ts +6 -0
  155. package/dist/types/components/TextNodeView.d.ts +23 -0
  156. package/dist/types/components/TrailingHackView.d.ts +6 -0
  157. package/dist/types/components/WidgetView.d.ts +8 -0
  158. package/dist/types/components/WidgetViewComponentProps.d.ts +6 -0
  159. package/dist/types/components/__tests__/ProseMirror.composition.test.d.ts +1 -0
  160. package/dist/types/components/__tests__/ProseMirror.domchange.test.d.ts +1 -0
  161. package/dist/types/components/__tests__/ProseMirror.draw-decoration.test.d.ts +1 -0
  162. package/dist/types/components/__tests__/ProseMirror.draw.test.d.ts +1 -0
  163. package/dist/types/components/__tests__/ProseMirror.node-view.test.d.ts +1 -0
  164. package/dist/types/components/__tests__/ProseMirror.selection.test.d.ts +1 -0
  165. package/dist/types/components/__tests__/ProseMirror.test.d.ts +1 -0
  166. package/dist/types/contexts/ChildDescriptorsContext.d.ts +6 -0
  167. package/dist/types/contexts/EditorContext.d.ts +14 -0
  168. package/dist/types/contexts/EditorStateContext.d.ts +2 -0
  169. package/dist/types/contexts/LayoutGroupContext.d.ts +5 -0
  170. package/dist/types/contexts/NodeViewContext.d.ts +6 -0
  171. package/dist/types/contexts/SelectNodeContext.d.ts +3 -0
  172. package/dist/types/contexts/StopEventContext.d.ts +3 -0
  173. package/dist/types/contexts/__tests__/DeferredLayoutEffects.test.d.ts +1 -0
  174. package/dist/types/decorations/ReactWidgetType.d.ts +39 -0
  175. package/dist/types/decorations/computeDocDeco.d.ts +13 -0
  176. package/dist/types/decorations/internalTypes.d.ts +16 -0
  177. package/dist/types/decorations/iterDeco.d.ts +3 -0
  178. package/dist/types/decorations/viewDecorations.d.ts +13 -0
  179. package/dist/types/dom.d.ts +22 -0
  180. package/dist/types/hooks/__tests__/useEditorViewLayoutEffect.test.d.ts +1 -0
  181. package/dist/types/hooks/useClientOnly.d.ts +1 -0
  182. package/dist/types/hooks/useComponentEventListeners.d.ts +33 -0
  183. package/dist/types/hooks/useEditor.d.ts +66 -0
  184. package/dist/types/hooks/useEditorEffect.d.ts +17 -0
  185. package/dist/types/hooks/useEditorEventCallback.d.ts +15 -0
  186. package/dist/types/hooks/useEditorEventListener.d.ts +8 -0
  187. package/dist/types/hooks/useEditorState.d.ts +5 -0
  188. package/dist/types/hooks/useForceUpdate.d.ts +5 -0
  189. package/dist/types/hooks/useLayoutGroupEffect.d.ts +3 -0
  190. package/dist/types/hooks/useNodeViewDescriptor.d.ts +11 -0
  191. package/dist/types/hooks/useReactKeys.d.ts +5 -0
  192. package/dist/types/hooks/useSelectNode.d.ts +1 -0
  193. package/dist/types/hooks/useStopEvent.d.ts +2 -0
  194. package/dist/types/index.d.ts +12 -0
  195. package/dist/types/plugins/__tests__/reactKeys.test.d.ts +1 -0
  196. package/dist/types/plugins/beforeInputPlugin.d.ts +3 -0
  197. package/dist/types/plugins/componentEventListeners.d.ts +4 -0
  198. package/dist/types/plugins/componentEventListenersPlugin.d.ts +4 -0
  199. package/dist/types/plugins/reactKeys.d.ts +19 -0
  200. package/dist/types/props.d.ts +1174 -0
  201. package/dist/types/selection/SelectionDOMObserver.d.ts +34 -0
  202. package/dist/types/selection/hasFocusAndSelection.d.ts +3 -0
  203. package/dist/types/selection/selectionFromDOM.d.ts +4 -0
  204. package/dist/types/selection/selectionToDOM.d.ts +9 -0
  205. package/dist/types/ssr.d.ts +19 -0
  206. package/dist/types/testing/editorViewTestHelpers.d.ts +23 -0
  207. package/dist/types/testing/setupProseMirrorView.d.ts +2 -0
  208. package/dist/types/viewdesc.d.ts +131 -0
  209. package/package.json +113 -0
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "OutputSpec", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ForwardedOutputSpec;
9
+ }
10
+ });
11
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _props = require("../props.js");
13
+ function _getRequireWildcardCache(nodeInterop) {
14
+ if (typeof WeakMap !== "function") return null;
15
+ var cacheBabelInterop = new WeakMap();
16
+ var cacheNodeInterop = new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop) {
18
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {
35
+ __proto__: null
36
+ };
37
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
38
+ for(var key in obj){
39
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
40
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
41
+ if (desc && (desc.get || desc.set)) {
42
+ Object.defineProperty(newObj, key, desc);
43
+ } else {
44
+ newObj[key] = obj[key];
45
+ }
46
+ }
47
+ }
48
+ newObj.default = obj;
49
+ if (cache) {
50
+ cache.set(obj, newObj);
51
+ }
52
+ return newObj;
53
+ }
54
+ const ForwardedOutputSpec = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function OutputSpec(param, ref) {
55
+ let { outputSpec, children, ...propOverrides } = param;
56
+ if (typeof outputSpec === "string") {
57
+ return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, outputSpec);
58
+ }
59
+ if (!Array.isArray(outputSpec)) {
60
+ throw new Error("@nytimes/react-prosemirror only supports strings and arrays in toDOM");
61
+ }
62
+ const tagSpec = outputSpec[0];
63
+ const tagName = tagSpec.replace(" ", ":");
64
+ const attrs = outputSpec[1];
65
+ let props = {
66
+ ref,
67
+ ...propOverrides
68
+ };
69
+ let start = 1;
70
+ if (attrs && typeof attrs === "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
71
+ start = 2;
72
+ props = (0, _props.mergeReactProps)((0, _props.htmlAttrsToReactProps)(attrs), props);
73
+ }
74
+ const content = [];
75
+ for(let i = start; i < outputSpec.length; i++){
76
+ const child = outputSpec[i];
77
+ if (child === 0) {
78
+ if (i < outputSpec.length - 1 || i > start) {
79
+ throw new RangeError("Content hole must be the only child of its parent node");
80
+ }
81
+ return /*#__PURE__*/ (0, _react.createElement)(tagName, props, children);
82
+ }
83
+ content.push(/*#__PURE__*/ _react.default.createElement(ForwardedOutputSpec, {
84
+ outputSpec: child
85
+ }, children));
86
+ }
87
+ return /*#__PURE__*/ (0, _react.createElement)(tagName, props, ...content);
88
+ }));
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ProseMirror", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ProseMirror;
9
+ }
10
+ });
11
+ const _prosemirrorview = require("prosemirror-view");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13
+ const _EditorContext = require("../contexts/EditorContext.js");
14
+ const _EditorStateContext = require("../contexts/EditorStateContext.js");
15
+ const _NodeViewContext = require("../contexts/NodeViewContext.js");
16
+ const _computeDocDeco = require("../decorations/computeDocDeco.js");
17
+ const _viewDecorations = require("../decorations/viewDecorations.js");
18
+ const _useEditor = require("../hooks/useEditor.js");
19
+ const _LayoutGroup = require("./LayoutGroup.js");
20
+ const _ProseMirrorDoc = require("./ProseMirrorDoc.js");
21
+ function _getRequireWildcardCache(nodeInterop) {
22
+ if (typeof WeakMap !== "function") return null;
23
+ var cacheBabelInterop = new WeakMap();
24
+ var cacheNodeInterop = new WeakMap();
25
+ return (_getRequireWildcardCache = function(nodeInterop) {
26
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
27
+ })(nodeInterop);
28
+ }
29
+ function _interop_require_wildcard(obj, nodeInterop) {
30
+ if (!nodeInterop && obj && obj.__esModule) {
31
+ return obj;
32
+ }
33
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
34
+ return {
35
+ default: obj
36
+ };
37
+ }
38
+ var cache = _getRequireWildcardCache(nodeInterop);
39
+ if (cache && cache.has(obj)) {
40
+ return cache.get(obj);
41
+ }
42
+ var newObj = {
43
+ __proto__: null
44
+ };
45
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
46
+ for(var key in obj){
47
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
48
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
49
+ if (desc && (desc.get || desc.set)) {
50
+ Object.defineProperty(newObj, key, desc);
51
+ } else {
52
+ newObj[key] = obj[key];
53
+ }
54
+ }
55
+ }
56
+ newObj.default = obj;
57
+ if (cache) {
58
+ cache.set(obj, newObj);
59
+ }
60
+ return newObj;
61
+ }
62
+ const EMPTY_OUTER_DECOS = [];
63
+ function ProseMirrorInner(param) {
64
+ let { className, children, nodeViews, customNodeViews, ...props } = param;
65
+ const [mount, setMount] = (0, _react.useState)(null);
66
+ const { editor, state } = (0, _useEditor.useEditor)(mount, {
67
+ ...props,
68
+ nodeViews: customNodeViews
69
+ });
70
+ const innerDecos = editor.view ? (0, _viewDecorations.viewDecorations)(editor.view, editor.cursorWrapper) : _prosemirrorview.DecorationSet.empty;
71
+ const outerDecos = editor.view ? (0, _computeDocDeco.computeDocDeco)(editor.view) : EMPTY_OUTER_DECOS;
72
+ const nodeViewContextValue = (0, _react.useMemo)(()=>({
73
+ nodeViews: nodeViews ?? {}
74
+ }), [
75
+ nodeViews
76
+ ]);
77
+ const docNodeViewContextValue = (0, _react.useMemo)(()=>({
78
+ className: className,
79
+ setMount: setMount,
80
+ node: editor.view?.state.doc,
81
+ innerDeco: innerDecos,
82
+ outerDeco: outerDecos,
83
+ viewDesc: editor.docViewDescRef.current
84
+ }), [
85
+ className,
86
+ editor.docViewDescRef,
87
+ editor.view?.state.doc,
88
+ innerDecos,
89
+ outerDecos
90
+ ]);
91
+ return /*#__PURE__*/ _react.default.createElement(_EditorContext.EditorContext.Provider, {
92
+ value: editor
93
+ }, /*#__PURE__*/ _react.default.createElement(_EditorStateContext.EditorStateContext.Provider, {
94
+ value: state
95
+ }, /*#__PURE__*/ _react.default.createElement(_NodeViewContext.NodeViewContext.Provider, {
96
+ value: nodeViewContextValue
97
+ }, /*#__PURE__*/ _react.default.createElement(_ProseMirrorDoc.DocNodeViewContext.Provider, {
98
+ value: docNodeViewContextValue
99
+ }, children))));
100
+ }
101
+ function ProseMirror(props) {
102
+ return /*#__PURE__*/ _react.default.createElement(_LayoutGroup.LayoutGroup, null, /*#__PURE__*/ _react.default.createElement(ProseMirrorInner, props));
103
+ }
@@ -0,0 +1,92 @@
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
+ DocNodeViewContext: function() {
13
+ return DocNodeViewContext;
14
+ },
15
+ ProseMirrorDoc: function() {
16
+ return ForwardedProseMirrorDoc;
17
+ }
18
+ });
19
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
20
+ const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
21
+ const _DocNodeView = require("./DocNodeView.js");
22
+ function _getRequireWildcardCache(nodeInterop) {
23
+ if (typeof WeakMap !== "function") return null;
24
+ var cacheBabelInterop = new WeakMap();
25
+ var cacheNodeInterop = new WeakMap();
26
+ return (_getRequireWildcardCache = function(nodeInterop) {
27
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
28
+ })(nodeInterop);
29
+ }
30
+ function _interop_require_wildcard(obj, nodeInterop) {
31
+ if (!nodeInterop && obj && obj.__esModule) {
32
+ return obj;
33
+ }
34
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
35
+ return {
36
+ default: obj
37
+ };
38
+ }
39
+ var cache = _getRequireWildcardCache(nodeInterop);
40
+ if (cache && cache.has(obj)) {
41
+ return cache.get(obj);
42
+ }
43
+ var newObj = {
44
+ __proto__: null
45
+ };
46
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
47
+ for(var key in obj){
48
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
49
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
50
+ if (desc && (desc.get || desc.set)) {
51
+ Object.defineProperty(newObj, key, desc);
52
+ } else {
53
+ newObj[key] = obj[key];
54
+ }
55
+ }
56
+ }
57
+ newObj.default = obj;
58
+ if (cache) {
59
+ cache.set(obj, newObj);
60
+ }
61
+ return newObj;
62
+ }
63
+ const DocNodeViewContext = /*#__PURE__*/ (0, _react.createContext)(null);
64
+ function ProseMirrorDoc(param, ref) {
65
+ let { as, ...props } = param;
66
+ const childDescriptors = (0, _react.useRef)([]);
67
+ const innerRef = (0, _react.useRef)(null);
68
+ const { setMount, ...docProps } = (0, _react.useContext)(DocNodeViewContext);
69
+ const viewDescRef = (0, _react.useRef)(undefined);
70
+ (0, _react.useImperativeHandle)(ref, ()=>{
71
+ return innerRef.current;
72
+ }, []);
73
+ const childContextValue = (0, _react.useMemo)(()=>({
74
+ parentRef: viewDescRef,
75
+ siblingsRef: childDescriptors
76
+ }), [
77
+ childDescriptors,
78
+ viewDescRef
79
+ ]);
80
+ return /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
81
+ value: childContextValue
82
+ }, /*#__PURE__*/ _react.default.createElement(_DocNodeView.DocNodeView, {
83
+ ref: (el)=>{
84
+ innerRef.current = el;
85
+ setMount(el);
86
+ },
87
+ ...props,
88
+ ...docProps,
89
+ as: as
90
+ }));
91
+ }
92
+ const ForwardedProseMirrorDoc = /*#__PURE__*/ (0, _react.forwardRef)(ProseMirrorDoc);
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "SeparatorHackView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return SeparatorHackView;
9
+ }
10
+ });
11
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _browser = require("../browser.js");
13
+ const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
14
+ const _viewdesc = require("../viewdesc.js");
15
+ function _getRequireWildcardCache(nodeInterop) {
16
+ if (typeof WeakMap !== "function") return null;
17
+ var cacheBabelInterop = new WeakMap();
18
+ var cacheNodeInterop = new WeakMap();
19
+ return (_getRequireWildcardCache = function(nodeInterop) {
20
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
21
+ })(nodeInterop);
22
+ }
23
+ function _interop_require_wildcard(obj, nodeInterop) {
24
+ if (!nodeInterop && obj && obj.__esModule) {
25
+ return obj;
26
+ }
27
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
28
+ return {
29
+ default: obj
30
+ };
31
+ }
32
+ var cache = _getRequireWildcardCache(nodeInterop);
33
+ if (cache && cache.has(obj)) {
34
+ return cache.get(obj);
35
+ }
36
+ var newObj = {
37
+ __proto__: null
38
+ };
39
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
40
+ for(var key in obj){
41
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
42
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
43
+ if (desc && (desc.get || desc.set)) {
44
+ Object.defineProperty(newObj, key, desc);
45
+ } else {
46
+ newObj[key] = obj[key];
47
+ }
48
+ }
49
+ }
50
+ newObj.default = obj;
51
+ if (cache) {
52
+ cache.set(obj, newObj);
53
+ }
54
+ return newObj;
55
+ }
56
+ function SeparatorHackView(param) {
57
+ let { getPos } = param;
58
+ const { siblingsRef, parentRef } = (0, _react.useContext)(_ChildDescriptorsContext.ChildDescriptorsContext);
59
+ const viewDescRef = (0, _react.useRef)(null);
60
+ const ref = (0, _react.useRef)(null);
61
+ const [shouldRender, setShouldRender] = (0, _react.useState)(false);
62
+ (0, _react.useLayoutEffect)(()=>{
63
+ const siblings = siblingsRef.current;
64
+ return ()=>{
65
+ if (!viewDescRef.current) return;
66
+ if (siblings.includes(viewDescRef.current)) {
67
+ const index = siblings.indexOf(viewDescRef.current);
68
+ siblings.splice(index, 1);
69
+ }
70
+ };
71
+ }, [
72
+ siblingsRef
73
+ ]);
74
+ // There's no risk of an infinite loop here, because
75
+ // we call setShouldRender conditionally
76
+ // eslint-disable-next-line react-hooks/exhaustive-deps
77
+ (0, _react.useLayoutEffect)(()=>{
78
+ const lastSibling = siblingsRef.current[siblingsRef.current.length - 1];
79
+ if ((_browser.browser.safari || _browser.browser.chrome) && lastSibling?.dom?.contentEditable == "false") {
80
+ setShouldRender(true);
81
+ return;
82
+ }
83
+ if (!ref.current) return;
84
+ if (!viewDescRef.current) {
85
+ viewDescRef.current = new _viewdesc.TrailingHackViewDesc(parentRef.current, [], ()=>getPos.current(), ref.current, null);
86
+ } else {
87
+ viewDescRef.current.parent = parentRef.current;
88
+ viewDescRef.current.dom = ref.current;
89
+ viewDescRef.current.getPos = ()=>getPos.current();
90
+ }
91
+ if (!siblingsRef.current.includes(viewDescRef.current)) {
92
+ siblingsRef.current.push(viewDescRef.current);
93
+ }
94
+ siblingsRef.current.sort(_viewdesc.sortViewDescs);
95
+ });
96
+ return shouldRender ? /*#__PURE__*/ _react.default.createElement("img", {
97
+ ref: ref,
98
+ className: "ProseMirror-separator"
99
+ }) : null;
100
+ }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "TextNodeView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return TextNodeView;
9
+ }
10
+ });
11
+ const _prosemirrorview = require("prosemirror-view");
12
+ const _react = require("react");
13
+ const _reactdom = require("react-dom");
14
+ const _viewdesc = require("../viewdesc.js");
15
+ const _ChildNodeViews = require("./ChildNodeViews.js");
16
+ function shallowEqual(objA, objB) {
17
+ if (objA === objB) {
18
+ return true;
19
+ }
20
+ if (!objA || !objB) {
21
+ return false;
22
+ }
23
+ const aKeys = Object.keys(objA);
24
+ const bKeys = Object.keys(objB);
25
+ const len = aKeys.length;
26
+ if (bKeys.length !== len) {
27
+ return false;
28
+ }
29
+ for(let i = 0; i < len; i++){
30
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
31
+ const key = aKeys[i];
32
+ if (objA[key] !== objB[key] || !Object.prototype.hasOwnProperty.call(objB, key)) {
33
+ return false;
34
+ }
35
+ }
36
+ return true;
37
+ }
38
+ let TextNodeView = class TextNodeView extends _react.Component {
39
+ viewDescRef = null;
40
+ renderRef = null;
41
+ updateEffect() {
42
+ const { view, decorations, siblingsRef, parentRef, getPos, node } = this.props;
43
+ // There simply is no other way to ref a text node
44
+ // eslint-disable-next-line react/no-find-dom-node
45
+ const dom = (0, _reactdom.findDOMNode)(this);
46
+ // We only need to explicitly create a CompositionViewDesc
47
+ // when a composition was started that produces a new text node.
48
+ // Otherwise we just rely on re-rendering the renderRef
49
+ if (!dom) {
50
+ if (!view?.composing) return;
51
+ this.viewDescRef = new _viewdesc.CompositionViewDesc(parentRef.current, ()=>getPos.current(), // These are just placeholders/dummies. We can't
52
+ // actually find the correct DOM nodes from here,
53
+ // so we let our parent do it.
54
+ // Passing a valid element here just so that the
55
+ // ViewDesc constructor doesn't blow up.
56
+ document.createElement("div"), document.createTextNode(node.text ?? ""), node.text ?? "");
57
+ return;
58
+ }
59
+ let textNode = dom;
60
+ while(textNode.firstChild){
61
+ textNode = textNode.firstChild;
62
+ }
63
+ if (!this.viewDescRef || this.viewDescRef instanceof _viewdesc.CompositionViewDesc) {
64
+ this.viewDescRef = new _viewdesc.TextViewDesc(undefined, [], ()=>getPos.current(), node, decorations, _prosemirrorview.DecorationSet.empty, dom, textNode);
65
+ } else {
66
+ this.viewDescRef.parent = parentRef.current;
67
+ this.viewDescRef.children = [];
68
+ this.viewDescRef.node = node;
69
+ this.viewDescRef.getPos = ()=>getPos.current();
70
+ this.viewDescRef.outerDeco = decorations;
71
+ this.viewDescRef.innerDeco = _prosemirrorview.DecorationSet.empty;
72
+ this.viewDescRef.dom = dom;
73
+ // @ts-expect-error We have our own ViewDesc implementations
74
+ this.viewDescRef.dom.pmViewDesc = this.viewDescRef;
75
+ this.viewDescRef.nodeDOM = textNode;
76
+ }
77
+ if (!siblingsRef.current.includes(this.viewDescRef)) {
78
+ siblingsRef.current.push(this.viewDescRef);
79
+ }
80
+ siblingsRef.current.sort(_viewdesc.sortViewDescs);
81
+ }
82
+ shouldComponentUpdate(nextProps) {
83
+ return !shallowEqual(this.props, nextProps);
84
+ }
85
+ componentDidMount() {
86
+ this.updateEffect();
87
+ }
88
+ componentDidUpdate() {
89
+ this.updateEffect();
90
+ }
91
+ componentWillUnmount() {
92
+ const { siblingsRef } = this.props;
93
+ if (!this.viewDescRef) return;
94
+ if (siblingsRef.current.includes(this.viewDescRef)) {
95
+ const index = siblingsRef.current.indexOf(this.viewDescRef);
96
+ siblingsRef.current.splice(index, 1);
97
+ }
98
+ }
99
+ render() {
100
+ const { view, getPos, node, decorations } = this.props;
101
+ // During a composition, it's crucial that we don't try to
102
+ // update the DOM that the user is working in. If there's
103
+ // an active composition and the selection is in this node,
104
+ // we freeze the DOM of this element so that it doesn't
105
+ // interrupt the composition
106
+ if (view?.composing && view.state.selection.from >= getPos.current() && view.state.selection.from <= getPos.current() + node.nodeSize) {
107
+ return this.renderRef;
108
+ }
109
+ this.renderRef = decorations.reduce(_ChildNodeViews.wrapInDeco, node.text);
110
+ return this.renderRef;
111
+ }
112
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "TrailingHackView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return TrailingHackView;
9
+ }
10
+ });
11
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
13
+ const _viewdesc = require("../viewdesc.js");
14
+ function _getRequireWildcardCache(nodeInterop) {
15
+ if (typeof WeakMap !== "function") return null;
16
+ var cacheBabelInterop = new WeakMap();
17
+ var cacheNodeInterop = new WeakMap();
18
+ return (_getRequireWildcardCache = function(nodeInterop) {
19
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
20
+ })(nodeInterop);
21
+ }
22
+ function _interop_require_wildcard(obj, nodeInterop) {
23
+ if (!nodeInterop && obj && obj.__esModule) {
24
+ return obj;
25
+ }
26
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
27
+ return {
28
+ default: obj
29
+ };
30
+ }
31
+ var cache = _getRequireWildcardCache(nodeInterop);
32
+ if (cache && cache.has(obj)) {
33
+ return cache.get(obj);
34
+ }
35
+ var newObj = {
36
+ __proto__: null
37
+ };
38
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
39
+ for(var key in obj){
40
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
41
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
42
+ if (desc && (desc.get || desc.set)) {
43
+ Object.defineProperty(newObj, key, desc);
44
+ } else {
45
+ newObj[key] = obj[key];
46
+ }
47
+ }
48
+ }
49
+ newObj.default = obj;
50
+ if (cache) {
51
+ cache.set(obj, newObj);
52
+ }
53
+ return newObj;
54
+ }
55
+ function TrailingHackView(param) {
56
+ let { getPos } = param;
57
+ const { siblingsRef, parentRef } = (0, _react.useContext)(_ChildDescriptorsContext.ChildDescriptorsContext);
58
+ const viewDescRef = (0, _react.useRef)(null);
59
+ const ref = (0, _react.useRef)(null);
60
+ (0, _react.useLayoutEffect)(()=>{
61
+ const siblings = siblingsRef.current;
62
+ return ()=>{
63
+ if (!viewDescRef.current) return;
64
+ if (siblings.includes(viewDescRef.current)) {
65
+ const index = siblings.indexOf(viewDescRef.current);
66
+ siblings.splice(index, 1);
67
+ }
68
+ };
69
+ }, [
70
+ siblingsRef
71
+ ]);
72
+ (0, _react.useLayoutEffect)(()=>{
73
+ if (!ref.current) return;
74
+ if (!viewDescRef.current) {
75
+ viewDescRef.current = new _viewdesc.TrailingHackViewDesc(parentRef.current, [], ()=>getPos.current(), ref.current, null);
76
+ } else {
77
+ viewDescRef.current.parent = parentRef.current;
78
+ viewDescRef.current.dom = ref.current;
79
+ viewDescRef.current.getPos = ()=>getPos.current();
80
+ }
81
+ if (!siblingsRef.current.includes(viewDescRef.current)) {
82
+ siblingsRef.current.push(viewDescRef.current);
83
+ }
84
+ siblingsRef.current.sort(_viewdesc.sortViewDescs);
85
+ });
86
+ return /*#__PURE__*/ _react.default.createElement("br", {
87
+ ref: ref,
88
+ className: "ProseMirror-trailingBreak"
89
+ });
90
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "WidgetView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return WidgetView;
9
+ }
10
+ });
11
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
13
+ const _viewdesc = require("../viewdesc.js");
14
+ function _getRequireWildcardCache(nodeInterop) {
15
+ if (typeof WeakMap !== "function") return null;
16
+ var cacheBabelInterop = new WeakMap();
17
+ var cacheNodeInterop = new WeakMap();
18
+ return (_getRequireWildcardCache = function(nodeInterop) {
19
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
20
+ })(nodeInterop);
21
+ }
22
+ function _interop_require_wildcard(obj, nodeInterop) {
23
+ if (!nodeInterop && obj && obj.__esModule) {
24
+ return obj;
25
+ }
26
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
27
+ return {
28
+ default: obj
29
+ };
30
+ }
31
+ var cache = _getRequireWildcardCache(nodeInterop);
32
+ if (cache && cache.has(obj)) {
33
+ return cache.get(obj);
34
+ }
35
+ var newObj = {
36
+ __proto__: null
37
+ };
38
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
39
+ for(var key in obj){
40
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
41
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
42
+ if (desc && (desc.get || desc.set)) {
43
+ Object.defineProperty(newObj, key, desc);
44
+ } else {
45
+ newObj[key] = obj[key];
46
+ }
47
+ }
48
+ }
49
+ newObj.default = obj;
50
+ if (cache) {
51
+ cache.set(obj, newObj);
52
+ }
53
+ return newObj;
54
+ }
55
+ function WidgetView(param) {
56
+ let { widget, getPos } = param;
57
+ const { siblingsRef, parentRef } = (0, _react.useContext)(_ChildDescriptorsContext.ChildDescriptorsContext);
58
+ const viewDescRef = (0, _react.useRef)(null);
59
+ const getPosFunc = (0, _react.useRef)(()=>getPos.current()).current;
60
+ const domRef = (0, _react.useRef)(null);
61
+ (0, _react.useLayoutEffect)(()=>{
62
+ const siblings = siblingsRef.current;
63
+ return ()=>{
64
+ if (!viewDescRef.current) return;
65
+ if (siblings.includes(viewDescRef.current)) {
66
+ const index = siblings.indexOf(viewDescRef.current);
67
+ siblings.splice(index, 1);
68
+ }
69
+ };
70
+ }, [
71
+ siblingsRef
72
+ ]);
73
+ (0, _react.useLayoutEffect)(()=>{
74
+ if (!domRef.current) return;
75
+ if (!viewDescRef.current) {
76
+ viewDescRef.current = new _viewdesc.WidgetViewDesc(parentRef.current, ()=>getPos.current(), widget, domRef.current);
77
+ } else {
78
+ viewDescRef.current.parent = parentRef.current;
79
+ viewDescRef.current.widget = widget;
80
+ viewDescRef.current.getPos = ()=>getPos.current();
81
+ viewDescRef.current.dom = domRef.current;
82
+ }
83
+ if (!siblingsRef.current.includes(viewDescRef.current)) {
84
+ siblingsRef.current.push(viewDescRef.current);
85
+ }
86
+ siblingsRef.current.sort(_viewdesc.sortViewDescs);
87
+ });
88
+ const { Component } = widget.type;
89
+ return Component && /*#__PURE__*/ _react.default.createElement(Component, {
90
+ ref: domRef,
91
+ widget: widget,
92
+ getPos: getPosFunc,
93
+ contentEditable: false
94
+ });
95
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });