basalt-ui 2.11.1 → 2.13.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 +39 -0
- package/MIGRATING.md +51 -12
- package/README.md +2 -0
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/rules/basalt-state.md +1 -1
- package/agent/skills/basalt-app/SKILL.md +2 -2
- package/agent/templates/main.tpl +1 -0
- package/dist/cli/basalt-install.d.ts +10 -0
- package/dist/cli/basalt-install.d.ts.map +1 -0
- package/dist/cli/basalt-install.js +0 -0
- package/dist/cli/check-theme.js +1 -1
- package/dist/cli/doctor-upgrade.d.ts +5 -6
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +85 -56
- package/dist/cli/doctor.js +3 -3
- package/dist/cli/index.d.ts +5 -27
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +12 -49
- package/dist/cli/provider-tags.d.ts +12 -0
- package/dist/cli/provider-tags.d.ts.map +1 -0
- package/dist/cli/provider-tags.js +28 -0
- package/dist/cli/render-imports.d.ts +24 -0
- package/dist/cli/render-imports.d.ts.map +1 -0
- package/dist/cli/render-imports.js +74 -0
- package/dist/cli/router-wiring.d.ts +12 -0
- package/dist/cli/router-wiring.d.ts.map +1 -1
- package/dist/cli/router-wiring.js +18 -0
- package/dist/cli/source-text.d.ts +7 -0
- package/dist/cli/source-text.d.ts.map +1 -1
- package/dist/cli/source-text.js +34 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +19 -13
- 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/guard/fonts-hint.d.ts +3 -0
- package/dist/guard/fonts-hint.d.ts.map +1 -0
- package/dist/guard/fonts-hint.js +4 -0
- package/dist/guard/index.d.ts +1 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/provider/create-router.d.ts +57 -10
- package/dist/provider/create-router.d.ts.map +1 -1
- package/dist/provider/create-router.js +28 -17
- 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 +7 -5
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +35 -42
- 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/query-client.d.ts +2 -62
- package/dist/query-client.d.ts.map +1 -1
- package/dist/query-client.js +13 -18
- 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/search-store-warnings.d.ts +33 -0
- package/dist/router-tanstack/search-store-warnings.d.ts.map +1 -0
- package/dist/router-tanstack/search-store-warnings.js +77 -0
- package/dist/router-tanstack/search-store.d.ts +2 -5
- package/dist/router-tanstack/search-store.d.ts.map +1 -1
- package/dist/router-tanstack/search-store.js +111 -110
- package/dist/router-tanstack/use-nav.js +1 -1
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.js +1 -1
- package/dist/telemetry.d.ts +31 -2
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +32 -12
- package/dist/theme/ctl-theme.d.ts.map +1 -1
- package/dist/theme/ctl-theme.js +17 -30
- package/dist/theme/extend.d.ts +18 -0
- package/dist/theme/extend.d.ts.map +1 -0
- package/dist/theme/extend.js +6 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +44 -84
- package/dist/unwrap.d.ts +29 -0
- package/dist/unwrap.d.ts.map +1 -0
- package/dist/unwrap.js +18 -0
- package/llms.txt +11 -7
- package/package.json +2 -2
- package/src/cli/basalt-install.ts +9 -0
- package/src/cli/check-theme.ts +1 -1
- package/src/cli/doctor-upgrade.ts +117 -72
- package/src/cli/doctor.ts +3 -3
- package/src/cli/index.ts +15 -70
- package/src/cli/provider-tags.ts +38 -0
- package/src/cli/render-imports.ts +104 -0
- package/src/cli/router-wiring.ts +23 -0
- package/src/cli/source-text.ts +39 -0
- package/src/cli/sync.ts +28 -22
- 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/guard/fonts-hint.ts +2 -0
- package/src/guard/index.ts +2 -2
- package/src/index.ts +4 -2
- package/src/provider/create-router.tsx +103 -39
- package/src/provider/hotkeys.ts +14 -22
- package/src/provider/index.tsx +55 -61
- 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/query-client.ts +20 -78
- package/src/router-tanstack/nav-stash.ts +41 -0
- package/src/router-tanstack/nav.ts +11 -31
- package/src/router-tanstack/search-store-warnings.ts +120 -0
- package/src/router-tanstack/search-store.ts +200 -206
- package/src/router-tanstack/use-nav.ts +1 -1
- package/src/surfaces.ts +1 -1
- package/src/telemetry.ts +71 -13
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +2354 -0
- package/src/theme/ctl-theme.tsx +20 -19
- package/src/theme/extend.ts +18 -0
- package/src/theme/index.ts +50 -49
- package/src/unwrap.ts +44 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE import hop `doctor` follows from a Start route file to a component wrapper that holds the
|
|
3
|
+
* `<BasaltProvider>` tag. A leaf: it imports no CLI command module. Textual, so blind to tsconfig
|
|
4
|
+
* `extends` paths, `export … from` re-exports, dynamic `import()` and multi-wildcard `paths`.
|
|
5
|
+
*/
|
|
6
|
+
import { dirname, relative, resolve } from 'node:path'
|
|
7
|
+
|
|
8
|
+
import { providerTags } from './provider-tags'
|
|
9
|
+
import type { ProviderTag } from './provider-tags'
|
|
10
|
+
import { parseJsonc, readIfExists, tokenize } from './source-text'
|
|
11
|
+
|
|
12
|
+
export type ModuleFile = { file: string; text: string | null; tags: ProviderTag[] }
|
|
13
|
+
|
|
14
|
+
/** One read path for every module in the walk; `text` is null for a missing file. */
|
|
15
|
+
export function loadModule(cwd: string, file: string): ModuleFile {
|
|
16
|
+
const text = readIfExists(resolve(cwd, file))
|
|
17
|
+
return { file, text, tags: providerTags(text ?? '') }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const MODULE_SUFFIXES = ['.tsx', '.ts', '.jsx', '.js', '/index.tsx', '/index.ts']
|
|
21
|
+
|
|
22
|
+
type Alias = [prefix: string, dir: string]
|
|
23
|
+
|
|
24
|
+
/** tsconfig `compilerOptions.paths` single-wildcard `alias/*` entries; a malformed shape is no alias. */
|
|
25
|
+
export function pathAliases(cwd: string): Alias[] {
|
|
26
|
+
const opts = parseJsonc(readIfExists(resolve(cwd, 'tsconfig.json')) ?? '')?.['compilerOptions']
|
|
27
|
+
if (typeof opts !== 'object' || opts === null) return []
|
|
28
|
+
const { baseUrl, paths } = opts as { baseUrl?: unknown; paths?: Record<string, unknown> | null }
|
|
29
|
+
if (typeof paths !== 'object' || paths === null || Array.isArray(paths)) return []
|
|
30
|
+
const base = typeof baseUrl === 'string' ? baseUrl : '.'
|
|
31
|
+
return Object.entries(paths).flatMap(([pattern, targets]) => {
|
|
32
|
+
const target: unknown = Array.isArray(targets) ? targets[0] : undefined
|
|
33
|
+
if (!pattern.endsWith('/*') || typeof target !== 'string' || !target.endsWith('/*')) return []
|
|
34
|
+
return [[pattern.slice(0, -1), `${base}/${target.slice(0, -1)}`]]
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const aliasedBase = (cwd: string, spec: string, aliases: Alias[]): string | undefined => {
|
|
39
|
+
const hit = aliases.find(([prefix]) => spec.startsWith(prefix))
|
|
40
|
+
return hit === undefined ? undefined : resolve(cwd, hit[1] + spec.slice(hit[0].length))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const escapeRegex = (name: string): string => name.replaceAll('$', String.raw`\$`)
|
|
44
|
+
|
|
45
|
+
/** The local modules `file` renders a component from: `<Name` in JSX, name imported from a relative or aliased specifier. */
|
|
46
|
+
export function renderedImports(
|
|
47
|
+
cwd: string,
|
|
48
|
+
file: string,
|
|
49
|
+
text: string,
|
|
50
|
+
aliases: Alias[],
|
|
51
|
+
): string[] {
|
|
52
|
+
const { code, inLiteral } = tokenize(text)
|
|
53
|
+
const found = new Set<string>()
|
|
54
|
+
for (const m of code.matchAll(/\bimport\s+(?!type\b)([^'"]*?)\s*from\s*['"]([^'"]+)['"]/g)) {
|
|
55
|
+
if (inLiteral(m.index)) continue
|
|
56
|
+
const spec = m[2]!.replace(/\.[jt]sx?$/, '')
|
|
57
|
+
const base = spec.startsWith('.')
|
|
58
|
+
? resolve(cwd, dirname(file), spec)
|
|
59
|
+
: aliasedBase(cwd, spec, aliases)
|
|
60
|
+
if (base === undefined) continue
|
|
61
|
+
const names = [...m[1]!.replace(/\btype\s+/g, '').matchAll(/[A-Za-z_$][\w$]*/g)].map(
|
|
62
|
+
(n) => n[0],
|
|
63
|
+
)
|
|
64
|
+
if (!names.some((n) => new RegExp(`<${escapeRegex(n)}\\b`).test(code))) continue
|
|
65
|
+
const rel = relative(cwd, base).split('\\').join('/')
|
|
66
|
+
const hit = MODULE_SUFFIXES.map((x) => rel + x).find(
|
|
67
|
+
(c) => readIfExists(resolve(cwd, c)) !== null,
|
|
68
|
+
)
|
|
69
|
+
if (hit !== undefined) found.add(hit)
|
|
70
|
+
}
|
|
71
|
+
return [...found]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* `hops`: one entry per render EDGE (scanned file -> rendered module holding a provider tag), so the
|
|
76
|
+
* same wrapper rendered from two route files counts twice. `far`: provider-holding modules one more hop out, which doctor does not follow but
|
|
77
|
+
* names (the one-provider invariant and the failure message both need them).
|
|
78
|
+
*/
|
|
79
|
+
export function followProviderHops(
|
|
80
|
+
cwd: string,
|
|
81
|
+
scanned: ModuleFile[],
|
|
82
|
+
): { hops: ModuleFile[]; far: string[] } {
|
|
83
|
+
const aliases = pathAliases(cwd)
|
|
84
|
+
const modules = new Map(scanned.map((f) => [f.file, f]))
|
|
85
|
+
const load = (file: string): ModuleFile => {
|
|
86
|
+
const known = modules.get(file) ?? loadModule(cwd, file)
|
|
87
|
+
modules.set(file, known)
|
|
88
|
+
return known
|
|
89
|
+
}
|
|
90
|
+
const hops: ModuleFile[] = []
|
|
91
|
+
const far = new Set<string>()
|
|
92
|
+
for (const f of scanned) {
|
|
93
|
+
for (const mod of renderedImports(cwd, f.file, f.text ?? '', aliases)) {
|
|
94
|
+
if (scanned.some((s) => s.file === mod)) continue
|
|
95
|
+
const hop = load(mod)
|
|
96
|
+
if (hop.tags.length > 0) hops.push(hop)
|
|
97
|
+
for (const next of renderedImports(cwd, mod, hop.text ?? '', aliases)) {
|
|
98
|
+
if (!scanned.some((s) => s.file === next) && load(next).tags.length > 0) far.add(next)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const nearFiles = new Set(hops.map((h) => h.file))
|
|
103
|
+
return { hops, far: [...far].filter((f) => !nearFiles.has(f)) }
|
|
104
|
+
}
|
package/src/cli/router-wiring.ts
CHANGED
|
@@ -187,3 +187,26 @@ export function routerSeedSkip(cwd: string, appRel: string): RouterSeedSkip {
|
|
|
187
187
|
|
|
188
188
|
export const SHELL_LESS_NOTE =
|
|
189
189
|
'`basalt.shell: false` — no main.tsx/nav.tsx/__root.tsx seeded; the app owns its root route (or has none).'
|
|
190
|
+
|
|
191
|
+
/** The router seeds (TanStack Router and Query are required peers of `.`, so they are always written). */
|
|
192
|
+
export const ROUTER_SEED_DESTS = {
|
|
193
|
+
nav: 'src/lib/nav.tsx',
|
|
194
|
+
root: 'src/routes/__root.tsx',
|
|
195
|
+
main: 'src/main.tsx',
|
|
196
|
+
} as const
|
|
197
|
+
|
|
198
|
+
/** A router seed's dest, relative to the install root: under the app dir when it is not the root. */
|
|
199
|
+
export function routerSeedDest(appRel: string, seed: keyof typeof ROUTER_SEED_DESTS): string {
|
|
200
|
+
return appRel === '' ? ROUTER_SEED_DESTS[seed] : `${appRel}/${ROUTER_SEED_DESTS[seed]}`
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The router seeds' dests for an app dir (`main.tsx`, `nav.tsx`, `__root.tsx`). */
|
|
204
|
+
export function routerSeedDests(appRel: string): string[] {
|
|
205
|
+
return (Object.keys(ROUTER_SEED_DESTS) as (keyof typeof ROUTER_SEED_DESTS)[]).map((seed) =>
|
|
206
|
+
routerSeedDest(appRel, seed),
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Where a Start app's embedded provider goes (doctor, init and sync all say it). */
|
|
211
|
+
export const START_PROVIDER_HINT =
|
|
212
|
+
'render <BasaltProvider><Outlet /></BasaltProvider> in the root route component or a pathless layout'
|
package/src/cli/source-text.ts
CHANGED
|
@@ -60,3 +60,42 @@ export function tokenize(src: string): { code: string; inLiteral: (at: number) =
|
|
|
60
60
|
})
|
|
61
61
|
return { code, inLiteral: (at) => literals.some(([from, to]) => at >= from && at < to) }
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Strip JSONC comments and trailing commas so oxlint/tsconfig files can be READ (string-aware). A
|
|
66
|
+
* mangled string fails as a parse error, which callers treat as "cannot tell", never as a pass.
|
|
67
|
+
*/
|
|
68
|
+
export function stripJsonc(text: string): string {
|
|
69
|
+
let out = ''
|
|
70
|
+
let inString = false
|
|
71
|
+
for (let i = 0; i < text.length; i++) {
|
|
72
|
+
const ch = text[i] as string
|
|
73
|
+
if (inString) {
|
|
74
|
+
out += ch
|
|
75
|
+
if (ch === '\\') out += text[++i] ?? ''
|
|
76
|
+
else if (ch === '"') inString = false
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
if (ch === '"') inString = true
|
|
80
|
+
else if (ch === '/' && text[i + 1] === '/') {
|
|
81
|
+
while (i < text.length && text[i] !== '\n') i++
|
|
82
|
+
continue
|
|
83
|
+
} else if (ch === '/' && text[i + 1] === '*') {
|
|
84
|
+
i += 2
|
|
85
|
+
while (i < text.length && !(text[i] === '*' && text[i + 1] === '/')) i++
|
|
86
|
+
i++
|
|
87
|
+
continue
|
|
88
|
+
}
|
|
89
|
+
out += ch
|
|
90
|
+
}
|
|
91
|
+
return out.replace(/,(\s*[}\]])/g, '$1')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Parse a JSONC document, or null when it does not parse at all. */
|
|
95
|
+
export function parseJsonc(text: string): Record<string, unknown> | null {
|
|
96
|
+
try {
|
|
97
|
+
return JSON.parse(stripJsonc(text.replace(/^\uFEFF/, ''))) as Record<string, unknown>
|
|
98
|
+
} catch {
|
|
99
|
+
return null
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/cli/sync.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { resolve } from 'node:path'
|
|
|
4
4
|
|
|
5
5
|
import { deriveSpacing } from '../tokens/core'
|
|
6
6
|
import { shellConfigError } from './config'
|
|
7
|
+
import type { RouterSeedSkip } from './router-wiring'
|
|
8
|
+
import { carriesRouter, providerTags } from './provider-tags'
|
|
7
9
|
import {
|
|
8
10
|
MANIFEST_PATH,
|
|
9
11
|
basaltPresetEntry,
|
|
@@ -18,7 +20,6 @@ import {
|
|
|
18
20
|
normalizeForLedger,
|
|
19
21
|
noteRelocation,
|
|
20
22
|
OXLINT_FILES,
|
|
21
|
-
parseJsonc,
|
|
22
23
|
placementNotices,
|
|
23
24
|
pruneRetiredManagedFiles,
|
|
24
25
|
readBasaltConfig,
|
|
@@ -36,10 +37,12 @@ import {
|
|
|
36
37
|
sha256,
|
|
37
38
|
shippedAssetPath,
|
|
38
39
|
START_APP_NOTE,
|
|
40
|
+
START_PROVIDER_HINT,
|
|
39
41
|
unitState,
|
|
40
42
|
writeFileEnsuringDir,
|
|
41
43
|
writeUnit,
|
|
42
44
|
} from './index'
|
|
45
|
+
import { parseJsonc } from './source-text'
|
|
43
46
|
import { findManifestAbove, installRootAbove } from './install-root'
|
|
44
47
|
|
|
45
48
|
/** The oxlint plugins the shipped preset switches on — read from the preset, never restated. */
|
|
@@ -66,6 +69,12 @@ export function parentInstallAdvice(cwd: string, parent: string, verb: string):
|
|
|
66
69
|
)
|
|
67
70
|
}
|
|
68
71
|
|
|
72
|
+
const RETIRED_BECAUSE = {
|
|
73
|
+
'code-routed': 'code-routed app',
|
|
74
|
+
start: 'TanStack Start app',
|
|
75
|
+
'shell-less': 'basalt.shell: false',
|
|
76
|
+
} as const satisfies Record<NonNullable<RouterSeedSkip>, string>
|
|
77
|
+
|
|
69
78
|
/**
|
|
70
79
|
* Reconcile managed files with the shipped versions via a sha256 three-way compare.
|
|
71
80
|
*
|
|
@@ -207,16 +216,18 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
207
216
|
})
|
|
208
217
|
staleForCheck += pruned.removed.length + pruned.drifted.length
|
|
209
218
|
|
|
210
|
-
// A code-routed or declared shell-less app takes no router seeds: their manifest entries
|
|
211
|
-
// (so the next sync does not resurrect them); any file stays the consumer's.
|
|
219
|
+
// A code-routed, Start or declared shell-less app takes no router seeds: their manifest entries
|
|
220
|
+
// go (so the next sync does not resurrect them); any file stays the consumer's.
|
|
212
221
|
const isTracked = (d: string): boolean => manifest.files[d] !== undefined
|
|
213
|
-
const retiredBecause =
|
|
214
|
-
seedSkip === 'code-routed'
|
|
215
|
-
? 'code-routed app'
|
|
216
|
-
: seedSkip === 'shell-less'
|
|
217
|
-
? 'basalt.shell: false'
|
|
218
|
-
: null
|
|
222
|
+
const retiredBecause = seedSkip === null ? null : RETIRED_BECAUSE[seedSkip]
|
|
219
223
|
const retiredSeeds = retiredBecause === null ? [] : [...skipped].filter(isTracked)
|
|
224
|
+
// Start is the new retirement: a gate green over seeds the next sync would drop is a stale gate.
|
|
225
|
+
if (opts.check && seedSkip === 'start' && retiredSeeds.length > 0) {
|
|
226
|
+
staleForCheck += retiredSeeds.length
|
|
227
|
+
console.error(
|
|
228
|
+
`basalt-ui sync --check: ${retiredSeeds.join(', ')} still tracked in the manifest of a TanStack Start app. Fix: run \`basalt-ui sync\`.`,
|
|
229
|
+
)
|
|
230
|
+
}
|
|
220
231
|
if (retiredSeeds.length > 0 && !opts.check) {
|
|
221
232
|
for (const d of retiredSeeds) delete manifest.files[d]
|
|
222
233
|
console.error(
|
|
@@ -227,21 +238,16 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
227
238
|
// Placement notices — informational, never affecting the exit code, and PERMANENT: `--check`
|
|
228
239
|
// hides them behind `--verbose` (it sits in consumers' CI chains, where three unchanging
|
|
229
240
|
// "skipped" paragraphs per run are noise indistinguishable from drift) but still prints the COUNT.
|
|
230
|
-
// Start
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
241
|
+
// A Start app's leftover seed is judged by CONTENT: only a `<BasaltProvider router=…>` tag mounts one.
|
|
242
|
+
const mounting =
|
|
243
|
+
seedSkip === 'start'
|
|
244
|
+
? [...skipped].filter((d) =>
|
|
245
|
+
providerTags(readIfExists(resolve(cwd, d)) ?? '').some(carriesRouter),
|
|
246
|
+
)
|
|
247
|
+
: []
|
|
237
248
|
if (mounting.length > 0) {
|
|
238
249
|
console.error(
|
|
239
|
-
`⚠ basalt-ui sync: ${mounting.join(', ')} mount a second router inside this TanStack Start app; left untouched. ${embedded
|
|
240
|
-
)
|
|
241
|
-
}
|
|
242
|
-
if (inert.length > 0) {
|
|
243
|
-
console.error(
|
|
244
|
-
`⚠ basalt-ui sync: ${inert.join(', ')} was seeded before this became a Start app; it mounts nothing, so keep or delete it. Left untouched.`,
|
|
250
|
+
`⚠ basalt-ui sync: ${mounting.join(', ')} mount a second router inside this TanStack Start app; left untouched. Delete them and ${START_PROVIDER_HINT} (embedded mode).`,
|
|
245
251
|
)
|
|
246
252
|
}
|
|
247
253
|
if (seedSkip === 'start' && (!opts.check || syncFlags.includes('--verbose')))
|
|
@@ -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
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* `ShortcutsHelp` renders. Reads the runtime stash (populated by `defineCommands`), not the
|
|
4
4
|
* type-erased `BasaltRegister` slot; safe to call before any commands are registered.
|
|
5
5
|
*/
|
|
6
|
-
import { getActiveCommands } from './
|
|
6
|
+
import { getActiveCommands } from './command-stash'
|
|
7
7
|
|
|
8
8
|
// ── ShortcutEntry ─────────────────────────────────────────────────────────────
|
|
9
9
|
|
package/src/guard/index.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import type { Finding, GuardConfig, GuardKind, GuardSeverity } from './types'
|
|
8
8
|
import { vxFamilyOf } from '../common/vx-family'
|
|
9
9
|
import { BASALT_VX_FAMILIES } from '../common/vx-families'
|
|
10
|
+
import { FONTS_CSS_HINT } from './fonts-hint'
|
|
10
11
|
import { BASALT_VX_NAMES } from './vx-names'
|
|
11
12
|
|
|
12
13
|
export type { Finding, GuardConfig, GuardKind, GuardSeverity }
|
|
@@ -2001,8 +2002,7 @@ export const GUARD_RULES = {
|
|
|
2001
2002
|
'raw-font-family': {
|
|
2002
2003
|
kind: 'raw-font-family',
|
|
2003
2004
|
pattern: RAW_FONT_FAMILY,
|
|
2004
|
-
message:
|
|
2005
|
-
'Route the font stack through createBasaltTheme(overrides, { fonts }) / the shipped --basalt-font-sans|head|mono vars instead of a hardcoded fontFamily literal.',
|
|
2005
|
+
message: `Route the font stack through createBasaltTheme(overrides, { fonts }) / the shipped --basalt-font-sans|head|mono vars instead of a hardcoded fontFamily literal (${FONTS_CSS_HINT}).`,
|
|
2006
2006
|
},
|
|
2007
2007
|
'off-identity-accent': {
|
|
2008
2008
|
kind: 'off-identity-accent',
|
package/src/index.ts
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
* `docs/waves/v2-surface.md`.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
export { BasaltProvider } from './provider'
|
|
9
|
+
export { BasaltProvider, type BasaltProviderProps } from './provider'
|
|
10
10
|
export {
|
|
11
|
+
basaltRouterOptions,
|
|
11
12
|
createBasaltRouter,
|
|
12
13
|
type BasaltRouter,
|
|
14
|
+
type BasaltRouterOptions,
|
|
13
15
|
type BasaltRouterContext,
|
|
14
16
|
} from './provider/create-router'
|
|
15
17
|
export type { BasaltEvent, ChatTurnEnd, ChatTurnTrace, Telemetry, TraceHeaders } from './telemetry'
|
|
@@ -47,7 +49,7 @@ export {
|
|
|
47
49
|
SettingsRow,
|
|
48
50
|
DangerZone,
|
|
49
51
|
} from './dashboard'
|
|
50
|
-
export { unwrap } from './
|
|
52
|
+
export { unwrap } from './unwrap'
|
|
51
53
|
|
|
52
54
|
// The one augmentable seam: `declare module 'basalt-ui' { interface BasaltRegister { … } }` only
|
|
53
55
|
// merges when the entry exports the interface. `v2-surface.md` marks it `delete` (no consumer
|