Skip to content

aionbuilders/codex

Repository files navigation

πŸš€ Codex Editor

A modular block editor experiment with single ContentEditable.
Built with Svelte 5 runes for fine-grained reactivity.

npm version License: MIT Svelte 5 Status: Early Alpha

⚠️ Not production ready. Active development. Everything may change.


What is Codex?

An experimental approach to building a block-based rich text editor using:

  • Single ContentEditable (preserves browser behavior)
  • Real block architecture (not just visual)
  • Svelte 5 runes for reactive state management

Currently, it's a working prototype that can handle basic text editing with paragraphs, line breaks, and selection.


βœ… What Actually Works Today

Core Features Implemented

  • βœ… Basic text editing in paragraphs
  • βœ… Line breaks with Shift+Enter
  • βœ… Single block selection and navigation
  • βœ… Block hierarchy (Codex β†’ Paragraph β†’ Text/Linebreak)
  • βœ… Transaction system with automatic rollback
  • βœ… Strategy pattern for keyboard handling
  • βœ… Reactive coordinates (each block knows its position)
  • βœ… Debug panel to visualize structure

Partially Working

  • 🟑 Multi-block selection (detection works, operations buggy)
  • 🟑 Block deletion (single block OK, multi-block buggy)
  • 🟑 Focus management (works but uses retry pattern = code smell)

Structure Ready (Not Functional)

  • πŸ“¦ Text styling (properties exist: bold, italic, etc. - no UI/shortcuts)
  • πŸ“¦ History system (tracks transactions - no undo/redo)
  • πŸ“¦ Preset system (MinimalPreset exists, not really configurable)

❌ What Doesn't Work Yet

Not Implemented At All

  • ❌ Copy/Paste
  • ❌ Undo/Redo (Ctrl+Z/Y)
  • ❌ Text formatting UI
  • ❌ Public API (getValue, setValue, etc.)
  • ❌ Touch/Mobile support
  • ❌ Lists, Headings, Tables, Images, etc.
  • ❌ Plugin system
  • ❌ Serialization (HTML, Markdown export)

πŸš€ Current Usage

Installation

npm install @aionbuilders/codex

Basic Setup (What works today)

import { Codex } from '@aionbuilders/codex';
import { Paragraph } from '@aionbuilders/codex/blocks';

// Create editor with initial content
const codex = new Codex({
  in: Codex.data([
    Paragraph.data("First paragraph\nwith linebreak"),
    Paragraph.data("Second paragraph")
  ])
});

// Get the Svelte component
const Editor = codex.component;

// In your Svelte component:
// <Editor {codex} />

With Debug Panel

<script>
  import { Codex } from '@aionbuilders/codex';
  import Debug from '@aionbuilders/codex/debug/Debug.svelte';
  
  const codex = new Codex();
</script>

<div>
  <Editor {codex} />
  <Debug {codex} />
</div>

That's it. That's all you can do right now.


πŸ—οΈ Architecture (The Good Part)

The architecture is actually solid and the main reason this project has potential:

Block Hierarchy

Codex (root)
└── Paragraph (container)
    β”œβ”€β”€ Text (leaf)
    β”œβ”€β”€ Linebreak (leaf)
    └── Text (leaf)

Every Block Has:

class Block {
  // Position tracking (reactive)
  start = $derived(/* calculated */);
  end = $derived(/* calculated */);
  
  // Selection state (reactive)
  selected = $derived(/* from selection API */);
  
  // Hierarchy
  parent    // Parent block
  before    // Previous sibling
  after     // Next sibling
  
  // Operations
  prepareEdit()    // Returns operations
  prepareInsert()  // Returns operations
  prepareRemove()  // Returns operations
}

Transaction System

// All mutations go through transactions
codex.tx([
  new TextEdition(block, { from: 0, to: 5, text: 'Hello' })
]).execute();  // Can rollback on error

Strategy Pattern

new Strategy(
  'multi-block-delete',
  (codex, context) => /* can handle? */,
  (codex, context) => /* handle it */
).tag('keydown', 'delete');

πŸ”¬ Technical Details

What's Good

  • Clean separation between state (.svelte.js) and UI (.svelte)
  • Reactive coordinates update automatically with Svelte 5 runes
  • Event bubbling through block hierarchy
  • Extensible via manifests and capabilities

What's Questionable

  • Focus retry pattern (up to 10 requestAnimationFrame retries)
  • Many $derived computations (performance unknown)
  • Complex prepare/execute/apply pattern (maybe overengineered)
  • Normalizations in effects (risk of infinite loops)

Dependencies

  • Svelte 5.34+
  • SvelteKit (for development)
  • No other runtime dependencies

πŸ—ΊοΈ Realistic Roadmap

Phase 1: Fix Core (Current)

  • Fix multi-block selection deletion
  • Stabilize focus without retries
  • Add copy/paste basic
  • Add undo/redo

Phase 2: Make Usable

  • Text styling with UI
  • Basic public API
  • Performance testing
  • Serialization

Phase 3: Add Features

  • More block types
  • Plugin system
  • Mobile support

🀝 Contributing

This is an experiment. If you're interested in the approach:

  1. Try it out and report what breaks (spoiler: lots)
  2. Fix bugs in multi-block selection (critical path)
  3. Add tests (there are none)
  4. Discuss architecture in issues

Dev Setup

git clone https://github.com/aionbuilders/codex
cd codex
npm install
npm run dev  # Starts dev server

Code Structure

src/lib/
β”œβ”€β”€ states/          # Core logic (Svelte 5 runes)
β”‚   β”œβ”€β”€ codex.svelte.js
β”‚   β”œβ”€β”€ block.svelte.js
β”‚   └── blocks/
β”‚       β”œβ”€β”€ paragraph.svelte.js
β”‚       └── text.svelte.js
β”œβ”€β”€ components/      # Svelte components
β”œβ”€β”€ strategies/      # Event handlers
└── utils/          # Helpers

πŸ’­ Philosophy & Vision

The Vision (not reality yet):

  • One editor that scales from textarea to Notion
  • Modular enough to use anywhere
  • Respects browser native behavior

Current Reality:

  • Interesting architecture
  • Basic editing works
  • Lots of bugs
  • No production use cases

⚠️ Important Disclaimers

  1. This is NOT production ready
  2. APIs will change completely
  3. Many basic features don't work
  4. No tests, no docs, no stability
  5. Copy/paste doesn't work at all

If you need a working editor today, use:


πŸ“œ License

MIT Β© Killian Di Vincenzo


This is an experiment in progress.

Interested in the approach? Star & watch the repo.
Want to help? Pick an issue and dive in.
Need an editor today? Use something else.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •