@shellui/core 0.4.1 → 0.5.0-alpha.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 +2 -2
- package/package.json +15 -3
- package/schemas/curated-themes.json +4035 -0
- package/schemas/shellui.config.schema.json +961 -0
- package/schemas/shellui.theme.schema.json +187 -0
- package/src/app.tsx +4 -1
- package/src/components/ContentView.tsx +144 -9
- package/src/components/LoadingOverlay.tsx +1 -1
- package/src/components/ui/alert-dialog.tsx +1 -1
- package/src/components/ui/dialog.tsx +23 -5
- package/src/components/ui/drawer.tsx +282 -42
- package/src/components/ui/dropdown-menu.tsx +7 -2
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/separator.tsx +23 -0
- package/src/components/ui/sheet.tsx +220 -0
- package/src/components/ui/sidebar.tsx +785 -221
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/constants/urls.ts +1 -0
- package/src/features/admin/utils.ts +2 -45
- package/src/features/alertDialog/DialogContext.tsx +1 -1
- package/src/features/auth/components/LoginButton.tsx +25 -18
- package/src/features/auth/components/LoginPreferencesControls.tsx +124 -0
- package/src/features/auth/components/LoginView.tsx +131 -49
- package/src/features/config/types.ts +64 -82
- package/src/features/drawer/DrawerContext.tsx +55 -19
- package/src/features/layouts/AppLayout.tsx +3 -3
- package/src/features/layouts/OverlayShell.tsx +376 -77
- package/src/features/layouts/appbar/AppBarLayout.tsx +501 -88
- package/src/features/layouts/branding/AppBrandIcon.tsx +95 -0
- package/src/features/layouts/branding/resolveThemeAsset.spec.ts +33 -0
- package/src/features/layouts/branding/resolveThemeAsset.ts +33 -0
- package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +49 -0
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +19 -0
- package/src/features/layouts/chrome/DesktopBackButton.tsx +71 -0
- package/src/features/layouts/chrome/DesktopChrome.tsx +28 -0
- package/src/features/layouts/chrome/DesktopForwardButton.tsx +59 -0
- package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +16 -0
- package/src/features/layouts/chrome/constants.ts +11 -0
- package/src/features/layouts/chrome/goDesktopBack.spec.ts +218 -0
- package/src/features/layouts/chrome/goDesktopBack.ts +106 -0
- package/src/features/layouts/chrome/index.ts +26 -0
- package/src/features/layouts/chrome/runtime.ts +45 -0
- package/src/features/layouts/findMatchingNavigationItem.spec.ts +55 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +17 -1
- package/src/features/layouts/isFrameForAppUrl.spec.ts +33 -0
- package/src/features/layouts/sidebar/NavigationContent.tsx +70 -34
- package/src/features/layouts/sidebar/SidebarIcons.tsx +41 -42
- package/src/features/layouts/sidebar/SidebarInner.tsx +142 -24
- package/src/features/layouts/sidebar/SidebarLayout.tsx +100 -37
- package/src/features/layouts/sidebar/sidebarUtils.ts +0 -7
- package/src/features/layouts/sidebar/types.ts +3 -3
- package/src/features/layouts/utils.ts +73 -5
- package/src/features/layouts/windows/WindowsLayout.tsx +173 -61
- package/src/features/modal/ModalContext.tsx +21 -8
- package/src/features/overlays/OverlayDrawerPendingBar.tsx +26 -0
- package/src/features/overlays/OverlayDynamicDemoView.tsx +108 -0
- package/src/features/overlays/OverlayPendingSpinner.tsx +18 -0
- package/src/features/overlays/ResponsiveModal.tsx +483 -0
- package/src/features/overlays/overlaySize.spec.ts +71 -0
- package/src/features/overlays/overlaySize.ts +228 -0
- package/src/features/overlays/useOverlayReportedSize.ts +130 -0
- package/src/features/settings/SettingsProvider.tsx +66 -46
- package/src/features/settings/SettingsView.tsx +42 -47
- package/src/features/settings/components/Appearance.tsx +305 -55
- package/src/features/settings/components/develop/DrawerTestButtons.tsx +18 -0
- package/src/features/settings/components/develop/ModalTestButtons.tsx +23 -0
- package/src/features/settings/utils/getResolvedAppearanceForSettings.ts +11 -5
- package/src/features/theme/applyTheme.ts +143 -0
- package/src/features/theme/color.ts +83 -0
- package/src/features/theme/curated/amber-minimal.json +86 -0
- package/src/features/theme/curated/amethyst-haze.json +86 -0
- package/src/features/theme/curated/astro-vista.json +86 -0
- package/src/features/theme/curated/bold-tech.json +86 -0
- package/src/features/theme/curated/bubblegum.json +86 -0
- package/src/features/theme/curated/caffeine.json +83 -0
- package/src/features/theme/curated/candyland.json +86 -0
- package/src/features/theme/curated/catppuccin.json +86 -0
- package/src/features/theme/curated/claude.json +86 -0
- package/src/features/theme/curated/claymorphism.json +86 -0
- package/src/features/theme/curated/clean-slate.json +86 -0
- package/src/features/theme/curated/cosmic-night.json +86 -0
- package/src/features/theme/curated/cyberpunk.json +86 -0
- package/src/features/theme/curated/darkmatter.json +86 -0
- package/src/features/theme/curated/doom-64.json +86 -0
- package/src/features/theme/curated/elegant-luxury.json +86 -0
- package/src/features/theme/curated/graphite.json +86 -0
- package/src/features/theme/curated/index.ts +260 -0
- package/src/features/theme/curated/kodama-grove.json +86 -0
- package/src/features/theme/curated/light-green.json +87 -0
- package/src/features/theme/curated/midnight-bloom.json +86 -0
- package/src/features/theme/curated/mocha-mousse.json +86 -0
- package/src/features/theme/curated/modern-minimal.json +86 -0
- package/src/features/theme/curated/mono.json +84 -0
- package/src/features/theme/curated/nature.json +86 -0
- package/src/features/theme/curated/neo-brutalism.json +86 -0
- package/src/features/theme/curated/northern-lights.json +86 -0
- package/src/features/theme/curated/notebook.json +87 -0
- package/src/features/theme/curated/ocean-breeze.json +86 -0
- package/src/features/theme/curated/pastel-dreams.json +86 -0
- package/src/features/theme/curated/perpetuity.json +86 -0
- package/src/features/theme/curated/quantum-rose.json +86 -0
- package/src/features/theme/curated/retro-arcade.json +86 -0
- package/src/features/theme/curated/sage-garden.json +86 -0
- package/src/features/theme/curated/shadcn.json +83 -0
- package/src/features/theme/curated/shellui.json +82 -0
- package/src/features/theme/curated/soft-pop.json +86 -0
- package/src/features/theme/curated/solar-dusk.json +86 -0
- package/src/features/theme/curated/starry-night.json +86 -0
- package/src/features/theme/curated/sunset-horizon.json +86 -0
- package/src/features/theme/curated/supabase.json +85 -0
- package/src/features/theme/curated/t3-chat.json +83 -0
- package/src/features/theme/curated/tangerine.json +86 -0
- package/src/features/theme/curated/twitter.json +86 -0
- package/src/features/theme/curated/vercel.json +86 -0
- package/src/features/theme/curated/vintage-paper.json +86 -0
- package/src/features/theme/curated/violet-bloom.json +87 -0
- package/src/features/theme/curated/zen-inspired.json +87 -0
- package/src/features/theme/index.ts +76 -0
- package/src/features/theme/normalize.ts +159 -0
- package/src/features/theme/registry.ts +50 -0
- package/src/features/theme/resolveConfig.ts +182 -0
- package/src/features/theme/safeApplyTheme.ts +147 -0
- package/src/features/theme/themes.spec.ts +276 -0
- package/src/features/theme/themes.ts +82 -558
- package/src/features/theme/tokenKeys.ts +60 -0
- package/src/features/theme/types.ts +170 -0
- package/src/features/theme/useTheme.tsx +48 -50
- package/src/hooks/use-mobile.tsx +19 -0
- package/src/i18n/translations/en/common.json +41 -0
- package/src/i18n/translations/en/settings.json +10 -2
- package/src/i18n/translations/fr/common.json +41 -0
- package/src/i18n/translations/fr/settings.json +10 -2
- package/src/index.css +372 -128
- package/src/index.ts +71 -0
- package/src/lib/z-index.ts +4 -1
- package/src/routes/components/IndexRoute.tsx +12 -2
- package/src/routes/components/NavigationItemRoute.tsx +1 -10
- package/src/routes/hooks/useNavigationItems.ts +29 -44
- package/src/routes/routes.tsx +58 -27
- package/tailwind.config.js +27 -27
- package/src/features/layouts/sidebar/BottomNavItem.tsx +0 -88
- package/src/features/layouts/sidebar/MobileBottomNav.tsx +0 -168
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Link } from 'react-router';
|
|
3
|
+
import type { ThemeAsset } from '../../config/types';
|
|
4
|
+
import { cn } from '../../../lib/utils';
|
|
5
|
+
import { isThemeAssetPair, resolveThemeAsset } from './resolveThemeAsset';
|
|
6
|
+
|
|
7
|
+
function useDocumentIsDark(): boolean {
|
|
8
|
+
const [isDark, setIsDark] = useState(() =>
|
|
9
|
+
typeof document !== 'undefined' ? document.documentElement.classList.contains('dark') : false,
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const root = document.documentElement;
|
|
14
|
+
const sync = () => setIsDark(root.classList.contains('dark'));
|
|
15
|
+
sync();
|
|
16
|
+
const observer = new MutationObserver(sync);
|
|
17
|
+
observer.observe(root, { attributes: true, attributeFilter: ['class'] });
|
|
18
|
+
return () => observer.disconnect();
|
|
19
|
+
}, []);
|
|
20
|
+
|
|
21
|
+
return isDark;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AppBrandIconProps {
|
|
25
|
+
appIcon?: ThemeAsset;
|
|
26
|
+
/** Accessible name / link title (usually config.title). */
|
|
27
|
+
title?: string;
|
|
28
|
+
className?: string;
|
|
29
|
+
/** Extra class on the <img> (layout-specific theming hooks). */
|
|
30
|
+
imgClassName?: string;
|
|
31
|
+
/** When false, render the image only (no home link). Default true. */
|
|
32
|
+
linkToHome?: boolean;
|
|
33
|
+
/** Forwarded to the link/wrapper (e.g. data-shellui-no-drag for Tauri). */
|
|
34
|
+
'data-shellui-no-drag'?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Small square brand mark from config.appIcon.
|
|
39
|
+
* Single-path assets are recolored for light/dark via CSS; `{ light, dark }` pairs swap files.
|
|
40
|
+
*/
|
|
41
|
+
export function AppBrandIcon({
|
|
42
|
+
appIcon,
|
|
43
|
+
title,
|
|
44
|
+
className,
|
|
45
|
+
imgClassName,
|
|
46
|
+
linkToHome = true,
|
|
47
|
+
'data-shellui-no-drag': noDrag,
|
|
48
|
+
}: AppBrandIconProps) {
|
|
49
|
+
const isDark = useDocumentIsDark();
|
|
50
|
+
const mode = isDark ? 'dark' : 'light';
|
|
51
|
+
const src = resolveThemeAsset(appIcon, mode);
|
|
52
|
+
if (!src) return null;
|
|
53
|
+
|
|
54
|
+
const paired = isThemeAssetPair(appIcon);
|
|
55
|
+
const alt = title?.trim() || 'Home';
|
|
56
|
+
const noDragProps = noDrag !== undefined ? { 'data-shellui-no-drag': noDrag } : undefined;
|
|
57
|
+
|
|
58
|
+
const image = (
|
|
59
|
+
<img
|
|
60
|
+
src={src}
|
|
61
|
+
alt={alt}
|
|
62
|
+
className={cn(
|
|
63
|
+
'size-5 shrink-0 object-contain',
|
|
64
|
+
paired ? 'app-brand-icon-static' : 'app-brand-icon',
|
|
65
|
+
imgClassName,
|
|
66
|
+
)}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
if (!linkToHome) {
|
|
71
|
+
return (
|
|
72
|
+
<span
|
|
73
|
+
className={cn('inline-flex shrink-0 items-center', className)}
|
|
74
|
+
{...noDragProps}
|
|
75
|
+
>
|
|
76
|
+
{image}
|
|
77
|
+
</span>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<Link
|
|
83
|
+
to="/"
|
|
84
|
+
title={alt}
|
|
85
|
+
aria-label={alt}
|
|
86
|
+
className={cn(
|
|
87
|
+
'inline-flex shrink-0 items-center justify-center rounded-sm outline-none focus-visible:ring-2 focus-visible:ring-sidebar-ring',
|
|
88
|
+
className,
|
|
89
|
+
)}
|
|
90
|
+
{...noDragProps}
|
|
91
|
+
>
|
|
92
|
+
{image}
|
|
93
|
+
</Link>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getThemeAssetSourcePath, isThemeAssetPair, resolveThemeAsset } from './resolveThemeAsset';
|
|
3
|
+
|
|
4
|
+
describe('resolveThemeAsset', () => {
|
|
5
|
+
it('returns trimmed string assets', () => {
|
|
6
|
+
expect(resolveThemeAsset('/app-icon.svg', 'light')).toBe('/app-icon.svg');
|
|
7
|
+
expect(resolveThemeAsset(' /x.png ', 'dark')).toBe('/x.png');
|
|
8
|
+
expect(resolveThemeAsset(' ', 'light')).toBeUndefined();
|
|
9
|
+
expect(resolveThemeAsset(undefined, 'dark')).toBeUndefined();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('picks light/dark paths from pairs', () => {
|
|
13
|
+
const pair = { light: '/a-light.png', dark: '/a-dark.png' };
|
|
14
|
+
expect(resolveThemeAsset(pair, 'light')).toBe('/a-light.png');
|
|
15
|
+
expect(resolveThemeAsset(pair, 'dark')).toBe('/a-dark.png');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('isThemeAssetPair', () => {
|
|
20
|
+
it('detects pair objects', () => {
|
|
21
|
+
expect(isThemeAssetPair('/x.svg')).toBe(false);
|
|
22
|
+
expect(isThemeAssetPair({ light: '/a.png', dark: '/b.png' })).toBe(true);
|
|
23
|
+
expect(isThemeAssetPair(undefined)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('getThemeAssetSourcePath', () => {
|
|
28
|
+
it('prefers light path for tooling', () => {
|
|
29
|
+
expect(getThemeAssetSourcePath('/icon.svg')).toBe('/icon.svg');
|
|
30
|
+
expect(getThemeAssetSourcePath({ light: '/l.png', dark: '/d.png' })).toBe('/l.png');
|
|
31
|
+
expect(getThemeAssetSourcePath({ light: '', dark: '/d.png' })).toBe('/d.png');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ThemeAsset } from '../../config/types';
|
|
2
|
+
|
|
3
|
+
/** Pick the concrete URL for the current color mode. */
|
|
4
|
+
export function resolveThemeAsset(
|
|
5
|
+
asset: ThemeAsset | undefined,
|
|
6
|
+
mode: 'light' | 'dark',
|
|
7
|
+
): string | undefined {
|
|
8
|
+
if (!asset) return undefined;
|
|
9
|
+
if (typeof asset === 'string') {
|
|
10
|
+
const trimmed = asset.trim();
|
|
11
|
+
return trimmed || undefined;
|
|
12
|
+
}
|
|
13
|
+
const path = (mode === 'dark' ? asset.dark : asset.light)?.trim();
|
|
14
|
+
return path || undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** True when light/dark are separate files (skip CSS invert filters). */
|
|
18
|
+
export function isThemeAssetPair(asset: ThemeAsset | undefined): asset is {
|
|
19
|
+
light: string;
|
|
20
|
+
dark: string;
|
|
21
|
+
} {
|
|
22
|
+
return typeof asset === 'object' && asset !== null && 'light' in asset && 'dark' in asset;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Prefer light (or dark) path for tooling that needs a single file (e.g. Tauri icons). */
|
|
26
|
+
export function getThemeAssetSourcePath(asset: ThemeAsset | undefined): string | undefined {
|
|
27
|
+
if (!asset) return undefined;
|
|
28
|
+
if (typeof asset === 'string') {
|
|
29
|
+
const trimmed = asset.trim();
|
|
30
|
+
return trimmed || undefined;
|
|
31
|
+
}
|
|
32
|
+
return asset.light?.trim() || asset.dark?.trim() || undefined;
|
|
33
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SidebarTrigger, useSidebar } from '../../../components/ui/sidebar';
|
|
2
|
+
import { cn } from '../../../lib/utils';
|
|
3
|
+
import { DesktopHistoryButtons } from './DesktopHistoryButtons';
|
|
4
|
+
import {
|
|
5
|
+
DESKTOP_TITLEBAR_HEIGHT_PX,
|
|
6
|
+
MAC_TRAFFIC_LIGHTS_GAP_PX,
|
|
7
|
+
MAC_TRAFFIC_LIGHTS_WIDTH_PX,
|
|
8
|
+
} from './constants';
|
|
9
|
+
import { useIsTauriClient, useMacOverlayChrome } from './runtime';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Full-width 38px chrome when the sidebar is collapsed in a Tauri overlay window.
|
|
13
|
+
* Open-sidebar first, then Back; room for more controls later.
|
|
14
|
+
*/
|
|
15
|
+
export function CollapsedDesktopTitlebar({ className }: { className?: string }) {
|
|
16
|
+
const overlay = useMacOverlayChrome();
|
|
17
|
+
const isTauriEnv = useIsTauriClient();
|
|
18
|
+
const { state, isMobile } = useSidebar();
|
|
19
|
+
const collapsed = state === 'collapsed' && !isMobile;
|
|
20
|
+
|
|
21
|
+
if (!overlay || !collapsed) return null;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
data-shellui-collapsed-titlebar=""
|
|
26
|
+
data-shellui-drag-region=""
|
|
27
|
+
data-tauri-drag-region=""
|
|
28
|
+
className={cn(
|
|
29
|
+
'fixed inset-x-0 top-0 z-[47] flex w-full items-center border-b border-sidebar-border bg-sidebar text-sidebar-foreground select-none',
|
|
30
|
+
className,
|
|
31
|
+
)}
|
|
32
|
+
style={{ height: DESKTOP_TITLEBAR_HEIGHT_PX }}
|
|
33
|
+
>
|
|
34
|
+
<div
|
|
35
|
+
className="h-full shrink-0"
|
|
36
|
+
style={{ width: MAC_TRAFFIC_LIGHTS_WIDTH_PX }}
|
|
37
|
+
aria-hidden
|
|
38
|
+
/>
|
|
39
|
+
<div
|
|
40
|
+
data-shellui-no-drag=""
|
|
41
|
+
className="flex h-full items-center gap-0.5"
|
|
42
|
+
style={{ paddingLeft: MAC_TRAFFIC_LIGHTS_GAP_PX }}
|
|
43
|
+
>
|
|
44
|
+
<SidebarTrigger className="size-8 touch-manipulation" />
|
|
45
|
+
{isTauriEnv ? <DesktopHistoryButtons /> : null}
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DESKTOP_TITLEBAR_HEIGHT_PX } from './constants';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Full-width invisible 38px strip at the top of the Tauri window.
|
|
5
|
+
*
|
|
6
|
+
* Uses Tauri's official `data-tauri-drag-region` (requires
|
|
7
|
+
* `core:window:allow-start-dragging` in capabilities). Shell controls must sit
|
|
8
|
+
* above this strip (higher z-index) so they stay clickable.
|
|
9
|
+
*/
|
|
10
|
+
export function ContentDragOverlay() {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
aria-hidden
|
|
14
|
+
data-tauri-drag-region
|
|
15
|
+
className="fixed inset-x-0 top-0 z-[45] w-full"
|
|
16
|
+
style={{ height: DESKTOP_TITLEBAR_HEIGHT_PX }}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useNavigate } from 'react-router';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { shellui } from '@shellui/sdk';
|
|
5
|
+
import { Button } from '../../../components/ui/button';
|
|
6
|
+
import { cn } from '../../../lib/utils';
|
|
7
|
+
import { useModal } from '../../modal/ModalContext';
|
|
8
|
+
import { useDrawer } from '../../drawer/DrawerContext';
|
|
9
|
+
import { useStoragePicker } from '../../storage/StoragePickerContext';
|
|
10
|
+
import { goDesktopBack, type DesktopBackIframe } from './goDesktopBack';
|
|
11
|
+
|
|
12
|
+
function BackIcon({ className }: { className?: string }) {
|
|
13
|
+
return (
|
|
14
|
+
<svg
|
|
15
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
16
|
+
width="24"
|
|
17
|
+
height="24"
|
|
18
|
+
viewBox="0 0 24 24"
|
|
19
|
+
fill="none"
|
|
20
|
+
stroke="currentColor"
|
|
21
|
+
strokeWidth="2"
|
|
22
|
+
strokeLinecap="round"
|
|
23
|
+
strokeLinejoin="round"
|
|
24
|
+
className={className}
|
|
25
|
+
aria-hidden
|
|
26
|
+
>
|
|
27
|
+
<path d="M15 18l-6-6 6-6" />
|
|
28
|
+
</svg>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function DesktopBackButton({ className }: { className?: string }) {
|
|
33
|
+
const navigate = useNavigate();
|
|
34
|
+
const { t } = useTranslation();
|
|
35
|
+
const { isOpen: modalOpen, closeModal } = useModal();
|
|
36
|
+
const { isOpen: drawerOpen, closeDrawer } = useDrawer();
|
|
37
|
+
const { isOpen: pickerOpen, closePicker } = useStoragePicker();
|
|
38
|
+
|
|
39
|
+
const handleBack = useCallback(() => {
|
|
40
|
+
const iframes = shellui.frameRegistry.getAllIframes().map(([, iframe]) => iframe);
|
|
41
|
+
goDesktopBack({
|
|
42
|
+
iframes: iframes as DesktopBackIframe[],
|
|
43
|
+
overlaysOpen: modalOpen || drawerOpen || pickerOpen,
|
|
44
|
+
closeOverlays: () => {
|
|
45
|
+
if (pickerOpen) closePicker();
|
|
46
|
+
if (modalOpen) closeModal();
|
|
47
|
+
if (drawerOpen) closeDrawer();
|
|
48
|
+
},
|
|
49
|
+
goRouterBack: () => navigate(-1),
|
|
50
|
+
baseHref: window.location.href,
|
|
51
|
+
});
|
|
52
|
+
}, [closeDrawer, closeModal, closePicker, drawerOpen, modalOpen, navigate, pickerOpen]);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Button
|
|
56
|
+
type="button"
|
|
57
|
+
variant="ghost"
|
|
58
|
+
size="icon"
|
|
59
|
+
aria-label={t('desktopChrome.back')}
|
|
60
|
+
data-shellui-no-drag=""
|
|
61
|
+
className={cn(
|
|
62
|
+
'size-7 shrink-0 touch-manipulation select-none text-muted-foreground [-webkit-touch-callout:none]',
|
|
63
|
+
'hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
64
|
+
className,
|
|
65
|
+
)}
|
|
66
|
+
onClick={handleBack}
|
|
67
|
+
>
|
|
68
|
+
<BackIcon />
|
|
69
|
+
</Button>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { ContentDragOverlay } from './ContentDragOverlay';
|
|
3
|
+
import { useIsTauriClient, useMacTrafficLights } from './runtime';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Global Tauri desktop chrome: document flags + the 38px top drag strip.
|
|
7
|
+
* Mounted at the app root so it stays available on every page (layouts, login,
|
|
8
|
+
* settings, route error boundary, empty config) — including narrow/mobile widths.
|
|
9
|
+
*/
|
|
10
|
+
export function DesktopChrome() {
|
|
11
|
+
const isTauriEnv = useIsTauriClient();
|
|
12
|
+
const trafficLights = useMacTrafficLights();
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const root = document.documentElement;
|
|
16
|
+
if (trafficLights) root.setAttribute('data-shellui-overlay-chrome', '');
|
|
17
|
+
else root.removeAttribute('data-shellui-overlay-chrome');
|
|
18
|
+
if (isTauriEnv) root.setAttribute('data-shellui-tauri', '');
|
|
19
|
+
else root.removeAttribute('data-shellui-tauri');
|
|
20
|
+
return () => {
|
|
21
|
+
root.removeAttribute('data-shellui-overlay-chrome');
|
|
22
|
+
root.removeAttribute('data-shellui-tauri');
|
|
23
|
+
};
|
|
24
|
+
}, [trafficLights, isTauriEnv]);
|
|
25
|
+
|
|
26
|
+
if (!trafficLights) return null;
|
|
27
|
+
return <ContentDragOverlay />;
|
|
28
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useNavigate } from 'react-router';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { shellui } from '@shellui/sdk';
|
|
5
|
+
import { Button } from '../../../components/ui/button';
|
|
6
|
+
import { cn } from '../../../lib/utils';
|
|
7
|
+
import { goDesktopForward, type DesktopBackIframe } from './goDesktopBack';
|
|
8
|
+
|
|
9
|
+
function ForwardIcon({ className }: { className?: string }) {
|
|
10
|
+
return (
|
|
11
|
+
<svg
|
|
12
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
13
|
+
width="24"
|
|
14
|
+
height="24"
|
|
15
|
+
viewBox="0 0 24 24"
|
|
16
|
+
fill="none"
|
|
17
|
+
stroke="currentColor"
|
|
18
|
+
strokeWidth="2"
|
|
19
|
+
strokeLinecap="round"
|
|
20
|
+
strokeLinejoin="round"
|
|
21
|
+
className={className}
|
|
22
|
+
aria-hidden
|
|
23
|
+
>
|
|
24
|
+
<path d="M9 18l6-6-6-6" />
|
|
25
|
+
</svg>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function DesktopForwardButton({ className }: { className?: string }) {
|
|
30
|
+
const navigate = useNavigate();
|
|
31
|
+
const { t } = useTranslation();
|
|
32
|
+
|
|
33
|
+
const handleForward = useCallback(() => {
|
|
34
|
+
const iframes = shellui.frameRegistry.getAllIframes().map(([, iframe]) => iframe);
|
|
35
|
+
goDesktopForward({
|
|
36
|
+
iframes: iframes as DesktopBackIframe[],
|
|
37
|
+
goRouterForward: () => navigate(1),
|
|
38
|
+
baseHref: window.location.href,
|
|
39
|
+
});
|
|
40
|
+
}, [navigate]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Button
|
|
44
|
+
type="button"
|
|
45
|
+
variant="ghost"
|
|
46
|
+
size="icon"
|
|
47
|
+
aria-label={t('desktopChrome.forward')}
|
|
48
|
+
data-shellui-no-drag=""
|
|
49
|
+
className={cn(
|
|
50
|
+
'size-7 shrink-0 touch-manipulation select-none text-muted-foreground [-webkit-touch-callout:none]',
|
|
51
|
+
'hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
52
|
+
className,
|
|
53
|
+
)}
|
|
54
|
+
onClick={handleForward}
|
|
55
|
+
>
|
|
56
|
+
<ForwardIcon />
|
|
57
|
+
</Button>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { cn } from '../../../lib/utils';
|
|
2
|
+
import { DesktopBackButton } from './DesktopBackButton';
|
|
3
|
+
import { DesktopForwardButton } from './DesktopForwardButton';
|
|
4
|
+
|
|
5
|
+
/** Browser-like Back + Forward for Tauri / desktop chrome. */
|
|
6
|
+
export function DesktopHistoryButtons({ className }: { className?: string }) {
|
|
7
|
+
return (
|
|
8
|
+
<div
|
|
9
|
+
data-shellui-no-drag=""
|
|
10
|
+
className={cn('flex shrink-0 items-center', className)}
|
|
11
|
+
>
|
|
12
|
+
<DesktopBackButton />
|
|
13
|
+
<DesktopForwardButton />
|
|
14
|
+
</div>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Height of the macOS overlay titlebar / traffic-light row. */
|
|
2
|
+
export const DESKTOP_TITLEBAR_HEIGHT_PX = 38;
|
|
3
|
+
|
|
4
|
+
/** Width reserved for macOS traffic lights (close / minimize / zoom). */
|
|
5
|
+
export const MAC_TRAFFIC_LIGHTS_WIDTH_PX = 78;
|
|
6
|
+
|
|
7
|
+
/** Extra space between traffic lights and the first chrome control. */
|
|
8
|
+
export const MAC_TRAFFIC_LIGHTS_GAP_PX = 12;
|
|
9
|
+
|
|
10
|
+
/** Set on an iframe after it navigates to a foreign origin (login pages, OAuth). */
|
|
11
|
+
export const IFRAME_FOREIGN_ATTR = 'data-shellui-iframe-foreign';
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { IFRAME_FOREIGN_ATTR } from './constants';
|
|
3
|
+
import {
|
|
4
|
+
goBackInIframes,
|
|
5
|
+
goDesktopBack,
|
|
6
|
+
goDesktopForward,
|
|
7
|
+
normalizeHref,
|
|
8
|
+
tryGoBackInIframe,
|
|
9
|
+
tryGoForwardInIframe,
|
|
10
|
+
type DesktopBackIframe,
|
|
11
|
+
} from './goDesktopBack';
|
|
12
|
+
|
|
13
|
+
function mockIframe(
|
|
14
|
+
overrides: Partial<DesktopBackIframe> & { foreign?: boolean } = {},
|
|
15
|
+
): DesktopBackIframe {
|
|
16
|
+
const { foreign, ...rest } = overrides;
|
|
17
|
+
const attrs: Record<string, string> = {};
|
|
18
|
+
if (foreign) attrs[IFRAME_FOREIGN_ATTR] = 'true';
|
|
19
|
+
const src = rest.src ?? 'http://localhost/app';
|
|
20
|
+
attrs.src = src;
|
|
21
|
+
|
|
22
|
+
const iframe: DesktopBackIframe = {
|
|
23
|
+
isConnected: rest.isConnected ?? true,
|
|
24
|
+
src,
|
|
25
|
+
contentWindow: rest.contentWindow ?? {
|
|
26
|
+
location: { href: src },
|
|
27
|
+
history: { back: vi.fn(), forward: vi.fn() },
|
|
28
|
+
},
|
|
29
|
+
getAttribute: (name) => attrs[name] ?? null,
|
|
30
|
+
removeAttribute: (name) => {
|
|
31
|
+
delete attrs[name];
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
...iframe,
|
|
37
|
+
...rest,
|
|
38
|
+
getAttribute: iframe.getAttribute,
|
|
39
|
+
removeAttribute: iframe.removeAttribute,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('normalizeHref', () => {
|
|
44
|
+
it('strips trailing slashes but keeps hash for hash-router apps', () => {
|
|
45
|
+
expect(normalizeHref('http://localhost/app/#/foo')).toBe('http://localhost/app#/foo');
|
|
46
|
+
expect(normalizeHref('http://localhost/app/')).toBe('http://localhost/app');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('tryGoBackInIframe', () => {
|
|
51
|
+
it('resets src when the iframe navigated to a foreign origin', () => {
|
|
52
|
+
const iframe = mockIframe({
|
|
53
|
+
foreign: true,
|
|
54
|
+
src: 'http://localhost/app',
|
|
55
|
+
});
|
|
56
|
+
iframe.src = 'https://accounts.example/login';
|
|
57
|
+
|
|
58
|
+
expect(tryGoBackInIframe(iframe)).toBe(true);
|
|
59
|
+
expect(iframe.src).toBe('http://localhost/app');
|
|
60
|
+
expect(iframe.getAttribute(IFRAME_FOREIGN_ATTR)).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('does not use iframe history for same-origin SPA routes (shell owns history)', () => {
|
|
64
|
+
const back = vi.fn();
|
|
65
|
+
const iframe = mockIframe({
|
|
66
|
+
src: 'http://localhost/app',
|
|
67
|
+
contentWindow: {
|
|
68
|
+
location: { href: 'http://localhost/app/login' },
|
|
69
|
+
history: { back, forward: vi.fn() },
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(tryGoBackInIframe(iframe, 'http://localhost')).toBe(false);
|
|
74
|
+
expect(back).not.toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('does not use iframe history when only the hash differs', () => {
|
|
78
|
+
const back = vi.fn();
|
|
79
|
+
const iframe = mockIframe({
|
|
80
|
+
src: 'http://localhost:5173/#/',
|
|
81
|
+
contentWindow: {
|
|
82
|
+
location: { href: 'http://localhost:5173/#/layout' },
|
|
83
|
+
history: { back, forward: vi.fn() },
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(tryGoBackInIframe(iframe, 'http://localhost:5173/')).toBe(false);
|
|
88
|
+
expect(back).not.toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('tryGoForwardInIframe', () => {
|
|
93
|
+
it('still detects whether forward would change the URL', () => {
|
|
94
|
+
const location = { href: 'http://localhost/app' };
|
|
95
|
+
const forward = vi.fn(() => {
|
|
96
|
+
location.href = 'http://localhost/app/login';
|
|
97
|
+
});
|
|
98
|
+
const iframe = mockIframe({
|
|
99
|
+
src: 'http://localhost/app',
|
|
100
|
+
contentWindow: {
|
|
101
|
+
location,
|
|
102
|
+
history: { back: vi.fn(), forward },
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
expect(tryGoForwardInIframe(iframe, 'http://localhost')).toBe(true);
|
|
107
|
+
expect(forward).toHaveBeenCalledOnce();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('goDesktopBack', () => {
|
|
112
|
+
it('prefers foreign iframe reset over closing overlays', () => {
|
|
113
|
+
const closeOverlays = vi.fn();
|
|
114
|
+
const iframes = [
|
|
115
|
+
mockIframe({
|
|
116
|
+
foreign: true,
|
|
117
|
+
src: 'http://localhost/app',
|
|
118
|
+
}),
|
|
119
|
+
];
|
|
120
|
+
iframes[0].src = 'https://accounts.example/login';
|
|
121
|
+
|
|
122
|
+
expect(
|
|
123
|
+
goDesktopBack({
|
|
124
|
+
iframes,
|
|
125
|
+
overlaysOpen: true,
|
|
126
|
+
closeOverlays,
|
|
127
|
+
baseHref: 'http://localhost',
|
|
128
|
+
}),
|
|
129
|
+
).toBe('iframe');
|
|
130
|
+
expect(iframes[0].src).toBe('http://localhost/app');
|
|
131
|
+
expect(closeOverlays).not.toHaveBeenCalled();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('closes overlays when iframes cannot go back', () => {
|
|
135
|
+
const closeOverlays = vi.fn();
|
|
136
|
+
expect(
|
|
137
|
+
goDesktopBack({
|
|
138
|
+
iframes: [mockIframe()],
|
|
139
|
+
overlaysOpen: true,
|
|
140
|
+
closeOverlays,
|
|
141
|
+
baseHref: 'http://localhost',
|
|
142
|
+
}),
|
|
143
|
+
).toBe('overlay');
|
|
144
|
+
expect(closeOverlays).toHaveBeenCalledOnce();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('falls back to router back for mirrored SPA navigations', () => {
|
|
148
|
+
const goRouterBack = vi.fn();
|
|
149
|
+
const back = vi.fn();
|
|
150
|
+
expect(
|
|
151
|
+
goDesktopBack({
|
|
152
|
+
iframes: [
|
|
153
|
+
mockIframe({
|
|
154
|
+
src: 'http://localhost:5173/#/',
|
|
155
|
+
contentWindow: {
|
|
156
|
+
location: { href: 'http://localhost:5173/#/layout' },
|
|
157
|
+
history: { back, forward: vi.fn() },
|
|
158
|
+
},
|
|
159
|
+
}),
|
|
160
|
+
],
|
|
161
|
+
goRouterBack,
|
|
162
|
+
baseHref: 'http://localhost:5173/',
|
|
163
|
+
}),
|
|
164
|
+
).toBe('router');
|
|
165
|
+
expect(goRouterBack).toHaveBeenCalledOnce();
|
|
166
|
+
expect(back).not.toHaveBeenCalled();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('falls back to router back when no iframe action applies', () => {
|
|
170
|
+
const goRouterBack = vi.fn();
|
|
171
|
+
expect(goDesktopBack({ iframes: [], goRouterBack })).toBe('router');
|
|
172
|
+
expect(goRouterBack).toHaveBeenCalledOnce();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('walks iframes from the topmost (last) entry for foreign resets', () => {
|
|
176
|
+
expect(goBackInIframes([])).toBe(false);
|
|
177
|
+
const top = mockIframe({
|
|
178
|
+
foreign: true,
|
|
179
|
+
src: 'http://localhost/modal',
|
|
180
|
+
});
|
|
181
|
+
top.src = 'https://accounts.example/login';
|
|
182
|
+
const result = goBackInIframes([mockIframe(), top], 'http://localhost');
|
|
183
|
+
expect(result).toBe(true);
|
|
184
|
+
expect(top.src).toBe('http://localhost/modal');
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('goDesktopForward', () => {
|
|
189
|
+
it('uses router forward (shell owns mirrored SPA history)', () => {
|
|
190
|
+
const location = { href: 'http://localhost/app' };
|
|
191
|
+
const forward = vi.fn(() => {
|
|
192
|
+
location.href = 'http://localhost/app/next';
|
|
193
|
+
});
|
|
194
|
+
const goRouterForward = vi.fn();
|
|
195
|
+
expect(
|
|
196
|
+
goDesktopForward({
|
|
197
|
+
iframes: [
|
|
198
|
+
mockIframe({
|
|
199
|
+
contentWindow: {
|
|
200
|
+
location,
|
|
201
|
+
history: { back: vi.fn(), forward },
|
|
202
|
+
},
|
|
203
|
+
}),
|
|
204
|
+
],
|
|
205
|
+
goRouterForward,
|
|
206
|
+
baseHref: 'http://localhost',
|
|
207
|
+
}),
|
|
208
|
+
).toBe('router');
|
|
209
|
+
expect(goRouterForward).toHaveBeenCalledOnce();
|
|
210
|
+
expect(forward).not.toHaveBeenCalled();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('falls back to router forward', () => {
|
|
214
|
+
const goRouterForward = vi.fn();
|
|
215
|
+
expect(goDesktopForward({ iframes: [], goRouterForward })).toBe('router');
|
|
216
|
+
expect(goRouterForward).toHaveBeenCalledOnce();
|
|
217
|
+
});
|
|
218
|
+
});
|