@donotdev/ui 0.3.1 → 0.3.3
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 -3
- 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.d.ts +4 -1
- package/dist/crud/components/EntityCardList.d.ts.map +1 -1
- 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 +3 -1
- 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 +113 -41
- package/dist/dndev.css +113 -41
- 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 +5 -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.d.ts +18 -14
- package/dist/internal/layout/components/FaviconHead.d.ts.map +1 -1
- 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/headTagElement.d.ts +16 -0
- package/dist/internal/layout/components/headTagElement.d.ts.map +1 -0
- package/dist/internal/layout/components/headTagElement.js +1 -0
- package/dist/internal/layout/components/index.js +1 -13
- package/dist/internal/layout/components/prerenderedHead.d.ts +15 -0
- package/dist/internal/layout/components/prerenderedHead.d.ts.map +1 -0
- package/dist/internal/layout/components/prerenderedHead.js +1 -0
- package/dist/internal/layout/components/trailingSlash.d.ts +13 -0
- package/dist/internal/layout/components/trailingSlash.d.ts.map +1 -0
- package/dist/internal/layout/components/trailingSlash.js +1 -0
- 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 +11 -9
- 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.next.js +1 -1
- 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.d.ts +5 -3
- package/dist/routing/hooks/useRoutePath.next.d.ts.map +1 -1
- 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 +4 -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 +113 -41
- 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 +19 -19
- package/dist/utils/assetResolver.d.ts.map +1 -1
- package/dist/utils/assetResolver.js +1 -297
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- 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/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 +16 -0
- package/guidelines/SEO.md +160 -142
- 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
- package/dist/internal/layout/components/i18nSeoMeta.d.ts +0 -54
- package/dist/internal/layout/components/i18nSeoMeta.d.ts.map +0 -1
- package/dist/internal/layout/components/i18nSeoMeta.js +0 -53
- package/dist/utils/useSeo.d.ts +0 -129
- package/dist/utils/useSeo.d.ts.map +0 -1
- package/dist/utils/useSeo.js +0 -151
|
@@ -1,55 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { Button, Stack, Stepper } from '@donotdev/components';
|
|
4
|
-
import { useTranslation } from '@donotdev/core';
|
|
5
|
-
import { isCrudModuleAvailable, useEntityWorkflow } from '../crudImports';
|
|
6
|
-
import { EntityFormRenderer } from './EntityFormRenderer';
|
|
7
|
-
/**
|
|
8
|
-
* EntityWorkflow — renders a multi-step entity workflow.
|
|
9
|
-
*
|
|
10
|
-
* Default mode: auto-renders Stepper + form + navigation buttons.
|
|
11
|
-
* Custom mode: pass a render prop as children for full control.
|
|
12
|
-
*/
|
|
13
|
-
export function EntityWorkflow({ workflow: config, onComplete, onStepChange, defaultValues, viewerRole, children, className, }) {
|
|
14
|
-
// Safe guard: isCrudModuleAvailable is a module-level constant (immutable after load).
|
|
15
|
-
if (!isCrudModuleAvailable)
|
|
16
|
-
return null;
|
|
17
|
-
const { t } = useTranslation('crud');
|
|
18
|
-
const wf = useEntityWorkflow(config, {
|
|
19
|
-
onComplete,
|
|
20
|
-
onStepChange,
|
|
21
|
-
defaultValues,
|
|
22
|
-
});
|
|
23
|
-
// Custom render mode
|
|
24
|
-
if (children) {
|
|
25
|
-
return _jsx(_Fragment, { children: children(wf) });
|
|
26
|
-
}
|
|
27
|
-
const { currentStep, currentStepIndex, visibleSteps, isFirst, isLast, isSubmitting, stepData, } = wf;
|
|
28
|
-
// Build stepper steps (for the Stepper header)
|
|
29
|
-
const stepperSteps = visibleSteps.map((step, index) => ({
|
|
30
|
-
number: index + 1,
|
|
31
|
-
title: step.title,
|
|
32
|
-
content: null, // Content is rendered separately below
|
|
33
|
-
}));
|
|
34
|
-
return (_jsxs(Stack, { className: className, gap: "large", children: [_jsx(Stepper, { steps: stepperSteps, activeStep: currentStepIndex, showStepNumbers: true, onStepChange: (index) => {
|
|
35
|
-
// Only allow navigating to completed steps (not jumping forward)
|
|
36
|
-
if (index <= currentStepIndex) {
|
|
37
|
-
wf.goToStep(index);
|
|
38
|
-
}
|
|
39
|
-
} }), currentStep.custom ? (
|
|
40
|
-
// Custom render step (e.g., review/summary)
|
|
41
|
-
currentStep.custom(wf.allData)) : currentStep.entity ? (
|
|
42
|
-
// Entity form step
|
|
43
|
-
_jsx(EntityFormRenderer, { entity: currentStep.entity, operation: "create", viewerRole: viewerRole, defaultValues: {
|
|
44
|
-
...stepData[currentStep.id],
|
|
45
|
-
...(!isLast && { status: 'draft' }),
|
|
46
|
-
}, onSubmit: async (data) => {
|
|
47
|
-
await wf.goNext(data);
|
|
48
|
-
},
|
|
49
|
-
// Steps advance in place; the caller's onComplete decides where to go.
|
|
50
|
-
successPath: null, submitText: isLast
|
|
51
|
-
? t('workflow.submit')
|
|
52
|
-
: t('workflow.next'), cancelText: isFirst
|
|
53
|
-
? null
|
|
54
|
-
: t('workflow.previous'), onCancel: isFirst ? undefined : wf.goPrevious, loading: isSubmitting, hideVisibilityInfo: true })) : null, currentStep.allowSkip && !isLast && (_jsx(Button, { variant: "ghost", onClick: wf.skipStep, className: "dndev-w-full", children: t('workflow.skip') }))] }));
|
|
55
|
-
}
|
|
1
|
+
"use client";import{Button as v,Stack as b,Stepper as R}from"@donotdev/components";import{useTranslation as C}from"@donotdev/core";import{isCrudModuleAvailable as W,useEntityWorkflow as h}from"../crudImports.js";import{EntityFormRenderer as E}from"./EntityFormRenderer.js";import{Fragment as N,jsx as r,jsxs as x}from"react/jsx-runtime";function V({workflow:u,onComplete:p,onStepChange:c,defaultValues:f,viewerRole:w,children:l,className:d}){if(!W)return null;let{t:n}=C("crud"),t=h(u,{onComplete:p,onStepChange:c,defaultValues:f});if(l)return r(N,{children:l(t)});let{currentStep:e,currentStepIndex:s,visibleSteps:m,isFirst:a,isLast:i,isSubmitting:k,stepData:g}=t,S=m.map((o,y)=>({number:y+1,title:o.title,content:null}));return x(b,{className:d,gap:"large",children:[r(R,{steps:S,activeStep:s,showStepNumbers:!0,onStepChange:o=>{o<=s&&t.goToStep(o)}}),e.custom?e.custom(t.allData):e.entity?r(E,{entity:e.entity,operation:"create",viewerRole:w,defaultValues:{...g[e.id],...!i&&{status:"draft"}},onSubmit:async o=>{await t.goNext(o)},successPath:null,submitText:n(i?"workflow.submit":"workflow.next"),cancelText:a?null:n("workflow.previous"),onCancel:a?void 0:t.goPrevious,loading:k,hideVisibilityInfo:!0}):null,e.allowSkip&&!i&&r(v,{variant:"ghost",onClick:t.skipStep,className:"dndev-w-full",children:n("workflow.skip")})]})}export{V as EntityWorkflow};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/crud/components/Form.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/crud/components/Form.tsx"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,WAAW,EAGjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAa,MAAM,sBAAsB,CAAC;AAE9D;;;;;;GAMG;AACH,QAAA,MAAM,IAAI,yaAAe,CAAC;AAqB1B;;;;;;;;;;GAUG;AACH,QAAA,MAAM,SAAS,GACb,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,EAC/D,cAEC,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,gCAMtC,CAAC;AAYF;;;;;;;;;;GAUG;AACH,QAAA,MAAM,QAAQ,GAAI,mCAIf,cAAc,CAAC,cAAc,CAAC,gCAShC,CAAC;AAEF;;;;;;;;;GASG;AACH,QAAA,MAAM,YAAY;;;;;;;;;;;QA4BjB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,QAAA,MAAM,SAAS,GAAI,yBAAyB,cAAc,CAAC,OAAO,KAAK,CAAC,uCAWvE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,QAAA,MAAM,WAAW,GAAI,cAAc,cAAc,CAAC,OAAO,IAAI,CAAC,uCAgB7D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,QAAA,MAAM,eAAe,GAAI,yBAGtB,cAAc,CAAC,oBAAoB,CAAC,uCAetC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,QAAA,MAAM,WAAW,GAAI,mCAIlB,cAAc,CAAC,oBAAoB,CAAC,uCAsBtC,CAAC;AAEF;;;;;;GAMG;AACH,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,eAAe,EACf,WAAW,EACX,SAAS,EACT,YAAY,GACb,CAAC"}
|
|
@@ -1,198 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// packages/ui/src/crud/components/Form.tsx
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview Form Components
|
|
5
|
-
* @description Form components built on react-hook-form and Radix UI primitives. Provides form context, field management, and validation support.
|
|
6
|
-
*
|
|
7
|
-
* @version 0.1.0
|
|
8
|
-
* @since 0.0.1
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
import { createContext, useId, use, } from 'react';
|
|
12
|
-
import { Controller, FormProvider, useFormContext, } from 'react-hook-form';
|
|
13
|
-
import { Label, Slot, cn, Stack } from '@donotdev/components';
|
|
14
|
-
/**
|
|
15
|
-
* Form provider component
|
|
16
|
-
*
|
|
17
|
-
* @version 0.1.0
|
|
18
|
-
* @since 0.0.1
|
|
19
|
-
* @author AMBROISE PARK Consulting
|
|
20
|
-
*/
|
|
21
|
-
const Form = FormProvider;
|
|
22
|
-
/**
|
|
23
|
-
* Form field context for sharing field name
|
|
24
|
-
*
|
|
25
|
-
* @type {React.Context<FormFieldContextValue>}
|
|
26
|
-
* @version 0.1.0
|
|
27
|
-
* @since 0.0.1
|
|
28
|
-
* @author AMBROISE PARK Consulting
|
|
29
|
-
*/
|
|
30
|
-
const FormFieldContext = createContext({});
|
|
31
|
-
/**
|
|
32
|
-
* Form field component
|
|
33
|
-
*
|
|
34
|
-
* Wraps a form field with context and controller for react-hook-form integration.
|
|
35
|
-
*
|
|
36
|
-
* @param {ControllerProps<TFieldValues, TName>} props - Controller props
|
|
37
|
-
* @returns {JSX.Element} Form field component
|
|
38
|
-
* @version 0.1.0
|
|
39
|
-
* @since 0.0.1
|
|
40
|
-
* @author AMBROISE PARK Consulting
|
|
41
|
-
*/
|
|
42
|
-
const FormField = ({ ...props }) => {
|
|
43
|
-
return (_jsx(FormFieldContext.Provider, { value: { name: props.name }, children: _jsx(Controller, { ...props }) }));
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Form item context for sharing item ID
|
|
47
|
-
*
|
|
48
|
-
* @type {React.Context<{ id: string }>}
|
|
49
|
-
* @version 0.1.0
|
|
50
|
-
* @since 0.0.1
|
|
51
|
-
* @author AMBROISE PARK Consulting
|
|
52
|
-
*/
|
|
53
|
-
const FormItemContext = createContext({});
|
|
54
|
-
/**
|
|
55
|
-
* Form item component
|
|
56
|
-
*
|
|
57
|
-
* Container component for form fields with spacing and layout.
|
|
58
|
-
*
|
|
59
|
-
* @param {HTMLAttributes<HTMLDivElement>} props - Component props
|
|
60
|
-
* @returns {JSX.Element} Form item component
|
|
61
|
-
* @version 0.1.0
|
|
62
|
-
* @since 0.0.1
|
|
63
|
-
* @author AMBROISE PARK Consulting
|
|
64
|
-
*/
|
|
65
|
-
const FormItem = ({ className, children, ...props }) => {
|
|
66
|
-
const id = useId();
|
|
67
|
-
return (_jsx(FormItemContext.Provider, { value: { id }, children: _jsx(Stack, { className: className, ...props, children: children }) }));
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Hook for accessing form field context
|
|
71
|
-
*
|
|
72
|
-
* Returns form field state and IDs for form components.
|
|
73
|
-
*
|
|
74
|
-
* @returns {Object | null} Form field context with IDs and state
|
|
75
|
-
* @version 0.1.0
|
|
76
|
-
* @since 0.0.1
|
|
77
|
-
* @author AMBROISE PARK Consulting
|
|
78
|
-
*/
|
|
79
|
-
const useFormField = () => {
|
|
80
|
-
const fieldContext = use(FormFieldContext);
|
|
81
|
-
if (!fieldContext || !fieldContext.name) {
|
|
82
|
-
if (process.env.NODE_ENV === 'development') {
|
|
83
|
-
console.warn('useFormField must be used within <FormField> with a valid name');
|
|
84
|
-
}
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
const itemContext = use(FormItemContext);
|
|
88
|
-
if (!itemContext) {
|
|
89
|
-
if (process.env.NODE_ENV === 'development') {
|
|
90
|
-
console.warn('useFormField must be used within <FormItem>');
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
const { getFieldState, formState } = useFormContext();
|
|
95
|
-
const fieldState = getFieldState(fieldContext.name, formState);
|
|
96
|
-
const { id } = itemContext;
|
|
97
|
-
return {
|
|
98
|
-
id,
|
|
99
|
-
name: fieldContext.name,
|
|
100
|
-
formItemId: `${id}-form-item`,
|
|
101
|
-
formDescriptionId: `${id}-form-item-description`,
|
|
102
|
-
formMessageId: `${id}-form-item-message`,
|
|
103
|
-
...fieldState,
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
/**
|
|
107
|
-
* Form label component
|
|
108
|
-
*
|
|
109
|
-
* Renders a label for a form field with error state styling.
|
|
110
|
-
*
|
|
111
|
-
* @param {ComponentProps<typeof Label>} props - Component props
|
|
112
|
-
* @returns {JSX.Element | null} Form label component
|
|
113
|
-
* @version 0.1.0
|
|
114
|
-
* @since 0.0.1
|
|
115
|
-
* @author AMBROISE PARK Consulting
|
|
116
|
-
*/
|
|
117
|
-
const FormLabel = ({ className, ...props }) => {
|
|
118
|
-
const formField = useFormField();
|
|
119
|
-
if (!formField)
|
|
120
|
-
return null;
|
|
121
|
-
const { error, formItemId } = formField;
|
|
122
|
-
return (_jsx(Label, { className: cn(error && 'text-destructive', className), htmlFor: formItemId, ...props }));
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Form control component
|
|
126
|
-
*
|
|
127
|
-
* Wraps form input components with proper ARIA attributes.
|
|
128
|
-
*
|
|
129
|
-
* @param {ComponentProps<typeof Slot>} props - Component props
|
|
130
|
-
* @returns {JSX.Element | null} Form control component
|
|
131
|
-
* @version 0.1.0
|
|
132
|
-
* @since 0.0.1
|
|
133
|
-
* @author AMBROISE PARK Consulting
|
|
134
|
-
*/
|
|
135
|
-
const FormControl = ({ ...props }) => {
|
|
136
|
-
const formField = useFormField();
|
|
137
|
-
if (!formField)
|
|
138
|
-
return null;
|
|
139
|
-
const { error, formItemId, formDescriptionId, formMessageId } = formField;
|
|
140
|
-
return (_jsx(Slot, { id: formItemId, "aria-describedby": !error
|
|
141
|
-
? `${formDescriptionId}`
|
|
142
|
-
: `${formDescriptionId} ${formMessageId}`, "aria-invalid": !!error, ...props }));
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* Form description component
|
|
146
|
-
*
|
|
147
|
-
* Renders descriptive text for a form field.
|
|
148
|
-
*
|
|
149
|
-
* @param {HTMLAttributes<HTMLParagraphElement>} props - Component props
|
|
150
|
-
* @returns {JSX.Element | null} Form description component
|
|
151
|
-
* @version 0.1.0
|
|
152
|
-
* @since 0.0.1
|
|
153
|
-
* @author AMBROISE PARK Consulting
|
|
154
|
-
*/
|
|
155
|
-
const FormDescription = ({ className, ...props }) => {
|
|
156
|
-
const formField = useFormField();
|
|
157
|
-
if (!formField)
|
|
158
|
-
return null;
|
|
159
|
-
const { formDescriptionId } = formField;
|
|
160
|
-
return (_jsx("p", { id: formDescriptionId, className: className, style: {
|
|
161
|
-
fontSize: 'var(--font-size-sm)',
|
|
162
|
-
color: 'var(--muted-foreground)',
|
|
163
|
-
}, ...props }));
|
|
164
|
-
};
|
|
165
|
-
/**
|
|
166
|
-
* Form message component
|
|
167
|
-
*
|
|
168
|
-
* Renders error or custom messages for a form field.
|
|
169
|
-
*
|
|
170
|
-
* @param {HTMLAttributes<HTMLParagraphElement>} props - Component props
|
|
171
|
-
* @returns {JSX.Element | null} Form message component
|
|
172
|
-
* @version 0.1.0
|
|
173
|
-
* @since 0.0.1
|
|
174
|
-
* @author AMBROISE PARK Consulting
|
|
175
|
-
*/
|
|
176
|
-
const FormMessage = ({ className, children, ...props }) => {
|
|
177
|
-
const formField = useFormField();
|
|
178
|
-
if (!formField)
|
|
179
|
-
return null;
|
|
180
|
-
const { error, formMessageId } = formField;
|
|
181
|
-
const body = error ? String(error?.message) : children;
|
|
182
|
-
if (!body) {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
return (_jsx("p", { id: formMessageId, className: className, style: {
|
|
186
|
-
fontSize: 'var(--font-size-sm)',
|
|
187
|
-
fontWeight: 500,
|
|
188
|
-
color: 'var(--destructive)',
|
|
189
|
-
}, ...props, children: body }));
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Form component exports
|
|
193
|
-
*
|
|
194
|
-
* @version 0.1.0
|
|
195
|
-
* @since 0.0.1
|
|
196
|
-
* @author AMBROISE PARK Consulting
|
|
197
|
-
*/
|
|
198
|
-
export { Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField, useFormField, };
|
|
1
|
+
"use client";import{createContext as d,useId as c,use as a}from"react";import{Controller as f,FormProvider as p,useFormContext as v}from"react-hook-form";import{Label as C,Slot as T,cn as I,Stack as P}from"@donotdev/components";import{jsx as i}from"react/jsx-runtime";var b=p,u=d({}),h=({...e})=>i(u.Provider,{value:{name:e.name},children:i(f,{...e})}),F=d({}),y=({className:e,children:o,...t})=>{let r=c();return i(F.Provider,{value:{id:r},children:i(P,{className:e,...t,children:o})})},l=()=>{let e=a(u);if(!e||!e.name)return null;let o=a(F);if(!o)return null;let{getFieldState:t,formState:r}=v(),n=t(e.name,r),{id:s}=o;return{id:s,name:e.name,formItemId:`${s}-form-item`,formDescriptionId:`${s}-form-item-description`,formMessageId:`${s}-form-item-message`,...n}},N=({className:e,...o})=>{let t=l();if(!t)return null;let{error:r,formItemId:n}=t;return i(C,{className:I(r&&"text-destructive",e),htmlFor:n,...o})},M=({...e})=>{let o=l();if(!o)return null;let{error:t,formItemId:r,formDescriptionId:n,formMessageId:s}=o;return i(T,{id:r,"aria-describedby":t?`${n} ${s}`:`${n}`,"aria-invalid":!!t,...e})},L=({className:e,...o})=>{let t=l();if(!t)return null;let{formDescriptionId:r}=t;return i("p",{id:r,className:e,style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},...o})},S=({className:e,children:o,...t})=>{let r=l();if(!r)return null;let{error:n,formMessageId:s}=r,m=n?String(n?.message):o;return m?i("p",{id:s,className:e,style:{fontSize:"var(--font-size-sm)",fontWeight:500,color:"var(--destructive)"},...t,children:m}):null};export{b as Form,M as FormControl,L as FormDescription,h as FormField,y as FormItem,N as FormLabel,S as FormMessage,l as useFormField};
|
|
@@ -1,74 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { describeEntity } from '@donotdev/core';
|
|
3
|
-
import { translateLabel } from '../crudImports';
|
|
4
|
-
/** Field types edited as free text in an editable list. */
|
|
5
|
-
const TEXT_TYPES = new Set(['text', 'email', 'url', 'tel', 'textarea']);
|
|
6
|
-
/** Field types edited as a dropdown of their `validation.options`. */
|
|
7
|
-
const OPTION_TYPES = new Set(['select', 'radio']);
|
|
8
|
-
/**
|
|
9
|
-
* Cell editor of a list field, or `undefined` when the field is not edited in
|
|
10
|
-
* the table (type without a cell editor, or not editable by the viewer).
|
|
11
|
-
* Editability is the form's (`editableFor(viewerRole, 'edit')`): generated,
|
|
12
|
-
* computed, `editable: false`, create-only, role-denied and technical fields stay
|
|
13
|
-
* read-only. References (any field type with `validation.reference`, descriptor
|
|
14
|
-
* `value.kind === 'ref'`) list the referenced records by their resolved label
|
|
15
|
-
* (`useReferenceResolver`); a reference whose collection is not resolved yet stays
|
|
16
|
-
* read-only.
|
|
17
|
-
*
|
|
18
|
-
* @param entity - Entity owning the field (the extension entity for an extension column)
|
|
19
|
-
* @param name - Field name in `entity.fields` (unprefixed)
|
|
20
|
-
* @param viewerRole - Viewer's role
|
|
21
|
-
* @param referenceData - Resolved reference labels by collection
|
|
22
|
-
* @param t - Translator for option labels
|
|
23
|
-
* @returns The cell editor, or `undefined`
|
|
24
|
-
* @throws When `entity` has no field `name`
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* cellEditFor(productEntity, 'price', 'admin', {}, t);
|
|
29
|
-
* // { type: 'number' }
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @version 0.2.0
|
|
33
|
-
* @since 0.2.3
|
|
34
|
-
*/
|
|
35
|
-
export function cellEditFor(entity, name, viewerRole, referenceData, t) {
|
|
36
|
-
const field = entity.fields[name];
|
|
37
|
-
const descriptor = describeEntity(entity).fields[name];
|
|
38
|
-
if (!field || !descriptor) {
|
|
39
|
-
throw new Error(`cellEditFor: entity "${entity.name}" has no field "${name}".`);
|
|
40
|
-
}
|
|
41
|
-
if (!descriptor.editableFor(viewerRole, 'edit'))
|
|
42
|
-
return undefined;
|
|
43
|
-
const { value } = descriptor;
|
|
44
|
-
if (value.kind === 'ref' && value.ref !== undefined) {
|
|
45
|
-
const labels = referenceData[value.ref];
|
|
46
|
-
if (!labels)
|
|
47
|
-
return undefined;
|
|
48
|
-
return {
|
|
49
|
-
type: 'select',
|
|
50
|
-
options: Object.entries(labels)
|
|
51
|
-
.map(([id, label]) => ({ value: id, label }))
|
|
52
|
-
.sort((a, b) => a.label.localeCompare(b.label)),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
const { type } = field;
|
|
56
|
-
if (TEXT_TYPES.has(type))
|
|
57
|
-
return { type: 'text' };
|
|
58
|
-
if (type === 'number')
|
|
59
|
-
return { type: 'number' };
|
|
60
|
-
if (OPTION_TYPES.has(type)) {
|
|
61
|
-
const raw = field.validation?.options;
|
|
62
|
-
const options = typeof raw === 'function' ? raw() : raw;
|
|
63
|
-
if (!Array.isArray(options))
|
|
64
|
-
return undefined;
|
|
65
|
-
return {
|
|
66
|
-
type: 'select',
|
|
67
|
-
options: options.map((o) => ({
|
|
68
|
-
value: String(o.value),
|
|
69
|
-
label: translateLabel(o.label, t),
|
|
70
|
-
})),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
1
|
+
import{describeEntity as u}from"@donotdev/core";import{translateLabel as p}from"../crudImports.js";var y=new Set(["text","email","url","tel","textarea"]),b=new Set(["select","radio"]);function E(r,i,d,f,c){let o=r.fields[i],l=u(r).fields[i];if(!o||!l)throw new Error(`cellEditFor: entity "${r.name}" has no field "${i}".`);if(!l.editableFor(d,"edit"))return;let{value:s}=l;if(s.kind==="ref"&&s.ref!==void 0){let e=f[s.ref];return e?{type:"select",options:Object.entries(e).map(([t,n])=>({value:t,label:n})).sort((t,n)=>t.label.localeCompare(n.label))}:void 0}let{type:a}=o;if(y.has(a))return{type:"text"};if(a==="number")return{type:"number"};if(b.has(a)){let e=o.validation?.options,t=typeof e=="function"?e():e;return Array.isArray(t)?{type:"select",options:t.map(n=>({value:String(n.value),label:p(n.label,c)}))}:void 0}}export{E as cellEditFor};
|
|
@@ -1,76 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Parent / child records (nested lists)
|
|
4
|
-
* @description An `EntityList` with `parent` lists one parent's children and its
|
|
5
|
-
* add button opens `basePath/new?<field>=<id>`. `EntityFormRenderer` (create)
|
|
6
|
-
* prefills that reference field from the URL. `parent.value: null` (parent not
|
|
7
|
-
* created yet) shows the create-first message instead. URL input is untrusted: only
|
|
8
|
-
* reference fields of the entity the viewer may set on create, with an id-shaped
|
|
9
|
-
* value, are taken. Reference fields and editability come from the entity
|
|
10
|
-
* descriptor (`describeEntity`).
|
|
11
|
-
*
|
|
12
|
-
* @version 0.1.0
|
|
13
|
-
* @since 0.2.3
|
|
14
|
-
* @author AMBROISE PARK Consulting
|
|
15
|
-
*/
|
|
16
|
-
import { describeEntity } from '@donotdev/core';
|
|
17
|
-
/** Record id shape accepted from a URL (Firestore ids, UUIDs, slugs). */
|
|
18
|
-
const RECORD_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
19
|
-
/**
|
|
20
|
-
* True when `field` is a reference field of `entity`: descriptor
|
|
21
|
-
* `value.kind === 'ref'` (any field type with `validation.reference`, custom ones included).
|
|
22
|
-
*/
|
|
23
|
-
const isReferenceField = (entity, field) => {
|
|
24
|
-
const value = Object.hasOwn(entity.fields, field)
|
|
25
|
-
? describeEntity(entity).fields[field]?.value
|
|
26
|
-
: undefined;
|
|
27
|
-
return value?.kind === 'ref' && value.ref !== undefined;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Throws when `parent.field` is not a reference field of the listed entity, or
|
|
31
|
-
* `parent.value` is neither a record id nor `null` (parent not created yet).
|
|
32
|
-
* A wrong parent would silently list nothing.
|
|
33
|
-
*
|
|
34
|
-
* @param entity - The listed (child) entity
|
|
35
|
-
* @param parent - The nested list's parent
|
|
36
|
-
*/
|
|
37
|
-
export function assertEntityParent(entity, parent) {
|
|
38
|
-
if (!isReferenceField(entity, parent.field)) {
|
|
39
|
-
throw new Error(`EntityList: parent.field "${parent.field}" is not a reference field of entity "${entity.name}".`);
|
|
40
|
-
}
|
|
41
|
-
if (parent.value !== null && !RECORD_ID.test(parent.value)) {
|
|
42
|
-
throw new Error(`EntityList: parent.value "${parent.value}" is not a record id.`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Create path of a child record with its parent prefilled.
|
|
47
|
-
*
|
|
48
|
-
* @param basePath - The list's base path
|
|
49
|
-
* @param parent - The nested list's parent (created)
|
|
50
|
-
* @returns `${basePath}/new?<field>=<id>`
|
|
51
|
-
*/
|
|
52
|
-
export function childCreatePath(basePath, parent) {
|
|
53
|
-
const query = new URLSearchParams({ [parent.field]: parent.value });
|
|
54
|
-
return `${basePath}/new?${query.toString()}`;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Create-form values taken from the URL: reference fields of the entity the
|
|
58
|
-
* viewer may set on create, whose value is a record id. Anything else is ignored.
|
|
59
|
-
*
|
|
60
|
-
* @param entity - The entity being created
|
|
61
|
-
* @param params - The current URL's search params
|
|
62
|
-
* @param viewerRole - The viewer's role
|
|
63
|
-
* @returns The prefilled reference values (empty when none)
|
|
64
|
-
*/
|
|
65
|
-
export function referencePrefillFromQuery(entity, params, viewerRole) {
|
|
66
|
-
const prefill = {};
|
|
67
|
-
for (const [key, value] of params.entries()) {
|
|
68
|
-
if (Object.hasOwn(entity.fields, key) &&
|
|
69
|
-
isReferenceField(entity, key) &&
|
|
70
|
-
RECORD_ID.test(value) &&
|
|
71
|
-
describeEntity(entity).fields[key]?.editableFor(viewerRole, 'create') === true) {
|
|
72
|
-
prefill[key] = value;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return prefill;
|
|
76
|
-
}
|
|
1
|
+
import{describeEntity as s}from"@donotdev/core";var a=/^[A-Za-z0-9_-]{1,128}$/,f=(t,e)=>{let n=Object.hasOwn(t.fields,e)?s(t).fields[e]?.value:void 0;return n?.kind==="ref"&&n.ref!==void 0};function l(t,e){if(!f(t,e.field))throw new Error(`EntityList: parent.field "${e.field}" is not a reference field of entity "${t.name}".`);if(e.value!==null&&!a.test(e.value))throw new Error(`EntityList: parent.value "${e.value}" is not a record id.`)}function c(t,e){let n=new URLSearchParams({[e.field]:e.value});return`${t}/new?${n.toString()}`}function u(t,e,n){let i={};for(let[r,o]of e.entries())Object.hasOwn(t.fields,r)&&f(t,r)&&a.test(o)&&s(t).fields[r]?.editableFor(n,"create")===!0&&(i[r]=o);return i}export{l as assertEntityParent,c as childCreatePath,u as referencePrefillFromQuery};
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview CRUD components
|
|
4
|
-
* @description CRUD components with routing support (moved from @donotdev/crud)
|
|
5
|
-
*
|
|
6
|
-
* @version 0.1.0
|
|
7
|
-
* @since 0.0.1
|
|
8
|
-
* @author AMBROISE PARK Consulting
|
|
9
|
-
*/
|
|
10
|
-
export { EntityDisplayRenderer } from './EntityDisplayRenderer';
|
|
11
|
-
export { EntityList } from './EntityList';
|
|
12
|
-
export { EntityCardList } from './EntityCardList';
|
|
13
|
-
export { EntityFormRenderer } from './EntityFormRenderer';
|
|
14
|
-
export { EntityRecommendations } from './EntityRecommendations';
|
|
15
|
-
export { EntityWorkflow } from './EntityWorkflow';
|
|
16
|
-
export * from './Form';
|
|
1
|
+
import{EntityDisplayRenderer as o}from"./EntityDisplayRenderer.js";import{EntityList as n}from"./EntityList.js";import{EntityCardList as p}from"./EntityCardList.js";import{EntityFormRenderer as m}from"./EntityFormRenderer.js";import{EntityRecommendations as E}from"./EntityRecommendations.js";import{EntityWorkflow as d}from"./EntityWorkflow.js";export*from"./Form.js";export{p as EntityCardList,o as EntityDisplayRenderer,m as EntityFormRenderer,n as EntityList,E as EntityRecommendations,d as EntityWorkflow};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { AnyEntity } from '@donotdev/core';
|
|
2
2
|
/**
|
|
3
3
|
* Names the shown record in the breadcrumbs: the entity's card title, formatted like
|
|
4
|
-
* the card (the same title
|
|
4
|
+
* the card (the same title `deriveEntitySeo` gives the entity page's metadata and the last
|
|
5
|
+
* BreadcrumbList item), on the segment naming the record ({@link recordSegment}: its slug
|
|
6
|
+
* on `/produits/:slug`, its id on `/products/:id`). Cleared when the page unmounts or the record
|
|
5
7
|
* has no title, unless another component replaced it meanwhile (its label stays). Client effect: the server render keeps the URL segment.
|
|
6
8
|
*
|
|
7
9
|
* @param entity - Entity of the record
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRecordBreadcrumb.d.ts","sourceRoot":"","sources":["../../../src/crud/components/useRecordBreadcrumb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRecordBreadcrumb.d.ts","sourceRoot":"","sources":["../../../src/crud/components/useRecordBreadcrumb.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAoChD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GACjD,IAAI,CAuBN"}
|
|
@@ -1,43 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Record name in the breadcrumbs
|
|
4
|
-
* @description Publishes the shown record's display name to the layout store, so the
|
|
5
|
-
* breadcrumb segment holding its id (`/products/<uuid>`) reads as the record's name.
|
|
6
|
-
*
|
|
7
|
-
* @version 0.1.0
|
|
8
|
-
* @since 0.2.3
|
|
9
|
-
* @author AMBROISE PARK Consulting
|
|
10
|
-
*/
|
|
11
|
-
import { useEffect, useRef } from 'react';
|
|
12
|
-
import { deriveEntitySeo, useLayout, useTranslation } from '@donotdev/core';
|
|
13
|
-
/**
|
|
14
|
-
* Names the shown record in the breadcrumbs: the entity's card title, formatted like
|
|
15
|
-
* the card (the same title `<Seo entity>` uses). Cleared when the page unmounts or the record
|
|
16
|
-
* has no title, unless another component replaced it meanwhile (its label stays). Client effect: the server render keeps the URL segment.
|
|
17
|
-
*
|
|
18
|
-
* @param entity - Entity of the record
|
|
19
|
-
* @param record - Loaded record (`undefined` / `null` while loading)
|
|
20
|
-
*/
|
|
21
|
-
export function useRecordBreadcrumb(entity, record) {
|
|
22
|
-
const setRecordLabel = useLayout('setRouteRecordLabel');
|
|
23
|
-
// The label currently shown: cleanup clears only its own label, never one another
|
|
24
|
-
// component (e.g. the page) set after it.
|
|
25
|
-
const shown = useLayout('routeRecordLabel');
|
|
26
|
-
const shownRef = useRef(shown);
|
|
27
|
-
shownRef.current = shown;
|
|
28
|
-
const id = typeof record?.id === 'string' ? record.id : undefined;
|
|
29
|
-
const { t, language } = useTranslation([entity.namespace, 'crud']);
|
|
30
|
-
const label = record
|
|
31
|
-
? deriveEntitySeo(entity, record, { t, locale: language }).title
|
|
32
|
-
: undefined;
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (!id || !label)
|
|
35
|
-
return;
|
|
36
|
-
setRecordLabel({ id, label });
|
|
37
|
-
return () => {
|
|
38
|
-
const current = shownRef.current;
|
|
39
|
-
if (current?.id === id && current.label === label)
|
|
40
|
-
setRecordLabel(null);
|
|
41
|
-
};
|
|
42
|
-
}, [id, label, setRecordLabel]);
|
|
43
|
-
}
|
|
1
|
+
"use client";import{useEffect as l,useRef as g}from"react";import{deriveEntitySeo as m,useLayout as c,useTranslation as p}from"@donotdev/core";import{useParams as y}from"@donotdev/ui/routing/hooks";function R(n){try{return decodeURIComponent(n)}catch{return n}}function b(n,t){for(let[o,r]of Object.entries(t)){let e=n[o];if(typeof r=="string"&&!(typeof e!="string"&&typeof e!="number")&&(String(e)===r||String(e)===R(r)))return String(e)}return typeof n.id=="string"?n.id:void 0}function L(n,t){let o=c("setRouteRecordLabel"),r=c("routeRecordLabel"),e=g(r);e.current=r;let d=y(),i=t?b(t,d):void 0,{t:f,language:a}=p([n.namespace,"crud"]),u=t?m(n,t,{t:f,locale:a}).title:void 0;l(()=>{if(!(!i||!u))return o({id:i,label:u}),()=>{let s=e.current;s?.id===i&&s.label===u&&o(null)}},[i,u,o])}export{L as useRecordBreadcrumb};
|
package/dist/crud/crudImports.js
CHANGED
|
@@ -1,51 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Safe import hub for @donotdev/crud
|
|
4
|
-
* @description Single module-level import using the proven `import * as` pattern.
|
|
5
|
-
* When crud is not installed, Vite aliases it to an empty module — all extractions
|
|
6
|
-
* resolve to `undefined`. This is immutable: the decision is made once at module load.
|
|
7
|
-
*
|
|
8
|
-
* Components import from here instead of directly from '@donotdev/crud'.
|
|
9
|
-
* Type-only imports (`import type`) can still go directly to '@donotdev/crud'.
|
|
10
|
-
*
|
|
11
|
-
* @see useCrudSafe.ts — same pattern, proven in production
|
|
12
|
-
* @version 0.1.0
|
|
13
|
-
* @since 0.0.25
|
|
14
|
-
* @author AMBROISE PARK Consulting
|
|
15
|
-
*/
|
|
16
|
-
import * as crudModule from '@donotdev/crud';
|
|
17
|
-
/** true when @donotdev/crud resolved with real exports */
|
|
18
|
-
export const isCrudModuleAvailable = typeof crudModule?.useCrud === 'function';
|
|
19
|
-
// --- Hooks ---
|
|
20
|
-
export const useEntityForm = crudModule?.useEntityForm;
|
|
21
|
-
export const useFormStore = crudModule?.useFormStore;
|
|
22
|
-
/** Router placeholder for useEntityForm's leave-on-save (filled by UIProviders). */
|
|
23
|
-
export const FormNavigationProvider = crudModule?.FormNavigationProvider;
|
|
24
|
-
/** Subscribe to the existing submission error without duplicating form state. */
|
|
25
|
-
export const useFormError = crudModule?.useFormError;
|
|
26
|
-
export const useFieldConditions = crudModule?.useFieldConditions;
|
|
27
|
-
export const useCrud = crudModule?.useCrud;
|
|
28
|
-
export const useCrudList = crudModule?.useCrudList;
|
|
29
|
-
export const useCrudDoc = crudModule?.useCrudDoc;
|
|
30
|
-
export const useCrudCardList = crudModule?.useCrudCardList;
|
|
31
|
-
export const useEntityFavorites = crudModule?.useEntityFavorites;
|
|
32
|
-
export const useCrudFilters = crudModule?.useCrudFilters;
|
|
33
|
-
export const useCrudPageSize = crudModule?.useCrudPageSize;
|
|
34
|
-
export const useEntityWorkflow = crudModule?.useEntityWorkflow;
|
|
35
|
-
export const useReferenceResolver = crudModule?.useReferenceResolver;
|
|
36
|
-
/** Child rows of a record, joined to the form open on it (EntityList with `parent`). */
|
|
37
|
-
export const useChildRows = crudModule?.useChildRows;
|
|
38
|
-
/** The edit form open on a parent record that its child rows join, or null. */
|
|
39
|
-
export const useJoinedForm = crudModule?.useJoinedForm;
|
|
40
|
-
// --- Components ---
|
|
41
|
-
export const DisplayFieldRenderer = crudModule?.DisplayFieldRenderer;
|
|
42
|
-
export const FormFieldRenderer = crudModule?.FormFieldRenderer;
|
|
43
|
-
export const UploadProvider = crudModule?.UploadProvider;
|
|
44
|
-
export const EntityFilters = crudModule?.EntityFilters;
|
|
45
|
-
export const CrudCard = crudModule?.CrudCard;
|
|
46
|
-
// --- Utils ---
|
|
47
|
-
export const translateFieldLabel = crudModule?.translateFieldLabel;
|
|
48
|
-
export const formatValue = crudModule?.formatValue;
|
|
49
|
-
export const translateLabel = crudModule?.translateLabel;
|
|
50
|
-
export const applyFilters = crudModule?.applyFilters;
|
|
51
|
-
export const applySearch = crudModule?.applySearch;
|
|
1
|
+
import*as e from"@donotdev/crud";var r=typeof e?.useCrud=="function",o=e?.useEntityForm,t=e?.useFormStore,s=e?.FormNavigationProvider,n=e?.useFormError,u=e?.useFieldConditions,i=e?.useCrud,d=e?.useCrudList,l=e?.useCrudDoc,a=e?.useCrudCardList,p=e?.useEntityFavorites,c=e?.useCrudFilters,F=e?.useCrudPageSize,x=e?.useEntityWorkflow,C=e?.useReferenceResolver,m=e?.useChildRows,y=e?.useJoinedForm,v=e?.DisplayFieldRenderer,E=e?.FormFieldRenderer,R=e?.UploadProvider,f=e?.EntityFilters,L=e?.CrudCard,P=e?.translateFieldLabel,S=e?.formatValue,b=e?.translateLabel,g=e?.applyFilters,h=e?.applySearch;export{L as CrudCard,v as DisplayFieldRenderer,f as EntityFilters,E as FormFieldRenderer,s as FormNavigationProvider,R as UploadProvider,g as applyFilters,h as applySearch,S as formatValue,r as isCrudModuleAvailable,P as translateFieldLabel,b as translateLabel,m as useChildRows,i as useCrud,a as useCrudCardList,l as useCrudDoc,c as useCrudFilters,d as useCrudList,F as useCrudPageSize,p as useEntityFavorites,o as useEntityForm,x as useEntityWorkflow,u as useFieldConditions,n as useFormError,t as useFormStore,y as useJoinedForm,C as useReferenceResolver};
|
package/dist/crud/index.js
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview CRUD Package Re-exports
|
|
4
|
-
* @description Re-exports CRUD functionality from @donotdev/crud feature package
|
|
5
|
-
*
|
|
6
|
-
* @version 0.1.0
|
|
7
|
-
* @since 0.0.1
|
|
8
|
-
* @author AMBROISE PARK Consulting
|
|
9
|
-
*/
|
|
10
|
-
// Export display components (still in UI package)
|
|
11
|
-
export * from './components';
|
|
1
|
+
export*from"./components/index.js";
|