@shellui/core 0.7.0-alpha.10 → 0.7.0-alpha.12
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/shell-divider.spec.tsx +63 -0
- package/src/components/ui/shell-divider.tsx +20 -0
- package/src/components/ui/sidebar.tsx +15 -7
- package/src/components/ui/tooltip.tsx +4 -2
- package/src/features/auth/components/LoginButton.spec.tsx +203 -0
- package/src/features/auth/components/LoginButton.tsx +77 -28
- 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 +67 -26
- package/src/features/layouts/floating/FloatingLayout.tsx +1 -0
- package/src/features/layouts/floating/FloatingSidebar.tsx +43 -20
- 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 +149 -0
- package/src/features/layouts/sidebar/SidebarInner.tsx +60 -11
- package/src/features/layouts/sidebar/SidebarLayout.tsx +23 -13
- package/src/features/layouts/windows/WindowsLayout.tsx +93 -47
- 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 +232 -42
- 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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Fragment,
|
|
2
3
|
useMemo,
|
|
3
4
|
useState,
|
|
4
5
|
useCallback,
|
|
@@ -28,9 +29,12 @@ import { useSettings } from '../../settings/hooks/useSettings';
|
|
|
28
29
|
import { ContentView } from '../../../components/ContentView';
|
|
29
30
|
import { cn } from '../../../lib/utils';
|
|
30
31
|
import { Z_INDEX } from '../../../lib/z-index';
|
|
32
|
+
import { ShellDivider } from '../../../components/ui/shell-divider';
|
|
31
33
|
import { LoginButton } from '../../auth/components/LoginButton';
|
|
32
34
|
import { useAuth } from '../../auth/hooks/useAuth';
|
|
33
|
-
import { ExternalLinkIcon, NavIcon } from '../sidebar/SidebarIcons';
|
|
35
|
+
import { ExternalLinkIcon, NavIcon, SettingsIcon } from '../sidebar/SidebarIcons';
|
|
36
|
+
import { AppBarTooltip, TooltipProvider } from '../../../components/ui/tooltip';
|
|
37
|
+
import urls from '../../../constants/urls';
|
|
34
38
|
import { getExternalFaviconUrl, isAppIcon } from '../sidebar/sidebarUtils';
|
|
35
39
|
import { AppBrandIcon } from '../branding/AppBrandIcon';
|
|
36
40
|
import { useIsMobile } from '../../../hooks/use-mobile';
|
|
@@ -934,12 +938,16 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
934
938
|
useEffect(() => {
|
|
935
939
|
if (!startMenuOpen) return;
|
|
936
940
|
const onDocClick = (e: MouseEvent) => {
|
|
941
|
+
// The footer account menu renders in a portal: clicks there stay in the start menu.
|
|
942
|
+
if (e.target instanceof Element && e.target.closest('[data-auth-menu-content]')) return;
|
|
937
943
|
if (startPanelRef.current && !startPanelRef.current.contains(e.target as Node)) {
|
|
938
944
|
setStartMenuOpen(false);
|
|
939
945
|
}
|
|
940
946
|
};
|
|
941
947
|
const onKeyDown = (e: KeyboardEvent) => {
|
|
942
948
|
if (e.key !== 'Escape') return;
|
|
949
|
+
// Escape closes the open account menu first.
|
|
950
|
+
if (document.querySelector('[data-auth-menu-content][data-state="open"]')) return;
|
|
943
951
|
e.preventDefault();
|
|
944
952
|
setStartMenuOpen(false);
|
|
945
953
|
startButtonRef.current?.focus();
|
|
@@ -1002,7 +1010,7 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
1002
1010
|
className="fixed inset-0 overflow-hidden bg-background"
|
|
1003
1011
|
style={{ paddingBottom: TASKBAR_SLOT_CSS }}
|
|
1004
1012
|
>
|
|
1005
|
-
{/* Desktop: two low primary washes at the bottom, under the
|
|
1013
|
+
{/* Desktop: two low primary washes at the bottom, under the dot field. */}
|
|
1006
1014
|
<div
|
|
1007
1015
|
aria-hidden
|
|
1008
1016
|
className="shellui-desk-wash pointer-events-none absolute inset-0"
|
|
@@ -1124,8 +1132,9 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
1124
1132
|
</p>
|
|
1125
1133
|
<p className="shellui-start-hint text-muted-foreground">{t('windows.chooseApp')}</p>
|
|
1126
1134
|
</div>
|
|
1135
|
+
<ShellDivider />
|
|
1127
1136
|
|
|
1128
|
-
<div className="min-h-0 flex-1
|
|
1137
|
+
<div className="min-h-0 flex-1 overflow-y-auto px-2 py-3">
|
|
1129
1138
|
{menuSections.length === 0 ? (
|
|
1130
1139
|
<p className="px-2 py-6 text-center text-sm text-muted-foreground">
|
|
1131
1140
|
{t('windows.noApps')}
|
|
@@ -1142,7 +1151,7 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
1142
1151
|
sectionIndex === menuSections.length - 1 &&
|
|
1143
1152
|
section.type === 'items' &&
|
|
1144
1153
|
section.items === endNavItems;
|
|
1145
|
-
|
|
1154
|
+
const sectionNode = (
|
|
1146
1155
|
<section
|
|
1147
1156
|
key={
|
|
1148
1157
|
section.type === 'group'
|
|
@@ -1151,13 +1160,13 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
1151
1160
|
? 'end-items'
|
|
1152
1161
|
: `items-${sectionIndex}`
|
|
1153
1162
|
}
|
|
1154
|
-
className={cn(
|
|
1163
|
+
className={cn(
|
|
1164
|
+
'space-y-1.5',
|
|
1165
|
+
isEndSection ? 'pt-3' : sectionIndex > 0 && 'mt-4',
|
|
1166
|
+
)}
|
|
1155
1167
|
>
|
|
1156
1168
|
{categoryLabel ? (
|
|
1157
|
-
<h2
|
|
1158
|
-
className="px-2.5 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground"
|
|
1159
|
-
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
1160
|
-
>
|
|
1169
|
+
<h2 className="shellui-start-label px-2.5 text-xs font-semibold text-muted-foreground">
|
|
1161
1170
|
{categoryLabel}
|
|
1162
1171
|
</h2>
|
|
1163
1172
|
) : null}
|
|
@@ -1212,9 +1221,42 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
1212
1221
|
</div>
|
|
1213
1222
|
</section>
|
|
1214
1223
|
);
|
|
1224
|
+
return isEndSection ? (
|
|
1225
|
+
<Fragment key="end-items">
|
|
1226
|
+
<ShellDivider className="-mx-2 mt-4" />
|
|
1227
|
+
{sectionNode}
|
|
1228
|
+
</Fragment>
|
|
1229
|
+
) : (
|
|
1230
|
+
sectionNode
|
|
1231
|
+
);
|
|
1215
1232
|
})
|
|
1216
1233
|
)}
|
|
1217
1234
|
</div>
|
|
1235
|
+
{/* Footer: account and settings (spec). */}
|
|
1236
|
+
<ShellDivider />
|
|
1237
|
+
<div
|
|
1238
|
+
data-shellui-start-footer=""
|
|
1239
|
+
className="shellui-start-foot flex shrink-0 items-center gap-1 px-2 py-1.5"
|
|
1240
|
+
>
|
|
1241
|
+
<div className="min-w-0 flex-1">
|
|
1242
|
+
<LoginButton
|
|
1243
|
+
variant="sidebar"
|
|
1244
|
+
hideWhenLoggedOut={hasCustomLoginNav}
|
|
1245
|
+
/>
|
|
1246
|
+
</div>
|
|
1247
|
+
<button
|
|
1248
|
+
type="button"
|
|
1249
|
+
className="shellui-start-settings shellui-chrome-focus"
|
|
1250
|
+
aria-label={t('settings')}
|
|
1251
|
+
title={t('settings')}
|
|
1252
|
+
onClick={() => {
|
|
1253
|
+
setStartMenuOpen(false);
|
|
1254
|
+
shellui.openModal(urls.settings);
|
|
1255
|
+
}}
|
|
1256
|
+
>
|
|
1257
|
+
<SettingsIcon className="size-4" />
|
|
1258
|
+
</button>
|
|
1259
|
+
</div>
|
|
1218
1260
|
</div>
|
|
1219
1261
|
)}
|
|
1220
1262
|
</div>
|
|
@@ -1270,44 +1312,48 @@ export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: Windo
|
|
|
1270
1312
|
|
|
1271
1313
|
{/* End navigation items (right side of taskbar) — desktop only; phone uses start menu */}
|
|
1272
1314
|
{!phoneMode && endNavItems.length > 0 && (
|
|
1273
|
-
<
|
|
1274
|
-
{
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
<
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
className=
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1315
|
+
<TooltipProvider
|
|
1316
|
+
delayDuration={200}
|
|
1317
|
+
skipDelayDuration={0}
|
|
1318
|
+
>
|
|
1319
|
+
<div
|
|
1320
|
+
data-shellui-taskbar-end=""
|
|
1321
|
+
className="ml-1 flex shrink-0 items-center gap-0.5 border-l border-sidebar-border pl-2"
|
|
1322
|
+
>
|
|
1323
|
+
{endNavItems.map((item) => {
|
|
1324
|
+
const label =
|
|
1325
|
+
typeof item.label === 'string'
|
|
1326
|
+
? item.label
|
|
1327
|
+
: resolveNavLabel(item.label, currentLanguage);
|
|
1328
|
+
const icon =
|
|
1329
|
+
item.icon ??
|
|
1330
|
+
(item.openIn === 'external' ? getExternalFaviconUrl(item.url) : null);
|
|
1331
|
+
return (
|
|
1332
|
+
<AppBarTooltip
|
|
1333
|
+
key={item.path}
|
|
1334
|
+
label={label}
|
|
1335
|
+
side="top"
|
|
1336
|
+
>
|
|
1337
|
+
<button
|
|
1338
|
+
type="button"
|
|
1339
|
+
onClick={() => handleNavClick(item)}
|
|
1340
|
+
className="shellui-task shellui-task-icon shellui-chrome-focus"
|
|
1341
|
+
aria-label={
|
|
1342
|
+
item.openIn === 'external'
|
|
1343
|
+
? `${label} (${t('shellChrome.externalLink')})`
|
|
1344
|
+
: label
|
|
1345
|
+
}
|
|
1346
|
+
>
|
|
1347
|
+
<NavIcon
|
|
1348
|
+
src={icon}
|
|
1349
|
+
className="size-4"
|
|
1350
|
+
/>
|
|
1351
|
+
</button>
|
|
1352
|
+
</AppBarTooltip>
|
|
1353
|
+
);
|
|
1354
|
+
})}
|
|
1355
|
+
</div>
|
|
1356
|
+
</TooltipProvider>
|
|
1311
1357
|
)}
|
|
1312
1358
|
|
|
1313
1359
|
<div className="flex items-center shrink-0 border-l border-sidebar-border pl-2 ml-1">
|
|
@@ -4,12 +4,14 @@ import { DESK_DOTS, bucketAlpha, gridSize, isAccentDot } from './deskDots';
|
|
|
4
4
|
import { isDesktopCovered } from './DesktopDots';
|
|
5
5
|
|
|
6
6
|
describe('DESK_DOTS', () => {
|
|
7
|
-
it('
|
|
7
|
+
it('runs at the website normal speed, capped at 30 fps', () => {
|
|
8
8
|
expect(DESK_DOTS.fps).toBe(30);
|
|
9
9
|
expect(DESK_DOTS.dprMax).toBe(2);
|
|
10
|
-
expect(DESK_DOTS.gustPx).toBe(
|
|
11
|
-
expect(DESK_DOTS.
|
|
12
|
-
expect(DESK_DOTS.
|
|
10
|
+
expect(DESK_DOTS.gustPx).toBe(7);
|
|
11
|
+
expect(DESK_DOTS.frontWidth).toBe(70);
|
|
12
|
+
expect(DESK_DOTS.crossMs).toEqual([6700, 10000]);
|
|
13
|
+
expect(DESK_DOTS.everyMs).toEqual([1000, 3000]);
|
|
14
|
+
expect([DESK_DOTS.spring, DESK_DOTS.damp]).toEqual([0.06, 0.82]);
|
|
13
15
|
});
|
|
14
16
|
});
|
|
15
17
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Windows layout desktop:
|
|
2
|
+
* Windows layout desktop: dot field on a canvas.
|
|
3
3
|
* Ported from the layouts redesign reference (`desk-dots.js`), itself derived from
|
|
4
|
-
* the shellui.com hero dots
|
|
4
|
+
* the shellui.com hero dots at the website's normal speed and travel, no pointer play.
|
|
5
5
|
* Decorative only. The caller mounts it on an `aria-hidden` host.
|
|
6
6
|
*/
|
|
7
7
|
export const DESK_DOTS = {
|
|
@@ -20,17 +20,17 @@ export const DESK_DOTS = {
|
|
|
20
20
|
/** Extra alpha at full displacement. */
|
|
21
21
|
gustLift: 0.16,
|
|
22
22
|
/** Max displacement in px. */
|
|
23
|
-
gustPx:
|
|
23
|
+
gustPx: 7,
|
|
24
24
|
/** Width of a wind front in px. */
|
|
25
|
-
frontWidth:
|
|
25
|
+
frontWidth: 70,
|
|
26
26
|
/** Front slant in degrees. */
|
|
27
27
|
slantDeg: 18,
|
|
28
28
|
/** Time for one front to cross the desktop, ms range. */
|
|
29
|
-
crossMs: [
|
|
29
|
+
crossMs: [6700, 10000] as const,
|
|
30
30
|
/** Gap between fronts, ms range. */
|
|
31
|
-
everyMs: [
|
|
32
|
-
spring: 0.
|
|
33
|
-
damp: 0.
|
|
31
|
+
everyMs: [1000, 3000] as const,
|
|
32
|
+
spring: 0.06,
|
|
33
|
+
damp: 0.82,
|
|
34
34
|
/** Frame cap. */
|
|
35
35
|
fps: 30,
|
|
36
36
|
/** Device pixel ratio cap. */
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../../components/ui/dialog';
|
|
12
12
|
import { cn } from '../../lib/utils';
|
|
13
13
|
import { sheetExpandedHeightPx } from './overlaySize';
|
|
14
|
+
import { readDrawerBottomOffset } from '../layouts/chrome/viewport';
|
|
14
15
|
|
|
15
16
|
export type ResponsiveModalPresentation = 'dialog' | 'sheet';
|
|
16
17
|
|
|
@@ -452,7 +453,8 @@ export function ResponsiveModal({
|
|
|
452
453
|
(rawDelta >= SWIPE_DISMISS_PX || rawDelta >= height * SWIPE_DISMISS_RATIO);
|
|
453
454
|
if (shouldDismiss) {
|
|
454
455
|
setDismissMode('swipe');
|
|
455
|
-
|
|
456
|
+
// Past the bottom offset and shadow so no strip stays on screen
|
|
457
|
+
setSheetDragOffset(Math.max(rawDelta, height + readDrawerBottomOffset() + 48));
|
|
456
458
|
setSheetDragHeight(null);
|
|
457
459
|
onOpenChange(false);
|
|
458
460
|
return;
|
|
@@ -570,7 +572,7 @@ export function ResponsiveModal({
|
|
|
570
572
|
className={cn(
|
|
571
573
|
'gap-0 p-0 overflow-hidden flex flex-col',
|
|
572
574
|
isSheet
|
|
573
|
-
? 'left-
|
|
575
|
+
? 'left-[var(--shellui-drawer-left)] right-[var(--shellui-drawer-right)] top-auto bottom-[var(--shellui-drawer-bottom)] max-w-none w-auto translate-x-0 translate-y-0 rounded-[var(--shellui-sheet-radius)] border border-[var(--shellui-drawer-border)] shadow-[var(--shellui-drawer-shadow)]'
|
|
574
576
|
: cn('rounded-lg', hasCustomGeometry && 'translate-x-0 translate-y-0 max-w-none'),
|
|
575
577
|
className,
|
|
576
578
|
)}
|
|
@@ -647,7 +649,7 @@ export function ResponsiveModal({
|
|
|
647
649
|
>
|
|
648
650
|
{/* Centered tall hit target only — rest of the strip is click-through */}
|
|
649
651
|
<div
|
|
650
|
-
className="pointer-events-auto relative h-11 w-28 shrink-0 cursor-grab touch-none active:cursor-grabbing after:absolute after:left-1/2 after:top-1.5 after:h-[
|
|
652
|
+
className="pointer-events-auto relative h-11 w-28 shrink-0 cursor-grab touch-none active:cursor-grabbing after:absolute after:left-1/2 after:top-1.5 after:h-[5px] after:w-9 after:-translate-x-1/2 after:rounded-full after:bg-[color-mix(in_oklch,var(--foreground)_22%,transparent)] after:content-['']"
|
|
651
653
|
onPointerDown={handleSheetPointerDown}
|
|
652
654
|
onPointerMove={handleSheetPointerMove}
|
|
653
655
|
onPointerUp={handleSheetPointerUp}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
resolveDrawerSize,
|
|
10
10
|
resolveDrawerSizeForViewport,
|
|
11
11
|
resolveEffectiveDrawerPosition,
|
|
12
|
-
|
|
12
|
+
sheetExpandedHeightPx,
|
|
13
13
|
SHEET_EXPANDED_TOP_GAP_PX,
|
|
14
14
|
toCssLength,
|
|
15
15
|
} from './overlaySize';
|
|
@@ -69,18 +69,32 @@ describe('overlaySize', () => {
|
|
|
69
69
|
expect(resolveEffectiveDrawerPosition('right', false)).toBe('right');
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
it('
|
|
72
|
+
it('sizes phone sheets to content, keeping the requested height as fallback', () => {
|
|
73
73
|
const desktop = resolveDrawerSizeForViewport({ size: '60vw' }, 'right', false);
|
|
74
74
|
expect(desktop.drawerSize).toBe('60vw');
|
|
75
|
+
expect(desktop.contentSized).toBe(false);
|
|
75
76
|
|
|
77
|
+
const cap = 'var(--shellui-drawer-max-height)';
|
|
76
78
|
const mobile = resolveDrawerSizeForViewport({ size: '60vw' }, 'right', true);
|
|
77
|
-
expect(mobile.
|
|
79
|
+
expect(mobile.contentSized).toBe(true);
|
|
80
|
+
expect(mobile.drawerSize).toBeNull();
|
|
81
|
+
expect(mobile.style.height).toBe('auto');
|
|
82
|
+
expect(mobile.style.maxHeight).toBe(cap);
|
|
83
|
+
// Horizontal freeform width never becomes a sheet height
|
|
84
|
+
expect(mobile.fallbackHeight).toBe(
|
|
85
|
+
`min(calc(var(--shellui-overlay-max-height) * 0.8), ${cap})`,
|
|
86
|
+
);
|
|
78
87
|
|
|
79
88
|
const preset = resolveDrawerSizeForViewport({ size: 'md' }, 'right', true);
|
|
80
|
-
expect(preset.
|
|
89
|
+
expect(preset.fallbackHeight).toBe(
|
|
90
|
+
`min(calc(var(--shellui-overlay-max-height) * 0.55), ${cap})`,
|
|
91
|
+
);
|
|
81
92
|
|
|
82
93
|
const fromTop = resolveDrawerSizeForViewport({ size: '60vh' }, 'top', true);
|
|
83
|
-
expect(fromTop.
|
|
94
|
+
expect(fromTop.fallbackHeight).toBe(`min(60vh, ${cap})`);
|
|
95
|
+
|
|
96
|
+
const content = resolveDrawerSizeForViewport({ size: 'content' }, 'left', true);
|
|
97
|
+
expect(content.fallbackHeight).toBeNull();
|
|
84
98
|
});
|
|
85
99
|
|
|
86
100
|
it('defaults dismiss options', () => {
|
|
@@ -99,17 +113,43 @@ describe('overlaySize', () => {
|
|
|
99
113
|
});
|
|
100
114
|
|
|
101
115
|
it('resolves bottom sheet snap points for expand / collapse', () => {
|
|
102
|
-
// viewport 1000, no safe
|
|
103
|
-
|
|
104
|
-
expect(
|
|
105
|
-
expect(resolveBottomSheetSnapPoints(
|
|
106
|
-
expect(resolveBottomSheetSnapPoints(
|
|
107
|
-
expect(resolveBottomSheetSnapPoints({ size: '
|
|
108
|
-
expect(resolveBottomSheetSnapPoints({ size: '
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
// viewport 1000, no safe area, 8px bottom gap → sheet 932px, Vaul offset 68px
|
|
117
|
+
expect(sheetExpandedHeightPx(1000, 0, 8)).toBe(1000 - SHEET_EXPANDED_TOP_GAP_PX - 8);
|
|
118
|
+
expect(resolveBottomSheetSnapPoints({ size: 'md' }, null, 1000, 0, 8)).toEqual([0.618, 1]);
|
|
119
|
+
expect(resolveBottomSheetSnapPoints(null, null, 1000, 0, 8)).toEqual([0.868, 1]);
|
|
120
|
+
expect(resolveBottomSheetSnapPoints({ size: '400px' }, null, 1000, 0, 8)).toEqual([0.468, 1]);
|
|
121
|
+
expect(resolveBottomSheetSnapPoints({ size: 'full' }, null, 1000, 0, 8)).toBeNull();
|
|
122
|
+
expect(resolveBottomSheetSnapPoints({ size: 'sm' }, 700, 1000, 0, 8)).toEqual([0.768, 1]);
|
|
123
|
+
// Content close to the expanded height: nothing to expand to
|
|
124
|
+
expect(resolveBottomSheetSnapPoints({ size: 'sm' }, 920, 1000, 0, 8)).toBeNull();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('keeps the expanded phone sheet on screen (390 x 844, notch)', () => {
|
|
128
|
+
const H = 844;
|
|
129
|
+
const safeTop = 47;
|
|
130
|
+
const bottom = 8 + 34; // gap + home indicator
|
|
131
|
+
const h = sheetExpandedHeightPx(H, safeTop, bottom);
|
|
132
|
+
expect(h).toBe(695);
|
|
133
|
+
const snaps = resolveBottomSheetSnapPoints({ size: 'md' }, null, H, safeTop, bottom);
|
|
134
|
+
expect(snaps).not.toBeNull();
|
|
135
|
+
const [normal, expanded] = snaps ?? [0, 0];
|
|
136
|
+
// Expanded snap = no translate: top at 60px + safe area, bottom 8px above the indicator
|
|
137
|
+
expect(expanded).toBe(1);
|
|
138
|
+
const sheetTop = H - bottom - h;
|
|
139
|
+
const translate = (snap: number) => H - snap * H;
|
|
140
|
+
expect(sheetTop + translate(expanded)).toBe(SHEET_EXPANDED_TOP_GAP_PX + safeTop);
|
|
141
|
+
expect(sheetTop + translate(expanded) + h).toBe(H - bottom);
|
|
142
|
+
// First snap still shows the requested height (55%) above the bottom offset
|
|
143
|
+
const visibleAboveGap = H - bottom - (sheetTop + translate(normal));
|
|
144
|
+
expect(Math.abs(visibleAboveGap - 0.55 * H)).toBeLessThan(1);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('leaves the drawer gap around full drawers', () => {
|
|
148
|
+
expect(resolveDrawerSize({ size: 'full' }, 'right').drawerSize).toBe(
|
|
149
|
+
'calc(100% - 2 * var(--shellui-drawer-gap))',
|
|
150
|
+
);
|
|
151
|
+
expect(resolveDrawerSize({ size: 'full' }, 'top').drawerSize).toBe(
|
|
152
|
+
'var(--shellui-drawer-max-height)',
|
|
113
153
|
);
|
|
114
154
|
});
|
|
115
155
|
});
|
|
@@ -5,11 +5,17 @@ import type {
|
|
|
5
5
|
OverlaySizeValue,
|
|
6
6
|
DrawerPosition,
|
|
7
7
|
} from '@shellui/sdk';
|
|
8
|
-
import { readSafeAreaInsetTop } from '../layouts/chrome/viewport';
|
|
8
|
+
import { readDrawerBottomOffset, readSafeAreaInsetTop } from '../layouts/chrome/viewport';
|
|
9
9
|
|
|
10
10
|
/** CSS max-height for overlays — matches --shellui-overlay-max-height in index.css. */
|
|
11
11
|
const OVERLAY_MAX_HEIGHT_CSS = 'var(--shellui-overlay-max-height)';
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Largest floating drawer height: the shell height minus the top and bottom drawer
|
|
15
|
+
* offsets (each is the gap plus the safe area). Matches --shellui-drawer-max-height.
|
|
16
|
+
*/
|
|
17
|
+
const DRAWER_MAX_HEIGHT_CSS = 'var(--shellui-drawer-max-height)';
|
|
18
|
+
|
|
13
19
|
/** Fraction of overlay max height — avoids raw dvh which disagrees with iOS standalone measure. */
|
|
14
20
|
function overlayHeightFrac(fraction: number): string {
|
|
15
21
|
return `calc(${OVERLAY_MAX_HEIGHT_CSS} * ${fraction})`;
|
|
@@ -89,7 +95,7 @@ const DRAWER_PRESET_VERTICAL: Record<OverlaySizePreset, string> = {
|
|
|
89
95
|
md: overlayHeightFrac(0.55),
|
|
90
96
|
lg: overlayHeightFrac(0.75),
|
|
91
97
|
xl: overlayHeightFrac(0.9),
|
|
92
|
-
full:
|
|
98
|
+
full: DRAWER_MAX_HEIGHT_CSS,
|
|
93
99
|
content: 'auto',
|
|
94
100
|
};
|
|
95
101
|
|
|
@@ -98,7 +104,7 @@ const DRAWER_PRESET_HORIZONTAL: Record<OverlaySizePreset, string> = {
|
|
|
98
104
|
md: '28rem',
|
|
99
105
|
lg: '36rem',
|
|
100
106
|
xl: '48rem',
|
|
101
|
-
full: '100%',
|
|
107
|
+
full: 'calc(100% - 2 * var(--shellui-drawer-gap))',
|
|
102
108
|
content: 'auto',
|
|
103
109
|
};
|
|
104
110
|
|
|
@@ -111,6 +117,11 @@ export interface ResolvedOverlaySize {
|
|
|
111
117
|
contentSized: boolean;
|
|
112
118
|
/** Primary drawer CSS length (vaul size prop) when applicable. */
|
|
113
119
|
drawerSize: string | null;
|
|
120
|
+
/**
|
|
121
|
+
* Phone sheets only: the preset height to use when the app never reports its
|
|
122
|
+
* content size (no `shellui.overlay.autoSize()`), clamped by the drawer max height.
|
|
123
|
+
*/
|
|
124
|
+
fallbackHeight?: string | null;
|
|
114
125
|
}
|
|
115
126
|
|
|
116
127
|
function applyExplicitDimensions(
|
|
@@ -213,7 +224,7 @@ export function resolveDrawerSize(
|
|
|
213
224
|
if (contentSized) {
|
|
214
225
|
drawerSize = 'auto';
|
|
215
226
|
if (isVertical) {
|
|
216
|
-
style.maxHeight = style.maxHeight ??
|
|
227
|
+
style.maxHeight = style.maxHeight ?? DRAWER_MAX_HEIGHT_CSS;
|
|
217
228
|
style.height = style.height ?? 'auto';
|
|
218
229
|
} else {
|
|
219
230
|
style.maxWidth = style.maxWidth ?? 'min(90vw, 100%)';
|
|
@@ -231,8 +242,15 @@ export function resolveDrawerSize(
|
|
|
231
242
|
|
|
232
243
|
/**
|
|
233
244
|
* Resolve drawer size for the active viewport.
|
|
234
|
-
*
|
|
235
|
-
*
|
|
245
|
+
*
|
|
246
|
+
* Desktop: the requested edge and size.
|
|
247
|
+
*
|
|
248
|
+
* Phones: every drawer is a bottom sheet sized to its content. It listens for
|
|
249
|
+
* SHELLUI_OVERLAY_SIZE and grows with the iframe up to the drawer max height
|
|
250
|
+
* (8px plus the safe area above the bottom, the top below the notch), then the
|
|
251
|
+
* iframe scrolls. The requested size only applies as `fallbackHeight` when the
|
|
252
|
+
* app never reports. Horizontal freeform widths (`60vw`, `400px`, explicit
|
|
253
|
+
* `width`) are dropped so they are not applied as height.
|
|
236
254
|
*/
|
|
237
255
|
export function resolveDrawerSizeForViewport(
|
|
238
256
|
options?: OverlayOpenOptions | null,
|
|
@@ -244,22 +262,31 @@ export function resolveDrawerSizeForViewport(
|
|
|
244
262
|
return resolveDrawerSize(options, effective);
|
|
245
263
|
}
|
|
246
264
|
|
|
265
|
+
let presetOptions: OverlayOpenOptions | null | undefined = options;
|
|
247
266
|
// left/right → bottom: width-oriented sizes must not become sheet height
|
|
248
267
|
if (position === 'left' || position === 'right') {
|
|
249
268
|
const dynamic = isDynamicSizing(options);
|
|
250
269
|
const size = options?.size;
|
|
251
270
|
const dropFreeformWidth =
|
|
252
271
|
!dynamic && size !== undefined && size !== null && !isOverlaySizePreset(size);
|
|
253
|
-
|
|
272
|
+
presetOptions = dropFreeformWidth
|
|
254
273
|
? { ...options, size: undefined, width: undefined }
|
|
255
274
|
: options?.width !== undefined
|
|
256
275
|
? { ...options, width: undefined }
|
|
257
276
|
: options;
|
|
258
|
-
return resolveDrawerSize(nextOptions, 'bottom');
|
|
259
277
|
}
|
|
260
278
|
|
|
261
|
-
|
|
262
|
-
|
|
279
|
+
const preset = resolveDrawerSize(presetOptions, 'bottom');
|
|
280
|
+
const { width: _width, height: _height, ...rest } = presetOptions ?? {};
|
|
281
|
+
const sheet = resolveDrawerSize({ ...rest, size: 'content' }, 'bottom');
|
|
282
|
+
// Content sheets never exceed the drawer max height, whatever maxHeight asks for.
|
|
283
|
+
sheet.style.maxHeight = DRAWER_MAX_HEIGHT_CSS;
|
|
284
|
+
return {
|
|
285
|
+
...sheet,
|
|
286
|
+
fallbackHeight: preset.contentSized
|
|
287
|
+
? null
|
|
288
|
+
: `min(${preset.drawerSize ?? DEFAULT_VERTICAL_DRAWER}, ${DRAWER_MAX_HEIGHT_CSS})`,
|
|
289
|
+
};
|
|
263
290
|
}
|
|
264
291
|
|
|
265
292
|
export type OverlayDismissOptions = {
|
|
@@ -283,19 +310,72 @@ export function resolveDismissOptions(
|
|
|
283
310
|
};
|
|
284
311
|
}
|
|
285
312
|
|
|
313
|
+
/** How the shell presents a drawer: edge, drag handle, and whether Vaul snaps apply. */
|
|
314
|
+
export type DrawerChrome = {
|
|
315
|
+
direction: DrawerPosition;
|
|
316
|
+
showDragHandle: boolean;
|
|
317
|
+
allowSnapPoints: boolean;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Resolve drawer chrome for the active viewport.
|
|
322
|
+
*
|
|
323
|
+
* Phones (below md): every drawer, whatever edge was requested, is a bottom sheet
|
|
324
|
+
* anchored above the home indicator, always with a drag handle for the thumb. Phone
|
|
325
|
+
* sheets never snap: they sit at their content height (see
|
|
326
|
+
* {@link resolveDrawerSizeForViewport}), so there is no half-height stop leaving
|
|
327
|
+
* empty space under the actions.
|
|
328
|
+
*
|
|
329
|
+
* Content-sized drawers never snap on desktop either: a snap sheet is the expanded
|
|
330
|
+
* height, so the iframe would report that height back and the sheet would end up
|
|
331
|
+
* below the screen.
|
|
332
|
+
*
|
|
333
|
+
* Desktop: the requested edge, with the handle and snaps the options ask for.
|
|
334
|
+
*/
|
|
335
|
+
export function resolveDrawerChrome({
|
|
336
|
+
position,
|
|
337
|
+
isMobile,
|
|
338
|
+
dismiss,
|
|
339
|
+
pending = false,
|
|
340
|
+
desktopResizable = false,
|
|
341
|
+
contentSized = false,
|
|
342
|
+
}: {
|
|
343
|
+
position?: DrawerPosition;
|
|
344
|
+
isMobile: boolean;
|
|
345
|
+
dismiss: Pick<OverlayDismissOptions, 'dismissible' | 'showDragHandle'>;
|
|
346
|
+
pending?: boolean;
|
|
347
|
+
desktopResizable?: boolean;
|
|
348
|
+
contentSized?: boolean;
|
|
349
|
+
}): DrawerChrome {
|
|
350
|
+
const direction = resolveEffectiveDrawerPosition(position, isMobile);
|
|
351
|
+
if (isMobile) {
|
|
352
|
+
return { direction, showDragHandle: !pending, allowSnapPoints: false };
|
|
353
|
+
}
|
|
354
|
+
const vertical = direction === 'top' || direction === 'bottom';
|
|
355
|
+
const handle = dismiss.showDragHandle && dismiss.dismissible;
|
|
356
|
+
return {
|
|
357
|
+
direction,
|
|
358
|
+
showDragHandle: !pending && vertical && handle,
|
|
359
|
+
allowSnapPoints:
|
|
360
|
+
direction === 'bottom' && handle && !pending && !desktopResizable && !contentSized,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
286
364
|
/**
|
|
287
365
|
* Expanded bottom-sheet height leaves a tappable overlay band above the sheet:
|
|
288
|
-
* top safe-area inset + {@link SHEET_EXPANDED_TOP_GAP_PX}.
|
|
366
|
+
* top safe-area inset + {@link SHEET_EXPANDED_TOP_GAP_PX}. The floating sheet also
|
|
367
|
+
* ends a gap above the home indicator (--shellui-drawer-bottom).
|
|
289
368
|
*/
|
|
290
369
|
export const SHEET_EXPANDED_TOP_GAP_PX = 60;
|
|
291
370
|
|
|
292
|
-
/** CSS height for the expanded bottom
|
|
293
|
-
export const SHEET_EXPANDED_HEIGHT_CSS = `calc(var(--shellui-app-height) - var(--shellui-safe-area-top) - ${SHEET_EXPANDED_TOP_GAP_PX}px)`;
|
|
371
|
+
/** CSS height for the expanded floating bottom sheet. */
|
|
372
|
+
export const SHEET_EXPANDED_HEIGHT_CSS = `calc(var(--shellui-app-height) - var(--shellui-safe-area-top) - ${SHEET_EXPANDED_TOP_GAP_PX}px - var(--shellui-drawer-bottom))`;
|
|
294
373
|
|
|
295
|
-
/** Pixel height for the expanded
|
|
374
|
+
/** Pixel height for the expanded sheet (matches {@link SHEET_EXPANDED_HEIGHT_CSS}). */
|
|
296
375
|
export function sheetExpandedHeightPx(
|
|
297
376
|
viewportHeightPx?: number,
|
|
298
377
|
safeAreaTopPx?: number,
|
|
378
|
+
bottomOffsetPx?: number,
|
|
299
379
|
topGapPx = SHEET_EXPANDED_TOP_GAP_PX,
|
|
300
380
|
): number {
|
|
301
381
|
const viewport = viewportHeightPx ?? (typeof window !== 'undefined' ? window.innerHeight : 0);
|
|
@@ -303,20 +383,14 @@ export function sheetExpandedHeightPx(
|
|
|
303
383
|
if (safeTop === undefined) {
|
|
304
384
|
safeTop = typeof document !== 'undefined' ? readSafeAreaInsetTop() : 0;
|
|
305
385
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
viewportHeightPx?: number,
|
|
312
|
-
safeAreaTopPx?: number,
|
|
313
|
-
): number {
|
|
314
|
-
const viewport = viewportHeightPx ?? (typeof window !== 'undefined' ? window.innerHeight : 0);
|
|
315
|
-
if (!(viewport > 0)) return 0.9;
|
|
316
|
-
return Number((sheetExpandedHeightPx(viewport, safeAreaTopPx) / viewport).toFixed(4));
|
|
386
|
+
let bottom = bottomOffsetPx;
|
|
387
|
+
if (bottom === undefined) {
|
|
388
|
+
bottom = typeof document !== 'undefined' ? readDrawerBottomOffset() : 0;
|
|
389
|
+
}
|
|
390
|
+
return Math.max(0, Math.round(viewport - safeTop - topGapPx - bottom));
|
|
317
391
|
}
|
|
318
392
|
|
|
319
|
-
/** Vertical drawer presets →
|
|
393
|
+
/** Vertical drawer presets → visible fraction of the window height. */
|
|
320
394
|
const VERTICAL_SNAP_BY_PRESET: Record<OverlaySizePreset, number> = {
|
|
321
395
|
sm: 0.4,
|
|
322
396
|
md: 0.55,
|
|
@@ -329,17 +403,24 @@ const VERTICAL_SNAP_BY_PRESET: Record<OverlaySizePreset, number> = {
|
|
|
329
403
|
/**
|
|
330
404
|
* Resolve `[normal, expanded]` Vaul snap points for a bottom sheet.
|
|
331
405
|
* Returns null when the sheet is already near the expanded height (nothing useful to expand to).
|
|
406
|
+
*
|
|
407
|
+
* Vaul moves a bottom sheet by `translateY(H - snap)` as if the sheet started at the top
|
|
408
|
+
* of the screen. The sheet is shorter than the viewport (h < H) and floats above the home
|
|
409
|
+
* indicator, so to show a visible height v the snap is `v + (H - h)`, and the expanded
|
|
410
|
+
* snap is `1` (no translate: the whole sheet shows, ending at its bottom offset).
|
|
332
411
|
*/
|
|
333
412
|
export function resolveBottomSheetSnapPoints(
|
|
334
413
|
options?: OverlayOpenOptions | null,
|
|
335
414
|
reportedHeightPx?: number | null,
|
|
336
415
|
viewportHeightPx?: number,
|
|
337
416
|
safeAreaTopPx?: number,
|
|
417
|
+
bottomOffsetPx?: number,
|
|
338
418
|
): number[] | null {
|
|
339
419
|
const viewport = viewportHeightPx ?? (typeof window !== 'undefined' ? window.innerHeight : 0);
|
|
340
420
|
if (!(viewport > 0)) return null;
|
|
341
421
|
|
|
342
|
-
const
|
|
422
|
+
const sheetPx = sheetExpandedHeightPx(viewport, safeAreaTopPx, bottomOffsetPx);
|
|
423
|
+
const expandedVisible = sheetPx / viewport;
|
|
343
424
|
|
|
344
425
|
let normal: number;
|
|
345
426
|
if (reportedHeightPx !== null && Number.isFinite(reportedHeightPx) && reportedHeightPx > 0) {
|
|
@@ -364,9 +445,11 @@ export function resolveBottomSheetSnapPoints(
|
|
|
364
445
|
}
|
|
365
446
|
}
|
|
366
447
|
|
|
367
|
-
// Already near expanded
|
|
368
|
-
if (normal >=
|
|
448
|
+
// Already near expanded: expand would be a no-op
|
|
449
|
+
if (normal >= expandedVisible - 0.04) return null;
|
|
369
450
|
// Keep a meaningful gap between snaps
|
|
370
|
-
normal = Math.min(Math.max(normal, 0.2),
|
|
371
|
-
|
|
451
|
+
normal = Math.min(Math.max(normal, 0.2), expandedVisible - 0.05);
|
|
452
|
+
// Visible height → Vaul snap (add the part of the viewport the sheet never covers)
|
|
453
|
+
const snap = normal + (viewport - sheetPx) / viewport;
|
|
454
|
+
return [Number(snap.toFixed(4)), 1];
|
|
372
455
|
}
|