@adea-ai/ui 0.151.10 → 0.151.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/components/composites/appearance-editor/appearance-rows.d.ts.map +1 -1
  2. package/dist/components/composites/appearance-editor/appearance-rows.js +16 -3
  3. package/dist/components/composites/appearance-editor/appearance-rows.js.map +1 -1
  4. package/dist/components/layout/contextual-sidebar/contextual-sidebar.d.ts +12 -0
  5. package/dist/components/layout/contextual-sidebar/contextual-sidebar.d.ts.map +1 -1
  6. package/dist/components/layout/contextual-sidebar/contextual-sidebar.js +51 -16
  7. package/dist/components/layout/contextual-sidebar/contextual-sidebar.js.map +1 -1
  8. package/dist/components/layout/contextual-sidebar/index.d.ts +1 -1
  9. package/dist/components/layout/contextual-sidebar/index.d.ts.map +1 -1
  10. package/dist/components/layout/shell-top-bar/shell-top-bar.d.ts +16 -10
  11. package/dist/components/layout/shell-top-bar/shell-top-bar.d.ts.map +1 -1
  12. package/dist/components/layout/shell-top-bar/shell-top-bar.js +2 -1
  13. package/dist/components/layout/shell-top-bar/shell-top-bar.js.map +1 -1
  14. package/dist/components/theme/script-projection.d.ts +17 -0
  15. package/dist/components/theme/script-projection.d.ts.map +1 -0
  16. package/dist/components/theme/script-projection.js +16 -0
  17. package/dist/components/theme/script-projection.js.map +1 -0
  18. package/dist/components/theme/theme-document-core.d.ts +5 -4
  19. package/dist/components/theme/theme-document-core.d.ts.map +1 -1
  20. package/dist/components/theme/theme-document-core.js +13 -3
  21. package/dist/components/theme/theme-document-core.js.map +1 -1
  22. package/dist/components/theme/theme-provider-value.d.ts +2 -1
  23. package/dist/components/theme/theme-provider-value.d.ts.map +1 -1
  24. package/dist/components/theme/theme-provider-value.js +7 -0
  25. package/dist/components/theme/theme-provider-value.js.map +1 -1
  26. package/dist/components/theme/theme-script.d.ts +12 -0
  27. package/dist/components/theme/theme-script.d.ts.map +1 -1
  28. package/dist/components/theme/theme-script.js +14 -5
  29. package/dist/components/theme/theme-script.js.map +1 -1
  30. package/dist/components/theme/theme-state-core.d.ts +6 -0
  31. package/dist/components/theme/theme-state-core.d.ts.map +1 -1
  32. package/dist/components/theme/theme-state-core.js.map +1 -1
  33. package/dist/components/theme/token-projection-options.d.ts +3 -0
  34. package/dist/components/theme/token-projection-options.d.ts.map +1 -0
  35. package/dist/components/theme/token-projection-options.js +9 -0
  36. package/dist/components/theme/token-projection-options.js.map +1 -0
  37. package/dist/components/theme/token-projection.d.ts +22 -0
  38. package/dist/components/theme/token-projection.d.ts.map +1 -0
  39. package/dist/components/theme/token-projection.js +1 -0
  40. package/dist/r/appearance-editor.json +1 -1
  41. package/dist/r/lib.json +1 -1
  42. package/dist/r/registry.json +18 -3
  43. package/dist/r/src/components/composites/appearance-editor/appearance-rows.tsx +17 -9
  44. package/dist/r/src/components/layout/contextual-sidebar/contextual-sidebar.tsx +76 -19
  45. package/dist/r/src/components/layout/contextual-sidebar/index.ts +1 -0
  46. package/dist/r/src/components/layout/shell-top-bar/shell-top-bar.tsx +22 -14
  47. package/dist/r/src/components/theme/script-projection.ts +40 -0
  48. package/dist/r/src/components/theme/theme-document-core.ts +17 -4
  49. package/dist/r/src/components/theme/theme-provider-value.ts +11 -1
  50. package/dist/r/src/components/theme/theme-script.ts +52 -4
  51. package/dist/r/src/components/theme/theme-state-core.ts +6 -0
  52. package/dist/r/src/components/theme/token-projection-options.ts +14 -0
  53. package/dist/r/src/components/theme/token-projection.ts +37 -0
  54. package/dist/r/theming.json +16 -1
  55. package/package.json +14 -2
  56. package/registry.json +18 -3
  57. package/src/components/composites/appearance-editor/appearance-rows.tsx +17 -9
  58. package/src/components/layout/contextual-sidebar/contextual-sidebar.tsx +76 -19
  59. package/src/components/layout/contextual-sidebar/index.ts +1 -0
  60. package/src/components/layout/shell-top-bar/shell-top-bar.tsx +22 -14
  61. package/src/components/theme/script-projection.ts +40 -0
  62. package/src/components/theme/theme-document-core.ts +17 -4
  63. package/src/components/theme/theme-provider-value.ts +11 -1
  64. package/src/components/theme/theme-script.ts +52 -4
  65. package/src/components/theme/theme-state-core.ts +6 -0
  66. package/src/components/theme/token-projection-options.ts +14 -0
  67. package/src/components/theme/token-projection.ts +37 -0
@@ -1,5 +1,7 @@
1
1
  import type { JSX } from 'solid-js'
2
2
  import { createEffect, createMemo, createSignal, onCleanup, splitProps, untrack } from 'solid-js'
3
+ import type { ThemeTokenProjectionOptions } from './token-projection'
4
+ import { assertThemeTokenProjectionConfig } from './token-projection-options'
3
5
  import { fontZoomShortcut, type FontZoomIntent } from '../../lib/font-zoom'
4
6
  import { REDUCED_TRANSPARENCY_QUERY, resolveSurfaceState } from '../../lib/theme-surface'
5
7
  import { CatalogueRequired, needsCatalogue, type ThemeEngine } from '../../lib/theme-engine'
@@ -156,7 +158,7 @@ export type ThemeProviderProps = {
156
158
  * `zoomFonts` on the context does the same from a menu or a host's own binding.
157
159
  */
158
160
  fontZoom?: boolean
159
- }
161
+ } & ThemeTokenProjectionOptions
160
162
 
161
163
  /**
162
164
  * Where the provider's catalogue questions are answered, and whether the whole
@@ -199,6 +201,7 @@ function reducedTransparencyMedia(): MediaQueryList | undefined {
199
201
  export function createThemeContextValue(
200
202
  props: ThemeProviderProps & { catalogue: ThemeCatalogueSource }
201
203
  ): ThemeContextValue {
204
+ assertThemeTokenProjectionConfig(props.tokenProjection)
202
205
  const [local] = splitProps(props, [
203
206
  'catalogue',
204
207
  'storageKey',
@@ -207,6 +210,7 @@ export function createThemeContextValue(
207
210
  'persistence',
208
211
  'themes',
209
212
  'transformTokens',
213
+ 'tokenProjection',
210
214
  'disableTransitionOnChange',
211
215
  'accentContrastFloor',
212
216
  'surface',
@@ -266,6 +270,7 @@ export function createThemeContextValue(
266
270
  const shown = createMemo(() =>
267
271
  draft() ? resolveThemeState(shownSelection(), systemAppearance(), registry()) : committed()
268
272
  )
273
+ const shownAppearance = createMemo<ThemeAppearance>(() => shown().appearance)
269
274
 
270
275
  // The surface axis. Off, none of this reads the operating system: the media query
271
276
  // is subscribed only while the axis is on, so a provider that never opts in adds no
@@ -328,8 +333,12 @@ export function createThemeContextValue(
328
333
  terminalVariant: resolveTerminalVariant(shownSelection().terminalThemeId, registry()),
329
334
  surface: axisOn() ? surfaceStateOf(shownSelection()) : undefined,
330
335
  }
336
+ const projectionOptions = local.tokenProjection
337
+ ? { tokenProjection: local.tokenProjection }
338
+ : {}
331
339
  const options = {
332
340
  transformTokens: local.transformTokens,
341
+ ...projectionOptions,
333
342
  accentContrastFloor: local.accentContrastFloor,
334
343
  palette: local.palette,
335
344
  editorRoles: local.editorRoles,
@@ -382,6 +391,7 @@ export function createThemeContextValue(
382
391
  const value: ThemeContextValue = {
383
392
  selection,
384
393
  resolvedAppearance,
394
+ shownAppearance,
385
395
  variant,
386
396
  get themes() {
387
397
  return engine().builtinThemes
@@ -13,6 +13,7 @@ import { safeScriptStringLiteral } from '../../lib/safe-script'
13
13
  import { REDUCED_TRANSPARENCY_QUERY, surfaceAlpha } from '../../lib/theme-surface'
14
14
  import { accentPresets } from '../../lib/accent-presets'
15
15
  import { THEME_INDEX, defaultDarkThemeId, defaultLightThemeId } from '../../lib/theme-defaults'
16
+ import type { ThemeTokenProjection } from '@adea-ai/themes/theme-token-projection'
16
17
  import type { ThemeStorageSchema } from './theme-persistence'
17
18
 
18
19
  /**
@@ -37,6 +38,14 @@ export function inlineScriptLiteral(value: string): string {
37
38
  return safeScriptStringLiteral(value)
38
39
  }
39
40
 
41
+ /** A stored-record path that can supply an absent projection source token. */
42
+ export type ThemeTokenProjectionFallback = Readonly<{
43
+ /** The CSS custom property to fill only when the stored token map omits it. */
44
+ token: string
45
+ /** Own-property path from the stored library record to a string value. */
46
+ path: readonly string[]
47
+ }>
48
+
40
49
  /**
41
50
  * Options for the host-shaped no-flash script: the document's {@link ThemeStorageSchema}
42
51
  * plus what the script paints from it.
@@ -122,6 +131,24 @@ export function themeScript(input: string | ThemeScriptOptions = 'adea-appearanc
122
131
  return optionsFormScript(input)
123
132
  }
124
133
 
134
+ /** Internal hook for the opt-in script entry, which supplies its generated browser bundle. */
135
+ export function themeScriptWithProjection(
136
+ options: ThemeScriptOptions & {
137
+ tokenProjectionFallbacks?: readonly ThemeTokenProjectionFallback[]
138
+ },
139
+ tokenProjection: ThemeTokenProjection,
140
+ projectionBundle: string,
141
+ projectionFallbackScript: string
142
+ ): string {
143
+ return optionsFormScript(
144
+ options,
145
+ tokenProjection,
146
+ projectionBundle,
147
+ projectionFallbackScript,
148
+ options.tokenProjectionFallbacks
149
+ )
150
+ }
151
+
125
152
  function stringFormScript(storageKey: string): string {
126
153
  const script = `(function(){try{var s=localStorage.getItem(${inlineScriptLiteral(storageKey)});var p=s?JSON.parse(s):{};var a=p.appearance||'system';var d=a==='dark'||(a==='system'&&window.matchMedia('(prefers-color-scheme: dark)').matches);var r=document.documentElement;if(d)r.classList.add('dark');r.style.colorScheme=d?'dark':'light';if(p.accent&&p.accent!=='theme')r.dataset.accent=p.accent;if(p.density==='compact')r.dataset.density='compact';}catch(e){}})();`
127
154
  return `${script}${fontSettingsBootstrapScript(storageKey)}`
@@ -129,7 +156,13 @@ function stringFormScript(storageKey: string): string {
129
156
 
130
157
  const literal = safeScriptStringLiteral
131
158
 
132
- function optionsFormScript(options: ThemeScriptOptions): string {
159
+ function optionsFormScript(
160
+ options: ThemeScriptOptions,
161
+ projection?: ThemeTokenProjection,
162
+ projectionBundle?: string,
163
+ projectionFallbackScript = '',
164
+ projectionFallbacks?: readonly ThemeTokenProjectionFallback[]
165
+ ): string {
133
166
  const field = options.appearanceField ?? 'appearance'
134
167
  const versionGuard =
135
168
  options.version === undefined ? '' : `&&x.version===${Number(options.version)}`
@@ -142,6 +175,20 @@ function optionsFormScript(options: ThemeScriptOptions): string {
142
175
  : isCustomAccent(options.defaultAccent)
143
176
  ? 'custom'
144
177
  : options.defaultAccent
178
+ const canProjectTokens =
179
+ options.libraryKey !== undefined &&
180
+ projection &&
181
+ projection.length > 0 &&
182
+ projectionBundle !== undefined
183
+ const hasProjectionFallbacks = canProjectTokens && !!projectionFallbacks?.length
184
+ const tokenProjection = canProjectTokens
185
+ ? `var projectTokens=${projectionBundle};var tokenProjection=JSON.parse(${literal(JSON.stringify(projection))});${
186
+ hasProjectionFallbacks
187
+ ? `var tokenProjectionFallbacks=JSON.parse(${literal(JSON.stringify(projectionFallbacks))});`
188
+ : ''
189
+ }`
190
+ : ''
191
+ const projectionFallbackCode = hasProjectionFallbacks ? projectionFallbackScript : ''
145
192
 
146
193
  const parts: string[] = []
147
194
  parts.push(
@@ -165,16 +212,17 @@ function optionsFormScript(options: ThemeScriptOptions): string {
165
212
  `var want=doc?(dark?doc.darkThemeId:doc.lightThemeId):null;`,
166
213
  `if(typeof want!=='string')want=fallback;`,
167
214
  `var ids=[${THEME_INDEX.map(([id]) => literal(id)).join(',')}];`,
168
- `var id=ids.indexOf(want)!==-1?want:null,tokens=null;`
215
+ `var id=ids.indexOf(want)!==-1?want:null,tokens=null${hasProjectionFallbacks ? ',storedTheme=null' : ''};`
169
216
  )
170
217
  if (options.libraryKey !== undefined) {
171
218
  parts.push(
172
219
  `if(id===null){try{var lib=JSON.parse(get(${literal(options.libraryKey)})||'null');`,
173
220
  `if(lib&&typeof lib==='object'&&lib.version===${Number(options.libraryVersion ?? 1)}&&Array.isArray(lib.themes)){`,
174
221
  `for(var i=0;i!==lib.themes.length;i++){var t=lib.themes[i];`,
175
- `if(t&&t.id===want&&t.flatTokens&&typeof t.flatTokens==='object'){id=want;tokens=t.flatTokens;break}}}}catch(e){}}`
222
+ `if(t&&t.id===want&&t.flatTokens&&typeof t.flatTokens==='object'){id=want;tokens=t.flatTokens;${hasProjectionFallbacks ? 'storedTheme=t;' : ''}break}}}}catch(e){}}`
176
223
  )
177
224
  }
225
+ if (options.libraryKey !== undefined && tokenProjection) parts.push(tokenProjection)
178
226
  parts.push(
179
227
  `if(id===null)id=fallback;`,
180
228
  `r.classList.toggle('dark',dark);`,
@@ -184,7 +232,7 @@ function optionsFormScript(options: ThemeScriptOptions): string {
184
232
  )
185
233
  if (options.libraryKey !== undefined) {
186
234
  parts.push(
187
- `if(tokens){for(var n in tokens){if(Object.prototype.hasOwnProperty.call(tokens,n)&&n.slice(0,2)==='--'&&typeof tokens[n]==='string')s.setProperty(n,tokens[n])}}`
235
+ `if(tokens){if(typeof projectTokens==='function'){${projectionFallbackCode}tokens=projectTokens(tokens,tokenProjection)}for(var n in tokens){if(Object.prototype.hasOwnProperty.call(tokens,n)&&n.slice(0,2)==='--'&&typeof tokens[n]==='string')s.setProperty(n,tokens[n])}}`
188
236
  )
189
237
  }
190
238
  parts.push(
@@ -131,6 +131,12 @@ export type ThemeContextValue = {
131
131
  selection: () => ThemeSelection
132
132
  /** What the preference resolves to right now, after `system`. */
133
133
  resolvedAppearance: () => ThemeAppearance
134
+ /**
135
+ * The appearance currently shown by the provider, including an active preview.
136
+ * Optional for compatibility with values supplied by an older copy of the UI
137
+ * package or by a host-owned context mock; providers always expose it.
138
+ */
139
+ shownAppearance?: () => ThemeAppearance
134
140
  /** The variant in use. */
135
141
  variant: () => ThemeVariant
136
142
  /** Update part of the preference. */
@@ -0,0 +1,14 @@
1
+ /** Keep the runtime configuration check free of the optional Themes projector import. */
2
+ export function assertThemeTokenProjectionConfig(config: unknown): void {
3
+ if (config === undefined) return
4
+ if (
5
+ !config ||
6
+ typeof config !== 'object' ||
7
+ !('rules' in config) ||
8
+ !Array.isArray(config.rules) ||
9
+ !('project' in config) ||
10
+ typeof config.project !== 'function'
11
+ ) {
12
+ throw new TypeError('tokenProjection requires both rules and project')
13
+ }
14
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Runtime token projection for hosts that opt in to projecting legacy theme maps.
3
+ * The default provider and boot script do not import this entry.
4
+ */
5
+ import type { ThemeTokenProjection } from '@adea-ai/themes/theme-token-projection'
6
+
7
+ export {
8
+ projectThemeTokens,
9
+ projectThemeTokensDetailed,
10
+ } from '@adea-ai/themes/theme-token-projection'
11
+ export type {
12
+ ThemeTokenContrastRule,
13
+ ThemeTokenProjection,
14
+ ThemeTokenProjectionFailure,
15
+ ThemeTokenProjectionResult,
16
+ ThemeTokenProjectionRule,
17
+ } from '@adea-ai/themes/theme-token-projection'
18
+
19
+ /** Function type for the shared projector supplied by opt-in hosts. */
20
+ export type ThemeTokenProjector = (
21
+ tokens: Readonly<Record<string, string>>,
22
+ projection: ThemeTokenProjection
23
+ ) => Record<string, string>
24
+
25
+ /** Rules and their projector travel together through provider/document options. */
26
+ export type ThemeTokenProjectionConfig = Readonly<{
27
+ rules: ThemeTokenProjection
28
+ project: ThemeTokenProjector
29
+ }>
30
+
31
+ /**
32
+ * Projection rules and their runtime; hosts that opt in provide both. The rules operate
33
+ * on each custom variant's raw `tokens` map, preserving the prepaint source's availability.
34
+ */
35
+ export type ThemeTokenProjectionOptions = {
36
+ tokenProjection?: ThemeTokenProjectionConfig
37
+ }
@@ -4,7 +4,7 @@
4
4
  "title": "Theming",
5
5
  "description": "",
6
6
  "dependencies": [
7
- "@adea-ai/themes@^0.11.7",
7
+ "@adea-ai/themes@>0.11.7 <0.12.0",
8
8
  "@kobalte/core@^0.13.14",
9
9
  "lucide-solid@^1.65.0"
10
10
  ],
@@ -33,6 +33,11 @@
33
33
  "type": "registry:ui",
34
34
  "target": "components/theming/lazy.ts"
35
35
  },
36
+ {
37
+ "path": "src/components/theme/script-projection.ts",
38
+ "type": "registry:ui",
39
+ "target": "components/theming/script-projection.ts"
40
+ },
36
41
  {
37
42
  "path": "src/components/theme/script.ts",
38
43
  "type": "registry:ui",
@@ -112,6 +117,16 @@
112
117
  "path": "src/components/theme/theme-toggle.tsx",
113
118
  "type": "registry:ui",
114
119
  "target": "components/theming/theme-toggle.tsx"
120
+ },
121
+ {
122
+ "path": "src/components/theme/token-projection-options.ts",
123
+ "type": "registry:ui",
124
+ "target": "components/theming/token-projection-options.ts"
125
+ },
126
+ {
127
+ "path": "src/components/theme/token-projection.ts",
128
+ "type": "registry:ui",
129
+ "target": "components/theming/token-projection.ts"
115
130
  }
116
131
  ]
117
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adea-ai/ui",
3
- "version": "0.151.10",
3
+ "version": "0.151.12",
4
4
  "description": "The Adea design system: Kobalte-backed Solid components, semantic OKLCH tokens, and the app-shell layout primitives shared by Adea and Cortana.",
5
5
  "keywords": [
6
6
  "adea",
@@ -85,6 +85,18 @@
85
85
  "development": "./src/components/theme/script.ts",
86
86
  "import": "./dist/components/theme/script.js"
87
87
  },
88
+ "./components/theme/script-projection": {
89
+ "types": "./dist/components/theme/script-projection.d.ts",
90
+ "solid": "./src/components/theme/script-projection.ts",
91
+ "development": "./src/components/theme/script-projection.ts",
92
+ "import": "./dist/components/theme/script-projection.js"
93
+ },
94
+ "./components/theme/token-projection": {
95
+ "types": "./dist/components/theme/token-projection.d.ts",
96
+ "solid": "./src/components/theme/token-projection.ts",
97
+ "development": "./src/components/theme/token-projection.ts",
98
+ "import": "./dist/components/theme/token-projection.js"
99
+ },
88
100
  "./components/theme/lazy": {
89
101
  "types": "./dist/components/theme/lazy.d.ts",
90
102
  "solid": "./src/components/theme/lazy.ts",
@@ -156,7 +168,7 @@
156
168
  "check:packed-paste-model": "node scripts/check-packed-paste-model.mjs"
157
169
  },
158
170
  "dependencies": {
159
- "@adea-ai/themes": "^0.11.7",
171
+ "@adea-ai/themes": ">0.11.7 <0.12.0",
160
172
  "@corvu/calendar": "^0.1.2",
161
173
  "@corvu/drawer": "^0.2.4",
162
174
  "@corvu/otp-field": "^0.1.4",
package/registry.json CHANGED
@@ -2298,7 +2298,7 @@
2298
2298
  "title": "Appearance Editor",
2299
2299
  "description": "",
2300
2300
  "dependencies": [
2301
- "@adea-ai/themes@^0.11.7",
2301
+ "@adea-ai/themes@>0.11.7 <0.12.0",
2302
2302
  "@kobalte/core@^0.13.14",
2303
2303
  "lucide-solid@^1.65.0"
2304
2304
  ],
@@ -3458,7 +3458,7 @@
3458
3458
  "title": "Theming",
3459
3459
  "description": "",
3460
3460
  "dependencies": [
3461
- "@adea-ai/themes@^0.11.7",
3461
+ "@adea-ai/themes@>0.11.7 <0.12.0",
3462
3462
  "@kobalte/core@^0.13.14",
3463
3463
  "lucide-solid@^1.65.0"
3464
3464
  ],
@@ -3487,6 +3487,11 @@
3487
3487
  "type": "registry:ui",
3488
3488
  "target": "components/theming/lazy.ts"
3489
3489
  },
3490
+ {
3491
+ "path": "src/components/theme/script-projection.ts",
3492
+ "type": "registry:ui",
3493
+ "target": "components/theming/script-projection.ts"
3494
+ },
3490
3495
  {
3491
3496
  "path": "src/components/theme/script.ts",
3492
3497
  "type": "registry:ui",
@@ -3566,6 +3571,16 @@
3566
3571
  "path": "src/components/theme/theme-toggle.tsx",
3567
3572
  "type": "registry:ui",
3568
3573
  "target": "components/theming/theme-toggle.tsx"
3574
+ },
3575
+ {
3576
+ "path": "src/components/theme/token-projection-options.ts",
3577
+ "type": "registry:ui",
3578
+ "target": "components/theming/token-projection-options.ts"
3579
+ },
3580
+ {
3581
+ "path": "src/components/theme/token-projection.ts",
3582
+ "type": "registry:ui",
3583
+ "target": "components/theming/token-projection.ts"
3569
3584
  }
3570
3585
  ]
3571
3586
  },
@@ -3643,7 +3658,7 @@
3643
3658
  "title": "Class-name and token helpers",
3644
3659
  "description": "The private helpers the components import: the class-name merge, the variant recipes, the token manifest and the theme bridge. Installed automatically as a peer of any component that needs it.",
3645
3660
  "dependencies": [
3646
- "@adea-ai/themes@^0.11.7",
3661
+ "@adea-ai/themes@>0.11.7 <0.12.0",
3647
3662
  "class-variance-authority@^0.7.1",
3648
3663
  "cn@^0.5.1"
3649
3664
  ],
@@ -127,11 +127,14 @@ function ThemeSelectMenu(props: {
127
127
  onCleanup(() => {
128
128
  focusLifecycleVersion += 1
129
129
  })
130
- const selected = createMemo(
131
- () =>
132
- props.options.find((option) => option.id === props.selectedId) ??
133
- props.options.find((option) => option.id === props.triggerPreview.id)
134
- )
130
+ const selected = createMemo(() => {
131
+ const options = props.options
132
+ const selectedId = props.selectedId
133
+ const matched = options.find((option) => option.id === selectedId)
134
+ if (matched) return matched
135
+ const previewId = props.triggerPreview.id
136
+ return options.find((option) => option.id === previewId)
137
+ })
135
138
  const selectedName = () => selected()?.name ?? props.triggerPreview.name
136
139
  const closeMenu = () => {
137
140
  if (menuOpen()) focusLifecycleVersion += 1
@@ -418,11 +421,16 @@ export function TerminalRow(props: {
418
421
  preview: theme,
419
422
  })),
420
423
  ])
421
- const selectedOption = () => options().find((option) => option.id === props.selectedId)
422
- const description = () =>
423
- selectedOption() && selectedOption()?.id !== 'theme'
424
- ? `The terminal follows ${selectedOption()?.name}.`
424
+ const selectedOption = createMemo(() => {
425
+ const selectedId = props.selectedId
426
+ return options().find((option) => option.id === selectedId)
427
+ })
428
+ const description = () => {
429
+ const option = selectedOption()
430
+ return option && option.id !== 'theme'
431
+ ? `The terminal follows ${option.name}.`
425
432
  : 'The terminal follows the interface theme.'
433
+ }
426
434
  return (
427
435
  <SettingsRow title="Terminal" icon={<SquareTerminal />} description={description()}>
428
436
  <ThemeSelectMenu
@@ -1,5 +1,13 @@
1
1
  import type { Accessor, JSX } from 'solid-js'
2
- import { Show, createEffect, createSignal, createUniqueId, onCleanup, untrack } from 'solid-js'
2
+ import {
3
+ Show,
4
+ createEffect,
5
+ createMemo,
6
+ createSignal,
7
+ createUniqueId,
8
+ onCleanup,
9
+ untrack,
10
+ } from 'solid-js'
3
11
  import { cn } from '#lib/utils'
4
12
  import {
5
13
  SidebarNav,
@@ -20,6 +28,13 @@ export type ContextualSidebarRenderContext = {
20
28
  portalMount(): HTMLElement | undefined
21
29
  }
22
30
 
31
+ export type ContextualSidebarModeTransition = {
32
+ phase: 'before' | 'after'
33
+ from: 'desktop' | 'mobile'
34
+ to: 'desktop' | 'mobile'
35
+ desktopSidebar: HTMLElement | undefined
36
+ }
37
+
23
38
  export type ContextualSidebarProps = {
24
39
  /** Stable host id prefix; generated when omitted. */
25
40
  id?: string
@@ -42,6 +57,12 @@ export type ContextualSidebarProps = {
42
57
  * hosts can select `desktop` or the shared mobile `Sheet` themselves.
43
58
  */
44
59
  responsiveMode?: 'auto' | 'desktop' | 'mobile'
60
+ /**
61
+ * Coordinate host layout before a runtime mode change and after its DOM settles.
62
+ * A superseded transition or unmounted sidebar does not emit an after phase.
63
+ * Initial mode resolution does not emit either phase.
64
+ */
65
+ onResponsiveModeTransition?(event: ContextualSidebarModeTransition): void
45
66
  /** Current host-owned pixel width, reflected by the resize handle. */
46
67
  width: number
47
68
  minimum: number
@@ -91,6 +112,46 @@ export function ContextualSidebar(props: ContextualSidebarProps) {
91
112
  let mobileLoadPending = false
92
113
  let mobileLoadSettled = false
93
114
  let responsiveModeInitialized = false
115
+ let desktopSidebar: HTMLElement | undefined
116
+ let transitionGeneration = 0
117
+ let pendingMode: boolean | undefined
118
+ let disposed = false
119
+ onCleanup(() => {
120
+ disposed = true
121
+ transitionGeneration += 1
122
+ })
123
+
124
+ const transition = (next: boolean, closeStaleOpen: boolean) => {
125
+ // The host may synchronously update its props from either callback, which
126
+ // re-enters the responsive effect before this transition has finished.
127
+ if (pendingMode === next) return
128
+ const previous = untrack(isMobile)
129
+ const changed = responsiveModeInitialized && previous !== next
130
+ const generation =
131
+ changed || pendingMode !== undefined ? ++transitionGeneration : transitionGeneration
132
+ pendingMode = next
133
+ const event = {
134
+ from: previous ? ('mobile' as const) : ('desktop' as const),
135
+ to: next ? ('mobile' as const) : ('desktop' as const),
136
+ desktopSidebar,
137
+ }
138
+ try {
139
+ if (changed) untrack(() => props.onResponsiveModeTransition?.({ ...event, phase: 'before' }))
140
+ if (disposed || generation !== transitionGeneration) return
141
+ if (closeStaleOpen) untrack(() => props.onOpenChange(false))
142
+ if (disposed || generation !== transitionGeneration) return
143
+ if (next) loadMobile()
144
+ setIsMobile(next)
145
+ if (changed) {
146
+ queueMicrotask(() => {
147
+ if (!disposed && generation === transitionGeneration && untrack(isMobile) === next)
148
+ untrack(() => props.onResponsiveModeTransition?.({ ...event, phase: 'after' }))
149
+ })
150
+ }
151
+ } finally {
152
+ if (generation === transitionGeneration) pendingMode = undefined
153
+ }
154
+ }
94
155
  // Keep the resolved component mounted across viewport changes for Sheet cleanup.
95
156
  const loadMobile = () => {
96
157
  if (mobileLoadPending || mobileLoadSettled) return
@@ -124,8 +185,9 @@ export function ContextualSidebar(props: ContextualSidebarProps) {
124
185
  return mount?.connected && mount.element.isConnected ? mount.element : undefined
125
186
  }
126
187
 
188
+ const responsiveMode = createMemo(() => props.responsiveMode ?? 'auto')
127
189
  createEffect(() => {
128
- const mode = props.responsiveMode ?? 'auto'
190
+ const mode = responsiveMode()
129
191
  const wasMobile = untrack(isMobile)
130
192
  let media: MediaQueryList | undefined
131
193
  let viewportListener: (() => void) | undefined
@@ -137,7 +199,7 @@ export function ContextualSidebar(props: ContextualSidebarProps) {
137
199
  })
138
200
 
139
201
  if (mode === 'desktop') {
140
- setIsMobile(false)
202
+ transition(false, false)
141
203
  } else if (mode === 'mobile') {
142
204
  // An explicit host transition into mobile must not briefly open a Sheet
143
205
  // with stale desktop-expanded state. An initial wide-loaded seed still
@@ -145,35 +207,28 @@ export function ContextualSidebar(props: ContextualSidebarProps) {
145
207
  const shouldCloseStaleOpen = responsiveModeInitialized
146
208
  ? !wasMobile && untrack(() => props.open)
147
209
  : untrack(() => props.wideViewportAtLoad && props.open)
148
- if (shouldCloseStaleOpen) untrack(() => props.onOpenChange(false))
149
- loadMobile()
150
- setIsMobile(true)
210
+ transition(true, Boolean(shouldCloseStaleOpen))
151
211
  } else {
152
212
  const mediaQuery = window.matchMedia('(max-width: 48rem)')
153
213
  media = mediaQuery
154
214
  const updateViewport = () => {
155
215
  const nextIsMobile = mediaQuery.matches
156
216
  const wasNarrow = untrack(isMobile)
157
- if (nextIsMobile) loadMobile()
158
217
  // Close before mounting a modal. A desktop-expanded host state is not
159
218
  // mobile intent, and opening the Sheet for one frame can steal focus.
160
- if (nextIsMobile && !wasNarrow) props.onOpenChange(false)
161
- setIsMobile(nextIsMobile)
219
+ transition(nextIsMobile, nextIsMobile && !wasNarrow)
162
220
  }
163
221
  viewportListener = updateViewport
164
222
 
165
223
  // Preserve a narrow-boot open intent. Initial auto and mobile modes use
166
224
  // the viewport seed to clear stale state; runtime transitions close it.
167
- if (media.matches) {
168
- if (!responsiveModeInitialized && untrack(() => props.wideViewportAtLoad && props.open)) {
169
- untrack(() => props.onOpenChange(false))
170
- } else if (responsiveModeInitialized && !wasMobile) {
171
- untrack(() => props.onOpenChange(false))
172
- }
173
- loadMobile()
174
- }
175
- setIsMobile(mediaQuery.matches)
176
- mediaQuery.addEventListener('change', updateViewport)
225
+ const shouldCloseStaleOpen =
226
+ media.matches &&
227
+ (!responsiveModeInitialized
228
+ ? untrack(() => props.wideViewportAtLoad && props.open)
229
+ : !wasMobile)
230
+ transition(media.matches, Boolean(shouldCloseStaleOpen))
231
+ if (!disposed) mediaQuery.addEventListener('change', updateViewport)
177
232
  }
178
233
 
179
234
  responsiveModeInitialized = true
@@ -189,6 +244,7 @@ export function ContextualSidebar(props: ContextualSidebarProps) {
189
244
 
190
245
  onCleanup(() => {
191
246
  if (mobile && mobileMount()?.element === element) setMobileMount(undefined)
247
+ if (!mobile && desktopSidebar === element) desktopSidebar = undefined
192
248
  element = undefined
193
249
  props.onSidebarElement?.(undefined, mobile)
194
250
  })
@@ -204,6 +260,7 @@ export function ContextualSidebar(props: ContextualSidebarProps) {
204
260
  data-open={mobile ? undefined : String(props.open)}
205
261
  ref={(node) => {
206
262
  element = node
263
+ if (!mobile) desktopSidebar = node
207
264
  if (mobile) {
208
265
  setMobileMount({ element: node, connected: node.isConnected })
209
266
  queueMicrotask(() => {
@@ -2,5 +2,6 @@ export {
2
2
  ContextualSidebar,
3
3
  type ContextualSidebarProps,
4
4
  type ContextualSidebarRenderContext,
5
+ type ContextualSidebarModeTransition,
5
6
  } from './contextual-sidebar'
6
7
  export { PixelResizeHandle, type PixelResizeHandleProps } from '../pixel-resize-handle'
@@ -16,14 +16,15 @@ import { Separator } from '../../ui/separator'
16
16
  *
17
17
  * ## Why the divider tracks the sidebar
18
18
  *
19
- * With the sidebar open the divider lands on the sidebar's trailing edge, so the
20
- * bar reads as the rail and sidebar's header on one side and the content's
21
- * header on the other. The bar spans the rail and the sidebar (they sit under
22
- * it), so the leading half is as wide as `--rail-width` plus the sidebar's width
23
- * less the bar's own start padding. The host publishes the width as
24
- * `--shell-sidebar-width` on an ancestor; the fallback of 17rem matches the
25
- * default sidebar. Below the 48rem breakpoint the sidebar is a drawer and the
26
- * leading half is only as wide as its controls.
19
+ * When the host marks an inline sidebar open, the divider lands on the sidebar's
20
+ * trailing edge, so the bar reads as the rail and sidebar's header on one side
21
+ * and the content's header on the other. The bar spans the rail and the sidebar
22
+ * (they sit under it), so the leading half is as wide as `--rail-width` plus the
23
+ * sidebar's width less the bar's own start padding. The host publishes the width
24
+ * as `--shell-sidebar-width` on an ancestor; the fallback of 17rem matches the
25
+ * default sidebar. The default behavior keeps the leading half with its controls
26
+ * below 48rem. A host that keeps the sidebar inline at narrow widths opts into
27
+ * `alignSidebarAtNarrow` so the divider still tracks it.
27
28
  *
28
29
  * ## Narrow windows
29
30
  *
@@ -48,10 +49,15 @@ export type ShellTopBarProps = Omit<ComponentProps<'header'>, 'children'> & {
48
49
  /** The workspace switcher. */
49
50
  workspace?: JSX.Element
50
51
  /**
51
- * Whether the sidebar is open at wide widths. Open, the divider aligns with
52
- * the sidebar's edge; closed, the leading half hugs its controls.
52
+ * Whether the sidebar is open. Its width applies at wide widths by default.
53
53
  */
54
54
  sidebarOpen?: boolean
55
+ /**
56
+ * Also align the open sidebar below the default 48rem breakpoint. Use this
57
+ * when the host keeps the sidebar inline at narrow widths; drawer layouts keep
58
+ * the default controls-only leading half.
59
+ */
60
+ alignSidebarAtNarrow?: boolean
55
61
  /**
56
62
  * The open sidebar's width in pixels. Published as `--shell-sidebar-width` on
57
63
  * the bar so the divider tracks a resizable sidebar; leave it unset to use an
@@ -81,6 +87,7 @@ export function ShellTopBar(props: ShellTopBarProps) {
81
87
  'sidebarToggle',
82
88
  'workspace',
83
89
  'sidebarOpen',
90
+ 'alignSidebarAtNarrow',
84
91
  'sidebarWidth',
85
92
  'breadcrumb',
86
93
  'search',
@@ -132,11 +139,12 @@ export function ShellTopBar(props: ShellTopBarProps) {
132
139
  data-sidebar-open={local.sidebarOpen ? 'true' : 'false'}
133
140
  class={cn(
134
141
  'window-no-drag flex min-h-[calc(var(--topbar-height)-1px)] max-w-full min-w-0 shrink-0 flex-wrap items-center gap-x-2 gap-y-1 pe-3',
135
- /* Wide and open: span the rail and the sidebar so the divider lands on
136
- the sidebar's edge. The sidebar's own border is the 1px the divider
137
- overlaps, so no extra allowance is needed. */
142
+ /* Open sidebar: preserve wide-only alignment unless the host opts into
143
+ the same geometry below the breakpoint. */
138
144
  local.sidebarOpen &&
139
- 'md:w-[calc(var(--rail-width)+var(--shell-sidebar-width,17rem)-var(--shell-top-bar-inset))]'
145
+ (local.alignSidebarAtNarrow
146
+ ? 'w-[calc(var(--rail-width)+var(--shell-sidebar-width,17rem)-var(--shell-top-bar-inset))]'
147
+ : 'md:w-[calc(var(--rail-width)+var(--shell-sidebar-width,17rem)-var(--shell-top-bar-inset))]')
140
148
  )}
141
149
  >
142
150
  <Show when={navigation()}>