| description | |
|---|---|
| alwaysApply | false |
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Development:
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production build
Testing:
npm run test:unit- Run unit tests with Vitestnpm run test:e2e- Run end-to-end tests with Playwrightnpm run test- Run both unit and e2e tests
Testing Guidelines:
- DO NOT run tests automatically (test:unit, test:e2e, test, etc.)
- The user prefers to run all tests manually
- Focus on implementing code changes and let the user handle testing
Implementation Guidelines:
- Do exactly what the user asks for - one step at a time
- Do NOT think 4 steps ahead or add extra features/improvements
- Only implement the specific change requested
- You can suggest what the next step could be, but don't implement it
Refactoring Guidelines:
- During refactors, make ONLY the minimal changes needed (e.g., renaming APIs)
- Do NOT "improve" or restructure logic while refactoring
- If you see something that could be improved, note it separately for a future task
- Refactoring and improving are two separate activities - never combine them
Code Style:
- Use snake_case for all variable names, function names, and identifiers
- This applies to JavaScript/TypeScript code, test files, and any new code written
What to NOT change (keep camelCase):
window.getSelection()- native APIdocument.activeElement- native APInavigator.clipboard- native APIaddEventListener- native APIpreventDefault()- native APIstopPropagation()- native APIgetRangeAt()- native API- Svelte event handlers:
onclick,onmousedown, etc. - DOM properties:
innerHTML,textContent,nodeType, etc.
Pattern: If it's a web platform API or Svelte API, keep camelCase. If it's our custom variable/function name, use snake_case.
File Extensions:
- Files using Svelte runes (
$state,$derived,$effect, etc.) must use.svelte.jsor.svelte.tsextension
Documentation Style:
- Use sentence case for all headings in documentation (README.md, etc.)
- Use sentence case for code comments
- Sentence case means: capitalize only the first word and proper nouns
- Exception: "Svedit" is always capitalized as it's a proper noun (the product name)
- Examples:
- ✓ "Getting started" (not "Getting Started")
- ✓ "Why Svedit?" (not "Why svedit?") - Svedit is a proper noun
- ✓ "Developing Svedit" (not "Developing svedit") - Svedit is a proper noun
- ✓ "Document-scoped commands" (not "Document-Scoped Commands")
- ✓ "Create a new user" (not "Create a New User")
- ✓ "API reference" (not "API Reference")
- This applies to: markdown headings, JSDoc comments, inline comments, commit messages
Svedit is a rich content editor template built with Svelte 5 that uses a graph-based data model.
Document Model:
Document- Central document class with state management, transactions, and historyTras- Handles atomic operations on the document- Documents are represented as graphs of nodes with properties and references
Selection System:
- Supports text, node, and property selections
- Maps between internal selection model and DOM selection
- Handles complex selection scenarios like backwards selections and multi-node selections
Key Components:
Svedit.svelte- Main editor component with event handling and selection managementNodeArrayProperty.svelte- Renders containers that hold sequences of nodesNode.svelte- Wrapper component for document nodes that handles node gap placement and viewport cullingAnnotatedTextProperty.svelte- Handles annotated text rendering and editing- Node components (
Story,List, etc.) - Render specific content types
Content is defined through schemas that specify:
- Node types and their properties
- Property types:
string,integer,boolean,string_array,annotated_text,node,node_array - Reference relationships between nodes
- Default types for node arrays
- Raw document data is loaded into
Session - Changes are made through transactions for undo/redo support
- Selection state is synchronized between internal model and DOM
- Components render content based on document state and schema definitions