@donotdev/ui 0.2.2 → 0.2.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.
Files changed (160) hide show
  1. package/dist/{GoToDialog-CICRYHHG.js → GoToDialog-KSBGOIWO.js} +1 -1
  2. package/dist/chunk-MS7ZIW5Z.js +1 -0
  3. package/dist/components/auth/AuthHeader.d.ts.map +1 -1
  4. package/dist/components/auth/AuthHeader.js +0 -2
  5. package/dist/components/auth/AuthMenu.d.ts.map +1 -1
  6. package/dist/components/auth/AuthMenu.js +6 -40
  7. package/dist/components/common/icon.d.ts.map +1 -1
  8. package/dist/components/common/icon.js +2 -1
  9. package/dist/components/common/lucideIconByName.d.ts +9 -0
  10. package/dist/components/common/lucideIconByName.d.ts.map +1 -0
  11. package/dist/components/common/lucideIconByName.js +32 -0
  12. package/dist/components/layout/GameFlow.d.ts.map +1 -1
  13. package/dist/components/layout/components/Breadcrumbs.d.ts.map +1 -1
  14. package/dist/components/layout/components/Breadcrumbs.js +14 -9
  15. package/dist/components/layout/components/header/CacheSettings.d.ts.map +1 -1
  16. package/dist/components/layout/components/header/CacheSettings.js +6 -4
  17. package/dist/components/layout/components/header/SettingsMenu.d.ts.map +1 -1
  18. package/dist/components/layout/components/header/SettingsMenu.js +2 -1
  19. package/dist/components/layout/components/header/ThemeToggle.d.ts.map +1 -1
  20. package/dist/components/layout/components/header/ThemeToggle.js +2 -1
  21. package/dist/crud/components/CrudCardLink.d.ts +6 -6
  22. package/dist/crud/components/CrudCardLink.d.ts.map +1 -1
  23. package/dist/crud/components/CrudCardLink.js +3 -9
  24. package/dist/crud/components/EntityCardList.d.ts.map +1 -1
  25. package/dist/crud/components/EntityCardList.js +3 -11
  26. package/dist/crud/components/EntityDisplayRenderer.d.ts.map +1 -1
  27. package/dist/crud/components/EntityDisplayRenderer.js +4 -1
  28. package/dist/crud/components/EntityFormRenderer.d.ts.map +1 -1
  29. package/dist/crud/components/EntityFormRenderer.js +27 -5
  30. package/dist/crud/components/EntityList.d.ts +4 -4
  31. package/dist/crud/components/EntityList.d.ts.map +1 -1
  32. package/dist/crud/components/EntityList.js +136 -59
  33. package/dist/crud/components/Form.d.ts +1 -1
  34. package/dist/crud/components/Form.d.ts.map +1 -1
  35. package/dist/crud/components/Form.js +2 -2
  36. package/dist/crud/components/cellEditFor.d.ts +28 -0
  37. package/dist/crud/components/cellEditFor.d.ts.map +1 -0
  38. package/dist/crud/components/cellEditFor.js +54 -0
  39. package/dist/crud/components/entityParent.d.ts +40 -0
  40. package/dist/crud/components/entityParent.d.ts.map +1 -0
  41. package/dist/crud/components/entityParent.js +54 -0
  42. package/dist/crud/components/useRecordBreadcrumb.d.ts +11 -0
  43. package/dist/crud/components/useRecordBreadcrumb.d.ts.map +1 -0
  44. package/dist/crud/components/useRecordBreadcrumb.js +34 -0
  45. package/dist/crud/crudImports.d.ts +2 -0
  46. package/dist/crud/crudImports.d.ts.map +1 -1
  47. package/dist/crud/crudImports.js +2 -0
  48. package/dist/dndev-next.css +483 -145
  49. package/dist/dndev.css +483 -145
  50. package/dist/index.js +4 -4
  51. package/dist/internal/common/RouteErrorFallback.d.ts.map +1 -1
  52. package/dist/internal/common/RouteErrorFallback.js +2 -4
  53. package/dist/internal/devtools/components/ConfigTab.d.ts.map +1 -1
  54. package/dist/internal/devtools/components/ConfigTab.js +1 -1
  55. package/dist/internal/devtools/components/CookieTab.d.ts.map +1 -1
  56. package/dist/internal/devtools/components/CookieTab.js +1 -5
  57. package/dist/internal/devtools/components/DesignTab.d.ts.map +1 -1
  58. package/dist/internal/devtools/components/DesignTab.js +18 -7
  59. package/dist/internal/devtools/components/StoresTab.d.ts.map +1 -1
  60. package/dist/internal/devtools/components/StoresTab.js +17 -3
  61. package/dist/internal/devtools/types.d.ts +3 -3
  62. package/dist/internal/devtools/types.d.ts.map +1 -1
  63. package/dist/internal/devtools/utils/maskSensitive.d.ts +1 -1
  64. package/dist/internal/devtools/utils/maskSensitive.d.ts.map +1 -1
  65. package/dist/internal/layout/DnDevLayout.d.ts.map +1 -1
  66. package/dist/internal/layout/DnDevLayout.js +21 -21
  67. package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
  68. package/dist/internal/layout/components/AutoMetaTags.js +39 -36
  69. package/dist/internal/layout/components/i18nSeoMeta.d.ts.map +1 -1
  70. package/dist/internal/layout/components/i18nSeoMeta.js +1 -0
  71. package/dist/internal/layout/zones/DnDevMergedBar.js +3 -3
  72. package/dist/internal/providers/UIProviders.d.ts.map +1 -1
  73. package/dist/internal/providers/UIProviders.js +7 -2
  74. package/dist/providers/NextJsAppProviders.d.ts +5 -1
  75. package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
  76. package/dist/providers/NextJsAppProviders.js +36 -5
  77. package/dist/providers/ViteAppProviders.d.ts.map +1 -1
  78. package/dist/providers/ViteAppProviders.js +42 -4
  79. package/dist/routing/404.js +4 -4
  80. package/dist/routing/AuthGuardFallback.d.ts.map +1 -1
  81. package/dist/routing/AuthGuardFallback.js +1 -2
  82. package/dist/routing/AuthReturnTo.d.ts.map +1 -1
  83. package/dist/routing/AuthReturnTo.js +9 -2
  84. package/dist/routing/GoTo.d.ts +0 -6
  85. package/dist/routing/GoTo.d.ts.map +1 -1
  86. package/dist/routing/GoTo.js +5 -8
  87. package/dist/routing/Link.d.ts +4 -2
  88. package/dist/routing/Link.d.ts.map +1 -1
  89. package/dist/routing/Link.js +8 -5
  90. package/dist/routing/SignedInRedirect.d.ts +27 -0
  91. package/dist/routing/SignedInRedirect.d.ts.map +1 -0
  92. package/dist/routing/SignedInRedirect.js +47 -0
  93. package/dist/routing/hooks/hooks.next.d.ts +2 -0
  94. package/dist/routing/hooks/hooks.next.d.ts.map +1 -1
  95. package/dist/routing/hooks/hooks.next.js +1 -1
  96. package/dist/routing/hooks/hooks.vite.d.ts +2 -0
  97. package/dist/routing/hooks/hooks.vite.d.ts.map +1 -1
  98. package/dist/routing/hooks/hooks.vite.js +1 -1
  99. package/dist/routing/hooks/useLocation.next.d.ts +12 -0
  100. package/dist/routing/hooks/useLocation.next.d.ts.map +1 -1
  101. package/dist/routing/hooks/useLocation.next.js +17 -4
  102. package/dist/routing/hooks/useMatch.next.d.ts +6 -0
  103. package/dist/routing/hooks/useMatch.next.d.ts.map +1 -1
  104. package/dist/routing/hooks/useMatch.next.js +8 -2
  105. package/dist/routing/hooks/useNavigate.next.d.ts +6 -1
  106. package/dist/routing/hooks/useNavigate.next.d.ts.map +1 -1
  107. package/dist/routing/hooks/useNavigate.next.js +13 -4
  108. package/dist/routing/hooks/useNavigate.vite.d.ts +7 -1
  109. package/dist/routing/hooks/useNavigate.vite.d.ts.map +1 -1
  110. package/dist/routing/hooks/useNavigate.vite.js +20 -4
  111. package/dist/routing/hooks/useRedirectGuard.next.d.ts.map +1 -1
  112. package/dist/routing/hooks/useRedirectGuard.next.js +7 -1
  113. package/dist/routing/hooks/useRedirectGuard.vite.d.ts.map +1 -1
  114. package/dist/routing/hooks/useRedirectGuard.vite.js +7 -1
  115. package/dist/routing/hooks/useRoutePath.next.d.ts +23 -0
  116. package/dist/routing/hooks/useRoutePath.next.d.ts.map +1 -0
  117. package/dist/routing/hooks/useRoutePath.next.js +36 -0
  118. package/dist/routing/hooks/useRoutePath.vite.d.ts +13 -0
  119. package/dist/routing/hooks/useRoutePath.vite.d.ts.map +1 -0
  120. package/dist/routing/hooks/useRoutePath.vite.js +25 -0
  121. package/dist/routing/hooks/useUrlLanguage.next.d.ts +28 -0
  122. package/dist/routing/hooks/useUrlLanguage.next.d.ts.map +1 -0
  123. package/dist/routing/hooks/useUrlLanguage.next.js +50 -0
  124. package/dist/routing/hooks/useUrlLanguage.vite.d.ts +22 -0
  125. package/dist/routing/hooks/useUrlLanguage.vite.d.ts.map +1 -0
  126. package/dist/routing/hooks/useUrlLanguage.vite.js +41 -0
  127. package/dist/routing/index.d.ts +3 -1
  128. package/dist/routing/index.d.ts.map +1 -1
  129. package/dist/routing/index.js +2 -1
  130. package/dist/routing/useNavigation.js +4 -4
  131. package/dist/styles/index.css +483 -145
  132. package/dist/symbol-index.json +1 -1
  133. package/dist/utils/assetResolver.d.ts.map +1 -1
  134. package/dist/utils/assetResolver.js +1 -0
  135. package/dist/utils/index.d.ts +2 -0
  136. package/dist/utils/index.d.ts.map +1 -1
  137. package/dist/utils/index.js +3 -0
  138. package/dist/utils/useDeleteAccountSafe.d.ts +17 -0
  139. package/dist/utils/useDeleteAccountSafe.d.ts.map +1 -0
  140. package/dist/utils/useDeleteAccountSafe.js +52 -0
  141. package/dist/utils/useFormStoreSafe.d.ts.map +1 -1
  142. package/dist/utils/useFormStoreSafe.js +1 -0
  143. package/dist/utils/useSeo.d.ts +10 -2
  144. package/dist/utils/useSeo.d.ts.map +1 -1
  145. package/dist/utils/useSeo.js +44 -9
  146. package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
  147. package/dist/vite-routing/AppRoutes.js +37 -4
  148. package/guidelines/COMPONENTS.md +2 -1
  149. package/guidelines/PAGES.md +7 -0
  150. package/guidelines/ROUTING.md +4 -0
  151. package/guidelines/SEO.md +52 -0
  152. package/package.json +9 -9
  153. package/dist/CookieConsent-5NH5DNTP.js +0 -1
  154. package/dist/CookieConsent-W7UE647Y.js +0 -1
  155. package/dist/GoToDialog-YGBON6FR.js +0 -1
  156. package/dist/chunk-DRFM6WXH.js +0 -1
  157. package/dist/chunk-MIPTBUWY.js +0 -1
  158. package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts +0 -57
  159. package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts.map +0 -1
  160. package/dist/internal/layout/components/NextJsAutoMetaTags.js +0 -182
@@ -9,31 +9,48 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
9
9
  * **Routing:** Convention basePath = `/${collection}`. View/Edit = basePath/:id, Create = basePath/new.
10
10
  * Override basePath for nested routes; use onClick(id) to open sheet instead of navigating.
11
11
  *
12
+ * **Rows:** open-link icon (opens the record) | checkbox (bulk select, select-all
13
+ * in the header) | fields. Checked rows can be deleted together (one `bulk({ deletes })`;
14
+ * rows not deleted stay checked).
15
+ *
16
+ * **Editing (default):** list fields are edited in their cells (DataTable `editable`),
17
+ * checked rows take one value at once; Save writes every change in one `bulk({ updates })`.
18
+ * Partial success: rows that fail stay pending (still marked) with an error count.
19
+ * `editable={false}`: read-only cells, a row click opens the record.
20
+ *
21
+ * **Nested list:** `parent={{ field, value }}` lists one parent's children; the add
22
+ * button opens the create form with the parent prefilled.
23
+ *
12
24
  * @version 0.1.0
13
25
  * @since 0.0.1
14
26
  * @author AMBROISE PARK Consulting
15
27
  */
16
- import { RefreshCw, Plus, Trash2, Edit, Search } from 'lucide-react';
28
+ import { RefreshCw, Plus, Trash2, Search, Save, Undo2 } from 'lucide-react';
17
29
  import { useCallback, useState } from 'react';
18
- import { DataTable, Button, Stack, ActionButton, Section, Input, } from '@donotdev/components';
30
+ import { DataTable, Button, Stack, ActionButton, Section, Input, Alert, Text, } from '@donotdev/components';
19
31
  import { useTranslation } from '@donotdev/core';
20
32
  import { Link, useNavigate } from '../../routing';
21
- import { isCrudModuleAvailable, translateFieldLabel, useCrud, useCrudList, useCrudPageSize, EntityFilters, formatValue, useReferenceResolver, } from '../crudImports';
33
+ import { useAuthSafe } from '../../utils/useAuthSafe';
34
+ import { cellEditFor } from './cellEditFor';
35
+ import { assertEntityParent, childCreatePath } from './entityParent';
36
+ import { isCrudModuleAvailable, translateFieldLabel, useCrud, useCrudFilters, useCrudList, useCrudPageSize, EntityFilters, formatValue, useReferenceResolver, } from '../crudImports';
22
37
  /**
23
38
  * Entity List Component - Table view for admin/internal operations
24
39
  *
25
40
  * Features:
26
- * - Filters section (collapsible) with actions and filter inputs
27
- * - Results section (collapsible) with DataTable
41
+ * - Filters section (collapsible): closed unless filters are active (e.g. from the URL)
42
+ * - Results section with the search / refresh / add toolbar and the DataTable
28
43
  * - Excel-like table display with formatted values
29
- * - Edit and Delete actions (admin only)
44
+ * - Open-link icon per row, bulk select, bulk delete of the checked rows
30
45
  * - Auto-routing when handlers not provided
31
46
  */
32
- export function EntityList({ entity, basePath, onClick, hideFilters = false, pagination = 'auto', pageSize: pageSizeProp, queryOptions, exportable = true, preview, tone, }) {
47
+ export function EntityList({ entity, basePath, onClick, hideFilters = false, pagination = 'auto', pageSize: pageSizeProp, queryOptions, exportable = true, editable = true, parent, preview, tone, }) {
33
48
  // Safe guard: isCrudModuleAvailable is a module-level constant (immutable after load).
34
49
  if (!isCrudModuleAvailable)
35
50
  return null;
36
51
  const isPreview = !!preview;
52
+ if (parent)
53
+ assertEntityParent(entity, parent);
37
54
  const navigate = useNavigate();
38
55
  const base = basePath ?? `/${entity.collection}`;
39
56
  // Pre-fetch referenced collections for display resolution
@@ -46,13 +63,27 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
46
63
  ...(pageSizeProp != null && { defaultPageSize: pageSizeProp }),
47
64
  });
48
65
  const [searchQuery, setSearchQuery] = useState('');
66
+ // Filters panel starts closed so the table is above the fold; open when filters
67
+ // are already applied (URL or store), so they are never hidden.
68
+ const { filters } = useCrudFilters({ collection: entity.collection });
69
+ const hasActiveFilters = Object.keys(filters).length > 0;
49
70
  // useCrudList now handles client-side filter + search + sort via `processed`
50
71
  // effectiveMode tells us if auto-mode switched to server (for DataTable props)
51
72
  const { data: listData, items: rawData, processed: fetchedData, loading: fetchLoading, mutate: refreshList, effectiveMode, } = useCrudList(entity, {
52
73
  enabled: !isPreview,
53
74
  pagination,
54
75
  searchQuery,
55
- ...(queryOptions && { queryOptions }),
76
+ ...((queryOptions || parent) && {
77
+ queryOptions: parent
78
+ ? {
79
+ ...queryOptions,
80
+ where: [
81
+ ...(queryOptions?.where ?? []),
82
+ { field: parent.field, operator: '==', value: parent.value },
83
+ ],
84
+ }
85
+ : queryOptions,
86
+ }),
56
87
  ...((pagination === 'server' || pagination === 'auto') && {
57
88
  page: currentPage,
58
89
  pageSize: storedPageSize,
@@ -60,11 +91,48 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
60
91
  });
61
92
  // In preview mode: use preview data, skip loading state
62
93
  const filteredData = isPreview
63
- ? preview
94
+ ? // why: public `preview` prop is untyped records (Record<string, unknown>); rows are trusted to match the entity
95
+ preview
64
96
  : fetchedData;
65
97
  const loading = isPreview ? false : fetchLoading;
66
- // useCrud -> handles actions (delete)
67
- const { delete: deleteItem } = useCrud(entity);
98
+ // useCrud -> bulk save of in-place edits, bulk delete of checked rows
99
+ const { bulk } = useCrud(entity);
100
+ // In-place editing: unsaved cell values, keyed by record id
101
+ const isEditing = editable && !isPreview;
102
+ const viewerRole = useAuthSafe('userRole');
103
+ const [pendingChanges, setPendingChanges] = useState({});
104
+ // Checked rows (bulk delete); DataTable drops rows that leave the data
105
+ const [selectedIds, setSelectedIds] = useState([]);
106
+ const presentIds = new Set(filteredData.map((row) => row.id));
107
+ const checkedIds = selectedIds.filter((id) => presentIds.has(id));
108
+ const [saving, setSaving] = useState(false);
109
+ // Rows the last bulk save / delete did not write (they stay pending / checked)
110
+ const [failedCount, setFailedCount] = useState(0);
111
+ const pendingCount = Object.values(pendingChanges).reduce((sum, row) => sum + Object.keys(row).length, 0);
112
+ // Partial success: saved rows leave the pending set, failed rows stay pending
113
+ // (still marked) so nothing typed is lost; the alert gives the count to retry.
114
+ const handleSave = async () => {
115
+ setSaving(true);
116
+ setFailedCount(0);
117
+ try {
118
+ const { failed } = await bulk({
119
+ updates: Object.entries(pendingChanges).map(([id, patch]) => ({
120
+ id,
121
+ patch: patch,
122
+ })),
123
+ });
124
+ const failedIds = new Set(failed.map((f) => f.id));
125
+ setPendingChanges(Object.fromEntries(Object.entries(pendingChanges).filter(([id]) => failedIds.has(id))));
126
+ setFailedCount(failedIds.size);
127
+ }
128
+ catch {
129
+ // Batch not attempted: every edit stays pending
130
+ setFailedCount(Object.keys(pendingChanges).length);
131
+ }
132
+ finally {
133
+ setSaving(false);
134
+ }
135
+ };
68
136
  const { t: tCrud } = useTranslation('crud');
69
137
  // Entity + crud namespaces so formatValue can resolve crud:price.* etc.
70
138
  const { t } = useTranslation([entity.namespace, 'crud']);
@@ -83,14 +151,20 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
83
151
  navigate(`${base}/${id}`);
84
152
  }
85
153
  }, [base, navigate, onClick, isPreview]);
86
- // Delete handler - store handles optimistic removal automatically
87
- const handleDelete = async (itemId) => {
154
+ // Delete the checked rows in one bulk call (partial success): deleted rows leave
155
+ // the list, rows not deleted stay listed and checked; the alert gives the count.
156
+ const handleDeleteSelected = async () => {
88
157
  if (isPreview)
89
158
  return;
90
- await deleteItem(itemId);
159
+ setFailedCount(0);
160
+ const { failed } = await bulk({ deletes: checkedIds });
161
+ const failedIds = new Set(failed.map((f) => f.id));
162
+ setSelectedIds(checkedIds.filter((id) => failedIds.has(id)));
163
+ setFailedCount(failedIds.size);
91
164
  };
92
- // Generate columns from entity.listFields or entity.fields
93
- const fieldsToShow = entity.listFields || Object.keys(entity.fields);
165
+ // Generate columns from entity.listFields or entity.fields.
166
+ // A nested list hides its parent column: every row has the same parent.
167
+ const fieldsToShow = (entity.listFields || Object.keys(entity.fields)).filter((fieldName) => fieldName !== parent?.field);
94
168
  const dataColumns = fieldsToShow
95
169
  .map((fieldName) => {
96
170
  const fieldConfig = entity.fields[fieldName];
@@ -107,6 +181,9 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
107
181
  sortable: !isPreview,
108
182
  filterable: !isPreview,
109
183
  align,
184
+ ...(isEditing && {
185
+ edit: cellEditFor(fieldConfig, viewerRole, referenceData, t),
186
+ }),
110
187
  render: (value, record) => formatValue(value, fieldConfig, t, {
111
188
  compact: true,
112
189
  referenceData,
@@ -115,36 +192,16 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
115
192
  };
116
193
  })
117
194
  .filter(Boolean);
118
- // Actions column at the front (for mobile accessibility)
119
- const actionsColumn = {
120
- key: '_actions',
121
- title: tCrud('actions.label', { defaultValue: 'Actions' }),
122
- dataIndex: undefined,
123
- sortable: false,
124
- width: 120,
125
- align: 'center',
126
- render: (_, record) => (_jsxs(Stack, { direction: "row", gap: "tight", align: "center", justify: "center", children: [isPreview ? (_jsx(Button, { variant: "outline", icon: Edit, disabled: true, "aria-label": tCrud('edit', { defaultValue: 'Edit' }) })) : (_jsx(Button, { variant: "outline", icon: Edit, render: ({ children, ...renderProps }) => (_jsx(Link, { path: `${base}/${record.id}`, onClick: (e) => e.stopPropagation(), ...renderProps, children: children })), "aria-label": tCrud('edit', { defaultValue: 'Edit' }) })), _jsx(ActionButton, { action: async () => {
127
- await handleDelete(record.id);
128
- }, confirmText: tCrud('delete.confirm', {
129
- defaultValue: 'Are you sure you want to delete this item?',
130
- }), confirmTitle: tCrud('delete.title', {
131
- defaultValue: 'Delete Item',
132
- }), loadingText: tCrud('delete.loading', {
133
- defaultValue: 'Deleting...',
134
- }), variant: "destructive", icon: Trash2, disabled: isPreview, "aria-label": tCrud('delete', { defaultValue: 'Delete' }), children: tCrud('delete', { defaultValue: 'Delete' }) })] })),
135
- };
136
- const columns = [actionsColumn, ...dataColumns];
195
+ const columns = dataColumns;
137
196
  // Entity name for section title
138
197
  const entityName = t('name', { defaultValue: entity.name });
139
198
  // Result count
140
199
  const resultCount = filteredData.length;
141
200
  // Always show table structure - DataTable will show skeleton rows when loading
142
- return (_jsxs(_Fragment, { children: [_jsx(Section, { title: tCrud('filters.title', {
201
+ return (_jsxs(_Fragment, { children: [!hideFilters && (_jsx(Section, { title: tCrud('filters.title', {
143
202
  entity: entityName,
144
203
  defaultValue: `Browse ${entityName} - Filters`,
145
- }), collapsible: true, defaultOpen: true, tone: tone, children: _jsxs(Stack, { children: [_jsxs(Stack, { direction: "row", gap: "tight", align: "center", className: "dndev-w-full", style: { display: 'grid', gridTemplateColumns: '1fr auto auto' }, children: [_jsx(Input, { placeholder: tCrud('search.placeholder', {
146
- defaultValue: 'Search...',
147
- }), value: searchQuery, onChange: (e) => setSearchQuery(e.target.value), icon: Search, className: "dndev-w-full", disabled: isPreview }), _jsx(Button, { icon: RefreshCw, variant: "outline", onClick: handleRefresh, disabled: isPreview || loading, display: "compact", "aria-label": tCrud('refresh', { defaultValue: 'Refresh' }) }), isPreview ? (_jsx(Button, { icon: Plus, display: "compact", disabled: true, children: tCrud('addNew', { defaultValue: 'Add New' }) })) : (_jsx(Button, { icon: Plus, display: "compact", render: ({ children, ...renderProps }) => (_jsx(Link, { path: `${base}/new`, ...renderProps, children: children })), children: tCrud('addNew', { defaultValue: 'Add New' }) }))] }), !hideFilters && (_jsx(EntityFilters, { entity: entity, data: rawData, fieldsToFilter: entity.listFields }))] }) }), _jsx(Section, { title: loading
204
+ }), collapsible: true, defaultOpen: hasActiveFilters, tone: tone, children: _jsx(EntityFilters, { entity: entity, data: rawData, fieldsToFilter: fieldsToShow }) })), _jsx(Section, { title: loading
148
205
  ? tCrud('results.title.fetching', {
149
206
  defaultValue: 'Fetching...',
150
207
  })
@@ -153,24 +210,44 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
153
210
  defaultValue: resultCount === 1
154
211
  ? 'Found 1 occurrence'
155
212
  : `Found ${resultCount} occurrences`,
156
- }), collapsible: true, defaultOpen: true, tone: tone, children: _jsx(DataTable, { data: filteredData, columns: columns, sortable: !isPreview, searchable: false, pagination: true, loading: loading, onRowClick: isPreview ? undefined : (item) => handleView(item.id),
157
- // Pagination labels (translated)
158
- showingLabel: tCrud('pagination.showing', {
159
- defaultValue: 'Showing {{from}} to {{to}} of {{total}} entries',
160
- }), paginationPreviousLabel: tCrud('pagination.previous', {
161
- defaultValue: 'Previous',
162
- }), paginationNextLabel: tCrud('pagination.next', {
163
- defaultValue: 'Next',
164
- }), paginationItemsPerPagePlaceholder: tCrud('pagination.itemsPerPagePlaceholder', {
165
- defaultValue: 'Items per page',
166
- }),
167
- // Persisted page size — always controlled via CrudStore
168
- pageSize: storedPageSize, onPageSizeChange: setStoredPageSize, ...(!isPreview &&
169
- effectiveMode === 'server' && {
170
- currentPage,
171
- total: listData?.total,
172
- onPageChange: setCurrentPage,
173
- }),
174
- // Export functionality
175
- exportable: isPreview ? false : exportable, exportFilename: `${entity.collection}-export`, exportLabel: tCrud('export', { defaultValue: 'Export' }) }) })] }));
213
+ }), tone: tone, children: _jsxs(Stack, { children: [_jsxs(Stack, { direction: "row", gap: "tight", align: "center", className: "dndev-w-full", style: { display: 'grid', gridTemplateColumns: '1fr auto auto' }, children: [_jsx(Input, { placeholder: tCrud('actions.searchPlaceholder'), value: searchQuery, onChange: (e) => setSearchQuery(e.target.value), icon: Search, className: "dndev-w-full", disabled: isPreview }), _jsx(Button, { icon: RefreshCw, variant: "outline", onClick: handleRefresh, disabled: isPreview || loading, display: "compact", "aria-label": tCrud('actions.refresh') }), isPreview ? (_jsx(Button, { icon: Plus, display: "compact", disabled: true, children: tCrud('addNew', { defaultValue: 'Add New' }) })) : (_jsx(Button, { icon: Plus, display: "compact", render: ({ children, ...renderProps }) => (_jsx(Link, { path: parent ? childCreatePath(base, parent) : `${base}/new`, ...renderProps, children: children })), children: tCrud('addNew', { defaultValue: 'Add New' }) }))] }), isEditing && pendingCount > 0 && (_jsxs(Stack, { direction: "row", gap: "tight", align: "center", wrap: "wrap", children: [_jsx(Text, { level: "body", children: tCrud('bulkEdit.pending', { count: pendingCount }) }), _jsx(Button, { icon: Save, display: "compact", onClick: handleSave, disabled: saving, children: saving ? tCrud('form.saving') : tCrud('actions.save') }), _jsx(Button, { icon: Undo2, variant: "outline", display: "compact", onClick: () => {
214
+ setPendingChanges({});
215
+ setFailedCount(0);
216
+ }, disabled: saving, children: tCrud('bulkEdit.discard') })] })), failedCount > 0 && (_jsx(Alert, { variant: "error", title: tCrud('bulkEdit.failed', { count: failedCount }) })), !isPreview && checkedIds.length > 0 && (_jsx(Stack, { direction: "row", gap: "tight", align: "center", wrap: "wrap", children: _jsx(ActionButton, { action: handleDeleteSelected, confirmTitle: tCrud('delete.titleSelected', {
217
+ count: checkedIds.length,
218
+ }), confirmText: tCrud('delete.confirmSelected', {
219
+ count: checkedIds.length,
220
+ }), confirmLabel: tCrud('actions.delete'), cancelLabel: tCrud('actions.cancel'), variant: "outline", icon: Trash2, display: "compact", children: tCrud('bulkEdit.deleteSelected', { count: checkedIds.length }) }) })), _jsx(DataTable, { data: filteredData, columns: columns, sortable: !isPreview, searchable: false, pagination: true, loading: loading, onRowClick: isPreview ? undefined : (item) => handleView(item.id), selectable: !isPreview, getRowId: (row) => row.id, onSelect: (rows) => setSelectedIds(rows.map((row) => row.id)), openLabel: tCrud('actions.open'), ...(!isPreview &&
221
+ (onClick
222
+ ? { onRowOpen: (row) => onClick(row.id) }
223
+ : { getRowHref: (row) => `${base}/${row.id}` })), ...(isEditing && {
224
+ editable: true,
225
+ pendingChanges,
226
+ onPendingChange: setPendingChanges,
227
+ editLabels: {
228
+ selected: tCrud('bulkEdit.selected'),
229
+ field: tCrud('bulkEdit.field'),
230
+ value: tCrud('bulkEdit.value'),
231
+ apply: tCrud('bulkEdit.apply'),
232
+ },
233
+ }),
234
+ // Pagination labels (translated)
235
+ showingLabel: tCrud('pagination.showing', {
236
+ defaultValue: 'Showing {{from}} to {{to}} of {{total}} entries',
237
+ }), paginationPreviousLabel: tCrud('pagination.previous', {
238
+ defaultValue: 'Previous',
239
+ }), paginationNextLabel: tCrud('pagination.next', {
240
+ defaultValue: 'Next',
241
+ }), paginationItemsPerPagePlaceholder: tCrud('pagination.itemsPerPagePlaceholder', {
242
+ defaultValue: 'Items per page',
243
+ }),
244
+ // Persisted page size — always controlled via CrudStore
245
+ pageSize: storedPageSize, onPageSizeChange: setStoredPageSize, ...(!isPreview &&
246
+ effectiveMode === 'server' && {
247
+ currentPage,
248
+ total: listData?.total,
249
+ onPageChange: setCurrentPage,
250
+ }),
251
+ // Export functionality
252
+ exportable: isPreview ? false : exportable, exportFilename: `${entity.collection}-export`, exportLabel: tCrud('export', { defaultValue: 'Export' }) })] }) })] }));
176
253
  }
@@ -40,7 +40,7 @@ declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName
40
40
  * @since 0.0.1
41
41
  * @author AMBROISE PARK Consulting
42
42
  */
43
- declare const FormItem: ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => import("react").JSX.Element;
43
+ declare const FormItem: ({ className, children, ...props }: HTMLAttributes<HTMLDivElement>) => import("react").JSX.Element;
44
44
  /**
45
45
  * Hook for accessing form field context
46
46
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/crud/components/Form.tsx"],"names":[],"mappings":"AAEA;;;;;;;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,yBAAyB,cAAc,CAAC,cAAc,CAAC,gCAOxE,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
+ {"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/crud/components/Form.tsx"],"names":[],"mappings":"AAEA;;;;;;;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"}
@@ -62,9 +62,9 @@ const FormItemContext = createContext({});
62
62
  * @since 0.0.1
63
63
  * @author AMBROISE PARK Consulting
64
64
  */
65
- const FormItem = ({ className, ...props }) => {
65
+ const FormItem = ({ className, children, ...props }) => {
66
66
  const id = useId();
67
- return (_jsx(FormItemContext.Provider, { value: { id }, children: _jsx(Stack, { className: className, ...props }) }));
67
+ return (_jsx(FormItemContext.Provider, { value: { id }, children: _jsx(Stack, { className: className, ...props, children: children }) }));
68
68
  };
69
69
  /**
70
70
  * Hook for accessing form field context
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @fileoverview Cell editor of an entity field
3
+ * @description Maps an entity field to the DataTable cell editor used by an
4
+ * `editable` EntityList.
5
+ *
6
+ * @version 0.1.0
7
+ * @since 0.2.3
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ import type { TableCellEdit } from '@donotdev/components';
11
+ import type { EntityField } from '@donotdev/core';
12
+ type Translate = (key: string, options?: Record<string, unknown>) => string;
13
+ /**
14
+ * Cell editor of a list field, or `undefined` when the field is not edited in
15
+ * the table (type without a cell editor, or not editable by the viewer).
16
+ * References list the referenced records by their resolved label
17
+ * (`useReferenceResolver`); a reference whose collection is not resolved yet
18
+ * stays read-only.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * cellEditFor({ name: 'price', type: 'number', visibility: 'user' }, 'admin', {}, t);
23
+ * // { type: 'number' }
24
+ * ```
25
+ */
26
+ export declare function cellEditFor(field: EntityField, viewerRole: string, referenceData: Record<string, Record<string, string>>, t: Translate): TableCellEdit | undefined;
27
+ export {};
28
+ //# sourceMappingURL=cellEditFor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cellEditFor.d.ts","sourceRoot":"","sources":["../../../src/crud/components/cellEditFor.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AASlD,KAAK,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;AAE5E;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACrD,CAAC,EAAE,SAAS,GACX,aAAa,GAAG,SAAS,CA8B3B"}
@@ -0,0 +1,54 @@
1
+ // packages/ui/src/crud/components/cellEditFor.ts
2
+ import { isFieldEditable, translateLabel } from '../crudImports';
3
+ /** Field types edited as free text in an editable list. */
4
+ const TEXT_TYPES = new Set(['text', 'email', 'url', 'tel', 'textarea']);
5
+ /** Field types edited as a dropdown of their `validation.options`. */
6
+ const OPTION_TYPES = new Set(['select', 'radio']);
7
+ /**
8
+ * Cell editor of a list field, or `undefined` when the field is not edited in
9
+ * the table (type without a cell editor, or not editable by the viewer).
10
+ * References list the referenced records by their resolved label
11
+ * (`useReferenceResolver`); a reference whose collection is not resolved yet
12
+ * stays read-only.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * cellEditFor({ name: 'price', type: 'number', visibility: 'user' }, 'admin', {}, t);
17
+ * // { type: 'number' }
18
+ * ```
19
+ */
20
+ export function cellEditFor(field, viewerRole, referenceData, t) {
21
+ if (!isFieldEditable(field.editable, viewerRole, 'edit'))
22
+ return undefined;
23
+ const type = field.type || 'text';
24
+ if (TEXT_TYPES.has(type))
25
+ return { type: 'text' };
26
+ if (type === 'number')
27
+ return { type: 'number' };
28
+ if (OPTION_TYPES.has(type)) {
29
+ const raw = field.validation?.options;
30
+ const options = typeof raw === 'function' ? raw() : raw;
31
+ if (!Array.isArray(options))
32
+ return undefined;
33
+ return {
34
+ type: 'select',
35
+ options: options.map((o) => ({
36
+ value: String(o.value),
37
+ label: translateLabel(o.label, t),
38
+ })),
39
+ };
40
+ }
41
+ if (type === 'reference') {
42
+ const collection = field.validation?.reference;
43
+ const labels = typeof collection === 'string' ? referenceData[collection] : undefined;
44
+ if (!labels)
45
+ return undefined;
46
+ return {
47
+ type: 'select',
48
+ options: Object.entries(labels)
49
+ .map(([value, label]) => ({ value, label }))
50
+ .sort((a, b) => a.label.localeCompare(b.label)),
51
+ };
52
+ }
53
+ return undefined;
54
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @fileoverview Parent / child records (nested lists)
3
+ * @description An `EntityList` with `parent` lists one parent's children and its
4
+ * add button opens `basePath/new?<field>=<id>`. `EntityFormRenderer` (create)
5
+ * prefills that reference field from the URL. URL input is untrusted: only
6
+ * reference fields of the entity the viewer may set on create, with an id-shaped
7
+ * value, are taken.
8
+ *
9
+ * @version 0.1.0
10
+ * @since 0.2.3
11
+ * @author AMBROISE PARK Consulting
12
+ */
13
+ import type { AnyEntity, EntityListParent } from '@donotdev/core';
14
+ /**
15
+ * Throws when `parent.field` is not a reference field of the listed entity.
16
+ * A wrong parent would silently list nothing.
17
+ *
18
+ * @param entity - The listed (child) entity
19
+ * @param parent - The nested list's parent
20
+ */
21
+ export declare function assertEntityParent(entity: AnyEntity, parent: EntityListParent): void;
22
+ /**
23
+ * Create path of a child record with its parent prefilled.
24
+ *
25
+ * @param basePath - The list's base path
26
+ * @param parent - The nested list's parent
27
+ * @returns `${basePath}/new?<field>=<id>`
28
+ */
29
+ export declare function childCreatePath(basePath: string, parent: EntityListParent): string;
30
+ /**
31
+ * Create-form values taken from the URL: reference fields of the entity the
32
+ * viewer may set on create, whose value is a record id. Anything else is ignored.
33
+ *
34
+ * @param entity - The entity being created
35
+ * @param params - The current URL's search params
36
+ * @param viewerRole - The viewer's role
37
+ * @returns The prefilled reference values (empty when none)
38
+ */
39
+ export declare function referencePrefillFromQuery(entity: AnyEntity, params: URLSearchParams, viewerRole: string): Record<string, string>;
40
+ //# sourceMappingURL=entityParent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entityParent.d.ts","sourceRoot":"","sources":["../../../src/crud/components/entityParent.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAYlE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,gBAAgB,GACvB,IAAI,CAWN;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,gBAAgB,GACvB,MAAM,CAGR;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAaxB"}
@@ -0,0 +1,54 @@
1
+ // packages/ui/src/crud/components/entityParent.ts
2
+ import { isFieldEditable } from '../crudImports';
3
+ /** Record id shape accepted from a URL (Firestore ids, UUIDs, slugs). */
4
+ const RECORD_ID = /^[A-Za-z0-9_-]{1,128}$/;
5
+ /** True when `field` is a reference field of `entity`. */
6
+ const isReferenceField = (entity, field) => entity.fields[field]?.type === 'reference' &&
7
+ typeof entity.fields[field]?.validation?.reference === 'string';
8
+ /**
9
+ * Throws when `parent.field` is not a reference field of the listed entity.
10
+ * A wrong parent would silently list nothing.
11
+ *
12
+ * @param entity - The listed (child) entity
13
+ * @param parent - The nested list's parent
14
+ */
15
+ export function assertEntityParent(entity, parent) {
16
+ if (!isReferenceField(entity, parent.field)) {
17
+ throw new Error(`EntityList: parent.field "${parent.field}" is not a reference field of entity "${entity.name}".`);
18
+ }
19
+ if (!RECORD_ID.test(parent.value)) {
20
+ throw new Error(`EntityList: parent.value "${parent.value}" is not a record id.`);
21
+ }
22
+ }
23
+ /**
24
+ * Create path of a child record with its parent prefilled.
25
+ *
26
+ * @param basePath - The list's base path
27
+ * @param parent - The nested list's parent
28
+ * @returns `${basePath}/new?<field>=<id>`
29
+ */
30
+ export function childCreatePath(basePath, parent) {
31
+ const query = new URLSearchParams({ [parent.field]: parent.value });
32
+ return `${basePath}/new?${query.toString()}`;
33
+ }
34
+ /**
35
+ * Create-form values taken from the URL: reference fields of the entity the
36
+ * viewer may set on create, whose value is a record id. Anything else is ignored.
37
+ *
38
+ * @param entity - The entity being created
39
+ * @param params - The current URL's search params
40
+ * @param viewerRole - The viewer's role
41
+ * @returns The prefilled reference values (empty when none)
42
+ */
43
+ export function referencePrefillFromQuery(entity, params, viewerRole) {
44
+ const prefill = {};
45
+ for (const [key, value] of params.entries()) {
46
+ if (Object.hasOwn(entity.fields, key) &&
47
+ isReferenceField(entity, key) &&
48
+ RECORD_ID.test(value) &&
49
+ isFieldEditable(entity.fields[key].editable, viewerRole, 'create')) {
50
+ prefill[key] = value;
51
+ }
52
+ }
53
+ return prefill;
54
+ }
@@ -0,0 +1,11 @@
1
+ import type { AnyEntity } from '@donotdev/core';
2
+ /**
3
+ * Names the shown record in the breadcrumbs: the entity's card title, formatted like
4
+ * the card (the same title `<Seo entity>` uses). Cleared when the page unmounts or the record
5
+ * has no title. Client effect: the server render keeps the URL segment.
6
+ *
7
+ * @param entity - Entity of the record
8
+ * @param record - Loaded record (`undefined` / `null` while loading)
9
+ */
10
+ export declare function useRecordBreadcrumb(entity: AnyEntity, record: Record<string, unknown> | null | undefined): void;
11
+ //# sourceMappingURL=useRecordBreadcrumb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRecordBreadcrumb.d.ts","sourceRoot":"","sources":["../../../src/crud/components/useRecordBreadcrumb.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GACjD,IAAI,CAaN"}
@@ -0,0 +1,34 @@
1
+ // packages/ui/src/crud/components/useRecordBreadcrumb.ts
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 } 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. 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
+ const id = typeof record?.id === 'string' ? record.id : undefined;
24
+ const { t, language } = useTranslation([entity.namespace, 'crud']);
25
+ const label = record
26
+ ? deriveEntitySeo(entity, record, { t, locale: language }).title
27
+ : undefined;
28
+ useEffect(() => {
29
+ if (!id || !label)
30
+ return;
31
+ setRecordLabel({ id, label });
32
+ return () => setRecordLabel(null);
33
+ }, [id, label, setRecordLabel]);
34
+ }
@@ -34,4 +34,6 @@ export declare const EntityFilters: typeof crudModule.EntityFilters;
34
34
  export declare const CrudCard: typeof crudModule.CrudCard;
35
35
  export declare const translateFieldLabel: typeof crudModule.translateFieldLabel;
36
36
  export declare const formatValue: typeof crudModule.formatValue;
37
+ export declare const translateLabel: typeof crudModule.translateLabel;
38
+ export declare const isFieldEditable: typeof crudModule.isFieldEditable;
37
39
  //# sourceMappingURL=crudImports.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"crudImports.d.ts","sourceRoot":"","sources":["../../src/crud/crudImports.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,UAAU,MAAM,gBAAgB,CAAC;AAE7C,0DAA0D;AAC1D,eAAO,MAAM,qBAAqB,SAA4C,CAAC;AAG/E,eAAO,MAAM,aAAa,iCAA4B,CAAC;AACvD,eAAO,MAAM,YAAY,iKAA2B,CAAC;AACrD,eAAO,MAAM,kBAAkB,sCAAiC,CAAC;AACjE,eAAO,MAAM,OAAO,2BAAsB,CAAC;AAC3C,eAAO,MAAM,WAAW,+BAA0B,CAAC;AACnD,eAAO,MAAM,UAAU,8BAAyB,CAAC;AACjD,eAAO,MAAM,eAAe,mCAA8B,CAAC;AAC3D,eAAO,MAAM,kBAAkB,sCAAiC,CAAC;AACjE,eAAO,MAAM,cAAc,kCAA6B,CAAC;AACzD,eAAO,MAAM,eAAe,mCAA8B,CAAC;AAC3D,eAAO,MAAM,iBAAiB,qCAAgC,CAAC;AAC/D,eAAO,MAAM,oBAAoB,wCAAmC,CAAC;AAGrE,eAAO,MAAM,oBAAoB,wCAAmC,CAAC;AACrE,eAAO,MAAM,iBAAiB,qCAAgC,CAAC;AAC/D,eAAO,MAAM,cAAc,kCAA6B,CAAC;AACzD,eAAO,MAAM,aAAa,iCAA4B,CAAC;AACvD,eAAO,MAAM,QAAQ,4BAAuB,CAAC;AAG7C,eAAO,MAAM,mBAAmB,uCAAkC,CAAC;AACnE,eAAO,MAAM,WAAW,+BAA0B,CAAC"}
1
+ {"version":3,"file":"crudImports.d.ts","sourceRoot":"","sources":["../../src/crud/crudImports.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,UAAU,MAAM,gBAAgB,CAAC;AAE7C,0DAA0D;AAC1D,eAAO,MAAM,qBAAqB,SAA4C,CAAC;AAG/E,eAAO,MAAM,aAAa,iCAA4B,CAAC;AACvD,eAAO,MAAM,YAAY,iKAA2B,CAAC;AACrD,eAAO,MAAM,kBAAkB,sCAAiC,CAAC;AACjE,eAAO,MAAM,OAAO,2BAAsB,CAAC;AAC3C,eAAO,MAAM,WAAW,+BAA0B,CAAC;AACnD,eAAO,MAAM,UAAU,8BAAyB,CAAC;AACjD,eAAO,MAAM,eAAe,mCAA8B,CAAC;AAC3D,eAAO,MAAM,kBAAkB,sCAAiC,CAAC;AACjE,eAAO,MAAM,cAAc,kCAA6B,CAAC;AACzD,eAAO,MAAM,eAAe,mCAA8B,CAAC;AAC3D,eAAO,MAAM,iBAAiB,qCAAgC,CAAC;AAC/D,eAAO,MAAM,oBAAoB,wCAAmC,CAAC;AAGrE,eAAO,MAAM,oBAAoB,wCAAmC,CAAC;AACrE,eAAO,MAAM,iBAAiB,qCAAgC,CAAC;AAC/D,eAAO,MAAM,cAAc,kCAA6B,CAAC;AACzD,eAAO,MAAM,aAAa,iCAA4B,CAAC;AACvD,eAAO,MAAM,QAAQ,4BAAuB,CAAC;AAG7C,eAAO,MAAM,mBAAmB,uCAAkC,CAAC;AACnE,eAAO,MAAM,WAAW,+BAA0B,CAAC;AACnD,eAAO,MAAM,cAAc,kCAA6B,CAAC;AACzD,eAAO,MAAM,eAAe,mCAA8B,CAAC"}
@@ -38,3 +38,5 @@ export const CrudCard = crudModule?.CrudCard;
38
38
  // --- Utils ---
39
39
  export const translateFieldLabel = crudModule?.translateFieldLabel;
40
40
  export const formatValue = crudModule?.formatValue;
41
+ export const translateLabel = crudModule?.translateLabel;
42
+ export const isFieldEditable = crudModule?.isFieldEditable;