@shellui/core 0.5.0-beta.2 → 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.
- package/package.json +2 -2
- package/schemas/shellui.config.schema.json +10 -2
- package/src/components/ContentView.tsx +12 -5
- package/src/components/ui/alert-dialog.tsx +1 -1
- package/src/components/ui/sidebar.tsx +59 -20
- package/src/features/config/types.ts +16 -2
- package/src/features/layouts/AppLayout.tsx +30 -3
- package/src/features/layouts/OverlayShell.tsx +3 -1
- package/src/features/layouts/app-bar-inset/AppBarInsetLayout.tsx +22 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +51 -12
- package/src/features/layouts/floating/FloatingFadeMask.tsx +22 -0
- package/src/features/layouts/floating/FloatingLayout.tsx +142 -0
- package/src/features/layouts/floating/FloatingSidebar.tsx +327 -0
- package/src/features/layouts/floating/FloatingTabBar.tsx +437 -0
- package/src/features/layouts/floating/FloatingTabIndicator.tsx +216 -0
- package/src/features/layouts/floating/computeFloatingInsets.spec.ts +83 -0
- package/src/features/layouts/floating/computeFloatingInsets.ts +103 -0
- package/src/features/layouts/floating/isShellOwnedPath.spec.ts +23 -0
- package/src/features/layouts/floating/isShellOwnedPath.ts +16 -0
- package/src/features/layouts/floating/layoutChromeStore.ts +46 -0
- package/src/features/layouts/floating/scrollChrome.spec.ts +49 -0
- package/src/features/layouts/floating/useFloatingChrome.ts +216 -0
- package/src/features/layouts/sidebar/SidebarLayout.tsx +32 -6
- package/src/features/layouts/sidebar/types.ts +4 -0
- package/src/features/layouts/sidebar-inset/SidebarInsetLayout.tsx +15 -0
- package/src/features/settings/SettingsProvider.tsx +7 -0
- package/src/features/settings/SettingsView.tsx +6 -6
- package/src/features/settings/components/Develop.tsx +31 -13
- package/src/features/settings/utils/buildSettingsForPropagation.ts +16 -0
- package/src/features/storage/StoragePickerContext.tsx +1 -0
- package/src/hooks/use-viewport.ts +40 -0
- package/src/i18n/translations/en/settings.json +8 -2
- package/src/i18n/translations/fr/settings.json +8 -2
- package/src/index.css +321 -0
- 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
|
+
}
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
DESKTOP_TITLEBAR_HEIGHT_PX,
|
|
40
40
|
DESKTOP_TITLEBAR_PAD_TOP_PX,
|
|
41
41
|
} from '../chrome/constants';
|
|
42
|
+
import { cn } from '../../../lib/utils';
|
|
42
43
|
|
|
43
44
|
/** Close the mobile sheet when the route changes. */
|
|
44
45
|
function CloseMobileSidebarOnNavigate() {
|
|
@@ -81,7 +82,12 @@ function CollapsedTitlebarOffset() {
|
|
|
81
82
|
return null;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
const SidebarLayoutContent = ({
|
|
85
|
+
const SidebarLayoutContent = ({
|
|
86
|
+
title,
|
|
87
|
+
appIcon,
|
|
88
|
+
navigation,
|
|
89
|
+
variant = 'sidebar',
|
|
90
|
+
}: SidebarLayoutProps) => {
|
|
85
91
|
const { i18n } = useTranslation();
|
|
86
92
|
const { isAuthenticated } = useAuth();
|
|
87
93
|
const { settings } = useSettings();
|
|
@@ -131,7 +137,12 @@ const SidebarLayoutContent = ({ title, appIcon, navigation }: SidebarLayoutProps
|
|
|
131
137
|
return (
|
|
132
138
|
<div
|
|
133
139
|
data-shellui-sidebar-layout=""
|
|
134
|
-
|
|
140
|
+
data-shellui-layout-variant={variant}
|
|
141
|
+
className={cn(
|
|
142
|
+
'flex h-full max-h-full flex-col overflow-hidden',
|
|
143
|
+
// Inset chrome: darkened tray so the main frame (and in-app sidebars) separate cleanly.
|
|
144
|
+
variant === 'inset' && 'bg-shellui-inset-chrome',
|
|
145
|
+
)}
|
|
135
146
|
>
|
|
136
147
|
<SafeAreaTopbarOffset enabled={showSafeAreaTopbar} />
|
|
137
148
|
{/*
|
|
@@ -139,7 +150,14 @@ const SidebarLayoutContent = ({ title, appIcon, navigation }: SidebarLayoutProps
|
|
|
139
150
|
top safe-area, painted with sidebar background. Height is 0 when the inset
|
|
140
151
|
is 0; overflow clips the border so no stray hairline.
|
|
141
152
|
*/}
|
|
142
|
-
<SafeAreaTopbarStrip
|
|
153
|
+
<SafeAreaTopbarStrip
|
|
154
|
+
enabled={showSafeAreaTopbar}
|
|
155
|
+
className={
|
|
156
|
+
variant === 'inset'
|
|
157
|
+
? '[&>div]:border-transparent [&>div]:bg-shellui-inset-chrome'
|
|
158
|
+
: undefined
|
|
159
|
+
}
|
|
160
|
+
/>
|
|
143
161
|
<SidebarProvider className="min-h-0 flex-1 overflow-hidden">
|
|
144
162
|
<CloseMobileSidebarOnNavigate />
|
|
145
163
|
<CloseMobileSidebarOnOverlay />
|
|
@@ -147,6 +165,7 @@ const SidebarLayoutContent = ({ title, appIcon, navigation }: SidebarLayoutProps
|
|
|
147
165
|
<CollapsedDesktopTitlebar />
|
|
148
166
|
<Sidebar
|
|
149
167
|
collapsible="icon"
|
|
168
|
+
variant={variant}
|
|
150
169
|
className="border-sidebar-border"
|
|
151
170
|
>
|
|
152
171
|
<SidebarInner
|
|
@@ -156,10 +175,11 @@ const SidebarLayoutContent = ({ title, appIcon, navigation }: SidebarLayoutProps
|
|
|
156
175
|
title={title}
|
|
157
176
|
appIcon={appIcon}
|
|
158
177
|
/>
|
|
159
|
-
<SidebarRail />
|
|
178
|
+
{variant !== 'inset' ? <SidebarRail /> : null}
|
|
160
179
|
</Sidebar>
|
|
161
180
|
|
|
162
181
|
<SidebarInset className="relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
|
182
|
+
{variant === 'inset' ? <SidebarRail placement="inset" /> : null}{' '}
|
|
163
183
|
{/*
|
|
164
184
|
Mobile top chrome: extend the header background into the status-bar band
|
|
165
185
|
so there is no empty strip. Interactive controls stay below the inset via
|
|
@@ -187,7 +207,6 @@ const SidebarLayoutContent = ({ title, appIcon, navigation }: SidebarLayoutProps
|
|
|
187
207
|
/>
|
|
188
208
|
{isTauriEnv ? <DesktopHistoryButtons /> : null}
|
|
189
209
|
</header>
|
|
190
|
-
|
|
191
210
|
{/*
|
|
192
211
|
Fill to the physical bottom — do not pad safe-area here or the iframe
|
|
193
212
|
looks cut off. In-app content (settings, etc.) owns bottom safe insets.
|
|
@@ -201,13 +220,20 @@ const SidebarLayoutContent = ({ title, appIcon, navigation }: SidebarLayoutProps
|
|
|
201
220
|
);
|
|
202
221
|
};
|
|
203
222
|
|
|
204
|
-
export function SidebarLayout({
|
|
223
|
+
export function SidebarLayout({
|
|
224
|
+
title,
|
|
225
|
+
appIcon,
|
|
226
|
+
logo,
|
|
227
|
+
navigation,
|
|
228
|
+
variant = 'sidebar',
|
|
229
|
+
}: SidebarLayoutProps) {
|
|
205
230
|
return (
|
|
206
231
|
<SidebarLayoutContent
|
|
207
232
|
title={title}
|
|
208
233
|
appIcon={appIcon}
|
|
209
234
|
logo={logo}
|
|
210
235
|
navigation={navigation}
|
|
236
|
+
variant={variant}
|
|
211
237
|
/>
|
|
212
238
|
);
|
|
213
239
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { NavigationItem, NavigationGroup, ThemeAsset } from '../../config/types';
|
|
2
2
|
|
|
3
|
+
export type SidebarChromeVariant = 'sidebar' | 'inset';
|
|
4
|
+
|
|
3
5
|
export interface SidebarLayoutProps {
|
|
4
6
|
title?: string;
|
|
5
7
|
appIcon?: ThemeAsset;
|
|
6
8
|
logo?: ThemeAsset;
|
|
7
9
|
navigation: (NavigationItem | NavigationGroup)[];
|
|
10
|
+
/** Visual chrome: default flush sidebar, or inset padded/rounded main frame. */
|
|
11
|
+
variant?: SidebarChromeVariant;
|
|
8
12
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SidebarLayout } from '../sidebar/SidebarLayout';
|
|
2
|
+
import type { SidebarLayoutProps } from '../sidebar/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sidebar inset layout — same as sidebar, with a padded, rounded main frame that
|
|
6
|
+
* reveals the chrome background around the content area (desktop).
|
|
7
|
+
*/
|
|
8
|
+
export function SidebarInsetLayout(props: SidebarLayoutProps) {
|
|
9
|
+
return (
|
|
10
|
+
<SidebarLayout
|
|
11
|
+
{...props}
|
|
12
|
+
variant="inset"
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
15
|
+
}
|