ding-react-admin 1.0.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +38 -13
  2. package/dist/index.js +1317 -1060
  3. package/dist/src/crud/InlineFormSet.d.ts +12 -25
  4. package/dist/src/crud/InlineFormSet.d.ts.map +1 -1
  5. package/dist/src/crud/ResourceForm.d.ts +7 -4
  6. package/dist/src/crud/ResourceForm.d.ts.map +1 -1
  7. package/dist/src/crud/ResourceFormModal.d.ts.map +1 -1
  8. package/dist/src/crud/ResourceList.d.ts.map +1 -1
  9. package/dist/src/crud/columns/ImageColumn.d.ts +14 -0
  10. package/dist/src/crud/columns/ImageColumn.d.ts.map +1 -0
  11. package/dist/src/crud/context/InlineFieldsRegistry.d.ts +15 -0
  12. package/dist/src/crud/context/InlineFieldsRegistry.d.ts.map +1 -0
  13. package/dist/src/crud/context/PayloadFieldsContext.d.ts +18 -0
  14. package/dist/src/crud/context/PayloadFieldsContext.d.ts.map +1 -0
  15. package/dist/src/crud/fields/BooleanField.d.ts +3 -1
  16. package/dist/src/crud/fields/BooleanField.d.ts.map +1 -1
  17. package/dist/src/crud/fields/DateField.d.ts +3 -1
  18. package/dist/src/crud/fields/DateField.d.ts.map +1 -1
  19. package/dist/src/crud/fields/FieldWrapper.d.ts +7 -14
  20. package/dist/src/crud/fields/FieldWrapper.d.ts.map +1 -1
  21. package/dist/src/crud/fields/FileField.d.ts +12 -0
  22. package/dist/src/crud/fields/FileField.d.ts.map +1 -0
  23. package/dist/src/crud/fields/ImageField.d.ts +14 -0
  24. package/dist/src/crud/fields/ImageField.d.ts.map +1 -0
  25. package/dist/src/crud/fields/NumberField.d.ts +5 -3
  26. package/dist/src/crud/fields/NumberField.d.ts.map +1 -1
  27. package/dist/src/crud/fields/PasswordField.d.ts +5 -3
  28. package/dist/src/crud/fields/PasswordField.d.ts.map +1 -1
  29. package/dist/src/crud/fields/ReferenceField.d.ts +6 -5
  30. package/dist/src/crud/fields/ReferenceField.d.ts.map +1 -1
  31. package/dist/src/crud/fields/ReferenceManyField.d.ts +3 -1
  32. package/dist/src/crud/fields/ReferenceManyField.d.ts.map +1 -1
  33. package/dist/src/crud/fields/SelectField.d.ts +3 -1
  34. package/dist/src/crud/fields/SelectField.d.ts.map +1 -1
  35. package/dist/src/crud/fields/TextField.d.ts +5 -3
  36. package/dist/src/crud/fields/TextField.d.ts.map +1 -1
  37. package/dist/src/crud/fields/uploadFieldUtils.d.ts +5 -0
  38. package/dist/src/crud/fields/uploadFieldUtils.d.ts.map +1 -0
  39. package/dist/src/crud/fields/useUploadPreviewUrl.d.ts +4 -0
  40. package/dist/src/crud/fields/useUploadPreviewUrl.d.ts.map +1 -0
  41. package/dist/src/crud/index.d.ts +26 -9
  42. package/dist/src/crud/index.d.ts.map +1 -1
  43. package/dist/src/crud/types.d.ts +23 -20
  44. package/dist/src/crud/types.d.ts.map +1 -1
  45. package/dist/src/crud/utils/buildFormPayload.d.ts +6 -0
  46. package/dist/src/crud/utils/buildFormPayload.d.ts.map +1 -0
  47. package/dist/src/crud/utils/buildInlineRowsPayload.d.ts +6 -0
  48. package/dist/src/crud/utils/buildInlineRowsPayload.d.ts.map +1 -0
  49. package/dist/src/crud/utils/buildResourceFormSubmitBody.d.ts +5 -0
  50. package/dist/src/crud/utils/buildResourceFormSubmitBody.d.ts.map +1 -0
  51. package/dist/src/crud/utils/formErrors.d.ts +1 -1
  52. package/dist/src/crud/utils/formErrors.d.ts.map +1 -1
  53. package/dist/src/crud/utils/getFormValue.d.ts +3 -0
  54. package/dist/src/crud/utils/getFormValue.d.ts.map +1 -0
  55. package/dist/src/crud/utils/hasUploadValues.d.ts +3 -0
  56. package/dist/src/crud/utils/hasUploadValues.d.ts.map +1 -0
  57. package/dist/src/crud/utils/nestedFieldPath.d.ts +3 -0
  58. package/dist/src/crud/utils/nestedFieldPath.d.ts.map +1 -0
  59. package/dist/src/crud/utils/prepareFormSubmitBody.d.ts +7 -0
  60. package/dist/src/crud/utils/prepareFormSubmitBody.d.ts.map +1 -0
  61. package/dist/src/crud/utils/setFormValue.d.ts +3 -0
  62. package/dist/src/crud/utils/setFormValue.d.ts.map +1 -0
  63. package/dist/src/crud/utils/toFormData.d.ts +13 -0
  64. package/dist/src/crud/utils/toFormData.d.ts.map +1 -0
  65. package/dist/src/crud/utils/useAbortableEffect.d.ts +7 -0
  66. package/dist/src/crud/utils/useAbortableEffect.d.ts.map +1 -0
  67. package/dist/src/crud/utils/useFormRecord.d.ts +42 -0
  68. package/dist/src/crud/utils/useFormRecord.d.ts.map +1 -0
  69. package/dist/src/data/abortError.d.ts +3 -0
  70. package/dist/src/data/abortError.d.ts.map +1 -0
  71. package/dist/src/data/abortError.test.d.ts +2 -0
  72. package/dist/src/data/abortError.test.d.ts.map +1 -0
  73. package/dist/src/data/createRestResourceHandlers.d.ts +6 -6
  74. package/dist/src/data/createRestResourceHandlers.d.ts.map +1 -1
  75. package/dist/src/data/dataProviderTypes.d.ts +13 -6
  76. package/dist/src/data/dataProviderTypes.d.ts.map +1 -1
  77. package/dist/src/data/parseFormErrorHelpers.d.ts +44 -6
  78. package/dist/src/data/parseFormErrorHelpers.d.ts.map +1 -1
  79. package/dist/src/data/resourceHandlers.d.ts +3 -3
  80. package/dist/src/data/resourceHandlers.d.ts.map +1 -1
  81. package/dist/src/index.d.ts +5 -4
  82. package/dist/src/index.d.ts.map +1 -1
  83. package/dist/src/layouts/AdminLayout.d.ts.map +1 -1
  84. package/package.json +59 -59
  85. package/src/crud/InlineFormSet.tsx +90 -159
  86. package/src/crud/ResourceForm.tsx +83 -204
  87. package/src/crud/ResourceFormModal.tsx +57 -45
  88. package/src/crud/ResourceList.tsx +36 -26
  89. package/src/crud/columns/ImageColumn.tsx +58 -0
  90. package/src/crud/columns/TextColumn.tsx +2 -2
  91. package/src/crud/context/InlineFieldsRegistry.tsx +61 -0
  92. package/src/crud/context/PayloadFieldsContext.tsx +62 -0
  93. package/src/crud/fields/BooleanField.tsx +22 -16
  94. package/src/crud/fields/DateField.tsx +32 -26
  95. package/src/crud/fields/FieldWrapper.tsx +87 -109
  96. package/src/crud/fields/FileField.tsx +123 -0
  97. package/src/crud/fields/ImageField.tsx +120 -0
  98. package/src/crud/fields/NumberField.tsx +36 -34
  99. package/src/crud/fields/PasswordField.tsx +41 -40
  100. package/src/crud/fields/ReferenceField.tsx +35 -130
  101. package/src/crud/fields/ReferenceManyField.tsx +31 -25
  102. package/src/crud/fields/SelectField.tsx +6 -0
  103. package/src/crud/fields/TextField.tsx +32 -30
  104. package/src/crud/fields/uploadFieldUtils.ts +21 -0
  105. package/src/crud/fields/useUploadPreviewUrl.ts +20 -0
  106. package/src/crud/index.ts +35 -14
  107. package/src/crud/types.ts +134 -130
  108. package/src/crud/utils/buildFormPayload.ts +24 -0
  109. package/src/crud/utils/buildInlineRowsPayload.ts +37 -0
  110. package/src/crud/utils/buildResourceFormSubmitBody.ts +29 -0
  111. package/src/crud/utils/formErrors.ts +42 -38
  112. package/src/crud/utils/{getByPath.ts → getFormValue.ts} +2 -2
  113. package/src/crud/utils/hasUploadValues.ts +9 -0
  114. package/src/crud/utils/nestedFieldPath.ts +8 -0
  115. package/src/crud/utils/prepareFormSubmitBody.ts +17 -0
  116. package/src/crud/utils/{setByPath.ts → setFormValue.ts} +2 -2
  117. package/src/crud/utils/toFormData.ts +81 -0
  118. package/src/crud/utils/useAbortableEffect.ts +17 -0
  119. package/src/crud/utils/useFormRecord.ts +156 -0
  120. package/src/data/abortError.test.ts +19 -0
  121. package/src/data/abortError.ts +10 -0
  122. package/src/data/createMemoryResourceHandlers.ts +1 -1
  123. package/src/data/createRestResourceHandlers.ts +22 -16
  124. package/src/data/dataProviderTypes.ts +15 -5
  125. package/src/data/dataUtils.test.ts +118 -6
  126. package/src/data/parseFormErrorHelpers.test.ts +138 -84
  127. package/src/data/parseFormErrorHelpers.ts +311 -224
  128. package/src/data/resourceHandlers.ts +5 -4
  129. package/src/index.ts +34 -9
  130. package/src/layouts/AdminLayout.tsx +2 -1
  131. package/dist/src/crud/context/FormFieldsContext.d.ts +0 -14
  132. package/dist/src/crud/context/FormFieldsContext.d.ts.map +0 -1
  133. package/dist/src/crud/context/InlineFormContext.d.ts +0 -16
  134. package/dist/src/crud/context/InlineFormContext.d.ts.map +0 -1
  135. package/dist/src/crud/fields/useInlineOrFormField.d.ts +0 -10
  136. package/dist/src/crud/fields/useInlineOrFormField.d.ts.map +0 -1
  137. package/dist/src/crud/utils/getByPath.d.ts +0 -3
  138. package/dist/src/crud/utils/getByPath.d.ts.map +0 -1
  139. package/dist/src/crud/utils/inlineArrayName.d.ts +0 -3
  140. package/dist/src/crud/utils/inlineArrayName.d.ts.map +0 -1
  141. package/dist/src/crud/utils/pickBySources.d.ts +0 -6
  142. package/dist/src/crud/utils/pickBySources.d.ts.map +0 -1
  143. package/dist/src/crud/utils/setByPath.d.ts +0 -3
  144. package/dist/src/crud/utils/setByPath.d.ts.map +0 -1
  145. package/src/crud/context/FormFieldsContext.tsx +0 -76
  146. package/src/crud/context/InlineFormContext.tsx +0 -71
  147. package/src/crud/fields/useInlineOrFormField.tsx +0 -91
  148. package/src/crud/utils/inlineArrayName.ts +0 -4
  149. package/src/crud/utils/pickBySources.ts +0 -24
package/src/index.ts CHANGED
@@ -28,6 +28,7 @@ export type {
28
28
  DeleteResult,
29
29
  GetListParams,
30
30
  GetListResult,
31
+ GetOneParams,
31
32
  GetOneResult,
32
33
  Identifier,
33
34
  PaginationParams,
@@ -36,17 +37,20 @@ export type {
36
37
  UpdateParams,
37
38
  UpdateResult,
38
39
  FormMutation,
40
+ FormMutationBody,
39
41
  FormValidationErrors,
40
42
  ParseFormError,
41
43
  ParseFormErrorContext,
42
44
  } from "./data/dataProviderTypes";
43
45
  export { combineResourceHandlers } from "./data/resourceHandlers";
46
+ export { isAbortError } from "./data/abortError";
44
47
  export {
45
48
  parseDjangoDRFFormErrors,
46
49
  parseDotNetFormErrors,
47
50
  parseNodeFormErrors,
48
51
  getErrorBody,
49
- applyInlineFieldPaths,
52
+ resolveErrorBody,
53
+ flattenNestedArrayErrors,
50
54
  asStringMessages,
51
55
  finalizeFormErrors,
52
56
  } from "./data/parseFormErrorHelpers";
@@ -118,12 +122,11 @@ export {
118
122
  ResourceForm,
119
123
  ResourceFormModal,
120
124
  InlineFormSet,
125
+ InlineFormSetStacked,
121
126
  FormTabs,
122
127
  FormTab,
123
128
  FormSteps,
124
129
  FormStep,
125
- saveInlineRows,
126
- loadInlineRows,
127
130
  TextField,
128
131
  NumberField,
129
132
  BooleanField,
@@ -132,12 +135,16 @@ export {
132
135
  PasswordField,
133
136
  ReferenceField,
134
137
  ReferenceManyField,
138
+ ImageField,
139
+ FileField,
140
+ FieldWrapper,
135
141
  TextColumn,
136
142
  NumberColumn,
137
143
  BooleanColumn,
138
144
  DateColumn,
139
145
  ReferenceColumn,
140
146
  ReferenceManyColumn,
147
+ ImageColumn,
141
148
  CustomColumn,
142
149
  TextFilter,
143
150
  NumberFilter,
@@ -148,22 +155,29 @@ export {
148
155
  ReferenceManyFilter,
149
156
  useListQueryState,
150
157
  useChoices,
151
- getByPath,
152
- pickBySources,
153
- inlineArrayName,
158
+ useAbortableEffect,
159
+ getFormValue,
160
+ setFormValue,
161
+ buildFormPayload,
162
+ buildInlineRowsPayload,
163
+ buildResourceFormSubmitBody,
164
+ prepareFormSubmitBody,
165
+ toFormData,
166
+ hasUploadValues,
167
+ nestedFieldPath,
154
168
  useResourceListContext,
155
- useRegisterFormSource,
169
+ useRegisterPayloadField,
170
+ useRegisterSectionField,
156
171
  } from "./crud";
157
172
  export type {
158
173
  ResourceFormProps,
159
- ResourceFormInlineConfig,
160
174
  ResourceFormModalProps,
161
175
  InlineFormSetProps,
176
+ InlineFormSetStackedProps,
162
177
  FormTabsProps,
163
178
  FormTabProps,
164
179
  FormStepsProps,
165
180
  FormStepProps,
166
- SaveInlineOptions,
167
181
  InlineFormSetLayout,
168
182
  ResourceListProps,
169
183
  BaseSourceProps,
@@ -173,6 +187,17 @@ export type {
173
187
  DisplayProps,
174
188
  EditMode,
175
189
  FieldRules,
190
+ InlineCellContext,
191
+ InlineColumnDef,
192
+ InlineFormSetBaseProps,
193
+ InlineRowContext,
194
+ InlineFieldRegistration,
195
+ FieldWrapperProps,
196
+ ImageFieldProps,
197
+ FileFieldProps,
198
+ UploadFieldValue,
199
+ ToFormDataOptions,
200
+ PrepareFormSubmitBodyOptions,
176
201
  ResourceListBuiltInActions,
177
202
  ResourceListBulkAction,
178
203
  ResourceListBulkActionHelpers,
@@ -321,7 +321,7 @@ export function AdminLayout({
321
321
  />
322
322
  </Drawer>
323
323
  )}
324
- <Layout>
324
+ <Layout style={{ minWidth: 0 }}>
325
325
  <Layout.Header
326
326
  style={{
327
327
  background: token.colorBgContainer,
@@ -371,6 +371,7 @@ export function AdminLayout({
371
371
  <Layout.Content
372
372
  style={{
373
373
  margin: isMobile ? token.marginSM : token.marginLG,
374
+ minWidth: 0,
374
375
  }}
375
376
  >
376
377
  <Outlet />
@@ -1,14 +0,0 @@
1
- import { MutableRefObject, ReactNode } from 'react';
2
- type FormFieldsContextValue = {
3
- registerSource: (source: string) => () => void;
4
- getSources: () => string[];
5
- };
6
- export declare function FormFieldsProvider({ children, sourcesRef: externalSourcesRef, }: {
7
- children: ReactNode;
8
- /** Optional ref shared with submit handler outside this provider. */
9
- sourcesRef?: MutableRefObject<Set<string>>;
10
- }): import("react/jsx-runtime").JSX.Element;
11
- export declare function useFormFieldsOptional(): FormFieldsContextValue | null;
12
- export declare function useRegisterFormSource(source: string): void;
13
- export {};
14
- //# sourceMappingURL=FormFieldsContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormFieldsContext.d.ts","sourceRoot":"","sources":["../../../../src/crud/context/FormFieldsContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAGf,KAAK,sBAAsB,GAAG;IAC5B,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,IAAI,CAAC;IAC/C,UAAU,EAAE,MAAM,MAAM,EAAE,CAAC;CAC5B,CAAC;AAIF,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,UAAU,EAAE,kBAAkB,GAC/B,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,qEAAqE;IACrE,UAAU,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;CAC5C,2CA6BA;AAED,wBAAgB,qBAAqB,kCAEpC;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,QAcnD"}
@@ -1,16 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { InlineFieldDefinition } from '../types';
3
- export type InlineFormSetLayout = "tabular" | "stacked";
4
- export declare function InlineFormSetProvider({ children, arrayName, layout, }: {
5
- children: ReactNode;
6
- arrayName: string;
7
- layout?: InlineFormSetLayout;
8
- }): import("react/jsx-runtime").JSX.Element;
9
- export declare function useInlineFormSetContext(): {
10
- fields: InlineFieldDefinition[];
11
- registerField: (def: InlineFieldDefinition) => () => void;
12
- arrayName: string;
13
- layout: InlineFormSetLayout;
14
- } | null;
15
- export declare function useRegisterInlineField(def: InlineFieldDefinition): void;
16
- //# sourceMappingURL=InlineFormContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InlineFormContext.d.ts","sourceRoot":"","sources":["../../../../src/crud/context/InlineFormContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEtD,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,SAAS,CAAC;AAWxD,wBAAgB,qBAAqB,CAAC,EACpC,QAAQ,EACR,SAAS,EACT,MAAkB,GACnB,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B,2CAyBA;AAED,wBAAgB,uBAAuB;;mBA3CtB,CAAC,GAAG,EAAE,qBAAqB,KAAK,MAAM,IAAI;eAC9C,MAAM;YACT,mBAAmB;SA8C5B;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,qBAAqB,QAMhE"}
@@ -1,10 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { FieldRenderProps, FieldRules, InlineFieldOptions } from '../types';
3
- export declare function useInlineOrFormField(source: string, label: string | undefined, required: boolean | undefined, rules: FieldRules | undefined, renderInput: (props: FieldRenderProps) => ReactNode, inlineOptions?: InlineFieldOptions): {
4
- mode: "inline";
5
- element?: undefined;
6
- } | {
7
- mode: "form";
8
- element: import("react/jsx-runtime").JSX.Element;
9
- };
10
- //# sourceMappingURL=useInlineOrFormField.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useInlineOrFormField.d.ts","sourceRoot":"","sources":["../../../../src/crud/fields/useInlineOrFormField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEnE,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EAEV,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAGlB,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,OAAO,GAAG,SAAS,EAC7B,KAAK,EAAE,UAAU,GAAG,SAAS,EAC7B,WAAW,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,SAAS,EACnD,aAAa,CAAC,EAAE,kBAAkB;;;;;;EA0EnC"}
@@ -1,3 +0,0 @@
1
- /** Read nested value from a record using dot notation, e.g. `brand.name`. */
2
- export declare function getByPath(record: Record<string, unknown>, path: string): unknown;
3
- //# sourceMappingURL=getByPath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getByPath.d.ts","sourceRoot":"","sources":["../../../../src/crud/utils/getByPath.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,IAAI,EAAE,MAAM,GACX,OAAO,CAQT"}
@@ -1,3 +0,0 @@
1
- /** Shared field-array name for InlineFormSet + ResourceForm inline loading. */
2
- export declare function inlineArrayName(resource: string, name?: string): string;
3
- //# sourceMappingURL=inlineArrayName.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inlineArrayName.d.ts","sourceRoot":"","sources":["../../../../src/crud/utils/inlineArrayName.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,UAE9D"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Build a submit payload from form values using declared field `source` paths.
3
- * Flat `username` → `{ username }`; nested `invoiceLine.product` → `{ invoiceLine: { product } }`.
4
- */
5
- export declare function pickBySources(values: Record<string, unknown>, sources: string[]): Record<string, unknown>;
6
- //# sourceMappingURL=pickBySources.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pickBySources.d.ts","sourceRoot":"","sources":["../../../../src/crud/utils/pickBySources.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,MAAM,EAAE,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB"}
@@ -1,3 +0,0 @@
1
- /** Write a value into a record using dot notation, e.g. `invoiceLine.product`. */
2
- export declare function setByPath(record: Record<string, unknown>, path: string, value: unknown): void;
3
- //# sourceMappingURL=setByPath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setByPath.d.ts","sourceRoot":"","sources":["../../../../src/crud/utils/setByPath.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,IAAI,CAYN"}
@@ -1,76 +0,0 @@
1
- import {
2
- createContext,
3
- useCallback,
4
- useContext,
5
- useEffect,
6
- useMemo,
7
- useRef,
8
- type MutableRefObject,
9
- type ReactNode,
10
- } from "react";
11
- import { useFormSectionSourcesOptional } from "./FormSectionContext";
12
-
13
- type FormFieldsContextValue = {
14
- registerSource: (source: string) => () => void;
15
- getSources: () => string[];
16
- };
17
-
18
- const FormFieldsContext = createContext<FormFieldsContextValue | null>(null);
19
-
20
- export function FormFieldsProvider({
21
- children,
22
- sourcesRef: externalSourcesRef,
23
- }: {
24
- children: ReactNode;
25
- /** Optional ref shared with submit handler outside this provider. */
26
- sourcesRef?: MutableRefObject<Set<string>>;
27
- }) {
28
- const internalSourcesRef = useRef(new Set<string>());
29
- const sourcesRef = externalSourcesRef ?? internalSourcesRef;
30
-
31
- const registerSource = useCallback(
32
- (source: string) => {
33
- sourcesRef.current.add(source);
34
- return () => {
35
- sourcesRef.current.delete(source);
36
- };
37
- },
38
- [sourcesRef],
39
- );
40
-
41
- const getSources = useCallback(
42
- () => Array.from(sourcesRef.current),
43
- [sourcesRef],
44
- );
45
-
46
- const value = useMemo(
47
- () => ({ registerSource, getSources }),
48
- [registerSource, getSources],
49
- );
50
-
51
- return (
52
- <FormFieldsContext.Provider value={value}>
53
- {children}
54
- </FormFieldsContext.Provider>
55
- );
56
- }
57
-
58
- export function useFormFieldsOptional() {
59
- return useContext(FormFieldsContext);
60
- }
61
-
62
- export function useRegisterFormSource(source: string) {
63
- const ctx = useFormFieldsOptional();
64
- const registerSource = ctx?.registerSource;
65
- const sectionSourcesRef = useFormSectionSourcesOptional();
66
-
67
- useEffect(() => {
68
- if (!registerSource) return;
69
- const unregister = registerSource(source);
70
- sectionSourcesRef?.current.add(source);
71
- return () => {
72
- unregister();
73
- sectionSourcesRef?.current.delete(source);
74
- };
75
- }, [registerSource, sectionSourcesRef, source]);
76
- }
@@ -1,71 +0,0 @@
1
- import {
2
- createContext,
3
- useCallback,
4
- useContext,
5
- useEffect,
6
- useMemo,
7
- useState,
8
- type ReactNode,
9
- } from "react";
10
- import type { InlineFieldDefinition } from "../types";
11
-
12
- export type InlineFormSetLayout = "tabular" | "stacked";
13
-
14
- type InlineFormSetMeta = {
15
- registerField: (def: InlineFieldDefinition) => () => void;
16
- arrayName: string;
17
- layout: InlineFormSetLayout;
18
- };
19
-
20
- const InlineFormSetMetaContext = createContext<InlineFormSetMeta | null>(null);
21
- const InlineFormSetFieldsContext = createContext<InlineFieldDefinition[]>([]);
22
-
23
- export function InlineFormSetProvider({
24
- children,
25
- arrayName,
26
- layout = "tabular",
27
- }: {
28
- children: ReactNode;
29
- arrayName: string;
30
- layout?: InlineFormSetLayout;
31
- }) {
32
- const [fields, setFields] = useState<InlineFieldDefinition[]>([]);
33
-
34
- const registerField = useCallback((def: InlineFieldDefinition) => {
35
- setFields((prev) => {
36
- if (prev.some((f) => f.key === def.key)) return prev;
37
- return [...prev, def];
38
- });
39
- return () => {
40
- setFields((prev) => prev.filter((f) => f.key !== def.key));
41
- };
42
- }, []);
43
-
44
- const meta = useMemo(
45
- (): InlineFormSetMeta => ({ arrayName, registerField, layout }),
46
- [arrayName, registerField, layout],
47
- );
48
-
49
- return (
50
- <InlineFormSetMetaContext.Provider value={meta}>
51
- <InlineFormSetFieldsContext.Provider value={fields}>
52
- {children}
53
- </InlineFormSetFieldsContext.Provider>
54
- </InlineFormSetMetaContext.Provider>
55
- );
56
- }
57
-
58
- export function useInlineFormSetContext() {
59
- const meta = useContext(InlineFormSetMetaContext);
60
- const fields = useContext(InlineFormSetFieldsContext);
61
- if (!meta) return null;
62
- return { ...meta, fields };
63
- }
64
-
65
- export function useRegisterInlineField(def: InlineFieldDefinition) {
66
- const registerField = useContext(InlineFormSetMetaContext)?.registerField;
67
- useEffect(() => {
68
- if (!registerField) return;
69
- return registerField(def);
70
- }, [registerField, def]);
71
- }
@@ -1,91 +0,0 @@
1
- import { useEffect, useMemo, useRef, type ReactNode } from "react";
2
- import { useInlineFormSetContext } from "../context/InlineFormContext";
3
- import type {
4
- FieldRenderProps,
5
- FieldRules,
6
- InlineFieldDefinition,
7
- InlineFieldOptions,
8
- } from "../types";
9
- import { FieldWrapper, InlineFieldWrapper } from "./FieldWrapper";
10
-
11
- export function useInlineOrFormField(
12
- source: string,
13
- label: string | undefined,
14
- required: boolean | undefined,
15
- rules: FieldRules | undefined,
16
- renderInput: (props: FieldRenderProps) => ReactNode,
17
- inlineOptions?: InlineFieldOptions,
18
- ) {
19
- const inlineCtx = useInlineFormSetContext();
20
- const registerField = inlineCtx?.registerField;
21
- const isInline = registerField != null;
22
- const renderInputRef = useRef(renderInput);
23
- renderInputRef.current = renderInput;
24
-
25
- const inlineDef = useMemo((): InlineFieldDefinition | null => {
26
- if (!registerField) return null;
27
- return {
28
- key: source,
29
- source,
30
- label,
31
- width: inlineOptions?.width,
32
- minWidth: inlineOptions?.minWidth,
33
- render: ({ name, index }) => (
34
- <InlineFieldWrapper
35
- name={name}
36
- label={label}
37
- required={required}
38
- rules={rules}
39
- hideLabel={inlineCtx?.layout !== "stacked"}
40
- >
41
- {({ value, onChange, onBlur }) =>
42
- renderInputRef.current({
43
- value,
44
- onChange,
45
- onBlur,
46
- name,
47
- index,
48
- })
49
- }
50
- </InlineFieldWrapper>
51
- ),
52
- };
53
- }, [
54
- registerField,
55
- source,
56
- label,
57
- required,
58
- rules,
59
- inlineCtx?.layout,
60
- inlineOptions?.width,
61
- inlineOptions?.minWidth,
62
- ]);
63
-
64
- const inlineDefRef = useRef(inlineDef);
65
- inlineDefRef.current = inlineDef;
66
-
67
- useEffect(() => {
68
- if (!registerField) return;
69
- const def = inlineDefRef.current;
70
- if (!def) return;
71
- return registerField(def);
72
- }, [registerField, source]);
73
-
74
- if (isInline) return { mode: "inline" as const };
75
-
76
- return {
77
- mode: "form" as const,
78
- element: (
79
- <FieldWrapper
80
- source={source}
81
- label={label}
82
- required={required}
83
- rules={rules}
84
- >
85
- {({ value, onChange, onBlur, disabled }) =>
86
- renderInput({ value, onChange, onBlur, disabled })
87
- }
88
- </FieldWrapper>
89
- ),
90
- };
91
- }
@@ -1,4 +0,0 @@
1
- /** Shared field-array name for InlineFormSet + ResourceForm inline loading. */
2
- export function inlineArrayName(resource: string, name?: string) {
3
- return name ?? `__inline_${resource.replace(/[^a-z0-9]/gi, "_")}`;
4
- }
@@ -1,24 +0,0 @@
1
- import { getByPath } from "./getByPath";
2
- import { setByPath } from "./setByPath";
3
-
4
- /**
5
- * Build a submit payload from form values using declared field `source` paths.
6
- * Flat `username` → `{ username }`; nested `invoiceLine.product` → `{ invoiceLine: { product } }`.
7
- */
8
- export function pickBySources(
9
- values: Record<string, unknown>,
10
- sources: string[],
11
- ): Record<string, unknown> {
12
- if (sources.length === 0) {
13
- return { ...values };
14
- }
15
-
16
- const result: Record<string, unknown> = {};
17
- for (const source of sources) {
18
- const value = getByPath(values, source);
19
- if (value !== undefined) {
20
- setByPath(result, source, value);
21
- }
22
- }
23
- return result;
24
- }