feat(admin): codeeditor field on CodeMirror 6, loaded lazily

- Pin the seven approved CodeMirror/lezer packages exactly; lockfile integrity matches the decision note
- Lazy createCodeEditor with Go {{ }} highlighting, form hotkeys kept, Tab unbound
- Loading skeleton, chunk-failure textarea fallback, read-only pre

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-13 13:28:02 +01:00
parent 7e2c01172f
commit 9975cf4b52
6 changed files with 597 additions and 26 deletions

View File

@@ -34,11 +34,14 @@ function field(overrides: Partial<FormField> = {}): FormField {
}
async function editorReady(root: HTMLElement): Promise<HTMLElement> {
return vi.waitFor(() => {
const content = root.querySelector<HTMLElement>('.cm-content')
expect(content).not.toBeNull()
return content!
})
return vi.waitFor(
() => {
const content = root.querySelector<HTMLElement>('.cm-content')
expect(content, root.innerHTML.slice(0, 500)).not.toBeNull()
return content!
},
{ timeout: 15000 },
)
}
beforeEach(() => {
@@ -85,7 +88,7 @@ describe('codeeditor keyboard in a real browser engine', () => {
attachTo: host,
})
await flushPromises()
const content = await editorReady(wrapper.element as HTMLElement)
const content = await editorReady(form)
content.focus()
expect(document.activeElement).toBe(content)
@@ -120,16 +123,20 @@ describe('codeeditor keyboard in a real browser engine', () => {
attachTo: document.body,
})
await flushPromises()
const content = await editorReady(wrapper.element as HTMLElement)
const content = await editorReady(document.body)
content.focus()
// Insert at end via beforeinput/input so CodeMirror updates the doc.
document.execCommand('selectAll')
// Replace the document through the contenteditable surface CodeMirror owns.
const selection = window.getSelection()
const range = document.createRange()
range.selectNodeContents(content)
selection?.removeAllRanges()
selection?.addRange(range)
document.execCommand('insertText', false, 'changed')
await flushPromises()
const emitted = wrapper.emitted('update:modelValue')
expect(emitted).toBeTruthy()
expect(emitted!.at(-1)).toEqual(['changed'])
await vi.waitFor(() => {
const emitted = wrapper.emitted('update:modelValue')
expect(emitted?.at(-1)).toEqual(['changed'])
})
})
})