@shellui/core 0.4.0 → 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.spec.ts +77 -0
- package/src/features/modal/ModalContext.tsx +32 -57
- package/src/features/modal/validateAndNormalizeUrl.ts +96 -0
- 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/storage/StoragePickerContext.tsx +3 -3
- 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
|
@@ -9,7 +9,12 @@ import {
|
|
|
9
9
|
import { useLocation } from 'react-router';
|
|
10
10
|
import { useTranslation } from 'react-i18next';
|
|
11
11
|
import { shellui } from '@shellui/sdk';
|
|
12
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
NavigationItem,
|
|
14
|
+
NavigationGroup,
|
|
15
|
+
LocalizedString,
|
|
16
|
+
ThemeAsset,
|
|
17
|
+
} from '../../config/types';
|
|
13
18
|
import {
|
|
14
19
|
filterNavigationForAuthState,
|
|
15
20
|
flattenNavigationItems,
|
|
@@ -25,27 +30,45 @@ import { cn } from '../../../lib/utils';
|
|
|
25
30
|
import { Z_INDEX } from '../../../lib/z-index';
|
|
26
31
|
import { LoginButton } from '../../auth/components/LoginButton';
|
|
27
32
|
import { useAuth } from '../../auth/hooks/useAuth';
|
|
33
|
+
import { ExternalLinkIcon, NavIcon } from '../sidebar/SidebarIcons';
|
|
34
|
+
import { getExternalFaviconUrl, isAppIcon } from '../sidebar/sidebarUtils';
|
|
35
|
+
import { AppBrandIcon } from '../branding/AppBrandIcon';
|
|
28
36
|
|
|
29
37
|
interface WindowsLayoutProps {
|
|
30
38
|
title?: string;
|
|
31
|
-
appIcon?:
|
|
32
|
-
logo?:
|
|
39
|
+
appIcon?: ThemeAsset;
|
|
40
|
+
logo?: ThemeAsset;
|
|
33
41
|
navigation: (NavigationItem | NavigationGroup)[];
|
|
34
42
|
}
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
type StartSection =
|
|
45
|
+
| { type: 'group'; title: string | LocalizedString; items: NavigationItem[] }
|
|
46
|
+
| { type: 'items'; items: NavigationItem[] };
|
|
47
|
+
|
|
48
|
+
const isNavigationGroup = (item: NavigationItem | NavigationGroup): item is NavigationGroup =>
|
|
49
|
+
'title' in item && 'items' in item;
|
|
50
|
+
|
|
51
|
+
/** Keep navigation groups as labeled categories; consecutive loose items share one untitled section. */
|
|
52
|
+
function buildStartSections(start: (NavigationItem | NavigationGroup)[]): StartSection[] {
|
|
53
|
+
const sections: StartSection[] = [];
|
|
54
|
+
for (const entry of start) {
|
|
55
|
+
if (isNavigationGroup(entry)) {
|
|
56
|
+
const items = entry.items.filter((i) => !i.hidden);
|
|
57
|
+
if (items.length > 0) {
|
|
58
|
+
sections.push({ type: 'group', title: entry.title, items });
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (entry.hidden) continue;
|
|
63
|
+
const last = sections[sections.length - 1];
|
|
64
|
+
if (last?.type === 'items') {
|
|
65
|
+
last.items.push(entry);
|
|
66
|
+
} else {
|
|
67
|
+
sections.push({ type: 'items', items: [entry] });
|
|
68
|
+
}
|
|
44
69
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/** True when the icon is a local app icon (/icons/); apply theme (dark invert) so it matches foreground. */
|
|
48
|
-
const isAppIcon = (src: string) => src.startsWith('/icons/');
|
|
70
|
+
return sections;
|
|
71
|
+
}
|
|
49
72
|
|
|
50
73
|
const genId = () => `win-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
51
74
|
|
|
@@ -505,12 +528,7 @@ function getBrowserTimezone(): string {
|
|
|
505
528
|
return 'UTC';
|
|
506
529
|
}
|
|
507
530
|
|
|
508
|
-
export function WindowsLayout({
|
|
509
|
-
title,
|
|
510
|
-
appIcon: _appIcon,
|
|
511
|
-
logo: _logo,
|
|
512
|
-
navigation,
|
|
513
|
-
}: WindowsLayoutProps) {
|
|
531
|
+
export function WindowsLayout({ title, appIcon, logo: _logo, navigation }: WindowsLayoutProps) {
|
|
514
532
|
const location = useLocation();
|
|
515
533
|
const { i18n } = useTranslation();
|
|
516
534
|
const { isAuthenticated } = useAuth();
|
|
@@ -523,10 +541,10 @@ export function WindowsLayout({
|
|
|
523
541
|
[navigation, isAuthenticated, settings.developerFeatures.enabled],
|
|
524
542
|
);
|
|
525
543
|
const timeZone = settings.region?.timezone ?? getBrowserTimezone();
|
|
526
|
-
const {
|
|
544
|
+
const { startSections, endNavItems, navigationItems } = useMemo(() => {
|
|
527
545
|
const { start, end } = splitNavigationByPosition(authAwareNavigation);
|
|
528
546
|
return {
|
|
529
|
-
|
|
547
|
+
startSections: buildStartSections(start),
|
|
530
548
|
endNavItems: end,
|
|
531
549
|
navigationItems: flattenNavigationItems(authAwareNavigation),
|
|
532
550
|
};
|
|
@@ -539,6 +557,7 @@ export function WindowsLayout({
|
|
|
539
557
|
const [now, setNow] = useState(() => new Date());
|
|
540
558
|
const startPanelRef = useRef<HTMLDivElement>(null);
|
|
541
559
|
const initialOpenFromUrlDoneRef = useRef(false);
|
|
560
|
+
const openPaths = useMemo(() => new Set(windows.map((w) => w.path)), [windows]);
|
|
542
561
|
|
|
543
562
|
// Update date/time every second for taskbar clock
|
|
544
563
|
useEffect(() => {
|
|
@@ -653,17 +672,38 @@ export function WindowsLayout({
|
|
|
653
672
|
setStartMenuOpen(false);
|
|
654
673
|
return;
|
|
655
674
|
}
|
|
675
|
+
const existing = windows.find((w) => w.path === item.path);
|
|
676
|
+
if (existing) {
|
|
677
|
+
focusWindow(existing.id);
|
|
678
|
+
setStartMenuOpen(false);
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
656
681
|
openWindow(item);
|
|
657
682
|
},
|
|
658
|
-
[openWindow],
|
|
683
|
+
[openWindow, windows, focusWindow],
|
|
659
684
|
);
|
|
660
685
|
|
|
661
686
|
return (
|
|
662
687
|
<>
|
|
663
688
|
<div
|
|
664
|
-
className="fixed inset-0 bg-
|
|
689
|
+
className="fixed inset-0 overflow-hidden bg-background"
|
|
665
690
|
style={{ paddingBottom: TASKBAR_HEIGHT }}
|
|
666
691
|
>
|
|
692
|
+
{/* Organic primary wash behind windows — follows --primary with the active theme. */}
|
|
693
|
+
<div
|
|
694
|
+
aria-hidden
|
|
695
|
+
className="pointer-events-none absolute inset-0"
|
|
696
|
+
style={{
|
|
697
|
+
backgroundImage: [
|
|
698
|
+
'radial-gradient(ellipse 95% 70% at 18% 108%, color-mix(in oklch, var(--primary) 32%, transparent), transparent 58%)',
|
|
699
|
+
'radial-gradient(ellipse 70% 55% at 78% 118%, color-mix(in oklch, var(--primary) 22%, transparent), transparent 62%)',
|
|
700
|
+
'radial-gradient(ellipse 55% 40% at 52% 92%, color-mix(in oklch, var(--primary) 14%, transparent), transparent 70%)',
|
|
701
|
+
'radial-gradient(ellipse 40% 30% at 92% 78%, color-mix(in oklch, var(--primary) 10%, transparent), transparent 68%)',
|
|
702
|
+
'radial-gradient(ellipse 35% 28% at 8% 72%, color-mix(in oklch, var(--primary) 8%, transparent), transparent 65%)',
|
|
703
|
+
].join(', '),
|
|
704
|
+
}}
|
|
705
|
+
/>
|
|
706
|
+
|
|
667
707
|
{/* Desktop area: windows */}
|
|
668
708
|
{windows.map((win, index) => {
|
|
669
709
|
const navItem = navigationItems.find((n) => n.path === win.path);
|
|
@@ -714,54 +754,126 @@ export function WindowsLayout({
|
|
|
714
754
|
aria-haspopup="true"
|
|
715
755
|
aria-label="Start"
|
|
716
756
|
>
|
|
717
|
-
|
|
757
|
+
{appIcon ? (
|
|
758
|
+
<AppBrandIcon
|
|
759
|
+
appIcon={appIcon}
|
|
760
|
+
title={title}
|
|
761
|
+
linkToHome={false}
|
|
762
|
+
imgClassName="windows-app-icon size-5"
|
|
763
|
+
/>
|
|
764
|
+
) : (
|
|
765
|
+
<StartIcon className="h-5 w-5" />
|
|
766
|
+
)}
|
|
718
767
|
<span className="font-semibold text-sm hidden sm:inline">{title || 'Start'}</span>
|
|
719
768
|
</button>
|
|
720
769
|
{/* Start menu panel */}
|
|
721
770
|
{startMenuOpen && (
|
|
722
771
|
<div
|
|
723
|
-
className="absolute bottom-full left-0 mb-
|
|
772
|
+
className="absolute bottom-full left-0 mb-2 flex w-[22rem] max-h-[min(72vh,34rem)] flex-col overflow-hidden rounded-xl border border-border/80 bg-popover/95 text-popover-foreground shadow-xl backdrop-blur-md"
|
|
724
773
|
style={{ zIndex: Z_INDEX.MODAL_CONTENT }}
|
|
774
|
+
role="menu"
|
|
775
|
+
aria-label={title || 'Applications'}
|
|
725
776
|
>
|
|
726
|
-
<div className="
|
|
727
|
-
<
|
|
777
|
+
<div className="shrink-0 border-b border-border/60 px-4 py-3">
|
|
778
|
+
<p
|
|
779
|
+
className="text-sm font-semibold tracking-tight"
|
|
780
|
+
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
781
|
+
>
|
|
728
782
|
{title || 'Applications'}
|
|
729
|
-
</
|
|
783
|
+
</p>
|
|
784
|
+
<p className="mt-0.5 text-xs text-muted-foreground">
|
|
785
|
+
Choose an app to open in a window
|
|
786
|
+
</p>
|
|
730
787
|
</div>
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
const
|
|
740
|
-
|
|
741
|
-
|
|
788
|
+
|
|
789
|
+
<div className="min-h-0 flex-1 space-y-4 overflow-y-auto px-2 py-3">
|
|
790
|
+
{startSections.length === 0 ? (
|
|
791
|
+
<p className="px-2 py-6 text-center text-sm text-muted-foreground">
|
|
792
|
+
No applications available
|
|
793
|
+
</p>
|
|
794
|
+
) : (
|
|
795
|
+
startSections.map((section, sectionIndex) => {
|
|
796
|
+
const categoryLabel =
|
|
797
|
+
section.type === 'group'
|
|
798
|
+
? resolveNavLabel(section.title, currentLanguage)
|
|
799
|
+
: null;
|
|
742
800
|
return (
|
|
743
|
-
<
|
|
744
|
-
key={
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
801
|
+
<section
|
|
802
|
+
key={
|
|
803
|
+
section.type === 'group'
|
|
804
|
+
? `group-${categoryLabel}-${sectionIndex}`
|
|
805
|
+
: `items-${sectionIndex}`
|
|
806
|
+
}
|
|
807
|
+
className="space-y-1.5"
|
|
748
808
|
>
|
|
749
|
-
{
|
|
750
|
-
<
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
809
|
+
{categoryLabel ? (
|
|
810
|
+
<h2
|
|
811
|
+
className="px-2.5 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground"
|
|
812
|
+
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
813
|
+
>
|
|
814
|
+
{categoryLabel}
|
|
815
|
+
</h2>
|
|
816
|
+
) : null}
|
|
817
|
+
<div className="space-y-0.5">
|
|
818
|
+
{section.items.map((item) => {
|
|
819
|
+
const label = resolveNavLabel(item.label, currentLanguage);
|
|
820
|
+
const isExternal = item.openIn === 'external';
|
|
821
|
+
const isOverlay = item.openIn === 'modal' || item.openIn === 'drawer';
|
|
822
|
+
const icon =
|
|
823
|
+
item.icon ?? (isExternal ? getExternalFaviconUrl(item.url) : null);
|
|
824
|
+
const isOpen = openPaths.has(item.path);
|
|
825
|
+
return (
|
|
826
|
+
<button
|
|
827
|
+
key={item.path}
|
|
828
|
+
type="button"
|
|
829
|
+
role="menuitem"
|
|
830
|
+
onClick={() => handleNavClick(item)}
|
|
831
|
+
className={cn(
|
|
832
|
+
'group flex w-full items-center gap-3 rounded-lg px-2 py-2 text-left transition-colors',
|
|
833
|
+
'cursor-pointer text-popover-foreground',
|
|
834
|
+
'hover:bg-accent hover:text-accent-foreground',
|
|
835
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-popover',
|
|
836
|
+
isOpen && 'bg-accent/50',
|
|
837
|
+
)}
|
|
838
|
+
>
|
|
839
|
+
<span
|
|
840
|
+
className={cn(
|
|
841
|
+
'flex size-9 shrink-0 items-center justify-center rounded-md',
|
|
842
|
+
'bg-muted/70 text-foreground ring-1 ring-border/50',
|
|
843
|
+
'group-hover:bg-background/80 group-hover:ring-border',
|
|
844
|
+
)}
|
|
845
|
+
>
|
|
846
|
+
<NavIcon
|
|
847
|
+
src={icon}
|
|
848
|
+
className="size-4"
|
|
849
|
+
/>
|
|
850
|
+
</span>
|
|
851
|
+
<span className="min-w-0 flex-1">
|
|
852
|
+
<span className="block truncate text-sm font-medium leading-tight">
|
|
853
|
+
{label}
|
|
854
|
+
</span>
|
|
855
|
+
{isOpen && !isOverlay && !isExternal ? (
|
|
856
|
+
<span className="mt-0.5 block text-[11px] text-muted-foreground">
|
|
857
|
+
Open
|
|
858
|
+
</span>
|
|
859
|
+
) : null}
|
|
860
|
+
</span>
|
|
861
|
+
{isExternal ? (
|
|
862
|
+
<ExternalLinkIcon className="size-3.5 shrink-0 opacity-50 group-hover:opacity-80" />
|
|
863
|
+
) : isOpen && !isOverlay ? (
|
|
864
|
+
<span
|
|
865
|
+
className="size-1.5 shrink-0 rounded-full bg-primary"
|
|
866
|
+
aria-hidden
|
|
867
|
+
/>
|
|
868
|
+
) : null}
|
|
869
|
+
</button>
|
|
870
|
+
);
|
|
871
|
+
})}
|
|
872
|
+
</div>
|
|
873
|
+
</section>
|
|
763
874
|
);
|
|
764
|
-
})
|
|
875
|
+
})
|
|
876
|
+
)}
|
|
765
877
|
</div>
|
|
766
878
|
</div>
|
|
767
879
|
)}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { DEFAULT_ADMIN_URL } from '../admin/config';
|
|
3
|
+
import type { ShellUIConfig } from '../config/types';
|
|
4
|
+
import { validateAndNormalizeUrl } from './validateAndNormalizeUrl';
|
|
5
|
+
|
|
6
|
+
const config = {
|
|
7
|
+
storage: {
|
|
8
|
+
url: 'https://storage.example.com/',
|
|
9
|
+
filesUrl: 'https://files.example.com/',
|
|
10
|
+
},
|
|
11
|
+
backend: {
|
|
12
|
+
type: 'shellui',
|
|
13
|
+
url: 'https://api.example.com',
|
|
14
|
+
adminUrl: 'https://admin.example.com',
|
|
15
|
+
},
|
|
16
|
+
administration: {
|
|
17
|
+
title: 'Apps',
|
|
18
|
+
navigation: [
|
|
19
|
+
{
|
|
20
|
+
label: 'Billing',
|
|
21
|
+
path: 'billing',
|
|
22
|
+
url: 'https://billing.example.com/app',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: 'Django admin',
|
|
26
|
+
path: 'django-admin',
|
|
27
|
+
url: 'https://untrusted.example.com/admin',
|
|
28
|
+
openIn: 'external',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
} as ShellUIConfig;
|
|
33
|
+
|
|
34
|
+
describe('validateAndNormalizeUrl', () => {
|
|
35
|
+
it('allows relative paths', () => {
|
|
36
|
+
expect(validateAndNormalizeUrl('/settings')).toBe('/settings');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('allows localhost urls', () => {
|
|
40
|
+
expect(validateAndNormalizeUrl('http://localhost:5175/#/select')).toBe(
|
|
41
|
+
'http://localhost:5175/#/select',
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('rejects unrelated origins', () => {
|
|
46
|
+
expect(validateAndNormalizeUrl('https://evil.example.com/form', config)).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('allows storage.url and storage.filesUrl origins', () => {
|
|
50
|
+
expect(validateAndNormalizeUrl('https://storage.example.com/storage/v1/quota', config)).toBe(
|
|
51
|
+
'https://storage.example.com/storage/v1/quota',
|
|
52
|
+
);
|
|
53
|
+
expect(validateAndNormalizeUrl('https://files.example.com/#/select?mode=files', config)).toBe(
|
|
54
|
+
'https://files.example.com/#/select?mode=files',
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('allows the configured administration adminUrl', () => {
|
|
59
|
+
expect(validateAndNormalizeUrl('https://admin.example.com/#/users', config)).toBe(
|
|
60
|
+
'https://admin.example.com/#/users',
|
|
61
|
+
);
|
|
62
|
+
expect(validateAndNormalizeUrl(`${DEFAULT_ADMIN_URL}/#/users`, config)).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('allows the default administration url when adminUrl is not configured', () => {
|
|
66
|
+
expect(validateAndNormalizeUrl(`${DEFAULT_ADMIN_URL}/#/dashboard`)).toBe(
|
|
67
|
+
`${DEFAULT_ADMIN_URL}/#/dashboard`,
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('allows administration navigation urls but not external ones', () => {
|
|
72
|
+
expect(validateAndNormalizeUrl('https://billing.example.com/app/#/invoices', config)).toBe(
|
|
73
|
+
'https://billing.example.com/app/#/invoices',
|
|
74
|
+
);
|
|
75
|
+
expect(validateAndNormalizeUrl('https://untrusted.example.com/admin', config)).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -1,56 +1,15 @@
|
|
|
1
|
-
import { shellui, type ShellUIMessage } from '@shellui/sdk';
|
|
1
|
+
import { shellui, type OpenModalOptions, type ShellUIMessage } from '@shellui/sdk';
|
|
2
2
|
import { createContext, useContext, useState, useEffect, useCallback, type ReactNode } from 'react';
|
|
3
|
+
import { useConfig } from '../config/useConfig';
|
|
4
|
+
import { validateAndNormalizeUrl } from './validateAndNormalizeUrl';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
* Validates and normalizes a URL to ensure it's from the same domain or localhost
|
|
6
|
-
* @param url - The URL or path to validate
|
|
7
|
-
* @returns The normalized absolute URL or null if invalid
|
|
8
|
-
*/
|
|
9
|
-
export const validateAndNormalizeUrl = (url: string | undefined | null): string | null => {
|
|
10
|
-
if (!url || typeof url !== 'string') {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
// If it's already an absolute URL, check if it's same origin or localhost
|
|
16
|
-
if (url.startsWith('http://') || url.startsWith('https://')) {
|
|
17
|
-
const urlObj = new URL(url);
|
|
18
|
-
const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
|
|
19
|
-
|
|
20
|
-
// Allow same origin
|
|
21
|
-
if (urlObj.origin === currentOrigin) {
|
|
22
|
-
return url;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Allow localhost URLs (for development)
|
|
26
|
-
if (urlObj.hostname === 'localhost' || urlObj.hostname === '127.0.0.1') {
|
|
27
|
-
return url;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return null; // Different origin, reject for security
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// If it's a relative URL, make it absolute using current origin
|
|
34
|
-
if (url.startsWith('/') || url.startsWith('./') || !url.startsWith('//')) {
|
|
35
|
-
const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
|
|
36
|
-
// Ensure relative paths start with /
|
|
37
|
-
const normalizedPath = url.startsWith('/') ? url : `/${url}`;
|
|
38
|
-
return `${currentOrigin}${normalizedPath}`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Reject protocol-relative URLs (//example.com) for security
|
|
42
|
-
return null;
|
|
43
|
-
} catch (error) {
|
|
44
|
-
// eslint-disable-next-line no-console
|
|
45
|
-
console.error('Invalid URL:', url, error);
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
6
|
+
export { validateAndNormalizeUrl } from './validateAndNormalizeUrl';
|
|
49
7
|
|
|
50
8
|
interface ModalContextValue {
|
|
51
9
|
isOpen: boolean;
|
|
52
10
|
modalUrl: string | null;
|
|
53
|
-
|
|
11
|
+
options: OpenModalOptions | null;
|
|
12
|
+
openModal: (urlOrOptions?: string | OpenModalOptions) => void;
|
|
54
13
|
closeModal: () => void;
|
|
55
14
|
}
|
|
56
15
|
|
|
@@ -69,19 +28,32 @@ interface ModalProviderProps {
|
|
|
69
28
|
}
|
|
70
29
|
|
|
71
30
|
export const ModalProvider = ({ children }: ModalProviderProps) => {
|
|
31
|
+
const { config } = useConfig();
|
|
72
32
|
const [isOpen, setIsOpen] = useState(false);
|
|
73
33
|
const [modalUrl, setModalUrl] = useState<string | null>(null);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
34
|
+
const [options, setOptions] = useState<OpenModalOptions | null>(null);
|
|
35
|
+
|
|
36
|
+
const openModal = useCallback(
|
|
37
|
+
(urlOrOptions?: string | OpenModalOptions) => {
|
|
38
|
+
const opts: OpenModalOptions =
|
|
39
|
+
typeof urlOrOptions === 'string' || urlOrOptions === undefined
|
|
40
|
+
? { url: urlOrOptions }
|
|
41
|
+
: urlOrOptions;
|
|
42
|
+
const validatedUrl = opts.url ? validateAndNormalizeUrl(opts.url, config) : null;
|
|
43
|
+
setModalUrl(validatedUrl);
|
|
44
|
+
setOptions(opts);
|
|
45
|
+
setIsOpen(true);
|
|
46
|
+
},
|
|
47
|
+
[config],
|
|
48
|
+
);
|
|
80
49
|
|
|
81
50
|
const closeModal = useCallback(() => {
|
|
82
51
|
setIsOpen(false);
|
|
83
52
|
// Clear URL after a short delay to allow animation to complete
|
|
84
|
-
setTimeout(() =>
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
setModalUrl(null);
|
|
55
|
+
setOptions(null);
|
|
56
|
+
}, 200);
|
|
85
57
|
}, []);
|
|
86
58
|
|
|
87
59
|
// Listen for postMessage events from nested iframes
|
|
@@ -89,8 +61,11 @@ export const ModalProvider = ({ children }: ModalProviderProps) => {
|
|
|
89
61
|
const cleanupOpenModal = shellui.addMessageListener(
|
|
90
62
|
'SHELLUI_OPEN_MODAL',
|
|
91
63
|
(data: ShellUIMessage) => {
|
|
92
|
-
const payload = data.payload as { url?: string };
|
|
93
|
-
openModal(
|
|
64
|
+
const payload = data.payload as OpenModalOptions & { url?: string | null };
|
|
65
|
+
openModal({
|
|
66
|
+
...payload,
|
|
67
|
+
url: payload.url ?? undefined,
|
|
68
|
+
});
|
|
94
69
|
},
|
|
95
70
|
);
|
|
96
71
|
|
|
@@ -105,7 +80,7 @@ export const ModalProvider = ({ children }: ModalProviderProps) => {
|
|
|
105
80
|
}, [openModal, closeModal]);
|
|
106
81
|
|
|
107
82
|
return (
|
|
108
|
-
<ModalContext.Provider value={{ isOpen, modalUrl, openModal, closeModal }}>
|
|
83
|
+
<ModalContext.Provider value={{ isOpen, modalUrl, options, openModal, closeModal }}>
|
|
109
84
|
{children}
|
|
110
85
|
</ModalContext.Provider>
|
|
111
86
|
);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { getAdminContentUrl } from '../admin/config';
|
|
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
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Origins allowed in modal iframes: storage service/files app, admin panel, and administration nav apps. */
|
|
20
|
+
const getAllowedModalOrigins = (config?: ShellUIConfig | null): Set<string> => {
|
|
21
|
+
const origins = new Set<string>();
|
|
22
|
+
const add = (value?: string | null) => {
|
|
23
|
+
const origin = originFromAbsoluteUrl(value);
|
|
24
|
+
if (origin) {
|
|
25
|
+
origins.add(origin);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
add(config?.storage?.url);
|
|
30
|
+
add(config?.storage?.filesUrl);
|
|
31
|
+
add(getAdminContentUrl(config ?? undefined));
|
|
32
|
+
|
|
33
|
+
for (const item of config?.administration?.navigation ?? []) {
|
|
34
|
+
if (item.openIn === 'external') {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
add(item.url);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return origins;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Validates and normalizes a URL to ensure it's from the same domain, localhost,
|
|
45
|
+
* storage, or administration origins configured on the host.
|
|
46
|
+
* @param url - The URL or path to validate
|
|
47
|
+
* @param config - Host config used to allow storage and administration origins
|
|
48
|
+
* @returns The normalized absolute URL or null if invalid
|
|
49
|
+
*/
|
|
50
|
+
export const validateAndNormalizeUrl = (
|
|
51
|
+
url: string | undefined | null,
|
|
52
|
+
config?: ShellUIConfig | null,
|
|
53
|
+
): string | null => {
|
|
54
|
+
if (!url || typeof url !== 'string') {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
// If it's already an absolute URL, check if it's same origin, localhost, or trusted
|
|
60
|
+
if (url.startsWith('http://') || url.startsWith('https://')) {
|
|
61
|
+
const urlObj = new URL(url);
|
|
62
|
+
const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
|
|
63
|
+
|
|
64
|
+
// Allow same origin
|
|
65
|
+
if (urlObj.origin === currentOrigin) {
|
|
66
|
+
return url;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Allow localhost URLs (for development)
|
|
70
|
+
if (urlObj.hostname === 'localhost' || urlObj.hostname === '127.0.0.1') {
|
|
71
|
+
return url;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (getAllowedModalOrigins(config).has(urlObj.origin)) {
|
|
75
|
+
return url;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return null; // Different origin, reject for security
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// If it's a relative URL, make it absolute using current origin
|
|
82
|
+
if (url.startsWith('/') || url.startsWith('./') || !url.startsWith('//')) {
|
|
83
|
+
const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
|
|
84
|
+
// Ensure relative paths start with /
|
|
85
|
+
const normalizedPath = url.startsWith('/') ? url : `/${url}`;
|
|
86
|
+
return `${currentOrigin}${normalizedPath}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Reject protocol-relative URLs (//example.com) for security
|
|
90
|
+
return null;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
// eslint-disable-next-line no-console
|
|
93
|
+
console.error('Invalid URL:', url, error);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LOADING_OVERLAY_DURATION_MS } from '../../constants/loading';
|
|
2
|
+
import { DYNAMIC_DRAWER_PENDING_PX } from './overlaySize';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Full-bleed loading bar for dynamic drawers while waiting for the first size report.
|
|
6
|
+
* Matches drawer pending chrome height so the strip is the animation.
|
|
7
|
+
*/
|
|
8
|
+
export function OverlayDrawerPendingBar() {
|
|
9
|
+
return (
|
|
10
|
+
<div
|
|
11
|
+
className="absolute inset-0 z-20 overflow-hidden bg-muted/30"
|
|
12
|
+
style={{ minHeight: DYNAMIC_DRAWER_PENDING_PX }}
|
|
13
|
+
aria-busy="true"
|
|
14
|
+
aria-live="polite"
|
|
15
|
+
>
|
|
16
|
+
<div
|
|
17
|
+
className="h-full w-0 bg-muted-foreground/40"
|
|
18
|
+
style={{
|
|
19
|
+
animation: `loading-bar-slide ${LOADING_OVERLAY_DURATION_MS}ms linear infinite`,
|
|
20
|
+
}}
|
|
21
|
+
aria-hidden
|
|
22
|
+
/>
|
|
23
|
+
<span className="sr-only">Loading</span>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|