Skip to content

Let lf-code run on a plain HTML page, and declare package keys as data Leaf reads - #4574

Merged
max-sixty merged 6 commits into
mainfrom
agent-a654c07ec36e2cd9a
Oct 28, 2026
Merged

max-sixty merged 6 commits into
mainfrom
agent-a654c07ec36e2cd9a

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

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, 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). Reading
it 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 height
after 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.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.
  • test_a_chart_keeps_its_stated_height_beside_a_taller_one puts charts of
    data-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.md lists every declaration field and says that a new
    lfCommands object replaces the scope and is checked, while commandsChanged
    on the same object only repaints. module-authoring.md states the limit: Leaf
    finds data-lf-copy and data-lf-quiet in the page and its own shadow stages,
    not in a shadow root a page script attaches. The widget-list-keeps-focus eval
    rubric asks for the declaration.
  • Also run: pnpm run test:runtime (694 after merging main), 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.

This was written by Claude Code on behalf of max-sixty

…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
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
leaf-agent previously approved these changes Oct 28, 2026
# Conflicts:
#	dist/kernel/kernel.json
#	dist/kernel/runtime/check-api.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants