Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/guides/develop-a-renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ what broke and where), or skipped:
reserved: a rule may recolor it (its border color and opacity), but anything
drawn there instead loses to the kit's or moves the edge, and the check fails
it. Draw a badge or label in an element of its own.
- **Labels centred on their capitals** — A chip, bar or button's text has as
much room above its capitals as below its baseline. Centring a line box leaves
it a little high or low, by how the font's ascent, descent and cap height
compare, and differently in each engine. Put the text in an element of its own
with the kit's `pk-label` class: a block or flex item, in the text's own font.
It trims the text's box to its capitals and baseline and pads it back to its
line height, so whatever centres it centres the capitals. Extra room goes in
`--pk-label-inset`.
- **Legend shown once** — Render at most one legend, and omit it altogether when
the host already draws one.
- **No horizontal overflow at phone width** — The page must never scroll
Expand Down
8 changes: 8 additions & 0 deletions docs/guides/renderer-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ the badges stay on the same line without wrapping or clipping. For mixed labels
such as `GET /api/cart` or `Inter.woff2 (preloaded)`, `IdentifierText` renders
only the detected code spans (`identifierParts`) in monospace.

**Labels centred on their capitals.** A line box sets text a little high or low
of its capitals, differently in each engine. Put a chip, bar or button's text in
its own `pk-label` (a block or flex item, in the text's own font): it trims the
box to the capitals and baseline (`text-box`) and pads it back to its line
height, so whatever centres it centres the capitals. Extra room goes in
`--pk-label-inset`; the `label-centring` renderer check holds every chip, bar
and button to it.

Protocol text that already marks code spans in backticks—reasons, summaries,
notices, diagnostics, and details (see
[text with inline code](../contracts.md#text-with-inline-code))—should be
Expand Down
5 changes: 3 additions & 2 deletions docs/reference/renderer-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -4755,13 +4755,14 @@ and set it. Spread them: `<DataTable {...useTableProps(props)} label columns row
### `ValueChange`

```ts
ValueChange(__0: { "after"?: Iterable<ReactNode, any, any> | Promise<Iterable<ReactNode, any, any> | ReactElement<unknown, string | { (props: any): Iterable<ReactNode, any, any> | Promise | Promise<ReactNode> | ReactElement<unknown, recursive> | ReactPortal | bigint | false | null | number | string | true | undefined } | { new (props: any, context: any): Component<any, any, any> }> | ReactPortal | bigint | false | null | number | string | true | undefined> | ReactElement<unknown, string | { (props: any): Iterable<ReactNode, any, any> | Promise<Iterable<ReactNode, any, any> | ReactElement<unknown, recursive> | ReactPortal | bigint | false | null | number | string | true | undefined> | Promise<ReactNode> | ReactElement | ReactPortal | bigint | false | null | number | string | true | undefined } | { new (props: any, context: any): Component<any, any, any> }> | ReactPortal | bigint | false | null | number | string | true | undefined; "before"?: Iterable<ReactNode, any, any> | Promise<Iterable<ReactNode, any, any> | ReactElement<unknown, string | { (props: any): Iterable<ReactNode, any, any> | Promise | Promise<ReactNode> | ReactElement<unknown, recursive> | ReactPortal | bigint | false | null | number | string | true | undefined } | { new (props: any, context: any): Component<any, any, any> }> | ReactPortal | bigint | false | null | number | string | true | undefined> | ReactElement<unknown, string | { (props: any): Iterable<ReactNode, any, any> | Promise<Iterable<ReactNode, any, any> | ReactElement<unknown, recursive> | ReactPortal | bigint | false | null | number | string | true | undefined> | Promise<ReactNode> | ReactElement | ReactPortal | bigint | false | null | number | string | true | undefined } | { new (props: any, context: any): Component<any, any, any> }> | ReactPortal | bigint | false | null | number | string | true | undefined; "className"?: string; "layout"?: "inline" | "stacked" }): Element
ValueChange(__0: { "after"?: Iterable<ReactNode, any, any> | Promise<Iterable<ReactNode, any, any> | ReactElement<unknown, string | { (props: any): Iterable<ReactNode, any, any> | Promise | Promise<ReactNode> | ReactElement<unknown, recursive> | ReactPortal | bigint | false | null | number | string | true | undefined } | { new (props: any, context: any): Component<any, any, any> }> | ReactPortal | bigint | false | null | number | string | true | undefined> | ReactElement<unknown, string | { (props: any): Iterable<ReactNode, any, any> | Promise<Iterable<ReactNode, any, any> | ReactElement<unknown, recursive> | ReactPortal | bigint | false | null | number | string | true | undefined> | Promise<ReactNode> | ReactElement | ReactPortal | bigint | false | null | number | string | true | undefined } | { new (props: any, context: any): Component<any, any, any> }> | ReactPortal | bigint | false | null | number | string | true | undefined; "before"?: Iterable<ReactNode, any, any> | Promise<Iterable<ReactNode, any, any> | ReactElement<unknown, string | { (props: any): Iterable<ReactNode, any, any> | Promise | Promise<ReactNode> | ReactElement<unknown, recursive> | ReactPortal | bigint | false | null | number | string | true | undefined } | { new (props: any, context: any): Component<any, any, any> }> | ReactPortal | bigint | false | null | number | string | true | undefined> | ReactElement<unknown, string | { (props: any): Iterable<ReactNode, any, any> | Promise<Iterable<ReactNode, any, any> | ReactElement<unknown, recursive> | ReactPortal | bigint | false | null | number | string | true | undefined> | Promise<ReactNode> | ReactElement | ReactPortal | bigint | false | null | number | string | true | undefined } | { new (props: any, context: any): Component<any, any, any> }> | ReactPortal | bigint | false | null | number | string | true | undefined; "className"?: string; "code"?: false | true; "layout"?: "inline" | "stacked" }): Element
```

A value that changed: the old one struck through in a removed pill, then
the new one in an added pill, stacked (the default) or on one line with an
arrow. Assistive technology reads "was …, now …". A missing side shows
only the other pill.
only the other pill. `code` marks the values as identifiers (a type, a
version), in the monospace font.

### `VariedMarker`

Expand Down
4 changes: 3 additions & 1 deletion packages/renderers/agentic-workflows/src/matrix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ function Row({item, view, frame}: {item: WorkflowItem; view: AgenticModel; frame
const value = cell(item, category, column, frame)
return (
<td key={`${category.section}:${column.key}`} className="aw-matrix-cell" data-cell={value}>
<span aria-hidden="true">{glyphs[value]}</span>
<span className="aw-matrix-glyph" aria-hidden="true">
<span className="pk-label">{glyphs[value]}</span>
</span>
<span className="sr-only">{words[value]}</span>
</td>
)
Expand Down
23 changes: 20 additions & 3 deletions packages/renderers/agentic-workflows/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@
}
.aw-lock {
display: inline-flex;
align-items: center;
align-items: baseline;
gap: var(--projections-space-1);
}
/* The icon is centred on the line, and the words give the lock its baseline, so it sits on the line around it. */
.aw-lock > .pk-icon {
align-self: center;
}
.aw-lock:not([data-lock='current']) {
color: var(--text);
font-weight: var(--projections-font-weight-semibold);
Expand Down Expand Up @@ -206,8 +210,11 @@
width: 100%;
}
/* Every body row is one fixed line high, whatever its status shows, so emphasis never moves a row. */
.aw-matrix {
--aw-row-height: 1.5rem;
}
.aw-matrix tbody tr {
height: 1.5rem;
height: var(--aw-row-height);
}
.aw-matrix tbody :is(th, td) {
padding-block: 0;
Expand All @@ -219,7 +226,7 @@
.aw-matrix .aw-matrix-status > .pk-change-status {
display: flex;
align-items: center;
height: 1.5rem;
height: var(--aw-row-height);
overflow: hidden;
}
.aw-matrix-select {
Expand All @@ -235,6 +242,16 @@
font-family: var(--font-mono);
font-weight: var(--projections-font-weight-semibold);
}
/*
* The row's height, centring its mark (a `pk-label`, trimmed to its capitals) exactly: a table cell centres its content
* to whole pixels, which leaves an odd pixel's room under it.
*/
.aw-matrix-glyph {
display: flex;
align-items: center;
justify-content: center;
height: var(--aw-row-height);
}
.aw-matrix-cell[data-cell='present'] {
color: var(--muted);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/renderers/api/browser/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function rows(root: Locator) {
id: row.dataset.entityId!,
status: [...row.querySelectorAll('.api-declaration-footer .pk-status-part')].map(part => part.textContent),
lines: [...row.querySelectorAll<HTMLElement>('pre')].map(
pre => `${pre.className.replace('api-signature', '').trim() || 'plain'}:${pre.textContent.replace(/^[−+]/u, '')}`,
pre =>
`${pre.className.replace('api-signature', '').replace('pk-label', '').trim() || 'plain'}:${pre.textContent.replace(/^[−+]/u, '')}`,
),
runs: [...row.querySelectorAll('del, ins, mark')].map(run => `${run.localName}:${run.textContent}`),
})),
Expand Down
4 changes: 2 additions & 2 deletions packages/renderers/api/src/signature-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const toneMarks: Record<Tone, string> = {added: '+', removed: '−'}
/** One signature line; a toned line carries a `+` or `−` marker in its gutter. */
function Line({tone, children}: {tone?: Tone | undefined; children: ReactNode}) {
return (
<pre className={`api-signature${tone ? ` ${tone}` : ''}`} {...identifier}>
<pre className={`api-signature pk-label${tone ? ` ${tone}` : ''}`} {...identifier}>
{tone && (
<span className="api-line-mark" aria-hidden="true">
<span className="api-line-mark pk-label" aria-hidden="true">
{toneMarks[tone]}
</span>
)}
Expand Down
8 changes: 8 additions & 0 deletions packages/renderers/api/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
position: relative;
margin: 0;
padding: calc(var(--projections-space-1) / 2) var(--projections-space-2) calc(var(--projections-space-1) / 2) var(--projections-space-5);
/* Its text is a label (`pk-label`), centred on its capitals inside this inset. */
--pk-label-inset: calc(var(--projections-space-1) / 2);
font-size: var(--projections-font-size-xs);
white-space: pre-wrap;
overflow-wrap: anywhere;
Expand All @@ -128,6 +130,12 @@
color: var(--muted);
user-select: none;
}
/* On the first line, wherever a browser trims text: a label (`pk-label`) at the top, padded as the signature's text is. */
@supports (text-box: trim-both cap alphabetic) {
.api-line-mark {
top: 0;
}
}
.api-signature :is(mark, del, ins) {
color: inherit;
border-radius: var(--projections-radius-sm);
Expand Down
21 changes: 12 additions & 9 deletions packages/renderers/api/test/api.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,28 @@ test('the diff renders every change with its status footer and signature diff, a
assert.equal(statusOf(rows.added), 'Added')
assert.match(
rows.added,
/class="api-signature added" data-projections-identifier=""><span class="api-line-mark" aria-hidden="true">\+<\/span>added\(\): void/u,
/class="api-signature pk-label added" data-projections-identifier=""><span class="api-line-mark pk-label" aria-hidden="true">\+<\/span>added\(\): void/u,
)
assert.equal(statusOf(rows.legacy), 'Removed')
assert.match(
rows.legacy,
/class="api-signature removed" data-projections-identifier=""><span class="api-line-mark" aria-hidden="true">−<\/span>legacy\(\): void/u,
/class="api-signature pk-label removed" data-projections-identifier=""><span class="api-line-mark pk-label" aria-hidden="true">−<\/span>legacy\(\): void/u,
)
assert.equal(statusOf(rows.greet), 'Modified')
assert.match(
rows.greet,
/<pre class="api-signature" data-projections-identifier=""><span>greet\(<\/span><ins>name: string<\/ins><span>\): string<\/span><\/pre>/u,
/<pre class="api-signature pk-label" data-projections-identifier=""><span>greet\(<\/span><ins>name: string<\/ins><span>\): string<\/span><\/pre>/u,
)
assert.match(rows.greet, /Signature changed from “greet\(\): string” to “greet\(name: string\): string”/u)
// A rewritten signature splits into a removed line above an added one.
assert.match(
rows.parse,
/class="api-signature removed" data-projections-identifier="">.*>parse\(text: string\): Node<\/pre><pre class="api-signature added" data-projections-identifier="">.*>tokenize\(input: Buffer\): Token\[\]<\/pre>/u,
/class="api-signature pk-label removed" data-projections-identifier="">.*>parse\(text: string\): Node<\/pre><pre class="api-signature pk-label added" data-projections-identifier="">.*>tokenize\(input: Buffer\): Token\[\]<\/pre>/u,
)
assert.ok(!rows.stable.includes('pk-status') && !rows.stable.includes('<del') && !rows.stable.includes('<ins'))
// The unchanged row still reserves its footer, so every row has the same rhythm.
assert.ok(rows.stable.endsWith(footer))
assert.match(rows.stable, /<pre class="api-signature" data-projections-identifier="">stable\(\): void<\/pre>/u)
assert.match(rows.stable, /<pre class="api-signature pk-label" data-projections-identifier="">stable\(\): void<\/pre>/u)
})

test('a renamed declaration shows its previous label and its renamed signature', async () => {
Expand Down Expand Up @@ -268,10 +268,13 @@ test('side-by-side panes list each revision; with highlighting each marks its si
assert.ok(!('added' in start) && !('legacy' in end))
assert.equal(statusOf(start.legacy), 'Removed')
assert.equal(statusOf(end.added), 'Added')
assert.match(start.legacy, /class="api-signature removed"/u)
assert.match(end.added, /class="api-signature added"/u)
assert.match(start.greet, /class="api-signature removed" data-projections-identifier="">.*<span>greet\(<\/span><span>\): string<\/span>/u)
assert.match(end.greet, /class="api-signature added" data-projections-identifier="">.*<mark>name: string<\/mark>/u)
assert.match(start.legacy, /class="api-signature pk-label removed"/u)
assert.match(end.added, /class="api-signature pk-label added"/u)
assert.match(
start.greet,
/class="api-signature pk-label removed" data-projections-identifier="">.*<span>greet\(<\/span><span>\): string<\/span>/u,
)
assert.match(end.greet, /class="api-signature pk-label added" data-projections-identifier="">.*<mark>name: string<\/mark>/u)
assert.ok(!start.parse.includes('<mark'), 'a rewrite is not marked run by run')
assert.ok(!start.stable.includes('pk-status') && !end.stable.includes('<mark'))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ test('endpoints are neutral and the midpoint interpolates every count', async ()
// Every row reserves its status cell; changed languages state their status as icon and word.
const rows = [...mid.matchAll(/class="stat-row/gu)].length
assert.equal([...mid.matchAll(/class="pk-change-status stat-status"/gu)].length, rows)
assert.match(mid, /data-change-status="modified"><span class="pk-icon" data-icon="modified" aria-hidden="true"><\/span>Modified/u)
assert.match(
mid,
/data-change-status="modified"><span class="pk-icon" data-icon="modified" aria-hidden="true"><\/span><span class="pk-label">Modified<\/span>/u,
)
assert.match(mid, /aria-label="Inspect TypeScript, 1,200 lines of code, \+400, Modified"/u)
const legend = await render('mid', 1, {controls: {chart: 'share'}})
assert.equal(
Expand Down
10 changes: 3 additions & 7 deletions packages/renderers/database/src/row-parts.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Entity} from '@githubnext/projections-schemas'
import {identifier, type EntityChange} from '@githubnext/projections-renderer-sdk/presentation'
import type {EntityChange} from '@githubnext/projections-renderer-sdk/presentation'
import {describeChange, statusParts} from '@githubnext/projections-renderer-kit'
import {Icon, ValueChange} from '@githubnext/projections-renderer-kit/react'
import {Breakable} from './measure.js'
Expand Down Expand Up @@ -66,17 +66,13 @@ export function ChangeLines({
return lines.map((line, index) => {
const shown = line.after !== undefined && shows(line.after)
const fits = oneLine(slots[index] ?? 0)
const value = (text: string | undefined) =>
text === undefined ? undefined : (
<span {...identifier}>
<Breakable lines={wrap('type', text, fits, 'pill')} />
</span>
)
const value = (text: string | undefined) => (text === undefined ? undefined : <Breakable lines={wrap('type', text, fits, 'pill')} />)
return (
<span key={line.key} className={`database-slot database-change-line${fits ? '' : ' wrapped'}`}>
<span className="database-change-word">{line.word}</span>
{(line.before !== undefined || line.after !== undefined) && (
<ValueChange
code
layout={fits ? 'inline' : 'stacked'}
before={value(line.before)}
after={shown ? undefined : value(line.after)}
Expand Down
11 changes: 10 additions & 1 deletion packages/renderers/database/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@
line-height: 18px;
overflow-wrap: anywhere;
}
/* The names, types and keys and a pill's value are trimmed to their capitals (`pk-label`), which needs a block. */
.database-name,
.database-rowtext .entity-link > .pk-label,
.database-key > .pk-label,
.pk .database-change-values .pk-change-pill > .pk-label {
display: block;
}
/* Too narrow for the name beside its kind and status: the name takes the first lines, the kind and status the last. */
.database-table header.wrapped {
flex-wrap: wrap;
Expand Down Expand Up @@ -118,7 +125,9 @@
height: 32px;
display: flex;
align-items: flex-start;
padding: 8px var(--projections-space-3) 8px var(--projections-space-2);
/* Lines centred in the room under the row's top rule: the rule takes a pixel of its 32. */
padding: calc(8px - var(--projections-border-width) / 2) var(--projections-space-3) calc(8px - var(--projections-border-width) / 2)
var(--projections-space-2);
line-height: 16px;
gap: var(--projections-space-2);
border-top: var(--projections-border-width) solid var(--border);
Expand Down
Loading
Loading