@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 +2 -2
- package/dist/cjs/ReactEditorView.js +11 -6
- package/dist/cjs/components/marks/ReactMarkView.js +2 -1
- package/dist/cjs/components/nodes/ReactNodeView.js +1 -0
- package/dist/cjs/decorations/iterDeco.js +2 -0
- package/dist/cjs/tiptap/tiptapNodeView.js +2 -2
- package/dist/cjs/viewdesc.js +2 -2
- package/dist/esm/ReactEditorView.js +11 -6
- package/dist/esm/components/marks/ReactMarkView.js +2 -1
- package/dist/esm/components/nodes/ReactNodeView.js +1 -0
- package/dist/esm/decorations/iterDeco.js +2 -0
- package/dist/esm/tiptap/tiptapNodeView.js +2 -2
- package/dist/esm/viewdesc.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/contexts/IgnoreMutationContext.d.ts +2 -2
- package/dist/types/contexts/StopEventContext.d.ts +2 -1
- package/dist/types/hooks/useIgnoreMutation.d.ts +2 -2
- package/dist/types/hooks/useStopEvent.d.ts +2 -2
- package/package.json +4 -4
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
|
|
192
|
-
const selectionChanged = !nextSelection.eq(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -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,
|
package/dist/cjs/viewdesc.js
CHANGED
|
@@ -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
|
|
776
|
+
return this.spec.stopEvent ? this.spec.stopEvent(event) : false;
|
|
777
777
|
}
|
|
778
778
|
ignoreMutation(mutation) {
|
|
779
|
-
return this.spec.ignoreMutation ? this.spec.ignoreMutation
|
|
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
|
|
192
|
-
const selectionChanged = !nextSelection.eq(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -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,
|
package/dist/esm/viewdesc.js
CHANGED
|
@@ -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
|
|
754
|
+
return this.spec.stopEvent ? this.spec.stopEvent(event) : false;
|
|
755
755
|
}
|
|
756
756
|
ignoreMutation(mutation) {
|
|
757
|
-
return this.spec.ignoreMutation ? this.spec.ignoreMutation
|
|
757
|
+
return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation);
|
|
758
758
|
}
|
|
759
759
|
};
|
|
760
760
|
export class ReactMarkViewDesc extends MarkViewDesc {
|