Skip to content

Commit 42dca83

Browse files
author
Rajat
committed
Fixed deps
1 parent 0cddc18 commit 42dca83

7 files changed

Lines changed: 2290 additions & 330 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"test:watch": "NODE_OPTIONS='--experimental-vm-modules' SUPPRESS_JEST_WARNINGS=1 jest --watch",
2929
"test:coverage": "NODE_OPTIONS='--experimental-vm-modules' SUPPRESS_JEST_WARNINGS=1 jest --coverage"
3030
},
31-
"packageManager": "pnpm@10.17.0+sha512.fce8a3dd29a4ed2ec566fb53efbb04d8c44a0f05bc6f24a73046910fb9c3ce7afa35a0980500668fa3573345bd644644fa98338fa168235c80f4aa17aa17fbef",
31+
"packageManager": "pnpm@10.22.0+sha512.bf049efe995b28f527fd2b41ae0474ce29186f7edcb3bf545087bd61fbbebb2bf75362d1307fda09c2d288e1e499787ac12d4fcb617a974718a6051f2eee741c",
3232
"devDependencies": {
3333
"@testing-library/dom": "^10.4.0",
3434
"@testing-library/jest-dom": "^6.6.3",

packages/text-editor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"@tiptap/extension-image": "^3.0.0",
6262
"@tiptap/extension-link": "^3.0.0",
6363
"@tiptap/extension-placeholder": "^3.0.0",
64-
"@tiptap/extension-table": "^3.0.0",
64+
"@tiptap/extension-table": "^3.10.7",
6565
"@tiptap/react": "^3.0.0",
6666
"@tiptap/starter-kit": "^3.0.0",
6767
"highlight.js": "^11.10.0",

packages/text-editor/src/BubbleMenu.tsx

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import React, { useCallback, useEffect, useState } from "react";
1+
import React, { useCallback, useEffect, useRef, useState } from "react";
22
import type { Editor } from "@tiptap/core";
3-
import { BubbleMenu as TipTapBubbleMenu } from "@tiptap/react";
3+
import type { BubbleMenuPluginProps } from "@tiptap/extension-bubble-menu";
4+
import { BubbleMenuPlugin } from "@tiptap/extension-bubble-menu";
45
import {
56
Bold,
67
Code,
@@ -18,6 +19,73 @@ interface BubbleMenuProps {
1819
const buttonBase =
1920
"inline-flex h-8 w-8 items-center justify-center rounded text-foreground transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
2021

22+
type TipTapBubbleMenuProps = {
23+
editor: Editor | null;
24+
className?: string;
25+
children: React.ReactNode;
26+
pluginKey?: string;
27+
} & Partial<Omit<BubbleMenuPluginProps, "editor" | "element" | "pluginKey">>;
28+
29+
const TipTapBubbleMenu = ({
30+
editor,
31+
className,
32+
children,
33+
pluginKey = "inlineBubbleMenu",
34+
updateDelay,
35+
resizeDelay,
36+
shouldShow,
37+
appendTo,
38+
getReferencedVirtualElement,
39+
options,
40+
}: TipTapBubbleMenuProps): JSX.Element => {
41+
const menuRef = useRef<HTMLDivElement | null>(null);
42+
43+
useEffect(() => {
44+
const element = menuRef.current;
45+
46+
if (!editor || editor.isDestroyed || !element) {
47+
return;
48+
}
49+
50+
const plugin = BubbleMenuPlugin({
51+
editor,
52+
element,
53+
pluginKey,
54+
updateDelay,
55+
resizeDelay,
56+
shouldShow: shouldShow ?? null,
57+
appendTo,
58+
getReferencedVirtualElement,
59+
options,
60+
});
61+
62+
editor.registerPlugin(plugin);
63+
64+
return () => {
65+
editor.unregisterPlugin(pluginKey);
66+
};
67+
}, [
68+
editor,
69+
pluginKey,
70+
updateDelay,
71+
resizeDelay,
72+
shouldShow,
73+
appendTo,
74+
getReferencedVirtualElement,
75+
options,
76+
]);
77+
78+
return (
79+
<div
80+
ref={menuRef}
81+
className={className}
82+
style={{ visibility: "hidden" }}
83+
>
84+
{children}
85+
</div>
86+
);
87+
};
88+
2189
function InlineButton({
2290
icon: Icon,
2391
label,

packages/text-editor/src/Renderer/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ const Renderer = ({ json, fontFamily, className }: RendererProps) => {
4444

4545
if (serializedContentRef.current !== nextSerialized) {
4646
serializedContentRef.current = nextSerialized;
47-
editor.commands.setContent(json ?? emptyDoc, false);
47+
editor.commands.setContent(json ?? emptyDoc, {
48+
emitUpdate: false,
49+
});
4850
}
4951
}, [editor, json]);
5052

packages/text-editor/src/WysiwygEditor.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,18 @@ const WysiwygEditor: WysiwygEditorType = Object.assign(
123123
refreshRef.current = refresh;
124124
hasInteractedRef.current = false;
125125
lastSerializedContentRef.current = nextSerialized;
126-
editor.commands.setContent(nextContent, false);
126+
editor.commands.setContent(nextContent, {
127+
emitUpdate: false,
128+
});
127129
return;
128130
}
129131

130132
if (!hasInteractedRef.current) {
131133
if (lastSerializedContentRef.current !== nextSerialized) {
132134
lastSerializedContentRef.current = nextSerialized;
133-
editor.commands.setContent(nextContent, false);
135+
editor.commands.setContent(nextContent, {
136+
emitUpdate: false,
137+
});
134138
}
135139
return;
136140
}

packages/text-editor/src/extensions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import StarterKit from "@tiptap/starter-kit";
22
import Placeholder from "@tiptap/extension-placeholder";
33
import Link from "@tiptap/extension-link";
4-
import Table from "@tiptap/extension-table";
5-
import TableRow from "@tiptap/extension-table-row";
6-
import TableCell from "@tiptap/extension-table-cell";
7-
import TableHeader from "@tiptap/extension-table-header";
4+
import {
5+
Table,
6+
TableCell,
7+
TableHeader,
8+
TableRow,
9+
} from "@tiptap/extension-table";
810
import Image from "@tiptap/extension-image";
911
import Dropcursor from "@tiptap/extension-dropcursor";
1012
import Gapcursor from "@tiptap/extension-gapcursor";

0 commit comments

Comments
 (0)