@handlewithcare/react-prosemirror 3.2.1 → 3.2.3

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.
package/README.md CHANGED
@@ -739,7 +739,7 @@ update.
739
739
  ### `useStopEvent`
740
740
 
741
741
  ```tsx
742
- type useStopEvent = (stopEvent: (view: EditorView, event: Event) => boolean): void
742
+ type useStopEvent = (stopEvent: (this: NodeView, view: EditorView, event: Event) => boolean): void
743
743
  ```
744
744
 
745
745
  This hook can be used within a node view component to register a
@@ -749,7 +749,7 @@ Events for which this returns true are not handled by the editor.
749
749
  ### `useIgnoreMutation`
750
750
 
751
751
  ```tsx
752
- type useIgnoreMutation = (stopEvent: (view: EditorView, mutation: ViewMutationRecord) => boolean): void
752
+ type useIgnoreMutation = (stopEvent: (this: NodeView, view: EditorView, mutation: ViewMutationRecord) => boolean): void
753
753
  ```
754
754
 
755
755
  This hook can be used within a node view component to register an
@@ -188,11 +188,14 @@ let ReactEditorView = class ReactEditorView extends _prosemirrorview.EditorView
188
188
  // node view selection callbacks.
189
189
  this.docView.markDirty(-1, -1);
190
190
  const nextSelection = this.nextProps.state.selection;
191
- const currentSelection = this.prevState.selection;
192
- const selectionChanged = !nextSelection.eq(currentSelection);
193
- if (selectionChanged) {
194
- super.update(this.nextProps);
195
- } else {
191
+ const prevSelection = this.prevState.selection;
192
+ const selectionChanged = !nextSelection.eq(prevSelection);
193
+ const needsSelectionUpdate = selectionChanged || // If the doc within the selection has changed, then the DOM has likely changed.
194
+ // In this case, we need to force a re-sync of the selection, because the browser
195
+ // will have probably collapsed the selection to work around the new DOM, which
196
+ // no longer matches the previous selection.
197
+ !this.prevState.doc.slice(prevSelection.from, prevSelection.to).eq(this.nextProps.state.doc.slice(prevSelection.from, prevSelection.to));
198
+ if (!needsSelectionUpdate) {
196
199
  // If the selection hasn't changed between renders, force
197
200
  // prosemirror-view to skip the selectionToDOM call. If a render happens after a DOM
198
201
  // selection change but before the "selectionchange" event fired, calling
@@ -202,7 +205,9 @@ let ReactEditorView = class ReactEditorView extends _prosemirrorview.EditorView
202
205
  allowDefault: false,
203
206
  delayedSelectionSync: false
204
207
  };
205
- super.update(this.nextProps);
208
+ }
209
+ super.update(this.nextProps);
210
+ if (!needsSelectionUpdate) {
206
211
  this.input.mouseDown = null;
207
212
  }
208
213
  // Store the new previous state.
@@ -78,10 +78,11 @@ const ReactMarkView = /*#__PURE__*/ (0, _react.memo)(function ReactMarkView(para
78
78
  ]);
79
79
  const { childContextValue, refUpdated } = (0, _useMarkViewDescription.useMarkViewDescription)(()=>ref.current, ()=>contentDOMRef.current ?? ref.current, ()=>({
80
80
  dom: ref.current,
81
+ contentDOM: contentDOMRef.current ?? ref.current,
81
82
  ignoreMutation (mutation) {
82
83
  const ignoreMutation = ignoreMutationRef.current;
83
84
  if (ignoreMutation) {
84
- return ignoreMutation(mutation);
85
+ return ignoreMutation.call(this, mutation);
85
86
  }
86
87
  return false;
87
88
  }
@@ -109,6 +109,7 @@ const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(para
109
109
  setSelected(false);
110
110
  return {
111
111
  dom: nodeDOMRef.current ?? domRef.current,
112
+ contentDOM: contentDOMRef.current,
112
113
  update () {
113
114
  return true;
114
115
  },
@@ -81,6 +81,8 @@ onWidget, onNode) {
81
81
  end = cutAt;
82
82
  index = -1;
83
83
  }
84
+ } else {
85
+ while(decoIndex < locals.length && locals[decoIndex].to < end)decoIndex++;
84
86
  }
85
87
  const outerDeco = child.isInline && !child.isLeaf ? active.filter((d)=>!d.inline) : active.slice();
86
88
  onNode(child, outerDeco, deco.forChild(offset, child), offset, index);
@@ -97,7 +97,7 @@ function tiptapNodeView(param) {
97
97
  innerDecorations,
98
98
  node,
99
99
  view: editor.view
100
- }, this.dom, this.contentDOM);
100
+ }, this.dom, this.contentDOM ?? null);
101
101
  nodeView.isDragging = isDraggingRef.current;
102
102
  if (stopEvent) {
103
103
  const result = stopEvent.call({
@@ -126,7 +126,7 @@ function tiptapNodeView(param) {
126
126
  innerDecorations,
127
127
  node,
128
128
  view: editor.view
129
- }, this.dom, this.contentDOM);
129
+ }, this.dom, this.contentDOM ?? null);
130
130
  if (ignoreMutation) {
131
131
  return ignoreMutation.call({
132
132
  name: extension.name,
@@ -773,10 +773,10 @@ let CustomNodeViewDesc = class CustomNodeViewDesc extends NodeViewDesc {
773
773
  super.destroy();
774
774
  }
775
775
  stopEvent(event) {
776
- return this.spec.stopEvent ? this.spec.stopEvent.call(this, event) : false;
776
+ return this.spec.stopEvent ? this.spec.stopEvent(event) : false;
777
777
  }
778
778
  ignoreMutation(mutation) {
779
- return this.spec.ignoreMutation ? this.spec.ignoreMutation.call(this, mutation) : super.ignoreMutation(mutation);
779
+ return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation);
780
780
  }
781
781
  };
782
782
  let ReactMarkViewDesc = class ReactMarkViewDesc extends MarkViewDesc {
@@ -188,11 +188,14 @@ function changedNodeViews(a, b) {
188
188
  // node view selection callbacks.
189
189
  this.docView.markDirty(-1, -1);
190
190
  const nextSelection = this.nextProps.state.selection;
191
- const currentSelection = this.prevState.selection;
192
- const selectionChanged = !nextSelection.eq(currentSelection);
193
- if (selectionChanged) {
194
- super.update(this.nextProps);
195
- } else {
191
+ const prevSelection = this.prevState.selection;
192
+ const selectionChanged = !nextSelection.eq(prevSelection);
193
+ const needsSelectionUpdate = selectionChanged || // If the doc within the selection has changed, then the DOM has likely changed.
194
+ // In this case, we need to force a re-sync of the selection, because the browser
195
+ // will have probably collapsed the selection to work around the new DOM, which
196
+ // no longer matches the previous selection.
197
+ !this.prevState.doc.slice(prevSelection.from, prevSelection.to).eq(this.nextProps.state.doc.slice(prevSelection.from, prevSelection.to));
198
+ if (!needsSelectionUpdate) {
196
199
  // If the selection hasn't changed between renders, force
197
200
  // prosemirror-view to skip the selectionToDOM call. If a render happens after a DOM
198
201
  // selection change but before the "selectionchange" event fired, calling
@@ -202,7 +205,9 @@ function changedNodeViews(a, b) {
202
205
  allowDefault: false,
203
206
  delayedSelectionSync: false
204
207
  };
205
- super.update(this.nextProps);
208
+ }
209
+ super.update(this.nextProps);
210
+ if (!needsSelectionUpdate) {
206
211
  this.input.mouseDown = null;
207
212
  }
208
213
  // Store the new previous state.
@@ -27,10 +27,11 @@ export const ReactMarkView = /*#__PURE__*/ memo(function ReactMarkView(param) {
27
27
  ]);
28
28
  const { childContextValue, refUpdated } = useMarkViewDescription(()=>ref.current, ()=>contentDOMRef.current ?? ref.current, ()=>({
29
29
  dom: ref.current,
30
+ contentDOM: contentDOMRef.current ?? ref.current,
30
31
  ignoreMutation (mutation) {
31
32
  const ignoreMutation = ignoreMutationRef.current;
32
33
  if (ignoreMutation) {
33
- return ignoreMutation(mutation);
34
+ return ignoreMutation.call(this, mutation);
34
35
  }
35
36
  return false;
36
37
  }
@@ -58,6 +58,7 @@ export const ReactNodeView = /*#__PURE__*/ memo(function ReactNodeView(param) {
58
58
  setSelected(false);
59
59
  return {
60
60
  dom: nodeDOMRef.current ?? domRef.current,
61
+ contentDOM: contentDOMRef.current,
61
62
  update () {
62
63
  return true;
63
64
  },
@@ -75,6 +75,8 @@ onWidget, onNode) {
75
75
  end = cutAt;
76
76
  index = -1;
77
77
  }
78
+ } else {
79
+ while(decoIndex < locals.length && locals[decoIndex].to < end)decoIndex++;
78
80
  }
79
81
  const outerDeco = child.isInline && !child.isLeaf ? active.filter((d)=>!d.inline) : active.slice();
80
82
  onNode(child, outerDeco, deco.forChild(offset, child), offset, index);
@@ -63,7 +63,7 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
63
63
  innerDecorations,
64
64
  node,
65
65
  view: editor.view
66
- }, this.dom, this.contentDOM);
66
+ }, this.dom, this.contentDOM ?? null);
67
67
  nodeView.isDragging = isDraggingRef.current;
68
68
  if (stopEvent) {
69
69
  const result = stopEvent.call({
@@ -92,7 +92,7 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
92
92
  innerDecorations,
93
93
  node,
94
94
  view: editor.view
95
- }, this.dom, this.contentDOM);
95
+ }, this.dom, this.contentDOM ?? null);
96
96
  if (ignoreMutation) {
97
97
  return ignoreMutation.call({
98
98
  name: extension.name,
@@ -751,10 +751,10 @@ let CustomNodeViewDesc = class CustomNodeViewDesc extends NodeViewDesc {
751
751
  super.destroy();
752
752
  }
753
753
  stopEvent(event) {
754
- return this.spec.stopEvent ? this.spec.stopEvent.call(this, event) : false;
754
+ return this.spec.stopEvent ? this.spec.stopEvent(event) : false;
755
755
  }
756
756
  ignoreMutation(mutation) {
757
- return this.spec.ignoreMutation ? this.spec.ignoreMutation.call(this, mutation) : super.ignoreMutation(mutation);
757
+ return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation);
758
758
  }
759
759
  };
760
760
  export class ReactMarkViewDesc extends MarkViewDesc {