@tiptap/react 3.0.0-next.2 → 3.0.0-next.4
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/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +72 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -26
- package/dist/index.d.ts +24 -26
- package/dist/index.js +72 -119
- package/dist/index.js.map +1 -1
- package/package.json +18 -14
- package/src/BubbleMenu.tsx +7 -32
- package/src/Context.tsx +9 -13
- package/src/Editor.ts +5 -5
- package/src/EditorContent.tsx +8 -18
- package/src/FloatingMenu.tsx +49 -64
- package/src/NodeViewContent.tsx +12 -9
- package/src/NodeViewWrapper.tsx +2 -2
- package/src/ReactNodeViewRenderer.tsx +22 -35
- package/src/ReactRenderer.tsx +16 -25
- package/src/useEditor.ts +11 -20
- package/src/useEditorState.ts +14 -19
- package/src/useReactNodeView.ts +20 -5
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024, Tiptap GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
# @tiptap/react
|
|
2
|
+
|
|
2
3
|
[](https://www.npmjs.com/package/@tiptap/react)
|
|
3
4
|
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
4
5
|
[](https://www.npmjs.com/package/@tiptap/react)
|
|
5
6
|
[](https://github.com/sponsors/ueberdosis)
|
|
6
7
|
|
|
7
8
|
## Introduction
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as _New York Times_, _The Guardian_ or _Atlassian_.
|
|
9
11
|
|
|
10
12
|
## Official Documentation
|
|
13
|
+
|
|
11
14
|
Documentation can be found on the [Tiptap website](https://tiptap.dev).
|
|
12
15
|
|
|
13
16
|
## License
|
|
17
|
+
|
|
14
18
|
Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
package/dist/index.cjs
CHANGED
|
@@ -29,8 +29,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
30
|
|
|
31
31
|
// src/index.ts
|
|
32
|
-
var
|
|
33
|
-
__export(
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
34
|
BubbleMenu: () => BubbleMenu,
|
|
35
35
|
EditorConsumer: () => EditorConsumer,
|
|
36
36
|
EditorContent: () => EditorContent,
|
|
@@ -41,6 +41,7 @@ __export(src_exports, {
|
|
|
41
41
|
NodeViewWrapper: () => NodeViewWrapper,
|
|
42
42
|
PureEditorContent: () => PureEditorContent,
|
|
43
43
|
ReactNodeView: () => ReactNodeView,
|
|
44
|
+
ReactNodeViewContentProvider: () => ReactNodeViewContentProvider,
|
|
44
45
|
ReactNodeViewContext: () => ReactNodeViewContext,
|
|
45
46
|
ReactNodeViewRenderer: () => ReactNodeViewRenderer,
|
|
46
47
|
ReactRenderer: () => ReactRenderer,
|
|
@@ -49,7 +50,7 @@ __export(src_exports, {
|
|
|
49
50
|
useEditorState: () => useEditorState,
|
|
50
51
|
useReactNodeView: () => useReactNodeView
|
|
51
52
|
});
|
|
52
|
-
module.exports = __toCommonJS(
|
|
53
|
+
module.exports = __toCommonJS(index_exports);
|
|
53
54
|
|
|
54
55
|
// src/BubbleMenu.tsx
|
|
55
56
|
var import_extension_bubble_menu = require("@tiptap/extension-bubble-menu");
|
|
@@ -69,14 +70,13 @@ var mergeRefs = (...refs) => {
|
|
|
69
70
|
if (typeof ref === "function") {
|
|
70
71
|
ref(node);
|
|
71
72
|
} else if (ref) {
|
|
73
|
+
;
|
|
72
74
|
ref.current = node;
|
|
73
75
|
}
|
|
74
76
|
});
|
|
75
77
|
};
|
|
76
78
|
};
|
|
77
|
-
var Portals = ({
|
|
78
|
-
contentComponent
|
|
79
|
-
}) => {
|
|
79
|
+
var Portals = ({ contentComponent }) => {
|
|
80
80
|
const renderers = (0, import_shim.useSyncExternalStore)(
|
|
81
81
|
contentComponent.subscribe,
|
|
82
82
|
contentComponent.getSnapshot,
|
|
@@ -556,16 +556,7 @@ function EditorProvider({
|
|
|
556
556
|
|
|
557
557
|
// src/BubbleMenu.tsx
|
|
558
558
|
var BubbleMenu = import_react6.default.forwardRef(
|
|
559
|
-
({
|
|
560
|
-
pluginKey = "bubbleMenu",
|
|
561
|
-
editor,
|
|
562
|
-
updateDelay,
|
|
563
|
-
resizeDelay,
|
|
564
|
-
shouldShow = null,
|
|
565
|
-
options,
|
|
566
|
-
children,
|
|
567
|
-
...restProps
|
|
568
|
-
}, ref) => {
|
|
559
|
+
({ pluginKey = "bubbleMenu", editor, updateDelay, resizeDelay, shouldShow = null, options, children, ...restProps }, ref) => {
|
|
569
560
|
const menuEl = (0, import_react6.useRef)(document.createElement("div"));
|
|
570
561
|
if (typeof ref === "function") {
|
|
571
562
|
ref(menuEl.current);
|
|
@@ -582,9 +573,7 @@ var BubbleMenu = import_react6.default.forwardRef(
|
|
|
582
573
|
}
|
|
583
574
|
const attachToEditor = editor || currentEditor;
|
|
584
575
|
if (!attachToEditor) {
|
|
585
|
-
console.warn(
|
|
586
|
-
"BubbleMenu component is not rendered inside of an editor component or does not have editor prop."
|
|
587
|
-
);
|
|
576
|
+
console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");
|
|
588
577
|
return;
|
|
589
578
|
}
|
|
590
579
|
const plugin = (0, import_extension_bubble_menu.BubbleMenuPlugin)({
|
|
@@ -606,16 +595,7 @@ var BubbleMenu = import_react6.default.forwardRef(
|
|
|
606
595
|
});
|
|
607
596
|
};
|
|
608
597
|
}, [editor, currentEditor]);
|
|
609
|
-
return (0, import_react_dom2.createPortal)(
|
|
610
|
-
/* @__PURE__ */ import_react6.default.createElement(
|
|
611
|
-
"div",
|
|
612
|
-
{
|
|
613
|
-
...restProps
|
|
614
|
-
},
|
|
615
|
-
children
|
|
616
|
-
),
|
|
617
|
-
menuEl.current
|
|
618
|
-
);
|
|
598
|
+
return (0, import_react_dom2.createPortal)(/* @__PURE__ */ import_react6.default.createElement("div", { ...restProps }, children), menuEl.current);
|
|
619
599
|
}
|
|
620
600
|
);
|
|
621
601
|
|
|
@@ -623,63 +603,49 @@ var BubbleMenu = import_react6.default.forwardRef(
|
|
|
623
603
|
var import_extension_floating_menu = require("@tiptap/extension-floating-menu");
|
|
624
604
|
var import_react7 = __toESM(require("react"), 1);
|
|
625
605
|
var import_react_dom3 = require("react-dom");
|
|
626
|
-
var FloatingMenu = import_react7.default.forwardRef(
|
|
627
|
-
pluginKey = "floatingMenu",
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
}, ref) => {
|
|
634
|
-
const menuEl = (0, import_react7.useRef)(document.createElement("div"));
|
|
635
|
-
if (typeof ref === "function") {
|
|
636
|
-
ref(menuEl.current);
|
|
637
|
-
} else if (ref) {
|
|
638
|
-
ref.current = menuEl.current;
|
|
639
|
-
}
|
|
640
|
-
const { editor: currentEditor } = useCurrentEditor();
|
|
641
|
-
(0, import_react7.useEffect)(() => {
|
|
642
|
-
const floatingMenuElement = menuEl.current;
|
|
643
|
-
floatingMenuElement.style.visibility = "hidden";
|
|
644
|
-
floatingMenuElement.style.position = "absolute";
|
|
645
|
-
if ((editor == null ? void 0 : editor.isDestroyed) || (currentEditor == null ? void 0 : currentEditor.isDestroyed)) {
|
|
646
|
-
return;
|
|
647
|
-
}
|
|
648
|
-
const attachToEditor = editor || currentEditor;
|
|
649
|
-
if (!attachToEditor) {
|
|
650
|
-
console.warn(
|
|
651
|
-
"FloatingMenu component is not rendered inside of an editor component or does not have editor prop."
|
|
652
|
-
);
|
|
653
|
-
return;
|
|
606
|
+
var FloatingMenu = import_react7.default.forwardRef(
|
|
607
|
+
({ pluginKey = "floatingMenu", editor, shouldShow = null, options, children, ...restProps }, ref) => {
|
|
608
|
+
const menuEl = (0, import_react7.useRef)(document.createElement("div"));
|
|
609
|
+
if (typeof ref === "function") {
|
|
610
|
+
ref(menuEl.current);
|
|
611
|
+
} else if (ref) {
|
|
612
|
+
ref.current = menuEl.current;
|
|
654
613
|
}
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
attachToEditor
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
614
|
+
const { editor: currentEditor } = useCurrentEditor();
|
|
615
|
+
(0, import_react7.useEffect)(() => {
|
|
616
|
+
const floatingMenuElement = menuEl.current;
|
|
617
|
+
floatingMenuElement.style.visibility = "hidden";
|
|
618
|
+
floatingMenuElement.style.position = "absolute";
|
|
619
|
+
if ((editor == null ? void 0 : editor.isDestroyed) || (currentEditor == null ? void 0 : currentEditor.isDestroyed)) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
const attachToEditor = editor || currentEditor;
|
|
623
|
+
if (!attachToEditor) {
|
|
624
|
+
console.warn(
|
|
625
|
+
"FloatingMenu component is not rendered inside of an editor component or does not have editor prop."
|
|
626
|
+
);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
const plugin = (0, import_extension_floating_menu.FloatingMenuPlugin)({
|
|
630
|
+
editor: attachToEditor,
|
|
631
|
+
element: floatingMenuElement,
|
|
632
|
+
pluginKey,
|
|
633
|
+
shouldShow,
|
|
634
|
+
options
|
|
669
635
|
});
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
)
|
|
680
|
-
menuEl.current
|
|
681
|
-
|
|
682
|
-
|
|
636
|
+
attachToEditor.registerPlugin(plugin);
|
|
637
|
+
return () => {
|
|
638
|
+
attachToEditor.unregisterPlugin(pluginKey);
|
|
639
|
+
window.requestAnimationFrame(() => {
|
|
640
|
+
if (floatingMenuElement.parentNode) {
|
|
641
|
+
floatingMenuElement.parentNode.removeChild(floatingMenuElement);
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
};
|
|
645
|
+
}, [editor, currentEditor]);
|
|
646
|
+
return (0, import_react_dom3.createPortal)(/* @__PURE__ */ import_react7.default.createElement("div", { ...restProps }, children), menuEl.current);
|
|
647
|
+
}
|
|
648
|
+
);
|
|
683
649
|
|
|
684
650
|
// src/NodeViewContent.tsx
|
|
685
651
|
var import_react9 = __toESM(require("react"), 1);
|
|
@@ -687,14 +653,23 @@ var import_react9 = __toESM(require("react"), 1);
|
|
|
687
653
|
// src/useReactNodeView.ts
|
|
688
654
|
var import_react8 = require("react");
|
|
689
655
|
var ReactNodeViewContext = (0, import_react8.createContext)({
|
|
690
|
-
onDragStart:
|
|
656
|
+
onDragStart: () => {
|
|
657
|
+
},
|
|
658
|
+
nodeViewContentChildren: void 0,
|
|
659
|
+
nodeViewContentRef: () => {
|
|
660
|
+
}
|
|
691
661
|
});
|
|
662
|
+
var ReactNodeViewContentProvider = ({ children, content }) => {
|
|
663
|
+
return (0, import_react8.createElement)(ReactNodeViewContext.Provider, { value: { nodeViewContentChildren: content } }, children);
|
|
664
|
+
};
|
|
692
665
|
var useReactNodeView = () => (0, import_react8.useContext)(ReactNodeViewContext);
|
|
693
666
|
|
|
694
667
|
// src/NodeViewContent.tsx
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
668
|
+
function NodeViewContent({
|
|
669
|
+
as: Tag = "div",
|
|
670
|
+
...props
|
|
671
|
+
}) {
|
|
672
|
+
const { nodeViewContentRef, nodeViewContentChildren } = useReactNodeView();
|
|
698
673
|
return (
|
|
699
674
|
// @ts-ignore
|
|
700
675
|
/* @__PURE__ */ import_react9.default.createElement(
|
|
@@ -707,10 +682,11 @@ var NodeViewContent = (props) => {
|
|
|
707
682
|
whiteSpace: "pre-wrap",
|
|
708
683
|
...props.style
|
|
709
684
|
}
|
|
710
|
-
}
|
|
685
|
+
},
|
|
686
|
+
nodeViewContentChildren
|
|
711
687
|
)
|
|
712
688
|
);
|
|
713
|
-
}
|
|
689
|
+
}
|
|
714
690
|
|
|
715
691
|
// src/NodeViewWrapper.tsx
|
|
716
692
|
var import_react10 = __toESM(require("react"), 1);
|
|
@@ -753,12 +729,7 @@ var ReactRenderer = class {
|
|
|
753
729
|
/**
|
|
754
730
|
* Immediately creates element and renders the provided React component.
|
|
755
731
|
*/
|
|
756
|
-
constructor(component, {
|
|
757
|
-
editor,
|
|
758
|
-
props = {},
|
|
759
|
-
as = "div",
|
|
760
|
-
className = ""
|
|
761
|
-
}) {
|
|
732
|
+
constructor(component, { editor, props = {}, as = "div", className = "" }) {
|
|
762
733
|
this.ref = null;
|
|
763
734
|
this.id = Math.floor(Math.random() * 4294967295).toString();
|
|
764
735
|
this.component = component;
|
|
@@ -855,11 +826,9 @@ var ReactNodeView = class extends import_core2.NodeView {
|
|
|
855
826
|
};
|
|
856
827
|
const context = { onDragStart, nodeViewContentRef };
|
|
857
828
|
const Component = this.component;
|
|
858
|
-
const ReactNodeViewProvider = import_react12.default.memo(
|
|
859
|
-
(componentProps)
|
|
860
|
-
|
|
861
|
-
}
|
|
862
|
-
);
|
|
829
|
+
const ReactNodeViewProvider = import_react12.default.memo((componentProps) => {
|
|
830
|
+
return /* @__PURE__ */ import_react12.default.createElement(ReactNodeViewContext.Provider, { value: context }, import_react12.default.createElement(Component, componentProps));
|
|
831
|
+
});
|
|
863
832
|
ReactNodeViewProvider.displayName = "ReactNodeView";
|
|
864
833
|
if (this.node.isLeaf) {
|
|
865
834
|
this.contentDOMElement = null;
|
|
@@ -1026,7 +995,7 @@ function ReactNodeViewRenderer(component, options) {
|
|
|
1026
995
|
}
|
|
1027
996
|
|
|
1028
997
|
// src/index.ts
|
|
1029
|
-
__reExport(
|
|
998
|
+
__reExport(index_exports, require("@tiptap/core"), module.exports);
|
|
1030
999
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1031
1000
|
0 && (module.exports = {
|
|
1032
1001
|
BubbleMenu,
|
|
@@ -1039,6 +1008,7 @@ __reExport(src_exports, require("@tiptap/core"), module.exports);
|
|
|
1039
1008
|
NodeViewWrapper,
|
|
1040
1009
|
PureEditorContent,
|
|
1041
1010
|
ReactNodeView,
|
|
1011
|
+
ReactNodeViewContentProvider,
|
|
1042
1012
|
ReactNodeViewContext,
|
|
1043
1013
|
ReactNodeViewRenderer,
|
|
1044
1014
|
ReactRenderer,
|