AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
Improve note action menu access
tianma-ifd8e04e333072
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex 098fb47e..b005b2b7 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -107,6 +107,7 @@ import {EDITOR_LOCAL_SAVE_DELAY_MS,getEditableMemoTitle,getNotebookMoveOptions,+ type MemoDocumentActionRequest,} from "@/lib/app-helpers";import { copyEditorToWeChat, copyMarkdownToWeChat } from "@/lib/wechat-copy";import { ThemeBlock } from "./ThemeBlock";@@ -610,6 +611,8 @@ type EditorPaneProps = {onSaveAsTemplate: (memo: MemoDetail, name: string) => Promise<void>;searchFocusToken: number;replaceFocusToken: number;+ documentActionRequest?: MemoDocumentActionRequest | null;+ onDocumentActionConsumed?: (requestId: number) => void;selectionActionBar?: ReactNode;onOpenMemo?: (memoId: string) => void;};@@ -671,6 +674,8 @@ const RichEditorPane = ({onSaveAsTemplate,searchFocusToken,replaceFocusToken,+ documentActionRequest,+ onDocumentActionConsumed,selectionActionBar,onOpenMemo,onRequestMobileNativeEdit,@@ -1745,33 +1750,41 @@ const RichEditorPane = ({}}, [editor, markdownSource, useMarkdownSourceEditor]);- const handleExportPdf = useCallback(() => {+ const handleExportPdf = useCallback((preopenedWindow?: Window | null) => {if (!isEditorReady(editor) || !memo) {return;}+ if (preopenedWindow === null) {+ window.alert(t("editor.pdfExport.popupBlocked"));+ return;+ }+const currentDocument = useMobilePlainTextEditor? markdownToDoc(getMobilePlainTextValue()): useMarkdownSourceEditor? markdownToDoc(markdownSource): editor.getJSON() as TiptapDoc;const html = serializeNoteDocumentForPrint(editor, currentDocument);- const opened = openNotePrintPreview({- title: title.trim() || t("common.untitledMemo"),- notebook: notebookOptions.find((notebook) => notebook.id === memo.notebookId)?.name ?? "",- tags: parseTagsText(tagsText),- updatedAt: formatDateTime(memo.updatedAt),- html,- language: i18n.resolvedLanguage ?? i18n.language,- labels: {- close: t("editor.pdfExport.close"),- error: t("editor.pdfExport.error"),- hint: t("editor.pdfExport.hint"),- preparing: t("editor.pdfExport.preparing"),- print: t("editor.pdfExport.print"),- ready: t("editor.pdfExport.ready"),+ const opened = openNotePrintPreview(+ {+ title: title.trim() || t("common.untitledMemo"),+ notebook: notebookOptions.find((notebook) => notebook.id === memo.notebookId)?.name ?? "",+ tags: parseTagsText(tagsText),+ updatedAt: formatDateTime(memo.updatedAt),+ html,+ language: i18n.resolvedLanguage ?? i18n.language,+ labels: {+ close: t("editor.pdfExport.close"),+ error: t("editor.pdfExport.error"),+ hint: t("editor.pdfExport.hint"),+ preparing: t("editor.pdfExport.preparing"),+ print: t("editor.pdfExport.print"),+ ready: t("editor.pdfExport.ready"),+ },},- });+ preopenedWindow ?? undefined,+ );if (!opened) {window.alert(t("editor.pdfExport.popupBlocked"));@@ -1817,6 +1830,68 @@ const RichEditorPane = ({useMobilePlainTextEditor,]);+ const handleSaveAsTemplate = useCallback(() => {+ if (!memo) {+ return;+ }++ const name = window.prompt(t("templates.templateNamePrompt"), memo.title || "");+ if (!name?.trim()) {+ return;+ }++ const currentMarkdown = useMobilePlainTextEditor+ ? getMobilePlainTextValue()+ : isEditorReady(editor)+ ? docToMarkdown(editor.getJSON() as TiptapDoc)+ : memo.contentMarkdown;+ const currentTemplateMemo: MemoDetail = {+ ...memo,+ title,+ tags: parseTagsText(tagsText),+ contentJson: markdownToDoc(currentMarkdown),+ contentMarkdown: currentMarkdown,+ };+ void onSaveAsTemplate(currentTemplateMemo, name.trim());+ }, [editor, getMobilePlainTextValue, memo, onSaveAsTemplate, t, tagsText, title, useMobilePlainTextEditor]);++ useEffect(() => {+ if (+ !documentActionRequest ||+ documentActionRequest.memoId !== memo?.id ||+ hydratedEditorMemoId !== memo.id ||+ !isEditorReady(editor)+ ) {+ return;+ }++ onDocumentActionConsumed?.(documentActionRequest.id);++ switch (documentActionRequest.action) {+ case "share":+ setShareOpen(true);+ break;+ case "export-markdown":+ handleExportMarkdown();+ break;+ case "export-pdf":+ handleExportPdf(documentActionRequest.printWindow);+ break;+ case "save-as-template":+ handleSaveAsTemplate();+ break;+ }+ }, [+ documentActionRequest,+ editor,+ handleExportMarkdown,+ handleExportPdf,+ handleSaveAsTemplate,+ hydratedEditorMemoId,+ memo,+ onDocumentActionConsumed,+ ]);+useEffect(() => {if (!useMobilePlainTextEditor) {return;@@ -2653,7 +2728,7 @@ const RichEditorPane = ({</DropdownMenuItem><DropdownMenuItemclassName="flex h-9 w-full items-center gap-2 px-3 text-left text-sm text-slate-700 hover:bg-slate-50 cursor-pointer outline-none"- onClick={handleExportPdf}+ onClick={() => handleExportPdf()}><Printer className="h-4 w-4 text-slate-500" />{t("editor.exportPdf")}@@ -2680,24 +2755,7 @@ const RichEditorPane = ({<><DropdownMenuItemclassName="flex h-9 w-full items-center gap-2 px-3 text-left text-sm text-slate-700 hover:bg-slate-50 cursor-pointer outline-none"- onClick={() => {- const name = window.prompt(t("templates.templateNamePrompt"), memo.title || "");- if (name?.trim()) {- const currentMarkdown = useMobilePlainTextEditor- ? getMobilePlainTextValue()- : isEditorReady(editor)- ? docToMarkdown(editor.getJSON() as TiptapDoc)- : memo.contentMarkdown;- const currentTemplateMemo: MemoDetail = {- ...memo,- title,- tags: parseTagsText(tagsText),- contentJson: markdownToDoc(currentMarkdown),- contentMarkdown: currentMarkdown,- };- void onSaveAsTemplate(currentTemplateMemo, name.trim());- }- }}+ onClick={handleSaveAsTemplate}><Pencil className="h-4 w-4 text-slate-500" />{t("templates.saveAsTemplate")}diff --git a/apps/web/src/components/MemoCard.tsx b/apps/web/src/components/MemoCard.tsxindex d6022bb8..a6b71ac4 100644--- a/apps/web/src/components/MemoCard.tsx+++ b/apps/web/src/components/MemoCard.tsx@@ -1,7 +1,7 @@import { useRef, useState, useEffect, type DragEvent, type MouseEvent, type PointerEvent as ReactPointerEvent, type KeyboardEvent as ReactKeyboardEvent } from "react";import { useTranslation } from "react-i18next";import * as m from "motion/react-m";-import { Star, Check, MoreHorizontal, RotateCcw, Trash2 } from "lucide-react";+import { Star, Check, MoreHorizontal, RotateCcw } from "lucide-react";import type { MemoSummary } from "@edgeever/shared";import { cn } from "@/lib/utils";import { selectionSettleMotion } from "@/lib/motion";@@ -49,7 +49,6 @@ export const MemoCard = ({listDensity,multiSelectKeyDown,onOpen,- onDelete,onRestore,onOpenContextMenu,onOpenSelectionContextMenu,@@ -66,7 +65,6 @@ export const MemoCard = ({listDensity: MemoListDensity;multiSelectKeyDown: boolean;onOpen: () => void;- onDelete: () => void;onRestore: () => void;onOpenContextMenu: (event: MouseEvent<HTMLElement>) => void;onOpenSelectionContextMenu: (event: MouseEvent<HTMLElement>) => void;@@ -420,26 +418,20 @@ export const MemoCard = ({><MoreHorizontal className="h-4 w-4" /></button>- <button- className={cn(- "flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-slate-400 transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-400/70 focus-visible:ring-offset-2",- isTrashView ? "hover:bg-slate-100 hover:text-slate-800" : "hover:bg-rose-50 hover:text-rose-700"- )}- type="button"- title={isTrashView ? t("memoCard.restoreMemo") : t("memoCard.deleteMemo")}- aria-label={isTrashView ? t("memoCard.restoreMemo") : t("memoCard.deleteMemo")}- onClick={(event) => {- event.stopPropagation();- if (isTrashView) {+ {isTrashView && (+ <button+ className="flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-slate-400 transition hover:bg-slate-100 hover:text-slate-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-400/70 focus-visible:ring-offset-2"+ type="button"+ title={t("memoCard.restoreMemo")}+ aria-label={t("memoCard.restoreMemo")}+ onClick={(event) => {+ event.stopPropagation();onRestore();- return;- }-- onDelete();- }}- >- {isTrashView ? <RotateCcw className="h-4 w-4" /> : <Trash2 className="h-4 w-4" />}- </button>+ }}+ >+ <RotateCcw className="h-4 w-4" />+ </button>+ )}</div>)}</div>diff --git a/apps/web/src/components/MemoListPane.tsx b/apps/web/src/components/MemoListPane.tsxindex 5ee84c87..da87f223 100644--- a/apps/web/src/components/MemoListPane.tsx+++ b/apps/web/src/components/MemoListPane.tsx@@ -39,6 +39,10 @@ import {MoreVertical,CheckCircle2,TagX,+ Link2,+ FileDown,+ Printer,+ Pencil,} from "lucide-react";import { Button } from "@/components/ui/button";import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";@@ -60,10 +64,12 @@ import type {MemoSortMode,MemoListDensity,MemoContextMenuState,+ MemoDocumentAction,NotebookMoveOption,} from "@/lib/app-helpers";import { contentEnterMotion, paneEnterMotion } from "@/lib/motion";import type { SyncQueueSummary } from "@/lib/sync-queue";+import { isLocalMemoId } from "@/lib/local-mirror";import {getMemoFilterOptions,getMemoSortOptions,@@ -343,6 +349,7 @@ export const MemoListPane = ({onRestoreMemo,onTogglePinMemo,onMoveMemo,+ onRequestDocumentAction,onMoveSelectedMemos,onPinSelectedMemos,onDeleteSelectedMemos,@@ -415,6 +422,7 @@ export const MemoListPane = ({onRestoreMemo: (memoId: string) => void;onTogglePinMemo: (memo: MemoSummary) => void;onMoveMemo: (memoId: string, notebookId: string) => void;+ onRequestDocumentAction: (memoId: string, action: MemoDocumentAction, printWindow?: Window | null) => void;onMoveSelectedMemos: (notebookId: string) => void;onPinSelectedMemos: (pinned: boolean) => void;onDeleteSelectedMemos: () => void;@@ -524,6 +532,17 @@ export const MemoListPane = ({? t("memoList.manualSyncing"): t("memoList.manualSync");+ const requestContextDocumentAction = (action: MemoDocumentAction) => {+ if (!memoContextMenu) {+ return;+ }++ const { memo } = memoContextMenu;+ const printWindow = action === "export-pdf" ? window.open("about:blank", "_blank") : undefined;+ setMemoContextMenu(null);+ onRequestDocumentAction(memo.id, action, printWindow);+ };+useEffect(() => {if (notebook?.id) {setMoveTargetNotebookId(notebook.id);@@ -1375,7 +1394,6 @@ export const MemoListPane = ({listDensity={listDensity}multiSelectKeyDown={multiSelectKeyDown}onOpen={() => onOpenMemo(memo.id)}- onDelete={() => onDeleteMemo(memo.id)}onRestore={() => onRestoreMemo(memo.id)}onOpenContextMenu={(event) => handleOpenMemoContextMenu(memo, event)}onOpenSelectionContextMenu={(event) => handleOpenSelectionContextMenu(memo, event)}@@ -1503,6 +1521,37 @@ export const MemoListPane = ({))}</div>)}+ <DropdownMenuSeparator className="my-1 h-px bg-slate-100" />+ <DropdownMenuItem+ className="flex h-9 w-full items-center gap-2 px-3 text-left text-sm text-slate-700 hover:bg-slate-50 cursor-pointer outline-none"+ disabled={isLocalMemoId(memoContextMenu.memo.id)}+ onClick={() => requestContextDocumentAction("share")}+ >+ <Link2 className="h-4 w-4 text-slate-500" />+ {t("sharing.action")}+ </DropdownMenuItem>+ <DropdownMenuItem+ className="flex h-9 w-full items-center gap-2 px-3 text-left text-sm text-slate-700 hover:bg-slate-50 cursor-pointer outline-none"+ onClick={() => requestContextDocumentAction("export-markdown")}+ >+ <FileDown className="h-4 w-4 text-slate-500" />+ {t("editor.exportMarkdown")}+ </DropdownMenuItem>+ <DropdownMenuItem+ className="flex h-9 w-full items-center gap-2 px-3 text-left text-sm text-slate-700 hover:bg-slate-50 cursor-pointer outline-none"+ onClick={() => requestContextDocumentAction("export-pdf")}+ >+ <Printer className="h-4 w-4 text-slate-500" />+ {t("editor.exportPdf")}+ </DropdownMenuItem>+ <DropdownMenuItem+ className="flex h-9 w-full items-center gap-2 px-3 text-left text-sm text-slate-700 hover:bg-slate-50 cursor-pointer outline-none"+ onClick={() => requestContextDocumentAction("save-as-template")}+ >+ <Pencil className="h-4 w-4 text-slate-500" />+ {t("templates.saveAsTemplate")}+ </DropdownMenuItem>+ <DropdownMenuSeparator className="my-1 h-px bg-slate-100" /><DropdownMenuItemclassName="flex h-9 w-full items-center gap-2 px-3 text-left text-sm text-rose-700 hover:bg-rose-50 cursor-pointer outline-none"onClick={() => {diff --git a/apps/web/src/components/WorkspaceApp.tsx b/apps/web/src/components/WorkspaceApp.tsxindex 3e6cc7ee..04ee2b36 100644--- a/apps/web/src/components/WorkspaceApp.tsx+++ b/apps/web/src/components/WorkspaceApp.tsx@@ -56,6 +56,8 @@ import type {ShortcutSettings,MemoFilterMode,MemoSortMode,+ MemoDocumentAction,+ MemoDocumentActionRequest,} from "@/lib/app-helpers";import {MIN_MEMO_LIST_WIDTH_PX,@@ -698,6 +700,8 @@ export const WorkspaceApp = ({const pendingCreatedMemoIdRef = useRef<string | null>(null);const creatingMemoSelectionRef = useRef(false);const [selectedMemoIds, setSelectedMemoIds] = useState<Set<string>>(new Set());+ const memoDocumentActionIdRef = useRef(0);+ const [memoDocumentActionRequest, setMemoDocumentActionRequest] = useState<MemoDocumentActionRequest | null>(null);const [memoSelectionMode, setMemoSelectionMode] = useState(false);const [selectionMoveTargetNotebookId, setSelectionMoveTargetNotebookId] = useState("");const [memoDeleteConfirmation, setMemoDeleteConfirmation] = useState<MemoDeleteConfirmation | null>(null);@@ -2927,6 +2931,23 @@ export const WorkspaceApp = ({onEmptyTrash={handleEmptyTrash}onRestoreMemo={handleRestoreMemoFromList}onMoveMemo={handleMoveMemoFromList}+ onRequestDocumentAction={(memoId: string, action: MemoDocumentAction, printWindow?: Window | null) => {+ if (shouldNavigateHomeWhenOpeningMemo(memoView)) {+ navigateWorkspaceHome();+ }+ setRightView("editor");+ clearPendingCreatedMemo();+ setCreatedMemoEditId(null);+ setSelectedMemoId(memoId);+ setActivePane("editor");+ memoDocumentActionIdRef.current += 1;+ setMemoDocumentActionRequest({+ id: memoDocumentActionIdRef.current,+ memoId,+ action,+ printWindow,+ });+ }}onTogglePinMemo={handleToggleMemoPinned}onPinSelectedMemos={handlePinSelectedMemos}onDeleteSelectedMemos={handleDeleteSelectedMemos}@@ -3016,6 +3037,10 @@ export const WorkspaceApp = ({contentSearchQuery={search}searchFocusToken={noteSearchFocusToken}replaceFocusToken={noteReplaceFocusToken}+ documentActionRequest={memoDocumentActionRequest}+ onDocumentActionConsumed={(requestId) => {+ setMemoDocumentActionRequest((current) => current?.id === requestId ? null : current);+ }}onOpenMemo={(memoId) => {clearPendingCreatedMemo();setMemoView("notebook");diff --git a/apps/web/src/lib/app-helpers.ts b/apps/web/src/lib/app-helpers.tsindex 82fcda50..348867c2 100644--- a/apps/web/src/lib/app-helpers.ts+++ b/apps/web/src/lib/app-helpers.ts@@ -22,6 +22,13 @@ export type ShortcutBinding = {export type ShortcutSettings = Record<ShortcutAction, ShortcutBinding>;export type MobileBottomNavItem = "home" | "search" | "templates" | "settings";export type MemoContextMenuState = { memo: MemoSummary; x: number; y: number };+export type MemoDocumentAction = "share" | "export-markdown" | "export-pdf" | "save-as-template";+export type MemoDocumentActionRequest = {+ id: number;+ memoId: string;+ action: MemoDocumentAction;+ printWindow?: Window | null;+};export type MemoSelectionContextMenuState = { x: number; y: number };export type NotebookContextMenuState = { notebook: NotebookNode; x: number; y: number };export type MemoDeleteConfirmation = { kind: "single" | "bulk"; memoIds: string[]; permanent: boolean };diff --git a/apps/web/src/lib/note-print.ts b/apps/web/src/lib/note-print.tsindex cc1201f9..1602b156 100644--- a/apps/web/src/lib/note-print.ts+++ b/apps/web/src/lib/note-print.ts@@ -41,10 +41,11 @@ export const serializeNoteDocumentForPrint = (editor: Editor, document: TiptapDo};export const openNotePrintPreview = (- payload: Omit<NotePrintPayload, "type" | "token">+ payload: Omit<NotePrintPayload, "type" | "token">,+ preopenedWindow?: Window,) => {const token = crypto.randomUUID();- let printWindow: Window | null = null;+ let printWindow: Window | null = preopenedWindow ?? null;const handleMessage = (event: MessageEvent<NotePrintReadyMessage>) => {if (@@ -68,10 +69,18 @@ export const openNotePrintPreview = (};window.addEventListener("message", handleMessage);- printWindow = window.open(- `${NOTE_PRINT_PATH}?token=${encodeURIComponent(token)}`,- "_blank"- );+ const printUrl = `${NOTE_PRINT_PATH}?token=${encodeURIComponent(token)}`;++ if (printWindow) {+ try {+ printWindow.location.href = printUrl;+ } catch {+ window.removeEventListener("message", handleMessage);+ return false;+ }+ } else {+ printWindow = window.open(printUrl, "_blank");+ }if (!printWindow) {window.removeEventListener("message", handleMessage);