@donotdev/ui 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/{GoToDialog-CR4VOVXT.js → GoToDialog-RU5RP7S2.js} +1 -1
  2. package/dist/chunk-ETE4RC7M.js +1 -0
  3. package/dist/components/auth/AuthHeader.d.ts +6 -1
  4. package/dist/components/auth/AuthHeader.d.ts.map +1 -1
  5. package/dist/components/auth/AuthHeader.js +4 -4
  6. package/dist/components/common/FeatureCard.d.ts +2 -0
  7. package/dist/components/common/FeatureCard.d.ts.map +1 -1
  8. package/dist/components/common/FeatureDisabled.d.ts +1 -0
  9. package/dist/components/common/FeatureDisabled.d.ts.map +1 -1
  10. package/dist/components/common/TechBento.d.ts +1 -0
  11. package/dist/components/common/TechBento.d.ts.map +1 -1
  12. package/dist/components/common/icon.d.ts +1 -0
  13. package/dist/components/common/icon.d.ts.map +1 -1
  14. package/dist/components/cookie-consent/CookieConsent.d.ts +1 -0
  15. package/dist/components/cookie-consent/CookieConsent.d.ts.map +1 -1
  16. package/dist/components/layout/PageConfig.d.ts +25 -0
  17. package/dist/components/layout/PageConfig.d.ts.map +1 -0
  18. package/dist/components/layout/PageConfig.js +47 -0
  19. package/dist/components/layout/components/Breadcrumbs.d.ts +2 -0
  20. package/dist/components/layout/components/Breadcrumbs.d.ts.map +1 -1
  21. package/dist/components/layout/components/FloatingLanguageSwitcher.d.ts +1 -0
  22. package/dist/components/layout/components/FloatingLanguageSwitcher.d.ts.map +1 -1
  23. package/dist/components/layout/components/header/AppBranding.d.ts +1 -0
  24. package/dist/components/layout/components/header/AppBranding.d.ts.map +1 -1
  25. package/dist/components/layout/components/header/AppIcon.d.ts +1 -0
  26. package/dist/components/layout/components/header/AppIcon.d.ts.map +1 -1
  27. package/dist/components/layout/components/header/AppTitle.d.ts +1 -0
  28. package/dist/components/layout/components/header/AppTitle.d.ts.map +1 -1
  29. package/dist/components/layout/components/header/CacheSettings.js +2 -2
  30. package/dist/components/layout/components/header/GameTitle.d.ts +1 -0
  31. package/dist/components/layout/components/header/GameTitle.d.ts.map +1 -1
  32. package/dist/components/layout/components/header/HeaderMenu.d.ts +1 -0
  33. package/dist/components/layout/components/header/HeaderMenu.d.ts.map +1 -1
  34. package/dist/components/layout/components/header/HeaderNavigation.d.ts +1 -0
  35. package/dist/components/layout/components/header/HeaderNavigation.d.ts.map +1 -1
  36. package/dist/components/layout/components/header/SettingsMenu.d.ts +1 -0
  37. package/dist/components/layout/components/header/SettingsMenu.d.ts.map +1 -1
  38. package/dist/components/layout/index.d.ts +1 -0
  39. package/dist/components/layout/index.d.ts.map +1 -1
  40. package/dist/components/layout/index.js +1 -0
  41. package/dist/crud/components/EntityCardList.d.ts +1 -1
  42. package/dist/crud/components/EntityCardList.d.ts.map +1 -1
  43. package/dist/crud/components/EntityCardList.js +32 -21
  44. package/dist/crud/components/EntityDisplayRenderer.d.ts +1 -1
  45. package/dist/crud/components/EntityDisplayRenderer.d.ts.map +1 -1
  46. package/dist/crud/components/EntityDisplayRenderer.js +13 -12
  47. package/dist/crud/components/EntityFormRenderer.d.ts.map +1 -1
  48. package/dist/crud/components/EntityFormRenderer.js +16 -18
  49. package/dist/crud/components/EntityList.d.ts +1 -1
  50. package/dist/crud/components/EntityList.d.ts.map +1 -1
  51. package/dist/crud/components/EntityList.js +40 -24
  52. package/dist/crud/components/EntityRecommendations.d.ts +1 -1
  53. package/dist/crud/components/EntityRecommendations.d.ts.map +1 -1
  54. package/dist/crud/components/EntityRecommendations.js +4 -4
  55. package/dist/crud/crudImports.d.ts +1 -0
  56. package/dist/crud/crudImports.d.ts.map +1 -1
  57. package/dist/crud/crudImports.js +1 -0
  58. package/dist/dndev-next.css +198 -75
  59. package/dist/dndev.css +228 -74
  60. package/dist/index.js +4 -4
  61. package/dist/internal/common/ErrorFallback.js +1 -1
  62. package/dist/internal/devtools/DebugTools.js +1 -1
  63. package/dist/internal/devtools/components/DesignTab.d.ts.map +1 -1
  64. package/dist/internal/devtools/components/DesignTab.js +6 -2
  65. package/dist/internal/devtools/utils/envVarDiscovery.d.ts.map +1 -1
  66. package/dist/internal/devtools/utils/envVarDiscovery.js +4 -5
  67. package/dist/internal/devtools/utils/virtualModuleInspector.d.ts.map +1 -1
  68. package/dist/internal/devtools/utils/virtualModuleInspector.js +2 -0
  69. package/dist/internal/initializers/BaseStoresInitializer.d.ts.map +1 -1
  70. package/dist/internal/initializers/BaseStoresInitializer.js +11 -2
  71. package/dist/internal/layout/DnDevLayout.d.ts.map +1 -1
  72. package/dist/internal/layout/DnDevLayout.js +39 -16
  73. package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
  74. package/dist/internal/layout/components/AutoMetaTags.js +55 -23
  75. package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts +2 -0
  76. package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts.map +1 -1
  77. package/dist/internal/layout/components/NextJsAutoMetaTags.js +45 -15
  78. package/dist/internal/layout/components/PWAUpdateNotification.d.ts.map +1 -1
  79. package/dist/internal/layout/components/PWAUpdateNotification.js +15 -2
  80. package/dist/internal/layout/zones/DnDevFooter.d.ts +3 -1
  81. package/dist/internal/layout/zones/DnDevFooter.d.ts.map +1 -1
  82. package/dist/internal/layout/zones/DnDevFooter.js +5 -1
  83. package/dist/internal/layout/zones/DnDevHeader.d.ts +3 -1
  84. package/dist/internal/layout/zones/DnDevHeader.d.ts.map +1 -1
  85. package/dist/internal/layout/zones/DnDevHeader.js +7 -2
  86. package/dist/internal/layout/zones/DnDevSidebar.d.ts +3 -1
  87. package/dist/internal/layout/zones/DnDevSidebar.d.ts.map +1 -1
  88. package/dist/internal/layout/zones/DnDevSidebar.js +9 -3
  89. package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
  90. package/dist/providers/NextJsAppProviders.js +3 -1
  91. package/dist/routing/AuthGuard.d.ts +7 -22
  92. package/dist/routing/AuthGuard.d.ts.map +1 -1
  93. package/dist/routing/AuthGuard.js +19 -64
  94. package/dist/routing/AuthReturnTo.d.ts +13 -0
  95. package/dist/routing/AuthReturnTo.d.ts.map +1 -0
  96. package/dist/routing/AuthReturnTo.js +61 -0
  97. package/dist/routing/DnDevNavigationMenu.d.ts +1 -0
  98. package/dist/routing/DnDevNavigationMenu.d.ts.map +1 -1
  99. package/dist/routing/GoTo.d.ts +1 -0
  100. package/dist/routing/GoTo.d.ts.map +1 -1
  101. package/dist/routing/hooks/hooks.next.js +1 -1
  102. package/dist/routing/hooks/hooks.vite.js +1 -1
  103. package/dist/routing/hooks/useNavigate.next.d.ts +8 -0
  104. package/dist/routing/hooks/useNavigate.next.d.ts.map +1 -1
  105. package/dist/routing/hooks/useNavigate.next.js +58 -8
  106. package/dist/routing/hooks/useNavigate.vite.d.ts +8 -0
  107. package/dist/routing/hooks/useNavigate.vite.d.ts.map +1 -1
  108. package/dist/routing/hooks/useNavigate.vite.js +64 -14
  109. package/dist/routing/hooks/useRedirectGuard.next.d.ts +2 -0
  110. package/dist/routing/hooks/useRedirectGuard.next.d.ts.map +1 -1
  111. package/dist/routing/hooks/useRedirectGuard.next.js +11 -27
  112. package/dist/routing/hooks/useRedirectGuard.vite.d.ts +2 -0
  113. package/dist/routing/hooks/useRedirectGuard.vite.d.ts.map +1 -1
  114. package/dist/routing/hooks/useRedirectGuard.vite.js +11 -27
  115. package/dist/routing/index.d.ts +1 -0
  116. package/dist/routing/index.d.ts.map +1 -1
  117. package/dist/routing/index.js +1 -0
  118. package/dist/styles/index.css +228 -74
  119. package/dist/symbol-index.json +1 -0
  120. package/dist/utils/index.d.ts +1 -0
  121. package/dist/utils/index.d.ts.map +1 -1
  122. package/dist/utils/index.js +1 -0
  123. package/dist/utils/sanitizeSvg.d.ts +4 -0
  124. package/dist/utils/sanitizeSvg.d.ts.map +1 -1
  125. package/dist/utils/sanitizeSvg.js +4 -0
  126. package/dist/utils/useAISafe.d.ts +28 -0
  127. package/dist/utils/useAISafe.d.ts.map +1 -0
  128. package/dist/utils/useAISafe.js +53 -0
  129. package/dist/utils/useAuthSafe.d.ts +39 -0
  130. package/dist/utils/useAuthSafe.d.ts.map +1 -1
  131. package/dist/utils/useAuthSafe.js +5 -0
  132. package/dist/utils/useAuthVisibility.d.ts +1 -0
  133. package/dist/utils/useAuthVisibility.d.ts.map +1 -1
  134. package/dist/utils/useBillingVisibility.d.ts +1 -0
  135. package/dist/utils/useBillingVisibility.d.ts.map +1 -1
  136. package/dist/utils/useSeo.d.ts +121 -0
  137. package/dist/utils/useSeo.d.ts.map +1 -0
  138. package/dist/utils/useSeo.js +114 -0
  139. package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
  140. package/dist/vite-routing/AppRoutes.js +14 -4
  141. package/dist/vite-routing/RootLayout.d.ts.map +1 -1
  142. package/dist/vite-routing/RootLayout.js +6 -4
  143. package/guidelines/COMPONENTS.md +136 -0
  144. package/guidelines/GOTCHAS.md +66 -0
  145. package/guidelines/LAYOUTS.md +310 -0
  146. package/guidelines/PAGES.md +205 -0
  147. package/guidelines/ROUTING.md +499 -0
  148. package/guidelines/SEO.md +275 -0
  149. package/package.json +12 -7
  150. package/dist/chunk-XHGRMKOY.js +0 -1
@@ -31,14 +31,15 @@ import { useAuthSafe } from '../../utils/useAuthSafe';
31
31
  * <EntityDisplayRenderer entity={carEntity} id={carId} />
32
32
  * ```
33
33
  */
34
- export function EntityDisplayRenderer({ entity, id, t, className = '', loadingMessage, notFoundMessage, viewerRole: viewerRoleProp, excludeFields, }) {
34
+ export function EntityDisplayRenderer({ entity, id, t, className = '', loadingMessage, notFoundMessage, viewerRole: viewerRoleProp, excludeFields, preview, }) {
35
35
  // Safe guard: isCrudModuleAvailable is a module-level constant (immutable after load).
36
36
  // eslint-disable-next-line react-hooks/rules-of-hooks
37
37
  if (!isCrudModuleAvailable)
38
38
  return null;
39
- // Auto-detect role from auth; prop overrides
39
+ const isPreview = !!preview;
40
+ // Auto-detect role from auth; prop overrides. Preview = design-time showcase, show all fields.
40
41
  const authRole = useAuthSafe('userRole');
41
- const viewerRole = viewerRoleProp ?? authRole;
42
+ const viewerRole = viewerRoleProp ?? (isPreview ? 'super' : authRole);
42
43
  const { get, loading, data: storeData, error: storeError, isAvailable, } = useCrud(entity);
43
44
  const [isFetching, setIsFetching] = useState(false);
44
45
  const [fetchError, setFetchError] = useState(null);
@@ -47,8 +48,10 @@ export function EntityDisplayRenderer({ entity, id, t, className = '', loadingMe
47
48
  const { t: tDual } = useTranslation([entity.namespace, 'crud']);
48
49
  const { t: tCrud } = useTranslation('crud');
49
50
  const translate = t || tDual;
50
- // Fetch data when id is available and service is ready
51
+ // Fetch data when id is available and service is ready (skip in preview mode)
51
52
  useEffect(() => {
53
+ if (isPreview)
54
+ return;
52
55
  // Early return if no ID
53
56
  if (!id) {
54
57
  setData(null);
@@ -88,14 +91,12 @@ export function EntityDisplayRenderer({ entity, id, t, className = '', loadingMe
88
91
  return () => {
89
92
  cancelled = true;
90
93
  };
91
- }, [id, get, isAvailable]);
92
- // Priority: store data (reactive, updated by other components) > local fetch data.
93
- // Store may already have the entity from a list view or prior navigation,
94
- // so we prefer it to avoid a redundant fetch. Local fetch is the fallback
95
- // when the entity isn't in the store yet (e.g., direct URL access).
96
- const displayData = storeData || data;
97
- const displayError = storeError || fetchError;
98
- const isLoading = loading || isFetching || !id;
94
+ }, [id, get, isAvailable, isPreview]);
95
+ // In preview mode: use preview data directly
96
+ // Priority: preview > store data (reactive) > local fetch data
97
+ const displayData = isPreview ? preview : (storeData || data);
98
+ const displayError = isPreview ? null : (storeError || fetchError);
99
+ const isLoading = isPreview ? false : (loading || isFetching || !id);
99
100
  // Filter fields: respect visibility AND skip empty values
100
101
  // MUST be called before any early returns (Rules of Hooks)
101
102
  const visibleFields = useMemo(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"EntityFormRenderer.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityFormRenderer.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EACV,uBAAuB,EACvB,YAAY,EAEb,MAAM,gBAAgB,CAAC;AAgBxB,YAAY,EAAE,uBAAuB,EAAE,CAAC;AAExC;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,EACxE,MAAM,EACN,QAAQ,EACR,CAAC,EACD,SAAc,EACd,UAAU,EACV,OAAe,EACf,aAAa,EACb,aAAyB,EACzB,mBAAmB,EACnB,sBAAkC,EAClC,iBAAiB,EACjB,UAAU,EAAE,cAAc,EAC1B,SAA6C,EAC7C,MAAM,EAAE,cAAc,EACtB,UAAU,EACV,UAAU,EACV,WAAW,EACX,QAAQ,EACR,oBAA2B,EAC3B,qBAAqB,EACrB,kBAA0B,GAC3B,EAAE,uBAAuB,CAAC,CAAC,CAAC,kDAgd5B;AAED,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"EntityFormRenderer.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityFormRenderer.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EACV,uBAAuB,EACvB,YAAY,EAEb,MAAM,gBAAgB,CAAC;AAgBxB,YAAY,EAAE,uBAAuB,EAAE,CAAC;AAExC;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,EACxE,MAAM,EACN,QAAQ,EACR,CAAC,EACD,SAAc,EACd,UAAU,EACV,OAAe,EACf,aAAa,EACb,aAAyB,EACzB,mBAAmB,EACnB,sBAAkC,EAClC,iBAAiB,EACjB,UAAU,EAAE,cAAc,EAC1B,SAA6C,EAC7C,MAAM,EAAE,cAAc,EACtB,UAAU,EACV,UAAU,EACV,WAAW,EACX,QAAQ,EACR,oBAA2B,EAC3B,qBAAqB,EACrB,kBAA0B,GAC3B,EAAE,uBAAuB,CAAC,CAAC,CAAC,kDAid5B;AAED,eAAe,kBAAkB,CAAC"}
@@ -151,24 +151,15 @@ export function EntityFormRenderer({ entity, onSubmit, t, className = '', submit
151
151
  // handleSubmit from react-hook-form expects: (data: EntityData) => void | Promise<void>
152
152
  // Our onSubmit prop is (data: T) => void | Promise<void>, where T extends EntityRecord
153
153
  // EntityData should be compatible with T, so we can safely pass it
154
+ // No try/catch here — errors MUST propagate to useEntityForm's orchestrator
155
+ // which properly calls setError() and does NOT clearDraft/reset.
154
156
  const handleFormSubmit = async (data) => {
155
- try {
156
- // Await onSubmit so navigation only happens after successful submission
157
- // Type assertion is safe: EntityData is the validated form data, T is EntityRecord
158
- await onSubmit(data);
159
- // Navigate only after successful submission
160
- if (successPath) {
161
- navigate(successPath);
162
- }
163
- else {
164
- // Default: navigate back (user came from list, go back there)
165
- navigate('back');
166
- }
167
- }
168
- catch (error) {
169
- // onSubmit rejected — stay on form so user can correct errors
170
- // Error display is handled by the caller's onSubmit implementation
171
- console.error(error);
157
+ await onSubmit(data);
158
+ // Navigate only when successPath is explicitly provided.
159
+ // Edit: stay on page (most common UX). Create: consumer navigates
160
+ // in onSubmit (knows the new ID) or provides successPath.
161
+ if (successPath) {
162
+ navigate(successPath);
172
163
  }
173
164
  };
174
165
  // Determine if cancel button should show
@@ -217,6 +208,12 @@ export function EntityFormRenderer({ entity, onSubmit, t, className = '', submit
217
208
  loadingText: tCrud('form.saving', { defaultValue: 'Saving...' }),
218
209
  };
219
210
  }
211
+ if (formStatus === 'success') {
212
+ return {
213
+ loading: false,
214
+ successText: tCrud('form.saved', { defaultValue: 'Saved' }),
215
+ };
216
+ }
220
217
  return { loading: false };
221
218
  }, [formStatus, uploadProgress, tCrud]);
222
219
  return (_jsx(FormProvider, { ...form, children: _jsx(UploadProvider, { formId: formId, children: _jsxs("div", { style: {
@@ -287,7 +284,8 @@ export function EntityFormRenderer({ entity, onSubmit, t, className = '', submit
287
284
  }, loading: buttonState.loading, loadingText: buttonState.loadingText, progress: buttonState.progress, variant: secondaryButtonVariant, className: "dndev-w-full", children: secondaryButtonText }, "secondary"));
288
285
  }
289
286
  // Primary submit button (always shown)
290
- buttons.push(_jsx(Button, { type: "submit", loading: buttonState.loading, loadingText: buttonState.loadingText, progress: buttonState.progress, variant: submitVariant, className: "dndev-w-full", children: submitText ||
287
+ buttons.push(_jsx(Button, { type: "submit", loading: buttonState.loading, loadingText: buttonState.loadingText, progress: buttonState.progress, variant: buttonState.successText ? 'success' : submitVariant, disabled: !!buttonState.successText, className: "dndev-w-full", children: buttonState.successText ||
288
+ submitText ||
291
289
  tCrud('form.submit', { defaultValue: 'Submit' }) }, "submit"));
292
290
  const buttonCount = buttons.length;
293
291
  // Single button: use Stack
@@ -10,5 +10,5 @@ export type { EntityListProps };
10
10
  * - Edit and Delete actions (admin only)
11
11
  * - Auto-routing when handlers not provided
12
12
  */
13
- export declare function EntityList({ entity, basePath, onClick, hideFilters, pagination, pageSize: pageSizeProp, queryOptions, exportable, }: EntityListProps): import("react/jsx-runtime").JSX.Element | null;
13
+ export declare function EntityList({ entity, basePath, onClick, hideFilters, pagination, pageSize: pageSizeProp, queryOptions, exportable, preview, tone, }: EntityListProps): import("react/jsx-runtime").JSX.Element | null;
14
14
  //# sourceMappingURL=EntityList.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityList.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityList.tsx"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AActD,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,QAAQ,EACR,OAAO,EACP,WAAmB,EACnB,UAAmB,EACnB,QAAQ,EAAE,YAAY,EACtB,YAAY,EACZ,UAAiB,GAClB,EAAE,eAAe,kDAyRjB"}
1
+ {"version":3,"file":"EntityList.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityList.tsx"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAetD,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,QAAQ,EACR,OAAO,EACP,WAAmB,EACnB,UAAmB,EACnB,QAAQ,EAAE,YAAY,EACtB,YAAY,EACZ,UAAiB,EACjB,OAAO,EACP,IAAI,GACL,EAAE,eAAe,kDA6SjB"}
@@ -17,7 +17,7 @@ import { RefreshCw, Plus, Trash2, Edit, Search } from 'lucide-react';
17
17
  import { useMemo, useCallback, useState } from 'react';
18
18
  import { DataTable, Button, Stack, ActionButton, Section, Input, } from '@donotdev/components';
19
19
  import { useTranslation } from '@donotdev/core';
20
- import { isCrudModuleAvailable, translateFieldLabel, useCrud, useCrudList, EntityFilters, formatValue, useReferenceResolver, } from '../crudImports';
20
+ import { isCrudModuleAvailable, translateFieldLabel, useCrud, useCrudList, useCrudPageSize, EntityFilters, formatValue, useReferenceResolver, } from '../crudImports';
21
21
  import { useNavigate } from '../../routing';
22
22
  /**
23
23
  * Entity List Component - Table view for admin/internal operations
@@ -29,32 +29,39 @@ import { useNavigate } from '../../routing';
29
29
  * - Edit and Delete actions (admin only)
30
30
  * - Auto-routing when handlers not provided
31
31
  */
32
- export function EntityList({ entity, basePath, onClick, hideFilters = false, pagination = 'auto', pageSize: pageSizeProp, queryOptions, exportable = true, }) {
32
+ export function EntityList({ entity, basePath, onClick, hideFilters = false, pagination = 'auto', pageSize: pageSizeProp, queryOptions, exportable = true, preview, tone, }) {
33
33
  // Safe guard: isCrudModuleAvailable is a module-level constant (immutable after load).
34
34
  // eslint-disable-next-line react-hooks/rules-of-hooks
35
35
  if (!isCrudModuleAvailable)
36
36
  return null;
37
+ const isPreview = !!preview;
37
38
  const navigate = useNavigate();
38
39
  const base = basePath ?? `/${entity.collection}`;
39
40
  // Pre-fetch referenced collections for display resolution
40
- const referenceData = useReferenceResolver(entity);
41
+ const referenceData = useReferenceResolver(entity, !isPreview);
41
42
  // Server-side pagination state (only used when pagination='server')
42
43
  const [currentPage, setCurrentPage] = useState(1);
43
- // For server-side, we need to track pageSize state (DataTable will call onPageSizeChange)
44
- // For client-side, we just pass pageSizeProp to DataTable and it handles its own state
45
- const [serverPageSize, setServerPageSize] = useState(pageSizeProp);
44
+ // Persisted page size — survives navigation, per collection
45
+ const { pageSize: storedPageSize, setPageSize: setStoredPageSize } = useCrudPageSize({
46
+ collection: entity.collection,
47
+ ...(pageSizeProp != null && { defaultPageSize: pageSizeProp }),
48
+ });
46
49
  const [searchQuery, setSearchQuery] = useState('');
47
50
  // useCrudList now handles client-side filter + search + sort via `processed`
48
51
  // effectiveMode tells us if auto-mode switched to server (for DataTable props)
49
- const { data: listData, items: rawData, processed: filteredData, loading, mutate: refreshList, effectiveMode, } = useCrudList(entity, {
52
+ const { data: listData, items: rawData, processed: fetchedData, loading: fetchLoading, mutate: refreshList, effectiveMode, } = useCrudList(entity, {
53
+ enabled: !isPreview,
50
54
  pagination,
51
55
  searchQuery,
52
56
  ...(queryOptions && { queryOptions }),
53
57
  ...((pagination === 'server' || pagination === 'auto') && {
54
58
  page: currentPage,
55
- pageSize: serverPageSize,
59
+ pageSize: storedPageSize,
56
60
  }),
57
61
  });
62
+ // In preview mode: use preview data, skip loading state
63
+ const filteredData = isPreview ? preview : fetchedData;
64
+ const loading = isPreview ? false : fetchLoading;
58
65
  // useCrud -> handles actions (delete)
59
66
  const { delete: deleteItem } = useCrud(entity);
60
67
  const { t: tCrud } = useTranslation('crud');
@@ -66,25 +73,33 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
66
73
  }, [refreshList]);
67
74
  // Edit button: always navigate to basePath/:id
68
75
  const handleEdit = useCallback((id) => {
76
+ if (isPreview)
77
+ return;
69
78
  navigate(`${base}/${id}`);
70
- }, [base, navigate]);
79
+ }, [base, navigate, isPreview]);
71
80
  // Row click: onClick(id) if provided, else navigate to basePath/:id
72
81
  const handleView = useCallback((id) => {
82
+ if (isPreview)
83
+ return;
73
84
  if (onClick) {
74
85
  onClick(id);
75
86
  }
76
87
  else {
77
88
  navigate(`${base}/${id}`);
78
89
  }
79
- }, [base, navigate, onClick]);
90
+ }, [base, navigate, onClick, isPreview]);
80
91
  // Add New: navigate to basePath/new
81
92
  const handleCreate = useCallback(() => {
93
+ if (isPreview)
94
+ return;
82
95
  navigate(`${base}/new`);
83
- }, [base, navigate]);
96
+ }, [base, navigate, isPreview]);
84
97
  // Delete handler - store handles optimistic removal automatically
85
98
  const handleDelete = useCallback(async (itemId) => {
99
+ if (isPreview)
100
+ return;
86
101
  await deleteItem(itemId);
87
- }, [deleteItem]);
102
+ }, [deleteItem, isPreview]);
88
103
  // Generate columns from entity.listFields or entity.fields
89
104
  const columns = useMemo(() => {
90
105
  const fieldsToShow = entity.listFields || Object.keys(entity.fields);
@@ -101,12 +116,13 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
101
116
  key: fieldName,
102
117
  title: label,
103
118
  dataIndex: fieldName,
104
- sortable: true,
105
- filterable: true,
119
+ sortable: !isPreview,
120
+ filterable: !isPreview,
106
121
  align,
107
122
  render: (value, record) => formatValue(value, fieldConfig, t, {
108
123
  compact: true,
109
124
  referenceData,
125
+ item: record,
110
126
  }),
111
127
  };
112
128
  })
@@ -119,7 +135,7 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
119
135
  sortable: false,
120
136
  width: 120,
121
137
  align: 'center',
122
- render: (_, record) => (_jsxs(Stack, { direction: "row", gap: "tight", align: "center", justify: "center", children: [_jsx(Button, { variant: "outline", icon: Edit, onClick: (e) => {
138
+ render: (_, record) => (_jsxs(Stack, { direction: "row", gap: "tight", align: "center", justify: "center", children: [_jsx(Button, { variant: "outline", icon: Edit, disabled: isPreview, onClick: (e) => {
123
139
  e.stopPropagation();
124
140
  handleEdit(record.id);
125
141
  }, "aria-label": tCrud('edit', { defaultValue: 'Edit' }) }), _jsx(ActionButton, { action: async () => {
@@ -130,12 +146,12 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
130
146
  defaultValue: 'Delete Item',
131
147
  }), loadingText: tCrud('delete.loading', {
132
148
  defaultValue: 'Deleting...',
133
- }), variant: "destructive", icon: Trash2, "aria-label": tCrud('delete', { defaultValue: 'Delete' }), children: tCrud('delete', { defaultValue: 'Delete' }) })] })),
149
+ }), variant: "destructive", icon: Trash2, disabled: isPreview, "aria-label": tCrud('delete', { defaultValue: 'Delete' }), children: tCrud('delete', { defaultValue: 'Delete' }) })] })),
134
150
  });
135
151
  return baseColumns;
136
152
  // Note: 't' and 'tCrud' are assumed stable across renders (i18next returns the same reference
137
153
  // unless the language changes). If i18n language switching causes stale columns, add i18n.language to deps.
138
- }, [entity, t, tCrud, handleEdit, handleDelete]);
154
+ }, [entity, t, tCrud, handleEdit, handleDelete, isPreview]);
139
155
  // Entity name for section title
140
156
  const entityName = t('name', { defaultValue: entity.name });
141
157
  // Result count
@@ -144,9 +160,9 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
144
160
  return (_jsxs(_Fragment, { children: [_jsx(Section, { title: tCrud('filters.title', {
145
161
  entity: entityName,
146
162
  defaultValue: `Browse ${entityName} - Filters`,
147
- }), collapsible: true, defaultOpen: true, 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', {
163
+ }), 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', {
148
164
  defaultValue: 'Search...',
149
- }), value: searchQuery, onChange: (e) => setSearchQuery(e.target.value), icon: Search, className: "dndev-w-full" }), _jsx(Button, { icon: RefreshCw, variant: "outline", onClick: handleRefresh, disabled: loading, display: "compact", "aria-label": tCrud('refresh', { defaultValue: 'Refresh' }) }), _jsx(Button, { icon: Plus, onClick: handleCreate, display: "compact", children: tCrud('addNew', { defaultValue: 'Add New' }) })] }), !hideFilters && (_jsx(EntityFilters, { entity: entity, data: rawData, fieldsToFilter: entity.listFields }))] }) }), _jsx(Section, { title: loading
165
+ }), 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' }) }), _jsx(Button, { icon: Plus, onClick: handleCreate, display: "compact", disabled: isPreview, children: tCrud('addNew', { defaultValue: 'Add New' }) })] }), !hideFilters && (_jsx(EntityFilters, { entity: entity, data: rawData, fieldsToFilter: entity.listFields }))] }) }), _jsx(Section, { title: loading
150
166
  ? tCrud('results.title.fetching', {
151
167
  defaultValue: 'Fetching...',
152
168
  })
@@ -155,7 +171,7 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
155
171
  defaultValue: resultCount === 1
156
172
  ? 'Found 1 occurrence'
157
173
  : `Found ${resultCount} occurrences`,
158
- }), collapsible: true, defaultOpen: true, children: _jsx(DataTable, { data: filteredData, columns: columns, sortable: true, searchable: false, pagination: true, loading: loading, onRowClick: (item) => handleView(item.id),
174
+ }), 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),
159
175
  // Pagination labels (translated)
160
176
  showingLabel: tCrud('pagination.showing', {
161
177
  defaultValue: 'Showing {{from}} to {{to}} of {{total}} entries',
@@ -165,13 +181,13 @@ export function EntityList({ entity, basePath, onClick, hideFilters = false, pag
165
181
  defaultValue: 'Next',
166
182
  }), paginationItemsPerPagePlaceholder: tCrud('pagination.itemsPerPagePlaceholder', {
167
183
  defaultValue: 'Items per page',
168
- }), ...(pageSizeProp && { pageSize: pageSizeProp }), ...(effectiveMode === 'server' && {
184
+ }),
185
+ // Persisted page size — always controlled via CrudStore
186
+ pageSize: storedPageSize, onPageSizeChange: setStoredPageSize, ...(!isPreview && effectiveMode === 'server' && {
169
187
  currentPage,
170
- pageSize: serverPageSize,
171
188
  total: listData?.total,
172
189
  onPageChange: setCurrentPage,
173
- onPageSizeChange: setServerPageSize,
174
190
  }),
175
191
  // Export functionality
176
- exportable: exportable, exportFilename: `${entity.collection}-export`, exportLabel: tCrud('export', { defaultValue: 'Export' }) }) })] }));
192
+ exportable: isPreview ? false : exportable, exportFilename: `${entity.collection}-export`, exportLabel: tCrud('export', { defaultValue: 'Export' }) }) })] }));
177
193
  }
@@ -39,5 +39,5 @@ import type { EntityRecommendationsProps } from '@donotdev/core';
39
39
  * @since 0.0.15
40
40
  * @author AMBROISE PARK Consulting
41
41
  */
42
- export declare function EntityRecommendations({ entity, queryOptions, title, basePath, cols, className, }: EntityRecommendationsProps): import("react/jsx-runtime").JSX.Element | null;
42
+ export declare function EntityRecommendations({ entity, queryOptions, title, basePath, cols, tone, className, }: EntityRecommendationsProps): import("react/jsx-runtime").JSX.Element | null;
43
43
  //# sourceMappingURL=EntityRecommendations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityRecommendations.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityRecommendations.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAKjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,MAAM,EACN,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,IAAmB,EACnB,SAAS,GACV,EAAE,0BAA0B,kDA8D5B"}
1
+ {"version":3,"file":"EntityRecommendations.d.ts","sourceRoot":"","sources":["../../../src/crud/components/EntityRecommendations.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAKjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,MAAM,EACN,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,IAAmB,EACnB,IAAI,EACJ,SAAS,GACV,EAAE,0BAA0B,kDA8D5B"}
@@ -54,7 +54,7 @@ import { CrudCard } from './CrudCardLink';
54
54
  * @since 0.0.15
55
55
  * @author AMBROISE PARK Consulting
56
56
  */
57
- export function EntityRecommendations({ entity, queryOptions, title, basePath, cols = [1, 1, 3, 3], className, }) {
57
+ export function EntityRecommendations({ entity, queryOptions, title, basePath, cols = [1, 1, 3, 3], tone, className, }) {
58
58
  // Safe guard: isCrudModuleAvailable is a module-level constant (immutable after load).
59
59
  // eslint-disable-next-line react-hooks/rules-of-hooks
60
60
  if (!isCrudModuleAvailable)
@@ -63,13 +63,13 @@ export function EntityRecommendations({ entity, queryOptions, title, basePath, c
63
63
  const { items, loading } = useCrudCardList(entity, {
64
64
  queryOptions,
65
65
  });
66
+ // Must be called before any early return to satisfy Rules of Hooks.
67
+ const bp = useBreakpoint('current');
66
68
  if (!loading && items.length === 0) {
67
69
  return null;
68
70
  }
69
71
  const resolvedBasePath = basePath ?? `/${entity.collection}`;
70
72
  const resolvedTitle = title ?? t('recommendations.title', { defaultValue: 'You may also like' });
71
- // Breakpoint-aware skeleton count: 3 rows at current breakpoint
72
- const bp = useBreakpoint('current');
73
73
  const bpIndex = {
74
74
  mobile: 0,
75
75
  tablet: 1,
@@ -82,7 +82,7 @@ export function EntityRecommendations({ entity, queryOptions, title, basePath, c
82
82
  ? cols
83
83
  : 3) ?? 1;
84
84
  const skeletonCount = (typeof currentCols === 'number' ? currentCols : 3) * 3;
85
- return (_jsx(Section, { title: resolvedTitle, gridCols: cols, className: className, children: loading
85
+ return (_jsx(Section, { title: resolvedTitle, gridCols: cols, tone: tone, className: className, children: loading
86
86
  ? Array.from({ length: skeletonCount }, (_, i) => (_jsx(Card, { title: _jsx(Skeleton, { width: "60%" }), subtitle: _jsx(Skeleton, { width: "40%" }), content: _jsxs(Stack, { direction: "column", gap: "tight", children: [_jsx(Skeleton, { width: "80%" }), _jsx(Skeleton, { width: "50%" })] }), elevated: true }, i)))
87
87
  : items.map((item) => (_jsx(CrudCard, { item: item, entity: entity, detailHref: `${resolvedBasePath}/${item.id}` }, item.id))) }));
88
88
  }
@@ -24,6 +24,7 @@ export declare const useCrudList: typeof crudModule.useCrudList;
24
24
  export declare const useCrudCardList: typeof crudModule.useCrudCardList;
25
25
  export declare const useEntityFavorites: typeof crudModule.useEntityFavorites;
26
26
  export declare const useCrudFilters: typeof crudModule.useCrudFilters;
27
+ export declare const useCrudPageSize: typeof crudModule.useCrudPageSize;
27
28
  export declare const useEntityWorkflow: typeof crudModule.useEntityWorkflow;
28
29
  export declare const useReferenceResolver: typeof crudModule.useReferenceResolver;
29
30
  export declare const DisplayFieldRenderer: typeof crudModule.DisplayFieldRenderer;
@@ -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,wBAAwB,4CAAuC,CAAC;AAC7E,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,eAAe,mCAA8B,CAAC;AAC3D,eAAO,MAAM,kBAAkB,sCAAiC,CAAC;AACjE,eAAO,MAAM,cAAc,kCAA6B,CAAC;AACzD,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,wBAAwB,4CAAuC,CAAC;AAC7E,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,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"}
@@ -26,6 +26,7 @@ export const useCrudList = crudModule?.useCrudList;
26
26
  export const useCrudCardList = crudModule?.useCrudCardList;
27
27
  export const useEntityFavorites = crudModule?.useEntityFavorites;
28
28
  export const useCrudFilters = crudModule?.useCrudFilters;
29
+ export const useCrudPageSize = crudModule?.useCrudPageSize;
29
30
  export const useEntityWorkflow = crudModule?.useEntityWorkflow;
30
31
  export const useReferenceResolver = crudModule?.useReferenceResolver;
31
32
  // --- Components ---