basalt-ui 2.7.2 → 2.8.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/AGENTS.md +1 -1
- package/CHANGELOG.md +33 -0
- package/MIGRATING.md +101 -15
- package/agent/rules/basalt-batteries.md +1 -1
- package/agent/rules/basalt-controls.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/skills/basalt-app/SKILL.md +7 -7
- package/agent/templates/AGENTS-block.md.tpl +1 -1
- package/dist/charts/BandStrip.d.ts +13 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +142 -44
- 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 +122 -10
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +4 -0
- package/dist/cli/help.js +1 -1
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +12 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +7 -4
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +27 -2
- package/dist/content/toc.d.ts +5 -0
- package/dist/content/toc.d.ts.map +1 -1
- package/dist/provider/index.d.ts +22 -4
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +21 -6
- package/dist/provider/test-router.d.ts +2 -1
- package/dist/provider/test-router.d.ts.map +1 -1
- package/dist/provider/test-router.js +6 -7
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.js +1 -1
- package/llms.txt +36 -4
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +223 -48
- package/src/cli/doctor-upgrade.ts +171 -15
- package/src/cli/doctor.ts +4 -0
- package/src/cli/help.ts +1 -1
- package/src/cli/index.ts +16 -0
- package/src/cli/init.ts +7 -6
- package/src/cli/sync.ts +29 -2
- package/src/content/toc.tsx +5 -0
- package/src/provider/index.tsx +65 -15
- package/src/provider/test-router.tsx +9 -9
- package/src/surfaces.ts +1 -1
package/src/charts/BandStrip.tsx
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* `BandStrip` — a 1-D state strip: one gap-free band per slot over the shared x axis, no y
|
|
3
3
|
* dimension (`docs/V2-SPEC.md` § 9.3). Each band is in one of the `states`, tinted by the state's
|
|
4
4
|
* color (or an intensity `fill` of the datum's own), optionally carrying an inset `marker`.
|
|
5
|
-
* Absence is a state like any other: color it `VX.neutral` for a flat, unhatched fill.
|
|
5
|
+
* Absence is a state like any other: color it `VX.neutral` for a flat, unhatched fill. Name it
|
|
6
|
+
* with `absentState` and a folded band can carry an `absentFraction` share of it.
|
|
6
7
|
*
|
|
7
8
|
* The rung supplies the legend, cursor, crosshair and tooltip. The visible bands are decorative
|
|
8
9
|
* rects on the rung's `[0, 1]` zone scale (a band scale pads its slots, a strip must not), and an
|
|
@@ -14,7 +15,7 @@ import { decorative } from '@tanstack/charts/mark/decorative'
|
|
|
14
15
|
import { rect } from '@tanstack/charts/rect'
|
|
15
16
|
import { useCallback, useMemo } from 'react'
|
|
16
17
|
import type { ReactElement } from 'react'
|
|
17
|
-
import { oneOf } from '../common/errors'
|
|
18
|
+
import { oneOf, requiredProp } from '../common/errors'
|
|
18
19
|
import { NON_FINITE } from '../format/shared'
|
|
19
20
|
import { VX, alpha } from '../tokens'
|
|
20
21
|
import { CartesianRung } from './CartesianChart'
|
|
@@ -48,6 +49,12 @@ export type BandSpan = {
|
|
|
48
49
|
state: string
|
|
49
50
|
/** Overrides the state's fill — an intensity ramp WITHIN a state. `alpha(VX.*, …)`, never a hex. */
|
|
50
51
|
fill?: string | undefined
|
|
52
|
+
/**
|
|
53
|
+
* 0..1 of the band's width that no source sample covers, painted from its right edge in the
|
|
54
|
+
* `absentState` color. A fold owes the reader this: a band whose merge reports the one measured
|
|
55
|
+
* member of three would otherwise read as fully measured. Needs `absentState` on the strip.
|
|
56
|
+
*/
|
|
57
|
+
absentFraction?: number | undefined
|
|
51
58
|
/**
|
|
52
59
|
* A shorter, inset bar over the band, for a fact that must not be read off the fill ramp (a
|
|
53
60
|
* renegotiation, a restart). Its color is a `states` entry, so the legend names it.
|
|
@@ -82,6 +89,13 @@ export type BandStripProps<T, X extends ChartX = ChartX> = Omit<
|
|
|
82
89
|
/** Which state, fill and marker each datum has. Memoize it: a new function recompiles the chart. */
|
|
83
90
|
getBand: (d: T) => BandSpan
|
|
84
91
|
fold?: BandFold<T> | undefined
|
|
92
|
+
/**
|
|
93
|
+
* The `states` key that means "not measured". A band in it is flat-filled like any state; a
|
|
94
|
+
* band in another state paints its `absentFraction` share in this state's color, and the
|
|
95
|
+
* tooltip adds this state's row. Absent stays a legended, flat `VX.neutral` state, never a
|
|
96
|
+
* hatch: it reads as "no data" by hue and by sitting at the band's right edge, not as zero.
|
|
97
|
+
*/
|
|
98
|
+
absentState?: string | undefined
|
|
85
99
|
}
|
|
86
100
|
|
|
87
101
|
const DEFAULT_MIN_BAND_PX = 3
|
|
@@ -106,7 +120,7 @@ type Layer = { fill: string; opacity: number; cells: Cell[] }
|
|
|
106
120
|
/** A run of adjacent slots drawn as one band; `items` are the source data it stands for. */
|
|
107
121
|
type Group<T> = { start: number; items: T[] }
|
|
108
122
|
/** A slot that answers the pointer: its own source datum, and the (possibly merged) one it reads. */
|
|
109
|
-
type Hit<T> = { source: T; state: string; datum: T }
|
|
123
|
+
type Hit<T> = { slot: number; source: T; state: string; datum: T }
|
|
110
124
|
|
|
111
125
|
/** Adjacent data in groups of equal size, the last possibly shorter, at most `cap` groups. */
|
|
112
126
|
function groupsOf<T>(data: readonly T[], cap: number): Group<T>[] {
|
|
@@ -132,6 +146,7 @@ type LayoutInput<T> = {
|
|
|
132
146
|
data: readonly T[]
|
|
133
147
|
getBand: (d: T) => BandSpan
|
|
134
148
|
fold: BandFold<T> | undefined
|
|
149
|
+
absentState: string | undefined
|
|
135
150
|
states: ReadonlyMap<string, BandStripSeries<T>>
|
|
136
151
|
/** State keys the legend has not toggled off. */
|
|
137
152
|
visible: ReadonlySet<string>
|
|
@@ -141,9 +156,113 @@ type LayoutInput<T> = {
|
|
|
141
156
|
emphasis: (key: string) => number
|
|
142
157
|
}
|
|
143
158
|
|
|
159
|
+
/** NaN and out-of-range fractions (a 0/0 on an un-folded slot) must not reach an SVG attribute. */
|
|
160
|
+
const clampFraction = (f: number | undefined): number =>
|
|
161
|
+
f === undefined || Number.isNaN(f) ? 0 : Math.min(1, Math.max(0, f))
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The share of a band the strip's absent state owns. A band already in that state is absent in
|
|
165
|
+
* whole, so the fraction only qualifies the others.
|
|
166
|
+
*/
|
|
167
|
+
function absentShareOf(span: BandSpan, absentKey: string | undefined): number {
|
|
168
|
+
return absentKey === undefined || span.state === absentKey
|
|
169
|
+
? 0
|
|
170
|
+
: clampFraction(span.absentFraction)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The one visibility-aware split that paint, hits and the tooltip all read: the absent share that
|
|
175
|
+
* is drawn (a hidden absent state gives its share back to the primary part) and whether the
|
|
176
|
+
* primary part is drawn (a hidden primary state leaves its part unpainted, the absent part
|
|
177
|
+
* untouched). `isVisible` is the legend's test, in whichever form the caller holds it.
|
|
178
|
+
*/
|
|
179
|
+
function resolveAbsent(
|
|
180
|
+
span: BandSpan,
|
|
181
|
+
absentKey: string | undefined,
|
|
182
|
+
isVisible: (key: string) => boolean,
|
|
183
|
+
): { share: number; primaryShown: boolean } {
|
|
184
|
+
const share = absentKey !== undefined && isVisible(absentKey) ? absentShareOf(span, absentKey) : 0
|
|
185
|
+
return { share, primaryShown: share < 1 && isVisible(span.state) }
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** A state's tooltip value: its own reading, an em dash for `null`, empty when the name says it all. */
|
|
189
|
+
const stateValue = <T,>(s: BandStripSeries<T>, d: T): string =>
|
|
190
|
+
s.formatValue ? (s.formatValue(d) ?? NON_FINITE) : ''
|
|
191
|
+
|
|
144
192
|
const unknownState = (prop: string, got: string, known: Iterable<string>): Error =>
|
|
145
193
|
new Error(oneOf('BandStrip', prop, [...known], got))
|
|
146
194
|
|
|
195
|
+
type PaintCtx<T> = {
|
|
196
|
+
base: Map<string, Layer>
|
|
197
|
+
markers: Map<string, Layer>
|
|
198
|
+
states: ReadonlyMap<string, BandStripSeries<T>>
|
|
199
|
+
visible: ReadonlySet<string>
|
|
200
|
+
height: number
|
|
201
|
+
emphasis: (key: string) => number
|
|
202
|
+
/** The strip's absent state, when it names a real entry of `states`. */
|
|
203
|
+
absentKey: string | undefined
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Paints one band: its primary part (when shown), its absent share from the right edge, and its
|
|
208
|
+
* marker over the primary part. Returns which states answer the pointer for the band's slots.
|
|
209
|
+
*/
|
|
210
|
+
function paintSpan<T>(
|
|
211
|
+
ctx: PaintCtx<T>,
|
|
212
|
+
span: BandSpan,
|
|
213
|
+
cell: { f0: number; f1: number },
|
|
214
|
+
): { primary: boolean; absent: boolean } {
|
|
215
|
+
const { states, visible, absentKey } = ctx
|
|
216
|
+
const state = states.get(span.state)
|
|
217
|
+
if (!state && process.env.NODE_ENV !== 'production')
|
|
218
|
+
throw unknownState('BandSpan.state', span.state, states.keys())
|
|
219
|
+
if (
|
|
220
|
+
absentKey === undefined &&
|
|
221
|
+
clampFraction(span.absentFraction) > 0 &&
|
|
222
|
+
process.env.NODE_ENV !== 'production'
|
|
223
|
+
)
|
|
224
|
+
throw new Error(
|
|
225
|
+
requiredProp('BandStrip', 'absentState', 'a BandSpan carries an absentFraction'),
|
|
226
|
+
)
|
|
227
|
+
const { share, primaryShown } = resolveAbsent(span, absentKey, (k) => visible.has(k))
|
|
228
|
+
// An unknown state (production only) has no visibility to toggle: it always paints.
|
|
229
|
+
const primary = state ? primaryShown : share < 1
|
|
230
|
+
const absentStyle = absentKey === undefined ? undefined : states.get(absentKey)
|
|
231
|
+
const split = cell.f1 - (cell.f1 - cell.f0) * share
|
|
232
|
+
if (primary)
|
|
233
|
+
paintInto(
|
|
234
|
+
ctx.base,
|
|
235
|
+
span.fill ?? (state ? alpha(state.color, state.fillOpacity ?? 1) : UNKNOWN_FILL),
|
|
236
|
+
ctx.emphasis(span.state),
|
|
237
|
+
{ ...cell, f1: split, y0: 0, y1: 1 },
|
|
238
|
+
)
|
|
239
|
+
if (share > 0 && absentStyle && absentKey !== undefined)
|
|
240
|
+
paintInto(
|
|
241
|
+
ctx.base,
|
|
242
|
+
alpha(absentStyle.color, absentStyle.fillOpacity ?? 1),
|
|
243
|
+
ctx.emphasis(absentKey),
|
|
244
|
+
{ f0: split, f1: cell.f1, y0: 0, y1: 1 },
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
if (span.marker && primary) {
|
|
248
|
+
const markerKey = span.marker.state ?? span.state
|
|
249
|
+
const markerState = states.get(markerKey)
|
|
250
|
+
if (!markerState && process.env.NODE_ENV !== 'production')
|
|
251
|
+
throw unknownState('BandSpan.marker.state', markerKey, states.keys())
|
|
252
|
+
if (!markerState || visible.has(markerKey)) {
|
|
253
|
+
const inset = (span.marker.inset ?? DEFAULT_MARKER_INSET) / Math.max(ctx.height, 1)
|
|
254
|
+
paintInto(ctx.markers, markerState?.color ?? UNKNOWN_FILL, ctx.emphasis(markerKey), {
|
|
255
|
+
...cell,
|
|
256
|
+
f1: split,
|
|
257
|
+
y0: inset,
|
|
258
|
+
y1: 1 - inset,
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// An unknown state (production only) answers no pointer: a tooltip row needs its series.
|
|
263
|
+
return { primary: primary && state !== undefined, absent: share > 0 }
|
|
264
|
+
}
|
|
265
|
+
|
|
147
266
|
/**
|
|
148
267
|
* Where every band and marker goes, and which slots answer the pointer. Pure: base layers and
|
|
149
268
|
* marker layers come back separately so the caller can paint all markers after all bands (a
|
|
@@ -154,56 +273,59 @@ function layoutBands<T>(input: LayoutInput<T>): {
|
|
|
154
273
|
markers: Layer[]
|
|
155
274
|
hits: Hit<T>[]
|
|
156
275
|
} {
|
|
157
|
-
const { data, getBand, fold,
|
|
276
|
+
const { data, getBand, fold, absentState: absentKey } = input
|
|
158
277
|
const cap = Math.floor(input.width / (fold?.minBandPx ?? DEFAULT_MIN_BAND_PX))
|
|
159
278
|
const groups: Group<T>[] =
|
|
160
279
|
fold && data.length > cap
|
|
161
280
|
? groupsOf(data, cap)
|
|
162
281
|
: data.map((d, start) => ({ start, items: [d] }))
|
|
163
|
-
const
|
|
164
|
-
|
|
282
|
+
const ctx: PaintCtx<T> = {
|
|
283
|
+
base: new Map(),
|
|
284
|
+
markers: new Map(),
|
|
285
|
+
states: input.states,
|
|
286
|
+
visible: input.visible,
|
|
287
|
+
height: input.height,
|
|
288
|
+
emphasis: input.emphasis,
|
|
289
|
+
absentKey,
|
|
290
|
+
}
|
|
165
291
|
const hits: Hit<T>[] = []
|
|
166
292
|
|
|
167
293
|
for (const g of groups) {
|
|
168
294
|
const datum = fold && g.items.length > 1 ? fold.merge(g.items) : g.items[0]
|
|
169
295
|
if (datum === undefined) continue
|
|
170
296
|
const span = getBand(datum)
|
|
171
|
-
const state = states.get(span.state)
|
|
172
|
-
if (!state && process.env.NODE_ENV !== 'production')
|
|
173
|
-
throw unknownState('BandSpan.state', span.state, states.keys())
|
|
174
|
-
if (state && !visible.has(span.state)) continue
|
|
175
297
|
const cell = { f0: g.start / data.length, f1: (g.start + g.items.length) / data.length }
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
if (span.marker) {
|
|
185
|
-
const markerKey = span.marker.state ?? span.state
|
|
186
|
-
const markerState = states.get(markerKey)
|
|
187
|
-
if (!markerState && process.env.NODE_ENV !== 'production')
|
|
188
|
-
throw unknownState('BandSpan.marker.state', markerKey, states.keys())
|
|
189
|
-
if (!markerState || visible.has(markerKey)) {
|
|
190
|
-
const inset = (span.marker.inset ?? DEFAULT_MARKER_INSET) / Math.max(input.height, 1)
|
|
191
|
-
paintInto(markers, markerState?.color ?? UNKNOWN_FILL, input.emphasis(markerKey), {
|
|
192
|
-
...cell,
|
|
193
|
-
y0: inset,
|
|
194
|
-
y1: 1 - inset,
|
|
195
|
-
})
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// An unknown state (production only) answers no pointer: a tooltip row needs its series.
|
|
199
|
-
if (state) for (const source of g.items) hits.push({ source, state: span.state, datum })
|
|
298
|
+
const answers = paintSpan(ctx, span, cell)
|
|
299
|
+
g.items.forEach((source, i) => {
|
|
300
|
+
const slot = g.start + i
|
|
301
|
+
if (answers.primary) hits.push({ slot, source, state: span.state, datum })
|
|
302
|
+
if (answers.absent && absentKey !== undefined)
|
|
303
|
+
hits.push({ slot, source, state: absentKey, datum })
|
|
304
|
+
})
|
|
200
305
|
}
|
|
201
|
-
return { base: [...base.values()], markers: [...markers.values()], hits }
|
|
306
|
+
return { base: [...ctx.base.values()], markers: [...ctx.markers.values()], hits }
|
|
202
307
|
}
|
|
203
308
|
|
|
204
309
|
export function BandStrip<T, X extends ChartX = ChartX>(props: BandStripProps<T, X>): ReactElement {
|
|
205
|
-
const {
|
|
310
|
+
const {
|
|
311
|
+
states,
|
|
312
|
+
getBand,
|
|
313
|
+
fold,
|
|
314
|
+
absentState,
|
|
315
|
+
cursorResolution = 'leading',
|
|
316
|
+
tooltip,
|
|
317
|
+
...rest
|
|
318
|
+
} = props
|
|
206
319
|
const { data, x } = rest
|
|
320
|
+
// Resolved once: a misconfigured absent state degrades to primary-only paint, hits and rows.
|
|
321
|
+
const absentKey =
|
|
322
|
+
absentState !== undefined && states.some((s) => s.key === absentState) ? absentState : undefined
|
|
323
|
+
if (absentState !== undefined && absentKey === undefined && process.env.NODE_ENV !== 'production')
|
|
324
|
+
throw unknownState(
|
|
325
|
+
'BandStrip.absentState',
|
|
326
|
+
absentState,
|
|
327
|
+
states.map((s) => s.key),
|
|
328
|
+
)
|
|
207
329
|
|
|
208
330
|
const series = useMemo<ChartSeries<T>[]>(
|
|
209
331
|
() =>
|
|
@@ -215,10 +337,15 @@ export function BandStrip<T, X extends ChartX = ChartX>(props: BandStripProps<T,
|
|
|
215
337
|
...(s.tooltip !== undefined && { tooltip: s.tooltip }),
|
|
216
338
|
...(s.legend !== undefined && { legend: s.legend }),
|
|
217
339
|
...(s.note !== undefined && { note: s.note }),
|
|
218
|
-
getValue: (d) =>
|
|
219
|
-
|
|
340
|
+
getValue: (d) => {
|
|
341
|
+
const span = getBand(d)
|
|
342
|
+
const share = absentShareOf(span, absentKey)
|
|
343
|
+
if (span.state === s.key) return share < 1 ? 1 : null
|
|
344
|
+
return s.key === absentKey && share > 0 ? 1 : null
|
|
345
|
+
},
|
|
346
|
+
formatValue: (_v, d) => stateValue(s, d),
|
|
220
347
|
})),
|
|
221
|
-
[states, getBand],
|
|
348
|
+
[states, getBand, absentKey],
|
|
222
349
|
)
|
|
223
350
|
|
|
224
351
|
const marks = useCallback(
|
|
@@ -227,18 +354,19 @@ export function BandStrip<T, X extends ChartX = ChartX>(props: BandStripProps<T,
|
|
|
227
354
|
data,
|
|
228
355
|
getBand,
|
|
229
356
|
fold,
|
|
357
|
+
absentState: absentKey,
|
|
230
358
|
states: new Map(states.map((s) => [s.key, s])),
|
|
231
359
|
visible: new Set(plot.visible.map((s) => s.key)),
|
|
232
360
|
width: plot.width,
|
|
233
361
|
height: plot.height,
|
|
234
362
|
emphasis: (key) => emphasis(plot.highlighted, { key }),
|
|
235
363
|
})
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
y: 1,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
})
|
|
364
|
+
const rowKeys = new Map<PlotRow<T, X>, string>()
|
|
365
|
+
const rows: PlotRow<T, X>[] = hits.map((h) => {
|
|
366
|
+
const row = { x: x(h.source), y: 1, series: h.state, datum: h.datum }
|
|
367
|
+
rowKeys.set(row, `${h.slot}|${h.state}`)
|
|
368
|
+
return row
|
|
369
|
+
})
|
|
242
370
|
return [
|
|
243
371
|
...[...base, ...markers].map(({ fill, opacity, cells }, i) =>
|
|
244
372
|
decorative(
|
|
@@ -256,13 +384,60 @@ export function BandStrip<T, X extends ChartX = ChartX>(props: BandStripProps<T,
|
|
|
256
384
|
),
|
|
257
385
|
),
|
|
258
386
|
...(rows.length > 0
|
|
259
|
-
? [
|
|
387
|
+
? [
|
|
388
|
+
barY(rows, {
|
|
389
|
+
id: 'hit',
|
|
390
|
+
// One row per source slot and state, whatever the x values look like.
|
|
391
|
+
key: (r) => rowKeys.get(r) ?? '',
|
|
392
|
+
x: rowX,
|
|
393
|
+
y1: 0,
|
|
394
|
+
y2: 1,
|
|
395
|
+
fill: 'transparent',
|
|
396
|
+
}),
|
|
397
|
+
]
|
|
260
398
|
: []),
|
|
261
399
|
]
|
|
262
400
|
},
|
|
263
|
-
[states, getBand, fold, data, x],
|
|
401
|
+
[states, getBand, fold, absentKey, data, x],
|
|
264
402
|
)
|
|
265
403
|
|
|
404
|
+
// `getValue` cannot see the legend, so a fully absent band has no primary row. When the absent
|
|
405
|
+
// state is hidden the strip paints the primary fill instead, and its row is added back here by
|
|
406
|
+
// the same `resolveAbsent` that paints it.
|
|
407
|
+
const tooltipWithPrimary = useMemo<BandStripProps<T, X>['tooltip']>(() => {
|
|
408
|
+
if (tooltip === false || absentKey === undefined) return tooltip
|
|
409
|
+
return {
|
|
410
|
+
...tooltip,
|
|
411
|
+
rows: (d, ctx) => {
|
|
412
|
+
const span = getBand(d)
|
|
413
|
+
const primary = states.find((s) => s.key === span.state)
|
|
414
|
+
const { primaryShown } = resolveAbsent(span, absentKey, (k) =>
|
|
415
|
+
ctx.visible.some((s) => s.key === k),
|
|
416
|
+
)
|
|
417
|
+
const readdPrimary =
|
|
418
|
+
primary?.tooltip !== false &&
|
|
419
|
+
primary &&
|
|
420
|
+
primaryShown &&
|
|
421
|
+
absentShareOf(span, absentKey) === 1
|
|
422
|
+
return [
|
|
423
|
+
...(readdPrimary
|
|
424
|
+
? [
|
|
425
|
+
{
|
|
426
|
+
label:
|
|
427
|
+
primary.note === undefined
|
|
428
|
+
? primary.label
|
|
429
|
+
: `${primary.label} · ${primary.note}`,
|
|
430
|
+
value: stateValue(primary, d),
|
|
431
|
+
color: primary.color,
|
|
432
|
+
},
|
|
433
|
+
]
|
|
434
|
+
: []),
|
|
435
|
+
...(tooltip?.rows?.(d, ctx) ?? []),
|
|
436
|
+
]
|
|
437
|
+
},
|
|
438
|
+
}
|
|
439
|
+
}, [tooltip, absentKey, getBand, states])
|
|
440
|
+
|
|
266
441
|
return (
|
|
267
442
|
<CartesianRung
|
|
268
443
|
{...rest}
|
|
@@ -272,7 +447,7 @@ export function BandStrip<T, X extends ChartX = ChartX>(props: BandStripProps<T,
|
|
|
272
447
|
y={STRIP_AXIS}
|
|
273
448
|
xZones={ZX_ANCHOR}
|
|
274
449
|
cursorResolution={cursorResolution}
|
|
275
|
-
{...(
|
|
450
|
+
{...(tooltipWithPrimary !== undefined && { tooltip: tooltipWithPrimary })}
|
|
276
451
|
/>
|
|
277
452
|
)
|
|
278
453
|
}
|
|
@@ -8,7 +8,14 @@ import { dirname, relative, resolve } from 'node:path'
|
|
|
8
8
|
|
|
9
9
|
import { BASALT_CONFIG_KEYS, RETIRED_CONFIG_KEYS } from './config'
|
|
10
10
|
import type { BasaltConfig } from './config'
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
isStartApp,
|
|
13
|
+
parseJsonc,
|
|
14
|
+
readIfExists,
|
|
15
|
+
readPackageJson,
|
|
16
|
+
routerSeedDest,
|
|
17
|
+
scannableFiles,
|
|
18
|
+
} from './index'
|
|
12
19
|
import type { BasaltInstall } from './index'
|
|
13
20
|
|
|
14
21
|
export type Check = { fail: string } | { skip: string } | null
|
|
@@ -225,15 +232,46 @@ function basaltImports(src: string): [string, number][] {
|
|
|
225
232
|
.map((m) => [m[2] as string, code.slice(0, m.index + m[0].length).split('\n').length])
|
|
226
233
|
}
|
|
227
234
|
|
|
228
|
-
/**
|
|
235
|
+
/** `@import 'basalt-ui/x'`, `@import "basalt-ui/x"`, `@import url(basalt-ui/x)` in a stylesheet (at-rule position only). */
|
|
236
|
+
const CSS_SUBPATH_IMPORT = /(?:^|[;{}])\s*@import\s+(?:url\(\s*)?(['"]?)basalt-ui\/([^'")\s;]+)\1/g
|
|
237
|
+
|
|
238
|
+
/** `[subpath, line]` per `basalt-ui/<subpath>` `@import` in a stylesheet (comments blanked). */
|
|
239
|
+
function cssImports(src: string): [string, number][] {
|
|
240
|
+
const blank = (m: string): string => m.replace(/[^\n]/g, ' ')
|
|
241
|
+
const code = src
|
|
242
|
+
.replace(/\/\*[\s\S]*?\*\//g, blank)
|
|
243
|
+
// A quoted string that is not an @import/url() target is a value: `content: "a; @import …"`.
|
|
244
|
+
.replace(/(@import\s+|url\(\s*)?(["'])(?:\\.|(?!\2)[^\\\n])*\2/g, (m, target) =>
|
|
245
|
+
target === undefined ? blank(m) : m,
|
|
246
|
+
)
|
|
247
|
+
return [...code.matchAll(CSS_SUBPATH_IMPORT)].map((m) => [
|
|
248
|
+
m[2] as string,
|
|
249
|
+
code.slice(0, m.index + m[0].length).split('\n').length,
|
|
250
|
+
])
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** `[subpath, file, line]` per `basalt-ui/<subpath>` import in the app's source and style files. */
|
|
229
254
|
const appImports = (cwd: string, cfg: BasaltConfig): [string, string, number][] =>
|
|
230
|
-
scannableFiles(cwd, cfg)
|
|
231
|
-
|
|
232
|
-
.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
),
|
|
255
|
+
scannableFiles(cwd, cfg).flatMap((rel) => {
|
|
256
|
+
const isCode = /\.(?:[cm]?[jt]sx?|vue|astro)$/.test(rel)
|
|
257
|
+
if (!isCode && !rel.endsWith('.css')) return []
|
|
258
|
+
const src = readIfExists(resolve(cwd, rel)) ?? ''
|
|
259
|
+
return (isCode ? basaltImports(src) : cssImports(src)).map(
|
|
260
|
+
([sub, line]): [string, string, number] => [sub, rel, line],
|
|
236
261
|
)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
/** Subpaths 2.x removed, checked besides the install's `exports`: a walked-up 1.x install exports them. */
|
|
265
|
+
const DROPPED_FIXES = new Map([
|
|
266
|
+
[
|
|
267
|
+
'tokens.css',
|
|
268
|
+
'commit the emit instead: `basalt-ui tokens:css --out src/tokens.css` and import that file',
|
|
269
|
+
],
|
|
270
|
+
[
|
|
271
|
+
'router-tanstack',
|
|
272
|
+
'nav symbols (`defineNav`, `navTarget`, …) now import from `basalt-ui`, stores (`createSearchStore`, `field`, …) from `basalt-ui/state`',
|
|
273
|
+
],
|
|
274
|
+
])
|
|
237
275
|
|
|
238
276
|
/** `dropped-subpaths`: `basalt-ui/<subpath>` imports the installed `exports` map does not have. */
|
|
239
277
|
export function droppedSubpathsCheck(
|
|
@@ -249,17 +287,51 @@ export function droppedSubpathsCheck(
|
|
|
249
287
|
// No `exports` field means nothing restricts the deep imports.
|
|
250
288
|
if (exportsMap === undefined) return null
|
|
251
289
|
const keys = Object.keys(exportsMap)
|
|
252
|
-
const
|
|
290
|
+
const hasExport = (sub: string): boolean =>
|
|
253
291
|
keys.some(
|
|
254
292
|
(k) => k === `./${sub}` || (k.endsWith('*') && `./${sub}`.startsWith(k.slice(0, -1))),
|
|
255
293
|
)
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
294
|
+
const isDropped = (sub: string): boolean => DROPPED_FIXES.has(sub) || !hasExport(sub)
|
|
295
|
+
const found = appImports(cwd, cfg).filter(([sub]) => isDropped(sub))
|
|
296
|
+
if (found.length === 0) return null
|
|
297
|
+
const hits = found.map(([sub, rel, line]) => `${rel}:${line} imports basalt-ui/${sub}`)
|
|
260
298
|
const more = hits.length > 10 ? ` (+${hits.length - 10} more)` : ''
|
|
299
|
+
const fixes = [...new Set(found.map(([sub]) => sub))].flatMap((sub) => {
|
|
300
|
+
const fix = DROPPED_FIXES.get(sub)
|
|
301
|
+
return fix === undefined ? [] : [`basalt-ui/${sub}: ${fix}`]
|
|
302
|
+
})
|
|
303
|
+
fixes.push("see MIGRATING.md § 2.0 for each subpath's replacement")
|
|
304
|
+
return { fail: `${id}: ${hits.slice(0, 10).join('; ')}${more}. Fix: ${fixes.join('; ')}.` }
|
|
305
|
+
})
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** The oldest oxlint that parses the shipped preset (1.78 lacks `react/globals` and friends). */
|
|
309
|
+
const OXLINT_FLOOR = '1.79.0'
|
|
310
|
+
|
|
311
|
+
const SEMVER = /^(\d+)\.(\d+)\.(\d+)(-[^+]+)?(?:\+.*)?$/
|
|
312
|
+
|
|
313
|
+
/** True when `version` is below `floor`; a prerelease of the floor is below it, build metadata is ignored. */
|
|
314
|
+
function isBelowFloor(version: string, floor: string): boolean {
|
|
315
|
+
const [v, f] = [SEMVER.exec(version), SEMVER.exec(floor)]
|
|
316
|
+
if (v === null || f === null) return false
|
|
317
|
+
for (const i of [1, 2, 3]) {
|
|
318
|
+
if (Number(v[i]) !== Number(f[i])) return Number(v[i]) < Number(f[i])
|
|
319
|
+
}
|
|
320
|
+
return v[4] !== undefined
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* `oxlint-floor`: fails when the nearest installed oxlint is older than {@link OXLINT_FLOOR}, which
|
|
325
|
+
* cannot parse the preset. Reads `cwd`, as `oxlint-preset` does; a missing oxlint is that check's job.
|
|
326
|
+
*/
|
|
327
|
+
export function oxlintFloorCheck(cwd: string): Check {
|
|
328
|
+
const id = 'oxlint-floor'
|
|
329
|
+
return guarded(id, () => {
|
|
330
|
+
if (readIfExists(resolve(cwd, '.oxlintrc.json')) === null) return null
|
|
331
|
+
const version = installedVersion(cwd, 'oxlint')
|
|
332
|
+
if (version === null || !isBelowFloor(version, OXLINT_FLOOR)) return null
|
|
261
333
|
return {
|
|
262
|
-
fail: `${id}: ${
|
|
334
|
+
fail: `${id}: oxlint ${version} is installed, but the shipped preset needs >= ${OXLINT_FLOOR} (older versions reject its react/* rules). Fix: \`bun add -D oxlint@^${OXLINT_FLOOR}\`.`,
|
|
263
335
|
}
|
|
264
336
|
})
|
|
265
337
|
}
|
|
@@ -408,6 +480,89 @@ function routerCreatedInImports(cwd: string, entry: string): boolean {
|
|
|
408
480
|
return false
|
|
409
481
|
}
|
|
410
482
|
|
|
483
|
+
/** True when `{` at `i` opens a `{...spread}`: sticky, so any whitespace width is read. */
|
|
484
|
+
function isSpreadAt(code: string, i: number): boolean {
|
|
485
|
+
const spread = /\{\s*\.\.\./y
|
|
486
|
+
spread.lastIndex = i
|
|
487
|
+
return spread.test(code)
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
type ProviderTag = { attrs: string; spread: boolean }
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Every `<BasaltProvider …>` opening tag in a root route: its attribute text at JSX brace depth 0,
|
|
494
|
+
* with string literals skipped (so `className="a > b"` cannot end the tag, nor `"router="` count),
|
|
495
|
+
* and whether a `{...spread}` could carry a `router`.
|
|
496
|
+
*/
|
|
497
|
+
function providerTags(src: string): ProviderTag[] {
|
|
498
|
+
const { code, inLiteral } = tokenize(src)
|
|
499
|
+
return [...code.matchAll(/<BasaltProvider\b/g)]
|
|
500
|
+
.filter((m) => !inLiteral(m.index))
|
|
501
|
+
.map((m) => {
|
|
502
|
+
const tag: ProviderTag = { attrs: '', spread: false }
|
|
503
|
+
let depth = 0
|
|
504
|
+
for (let i = m.index + m[0].length; i < code.length; i++) {
|
|
505
|
+
const ch = code[i]!
|
|
506
|
+
if (inLiteral(i)) continue
|
|
507
|
+
if (ch === '{') {
|
|
508
|
+
if (depth++ === 0 && isSpreadAt(code, i)) tag.spread = true
|
|
509
|
+
} else if (ch === '}') depth--
|
|
510
|
+
else if (ch === '>' && depth === 0) break
|
|
511
|
+
else if (depth === 0) tag.attrs += ch
|
|
512
|
+
}
|
|
513
|
+
return tag
|
|
514
|
+
})
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const carriesRouter = (tag: ProviderTag): boolean => /(^|\s)router\s*=/.test(tag.attrs)
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* A Start app owns its router and entry: the wiring is an embedded `<BasaltProvider>` (no `router=`)
|
|
521
|
+
* in its root route component, around `<Outlet />`. ANY tag with `router=` mounts a second router
|
|
522
|
+
* inside Start's, so it fails even beside an embedded one.
|
|
523
|
+
*/
|
|
524
|
+
function startWiring(cwd: string): { fail: string } | null {
|
|
525
|
+
const root = routerSeedDest('', 'root')
|
|
526
|
+
const text = readIfExists(resolve(cwd, root))
|
|
527
|
+
const tags = providerTags(text ?? '')
|
|
528
|
+
const mounting = tags.some(carriesRouter)
|
|
529
|
+
if (!mounting && tags.length > 0) return null
|
|
530
|
+
const problem =
|
|
531
|
+
text === null
|
|
532
|
+
? 'does not exist'
|
|
533
|
+
: mounting
|
|
534
|
+
? 'passes router= to BasaltProvider, which mounts a second router inside Start'
|
|
535
|
+
: 'does not render <BasaltProvider>'
|
|
536
|
+
return {
|
|
537
|
+
fail: `app-wiring: ${root} ${problem} (TanStack Start app). Fix: render <BasaltProvider><Outlet /></BasaltProvider> in the root route component.`,
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Warnings for a Start app's embedded provider; heuristics, not proofs. A `{...spread}` on the tag
|
|
543
|
+
* could carry a `router`; `src/router.tsx` never mentioning `queryClient` means the embedded
|
|
544
|
+
* provider will find no `context.queryClient`. Empty when there is nothing to judge.
|
|
545
|
+
*/
|
|
546
|
+
export function startWiringWarnings(cwd: string): string[] {
|
|
547
|
+
if (!isStartApp(cwd, '')) return []
|
|
548
|
+
const out: string[] = []
|
|
549
|
+
const root = readIfExists(resolve(cwd, routerSeedDest('', 'root')))
|
|
550
|
+
if (root !== null && providerTags(root).some((t) => t.spread)) {
|
|
551
|
+
out.push(
|
|
552
|
+
'app-wiring: <BasaltProvider {...spread}> in the root route could pass router=, which mounts ' +
|
|
553
|
+
'a second router inside Start (heuristic: the spread is not followed).',
|
|
554
|
+
)
|
|
555
|
+
}
|
|
556
|
+
const router = readIfExists(resolve(cwd, 'src/router.tsx'))
|
|
557
|
+
if (router !== null && !/queryClient/.test(router)) {
|
|
558
|
+
out.push(
|
|
559
|
+
'app-wiring: src/router.tsx never mentions queryClient — embedded BasaltProvider needs ' +
|
|
560
|
+
'context.queryClient on the Start router (heuristic text check; ignore if you build it elsewhere).',
|
|
561
|
+
)
|
|
562
|
+
}
|
|
563
|
+
return out
|
|
564
|
+
}
|
|
565
|
+
|
|
411
566
|
/**
|
|
412
567
|
* `app-wiring`: the entry module `index.html` loads (default src/main.tsx) mounts `BasaltProvider`
|
|
413
568
|
* on a `createBasaltRouter` router (called in the entry or a module it imports), and the router tree is generated: the vite config calls a
|
|
@@ -417,6 +572,7 @@ function routerCreatedInImports(cwd: string, entry: string): boolean {
|
|
|
417
572
|
*/
|
|
418
573
|
export function appWiringCheck(cwd: string): Check {
|
|
419
574
|
return guarded('app-wiring', () => {
|
|
575
|
+
if (isStartApp(cwd, '')) return startWiring(cwd)
|
|
420
576
|
const entry = (
|
|
421
577
|
htmlEntry(readIfExists(resolve(cwd, 'index.html')) ?? '') ?? 'src/main.tsx'
|
|
422
578
|
).replace(/^\//, '')
|
|
@@ -483,7 +639,7 @@ const EXACT_VERSION = /^\d+\.\d+\.\d+$/
|
|
|
483
639
|
function installedVersion(cwd: string, pkg: string): string | null {
|
|
484
640
|
for (let dir = cwd; ; dir = dirname(dir)) {
|
|
485
641
|
const manifest = readPackageJson<{ version?: string }>(resolve(dir, 'node_modules', pkg))
|
|
486
|
-
if (manifest !== null) return manifest.version
|
|
642
|
+
if (manifest !== null) return typeof manifest.version === 'string' ? manifest.version : null
|
|
487
643
|
if (dirname(dir) === dir) return null
|
|
488
644
|
}
|
|
489
645
|
}
|
package/src/cli/doctor.ts
CHANGED
|
@@ -37,8 +37,10 @@ import {
|
|
|
37
37
|
import { resolveRoots } from './config'
|
|
38
38
|
import {
|
|
39
39
|
appWiringCheck,
|
|
40
|
+
startWiringWarnings,
|
|
40
41
|
droppedSubpathsCheck,
|
|
41
42
|
exactPeersCheck,
|
|
43
|
+
oxlintFloorCheck,
|
|
42
44
|
retiredLintRulesCheck,
|
|
43
45
|
subpathPeersCheck,
|
|
44
46
|
tsconfigBaseCheck,
|
|
@@ -397,6 +399,7 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
397
399
|
'dropped-subpaths: no import of a basalt-ui subpath the install lacks',
|
|
398
400
|
droppedSubpathsCheck(appDir, cfg, install),
|
|
399
401
|
],
|
|
402
|
+
['oxlint-floor: the installed oxlint parses the shipped preset', oxlintFloorCheck(cwd)],
|
|
400
403
|
[
|
|
401
404
|
'app-wiring: the entry mounts BasaltProvider and the router tree is generated',
|
|
402
405
|
appWiringCheck(appDir),
|
|
@@ -416,6 +419,7 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
416
419
|
else if ('fail' in check) fail(check.fail)
|
|
417
420
|
else skip(check.skip)
|
|
418
421
|
}
|
|
422
|
+
for (const line of startWiringWarnings(appDir)) warn(line)
|
|
419
423
|
}
|
|
420
424
|
|
|
421
425
|
// ── Report ──────────────────────────────────────────────────────────────────
|
package/src/cli/help.ts
CHANGED
|
@@ -76,7 +76,7 @@ export const USAGE =
|
|
|
76
76
|
' [--light-class <class>] [--dark-value <v>] [--light-value <v>]\n' +
|
|
77
77
|
' [--default-scheme <dark|light|none>] [--media-fallback] [--only <core|all>]\n' +
|
|
78
78
|
' [--no-legacy-aliases]\n' +
|
|
79
|
-
' Emit the --vx-* stylesheet (stdout unless --out). Defaults
|
|
79
|
+
' Emit the --vx-* stylesheet (stdout unless --out). Defaults emit the stock identity; commit the output as your tokens file.\n' +
|
|
80
80
|
' --selector-class emits `:root.dark` instead of an attribute selector (the Tailwind convention).\n' +
|
|
81
81
|
' --check writes nothing and exits 1 when --out differs from what would be emitted (a CI gate).\n' +
|
|
82
82
|
' --no-legacy-aliases drops the deprecated camelCase spellings (--vx-accentFill and friends),\n' +
|