Skip to content

Commit d3e3eea

Browse files
authored
Add note mention in tiptap editor (#813)
1 parent 7c8cf1c commit d3e3eea

File tree

13 files changed

+911
-488
lines changed

13 files changed

+911
-488
lines changed

apps/app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"start": "vite"
1212
},
1313
"devDependencies": {
14-
"@clerk/types": "^4.58.0",
14+
"@clerk/types": "^4.59.0",
1515
"@hypr/client": "workspace:^",
1616
"@tailwindcss/typography": "^0.5.16",
1717
"@tanstack/router-plugin": "^1.120.3",
@@ -26,7 +26,7 @@
2626
"vite": "^6.3.5"
2727
},
2828
"dependencies": {
29-
"@clerk/clerk-react": "^5.31.2",
29+
"@clerk/clerk-react": "^5.31.4",
3030
"@hypr/tiptap": "workspace:^",
3131
"@hypr/ui": "workspace:^",
3232
"@hypr/utils": "workspace:^",

apps/desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"@mux/mux-player": "^3.4.0",
9393
"@tanstack/router-plugin": "^1.120.3",
9494
"@tauri-apps/cli": "^2.5.0",
95-
"@types/node": "^22.15.17",
95+
"@types/node": "^22.15.18",
9696
"@types/react": "^18.3.21",
9797
"@types/react-dom": "^18.3.7",
9898
"@types/react-grid-layout": "^1.3.5",

apps/desktop/src/components/editor-area/index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default function EditorArea({
2929
sessionId: string;
3030
}) {
3131
const showRaw = useSession(sessionId, (s) => s.showRaw);
32+
const { userId } = useHypr();
3233

3334
const [rawContent, setRawContent] = useSession(sessionId, (s) => [
3435
s.session?.raw_memo_html ?? "",
@@ -90,6 +91,16 @@ export default function EditorArea({
9091
}
9192
}, []);
9293

94+
const handleMentionSearch = async (query: string) => {
95+
const session = await dbCommands.listSessions({ type: "search", query, user_id: userId, limit: 5 });
96+
97+
return session.map((s) => ({
98+
id: s.id,
99+
type: "note",
100+
label: s.title,
101+
}));
102+
};
103+
93104
return (
94105
<div className="relative flex h-full flex-col w-full">
95106
<NoteHeader
@@ -120,6 +131,10 @@ export default function EditorArea({
120131
initialContent={noteContent}
121132
editable={enhance.status !== "pending"}
122133
setContentFromOutside={!showRaw && enhance.status === "pending"}
134+
mentionConfig={{
135+
trigger: "@",
136+
handleSearch: handleMentionSearch,
137+
}}
123138
/>
124139
)
125140
: <Renderer ref={editorRef} initialContent={noteContent} />}

apps/desktop/src/routes/__root.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export const Route = createRootRouteWithContext<Required<Context>>()({
1919

2020
const POSITION = "bottom-right";
2121

22+
declare global {
23+
interface Window {
24+
__HYPR_NAVIGATE__?: (to: string) => void;
25+
}
26+
}
27+
2228
function Component() {
2329
const navigate = useNavigate();
2430

@@ -32,6 +38,16 @@ function Component() {
3238
refetchInterval: 1000,
3339
});
3440

41+
useEffect(() => {
42+
window.__HYPR_NAVIGATE__ = (to: string) => {
43+
navigate({ to });
44+
};
45+
46+
return () => {
47+
window.__HYPR_NAVIGATE__ = undefined;
48+
};
49+
}, [navigate]);
50+
3551
useEffect(() => {
3652
let unlisten: (() => void) | undefined;
3753

apps/docs/data/i18n.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[
22
{
33
"language": "ko",
4-
"total": 267,
5-
"missing": 267
4+
"total": 246,
5+
"missing": 246
66
},
77
{
88
"language": "en (source)",
9-
"total": 267,
9+
"total": 246,
1010
"missing": 0
1111
}
1212
]

apps/docs/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
},
99
"devDependencies": {
1010
"@iconify-json/heroicons": "^1.2.2",
11-
"@unocss/preset-icons": "^66.1.1",
12-
"@unocss/preset-wind3": "^66.1.1",
11+
"@unocss/preset-icons": "^66.1.2",
12+
"@unocss/preset-wind3": "^66.1.2",
1313
"isomorphic-git": "^1.30.1",
1414
"octokit": "^4.1.3",
1515
"typedoc": "^0.27.9",
16-
"unocss": "^66.1.1",
16+
"unocss": "^66.1.2",
1717
"vite-plugin-posthog": "^2.1.0",
1818
"vitepress": "2.0.0-alpha.5",
19-
"vue": "^3.5.13",
19+
"vue": "^3.5.14",
2020
"zod": "^3.24.4"
2121
},
2222
"dependencies": {
2323
"@tanstack/vue-table": "^8.21.3",
2424
"clsx": "^2.1.1",
2525
"floating-vue": "^5.2.2",
26-
"posthog-js": "^1.242.0",
26+
"posthog-js": "^1.242.2",
2727
"react": "^18.3.1",
2828
"react-dom": "^18.3.1"
2929
}

packages/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@hey-api/openapi-ts": "^0.64.15"
1616
},
1717
"dependencies": {
18-
"@hey-api/client-fetch": "^0.10.0",
18+
"@hey-api/client-fetch": "^0.10.1",
1919
"@tanstack/react-query": "^5.76.1"
2020
}
2121
}

packages/tiptap/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"react-dom": "^18.3.1"
1515
},
1616
"dependencies": {
17+
"@floating-ui/dom": "^1.7.0",
1718
"@hypr/ui": "workspace:^",
1819
"@remixicon/react": "^4.6.0",
1920
"@sereneinserenade/tiptap-search-and-replace": "^0.1.1",
@@ -24,6 +25,7 @@
2425
"@tiptap/extension-image": "^2.12.0",
2526
"@tiptap/extension-link": "^2.12.0",
2627
"@tiptap/extension-list-keymap": "^2.12.0",
28+
"@tiptap/extension-mention": "^2.12.0",
2729
"@tiptap/extension-placeholder": "^2.12.0",
2830
"@tiptap/extension-strike": "^2.12.0",
2931
"@tiptap/extension-task-item": "^2.12.0",
@@ -34,14 +36,15 @@
3436
"@tiptap/pm": "^2.12.0",
3537
"@tiptap/react": "^2.12.0",
3638
"@tiptap/starter-kit": "^2.12.0",
39+
"@tiptap/suggestion": "^2.12.0",
3740
"clsx": "^2.1.1",
3841
"prosemirror-commands": "^1.7.1",
3942
"prosemirror-state": "^1.4.3",
4043
"tippy.js": "^6.3.7",
4144
"turndown": "^7.2.0"
4245
},
4346
"devDependencies": {
44-
"@types/node": "^22.15.17",
47+
"@types/node": "^22.15.18",
4548
"@types/react": "^18.3.21",
4649
"@types/react-dom": "^18.3.7",
4750
"@types/turndown": "^5.0.5"

packages/tiptap/src/editor/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import "../styles/tiptap.css";
2+
import "../styles/mention.css";
23

34
import { type Editor as TiptapEditor, EditorContent, type HTMLContent, useEditor } from "@tiptap/react";
45
import { forwardRef, useEffect, useRef } from "react";
56

67
import * as shared from "../shared";
8+
import { mention, type MentionConfig } from "./mention";
79

810
export type { TiptapEditor };
911

@@ -12,10 +14,11 @@ interface EditorProps {
1214
initialContent: HTMLContent;
1315
editable?: boolean;
1416
setContentFromOutside?: boolean;
17+
mentionConfig: MentionConfig;
1518
}
1619

1720
const Editor = forwardRef<{ editor: TiptapEditor | null }, EditorProps>(
18-
({ handleChange, initialContent, editable = true, setContentFromOutside = false }, ref) => {
21+
({ handleChange, initialContent, editable = true, setContentFromOutside = false, mentionConfig }, ref) => {
1922
const previousContentRef = useRef<HTMLContent>(initialContent);
2023

2124
const onUpdate = ({ editor }: { editor: TiptapEditor }) => {
@@ -27,7 +30,10 @@ const Editor = forwardRef<{ editor: TiptapEditor | null }, EditorProps>(
2730
};
2831

2932
const editor = useEditor({
30-
extensions: shared.extensions,
33+
extensions: [
34+
...shared.extensions,
35+
mention(mentionConfig),
36+
],
3137
editable,
3238
content: initialContent || "<p></p>",
3339
onCreate: ({ editor }) => {

0 commit comments

Comments
 (0)