Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(web): open note links from the infographic companion sidebar

tianma-iff167530c5984
diff --git a/apps/web/src/components/InfographicEditorPane.tsx b/apps/web/src/components/InfographicEditorPane.tsx
index 2e041c66..cae1b374 100644
--- a/apps/web/src/components/InfographicEditorPane.tsx
+++ b/apps/web/src/components/InfographicEditorPane.tsx
@@ -42,6 +42,7 @@ type Props = {
onToggleDesktopFocusMode: () => void;
aiAssistantOpenToken: number;
shortcutSettings: ShortcutSettings;
+ onOpenCompanionNote?: (id: string, notebookId: string) => void;
};
const plainLine = (value: string) => value.replace(/\s+/g, " ").trim();
@@ -197,6 +198,7 @@ export default function InfographicEditorPane({
onToggleDesktopFocusMode,
aiAssistantOpenToken,
shortcutSettings,
+ onOpenCompanionNote,
}: Props) {
const { t, i18n } = useTranslation();
const parsed = useMemo(() => parseInfographicDocument(memo.contentMarkdown), [memo.contentMarkdown]);
@@ -785,6 +787,7 @@ export default function InfographicEditorPane({
notebookId={memo.notebookId}
noteTitle={title}
infographic={infographicAssistant}
+ onOpenCompanionNote={onOpenCompanionNote}
/>
</AiSidebarErrorBoundary>
<Dialog open={galleryDialogOpen} onOpenChange={setGalleryDialogOpen}>
diff --git a/apps/web/src/components/WorkspaceApp.tsx b/apps/web/src/components/WorkspaceApp.tsx
index 725b9653..97d030e4 100644
--- a/apps/web/src/components/WorkspaceApp.tsx
+++ b/apps/web/src/components/WorkspaceApp.tsx
@@ -3576,6 +3576,7 @@ export const WorkspaceApp = ({
onToggleDesktopFocusMode={toggleDesktopFocusMode}
aiAssistantOpenToken={noteAiAssistantOpenToken}
shortcutSettings={shortcutSettings}
+ onOpenCompanionNote={handleOpenPluginNote}
onSaved={async (memo) => {
await putLocalMemo(localDataScope, memo);
cacheMemoDetail(queryClient, memo, memoView);
diff --git a/apps/web/src/components/ai-sidebar/AiSidebar.tsx b/apps/web/src/components/ai-sidebar/AiSidebar.tsx
index 83dfc11c..11aca06c 100644
--- a/apps/web/src/components/ai-sidebar/AiSidebar.tsx
+++ b/apps/web/src/components/ai-sidebar/AiSidebar.tsx
@@ -4,7 +4,7 @@ import * as m from "motion/react-m";
import { useTranslation } from "react-i18next";
import { Check, ChevronDown, Download, FileText, Loader2, PanelRightClose, Paperclip, Plus, Search, Sparkles, X } from "lucide-react";
import type { CompanionAction, CompanionAnswer, CompanionEvent, CompanionTurn, CompanionTurnInput } from "@edgeever/shared";
-import { buildRevisionDiffRows, createMemoLinkHref, parseMemoLinkHref } from "@edgeever/shared";
+import { buildRevisionDiffRows, createMemoLinkHref } from "@edgeever/shared";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
@@ -84,6 +84,7 @@ import { AiSidebarMessage } from "./AiSidebarMessage";
import { AiSidebarLocalProcess } from "./AiSidebarLocalProcess";
import { BuiltinAgentStatus } from "./BuiltinAgentStatus";
import { InfographicSidebarSession, type InfographicSidebarController } from "./InfographicSidebarSession";
+import { memoIdFromSidebarLinkEvent } from "./sidebar-note-links";
const SIDEBAR_DEFAULT_WIDTH = 380;
const sidebarThreadClassName = cn(
@@ -1422,15 +1423,9 @@ function AiSidebarSession({
};
const openLinkedNote = (event: MouseEvent<HTMLElement>, sources: Array<{ id: string; notebookId?: string }>) => {
- const target = event.target;
- if (!(target instanceof Element) || !onOpenCompanionNote) return;
- const link = target.closest("a");
- if (!(link instanceof HTMLAnchorElement)) return;
- const linkedId = parseMemoLinkHref(link.getAttribute("href"))
- ?? parseMemoLinkHref(link.hash)
- ?? parseMemoLinkHref(link.href);
+ if (!onOpenCompanionNote) return;
+ const linkedId = memoIdFromSidebarLinkEvent(event);
if (!linkedId) return;
- event.preventDefault();
onOpenCompanionNote(linkedId, sources.find((item) => item.id === linkedId)?.notebookId ?? "");
};
@@ -1784,18 +1779,14 @@ export function AiSidebar(props: AiSidebarProps) {
</AnimatePresence>
<m.aside
initial={false}
- animate={narrow ? { x: open ? 0 : "100%" } : { x: 0 }}
+ animate={narrow ? { x: open ? 0 : "100%", width: panelWidth } : { x: 0, width: open ? width : 0 }}
transition={resizing ? { duration: 0 } : sidebarRevealTransition}
aria-hidden={!open}
aria-label={t("aiAssistant.sidebar.title")}
inert={open ? undefined : true}
- style={{ width: narrow ? panelWidth : (open ? width : 0) }}
className={cn(
"h-full min-h-0 min-w-0 shrink-0 overflow-hidden bg-card",
- narrow
- ? "fixed inset-y-0 right-0 z-50 shadow-xl"
- : "relative transition-[width] duration-[320ms] ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",
- !narrow && resizing && "transition-none",
+ narrow ? "fixed inset-y-0 right-0 z-50 shadow-xl" : "relative",
)}
onDragOverCapture={(event) => {
if (event.dataTransfer?.types?.includes("Files")) event.preventDefault();
@@ -1841,6 +1832,7 @@ export function AiSidebar(props: AiSidebarProps) {
session={props.infographic}
noteTitle={props.noteTitle}
onOpenChange={onOpenChange}
+ onOpenNote={props.onOpenCompanionNote}
/>
) : (
<AiSidebarSession {...props} addFilesRef={addFilesRef} onStopReady={onStopReady} />
diff --git a/apps/web/src/components/ai-sidebar/InfographicSidebarSession.test.mjs b/apps/web/src/components/ai-sidebar/InfographicSidebarSession.test.mjs
new file mode 100644
index 00000000..d84e8ef5
--- /dev/null
+++ b/apps/web/src/components/ai-sidebar/InfographicSidebarSession.test.mjs
@@ -0,0 +1,62 @@
+import { describe, expect, test } from "bun:test";
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { createInstance } from "i18next";
+import { I18nextProvider } from "react-i18next";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { zhCN } from "../../../../../packages/shared/src/i18n/zh-CN.ts";
+import { InfographicSidebarSession } from "./InfographicSidebarSession.tsx";
+
+const queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false, enabled: false } },
+});
+
+const session = {
+ turns: [{
+ id: "turn-1",
+ prompt: "做成信息图",
+ createdAt: "2026-10-02T00:00:00.000Z",
+ kind: "generated",
+ resultTitle: "里程碑",
+ response: "相关笔记:[演进里程碑](#memo=memo_demo_infographic)\n\n详见 [文档](https://example.com/docs)。",
+ }],
+ activeTurn: {
+ prompt: "再补一张",
+ response: "见 [流程图](#memo=memo_03de025fc0134b7da0d155c2c1686b92)",
+ },
+ generating: false,
+ readOnly: true,
+ canUndo: false,
+ hasGraphic: true,
+ async onSubmit() {},
+ onUndo() {},
+ onStop() {},
+};
+
+describe("infographic sidebar note links", () => {
+ test("renders note links as in-app anchors and leaves external links as buttons", async () => {
+ const i18n = createInstance();
+ await i18n.init({ lng: "zh-CN", resources: { "zh-CN": { translation: zhCN } } });
+ const markup = renderToStaticMarkup(createElement(
+ QueryClientProvider,
+ { client: queryClient },
+ createElement(
+ I18nextProvider,
+ { i18n },
+ createElement(InfographicSidebarSession, {
+ session,
+ noteTitle: "演进里程碑",
+ onOpenChange() {},
+ onOpenNote() {},
+ }),
+ ),
+ ));
+ expect(markup).toContain('href="#memo=memo_demo_infographic"');
+ expect(markup).toContain('href="#memo=memo_03de025fc0134b7da0d155c2c1686b92"');
+ expect(markup).toContain("演进里程碑");
+ expect(markup).toContain("流程图");
+ expect(markup).not.toContain('href="#memo=memo_demo_infographic" target="_blank"');
+ expect(markup).toContain(">文档</button>");
+ expect(markup).not.toContain('href="https://example.com/docs"');
+ });
+});
diff --git a/apps/web/src/components/ai-sidebar/InfographicSidebarSession.tsx b/apps/web/src/components/ai-sidebar/InfographicSidebarSession.tsx
index 0c15bb94..6d454524 100644
--- a/apps/web/src/components/ai-sidebar/InfographicSidebarSession.tsx
+++ b/apps/web/src/components/ai-sidebar/InfographicSidebarSession.tsx
@@ -1,5 +1,6 @@
import { useTranslation } from "react-i18next";
import { PanelRightClose, Sparkles, Undo2 } from "lucide-react";
+import type { MouseEvent } from "react";
import type { InfographicConversationTurn } from "@edgeever/shared";
import { Button } from "@/components/ui/button";
import { Conversation, ConversationContent, ConversationEmptyState, ConversationScrollButton } from "@/components/ai-elements/conversation";
@@ -15,6 +16,7 @@ import {
} from "@/components/ai-elements/prompt-input";
import { cn } from "@/lib/utils";
import { SidebarAgentModeStatus } from "./SidebarAgentModeStatus";
+import { memoIdFromSidebarLinkEvent, rewriteSidebarNoteLinks, sidebarNoteLinkAllowedTags, sidebarNoteLinkComponents } from "./sidebar-note-links";
const threadClassName = cn(
"gap-3 p-3 text-[13px] leading-[1.6]",
@@ -89,17 +91,37 @@ function InfographicSidebarComposer({ session }: { session: InfographicSidebarCo
);
}
+function InfographicReply({ children, isAnimating }: { children: string; isAnimating?: boolean }) {
+ return (
+ <MessageResponse
+ allowedTags={sidebarNoteLinkAllowedTags}
+ className="edgeever-infographic-chat-response break-words"
+ components={sidebarNoteLinkComponents}
+ isAnimating={isAnimating}
+ >
+ {rewriteSidebarNoteLinks(children)}
+ </MessageResponse>
+ );
+}
+
export function InfographicSidebarSession({
session,
noteTitle,
onOpenChange,
+ onOpenNote,
}: {
session: InfographicSidebarController;
noteTitle?: string;
onOpenChange: (open: boolean) => void;
+ onOpenNote?: (memoId: string, notebookId: string) => void;
}) {
const { t, i18n } = useTranslation();
const title = noteTitle?.trim() || t("infographic.name");
+ const openLinkedNote = (event: MouseEvent<HTMLElement>) => {
+ const linkedId = memoIdFromSidebarLinkEvent(event);
+ if (!linkedId || !onOpenNote) return;
+ onOpenNote(linkedId, "");
+ };
const reply = (turn: InfographicConversationTurn) => turn.response
|| (turn.kind === "clarified"
? t("infographic.historyClarified")
@@ -127,7 +149,7 @@ export function InfographicSidebarSession({
</Button>
</div>
<Conversation className="min-h-0 flex-1" aria-label={t("infographic.historyTitle")}>
- <ConversationContent className={threadClassName}>
+ <ConversationContent className={threadClassName} onClick={openLinkedNote}>
{!session.turns.length && !session.activeTurn ? (
<ConversationEmptyState
icon={<Sparkles className="h-6 w-6" />}
@@ -142,7 +164,7 @@ export function InfographicSidebarSession({
</Message>
<Message from="assistant">
<MessageContent className="w-full text-foreground">
- <MessageResponse className="edgeever-infographic-chat-response break-words">{reply(turn)}</MessageResponse>
+ <InfographicReply>{reply(turn)}</InfographicReply>
{turn.decision && turn.decision !== turn.response ? <p className="text-xs text-slate-600">{turn.decision}</p> : null}
{turn.template ? <p className="text-xs text-slate-500">{turn.template}</p> : null}
{turn.error ? <p className="text-xs text-red-600">{turn.error}</p> : null}
@@ -159,9 +181,9 @@ export function InfographicSidebarSession({
</Message>
<Message from="assistant">
<MessageContent className="w-full text-foreground">
- <MessageResponse className="edgeever-infographic-chat-response break-words" isAnimating={session.generating}>
+ <InfographicReply isAnimating={session.generating}>
{session.activeTurn.response || session.activeTurn.question || t("infographic.generating")}
- </MessageResponse>
+ </InfographicReply>
{session.activeTurn.decision && session.activeTurn.decision !== session.activeTurn.response ? <p className="text-xs text-slate-600">{session.activeTurn.decision}</p> : null}
{session.activeTurn.template ? <p className="text-xs text-slate-500">{session.activeTurn.template}</p> : null}
</MessageContent>
diff --git a/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx b/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx
index 8bdbd248..daf5f99e 100644
--- a/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx
+++ b/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx
@@ -57,3 +57,20 @@ export function SidebarNoteLink({
export const sidebarNoteLinkComponents = {
"edgeever-note": SidebarNoteLink,
} satisfies Record<string, (props: ComponentProps<typeof SidebarNoteLink>) => ReactNode>;
+
+/** Read a clicked in-app note link. Other anchors stay untouched. */
+export function memoIdFromSidebarLinkEvent(event: {
+ target: EventTarget | null;
+ preventDefault: () => void;
+}): string {
+ const target = event.target;
+ if (!(target instanceof Element)) return "";
+ const link = target.closest("a");
+ if (!(link instanceof HTMLAnchorElement)) return "";
+ const linkedId = parseMemoLinkHref(link.getAttribute("href"))
+ ?? parseMemoLinkHref(link.hash)
+ ?? parseMemoLinkHref(link.href);
+ if (!linkedId) return "";
+ event.preventDefault();
+ return linkedId;
+}