Repository navigation
Let lf-code run on a plain HTML page, and declare package keys as data Leaf reads - #4574
Merged
Merged
Conversation
…a Leaf reads `lf-code` now loads and draws on a plain HTML page that maps `/runtime/` and `/vendor/` with its own import map, as `lf-chart` does since #4542. On a Leaf page it behaves as before. Its import graph is 14 runtime modules and 80 KB of source, down from 182 and 2,271 KB. `lf-chart` draws to its own box's height, so a plain host no longer has to write `data-lf-height`. Off Leaf a widget binds no keys, shows no Copy control and writes no quiet word. Leaf adds each of those by reading what the widget declares on its elements, rather than the widget calling into Leaf. **Keys are data on the element.** A widget sets an element's `lfCommands` to the scope (`{title, rows, when, ready, escape, claims}`, the rows unchanged, or a `commandScope()` value) and calls `commandsChanged(element)`, a portable helper that dispatches a bubbling, composed `lf-commands` event. Leaf's register (`keyboard/scopes.js`) reads the declaration from a window listener: a new one stands in place of the last, `null` withdraws it, and the same one standing means something its rows read changed, so the register repaints, as `paintKeys()` did. Leaf stays the only writer of `aria-keyshortcuts`, and a plain page, which hears nothing, advertises no key. - One public route. `commands` and `paintKeys` leave `widget-api.js`, and every caller moves to the declaration: all 16 package widgets, `lf-suggestion`, the feature gallery's page script, the docs and the tests. `commandScope` stays, as the value form a margin entry and several elements share, and so does the template directive `commandsOn`. The internal `keys` remains core's own entry to the register, which the declaration's reader calls. - A malformed declaration still throws where the widget made it. A listener's exception never reaches the dispatcher, so the reader hands the refusal back on the event and `commandsChanged` throws it. - An element out of the document dispatches on the window, carrying itself, as `reportFailure` does, so a control declared before it is placed keeps its keys. - Rejected: reading `lfCommands` at upgrade or connection without a signal. It would need a second way in, an arrival watch over every widget tag plus a sweep after each module import, and would still miss elements a render creates and declarations made after asynchronous drawing, such as lf-code's. Also rejected: keeping `commands` public as a portable writer of the declaration, which leaves two public routes to one capability. **Copy.** A widget block declares its Copy control with `data-lf-copy`, naming what it holds, and an `lfCopy()` method returning the text to copy. Leaf's code block watch (`code-copy.js`) stands the control right after the block while both are in the page. `copyBlock` stays for a widget that seats the control among its own, as `lf-draft` does in its toolbar; declaring that placement would add an option for one caller. **Quiet words.** A module declares a part's quiet word with `data-lf-quiet`, and Leaf writes it there (`watchQuietWords`, `declared-words.js`). Off Leaf no stylesheet would clip the word, so it would show in the code line. `quietWord` leaves `widget-api.js`; `lf-suggestion` declares its slots' words the same way, so `data-lf-quiet` joins `PAGE_PAINT_ATTRIBUTE`, the paint an authored element's reading looks past. **Portable homes.** - `tab-store.js` holds `tabStore`: Leaf's tab store where the prepaint opened one, and off Leaf a store that keeps nothing (reads answer null, writes are refused). Off Leaf the wrap can't be toggled anyway, since the key is Leaf's. - `syntax-tokens.js` holds `syntax`, `synNodes`, `tokenLines` and `ensureSyntaxLanguage`. `syntax.js` keeps the page's code blocks and `langForPath`, which read Leaf's registry. A tokenizer failure reaches Leaf through `failSoft`'s error event. - `layoutChanged` and `LAYOUT` move to `widget-upgrade.js`. - lf-code announces its drawing with `PendingTaskEvent` instead of `widgetController(this).present`. **lf-chart height.** It reads `clientHeight` instead of `data-lf-height`. On a Leaf page the theme holds the box at the stated height until `lf-rendered`, and after that the box is the drawing's, so a redraw for a new width reads the height the last drawing filled; the legend subtraction is unchanged. **Protocol bump to 36.** Removing `commands`, `paintKeys` and `quietWord` from `widget-api.js` breaks an earlier page's vendored widgets, so pages re-vendor. **Tests.** - `tests/smoke/test_plain_page.py` adds lf-code, drawing coloured lines with the highlighted one among them, and asserts the page holds no `aria-keyshortcuts`, Copy control or quiet word. The chart's drawing now fills its host's height, with no `data-lf-height`. Each assertion failed when undone: lf-code importing `widget-api.js` (fails at load), lf-code writing its own quiet word, lf-code setting `aria-keyshortcuts`, and lf-chart reading `data-lf-height` again. - `test_code_wrapping_keeps_source_copy_and_reader_choice` asserts that on a Leaf page lf-code advertises `w`, its Copy control stands after its block and its highlighted line says "highlighted". Each failed with its declaration withheld. - A runtime test covers a declaration made out of the document, its withdrawal and its refusal; it failed with the window dispatch or the withdrawal removed. - Also run: `pnpm run test:runtime` (695), `pnpm run check:browser`, `pnpm run test:browser`, and 66 focused browser tests: every converted register test, a keyboard test for each converted widget, the chart tests, code copy, export quiet words, composition and the pending-task test.
# Conflicts: # dist/kernel/kernel.json # dist/kernel/leaf.js # dist/kernel/runtime/bundle-data.js # dist/kernel/runtime/bundle-layer-client.js
…on docs Follow-up to the previous commit, from an independent review. **lf-chart height ratchet.** The chart read `clientHeight` on every redraw. Once drawn, its box is the drawing's, so a chart a grid or flex row stretches, such as a short chart beside a taller one in `.layout-tiles`, redrew at the row's height after a width change and kept it. The chart now reads the height once, at the first drawing, while the theme or the host still holds the box, and reuses it (`#height`). New test `test_a_chart_keeps_its_stated_height_beside_a_taller_one`: charts of data-height 200 and 420 in one tiles row, resized 640 then 1280 wide. Reading `clientHeight` on each redraw, it fails with the short chart at 420. **Declaration docs.** `module-input.md` lists every field a declaration holds (`title`, `rows`, `when`, `ready`, `claims`, `escape`). It says that assigning a new `lfCommands` object replaces the scope and has Leaf check its rows, while `commandsChanged` with the same object only has Leaf read its rows' titles and availability again, so an in-place edit goes unchecked. **Limit stated.** `module-authoring.md` says that Leaf finds `data-lf-copy` and `data-lf-quiet` in the page and in the shadow stages it builds, not in a shadow root a page script attaches itself. The arrival watch reaches only those (`arrivals.js`), and Leaf can't discover a foreign root without patching `attachShadow`. **Eval.** `widget-list-keeps-focus` asks for the popup's Escape as a row in an element's `lfCommands` rather than `commands(...)`. **No protocol bump after all.** Main's #4551 composes each page's layer from the Leaf reading it, so the public package API no longer bumps the protocol. The merge keeps main's 36, the previous commit's bump to 36 is moot, and the baseline is main's. Tests: the new chart test and its bug-back, the other six chart tests, `pnpm run test:runtime`, `pnpm run check:browser`, and the 66 focused browser tests from the previous commit, run again after merging main.
leaf-agent
previously approved these changes
Oct 28, 2026
# Conflicts: # dist/kernel/kernel.json # dist/kernel/runtime/bundle-layer-client.js # dist/kernel/runtime/widget-api.js # packages/deck/widgets/lf-deck.js # packages/diff/widgets/lf-diff.js
leaf-agent
previously approved these changes
Oct 28, 2026
# Conflicts: # dist/kernel/leaf.js
# Conflicts: # dist/kernel/kernel.json # dist/kernel/runtime/check-api.js
leaf-agent
approved these changes
Oct 28, 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.
lf-codenow loads and draws on a plain HTML page that maps/runtime/and/vendor/with its own import map, aslf-chartdoes since #4542. On a Leafpage it behaves as before. Its import graph is 14 runtime modules and 80 KB of
source, down from 182 and 2,271 KB.
lf-chartdraws to its own box's height,so a plain host no longer has to write
data-lf-height.Off Leaf a widget binds no keys, shows no Copy control and writes no quiet
word. Leaf adds each of those by reading what the widget declares on its
elements, rather than the widget calling into Leaf.
Keys are data on the element. A widget sets an element's
lfCommandsto thescope (
{title, rows, when, ready, escape, claims}, the rows unchanged, or acommandScope()value) and callscommandsChanged(element), a portable helperthat dispatches a bubbling, composed
lf-commandsevent. Leaf's register(
keyboard/scopes.js) reads the declaration from a window listener: a new onestands in place of the last,
nullwithdraws it, and the same one standingmeans something its rows read changed, so the register repaints, as
paintKeys()did. Leaf stays the only writer ofaria-keyshortcuts, and aplain page, which hears nothing, advertises no key.
commandsandpaintKeysleavewidget-api.js, andevery caller moves to the declaration: all 16 package widgets,
lf-suggestion,the feature gallery's page script, the docs and the tests.
commandScopestays,as the value form a margin entry and several elements share, and so does the
template directive
commandsOn. The internalkeysremains core's own entryto the register, which the declaration's reader calls.
exception never reaches the dispatcher, so the reader hands the refusal back on
the event and
commandsChangedthrows it.reportFailuredoes, so a control declared before it is placed keeps its keys.lfCommandsat upgrade or connection without a signal. Itwould need a second way in, an arrival watch over every widget tag plus a sweep
after each module import, and would still miss elements a render creates and
declarations made after asynchronous drawing, such as lf-code's. Also rejected:
keeping
commandspublic as a portable writer of the declaration, which leavestwo public routes to one capability.
Copy. A widget block declares its Copy control with
data-lf-copy, namingwhat it holds, and an
lfCopy()method returning the text to copy. Leaf's codeblock watch (
code-copy.js) stands the control right after the block whileboth are in the page.
copyBlockstays for a widget that seats the controlamong its own, as
lf-draftdoes in its toolbar; declaring that placement wouldadd an option for one caller.
Quiet words. A module declares a part's quiet word with
data-lf-quiet, andLeaf writes it there (
watchQuietWords,declared-words.js). Off Leaf nostylesheet would clip the word, so it would show in the code line.
quietWordleaves
widget-api.js;lf-suggestiondeclares its slots' words the same way,so
data-lf-quietjoinsPAGE_PAINT_ATTRIBUTE, the paint an authoredelement's reading looks past.
Portable homes.
tab-store.jsholdstabStore: Leaf's tab store where the prepaint openedone, and off Leaf a store that keeps nothing (reads answer null, writes are
refused). Off Leaf the wrap can't be toggled anyway, since the key is Leaf's.
syntax-tokens.jsholdssyntax,synNodes,tokenLinesandensureSyntaxLanguage.syntax.jskeeps the page's code blocks andlangForPath, which read Leaf's registry. A tokenizer failure reaches Leafthrough
failSoft's error event.layoutChangedandLAYOUTmove towidget-upgrade.js.PendingTaskEventinstead ofwidgetController(this).present.lf-chart height. It reads
clientHeightinstead ofdata-lf-height, once,at its first drawing, while the theme (on a Leaf page) or the host (off Leaf)
still holds the box, and keeps that height through redraws (
#height). Readingit on every redraw would let a chart that a grid or flex row stretches, such as
a short chart beside a taller one in
.layout-tiles, grow to the row's heightafter a width change. The legend subtraction is unchanged.
No protocol bump. Since #4551 each page's layer is composed by the Leaf
that reads it, so a change to the package API leaves the protocol at 36.
Tests.
tests/smoke/test_plain_page.pyadds lf-code, drawing coloured lines with thehighlighted one among them, and asserts the page holds no
aria-keyshortcuts,Copy control or quiet word. The chart's drawing now fills its host's height,
with no
data-lf-height. Each assertion failed when undone: lf-code importingwidget-api.js(fails at load), lf-code writing its own quiet word, lf-codesetting
aria-keyshortcuts, and lf-chart readingdata-lf-heightagain.test_code_wrapping_keeps_source_copy_and_reader_choiceasserts that on aLeaf page lf-code advertises
w, its Copy control stands after its block andits highlighted line says "highlighted". Each failed with its declaration
withheld.
and its refusal; it failed with the window dispatch or the withdrawal removed.
test_a_chart_keeps_its_stated_height_beside_a_taller_oneputs charts ofdata-height 200 and 420 in one tiles row and resizes it 640 then 1280 wide;
reading the height on each redraw, the short chart ends at 420.
module-input.mdlists every declaration field and says that a newlfCommandsobject replaces the scope and is checked, whilecommandsChangedon the same object only repaints.
module-authoring.mdstates the limit: Leaffinds
data-lf-copyanddata-lf-quietin the page and its own shadow stages,not in a shadow root a page script attaches. The
widget-list-keeps-focusevalrubric asks for the declaration.
pnpm run test:runtime(694 after merging main),pnpm run check:browser,pnpm run test:browser, and 66 focused browser tests: every converted registertest, a keyboard test for each converted widget, the chart tests, code copy,
export quiet words, composition and the pending-task test.