basalt-ui 2.7.3 → 2.8.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.
- package/CHANGELOG.md +194 -172
- package/MIGRATING.md +137 -16
- package/agent/rules/basalt-batteries.md +1 -1
- package/agent/rules/basalt-controls.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/skills/basalt-app/SKILL.md +7 -7
- package/agent/templates/AGENTS-block.md.tpl +1 -1
- package/dist/charts/BandStrip.d.ts +13 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +142 -44
- package/dist/cli/doctor-upgrade.d.ts +16 -4
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +132 -96
- package/dist/cli/doctor.d.ts +2 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +21 -13
- package/dist/cli/help.js +1 -1
- package/dist/cli/index.d.ts +18 -4
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +25 -24
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +10 -4
- package/dist/cli/router-wiring.d.ts +37 -0
- package/dist/cli/router-wiring.d.ts.map +1 -0
- package/dist/cli/router-wiring.js +116 -0
- package/dist/cli/source-text.d.ts +12 -0
- package/dist/cli/source-text.d.ts.map +1 -0
- package/dist/cli/source-text.js +46 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +32 -2
- package/dist/content/code-block.d.ts.map +1 -1
- package/dist/content/code-block.js +36 -27
- package/dist/content/code-block.module.css +19 -1
- package/dist/content/mermaid-sanitize.d.ts +15 -0
- package/dist/content/mermaid-sanitize.d.ts.map +1 -0
- package/dist/content/mermaid-sanitize.js +28 -0
- package/dist/content/mermaid.d.ts +6 -0
- package/dist/content/mermaid.d.ts.map +1 -1
- package/dist/content/mermaid.js +3 -1
- package/dist/provider/index.d.ts +22 -4
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +24 -8
- package/dist/provider/test-router.d.ts +2 -1
- package/dist/provider/test-router.d.ts.map +1 -1
- package/dist/provider/test-router.js +6 -7
- package/dist/vite-boot.d.ts +25 -0
- package/dist/vite-boot.d.ts.map +1 -0
- package/dist/vite-boot.js +36 -0
- package/dist/vite.d.ts +24 -3
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +7 -16
- package/llms.txt +37 -4
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +223 -48
- package/src/cli/doctor-upgrade.ts +181 -141
- package/src/cli/doctor.ts +23 -14
- package/src/cli/help.ts +1 -1
- package/src/cli/index.ts +37 -36
- package/src/cli/init.ts +10 -6
- package/src/cli/router-wiring.ts +185 -0
- package/src/cli/source-text.ts +62 -0
- package/src/cli/sync.ts +36 -2
- package/src/content/code-block.module.css +19 -1
- package/src/content/code-block.tsx +7 -2
- package/src/content/mermaid-sanitize.ts +49 -0
- package/src/content/mermaid.tsx +3 -2
- package/src/provider/index.tsx +71 -18
- package/src/provider/test-router.tsx +9 -9
- package/src/vite-boot.ts +109 -0
- package/src/vite.ts +32 -61
package/src/cli/init.ts
CHANGED
|
@@ -11,9 +11,9 @@ import type { MergeLintResult, ScaffoldFlags } from './index'
|
|
|
11
11
|
import {
|
|
12
12
|
MANIFEST_PATH,
|
|
13
13
|
declaredProfile,
|
|
14
|
+
routerSeedPlan,
|
|
15
|
+
seedSkipNote,
|
|
14
16
|
readBasaltConfig,
|
|
15
|
-
ROUTER_SEED_DESTS,
|
|
16
|
-
routerSeedDest,
|
|
17
17
|
findBasaltInstall,
|
|
18
18
|
managedFiles,
|
|
19
19
|
mergeOxlintExtends,
|
|
@@ -127,10 +127,12 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
|
|
|
127
127
|
const placement = resolvePlacement(cwd)
|
|
128
128
|
// A tokens-only consumer has no use for the Mantine/React scaffolds (doctor skips them there too).
|
|
129
129
|
const tokensOnly = declaredProfile(readBasaltConfig(cwd), []) === 'tokens-only'
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
const { skip: seedSkip, skipped: skippedSeeds } = routerSeedPlan(
|
|
131
|
+
cwd,
|
|
132
|
+
placement.appRel,
|
|
133
|
+
tokensOnly,
|
|
134
|
+
)
|
|
135
|
+
const files = managedFiles(placement).filter((f) => !skippedSeeds.has(f.dest))
|
|
134
136
|
|
|
135
137
|
const writtenFiles: string[] = []
|
|
136
138
|
const keptFiles: string[] = []
|
|
@@ -205,6 +207,8 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
|
|
|
205
207
|
const tsconfigLine = tokensOnly ? null : seedTsconfigExtends(cwd)
|
|
206
208
|
if (tsconfigLine !== null) console.log(`basalt-ui init: ${tsconfigLine}`)
|
|
207
209
|
if (buildNote !== null) console.log(`basalt-ui init: ${buildNote}`)
|
|
210
|
+
const skipNote = seedSkipNote(seedSkip)
|
|
211
|
+
if (skipNote !== null) console.log(`basalt-ui init: ${skipNote}`)
|
|
208
212
|
const rootsMessages = rootsNotices(rootsState)
|
|
209
213
|
for (const line of rootsMessages.log) console.log(`basalt-ui init: ${line}`)
|
|
210
214
|
for (const line of rootsMessages.error) console.error(`⚠ basalt-ui init: ${line}`)
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Router wiring: is an app TanStack Start, code-routed (route tree defined in code) or file-routed
|
|
3
|
+
* (plugin or `routeTree.gen.*`)? Textual, no TS program. A leaf module shared by init/sync/doctor.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync } from 'node:fs'
|
|
6
|
+
import { dirname, resolve } from 'node:path'
|
|
7
|
+
|
|
8
|
+
import { hasDependency, readIfExists, tokenize } from './source-text'
|
|
9
|
+
|
|
10
|
+
/** Relative-import hops (static or dynamic) `callsIn` follows from the entry; a router often lives in a singleton module. */
|
|
11
|
+
const IMPORT_DEPTH = 3
|
|
12
|
+
|
|
13
|
+
const VITE_CONFIGS = ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs'].map((e) => `vite.config.${e}`)
|
|
14
|
+
/** The first local `<script type="module" src>` in index.html (comments and remote src skipped). */
|
|
15
|
+
function htmlEntry(html: string): string | undefined {
|
|
16
|
+
for (const [, attrs = ''] of html
|
|
17
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
18
|
+
.matchAll(/<script\b([^>]*)>/gi)) {
|
|
19
|
+
const src = /\bsrc\s*=\s*["']?([^"'\s>]+)/i.exec(attrs)?.[1]
|
|
20
|
+
if (
|
|
21
|
+
/\btype\s*=\s*["']?module\b/i.test(attrs) &&
|
|
22
|
+
src !== undefined &&
|
|
23
|
+
!/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(src)
|
|
24
|
+
) {
|
|
25
|
+
return src
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return undefined
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** True when `src` calls a binding imported from `@tanstack/router-plugin` after its `plugins` key (a textual proxy for "inside the array"). */
|
|
32
|
+
function registersRouterPlugin(src: string): boolean {
|
|
33
|
+
const { code, inLiteral } = tokenize(src)
|
|
34
|
+
const pluginsAt = [...code.matchAll(/\bplugins\b/g)].find((m) => !inLiteral(m.index))?.index
|
|
35
|
+
if (pluginsAt === undefined) return false
|
|
36
|
+
const imports = code.matchAll(
|
|
37
|
+
/(?:^|;)[ \t]*import\s+(?:type\s+)?([^'"`;]*?)\s*from\s*(['"])@tanstack\/router-plugin(?:\/[^'"]*)?\2/gm,
|
|
38
|
+
)
|
|
39
|
+
return [...imports].some((m) => {
|
|
40
|
+
if (inLiteral(m.index)) return false
|
|
41
|
+
const names = (m[1] ?? '')
|
|
42
|
+
.replace(/[{}]/g, '')
|
|
43
|
+
.split(',')
|
|
44
|
+
.map((part) => part.trim())
|
|
45
|
+
.filter((part) => part !== '' && !/^type\s/.test(part))
|
|
46
|
+
.map((part) => part.split(/\s+as\s+/).pop() ?? part)
|
|
47
|
+
return names.some((name) =>
|
|
48
|
+
[
|
|
49
|
+
...code.matchAll(
|
|
50
|
+
new RegExp(`(?<![.\\w$])${name.replace(/\$/g, '\\$')}(?:\\.\\w+)?\\s*\\(`, 'g'),
|
|
51
|
+
),
|
|
52
|
+
].some((call) => call.index > pluginsAt && !inLiteral(call.index)),
|
|
53
|
+
)
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A relative specifier: `import … from`, `export … from`, bare `import '…'` and dynamic `import('…')`. */
|
|
58
|
+
const RELATIVE_IMPORT =
|
|
59
|
+
/(?<![.\w$])(?:(?:import|export)\b[^'";]*?\bfrom|import\s*\(?)\s*['"](\.{1,2}\/[^'"]+)['"]/g
|
|
60
|
+
|
|
61
|
+
/** An import/export specifier naming the generated route tree (`./routeTree.gen`). */
|
|
62
|
+
const GENERATED_TREE_IMPORT =
|
|
63
|
+
/(?<![.\w$])(?:(?:import|export)\b[^'";]*?\bfrom|import\s*\(?)\s*['"][^'"]*routeTree\.gen[^'"]*['"]/g
|
|
64
|
+
|
|
65
|
+
/** The source file a relative specifier names: as written, `.ts`/`.tsx` appended, or a directory index. */
|
|
66
|
+
function resolveRelative(from: string, spec: string): string | null {
|
|
67
|
+
const base = resolve(dirname(from), spec.replace(/\.[jt]sx?$/, ''))
|
|
68
|
+
return (
|
|
69
|
+
[
|
|
70
|
+
resolve(dirname(from), spec),
|
|
71
|
+
`${base}.ts`,
|
|
72
|
+
`${base}.tsx`,
|
|
73
|
+
`${base}/index.ts`,
|
|
74
|
+
`${base}/index.tsx`,
|
|
75
|
+
].find((f) => /\.[jt]sx?$/.test(f) && existsSync(f)) ?? null
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The module `index.html` loads for the app at `dir` (default src/main.tsx), relative to `dir`. */
|
|
80
|
+
export function appEntry(dir: string): string {
|
|
81
|
+
const src = htmlEntry(readIfExists(resolve(dir, 'index.html')) ?? '') ?? 'src/main.tsx'
|
|
82
|
+
return src.replace(/^\//, '')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type Tokens = ReturnType<typeof tokenize>
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Whether the entry or a module it imports (relative imports, static or dynamic, `IMPORT_DEPTH`
|
|
89
|
+
* hops) matches `pattern` in code — a global regex, ignoring comments and string literals; an
|
|
90
|
+
* import inside a comment or a string is not followed. `entryTokens` reuses an already-tokenized entry.
|
|
91
|
+
*/
|
|
92
|
+
export function callsIn(
|
|
93
|
+
dir: string,
|
|
94
|
+
entry: string,
|
|
95
|
+
pattern: RegExp,
|
|
96
|
+
entryTokens?: Tokens,
|
|
97
|
+
): boolean {
|
|
98
|
+
const entryPath = resolve(dir, entry)
|
|
99
|
+
const seen = new Set([entryPath])
|
|
100
|
+
let frontier = [entryPath]
|
|
101
|
+
for (let depth = 0; depth <= IMPORT_DEPTH && frontier.length > 0; depth++) {
|
|
102
|
+
const next: string[] = []
|
|
103
|
+
for (const file of frontier) {
|
|
104
|
+
const { code, inLiteral } =
|
|
105
|
+
file === entryPath && entryTokens ? entryTokens : tokenize(readIfExists(file) ?? '')
|
|
106
|
+
if ([...code.matchAll(pattern)].some((c) => !inLiteral(c.index))) return true
|
|
107
|
+
for (const m of code.matchAll(RELATIVE_IMPORT)) {
|
|
108
|
+
if (inLiteral(m.index)) continue
|
|
109
|
+
const dep = resolveRelative(file, m[1] ?? '')
|
|
110
|
+
if (dep === null || seen.has(dep)) continue
|
|
111
|
+
seen.add(dep)
|
|
112
|
+
next.push(dep)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
frontier = next
|
|
116
|
+
}
|
|
117
|
+
return false
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** A global regex matching a CALL of `name` (itself a regex source), generic or not — not an import or bare mention. */
|
|
121
|
+
export function callOf(pattern: string): RegExp {
|
|
122
|
+
return new RegExp(`\\b${pattern}\\b\\s*(?:<[^()]*>)?\\s*\\(`, 'g')
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const CREATE_BASALT_ROUTER = callOf('createBasaltRouter')
|
|
126
|
+
|
|
127
|
+
/** The directories a generated `routeTree.gen.*` is looked for in: beside the entry, then src/. */
|
|
128
|
+
export function routeTreeDirs(entry: string): string[] {
|
|
129
|
+
return [...new Set([dirname(entry), 'src'])]
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** A TanStack router plugin in the vite config, or a `routeTree.gen.*` in `routeTreeDirs`. */
|
|
133
|
+
export function hasRouteTree(dir: string, entry: string): boolean {
|
|
134
|
+
const vite = VITE_CONFIGS.map((f) => readIfExists(resolve(dir, f))).find((t) => t !== null) ?? ''
|
|
135
|
+
return (
|
|
136
|
+
registersRouterPlugin(vite) ||
|
|
137
|
+
routeTreeDirs(entry).some((d) =>
|
|
138
|
+
['ts', 'tsx', 'js'].some((e) => existsSync(resolve(dir, d, `routeTree.gen.${e}`))),
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Whether `createBasaltRouter` is called in a module reachable from the entry. */
|
|
144
|
+
export function hasRouter(dir: string, entry: string, entryTokens?: Tokens): boolean {
|
|
145
|
+
return callsIn(dir, entry, CREATE_BASALT_ROUTER, entryTokens)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Whether the (tokenized) entry imports the generated route tree — a freshly seeded entry does. */
|
|
149
|
+
function importsGeneratedTree({ code, inLiteral }: Tokens): boolean {
|
|
150
|
+
return [...code.matchAll(GENERATED_TREE_IMPORT)].some((m) => !inLiteral(m.index))
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* THE classification, shared by `init`, `sync` and `doctor`: code-routed = `createBasaltRouter` is
|
|
155
|
+
* called in a module reachable from the entry, no router plugin is registered and no
|
|
156
|
+
* `routeTree.gen.*` exists, and the entry does not import a generated tree (a freshly seeded entry
|
|
157
|
+
* does, before the first vite run — that app is file-routed). Comments and strings do not count.
|
|
158
|
+
*/
|
|
159
|
+
export function isCodeRoutedApp(cwd: string, appRel: string): boolean {
|
|
160
|
+
const dir = resolve(cwd, appRel)
|
|
161
|
+
const entry = appEntry(dir)
|
|
162
|
+
const tokens = tokenize(readIfExists(resolve(dir, entry)) ?? '')
|
|
163
|
+
if (importsGeneratedTree(tokens)) return false
|
|
164
|
+
return hasRouter(dir, entry, tokens) && !hasRouteTree(dir, entry)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** A TanStack Start app owns its router, so its router seeds give way to an in-tree `<BasaltProvider>`. */
|
|
168
|
+
export function isStartApp(cwd: string, appRel: string): boolean {
|
|
169
|
+
return hasDependency(resolve(cwd, appRel), '@tanstack/react-start')
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Why an app's router seeds are not placed (see `routerSeedSkip`). */
|
|
173
|
+
export type RouterSeedSkip = 'start' | 'code-routed' | null
|
|
174
|
+
|
|
175
|
+
export const CODE_ROUTED_NOTE =
|
|
176
|
+
'code-routed app (createBasaltRouter, no route-tree plugin or routeTree.gen) — no main.tsx/nav.tsx/__root.tsx seeded.'
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Why an app's router seeds (main/nav/__root) are not placed: `start` (Start owns the router, and
|
|
180
|
+
* wins when both apply) or `code-routed` (no generated tree to assume); null when they are.
|
|
181
|
+
*/
|
|
182
|
+
export function routerSeedSkip(cwd: string, appRel: string): RouterSeedSkip {
|
|
183
|
+
if (isStartApp(cwd, appRel)) return 'start'
|
|
184
|
+
return isCodeRoutedApp(cwd, appRel) ? 'code-routed' : null
|
|
185
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Textual source helpers shared by the CLI's router detection and its checks: reading a file as
|
|
3
|
+
* `null` when it is not there, a package.json dependency probe, and a comment/string tokenizer.
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync } from 'node:fs'
|
|
6
|
+
import { resolve } from 'node:path'
|
|
7
|
+
|
|
8
|
+
/** `abs` read as text, or null: absent, a directory, unreadable or raced away all mean "not there". */
|
|
9
|
+
export function readIfExists(abs: string): string | null {
|
|
10
|
+
try {
|
|
11
|
+
return readFileSync(abs, 'utf8')
|
|
12
|
+
} catch {
|
|
13
|
+
return null
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** `<dir>/package.json` parsed as `T`; null when absent or not JSON. */
|
|
18
|
+
export function readPackageJson<T>(dir: string): T | null {
|
|
19
|
+
const raw = readIfExists(resolve(dir, 'package.json'))
|
|
20
|
+
try {
|
|
21
|
+
return raw === null ? null : (JSON.parse(raw) as T)
|
|
22
|
+
} catch {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const DEPENDENCY_FIELDS = ['dependencies', 'devDependencies', 'peerDependencies'] as const
|
|
28
|
+
|
|
29
|
+
/** True when `pkgName` appears in any of the consumer's dependencies, devDependencies or peerDependencies. */
|
|
30
|
+
export function hasDependency(cwd: string, pkgName: string): boolean {
|
|
31
|
+
const pkg =
|
|
32
|
+
readPackageJson<Partial<Record<(typeof DEPENDENCY_FIELDS)[number], Record<string, string>>>>(
|
|
33
|
+
cwd,
|
|
34
|
+
)
|
|
35
|
+
return DEPENDENCY_FIELDS.some((field) => pkg?.[field]?.[pkgName] !== undefined)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Strings and template literals (captured) and comments. Known, accepted gap: a regex literal that
|
|
40
|
+
* contains a quote (`/'/`) opens a string this tokenizer never closes, which can blank or hide code
|
|
41
|
+
* after it on that line; a template literal nested inside a `${…}` is not tracked either.
|
|
42
|
+
*/
|
|
43
|
+
const TOKEN =
|
|
44
|
+
/("(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|`(?:\\.|[^`\\])*`)|\/\/[^\n]*|\/\*[\s\S]*?\*\//g
|
|
45
|
+
|
|
46
|
+
/** Source with comments blanked (and template text), plus a test for "offset sits inside a string". */
|
|
47
|
+
export function tokenize(src: string): { code: string; inLiteral: (at: number) => boolean } {
|
|
48
|
+
const literals: [number, number][] = []
|
|
49
|
+
const code = src.replace(TOKEN, (m, literal: string | undefined, at: number) => {
|
|
50
|
+
if (literal === undefined) return m.replace(/[^\n]/g, ' ')
|
|
51
|
+
if (!literal.startsWith('`')) {
|
|
52
|
+
literals.push([at, at + m.length])
|
|
53
|
+
return m
|
|
54
|
+
}
|
|
55
|
+
// Template literal: blank the text, keep the delimiters and the `${…}` code scannable.
|
|
56
|
+
return m.replace(
|
|
57
|
+
/(\$\{[^}]*\})|[^\n`]/g,
|
|
58
|
+
(c, interpolation: string | undefined) => interpolation ?? ' ',
|
|
59
|
+
)
|
|
60
|
+
})
|
|
61
|
+
return { code, inLiteral: (at) => literals.some(([from, to]) => at >= from && at < to) }
|
|
62
|
+
}
|
package/src/cli/sync.ts
CHANGED
|
@@ -30,9 +30,11 @@ import {
|
|
|
30
30
|
reportPrune,
|
|
31
31
|
resolvePlacement,
|
|
32
32
|
resolveProjectDir,
|
|
33
|
+
routerSeedPlan,
|
|
33
34
|
rootsNotices,
|
|
34
35
|
sha256,
|
|
35
36
|
shippedAssetPath,
|
|
37
|
+
START_APP_NOTE,
|
|
36
38
|
unitState,
|
|
37
39
|
writeFileEnsuringDir,
|
|
38
40
|
writeUnit,
|
|
@@ -110,7 +112,9 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
110
112
|
// Refuse BEFORE reconcileRoots, which writes `basalt.roots` into package.json.
|
|
111
113
|
if (!existsSync(resolve(cwd, MANIFEST_PATH))) {
|
|
112
114
|
const elsewhere = findManifestAbove(cwd)
|
|
113
|
-
const
|
|
115
|
+
const refused = resolvePlacement(cwd)
|
|
116
|
+
const { skipped: skippedSeeds } = routerSeedPlan(cwd, refused.appRel)
|
|
117
|
+
const wouldWrite = managedFiles(refused).filter((f) => !skippedSeeds.has(f.dest)).length
|
|
114
118
|
console.error(
|
|
115
119
|
`✖ basalt-ui sync: no ${MANIFEST_PATH} at ${cwd} — refusing to scaffold. ` +
|
|
116
120
|
`\`sync\` refreshes an EXISTING basalt install; creating one is \`basalt-ui init\`'s ` +
|
|
@@ -129,7 +133,8 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
129
133
|
const ctx = renderContext(cwd)
|
|
130
134
|
const manifest = readManifest(cwd)
|
|
131
135
|
const placement = resolvePlacement(cwd)
|
|
132
|
-
const
|
|
136
|
+
const { skip: seedSkip, skipped } = routerSeedPlan(cwd, placement.appRel)
|
|
137
|
+
const files = managedFiles(placement).filter((f) => !skipped.has(f.dest))
|
|
133
138
|
|
|
134
139
|
let updated = 0
|
|
135
140
|
// `created` and `recreated` were one counter, and `0 updated, 20 recreated` is what a full
|
|
@@ -198,9 +203,38 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
198
203
|
})
|
|
199
204
|
staleForCheck += pruned.removed.length + pruned.drifted.length
|
|
200
205
|
|
|
206
|
+
// A code-routed app takes no router seeds: their manifest entries go; any file stays the consumer's.
|
|
207
|
+
const isTracked = (d: string): boolean => manifest.files[d] !== undefined
|
|
208
|
+
const codeRoutedSeeds = seedSkip === 'code-routed' ? [...skipped].filter(isTracked) : []
|
|
209
|
+
if (codeRoutedSeeds.length > 0 && !opts.check) {
|
|
210
|
+
for (const d of codeRoutedSeeds) delete manifest.files[d]
|
|
211
|
+
console.error(
|
|
212
|
+
`⚠ basalt-ui sync: code-routed app — dropped ${codeRoutedSeeds.join(', ')} from the manifest (any file is yours).`,
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
|
|
201
216
|
// Placement notices — informational, never affecting the exit code, and PERMANENT: `--check`
|
|
202
217
|
// hides them behind `--verbose` (it sits in consumers' CI chains, where three unchanging
|
|
203
218
|
// "skipped" paragraphs per run are noise indistinguishable from drift) but still prints the COUNT.
|
|
219
|
+
// Start added AFTER a pre-Start init: the old seeds are the consumer's now — left untouched, named.
|
|
220
|
+
const startSkippedSeeds = seedSkip === 'start' ? [...skipped] : []
|
|
221
|
+
const stale = startSkippedSeeds.filter((d) => isTracked(d) && existsSync(resolve(cwd, d)))
|
|
222
|
+
const mounting = stale.filter((d) => !d.endsWith('nav.tsx'))
|
|
223
|
+
const inert = stale.filter((d) => d.endsWith('nav.tsx'))
|
|
224
|
+
const embedded =
|
|
225
|
+
'Delete them and render <BasaltProvider><Outlet /></BasaltProvider> in the Start root route (embedded mode).'
|
|
226
|
+
if (mounting.length > 0) {
|
|
227
|
+
console.error(
|
|
228
|
+
`⚠ basalt-ui sync: ${mounting.join(', ')} mount a second router inside this TanStack Start app; left untouched. ${embedded}`,
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
if (inert.length > 0) {
|
|
232
|
+
console.error(
|
|
233
|
+
`⚠ basalt-ui sync: ${inert.join(', ')} was seeded before this became a Start app; it mounts nothing, so keep or delete it. Left untouched.`,
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
if (seedSkip === 'start' && (!opts.check || syncFlags.includes('--verbose')))
|
|
237
|
+
console.log(`basalt-ui sync: ${START_APP_NOTE}`)
|
|
204
238
|
const placementSkips = placementNotices(cwd, placement)
|
|
205
239
|
if (opts.check !== true || syncFlags.includes('--verbose')) {
|
|
206
240
|
for (const line of placementSkips) console.log(`basalt-ui sync: ${line}`)
|
|
@@ -77,7 +77,13 @@
|
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
/* Both body states — the highlighted wrapper's `pre.shiki` and the bare fallback `<pre class=body>`
|
|
81
|
+
* — outrank Prose's `.root.article pre` block margin (0,2,1): at a tie, stylesheet order decided
|
|
82
|
+
* whether the inner pre kept 18px, so the fallback was ~36px taller than the highlighted fence and
|
|
83
|
+
* the swap jumped. `.body.body` lifts the fallback to (0,3,0); the outer `.container` margin alone
|
|
84
|
+
* owns the rhythm. */
|
|
85
|
+
.container .body.body,
|
|
86
|
+
.container .body :global(pre.shiki) {
|
|
81
87
|
margin: 0;
|
|
82
88
|
padding: 0;
|
|
83
89
|
background: transparent !important;
|
|
@@ -93,6 +99,18 @@ html[data-mantine-color-scheme='light'] .body :global(.shiki span) {
|
|
|
93
99
|
color: var(--shiki-light);
|
|
94
100
|
}
|
|
95
101
|
|
|
102
|
+
/* The floating button sits over the body's top-right corner, so the body reserves its box: the
|
|
103
|
+
* first line starts below offset + button height instead of running underneath it on touch (always
|
|
104
|
+
* visible) or on hover. `--code-block-copy-size` mirrors ActionIcon size="sm" (Mantine scopes its
|
|
105
|
+
* own `--ai-size-sm` to the button, out of the body's reach); the layout suite pins the two. */
|
|
106
|
+
.container[data-floating-copy] {
|
|
107
|
+
--code-block-copy-size: calc(1.375rem * var(--mantine-scale, 1));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.container[data-floating-copy] .body {
|
|
111
|
+
padding-top: calc(var(--vx-space-code-block-floating-copy-offset) + var(--code-block-copy-size));
|
|
112
|
+
}
|
|
113
|
+
|
|
96
114
|
/* Floating copy button — shown only when there is no header (no title), revealed on hover/focus. */
|
|
97
115
|
.floatingCopy {
|
|
98
116
|
position: absolute;
|
|
@@ -88,9 +88,14 @@ export function CodeBlock({
|
|
|
88
88
|
}, [html, code])
|
|
89
89
|
|
|
90
90
|
const containerClass = [classes.container, className].filter(Boolean).join(' ')
|
|
91
|
+
const showFloatingCopy = title === undefined && showCopy
|
|
91
92
|
|
|
92
93
|
return (
|
|
93
|
-
<div
|
|
94
|
+
<div
|
|
95
|
+
className={containerClass}
|
|
96
|
+
{...(showFloatingCopy && { 'data-floating-copy': true })}
|
|
97
|
+
{...(style !== undefined && { style })}
|
|
98
|
+
>
|
|
94
99
|
{title !== undefined && (
|
|
95
100
|
<div className={classes.header}>
|
|
96
101
|
<span className={classes.title}>{title}</span>
|
|
@@ -116,7 +121,7 @@ export function CodeBlock({
|
|
|
116
121
|
<code>{code}</code>
|
|
117
122
|
</pre>
|
|
118
123
|
)}
|
|
119
|
-
{
|
|
124
|
+
{showFloatingCopy && (
|
|
120
125
|
<div className={classes.floatingCopy}>
|
|
121
126
|
<CopyAction value={code} ariaLabel="Copy code" />
|
|
122
127
|
</div>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-process for beautiful-mermaid's SVG (consumed by `./mermaid`).
|
|
3
|
+
*
|
|
4
|
+
* `buildStyleBlock(font)` treats the font as a family NAME: it emits a Google Fonts `@import` (plus
|
|
5
|
+
* a JetBrains Mono one when `mono` is set) and writes `text { font-family: '<font>', … }`. basalt
|
|
6
|
+
* feeds it `var(--basalt-font-sans)`, so the import is a broken request and the quoted `'var(…)'`
|
|
7
|
+
* is an invalid family. basalt self-hosts its fonts: drop the import, unquote the var().
|
|
8
|
+
*
|
|
9
|
+
* Patterns verified against beautiful-mermaid 1.1.3 (peer range ^1.1.0): the style block is a
|
|
10
|
+
* single `<style>` holding the `@import`s and one `text { font-family }` rule; `font-family`
|
|
11
|
+
* never appears as a presentation attribute. Only `<style>` content is rewritten — a node label
|
|
12
|
+
* that happens to contain the same text is left alone.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const STYLE_BLOCK = /(<style\b[^>]*>)([\s\S]*?)(<\/style>)/gi
|
|
16
|
+
|
|
17
|
+
// One `@import` statement, built from fragments. The family URL itself contains `;` (`wght@400;500`,
|
|
18
|
+
// `&`), so each form is bounded by its closing quote / `)` — never by `;` — and never crosses
|
|
19
|
+
// a newline or `}`: a truncated import cannot eat unrelated CSS.
|
|
20
|
+
const HOST = String.raw`(?:https?:)?\/\/fonts\.googleapis\.com`
|
|
21
|
+
const QUOTED_FORM = String.raw`(?:url\(\s*)?(['"])${HOST}[^'"}\n]*\1(?:\s*\))?` // 'url' | url('url') | url("url")
|
|
22
|
+
const URL_FORM = String.raw`url\(\s*${HOST}[^}'"\n]*?\)` // url(url)
|
|
23
|
+
const MEDIA_LIST = String.raw`(?:[ \t]+[^;{}\n]*)?` // `url(…) screen`
|
|
24
|
+
const GOOGLE_FONTS_IMPORT = new RegExp(
|
|
25
|
+
String.raw`@import\s+(?:${QUOTED_FORM}|${URL_FORM})${MEDIA_LIST}[ \t]*;?`,
|
|
26
|
+
'g',
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
// `font-family: 'var(--x)'` — a value that is exactly a quoted var(). `var(--a, 'fallback')` has a
|
|
30
|
+
// quote inside and `'Inter', var(--x)` does not start with var(, so neither matches.
|
|
31
|
+
const QUOTED_VAR_FONT_FAMILY = /(font-family\s*:\s*)(['"])(var\([^'"]*\))\2/g
|
|
32
|
+
|
|
33
|
+
function sanitizeStyle(css: string): string {
|
|
34
|
+
const cleaned = css.replace(GOOGLE_FONTS_IMPORT, '').replace(QUOTED_VAR_FONT_FAMILY, '$1$3')
|
|
35
|
+
if (process.env.NODE_ENV !== 'production' && /googleapis/i.test(cleaned)) {
|
|
36
|
+
console.warn(
|
|
37
|
+
'[basalt] MermaidDiagram: a remote font import survived sanitization — beautiful-mermaid ' +
|
|
38
|
+
'changed its <style> output; update src/content/mermaid-sanitize.ts.',
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
return cleaned
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function sanitizeMermaidFonts(svg: string): string {
|
|
45
|
+
return svg.replace(
|
|
46
|
+
STYLE_BLOCK,
|
|
47
|
+
(_block, open: string, css: string, close: string) => open + sanitizeStyle(css) + close,
|
|
48
|
+
)
|
|
49
|
+
}
|
package/src/content/mermaid.tsx
CHANGED
|
@@ -23,6 +23,7 @@ import type { CSSProperties, ReactNode } from 'react'
|
|
|
23
23
|
import { useEffect, useMemo, useState } from 'react'
|
|
24
24
|
import { CodeBlock } from './code-block'
|
|
25
25
|
import classes from './mermaid.module.css'
|
|
26
|
+
import { sanitizeMermaidFonts } from './mermaid-sanitize'
|
|
26
27
|
|
|
27
28
|
// Import the type only — erased at runtime (verbatimModuleSyntax safe). `beautiful-mermaid` is a
|
|
28
29
|
// devDependency purely so this type resolves; the runtime import below is fully dynamic.
|
|
@@ -36,7 +37,7 @@ type MermaidModule = {
|
|
|
36
37
|
* Static theme mapping onto the `--vx-*` token layer — every value is a `var(--vx-*)` string, so
|
|
37
38
|
* this object never changes across renders/schemes and can live at module scope.
|
|
38
39
|
*/
|
|
39
|
-
const MERMAID_THEME_OPTIONS: RenderOptions = {
|
|
40
|
+
export const MERMAID_THEME_OPTIONS: RenderOptions = {
|
|
40
41
|
bg: 'var(--vx-surface-panel)',
|
|
41
42
|
fg: 'var(--vx-ink)',
|
|
42
43
|
line: 'var(--vx-line)',
|
|
@@ -87,7 +88,7 @@ export function MermaidDiagram({ code, className, style, fallback }: MermaidDiag
|
|
|
87
88
|
const rendered = useMemo(() => {
|
|
88
89
|
if (!mod) return null
|
|
89
90
|
try {
|
|
90
|
-
return mod.renderMermaidSVG(code, MERMAID_THEME_OPTIONS)
|
|
91
|
+
return sanitizeMermaidFonts(mod.renderMermaidSVG(code, MERMAID_THEME_OPTIONS))
|
|
91
92
|
} catch {
|
|
92
93
|
return undefined
|
|
93
94
|
}
|
package/src/provider/index.tsx
CHANGED
|
@@ -18,7 +18,7 @@ import { Spotlight } from '@mantine/spotlight'
|
|
|
18
18
|
import type { SpotlightActionData } from '@mantine/spotlight'
|
|
19
19
|
import { QueryClientProvider } from '@tanstack/react-query'
|
|
20
20
|
import type { QueryClient } from '@tanstack/react-query'
|
|
21
|
-
import { RouterProvider } from '@tanstack/react-router'
|
|
21
|
+
import { RouterProvider, useRouter } from '@tanstack/react-router'
|
|
22
22
|
import type { AnyRouter } from '@tanstack/react-router'
|
|
23
23
|
import { Component, Suspense, lazy, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
24
24
|
import type { ErrorInfo, ReactNode } from 'react'
|
|
@@ -50,9 +50,7 @@ import { useRegistryHotkeys } from './hotkeys'
|
|
|
50
50
|
import type { FlatNavItem } from '../router-tanstack/nav'
|
|
51
51
|
import { buildSpotlightActions } from './spotlight-actions'
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
/** From `createBasaltRouter`; the provider mounts it and reads its `queryClient`. */
|
|
55
|
-
router: BasaltRouter
|
|
53
|
+
type BasaltProviderCommonProps = {
|
|
56
54
|
/** Theme override merged onto the Basalt base. Defaults to `createBasaltTheme()`. */
|
|
57
55
|
theme?: MantineProviderProps['theme']
|
|
58
56
|
/**
|
|
@@ -92,8 +90,33 @@ export type BasaltProviderProps = {
|
|
|
92
90
|
* entry with id `nav.<id>` replaces the generated one outright.
|
|
93
91
|
*/
|
|
94
92
|
navCommandLabel?: (item: FlatNavItem) => string
|
|
93
|
+
/**
|
|
94
|
+
* Mount Basalt's `<Spotlight>` (Cmd+K) with the generated nav + command actions. Default `true`.
|
|
95
|
+
* Set `false` when the app owns its own palette: neither the component nor its action wiring mounts.
|
|
96
|
+
*/
|
|
97
|
+
spotlight?: boolean
|
|
95
98
|
} & Omit<MantineProviderProps, 'children' | 'theme' | 'defaultColorScheme' | 'cssVariablesResolver'>
|
|
96
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Two modes, never both: pass a `createBasaltRouter` `router` and the provider mounts it, or pass
|
|
102
|
+
* `children` and render the provider INSIDE a router the app does not own (around the `<Outlet />`
|
|
103
|
+
* of TanStack Start's root route component) — the router then comes from `useRouter()` and must carry
|
|
104
|
+
* `context.queryClient` (its `getRouter()` builds the same context `createBasaltRouter` does).
|
|
105
|
+
*/
|
|
106
|
+
export type BasaltProviderProps = BasaltProviderCommonProps &
|
|
107
|
+
(
|
|
108
|
+
| {
|
|
109
|
+
/** From `createBasaltRouter`; the provider mounts it and reads its `queryClient`. */
|
|
110
|
+
router: BasaltRouter
|
|
111
|
+
children?: never
|
|
112
|
+
}
|
|
113
|
+
| {
|
|
114
|
+
router?: never
|
|
115
|
+
/** The subtree inside the app's own router; rendered where `<RouterProvider>` would be. */
|
|
116
|
+
children: ReactNode
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
|
|
97
120
|
// ── Root error boundary ───────────────────────────────────────────────────────────────────────────
|
|
98
121
|
|
|
99
122
|
type RootBoundaryProps = {
|
|
@@ -395,24 +418,42 @@ function useDataTelemetry(router: AnyRouter, client: QueryClient, emit: Telemetr
|
|
|
395
418
|
}
|
|
396
419
|
|
|
397
420
|
// ── Dev dock (dev-only, behind a literal NODE_ENV read at the lazy site) ──────────────────────────
|
|
421
|
+
// The gate wraps `lazy()` itself so the dock chunks never ship; the consumer bundler must define
|
|
422
|
+
// `process.env.NODE_ENV` for the fold, as it already must for `lab-theme.ts`.
|
|
398
423
|
|
|
399
|
-
const
|
|
424
|
+
const loadDevDock = () => import('../dev-dock').then((m) => ({ default: m.BasaltDevDock }))
|
|
425
|
+
const LazyDevDock = process.env.NODE_ENV === 'production' ? null : lazy(loadDevDock)
|
|
400
426
|
|
|
401
427
|
function readQueryClient(router: AnyRouter): QueryClient {
|
|
402
428
|
const client = (router.options.context as Partial<BasaltRouterContext> | undefined)?.queryClient
|
|
403
429
|
if (client === undefined) {
|
|
404
430
|
throw new Error(
|
|
405
|
-
'[basalt] BasaltProvider:
|
|
406
|
-
'
|
|
431
|
+
'[basalt] BasaltProvider: no context.queryClient — pass `router` from createBasaltRouter, ' +
|
|
432
|
+
'or with `children` put a QueryClient in the router context.',
|
|
407
433
|
)
|
|
408
434
|
}
|
|
409
435
|
return client
|
|
410
436
|
}
|
|
411
437
|
|
|
438
|
+
/**
|
|
439
|
+
* The router this provider serves: the one it mounts (`router`), else — embedded mode — the one the
|
|
440
|
+
* host already mounted above it. `warn: false`: mount mode sits ABOVE any router, so no context is
|
|
441
|
+
* expected there. The context read is SSR-safe.
|
|
442
|
+
*/
|
|
443
|
+
function useEffectiveRouter(mounted: BasaltRouter | undefined): AnyRouter {
|
|
444
|
+
const ambient: AnyRouter | undefined = useRouter<AnyRouter>({ warn: false })
|
|
445
|
+
const router = mounted ?? ambient
|
|
446
|
+
if (!router) {
|
|
447
|
+
throw new Error(
|
|
448
|
+
'[basalt] BasaltProvider: no router — pass `router` to mount one, or `children` inside one.',
|
|
449
|
+
)
|
|
450
|
+
}
|
|
451
|
+
return router
|
|
452
|
+
}
|
|
453
|
+
|
|
412
454
|
// ── Public provider ───────────────────────────────────────────────────────────────────────────────
|
|
413
455
|
|
|
414
456
|
export function BasaltProvider({
|
|
415
|
-
router,
|
|
416
457
|
theme,
|
|
417
458
|
telemetry,
|
|
418
459
|
fallback,
|
|
@@ -422,6 +463,9 @@ export function BasaltProvider({
|
|
|
422
463
|
nonce,
|
|
423
464
|
sizeClassHint = 'compact',
|
|
424
465
|
navCommandLabel,
|
|
466
|
+
spotlight = true,
|
|
467
|
+
router: mountedRouter,
|
|
468
|
+
children,
|
|
425
469
|
...rest
|
|
426
470
|
}: BasaltProviderProps) {
|
|
427
471
|
useDuplicateProviderGuard()
|
|
@@ -438,6 +482,7 @@ export function BasaltProvider({
|
|
|
438
482
|
// `overlays.confirm` is an imperative call; this tells it a `ModalsProvider` is live.
|
|
439
483
|
useEffect(() => registerModalsProvider(), [])
|
|
440
484
|
|
|
485
|
+
const router = useEffectiveRouter(mountedRouter)
|
|
441
486
|
const client = readQueryClient(router)
|
|
442
487
|
useDataTelemetry(router, client, emit)
|
|
443
488
|
|
|
@@ -449,7 +494,9 @@ export function BasaltProvider({
|
|
|
449
494
|
() => setActions(buildSpotlightActions(router, setDevTool, navCommandLabel)),
|
|
450
495
|
[router, navCommandLabel],
|
|
451
496
|
)
|
|
452
|
-
useEffect(
|
|
497
|
+
useEffect(() => {
|
|
498
|
+
if (spotlight) refreshActions()
|
|
499
|
+
}, [spotlight, refreshActions])
|
|
453
500
|
|
|
454
501
|
// `createBasaltTheme(theme)` — plus, when the theme lab's "Apply" switch is on, the delta of its
|
|
455
502
|
// persisted config, so the dev tool moves the numeric `defaultProps` and `theme.spacing` a `<style>`
|
|
@@ -474,9 +521,13 @@ export function BasaltProvider({
|
|
|
474
521
|
<QueryClientProvider client={client}>
|
|
475
522
|
{/* ModalsProvider WRAPS the router, so `useModals()` / `openContextModal` have real context. */}
|
|
476
523
|
<ModalsProvider>
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
524
|
+
{mountedRouter === undefined ? (
|
|
525
|
+
children
|
|
526
|
+
) : (
|
|
527
|
+
<RouterProvider router={mountedRouter} />
|
|
528
|
+
)}
|
|
529
|
+
{/* `LazyDevDock` is `null` in production (module-scope gate above), so nothing mounts. */}
|
|
530
|
+
{LazyDevDock !== null && (
|
|
480
531
|
<Suspense fallback={null}>
|
|
481
532
|
<LazyDevDock
|
|
482
533
|
tool={devTool}
|
|
@@ -488,12 +539,14 @@ export function BasaltProvider({
|
|
|
488
539
|
</ModalsProvider>
|
|
489
540
|
</QueryClientProvider>
|
|
490
541
|
<Notifications position="bottom-right" autoClose={4000} limit={5} />
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
542
|
+
{spotlight && (
|
|
543
|
+
<Spotlight
|
|
544
|
+
actions={actions}
|
|
545
|
+
onSpotlightOpen={refreshActions}
|
|
546
|
+
shortcut="mod + K"
|
|
547
|
+
maxHeight={420}
|
|
548
|
+
/>
|
|
549
|
+
)}
|
|
497
550
|
</SizeClassHintContext.Provider>
|
|
498
551
|
</TelemetryContext.Provider>
|
|
499
552
|
</BasaltBridge>
|