basalt-ui 2.28.0 → 2.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +461 -401
- package/MIGRATING.md +202 -12
- package/agent/skills/basalt-app/SKILL.md +3 -3
- package/agent/skills/basalt-charts/SKILL.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +11 -5
- package/agent/skills/basalt-design/references/catalogue.md +3 -1
- package/agent/skills/basalt-design/references/recipes.md +1 -1
- package/agent/skills/basalt-design/references/states.md +1 -1
- package/configs/oxlint-plugin.js +2 -1
- package/configs/oxlint.json +1 -0
- package/dist/charts/ChartCard.d.ts +9 -5
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +68 -12
- package/dist/charts/Sparkline.d.ts +5 -0
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +53 -5
- package/dist/charts/chart-box.module.css +9 -2
- package/dist/charts/chart-card.module.css +16 -13
- package/dist/charts/chart-card.module.css.d.ts +2 -0
- package/dist/charts/compile.d.ts +1 -1
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +18 -9
- package/dist/charts/ref-label.d.ts +6 -0
- package/dist/charts/ref-label.d.ts.map +1 -1
- package/dist/charts/ref-label.js +19 -5
- package/dist/charts/sparkline.module.css +44 -0
- package/dist/charts/sparkline.module.css.d.ts +3 -0
- package/dist/charts/state.d.ts +1 -1
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +3 -3
- package/dist/cli/doctor-upgrade.d.ts +11 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +54 -0
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +32 -0
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +8 -3
- package/dist/cli/index.d.ts +13 -13
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +36 -2
- package/dist/cli/init.d.ts +6 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +118 -27
- package/dist/cli/router-wiring.d.ts +3 -0
- package/dist/cli/router-wiring.d.ts.map +1 -1
- package/dist/cli/router-wiring.js +2 -0
- package/dist/cli/shot/capture.d.ts +28 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +77 -7
- package/dist/cli/shot/detect.d.ts +4 -1
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +38 -16
- package/dist/cli/shot/index.d.ts.map +1 -1
- package/dist/cli/shot/index.js +9 -2
- package/dist/cli/shot/measure.d.ts.map +1 -1
- package/dist/cli/shot/measure.js +11 -2
- package/dist/cli/shot/types.d.ts +4 -1
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +10 -2
- package/dist/common/could-not-load.d.ts +13 -0
- package/dist/common/could-not-load.d.ts.map +1 -0
- package/dist/common/could-not-load.js +14 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +3 -0
- package/dist/common/props.d.ts +20 -0
- package/dist/common/props.d.ts.map +1 -1
- package/dist/common/props.js +13 -1
- package/dist/common/retry-button.module.css +7 -3
- package/dist/dashboard/bar-list.d.ts +4 -4
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +10 -7
- package/dist/dashboard/bar-list.module.css +21 -3
- package/dist/dashboard/board.d.ts +2 -2
- package/dist/dashboard/board.d.ts.map +1 -1
- package/dist/dashboard/board.js +31 -12
- package/dist/dashboard/board.module.css +19 -0
- package/dist/dashboard/board.module.css.d.ts +2 -0
- package/dist/dashboard/empty-state.d.ts +3 -3
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/empty-state.js +4 -2
- package/dist/dashboard/event-list-model.d.ts +3 -0
- package/dist/dashboard/event-list-model.d.ts.map +1 -1
- package/dist/dashboard/event-list-model.js +5 -1
- package/dist/dashboard/event-list-rows.d.ts.map +1 -1
- package/dist/dashboard/event-list-rows.js +2 -6
- package/dist/dashboard/event-list-scroll.d.ts +32 -4
- package/dist/dashboard/event-list-scroll.d.ts.map +1 -1
- package/dist/dashboard/event-list-scroll.js +117 -4
- package/dist/dashboard/event-list-skeleton.d.ts.map +1 -1
- package/dist/dashboard/event-list-skeleton.js +2 -4
- package/dist/dashboard/event-list.d.ts +4 -4
- package/dist/dashboard/event-list.d.ts.map +1 -1
- package/dist/dashboard/event-list.js +53 -23
- package/dist/dashboard/event-list.module.css +90 -37
- package/dist/dashboard/event-list.module.css.d.ts +1 -0
- package/dist/dashboard/meter-model.d.ts +6 -3
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +9 -4
- package/dist/dashboard/meter-parts.d.ts +3 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +32 -4
- package/dist/dashboard/meter.d.ts +3 -3
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +10 -2
- package/dist/dashboard/meter.module.css +18 -11
- package/dist/dashboard/meter.module.css.d.ts +0 -1
- package/dist/dashboard/page-summary.d.ts +3 -3
- package/dist/dashboard/page-summary.d.ts.map +1 -1
- package/dist/dashboard/page-summary.js +7 -2
- package/dist/dashboard/page-summary.module.css +5 -2
- package/dist/dashboard/query-state.d.ts +9 -8
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +28 -10
- package/dist/dashboard/section.d.ts +11 -3
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +34 -7
- package/dist/dashboard/settings-section.d.ts +4 -4
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +11 -7
- package/dist/dashboard/settings-section.module.css +6 -0
- package/dist/dashboard/settings-section.module.css.d.ts +1 -0
- package/dist/dashboard/stat-card.d.ts +3 -3
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +24 -8
- package/dist/dashboard/stat-card.module.css +11 -0
- package/dist/dashboard/stat-group.d.ts +2 -2
- package/dist/dashboard/stat-group.d.ts.map +1 -1
- package/dist/dashboard/stat-group.js +10 -3
- package/dist/dashboard/stat-strip.d.ts +5 -4
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +41 -31
- package/dist/dashboard/stat-strip.module.css +4 -5
- package/dist/dashboard/visual-slot.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts.map +1 -1
- package/dist/dashboard/visual-slot.js +2 -0
- package/dist/dashboard/widget-header.d.ts +6 -6
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +4 -2
- package/dist/dashboard/widget-header.module.css +6 -25
- package/dist/format/shared.d.ts.map +1 -1
- package/dist/format/shared.js +24 -1
- package/dist/guard/index.d.ts +1 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -1
- package/dist/styles.css +23 -0
- package/dist/table/cell-kinds.d.ts +10 -7
- package/dist/table/cell-kinds.d.ts.map +1 -1
- package/dist/table/cell-kinds.js +18 -7
- package/dist/table/data-table-fold.d.ts +13 -5
- package/dist/table/data-table-fold.d.ts.map +1 -1
- package/dist/table/data-table-fold.js +48 -16
- package/dist/table/data-table.d.ts +2 -2
- package/dist/table/data-table.d.ts.map +1 -1
- package/dist/table/data-table.js +16 -9
- package/dist/table/data-table.module.css +74 -2
- package/dist/table/data-table.module.css.d.ts +4 -0
- package/dist/theme/controls.module.css +23 -2
- package/llms.txt +263 -2
- package/package.json +1 -1
- package/src/charts/ChartCard.tsx +98 -16
- package/src/charts/Sparkline.tsx +84 -5
- package/src/charts/chart-box.module.css +9 -2
- package/src/charts/chart-card.module.css +16 -13
- package/src/charts/chart-card.module.css.d.ts +2 -0
- package/src/charts/compile.ts +37 -15
- package/src/charts/ref-label.ts +36 -9
- package/src/charts/sparkline.module.css +44 -0
- package/src/charts/sparkline.module.css.d.ts +3 -0
- package/src/charts/state.tsx +4 -3
- package/src/cli/doctor-upgrade.ts +75 -0
- package/src/cli/doctor.ts +36 -0
- package/src/cli/help.ts +16 -6
- package/src/cli/index.ts +73 -67
- package/src/cli/init.ts +157 -36
- package/src/cli/router-wiring.ts +2 -2
- package/src/cli/shot/capture.ts +109 -10
- package/src/cli/shot/detect.ts +46 -22
- package/src/cli/shot/index.ts +8 -2
- package/src/cli/shot/measure.ts +11 -2
- package/src/cli/shot/types.ts +4 -1
- package/src/cli/sync.ts +12 -2
- package/src/common/could-not-load.ts +22 -0
- package/src/common/index.ts +1 -0
- package/src/common/props.ts +30 -0
- package/src/common/retry-button.module.css +7 -3
- package/src/dashboard/bar-list.module.css +21 -3
- package/src/dashboard/bar-list.tsx +46 -41
- package/src/dashboard/board.module.css +19 -0
- package/src/dashboard/board.module.css.d.ts +2 -0
- package/src/dashboard/board.tsx +69 -48
- package/src/dashboard/empty-state.tsx +5 -2
- package/src/dashboard/event-list-model.ts +13 -1
- package/src/dashboard/event-list-rows.tsx +3 -6
- package/src/dashboard/event-list-scroll.ts +154 -8
- package/src/dashboard/event-list-skeleton.tsx +5 -1
- package/src/dashboard/event-list.module.css +90 -37
- package/src/dashboard/event-list.module.css.d.ts +1 -0
- package/src/dashboard/event-list.tsx +92 -65
- package/src/dashboard/meter-model.ts +16 -7
- package/src/dashboard/meter-parts.tsx +45 -13
- package/src/dashboard/meter.module.css +18 -11
- package/src/dashboard/meter.module.css.d.ts +0 -1
- package/src/dashboard/meter.tsx +36 -18
- package/src/dashboard/page-summary.module.css +5 -2
- package/src/dashboard/page-summary.tsx +13 -6
- package/src/dashboard/query-state.tsx +54 -29
- package/src/dashboard/section.tsx +83 -41
- package/src/dashboard/settings-section.module.css +6 -0
- package/src/dashboard/settings-section.module.css.d.ts +1 -0
- package/src/dashboard/settings-section.tsx +11 -6
- package/src/dashboard/stat-card.module.css +11 -0
- package/src/dashboard/stat-card.tsx +31 -8
- package/src/dashboard/stat-group.tsx +22 -14
- package/src/dashboard/stat-strip.module.css +4 -5
- package/src/dashboard/stat-strip.tsx +29 -20
- package/src/dashboard/visual-slot.ts +5 -0
- package/src/dashboard/widget-header.module.css +6 -25
- package/src/dashboard/widget-header.tsx +8 -5
- package/src/format/shared.ts +30 -1
- package/src/guard/index.ts +5 -1
- package/src/styles.css +23 -0
- package/src/table/cell-kinds.tsx +42 -13
- package/src/table/data-table-fold.tsx +65 -12
- package/src/table/data-table.module.css +74 -2
- package/src/table/data-table.module.css.d.ts +4 -0
- package/src/table/data-table.tsx +34 -13
- package/src/theme/controls.module.css +23 -2
package/src/cli/router-wiring.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { hasDependency, readIfExists, tokenize } from './source-text'
|
|
|
10
10
|
/** Relative-import hops (static or dynamic) `callsIn` follows from the entry; a router often lives in a singleton module. */
|
|
11
11
|
const IMPORT_DEPTH = 3
|
|
12
12
|
|
|
13
|
-
const VITE_CONFIGS = ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs'].map((e) => `vite.config.${e}`)
|
|
13
|
+
export const VITE_CONFIGS = ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs'].map((e) => `vite.config.${e}`)
|
|
14
14
|
/** The first local `<script type="module" src>` in index.html (comments and remote src skipped). */
|
|
15
15
|
function htmlEntry(html: string): string | undefined {
|
|
16
16
|
for (const [, attrs = ''] of html
|
|
@@ -29,7 +29,7 @@ function htmlEntry(html: string): string | undefined {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** True when `src` calls a binding imported from `@tanstack/router-plugin` after its `plugins` key (a textual proxy for "inside the array"). */
|
|
32
|
-
function registersRouterPlugin(src: string): boolean {
|
|
32
|
+
export function registersRouterPlugin(src: string): boolean {
|
|
33
33
|
const { code, inLiteral } = tokenize(src)
|
|
34
34
|
const pluginsAt = [...code.matchAll(/\bplugins\b/g)].find((m) => !inLiteral(m.index))?.index
|
|
35
35
|
if (pluginsAt === undefined) return false
|
package/src/cli/shot/capture.ts
CHANGED
|
@@ -40,6 +40,8 @@ const TAB_PRESSES = 80
|
|
|
40
40
|
const FOCUS_MARGIN_PX = 8
|
|
41
41
|
const TIP_PROBE_MS = 250
|
|
42
42
|
const TIP_SETTLE_MS = 60
|
|
43
|
+
/** How long a previous anchor's tooltip gets to unmount before the next hover. */
|
|
44
|
+
const TIP_CLEAR_MS = 1_000
|
|
43
45
|
const TIP_SETTLE_READS = 10
|
|
44
46
|
|
|
45
47
|
export type CaptureInput = {
|
|
@@ -64,10 +66,14 @@ export type CaptureInput = {
|
|
|
64
66
|
type PageFacts = {
|
|
65
67
|
anchors: string[]
|
|
66
68
|
declared: string[]
|
|
69
|
+
/** Anchors that carry `data-shot-states` themselves (on, inside or above the anchor element). Absent in a hand-built fact: the page's `declared` stands for every anchor. */
|
|
70
|
+
declaring?: string[]
|
|
67
71
|
/** Anchors that hold a basalt state surface (ChartCard, StatCard, a chart state). */
|
|
68
72
|
stateful?: string[]
|
|
69
73
|
/** Anchor → the URL states it declares itself absent in (`data-shot-absent="empty error"`). */
|
|
70
74
|
absent?: Record<string, string[]>
|
|
75
|
+
/** The page's visible text, to tell whether every route rendered the same thing. */
|
|
76
|
+
content?: string
|
|
71
77
|
}
|
|
72
78
|
|
|
73
79
|
/** Everything one page visit shares: where the records go and what was already measured. */
|
|
@@ -85,6 +91,7 @@ type Ctx = {
|
|
|
85
91
|
measured: Set<string>
|
|
86
92
|
/** What the last visit showed to be wrong about the data itself: a failed seed, a 401/403, no API answer. */
|
|
87
93
|
problems: string[]
|
|
94
|
+
content?: string
|
|
88
95
|
/** Read on the first page of a context that loads. */
|
|
89
96
|
scale?: Steps | undefined
|
|
90
97
|
scaleError?: string | undefined
|
|
@@ -116,6 +123,9 @@ function within<T>(what: string, work: Promise<T>, ms = STEP_TIMEOUT_MS): Promis
|
|
|
116
123
|
return Promise.race([work, late]).finally(() => clearTimeout(timer))
|
|
117
124
|
}
|
|
118
125
|
|
|
126
|
+
export const SAME_CONTENT_WARNING =
|
|
127
|
+
'[shot] warning: every route rendered the same content — a lock screen or auth wall? see --api'
|
|
128
|
+
|
|
119
129
|
const hash = (text: string): string => createHash('sha1').update(text).digest('hex').slice(0, 6)
|
|
120
130
|
const slug = (text: string): string => text.replace(/[^\w-]+/g, '-').replace(/^-+|-+$/g, '')
|
|
121
131
|
const firstLine = (error: unknown): string =>
|
|
@@ -208,14 +218,24 @@ async function load(page: PwPage, url: string, settle = 0): Promise<void> {
|
|
|
208
218
|
if (settle > 0) await new Promise((done) => setTimeout(done, settle))
|
|
209
219
|
}
|
|
210
220
|
|
|
211
|
-
/**
|
|
221
|
+
/**
|
|
222
|
+
* Runs in the page: numbers every Card, Paper and table in DOM order, tagging those over 120×60 px as
|
|
223
|
+
* anchors. A page with none of them (Tailwind, a reader) falls back to `main`, `section`, `header`
|
|
224
|
+
* and `form` under the same floor.
|
|
225
|
+
*/
|
|
212
226
|
export function tagAutoAnchors(): void {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
227
|
+
const tag = (selector: string): number => {
|
|
228
|
+
let tagged = 0
|
|
229
|
+
Array.from(document.querySelectorAll(selector)).forEach((el, i) => {
|
|
230
|
+
const { width, height } = el.getBoundingClientRect()
|
|
231
|
+
if (width <= 120 || height <= 60) return
|
|
217
232
|
el.setAttribute('data-shot', `auto-${String(i + 1).padStart(2, '0')}`)
|
|
218
|
-
|
|
233
|
+
tagged++
|
|
234
|
+
})
|
|
235
|
+
return tagged
|
|
236
|
+
}
|
|
237
|
+
if (tag('.mantine-Card-root, .mantine-Paper-root, table') === 0)
|
|
238
|
+
tag('main, section, header, form')
|
|
219
239
|
}
|
|
220
240
|
|
|
221
241
|
/** The DOM marks of a basalt state surface: `ChartCard` and the chart state write theirs; `StatCard` has none but its `basalt-card` container. */
|
|
@@ -226,7 +246,9 @@ const readFacts = (page: PwPage): Promise<PageFacts> =>
|
|
|
226
246
|
page.evaluate(`(() => { const STATE_SURFACE = ${JSON.stringify(STATE_SURFACE)}; return {
|
|
227
247
|
anchors: [...new Set([...document.querySelectorAll('[data-shot]')].map((e) => e.getAttribute('data-shot')).filter(Boolean))],
|
|
228
248
|
declared: [...document.querySelectorAll('[data-shot-states]')].flatMap((e) => (e.getAttribute('data-shot-states') ?? '').split(/\\s+/)).filter(Boolean),
|
|
249
|
+
declaring: [...new Set([...document.querySelectorAll('[data-shot]')].filter((e) => e.closest('[data-shot-states]') || e.querySelector('[data-shot-states]')).map((e) => e.getAttribute('data-shot')).filter(Boolean))],
|
|
229
250
|
stateful: [...new Set([...document.querySelectorAll('[data-shot]')].filter((e) => e.matches(STATE_SURFACE) || e.querySelector(STATE_SURFACE)).map((e) => e.getAttribute('data-shot')).filter(Boolean))],
|
|
251
|
+
content: document.body ? document.body.innerText : '',
|
|
230
252
|
absent: Object.fromEntries([...document.querySelectorAll('[data-shot][data-shot-absent]')].map((e) => [e.getAttribute('data-shot'), (e.getAttribute('data-shot-absent') ?? '').split(/\\s+/).filter(Boolean)])),
|
|
231
253
|
}; })()`)
|
|
232
254
|
|
|
@@ -533,6 +555,55 @@ export function markVisibleTooltips(): void {
|
|
|
533
555
|
}
|
|
534
556
|
}
|
|
535
557
|
|
|
558
|
+
/** Runs in the page: how many tooltips are rendered now (the readouts a hover leaves behind while they animate out). */
|
|
559
|
+
export function visibleTooltipCount(): number {
|
|
560
|
+
return Array.from(document.querySelectorAll('[role="tooltip"]')).filter((el) => {
|
|
561
|
+
const rect = el.getBoundingClientRect()
|
|
562
|
+
return rect.width > 0 && rect.height > 0 && getComputedStyle(el).visibility !== 'hidden'
|
|
563
|
+
}).length
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Moves the pointer off the previous anchor and waits for its tooltip to unmount, so a hover crop
|
|
568
|
+
* (a union box over the anchor and its tooltip) never holds a fragment of the component above.
|
|
569
|
+
* Bounded: a tooltip that stays (pinned by the app) is left to `markVisibleTooltips`.
|
|
570
|
+
*/
|
|
571
|
+
export async function clearStrayTooltips(page: PwPage): Promise<void> {
|
|
572
|
+
await page.mouse.move(0, 0)
|
|
573
|
+
for (let waited = 0; waited < TIP_CLEAR_MS; waited += TIP_SETTLE_MS) {
|
|
574
|
+
if ((await page.evaluate(visibleTooltipCount, undefined)) === 0) return
|
|
575
|
+
await sleep(TIP_SETTLE_MS)
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Runs in the page, on the tooltip a hover opened: hides every other visible one (another anchor's
|
|
581
|
+
* readout still fading or pinned) so the crop holds none, and marks what it hid.
|
|
582
|
+
*/
|
|
583
|
+
export function muteOtherTooltips(open: Element): void {
|
|
584
|
+
for (const el of Array.from(document.querySelectorAll<HTMLElement>('[role="tooltip"]'))) {
|
|
585
|
+
const rect = el.getBoundingClientRect()
|
|
586
|
+
if (el === open || rect.width === 0 || rect.height === 0) continue
|
|
587
|
+
el.setAttribute('data-shot-muted', el.style.visibility)
|
|
588
|
+
el.style.setProperty('visibility', 'hidden', 'important')
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/** Runs in the page, for a trigger with no `aria-describedby`: marks the tooltips outside it as seen, so an earlier chart's stale readout never wins `.first()`. */
|
|
593
|
+
export function claimOwnTooltip(trigger: Element): void {
|
|
594
|
+
const tips = Array.from(document.querySelectorAll('[role="tooltip"]'))
|
|
595
|
+
if (tips.some((el) => trigger.contains(el)))
|
|
596
|
+
for (const el of tips) if (!trigger.contains(el)) el.setAttribute('data-shot-seen', '')
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/** Runs in the page: puts back exactly what `muteOtherTooltips` marked. */
|
|
600
|
+
export function unmuteTooltips(): void {
|
|
601
|
+
for (const el of Array.from(document.querySelectorAll<HTMLElement>('[data-shot-muted]'))) {
|
|
602
|
+
el.style.visibility = el.getAttribute('data-shot-muted') ?? ''
|
|
603
|
+
el.removeAttribute('data-shot-muted')
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
536
607
|
/** Runs in the page: the first id a trigger names in `aria-describedby`, looking at it and its descendants. */
|
|
537
608
|
export function describedByOf(el: Element | null): string {
|
|
538
609
|
const named = el?.matches('[aria-describedby]') ? el : el?.querySelector('[aria-describedby]')
|
|
@@ -616,12 +687,20 @@ async function captureHover(c: Ctx, name: string): Promise<void> {
|
|
|
616
687
|
await reveal(c, name, 'hover')
|
|
617
688
|
const inner = c.page.locator(`${sel(name)} [data-shot-hover]`).first()
|
|
618
689
|
const target = (await inner.count()) > 0 ? inner : anchor
|
|
690
|
+
await clearStrayTooltips(c.page)
|
|
619
691
|
await c.page.evaluate(markVisibleTooltips, undefined)
|
|
620
692
|
await hoverTrigger(target)
|
|
621
693
|
const describedBy = idOf(await target.evaluate(describedByOf))
|
|
694
|
+
if (describedBy === '') await target.evaluate(claimOwnTooltip)
|
|
622
695
|
const [box, tip] = [await settledBox(anchor), await openTooltipBox(c, describedBy)]
|
|
623
696
|
if (!box || !tip) return void (await snap(anchor, path))
|
|
624
|
-
|
|
697
|
+
try {
|
|
698
|
+
await tipOf(c, describedBy).evaluate(muteOtherTooltips)
|
|
699
|
+
await snapClip(c, path, [anchor, tipOf(c, describedBy)])
|
|
700
|
+
} finally {
|
|
701
|
+
// Best effort: a page that died under the crop must not hide the crop's own error.
|
|
702
|
+
await c.page.evaluate(unmuteTooltips, undefined).catch(() => undefined)
|
|
703
|
+
}
|
|
625
704
|
})
|
|
626
705
|
await c.page.mouse.move(0, 0)
|
|
627
706
|
}
|
|
@@ -692,9 +771,11 @@ async function captureTooltip(c: Ctx, name: string): Promise<void> {
|
|
|
692
771
|
if ((await trigger.count()) === 0) throw new NotDeclared('no [data-shot-tooltip] in the anchor')
|
|
693
772
|
const anchor = anchorOf(c, name)
|
|
694
773
|
await reveal(c, name, 'tooltip')
|
|
774
|
+
await clearStrayTooltips(c.page)
|
|
695
775
|
await c.page.evaluate(markVisibleTooltips, undefined)
|
|
696
776
|
await hoverTrigger(trigger)
|
|
697
777
|
const describedBy = idOf(await trigger.evaluate(describedByOf))
|
|
778
|
+
if (describedBy === '') await trigger.evaluate(claimOwnTooltip)
|
|
698
779
|
const t = await openTooltipBox(c, describedBy, TOOLTIP_TIMEOUT_MS)
|
|
699
780
|
if (!t) throw new Error('no visible [role="tooltip"] after hover')
|
|
700
781
|
const a = await settledBox(anchor)
|
|
@@ -711,6 +792,15 @@ const POINTER_STATES = {
|
|
|
711
792
|
tooltip: captureTooltip,
|
|
712
793
|
}
|
|
713
794
|
|
|
795
|
+
/** A state surface no `data-shot-states` covers and no `data-shot-absent` excuses: its `state` was never scored. */
|
|
796
|
+
function lacksStates(c: Ctx, name: string, state: ShotState): boolean {
|
|
797
|
+
const { stateful, declaring, declared, absent } = c.facts
|
|
798
|
+
const own = declaring ?? (declared.length > 0 ? c.facts.anchors : [])
|
|
799
|
+
return (
|
|
800
|
+
stateful?.includes(name) === true && !own.includes(name) && !absent?.[name]?.includes(state)
|
|
801
|
+
)
|
|
802
|
+
}
|
|
803
|
+
|
|
714
804
|
/** `empty`/`loading`/`error`: reload with `shot-state=<state>`, re-read the anchors, crop each. */
|
|
715
805
|
async function captureUrlState(c: Ctx, state: ShotState): Promise<void> {
|
|
716
806
|
const restNames = c.facts.anchors
|
|
@@ -721,9 +811,7 @@ async function captureUrlState(c: Ctx, state: ShotState): Promise<void> {
|
|
|
721
811
|
state,
|
|
722
812
|
status: 'not-declared',
|
|
723
813
|
note: c.facts.declared.length === 0 ? NO_STATES_NOTE : 'page does not declare this state',
|
|
724
|
-
...(c
|
|
725
|
-
? { stateful: true as const }
|
|
726
|
-
: {}),
|
|
814
|
+
...(lacksStates(c, name, state) ? { stateful: true as const } : {}),
|
|
727
815
|
})
|
|
728
816
|
}
|
|
729
817
|
return
|
|
@@ -750,6 +838,8 @@ async function captureUrlState(c: Ctx, state: ShotState): Promise<void> {
|
|
|
750
838
|
}
|
|
751
839
|
const note = restNames.includes(name) ? undefined : 'anchor only present in this state'
|
|
752
840
|
await attempt(c, name, state, (path) => restCrop(c, name, state, path), note)
|
|
841
|
+
const shot = c.shots.findLast((r) => r.name === name && r.state === state)
|
|
842
|
+
if (shot && shot.status !== 'not-declared' && lacksStates(c, name, state)) shot.stateful = true
|
|
753
843
|
}
|
|
754
844
|
}
|
|
755
845
|
|
|
@@ -857,6 +947,7 @@ async function capturePage(
|
|
|
857
947
|
input.apiProblems?.() // calls still in flight from an earlier route are not this page's
|
|
858
948
|
try {
|
|
859
949
|
c.facts = await visit(c, input.base + route)
|
|
950
|
+
if (c.facts.content) c.content = hash(c.facts.content)
|
|
860
951
|
} catch (error) {
|
|
861
952
|
record(c, {
|
|
862
953
|
name: PAGE_ANCHOR,
|
|
@@ -1007,6 +1098,7 @@ export async function capture(input: CaptureInput): Promise<{
|
|
|
1007
1098
|
scale: [] as Scale[],
|
|
1008
1099
|
scaleError: undefined as string | undefined,
|
|
1009
1100
|
}
|
|
1101
|
+
const contents = new Map<string, string>()
|
|
1010
1102
|
for (const scheme of SCHEMES) {
|
|
1011
1103
|
for (const viewport of VIEWPORTS) {
|
|
1012
1104
|
input.apiProblems?.() // a new context starts with a clean queue
|
|
@@ -1034,6 +1126,7 @@ export async function capture(input: CaptureInput): Promise<{
|
|
|
1034
1126
|
out.scale.push({ scheme, viewport, ...done.scale })
|
|
1035
1127
|
scaled = true
|
|
1036
1128
|
}
|
|
1129
|
+
if (done.content && !contents.has(route)) contents.set(route, done.content)
|
|
1037
1130
|
if (done.scaleError) out.scaleError = out.scaleError ?? done.scaleError
|
|
1038
1131
|
out.anchors.push(...done.anchors)
|
|
1039
1132
|
out.shots.push(...done.shots)
|
|
@@ -1043,6 +1136,12 @@ export async function capture(input: CaptureInput): Promise<{
|
|
|
1043
1136
|
}
|
|
1044
1137
|
}
|
|
1045
1138
|
}
|
|
1139
|
+
if (
|
|
1140
|
+
input.routes.length > 1 &&
|
|
1141
|
+
contents.size === new Set(input.routes).size &&
|
|
1142
|
+
new Set(contents.values()).size === 1
|
|
1143
|
+
)
|
|
1144
|
+
input.log(SAME_CONTENT_WARNING)
|
|
1046
1145
|
await writeSheets(input, out).catch((error: unknown) =>
|
|
1047
1146
|
input.log(`[shot] contact sheets not written: ${firstLine(error)}`),
|
|
1048
1147
|
)
|
package/src/cli/shot/detect.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* |-|-|-|
|
|
10
10
|
* | scan/shot-error | content | P0 |
|
|
11
11
|
* | scan/no-anchors | content | P0 |
|
|
12
|
-
* | craft-7/no-declared-states | content | P2 (
|
|
12
|
+
* | craft-7/no-declared-states | content | P2 (per anchor that renders a state surface) |
|
|
13
13
|
* | craft-5/contrast | content | P0 |
|
|
14
14
|
* | craft-5/assumed-backdrop | content | P2 |
|
|
15
15
|
* | craft-1/scale-error, -missing| layout | P1 |
|
|
@@ -22,14 +22,15 @@
|
|
|
22
22
|
*
|
|
23
23
|
* P0 and P1 fail the run (exit 2); P2 and P3 are listed findings that do not (exit 0).
|
|
24
24
|
* Findings run content → layout → style, the order the reviewer reports in.
|
|
25
|
-
* Score = 100 − (25·P0 + 10·P1 + 3·P2 + 1·P3), floored at 0.
|
|
25
|
+
* Score = 100 − (25·P0 + 10·P1 + 3·P2 + 1·P3), floored at 0; null ("nothing measured") when no anchor resolved.
|
|
26
26
|
*/
|
|
27
27
|
import { execFileSync } from 'node:child_process'
|
|
28
28
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
29
29
|
import { isAbsolute, join, relative, resolve } from 'node:path'
|
|
30
30
|
import { parseArgs } from 'node:util'
|
|
31
31
|
|
|
32
|
-
import {
|
|
32
|
+
import { contrastThreshold } from './measure'
|
|
33
|
+
import { PAGE_ANCHOR, SHOT_HOME } from './types'
|
|
33
34
|
import type { AnchorMetrics, Scale, ShotMetrics, Sides } from './types'
|
|
34
35
|
|
|
35
36
|
export type Severity = 'P0' | 'P1' | 'P2' | 'P3'
|
|
@@ -73,7 +74,10 @@ export type HistoryEntry = {
|
|
|
73
74
|
out: string
|
|
74
75
|
commit?: string
|
|
75
76
|
counts: Record<Severity, number>
|
|
76
|
-
|
|
77
|
+
/** Null when no anchor resolved: nothing was measured, so there is no score. */
|
|
78
|
+
score: number | null
|
|
79
|
+
/** Total findings: the score floors at 0, this keeps counting. */
|
|
80
|
+
findings?: number
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
const LAYERS: readonly Layer[] = ['content', 'layout', 'style']
|
|
@@ -213,7 +217,7 @@ function anchorFindings(a: AnchorMetrics, scale: Scale | undefined): Draft[] {
|
|
|
213
217
|
severity: 'P0',
|
|
214
218
|
layer: 'content',
|
|
215
219
|
cite: cite('contrast.failures'),
|
|
216
|
-
defect: `${failures.length} text run${failures.length === 1 ? '' : 's'} below the AA contrast threshold; lowest ${worst.ratio}:1 on "${worst.text}" (${worst.fontSize}px).`,
|
|
220
|
+
defect: `${failures.length} text run${failures.length === 1 ? '' : 's'} below the AA contrast threshold; lowest ${worst.ratio}:1 on "${worst.text}" (needs ${worst.needs ?? contrastThreshold(worst.fontSize, worst.bold ?? false)}:1 at ${worst.fontSize}px${worst.bold === undefined ? '' : worst.bold ? ' bold' : ' regular'}).`,
|
|
217
221
|
})
|
|
218
222
|
}
|
|
219
223
|
if (a.contrast.backdrop === 'assumed-white') {
|
|
@@ -277,20 +281,20 @@ export function detectFindings(m: ShotMetrics, lint?: LintReport): Finding[] {
|
|
|
277
281
|
defect: `The shot failed${s.note ? `: ${s.note}` : ''}.`,
|
|
278
282
|
})
|
|
279
283
|
}
|
|
280
|
-
const stateful = new Map<string,
|
|
284
|
+
const stateful = new Map<string, { route: string; name: string }>()
|
|
281
285
|
for (const s of m.shots) {
|
|
282
|
-
if (s.
|
|
283
|
-
stateful.set(s.route
|
|
286
|
+
if (!s.stateful || s.status === 'absent') continue
|
|
287
|
+
stateful.set(`${s.route}\0${s.name}`, { route: s.route, name: s.name })
|
|
284
288
|
}
|
|
285
|
-
for (const
|
|
289
|
+
for (const { route, name } of stateful.values()) {
|
|
286
290
|
drafts.push({
|
|
287
291
|
...scan,
|
|
288
292
|
rule: 'craft-7/no-declared-states',
|
|
289
293
|
severity: 'P2',
|
|
290
|
-
anchor:
|
|
294
|
+
anchor: name,
|
|
291
295
|
route,
|
|
292
|
-
cite: `metrics.json shots[${route}
|
|
293
|
-
defect: `${
|
|
296
|
+
cite: `metrics.json shots[${route} ${name} stateful]`,
|
|
297
|
+
defect: `${name} renders a state surface but declares no data-shot-states of its own, so empty, loading and error were never scored: add data-shot-states="empty loading error" to it, or data-shot-absent for a state it never shows.`,
|
|
294
298
|
})
|
|
295
299
|
}
|
|
296
300
|
if (m.scaleError || m.scale.length === 0) {
|
|
@@ -439,12 +443,12 @@ function nextHistory(
|
|
|
439
443
|
|
|
440
444
|
/**
|
|
441
445
|
* Writes `detect.json` and `history.json` through temp files and renames both only after both are
|
|
442
|
-
* written, so a failed write never leaves one without the other. Returns the last
|
|
446
|
+
* written, so a failed write never leaves one without the other. Returns the last runs of this out dir (other dirs never chain into one trend).
|
|
443
447
|
*/
|
|
444
448
|
function persist(
|
|
445
449
|
files: { detectPath: string; report: object; home: string; entry: HistoryEntry },
|
|
446
450
|
log: (line: string) => void,
|
|
447
|
-
):
|
|
451
|
+
): HistoryEntry[] {
|
|
448
452
|
const { detectPath, report, home, entry } = files
|
|
449
453
|
const historyPath = join(home, 'history.json')
|
|
450
454
|
return io('write detect.json or history.json', () => {
|
|
@@ -456,7 +460,7 @@ function persist(
|
|
|
456
460
|
writeFileSync(`${detectPath}.tmp`, json(report))
|
|
457
461
|
renameSync(`${historyPath}.tmp`, historyPath)
|
|
458
462
|
renameSync(`${detectPath}.tmp`, detectPath)
|
|
459
|
-
return runs.
|
|
463
|
+
return runs.filter((r) => r.out === entry.out).slice(-TREND_RUNS)
|
|
460
464
|
})
|
|
461
465
|
}
|
|
462
466
|
|
|
@@ -490,12 +494,19 @@ export async function detect(
|
|
|
490
494
|
try {
|
|
491
495
|
let values: { out?: string | undefined; lint?: string | undefined }
|
|
492
496
|
try {
|
|
493
|
-
|
|
497
|
+
const parsed = parseArgs({
|
|
494
498
|
args: [...flags],
|
|
495
499
|
options: { out: { type: 'string' }, lint: { type: 'string' } },
|
|
496
|
-
|
|
497
|
-
})
|
|
500
|
+
allowPositionals: true,
|
|
501
|
+
})
|
|
502
|
+
const [positional] = parsed.positionals
|
|
503
|
+
if (positional !== undefined)
|
|
504
|
+
throw new DetectError(
|
|
505
|
+
`detect takes --out <dir>, not a positional ('${positional}'): basalt-ui shot detect --out ${positional}`,
|
|
506
|
+
)
|
|
507
|
+
values = parsed.values
|
|
498
508
|
} catch (error) {
|
|
509
|
+
if (error instanceof DetectError) throw new DetectError(`${error.message}\n${USAGE_LINE}`)
|
|
499
510
|
throw new DetectError(
|
|
500
511
|
`${error instanceof Error ? error.message : String(error)}\n${USAGE_LINE}`,
|
|
501
512
|
)
|
|
@@ -505,7 +516,7 @@ export async function detect(
|
|
|
505
516
|
const lint = values.lint ? readLint(resolve(cwd, values.lint)) : undefined
|
|
506
517
|
const findings = detectFindings(metrics, lint)
|
|
507
518
|
const counts = countsOf(findings)
|
|
508
|
-
const score = scoreOf(findings)
|
|
519
|
+
const score = metrics.anchors.length === 0 ? null : scoreOf(findings)
|
|
509
520
|
const at = (deps.now ?? (() => new Date()))().toISOString()
|
|
510
521
|
const rel = relative(cwd, outDir)
|
|
511
522
|
const out = rel === '' || rel.startsWith('..') || isAbsolute(rel) ? outDir : rel
|
|
@@ -515,7 +526,14 @@ export async function detect(
|
|
|
515
526
|
detectPath: join(outDir, 'detect.json'),
|
|
516
527
|
report: { version: 1, at, out, ...(commit && { commit }), counts, score, findings },
|
|
517
528
|
home: join(cwd, SHOT_HOME),
|
|
518
|
-
entry: {
|
|
529
|
+
entry: {
|
|
530
|
+
at,
|
|
531
|
+
out,
|
|
532
|
+
...(commit && { commit }),
|
|
533
|
+
counts,
|
|
534
|
+
score,
|
|
535
|
+
findings: findings.length,
|
|
536
|
+
},
|
|
519
537
|
},
|
|
520
538
|
log,
|
|
521
539
|
)
|
|
@@ -523,10 +541,16 @@ export async function detect(
|
|
|
523
541
|
.map((s) => `${s} ${counts[s]}`)
|
|
524
542
|
.join(', ')
|
|
525
543
|
log(
|
|
526
|
-
`[detect] ${findings.length === 0 ? 'no findings' : `${findings.length} findings (${summary})`} · score ${score}`,
|
|
544
|
+
`[detect] ${findings.length === 0 ? 'no findings' : `${findings.length} findings (${summary})`} · ${score === null ? 'nothing measured (no anchor resolved: not a score)' : `score ${score}`}`,
|
|
527
545
|
)
|
|
528
546
|
for (const line of table(findings)) log(line)
|
|
529
|
-
|
|
547
|
+
const point = (r: HistoryEntry): string => {
|
|
548
|
+
const n = r.findings === undefined ? '' : ` (${r.findings} findings)`
|
|
549
|
+
return `${r.score ?? 'nothing measured'}${n}`
|
|
550
|
+
}
|
|
551
|
+
log(
|
|
552
|
+
`[detect] trend ${trend.map(point).join(' → ')} · ${relative(cwd, join(outDir, 'detect.json'))}`,
|
|
553
|
+
)
|
|
530
554
|
return counts.P0 + counts.P1 > 0 ? 2 : 0
|
|
531
555
|
} catch (error) {
|
|
532
556
|
if (!(error instanceof DetectError)) throw error
|
package/src/cli/shot/index.ts
CHANGED
|
@@ -90,6 +90,11 @@ export function parseShotArgs(
|
|
|
90
90
|
if (positionals.length === 0) throw new ShotError(`no route given.\n${USAGE_LINE}`)
|
|
91
91
|
const bad = positionals.find((r) => !r.startsWith('/'))
|
|
92
92
|
if (bad) throw new ShotError(`route '${bad}' must start with '/'.\n${USAGE_LINE}`)
|
|
93
|
+
const spaced = positionals.find((r) => /\s/.test(r))
|
|
94
|
+
if (spaced)
|
|
95
|
+
throw new ShotError(
|
|
96
|
+
`route '${spaced}' contains whitespace: pass each route as its own argument (zsh does not word-split $ROUTES; use \${=ROUTES} or an array).\n${USAGE_LINE}`,
|
|
97
|
+
)
|
|
93
98
|
if (Boolean(values.base) === Boolean(values.dist)) {
|
|
94
99
|
throw new ShotError(`pass exactly one of --base <url> or --dist <dir>.\n${USAGE_LINE}`)
|
|
95
100
|
}
|
|
@@ -172,7 +177,8 @@ export function planOut(cwd: string, out: string): string {
|
|
|
172
177
|
const refuse = (why: string): never => {
|
|
173
178
|
throw new ShotError(`--out ${out} ${why}`)
|
|
174
179
|
}
|
|
175
|
-
|
|
180
|
+
const inProject = `a directory inside the project (${cwd}; in a monorepo, the app dir)`
|
|
181
|
+
if (rel === '' || outside(rel)) refuse(`must be ${inProject}`)
|
|
176
182
|
if (relative(join(cwd, HOME), dir) === '')
|
|
177
183
|
refuse('is the shot home (holds last.json); use a subdirectory')
|
|
178
184
|
if (rel === '.basalt' || rel.split(sep).some((part) => PROTECTED_SEGMENTS.has(part))) {
|
|
@@ -188,7 +194,7 @@ export function planOut(cwd: string, out: string): string {
|
|
|
188
194
|
} catch {
|
|
189
195
|
refuse('sits behind a dangling symlink')
|
|
190
196
|
}
|
|
191
|
-
if (outside(relative(realpathSync(cwd), real))) refuse(
|
|
197
|
+
if (outside(relative(realpathSync(cwd), real))) refuse(`resolves outside the project (${cwd})`)
|
|
192
198
|
if (probe === dir) {
|
|
193
199
|
if (!statSync(dir).isDirectory()) refuse('exists and is not a directory')
|
|
194
200
|
if (readdirSync(dir).length > 0 && !isPreviousShot(dir)) {
|
package/src/cli/shot/measure.ts
CHANGED
|
@@ -78,8 +78,17 @@ export function finishMeasurement({ texts, radius, nested, ...rest }: Reading):
|
|
|
78
78
|
const exact = contrastRatio(t.fg, t.bg)
|
|
79
79
|
const ratio = Math.round(exact * 100) / 100
|
|
80
80
|
min = min === null ? ratio : Math.min(min, ratio)
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const needs = contrastThreshold(t.fontSize, t.bold)
|
|
82
|
+
if (exact < needs) {
|
|
83
|
+
failures.push({
|
|
84
|
+
text: t.text,
|
|
85
|
+
ratio,
|
|
86
|
+
fg: hex(t.fg),
|
|
87
|
+
bg: hex(t.bg),
|
|
88
|
+
fontSize: t.fontSize,
|
|
89
|
+
needs,
|
|
90
|
+
bold: t.bold,
|
|
91
|
+
})
|
|
83
92
|
}
|
|
84
93
|
}
|
|
85
94
|
const backdrop = texts.some((t) => t.assumedWhite) ? ({ backdrop: 'assumed-white' } as const) : {}
|
package/src/cli/shot/types.ts
CHANGED
|
@@ -31,6 +31,9 @@ export type ContrastFailure = {
|
|
|
31
31
|
fg: string
|
|
32
32
|
bg: string
|
|
33
33
|
fontSize: number
|
|
34
|
+
/** The WCAG threshold applied (3 for large text, else 4.5); absent in older metrics.json. */
|
|
35
|
+
needs?: number
|
|
36
|
+
bold?: boolean
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
/** What the in-page measurer returns for one anchor. */
|
|
@@ -72,7 +75,7 @@ export type ShotRecord = {
|
|
|
72
75
|
/** `absent`: the anchor declared itself missing in this state (`data-shot-absent`): not a defect. */
|
|
73
76
|
status: 'ok' | 'not-declared' | 'absent' | 'skipped' | 'error'
|
|
74
77
|
note?: string
|
|
75
|
-
/** The anchor renders a basalt state surface (a ChartCard, StatCard or chart state)
|
|
78
|
+
/** The anchor renders a basalt state surface (a ChartCard, StatCard or chart state) but declares no `data-shot-states` of its own (and no `data-shot-absent` for this state). */
|
|
76
79
|
stateful?: true
|
|
77
80
|
}
|
|
78
81
|
|
package/src/cli/sync.ts
CHANGED
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
resolveProjectDir,
|
|
36
36
|
routerSeedPlan,
|
|
37
37
|
rootsNotices,
|
|
38
|
+
rootToolingStates,
|
|
38
39
|
sha256,
|
|
39
40
|
shippedAssetPath,
|
|
40
41
|
START_APP_NOTE,
|
|
@@ -255,9 +256,18 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
255
256
|
}
|
|
256
257
|
if (seedSkip === 'start' && (!opts.check || syncFlags.includes('--verbose')))
|
|
257
258
|
console.log(`basalt-ui sync: ${START_APP_NOTE}`)
|
|
258
|
-
|
|
259
|
+
// A skipped root template is compared with the repo root's own file (read-only): only a drifted
|
|
260
|
+
// or absent one reads as unfinished work.
|
|
261
|
+
const states = rootToolingStates(cwd, placement, ctx)
|
|
262
|
+
const notices = placementNotices(cwd, placement)
|
|
263
|
+
const placementSkips = notices.filter((_, i) => states[i] !== 'in sync')
|
|
259
264
|
if (opts.check !== true || syncFlags.includes('--verbose')) {
|
|
260
|
-
|
|
265
|
+
states.forEach((st, i) => {
|
|
266
|
+
const file = i === 0 ? 'lefthook.yml' : 'check.yml'
|
|
267
|
+
console.log(
|
|
268
|
+
`basalt-ui sync: ${file} at the repo root: ${st}${st === 'in sync' ? '' : ` — ${notices[i]}`}`,
|
|
269
|
+
)
|
|
270
|
+
})
|
|
261
271
|
}
|
|
262
272
|
|
|
263
273
|
const rootsMessages = rootsNotices(rootsState)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createContext } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The title of the host region a `QueryState` sits in (`Section` sets it), so the error default
|
|
5
|
+
* names it — "Could not load practice record" — instead of the bare "Could not load". An explicit
|
|
6
|
+
* `errorTitle` still wins; outside any host it is `undefined` and nothing changes.
|
|
7
|
+
*/
|
|
8
|
+
export const HostTitleContext = createContext<string | undefined>(undefined)
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The error title a component names itself in: "Revenue" → "Could not load revenue". A leading
|
|
12
|
+
* capital followed by another capital or a non-letter ("KPI", "MRR", "2024 sales") keeps its case;
|
|
13
|
+
* a missing or blank label stays the bare "Could not load". Mantine-free: `charts/**` imports it.
|
|
14
|
+
*/
|
|
15
|
+
export function couldNotLoad(label?: string): string {
|
|
16
|
+
const noun = label?.trim()
|
|
17
|
+
if (!noun) return 'Could not load'
|
|
18
|
+
const lead = noun.charAt(0)
|
|
19
|
+
const second = noun.charAt(1)
|
|
20
|
+
const lowers = second !== '' && second === second.toLowerCase() && second !== second.toUpperCase()
|
|
21
|
+
return `Could not load ${lowers ? lead.toLowerCase() : lead}${noun.slice(1)}`
|
|
22
|
+
}
|
package/src/common/index.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* may reach it too.
|
|
8
8
|
*/
|
|
9
9
|
export { type BasaltProps, type SlotClassNames, type SlotStylesProps } from './props'
|
|
10
|
+
export { type DataAttributes, pickDataAttributes, splitDataAttributes } from './props'
|
|
10
11
|
export { type Tone, type ToneWithNeutral, type Tier, cx } from './props'
|
|
11
12
|
export { assignRef, mergeRefs } from './refs'
|
|
12
13
|
export { BASALT_PREFIX, requiredProp, oneOf, duplicateMount, missingLayer } from './errors'
|
package/src/common/props.ts
CHANGED
|
@@ -31,6 +31,36 @@ export interface BasaltProps {
|
|
|
31
31
|
readonly style?: CSSProperties | undefined
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Free-form `data-*` attributes. A composite takes them on top of `BasaltProps` and forwards them to
|
|
36
|
+
* its ROOT element through `pickDataAttributes` — the seam `basalt-ui shot` (`data-shot`,
|
|
37
|
+
* `data-shot-states`) and consumer test hooks read. Only `data-*` crosses: basalt still does not
|
|
38
|
+
* spread `...rest`.
|
|
39
|
+
*/
|
|
40
|
+
export type DataAttributes = {
|
|
41
|
+
readonly [K in `data-${string}`]?: string | number | boolean | undefined
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Splits `props` into its `data-*` entries (spread them onto the root: `{...data}`) and everything
|
|
46
|
+
* else. A composite that already forwards its remainder to a child (`...header`) splits first, or
|
|
47
|
+
* the anchor lands on the child instead of the root.
|
|
48
|
+
*/
|
|
49
|
+
export function splitDataAttributes<P extends object>(
|
|
50
|
+
props: P,
|
|
51
|
+
): { data: DataAttributes; rest: Omit<P, `data-${string}`> } {
|
|
52
|
+
const data: Record<string, unknown> = {}
|
|
53
|
+
const rest: Record<string, unknown> = {}
|
|
54
|
+
for (const [key, value] of Object.entries(props)) {
|
|
55
|
+
if (key.startsWith('data-')) data[key] = value
|
|
56
|
+
else rest[key] = value
|
|
57
|
+
}
|
|
58
|
+
return { data: data as DataAttributes, rest: rest as Omit<P, `data-${string}`> }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The `data-*` entries of `props` alone, for a component that destructures the rest itself. */
|
|
62
|
+
export const pickDataAttributes = (props: object): DataAttributes => splitDataAttributes(props).data
|
|
63
|
+
|
|
34
64
|
/** One class per named slot. The slot union is the component's documented contract. */
|
|
35
65
|
export type SlotClassNames<S extends string> = Partial<Record<S, string>>
|
|
36
66
|
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* The one Retry. ErrorState (Mantine, StatCard / pages), ChartCard's placeholder and a strip cell's
|
|
3
3
|
* error all render this, so the three read as one button. It is a plain element because `./charts`
|
|
4
4
|
* resolves with no Mantine, and it is styled to be a Mantine `size="xs" variant="default"` Button
|
|
5
|
-
* reading the same `--vx-*` tokens the theme binds that button to: panel fill (elevated on hover),
|
|
6
|
-
*
|
|
5
|
+
* reading the same `--vx-*` tokens the theme binds that button to: panel fill (elevated on hover),
|
|
6
|
+
* `shadow-raised`, the control radius, the xs type size, the theme's inline padding step and
|
|
7
7
|
* Mantine's 30px xs height. `--mantine-scale` carries the app's scale knob, 1 where Mantine is absent.
|
|
8
8
|
*/
|
|
9
9
|
.retry {
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
height: calc(1.875rem * var(--mantine-scale, 1));
|
|
16
16
|
padding-block: 0;
|
|
17
17
|
padding-inline: calc(var(--vx-space-stack-md, 0.75rem) * var(--mantine-scale, 1));
|
|
18
|
-
|
|
18
|
+
/* A visible edge: the panel fill and `shadow-raised` alone read as a pale chip on the page or a card,
|
|
19
|
+
so the border is ink mixed into the panel (>= 3:1 against it in both schemes), not the hairline. */
|
|
20
|
+
border: calc(0.0625rem * var(--mantine-scale, 1)) solid var(--vx-muted);
|
|
21
|
+
border-color: color-mix(in srgb, var(--vx-ink) 55%, var(--vx-surface-panel));
|
|
19
22
|
border-radius: var(--vx-radius-ctrl);
|
|
20
23
|
background: var(--vx-surface-panel);
|
|
21
24
|
box-shadow: var(--vx-shadow-raised);
|
|
@@ -46,6 +49,7 @@
|
|
|
46
49
|
/* Busy is Mantine's disabled paint: its own disabled colour and background, flat, no border. */
|
|
47
50
|
.retry:disabled {
|
|
48
51
|
background: var(--mantine-color-disabled, var(--vx-surface-subtle));
|
|
52
|
+
border-color: transparent;
|
|
49
53
|
color: var(--mantine-color-disabled-color, var(--vx-muted));
|
|
50
54
|
box-shadow: none;
|
|
51
55
|
cursor: not-allowed;
|