Procházet zdrojové kódy

docs: update AGENTS and READMEs to match current architecture

- AGENTS.md:
  - Fix parsing pipeline from 3-stage hybrid to Lezer-only 2-stage
  - Note block-classifier is paste-handler-only, not in main engine
  - Note priority tokens (#A etc.) are plain text, not parsed
  - Update component flow to include Editor.vue and InsertionZone.vue

- README.md (root):
  - Split lumped phases into 13 granular phases matching development.md
  - Mark multi-block editing & history as done
  - Add missing files to monorepo structure (Editor, InsertionZone, EditorToolbar, formatting, operation-history, theme, etc.)

- packages/editor/README.md:
  - Add complete Editor.vue API docs (props, #toolbar slot, emits, exposed methods)
  - Complete Block.vue props table (onBoundaryExit, registry, depth)
  - Add highlight syntax (^^text^^) and note removed priority/date tokens
  - Expand Key Files from 18 to 26 entries

- apps/dev/README.md:
  - Add Editor Shell, Toolbar, and Themes pages to site map
Zander Hawke před 5 dny
rodič
revize
5c82c7b008
4 změnil soubory, kde provedl 133 přidání a 44 odebrání
  1. 21 17
      AGENTS.md
  2. 30 15
      README.md
  3. 4 1
      apps/dev/README.md
  4. 78 11
      packages/editor/README.md

+ 21 - 17
AGENTS.md

@@ -13,41 +13,45 @@ apps/dev/          Development and testing sandbox (Vue 3 + Vite + TypeScript)
 packages/editor/   Core headless engine — parsers, rule registries, composables, tests
 ```
 
-**Component flow:**
+**Component flow (editor shell):**
 
 ```
 apps/dev/src/pages/EditorView.vue
   └── apps/dev/src/components/Editor.vue
-        └── packages/editor/src/components/Block.vue
-              ├── packages/editor/src/composables/useMarkdownDecorations.ts
-              │     └── packages/editor/src/lib/markdown-parser.ts
-              │           └── packages/editor/src/lib/markdown-rules/engine.ts
-              │                 ├── block-classifier.ts
-              │                 ├── inline-rules.ts
-              │                 └── block-rules.ts
-              ├── packages/editor/src/composables/useBlockKeyboardHandlers.ts
-              └── packages/editor/src/composables/usePatternPlugin.ts
-                    └── Lezer Parser Engine
+        └── packages/editor/src/components/Editor.vue    ← multi-block shell
+              ├── packages/editor/src/components/InsertionZone.vue
+              └── packages/editor/src/components/Block.vue
+                    ├── packages/editor/src/composables/useMarkdownDecorations.ts
+                    │     └── packages/editor/src/lib/markdown-parser.ts
+                    │           └── packages/editor/src/lib/markdown-rules/engine.ts
+                    │                 ├── block-classifier.ts  (paste only)
+                    │                 ├── inline-rules.ts
+                    │                 └── block-rules.ts
+                    ├── packages/editor/src/composables/useBlockKeyboardHandlers.ts
+                    └── packages/editor/src/composables/usePatternPlugin.ts
 ```
 
 ---
 
 ## Parsing Pipeline
 
-All syntax features flow through a 3-stage pipeline in `packages/editor/src/lib/markdown-rules/engine.ts`:
+All syntax features flow through a 2-stage pipeline in `packages/editor/src/lib/markdown-rules/engine.ts`:
 
 ```
 [Raw Block Content String]
-       ├── Phase 1: Block Classification   →  regex classifyBlock() on first line
-       ├── Phase 1a: Priority Detection    →  separate from task state
-       ├── Phase 2: Lezer AST Visitor      →  Inline Rules (Bold, Links, PageRef, Tags, Highlights)
-       └── Phase 3: Property Extraction    →  Suffix Matcher (Key::Value)
+       ├── Phase 1: Lezer AST Visitor
+       │     ├─ enter → block rules (headings, blockquotes, callouts, tasks)
+       │     └─ leave → inline rules (bold, italic, code, links, refs, tags, highlights)
+       │
+       ├── Phase 2: Property Extraction    →  Suffix Matcher (Key::Value)
 [ParsedDecorations — unified output struct]
 ```
 
+> **Note**: `classifyBlock()` in `block-classifier.ts` is used only by the paste handler (`usePasteHandler.ts`), not by the main decoration engine. Priority detection (`[#A]`, `[#B]`, `[#C]`) was removed from the parser; these are treated as plain text.
+
 ### Unified Output Contract
 
 ```typescript
@@ -81,7 +85,7 @@ status                          priority
 
 - **Valid states:** `TODO`, `DOING`, `DONE`, `LATER`, `NOW`, `WAITING`, `CANCELLED`
 - **State progression:** `TODO → DOING → DONE` (linear). `LATER`, `NOW`, `WAITING`, `CANCELLED` are orthogonal.
-- **Valid priorities:** `[#A]`, `[#B]`, `[#C]` — independent of task state.
+- **Valid priorities:** `[#A]`, `[#B]`, `[#C]` — independent of task state. Priority tokens are **plain text** in the parser; they are not extracted as decorations.
 
 ### Obsidian-Style Elements
 

+ 30 - 15
README.md

@@ -12,16 +12,20 @@ Enesis is being built as a complete block-editing substrate:
 
 | Phase | Feature | Status |
 |---|---|---|---|
-| 1–5 | Core editor: clean content model, keyboard boundaries, focus/cursor, inline + block decorations, Lezer-only AST pipeline | **Done** |
-| 6 | Code block node views with CodeMirror 6, inline/block LaTeX with KaTeX | **Done** |
-| 6.75 | Build system — type declarations pass cleanly, dev app as interactive docs site | **Done** |
+| 1 | Clean content model — raw markdown in/out, ProseMirror never parses formatting | **Done** |
+| 2 | Keyboard & boundary behavior — Enter, Backspace, Tab, arrows, pattern triggers | **Done** |
+| 3 | Focus & cursor control — programmatic focus, expose API | **Done** |
+| 4 | Core decoration system — Lezer-based inline tokens, cursor-reveal, caching | **Done** |
+| 5 | Block-level decorations — headings, blockquotes, tasks, callouts, properties | **Done** |
+| 6 | Code & math node views — CM6 fenced code blocks, KaTeX LaTeX rendering | **Done** |
+| 6.5 | Formatting handlers — toggle bold/italic/code/strike/highlight, insertLink, setHeading, toggleTask | **Done** |
 | 7 | Reference & tag insertion handlers — `insertPageRef`, `insertBlockRef`, `insertTag` | **Done** |
-| 8 | Asset handling — image drop, upload protocol, inline preview | Planned |
-| 9 | Reference interactivity — clickable `[[page]]`, `((block))`, `#tag` chips with preview | Planned |
-| 10 | Multi-block editing — shared toolbar, drag handle, suggestion/mention menus | Planned |
+| 8 | Reference interactivity — clickable `[[page]]`, `((block))`, `#tag` chips with preview | Planned |
+| 9 | Asset handling — image drop, upload protocol, inline preview | Planned |
+| 10 | Multi-block editing — shared toolbar, insertion zones, suggestion/mention menus, undo/redo | **Done** (shell + history) |
 | 11 | WCAG 2.1 AA compliance, screen reader support, RTL, high contrast | Planned |
-| 12 | Third-party decoration plugin system | Planned |
-| 13 | History orchestration API across blocks | Planned |
+| 12 | History orchestration API across blocks | Planned |
+| Post-v1 | Third-party decoration plugin system | Planned |
 
 ## Design Principles
 
@@ -59,27 +63,38 @@ Enesis is being built as a complete block-editing substrate:
 ├── packages/
 │   └── editor/                Core headless engine
 │       ├── src/
-│       │   ├── index.ts               Public API (Block component + plugin)
+│       │   ├── index.ts               Public API (Block + Editor + EditorToolbar components)
 │       │   ├── components/
-│       │   │   └── Block.vue           Self-contained ProseMirror block editor
+│       │   │   ├── Block.vue           Self-contained ProseMirror block editor
+│       │   │   ├── Editor.vue          Multi-block shell with insertion zones, undo/redo
+│       │   │   ├── InsertionZone.vue   32px hit target between blocks, hover-reveal
+│       │   │   └── EditorToolbar.vue   Shared toolbar bound to active block
 │       │   ├── composables/
 │       │   │   ├── useMarkdownDecorations.ts   ProseMirror decoration plugin
 │       │   │   ├── useBlockKeyboardHandlers.ts Keyboard handler (Enter, Backspace, arrows)
 │       │   │   ├── useCodeBlockView.ts         CM6 NodeView for fenced code blocks
-│       │   │   └── usePatternPlugin.ts         Pattern detection ([[, ((, /, #)
+│       │   │   ├── useMathBlockView.ts         KaTeX NodeView for display math
+│       │   │   ├── usePatternPlugin.ts         Pattern detection ([[, ((, /, #)
+│       │   │   ├── usePasteHandler.ts          Multi-line paste split handler
+│       │   │   └── useFocusRegistry.ts         Cross-block focus management
 │       │   └── lib/
-│       │       ├── markdown-parser.ts          Lezer parser configuration
-│       │       ├── markdown-extensions.ts      Custom Lezer extensions
+│       │       ├── block-parser.ts             splitMarkdownIntoBlocks / serializeBlocks
 │       │       ├── content-model.ts            Markdown ↔ ProseMirror conversion
 │       │       ├── schema.ts                   Minimal ProseMirror schema
 │       │       ├── auto-close-plugin.ts        Auto-close for ```, **, _
+│       │       ├── formatting.ts               Formatting handlers (toggleBold, insertLink, etc.)
+│       │       ├── operation-history.ts        EditorOperation types + undo/redo stack
+│       │       ├── theme.ts                    CSS-variable theme system with presets
+│       │       ├── katex.ts                    Dynamic KaTeX import + render helpers
 │       │       ├── logger.ts                   Namespace-based debug logger
+│       │       ├── markdown-parser.ts          Lezer parser configuration
+│       │       ├── markdown-extensions.ts      Custom Lezer extensions
 │       │       └── markdown-rules/
-│       │           ├── engine.ts               MarkdownRuleEngine (3-stage pipeline)
+│       │           ├── engine.ts               MarkdownRuleEngine (2-stage pipeline)
 │       │           ├── types.ts                Shared type interfaces
 │       │           ├── inline-rules.ts         Inline syntax rules
 │       │           ├── block-rules.ts          Block syntax rules
-│       │           └── block-classifier.ts     First-line regex classifier
+│       │           └── block-classifier.ts     First-line regex classifier (paste only)
 │       ├── vite.config.ts            Library build (ESM, tailwind, vue)
 │       └── vitest.config.ts          Test runner configuration

+ 4 - 1
apps/dev/README.md

@@ -16,7 +16,7 @@ Opens at `http://localhost:5173`.
 
 | Page | Route | Features Demonstrated |
 |---|---|---|
-| Overview | `/` | Key concepts, Block API table (props + events) |
+| Overview | `/` | Key concepts, Block + Editor API tables (props + events) |
 | Basic Editing | `/basic-editing` | Headings `#`–`######`, paragraphs, horizontal rules |
 | Inline Marks | `/inline-marks` | Bold, italic, inline code, strikethrough, highlight, combined marks |
 | Tasks & Priorities | `/tasks` | Task states (TODO→DONE cycle), priority flags `[#A]` |
@@ -26,6 +26,9 @@ Opens at `http://localhost:5173`.
 | Code Blocks | `/code-blocks` | Fenced code blocks with language labels and CM6 syntax highlighting |
 | Properties & Dates | `/properties` | `key:: value` properties, date parsing |
 | Math | `/math` | Inline `$...$`, display `$$...$$`, mixed content |
+| Editor Shell | `/editor-shell` | Multi-block Editor component with insertion zones, split/merge |
+| Toolbar | `/toolbar` | Shared EditorToolbar bound to active block via `#toolbar` slot |
+| Themes | `/themes` | CSS-variable theme presets and overrides |
 
 Each page features multiple `<LiveExample>` sections — editable `<Block>` instances with a collapsible source code panel.
 

+ 78 - 11
packages/editor/README.md

@@ -38,12 +38,15 @@ app.use(EnesisEditor)
 ### Props
 
 | Prop | Type | Default | Description |
-|---|---|---|---|---|
+|---|---|---|---|
 | `content` (v-model) | `string` | required | Markdown content of the block |
 | `focused` | `boolean` | `false` | Whether the block receives focus on mount |
 | `cursorPosition` | `"start" \| "end" \| number` | — | Cursor placement on focus |
 | `markerMode` | `"live-preview" \| "always-visible"` | `"live-preview"` | When to show markdown delimiters |
 | `debug` | `string` | — | Namespace filter for debug logs (e.g. `"CodeBlockView"`, `"*"`) |
+| `onBoundaryExit` | `(dir: "up" \| "down") => void` | — | Called when code-block cursor exits at a doc boundary. |
+| `registry` | `FocusRegistry` | — | Cross-block focus registry (see `useFocusRegistry`). |
+| `depth` | `number` | — | List-item indent depth (0–10). |
 
 ### Emits
 
@@ -74,16 +77,68 @@ blockRef.value?.getContent()  // Current markdown content
 blockRef.value?.setContent(md)// Set content externally
 ```
 
+## `<Editor>` API
+
+The `Editor` component manages a list of blocks with insertion zones between them. Each block is a `* ` list item in the unified markdown string. The editor owns parsing, serialization, split/merge, indent/outdent, and undo/redo.
+
+### Props
+
+| Prop | Type | Default | Description |
+|---|---|---|---|
+| `content` (v-model) | `string` | required | Full document markdown (all blocks serialized). |
+| `focused` | `boolean` | `false` | Whether the first block receives focus on mount. |
+| `markerMode` | `"live-preview" \| "always-visible"` | `"live-preview"` | When to show markdown delimiters. |
+| `debug` | `string` | — | Namespace filter for debug logs. |
+| `theme` | `ThemeInput` | — | CSS-variable theme preset or overrides (see `theme.ts`). |
+
+### Scoped Slot: `#toolbar`
+
+The editor forwards a `#toolbar` slot with bindings from the focused block:
+
+```vue
+<Editor v-model:content="md">
+  <template #toolbar="{ handlers, selectionVersion, canUndo, canRedo, undo, redo }">
+    <EditorToolbar :handlers="handlers" :selection-version="selectionVersion" />
+  </template>
+</Editor>
+```
+
+| Binding | Type | Description |
+|---|---|---|
+| `handlers` | `FormattingHandlers \| null` | Handler object from the focused block, or `null` if blurred. |
+| `selectionVersion` | `number` | Incremented on each selection change — use as watch key. |
+| `canUndo` | `boolean` | Whether undo history has entries. |
+| `canRedo` | `boolean` | Whether redo history has entries. |
+| `undo` | `() => void` | Pop and apply the inverse of the last operation. |
+| `redo` | `() => void` | Re-apply the last undone operation. |
+
+### Emits
+
+| Event | Payload | Trigger |
+|---|---|---|
+| `focus` | `{ view, handlers }` | Any block received focus. |
+| `blur` | — | All blocks lost focus. |
+| `selection-change` | `{ from, to, empty }` | Selection changed in the active block. |
+
+### Exposed methods
+
+```ts
+const editorRef = ref<{ undo: () => void; redo: () => void; canUndo: Ref<boolean>; canRedo: Ref<boolean> }>()
+
+editorRef.value?.undo()
+editorRef.value?.redo()
+```
+
 ## Architecture
 
-### Parsing Pipeline (3-stage)
+### Parsing Pipeline
 
 ```
 [Raw block content string]
        ├── Phase 1: Lezer AST Walk
        │     ├─ enter → block rules (headings, blockquotes, callouts, tasks)
-       │     └─ leave → inline rules (bold, italic, code, links, refs, tags)
+       │     └─ leave → inline rules (bold, italic, code, links, refs, tags, highlights)
        ├── Phase 2: Property Extraction (key:: value)
@@ -118,6 +173,9 @@ Formatting is purely decorative — markdown syntax is stored as plain text in P
 | Inline Math | `$...$` | `md-math-inline` (+ KaTeX preview on blur) |
 | Display Math | `$$...$$` | MathBlock node view (+ KaTeX preview) |
 | Fenced Code Block | `` ```python `` / `~~~js` | CM6 node view |
+| Highlight | `^^text^^` | `md-highlight` |
+
+> **Priority flags** (`[#A]`, `[#B]`, `[#C]`) and **date emoji** (`📅 YYYY-MM-DD`) were removed from the parser — they render as plain text. Styling classes remain for backward compatibility.
 
 ### Pattern Detection
 
@@ -167,20 +225,29 @@ pnpm dev          # Watch mode rebuild
 |---|---|
 | `src/index.ts` | Public API surface |
 | `src/components/Block.vue` | ProseMirror block editor component |
+| `src/components/Editor.vue` | Multi-block shell with insertion zones, split/merge, undo/redo |
+| `src/components/InsertionZone.vue` | Invisible click target between blocks |
+| `src/components/EditorToolbar.vue` | Shared toolbar bound to active block's handlers |
 | `src/composables/useMarkdownDecorations.ts` | Decoration plugin (live-preview, caching) |
 | `src/composables/useBlockKeyboardHandlers.ts` | Keyboard event handler |
 | `src/composables/useCodeBlockView.ts` | CM6 NodeView for fenced code blocks |
+| `src/composables/useMathBlockView.ts` | KaTeX NodeView for display math blocks |
 | `src/composables/usePatternPlugin.ts` | Pattern detection plugin |
-| `src/lib/markdown-parser.ts` | Lezer parser configuration |
-| `src/lib/markdown-extensions.ts` | Custom Lezer node definitions (PageRef, BlockRef, Tag, Highlight, InlineMath, Task) |
-| `src/lib/katex.ts` | Dynamic KaTeX import + async/sync render helpers |
-| `src/lib/auto-close-plugin.ts` | Auto-close for ```, **, _ |
-| `src/lib/content-model.ts` | Markdown ↔ ProseMirror doc conversion |
-| `src/lib/formatting.ts` | Formatting handlers — toggle/wrap/insert for bold, link, math, page refs, block refs, tags, heading, task |
+| `src/composables/usePasteHandler.ts` | Multi-line paste split handler |
+| `src/composables/useFocusRegistry.ts` | Cross-block focus management |
+| `src/lib/block-parser.ts` | `splitMarkdownIntoBlocks` / `serializeBlocks` |
+| `src/lib/content-model.ts` | `contentToDoc(md)` / `docToContent(doc)` — Markdown ↔ ProseMirror |
+| `src/lib/formatting.ts` | Formatting handlers — toggle/wrap/insert for bold, link, math, page refs, tags, heading, task |
+| `src/lib/operation-history.ts` | `EditorOperation` types + undo/redo stack |
+| `src/lib/theme.ts` | CSS-variable theme system with presets |
+| `src/lib/katex.ts` | Dynamic KaTeX import + render helpers |
+| `src/lib/auto-close-plugin.ts` | Auto-close for ```, **, _ and bracket pairs |
 | `src/lib/logger.ts` | Namespace-based debug logger |
 | `src/lib/schema.ts` | ProseMirror schema |
-| `src/lib/markdown-rules/engine.ts` | 3-stage rule engine |
+| `src/lib/markdown-parser.ts` | Lezer parser configuration |
+| `src/lib/markdown-extensions.ts` | Custom Lezer node definitions (PageRef, BlockRef, Tag, Highlight, InlineMath, Task) |
+| `src/lib/markdown-rules/engine.ts` | MarkdownRuleEngine — Lezer AST walk |
 | `src/lib/markdown-rules/inline-rules.ts` | Inline decoration rules |
 | `src/lib/markdown-rules/block-rules.ts` | Block decoration rules |
 | `src/lib/markdown-rules/types.ts` | Shared type definitions |
-| `src/lib/markdown-rules/block-classifier.ts` | Regex first-line classifier |
+| `src/lib/markdown-rules/block-classifier.ts` | Regex first-line classifier (paste only) |