@handlewithcare/react-prosemirror 2.9.0-tiptap.24 → 3.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 (143) hide show
  1. package/README.md +140 -75
  2. package/dist/cjs/StaticEditorView.js +0 -3
  3. package/dist/cjs/components/ChildNodeViews.js +4 -4
  4. package/dist/cjs/components/NativeWidgetView.js +2 -2
  5. package/dist/cjs/components/OutputSpec.js +10 -3
  6. package/dist/cjs/components/ProseMirror.js +11 -17
  7. package/dist/cjs/components/SeparatorHackView.js +2 -2
  8. package/dist/cjs/components/TrailingHackView.js +2 -2
  9. package/dist/cjs/components/WidgetView.js +2 -2
  10. package/dist/cjs/components/marks/DefaultMarkView.js +2 -1
  11. package/dist/cjs/components/marks/MarkView.js +2 -2
  12. package/dist/cjs/components/marks/{CustomMarkView.js → MarkViewConstructorView.js} +16 -7
  13. package/dist/cjs/components/marks/ReactMarkView.js +26 -6
  14. package/dist/cjs/components/nodes/DefaultNodeView.js +3 -2
  15. package/dist/cjs/components/nodes/DocNodeView.js +7 -6
  16. package/dist/cjs/components/nodes/NodeView.js +17 -6
  17. package/dist/cjs/components/nodes/{CustomNodeView.js → NodeViewConstructorView.js} +22 -9
  18. package/dist/cjs/components/nodes/ReactNodeView.js +59 -17
  19. package/dist/cjs/contexts/{ChildDescriptorsContext.js → ChildDescriptionsContext.js} +3 -3
  20. package/dist/cjs/hooks/useEditor.js +0 -4
  21. package/dist/cjs/hooks/useEditorEventCallback.js +1 -1
  22. package/dist/cjs/hooks/useMarkViewDescription.js +24 -21
  23. package/dist/cjs/hooks/useNodePos.js +18 -0
  24. package/dist/cjs/hooks/{useNodeViewDescriptor.js → useNodeViewDescription.js} +30 -25
  25. package/dist/cjs/index.js +8 -0
  26. package/dist/cjs/refs.js +28 -0
  27. package/dist/cjs/viewdesc.js +18 -5
  28. package/dist/esm/StaticEditorView.js +0 -3
  29. package/dist/esm/components/ChildNodeViews.js +4 -4
  30. package/dist/esm/components/NativeWidgetView.js +2 -2
  31. package/dist/esm/components/OutputSpec.js +10 -3
  32. package/dist/esm/components/ProseMirror.js +11 -17
  33. package/dist/esm/components/SeparatorHackView.js +2 -2
  34. package/dist/esm/components/TrailingHackView.js +2 -2
  35. package/dist/esm/components/WidgetView.js +2 -2
  36. package/dist/esm/components/marks/DefaultMarkView.js +2 -1
  37. package/dist/esm/components/marks/MarkView.js +2 -2
  38. package/dist/esm/components/marks/{CustomMarkView.js → MarkViewConstructorView.js} +14 -5
  39. package/dist/esm/components/marks/ReactMarkView.js +26 -6
  40. package/dist/esm/components/nodes/DefaultNodeView.js +3 -2
  41. package/dist/esm/components/nodes/DocNodeView.js +8 -7
  42. package/dist/esm/components/nodes/NodeView.js +7 -4
  43. package/dist/esm/components/nodes/{CustomNodeView.js → NodeViewConstructorView.js} +20 -7
  44. package/dist/esm/components/nodes/ReactNodeView.js +59 -17
  45. package/dist/esm/contexts/{ChildDescriptorsContext.js → ChildDescriptionsContext.js} +1 -1
  46. package/dist/esm/hooks/useEditor.js +0 -4
  47. package/dist/esm/hooks/useEditorEffect.js +0 -4
  48. package/dist/esm/hooks/useEditorEventCallback.js +6 -4
  49. package/dist/esm/hooks/useMarkViewDescription.js +26 -23
  50. package/dist/esm/hooks/useNodePos.js +15 -0
  51. package/dist/esm/hooks/{useNodeViewDescriptor.js → useNodeViewDescription.js} +29 -24
  52. package/dist/esm/index.js +2 -0
  53. package/dist/esm/refs.js +18 -0
  54. package/dist/esm/viewdesc.js +13 -6
  55. package/dist/tsconfig.tsbuildinfo +1 -1
  56. package/dist/types/AbstractEditorView.d.ts +0 -1
  57. package/dist/types/StaticEditorView.d.ts +0 -1
  58. package/dist/types/components/OutputSpec.d.ts +2 -1
  59. package/dist/types/components/ProseMirror.d.ts +3 -11
  60. package/dist/types/components/ProseMirrorDoc.d.ts +2 -2
  61. package/dist/types/components/marks/DefaultMarkView.d.ts +1 -1
  62. package/dist/types/components/marks/MarkViewComponentProps.d.ts +4 -3
  63. package/dist/types/components/marks/{CustomMarkView.d.ts → MarkViewConstructorView.d.ts} +1 -1
  64. package/dist/types/components/nodes/DefaultNodeView.d.ts +1 -1
  65. package/dist/types/components/nodes/DocNodeView.d.ts +2 -2
  66. package/dist/types/components/nodes/NodeView.d.ts +1 -0
  67. package/dist/types/components/nodes/NodeViewComponentProps.d.ts +4 -3
  68. package/dist/types/components/{CustomNodeView.d.ts → nodes/NodeViewConstructorView.d.ts} +1 -1
  69. package/dist/types/constants.d.ts +1 -1
  70. package/dist/types/contexts/{ChildDescriptorsContext.d.ts → ChildDescriptionsContext.d.ts} +1 -1
  71. package/dist/types/hooks/useEditorEffect.d.ts +0 -4
  72. package/dist/types/hooks/useEditorEventCallback.d.ts +6 -4
  73. package/dist/types/hooks/useMarkViewDescription.d.ts +6 -9
  74. package/dist/types/hooks/useNodePos.d.ts +9 -0
  75. package/dist/types/hooks/{useNodeViewDescriptor.d.ts → useNodeViewDescription.d.ts} +5 -9
  76. package/dist/types/index.d.ts +2 -0
  77. package/dist/types/props.d.ts +26 -26
  78. package/dist/types/refs.d.ts +2 -0
  79. package/dist/types/viewdesc.d.ts +4 -0
  80. package/package.json +12 -20
  81. package/dist/cjs/components/CustomNodeView.js +0 -132
  82. package/dist/cjs/components/DefaultNodeView.js +0 -67
  83. package/dist/cjs/components/DocNodeView.js +0 -96
  84. package/dist/cjs/components/MarkView.js +0 -119
  85. package/dist/cjs/components/NodeView.js +0 -86
  86. package/dist/cjs/components/NodeViewComponentProps.js +0 -4
  87. package/dist/cjs/components/ReactNodeView.js +0 -174
  88. package/dist/cjs/components/marks/OldMarkView.js +0 -120
  89. package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +0 -26
  90. package/dist/cjs/tiptap/TiptapEditor.js +0 -34
  91. package/dist/cjs/tiptap/TiptapEditorContent.js +0 -142
  92. package/dist/cjs/tiptap/TiptapEditorView.js +0 -118
  93. package/dist/cjs/tiptap/TiptapNodeView.js +0 -26
  94. package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +0 -12
  95. package/dist/cjs/tiptap/extensions/ReactProseMirror.js +0 -40
  96. package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +0 -15
  97. package/dist/cjs/tiptap/hooks/useTiptapEditor.js +0 -43
  98. package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +0 -35
  99. package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +0 -35
  100. package/dist/cjs/tiptap/index.js +0 -48
  101. package/dist/cjs/tiptap/tiptapNodeView.js +0 -237
  102. package/dist/esm/components/CustomNodeView.js +0 -81
  103. package/dist/esm/components/DefaultNodeView.js +0 -16
  104. package/dist/esm/components/DocNodeView.js +0 -45
  105. package/dist/esm/components/MarkView.js +0 -68
  106. package/dist/esm/components/NodeView.js +0 -35
  107. package/dist/esm/components/NodeViewComponentProps.js +0 -1
  108. package/dist/esm/components/ReactNodeView.js +0 -123
  109. package/dist/esm/components/marks/OldMarkView.js +0 -69
  110. package/dist/esm/tiptap/ReactProseMirrorNodeView.js +0 -22
  111. package/dist/esm/tiptap/TiptapEditor.js +0 -24
  112. package/dist/esm/tiptap/TiptapEditorContent.js +0 -91
  113. package/dist/esm/tiptap/TiptapEditorView.js +0 -69
  114. package/dist/esm/tiptap/TiptapNodeView.js +0 -22
  115. package/dist/esm/tiptap/contexts/TiptapEditorContext.js +0 -2
  116. package/dist/esm/tiptap/extensions/ReactProseMirror.js +0 -30
  117. package/dist/esm/tiptap/hooks/useIsInReactProseMirror.js +0 -5
  118. package/dist/esm/tiptap/hooks/useTiptapEditor.js +0 -33
  119. package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +0 -42
  120. package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +0 -35
  121. package/dist/esm/tiptap/index.js +0 -9
  122. package/dist/esm/tiptap/tiptapNodeView.js +0 -205
  123. package/dist/types/components/DefaultNodeView.d.ts +0 -3
  124. package/dist/types/components/DocNodeView.d.ts +0 -12
  125. package/dist/types/components/MarkView.d.ts +0 -9
  126. package/dist/types/components/NodeView.d.ts +0 -11
  127. package/dist/types/components/NodeViewComponentProps.d.ts +0 -12
  128. package/dist/types/components/ReactNodeView.d.ts +0 -13
  129. package/dist/types/components/marks/OldMarkView.d.ts +0 -10
  130. package/dist/types/components/nodes/CustomNodeView.d.ts +0 -12
  131. package/dist/types/tiptap/ReactProseMirrorNodeView.d.ts +0 -15
  132. package/dist/types/tiptap/TiptapEditor.d.ts +0 -6
  133. package/dist/types/tiptap/TiptapEditorContent.d.ts +0 -19
  134. package/dist/types/tiptap/TiptapEditorView.d.ts +0 -16
  135. package/dist/types/tiptap/TiptapNodeView.d.ts +0 -15
  136. package/dist/types/tiptap/contexts/TiptapEditorContext.d.ts +0 -6
  137. package/dist/types/tiptap/extensions/ReactProseMirror.d.ts +0 -9
  138. package/dist/types/tiptap/hooks/useIsInReactProseMirror.d.ts +0 -1
  139. package/dist/types/tiptap/hooks/useTiptapEditor.d.ts +0 -4
  140. package/dist/types/tiptap/hooks/useTiptapEditorEffect.d.ts +0 -21
  141. package/dist/types/tiptap/hooks/useTiptapEditorEventCallback.d.ts +0 -13
  142. package/dist/types/tiptap/index.d.ts +0 -9
  143. package/dist/types/tiptap/tiptapNodeView.d.ts +0 -50
@@ -2,16 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "CustomMarkView", {
5
+ Object.defineProperty(exports, "MarkViewConstructorView", {
6
6
  enumerable: true,
7
7
  get: function() {
8
- return CustomMarkView;
8
+ return MarkViewConstructorView;
9
9
  }
10
10
  });
11
11
  const _prosemirrormodel = require("prosemirror-model");
12
12
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13
13
  const _reactdom = require("react-dom");
14
- const _ChildDescriptorsContext = require("../../contexts/ChildDescriptorsContext.js");
14
+ const _ChildDescriptionsContext = require("../../contexts/ChildDescriptionsContext.js");
15
+ const _useForceUpdate = require("../../hooks/useForceUpdate.js");
15
16
  const _useMarkViewDescription = require("../../hooks/useMarkViewDescription.js");
16
17
  function _getRequireWildcardCache(nodeInterop) {
17
18
  if (typeof WeakMap !== "function") return null;
@@ -54,14 +55,18 @@ function _interop_require_wildcard(obj, nodeInterop) {
54
55
  }
55
56
  return newObj;
56
57
  }
57
- const CustomMarkView = /*#__PURE__*/ (0, _react.memo)(function CustomMarkView(param) {
58
+ const MarkViewConstructorView = /*#__PURE__*/ (0, _react.memo)(function MarkViewConstructorView(param) {
58
59
  let { constructor, mark, inline, getPos, children } = param;
59
60
  const ref = (0, _react.useRef)(null);
60
61
  const innerRef = (0, _react.useRef)(null);
62
+ const forceUpdate = (0, _useForceUpdate.useForceUpdate)();
61
63
  const markProps = (0, _react.useMemo)(()=>({
62
64
  mark,
63
65
  inline,
64
- getPos
66
+ getPos,
67
+ contentDOMRef: {
68
+ current: null
69
+ }
65
70
  }), [
66
71
  mark,
67
72
  inline,
@@ -81,13 +86,17 @@ const CustomMarkView = /*#__PURE__*/ (0, _react.memo)(function CustomMarkView(pa
81
86
  }
82
87
  return markView;
83
88
  };
84
- const { childContextValue, contentDOM } = (0, _useMarkViewDescription.useMarkViewDescription)(ref, function() {
89
+ const { childContextValue, contentDOM } = (0, _useMarkViewDescription.useMarkViewDescription)(()=>ref.current, (markView)=>markView?.contentDOM ?? null, function() {
85
90
  for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
86
91
  args[_key] = arguments[_key];
87
92
  }
88
93
  const markView = createMarkView(...args);
89
94
  const dom = markView.dom;
90
95
  const wrapperDOM = innerRef.current ?? ref.current;
96
+ wrapperDOM.appendChild(dom);
97
+ // Force a re-render so that we properly create
98
+ // a portal into the contentDOM/dom
99
+ forceUpdate();
91
100
  return {
92
101
  ...markView,
93
102
  destroy () {
@@ -101,7 +110,7 @@ const CustomMarkView = /*#__PURE__*/ (0, _react.memo)(function CustomMarkView(pa
101
110
  const props = {
102
111
  ref: innerRef
103
112
  };
104
- return /*#__PURE__*/ _react.default.createElement(Component, props, contentDOM ? /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
113
+ return /*#__PURE__*/ _react.default.createElement(Component, props, contentDOM ? /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ _react.default.createElement(_ChildDescriptionsContext.ChildDescriptionsContext.Provider, {
105
114
  value: childContextValue
106
115
  }, children), contentDOM) : null);
107
116
  });
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "ReactMarkView", {
9
9
  }
10
10
  });
11
11
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
- const _ChildDescriptorsContext = require("../../contexts/ChildDescriptorsContext.js");
12
+ const _ChildDescriptionsContext = require("../../contexts/ChildDescriptionsContext.js");
13
13
  const _IgnoreMutationContext = require("../../contexts/IgnoreMutationContext.js");
14
14
  const _useMarkViewDescription = require("../../hooks/useMarkViewDescription.js");
15
15
  function _getRequireWildcardCache(nodeInterop) {
@@ -56,6 +56,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
56
56
  const ReactMarkView = /*#__PURE__*/ (0, _react.memo)(function ReactMarkView(param) {
57
57
  let { component: Component, mark, inline, getPos, children } = param;
58
58
  const ref = (0, _react.useRef)(null);
59
+ const contentDOMRef = (0, _react.useRef)(null);
59
60
  const ignoreMutationRef = (0, _react.useRef)(null);
60
61
  const setIgnoreMutation = (0, _react.useCallback)((handler)=>{
61
62
  ignoreMutationRef.current = handler;
@@ -66,7 +67,7 @@ const ReactMarkView = /*#__PURE__*/ (0, _react.memo)(function ReactMarkView(para
66
67
  };
67
68
  };
68
69
  }, []);
69
- const markProps = (0, _react.useMemo)(()=>({
70
+ const markViewDescProps = (0, _react.useMemo)(()=>({
70
71
  mark,
71
72
  getPos,
72
73
  inline
@@ -75,7 +76,7 @@ const ReactMarkView = /*#__PURE__*/ (0, _react.memo)(function ReactMarkView(para
75
76
  inline,
76
77
  mark
77
78
  ]);
78
- const { childContextValue } = (0, _useMarkViewDescription.useMarkViewDescription)(ref, ()=>({
79
+ const { childContextValue, refUpdated } = (0, _useMarkViewDescription.useMarkViewDescription)(()=>ref.current, ()=>contentDOMRef.current ?? ref.current, ()=>({
79
80
  dom: ref.current,
80
81
  ignoreMutation (mutation) {
81
82
  const ignoreMutation = ignoreMutationRef.current;
@@ -84,14 +85,33 @@ const ReactMarkView = /*#__PURE__*/ (0, _react.memo)(function ReactMarkView(para
84
85
  }
85
86
  return false;
86
87
  }
87
- }), markProps);
88
+ }), markViewDescProps);
89
+ const setDOM = (0, _react.useCallback)((el)=>{
90
+ ref.current = el;
91
+ refUpdated();
92
+ }, [
93
+ refUpdated
94
+ ]);
95
+ const setContentDOM = (0, _react.useCallback)((el)=>{
96
+ contentDOMRef.current = el;
97
+ refUpdated();
98
+ }, [
99
+ refUpdated
100
+ ]);
101
+ const markProps = (0, _react.useMemo)(()=>({
102
+ ...markViewDescProps,
103
+ contentDOMRef: setContentDOM
104
+ }), [
105
+ markViewDescProps,
106
+ setContentDOM
107
+ ]);
88
108
  const props = {
89
109
  markProps,
90
- ref
110
+ ref: setDOM
91
111
  };
92
112
  return /*#__PURE__*/ _react.default.createElement(_IgnoreMutationContext.IgnoreMutationContext.Provider, {
93
113
  value: setIgnoreMutation
94
- }, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
114
+ }, /*#__PURE__*/ _react.default.createElement(_ChildDescriptionsContext.ChildDescriptionsContext.Provider, {
95
115
  value: childContextValue
96
116
  }, /*#__PURE__*/ _react.default.createElement(Component, props, children)));
97
117
  });
@@ -52,7 +52,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
52
52
  return newObj;
53
53
  }
54
54
  const DefaultNodeView = /*#__PURE__*/ (0, _react.forwardRef)(function DefaultNodeView(param, ref) {
55
- let { nodeProps: { node }, children, ...props } = param;
55
+ let { nodeProps: { node, contentDOMRef }, children, ...props } = param;
56
56
  const spec = (0, _react.useMemo)(()=>node.type.spec.toDOM?.(node), [
57
57
  node
58
58
  ]);
@@ -62,6 +62,7 @@ const DefaultNodeView = /*#__PURE__*/ (0, _react.forwardRef)(function DefaultNod
62
62
  return /*#__PURE__*/ _react.default.createElement(_OutputSpec.OutputSpec, {
63
63
  ...props,
64
64
  outputSpec: spec,
65
- ref: ref
65
+ ref: ref,
66
+ contentDOMRef: contentDOMRef
66
67
  }, children);
67
68
  });
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "DocNodeView", {
9
9
  }
10
10
  });
11
11
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
- const _ChildDescriptorsContext = require("../../contexts/ChildDescriptorsContext.js");
13
- const _useNodeViewDescriptor = require("../../hooks/useNodeViewDescriptor.js");
12
+ const _ChildDescriptionsContext = require("../../contexts/ChildDescriptionsContext.js");
13
+ const _useNodeViewDescription = require("../../hooks/useNodeViewDescription.js");
14
14
  const _ChildNodeViews = require("../ChildNodeViews.js");
15
15
  function _getRequireWildcardCache(nodeInterop) {
16
16
  if (typeof WeakMap !== "function") return null;
@@ -62,14 +62,15 @@ const DocNodeView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forw
62
62
  node,
63
63
  getPos,
64
64
  decorations,
65
- innerDecorations
65
+ innerDecorations,
66
+ contentDOMRef: innerRef
66
67
  }), [
67
68
  node,
68
69
  getPos,
69
70
  decorations,
70
71
  innerDecorations
71
72
  ]);
72
- const { childContextValue } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(innerRef, ()=>{
73
+ const { childContextValue } = (0, _useNodeViewDescription.useNodeViewDescription)(()=>innerRef.current, ()=>innerRef.current, ()=>{
73
74
  const dom = innerRef.current;
74
75
  return {
75
76
  dom,
@@ -79,7 +80,7 @@ const DocNodeView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forw
79
80
  }
80
81
  };
81
82
  }, nodeProps);
82
- const children = /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
83
+ const children = /*#__PURE__*/ _react.default.createElement(_ChildDescriptionsContext.ChildDescriptionsContext.Provider, {
83
84
  value: childContextValue
84
85
  }, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
85
86
  getPos: getPos,
@@ -91,6 +92,6 @@ const DocNodeView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forw
91
92
  suppressContentEditableWarning: true,
92
93
  ref: innerRef
93
94
  };
94
- const element = as ? /*#__PURE__*/ (0, _react.cloneElement)(as, props, children) : /*#__PURE__*/ (0, _react.createElement)("div", props, children);
95
+ const element = as ? /*#__PURE__*/ (0, _react.createElement)(as, props, children) : /*#__PURE__*/ (0, _react.createElement)("div", props, children);
95
96
  return nodeProps.decorations.reduce(_ChildNodeViews.wrapInDeco, element);
96
97
  }));
@@ -2,16 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "NodeView", {
6
- enumerable: true,
7
- get: function() {
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
+ GetPosContext: function() {
13
+ return GetPosContext;
14
+ },
15
+ NodeView: function() {
8
16
  return NodeView;
9
17
  }
10
18
  });
11
19
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
20
  const _NodeViewContext = require("../../contexts/NodeViewContext.js");
13
- const _CustomNodeView = require("./CustomNodeView.js");
14
21
  const _DefaultNodeView = require("./DefaultNodeView.js");
22
+ const _NodeViewConstructorView = require("./NodeViewConstructorView.js");
15
23
  const _ReactNodeView = require("./ReactNodeView.js");
16
24
  function _getRequireWildcardCache(nodeInterop) {
17
25
  if (typeof WeakMap !== "function") return null;
@@ -65,7 +73,7 @@ const NodeView = /*#__PURE__*/ (0, _react.memo)(function NodeView(props) {
65
73
  const Component = (0, _react.useMemo)(()=>{
66
74
  if (constructor) {
67
75
  return function NodeView(props) {
68
- return /*#__PURE__*/ _react.default.createElement(_CustomNodeView.CustomNodeView, {
76
+ return /*#__PURE__*/ _react.default.createElement(_NodeViewConstructorView.NodeViewConstructorView, {
69
77
  constructor: constructor,
70
78
  ...props
71
79
  });
@@ -82,5 +90,8 @@ const NodeView = /*#__PURE__*/ (0, _react.memo)(function NodeView(props) {
82
90
  constructor,
83
91
  component
84
92
  ]);
85
- return /*#__PURE__*/ _react.default.createElement(Component, props);
93
+ return /*#__PURE__*/ _react.default.createElement(GetPosContext.Provider, {
94
+ value: props.getPos
95
+ }, /*#__PURE__*/ _react.default.createElement(Component, props));
86
96
  });
97
+ const GetPosContext = /*#__PURE__*/ (0, _react.createContext)(null);
@@ -2,17 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "CustomNodeView", {
5
+ Object.defineProperty(exports, "NodeViewConstructorView", {
6
6
  enumerable: true,
7
7
  get: function() {
8
- return CustomNodeView;
8
+ return NodeViewConstructorView;
9
9
  }
10
10
  });
11
11
  const _prosemirrormodel = require("prosemirror-model");
12
12
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13
13
  const _reactdom = require("react-dom");
14
- const _ChildDescriptorsContext = require("../../contexts/ChildDescriptorsContext.js");
15
- const _useNodeViewDescriptor = require("../../hooks/useNodeViewDescriptor.js");
14
+ const _ChildDescriptionsContext = require("../../contexts/ChildDescriptionsContext.js");
15
+ const _useForceUpdate = require("../../hooks/useForceUpdate.js");
16
+ const _useNodeViewDescription = require("../../hooks/useNodeViewDescription.js");
16
17
  const _ChildNodeViews = require("../ChildNodeViews.js");
17
18
  function _getRequireWildcardCache(nodeInterop) {
18
19
  if (typeof WeakMap !== "function") return null;
@@ -55,15 +56,19 @@ function _interop_require_wildcard(obj, nodeInterop) {
55
56
  }
56
57
  return newObj;
57
58
  }
58
- const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(param) {
59
+ const NodeViewConstructorView = /*#__PURE__*/ (0, _react.memo)(function NodeViewConstructorView(param) {
59
60
  let { constructor, node, getPos, innerDeco, outerDeco } = param;
60
61
  const ref = (0, _react.useRef)(null);
61
62
  const innerRef = (0, _react.useRef)(null);
63
+ const forceUpdate = (0, _useForceUpdate.useForceUpdate)();
62
64
  const nodeProps = (0, _react.useMemo)(()=>({
63
65
  node,
64
66
  getPos,
65
67
  decorations: outerDeco,
66
- innerDecorations: innerDeco
68
+ innerDecorations: innerDeco,
69
+ contentDOMRef: {
70
+ current: null
71
+ }
67
72
  }), [
68
73
  node,
69
74
  getPos,
@@ -84,7 +89,7 @@ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(pa
84
89
  }
85
90
  return nodeView;
86
91
  };
87
- const { childContextValue, contentDOM } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(ref, function() {
92
+ const { childContextValue, contentDOM } = (0, _useNodeViewDescription.useNodeViewDescription)(()=>ref.current, (source)=>source?.contentDOM ?? null, function() {
88
93
  for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
89
94
  args[_key] = arguments[_key];
90
95
  }
@@ -101,14 +106,22 @@ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(pa
101
106
  nodeDOM.draggable = true;
102
107
  }
103
108
  }
109
+ if (contentDOM) {
110
+ // Force a re-render if we have a contentDOM,
111
+ // so that we properly create a portal into it
112
+ forceUpdate();
113
+ }
104
114
  return {
105
- ...nodeView,
106
115
  destroy () {
107
116
  if (nodeView.destroy) {
108
117
  nodeView.destroy();
109
118
  }
110
119
  wrapperDOM.removeChild(nodeDOM);
111
120
  },
121
+ dom: nodeView.dom,
122
+ contentDOM: nodeView.contentDOM,
123
+ multiType: nodeView.multiType,
124
+ update: nodeView.update?.bind(nodeView),
112
125
  selectNode: nodeView.selectNode?.bind(nodeView),
113
126
  deselectNode: nodeView.deselectNode?.bind(nodeView),
114
127
  stopEvent: nodeView.stopEvent?.bind(nodeView),
@@ -119,7 +132,7 @@ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(pa
119
132
  const props = {
120
133
  ref: innerRef
121
134
  };
122
- const children = !node.isLeaf && contentDOM ? /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
135
+ const children = !node.isLeaf && contentDOM ? /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ _react.default.createElement(_ChildDescriptionsContext.ChildDescriptionsContext.Provider, {
123
136
  value: childContextValue
124
137
  }, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
125
138
  getPos: getPos,
@@ -9,11 +9,12 @@ Object.defineProperty(exports, "ReactNodeView", {
9
9
  }
10
10
  });
11
11
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
- const _ChildDescriptorsContext = require("../../contexts/ChildDescriptorsContext.js");
12
+ const _ChildDescriptionsContext = require("../../contexts/ChildDescriptionsContext.js");
13
13
  const _IgnoreMutationContext = require("../../contexts/IgnoreMutationContext.js");
14
14
  const _SelectNodeContext = require("../../contexts/SelectNodeContext.js");
15
15
  const _StopEventContext = require("../../contexts/StopEventContext.js");
16
- const _useNodeViewDescriptor = require("../../hooks/useNodeViewDescriptor.js");
16
+ const _useForceUpdate = require("../../hooks/useForceUpdate.js");
17
+ const _useNodeViewDescription = require("../../hooks/useNodeViewDescription.js");
17
18
  const _ChildNodeViews = require("../ChildNodeViews.js");
18
19
  function _getRequireWildcardCache(nodeInterop) {
19
20
  if (typeof WeakMap !== "function") return null;
@@ -60,8 +61,10 @@ const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(para
60
61
  let { component: Component, outerDeco, getPos, node, innerDeco } = param;
61
62
  const [hasCustomSelectNode, setHasCustomSelectNode] = (0, _react.useState)(false);
62
63
  const [selected, setSelected] = (0, _react.useState)(false);
63
- const ref = (0, _react.useRef)(null);
64
- const innerRef = (0, _react.useRef)(null);
64
+ const forceUpdate = (0, _useForceUpdate.useForceUpdate)();
65
+ const domRef = (0, _react.useRef)(null);
66
+ const nodeDOMRef = (0, _react.useRef)(null);
67
+ const contentDOMRef = (0, _react.useRef)(null);
65
68
  const selectNodeRef = (0, _react.useRef)(null);
66
69
  const deselectNodeRef = (0, _react.useRef)(null);
67
70
  const stopEventRef = (0, _react.useRef)(null);
@@ -91,7 +94,7 @@ const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(para
91
94
  };
92
95
  };
93
96
  }, []);
94
- const nodeProps = (0, _react.useMemo)(()=>({
97
+ const nodeViewDescProps = (0, _react.useMemo)(()=>({
95
98
  node: node,
96
99
  getPos: getPos,
97
100
  decorations: outerDeco,
@@ -102,10 +105,10 @@ const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(para
102
105
  node,
103
106
  outerDeco
104
107
  ]);
105
- const { childContextValue, contentDOM, nodeDOM } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(ref, ()=>{
108
+ const { childContextValue, refUpdated } = (0, _useNodeViewDescription.useNodeViewDescription)(()=>domRef.current, ()=>contentDOMRef.current, ()=>{
106
109
  setSelected(false);
107
110
  return {
108
- dom: innerRef.current ?? ref.current,
111
+ dom: nodeDOMRef.current ?? domRef.current,
109
112
  update () {
110
113
  return true;
111
114
  },
@@ -113,46 +116,85 @@ const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(para
113
116
  selectNode () {
114
117
  const selectNode = selectNodeRef.current;
115
118
  if (selectNode) {
116
- selectNode.call(this);
119
+ selectNode();
117
120
  }
118
121
  setSelected(true);
119
122
  },
120
123
  deselectNode () {
121
124
  const deselectNode = deselectNodeRef.current;
122
125
  if (deselectNode) {
123
- deselectNode.call(this);
126
+ deselectNode();
124
127
  }
125
128
  setSelected(false);
126
129
  },
127
130
  stopEvent (event) {
128
131
  const stopEvent = stopEventRef.current;
129
132
  if (stopEvent) {
130
- return stopEvent.call(this, event);
133
+ return stopEvent(event);
131
134
  }
132
135
  return false;
133
136
  },
134
137
  ignoreMutation (mutation) {
135
138
  const ignoreMutation = ignoreMutationRef.current;
136
139
  if (ignoreMutation) {
137
- return ignoreMutation.call(this, mutation);
140
+ return ignoreMutation(mutation);
138
141
  }
139
142
  return false;
140
143
  }
141
144
  };
142
- }, nodeProps);
145
+ }, nodeViewDescProps);
146
+ const setDOM = (0, _react.useCallback)((el)=>{
147
+ domRef.current = el;
148
+ refUpdated();
149
+ }, [
150
+ refUpdated
151
+ ]);
152
+ const setNodeDOM = (0, _react.useCallback)((el)=>{
153
+ if (!!nodeDOMRef.current !== !!el) {
154
+ // Force a re-render if the existence of nodeDOM
155
+ // is changing, since we use its existince to set
156
+ // some props
157
+ forceUpdate();
158
+ }
159
+ nodeDOMRef.current = el;
160
+ refUpdated();
161
+ }, [
162
+ forceUpdate,
163
+ refUpdated
164
+ ]);
165
+ const setContentDOM = (0, _react.useCallback)((el)=>{
166
+ if (!!contentDOMRef.current !== !!el) {
167
+ // Force a re-render if the existence of contentDOM
168
+ // is changing, since we use its existince to set
169
+ // some props
170
+ forceUpdate();
171
+ }
172
+ contentDOMRef.current = el;
173
+ refUpdated();
174
+ }, [
175
+ forceUpdate,
176
+ refUpdated
177
+ ]);
178
+ const nodeProps = (0, _react.useMemo)(()=>({
179
+ ...nodeViewDescProps,
180
+ contentDOMRef: setContentDOM
181
+ }), [
182
+ nodeViewDescProps,
183
+ setContentDOM
184
+ ]);
143
185
  const props = {
144
186
  nodeProps,
145
- ...!contentDOM && !nodeProps.node.isText && nodeDOM?.nodeName !== "BR" ? {
187
+ ...!contentDOMRef.current && !nodeProps.node.isText && nodeDOMRef.current?.nodeName !== "BR" ? {
146
188
  contentEditable: false,
147
189
  suppressContentEditableWarning: true
148
190
  } : null,
149
191
  ...!hasCustomSelectNode && selected ? {
150
192
  className: "ProseMirror-selectednode"
151
193
  } : null,
152
- ...!hasCustomSelectNode && selected || node.type.spec.draggable ? {
194
+ ...!hasCustomSelectNode && selected || !contentDOMRef.current && !nodeProps.node.isText && domRef.current?.nodeName !== "BR" && node.type.spec.draggable ? {
153
195
  draggable: true
154
196
  } : null,
155
- ref: innerRef
197
+ ref: setNodeDOM
156
198
  };
157
199
  const children = !node.isLeaf ? /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
158
200
  getPos: getPos,
@@ -160,7 +202,7 @@ const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(para
160
202
  innerDecorations: innerDeco
161
203
  }) : null;
162
204
  const element = /*#__PURE__*/ (0, _react.cloneElement)(outerDeco.reduce(_ChildNodeViews.wrapInDeco, /*#__PURE__*/ _react.default.createElement(Component, props, children)), {
163
- ref
205
+ ref: setDOM
164
206
  });
165
207
  return /*#__PURE__*/ _react.default.createElement(_SelectNodeContext.SelectNodeContext.Provider, {
166
208
  value: setSelectNode
@@ -168,7 +210,7 @@ const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(para
168
210
  value: setStopEvent
169
211
  }, /*#__PURE__*/ _react.default.createElement(_IgnoreMutationContext.IgnoreMutationContext.Provider, {
170
212
  value: setIgnoreMutation
171
- }, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
213
+ }, /*#__PURE__*/ _react.default.createElement(_ChildDescriptionsContext.ChildDescriptionsContext.Provider, {
172
214
  value: childContextValue
173
215
  }, element))));
174
216
  });
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "ChildDescriptorsContext", {
5
+ Object.defineProperty(exports, "ChildDescriptionsContext", {
6
6
  enumerable: true,
7
7
  get: function() {
8
- return ChildDescriptorsContext;
8
+ return ChildDescriptionsContext;
9
9
  }
10
10
  });
11
11
  const _react = require("react");
12
- const ChildDescriptorsContext = (0, _react.createContext)({
12
+ const ChildDescriptionsContext = (0, _react.createContext)({
13
13
  parentRef: {
14
14
  current: undefined
15
15
  },
@@ -103,11 +103,7 @@ function useEditor(mount, options) {
103
103
  // running effects. Running effects will reattach selection
104
104
  // change listeners if the EditorView has been destroyed.
105
105
  if (view instanceof _ReactEditorView.ReactEditorView && !view.isDestroyed) {
106
- // Plugins might dispatch transactions from their
107
- // view update lifecycle hooks
108
- flushSyncRef.current = false;
109
106
  view.commitPendingEffects();
110
- flushSyncRef.current = true;
111
107
  }
112
108
  });
113
109
  view.update(directEditorProps);
@@ -31,7 +31,7 @@ function useEditorEventCallback(callback) {
31
31
  args[_key] = arguments[_key];
32
32
  }
33
33
  assertIsReactEditorView(view);
34
- return ref.current.call(this, view, ...args);
34
+ return ref.current(view, ...args);
35
35
  }, [
36
36
  view
37
37
  ]);
@@ -10,26 +10,22 @@ Object.defineProperty(exports, "useMarkViewDescription", {
10
10
  });
11
11
  const _react = require("react");
12
12
  const _ReactEditorView = require("../ReactEditorView.js");
13
- const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
13
+ const _ChildDescriptionsContext = require("../contexts/ChildDescriptionsContext.js");
14
14
  const _EditorContext = require("../contexts/EditorContext.js");
15
15
  const _viewdesc = require("../viewdesc.js");
16
16
  const _useClientLayoutEffect = require("./useClientLayoutEffect.js");
17
17
  const _useEffectEvent = require("./useEffectEvent.js");
18
- function findContentDOM(source, children, dom) {
19
- return source?.contentDOM ?? children[0]?.dom?.parentElement ?? dom;
20
- }
21
- function useMarkViewDescription(ref, constructor, props) {
18
+ function useMarkViewDescription(getDOM, getContentDOM, constructor, props) {
22
19
  const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
23
- const { parentRef, siblingsRef } = (0, _react.useContext)(_ChildDescriptorsContext.ChildDescriptorsContext);
24
- const [dom, setDOM] = (0, _react.useState)(null);
25
- const [contentDOM, setContentDOM] = (0, _react.useState)(null);
20
+ const { parentRef, siblingsRef } = (0, _react.useContext)(_ChildDescriptionsContext.ChildDescriptionsContext);
21
+ const contentDOMRef = (0, _react.useRef)(null);
26
22
  const viewDescRef = (0, _react.useRef)();
27
23
  const childrenRef = (0, _react.useRef)([]);
28
24
  const create = (0, _useEffectEvent.useEffectEvent)(()=>{
29
25
  if (!(view instanceof _ReactEditorView.ReactEditorView)) {
30
26
  return;
31
27
  }
32
- const dom = ref.current;
28
+ const dom = getDOM();
33
29
  if (!dom) {
34
30
  return;
35
31
  }
@@ -40,10 +36,9 @@ function useMarkViewDescription(ref, constructor, props) {
40
36
  }
41
37
  const parent = parentRef.current;
42
38
  const children = childrenRef.current;
43
- const contentDOM = findContentDOM(markView, children, ref.current);
44
- const viewDesc = new _viewdesc.MarkViewDesc(parent, children, getPos, mark, dom, contentDOM, markView);
45
- setDOM(dom);
46
- setContentDOM(contentDOM);
39
+ const contentDOM = getContentDOM(markView);
40
+ const viewDesc = new _viewdesc.ReactMarkViewDesc(parent, children, getPos, mark, dom, contentDOM ?? markView.dom, markView);
41
+ contentDOMRef.current = contentDOM;
47
42
  return viewDesc;
48
43
  });
49
44
  const update = (0, _useEffectEvent.useEffectEvent)(()=>{
@@ -54,12 +49,12 @@ function useMarkViewDescription(ref, constructor, props) {
54
49
  if (!viewDesc) {
55
50
  return false;
56
51
  }
57
- const dom = ref.current;
52
+ const dom = getDOM();
58
53
  if (!dom || dom !== viewDesc.dom) {
59
54
  return false;
60
55
  }
61
- const contentDOM = findContentDOM(viewDesc, viewDesc.children, dom);
62
- if (contentDOM !== viewDesc.contentDOM) {
56
+ const contentDOM = getContentDOM(viewDesc);
57
+ if (contentDOM !== (viewDesc.contentDOM ?? dom)) {
63
58
  return false;
64
59
  }
65
60
  const { mark } = props;
@@ -76,8 +71,7 @@ function useMarkViewDescription(ref, constructor, props) {
76
71
  const index = siblings.indexOf(viewDesc);
77
72
  siblings.splice(index, 1);
78
73
  }
79
- setDOM(null);
80
- setContentDOM(null);
74
+ contentDOMRef.current = null;
81
75
  });
82
76
  (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
83
77
  viewDescRef.current = create();
@@ -88,6 +82,16 @@ function useMarkViewDescription(ref, constructor, props) {
88
82
  create,
89
83
  destroy
90
84
  ]);
85
+ const refUpdated = (0, _react.useCallback)(()=>{
86
+ if (!update()) {
87
+ destroy();
88
+ viewDescRef.current = create();
89
+ }
90
+ }, [
91
+ create,
92
+ destroy,
93
+ update
94
+ ]);
91
95
  (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
92
96
  if (!update()) {
93
97
  destroy();
@@ -118,8 +122,7 @@ function useMarkViewDescription(ref, constructor, props) {
118
122
  ]);
119
123
  return {
120
124
  childContextValue,
121
- dom,
122
- contentDOM,
123
- ref
125
+ contentDOM: contentDOMRef.current ?? viewDescRef.current?.dom,
126
+ refUpdated
124
127
  };
125
128
  }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useNodePos", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useNodePos;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const _NodeView = require("../components/nodes/NodeView.js");
13
+ const _useEditorState = require("./useEditorState.js");
14
+ function useNodePos() {
15
+ (0, _useEditorState.useEditorState)();
16
+ const getPos = (0, _react.useContext)(_NodeView.GetPosContext);
17
+ return getPos();
18
+ }