basalt-ui 2.12.0 → 2.13.1

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 (119) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/MIGRATING.md +50 -12
  3. package/agent/rules/basalt-state.md +1 -1
  4. package/agent/skills/basalt-app/SKILL.md +1 -1
  5. package/agent/templates/main.tpl +1 -0
  6. package/dist/cli/basalt-install.d.ts +10 -0
  7. package/dist/cli/basalt-install.d.ts.map +1 -0
  8. package/dist/cli/basalt-install.js +0 -0
  9. package/dist/cli/check-theme.js +1 -1
  10. package/dist/cli/doctor-upgrade.d.ts +3 -3
  11. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  12. package/dist/cli/doctor-upgrade.js +28 -44
  13. package/dist/cli/doctor.js +3 -3
  14. package/dist/cli/index.d.ts +4 -28
  15. package/dist/cli/index.d.ts.map +1 -1
  16. package/dist/cli/index.js +10 -49
  17. package/dist/cli/provider-tags.d.ts +12 -0
  18. package/dist/cli/provider-tags.d.ts.map +1 -0
  19. package/dist/cli/provider-tags.js +28 -0
  20. package/dist/cli/render-imports.d.ts +24 -0
  21. package/dist/cli/render-imports.d.ts.map +1 -0
  22. package/dist/cli/render-imports.js +74 -0
  23. package/dist/cli/router-wiring.d.ts +12 -0
  24. package/dist/cli/router-wiring.d.ts.map +1 -1
  25. package/dist/cli/router-wiring.js +18 -0
  26. package/dist/cli/source-text.d.ts +7 -0
  27. package/dist/cli/source-text.d.ts.map +1 -1
  28. package/dist/cli/source-text.js +34 -0
  29. package/dist/cli/sync.d.ts.map +1 -1
  30. package/dist/cli/sync.js +18 -13
  31. package/dist/guard/fonts-hint.d.ts +3 -0
  32. package/dist/guard/fonts-hint.d.ts.map +1 -0
  33. package/dist/guard/fonts-hint.js +4 -0
  34. package/dist/guard/index.d.ts +1 -1
  35. package/dist/guard/index.d.ts.map +1 -1
  36. package/dist/guard/index.js +2 -1
  37. package/dist/index.d.ts +3 -3
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +3 -1
  40. package/dist/provider/create-router.d.ts +57 -10
  41. package/dist/provider/create-router.d.ts.map +1 -1
  42. package/dist/provider/create-router.js +28 -17
  43. package/dist/provider/index.d.ts +2 -2
  44. package/dist/provider/index.d.ts.map +1 -1
  45. package/dist/provider/index.js +23 -7
  46. package/dist/query-client.d.ts +2 -62
  47. package/dist/query-client.d.ts.map +1 -1
  48. package/dist/query-client.js +13 -18
  49. package/dist/router-tanstack/nav.d.ts +5 -0
  50. package/dist/router-tanstack/nav.d.ts.map +1 -1
  51. package/dist/router-tanstack/search-store-warnings.d.ts +33 -0
  52. package/dist/router-tanstack/search-store-warnings.d.ts.map +1 -0
  53. package/dist/router-tanstack/search-store-warnings.js +77 -0
  54. package/dist/router-tanstack/search-store.d.ts +2 -5
  55. package/dist/router-tanstack/search-store.d.ts.map +1 -1
  56. package/dist/router-tanstack/search-store.js +111 -110
  57. package/dist/router-tanstack/use-nav.d.ts +4 -2
  58. package/dist/router-tanstack/use-nav.d.ts.map +1 -1
  59. package/dist/router-tanstack/use-nav.js +55 -18
  60. package/dist/shell/app-breadcrumbs.d.ts +1 -3
  61. package/dist/shell/app-breadcrumbs.d.ts.map +1 -1
  62. package/dist/shell/app-breadcrumbs.js +1 -6
  63. package/dist/shell/index.d.ts +14 -5
  64. package/dist/shell/index.d.ts.map +1 -1
  65. package/dist/shell/index.js +6 -29
  66. package/dist/shell/nav-types.d.ts +7 -0
  67. package/dist/shell/nav-types.d.ts.map +1 -1
  68. package/dist/shell/page-aside.d.ts +4 -2
  69. package/dist/shell/page-aside.d.ts.map +1 -1
  70. package/dist/shell/page-aside.js +41 -23
  71. package/dist/shell/page-bar.d.ts +1 -1
  72. package/dist/shell/page-bar.d.ts.map +1 -1
  73. package/dist/shell/page-bar.js +39 -33
  74. package/dist/telemetry.d.ts +31 -2
  75. package/dist/telemetry.d.ts.map +1 -1
  76. package/dist/telemetry.js +32 -12
  77. package/dist/theme/ctl-theme.d.ts.map +1 -1
  78. package/dist/theme/ctl-theme.js +17 -30
  79. package/dist/theme/extend.d.ts +18 -0
  80. package/dist/theme/extend.d.ts.map +1 -0
  81. package/dist/theme/extend.js +6 -0
  82. package/dist/theme/index.d.ts.map +1 -1
  83. package/dist/theme/index.js +44 -84
  84. package/dist/unwrap.d.ts +29 -0
  85. package/dist/unwrap.d.ts.map +1 -0
  86. package/dist/unwrap.js +18 -0
  87. package/llms.txt +9 -5
  88. package/package.json +1 -1
  89. package/src/cli/basalt-install.ts +9 -0
  90. package/src/cli/check-theme.ts +1 -1
  91. package/src/cli/doctor-upgrade.ts +40 -61
  92. package/src/cli/doctor.ts +3 -3
  93. package/src/cli/index.ts +14 -71
  94. package/src/cli/provider-tags.ts +38 -0
  95. package/src/cli/render-imports.ts +104 -0
  96. package/src/cli/router-wiring.ts +23 -0
  97. package/src/cli/source-text.ts +39 -0
  98. package/src/cli/sync.ts +27 -21
  99. package/src/guard/fonts-hint.ts +2 -0
  100. package/src/guard/index.ts +2 -2
  101. package/src/index.ts +4 -2
  102. package/src/provider/create-router.tsx +103 -39
  103. package/src/provider/index.tsx +27 -9
  104. package/src/query-client.ts +20 -78
  105. package/src/router-tanstack/nav.ts +5 -0
  106. package/src/router-tanstack/search-store-warnings.ts +120 -0
  107. package/src/router-tanstack/search-store.ts +200 -206
  108. package/src/router-tanstack/use-nav.ts +116 -76
  109. package/src/shell/app-breadcrumbs.tsx +1 -12
  110. package/src/shell/index.tsx +22 -55
  111. package/src/shell/nav-types.ts +8 -0
  112. package/src/shell/page-aside.tsx +59 -26
  113. package/src/shell/page-bar.tsx +63 -59
  114. package/src/telemetry.ts +71 -13
  115. package/src/theme/__snapshots__/plain-theme.test.ts.snap +2354 -0
  116. package/src/theme/ctl-theme.tsx +20 -19
  117. package/src/theme/extend.ts +18 -0
  118. package/src/theme/index.ts +50 -49
  119. package/src/unwrap.ts +44 -0
@@ -22,7 +22,7 @@
22
22
  * Originally extracted from argo's `apps/dashboard/src/components/app-shell/page-header.tsx`;
23
23
  * linewatch's `page-header.tsx` measure-and-publish effect became the framework behaviour below.
24
24
  */
25
- import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react'
25
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'
26
26
  import type { ReactNode } from 'react'
27
27
  import { createPortal } from 'react-dom'
28
28
  import { cx } from '../common/props'
@@ -50,7 +50,7 @@ export const PAGE_BAR_HEIGHT_VAR = '--basalt-page-bar-h'
50
50
  * What a `PageAside` publishes when it projects itself into row 2 below `sm`
51
51
  * (`docs/ASIDE-SPEC.md` §0 "Desktop and mobile are one declaration"). Metadata only — the aside's
52
52
  * CHILDREN never travel through this context: they are portalled into the sheet's own node
53
- * ({@link PageBarSlots.panelTarget}), because a `ReactNode` in state would be a fresh object on
53
+ * ({@link AsidePanelSlot.panelTarget}), because a `ReactNode` in state would be a fresh object on
54
54
  * every parent render and the claim effect would loop.
55
55
  */
56
56
  export type AsidePanelClaim = {
@@ -60,49 +60,36 @@ export type AsidePanelClaim = {
60
60
  readonly icon: ReactNode
61
61
  }
62
62
 
63
- type PageBarSlots = {
63
+ /** Narrow, memoized contexts: a reader of one is not re-rendered by a change to another. */
64
+ type PortalTargets = {
64
65
  /** The header node row 1 portals into. `null` outside a shell, and until the outlet mounts. */
65
66
  target: HTMLElement | null
66
67
  setTarget: (el: HTMLElement | null) => void
67
- /**
68
- * The BAND node row 2 portals into — a shell-owned box between the header and the scrollport.
69
- * Same mechanism as `target` one region down, and it exists for the same reason: where a row
70
- * renders must not depend on where the consumer wrote `<PageBar>` in its page tree. Row 2 used to
71
- * render in flow at the top of Main and stick there, which meant a bar nested inside a `Stack`
72
- * (every real page) had `position: sticky` clamped to that wrapper and sat one shell padding low.
73
- * `null` outside a shell, and until the outlet mounts.
74
- */
68
+ /** The shell-owned band between the header and the scrollport that row 2 portals into. */
75
69
  bandTarget: HTMLElement | null
76
70
  setBandTarget: (el: HTMLElement | null) => void
77
- /** True only under `BasaltShell` — the provider is shell-internal, so the context IS the probe. */
78
- inShell: boolean
79
- /** Shell `globalActions` marked `mobile: 'more'`, already shaped as kebab rows. */
80
- mobileMoreActions: readonly BarAction[]
81
- /** How many page kebabs are mounted. `> 0` means the shell must not render one of its own. */
82
- kebabClaims: number
83
- claimKebab: () => () => void
84
- /** True while a mounted `PageBar` is rendering a row 2 — the row that can host the aside's pill.
85
- * Without one the aside keeps its in-flow mobile form; there is nowhere to put the trigger. */
71
+ }
72
+
73
+ type AsidePanelSlot = {
74
+ /** True while a mounted `PageBar` renders a row 2 (the only host for the aside's pill). */
86
75
  panelHost: boolean
87
76
  claimPanelHost: () => () => void
88
- /** The projecting aside, or `null`. At most one — the aside region holds one page at a time. */
77
+ /** The projecting aside, or `null`. */
89
78
  panel: AsidePanelClaim | null
90
79
  claimPanel: (panel: AsidePanelClaim) => () => void
91
- /** The node inside the open panel sheet the aside's children portal into. `null` while closed —
92
- * the Drawer unmounts its body, which is what keeps ONE node mounted at a time (law C9). */
80
+ /** The node inside the open panel sheet the aside's children portal into; `null` while closed. */
93
81
  panelTarget: HTMLElement | null
94
82
  setPanelTarget: (el: HTMLElement | null) => void
95
83
  }
96
84
 
97
- const NO_SLOTS: PageBarSlots = {
85
+ const NO_TARGETS: PortalTargets = {
98
86
  target: null,
99
87
  setTarget: () => {},
100
88
  bandTarget: null,
101
89
  setBandTarget: () => {},
102
- inShell: false,
103
- mobileMoreActions: [],
104
- kebabClaims: 0,
105
- claimKebab: () => () => {},
90
+ }
91
+
92
+ const NO_PANEL_SLOT: AsidePanelSlot = {
106
93
  panelHost: false,
107
94
  claimPanelHost: () => () => {},
108
95
  panel: null,
@@ -111,7 +98,12 @@ const NO_SLOTS: PageBarSlots = {
111
98
  setPanelTarget: () => {},
112
99
  }
113
100
 
114
- const PageBarContext = createContext<PageBarSlots>(NO_SLOTS)
101
+ const PortalTargetsContext = createContext<PortalTargets>(NO_TARGETS)
102
+ const AsidePanelContext = createContext<AsidePanelSlot>(NO_PANEL_SLOT)
103
+ /** True only under `BasaltShell` — the provider is shell-internal, so the context IS the probe. */
104
+ const InShellContext = createContext(false)
105
+ /** True while a page's `ActionGroup` holds the header's one mobile kebab. */
106
+ const KebabClaimedContext = createContext(false)
115
107
 
116
108
  /**
117
109
  * Internal — mounted by `BasaltShell`. Owns the portal target, and the single-kebab claim that
@@ -151,37 +143,47 @@ export function PageBarProvider({
151
143
  }
152
144
  }, [])
153
145
 
154
- const mobileMoreActions = globalActions
155
- .filter((action, index) => (action.mobile ?? (index < 2 ? 'bar' : 'more')) === 'more')
156
- .map(globalActionAsBarAction)
157
-
158
- const value: PageBarSlots = {
159
- target,
160
- setTarget,
161
- bandTarget,
162
- setBandTarget,
163
- inShell: true,
164
- mobileMoreActions,
165
- kebabClaims,
166
- claimKebab,
167
- panelHost: panelHostClaims > 0,
168
- claimPanelHost,
169
- panel,
170
- claimPanel,
171
- panelTarget,
172
- setPanelTarget,
173
- }
146
+ const mobileMoreActions = useMemo(
147
+ () =>
148
+ globalActions
149
+ .filter((action, index) => (action.mobile ?? (index < 2 ? 'bar' : 'more')) === 'more')
150
+ .map(globalActionAsBarAction),
151
+ [globalActions],
152
+ )
153
+
154
+ const targets = useMemo(
155
+ () => ({ target, setTarget, bandTarget, setBandTarget }),
156
+ [target, bandTarget],
157
+ )
158
+ const panelSlot = useMemo(
159
+ () => ({
160
+ panelHost: panelHostClaims > 0,
161
+ claimPanelHost,
162
+ panel,
163
+ claimPanel,
164
+ panelTarget,
165
+ setPanelTarget,
166
+ }),
167
+ [panelHostClaims, claimPanelHost, panel, claimPanel, panelTarget],
168
+ )
169
+ const extras = useMemo(() => ({ mobileMoreActions, claimKebab }), [mobileMoreActions, claimKebab])
174
170
 
175
171
  return (
176
- <PageBarContext.Provider value={value}>
177
- <BarExtrasProvider value={{ mobileMoreActions, claimKebab }}>{children}</BarExtrasProvider>
178
- </PageBarContext.Provider>
172
+ <InShellContext.Provider value>
173
+ <PortalTargetsContext.Provider value={targets}>
174
+ <KebabClaimedContext.Provider value={kebabClaims > 0}>
175
+ <AsidePanelContext.Provider value={panelSlot}>
176
+ <BarExtrasProvider value={extras}>{children}</BarExtrasProvider>
177
+ </AsidePanelContext.Provider>
178
+ </KebabClaimedContext.Provider>
179
+ </PortalTargetsContext.Provider>
180
+ </InShellContext.Provider>
179
181
  )
180
182
  }
181
183
 
182
184
  /** Internal — the app-shell header node the active page's row 1 portals into. */
183
185
  export function PageBarOutlet({ className }: { className?: string }) {
184
- const { setTarget } = useContext(PageBarContext)
186
+ const { setTarget } = useContext(PortalTargetsContext)
185
187
  return <div ref={setTarget} className={className} />
186
188
  }
187
189
 
@@ -195,7 +197,7 @@ export function PageBarOutlet({ className }: { className?: string }) {
195
197
  * `app-main.module.css` is what makes "nothing mounted" and "nothing painted" the same state.
196
198
  */
197
199
  export function PageBarBandOutlet({ className }: { className?: string }) {
198
- const { setBandTarget } = useContext(PageBarContext)
200
+ const { setBandTarget } = useContext(PortalTargetsContext)
199
201
  return <div ref={setBandTarget} className={className} />
200
202
  }
201
203
 
@@ -205,12 +207,12 @@ export function PageBarBandOutlet({ className }: { className?: string }) {
205
207
  * sticky in the document and `Section` must clear it.
206
208
  */
207
209
  export function useInPageBarShell(): boolean {
208
- return useContext(PageBarContext).inShell
210
+ return useContext(InShellContext)
209
211
  }
210
212
 
211
213
  /** Internal — `true` while a page's `ActionGroup` owns the header's one mobile kebab. */
212
214
  export function usePageKebabClaimed(): boolean {
213
- return useContext(PageBarContext).kebabClaims > 0
215
+ return useContext(KebabClaimedContext)
214
216
  }
215
217
 
216
218
  /**
@@ -236,7 +238,8 @@ export function useAsidePanelSlot(): {
236
238
  claim: (panel: AsidePanelClaim) => () => void
237
239
  target: HTMLElement | null
238
240
  } {
239
- const { panelHost, claimPanel, panelTarget, inShell } = useContext(PageBarContext)
241
+ const { panelHost, claimPanel, panelTarget } = useContext(AsidePanelContext)
242
+ const inShell = useContext(InShellContext)
240
243
  const [settled, setSettled] = useState(false)
241
244
  useIsomorphicLayoutEffect(() => {
242
245
  setSettled(true)
@@ -398,8 +401,9 @@ export function PageBar({
398
401
  style,
399
402
  classNames,
400
403
  }: PageBarProps): ReactNode {
401
- const { target, bandTarget, inShell, panel, claimPanelHost, setPanelTarget } =
402
- useContext(PageBarContext)
404
+ const { target, bandTarget } = useContext(PortalTargetsContext)
405
+ const { panel, claimPanelHost, setPanelTarget } = useContext(AsidePanelContext)
406
+ const inShell = useContext(InShellContext)
403
407
  // An overlay's open flag, like `FilterPill`'s and `FilterSet`'s — not page state (C3).
404
408
  const [panelOpened, setPanelOpened] = useState(false)
405
409
 
package/src/telemetry.ts CHANGED
@@ -58,8 +58,21 @@ type ChatAttrs = {
58
58
  export type BasaltEvent =
59
59
  | Ok<'route.navigate', RouteAttrs>
60
60
  | Err<'route.error', { 'basalt.route.id': string }>
61
- | Err<'query.error', { 'basalt.query.hash': string; 'basalt.query.failure_count': number }>
62
- | Err<'mutation.error', { 'basalt.mutation.key': string }>
61
+ | Err<
62
+ 'query.error',
63
+ {
64
+ /** `groupingId(queryHash)`: an opaque grouping id, not the key. */
65
+ 'basalt.query.hash': string
66
+ 'basalt.query.failure_count': number
67
+ }
68
+ >
69
+ | Err<
70
+ 'mutation.error',
71
+ {
72
+ /** `groupingId(JSON.stringify(key))`: an opaque grouping id, not the key. */
73
+ 'basalt.mutation.key': string
74
+ }
75
+ >
63
76
  | Err<'render.error', { 'basalt.error.boundary': 'root' }>
64
77
  | Err<'window.error', { 'basalt.error.source': 'error' | 'unhandledrejection' }>
65
78
  | Ok<'chat.turn', ChatAttrs>
@@ -128,6 +141,26 @@ export type Telemetry = ((event: BasaltEvent) => void) & {
128
141
 
129
142
  export const now = (): number => performance.timeOrigin + performance.now()
130
143
 
144
+ /**
145
+ * An opaque grouping id (32-bit djb2, hex) for a query or mutation key, so events from one key group
146
+ * together and the key's segments (ids, slugs) stay out of the event. NOT a privacy guarantee: it is
147
+ * non-cryptographic and a short or guessable key can be recovered by trying candidates.
148
+ */
149
+ export function groupingId(value: string): string {
150
+ let h = 5381
151
+ for (let i = 0; i < value.length; i++) h = (h * 33) ^ value.charCodeAt(i)
152
+ return (h >>> 0).toString(16)
153
+ }
154
+
155
+ /**
156
+ * The sink an unset `telemetry` gets outside production: query and mutation failures, which nothing
157
+ * else surfaces (route, render and window errors already log themselves). Ids and error names only.
158
+ */
159
+ export const devConsoleSink: Telemetry = (event) => {
160
+ if (event.type === 'query.error' || event.type === 'mutation.error')
161
+ console.error(`[basalt] ${event.type}`, event.attributes)
162
+ }
163
+
131
164
  /** `error.name`, `'Error'` for a non-`Error` throw. */
132
165
  export const errorName = (error: unknown): string => (error instanceof Error ? error.name : 'Error')
133
166
 
@@ -155,24 +188,49 @@ export function createLiveEmitter(read: () => Telemetry | undefined): Telemetry
155
188
  })
156
189
  }
157
190
 
158
- function noop(): void {}
159
-
160
191
  /**
161
192
  * The provider's wrapped emitter, for hooks that emit their own events (`useAgentThreadRuns`'
162
193
  * `chat.turn`). `undefined` outside a `BasaltProvider`, where such a hook emits nothing.
163
194
  */
164
195
  export const TelemetryContext = createContext<Telemetry | undefined>(undefined)
165
196
 
166
- /** The event sink of the provider mounted on a router, read by `createBasaltRouter`'s `onCatch`. */
167
- const routerSinks = new WeakMap<object, Telemetry>()
197
+ /**
198
+ * On `context.__basalt` of a `basaltRouterOptions` router: where its `defaultOnCatch` reports to.
199
+ * The factory and `bindRouteError` are the only two places that know this key.
200
+ */
201
+ export type RouterHook = { onRouteError?: ((error: unknown) => void) | undefined }
168
202
 
169
- export function bindRouterTelemetry(router: object, emit: Telemetry): () => void {
170
- routerSinks.set(router, emit)
171
- return () => {
172
- if (routerSinks.get(router) === emit) routerSinks.delete(router)
173
- }
203
+ function hookOf(context: unknown): RouterHook | undefined {
204
+ if (typeof context !== 'object' || context === null || !('__basalt' in context)) return undefined
205
+ const hook = context.__basalt
206
+ return typeof hook === 'object' && hook !== null ? hook : undefined
174
207
  }
175
208
 
176
- export function routerTelemetry(router: object): Telemetry {
177
- return routerSinks.get(router) ?? noop
209
+ const MISSING_HOOK =
210
+ '[basalt] route.error telemetry is off: the router was not built with `basaltRouterOptions()` (or `createBasaltRouter`).'
211
+ let warnedMissingHook = false
212
+
213
+ /**
214
+ * Points the router's `route.error` hook at `handler` (the provider's emitter); returns the unbind.
215
+ * The binding happens in the provider's effect, so a route error thrown before the first provider
216
+ * effect (a loader failing during the initial load) reaches the console only, never the sink. A
217
+ * router without the hook was not built with `basaltRouterOptions`: nothing is bound and it warns.
218
+ */
219
+ export function bindRouteError(
220
+ router: { options: { context?: unknown } },
221
+ handler: (error: unknown) => void,
222
+ ): () => void {
223
+ const hook = hookOf(router.options.context)
224
+ if (!hook) {
225
+ // Dev warns on every bind; production once per document.
226
+ if (process.env.NODE_ENV !== 'production' || !warnedMissingHook) {
227
+ warnedMissingHook = true
228
+ console.warn(MISSING_HOOK)
229
+ }
230
+ return () => {}
231
+ }
232
+ hook.onRouteError = handler
233
+ return () => {
234
+ if (hook.onRouteError === handler) hook.onRouteError = undefined
235
+ }
178
236
  }