@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
|
@@ -8,14 +8,10 @@ Object.defineProperty(exports, "CustomNodeView", {
|
|
|
8
8
|
return CustomNodeView;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const _prosemirrormodel = require("prosemirror-model");
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
13
13
|
const _reactdom = require("react-dom");
|
|
14
14
|
const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
|
|
15
|
-
const _EditorContext = require("../contexts/EditorContext.js");
|
|
16
|
-
const _useClientLayoutEffect = require("../hooks/useClientLayoutEffect.js");
|
|
17
|
-
const _useClientOnly = require("../hooks/useClientOnly.js");
|
|
18
|
-
const _useForceUpdate = require("../hooks/useForceUpdate.js");
|
|
19
15
|
const _useNodeViewDescriptor = require("../hooks/useNodeViewDescriptor.js");
|
|
20
16
|
const _ChildNodeViews = require("./ChildNodeViews.js");
|
|
21
17
|
function _getRequireWildcardCache(nodeInterop) {
|
|
@@ -60,145 +56,89 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
60
56
|
return newObj;
|
|
61
57
|
}
|
|
62
58
|
const CustomNodeView = /*#__PURE__*/ (0, _react.memo)(function CustomNodeView(param) {
|
|
63
|
-
let {
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const innerDecoRef = (0, _react.useRef)(innerDeco);
|
|
74
|
-
innerDecoRef.current = innerDeco;
|
|
75
|
-
const customNodeViewRootRef = (0, _react.useRef)(null);
|
|
76
|
-
const customNodeViewRef = (0, _react.useRef)(null);
|
|
77
|
-
const forceUpdate = (0, _useForceUpdate.useForceUpdate)();
|
|
78
|
-
const isOnClient = (0, _useClientOnly.useClientOnly)();
|
|
79
|
-
// In Strict/Concurrent mode, layout effects can be destroyed/re-run
|
|
80
|
-
// independently of renders. We need to ensure that if the
|
|
81
|
-
// destructor that destroys the node view is called, we then recreate
|
|
82
|
-
// the node view when the layout effect is re-run.
|
|
83
|
-
(0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
|
|
84
|
-
if (!customNodeViewRef.current) {
|
|
85
|
-
customNodeViewRef.current = customNodeView(nodeRef.current, // customNodeView will only be set if view is set, and we can only reach
|
|
86
|
-
// this line if customNodeView is set
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
88
|
-
view, getPosFunc, outerDecoRef.current, innerDecoRef.current);
|
|
89
|
-
if (customNodeViewRef.current.stopEvent) {
|
|
90
|
-
setStopEvent(customNodeViewRef.current.stopEvent.bind(customNodeViewRef.current));
|
|
91
|
-
}
|
|
92
|
-
if (customNodeViewRef.current.selectNode) {
|
|
93
|
-
setSelectNode(customNodeViewRef.current.selectNode.bind(customNodeViewRef.current), customNodeViewRef.current.deselectNode?.bind(customNodeViewRef.current) ?? (()=>{}));
|
|
94
|
-
}
|
|
95
|
-
if (customNodeViewRef.current.ignoreMutation) {
|
|
96
|
-
setIgnoreMutation(customNodeViewRef.current.ignoreMutation.bind(customNodeViewRef.current));
|
|
97
|
-
}
|
|
98
|
-
// If we've reconstructed the nodeview, then we need to
|
|
99
|
-
// recreate the portal into its contentDOM, which happens
|
|
100
|
-
// during the render. So we need to trigger a re-render!
|
|
101
|
-
forceUpdate();
|
|
102
|
-
}
|
|
103
|
-
if (!customNodeViewRootRef.current) return;
|
|
104
|
-
const { dom } = customNodeViewRef.current;
|
|
105
|
-
if (customNodeViewRootRef.current.firstChild === dom) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
nodeDomRef.current = customNodeViewRootRef.current;
|
|
109
|
-
customNodeViewRootRef.current.appendChild(dom);
|
|
110
|
-
// Layout effects can run multiple times — if this effect
|
|
111
|
-
// destroyed and recreated this node view, then we need to
|
|
112
|
-
// resync the selectNode state
|
|
113
|
-
if (view?.state.selection instanceof _prosemirrorstate.NodeSelection && view.state.selection.node === nodeRef.current) {
|
|
114
|
-
customNodeViewRef.current.selectNode?.();
|
|
115
|
-
}
|
|
116
|
-
const nodeView = customNodeViewRef.current;
|
|
117
|
-
return ()=>{
|
|
118
|
-
nodeView.destroy?.();
|
|
119
|
-
customNodeViewRef.current = null;
|
|
120
|
-
};
|
|
121
|
-
// setStopEvent, setSelectNodee, and setIgnoreMutation are all stable
|
|
122
|
-
// functions and don't need to be added to the dependencies. They also
|
|
123
|
-
// can't be, because they come from useNodeViewDescriptor, which
|
|
124
|
-
// _has_ to be called after this hook, so that the effects run
|
|
125
|
-
// in the correct order
|
|
126
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
127
|
-
}, [
|
|
128
|
-
customNodeView,
|
|
129
|
-
getPosFunc,
|
|
130
|
-
view
|
|
131
|
-
]);
|
|
132
|
-
(0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
|
|
133
|
-
if (!customNodeView || !customNodeViewRef.current) return;
|
|
134
|
-
const { destroy, update } = customNodeViewRef.current;
|
|
135
|
-
const updated = update?.call(customNodeViewRef.current, node, outerDeco, innerDeco) ?? true;
|
|
136
|
-
if (updated) return;
|
|
137
|
-
destroy?.call(customNodeViewRef.current);
|
|
138
|
-
if (!customNodeViewRootRef.current) return;
|
|
139
|
-
customNodeViewRef.current = customNodeView(nodeRef.current, // customNodeView will only be set if view is set, and we can only reach
|
|
140
|
-
// this line if customNodeView is set
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
142
|
-
view, getPosFunc, outerDecoRef.current, innerDecoRef.current);
|
|
143
|
-
const { dom } = customNodeViewRef.current;
|
|
144
|
-
nodeDomRef.current = customNodeViewRootRef.current;
|
|
145
|
-
customNodeViewRootRef.current.appendChild(dom);
|
|
146
|
-
}, [
|
|
147
|
-
customNodeView,
|
|
148
|
-
view,
|
|
149
|
-
innerDeco,
|
|
59
|
+
let { constructor, node, getPos, innerDeco, outerDeco } = param;
|
|
60
|
+
const ref = (0, _react.useRef)(null);
|
|
61
|
+
const innerRef = (0, _react.useRef)(null);
|
|
62
|
+
const [selected, setSelected] = (0, _react.useState)(false);
|
|
63
|
+
const nodeProps = (0, _react.useMemo)(()=>({
|
|
64
|
+
node,
|
|
65
|
+
getPos,
|
|
66
|
+
decorations: outerDeco,
|
|
67
|
+
innerDecorations: innerDeco
|
|
68
|
+
}), [
|
|
150
69
|
node,
|
|
151
|
-
outerDeco,
|
|
152
70
|
getPos,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const { childDescriptors, nodeViewDescRef, setStopEvent, setSelectNode, setIgnoreMutation } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(node, getPosFunc, domRef, nodeDomRef, innerDeco, outerDeco, undefined, contentDomRef);
|
|
156
|
-
const childContextValue = (0, _react.useMemo)(()=>({
|
|
157
|
-
parentRef: nodeViewDescRef,
|
|
158
|
-
siblingsRef: childDescriptors
|
|
159
|
-
}), [
|
|
160
|
-
childDescriptors,
|
|
161
|
-
nodeViewDescRef
|
|
71
|
+
outerDeco,
|
|
72
|
+
innerDeco
|
|
162
73
|
]);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (customNodeViewRef.current.stopEvent) {
|
|
175
|
-
setStopEvent(customNodeViewRef.current.stopEvent.bind(customNodeViewRef.current));
|
|
74
|
+
const createNodeView = function() {
|
|
75
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
76
|
+
args[_key] = arguments[_key];
|
|
77
|
+
}
|
|
78
|
+
const nodeView = constructor(...args);
|
|
79
|
+
if (!nodeView || !nodeView.dom) {
|
|
80
|
+
const spec = node.type.spec.toDOM?.(node);
|
|
81
|
+
if (!spec) {
|
|
82
|
+
throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
|
|
83
|
+
}
|
|
84
|
+
return _prosemirrormodel.DOMSerializer.renderSpec(document, spec, null);
|
|
176
85
|
}
|
|
177
|
-
|
|
178
|
-
|
|
86
|
+
return nodeView;
|
|
87
|
+
};
|
|
88
|
+
const { childContextValue, contentDOM } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(ref, function() {
|
|
89
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
90
|
+
args[_key] = arguments[_key];
|
|
179
91
|
}
|
|
180
|
-
|
|
181
|
-
|
|
92
|
+
setSelected(false);
|
|
93
|
+
const nodeView = createNodeView(...args);
|
|
94
|
+
const contentDOM = nodeView.contentDOM;
|
|
95
|
+
const nodeDOM = nodeView.dom;
|
|
96
|
+
const wrapperDOM = innerRef.current ?? ref.current;
|
|
97
|
+
wrapperDOM.appendChild(nodeDOM);
|
|
98
|
+
if (!contentDOM && nodeDOM instanceof HTMLElement && nodeDOM.tagName !== "BR") {
|
|
99
|
+
if (!nodeDOM.hasAttribute("contenteditable")) {
|
|
100
|
+
nodeDOM.contentEditable = "false";
|
|
101
|
+
}
|
|
182
102
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
103
|
+
return {
|
|
104
|
+
...nodeView,
|
|
105
|
+
destroy () {
|
|
106
|
+
if (nodeView.destroy) {
|
|
107
|
+
nodeView.destroy();
|
|
108
|
+
}
|
|
109
|
+
wrapperDOM.removeChild(nodeDOM);
|
|
110
|
+
},
|
|
111
|
+
selectNode: nodeView.selectNode?.bind(nodeView) ?? (()=>{
|
|
112
|
+
if (nodeDOM instanceof HTMLElement) {
|
|
113
|
+
nodeDOM.classList.add("ProseMirror-selectednode");
|
|
114
|
+
}
|
|
115
|
+
setSelected(true);
|
|
116
|
+
}),
|
|
117
|
+
deselectNode: nodeView.deselectNode?.bind(nodeView) ?? (()=>{
|
|
118
|
+
if (nodeDOM instanceof HTMLElement) {
|
|
119
|
+
nodeDOM.classList.remove("ProseMirror-selectednode");
|
|
120
|
+
}
|
|
121
|
+
setSelected(false);
|
|
122
|
+
}),
|
|
123
|
+
stopEvent: nodeView.stopEvent?.bind(nodeView),
|
|
124
|
+
ignoreMutation: nodeView.ignoreMutation?.bind(nodeView)
|
|
125
|
+
};
|
|
126
|
+
}, nodeProps);
|
|
127
|
+
const children = !node.isLeaf && contentDOM ? /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
128
|
+
value: childContextValue
|
|
129
|
+
}, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
191
130
|
getPos: getPos,
|
|
192
131
|
node: node,
|
|
193
132
|
innerDecorations: innerDeco
|
|
194
|
-
}), contentDOM)
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
133
|
+
})), contentDOM) : null;
|
|
134
|
+
const innerElement = /*#__PURE__*/ (0, _react.createElement)(node.isInline ? "span" : "div", {
|
|
135
|
+
ref: innerRef
|
|
136
|
+
}, children);
|
|
137
|
+
const props = {
|
|
138
|
+
...selected || node.type.spec.draggable ? {
|
|
139
|
+
draggable: true
|
|
140
|
+
} : null,
|
|
141
|
+
ref
|
|
142
|
+
};
|
|
143
|
+
return /*#__PURE__*/ (0, _react.cloneElement)(outerDeco.reduce(_ChildNodeViews.wrapInDeco, innerElement), props);
|
|
204
144
|
});
|
|
@@ -2,19 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
NodePosProvider: ()=>NodePosProvider,
|
|
13
|
-
useNodePos: ()=>useNodePos
|
|
5
|
+
Object.defineProperty(exports, "DefaultNodeView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return DefaultNodeView;
|
|
9
|
+
}
|
|
14
10
|
});
|
|
15
|
-
const _react = /*#__PURE__*/
|
|
16
|
-
const
|
|
17
|
-
const _useEditorStateJs = require("./useEditorState.js");
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _OutputSpec = require("./OutputSpec.js");
|
|
18
13
|
function _getRequireWildcardCache(nodeInterop) {
|
|
19
14
|
if (typeof WeakMap !== "function") return null;
|
|
20
15
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -23,7 +18,7 @@ function _getRequireWildcardCache(nodeInterop) {
|
|
|
23
18
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
24
19
|
})(nodeInterop);
|
|
25
20
|
}
|
|
26
|
-
function
|
|
21
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
27
22
|
if (!nodeInterop && obj && obj.__esModule) {
|
|
28
23
|
return obj;
|
|
29
24
|
}
|
|
@@ -36,7 +31,9 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
36
31
|
if (cache && cache.has(obj)) {
|
|
37
32
|
return cache.get(obj);
|
|
38
33
|
}
|
|
39
|
-
var newObj = {
|
|
34
|
+
var newObj = {
|
|
35
|
+
__proto__: null
|
|
36
|
+
};
|
|
40
37
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
41
38
|
for(var key in obj){
|
|
42
39
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -54,16 +51,17 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
54
51
|
}
|
|
55
52
|
return newObj;
|
|
56
53
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
const DefaultNodeView = /*#__PURE__*/ (0, _react.forwardRef)(function DefaultNodeView(param, ref) {
|
|
55
|
+
let { nodeProps: { node }, children, ...props } = param;
|
|
56
|
+
const spec = (0, _react.useMemo)(()=>node.type.spec.toDOM?.(node), [
|
|
57
|
+
node
|
|
58
|
+
]);
|
|
59
|
+
if (!spec) {
|
|
60
|
+
throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
|
|
61
|
+
}
|
|
62
|
+
return /*#__PURE__*/ _react.default.createElement(_OutputSpec.OutputSpec, {
|
|
63
|
+
...props,
|
|
64
|
+
outputSpec: spec,
|
|
65
|
+
ref: ref
|
|
65
66
|
}, children);
|
|
66
|
-
}
|
|
67
|
-
function useNodePos() {
|
|
68
|
-
return (0, _react.useContext)(NodePosContext);
|
|
69
|
-
}
|
|
67
|
+
});
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// this linting rule is only broken in this file
|
|
3
|
-
/* eslint-disable react/prop-types */ "use strict";
|
|
1
|
+
"use strict";
|
|
4
2
|
Object.defineProperty(exports, "__esModule", {
|
|
5
3
|
value: true
|
|
6
4
|
});
|
|
@@ -55,50 +53,44 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
55
53
|
}
|
|
56
54
|
return newObj;
|
|
57
55
|
}
|
|
58
|
-
const getPos = {
|
|
59
|
-
current () {
|
|
60
|
-
return -1;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
56
|
const DocNodeView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function DocNodeView(param, ref) {
|
|
64
|
-
let {
|
|
57
|
+
let { as, node, getPos, decorations, innerDecorations, setMount, ...elementProps } = param;
|
|
65
58
|
const innerRef = (0, _react.useRef)(null);
|
|
66
|
-
(0, _react.useImperativeHandle)(ref, ()=>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
(0, _react.useImperativeHandle)(ref, ()=>innerRef.current);
|
|
60
|
+
(0, _react.useImperativeHandle)(setMount, ()=>innerRef.current);
|
|
61
|
+
const nodeProps = (0, _react.useMemo)(()=>({
|
|
62
|
+
node,
|
|
63
|
+
getPos,
|
|
64
|
+
decorations,
|
|
65
|
+
innerDecorations
|
|
73
66
|
}), [
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
node,
|
|
68
|
+
getPos,
|
|
69
|
+
decorations,
|
|
70
|
+
innerDecorations
|
|
76
71
|
]);
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
innerDecorations: innerDeco
|
|
89
|
-
}))) : /*#__PURE__*/ (0, _react.createElement)("div", props, /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
72
|
+
const { childContextValue } = (0, _useNodeViewDescriptor.useNodeViewDescriptor)(innerRef, ()=>{
|
|
73
|
+
const dom = innerRef.current;
|
|
74
|
+
return {
|
|
75
|
+
dom,
|
|
76
|
+
contentDOM: dom,
|
|
77
|
+
update () {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}, nodeProps);
|
|
82
|
+
const children = /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
90
83
|
value: childContextValue
|
|
91
84
|
}, /*#__PURE__*/ _react.default.createElement(_ChildNodeViews.ChildNodeViews, {
|
|
92
85
|
getPos: getPos,
|
|
93
86
|
node: node,
|
|
94
|
-
innerDecorations:
|
|
95
|
-
}))
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return wrapped;
|
|
87
|
+
innerDecorations: innerDecorations
|
|
88
|
+
}));
|
|
89
|
+
const props = {
|
|
90
|
+
...elementProps,
|
|
91
|
+
suppressContentEditableWarning: true,
|
|
92
|
+
ref: innerRef
|
|
93
|
+
};
|
|
94
|
+
const element = as ? /*#__PURE__*/ (0, _react.cloneElement)(as, props, children) : /*#__PURE__*/ (0, _react.createElement)("div", props, children);
|
|
95
|
+
return nodeProps.decorations.reduce(_ChildNodeViews.wrapInDeco, element);
|
|
104
96
|
}));
|
|
@@ -83,7 +83,7 @@ const MarkView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forward
|
|
|
83
83
|
if (!domRef.current) return;
|
|
84
84
|
const firstChildDesc = childDescriptors.current[0];
|
|
85
85
|
if (!viewDescRef.current) {
|
|
86
|
-
viewDescRef.current = new _viewdesc.MarkViewDesc(parentRef.current, childDescriptors.current,
|
|
86
|
+
viewDescRef.current = new _viewdesc.MarkViewDesc(parentRef.current, childDescriptors.current, getPos, mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current, {
|
|
87
87
|
dom: domRef.current,
|
|
88
88
|
contentDOM: firstChildDesc?.dom.parentElement ?? domRef.current
|
|
89
89
|
});
|
|
@@ -93,7 +93,6 @@ const MarkView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forward
|
|
|
93
93
|
viewDescRef.current.children = childDescriptors.current;
|
|
94
94
|
viewDescRef.current.spec.contentDOM = viewDescRef.current.contentDOM = firstChildDesc?.dom.parentElement ?? domRef.current;
|
|
95
95
|
viewDescRef.current.mark = mark;
|
|
96
|
-
viewDescRef.current.getPos = ()=>getPos.current();
|
|
97
96
|
}
|
|
98
97
|
if (!siblingsRef.current.includes(viewDescRef.current)) {
|
|
99
98
|
siblingsRef.current.push(viewDescRef.current);
|
|
@@ -75,7 +75,7 @@ function NativeWidgetView(param) {
|
|
|
75
75
|
if (!rootDomRef.current) return;
|
|
76
76
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
77
|
const toDOM = widget.type.toDOM;
|
|
78
|
-
let dom = typeof toDOM === "function" ? toDOM(view,
|
|
78
|
+
let dom = typeof toDOM === "function" ? toDOM(view, getPos) : toDOM;
|
|
79
79
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
80
|
if (!widget.type.spec.raw) {
|
|
81
81
|
if (dom.nodeType != 1) {
|
|
@@ -92,11 +92,10 @@ function NativeWidgetView(param) {
|
|
|
92
92
|
(0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
|
|
93
93
|
if (!rootDomRef.current) return;
|
|
94
94
|
if (!viewDescRef.current) {
|
|
95
|
-
viewDescRef.current = new _viewdesc.WidgetViewDesc(parentRef.current,
|
|
95
|
+
viewDescRef.current = new _viewdesc.WidgetViewDesc(parentRef.current, getPos, widget, rootDomRef.current);
|
|
96
96
|
} else {
|
|
97
97
|
viewDescRef.current.parent = parentRef.current;
|
|
98
98
|
viewDescRef.current.widget = widget;
|
|
99
|
-
viewDescRef.current.getPos = ()=>getPos.current();
|
|
100
99
|
viewDescRef.current.dom = rootDomRef.current;
|
|
101
100
|
}
|
|
102
101
|
if (!siblingsRef.current.includes(viewDescRef.current)) {
|
|
@@ -9,8 +9,9 @@ Object.defineProperty(exports, "NodeView", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
-
const
|
|
12
|
+
const _NodeViewContext = require("../contexts/NodeViewContext.js");
|
|
13
13
|
const _CustomNodeView = require("./CustomNodeView.js");
|
|
14
|
+
const _DefaultNodeView = require("./DefaultNodeView.js");
|
|
14
15
|
const _ReactNodeView = require("./ReactNodeView.js");
|
|
15
16
|
function _getRequireWildcardCache(nodeInterop) {
|
|
16
17
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -53,24 +54,33 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
53
54
|
}
|
|
54
55
|
return newObj;
|
|
55
56
|
}
|
|
56
|
-
const NodeView = /*#__PURE__*/ (0, _react.memo)(function NodeView(
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
57
|
+
const NodeView = /*#__PURE__*/ (0, _react.memo)(function NodeView(props) {
|
|
58
|
+
const { components, constructors } = (0, _react.useContext)(_NodeViewContext.NodeViewContext);
|
|
59
|
+
const component = components[props.node.type.name] ?? _DefaultNodeView.DefaultNodeView;
|
|
60
|
+
const constructor = constructors[props.node.type.name];
|
|
61
|
+
// Construct a wrapper component so that the node view remounts when either
|
|
62
|
+
// its component or constructor changes. A React node view would remount if
|
|
63
|
+
// its underlying component changed without this wrapper, but a custom node
|
|
64
|
+
// view otherwise uses the same React components for all custom node views.
|
|
65
|
+
const Component = (0, _react.useMemo)(()=>{
|
|
66
|
+
if (constructor) {
|
|
67
|
+
return function NodeView(props) {
|
|
68
|
+
return /*#__PURE__*/ _react.default.createElement(_CustomNodeView.CustomNodeView, {
|
|
69
|
+
constructor: constructor,
|
|
70
|
+
...props
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
} else {
|
|
74
|
+
return function NodeView(props) {
|
|
75
|
+
return /*#__PURE__*/ _react.default.createElement(_ReactNodeView.ReactNodeView, {
|
|
76
|
+
component: component,
|
|
77
|
+
...props
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}, [
|
|
82
|
+
constructor,
|
|
83
|
+
component
|
|
84
|
+
]);
|
|
85
|
+
return /*#__PURE__*/ _react.default.createElement(Component, props);
|
|
76
86
|
});
|
|
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "ProseMirror", {
|
|
|
8
8
|
return ProseMirror;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _prosemirrorview = require("prosemirror-view");
|
|
12
11
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
13
12
|
const _EditorContext = require("../contexts/EditorContext.js");
|
|
14
13
|
const _EditorStateContext = require("../contexts/EditorStateContext.js");
|
|
@@ -59,7 +58,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
59
58
|
}
|
|
60
59
|
return newObj;
|
|
61
60
|
}
|
|
62
|
-
|
|
61
|
+
function getPos() {
|
|
62
|
+
return -1;
|
|
63
|
+
}
|
|
63
64
|
function ProseMirrorInner(param) {
|
|
64
65
|
let { className, children, nodeViews, customNodeViews, ...props } = param;
|
|
65
66
|
const [mount, setMount] = (0, _react.useState)(null);
|
|
@@ -67,26 +68,33 @@ function ProseMirrorInner(param) {
|
|
|
67
68
|
...props,
|
|
68
69
|
nodeViews: customNodeViews
|
|
69
70
|
});
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
const nodeViewConstructors = editor.view.nodeViews;
|
|
72
|
+
const nodeViewContextValue = (0, _react.useMemo)(()=>{
|
|
73
|
+
return {
|
|
74
|
+
components: {
|
|
75
|
+
...nodeViews
|
|
76
|
+
},
|
|
77
|
+
constructors: nodeViewConstructors
|
|
78
|
+
};
|
|
79
|
+
}, [
|
|
80
|
+
nodeViewConstructors,
|
|
75
81
|
nodeViews
|
|
76
82
|
]);
|
|
83
|
+
const node = state.doc;
|
|
84
|
+
const decorations = (0, _computeDocDeco.computeDocDeco)(editor.view);
|
|
85
|
+
const innerDecorations = (0, _viewDecorations.viewDecorations)(editor.view, editor.cursorWrapper);
|
|
77
86
|
const docNodeViewContextValue = (0, _react.useMemo)(()=>({
|
|
78
|
-
className
|
|
79
|
-
setMount
|
|
80
|
-
node
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
className,
|
|
88
|
+
setMount,
|
|
89
|
+
node,
|
|
90
|
+
getPos,
|
|
91
|
+
decorations,
|
|
92
|
+
innerDecorations
|
|
84
93
|
}), [
|
|
85
94
|
className,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
outerDecos
|
|
95
|
+
node,
|
|
96
|
+
decorations,
|
|
97
|
+
innerDecorations
|
|
90
98
|
]);
|
|
91
99
|
return /*#__PURE__*/ _react.default.createElement(_EditorContext.EditorContext.Provider, {
|
|
92
100
|
value: editor
|
|
@@ -13,11 +13,10 @@ _export(exports, {
|
|
|
13
13
|
return DocNodeViewContext;
|
|
14
14
|
},
|
|
15
15
|
ProseMirrorDoc: function() {
|
|
16
|
-
return
|
|
16
|
+
return ProseMirrorDoc;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
20
|
-
const _ChildDescriptorsContext = require("../contexts/ChildDescriptorsContext.js");
|
|
21
20
|
const _DocNodeView = require("./DocNodeView.js");
|
|
22
21
|
function _getRequireWildcardCache(nodeInterop) {
|
|
23
22
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -61,32 +60,13 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
61
60
|
return newObj;
|
|
62
61
|
}
|
|
63
62
|
const DocNodeViewContext = /*#__PURE__*/ (0, _react.createContext)(null);
|
|
64
|
-
function ProseMirrorDoc(param, ref) {
|
|
63
|
+
const ProseMirrorDoc = /*#__PURE__*/ (0, _react.forwardRef)(function ProseMirrorDoc(param, ref) {
|
|
65
64
|
let { as, ...props } = param;
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const viewDescRef = (0, _react.useRef)(undefined);
|
|
70
|
-
(0, _react.useImperativeHandle)(ref, ()=>{
|
|
71
|
-
return innerRef.current;
|
|
72
|
-
}, []);
|
|
73
|
-
const childContextValue = (0, _react.useMemo)(()=>({
|
|
74
|
-
parentRef: viewDescRef,
|
|
75
|
-
siblingsRef: childDescriptors
|
|
76
|
-
}), [
|
|
77
|
-
childDescriptors,
|
|
78
|
-
viewDescRef
|
|
79
|
-
]);
|
|
80
|
-
return /*#__PURE__*/ _react.default.createElement(_ChildDescriptorsContext.ChildDescriptorsContext.Provider, {
|
|
81
|
-
value: childContextValue
|
|
82
|
-
}, /*#__PURE__*/ _react.default.createElement(_DocNodeView.DocNodeView, {
|
|
83
|
-
ref: (el)=>{
|
|
84
|
-
innerRef.current = el;
|
|
85
|
-
setMount(el);
|
|
86
|
-
},
|
|
65
|
+
const docProps = (0, _react.useContext)(DocNodeViewContext);
|
|
66
|
+
return /*#__PURE__*/ _react.default.createElement(_DocNodeView.DocNodeView, {
|
|
67
|
+
ref: ref,
|
|
87
68
|
...props,
|
|
88
69
|
...docProps,
|
|
89
70
|
as: as
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
const ForwardedProseMirrorDoc = /*#__PURE__*/ (0, _react.forwardRef)(ProseMirrorDoc);
|
|
71
|
+
});
|
|
72
|
+
});
|