ding-react-admin 2.0.0 → 2.0.5

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 (169) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +254 -195
  3. package/dist/index.css +1 -0
  4. package/dist/index.js +1773 -1170
  5. package/dist/src/components/NavMenuLabel.d.ts +8 -0
  6. package/dist/src/components/NavMenuLabel.d.ts.map +1 -0
  7. package/dist/src/components/NavMenuSearch.d.ts +9 -0
  8. package/dist/src/components/NavMenuSearch.d.ts.map +1 -0
  9. package/dist/src/components/ScrollableArea.d.ts +10 -0
  10. package/dist/src/components/ScrollableArea.d.ts.map +1 -0
  11. package/dist/src/components/index.d.ts +3 -0
  12. package/dist/src/components/index.d.ts.map +1 -1
  13. package/dist/src/context/AuthProvider.d.ts +2 -0
  14. package/dist/src/context/AuthProvider.d.ts.map +1 -1
  15. package/dist/src/crud/FormGlobalErrorsAlert.d.ts +5 -0
  16. package/dist/src/crud/FormGlobalErrorsAlert.d.ts.map +1 -0
  17. package/dist/src/crud/ResourceForm.d.ts +1 -4
  18. package/dist/src/crud/ResourceForm.d.ts.map +1 -1
  19. package/dist/src/crud/ResourceFormModal.d.ts +7 -1
  20. package/dist/src/crud/ResourceFormModal.d.ts.map +1 -1
  21. package/dist/src/crud/ResourceRecordForm.d.ts +27 -0
  22. package/dist/src/crud/ResourceRecordForm.d.ts.map +1 -0
  23. package/dist/src/crud/fields/ReferenceField.d.ts +12 -2
  24. package/dist/src/crud/fields/ReferenceField.d.ts.map +1 -1
  25. package/dist/src/crud/fields/ReferenceInputActions.d.ts +16 -0
  26. package/dist/src/crud/fields/ReferenceInputActions.d.ts.map +1 -0
  27. package/dist/src/crud/fields/ReferenceManyField.d.ts +10 -1
  28. package/dist/src/crud/fields/ReferenceManyField.d.ts.map +1 -1
  29. package/dist/src/crud/filters/ReferenceFilter.d.ts +1 -1
  30. package/dist/src/crud/filters/ReferenceFilter.d.ts.map +1 -1
  31. package/dist/src/crud/index.d.ts +5 -0
  32. package/dist/src/crud/index.d.ts.map +1 -1
  33. package/dist/src/crud/types.d.ts +12 -0
  34. package/dist/src/crud/types.d.ts.map +1 -1
  35. package/dist/src/crud/utils/choiceSelectionUtils.d.ts +10 -0
  36. package/dist/src/crud/utils/choiceSelectionUtils.d.ts.map +1 -0
  37. package/dist/src/crud/utils/choiceSelectionUtils.test.d.ts +2 -0
  38. package/dist/src/crud/utils/choiceSelectionUtils.test.d.ts.map +1 -0
  39. package/dist/src/crud/utils/formErrors.d.ts +18 -7
  40. package/dist/src/crud/utils/formErrors.d.ts.map +1 -1
  41. package/dist/src/crud/utils/formErrors.test.d.ts +2 -0
  42. package/dist/src/crud/utils/formErrors.test.d.ts.map +1 -0
  43. package/dist/src/crud/utils/prepareFormSubmitBody.d.ts +1 -0
  44. package/dist/src/crud/utils/prepareFormSubmitBody.d.ts.map +1 -1
  45. package/dist/src/crud/utils/referenceSelectNotFoundContent.d.ts +4 -0
  46. package/dist/src/crud/utils/referenceSelectNotFoundContent.d.ts.map +1 -0
  47. package/dist/src/crud/utils/toFormData.d.ts +1 -1
  48. package/dist/src/crud/utils/toFormData.d.ts.map +1 -1
  49. package/dist/src/crud/utils/uploadReferenceUtils.d.ts +5 -0
  50. package/dist/src/crud/utils/uploadReferenceUtils.d.ts.map +1 -0
  51. package/dist/src/crud/utils/useChoices.d.ts +27 -1
  52. package/dist/src/crud/utils/useChoices.d.ts.map +1 -1
  53. package/dist/src/crud/utils/useFormRecord.d.ts +9 -7
  54. package/dist/src/crud/utils/useFormRecord.d.ts.map +1 -1
  55. package/dist/src/data/parseFormErrorHelpers.d.ts +6 -27
  56. package/dist/src/data/parseFormErrorHelpers.d.ts.map +1 -1
  57. package/dist/src/index.d.ts +2 -2
  58. package/dist/src/index.d.ts.map +1 -1
  59. package/dist/src/layouts/AdminLayout.d.ts +1 -1
  60. package/dist/src/layouts/AdminLayout.d.ts.map +1 -1
  61. package/dist/src/layouts/AuthPageLayout.d.ts.map +1 -1
  62. package/dist/src/layouts/navFilter.d.ts +5 -0
  63. package/dist/src/layouts/navFilter.d.ts.map +1 -0
  64. package/dist/src/layouts/navMenuItems.d.ts +6 -0
  65. package/dist/src/layouts/navMenuItems.d.ts.map +1 -0
  66. package/dist/src/types.d.ts +12 -0
  67. package/dist/src/types.d.ts.map +1 -1
  68. package/package.json +85 -59
  69. package/src/app/AdminApp.tsx +34 -34
  70. package/src/components/AuthAlternateLink.tsx +23 -23
  71. package/src/components/DensitySwitch.tsx +31 -31
  72. package/src/components/NavMenuLabel.tsx +26 -0
  73. package/src/components/NavMenuSearch.tsx +76 -0
  74. package/src/components/ScrollableArea.tsx +46 -0
  75. package/src/components/ThemeSwitch.tsx +28 -28
  76. package/src/components/ThemeToolbar.tsx +34 -34
  77. package/src/components/index.ts +7 -4
  78. package/src/components/navMenu.css +21 -0
  79. package/src/components/scrollable.css +28 -0
  80. package/src/context/AppThemeProvider.tsx +128 -128
  81. package/src/context/AuthProvider.tsx +89 -77
  82. package/src/context/DataProvider.tsx +30 -30
  83. package/src/context/PermissionsProvider.tsx +57 -57
  84. package/src/crud/FilterBar.tsx +36 -36
  85. package/src/crud/FormGlobalErrorsAlert.tsx +36 -0
  86. package/src/crud/FormSteps.tsx +135 -135
  87. package/src/crud/FormTabs.tsx +126 -126
  88. package/src/crud/InlineFormSet.tsx +162 -162
  89. package/src/crud/ListActionsBar.tsx +106 -106
  90. package/src/crud/ResourceForm.tsx +83 -160
  91. package/src/crud/ResourceFormModal.tsx +75 -133
  92. package/src/crud/ResourceRecordForm.tsx +166 -0
  93. package/src/crud/columns/BooleanColumn.tsx +32 -32
  94. package/src/crud/columns/CustomColumn.tsx +33 -33
  95. package/src/crud/columns/DateColumn.tsx +28 -28
  96. package/src/crud/columns/ImageColumn.tsx +58 -58
  97. package/src/crud/columns/NumberColumn.tsx +31 -31
  98. package/src/crud/columns/ReferenceColumn.tsx +85 -85
  99. package/src/crud/columns/ReferenceManyColumn.tsx +67 -67
  100. package/src/crud/columns/TextColumn.tsx +38 -38
  101. package/src/crud/context/FilterContext.tsx +71 -71
  102. package/src/crud/context/FormContext.tsx +39 -39
  103. package/src/crud/context/FormSectionContext.tsx +22 -22
  104. package/src/crud/context/InlineFieldsRegistry.tsx +61 -61
  105. package/src/crud/context/ListContext.tsx +93 -93
  106. package/src/crud/fields/BooleanField.tsx +38 -38
  107. package/src/crud/fields/DateField.tsx +53 -53
  108. package/src/crud/fields/FileField.tsx +123 -123
  109. package/src/crud/fields/ImageField.tsx +120 -120
  110. package/src/crud/fields/NumberField.tsx +52 -52
  111. package/src/crud/fields/PasswordField.tsx +99 -99
  112. package/src/crud/fields/ReferenceField.tsx +237 -96
  113. package/src/crud/fields/ReferenceInputActions.tsx +106 -0
  114. package/src/crud/fields/ReferenceManyField.tsx +200 -76
  115. package/src/crud/fields/SelectField.tsx +48 -48
  116. package/src/crud/fields/TextField.tsx +46 -46
  117. package/src/crud/fields/uploadFieldUtils.ts +21 -21
  118. package/src/crud/fields/useUploadPreviewUrl.ts +20 -20
  119. package/src/crud/filters/BooleanFilter.tsx +38 -38
  120. package/src/crud/filters/DateFilter.tsx +35 -35
  121. package/src/crud/filters/NumberFilter.tsx +33 -33
  122. package/src/crud/filters/ReferenceFilter.tsx +192 -173
  123. package/src/crud/filters/SelectFilter.tsx +44 -44
  124. package/src/crud/filters/TextFilter.tsx +36 -36
  125. package/src/crud/index.ts +99 -94
  126. package/src/crud/types.ts +146 -134
  127. package/src/crud/utils/buildFormPayload.ts +24 -24
  128. package/src/crud/utils/buildInlineRowsPayload.ts +37 -37
  129. package/src/crud/utils/buildResourceFormSubmitBody.ts +29 -29
  130. package/src/crud/utils/choiceSelectionUtils.test.ts +45 -0
  131. package/src/crud/utils/choiceSelectionUtils.ts +116 -0
  132. package/src/crud/utils/formErrors.test.ts +168 -0
  133. package/src/crud/utils/formErrors.ts +138 -42
  134. package/src/crud/utils/formSectionErrors.ts +85 -85
  135. package/src/crud/utils/getFormValue.ts +13 -13
  136. package/src/crud/utils/hasUploadValues.ts +9 -9
  137. package/src/crud/utils/nestedFieldPath.ts +8 -8
  138. package/src/crud/utils/prepareFormSubmitBody.ts +22 -17
  139. package/src/crud/utils/referenceSelectNotFoundContent.tsx +7 -0
  140. package/src/crud/utils/setFormValue.ts +18 -18
  141. package/src/crud/utils/sortQueryParam.ts +37 -37
  142. package/src/crud/utils/toFormData.ts +79 -81
  143. package/src/crud/utils/uploadReferenceUtils.ts +44 -0
  144. package/src/crud/utils/useAbortableEffect.ts +17 -17
  145. package/src/crud/utils/useChoices.ts +330 -182
  146. package/src/crud/utils/useFormRecord.ts +179 -156
  147. package/src/crud/utils/useListQueryState.ts +191 -191
  148. package/src/data/abortError.test.ts +19 -19
  149. package/src/data/abortError.ts +10 -10
  150. package/src/data/createMemoryResourceHandlers.ts +78 -78
  151. package/src/data/createRestResourceHandlers.ts +63 -63
  152. package/src/data/dataUtils.test.ts +228 -220
  153. package/src/data/inMemoryList.ts +97 -97
  154. package/src/data/parseFormErrorHelpers.test.ts +201 -138
  155. package/src/data/parseFormErrorHelpers.ts +376 -311
  156. package/src/data/sortHelpers.ts +48 -48
  157. package/src/index.ts +211 -207
  158. package/src/layouts/AdminLayout.tsx +530 -382
  159. package/src/layouts/AuthPageLayout.tsx +87 -81
  160. package/src/layouts/navFilter.ts +49 -0
  161. package/src/layouts/navMenuItems.tsx +44 -0
  162. package/src/pages/LoginPage.tsx +80 -80
  163. package/src/pages/PlaceholderPage.tsx +9 -9
  164. package/src/permissions/resourcePermissions.ts +47 -47
  165. package/src/router/createAdminRouter.tsx +64 -64
  166. package/src/router/guards.tsx +63 -63
  167. package/src/router/routeAccess.ts +89 -89
  168. package/src/types.ts +10 -0
  169. package/src/vite-env.d.ts +1 -1
package/src/crud/index.ts CHANGED
@@ -1,94 +1,99 @@
1
- export { ResourceList, useResourceListContext } from "./ResourceList";
2
- export type { ResourceListProps } from "./ResourceList";
3
- export { FilterBar } from "./FilterBar";
4
- export { ResourceForm } from "./ResourceForm";
5
- export type { ResourceFormProps } from "./ResourceForm";
6
- export { ResourceFormModal } from "./ResourceFormModal";
7
- export type { ResourceFormModalProps } from "./ResourceFormModal";
8
- export { InlineFormSet, InlineFormSetStacked } from "./InlineFormSet";
9
- export type {
10
- InlineFormSetProps,
11
- InlineFormSetStackedProps,
12
- InlineFormSetLayout,
13
- } from "./InlineFormSet";
14
- export { FormTabs, FormTab } from "./FormTabs";
15
- export type { FormTabsProps, FormTabProps } from "./FormTabs";
16
- export { FormSteps, FormStep } from "./FormSteps";
17
- export type { FormStepsProps, FormStepProps } from "./FormSteps";
18
-
19
- export { TextField } from "./fields/TextField";
20
- export { NumberField } from "./fields/NumberField";
21
- export { BooleanField } from "./fields/BooleanField";
22
- export { DateField } from "./fields/DateField";
23
- export { SelectField } from "./fields/SelectField";
24
- export { PasswordField } from "./fields/PasswordField";
25
- export { ReferenceField } from "./fields/ReferenceField";
26
- export { ReferenceManyField } from "./fields/ReferenceManyField";
27
- export { ImageField } from "./fields/ImageField";
28
- export { FileField } from "./fields/FileField";
29
- export { FieldWrapper } from "./fields/FieldWrapper";
30
- export type { FieldWrapperProps } from "./fields/FieldWrapper";
31
- export type { ImageFieldProps } from "./fields/ImageField";
32
- export type { FileFieldProps } from "./fields/FileField";
33
- export type { UploadFieldValue } from "./fields/uploadFieldUtils";
34
-
35
- export { TextColumn } from "./columns/TextColumn";
36
- export { NumberColumn } from "./columns/NumberColumn";
37
- export { BooleanColumn } from "./columns/BooleanColumn";
38
- export { DateColumn } from "./columns/DateColumn";
39
- export { ReferenceColumn } from "./columns/ReferenceColumn";
40
- export { ReferenceManyColumn } from "./columns/ReferenceManyColumn";
41
- export { ImageColumn } from "./columns/ImageColumn";
42
- export { CustomColumn } from "./columns/CustomColumn";
43
-
44
- export { TextFilter } from "./filters/TextFilter";
45
- export { NumberFilter } from "./filters/NumberFilter";
46
- export { BooleanFilter } from "./filters/BooleanFilter";
47
- export { DateFilter } from "./filters/DateFilter";
48
- export { SelectFilter } from "./filters/SelectFilter";
49
- export {
50
- ReferenceFilter,
51
- ReferenceManyFilter,
52
- } from "./filters/ReferenceFilter";
53
-
54
- export { useListQueryState } from "./utils/useListQueryState";
55
- export { useAbortableEffect } from "./utils/useAbortableEffect";
56
- export type {
57
- ListQueryState,
58
- ListQueryActions,
59
- } from "./utils/useListQueryState";
60
- export { useChoices } from "./utils/useChoices";
61
- export { getFormValue } from "./utils/getFormValue";
62
- export { setFormValue } from "./utils/setFormValue";
63
- export { buildFormPayload } from "./utils/buildFormPayload";
64
- export { buildInlineRowsPayload } from "./utils/buildInlineRowsPayload";
65
- export { buildResourceFormSubmitBody } from "./utils/buildResourceFormSubmitBody";
66
- export { prepareFormSubmitBody } from "./utils/prepareFormSubmitBody";
67
- export { toFormData } from "./utils/toFormData";
68
- export { hasUploadValues } from "./utils/hasUploadValues";
69
- export type { ToFormDataOptions } from "./utils/toFormData";
70
- export type { PrepareFormSubmitBodyOptions } from "./utils/prepareFormSubmitBody";
71
- export { nestedFieldPath } from "./utils/nestedFieldPath";
72
- export {
73
- useRegisterPayloadField,
74
- useRegisterSectionField,
75
- } from "./context/PayloadFieldsContext";
76
- export type { InlineFieldRegistration } from "./context/InlineFieldsRegistry";
77
-
78
- export type {
79
- BaseSourceProps,
80
- ChoiceOption,
81
- ChoicesLoader,
82
- ReferenceProps,
83
- DisplayProps,
84
- EditMode,
85
- FieldRules,
86
- InlineCellContext,
87
- InlineColumnDef,
88
- InlineFormSetBaseProps,
89
- InlineRowContext,
90
- ResourceListBuiltInActions,
91
- ResourceListBulkAction,
92
- ResourceListBulkActionHelpers,
93
- ResourceListRowActionsHelpers,
94
- } from "./types";
1
+ export { ResourceList, useResourceListContext } from "./ResourceList";
2
+ export type { ResourceListProps } from "./ResourceList";
3
+ export { FilterBar } from "./FilterBar";
4
+ export { ResourceForm } from "./ResourceForm";
5
+ export type { ResourceFormProps } from "./ResourceForm";
6
+ export { ResourceFormModal } from "./ResourceFormModal";
7
+ export type { ResourceFormModalProps } from "./ResourceFormModal";
8
+ export { InlineFormSet, InlineFormSetStacked } from "./InlineFormSet";
9
+ export type {
10
+ InlineFormSetProps,
11
+ InlineFormSetStackedProps,
12
+ InlineFormSetLayout,
13
+ } from "./InlineFormSet";
14
+ export { FormTabs, FormTab } from "./FormTabs";
15
+ export type { FormTabsProps, FormTabProps } from "./FormTabs";
16
+ export { FormSteps, FormStep } from "./FormSteps";
17
+ export type { FormStepsProps, FormStepProps } from "./FormSteps";
18
+
19
+ export { TextField } from "./fields/TextField";
20
+ export { NumberField } from "./fields/NumberField";
21
+ export { BooleanField } from "./fields/BooleanField";
22
+ export { DateField } from "./fields/DateField";
23
+ export { SelectField } from "./fields/SelectField";
24
+ export { PasswordField } from "./fields/PasswordField";
25
+ export { ReferenceField } from "./fields/ReferenceField";
26
+ export type { ReferenceFieldProps } from "./fields/ReferenceField";
27
+ export { ReferenceManyField } from "./fields/ReferenceManyField";
28
+ export type { ReferenceManyFieldProps } from "./fields/ReferenceManyField";
29
+ export { ReferenceInputActions } from "./fields/ReferenceInputActions";
30
+ export type { ReferenceInputActionsProps } from "./fields/ReferenceInputActions";
31
+ export { ImageField } from "./fields/ImageField";
32
+ export { FileField } from "./fields/FileField";
33
+ export { FieldWrapper } from "./fields/FieldWrapper";
34
+ export type { FieldWrapperProps } from "./fields/FieldWrapper";
35
+ export type { ImageFieldProps } from "./fields/ImageField";
36
+ export type { FileFieldProps } from "./fields/FileField";
37
+ export type { UploadFieldValue } from "./fields/uploadFieldUtils";
38
+
39
+ export { TextColumn } from "./columns/TextColumn";
40
+ export { NumberColumn } from "./columns/NumberColumn";
41
+ export { BooleanColumn } from "./columns/BooleanColumn";
42
+ export { DateColumn } from "./columns/DateColumn";
43
+ export { ReferenceColumn } from "./columns/ReferenceColumn";
44
+ export { ReferenceManyColumn } from "./columns/ReferenceManyColumn";
45
+ export { ImageColumn } from "./columns/ImageColumn";
46
+ export { CustomColumn } from "./columns/CustomColumn";
47
+
48
+ export { TextFilter } from "./filters/TextFilter";
49
+ export { NumberFilter } from "./filters/NumberFilter";
50
+ export { BooleanFilter } from "./filters/BooleanFilter";
51
+ export { DateFilter } from "./filters/DateFilter";
52
+ export { SelectFilter } from "./filters/SelectFilter";
53
+ export {
54
+ ReferenceFilter,
55
+ ReferenceManyFilter,
56
+ } from "./filters/ReferenceFilter";
57
+
58
+ export { useListQueryState } from "./utils/useListQueryState";
59
+ export { useAbortableEffect } from "./utils/useAbortableEffect";
60
+ export type {
61
+ ListQueryState,
62
+ ListQueryActions,
63
+ } from "./utils/useListQueryState";
64
+ export { useChoices } from "./utils/useChoices";
65
+ export type { UseChoicesOptions } from "./utils/useChoices";
66
+ export { getFormValue } from "./utils/getFormValue";
67
+ export { setFormValue } from "./utils/setFormValue";
68
+ export { buildFormPayload } from "./utils/buildFormPayload";
69
+ export { buildInlineRowsPayload } from "./utils/buildInlineRowsPayload";
70
+ export { buildResourceFormSubmitBody } from "./utils/buildResourceFormSubmitBody";
71
+ export { prepareFormSubmitBody } from "./utils/prepareFormSubmitBody";
72
+ export { toFormData } from "./utils/toFormData";
73
+ export { hasUploadValues } from "./utils/hasUploadValues";
74
+ export type { ToFormDataOptions } from "./utils/toFormData";
75
+ export type { PrepareFormSubmitBodyOptions } from "./utils/prepareFormSubmitBody";
76
+ export { nestedFieldPath } from "./utils/nestedFieldPath";
77
+ export {
78
+ useRegisterPayloadField,
79
+ useRegisterSectionField,
80
+ } from "./context/PayloadFieldsContext";
81
+ export type { InlineFieldRegistration } from "./context/InlineFieldsRegistry";
82
+
83
+ export type {
84
+ BaseSourceProps,
85
+ ChoiceOption,
86
+ ChoicesLoader,
87
+ ReferenceProps,
88
+ DisplayProps,
89
+ EditMode,
90
+ FieldRules,
91
+ InlineCellContext,
92
+ InlineColumnDef,
93
+ InlineFormSetBaseProps,
94
+ InlineRowContext,
95
+ ResourceListBuiltInActions,
96
+ ResourceListBulkAction,
97
+ ResourceListBulkActionHelpers,
98
+ ResourceListRowActionsHelpers,
99
+ } from "./types";
package/src/crud/types.ts CHANGED
@@ -1,134 +1,146 @@
1
- import type { ReactNode } from "react";
2
- import type { ColumnsType } from "antd/es/table";
3
- import type { DataProvider } from "../data/dataProviderTypes";
4
- import type { RegisterOptions } from "react-hook-form";
5
-
6
- export type BaseSourceProps = {
7
- source: string;
8
- label?: string;
9
- };
10
-
11
- export type ChoiceOption = {
12
- label: string;
13
- value: unknown;
14
- /** Full record when loaded from a reference resource (for dependent fields). */
15
- record?: Record<string, unknown>;
16
- };
17
-
18
- export type ChoicesContext = {
19
- dataProvider: DataProvider;
20
- search?: string;
21
- };
22
-
23
- export type ChoicesLoader =
24
- | { resource: string; filter?: Record<string, unknown> }
25
- | ChoiceOption[]
26
- | ((ctx: ChoicesContext) => Promise<ChoiceOption[]>);
27
-
28
- export type ReferenceProps = {
29
- reference?: string;
30
- choices?: ChoicesLoader;
31
- optionLabel?: string | ((record: Record<string, unknown>) => string);
32
- optionValue?: string;
33
- };
34
-
35
- export type DisplayProps = {
36
- display?: string | ((record: Record<string, unknown>) => ReactNode);
37
- };
38
-
39
- export type FieldRules = RegisterOptions;
40
-
41
- export type ColumnDefinition<T extends Record<string, unknown>> = {
42
- key: string;
43
- source: string;
44
- label?: string;
45
- sortable?: boolean;
46
- buildColumn: () => ColumnsType<T>[number];
47
- };
48
-
49
- export type FilterDefinition = {
50
- key: string;
51
- source: string;
52
- label?: string;
53
- render: (props: {
54
- value: unknown;
55
- onChange: (value: unknown) => void;
56
- }) => ReactNode;
57
- };
58
-
59
- export type InlineFormSetBaseProps = {
60
- /** RHF `useFieldArray` name and default API nested key, e.g. `"lines"`. */
61
- field: string;
62
- label?: string;
63
- /** API key when different from `field`. */
64
- payloadKey?: string;
65
- transformRows?: (rows: Record<string, unknown>[]) => unknown;
66
- };
67
-
68
- /** Passed to each tabular inline column's `cell` renderer. */
69
- export type InlineCellContext = {
70
- /** Full RHF path, e.g. `lines.0.label`. */
71
- name: string;
72
- index: number;
73
- field: string;
74
- };
75
-
76
- export type InlineColumnDef = {
77
- source: string;
78
- label?: string;
79
- width?: number | string;
80
- minWidth?: number | string;
81
- cell: (ctx: InlineCellContext) => ReactNode;
82
- };
83
-
84
- /** Passed to `InlineFormSetStacked`'s `renderRow` for one related row. */
85
- export type InlineRowContext = {
86
- field: string;
87
- index: number;
88
- /** RHF path helper — `name("label")` → `field.index.label`. */
89
- name: (source: string) => string;
90
- };
91
-
92
- export type EditMode = "page" | "modal" | "both";
93
-
94
- /** Toggle built-in row actions. Omitted keys default to `true` (still gated by permissions). */
95
- export type ResourceListBuiltInActions = {
96
- edit?: boolean;
97
- quickEdit?: boolean;
98
- delete?: boolean;
99
- };
100
-
101
- export type ResourceListRowActionsHelpers = {
102
- reload: () => void;
103
- openEditModal: (id: string | number) => void;
104
- };
105
-
106
- export type ResourceListBulkActionHelpers = {
107
- reload: () => void;
108
- clearSelection: () => void;
109
- };
110
-
111
- /** Bulk list action (Django admin–style). Runs on selected row ids. */
112
- export type ResourceListBulkAction = {
113
- key: string;
114
- label: string;
115
- /** Optional confirmation message. Return false to cancel. */
116
- confirm?:
117
- | string
118
- | ((
119
- selectedIds: (string | number)[],
120
- helpers: ResourceListBulkActionHelpers,
121
- ) => string | false | Promise<string | false>);
122
- execute: (
123
- selectedIds: (string | number)[],
124
- helpers: ResourceListBulkActionHelpers,
125
- ) => void | Promise<void>;
126
- };
127
-
128
- export const LIST_QUERY_RESERVED = new Set([
129
- "page",
130
- "perPage",
131
- "sort",
132
- "create",
133
- "edit",
134
- ]);
1
+ import type { ReactNode } from "react";
2
+ import type { ColumnsType } from "antd/es/table";
3
+ import type { DataProvider } from "../data/dataProviderTypes";
4
+ import type { RegisterOptions } from "react-hook-form";
5
+
6
+ export type BaseSourceProps = {
7
+ source: string;
8
+ label?: string;
9
+ };
10
+
11
+ export type ChoiceOption = {
12
+ label: string;
13
+ value: unknown;
14
+ /** Full record when loaded from a reference resource (for dependent fields). */
15
+ record?: Record<string, unknown>;
16
+ };
17
+
18
+ export type ChoicesContext = {
19
+ dataProvider: DataProvider;
20
+ search?: string;
21
+ };
22
+
23
+ export type ChoicesLoader =
24
+ | { resource: string; filter?: Record<string, unknown> }
25
+ | ChoiceOption[]
26
+ | ((ctx: ChoicesContext) => Promise<ChoiceOption[]>);
27
+
28
+ export type ReferenceProps = {
29
+ reference?: string;
30
+ choices?: ChoicesLoader;
31
+ optionLabel?: string | ((record: Record<string, unknown>) => string);
32
+ optionValue?: string;
33
+ /** When true (default), options load on dropdown open / search instead of on mount. */
34
+ lazy?: boolean;
35
+ /**
36
+ * Key on the loaded form record with the related object or array of objects.
37
+ * Use when retrieve embeds relations, e.g. `source="branch_id"` + `recordSource="branch"`.
38
+ */
39
+ recordSource?: string;
40
+ /**
41
+ * When true (default), fetch labels for primitive ids via `getOne` if they are not
42
+ * already embedded in the form record. Set `false` to never call `getOne`.
43
+ */
44
+ fetchSelected?: boolean;
45
+ };
46
+
47
+ export type DisplayProps = {
48
+ display?: string | ((record: Record<string, unknown>) => ReactNode);
49
+ };
50
+
51
+ export type FieldRules = RegisterOptions;
52
+
53
+ export type ColumnDefinition<T extends Record<string, unknown>> = {
54
+ key: string;
55
+ source: string;
56
+ label?: string;
57
+ sortable?: boolean;
58
+ buildColumn: () => ColumnsType<T>[number];
59
+ };
60
+
61
+ export type FilterDefinition = {
62
+ key: string;
63
+ source: string;
64
+ label?: string;
65
+ render: (props: {
66
+ value: unknown;
67
+ onChange: (value: unknown) => void;
68
+ }) => ReactNode;
69
+ };
70
+
71
+ export type InlineFormSetBaseProps = {
72
+ /** RHF `useFieldArray` name and default API nested key, e.g. `"lines"`. */
73
+ field: string;
74
+ label?: string;
75
+ /** API key when different from `field`. */
76
+ payloadKey?: string;
77
+ transformRows?: (rows: Record<string, unknown>[]) => unknown;
78
+ };
79
+
80
+ /** Passed to each tabular inline column's `cell` renderer. */
81
+ export type InlineCellContext = {
82
+ /** Full RHF path, e.g. `lines.0.label`. */
83
+ name: string;
84
+ index: number;
85
+ field: string;
86
+ };
87
+
88
+ export type InlineColumnDef = {
89
+ source: string;
90
+ label?: string;
91
+ width?: number | string;
92
+ minWidth?: number | string;
93
+ cell: (ctx: InlineCellContext) => ReactNode;
94
+ };
95
+
96
+ /** Passed to `InlineFormSetStacked`'s `renderRow` for one related row. */
97
+ export type InlineRowContext = {
98
+ field: string;
99
+ index: number;
100
+ /** RHF path helper — `name("label")` → `field.index.label`. */
101
+ name: (source: string) => string;
102
+ };
103
+
104
+ export type EditMode = "page" | "modal" | "both";
105
+
106
+ /** Toggle built-in row actions. Omitted keys default to `true` (still gated by permissions). */
107
+ export type ResourceListBuiltInActions = {
108
+ edit?: boolean;
109
+ quickEdit?: boolean;
110
+ delete?: boolean;
111
+ };
112
+
113
+ export type ResourceListRowActionsHelpers = {
114
+ reload: () => void;
115
+ openEditModal: (id: string | number) => void;
116
+ };
117
+
118
+ export type ResourceListBulkActionHelpers = {
119
+ reload: () => void;
120
+ clearSelection: () => void;
121
+ };
122
+
123
+ /** Bulk list action (Django admin–style). Runs on selected row ids. */
124
+ export type ResourceListBulkAction = {
125
+ key: string;
126
+ label: string;
127
+ /** Optional confirmation message. Return false to cancel. */
128
+ confirm?:
129
+ | string
130
+ | ((
131
+ selectedIds: (string | number)[],
132
+ helpers: ResourceListBulkActionHelpers,
133
+ ) => string | false | Promise<string | false>);
134
+ execute: (
135
+ selectedIds: (string | number)[],
136
+ helpers: ResourceListBulkActionHelpers,
137
+ ) => void | Promise<void>;
138
+ };
139
+
140
+ export const LIST_QUERY_RESERVED = new Set([
141
+ "page",
142
+ "perPage",
143
+ "sort",
144
+ "create",
145
+ "edit",
146
+ ]);
@@ -1,24 +1,24 @@
1
- import { getFormValue } from "./getFormValue";
2
- import { setFormValue } from "./setFormValue";
3
-
4
- /**
5
- * Build the API save body from form values using registered field paths.
6
- * Flat `email` → `{ email }`; nested `address.city` → `{ address: { city } }`.
7
- */
8
- export function buildFormPayload(
9
- values: Record<string, unknown>,
10
- fieldPaths: string[],
11
- ): Record<string, unknown> {
12
- if (fieldPaths.length === 0) {
13
- return { ...values };
14
- }
15
-
16
- const result: Record<string, unknown> = {};
17
- for (const path of fieldPaths) {
18
- const value = getFormValue(values, path);
19
- if (value !== undefined) {
20
- setFormValue(result, path, value);
21
- }
22
- }
23
- return result;
24
- }
1
+ import { getFormValue } from "./getFormValue";
2
+ import { setFormValue } from "./setFormValue";
3
+
4
+ /**
5
+ * Build the API save body from form values using registered field paths.
6
+ * Flat `email` → `{ email }`; nested `address.city` → `{ address: { city } }`.
7
+ */
8
+ export function buildFormPayload(
9
+ values: Record<string, unknown>,
10
+ fieldPaths: string[],
11
+ ): Record<string, unknown> {
12
+ if (fieldPaths.length === 0) {
13
+ return { ...values };
14
+ }
15
+
16
+ const result: Record<string, unknown> = {};
17
+ for (const path of fieldPaths) {
18
+ const value = getFormValue(values, path);
19
+ if (value !== undefined) {
20
+ setFormValue(result, path, value);
21
+ }
22
+ }
23
+ return result;
24
+ }
@@ -1,37 +1,37 @@
1
- export type BuildInlineRowsPayloadOptions = {
2
- transformRows?: (rows: Record<string, unknown>[]) => unknown;
3
- };
4
-
5
- /** Clean inline field-array rows for the API (strip RHF `rowKey`, keep record `id`). */
6
- export function buildInlineRowsPayload(
7
- rows: unknown,
8
- sources: string[],
9
- options?: BuildInlineRowsPayloadOptions,
10
- ): unknown {
11
- if (!Array.isArray(rows)) return [];
12
-
13
- const cleaned = rows.map((row) => {
14
- if (!row || typeof row !== "object") return {};
15
- const record = row as Record<string, unknown>;
16
- const out: Record<string, unknown> = {};
17
-
18
- for (const source of sources) {
19
- const value = record[source];
20
- if (value !== undefined) {
21
- out[source] = value;
22
- }
23
- }
24
-
25
- const id = record.id;
26
- if (id !== undefined && id !== null) {
27
- out.id = id;
28
- }
29
-
30
- return out;
31
- });
32
-
33
- if (options?.transformRows) {
34
- return options.transformRows(cleaned);
35
- }
36
- return cleaned;
37
- }
1
+ export type BuildInlineRowsPayloadOptions = {
2
+ transformRows?: (rows: Record<string, unknown>[]) => unknown;
3
+ };
4
+
5
+ /** Clean inline field-array rows for the API (strip RHF `rowKey`, keep record `id`). */
6
+ export function buildInlineRowsPayload(
7
+ rows: unknown,
8
+ sources: string[],
9
+ options?: BuildInlineRowsPayloadOptions,
10
+ ): unknown {
11
+ if (!Array.isArray(rows)) return [];
12
+
13
+ const cleaned = rows.map((row) => {
14
+ if (!row || typeof row !== "object") return {};
15
+ const record = row as Record<string, unknown>;
16
+ const out: Record<string, unknown> = {};
17
+
18
+ for (const source of sources) {
19
+ const value = record[source];
20
+ if (value !== undefined) {
21
+ out[source] = value;
22
+ }
23
+ }
24
+
25
+ const id = record.id;
26
+ if (id !== undefined && id !== null) {
27
+ out.id = id;
28
+ }
29
+
30
+ return out;
31
+ });
32
+
33
+ if (options?.transformRows) {
34
+ return options.transformRows(cleaned);
35
+ }
36
+ return cleaned;
37
+ }