@shellui/core 0.4.1 → 0.5.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +2 -2
  2. package/package.json +15 -3
  3. package/schemas/curated-themes.json +4035 -0
  4. package/schemas/shellui.config.schema.json +961 -0
  5. package/schemas/shellui.theme.schema.json +187 -0
  6. package/src/app.tsx +4 -1
  7. package/src/components/ContentView.tsx +144 -9
  8. package/src/components/LoadingOverlay.tsx +1 -1
  9. package/src/components/ui/alert-dialog.tsx +1 -1
  10. package/src/components/ui/dialog.tsx +23 -5
  11. package/src/components/ui/drawer.tsx +282 -42
  12. package/src/components/ui/dropdown-menu.tsx +7 -2
  13. package/src/components/ui/input.tsx +21 -0
  14. package/src/components/ui/separator.tsx +23 -0
  15. package/src/components/ui/sheet.tsx +220 -0
  16. package/src/components/ui/sidebar.tsx +785 -221
  17. package/src/components/ui/skeleton.tsx +13 -0
  18. package/src/constants/urls.ts +1 -0
  19. package/src/features/admin/utils.ts +2 -45
  20. package/src/features/alertDialog/DialogContext.tsx +1 -1
  21. package/src/features/auth/components/LoginButton.tsx +25 -18
  22. package/src/features/auth/components/LoginPreferencesControls.tsx +124 -0
  23. package/src/features/auth/components/LoginView.tsx +131 -49
  24. package/src/features/config/types.ts +64 -82
  25. package/src/features/drawer/DrawerContext.tsx +55 -19
  26. package/src/features/layouts/AppLayout.tsx +3 -3
  27. package/src/features/layouts/OverlayShell.tsx +376 -77
  28. package/src/features/layouts/appbar/AppBarLayout.tsx +501 -88
  29. package/src/features/layouts/branding/AppBrandIcon.tsx +95 -0
  30. package/src/features/layouts/branding/resolveThemeAsset.spec.ts +33 -0
  31. package/src/features/layouts/branding/resolveThemeAsset.ts +33 -0
  32. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +49 -0
  33. package/src/features/layouts/chrome/ContentDragOverlay.tsx +19 -0
  34. package/src/features/layouts/chrome/DesktopBackButton.tsx +71 -0
  35. package/src/features/layouts/chrome/DesktopChrome.tsx +28 -0
  36. package/src/features/layouts/chrome/DesktopForwardButton.tsx +59 -0
  37. package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +16 -0
  38. package/src/features/layouts/chrome/constants.ts +11 -0
  39. package/src/features/layouts/chrome/goDesktopBack.spec.ts +218 -0
  40. package/src/features/layouts/chrome/goDesktopBack.ts +106 -0
  41. package/src/features/layouts/chrome/index.ts +26 -0
  42. package/src/features/layouts/chrome/runtime.ts +45 -0
  43. package/src/features/layouts/findMatchingNavigationItem.spec.ts +55 -0
  44. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +17 -1
  45. package/src/features/layouts/isFrameForAppUrl.spec.ts +33 -0
  46. package/src/features/layouts/sidebar/NavigationContent.tsx +70 -34
  47. package/src/features/layouts/sidebar/SidebarIcons.tsx +41 -42
  48. package/src/features/layouts/sidebar/SidebarInner.tsx +142 -24
  49. package/src/features/layouts/sidebar/SidebarLayout.tsx +100 -37
  50. package/src/features/layouts/sidebar/sidebarUtils.ts +0 -7
  51. package/src/features/layouts/sidebar/types.ts +3 -3
  52. package/src/features/layouts/utils.ts +73 -5
  53. package/src/features/layouts/windows/WindowsLayout.tsx +173 -61
  54. package/src/features/modal/ModalContext.tsx +21 -8
  55. package/src/features/overlays/OverlayDrawerPendingBar.tsx +26 -0
  56. package/src/features/overlays/OverlayDynamicDemoView.tsx +108 -0
  57. package/src/features/overlays/OverlayPendingSpinner.tsx +18 -0
  58. package/src/features/overlays/ResponsiveModal.tsx +483 -0
  59. package/src/features/overlays/overlaySize.spec.ts +71 -0
  60. package/src/features/overlays/overlaySize.ts +228 -0
  61. package/src/features/overlays/useOverlayReportedSize.ts +130 -0
  62. package/src/features/settings/SettingsProvider.tsx +66 -46
  63. package/src/features/settings/SettingsView.tsx +42 -47
  64. package/src/features/settings/components/Appearance.tsx +305 -55
  65. package/src/features/settings/components/develop/DrawerTestButtons.tsx +18 -0
  66. package/src/features/settings/components/develop/ModalTestButtons.tsx +23 -0
  67. package/src/features/settings/utils/getResolvedAppearanceForSettings.ts +11 -5
  68. package/src/features/theme/applyTheme.ts +143 -0
  69. package/src/features/theme/color.ts +83 -0
  70. package/src/features/theme/curated/amber-minimal.json +86 -0
  71. package/src/features/theme/curated/amethyst-haze.json +86 -0
  72. package/src/features/theme/curated/astro-vista.json +86 -0
  73. package/src/features/theme/curated/bold-tech.json +86 -0
  74. package/src/features/theme/curated/bubblegum.json +86 -0
  75. package/src/features/theme/curated/caffeine.json +83 -0
  76. package/src/features/theme/curated/candyland.json +86 -0
  77. package/src/features/theme/curated/catppuccin.json +86 -0
  78. package/src/features/theme/curated/claude.json +86 -0
  79. package/src/features/theme/curated/claymorphism.json +86 -0
  80. package/src/features/theme/curated/clean-slate.json +86 -0
  81. package/src/features/theme/curated/cosmic-night.json +86 -0
  82. package/src/features/theme/curated/cyberpunk.json +86 -0
  83. package/src/features/theme/curated/darkmatter.json +86 -0
  84. package/src/features/theme/curated/doom-64.json +86 -0
  85. package/src/features/theme/curated/elegant-luxury.json +86 -0
  86. package/src/features/theme/curated/graphite.json +86 -0
  87. package/src/features/theme/curated/index.ts +260 -0
  88. package/src/features/theme/curated/kodama-grove.json +86 -0
  89. package/src/features/theme/curated/light-green.json +87 -0
  90. package/src/features/theme/curated/midnight-bloom.json +86 -0
  91. package/src/features/theme/curated/mocha-mousse.json +86 -0
  92. package/src/features/theme/curated/modern-minimal.json +86 -0
  93. package/src/features/theme/curated/mono.json +84 -0
  94. package/src/features/theme/curated/nature.json +86 -0
  95. package/src/features/theme/curated/neo-brutalism.json +86 -0
  96. package/src/features/theme/curated/northern-lights.json +86 -0
  97. package/src/features/theme/curated/notebook.json +87 -0
  98. package/src/features/theme/curated/ocean-breeze.json +86 -0
  99. package/src/features/theme/curated/pastel-dreams.json +86 -0
  100. package/src/features/theme/curated/perpetuity.json +86 -0
  101. package/src/features/theme/curated/quantum-rose.json +86 -0
  102. package/src/features/theme/curated/retro-arcade.json +86 -0
  103. package/src/features/theme/curated/sage-garden.json +86 -0
  104. package/src/features/theme/curated/shadcn.json +83 -0
  105. package/src/features/theme/curated/shellui.json +82 -0
  106. package/src/features/theme/curated/soft-pop.json +86 -0
  107. package/src/features/theme/curated/solar-dusk.json +86 -0
  108. package/src/features/theme/curated/starry-night.json +86 -0
  109. package/src/features/theme/curated/sunset-horizon.json +86 -0
  110. package/src/features/theme/curated/supabase.json +85 -0
  111. package/src/features/theme/curated/t3-chat.json +83 -0
  112. package/src/features/theme/curated/tangerine.json +86 -0
  113. package/src/features/theme/curated/twitter.json +86 -0
  114. package/src/features/theme/curated/vercel.json +86 -0
  115. package/src/features/theme/curated/vintage-paper.json +86 -0
  116. package/src/features/theme/curated/violet-bloom.json +87 -0
  117. package/src/features/theme/curated/zen-inspired.json +87 -0
  118. package/src/features/theme/index.ts +76 -0
  119. package/src/features/theme/normalize.ts +159 -0
  120. package/src/features/theme/registry.ts +50 -0
  121. package/src/features/theme/resolveConfig.ts +182 -0
  122. package/src/features/theme/safeApplyTheme.ts +147 -0
  123. package/src/features/theme/themes.spec.ts +276 -0
  124. package/src/features/theme/themes.ts +82 -558
  125. package/src/features/theme/tokenKeys.ts +60 -0
  126. package/src/features/theme/types.ts +170 -0
  127. package/src/features/theme/useTheme.tsx +48 -50
  128. package/src/hooks/use-mobile.tsx +19 -0
  129. package/src/i18n/translations/en/common.json +41 -0
  130. package/src/i18n/translations/en/settings.json +10 -2
  131. package/src/i18n/translations/fr/common.json +41 -0
  132. package/src/i18n/translations/fr/settings.json +10 -2
  133. package/src/index.css +372 -128
  134. package/src/index.ts +71 -0
  135. package/src/lib/z-index.ts +4 -1
  136. package/src/routes/components/IndexRoute.tsx +12 -2
  137. package/src/routes/components/NavigationItemRoute.tsx +1 -10
  138. package/src/routes/hooks/useNavigationItems.ts +29 -44
  139. package/src/routes/routes.tsx +58 -27
  140. package/tailwind.config.js +27 -27
  141. package/src/features/layouts/sidebar/BottomNavItem.tsx +0 -88
  142. package/src/features/layouts/sidebar/MobileBottomNav.tsx +0 -168
@@ -0,0 +1,228 @@
1
+ import type { CSSProperties } from 'react';
2
+ import type {
3
+ OverlayOpenOptions,
4
+ OverlaySizePreset,
5
+ OverlaySizeValue,
6
+ DrawerPosition,
7
+ } from '@shellui/sdk';
8
+
9
+ const PRESETS = new Set<string>(['sm', 'md', 'lg', 'xl', 'full', 'content']);
10
+
11
+ /**
12
+ * Compact square while a dynamic modal waits for the first size report.
13
+ */
14
+ export const DYNAMIC_OVERLAY_PENDING_PX = 112;
15
+
16
+ /**
17
+ * Full-bleed loading strip height/width for dynamic drawers while pending.
18
+ * Matches the integrated loading-bar animation.
19
+ */
20
+ export const DYNAMIC_DRAWER_PENDING_PX = 40;
21
+
22
+ /**
23
+ * Hidden iframe layout width while pending so content height is measured at a
24
+ * realistic wrap width (not the spinner square), avoiding tall→short jumps.
25
+ */
26
+ export const DYNAMIC_OVERLAY_MEASURE_WIDTH_PX = 420;
27
+
28
+ export function isOverlaySizePreset(value: unknown): value is OverlaySizePreset {
29
+ return typeof value === 'string' && PRESETS.has(value);
30
+ }
31
+
32
+ export function toCssLength(value: string | number | undefined): string | undefined {
33
+ if (value === undefined || value === null) return undefined;
34
+ if (typeof value === 'number' && Number.isFinite(value)) return `${value}px`;
35
+ const trimmed = String(value).trim();
36
+ return trimmed || undefined;
37
+ }
38
+
39
+ /** Dialog (desktop/tablet modal) preset → class + inline style hints.
40
+ * Width uses `calc(100vw - …)` gutters so tablets never edge-to-edge;
41
+ * `max-w-*` still caps size on large desktops. */
42
+ const DIALOG_PRESET: Record<
43
+ OverlaySizePreset,
44
+ { className: string; style?: CSSProperties; contentSized?: boolean }
45
+ > = {
46
+ sm: {
47
+ className:
48
+ 'max-w-sm w-[min(24rem,calc(100vw-3rem))] h-[min(50dvh,24rem)] max-h-[min(70dvh,28rem)] rounded-lg',
49
+ },
50
+ md: {
51
+ className:
52
+ 'max-w-lg w-[min(32rem,calc(100vw-4rem))] h-[min(60dvh,32rem)] max-h-[min(75dvh,36rem)] rounded-lg',
53
+ },
54
+ lg: {
55
+ // Wider than the 768px mobile breakpoint so iframe apps keep desktop UI
56
+ className:
57
+ 'max-w-4xl w-[min(56rem,calc(100vw-5rem))] h-[min(80dvh,42.5rem)] max-h-[min(80dvh,42.5rem)] rounded-lg',
58
+ },
59
+ xl: {
60
+ className:
61
+ 'max-w-6xl w-[min(72rem,calc(100vw-5rem))] h-[min(85dvh,50rem)] max-h-[min(85dvh,50rem)] rounded-lg',
62
+ },
63
+ full: {
64
+ className:
65
+ 'max-w-[calc(100vw-2.5rem)] w-[calc(100vw-2.5rem)] h-[calc(100dvh-2.5rem)] max-h-[calc(100dvh-2.5rem)] rounded-lg',
66
+ },
67
+ content: {
68
+ // Width comes from SHELLUI_OVERLAY_SIZE; max-w only caps. Avoid forcing 56rem
69
+ // (that caused reflow: narrow measure → tall report → wide chrome → shorter report).
70
+ className: 'max-w-4xl w-max rounded-lg',
71
+ style: { height: 'auto', width: 'auto', maxHeight: 'min(90dvh, 100dvh - 2.5rem)' },
72
+ contentSized: true,
73
+ },
74
+ };
75
+
76
+ /** Drawer primary dimension presets (height for top/bottom, width for left/right). */
77
+ const DRAWER_PRESET_VERTICAL: Record<OverlaySizePreset, string> = {
78
+ sm: '40dvh',
79
+ md: '55dvh',
80
+ lg: '75dvh',
81
+ xl: '90dvh',
82
+ full: '100dvh',
83
+ content: 'auto',
84
+ };
85
+
86
+ const DRAWER_PRESET_HORIZONTAL: Record<OverlaySizePreset, string> = {
87
+ sm: '20rem',
88
+ md: '28rem',
89
+ lg: '36rem',
90
+ xl: '48rem',
91
+ full: '100%',
92
+ content: 'auto',
93
+ };
94
+
95
+ export interface ResolvedOverlaySize {
96
+ className: string;
97
+ style: CSSProperties;
98
+ /** When true, listen for SHELLUI_OVERLAY_SIZE and grow with iframe content. */
99
+ contentSized: boolean;
100
+ /** Primary drawer CSS length (vaul size prop) when applicable. */
101
+ drawerSize: string | null;
102
+ }
103
+
104
+ function applyExplicitDimensions(
105
+ style: CSSProperties,
106
+ options: Pick<OverlayOpenOptions, 'width' | 'height' | 'maxWidth' | 'maxHeight'>,
107
+ ): CSSProperties {
108
+ const next = { ...style };
109
+ const width = toCssLength(options.width);
110
+ const height = toCssLength(options.height);
111
+ const maxWidth = toCssLength(options.maxWidth);
112
+ const maxHeight = toCssLength(options.maxHeight);
113
+ if (width) next.width = width;
114
+ if (height) next.height = height;
115
+ if (maxWidth) next.maxWidth = `min(${maxWidth}, 100vw)`;
116
+ if (maxHeight) next.maxHeight = `min(${maxHeight}, 100dvh)`;
117
+ return next;
118
+ }
119
+
120
+ export function isDynamicSizing(options?: OverlayOpenOptions | null): boolean {
121
+ return options?.dynamicSizing === true || options?.size === 'content';
122
+ }
123
+
124
+ /**
125
+ * Resolve modal (dialog) sizing from open options.
126
+ * Default preset: `lg` (matches previous fixed chrome).
127
+ */
128
+ export function resolveDialogSize(options?: OverlayOpenOptions | null): ResolvedOverlaySize {
129
+ const dynamic = isDynamicSizing(options);
130
+ const size = dynamic ? 'content' : options?.size;
131
+ const preset: OverlaySizePreset = size && isOverlaySizePreset(size) ? size : 'lg';
132
+ // Freeform CSS size on modal maps to height when not a preset
133
+ const freeform = !dynamic && size && !isOverlaySizePreset(size) ? toCssLength(size) : undefined;
134
+
135
+ const base = DIALOG_PRESET[preset];
136
+ let style: CSSProperties = {
137
+ transition: dynamic ? 'none' : 'height 200ms ease, width 200ms ease, max-height 200ms ease',
138
+ ...base.style,
139
+ };
140
+ if (freeform) {
141
+ style.height = freeform;
142
+ style.maxHeight = `min(${freeform}, 100dvh)`;
143
+ }
144
+ style = applyExplicitDimensions(style, options ?? {});
145
+
146
+ return {
147
+ className: `${base.className} flex flex-col p-0 overflow-hidden`,
148
+ style,
149
+ contentSized: dynamic || base.contentSized === true || preset === 'content',
150
+ drawerSize: null,
151
+ };
152
+ }
153
+
154
+ /**
155
+ * Resolve drawer sizing from open options + direction.
156
+ * Default: 80dvh / 80vw (previous behavior).
157
+ */
158
+ export function resolveDrawerSize(
159
+ options?: OverlayOpenOptions | null,
160
+ position: DrawerPosition = 'right',
161
+ ): ResolvedOverlaySize {
162
+ const isVertical = position === 'top' || position === 'bottom';
163
+ const dynamic = isDynamicSizing(options);
164
+ const size = (dynamic ? 'content' : options?.size) as OverlaySizeValue | undefined;
165
+ const contentSized = dynamic || size === 'content';
166
+
167
+ let drawerSize: string;
168
+ if (!size) {
169
+ drawerSize = isVertical ? '80dvh' : '80vw';
170
+ } else if (isOverlaySizePreset(size)) {
171
+ drawerSize = isVertical ? DRAWER_PRESET_VERTICAL[size] : DRAWER_PRESET_HORIZONTAL[size];
172
+ } else {
173
+ drawerSize = toCssLength(size) ?? (isVertical ? '80dvh' : '80vw');
174
+ }
175
+
176
+ let style: CSSProperties = {
177
+ transition: contentSized
178
+ ? 'none'
179
+ : 'height 200ms ease, width 200ms ease, max-height 200ms ease, max-width 200ms ease',
180
+ };
181
+ style = applyExplicitDimensions(style, options ?? {});
182
+
183
+ // Explicit width/height override the primary drawer dimension
184
+ if (isVertical && style.height) {
185
+ drawerSize = String(style.height);
186
+ } else if (!isVertical && style.width) {
187
+ drawerSize = String(style.width);
188
+ }
189
+
190
+ if (contentSized) {
191
+ drawerSize = 'auto';
192
+ if (isVertical) {
193
+ style.maxHeight = style.maxHeight ?? 'min(90dvh, 100dvh)';
194
+ style.height = style.height ?? 'auto';
195
+ } else {
196
+ style.maxWidth = style.maxWidth ?? 'min(90vw, 100%)';
197
+ style.width = style.width ?? 'auto';
198
+ }
199
+ }
200
+
201
+ return {
202
+ className: 'p-0 overflow-hidden flex flex-col',
203
+ style,
204
+ contentSized,
205
+ drawerSize: drawerSize === 'auto' ? null : drawerSize,
206
+ };
207
+ }
208
+
209
+ export type OverlayDismissOptions = {
210
+ showCloseButton: boolean;
211
+ dismissible: boolean;
212
+ closeOnOverlayClick: boolean;
213
+ showDragHandle: boolean;
214
+ };
215
+
216
+ export function resolveDismissOptions(
217
+ options?: (OverlayOpenOptions & { showDragHandle?: boolean }) | null,
218
+ ): OverlayDismissOptions {
219
+ const dismissible = options?.dismissible !== false;
220
+ const showDragHandle =
221
+ options?.showDragHandle !== undefined ? options.showDragHandle : dismissible;
222
+ return {
223
+ showCloseButton: options?.showCloseButton !== false,
224
+ dismissible,
225
+ closeOnOverlayClick: options?.closeOnOverlayClick !== false,
226
+ showDragHandle,
227
+ };
228
+ }
@@ -0,0 +1,130 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { shellui, type OverlaySizePayload, type ShellUIMessage } from '@shellui/sdk';
3
+
4
+ const MIN_CONTENT_HEIGHT = 40;
5
+ const MAX_VIEWPORT_RATIO = 0.92;
6
+ /** If no size messages arrive, fall back to a scrollable preset height. */
7
+ const FALLBACK_MS = 1500;
8
+ const FALLBACK_HEIGHT_RATIO = 0.6;
9
+ /** Keep last size through overlay close animation, then clear. */
10
+ const CLOSE_SIZE_CLEAR_MS = 280;
11
+
12
+ export type ReportedOverlaySize = {
13
+ height: number;
14
+ width?: number;
15
+ /** True when the raw content height exceeded the viewport max and was clamped. */
16
+ wasClamped?: boolean;
17
+ };
18
+
19
+ /**
20
+ * Listen for `SHELLUI_OVERLAY_SIZE` from iframe content and expose clamped dimensions.
21
+ * Applies immediately (no debounce). Ignores invalid / no-op values.
22
+ * When `enabled` is false (non-content presets), reported size stays null (preset + inner scroll).
23
+ * If no messages arrive within FALLBACK_MS, returns a viewport-relative fallback height
24
+ * so the overlay remains usable with inner scroll.
25
+ *
26
+ * On close: last size is kept for CLOSE_SIZE_CLEAR_MS so exit animation does not
27
+ * shrink back to the pending spinner. On open: size resets immediately (pending again).
28
+ */
29
+ export function useOverlayReportedSize(enabled: boolean, active: boolean) {
30
+ const [reported, setReported] = useState<ReportedOverlaySize | null>(null);
31
+ const [fallback, setFallback] = useState(false);
32
+ const lastRef = useRef<ReportedOverlaySize | null>(null);
33
+ const fallbackTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
34
+
35
+ const reset = useCallback(() => {
36
+ lastRef.current = null;
37
+ setReported(null);
38
+ setFallback(false);
39
+ if (fallbackTimerRef.current) {
40
+ clearTimeout(fallbackTimerRef.current);
41
+ fallbackTimerRef.current = null;
42
+ }
43
+ }, []);
44
+
45
+ useEffect(() => {
46
+ if (active) {
47
+ // Fresh open — clear so pending spinner shows until the first report
48
+ reset();
49
+ return;
50
+ }
51
+ // Keep last size through the close animation, then clear for next open
52
+ const t = window.setTimeout(reset, CLOSE_SIZE_CLEAR_MS);
53
+ return () => window.clearTimeout(t);
54
+ }, [active, reset]);
55
+
56
+ useEffect(() => {
57
+ if (!enabled || !active) return;
58
+
59
+ fallbackTimerRef.current = setTimeout(() => {
60
+ if (!lastRef.current) {
61
+ setFallback(true);
62
+ }
63
+ }, FALLBACK_MS);
64
+
65
+ const apply = (payload: OverlaySizePayload) => {
66
+ const height = Number(payload?.height);
67
+ if (!Number.isFinite(height) || height <= 0) return;
68
+
69
+ const maxH = Math.floor(window.innerHeight * MAX_VIEWPORT_RATIO);
70
+ const rawH = Math.ceil(height);
71
+ const clampedH = Math.min(Math.max(rawH, MIN_CONTENT_HEIGHT), maxH);
72
+ const wasClamped = rawH > maxH;
73
+
74
+ let clampedW: number | undefined;
75
+ if (payload.width !== undefined) {
76
+ const width = Number(payload.width);
77
+ if (Number.isFinite(width) && width > 0) {
78
+ const maxW = Math.floor(window.innerWidth * MAX_VIEWPORT_RATIO);
79
+ clampedW = Math.min(Math.ceil(width), maxW);
80
+ }
81
+ }
82
+
83
+ const prev = lastRef.current;
84
+ if (
85
+ prev &&
86
+ Math.abs(prev.height - clampedH) < 1 &&
87
+ prev.wasClamped === wasClamped &&
88
+ (clampedW === undefined ||
89
+ prev.width === undefined ||
90
+ Math.abs((prev.width ?? 0) - clampedW) < 1)
91
+ ) {
92
+ return;
93
+ }
94
+
95
+ const next = { height: clampedH, width: clampedW, wasClamped };
96
+ lastRef.current = next;
97
+ setFallback(false);
98
+ setReported(next);
99
+ };
100
+
101
+ const cleanup = shellui.addMessageListener('SHELLUI_OVERLAY_SIZE', (data: ShellUIMessage) => {
102
+ const payload = data.payload as OverlaySizePayload;
103
+ if (payload?.version !== undefined && payload.version !== 1) return;
104
+ apply(payload);
105
+ });
106
+
107
+ return () => {
108
+ cleanup();
109
+ if (fallbackTimerRef.current) clearTimeout(fallbackTimerRef.current);
110
+ };
111
+ }, [enabled, active]);
112
+
113
+ const effectiveReported =
114
+ reported ??
115
+ (fallback && enabled
116
+ ? {
117
+ height: Math.floor(
118
+ (typeof window !== 'undefined' ? window.innerHeight : 600) * FALLBACK_HEIGHT_RATIO,
119
+ ),
120
+ wasClamped: true,
121
+ }
122
+ : null);
123
+
124
+ return {
125
+ reported: effectiveReported,
126
+ usedFallback: fallback && !reported,
127
+ wasClamped: Boolean(effectiveReported?.wasClamped),
128
+ reset,
129
+ };
130
+ }
@@ -11,6 +11,7 @@ import { useConfig } from '../config/useConfig';
11
11
  import type { NavigationItem } from '../config/types';
12
12
  import { useAuth } from '../auth/hooks/useAuth';
13
13
  import { isAdminFrame } from '../admin/utils';
14
+ import { isFrameForAppUrl } from '../layouts/utils';
14
15
  import { defaultTheme } from '../theme/themes';
15
16
  import {
16
17
  buildSettingsForPropagation,
@@ -28,49 +29,8 @@ const STORAGE_KEY = 'shellui:settings';
28
29
  const AUTH_SESSION_STORAGE_KEY = 'shellui.auth.session';
29
30
  const AUTH_LAST_USED_LOGIN_STORAGE_KEY = 'shellui.auth.last_used_login';
30
31
 
31
- const toAbsoluteUrl = (url: string): URL | null => {
32
- try {
33
- return new URL(
34
- url,
35
- typeof window !== 'undefined' ? window.location.origin : 'http://localhost',
36
- );
37
- } catch {
38
- return null;
39
- }
40
- };
41
-
42
- const normalizePath = (value: string): string => {
43
- const trimmed = value.trim();
44
- if (!trimmed) return '/';
45
- const withoutTrailing = trimmed.replace(/\/+$/, '');
46
- return withoutTrailing || '/';
47
- };
48
-
49
- const normalizeHashPath = (value: string): string => {
50
- const hash = value.replace(/^#\/?/, '').replace(/\/+$/, '');
51
- return hash;
52
- };
53
-
54
- const isFrameForNavigationItem = (frameSrc: string, itemUrl: string): boolean => {
55
- const frame = toAbsoluteUrl(frameSrc);
56
- const item = toAbsoluteUrl(itemUrl);
57
- if (!frame || !item) return false;
58
- if (frame.origin !== item.origin) return false;
59
-
60
- const itemPathname = normalizePath(item.pathname);
61
- const framePathname = normalizePath(frame.pathname);
62
- if (framePathname !== itemPathname && !framePathname.startsWith(`${itemPathname}/`)) {
63
- return false;
64
- }
65
-
66
- const itemHashPath = normalizeHashPath(item.hash);
67
- if (!itemHashPath) {
68
- return true;
69
- }
70
-
71
- const frameHashPath = normalizeHashPath(frame.hash);
72
- return frameHashPath === itemHashPath || frameHashPath.startsWith(`${itemHashPath}/`);
73
- };
32
+ const isFrameForNavigationItem = (frameSrc: string, itemUrl: string): boolean =>
33
+ isFrameForAppUrl(frameSrc, itemUrl);
74
34
 
75
35
  const stripSensitiveUserFields = (settings: Settings): Settings => {
76
36
  return {
@@ -124,6 +84,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
124
84
  const { user: authUser, session, syncUserPreferences, loadUserPreferences, logout } = useAuth();
125
85
  const lastSyncedPreferencesRef = useRef<string | null>(null);
126
86
  const loadingPreferencesRef = useRef(false);
87
+ const settingsHydratedFromStorageRef = useRef(false);
127
88
  // Use a ref to always have current settings for message listeners (avoids closure issues)
128
89
  const settingsRef = useRef<Settings | null>(null);
129
90
  const [settings, setSettings] = useState<Settings>(() => {
@@ -132,6 +93,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
132
93
  if (shellui.initialSettings) {
133
94
  initialSettings = shellui.initialSettings;
134
95
  settingsRef.current = initialSettings;
96
+ settingsHydratedFromStorageRef.current = true;
135
97
  return initialSettings;
136
98
  }
137
99
 
@@ -140,6 +102,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
140
102
  try {
141
103
  const stored = localStorage.getItem(STORAGE_KEY);
142
104
  if (stored) {
105
+ settingsHydratedFromStorageRef.current = true;
143
106
  const parsed = JSON.parse(stored);
144
107
  // Deep merge with defaults to handle new settings
145
108
  initialSettings = {
@@ -303,6 +266,25 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
303
266
  const propagateSettingsToIframesRef = useRef(propagateSettingsToIframes);
304
267
  propagateSettingsToIframesRef.current = propagateSettingsToIframes;
305
268
 
269
+ // Trailing-debounce iframe settings pushes during rapid theme spam so
270
+ // children only apply the final theme after switching settles.
271
+ const pendingIframeSettingsRef = useRef<Settings | null>(null);
272
+ const iframePropagateTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
273
+ const schedulePropagateSettingsToIframes = useCallback((next: Settings) => {
274
+ pendingIframeSettingsRef.current = next;
275
+ if (iframePropagateTimerRef.current !== null) {
276
+ clearTimeout(iframePropagateTimerRef.current);
277
+ }
278
+ iframePropagateTimerRef.current = setTimeout(() => {
279
+ iframePropagateTimerRef.current = null;
280
+ const pending = pendingIframeSettingsRef.current;
281
+ pendingIframeSettingsRef.current = null;
282
+ if (pending) {
283
+ propagateSettingsToIframesRef.current(pending);
284
+ }
285
+ }, 100);
286
+ }, []);
287
+
306
288
  // Keep ref in sync with state for message listeners
307
289
  useEffect(() => {
308
290
  settingsRef.current = settings;
@@ -541,6 +523,44 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
541
523
  };
542
524
  }, [config, isTrustedFrameForAuthToken, propagateSettingsToIframes, pushSettingsToFrame]);
543
525
 
526
+ // Apply config activeTheme / defaultTheme on first visit (no localStorage preference yet)
527
+ useEffect(() => {
528
+ if (settingsHydratedFromStorageRef.current) return;
529
+ const desired = config?.activeTheme || config?.defaultTheme;
530
+ if (!desired) return;
531
+ setSettings((prev) => {
532
+ if (prev.appearance?.name === desired) return prev;
533
+ const themeFromConfig = Array.isArray(config?.themes)
534
+ ? config.themes.find(
535
+ (t) =>
536
+ t && typeof t === 'object' && 'name' in t && (t as { name: string }).name === desired,
537
+ )
538
+ : undefined;
539
+ const typed =
540
+ themeFromConfig && typeof themeFromConfig === 'object' && 'displayName' in themeFromConfig
541
+ ? (themeFromConfig as {
542
+ displayName: string;
543
+ colors: Appearance['colors'];
544
+ })
545
+ : undefined;
546
+ const next: Settings = {
547
+ ...prev,
548
+ appearance: {
549
+ ...prev.appearance,
550
+ name: desired,
551
+ ...(typed
552
+ ? {
553
+ displayName: typed.displayName,
554
+ colors: typed.colors,
555
+ }
556
+ : {}),
557
+ },
558
+ };
559
+ settingsRef.current = next;
560
+ return next;
561
+ });
562
+ }, [config?.activeTheme, config?.defaultTheme, config?.themes]);
563
+
544
564
  useEffect(() => {
545
565
  if (
546
566
  typeof window === 'undefined' ||
@@ -587,8 +607,8 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
587
607
  localStorage.setItem(STORAGE_KEY, JSON.stringify(newSettings));
588
608
  settingsRef.current = newSettings;
589
609
  setSettings(newSettings);
590
- // Propagate to child iframes (sendMessageToParent does nothing in root)
591
- propagateSettingsToIframes(newSettings);
610
+ // Trailing coalesce: spam theme switches only push the latest to iframes
611
+ schedulePropagateSettingsToIframes(newSettings);
592
612
  } catch (error) {
593
613
  logger.error('Failed to update settings in localStorage:', { error });
594
614
  }
@@ -604,7 +624,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
604
624
  payload: { settings: stripSensitiveUserFields(nextSettings) },
605
625
  });
606
626
  },
607
- [settings, propagateSettingsToIframes],
627
+ [settings, schedulePropagateSettingsToIframes],
608
628
  );
609
629
 
610
630
  const updateSetting = useCallback(
@@ -15,6 +15,7 @@ import {
15
15
  SidebarMenu,
16
16
  SidebarMenuButton,
17
17
  SidebarMenuItem,
18
+ SidebarProvider,
18
19
  } from '../../components/ui/sidebar';
19
20
  import { Route, Routes, useLocation, useNavigate, Navigate } from 'react-router';
20
21
  import { useTranslation } from 'react-i18next';
@@ -25,6 +26,7 @@ import { useConfig } from '../config/useConfig';
25
26
  import { isTauri } from '../../service-worker/register';
26
27
  import { Button } from '../../components/ui/button';
27
28
  import { ChevronRightIcon, ChevronLeftIcon } from './SettingsIcons';
29
+ import { NavIcon } from '../layouts/sidebar/SidebarIcons';
28
30
  import { flattenNavigationItems, resolveLocalizedString } from '../layouts/utils';
29
31
  import { ApplicationSettingsPanel } from './components/ApplicationSettingsPanel';
30
32
  import { createUserSettingsRoute } from './components/createUserSettingsRoute';
@@ -229,46 +231,45 @@ export const SettingsView = () => {
229
231
 
230
232
  return (
231
233
  <div className="flex h-full w-full overflow-hidden items-start">
232
- {/* Desktop Sidebar */}
233
- <Sidebar className="hidden md:flex">
234
- <SidebarContent>
235
- {groupedRoutes.map((group) => (
236
- <SidebarGroup key={group.title}>
237
- <SidebarGroupLabel>{group.title}</SidebarGroupLabel>
238
- <SidebarGroupContent>
239
- <SidebarMenu>
240
- {group.routes.map((item) => (
241
- <SidebarMenuItem key={item.name}>
242
- <SidebarMenuButton
243
- asChild
244
- isActive={item.name === selectedItem?.name}
245
- >
246
- <button
247
- onClick={() => navigate(`${urls.settings}/${item.path}`)}
248
- className="cursor-pointer"
234
+ {/* Desktop settings nav — local provider so this works outside the shell sidebar layout */}
235
+ <SidebarProvider className="hidden h-full min-h-0 w-auto shrink-0 md:flex">
236
+ <Sidebar
237
+ collapsible="none"
238
+ className="flex h-full border-r border-sidebar-border"
239
+ >
240
+ <SidebarContent>
241
+ {groupedRoutes.map((group) => (
242
+ <SidebarGroup key={group.title}>
243
+ <SidebarGroupLabel>{group.title}</SidebarGroupLabel>
244
+ <SidebarGroupContent>
245
+ <SidebarMenu>
246
+ {group.routes.map((item) => (
247
+ <SidebarMenuItem key={item.name}>
248
+ <SidebarMenuButton
249
+ asChild
250
+ isActive={item.name === selectedItem?.name}
249
251
  >
250
- {'icon' in item && item.icon ? (
251
- <item.icon />
252
- ) : 'iconSrc' in item && item.iconSrc ? (
253
- <img
254
- src={item.iconSrc}
255
- alt=""
256
- className="h-4 w-4 shrink-0"
257
- />
258
- ) : (
259
- <span className="h-4 w-4 shrink-0" />
260
- )}
261
- <span>{item.name}</span>
262
- </button>
263
- </SidebarMenuButton>
264
- </SidebarMenuItem>
265
- ))}
266
- </SidebarMenu>
267
- </SidebarGroupContent>
268
- </SidebarGroup>
269
- ))}
270
- </SidebarContent>
271
- </Sidebar>
252
+ <button
253
+ onClick={() => navigate(`${urls.settings}/${item.path}`)}
254
+ className="cursor-pointer"
255
+ >
256
+ {'icon' in item && item.icon ? (
257
+ <item.icon />
258
+ ) : (
259
+ <NavIcon src={'iconSrc' in item ? item.iconSrc : null} />
260
+ )}
261
+ <span>{item.name}</span>
262
+ </button>
263
+ </SidebarMenuButton>
264
+ </SidebarMenuItem>
265
+ ))}
266
+ </SidebarMenu>
267
+ </SidebarGroupContent>
268
+ </SidebarGroup>
269
+ ))}
270
+ </SidebarContent>
271
+ </Sidebar>
272
+ </SidebarProvider>
272
273
 
273
274
  {/* Mobile List View */}
274
275
  <div className="md:hidden flex h-full w-full flex-col overflow-hidden">
@@ -296,14 +297,8 @@ export const SettingsView = () => {
296
297
  const iconEl =
297
298
  'icon' in item && item.icon ? (
298
299
  <item.icon />
299
- ) : 'iconSrc' in item && item.iconSrc ? (
300
- <img
301
- src={item.iconSrc}
302
- alt=""
303
- className="h-4 w-4 shrink-0"
304
- />
305
300
  ) : (
306
- <span className="h-4 w-4 shrink-0" />
301
+ <NavIcon src={'iconSrc' in item ? item.iconSrc : null} />
307
302
  );
308
303
  return (
309
304
  <div
@@ -318,7 +313,7 @@ export const SettingsView = () => {
318
313
  className="w-full flex items-center justify-between px-4 py-3 bg-transparent hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground transition-colors cursor-pointer rounded-none"
319
314
  >
320
315
  <div className="flex items-center gap-2 flex-1 min-w-0">
321
- <div className="flex-shrink-0 text-foreground/70">{iconEl}</div>
316
+ <div className="flex-shrink-0">{iconEl}</div>
322
317
  <span className="text-sm font-normal text-foreground">
323
318
  {item.name}
324
319
  </span>