basalt-ui 2.11.1 → 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.
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +16 -0
- package/MIGRATING.md +24 -12
- package/README.md +2 -0
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/skills/basalt-app/SKILL.md +1 -1
- package/dist/cli/doctor-upgrade.d.ts +2 -3
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +71 -26
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +2 -1
- package/dist/commands/command-stash.d.ts +15 -0
- package/dist/commands/command-stash.d.ts.map +1 -0
- package/dist/commands/command-stash.js +31 -0
- package/dist/commands/define-commands.d.ts +2 -3
- package/dist/commands/define-commands.d.ts.map +1 -1
- package/dist/commands/define-commands.js +9 -7
- package/dist/commands/define-overlays.d.ts +6 -12
- package/dist/commands/define-overlays.d.ts.map +1 -1
- package/dist/commands/define-overlays.js +28 -34
- package/dist/commands/projectors.js +1 -1
- package/dist/provider/hotkeys.d.ts +2 -6
- package/dist/provider/hotkeys.d.ts.map +1 -1
- package/dist/provider/hotkeys.js +10 -15
- package/dist/provider/index.d.ts +5 -3
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +12 -35
- package/dist/provider/modals-mount.d.ts +16 -0
- package/dist/provider/modals-mount.d.ts.map +1 -0
- package/dist/provider/modals-mount.js +42 -0
- package/dist/provider/notifier.d.ts +22 -0
- package/dist/provider/notifier.d.ts.map +1 -0
- package/dist/provider/notifier.js +36 -0
- package/dist/provider/route-transition.d.ts +1 -1
- package/dist/provider/route-transition.d.ts.map +1 -1
- package/dist/provider/route-transition.js +1 -1
- package/dist/provider/slots.d.ts +25 -0
- package/dist/provider/slots.d.ts.map +1 -0
- package/dist/provider/slots.js +29 -0
- package/dist/provider/spotlight-actions.d.ts +1 -1
- package/dist/provider/spotlight-actions.d.ts.map +1 -1
- package/dist/provider/spotlight-actions.js +2 -3
- package/dist/provider/spotlight-mount.d.ts +3 -0
- package/dist/provider/spotlight-mount.d.ts.map +1 -0
- package/dist/provider/spotlight-mount.js +26 -0
- package/dist/router-tanstack/nav-stash.d.ts +24 -0
- package/dist/router-tanstack/nav-stash.d.ts.map +1 -0
- package/dist/router-tanstack/nav-stash.js +23 -0
- package/dist/router-tanstack/nav.d.ts +5 -15
- package/dist/router-tanstack/nav.d.ts.map +1 -1
- package/dist/router-tanstack/nav.js +6 -16
- package/dist/router-tanstack/use-nav.js +1 -1
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.js +1 -1
- package/llms.txt +4 -4
- package/package.json +2 -2
- package/src/cli/doctor-upgrade.ts +101 -35
- package/src/cli/index.ts +5 -3
- package/src/cli/sync.ts +2 -2
- package/src/commands/command-stash.ts +44 -0
- package/src/commands/define-commands.ts +10 -17
- package/src/commands/define-overlays.ts +40 -68
- package/src/commands/projectors.ts +1 -1
- package/src/provider/hotkeys.ts +14 -22
- package/src/provider/index.tsx +28 -52
- package/src/provider/modals-mount.tsx +66 -0
- package/src/provider/notifier.ts +52 -0
- package/src/provider/route-transition.ts +1 -1
- package/src/provider/slots.ts +59 -0
- package/src/provider/spotlight-actions.tsx +3 -4
- package/src/provider/spotlight-mount.tsx +33 -0
- package/src/router-tanstack/nav-stash.ts +41 -0
- package/src/router-tanstack/nav.ts +11 -31
- package/src/router-tanstack/use-nav.ts +1 -1
- package/src/surfaces.ts +1 -1
|
@@ -9,7 +9,9 @@
|
|
|
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';
|
|
@@ -146,10 +148,6 @@ export declare function defineNav<const G extends ReadonlyArray<AnyNavGroup>, co
|
|
|
146
148
|
* literal whose text is the fix (V2-SPEC § 3).
|
|
147
149
|
*/
|
|
148
150
|
type RegisteredOr<T> = 0 extends 1 & RegisteredRouter['routeTree'] ? 'basalt: declare Register { router }' : T;
|
|
149
|
-
/** @internal */
|
|
150
|
-
export declare function getActiveNav(): {
|
|
151
|
-
groups: ReadonlyArray<AnyNavGroup>;
|
|
152
|
-
} | undefined;
|
|
153
151
|
/**
|
|
154
152
|
* The link options for one destination, by id. Spreadable into `<Link>`, `router.navigate()`
|
|
155
153
|
* and `redirect()`. This is what collapses a consumer's Spotlight commands and index redirect.
|
|
@@ -161,14 +159,6 @@ export declare function getActiveNav(): {
|
|
|
161
159
|
export declare function navTarget<const C extends {
|
|
162
160
|
groups: ReadonlyArray<AnyNavGroup>;
|
|
163
161
|
}, K extends NavItemId<C['groups']>>(config: C, id: K): NavIndex<C['groups']>[K];
|
|
164
|
-
|
|
165
|
-
export type FlatNavItem
|
|
166
|
-
groupId: string;
|
|
167
|
-
groupLabel: string;
|
|
168
|
-
};
|
|
169
|
-
/** Depth-first flatten, parent then children — the leaf every other surface reads. */
|
|
170
|
-
export declare function flattenNav(config: {
|
|
171
|
-
groups: ReadonlyArray<AnyNavGroup>;
|
|
172
|
-
}): FlatNavItem[];
|
|
173
|
-
export {};
|
|
162
|
+
export { flattenNav, getActiveNav } from './nav-stash.js';
|
|
163
|
+
export type { FlatNavItem } from './nav-stash.js';
|
|
174
164
|
//# sourceMappingURL=nav.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nav.d.ts","sourceRoot":"","sources":["../../src/router-tanstack/nav.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"nav.d.ts","sourceRoot":"","sources":["../../src/router-tanstack/nav.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { registerSlot } from "../provider/slots.js";
|
|
2
|
+
import { setActiveNav } from "./nav-stash.js";
|
|
3
|
+
import { SpotlightMount } from "../provider/spotlight-mount.js";
|
|
1
4
|
function navGroup(meta, items) {
|
|
2
5
|
return { ...meta, items };
|
|
3
6
|
}
|
|
4
7
|
function defineNav(config) {
|
|
5
8
|
const nav = config;
|
|
6
|
-
|
|
9
|
+
setActiveNav(nav);
|
|
10
|
+
registerSlot("spotlight", SpotlightMount);
|
|
7
11
|
return nav;
|
|
8
12
|
}
|
|
9
|
-
let activeNav;
|
|
10
|
-
function getActiveNav() {
|
|
11
|
-
return activeNav;
|
|
12
|
-
}
|
|
13
13
|
function findById(items, id) {
|
|
14
14
|
for (const item of items) {
|
|
15
15
|
if (item.id === id) return item;
|
|
@@ -25,17 +25,7 @@ function navTarget(config, id) {
|
|
|
25
25
|
}
|
|
26
26
|
throw new Error(`navTarget: no nav item with id "${id}"`);
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
const out = [];
|
|
30
|
-
const walk = (items, groupId, groupLabel) => {
|
|
31
|
-
for (const item of items) {
|
|
32
|
-
out.push({ ...item, groupId, groupLabel });
|
|
33
|
-
if (item.children) walk(item.children, groupId, groupLabel);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
for (const g of config.groups) walk(g.items, g.id, g.label);
|
|
37
|
-
return out;
|
|
38
|
-
}
|
|
28
|
+
import { flattenNav, getActiveNav } from "./nav-stash.js";
|
|
39
29
|
export {
|
|
40
30
|
defineNav,
|
|
41
31
|
flattenNav,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createElement, forwardRef, useMemo } from "react";
|
|
2
2
|
import { Link, useMatchRoute, useRouterState } from "@tanstack/react-router";
|
|
3
|
-
import { flattenNav } from "./nav.js";
|
|
3
|
+
import { flattenNav } from "./nav-stash.js";
|
|
4
4
|
const OverriddenAnchor = forwardRef((props, ref) => {
|
|
5
5
|
const {
|
|
6
6
|
"aria-current": _routerCurrent,
|
package/dist/surfaces.d.ts
CHANGED
|
@@ -248,7 +248,7 @@ export declare const SURFACES: {
|
|
|
248
248
|
readonly skill: readonly ["basalt-app"];
|
|
249
249
|
readonly guardKinds: readonly [];
|
|
250
250
|
readonly pluginRules: readonly [];
|
|
251
|
-
readonly description: "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
|
|
251
|
+
readonly description: "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";
|
|
252
252
|
readonly optionalPeers: readonly ["@tanstack/react-hotkeys"];
|
|
253
253
|
readonly forbiddenImports: readonly [];
|
|
254
254
|
};
|
package/dist/surfaces.js
CHANGED
|
@@ -207,7 +207,7 @@ const SURFACES = {
|
|
|
207
207
|
skill: ["basalt-app"],
|
|
208
208
|
guardKinds: [],
|
|
209
209
|
pluginRules: [],
|
|
210
|
-
description: "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
|
|
210
|
+
description: "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",
|
|
211
211
|
optionalPeers: ["@tanstack/react-hotkeys"],
|
|
212
212
|
forbiddenImports: []
|
|
213
213
|
},
|
package/llms.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# basalt-ui v2.
|
|
1
|
+
# basalt-ui v2.12.0
|
|
2
2
|
# Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets
|
|
3
3
|
#
|
|
4
4
|
# Entry points: use the exact import specifier below; do not guess.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# A subpath's `Install:` line is its required peers; `OptionalPeers:` are import()-only, install on use.
|
|
14
14
|
|
|
15
15
|
Package: basalt-ui
|
|
16
|
-
Version: 2.
|
|
16
|
+
Version: 2.12.0
|
|
17
17
|
|
|
18
18
|
## basalt-ui
|
|
19
19
|
Import: import { ... } from 'basalt-ui'
|
|
@@ -535,7 +535,7 @@ Install: bun add @mantine/form@^9.7.0
|
|
|
535
535
|
|
|
536
536
|
## basalt-ui/commands
|
|
537
537
|
Import: import { ... } from 'basalt-ui/commands'
|
|
538
|
-
Description: 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
|
|
538
|
+
Description: 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
|
|
539
539
|
Layer: mantine-coupled
|
|
540
540
|
Rule: basalt-batteries
|
|
541
541
|
Signature: NotificationBell(props: NotificationBellProps): JSX.Element
|
|
@@ -688,7 +688,7 @@ Signature: useAgentThreadRuns(props: UseAgentThreadRunsArgs<TPart>): UseAgentThr
|
|
|
688
688
|
onError?: ((info: { readonly threadId: string; readonly error: unknow…
|
|
689
689
|
throttle?: number
|
|
690
690
|
telemetry?: Telemetry
|
|
691
|
-
Install: bun add ai@^7.0.137 @ai-sdk/provider@^4.0.26 motion
|
|
691
|
+
Install: bun add ai@^7.0.137 @ai-sdk/provider@^4.0.26 motion@^14.1.0
|
|
692
692
|
OptionalPeers: use-stick-to-bottom@^1.1.6, @tanstack/react-virtual@>=3.14.0 <4
|
|
693
693
|
|
|
694
694
|
## basalt-ui/content
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "basalt-ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"charts",
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
"beautiful-mermaid": "^1.1.0",
|
|
190
190
|
"d3-scale": "4.0.2",
|
|
191
191
|
"dayjs": "^1.11.0",
|
|
192
|
-
"motion": "14.1.0",
|
|
192
|
+
"motion": "^14.1.0",
|
|
193
193
|
"react": "^19.3.0",
|
|
194
194
|
"react-dom": "^19.3.0",
|
|
195
195
|
"react-markdown": "^10.1.0",
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* `doctor`'s 2.0 strictness and upgrade checks. Each returns null (pass), `{ fail }` (the problem
|
|
3
3
|
* plus its fix) or `{ skip }` (the check could not run: a check that cannot run is not a pass).
|
|
4
4
|
*/
|
|
5
|
-
import { writeFileSync } from 'node:fs'
|
|
5
|
+
import { readdirSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import type { Dirent } from 'node:fs'
|
|
6
7
|
import { createRequire } from 'node:module'
|
|
7
8
|
import { dirname, relative, resolve } from 'node:path'
|
|
8
9
|
|
|
9
10
|
import { BASALT_CONFIG_KEYS, RETIRED_CONFIG_KEYS, shellConfigError } from './config'
|
|
10
11
|
import type { BasaltConfig } from './config'
|
|
11
|
-
import { parseJsonc, routerSeedDest, scannableFiles } from './index'
|
|
12
|
+
import { START_PROVIDER_HINT, parseJsonc, routerSeedDest, scannableFiles } from './index'
|
|
12
13
|
import type { BasaltInstall } from './index'
|
|
13
14
|
import {
|
|
14
15
|
appEntry,
|
|
@@ -405,51 +406,116 @@ function providerTags(src: string): ProviderTag[] {
|
|
|
405
406
|
|
|
406
407
|
const carriesRouter = (tag: ProviderTag): boolean => /(^|\s)router\s*=/.test(tag.attrs)
|
|
407
408
|
|
|
409
|
+
/** `_app.tsx` or `_app/route.tsx` at any depth: a pathless layout (`_app.map.tsx` is a child, `__root` is the root). */
|
|
410
|
+
const PATHLESS_LAYOUT = /(^|\/)(_[^_./][^./]*\.[jt]sx|_[^_./][^./]*\/route\.[jt]sx)$/
|
|
411
|
+
|
|
412
|
+
/** Every file under `rel`, recursively; an unreadable directory has no files. */
|
|
413
|
+
function filesUnder(cwd: string, rel: string): string[] {
|
|
414
|
+
let entries: Dirent[]
|
|
415
|
+
try {
|
|
416
|
+
entries = readdirSync(resolve(cwd, rel), { withFileTypes: true })
|
|
417
|
+
} catch {
|
|
418
|
+
return []
|
|
419
|
+
}
|
|
420
|
+
return entries.flatMap((e) =>
|
|
421
|
+
e.isDirectory() ? filesUnder(cwd, `${rel}/${e.name}`) : [`${rel}/${e.name}`],
|
|
422
|
+
)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
type RouteFile = { file: string; text: string | null; tags: ProviderTag[] }
|
|
426
|
+
|
|
427
|
+
/** The root route and every pathless layout, each read once; `text` is null for a missing file. */
|
|
428
|
+
function startProviderFiles(cwd: string): { root: RouteFile; layouts: RouteFile[] } {
|
|
429
|
+
const rootFile = routerSeedDest('', 'root')
|
|
430
|
+
const routesDir = dirname(rootFile)
|
|
431
|
+
const load = (file: string): RouteFile => {
|
|
432
|
+
const text = readIfExists(resolve(cwd, file))
|
|
433
|
+
return { file, text, tags: providerTags(text ?? '') }
|
|
434
|
+
}
|
|
435
|
+
const layouts = filesUnder(cwd, routesDir)
|
|
436
|
+
.filter((f) => PATHLESS_LAYOUT.test(f.slice(routesDir.length + 1)))
|
|
437
|
+
.toSorted()
|
|
438
|
+
return { root: load(rootFile), layouts: layouts.map(load) }
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* How the exported root route is created: `createRootRouteWithContext` is typed (TypeScript gates the
|
|
443
|
+
* context at `createRouter`), `createRootRoute` is not. Anything else (a re-export, a wrapper, no
|
|
444
|
+
* `export const Route`) is null and never fails. A type annotation on `Route` is allowed.
|
|
445
|
+
*/
|
|
446
|
+
function rootRouteKind(src: string): 'typed' | 'untyped' | null {
|
|
447
|
+
const kind =
|
|
448
|
+
/\bexport\s+const\s+Route\s*(?::[^=]+)?=\s*(createRootRouteWithContext|createRootRoute)\b/.exec(
|
|
449
|
+
tokenize(src).code,
|
|
450
|
+
)?.[1]
|
|
451
|
+
if (kind === undefined) return null
|
|
452
|
+
return kind === 'createRootRoute' ? 'untyped' : 'typed'
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const fail = (problem: string, fix: string): { fail: string } => ({
|
|
456
|
+
fail: `app-wiring: ${problem} (TanStack Start app). Fix: ${fix}.`,
|
|
457
|
+
})
|
|
458
|
+
|
|
408
459
|
/**
|
|
409
|
-
* A Start app owns its router and entry: the wiring is
|
|
410
|
-
* in
|
|
411
|
-
* inside Start's, so it
|
|
460
|
+
* A Start app owns its router and entry: the wiring is ONE embedded `<BasaltProvider>` tag (no
|
|
461
|
+
* `router=`) around `<Outlet />`, in the root route or a pathless layout (a landing kept at 0 JS
|
|
462
|
+
* mounts it in the layout). ANY tag with `router=` mounts a second router inside Start's, so it
|
|
463
|
+
* fails even beside an embedded one. The exported root route must not be a bare `createRootRoute(`:
|
|
464
|
+
* the provider reads `context.queryClient`. Only that untyped form fails — a re-export, wrapper or
|
|
465
|
+
* missing `Route` export is skipped silently, and the context's type argument is left to TypeScript.
|
|
412
466
|
*/
|
|
413
467
|
function startWiring(cwd: string): { fail: string } | null {
|
|
414
|
-
const root =
|
|
415
|
-
const
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
468
|
+
const { root, layouts } = startProviderFiles(cwd)
|
|
469
|
+
const withTags = [root, ...layouts].filter((f) => f.tags.length > 0)
|
|
470
|
+
const mounting = withTags.find((f) => f.tags.some(carriesRouter))
|
|
471
|
+
if (mounting) {
|
|
472
|
+
return fail(
|
|
473
|
+
`${mounting.file} passes router= to BasaltProvider, which mounts a second router inside Start`,
|
|
474
|
+
START_PROVIDER_HINT,
|
|
475
|
+
)
|
|
476
|
+
}
|
|
477
|
+
const [first] = withTags
|
|
478
|
+
if (first === undefined) {
|
|
479
|
+
const problem =
|
|
480
|
+
root.text === null
|
|
481
|
+
? `${root.file} does not exist and no pathless layout renders <BasaltProvider>`
|
|
482
|
+
: `neither ${root.file} nor a pathless layout (src/routes/_<name>.tsx, _<name>/route.tsx) renders <BasaltProvider>`
|
|
483
|
+
return fail(problem, START_PROVIDER_HINT)
|
|
484
|
+
}
|
|
485
|
+
const tagCount = withTags.reduce((n, f) => n + f.tags.length, 0)
|
|
486
|
+
if (tagCount > 1) {
|
|
487
|
+
return fail(
|
|
488
|
+
`${withTags.map((f) => f.file).join(' and ')} render ${tagCount} <BasaltProvider> tags; the extra ones nest a duplicate Query/Mantine tree`,
|
|
489
|
+
'keep one',
|
|
490
|
+
)
|
|
427
491
|
}
|
|
492
|
+
if (root.text === null) {
|
|
493
|
+
return fail(
|
|
494
|
+
`${root.file} does not exist, so the provider in ${first.file} has no root route context`,
|
|
495
|
+
'create it with `export const Route = createRootRouteWithContext<BasaltRouterContext>()({ … })`',
|
|
496
|
+
)
|
|
497
|
+
}
|
|
498
|
+
if (rootRouteKind(root.text) !== 'untyped') return null
|
|
499
|
+
return fail(
|
|
500
|
+
`${root.file} exports a Route built with createRootRoute(), so its router context has no queryClient, which the embedded BasaltProvider reads from context.queryClient`,
|
|
501
|
+
"`createRootRouteWithContext<BasaltRouterContext>()({ … })` (import type { BasaltRouterContext } from 'basalt-ui') and pass the QueryClient in createRouter({ context })",
|
|
502
|
+
)
|
|
428
503
|
}
|
|
429
504
|
|
|
430
505
|
/**
|
|
431
|
-
* Warnings for a Start app's embedded provider; heuristics, not proofs. A `{...spread}` on
|
|
432
|
-
* could carry a `router
|
|
433
|
-
* provider will find no `context.queryClient`. Empty when there is nothing to judge.
|
|
506
|
+
* Warnings for a Start app's embedded provider; heuristics, not proofs. A `{...spread}` on a tag
|
|
507
|
+
* could carry a `router`. Empty when there is nothing to judge.
|
|
434
508
|
*/
|
|
435
509
|
export function startWiringWarnings(cwd: string): string[] {
|
|
436
510
|
if (!isStartApp(cwd, '')) return []
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
511
|
+
const { root, layouts } = startProviderFiles(cwd)
|
|
512
|
+
return [root, ...layouts]
|
|
513
|
+
.filter((f) => f.tags.some((t) => t.spread))
|
|
514
|
+
.map(
|
|
515
|
+
(f) =>
|
|
516
|
+
`app-wiring: <BasaltProvider {...spread}> in ${f.file} could pass router=, which mounts ` +
|
|
442
517
|
'a second router inside Start (heuristic: the spread is not followed).',
|
|
443
518
|
)
|
|
444
|
-
}
|
|
445
|
-
const router = readIfExists(resolve(cwd, 'src/router.tsx'))
|
|
446
|
-
if (router !== null && !/queryClient/.test(router)) {
|
|
447
|
-
out.push(
|
|
448
|
-
'app-wiring: src/router.tsx never mentions queryClient — embedded BasaltProvider needs ' +
|
|
449
|
-
'context.queryClient on the Start router (heuristic text check; ignore if you build it elsewhere).',
|
|
450
|
-
)
|
|
451
|
-
}
|
|
452
|
-
return out
|
|
453
519
|
}
|
|
454
520
|
|
|
455
521
|
const BASALT_SHELL_TAG = /<BasaltShell\b/g
|
package/src/cli/index.ts
CHANGED
|
@@ -661,9 +661,11 @@ export function routerSeedDests(appRel: string): string[] {
|
|
|
661
661
|
)
|
|
662
662
|
}
|
|
663
663
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
'<BasaltProvider><Outlet /></BasaltProvider> in
|
|
664
|
+
/** Where a Start app's embedded provider goes (doctor, init and sync all say it). */
|
|
665
|
+
export const START_PROVIDER_HINT =
|
|
666
|
+
'render <BasaltProvider><Outlet /></BasaltProvider> in the root route component or a pathless layout'
|
|
667
|
+
|
|
668
|
+
export const START_APP_NOTE = `TanStack Start app — no main.tsx/nav.tsx/__root.tsx seeded (Start owns the router); ${START_PROVIDER_HINT}.`
|
|
667
669
|
|
|
668
670
|
/**
|
|
669
671
|
* The router seeds an app does not get, for `init` and `sync`: why (`start` | `code-routed` |
|
package/src/cli/sync.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
sha256,
|
|
37
37
|
shippedAssetPath,
|
|
38
38
|
START_APP_NOTE,
|
|
39
|
+
START_PROVIDER_HINT,
|
|
39
40
|
unitState,
|
|
40
41
|
writeFileEnsuringDir,
|
|
41
42
|
writeUnit,
|
|
@@ -232,8 +233,7 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
232
233
|
const stale = startSkippedSeeds.filter((d) => isTracked(d) && existsSync(resolve(cwd, d)))
|
|
233
234
|
const mounting = stale.filter((d) => !d.endsWith('nav.tsx'))
|
|
234
235
|
const inert = stale.filter((d) => d.endsWith('nav.tsx'))
|
|
235
|
-
const embedded =
|
|
236
|
-
'Delete them and render <BasaltProvider><Outlet /></BasaltProvider> in the Start root route (embedded mode).'
|
|
236
|
+
const embedded = `Delete them and ${START_PROVIDER_HINT} (embedded mode).`
|
|
237
237
|
if (mounting.length > 0) {
|
|
238
238
|
console.error(
|
|
239
239
|
`⚠ basalt-ui sync: ${mounting.join(', ')} mount a second router inside this TanStack Start app; left untouched. ${embedded}`,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command registry's runtime stash, as a leaf: no React, no peers. `defineCommands` fills it;
|
|
3
|
+
* the provider's hotkey binder, the Spotlight projector and `ShortcutsHelp` read it. Kept apart from
|
|
4
|
+
* `define-commands.ts` so a reader never imports the module that registers feature mounts.
|
|
5
|
+
*/
|
|
6
|
+
import { createNotifier } from '../provider/notifier'
|
|
7
|
+
import type { Command, CommandMap } from './define-commands'
|
|
8
|
+
|
|
9
|
+
let activeCommands: CommandMap = {}
|
|
10
|
+
const store = createNotifier()
|
|
11
|
+
|
|
12
|
+
/** @internal — `defineCommands` only. The last call wins; readers subscribed via {@link subscribeCommands} re-read. */
|
|
13
|
+
export function setActiveCommands(spec: CommandMap): void {
|
|
14
|
+
activeCommands = spec
|
|
15
|
+
store.notify()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** @internal — test isolation only. */
|
|
19
|
+
export function resetCommandStash(): void {
|
|
20
|
+
setActiveCommands({})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** @internal — exposed to the provider and projectors.ts to iterate the runtime stash. Returns a readonly view. */
|
|
24
|
+
export function getActiveCommands(): Readonly<CommandMap> {
|
|
25
|
+
return activeCommands
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @internal — `useSyncExternalStore` subscribe for a late `defineCommands` (a lazily loaded route). */
|
|
29
|
+
export const subscribeCommands = store.subscribe
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Runs a command, swallowing a sync throw or async rejection so a failing command never becomes an
|
|
33
|
+
* unhandled rejection (which the provider would report as a `window.error`). Dev logs it.
|
|
34
|
+
*/
|
|
35
|
+
export function runCommandSafely(cmd: Command): void {
|
|
36
|
+
const report = (error: unknown): void => {
|
|
37
|
+
if (process.env.NODE_ENV !== 'production') console.error('[basalt] command failed', error)
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
Promise.resolve(cmd.run()).catch(report)
|
|
41
|
+
} catch (error) {
|
|
42
|
+
report(error)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -19,7 +19,11 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import type { Hotkey } from '@tanstack/react-hotkeys'
|
|
21
21
|
import type { ReactNode } from 'react'
|
|
22
|
+
import { HotkeyBinder } from '../provider/hotkeys'
|
|
23
|
+
import { registerSlot } from '../provider/slots'
|
|
24
|
+
import { SpotlightMount } from '../provider/spotlight-mount'
|
|
22
25
|
import type { Slot } from '../register'
|
|
26
|
+
import { setActiveCommands } from './command-stash'
|
|
23
27
|
|
|
24
28
|
// ── Context ───────────────────────────────────────────────────────────────────
|
|
25
29
|
|
|
@@ -101,16 +105,6 @@ type Commands = Slot<'commands', CommandMap>
|
|
|
101
105
|
*/
|
|
102
106
|
export type CommandId = Extract<keyof Commands, string>
|
|
103
107
|
|
|
104
|
-
// ── Runtime stash ─────────────────────────────────────────────────────────────
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Module-level runtime registry. The BasaltRegister type-slot gives the compile-time id union,
|
|
108
|
-
* but the augmentation is erased at runtime — so defineCommands also stashes the runtime map here
|
|
109
|
-
* for the provider and the projectors to resolve Command objects. Call defineCommands once (the
|
|
110
|
-
* app's single command registry); the last call wins.
|
|
111
|
-
*/
|
|
112
|
-
let activeCommands: CommandMap = {}
|
|
113
|
-
|
|
114
108
|
// ── defineCommands ────────────────────────────────────────────────────────────
|
|
115
109
|
|
|
116
110
|
/**
|
|
@@ -118,7 +112,8 @@ let activeCommands: CommandMap = {}
|
|
|
118
112
|
* keys so the id union is exact after augmenting BasaltRegister.
|
|
119
113
|
*
|
|
120
114
|
* Stashes the runtime map so the provider resolves commands at runtime (type augmentation is
|
|
121
|
-
* erased; the stash is the live source)
|
|
115
|
+
* erased; the stash is the live source), and registers the provider mounts that need it: Spotlight,
|
|
116
|
+
* plus the hotkey binder when any command has a `shortcut`. Nothing else pulls those into a bundle.
|
|
122
117
|
*
|
|
123
118
|
* @example
|
|
124
119
|
* export const COMMANDS = defineCommands({
|
|
@@ -129,7 +124,10 @@ let activeCommands: CommandMap = {}
|
|
|
129
124
|
* }
|
|
130
125
|
*/
|
|
131
126
|
export function defineCommands<const T extends CommandMap>(spec: T): T {
|
|
132
|
-
|
|
127
|
+
setActiveCommands(spec)
|
|
128
|
+
registerSlot('spotlight', SpotlightMount)
|
|
129
|
+
if (Object.values(spec).some((c) => c.shortcut !== undefined))
|
|
130
|
+
registerSlot('hotkeys', HotkeyBinder)
|
|
133
131
|
return spec
|
|
134
132
|
}
|
|
135
133
|
|
|
@@ -150,8 +148,3 @@ export function defineCommands<const T extends CommandMap>(spec: T): T {
|
|
|
150
148
|
export function defineCommand(cmd: Command): Command {
|
|
151
149
|
return cmd
|
|
152
150
|
}
|
|
153
|
-
|
|
154
|
-
/** @internal — exposed to the provider and projectors.ts to iterate the runtime stash. Returns a readonly view. */
|
|
155
|
-
export function getActiveCommands(): Readonly<CommandMap> {
|
|
156
|
-
return activeCommands
|
|
157
|
-
}
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* A form dialog is an entry whose `render` returns the form; open it from a row action with
|
|
9
9
|
* `overlays.open('id', props)` and put its component in a `*-modal.tsx`.
|
|
10
10
|
*
|
|
11
|
-
* Uses @mantine/modals under the hood.
|
|
11
|
+
* Uses @mantine/modals under the hood. Calling `defineOverlays` registers the `ModalsProvider` mount
|
|
12
|
+
* (a sibling of the router, in `BasaltProvider`) — an app that defines none ships none of the peer.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* // overlays.ts (app-side)
|
|
@@ -31,53 +32,11 @@
|
|
|
31
32
|
import type { ReactNode } from 'react'
|
|
32
33
|
import { missingLayer } from '../common/errors'
|
|
33
34
|
import type { Slot } from '../register'
|
|
35
|
+
import { modals } from '@mantine/modals'
|
|
36
|
+
import { ensureModalsMount, registerModalsMount } from '../provider/modals-mount'
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// this module (and the ./commands barrel that re-exports it) does not require the peer. Resolves
|
|
38
|
-
// to undefined when the peer is absent — overlays.open/close then degrade to a no-op.
|
|
39
|
-
|
|
40
|
-
type ModalsModule = typeof import('@mantine/modals')
|
|
41
|
-
type ModalsSingleton = ModalsModule['modals']
|
|
42
|
-
|
|
43
|
-
let modalsPromise: Promise<ModalsSingleton | undefined> | undefined
|
|
44
|
-
|
|
45
|
-
function loadModals(): Promise<ModalsSingleton | undefined> {
|
|
46
|
-
modalsPromise ??= import('@mantine/modals').then((m) => m.modals).catch(() => undefined)
|
|
47
|
-
return modalsPromise
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ── Modals-layer availability ─────────────────────────────────────────────────
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* How many `ModalsProvider`s are live right now — a COUNTER, not a flag: two overlapping mounts
|
|
54
|
-
* are normal (a route swap mounts the next provider before unmounting the previous one), and a
|
|
55
|
-
* last-write-wins boolean reports the teardown of the OLD one as "no layer" while the new one is
|
|
56
|
-
* serving.
|
|
57
|
-
*
|
|
58
|
-
* It is the availability test `overlays.confirm` runs, because `@mantine/modals`' imperative API is
|
|
59
|
-
* a window event bus: with nothing subscribed the dialog never appears and the promise never
|
|
60
|
-
* settles.
|
|
61
|
-
*/
|
|
62
|
-
let mountedModalsProviders = 0
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Internal — `BasaltProvider` declares its `ModalsProvider` as live for as long as it is mounted,
|
|
66
|
-
* and gets back the function that retracts it. There is no way to detect the provider from outside
|
|
67
|
-
* React (its context is only readable through `useModals()`, and `confirm` is an imperative call),
|
|
68
|
-
* so the registration is explicit. Not on the `./commands` barrel.
|
|
69
|
-
*/
|
|
70
|
-
export function registerModalsProvider(): () => void {
|
|
71
|
-
mountedModalsProviders++
|
|
72
|
-
let released = false
|
|
73
|
-
return () => {
|
|
74
|
-
// Idempotent: an effect cleanup React runs twice (StrictMode remount) must not drive the count
|
|
75
|
-
// below the number of providers actually on screen.
|
|
76
|
-
if (released) return
|
|
77
|
-
released = true
|
|
78
|
-
mountedModalsProviders--
|
|
79
|
-
}
|
|
80
|
-
}
|
|
38
|
+
/** Bumped by `overlays.close()`; a deferred open / confirm that started in an older generation is cancelled. */
|
|
39
|
+
let closeGeneration = 0
|
|
81
40
|
|
|
82
41
|
// ── Overlay + OverlayMap ──────────────────────────────────────────────────────
|
|
83
42
|
|
|
@@ -150,6 +109,7 @@ let activeOverlays: OverlayMap = {}
|
|
|
150
109
|
*/
|
|
151
110
|
export function defineOverlays<const T extends OverlayMap>(spec: T): T {
|
|
152
111
|
activeOverlays = spec
|
|
112
|
+
registerModalsMount()
|
|
153
113
|
return spec
|
|
154
114
|
}
|
|
155
115
|
|
|
@@ -213,10 +173,10 @@ export type ConfirmDeleteOptions = {
|
|
|
213
173
|
* other exit (cancel, escape, click-outside, the close button). `onConfirm`/`onCancel` fire exactly
|
|
214
174
|
* once each at most, before the promise settles.
|
|
215
175
|
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
176
|
+
* The first call registers the modals mount and waits for the `BasaltProvider` to commit it — a tick
|
|
177
|
+
* normally, up to 5 s while a provider is mounted and busy. Rejects with a named `[basalt]` error when
|
|
178
|
+
* no `BasaltProvider` is mounted (after a 500 ms grace for one mounting now): the imperative API is a
|
|
179
|
+
* window event bus, and with nothing subscribed the promise would stay pending forever.
|
|
220
180
|
*
|
|
221
181
|
* @example
|
|
222
182
|
* if (await overlays.confirm({ title: 'Discard draft?', onConfirm: () => reset() })) navigate('/')
|
|
@@ -241,17 +201,15 @@ async function confirm(options: ConfirmOptions): Promise<boolean> {
|
|
|
241
201
|
onCancel,
|
|
242
202
|
} = options
|
|
243
203
|
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
),
|
|
252
|
-
)
|
|
204
|
+
const startedAt = closeGeneration
|
|
205
|
+
// `confirm` needs no registry entry, so it asks for the mount itself and waits for the provider.
|
|
206
|
+
const live = await ensureModalsMount()
|
|
207
|
+
if (startedAt !== closeGeneration) {
|
|
208
|
+
// `overlays.close()` ran while the mount was pending: the dialog never opens, the answer is "no".
|
|
209
|
+
onCancel?.()
|
|
210
|
+
return false
|
|
253
211
|
}
|
|
254
|
-
if (
|
|
212
|
+
if (!live) {
|
|
255
213
|
throw new Error(
|
|
256
214
|
missingLayer(
|
|
257
215
|
'overlays.confirm',
|
|
@@ -356,12 +314,24 @@ export const overlays = {
|
|
|
356
314
|
console.warn(`[basalt] overlays.open: no overlay registered for "${String(key)}"`)
|
|
357
315
|
return
|
|
358
316
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
317
|
+
// A `defineOverlays` made after first render has its mount committed a tick later: wait for it,
|
|
318
|
+
// or the dialog is published to a bus with no subscriber and lost.
|
|
319
|
+
const startedAt = closeGeneration
|
|
320
|
+
void ensureModalsMount().then((live) => {
|
|
321
|
+
// `overlays.close()` ran while the mount was pending: it cancels this open.
|
|
322
|
+
if (startedAt !== closeGeneration) return
|
|
323
|
+
if (!live) {
|
|
324
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
325
|
+
console.warn('[basalt] overlays.open: no mounted <BasaltProvider> to show the overlay')
|
|
326
|
+
}
|
|
327
|
+
return
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
modals.open({ title: spec.title, children: spec.render(props) })
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (process.env.NODE_ENV !== 'production') console.error('[basalt] overlay failed', error)
|
|
333
|
+
}
|
|
334
|
+
})
|
|
365
335
|
},
|
|
366
336
|
|
|
367
337
|
/**
|
|
@@ -387,6 +357,8 @@ export const overlays = {
|
|
|
387
357
|
* overlays.close()
|
|
388
358
|
*/
|
|
389
359
|
close(): void {
|
|
390
|
-
|
|
360
|
+
// Cancels every open / confirm still waiting for the modals mount.
|
|
361
|
+
closeGeneration++
|
|
362
|
+
modals.closeAll()
|
|
391
363
|
},
|
|
392
364
|
}
|