@shellui/core 0.5.0-beta.1 → 0.5.0-beta.3

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 (47) hide show
  1. package/package.json +2 -2
  2. package/schemas/shellui.config.schema.json +10 -2
  3. package/src/components/ContentView.tsx +12 -5
  4. package/src/components/ui/alert-dialog.tsx +1 -1
  5. package/src/components/ui/sidebar.tsx +60 -21
  6. package/src/features/admin/AdminView.tsx +31 -2
  7. package/src/features/auth/components/LoginButton.tsx +3 -3
  8. package/src/features/auth/components/LoginView.tsx +74 -28
  9. package/src/features/config/types.ts +16 -2
  10. package/src/features/layouts/AppLayout.tsx +30 -3
  11. package/src/features/layouts/OverlayShell.tsx +3 -1
  12. package/src/features/layouts/app-bar-inset/AppBarInsetLayout.tsx +22 -0
  13. package/src/features/layouts/appbar/AppBarLayout.tsx +98 -33
  14. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +18 -10
  15. package/src/features/layouts/chrome/ContentDragOverlay.tsx +1 -1
  16. package/src/features/layouts/chrome/DesktopChrome.tsx +1 -1
  17. package/src/features/layouts/chrome/SafeAreaTopbar.tsx +48 -0
  18. package/src/features/layouts/chrome/constants.ts +7 -1
  19. package/src/features/layouts/chrome/index.ts +5 -0
  20. package/src/features/layouts/chrome/runtime.ts +157 -7
  21. package/src/features/layouts/floating/FloatingFadeMask.tsx +22 -0
  22. package/src/features/layouts/floating/FloatingLayout.tsx +142 -0
  23. package/src/features/layouts/floating/FloatingSidebar.tsx +327 -0
  24. package/src/features/layouts/floating/FloatingTabBar.tsx +437 -0
  25. package/src/features/layouts/floating/FloatingTabIndicator.tsx +216 -0
  26. package/src/features/layouts/floating/computeFloatingInsets.spec.ts +83 -0
  27. package/src/features/layouts/floating/computeFloatingInsets.ts +103 -0
  28. package/src/features/layouts/floating/isShellOwnedPath.spec.ts +23 -0
  29. package/src/features/layouts/floating/isShellOwnedPath.ts +16 -0
  30. package/src/features/layouts/floating/layoutChromeStore.ts +46 -0
  31. package/src/features/layouts/floating/scrollChrome.spec.ts +49 -0
  32. package/src/features/layouts/floating/useFloatingChrome.ts +216 -0
  33. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +9 -4
  34. package/src/features/layouts/sidebar/SidebarInner.tsx +25 -29
  35. package/src/features/layouts/sidebar/SidebarLayout.tsx +41 -36
  36. package/src/features/layouts/sidebar/types.ts +4 -0
  37. package/src/features/layouts/sidebar-inset/SidebarInsetLayout.tsx +15 -0
  38. package/src/features/settings/SettingsProvider.tsx +7 -0
  39. package/src/features/settings/SettingsView.tsx +6 -6
  40. package/src/features/settings/components/Develop.tsx +31 -13
  41. package/src/features/settings/utils/buildSettingsForPropagation.ts +16 -0
  42. package/src/features/storage/StoragePickerContext.tsx +1 -0
  43. package/src/hooks/use-viewport.ts +40 -0
  44. package/src/i18n/translations/en/settings.json +8 -2
  45. package/src/i18n/translations/fr/settings.json +8 -2
  46. package/src/index.css +339 -15
  47. package/src/routes/components/RouteFallback.tsx +6 -2
@@ -0,0 +1,83 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ computeFloatingInsets,
4
+ FLOATING_CHROME_MARGIN,
5
+ FLOATING_COLLAPSED_TOP_INSET,
6
+ FLOATING_CONTENT_CLEARANCE,
7
+ FLOATING_SIDEBAR_WIDTH,
8
+ FLOATING_TAB_BAR_HEIGHT,
9
+ } from './computeFloatingInsets';
10
+
11
+ describe('computeFloatingInsets', () => {
12
+ const safe = { top: 10, right: 2, bottom: 20, left: 3 };
13
+
14
+ it('returns safe area only when chrome is hidden', () => {
15
+ expect(
16
+ computeFloatingInsets({ viewport: 'mobile', chromeVisible: false, safeArea: safe }),
17
+ ).toEqual(safe);
18
+ expect(
19
+ computeFloatingInsets({ viewport: 'tablet', chromeVisible: false, safeArea: safe }),
20
+ ).toEqual(safe);
21
+ expect(
22
+ computeFloatingInsets({ viewport: 'desktop', chromeVisible: false, safeArea: safe }),
23
+ ).toEqual(safe);
24
+ });
25
+
26
+ it('adds bottom tab bar on mobile when visible (half bottom pad)', () => {
27
+ expect(
28
+ computeFloatingInsets({ viewport: 'mobile', chromeVisible: true, safeArea: safe }),
29
+ ).toEqual({
30
+ top: 10,
31
+ right: 2,
32
+ bottom:
33
+ (20 + FLOATING_CHROME_MARGIN) / 2 +
34
+ FLOATING_TAB_BAR_HEIGHT +
35
+ FLOATING_CHROME_MARGIN +
36
+ FLOATING_CONTENT_CLEARANCE,
37
+ left: 3,
38
+ });
39
+ });
40
+
41
+ it('adds bottom tab bar on tablet when visible (full bottom pad)', () => {
42
+ expect(
43
+ computeFloatingInsets({ viewport: 'tablet', chromeVisible: true, safeArea: safe }),
44
+ ).toEqual({
45
+ top: 10,
46
+ right: 2,
47
+ bottom:
48
+ 20 +
49
+ FLOATING_CHROME_MARGIN +
50
+ FLOATING_TAB_BAR_HEIGHT +
51
+ FLOATING_CHROME_MARGIN +
52
+ FLOATING_CONTENT_CLEARANCE,
53
+ left: 3,
54
+ });
55
+ });
56
+
57
+ it('adds left sidebar on desktop when visible', () => {
58
+ expect(
59
+ computeFloatingInsets({ viewport: 'desktop', chromeVisible: true, safeArea: safe }),
60
+ ).toEqual({
61
+ top: 10,
62
+ right: 2,
63
+ bottom: 20,
64
+ left: 3 + FLOATING_SIDEBAR_WIDTH + FLOATING_CHROME_MARGIN * 2 + FLOATING_CONTENT_CLEARANCE,
65
+ });
66
+ });
67
+
68
+ it('drops left sidebar inset when desktop sidebar is collapsed', () => {
69
+ expect(
70
+ computeFloatingInsets({
71
+ viewport: 'desktop',
72
+ chromeVisible: true,
73
+ sidebarCollapsed: true,
74
+ safeArea: safe,
75
+ }),
76
+ ).toEqual({
77
+ top: 10 + FLOATING_COLLAPSED_TOP_INSET,
78
+ right: 2,
79
+ bottom: 20,
80
+ left: 3,
81
+ });
82
+ });
83
+ });
@@ -0,0 +1,103 @@
1
+ import type { LayoutChromeInsets, LayoutChromeViewport } from '@shellui/sdk';
2
+
3
+ /** Floating tab bar content height (icon + label). */
4
+ export const FLOATING_TAB_BAR_HEIGHT = 64;
5
+ /** Gap between floating chrome and screen edge. */
6
+ export const FLOATING_CHROME_MARGIN = 12;
7
+ /** Extra clearance so the last content row clears the floating chrome comfortably. */
8
+ export const FLOATING_CONTENT_CLEARANCE = 12;
9
+ /** Desktop floating sidebar width. */
10
+ export const FLOATING_SIDEBAR_WIDTH = 240;
11
+ /**
12
+ * Max visible slots in the floating tab bar (primary tabs + optional More).
13
+ * Matches a compact pill tab bar (e.g. 4 icons, or 3 + More).
14
+ */
15
+ export const FLOATING_MAX_TAB_SLOTS = 4;
16
+
17
+ /**
18
+ * Padding under the floating tab bar (chrome margin + safe-area).
19
+ * Phone uses half so the bar sits lower on iPhone home-indicator devices.
20
+ */
21
+ export function floatingTabBarBottomPadPx(
22
+ safeBottom: number,
23
+ viewport: LayoutChromeViewport,
24
+ ): number {
25
+ const full = FLOATING_CHROME_MARGIN + safeBottom;
26
+ return viewport === 'mobile' ? full / 2 : full;
27
+ }
28
+ /** Collapsed desktop toggle control size (glass chip). */
29
+ export const FLOATING_SIDEBAR_TOGGLE_SIZE = 36;
30
+ /**
31
+ * Top inset when the desktop sidebar is collapsed — clears the floating
32
+ * expand chip so content does not sit under it.
33
+ */
34
+ export const FLOATING_COLLAPSED_TOP_INSET =
35
+ FLOATING_CHROME_MARGIN + FLOATING_SIDEBAR_TOGGLE_SIZE + FLOATING_CONTENT_CLEARANCE;
36
+
37
+ export type FloatingSafeArea = LayoutChromeInsets;
38
+
39
+ export function computeFloatingInsets(options: {
40
+ viewport: LayoutChromeViewport;
41
+ chromeVisible: boolean;
42
+ /** Desktop only: sidebar fully hidden; left inset drops to safe-area. */
43
+ sidebarCollapsed?: boolean;
44
+ safeArea?: Partial<FloatingSafeArea>;
45
+ }): LayoutChromeInsets {
46
+ const safe: FloatingSafeArea = {
47
+ top: options.safeArea?.top ?? 0,
48
+ right: options.safeArea?.right ?? 0,
49
+ bottom: options.safeArea?.bottom ?? 0,
50
+ left: options.safeArea?.left ?? 0,
51
+ };
52
+
53
+ if (!options.chromeVisible) {
54
+ return { ...safe };
55
+ }
56
+
57
+ const { viewport } = options;
58
+ if (viewport === 'mobile' || viewport === 'tablet') {
59
+ return {
60
+ top: safe.top,
61
+ right: safe.right,
62
+ bottom:
63
+ floatingTabBarBottomPadPx(safe.bottom, viewport) +
64
+ FLOATING_TAB_BAR_HEIGHT +
65
+ FLOATING_CHROME_MARGIN +
66
+ FLOATING_CONTENT_CLEARANCE,
67
+ left: safe.left,
68
+ };
69
+ }
70
+
71
+ if (options.sidebarCollapsed) {
72
+ return {
73
+ top: safe.top + FLOATING_COLLAPSED_TOP_INSET,
74
+ right: safe.right,
75
+ bottom: safe.bottom,
76
+ left: safe.left,
77
+ };
78
+ }
79
+
80
+ return {
81
+ top: safe.top,
82
+ right: safe.right,
83
+ bottom: safe.bottom,
84
+ left:
85
+ safe.left + FLOATING_SIDEBAR_WIDTH + FLOATING_CHROME_MARGIN * 2 + FLOATING_CONTENT_CLEARANCE,
86
+ };
87
+ }
88
+
89
+ /** Read shell safe-area CSS vars as pixel numbers (0 when unavailable). */
90
+ export function readShellSafeAreaPx(el: HTMLElement = document.documentElement): FloatingSafeArea {
91
+ const styles = getComputedStyle(el);
92
+ const parse = (name: string): number => {
93
+ const raw = styles.getPropertyValue(name).trim();
94
+ const n = parseFloat(raw);
95
+ return Number.isFinite(n) ? n : 0;
96
+ };
97
+ return {
98
+ top: parse('--shellui-safe-area-top'),
99
+ right: parse('--shellui-safe-area-right'),
100
+ bottom: parse('--shellui-safe-area-bottom'),
101
+ left: parse('--shellui-safe-area-left'),
102
+ };
103
+ }
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { isShellOwnedPath } from './isShellOwnedPath';
3
+
4
+ describe('isShellOwnedPath', () => {
5
+ it('matches settings and nested settings routes', () => {
6
+ expect(isShellOwnedPath('/__settings')).toBe(true);
7
+ expect(isShellOwnedPath('/__settings/')).toBe(true);
8
+ expect(isShellOwnedPath('/__settings/developpers')).toBe(true);
9
+ expect(isShellOwnedPath('/__settings/appearance')).toBe(true);
10
+ });
11
+
12
+ it('matches other shell pages', () => {
13
+ expect(isShellOwnedPath('/login')).toBe(true);
14
+ expect(isShellOwnedPath('/admin')).toBe(true);
15
+ expect(isShellOwnedPath('/legal/privacy-policy')).toBe(true);
16
+ });
17
+
18
+ it('rejects embedded app paths', () => {
19
+ expect(isShellOwnedPath('/')).toBe(false);
20
+ expect(isShellOwnedPath('/home')).toBe(false);
21
+ expect(isShellOwnedPath('/dashboard')).toBe(false);
22
+ });
23
+ });
@@ -0,0 +1,16 @@
1
+ import urls from '../../../constants/urls';
2
+
3
+ const SHELL_OWNED_PREFIXES = [
4
+ urls.settings,
5
+ urls.cookiePreferences,
6
+ urls.overlayDemo,
7
+ urls.login,
8
+ urls.admin,
9
+ urls.legalDocuments,
10
+ ] as const;
11
+
12
+ /** True for shell React pages (settings, login, admin, …) — not embedded iframe apps. */
13
+ export function isShellOwnedPath(pathname: string): boolean {
14
+ const path = pathname.replace(/\/+$/, '') || '/';
15
+ return SHELL_OWNED_PREFIXES.some((prefix) => path === prefix || path.startsWith(`${prefix}/`));
16
+ }
@@ -0,0 +1,46 @@
1
+ import { applyLayoutChromeStyles, shellui, type LayoutChrome } from '@shellui/sdk';
2
+
3
+ let currentChrome: LayoutChrome | null = null;
4
+
5
+ /** Current layout-chrome snapshot (shell-side). Used when building settings for iframes. */
6
+ export function getPublishedLayoutChrome(): LayoutChrome | null {
7
+ return currentChrome;
8
+ }
9
+
10
+ /** Main layout content iframes only (not modal / drawer / picker overlays). */
11
+ export function isMainLayoutFrame(iframe: HTMLIFrameElement | null | undefined): boolean {
12
+ if (!iframe) return false;
13
+ return iframe.dataset.shelluiFrame !== 'overlay';
14
+ }
15
+
16
+ const CLEARED_CHROME: LayoutChrome = {
17
+ layout: 'none',
18
+ viewport: 'desktop',
19
+ insets: { top: 0, right: 0, bottom: 0, left: 0 },
20
+ chromeVisible: false,
21
+ autoPadding: true,
22
+ };
23
+
24
+ /**
25
+ * Publish layout chrome to main layout content frames only.
26
+ * Overlay iframes (modal / drawer) are skipped. Apps apply insets inside their UI
27
+ * via CSS vars / `shellui-apply-layout-chrome-pad` — the iframe stays 100%×100%.
28
+ */
29
+ export function publishLayoutChrome(chrome: LayoutChrome | null): void {
30
+ currentChrome = chrome;
31
+ if (typeof window === 'undefined') return;
32
+
33
+ const payload: LayoutChrome = chrome ?? CLEARED_CHROME;
34
+
35
+ // Host shell document: vars only (no padding on the outer shell).
36
+ applyLayoutChromeStyles(payload, { autoPadding: false });
37
+
38
+ for (const [uuid, iframe] of shellui.frameRegistry.getAllIframes()) {
39
+ if (!isMainLayoutFrame(iframe)) continue;
40
+ shellui.sendMessage({
41
+ type: 'SHELLUI_LAYOUT_CHROME',
42
+ payload: { layoutChrome: payload },
43
+ to: [uuid],
44
+ });
45
+ }
46
+ }
@@ -0,0 +1,49 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { resolveViewport } from '../../../hooks/use-viewport';
3
+ import { reduceScrollChromeVisibility } from '@shellui/sdk';
4
+
5
+ describe('resolveViewport', () => {
6
+ it('maps widths to mobile / tablet / desktop', () => {
7
+ expect(resolveViewport(320)).toBe('mobile');
8
+ expect(resolveViewport(767)).toBe('mobile');
9
+ expect(resolveViewport(768)).toBe('tablet');
10
+ expect(resolveViewport(1023)).toBe('tablet');
11
+ expect(resolveViewport(1024)).toBe('desktop');
12
+ });
13
+ });
14
+
15
+ describe('reduceScrollChromeVisibility', () => {
16
+ it('reveals chrome near the top', () => {
17
+ const next = reduceScrollChromeVisibility({ visible: false, lastY: 100 }, 10);
18
+ expect(next.visible).toBe(true);
19
+ });
20
+
21
+ it('hides chrome when scrolling down past threshold', () => {
22
+ const next = reduceScrollChromeVisibility({ visible: true, lastY: 40 }, 60);
23
+ expect(next.visible).toBe(false);
24
+ });
25
+
26
+ it('shows chrome when scrolling up past threshold', () => {
27
+ const next = reduceScrollChromeVisibility({ visible: false, lastY: 80 }, 60);
28
+ expect(next.visible).toBe(true);
29
+ });
30
+
31
+ it('ignores small deltas (hysteresis)', () => {
32
+ const next = reduceScrollChromeVisibility({ visible: true, lastY: 50 }, 55);
33
+ expect(next.visible).toBe(true);
34
+ });
35
+
36
+ it('reveals chrome near the bottom of the scroller', () => {
37
+ const next = reduceScrollChromeVisibility({ visible: false, lastY: 400 }, 480, {
38
+ distanceFromBottom: 40,
39
+ });
40
+ expect(next.visible).toBe(true);
41
+ });
42
+
43
+ it('keeps chrome hidden when still far from the bottom while scrolling down', () => {
44
+ const next = reduceScrollChromeVisibility({ visible: true, lastY: 200 }, 260, {
45
+ distanceFromBottom: 200,
46
+ });
47
+ expect(next.visible).toBe(false);
48
+ });
49
+ });
@@ -0,0 +1,216 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useLocation } from 'react-router';
3
+ import {
4
+ shellui,
5
+ getScrollMetrics,
6
+ reduceScrollChromeVisibility,
7
+ type LayoutChrome,
8
+ type LayoutChromeInsets,
9
+ type LayoutChromeViewport,
10
+ type ScrollChromeState,
11
+ } from '@shellui/sdk';
12
+ import { computeFloatingInsets, readShellSafeAreaPx } from './computeFloatingInsets';
13
+ import { publishLayoutChrome } from './layoutChromeStore';
14
+
15
+ const SIDEBAR_COLLAPSED_STORAGE_KEY = 'shellui:floating-sidebar:collapsed';
16
+ /** Scroll Y / bottom distance under which an edge counts as “at end” (no fade). */
17
+ const SCROLL_EDGE_PX = 8;
18
+
19
+ export type FloatingScrollEdges = {
20
+ atTop: boolean;
21
+ atBottom: boolean;
22
+ };
23
+
24
+ const INITIAL_SCROLL_EDGES: FloatingScrollEdges = { atTop: true, atBottom: true };
25
+
26
+ function edgesFromMetrics(scrollY: number, distanceFromBottom?: number): FloatingScrollEdges {
27
+ const atTop = scrollY <= SCROLL_EDGE_PX;
28
+ const atBottom =
29
+ typeof distanceFromBottom === 'number' ? distanceFromBottom <= SCROLL_EDGE_PX : atTop;
30
+ return { atTop, atBottom };
31
+ }
32
+
33
+ function readSidebarCollapsed(): boolean {
34
+ if (typeof window === 'undefined') return false;
35
+ try {
36
+ return sessionStorage.getItem(SIDEBAR_COLLAPSED_STORAGE_KEY) === 'true';
37
+ } catch {
38
+ return false;
39
+ }
40
+ }
41
+
42
+ function writeSidebarCollapsed(collapsed: boolean): void {
43
+ if (typeof window === 'undefined') return;
44
+ try {
45
+ sessionStorage.setItem(SIDEBAR_COLLAPSED_STORAGE_KEY, String(collapsed));
46
+ } catch {
47
+ // Ignore quota / privacy mode errors.
48
+ }
49
+ }
50
+
51
+ function buildChrome(
52
+ viewport: LayoutChromeViewport,
53
+ chromeVisible: boolean,
54
+ sidebarCollapsed: boolean,
55
+ autoPadding = true,
56
+ ): LayoutChrome {
57
+ const safeArea =
58
+ typeof document !== 'undefined'
59
+ ? readShellSafeAreaPx()
60
+ : { top: 0, right: 0, bottom: 0, left: 0 };
61
+ const desktopCollapsed = viewport === 'desktop' && sidebarCollapsed;
62
+ return {
63
+ layout: 'floating',
64
+ viewport,
65
+ chromeVisible: viewport === 'desktop' ? !desktopCollapsed : chromeVisible,
66
+ autoPadding,
67
+ // Phone/tablet: keep tab-bar-sized insets even when chrome hides on scroll
68
+ // so padding does not jump. Desktop: insets follow sidebar collapsed state.
69
+ insets: computeFloatingInsets({
70
+ viewport,
71
+ chromeVisible: true,
72
+ sidebarCollapsed: desktopCollapsed,
73
+ safeArea,
74
+ }),
75
+ };
76
+ }
77
+
78
+ /**
79
+ * Owns floating chrome visibility (hide-on-scroll on phone/tablet),
80
+ * desktop sidebar collapse, publishes layoutChrome to iframes.
81
+ */
82
+ export function useFloatingChrome(viewport: LayoutChromeViewport) {
83
+ const location = useLocation();
84
+ const [chromeVisible, setChromeVisible] = useState(true);
85
+ const [scrollEdges, setScrollEdges] = useState<FloatingScrollEdges>(INITIAL_SCROLL_EDGES);
86
+ const [sidebarCollapsed, setSidebarCollapsedState] = useState(readSidebarCollapsed);
87
+ const scrollStateRef = useRef<ScrollChromeState>({ visible: true, lastY: 0 });
88
+ const viewportRef = useRef(viewport);
89
+ viewportRef.current = viewport;
90
+ const sidebarCollapsedRef = useRef(sidebarCollapsed);
91
+ sidebarCollapsedRef.current = sidebarCollapsed;
92
+ const hideOnScroll = viewport !== 'desktop';
93
+
94
+ const pushChrome = useCallback(
95
+ (visible: boolean, vp: LayoutChromeViewport, collapsed: boolean) => {
96
+ publishLayoutChrome(buildChrome(vp, visible, collapsed));
97
+ },
98
+ [],
99
+ );
100
+
101
+ const setSidebarCollapsed = useCallback((collapsed: boolean) => {
102
+ setSidebarCollapsedState(collapsed);
103
+ writeSidebarCollapsed(collapsed);
104
+ }, []);
105
+
106
+ const toggleSidebarCollapsed = useCallback(() => {
107
+ setSidebarCollapsed(!sidebarCollapsedRef.current);
108
+ }, [setSidebarCollapsed]);
109
+
110
+ const applyScrollMetrics = useCallback((scrollY: number, distanceFromBottom?: number) => {
111
+ if (viewportRef.current === 'desktop') return;
112
+
113
+ const edges = edgesFromMetrics(scrollY, distanceFromBottom);
114
+ setScrollEdges((prev) =>
115
+ prev.atTop === edges.atTop && prev.atBottom === edges.atBottom ? prev : edges,
116
+ );
117
+
118
+ const next = reduceScrollChromeVisibility(scrollStateRef.current, scrollY, {
119
+ distanceFromBottom,
120
+ });
121
+ scrollStateRef.current = next;
122
+ setChromeVisible((prev) => (prev === next.visible ? prev : next.visible));
123
+ }, []);
124
+
125
+ // Reset hide-on-scroll when viewport tier or shell route changes.
126
+ useEffect(() => {
127
+ setChromeVisible(true);
128
+ setScrollEdges(INITIAL_SCROLL_EDGES);
129
+ scrollStateRef.current = { visible: true, lastY: 0 };
130
+ pushChrome(true, viewport, sidebarCollapsedRef.current);
131
+ // Shell-owned pages: sample document scroller (iframes report via message).
132
+ const metrics = getScrollMetrics(document);
133
+ if (metrics) {
134
+ applyScrollMetrics(metrics.scrollY, metrics.distanceFromBottom);
135
+ }
136
+ }, [viewport, location.pathname, pushChrome, applyScrollMetrics]);
137
+
138
+ useEffect(() => {
139
+ const visible = viewport === 'desktop' ? true : chromeVisible;
140
+ pushChrome(visible, viewport, sidebarCollapsed);
141
+ }, [chromeVisible, viewport, sidebarCollapsed, pushChrome]);
142
+
143
+ useEffect(() => {
144
+ const onResize = () => {
145
+ const visible = viewportRef.current === 'desktop' ? true : scrollStateRef.current.visible;
146
+ pushChrome(visible, viewportRef.current, sidebarCollapsedRef.current);
147
+ };
148
+ window.addEventListener('resize', onResize);
149
+ return () => window.removeEventListener('resize', onResize);
150
+ }, [pushChrome]);
151
+
152
+ useEffect(() => {
153
+ if (!hideOnScroll) return;
154
+ const cleanup = shellui.addMessageListener('SHELLUI_CONTENT_SCROLL', (data) => {
155
+ const payload = data.payload as
156
+ | { scrollY?: number; direction?: 'up' | 'down' | 'none'; distanceFromBottom?: number }
157
+ | undefined;
158
+ if (typeof payload?.scrollY !== 'number') return;
159
+ applyScrollMetrics(payload.scrollY, payload.distanceFromBottom);
160
+ });
161
+ return cleanup;
162
+ }, [applyScrollMetrics, hideOnScroll]);
163
+
164
+ useEffect(() => {
165
+ if (!hideOnScroll) return;
166
+ const onScroll = (event: Event) => {
167
+ const el = event.target;
168
+ if (el instanceof Element) {
169
+ if (
170
+ el.closest(
171
+ '[data-shellui-floating-tabbar], [data-shellui-floating-sidebar], [data-shellui-floating-fade]',
172
+ )
173
+ ) {
174
+ return;
175
+ }
176
+ }
177
+ const metrics = getScrollMetrics(el);
178
+ if (!metrics) return;
179
+ applyScrollMetrics(metrics.scrollY, metrics.distanceFromBottom);
180
+ };
181
+
182
+ document.addEventListener('scroll', onScroll, { capture: true, passive: true });
183
+ return () => document.removeEventListener('scroll', onScroll, true);
184
+ }, [applyScrollMetrics, hideOnScroll]);
185
+
186
+ useEffect(() => {
187
+ return () => {
188
+ publishLayoutChrome(null);
189
+ };
190
+ }, []);
191
+
192
+ const effectiveVisible = viewport === 'desktop' ? true : chromeVisible;
193
+
194
+ const insets: LayoutChromeInsets = useMemo(() => {
195
+ const safeArea =
196
+ typeof document !== 'undefined'
197
+ ? readShellSafeAreaPx()
198
+ : { top: 0, right: 0, bottom: 0, left: 0 };
199
+ return computeFloatingInsets({
200
+ viewport,
201
+ chromeVisible: true,
202
+ sidebarCollapsed: viewport === 'desktop' && sidebarCollapsed,
203
+ safeArea,
204
+ });
205
+ }, [viewport, sidebarCollapsed]);
206
+
207
+ return {
208
+ chromeVisible: effectiveVisible,
209
+ setChromeVisible,
210
+ sidebarCollapsed: viewport === 'desktop' ? sidebarCollapsed : false,
211
+ setSidebarCollapsed,
212
+ toggleSidebarCollapsed,
213
+ scrollEdges,
214
+ insets,
215
+ };
216
+ }
@@ -4,8 +4,12 @@ import { useTranslation } from 'react-i18next';
4
4
  import type { NavigationItem, NavigationGroup } from '../../config/types';
5
5
  import { flattenNavigationItems } from '../utils';
6
6
  import { DesktopHistoryButtons } from '../chrome/DesktopHistoryButtons';
7
- import { useIsTauriClient, useMacOverlayChrome } from '../chrome/runtime';
8
- import { DESKTOP_TITLEBAR_HEIGHT_PX, MAC_TRAFFIC_LIGHTS_WIDTH_PX } from '../chrome/constants';
7
+ import { useIsTauriClient, useMacTrafficLights } from '../chrome/runtime';
8
+ import {
9
+ DESKTOP_TITLEBAR_HEIGHT_PX,
10
+ DESKTOP_TITLEBAR_PAD_TOP_PX,
11
+ MAC_TRAFFIC_LIGHTS_WIDTH_PX,
12
+ } from '../chrome/constants';
9
13
 
10
14
  interface FullscreenLayoutProps {
11
15
  title?: string;
@@ -26,7 +30,7 @@ export function FullscreenLayout({ title, navigation, children }: FullscreenLayo
26
30
  const location = useLocation();
27
31
  const { i18n } = useTranslation();
28
32
  const isTauriEnv = useIsTauriClient();
29
- const overlay = useMacOverlayChrome();
33
+ const trafficLights = useMacTrafficLights();
30
34
  const currentLanguage = i18n.language || 'en';
31
35
  const navigationItems = useMemo(() => flattenNavigationItems(navigation), [navigation]);
32
36
 
@@ -54,7 +58,8 @@ export function FullscreenLayout({ title, navigation, children }: FullscreenLayo
54
58
  className="pointer-events-auto absolute top-0 left-0 z-[46] flex items-center"
55
59
  style={{
56
60
  height: DESKTOP_TITLEBAR_HEIGHT_PX,
57
- paddingLeft: overlay ? MAC_TRAFFIC_LIGHTS_WIDTH_PX : 8,
61
+ paddingTop: DESKTOP_TITLEBAR_PAD_TOP_PX,
62
+ paddingLeft: trafficLights ? MAC_TRAFFIC_LIGHTS_WIDTH_PX : 8,
58
63
  }}
59
64
  >
60
65
  <DesktopHistoryButtons />
@@ -13,6 +13,7 @@ import { DesktopHistoryButtons } from '../chrome/DesktopHistoryButtons';
13
13
  import { useIsTauriClient, useMacOverlayChrome, useMacTrafficLights } from '../chrome/runtime';
14
14
  import {
15
15
  DESKTOP_TITLEBAR_HEIGHT_PX,
16
+ DESKTOP_TITLEBAR_PAD_TOP_PX,
16
17
  MAC_TRAFFIC_LIGHTS_GAP_PX,
17
18
  MAC_TRAFFIC_LIGHTS_WIDTH_PX,
18
19
  } from '../chrome/constants';
@@ -76,44 +77,45 @@ export function SidebarInner({
76
77
  <>
77
78
  <SidebarHeader
78
79
  className={cn(
79
- 'border-b border-sidebar-border select-none',
80
- showOverlayHeader && 'gap-0 p-0',
80
+ // Always pin to titlebar height — default SidebarHeader p-2 is taller on web.
81
+ 'gap-0 border-b border-sidebar-border select-none',
82
+ showOverlayHeader || mobileSheetHeader ? 'p-0' : 'px-2 py-0',
81
83
  showCollapsedTopBar && 'hidden',
82
- mobileSheetHeader && 'gap-0 p-0',
83
84
  )}
84
- style={
85
- mobileSheetHeader
86
- ? {
87
- height: DESKTOP_TITLEBAR_HEIGHT_PX,
88
- paddingLeft: mobileTrafficInset,
89
- }
90
- : undefined
91
- }
85
+ style={{
86
+ height: DESKTOP_TITLEBAR_HEIGHT_PX,
87
+ // Nudge controls down so they optically match centered traffic lights.
88
+ paddingTop: DESKTOP_TITLEBAR_PAD_TOP_PX,
89
+ ...(mobileSheetHeader ? { paddingLeft: mobileTrafficInset } : {}),
90
+ }}
92
91
  {...(showOverlayHeader
93
92
  ? { 'data-shellui-drag-region': '', 'data-tauri-drag-region': '' }
94
93
  : {})}
95
94
  >
96
95
  {showOverlayHeader ? (
97
96
  <div
98
- className="flex w-full shrink-0 items-stretch"
99
- style={{ height: DESKTOP_TITLEBAR_HEIGHT_PX }}
97
+ className="flex h-full w-full shrink-0 items-stretch"
100
98
  data-shellui-drag-region=""
101
99
  data-tauri-drag-region=""
102
100
  >
103
- <div
104
- className="h-full shrink-0"
105
- style={{ width: MAC_TRAFFIC_LIGHTS_WIDTH_PX }}
106
- aria-hidden
107
- />
101
+ {trafficLights ? (
102
+ <div
103
+ className="h-full shrink-0"
104
+ style={{ width: MAC_TRAFFIC_LIGHTS_WIDTH_PX }}
105
+ aria-hidden
106
+ />
107
+ ) : null}
108
108
  <div
109
109
  className="flex h-full min-w-0 flex-1 items-center gap-1"
110
- style={{ paddingLeft: MAC_TRAFFIC_LIGHTS_GAP_PX }}
110
+ style={{
111
+ paddingLeft: trafficLights ? MAC_TRAFFIC_LIGHTS_GAP_PX : 8,
112
+ }}
111
113
  >
112
114
  {hasAppIcon ? brandIcon : null}
113
115
  {!hasAppIcon ? (
114
116
  <SidebarTrigger
115
117
  data-shellui-no-drag=""
116
- className="size-8 shrink-0 touch-manipulation"
118
+ className="size-7 shrink-0 touch-manipulation"
117
119
  />
118
120
  ) : null}
119
121
  <div
@@ -126,20 +128,14 @@ export function SidebarInner({
126
128
  {hasAppIcon ? (
127
129
  <SidebarTrigger
128
130
  data-shellui-no-drag=""
129
- className="size-8 shrink-0 touch-manipulation"
131
+ className="size-7 shrink-0 touch-manipulation"
130
132
  />
131
133
  ) : null}
132
134
  {hasAppIcon ? trailingInset : null}
133
135
  </div>
134
136
  </div>
135
137
  ) : (
136
- <div
137
- className={cn(
138
- 'flex w-full items-center',
139
- hasAppIcon ? 'gap-0' : 'gap-0.5',
140
- mobileSheetHeader && 'h-full',
141
- )}
142
- >
138
+ <div className={cn('flex h-full w-full items-center', hasAppIcon ? 'gap-0' : 'gap-0.5')}>
143
139
  {brandIcon}
144
140
  {hasAppIcon ? (
145
141
  <div
@@ -147,7 +143,7 @@ export function SidebarInner({
147
143
  className="min-w-0 flex-1"
148
144
  />
149
145
  ) : null}
150
- <SidebarTrigger className="size-8 shrink-0 touch-manipulation" />
146
+ <SidebarTrigger className="size-7 shrink-0 touch-manipulation" />
151
147
  {trailingInset}
152
148
  </div>
153
149
  )}