@handlewithcare/react-prosemirror 3.1.0-tiptap.42 → 3.1.0-tiptap.44
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 +26 -0
- package/dist/cjs/ReactEditorView.js +74 -70
- package/dist/cjs/StaticEditorView.js +21 -18
- package/dist/cjs/browser.js +3 -1
- package/dist/cjs/commands/reorderSiblings.js +13 -9
- package/dist/cjs/components/ChildNodeViews.js +74 -69
- package/dist/cjs/components/CursorWrapper.js +20 -34
- package/dist/cjs/components/LayoutGroup.js +16 -12
- package/dist/cjs/components/NativeWidgetView.js +19 -15
- package/dist/cjs/components/OutputSpec.js +13 -9
- package/dist/cjs/components/ProseMirror.js +27 -37
- package/dist/cjs/components/ProseMirrorDoc.js +18 -25
- package/dist/cjs/components/SeparatorHackView.js +20 -17
- package/dist/cjs/components/TextNodeView.js +20 -22
- package/dist/cjs/components/TrailingHackView.js +17 -13
- package/dist/cjs/components/WidgetView.js +18 -14
- package/dist/cjs/components/marks/DefaultMarkView.js +15 -27
- package/dist/cjs/components/marks/MarkView.js +23 -32
- package/dist/cjs/components/marks/MarkViewConstructorView.js +22 -38
- package/dist/cjs/components/marks/ReactMarkView.js +16 -27
- package/dist/cjs/components/nodes/DefaultNodeView.js +15 -27
- package/dist/cjs/components/nodes/DocNodeView.js +16 -12
- package/dist/cjs/components/nodes/NodeView.js +26 -33
- package/dist/cjs/components/nodes/NodeViewConstructorView.js +29 -45
- package/dist/cjs/components/nodes/ReactNodeView.js +27 -39
- package/dist/cjs/constants.js +10 -6
- package/dist/cjs/contexts/ChildDescriptionsContext.js +3 -1
- package/dist/cjs/contexts/EditorContext.js +3 -1
- package/dist/cjs/contexts/EditorStateContext.js +3 -1
- package/dist/cjs/contexts/IgnoreMutationContext.js +3 -1
- package/dist/cjs/contexts/LayoutGroupContext.js +3 -1
- package/dist/cjs/contexts/NodeViewContext.js +3 -1
- package/dist/cjs/contexts/SelectNodeContext.js +3 -1
- package/dist/cjs/contexts/StopEventContext.js +3 -1
- package/dist/cjs/decorations/ReactWidgetType.js +19 -13
- package/dist/cjs/decorations/computeDocDeco.js +5 -3
- package/dist/cjs/decorations/iterDeco.js +19 -17
- package/dist/cjs/decorations/viewDecorations.js +15 -12
- package/dist/cjs/dom.js +34 -13
- package/dist/cjs/findDOMNode.js +9 -5
- package/dist/cjs/hooks/useClientLayoutEffect.js +3 -1
- package/dist/cjs/hooks/useComponentEventListeners.js +7 -6
- package/dist/cjs/hooks/useEditor.js +29 -32
- package/dist/cjs/hooks/useEditorEffect.js +9 -7
- package/dist/cjs/hooks/useEditorEventCallback.js +9 -7
- package/dist/cjs/hooks/useEditorEventListener.js +8 -6
- package/dist/cjs/hooks/useEditorState.js +5 -3
- package/dist/cjs/hooks/useEffectEvent.js +3 -1
- package/dist/cjs/hooks/useForceUpdate.js +3 -1
- package/dist/cjs/hooks/useIgnoreMutation.js +9 -7
- package/dist/cjs/hooks/useIsEditorStatic.js +5 -5
- package/dist/cjs/hooks/useIsNodeSelected.js +5 -3
- package/dist/cjs/hooks/useLayoutGroupEffect.js +7 -5
- package/dist/cjs/hooks/useMarkViewDescription.js +31 -25
- package/dist/cjs/hooks/useNodePos.js +7 -5
- package/dist/cjs/hooks/useNodeViewDescription.js +32 -28
- package/dist/cjs/hooks/useReactKeys.js +7 -5
- package/dist/cjs/hooks/useSelectNode.js +10 -8
- package/dist/cjs/hooks/useStopEvent.js +9 -7
- package/dist/cjs/index.js +66 -34
- package/dist/cjs/plugins/beforeInputPlugin.js +51 -24
- package/dist/cjs/plugins/componentEventListeners.js +8 -6
- package/dist/cjs/plugins/componentEventListenersPlugin.js +8 -6
- package/dist/cjs/plugins/reactKeys.js +15 -10
- package/dist/cjs/props.js +23 -19
- package/dist/cjs/refs.js +3 -1
- package/dist/cjs/testing/editorViewTestHelpers.js +40 -47
- package/dist/cjs/testing/setupProseMirrorView.js +7 -4
- package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +10 -6
- package/dist/cjs/tiptap/TiptapEditor.js +15 -14
- package/dist/cjs/tiptap/TiptapEditorContent.js +18 -28
- package/dist/cjs/tiptap/TiptapEditorView.js +23 -34
- package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +3 -1
- package/dist/cjs/tiptap/extensions/ReactProseMirror.js +8 -6
- package/dist/cjs/tiptap/extensions/ReactProseMirrorCommands.js +5 -3
- package/dist/cjs/tiptap/extensions/commands/updateAttributes.js +4 -2
- package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +5 -3
- package/dist/cjs/tiptap/hooks/useTiptapEditor.js +12 -14
- package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +12 -10
- package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +6 -4
- package/dist/cjs/tiptap/index.js +36 -18
- package/dist/cjs/tiptap/tiptapNodeView.js +48 -62
- package/dist/cjs/viewdesc.js +119 -89
- package/dist/esm/ReactEditorView.js +68 -66
- package/dist/esm/StaticEditorView.js +18 -17
- package/dist/esm/commands/reorderSiblings.js +5 -5
- package/dist/esm/components/ChildNodeViews.js +36 -37
- package/dist/esm/components/CursorWrapper.js +10 -28
- package/dist/esm/components/LayoutGroup.js +1 -1
- package/dist/esm/components/NativeWidgetView.js +2 -2
- package/dist/esm/components/OutputSpec.js +1 -1
- package/dist/esm/components/ProseMirror.js +4 -18
- package/dist/esm/components/ProseMirrorDoc.js +6 -19
- package/dist/esm/components/SeparatorHackView.js +3 -4
- package/dist/esm/components/TextNodeView.js +6 -10
- package/dist/esm/components/TrailingHackView.js +2 -2
- package/dist/esm/components/WidgetView.js +3 -3
- package/dist/esm/components/marks/DefaultMarkView.js +6 -22
- package/dist/esm/components/marks/MarkView.js +11 -24
- package/dist/esm/components/marks/MarkViewConstructorView.js +7 -27
- package/dist/esm/components/marks/ReactMarkView.js +3 -18
- package/dist/esm/components/nodes/DefaultNodeView.js +6 -22
- package/dist/esm/components/nodes/DocNodeView.js +2 -2
- package/dist/esm/components/nodes/NodeView.js +11 -24
- package/dist/esm/components/nodes/NodeViewConstructorView.js +11 -31
- package/dist/esm/components/nodes/ReactNodeView.js +6 -22
- package/dist/esm/decorations/ReactWidgetType.js +10 -8
- package/dist/esm/decorations/iterDeco.js +13 -13
- package/dist/esm/decorations/viewDecorations.js +7 -6
- package/dist/esm/dom.js +1 -2
- package/dist/esm/findDOMNode.js +1 -1
- package/dist/esm/hooks/useComponentEventListeners.js +2 -3
- package/dist/esm/hooks/useEditor.js +6 -11
- package/dist/esm/hooks/useEditorEffect.js +1 -1
- package/dist/esm/hooks/useEditorEventCallback.js +1 -1
- package/dist/esm/hooks/useEditorEventListener.js +1 -1
- package/dist/esm/hooks/useIsEditorStatic.js +1 -3
- package/dist/esm/hooks/useMarkViewDescription.js +14 -10
- package/dist/esm/hooks/useNodeViewDescription.js +10 -8
- package/dist/esm/hooks/useReactKeys.js +1 -1
- package/dist/esm/plugins/beforeInputPlugin.js +44 -19
- package/dist/esm/plugins/reactKeys.js +3 -4
- package/dist/esm/props.js +15 -15
- package/dist/esm/testing/editorViewTestHelpers.js +20 -31
- package/dist/esm/testing/setupProseMirrorView.js +1 -2
- package/dist/esm/tiptap/ReactProseMirrorNodeView.js +7 -5
- package/dist/esm/tiptap/TiptapEditor.js +9 -10
- package/dist/esm/tiptap/TiptapEditorContent.js +4 -18
- package/dist/esm/tiptap/TiptapEditorView.js +8 -23
- package/dist/esm/tiptap/extensions/ReactProseMirror.js +1 -1
- package/dist/esm/tiptap/extensions/commands/updateAttributes.js +1 -1
- package/dist/esm/tiptap/hooks/useTiptapEditor.js +4 -8
- package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +4 -4
- package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +1 -1
- package/dist/esm/tiptap/tiptapNodeView.js +20 -38
- package/dist/esm/viewdesc.js +74 -66
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/contexts/EditorContext.d.ts +1 -2
- package/dist/types/hooks/useEditor.d.ts +1 -1
- package/dist/types/props.d.ts +8 -8
- package/dist/types/testing/editorViewTestHelpers.d.ts +1 -0
- package/package.json +1 -2
|
@@ -26,8 +26,10 @@ function shallowEqual(objA, objB) {
|
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
export class TextNodeView extends Component {
|
|
29
|
+
viewDescRef = null;
|
|
30
|
+
renderRef = null;
|
|
29
31
|
updateEffect() {
|
|
30
|
-
const { view
|
|
32
|
+
const { view, decorations, siblingsRef, parentRef, getPos, node } = this.props;
|
|
31
33
|
// There simply is no other way to ref a text node
|
|
32
34
|
// eslint-disable-next-line react/no-find-dom-node
|
|
33
35
|
const dom = findDOMNode(this);
|
|
@@ -36,13 +38,12 @@ export class TextNodeView extends Component {
|
|
|
36
38
|
// Otherwise we just rely on re-rendering the renderRef
|
|
37
39
|
if (!dom) {
|
|
38
40
|
if (!view.composing) return;
|
|
39
|
-
var _text, _text1;
|
|
40
41
|
this.viewDescRef = new CompositionViewDesc(parentRef.current, getPos, // These are just placeholders/dummies. We can't
|
|
41
42
|
// actually find the correct DOM nodes from here,
|
|
42
43
|
// so we let our parent do it.
|
|
43
44
|
// Passing a valid element here just so that the
|
|
44
45
|
// ViewDesc constructor doesn't blow up.
|
|
45
|
-
document.createElement("div"), document.createTextNode(
|
|
46
|
+
document.createElement("div"), document.createTextNode(node.text ?? ""), node.text ?? "");
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
49
|
let textNode = dom;
|
|
@@ -76,7 +77,7 @@ export class TextNodeView extends Component {
|
|
|
76
77
|
this.updateEffect();
|
|
77
78
|
}
|
|
78
79
|
componentWillUnmount() {
|
|
79
|
-
const { siblingsRef
|
|
80
|
+
const { siblingsRef } = this.props;
|
|
80
81
|
if (!this.viewDescRef) return;
|
|
81
82
|
if (siblingsRef.current.includes(this.viewDescRef)) {
|
|
82
83
|
const index = siblingsRef.current.indexOf(this.viewDescRef);
|
|
@@ -84,7 +85,7 @@ export class TextNodeView extends Component {
|
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
render() {
|
|
87
|
-
const { view
|
|
88
|
+
const { view, getPos, node, decorations } = this.props;
|
|
88
89
|
// During a composition, it's crucial that we don't try to
|
|
89
90
|
// update the DOM that the user is working in. If there's
|
|
90
91
|
// an active composition and the selection is in this node,
|
|
@@ -96,9 +97,4 @@ export class TextNodeView extends Component {
|
|
|
96
97
|
this.renderRef = decorations.reduce(wrapInDeco, node.text);
|
|
97
98
|
return this.renderRef;
|
|
98
99
|
}
|
|
99
|
-
constructor(...args){
|
|
100
|
-
super(...args);
|
|
101
|
-
this.viewDescRef = null;
|
|
102
|
-
this.renderRef = null;
|
|
103
|
-
}
|
|
104
100
|
}
|
|
@@ -3,8 +3,8 @@ import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.j
|
|
|
3
3
|
import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
|
|
4
4
|
import { TrailingHackViewDesc, sortViewDescs } from "../viewdesc.js";
|
|
5
5
|
export function TrailingHackView(param) {
|
|
6
|
-
let { getPos
|
|
7
|
-
const { siblingsRef
|
|
6
|
+
let { getPos } = param;
|
|
7
|
+
const { siblingsRef, parentRef } = useContext(ChildDescriptionsContext);
|
|
8
8
|
const viewDescRef = useRef(null);
|
|
9
9
|
const ref = useRef(null);
|
|
10
10
|
useClientLayoutEffect(()=>{
|
|
@@ -3,8 +3,8 @@ import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.j
|
|
|
3
3
|
import { useClientLayoutEffect } from "../hooks/useClientLayoutEffect.js";
|
|
4
4
|
import { WidgetViewDesc, sortViewDescs } from "../viewdesc.js";
|
|
5
5
|
export function WidgetView(param) {
|
|
6
|
-
let { widget
|
|
7
|
-
const { siblingsRef
|
|
6
|
+
let { widget, getPos } = param;
|
|
7
|
+
const { siblingsRef, parentRef } = useContext(ChildDescriptionsContext);
|
|
8
8
|
const viewDescRef = useRef(null);
|
|
9
9
|
const domRef = useRef(null);
|
|
10
10
|
useClientLayoutEffect(()=>{
|
|
@@ -33,7 +33,7 @@ export function WidgetView(param) {
|
|
|
33
33
|
}
|
|
34
34
|
siblingsRef.current.sort(sortViewDescs);
|
|
35
35
|
});
|
|
36
|
-
const { Component
|
|
36
|
+
const { Component } = widget.type;
|
|
37
37
|
return Component && /*#__PURE__*/ React.createElement(Component, {
|
|
38
38
|
ref: domRef,
|
|
39
39
|
widget: widget,
|
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function(target) {
|
|
3
|
-
for(var i = 1; i < arguments.length; i++){
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
for(var key in source){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
7
|
-
target[key] = source[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
};
|
|
13
|
-
return _extends.apply(this, arguments);
|
|
14
|
-
}
|
|
15
1
|
import React, { forwardRef, useMemo } from "react";
|
|
16
2
|
import { OutputSpec } from "../OutputSpec.js";
|
|
17
3
|
export const DefaultMarkView = /*#__PURE__*/ forwardRef(function DefaultMarkView(param, ref) {
|
|
18
|
-
let { markProps: { mark
|
|
19
|
-
const spec = useMemo(()=>
|
|
20
|
-
var _spec, ref;
|
|
21
|
-
return (ref = (_spec = mark.type.spec).toDOM) === null || ref === void 0 ? void 0 : ref.call(_spec, mark, inline);
|
|
22
|
-
}, [
|
|
4
|
+
let { markProps: { mark, inline, contentDOMRef }, children, ...props } = param;
|
|
5
|
+
const spec = useMemo(()=>mark.type.spec.toDOM?.(mark, inline), [
|
|
23
6
|
mark,
|
|
24
7
|
inline
|
|
25
8
|
]);
|
|
26
9
|
if (!spec) {
|
|
27
|
-
throw new Error(
|
|
10
|
+
throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
|
|
28
11
|
}
|
|
29
|
-
return /*#__PURE__*/ React.createElement(OutputSpec,
|
|
12
|
+
return /*#__PURE__*/ React.createElement(OutputSpec, {
|
|
13
|
+
...props,
|
|
30
14
|
outputSpec: spec,
|
|
31
15
|
contentDOMRef: contentDOMRef,
|
|
32
16
|
ref: ref,
|
|
33
17
|
isMark: true
|
|
34
|
-
}
|
|
18
|
+
}, children);
|
|
35
19
|
});
|
|
@@ -1,26 +1,11 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function(target) {
|
|
3
|
-
for(var i = 1; i < arguments.length; i++){
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
for(var key in source){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
7
|
-
target[key] = source[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
};
|
|
13
|
-
return _extends.apply(this, arguments);
|
|
14
|
-
}
|
|
15
1
|
import React, { memo, useContext, useMemo } from "react";
|
|
16
2
|
import { NodeViewContext } from "../../contexts/NodeViewContext.js";
|
|
17
3
|
import { DefaultMarkView } from "./DefaultMarkView.js";
|
|
18
4
|
import { MarkViewConstructorView } from "./MarkViewConstructorView.js";
|
|
19
5
|
import { ReactMarkView } from "./ReactMarkView.js";
|
|
20
6
|
export const MarkView = /*#__PURE__*/ memo(function MarkView(props) {
|
|
21
|
-
const { components
|
|
22
|
-
|
|
23
|
-
const component = (_name = components[props.mark.type.name]) !== null && _name !== void 0 ? _name : DefaultMarkView;
|
|
7
|
+
const { components, constructors } = useContext(NodeViewContext);
|
|
8
|
+
const component = components[props.mark.type.name] ?? DefaultMarkView;
|
|
24
9
|
const constructor = constructors[props.mark.type.name];
|
|
25
10
|
// Construct a wrapper component so that the mark view remounts when either
|
|
26
11
|
// its component or constructor changes. A React mark view would remount
|
|
@@ -29,19 +14,21 @@ export const MarkView = /*#__PURE__*/ memo(function MarkView(props) {
|
|
|
29
14
|
const Component = useMemo(()=>{
|
|
30
15
|
if (constructor) {
|
|
31
16
|
return function MarkView(props) {
|
|
32
|
-
return /*#__PURE__*/ React.createElement(MarkViewConstructorView,
|
|
33
|
-
constructor: constructor
|
|
34
|
-
|
|
17
|
+
return /*#__PURE__*/ React.createElement(MarkViewConstructorView, {
|
|
18
|
+
constructor: constructor,
|
|
19
|
+
...props
|
|
20
|
+
});
|
|
35
21
|
};
|
|
36
22
|
}
|
|
37
23
|
return function NodeView(props) {
|
|
38
|
-
return /*#__PURE__*/ React.createElement(ReactMarkView,
|
|
39
|
-
component: component
|
|
40
|
-
|
|
24
|
+
return /*#__PURE__*/ React.createElement(ReactMarkView, {
|
|
25
|
+
component: component,
|
|
26
|
+
...props
|
|
27
|
+
});
|
|
41
28
|
};
|
|
42
29
|
}, [
|
|
43
30
|
component,
|
|
44
31
|
constructor
|
|
45
32
|
]);
|
|
46
|
-
return /*#__PURE__*/ React.createElement(Component,
|
|
33
|
+
return /*#__PURE__*/ React.createElement(Component, props);
|
|
47
34
|
});
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function(target) {
|
|
3
|
-
for(var i = 1; i < arguments.length; i++){
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
for(var key in source){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
7
|
-
target[key] = source[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
};
|
|
13
|
-
return _extends.apply(this, arguments);
|
|
14
|
-
}
|
|
15
1
|
import { DOMSerializer } from "prosemirror-model";
|
|
16
2
|
import React, { memo, useMemo, useRef } from "react";
|
|
17
3
|
import { createPortal } from "react-dom";
|
|
@@ -19,7 +5,7 @@ import { ChildDescriptionsContext } from "../../contexts/ChildDescriptionsContex
|
|
|
19
5
|
import { useForceUpdate } from "../../hooks/useForceUpdate.js";
|
|
20
6
|
import { useMarkViewDescription } from "../../hooks/useMarkViewDescription.js";
|
|
21
7
|
export const MarkViewConstructorView = /*#__PURE__*/ memo(function MarkViewConstructorView(param) {
|
|
22
|
-
let { constructor
|
|
8
|
+
let { constructor, mark, inline, getPos, children } = param;
|
|
23
9
|
const ref = useRef(null);
|
|
24
10
|
const innerRef = useRef(null);
|
|
25
11
|
const forceUpdate = useForceUpdate();
|
|
@@ -41,26 +27,21 @@ export const MarkViewConstructorView = /*#__PURE__*/ memo(function MarkViewConst
|
|
|
41
27
|
}
|
|
42
28
|
const markView = constructor(...args);
|
|
43
29
|
if (!markView || !markView.dom) {
|
|
44
|
-
|
|
45
|
-
const spec = (ref = (_spec = mark.type.spec).toDOM) === null || ref === void 0 ? void 0 : ref.call(_spec, mark, inline);
|
|
30
|
+
const spec = mark.type.spec.toDOM?.(mark, inline);
|
|
46
31
|
if (!spec) {
|
|
47
|
-
throw new Error(
|
|
32
|
+
throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
|
|
48
33
|
}
|
|
49
34
|
return DOMSerializer.renderSpec(document, spec, null);
|
|
50
35
|
}
|
|
51
36
|
return markView;
|
|
52
37
|
};
|
|
53
|
-
|
|
54
|
-
const { childContextValue , contentDOM } = useMarkViewDescription(()=>ref.current, (markView)=>{
|
|
55
|
-
return (ref1 = markView === null || markView === void 0 ? void 0 : markView.contentDOM) !== null && ref1 !== void 0 ? ref1 : null;
|
|
56
|
-
}, function() {
|
|
38
|
+
const { childContextValue, contentDOM } = useMarkViewDescription(()=>ref.current, (markView)=>markView?.contentDOM ?? null, function() {
|
|
57
39
|
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
58
40
|
args[_key] = arguments[_key];
|
|
59
41
|
}
|
|
60
42
|
const markView = createMarkView(...args);
|
|
61
43
|
const dom = markView.dom;
|
|
62
|
-
|
|
63
|
-
const wrapperDOM = (_current = innerRef.current) !== null && _current !== void 0 ? _current : ref.current;
|
|
44
|
+
const wrapperDOM = innerRef.current ?? ref.current;
|
|
64
45
|
wrapperDOM.appendChild(dom);
|
|
65
46
|
// Force a re-render so that we properly create
|
|
66
47
|
// a portal into the contentDOM/dom
|
|
@@ -68,8 +49,7 @@ export const MarkViewConstructorView = /*#__PURE__*/ memo(function MarkViewConst
|
|
|
68
49
|
return {
|
|
69
50
|
...markView,
|
|
70
51
|
destroy () {
|
|
71
|
-
|
|
72
|
-
(ref = markView.destroy) === null || ref === void 0 ? void 0 : ref.call(markView);
|
|
52
|
+
markView.destroy?.();
|
|
73
53
|
wrapperDOM.removeChild(dom);
|
|
74
54
|
},
|
|
75
55
|
ignoreMutation: markView.ignoreMutation
|
|
@@ -79,7 +59,7 @@ export const MarkViewConstructorView = /*#__PURE__*/ memo(function MarkViewConst
|
|
|
79
59
|
const props = {
|
|
80
60
|
ref: innerRef
|
|
81
61
|
};
|
|
82
|
-
return /*#__PURE__*/ React.createElement(Component,
|
|
62
|
+
return /*#__PURE__*/ React.createElement(Component, props, contentDOM ? /*#__PURE__*/ createPortal(/*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
|
|
83
63
|
value: childContextValue
|
|
84
64
|
}, children), contentDOM) : null);
|
|
85
65
|
});
|
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function(target) {
|
|
3
|
-
for(var i = 1; i < arguments.length; i++){
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
for(var key in source){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
7
|
-
target[key] = source[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
};
|
|
13
|
-
return _extends.apply(this, arguments);
|
|
14
|
-
}
|
|
15
1
|
import React, { memo, useCallback, useMemo, useRef } from "react";
|
|
16
2
|
import { ChildDescriptionsContext } from "../../contexts/ChildDescriptionsContext.js";
|
|
17
3
|
import { IgnoreMutationContext } from "../../contexts/IgnoreMutationContext.js";
|
|
18
4
|
import { useMarkViewDescription } from "../../hooks/useMarkViewDescription.js";
|
|
19
5
|
export const ReactMarkView = /*#__PURE__*/ memo(function ReactMarkView(param) {
|
|
20
|
-
let { component: Component
|
|
6
|
+
let { component: Component, mark, inline, getPos, children } = param;
|
|
21
7
|
const ref = useRef(null);
|
|
22
8
|
const contentDOMRef = useRef(null);
|
|
23
9
|
const ignoreMutationRef = useRef(null);
|
|
@@ -39,8 +25,7 @@ export const ReactMarkView = /*#__PURE__*/ memo(function ReactMarkView(param) {
|
|
|
39
25
|
inline,
|
|
40
26
|
mark
|
|
41
27
|
]);
|
|
42
|
-
|
|
43
|
-
const { childContextValue , refUpdated } = useMarkViewDescription(()=>ref.current, ()=>(_current = contentDOMRef.current) !== null && _current !== void 0 ? _current : ref.current, ()=>({
|
|
28
|
+
const { childContextValue, refUpdated } = useMarkViewDescription(()=>ref.current, ()=>contentDOMRef.current ?? ref.current, ()=>({
|
|
44
29
|
dom: ref.current,
|
|
45
30
|
ignoreMutation (mutation) {
|
|
46
31
|
const ignoreMutation = ignoreMutationRef.current;
|
|
@@ -77,5 +62,5 @@ export const ReactMarkView = /*#__PURE__*/ memo(function ReactMarkView(param) {
|
|
|
77
62
|
value: setIgnoreMutation
|
|
78
63
|
}, /*#__PURE__*/ React.createElement(ChildDescriptionsContext.Provider, {
|
|
79
64
|
value: childContextValue
|
|
80
|
-
}, /*#__PURE__*/ React.createElement(Component,
|
|
65
|
+
}, /*#__PURE__*/ React.createElement(Component, props, children)));
|
|
81
66
|
});
|
|
@@ -1,33 +1,17 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function(target) {
|
|
3
|
-
for(var i = 1; i < arguments.length; i++){
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
for(var key in source){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
7
|
-
target[key] = source[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
};
|
|
13
|
-
return _extends.apply(this, arguments);
|
|
14
|
-
}
|
|
15
1
|
import React, { forwardRef, useMemo } from "react";
|
|
16
2
|
import { OutputSpec } from "../OutputSpec.js";
|
|
17
3
|
export const DefaultNodeView = /*#__PURE__*/ forwardRef(function DefaultNodeView(param, ref) {
|
|
18
|
-
let { nodeProps: { node
|
|
19
|
-
const spec = useMemo(()=>
|
|
20
|
-
var _spec, ref;
|
|
21
|
-
return (ref = (_spec = node.type.spec).toDOM) === null || ref === void 0 ? void 0 : ref.call(_spec, node);
|
|
22
|
-
}, [
|
|
4
|
+
let { nodeProps: { node, contentDOMRef }, children, ...props } = param;
|
|
5
|
+
const spec = useMemo(()=>node.type.spec.toDOM?.(node), [
|
|
23
6
|
node
|
|
24
7
|
]);
|
|
25
8
|
if (!spec) {
|
|
26
|
-
throw new Error(
|
|
9
|
+
throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
|
|
27
10
|
}
|
|
28
|
-
return /*#__PURE__*/ React.createElement(OutputSpec,
|
|
11
|
+
return /*#__PURE__*/ React.createElement(OutputSpec, {
|
|
12
|
+
...props,
|
|
29
13
|
outputSpec: spec,
|
|
30
14
|
ref: ref,
|
|
31
15
|
contentDOMRef: contentDOMRef
|
|
32
|
-
}
|
|
16
|
+
}, children);
|
|
33
17
|
});
|
|
@@ -3,7 +3,7 @@ import { ChildDescriptionsContext } from "../../contexts/ChildDescriptionsContex
|
|
|
3
3
|
import { useNodeViewDescription } from "../../hooks/useNodeViewDescription.js";
|
|
4
4
|
import { ChildNodeViews, wrapInDeco } from "../ChildNodeViews.js";
|
|
5
5
|
export const DocNodeView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function DocNodeView(param, ref) {
|
|
6
|
-
let { as
|
|
6
|
+
let { as, node, getPos, decorations, innerDecorations, setMount, ...elementProps } = param;
|
|
7
7
|
const innerRef = useRef(null);
|
|
8
8
|
useImperativeHandle(ref, ()=>innerRef.current);
|
|
9
9
|
useImperativeHandle(setMount, ()=>innerRef.current);
|
|
@@ -19,7 +19,7 @@ export const DocNodeView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function
|
|
|
19
19
|
decorations,
|
|
20
20
|
innerDecorations
|
|
21
21
|
]);
|
|
22
|
-
const { childContextValue
|
|
22
|
+
const { childContextValue } = useNodeViewDescription(()=>innerRef.current, ()=>innerRef.current, ()=>{
|
|
23
23
|
const dom = innerRef.current;
|
|
24
24
|
return {
|
|
25
25
|
dom,
|
|
@@ -1,26 +1,11 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function(target) {
|
|
3
|
-
for(var i = 1; i < arguments.length; i++){
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
for(var key in source){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
7
|
-
target[key] = source[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
};
|
|
13
|
-
return _extends.apply(this, arguments);
|
|
14
|
-
}
|
|
15
1
|
import React, { createContext, memo, useContext, useMemo } from "react";
|
|
16
2
|
import { NodeViewContext } from "../../contexts/NodeViewContext.js";
|
|
17
3
|
import { DefaultNodeView } from "./DefaultNodeView.js";
|
|
18
4
|
import { NodeViewConstructorView } from "./NodeViewConstructorView.js";
|
|
19
5
|
import { ReactNodeView } from "./ReactNodeView.js";
|
|
20
6
|
export const NodeView = /*#__PURE__*/ memo(function NodeView(props) {
|
|
21
|
-
const { components
|
|
22
|
-
|
|
23
|
-
const component = (_name = components[props.node.type.name]) !== null && _name !== void 0 ? _name : DefaultNodeView;
|
|
7
|
+
const { components, constructors } = useContext(NodeViewContext);
|
|
8
|
+
const component = components[props.node.type.name] ?? DefaultNodeView;
|
|
24
9
|
const constructor = constructors[props.node.type.name];
|
|
25
10
|
// Construct a wrapper component so that the node view remounts when either
|
|
26
11
|
// its component or constructor changes. A React node view would remount if
|
|
@@ -29,15 +14,17 @@ export const NodeView = /*#__PURE__*/ memo(function NodeView(props) {
|
|
|
29
14
|
const Component = useMemo(()=>{
|
|
30
15
|
if (constructor) {
|
|
31
16
|
return function NodeView(props) {
|
|
32
|
-
return /*#__PURE__*/ React.createElement(NodeViewConstructorView,
|
|
33
|
-
constructor: constructor
|
|
34
|
-
|
|
17
|
+
return /*#__PURE__*/ React.createElement(NodeViewConstructorView, {
|
|
18
|
+
constructor: constructor,
|
|
19
|
+
...props
|
|
20
|
+
});
|
|
35
21
|
};
|
|
36
22
|
} else {
|
|
37
23
|
return function NodeView(props) {
|
|
38
|
-
return /*#__PURE__*/ React.createElement(ReactNodeView,
|
|
39
|
-
component: component
|
|
40
|
-
|
|
24
|
+
return /*#__PURE__*/ React.createElement(ReactNodeView, {
|
|
25
|
+
component: component,
|
|
26
|
+
...props
|
|
27
|
+
});
|
|
41
28
|
};
|
|
42
29
|
}
|
|
43
30
|
}, [
|
|
@@ -46,6 +33,6 @@ export const NodeView = /*#__PURE__*/ memo(function NodeView(props) {
|
|
|
46
33
|
]);
|
|
47
34
|
return /*#__PURE__*/ React.createElement(GetPosContext.Provider, {
|
|
48
35
|
value: props.getPos
|
|
49
|
-
}, /*#__PURE__*/ React.createElement(Component,
|
|
36
|
+
}, /*#__PURE__*/ React.createElement(Component, props));
|
|
50
37
|
});
|
|
51
38
|
export const GetPosContext = /*#__PURE__*/ createContext(null);
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function(target) {
|
|
3
|
-
for(var i = 1; i < arguments.length; i++){
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
for(var key in source){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
7
|
-
target[key] = source[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
};
|
|
13
|
-
return _extends.apply(this, arguments);
|
|
14
|
-
}
|
|
15
1
|
import { DOMSerializer } from "prosemirror-model";
|
|
16
2
|
import React, { cloneElement, memo, useMemo, useRef } from "react";
|
|
17
3
|
import { createPortal } from "react-dom";
|
|
@@ -20,7 +6,7 @@ import { useForceUpdate } from "../../hooks/useForceUpdate.js";
|
|
|
20
6
|
import { useNodeViewDescription } from "../../hooks/useNodeViewDescription.js";
|
|
21
7
|
import { ChildNodeViews, wrapInDeco } from "../ChildNodeViews.js";
|
|
22
8
|
export const NodeViewConstructorView = /*#__PURE__*/ memo(function NodeViewConstructorView(param) {
|
|
23
|
-
let { constructor
|
|
9
|
+
let { constructor, node, getPos, innerDeco, outerDeco } = param;
|
|
24
10
|
const ref = useRef(null);
|
|
25
11
|
const innerRef = useRef(null);
|
|
26
12
|
const forceUpdate = useForceUpdate();
|
|
@@ -44,28 +30,22 @@ export const NodeViewConstructorView = /*#__PURE__*/ memo(function NodeViewConst
|
|
|
44
30
|
}
|
|
45
31
|
const nodeView = constructor(...args);
|
|
46
32
|
if (!nodeView || !nodeView.dom) {
|
|
47
|
-
|
|
48
|
-
const spec = (ref = (_spec = node.type.spec).toDOM) === null || ref === void 0 ? void 0 : ref.call(_spec, node);
|
|
33
|
+
const spec = node.type.spec.toDOM?.(node);
|
|
49
34
|
if (!spec) {
|
|
50
|
-
throw new Error(
|
|
35
|
+
throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
|
|
51
36
|
}
|
|
52
37
|
return DOMSerializer.renderSpec(document, spec, null);
|
|
53
38
|
}
|
|
54
39
|
return nodeView;
|
|
55
40
|
};
|
|
56
|
-
|
|
57
|
-
const { childContextValue , contentDOM } = useNodeViewDescription(()=>ref.current, (source)=>{
|
|
58
|
-
return (ref1 = source === null || source === void 0 ? void 0 : source.contentDOM) !== null && ref1 !== void 0 ? ref1 : null;
|
|
59
|
-
}, function() {
|
|
41
|
+
const { childContextValue, contentDOM } = useNodeViewDescription(()=>ref.current, (source)=>source?.contentDOM ?? null, function() {
|
|
60
42
|
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
61
43
|
args[_key] = arguments[_key];
|
|
62
44
|
}
|
|
63
|
-
var ref1, ref2, ref3, ref4, ref5;
|
|
64
45
|
const nodeView = createNodeView(...args);
|
|
65
46
|
const contentDOM = nodeView.contentDOM;
|
|
66
47
|
const nodeDOM = nodeView.dom;
|
|
67
|
-
|
|
68
|
-
const wrapperDOM = (_current = innerRef.current) !== null && _current !== void 0 ? _current : ref.current;
|
|
48
|
+
const wrapperDOM = innerRef.current ?? ref.current;
|
|
69
49
|
wrapperDOM.appendChild(nodeDOM);
|
|
70
50
|
if (!contentDOM && nodeDOM instanceof HTMLElement && nodeDOM.tagName !== "BR") {
|
|
71
51
|
if (!nodeDOM.hasAttribute("contenteditable")) {
|
|
@@ -90,11 +70,11 @@ export const NodeViewConstructorView = /*#__PURE__*/ memo(function NodeViewConst
|
|
|
90
70
|
dom: nodeView.dom,
|
|
91
71
|
contentDOM: nodeView.contentDOM,
|
|
92
72
|
multiType: nodeView.multiType,
|
|
93
|
-
update:
|
|
94
|
-
selectNode:
|
|
95
|
-
deselectNode:
|
|
96
|
-
stopEvent:
|
|
97
|
-
ignoreMutation:
|
|
73
|
+
update: nodeView.update?.bind(nodeView),
|
|
74
|
+
selectNode: nodeView.selectNode?.bind(nodeView),
|
|
75
|
+
deselectNode: nodeView.deselectNode?.bind(nodeView),
|
|
76
|
+
stopEvent: nodeView.stopEvent?.bind(nodeView),
|
|
77
|
+
ignoreMutation: nodeView.ignoreMutation?.bind(nodeView)
|
|
98
78
|
};
|
|
99
79
|
}, nodeProps);
|
|
100
80
|
const Component = node.isInline ? "span" : "div";
|
|
@@ -108,7 +88,7 @@ export const NodeViewConstructorView = /*#__PURE__*/ memo(function NodeViewConst
|
|
|
108
88
|
node: node,
|
|
109
89
|
innerDecorations: innerDeco
|
|
110
90
|
})), contentDOM) : null;
|
|
111
|
-
return /*#__PURE__*/ cloneElement(outerDeco.reduce(wrapInDeco, /*#__PURE__*/ React.createElement(Component,
|
|
91
|
+
return /*#__PURE__*/ cloneElement(outerDeco.reduce(wrapInDeco, /*#__PURE__*/ React.createElement(Component, props, children)), {
|
|
112
92
|
ref
|
|
113
93
|
});
|
|
114
94
|
});
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function(target) {
|
|
3
|
-
for(var i = 1; i < arguments.length; i++){
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
for(var key in source){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
7
|
-
target[key] = source[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
};
|
|
13
|
-
return _extends.apply(this, arguments);
|
|
14
|
-
}
|
|
15
1
|
import React, { cloneElement, memo, useCallback, useMemo, useRef, useState } from "react";
|
|
16
2
|
import { ChildDescriptionsContext } from "../../contexts/ChildDescriptionsContext.js";
|
|
17
3
|
import { IgnoreMutationContext } from "../../contexts/IgnoreMutationContext.js";
|
|
@@ -21,8 +7,7 @@ import { useForceUpdate } from "../../hooks/useForceUpdate.js";
|
|
|
21
7
|
import { useNodeViewDescription } from "../../hooks/useNodeViewDescription.js";
|
|
22
8
|
import { ChildNodeViews, wrapInDeco } from "../ChildNodeViews.js";
|
|
23
9
|
export const ReactNodeView = /*#__PURE__*/ memo(function ReactNodeView(param) {
|
|
24
|
-
let { component: Component
|
|
25
|
-
var ref, ref1;
|
|
10
|
+
let { component: Component, outerDeco, getPos, node, innerDeco } = param;
|
|
26
11
|
const [hasCustomSelectNode, setHasCustomSelectNode] = useState(false);
|
|
27
12
|
const [selected, setSelected] = useState(false);
|
|
28
13
|
const forceUpdate = useForceUpdate();
|
|
@@ -69,11 +54,10 @@ export const ReactNodeView = /*#__PURE__*/ memo(function ReactNodeView(param) {
|
|
|
69
54
|
node,
|
|
70
55
|
outerDeco
|
|
71
56
|
]);
|
|
72
|
-
const { childContextValue
|
|
57
|
+
const { childContextValue, refUpdated } = useNodeViewDescription(()=>domRef.current, ()=>contentDOMRef.current, ()=>{
|
|
73
58
|
setSelected(false);
|
|
74
|
-
var _current;
|
|
75
59
|
return {
|
|
76
|
-
dom:
|
|
60
|
+
dom: nodeDOMRef.current ?? domRef.current,
|
|
77
61
|
update () {
|
|
78
62
|
return true;
|
|
79
63
|
},
|
|
@@ -149,14 +133,14 @@ export const ReactNodeView = /*#__PURE__*/ memo(function ReactNodeView(param) {
|
|
|
149
133
|
]);
|
|
150
134
|
const props = {
|
|
151
135
|
nodeProps,
|
|
152
|
-
...!contentDOMRef.current && !nodeProps.node.isText &&
|
|
136
|
+
...!contentDOMRef.current && !nodeProps.node.isText && nodeDOMRef.current?.nodeName !== "BR" ? {
|
|
153
137
|
contentEditable: false,
|
|
154
138
|
suppressContentEditableWarning: true
|
|
155
139
|
} : null,
|
|
156
140
|
...!hasCustomSelectNode && selected ? {
|
|
157
141
|
className: "ProseMirror-selectednode"
|
|
158
142
|
} : null,
|
|
159
|
-
...!hasCustomSelectNode && selected || !contentDOMRef.current && !nodeProps.node.isText &&
|
|
143
|
+
...!hasCustomSelectNode && selected || !contentDOMRef.current && !nodeProps.node.isText && domRef.current?.nodeName !== "BR" && node.type.spec.draggable ? {
|
|
160
144
|
draggable: true
|
|
161
145
|
} : null,
|
|
162
146
|
ref: setNodeDOM
|
|
@@ -166,7 +150,7 @@ export const ReactNodeView = /*#__PURE__*/ memo(function ReactNodeView(param) {
|
|
|
166
150
|
node: node,
|
|
167
151
|
innerDecorations: innerDeco
|
|
168
152
|
}) : null;
|
|
169
|
-
const element = /*#__PURE__*/ cloneElement(outerDeco.reduce(wrapInDeco, /*#__PURE__*/ React.createElement(Component,
|
|
153
|
+
const element = /*#__PURE__*/ cloneElement(outerDeco.reduce(wrapInDeco, /*#__PURE__*/ React.createElement(Component, props, children)), {
|
|
170
154
|
ref: setDOM
|
|
171
155
|
});
|
|
172
156
|
return /*#__PURE__*/ React.createElement(SelectNodeContext.Provider, {
|
|
@@ -2,15 +2,23 @@ import { Decoration } from "prosemirror-view";
|
|
|
2
2
|
function compareObjs(a, b) {
|
|
3
3
|
if (a == b) return true;
|
|
4
4
|
for(const p in a)if (a[p] !== b[p]) return false;
|
|
5
|
-
for(const
|
|
5
|
+
for(const p in b)if (!(p in a)) return false;
|
|
6
6
|
return true;
|
|
7
7
|
}
|
|
8
8
|
const noSpec = {
|
|
9
9
|
side: 0
|
|
10
10
|
};
|
|
11
11
|
export class ReactWidgetType {
|
|
12
|
+
Component;
|
|
13
|
+
side;
|
|
14
|
+
spec;
|
|
15
|
+
constructor(Component, spec){
|
|
16
|
+
this.Component = Component;
|
|
17
|
+
this.spec = spec ?? noSpec;
|
|
18
|
+
this.side = this.spec.side ?? 0;
|
|
19
|
+
}
|
|
12
20
|
map(mapping, span, offset, oldOffset) {
|
|
13
|
-
const { pos
|
|
21
|
+
const { pos, deleted } = mapping.mapResult(span.from + oldOffset, this.side < 0 ? -1 : 1);
|
|
14
22
|
// @ts-expect-error The Decoration constructor is private/internal, but
|
|
15
23
|
// we need to use it for our custom widget implementation here.
|
|
16
24
|
return deleted ? null : new Decoration(pos - offset, pos - offset, this);
|
|
@@ -24,12 +32,6 @@ export class ReactWidgetType {
|
|
|
24
32
|
destroy() {
|
|
25
33
|
// Can be implemented with React effect hooks
|
|
26
34
|
}
|
|
27
|
-
constructor(Component, spec){
|
|
28
|
-
this.Component = Component;
|
|
29
|
-
this.spec = spec !== null && spec !== void 0 ? spec : noSpec;
|
|
30
|
-
var _side;
|
|
31
|
-
this.side = (_side = this.spec.side) !== null && _side !== void 0 ? _side : 0;
|
|
32
|
-
}
|
|
33
35
|
}
|
|
34
36
|
export function widget(pos, component, spec) {
|
|
35
37
|
// @ts-expect-error The Decoration constructor is private/internal, but
|