@handlewithcare/react-prosemirror 3.1.0-tiptap.40 → 3.1.0-tiptap.42
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 +2 -2
- package/dist/cjs/ReactEditorView.js +71 -75
- package/dist/cjs/StaticEditorView.js +19 -22
- package/dist/cjs/browser.js +1 -3
- package/dist/cjs/commands/reorderSiblings.js +9 -13
- package/dist/cjs/components/ChildNodeViews.js +68 -71
- package/dist/cjs/components/CursorWrapper.js +26 -17
- package/dist/cjs/components/LayoutGroup.js +12 -16
- package/dist/cjs/components/NativeWidgetView.js +15 -19
- package/dist/cjs/components/OutputSpec.js +9 -13
- package/dist/cjs/components/ProseMirror.js +37 -27
- package/dist/cjs/components/ProseMirrorDoc.js +25 -18
- package/dist/cjs/components/SeparatorHackView.js +20 -21
- package/dist/cjs/components/TextNodeView.js +22 -20
- package/dist/cjs/components/TrailingHackView.js +13 -17
- package/dist/cjs/components/WidgetView.js +14 -18
- package/dist/cjs/components/marks/DefaultMarkView.js +27 -15
- package/dist/cjs/components/marks/MarkView.js +32 -23
- package/dist/cjs/components/marks/MarkViewConstructorView.js +38 -22
- package/dist/cjs/components/marks/ReactMarkView.js +27 -16
- package/dist/cjs/components/nodes/DefaultNodeView.js +27 -15
- package/dist/cjs/components/nodes/DocNodeView.js +12 -16
- package/dist/cjs/components/nodes/NodeView.js +33 -26
- package/dist/cjs/components/nodes/NodeViewConstructorView.js +45 -29
- package/dist/cjs/components/nodes/ReactNodeView.js +39 -27
- package/dist/cjs/constants.js +6 -10
- package/dist/cjs/contexts/ChildDescriptionsContext.js +1 -3
- package/dist/cjs/contexts/EditorContext.js +1 -3
- package/dist/cjs/contexts/EditorStateContext.js +1 -3
- package/dist/cjs/contexts/IgnoreMutationContext.js +1 -3
- package/dist/cjs/contexts/LayoutGroupContext.js +1 -3
- package/dist/cjs/contexts/NodeViewContext.js +1 -3
- package/dist/cjs/contexts/SelectNodeContext.js +1 -3
- package/dist/cjs/contexts/StopEventContext.js +1 -3
- package/dist/cjs/decorations/ReactWidgetType.js +13 -19
- package/dist/cjs/decorations/computeDocDeco.js +3 -5
- package/dist/cjs/decorations/iterDeco.js +17 -19
- package/dist/cjs/decorations/viewDecorations.js +12 -15
- package/dist/cjs/dom.js +13 -34
- package/dist/cjs/findDOMNode.js +5 -9
- package/dist/cjs/hooks/useClientLayoutEffect.js +1 -3
- package/dist/cjs/hooks/useComponentEventListeners.js +6 -7
- package/dist/cjs/hooks/useEditor.js +30 -28
- package/dist/cjs/hooks/useEditorEffect.js +7 -9
- package/dist/cjs/hooks/useEditorEventCallback.js +7 -9
- package/dist/cjs/hooks/useEditorEventListener.js +6 -8
- package/dist/cjs/hooks/useEditorState.js +3 -5
- package/dist/cjs/hooks/useEffectEvent.js +1 -3
- package/dist/cjs/hooks/useForceUpdate.js +1 -3
- package/dist/cjs/hooks/useIgnoreMutation.js +7 -9
- package/dist/cjs/hooks/useIsEditorStatic.js +5 -5
- package/dist/cjs/hooks/useIsNodeSelected.js +3 -5
- package/dist/cjs/hooks/useLayoutGroupEffect.js +5 -7
- package/dist/cjs/hooks/useMarkViewDescription.js +25 -24
- package/dist/cjs/hooks/useNodePos.js +5 -7
- package/dist/cjs/hooks/useNodeViewDescription.js +41 -28
- package/dist/cjs/hooks/useReactKeys.js +5 -7
- package/dist/cjs/hooks/useSelectNode.js +8 -10
- package/dist/cjs/hooks/useStopEvent.js +7 -9
- package/dist/cjs/index.js +34 -66
- package/dist/cjs/plugins/beforeInputPlugin.js +23 -20
- package/dist/cjs/plugins/componentEventListeners.js +6 -8
- package/dist/cjs/plugins/componentEventListenersPlugin.js +6 -8
- package/dist/cjs/plugins/reactKeys.js +10 -15
- package/dist/cjs/props.js +19 -23
- package/dist/cjs/refs.js +1 -3
- package/dist/cjs/testing/editorViewTestHelpers.js +47 -40
- package/dist/cjs/testing/setupProseMirrorView.js +4 -7
- package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +6 -10
- package/dist/cjs/tiptap/TiptapEditor.js +14 -15
- package/dist/cjs/tiptap/TiptapEditorContent.js +28 -18
- package/dist/cjs/tiptap/TiptapEditorView.js +34 -23
- package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +1 -3
- package/dist/cjs/tiptap/extensions/ReactProseMirror.js +6 -8
- package/dist/cjs/tiptap/extensions/ReactProseMirrorCommands.js +3 -5
- package/dist/cjs/tiptap/extensions/commands/updateAttributes.js +2 -4
- package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +3 -5
- package/dist/cjs/tiptap/hooks/useTiptapEditor.js +14 -12
- package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +10 -12
- package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +4 -6
- package/dist/cjs/tiptap/index.js +18 -36
- package/dist/cjs/tiptap/tiptapNodeView.js +62 -48
- package/dist/cjs/viewdesc.js +95 -119
- package/dist/esm/ReactEditorView.js +67 -69
- package/dist/esm/StaticEditorView.js +18 -19
- package/dist/esm/commands/reorderSiblings.js +5 -5
- package/dist/esm/components/ChildNodeViews.js +36 -33
- package/dist/esm/components/CursorWrapper.js +18 -5
- 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 +17 -3
- package/dist/esm/components/ProseMirrorDoc.js +19 -6
- package/dist/esm/components/SeparatorHackView.js +8 -5
- package/dist/esm/components/TextNodeView.js +10 -6
- package/dist/esm/components/TrailingHackView.js +2 -2
- package/dist/esm/components/WidgetView.js +3 -3
- package/dist/esm/components/marks/DefaultMarkView.js +22 -6
- package/dist/esm/components/marks/MarkView.js +24 -11
- package/dist/esm/components/marks/MarkViewConstructorView.js +27 -7
- package/dist/esm/components/marks/ReactMarkView.js +18 -3
- package/dist/esm/components/nodes/DefaultNodeView.js +22 -6
- package/dist/esm/components/nodes/DocNodeView.js +2 -2
- package/dist/esm/components/nodes/NodeView.js +24 -11
- package/dist/esm/components/nodes/NodeViewConstructorView.js +31 -11
- package/dist/esm/components/nodes/ReactNodeView.js +22 -6
- package/dist/esm/decorations/ReactWidgetType.js +8 -10
- package/dist/esm/decorations/iterDeco.js +13 -13
- package/dist/esm/decorations/viewDecorations.js +6 -7
- package/dist/esm/dom.js +2 -1
- package/dist/esm/findDOMNode.js +1 -1
- package/dist/esm/hooks/useComponentEventListeners.js +3 -2
- package/dist/esm/hooks/useEditor.js +9 -5
- 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 +3 -1
- package/dist/esm/hooks/useMarkViewDescription.js +10 -7
- package/dist/esm/hooks/useNodeViewDescription.js +22 -7
- package/dist/esm/hooks/useReactKeys.js +1 -1
- package/dist/esm/plugins/beforeInputPlugin.js +17 -12
- package/dist/esm/plugins/reactKeys.js +4 -3
- package/dist/esm/props.js +15 -15
- package/dist/esm/testing/editorViewTestHelpers.js +31 -20
- package/dist/esm/testing/setupProseMirrorView.js +2 -1
- package/dist/esm/tiptap/ReactProseMirrorNodeView.js +5 -7
- package/dist/esm/tiptap/TiptapEditor.js +10 -9
- package/dist/esm/tiptap/TiptapEditorContent.js +18 -4
- package/dist/esm/tiptap/TiptapEditorView.js +23 -8
- 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 +8 -4
- package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +4 -4
- package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +1 -1
- package/dist/esm/tiptap/tiptapNodeView.js +38 -20
- package/dist/esm/viewdesc.js +72 -74
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ReactEditorView.d.ts +2 -2
- package/dist/types/StaticEditorView.d.ts +2 -1
- package/dist/types/props.d.ts +26 -26
- package/dist/types/viewdesc.d.ts +2 -0
- package/package.json +10 -6
|
@@ -6,17 +6,15 @@ import { NodeView } from "@tiptap/core";
|
|
|
6
6
|
* ViewDesc, so that we can call Tiptap's default stopEvent and ignoreMutation
|
|
7
7
|
* methods
|
|
8
8
|
*/ export class ReactProseMirrorNodeView extends NodeView {
|
|
9
|
-
_dom;
|
|
10
|
-
_contentDOM;
|
|
11
|
-
constructor(component, props, dom, contentDOM, options){
|
|
12
|
-
super(component, props, options);
|
|
13
|
-
this._dom = dom;
|
|
14
|
-
this._contentDOM = contentDOM;
|
|
15
|
-
}
|
|
16
9
|
get dom() {
|
|
17
10
|
return this._dom;
|
|
18
11
|
}
|
|
19
12
|
get contentDOM() {
|
|
20
13
|
return this._contentDOM;
|
|
21
14
|
}
|
|
15
|
+
constructor(component, props, dom, contentDOM, options){
|
|
16
|
+
super(component, props, options);
|
|
17
|
+
this._dom = dom;
|
|
18
|
+
this._contentDOM = contentDOM;
|
|
19
|
+
}
|
|
22
20
|
}
|
|
@@ -2,15 +2,10 @@ import { Editor } from "@tiptap/core";
|
|
|
2
2
|
import { EditorState } from "prosemirror-state";
|
|
3
3
|
import { StaticEditorView } from "../StaticEditorView.js";
|
|
4
4
|
export class TiptapEditor extends Editor {
|
|
5
|
-
constructor(options = {}){
|
|
6
|
-
super({
|
|
7
|
-
...options,
|
|
8
|
-
element: null
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
5
|
get view() {
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
var // @ts-expect-error private property
|
|
7
|
+
_editorView;
|
|
8
|
+
return (_editorView = this.editorView) !== null && _editorView !== void 0 ? _editorView : new StaticEditorView({
|
|
14
9
|
state: EditorState.create({
|
|
15
10
|
schema: this.extensionManager.schema
|
|
16
11
|
}),
|
|
@@ -19,6 +14,12 @@ export class TiptapEditor extends Editor {
|
|
|
19
14
|
role: "textbox",
|
|
20
15
|
...this.options.editorProps.attributes
|
|
21
16
|
}
|
|
22
|
-
})
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
constructor(options = {}){
|
|
20
|
+
super({
|
|
21
|
+
...options,
|
|
22
|
+
element: null
|
|
23
|
+
});
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -1,3 +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
|
+
}
|
|
1
15
|
import React, { useContext, useSyncExternalStore } from "react";
|
|
2
16
|
import { createPortal } from "react-dom";
|
|
3
17
|
import { ProseMirrorDoc } from "../components/ProseMirrorDoc.js";
|
|
@@ -6,7 +20,7 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
|
|
|
6
20
|
/**
|
|
7
21
|
* This component renders all of the editor's registered "React renderers".
|
|
8
22
|
*/ const Portals = (param)=>{
|
|
9
|
-
let { contentComponent
|
|
23
|
+
let { contentComponent } = param;
|
|
10
24
|
const renderers = useSyncExternalStore(contentComponent.subscribe, contentComponent.getSnapshot, contentComponent.getServerSnapshot);
|
|
11
25
|
return /*#__PURE__*/ React.createElement(React.Fragment, null, Object.values(renderers));
|
|
12
26
|
};
|
|
@@ -50,9 +64,9 @@ function getInstance() {
|
|
|
50
64
|
};
|
|
51
65
|
}
|
|
52
66
|
export function TiptapEditorContent(param) {
|
|
53
|
-
let { editor: editorProp, ...props } = param;
|
|
67
|
+
let { editor: editorProp , ...props } = param;
|
|
54
68
|
const editor = editorProp;
|
|
55
|
-
const { onEditorInitialize, onEditorDeinitialize
|
|
69
|
+
const { onEditorInitialize , onEditorDeinitialize } = useContext(TiptapEditorContext);
|
|
56
70
|
useEditorEffect((view)=>{
|
|
57
71
|
if (editor.view === view) {
|
|
58
72
|
return;
|
|
@@ -86,7 +100,7 @@ export function TiptapEditorContent(param) {
|
|
|
86
100
|
onEditorDeinitialize,
|
|
87
101
|
onEditorInitialize
|
|
88
102
|
]);
|
|
89
|
-
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ProseMirrorDoc, props), editor
|
|
103
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ProseMirrorDoc, _extends({}, props)), (editor === null || editor === void 0 ? void 0 : editor.contentComponent) && /*#__PURE__*/ React.createElement(Portals, {
|
|
90
104
|
contentComponent: editor.contentComponent
|
|
91
105
|
}));
|
|
92
106
|
}
|
|
@@ -1,3 +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
|
+
}
|
|
1
15
|
import { EditorContext } from "@tiptap/react";
|
|
2
16
|
import cx from "classnames";
|
|
3
17
|
import React, { useCallback, useMemo, useState } from "react";
|
|
@@ -7,9 +21,10 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
|
|
|
7
21
|
/**
|
|
8
22
|
* Render a Tiptap-compatible React ProseMirror editor.
|
|
9
23
|
*/ export function TiptapEditorView(param) {
|
|
10
|
-
let { editor, nodeViewComponents, markViewComponents, children, static: isStatic = false
|
|
24
|
+
let { editor , nodeViewComponents , markViewComponents , children , static: isStatic = false } = param;
|
|
25
|
+
var ref;
|
|
11
26
|
const [isEditorInitialized, setIsEditorInitialized] = useState(editor.isInitialized);
|
|
12
|
-
const attributesProp = editor.options.editorProps
|
|
27
|
+
const attributesProp = (ref = editor.options.editorProps) === null || ref === void 0 ? void 0 : ref.attributes;
|
|
13
28
|
const [attributes, setAttributes] = useState(typeof attributesProp === "function" ? attributesProp(editor.state) : attributesProp);
|
|
14
29
|
const forceUpdate = useForceUpdate();
|
|
15
30
|
const dispatchTransaction = useCallback((tr)=>{
|
|
@@ -32,10 +47,10 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
|
|
|
32
47
|
attributes: {
|
|
33
48
|
role: "textbox",
|
|
34
49
|
...attributes,
|
|
35
|
-
class: cx(attributes
|
|
50
|
+
class: cx(attributes === null || attributes === void 0 ? void 0 : attributes.class, "tiptap")
|
|
36
51
|
}
|
|
37
52
|
};
|
|
38
|
-
const { nodeViews, markViews
|
|
53
|
+
const { nodeViews , markViews } = editor.isDestroyed ? {
|
|
39
54
|
nodeViews: undefined,
|
|
40
55
|
markViews: undefined
|
|
41
56
|
} : editor.view.props;
|
|
@@ -59,16 +74,16 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
|
|
|
59
74
|
onEditorDeinitialize,
|
|
60
75
|
onEditorInitialize
|
|
61
76
|
]);
|
|
62
|
-
return /*#__PURE__*/ React.createElement(ProseMirror, {
|
|
63
|
-
static: isStatic
|
|
64
|
-
|
|
77
|
+
return /*#__PURE__*/ React.createElement(ProseMirror, _extends({
|
|
78
|
+
static: isStatic
|
|
79
|
+
}, editorProps, {
|
|
65
80
|
markViewComponents: markViewComponents,
|
|
66
81
|
markViews: markViews,
|
|
67
82
|
nodeViewComponents: nodeViewComponents,
|
|
68
83
|
nodeViews: nodeViews,
|
|
69
84
|
state: editor.state,
|
|
70
85
|
dispatchTransaction: dispatchTransaction
|
|
71
|
-
}, /*#__PURE__*/ React.createElement(EditorContext.Provider, {
|
|
86
|
+
}), /*#__PURE__*/ React.createElement(EditorContext.Provider, {
|
|
72
87
|
value: contextValue
|
|
73
88
|
}, /*#__PURE__*/ React.createElement(TiptapEditorContext.Provider, {
|
|
74
89
|
value: tiptapEditorContextValue
|
|
@@ -21,7 +21,7 @@ export const ReactProseMirror = Extension.create({
|
|
|
21
21
|
* and keep the other two in relative order, set `order` to `[1, 2, 0]`.
|
|
22
22
|
*/ reorderSiblings (initialPos, order) {
|
|
23
23
|
return function reorderSiblingsCommand(param) {
|
|
24
|
-
let { tr, state, dispatch
|
|
24
|
+
let { tr , state , dispatch } = param;
|
|
25
25
|
return reorderSiblingsOnTransaction(initialPos, order, tr, state, dispatch);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -4,7 +4,7 @@ import { getMarkType, getNodeType, getSchemaTypeNameByName } from "@tiptap/core"
|
|
|
4
4
|
export const updateAttributes = function(typeOrName) {
|
|
5
5
|
let attributes = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
6
6
|
return (param)=>{
|
|
7
|
-
let { tr, state, dispatch
|
|
7
|
+
let { tr , state , dispatch } = param;
|
|
8
8
|
let nodeType = null;
|
|
9
9
|
let markType = null;
|
|
10
10
|
const schemaType = getSchemaTypeNameByName(typeof typeOrName === "string" ? typeOrName : typeOrName.name, state.schema);
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
var // @ts-expect-error private property
|
|
2
|
+
_editor;
|
|
1
3
|
import { useEditor } from "@tiptap/react";
|
|
2
4
|
import { StaticEditorView } from "../../StaticEditorView.js";
|
|
3
5
|
import { ReactProseMirror } from "../extensions/ReactProseMirror.js";
|
|
4
6
|
import { ReactProseMirrorCommands } from "../extensions/ReactProseMirrorCommands.js";
|
|
5
7
|
export function useTiptapEditor(options, deps) {
|
|
8
|
+
var ref;
|
|
9
|
+
var _extensions;
|
|
6
10
|
const extensions = [
|
|
7
11
|
ReactProseMirror,
|
|
8
|
-
...options.extensions
|
|
12
|
+
...(_extensions = options.extensions) !== null && _extensions !== void 0 ? _extensions : []
|
|
9
13
|
];
|
|
10
14
|
// If a consumer explicitly disables core extensions (or the Commands core extension)
|
|
11
15
|
// do not re-add our custom Commands
|
|
12
|
-
if (options.enableCoreExtensions === false || typeof options.enableCoreExtensions === "object" && options
|
|
16
|
+
if (options.enableCoreExtensions === false || typeof options.enableCoreExtensions === "object" && (options === null || options === void 0 ? void 0 : (ref = options.enableCoreExtensions) === null || ref === void 0 ? void 0 : ref.commands) === false) {
|
|
13
17
|
// Do nothing
|
|
14
18
|
} else {
|
|
15
19
|
options.enableCoreExtensions = {
|
|
@@ -23,8 +27,8 @@ export function useTiptapEditor(options, deps) {
|
|
|
23
27
|
extensions,
|
|
24
28
|
element: null
|
|
25
29
|
}, deps);
|
|
26
|
-
|
|
27
|
-
editor.editorView
|
|
30
|
+
var _editorView;
|
|
31
|
+
(_editorView = (_editor = editor).editorView) !== null && _editorView !== void 0 ? _editorView : _editor.editorView = new StaticEditorView({
|
|
28
32
|
// @ts-expect-error private property
|
|
29
33
|
state: editor.editorState,
|
|
30
34
|
...editor.options.editorProps,
|
|
@@ -22,11 +22,11 @@ import { TiptapEditorContext } from "../contexts/TiptapEditorContext.js";
|
|
|
22
22
|
* as a child of the TiptapEditorView component, including
|
|
23
23
|
* React node view components.
|
|
24
24
|
*/ export function useTiptapEditorEffect(effect, dependencies) {
|
|
25
|
-
const { view
|
|
26
|
-
const { editor
|
|
27
|
-
const { isEditorInitialized
|
|
25
|
+
const { view } = useContext(EditorContext);
|
|
26
|
+
const { editor } = useCurrentEditor();
|
|
27
|
+
const { isEditorInitialized } = useContext(TiptapEditorContext);
|
|
28
28
|
useEditorEffect(()=>{
|
|
29
|
-
if (editor
|
|
29
|
+
if ((editor === null || editor === void 0 ? void 0 : editor.view) instanceof ReactEditorView && view instanceof ReactEditorView && isEditorInitialized) {
|
|
30
30
|
return effect(editor);
|
|
31
31
|
}
|
|
32
32
|
// The rules of hooks want to be able to statically
|
|
@@ -17,7 +17,7 @@ function assertEditor(editor) {
|
|
|
17
17
|
* React node view components.
|
|
18
18
|
*/ export function useTiptapEditorEventCallback(callback) {
|
|
19
19
|
const ref = useRef(callback);
|
|
20
|
-
const { editor
|
|
20
|
+
const { editor } = useCurrentEditor();
|
|
21
21
|
useEditorEffect(()=>{
|
|
22
22
|
ref.current = callback;
|
|
23
23
|
}, [
|
|
@@ -1,3 +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
|
+
}
|
|
1
15
|
import { getAttributesFromExtensions, getRenderedAttributes } from "@tiptap/core";
|
|
2
16
|
import { ReactNodeViewContext, useCurrentEditor } from "@tiptap/react";
|
|
3
17
|
import cx from "classnames";
|
|
@@ -35,14 +49,16 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
35
49
|
* }
|
|
36
50
|
* ```
|
|
37
51
|
*/ export function tiptapNodeView(param) {
|
|
38
|
-
let { component: WrappedComponent, extension, as, className =
|
|
52
|
+
let { component: WrappedComponent , extension , as , className ="" , attrs , contentDOMElementTag: InnerTag = "div" , stopEvent , ignoreMutation } = param;
|
|
39
53
|
const TiptapNodeView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function TiptapNodeView(param, ref) {
|
|
40
|
-
let { children, nodeProps, ...props } = param;
|
|
41
|
-
const { node, getPos, decorations, innerDecorations, contentDOMRef
|
|
42
|
-
const OuterTag = as
|
|
43
|
-
const { editor
|
|
44
|
-
|
|
45
|
-
const
|
|
54
|
+
let { children , nodeProps , ...props } = param;
|
|
55
|
+
const { node , getPos , decorations , innerDecorations , contentDOMRef } = nodeProps;
|
|
56
|
+
const OuterTag = as !== null && as !== void 0 ? as : node.type.isInline ? "span" : "div";
|
|
57
|
+
const { editor } = useCurrentEditor();
|
|
58
|
+
var ref1;
|
|
59
|
+
const extensionManager = (ref1 = editor === null || editor === void 0 ? void 0 : editor.extensionManager) !== null && ref1 !== void 0 ? ref1 : null;
|
|
60
|
+
var ref2;
|
|
61
|
+
const extensions = (ref2 = extensionManager === null || extensionManager === void 0 ? void 0 : extensionManager.extensions) !== null && ref2 !== void 0 ? ref2 : null;
|
|
46
62
|
const selected = useIsNodeSelected();
|
|
47
63
|
const isDraggingRef = useRef(false);
|
|
48
64
|
const htmlAttributes = useMemo(()=>{
|
|
@@ -79,9 +95,10 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
79
95
|
isDraggingRef.current = nodeView.isDragging;
|
|
80
96
|
return result;
|
|
81
97
|
}
|
|
82
|
-
|
|
98
|
+
var ref;
|
|
99
|
+
const result1 = (ref = nodeView.stopEvent(event)) !== null && ref !== void 0 ? ref : false;
|
|
83
100
|
isDraggingRef.current = nodeView.isDragging;
|
|
84
|
-
return
|
|
101
|
+
return result1;
|
|
85
102
|
});
|
|
86
103
|
useIgnoreMutation(function(_, mutation) {
|
|
87
104
|
if (ignoreMutation) {
|
|
@@ -104,15 +121,16 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
104
121
|
node,
|
|
105
122
|
view: editor.view
|
|
106
123
|
}, this.dom, this.contentDOM);
|
|
107
|
-
|
|
124
|
+
var ref;
|
|
125
|
+
return (ref = nodeView.ignoreMutation(mutation)) !== null && ref !== void 0 ? ref : false;
|
|
108
126
|
});
|
|
109
|
-
const { extraClassName, htmlProps
|
|
127
|
+
const { extraClassName , htmlProps } = useMemo(()=>{
|
|
110
128
|
if (!attrs) return {};
|
|
111
129
|
const resolvedAttrs = typeof attrs === "function" ? attrs({
|
|
112
130
|
node,
|
|
113
131
|
HTMLAttributes: htmlAttributes
|
|
114
132
|
}) : attrs;
|
|
115
|
-
const { className: extraClassName, ...htmlProps } = htmlAttrsToReactProps(resolvedAttrs);
|
|
133
|
+
const { className: extraClassName , ...htmlProps } = htmlAttrsToReactProps(resolvedAttrs);
|
|
116
134
|
return {
|
|
117
135
|
extraClassName,
|
|
118
136
|
htmlProps
|
|
@@ -121,7 +139,7 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
121
139
|
htmlAttributes,
|
|
122
140
|
node
|
|
123
141
|
]);
|
|
124
|
-
const finalClassName = cx("react-renderer",
|
|
142
|
+
const finalClassName = cx("react-renderer", "node-".concat(node.type.name), props.className, className, extraClassName, {
|
|
125
143
|
"ProseMirror-selectednode": selected
|
|
126
144
|
});
|
|
127
145
|
const updateAttributes = useEditorEventCallback((_, attributes)=>{
|
|
@@ -129,7 +147,7 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
129
147
|
return;
|
|
130
148
|
}
|
|
131
149
|
editor.commands.command((param)=>{
|
|
132
|
-
let { tr
|
|
150
|
+
let { tr } = param;
|
|
133
151
|
const pos = getPos();
|
|
134
152
|
tr.setNodeMarkup(pos, undefined, {
|
|
135
153
|
...node.attrs,
|
|
@@ -189,12 +207,11 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
189
207
|
if (!editor) return null;
|
|
190
208
|
return /*#__PURE__*/ React.createElement(ReactNodeViewContext.Provider, {
|
|
191
209
|
value: nodeViewContext
|
|
192
|
-
}, /*#__PURE__*/ React.createElement(OuterTag, {
|
|
193
|
-
ref: finalRef
|
|
194
|
-
|
|
195
|
-
...htmlProps,
|
|
210
|
+
}, /*#__PURE__*/ React.createElement(OuterTag, _extends({
|
|
211
|
+
ref: finalRef
|
|
212
|
+
}, props, htmlProps, {
|
|
196
213
|
className: finalClassName
|
|
197
|
-
}, /*#__PURE__*/ React.createElement(WrappedComponent, {
|
|
214
|
+
}), /*#__PURE__*/ React.createElement(WrappedComponent, {
|
|
198
215
|
node: node,
|
|
199
216
|
getPos: getPos,
|
|
200
217
|
view: editor.view,
|
|
@@ -208,6 +225,7 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
208
225
|
deleteNode: deleteNode
|
|
209
226
|
})));
|
|
210
227
|
}));
|
|
211
|
-
|
|
228
|
+
var _displayName;
|
|
229
|
+
TiptapNodeView.displayName = "TiptapNodeView(".concat((_displayName = WrappedComponent.displayName) !== null && _displayName !== void 0 ? _displayName : "Anonymous", ")");
|
|
212
230
|
return TiptapNodeView;
|
|
213
231
|
}
|