Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
chore(web): update focus mode
johnnyjoygh6387991fdd1d
diff --git a/web/package.json b/web/package.jsonindex f1d75087e..5727f656b 100644--- a/web/package.json+++ b/web/package.json@@ -26,7 +26,7 @@"@tailwindcss/vite": "^4.2.4","@tanstack/react-query": "^5.100.9","@tanstack/react-query-devtools": "^5.100.9",- "@usememos/editor": "26.10.26",+ "@usememos/editor": "26.10.27","class-variance-authority": "^0.7.1","clsx": "^2.1.1","copy-to-clipboard": "^4.0.2",diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yamlindex ca41597a2..fa4a9ae74 100644--- a/web/pnpm-lock.yaml+++ b/web/pnpm-lock.yaml@@ -39,8 +39,8 @@ importers:specifier: ^5.100.9'@usememos/editor':- specifier: 26.10.26+ specifier: 26.10.27class-variance-authority:specifier: ^0.7.1version: 0.7.1@@ -1009,8 +1009,8 @@ packages:resolution: {integrity: sha512-WmoN8qaIAo7WTYWbAZuG8PYEhn5fkz7dZrqTBZ7dtt//lL2Gwms1IcnQ5yHqjDfX8Ft5j4YzDM23f87zBfDe9g==}deprecated: Potential CWE-502 - Update to 1.3.1 or higher- '@usememos/[email protected]':- resolution: {integrity: sha512-0fij2QWZhW7t7sTrDidBCJgFY7gduEfI0KVKi9fyudtkVZRdhP4piRPpOtWtGZbi0vmBYp8kZmqRhx/2+c0MvQ==}+ '@usememos/[email protected]':+ resolution: {integrity: sha512-3CJliu0uFnRG9eDv5sDJjkjefbgBUKrugPd0K3h5wehiHVl0XxYnGjNfO6C+Kt0gHTRLhIwv+mEnYJKlh0uW0Q==}peerDependencies:react: '>=18'react-dom: '>=18'@@ -2695,7 +2695,7 @@ snapshots:'@ungap/[email protected]': {}optionalDependencies:react: 19.2.6react-dom: 19.2.6([email protected])diff --git a/web/src/components/MemoEditor/MemoMarkdown.tsx b/web/src/components/MemoEditor/MemoMarkdown.tsxindex 24a07c453..86b7776ee 100644--- a/web/src/components/MemoEditor/MemoMarkdown.tsx+++ b/web/src/components/MemoEditor/MemoMarkdown.tsx@@ -1,4 +1,4 @@-import type { Editor, EditorMode, Extension } from "@usememos/editor";+import type { Editor, EditorMode, Extension, Theme } from "@usememos/editor";import { MarkdownEditor, type MarkdownEditorProps } from "@usememos/editor/react";import "@usememos/editor/style.css";import { type Ref, useCallback, useMemo, useState } from "react";@@ -38,6 +38,8 @@ export interface MemoMarkdownProps {toolbar?: boolean;/** The slash menu's items, or `false` for none. Read once. */slashMenu?: MarkdownEditorProps["slashMenu"];+ /** The editor's look. Default MEMO_EDITOR_THEME. Updates live. */+ theme?: Theme;className?: string;}@@ -72,6 +74,7 @@ export const MemoMarkdown = (props: MemoMarkdownProps) => {attributes,toolbar,slashMenu,+ theme = MEMO_EDITOR_THEME,className,} = props;const t = useTranslate();@@ -105,7 +108,7 @@ export const MemoMarkdown = (props: MemoMarkdownProps) => {placeholder={placeholder}markdown={MEMO_MARKDOWN}extensions={allExtensions}- theme={MEMO_EDITOR_THEME}+ theme={theme}labels={labels}attributes={attributes}resolveUrl={resolveUrl}diff --git a/web/src/components/MemoEditor/README.md b/web/src/components/MemoEditor/README.mdindex 337e8aa8e..2f886f756 100644--- a/web/src/components/MemoEditor/README.md+++ b/web/src/components/MemoEditor/README.md@@ -47,7 +47,7 @@ A reducer (`edit/state/reducer.ts`) drives an external store; consumers subscrib### Formatting and source mode-Formatting is the editor's own: its toolbar appears over selected text, the slash menu and Markdown shortcuts change block types, and its keys cover the rest. The editor's `mode` option shows the whole memo as Markdown text, with its syntax highlighted, and edits it as text; `useSourceMode` remembers the choice per device. To people it is "Markdown mode", the + menu's item with the pilcrow (the word processors' "show formatting marks" glyph), checked while on; in code it keeps the editor's name, source mode. Nothing in the editor names the mode: the text shows it, as it does in Obsidian and GitLab, and the memo's chrome stays the memo's. Switching changes no text and emits no change. In source mode the toolbar, slash menu, block handle and link card do not show; the `#tag` and `:emoji` popups open as in rich mode, the formatting keys edit the Markdown, and the checklist chip toggles the task marker on the caret's line through the same `toggleTaskList` command. The controller reads tags and checklists from the text parsed as a memo. The source text is in the body font (the editor's `sourceFont` token is left at its default) so a switch keeps the text's rhythm; nothing in memos targets the editor's source classes.+Formatting is the editor's own: its toolbar appears over selected text, the slash menu and Markdown shortcuts change block types, and its keys cover the rest. The editor's `mode` option shows the whole memo as Markdown text, with its syntax highlighted, and edits it as text; `useSourceMode` remembers the choice per device. To people it is "Markdown mode", the + menu's item with the code glyph (Lucide `CodeXml`), checked while on; in code it keeps the editor's name, source mode. Nothing in the editor names the mode: the text shows it, as it does in Obsidian and GitLab, and the memo's chrome stays the memo's. Switching changes no text and emits no change. In source mode the toolbar, slash menu, block handle and link card do not show; the `#tag` and `:emoji` popups open as in rich mode, the formatting keys edit the Markdown, and the checklist chip toggles the task marker on the caret's line through the same `toggleTaskList` command. The controller reads tags and checklists from the text parsed as a memo. The source text is in the body font (the editor's `sourceFont` token is left at its default) so a switch keeps the text's rhythm; nothing in memos targets the editor's source classes.### Saving@@ -63,6 +63,8 @@ Hosts of a new top-level memo pass `useMemoSuggestions()` into `suggestions`; ed- **Inline** (Home, panels): the session brings its own frame. The + menu offers focus mode, which expands it over the page; the exit button minimizes it back.- **Hosted** (`onFocusModeExit`): a host presents the session full-screen and owns that frame (`contexts/GlobalMemoEditorContext.tsx`). It mounts straight into focus mode and exits by calling back to dismiss the host.+Focus mode is a sheet narrower than the page (`max-w-3xl`): its header, text and footer share one left edge, and the text is set larger (`MEMO_FOCUS_EDITOR_THEME`). Its header row shows only the memo's time on the left, as `TimestampPopover`: the time control once the memo has one (an edit, or a new memo dated from the calendar), otherwise "Now" in the viewer's language. The button that leaves the frame is on the right.+The session's code is a chunk of its own, loaded when a memo is first edited or composed, and renders without suspending once loaded. A host that knows an editor is coming calls `preloadMemoEditing()`: the router loads it with the Home page for a signed-in user, so the composer renders with the page, and the comment section loads it while the pointer is on its button. Until it is loaded a new draft shows a still of the empty composer, the same frame, placeholder line and toolbar height, so nothing moves when the session takes its place.### Destination and visibilitydiff --git a/web/src/components/MemoEditor/edit/EditSession.tsx b/web/src/components/MemoEditor/edit/EditSession.tsxindex 3d433ce4b..5404a2825 100644--- a/web/src/components/MemoEditor/edit/EditSession.tsx+++ b/web/src/components/MemoEditor/edit/EditSession.tsx@@ -114,7 +114,7 @@ export const EditSession: React.FC<EditSessionProps> = ({// Auto-save content to localStorage (subscribes to the store internally).const { discardDraft } = useAutoSave(draftKey, isInitialized && isDraftCacheEnabled);- const { containerRef: editorContainerRef, placeholderHeight } = useFocusMode(isFocusMode);+ const { containerRef: editorContainerRef, placeholderHeight, animateFocusMode } = useFocusMode(isFocusMode);// Live-sync the draft's createTime/updateTime to the calendar-derived prop.// Only applies in create mode; edit mode owns its own timestamps. Runs after@@ -233,7 +233,7 @@ export const EditSession: React.FC<EditSessionProps> = ({onFocusModeExit();return;}- dispatch(actions.toggleFocusMode());+ animateFocusMode(() => dispatch(actions.toggleFocusMode()));};const handleCancel = useCallback(() => {@@ -342,20 +342,19 @@ export const EditSession: React.FC<EditSessionProps> = ({// A card that is the frame already supplies the background, border and padding; a// session floating over the page in focus mode always brings its own.(!frameless || isFocusMode) && "bg-card px-4 py-3 rounded-lg border border-border/70",- FOCUS_MODE_STYLES.transition,isFocusMode && cn(FOCUS_MODE_STYLES.container.base, FOCUS_MODE_STYLES.container.spacing),!isFocusMode && className,)}>{/* Formatting is the editor's own: its toolbar appears over selectedtext, and the slash menu and Markdown shortcuts change block types.- Focus mode adds the button that leaves the current frame — minimize- inline, close when hosted. */}+ Focus mode always shows the memo's time ("Now" before it has one) and adds+ the button that leaves the current frame — minimize inline, close when hosted. */}{(showTimestamp || isFocusMode) && (- <div className="flex h-6 w-full items-center">- {showTimestamp && <TimestampPopover />}+ <div className={cn("flex w-full items-center", isFocusMode ? "h-10" : "h-6")}>+ <TimestampPopover />{isFocusMode && (- <div className="ms-auto">+ <div className="ms-auto -me-2"><FocusModeExitButton action={onFocusModeExit ? "close" : "minimize"} onExit={handleToggleFocusMode} /></div>)}diff --git a/web/src/components/MemoEditor/edit/Editor.tsx b/web/src/components/MemoEditor/edit/Editor.tsxindex bd5cf52cf..28f16514f 100644--- a/web/src/components/MemoEditor/edit/Editor.tsx+++ b/web/src/components/MemoEditor/edit/Editor.tsx@@ -1,6 +1,7 @@import type { EditorMode, Editor as MarkdownEditorInstance } from "@usememos/editor";import { forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef } from "react";import { useTagCounts } from "@/hooks/useUserQueries";+import { MEMO_FOCUS_EDITOR_THEME } from "@/lib/memo-markdown";import { cn } from "@/lib/utils";import type { Attachment } from "@/types/proto/api/attachment_service_pb";import { useTranslate } from "@/utils/i18n";@@ -95,6 +96,7 @@ const Editor = forwardRef(function Editor(props: EditorProps, ref: React.Forwardattachments={attachments}extensions={extensions}attributes={EDITOR_ATTRIBUTES}+ theme={isFocusMode ? MEMO_FOCUS_EDITOR_THEME : undefined}className="memo-editor-root"/></div>diff --git a/web/src/components/MemoEditor/edit/Toolbar/InsertMenu.tsx b/web/src/components/MemoEditor/edit/Toolbar/InsertMenu.tsxindex feb61f950..eca18746e 100644--- a/web/src/components/MemoEditor/edit/Toolbar/InsertMenu.tsx+++ b/web/src/components/MemoEditor/edit/Toolbar/InsertMenu.tsx@@ -1,5 +1,5 @@import { uniqBy } from "lodash-es";-import { ImageIcon, LinkIcon, LoaderIcon, MapPinIcon, Maximize2Icon, MicIcon, PaperclipIcon, PilcrowIcon, PlusIcon } from "lucide-react";+import { CodeXmlIcon, ImageIcon, LinkIcon, LoaderIcon, MapPinIcon, Maximize2Icon, MicIcon, PaperclipIcon, PlusIcon } from "lucide-react";import { useCallback, useEffect, useRef, useState } from "react";import { LinkMemoDialog, LocationDialog } from "@/components/MemoMetadata";import type { MapPoint } from "@/components/map/types";@@ -161,8 +161,8 @@ const InsertMenu = (props: InsertMenuProps) => {{/* How the composer presents itself. Focus mode is absent when a host owns theeditor's presentation; Markdown mode (the editor's source mode) only changes howthe text is edited, so every composer has it. Checked while on: the text shows- the mode, and nothing in the editor names it. The pilcrow is the "show formatting- marks" glyph of word processors: this mode shows the markup. */}+ the mode, and nothing in the editor names it. The code glyph says this mode+ shows the markup. */}<DropdownMenuSeparator />{viewToggles && (<DropdownMenuItem onClick={viewToggles.onToggleFocusMode}>@@ -171,7 +171,7 @@ const InsertMenu = (props: InsertMenuProps) => {</DropdownMenuItem>)}<DropdownMenuCheckboxItem checked={sourceMode.isSourceMode} onCheckedChange={sourceMode.onToggle} closeOnClick indicator="end">- <PilcrowIcon />+ <CodeXmlIcon />{t("editor.markdown-mode")}</DropdownMenuCheckboxItem></DropdownMenuContent>diff --git a/web/src/components/MemoEditor/edit/components/TimestampPopover.tsx b/web/src/components/MemoEditor/edit/components/TimestampPopover.tsxindex 6e7eff2e4..3e987c4c1 100644--- a/web/src/components/MemoEditor/edit/components/TimestampPopover.tsx+++ b/web/src/components/MemoEditor/edit/components/TimestampPopover.tsx@@ -1,6 +1,7 @@import { type FC, useId, useRef, useState } from "react";import { MEMO_TIME_CONTROL_CLASSES } from "@/components/MemoView/constants";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";+import i18n from "@/i18n";import { useTranslate } from "@/utils/i18n";import { useEditorContext, useEditorSelector } from "../state";@@ -63,13 +64,20 @@ const TimestampInput: FC<{);};+/** "Now" in the viewer's language, the word the memo card shows for a memo written this moment. */+function nowLabel(): string {+ const word = new Intl.RelativeTimeFormat(i18n.language, { numeric: "auto" }).format(0, "second");+ return word.charAt(0).toLocaleUpperCase(i18n.language) + word.slice(1);+}++/** The memo's time as a control; a memo being written that has no time yet reads "Now". */export const TimestampPopover: FC = () => {const t = useTranslate();const { actions, dispatch } = useEditorContext();const createTime = useEditorSelector((s) => s.timestamps.createTime);const updateTime = useEditorSelector((s) => s.timestamps.updateTime);- if (!createTime) return null;+ if (!createTime) return <span className="shrink-0 whitespace-nowrap text-ui text-muted-foreground select-none">{nowLabel()}</span>;return (<Popover>diff --git a/web/src/components/MemoEditor/edit/constants.ts b/web/src/components/MemoEditor/edit/constants.tsindex 0b445c73e..82fee9211 100644--- a/web/src/components/MemoEditor/edit/constants.ts+++ b/web/src/components/MemoEditor/edit/constants.ts@@ -1,8 +1,9 @@export const FOCUS_MODE_STYLES = {backdrop: "fixed inset-0 bg-overlay/20 backdrop-blur-sm z-overlay",container: {- base: "fixed z-50 w-auto max-w-5xl mx-auto shadow-2xl border-border h-auto overflow-y-auto",+ base: "fixed z-50 w-auto max-w-3xl mx-auto shadow-2xl border-border h-auto overflow-y-auto pt-2 pb-4 sm:px-6",spacing: "top-2 left-2 right-2 bottom-2 sm:top-4 sm:left-4 sm:right-4 sm:bottom-4 md:top-8 md:left-8 md:right-8 md:bottom-8",},- transition: "transition-all duration-300 ease-in-out",+ /** The view transition name the session's frame carries while focus mode toggles (see editor.css). */+ transitionName: "memo-focus-mode",} as const;diff --git a/web/src/components/MemoEditor/edit/editor.css b/web/src/components/MemoEditor/edit/editor.cssindex a5089cb30..17c468c81 100644--- a/web/src/components/MemoEditor/edit/editor.css+++ b/web/src/components/MemoEditor/edit/editor.css@@ -30,6 +30,48 @@}}+/*+ * Focus mode's toggle (useFocusMode): the frame's box moves and resizes between its+ * place on the page and the sheet, its two looks cross-fading inside it at their+ * own size, top-left anchored and clipped to the box, so text never stretches.+ * The page cross-fades under it (the default root fade), which fades the backdrop in and out.+ */+::view-transition-group(memo-focus-mode) {+ animation-duration: 280ms;+ animation-timing-function: cubic-bezier(0.2, 0, 0, 1);+ overflow: clip;+ border-radius: var(--radius);+}+::view-transition-old(memo-focus-mode),+::view-transition-new(memo-focus-mode) {+ height: 100%;+ object-fit: none;+ object-position: left top;+}+::view-transition-old(memo-focus-mode) {+ animation: 120ms ease-out both memo-focus-mode-fade-out;+}+::view-transition-new(memo-focus-mode) {+ animation: 200ms ease-out 60ms both memo-focus-mode-fade-in;+}+@media (prefers-reduced-motion: reduce) {+ ::view-transition-group(memo-focus-mode),+ ::view-transition-old(memo-focus-mode),+ ::view-transition-new(memo-focus-mode) {+ animation: none !important;+ }+}+@keyframes memo-focus-mode-fade-out {+ to {+ opacity: 0;+ }+}+@keyframes memo-focus-mode-fade-in {+ from {+ opacity: 0;+ }+}+.memo-upload-anchor {position: relative;display: flex;diff --git a/web/src/components/MemoEditor/edit/hooks/useFocusMode.ts b/web/src/components/MemoEditor/edit/hooks/useFocusMode.tsindex 04b198a1f..d90b8b89f 100644--- a/web/src/components/MemoEditor/edit/hooks/useFocusMode.ts+++ b/web/src/components/MemoEditor/edit/hooks/useFocusMode.ts@@ -1,9 +1,12 @@-import { useEffect, useLayoutEffect, useRef } from "react";+import { useCallback, useEffect, useLayoutEffect, useRef } from "react";+import { flushSync } from "react-dom";+import { FOCUS_MODE_STYLES } from "../constants";/**- * Manages the DOM-only parts of focus mode: body scroll locking and a measured+ * Manages the DOM-only parts of focus mode: body scroll locking, a measured* placeholder height that keeps masonry/grid layouts stable while the editor- * itself is fixed above the page.+ * itself is fixed above the page, and the view transition that grows the frame+ * out of its place on the page and back.*/export function useFocusMode(isFocusMode: boolean) {const containerRef = useRef<HTMLDivElement>(null);@@ -33,8 +36,35 @@ export function useFocusMode(isFocusMode: boolean) {return () => resizeObserver.disconnect();}, [isFocusMode]);+ const transitionRef = useRef<ViewTransition | null>(null);+ /**+ * Runs `toggle` as a view transition: the frame alone carries a transition name,+ * so it morphs between its place on the page and the focus sheet while the page+ * cross-fades under the backdrop. Without view transitions it simply toggles.+ */+ const animateFocusMode = useCallback((toggle: () => void) => {+ const container = containerRef.current;+ if (!container || !document.startViewTransition) {+ toggle();+ return;+ }+ // Named only while it runs: several sessions can be on a page, and a name must be unique.+ container.style.viewTransitionName = FOCUS_MODE_STYLES.transitionName;+ const transition = document.startViewTransition(() => flushSync(toggle));+ transitionRef.current = transition;+ // A second toggle mid-flight skips this transition and rejects `ready`.+ transition.ready.catch(() => {});+ void transition.finished.finally(() => {+ // A skipped transition finishes while the next one still needs the name.+ if (transitionRef.current !== transition) return;+ transitionRef.current = null;+ container.style.viewTransitionName = "";+ });+ }, []);+return {containerRef,placeholderHeight: normalModeHeightRef.current,+ animateFocusMode,};}diff --git a/web/src/lib/memo-markdown.ts b/web/src/lib/memo-markdown.tsindex 1cd9f3445..f323234ad 100644--- a/web/src/lib/memo-markdown.ts+++ b/web/src/lib/memo-markdown.ts@@ -266,6 +266,12 @@ export const MEMO_EDITOR_THEME: Theme = (() => {};})();+/** The composer's look in focus mode: the same theme, set larger for writing at length. */+export const MEMO_FOCUS_EDITOR_THEME: Theme = {+ ...MEMO_EDITOR_THEME,+ tokens: { ...MEMO_EDITOR_THEME.tokens, fontSize: 17, lineHeight: 28 },+};+/** The editor's UI strings in the user's language. */export const memoEditorLabels = (t: ReturnType<typeof useTranslate>): Partial<Labels> => ({text: t("editor.format.paragraph"),diff --git a/web/tests/memo-editor-timestamps.test.tsx b/web/tests/memo-editor-timestamps.test.tsxindex 5fb81ed9c..6652c92e2 100644--- a/web/tests/memo-editor-timestamps.test.tsx+++ b/web/tests/memo-editor-timestamps.test.tsx@@ -102,4 +102,14 @@ describe("memo editor timestamps", () => {expect(request.updateMask.paths).toEqual(["content", "update_time"]);expect(request.memo.updateTime).toEqual(timestampFromDate(customTime));});++ it("reads Now for a memo being written that has no time yet", () => {+ render(+ <EditorProvider initialEditorState={createInitialState()}>+ <TimestampPopover />+ </EditorProvider>,+ );+ expect(screen.getByText("Now")).toBeInTheDocument();+ expect(screen.queryByRole("button")).not.toBeInTheDocument();+ });});