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.
Files changed (47) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +33 -0
  3. package/MIGRATING.md +101 -15
  4. package/agent/rules/basalt-batteries.md +1 -1
  5. package/agent/rules/basalt-controls.md +1 -1
  6. package/agent/rules/basalt-mantine.md +1 -1
  7. package/agent/skills/basalt-app/SKILL.md +7 -7
  8. package/agent/templates/AGENTS-block.md.tpl +1 -1
  9. package/dist/charts/BandStrip.d.ts +13 -0
  10. package/dist/charts/BandStrip.d.ts.map +1 -1
  11. package/dist/charts/BandStrip.js +142 -44
  12. package/dist/cli/doctor-upgrade.d.ts +11 -0
  13. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  14. package/dist/cli/doctor-upgrade.js +122 -10
  15. package/dist/cli/doctor.d.ts.map +1 -1
  16. package/dist/cli/doctor.js +4 -0
  17. package/dist/cli/help.js +1 -1
  18. package/dist/cli/index.d.ts +5 -0
  19. package/dist/cli/index.d.ts.map +1 -1
  20. package/dist/cli/index.js +12 -0
  21. package/dist/cli/init.d.ts.map +1 -1
  22. package/dist/cli/init.js +7 -4
  23. package/dist/cli/sync.d.ts.map +1 -1
  24. package/dist/cli/sync.js +27 -2
  25. package/dist/content/toc.d.ts +5 -0
  26. package/dist/content/toc.d.ts.map +1 -1
  27. package/dist/provider/index.d.ts +22 -4
  28. package/dist/provider/index.d.ts.map +1 -1
  29. package/dist/provider/index.js +21 -6
  30. package/dist/provider/test-router.d.ts +2 -1
  31. package/dist/provider/test-router.d.ts.map +1 -1
  32. package/dist/provider/test-router.js +6 -7
  33. package/dist/surfaces.d.ts +1 -1
  34. package/dist/surfaces.js +1 -1
  35. package/llms.txt +36 -4
  36. package/package.json +1 -1
  37. package/src/charts/BandStrip.tsx +223 -48
  38. package/src/cli/doctor-upgrade.ts +171 -15
  39. package/src/cli/doctor.ts +4 -0
  40. package/src/cli/help.ts +1 -1
  41. package/src/cli/index.ts +16 -0
  42. package/src/cli/init.ts +7 -6
  43. package/src/cli/sync.ts +29 -2
  44. package/src/content/toc.tsx +5 -0
  45. package/src/provider/index.tsx +65 -15
  46. package/src/provider/test-router.tsx +9 -9
  47. package/src/surfaces.ts +1 -1
package/src/cli/index.ts CHANGED
@@ -670,6 +670,22 @@ export function routerSeedDest(appRel: string, seed: keyof typeof ROUTER_SEED_DE
670
670
  return appRel === '' ? ROUTER_SEED_DESTS[seed] : `${appRel}/${ROUTER_SEED_DESTS[seed]}`
671
671
  }
672
672
 
673
+ /** The router seeds' dests for an app dir (`main.tsx`, `nav.tsx`, `__root.tsx`). */
674
+ export function routerSeedDests(appRel: string): string[] {
675
+ return (Object.keys(ROUTER_SEED_DESTS) as (keyof typeof ROUTER_SEED_DESTS)[]).map((seed) =>
676
+ routerSeedDest(appRel, seed),
677
+ )
678
+ }
679
+
680
+ /** A TanStack Start app owns its router, so its router seeds give way to an in-tree `<BasaltProvider>`. */
681
+ export function isStartApp(cwd: string, appRel: string): boolean {
682
+ return hasDependency(resolve(cwd, appRel), '@tanstack/react-start')
683
+ }
684
+
685
+ export const START_APP_NOTE =
686
+ 'TanStack Start app — no main.tsx/nav.tsx/__root.tsx seeded (Start owns the router); render ' +
687
+ '<BasaltProvider><Outlet /></BasaltProvider> in your root route component.'
688
+
673
689
  /** The app directory a command's app-scoped half targets: `rel` is '' when it is the install root. */
674
690
  export type AppResolution = { dir: string; rel: string } | { error: string }
675
691
 
package/src/cli/init.ts CHANGED
@@ -11,9 +11,10 @@ import type { MergeLintResult, ScaffoldFlags } from './index'
11
11
  import {
12
12
  MANIFEST_PATH,
13
13
  declaredProfile,
14
+ isStartApp,
15
+ routerSeedDests,
16
+ START_APP_NOTE,
14
17
  readBasaltConfig,
15
- ROUTER_SEED_DESTS,
16
- routerSeedDest,
17
18
  findBasaltInstall,
18
19
  managedFiles,
19
20
  mergeOxlintExtends,
@@ -127,10 +128,9 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
127
128
  const placement = resolvePlacement(cwd)
128
129
  // A tokens-only consumer has no use for the Mantine/React scaffolds (doctor skips them there too).
129
130
  const tokensOnly = declaredProfile(readBasaltConfig(cwd), []) === 'tokens-only'
130
- const routerSeeds: string[] = (
131
- Object.keys(ROUTER_SEED_DESTS) as (keyof typeof ROUTER_SEED_DESTS)[]
132
- ).map((seed) => routerSeedDest(placement.appRel, seed))
133
- const files = managedFiles(placement).filter((f) => !(tokensOnly && routerSeeds.includes(f.dest)))
131
+ const startApp = isStartApp(cwd, placement.appRel)
132
+ const skippedSeeds = new Set(tokensOnly || startApp ? routerSeedDests(placement.appRel) : [])
133
+ const files = managedFiles(placement).filter((f) => !skippedSeeds.has(f.dest))
134
134
 
135
135
  const writtenFiles: string[] = []
136
136
  const keptFiles: string[] = []
@@ -205,6 +205,7 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
205
205
  const tsconfigLine = tokensOnly ? null : seedTsconfigExtends(cwd)
206
206
  if (tsconfigLine !== null) console.log(`basalt-ui init: ${tsconfigLine}`)
207
207
  if (buildNote !== null) console.log(`basalt-ui init: ${buildNote}`)
208
+ if (startApp && !tokensOnly) console.log(`basalt-ui init: ${START_APP_NOTE}`)
208
209
  const rootsMessages = rootsNotices(rootsState)
209
210
  for (const line of rootsMessages.log) console.log(`basalt-ui init: ${line}`)
210
211
  for (const line of rootsMessages.error) console.error(`⚠ basalt-ui init: ${line}`)
package/src/cli/sync.ts CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  diffSummary,
13
13
  findBasaltInstall,
14
14
  inspectLefthookGate,
15
+ isStartApp,
15
16
  isStringArray,
16
17
  managedFiles,
17
18
  normalizeForLedger,
@@ -30,9 +31,11 @@ import {
30
31
  reportPrune,
31
32
  resolvePlacement,
32
33
  resolveProjectDir,
34
+ routerSeedDests,
33
35
  rootsNotices,
34
36
  sha256,
35
37
  shippedAssetPath,
38
+ START_APP_NOTE,
36
39
  unitState,
37
40
  writeFileEnsuringDir,
38
41
  writeUnit,
@@ -110,7 +113,9 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
110
113
  // Refuse BEFORE reconcileRoots, which writes `basalt.roots` into package.json.
111
114
  if (!existsSync(resolve(cwd, MANIFEST_PATH))) {
112
115
  const elsewhere = findManifestAbove(cwd)
113
- const wouldWrite = managedFiles(resolvePlacement(cwd)).length
116
+ const refused = resolvePlacement(cwd)
117
+ const startSeeds = isStartApp(cwd, refused.appRel) ? routerSeedDests(refused.appRel) : []
118
+ const wouldWrite = managedFiles(refused).filter((f) => !startSeeds.includes(f.dest)).length
114
119
  console.error(
115
120
  `✖ basalt-ui sync: no ${MANIFEST_PATH} at ${cwd} — refusing to scaffold. ` +
116
121
  `\`sync\` refreshes an EXISTING basalt install; creating one is \`basalt-ui init\`'s ` +
@@ -129,7 +134,9 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
129
134
  const ctx = renderContext(cwd)
130
135
  const manifest = readManifest(cwd)
131
136
  const placement = resolvePlacement(cwd)
132
- const files = managedFiles(placement)
137
+ const startApp = isStartApp(cwd, placement.appRel)
138
+ const skipped = new Set(startApp ? routerSeedDests(placement.appRel) : [])
139
+ const files = managedFiles(placement).filter((f) => !skipped.has(f.dest))
133
140
 
134
141
  let updated = 0
135
142
  // `created` and `recreated` were one counter, and `0 updated, 20 recreated` is what a full
@@ -201,6 +208,26 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
201
208
  // Placement notices — informational, never affecting the exit code, and PERMANENT: `--check`
202
209
  // hides them behind `--verbose` (it sits in consumers' CI chains, where three unchanging
203
210
  // "skipped" paragraphs per run are noise indistinguishable from drift) but still prints the COUNT.
211
+ // Start added AFTER a pre-Start init: the old seeds are the consumer's now — left untouched, named.
212
+ const stale = [...skipped].filter(
213
+ (d) => manifest.files[d] !== undefined && existsSync(resolve(cwd, d)),
214
+ )
215
+ const mounting = stale.filter((d) => !d.endsWith('nav.tsx'))
216
+ const inert = stale.filter((d) => d.endsWith('nav.tsx'))
217
+ const embedded =
218
+ 'Delete them and render <BasaltProvider><Outlet /></BasaltProvider> in the Start root route (embedded mode).'
219
+ if (mounting.length > 0) {
220
+ console.error(
221
+ `⚠ basalt-ui sync: ${mounting.join(', ')} mount a second router inside this TanStack Start app; left untouched. ${embedded}`,
222
+ )
223
+ }
224
+ if (inert.length > 0) {
225
+ console.error(
226
+ `⚠ basalt-ui sync: ${inert.join(', ')} was seeded before this became a Start app; it mounts nothing, so keep or delete it. Left untouched.`,
227
+ )
228
+ }
229
+ if (startApp && (!opts.check || syncFlags.includes('--verbose')))
230
+ console.log(`basalt-ui sync: ${START_APP_NOTE}`)
204
231
  const placementSkips = placementNotices(cwd, placement)
205
232
  if (opts.check !== true || syncFlags.includes('--verbose')) {
206
233
  for (const line of placementSkips) console.log(`basalt-ui sync: ${line}`)
@@ -1,6 +1,11 @@
1
1
  /**
2
2
  * TableOfContents — an IntersectionObserver scroll-spy rail (docs/CONTENT-SPEC.md §3/§6).
3
3
  *
4
+ * Contract with `Markdown`: `Markdown` slugs every heading it renders into an `id` (deduped within the
5
+ * one document; per streamed block in `streaming` mode); `containerRef` collects the h2/h3 (`levels`)
6
+ * that already carry an `id` under that single container, on mount and on every childList mutation
7
+ * beneath it — late or lazy-rendered headings are picked up. `Prose` sets no ids; `items` replaces collection.
8
+ *
4
9
  * Headings self-register: pass `items` explicitly, or pass `containerRef` and the component
5
10
  * collects `h2`/`h3` (configurable via `levels`) that already carry an `id` — pair with
6
11
  * `headingSlug`/`SlugTracker` when authoring the headings. Sticky positioning is the consumer's
@@ -18,7 +18,7 @@ import { Spotlight } from '@mantine/spotlight'
18
18
  import type { SpotlightActionData } from '@mantine/spotlight'
19
19
  import { QueryClientProvider } from '@tanstack/react-query'
20
20
  import type { QueryClient } from '@tanstack/react-query'
21
- import { RouterProvider } from '@tanstack/react-router'
21
+ import { RouterProvider, useRouter } from '@tanstack/react-router'
22
22
  import type { AnyRouter } from '@tanstack/react-router'
23
23
  import { Component, Suspense, lazy, useCallback, useEffect, useMemo, useRef, useState } from 'react'
24
24
  import type { ErrorInfo, ReactNode } from 'react'
@@ -50,9 +50,7 @@ import { useRegistryHotkeys } from './hotkeys'
50
50
  import type { FlatNavItem } from '../router-tanstack/nav'
51
51
  import { buildSpotlightActions } from './spotlight-actions'
52
52
 
53
- export type BasaltProviderProps = {
54
- /** From `createBasaltRouter`; the provider mounts it and reads its `queryClient`. */
55
- router: BasaltRouter
53
+ type BasaltProviderCommonProps = {
56
54
  /** Theme override merged onto the Basalt base. Defaults to `createBasaltTheme()`. */
57
55
  theme?: MantineProviderProps['theme']
58
56
  /**
@@ -92,8 +90,33 @@ export type BasaltProviderProps = {
92
90
  * entry with id `nav.<id>` replaces the generated one outright.
93
91
  */
94
92
  navCommandLabel?: (item: FlatNavItem) => string
93
+ /**
94
+ * Mount Basalt's `<Spotlight>` (Cmd+K) with the generated nav + command actions. Default `true`.
95
+ * Set `false` when the app owns its own palette: neither the component nor its action wiring mounts.
96
+ */
97
+ spotlight?: boolean
95
98
  } & Omit<MantineProviderProps, 'children' | 'theme' | 'defaultColorScheme' | 'cssVariablesResolver'>
96
99
 
100
+ /**
101
+ * Two modes, never both: pass a `createBasaltRouter` `router` and the provider mounts it, or pass
102
+ * `children` and render the provider INSIDE a router the app does not own (around the `<Outlet />`
103
+ * of TanStack Start's root route component) — the router then comes from `useRouter()` and must carry
104
+ * `context.queryClient` (its `getRouter()` builds the same context `createBasaltRouter` does).
105
+ */
106
+ export type BasaltProviderProps = BasaltProviderCommonProps &
107
+ (
108
+ | {
109
+ /** From `createBasaltRouter`; the provider mounts it and reads its `queryClient`. */
110
+ router: BasaltRouter
111
+ children?: never
112
+ }
113
+ | {
114
+ router?: never
115
+ /** The subtree inside the app's own router; rendered where `<RouterProvider>` would be. */
116
+ children: ReactNode
117
+ }
118
+ )
119
+
97
120
  // ── Root error boundary ───────────────────────────────────────────────────────────────────────────
98
121
 
99
122
  type RootBoundaryProps = {
@@ -402,17 +425,32 @@ function readQueryClient(router: AnyRouter): QueryClient {
402
425
  const client = (router.options.context as Partial<BasaltRouterContext> | undefined)?.queryClient
403
426
  if (client === undefined) {
404
427
  throw new Error(
405
- '[basalt] BasaltProvider: the router has no context.queryClient — create it with ' +
406
- 'createBasaltRouter({ routeTree }).',
428
+ '[basalt] BasaltProvider: no context.queryClient — pass `router` from createBasaltRouter, ' +
429
+ 'or with `children` put a QueryClient in the router context.',
407
430
  )
408
431
  }
409
432
  return client
410
433
  }
411
434
 
435
+ /**
436
+ * The router this provider serves: the one it mounts (`router`), else — embedded mode — the one the
437
+ * host already mounted above it. `warn: false`: mount mode sits ABOVE any router, so no context is
438
+ * expected there. The context read is SSR-safe.
439
+ */
440
+ function useEffectiveRouter(mounted: BasaltRouter | undefined): AnyRouter {
441
+ const ambient: AnyRouter | undefined = useRouter<AnyRouter>({ warn: false })
442
+ const router = mounted ?? ambient
443
+ if (!router) {
444
+ throw new Error(
445
+ '[basalt] BasaltProvider: no router — pass `router` to mount one, or `children` inside one.',
446
+ )
447
+ }
448
+ return router
449
+ }
450
+
412
451
  // ── Public provider ───────────────────────────────────────────────────────────────────────────────
413
452
 
414
453
  export function BasaltProvider({
415
- router,
416
454
  theme,
417
455
  telemetry,
418
456
  fallback,
@@ -422,6 +460,9 @@ export function BasaltProvider({
422
460
  nonce,
423
461
  sizeClassHint = 'compact',
424
462
  navCommandLabel,
463
+ spotlight = true,
464
+ router: mountedRouter,
465
+ children,
425
466
  ...rest
426
467
  }: BasaltProviderProps) {
427
468
  useDuplicateProviderGuard()
@@ -438,6 +479,7 @@ export function BasaltProvider({
438
479
  // `overlays.confirm` is an imperative call; this tells it a `ModalsProvider` is live.
439
480
  useEffect(() => registerModalsProvider(), [])
440
481
 
482
+ const router = useEffectiveRouter(mountedRouter)
441
483
  const client = readQueryClient(router)
442
484
  useDataTelemetry(router, client, emit)
443
485
 
@@ -449,7 +491,9 @@ export function BasaltProvider({
449
491
  () => setActions(buildSpotlightActions(router, setDevTool, navCommandLabel)),
450
492
  [router, navCommandLabel],
451
493
  )
452
- useEffect(refreshActions, [refreshActions])
494
+ useEffect(() => {
495
+ if (spotlight) refreshActions()
496
+ }, [spotlight, refreshActions])
453
497
 
454
498
  // `createBasaltTheme(theme)` — plus, when the theme lab's "Apply" switch is on, the delta of its
455
499
  // persisted config, so the dev tool moves the numeric `defaultProps` and `theme.spacing` a `<style>`
@@ -474,7 +518,11 @@ export function BasaltProvider({
474
518
  <QueryClientProvider client={client}>
475
519
  {/* ModalsProvider WRAPS the router, so `useModals()` / `openContextModal` have real context. */}
476
520
  <ModalsProvider>
477
- <RouterProvider router={router} />
521
+ {mountedRouter === undefined ? (
522
+ children
523
+ ) : (
524
+ <RouterProvider router={mountedRouter} />
525
+ )}
478
526
  {/* The literal read sits at the branch, so a production build drops the import. */}
479
527
  {process.env.NODE_ENV !== 'production' && (
480
528
  <Suspense fallback={null}>
@@ -488,12 +536,14 @@ export function BasaltProvider({
488
536
  </ModalsProvider>
489
537
  </QueryClientProvider>
490
538
  <Notifications position="bottom-right" autoClose={4000} limit={5} />
491
- <Spotlight
492
- actions={actions}
493
- onSpotlightOpen={refreshActions}
494
- shortcut="mod + K"
495
- maxHeight={420}
496
- />
539
+ {spotlight && (
540
+ <Spotlight
541
+ actions={actions}
542
+ onSpotlightOpen={refreshActions}
543
+ shortcut="mod + K"
544
+ maxHeight={420}
545
+ />
546
+ )}
497
547
  </SizeClassHintContext.Provider>
498
548
  </TelemetryContext.Provider>
499
549
  </BasaltBridge>
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { Outlet, createRootRoute, createRoute } from '@tanstack/react-router'
6
6
  import type { AnyRouter } from '@tanstack/react-router'
7
+ import type { ReactNode } from 'react'
7
8
  import { createBasaltRouter } from './create-router'
8
9
  import type { BasaltRouterContext } from './create-router'
9
10
 
@@ -11,15 +12,14 @@ import type { BasaltRouterContext } from './create-router'
11
12
  export const queryClientOf = (router: AnyRouter): BasaltRouterContext['queryClient'] =>
12
13
  (router.options.context as BasaltRouterContext).queryClient
13
14
 
14
- export function testRouter(text = 'content') {
15
- const root = createRootRoute({
16
- component: () => (
17
- <>
18
- <div>{text}</div>
19
- <Outlet />
20
- </>
21
- ),
22
- })
15
+ export function testRouter(text = 'content', wrap?: (children: ReactNode) => ReactNode) {
16
+ const body = (
17
+ <>
18
+ <div>{text}</div>
19
+ <Outlet />
20
+ </>
21
+ )
22
+ const root = createRootRoute({ component: () => (wrap ? wrap(body) : body) })
23
23
  const other = createRoute({ getParentRoute: () => root, path: '/other', component: () => null })
24
24
  return createBasaltRouter({ routeTree: root.addChildren([other]) })
25
25
  }
package/src/surfaces.ts CHANGED
@@ -459,7 +459,7 @@ export const SURFACES = {
459
459
  guardKinds: [],
460
460
  pluginRules: [],
461
461
  description:
462
- 'Prose (article/chat typography), Callout, TableOfContents, Markdown (react-markdown + remark-gfm, optional peers; `streaming` is a rendering mode ONLY — `contentTrust` is the independent security input, and any surface rendering agent/model output must pin `contentTrust="untrusted"`, the sole input to the image-origin allowlist; `fenceRenderers` extends fenced-block rendering — settledOnly/FenceRenderer/FenceRenderers; `sanitizeSchema` is an additions-only SanitizeSchemaExtension merged over the default via mergeSanitizeSchema; shiki code blocks, beautiful-mermaid diagrams and the remend streaming repair load lazily from optional peers), ArticleLayout (docs-page frame), GuideLink (contextual-help link) — the content/prose surface',
462
+ 'Prose (article/chat typography), Callout, TableOfContents (given a containerRef it collects the id-bearing h2/h3 under that one container — levels changes which — on mount and on every DOM childList change, so it reads the slug ids `Markdown` gives every heading; `Prose` sets no ids and an explicit items list replaces collection), Markdown (react-markdown + remark-gfm, optional peers; `streaming` is a rendering mode ONLY — `contentTrust` is the independent security input, and any surface rendering agent/model output must pin `contentTrust="untrusted"`, the sole input to the image-origin allowlist; `fenceRenderers` extends fenced-block rendering — settledOnly/FenceRenderer/FenceRenderers; `sanitizeSchema` is an additions-only SanitizeSchemaExtension merged over the default via mergeSanitizeSchema; shiki code blocks, beautiful-mermaid diagrams and the remend streaming repair load lazily from optional peers), ArticleLayout (docs-page frame), GuideLink (contextual-help link) — the content/prose surface',
463
463
  optionalPeers: [
464
464
  'shiki',
465
465
  '@shikijs/langs',