@shellui/core 0.7.0-alpha.10 → 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/src/components/ui/drawer.tsx +47 -30
- package/src/components/ui/sheet.tsx +18 -12
- package/src/components/ui/sidebar.tsx +14 -6
- package/src/components/ui/tooltip.tsx +4 -2
- 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/chromeActions/ChromeActionsHost.tsx +5 -1
- 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 +53 -81
- 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 +1 -1
- package/src/features/layouts/chrome/constants.ts +3 -0
- package/src/features/layouts/chrome/viewport.ts +11 -4
- package/src/features/layouts/floating/FloatingBottomDock.tsx +66 -25
- package/src/features/layouts/floating/FloatingLayout.tsx +1 -0
- package/src/features/layouts/floating/FloatingSidebar.tsx +26 -8
- package/src/features/layouts/floating/moreSections.spec.ts +28 -0
- package/src/features/layouts/floating/moreSections.ts +31 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.spec.tsx +68 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +10 -1
- package/src/features/layouts/sidebar/NavigationContent.tsx +4 -4
- package/src/features/layouts/sidebar/SidebarIcons.tsx +67 -0
- package/src/features/layouts/sidebar/SidebarInner.spec.tsx +109 -0
- package/src/features/layouts/sidebar/SidebarInner.tsx +49 -9
- package/src/features/layouts/sidebar/SidebarLayout.tsx +23 -13
- package/src/features/layouts/windows/WindowsLayout.tsx +75 -44
- package/src/features/layouts/windows/deskDots.spec.ts +6 -4
- package/src/features/layouts/windows/deskDots.ts +8 -8
- 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/i18n/translations/en/common.json +1 -0
- package/src/i18n/translations/fr/common.json +1 -0
- package/src/index.css +211 -32
- 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
|
@@ -1464,9 +1464,12 @@ export function ChromeActionsHost() {
|
|
|
1464
1464
|
export function WindowTitleBarActions({
|
|
1465
1465
|
frameUuid,
|
|
1466
1466
|
fallbackTitle,
|
|
1467
|
+
centerTitle = false,
|
|
1467
1468
|
}: {
|
|
1468
1469
|
frameUuid: string | null;
|
|
1469
1470
|
fallbackTitle?: string;
|
|
1471
|
+
/** Phone header: centred 15px / 600 page title. */
|
|
1472
|
+
centerTitle?: boolean;
|
|
1470
1473
|
}) {
|
|
1471
1474
|
const all = useChromeActionsSnapshot();
|
|
1472
1475
|
const actions = useMemo(
|
|
@@ -1502,7 +1505,8 @@ export function WindowTitleBarActions({
|
|
|
1502
1505
|
return (
|
|
1503
1506
|
<span
|
|
1504
1507
|
className={cn(
|
|
1505
|
-
'min-w-0 flex-1 truncate
|
|
1508
|
+
'min-w-0 flex-1 truncate',
|
|
1509
|
+
centerTitle ? 'text-center text-[15px] font-semibold' : 'text-sm font-medium',
|
|
1506
1510
|
chromeActionsFadeClass,
|
|
1507
1511
|
'opacity-100',
|
|
1508
1512
|
)}
|
|
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
4
4
|
import { shellui } from '@shellui/sdk';
|
|
5
5
|
import type { NavigationItem } from '../config/types';
|
|
6
6
|
import { Drawer, DrawerContent, DrawerTitle, DrawerDescription } from '../../components/ui/drawer';
|
|
7
|
+
import type { WithFadeFromProps, WithoutFadeFromProps } from 'vaul';
|
|
7
8
|
import { ContentView } from '../../components/ContentView';
|
|
8
9
|
import { useModal } from '../modal/ModalContext';
|
|
9
10
|
import { useDrawer } from '../drawer/DrawerContext';
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
resolveDrawerSize,
|
|
24
25
|
resolveDrawerSizeForViewport,
|
|
25
26
|
resolveEffectiveDrawerPosition,
|
|
27
|
+
resolveDrawerChrome,
|
|
26
28
|
isDynamicSizing,
|
|
27
29
|
SHEET_EXPANDED_HEIGHT_CSS,
|
|
28
30
|
} from '../overlays/overlaySize';
|
|
@@ -33,6 +35,8 @@ import { OverlayDrawerPendingBar } from '../overlays/OverlayDrawerPendingBar';
|
|
|
33
35
|
|
|
34
36
|
/** Matches --shellui-overlay-max-height in index.css */
|
|
35
37
|
const OVERLAY_MAX_H = 'var(--shellui-overlay-max-height)';
|
|
38
|
+
/** Matches --shellui-drawer-max-height: the viewport minus the floating offsets. */
|
|
39
|
+
const DRAWER_MAX_H = 'var(--shellui-drawer-max-height)';
|
|
36
40
|
|
|
37
41
|
interface OverlayShellProps {
|
|
38
42
|
children: ReactNode;
|
|
@@ -228,11 +232,16 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
|
|
|
228
232
|
usedFallback: modalSizeFallback,
|
|
229
233
|
wasClamped: modalWasClamped,
|
|
230
234
|
} = useOverlayReportedSize(modalContentSized, isOpen && !isDrawerOpen);
|
|
235
|
+
// Phone sheets grow up to the drawer max height (CSS), so the report is not cut at 92%.
|
|
231
236
|
const {
|
|
232
237
|
reported: drawerReported,
|
|
233
238
|
usedFallback: drawerSizeFallback,
|
|
234
239
|
wasClamped: drawerWasClamped,
|
|
235
|
-
} = useOverlayReportedSize(
|
|
240
|
+
} = useOverlayReportedSize(
|
|
241
|
+
drawerSize.contentSized || drawerDynamic,
|
|
242
|
+
isDrawerOpen,
|
|
243
|
+
isMobile ? 1 : undefined,
|
|
244
|
+
);
|
|
236
245
|
|
|
237
246
|
const modalPending = isOpen && modalContentSized && !modalReported;
|
|
238
247
|
const drawerPending =
|
|
@@ -351,6 +360,10 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
|
|
|
351
360
|
}),
|
|
352
361
|
};
|
|
353
362
|
|
|
363
|
+
// Phone sheet from an app that never reports its size: use the requested preset.
|
|
364
|
+
const drawerPhoneFallback =
|
|
365
|
+
drawerSizeFallback && drawerSize.fallbackHeight ? drawerSize.fallbackHeight : null;
|
|
366
|
+
|
|
354
367
|
const drawerContentStyle: CSSProperties = {
|
|
355
368
|
...drawerSize.style,
|
|
356
369
|
...(drawerSize.contentSized || drawerDynamic ? { transition: 'none' } : {}),
|
|
@@ -366,17 +379,19 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
|
|
|
366
379
|
maxWidth: drawerPendingPx,
|
|
367
380
|
minWidth: drawerPendingPx,
|
|
368
381
|
}
|
|
369
|
-
:
|
|
370
|
-
?
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
382
|
+
: drawerPhoneFallback
|
|
383
|
+
? { height: drawerPhoneFallback, maxHeight: DRAWER_MAX_H }
|
|
384
|
+
: drawerReported
|
|
385
|
+
? drawerIsVertical
|
|
386
|
+
? {
|
|
387
|
+
height: drawerReported.height,
|
|
388
|
+
maxHeight: `min(${drawerReported.height}px, ${DRAWER_MAX_H})`,
|
|
389
|
+
}
|
|
390
|
+
: {
|
|
391
|
+
width: drawerReported.width ?? drawerReported.height,
|
|
392
|
+
maxWidth: `min(${drawerReported.width ?? drawerReported.height}px, 92vw)`,
|
|
393
|
+
}
|
|
394
|
+
: {}),
|
|
380
395
|
};
|
|
381
396
|
|
|
382
397
|
const handleModalOpenChange = (open: boolean) => {
|
|
@@ -397,22 +412,28 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
|
|
|
397
412
|
const drawerDesktopResizable =
|
|
398
413
|
!drawerPending && !isMobile && !drawerDynamic && drawerOptions?.resizable !== false;
|
|
399
414
|
|
|
400
|
-
//
|
|
401
|
-
|
|
415
|
+
// Phones: always a bottom sheet with a drag handle. Desktop: requested edge and options.
|
|
416
|
+
const drawerChrome = resolveDrawerChrome({
|
|
417
|
+
position: drawerPosition,
|
|
418
|
+
isMobile,
|
|
419
|
+
dismiss: drawerDismiss,
|
|
420
|
+
pending: drawerPending,
|
|
421
|
+
desktopResizable: drawerDesktopResizable,
|
|
422
|
+
contentSized: drawerSize.contentSized || drawerDynamic,
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// Desktop bottom sheets: snap between the configured height and near-full so drag-up
|
|
426
|
+
// expands. Phones never snap (content-height sheets). Skip when desktop free-edge
|
|
427
|
+
// resize is active (those compete with Vaul snaps).
|
|
402
428
|
const drawerSnapPoints = useMemo(() => {
|
|
403
|
-
if (
|
|
404
|
-
if (!drawerDismiss.showDragHandle || !drawerDismiss.dismissible) return undefined;
|
|
405
|
-
if (drawerPending || drawerDesktopResizable) return undefined;
|
|
429
|
+
if (!drawerChrome.allowSnapPoints) return undefined;
|
|
406
430
|
return resolveBottomSheetSnapPoints(drawerOptions, drawerReported?.height ?? null) ?? undefined;
|
|
407
|
-
}, [
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
drawerOptions,
|
|
414
|
-
drawerReported?.height,
|
|
415
|
-
]);
|
|
431
|
+
}, [drawerChrome.allowSnapPoints, drawerOptions, drawerReported?.height]);
|
|
432
|
+
|
|
433
|
+
// Floating sheet: show the scrim from the first snap, not only when expanded.
|
|
434
|
+
const drawerSnapProps: WithFadeFromProps | WithoutFadeFromProps = drawerSnapPoints
|
|
435
|
+
? { snapPoints: drawerSnapPoints, fadeFromIndex: 0 }
|
|
436
|
+
: {};
|
|
416
437
|
|
|
417
438
|
const [drawerActiveSnap, setDrawerActiveSnap] = useState<number | string | null>(null);
|
|
418
439
|
|
|
@@ -482,7 +503,7 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
|
|
|
482
503
|
onOpenChange={handleDrawerOpenChange}
|
|
483
504
|
direction={effectiveDrawerPosition}
|
|
484
505
|
dismissible={drawerDismiss.dismissible}
|
|
485
|
-
|
|
506
|
+
{...drawerSnapProps}
|
|
486
507
|
activeSnapPoint={drawerSnapPoints ? drawerActiveSnap : undefined}
|
|
487
508
|
setActiveSnapPoint={drawerSnapPoints ? setDrawerActiveSnap : undefined}
|
|
488
509
|
>
|
|
@@ -492,13 +513,15 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
|
|
|
492
513
|
size={
|
|
493
514
|
drawerSnapPoints
|
|
494
515
|
? SHEET_EXPANDED_HEIGHT_CSS
|
|
495
|
-
:
|
|
496
|
-
?
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
:
|
|
516
|
+
: drawerPhoneFallback
|
|
517
|
+
? drawerPhoneFallback
|
|
518
|
+
: drawerReported
|
|
519
|
+
? drawerIsVertical
|
|
520
|
+
? `${drawerReported.height}px`
|
|
521
|
+
: `${drawerReported.width ?? drawerReported.height}px`
|
|
522
|
+
: drawerPending
|
|
523
|
+
? `${drawerPendingPx}px`
|
|
524
|
+
: drawerSize.drawerSize
|
|
502
525
|
}
|
|
503
526
|
style={
|
|
504
527
|
drawerSnapPoints
|
|
@@ -511,12 +534,7 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
|
|
|
511
534
|
}
|
|
512
535
|
className={drawerSize.className}
|
|
513
536
|
showCloseButton={!drawerPending && drawerDismiss.showCloseButton}
|
|
514
|
-
showDragHandle={
|
|
515
|
-
!drawerPending &&
|
|
516
|
-
drawerIsVertical &&
|
|
517
|
-
drawerDismiss.showDragHandle &&
|
|
518
|
-
drawerDismiss.dismissible
|
|
519
|
-
}
|
|
537
|
+
showDragHandle={drawerChrome.showDragHandle}
|
|
520
538
|
closeOnOverlayClick={drawerDismiss.closeOnOverlayClick}
|
|
521
539
|
resizable={drawerDesktopResizable}
|
|
522
540
|
>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { act } from 'react';
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import type { NavigationItem } from '../../config/types';
|
|
6
|
+
import { AppBarItemIcon } from './AppBarItemIcon';
|
|
7
|
+
|
|
8
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
9
|
+
|
|
10
|
+
let container: HTMLDivElement;
|
|
11
|
+
let root: Root;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
container = document.createElement('div');
|
|
15
|
+
document.body.appendChild(container);
|
|
16
|
+
root = createRoot(container);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
act(() => root.unmount());
|
|
21
|
+
container.remove();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function render(item: Partial<NavigationItem>) {
|
|
25
|
+
act(() =>
|
|
26
|
+
root.render(<AppBarItemIcon item={{ path: 'x', url: '/x', label: 'Docs', ...item }} />),
|
|
27
|
+
);
|
|
28
|
+
return container.firstElementChild as HTMLElement;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('AppBarItemIcon', () => {
|
|
32
|
+
it('renders a plain 16px icon with no muted tile', () => {
|
|
33
|
+
const el = render({ icon: '/icons/book.svg' });
|
|
34
|
+
expect(el.className).toContain('size-4');
|
|
35
|
+
expect(el.className).not.toContain('bg-muted');
|
|
36
|
+
expect(el.className).not.toContain('rounded-md');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('falls back to the default 16px glyph instead of a letter tile', () => {
|
|
40
|
+
const el = render({});
|
|
41
|
+
expect(el.tagName.toLowerCase()).toBe('svg');
|
|
42
|
+
expect(el.getAttribute('class')).toContain('size-4');
|
|
43
|
+
expect(container.textContent).toBe('');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NavigationItem } from '../../config/types';
|
|
2
|
+
import { NavIcon } from '../sidebar/SidebarIcons';
|
|
3
|
+
import { getExternalFaviconUrl } from '../sidebar/sidebarUtils';
|
|
4
|
+
|
|
5
|
+
function itemIconSrc(item: NavigationItem): string | null {
|
|
6
|
+
if (item.icon) return item.icon;
|
|
7
|
+
if (item.openIn === 'external') return getExternalFaviconUrl(item.url);
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Plain 16px icon for start-nav links and their menus (no tile, like the mock). */
|
|
12
|
+
export function AppBarItemIcon({ item }: { item: NavigationItem }) {
|
|
13
|
+
return (
|
|
14
|
+
<NavIcon
|
|
15
|
+
src={itemIconSrc(item)}
|
|
16
|
+
className="size-4"
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -43,7 +43,9 @@ import { useIsMobile } from '../../../hooks/use-mobile';
|
|
|
43
43
|
import { LoginButton } from '../../auth/components/LoginButton';
|
|
44
44
|
import { useAuth } from '../../auth/hooks/useAuth';
|
|
45
45
|
import { useSettings } from '../../settings/hooks/useSettings';
|
|
46
|
-
import { NavIcon } from '../sidebar/SidebarIcons';
|
|
46
|
+
import { EllipsisIcon, NavIcon } from '../sidebar/SidebarIcons';
|
|
47
|
+
import { pickVisibleEntries } from './appBarOverflow';
|
|
48
|
+
import { AppBarItemIcon } from './AppBarItemIcon';
|
|
47
49
|
import { getExternalFaviconUrl } from '../sidebar/sidebarUtils';
|
|
48
50
|
import { DesktopHistoryButtons } from '../chrome/DesktopHistoryButtons';
|
|
49
51
|
import {
|
|
@@ -89,7 +91,7 @@ type NavEntry =
|
|
|
89
91
|
|
|
90
92
|
const NAV_GAP_PX = 4;
|
|
91
93
|
/** Reserved width guess before More is measured; kept close to the real control. */
|
|
92
|
-
const MORE_FALLBACK_PX =
|
|
94
|
+
const MORE_FALLBACK_PX = 36;
|
|
93
95
|
|
|
94
96
|
function resolveLocalizedLabel(
|
|
95
97
|
value: string | { en: string; fr: string; [key: string]: string },
|
|
@@ -210,39 +212,6 @@ function CaretDownIcon({ className }: { className?: string }) {
|
|
|
210
212
|
);
|
|
211
213
|
}
|
|
212
214
|
|
|
213
|
-
function itemIconSrc(item: NavigationItem): string | null {
|
|
214
|
-
if (item.icon) return item.icon;
|
|
215
|
-
if (item.openIn === 'external') return getExternalFaviconUrl(item.url);
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/** Compact icon (or first-letter fallback) for start-nav links. */
|
|
220
|
-
function AppBarItemIcon({ item, label }: { item: NavigationItem; label: string }) {
|
|
221
|
-
const iconSrc = itemIconSrc(item);
|
|
222
|
-
const firstLetter = label ? label.charAt(0).toUpperCase() : '?';
|
|
223
|
-
if (iconSrc) {
|
|
224
|
-
return (
|
|
225
|
-
<span
|
|
226
|
-
className="flex size-5 shrink-0 items-center justify-center rounded-md bg-muted/60 p-0.5"
|
|
227
|
-
aria-hidden
|
|
228
|
-
>
|
|
229
|
-
<NavIcon
|
|
230
|
-
src={iconSrc}
|
|
231
|
-
className="size-3"
|
|
232
|
-
/>
|
|
233
|
-
</span>
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
return (
|
|
237
|
-
<span
|
|
238
|
-
className="flex size-5 shrink-0 items-center justify-center rounded-md bg-muted p-0.5 text-[9px] font-semibold leading-none text-muted-foreground"
|
|
239
|
-
aria-hidden
|
|
240
|
-
>
|
|
241
|
-
{firstLetter}
|
|
242
|
-
</span>
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
215
|
const navTriggerClass = (active: boolean) =>
|
|
247
216
|
cn(
|
|
248
217
|
// h-8 fills the taller app-bar after the top pad. Colours, hover and the
|
|
@@ -267,10 +236,7 @@ function AppBarNavLink({
|
|
|
267
236
|
const className = navTriggerClass(isActive);
|
|
268
237
|
const content = (
|
|
269
238
|
<>
|
|
270
|
-
<AppBarItemIcon
|
|
271
|
-
item={item}
|
|
272
|
-
label={label}
|
|
273
|
-
/>
|
|
239
|
+
<AppBarItemIcon item={item} />
|
|
274
240
|
<span className="truncate">{label}</span>
|
|
275
241
|
</>
|
|
276
242
|
);
|
|
@@ -318,10 +284,7 @@ function AppBarNavMenuItem({
|
|
|
318
284
|
const itemClass = cn('shellui-appbar-menu-item gap-2 text-sm', isActive && 'is-active');
|
|
319
285
|
const content = (
|
|
320
286
|
<>
|
|
321
|
-
<AppBarItemIcon
|
|
322
|
-
item={item}
|
|
323
|
-
label={label}
|
|
324
|
-
/>
|
|
287
|
+
<AppBarItemIcon item={item} />
|
|
325
288
|
<span className="truncate">{label}</span>
|
|
326
289
|
</>
|
|
327
290
|
);
|
|
@@ -443,9 +406,9 @@ function AppBarNavMore({
|
|
|
443
406
|
aria-label={t('desktopChrome.more')}
|
|
444
407
|
aria-haspopup="menu"
|
|
445
408
|
aria-expanded={open}
|
|
409
|
+
data-shellui-appbar-more=""
|
|
446
410
|
>
|
|
447
|
-
<
|
|
448
|
-
<CaretDownIcon className="size-3.5 shrink-0 opacity-70" />
|
|
411
|
+
<EllipsisIcon className="size-4" />
|
|
449
412
|
</Button>
|
|
450
413
|
</DropdownMenuTrigger>
|
|
451
414
|
<DropdownMenuContent
|
|
@@ -511,7 +474,7 @@ function AppBarNavMeasureChip({
|
|
|
511
474
|
>
|
|
512
475
|
{withIcon ? (
|
|
513
476
|
<span
|
|
514
|
-
className="size-
|
|
477
|
+
className="size-4 shrink-0"
|
|
515
478
|
aria-hidden
|
|
516
479
|
/>
|
|
517
480
|
) : null}
|
|
@@ -541,7 +504,17 @@ function AppBarNav({
|
|
|
541
504
|
const containerRef = useRef<HTMLElement | null>(null);
|
|
542
505
|
const measureRefs = useRef<(HTMLElement | null)[]>([]);
|
|
543
506
|
const moreMeasureRef = useRef<HTMLElement | null>(null);
|
|
544
|
-
const
|
|
507
|
+
const allIndices = useMemo(() => entries.map((_, i) => i), [entries]);
|
|
508
|
+
const [visibleIndices, setVisibleIndices] = useState<number[]>(allIndices);
|
|
509
|
+
const activeIndex = useMemo(
|
|
510
|
+
() =>
|
|
511
|
+
entries.findIndex((entry) =>
|
|
512
|
+
entry.type === 'link'
|
|
513
|
+
? navItemIsActive(entry.item, activePathPrefix)
|
|
514
|
+
: categoryIsActive(entry.items, activePathPrefix),
|
|
515
|
+
),
|
|
516
|
+
[entries, activePathPrefix],
|
|
517
|
+
);
|
|
545
518
|
|
|
546
519
|
const setMeasureRef = useCallback((index: number, node: HTMLElement | null) => {
|
|
547
520
|
measureRefs.current[index] = node;
|
|
@@ -550,37 +523,25 @@ function AppBarNav({
|
|
|
550
523
|
const recompute = useCallback(() => {
|
|
551
524
|
const container = containerRef.current;
|
|
552
525
|
if (!container || entries.length === 0) {
|
|
553
|
-
|
|
526
|
+
setVisibleIndices(allIndices);
|
|
554
527
|
return;
|
|
555
528
|
}
|
|
556
529
|
|
|
557
|
-
const available = container.clientWidth;
|
|
558
530
|
const widths = entries.map((_, i) => measureRefs.current[i]?.offsetWidth ?? 0);
|
|
559
531
|
if (widths.some((w) => w <= 0)) return;
|
|
560
532
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
let count = 0;
|
|
574
|
-
for (let i = 0; i < widths.length; i++) {
|
|
575
|
-
const gap = count > 0 ? NAV_GAP_PX : 0;
|
|
576
|
-
const nextUsed = used + gap + widths[i];
|
|
577
|
-
const needed = nextUsed + NAV_GAP_PX + moreWidth;
|
|
578
|
-
if (needed > available) break;
|
|
579
|
-
used = nextUsed;
|
|
580
|
-
count += 1;
|
|
581
|
-
}
|
|
582
|
-
setVisibleCount(count);
|
|
583
|
-
}, [entries]);
|
|
533
|
+
// The active entry never hides inside More (phones especially).
|
|
534
|
+
const next = pickVisibleEntries({
|
|
535
|
+
widths,
|
|
536
|
+
available: container.clientWidth,
|
|
537
|
+
moreWidth: moreMeasureRef.current?.offsetWidth || MORE_FALLBACK_PX,
|
|
538
|
+
gap: NAV_GAP_PX,
|
|
539
|
+
activeIndex,
|
|
540
|
+
});
|
|
541
|
+
setVisibleIndices((prev) =>
|
|
542
|
+
prev.length === next.length && prev.every((v, k) => v === next[k]) ? prev : next,
|
|
543
|
+
);
|
|
544
|
+
}, [entries, allIndices, activeIndex]);
|
|
584
545
|
|
|
585
546
|
useLayoutEffect(() => {
|
|
586
547
|
measureRefs.current = measureRefs.current.slice(0, entries.length);
|
|
@@ -595,16 +556,17 @@ function AppBarNav({
|
|
|
595
556
|
return () => observer.disconnect();
|
|
596
557
|
}, [recompute]);
|
|
597
558
|
|
|
598
|
-
const
|
|
599
|
-
const
|
|
559
|
+
const visibleSet = new Set(visibleIndices);
|
|
560
|
+
const visible = entries.filter((_, i) => visibleSet.has(i));
|
|
561
|
+
const overflow = entries.filter((_, i) => !visibleSet.has(i));
|
|
600
562
|
const showMore = overflow.length > 0;
|
|
601
|
-
const moreLabel = t('desktopChrome.more');
|
|
602
563
|
|
|
603
564
|
return (
|
|
604
565
|
<nav
|
|
605
566
|
ref={containerRef}
|
|
606
567
|
aria-label={t('shellChrome.mainNav')}
|
|
607
|
-
|
|
568
|
+
// overflow-x clip only, so the active underline can reach the bar's bottom border.
|
|
569
|
+
className="relative flex min-w-0 flex-1 items-center gap-0.5 overflow-x-clip overflow-y-visible"
|
|
608
570
|
>
|
|
609
571
|
{/* Off-screen width probes (no DropdownMenu — avoids portal noise). */}
|
|
610
572
|
<div
|
|
@@ -633,13 +595,14 @@ function AppBarNav({
|
|
|
633
595
|
/>
|
|
634
596
|
);
|
|
635
597
|
})}
|
|
636
|
-
<
|
|
637
|
-
|
|
638
|
-
withCaret
|
|
639
|
-
measureRef={(node) => {
|
|
598
|
+
<span
|
|
599
|
+
ref={(node) => {
|
|
640
600
|
moreMeasureRef.current = node;
|
|
641
601
|
}}
|
|
642
|
-
|
|
602
|
+
className={cn(navTriggerClass(false), 'whitespace-nowrap')}
|
|
603
|
+
>
|
|
604
|
+
<EllipsisIcon className="size-4" />
|
|
605
|
+
</span>
|
|
643
606
|
</div>
|
|
644
607
|
|
|
645
608
|
{visible.map((entry) => {
|
|
@@ -1032,6 +995,15 @@ export function AppBarLayout({
|
|
|
1032
995
|
imgClassName={cn('app-bar-app-icon', macStrip ? 'size-5' : 'size-6')}
|
|
1033
996
|
/>
|
|
1034
997
|
) : null}
|
|
998
|
+
{appIcon && title && !isTauriRuntime ? (
|
|
999
|
+
<span
|
|
1000
|
+
aria-hidden
|
|
1001
|
+
data-shellui-appbar-brand-name=""
|
|
1002
|
+
className="mr-2 max-w-48 shrink-0 truncate text-sm font-semibold"
|
|
1003
|
+
>
|
|
1004
|
+
{title}
|
|
1005
|
+
</span>
|
|
1006
|
+
) : null}
|
|
1035
1007
|
|
|
1036
1008
|
{hasStartNav ? (
|
|
1037
1009
|
<AppBarNav
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { pickVisibleEntries } from './appBarOverflow';
|
|
3
|
+
|
|
4
|
+
const base = { widths: [60, 60, 60, 60, 60], moreWidth: 32, gap: 4 };
|
|
5
|
+
|
|
6
|
+
describe('pickVisibleEntries', () => {
|
|
7
|
+
it('shows everything when it fits', () => {
|
|
8
|
+
expect(pickVisibleEntries({ ...base, available: 400 })).toEqual([0, 1, 2, 3, 4]);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('fills in order and leaves room for More', () => {
|
|
12
|
+
// budget 200 - 4 - 32 = 164: two 60px items plus a gap.
|
|
13
|
+
expect(pickVisibleEntries({ ...base, available: 200 })).toEqual([0, 1]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('keeps the active entry visible when it would overflow', () => {
|
|
17
|
+
expect(pickVisibleEntries({ ...base, available: 200, activeIndex: 4 })).toEqual([0, 4]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('keeps order when the active entry already fits', () => {
|
|
21
|
+
expect(pickVisibleEntries({ ...base, available: 200, activeIndex: 1 })).toEqual([0, 1]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('returns nothing when even the active entry does not fit', () => {
|
|
25
|
+
expect(pickVisibleEntries({ ...base, available: 60, activeIndex: 2 })).toEqual([]);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pick which app-bar entries stay in the bar; the rest go into More.
|
|
3
|
+
* The active entry always stays visible (it is placed first in the budget),
|
|
4
|
+
* then the others fill the remaining width in their configured order.
|
|
5
|
+
*
|
|
6
|
+
* @returns sorted indices of the visible entries.
|
|
7
|
+
*/
|
|
8
|
+
export function pickVisibleEntries({
|
|
9
|
+
widths,
|
|
10
|
+
available,
|
|
11
|
+
moreWidth,
|
|
12
|
+
gap,
|
|
13
|
+
activeIndex = -1,
|
|
14
|
+
}: {
|
|
15
|
+
widths: number[];
|
|
16
|
+
available: number;
|
|
17
|
+
moreWidth: number;
|
|
18
|
+
gap: number;
|
|
19
|
+
activeIndex?: number;
|
|
20
|
+
}): number[] {
|
|
21
|
+
const all = widths.map((_, i) => i);
|
|
22
|
+
const total = widths.reduce((sum, w, i) => sum + w + (i > 0 ? gap : 0), 0);
|
|
23
|
+
if (total <= available) return all;
|
|
24
|
+
|
|
25
|
+
const budget = available - gap - moreWidth;
|
|
26
|
+
const picked: number[] = [];
|
|
27
|
+
let used = 0;
|
|
28
|
+
const tryAdd = (i: number): boolean => {
|
|
29
|
+
const next = used + (picked.length > 0 ? gap : 0) + widths[i];
|
|
30
|
+
if (next > budget) return false;
|
|
31
|
+
used = next;
|
|
32
|
+
picked.push(i);
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if (activeIndex >= 0 && activeIndex < widths.length) tryAdd(activeIndex);
|
|
37
|
+
for (const i of all) {
|
|
38
|
+
if (i === activeIndex) continue;
|
|
39
|
+
if (!tryAdd(i)) break;
|
|
40
|
+
}
|
|
41
|
+
return picked.sort((a, b) => a - b);
|
|
42
|
+
}
|
|
@@ -24,7 +24,7 @@ export function CollapsedDesktopTitlebar({ className }: { className?: string })
|
|
|
24
24
|
data-shellui-mac-strip=""
|
|
25
25
|
{...MAC_DRAG_REGION_PROPS}
|
|
26
26
|
className={cn(
|
|
27
|
-
'fixed inset-x-0 top-0 z-[47] flex w-full items-center
|
|
27
|
+
'fixed inset-x-0 top-0 z-[47] flex w-full items-center bg-sidebar text-sidebar-foreground select-none',
|
|
28
28
|
className,
|
|
29
29
|
)}
|
|
30
30
|
style={{
|
|
@@ -35,6 +35,9 @@ export const MAC_STRIP_CONTROL_PX = 24;
|
|
|
35
35
|
*/
|
|
36
36
|
export const SHELL_HEADER_HEIGHT_PX = 42;
|
|
37
37
|
|
|
38
|
+
/** Sidebar layout phone header height (spec: 48px, 40px trigger). */
|
|
39
|
+
export const MOBILE_SIDEBAR_HEADER_HEIGHT_PX = 48;
|
|
40
|
+
|
|
38
41
|
/** Top inset inside the shell header (web, phones, native caption bar hosts). */
|
|
39
42
|
export const SHELL_HEADER_PAD_TOP_PX = 2;
|
|
40
43
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
const APP_HEIGHT_VAR = '--shellui-app-height';
|
|
10
10
|
|
|
11
11
|
/** Read a CSS length on :root (px). `env(safe-area-*)` resolves through a probe. */
|
|
12
|
-
function
|
|
12
|
+
export function readCssLengthPx(cssLength: string): number {
|
|
13
13
|
if (typeof document === 'undefined') return 0;
|
|
14
14
|
const probe = document.createElement('div');
|
|
15
15
|
probe.style.cssText =
|
|
@@ -22,11 +22,18 @@ function readRootLengthPx(cssLength: string): number {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export function readSafeAreaInsetTop(): number {
|
|
25
|
-
return
|
|
25
|
+
return readCssLengthPx('var(--shellui-safe-area-top, env(safe-area-inset-top, 0px))');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Phone bottom sheet offset from the screen bottom: the drawer gap plus the home indicator. */
|
|
29
|
+
export function readDrawerBottomOffset(): number {
|
|
30
|
+
return readCssLengthPx(
|
|
31
|
+
'var(--shellui-drawer-bottom, calc(8px + env(safe-area-inset-bottom, 0px)))',
|
|
32
|
+
);
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
export function readSafeAreaInsetBottom(): number {
|
|
29
|
-
return
|
|
36
|
+
return readCssLengthPx('var(--shellui-safe-area-bottom, env(safe-area-inset-bottom, 0px))');
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
/** Current shell height in CSS pixels (falls back to innerHeight). */
|
|
@@ -40,7 +47,7 @@ export function readAppHeightPx(): number {
|
|
|
40
47
|
}
|
|
41
48
|
// Resolve dvh/vh/% via a probe so browser-tab fallback still works.
|
|
42
49
|
if (raw) {
|
|
43
|
-
const viaProbe =
|
|
50
|
+
const viaProbe = readCssLengthPx(raw);
|
|
44
51
|
if (viaProbe > 0) return viaProbe;
|
|
45
52
|
}
|
|
46
53
|
}
|