memos/web/src/components/MemoEditor
Kaki021 122ac94273
fix(web): ensure default memo visibility is correctly applied (#5623)
2026-02-14 16:58:58 +08:00
..
Editor style: remove unnecessary font-weight classes for cleaner UI 2026-01-13 23:19:43 +08:00
Toolbar style: enhance ActivityCalendar components with improved styling and layout adjustments 2026-01-30 00:13:58 +08:00
components feat(web): replace EditableTimestamp with inline editor timestamp popover 2026-02-11 23:45:53 +08:00
hooks perf(web): eliminate redundant fetch when opening inline memo editor 2026-02-12 23:02:25 +08:00
services perf(web): eliminate redundant fetch when opening inline memo editor 2026-02-12 23:02:25 +08:00
state feat(web): replace EditableTimestamp with inline editor timestamp popover 2026-02-11 23:45:53 +08:00
types perf(web): eliminate redundant fetch when opening inline memo editor 2026-02-12 23:02:25 +08:00
README.md refactor(editor): complete state machine and services migration 2025-12-23 08:38:02 +08:00
constants.ts chore: remove unused keyboard shortcuts 2026-01-02 09:57:09 +08:00
index.tsx fix(web): ensure default memo visibility is correctly applied (#5623) 2026-02-14 16:58:58 +08:00

README.md

MemoEditor Architecture

Overview

MemoEditor uses a three-layer architecture for better separation of concerns and testability.

Architecture

┌─────────────────────────────────────────┐
│   Presentation Layer (Components)       │
│   - EditorToolbar, EditorContent, etc.  │
└─────────────────┬───────────────────────┘
                  │
┌─────────────────▼───────────────────────┐
│   State Layer (Reducer + Context)       │
│   - state/, useEditorContext()          │
└─────────────────┬───────────────────────┘
                  │
┌─────────────────▼───────────────────────┐
│   Service Layer (Business Logic)        │
│   - services/ (pure functions)          │
└─────────────────────────────────────────┘

Directory Structure

MemoEditor/
├── state/                  # State management (reducer, actions, context)
├── services/              # Business logic (pure functions)
├── components/            # UI components
├── hooks/                 # React hooks (utilities)
├── Editor/               # Core editor component
├── Toolbar/              # Toolbar components
├── constants.ts
└── types/

Key Concepts

State Management

Uses useReducer + Context for predictable state transitions. All state changes go through action creators.

Services

Pure TypeScript functions containing business logic. No React hooks, easy to test.

Components

Thin presentation components that dispatch actions and render UI.

Usage

import MemoEditor from "@/components/MemoEditor";

<MemoEditor
  memoName="memos/123"
  onConfirm={(name) => console.log('Saved:', name)}
  onCancel={() => console.log('Cancelled')}
/>

Testing

Services are pure functions - easy to unit test without React.

const state = mockEditorState();
const result = await memoService.save(state, { memoName: 'memos/123' });