basalt-ui 2.11.0 → 2.12.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 (109) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +26 -0
  3. package/MIGRATING.md +33 -12
  4. package/README.md +2 -0
  5. package/agent/rules/basalt-mantine.md +1 -1
  6. package/agent/skills/basalt-app/SKILL.md +1 -1
  7. package/agent/skills/basalt-charts/SKILL.md +1 -1
  8. package/dist/charts/DualPanel.d.ts.map +1 -1
  9. package/dist/charts/DualPanel.js +1 -0
  10. package/dist/charts/Lines.d.ts.map +1 -1
  11. package/dist/charts/Lines.js +7 -45
  12. package/dist/charts/MirroredBars.js +2 -2
  13. package/dist/charts/compile.d.ts.map +1 -1
  14. package/dist/charts/compile.js +21 -5
  15. package/dist/charts/labels.d.ts +34 -0
  16. package/dist/charts/labels.d.ts.map +1 -0
  17. package/dist/charts/labels.js +63 -0
  18. package/dist/charts/marks.d.ts +7 -0
  19. package/dist/charts/marks.d.ts.map +1 -1
  20. package/dist/charts/marks.js +22 -0
  21. package/dist/charts/scales.d.ts +4 -1
  22. package/dist/charts/scales.d.ts.map +1 -1
  23. package/dist/charts/scales.js +5 -3
  24. package/dist/charts/ticks.d.ts +12 -0
  25. package/dist/charts/ticks.d.ts.map +1 -0
  26. package/dist/charts/ticks.js +42 -0
  27. package/dist/charts/types.d.ts +11 -3
  28. package/dist/charts/types.d.ts.map +1 -1
  29. package/dist/cli/doctor-upgrade.d.ts +2 -3
  30. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  31. package/dist/cli/doctor-upgrade.js +71 -26
  32. package/dist/cli/index.d.ts +3 -1
  33. package/dist/cli/index.d.ts.map +1 -1
  34. package/dist/cli/index.js +3 -1
  35. package/dist/cli/sync.d.ts.map +1 -1
  36. package/dist/cli/sync.js +2 -1
  37. package/dist/commands/command-stash.d.ts +15 -0
  38. package/dist/commands/command-stash.d.ts.map +1 -0
  39. package/dist/commands/command-stash.js +31 -0
  40. package/dist/commands/define-commands.d.ts +2 -3
  41. package/dist/commands/define-commands.d.ts.map +1 -1
  42. package/dist/commands/define-commands.js +9 -7
  43. package/dist/commands/define-overlays.d.ts +6 -12
  44. package/dist/commands/define-overlays.d.ts.map +1 -1
  45. package/dist/commands/define-overlays.js +28 -34
  46. package/dist/commands/projectors.js +1 -1
  47. package/dist/provider/hotkeys.d.ts +2 -6
  48. package/dist/provider/hotkeys.d.ts.map +1 -1
  49. package/dist/provider/hotkeys.js +10 -15
  50. package/dist/provider/index.d.ts +5 -3
  51. package/dist/provider/index.d.ts.map +1 -1
  52. package/dist/provider/index.js +12 -35
  53. package/dist/provider/modals-mount.d.ts +16 -0
  54. package/dist/provider/modals-mount.d.ts.map +1 -0
  55. package/dist/provider/modals-mount.js +42 -0
  56. package/dist/provider/notifier.d.ts +22 -0
  57. package/dist/provider/notifier.d.ts.map +1 -0
  58. package/dist/provider/notifier.js +36 -0
  59. package/dist/provider/route-transition.d.ts +1 -1
  60. package/dist/provider/route-transition.d.ts.map +1 -1
  61. package/dist/provider/route-transition.js +1 -1
  62. package/dist/provider/slots.d.ts +25 -0
  63. package/dist/provider/slots.d.ts.map +1 -0
  64. package/dist/provider/slots.js +29 -0
  65. package/dist/provider/spotlight-actions.d.ts +1 -1
  66. package/dist/provider/spotlight-actions.d.ts.map +1 -1
  67. package/dist/provider/spotlight-actions.js +2 -3
  68. package/dist/provider/spotlight-mount.d.ts +3 -0
  69. package/dist/provider/spotlight-mount.d.ts.map +1 -0
  70. package/dist/provider/spotlight-mount.js +26 -0
  71. package/dist/router-tanstack/nav-stash.d.ts +24 -0
  72. package/dist/router-tanstack/nav-stash.d.ts.map +1 -0
  73. package/dist/router-tanstack/nav-stash.js +23 -0
  74. package/dist/router-tanstack/nav.d.ts +5 -15
  75. package/dist/router-tanstack/nav.d.ts.map +1 -1
  76. package/dist/router-tanstack/nav.js +6 -16
  77. package/dist/router-tanstack/use-nav.js +1 -1
  78. package/dist/surfaces.d.ts +1 -1
  79. package/dist/surfaces.js +1 -1
  80. package/llms.txt +4 -4
  81. package/package.json +2 -2
  82. package/src/charts/DualPanel.tsx +1 -0
  83. package/src/charts/Lines.tsx +11 -57
  84. package/src/charts/MirroredBars.tsx +2 -2
  85. package/src/charts/compile.ts +34 -6
  86. package/src/charts/labels.ts +118 -0
  87. package/src/charts/marks.ts +41 -0
  88. package/src/charts/scales.ts +9 -7
  89. package/src/charts/ticks.ts +61 -0
  90. package/src/charts/types.ts +11 -3
  91. package/src/cli/doctor-upgrade.ts +101 -35
  92. package/src/cli/index.ts +5 -3
  93. package/src/cli/sync.ts +2 -2
  94. package/src/commands/command-stash.ts +44 -0
  95. package/src/commands/define-commands.ts +10 -17
  96. package/src/commands/define-overlays.ts +40 -68
  97. package/src/commands/projectors.ts +1 -1
  98. package/src/provider/hotkeys.ts +14 -22
  99. package/src/provider/index.tsx +28 -52
  100. package/src/provider/modals-mount.tsx +66 -0
  101. package/src/provider/notifier.ts +52 -0
  102. package/src/provider/route-transition.ts +1 -1
  103. package/src/provider/slots.ts +59 -0
  104. package/src/provider/spotlight-actions.tsx +3 -4
  105. package/src/provider/spotlight-mount.tsx +33 -0
  106. package/src/router-tanstack/nav-stash.ts +41 -0
  107. package/src/router-tanstack/nav.ts +11 -31
  108. package/src/router-tanstack/use-nav.ts +1 -1
  109. package/src/surfaces.ts +1 -1
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * BasaltProvider — the one provider tree (V2-SPEC § 2): `MantineProvider` with the Basalt theme and
3
3
  * resolver, the `--vx-*` palette `<style>`, and then
4
- * `QueryClientProvider > ModalsProvider > RouterProvider` with `Notifications` and `Spotlight` as
5
- * siblings. The consumer writes the route tree, the nav and the registries.
4
+ * `QueryClientProvider > RouterProvider` with `Notifications` as a sibling. Spotlight, the modals
5
+ * layer and the command hotkeys are slots: each mounts as a sibling only once the app's `defineNav` /
6
+ * `defineCommands` / `defineOverlays` call registered it (`./slots`), so an app defining none ships none
7
+ * of their runtimes. The consumer writes the route tree, the nav and the registries.
6
8
  *
7
9
  * It also owns the root error boundary, the `window` error listeners and the telemetry seam
8
10
  * (V2-SPEC § 7), the command hotkeys and Spotlight actions, and — in dev only — the dev dock.
@@ -12,15 +14,12 @@
12
14
  */
13
15
  import { MantineProvider, useMantineColorScheme, useMantineTheme } from '@mantine/core'
14
16
  import type { MantineProviderProps } from '@mantine/core'
15
- import { ModalsProvider } from '@mantine/modals'
16
17
  import { Notifications } from '@mantine/notifications'
17
- import { Spotlight } from '@mantine/spotlight'
18
- import type { SpotlightActionData } from '@mantine/spotlight'
19
18
  import { QueryClientProvider } from '@tanstack/react-query'
20
19
  import type { QueryClient } from '@tanstack/react-query'
21
20
  import { RouterProvider, useRouter } from '@tanstack/react-router'
22
21
  import type { AnyRouter } from '@tanstack/react-router'
23
- import { Component, Suspense, lazy, useCallback, useEffect, useMemo, useRef, useState } from 'react'
22
+ import { Component, Suspense, lazy, useEffect, useMemo, useRef, useState } from 'react'
24
23
  import type { ErrorInfo, ReactNode } from 'react'
25
24
  import fallbackClasses from './error-fallback.module.css'
26
25
  import { cssVariablesResolver } from '../theme'
@@ -30,7 +29,6 @@ import type { BuildPaletteOpts } from '../tokens/core'
30
29
  import { isDefaultDeriveConfig } from '../tokens/derive'
31
30
  import { buildPaletteData } from '../tokens/palette'
32
31
  import { useMediaQuery } from '../common/use-media-query'
33
- import { registerModalsProvider } from '../commands/define-overlays'
34
32
  import { registerColorSchemeSetter } from '../commands/shell-bridge'
35
33
  import { useIsomorphicLayoutEffect } from '../common/isomorphic-layout-effect'
36
34
  import { PageTitle } from '../shell/page-title'
@@ -46,9 +44,9 @@ import {
46
44
  import type { Telemetry } from '../telemetry'
47
45
  import type { BasaltDevDockTool } from '../dev-dock'
48
46
  import type { BasaltRouter, BasaltRouterContext } from './create-router'
49
- import { useRegistryHotkeys } from './hotkeys'
50
- import type { FlatNavItem } from '../router-tanstack/nav'
51
- import { buildSpotlightActions } from './spotlight-actions'
47
+ import type { FlatNavItem } from '../router-tanstack/nav-stash'
48
+ import { trackProvider, useSlots } from './slots'
49
+ import type { SlotProps } from './slots'
52
50
 
53
51
  type BasaltProviderCommonProps = {
54
52
  /** Theme override merged onto the Basalt base. Defaults to `createBasaltTheme()`. */
@@ -91,8 +89,10 @@ type BasaltProviderCommonProps = {
91
89
  */
92
90
  navCommandLabel?: (item: FlatNavItem) => string
93
91
  /**
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.
92
+ * Mount Basalt's `<Spotlight>` (Cmd+K) with the generated nav + command actions. Default `true`, and
93
+ * it mounts only when the app calls `defineNav` or `defineCommands` (nav entries and commands are
94
+ * what it lists). Set `false` when the app owns its own palette: neither the component nor its
95
+ * action wiring mounts.
96
96
  */
97
97
  spotlight?: boolean
98
98
  } & Omit<MantineProviderProps, 'children' | 'theme' | 'defaultColorScheme' | 'cssVariablesResolver'>
@@ -478,31 +478,22 @@ export function BasaltProvider({
478
478
  })
479
479
  const emit = useMemo(() => createLiveEmitter(() => sinkRef.current), [])
480
480
  useWindowErrors(emit)
481
- useRegistryHotkeys()
482
- // `overlays.confirm` is an imperative call; this tells it a `ModalsProvider` is live.
483
- useEffect(() => registerModalsProvider(), [])
481
+ const slots = useSlots()
482
+ // Tells the imperative overlay calls a provider is mounted to commit a slot they register late.
483
+ useEffect(trackProvider, [])
484
484
 
485
485
  const router = useEffectiveRouter(mountedRouter)
486
486
  const client = readQueryClient(router)
487
487
  useDataTelemetry(router, client, emit)
488
488
 
489
489
  const [devTool, setDevTool] = useState<BasaltDevDockTool | null>(null)
490
- // Rebuilt on mount and again at every open, so a command's `when()` is read when the palette
491
- // appears, not frozen at mount — and `detectMac` (inside the builder) never runs during render.
492
- const [actions, setActions] = useState<SpotlightActionData[]>([])
493
- const refreshActions = useCallback(
494
- () => setActions(buildSpotlightActions(router, setDevTool, navCommandLabel)),
495
- [router, navCommandLabel],
496
- )
497
- useEffect(() => {
498
- if (spotlight) refreshActions()
499
- }, [spotlight, refreshActions])
500
-
501
490
  // `createBasaltTheme(theme)` — plus, when the theme lab's "Apply" switch is on, the delta of its
502
491
  // persisted config, so the dev tool moves the numeric `defaultProps` and `theme.spacing` a `<style>`
503
492
  // tag cannot reach. No lab override (every production app) → the consumer theme merged onto the
504
493
  // Basalt base and nothing else. See `./lab-theme.ts`.
505
494
  const resolvedTheme = useLabTheme(theme)
495
+ const { modals: Modals, hotkeys: Hotkeys, spotlight: Spotlight } = slots
496
+ const slotProps: SlotProps = { router, navCommandLabel, openDevTool: setDevTool }
506
497
 
507
498
  return (
508
499
  // `...rest` spreads FIRST so a consumer's `MantineProviderProps` can never shadow the three
@@ -519,34 +510,19 @@ export function BasaltProvider({
519
510
  <TelemetryContext.Provider value={emit}>
520
511
  <SizeClassHintContext.Provider value={sizeClassHint}>
521
512
  <QueryClientProvider client={client}>
522
- {/* ModalsProvider WRAPS the router, so `useModals()` / `openContextModal` have real context. */}
523
- <ModalsProvider>
524
- {mountedRouter === undefined ? (
525
- children
526
- ) : (
527
- <RouterProvider router={mountedRouter} />
528
- )}
529
- {/* `LazyDevDock` is `null` in production (module-scope gate above), so nothing mounts. */}
530
- {LazyDevDock !== null && (
531
- <Suspense fallback={null}>
532
- <LazyDevDock
533
- tool={devTool}
534
- onClose={() => setDevTool(null)}
535
- router={router}
536
- />
537
- </Suspense>
538
- )}
539
- </ModalsProvider>
513
+ {mountedRouter === undefined ? children : <RouterProvider router={mountedRouter} />}
514
+ {/* A sibling, not a wrapper: a late `defineOverlays` mounts it without re-parenting the app. */}
515
+ {Modals !== undefined && <Modals {...slotProps} />}
516
+ {/* `LazyDevDock` is `null` in production (module-scope gate above), so nothing mounts. */}
517
+ {LazyDevDock !== null && (
518
+ <Suspense fallback={null}>
519
+ <LazyDevDock tool={devTool} onClose={() => setDevTool(null)} router={router} />
520
+ </Suspense>
521
+ )}
540
522
  </QueryClientProvider>
541
523
  <Notifications position="bottom-right" autoClose={4000} limit={5} />
542
- {spotlight && (
543
- <Spotlight
544
- actions={actions}
545
- onSpotlightOpen={refreshActions}
546
- shortcut="mod + K"
547
- maxHeight={420}
548
- />
549
- )}
524
+ {Hotkeys !== undefined && <Hotkeys {...slotProps} />}
525
+ {spotlight && Spotlight !== undefined && <Spotlight {...slotProps} />}
550
526
  </SizeClassHintContext.Provider>
551
527
  </TelemetryContext.Provider>
552
528
  </BasaltBridge>
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The modals mount: `ModalsProvider` as a SIBLING of the router, plus the live-provider declaration
3
+ * the imperative overlay calls wait on. Registered by `defineOverlays` / `overlays.*` (never imported
4
+ * by the provider), so an app using none ships none of `@mantine/modals`.
5
+ */
6
+ import { ModalsProvider } from '@mantine/modals'
7
+ import { useEffect } from 'react'
8
+ import { createLiveCounter } from './notifier'
9
+ import { hasMountedProvider, registerSlot } from './slots'
10
+
11
+ /**
12
+ * The live `ModalsProvider`s. `@mantine/modals`' imperative API is a window event bus: with nothing
13
+ * subscribed a dialog never appears and a confirm promise never settles, so the overlay calls wait for
14
+ * this to be non-zero.
15
+ */
16
+ const liveProviders = createLiveCounter()
17
+
18
+ /**
19
+ * Internal — `ModalsMount` declares its `ModalsProvider` live for as long as it is mounted and gets
20
+ * back the retraction. There is no way to detect the provider from outside React (its context is only
21
+ * readable through `useModals()`, and the overlay calls are imperative), so the registration is explicit.
22
+ * Exported for the confirm tests, which mount their own host.
23
+ */
24
+ export const registerModalsProvider = liveProviders.acquire
25
+
26
+ /** How long a call waits for a mounted `BasaltProvider` to commit the modals mount it asked for. */
27
+ const COMMIT_WAIT_MS = 5000
28
+ /** With no `BasaltProvider` mounted nothing will commit it; this is only the grace for one mounting now. */
29
+ const NO_PROVIDER_WAIT_MS = 500
30
+
31
+ /** Resolves `true` once a `ModalsProvider` is live, `false` after `timeoutMs` without one. */
32
+ function whenModalsLive(timeoutMs: number): Promise<boolean> {
33
+ if (liveProviders.count() > 0) return Promise.resolve(true)
34
+ return new Promise((resolve) => {
35
+ let timer: ReturnType<typeof setTimeout> | undefined
36
+ let unsubscribe: (() => void) | undefined
37
+ const finish = (isLive: boolean): void => {
38
+ clearTimeout(timer)
39
+ unsubscribe?.()
40
+ resolve(isLive)
41
+ }
42
+ timer = setTimeout(() => finish(false), timeoutMs)
43
+ unsubscribe = liveProviders.subscribe(() => {
44
+ if (liveProviders.count() > 0) finish(true)
45
+ })
46
+ })
47
+ }
48
+
49
+ /** @internal — put the modals mount in the provider's slots; synchronous, nothing awaited. */
50
+ export function registerModalsMount(): void {
51
+ registerSlot('modals', ModalsMount)
52
+ }
53
+
54
+ /**
55
+ * @internal — register the mount, then wait for it to go live: up to 5 s when a `BasaltProvider` is
56
+ * mounted (it commits the slot), 500 ms when none is. `false` means no dialog layer will serve the call.
57
+ */
58
+ export function ensureModalsMount(): Promise<boolean> {
59
+ registerModalsMount()
60
+ return whenModalsLive(hasMountedProvider() ? COMMIT_WAIT_MS : NO_PROVIDER_WAIT_MS)
61
+ }
62
+
63
+ export function ModalsMount() {
64
+ useEffect(() => registerModalsProvider(), [])
65
+ return <ModalsProvider>{null}</ModalsProvider>
66
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The one subscribe/notify pair behind every module-level store here (slots, the command stash, the
3
+ * modals-live waiters) — shaped for `useSyncExternalStore`. A leaf: no React, nothing at import.
4
+ */
5
+ export type Notifier = { subscribe: (listener: () => void) => () => void; notify: () => void }
6
+
7
+ export function createNotifier(): Notifier {
8
+ const listeners = new Set<() => void>()
9
+ return {
10
+ subscribe(listener) {
11
+ listeners.add(listener)
12
+ return () => void listeners.delete(listener)
13
+ },
14
+ // Deleting from a Set mid-iteration is safe, so a listener may unsubscribe itself here.
15
+ notify() {
16
+ for (const listener of listeners) listener()
17
+ },
18
+ }
19
+ }
20
+
21
+ export type LiveCounter = {
22
+ count: () => number
23
+ /** Count one more live thing, notify subscribers, and return its retraction (idempotent). */
24
+ acquire: () => () => void
25
+ subscribe: Notifier['subscribe']
26
+ }
27
+
28
+ /**
29
+ * A COUNTER of live things — not a flag: two overlapping mounts are normal (a route swap mounts the
30
+ * next one before unmounting the previous), and a last-write-wins boolean would report the OLD one's
31
+ * teardown as "none live" while the new one serves.
32
+ */
33
+ export function createLiveCounter(): LiveCounter {
34
+ let live = 0
35
+ const changes = createNotifier()
36
+ return {
37
+ count: () => live,
38
+ subscribe: changes.subscribe,
39
+ acquire() {
40
+ live++
41
+ changes.notify()
42
+ let released = false
43
+ return () => {
44
+ // A cleanup React runs twice (StrictMode remount) must not drive the count below the real one.
45
+ if (released) return
46
+ released = true
47
+ live--
48
+ changes.notify()
49
+ }
50
+ },
51
+ }
52
+ }
@@ -8,7 +8,7 @@
8
8
  * so `ready` and `finished` are dropped on the floor.
9
9
  */
10
10
  import type { AnyRouter } from '@tanstack/react-router'
11
- import { flattenNav, getActiveNav } from '../router-tanstack/nav'
11
+ import { flattenNav, getActiveNav } from '../router-tanstack/nav-stash'
12
12
 
13
13
  /** The three `:active-view-transition-type()` names `styles.css` animates. Namespaced: a consumer's own cannot collide. */
14
14
  export const ROUTE_TRANSITION_TYPES = {
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The provider's feature slots — a tiny leaf store (React types only, no Mantine, no peers, nothing
3
+ * touched at import so it is SSR-safe). "The bundle follows the definitions": a feature's runtime
4
+ * (hotkeys, Spotlight, modals) enters the import graph only through the `define*` call that needs
5
+ * it, and that call registers its mount here. `BasaltProvider` reads the store with
6
+ * `useSyncExternalStore`, so a registration made after first render (a `define*` call inside a lazily
7
+ * loaded route) mounts a sibling instead of re-parenting the app tree.
8
+ */
9
+ import { useSyncExternalStore } from 'react'
10
+ import type { ComponentType } from 'react'
11
+ import type { AnyRouter } from '@tanstack/react-router'
12
+ import type { BasaltDevDockTool } from '../dev-dock'
13
+ import type { FlatNavItem } from '../router-tanstack/nav-stash'
14
+ import { createLiveCounter, createNotifier } from './notifier'
15
+
16
+ /** What the provider hands every mount; a mount that needs none of it ignores it. */
17
+ export type SlotProps = {
18
+ router: AnyRouter
19
+ navCommandLabel: ((item: FlatNavItem) => string) | undefined
20
+ openDevTool: (tool: BasaltDevDockTool) => void
21
+ }
22
+
23
+ export type SlotName = 'hotkeys' | 'spotlight' | 'modals'
24
+ export type Slots = { readonly [K in SlotName]?: ComponentType<SlotProps> }
25
+
26
+ let slots: Slots = {}
27
+ const store = createNotifier()
28
+
29
+ /** @internal — idempotent: re-registering the same component is a no-op (no notify, no new snapshot). */
30
+ export function registerSlot(name: SlotName, component: ComponentType<SlotProps>): void {
31
+ if (slots[name] === component) return
32
+ slots = { ...slots, [name]: component }
33
+ store.notify()
34
+ }
35
+
36
+ /** @internal — test isolation only. */
37
+ export function resetSlots(): void {
38
+ slots = {}
39
+ store.notify()
40
+ }
41
+
42
+ const getSlots = (): Slots => slots
43
+
44
+ /** @internal — the registered mounts, read by `BasaltProvider`. */
45
+ export function useSlots(): Slots {
46
+ return useSyncExternalStore(store.subscribe, getSlots, getSlots)
47
+ }
48
+
49
+ // ── Mounted providers ─────────────────────────────────────────────────────────
50
+
51
+ const providers = createLiveCounter()
52
+
53
+ /** @internal — `BasaltProvider` declares itself mounted; returns the retraction. */
54
+ export const trackProvider = providers.acquire
55
+
56
+ /** @internal — whether a `BasaltProvider` is mounted to commit a slot registered right now. */
57
+ export function hasMountedProvider(): boolean {
58
+ return providers.count() > 0
59
+ }
@@ -5,12 +5,11 @@
5
5
  */
6
6
  import type { SpotlightActionData } from '@mantine/spotlight'
7
7
  import type { AnyRouter } from '@tanstack/react-router'
8
- import { getActiveCommands } from '../commands/define-commands'
8
+ import { getActiveCommands, runCommandSafely } from '../commands/command-stash'
9
9
  import { detectMac, formatShortcutDisplay } from '../commands/shortcut-format'
10
- import { flattenNav, getActiveNav } from '../router-tanstack/nav'
11
- import type { FlatNavItem } from '../router-tanstack/nav'
10
+ import { flattenNav, getActiveNav } from '../router-tanstack/nav-stash'
11
+ import type { FlatNavItem } from '../router-tanstack/nav-stash'
12
12
  import type { BasaltDevDockTool } from '../dev-dock'
13
- import { runCommandSafely } from './hotkeys'
14
13
 
15
14
  const DEV_TOOLS: ReadonlyArray<{ tool: BasaltDevDockTool; label: string }> = [
16
15
  { tool: 'router', label: 'Router devtools' },
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The Spotlight mount: `@mantine/spotlight` plus the generated nav + command actions. Registered by
3
+ * `defineNav` and `defineCommands` (never imported by the provider), so an app defining neither ships
4
+ * none of it.
5
+ */
6
+ import { Spotlight } from '@mantine/spotlight'
7
+ import type { SpotlightActionData } from '@mantine/spotlight'
8
+ import { useCallback, useEffect, useState } from 'react'
9
+ import { buildSpotlightActions } from './spotlight-actions'
10
+ import type { SlotProps } from './slots'
11
+
12
+ export function SpotlightMount({ router, navCommandLabel, openDevTool }: SlotProps) {
13
+ // Rebuilt on mount and again at every open, so a command's `when()` is read when the palette
14
+ // appears, not frozen at mount — and `detectMac` (inside the builder) never runs during render.
15
+ const [actions, setActions] = useState<SpotlightActionData[]>([])
16
+ const refreshActions = useCallback(
17
+ () => setActions(buildSpotlightActions(router, openDevTool, navCommandLabel)),
18
+ [router, openDevTool, navCommandLabel],
19
+ )
20
+ useEffect(() => {
21
+ // oxlint-disable-next-line react/set-state-in-effect -- reads `navigator` and `when()`: never during render
22
+ refreshActions()
23
+ }, [refreshActions])
24
+
25
+ return (
26
+ <Spotlight
27
+ actions={actions}
28
+ onSpotlightOpen={refreshActions}
29
+ shortcut="mod + K"
30
+ maxHeight={420}
31
+ />
32
+ )
33
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The nav definition's runtime stash and its flatten reader, as a leaf (types only from `./nav`):
3
+ * `defineNav` fills it; Spotlight's action builder, the route transitions and the provider read it.
4
+ * Kept apart from `nav.ts` so no reader imports the module that registers the Spotlight mount.
5
+ */
6
+ import type { AnyNavGroup, AnyNavItem } from './nav'
7
+
8
+ /**
9
+ * The runtime stash `defineNav` fills (the last call wins, like `defineCommands`), read by
10
+ * `BasaltProvider` to project the nav into Spotlight. Type augmentation is erased, so this is the
11
+ * live source.
12
+ *
13
+ * @internal
14
+ */
15
+ let activeNav: { groups: ReadonlyArray<AnyNavGroup> } | undefined
16
+
17
+ /** @internal */
18
+ export function getActiveNav(): { groups: ReadonlyArray<AnyNavGroup> } | undefined {
19
+ return activeNav
20
+ }
21
+
22
+ /** @internal — `defineNav` only. The last call wins. */
23
+ export function setActiveNav(nav: { groups: ReadonlyArray<AnyNavGroup> }): void {
24
+ activeNav = nav
25
+ }
26
+
27
+ /** A flattened destination, tagged with the group it was declared in. */
28
+ export type FlatNavItem = AnyNavItem & { groupId: string; groupLabel: string }
29
+
30
+ /** Depth-first flatten, parent then children — the leaf every other surface reads. */
31
+ export function flattenNav(config: { groups: ReadonlyArray<AnyNavGroup> }): FlatNavItem[] {
32
+ const out: FlatNavItem[] = []
33
+ const walk = (items: ReadonlyArray<AnyNavItem>, groupId: string, groupLabel: string): void => {
34
+ for (const item of items) {
35
+ out.push({ ...item, groupId, groupLabel })
36
+ if (item.children) walk(item.children, groupId, groupLabel)
37
+ }
38
+ }
39
+ for (const g of config.groups) walk(g.items, g.id, g.label)
40
+ return out
41
+ }
@@ -9,10 +9,15 @@
9
9
  * silently. Compile-verified. A config whose selling point is "typos are compile errors" cannot
10
10
  * have a hole exactly where metadata typos live.
11
11
  *
12
- * No JSX and no Mantine in this module — `./router-tanstack` is a headless barrel by contract.
12
+ * No JSX and no Mantine in this module — `./router-tanstack` is a headless barrel by contract. The one
13
+ * exception is `defineNav`'s registration of the Spotlight mount (`../provider/slots`): nav entries
14
+ * feed the palette, and the mount is only reachable through this call.
13
15
  */
14
16
  import type { RegisteredRouter } from '@tanstack/react-router'
15
17
  import type { ReactNode } from 'react'
18
+ import { registerSlot } from '../provider/slots'
19
+ import { setActiveNav } from './nav-stash'
20
+ import { SpotlightMount } from '../provider/spotlight-mount'
16
21
  import type { NavMobilePlacement, NavSectionMobile } from '../shell/nav-types'
17
22
 
18
23
  // ── authoring shapes ─────────────────────────────────────────────────────────────────────────────
@@ -157,7 +162,9 @@ export function defineNav<
157
162
  const T extends ReadonlyArray<NavTabId<G>>,
158
163
  >(config: RegisteredOr<NavConfig<G, T>>): NavConfig<G, T> {
159
164
  const nav = config as unknown as NavConfig<G, T>
160
- activeNav = nav
165
+ setActiveNav(nav)
166
+ // Nav entries feed the palette, so defining the nav is what puts Spotlight in the bundle.
167
+ registerSlot('spotlight', SpotlightMount)
161
168
  return nav
162
169
  }
163
170
 
@@ -170,20 +177,6 @@ type RegisteredOr<T> = 0 extends 1 & RegisteredRouter['routeTree']
170
177
  ? 'basalt: declare Register { router }'
171
178
  : T
172
179
 
173
- /**
174
- * The runtime stash `defineNav` fills (the last call wins, like `defineCommands`), read by
175
- * `BasaltProvider` to project the nav into Spotlight. Type augmentation is erased, so this is the
176
- * live source.
177
- *
178
- * @internal
179
- */
180
- let activeNav: { groups: ReadonlyArray<AnyNavGroup> } | undefined
181
-
182
- /** @internal */
183
- export function getActiveNav(): { groups: ReadonlyArray<AnyNavGroup> } | undefined {
184
- return activeNav
185
- }
186
-
187
180
  // ── readers ──────────────────────────────────────────────────────────────────────────────────────
188
181
 
189
182
  function findById(items: ReadonlyArray<AnyNavItem>, id: string): AnyNavItem | undefined {
@@ -214,18 +207,5 @@ export function navTarget<
214
207
  throw new Error(`navTarget: no nav item with id "${id}"`)
215
208
  }
216
209
 
217
- /** A flattened destination, tagged with the group it was declared in. */
218
- export type FlatNavItem = AnyNavItem & { groupId: string; groupLabel: string }
219
-
220
- /** Depth-first flatten, parent then children — the leaf every other surface reads. */
221
- export function flattenNav(config: { groups: ReadonlyArray<AnyNavGroup> }): FlatNavItem[] {
222
- const out: FlatNavItem[] = []
223
- const walk = (items: ReadonlyArray<AnyNavItem>, groupId: string, groupLabel: string): void => {
224
- for (const item of items) {
225
- out.push({ ...item, groupId, groupLabel })
226
- if (item.children) walk(item.children, groupId, groupLabel)
227
- }
228
- }
229
- for (const g of config.groups) walk(g.items, g.id, g.label)
230
- return out
231
- }
210
+ export { flattenNav, getActiveNav } from './nav-stash'
211
+ export type { FlatNavItem } from './nav-stash'
@@ -13,7 +13,7 @@ import { createElement, forwardRef, useMemo } from 'react'
13
13
  import type { AnchorHTMLAttributes, ElementType, ReactNode } from 'react'
14
14
  import { Link, useMatchRoute, useRouterState } from '@tanstack/react-router'
15
15
  import type { MobileNavConfig, NavAnchor, SidebarItem, SidebarSection } from '../shell/nav-types'
16
- import { flattenNav } from './nav'
16
+ import { flattenNav } from './nav-stash'
17
17
  import type { AnyNavGroup, AnyNavItem, NavConfig, NavItemId, NavTabId } from './nav'
18
18
 
19
19
  export type UseNavOptions<G extends ReadonlyArray<AnyNavGroup>> = {
package/src/surfaces.ts CHANGED
@@ -407,7 +407,7 @@ export const SURFACES = {
407
407
  guardKinds: [],
408
408
  pluginRules: [],
409
409
  description:
410
- 'defineCommands (typed command bus), defineOverlays/overlays (a form dialog is a registered overlay opened with overlays.open), setColorScheme, toggleSidebar, ShortcutsHelp, defineNotifications/emit/NotificationBell (emit only accepts kinds registered in defineNotifications; folded in from ./notifications); BasaltProvider mounts Spotlight, Modals and Notifications',
410
+ 'defineCommands (typed command bus), defineOverlays/overlays (a form dialog is a registered overlay opened with overlays.open), setColorScheme, toggleSidebar, ShortcutsHelp, defineNotifications/emit/NotificationBell (emit only accepts kinds registered in defineNotifications; folded in from ./notifications); BasaltProvider mounts Notifications; Spotlight mounts once defineNav/defineCommands ran, Modals once defineOverlays/overlays.confirm ran',
411
411
  optionalPeers: ['@tanstack/react-hotkeys'],
412
412
  forbiddenImports: [],
413
413
  },