A CodeMirror-like code editor implemented in MoonBit, targeting wasm-gc with DOM FFI
| directory | contents |
|---|---|
| core/ | text, ranges, changes, selections (pure, unit tested) |
| state/ | facets, fields, effects, transactions, history (pure) |
| highlight/ | incremental tokenizers and line cache (pure) |
| search/ | search/replace, folding, bracket matching (pure) |
| input/ | keymap, commands, multi-cursor (pure) |
| ffi/ | wasm DOM imports and code-unit string marshalling |
| view/ | layout, geometry, rendering, mouse/scroll dispatch |
| editor/ | assembled editor: extensions, options, event entry points |
| main/ | wasm exports (cm_*) and the editor registry |
| js/ | DOM runtime, stylesheet, Node DOM shim, e2e tests, loader |
| demo/ | static demo page |
export MOONBIT_INSTALL_DEV=1
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
moon version --all # moonc v0.10.14+...moon check --target wasm-gc # type check
moon test --target wasm-gc # 137 unit tests (pure packages)
moon build --target wasm-gc # _build/wasm-gc/debug/build/main/main.wasm
node js/e2e.mjs # 39 end-to-end tests through a DOM shim
node js/browser_e2e.mjs # 84 real-browser tests (Chromium over CDP)
moon fmt && moon infopython3 -m http.server 8000
# open http://localhost:8000/demo/<link rel="stylesheet" href="./js/codemoonbit.css" />
<div id="editor" style="height: 400px"></div>
<script type="module">
import { createEditor } from "./js/browser.js";
const editor = await createEditor(document.getElementById("editor"), {
value: "fn main {\n println(\"hello\")\n}\n",
language: "moonbit",
lineNumbers: true,
theme: "light",
});
editor.focus();
editor.onUpdate(() => console.log("document changed"));
</script>Install
Download zipA CodeMirror-like code editor implemented in MoonBit, targeting wasm-gc with DOM FFI