@handlewithcare/react-prosemirror 2.4.12 → 2.5.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 (127) hide show
  1. package/dist/cjs/AbstractEditorView.js +4 -0
  2. package/dist/cjs/ReactEditorView.js +156 -0
  3. package/dist/cjs/StaticEditorView.js +86 -0
  4. package/dist/cjs/components/ChildNodeViews.js +59 -30
  5. package/dist/cjs/components/CustomNodeView.js +9 -25
  6. package/dist/cjs/components/DocNodeView.js +6 -15
  7. package/dist/cjs/components/MarkView.js +1 -2
  8. package/dist/cjs/components/NativeWidgetView.js +2 -3
  9. package/dist/cjs/components/NodeView.js +1 -1
  10. package/dist/cjs/components/ProseMirror.js +11 -14
  11. package/dist/cjs/components/ReactNodeView.js +3 -4
  12. package/dist/cjs/components/SeparatorHackView.js +1 -2
  13. package/dist/cjs/components/TextNodeView.js +4 -5
  14. package/dist/cjs/components/TrailingHackView.js +1 -2
  15. package/dist/cjs/components/WidgetView.js +2 -4
  16. package/dist/cjs/constants.js +33 -0
  17. package/dist/cjs/hooks/useEditor.js +32 -228
  18. package/dist/cjs/hooks/useEditorEffect.js +2 -2
  19. package/dist/cjs/hooks/useEditorEventCallback.js +8 -5
  20. package/dist/cjs/hooks/useNodeViewDescriptor.js +10 -10
  21. package/dist/cjs/hooks/useReactKeys.js +1 -1
  22. package/dist/cjs/testing/editorViewTestHelpers.js +0 -2
  23. package/dist/cjs/viewdesc.js +10 -9
  24. package/dist/esm/AbstractEditorView.js +1 -0
  25. package/dist/esm/ReactEditorView.js +156 -0
  26. package/dist/esm/StaticEditorView.js +76 -0
  27. package/dist/esm/components/ChildNodeViews.js +60 -32
  28. package/dist/esm/components/CustomNodeView.js +9 -25
  29. package/dist/esm/components/DocNodeView.js +6 -15
  30. package/dist/esm/components/MarkView.js +1 -2
  31. package/dist/esm/components/NativeWidgetView.js +2 -3
  32. package/dist/esm/components/NodeView.js +1 -1
  33. package/dist/esm/components/ProseMirror.js +11 -14
  34. package/dist/esm/components/ReactNodeView.js +3 -4
  35. package/dist/esm/components/SeparatorHackView.js +1 -2
  36. package/dist/esm/components/TextNodeView.js +4 -5
  37. package/dist/esm/components/TrailingHackView.js +1 -2
  38. package/dist/esm/components/WidgetView.js +2 -4
  39. package/dist/esm/constants.js +15 -0
  40. package/dist/esm/hooks/useEditor.js +28 -217
  41. package/dist/esm/hooks/useEditorEffect.js +2 -2
  42. package/dist/esm/hooks/useEditorEventCallback.js +8 -5
  43. package/dist/esm/hooks/useNodeViewDescriptor.js +10 -10
  44. package/dist/esm/hooks/useReactKeys.js +1 -1
  45. package/dist/esm/testing/editorViewTestHelpers.js +0 -2
  46. package/dist/esm/viewdesc.js +3 -2
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/dist/types/AbstractEditorView.d.ts +27 -0
  49. package/dist/types/ReactEditorView.d.ts +79 -0
  50. package/dist/types/StaticEditorView.d.ts +24 -0
  51. package/dist/types/components/ChildNodeViews.d.ts +2 -2
  52. package/dist/types/components/CustomNodeView.d.ts +2 -2
  53. package/dist/types/components/DocNodeView.d.ts +2 -5
  54. package/dist/types/components/MarkView.d.ts +2 -2
  55. package/dist/types/components/NativeWidgetView.d.ts +2 -2
  56. package/dist/types/components/NodeView.d.ts +2 -2
  57. package/dist/types/components/ReactNodeView.d.ts +2 -2
  58. package/dist/types/components/SeparatorHackView.d.ts +2 -2
  59. package/dist/types/components/TextNodeView.d.ts +4 -3
  60. package/dist/types/components/TrailingHackView.d.ts +2 -2
  61. package/dist/types/components/WidgetView.d.ts +2 -2
  62. package/dist/types/constants.d.ts +4 -0
  63. package/dist/types/contexts/EditorContext.d.ts +6 -4
  64. package/dist/types/decorations/computeDocDeco.d.ts +3 -2
  65. package/dist/types/decorations/viewDecorations.d.ts +3 -2
  66. package/dist/types/hooks/useEditor.d.ts +5 -46
  67. package/dist/types/hooks/useNodeViewDescriptor.d.ts +1 -1
  68. package/dist/types/hooks/useReactKeys.d.ts +1 -1
  69. package/dist/types/props.d.ts +3 -3
  70. package/dist/types/viewdesc.d.ts +6 -5
  71. package/package.json +6 -2
  72. package/dist/cjs/components/Editor.js +0 -28
  73. package/dist/cjs/components/NodeViews.js +0 -73
  74. package/dist/cjs/components/__tests__/LayoutGroup.test.js +0 -141
  75. package/dist/cjs/components/__tests__/ProseMirror.test.js +0 -255
  76. package/dist/cjs/contexts/NodeViewsContext.js +0 -10
  77. package/dist/cjs/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -107
  78. package/dist/cjs/hooks/__tests__/useNodeViews.test.js +0 -159
  79. package/dist/cjs/hooks/useEditorView.js +0 -100
  80. package/dist/cjs/hooks/useNodePos.js +0 -69
  81. package/dist/cjs/hooks/useNodeViews.js +0 -100
  82. package/dist/cjs/nodeViews/createReactNodeViewConstructor.js +0 -244
  83. package/dist/cjs/nodeViews/phrasingContentTags.js +0 -57
  84. package/dist/cjs/plugins/__tests__/react.test.js +0 -139
  85. package/dist/cjs/plugins/react.js +0 -71
  86. package/dist/cjs/selection/SelectionDOMObserver.js +0 -171
  87. package/dist/cjs/selection/hasFocusAndSelection.js +0 -35
  88. package/dist/cjs/selection/selectionFromDOM.js +0 -77
  89. package/dist/cjs/selection/selectionToDOM.js +0 -226
  90. package/dist/cjs/ssr.js +0 -85
  91. package/dist/esm/components/Editor.js +0 -15
  92. package/dist/esm/components/NodeViews.js +0 -26
  93. package/dist/esm/components/__tests__/LayoutGroup.test.js +0 -98
  94. package/dist/esm/components/__tests__/ProseMirror.test.js +0 -207
  95. package/dist/esm/contexts/NodeViewsContext.js +0 -9
  96. package/dist/esm/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -98
  97. package/dist/esm/hooks/__tests__/useNodeViews.test.js +0 -116
  98. package/dist/esm/hooks/useEditorView.js +0 -99
  99. package/dist/esm/hooks/useNodePos.js +0 -16
  100. package/dist/esm/hooks/useNodeViews.js +0 -53
  101. package/dist/esm/nodeViews/createReactNodeViewConstructor.js +0 -214
  102. package/dist/esm/nodeViews/phrasingContentTags.js +0 -49
  103. package/dist/esm/plugins/__tests__/react.test.js +0 -135
  104. package/dist/esm/plugins/react.js +0 -64
  105. package/dist/esm/selection/SelectionDOMObserver.js +0 -161
  106. package/dist/esm/selection/hasFocusAndSelection.js +0 -17
  107. package/dist/esm/selection/selectionFromDOM.js +0 -59
  108. package/dist/esm/selection/selectionToDOM.js +0 -196
  109. package/dist/esm/ssr.js +0 -82
  110. package/dist/types/components/Editor.d.ts +0 -7
  111. package/dist/types/components/NodeViews.d.ts +0 -6
  112. package/dist/types/components/__tests__/LayoutGroup.test.d.ts +0 -1
  113. package/dist/types/contexts/NodeViewsContext.d.ts +0 -19
  114. package/dist/types/hooks/__tests__/useEditorViewLayoutEffect.test.d.ts +0 -1
  115. package/dist/types/hooks/__tests__/useNodeViews.test.d.ts +0 -1
  116. package/dist/types/hooks/useEditorView.d.ts +0 -23
  117. package/dist/types/hooks/useNodePos.d.ts +0 -9
  118. package/dist/types/hooks/useNodeViews.d.ts +0 -5
  119. package/dist/types/nodeViews/createReactNodeViewConstructor.d.ts +0 -48
  120. package/dist/types/nodeViews/phrasingContentTags.d.ts +0 -1
  121. package/dist/types/plugins/__tests__/react.test.d.ts +0 -1
  122. package/dist/types/plugins/react.d.ts +0 -21
  123. package/dist/types/selection/SelectionDOMObserver.d.ts +0 -33
  124. package/dist/types/selection/hasFocusAndSelection.d.ts +0 -3
  125. package/dist/types/selection/selectionFromDOM.d.ts +0 -4
  126. package/dist/types/selection/selectionToDOM.d.ts +0 -9
  127. package/dist/types/ssr.d.ts +0 -19
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ReactEditorView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ReactEditorView;
9
+ }
10
+ });
11
+ const _prosemirrorview = require("prosemirror-view");
12
+ const _constants = require("./constants.js");
13
+ function buildNodeViews(view) {
14
+ const result = Object.create(null);
15
+ function add(obj) {
16
+ for(const prop in obj)if (!Object.prototype.hasOwnProperty.call(result, prop)) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17
+ result[prop] = obj[prop];
18
+ }
19
+ view.someProp("nodeViews", add);
20
+ view.someProp("markViews", add);
21
+ return result;
22
+ }
23
+ function changedNodeViews(a, b) {
24
+ let nA = 0, nB = 0;
25
+ for(const prop in a){
26
+ if (a[prop] != b[prop]) return true;
27
+ nA++;
28
+ }
29
+ for(const _ in b)nB++;
30
+ return nA != nB;
31
+ }
32
+ let ReactEditorView = class ReactEditorView extends _prosemirrorview.EditorView {
33
+ nextProps;
34
+ prevState;
35
+ constructor(place, props){
36
+ // By the time the editor view mounts this should exist.
37
+ // We assume it is not possible to set the mount point otherwise.
38
+ const docView = place.mount.pmViewDesc;
39
+ // Prevent the base class from destroying the React-managed nodes.
40
+ // Restore them below after invoking the base class constructor.
41
+ const reactContent = [
42
+ ...place.mount.childNodes
43
+ ];
44
+ // Prevent the base class from mutating the React-managed attributes.
45
+ // Restore them below after invoking the base class constructor.
46
+ const reactAttrs = [
47
+ ...place.mount.attributes
48
+ ];
49
+ for (const attr of reactAttrs){
50
+ place.mount.removeAttributeNode(attr);
51
+ }
52
+ try {
53
+ // Call the superclass constructor with only a state and no plugins.
54
+ // We'll set everything else ourselves and apply props during layout.
55
+ super(place, {
56
+ state: _constants.EMPTY_STATE
57
+ });
58
+ this.domObserver.stop();
59
+ this.domObserver.observer = null;
60
+ this.domObserver.queue = [];
61
+ } finally{
62
+ place.mount.replaceChildren(...reactContent);
63
+ for (const attr of place.mount.attributes){
64
+ place.mount.removeAttributeNode(attr);
65
+ }
66
+ for (const attr of reactAttrs){
67
+ place.mount.setAttributeNode(attr);
68
+ }
69
+ }
70
+ this.prevState = _constants.EMPTY_STATE;
71
+ this.nextProps = props;
72
+ this.state = props.state;
73
+ this.nodeViews = buildNodeViews(this);
74
+ this.docView = docView;
75
+ this.dom.pmViewDesc = docView;
76
+ }
77
+ get props() {
78
+ return this.nextProps;
79
+ }
80
+ setProps(props) {
81
+ this.update({
82
+ ...this.props,
83
+ ...props
84
+ });
85
+ }
86
+ update(props) {
87
+ const prevProps = this.nextProps;
88
+ this.nextProps = props;
89
+ this.state = props.state;
90
+ if (prevProps.state.plugins !== props.state.plugins || prevProps.plugins !== props.plugins) {
91
+ const nodeViews = buildNodeViews(this);
92
+ if (changedNodeViews(this.nodeViews, nodeViews)) {
93
+ this.nodeViews = nodeViews;
94
+ }
95
+ }
96
+ this.editable = !this.someProp("editable", (value)=>value(this.state) === false);
97
+ }
98
+ updateState(state) {
99
+ this.setProps({
100
+ state
101
+ });
102
+ }
103
+ someProp(propName, f) {
104
+ if (!this.props) {
105
+ // The base class constructor calls this method before props are set.
106
+ return undefined;
107
+ }
108
+ const prop = this.props[propName];
109
+ if (prop) {
110
+ const result = f ? f(prop) : prop;
111
+ if (result) {
112
+ return result;
113
+ }
114
+ }
115
+ for (const plugin of this.props.plugins ?? []){
116
+ const prop = plugin.props[propName];
117
+ if (prop) {
118
+ const result = f ? f(prop) : prop;
119
+ if (result) {
120
+ return result;
121
+ }
122
+ }
123
+ }
124
+ for (const plugin of this.state.plugins){
125
+ const prop = plugin.props[propName];
126
+ if (prop) {
127
+ const result = f ? f(prop) : prop;
128
+ if (result) {
129
+ return result;
130
+ }
131
+ }
132
+ }
133
+ return undefined;
134
+ }
135
+ /**
136
+ * Commit effects by appling the pending props and state.
137
+ *
138
+ * Ensures the DOM selection is correct and updates plugin views.
139
+ *
140
+ * @privateRemarks
141
+ *
142
+ * The correctness of this depends on the pure update function ensuring that
143
+ * the node view set is up to date so that it does not try to redraw.
144
+ */ commitPendingEffects() {
145
+ // This class tracks state eagerly but the base class does it lazily.
146
+ // Temporarily roll it back so the base class can handle the updates.
147
+ this.state = this.prevState;
148
+ // Force the base class to try to update the document. React updated it, but
149
+ // this ensures that the base class validates the DOM selection and invokes
150
+ // node view selection callbacks.
151
+ this.docView.markDirty(-1, -1);
152
+ super.update(this.nextProps);
153
+ // Store the new previous state.
154
+ this.prevState = this.state;
155
+ }
156
+ };
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "StaticEditorView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return StaticEditorView;
9
+ }
10
+ });
11
+ let StaticEditorView = class StaticEditorView {
12
+ props;
13
+ nodeViews;
14
+ constructor(props){
15
+ this.props = props;
16
+ this.nodeViews = {};
17
+ }
18
+ get composing() {
19
+ return false;
20
+ }
21
+ get dom() {
22
+ return null;
23
+ }
24
+ get editable() {
25
+ return false;
26
+ }
27
+ get state() {
28
+ return this.props.state;
29
+ }
30
+ setProps(props) {
31
+ return this.update({
32
+ ...this.props,
33
+ ...props
34
+ });
35
+ }
36
+ update(props) {
37
+ this.props = props;
38
+ }
39
+ updateState(state) {
40
+ this.setProps({
41
+ state
42
+ });
43
+ }
44
+ someProp(propName, f) {
45
+ const prop = this.props[propName];
46
+ if (prop) {
47
+ const result = f ? f(prop) : prop;
48
+ if (result) {
49
+ return result;
50
+ }
51
+ }
52
+ for (const plugin of this.props.plugins ?? []){
53
+ const prop = plugin.props[propName];
54
+ if (prop) {
55
+ const result = f ? f(prop) : prop;
56
+ if (result) {
57
+ return result;
58
+ }
59
+ }
60
+ }
61
+ for (const plugin of this.state.plugins){
62
+ const prop = plugin.props[propName];
63
+ if (prop) {
64
+ const result = f ? f(prop) : prop;
65
+ if (result) {
66
+ return result;
67
+ }
68
+ }
69
+ }
70
+ return undefined;
71
+ }
72
+ destroy() {
73
+ // pass
74
+ }
75
+ domSelectionRange() {
76
+ return {
77
+ anchorNode: null,
78
+ anchorOffset: 0,
79
+ focusNode: null,
80
+ focusOffset: 0
81
+ };
82
+ }
83
+ domSelection() {
84
+ return null;
85
+ }
86
+ };
@@ -82,21 +82,30 @@ function wrapInDeco(reactNode, deco) {
82
82
  return /*#__PURE__*/ (0, _react.cloneElement)(reactNode, (0, _props.mergeReactProps)(reactNode.props, props));
83
83
  }
84
84
  function areChildrenEqual(a, b) {
85
- return a.type === b.type && a.marks.every((mark)=>mark.isInSet(b.marks)) && b.marks.every((mark)=>mark.isInSet(a.marks)) && a.key === b.key && (a.type === "node" ? a.outerDeco?.length === b.outerDeco?.length && a.outerDeco?.every((prevDeco)=>b.outerDeco?.some((nextDeco)=>prevDeco.from === nextDeco.from && prevDeco.to && nextDeco.to && prevDeco.type.eq(nextDeco.type))) && a.innerDeco.eq(b.innerDeco) : true) && a.node === b.node && a.widget === b.widget;
85
+ return a.type === b.type && a.marks.every((mark)=>mark.isInSet(b.marks)) && b.marks.every((mark)=>mark.isInSet(a.marks)) && a.key === b.key && (a.type === "node" ? a.outerDeco?.length === b.outerDeco?.length && a.outerDeco?.every((prevDeco)=>b.outerDeco?.some((nextDeco)=>prevDeco.from === nextDeco.from && prevDeco.to && nextDeco.to && // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
+ prevDeco.type.eq(nextDeco.type))) && a.innerDeco.eq(b.innerDeco) : true) && a.node === b.node && a.widget === b.widget;
86
87
  }
87
88
  const ChildView = /*#__PURE__*/ (0, _react.memo)(function ChildView(param) {
88
89
  let { child, getInnerPos } = param;
89
90
  const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
90
- const getChildPos = (0, _react.useRef)(()=>getInnerPos.current() + child.offset);
91
- getChildPos.current = ()=>getInnerPos.current() + child.offset;
91
+ const childRef = (0, _react.useRef)(child);
92
+ childRef.current = child;
93
+ const getPos = (0, _react.useCallback)(()=>{
94
+ return getInnerPos() + childRef.current.offset;
95
+ }, [
96
+ getInnerPos
97
+ ]);
92
98
  return child.type === "widget" ? /*#__PURE__*/ _react.default.createElement(_WidgetView.WidgetView, {
93
99
  key: child.key,
94
100
  widget: child.widget,
95
- getPos: getChildPos
101
+ getPos: getPos
96
102
  }) : child.type === "native-widget" ? /*#__PURE__*/ _react.default.createElement(_NativeWidgetView.NativeWidgetView, {
97
103
  key: child.key,
98
104
  widget: child.widget,
99
- getPos: getChildPos
105
+ getPos: getPos
106
+ }) : child.type === "hack" ? /*#__PURE__*/ _react.default.createElement(child.component, {
107
+ key: child.key,
108
+ getPos: getPos
100
109
  }) : child.node.isText ? /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Consumer, {
101
110
  key: child.key
102
111
  }, (param)=>{
@@ -104,7 +113,7 @@ const ChildView = /*#__PURE__*/ (0, _react.memo)(function ChildView(param) {
104
113
  return /*#__PURE__*/ _react.default.createElement(_TextNodeView.TextNodeView, {
105
114
  view: view,
106
115
  node: child.node,
107
- getPos: getChildPos,
116
+ getPos: getPos,
108
117
  siblingsRef: siblingsRef,
109
118
  parentRef: parentRef,
110
119
  decorations: child.outerDeco
@@ -112,7 +121,7 @@ const ChildView = /*#__PURE__*/ (0, _react.memo)(function ChildView(param) {
112
121
  }) : /*#__PURE__*/ _react.default.createElement(_NodeView.NodeView, {
113
122
  key: child.key,
114
123
  node: child.node,
115
- getPos: getChildPos,
124
+ getPos: getPos,
116
125
  outerDeco: child.outerDeco,
117
126
  innerDeco: child.innerDeco
118
127
  });
@@ -120,8 +129,13 @@ const ChildView = /*#__PURE__*/ (0, _react.memo)(function ChildView(param) {
120
129
  const InlinePartition = /*#__PURE__*/ (0, _react.memo)(function InlinePartition(param) {
121
130
  let { childViews, getInnerPos } = param;
122
131
  const firstChild = childViews[0];
123
- const getFirstChildPos = (0, _react.useRef)(()=>getInnerPos.current() + firstChild.offset);
124
- getFirstChildPos.current = ()=>getInnerPos.current() + firstChild.offset;
132
+ const firstChildRef = (0, _react.useRef)(firstChild);
133
+ firstChildRef.current = firstChild;
134
+ const getPos = (0, _react.useCallback)(()=>{
135
+ return getInnerPos() + firstChildRef.current.offset;
136
+ }, [
137
+ getInnerPos
138
+ ]);
125
139
  const firstMark = firstChild.marks[0];
126
140
  if (!firstMark) {
127
141
  return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, childViews.map((child)=>{
@@ -133,9 +147,9 @@ const InlinePartition = /*#__PURE__*/ (0, _react.memo)(function InlinePartition(
133
147
  }));
134
148
  }
135
149
  return /*#__PURE__*/ _react.default.createElement(_MarkView.MarkView, {
136
- getPos: getFirstChildPos,
137
150
  key: firstChild.key,
138
- mark: firstMark
151
+ mark: firstMark,
152
+ getPos: getPos
139
153
  }, /*#__PURE__*/ _react.default.createElement(InlineView, {
140
154
  key: firstChild.key,
141
155
  getInnerPos: getInnerPos,
@@ -193,7 +207,7 @@ const InlineView = /*#__PURE__*/ (0, _react.memo)(function InlineView(param) {
193
207
  });
194
208
  }));
195
209
  });
196
- function createKey(innerPos, offset, type, posToKey, widget, index) {
210
+ function createKey(innerPos, offset, index, type, posToKey, widget) {
197
211
  const pos = innerPos + offset;
198
212
  const key = posToKey?.get(pos);
199
213
  if (type === "widget" || type === "native-widget") {
@@ -237,18 +251,23 @@ function adjustWidgetMarksBack(widgetChildren, nodeChild) {
237
251
  }
238
252
  const ChildElement = /*#__PURE__*/ (0, _react.memo)(function ChildElement(param) {
239
253
  let { child, getInnerPos } = param;
240
- const getNodePos = (0, _react.useRef)(()=>getInnerPos.current() + child.offset);
241
- getNodePos.current = ()=>getInnerPos.current() + child.offset;
254
+ const childRef = (0, _react.useRef)(child);
255
+ childRef.current = child;
256
+ const getPos = (0, _react.useCallback)(()=>{
257
+ return getInnerPos() + childRef.current.offset;
258
+ }, [
259
+ getInnerPos
260
+ ]);
242
261
  if (child.type === "node") {
243
262
  return child.marks.reduce((element, mark)=>/*#__PURE__*/ _react.default.createElement(_MarkView.MarkView, {
244
- getPos: getNodePos,
245
- mark: mark
263
+ mark: mark,
264
+ getPos: getPos
246
265
  }, element), /*#__PURE__*/ _react.default.createElement(_NodeView.NodeView, {
247
266
  key: child.key,
248
267
  outerDeco: child.outerDeco,
249
268
  node: child.node,
250
269
  innerDeco: child.innerDeco,
251
- getPos: getNodePos
270
+ getPos: getPos
252
271
  }));
253
272
  } else {
254
273
  return /*#__PURE__*/ _react.default.createElement(InlineView, {
@@ -282,9 +301,10 @@ function createChildElements(children, getInnerPos) {
282
301
  }
283
302
  const ChildNodeViews = /*#__PURE__*/ (0, _react.memo)(function ChildNodeViews(param) {
284
303
  let { getPos, node, innerDecorations } = param;
285
- // const editorState = useEditorState();
286
304
  const reactKeys = (0, _useReactKeys.useReactKeys)();
287
- const getInnerPos = (0, _react.useRef)(()=>getPos.current() + 1);
305
+ const getInnerPos = (0, _react.useCallback)(()=>getPos() + 1, [
306
+ getPos
307
+ ]);
288
308
  const childMap = (0, _react.useRef)(new Map()).current;
289
309
  if (!node) return null;
290
310
  const keysSeen = new Map();
@@ -295,7 +315,7 @@ const ChildNodeViews = /*#__PURE__*/ (0, _react.memo)(function ChildNodeViews(pa
295
315
  const widgetMarks = widget.type.spec.marks ?? [];
296
316
  let key;
297
317
  if (isNative) {
298
- key = createKey(getInnerPos.current(), offset, "native-widget", reactKeys?.posToKey, widget, index);
318
+ key = createKey(getInnerPos(), offset, index, "native-widget", reactKeys?.posToKey, widget);
299
319
  const child = {
300
320
  type: "native-widget",
301
321
  widget,
@@ -312,7 +332,7 @@ const ChildNodeViews = /*#__PURE__*/ (0, _react.memo)(function ChildNodeViews(pa
312
332
  }
313
333
  keysSeen.set(key, keysSeen.size);
314
334
  } else {
315
- key = createKey(getInnerPos.current(), offset, "widget", reactKeys?.posToKey, widget, index);
335
+ key = createKey(getInnerPos(), offset, index, "widget", reactKeys?.posToKey, widget);
316
336
  const child = {
317
337
  type: "widget",
318
338
  widget: widget,
@@ -332,8 +352,8 @@ const ChildNodeViews = /*#__PURE__*/ (0, _react.memo)(function ChildNodeViews(pa
332
352
  const child = childMap.get(key);
333
353
  widgetChildren.push(child);
334
354
  adjustWidgetMarksForward(lastNodeChild, childMap.get(key));
335
- }, (childNode, outerDeco, innerDeco, offset)=>{
336
- const key = createKey(getInnerPos.current(), offset, "node", reactKeys?.posToKey);
355
+ }, (childNode, outerDeco, innerDeco, offset, index)=>{
356
+ const key = createKey(getInnerPos(), offset, index, "node", reactKeys?.posToKey);
337
357
  const child = {
338
358
  type: "node",
339
359
  node: childNode,
@@ -341,6 +361,7 @@ const ChildNodeViews = /*#__PURE__*/ (0, _react.memo)(function ChildNodeViews(pa
341
361
  innerDeco,
342
362
  outerDeco,
343
363
  offset,
364
+ index,
344
365
  key
345
366
  };
346
367
  const prevChild = childMap.get(key);
@@ -364,20 +385,28 @@ const ChildNodeViews = /*#__PURE__*/ (0, _react.memo)(function ChildNodeViews(pa
364
385
  // step
365
386
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
366
387
  (a, b)=>keysSeen.get(a.key) - keysSeen.get(b.key));
367
- const childElements = createChildElements(children, getInnerPos);
368
388
  if (node.isTextblock) {
369
389
  const lastChild = children[children.length - 1];
370
390
  if (!lastChild || lastChild.type !== "node" || lastChild.node.isInline && !lastChild.node.isText || // RegExp.test actually handles undefined just fine
371
391
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
372
392
  /\n$/.test(lastChild.node.text)) {
373
- childElements.push(/*#__PURE__*/ _react.default.createElement(_SeparatorHackView.SeparatorHackView, {
374
- getPos: getInnerPos,
375
- key: "trailing-hack-img"
376
- }), /*#__PURE__*/ _react.default.createElement(_TrailingHackView.TrailingHackView, {
377
- getPos: getInnerPos,
393
+ children.push({
394
+ type: "hack",
395
+ component: _TrailingHackView.TrailingHackView,
396
+ marks: [],
397
+ offset: lastChild?.offset ?? 0,
398
+ index: (lastChild?.index ?? 0) + 1,
378
399
  key: "trailing-hack-br"
379
- }));
400
+ }, {
401
+ type: "hack",
402
+ component: _SeparatorHackView.SeparatorHackView,
403
+ marks: [],
404
+ offset: lastChild?.offset ?? 0,
405
+ index: (lastChild?.index ?? 0) + 2,
406
+ key: "trailing-hack-img"
407
+ });
380
408
  }
381
409
  }
410
+ const childElements = createChildElements(children, getInnerPos);
382
411
  return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, childElements);
383
412
  });
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "CustomNodeView", {
8
8
  return CustomNodeView;
9
9
  }
10
10
  });
11
- const _prosemirrorstate = require("prosemirror-state");
12
11
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13
12
  const _reactdom = require("react-dom");
14
13
  const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
@@ -61,11 +60,12 @@ function _interop_require_wildcard(obj, nodeInterop) {
61
60
  }
62
61
  const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(param) {
63
62
  let { customNodeView, node, getPos, innerDeco, outerDeco } = param;
64
- const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
63
+ const editor = (0, _react.useContext)(_EditorContext.EditorContext);
64
+ // Only ReactEditorView supports custom node views.
65
+ const view = editor.view;
65
66
  const domRef = (0, _react.useRef)(null);
66
67
  const nodeDomRef = (0, _react.useRef)(null);
67
68
  const contentDomRef = (0, _react.useRef)(null);
68
- const getPosFunc = (0, _react.useRef)(()=>getPos.current()).current;
69
69
  const nodeRef = (0, _react.useRef)(node);
70
70
  nodeRef.current = node;
71
71
  const outerDecoRef = (0, _react.useRef)(outerDeco);
@@ -82,10 +82,7 @@ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(pa
82
82
  // the node view when the layout effect is re-run.
83
83
  (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
84
84
  if (!customNodeViewRef.current) {
85
- customNodeViewRef.current = customNodeView(nodeRef.current, // customNodeView will only be set if view is set, and we can only reach
86
- // this line if customNodeView is set
87
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
88
- view, getPosFunc, outerDecoRef.current, innerDecoRef.current);
85
+ customNodeViewRef.current = customNodeView(nodeRef.current, view, getPos, outerDecoRef.current, innerDecoRef.current);
89
86
  if (customNodeViewRef.current.stopEvent) {
90
87
  setStopEvent(customNodeViewRef.current.stopEvent.bind(customNodeViewRef.current));
91
88
  }
@@ -107,12 +104,6 @@ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(pa
107
104
  }
108
105
  nodeDomRef.current = customNodeViewRootRef.current;
109
106
  customNodeViewRootRef.current.appendChild(dom);
110
- // Layout effects can run multiple times — if this effect
111
- // destroyed and recreated this node view, then we need to
112
- // resync the selectNode state
113
- if (view?.state.selection instanceof _prosemirrorstate.NodeSelection && view.state.selection.node === nodeRef.current) {
114
- customNodeViewRef.current.selectNode?.();
115
- }
116
107
  const nodeView = customNodeViewRef.current;
117
108
  return ()=>{
118
109
  nodeView.destroy?.();
@@ -126,7 +117,7 @@ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(pa
126
117
  // eslint-disable-next-line react-hooks/exhaustive-deps
127
118
  }, [
128
119
  customNodeView,
129
- getPosFunc,
120
+ getPos,
130
121
  view
131
122
  ]);
132
123
  (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
@@ -136,10 +127,7 @@ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(pa
136
127
  if (updated) return;
137
128
  destroy?.call(customNodeViewRef.current);
138
129
  if (!customNodeViewRootRef.current) return;
139
- customNodeViewRef.current = customNodeView(nodeRef.current, // customNodeView will only be set if view is set, and we can only reach
140
- // this line if customNodeView is set
141
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
142
- view, getPosFunc, outerDecoRef.current, innerDecoRef.current);
130
+ customNodeViewRef.current = customNodeView(nodeRef.current, view, getPos, outerDecoRef.current, innerDecoRef.current);
143
131
  const { dom } = customNodeViewRef.current;
144
132
  nodeDomRef.current = customNodeViewRootRef.current;
145
133
  customNodeViewRootRef.current.appendChild(dom);
@@ -149,10 +137,9 @@ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(pa
149
137
  innerDeco,
150
138
  node,
151
139
  outerDeco,
152
- getPos,
153
- getPosFunc
140
+ getPos
154
141
  ]);
155
- const { childDescriptors, nodeViewDescRef, setStopEvent, setSelectNode, setIgnoreMutation } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(node, getPosFunc, domRef, nodeDomRef, innerDeco, outerDeco, undefined, contentDomRef);
142
+ const { childDescriptors, nodeViewDescRef, setStopEvent, setSelectNode, setIgnoreMutation } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(node, getPos, domRef, nodeDomRef, innerDeco, outerDeco, contentDomRef);
156
143
  const childContextValue = (0, _react.useMemo)(()=>({
157
144
  parentRef: nodeViewDescRef,
158
145
  siblingsRef: childDescriptors
@@ -167,10 +154,7 @@ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(pa
167
154
  // results are stored in a ref but not actually appended
168
155
  // to the DOM until a client effect
169
156
  if (!customNodeViewRef.current) {
170
- customNodeViewRef.current = customNodeView(nodeRef.current, // customNodeView will only be set if view is set, and we can only reach
171
- // this line if customNodeView is set
172
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
173
- view, ()=>getPos.current(), outerDecoRef.current, innerDecoRef.current);
157
+ customNodeViewRef.current = customNodeView(nodeRef.current, view, getPos, outerDecoRef.current, innerDecoRef.current);
174
158
  if (customNodeViewRef.current.stopEvent) {
175
159
  setStopEvent(customNodeViewRef.current.stopEvent.bind(customNodeViewRef.current));
176
160
  }
@@ -55,18 +55,16 @@ function _interop_require_wildcard(obj, nodeInterop) {
55
55
  }
56
56
  return newObj;
57
57
  }
58
- const getPos = {
59
- current () {
60
- return -1;
61
- }
62
- };
58
+ function getPos() {
59
+ return -1;
60
+ }
63
61
  const DocNodeView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function DocNodeView(param, ref) {
64
- let { className, node, innerDeco, outerDeco, as, viewDesc, ...elementProps } = param;
62
+ let { className, node, innerDeco, outerDeco, as, ...elementProps } = param;
65
63
  const innerRef = (0, _react.useRef)(null);
66
64
  (0, _react.useImperativeHandle)(ref, ()=>{
67
65
  return innerRef.current;
68
66
  }, []);
69
- const { childDescriptors, nodeViewDescRef } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(node, ()=>getPos.current(), innerRef, innerRef, innerDeco, outerDeco, viewDesc);
67
+ const { childDescriptors, nodeViewDescRef } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(node, getPos, innerRef, innerRef, innerDeco, outerDeco, innerRef);
70
68
  const childContextValue = (0, _react.useMemo)(()=>({
71
69
  parentRef: nodeViewDescRef,
72
70
  siblingsRef: childDescriptors
@@ -93,12 +91,5 @@ const DocNodeView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forw
93
91
  node: node,
94
92
  innerDecorations: innerDeco
95
93
  })));
96
- if (!node) return element;
97
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
- const nodeDecorations = outerDeco.filter((deco)=>!deco.inline);
99
- if (!nodeDecorations.length) {
100
- return element;
101
- }
102
- const wrapped = nodeDecorations.reduce(_ChildNodeViews.wrapInDeco, element);
103
- return wrapped;
94
+ return outerDeco.reduce(_ChildNodeViews.wrapInDeco, element);
104
95
  }));
@@ -83,7 +83,7 @@ const MarkView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forward
83
83
  if (!domRef.current) return;
84
84
  const firstChildDesc = childDescriptors.current[0];
85
85
  if (!viewDescRef.current) {
86
- viewDescRef.current = new _viewdesc.MarkViewDesc(parentRef.current, childDescriptors.current, ()=>getPos.current(), mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current, {
86
+ viewDescRef.current = new _viewdesc.MarkViewDesc(parentRef.current, childDescriptors.current, getPos, mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current, {
87
87
  dom: domRef.current,
88
88
  contentDOM: firstChildDesc?.dom.parentElement ?? domRef.current
89
89
  });
@@ -93,7 +93,6 @@ const MarkView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forward
93
93
  viewDescRef.current.children = childDescriptors.current;
94
94
  viewDescRef.current.spec.contentDOM = viewDescRef.current.contentDOM = firstChildDesc?.dom.parentElement ?? domRef.current;
95
95
  viewDescRef.current.mark = mark;
96
- viewDescRef.current.getPos = ()=>getPos.current();
97
96
  }
98
97
  if (!siblingsRef.current.includes(viewDescRef.current)) {
99
98
  siblingsRef.current.push(viewDescRef.current);
@@ -75,7 +75,7 @@ function NativeWidgetView(param) {
75
75
  if (!rootDomRef.current) return;
76
76
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
77
  const toDOM = widget.type.toDOM;
78
- let dom = typeof toDOM === "function" ? toDOM(view, ()=>getPos.current()) : toDOM;
78
+ let dom = typeof toDOM === "function" ? toDOM(view, getPos) : toDOM;
79
79
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
80
  if (!widget.type.spec.raw) {
81
81
  if (dom.nodeType != 1) {
@@ -92,11 +92,10 @@ function NativeWidgetView(param) {
92
92
  (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
93
93
  if (!rootDomRef.current) return;
94
94
  if (!viewDescRef.current) {
95
- viewDescRef.current = new _viewdesc.WidgetViewDesc(parentRef.current, ()=>getPos.current(), widget, rootDomRef.current);
95
+ viewDescRef.current = new _viewdesc.WidgetViewDesc(parentRef.current, getPos, widget, rootDomRef.current);
96
96
  } else {
97
97
  viewDescRef.current.parent = parentRef.current;
98
98
  viewDescRef.current.widget = widget;
99
- viewDescRef.current.getPos = ()=>getPos.current();
100
99
  viewDescRef.current.dom = rootDomRef.current;
101
100
  }
102
101
  if (!siblingsRef.current.includes(viewDescRef.current)) {
@@ -56,7 +56,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
56
56
  const NodeView = /*#__PURE__*/ (0, _react.memo)(function NodeView(param) {
57
57
  let { outerDeco, getPos, node, innerDeco, ...props } = param;
58
58
  const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
59
- const customNodeView = view?.someProp("nodeViews", (nodeViews)=>nodeViews?.[node.type.name]);
59
+ const customNodeView = view.nodeViews[node.type.name];
60
60
  if (customNodeView) {
61
61
  return /*#__PURE__*/ _react.default.createElement(_CustomNodeView.CustomNodeView, {
62
62
  customNodeView: customNodeView,