Core Architecture
ProseKit’s architecture is built around three key concepts:- Extensions - Modular building blocks that add functionality
- Facets - A hierarchical system for composing extensions
- Editor - The central orchestrator that brings everything together
The Facet System
At the heart of ProseKit is a facet system that allows extensions to contribute functionality in a composable way. Each facet represents a specific aspect of editor configuration:Facets use a reducer pattern - they accept an array of inputs and produce a single output. This allows multiple extensions to contribute to the same configuration.
Facet Tree Structure
Facets are organized in a tree structure with therootFacet at the top:
- Singleton: Only one output is produced (e.g., schema, state)
- Non-singleton: Multiple outputs are merged (e.g., plugins)
Extension Base Class
All extensions inherit fromBaseExtension (packages/core/src/facets/base-extension.ts):
The
Tuple5 type represents five priority levels (0-4), with 2 being the default priority. This allows extensions to control their precedence.Priority System
ProseKit uses a 5-level priority system for extensions:Extension Composition
ProseKit provides theunion() function to compose multiple extensions:
union() function:
- Flattens nested extensions into a single array
- Creates a
UnionExtensionImplthat combines all facet trees - Preserves full type information for TypeScript autocomplete
All extensions are flattened into a single array
Each extension creates its facet tree using
createTree()
Trees are merged using
unionFacetNode() which:
- Combines inputs from all extensions
- Merges child facet nodes recursively
- Applies reducers to produce final output
TypeScript extracts all nodes, marks, and commands from the union
Data Flow
Here’s how data flows through ProseKit’s architecture:Root Output Structure
The facet tree produces a root output (packages/core/src/facets/root.ts):Framework Agnostic Design
ProseKit’s core is framework-agnostic:- Core Package (
packages/core/src/): Pure TypeScript, no UI framework dependencies - Framework Integrations: React, Vue, Svelte, Solid, Preact packages provide hooks and components
- Web Components: Standard web components for framework-free usage
Type Safety
ProseKit leverages TypeScript’s type system extensively:- Autocomplete: IDE shows all available nodes, marks, and commands
- Type Checking: Invalid operations are caught at compile time
- IntelliSense: Full documentation in tooltips
Design Principles
- Composability: Extensions can be freely combined using
union() - Type Safety: Full TypeScript support with inference
- Framework Agnostic: Core logic separate from UI framework
- Extensibility: Easy to add custom extensions
- Performance: Facet trees are cached and computed lazily
- Immutability: Extensions are immutable; editor state changes create new states
Next Steps
Editor
Learn about the Editor lifecycle and API
Extensions
Deep dive into the extension system
Commands
Understand the command system
Schema
Learn about document schemas