diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fc1d5c..2c5c56c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: steps: - uses: actions/checkout@v7.0.1 - - uses: jdx/mise-action@v5.4.0 + - uses: jdx/mise-action@v5.5.0 - name: mise run install run: mise run install diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d0629e0..d6974a6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -58,7 +58,7 @@ jobs: exit 1 fi - - uses: jdx/mise-action@v5.4.0 + - uses: jdx/mise-action@v5.5.0 - name: mise run install run: mise run install diff --git a/CHANGELOG.md b/CHANGELOG.md index 376d76c..244f2cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,35 @@ All notable changes to `@standards-lab/web-components` are documented here. The [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.5.0] - 2026-12-02 + +This minor release breaks no consumer: the foundation peer stays `^0.5.0`, and every field it adds +is optional, so a stage or an event that leaves them out shows as it did. + +### Added + +- `sl-stage-timeline`'s stage gains `startedAt`, `attempt`, and `note`. Given a `startedAt`, a + complete or failed stage shows its duration to its `completedAt` or `failedAt`, and an active + stage the time elapsed, ticking each second, by the foundation's `formatDuration` in its digital + style; a start that doesn't parse, or a complete or failed stage's start after its end, shows + none. An `attempt` above 1 shows as "Attempt n". A `note` shows on its own row under the detail + line, above a failed stage's reason, and wraps to the timeline's width without widening it; a + blank note shows nothing. The duration and the attempt each hold a slot in every stage, so a + stage that ticks or reaches a later attempt moves nothing, and the timeline runs one timer, only + while it is connected and an active stage has a valid start. +- `sl-event-log`'s event gains `extensions`, a map of CloudEvents extension attribute names to + their string values. Each shows under the source, subject, and id, in name order, on a line of + its own labelled by its name, the name and the value each cut with an ellipsis when longer than + the line, as the subject and the id are, without widening the log. An extension whose value + isn't a non-empty string shows nothing, nor does an empty map. The event log specimen shows an + event with many long extensions. + +### Changed + +- The repository's tooling takes claude-plugins 0.26.0 and chrome-headless-shell 158.0.8127.91, + the foundation's development pin is its v0.5.1 tag, and the workflows take jdx/mise-action + v5.5.0. + ## [0.4.0] - 2026-12-01 This minor release breaks a consumer on web-foundation 0.4: the foundation peer is `^0.5.0`. It @@ -160,6 +189,7 @@ that measured or padded around them checks its layout. - Releases by tag: each `v` tag marks a pack commit whose tree is the pack, the build included, and whose one parent is main's merge commit; its GitHub release carries the tarball. +[0.5.0]: https://github.com/standards-lab/web-components/releases/tag/v0.5.0 [0.4.0]: https://github.com/standards-lab/web-components/releases/tag/v0.4.0 [0.3.0]: https://github.com/standards-lab/web-components/releases/tag/v0.3.0 [0.2.0]: https://github.com/standards-lab/web-components/releases/tag/v0.2.0 diff --git a/README.md b/README.md index 35dad60..8aca0da 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,9 @@ and the components share one copy of each, and a restyle of the foundation's she name reaches the components' shadow roots too. Install all three by their tags: ``` -pnpm add github:standards-lab/web-components#v0.4.0 github:standards-lab/web-foundation#v0.5.0 github:standards-lab/web-icons#v0.1.0 -bun add github:standards-lab/web-components#v0.4.0 github:standards-lab/web-foundation#v0.5.0 github:standards-lab/web-icons#v0.1.0 -npm install --allow-git=root github:standards-lab/web-components#v0.4.0 github:standards-lab/web-foundation#v0.5.0 github:standards-lab/web-icons#v0.1.0 +pnpm add github:standards-lab/web-components#v0.5.0 github:standards-lab/web-foundation#v0.5.1 github:standards-lab/web-icons#v0.1.0 +bun add github:standards-lab/web-components#v0.5.0 github:standards-lab/web-foundation#v0.5.1 github:standards-lab/web-icons#v0.1.0 +npm install --allow-git=root github:standards-lab/web-components#v0.5.0 github:standards-lab/web-foundation#v0.5.1 github:standards-lab/web-icons#v0.1.0 ``` npm 12 refuses git dependencies unless `--allow-git` allows them; `root` allows the ones the diff --git a/docs/components.md b/docs/components.md index cf4923b..4f24e5e 100644 --- a/docs/components.md +++ b/docs/components.md @@ -126,9 +126,14 @@ the tests measure as they do. loading note; a text type given a Blob shows as empty, as `""` does. - `./event-log.js`: `sl-event-log`, events as a log in the order given, each its type, its time by the foundation's `formatDateTime` when it has one, its source, subject, and id, each labelled on - a line of its own, and its data pretty-printed in a native details, collapsed; events appended - leave those shown in place, and a constrained log scrolls inside, following the newest only from - its end. It exports its event type, a CloudEvents subset, and sends no event. + a line of its own, then its `extensions`, CloudEvents extension attributes given as a map of + names to strings, each on a line of its own labelled by its name, in name order, so every event + lists them alike whatever order its map was written in; a subject, an id, and an extension's + name and value longer than the line are cut with an ellipsis, whole in their titles, and an + extension whose value isn't a non-empty string, or an empty map, shows nothing. Its data shows + pretty-printed in a native details, collapsed; events appended leave those shown in place, and a + constrained log scrolls inside, following the newest only from its end. It exports its event + type, a CloudEvents subset, and sends no event. - `./search-results.js`: `sl-search-results`, a search's matches under a status line, each a native button of its document's name, the field it matched in, and its snippet, marked case-insensitively as text for the query the matches were set with; its count names that query @@ -179,11 +184,16 @@ the tests measure as they do. `upload-cancel` with an upload's id. It exports its upload type and binds no key. - `./stage-timeline.js`: `sl-stage-timeline`, a run's stages as a connected, ordered list of steps in their positions' order, each its name, its state's label and marker, and its time by - the foundation's `formatDateTime`, a complete stage's `completedAt` or a failed one's `failedAt`; - a failed stage's `reason` shows under its label, part of its step for assistive technology, and - wraps to the timeline's width without widening it. The active stage is the current step, and a - stage that advances changes in place, moving nothing. It exports its stage type, holds nothing - focusable, and sends no event. + the foundation's `formatDateTime`, a complete stage's `completedAt` or a failed one's `failedAt`. + Given a `startedAt`, a complete or failed stage shows its duration to that time, and an active + one the time elapsed, ticking each second, by the foundation's `formatDuration` in its digital + style; a start that doesn't parse, or that comes after a complete or failed stage's end, shows + none. An `attempt` above 1 shows as "Attempt n". A `note` shows on its own row under the detail + line, and a failed stage's `reason` under that; + both are part of the step for assistive technology and wrap to the timeline's width without + widening it. The active stage is the current step, and a stage that advances or ticks changes in + place, moving nothing. It runs one timer, only while connected and an active stage has a valid + start. It exports its stage type, holds nothing focusable, and sends no event. ## Sheets diff --git a/docs/internals.md b/docs/internals.md index 68dbb42..f715a7a 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -128,6 +128,8 @@ each sheet is laid out as it is. - The time shows to the second, as the stage timeline's does, since a run's events arrive seconds apart. +- Extensions sort by name, compared by UTF-16 code unit rather than by locale, so the order is the + same on every page and whichever producer wrote the map. - A string datum shows as it is, since text data reads as text; a bigint as its digits; and a value JSON can't write, a circular object or a function, as its `String()`. @@ -168,6 +170,16 @@ each sheet is laid out as it is. - The time slot holds hidden a time as wide as any the format writes in the page's locale, a two-digit day and hour, so a stage that completes shows its time in space already there. +- The duration slot holds hidden the longest duration under a day, `23:59:59` in the digital + style, and the attempt slot `Attempt 99`; a duration of a day or more, or an attempt past 99, + widens its own slot. Every stage reserves both slots, so a narrow timeline's detail line may + wrap to a second line before either fills. +- An active stage's elapsed time is clamped at zero, so a start a little ahead of the page's clock + shows `0:00:00`; a complete or failed stage whose start comes after its end shows no duration. +- The timer is one `setInterval` of a second that requests an update; `updated` and + `connectedCallback` start it when an active stage has a valid start and it isn't running, and + `updated` and `disconnectedCallback` stop it otherwise. Each render reads the clock once, so every + active stage ticks together. - The stages sort by position with a stable sort, so equal positions keep the given order, and each step is keyed by its name. diff --git a/docs/layout.md b/docs/layout.md index e29349b..8652271 100644 --- a/docs/layout.md +++ b/docs/layout.md @@ -54,8 +54,8 @@ layout each one promises. name's line only when the two don't fit side by side, and a short name never wraps it in a parent sized to the content. - A slot that must not change width as its text changes (the composer's action, the stage - timeline's label and time) stacks every text it may show in one grid cell, the ones not shown - `visibility: hidden`, so it is as wide as the widest. + timeline's label, time, duration, and attempt) stacks every text it may show in one grid cell, + the ones not shown `visibility: hidden`, so it is as wide as the widest. - A visually hidden name (the composer's label, the entry's kind, the drawer's Close label) is a one-pixel absolute box clipped to nothing, so it takes no row and no gap. - `field-sizing` is Baseline newly available, as the foundation's `.field-grow` notes. Without it @@ -100,9 +100,10 @@ layout each one promises. value, and the larger step between pairs keeps each label grouped with its own value. - The step between pairs is each pair's margin, not the metadata's gap, because the metadata is the container the query reads, and a container query styles only what is inside its container. -- A subject or an id longer than its line is cut with an ellipsis inside its own value, which - neither scrolls nor takes focus; its whole text stays in the DOM for selection, copying, and a - screen reader. +- A subject, an id, or an extension's name or value longer than its line is cut with an ellipsis + inside its own box, which neither scrolls nor takes focus; its whole text stays in the DOM for + selection, copying, and a screen reader. Each label and value is held to the pair's width, so a + label that sits over its value at a narrow width is cut too rather than widen the log. ## Chat thread @@ -154,13 +155,17 @@ layout each one promises. ## Stage timeline - Each step is a grid of the marker's column and the text's, its rows the name, the detail line, a - failed stage's reason, and a gap; the connector spans the last three in the marker's column, so it - runs past a failed step's reason. The last step has no connector and no gap. + note, a failed stage's reason, and a gap; the connector spans the last four in the marker's + column, so it runs past a step's note and reason. The last step has no connector and no gap. - A pending stage's name recedes by color alone, so it keeps its width. - The active marker's ring is painted, never laid out, so it moves nothing; under reduced motion the tinted marker alone reads as in progress. -- A failed stage's reason contains its inline size, so it wraps to the column the names and detail - lines set and never widens the timeline. Its muted color leaves the failure's hue to the label. +- A note and a failed stage's reason each contain their inline size, so they wrap to the column the + names and detail lines set and never widen the timeline. Their muted color leaves the failure's + hue to the label. +- The detail line wraps between its slots, never inside one: every stage reserves the duration and + attempt slots, so at a narrow width the line may take a second row before either fills, and a + stage that ticks or reaches a later attempt moves nothing. ## Entry diff --git a/examples/event-log.html b/examples/event-log.html index 7071a22..7f157bb 100644 --- a/examples/event-log.html +++ b/examples/event-log.html @@ -51,6 +51,17 @@ { ...run[3], id: "kinds.4", type: "emulator.run.chunks", data: [{ index: 0, tokens: 512 }, { index: 1, tokens: 488 }] }, { ...run[4], id: "kinds.5", type: "emulator.run.ping", subject: null, data: undefined }, ]; + const extended = run.slice(0, 2).map((event, index) => ({ + ...event, + extensions: { + layer: "pipeline.stage.ingestion.document-processing.extraction-and-chunking", + correlationid: `${runs[0][0]}.${runs[0][1]}.correlation`, + causationid: index ? run[0].id : `${runs[0][1]}.upload.received.by-the-gateway`, + traceparent: `00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01.${event.id}`, + partitionkeyforthedocumentstore: `tenant-a/collection-b/${runs[0][1]}`, + dataref: "https://storage.example.invalid/runs/0193a5c2-7e4b-7c1d-9f2a-3b4c5d6e7f80/stages/upload/payload.json", + }, + })); const log = (fields, open = () => false) => () => { const element = make("sl-event-log", fields); @@ -80,6 +91,10 @@ label: "Every kind of data, opened: an object, a string, null, an array, and none", build: log({ events: kinds }, () => true), }, + { + label: "Extensions, many and long: each labelled under the id, in name order, cut on its line", + build: log({ events: extended }), + }, { label: "Many events: three runs', held to 16rem by the page, scrolling inside the log", build: log({ events: many, className: "held" }), @@ -105,7 +120,7 @@

Event log

sl-event-log, events in order as a log, each its type, time, source, subject, - and id, its data on demand, in each of its states. + id, and extensions, its data on demand, in each of its states.

diff --git a/examples/stage-timeline.html b/examples/stage-timeline.html index 7a2d5c2..320e1d4 100644 --- a/examples/stage-timeline.html +++ b/examples/stage-timeline.html @@ -54,12 +54,57 @@ : stage, ); + const starts = [ + "2026-10-29T15:42:00Z", + "2026-10-29T15:42:07Z", + "2026-10-29T15:42:09Z", + "2026-10-29T15:42:16Z", + "2026-10-29T15:42:31Z", + ]; + const timed = (stages) => + stages.map((stage) => + stage.state === "complete" || stage.state === "failed" + ? { ...stage, startedAt: starts[stage.position - 1] } + : stage, + ); + const failedNoted = timed(failed).map((stage) => + stage.state === "failed" + ? { + ...stage, + attempt: 2, + note: + "Second attempt, after the first stopped when the extractor's worker restarted; the upload at /var/lib/pipeline/uploads/0193a5d2-7c10-7e4f-9a1b-2c3d4e5f6071/fail-at-extraction.txt was read again from the start", + reason: + 'emulated failure: the document\'s name matches the fail rule "fail-at-*:extraction"; the extractor gave up after reading /var/lib/pipeline/uploads/0193a5d2-7c10-7e4f-9a1b-2c3d4e5f6071/fail-at-extraction.txt and three retries', + } + : stage, + ); + const running = timed(partWay).map((stage) => + stage.state === "active" + ? { + ...stage, + startedAt: new Date(Date.now() - 134_000), + attempt: 3, + note: "Retrying after two timeouts", + } + : stage, + ); + const timeline = (stages) => () => make("sl-stage-timeline", { stages }); specimens([ { label: "All pending: the run has not started", build: timeline(pending) }, { label: "Part way: two complete, extraction in progress", build: timeline(partWay) }, { label: "Complete: every stage, each with its time", build: timeline(complete) }, { label: "Failed: extraction failed after two completed, with its time and reason", build: timeline(failed) }, + { label: "Durations: each finished stage with how long it took", build: timeline(timed(complete)) }, + { + label: "Failed at attempt 2, with a long note and a long reason", + build: timeline(failedNoted), + }, + { + label: "Running: extraction at attempt 3, its clock ticking from a start 2:14 before the page loaded", + build: timeline(running), + }, ]); const fit = (label, parent) => ({ label, @@ -79,8 +124,8 @@

Stage timeline

sl-stage-timeline, a run's stages as a connected list of steps, each its name, - its state, and when it completed or failed, a failed stage with why, in each of the run's - states. + its state, when it completed or failed, how long it took or has taken, its attempt past the + first, a note, and a failed stage with why, in each of the run's states.

diff --git a/mise.toml b/mise.toml index ad8544f..2bd8409 100644 --- a/mise.toml +++ b/mise.toml @@ -4,7 +4,7 @@ task.run_auto_install = false [tools] -"github:standards-lab/claude-plugins" = { version = "0.25.0", version_prefix = "marathon/v" } +"github:standards-lab/claude-plugins" = { version = "0.26.0", version_prefix = "marathon/v" } actionlint = "1.7.12" node = "26.14.0" pnpm = "12.25.1" @@ -12,12 +12,12 @@ shellcheck = "0.11.0" "github:microsoft/typescript-go" = { version = "7.0.2", version_prefix = "typescript/v", bin_path = "package/lib" } [tools."http:chrome-headless-shell"] -version = "158.0.8127.88" +version = "158.0.8127.91" version_list_url = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json" version_json_path = ".channels.Stable.version" [tools."http:chrome-headless-shell".platforms] -linux-x64 = { url = "https://storage.googleapis.com/chrome-for-testing-public/{{ version }}/linux64/chrome-headless-shell-linux64.zip", checksum = "sha256:63401333cc587645bfaeea7f0c90958b327d249251e23954a47f30112ca23d5b", size = "132091593" } +linux-x64 = { url = "https://storage.googleapis.com/chrome-for-testing-public/{{ version }}/linux64/chrome-headless-shell-linux64.zip", checksum = "sha256:95fd6e7f5c7244545102abd33ae7a01b58d84e19e646416a5a50f34d13c92a01", size = "132090545" } [tasks.build] description = "Build src/ into dist/: tsc's emit, with the .css beside it" diff --git a/package.json b/package.json index af5b5d2..75a638f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@standards-lab/web-components", - "version": "0.4.0", + "version": "0.5.0", "license": "Apache-2.0", "type": "module", "files": [ @@ -24,7 +24,7 @@ "devDependencies": { "@eslint-community/eslint-plugin-eslint-comments": "4.8.1", "@eslint/js": "10.0.1", - "@standards-lab/web-foundation": "github:standards-lab/web-foundation#v0.5.0", + "@standards-lab/web-foundation": "github:standards-lab/web-foundation#v0.5.1", "@standards-lab/web-icons": "github:standards-lab/web-icons#v0.1.0", "@standards-lab/web-tooling": "github:standards-lab/web-tooling#v0.2.1", "@types/node": "26.6.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 773c980..b512d62 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22,8 +22,8 @@ importers: specifier: 10.0.1 version: 10.0.1(eslint@10.16.0(supports-color@7.2.0)) '@standards-lab/web-foundation': - specifier: github:standards-lab/web-foundation#v0.5.0 - version: https://codeload.github.com/standards-lab/web-foundation/tar.gz/1fc1417b783367f2e64e0a47ef3ee5f59b48aa83 + specifier: github:standards-lab/web-foundation#v0.5.1 + version: https://codeload.github.com/standards-lab/web-foundation/tar.gz/37371c7578084853cb78f71cb14380b2a65ace8d '@standards-lab/web-icons': specifier: github:standards-lab/web-icons#v0.1.0 version: https://codeload.github.com/standards-lab/web-icons/tar.gz/499927708dcf386e0cff3de7ba84a10eaf19fa1a @@ -161,9 +161,9 @@ packages: '@lit/reactive-element@2.1.2': resolution: {integrity: sha512-pbCDiVMnne1lYUIaYNN5wrwQXDtHaYtg7YEFPeW+hws6U47WeFvISGUWekPGKWOP1ygrs0ef0o1VJMk1exos5A==} - '@standards-lab/web-foundation@https://codeload.github.com/standards-lab/web-foundation/tar.gz/1fc1417b783367f2e64e0a47ef3ee5f59b48aa83': - resolution: {gitHosted: true, integrity: sha512-jEA9eVZU5pVYDkyTjX2YWLapNQo1WQTkwqoVwpUCLOZkhenDWZJ036g2KqZQpEQoSg44OoA0D58cHI/1qT1zOg==, tarball: https://codeload.github.com/standards-lab/web-foundation/tar.gz/1fc1417b783367f2e64e0a47ef3ee5f59b48aa83} - version: 0.5.0 + '@standards-lab/web-foundation@https://codeload.github.com/standards-lab/web-foundation/tar.gz/37371c7578084853cb78f71cb14380b2a65ace8d': + resolution: {gitHosted: true, integrity: sha512-VE/Qsr6rz12W2R2FAUvdWqlrkz2gO+zF7oyFqItoOl+PM1gzgkzT9pXnSaN+W/E4ffWl21pDPkvimb/CTRESwA==, tarball: https://codeload.github.com/standards-lab/web-foundation/tar.gz/37371c7578084853cb78f71cb14380b2a65ace8d} + version: 0.5.1 '@standards-lab/web-icons@https://codeload.github.com/standards-lab/web-icons/tar.gz/499927708dcf386e0cff3de7ba84a10eaf19fa1a': resolution: {gitHosted: true, integrity: sha512-oiiC6Qi9kuhp3arxvQt3zi4Y98DhRmIYGP2cA/W3TF4MyHYTWlFCGZ0wWIvmaK4NDTqsLdc5xfemPZin+ZP+dg==, tarball: https://codeload.github.com/standards-lab/web-icons/tar.gz/499927708dcf386e0cff3de7ba84a10eaf19fa1a} @@ -954,7 +954,7 @@ snapshots: dependencies: '@lit-labs/ssr-dom-shim': 1.6.0 - '@standards-lab/web-foundation@https://codeload.github.com/standards-lab/web-foundation/tar.gz/1fc1417b783367f2e64e0a47ef3ee5f59b48aa83': {} + '@standards-lab/web-foundation@https://codeload.github.com/standards-lab/web-foundation/tar.gz/37371c7578084853cb78f71cb14380b2a65ace8d': {} '@standards-lab/web-icons@https://codeload.github.com/standards-lab/web-icons/tar.gz/499927708dcf386e0cff3de7ba84a10eaf19fa1a': {} diff --git a/src/event-log.css b/src/event-log.css index ffde92f..b1f3e55 100644 --- a/src/event-log.css +++ b/src/event-log.css @@ -1,6 +1,6 @@ /* * The event log's shadow-root sheet: the utilities' scrolling frame around the bare list of events, - * each its type and time, its labelled source, subject, and id, and its data's details. + * each its type and time, its labelled source, subject, id, and extensions, and its data's details. * Unlayered, above the foundation's reset, elements, and utilities sheets; it reads only the * baseline tokens. * See docs/layout.md @@ -66,13 +66,16 @@ margin-block-start: var(--space-2xs); } } +.meta dt, +.meta dd { + max-inline-size: 100%; + min-inline-size: 0; +} .meta dt { font-family: var(--font-ui); color: var(--fg-3); } .meta dd { - max-inline-size: 100%; - min-inline-size: 0; margin: 0; font-family: var(--font-code); } diff --git a/src/event-log.ts b/src/event-log.ts index d84f909..5e9bcc4 100644 --- a/src/event-log.ts +++ b/src/event-log.ts @@ -1,7 +1,7 @@ // The event log, Lit with a shadow root: events in the order given, each its type, its time, and -// its source, subject, and id, with its data pretty-printed on demand, inside one frame that -// scrolls when its consumer constrains its block size. The event is a structural subset of -// CloudEvents 1.0, by its attribute names, so an event as a stream carries it fits as it is. It +// its source, subject, id, and extensions, with its data pretty-printed on demand, inside one +// frame that scrolls when its consumer constrains its block size. The event is a structural subset +// of CloudEvents 1.0, by its attribute names, so an event as a stream carries it fits as it is. It // knows no SDK and no domain. It is display-only: it sends no event and binds no key. // See docs/internals.md @@ -22,7 +22,8 @@ export const tagName = "sl-event-log"; * An event as the log shows it, a subset of CloudEvents 1.0 by its attribute names: its id, * unique within its source; its type; its source; the subject it is about, when it names one; * when it happened, an RFC 3339 string, as an event's JSON carries it, or a Date, absent when the - * event says not, as CloudEvents allows; and its data, a JSON value, absent when it carries none. + * event says not, as CloudEvents allows; its data, a JSON value, absent when it carries none; and + * its extension attributes, each name to its string value, absent when it carries none. */ export interface LogEvent { id: string; @@ -31,6 +32,7 @@ export interface LogEvent { subject?: string | null; time?: string | Date | null; data?: unknown; + extensions?: Readonly> | null; } const timeFormat: Intl.DateTimeFormatOptions = { dateStyle: "medium", timeStyle: "medium" }; @@ -41,6 +43,17 @@ function occurred(event: LogEvent): Date | null { return Number.isNaN(date.getTime()) ? null : date; } +function extended(event: LogEvent): [string, string][] { + const given: unknown = event.extensions; + if (typeof given !== "object" || given === null || Array.isArray(given)) return []; + return Object.entries(given as Record) + .filter( + (entry): entry is [string, string] => + entry[0] !== "" && typeof entry[1] === "string" && entry[1] !== "", + ) + .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)); +} + function pretty(data: unknown): string { if (typeof data === "string") return data; try { @@ -66,8 +79,10 @@ function atEnd(frame: HTMLElement): boolean { * by the foundation's formatDateTime, absolute and to the second, or its type alone when it has no * time or one that doesn't parse, the line holding no room for one; under them its source, subject, * and id, each labelled and each on a line of its own, a subject or an id longer than its line cut - * with an ellipsis, its whole text kept and shown in its title; and its data pretty-printed in a - * native details, collapsed until opened. An event without data says so in the details' place. + * with an ellipsis, its whole text kept and shown in its title; under the id its extensions, in + * name order, each labelled by its name, the name and the value each cut as the id is, an + * extension whose value isn't a non-empty string showing nothing; and its data pretty-printed in + * a native details, collapsed until opened. An event without data says so in the details' place. * Each event is keyed by its source and id, the pair CloudEvents makes unique, so events appended * to the list leave those shown in their own nodes and places, and a details the reader opened * stays open. @@ -109,9 +124,9 @@ export class EventLog extends LitElement { if (frame) frame.scrollTop = frame.scrollHeight; } - #pair(label: string, value: string, cut = false) { + #pair(label: string, value: string, cut = false, named = false) { return html`
-
${label}
+
${label}
${value}
`; } @@ -134,6 +149,7 @@ export class EventLog extends LitElement { ${this.#pair("source", event.source)} ${subject === undefined || subject === "" ? nothing : this.#pair("subject", subject, true)} ${this.#pair("id", event.id, true)} + ${extended(event).map(([name, value]) => this.#pair(name, value, true, true))} ${ event.data === undefined diff --git a/src/stage-timeline.css b/src/stage-timeline.css index 2a3f051..6385871 100644 --- a/src/stage-timeline.css +++ b/src/stage-timeline.css @@ -1,7 +1,8 @@ /* * The stage timeline's shadow-root sheet: the bare list of steps, each a marker, with the active * one's ring, which the motion sheet's ring runs, a connector to the next, a name, a detail line of - * the state's label and time, each on the utilities' alternatives, and a failed stage's reason. + * the state's label, time, duration, and attempt, each on the utilities' alternatives, a note, and + * a failed stage's reason. * Unlayered, above the foundation's reset, elements, utilities, and motion sheets; it reads only * the baseline tokens. * See docs/layout.md @@ -16,16 +17,16 @@ .stage { display: grid; grid-template-columns: auto minmax(0, 1fr); - grid-template-rows: auto auto auto var(--space-s); + grid-template-rows: auto auto auto auto var(--space-s); column-gap: var(--space-xs); } .stage:last-child { - grid-template-rows: auto auto auto; + grid-template-rows: auto auto auto auto; } .stage:not(:last-child)::after { content: ""; grid-column: 1; - grid-row: 2 / 5; + grid-row: 2 / 6; justify-self: center; inline-size: var(--line-m); margin-block: var(--space-3xs); @@ -117,9 +118,15 @@ .failed .label { color: var(--red); } +.note, .reason { grid-column: 2; - grid-row: 3; contain: inline-size; overflow-wrap: anywhere; } +.note { + grid-row: 3; +} +.reason { + grid-row: 4; +} diff --git a/src/stage-timeline.ts b/src/stage-timeline.ts index 93442ed..aaaa13e 100644 --- a/src/stage-timeline.ts +++ b/src/stage-timeline.ts @@ -1,7 +1,9 @@ // The stage timeline, Lit with a shadow root: a run's stages as a connected, ordered list of steps, -// each its name, its state in words and by its marker, and when it completed or failed, a failed -// stage with why. It knows no SDK and no domain: the app maps its run's stages onto the shape -// below. It is display-only: it sends no event, holds nothing focusable, and binds no key. +// each its name, its state in words and by its marker, when it completed or failed, how long it +// took or, while active, has taken, its attempt past the first, a note, and a failed stage with +// why. It knows no SDK and no domain: the app maps its run's stages onto the shape below. It is +// display-only: it sends no event, holds nothing focusable, and binds no key. It runs one +// one-second timer, only while connected and an active stage has a valid start. // See docs/internals.md import { html, LitElement, nothing, svg, type PropertyDeclarations } from "lit"; @@ -12,7 +14,11 @@ import reset from "@standards-lab/web-foundation/baseline/reset.css" with { type import motion from "@standards-lab/web-foundation/motion.css" with { type: "css" }; import utilities from "@standards-lab/web-foundation/utilities.css" with { type: "css" }; import { define } from "@standards-lab/web-foundation/dom.js"; -import { formatDateTime } from "@standards-lab/web-foundation/format.js"; +import { + formatDateTime, + formatDuration, + type DurationOptions, +} from "@standards-lab/web-foundation/format.js"; import styles from "./stage-timeline.css" with { type: "css" }; /** The tag the element defines. */ @@ -28,14 +34,21 @@ export type StageState = "pending" | "active" | "complete" | "failed"; * shows no time. A time is named for what it marks, as a run's stage names its own, so a stage * maps field for field: a failed stage shows `failedAt`, or `completedAt` when it has none, the * slot a failure's time took before `failedAt`; every other state shows `completedAt`. `reason` - * shows only with a failed stage, and an empty one shows nothing. + * shows only with a failed stage, and an empty one shows nothing. `startedAt`, a time as the others + * are, gives a complete or failed stage its duration, from it to the stage's shown time, and an + * active stage the time elapsed since it; a start that doesn't parse, or that comes after the + * stage's end, shows no duration. `attempt`, a positive integer, shows above 1; any other value is + * ignored. `note` shows with every state, and an empty one shows nothing. */ export interface TimelineStage { name: string; position: number; state: StageState; + startedAt?: string | Date | null; completedAt?: string | Date | null; failedAt?: string | Date | null; + attempt?: number | null; + note?: string | null; reason?: string | null; } @@ -50,27 +63,63 @@ const timeFormat: Intl.DateTimeFormatOptions = { dateStyle: "medium", timeStyle: const widest = new Date(2026, 4, 28, 22, 58, 58); +const durationFormat: DurationOptions = { style: "digital" }; + +const longest = 86_399_000; + +const attemptHeld = 99; + const check = svg``; const cross = svg``; -function timeOf(stage: TimelineStage): Date | null { - const at = stage.state === "failed" ? (stage.failedAt ?? stage.completedAt) : stage.completedAt; +function parse(at: string | Date | null | undefined): Date | null { if (at === undefined || at === null) return null; const date = new Date(at); return Number.isNaN(date.getTime()) ? null : date; } +function timeOf(stage: TimelineStage): Date | null { + return parse( + stage.state === "failed" ? (stage.failedAt ?? stage.completedAt) : stage.completedAt, + ); +} + +function startOf(stage: TimelineStage): Date | null { + return stage.state === "pending" ? null : parse(stage.startedAt); +} + +function durationOf(stage: TimelineStage, end: Date | null, now: number): number | null { + const start = startOf(stage); + if (start === null) return null; + if (stage.state === "active") return Math.max(0, now - start.getTime()); + if (end === null || end < start) return null; + return end.getTime() - start.getTime(); +} + +function attemptOf(stage: TimelineStage): number | null { + const { attempt } = stage; + return typeof attempt === "number" && Number.isInteger(attempt) && attempt > 1 ? attempt : null; +} + +function textOf(text: string | null | undefined): string | null { + return typeof text === "string" && text.trim() !== "" ? text : null; +} + /** * A run's stages as an ordered list of steps, connected top to bottom, in their positions' order. * Each step shows its name; under it, its state's label and its time, a complete stage's * completion or a failed one's failure, formatted by the foundation's formatDateTime; under that, a * failed stage's reason, when it has one; and before it a marker, its position for a pending or - * active stage, a check for a complete one, a cross for a failed one. The reason is the step's own - * text, in its list item, so assistive technology reads it with the stage's name, label, and time. - * The active stage is the list's current step. A stage that advances changes in place: its label - * and its time each have a slot as wide as the widest they hold, so nothing moves as a state - * changes; a failure's reason, the one line a state adds, adds it below the step's detail line, - * wrapping to the timeline's width and never widening it. + * active stage, a check for a complete one, a cross for a failed one. The detail line also shows + * the stage's duration, by the foundation's formatDuration in its digital style, ticking each + * second while the stage is active, and "Attempt n" past the first attempt. A note shows on its + * own row under the detail line, above a failed stage's reason. The note and reason are the step's + * own text, in its list item, so assistive technology reads them with the stage's name, label, and + * time. The active stage is the list's current step. A stage that advances or ticks changes in + * place: its label, time, duration, and attempt each have a slot as wide as the widest they hold + * (a duration under a day, an attempt under 100), so nothing moves as a state changes or a clock + * ticks; a note and a failure's reason, the lines a stage adds, add them below the step's detail + * line, wrapping to the timeline's width and never widening it. */ export class StageTimeline extends LitElement { static styles = [reset, elements, utilities, motion, styles]; @@ -82,11 +131,41 @@ export class StageTimeline extends LitElement { /** The stages to show; the timeline orders them by position. */ declare stages: readonly TimelineStage[]; + #timer: ReturnType | null = null; + constructor() { super(); this.stages = []; } + override connectedCallback() { + super.connectedCallback(); + this.#schedule(); + } + + override disconnectedCallback() { + super.disconnectedCallback(); + this.#stop(); + } + + protected override updated() { + this.#schedule(); + } + + #schedule() { + const ticking = + this.isConnected && + (this.stages ?? []).some((stage) => stage.state === "active" && startOf(stage) !== null); + if (!ticking) this.#stop(); + else this.#timer ??= setInterval(() => this.requestUpdate(), 1000); + } + + #stop() { + if (this.#timer === null) return; + clearInterval(this.#timer); + this.#timer = null; + } + #marker(stage: TimelineStage) { const glyph = stage.state === "complete" ? check : stage.state === "failed" ? cross : nothing; return html`