Skip to content

[docs-infra] Add editable source projections - #1780

Draft
brijeshb42 wants to merge 1 commit into
di-migration-textarea-editorfrom
di-migration-source-projections
Draft

[docs-infra] Add editable source projections#1780
brijeshb42 wants to merge 1 commit into
di-migration-textarea-editorfrom
di-migration-source-projections

Conversation

@brijeshb42

Copy link
Copy Markdown
Contributor

Sixth in the docs-infra migration stack, on top of #1779.

A collapsed code block had to expand before it could be edited: the textarea holds plain text and has no notion of hidden rows. A projection names the contiguous slice the collapsed view shows, so the editor holds that slice and patches each edit back into the complete source.

  • EditableSourceProjection on Transforms[key], VariantExtraFiles[file], VariantCode, ControlledVariantCode, and TransformedFile. hasCollapse/hasCollapseInFocus are untouched.
  • createEditableSourceProjection({ fullSource, previewSource }) resolves a preview the way Material UI's Demo does — strip leading whitespace from every line of both sides, then match as a substring — so it accepts exactly the preview files Material accepts. Over Material's corpus, all 392 .tsx.preview files with a .tsx sibling resolve to one region, none ambiguously, and every projection patches back byte-identical. Two deliberate differences: the projection records the indentation to restore, and a fragment matching more than once is refused rather than spliced into the first occurrence.
  • createFocusedSourceProjection(source, root) is the target producer, deriving the window from the parsed tree. It and <Pre>'s caret bounds now share one getCollapsedFrameWindow walk, so the edited region and the caret bounds cannot disagree.
  • setSource grows a fifth argument carrying the projection an edit was made through; useSourceEditing records it on the controlled file.
  • Pre takes sourceProjection and no longer expands on activation when it has one.

Gate: 27 browser tests across chromium, firefox, and webkit — the new one edits a collapsed block through its projection and asserts it never expands — plus a clean typecheck and lint.

@brijeshb42 brijeshb42 added the scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). label Aug 14, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Aug 14, 2026

Copy link
Copy Markdown

Deploy preview

Bundle size

Total Size Change: 🔺+1.42KB(+0.04%) - Total Gzip Change: 🔺+586B(+0.07%)
Files: 71 total (0 added, 0 removed, 3 changed)

Show details for 71 more bundles

CodeEditorparsed: 🔺+549B(+14.55%) gzip: 🔺+218B(+12.86%)
@mui/internal-docs-infra/useDemoparsed: 🔺+438B(+0.35%) gzip: 🔺+173B(+0.41%)
@mui/internal-docs-infra/useCodeparsed: 🔺+431B(+0.40%) gzip: 🔺+195B(+0.54%)
@mui/internal-docs-infra/abstractCreateDemoparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateDemoClientparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateStreamparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/ChunkProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/cliparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeControllerContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeExternalsContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighterparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/errorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CoordinatedLazyparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CoordinatedLazy/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoDataparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoData/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemapparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemap/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCodeWindowparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCoordinatedparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCopierparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCrossTabStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useDemoControllerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useErrorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useLocalStorageStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/usePreferenceparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useScrollAnchorparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearchparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearch/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useStreamparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useStream/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useUrlHashStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/withDocsInfraparsed: 0B(0.00%) gzip: 0B(0.00%)
addLineGuttersparsed: 0B(0.00%) gzip: 0B(0.00%)
BuildEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeContextparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeHighlighterChunkparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeHighlighterClientparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeInitialSourceLoaderparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeSourceLoaderparsed: 0B(0.00%) gzip: 0B(0.00%)
compileCssWithPostcssparsed: 0B(0.00%) gzip: 0B(0.00%)
createFrameparsed: 0B(0.00%) gzip: 0B(0.00%)
createParseSourceWorkerClientparsed: 0B(0.00%) gzip: 0B(0.00%)
EditingEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
embedTransformsparsed: 0B(0.00%) gzip: 0B(0.00%)
enhanceCodeEmphasisparsed: 0B(0.00%) gzip: 0B(0.00%)
findExpandingRangesparsed: 0B(0.00%) gzip: 0B(0.00%)
getHastTextContentparsed: 0B(0.00%) gzip: 0B(0.00%)
grammarLoadersparsed: 0B(0.00%) gzip: 0B(0.00%)
grammarsparsed: 0B(0.00%) gzip: 0B(0.00%)
isFrameSpanparsed: 0B(0.00%) gzip: 0B(0.00%)
loadIsomorphicCodeVariantparsed: 0B(0.00%) gzip: 0B(0.00%)
parseSourceparsed: 0B(0.00%) gzip: 0B(0.00%)
rolldown-runtimeparsed: 0B(0.00%) gzip: 0B(0.00%)
source.cssparsed: 0B(0.00%) gzip: 0B(0.00%)
source.jsparsed: 0B(0.00%) gzip: 0B(0.00%)
source.jsonparsed: 0B(0.00%) gzip: 0B(0.00%)
source.mdxparsed: 0B(0.00%) gzip: 0B(0.00%)
source.shellparsed: 0B(0.00%) gzip: 0B(0.00%)
source.tsparsed: 0B(0.00%) gzip: 0B(0.00%)
source.tsxparsed: 0B(0.00%) gzip: 0B(0.00%)
source.yamlparsed: 0B(0.00%) gzip: 0B(0.00%)
text.html.basicparsed: 0B(0.00%) gzip: 0B(0.00%)
text.mdparsed: 0B(0.00%) gzip: 0B(0.00%)
TransformEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
transpileSourceparsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Performance

Total duration: 19.43 ms +2.35 ms(+13.7%) | Renders: 5 (+0) | Paint: 67.21 ms +3.29 ms(+5.1%)

Test Duration Renders
HeavyList mount 10.06 ms 🔺+1.72 ms(+20.6%) 1 (+0)

6 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@brijeshb42
brijeshb42 force-pushed the di-migration-source-projections branch from 2853dcd to 5859a27 Compare August 14, 2026 16:37
A collapsed code block had to expand before it could be edited: the
textarea holds plain text and has no notion of hidden rows. A projection
names the contiguous slice the collapsed view shows, so the editor can
hold that slice and patch each edit back into the complete source.

`createEditableSourceProjection` resolves a preview the way Material UI's
`Demo` does — strip the leading whitespace from every line of both sides,
then find the fragment as a substring — so it accepts exactly the preview
files Material accepts. Run over Material's corpus, all 392 `.tsx.preview`
files with a `.tsx` sibling resolve to one region, none ambiguously, and
every projection patches back byte-identical.

Two differences, both because docs-infra displays the patched source
rather than only compiling it: the projection records the indentation to
restore, and a fragment matching more than once is refused instead of
spliced into the first occurrence.

`createFocusedSourceProjection` is the target producer, deriving the
window from the parsed tree. Both it and `<Pre>`'s caret bounds now read
one `getCollapsedFrameWindow` walk, so the region the editor edits and the
region the caret is held inside cannot disagree.

`setSource` grows a fifth argument carrying the projection an edit was
made through, and the controlled file records it alongside the edited
source.
@brijeshb42
brijeshb42 force-pushed the di-migration-textarea-editor branch from dcf13d1 to 7e52522 Compare August 14, 2026 18:43
@brijeshb42
brijeshb42 force-pushed the di-migration-source-projections branch from 5859a27 to 4c0bc69 Compare August 14, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant