[docs-infra] Add a headless source API - #1783
Conversation
Deploy previewBundle sizeTotal Size Change: 🔺+2.09KB(+0.06%) - Total Gzip Change: 🔺+473B(+0.05%) Show details for 71 more bundles@mui/internal-docs-infra/useCode parsed: 🔺+1.1KB(+1.01%) gzip: 🔺+260B(+0.72%) PerformanceTotal duration: 16.25 ms +0.67 ms(+4.3%) | Renders: 5 (+0) | Paint: 58.98 ms +3.20 ms(+5.7%)
5 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
A host with its own editor — Material UI's `DemoEditor`, with its styling, focus hint, and error overlay — had no way to drive a docs-infra block: editing meant adopting docs-infra's editor DOM. `editorMode: 'headless'` mounts no editor. The rendered file stays highlighted, read-only source, and `useCode` returns what a host needs to edit it: `selectedFileSource` as plain text, decoded from whichever shape the source arrived in; `selectedFileProjection` for a collapsed view; `selectedFileLanguage` and `selectedFileOriginalName`; `selectedFileEditable`; and `activateEditing` to warm the edit-time engine on focus. Edits go back through the same `setSource` the internal editor uses, so the controller, reset behaviour, and preview are unchanged. Decoding is skipped in `'internal'` mode, where nothing reads the text and a `hastCompressed` payload would pay an inflate for it. `useFileNavigation` also resolves the selected file's projection now, and forwards it to `<Pre>` — the precompute has produced one since the preview resolver landed, but nothing carried it to the editor.
260a65b to
0d4b10e
Compare
9e45aac to
b4dde9f
Compare
Ninth in the docs-infra migration stack, on top of #1782.
A host with its own editor — Material UI's
DemoEditor, with its styling, focus hint, and error overlay — had no way to drive a docs-infra block: editing meant adopting docs-infra's editor DOM.editorMode: 'headless'mounts no editor. The rendered file stays highlighted, read-only source, anduseCodereturns what a host needs to edit it:selectedFileSource— plain text, decoded from whichever shape the source arrived in (string, HAST, serialized HAST, or a compressed payload decoded through the block's fallback dictionary).nullin'internal'mode, where nothing reads it and ahastCompressedpayload would pay an inflate for it.selectedFileProjection— the slice a collapsed view is edited through.selectedFileLanguage,selectedFileOriginalName— the grammar and the canonical, pre-transform name.selectedFileEditable,activateEditing()— whether an edit is accepted now, and a way to warm the edit-time engine on focus.Edits go back through the same
setSourcethe internal editor uses, so the controller, the reset behaviour, and the rendered preview are unchanged.useFileNavigationalso resolves the selected file's projection and forwards it to<Pre>. The precompute has produced one since #1781, but nothing carried it to the editor.Gate: 4 new browser tests across chromium, firefox, and webkit — a host textarea edits through the headless API and the rendered preview follows, and the internal editor mounts in
'internal'mode but not in'headless'— plus 5,569 unit tests, a clean typecheck, lint, anddocs:validate.