@donotdev/ui 0.3.1 → 0.3.2
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/dist/components/auth/AuthHeader.js +1 -93
- package/dist/components/auth/AuthMenu.d.ts.map +1 -1
- package/dist/components/auth/AuthMenu.js +3 -286
- package/dist/components/auth/index.js +1 -9
- package/dist/components/common/FeatureCard.d.ts.map +1 -1
- package/dist/components/common/FeatureCard.js +1 -86
- package/dist/components/common/FeatureDisabled.js +1 -67
- package/dist/components/common/IconPlaceholder.d.ts +24 -0
- package/dist/components/common/IconPlaceholder.d.ts.map +1 -0
- package/dist/components/common/IconPlaceholder.js +1 -0
- package/dist/components/common/LazyLucideIcon.d.ts +39 -0
- package/dist/components/common/LazyLucideIcon.d.ts.map +1 -0
- package/dist/components/common/LazyLucideIcon.js +1 -0
- package/dist/components/common/ProgressBar.js +1 -84
- package/dist/components/common/RedirectOverlay.js +1 -243
- package/dist/components/common/Skeleton.js +1 -144
- package/dist/components/common/TechBento.d.ts.map +1 -1
- package/dist/components/common/TechBento.js +1 -53
- package/dist/components/common/icon.d.ts +1 -1
- package/dist/components/common/icon.d.ts.map +1 -1
- package/dist/components/common/icon.js +1 -84
- package/dist/components/common/iconByName.d.ts +33 -0
- package/dist/components/common/iconByName.d.ts.map +1 -0
- package/dist/components/common/iconByName.js +1 -0
- package/dist/components/common/index.js +1 -16
- package/dist/components/cookie-consent/ConsentBanner.d.ts +3 -1
- package/dist/components/cookie-consent/ConsentBanner.d.ts.map +1 -1
- package/dist/components/cookie-consent/ConsentBanner.js +1 -31
- package/dist/components/cookie-consent/CookieConsent.d.ts.map +1 -1
- package/dist/components/cookie-consent/CookieConsent.js +1 -183
- package/dist/components/cookie-consent/index.js +1 -11
- package/dist/components/cookie-consent/useCookieNoticeRequired.d.ts +7 -0
- package/dist/components/cookie-consent/useCookieNoticeRequired.d.ts.map +1 -0
- package/dist/components/cookie-consent/useCookieNoticeRequired.js +1 -0
- package/dist/components/index.js +1 -13
- package/dist/components/layout/GameContainer.d.ts.map +1 -1
- package/dist/components/layout/GameContainer.js +1 -72
- package/dist/components/layout/GameFlow.d.ts.map +1 -1
- package/dist/components/layout/GameFlow.js +1 -93
- package/dist/components/layout/PageConfig.d.ts.map +1 -1
- package/dist/components/layout/PageConfig.js +1 -47
- package/dist/components/layout/PageContainer.d.ts.map +1 -1
- package/dist/components/layout/PageContainer.js +1 -38
- package/dist/components/layout/components/Breadcrumbs.d.ts +2 -1
- package/dist/components/layout/components/Breadcrumbs.d.ts.map +1 -1
- package/dist/components/layout/components/Breadcrumbs.js +1 -89
- package/dist/components/layout/components/DropdownNavigation.d.ts.map +1 -1
- package/dist/components/layout/components/DropdownNavigation.js +1 -30
- package/dist/components/layout/components/FloatingLanguageSwitcher.d.ts.map +1 -1
- package/dist/components/layout/components/FloatingLanguageSwitcher.js +1 -26
- package/dist/components/layout/components/Notifications.js +1 -182
- package/dist/components/layout/components/header/AppBranding.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppBranding.js +1 -54
- package/dist/components/layout/components/header/AppIcon.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppIcon.js +1 -59
- package/dist/components/layout/components/header/AppTitle.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppTitle.js +1 -40
- package/dist/components/layout/components/header/CacheSettings.js +1 -225
- package/dist/components/layout/components/header/GameTitle.d.ts.map +1 -1
- package/dist/components/layout/components/header/GameTitle.js +1 -66
- package/dist/components/layout/components/header/HeaderMenu.js +1 -75
- package/dist/components/layout/components/header/HeaderNavigation.d.ts.map +1 -1
- package/dist/components/layout/components/header/HeaderNavigation.js +1 -66
- package/dist/components/layout/components/header/SettingsMenu.d.ts.map +1 -1
- package/dist/components/layout/components/header/SettingsMenu.js +1 -85
- package/dist/components/layout/components/header/ThemeToggle.d.ts.map +1 -1
- package/dist/components/layout/components/header/ThemeToggle.js +1 -93
- package/dist/components/layout/components/index.js +1 -25
- package/dist/components/layout/index.js +1 -14
- package/dist/crud/components/ChildRowsPicker.js +1 -68
- package/dist/crud/components/CrudCardLink.js +1 -14
- package/dist/crud/components/EntityCardList.js +1 -184
- package/dist/crud/components/EntityDisplayRenderer.js +1 -130
- package/dist/crud/components/EntityFormRenderer.js +1 -433
- package/dist/crud/components/EntityList.js +1 -521
- package/dist/crud/components/EntityRecommendations.js +1 -87
- package/dist/crud/components/EntityWorkflow.js +1 -55
- package/dist/crud/components/Form.d.ts.map +1 -1
- package/dist/crud/components/Form.js +1 -198
- package/dist/crud/components/cellEditFor.js +1 -74
- package/dist/crud/components/entityParent.js +1 -76
- package/dist/crud/components/index.js +1 -16
- package/dist/crud/components/useRecordBreadcrumb.d.ts.map +1 -1
- package/dist/crud/components/useRecordBreadcrumb.js +1 -43
- package/dist/crud/crudImports.js +1 -51
- package/dist/crud/index.js +1 -11
- package/dist/data/techLogos.js +1 -99
- package/dist/dndev-next.css +25 -4
- package/dist/dndev.css +25 -4
- package/dist/index.js +1 -5
- package/dist/internal/common/DnDevErrorBoundary.js +1 -55
- package/dist/internal/common/ErrorFallback.js +3 -214
- package/dist/internal/common/GlobalErrorFallback.js +1 -45
- package/dist/internal/common/RouteErrorFallback.js +3 -140
- package/dist/internal/devtools/DebugTools.js +1 -131
- package/dist/internal/devtools/components/AuthDebugButton.js +1 -72
- package/dist/internal/devtools/components/ConfigTab.js +1 -61
- package/dist/internal/devtools/components/CookieTab.js +1 -156
- package/dist/internal/devtools/components/DebugDialog.js +1 -48
- package/dist/internal/devtools/components/DesignTab.js +1 -469
- package/dist/internal/devtools/components/LayoutReset.js +1 -214
- package/dist/internal/devtools/components/MaskedValue.js +1 -39
- package/dist/internal/devtools/components/StoresTab.js +1 -90
- package/dist/internal/devtools/components/index.js +1 -16
- package/dist/internal/devtools/index.js +1 -13
- package/dist/internal/devtools/types.js +0 -2
- package/dist/internal/devtools/utils/envVarDiscovery.js +1 -106
- package/dist/internal/devtools/utils/index.js +1 -12
- package/dist/internal/devtools/utils/maskSensitive.js +1 -59
- package/dist/internal/devtools/utils/virtualModuleInspector.js +1 -309
- package/dist/internal/initializers/BaseStoresInitializer.js +1 -367
- package/dist/internal/initializers/NextJsStoresInitializer.js +1 -78
- package/dist/internal/initializers/ViteStoresInitializer.js +1 -20
- package/dist/internal/initializers/index.js +1 -11
- package/dist/internal/layout/DnDevLayout.js +1 -321
- package/dist/internal/layout/components/AutoMetaTags.d.ts +2 -0
- package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
- package/dist/internal/layout/components/AutoMetaTags.js +1 -338
- package/dist/internal/layout/components/FaviconHead.js +1 -60
- package/dist/internal/layout/components/FontPreloadLinks.js +1 -31
- package/dist/internal/layout/components/HeadTags.js +1 -20
- package/dist/internal/layout/components/PWAUpdateNotification.js +1 -131
- package/dist/internal/layout/components/footer/FooterBranding.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterBranding.js +1 -35
- package/dist/internal/layout/components/footer/FooterCopyright.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterCopyright.js +1 -37
- package/dist/internal/layout/components/footer/FooterLegalLinks.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterLegalLinks.js +1 -44
- package/dist/internal/layout/components/footer/useLegalLinks.d.ts +4 -2
- package/dist/internal/layout/components/footer/useLegalLinks.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/useLegalLinks.js +1 -21
- package/dist/internal/layout/components/i18nSeoMeta.js +1 -53
- package/dist/internal/layout/components/index.js +1 -13
- package/dist/internal/layout/config/defaults.js +1 -47
- package/dist/internal/layout/config/index.js +1 -11
- package/dist/internal/layout/config/presets/admin.js +1 -35
- package/dist/internal/layout/config/presets/blog.js +1 -31
- package/dist/internal/layout/config/presets/docs.js +1 -51
- package/dist/internal/layout/config/presets/game.js +1 -53
- package/dist/internal/layout/config/presets/index.js +1 -24
- package/dist/internal/layout/config/presets/landing.js +1 -42
- package/dist/internal/layout/config/presets/moolti.js +1 -52
- package/dist/internal/layout/config/presets/plain.js +1 -25
- package/dist/internal/layout/renderers/index.js +0 -10
- package/dist/internal/layout/zones/DnDevFooter.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevFooter.js +1 -67
- package/dist/internal/layout/zones/DnDevHeader.js +1 -41
- package/dist/internal/layout/zones/DnDevMergedBar.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevMergedBar.js +1 -52
- package/dist/internal/layout/zones/DnDevSidebar.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevSidebar.js +1 -181
- package/dist/internal/layout/zones/index.js +1 -14
- package/dist/internal/providers/NavigationProvider.d.ts.map +1 -1
- package/dist/internal/providers/NavigationProvider.js +1 -71
- package/dist/internal/providers/SentryInitializer.d.ts.map +1 -1
- package/dist/internal/providers/SentryInitializer.js +1 -36
- package/dist/internal/providers/UIProviders.js +1 -79
- package/dist/internal/providers/index.js +1 -12
- package/dist/next.js +1 -11
- package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
- package/dist/providers/NextJsAppProviders.js +1 -107
- package/dist/providers/ViteAppProviders.d.ts.map +1 -1
- package/dist/providers/ViteAppProviders.js +1 -117
- package/dist/providers/index.js +1 -11
- package/dist/routing/404.js +1 -108
- package/dist/routing/AuthGuard.js +1 -178
- package/dist/routing/AuthGuardFallback.d.ts.map +1 -1
- package/dist/routing/AuthGuardFallback.js +1 -67
- package/dist/routing/AuthReturnTo.js +1 -68
- package/dist/routing/DnDevNavigationMenu.d.ts.map +1 -1
- package/dist/routing/DnDevNavigationMenu.js +1 -138
- package/dist/routing/GoTo.d.ts.map +1 -1
- package/dist/routing/GoTo.js +1 -38
- package/dist/routing/GoToDialog.d.ts.map +1 -1
- package/dist/routing/GoToDialog.js +1 -97
- package/dist/routing/GoToInput.d.ts.map +1 -1
- package/dist/routing/GoToInput.js +1 -49
- package/dist/routing/GoToWrapper.d.ts.map +1 -1
- package/dist/routing/GoToWrapper.js +1 -59
- package/dist/routing/Link.d.ts +10 -2
- package/dist/routing/Link.d.ts.map +1 -1
- package/dist/routing/Link.js +1 -109
- package/dist/routing/NavigationItem.d.ts.map +1 -1
- package/dist/routing/NavigationItem.js +1 -44
- package/dist/routing/NotFoundDocument.d.ts +33 -0
- package/dist/routing/NotFoundDocument.d.ts.map +1 -0
- package/dist/routing/NotFoundDocument.js +1 -0
- package/dist/routing/SignedInRedirect.js +1 -47
- package/dist/routing/hooks/hooks.vite.js +1 -1
- package/dist/routing/hooks/index.js +1 -26
- package/dist/routing/hooks/types.js +0 -2
- package/dist/routing/hooks/useLocation.next.js +1 -35
- package/dist/routing/hooks/useLocation.vite.js +1 -13
- package/dist/routing/hooks/useMatch.next.js +1 -31
- package/dist/routing/hooks/useMatch.vite.js +1 -6
- package/dist/routing/hooks/useNavigate.next.js +1 -64
- package/dist/routing/hooks/useNavigate.vite.js +1 -61
- package/dist/routing/hooks/useParams.next.js +1 -9
- package/dist/routing/hooks/useParams.vite.js +1 -6
- package/dist/routing/hooks/useQueryParams.next.js +1 -66
- package/dist/routing/hooks/useQueryParams.vite.js +1 -66
- package/dist/routing/hooks/useRedirectGuard.next.js +1 -119
- package/dist/routing/hooks/useRedirectGuard.vite.js +1 -117
- package/dist/routing/hooks/useRouteParam.next.js +1 -38
- package/dist/routing/hooks/useRouteParam.vite.js +1 -38
- package/dist/routing/hooks/useRoutePath.next.js +1 -36
- package/dist/routing/hooks/useRoutePath.vite.js +1 -25
- package/dist/routing/hooks/useSearchParams.next.js +1 -22
- package/dist/routing/hooks/useSearchParams.vite.js +1 -22
- package/dist/routing/hooks/useUrlLanguage.next.js +1 -50
- package/dist/routing/hooks/useUrlLanguage.vite.js +1 -41
- package/dist/routing/index.d.ts +1 -0
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +1 -32
- package/dist/routing/link/InternalLink.next.d.ts +23 -0
- package/dist/routing/link/InternalLink.next.d.ts.map +1 -0
- package/dist/routing/link/InternalLink.next.js +1 -0
- package/dist/routing/link/InternalLink.vite.d.ts +22 -0
- package/dist/routing/link/InternalLink.vite.d.ts.map +1 -0
- package/dist/routing/link/InternalLink.vite.js +1 -0
- package/dist/routing/link/absolutePath.d.ts +17 -0
- package/dist/routing/link/absolutePath.d.ts.map +1 -0
- package/dist/routing/link/absolutePath.js +1 -0
- package/dist/routing/link/link.next.d.ts +12 -0
- package/dist/routing/link/link.next.d.ts.map +1 -0
- package/dist/routing/link/link.next.js +1 -0
- package/dist/routing/link/link.vite.d.ts +12 -0
- package/dist/routing/link/link.vite.d.ts.map +1 -0
- package/dist/routing/link/link.vite.js +1 -0
- package/dist/routing/link/types.d.ts +30 -0
- package/dist/routing/link/types.d.ts.map +1 -0
- package/dist/routing/link/types.js +0 -0
- package/dist/routing/parentRoute.js +1 -43
- package/dist/routing/useGoTo.d.ts.map +1 -1
- package/dist/routing/useGoTo.js +1 -59
- package/dist/routing/useNavigation.d.ts.map +1 -1
- package/dist/routing/useNavigation.js +1 -114
- package/dist/routing/useRouteDiscovery.d.ts +1 -0
- package/dist/routing/useRouteDiscovery.d.ts.map +1 -1
- package/dist/routing/useRouteDiscovery.js +1 -313
- package/dist/rsc.d.ts +28 -0
- package/dist/rsc.d.ts.map +1 -0
- package/dist/rsc.js +1 -0
- package/dist/styles/index.css +25 -4
- package/dist/styles/index.js +1 -10
- package/dist/styles/layoutConstants.js +1 -134
- package/dist/symbol-index.json +1 -1
- package/dist/utils/assetResolver.d.ts.map +1 -1
- package/dist/utils/assetResolver.js +1 -297
- package/dist/utils/index.js +1 -23
- package/dist/utils/sanitizeSvg.js +1 -51
- package/dist/utils/tList.js +1 -42
- package/dist/utils/useAISafe.d.ts.map +1 -1
- package/dist/utils/useAISafe.js +1 -53
- package/dist/utils/useAuthSafe.d.ts.map +1 -1
- package/dist/utils/useAuthSafe.js +1 -78
- package/dist/utils/useAuthVisibility.d.ts.map +1 -1
- package/dist/utils/useAuthVisibility.js +1 -63
- package/dist/utils/useBillingVisibility.d.ts.map +1 -1
- package/dist/utils/useBillingVisibility.js +1 -57
- package/dist/utils/useCrudSafe.d.ts.map +1 -1
- package/dist/utils/useCrudSafe.js +1 -75
- package/dist/utils/useDeleteAccountSafe.js +1 -52
- package/dist/utils/useFormStoreSafe.d.ts.map +1 -1
- package/dist/utils/useFormStoreSafe.js +1 -85
- package/dist/utils/useOAuthSafe.d.ts.map +1 -1
- package/dist/utils/useOAuthSafe.js +1 -38
- package/dist/utils/useSeo.js +1 -151
- package/dist/utils/useStripeBillingSafe.d.ts.map +1 -1
- package/dist/utils/useStripeBillingSafe.js +1 -81
- package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
- package/dist/vite-routing/AppRoutes.js +1 -235
- package/dist/vite-routing/RootLayout.d.ts.map +1 -1
- package/dist/vite-routing/RootLayout.js +1 -205
- package/dist/vite-routing/index.js +1 -11
- package/dist/vite.js +1 -10
- package/guidelines/COMPONENTS.md +3 -3
- package/guidelines/PAGES.md +3 -0
- package/guidelines/ROUTING.md +15 -0
- package/guidelines/SEO.md +4 -1
- package/package.json +18 -8
- package/dist/ChildRowsPicker-63M4EQUQ.js +0 -1
- package/dist/ChildRowsPicker-ISP365ON.js +0 -1
- package/dist/ChildRowsPicker-PQFE6NCR.js +0 -1
- package/dist/ChildRowsPicker-XXFFSMWY.js +0 -1
- package/dist/CookieConsent-QOUAY6B4.js +0 -1
- package/dist/GoToDialog-KSBGOIWO.js +0 -1
- package/dist/GoToDialog-XBK5EZF4.js +0 -1
- package/dist/chunk-3CIZFGST.js +0 -1
- package/dist/chunk-LHMKU342.js +0 -1
- package/dist/chunk-MS7ZIW5Z.js +0 -1
- package/dist/chunk-O2XFH626.js +0 -1
- package/dist/chunk-P2DHZWPY.js +0 -1
- package/dist/components/common/lucideIconByName.d.ts +0 -9
- package/dist/components/common/lucideIconByName.d.ts.map +0 -1
- package/dist/components/common/lucideIconByName.js +0 -32
- package/dist/internal/layout/components/PerformanceHints.d.ts +0 -71
- package/dist/internal/layout/components/PerformanceHints.d.ts.map +0 -1
- package/dist/internal/layout/components/PerformanceHints.js +0 -71
|
@@ -1,93 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
// packages/ui/src/components/layout/components/header/ThemeToggle.tsx
|
|
4
|
-
/**
|
|
5
|
-
* @fileoverview ThemeToggle component
|
|
6
|
-
* @description Theme switching component with dropdown menu
|
|
7
|
-
*
|
|
8
|
-
* @version 0.1.0
|
|
9
|
-
* @since 0.0.1
|
|
10
|
-
* @author AMBROISE PARK Consulting
|
|
11
|
-
*/
|
|
12
|
-
import * as LucideIcons from 'lucide-react';
|
|
13
|
-
import { Button, BUTTON_VARIANT, DropdownMenu, DISPLAY, } from '@donotdev/components';
|
|
14
|
-
import { useTranslation } from '@donotdev/core';
|
|
15
|
-
import { useTheme } from '@donotdev/core';
|
|
16
|
-
import { findLucideIcon } from '../../../common/lucideIconByName';
|
|
17
|
-
const getIcon = (iconName) => {
|
|
18
|
-
if (!iconName)
|
|
19
|
-
return LucideIcons.Palette;
|
|
20
|
-
const cleanIconName = iconName.replace(/['"]/g, '');
|
|
21
|
-
return findLucideIcon(cleanIconName) || LucideIcons.Palette;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* ThemeToggle - Theme switching component
|
|
25
|
-
*
|
|
26
|
-
* Allows users to switch between available themes (light, dark, system, custom).
|
|
27
|
-
* Integrates with the theme store for state management.
|
|
28
|
-
*
|
|
29
|
-
* @version 0.1.0
|
|
30
|
-
* @since 0.0.1
|
|
31
|
-
* @author AMBROISE PARK Consulting
|
|
32
|
-
*/
|
|
33
|
-
const ThemeToggle = ({ display = DISPLAY.AUTO, 'no-tooltip': noTooltip = false, }) => {
|
|
34
|
-
const { t } = useTranslation('dndev');
|
|
35
|
-
const availableThemes = useTheme('availableThemes');
|
|
36
|
-
const currentThemeName = useTheme('currentTheme');
|
|
37
|
-
const setTheme = useTheme('setTheme');
|
|
38
|
-
// 0-1 theme: don't show
|
|
39
|
-
if (availableThemes.length <= 1) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
// Find current and next theme info
|
|
43
|
-
// Safety: If currentThemeName doesn't exist in availableThemes (stale cache),
|
|
44
|
-
// fallback to first available theme to prevent UI inconsistencies
|
|
45
|
-
const currentThemeInfo = availableThemes.find((t) => t.name === currentThemeName) ||
|
|
46
|
-
availableThemes[0];
|
|
47
|
-
const nextThemeInfo = availableThemes.length === 2
|
|
48
|
-
? availableThemes.find((t) => t.name !== currentThemeInfo?.name) || availableThemes[0]
|
|
49
|
-
: null;
|
|
50
|
-
// Get icons
|
|
51
|
-
const currentIcon = currentThemeInfo
|
|
52
|
-
? getIcon(currentThemeInfo.meta?.icon)
|
|
53
|
-
: null;
|
|
54
|
-
const nextIcon = nextThemeInfo ? getIcon(nextThemeInfo.meta?.icon) : null;
|
|
55
|
-
const currentLabel = currentThemeInfo?.displayName || currentThemeInfo?.name || 'Theme';
|
|
56
|
-
const nextLabel = nextThemeInfo?.displayName || nextThemeInfo?.name || 'Theme';
|
|
57
|
-
// Determine button props based on theme count
|
|
58
|
-
const isTwoThemes = availableThemes.length === 2 && nextThemeInfo && nextIcon;
|
|
59
|
-
const buttonIcon = isTwoThemes ? nextIcon : currentIcon;
|
|
60
|
-
const buttonTooltip = isTwoThemes
|
|
61
|
-
? !noTooltip
|
|
62
|
-
? t('common.themeSelector.tooltipWithNext', 'Change Theme: Switch to {{next}}', { next: nextThemeInfo?.displayName || nextThemeInfo?.name })
|
|
63
|
-
: undefined
|
|
64
|
-
: !noTooltip
|
|
65
|
-
? t('common.themeSelector.changeTheme', 'Change Theme')
|
|
66
|
-
: undefined;
|
|
67
|
-
const buttonProps = {
|
|
68
|
-
variant: BUTTON_VARIANT.OUTLINE,
|
|
69
|
-
'aria-label': t('common.themeSelector.changeTheme', 'Change Theme'),
|
|
70
|
-
tooltip: buttonTooltip,
|
|
71
|
-
icon: buttonIcon,
|
|
72
|
-
display,
|
|
73
|
-
};
|
|
74
|
-
// 2 themes: direct toggle button - show next theme (what you'll switch to)
|
|
75
|
-
if (isTwoThemes && nextThemeInfo) {
|
|
76
|
-
return (_jsx(Button, { ...buttonProps, onClick: () => setTheme(nextThemeInfo.name), children: nextLabel }));
|
|
77
|
-
}
|
|
78
|
-
// 3+ themes: dropdown with current theme icon
|
|
79
|
-
if (!currentThemeInfo || !currentIcon)
|
|
80
|
-
return null;
|
|
81
|
-
const items = availableThemes.map((themeInfo) => {
|
|
82
|
-
const Icon = getIcon(themeInfo.meta?.icon);
|
|
83
|
-
const isCurrent = themeInfo.name === currentThemeName;
|
|
84
|
-
return {
|
|
85
|
-
label: themeInfo.displayName || themeInfo.name,
|
|
86
|
-
icon: Icon,
|
|
87
|
-
onClick: () => setTheme(themeInfo.name),
|
|
88
|
-
checked: isCurrent,
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
return (_jsx(DropdownMenu, { trigger: _jsx(Button, { ...buttonProps, children: currentLabel }), items: items, contentWidth: "10rem" }));
|
|
92
|
-
};
|
|
93
|
-
export default ThemeToggle;
|
|
1
|
+
"use client";import{Palette as f}from"lucide-react";import{Button as g,BUTTON_VARIANT as S,DropdownMenu as v,DISPLAY as x}from"@donotdev/components";import{useTranslation as A}from"@donotdev/core";import{useTheme as c}from"@donotdev/core";import{iconByName as L}from"../../../common/iconByName.js";import{jsx as l}from"react/jsx-runtime";var i=m=>m?L(m,f):f,w=({display:m=x.AUTO,"no-tooltip":s=!1})=>{let{t:r}=A("dndev"),t=c("availableThemes"),p=c("currentTheme"),T=c("setTheme");if(t.length<=1)return null;let o=t.find(n=>n.name===p)||t[0],e=t.length===2?t.find(n=>n.name!==o?.name)||t[0]:null,h=o?i(o.meta?.icon):null,u=e?i(e.meta?.icon):null,y=o?.displayName||o?.name||"Theme",I=e?.displayName||e?.name||"Theme",a=t.length===2&&e&&u,b=a?u:h,N=a?s?void 0:r("common.themeSelector.tooltipWithNext","Change Theme: Switch to {{next}}",{next:e?.displayName||e?.name}):s?void 0:r("common.themeSelector.changeTheme","Change Theme"),d={variant:S.OUTLINE,"aria-label":r("common.themeSelector.changeTheme","Change Theme"),tooltip:N,icon:b,display:m};if(a&&e)return l(g,{...d,onClick:()=>T(e.name),children:I});if(!o||!h)return null;let C=t.map(n=>{let D=i(n.meta?.icon),P=n.name===p;return{label:n.displayName||n.name,icon:D,onClick:()=>T(n.name),checked:P}});return l(v,{trigger:l(g,{...d,children:y}),items:C,contentWidth:"10rem"})},Y=w;export{Y as default};
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Layout Components Barrel Exports
|
|
4
|
-
* @description Barrel exports for layout component modules
|
|
5
|
-
*
|
|
6
|
-
* @version 0.1.0
|
|
7
|
-
* @since 0.0.1
|
|
8
|
-
* @author AMBROISE PARK Consulting
|
|
9
|
-
*/
|
|
10
|
-
export { default as AppBranding } from './header/AppBranding';
|
|
11
|
-
export { default as AppIcon } from './header/AppIcon';
|
|
12
|
-
export { default as AppTitle } from './header/AppTitle';
|
|
13
|
-
export { default as Breadcrumbs } from './Breadcrumbs';
|
|
14
|
-
export { GameTitle } from './header/GameTitle';
|
|
15
|
-
export { default as CacheSettings } from './header/CacheSettings';
|
|
16
|
-
export { default as DropdownNavigation } from './DropdownNavigation';
|
|
17
|
-
export { default as FloatingLanguageSwitcher } from './FloatingLanguageSwitcher';
|
|
18
|
-
export { default as HeaderMenu } from './header/HeaderMenu';
|
|
19
|
-
export { default as HeaderNavigation } from './header/HeaderNavigation';
|
|
20
|
-
export { default as Notifications } from './Notifications';
|
|
21
|
-
export { default as SettingsMenu } from './header/SettingsMenu';
|
|
22
|
-
export { default as ThemeToggle } from './header/ThemeToggle';
|
|
23
|
-
export { FooterBranding } from '../../../internal/layout/components/footer/FooterBranding';
|
|
24
|
-
export { FooterCopyright } from '../../../internal/layout/components/footer/FooterCopyright';
|
|
25
|
-
export { FooterLegalLinks } from '../../../internal/layout/components/footer/FooterLegalLinks';
|
|
1
|
+
import{default as r}from"./header/AppBranding.js";import{default as a}from"./header/AppIcon.js";import{default as p}from"./header/AppTitle.js";import{default as d}from"./Breadcrumbs.js";import{GameTitle as l}from"./header/GameTitle.js";import{default as n}from"./header/CacheSettings.js";import{default as x}from"./DropdownNavigation.js";import{default as c}from"./FloatingLanguageSwitcher.js";import{default as F}from"./header/HeaderMenu.js";import{default as A}from"./header/HeaderNavigation.js";import{default as L}from"./Notifications.js";import{default as S}from"./header/SettingsMenu.js";import{default as w}from"./header/ThemeToggle.js";import{FooterBranding as H}from"../../../internal/layout/components/footer/FooterBranding.js";import{FooterCopyright as b}from"../../../internal/layout/components/footer/FooterCopyright.js";import{FooterLegalLinks as y}from"../../../internal/layout/components/footer/FooterLegalLinks.js";export{r as AppBranding,a as AppIcon,p as AppTitle,d as Breadcrumbs,n as CacheSettings,x as DropdownNavigation,c as FloatingLanguageSwitcher,H as FooterBranding,b as FooterCopyright,y as FooterLegalLinks,l as GameTitle,F as HeaderMenu,A as HeaderNavigation,L as Notifications,S as SettingsMenu,w as ThemeToggle};
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Layout Components Barrel Exports
|
|
4
|
-
* @description Barrel exports for layout components. Provides centralized access to layout, page container, layout components, debug utilities, and layout presets.
|
|
5
|
-
*
|
|
6
|
-
* @version 0.1.0
|
|
7
|
-
* @since 0.0.1
|
|
8
|
-
* @author AMBROISE PARK Consulting
|
|
9
|
-
*/
|
|
10
|
-
export * from './PageContainer';
|
|
11
|
-
export * from './PageConfig';
|
|
12
|
-
export * from './GameContainer';
|
|
13
|
-
export * from './GameFlow';
|
|
14
|
-
export * from './components';
|
|
1
|
+
export*from"./PageContainer.js";export*from"./PageConfig.js";export*from"./GameContainer.js";export*from"./GameFlow.js";export*from"./components/index.js";
|
|
@@ -1,68 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
// packages/ui/src/crud/components/ChildRowsPicker.tsx
|
|
4
|
-
/**
|
|
5
|
-
* @fileoverview Link table picker
|
|
6
|
-
* @description Dialog of a joined `EntityList` on a link table (the child has
|
|
7
|
-
* one reference besides the parent's): the other side's records with
|
|
8
|
-
* `EntityFilters` (for the viewer's role, own filter state: the lists of that
|
|
9
|
-
* collection keep theirs) and a text search over a selectable list; deleted and
|
|
10
|
-
* already-linked records excluded; multi-select. Picked records become unsaved
|
|
11
|
-
* rows. Loaded lazily by EntityList.
|
|
12
|
-
*
|
|
13
|
-
* @version 0.1.0
|
|
14
|
-
* @since 0.2.5
|
|
15
|
-
* @author AMBROISE PARK Consulting
|
|
16
|
-
*/
|
|
17
|
-
import { Search } from 'lucide-react';
|
|
18
|
-
import { useState } from 'react';
|
|
19
|
-
import { Button, DataTable, Dialog, Input, Stack, Text, } from '@donotdev/components';
|
|
20
|
-
import { statusCan, useTranslation } from '@donotdev/core';
|
|
21
|
-
import { EntityFilters, applyFilters, applySearch, formatValue, translateFieldLabel, useCrudFilters, useCrudList, useReferenceResolver, } from '../crudImports';
|
|
22
|
-
/**
|
|
23
|
-
* Pick records of the other side of a link table: filters, text search,
|
|
24
|
-
* selectable list (deleted and already-linked records excluded), multi-select,
|
|
25
|
-
* "Add selected".
|
|
26
|
-
*/
|
|
27
|
-
export default function ChildRowsPicker({ entity, excludedIds, viewerRole, onPick, onClose, }) {
|
|
28
|
-
const { t } = useTranslation([entity.namespace, 'crud']);
|
|
29
|
-
const { t: tCrud } = useTranslation('crud');
|
|
30
|
-
const list = useCrudList(entity, { pagination: 'client' });
|
|
31
|
-
const referenceData = useReferenceResolver(entity);
|
|
32
|
-
const [selectedIds, setSelectedIds] = useState([]);
|
|
33
|
-
const [searchQuery, setSearchQuery] = useState('');
|
|
34
|
-
// Own filter state: picking must not filter the lists of this collection.
|
|
35
|
-
const filterKey = `${entity.collection}#picker`;
|
|
36
|
-
const { filters } = useCrudFilters({ collection: filterKey });
|
|
37
|
-
// Removed records (STATUS_MATRIX `isRemoved`) are never offered.
|
|
38
|
-
const candidates = list.items.filter((row) => !statusCan(typeof row.status === 'string' ? row.status : null, 'isRemoved') &&
|
|
39
|
-
!excludedIds.has(row.id));
|
|
40
|
-
const available = applySearch(applyFilters(candidates, filters, entity), searchQuery, entity);
|
|
41
|
-
const fields = entity.listFields || Object.keys(entity.fields);
|
|
42
|
-
const columns = fields.flatMap((fieldName) => {
|
|
43
|
-
const config = entity.fields[fieldName];
|
|
44
|
-
if (!config)
|
|
45
|
-
return [];
|
|
46
|
-
return [
|
|
47
|
-
{
|
|
48
|
-
key: fieldName,
|
|
49
|
-
title: translateFieldLabel(fieldName, config, t),
|
|
50
|
-
dataIndex: fieldName,
|
|
51
|
-
sortable: true,
|
|
52
|
-
render: (value, record) => formatValue(value, config, t, {
|
|
53
|
-
compact: true,
|
|
54
|
-
referenceData,
|
|
55
|
-
item: record,
|
|
56
|
-
}),
|
|
57
|
-
},
|
|
58
|
-
];
|
|
59
|
-
});
|
|
60
|
-
const entityName = t('name', { defaultValue: entity.name });
|
|
61
|
-
return (_jsx(Dialog, { open: true, onOpenChange: (open) => {
|
|
62
|
-
if (!open)
|
|
63
|
-
onClose();
|
|
64
|
-
}, title: tCrud('childRows.pickTitle', { entity: entityName }), footer: _jsxs(Stack, { direction: "row", gap: "tight", justify: "end", children: [_jsx(Button, { variant: "outline", onClick: onClose, children: tCrud('actions.cancel') }), _jsx(Button, { intent: "add", disabled: selectedIds.length === 0, onClick: () => {
|
|
65
|
-
onPick(selectedIds);
|
|
66
|
-
onClose();
|
|
67
|
-
}, children: tCrud('childRows.pickConfirm', { count: selectedIds.length }) })] }), children: _jsxs(Stack, { children: [_jsx(EntityFilters, { entity: entity, data: candidates, fieldsToFilter: fields, viewerRole: viewerRole, filterKey: filterKey }), _jsx(Input, { placeholder: tCrud('actions.searchPlaceholder'), value: searchQuery, onChange: (e) => setSearchQuery(e.target.value), icon: Search, className: "dndev-w-full" }), !list.loading && available.length === 0 ? (_jsx(Text, { level: "body", children: tCrud('childRows.pickEmpty') })) : (_jsx(DataTable, { data: available, columns: columns, sortable: true, searchable: false, pagination: true, loading: list.loading, selectable: true, getRowId: (row) => row.id, onSelect: (rows) => setSelectedIds(rows.map((row) => row.id)), showingLabel: tCrud('pagination.showing'), paginationPreviousLabel: tCrud('pagination.previous'), paginationNextLabel: tCrud('pagination.next'), paginationItemsPerPagePlaceholder: tCrud('pagination.itemsPerPagePlaceholder') }))] }) }));
|
|
68
|
-
}
|
|
1
|
+
"use client";import{Search as L}from"lucide-react";import{useState as m}from"react";import{Button as f,DataTable as D,Dialog as E,Input as B,Stack as h,Text as A}from"@donotdev/components";import{statusCan as K,useTranslation as k}from"@donotdev/core";import{EntityFilters as O,applyFilters as Q,applySearch as V,formatValue as j,translateFieldLabel as M,useCrudFilters as $,useCrudList as q,useReferenceResolver as z}from"../crudImports.js";import{jsx as i,jsxs as P}from"react/jsx-runtime";function G({entity:t,excludedIds:R,viewerRole:w,onPick:v,onClose:a}){let{t:l}=k([t.namespace,"crud"]),{t:o}=k("crud"),s=q(t,{pagination:"client"}),b=z(t),[r,y]=m([]),[c,C]=m(""),d=`${t.collection}#picker`,{filters:S}=$({collection:d}),u=s.items.filter(e=>!K(typeof e.status=="string"?e.status:null,"isRemoved")&&!R.has(e.id)),p=V(Q(u,S,t),c,t),g=t.listFields||Object.keys(t.fields),T=g.flatMap(e=>{let n=t.fields[e];return n?[{key:e,title:M(e,n,l),dataIndex:e,sortable:!0,render:(I,F)=>j(I,n,l,{compact:!0,referenceData:b,item:F})}]:[]}),x=l("name",{defaultValue:t.name});return i(E,{open:!0,onOpenChange:e=>{e||a()},title:o("childRows.pickTitle",{entity:x}),footer:P(h,{direction:"row",gap:"tight",justify:"end",children:[i(f,{variant:"outline",onClick:a,children:o("actions.cancel")}),i(f,{intent:"add",disabled:r.length===0,onClick:()=>{v(r),a()},children:o("childRows.pickConfirm",{count:r.length})})]}),children:P(h,{children:[i(O,{entity:t,data:u,fieldsToFilter:g,viewerRole:w,filterKey:d}),i(B,{placeholder:o("actions.searchPlaceholder"),value:c,onChange:e=>C(e.target.value),icon:L,className:"dndev-w-full"}),!s.loading&&p.length===0?i(A,{level:"body",children:o("childRows.pickEmpty")}):i(D,{data:p,columns:T,sortable:!0,searchable:!1,pagination:!0,loading:s.loading,selectable:!0,getRowId:e=>e.id,onSelect:e=>y(e.map(n=>n.id)),showingLabel:o("pagination.showing"),paginationPreviousLabel:o("pagination.previous"),paginationNextLabel:o("pagination.next"),paginationItemsPerPagePlaceholder:o("pagination.itemsPerPagePlaceholder")})]})})}export{G as default};
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { isCrudModuleAvailable, CrudCard as BaseCrudCard, } from '../crudImports';
|
|
4
|
-
/**
|
|
5
|
-
* CrudCard with link navigation.
|
|
6
|
-
* When detailHref is provided, the card links to it (crawlable, client-side navigation).
|
|
7
|
-
*/
|
|
8
|
-
export function CrudCard({ detailHref, onClick, ...rest }) {
|
|
9
|
-
// Safe guard: isCrudModuleAvailable is a module-level constant (immutable after load).
|
|
10
|
-
if (!isCrudModuleAvailable)
|
|
11
|
-
return null;
|
|
12
|
-
return detailHref ? (_jsx(BaseCrudCard, { ...rest, href: detailHref })) : (_jsx(BaseCrudCard, { ...rest, onClick: onClick }));
|
|
13
|
-
}
|
|
14
|
-
export default CrudCard;
|
|
1
|
+
"use client";import{isCrudModuleAvailable as e,CrudCard as o}from"../crudImports.js";import{jsx as u}from"react/jsx-runtime";function a({detailHref:r,onClick:C,...d}){return e?r?u(o,{...d,href:r}):u(o,{...d,onClick:C}):null}var i=a;export{a as CrudCard,i as default};
|
|
@@ -1,184 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
// packages/ui/src/crud/components/EntityCardList.tsx
|
|
4
|
-
/**
|
|
5
|
-
* @fileoverview Entity Card List Component
|
|
6
|
-
* @description Card grid view for public/user-facing entity browsing.
|
|
7
|
-
* Features: Responsive grid of cards with images, key fields, and navigation to detail pages.
|
|
8
|
-
*
|
|
9
|
-
* **Routing:** Convention basePath = `/${collection}`. View = basePath/:id.
|
|
10
|
-
* Override basePath for nested routes; use onClick(id) to open sheet instead of navigating.
|
|
11
|
-
*
|
|
12
|
-
* @version 0.1.0
|
|
13
|
-
* @since 0.0.1
|
|
14
|
-
* @author AMBROISE PARK Consulting
|
|
15
|
-
*/
|
|
16
|
-
import { Heart } from 'lucide-react';
|
|
17
|
-
import { useMemo, useCallback } from 'react';
|
|
18
|
-
import { Card, Grid, Stack, Text, Skeleton, Section, Button, } from '@donotdev/components';
|
|
19
|
-
import { useTranslation, getListCardFieldNames, useBreakpoint, } from '@donotdev/core';
|
|
20
|
-
import { isCrudModuleAvailable, useCrudCardList, EntityFilters, useEntityFavorites, useCrudFilters, } from '../crudImports';
|
|
21
|
-
import { CrudCard } from './CrudCardLink';
|
|
22
|
-
import { useNavigate } from '../../routing';
|
|
23
|
-
import { useAuthSafe } from '../../utils/useAuthSafe';
|
|
24
|
-
/**
|
|
25
|
-
* Resolve skeleton slots from entity shape — mirrors CrudCard's useResolvedSlots exactly.
|
|
26
|
-
* Returns the actual field names per slot so skeletons render the same structure as real cards.
|
|
27
|
-
*/
|
|
28
|
-
function resolveSkeletonSlots(entity) {
|
|
29
|
-
const l = entity.listCardFields;
|
|
30
|
-
if (l && !Array.isArray(l)) {
|
|
31
|
-
const layout = l;
|
|
32
|
-
return {
|
|
33
|
-
titleFields: layout.title ?? [],
|
|
34
|
-
subtitleFields: layout.subtitle ?? [],
|
|
35
|
-
contentFields: layout.content ?? [],
|
|
36
|
-
footerFields: layout.footer ?? [],
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const fieldsToShow = getListCardFieldNames(entity);
|
|
40
|
-
const isImage = (name) => {
|
|
41
|
-
const type = entity.fields[name]?.type;
|
|
42
|
-
return type === 'image' || type === 'images';
|
|
43
|
-
};
|
|
44
|
-
const other = fieldsToShow.filter((n) => !isImage(n));
|
|
45
|
-
const images = fieldsToShow.filter(isImage);
|
|
46
|
-
return {
|
|
47
|
-
titleFields: other.length > 0 ? [other[0]] : [],
|
|
48
|
-
subtitleFields: [],
|
|
49
|
-
contentFields: [...other.slice(1, 4), ...images],
|
|
50
|
-
footerFields: [],
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Skeleton grid — renders the same Card structure as CrudCard but with
|
|
55
|
-
* Skeleton elements instead of real data. No hardcoded sizes; the Card's
|
|
56
|
-
* own layout determines the shape.
|
|
57
|
-
*/
|
|
58
|
-
const BREAKPOINT_INDEX = {
|
|
59
|
-
mobile: 0,
|
|
60
|
-
tablet: 1,
|
|
61
|
-
laptop: 2,
|
|
62
|
-
desktop: 3,
|
|
63
|
-
};
|
|
64
|
-
function CardListSkeleton({ cols, entity, }) {
|
|
65
|
-
const slots = resolveSkeletonSlots(entity);
|
|
66
|
-
const bp = useBreakpoint('current');
|
|
67
|
-
const currentCols = (Array.isArray(cols) ? cols[BREAKPOINT_INDEX[bp] ?? 3] : cols) ?? 1;
|
|
68
|
-
const count = currentCols * 3;
|
|
69
|
-
const isImage = (name) => {
|
|
70
|
-
const type = entity.fields[name]?.type;
|
|
71
|
-
return type === 'image' || type === 'images';
|
|
72
|
-
};
|
|
73
|
-
const contentNode = slots.contentFields.length > 0 ? (_jsx(Stack, { direction: "column", gap: "tight", children: slots.contentFields.map((fieldName) => isImage(fieldName) ? (_jsx(Skeleton, { height: 120 }, fieldName)) : (_jsxs("div", { children: [_jsx(Text, { level: "small", variant: "muted", children: _jsx(Skeleton, {}) }), _jsx(Text, { children: _jsx(Skeleton, {}) })] }, fieldName))) })) : undefined;
|
|
74
|
-
const footerNode = slots.footerFields.length > 0 ? (_jsx(Text, { level: "small", children: _jsx(Skeleton, {}) })) : undefined;
|
|
75
|
-
return (_jsx(Grid, { cols: cols, children: Array.from({ length: count }, (_, i) => (_jsx(Card, { title: _jsx(Skeleton, {}), subtitle: slots.subtitleFields.length > 0 ? _jsx(Skeleton, {}) : undefined, content: contentNode, footer: footerNode, elevated: true }, i))) }));
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Entity Card List Component - Card grid view for public/user-facing browsing
|
|
79
|
-
*
|
|
80
|
-
* Features:
|
|
81
|
-
* - Responsive card grid layout
|
|
82
|
-
* - Image + key fields display
|
|
83
|
-
* - Click card to navigate to detail
|
|
84
|
-
* - Simple formatted text display (labels + values)
|
|
85
|
-
* - Empty state handling
|
|
86
|
-
* - Auto-routing when handler not provided
|
|
87
|
-
*/
|
|
88
|
-
export function EntityCardList({ entity, basePath, onClick, cols = [1, 2, 3, 4], staleTime = 1000 * 60 * 30, // 30 minutes default cache
|
|
89
|
-
queryOptions, filter, hideFilters = false, resultLabel, tone, renderCardOverlay, clientSort, collapsible = false, defaultOpen, preview, }) {
|
|
90
|
-
// Safe guard: isCrudModuleAvailable is a module-level constant (immutable after load).
|
|
91
|
-
if (!isCrudModuleAvailable)
|
|
92
|
-
return null;
|
|
93
|
-
const isPreview = !!preview;
|
|
94
|
-
const navigate = useNavigate();
|
|
95
|
-
const viewerRole = useAuthSafe('userRole');
|
|
96
|
-
const base = basePath ?? `/${entity.collection}`;
|
|
97
|
-
// useCrudCardList -> handles fetching + client-side filter/search/sort via `processed`
|
|
98
|
-
const { items: rawData, processed, loading: fetchLoading, error: fetchError, } = useCrudCardList(entity, {
|
|
99
|
-
enabled: !isPreview,
|
|
100
|
-
staleTime,
|
|
101
|
-
queryOptions,
|
|
102
|
-
clientSort,
|
|
103
|
-
});
|
|
104
|
-
// In preview mode: use preview data, skip loading state
|
|
105
|
-
const loading = isPreview ? false : fetchLoading;
|
|
106
|
-
// Favorites - always enabled, no props needed
|
|
107
|
-
const { isFavorite, toggleFavorite, favoritesFilter } = useEntityFavorites({
|
|
108
|
-
collection: entity.collection,
|
|
109
|
-
});
|
|
110
|
-
// Favorites toggle from CrudStore (persists across navigation)
|
|
111
|
-
const { showFavoritesOnly, setShowFavoritesOnly, filters, setFilters } = useCrudFilters({
|
|
112
|
-
collection: entity.collection,
|
|
113
|
-
});
|
|
114
|
-
// Apply UI-specific filters (favorites, consumer filter prop) on top of processed
|
|
115
|
-
// Favorites always sort to front; when showFavoritesOnly, only favorites are shown
|
|
116
|
-
let data = isPreview
|
|
117
|
-
? preview
|
|
118
|
-
: processed;
|
|
119
|
-
if (!isPreview) {
|
|
120
|
-
if (showFavoritesOnly) {
|
|
121
|
-
data = data.filter(favoritesFilter);
|
|
122
|
-
}
|
|
123
|
-
if (filter) {
|
|
124
|
-
data = data.filter(filter);
|
|
125
|
-
}
|
|
126
|
-
// Sort favorites to front (stable sort preserves relative order within each group)
|
|
127
|
-
data = data.toSorted((a, b) => {
|
|
128
|
-
const aFav = isFavorite(String(a.id)) ? 0 : 1;
|
|
129
|
-
const bFav = isFavorite(String(b.id)) ? 0 : 1;
|
|
130
|
-
return aFav - bFav;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
// Entity + crud namespaces so formatValue can resolve crud:price.* etc.
|
|
134
|
-
const { t } = useTranslation([entity.namespace, 'crud']);
|
|
135
|
-
const { t: tCrud } = useTranslation('crud');
|
|
136
|
-
// Card click: onClick(id) if provided, else navigate to basePath/:id
|
|
137
|
-
const handleView = useCallback((id) => {
|
|
138
|
-
if (isPreview)
|
|
139
|
-
return;
|
|
140
|
-
if (onClick) {
|
|
141
|
-
onClick(id);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
navigate(`${base}/${id}`);
|
|
145
|
-
}
|
|
146
|
-
}, [base, navigate, onClick, isPreview]);
|
|
147
|
-
// Flat field names for filters (works with both string[] and ListCardLayout)
|
|
148
|
-
const fieldsToFilter = useMemo(() => getListCardFieldNames(entity), [entity]);
|
|
149
|
-
const entityName = t('name', { defaultValue: entity.name });
|
|
150
|
-
return (_jsxs(_Fragment, { children: [!hideFilters && (_jsx(Section, { title: tCrud('filters.title', {
|
|
151
|
-
entity: entityName,
|
|
152
|
-
}), collapsible: collapsible, defaultOpen: defaultOpen, tone: tone, children: _jsx(Card, { children: _jsxs(Stack, { direction: "column", children: [_jsx(Button, { variant: !isPreview && showFavoritesOnly ? 'primary' : 'outline', icon: _jsx(Heart, { size: 18 }), onClick: () => setShowFavoritesOnly(!showFavoritesOnly), disabled: isPreview, children: showFavoritesOnly
|
|
153
|
-
? tCrud('favorites.showAll')
|
|
154
|
-
: tCrud('favorites.showFavorites') }), !isPreview && (_jsx(EntityFilters, { entity: entity, data: rawData, fieldsToFilter: fieldsToFilter, viewerRole: viewerRole }))] }) }) })), _jsx(Section, { title: loading
|
|
155
|
-
? tCrud('results.title.fetching')
|
|
156
|
-
: resultLabel
|
|
157
|
-
? resultLabel(data.length)
|
|
158
|
-
: tCrud('results.title.count', {
|
|
159
|
-
count: data.length,
|
|
160
|
-
}), collapsible: collapsible, defaultOpen: collapsible ? true : undefined, tone: tone, children: loading ? (_jsx(CardListSkeleton, { cols: cols, entity: entity })) : fetchError ? (_jsxs(Stack, { align: "center", justify: "center", style: { padding: 'var(--gap-lg)', textAlign: 'center' }, children: [_jsx(Text, { level: "h3", style: { color: 'var(--destructive)' }, children: tCrud('errors.fetchFailed', { entity: entityName }) }), _jsx(Text, { level: "small", style: { color: 'var(--destructive)' }, children: fetchError instanceof Error
|
|
161
|
-
? fetchError.message
|
|
162
|
-
: String(fetchError) })] })) : data.length === 0 ? (_jsxs(Stack, { align: "center", justify: "center", style: { padding: 'var(--gap-lg)', textAlign: 'center' }, children: [_jsx(Text, { level: "h3", style: { color: 'var(--muted-foreground)' }, children: tCrud('emptyState.title') }), _jsx(Text, { style: { color: 'var(--muted-foreground)' }, children: tCrud('emptyState.description') })] })) : (_jsx(Grid, { cols: cols, children: data.map((item) => {
|
|
163
|
-
const itemIsFavorite = isFavorite(item.id);
|
|
164
|
-
const detailHref = isPreview || onClick ? undefined : `${base}/${item.id}`;
|
|
165
|
-
return (_jsx(CrudCard, { item: item, entity: entity, detailHref: detailHref, onClick: isPreview
|
|
166
|
-
? undefined
|
|
167
|
-
: onClick
|
|
168
|
-
? () => handleView(item.id)
|
|
169
|
-
: undefined, renderOverlay: renderCardOverlay?.(item), renderActions: _jsx(Heart, { fill: itemIsFavorite ? '#ef4444' : '#ffffff', stroke: itemIsFavorite ? '#ef4444' : 'var(--muted-foreground)', onClick: (e) => {
|
|
170
|
-
e.preventDefault();
|
|
171
|
-
e.stopPropagation();
|
|
172
|
-
if (!isPreview)
|
|
173
|
-
toggleFavorite(item.id);
|
|
174
|
-
}, style: {
|
|
175
|
-
cursor: isPreview ? 'default' : 'pointer',
|
|
176
|
-
width: 'var(--icon-md)',
|
|
177
|
-
height: 'var(--icon-md)',
|
|
178
|
-
transition: 'fill 0.2s, stroke 0.2s',
|
|
179
|
-
opacity: isPreview ? 0.5 : 1,
|
|
180
|
-
}, "aria-label": itemIsFavorite
|
|
181
|
-
? tCrud('favorites.remove')
|
|
182
|
-
: tCrud('favorites.add') }) }, item.id));
|
|
183
|
-
}) })) })] }));
|
|
184
|
-
}
|
|
1
|
+
"use client";import{Heart as O}from"lucide-react";import{useMemo as U,useCallback as W}from"react";import{Card as $,Grid as B,Stack as k,Text as f,Skeleton as m,Section as I,Button as Y}from"@donotdev/components";import{useTranslation as N,getListCardFieldNames as D,useBreakpoint as Z}from"@donotdev/core";import{isCrudModuleAvailable as tt,useCrudCardList as et,EntityFilters as rt,useEntityFavorites as ot,useCrudFilters as it}from"../crudImports.js";import{CrudCard as nt}from"./CrudCardLink.js";import{useNavigate as st}from"../../routing/index.js";import{useAuthSafe as lt}from"../../utils/useAuthSafe.js";import{Fragment as ft,jsx as t,jsxs as F}from"react/jsx-runtime";function at(e){let d=e.listCardFields;if(d&&!Array.isArray(d)){let i=d;return{titleFields:i.title??[],subtitleFields:i.subtitle??[],contentFields:i.content??[],footerFields:i.footer??[]}}let o=D(e),c=i=>{let g=e.fields[i]?.type;return g==="image"||g==="images"},u=o.filter(i=>!c(i)),v=o.filter(c);return{titleFields:u.length>0?[u[0]]:[],subtitleFields:[],contentFields:[...u.slice(1,4),...v],footerFields:[]}}var dt={mobile:0,tablet:1,laptop:2,desktop:3};function ct({cols:e,entity:d}){let o=at(d),c=Z("current"),v=((Array.isArray(e)?e[dt[c]??3]:e)??1)*3,i=a=>{let p=d.fields[a]?.type;return p==="image"||p==="images"},g=o.contentFields.length>0?t(k,{direction:"column",gap:"tight",children:o.contentFields.map(a=>i(a)?t(m,{height:120},a):F("div",{children:[t(f,{level:"small",variant:"muted",children:t(m,{})}),t(f,{children:t(m,{})})]},a))}):void 0,h=o.footerFields.length>0?t(f,{level:"small",children:t(m,{})}):void 0;return t(B,{cols:e,children:Array.from({length:v},(a,p)=>t($,{title:t(m,{}),subtitle:o.subtitleFields.length>0?t(m,{}):void 0,content:g,footer:h,elevated:!0},p))})}function Et({entity:e,basePath:d,onClick:o,cols:c=[1,2,3,4],staleTime:u=1e3*60*30,queryOptions:v,filter:i,hideFilters:g=!1,resultLabel:h,tone:a,renderCardOverlay:p,clientSort:G,collapsible:b=!1,defaultOpen:H,preview:x}){if(!tt)return null;let r=!!x,w=st(),M=lt("userRole"),T=d??`/${e.collection}`,{items:V,processed:_,loading:j,error:C}=et(e,{enabled:!r,staleTime:u,queryOptions:v,clientSort:G}),P=r?!1:j,{isFavorite:A,toggleFavorite:z,favoritesFilter:K}=ot({collection:e.collection}),{showFavoritesOnly:S,setShowFavoritesOnly:X,filters:ut,setFilters:gt}=it({collection:e.collection}),s=r?x:_;r||(S&&(s=s.filter(K)),i&&(s=s.filter(i)),s=s.toSorted((n,y)=>{let L=A(String(n.id))?0:1,E=A(String(y.id))?0:1;return L-E}));let{t:q}=N([e.namespace,"crud"]),{t:l}=N("crud"),J=W(n=>{r||(o?o(n):w(`${T}/${n}`))},[T,w,o,r]),Q=U(()=>D(e),[e]),R=q("name",{defaultValue:e.name});return F(ft,{children:[!g&&t(I,{title:l("filters.title",{entity:R}),collapsible:b,defaultOpen:H,tone:a,children:t($,{children:F(k,{direction:"column",children:[t(Y,{variant:!r&&S?"primary":"outline",icon:t(O,{size:18}),onClick:()=>X(!S),disabled:r,children:l(S?"favorites.showAll":"favorites.showFavorites")}),!r&&t(rt,{entity:e,data:V,fieldsToFilter:Q,viewerRole:M})]})})}),t(I,{title:P?l("results.title.fetching"):h?h(s.length):l("results.title.count",{count:s.length}),collapsible:b,defaultOpen:b?!0:void 0,tone:a,children:P?t(ct,{cols:c,entity:e}):C?F(k,{align:"center",justify:"center",style:{padding:"var(--gap-lg)",textAlign:"center"},children:[t(f,{level:"h3",style:{color:"var(--destructive)"},children:l("errors.fetchFailed",{entity:R})}),t(f,{level:"small",style:{color:"var(--destructive)"},children:C instanceof Error?C.message:String(C)})]}):s.length===0?F(k,{align:"center",justify:"center",style:{padding:"var(--gap-lg)",textAlign:"center"},children:[t(f,{level:"h3",style:{color:"var(--muted-foreground)"},children:l("emptyState.title")}),t(f,{style:{color:"var(--muted-foreground)"},children:l("emptyState.description")})]}):t(B,{cols:c,children:s.map(n=>{let y=A(n.id),L=r||o?void 0:`${T}/${n.id}`;return t(nt,{item:n,entity:e,detailHref:L,onClick:r?void 0:o?()=>J(n.id):void 0,renderOverlay:p?.(n),renderActions:t(O,{fill:y?"#ef4444":"#ffffff",stroke:y?"#ef4444":"var(--muted-foreground)",onClick:E=>{E.preventDefault(),E.stopPropagation(),r||z(n.id)},style:{cursor:r?"default":"pointer",width:"var(--icon-md)",height:"var(--icon-md)",transition:"fill 0.2s, stroke 0.2s",opacity:r?.5:1},"aria-label":l(y?"favorites.remove":"favorites.add")})},n.id)})})})]})}export{Et as EntityCardList};
|
|
@@ -1,130 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
// packages/ui/src/crud/components/EntityDisplayRenderer.tsx
|
|
4
|
-
/**
|
|
5
|
-
* @fileoverview EntityDisplayRenderer component
|
|
6
|
-
* @description High-level component that automatically fetches and displays entity data in read-only mode.
|
|
7
|
-
* Perfect for detail/view pages - just pass the entity and it handles everything.
|
|
8
|
-
*
|
|
9
|
-
* @version 0.1.0
|
|
10
|
-
* @since 0.0.1
|
|
11
|
-
* @author AMBROISE PARK Consulting
|
|
12
|
-
*/
|
|
13
|
-
import { useMemo } from 'react';
|
|
14
|
-
import { Stack, Spinner } from '@donotdev/components';
|
|
15
|
-
import { useTranslation, isFieldVisible } from '@donotdev/core';
|
|
16
|
-
import { useAuthSafe } from '../../utils/useAuthSafe';
|
|
17
|
-
import { isCrudModuleAvailable, useCrudDoc, DisplayFieldRenderer, } from '../crudImports';
|
|
18
|
-
import { useRecordBreadcrumb } from './useRecordBreadcrumb';
|
|
19
|
-
/**
|
|
20
|
-
* EntityDisplayRenderer - Automatically fetches and displays entity data
|
|
21
|
-
*
|
|
22
|
-
* Features:
|
|
23
|
-
* - Reactive data fetching using useCrudDoc (stays in sync with edits)
|
|
24
|
-
* - Loading state handling
|
|
25
|
-
* - Error handling
|
|
26
|
-
* - Automatic field rendering (respects visibility rules)
|
|
27
|
-
* - Full i18n support
|
|
28
|
-
* - No form/submit buttons - pure read-only display
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```tsx
|
|
32
|
-
* <EntityDisplayRenderer entity={carEntity} id={carId} />
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export function EntityDisplayRenderer({ entity, id, t, className = '', loadingMessage, notFoundMessage, viewerRole: viewerRoleProp, excludeFields, preview, }) {
|
|
36
|
-
// Safe guard: isCrudModuleAvailable is a module-level constant (immutable after load).
|
|
37
|
-
if (!isCrudModuleAvailable)
|
|
38
|
-
return null;
|
|
39
|
-
const isPreview = !!preview;
|
|
40
|
-
// Auto-detect role from auth; prop overrides. Preview = design-time showcase, show all fields.
|
|
41
|
-
const authRole = useAuthSafe('userRole');
|
|
42
|
-
const viewerRole = viewerRoleProp ?? (isPreview ? 'super' : authRole);
|
|
43
|
-
// Reactive read: re-renders on every cache write for this document (edits, deletes)
|
|
44
|
-
const { data: fetchedData, loading, error, notFound, } = useCrudDoc(entity, id, { enabled: !isPreview });
|
|
45
|
-
// Entity + crud namespaces so formatValue can resolve crud:price.* etc.
|
|
46
|
-
const { t: tDual } = useTranslation([entity.namespace, 'crud']);
|
|
47
|
-
const { t: tCrud } = useTranslation('crud');
|
|
48
|
-
const translate = t || tDual;
|
|
49
|
-
// Preview: design-time showcase data, no read
|
|
50
|
-
const displayData = isPreview ? preview : fetchedData;
|
|
51
|
-
// Breadcrumb shows the record's name instead of its id
|
|
52
|
-
useRecordBreadcrumb(entity, isPreview ? null : displayData);
|
|
53
|
-
const displayError = isPreview ? null : error;
|
|
54
|
-
const isLoading = isPreview ? false : loading || !id;
|
|
55
|
-
// Filter fields: respect visibility AND skip empty values
|
|
56
|
-
// MUST be called before any early returns (Rules of Hooks)
|
|
57
|
-
const visibleFields = useMemo(() => {
|
|
58
|
-
if (!displayData)
|
|
59
|
-
return [];
|
|
60
|
-
return Object.entries(entity.fields).filter(([fieldName, fieldConfig]) => {
|
|
61
|
-
// Skip excluded fields
|
|
62
|
-
if (excludeFields?.includes(fieldName)) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
// Check visibility first
|
|
66
|
-
if (!isFieldVisible(fieldConfig.visibility, viewerRole)) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
// Skip hidden fields
|
|
70
|
-
if (fieldConfig.visibility === 'hidden') {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
// Get field value (displayData may be preview T or cached row; entity is AnyEntity in props)
|
|
74
|
-
const value = displayData[fieldName];
|
|
75
|
-
// Hide if value is empty/null/undefined
|
|
76
|
-
if (value === null || value === undefined) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
// Hide empty strings
|
|
80
|
-
if (typeof value === 'string' && value.trim() === '') {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
// Hide empty arrays
|
|
84
|
-
if (Array.isArray(value) && value.length === 0) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
// Hide empty objects (but allow objects with properties)
|
|
88
|
-
if (typeof value === 'object' &&
|
|
89
|
-
!Array.isArray(value) &&
|
|
90
|
-
value !== null &&
|
|
91
|
-
Object.keys(value).length === 0) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
return true;
|
|
95
|
-
});
|
|
96
|
-
}, [entity.fields, viewerRole, displayData, excludeFields]);
|
|
97
|
-
// Loading state
|
|
98
|
-
if (isLoading) {
|
|
99
|
-
return (_jsx("div", { style: {
|
|
100
|
-
position: 'relative',
|
|
101
|
-
width: '100%',
|
|
102
|
-
gridColumn: '1 / -1',
|
|
103
|
-
display: 'contents',
|
|
104
|
-
}, className: className, children: _jsx(Spinner, { overlay: true, "aria-label": loadingMessage ||
|
|
105
|
-
tCrud('form.loading') }) }));
|
|
106
|
-
}
|
|
107
|
-
// CRUD unavailable (consent declined / feature absent): nothing will load
|
|
108
|
-
if (!displayData && !displayError && !notFound)
|
|
109
|
-
return null;
|
|
110
|
-
// Error or not found state
|
|
111
|
-
if (displayError || !displayData) {
|
|
112
|
-
return (_jsx(Stack, { align: "center", justify: "center", style: {
|
|
113
|
-
padding: 'var(--gap-lg)',
|
|
114
|
-
textAlign: 'center',
|
|
115
|
-
}, className: className, children: _jsxs(Stack, { direction: "column", gap: "tight", children: [_jsx("h3", { style: { color: 'var(--muted-foreground)' }, children: notFoundMessage ||
|
|
116
|
-
tCrud('errors.notFound', {
|
|
117
|
-
entity: tDual('name', { defaultValue: entity.name }),
|
|
118
|
-
}) }), displayError && (_jsx("p", { style: {
|
|
119
|
-
color: 'var(--destructive)',
|
|
120
|
-
fontSize: 'var(--font-size-sm)',
|
|
121
|
-
}, children: displayError instanceof Error
|
|
122
|
-
? displayError.message
|
|
123
|
-
: String(displayError) }))] }) }));
|
|
124
|
-
}
|
|
125
|
-
// Render all visible fields with values
|
|
126
|
-
return (_jsx(Stack, { direction: "column", className: className, children: visibleFields.map(([fieldName, fieldConfig]) => {
|
|
127
|
-
return (_jsx(DisplayFieldRenderer, { name: fieldName, config: fieldConfig, value: displayData[fieldName], t: translate }, fieldName));
|
|
128
|
-
}) }));
|
|
129
|
-
}
|
|
130
|
-
export default EntityDisplayRenderer;
|
|
1
|
+
"use client";import{useMemo as P}from"react";import{Stack as u,Spinner as j}from"@donotdev/components";import{useTranslation as g,isFieldVisible as x}from"@donotdev/core";import{useAuthSafe as C}from"../../utils/useAuthSafe.js";import{isCrudModuleAvailable as z,useCrudDoc as M,DisplayFieldRenderer as O}from"../crudImports.js";import{useRecordBreadcrumb as V}from"./useRecordBreadcrumb.js";import{jsx as t,jsxs as L}from"react/jsx-runtime";function B({entity:n,id:d,t:v,className:a="",loadingMessage:R,notFoundMessage:b,viewerRole:h,excludeFields:c,preview:f}){if(!z)return null;let o=!!f,E=C("userRole"),p=h??(o?"super":E),{data:k,loading:D,error:S,notFound:A}=M(n,d,{enabled:!o}),{t:y}=g([n.namespace,"crud"]),{t:m}=g("crud"),w=v||y,r=o?f:k;V(n,o?null:r);let i=o?null:S,T=o?!1:D||!d,F=P(()=>r?Object.entries(n.fields).filter(([s,l])=>{if(c?.includes(s)||!x(l.visibility,p)||l.visibility==="hidden")return!1;let e=r[s];return!(e==null||typeof e=="string"&&e.trim()===""||Array.isArray(e)&&e.length===0||typeof e=="object"&&!Array.isArray(e)&&e!==null&&Object.keys(e).length===0)}):[],[n.fields,p,r,c]);return T?t("div",{style:{position:"relative",width:"100%",gridColumn:"1 / -1",display:"contents"},className:a,children:t(j,{overlay:!0,"aria-label":R||m("form.loading")})}):!r&&!i&&!A?null:i||!r?t(u,{align:"center",justify:"center",style:{padding:"var(--gap-lg)",textAlign:"center"},className:a,children:L(u,{direction:"column",gap:"tight",children:[t("h3",{style:{color:"var(--muted-foreground)"},children:b||m("errors.notFound",{entity:y("name",{defaultValue:n.name})})}),i&&t("p",{style:{color:"var(--destructive)",fontSize:"var(--font-size-sm)"},children:i instanceof Error?i.message:String(i)})]})}):t(u,{direction:"column",className:a,children:F.map(([s,l])=>t(O,{name:s,config:l,value:r[s],t:w},s))})}var K=B;export{B as EntityDisplayRenderer,K as default};
|