@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
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
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
|
-
import { render } from "@testing-library/react";
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */ import { render } from "@testing-library/react";
|
|
16
2
|
import { expect } from "expect";
|
|
17
3
|
import { Node } from "prosemirror-model";
|
|
18
4
|
import { EditorState, TextSelection } from "prosemirror-state";
|
|
@@ -29,7 +15,7 @@ const toEqualNode = function(actual, expected) {
|
|
|
29
15
|
const pass = eq(actual, expected);
|
|
30
16
|
return {
|
|
31
17
|
message: ()=>// `this` context will have correct typings
|
|
32
|
-
|
|
18
|
+
`expected ${this.utils.printReceived(actual)} ${pass ? "not " : ""}to equal ${this.utils.printExpected(expected)}`,
|
|
33
19
|
pass
|
|
34
20
|
};
|
|
35
21
|
};
|
|
@@ -37,15 +23,14 @@ expect.extend({
|
|
|
37
23
|
toEqualNode
|
|
38
24
|
});
|
|
39
25
|
export function tempEditor(param) {
|
|
40
|
-
let { doc: startDoc
|
|
41
|
-
|
|
42
|
-
startDoc = startDoc !== null && startDoc !== void 0 ? startDoc : doc(p());
|
|
26
|
+
let { doc: startDoc, selection, controlled, plugins, ...props } = param;
|
|
27
|
+
startDoc = startDoc ?? doc(p());
|
|
43
28
|
const state = EditorState.create({
|
|
44
29
|
doc: startDoc,
|
|
45
30
|
schema,
|
|
46
|
-
selection:
|
|
31
|
+
selection: selection ?? (startDoc.tag?.a ? TextSelection.create(startDoc, startDoc.tag.a, startDoc.tag?.b) : undefined),
|
|
47
32
|
plugins: [
|
|
48
|
-
...plugins
|
|
33
|
+
...plugins ?? [],
|
|
49
34
|
reactKeys()
|
|
50
35
|
]
|
|
51
36
|
});
|
|
@@ -56,21 +41,25 @@ export function tempEditor(param) {
|
|
|
56
41
|
});
|
|
57
42
|
return null;
|
|
58
43
|
}
|
|
59
|
-
const { rerender
|
|
60
|
-
|
|
61
|
-
} : {
|
|
62
|
-
defaultState: state
|
|
63
|
-
}, props), /*#__PURE__*/ React.createElement(Test, null), /*#__PURE__*/ React.createElement(ProseMirrorDoc, null)));
|
|
64
|
-
function rerenderEditor() {
|
|
65
|
-
let { ...newProps } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
66
|
-
rerender(/*#__PURE__*/ React.createElement(ProseMirror, _extends({}, controlled ? {
|
|
44
|
+
const { rerender, unmount } = render(/*#__PURE__*/ React.createElement(ProseMirror, {
|
|
45
|
+
...controlled ? {
|
|
67
46
|
state
|
|
68
47
|
} : {
|
|
69
48
|
defaultState: state
|
|
70
|
-
},
|
|
49
|
+
},
|
|
50
|
+
...props
|
|
51
|
+
}, /*#__PURE__*/ React.createElement(Test, null), /*#__PURE__*/ React.createElement(ProseMirrorDoc, null)));
|
|
52
|
+
function rerenderEditor() {
|
|
53
|
+
let { ...newProps } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
54
|
+
rerender(/*#__PURE__*/ React.createElement(ProseMirror, {
|
|
55
|
+
...controlled ? {
|
|
56
|
+
state
|
|
57
|
+
} : {
|
|
58
|
+
defaultState: state
|
|
59
|
+
},
|
|
71
60
|
...props,
|
|
72
61
|
...newProps
|
|
73
|
-
}
|
|
62
|
+
}, /*#__PURE__*/ React.createElement(Test, null), /*#__PURE__*/ React.createElement(ProseMirrorDoc, null)));
|
|
74
63
|
return view;
|
|
75
64
|
}
|
|
76
65
|
return {
|
|
@@ -53,8 +53,7 @@ const mockGetClientRects = ()=>{
|
|
|
53
53
|
];
|
|
54
54
|
const domRectList = Object.assign(list, {
|
|
55
55
|
item (index) {
|
|
56
|
-
|
|
57
|
-
return (_index = list[index]) !== null && _index !== void 0 ? _index : null;
|
|
56
|
+
return list[index] ?? null;
|
|
58
57
|
}
|
|
59
58
|
});
|
|
60
59
|
return domRectList;
|
|
@@ -6,15 +6,17 @@ 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
|
+
}
|
|
9
16
|
get dom() {
|
|
10
17
|
return this._dom;
|
|
11
18
|
}
|
|
12
19
|
get contentDOM() {
|
|
13
20
|
return this._contentDOM;
|
|
14
21
|
}
|
|
15
|
-
constructor(component, props, dom, contentDOM, options){
|
|
16
|
-
super(component, props, options);
|
|
17
|
-
this._dom = dom;
|
|
18
|
-
this._contentDOM = contentDOM;
|
|
19
|
-
}
|
|
20
22
|
}
|
|
@@ -2,10 +2,15 @@ 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
|
+
}
|
|
5
11
|
get view() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return (_editorView = this.editorView) !== null && _editorView !== void 0 ? _editorView : new StaticEditorView({
|
|
12
|
+
return(// @ts-expect-error private property
|
|
13
|
+
this.editorView ?? new StaticEditorView({
|
|
9
14
|
state: EditorState.create({
|
|
10
15
|
schema: this.extensionManager.schema
|
|
11
16
|
}),
|
|
@@ -14,12 +19,6 @@ export class TiptapEditor extends Editor {
|
|
|
14
19
|
role: "textbox",
|
|
15
20
|
...this.options.editorProps.attributes
|
|
16
21
|
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
constructor(options = {}){
|
|
20
|
-
super({
|
|
21
|
-
...options,
|
|
22
|
-
element: null
|
|
23
|
-
});
|
|
22
|
+
}));
|
|
24
23
|
}
|
|
25
24
|
}
|
|
@@ -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, { useContext, useSyncExternalStore } from "react";
|
|
16
2
|
import { createPortal } from "react-dom";
|
|
17
3
|
import { ProseMirrorDoc } from "../components/ProseMirrorDoc.js";
|
|
@@ -20,7 +6,7 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
|
|
|
20
6
|
/**
|
|
21
7
|
* This component renders all of the editor's registered "React renderers".
|
|
22
8
|
*/ const Portals = (param)=>{
|
|
23
|
-
let { contentComponent
|
|
9
|
+
let { contentComponent } = param;
|
|
24
10
|
const renderers = useSyncExternalStore(contentComponent.subscribe, contentComponent.getSnapshot, contentComponent.getServerSnapshot);
|
|
25
11
|
return /*#__PURE__*/ React.createElement(React.Fragment, null, Object.values(renderers));
|
|
26
12
|
};
|
|
@@ -64,9 +50,9 @@ function getInstance() {
|
|
|
64
50
|
};
|
|
65
51
|
}
|
|
66
52
|
export function TiptapEditorContent(param) {
|
|
67
|
-
let { editor: editorProp
|
|
53
|
+
let { editor: editorProp, ...props } = param;
|
|
68
54
|
const editor = editorProp;
|
|
69
|
-
const { onEditorInitialize
|
|
55
|
+
const { onEditorInitialize, onEditorDeinitialize } = useContext(TiptapEditorContext);
|
|
70
56
|
useEditorEffect((view)=>{
|
|
71
57
|
if (editor.view === view) {
|
|
72
58
|
return;
|
|
@@ -100,7 +86,7 @@ export function TiptapEditorContent(param) {
|
|
|
100
86
|
onEditorDeinitialize,
|
|
101
87
|
onEditorInitialize
|
|
102
88
|
]);
|
|
103
|
-
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ProseMirrorDoc,
|
|
89
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ProseMirrorDoc, props), editor?.contentComponent && /*#__PURE__*/ React.createElement(Portals, {
|
|
104
90
|
contentComponent: editor.contentComponent
|
|
105
91
|
}));
|
|
106
92
|
}
|
|
@@ -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 { EditorContext } from "@tiptap/react";
|
|
16
2
|
import cx from "classnames";
|
|
17
3
|
import React, { useCallback, useMemo, useState } from "react";
|
|
@@ -21,10 +7,9 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
|
|
|
21
7
|
/**
|
|
22
8
|
* Render a Tiptap-compatible React ProseMirror editor.
|
|
23
9
|
*/ export function TiptapEditorView(param) {
|
|
24
|
-
let { editor
|
|
25
|
-
var ref;
|
|
10
|
+
let { editor, nodeViewComponents, markViewComponents, children, static: isStatic = false } = param;
|
|
26
11
|
const [isEditorInitialized, setIsEditorInitialized] = useState(editor.isInitialized);
|
|
27
|
-
const attributesProp =
|
|
12
|
+
const attributesProp = editor.options.editorProps?.attributes;
|
|
28
13
|
const [attributes, setAttributes] = useState(typeof attributesProp === "function" ? attributesProp(editor.state) : attributesProp);
|
|
29
14
|
const forceUpdate = useForceUpdate();
|
|
30
15
|
const dispatchTransaction = useCallback((tr)=>{
|
|
@@ -47,10 +32,10 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
|
|
|
47
32
|
attributes: {
|
|
48
33
|
role: "textbox",
|
|
49
34
|
...attributes,
|
|
50
|
-
class: cx(attributes
|
|
35
|
+
class: cx(attributes?.class, "tiptap")
|
|
51
36
|
}
|
|
52
37
|
};
|
|
53
|
-
const { nodeViews
|
|
38
|
+
const { nodeViews, markViews } = editor.isDestroyed ? {
|
|
54
39
|
nodeViews: undefined,
|
|
55
40
|
markViews: undefined
|
|
56
41
|
} : editor.view.props;
|
|
@@ -74,16 +59,16 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
|
|
|
74
59
|
onEditorDeinitialize,
|
|
75
60
|
onEditorInitialize
|
|
76
61
|
]);
|
|
77
|
-
return /*#__PURE__*/ React.createElement(ProseMirror,
|
|
78
|
-
static: isStatic
|
|
79
|
-
|
|
62
|
+
return /*#__PURE__*/ React.createElement(ProseMirror, {
|
|
63
|
+
static: isStatic,
|
|
64
|
+
...editorProps,
|
|
80
65
|
markViewComponents: markViewComponents,
|
|
81
66
|
markViews: markViews,
|
|
82
67
|
nodeViewComponents: nodeViewComponents,
|
|
83
68
|
nodeViews: nodeViews,
|
|
84
69
|
state: editor.state,
|
|
85
70
|
dispatchTransaction: dispatchTransaction
|
|
86
|
-
}
|
|
71
|
+
}, /*#__PURE__*/ React.createElement(EditorContext.Provider, {
|
|
87
72
|
value: contextValue
|
|
88
73
|
}, /*#__PURE__*/ React.createElement(TiptapEditorContext.Provider, {
|
|
89
74
|
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
|
|
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
|
|
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,19 +1,15 @@
|
|
|
1
|
-
var // @ts-expect-error private property
|
|
2
|
-
_editor;
|
|
3
1
|
import { useEditor } from "@tiptap/react";
|
|
4
2
|
import { StaticEditorView } from "../../StaticEditorView.js";
|
|
5
3
|
import { ReactProseMirror } from "../extensions/ReactProseMirror.js";
|
|
6
4
|
import { ReactProseMirrorCommands } from "../extensions/ReactProseMirrorCommands.js";
|
|
7
5
|
export function useTiptapEditor(options, deps) {
|
|
8
|
-
var ref;
|
|
9
|
-
var _extensions;
|
|
10
6
|
const extensions = [
|
|
11
7
|
ReactProseMirror,
|
|
12
|
-
...
|
|
8
|
+
...options.extensions ?? []
|
|
13
9
|
];
|
|
14
10
|
// If a consumer explicitly disables core extensions (or the Commands core extension)
|
|
15
11
|
// do not re-add our custom Commands
|
|
16
|
-
if (options.enableCoreExtensions === false || typeof options.enableCoreExtensions === "object" &&
|
|
12
|
+
if (options.enableCoreExtensions === false || typeof options.enableCoreExtensions === "object" && options?.enableCoreExtensions?.commands === false) {
|
|
17
13
|
// Do nothing
|
|
18
14
|
} else {
|
|
19
15
|
options.enableCoreExtensions = {
|
|
@@ -27,8 +23,8 @@ export function useTiptapEditor(options, deps) {
|
|
|
27
23
|
extensions,
|
|
28
24
|
element: null
|
|
29
25
|
}, deps);
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
// @ts-expect-error private property
|
|
27
|
+
editor.editorView ??= new StaticEditorView({
|
|
32
28
|
// @ts-expect-error private property
|
|
33
29
|
state: editor.editorState,
|
|
34
30
|
...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 (
|
|
29
|
+
if (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,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 { getAttributesFromExtensions, getRenderedAttributes } from "@tiptap/core";
|
|
16
2
|
import { ReactNodeViewContext, useCurrentEditor } from "@tiptap/react";
|
|
17
3
|
import cx from "classnames";
|
|
@@ -49,16 +35,14 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
49
35
|
* }
|
|
50
36
|
* ```
|
|
51
37
|
*/ export function tiptapNodeView(param) {
|
|
52
|
-
let { component: WrappedComponent
|
|
38
|
+
let { component: WrappedComponent, extension, as, className = "", attrs, contentDOMElementTag: InnerTag = "div", stopEvent, ignoreMutation } = param;
|
|
53
39
|
const TiptapNodeView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function TiptapNodeView(param, ref) {
|
|
54
|
-
let { children
|
|
55
|
-
const { node
|
|
56
|
-
const OuterTag = as
|
|
57
|
-
const { editor
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
var ref2;
|
|
61
|
-
const extensions = (ref2 = extensionManager === null || extensionManager === void 0 ? void 0 : extensionManager.extensions) !== null && ref2 !== void 0 ? ref2 : null;
|
|
40
|
+
let { children, nodeProps, ...props } = param;
|
|
41
|
+
const { node, getPos, decorations, innerDecorations, contentDOMRef } = nodeProps;
|
|
42
|
+
const OuterTag = as ?? (node.type.isInline ? "span" : "div");
|
|
43
|
+
const { editor } = useCurrentEditor();
|
|
44
|
+
const extensionManager = editor?.extensionManager ?? null;
|
|
45
|
+
const extensions = extensionManager?.extensions ?? null;
|
|
62
46
|
const selected = useIsNodeSelected();
|
|
63
47
|
const isDraggingRef = useRef(false);
|
|
64
48
|
const htmlAttributes = useMemo(()=>{
|
|
@@ -95,10 +79,9 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
95
79
|
isDraggingRef.current = nodeView.isDragging;
|
|
96
80
|
return result;
|
|
97
81
|
}
|
|
98
|
-
|
|
99
|
-
const result1 = (ref = nodeView.stopEvent(event)) !== null && ref !== void 0 ? ref : false;
|
|
82
|
+
const result = nodeView.stopEvent(event) ?? false;
|
|
100
83
|
isDraggingRef.current = nodeView.isDragging;
|
|
101
|
-
return
|
|
84
|
+
return result;
|
|
102
85
|
});
|
|
103
86
|
useIgnoreMutation(function(_, mutation) {
|
|
104
87
|
if (ignoreMutation) {
|
|
@@ -121,16 +104,15 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
121
104
|
node,
|
|
122
105
|
view: editor.view
|
|
123
106
|
}, this.dom, this.contentDOM);
|
|
124
|
-
|
|
125
|
-
return (ref = nodeView.ignoreMutation(mutation)) !== null && ref !== void 0 ? ref : false;
|
|
107
|
+
return nodeView.ignoreMutation(mutation) ?? false;
|
|
126
108
|
});
|
|
127
|
-
const { extraClassName
|
|
109
|
+
const { extraClassName, htmlProps } = useMemo(()=>{
|
|
128
110
|
if (!attrs) return {};
|
|
129
111
|
const resolvedAttrs = typeof attrs === "function" ? attrs({
|
|
130
112
|
node,
|
|
131
113
|
HTMLAttributes: htmlAttributes
|
|
132
114
|
}) : attrs;
|
|
133
|
-
const { className: extraClassName
|
|
115
|
+
const { className: extraClassName, ...htmlProps } = htmlAttrsToReactProps(resolvedAttrs);
|
|
134
116
|
return {
|
|
135
117
|
extraClassName,
|
|
136
118
|
htmlProps
|
|
@@ -139,7 +121,7 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
139
121
|
htmlAttributes,
|
|
140
122
|
node
|
|
141
123
|
]);
|
|
142
|
-
const finalClassName = cx("react-renderer",
|
|
124
|
+
const finalClassName = cx("react-renderer", `node-${node.type.name}`, props.className, className, extraClassName, {
|
|
143
125
|
"ProseMirror-selectednode": selected
|
|
144
126
|
});
|
|
145
127
|
const updateAttributes = useEditorEventCallback((_, attributes)=>{
|
|
@@ -147,7 +129,7 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
147
129
|
return;
|
|
148
130
|
}
|
|
149
131
|
editor.commands.command((param)=>{
|
|
150
|
-
let { tr
|
|
132
|
+
let { tr } = param;
|
|
151
133
|
const pos = getPos();
|
|
152
134
|
tr.setNodeMarkup(pos, undefined, {
|
|
153
135
|
...node.attrs,
|
|
@@ -207,11 +189,12 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
207
189
|
if (!editor) return null;
|
|
208
190
|
return /*#__PURE__*/ React.createElement(ReactNodeViewContext.Provider, {
|
|
209
191
|
value: nodeViewContext
|
|
210
|
-
}, /*#__PURE__*/ React.createElement(OuterTag,
|
|
211
|
-
ref: finalRef
|
|
212
|
-
|
|
192
|
+
}, /*#__PURE__*/ React.createElement(OuterTag, {
|
|
193
|
+
ref: finalRef,
|
|
194
|
+
...props,
|
|
195
|
+
...htmlProps,
|
|
213
196
|
className: finalClassName
|
|
214
|
-
}
|
|
197
|
+
}, /*#__PURE__*/ React.createElement(WrappedComponent, {
|
|
215
198
|
node: node,
|
|
216
199
|
getPos: getPos,
|
|
217
200
|
view: editor.view,
|
|
@@ -225,7 +208,6 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
|
|
|
225
208
|
deleteNode: deleteNode
|
|
226
209
|
})));
|
|
227
210
|
}));
|
|
228
|
-
|
|
229
|
-
TiptapNodeView.displayName = "TiptapNodeView(".concat((_displayName = WrappedComponent.displayName) !== null && _displayName !== void 0 ? _displayName : "Anonymous", ")");
|
|
211
|
+
TiptapNodeView.displayName = `TiptapNodeView(${WrappedComponent.displayName ?? "Anonymous"})`;
|
|
230
212
|
return TiptapNodeView;
|
|
231
213
|
}
|