@handlewithcare/react-prosemirror 2.4.12 → 2.5.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/AbstractEditorView.js +4 -0
- package/dist/cjs/ReactEditorView.js +156 -0
- package/dist/cjs/StaticEditorView.js +86 -0
- package/dist/cjs/components/ChildNodeViews.js +58 -29
- package/dist/cjs/components/CustomNodeView.js +77 -137
- package/dist/cjs/{hooks/useNodePos.js → components/DefaultNodeView.js} +24 -26
- package/dist/cjs/components/DocNodeView.js +33 -41
- package/dist/cjs/components/MarkView.js +1 -2
- package/dist/cjs/components/NativeWidgetView.js +2 -3
- package/dist/cjs/components/NodeView.js +31 -21
- package/dist/cjs/components/ProseMirror.js +25 -17
- package/dist/cjs/components/ProseMirrorDoc.js +7 -27
- package/dist/cjs/components/ReactNodeView.js +98 -61
- package/dist/cjs/components/SeparatorHackView.js +1 -2
- package/dist/cjs/components/TextNodeView.js +4 -5
- package/dist/cjs/components/TrailingHackView.js +1 -2
- package/dist/cjs/components/WidgetView.js +2 -4
- package/dist/cjs/constants.js +33 -0
- package/dist/cjs/hooks/useEditor.js +33 -229
- package/dist/cjs/hooks/useEditorEffect.js +2 -2
- package/dist/cjs/hooks/useEditorEventCallback.js +8 -5
- package/dist/cjs/hooks/useIgnoreMutation.js +1 -1
- package/dist/cjs/hooks/useNodeViewDescriptor.js +123 -80
- package/dist/cjs/hooks/useReactKeys.js +1 -1
- package/dist/cjs/hooks/useSelectNode.js +9 -7
- package/dist/cjs/hooks/useStopEvent.js +1 -1
- package/dist/cjs/plugins/beforeInputPlugin.js +12 -0
- package/dist/cjs/testing/editorViewTestHelpers.js +0 -2
- package/dist/cjs/viewdesc.js +104 -25
- package/dist/esm/AbstractEditorView.js +1 -0
- package/dist/esm/ReactEditorView.js +156 -0
- package/dist/esm/StaticEditorView.js +76 -0
- package/dist/esm/components/ChildNodeViews.js +59 -31
- package/dist/esm/components/CustomNodeView.js +78 -138
- package/dist/esm/components/DefaultNodeView.js +16 -0
- package/dist/esm/components/DocNodeView.js +33 -41
- package/dist/esm/components/MarkView.js +1 -2
- package/dist/esm/components/NativeWidgetView.js +2 -3
- package/dist/esm/components/NodeView.js +32 -22
- package/dist/esm/components/ProseMirror.js +25 -17
- package/dist/esm/components/ProseMirrorDoc.js +7 -28
- package/dist/esm/components/ReactNodeView.js +99 -62
- package/dist/esm/components/SeparatorHackView.js +1 -2
- package/dist/esm/components/TextNodeView.js +4 -5
- package/dist/esm/components/TrailingHackView.js +1 -2
- package/dist/esm/components/WidgetView.js +2 -4
- package/dist/esm/constants.js +15 -0
- package/dist/esm/hooks/useEditor.js +29 -218
- package/dist/esm/hooks/useEditorEffect.js +2 -2
- package/dist/esm/hooks/useEditorEventCallback.js +8 -5
- package/dist/esm/hooks/useIgnoreMutation.js +1 -1
- package/dist/esm/hooks/useNodeViewDescriptor.js +125 -82
- package/dist/esm/hooks/useReactKeys.js +1 -1
- package/dist/esm/hooks/useSelectNode.js +9 -7
- package/dist/esm/hooks/useStopEvent.js +1 -1
- package/dist/esm/plugins/beforeInputPlugin.js +12 -0
- package/dist/esm/testing/editorViewTestHelpers.js +0 -2
- package/dist/esm/viewdesc.js +94 -18
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/AbstractEditorView.d.ts +27 -0
- package/dist/types/ReactEditorView.d.ts +80 -0
- package/dist/types/StaticEditorView.d.ts +24 -0
- package/dist/types/components/ChildNodeViews.d.ts +2 -2
- package/dist/types/components/CustomNodeView.d.ts +3 -3
- package/dist/types/components/DefaultNodeView.d.ts +3 -0
- package/dist/types/components/DocNodeView.d.ts +9 -17
- package/dist/types/components/MarkView.d.ts +2 -2
- package/dist/types/components/NativeWidgetView.d.ts +2 -2
- package/dist/types/components/NodeView.d.ts +5 -5
- package/dist/types/components/NodeViewComponentProps.d.ts +3 -4
- package/dist/types/components/ProseMirrorDoc.d.ts +14 -8
- package/dist/types/components/ReactNodeView.d.ts +4 -2
- package/dist/types/components/SeparatorHackView.d.ts +2 -2
- package/dist/types/components/TextNodeView.d.ts +4 -3
- package/dist/types/components/TrailingHackView.d.ts +2 -2
- package/dist/types/components/WidgetView.d.ts +2 -2
- package/dist/types/constants.d.ts +4 -0
- package/dist/types/contexts/EditorContext.d.ts +6 -4
- package/dist/types/contexts/IgnoreMutationContext.d.ts +2 -1
- package/dist/types/contexts/NodeViewContext.d.ts +3 -1
- package/dist/types/contexts/SelectNodeContext.d.ts +3 -1
- package/dist/types/contexts/StopEventContext.d.ts +2 -1
- package/dist/types/decorations/computeDocDeco.d.ts +3 -2
- package/dist/types/decorations/viewDecorations.d.ts +3 -2
- package/dist/types/hooks/useEditor.d.ts +5 -46
- package/dist/types/hooks/useNodeViewDescriptor.d.ts +18 -10
- package/dist/types/hooks/useReactKeys.d.ts +1 -1
- package/dist/types/hooks/useSelectNode.d.ts +2 -1
- package/dist/types/props.d.ts +3 -3
- package/dist/types/viewdesc.d.ts +29 -11
- package/package.json +7 -3
- package/dist/cjs/components/Editor.js +0 -28
- package/dist/cjs/components/NodeViews.js +0 -73
- package/dist/cjs/components/__tests__/LayoutGroup.test.js +0 -141
- package/dist/cjs/components/__tests__/ProseMirror.test.js +0 -255
- package/dist/cjs/contexts/NodeViewsContext.js +0 -10
- package/dist/cjs/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -107
- package/dist/cjs/hooks/__tests__/useNodeViews.test.js +0 -159
- package/dist/cjs/hooks/useClientOnly.js +0 -19
- package/dist/cjs/hooks/useEditorView.js +0 -100
- package/dist/cjs/hooks/useNodeViews.js +0 -100
- package/dist/cjs/nodeViews/createReactNodeViewConstructor.js +0 -244
- package/dist/cjs/nodeViews/phrasingContentTags.js +0 -57
- package/dist/cjs/plugins/__tests__/react.test.js +0 -139
- package/dist/cjs/plugins/react.js +0 -71
- package/dist/cjs/selection/SelectionDOMObserver.js +0 -171
- package/dist/cjs/selection/hasFocusAndSelection.js +0 -35
- package/dist/cjs/selection/selectionFromDOM.js +0 -77
- package/dist/cjs/selection/selectionToDOM.js +0 -226
- package/dist/cjs/ssr.js +0 -85
- package/dist/esm/components/Editor.js +0 -15
- package/dist/esm/components/NodeViews.js +0 -26
- package/dist/esm/components/__tests__/LayoutGroup.test.js +0 -98
- package/dist/esm/components/__tests__/ProseMirror.test.js +0 -207
- package/dist/esm/contexts/NodeViewsContext.js +0 -9
- package/dist/esm/hooks/__tests__/useEditorViewLayoutEffect.test.js +0 -98
- package/dist/esm/hooks/__tests__/useNodeViews.test.js +0 -116
- package/dist/esm/hooks/useClientOnly.js +0 -9
- package/dist/esm/hooks/useEditorView.js +0 -99
- package/dist/esm/hooks/useNodePos.js +0 -16
- package/dist/esm/hooks/useNodeViews.js +0 -53
- package/dist/esm/nodeViews/createReactNodeViewConstructor.js +0 -214
- package/dist/esm/nodeViews/phrasingContentTags.js +0 -49
- package/dist/esm/plugins/__tests__/react.test.js +0 -135
- package/dist/esm/plugins/react.js +0 -64
- package/dist/esm/selection/SelectionDOMObserver.js +0 -161
- package/dist/esm/selection/hasFocusAndSelection.js +0 -17
- package/dist/esm/selection/selectionFromDOM.js +0 -59
- package/dist/esm/selection/selectionToDOM.js +0 -196
- package/dist/esm/ssr.js +0 -82
- package/dist/types/components/Editor.d.ts +0 -7
- package/dist/types/components/NodeViews.d.ts +0 -6
- package/dist/types/components/__tests__/LayoutGroup.test.d.ts +0 -1
- package/dist/types/contexts/NodeViewsContext.d.ts +0 -19
- package/dist/types/hooks/__tests__/useEditorViewLayoutEffect.test.d.ts +0 -1
- package/dist/types/hooks/__tests__/useNodeViews.test.d.ts +0 -1
- package/dist/types/hooks/useClientOnly.d.ts +0 -1
- package/dist/types/hooks/useEditorView.d.ts +0 -23
- package/dist/types/hooks/useNodePos.d.ts +0 -9
- package/dist/types/hooks/useNodeViews.d.ts +0 -5
- package/dist/types/nodeViews/createReactNodeViewConstructor.d.ts +0 -48
- package/dist/types/nodeViews/phrasingContentTags.d.ts +0 -1
- package/dist/types/plugins/__tests__/react.test.d.ts +0 -1
- package/dist/types/plugins/react.d.ts +0 -21
- package/dist/types/selection/SelectionDOMObserver.d.ts +0 -33
- package/dist/types/selection/hasFocusAndSelection.d.ts +0 -3
- package/dist/types/selection/selectionFromDOM.d.ts +0 -4
- package/dist/types/selection/selectionToDOM.d.ts +0 -9
- package/dist/types/ssr.d.ts +0 -19
|
@@ -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
|
+
// Prevent the base class from destroying the React-managed nodes.
|
|
37
|
+
// Restore them below after invoking the base class constructor.
|
|
38
|
+
const reactContent = [
|
|
39
|
+
...place.mount.childNodes
|
|
40
|
+
];
|
|
41
|
+
// Prevent the base class from mutating the React-managed attributes.
|
|
42
|
+
// Restore them below after invoking the base class constructor.
|
|
43
|
+
const reactAttrs = [
|
|
44
|
+
...place.mount.attributes
|
|
45
|
+
];
|
|
46
|
+
for (const attr of reactAttrs){
|
|
47
|
+
place.mount.removeAttributeNode(attr);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
// Call the superclass constructor with only a state and no plugins.
|
|
51
|
+
// We'll set everything else ourselves and apply props during layout.
|
|
52
|
+
super(place, {
|
|
53
|
+
state: _constants.EMPTY_STATE
|
|
54
|
+
});
|
|
55
|
+
this.domObserver.stop();
|
|
56
|
+
this.domObserver.observer = null;
|
|
57
|
+
this.domObserver.queue = [];
|
|
58
|
+
} finally{
|
|
59
|
+
place.mount.replaceChildren(...reactContent);
|
|
60
|
+
for (const attr of place.mount.attributes){
|
|
61
|
+
place.mount.removeAttributeNode(attr);
|
|
62
|
+
}
|
|
63
|
+
for (const attr of reactAttrs){
|
|
64
|
+
place.mount.setAttributeNode(attr);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
this.prevState = _constants.EMPTY_STATE;
|
|
68
|
+
this.nextProps = props;
|
|
69
|
+
this.state = props.state;
|
|
70
|
+
this.nodeViews = buildNodeViews(this);
|
|
71
|
+
// Destroy the document view description that the base class makes.
|
|
72
|
+
// A React document view will assign itself to this attribute later.
|
|
73
|
+
this.docView.destroy();
|
|
74
|
+
// @ts-expect-error this violates the typing but class does it, too.
|
|
75
|
+
this.docView = null;
|
|
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 || prevProps.nodeViews !== props.nodeViews) {
|
|
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 &&
|
|
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
|
|
91
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
124
|
-
|
|
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
|
|
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
|
|
241
|
-
|
|
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
|
-
|
|
245
|
-
|
|
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:
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
374
|
-
|
|
393
|
+
children.push({
|
|
394
|
+
type: "hack",
|
|
395
|
+
component: _SeparatorHackView.SeparatorHackView,
|
|
396
|
+
marks: [],
|
|
397
|
+
offset: lastChild?.offset ?? 0,
|
|
398
|
+
index: (lastChild?.index ?? 0) + 2,
|
|
375
399
|
key: "trailing-hack-img"
|
|
376
|
-
}
|
|
377
|
-
|
|
400
|
+
}, {
|
|
401
|
+
type: "hack",
|
|
402
|
+
component: _TrailingHackView.TrailingHackView,
|
|
403
|
+
marks: [],
|
|
404
|
+
offset: lastChild?.offset ?? 0,
|
|
405
|
+
index: (lastChild?.index ?? 0) + 1,
|
|
378
406
|
key: "trailing-hack-br"
|
|
379
|
-
})
|
|
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
|
});
|