@donotdev/ui 0.2.2 → 0.3.0
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/ChildRowsPicker-63M4EQUQ.js +1 -0
- package/dist/ChildRowsPicker-ISP365ON.js +1 -0
- package/dist/ChildRowsPicker-PQFE6NCR.js +1 -0
- package/dist/ChildRowsPicker-XXFFSMWY.js +1 -0
- package/dist/{GoToDialog-CICRYHHG.js → GoToDialog-KSBGOIWO.js} +1 -1
- package/dist/{GoToDialog-YGBON6FR.js → GoToDialog-XBK5EZF4.js} +1 -1
- package/dist/chunk-3CIZFGST.js +1 -0
- package/dist/chunk-LHMKU342.js +1 -0
- package/dist/chunk-MS7ZIW5Z.js +1 -0
- package/dist/chunk-P2DHZWPY.js +1 -0
- package/dist/components/auth/AuthHeader.d.ts.map +1 -1
- package/dist/components/auth/AuthHeader.js +0 -2
- package/dist/components/auth/AuthMenu.d.ts.map +1 -1
- package/dist/components/auth/AuthMenu.js +6 -40
- package/dist/components/common/icon.d.ts.map +1 -1
- package/dist/components/common/icon.js +2 -1
- package/dist/components/common/lucideIconByName.d.ts +9 -0
- package/dist/components/common/lucideIconByName.d.ts.map +1 -0
- package/dist/components/common/lucideIconByName.js +32 -0
- package/dist/components/layout/GameFlow.d.ts.map +1 -1
- package/dist/components/layout/components/Breadcrumbs.d.ts.map +1 -1
- package/dist/components/layout/components/Breadcrumbs.js +18 -12
- package/dist/components/layout/components/header/CacheSettings.d.ts.map +1 -1
- package/dist/components/layout/components/header/CacheSettings.js +6 -4
- package/dist/components/layout/components/header/SettingsMenu.d.ts.map +1 -1
- package/dist/components/layout/components/header/SettingsMenu.js +4 -3
- package/dist/components/layout/components/header/ThemeToggle.d.ts.map +1 -1
- package/dist/components/layout/components/header/ThemeToggle.js +2 -1
- package/dist/crud/components/ChildRowsPicker.d.ts +21 -0
- package/dist/crud/components/ChildRowsPicker.d.ts.map +1 -0
- package/dist/crud/components/ChildRowsPicker.js +68 -0
- package/dist/crud/components/CrudCardLink.d.ts +6 -6
- package/dist/crud/components/CrudCardLink.d.ts.map +1 -1
- package/dist/crud/components/CrudCardLink.js +3 -9
- package/dist/crud/components/EntityCardList.d.ts.map +1 -1
- package/dist/crud/components/EntityCardList.js +10 -26
- package/dist/crud/components/EntityDisplayRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityDisplayRenderer.js +6 -3
- package/dist/crud/components/EntityFormRenderer.d.ts +4 -2
- package/dist/crud/components/EntityFormRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityFormRenderer.js +160 -56
- package/dist/crud/components/EntityList.d.ts +6 -4
- package/dist/crud/components/EntityList.d.ts.map +1 -1
- package/dist/crud/components/EntityList.js +437 -92
- package/dist/crud/components/EntityRecommendations.js +1 -1
- package/dist/crud/components/EntityWorkflow.d.ts.map +1 -1
- package/dist/crud/components/EntityWorkflow.js +6 -4
- package/dist/crud/components/Form.d.ts +1 -1
- package/dist/crud/components/Form.d.ts.map +1 -1
- package/dist/crud/components/Form.js +2 -2
- package/dist/crud/components/cellEditFor.d.ts +43 -0
- package/dist/crud/components/cellEditFor.d.ts.map +1 -0
- package/dist/crud/components/cellEditFor.js +74 -0
- package/dist/crud/components/entityParent.d.ts +33 -0
- package/dist/crud/components/entityParent.d.ts.map +1 -0
- package/dist/crud/components/entityParent.js +76 -0
- package/dist/crud/components/useRecordBreadcrumb.d.ts +11 -0
- package/dist/crud/components/useRecordBreadcrumb.d.ts.map +1 -0
- package/dist/crud/components/useRecordBreadcrumb.js +43 -0
- package/dist/crud/crudImports.d.ts +12 -1
- package/dist/crud/crudImports.d.ts.map +1 -1
- package/dist/crud/crudImports.js +11 -0
- package/dist/dndev-next.css +782 -193
- package/dist/dndev.css +784 -193
- package/dist/index.js +4 -4
- package/dist/internal/common/RouteErrorFallback.d.ts.map +1 -1
- package/dist/internal/common/RouteErrorFallback.js +2 -4
- package/dist/internal/devtools/components/ConfigTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/ConfigTab.js +1 -1
- package/dist/internal/devtools/components/CookieTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/CookieTab.js +1 -5
- package/dist/internal/devtools/components/DesignTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/DesignTab.js +18 -7
- package/dist/internal/devtools/components/StoresTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/StoresTab.js +17 -3
- package/dist/internal/devtools/types.d.ts +3 -3
- package/dist/internal/devtools/types.d.ts.map +1 -1
- package/dist/internal/devtools/utils/maskSensitive.d.ts +1 -1
- package/dist/internal/devtools/utils/maskSensitive.d.ts.map +1 -1
- package/dist/internal/initializers/NextJsStoresInitializer.d.ts +3 -0
- package/dist/internal/initializers/NextJsStoresInitializer.d.ts.map +1 -1
- package/dist/internal/initializers/NextJsStoresInitializer.js +8 -1
- package/dist/internal/layout/DnDevLayout.d.ts.map +1 -1
- package/dist/internal/layout/DnDevLayout.js +21 -21
- package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
- package/dist/internal/layout/components/AutoMetaTags.js +42 -38
- package/dist/internal/layout/components/FontPreloadLinks.d.ts +7 -4
- package/dist/internal/layout/components/FontPreloadLinks.d.ts.map +1 -1
- package/dist/internal/layout/components/FontPreloadLinks.js +12 -25
- package/dist/internal/layout/components/footer/FooterCopyright.d.ts +2 -0
- package/dist/internal/layout/components/footer/FooterCopyright.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/FooterCopyright.js +4 -0
- package/dist/internal/layout/components/footer/useLegalLinks.d.ts +2 -1
- package/dist/internal/layout/components/footer/useLegalLinks.d.ts.map +1 -1
- package/dist/internal/layout/components/footer/useLegalLinks.js +4 -3
- package/dist/internal/layout/components/i18nSeoMeta.d.ts.map +1 -1
- package/dist/internal/layout/components/i18nSeoMeta.js +1 -0
- package/dist/internal/layout/zones/DnDevMergedBar.js +3 -3
- package/dist/internal/providers/UIProviders.d.ts +0 -8
- package/dist/internal/providers/UIProviders.d.ts.map +1 -1
- package/dist/internal/providers/UIProviders.js +45 -2
- package/dist/providers/NextJsAppProviders.d.ts +5 -1
- package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
- package/dist/providers/NextJsAppProviders.js +36 -6
- package/dist/providers/ViteAppProviders.d.ts.map +1 -1
- package/dist/providers/ViteAppProviders.js +42 -7
- package/dist/routing/404.d.ts +8 -1
- package/dist/routing/404.d.ts.map +1 -1
- package/dist/routing/404.js +9 -5
- package/dist/routing/AuthGuardFallback.d.ts.map +1 -1
- package/dist/routing/AuthGuardFallback.js +1 -2
- package/dist/routing/AuthReturnTo.d.ts.map +1 -1
- package/dist/routing/AuthReturnTo.js +9 -2
- package/dist/routing/GoTo.d.ts +0 -6
- package/dist/routing/GoTo.d.ts.map +1 -1
- package/dist/routing/GoTo.js +5 -8
- package/dist/routing/Link.d.ts +4 -2
- package/dist/routing/Link.d.ts.map +1 -1
- package/dist/routing/Link.js +8 -5
- package/dist/routing/SignedInRedirect.d.ts +27 -0
- package/dist/routing/SignedInRedirect.d.ts.map +1 -0
- package/dist/routing/SignedInRedirect.js +47 -0
- package/dist/routing/hooks/hooks.next.d.ts +2 -0
- package/dist/routing/hooks/hooks.next.d.ts.map +1 -1
- package/dist/routing/hooks/hooks.next.js +1 -1
- package/dist/routing/hooks/hooks.vite.d.ts +2 -0
- package/dist/routing/hooks/hooks.vite.d.ts.map +1 -1
- package/dist/routing/hooks/hooks.vite.js +1 -1
- package/dist/routing/hooks/useLocation.next.d.ts +12 -0
- package/dist/routing/hooks/useLocation.next.d.ts.map +1 -1
- package/dist/routing/hooks/useLocation.next.js +17 -4
- package/dist/routing/hooks/useMatch.next.d.ts +6 -0
- package/dist/routing/hooks/useMatch.next.d.ts.map +1 -1
- package/dist/routing/hooks/useMatch.next.js +8 -2
- package/dist/routing/hooks/useNavigate.next.d.ts +6 -1
- package/dist/routing/hooks/useNavigate.next.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.next.js +13 -4
- package/dist/routing/hooks/useNavigate.vite.d.ts +7 -1
- package/dist/routing/hooks/useNavigate.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.vite.js +20 -4
- package/dist/routing/hooks/useRedirectGuard.next.d.ts +3 -1
- package/dist/routing/hooks/useRedirectGuard.next.d.ts.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.next.js +18 -10
- package/dist/routing/hooks/useRedirectGuard.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.vite.js +7 -1
- package/dist/routing/hooks/useRoutePath.next.d.ts +23 -0
- package/dist/routing/hooks/useRoutePath.next.d.ts.map +1 -0
- package/dist/routing/hooks/useRoutePath.next.js +36 -0
- package/dist/routing/hooks/useRoutePath.vite.d.ts +13 -0
- package/dist/routing/hooks/useRoutePath.vite.d.ts.map +1 -0
- package/dist/routing/hooks/useRoutePath.vite.js +25 -0
- package/dist/routing/hooks/useUrlLanguage.next.d.ts +28 -0
- package/dist/routing/hooks/useUrlLanguage.next.d.ts.map +1 -0
- package/dist/routing/hooks/useUrlLanguage.next.js +50 -0
- package/dist/routing/hooks/useUrlLanguage.vite.d.ts +22 -0
- package/dist/routing/hooks/useUrlLanguage.vite.d.ts.map +1 -0
- package/dist/routing/hooks/useUrlLanguage.vite.js +41 -0
- package/dist/routing/index.d.ts +3 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +2 -1
- package/dist/routing/parentRoute.d.ts +27 -0
- package/dist/routing/parentRoute.d.ts.map +1 -0
- package/dist/routing/parentRoute.js +43 -0
- package/dist/routing/useNavigation.d.ts.map +1 -1
- package/dist/routing/useNavigation.js +8 -27
- package/dist/routing/useRouteDiscovery.d.ts +2 -2
- package/dist/routing/useRouteDiscovery.d.ts.map +1 -1
- package/dist/routing/useRouteDiscovery.js +6 -5
- package/dist/styles/index.css +781 -192
- package/dist/symbol-index.json +1 -1
- package/dist/utils/assetResolver.d.ts.map +1 -1
- package/dist/utils/assetResolver.js +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -0
- package/dist/utils/useDeleteAccountSafe.d.ts +17 -0
- package/dist/utils/useDeleteAccountSafe.d.ts.map +1 -0
- package/dist/utils/useDeleteAccountSafe.js +52 -0
- package/dist/utils/useFormStoreSafe.d.ts.map +1 -1
- package/dist/utils/useFormStoreSafe.js +1 -0
- package/dist/utils/useSeo.d.ts +10 -2
- package/dist/utils/useSeo.d.ts.map +1 -1
- package/dist/utils/useSeo.js +44 -9
- package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
- package/dist/vite-routing/AppRoutes.js +37 -4
- package/guidelines/COMPONENTS.md +2 -1
- package/guidelines/GOTCHAS.md +2 -0
- package/guidelines/LAYOUTS.md +4 -0
- package/guidelines/PAGES.md +30 -3
- package/guidelines/ROUTING.md +29 -0
- package/guidelines/SEO.md +52 -0
- package/package.json +9 -9
- package/dist/CookieConsent-5NH5DNTP.js +0 -1
- package/dist/CookieConsent-W7UE647Y.js +0 -1
- package/dist/chunk-DRFM6WXH.js +0 -1
- package/dist/chunk-MIPTBUWY.js +0 -1
- package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts +0 -57
- package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts.map +0 -1
- package/dist/internal/layout/components/NextJsAutoMetaTags.js +0 -182
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { Link } from '../../routing';
|
|
4
3
|
import { isCrudModuleAvailable, CrudCard as BaseCrudCard, } from '../crudImports';
|
|
5
4
|
/**
|
|
6
|
-
* CrudCard with
|
|
7
|
-
* When detailHref is provided,
|
|
5
|
+
* CrudCard with link navigation.
|
|
6
|
+
* When detailHref is provided, the card links to it (crawlable, client-side navigation).
|
|
8
7
|
*/
|
|
9
8
|
export function CrudCard({ detailHref, onClick, ...rest }) {
|
|
10
9
|
// Safe guard: isCrudModuleAvailable is a module-level constant (immutable after load).
|
|
11
10
|
if (!isCrudModuleAvailable)
|
|
12
11
|
return null;
|
|
13
|
-
|
|
14
|
-
const card = (_jsx(BaseCrudCard, { ...rest, onClick: detailHref ? undefined : onClick }));
|
|
15
|
-
if (detailHref) {
|
|
16
|
-
return (_jsx(Link, { path: detailHref, "aria-label": rest.item?.id ? `View ${rest.item.id}` : undefined, children: card }));
|
|
17
|
-
}
|
|
18
|
-
return card;
|
|
12
|
+
return detailHref ? (_jsx(BaseCrudCard, { ...rest, href: detailHref })) : (_jsx(BaseCrudCard, { ...rest, onClick: onClick }));
|
|
19
13
|
}
|
|
20
14
|
export default CrudCard;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityCardList.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityCardList.tsx"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,mBAAmB,EAAgB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"EntityCardList.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityCardList.tsx"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,mBAAmB,EAAgB,MAAM,gBAAgB,CAAC;AAaxE,YAAY,EAAE,mBAAmB,EAAE,CAAC;AAwGpC;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,QAAQ,EACR,OAAO,EACP,IAAmB,EACnB,SAA0B,EAAE,2BAA2B;AACvD,YAAY,EACZ,MAAM,EACN,WAAmB,EACnB,WAAW,EACX,IAAI,EACJ,iBAAiB,EACjB,UAAU,EACV,WAAmB,EACnB,WAAW,EACX,OAAO,GACR,EAAE,mBAAmB,sCA6NrB"}
|
|
@@ -20,6 +20,7 @@ import { useTranslation, getListCardFieldNames, useBreakpoint, } from '@donotdev
|
|
|
20
20
|
import { isCrudModuleAvailable, useCrudCardList, EntityFilters, useEntityFavorites, useCrudFilters, } from '../crudImports';
|
|
21
21
|
import { CrudCard } from './CrudCardLink';
|
|
22
22
|
import { useNavigate } from '../../routing';
|
|
23
|
+
import { useAuthSafe } from '../../utils/useAuthSafe';
|
|
23
24
|
/**
|
|
24
25
|
* Resolve skeleton slots from entity shape — mirrors CrudCard's useResolvedSlots exactly.
|
|
25
26
|
* Returns the actual field names per slot so skeletons render the same structure as real cards.
|
|
@@ -63,9 +64,7 @@ const BREAKPOINT_INDEX = {
|
|
|
63
64
|
function CardListSkeleton({ cols, entity, }) {
|
|
64
65
|
const slots = resolveSkeletonSlots(entity);
|
|
65
66
|
const bp = useBreakpoint('current');
|
|
66
|
-
const currentCols = (Array.isArray(cols)
|
|
67
|
-
? cols[BREAKPOINT_INDEX[bp] ?? 3]
|
|
68
|
-
: cols) ?? 1;
|
|
67
|
+
const currentCols = (Array.isArray(cols) ? cols[BREAKPOINT_INDEX[bp] ?? 3] : cols) ?? 1;
|
|
69
68
|
const count = currentCols * 3;
|
|
70
69
|
const isImage = (name) => {
|
|
71
70
|
const type = entity.fields[name]?.type;
|
|
@@ -93,6 +92,7 @@ queryOptions, filter, hideFilters = false, resultLabel, tone, renderCardOverlay,
|
|
|
93
92
|
return null;
|
|
94
93
|
const isPreview = !!preview;
|
|
95
94
|
const navigate = useNavigate();
|
|
95
|
+
const viewerRole = useAuthSafe('userRole');
|
|
96
96
|
const base = basePath ?? `/${entity.collection}`;
|
|
97
97
|
// useCrudCardList -> handles fetching + client-side filter/search/sort via `processed`
|
|
98
98
|
const { items: rawData, processed, loading: fetchLoading, error: fetchError, } = useCrudCardList(entity, {
|
|
@@ -149,29 +149,17 @@ queryOptions, filter, hideFilters = false, resultLabel, tone, renderCardOverlay,
|
|
|
149
149
|
const entityName = t('name', { defaultValue: entity.name });
|
|
150
150
|
return (_jsxs(_Fragment, { children: [!hideFilters && (_jsx(Section, { title: tCrud('filters.title', {
|
|
151
151
|
entity: entityName,
|
|
152
|
-
defaultValue: `Browse ${entityName} - Filters`,
|
|
153
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
|
|
154
|
-
? tCrud('favorites.showAll'
|
|
155
|
-
: tCrud('favorites.showFavorites', {
|
|
156
|
-
|
|
157
|
-
}) }), !isPreview && (_jsx(EntityFilters, { entity: entity, data: rawData, fieldsToFilter: fieldsToFilter }))] }) }) })), _jsx(Section, { title: loading
|
|
158
|
-
? tCrud('results.title.fetching', { defaultValue: 'Fetching...' })
|
|
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')
|
|
159
156
|
: resultLabel
|
|
160
157
|
? resultLabel(data.length)
|
|
161
158
|
: tCrud('results.title.count', {
|
|
162
159
|
count: data.length,
|
|
163
|
-
|
|
164
|
-
? 'Found 1 occurrence'
|
|
165
|
-
: `Found ${data.length} occurrences`,
|
|
166
|
-
}), 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-3xl)', textAlign: 'center' }, children: [_jsx(Text, { level: "h3", style: { color: 'var(--destructive)' }, children: tCrud('errors.fetchFailed', {
|
|
167
|
-
defaultValue: `Failed to load ${entity.name.toLowerCase()}`,
|
|
168
|
-
}) }), _jsx(Text, { level: "small", style: { color: 'var(--destructive)' }, children: fetchError instanceof Error
|
|
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
|
|
169
161
|
? fetchError.message
|
|
170
|
-
: String(fetchError) })] })) : data.length === 0 ? (_jsxs(Stack, { align: "center", justify: "center", style: { padding: 'var(--gap-
|
|
171
|
-
defaultValue: `No ${entity.name.toLowerCase()} found`,
|
|
172
|
-
}) }), _jsx(Text, { style: { color: 'var(--muted-foreground)' }, children: tCrud('emptyState.description', {
|
|
173
|
-
defaultValue: `No ${entity.name.toLowerCase()} available at this time.`,
|
|
174
|
-
}) })] })) : (_jsx(Grid, { cols: cols, children: data.map((item) => {
|
|
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) => {
|
|
175
163
|
const itemIsFavorite = isFavorite(item.id);
|
|
176
164
|
const detailHref = isPreview || onClick ? undefined : `${base}/${item.id}`;
|
|
177
165
|
return (_jsx(CrudCard, { item: item, entity: entity, detailHref: detailHref, onClick: isPreview
|
|
@@ -190,11 +178,7 @@ queryOptions, filter, hideFilters = false, resultLabel, tone, renderCardOverlay,
|
|
|
190
178
|
transition: 'fill 0.2s, stroke 0.2s',
|
|
191
179
|
opacity: isPreview ? 0.5 : 1,
|
|
192
180
|
}, "aria-label": itemIsFavorite
|
|
193
|
-
? tCrud('favorites.remove'
|
|
194
|
-
|
|
195
|
-
})
|
|
196
|
-
: tCrud('favorites.add', {
|
|
197
|
-
defaultValue: 'Add to favorites',
|
|
198
|
-
}) }) }, item.id));
|
|
181
|
+
? tCrud('favorites.remove')
|
|
182
|
+
: tCrud('favorites.add') }) }, item.id));
|
|
199
183
|
}) })) })] }));
|
|
200
184
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityDisplayRenderer.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityDisplayRenderer.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"EntityDisplayRenderer.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityDisplayRenderer.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAU/E,YAAY,EAAE,0BAA0B,EAAE,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,EAC3E,MAAM,EACN,EAAE,EACF,CAAC,EACD,SAAc,EACd,cAAc,EACd,eAAe,EACf,UAAU,EAAE,cAAc,EAC1B,aAAa,EACb,OAAO,GACR,EAAE,0BAA0B,CAAC,CAAC,CAAC,sCAoK/B;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -15,6 +15,7 @@ import { Stack, Spinner } from '@donotdev/components';
|
|
|
15
15
|
import { useTranslation, isFieldVisible } from '@donotdev/core';
|
|
16
16
|
import { useAuthSafe } from '../../utils/useAuthSafe';
|
|
17
17
|
import { isCrudModuleAvailable, useCrudDoc, DisplayFieldRenderer, } from '../crudImports';
|
|
18
|
+
import { useRecordBreadcrumb } from './useRecordBreadcrumb';
|
|
18
19
|
/**
|
|
19
20
|
* EntityDisplayRenderer - Automatically fetches and displays entity data
|
|
20
21
|
*
|
|
@@ -47,6 +48,8 @@ export function EntityDisplayRenderer({ entity, id, t, className = '', loadingMe
|
|
|
47
48
|
const translate = t || tDual;
|
|
48
49
|
// Preview: design-time showcase data, no read
|
|
49
50
|
const displayData = isPreview ? preview : fetchedData;
|
|
51
|
+
// Breadcrumb shows the record's name instead of its id
|
|
52
|
+
useRecordBreadcrumb(entity, isPreview ? null : displayData);
|
|
50
53
|
const displayError = isPreview ? null : error;
|
|
51
54
|
const isLoading = isPreview ? false : loading || !id;
|
|
52
55
|
// Filter fields: respect visibility AND skip empty values
|
|
@@ -99,7 +102,7 @@ export function EntityDisplayRenderer({ entity, id, t, className = '', loadingMe
|
|
|
99
102
|
gridColumn: '1 / -1',
|
|
100
103
|
display: 'contents',
|
|
101
104
|
}, className: className, children: _jsx(Spinner, { overlay: true, "aria-label": loadingMessage ||
|
|
102
|
-
tCrud('form.loading'
|
|
105
|
+
tCrud('form.loading') }) }));
|
|
103
106
|
}
|
|
104
107
|
// CRUD unavailable (consent declined / feature absent): nothing will load
|
|
105
108
|
if (!displayData && !displayError && !notFound)
|
|
@@ -107,11 +110,11 @@ export function EntityDisplayRenderer({ entity, id, t, className = '', loadingMe
|
|
|
107
110
|
// Error or not found state
|
|
108
111
|
if (displayError || !displayData) {
|
|
109
112
|
return (_jsx(Stack, { align: "center", justify: "center", style: {
|
|
110
|
-
padding: 'var(--gap-
|
|
113
|
+
padding: 'var(--gap-lg)',
|
|
111
114
|
textAlign: 'center',
|
|
112
115
|
}, className: className, children: _jsxs(Stack, { direction: "column", gap: "tight", children: [_jsx("h3", { style: { color: 'var(--muted-foreground)' }, children: notFoundMessage ||
|
|
113
116
|
tCrud('errors.notFound', {
|
|
114
|
-
defaultValue:
|
|
117
|
+
entity: tDual('name', { defaultValue: entity.name }),
|
|
115
118
|
}) }), displayError && (_jsx("p", { style: {
|
|
116
119
|
color: 'var(--destructive)',
|
|
117
120
|
fontSize: 'var(--font-size-sm)',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EntityFormRendererProps,
|
|
1
|
+
import type { AnyEntity, EntityFormRendererProps, FieldOperation } from '@donotdev/core';
|
|
2
2
|
export type { EntityFormRendererProps };
|
|
3
3
|
/**
|
|
4
4
|
* EntityFormRenderer - Dumb component that renders a form from entity definition.
|
|
@@ -8,6 +8,8 @@ export type { EntityFormRendererProps };
|
|
|
8
8
|
* - Generates formId
|
|
9
9
|
* - Renders fields
|
|
10
10
|
* - Renders submit button with status from useEntityForm
|
|
11
|
+
* - Submits through `onSubmit`, or, without it, useEntityForm's default writer
|
|
12
|
+
* (the record plus the child rows joined to the form, one `bulkAcross`)
|
|
11
13
|
*
|
|
12
14
|
* @version 0.1.0
|
|
13
15
|
* @since 0.0.1
|
|
@@ -18,6 +20,6 @@ export type { EntityFormRendererProps };
|
|
|
18
20
|
* Applies instanceKey as React key on the inner component for clean state isolation
|
|
19
21
|
* when navigating between entities on the same route (e.g. /cars/:id).
|
|
20
22
|
*/
|
|
21
|
-
export declare function EntityFormRenderer<
|
|
23
|
+
export declare function EntityFormRenderer<E extends AnyEntity, Op extends FieldOperation = FieldOperation>(props: EntityFormRendererProps<E, Op>): import("react").JSX.Element;
|
|
22
24
|
export default EntityFormRenderer;
|
|
23
25
|
//# sourceMappingURL=EntityFormRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityFormRenderer.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityFormRenderer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EntityFormRenderer.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityFormRenderer.tsx"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EACV,SAAS,EACT,uBAAuB,EACvB,cAAc,EAGf,MAAM,gBAAgB,CAAC;AAmBxB,YAAY,EAAE,uBAAuB,EAAE,CAAC;AA2DxC;;;;;;;;;;;;;;GAcG;AACH;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,SAAS,EACnB,EAAE,SAAS,cAAc,GAAG,cAAc,EAC1C,KAAK,EAAE,uBAAuB,CAAC,CAAC,EAAE,EAAE,CAAC,+BAGtC;AAqnBD,eAAe,kBAAkB,CAAC"}
|
|
@@ -10,15 +10,31 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
10
10
|
* @since 0.0.1
|
|
11
11
|
* @author AMBROISE PARK Consulting
|
|
12
12
|
*/
|
|
13
|
-
import { useEffect,
|
|
13
|
+
import { useEffect, useMemo, useRef, useState, } from 'react';
|
|
14
14
|
import { FormProvider, useWatch } from 'react-hook-form';
|
|
15
|
-
import { Badge, Button, DropdownMenu, Grid, Stack, Spinner, } from '@donotdev/components';
|
|
15
|
+
import { Alert, Badge, Button, DropdownMenu, Grid, Stack, Spinner, } from '@donotdev/components';
|
|
16
16
|
import { hasRoleAccess, useTranslation } from '@donotdev/core';
|
|
17
17
|
import { useNavigate } from '../../routing';
|
|
18
18
|
import { useAuthSafe } from '../../utils/useAuthSafe';
|
|
19
|
-
import { isCrudModuleAvailable, DisplayFieldRenderer, FormFieldRenderer, UploadProvider, useEntityForm, useFormStore, useFieldConditions, } from '../crudImports';
|
|
19
|
+
import { isCrudModuleAvailable, DisplayFieldRenderer, FormFieldRenderer, UploadProvider, useEntityForm, useFormStore, useFormError, useFieldConditions, translateFieldLabel, } from '../crudImports';
|
|
20
|
+
import { referencePrefillFromQuery } from './entityParent';
|
|
21
|
+
import { useRecordBreadcrumb } from './useRecordBreadcrumb';
|
|
22
|
+
const errorSummaryStyle = { gridColumn: '1 / -1', width: '100%' };
|
|
23
|
+
// RHF root errors may be a single message or named server errors.
|
|
24
|
+
function rootErrorMessages(error) {
|
|
25
|
+
if (!error || typeof error !== 'object')
|
|
26
|
+
return [];
|
|
27
|
+
return Object.entries(error).flatMap(([key, value]) => {
|
|
28
|
+
if (key === 'message' && typeof value === 'string')
|
|
29
|
+
return [value];
|
|
30
|
+
if (key === 'ref' || key === 'types')
|
|
31
|
+
return [];
|
|
32
|
+
return rootErrorMessages(value);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
20
35
|
/**
|
|
21
|
-
* Read-only field
|
|
36
|
+
* Read-only field the form writes (`editable: 'computed'`, or an input disabled
|
|
37
|
+
* by a condition).
|
|
22
38
|
*
|
|
23
39
|
* Subscribes to the field's live form value rather than reading the initial
|
|
24
40
|
* `defaultValues`, so fields written during the session — a computed value set
|
|
@@ -28,9 +44,23 @@ import { isCrudModuleAvailable, DisplayFieldRenderer, FormFieldRenderer, UploadP
|
|
|
28
44
|
* Mirrors FormFieldRenderer's contract: takes `control`, subscribes itself.
|
|
29
45
|
*/
|
|
30
46
|
function FormDisplayField({ name, config, control, t, }) {
|
|
31
|
-
|
|
47
|
+
// why: renderable field names are the entity's own field names
|
|
48
|
+
const value = useWatch({ control, name: name });
|
|
32
49
|
return (_jsx(DisplayFieldRenderer, { name: name, config: config, value: value, t: t }));
|
|
33
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Value of a field in the stored row (`form.record`): an extension field
|
|
53
|
+
* (`offer.price`) reads the extension row under its key.
|
|
54
|
+
*/
|
|
55
|
+
function recordValue(record, name) {
|
|
56
|
+
const dot = name.indexOf('.');
|
|
57
|
+
if (dot === -1)
|
|
58
|
+
return record?.[name];
|
|
59
|
+
const nested = record?.[name.slice(0, dot)];
|
|
60
|
+
return typeof nested === 'object' && nested !== null
|
|
61
|
+
? nested[name.slice(dot + 1)]
|
|
62
|
+
: undefined;
|
|
63
|
+
}
|
|
34
64
|
/**
|
|
35
65
|
* EntityFormRenderer - Dumb component that renders a form from entity definition.
|
|
36
66
|
*
|
|
@@ -39,6 +69,8 @@ function FormDisplayField({ name, config, control, t, }) {
|
|
|
39
69
|
* - Generates formId
|
|
40
70
|
* - Renders fields
|
|
41
71
|
* - Renders submit button with status from useEntityForm
|
|
72
|
+
* - Submits through `onSubmit`, or, without it, useEntityForm's default writer
|
|
73
|
+
* (the record plus the child rows joined to the form, one `bulkAcross`)
|
|
42
74
|
*
|
|
43
75
|
* @version 0.1.0
|
|
44
76
|
* @since 0.0.1
|
|
@@ -53,18 +85,21 @@ export function EntityFormRenderer(props) {
|
|
|
53
85
|
const { instanceKey, ...rest } = props;
|
|
54
86
|
return _jsx(EntityFormRendererCore, { ...rest }, instanceKey);
|
|
55
87
|
}
|
|
56
|
-
function EntityFormRendererCore({ entity, onSubmit, t, className = '', submitText, loading = false, defaultValues, submitVariant = 'primary', secondaryButtonText, secondaryButtonVariant = 'outline', onSecondarySubmit, viewerRole: viewerRoleProp, operation
|
|
88
|
+
function EntityFormRendererCore({ entity, onSubmit, t, className = '', submitText, loading = false, defaultValues, submitVariant = 'primary', secondaryButtonText, secondaryButtonVariant = 'outline', onSecondarySubmit, viewerRole: viewerRoleProp, operation: operationProp, formId: externalFormId, cancelText, cancelPath, successPath, onCancel, hideVisibilityInfo = false, }) {
|
|
57
89
|
// Safe guard: isCrudModuleAvailable is a module-level constant (immutable after load).
|
|
58
90
|
// Hooks below are either ALL called or NONE — no Rules-of-Hooks violation at runtime.
|
|
59
91
|
if (!isCrudModuleAvailable)
|
|
60
92
|
return null;
|
|
93
|
+
// why: without the prop, Op is FieldOperation (both operations), so the runtime
|
|
94
|
+
// default ('edit' with defaultValues, else 'create') is an Op
|
|
95
|
+
const operation = (operationProp ?? (defaultValues ? 'edit' : 'create'));
|
|
61
96
|
const navigate = useNavigate();
|
|
62
97
|
// Auto-detect role from auth; prop overrides (e.g. View-As preview)
|
|
63
98
|
const authRole = useAuthSafe('userRole');
|
|
64
99
|
const viewerRole = viewerRoleProp ?? authRole;
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
const formId = externalFormId ?? `entity-form-${entity.name}
|
|
100
|
+
// Deterministic form ID: it also keys the auto-saved draft, so it must survive reloads.
|
|
101
|
+
// Several forms of the same entity on one page pass their own formId.
|
|
102
|
+
const formId = externalFormId ?? `entity-form-${entity.name}`;
|
|
68
103
|
// Entity + crud namespaces so translateLabel can resolve crud:status.* etc.
|
|
69
104
|
const { t: translationFn } = useTranslation([entity.namespace, 'crud']);
|
|
70
105
|
const { t: tCrud } = useTranslation('crud');
|
|
@@ -72,8 +107,9 @@ function EntityFormRendererCore({ entity, onSubmit, t, className = '', submitTex
|
|
|
72
107
|
// Visibility badges (developer-facing) are for admins/super only
|
|
73
108
|
const isAdminOrSuper = viewerRole === 'admin' || viewerRole === 'super';
|
|
74
109
|
const showVisibilityBadges = !hideVisibilityInfo && isAdminOrSuper;
|
|
75
|
-
// Preview dropdown (View As) is available for user/admin/super
|
|
76
|
-
const canPreviewRole =
|
|
110
|
+
// Preview dropdown (View As) is available for user/admin/super, hidden with the badges
|
|
111
|
+
const canPreviewRole = !hideVisibilityInfo &&
|
|
112
|
+
(viewerRole === 'user' || viewerRole === 'admin' || viewerRole === 'super');
|
|
77
113
|
// Preview role state for View As toggle
|
|
78
114
|
const [previewRole, setPreviewRole] = useState(viewerRole === 'admin' || viewerRole === 'super' || viewerRole === 'user'
|
|
79
115
|
? viewerRole
|
|
@@ -105,6 +141,10 @@ function EntityFormRendererCore({ entity, onSubmit, t, className = '', submitTex
|
|
|
105
141
|
checked: previewRole === role,
|
|
106
142
|
onClick: () => setPreviewRole(role),
|
|
107
143
|
})), [previewRole, viewerRole]);
|
|
144
|
+
// Breadcrumb shows the edited record's name instead of its id
|
|
145
|
+
useRecordBreadcrumb(entity, operation === 'edit'
|
|
146
|
+
? defaultValues
|
|
147
|
+
: undefined);
|
|
108
148
|
// useEntityForm handles all orchestration
|
|
109
149
|
const form = useEntityForm(entity, {
|
|
110
150
|
formId,
|
|
@@ -113,9 +153,78 @@ function EntityFormRendererCore({ entity, onSubmit, t, className = '', submitTex
|
|
|
113
153
|
viewerRole,
|
|
114
154
|
t: translate,
|
|
115
155
|
loading,
|
|
156
|
+
successPath,
|
|
116
157
|
});
|
|
117
|
-
const { control, handleSubmit, fields: rawFields, formStatus, uploadProgress, isDirty, hasUserInteracted, resetForm, } = form;
|
|
158
|
+
const { control, setValue, handleSubmit, fields: rawFields, formStatus, uploadProgress, isDirty, hasUserInteracted, resetForm, } = form;
|
|
159
|
+
const submissionError = useFormError(formId);
|
|
160
|
+
const { errors, submitCount } = form.formState;
|
|
161
|
+
const formRef = useRef(null);
|
|
162
|
+
const summaryRef = useRef(null);
|
|
163
|
+
// RHF keeps only the fields that have an error (cleared ones are unset)
|
|
164
|
+
const errorFields = Object.keys(errors).filter((name) => name !== 'root');
|
|
165
|
+
const rootMessages = rootErrorMessages(errors.root);
|
|
166
|
+
const hasErrors = errorFields.length > 0 || rootMessages.length > 0 || !!submissionError;
|
|
167
|
+
const previousFeedback = useRef({ submitCount: 0, rootKey: '', submissionError: null });
|
|
168
|
+
const rootKey = JSON.stringify(rootMessages);
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
const previous = previousFeedback.current;
|
|
171
|
+
previousFeedback.current = { submitCount, rootKey, submissionError };
|
|
172
|
+
// Blur/condition revalidation may update errors while the user is editing.
|
|
173
|
+
// Announce them inline, but move focus only for a submit or a new root failure.
|
|
174
|
+
const submitted = submitCount > previous.submitCount;
|
|
175
|
+
const rootFailure = (rootKey !== previous.rootKey && rootKey !== '[]') ||
|
|
176
|
+
(!!submissionError && submissionError !== previous.submissionError);
|
|
177
|
+
if (!submitted && !rootFailure)
|
|
178
|
+
return;
|
|
179
|
+
const summary = summaryRef.current;
|
|
180
|
+
const formElement = formRef.current;
|
|
181
|
+
if (!summary || !formElement)
|
|
182
|
+
return;
|
|
183
|
+
// The orchestrator owns actionable field focus. Only focus the summary when
|
|
184
|
+
// there is no mounted, focusable invalid control in THIS form (e.g. a hidden
|
|
185
|
+
// field or a server/root error), including inside a Sheet's scroll container.
|
|
186
|
+
const invalidNames = Object.keys(errors).filter((name) => name !== 'root');
|
|
187
|
+
const hasActionableError = Array.from(formElement.querySelectorAll('input, textarea, select, button, [tabindex]')).some((control) => {
|
|
188
|
+
const name = control.getAttribute('name');
|
|
189
|
+
const invalid = control.getAttribute('aria-invalid') === 'true' ||
|
|
190
|
+
(name !== null &&
|
|
191
|
+
invalidNames.some((field) => name === field || name.startsWith(`${field}.`)));
|
|
192
|
+
if (!invalid ||
|
|
193
|
+
control.matches(':disabled, input[type="hidden"]') ||
|
|
194
|
+
control.closest('[hidden], [inert], [aria-hidden="true"]') ||
|
|
195
|
+
control.getClientRects().length === 0) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
for (let element = control; element; element = element.parentElement) {
|
|
199
|
+
const style = getComputedStyle(element);
|
|
200
|
+
if (style.display === 'none' || style.visibility === 'hidden')
|
|
201
|
+
return false;
|
|
202
|
+
if (element === formElement)
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
return true;
|
|
206
|
+
});
|
|
207
|
+
if (hasActionableError)
|
|
208
|
+
return;
|
|
209
|
+
summary.focus({ preventScroll: true });
|
|
210
|
+
summary.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
211
|
+
}, [errors, submitCount, submissionError, rootKey]);
|
|
118
212
|
const isDirtyForBlocking = isDirty && hasUserInteracted;
|
|
213
|
+
// Create: prefill reference fields named in the URL (`?brandId=…`, from a nested
|
|
214
|
+
// EntityList's add button). After mount, client-only (no Suspense / hydration
|
|
215
|
+
// impact on SSR pages); runs after draft restore, so the URL parent wins.
|
|
216
|
+
const prefilled = useRef(false);
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
if (operation !== 'create' || prefilled.current)
|
|
219
|
+
return;
|
|
220
|
+
prefilled.current = true;
|
|
221
|
+
const prefill = referencePrefillFromQuery(entity, new URLSearchParams(window.location.search), viewerRole);
|
|
222
|
+
for (const [field, value] of Object.entries(prefill)) {
|
|
223
|
+
// why: prefill keys are reference fields the form writes on create
|
|
224
|
+
// (referencePrefillFromQuery), values record ids
|
|
225
|
+
setValue(field, value);
|
|
226
|
+
}
|
|
227
|
+
}, [operation, entity, viewerRole, setValue]);
|
|
119
228
|
// Filter fields based on previewRole when visibility info is shown
|
|
120
229
|
const renderableFields = useMemo(() => {
|
|
121
230
|
if (!canPreviewRole)
|
|
@@ -154,25 +263,22 @@ function EntityFormRendererCore({ entity, onSubmit, t, className = '', submitTex
|
|
|
154
263
|
navigate('back');
|
|
155
264
|
}
|
|
156
265
|
};
|
|
157
|
-
//
|
|
158
|
-
// handleSubmit from react-hook-form expects: (data: EntityData) => void | Promise<void>
|
|
159
|
-
// Our onSubmit prop is (data: T) => void | Promise<void>, where T extends EntityRecord
|
|
160
|
-
// EntityData should be compatible with T, so we can safely pass it
|
|
266
|
+
// onSubmit receives the written fields (FormValues), not the whole row
|
|
161
267
|
// No try/catch here — errors MUST propagate to useEntityForm's orchestrator
|
|
162
268
|
// which properly calls setError() and does NOT clearDraft/reset.
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
269
|
+
// Leaving on save (successPath) is useEntityForm's job: it leaves before the
|
|
270
|
+
// write and returns on rejection.
|
|
271
|
+
// Without onSubmit, useEntityForm's default writer saves the record and the
|
|
272
|
+
// child rows joined to this form (nested EntityList on this record).
|
|
273
|
+
const handleFormSubmit = onSubmit
|
|
274
|
+
? async (data) => {
|
|
275
|
+
await onSubmit(data);
|
|
170
276
|
}
|
|
171
|
-
|
|
277
|
+
: undefined;
|
|
172
278
|
// Determine if cancel button should show
|
|
173
279
|
// Show by default, hide only if cancelText is explicitly null
|
|
174
280
|
const showCancelButton = cancelText !== null;
|
|
175
|
-
const cancelButtonText = cancelText ?? tCrud('form.cancel'
|
|
281
|
+
const cancelButtonText = cancelText ?? tCrud('form.cancel');
|
|
176
282
|
// Common button container style (sticky footer)
|
|
177
283
|
const buttonContainerStyle = {
|
|
178
284
|
gridColumn: '1 / -1',
|
|
@@ -195,38 +301,33 @@ function EntityFormRendererCore({ entity, onSubmit, t, className = '', submitTex
|
|
|
195
301
|
loadingText: uploadProgress < 100
|
|
196
302
|
? tCrud('form.uploading', {
|
|
197
303
|
progress: Math.round(uploadProgress),
|
|
198
|
-
defaultValue: `Uploading ${Math.round(uploadProgress)}%...`,
|
|
199
304
|
})
|
|
200
|
-
: tCrud('form.processing'
|
|
305
|
+
: tCrud('form.processing'),
|
|
201
306
|
progress: uploadProgress,
|
|
202
307
|
};
|
|
203
308
|
}
|
|
204
309
|
if (formStatus === 'validating') {
|
|
205
310
|
return {
|
|
206
311
|
loading: true,
|
|
207
|
-
loadingText: tCrud('form.validating',
|
|
208
|
-
defaultValue: 'Validating...',
|
|
209
|
-
}),
|
|
312
|
+
loadingText: tCrud('form.validating'),
|
|
210
313
|
};
|
|
211
314
|
}
|
|
212
315
|
if (formStatus === 'submitting') {
|
|
213
316
|
return {
|
|
214
317
|
loading: true,
|
|
215
|
-
loadingText: tCrud('form.saving'
|
|
318
|
+
loadingText: tCrud('form.saving'),
|
|
216
319
|
};
|
|
217
320
|
}
|
|
218
321
|
if (formStatus === 'success') {
|
|
219
322
|
return {
|
|
220
323
|
loading: false,
|
|
221
|
-
successText: tCrud('form.saved'
|
|
324
|
+
successText: tCrud('form.saved'),
|
|
222
325
|
};
|
|
223
326
|
}
|
|
224
327
|
if (formStatus === 'error') {
|
|
225
328
|
return {
|
|
226
329
|
loading: false,
|
|
227
|
-
errorText: tCrud('form.error',
|
|
228
|
-
defaultValue: 'Error — try again',
|
|
229
|
-
}),
|
|
330
|
+
errorText: tCrud('form.error'),
|
|
230
331
|
};
|
|
231
332
|
}
|
|
232
333
|
return { loading: false };
|
|
@@ -236,26 +337,26 @@ function EntityFormRendererCore({ entity, onSubmit, t, className = '', submitTex
|
|
|
236
337
|
width: '100%',
|
|
237
338
|
gridColumn: '1 / -1',
|
|
238
339
|
display: 'contents',
|
|
239
|
-
}, children: [isLoading && _jsx(Spinner, { overlay: true }), _jsxs("form", { onSubmit: (e) => {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}, noValidate: true, className: className, style: { width: '100%', gridColumn: '1 / -1', display: 'contents' }, children: [
|
|
340
|
+
}, children: [isLoading && _jsx(Spinner, { overlay: true }), _jsxs("form", { ref: formRef, id: formId, onSubmit: (e) => {
|
|
341
|
+
// The orchestrator records failure and preserves the draft before
|
|
342
|
+
// rethrowing. Consume only the final DOM event promise, never the
|
|
343
|
+
// consumer callback's rejection (which must remain a failure).
|
|
344
|
+
void handleSubmit(handleFormSubmit)(e).catch(() => { });
|
|
345
|
+
}, noValidate: true, className: className, style: { width: '100%', gridColumn: '1 / -1', display: 'contents' }, children: [hasErrors && (_jsx("div", { ref: summaryRef, tabIndex: -1, "aria-label": tCrud('form.error'), style: errorSummaryStyle, children: _jsxs(Alert, { variant: "error", title: tCrud(errorFields.length > 0 ? 'form.validationFailed' : 'form.error'), children: [errorFields.length > 0 && (_jsx("p", { children: tCrud('form.fixFields', {
|
|
346
|
+
fields: errorFields
|
|
347
|
+
.map((name) => translateFieldLabel(name, entity.fields[name], translate))
|
|
348
|
+
.join(', '),
|
|
349
|
+
}) })), rootMessages.map((message, index) => (_jsx("p", { children: translate(message) }, index))), submissionError && _jsx("p", { children: translate(submissionError) })] }) })), renderableFields.map(({ name, config, editable, written }) => {
|
|
245
350
|
// Evaluate dynamic conditions for this field
|
|
246
351
|
const cond = fieldConditions[name];
|
|
247
352
|
if (cond && !cond.visible)
|
|
248
353
|
return null;
|
|
249
354
|
// Apply condition overrides to field config
|
|
250
|
-
const effectiveConfig = cond
|
|
355
|
+
const effectiveConfig = cond && config.conditions?.required !== undefined
|
|
251
356
|
? {
|
|
252
357
|
...config,
|
|
253
|
-
//
|
|
254
|
-
...
|
|
255
|
-
? { validation: { ...config.validation, required: true } }
|
|
256
|
-
: cond.required
|
|
257
|
-
? { validation: { required: true } }
|
|
258
|
-
: {}),
|
|
358
|
+
// An explicit condition overrides static required in BOTH directions.
|
|
359
|
+
validation: { ...config.validation, required: cond.required },
|
|
259
360
|
}
|
|
260
361
|
: config;
|
|
261
362
|
// Condition-based disabled/readonly override editability
|
|
@@ -267,8 +368,10 @@ function EntityFormRendererCore({ entity, onSubmit, t, className = '', submitTex
|
|
|
267
368
|
: undefined;
|
|
268
369
|
const badgeLabel = roleLabels[config.visibility] ??
|
|
269
370
|
config.visibility;
|
|
270
|
-
//
|
|
271
|
-
|
|
371
|
+
// Read-only: a field the form writes from form state (computed, or an
|
|
372
|
+
// input disabled by a condition), any other from the stored row
|
|
373
|
+
// (technical, editable: false, role-denied: never in form state).
|
|
374
|
+
const fieldElement = !effectiveEditable ? (written ? (_jsx(FormDisplayField, { name: name, config: effectiveConfig, control: control, t: translate }, name)) : (_jsx(DisplayFieldRenderer, { name: name, config: effectiveConfig, value: recordValue(form.record, name), t: translate }, name))) : (_jsx(FormFieldRenderer, { name: name, config: effectiveConfig, control: control, t: translate }, name));
|
|
272
375
|
// If no badge needed, return field directly
|
|
273
376
|
if (!showBadge)
|
|
274
377
|
return fieldElement;
|
|
@@ -285,33 +388,34 @@ function EntityFormRendererCore({ entity, onSubmit, t, className = '', submitTex
|
|
|
285
388
|
const buttons = [];
|
|
286
389
|
// Cancel button
|
|
287
390
|
if (showCancelButton && cancelButtonText) {
|
|
288
|
-
buttons.push(_jsx(Button, { type: "button", onClick: handleCancel, disabled: buttonState.loading, variant: "outline", className: "dndev-w-full", children: cancelButtonText }, "cancel"));
|
|
391
|
+
buttons.push(_jsx(Button, { type: "button", intent: "cancel", onClick: handleCancel, disabled: buttonState.loading, variant: "outline", className: "dndev-w-full", children: cancelButtonText }, "cancel"));
|
|
289
392
|
}
|
|
290
393
|
// Preview dropdown (user/admin/super only)
|
|
291
394
|
if (canPreviewRole) {
|
|
292
395
|
const previewVariant = visibilityBadgeVariant[previewRole] || 'muted';
|
|
293
|
-
buttons.push(_jsx(DropdownMenu, { trigger: _jsxs(Button, { type: "button", variant: previewVariant, disabled: buttonState.loading, className: "dndev-w-full", children: [tCrud('visibility.preview',
|
|
294
|
-
defaultValue: 'Preview',
|
|
295
|
-
}), ": ", roleLabels[previewRole]] }), items: previewMenuItems }, "preview"));
|
|
396
|
+
buttons.push(_jsx(DropdownMenu, { trigger: _jsxs(Button, { type: "button", intent: "preview", variant: previewVariant, disabled: buttonState.loading, className: "dndev-w-full", children: [tCrud('visibility.preview'), ": ", roleLabels[previewRole]] }), items: previewMenuItems }, "preview"));
|
|
296
397
|
}
|
|
297
398
|
// Secondary submit button
|
|
298
399
|
if (secondaryButtonText) {
|
|
299
400
|
buttons.push(_jsx(Button, { type: "button", onClick: () => {
|
|
300
401
|
if (onSecondarySubmit) {
|
|
402
|
+
// why: form state is typed for both operations (EntityFormState); at
|
|
403
|
+
// runtime it is the projection for this form's Op (the fields it
|
|
404
|
+
// writes), the shape onSubmit receives, not validated.
|
|
301
405
|
const currentValues = form.getValues();
|
|
302
406
|
onSecondarySubmit(currentValues);
|
|
303
407
|
}
|
|
304
408
|
}, loading: buttonState.loading, loadingText: buttonState.loadingText, progress: buttonState.progress, variant: secondaryButtonVariant, className: "dndev-w-full", children: secondaryButtonText }, "secondary"));
|
|
305
409
|
}
|
|
306
410
|
// Primary submit button (always shown)
|
|
307
|
-
buttons.push(_jsx(Button, { type: "submit", loading: buttonState.loading, loadingText: buttonState.loadingText, progress: buttonState.progress, variant: buttonState.successText
|
|
411
|
+
buttons.push(_jsx(Button, { type: "submit", intent: "save", loading: buttonState.loading, loadingText: buttonState.loadingText, progress: buttonState.progress, variant: buttonState.successText
|
|
308
412
|
? 'success'
|
|
309
413
|
: buttonState.errorText
|
|
310
414
|
? 'destructive'
|
|
311
415
|
: submitVariant, disabled: !!buttonState.successText, className: "dndev-w-full", children: buttonState.successText ||
|
|
312
416
|
buttonState.errorText ||
|
|
313
417
|
submitText ||
|
|
314
|
-
tCrud('form.submit'
|
|
418
|
+
tCrud('form.submit') }, "submit"));
|
|
315
419
|
const buttonCount = buttons.length;
|
|
316
420
|
// Single button: use Stack
|
|
317
421
|
if (buttonCount === 1) {
|
|
@@ -4,11 +4,13 @@ export type { EntityListProps };
|
|
|
4
4
|
* Entity List Component - Table view for admin/internal operations
|
|
5
5
|
*
|
|
6
6
|
* Features:
|
|
7
|
-
* - Filters section (collapsible)
|
|
8
|
-
* - Results section
|
|
7
|
+
* - Filters section (collapsible): closed unless filters are active (e.g. from the URL)
|
|
8
|
+
* - Results section with the search / refresh / add toolbar and the DataTable
|
|
9
9
|
* - Excel-like table display with formatted values
|
|
10
|
-
* -
|
|
10
|
+
* - Open-link icon per row, bulk select, bulk delete of the checked rows
|
|
11
11
|
* - Auto-routing when handlers not provided
|
|
12
|
+
* - With `parent`, `editable` (default) and an edit form open on that record:
|
|
13
|
+
* joined to the form (`useChildRows`), saved by its Save
|
|
12
14
|
*/
|
|
13
|
-
export declare function EntityList(
|
|
15
|
+
export declare function EntityList(props: EntityListProps): import("react").JSX.Element | null;
|
|
14
16
|
//# sourceMappingURL=EntityList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityList.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityList.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EntityList.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityList.tsx"],"names":[],"mappings":"AA6DA,OAAO,KAAK,EAGV,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAwBxB,YAAY,EAAE,eAAe,EAAE,CAAC;AAsFhC;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,sCAwBhD"}
|