@shellui/core 0.5.0-beta.3 → 0.5.1
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/README.md +5 -5
- package/package.json +3 -2
- package/schemas/shellui.config.schema.json +98 -33
- package/src/app.tsx +10 -4
- package/src/components/ContentView.tsx +3 -5
- package/src/components/contentIframeSandbox.spec.ts +25 -0
- package/src/components/contentIframeSandbox.ts +43 -0
- package/src/components/ui/dialog.tsx +5 -1
- package/src/components/ui/dropdown-menu.tsx +39 -4
- package/src/components/ui/sheet.tsx +1 -1
- package/src/components/ui/sidebar.tsx +3 -2
- package/src/components/ui/tabs.tsx +52 -0
- package/src/constants/urls.ts +1 -0
- package/src/features/auth/AuthProvider.tsx +169 -35
- package/src/features/auth/backends/index.ts +2 -0
- package/src/features/auth/backends/shellui.ts +43 -35
- package/src/features/auth/backends/supabase.ts +1 -0
- package/src/features/auth/backends/types.ts +5 -0
- package/src/features/auth/components/LoginView.tsx +5 -1
- package/src/features/auth/components/OAuthCallbackView.tsx +115 -44
- package/src/features/auth/constants/oauth.ts +2 -0
- package/src/features/auth/hooks/useAuth.tsx +4 -0
- package/src/features/auth/utils/authSessionPersistence.spec.ts +93 -0
- package/src/features/auth/utils/authSessionPersistence.ts +138 -0
- package/src/features/auth/utils/authStorageKeys.ts +8 -0
- package/src/features/auth/utils/bffAuthClient.ts +107 -0
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +22 -0
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +17 -0
- package/src/features/auth/utils/buildSessionFromTokenPayload.spec.ts +29 -0
- package/src/features/auth/utils/buildSessionFromTokenPayload.ts +24 -0
- package/src/features/auth/utils/index.ts +18 -3
- package/src/features/auth/utils/isBffAuthEnabled.ts +12 -0
- package/src/features/chromeActions/ChromeActionIcons.tsx +261 -0
- package/src/features/chromeActions/ChromeActionsDemoView.tsx +149 -0
- package/src/features/chromeActions/ChromeActionsHost.tsx +1511 -0
- package/src/features/chromeActions/ChromeActionsProvider.tsx +141 -0
- package/src/features/chromeActions/chromeActionsStore.spec.ts +61 -0
- package/src/features/chromeActions/chromeActionsStore.ts +77 -0
- package/src/features/chromeActions/computeActionInsets.spec.ts +360 -0
- package/src/features/chromeActions/computeActionInsets.ts +326 -0
- package/src/features/chromeActions/index.ts +26 -0
- package/src/features/chromeActions/resolveUuidForRemoveIframe.spec.ts +49 -0
- package/src/features/config/types.ts +49 -2
- package/src/features/layouts/AppLayout.tsx +4 -4
- package/src/features/layouts/OverlayShell.tsx +60 -12
- package/src/features/layouts/app-bar-inset/AppBarInsetLayout.tsx +1 -1
- package/src/features/layouts/appbar/AppBarLayout.tsx +194 -89
- package/src/features/layouts/chrome/DesktopChrome.tsx +17 -3
- package/src/features/layouts/chrome/InsetMobileRadiusOverlay.tsx +18 -0
- package/src/features/layouts/chrome/index.ts +8 -0
- package/src/features/layouts/chrome/runtime.ts +73 -0
- package/src/features/layouts/chrome/useScrollHideChrome.ts +210 -0
- package/src/features/layouts/floating/FloatingBottomDock.tsx +410 -0
- package/src/features/layouts/floating/FloatingLayout.tsx +31 -21
- package/src/features/layouts/floating/FloatingStatusScrim.tsx +36 -0
- package/src/features/layouts/floating/computeFloatingInsets.spec.ts +5 -5
- package/src/features/layouts/floating/computeFloatingInsets.ts +64 -12
- package/src/features/layouts/floating/isShellOwnedPath.spec.ts +2 -0
- package/src/features/layouts/floating/isShellOwnedPath.ts +1 -0
- package/src/features/layouts/floating/layoutChromeStore.spec.ts +138 -0
- package/src/features/layouts/floating/layoutChromeStore.ts +169 -6
- package/src/features/layouts/floating/useFloatingChrome.ts +20 -30
- package/src/features/layouts/sidebar/SidebarLayout.tsx +87 -31
- package/src/features/layouts/sidebar-inset/SidebarInsetLayout.tsx +1 -1
- package/src/features/layouts/windows/WindowsLayout.tsx +240 -110
- package/src/features/messaging/MessagingSecurityBootstrap.tsx +19 -0
- package/src/features/messaging/deriveAllowedMessageOrigins.spec.ts +86 -0
- package/src/features/messaging/deriveAllowedMessageOrigins.ts +74 -0
- package/src/features/modal/ModalContext.spec.ts +13 -2
- package/src/features/modal/validateAndNormalizeUrl.ts +9 -23
- package/src/features/overlays/ResponsiveModal.tsx +201 -21
- package/src/features/overlays/overlaySize.spec.ts +18 -0
- package/src/features/overlays/overlaySize.ts +89 -0
- package/src/features/security/trustedFrames.spec.ts +129 -0
- package/src/features/security/trustedFrames.ts +79 -0
- package/src/features/security/urlAllowlist.spec.ts +99 -0
- package/src/features/security/urlAllowlist.ts +122 -0
- package/src/features/settings/SettingsProvider.tsx +38 -54
- package/src/features/settings/components/Develop.tsx +2 -0
- package/src/features/settings/components/develop/ChromeActionsTestButtons.tsx +63 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +23 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +7 -0
- package/src/features/storage/StorageBridge.spec.ts +82 -0
- package/src/features/storage/StorageBridge.tsx +25 -3
- package/src/features/storage/StoragePickerContext.tsx +3 -4
- package/src/features/storage/uploads/uploadQueue.spec.ts +56 -1
- package/src/features/storage/uploads/uploadQueue.ts +44 -6
- package/src/features/theme/applyTheme.ts +23 -5
- package/src/hooks/use-mobile.tsx +21 -7
- package/src/i18n/translations/en/settings.json +9 -0
- package/src/i18n/translations/fr/settings.json +9 -0
- package/src/index.css +264 -124
- package/src/index.html +6 -4
- package/src/index.ts +8 -0
- package/src/routes/components/NavigationItemRoute.tsx +30 -15
- package/src/routes/components/RouteFallback.tsx +15 -0
- package/src/routes/routes.tsx +14 -0
- package/src/routes/utils/navigationRouteAccess.spec.ts +85 -0
- package/src/routes/utils/navigationRouteAccess.ts +43 -0
- package/src/features/auth/utils/clearStoredAuthSession.spec.ts +0 -23
- package/src/features/auth/utils/clearStoredAuthSession.ts +0 -10
- package/src/features/auth/utils/persistAuthSession.spec.ts +0 -35
- package/src/features/auth/utils/persistAuthSession.ts +0 -12
- package/src/features/auth/utils/readStoredAuthSession.spec.ts +0 -34
- package/src/features/auth/utils/readStoredAuthSession.ts +0 -14
- package/src/features/layouts/floating/FloatingFadeMask.tsx +0 -22
- package/src/features/layouts/floating/FloatingTabBar.tsx +0 -437
- package/src/features/layouts/floating/FloatingTabIndicator.tsx +0 -216
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { deriveAllowedMessageOrigins } from './deriveAllowedMessageOrigins';
|
|
3
|
+
import type { ShellUIConfig } from '../config/types';
|
|
4
|
+
|
|
5
|
+
describe('deriveAllowedMessageOrigins', () => {
|
|
6
|
+
it('collects origins from navigation, storage, and admin URLs', () => {
|
|
7
|
+
const config = {
|
|
8
|
+
navigation: [
|
|
9
|
+
{
|
|
10
|
+
label: 'App',
|
|
11
|
+
path: 'app',
|
|
12
|
+
url: 'http://localhost:3000/',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
title: 'Group',
|
|
16
|
+
items: [
|
|
17
|
+
{
|
|
18
|
+
label: 'Files',
|
|
19
|
+
path: 'files',
|
|
20
|
+
url: 'https://files.example.com/app/',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
storage: {
|
|
26
|
+
url: 'https://storage.example.com',
|
|
27
|
+
filesUrl: 'https://files.example.com/explorer/',
|
|
28
|
+
},
|
|
29
|
+
administration: {
|
|
30
|
+
navigation: [
|
|
31
|
+
{
|
|
32
|
+
label: 'Admin app',
|
|
33
|
+
path: 'admin-app',
|
|
34
|
+
url: 'https://admin.example.com/panel/',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
} as ShellUIConfig;
|
|
39
|
+
|
|
40
|
+
const origins = deriveAllowedMessageOrigins(config);
|
|
41
|
+
expect(origins).toContain('http://localhost:3000');
|
|
42
|
+
expect(origins).toContain('https://admin.example.com');
|
|
43
|
+
expect(origins).toContain('https://files.example.com');
|
|
44
|
+
expect(origins).toContain('https://storage.example.com');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('unions security.allowedMessageOrigins with derived origins', () => {
|
|
48
|
+
const config = {
|
|
49
|
+
navigation: [{ label: 'App', path: 'app', url: 'http://localhost:3000/' }],
|
|
50
|
+
security: {
|
|
51
|
+
allowedMessageOrigins: ['https://preview.example.com', 'http://127.0.0.1:4173/preview/'],
|
|
52
|
+
},
|
|
53
|
+
} as ShellUIConfig;
|
|
54
|
+
|
|
55
|
+
const origins = deriveAllowedMessageOrigins(config);
|
|
56
|
+
expect(origins).toContain('http://localhost:3000');
|
|
57
|
+
expect(origins).toContain('https://preview.example.com');
|
|
58
|
+
expect(origins).toContain('http://127.0.0.1:4173');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('keeps derive-only behavior when security.allowedMessageOrigins is empty or omitted', () => {
|
|
62
|
+
const base = {
|
|
63
|
+
navigation: [{ label: 'App', path: 'app', url: 'http://localhost:3000/' }],
|
|
64
|
+
} as ShellUIConfig;
|
|
65
|
+
|
|
66
|
+
const derivedOnly = deriveAllowedMessageOrigins(base);
|
|
67
|
+
expect(derivedOnly).toContain('http://localhost:3000');
|
|
68
|
+
expect(
|
|
69
|
+
deriveAllowedMessageOrigins({ ...base, security: { allowedMessageOrigins: [] } }),
|
|
70
|
+
).toEqual(derivedOnly);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('skips invalid security.allowedMessageOrigins entries without throwing', () => {
|
|
74
|
+
const config = {
|
|
75
|
+
navigation: [{ label: 'App', path: 'app', url: 'http://localhost:3000/' }],
|
|
76
|
+
security: {
|
|
77
|
+
allowedMessageOrigins: ['https://preview.example.com', 'javascript:alert(1)', '', 42],
|
|
78
|
+
},
|
|
79
|
+
} as unknown as ShellUIConfig;
|
|
80
|
+
|
|
81
|
+
const origins = deriveAllowedMessageOrigins(config);
|
|
82
|
+
expect(origins).toContain('http://localhost:3000');
|
|
83
|
+
expect(origins).toContain('https://preview.example.com');
|
|
84
|
+
expect(origins).not.toContain('javascript:alert(1)');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { collectOriginsFromUrls, getLogger } from '@shellui/sdk';
|
|
2
|
+
import { getAdminContentUrl } from '../admin/config';
|
|
3
|
+
import type { ShellUIConfig } from '../config/types';
|
|
4
|
+
|
|
5
|
+
const logger = getLogger('shellcore');
|
|
6
|
+
|
|
7
|
+
function collectConfiguredMessageOrigins(config?: ShellUIConfig | null): string[] {
|
|
8
|
+
const raw = config?.security?.allowedMessageOrigins;
|
|
9
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const valid = new Set<string>();
|
|
14
|
+
const invalid: string[] = [];
|
|
15
|
+
|
|
16
|
+
for (const entry of raw) {
|
|
17
|
+
if (typeof entry !== 'string') {
|
|
18
|
+
invalid.push(String(entry));
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const trimmed = entry.trim();
|
|
22
|
+
if (!trimmed) {
|
|
23
|
+
invalid.push(entry);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const [origin] = collectOriginsFromUrls(trimmed);
|
|
27
|
+
if (origin) {
|
|
28
|
+
valid.add(origin);
|
|
29
|
+
} else {
|
|
30
|
+
invalid.push(trimmed);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (invalid.length > 0) {
|
|
35
|
+
logger.warn(
|
|
36
|
+
'Ignoring invalid security.allowedMessageOrigins entries (expected http(s) origins or URLs)',
|
|
37
|
+
{ invalid },
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return [...valid];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Origins permitted for inbound/outbound Shellui postMessage traffic on this host. */
|
|
45
|
+
export function deriveAllowedMessageOrigins(config?: ShellUIConfig | null): string[] {
|
|
46
|
+
const urls: (string | undefined | null)[] = [
|
|
47
|
+
config?.storage?.url,
|
|
48
|
+
config?.storage?.filesUrl,
|
|
49
|
+
getAdminContentUrl(config ?? undefined),
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
for (const item of config?.administration?.navigation ?? []) {
|
|
53
|
+
if (item.openIn === 'external') continue;
|
|
54
|
+
urls.push(item.url);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const entry of config?.navigation ?? []) {
|
|
58
|
+
if ('items' in entry) {
|
|
59
|
+
for (const item of entry.items) {
|
|
60
|
+
if (item.openIn === 'external') continue;
|
|
61
|
+
urls.push(item.url);
|
|
62
|
+
urls.push(item.settings);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if (entry.openIn === 'external') continue;
|
|
66
|
+
urls.push(entry.url);
|
|
67
|
+
urls.push(entry.settings);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const derived = collectOriginsFromUrls(...urls);
|
|
72
|
+
const configured = collectConfiguredMessageOrigins(config);
|
|
73
|
+
return [...new Set([...derived, ...configured])];
|
|
74
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { DEFAULT_ADMIN_URL } from '../admin/config';
|
|
3
3
|
import type { ShellUIConfig } from '../config/types';
|
|
4
4
|
import { validateAndNormalizeUrl } from './validateAndNormalizeUrl';
|
|
@@ -36,12 +36,23 @@ describe('validateAndNormalizeUrl', () => {
|
|
|
36
36
|
expect(validateAndNormalizeUrl('/settings')).toBe('/settings');
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
vi.unstubAllEnvs();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('allows localhost urls in development builds', () => {
|
|
44
|
+
vi.stubEnv('NODE_ENV', 'development');
|
|
40
45
|
expect(validateAndNormalizeUrl('http://localhost:5175/#/select')).toBe(
|
|
41
46
|
'http://localhost:5175/#/select',
|
|
42
47
|
);
|
|
43
48
|
});
|
|
44
49
|
|
|
50
|
+
it('rejects localhost urls in production builds', () => {
|
|
51
|
+
vi.stubEnv('NODE_ENV', 'production');
|
|
52
|
+
expect(validateAndNormalizeUrl('http://localhost:5175/#/select', config)).toBeNull();
|
|
53
|
+
expect(validateAndNormalizeUrl('http://127.0.0.1:5175/#/select', config)).toBeNull();
|
|
54
|
+
});
|
|
55
|
+
|
|
45
56
|
it('rejects unrelated origins', () => {
|
|
46
57
|
expect(validateAndNormalizeUrl('https://evil.example.com/form', config)).toBeNull();
|
|
47
58
|
});
|
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
import { getAdminContentUrl } from '../admin/config';
|
|
2
2
|
import type { ShellUIConfig } from '../config/types';
|
|
3
|
-
|
|
4
|
-
const originFromAbsoluteUrl = (value: string | undefined | null): string | null => {
|
|
5
|
-
if (!value || typeof value !== 'string') {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
const trimmed = value.trim();
|
|
9
|
-
if (!trimmed.startsWith('http://') && !trimmed.startsWith('https://')) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
try {
|
|
13
|
-
return new URL(trimmed).origin;
|
|
14
|
-
} catch {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
3
|
+
import { isAllowedIframeOrigin, originFromAbsoluteUrl } from '../security/urlAllowlist';
|
|
18
4
|
|
|
19
5
|
/** Origins allowed in modal iframes: storage service/files app, admin panel, and administration nav apps. */
|
|
20
6
|
const getAllowedModalOrigins = (config?: ShellUIConfig | null): Set<string> => {
|
|
@@ -41,7 +27,7 @@ const getAllowedModalOrigins = (config?: ShellUIConfig | null): Set<string> => {
|
|
|
41
27
|
};
|
|
42
28
|
|
|
43
29
|
/**
|
|
44
|
-
* Validates and normalizes a URL to ensure it's from the same domain, localhost,
|
|
30
|
+
* Validates and normalizes a URL to ensure it's from the same domain, localhost (dev only),
|
|
45
31
|
* storage, or administration origins configured on the host.
|
|
46
32
|
* @param url - The URL or path to validate
|
|
47
33
|
* @param config - Host config used to allow storage and administration origins
|
|
@@ -61,13 +47,13 @@ export const validateAndNormalizeUrl = (
|
|
|
61
47
|
const urlObj = new URL(url);
|
|
62
48
|
const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
|
|
63
49
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
50
|
+
if (
|
|
51
|
+
isAllowedIframeOrigin(urlObj.origin, {
|
|
52
|
+
allowLocalhost: true,
|
|
53
|
+
config,
|
|
54
|
+
currentOrigin,
|
|
55
|
+
})
|
|
56
|
+
) {
|
|
71
57
|
return url;
|
|
72
58
|
}
|
|
73
59
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useCallback,
|
|
3
3
|
useEffect,
|
|
4
|
+
useLayoutEffect,
|
|
4
5
|
useRef,
|
|
5
6
|
useState,
|
|
6
7
|
type CSSProperties,
|
|
@@ -9,16 +10,20 @@ import {
|
|
|
9
10
|
} from 'react';
|
|
10
11
|
import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../../components/ui/dialog';
|
|
11
12
|
import { cn } from '../../lib/utils';
|
|
13
|
+
import { sheetExpandedHeightPx } from './overlaySize';
|
|
12
14
|
|
|
13
15
|
export type ResponsiveModalPresentation = 'dialog' | 'sheet';
|
|
14
16
|
|
|
15
17
|
const SWIPE_DISMISS_PX = 80;
|
|
16
18
|
const SWIPE_DISMISS_RATIO = 0.2;
|
|
19
|
+
/** Drag distance (px) to commit expand / collapse on release. */
|
|
20
|
+
const SHEET_SNAP_COMMIT_PX = 56;
|
|
17
21
|
const MIN_WIDTH = 320;
|
|
18
22
|
const MIN_HEIGHT = 240;
|
|
19
23
|
const VIEWPORT_MARGIN = 8;
|
|
20
24
|
|
|
21
25
|
type ResizeEdge = 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw';
|
|
26
|
+
type SheetSnap = 'normal' | 'expanded';
|
|
22
27
|
|
|
23
28
|
type ModalGeometry = {
|
|
24
29
|
x: number;
|
|
@@ -133,6 +138,16 @@ export function ResponsiveModal({
|
|
|
133
138
|
const dragCurrentY = useRef(0);
|
|
134
139
|
const [sheetDragOffset, setSheetDragOffset] = useState(0);
|
|
135
140
|
const [isSheetDragging, setIsSheetDragging] = useState(false);
|
|
141
|
+
/** True only during the opening slide so resize morph doesn’t re-trigger enter. */
|
|
142
|
+
const [enterMotion, setEnterMotion] = useState(false);
|
|
143
|
+
/** Swipe dismiss already translated off-screen — skip the CSS close slide. */
|
|
144
|
+
const [dismissMode, setDismissMode] = useState<'none' | 'swipe'>('none');
|
|
145
|
+
/** Bottom sheet height snap: normal (configured) ↔ near-full. */
|
|
146
|
+
const [sheetSnap, setSheetSnap] = useState<SheetSnap>('normal');
|
|
147
|
+
/** Live height while dragging between snaps (px). */
|
|
148
|
+
const [sheetDragHeight, setSheetDragHeight] = useState<number | null>(null);
|
|
149
|
+
const normalHeightRef = useRef<number | null>(null);
|
|
150
|
+
const sheetSnapRef = useRef<SheetSnap>('normal');
|
|
136
151
|
|
|
137
152
|
const [geometry, setGeometry] = useState<ModalGeometry | null>(null);
|
|
138
153
|
const geometryRef = useRef<ModalGeometry | null>(null);
|
|
@@ -310,12 +325,60 @@ export function ResponsiveModal({
|
|
|
310
325
|
dragCurrentY.current = 0;
|
|
311
326
|
setSheetDragOffset(0);
|
|
312
327
|
setIsSheetDragging(false);
|
|
328
|
+
setDismissMode('none');
|
|
329
|
+
setSheetSnap('normal');
|
|
330
|
+
sheetSnapRef.current = 'normal';
|
|
331
|
+
setSheetDragHeight(null);
|
|
332
|
+
normalHeightRef.current = null;
|
|
333
|
+
if (isSheet) {
|
|
334
|
+
setEnterMotion(true);
|
|
335
|
+
const t = window.setTimeout(() => setEnterMotion(false), 450);
|
|
336
|
+
return () => window.clearTimeout(t);
|
|
337
|
+
}
|
|
338
|
+
setEnterMotion(false);
|
|
339
|
+
return;
|
|
313
340
|
}
|
|
314
|
-
|
|
341
|
+
setEnterMotion(false);
|
|
342
|
+
}, [open, isSheet]);
|
|
343
|
+
|
|
344
|
+
useEffect(() => {
|
|
345
|
+
sheetSnapRef.current = sheetSnap;
|
|
346
|
+
}, [sheetSnap]);
|
|
347
|
+
|
|
348
|
+
const expandedSheetHeight = useCallback(() => {
|
|
349
|
+
return sheetExpandedHeightPx();
|
|
350
|
+
}, []);
|
|
351
|
+
|
|
352
|
+
// Remember the configured (normal) height whenever we're settled at that snap
|
|
353
|
+
useLayoutEffect(() => {
|
|
354
|
+
if (
|
|
355
|
+
!open ||
|
|
356
|
+
!isSheet ||
|
|
357
|
+
sheetSnap !== 'normal' ||
|
|
358
|
+
isSheetDragging ||
|
|
359
|
+
sheetDragHeight !== null
|
|
360
|
+
) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const h = contentRef.current?.offsetHeight;
|
|
364
|
+
if (h && h > 0) {
|
|
365
|
+
normalHeightRef.current = h;
|
|
366
|
+
}
|
|
367
|
+
}, [open, isSheet, sheetSnap, isSheetDragging, sheetDragHeight, style, className, children]);
|
|
368
|
+
|
|
369
|
+
const canExpandSheet = useCallback(() => {
|
|
370
|
+
const normal = normalHeightRef.current ?? contentRef.current?.offsetHeight ?? 0;
|
|
371
|
+
const expanded = expandedSheetHeight();
|
|
372
|
+
return normal > 0 && expanded - normal >= SHEET_SNAP_COMMIT_PX;
|
|
373
|
+
}, [expandedSheetHeight]);
|
|
315
374
|
|
|
316
375
|
const handleSheetPointerDown = useCallback(
|
|
317
376
|
(e: ReactPointerEvent<HTMLDivElement>) => {
|
|
318
377
|
if (!isSheet || !dismissible) return;
|
|
378
|
+
// Capture normal height before expand so collapse can restore it
|
|
379
|
+
if (sheetSnapRef.current === 'normal' && contentRef.current) {
|
|
380
|
+
normalHeightRef.current = contentRef.current.offsetHeight;
|
|
381
|
+
}
|
|
319
382
|
dragStartY.current = e.clientY;
|
|
320
383
|
dragCurrentY.current = 0;
|
|
321
384
|
setIsSheetDragging(true);
|
|
@@ -324,12 +387,45 @@ export function ResponsiveModal({
|
|
|
324
387
|
[isSheet, dismissible],
|
|
325
388
|
);
|
|
326
389
|
|
|
327
|
-
const handleSheetPointerMove = useCallback(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
390
|
+
const handleSheetPointerMove = useCallback(
|
|
391
|
+
(e: ReactPointerEvent<HTMLDivElement>) => {
|
|
392
|
+
if (dragStartY.current === null) return;
|
|
393
|
+
const rawDelta = e.clientY - dragStartY.current; // +down / −up
|
|
394
|
+
dragCurrentY.current = rawDelta;
|
|
395
|
+
const normal = normalHeightRef.current ?? contentRef.current?.offsetHeight ?? 0;
|
|
396
|
+
const expanded = expandedSheetHeight();
|
|
397
|
+
const expandable = canExpandSheet();
|
|
398
|
+
|
|
399
|
+
if (sheetSnapRef.current === 'normal') {
|
|
400
|
+
if (rawDelta >= 0 || !expandable) {
|
|
401
|
+
// Drag down → dismiss preview (no upward expand)
|
|
402
|
+
setSheetDragOffset(Math.max(0, rawDelta));
|
|
403
|
+
setSheetDragHeight(null);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
// Drag up → grow toward expanded
|
|
407
|
+
setSheetDragOffset(0);
|
|
408
|
+
setSheetDragHeight(Math.min(expanded, normal - rawDelta));
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Expanded: drag down shrinks; further down peeks dismiss translate
|
|
413
|
+
if (rawDelta <= 0) {
|
|
414
|
+
setSheetDragOffset(0);
|
|
415
|
+
setSheetDragHeight(expanded);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const shrinkRange = expanded - normal;
|
|
419
|
+
if (rawDelta < shrinkRange) {
|
|
420
|
+
setSheetDragOffset(0);
|
|
421
|
+
setSheetDragHeight(expanded - rawDelta);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
setSheetDragHeight(normal);
|
|
425
|
+
setSheetDragOffset(rawDelta - shrinkRange);
|
|
426
|
+
},
|
|
427
|
+
[canExpandSheet, expandedSheetHeight],
|
|
428
|
+
);
|
|
333
429
|
|
|
334
430
|
const handleSheetPointerUp = useCallback(
|
|
335
431
|
(e: ReactPointerEvent<HTMLDivElement>) => {
|
|
@@ -339,32 +435,87 @@ export function ResponsiveModal({
|
|
|
339
435
|
} catch {
|
|
340
436
|
// ignore
|
|
341
437
|
}
|
|
342
|
-
const
|
|
438
|
+
const rawDelta = dragCurrentY.current;
|
|
343
439
|
const height = contentRef.current?.offsetHeight ?? window.innerHeight;
|
|
344
|
-
const
|
|
440
|
+
const normal = normalHeightRef.current ?? height;
|
|
441
|
+
const expanded = expandedSheetHeight();
|
|
442
|
+
const expandable = canExpandSheet();
|
|
345
443
|
|
|
346
444
|
dragStartY.current = null;
|
|
347
445
|
dragCurrentY.current = 0;
|
|
348
446
|
setIsSheetDragging(false);
|
|
349
447
|
|
|
350
|
-
if (
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
448
|
+
if (sheetSnapRef.current === 'normal') {
|
|
449
|
+
if (rawDelta > 0) {
|
|
450
|
+
const shouldDismiss =
|
|
451
|
+
dismissible &&
|
|
452
|
+
(rawDelta >= SWIPE_DISMISS_PX || rawDelta >= height * SWIPE_DISMISS_RATIO);
|
|
453
|
+
if (shouldDismiss) {
|
|
454
|
+
setDismissMode('swipe');
|
|
455
|
+
setSheetDragOffset(Math.max(rawDelta, height));
|
|
456
|
+
setSheetDragHeight(null);
|
|
457
|
+
onOpenChange(false);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
setSheetDragOffset(0);
|
|
461
|
+
setSheetDragHeight(null);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Dragged up — commit expand if far enough / past midpoint
|
|
466
|
+
if (
|
|
467
|
+
expandable &&
|
|
468
|
+
(normal - rawDelta >= (normal + expanded) / 2 || -rawDelta >= SHEET_SNAP_COMMIT_PX)
|
|
469
|
+
) {
|
|
470
|
+
setSheetSnap('expanded');
|
|
471
|
+
sheetSnapRef.current = 'expanded';
|
|
472
|
+
setSheetDragHeight(null);
|
|
473
|
+
setSheetDragOffset(0);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
setSheetDragHeight(null);
|
|
477
|
+
setSheetDragOffset(0);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// From expanded
|
|
482
|
+
const shrinkRange = Math.max(1, expanded - normal);
|
|
483
|
+
if (rawDelta > shrinkRange) {
|
|
484
|
+
const dismissDelta = rawDelta - shrinkRange;
|
|
485
|
+
const shouldDismiss =
|
|
486
|
+
dismissible &&
|
|
487
|
+
(dismissDelta >= SWIPE_DISMISS_PX || dismissDelta >= normal * SWIPE_DISMISS_RATIO);
|
|
488
|
+
if (shouldDismiss) {
|
|
489
|
+
setDismissMode('swipe');
|
|
490
|
+
setSheetDragOffset(Math.max(dismissDelta, height));
|
|
491
|
+
setSheetDragHeight(null);
|
|
492
|
+
onOpenChange(false);
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
// Not far enough past normal — collapse to normal
|
|
496
|
+
setSheetSnap('normal');
|
|
497
|
+
sheetSnapRef.current = 'normal';
|
|
498
|
+
setSheetDragHeight(null);
|
|
499
|
+
setSheetDragOffset(0);
|
|
354
500
|
return;
|
|
355
501
|
}
|
|
356
502
|
|
|
357
|
-
|
|
503
|
+
if (rawDelta >= SHEET_SNAP_COMMIT_PX || expanded - rawDelta <= (normal + expanded) / 2) {
|
|
504
|
+
setSheetSnap('normal');
|
|
505
|
+
sheetSnapRef.current = 'normal';
|
|
506
|
+
}
|
|
507
|
+
setSheetDragHeight(null);
|
|
358
508
|
setSheetDragOffset(0);
|
|
359
509
|
},
|
|
360
|
-
[dismissible, onOpenChange],
|
|
510
|
+
[canExpandSheet, dismissible, expandedSheetHeight, onOpenChange],
|
|
361
511
|
);
|
|
362
512
|
|
|
363
513
|
const canMove = movable && !isSheet;
|
|
364
514
|
const canResize = resizable && !isSheet;
|
|
365
515
|
const hasCustomGeometry = !isSheet && geometry !== null;
|
|
366
516
|
|
|
367
|
-
const sheetExitTransition =
|
|
517
|
+
const sheetExitTransition =
|
|
518
|
+
'transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.32s ease-out, height 0.32s cubic-bezier(0.32, 0.72, 0, 1), max-height 0.32s cubic-bezier(0.32, 0.72, 0, 1)';
|
|
368
519
|
|
|
369
520
|
const geometryStyle: CSSProperties | undefined = hasCustomGeometry
|
|
370
521
|
? {
|
|
@@ -380,6 +531,26 @@ export function ResponsiveModal({
|
|
|
380
531
|
}
|
|
381
532
|
: undefined;
|
|
382
533
|
|
|
534
|
+
const sheetHeightStyle: CSSProperties | undefined = (() => {
|
|
535
|
+
if (!isSheet) return undefined;
|
|
536
|
+
if (sheetDragHeight !== null) {
|
|
537
|
+
return {
|
|
538
|
+
height: sheetDragHeight,
|
|
539
|
+
maxHeight: sheetDragHeight,
|
|
540
|
+
minHeight: sheetDragHeight,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
if (sheetSnap === 'expanded') {
|
|
544
|
+
const h = expandedSheetHeight();
|
|
545
|
+
return {
|
|
546
|
+
height: h,
|
|
547
|
+
maxHeight: h,
|
|
548
|
+
minHeight: h,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
return undefined;
|
|
552
|
+
})();
|
|
553
|
+
|
|
383
554
|
return (
|
|
384
555
|
<Dialog
|
|
385
556
|
open={open}
|
|
@@ -392,6 +563,9 @@ export function ResponsiveModal({
|
|
|
392
563
|
data-presentation={presentation}
|
|
393
564
|
data-geometry={hasCustomGeometry ? 'custom' : 'auto'}
|
|
394
565
|
data-window-interacting={isWindowInteracting ? 'true' : undefined}
|
|
566
|
+
data-enter-motion={enterMotion ? '' : undefined}
|
|
567
|
+
data-dismiss={dismissMode === 'swipe' ? 'swipe' : undefined}
|
|
568
|
+
data-sheet-snap={isSheet ? sheetSnap : undefined}
|
|
395
569
|
showCloseButton={showCloseButton}
|
|
396
570
|
className={cn(
|
|
397
571
|
'gap-0 p-0 overflow-hidden flex flex-col',
|
|
@@ -403,11 +577,16 @@ export function ResponsiveModal({
|
|
|
403
577
|
style={{
|
|
404
578
|
...style,
|
|
405
579
|
...geometryStyle,
|
|
580
|
+
...sheetHeightStyle,
|
|
406
581
|
...(isSheet
|
|
407
|
-
?
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
582
|
+
? enterMotion
|
|
583
|
+
? {
|
|
584
|
+
// Opening slide owns `transform` — don’t pin translateY(0) inline.
|
|
585
|
+
}
|
|
586
|
+
: {
|
|
587
|
+
transform: `translateY(${sheetDragOffset}px)`,
|
|
588
|
+
transition: isSheetDragging ? 'none' : sheetExitTransition,
|
|
589
|
+
}
|
|
411
590
|
: {}),
|
|
412
591
|
...((isSheetDragging || isWindowInteracting) && { transition: 'none' }),
|
|
413
592
|
}}
|
|
@@ -473,11 +652,12 @@ export function ResponsiveModal({
|
|
|
473
652
|
onPointerMove={handleSheetPointerMove}
|
|
474
653
|
onPointerUp={handleSheetPointerUp}
|
|
475
654
|
onPointerCancel={() => {
|
|
476
|
-
// Cancel mid-drag — ease back to
|
|
655
|
+
// Cancel mid-drag — ease back to the current snap
|
|
477
656
|
dragStartY.current = null;
|
|
478
657
|
dragCurrentY.current = 0;
|
|
479
658
|
setIsSheetDragging(false);
|
|
480
659
|
setSheetDragOffset(0);
|
|
660
|
+
setSheetDragHeight(null);
|
|
481
661
|
}}
|
|
482
662
|
/>
|
|
483
663
|
</div>
|
|
@@ -3,11 +3,14 @@ import {
|
|
|
3
3
|
DYNAMIC_DRAWER_PENDING_PX,
|
|
4
4
|
DYNAMIC_OVERLAY_PENDING_PX,
|
|
5
5
|
isOverlaySizePreset,
|
|
6
|
+
resolveBottomSheetSnapPoints,
|
|
6
7
|
resolveDialogSize,
|
|
7
8
|
resolveDismissOptions,
|
|
8
9
|
resolveDrawerSize,
|
|
9
10
|
resolveDrawerSizeForViewport,
|
|
10
11
|
resolveEffectiveDrawerPosition,
|
|
12
|
+
sheetExpandedSnapFraction,
|
|
13
|
+
SHEET_EXPANDED_TOP_GAP_PX,
|
|
11
14
|
toCssLength,
|
|
12
15
|
} from './overlaySize';
|
|
13
16
|
|
|
@@ -94,4 +97,19 @@ describe('overlaySize', () => {
|
|
|
94
97
|
showDragHandle: false,
|
|
95
98
|
});
|
|
96
99
|
});
|
|
100
|
+
|
|
101
|
+
it('resolves bottom sheet snap points for expand / collapse', () => {
|
|
102
|
+
// viewport 1000, no safe-area → expanded = 1000 - 60
|
|
103
|
+
const expanded = sheetExpandedSnapFraction(1000, 0);
|
|
104
|
+
expect(expanded).toBe(Number(((1000 - SHEET_EXPANDED_TOP_GAP_PX) / 1000).toFixed(4)));
|
|
105
|
+
expect(resolveBottomSheetSnapPoints({ size: 'md' }, null, 1000, 0)).toEqual([0.55, expanded]);
|
|
106
|
+
expect(resolveBottomSheetSnapPoints(null, null, 1000, 0)).toEqual([0.8, expanded]);
|
|
107
|
+
expect(resolveBottomSheetSnapPoints({ size: '400px' }, null, 1000, 0)).toEqual([0.4, expanded]);
|
|
108
|
+
expect(resolveBottomSheetSnapPoints({ size: 'full' }, null, 1000, 0)).toBeNull();
|
|
109
|
+
expect(resolveBottomSheetSnapPoints({ size: 'sm' }, 700, 1000, 0)).toEqual([0.7, expanded]);
|
|
110
|
+
// With notch inset, expanded shrinks further
|
|
111
|
+
expect(sheetExpandedSnapFraction(1000, 47)).toBe(
|
|
112
|
+
Number(((1000 - 47 - SHEET_EXPANDED_TOP_GAP_PX) / 1000).toFixed(4)),
|
|
113
|
+
);
|
|
114
|
+
});
|
|
97
115
|
});
|