CodeMirror stack 3/4: datasette-sql-editor ESM primitives module#2836
Draft
asg017 wants to merge 1 commit into
Draft
CodeMirror stack 3/4: datasette-sql-editor ESM primitives module#2836asg017 wants to merge 1 commit into
asg017 wants to merge 1 commit into
Conversation
Single source of truth for the CodeMirror setup: SQLiteDialect, createSqlEditor() (delegable history with host undo/redo forwarding, hostChange annotation for echo suppression, submit/escape callbacks, fixed-tooltip mode, per-editor Compartment updateSchema), and datasetteSchema() which fetches /-/editor-schema.json and maps it to a lang-sql SQLNamespace identical to the server-inlined shape. cm-editor.js is now a thin consumer; rollup emits both the IIFE and an importable ESM bundle. Submit key is Mod-Enter (Cmd on mac as before, now also Ctrl elsewhere) plus Shift-Enter. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 3 of the CodeMirror stack (integration view: #2833). Pure addition — no behavior change to any page.
What
New ESM module
datasette/static/datasette-sql-editor.js(built to an importabledatasette-sql-editor.bundle.js), now the single source of truth for Datasette's CodeMirror setup — the IIFE entrycm-editor.jsbecomes a thin consumer of it.Exports:
SQLiteDialect— the curated dialect (moved here)createSqlEditor(parent, opts)→{view, updateSchema(conf), destroy(), value}with:history: falsebuilds the basicSetup-equivalent without CM undo and forwards Mod-z / Mod-y / Mod-Shift-z toonHostUndo/onHostRedo— for hosts whose collab/ProseMirror stack owns undo (datasette-paper's headline requirement)hostChangeannotation: host-pushed edits don't echo back throughonChangeonSubmit(Mod-Enter / Shift-Enter, highest precedence),onEscape,fixedTooltips(for overflow-clipped containers),extensions,lineWrappingdatasetteSchema(baseUrl, database)— fetches/-/editor-schema.json(part 2) and maps it to a lang-sqlSQLNamespaceidentically to the server-inlined shapeEditorView,EditorState,Compartment,keymap,sql, …) so plugin code shares one CodeMirror instance per page — avoiding the classic duplicate-@codemirror/statebreakageWhy this shape
datasette-paper's CodeMirror branch built an entire parallel CM stack with an explicit seam (
cmCore.ts) documented as "the seam for a future swap to a Datasette-core-provided CM setup" — this module is that setup. The custom element in part 4 builds on it; hosts needing deep integration (minimal-diff sync, delegated history) use these primitives directly.Review focus
The
createSqlEditoroptions surface — it's the public API contract for embedders.baseSetup()replicatescodemirror'sbasicSetupextension-for-extension (verified against the package source) minus optional history.Testing
Both bundles build (
npm run build:codemirror); IIFE behavior preserved (Datasette's own pages route through the refactored entry); full suite green. Rollup inlines the shared module into the IIFE so pages still make one script fetch.The stack
/-/editor-schema.json,defaultTabledatasette-sql-editorESM primitives<datasette-sql-editor>element + core-page dogfoodEach PR is based on the previous branch; merge top-down, retargeting the next base to
mainas each lands. Bundle files (*.bundle.js) conflict on rebase by nature — resolve by re-runningnpm run build:codemirror, never by merging. Integration view of the whole branch: #2833.🤖 Generated with Claude Code