@handlewithcare/react-prosemirror 2.8.0-tiptap.23 → 2.8.1
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/dist/cjs/StaticEditorView.js +0 -3
- package/dist/cjs/commands/reorderSiblings.js +60 -45
- package/dist/cjs/components/nodes/CustomNodeView.js +1 -1
- package/dist/cjs/components/nodes/DocNodeView.js +1 -1
- package/dist/cjs/components/nodes/ReactNodeView.js +7 -5
- package/dist/cjs/hooks/useEditor.js +0 -4
- package/dist/cjs/hooks/useEditorEventCallback.js +1 -1
- package/dist/cjs/hooks/useNodeViewDescriptor.js +1 -4
- package/dist/cjs/viewdesc.js +5 -5
- package/dist/esm/StaticEditorView.js +0 -3
- package/dist/esm/commands/reorderSiblings.js +49 -42
- package/dist/esm/components/nodes/CustomNodeView.js +1 -1
- package/dist/esm/components/nodes/DocNodeView.js +1 -1
- package/dist/esm/components/nodes/ReactNodeView.js +8 -6
- 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/useNodeViewDescriptor.js +1 -4
- package/dist/esm/viewdesc.js +5 -5
- 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/commands/__tests__/reorderSiblings.test.d.ts +1 -0
- package/dist/types/commands/reorderSiblings.d.ts +3 -1
- package/dist/types/constants.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/useNodeViewDescriptor.d.ts +3 -1
- package/dist/types/props.d.ts +26 -26
- 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/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 -79
- 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/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 -69
- 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/CustomNodeView.d.ts +0 -12
- 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/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
|
@@ -1,57 +1,72 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ "use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
reorderSiblings: function() {
|
|
8
13
|
return reorderSiblings;
|
|
14
|
+
},
|
|
15
|
+
reorderSiblingsOnTransaction: function() {
|
|
16
|
+
return reorderSiblingsOnTransaction;
|
|
9
17
|
}
|
|
10
18
|
});
|
|
11
19
|
const _reactKeys = require("../plugins/reactKeys.js");
|
|
12
20
|
function reorderSiblings(pos, order) {
|
|
13
21
|
return function reorderSiblingsCommand(state, dispatch) {
|
|
14
|
-
const $pos = state.doc.resolve(pos);
|
|
15
|
-
if ($pos.start() !== pos) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
if (!dispatch) return true;
|
|
19
|
-
const nodes = $pos.parent.children;
|
|
20
|
-
const reordered = nodes.map((node, i)=>[
|
|
21
|
-
node,
|
|
22
|
-
i
|
|
23
|
-
]).sort((param, param1)=>{
|
|
24
|
-
let [, a] = param, [, b] = param1;
|
|
25
|
-
return order[a] - order[b];
|
|
26
|
-
}).map((param)=>{
|
|
27
|
-
let [node] = param;
|
|
28
|
-
return node;
|
|
29
|
-
});
|
|
30
22
|
const tr = state.tr;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
23
|
+
return reorderSiblingsOnTransaction(pos, order, tr, state, dispatch);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function reorderSiblingsOnTransaction(pos, order, tr, state, dispatch) {
|
|
27
|
+
const orderLookup = order.reduce((acc, oldIndex, newIndex)=>{
|
|
28
|
+
acc[oldIndex] = newIndex;
|
|
29
|
+
return acc;
|
|
30
|
+
}, []);
|
|
31
|
+
const $pos = state.doc.resolve(pos);
|
|
32
|
+
if ($pos.start() !== pos) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (!dispatch) return true;
|
|
36
|
+
const nodes = $pos.parent.children;
|
|
37
|
+
const reordered = nodes.map((node, i)=>[
|
|
38
|
+
node,
|
|
39
|
+
i
|
|
40
|
+
]).sort((param, param1)=>{
|
|
41
|
+
let [, a] = param, [, b] = param1;
|
|
42
|
+
return orderLookup[a] - orderLookup[b];
|
|
43
|
+
}).map((param)=>{
|
|
44
|
+
let [node] = param;
|
|
45
|
+
return node;
|
|
46
|
+
});
|
|
47
|
+
tr.replaceWith(pos, $pos.parent.content.size + pos, reordered);
|
|
48
|
+
const meta = {
|
|
49
|
+
overrides: {}
|
|
56
50
|
};
|
|
51
|
+
const oldPositions = [];
|
|
52
|
+
let start = pos;
|
|
53
|
+
for (const node of nodes){
|
|
54
|
+
oldPositions.push(start);
|
|
55
|
+
start += node.nodeSize;
|
|
56
|
+
}
|
|
57
|
+
start = pos;
|
|
58
|
+
const newPositions = [];
|
|
59
|
+
for(let i = 0; i < reordered.length; i++){
|
|
60
|
+
const node = reordered[i];
|
|
61
|
+
newPositions[order[i]] = start;
|
|
62
|
+
start += node.nodeSize;
|
|
63
|
+
}
|
|
64
|
+
for(let i = 0; i < oldPositions.length; i++){
|
|
65
|
+
const oldPosition = oldPositions[i];
|
|
66
|
+
const newPosition = newPositions[i];
|
|
67
|
+
meta.overrides[oldPosition] = newPosition;
|
|
68
|
+
}
|
|
69
|
+
tr.setMeta(_reactKeys.reactKeysPluginKey, meta);
|
|
70
|
+
dispatch(tr);
|
|
71
|
+
return true;
|
|
57
72
|
}
|
|
@@ -114,7 +114,7 @@ const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(pa
|
|
|
114
114
|
stopEvent: nodeView.stopEvent?.bind(nodeView),
|
|
115
115
|
ignoreMutation: nodeView.ignoreMutation?.bind(nodeView)
|
|
116
116
|
};
|
|
117
|
-
}, nodeProps);
|
|
117
|
+
}, (source)=>source?.contentDOM ?? null, nodeProps);
|
|
118
118
|
const Component = node.isInline ? "span" : "div";
|
|
119
119
|
const props = {
|
|
120
120
|
ref: innerRef
|
|
@@ -78,7 +78,7 @@ const DocNodeView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forw
|
|
|
78
78
|
return true;
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
}, nodeProps);
|
|
81
|
+
}, ()=>innerRef.current, nodeProps);
|
|
82
82
|
const children = /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
83
83
|
value: childContextValue
|
|
84
84
|
}, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "ReactNodeView", {
|
|
|
10
10
|
});
|
|
11
11
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _ChildDescriptorsContext = require("../../contexts/ChildDescriptorsContext.js");
|
|
13
|
+
const _EditorContext = require("../../contexts/EditorContext.js");
|
|
13
14
|
const _IgnoreMutationContext = require("../../contexts/IgnoreMutationContext.js");
|
|
14
15
|
const _SelectNodeContext = require("../../contexts/SelectNodeContext.js");
|
|
15
16
|
const _StopEventContext = require("../../contexts/StopEventContext.js");
|
|
@@ -58,6 +59,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
58
59
|
}
|
|
59
60
|
const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(param) {
|
|
60
61
|
let { component: Component, outerDeco, getPos, node, innerDeco } = param;
|
|
62
|
+
const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
|
|
61
63
|
const [hasCustomSelectNode, setHasCustomSelectNode] = (0, _react.useState)(false);
|
|
62
64
|
const [selected, setSelected] = (0, _react.useState)(false);
|
|
63
65
|
const ref = (0, _react.useRef)(null);
|
|
@@ -113,33 +115,33 @@ const ReactNodeView = /*#__PURE__*/ (0, _react.memo)(function ReactNodeView(para
|
|
|
113
115
|
selectNode () {
|
|
114
116
|
const selectNode = selectNodeRef.current;
|
|
115
117
|
if (selectNode) {
|
|
116
|
-
selectNode
|
|
118
|
+
selectNode();
|
|
117
119
|
}
|
|
118
120
|
setSelected(true);
|
|
119
121
|
},
|
|
120
122
|
deselectNode () {
|
|
121
123
|
const deselectNode = deselectNodeRef.current;
|
|
122
124
|
if (deselectNode) {
|
|
123
|
-
deselectNode
|
|
125
|
+
deselectNode();
|
|
124
126
|
}
|
|
125
127
|
setSelected(false);
|
|
126
128
|
},
|
|
127
129
|
stopEvent (event) {
|
|
128
130
|
const stopEvent = stopEventRef.current;
|
|
129
131
|
if (stopEvent) {
|
|
130
|
-
return stopEvent
|
|
132
|
+
return stopEvent(event);
|
|
131
133
|
}
|
|
132
134
|
return false;
|
|
133
135
|
},
|
|
134
136
|
ignoreMutation (mutation) {
|
|
135
137
|
const ignoreMutation = ignoreMutationRef.current;
|
|
136
138
|
if (ignoreMutation) {
|
|
137
|
-
return ignoreMutation
|
|
139
|
+
return ignoreMutation(mutation);
|
|
138
140
|
}
|
|
139
141
|
return false;
|
|
140
142
|
}
|
|
141
143
|
};
|
|
142
|
-
}, nodeProps);
|
|
144
|
+
}, (source, children)=>view.composing ? source?.contentDOM ?? null : children[0]?.dom.parentElement ?? null, nodeProps);
|
|
143
145
|
const props = {
|
|
144
146
|
nodeProps,
|
|
145
147
|
...!contentDOM && !nodeProps.node.isText && nodeDOM?.nodeName !== "BR" ? {
|
|
@@ -103,11 +103,7 @@ function useEditor(mount, options) {
|
|
|
103
103
|
// running effects. Running effects will reattach selection
|
|
104
104
|
// change listeners if the EditorView has been destroyed.
|
|
105
105
|
if (view instanceof _ReactEditorView.ReactEditorView && !view.isDestroyed) {
|
|
106
|
-
// Plugins might dispatch transactions from their
|
|
107
|
-
// view update lifecycle hooks
|
|
108
|
-
flushSyncRef.current = false;
|
|
109
106
|
view.commitPendingEffects();
|
|
110
|
-
flushSyncRef.current = true;
|
|
111
107
|
}
|
|
112
108
|
});
|
|
113
109
|
view.update(directEditorProps);
|
|
@@ -15,10 +15,7 @@ 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 useNodeViewDescriptor(ref, constructor, findContentDOM, props) {
|
|
22
19
|
const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
|
|
23
20
|
const { parentRef, siblingsRef } = (0, _react.useContext)(_ChildDescriptorsContext.ChildDescriptorsContext);
|
|
24
21
|
const [dom, setDOM] = (0, _react.useState)(null);
|
package/dist/cjs/viewdesc.js
CHANGED
|
@@ -724,23 +724,23 @@ let CustomNodeViewDesc = class CustomNodeViewDesc extends NodeViewDesc {
|
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
726
|
selectNode() {
|
|
727
|
-
this.spec.selectNode ? this.spec.selectNode
|
|
727
|
+
this.spec.selectNode ? this.spec.selectNode() : super.selectNode();
|
|
728
728
|
}
|
|
729
729
|
deselectNode() {
|
|
730
|
-
this.spec.deselectNode ? this.spec.deselectNode
|
|
730
|
+
this.spec.deselectNode ? this.spec.deselectNode() : super.deselectNode();
|
|
731
731
|
}
|
|
732
732
|
setSelection(anchor, head, view, force) {
|
|
733
|
-
this.spec.setSelection ? this.spec.setSelection
|
|
733
|
+
this.spec.setSelection ? this.spec.setSelection(anchor, head, view.root) : super.setSelection(anchor, head, view, force);
|
|
734
734
|
}
|
|
735
735
|
destroy() {
|
|
736
736
|
if (this.spec.destroy) this.spec.destroy();
|
|
737
737
|
super.destroy();
|
|
738
738
|
}
|
|
739
739
|
stopEvent(event) {
|
|
740
|
-
return this.spec.stopEvent ? this.spec.stopEvent
|
|
740
|
+
return this.spec.stopEvent ? this.spec.stopEvent(event) : false;
|
|
741
741
|
}
|
|
742
742
|
ignoreMutation(mutation) {
|
|
743
|
-
return this.spec.ignoreMutation ? this.spec.ignoreMutation
|
|
743
|
+
return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation);
|
|
744
744
|
}
|
|
745
745
|
};
|
|
746
746
|
let ReactNodeViewDesc = class ReactNodeViewDesc extends CustomNodeViewDesc {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { reactKeysPluginKey } from "../plugins/reactKeys.js";
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { reactKeysPluginKey } from "../plugins/reactKeys.js";
|
|
2
2
|
/**
|
|
3
3
|
* Create a command function that reorders the adjacent nodes starting
|
|
4
4
|
* at the provided position.
|
|
@@ -10,47 +10,54 @@ import { reactKeysPluginKey } from "../plugins/reactKeys.js";
|
|
|
10
10
|
* and keep the other two in relative order, set `order` to `[1, 2, 0]`.
|
|
11
11
|
*/ export function reorderSiblings(pos, order) {
|
|
12
12
|
return function reorderSiblingsCommand(state, dispatch) {
|
|
13
|
-
const $pos = state.doc.resolve(pos);
|
|
14
|
-
if ($pos.start() !== pos) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
if (!dispatch) return true;
|
|
18
|
-
const nodes = $pos.parent.children;
|
|
19
|
-
const reordered = nodes.map((node, i)=>[
|
|
20
|
-
node,
|
|
21
|
-
i
|
|
22
|
-
]).sort((param, param1)=>{
|
|
23
|
-
let [, a] = param, [, b] = param1;
|
|
24
|
-
return order[a] - order[b];
|
|
25
|
-
}).map((param)=>{
|
|
26
|
-
let [node] = param;
|
|
27
|
-
return node;
|
|
28
|
-
});
|
|
29
13
|
const tr = state.tr;
|
|
30
|
-
|
|
31
|
-
const meta = {
|
|
32
|
-
overrides: {}
|
|
33
|
-
};
|
|
34
|
-
const oldPositions = [];
|
|
35
|
-
let start = pos;
|
|
36
|
-
for (const node of nodes){
|
|
37
|
-
oldPositions.push(start);
|
|
38
|
-
start += node.nodeSize;
|
|
39
|
-
}
|
|
40
|
-
start = pos;
|
|
41
|
-
const newPositions = [];
|
|
42
|
-
for(let i = 0; i < reordered.length; i++){
|
|
43
|
-
const node = reordered[i];
|
|
44
|
-
newPositions[order[i]] = start;
|
|
45
|
-
start += node.nodeSize;
|
|
46
|
-
}
|
|
47
|
-
for(let i = 0; i < oldPositions.length; i++){
|
|
48
|
-
const oldPosition = oldPositions[i];
|
|
49
|
-
const newPosition = newPositions[i];
|
|
50
|
-
meta.overrides[oldPosition] = newPosition;
|
|
51
|
-
}
|
|
52
|
-
tr.setMeta(reactKeysPluginKey, meta);
|
|
53
|
-
dispatch(tr);
|
|
54
|
-
return true;
|
|
14
|
+
return reorderSiblingsOnTransaction(pos, order, tr, state, dispatch);
|
|
55
15
|
};
|
|
56
16
|
}
|
|
17
|
+
export function reorderSiblingsOnTransaction(pos, order, tr, state, dispatch) {
|
|
18
|
+
const orderLookup = order.reduce((acc, oldIndex, newIndex)=>{
|
|
19
|
+
acc[oldIndex] = newIndex;
|
|
20
|
+
return acc;
|
|
21
|
+
}, []);
|
|
22
|
+
const $pos = state.doc.resolve(pos);
|
|
23
|
+
if ($pos.start() !== pos) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (!dispatch) return true;
|
|
27
|
+
const nodes = $pos.parent.children;
|
|
28
|
+
const reordered = nodes.map((node, i)=>[
|
|
29
|
+
node,
|
|
30
|
+
i
|
|
31
|
+
]).sort((param, param1)=>{
|
|
32
|
+
let [, a] = param, [, b] = param1;
|
|
33
|
+
return orderLookup[a] - orderLookup[b];
|
|
34
|
+
}).map((param)=>{
|
|
35
|
+
let [node] = param;
|
|
36
|
+
return node;
|
|
37
|
+
});
|
|
38
|
+
tr.replaceWith(pos, $pos.parent.content.size + pos, reordered);
|
|
39
|
+
const meta = {
|
|
40
|
+
overrides: {}
|
|
41
|
+
};
|
|
42
|
+
const oldPositions = [];
|
|
43
|
+
let start = pos;
|
|
44
|
+
for (const node of nodes){
|
|
45
|
+
oldPositions.push(start);
|
|
46
|
+
start += node.nodeSize;
|
|
47
|
+
}
|
|
48
|
+
start = pos;
|
|
49
|
+
const newPositions = [];
|
|
50
|
+
for(let i = 0; i < reordered.length; i++){
|
|
51
|
+
const node = reordered[i];
|
|
52
|
+
newPositions[order[i]] = start;
|
|
53
|
+
start += node.nodeSize;
|
|
54
|
+
}
|
|
55
|
+
for(let i = 0; i < oldPositions.length; i++){
|
|
56
|
+
const oldPosition = oldPositions[i];
|
|
57
|
+
const newPosition = newPositions[i];
|
|
58
|
+
meta.overrides[oldPosition] = newPosition;
|
|
59
|
+
}
|
|
60
|
+
tr.setMeta(reactKeysPluginKey, meta);
|
|
61
|
+
dispatch(tr);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
@@ -63,7 +63,7 @@ export const CustomNodeView = /*#__PURE__*/ memo(function CustomNodeView(param)
|
|
|
63
63
|
stopEvent: nodeView.stopEvent?.bind(nodeView),
|
|
64
64
|
ignoreMutation: nodeView.ignoreMutation?.bind(nodeView)
|
|
65
65
|
};
|
|
66
|
-
}, nodeProps);
|
|
66
|
+
}, (source)=>source?.contentDOM ?? null, nodeProps);
|
|
67
67
|
const Component = node.isInline ? "span" : "div";
|
|
68
68
|
const props = {
|
|
69
69
|
ref: innerRef
|
|
@@ -27,7 +27,7 @@ export const DocNodeView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function
|
|
|
27
27
|
return true;
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
}, nodeProps);
|
|
30
|
+
}, ()=>innerRef.current, nodeProps);
|
|
31
31
|
const children = /*#__PURE__*/ React.createElement(ChildDescriptorsContext.Provider, {
|
|
32
32
|
value: childContextValue
|
|
33
33
|
}, /*#__PURE__*/ React.createElement(ChildNodeViews, {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React, { cloneElement, memo, useCallback, useMemo, useRef, useState } from "react";
|
|
1
|
+
import React, { cloneElement, memo, useCallback, useContext, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { ChildDescriptorsContext } from "../../contexts/ChildDescriptorsContext.js";
|
|
3
|
+
import { EditorContext } from "../../contexts/EditorContext.js";
|
|
3
4
|
import { IgnoreMutationContext } from "../../contexts/IgnoreMutationContext.js";
|
|
4
5
|
import { SelectNodeContext } from "../../contexts/SelectNodeContext.js";
|
|
5
6
|
import { StopEventContext } from "../../contexts/StopEventContext.js";
|
|
@@ -7,6 +8,7 @@ import { useNodeViewDescriptor } from "../../hooks/useNodeViewDescriptor.js";
|
|
|
7
8
|
import { ChildNodeViews, wrapInDeco } from "../ChildNodeViews.js";
|
|
8
9
|
export const ReactNodeView = /*#__PURE__*/ memo(function ReactNodeView(param) {
|
|
9
10
|
let { component: Component, outerDeco, getPos, node, innerDeco } = param;
|
|
11
|
+
const { view } = useContext(EditorContext);
|
|
10
12
|
const [hasCustomSelectNode, setHasCustomSelectNode] = useState(false);
|
|
11
13
|
const [selected, setSelected] = useState(false);
|
|
12
14
|
const ref = useRef(null);
|
|
@@ -62,33 +64,33 @@ export const ReactNodeView = /*#__PURE__*/ memo(function ReactNodeView(param) {
|
|
|
62
64
|
selectNode () {
|
|
63
65
|
const selectNode = selectNodeRef.current;
|
|
64
66
|
if (selectNode) {
|
|
65
|
-
selectNode
|
|
67
|
+
selectNode();
|
|
66
68
|
}
|
|
67
69
|
setSelected(true);
|
|
68
70
|
},
|
|
69
71
|
deselectNode () {
|
|
70
72
|
const deselectNode = deselectNodeRef.current;
|
|
71
73
|
if (deselectNode) {
|
|
72
|
-
deselectNode
|
|
74
|
+
deselectNode();
|
|
73
75
|
}
|
|
74
76
|
setSelected(false);
|
|
75
77
|
},
|
|
76
78
|
stopEvent (event) {
|
|
77
79
|
const stopEvent = stopEventRef.current;
|
|
78
80
|
if (stopEvent) {
|
|
79
|
-
return stopEvent
|
|
81
|
+
return stopEvent(event);
|
|
80
82
|
}
|
|
81
83
|
return false;
|
|
82
84
|
},
|
|
83
85
|
ignoreMutation (mutation) {
|
|
84
86
|
const ignoreMutation = ignoreMutationRef.current;
|
|
85
87
|
if (ignoreMutation) {
|
|
86
|
-
return ignoreMutation
|
|
88
|
+
return ignoreMutation(mutation);
|
|
87
89
|
}
|
|
88
90
|
return false;
|
|
89
91
|
}
|
|
90
92
|
};
|
|
91
|
-
}, nodeProps);
|
|
93
|
+
}, (source, children)=>view.composing ? source?.contentDOM ?? null : children[0]?.dom.parentElement ?? null, nodeProps);
|
|
92
94
|
const props = {
|
|
93
95
|
nodeProps,
|
|
94
96
|
...!contentDOM && !nodeProps.node.isText && nodeDOM?.nodeName !== "BR" ? {
|
|
@@ -101,11 +101,7 @@ let didWarnValueDefaultValue = false;
|
|
|
101
101
|
// running effects. Running effects will reattach selection
|
|
102
102
|
// change listeners if the EditorView has been destroyed.
|
|
103
103
|
if (view instanceof ReactEditorView && !view.isDestroyed) {
|
|
104
|
-
// Plugins might dispatch transactions from their
|
|
105
|
-
// view update lifecycle hooks
|
|
106
|
-
flushSyncRef.current = false;
|
|
107
104
|
view.commitPendingEffects();
|
|
108
|
-
flushSyncRef.current = true;
|
|
109
105
|
}
|
|
110
106
|
});
|
|
111
107
|
view.update(directEditorProps);
|
|
@@ -15,10 +15,6 @@ import { useLayoutGroupEffect } from "./useLayoutGroupEffect.js";
|
|
|
15
15
|
* synchronously after all DOM mutations, but they do so
|
|
16
16
|
* _after_ the EditorView has been updated, even when the
|
|
17
17
|
* EditorView lives in an ancestor component.
|
|
18
|
-
*
|
|
19
|
-
* This hook can only be used in a component that is mounted
|
|
20
|
-
* as a child of the TiptapEditorView component, including
|
|
21
|
-
* React node view components.
|
|
22
18
|
*/ export function useEditorEffect(effect, dependencies) {
|
|
23
19
|
const { view, flushSyncRef } = useContext(EditorContext);
|
|
24
20
|
// The rules of hooks want `effect` to be included in the
|
|
@@ -15,9 +15,11 @@ function assertIsReactEditorView(view) {
|
|
|
15
15
|
* The callback will be called with the EditorView instance
|
|
16
16
|
* as its first argument.
|
|
17
17
|
*
|
|
18
|
-
* This hook
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* This hook is dependent on both the
|
|
19
|
+
* `EditorViewContext.Provider` and the
|
|
20
|
+
* `DeferredLayoutEffectProvider`. It can only be used in a
|
|
21
|
+
* component that is mounted as a child of both of these
|
|
22
|
+
* providers.
|
|
21
23
|
*/ export function useEditorEventCallback(callback) {
|
|
22
24
|
const ref = useRef(callback);
|
|
23
25
|
const { view } = useContext(EditorContext);
|
|
@@ -31,7 +33,7 @@ function assertIsReactEditorView(view) {
|
|
|
31
33
|
args[_key] = arguments[_key];
|
|
32
34
|
}
|
|
33
35
|
assertIsReactEditorView(view);
|
|
34
|
-
return ref.current
|
|
36
|
+
return ref.current(view, ...args);
|
|
35
37
|
}, [
|
|
36
38
|
view
|
|
37
39
|
]);
|
|
@@ -5,10 +5,7 @@ import { EditorContext } from "../contexts/EditorContext.js";
|
|
|
5
5
|
import { CompositionViewDesc, ReactNodeViewDesc, sortViewDescs } from "../viewdesc.js";
|
|
6
6
|
import { useClientLayoutEffect } from "./useClientLayoutEffect.js";
|
|
7
7
|
import { useEffectEvent } from "./useEffectEvent.js";
|
|
8
|
-
function
|
|
9
|
-
return source?.contentDOM ?? children[0]?.dom?.parentElement ?? null;
|
|
10
|
-
}
|
|
11
|
-
export function useNodeViewDescriptor(ref, constructor, props) {
|
|
8
|
+
export function useNodeViewDescriptor(ref, constructor, findContentDOM, props) {
|
|
12
9
|
const { view } = useContext(EditorContext);
|
|
13
10
|
const { parentRef, siblingsRef } = useContext(ChildDescriptorsContext);
|
|
14
11
|
const [dom, setDOM] = useState(null);
|
package/dist/esm/viewdesc.js
CHANGED
|
@@ -711,23 +711,23 @@ let CustomNodeViewDesc = class CustomNodeViewDesc extends NodeViewDesc {
|
|
|
711
711
|
}
|
|
712
712
|
}
|
|
713
713
|
selectNode() {
|
|
714
|
-
this.spec.selectNode ? this.spec.selectNode
|
|
714
|
+
this.spec.selectNode ? this.spec.selectNode() : super.selectNode();
|
|
715
715
|
}
|
|
716
716
|
deselectNode() {
|
|
717
|
-
this.spec.deselectNode ? this.spec.deselectNode
|
|
717
|
+
this.spec.deselectNode ? this.spec.deselectNode() : super.deselectNode();
|
|
718
718
|
}
|
|
719
719
|
setSelection(anchor, head, view, force) {
|
|
720
|
-
this.spec.setSelection ? this.spec.setSelection
|
|
720
|
+
this.spec.setSelection ? this.spec.setSelection(anchor, head, view.root) : super.setSelection(anchor, head, view, force);
|
|
721
721
|
}
|
|
722
722
|
destroy() {
|
|
723
723
|
if (this.spec.destroy) this.spec.destroy();
|
|
724
724
|
super.destroy();
|
|
725
725
|
}
|
|
726
726
|
stopEvent(event) {
|
|
727
|
-
return this.spec.stopEvent ? this.spec.stopEvent
|
|
727
|
+
return this.spec.stopEvent ? this.spec.stopEvent(event) : false;
|
|
728
728
|
}
|
|
729
729
|
ignoreMutation(mutation) {
|
|
730
|
-
return this.spec.ignoreMutation ? this.spec.ignoreMutation
|
|
730
|
+
return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation);
|
|
731
731
|
}
|
|
732
732
|
};
|
|
733
733
|
export class ReactNodeViewDesc extends CustomNodeViewDesc {
|