basalt-ui 2.9.0 → 2.10.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 +51 -34
- package/MIGRATING.md +43 -12
- package/configs/oxlint.json +4 -0
- package/dist/charts/BandStrip.d.ts +6 -4
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +8 -8
- package/dist/charts/CartesianChart.d.ts.map +1 -1
- package/dist/charts/CartesianChart.js +4 -3
- package/dist/charts/MirroredBars.d.ts +16 -5
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +46 -9
- package/dist/charts/band-fold.d.ts +6 -0
- package/dist/charts/band-fold.d.ts.map +1 -1
- package/dist/charts/band-fold.js +11 -1
- package/dist/charts/legend.d.ts +2 -0
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +14 -10
- package/dist/charts/types.d.ts +7 -1
- package/dist/charts/types.d.ts.map +1 -1
- package/dist/cli/config.d.ts +10 -0
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +7 -2
- package/dist/cli/doctor-upgrade.d.ts +9 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +14 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +4 -0
- package/dist/cli/index.d.ts +3 -2
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +4 -2
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +6 -0
- package/dist/cli/router-wiring.d.ts +4 -2
- package/dist/cli/router-wiring.d.ts.map +1 -1
- package/dist/cli/router-wiring.js +2 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +11 -4
- package/dist/controls/enum-filter.d.ts +4 -1
- package/dist/controls/enum-filter.d.ts.map +1 -1
- package/dist/controls/enum-filter.js +2 -1
- package/dist/controls/number-filter.d.ts.map +1 -1
- package/dist/controls/number-filter.js +2 -0
- package/llms.txt +8 -7
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +17 -15
- package/src/charts/CartesianChart.tsx +3 -2
- package/src/charts/MirroredBars.tsx +71 -18
- package/src/charts/band-fold.ts +21 -0
- package/src/charts/legend.tsx +21 -12
- package/src/charts/types.ts +7 -1
- package/src/cli/config.ts +17 -1
- package/src/cli/doctor-upgrade.ts +23 -1
- package/src/cli/doctor.ts +4 -0
- package/src/cli/index.ts +8 -4
- package/src/cli/init.ts +7 -0
- package/src/cli/router-wiring.ts +6 -2
- package/src/cli/sync.ts +19 -5
- package/src/controls/enum-filter.tsx +5 -1
- package/src/controls/number-filter.tsx +6 -1
|
@@ -116,6 +116,7 @@ export function ChartShell<T>(props: ChartShellProps<T>): ReactElement {
|
|
|
116
116
|
return next
|
|
117
117
|
})
|
|
118
118
|
}, [])
|
|
119
|
+
const resolved = resolveChartState(state)
|
|
119
120
|
const legendNode: ReactNode = useMemo(
|
|
120
121
|
() =>
|
|
121
122
|
shown ? (
|
|
@@ -127,16 +128,16 @@ export function ChartShell<T>(props: ChartShellProps<T>): ReactElement {
|
|
|
127
128
|
toggle={toggle}
|
|
128
129
|
onToggle={onToggle}
|
|
129
130
|
onHighlight={setHighlighted}
|
|
131
|
+
concealed={resolved !== null}
|
|
130
132
|
/>
|
|
131
133
|
) : null,
|
|
132
|
-
[shown, series, hidden, config?.groups, toggle, onToggle],
|
|
134
|
+
[shown, series, hidden, config?.groups, toggle, onToggle, resolved],
|
|
133
135
|
)
|
|
134
136
|
// `header` is the enclosing card's header row (`top` outside a card); either way the legend is
|
|
135
137
|
// the first thing in the chart's own markup.
|
|
136
138
|
const atTop = config?.placement === 'top' || config?.placement === 'header'
|
|
137
139
|
const asHeaderRow = config?.placement === 'header' && inCard
|
|
138
140
|
|
|
139
|
-
const resolved = resolveChartState(state)
|
|
140
141
|
return (
|
|
141
142
|
<div
|
|
142
143
|
ref={ref}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* configure — its zero IS the baseline.
|
|
10
10
|
*
|
|
11
11
|
* ABSENCE is a state a reader cannot decode from either axis, so it is drawn across the full height
|
|
12
|
-
* of both panes in one flat `--vx-neutral`
|
|
12
|
+
* of both panes in one flat fill (`--vx-neutral`, or the `absentState` entry's colour): a `getAbsentFraction` share of a bar's width that no
|
|
13
13
|
* source sample covers. A bar that measured zero draws nothing; an absent one draws neutral.
|
|
14
14
|
*/
|
|
15
15
|
import { decorative } from '@tanstack/charts/mark/decorative'
|
|
@@ -26,7 +26,7 @@ import { barMark, emphasis } from './marks'
|
|
|
26
26
|
import { PanelRung, chartHeightOf, paneX, paneY, rowsOf } from './panel'
|
|
27
27
|
import type { PaneBuilder, PanelInput, PanelPlan } from './panel'
|
|
28
28
|
import { xScaleFor } from './scales'
|
|
29
|
-
import { foldBands } from './band-fold'
|
|
29
|
+
import { foldBands, resolveNamedState } from './band-fold'
|
|
30
30
|
import { rowX } from './types'
|
|
31
31
|
import type { CartesianChartProps, ChartSeries, ChartX, PlotRow } from './types'
|
|
32
32
|
|
|
@@ -46,12 +46,16 @@ export type MirroredBarPane = {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/** A bar series. Any entry that is neither pane is legend-only (give it `getValue: () => null`). */
|
|
49
|
-
export type MirroredBarsSeries<T> = Pick<
|
|
49
|
+
export type MirroredBarsSeries<T, K extends string = string> = Pick<
|
|
50
50
|
ChartSeries<T>,
|
|
51
|
-
'
|
|
52
|
-
>
|
|
51
|
+
'label' | 'color' | 'getValue' | 'formatValue' | 'tooltip' | 'legend' | 'role' | 'note'
|
|
52
|
+
> & {
|
|
53
|
+
key: K
|
|
54
|
+
/** Read for the `absentState` entry only (its fill and swatch); the panes draw at full colour. */
|
|
55
|
+
fillOpacity?: number | undefined
|
|
56
|
+
}
|
|
53
57
|
|
|
54
|
-
export type MirroredBarsProps<T, X extends ChartX = ChartX> = Pick<
|
|
58
|
+
export type MirroredBarsProps<T, X extends ChartX = ChartX, K extends string = string> = Pick<
|
|
55
59
|
CartesianChartProps<T, X>,
|
|
56
60
|
| 'ariaLabel'
|
|
57
61
|
| 'data'
|
|
@@ -66,15 +70,22 @@ export type MirroredBarsProps<T, X extends ChartX = ChartX> = Pick<
|
|
|
66
70
|
| 'style'
|
|
67
71
|
> & {
|
|
68
72
|
/** The single source of colours, legend entries and tooltip rows. */
|
|
69
|
-
series: readonly MirroredBarsSeries<T>[]
|
|
73
|
+
series: readonly MirroredBarsSeries<T, K>[]
|
|
70
74
|
/** Drawn above the baseline. */
|
|
71
75
|
up: MirroredBarPane
|
|
72
76
|
/** Drawn below the baseline. */
|
|
73
77
|
down: MirroredBarPane
|
|
74
78
|
/** The up pane's share of the height. Default 0.35: the pair is usually asymmetric. */
|
|
75
79
|
upFraction?: number | undefined
|
|
76
|
-
/** 0..1 of a bar's width that no source sample covers, drawn
|
|
80
|
+
/** 0..1 of a bar's width that no source sample covers, drawn across both panes. */
|
|
77
81
|
getAbsentFraction?: ((d: T) => number) | undefined
|
|
82
|
+
/**
|
|
83
|
+
* The `series` key that names the absent share: its colour fills it and its legend entry labels
|
|
84
|
+
* it (give it `getValue: () => null`, it is legend-only). `BandStrip.absentState`'s shape. Its
|
|
85
|
+
* colour must differ from every measured series', not only by alpha. Default: a flat
|
|
86
|
+
* `--vx-neutral` with no legend entry. A key naming no entry throws.
|
|
87
|
+
*/
|
|
88
|
+
absentState?: K | undefined
|
|
78
89
|
/** Per-datum bar opacity: a real but qualified measurement (a short bucket) drawn dimmer. */
|
|
79
90
|
getBarOpacity?: ((d: T) => number) | undefined
|
|
80
91
|
/**
|
|
@@ -122,18 +133,42 @@ function assertPaneKey<T>(
|
|
|
122
133
|
)
|
|
123
134
|
}
|
|
124
135
|
|
|
125
|
-
export function MirroredBars<T, X extends ChartX = ChartX>(
|
|
126
|
-
props: MirroredBarsProps<T, X>,
|
|
136
|
+
export function MirroredBars<T, X extends ChartX = ChartX, K extends string = string>(
|
|
137
|
+
props: MirroredBarsProps<T, X, K>,
|
|
127
138
|
): ReactElement {
|
|
128
|
-
const {
|
|
129
|
-
|
|
130
|
-
|
|
139
|
+
const {
|
|
140
|
+
data,
|
|
141
|
+
x,
|
|
142
|
+
series,
|
|
143
|
+
up,
|
|
144
|
+
down,
|
|
145
|
+
upFraction = DEFAULT_UP_FRACTION,
|
|
146
|
+
getAbsentFraction,
|
|
147
|
+
getBarOpacity,
|
|
148
|
+
fold: foldConfig,
|
|
149
|
+
cursorResolution = 'leading',
|
|
150
|
+
absentState,
|
|
151
|
+
...rung
|
|
152
|
+
} = props
|
|
131
153
|
const { formatX } = rung
|
|
132
154
|
|
|
155
|
+
const absentKey = resolveNamedState(
|
|
156
|
+
'MirroredBars',
|
|
157
|
+
'absentState',
|
|
158
|
+
absentState,
|
|
159
|
+
series.map((s) => s.key),
|
|
160
|
+
)
|
|
133
161
|
const bars = useMemo<ChartSeries<T>[]>(
|
|
134
|
-
() =>
|
|
135
|
-
|
|
162
|
+
() =>
|
|
163
|
+
series.map((s) => ({
|
|
164
|
+
...s,
|
|
165
|
+
mark: 'bar' as const,
|
|
166
|
+
// A pane draws at full colour, so its swatch must not claim an opacity the plot lacks.
|
|
167
|
+
...(s.key !== absentKey && { fillOpacity: undefined }),
|
|
168
|
+
})),
|
|
169
|
+
[series, absentKey],
|
|
136
170
|
)
|
|
171
|
+
const absentEntry = bars.find((s) => s.key === absentKey)
|
|
137
172
|
|
|
138
173
|
const plan = useCallback(
|
|
139
174
|
({ hidden, highlighted, width }: PanelInput): PanelPlan<T> => {
|
|
@@ -148,6 +183,12 @@ export function MirroredBars<T, X extends ChartX = ChartX>(
|
|
|
148
183
|
: data
|
|
149
184
|
const model = xScaleFor<X>(drawn.map(x), true)
|
|
150
185
|
const visible = visibleSeries(bars, hidden)
|
|
186
|
+
// A legend-hidden absent entry gives its share back to the measured bar, as `BandStrip`
|
|
187
|
+
// does; with no entry the share is always drawn, flat neutral.
|
|
188
|
+
const absentOn = !absentEntry || visible.includes(absentEntry)
|
|
189
|
+
const absentFill = absentEntry
|
|
190
|
+
? alpha(absentEntry.color, absentEntry.fillOpacity ?? 1)
|
|
191
|
+
: VX.neutral
|
|
151
192
|
const upOn = visible.includes(upSeries)
|
|
152
193
|
const downOn = visible.includes(downSeries)
|
|
153
194
|
const format = (v: ChartValue): string => (formatX ? formatX(v as X) : defaultFormatX(v))
|
|
@@ -176,7 +217,7 @@ export function MirroredBars<T, X extends ChartX = ChartX>(
|
|
|
176
217
|
// A partly-absent bar is painted by rects on the plot-fraction scale, so its measured share
|
|
177
218
|
// is narrower than its band; the bar itself stays as the (transparent) focus target.
|
|
178
219
|
const left = (row: PlotRow<T, X>): number => (model.fraction(row.x) ?? 0) - bandWidth / 2
|
|
179
|
-
const absent = (d: T): number => clamp01(getAbsentFraction?.(d))
|
|
220
|
+
const absent = (d: T): number => (absentOn ? clamp01(getAbsentFraction?.(d)) : 0)
|
|
180
221
|
const measured = rows.filter(
|
|
181
222
|
(r) => r.y !== null && absent(r.datum) > 0 && absent(r.datum) < 1,
|
|
182
223
|
)
|
|
@@ -233,7 +274,7 @@ export function MirroredBars<T, X extends ChartX = ChartX>(
|
|
|
233
274
|
y1: () => 0,
|
|
234
275
|
y2: () => max,
|
|
235
276
|
xScale: 'zx',
|
|
236
|
-
fill:
|
|
277
|
+
fill: absentFill,
|
|
237
278
|
inset: 0,
|
|
238
279
|
}),
|
|
239
280
|
),
|
|
@@ -282,7 +323,19 @@ export function MirroredBars<T, X extends ChartX = ChartX>(
|
|
|
282
323
|
},
|
|
283
324
|
}
|
|
284
325
|
},
|
|
285
|
-
[
|
|
326
|
+
[
|
|
327
|
+
data,
|
|
328
|
+
x,
|
|
329
|
+
bars,
|
|
330
|
+
up,
|
|
331
|
+
down,
|
|
332
|
+
upFraction,
|
|
333
|
+
getAbsentFraction,
|
|
334
|
+
getBarOpacity,
|
|
335
|
+
foldConfig,
|
|
336
|
+
formatX,
|
|
337
|
+
absentEntry,
|
|
338
|
+
],
|
|
286
339
|
)
|
|
287
340
|
|
|
288
341
|
return (
|
package/src/charts/band-fold.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { oneOf } from '../common/errors'
|
|
2
|
+
|
|
1
3
|
/** A run of adjacent slots drawn as one band; `items` are the source data it stands for. */
|
|
2
4
|
export type Group<T> = { start: number; items: T[] }
|
|
3
5
|
|
|
@@ -24,3 +26,22 @@ export function foldBands<T>(data: readonly T[], cap: number, merge: (group: T[]
|
|
|
24
26
|
if (data.length <= cap) return [...data]
|
|
25
27
|
return groupsOf(data, cap).map((g) => merge(g.items))
|
|
26
28
|
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Resolves a prop that names a `series` / `states` key (`absentState`): the key when it names an
|
|
32
|
+
* entry, `undefined` when it is unset. A key naming nothing throws in dev, naming the valid set;
|
|
33
|
+
* in production the chart degrades to the unset behaviour.
|
|
34
|
+
*/
|
|
35
|
+
export function resolveNamedState<K extends string>(
|
|
36
|
+
component: string,
|
|
37
|
+
prop: string,
|
|
38
|
+
requested: K | undefined,
|
|
39
|
+
known: readonly string[],
|
|
40
|
+
): K | undefined {
|
|
41
|
+
if (requested === undefined) return undefined
|
|
42
|
+
if (known.includes(requested)) return requested
|
|
43
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
44
|
+
throw new Error(oneOf(component, prop, [...known], requested))
|
|
45
|
+
}
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
package/src/charts/legend.tsx
CHANGED
|
@@ -58,6 +58,21 @@ const autoRowStyle: LegendVars = {
|
|
|
58
58
|
'--bc-legend-gap': `${VX.legendGap}px`,
|
|
59
59
|
'--bc-dots-gap': `${DOTS_GAP}px`,
|
|
60
60
|
}
|
|
61
|
+
/** The row's layout; a concealed legend keeps it (and so its height) but is not visible. */
|
|
62
|
+
function rowLayout(mode: LegendMode, concealed: boolean): CSSProperties {
|
|
63
|
+
// Hidden, not removed: the data arriving must not shift the chart below it.
|
|
64
|
+
const hide: CSSProperties = concealed ? { visibility: 'hidden' } : {}
|
|
65
|
+
// `display` and the gaps are the stylesheet's in `auto`: the container picks them by width.
|
|
66
|
+
if (mode === 'auto') return { ...autoRowStyle, ...hide }
|
|
67
|
+
const gap = mode === 'dots' ? DOTS_GAP : VX.legendGap
|
|
68
|
+
return {
|
|
69
|
+
...rowStyle,
|
|
70
|
+
columnGap: gap,
|
|
71
|
+
// Caps each entry's `[data-basalt-hit]` overlay at the real gap between entries.
|
|
72
|
+
...({ '--vx-hit-gap': `${gap}px` } as CSSProperties),
|
|
73
|
+
...hide,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
61
76
|
const dividerStyle: CSSProperties = { width: 1, alignSelf: 'stretch', background: VX.divider }
|
|
62
77
|
const buttonStyle: CSSProperties = {
|
|
63
78
|
all: 'unset',
|
|
@@ -155,29 +170,23 @@ export type ChartLegendProps<T> = {
|
|
|
155
170
|
toggle: boolean
|
|
156
171
|
onToggle: (key: string) => void
|
|
157
172
|
onHighlight: (key: string | null) => void
|
|
173
|
+
/** Keeps the legend's box but shows and offers nothing: a chart with no marks names no series. */
|
|
174
|
+
concealed?: boolean
|
|
158
175
|
}
|
|
159
176
|
|
|
160
177
|
export function ChartLegend<T>(props: ChartLegendProps<T>): ReactElement | null {
|
|
161
178
|
const groups = legendEntries(props.series, props.groups)
|
|
162
179
|
if (groups.length === 0) return null
|
|
163
180
|
const auto = props.mode === 'auto'
|
|
164
|
-
const gap = props.mode === 'dots' ? DOTS_GAP : VX.legendGap
|
|
165
181
|
return (
|
|
166
182
|
<fieldset
|
|
167
183
|
aria-label="Legend"
|
|
168
184
|
data-basalt-chart-legend={props.mode}
|
|
185
|
+
// `visibility: hidden` is the real guard (nothing is announced, focused or clickable);
|
|
186
|
+
// `aria-hidden` is belt-and-braces for a tree that ignores computed visibility.
|
|
187
|
+
{...(props.concealed && { 'aria-hidden': true })}
|
|
169
188
|
{...(auto && { className: classes.auto })}
|
|
170
|
-
style={
|
|
171
|
-
auto
|
|
172
|
-
? // `display` and the gaps are the stylesheet's: the container picks them by width.
|
|
173
|
-
autoRowStyle
|
|
174
|
-
: {
|
|
175
|
-
...rowStyle,
|
|
176
|
-
columnGap: gap,
|
|
177
|
-
// Caps each entry's `[data-basalt-hit]` overlay at the real gap between entries.
|
|
178
|
-
...({ '--vx-hit-gap': `${gap}px` } as CSSProperties),
|
|
179
|
-
}
|
|
180
|
-
}
|
|
189
|
+
style={rowLayout(props.mode, props.concealed === true)}
|
|
181
190
|
>
|
|
182
191
|
{groups.map((group, gi) => [
|
|
183
192
|
gi > 0 && <span key={`divider-${gi}`} aria-hidden style={dividerStyle} />,
|
package/src/charts/types.ts
CHANGED
|
@@ -275,7 +275,13 @@ export type CartesianChartProps<T, X extends ChartX = ChartX> = BasaltProps & {
|
|
|
275
275
|
refLines?: readonly RefLine[] | undefined
|
|
276
276
|
/** `false` hides the legend. */
|
|
277
277
|
legend?: ChartLegendConfig | false | undefined
|
|
278
|
-
/**
|
|
278
|
+
/**
|
|
279
|
+
* Default: the height law (measured width × class ratio, 160–420px, ≤ 45vh on touch). Always the
|
|
280
|
+
* FRAME, in every kind: the plot plus the axis the engine measures. A `BandStrip` band is the
|
|
281
|
+
* frame less the x axis (about 21 px at the default font and density, so `height: 65` for a
|
|
282
|
+
* 44 px band). There is no separate plot height: the box is CSS-owned before any measurement
|
|
283
|
+
* exists, and a plot height would add a guess to it.
|
|
284
|
+
*/
|
|
279
285
|
height?: number | ResponsiveChartHeight | undefined
|
|
280
286
|
state?: ChartState | undefined
|
|
281
287
|
/** Joins a named cursor group instead of the page-shared default. */
|
package/src/cli/config.ts
CHANGED
|
@@ -14,6 +14,14 @@ export type BasaltConfig = {
|
|
|
14
14
|
* { app: 'apps/dashboard' }
|
|
15
15
|
*/
|
|
16
16
|
app?: string
|
|
17
|
+
/**
|
|
18
|
+
* Declares the app renders no `BasaltShell` (a one-page app on `BasaltProvider` + `PageBar`).
|
|
19
|
+
* `false` stops `init`/`sync` placing the nav and root-route seeds — they are a pair, the root
|
|
20
|
+
* route imports the nav module — and retires their manifest entries. Default: `true`. Declared,
|
|
21
|
+
* never inferred: a heuristic over the app's imports mis-reads aliased and deeply nested shells.
|
|
22
|
+
* `doctor` warns when `false` is declared and the entry's imports render `<BasaltShell`.
|
|
23
|
+
*/
|
|
24
|
+
shell?: boolean
|
|
17
25
|
/** Source roots to scan. Default: `['src']`. Set explicitly for a monorepo layout. */
|
|
18
26
|
roots?: string[]
|
|
19
27
|
/** Files exempt from the scan (they ARE the palette source). Default: argo's exempt set. */
|
|
@@ -189,9 +197,17 @@ export function resolveRoots(cfg: BasaltConfig): string[] {
|
|
|
189
197
|
return cfg.roots?.length ? cfg.roots : DEFAULT_ROOTS
|
|
190
198
|
}
|
|
191
199
|
|
|
200
|
+
/** A clear message when `basalt.shell` is set to something other than a boolean, else null. */
|
|
201
|
+
export function shellConfigError(cfg: BasaltConfig): string | null {
|
|
202
|
+
const shell: unknown = cfg.shell
|
|
203
|
+
return shell === undefined || typeof shell === 'boolean'
|
|
204
|
+
? null
|
|
205
|
+
: `basalt.shell must be a boolean (true | false), got ${JSON.stringify(shell)}.`
|
|
206
|
+
}
|
|
207
|
+
|
|
192
208
|
/** Every `BasaltConfig` key, as data for `doctor`'s `config-keys` (a test pins it to the type). */
|
|
193
209
|
export const BASALT_CONFIG_KEYS = (
|
|
194
|
-
'app roots exempt profile include spacingSteps severity forbiddenAccents accentHue rawRadius rawSurface ' +
|
|
210
|
+
'app shell roots exempt profile include spacingSteps severity forbiddenAccents accentHue rawRadius rawSurface ' +
|
|
195
211
|
'cardWithBorder offSystemSurfaceVar mantineShadeIndex rawHtmlLayout inlineSpacing inlineDisplay ' +
|
|
196
212
|
'rawMotionValue rawFormControl sub16InputFont seriesModulePath exemptRules aiMajorSkewReason'
|
|
197
213
|
).split(' ') as (keyof BasaltConfig)[]
|
|
@@ -6,12 +6,13 @@ import { writeFileSync } from 'node:fs'
|
|
|
6
6
|
import { createRequire } from 'node:module'
|
|
7
7
|
import { dirname, relative, resolve } from 'node:path'
|
|
8
8
|
|
|
9
|
-
import { BASALT_CONFIG_KEYS, RETIRED_CONFIG_KEYS } from './config'
|
|
9
|
+
import { BASALT_CONFIG_KEYS, RETIRED_CONFIG_KEYS, shellConfigError } from './config'
|
|
10
10
|
import type { BasaltConfig } from './config'
|
|
11
11
|
import { parseJsonc, routerSeedDest, scannableFiles } from './index'
|
|
12
12
|
import type { BasaltInstall } from './index'
|
|
13
13
|
import {
|
|
14
14
|
appEntry,
|
|
15
|
+
callsIn,
|
|
15
16
|
hasRouteTree,
|
|
16
17
|
hasRouter,
|
|
17
18
|
isCodeRoutedApp,
|
|
@@ -451,6 +452,27 @@ export function startWiringWarnings(cwd: string): string[] {
|
|
|
451
452
|
return out
|
|
452
453
|
}
|
|
453
454
|
|
|
455
|
+
const BASALT_SHELL_TAG = /<BasaltShell\b/g
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* `basalt.shell: false` is a declaration, never a heuristic — but a declaration can go stale: warn
|
|
459
|
+
* when a module reachable from the entry renders `<BasaltShell` (JSX open tag, outside literals),
|
|
460
|
+
* and fail on a non-boolean value. Empty when `shell` is not `false`.
|
|
461
|
+
*/
|
|
462
|
+
export function shellDeclarationFindings(
|
|
463
|
+
cwd: string,
|
|
464
|
+
cfg: BasaltConfig,
|
|
465
|
+
): { fail: string | null; warnings: string[] } {
|
|
466
|
+
const fail = shellConfigError(cfg)
|
|
467
|
+
if (cfg.shell !== false || !callsIn(cwd, appEntry(cwd), BASALT_SHELL_TAG)) {
|
|
468
|
+
return { fail, warnings: [] }
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
fail,
|
|
472
|
+
warnings: ['declared basalt.shell: false but the app renders BasaltShell — drop the key.'],
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
454
476
|
/**
|
|
455
477
|
* `app-wiring`: the entry module `index.html` loads (default src/main.tsx) mounts `BasaltProvider`
|
|
456
478
|
* on a `createBasaltRouter` router (called in the entry or a module it imports), and the router tree
|
package/src/cli/doctor.ts
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
import { resolveRoots } from './config'
|
|
38
38
|
import {
|
|
39
39
|
appWiringCheck,
|
|
40
|
+
shellDeclarationFindings,
|
|
40
41
|
startWiringWarnings,
|
|
41
42
|
droppedSubpathsCheck,
|
|
42
43
|
exactPeersCheck,
|
|
@@ -414,6 +415,9 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
414
415
|
],
|
|
415
416
|
])
|
|
416
417
|
for (const line of startWiringWarnings(appDir)) warn(line)
|
|
418
|
+
const shell = shellDeclarationFindings(appDir, cfg)
|
|
419
|
+
if (shell.fail !== null) fail(shell.fail)
|
|
420
|
+
for (const line of shell.warnings) warn(line)
|
|
417
421
|
}
|
|
418
422
|
|
|
419
423
|
// ── Report ──────────────────────────────────────────────────────────────────
|
package/src/cli/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ import { guardHook } from './guard-hook'
|
|
|
29
29
|
import { COMMAND_OPTIONS, USAGE, unknownFlag } from './help'
|
|
30
30
|
import { init } from './init'
|
|
31
31
|
import { sync } from './sync'
|
|
32
|
-
import { CODE_ROUTED_NOTE, routerSeedSkip } from './router-wiring'
|
|
32
|
+
import { CODE_ROUTED_NOTE, SHELL_LESS_NOTE, routerSeedSkip } from './router-wiring'
|
|
33
33
|
import type { RouterSeedSkip } from './router-wiring'
|
|
34
34
|
import { hasDependency, readIfExists, readPackageJson } from './source-text'
|
|
35
35
|
import { fontsCss, normalizeColorFunctions, tokensCss } from './tokens-css'
|
|
@@ -666,21 +666,25 @@ export const START_APP_NOTE =
|
|
|
666
666
|
'<BasaltProvider><Outlet /></BasaltProvider> in your root route component.'
|
|
667
667
|
|
|
668
668
|
/**
|
|
669
|
-
* The router seeds an app does not get, for `init` and `sync`: why (`start` | `code-routed` |
|
|
670
|
-
* and which dests. A tokens-only consumer gets none of them either
|
|
669
|
+
* The router seeds an app does not get, for `init` and `sync`: why (`start` | `code-routed` |
|
|
670
|
+
* `shell-less` | null) and which dests. A tokens-only consumer gets none of them either; so does an
|
|
671
|
+
* app that declares `basalt.shell: false` — the nav and root seeds are a pair, so the whole set goes.
|
|
671
672
|
*/
|
|
672
673
|
export function routerSeedPlan(
|
|
673
674
|
cwd: string,
|
|
674
675
|
appRel: string,
|
|
675
676
|
tokensOnly = false,
|
|
676
677
|
): { skip: RouterSeedSkip; skipped: Set<string> } {
|
|
677
|
-
const
|
|
678
|
+
const detected = tokensOnly ? null : routerSeedSkip(cwd, appRel)
|
|
679
|
+
const skip =
|
|
680
|
+
detected ?? (!tokensOnly && readBasaltConfig(cwd).shell === false ? 'shell-less' : null)
|
|
678
681
|
return { skip, skipped: new Set(tokensOnly || skip !== null ? routerSeedDests(appRel) : []) }
|
|
679
682
|
}
|
|
680
683
|
|
|
681
684
|
/** The note `init` prints for a router-seed skip, or null when nothing was skipped. */
|
|
682
685
|
export function seedSkipNote(skip: RouterSeedSkip): string | null {
|
|
683
686
|
if (skip === 'start') return START_APP_NOTE
|
|
687
|
+
if (skip === 'shell-less') return SHELL_LESS_NOTE
|
|
684
688
|
return skip === 'code-routed' ? CODE_ROUTED_NOTE : null
|
|
685
689
|
}
|
|
686
690
|
|
package/src/cli/init.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { existsSync } from 'node:fs'
|
|
|
7
7
|
import { resolve } from 'node:path'
|
|
8
8
|
|
|
9
9
|
import { deriveSpacing } from '../tokens/core'
|
|
10
|
+
import { shellConfigError } from './config'
|
|
10
11
|
import type { MergeLintResult, ScaffoldFlags } from './index'
|
|
11
12
|
import {
|
|
12
13
|
MANIFEST_PATH,
|
|
@@ -83,6 +84,12 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
|
|
|
83
84
|
)
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
const shellError = shellConfigError(readBasaltConfig(cwd))
|
|
88
|
+
if (shellError !== null) {
|
|
89
|
+
console.error(`✖ basalt-ui init: ${shellError}`)
|
|
90
|
+
return 1
|
|
91
|
+
}
|
|
92
|
+
|
|
86
93
|
const appError = resolvePlacement(cwd).appError
|
|
87
94
|
if (appError !== null) {
|
|
88
95
|
console.error(`✖ basalt-ui init: ${appError}`)
|
package/src/cli/router-wiring.ts
CHANGED
|
@@ -170,16 +170,20 @@ export function isStartApp(cwd: string, appRel: string): boolean {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
/** Why an app's router seeds are not placed (see `routerSeedSkip`). */
|
|
173
|
-
export type RouterSeedSkip = 'start' | 'code-routed' | null
|
|
173
|
+
export type RouterSeedSkip = 'start' | 'code-routed' | 'shell-less' | null
|
|
174
174
|
|
|
175
175
|
export const CODE_ROUTED_NOTE =
|
|
176
176
|
'code-routed app (createBasaltRouter, no route-tree plugin or routeTree.gen) — no main.tsx/nav.tsx/__root.tsx seeded.'
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
179
|
* Why an app's router seeds (main/nav/__root) are not placed: `start` (Start owns the router, and
|
|
180
|
-
* wins when both apply) or `code-routed` (no generated tree to assume); null when they are.
|
|
180
|
+
* wins when both apply) or `code-routed` (no generated tree to assume); null when they are. The
|
|
181
|
+
* declared `shell: false` (`shell-less`) is applied by `routerSeedPlan`, which reads the config.
|
|
181
182
|
*/
|
|
182
183
|
export function routerSeedSkip(cwd: string, appRel: string): RouterSeedSkip {
|
|
183
184
|
if (isStartApp(cwd, appRel)) return 'start'
|
|
184
185
|
return isCodeRoutedApp(cwd, appRel) ? 'code-routed' : null
|
|
185
186
|
}
|
|
187
|
+
|
|
188
|
+
export const SHELL_LESS_NOTE =
|
|
189
|
+
'`basalt.shell: false` — no main.tsx/nav.tsx/__root.tsx seeded; the app owns its root route (or has none).'
|
package/src/cli/sync.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { existsSync } from 'node:fs'
|
|
|
3
3
|
import { resolve } from 'node:path'
|
|
4
4
|
|
|
5
5
|
import { deriveSpacing } from '../tokens/core'
|
|
6
|
+
import { shellConfigError } from './config'
|
|
6
7
|
import {
|
|
7
8
|
MANIFEST_PATH,
|
|
8
9
|
basaltPresetEntry,
|
|
@@ -100,6 +101,12 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
100
101
|
return 0
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
const shellError = shellConfigError(readBasaltConfig(cwd))
|
|
105
|
+
if (shellError !== null) {
|
|
106
|
+
console.error(`✖ basalt-ui sync: ${shellError}`)
|
|
107
|
+
return 1
|
|
108
|
+
}
|
|
109
|
+
|
|
103
110
|
const appError = resolvePlacement(cwd).appError
|
|
104
111
|
if (appError !== null) {
|
|
105
112
|
console.error(`✖ basalt-ui sync: ${appError}`)
|
|
@@ -200,13 +207,20 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
200
207
|
})
|
|
201
208
|
staleForCheck += pruned.removed.length + pruned.drifted.length
|
|
202
209
|
|
|
203
|
-
// A code-routed app takes no router seeds: their manifest entries go
|
|
210
|
+
// A code-routed or declared shell-less app takes no router seeds: their manifest entries go
|
|
211
|
+
// (so the next sync does not resurrect them); any file stays the consumer's.
|
|
204
212
|
const isTracked = (d: string): boolean => manifest.files[d] !== undefined
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
213
|
+
const retiredBecause =
|
|
214
|
+
seedSkip === 'code-routed'
|
|
215
|
+
? 'code-routed app'
|
|
216
|
+
: seedSkip === 'shell-less'
|
|
217
|
+
? 'basalt.shell: false'
|
|
218
|
+
: null
|
|
219
|
+
const retiredSeeds = retiredBecause === null ? [] : [...skipped].filter(isTracked)
|
|
220
|
+
if (retiredSeeds.length > 0 && !opts.check) {
|
|
221
|
+
for (const d of retiredSeeds) delete manifest.files[d]
|
|
208
222
|
console.error(
|
|
209
|
-
`⚠ basalt-ui sync:
|
|
223
|
+
`⚠ basalt-ui sync: ${retiredBecause} — dropped ${retiredSeeds.join(', ')} from the manifest (any file is yours).`,
|
|
210
224
|
)
|
|
211
225
|
}
|
|
212
226
|
|
|
@@ -65,6 +65,9 @@ export type EnumFilterProps<T extends string> = BasaltProps & {
|
|
|
65
65
|
* into, and `exactOptionalPropertyTypes` rejects a possibly-undefined member on a bare optional.
|
|
66
66
|
*/
|
|
67
67
|
readonly options?: readonly FilterOption[] | undefined
|
|
68
|
+
/** Pill text for a value no rendered option matches, ahead of `label` — the name `.labels()` gave
|
|
69
|
+
* an unset state that is deliberately not a row (`NumberFilter`'s preset form). */
|
|
70
|
+
readonly unmatchedLabel?: string | undefined
|
|
68
71
|
/**
|
|
69
72
|
* Mono pill label — forwarded to `FilterPill.numeric`. Set by `NumberFilter`, whose values ARE
|
|
70
73
|
* numbers (`1` / `2` / `7`), and by nothing else: the same law `[data-numeric]` applies to a
|
|
@@ -80,6 +83,7 @@ export function EnumFilter<T extends string>({
|
|
|
80
83
|
clearable,
|
|
81
84
|
numeric,
|
|
82
85
|
options: optionsProp,
|
|
86
|
+
unmatchedLabel,
|
|
83
87
|
className,
|
|
84
88
|
style,
|
|
85
89
|
}: EnumFilterProps<T>): ReactNode {
|
|
@@ -163,7 +167,7 @@ export function EnumFilter<T extends string>({
|
|
|
163
167
|
|
|
164
168
|
return (
|
|
165
169
|
<FilterPill
|
|
166
|
-
label={selected?.label ?? label}
|
|
170
|
+
label={selected?.label ?? unmatchedLabel ?? label}
|
|
167
171
|
active={!isDefault}
|
|
168
172
|
{...(numeric === true && { numeric: true })}
|
|
169
173
|
{...(icon !== undefined && { icon })}
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
*
|
|
59
59
|
* @example
|
|
60
60
|
* // "No filter" is the fallback, not a row: `clearable` writes it back, and the pill reads the
|
|
61
|
-
* // filter's name while no preset is picked
|
|
61
|
+
* // filter's name while no preset is picked — or the name `.labels({ difficulty: { 0: 'Any' } })`
|
|
62
|
+
* // gave the fallback, in this form as in the stepper's.
|
|
62
63
|
* // difficulty: field.number({ fallback: 0, min: 0, max: 5, int: true })
|
|
63
64
|
* <NumberFilter field={library.field.difficulty} label="Difficulty" options={LEVELS} clearable />
|
|
64
65
|
*/
|
|
@@ -176,6 +177,9 @@ function NumberChoice({
|
|
|
176
177
|
}): ReactNode {
|
|
177
178
|
const [value, setValue] = field.use()
|
|
178
179
|
const rows = options.map((option) => ({ value: String(option.value), label: option.label }))
|
|
180
|
+
// The same `.labels()` naming the stepper pill reads: a value it names (`{ 0: 'Any' }`) prints
|
|
181
|
+
// that name though it is not a row, so "no filter" needs no literal `Any` option.
|
|
182
|
+
const named = field.options.find((option) => option.value === String(value))?.label
|
|
179
183
|
const choice: ChoiceHandle<string> = {
|
|
180
184
|
fallback: String(field.fallback),
|
|
181
185
|
options: rows,
|
|
@@ -201,6 +205,7 @@ function NumberChoice({
|
|
|
201
205
|
label={label}
|
|
202
206
|
numeric
|
|
203
207
|
options={rows}
|
|
208
|
+
{...(named !== undefined && { unmatchedLabel: named })}
|
|
204
209
|
{...(clearable === true && { clearable: true })}
|
|
205
210
|
{...(icon !== undefined && { icon })}
|
|
206
211
|
{...(className !== undefined && { className })}
|