@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.
- package/README.md +140 -75
- package/dist/cjs/StaticEditorView.js +0 -3
- package/dist/cjs/components/ChildNodeViews.js +4 -4
- package/dist/cjs/components/NativeWidgetView.js +2 -2
- package/dist/cjs/components/OutputSpec.js +10 -3
- package/dist/cjs/components/ProseMirror.js +11 -17
- package/dist/cjs/components/SeparatorHackView.js +2 -2
- package/dist/cjs/components/TrailingHackView.js +2 -2
- package/dist/cjs/components/WidgetView.js +2 -2
- package/dist/cjs/components/marks/DefaultMarkView.js +2 -1
- package/dist/cjs/components/marks/MarkView.js +2 -2
- package/dist/cjs/components/marks/{CustomMarkView.js → MarkViewConstructorView.js} +16 -7
- package/dist/cjs/components/marks/ReactMarkView.js +26 -6
- package/dist/cjs/components/nodes/DefaultNodeView.js +3 -2
- package/dist/cjs/components/nodes/DocNodeView.js +7 -6
- package/dist/cjs/components/nodes/NodeView.js +17 -6
- package/dist/cjs/components/nodes/{CustomNodeView.js → NodeViewConstructorView.js} +22 -9
- package/dist/cjs/components/nodes/ReactNodeView.js +59 -17
- package/dist/cjs/contexts/{ChildDescriptorsContext.js → ChildDescriptionsContext.js} +3 -3
- package/dist/cjs/hooks/useEditor.js +0 -4
- package/dist/cjs/hooks/useEditorEventCallback.js +1 -1
- package/dist/cjs/hooks/useMarkViewDescription.js +24 -21
- package/dist/cjs/hooks/useNodePos.js +18 -0
- package/dist/cjs/hooks/{useNodeViewDescriptor.js → useNodeViewDescription.js} +30 -25
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/refs.js +28 -0
- package/dist/cjs/viewdesc.js +18 -5
- package/dist/esm/StaticEditorView.js +0 -3
- package/dist/esm/components/ChildNodeViews.js +4 -4
- package/dist/esm/components/NativeWidgetView.js +2 -2
- package/dist/esm/components/OutputSpec.js +10 -3
- package/dist/esm/components/ProseMirror.js +11 -17
- package/dist/esm/components/SeparatorHackView.js +2 -2
- package/dist/esm/components/TrailingHackView.js +2 -2
- package/dist/esm/components/WidgetView.js +2 -2
- package/dist/esm/components/marks/DefaultMarkView.js +2 -1
- package/dist/esm/components/marks/MarkView.js +2 -2
- package/dist/esm/components/marks/{CustomMarkView.js → MarkViewConstructorView.js} +14 -5
- package/dist/esm/components/marks/ReactMarkView.js +26 -6
- package/dist/esm/components/nodes/DefaultNodeView.js +3 -2
- package/dist/esm/components/nodes/DocNodeView.js +8 -7
- package/dist/esm/components/nodes/NodeView.js +7 -4
- package/dist/esm/components/nodes/{CustomNodeView.js → NodeViewConstructorView.js} +20 -7
- package/dist/esm/components/nodes/ReactNodeView.js +59 -17
- package/dist/esm/contexts/{ChildDescriptorsContext.js → ChildDescriptionsContext.js} +1 -1
- package/dist/esm/hooks/useEditor.js +0 -4
- package/dist/esm/hooks/useEditorEffect.js +0 -4
- package/dist/esm/hooks/useEditorEventCallback.js +6 -4
- package/dist/esm/hooks/useMarkViewDescription.js +26 -23
- package/dist/esm/hooks/useNodePos.js +15 -0
- package/dist/esm/hooks/{useNodeViewDescriptor.js → useNodeViewDescription.js} +29 -24
- package/dist/esm/index.js +2 -0
- package/dist/esm/refs.js +18 -0
- package/dist/esm/viewdesc.js +13 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/AbstractEditorView.d.ts +0 -1
- package/dist/types/StaticEditorView.d.ts +0 -1
- package/dist/types/components/OutputSpec.d.ts +2 -1
- package/dist/types/components/ProseMirror.d.ts +3 -11
- package/dist/types/components/ProseMirrorDoc.d.ts +2 -2
- package/dist/types/components/marks/DefaultMarkView.d.ts +1 -1
- package/dist/types/components/marks/MarkViewComponentProps.d.ts +4 -3
- package/dist/types/components/marks/{CustomMarkView.d.ts → MarkViewConstructorView.d.ts} +1 -1
- package/dist/types/components/nodes/DefaultNodeView.d.ts +1 -1
- package/dist/types/components/nodes/DocNodeView.d.ts +2 -2
- package/dist/types/components/nodes/NodeView.d.ts +1 -0
- package/dist/types/components/nodes/NodeViewComponentProps.d.ts +4 -3
- package/dist/types/components/{CustomNodeView.d.ts → nodes/NodeViewConstructorView.d.ts} +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/contexts/{ChildDescriptorsContext.d.ts → ChildDescriptionsContext.d.ts} +1 -1
- package/dist/types/hooks/useEditorEffect.d.ts +0 -4
- package/dist/types/hooks/useEditorEventCallback.d.ts +6 -4
- package/dist/types/hooks/useMarkViewDescription.d.ts +6 -9
- package/dist/types/hooks/useNodePos.d.ts +9 -0
- package/dist/types/hooks/{useNodeViewDescriptor.d.ts → useNodeViewDescription.d.ts} +5 -9
- package/dist/types/index.d.ts +2 -0
- package/dist/types/props.d.ts +26 -26
- package/dist/types/refs.d.ts +2 -0
- package/dist/types/viewdesc.d.ts +4 -0
- package/package.json +12 -20
- package/dist/cjs/components/CustomNodeView.js +0 -132
- package/dist/cjs/components/DefaultNodeView.js +0 -67
- package/dist/cjs/components/DocNodeView.js +0 -96
- package/dist/cjs/components/MarkView.js +0 -119
- package/dist/cjs/components/NodeView.js +0 -86
- package/dist/cjs/components/NodeViewComponentProps.js +0 -4
- package/dist/cjs/components/ReactNodeView.js +0 -174
- package/dist/cjs/components/marks/OldMarkView.js +0 -120
- package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +0 -26
- package/dist/cjs/tiptap/TiptapEditor.js +0 -34
- package/dist/cjs/tiptap/TiptapEditorContent.js +0 -142
- package/dist/cjs/tiptap/TiptapEditorView.js +0 -118
- package/dist/cjs/tiptap/TiptapNodeView.js +0 -26
- package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +0 -12
- package/dist/cjs/tiptap/extensions/ReactProseMirror.js +0 -40
- package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +0 -15
- package/dist/cjs/tiptap/hooks/useTiptapEditor.js +0 -43
- package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +0 -35
- package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +0 -35
- package/dist/cjs/tiptap/index.js +0 -48
- package/dist/cjs/tiptap/tiptapNodeView.js +0 -237
- package/dist/esm/components/CustomNodeView.js +0 -81
- package/dist/esm/components/DefaultNodeView.js +0 -16
- package/dist/esm/components/DocNodeView.js +0 -45
- package/dist/esm/components/MarkView.js +0 -68
- package/dist/esm/components/NodeView.js +0 -35
- package/dist/esm/components/NodeViewComponentProps.js +0 -1
- package/dist/esm/components/ReactNodeView.js +0 -123
- package/dist/esm/components/marks/OldMarkView.js +0 -69
- package/dist/esm/tiptap/ReactProseMirrorNodeView.js +0 -22
- package/dist/esm/tiptap/TiptapEditor.js +0 -24
- package/dist/esm/tiptap/TiptapEditorContent.js +0 -91
- package/dist/esm/tiptap/TiptapEditorView.js +0 -69
- package/dist/esm/tiptap/TiptapNodeView.js +0 -22
- package/dist/esm/tiptap/contexts/TiptapEditorContext.js +0 -2
- package/dist/esm/tiptap/extensions/ReactProseMirror.js +0 -30
- package/dist/esm/tiptap/hooks/useIsInReactProseMirror.js +0 -5
- package/dist/esm/tiptap/hooks/useTiptapEditor.js +0 -33
- package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +0 -42
- package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +0 -35
- package/dist/esm/tiptap/index.js +0 -9
- package/dist/esm/tiptap/tiptapNodeView.js +0 -205
- package/dist/types/components/DefaultNodeView.d.ts +0 -3
- package/dist/types/components/DocNodeView.d.ts +0 -12
- package/dist/types/components/MarkView.d.ts +0 -9
- package/dist/types/components/NodeView.d.ts +0 -11
- package/dist/types/components/NodeViewComponentProps.d.ts +0 -12
- package/dist/types/components/ReactNodeView.d.ts +0 -13
- package/dist/types/components/marks/OldMarkView.d.ts +0 -10
- package/dist/types/components/nodes/CustomNodeView.d.ts +0 -12
- package/dist/types/tiptap/ReactProseMirrorNodeView.d.ts +0 -15
- package/dist/types/tiptap/TiptapEditor.d.ts +0 -6
- package/dist/types/tiptap/TiptapEditorContent.d.ts +0 -19
- package/dist/types/tiptap/TiptapEditorView.d.ts +0 -16
- package/dist/types/tiptap/TiptapNodeView.d.ts +0 -15
- package/dist/types/tiptap/contexts/TiptapEditorContext.d.ts +0 -6
- package/dist/types/tiptap/extensions/ReactProseMirror.d.ts +0 -9
- package/dist/types/tiptap/hooks/useIsInReactProseMirror.d.ts +0 -1
- package/dist/types/tiptap/hooks/useTiptapEditor.d.ts +0 -4
- package/dist/types/tiptap/hooks/useTiptapEditorEffect.d.ts +0 -21
- package/dist/types/tiptap/hooks/useTiptapEditorEventCallback.d.ts +0 -13
- package/dist/types/tiptap/index.d.ts +0 -9
- package/dist/types/tiptap/tiptapNodeView.d.ts +0 -50
|
@@ -2,35 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "useNodeViewDescription", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return useNodeViewDescription;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _react = require("react");
|
|
12
12
|
const _ReactEditorView = require("../ReactEditorView.js");
|
|
13
|
-
const
|
|
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
|
|
19
|
-
return source?.contentDOM ?? children[0]?.dom?.parentElement ?? null;
|
|
20
|
-
}
|
|
21
|
-
function useNodeViewDescriptor(ref, constructor, props) {
|
|
18
|
+
function useNodeViewDescription(getDOM, getContentDOM, constructor, props) {
|
|
22
19
|
const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
|
|
23
|
-
const { parentRef, siblingsRef } = (0, _react.useContext)(
|
|
24
|
-
const
|
|
25
|
-
const [nodeDOM, setNodeDOM] = (0, _react.useState)(null);
|
|
26
|
-
const [contentDOM, setContentDOM] = (0, _react.useState)(null);
|
|
20
|
+
const { parentRef, siblingsRef } = (0, _react.useContext)(_ChildDescriptionsContext.ChildDescriptionsContext);
|
|
21
|
+
const contentDOMRef = (0, _react.useRef)(null);
|
|
27
22
|
const viewDescRef = (0, _react.useRef)();
|
|
28
23
|
const childrenRef = (0, _react.useRef)([]);
|
|
29
24
|
const create = (0, _useEffectEvent.useEffectEvent)(()=>{
|
|
30
25
|
if (!(view instanceof _ReactEditorView.ReactEditorView)) {
|
|
31
26
|
return;
|
|
32
27
|
}
|
|
33
|
-
const dom =
|
|
28
|
+
const dom = getDOM();
|
|
34
29
|
if (!dom) {
|
|
35
30
|
return;
|
|
36
31
|
}
|
|
@@ -41,12 +36,15 @@ function useNodeViewDescriptor(ref, constructor, props) {
|
|
|
41
36
|
}
|
|
42
37
|
const parent = parentRef.current;
|
|
43
38
|
const children = childrenRef.current;
|
|
44
|
-
const contentDOM =
|
|
39
|
+
const contentDOM = getContentDOM(nodeView);
|
|
45
40
|
const nodeDOM = nodeView.dom;
|
|
46
41
|
const viewDesc = new _viewdesc.ReactNodeViewDesc(parent, children, getPos, node, decorations, innerDecorations, dom, contentDOM, nodeDOM, nodeView);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
const siblings = siblingsRef.current;
|
|
43
|
+
if (!siblings.includes(viewDesc)) {
|
|
44
|
+
siblings.push(viewDesc);
|
|
45
|
+
}
|
|
46
|
+
siblings.sort(_viewdesc.sortViewDescs);
|
|
47
|
+
contentDOMRef.current = getContentDOM(nodeView);
|
|
50
48
|
return viewDesc;
|
|
51
49
|
});
|
|
52
50
|
const update = (0, _useEffectEvent.useEffectEvent)(()=>{
|
|
@@ -57,11 +55,11 @@ function useNodeViewDescriptor(ref, constructor, props) {
|
|
|
57
55
|
if (!viewDesc) {
|
|
58
56
|
return false;
|
|
59
57
|
}
|
|
60
|
-
const dom =
|
|
58
|
+
const dom = getDOM();
|
|
61
59
|
if (!dom || dom !== viewDesc.dom) {
|
|
62
60
|
return false;
|
|
63
61
|
}
|
|
64
|
-
const contentDOM =
|
|
62
|
+
const contentDOM = getContentDOM(viewDesc);
|
|
65
63
|
if (contentDOM !== viewDesc.contentDOM) {
|
|
66
64
|
return false;
|
|
67
65
|
}
|
|
@@ -82,9 +80,7 @@ function useNodeViewDescriptor(ref, constructor, props) {
|
|
|
82
80
|
const index = siblings.indexOf(viewDesc);
|
|
83
81
|
siblings.splice(index, 1);
|
|
84
82
|
}
|
|
85
|
-
|
|
86
|
-
setContentDOM(null);
|
|
87
|
-
setNodeDOM(null);
|
|
83
|
+
contentDOMRef.current = null;
|
|
88
84
|
});
|
|
89
85
|
(0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
|
|
90
86
|
viewDescRef.current = create();
|
|
@@ -95,6 +91,17 @@ function useNodeViewDescriptor(ref, constructor, props) {
|
|
|
95
91
|
create,
|
|
96
92
|
destroy
|
|
97
93
|
]);
|
|
94
|
+
const refUpdated = (0, _react.useCallback)(()=>{
|
|
95
|
+
if (!viewDescRef.current) return;
|
|
96
|
+
if (!update()) {
|
|
97
|
+
destroy();
|
|
98
|
+
viewDescRef.current = create();
|
|
99
|
+
}
|
|
100
|
+
}, [
|
|
101
|
+
create,
|
|
102
|
+
destroy,
|
|
103
|
+
update
|
|
104
|
+
]);
|
|
98
105
|
(0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
|
|
99
106
|
if (!update()) {
|
|
100
107
|
destroy();
|
|
@@ -146,9 +153,7 @@ function useNodeViewDescriptor(ref, constructor, props) {
|
|
|
146
153
|
]);
|
|
147
154
|
return {
|
|
148
155
|
childContextValue,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
nodeDOM,
|
|
152
|
-
ref
|
|
156
|
+
contentDOM: contentDOMRef.current,
|
|
157
|
+
refUpdated
|
|
153
158
|
};
|
|
154
159
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -43,6 +43,12 @@ _export(exports, {
|
|
|
43
43
|
useIsNodeSelected: function() {
|
|
44
44
|
return _useIsNodeSelected.useIsNodeSelected;
|
|
45
45
|
},
|
|
46
|
+
useMergedDOMRefs: function() {
|
|
47
|
+
return _refs.useMergedDOMRefs;
|
|
48
|
+
},
|
|
49
|
+
useNodePos: function() {
|
|
50
|
+
return _useNodePos.useNodePos;
|
|
51
|
+
},
|
|
46
52
|
useSelectNode: function() {
|
|
47
53
|
return _useSelectNode.useSelectNode;
|
|
48
54
|
},
|
|
@@ -60,6 +66,7 @@ const _useEditorEffect = require("./hooks/useEditorEffect.js");
|
|
|
60
66
|
const _useEditorEventCallback = require("./hooks/useEditorEventCallback.js");
|
|
61
67
|
const _useEditorEventListener = require("./hooks/useEditorEventListener.js");
|
|
62
68
|
const _useEditorState = require("./hooks/useEditorState.js");
|
|
69
|
+
const _useNodePos = require("./hooks/useNodePos.js");
|
|
63
70
|
const _useStopEvent = require("./hooks/useStopEvent.js");
|
|
64
71
|
const _useSelectNode = require("./hooks/useSelectNode.js");
|
|
65
72
|
const _useIgnoreMutation = require("./hooks/useIgnoreMutation.js");
|
|
@@ -67,3 +74,4 @@ const _useIsEditorStatic = require("./hooks/useIsEditorStatic.js");
|
|
|
67
74
|
const _useIsNodeSelected = require("./hooks/useIsNodeSelected.js");
|
|
68
75
|
const _reactKeys = require("./plugins/reactKeys.js");
|
|
69
76
|
const _ReactWidgetType = require("./decorations/ReactWidgetType.js");
|
|
77
|
+
const _refs = require("./refs.js");
|
package/dist/cjs/refs.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useMergedDOMRefs", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useMergedDOMRefs;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = require("react");
|
|
12
|
+
function useMergedDOMRefs() {
|
|
13
|
+
for(var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++){
|
|
14
|
+
refs[_key] = arguments[_key];
|
|
15
|
+
}
|
|
16
|
+
return (0, _react.useCallback)((value)=>{
|
|
17
|
+
refs.forEach((ref)=>{
|
|
18
|
+
if (typeof ref === "function") {
|
|
19
|
+
ref(value);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (ref) {
|
|
23
|
+
ref.current = value;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
+
}, refs);
|
|
28
|
+
}
|
package/dist/cjs/viewdesc.js
CHANGED
|
@@ -18,6 +18,9 @@ _export(exports, {
|
|
|
18
18
|
NodeViewDesc: function() {
|
|
19
19
|
return NodeViewDesc;
|
|
20
20
|
},
|
|
21
|
+
ReactMarkViewDesc: function() {
|
|
22
|
+
return ReactMarkViewDesc;
|
|
23
|
+
},
|
|
21
24
|
ReactNodeViewDesc: function() {
|
|
22
25
|
return ReactNodeViewDesc;
|
|
23
26
|
},
|
|
@@ -33,6 +36,9 @@ _export(exports, {
|
|
|
33
36
|
WidgetViewDesc: function() {
|
|
34
37
|
return WidgetViewDesc;
|
|
35
38
|
},
|
|
39
|
+
sameOuterDeco: function() {
|
|
40
|
+
return sameOuterDeco;
|
|
41
|
+
},
|
|
36
42
|
sortViewDescs: function() {
|
|
37
43
|
return sortViewDescs;
|
|
38
44
|
}
|
|
@@ -724,23 +730,30 @@ let CustomNodeViewDesc = class CustomNodeViewDesc extends NodeViewDesc {
|
|
|
724
730
|
}
|
|
725
731
|
}
|
|
726
732
|
selectNode() {
|
|
727
|
-
this.spec.selectNode ? this.spec.selectNode
|
|
733
|
+
this.spec.selectNode ? this.spec.selectNode() : super.selectNode();
|
|
728
734
|
}
|
|
729
735
|
deselectNode() {
|
|
730
|
-
this.spec.deselectNode ? this.spec.deselectNode
|
|
736
|
+
this.spec.deselectNode ? this.spec.deselectNode() : super.deselectNode();
|
|
731
737
|
}
|
|
732
738
|
setSelection(anchor, head, view, force) {
|
|
733
|
-
this.spec.setSelection ? this.spec.setSelection
|
|
739
|
+
this.spec.setSelection ? this.spec.setSelection(anchor, head, view.root) : super.setSelection(anchor, head, view, force);
|
|
734
740
|
}
|
|
735
741
|
destroy() {
|
|
736
742
|
if (this.spec.destroy) this.spec.destroy();
|
|
737
743
|
super.destroy();
|
|
738
744
|
}
|
|
739
745
|
stopEvent(event) {
|
|
740
|
-
return this.spec.stopEvent ? this.spec.stopEvent
|
|
746
|
+
return this.spec.stopEvent ? this.spec.stopEvent(event) : false;
|
|
741
747
|
}
|
|
742
748
|
ignoreMutation(mutation) {
|
|
743
|
-
return this.spec.ignoreMutation ? this.spec.ignoreMutation
|
|
749
|
+
return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
let ReactMarkViewDesc = class ReactMarkViewDesc extends MarkViewDesc {
|
|
753
|
+
destroy() {
|
|
754
|
+
// React has already destroyed the children (if needed).
|
|
755
|
+
this.children = [];
|
|
756
|
+
super.destroy();
|
|
744
757
|
}
|
|
745
758
|
};
|
|
746
759
|
let ReactNodeViewDesc = class ReactNodeViewDesc extends CustomNodeViewDesc {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React, { cloneElement, createElement, memo, useCallback, useContext, useRef } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
|
|
3
3
|
import { EditorContext } from "../contexts/EditorContext.js";
|
|
4
4
|
import { iterDeco } from "../decorations/iterDeco.js";
|
|
5
5
|
import { useReactKeys } from "../hooks/useReactKeys.js";
|
|
6
6
|
import { htmlAttrsToReactProps, mergeReactProps } from "../props.js";
|
|
7
|
+
import { sameOuterDeco } from "../viewdesc.js";
|
|
7
8
|
import { NativeWidgetView } from "./NativeWidgetView.js";
|
|
8
9
|
import { SeparatorHackView } from "./SeparatorHackView.js";
|
|
9
10
|
import { TextNodeView } from "./TextNodeView.js";
|
|
@@ -23,8 +24,7 @@ export function wrapInDeco(reactNode, deco) {
|
|
|
23
24
|
return /*#__PURE__*/ cloneElement(reactNode, mergeReactProps(reactNode.props, props));
|
|
24
25
|
}
|
|
25
26
|
function areChildrenEqual(a, b) {
|
|
26
|
-
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
|
|
27
|
-
prevDeco.type.eq(nextDeco.type))) && a.innerDeco.eq(b.innerDeco) : true) && a.node === b.node && a.widget === b.widget;
|
|
27
|
+
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" || b.type !== "node" || a.node.eq(b.node) && sameOuterDeco(a.outerDeco, b.outerDeco) && a.innerDeco.eq(b.innerDeco)) && a.widget === b.widget;
|
|
28
28
|
}
|
|
29
29
|
const ChildView = /*#__PURE__*/ memo(function ChildView(param) {
|
|
30
30
|
let { child, getInnerPos } = param;
|
|
@@ -47,7 +47,7 @@ const ChildView = /*#__PURE__*/ memo(function ChildView(param) {
|
|
|
47
47
|
}) : child.type === "hack" ? /*#__PURE__*/ React.createElement(child.component, {
|
|
48
48
|
key: child.key,
|
|
49
49
|
getPos: getPos
|
|
50
|
-
}) : child.node.isText ? /*#__PURE__*/ React.createElement(
|
|
50
|
+
}) : child.node.isText ? /*#__PURE__*/ React.createElement(ChildDescriptionsContext.Consumer, {
|
|
51
51
|
key: child.key
|
|
52
52
|
}, (param)=>{
|
|
53
53
|
let { siblingsRef, parentRef } = param;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { useContext, useRef } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
|
|
3
3
|
import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
|
|
4
4
|
import { useEditorEffect } from "../hooks/useEditorEffect.js";
|
|
5
5
|
import { WidgetViewDesc, sortViewDescs } from "../viewdesc.js";
|
|
6
6
|
export function NativeWidgetView(param) {
|
|
7
7
|
let { widget, getPos } = param;
|
|
8
|
-
const { siblingsRef, parentRef } = useContext(
|
|
8
|
+
const { siblingsRef, parentRef } = useContext(ChildDescriptionsContext);
|
|
9
9
|
const viewDescRef = useRef(null);
|
|
10
10
|
const rootDomRef = useRef(null);
|
|
11
11
|
useClientLayoutEffect(()=>{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { createElement, forwardRef, memo } from "react";
|
|
2
2
|
import { htmlAttrsToReactProps, mergeReactProps } from "../props.js";
|
|
3
|
+
import { useMergedDOMRefs } from "../refs.js";
|
|
3
4
|
/**
|
|
4
5
|
* Whether an output spec contains a hole
|
|
5
6
|
*/ function hasHole(outputSpec) {
|
|
@@ -21,7 +22,8 @@ import { htmlAttrsToReactProps, mergeReactProps } from "../props.js";
|
|
|
21
22
|
return false;
|
|
22
23
|
}
|
|
23
24
|
const ForwardedOutputSpec = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function OutputSpec(param, ref) {
|
|
24
|
-
let { outputSpec, isMark, children, ...propOverrides } = param;
|
|
25
|
+
let { outputSpec, isMark, contentDOMRef, children, ...propOverrides } = param;
|
|
26
|
+
const mergedRef = useMergedDOMRefs(ref, contentDOMRef);
|
|
25
27
|
if (typeof outputSpec === "string") {
|
|
26
28
|
return /*#__PURE__*/ React.createElement(React.Fragment, null, outputSpec);
|
|
27
29
|
}
|
|
@@ -47,10 +49,14 @@ const ForwardedOutputSpec = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function
|
|
|
47
49
|
if (i < outputSpec.length - 1 || i > start) {
|
|
48
50
|
throw new RangeError("Content hole must be the only child of its parent node");
|
|
49
51
|
}
|
|
50
|
-
return /*#__PURE__*/ createElement(tagName,
|
|
52
|
+
return /*#__PURE__*/ createElement(tagName, {
|
|
53
|
+
...props,
|
|
54
|
+
ref: ref ? mergedRef : contentDOMRef
|
|
55
|
+
}, children);
|
|
51
56
|
}
|
|
52
57
|
content.push(/*#__PURE__*/ React.createElement(ForwardedOutputSpec, {
|
|
53
|
-
outputSpec: child
|
|
58
|
+
outputSpec: child,
|
|
59
|
+
contentDOMRef: contentDOMRef
|
|
54
60
|
}, children));
|
|
55
61
|
}
|
|
56
62
|
// https://prosemirror.net/docs/ref/#model.MarkSpec.toDOM
|
|
@@ -58,6 +64,7 @@ const ForwardedOutputSpec = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function
|
|
|
58
64
|
// marked content is placed. Otherwise, it is appended to the top node.
|
|
59
65
|
if (isMark && !hasHole(outputSpec)) {
|
|
60
66
|
content.push(children);
|
|
67
|
+
props.ref = mergedRef;
|
|
61
68
|
}
|
|
62
69
|
return /*#__PURE__*/ createElement(tagName, props, ...content);
|
|
63
70
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useMemo, useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
|
|
3
3
|
import { EditorContext } from "../contexts/EditorContext.js";
|
|
4
4
|
import { EditorStateContext } from "../contexts/EditorStateContext.js";
|
|
5
5
|
import { NodeViewContext } from "../contexts/NodeViewContext.js";
|
|
@@ -11,7 +11,7 @@ import { DocNodeViewContext } from "./ProseMirrorDoc.js";
|
|
|
11
11
|
function getPos() {
|
|
12
12
|
return -1;
|
|
13
13
|
}
|
|
14
|
-
const
|
|
14
|
+
const rootChildDescriptionsContextValue = {
|
|
15
15
|
parentRef: {
|
|
16
16
|
current: undefined
|
|
17
17
|
},
|
|
@@ -20,39 +20,33 @@ const rootChildDescriptorsContextValue = {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
function ProseMirrorInner(param) {
|
|
23
|
-
let {
|
|
23
|
+
let { children, nodeViewComponents, markViewComponents, ...props } = param;
|
|
24
24
|
const [mount, setMount] = useState(null);
|
|
25
|
-
const { editor, state } = useEditor(mount,
|
|
26
|
-
...props,
|
|
27
|
-
nodeViews: customNodeViews,
|
|
28
|
-
markViews: customMarkViews
|
|
29
|
-
});
|
|
25
|
+
const { editor, state } = useEditor(mount, props);
|
|
30
26
|
const nodeViewConstructors = editor.view.nodeViews;
|
|
31
27
|
const nodeViewContextValue = useMemo(()=>{
|
|
32
28
|
return {
|
|
33
29
|
components: {
|
|
34
|
-
...
|
|
35
|
-
...
|
|
30
|
+
...nodeViewComponents,
|
|
31
|
+
...markViewComponents
|
|
36
32
|
},
|
|
37
33
|
constructors: nodeViewConstructors
|
|
38
34
|
};
|
|
39
35
|
}, [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
markViewComponents,
|
|
37
|
+
nodeViewComponents,
|
|
38
|
+
nodeViewConstructors
|
|
43
39
|
]);
|
|
44
40
|
const node = state.doc;
|
|
45
41
|
const decorations = computeDocDeco(editor.view);
|
|
46
42
|
const innerDecorations = viewDecorations(editor.view, editor.cursorWrapper);
|
|
47
43
|
const docNodeViewContextValue = useMemo(()=>({
|
|
48
|
-
className,
|
|
49
44
|
setMount,
|
|
50
45
|
node,
|
|
51
46
|
getPos,
|
|
52
47
|
decorations,
|
|
53
48
|
innerDecorations
|
|
54
49
|
}), [
|
|
55
|
-
className,
|
|
56
50
|
node,
|
|
57
51
|
decorations,
|
|
58
52
|
innerDecorations
|
|
@@ -63,8 +57,8 @@ function ProseMirrorInner(param) {
|
|
|
63
57
|
value: state
|
|
64
58
|
}, /*#__PURE__*/ React.createElement(NodeViewContext.Provider, {
|
|
65
59
|
value: nodeViewContextValue
|
|
66
|
-
}, /*#__PURE__*/ React.createElement(
|
|
67
|
-
value:
|
|
60
|
+
}, /*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
|
|
61
|
+
value: rootChildDescriptionsContextValue
|
|
68
62
|
}, /*#__PURE__*/ React.createElement(DocNodeViewContext.Provider, {
|
|
69
63
|
value: docNodeViewContextValue
|
|
70
64
|
}, children)))));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { useContext, useRef, useState } from "react";
|
|
2
2
|
import { browser } from "../browser.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
|
|
4
4
|
import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
|
|
5
5
|
import { TrailingHackViewDesc, sortViewDescs } from "../viewdesc.js";
|
|
6
6
|
export function SeparatorHackView(param) {
|
|
7
7
|
let { getPos } = param;
|
|
8
|
-
const { siblingsRef, parentRef } = useContext(
|
|
8
|
+
const { siblingsRef, parentRef } = useContext(ChildDescriptionsContext);
|
|
9
9
|
const viewDescRef = useRef(null);
|
|
10
10
|
const ref = useRef(null);
|
|
11
11
|
const [shouldRender, setShouldRender] = useState(false);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useContext, useRef } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
|
|
3
3
|
import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
|
|
4
4
|
import { TrailingHackViewDesc, sortViewDescs } from "../viewdesc.js";
|
|
5
5
|
export function TrailingHackView(param) {
|
|
6
6
|
let { getPos } = param;
|
|
7
|
-
const { siblingsRef, parentRef } = useContext(
|
|
7
|
+
const { siblingsRef, parentRef } = useContext(ChildDescriptionsContext);
|
|
8
8
|
const viewDescRef = useRef(null);
|
|
9
9
|
const ref = useRef(null);
|
|
10
10
|
useClientLayoutEffect(()=>{
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useContext, useRef } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
|
|
3
3
|
import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
|
|
4
4
|
import { WidgetViewDesc, sortViewDescs } from "../viewdesc.js";
|
|
5
5
|
export function WidgetView(param) {
|
|
6
6
|
let { widget, getPos } = param;
|
|
7
|
-
const { siblingsRef, parentRef } = useContext(
|
|
7
|
+
const { siblingsRef, parentRef } = useContext(ChildDescriptionsContext);
|
|
8
8
|
const viewDescRef = useRef(null);
|
|
9
9
|
const domRef = useRef(null);
|
|
10
10
|
useClientLayoutEffect(()=>{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef, useMemo } from "react";
|
|
2
2
|
import { OutputSpec } from "../OutputSpec.js";
|
|
3
3
|
export const DefaultMarkView = /*#__PURE__*/ forwardRef(function DefaultMarkView(param, ref) {
|
|
4
|
-
let { markProps: { mark, inline }, children, ...props } = param;
|
|
4
|
+
let { markProps: { mark, inline, contentDOMRef }, children, ...props } = param;
|
|
5
5
|
const spec = useMemo(()=>mark.type.spec.toDOM?.(mark, inline), [
|
|
6
6
|
mark,
|
|
7
7
|
inline
|
|
@@ -12,6 +12,7 @@ export const DefaultMarkView = /*#__PURE__*/ forwardRef(function DefaultMarkView
|
|
|
12
12
|
return /*#__PURE__*/ React.createElement(OutputSpec, {
|
|
13
13
|
...props,
|
|
14
14
|
outputSpec: spec,
|
|
15
|
+
contentDOMRef: contentDOMRef,
|
|
15
16
|
ref: ref,
|
|
16
17
|
isMark: true
|
|
17
18
|
}, children);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { memo, useContext, useMemo } from "react";
|
|
2
2
|
import { NodeViewContext } from "../../contexts/NodeViewContext.js";
|
|
3
|
-
import { CustomMarkView } from "./CustomMarkView.js";
|
|
4
3
|
import { DefaultMarkView } from "./DefaultMarkView.js";
|
|
4
|
+
import { MarkViewConstructorView } from "./MarkViewConstructorView.js";
|
|
5
5
|
import { ReactMarkView } from "./ReactMarkView.js";
|
|
6
6
|
export const MarkView = /*#__PURE__*/ memo(function MarkView(props) {
|
|
7
7
|
const { components, constructors } = useContext(NodeViewContext);
|
|
@@ -14,7 +14,7 @@ export const MarkView = /*#__PURE__*/ memo(function MarkView(props) {
|
|
|
14
14
|
const Component = useMemo(()=>{
|
|
15
15
|
if (constructor) {
|
|
16
16
|
return function MarkView(props) {
|
|
17
|
-
return /*#__PURE__*/ React.createElement(
|
|
17
|
+
return /*#__PURE__*/ React.createElement(MarkViewConstructorView, {
|
|
18
18
|
constructor: constructor,
|
|
19
19
|
...props
|
|
20
20
|
});
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { DOMSerializer } from "prosemirror-model";
|
|
2
2
|
import React, { memo, useMemo, useRef } from "react";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
|
-
import {
|
|
4
|
+
import { ChildDescriptionsContext } from "../../contexts/ChildDescriptionsContext.js";
|
|
5
|
+
import { useForceUpdate } from "../../hooks/useForceUpdate.js";
|
|
5
6
|
import { useMarkViewDescription } from "../../hooks/useMarkViewDescription.js";
|
|
6
|
-
export const
|
|
7
|
+
export const MarkViewConstructorView = /*#__PURE__*/ memo(function MarkViewConstructorView(param) {
|
|
7
8
|
let { constructor, mark, inline, getPos, children } = param;
|
|
8
9
|
const ref = useRef(null);
|
|
9
10
|
const innerRef = useRef(null);
|
|
11
|
+
const forceUpdate = useForceUpdate();
|
|
10
12
|
const markProps = useMemo(()=>({
|
|
11
13
|
mark,
|
|
12
14
|
inline,
|
|
13
|
-
getPos
|
|
15
|
+
getPos,
|
|
16
|
+
contentDOMRef: {
|
|
17
|
+
current: null
|
|
18
|
+
}
|
|
14
19
|
}), [
|
|
15
20
|
mark,
|
|
16
21
|
inline,
|
|
@@ -30,13 +35,17 @@ export const CustomMarkView = /*#__PURE__*/ memo(function CustomMarkView(param)
|
|
|
30
35
|
}
|
|
31
36
|
return markView;
|
|
32
37
|
};
|
|
33
|
-
const { childContextValue, contentDOM } = useMarkViewDescription(ref, function() {
|
|
38
|
+
const { childContextValue, contentDOM } = useMarkViewDescription(()=>ref.current, (markView)=>markView?.contentDOM ?? null, function() {
|
|
34
39
|
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
35
40
|
args[_key] = arguments[_key];
|
|
36
41
|
}
|
|
37
42
|
const markView = createMarkView(...args);
|
|
38
43
|
const dom = markView.dom;
|
|
39
44
|
const wrapperDOM = innerRef.current ?? ref.current;
|
|
45
|
+
wrapperDOM.appendChild(dom);
|
|
46
|
+
// Force a re-render so that we properly create
|
|
47
|
+
// a portal into the contentDOM/dom
|
|
48
|
+
forceUpdate();
|
|
40
49
|
return {
|
|
41
50
|
...markView,
|
|
42
51
|
destroy () {
|
|
@@ -50,7 +59,7 @@ export const CustomMarkView = /*#__PURE__*/ memo(function CustomMarkView(param)
|
|
|
50
59
|
const props = {
|
|
51
60
|
ref: innerRef
|
|
52
61
|
};
|
|
53
|
-
return /*#__PURE__*/ React.createElement(Component, props, contentDOM ? /*#__PURE__*/ createPortal(/*#__PURE__*/ React.createElement(
|
|
62
|
+
return /*#__PURE__*/ React.createElement(Component, props, contentDOM ? /*#__PURE__*/ createPortal(/*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
|
|
54
63
|
value: childContextValue
|
|
55
64
|
}, children), contentDOM) : null);
|
|
56
65
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { memo, useCallback, useMemo, useRef } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { ChildDescriptionsContext } from "../../contexts/ChildDescriptionsContext.js";
|
|
3
3
|
import { IgnoreMutationContext } from "../../contexts/IgnoreMutationContext.js";
|
|
4
4
|
import { useMarkViewDescription } from "../../hooks/useMarkViewDescription.js";
|
|
5
5
|
export const ReactMarkView = /*#__PURE__*/ memo(function ReactMarkView(param) {
|
|
6
6
|
let { component: Component, mark, inline, getPos, children } = param;
|
|
7
7
|
const ref = useRef(null);
|
|
8
|
+
const contentDOMRef = useRef(null);
|
|
8
9
|
const ignoreMutationRef = useRef(null);
|
|
9
10
|
const setIgnoreMutation = useCallback((handler)=>{
|
|
10
11
|
ignoreMutationRef.current = handler;
|
|
@@ -15,7 +16,7 @@ export const ReactMarkView = /*#__PURE__*/ memo(function ReactMarkView(param) {
|
|
|
15
16
|
};
|
|
16
17
|
};
|
|
17
18
|
}, []);
|
|
18
|
-
const
|
|
19
|
+
const markViewDescProps = useMemo(()=>({
|
|
19
20
|
mark,
|
|
20
21
|
getPos,
|
|
21
22
|
inline
|
|
@@ -24,7 +25,7 @@ export const ReactMarkView = /*#__PURE__*/ memo(function ReactMarkView(param) {
|
|
|
24
25
|
inline,
|
|
25
26
|
mark
|
|
26
27
|
]);
|
|
27
|
-
const { childContextValue } = useMarkViewDescription(ref, ()=>({
|
|
28
|
+
const { childContextValue, refUpdated } = useMarkViewDescription(()=>ref.current, ()=>contentDOMRef.current ?? ref.current, ()=>({
|
|
28
29
|
dom: ref.current,
|
|
29
30
|
ignoreMutation (mutation) {
|
|
30
31
|
const ignoreMutation = ignoreMutationRef.current;
|
|
@@ -33,14 +34,33 @@ export const ReactMarkView = /*#__PURE__*/ memo(function ReactMarkView(param) {
|
|
|
33
34
|
}
|
|
34
35
|
return false;
|
|
35
36
|
}
|
|
36
|
-
}),
|
|
37
|
+
}), markViewDescProps);
|
|
38
|
+
const setDOM = useCallback((el)=>{
|
|
39
|
+
ref.current = el;
|
|
40
|
+
refUpdated();
|
|
41
|
+
}, [
|
|
42
|
+
refUpdated
|
|
43
|
+
]);
|
|
44
|
+
const setContentDOM = useCallback((el)=>{
|
|
45
|
+
contentDOMRef.current = el;
|
|
46
|
+
refUpdated();
|
|
47
|
+
}, [
|
|
48
|
+
refUpdated
|
|
49
|
+
]);
|
|
50
|
+
const markProps = useMemo(()=>({
|
|
51
|
+
...markViewDescProps,
|
|
52
|
+
contentDOMRef: setContentDOM
|
|
53
|
+
}), [
|
|
54
|
+
markViewDescProps,
|
|
55
|
+
setContentDOM
|
|
56
|
+
]);
|
|
37
57
|
const props = {
|
|
38
58
|
markProps,
|
|
39
|
-
ref
|
|
59
|
+
ref: setDOM
|
|
40
60
|
};
|
|
41
61
|
return /*#__PURE__*/ React.createElement(IgnoreMutationContext.Provider, {
|
|
42
62
|
value: setIgnoreMutation
|
|
43
|
-
}, /*#__PURE__*/ React.createElement(
|
|
63
|
+
}, /*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
|
|
44
64
|
value: childContextValue
|
|
45
65
|
}, /*#__PURE__*/ React.createElement(Component, props, children)));
|
|
46
66
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef, useMemo } from "react";
|
|
2
2
|
import { OutputSpec } from "../OutputSpec.js";
|
|
3
3
|
export const DefaultNodeView = /*#__PURE__*/ forwardRef(function DefaultNodeView(param, ref) {
|
|
4
|
-
let { nodeProps: { node }, children, ...props } = param;
|
|
4
|
+
let { nodeProps: { node, contentDOMRef }, children, ...props } = param;
|
|
5
5
|
const spec = useMemo(()=>node.type.spec.toDOM?.(node), [
|
|
6
6
|
node
|
|
7
7
|
]);
|
|
@@ -11,6 +11,7 @@ export const DefaultNodeView = /*#__PURE__*/ forwardRef(function DefaultNodeView
|
|
|
11
11
|
return /*#__PURE__*/ React.createElement(OutputSpec, {
|
|
12
12
|
...props,
|
|
13
13
|
outputSpec: spec,
|
|
14
|
-
ref: ref
|
|
14
|
+
ref: ref,
|
|
15
|
+
contentDOMRef: contentDOMRef
|
|
15
16
|
}, children);
|
|
16
17
|
});
|