How mweiss/elm-rte-toolkit works
Project type and purpose
• This is an open-source Elm library/toolkit (“Rich Text Editor Toolkit”) plus a demo application.
• The library provides a programmable specification, commands, model, and view logic for building cross-platform rich-text editors in Elm.
• The demo folder is a standalone Create-Elm-App project that exercises the library as a WebComponent.
File structure
• Top-level folders and files:
• src/RichText – all Elm modules that make up the library:
– Config (spec, commands, decorations, element/mark definitions)
– Model (state, node, inline element, history, selection, etc.)
– Commands (insert, delete, wrap, lift, etc.)
– Html renderer
– Internal modules (DOM integration, events, history management, mutation observers)
– Editor entry point and Node abstraction
• demo – example app that imports and uses the compiled library as an ES6 web component
– elm.json, package.json, public/index.html, CSS, Elm sources (Main.elm orchestrating pages, routes, editor instance)
– js/elmEditor.js – compiled JS wrapper exporting the Elm editor as a custom element
– build/test scripts (build.sh, elm-app start, elm-test)
• js/elmEditor.js – the library’s pre-compiled WebComponent wrapper for non-bundler usage
• publish.sh – script to publish the package
README for additional insights
• Confirms that js/elmEditor.js + webcomponents polyfill turn the Elm editor into a custom element
• Demo is bootstrapped with Create-Elm-App; tests live in demo/tests
• Emphasis on using browser events and mutation observers to detect editor changes
a. Main components
• Browser environment
– WebComponents polyfill (optional)
– Custom Element (<elm-editor>) from js/elmEditor.js
• Elm compiled code
– Entry point: RichText.Editor
– Core subsystems in Elm:
· Config & Spec (drives allowed document structure)
· Model (document state, selection, history)
· Commands (user-driven transformations)
· Html Renderer (Virtual DOM ↔ real DOM)
· Internal integration (BeforeInput, keydown, paste, mutation observers)
• Demo application (Create-Elm-App)
– Elm Main app orchestrating pages, routes, editor instances
– Static assets (CSS, index.html)
• Build & Test Tools
– elm-app, elm-test, build.sh, publish.sh
b. Relationships & interactions
1. User interacts with the editor in the page (click, keypress, paste)
2. Browser fires DOM events → WebComponent wrapper captures events → forwards to Elm (ports or direct message)
3. Elm Editor module invokes Internal event handlers → translates to Commands → updates Model
4. Model change triggers Html Renderer → Virtual DOM diff → actual DOM updates inside the custom element
5. Mutation observers detect contenteditable mutations → feed back into Elm for consistency
6. Demo app uses the custom element API to instantiate/configure the editor with a Spec
c. Architectural patterns & design principles
• Modular Elm code split by concern (Config, Model, Commands, Renderer, Internals)
• Functional core with immutable Model, pure Command transformations
• Event-driven architecture bridging browser I/O and functional update loop
• WebComponent boundary isolates editor implementation from host page
d. Key technologies & libraries
• Elm (0.19) for core logic
• WebComponents (custom-elements, optional polyfills)
• create-elm-app for demo
• MutationObserver API, contenteditable for I/O
• CSS for styling the editor container