@shellui/core 0.7.0-alpha.1 → 0.7.0-alpha.11
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 +37 -4
- package/src/components/ContentView.tsx +19 -8
- package/src/components/ui/drawer.tsx +47 -30
- package/src/components/ui/sheet.tsx +18 -12
- package/src/components/ui/sidebar.tsx +25 -11
- package/src/components/ui/tooltip.tsx +4 -2
- package/src/features/admin/AdminView.tsx +9 -6
- package/src/features/auth/AuthProvider.tsx +25 -4
- package/src/features/auth/appBackend/appBackendSessions.spec.ts +134 -0
- package/src/features/auth/appBackend/appBackendSessions.ts +168 -17
- package/src/features/auth/appBackend/childFrames.spec.ts +328 -0
- package/src/features/auth/appBackend/childFrames.ts +180 -0
- package/src/features/auth/appBackend/frameAuth.ts +47 -10
- package/src/features/auth/appBackend/silentSignIn.spec.ts +18 -0
- package/src/features/auth/appBackend/silentSignIn.ts +15 -1
- package/src/features/auth/appBackend/tokenExchange.spec.ts +98 -0
- package/src/features/auth/appBackend/tokenExchange.ts +76 -0
- package/src/features/auth/components/LoginButton.spec.tsx +155 -0
- package/src/features/auth/components/LoginButton.tsx +52 -27
- package/src/features/auth/components/LoginButtonIcons.tsx +4 -8
- package/src/features/auth/components/OAuthCallbackView.tsx +7 -5
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +42 -1
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +23 -0
- package/src/features/auth/utils/canRestoreStoredSession.spec.ts +29 -0
- package/src/features/auth/utils/canRestoreStoredSession.ts +12 -0
- package/src/features/auth/utils/index.ts +7 -1
- package/src/features/auth/utils/resolveSdkLoginRedirectPath.spec.ts +41 -0
- package/src/features/auth/utils/resolveSdkLoginRedirectPath.ts +31 -0
- package/src/features/auth/utils/webPkce.spec.ts +23 -0
- package/src/features/auth/utils/webPkce.ts +23 -6
- package/src/features/chromeActions/ChromeActionsHost.tsx +5 -1
- package/src/features/chromeActions/computeActionInsets.ts +7 -4
- package/src/features/config/types.ts +30 -4
- package/src/features/layouts/OverlayShell.tsx +58 -40
- package/src/features/layouts/appbar/AppBarItemIcon.spec.tsx +45 -0
- package/src/features/layouts/appbar/AppBarItemIcon.tsx +19 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +115 -110
- package/src/features/layouts/appbar/appBarOverflow.spec.ts +27 -0
- package/src/features/layouts/appbar/appBarOverflow.ts +42 -0
- package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +13 -24
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +5 -6
- package/src/features/layouts/chrome/DesktopChrome.tsx +37 -0
- package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +15 -4
- package/src/features/layouts/chrome/MacStrip.tsx +33 -0
- package/src/features/layouts/chrome/constants.ts +36 -8
- package/src/features/layouts/chrome/index.ts +8 -0
- package/src/features/layouts/chrome/stripDragMap.ts +35 -0
- package/src/features/layouts/chrome/stripNoDrag.spec.tsx +103 -0
- package/src/features/layouts/chrome/useScrollHideChrome.ts +3 -8
- package/src/features/layouts/chrome/viewport.ts +11 -4
- package/src/features/layouts/filterNavigationForAuthState.spec.ts +5 -3
- package/src/features/layouts/floating/FloatingBottomDock.tsx +263 -43
- package/src/features/layouts/floating/FloatingLayout.tsx +14 -8
- package/src/features/layouts/floating/FloatingSidebar.tsx +165 -73
- package/src/features/layouts/floating/computeFloatingInsets.ts +22 -4
- package/src/features/layouts/floating/moreSections.spec.ts +28 -0
- package/src/features/layouts/floating/moreSections.ts +31 -0
- package/src/features/layouts/floating/useFloatingChrome.ts +3 -1
- package/src/features/layouts/floating/useSoftKeyboard.spec.ts +39 -0
- package/src/features/layouts/floating/useSoftKeyboard.ts +82 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.spec.tsx +68 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +47 -10
- package/src/features/layouts/sidebar/NavigationContent.tsx +17 -9
- package/src/features/layouts/sidebar/SidebarIcons.tsx +70 -9
- package/src/features/layouts/sidebar/SidebarInner.spec.tsx +109 -0
- package/src/features/layouts/sidebar/SidebarInner.tsx +94 -43
- package/src/features/layouts/sidebar/SidebarLayout.tsx +24 -17
- package/src/features/layouts/utils.ts +4 -3
- package/src/features/layouts/windows/DesktopDots.tsx +76 -0
- package/src/features/layouts/windows/WindowsLayout.tsx +251 -161
- package/src/features/layouts/windows/deskDots.spec.ts +54 -0
- package/src/features/layouts/windows/deskDots.ts +314 -0
- package/src/features/overlays/ResponsiveModal.tsx +5 -3
- package/src/features/overlays/overlaySize.spec.ts +56 -16
- package/src/features/overlays/overlaySize.ts +114 -31
- package/src/features/overlays/phoneDrawerAnchoring.spec.ts +187 -0
- package/src/features/overlays/useOverlayReportedSize.ts +8 -3
- package/src/features/settings/SettingsProvider.tsx +158 -2
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +8 -7
- package/src/features/settings/utils/buildSettingsForPropagation.ts +4 -6
- package/src/features/theme/applyTheme.ts +8 -0
- package/src/features/theme/navContrast.spec.ts +49 -0
- package/src/features/theme/navContrast.ts +108 -0
- package/src/features/transfers/transferQueue.spec.ts +6 -2
- package/src/i18n/translations/en/common.json +26 -0
- package/src/i18n/translations/fr/common.json +26 -0
- package/src/index.css +1145 -77
- package/src/index.ts +1 -0
- package/src/routes/hooks/useNavigationItems.ts +14 -3
- package/src/routes/hooks/withShellSearch.spec.ts +13 -0
- package/src/service-worker/devCaches.spec.ts +32 -0
- package/src/service-worker/devCaches.ts +27 -0
- package/src/service-worker/sw-dev.ts +23 -23
|
@@ -4,12 +4,20 @@ 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, useMacTrafficLights } from '../chrome/runtime';
|
|
7
|
+
import { useIsTauriClient, useMacOverlayChrome, useMacTrafficLights } from '../chrome/runtime';
|
|
8
8
|
import {
|
|
9
9
|
DESKTOP_TITLEBAR_HEIGHT_PX,
|
|
10
10
|
DESKTOP_TITLEBAR_PAD_TOP_PX,
|
|
11
|
-
|
|
11
|
+
MAC_LIGHTS_SAFE_PX,
|
|
12
|
+
SHELL_HEADER_HEIGHT_PX,
|
|
13
|
+
SHELL_HEADER_PAD_TOP_PX,
|
|
12
14
|
} from '../chrome/constants';
|
|
15
|
+
import { MAC_DRAG_REGION_PROPS, MacLightsSafeArea, MacStripSpacer } from '../chrome/MacStrip';
|
|
16
|
+
import { isShellUiRootWindow } from '../chrome/SafeAreaTopbar';
|
|
17
|
+
import { cn } from '../../../lib/utils';
|
|
18
|
+
|
|
19
|
+
/** macOS: content starts under the 32px strip plus 16px. */
|
|
20
|
+
const MAC_CONTENT_PAD_TOP_PX = 48;
|
|
13
21
|
|
|
14
22
|
interface FullscreenLayoutProps {
|
|
15
23
|
title?: string;
|
|
@@ -31,7 +39,10 @@ export function FullscreenLayout({ title, navigation, children }: FullscreenLayo
|
|
|
31
39
|
const { i18n } = useTranslation();
|
|
32
40
|
const isTauriEnv = useIsTauriClient();
|
|
33
41
|
const trafficLights = useMacTrafficLights();
|
|
42
|
+
const macStrip = useMacOverlayChrome();
|
|
34
43
|
const currentLanguage = i18n.language || 'en';
|
|
44
|
+
// Nested shell-in-iframe: the root window already cleared the safe areas.
|
|
45
|
+
const safeAreaPad = isShellUiRootWindow();
|
|
35
46
|
const navigationItems = useMemo(() => flattenNavigationItems(navigation), [navigation]);
|
|
36
47
|
|
|
37
48
|
useEffect(() => {
|
|
@@ -52,20 +63,46 @@ export function FullscreenLayout({ title, navigation, children }: FullscreenLayo
|
|
|
52
63
|
}, [location.pathname, title, navigationItems, currentLanguage]);
|
|
53
64
|
|
|
54
65
|
return (
|
|
55
|
-
<main
|
|
56
|
-
|
|
66
|
+
<main
|
|
67
|
+
data-shellui-fullscreen=""
|
|
68
|
+
className={cn(
|
|
69
|
+
'relative flex h-full max-h-full w-full flex-col overflow-hidden bg-background',
|
|
70
|
+
// Phones: clear the notch and home indicator (nothing higher up pads them).
|
|
71
|
+
!macStrip && safeAreaPad && 'shellui-fullscreen-safe',
|
|
72
|
+
)}
|
|
73
|
+
style={macStrip ? { paddingTop: MAC_CONTENT_PAD_TOP_PX } : undefined}
|
|
74
|
+
>
|
|
75
|
+
{macStrip ? (
|
|
76
|
+
/* Transparent 32px drag strip: safe area 80, history glass group, drag spacer. */
|
|
57
77
|
<div
|
|
58
|
-
|
|
78
|
+
data-shellui-mac-strip=""
|
|
79
|
+
{...MAC_DRAG_REGION_PROPS}
|
|
80
|
+
className="absolute inset-x-0 top-0 z-[46] flex items-center select-none"
|
|
59
81
|
style={{
|
|
60
82
|
height: DESKTOP_TITLEBAR_HEIGHT_PX,
|
|
61
83
|
paddingTop: DESKTOP_TITLEBAR_PAD_TOP_PX,
|
|
62
|
-
paddingLeft: trafficLights ? MAC_TRAFFIC_LIGHTS_WIDTH_PX : 8,
|
|
63
84
|
}}
|
|
64
|
-
{...(trafficLights
|
|
65
|
-
? { 'data-shellui-drag-region': '', 'data-tauri-drag-region': '' }
|
|
66
|
-
: {})}
|
|
67
85
|
>
|
|
68
|
-
<
|
|
86
|
+
<MacLightsSafeArea />
|
|
87
|
+
{isTauriEnv ? (
|
|
88
|
+
<DesktopHistoryButtons
|
|
89
|
+
strip
|
|
90
|
+
className="shellui-history-glass"
|
|
91
|
+
/>
|
|
92
|
+
) : null}
|
|
93
|
+
<MacStripSpacer />
|
|
94
|
+
</div>
|
|
95
|
+
) : isTauriEnv ? (
|
|
96
|
+
<div
|
|
97
|
+
className="pointer-events-auto absolute top-0 left-0 z-[46] flex items-center"
|
|
98
|
+
style={{
|
|
99
|
+
height: SHELL_HEADER_HEIGHT_PX,
|
|
100
|
+
paddingTop: SHELL_HEADER_PAD_TOP_PX,
|
|
101
|
+
paddingLeft: trafficLights ? MAC_LIGHTS_SAFE_PX : 8,
|
|
102
|
+
}}
|
|
103
|
+
{...(trafficLights ? MAC_DRAG_REGION_PROPS : {})}
|
|
104
|
+
>
|
|
105
|
+
<DesktopHistoryButtons className="shellui-history-glass" />
|
|
69
106
|
</div>
|
|
70
107
|
) : null}
|
|
71
108
|
{children || <Outlet />}
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
SidebarMenuItem,
|
|
12
12
|
SidebarMenuButton,
|
|
13
13
|
} from '../../../components/ui/sidebar';
|
|
14
|
-
import { cn } from '../../../lib/utils';
|
|
15
14
|
import { getActivePathPrefix, getNavPathPrefix, flattenNavigationItems } from '../utils';
|
|
16
15
|
import { getExternalFaviconUrl } from './sidebarUtils';
|
|
17
16
|
import { ExternalLinkIcon, NavIcon } from './SidebarIcons';
|
|
@@ -29,7 +28,7 @@ export function NavigationContent({
|
|
|
29
28
|
trailing?: ReactNode;
|
|
30
29
|
}) {
|
|
31
30
|
const location = useLocation();
|
|
32
|
-
const { i18n } = useTranslation();
|
|
31
|
+
const { t, i18n } = useTranslation();
|
|
33
32
|
const currentLanguage = i18n.language || 'en';
|
|
34
33
|
|
|
35
34
|
const resolveLocalizedString = (
|
|
@@ -77,9 +76,17 @@ export function NavigationContent({
|
|
|
77
76
|
const itemLabel = resolveLocalizedString(navItem.label, currentLanguage);
|
|
78
77
|
const faviconUrl = isExternal && !navItem.icon ? getExternalFaviconUrl(navItem.url) : null;
|
|
79
78
|
const iconSrc = navItem.icon ?? faviconUrl ?? null;
|
|
80
|
-
const iconEl =
|
|
79
|
+
const iconEl = (
|
|
80
|
+
<NavIcon
|
|
81
|
+
src={iconSrc}
|
|
82
|
+
className="shellui-nav-icon"
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
81
85
|
const externalIcon = isExternal ? (
|
|
82
|
-
|
|
86
|
+
<>
|
|
87
|
+
<ExternalLinkIcon className="shellui-nav-external ml-auto size-3.5 shrink-0 opacity-70" />
|
|
88
|
+
<span className="sr-only">{t('shellChrome.externalLink')}</span>
|
|
89
|
+
</>
|
|
83
90
|
) : null;
|
|
84
91
|
const content = (
|
|
85
92
|
<>
|
|
@@ -126,8 +133,9 @@ export function NavigationContent({
|
|
|
126
133
|
<SidebarMenuButton
|
|
127
134
|
asChild
|
|
128
135
|
isActive={isActive}
|
|
136
|
+
aria-current={isActive ? 'page' : undefined}
|
|
129
137
|
tooltip={itemLabel}
|
|
130
|
-
className=
|
|
138
|
+
className="shellui-nav-row w-full"
|
|
131
139
|
>
|
|
132
140
|
{linkOrTrigger}
|
|
133
141
|
</SidebarMenuButton>
|
|
@@ -140,7 +148,7 @@ export function NavigationContent({
|
|
|
140
148
|
|
|
141
149
|
if (sections.length === 0 && trailingItem) {
|
|
142
150
|
return (
|
|
143
|
-
<SidebarGroup className="mt-0">
|
|
151
|
+
<SidebarGroup className="mt-0 px-2 py-0">
|
|
144
152
|
<SidebarGroupContent>
|
|
145
153
|
<SidebarMenu className="gap-0.5">{trailingItem}</SidebarMenu>
|
|
146
154
|
</SidebarGroupContent>
|
|
@@ -159,9 +167,9 @@ export function NavigationContent({
|
|
|
159
167
|
return (
|
|
160
168
|
<SidebarGroup
|
|
161
169
|
key={`group-${groupTitle}-${sectionIndex}`}
|
|
162
|
-
className="mt-0"
|
|
170
|
+
className="mt-0 px-2 py-0"
|
|
163
171
|
>
|
|
164
|
-
<SidebarGroupLabel className="
|
|
172
|
+
<SidebarGroupLabel className="shellui-nav-label">{groupTitle}</SidebarGroupLabel>
|
|
165
173
|
<SidebarGroupContent>
|
|
166
174
|
<SidebarMenu className="gap-0.5">
|
|
167
175
|
{section.group.items.map((navItem) => (
|
|
@@ -177,7 +185,7 @@ export function NavigationContent({
|
|
|
177
185
|
return (
|
|
178
186
|
<SidebarGroup
|
|
179
187
|
key={`items-${section.items.map((i) => i.path).join('-')}-${sectionIndex}`}
|
|
180
|
-
className="mt-0"
|
|
188
|
+
className="mt-0 px-2 py-0"
|
|
181
189
|
>
|
|
182
190
|
<SidebarGroupContent>
|
|
183
191
|
<SidebarMenu className="gap-0.5">
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cn } from '../../../lib/utils';
|
|
2
2
|
import { isAppIcon } from './sidebarUtils';
|
|
3
3
|
|
|
4
|
-
/** Inline SVG: external
|
|
4
|
+
/** Inline SVG: external link (arrow up right). Bundled so consumers don't need to serve static SVGs. */
|
|
5
5
|
export function ExternalLinkIcon({ className }: { className?: string }) {
|
|
6
6
|
return (
|
|
7
7
|
<svg
|
|
@@ -17,18 +17,79 @@ export function ExternalLinkIcon({ className }: { className?: string }) {
|
|
|
17
17
|
className={cn('shrink-0', className)}
|
|
18
18
|
aria-hidden
|
|
19
19
|
>
|
|
20
|
-
<path d="
|
|
21
|
-
<
|
|
22
|
-
<line
|
|
23
|
-
x1="10"
|
|
24
|
-
y1="14"
|
|
25
|
-
x2="21"
|
|
26
|
-
y2="3"
|
|
27
|
-
/>
|
|
20
|
+
<path d="M7 7h10v10" />
|
|
21
|
+
<path d="M7 17 17 7" />
|
|
28
22
|
</svg>
|
|
29
23
|
);
|
|
30
24
|
}
|
|
31
25
|
|
|
26
|
+
function LucideSvg({ className, children }: { className?: string; children: React.ReactNode }) {
|
|
27
|
+
return (
|
|
28
|
+
<svg
|
|
29
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
30
|
+
width="24"
|
|
31
|
+
height="24"
|
|
32
|
+
viewBox="0 0 24 24"
|
|
33
|
+
fill="none"
|
|
34
|
+
stroke="currentColor"
|
|
35
|
+
strokeWidth="2"
|
|
36
|
+
strokeLinecap="round"
|
|
37
|
+
strokeLinejoin="round"
|
|
38
|
+
className={cn('shrink-0', className)}
|
|
39
|
+
aria-hidden
|
|
40
|
+
>
|
|
41
|
+
{children}
|
|
42
|
+
</svg>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** lucide x */
|
|
47
|
+
export function CloseIcon({ className }: { className?: string }) {
|
|
48
|
+
return (
|
|
49
|
+
<LucideSvg className={className}>
|
|
50
|
+
<path d="M18 6 6 18" />
|
|
51
|
+
<path d="m6 6 12 12" />
|
|
52
|
+
</LucideSvg>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** lucide ellipsis */
|
|
57
|
+
export function EllipsisIcon({ className }: { className?: string }) {
|
|
58
|
+
return (
|
|
59
|
+
<LucideSvg className={className}>
|
|
60
|
+
<circle
|
|
61
|
+
cx="12"
|
|
62
|
+
cy="12"
|
|
63
|
+
r="1"
|
|
64
|
+
/>
|
|
65
|
+
<circle
|
|
66
|
+
cx="19"
|
|
67
|
+
cy="12"
|
|
68
|
+
r="1"
|
|
69
|
+
/>
|
|
70
|
+
<circle
|
|
71
|
+
cx="5"
|
|
72
|
+
cy="12"
|
|
73
|
+
r="1"
|
|
74
|
+
/>
|
|
75
|
+
</LucideSvg>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Settings gear (same glyph as the account menu). */
|
|
80
|
+
export function SettingsIcon({ className }: { className?: string }) {
|
|
81
|
+
return (
|
|
82
|
+
<LucideSvg className={className}>
|
|
83
|
+
<circle
|
|
84
|
+
cx="12"
|
|
85
|
+
cy="12"
|
|
86
|
+
r="3"
|
|
87
|
+
/>
|
|
88
|
+
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z" />
|
|
89
|
+
</LucideSvg>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
32
93
|
/** Default nav icon when a navigation item has no custom icon. */
|
|
33
94
|
export function DefaultNavIcon({ className }: { className?: string }) {
|
|
34
95
|
return (
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { act } from 'react';
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
4
|
+
import { MemoryRouter } from 'react-router';
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import en from '../../../i18n/translations/en/common.json';
|
|
7
|
+
import fr from '../../../i18n/translations/fr/common.json';
|
|
8
|
+
import { SIDEBAR_PANEL_ID, SidebarProvider, SidebarTrigger } from '../../../components/ui/sidebar';
|
|
9
|
+
import { SidebarInner } from './SidebarInner';
|
|
10
|
+
|
|
11
|
+
const mobile = { value: false };
|
|
12
|
+
|
|
13
|
+
vi.mock('../../../hooks/use-mobile', () => ({ useIsMobile: () => mobile.value }));
|
|
14
|
+
vi.mock('../chrome/runtime', () => ({
|
|
15
|
+
useIsTauriClient: () => false,
|
|
16
|
+
useMacOverlayChrome: () => false,
|
|
17
|
+
useMacTrafficLights: () => false,
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('./NavigationContent', () => ({ NavigationContent: () => null }));
|
|
20
|
+
vi.mock('../../config/useConfig', () => ({ useConfig: () => ({ config: {} }) }));
|
|
21
|
+
vi.mock('../../auth/components/LoginButton', () => ({ LoginButton: () => null }));
|
|
22
|
+
vi.mock('react-i18next', () => ({
|
|
23
|
+
useTranslation: () => ({
|
|
24
|
+
t: (key: string) => {
|
|
25
|
+
const [group, leaf] = key.split('.') as [keyof typeof en, string];
|
|
26
|
+
return (en[group] as Record<string, string>)[leaf] ?? key;
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
32
|
+
|
|
33
|
+
let container: HTMLDivElement;
|
|
34
|
+
let root: Root;
|
|
35
|
+
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
mobile.value = false;
|
|
38
|
+
container = document.createElement('div');
|
|
39
|
+
document.body.appendChild(container);
|
|
40
|
+
root = createRoot(container);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
act(() => root.unmount());
|
|
45
|
+
container.remove();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function render(node: React.ReactNode, open = true) {
|
|
49
|
+
act(() => {
|
|
50
|
+
root.render(
|
|
51
|
+
<MemoryRouter>
|
|
52
|
+
<SidebarProvider defaultOpen={open}>{node}</SidebarProvider>
|
|
53
|
+
</MemoryRouter>,
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function q<T extends Element = HTMLElement>(scope: ParentNode, sel: string): T {
|
|
59
|
+
const el = scope.querySelector<T>(sel);
|
|
60
|
+
if (!el) throw new Error(`missing ${sel}`);
|
|
61
|
+
return el;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const inner = (
|
|
65
|
+
<SidebarInner
|
|
66
|
+
startNav={[]}
|
|
67
|
+
endItems={[]}
|
|
68
|
+
showAuthButton={false}
|
|
69
|
+
title="Acme"
|
|
70
|
+
appIcon="/icon.svg"
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
describe('SidebarTrigger', () => {
|
|
75
|
+
it('reports aria-expanded and aria-controls', () => {
|
|
76
|
+
render(<SidebarTrigger />);
|
|
77
|
+
const btn = q<HTMLButtonElement>(container, 'button');
|
|
78
|
+
expect(btn.getAttribute('aria-controls')).toBe(SIDEBAR_PANEL_ID);
|
|
79
|
+
expect(btn.getAttribute('aria-expanded')).toBe('true');
|
|
80
|
+
act(() => btn.click());
|
|
81
|
+
expect(btn.getAttribute('aria-expanded')).toBe('false');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('SidebarInner header', () => {
|
|
86
|
+
it('shows the app name next to the logo, with no border under the header', () => {
|
|
87
|
+
render(inner);
|
|
88
|
+
const header = q(container, '[data-sidebar="header"]');
|
|
89
|
+
expect(header.textContent).toContain('Acme');
|
|
90
|
+
expect(header.className).not.toContain('border-b');
|
|
91
|
+
expect(q(header, 'span.truncate').className).toContain(
|
|
92
|
+
'group-data-[collapsible=icon]:opacity-0',
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('mobile sheet header is 52px with a labelled close button', () => {
|
|
97
|
+
mobile.value = true;
|
|
98
|
+
render(inner);
|
|
99
|
+
const header = q(container, '[data-sidebar="header"]');
|
|
100
|
+
expect(header.style.height).toBe('52px');
|
|
101
|
+
const close = q(header, 'button');
|
|
102
|
+
expect(close.getAttribute('aria-label')).toBe('Close menu');
|
|
103
|
+
expect(header.textContent).toContain('Acme');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('has the close label in French', () => {
|
|
107
|
+
expect(fr.shellChrome.closeMenu).toBe('Fermer le menu');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
1
2
|
import type { NavigationItem, NavigationGroup, ThemeAsset } from '../../config/types';
|
|
2
3
|
import {
|
|
3
4
|
SidebarHeader,
|
|
@@ -6,19 +7,25 @@ import {
|
|
|
6
7
|
SidebarTrigger,
|
|
7
8
|
useSidebar,
|
|
8
9
|
} from '../../../components/ui/sidebar';
|
|
10
|
+
import { CloseIcon } from './SidebarIcons';
|
|
9
11
|
import { NavigationContent } from './NavigationContent';
|
|
10
12
|
import { LoginButton } from '../../auth/components/LoginButton';
|
|
11
13
|
import { cn } from '../../../lib/utils';
|
|
14
|
+
import { MacLightsSafeArea, MacStripSpacer } from '../chrome/MacStrip';
|
|
12
15
|
import { DesktopHistoryButtons } from '../chrome/DesktopHistoryButtons';
|
|
13
16
|
import { useIsTauriClient, useMacOverlayChrome, useMacTrafficLights } from '../chrome/runtime';
|
|
14
17
|
import {
|
|
15
18
|
DESKTOP_TITLEBAR_HEIGHT_PX,
|
|
16
19
|
DESKTOP_TITLEBAR_PAD_TOP_PX,
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
MAC_LIGHTS_SAFE_PX,
|
|
21
|
+
SHELL_HEADER_HEIGHT_PX,
|
|
22
|
+
SHELL_HEADER_PAD_TOP_PX,
|
|
19
23
|
} from '../chrome/constants';
|
|
20
24
|
import { AppBrandIcon } from '../branding/AppBrandIcon';
|
|
21
25
|
|
|
26
|
+
/** Mobile sheet brand row height (spec: 52px). */
|
|
27
|
+
const MOBILE_SHEET_HEADER_HEIGHT_PX = 52;
|
|
28
|
+
|
|
22
29
|
/** Reusable sidebar inner: header, main nav, footer. Used in desktop Sidebar and mobile Sheet. */
|
|
23
30
|
export function SidebarInner({
|
|
24
31
|
startNav,
|
|
@@ -36,19 +43,18 @@ export function SidebarInner({
|
|
|
36
43
|
/** Sidebar-inset: the column is padded, so the title row must break out to meet the lights. */
|
|
37
44
|
inset?: boolean;
|
|
38
45
|
}) {
|
|
46
|
+
const { t } = useTranslation();
|
|
39
47
|
const isTauriEnv = useIsTauriClient();
|
|
40
48
|
const overlay = useMacOverlayChrome();
|
|
41
49
|
const trafficLights = useMacTrafficLights();
|
|
42
|
-
const { state, isMobile } = useSidebar();
|
|
50
|
+
const { state, isMobile, setOpenMobile } = useSidebar();
|
|
43
51
|
const collapsed = state === 'collapsed' && !isMobile;
|
|
44
52
|
// Collapsed Tauri: Back + trigger live in CollapsedDesktopTitlebar instead.
|
|
45
53
|
const showCollapsedTopBar = overlay && collapsed;
|
|
46
54
|
const showOverlayHeader = overlay && !collapsed;
|
|
47
55
|
// Narrow Tauri window: sheet header must clear native traffic lights.
|
|
48
56
|
const mobileSheetHeader = isMobile && trafficLights;
|
|
49
|
-
const mobileTrafficInset = mobileSheetHeader
|
|
50
|
-
? MAC_TRAFFIC_LIGHTS_WIDTH_PX + MAC_TRAFFIC_LIGHTS_GAP_PX
|
|
51
|
-
: undefined;
|
|
57
|
+
const mobileTrafficInset = mobileSheetHeader ? MAC_LIGHTS_SAFE_PX : undefined;
|
|
52
58
|
// Keep trigger on the right whenever an icon is configured (even while collapsed),
|
|
53
59
|
// so it rides the sidebar width animation instead of jumping left.
|
|
54
60
|
const hasAppIcon = Boolean(appIcon);
|
|
@@ -59,7 +65,9 @@ export function SidebarInner({
|
|
|
59
65
|
title={title}
|
|
60
66
|
data-shellui-no-drag=""
|
|
61
67
|
className={cn(
|
|
62
|
-
'
|
|
68
|
+
'w-5 min-w-0 shrink-0 overflow-hidden transition-[width,opacity,margin] duration-200 ease-linear',
|
|
69
|
+
// macOS strip: the icon starts right at the 80px safe area edge.
|
|
70
|
+
showOverlayHeader ? 'ml-0' : 'ml-1',
|
|
63
71
|
// Sync with sidebar collapse; icon fades/shrinks while trigger stays put.
|
|
64
72
|
'group-data-[collapsible=icon]:pointer-events-none group-data-[collapsible=icon]:ml-0 group-data-[collapsible=icon]:w-0 group-data-[collapsible=icon]:opacity-0',
|
|
65
73
|
)}
|
|
@@ -81,20 +89,36 @@ export function SidebarInner({
|
|
|
81
89
|
<SidebarHeader
|
|
82
90
|
className={cn(
|
|
83
91
|
// Always pin to titlebar height — default SidebarHeader p-2 is taller on web.
|
|
84
|
-
'gap-0
|
|
92
|
+
'gap-0 select-none',
|
|
85
93
|
showOverlayHeader || mobileSheetHeader ? 'p-0' : 'px-2 py-0',
|
|
94
|
+
// Mobile sheet: brand row with a close button, 14px left like the mock.
|
|
95
|
+
isMobile && !mobileSheetHeader && 'pr-2 pl-3.5',
|
|
86
96
|
showCollapsedTopBar && 'hidden',
|
|
87
97
|
// Inset `p-3` sits this row 12px under the lights. Pull it to the window edge.
|
|
88
98
|
inset && showOverlayHeader && '-mt-3 -ml-3 w-[calc(100%+1.5rem)]',
|
|
99
|
+
// Web: same pull, so the brand row lines up with the plain sidebar header.
|
|
100
|
+
inset && !showOverlayHeader && !isMobile && '-mt-3 -ml-3 w-[calc(100%+0.75rem)] pl-5',
|
|
89
101
|
)}
|
|
90
102
|
style={{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
103
|
+
// macOS: the header is the 32px strip. Web, phones and caption bar hosts: 42px.
|
|
104
|
+
height: showOverlayHeader
|
|
105
|
+
? DESKTOP_TITLEBAR_HEIGHT_PX
|
|
106
|
+
: isMobile
|
|
107
|
+
? MOBILE_SHEET_HEADER_HEIGHT_PX
|
|
108
|
+
: SHELL_HEADER_HEIGHT_PX,
|
|
109
|
+
paddingTop: showOverlayHeader
|
|
110
|
+
? DESKTOP_TITLEBAR_PAD_TOP_PX
|
|
111
|
+
: isMobile
|
|
112
|
+
? 0
|
|
113
|
+
: SHELL_HEADER_PAD_TOP_PX,
|
|
94
114
|
...(mobileSheetHeader ? { paddingLeft: mobileTrafficInset } : {}),
|
|
95
115
|
}}
|
|
96
116
|
{...(showOverlayHeader
|
|
97
|
-
? {
|
|
117
|
+
? {
|
|
118
|
+
'data-shellui-drag-region': '',
|
|
119
|
+
'data-tauri-drag-region': '',
|
|
120
|
+
'data-shellui-mac-strip': '',
|
|
121
|
+
}
|
|
98
122
|
: {})}
|
|
99
123
|
>
|
|
100
124
|
{showOverlayHeader ? (
|
|
@@ -103,65 +127,92 @@ export function SidebarInner({
|
|
|
103
127
|
data-shellui-drag-region=""
|
|
104
128
|
data-tauri-drag-region=""
|
|
105
129
|
>
|
|
106
|
-
{
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
style={{ width: MAC_TRAFFIC_LIGHTS_WIDTH_PX }}
|
|
110
|
-
aria-hidden
|
|
111
|
-
/>
|
|
112
|
-
) : null}
|
|
113
|
-
<div
|
|
114
|
-
className="flex h-full min-w-0 flex-1 items-center gap-1"
|
|
115
|
-
style={{
|
|
116
|
-
paddingLeft: trafficLights ? MAC_TRAFFIC_LIGHTS_GAP_PX : 8,
|
|
117
|
-
}}
|
|
118
|
-
>
|
|
130
|
+
{/* 80px drag-only safe area next to the lights (12px in native fullscreen). */}
|
|
131
|
+
<MacLightsSafeArea />
|
|
132
|
+
<div className="flex h-full min-w-0 flex-1 items-center gap-1">
|
|
119
133
|
{hasAppIcon ? brandIcon : null}
|
|
120
134
|
{!hasAppIcon ? (
|
|
121
135
|
<SidebarTrigger
|
|
122
136
|
data-shellui-no-drag=""
|
|
123
|
-
className="size-
|
|
137
|
+
className="size-6 shrink-0 touch-manipulation"
|
|
138
|
+
/>
|
|
139
|
+
) : null}
|
|
140
|
+
<MacStripSpacer className="min-w-[8px]" />
|
|
141
|
+
{isTauriEnv ? (
|
|
142
|
+
<DesktopHistoryButtons
|
|
143
|
+
strip
|
|
144
|
+
className="self-center"
|
|
124
145
|
/>
|
|
125
146
|
) : null}
|
|
126
|
-
<div
|
|
127
|
-
aria-hidden
|
|
128
|
-
data-shellui-drag-region=""
|
|
129
|
-
data-tauri-drag-region=""
|
|
130
|
-
className="min-h-full min-w-[8px] flex-1 self-stretch"
|
|
131
|
-
/>
|
|
132
|
-
{isTauriEnv ? <DesktopHistoryButtons className="self-center" /> : null}
|
|
133
147
|
{hasAppIcon ? (
|
|
134
148
|
<SidebarTrigger
|
|
135
149
|
data-shellui-no-drag=""
|
|
136
|
-
className="size-
|
|
150
|
+
className="size-6 shrink-0 touch-manipulation"
|
|
137
151
|
/>
|
|
138
152
|
) : null}
|
|
139
153
|
{hasAppIcon ? trailingInset : null}
|
|
140
154
|
</div>
|
|
141
155
|
</div>
|
|
156
|
+
) : isMobile ? (
|
|
157
|
+
<div className="flex h-full w-full items-center gap-1.5">
|
|
158
|
+
{brandIcon}
|
|
159
|
+
<span
|
|
160
|
+
aria-hidden
|
|
161
|
+
className="min-w-0 flex-1 truncate text-sm font-semibold text-sidebar-foreground"
|
|
162
|
+
>
|
|
163
|
+
{title}
|
|
164
|
+
</span>
|
|
165
|
+
<button
|
|
166
|
+
type="button"
|
|
167
|
+
aria-label={t('shellChrome.closeMenu')}
|
|
168
|
+
onClick={() => setOpenMobile(false)}
|
|
169
|
+
className="inline-flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-[var(--shellui-r-row)] text-[var(--shellui-nav-icon)] hover:bg-[var(--shellui-nav-hover)] hover:text-sidebar-foreground focus-visible:outline-2 focus-visible:outline-[var(--sidebar-ring)]"
|
|
170
|
+
>
|
|
171
|
+
<CloseIcon className="size-5" />
|
|
172
|
+
</button>
|
|
173
|
+
</div>
|
|
142
174
|
) : (
|
|
143
175
|
<div className={cn('flex h-full w-full items-center', hasAppIcon ? 'gap-0' : 'gap-0.5')}>
|
|
144
176
|
{brandIcon}
|
|
145
177
|
{hasAppIcon ? (
|
|
146
178
|
<div
|
|
147
179
|
aria-hidden
|
|
148
|
-
className="min-w-0 flex-1"
|
|
149
|
-
|
|
180
|
+
className="min-w-0 flex-1 overflow-hidden"
|
|
181
|
+
>
|
|
182
|
+
{title ? (
|
|
183
|
+
<span className="block truncate pl-2 text-sm font-semibold text-sidebar-foreground transition-opacity duration-200 ease-linear group-data-[collapsible=icon]:opacity-0 motion-reduce:transition-none">
|
|
184
|
+
{title}
|
|
185
|
+
</span>
|
|
186
|
+
) : null}
|
|
187
|
+
</div>
|
|
150
188
|
) : null}
|
|
151
189
|
<SidebarTrigger className="size-7 shrink-0 touch-manipulation" />
|
|
152
190
|
{trailingInset}
|
|
153
191
|
</div>
|
|
154
192
|
)}
|
|
155
193
|
</SidebarHeader>
|
|
156
|
-
<SidebarContent className="gap-
|
|
157
|
-
<
|
|
194
|
+
<SidebarContent className="shellui-nav gap-0">
|
|
195
|
+
<nav
|
|
196
|
+
aria-label={t('shellChrome.mainNav')}
|
|
197
|
+
className="flex min-w-0 flex-col gap-0.5 py-2"
|
|
198
|
+
>
|
|
199
|
+
<NavigationContent navigation={startNav} />
|
|
200
|
+
</nav>
|
|
158
201
|
</SidebarContent>
|
|
159
|
-
<SidebarFooter
|
|
202
|
+
<SidebarFooter
|
|
203
|
+
data-shellui-nav-footer=""
|
|
204
|
+
className="shellui-nav gap-0 border-t border-sidebar-border px-0 pt-0 pb-[max(0.5rem,var(--shellui-safe-area-bottom))]"
|
|
205
|
+
>
|
|
160
206
|
{(endItems.length > 0 || showAuthButton) && (
|
|
161
|
-
<
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
207
|
+
<nav
|
|
208
|
+
aria-label={t('shellChrome.accountNav')}
|
|
209
|
+
className="flex min-w-0 flex-col gap-0.5 pb-1"
|
|
210
|
+
>
|
|
211
|
+
<NavigationContent
|
|
212
|
+
navigation={endItems}
|
|
213
|
+
trailing={showAuthButton ? <LoginButton variant="sidebar" /> : undefined}
|
|
214
|
+
/>
|
|
215
|
+
</nav>
|
|
165
216
|
)}
|
|
166
217
|
</SidebarFooter>
|
|
167
218
|
</>
|