This document defines how CodeMirror is integrated in @knighted/develop and what constraints must be preserved when changing editor behavior.
CodeMirror is used for both authoring panels:
- Component panel (JSX source)
- Styles panel (CSS, CSS Modules, Less, Sass source)
The integration is CDN-first and must keep textarea fallback behavior.
src/cdn.js: CDN import keys and provider candidatessrc/editor-codemirror.js: shared CodeMirror runtime + editor factorysrc/app.js: editor initialization, fallback handling, and value wiringsrc/styles.css: editor host styling
The app initializes CodeMirror asynchronously.
- On success: both textareas are hidden and CodeMirror views are mounted.
- On failure: textareas remain active and the app keeps rendering normally.
This fallback is required. Editor failures must never block rendering.
CodeMirror packages are loaded with importFromCdnWithFallback and entries in cdnImportSpecs.
Use unversioned esm specifiers for the CodeMirror package group:
@codemirror/state@codemirror/view@codemirror/commands@codemirror/autocomplete@codemirror/language@codemirror/lang-javascript@codemirror/lang-css
Reason: this lets esm.sh resolve one compatible dependency graph. Mixing pinned versions can load multiple @codemirror/state instances and trigger:
Unrecognized extension value in extension set ([object Object])
Keep jspmGa candidates as fallback entries.
src/editor-codemirror.js should continue to include these extensions:
- line numbers
- active line and gutter highlight
- bracket matching
- close brackets
- autocompletion
- syntax highlighting
- history keymap
- default keymap
- completion keymap
- close-bracket keymap
indentOnInput- tab size and indent unit
Language mapping should remain:
- component editor:
javascript-jsx - styles editor:
cssandmodule-> css languageless-> less languagesass-> sass language
In src/app.js:
- Keep
getJsxSource()andgetCssSource()abstraction so both CodeMirror and textarea fallback paths work. - Keep
initializeCodeEditors()non-blocking (void initializeCodeEditors()). - Keep style language reconfiguration on style mode change.
- Keep textarea input listeners in place for fallback mode.
When modifying editor integration:
- Run
npm run lint. - Run
npm run devand verify:- CodeMirror mounts in both panels.
- Textareas are hidden on success.
- Auto-close and indentation work while typing.
- Style mode change reconfigures language and still renders.
- Fallback path works if a CodeMirror import fails.
- Run
npm run buildwhen CDN import keys are changed.
If the UI still looks like plain textarea behavior:
- Check for
.cm-editornodes in devtools. - Check whether
textarea.source-textarea--hiddenis present. - Check status text for editor fallback message.
- Hard reload to clear cached CDN module responses.
- Inspect console for duplicate-state error:
Unrecognized extension value in extension set ([object Object])
If duplicate-state error returns, first verify esm CodeMirror specifiers in src/cdn.js are still unversioned for the full package group.