import { create } from "@bufbuild/protobuf";
import { Button, Field, Input, Textarea } from "@usememos/ui";
import { LockKeyholeIcon } from "lucide-react";
import { useEffect, useRef, useState } from "react";
import { useBlocker } from "react-router-dom";
import { VaultPanel } from "@/components/Encryption/VaultPanel";
import { lockEncryption, useVaultSession } from "@/contexts/E2EEContext";
import { useCreateMemo, useUpdateMemo } from "@/hooks/useMemoQueries";
import { decodeMemo, decryptMemo, type EncryptedMemo, encodeRecord, encryptMemo } from "@/lib/e2ee/crypto";
import { registerEncryptedDraft } from "@/lib/e2ee/dirty";
import { showErrorToast } from "@/lib/toast";
import { cn } from "@/lib/utils";
import { type Memo, MemoSchema, Visibility } from "@/types/proto/api/memo_service_pb";
import { useTranslate } from "@/utils/i18n";
interface Props {
className?: string;
onFocusModeExit?: () => void;
memo?: Memo;
editing?: boolean;
onConfirm?: (name: string) => void;
onCancel?: () => void;
onSavingChange?: (saving: boolean) => void;
}
/** The restricted text mode of MemoEditor never mounts Markdown plugins or draft persistence. */
export function EncryptedMemoEditor(props: Props) {
const vault = useVaultSession();
const content = !vault.key ? (
) : (
);
return (
{content}
);
}
/** Shows the plaintext title and offers vault unlock without exposing the encrypted body. */
function LockedText({ memo, onCancel }: Props) {
const t = useTranslate();
const [open, setOpen] = useState(!memo);
return (