From 32f4335bc3004d4bae642391d698604eaefcb3cc Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:49:01 +0100 Subject: [PATCH 1/6] Inspectors: compact menu and panels, denser watches, text grids as square blocks (#723) The WebFront tab's menu is compact for a mouse (28 px entries, 13 px text, 24 px targets at least) and takes 44 px again under a coarse pointer. The inspector panels have smaller margins, rows and controls, keep 24 px click areas (44 px under a coarse pointer) and a visible focus. In the Watches panel, elements that are all leaves of one kind show their kind once, on their container, with their labels in a narrow column. A container of strings of the same length, such as Life's grid, shows as a block: one line per element in square character cells, keeping the highlighting of changed lines, the full value and the edition in place. Its Tree button shows the elements one by one again; the choice is kept per watch and container in this browser. Only the display changes: the pages and passes of ADR-027 section 3 are the same. --- docs/CHANGELOG.md | 1 + docs/DEVELOPER_ENVIRONMENT.md | 12 +- docs/WATCHES.md | 14 ++ js/developer/environment/bundles.json | 12 +- js/developer/environment/inspector-bridge.mjs | 2 +- .../environment/inspector-packages.mjs | 21 +- .../environment/inspector-registry.mjs | 19 +- .../environment/inspector-watches.mjs | 198 +++++++++++++++--- js/developer/environment/inspector.mjs | 35 ++-- js/developer/environment/menu.mjs | 7 +- .../specs/inspector-watches-specs.mjs | 114 +++++++++- test/developer/specs/workspace-specs.mjs | 6 +- test/web/DeveloperTest.cpp | 35 +++- test/web/developer-specs.mjs | 44 +++- 14 files changed, 431 insertions(+), 89 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index aa988f23..cdf6d8ad 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -28,6 +28,7 @@ these entries stays in the GitHub releases and the Git history. - Let an agent read the locked packages with the `packages` grant: the `list`, `why` and `info` operations answer `wf list --tree`, `wf why` and `wf info`, in environment 1.2.1 or later (#685, `docs/AUTOMATION.md`). - Browse in the **Packages** panel of the inspectors the locked packages as a tree under the roots of the manifest, with the requested ranges and the `peer`, `deduped` and multiple-version marks; search a package by name and open its detail with its `wf why` chains; the tree follows `wf install` and `wf restore` (#683, ADR-027, `docs/DEVELOPER_ENVIRONMENT.md`). - See in the **Bridge** panel of the inspectors the state of the bridge in the interface's page: `webFront.ready` (pending, resolved, or rejected and why), the pending `cppFunction` calls and their duration, the Promises rejected lately, and the JavaScript functions that C++ calls; a bridge that no inspector reads records nothing (#684, ADR-027, `docs/DEVELOPER_ENVIRONMENT.md`). +- See more at once in the inspectors: a compact tab menu and panels for the mouse (44 px targets under a coarse pointer), the kind of like elements shown once, and a container of strings of the same length, such as the grid of Life, shown as a block of square character cells, with a Tree button to show its elements one by one (#723, `docs/WATCHES.md`). - Declare what the inspectors show with `app.watch(name, source)`, whose handle removes the watch when it is destroyed; the Watches panel follows their registrations and removals. Outside the developer environment and in a distribution build, `watch` registers nothing (#680, ADR-027). - Embed a plain interface directory (HTML, JavaScript, CSS, vendored files) from CMake with `webfront_embed_directory(app ui CLASS AppUI)`, without the developer environment: the build regenerates the provider when a file changes, and `fs::DocumentRootFirstFSWith` lets a development root serve in front of it (#675, `docs/EMBEDDED_ASSETS.md`). - Set from the configuration `Referrer-Policy` (`contentPolicy.referrerPolicy`: `"no-referrer"` forbids explicitly that a capability in your URLs leaves in `Referer`), `X-Content-Type-Options: nosniff` (`noSniff`) and the `Cache-Control` of HTML pages (`htmlCacheControl`), on files, route and generated replies unless a reply sets its own (#674, `docs/CONTENT_POLICY.md`). diff --git a/docs/DEVELOPER_ENVIRONMENT.md b/docs/DEVELOPER_ENVIRONMENT.md index 5fd1c4c4..bf0d11ca 100644 --- a/docs/DEVELOPER_ENVIRONMENT.md +++ b/docs/DEVELOPER_ENVIRONMENT.md @@ -489,6 +489,12 @@ environment's `mount`, not to the embedded bootstrap page): The arrow beside a watch unfolds its content as a tree: scalars, strings, containers, described and formattable types, read by pages of 200 children and refreshed at the chosen period, the values that changed highlighted. A value the application made writable is edited in place (Enter writes, Escape cancels); a value that is cut offers its full text. + Elements that are all leaves of one kind show that kind once, on their container (`sequence [3] of string`), with their + indices in a narrow column and their values aligned. A container of strings of the same length, such as the grid of + Life, shows as a **block**: one line per element, without index or kind, in square character cells, so that a grid of + 32 by 32 characters is square. The lines keep the highlighting of what changed, the full value and the edition in place. + Its **Tree** button shows the elements one by one again and **Block** returns to the block; the choice is kept per watch + in this browser, as the period is. The layout changes only what is shown: the pages read are the same. [Watches](WATCHES.md) tells how to declare them, under which lock or on which thread they are read, and their bounds. The **Functions** panel lists what the application registered with `cppFunction`, the functions of its spaces included @@ -544,8 +550,10 @@ environment's `mount`, not to the embedded bootstrap page): announcement is refused with `webfront.inspector.unavailable`, and its detached panel says that the page is not connected. -The tab is a button (`aria-expanded`, `aria-haspopup="menu"`, 44 px target), its menu a `menu` of `menuitem`s of 44 px, -and the window a non-modal dialog. The interface stays in the preview +The tab is a button (`aria-expanded`, `aria-haspopup="menu"`, 44 px target), its menu a `menu` of compact `menuitem`s +(28 px, 24 px at least, and 44 px under a coarse pointer such as a touch screen), and the window a non-modal dialog. The +inspector panels are dense in the same way: their controls keep 24 px at least, 44 px under a coarse pointer, and a +visible focus. The interface stays in the preview frame, as before: the layout adds nothing to the application's documents except the shortcut's listener and the preview page's announcement, installed in the interface and in the same-origin frames it embeds (not in a frame of another origin, nor one inside a shadow tree: click the interface or the tab first). This is a layout, not a diff --git a/docs/WATCHES.md b/docs/WATCHES.md index 7e73b8d3..ef53e0f3 100644 --- a/docs/WATCHES.md +++ b/docs/WATCHES.md @@ -224,6 +224,20 @@ write never waits for the end of a pass: it interrupts it, and the next pass fin (`webfront.inspector.children`, `changes`, `value`, `fold`, `reset`, `limits`, `write`) is described in section 3 of the ADR; it uses the bridge's existing types only. +## How the panel shows a container + +Elements that are all leaves of one kind show that kind once, on their container (`sequence [32] of string`), with their +indices in a narrow column and their values aligned, so that more of them fit in the window. + +A container of two or more strings of the same length, such as `grid` above, shows as a **block**: one line per element, +without index or kind, in a monospace font whose letter spacing widens the advance of a character to the line height, so +that each character is a square cell and a grid of 32 by 32 characters is square; the grid of Life fits in the default inspector window. The +block keeps what the tree offers: the lines that the last pass changed are highlighted, a line that is cut offers its full +value, and a line of a writable watch is edited in place (click it, or Enter or F2). Its **Tree** button shows the +elements one by one again, and **Block** returns to the block; the choice is kept per watch and container in this +browser, as the period is. A line that no longer has the length of the others turns the block back into a tree until they +agree. The layout changes only what is shown: the pages of 200 elements and the passes are the same (ADR-027, section 3). + ## Reading a watch from an agent An application that enables [automation](AUTOMATION.md#reading-the-applications-state) with the `state` grant gives an MCP diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index a2f9a59c..840090a8 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -23,13 +23,13 @@ "js/developer/environment/testing.mjs": "48695dc7c368d5f0671a0549a61d06c732e10604c56e98f7254f3c4dd21a792c", "js/developer/environment/terminal.mjs": "e7c3ca8f9833f10e07939277996eb01fb989c986420c96052271ff469fa59062", "js/developer/environment/workspace.mjs": "e82ec4df21ffb2b112550e0212504aba05af4f924b5645c0712f40f8466257fc", - "js/developer/environment/menu.mjs": "b4fe4c38e6b8cc6c1101df842e282ab85e6c6e029b2225738b9d27bc5efbc88d", + "js/developer/environment/menu.mjs": "29535371e75ecbb5e402397cf47e0970b664b75d6c663d33915724f6a3fa3af8", "js/developer/environment/inspector-host.mjs": "304a8a6713026939d66088dd0bb68a96ff4ee14e970c6886d61c82ebde611ac5", - "js/developer/environment/inspector.mjs": "183ece8ad6581c458315211b3edea6fa2823c2212d3999e7e9e069a1e78309e5", - "js/developer/environment/inspector-packages.mjs": "1c3f6350780b841784f83bc20ead2945157c48a1f136c47e3a7a90d89bea8522", - "js/developer/environment/inspector-registry.mjs": "6653afc473fcef677d8b02541085943da3f7d15c5b64d23dafd43c750a9e28d8", - "js/developer/environment/inspector-watches.mjs": "f5b8f901b86969bfe349d0e875cce9fba375d922f95f4fb213dc2f690083175e", - "js/developer/environment/inspector-bridge.mjs": "fa891a6098edccd4fdae288c07d5b5d766919021acece61f6d3e5a3e55882bbc", + "js/developer/environment/inspector.mjs": "44b6cd4443a3ed55a1bb188be96eafb64fc8b40b9a80500b3c47977740a6b336", + "js/developer/environment/inspector-packages.mjs": "de7ee0bcd85df4eadb434e52bd571951eea3314eb1b0d1fd3ada52cf21a0b14c", + "js/developer/environment/inspector-registry.mjs": "bcc15ef9801ad9a60e377eaa26582febb05c472d5e9b9678ee8b5ec369a2a15e", + "js/developer/environment/inspector-watches.mjs": "ecc5431cf2e098aee2a1fa2d41cd928059fea85e4ce97363d9500df1fdcf9933", + "js/developer/environment/inspector-bridge.mjs": "b3f269245870d1a7e126cab5f80b2918164a5c24b3d351015cf52d44bf343cb8", "js/developer/environment/inspector.html": "66bfb80d6bd29bc9aabf71e0dd9b163dfcd1f1c77d1a41818645af1a4f9b8616", "js/developer/environment/tarball.mjs": "1c1e1aea067910e1fec74e85b4bf9fbefed9b38187a04d8d2764f0b9a96fca39", "js/developer/environment/commands.mjs": "a759f48584b78aed79e9965fd202d2ec108a6948ef6f1b8d689fed87a458b265", diff --git a/js/developer/environment/inspector-bridge.mjs b/js/developer/environment/inspector-bridge.mjs index 7eb465a2..e1e2a4fe 100644 --- a/js/developer/environment/inspector-bridge.mjs +++ b/js/developer/environment/inspector-bridge.mjs @@ -419,7 +419,7 @@ const readyTexts = { export const describeReady = ready => ready.state === 'rejected' && ready.reason ? `rejected: ${ready.reason}` : readyTexts[ready.state] ?? ready.state; export const bridgeStyles = ` -dl.bridge{display:grid;grid-template-columns:auto 1fr;gap:4px 12px;margin:0 0 12px} +dl.bridge{display:grid;grid-template-columns:auto 1fr;gap:2px 8px;margin:0 0 8px} dl.bridge dt{color:#a9b3c4} dl.bridge dd{margin:0;overflow-wrap:anywhere} dl.bridge dd.rejected{color:#ffbd2e}`; diff --git a/js/developer/environment/inspector-packages.mjs b/js/developer/environment/inspector-packages.mjs index 1e8f99d5..9e751f02 100644 --- a/js/developer/environment/inspector-packages.mjs +++ b/js/developer/environment/inspector-packages.mjs @@ -50,11 +50,11 @@ export function searchPackages(lock, query) { const pathOf = (parent, id) => parent ? `${parent}>${id}` : id; export const packagesStyles = ` -.packages-layout{display:grid;grid-template-columns:minmax(0,1fr);gap:12px} +.packages-layout{display:grid;grid-template-columns:minmax(0,1fr);gap:8px} @media (min-width:720px){.packages-layout{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}} ul.packages,ul.packages ul,ul.matches,ol.chains,ul.files{list-style:none;margin:0;padding:0} -ul.packages ul{padding-left:18px} -ul.packages li>.row{display:flex;flex-wrap:wrap;align-items:center;gap:2px 8px;min-height:28px;padding:0 4px;border-radius:4px;cursor:pointer} +ul.packages ul{padding-left:14px} +ul.packages li>.row{display:flex;flex-wrap:wrap;align-items:center;gap:0 6px;min-height:24px;padding:0 4px;border-radius:4px;cursor:pointer} ul.packages li:focus{outline:none} ul.packages li:focus-visible>.row{outline:2px solid #d7fa85;outline-offset:-2px} ul.packages li[aria-selected=true]>.row,ul.matches button[aria-pressed=true]{background:#2f3a50} @@ -65,21 +65,22 @@ ul.packages li[aria-expanded=false]>ul{display:none} .badge{padding:0 6px;border:1px solid #46536a;border-radius:8px;color:#a9b3c4;font-size:11px;white-space:nowrap} .badge.peer{color:#8fd0ff;border-color:#8fd0ff} .badge.versions{color:#ffbd2e;border-color:#ffbd2e} -ul.matches button,.package-detail button.package-link{min-height:28px;padding:0 6px;border:0;border-radius:4px;background:none;color:#8fd0ff;font:13px ui-monospace,monospace;text-align:left;cursor:pointer;overflow-wrap:anywhere} +ul.matches button,.package-detail button.package-link{min-height:24px;padding:0 6px;border:0;border-radius:4px;background:none;color:#8fd0ff;font:13px ui-monospace,monospace;text-align:left;cursor:pointer;overflow-wrap:anywhere} ul.matches li{display:flex;flex-wrap:wrap;align-items:center;gap:2px 8px} ul.matches button:focus-visible,.package-detail button:focus-visible{outline:2px solid #d7fa85;outline-offset:-2px} -.package-detail{min-width:0;padding:8px 12px;border:1px solid #2f3a50;border-radius:4px;align-self:start} +.package-detail{min-width:0;padding:4px 8px;border:1px solid #2f3a50;border-radius:4px;align-self:start} .package-detail h2:focus{outline:none} .package-detail h2{margin:0 0 4px;font:600 14px ui-monospace,monospace;overflow-wrap:anywhere} -.package-detail h3{margin:12px 0 4px;font-size:12px;font-weight:600;color:#a9b3c4} -.package-detail p{margin:0 0 8px} -.package-detail dl{display:grid;grid-template-columns:auto minmax(0,1fr);gap:4px 12px;margin:0} +.package-detail h3{margin:8px 0 2px;font-size:12px;font-weight:600;color:#a9b3c4} +.package-detail p{margin:0 0 4px} +.package-detail dl{display:grid;grid-template-columns:auto minmax(0,1fr);gap:2px 8px;margin:0} .package-detail dt{color:#a9b3c4;font-size:12px} .package-detail dd{margin:0;overflow-wrap:anywhere} .package-detail .code{font-family:ui-monospace,monospace;font-size:12px} .package-detail .note,ul.matches .note{color:#a9b3c4;font-size:12px} -ol.chains li{padding:2px 0;border-bottom:1px solid #2f3a50} -ul.files{max-height:12em;overflow:auto;font-family:ui-monospace,monospace;font-size:12px}`; +ol.chains li{padding:1px 0;border-bottom:1px solid #2f3a50} +ul.files{max-height:12em;overflow:auto;font-family:ui-monospace,monospace;font-size:12px} +@media (pointer:coarse){ul.packages li>.row,ul.matches button,.package-detail button.package-link{min-height:44px}}`; /** * Shows the panel in `body`. `load(bridge)` reads the project and `state(bridge)` the token of its state (tests replace diff --git a/js/developer/environment/inspector-registry.mjs b/js/developer/environment/inspector-registry.mjs index 030a38aa..897586d8 100644 --- a/js/developer/environment/inspector-registry.mjs +++ b/js/developer/environment/inspector-registry.mjs @@ -323,17 +323,17 @@ export const commandColumns = [ ]; export const registryStyles = ` -.toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:8px 12px;margin:0 0 8px} -.toolbar input[type=search]{flex:1 1 160px;min-width:0;min-height:32px;padding:0 8px;border:1px solid #46536a;border-radius:4px;background:#0f131b;color:inherit;font:inherit} -.toolbar select{min-height:32px;padding:0 6px;border:1px solid #46536a;border-radius:4px;background:#2f3a50;color:inherit;font:inherit} +.toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:4px 8px;margin:0 0 4px} +.toolbar input[type=search]{flex:1 1 160px;min-width:0;min-height:26px;padding:0 6px;border:1px solid #46536a;border-radius:4px;background:#0f131b;color:inherit;font:inherit} +.toolbar select{min-height:26px;padding:0 4px;border:1px solid #46536a;border-radius:4px;background:#2f3a50;color:inherit;font:inherit} .toolbar label{display:flex;align-items:center;gap:6px;color:#a9b3c4;font-size:12px} .toolbar :focus-visible{outline:2px solid #d7fa85;outline-offset:1px} -.scroll{overflow-x:auto;margin:0 0 16px} -table.registry{border-collapse:collapse;width:100%;font-size:13px} -table.registry caption{text-align:left;font-weight:600;padding:4px 0} -table.registry th,table.registry td{padding:4px 8px;border-bottom:1px solid #2f3a50;text-align:left;vertical-align:top;white-space:nowrap} +.scroll{overflow-x:auto;margin:0 0 8px} +table.registry{border-collapse:collapse;width:100%;font-size:12px;line-height:16px} +table.registry caption{text-align:left;font-weight:600;padding:2px 0} +table.registry th,table.registry td{padding:2px 6px;border-bottom:1px solid #2f3a50;text-align:left;vertical-align:top;white-space:nowrap} table.registry th{position:sticky;top:0;background:#202737;padding:0} -table.registry th button{width:100%;min-height:32px;padding:0 8px;border:0;background:none;color:inherit;font:inherit;font-weight:600;text-align:inherit;cursor:pointer} +table.registry th button{width:100%;min-height:24px;padding:0 6px;border:0;background:none;color:inherit;font:inherit;font-weight:600;text-align:inherit;cursor:pointer} table.registry th button:focus-visible{outline:2px solid #d7fa85;outline-offset:-2px} table.registry th[aria-sort=ascending] button::after{content:" ▲";color:#d7fa85} table.registry th[aria-sort=descending] button::after{content:" ▼";color:#d7fa85} @@ -342,7 +342,8 @@ table.registry .name{font-weight:600} table.registry .code{font-family:ui-monospace,monospace;font-size:12px;color:#d7fa85} table.registry .location{color:#a9b3c4;font-size:12px} table.registry .error-text{color:#ffbd2e;white-space:normal;overflow-wrap:anywhere;min-width:12em} -.summary{margin:0 0 8px}`; +.summary{margin:0 0 4px} +@media (pointer:coarse){.toolbar input[type=search],.toolbar select,table.registry th button{min-height:44px}}`; // --- Panels ---------------------------------------------------------------------------------------------------- diff --git a/js/developer/environment/inspector-watches.mjs b/js/developer/environment/inspector-watches.mjs index 7f730337..f383cdeb 100644 --- a/js/developer/environment/inspector-watches.mjs +++ b/js/developer/environment/inspector-watches.mjs @@ -375,23 +375,41 @@ export function createWatchTree({bridge, watch, count = pageCount, onUpdate = () export const watchTreeStyles = ` ul.watches li{display:block} -ul.watches .head{display:grid;grid-template-columns:auto 1fr auto;gap:2px 12px;align-items:baseline} -ul.watches .head .location{grid-column:2/4} -ul.watches button.toggle,ul.tree button.toggle{width:24px;min-height:24px;padding:0;border:0;background:none;color:#a9b3c4;font:inherit;cursor:pointer} -ul.watches button.toggle:focus-visible,ul.tree button:focus-visible,ul.tree input:focus-visible{outline:2px solid #d7fa85;outline-offset:1px} -ul.tree{list-style:none;margin:4px 0 0;padding:0 0 0 16px;font:12px ui-monospace,monospace} -ul.tree li{padding:1px 0;border:0} -ul.tree .row{display:flex;gap:6px;align-items:baseline;min-height:24px} -ul.tree .spacer{display:inline-block;width:24px} +ul.watches .head{display:flex;align-items:center;gap:0 8px;min-width:0} +ul.watches .head .location{flex:1 1 0;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;direction:rtl;text-align:right} +ul.watches button.toggle,ul.tree button.toggle{flex:none;width:24px;height:24px;padding:0;border:0;border-radius:3px;background:none;color:#a9b3c4;font:inherit;line-height:1;cursor:pointer} +ul.watches button.toggle:hover,ul.tree button.toggle:hover{background:#2f3a50} +ul.watches button.toggle:focus-visible,ul.tree button:focus-visible,ul.tree input:focus-visible,ul.tree [role=button]:focus-visible{outline:2px solid #d7fa85;outline-offset:1px} +ul.tree{list-style:none;margin:2px 0 0;padding:0 0 0 12px;font:12px/16px ui-monospace,monospace} +ul.tree li{padding:0;border:0} +ul.tree .row{display:flex;gap:6px;align-items:center;min-height:18px} +ul.tree .row.target{min-height:24px} +ul.tree .spacer{flex:none;display:inline-block;width:24px} +ul.tree.leaves>li>.row>.spacer{display:none} ul.tree .label{color:#8fd0ff} -ul.tree .kind{color:#a9b3c4;justify-self:auto} -ul.tree .value{overflow-wrap:anywhere;white-space:pre-wrap} +ul.tree.homogeneous>li>.row>.label{min-width:var(--label-width);text-align:end;color:#7b8aa3} +ul.tree .kind,ul.tree .of{flex:none;color:#a9b3c4;justify-self:auto} +ul.tree .value{min-width:0;overflow-wrap:anywhere;white-space:pre-wrap} ul.tree .value.writable{cursor:text;border-bottom:1px dotted #46536a} ul.tree .changed>.row .value,ul.tree .changed>.row .kind{background:#4a3d12} ul.tree .note{color:#ffbd2e} ul.tree input{min-width:12ch;border:1px solid #46536a;border-radius:3px;background:#141821;color:inherit;font:inherit} -ul.tree button.more,ul.tree button.full{min-height:24px;padding:0 6px;border:1px solid #46536a;border-radius:3px;background:#2f3a50;color:inherit;font:inherit;cursor:pointer} -ul.tree pre.full{max-height:240px;overflow:auto;margin:2px 0;padding:4px;background:#0f131b;white-space:pre-wrap;overflow-wrap:anywhere}`; +ul.tree button.more,ul.tree button.full,ul.tree button.layout{flex:none;min-height:24px;padding:0 6px;border:1px solid #46536a;border-radius:3px;background:#2f3a50;color:inherit;font:11px system-ui;cursor:pointer} +ul.tree pre.full{max-height:240px;overflow:auto;margin:2px 0;padding:4px;background:#0f131b;white-space:pre-wrap;overflow-wrap:anywhere} +ul.tree.block{width:max-content;max-width:calc(100% - 12px);margin:2px 0 2px 12px;padding:0;overflow-x:auto;font-size:11px;line-height:1em} +ul.tree.block>li{margin:0;padding:0} +ul.tree.block>li>.row{display:block;min-height:0;line-height:1em;white-space:pre} +ul.tree.block .value{display:inline-block;vertical-align:top;letter-spacing:calc(1em - 1ch);white-space:pre;overflow-wrap:normal} +ul.tree.block .value.writable{border-bottom:0;text-decoration:underline dotted #46536a} +ul.tree.block .changed>.row .value{background:#4a3d12} +ul.tree.block .row button.full{min-height:0;height:1em;padding:0 4px;font-size:inherit;line-height:1} +ul.tree.block .row .note{white-space:normal;letter-spacing:normal} +@media (pointer:coarse){ +ul.watches button.toggle,ul.tree button.toggle{width:44px;height:44px} +ul.tree .row.target{min-height:44px} +ul.tree .spacer{width:44px} +ul.tree button.more,ul.tree button.full,ul.tree button.layout{min-height:44px;padding:0 10px} +}`; /** The most characters of a full value that the page shows; the rest is told by its size. */ export const shownValueCharacters = 64 * 1024; @@ -405,13 +423,75 @@ const reasons = { /** Why a write was not applied, for the user. */ export const writeFailure = ({code, message}) => message || reasons[code] || code; +/** The kind of the elements that a block shows, one line each. */ +const blockKind = 'string'; + +/** The width of a text in the columns of a block: its characters (code points). */ +const columns = text => [...text].length; + +/** + * The width, in characters, of the block that the loaded children of `path` can be shown as; 0 when they cannot. A block shows + * two or more strings of the same length, none of them empty: the rows of a grid of text. It reads only what is loaded, so the + * pages and the passes are the same in both layouts (ADR-027, section 3). + */ +export function blockWidth(tree, path) { + const entry = tree.nodes.get(path); + if (!entry || entry.node.children < 2) return 0; + let width = 0, count = 0; + for (const child of entry.positions.values()) { + const node = tree.nodes.get(child)?.node; + if (!node) continue; + if (node.kind !== blockKind || node.children !== 0) return 0; + const length = columns(node.value); + if (!length || (count && length !== width)) return 0; + width = length; + ++count; + } + return count >= 2 ? width : 0; +} + +/** How the elements of a container are shown: one row each in the tree, or one line each in a block. */ +export const layouts = Object.freeze({tree: 'tree', block: 'block'}); + +const layoutsKey = 'webfront.inspector.layouts'; +/** The most layouts this viewer's choices keep; the oldest are forgotten first. */ +export const keptLayoutCount = 200; + +/** The layout this viewer chose for the container `path` of the watch `name`, or null when none is kept or the storage is unavailable. */ +export function keptLayout(view, name, path) { + try { + const kept = JSON.parse(view.localStorage?.getItem(layoutsKey) ?? '{}')?.[JSON.stringify([name, path])]; + return Object.values(layouts).includes(kept) ? kept : null; + } catch { return null; } +} + +/** Keeps the layout chosen for the container `path` of the watch `name`, as the period is kept: a convenience of this viewer. */ +export function keepLayout(view, name, path, layout) { + try { + let kept = JSON.parse(view.localStorage?.getItem(layoutsKey) ?? '{}'); + if (!kept || typeof kept !== 'object' || Array.isArray(kept)) kept = {}; + const key = JSON.stringify([name, path]); + delete kept[key]; + kept[key] = layout; + const keys = Object.keys(kept); + for (const old of keys.slice(0, Math.max(0, keys.length - keptLayoutCount))) delete kept[old]; + view.localStorage?.setItem(layoutsKey, JSON.stringify(kept)); + } catch { /* a convenience only: the choice lasts as long as the page */ } +} + /** * Shows a tree in `list` (a `ul`), and wires its controls: unfolding and folding, the next page of a list, a position in a * large container, the edition in place of a writable value (Enter writes, Escape cancels), and the full value of one that * is cut. `render()` draws the model again; it keeps the focus and an edition in progress. + * + * The elements of a container that are all leaves of one kind show their kind once, on the container, and their labels in + * a narrow column. A container of strings of the same length (blockWidth) is shown as a block by default: one line per + * element, without label or kind, in square character cells, so that a grid of text keeps its proportions. Its Tree button + * shows the elements one by one again, and Block returns to the block; the choice is kept per watch (`name`) and container. */ -export function createTreeView({tree, list, view = globalThis}) { +export function createTreeView({tree, list, view = globalThis, name = null}) { const page = list.ownerDocument; + const chosen = new Map(); // path, the layout of its elements in this view const notes = new Map(); // path, why the last write was not applied const full = new Map(); // path, the full value read let editing = null; // {path, text}: kept across the renderings that a refresh causes @@ -469,22 +549,19 @@ export function createTreeView({tree, list, view = globalThis}) { render(); } - function row(path, depth) { - const entry = tree.nodes.get(path); - const {node} = entry; - const item = element('li'); - item.setAttribute('role', 'treeitem'); - item.dataset.path = path; - if (entry.changed && entry.changed === tree.pass) item.classList.add('changed'); - const line = element('div', 'row'); - const unfolds = node.children > 0 && !(node.flags & flags.depthReached); - const open = unfolds && tree.expanded.has(path); - if (unfolds) { - item.setAttribute('aria-expanded', String(open)); - line.append(button('toggle', open ? '▾' : '▸', `${open ? 'Fold' : 'Unfold'} ${node.label}`, - () => report(open ? tree.collapse(path) : tree.expand(path)))); - } else line.append(element('span', 'spacer')); - line.append(element('span', 'label', node.label), element('span', 'kind', node.children > 0 ? `${node.kind} [${node.children}]` : node.kind)); + /** The layout of the elements of `path`: the one this viewer chose, else a block. */ + const layoutOf = path => { + if (!chosen.has(path)) chosen.set(path, (name === null ? null : keptLayout(view, name, path)) ?? layouts.block); + return chosen.get(path); + }; + const choose = (path, layout) => { + chosen.set(path, layout); + if (name !== null) keepLayout(view, name, path, layout); + render(); + }; + + /** The value of a node, or the field that edits it; its full value and notes after it. */ + function valueOf(path, node, line, item) { if (editing?.path === path) { const input = element('input', 'edit'); input.value = editing.text; @@ -522,9 +599,66 @@ export function createTreeView({tree, list, view = globalThis}) { item.append(element('pre', 'full', shown), element('span', 'note', `${total} bytes${capped ? ', cut at the inspector\'s limit' : ''}`)); } + } + + /** A node as one line of a block: its value only, its label and kind being those of the block. */ + function blockLine(path) { + const {node, changed} = tree.nodes.get(path); + const item = element('li'); + item.setAttribute('role', 'treeitem'); + item.dataset.path = path; + if (changed && changed === tree.pass) item.classList.add('changed'); + valueOf(path, node, element('div', 'row'), item); + return item; + } + + /** A node as a row of the tree; `uniform` when its siblings are leaves of its kind, which their container shows once. */ + function row(path, depth, uniform = false) { + const entry = tree.nodes.get(path); + const {node} = entry; + const item = element('li'); + item.setAttribute('role', 'treeitem'); + item.dataset.path = path; + if (entry.changed && entry.changed === tree.pass) item.classList.add('changed'); + const line = element('div', 'row'); + const unfolds = node.children > 0 && !(node.flags & flags.depthReached); + const open = unfolds && tree.expanded.has(path); + const children = open + ? [...entry.positions].sort((a, b) => a[0] - b[0]).filter(([, child]) => tree.nodes.has(child)) : []; + const shown = children.map(([, child]) => tree.nodes.get(child).node); + const leaves = shown.length > 0 && shown.every(child => child.children === 0 || (child.flags & flags.depthReached)); + const sameKind = leaves && shown.length > 1 && shown.every(child => child.kind === shown[0].kind); + const width = open ? blockWidth(tree, path) : 0; + const block = width > 0 && layoutOf(path) === layouts.block; + if (unfolds) { + item.setAttribute('aria-expanded', String(open)); + line.append(button('toggle', open ? '▾' : '▸', `${open ? 'Fold' : 'Unfold'} ${node.label}`, + () => report(open ? tree.collapse(path) : tree.expand(path)))); + } else line.append(element('span', 'spacer')); + line.append(element('span', 'label', node.label)); + if (!uniform) line.append(element('span', 'kind', node.children > 0 ? `${node.kind} [${node.children}]` : node.kind)); + if (sameKind) line.append(element('span', 'of', `of ${shown[0].kind}`)); + if (width > 0) { + const layout = button('layout', block ? 'Tree' : 'Block', + block ? `Show the elements of ${node.label} one by one` : `Show the elements of ${node.label} as a block of text`, + () => choose(path, block ? layouts.tree : layouts.block)); + layout.title = block ? 'Show the elements one by one, with their index' : 'Show the elements as a block of text, one line each'; + line.append(layout); + } + valueOf(path, node, line, item); + if (line.querySelector('button, input, [role=button]')) line.classList.add('target'); if (open) { - const group = element('ul', 'tree'); + const group = element('ul', block ? 'tree block' : 'tree'); group.setAttribute('role', 'group'); + if (block) { + group.setAttribute('aria-label', `${node.label}, ${width} characters per line`); + } else if (leaves) { + group.classList.add('leaves'); + if (sameKind) { + group.classList.add('homogeneous'); + group.style.setProperty('--label-width', `${Math.max(...shown.map(child => columns(child.label)))}ch`); + } + } let expected = 0; const gap = (from, to) => { const more = element('li'); @@ -537,9 +671,9 @@ export function createTreeView({tree, list, view = globalThis}) { more.dataset.from = String(from); return more; }; - for (const [position, child] of [...entry.positions].sort((a, b) => a[0] - b[0])) { + for (const [position, child] of children) { if (position > expected) group.append(gap(expected, position)); - if (tree.nodes.has(child)) group.append(row(child, depth + 1)); + group.append(block ? blockLine(child) : row(child, depth + 1, sameKind)); expected = position + 1; } if (expected < node.children) { diff --git a/js/developer/environment/inspector.mjs b/js/developer/environment/inspector.mjs index 745a1be4..5d12a99c 100644 --- a/js/developer/environment/inspector.mjs +++ b/js/developer/environment/inspector.mjs @@ -189,21 +189,24 @@ export function createWatchDiscovery({bridge, onChange, onError = () => {}, onRe const styles = ` :root{color-scheme:dark} -body{margin:0;background:#141821;color:#e8edf4;font:14px system-ui} -header{display:flex;align-items:center;gap:8px;padding:8px 12px;background:#202737;border-bottom:1px solid #46536a} -header h1{flex:1 1 auto;margin:0;font-size:14px;font-weight:600} -header button{min-height:32px;padding:0 10px;border:1px solid #46536a;border-radius:4px;background:#2f3a50;color:inherit;font:inherit;cursor:pointer} -header button:focus-visible{outline:2px solid #d7fa85;outline-offset:1px} -main{padding:8px 12px} -.status{color:#a9b3c4;font-size:12px;margin:4px 0 8px} +body{margin:0;background:#141821;color:#e8edf4;font:13px/1.35 system-ui} +header{display:flex;flex-wrap:wrap;align-items:center;gap:4px 8px;padding:4px 8px;background:#202737;border-bottom:1px solid #46536a} +header h1{flex:1 1 auto;margin:0;font-size:13px;font-weight:600} +header label{display:flex;align-items:center;gap:4px;color:#a9b3c4;font-size:12px} +header button,header select{min-height:26px;padding:0 8px;border:1px solid #46536a;border-radius:4px;background:#2f3a50;color:inherit;font:inherit;cursor:pointer} +header select{padding:0 4px} +header button:focus-visible,header select:focus-visible{outline:2px solid #d7fa85;outline-offset:1px} +main{padding:4px 8px} +.status{color:#a9b3c4;font-size:12px;margin:2px 0 4px} .status:empty{display:none} .error{color:#ffbd2e} ul.watches{list-style:none;margin:0;padding:0} -ul.watches li{display:grid;grid-template-columns:auto 1fr;gap:2px 12px;padding:8px;border-bottom:1px solid #2f3a50} +ul.watches li{display:grid;grid-template-columns:auto 1fr;gap:0 8px;padding:2px 4px;border-bottom:1px solid #2f3a50} ul.watches .name{font-weight:600} ul.watches .kind{color:#d7fa85;font-family:ui-monospace,monospace;font-size:12px;justify-self:end} -ul.watches .location{grid-column:1/3;color:#a9b3c4;font-size:12px;overflow-wrap:anywhere} -ul.watches .writable{color:#8fd0ff;font-size:12px}`; +ul.watches .location{grid-column:1/3;color:#a9b3c4;font-size:11px;overflow-wrap:anywhere} +ul.watches .writable{color:#8fd0ff;font-size:11px} +@media (pointer:coarse){header button,header select{min-height:44px;padding:0 12px}}`; /** * Renders the list of the watches in `list`, one item per watch, kept by id so that a removal removes its item. With @@ -236,8 +239,16 @@ export function renderWatches(list, watches, {onToggle = null} = {}) { toggle.addEventListener('click', () => onToggle(watch, item)); head.append(toggle); } - head.append(cell('name', watch.name), cell('kind', watch.kind), cell('location', watch.location)); + head.append(cell('name', watch.name), cell('kind', watch.kind)); if (watch.writable) head.append(cell('writable', 'writable')); + // On the line of its name, cut at its start when the panel is narrow: its title gives it whole. + const location = cell('location', ''); + const path = page.createElement('span'); + path.dir = 'ltr'; + path.textContent = watch.location; + location.append(path); + location.title = watch.location; + head.append(location); item.append(head); list.append(item); } @@ -384,7 +395,7 @@ export async function main(view = window) { // A watch that C++ no longer knows leaves the list at once, without waiting for the next discovery. onGone: () => { close(watch.id); discovery.forget(watch.id); }, }); - shown = createTreeView({tree, list: element, view}); + shown = createTreeView({tree, list: element, view, name: watch.name}); trees.set(watch.id, {tree, view: shown, element}); button.textContent = '▾'; button.setAttribute('aria-expanded', 'true'); diff --git a/js/developer/environment/menu.mjs b/js/developer/environment/menu.mjs index e4f36ab3..b683236c 100644 --- a/js/developer/environment/menu.mjs +++ b/js/developer/environment/menu.mjs @@ -107,18 +107,19 @@ export const longPress = {delay: 550, distance: 10, settle: 1000}; // --- Menu ------------------------------------------------------------------------------------------------------ export const menuStyles = ` -.webfront-menu{position:fixed;z-index:2147483647;box-sizing:border-box;min-width:min(220px,100vw);max-width:min(360px,100vw);max-height:100vh;overflow:auto;padding:4px;background:#202737;color:#e8edf4;border:1px solid #46536a;border-radius:8px;box-shadow:0 8px 32px #000a;font:14px system-ui} +.webfront-menu{position:fixed;z-index:2147483647;box-sizing:border-box;min-width:min(176px,100vw);max-width:min(320px,100vw);max-height:100vh;overflow:auto;padding:3px;background:#202737;color:#e8edf4;border:1px solid #46536a;border-radius:8px;box-shadow:0 8px 32px #000a;font:13px/1.3 system-ui} .webfront-menu[hidden]{display:none} .webfront-menu [role=menu]{display:flex;flex-direction:column} -.webfront-menu-item{box-sizing:border-box;display:flex;align-items:center;gap:16px;width:100%;min-height:44px;margin:0;padding:0 12px;border:0;border-radius:4px;background:none;color:inherit;font:inherit;text-align:start;cursor:pointer} +.webfront-menu-item{box-sizing:border-box;display:flex;align-items:center;gap:12px;width:100%;min-height:28px;margin:0;padding:0 10px;border:0;border-radius:4px;background:none;color:inherit;font:inherit;text-align:start;cursor:pointer} .webfront-menu-item>span:first-child{flex:1 1 auto} .webfront-menu-item:focus{outline:none} .webfront-menu-item:hover,.webfront-menu-item:focus-visible,.webfront-menu-item[aria-expanded=true]{background:#2f3a50} .webfront-menu-item:focus-visible{outline:2px solid #d7fa85;outline-offset:-2px} .webfront-menu-item[aria-disabled=true]{color:#8d97aa;cursor:default} .webfront-menu-hint{color:#a9b3c4;font-size:12px} -.webfront-menu-reason{margin:4px 0 0;padding:8px 12px;border-top:1px solid #46536a;color:#c8cfdb;font-size:12px;line-height:1.4} +.webfront-menu-reason{margin:3px 0 0;padding:6px 10px;border-top:1px solid #46536a;color:#c8cfdb;font-size:12px;line-height:1.4} .webfront-menu-reason:empty{display:none} +@media (pointer:coarse){.webfront-menu{min-width:min(220px,100vw);padding:4px;font-size:14px}.webfront-menu-item{min-height:44px;gap:16px;padding:0 12px}} `; let menus = 0; diff --git a/test/developer/specs/inspector-watches-specs.mjs b/test/developer/specs/inspector-watches-specs.mjs index 0c266a59..ca20d749 100644 --- a/test/developer/specs/inspector-watches-specs.mjs +++ b/test/developer/specs/inspector-watches-specs.mjs @@ -3,7 +3,7 @@ // and the view that shows a tree. A fake of the C++ side answers here; the real one is read in a browser by // test/web/suite/specs/inspector-specs.mjs. import {flags, functions, codes, readNode, readNodePage, readLimits, writeBound, utf8Bytes, parentOf, createWatchTree, createTreeView, - writeFailure} from '../../../js/developer/environment/inspector-watches.mjs'; + writeFailure, blockWidth, layouts, keptLayout, keepLayout, keptLayoutCount, watchTreeStyles} from '../../../js/developer/environment/inspector-watches.mjs'; const node = (path, kind, label, value, children = 0, bits = 0) => [path, kind, label, value, children, bits]; const refusal = (code, message = code) => Object.assign(new Error(message), {code}); @@ -485,13 +485,13 @@ describe('The tree of a watch', () => { }); describe('The view of a tree', () => { - async function shown(values, options) { + async function shown(values, options = {}) { const bridge = fakeWatch(values, options); const list = document.createElement('ul'); document.body.append(list); let view = null; const tree = createWatchTree({bridge, watch: 1, onUpdate: () => view?.render()}); - view = createTreeView({tree, list, view: {}}); + view = createTreeView({tree, list, view: options.view ?? {}, name: options.name ?? null}); await tree.open(); return {bridge, tree, view, list}; } @@ -678,4 +678,112 @@ describe('The view of a tree', () => { expect(rows(list).length).toBe(7); expect(list.querySelector('button.more').textContent).toBe('[6] not loaded'); }); + it('shows the kind of elements of one kind once, on their container, and their labels in a narrow column', async () => { + const {list} = await shown(['a', 'bb', 'ccc']); + const group = list.querySelector('ul.tree ul.tree'); + expect(group.classList.contains('homogeneous')).toBeTrue(); + expect(group.style.getPropertyValue('--label-width')).toBe('3ch'); + expect(rows(list)[0].querySelector(':scope > .row > .of').textContent).toBe('of string'); + expect(rows(list).slice(1).map(item => item.querySelector('.kind'))).toEqual([null, null, null]); + expect(rows(list).slice(1).map(item => item.querySelector('.label').textContent)).toEqual(['[0]', '[1]', '[2]']); + // Strings of different lengths are no grid: no block is offered. + expect(list.querySelector('ul.block')).toBeNull(); + expect(list.querySelector('button.layout')).toBeNull(); + }); + + it('shows a container of strings of the same length as a block, and goes back to the tree with its button', async () => { + const storage = new Map(); + const localStorage = {getItem: key => storage.get(key) ?? null, setItem: (key, value) => storage.set(key, value)}; + const grid = ['#..', '.#.', '..#']; + const {list, tree} = await shown(grid, {view: {localStorage}, name: 'grid'}); + expect(blockWidth(tree, '')).toBe(3); + let block = list.querySelector('ul.tree.block'); + expect(block).not.toBeNull(); + // One line per element, its value only: no label, no kind. + expect([...block.children].map(line => line.textContent)).toEqual(grid); + expect(block.querySelector('.label, .kind')).toBeNull(); + expect([...block.children].map(line => line.dataset.path)).toEqual(['/#0', '/#1', '/#2']); + const layout = list.querySelector('button.layout'); + expect(layout.textContent).toBe('Tree'); + layout.focus(); + layout.click(); + expect(list.querySelector('ul.block')).toBeNull(); + expect(rows(list).slice(1).map(item => item.querySelector('.label').textContent)).toEqual(['[0]', '[1]', '[2]']); + expect(document.activeElement).withContext('the focus stays on the button').toBe(list.querySelector('button.layout')); + expect(keptLayout({localStorage}, 'grid', '')).toBe(layouts.tree); + // The choice is kept for this watch: another view of it opens on the tree, another watch on the block. + const again = await shown(grid, {view: {localStorage}, name: 'grid'}); + expect(again.list.querySelector('ul.block')).toBeNull(); + const other = await shown(grid, {view: {localStorage}, name: 'other'}); + expect(other.list.querySelector('ul.block')).not.toBeNull(); + list.querySelector('button.layout').click(); + block = list.querySelector('ul.tree.block'); + expect(block).not.toBeNull(); + expect(keptLayout({localStorage}, 'grid', '')).toBe(layouts.block); + }); + + it('shows a grid of 32 by 32 characters as a square block, its rows as compact as its columns', async () => { + const style = document.createElement('style'); + style.textContent = watchTreeStyles; + document.head.append(style); + try { + const {list} = await shown(Array.from({length: 32}, (unused, row) => '.#'.repeat(16).slice(row % 2, row % 2 + 32).padEnd(32, '.'))); + const box = list.querySelector('ul.block').getBoundingClientRect(); + expect(Math.abs(box.width / box.height - 1)).withContext(`${box.width} x ${box.height}`).toBeLessThan(0.05); + // Smaller than the rows of the tree, which a grid of 32 rows would make more than three times higher than wide. + expect(box.height).toBeLessThan(32 * 16); + } finally { style.remove(); } + }); + + it('highlights the lines of a block that the last pass changed', async () => { + const grid = ['....', '....', '....']; + const {list, tree} = await shown(grid); + grid[1] = '.##.'; + await tree.refresh(); + const lines = () => [...list.querySelectorAll('ul.block > li')]; + expect(lines().map(line => line.classList.contains('changed'))).toEqual([false, true, false]); + expect(lines()[1].textContent).toBe('.##.'); + await tree.refresh(); + expect(lines().some(line => line.classList.contains('changed'))).toBeFalse(); + // A line that no longer has the length of the others makes the block a tree again, until they agree. + grid[2] = '..'; + await tree.refresh(); + expect(list.querySelector('ul.block')).toBeNull(); + }); + + it('edits a writable line of a block in place, and reads the full value of one that is cut', async () => { + const grid = ['ab', 'cd']; + const {list, tree, bridge} = await shown(grid); + list.querySelectorAll('ul.block .value')[1].click(); + const input = list.querySelector('ul.block input.edit'); + expect(input.value).toBe('cd'); + input.value = 'CD'; + input.dispatchEvent(new Event('input')); + input.dispatchEvent(new KeyboardEvent('keydown', {key: 'Enter'})); + await tree.settled(); + await new Promise(resolve => setTimeout(resolve)); + expect(grid[1]).toBe('CD'); + expect(list.querySelectorAll('ul.block > li')[1].textContent).toBe('CD'); + // A line that C++ cut offers its full value. + const children = bridge.answers[functions.children]; + bridge.answers[functions.children] = (...args) => { + const page = children(...args); + page[0] = page[0].map(([path, kind, label, value, count, bits]) => [path, kind, label, value, count, path === '/#0' ? bits | flags.truncated : bits]); + return page; + }; + await tree.load('', 0); + list.querySelector('ul.block button.full').click(); + await new Promise(resolve => setTimeout(resolve)); + expect(list.querySelector('ul.block pre.full').textContent).toBe('ababab'); + }); + + it('keeps a bounded number of layouts, the last chosen ones', () => { + const storage = new Map(); + const view = {localStorage: {getItem: key => storage.get(key) ?? null, setItem: (key, value) => storage.set(key, value)}}; + for (let index = 0; index <= keptLayoutCount; ++index) keepLayout(view, `watch${index}`, '', layouts.tree); + expect(keptLayout(view, 'watch0', '')).toBeNull(); + expect(keptLayout(view, `watch${keptLayoutCount}`, '')).toBe(layouts.tree); + expect(keptLayout({localStorage: {getItem: () => { throw new Error('blocked'); }}}, 'grid', '')).toBeNull(); + expect(keptLayout({localStorage: {getItem: () => '{"x":'}}, 'grid', '')).toBeNull(); + }); }); diff --git a/test/developer/specs/workspace-specs.mjs b/test/developer/specs/workspace-specs.mjs index 5404259e..35c93d98 100644 --- a/test/developer/specs/workspace-specs.mjs +++ b/test/developer/specs/workspace-specs.mjs @@ -306,7 +306,11 @@ describe('The developer page layout', () => { expect(items(0)[1].getAttribute('aria-haspopup')).toBe('menu'); expect(items(0)[0].getAttribute('aria-keyshortcuts')).toBe('F9'); expect(document.activeElement).toBe(items(0)[0]); - expect(items(0).every(item => item.getBoundingClientRect().height >= 44)).toBeTrue(); + // Compact for a mouse (#723), never below 24 px (WCAG 2.2, 2.5.8); 44 px again under a coarse pointer. + const heights = items(0).map(item => item.getBoundingClientRect().height); + if (matchMedia('(pointer: coarse)').matches) expect(heights.every(height => height >= 44)).withContext(String(heights)).toBeTrue(); + else expect(heights.every(height => height >= 24 && height <= 32)).withContext(String(heights)).toBeTrue(); + expect(items(0).every(item => item.getBoundingClientRect().width >= 24)).toBeTrue(); const box = menu.panels[0].getBoundingClientRect(); expect(box.right).toBeLessThanOrEqual(document.documentElement.clientWidth + 0.5); expect(box.left).toBeGreaterThanOrEqual(0); diff --git a/test/web/DeveloperTest.cpp b/test/web/DeveloperTest.cpp index d3af601f..ec57d316 100644 --- a/test/web/DeveloperTest.cpp +++ b/test/web/DeveloperTest.cpp @@ -8,12 +8,14 @@ // LLM: real-browser test; fixtures are served locally, no public network #include "../../examples/life/Life.hpp" +#include "../../examples/life/LifeWatches.hpp" #include "../driver/RequestLog.hpp" #include "../unit/TemporaryDirectory.hpp" #include #include #include +#include #include #include #include @@ -317,6 +319,20 @@ class Part { app.cppFunction("test.unwatch", [this](std::string name) { watches.erase(name); }); + // The watches of the Life example (#723): its grid, 32 strings of 32 characters, here holding a glider. + app.cppFunction("test.watchLife", [this] { + { + std::scoped_lock lock{lifeObserved.mutex}; + lifeObserved.grid[0][1] = '#'; + lifeObserved.grid[1][2] = '#'; + lifeObserved.grid[2].replace(0, 3, "###"); + } + lifeWatches.reset(); // a name is unique while its handle lives + lifeWatches.emplace(webfront::demo::watchLife(app, lifeObserved)); + }); + app.cppFunction("test.unwatchLife", [this] { + lifeWatches.reset(); + }); // A call that answers only once the page lets it go: the Bridge panel shows it pending meanwhile (#684). app.cppFunction("test.hold", [this] { held = true; @@ -339,6 +355,7 @@ class Part { ~Part() { watches.clear(); + lifeWatches.reset(); states->releaseAll(); app.stop(); // Drain while the commands, callback state and project are still alive. @@ -391,14 +408,16 @@ class Part { return config; } - std::atomic passed{false}; - bool reported = false; - std::mutex reportMutex; - std::shared_ptr states; - webfront::Commands commands; - webfront::UISubscription subscription; - std::map watches; // used on the server thread only - std::atomic held{false}; // test.hold answers once test.letGo cleared it + std::atomic passed{false}; + bool reported = false; + std::mutex reportMutex; + std::shared_ptr states; + webfront::Commands commands; + webfront::UISubscription subscription; + std::map watches; // used on the server thread only + webfront::demo::LifeObserved lifeObserved; // declared before its watches, destroyed after them + std::optional> lifeWatches; // used on the server thread only + std::atomic held{false}; // test.hold answers once test.letGo cleared it }; } // namespace diff --git a/test/web/developer-specs.mjs b/test/web/developer-specs.mjs index 89568580..19b888d5 100644 --- a/test/web/developer-specs.mjs +++ b/test/web/developer-specs.mjs @@ -1037,6 +1037,30 @@ try { await until(() => !inShownList(), `A removed watch must disappear from the inspector: ${listed()}`); assert(shownList.isConnected && frame.isConnected && frame.contentDocument === shownDocument, 'The watch must have disappeared from the list that showed it, still in the inspector'); + // The watches of Life (#723): its grid, 32 strings of 32 characters, shows as a block of square character + // cells, one line per row, without label or kind, inside the default window; its Tree button shows the rows + // one by one, and Block brings the block back. + await webFront.cppFunction('test.watchLife')(); + await until(() => listed().includes('grid'), `The watches of Life must appear in the inspector: ${listed()}`); + const gridItem = () => [...shownList.querySelectorAll(':scope > li')].find(item => item.querySelector('.name')?.textContent === 'grid'); + gridItem().querySelector('button.toggle').click(); + const gridBlock = () => gridItem()?.querySelector('ul.tree.block'); + await until(() => gridBlock()?.querySelectorAll(':scope > li').length === 32, 'The grid of Life must show as a block of 32 lines'); + const lines = [...gridBlock().querySelectorAll(':scope > li')]; + assert(lines.every(line => line.textContent.length === 32) && lines[0].textContent.startsWith('.#.') + && !gridBlock().querySelector('.label, .kind'), `The block must show the rows alone: ${lines[0]?.textContent}`); + const gridBox = gridBlock().getBoundingClientRect(); + assert(Math.abs(gridBox.width / gridBox.height - 1) < 0.08, + `A grid of 32 by 32 characters must be square: ${gridBox.width} x ${gridBox.height}`); + assert(gridBox.left >= 0 && gridBox.right <= frame.contentWindow.innerWidth && gridBox.height <= frame.contentWindow.innerHeight, + `The grid of Life must fit in the default window: ${JSON.stringify(gridBox)} in ${frame.contentWindow.innerWidth} x ${frame.contentWindow.innerHeight}`); + gridItem().querySelector('button.layout').click(); + await until(() => !gridBlock() && gridItem().querySelectorAll('ul.tree ul.tree > li .label').length === 32, + 'The Tree button must show the rows of the grid one by one'); + gridItem().querySelector('button.layout').click(); + await until(() => gridBlock()?.querySelectorAll(':scope > li').length === 32, 'The Block button must show the grid as a block again'); + await webFront.cppFunction('test.unwatchLife')(); + await until(() => !listed().includes('grid'), `The watches of Life must disappear once removed: ${listed()}`); const detach = floating().querySelector('.webfront-inspector-detach'); if (secondaryWindow) { // A frontend that opens windows: Detach moves the panel to a native window with its own proven connection. @@ -1192,8 +1216,17 @@ try { assert(again.menus().length === 1 && again.menus()[0].querySelector('[role=menu]'), 'A right click on the tab must open its menu'); assert(again.entries(0).map(entry => entry.firstChild.textContent).join() === 'Terminal,C++ state,TypeScript state', `The menu must offer the terminal and the inspectors: ${again.entries(0).map(entry => entry.textContent)}`); - assert(again.inside('.webfront-menu') && again.entries(0).every(entry => entry.getBoundingClientRect().height >= 44), - 'The menu must stay inside the window, with targets of 44 px'); + // Compact for a mouse (#723): entries of 24 to 32 px, never less than 24 px (WCAG 2.2, 2.5.8), and 44 px again under a + // coarse pointer; each is the element a pointer finds at its centre. + const coarse = page.defaultView.matchMedia('(pointer: coarse)').matches; + const entryBoxes = () => again.entries(0).map(entry => entry.getBoundingClientRect()); + assert(again.inside('.webfront-menu') && entryBoxes().every(box => box.width >= 24 + && (coarse ? box.height >= 44 : box.height >= 24 && box.height <= 32)), + `The menu must stay inside the window, with compact targets of 24 px at least: ${JSON.stringify(entryBoxes().map(box => box.height))}`); + assert(again.entries(0).every((entry, index) => { + const box = entryBoxes()[index]; + return page.elementFromPoint(box.left + box.width / 2, box.top + box.height / 2)?.closest('[role=menuitem]') === entry; + }), 'Each entry of the menu must be reachable by the pointer'); assert(page.activeElement === again.entries(0)[0] && again.state() === 'interface', 'The menu must take the focus, and leave the terminal collapsed'); // The arrows move in the menu and open a submenu. This page is a frame of the test page: its connection is not // the proven view, so no container is admitted and the entries say how to admit one. @@ -1220,6 +1253,13 @@ try { again.press(page.activeElement, {key: 'Escape'}); again.press(button, {key: 'F10', shiftKey: true}); assert(again.menus().length === 1, 'Shift+F10 must open the menu on the tab'); + // With the mouse: a click on an entry with a submenu opens it, a press elsewhere closes the menu. + again.entries(0)[1].dispatchEvent(new page.defaultView.MouseEvent('click', {bubbles: true, cancelable: true, button: 0})); + assert(again.menus().length === 2 && again.entries(1).length === 3, 'A click on C++ state must open its submenu'); + page.body.dispatchEvent(new page.defaultView.PointerEvent('pointerdown', {bubbles: true, cancelable: true, pointerType: 'mouse'})); + assert(again.menus().length === 0, 'A press outside the menu must close it'); + again.press(button, {key: 'F10', shiftKey: true}); + assert(again.menus().length === 1, 'Shift+F10 must open the menu again'); again.press(again.entries(0)[0], {key: 'Enter'}); assert(again.menus().length === 0 && again.state() === 'floating' && again.panel().contains(page.activeElement), 'The Terminal entry must open the terminal and give it the keys'); From e31d0157afd6cb05e161d772099cba717b16911a Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:55:10 +0100 Subject: [PATCH 2/6] Developer integration: report the size of Life's grid block (#723) --- test/web/developer-specs.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/web/developer-specs.mjs b/test/web/developer-specs.mjs index 19b888d5..998e859f 100644 --- a/test/web/developer-specs.mjs +++ b/test/web/developer-specs.mjs @@ -1050,6 +1050,7 @@ try { assert(lines.every(line => line.textContent.length === 32) && lines[0].textContent.startsWith('.#.') && !gridBlock().querySelector('.label, .kind'), `The block must show the rows alone: ${lines[0]?.textContent}`); const gridBox = gridBlock().getBoundingClientRect(); + await progress(`Life grid block: ${gridBox.width} x ${gridBox.height} px in a frame of ${frame.contentWindow.innerWidth} x ${frame.contentWindow.innerHeight}`); assert(Math.abs(gridBox.width / gridBox.height - 1) < 0.08, `A grid of 32 by 32 characters must be square: ${gridBox.width} x ${gridBox.height}`); assert(gridBox.left >= 0 && gridBox.right <= frame.contentWindow.innerWidth && gridBox.height <= frame.contentWindow.innerHeight, From 906406da5c21cdc287f587d565388b66340c81da Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:56:47 +0100 Subject: [PATCH 3/6] Watches: a block shows only a sequence labelled by its indices, never the fields of an object or the keys of a map (#723) --- docs/DEVELOPER_ENVIRONMENT.md | 2 +- docs/WATCHES.md | 18 ++++++++------- js/developer/environment/bundles.json | 2 +- .../environment/inspector-watches.mjs | 15 +++++++------ .../specs/inspector-watches-specs.mjs | 22 +++++++++++++++++++ 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/docs/DEVELOPER_ENVIRONMENT.md b/docs/DEVELOPER_ENVIRONMENT.md index bf0d11ca..de855f5f 100644 --- a/docs/DEVELOPER_ENVIRONMENT.md +++ b/docs/DEVELOPER_ENVIRONMENT.md @@ -490,7 +490,7 @@ environment's `mount`, not to the embedded bootstrap page): read by pages of 200 children and refreshed at the chosen period, the values that changed highlighted. A value the application made writable is edited in place (Enter writes, Escape cancels); a value that is cut offers its full text. Elements that are all leaves of one kind show that kind once, on their container (`sequence [3] of string`), with their - indices in a narrow column and their values aligned. A container of strings of the same length, such as the grid of + indices in a narrow column and their values aligned. A sequence of strings of the same length, such as the grid of Life, shows as a **block**: one line per element, without index or kind, in square character cells, so that a grid of 32 by 32 characters is square. The lines keep the highlighting of what changed, the full value and the edition in place. Its **Tree** button shows the elements one by one again and **Block** returns to the block; the choice is kept per watch diff --git a/docs/WATCHES.md b/docs/WATCHES.md index ef53e0f3..c4f40113 100644 --- a/docs/WATCHES.md +++ b/docs/WATCHES.md @@ -229,14 +229,16 @@ ADR; it uses the bridge's existing types only. Elements that are all leaves of one kind show that kind once, on their container (`sequence [32] of string`), with their indices in a narrow column and their values aligned, so that more of them fit in the window. -A container of two or more strings of the same length, such as `grid` above, shows as a **block**: one line per element, -without index or kind, in a monospace font whose letter spacing widens the advance of a character to the line height, so -that each character is a square cell and a grid of 32 by 32 characters is square; the grid of Life fits in the default inspector window. The -block keeps what the tree offers: the lines that the last pass changed are highlighted, a line that is cut offers its full -value, and a line of a writable watch is edited in place (click it, or Enter or F2). Its **Tree** button shows the -elements one by one again, and **Block** returns to the block; the choice is kept per watch and container in this -browser, as the period is. A line that no longer has the length of the others turns the block back into a tree until they -agree. The layout changes only what is shown: the pages of 200 elements and the passes are the same (ADR-027, section 3). +A sequence (a vector, an array) of two or more strings of the same length, labelled by their index, such as `grid` +above, shows as a **block**: one line per element, without index or kind, in a monospace font whose letter spacing +widens the advance of a character to the line height, so that each character is a square cell and a grid of 32 by 32 +characters is square; the grid of Life fits in the default inspector window. The block keeps what the tree offers: the +lines that the last pass changed are highlighted, a line that is cut offers its full value, and a line of a writable +watch is edited in place (click it, or Enter or F2). Its **Tree** button shows the elements one by one again, and +**Block** returns to the block; the choice is kept per watch and container in this browser, as the period is. A line +that no longer has the length of the others turns the block back into a tree until they agree. The fields of an object +and the entries of a map keep their names in the tree. The layout changes only what is shown: the pages of 200 elements +and the passes are the same (ADR-027, section 3). ## Reading a watch from an agent diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index 840090a8..2ce60412 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -28,7 +28,7 @@ "js/developer/environment/inspector.mjs": "44b6cd4443a3ed55a1bb188be96eafb64fc8b40b9a80500b3c47977740a6b336", "js/developer/environment/inspector-packages.mjs": "de7ee0bcd85df4eadb434e52bd571951eea3314eb1b0d1fd3ada52cf21a0b14c", "js/developer/environment/inspector-registry.mjs": "bcc15ef9801ad9a60e377eaa26582febb05c472d5e9b9678ee8b5ec369a2a15e", - "js/developer/environment/inspector-watches.mjs": "ecc5431cf2e098aee2a1fa2d41cd928059fea85e4ce97363d9500df1fdcf9933", + "js/developer/environment/inspector-watches.mjs": "79352a11828008476660ff37beb96df67ce60c9ad1cfd057324ae0575485d6af", "js/developer/environment/inspector-bridge.mjs": "b3f269245870d1a7e126cab5f80b2918164a5c24b3d351015cf52d44bf343cb8", "js/developer/environment/inspector.html": "66bfb80d6bd29bc9aabf71e0dd9b163dfcd1f1c77d1a41818645af1a4f9b8616", "js/developer/environment/tarball.mjs": "1c1e1aea067910e1fec74e85b4bf9fbefed9b38187a04d8d2764f0b9a96fca39", diff --git a/js/developer/environment/inspector-watches.mjs b/js/developer/environment/inspector-watches.mjs index f383cdeb..317cfcc8 100644 --- a/js/developer/environment/inspector-watches.mjs +++ b/js/developer/environment/inspector-watches.mjs @@ -423,25 +423,26 @@ const reasons = { /** Why a write was not applied, for the user. */ export const writeFailure = ({code, message}) => message || reasons[code] || code; -/** The kind of the elements that a block shows, one line each. */ -const blockKind = 'string'; +/** The kind of the containers that a block shows, and of their elements, one line each. */ +const blockContainer = 'sequence', blockKind = 'string'; /** The width of a text in the columns of a block: its characters (code points). */ const columns = text => [...text].length; /** * The width, in characters, of the block that the loaded children of `path` can be shown as; 0 when they cannot. A block shows - * two or more strings of the same length, none of them empty: the rows of a grid of text. It reads only what is loaded, so the - * pages and the passes are the same in both layouts (ADR-027, section 3). + * the elements of a sequence, labelled by their index, that are two or more strings of the same length, none of them empty: + * the rows of a grid of text. The fields of an object and the entries of a map keep their names in the tree. It reads only what + * is loaded, so the pages and the passes are the same in both layouts (ADR-027, section 3). */ export function blockWidth(tree, path) { const entry = tree.nodes.get(path); - if (!entry || entry.node.children < 2) return 0; + if (!entry || entry.node.kind !== blockContainer || entry.node.children < 2) return 0; let width = 0, count = 0; - for (const child of entry.positions.values()) { + for (const [position, child] of entry.positions) { const node = tree.nodes.get(child)?.node; if (!node) continue; - if (node.kind !== blockKind || node.children !== 0) return 0; + if (node.kind !== blockKind || node.children !== 0 || node.label !== `[${position}]`) return 0; const length = columns(node.value); if (!length || (count && length !== width)) return 0; width = length; diff --git a/test/developer/specs/inspector-watches-specs.mjs b/test/developer/specs/inspector-watches-specs.mjs index ca20d749..09ea45e3 100644 --- a/test/developer/specs/inspector-watches-specs.mjs +++ b/test/developer/specs/inspector-watches-specs.mjs @@ -735,6 +735,28 @@ describe('The view of a tree', () => { } finally { style.remove(); } }); + it('keeps the names of the fields of an object, or the keys of a map, whose values have the same length', async () => { + const bridge = fakeWatch(['abc', 'def']); + const children = bridge.answers[functions.children]; + const named = (kind, label) => (...args) => { + const page = children(...args); + page[0] = page[0].map(([path, nodeKind, nodeLabel, ...rest]) => path === '' ? [path, kind, nodeLabel, ...rest] : [path, nodeKind, label(path), ...rest]); + return page; + }; + for (const [kind, label] of [['map', path => `key${path.slice(2)}`], ['described', path => `field${path.slice(2)}`], ['sequence', path => `#${path.slice(2)}`]]) { + bridge.answers[functions.children] = named(kind, label); + const list = document.createElement('ul'); + document.body.append(list); + let view = null; + const tree = createWatchTree({bridge, watch: 1, onUpdate: () => view?.render()}); + view = createTreeView({tree, list, view: {}}); + await tree.open(); + expect(blockWidth(tree, '')).withContext(kind).toBe(0); + expect(list.querySelector('ul.block')).withContext(kind).toBeNull(); + expect(rows(list).slice(1).map(item => item.querySelector('.label').textContent)).toEqual([label('/#0'), label('/#1')]); + } + }); + it('highlights the lines of a block that the last pass changed', async () => { const grid = ['....', '....', '....']; const {list, tree} = await shown(grid); From 751e048ea0ff1f9be83a6fbf02de816d67d89a9d Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:57:52 +0100 Subject: [PATCH 4/6] Watches: a block names each line by its index for assistive technologies, and its controls take 44 px under a coarse pointer (#723) --- js/developer/environment/bundles.json | 2 +- js/developer/environment/inspector-watches.mjs | 12 ++++++++++-- test/developer/specs/inspector-watches-specs.mjs | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index 2ce60412..08a4277f 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -28,7 +28,7 @@ "js/developer/environment/inspector.mjs": "44b6cd4443a3ed55a1bb188be96eafb64fc8b40b9a80500b3c47977740a6b336", "js/developer/environment/inspector-packages.mjs": "de7ee0bcd85df4eadb434e52bd571951eea3314eb1b0d1fd3ada52cf21a0b14c", "js/developer/environment/inspector-registry.mjs": "bcc15ef9801ad9a60e377eaa26582febb05c472d5e9b9678ee8b5ec369a2a15e", - "js/developer/environment/inspector-watches.mjs": "79352a11828008476660ff37beb96df67ce60c9ad1cfd057324ae0575485d6af", + "js/developer/environment/inspector-watches.mjs": "58b816889326d2c44a8957451fb5f50d27434819d9c26263da8b9cea4a42422d", "js/developer/environment/inspector-bridge.mjs": "b3f269245870d1a7e126cab5f80b2918164a5c24b3d351015cf52d44bf343cb8", "js/developer/environment/inspector.html": "66bfb80d6bd29bc9aabf71e0dd9b163dfcd1f1c77d1a41818645af1a4f9b8616", "js/developer/environment/tarball.mjs": "1c1e1aea067910e1fec74e85b4bf9fbefed9b38187a04d8d2764f0b9a96fca39", diff --git a/js/developer/environment/inspector-watches.mjs b/js/developer/environment/inspector-watches.mjs index 317cfcc8..b8e5fc81 100644 --- a/js/developer/environment/inspector-watches.mjs +++ b/js/developer/environment/inspector-watches.mjs @@ -409,6 +409,8 @@ ul.watches button.toggle,ul.tree button.toggle{width:44px;height:44px} ul.tree .row.target{min-height:44px} ul.tree .spacer{width:44px} ul.tree button.more,ul.tree button.full,ul.tree button.layout{min-height:44px;padding:0 10px} +ul.tree.block>li>.row.target{line-height:44px} +ul.tree.block>li>.row.target button.full{height:44px;min-height:44px} }`; /** The most characters of a full value that the page shows; the rest is told by its size. */ @@ -602,14 +604,20 @@ export function createTreeView({tree, list, view = globalThis, name = null}) { } } - /** A node as one line of a block: its value only, its label and kind being those of the block. */ + /** + * A node as one line of a block: its value only, its kind being the block's. Its index is not shown, but it names the line + * for assistive technologies. A line with a control is a target of 44 px under a coarse pointer. + */ function blockLine(path) { const {node, changed} = tree.nodes.get(path); const item = element('li'); item.setAttribute('role', 'treeitem'); + item.setAttribute('aria-label', `${node.label}: ${node.value}`); item.dataset.path = path; if (changed && changed === tree.pass) item.classList.add('changed'); - valueOf(path, node, element('div', 'row'), item); + const line = element('div', 'row'); + valueOf(path, node, line, item); + if (line.querySelector('button, input, [role=button]')) line.classList.add('target'); return item; } diff --git a/test/developer/specs/inspector-watches-specs.mjs b/test/developer/specs/inspector-watches-specs.mjs index 09ea45e3..eeec78c4 100644 --- a/test/developer/specs/inspector-watches-specs.mjs +++ b/test/developer/specs/inspector-watches-specs.mjs @@ -703,6 +703,8 @@ describe('The view of a tree', () => { expect([...block.children].map(line => line.textContent)).toEqual(grid); expect(block.querySelector('.label, .kind')).toBeNull(); expect([...block.children].map(line => line.dataset.path)).toEqual(['/#0', '/#1', '/#2']); + // The index is not shown, but names each line for assistive technologies. + expect([...block.children].map(line => line.getAttribute('aria-label'))).toEqual(['[0]: #..', '[1]: .#.', '[2]: ..#']); const layout = list.querySelector('button.layout'); expect(layout.textContent).toBe('Tree'); layout.focus(); From 2beebc67eda8dbe58b1f482748fd9cc201740c03 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:59:10 +0100 Subject: [PATCH 5/6] Watches: no block for strings that break their line; a Full value button keeps 24 px in a block (#723) --- docs/WATCHES.md | 12 ++++++------ js/developer/environment/bundles.json | 2 +- js/developer/environment/inspector-watches.mjs | 8 ++++++-- test/developer/specs/inspector-watches-specs.mjs | 12 ++++++++++++ 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/docs/WATCHES.md b/docs/WATCHES.md index c4f40113..93b9f5ea 100644 --- a/docs/WATCHES.md +++ b/docs/WATCHES.md @@ -233,12 +233,12 @@ A sequence (a vector, an array) of two or more strings of the same length, label above, shows as a **block**: one line per element, without index or kind, in a monospace font whose letter spacing widens the advance of a character to the line height, so that each character is a square cell and a grid of 32 by 32 characters is square; the grid of Life fits in the default inspector window. The block keeps what the tree offers: the -lines that the last pass changed are highlighted, a line that is cut offers its full value, and a line of a writable -watch is edited in place (click it, or Enter or F2). Its **Tree** button shows the elements one by one again, and -**Block** returns to the block; the choice is kept per watch and container in this browser, as the period is. A line -that no longer has the length of the others turns the block back into a tree until they agree. The fields of an object -and the entries of a map keep their names in the tree. The layout changes only what is shown: the pages of 200 elements -and the passes are the same (ADR-027, section 3). +lines that the last pass changed are highlighted, a line that is cut offers its full value (with a 24 px button, which +makes that line as high), and a line of a writable watch is edited in place (click it, or Enter or F2). Its **Tree** +button shows the elements one by one again, and **Block** returns to the block; the choice is kept per watch and +container in this browser, as the period is. A line that no longer has the length of the others turns the block back +into a tree until they agree. The fields of an object, the entries of a map and strings that break their line keep the +tree. The layout changes only what is shown: the pages of 200 elements and the passes are the same (ADR-027, section 3). ## Reading a watch from an agent diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index 08a4277f..eeee54f2 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -28,7 +28,7 @@ "js/developer/environment/inspector.mjs": "44b6cd4443a3ed55a1bb188be96eafb64fc8b40b9a80500b3c47977740a6b336", "js/developer/environment/inspector-packages.mjs": "de7ee0bcd85df4eadb434e52bd571951eea3314eb1b0d1fd3ada52cf21a0b14c", "js/developer/environment/inspector-registry.mjs": "bcc15ef9801ad9a60e377eaa26582febb05c472d5e9b9678ee8b5ec369a2a15e", - "js/developer/environment/inspector-watches.mjs": "58b816889326d2c44a8957451fb5f50d27434819d9c26263da8b9cea4a42422d", + "js/developer/environment/inspector-watches.mjs": "57f00272f14900c8ff2271e7f73c17c7c7e6c0de34d4d3dc1c37698366e0d1db", "js/developer/environment/inspector-bridge.mjs": "b3f269245870d1a7e126cab5f80b2918164a5c24b3d351015cf52d44bf343cb8", "js/developer/environment/inspector.html": "66bfb80d6bd29bc9aabf71e0dd9b163dfcd1f1c77d1a41818645af1a4f9b8616", "js/developer/environment/tarball.mjs": "1c1e1aea067910e1fec74e85b4bf9fbefed9b38187a04d8d2764f0b9a96fca39", diff --git a/js/developer/environment/inspector-watches.mjs b/js/developer/environment/inspector-watches.mjs index b8e5fc81..230af833 100644 --- a/js/developer/environment/inspector-watches.mjs +++ b/js/developer/environment/inspector-watches.mjs @@ -402,7 +402,8 @@ ul.tree.block>li>.row{display:block;min-height:0;line-height:1em;white-space:pre ul.tree.block .value{display:inline-block;vertical-align:top;letter-spacing:calc(1em - 1ch);white-space:pre;overflow-wrap:normal} ul.tree.block .value.writable{border-bottom:0;text-decoration:underline dotted #46536a} ul.tree.block .changed>.row .value{background:#4a3d12} -ul.tree.block .row button.full{min-height:0;height:1em;padding:0 4px;font-size:inherit;line-height:1} +ul.tree.block>li>.row.control{line-height:24px} +ul.tree.block .row button.full{height:24px;min-height:24px;vertical-align:top;line-height:1;letter-spacing:normal} ul.tree.block .row .note{white-space:normal;letter-spacing:normal} @media (pointer:coarse){ ul.watches button.toggle,ul.tree button.toggle{width:44px;height:44px} @@ -446,7 +447,8 @@ export function blockWidth(tree, path) { if (!node) continue; if (node.kind !== blockKind || node.children !== 0 || node.label !== `[${position}]`) return 0; const length = columns(node.value); - if (!length || (count && length !== width)) return 0; + // A line break would show one element on several lines, which a block, without indices, could not tell apart. + if (!length || (count && length !== width) || /[\n\r\u2028\u2029]/.test(node.value)) return 0; width = length; ++count; } @@ -618,6 +620,8 @@ export function createTreeView({tree, list, view = globalThis, name = null}) { const line = element('div', 'row'); valueOf(path, node, line, item); if (line.querySelector('button, input, [role=button]')) line.classList.add('target'); + // A button keeps 24 px: the line of a value that is cut is as high as its Full value button. + if (line.querySelector('button')) line.classList.add('control'); return item; } diff --git a/test/developer/specs/inspector-watches-specs.mjs b/test/developer/specs/inspector-watches-specs.mjs index eeec78c4..5c905bb2 100644 --- a/test/developer/specs/inspector-watches-specs.mjs +++ b/test/developer/specs/inspector-watches-specs.mjs @@ -689,6 +689,10 @@ describe('The view of a tree', () => { // Strings of different lengths are no grid: no block is offered. expect(list.querySelector('ul.block')).toBeNull(); expect(list.querySelector('button.layout')).toBeNull(); + // Nor strings that break their line, which a block would show as more lines than elements. + const broken = await shown(['a\nb', 'cde']); + expect(blockWidth(broken.tree, '')).toBe(0); + expect(broken.list.querySelector('ul.block')).toBeNull(); }); it('shows a container of strings of the same length as a block, and goes back to the tree with its button', async () => { @@ -796,6 +800,14 @@ describe('The view of a tree', () => { return page; }; await tree.load('', 0); + const style = document.createElement('style'); + style.textContent = watchTreeStyles; + document.head.append(style); + try { + // Its button keeps a target of 24 px, and so does its line. + expect(list.querySelector('ul.block button.full').getBoundingClientRect().height).toBeGreaterThanOrEqual(24); + expect(list.querySelector('ul.block > li').getBoundingClientRect().height).toBeGreaterThanOrEqual(24); + } finally { style.remove(); } list.querySelector('ul.block button.full').click(); await new Promise(resolve => setTimeout(resolve)); expect(list.querySelector('ul.block pre.full').textContent).toBe('ababab'); From d76e03ee13996d0d902dec5fb8cc4e690cf554f5 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:00:06 +0100 Subject: [PATCH 6/6] Watches: say why a writable line of a block is as high as its text with a mouse (#723) --- docs/WATCHES.md | 7 ++++--- js/developer/environment/bundles.json | 2 +- js/developer/environment/inspector-watches.mjs | 5 ++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/WATCHES.md b/docs/WATCHES.md index 93b9f5ea..6908375d 100644 --- a/docs/WATCHES.md +++ b/docs/WATCHES.md @@ -234,9 +234,10 @@ above, shows as a **block**: one line per element, without index or kind, in a m widens the advance of a character to the line height, so that each character is a square cell and a grid of 32 by 32 characters is square; the grid of Life fits in the default inspector window. The block keeps what the tree offers: the lines that the last pass changed are highlighted, a line that is cut offers its full value (with a 24 px button, which -makes that line as high), and a line of a writable watch is edited in place (click it, or Enter or F2). Its **Tree** -button shows the elements one by one again, and **Block** returns to the block; the choice is kept per watch and -container in this browser, as the period is. A line that no longer has the length of the others turns the block back +makes that line as high), and a line of a writable watch is edited in place (click it, or Enter or F2; with a mouse it +is as high as its line of text, and **Tree** gives rows of 24 px, 44 px under a coarse pointer as in the block). Its +**Tree** button shows the elements one by one again, and **Block** returns to the block; the choice is kept per watch +and container in this browser, as the period is. A line that no longer has the length of the others turns the block back into a tree until they agree. The fields of an object, the entries of a map and strings that break their line keep the tree. The layout changes only what is shown: the pages of 200 elements and the passes are the same (ADR-027, section 3). diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index eeee54f2..0de7925a 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -28,7 +28,7 @@ "js/developer/environment/inspector.mjs": "44b6cd4443a3ed55a1bb188be96eafb64fc8b40b9a80500b3c47977740a6b336", "js/developer/environment/inspector-packages.mjs": "de7ee0bcd85df4eadb434e52bd571951eea3314eb1b0d1fd3ada52cf21a0b14c", "js/developer/environment/inspector-registry.mjs": "bcc15ef9801ad9a60e377eaa26582febb05c472d5e9b9678ee8b5ec369a2a15e", - "js/developer/environment/inspector-watches.mjs": "57f00272f14900c8ff2271e7f73c17c7c7e6c0de34d4d3dc1c37698366e0d1db", + "js/developer/environment/inspector-watches.mjs": "d913f20f3b2d36788b6e2d831065a8cccbd242abc7a86d366e27533b91ee56e7", "js/developer/environment/inspector-bridge.mjs": "b3f269245870d1a7e126cab5f80b2918164a5c24b3d351015cf52d44bf343cb8", "js/developer/environment/inspector.html": "66bfb80d6bd29bc9aabf71e0dd9b163dfcd1f1c77d1a41818645af1a4f9b8616", "js/developer/environment/tarball.mjs": "1c1e1aea067910e1fec74e85b4bf9fbefed9b38187a04d8d2764f0b9a96fca39", diff --git a/js/developer/environment/inspector-watches.mjs b/js/developer/environment/inspector-watches.mjs index 230af833..bc79c160 100644 --- a/js/developer/environment/inspector-watches.mjs +++ b/js/developer/environment/inspector-watches.mjs @@ -608,7 +608,10 @@ export function createTreeView({tree, list, view = globalThis, name = null}) { /** * A node as one line of a block: its value only, its kind being the block's. Its index is not shown, but it names the line - * for assistive technologies. A line with a control is a target of 44 px under a coarse pointer. + * for assistive technologies. A line with a control is a target of 44 px under a coarse pointer. With a mouse, a writable + * line is a target as high as the line of text, as a link in a paragraph is (WCAG 2.2, 2.5.8, inline exception): a taller + * line would no longer give square cells. It is also edited from the keyboard (Enter, F2), and the Tree button gives + * rows of 24 px; a Full value button keeps its 24 px. */ function blockLine(path) { const {node, changed} = tree.nodes.get(path);