@donotdev/crud 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/dist/CrudService.bulk.d.ts +13 -14
  2. package/dist/CrudService.bulk.d.ts.map +1 -1
  3. package/dist/CrudService.bulk.js +1 -1
  4. package/dist/CrudService.bulkAcross.d.ts +12 -7
  5. package/dist/CrudService.bulkAcross.d.ts.map +1 -1
  6. package/dist/CrudService.bulkAcross.js +1 -1
  7. package/dist/CrudService.bulkReconciliation.d.ts +4 -0
  8. package/dist/CrudService.bulkReconciliation.d.ts.map +1 -0
  9. package/dist/CrudService.bulkReconciliation.js +1 -0
  10. package/dist/CrudService.cache.d.ts +1 -1
  11. package/dist/CrudService.cache.d.ts.map +1 -1
  12. package/dist/CrudService.cache.js +1 -1
  13. package/dist/CrudService.d.ts +35 -6
  14. package/dist/CrudService.d.ts.map +1 -1
  15. package/dist/CrudService.js +1 -1
  16. package/dist/CrudService.mutations.d.ts +3 -3
  17. package/dist/CrudService.mutations.d.ts.map +1 -1
  18. package/dist/CrudService.mutations.js +1 -1
  19. package/dist/CrudService.optimistic.d.ts +2 -2
  20. package/dist/CrudService.optimistic.d.ts.map +1 -1
  21. package/dist/CrudService.optimistic.js +1 -1
  22. package/dist/CrudService.subscriptions.js +1 -1
  23. package/dist/CrudService.writeRules.d.ts +57 -0
  24. package/dist/CrudService.writeRules.d.ts.map +1 -0
  25. package/dist/CrudService.writeRules.js +1 -0
  26. package/dist/CrudService.writeSchema.d.ts +64 -0
  27. package/dist/CrudService.writeSchema.d.ts.map +1 -0
  28. package/dist/CrudService.writeSchema.js +1 -0
  29. package/dist/CrudStore.d.ts +10 -1
  30. package/dist/CrudStore.d.ts.map +1 -1
  31. package/dist/CrudStore.js +1 -1
  32. package/dist/FieldRegistry.d.ts +1 -1
  33. package/dist/FieldRegistry.d.ts.map +1 -1
  34. package/dist/adapters/FunctionsAdapter.d.ts +3 -3
  35. package/dist/adapters/FunctionsAdapter.d.ts.map +1 -1
  36. package/dist/adapters/FunctionsAdapter.js +1 -1
  37. package/dist/components/CrudButton.d.ts +3 -2
  38. package/dist/components/CrudButton.d.ts.map +1 -1
  39. package/dist/components/CrudCard.d.ts.map +1 -1
  40. package/dist/components/CrudCard.js +1 -1
  41. package/dist/components/DateFilter.js +1 -1
  42. package/dist/components/EntityFilters.d.ts +23 -4
  43. package/dist/components/EntityFilters.d.ts.map +1 -1
  44. package/dist/components/EntityFilters.js +1 -1
  45. package/dist/components/FormFieldRenderer.d.ts +21 -4
  46. package/dist/components/FormFieldRenderer.d.ts.map +1 -1
  47. package/dist/components/FormFieldRenderer.js +1 -1
  48. package/dist/components/FormLayout.d.ts.map +1 -1
  49. package/dist/components/FormLayout.js +1 -1
  50. package/dist/components/SortableCardList.d.ts +47 -0
  51. package/dist/components/SortableCardList.d.ts.map +1 -0
  52. package/dist/components/SortableCardList.js +1 -0
  53. package/dist/components/YearFilter.js +1 -1
  54. package/dist/components/controlled/complex/ControlledAddressField.d.ts.map +1 -1
  55. package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
  56. package/dist/components/controlled/complex/ControlledDateField.d.ts.map +1 -1
  57. package/dist/components/controlled/complex/ControlledDateField.js +1 -1
  58. package/dist/components/controlled/complex/ControlledFieldArrayField.d.ts +9 -0
  59. package/dist/components/controlled/complex/ControlledFieldArrayField.d.ts.map +1 -1
  60. package/dist/components/controlled/complex/ControlledFieldArrayField.js +1 -1
  61. package/dist/components/controlled/complex/ControlledMultiInputField.d.ts.map +1 -1
  62. package/dist/components/controlled/complex/ControlledMultiInputField.js +1 -1
  63. package/dist/components/controlled/complex/ControlledTimestampField.d.ts.map +1 -1
  64. package/dist/components/controlled/complex/ControlledTimestampField.js +1 -1
  65. package/dist/components/controlled/fieldOptions.d.ts +9 -0
  66. package/dist/components/controlled/fieldOptions.d.ts.map +1 -1
  67. package/dist/components/controlled/fieldOptions.js +1 -1
  68. package/dist/components/controlled/file/ControlledImageField.js +1 -1
  69. package/dist/components/controlled/input/ControlledCurrencyField.d.ts.map +1 -1
  70. package/dist/components/controlled/input/ControlledCurrencyField.js +1 -1
  71. package/dist/components/controlled/input/ControlledDurationField.js +1 -1
  72. package/dist/components/controlled/input/ControlledNumberField.d.ts.map +1 -1
  73. package/dist/components/controlled/input/ControlledNumberField.js +1 -1
  74. package/dist/components/controlled/input/ControlledPasswordField.d.ts.map +1 -1
  75. package/dist/components/controlled/input/ControlledPasswordField.js +1 -1
  76. package/dist/components/controlled/input/ControlledPhoneField.d.ts.map +1 -1
  77. package/dist/components/controlled/input/ControlledPhoneField.js +1 -1
  78. package/dist/components/controlled/input/ControlledPriceField.d.ts.map +1 -1
  79. package/dist/components/controlled/input/ControlledPriceField.js +1 -1
  80. package/dist/components/controlled/input/ControlledRatingField.js +1 -1
  81. package/dist/components/controlled/input/ControlledTextField.d.ts.map +1 -1
  82. package/dist/components/controlled/input/ControlledTextField.js +1 -1
  83. package/dist/components/controlled/input/ControlledTextareaField.d.ts.map +1 -1
  84. package/dist/components/controlled/input/ControlledTextareaField.js +1 -1
  85. package/dist/components/controlled/select/ControlledComboboxField.d.ts.map +1 -1
  86. package/dist/components/controlled/select/ControlledComboboxField.js +1 -1
  87. package/dist/components/controlled/select/ControlledDropdownField.d.ts.map +1 -1
  88. package/dist/components/controlled/select/ControlledDropdownField.js +1 -1
  89. package/dist/components/controlled/select/ControlledMultiDropdownField.d.ts.map +1 -1
  90. package/dist/components/controlled/select/ControlledMultiDropdownField.js +1 -1
  91. package/dist/components/controlled/select/ControlledReferenceField.d.ts.map +1 -1
  92. package/dist/components/controlled/select/ControlledReferenceField.js +1 -1
  93. package/dist/components/controlled/select/ControlledYearField.d.ts.map +1 -1
  94. package/dist/components/controlled/select/ControlledYearField.js +1 -1
  95. package/dist/components/fields/display/BadgeFieldDisplay.js +1 -1
  96. package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -1
  97. package/dist/components/fields/display/MapFieldDisplay.js +1 -1
  98. package/dist/components/fields/display/NumberFieldDisplay.js +1 -1
  99. package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
  100. package/dist/components/fields/display/TextFieldDisplay.js +1 -1
  101. package/dist/components/form/fields/AddressFieldComponent.d.ts +3 -1
  102. package/dist/components/form/fields/AddressFieldComponent.d.ts.map +1 -1
  103. package/dist/components/form/fields/AddressFieldComponent.js +1 -1
  104. package/dist/components/form/fields/ComboboxComponent.d.ts +2 -0
  105. package/dist/components/form/fields/ComboboxComponent.d.ts.map +1 -1
  106. package/dist/components/form/fields/ComboboxComponent.js +1 -1
  107. package/dist/components/form/fields/CurrencyFieldComponent.d.ts +2 -0
  108. package/dist/components/form/fields/CurrencyFieldComponent.d.ts.map +1 -1
  109. package/dist/components/form/fields/CurrencyFieldComponent.js +1 -1
  110. package/dist/components/form/fields/DateFieldComponent.d.ts +2 -0
  111. package/dist/components/form/fields/DateFieldComponent.d.ts.map +1 -1
  112. package/dist/components/form/fields/DateFieldComponent.js +1 -1
  113. package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
  114. package/dist/components/form/fields/DropdownComponent.d.ts +2 -0
  115. package/dist/components/form/fields/DropdownComponent.d.ts.map +1 -1
  116. package/dist/components/form/fields/DropdownComponent.js +1 -1
  117. package/dist/components/form/fields/DurationFieldComponent.d.ts.map +1 -1
  118. package/dist/components/form/fields/DurationFieldComponent.js +1 -1
  119. package/dist/components/form/fields/FileFieldComponent.js +1 -1
  120. package/dist/components/form/fields/GdprConsentFieldComponent.d.ts.map +1 -1
  121. package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -1
  122. package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
  123. package/dist/components/form/fields/ImageFieldComponent.d.ts.map +1 -1
  124. package/dist/components/form/fields/ImageFieldComponent.js +1 -1
  125. package/dist/components/form/fields/MultiDropdownComponent.d.ts +2 -0
  126. package/dist/components/form/fields/MultiDropdownComponent.d.ts.map +1 -1
  127. package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
  128. package/dist/components/form/fields/MultiInputTextFieldComponent.d.ts +2 -0
  129. package/dist/components/form/fields/MultiInputTextFieldComponent.d.ts.map +1 -1
  130. package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
  131. package/dist/components/form/fields/NumberFieldComponent.d.ts +2 -0
  132. package/dist/components/form/fields/NumberFieldComponent.d.ts.map +1 -1
  133. package/dist/components/form/fields/NumberFieldComponent.js +1 -1
  134. package/dist/components/form/fields/PasswordFieldComponent.d.ts +2 -0
  135. package/dist/components/form/fields/PasswordFieldComponent.d.ts.map +1 -1
  136. package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
  137. package/dist/components/form/fields/PhoneNumberComponent.d.ts +11 -1
  138. package/dist/components/form/fields/PhoneNumberComponent.d.ts.map +1 -1
  139. package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
  140. package/dist/components/form/fields/PriceFieldComponent.d.ts +2 -0
  141. package/dist/components/form/fields/PriceFieldComponent.d.ts.map +1 -1
  142. package/dist/components/form/fields/PriceFieldComponent.js +1 -1
  143. package/dist/components/form/fields/RangeFieldComponent.js +1 -1
  144. package/dist/components/form/fields/ReferenceFieldComponent.d.ts +3 -1
  145. package/dist/components/form/fields/ReferenceFieldComponent.d.ts.map +1 -1
  146. package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
  147. package/dist/components/form/fields/RichTextComponent.js +1 -1
  148. package/dist/components/form/fields/TextAreaComponent.d.ts +2 -0
  149. package/dist/components/form/fields/TextAreaComponent.d.ts.map +1 -1
  150. package/dist/components/form/fields/TextAreaComponent.js +1 -1
  151. package/dist/components/form/fields/TextFieldComponent.d.ts +3 -1
  152. package/dist/components/form/fields/TextFieldComponent.d.ts.map +1 -1
  153. package/dist/components/form/fields/TextFieldComponent.js +1 -1
  154. package/dist/components/form/fields/TimestampFieldComponent.d.ts +2 -0
  155. package/dist/components/form/fields/TimestampFieldComponent.d.ts.map +1 -1
  156. package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
  157. package/dist/components/index.d.ts +2 -0
  158. package/dist/components/index.d.ts.map +1 -1
  159. package/dist/components/index.js +1 -1
  160. package/dist/fieldTypeRegistry.d.ts +2 -2
  161. package/dist/fieldTypeRegistry.d.ts.map +1 -1
  162. package/dist/fieldTypeRegistry.js +1 -1
  163. package/dist/fieldTypeRegistry.store.d.ts +0 -2
  164. package/dist/fieldTypeRegistry.store.d.ts.map +1 -1
  165. package/dist/fieldTypeRegistry.store.js +1 -1
  166. package/dist/fieldTypeRegistry.types.d.ts +8 -9
  167. package/dist/fieldTypeRegistry.types.d.ts.map +1 -1
  168. package/dist/forms/FormNavigation.d.ts +24 -0
  169. package/dist/forms/FormNavigation.d.ts.map +1 -0
  170. package/dist/forms/FormNavigation.js +1 -0
  171. package/dist/forms/childRows.d.ts +184 -0
  172. package/dist/forms/childRows.d.ts.map +1 -0
  173. package/dist/forms/childRows.js +1 -0
  174. package/dist/forms/extend.d.ts +88 -0
  175. package/dist/forms/extend.d.ts.map +1 -0
  176. package/dist/forms/extend.js +1 -0
  177. package/dist/forms/hooks/useEntityField.d.ts +11 -5
  178. package/dist/forms/hooks/useEntityField.d.ts.map +1 -1
  179. package/dist/forms/hooks/useEntityField.js +1 -1
  180. package/dist/forms/hooks/useEntityForm.d.ts +50 -5
  181. package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
  182. package/dist/forms/hooks/useEntityForm.js +1 -1
  183. package/dist/forms/hooks/useFormDraftState.d.ts +53 -0
  184. package/dist/forms/hooks/useFormDraftState.d.ts.map +1 -0
  185. package/dist/forms/hooks/useFormDraftState.js +1 -0
  186. package/dist/forms/index.d.ts +6 -2
  187. package/dist/forms/index.d.ts.map +1 -1
  188. package/dist/forms/index.js +1 -1
  189. package/dist/forms/types.d.ts +171 -25
  190. package/dist/forms/types.d.ts.map +1 -1
  191. package/dist/forms/utils/buildInitialValues.d.ts +32 -17
  192. package/dist/forms/utils/buildInitialValues.d.ts.map +1 -1
  193. package/dist/forms/utils/buildInitialValues.js +1 -1
  194. package/dist/forms/utils/conditionAwareResolver.d.ts +35 -0
  195. package/dist/forms/utils/conditionAwareResolver.d.ts.map +1 -0
  196. package/dist/forms/utils/conditionAwareResolver.js +1 -0
  197. package/dist/forms/utils/emptyValue.d.ts +34 -0
  198. package/dist/forms/utils/emptyValue.d.ts.map +1 -0
  199. package/dist/forms/utils/emptyValue.js +1 -0
  200. package/dist/forms/utils/getFieldsForOperation.d.ts +30 -19
  201. package/dist/forms/utils/getFieldsForOperation.d.ts.map +1 -1
  202. package/dist/forms/utils/getFieldsForOperation.js +1 -1
  203. package/dist/forms/utils/index.d.ts +1 -0
  204. package/dist/forms/utils/index.d.ts.map +1 -1
  205. package/dist/forms/utils/index.js +1 -1
  206. package/dist/forms/utils/isFieldEditable.d.ts +21 -22
  207. package/dist/forms/utils/isFieldEditable.d.ts.map +1 -1
  208. package/dist/forms/utils/isFieldEditable.js +1 -1
  209. package/dist/forms/utils/writableFields.d.ts +19 -0
  210. package/dist/forms/utils/writableFields.d.ts.map +1 -0
  211. package/dist/forms/utils/writableFields.js +1 -0
  212. package/dist/hooks/index.d.ts +2 -0
  213. package/dist/hooks/index.d.ts.map +1 -1
  214. package/dist/hooks/index.js +1 -1
  215. package/dist/hooks/useChildRows.d.ts +161 -0
  216. package/dist/hooks/useChildRows.d.ts.map +1 -0
  217. package/dist/hooks/useChildRows.js +1 -0
  218. package/dist/hooks/useCrudFilters.d.ts +21 -1
  219. package/dist/hooks/useCrudFilters.d.ts.map +1 -1
  220. package/dist/hooks/useCrudFilters.js +1 -1
  221. package/dist/hooks/useExtensionRows.d.ts +24 -0
  222. package/dist/hooks/useExtensionRows.d.ts.map +1 -0
  223. package/dist/hooks/useExtensionRows.js +1 -0
  224. package/dist/hooks/useFieldConditions.d.ts +2 -2
  225. package/dist/hooks/useFieldConditions.d.ts.map +1 -1
  226. package/dist/hooks/useFieldConditions.js +1 -1
  227. package/dist/hooks/useReferenceResolver.d.ts +4 -1
  228. package/dist/hooks/useReferenceResolver.d.ts.map +1 -1
  229. package/dist/hooks/useReferenceResolver.js +1 -1
  230. package/dist/index.d.ts +6 -5
  231. package/dist/index.d.ts.map +1 -1
  232. package/dist/index.js +1 -1
  233. package/dist/registerBuiltinFieldTypes.d.ts +2 -0
  234. package/dist/registerBuiltinFieldTypes.d.ts.map +1 -1
  235. package/dist/registerBuiltinFieldTypes.js +1 -1
  236. package/dist/stores/FormStore.d.ts +116 -5
  237. package/dist/stores/FormStore.d.ts.map +1 -1
  238. package/dist/stores/FormStore.js +1 -1
  239. package/dist/stores/UploadStore.js +1 -1
  240. package/dist/stores/index.d.ts +1 -1
  241. package/dist/stores/index.d.ts.map +1 -1
  242. package/dist/stores/index.js +1 -1
  243. package/dist/symbol-index.json +1 -1
  244. package/dist/tsconfig.tsbuildinfo +1 -1
  245. package/dist/types.d.ts +38 -6
  246. package/dist/types.d.ts.map +1 -1
  247. package/dist/useCrud.d.ts +7 -5
  248. package/dist/useCrud.d.ts.map +1 -1
  249. package/dist/useCrud.js +1 -1
  250. package/dist/useCrudDoc.js +1 -1
  251. package/dist/utils/clientListProcessing.d.ts +9 -12
  252. package/dist/utils/clientListProcessing.d.ts.map +1 -1
  253. package/dist/utils/clientListProcessing.js +1 -1
  254. package/dist/utils/collections.d.ts.map +1 -1
  255. package/dist/utils/collections.js +1 -1
  256. package/dist/utils/filterUrl.d.ts +45 -0
  257. package/dist/utils/filterUrl.d.ts.map +1 -0
  258. package/dist/utils/filterUrl.js +1 -0
  259. package/dist/utils/matchesFilter.d.ts +27 -3
  260. package/dist/utils/matchesFilter.d.ts.map +1 -1
  261. package/dist/utils/matchesFilter.js +1 -1
  262. package/dist/utils/uploadValidation.js +1 -1
  263. package/dist/utils/useRowTranslator.js +1 -1
  264. package/guidelines/COMPONENTS.md +82 -11
  265. package/guidelines/CRUD.md +242 -7
  266. package/guidelines/GOTCHAS.md +17 -1
  267. package/package.json +3 -3
@@ -0,0 +1,64 @@
1
+ import type { dndevSchema, WriteSchemaForInput } from '@donotdev/core';
2
+ /** Write schemas a caller passes, keyed like `createSchemas(entity)`. */
3
+ export interface WriteSchemaSet<S> {
4
+ create?: S;
5
+ draft?: S;
6
+ update?: S;
7
+ }
8
+ /**
9
+ * The schema of one write: `schemas[writeSchemaFor(input)]`. A write whose caller
10
+ * passes no write schema at all is not validated (`undefined`, the bulk contract:
11
+ * schemas are optional). Throws when the caller passes schemas but not the one the
12
+ * resulting status needs (e.g. a draft row with only `create`): no other schema
13
+ * stands in for it.
14
+ *
15
+ * @param schemas - The schemas the caller passes
16
+ * @param input - Operation, sent status, stored status
17
+ * @param collection - Collection written (named in the error)
18
+ * @returns The schema, or `undefined` when the caller passes none
19
+ * @throws When `schemas` has entries but not the needed one
20
+ *
21
+ * @version 0.1.0
22
+ * @since 0.2.5
23
+ * @author AMBROISE PARK Consulting
24
+ */
25
+ export declare function writeSchemaOf<S>(schemas: Readonly<WriteSchemaSet<S>>, input: WriteSchemaForInput, collection: string): S | undefined;
26
+ /** One update patch to validate (`validatedPatch`). */
27
+ export interface UpdatePatchInput<S> {
28
+ /** Id of the updated row */
29
+ id: string;
30
+ /** The patch as sent */
31
+ patch: Record<string, unknown>;
32
+ /** Sent status, stored status (`op: 'update'`) */
33
+ statusInput: WriteSchemaForInput;
34
+ /** The patch's write schema (`writeSchemaOf`); `undefined`: not validated */
35
+ schema: S | undefined;
36
+ /** The stored row (from the caches), `null` / `undefined` when unknown */
37
+ stored: Readonly<Record<string, unknown>> | null | undefined;
38
+ /** Validation context, named in errors */
39
+ context: string;
40
+ }
41
+ /**
42
+ * Validates an update patch like the server functions and returns what is written:
43
+ * - entering a visible status (`entersVisibleStatus`, a draft published) with a known
44
+ * stored row: the stored row merged with the patch is checked against `update`
45
+ * (a required field left empty while it was a draft is rejected); keys the stored
46
+ * row lacks (a list projection) are not checked here, the server checks the whole row;
47
+ * - resulting draft: the stored row merged with the patch (`status: 'draft'`, the
48
+ * resulting status, so a stored status known only from the caller works) against the
49
+ * draft schema;
50
+ * - otherwise: the patch with its id against its schema.
51
+ * Only the sent keys are written, as parsed (`id` never). Without a schema the patch is
52
+ * returned as sent.
53
+ *
54
+ * @param schemas - The schemas the caller passes (`update` for the publish check)
55
+ * @param input - The patch, its schema, status input and stored row
56
+ * @returns The parsed patch (sent keys only)
57
+ * @throws {DoNotDevError} `validation-failed` when the patch or the published row fails
58
+ *
59
+ * @version 0.1.0
60
+ * @since 0.2.5
61
+ * @author AMBROISE PARK Consulting
62
+ */
63
+ export declare function validatedPatch<S extends dndevSchema<unknown>>(schemas: Readonly<WriteSchemaSet<S>>, input: UpdatePatchInput<S>): Record<string, unknown>;
64
+ //# sourceMappingURL=CrudService.writeSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrudService.writeSchema.d.ts","sourceRoot":"","sources":["../src/CrudService.writeSchema.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEvE,yEAAyE;AACzE,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,MAAM,CAAC,EAAE,CAAC,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACpC,KAAK,EAAE,mBAAmB,EAC1B,UAAU,EAAE,MAAM,GACjB,CAAC,GAAG,SAAS,CASf;AAED,uDAAuD;AACvD,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,4BAA4B;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,kDAAkD;IAClD,WAAW,EAAE,mBAAmB,CAAC;IACjC,6EAA6E;IAC7E,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC;IACtB,0EAA0E;IAC1E,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAC7D,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,WAAW,CAAC,OAAO,CAAC,EAC3D,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACpC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBzB"}
@@ -0,0 +1 @@
1
+ import{entersVisibleStatus as m,validateWithSchema as u,writeSchemaFor as h}from"@donotdev/core";function p(s,a,r){const t=h(a),i=s[t];if(i)return i;const n=["create","draft","update"].filter(e=>s[e]);if(n.length!==0)throw new Error(`[dndev] "${r}": this ${a.op} (resulting status "${a.status??a.storedStatus??"none"}") is validated with schemas.${t} (createSchemas(entity).${t}); only ${n.map(e=>`schemas.${e}`).join(", ")} passed.`)}function l(s,a){const{id:r,patch:t,statusInput:i,schema:n,stored:e,context:o}=a;if(s.update&&e&&m(i)&&u(s.update,{...e,...t,id:r},o),!n)return t;const f=h(i)==="draft"?{...e,...t,status:"draft",id:r}:{...t,id:r},c=u(n,f,o);return Object.fromEntries(Object.keys(t).filter(d=>d!=="id"&&Object.hasOwn(c,d)).map(d=>[d,c[d]]))}export{l as validatedPatch,p as writeSchemaOf};
@@ -1,4 +1,4 @@
1
- import type { CrudState, CrudActions } from './types';
1
+ import type { CrudState, CrudActions, FilterState } from './types';
2
2
  /**
3
3
  * CRUD store hook for accessing CRUD state and actions
4
4
  *
@@ -7,4 +7,13 @@ import type { CrudState, CrudActions } from './types';
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
9
  export declare const useCrudStore: import("zustand").UseBoundStore<import("zustand").StoreApi<CrudState & CrudActions & import("@donotdev/stores").DoNotDevStore>>;
10
+ /**
11
+ * Filter state of a key for render: the stored state, else, for a URL-synced key on
12
+ * the client that is not seeded yet, the filters its `f_*` params encode. Reads only:
13
+ * never writes the store, so render can call it without notifying other components
14
+ * (the store is seeded by `syncFiltersFromUrl`, from an effect). Same reference while
15
+ * neither the store nor the URL changes (a `useSyncExternalStore` snapshot).
16
+ * Internal to `useCrudFilters`.
17
+ */
18
+ export declare function peekFilters(key: string): FilterState;
10
19
  //# sourceMappingURL=CrudStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CrudStore.d.ts","sourceRoot":"","sources":["../src/CrudStore.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAEV,SAAS,EACT,WAAW,EAIZ,MAAM,SAAS,CAAC;AA8FjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,iIA0cvB,CAAC"}
1
+ {"version":3,"file":"CrudStore.d.ts","sourceRoot":"","sources":["../src/CrudStore.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAEV,SAAS,EACT,WAAW,EAEX,WAAW,EAEZ,MAAM,SAAS,CAAC;AA4EjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,iIAigBvB,CAAC;AAWH;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAcpD"}
package/dist/CrudStore.js CHANGED
@@ -1 +1 @@
1
- import{createDoNotDevStore as g,isClient as f}from"@donotdev/core";import{OPTIMISTIC_STATUSES as d,CRUD_OPERATION as u}from"./types";let m=null;const a="f_";function S(n){if(!f())return;const s=new URLSearchParams(location.search);[...s.keys()].filter(i=>i.startsWith(a)).forEach(i=>s.delete(i));for(const[i,e]of Object.entries(n))typeof e=="string"?s.set(`${a}${i}`,e):Array.isArray(e)?s.set(`${a}${i}`,e.join(",")):(e.min&&s.set(`${a}${i}_min`,e.min),e.max&&s.set(`${a}${i}_max`,e.max));const t=s.toString();history.replaceState(null,"",`${location.pathname}${t?`?${t}`:""}`)}function h(){if(!f())return{};const n=new URLSearchParams(location.search),s={},t=new Map;return n.forEach((i,e)=>{if(!e.startsWith(a))return;const o=e.slice(a.length);if(o.endsWith("_min")){const c=o.slice(0,-4),l=t.get(c)??{};l.min=i,t.set(c,l)}else if(o.endsWith("_max")){const c=o.slice(0,-4),l=t.get(c)??{};l.max=i,t.set(c,l)}else i.includes(",")?s[o]=i.split(","):s[o]=i}),t.forEach((i,e)=>{s[e]=i}),s}const E={filters:{},showFavoritesOnly:!1};function r(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...E}}}const O={crudService:null,hideSuccessToasts:!1,collections:{}},U=g({name:"crud-store",createStore:(n,s)=>({...O,setCrudService:t=>{n({crudService:t})},setHideSuccessToasts:t=>{n({hideSuccessToasts:t})},setLoading:(t,i)=>{n(e=>{const o=e.collections[t]||r();return{collections:{...e.collections,[t]:{...o,loading:i}}}})},setError:(t,i)=>{n(e=>{const o=e.collections[t]||r();return{collections:{...e.collections,[t]:{...o,error:i,loading:!1}}}})},setFilters:(t,i)=>{n(e=>{const o=e.collections[t]||r();return{collections:{...e.collections,[t]:{...o,ui:{...o.ui,filters:i}}}}}),m&&clearTimeout(m),m=setTimeout(()=>{m=null,S(i)},500)},setShowFavoritesOnly:(t,i)=>{n(e=>{const o=e.collections[t]||r();return{collections:{...e.collections,[t]:{...o,ui:{...o.ui,showFavoritesOnly:i}}}}})},getFilters:t=>{const i=s().collections[t]?.ui?.filters;if(i)return i;const e=h();return Object.keys(e).length>0?(n(o=>{const c=o.collections[t]||r();return{collections:{...o.collections,[t]:{...c,ui:{...c.ui,filters:e}}}}}),e):{}},getShowFavoritesOnly:t=>s().collections[t]?.ui?.showFavoritesOnly||!1,setPageSize:(t,i)=>{n(e=>{const o=e.collections[t]||r();return{collections:{...e.collections,[t]:{...o,ui:{...o.ui,pageSize:i}}}}})},getPageSize:t=>s().collections[t]?.ui?.pageSize,clearCollection:t=>{n(i=>{const{[t]:e,...o}=i.collections;return{collections:o}})},clearError:t=>{n(i=>{const e=i.collections[t];return e?{collections:{...i.collections,[t]:{...e,error:null}}}:i})},addOptimistic:(t,i,e)=>{n(o=>{const c=o.collections[t]||r();return{collections:{...o.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:null,optimisticData:e,status:d.PENDING,operation:u.ADD}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,i,e,o)=>{n(c=>{const l=c.collections[t];if(!l)return c;const{[i]:p,...D}=l.optimistic;return{collections:{...c.collections,[t]:{...l,optimistic:D,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,i)=>{n(e=>{const o=e.collections[t];if(!o)return e;const{[i]:c,...l}=o.optimistic;return{collections:{...e.collections,[t]:{...o,optimistic:l,lastUpdated:Date.now()}}}})},updateOptimistic:(t,i,e,o)=>{n(c=>{const l=c.collections[t]||r();return{collections:{...c.collections,[t]:{...l,optimistic:{...l.optimistic,[i]:{tempId:i,originalData:o,optimisticData:e,status:d.PENDING,operation:u.UPDATE}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,i)=>{n(e=>{const o=e.collections[t];if(!o)return e;const{[i]:c,...l}=o.optimistic;return{collections:{...e.collections,[t]:{...o,optimistic:l}}}})},rejectUpdate:(t,i)=>{n(e=>{const o=e.collections[t];if(!o)return e;const c=o.optimistic[i];if(!c||c.operation!==u.UPDATE)return e;const{[i]:l,...p}=o.optimistic;return{collections:{...e.collections,[t]:{...o,optimistic:p,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,i,e)=>{n(o=>{const c=o.collections[t];return c?{collections:{...o.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:e,optimisticData:null,status:d.PENDING,operation:u.DELETE}},lastUpdated:Date.now()}}}:o})},confirmDelete:(t,i)=>{n(e=>{const o=e.collections[t];if(!o)return e;const{[i]:c,...l}=o.optimistic;return{collections:{...e.collections,[t]:{...o,optimistic:l}}}})},rejectDelete:(t,i)=>{n(e=>{const o=e.collections[t];if(!o)return e;const c=o.optimistic[i];if(!c||c.operation!==u.DELETE)return e;const{[i]:l,...p}=o.optimistic;return{collections:{...e.collections,[t]:{...o,optimistic:p,lastUpdated:Date.now()}}}})},getLoading:t=>s().collections[t]?.loading||!1,getError:t=>s().collections[t]?.error||null,isOptimistic:(t,i)=>s().collections[t]?.optimistic[i]?.status==="pending",getOptimisticStatus:(t,i)=>s().collections[t]?.optimistic[i]?.status??null,getOptimisticData:(t,i)=>s().collections[t]?.optimistic[i]?.optimisticData??null})});export{U as useCrudStore};
1
+ import{createDoNotDevStore as T,getEntityByCollection as v,isClient as u}from"@donotdev/core";import{OPTIMISTIC_STATUSES as g,CRUD_OPERATION as p}from"./types";import{encodeFilterParams as w,readFilterParams as D,writeFilterParams as P}from"./utils/filterUrl";const E=new Map,m=new Map,I=500;let U=!1;const d=new Set;function f(n){const l=E.get(n);return l!==void 0?l:v(n)??null}function N(n,l){const t=new URLSearchParams(location.search);P(t,n,l);const i=t.toString();i!==location.search.replace(/^\?/,"")&&history.replaceState(history.state,"",`${location.pathname}${i?`?${i}`:""}${location.hash}`)}const C={filters:{},showFavoritesOnly:!1};function a(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...C}}}const L={crudService:null,hideSuccessToasts:!1,collections:{}},h=T({name:"crud-store",createStore:(n,l)=>({...L,setCrudService:t=>{n({crudService:t})},setHideSuccessToasts:t=>{n({hideSuccessToasts:t})},setLoading:(t,i)=>{n(o=>{const e=o.collections[t]||a();return{collections:{...o.collections,[t]:{...e,loading:i}}}})},setError:(t,i)=>{n(o=>{const e=o.collections[t]||a();return{collections:{...o.collections,[t]:{...e,error:i,loading:!1}}}})},setFilters:(t,i)=>{if(n(c=>{const r=c.collections[t]||a();return{collections:{...c.collections,[t]:{...r,ui:{...r.ui,filters:i}}}}}),!u())return;const o=f(t);if(!o)return;S(),d.add(t);const e=m.get(t);e&&clearTimeout(e.timer);const s=location.pathname;m.set(t,{pathname:s,timer:setTimeout(()=>{m.delete(t),location.pathname===s&&N(i,o)},I)})},setFilterUrlSync:(t,i)=>{E.set(t,i)},syncFiltersFromUrl:t=>{if(!u())return;const i=f(t);if(!i)return;S(),d.add(t);const o=m.get(t);if(o){if(o.pathname===location.pathname)return;clearTimeout(o.timer),m.delete(t)}const e=D(location.search,i),s=l().collections[t]?.ui?.filters??{};w(e,i)!==w(s,i)&&n(c=>{const r=c.collections[t]||a();return{collections:{...c.collections,[t]:{...r,ui:{...r.ui,filters:e}}}}})},setShowFavoritesOnly:(t,i)=>{n(o=>{const e=o.collections[t]||a();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,showFavoritesOnly:i}}}}})},getFilters:t=>{const i=l().collections[t]?.ui?.filters;if(i)return i;const o=u()?f(t):null;if(!o)return{};S(),d.add(t);const e=D(location.search,o);return Object.keys(e).length>0?(n(s=>{const c=s.collections[t]||a();return{collections:{...s.collections,[t]:{...c,ui:{...c.ui,filters:e}}}}}),e):{}},getShowFavoritesOnly:t=>l().collections[t]?.ui?.showFavoritesOnly||!1,setPageSize:(t,i)=>{n(o=>{const e=o.collections[t]||a();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,pageSize:i}}}}})},getPageSize:t=>l().collections[t]?.ui?.pageSize,clearCollection:t=>{n(i=>{const{[t]:o,...e}=i.collections;return{collections:e}})},clearError:t=>{n(i=>{const o=i.collections[t];return o?{collections:{...i.collections,[t]:{...o,error:null}}}:i})},addOptimistic:(t,i,o)=>{n(e=>{const s=e.collections[t]||a();return{collections:{...e.collections,[t]:{...s,optimistic:{...s.optimistic,[i]:{tempId:i,originalData:null,optimisticData:o,status:g.PENDING,operation:p.ADD}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,i,o,e)=>{n(s=>{const c=s.collections[t];if(!c)return s;const{[i]:r,...F}=c.optimistic;return{collections:{...s.collections,[t]:{...c,optimistic:F,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const{[i]:s,...c}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:c,lastUpdated:Date.now()}}}})},updateOptimistic:(t,i,o,e)=>{n(s=>{const c=s.collections[t]||a();return{collections:{...s.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:e,optimisticData:o,status:g.PENDING,operation:p.UPDATE}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const{[i]:s,...c}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:c}}}})},rejectUpdate:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const s=e.optimistic[i];if(!s||s.operation!==p.UPDATE)return o;const{[i]:c,...r}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:r,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,i,o)=>{n(e=>{const s=e.collections[t];return s?{collections:{...e.collections,[t]:{...s,optimistic:{...s.optimistic,[i]:{tempId:i,originalData:o,optimisticData:null,status:g.PENDING,operation:p.DELETE}},lastUpdated:Date.now()}}}:e})},confirmDelete:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const{[i]:s,...c}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:c}}}})},rejectDelete:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const s=e.optimistic[i];if(!s||s.operation!==p.DELETE)return o;const{[i]:c,...r}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:r,lastUpdated:Date.now()}}}})},getLoading:t=>l().collections[t]?.loading||!1,getError:t=>l().collections[t]?.error||null,isOptimistic:(t,i)=>l().collections[t]?.optimistic[i]?.status==="pending",getOptimisticStatus:(t,i)=>l().collections[t]?.optimistic[i]?.status??null,getOptimisticData:(t,i)=>l().collections[t]?.optimistic[i]?.optimisticData??null})}),O={},y=new Map;function A(n){const l=h.getState().collections[n]?.ui?.filters;if(l)return l;if(!u())return O;const t=f(n);if(!t)return O;const i=location.search,o=y.get(n);if(o&&o.search===i&&o.entity===t)return o.filters;const e=D(i,t);return y.set(n,{search:i,entity:t,filters:e}),e}function S(){if(U||!u())return;U=!0;const n=()=>{const{syncFiltersFromUrl:t}=h.getState();d.forEach(i=>t(i))},l=window.navigation;l?l.addEventListener("currententrychange",n):window.addEventListener("popstate",n)}export{A as peekFilters,h as useCrudStore};
@@ -32,7 +32,7 @@ export type CustomDisplayFormatter = (value: unknown, config: EntityField, t: (k
32
32
  asString?: boolean;
33
33
  }) => string | ReactElement;
34
34
  /** Filter UI type for EntityFilters; must match fieldTypeRegistry.FilterType */
35
- export type CustomFilterType = 'text' | 'range' | 'select' | 'none' | 'address' | 'multiselect';
35
+ export type CustomFilterType = 'text' | 'range' | 'select' | 'none' | 'address' | 'multiselect' | 'reference';
36
36
  /**
37
37
  * Registration for custom field types (UI components only)
38
38
  * Schemas must be defined in entity.validation.schema
@@ -1 +1 @@
1
- {"version":3,"file":"FieldRegistry.d.ts","sourceRoot":"","sources":["../src/FieldRegistry.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,EAAE,SAAS,SAAS,GAAG,SAAS;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC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CAAC,IAAI,EAAE,MAAM,GAAG,sBAAsB,GAAG,SAAS;IAIrE;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAIzD;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAInC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAI9B;;OAEG;IACH,KAAK,IAAI,IAAI;CAKd;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,SAAS,EACpD,YAAY,EAAE,qBAAqB,CAAC,EAAE,CAAC,GACtC,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D"}
@@ -44,8 +44,8 @@ export declare class FunctionsAdapter implements ICrudAdapter {
44
44
  */
45
45
  private getCallableFn;
46
46
  get<T>(collectionName: string, id: string, schema: dndevSchema<unknown>): Promise<T | null>;
47
- set<T>(collectionName: string, id: string, data: T, schema: dndevSchema<T>): Promise<void>;
48
- update<T>(collectionName: string, id: string, data: Partial<T>): Promise<void>;
47
+ set<T>(collectionName: string, id: string, data: T, schema: dndevSchema<T>): Promise<Record<string, unknown>>;
48
+ update<T>(collectionName: string, id: string, data: Partial<T>): Promise<Record<string, unknown>>;
49
49
  delete(collectionName: string, id: string): Promise<void>;
50
50
  /**
51
51
  * Bulk transactional operation via the `bulk_${collection}` callable.
@@ -65,7 +65,7 @@ export declare class FunctionsAdapter implements ICrudAdapter {
65
65
  * — malformed payloads fail loud locally.
66
66
  * 4. Invokes the callable via the provider registry (identical path to
67
67
  * `add` / `update` / `delete`).
68
- * 5. Validates the server reply with {@link BulkResponseSchema} — a
68
+ * 5. Validates the server reply with {@link validateBulkOutcome} — a
69
69
  * malformed server response surfaces as a clean error, never as a
70
70
  * silent zeroed result.
71
71
  * 6. Any other failure is wrapped via {@link wrapCrudError} to preserve
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionsAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FunctionsAdapter.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,cAAc,EAGd,UAAU,EACV,oBAAoB,EACpB,WAAW,EAEX,YAAY,EACZ,cAAc,EACd,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAaxB;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACnE,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yFAAyF;IACzF,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,QAAQ,CAAC,cAAc,QAAQ;IAE/B;;;OAGG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;YACW,aAAa;IASrB,GAAG,CAAC,CAAC,EACT,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAsBd,GAAG,CAAC,CAAC,EACT,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,CAAC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GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAoB7B,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkDG;IACG,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1C,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,EACxB,QAAQ,CAAC,EAAE,oBAAoB,GAC9B,OAAO,CAAC,UAAU,CAAC;IA4FhB,GAAG,CAAC,CAAC,EACT,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,CAAC,EACP,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACtB,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IA0BnD,KAAK,CAAC,CAAC,EACX,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,UAAU,GAAE,cAAsC,GACjD,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAqEnC,SAAS,CAAC,CAAC,KAAK,MAAM,IAAI;IAS1B,qBAAqB,CAAC,CAAC,KAAK,MAAM,IAAI;CAQvC"}
@@ -1 +1 @@
1
- import*as h from"valibot";import{BulkCollisionError as y,BulkRequestSchema as g,BulkResponseSchema as A,detectBulkCollisions as m,DoNotDevError as f,getProvider as C,validateWithSchema as p,wrapCrudError as l}from"@donotdev/core";import{LIST_SCHEMA_TYPE as b}from"@donotdev/core";class E{serverSideOnly=!0;getCallable(){return C("callable")}async getCallableFn(e){const t=this.getCallable();return async s=>({data:await t.call(e,s)})}async get(e,t,s){const n=`get_${e}`,i=await this.getCallableFn(n);try{const a=(await i({id:t})).data;return s?{...p(s,a,"FunctionsAdapter.get"),id:t}:{...a,id:t}}catch(a){throw l(a,"FunctionsAdapter","get",e,t)}}async set(e,t,s,n){const i=n?p(n,s,"FunctionsAdapter.set"):s,a=`update_${e}`,o=await this.getCallableFn(a);try{await o({id:t,payload:i})}catch(r){throw l(r,"FunctionsAdapter","set",e,t)}}async update(e,t,s){const n=`update_${e}`,i=await this.getCallableFn(n);try{await i({id:t,payload:s})}catch(a){throw l(a,"FunctionsAdapter","update",e,t)}}async delete(e,t){const s=`delete_${e}`,n=await this.getCallableFn(s);try{await n({id:t})}catch(i){throw l(i,"FunctionsAdapter","delete",e,t)}}async bulk(e,t,s,n){const i=m({inserts:t.inserts,updates:t.updates,deletes:t.deletes});if(i.where!==null)throw new y(i.collisions,i.where);const a=t.inserts??[],o=t.updates??[],r=t.deletes??[];if(a.length===0&&o.length===0&&r.length===0)return{insertedIds:[],updatedIds:[],deletedIds:[],failed:[]};let w;try{w=h.parse(g,{inserts:a,updates:o,deletes:r})}catch(d){throw new f(`FunctionsAdapter.bulk(${e}): invalid bulk request payload`,"validation-failed",{details:{issues:d instanceof h.ValiError?d.issues:void 0},source:"validation",originalError:d instanceof Error?d:new Error(String(d))})}const F=await this.getCallableFn(`bulk_${e}`);try{const d=await F(w);if(!d.data)throw l(new Error("Bulk function returned no data"),"FunctionsAdapter","bulk",e);let u;try{u=h.parse(A,d.data)}catch(c){throw new f(`FunctionsAdapter.bulk(${e}): malformed server response`,"validation-failed",{details:{issues:c instanceof h.ValiError?c.issues:void 0,response:d.data},source:"validation",originalError:c instanceof Error?c:new Error(String(c))})}return{insertedIds:u.insertedIds,updatedIds:u.updatedIds,deletedIds:u.deletedIds,failed:[]}}catch(d){throw d instanceof y?d:l(d,"FunctionsAdapter","bulk",e)}}async add(e,t,s){const n=s?p(s,t,"FunctionsAdapter.add"):t,i=`create_${e}`,a=await this.getCallableFn(i);try{const o=await a({payload:n});if(!o.data)throw l(new Error("Create function returned no data"),"FunctionsAdapter","add",e);return{id:o.data.id,data:o.data}}catch(o){throw l(o,"FunctionsAdapter","add",e)}}async query(e,t,s,n=b.LIST){const i=n===b.LIST_CARD?`listCard_${e}`:`list_${e}`,a={};t.where&&(a.where=t.where.map(r=>[r.field,r.operator,r.value])),t.orderBy&&(a.orderBy=t.orderBy.map(r=>[r.field,r.direction||"asc"])),t.limit&&(a.limit=t.limit),t.startAfter&&(a.startAfterId=t.startAfter);const o=await this.getCallableFn(i);try{const r=await o(a);if(!r.data)throw l(new Error("Query function returned no data"),"FunctionsAdapter","query",e);return{items:r.data.items,total:r.data.count,hasMore:r.data.hasMore,lastVisible:r.data.lastVisible}}catch(r){throw l(r,"FunctionsAdapter","query",e)}}subscribe(){return()=>{}}subscribeToCollection(){return()=>{}}}export{E as FunctionsAdapter};
1
+ import*as h from"valibot";import{BulkCollisionError as y,BulkRequestSchema as g,validateBulkOutcome as A,detectBulkCollisions as m,DoNotDevError as f,getProvider as C,validateWithSchema as w,wrapCrudError as l}from"@donotdev/core";import{LIST_SCHEMA_TYPE as b}from"@donotdev/core";class E{serverSideOnly=!0;getCallable(){return C("callable")}async getCallableFn(a){const t=this.getCallable();return async s=>({data:await t.call(a,s)})}async get(a,t,s){const n=`get_${a}`,i=await this.getCallableFn(n);try{const e=(await i({id:t})).data;return s?{...w(s,e,"FunctionsAdapter.get"),id:t}:{...e,id:t}}catch(e){throw l(e,"FunctionsAdapter","get",a,t)}}async set(a,t,s,n){const i=n?w(n,s,"FunctionsAdapter.set"):s,e=`update_${a}`,d=await this.getCallableFn(e);try{return await d({id:t,payload:i})}catch(r){throw l(r,"FunctionsAdapter","set",a,t)}}async update(a,t,s){const n=`update_${a}`,i=await this.getCallableFn(n);try{return await i({id:t,payload:s})}catch(e){throw l(e,"FunctionsAdapter","update",a,t)}}async delete(a,t){const s=`delete_${a}`,n=await this.getCallableFn(s);try{await n({id:t})}catch(i){throw l(i,"FunctionsAdapter","delete",a,t)}}async bulk(a,t,s,n){const i=m({inserts:t.inserts,updates:t.updates,deletes:t.deletes});if(i.where!==null)throw new y(i.collisions,i.where);const e=t.inserts??[],d=t.updates??[],r=t.deletes??[];if(e.length===0&&d.length===0&&r.length===0)return{insertedIds:[],updatedIds:[],deletedIds:[],failed:[]};let u;try{u=h.parse(g,{inserts:e,updates:d,deletes:r})}catch(o){throw new f(`FunctionsAdapter.bulk(${a}): invalid bulk request payload`,"validation-failed",{details:{issues:o instanceof h.ValiError?o.issues:void 0},source:"validation",originalError:o instanceof Error?o:new Error(String(o))})}const F=await this.getCallableFn(`bulk_${a}`);try{const o=await F(u);if(!o.data)throw l(new Error("Bulk function returned no data"),"FunctionsAdapter","bulk",a);let p;try{p=A(u,o.data)}catch(c){throw new f(`FunctionsAdapter.bulk(${a}): malformed server response`,"validation-failed",{details:{issues:c instanceof h.ValiError?c.issues:void 0,response:o.data},source:"validation",originalError:c instanceof Error?c:new Error(String(c))})}return p}catch(o){throw o instanceof y?o:l(o,"FunctionsAdapter","bulk",a)}}async add(a,t,s){const n=s?w(s,t,"FunctionsAdapter.add"):t,i=`create_${a}`,e=await this.getCallableFn(i);try{const d=await e({payload:n});if(!d.data)throw l(new Error("Create function returned no data"),"FunctionsAdapter","add",a);return{id:d.data.id,data:d.data}}catch(d){throw l(d,"FunctionsAdapter","add",a)}}async query(a,t,s,n=b.LIST){const i=n===b.LIST_CARD?`listCard_${a}`:`list_${a}`,e={};t.where&&(e.where=t.where.map(r=>[r.field,r.operator,r.value])),t.orderBy&&(e.orderBy=t.orderBy.map(r=>[r.field,r.direction||"asc"])),t.limit&&(e.limit=t.limit),t.startAfter&&(e.startAfterId=t.startAfter);const d=await this.getCallableFn(i);try{const r=await d(e);if(!r.data)throw l(new Error("Query function returned no data"),"FunctionsAdapter","query",a);return{items:r.data.items,total:r.data.count,hasMore:r.data.hasMore,lastVisible:r.data.lastVisible}}catch(r){throw l(r,"FunctionsAdapter","query",a)}}subscribe(){return()=>{}}subscribeToCollection(){return()=>{}}}export{E as FunctionsAdapter};
@@ -44,11 +44,12 @@ export interface CrudButtonProps<T = unknown> extends Omit<ActionButtonProps<T>,
44
44
  *
45
45
  * @example
46
46
  * ```tsx
47
- * const { delete: deleteItem } = useCrud(itemEntity);
47
+ * // `remove` = logical delete (status `deleted`); `delete` = hard delete
48
+ * const { remove } = useCrud(itemEntity);
48
49
  * const user = useAuth('user');
49
50
  *
50
51
  * <CrudButton
51
- * action={() => deleteItem(itemId)}
52
+ * action={() => remove(itemId)}
52
53
  * user={user}
53
54
  * loadingText="Deleting..."
54
55
  * confirmText="Delete this item?"
@@ -1 +1 @@
1
- {"version":3,"file":"CrudButton.d.ts","sourceRoot":"","sources":["../../src/components/CrudButton.tsx"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D,gGAAgG;AAChG,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,IAAI,CACxD,iBAAiB,CAAC,CAAC,CAAC,EACpB,UAAU,CACX;IACC;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,iBAAS,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,EAC/B,YAAmB,EACnB,IAAI,EACJ,QAAgB,EAChB,QAAQ,EACR,GAAG,iBAAiB,EACrB,EAAE,eAAe,CAAC,CAAC,CAAC,+BAYpB;AAED,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"CrudButton.d.ts","sourceRoot":"","sources":["../../src/components/CrudButton.tsx"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D,gGAAgG;AAChG,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,IAAI,CACxD,iBAAiB,CAAC,CAAC,CAAC,EACpB,UAAU,CACX;IACC;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,iBAAS,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,EAC/B,YAAmB,EACnB,IAAI,EACJ,QAAgB,EAChB,QAAQ,EACR,GAAG,iBAAiB,EACrB,EAAE,eAAe,CAAC,CAAC,CAAC,+BAYpB;AAED,eAAe,UAAU,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"CrudCard.d.ts","sourceRoot":"","sources":["../../src/components/CrudCard.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAW,MAAM,gBAAgB,CAAC;AA2C7D;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,IAAI,EACJ,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,UAAkB,EAClB,aAAa,EACb,aAAa,EACb,SAAS,GACV,EAAE,aAAa,+BAkNf;AAED,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"CrudCard.d.ts","sourceRoot":"","sources":["../../src/components/CrudCard.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAW,MAAM,gBAAgB,CAAC;AA2C7D;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,IAAI,EACJ,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,UAAkB,EAClB,aAAa,EACb,aAAa,EACb,SAAS,GACV,EAAE,aAAa,+BA4Mf;AAED,eAAe,QAAQ,CAAC"}
@@ -1 +1 @@
1
- import{jsx as o,jsxs as L}from"react/jsx-runtime";import{Trash2 as G}from"lucide-react";import{useMemo as y}from"react";import{Card as H,Stack as k,Text as j,ActionButton as J}from"@donotdev/components";import{useTranslation as D,getListCardFieldNames as K}from"@donotdev/core";import{formatValue as h}from"./DisplayFieldRenderer";import{DisplayThumbnail as P}from"./DisplayThumbnail";import{translateFieldLabel as Q}from"../forms/utils/translateFieldLabel";import{useCrud as U}from"../useCrud";function d(e){return e==="image"||e==="images"}function W(e){return y(()=>{const t=e.listCardFields;if(t&&!Array.isArray(t))return{titleFields:t.title??[],subtitleFields:t.subtitle??[],contentFields:t.content??[],footerFields:t.footer??[]};const f=K(e),m=f.filter(p=>!d(e.fields[p]?.type)),C=f.filter(p=>d(e.fields[p]?.type)),b=m.length>0?[m[0]]:[],x=[...m.slice(1,4),...C];return{titleFields:b,subtitleFields:[],contentFields:x,footerFields:[]}},[e])}function I({item:e,entity:t,onClick:f,href:m,titleFields:C,subtitleFields:b,contentFields:x,footerFields:p,showDelete:w=!1,renderActions:V,renderOverlay:M,className:N}){const{t:s}=D([t.namespace,"crud"]),{t:a}=D("crud"),F=W(t),S=C??F.titleFields,A=b??F.subtitleFields,T=x??F.contentFields,g=p??F.footerFields,c=e,B=y(()=>{if(!S?.length)return e.id??"";const r=S.filter(i=>typeof i=="string").filter(i=>!d(t.fields[i]?.type)).map(i=>{const n=t.fields[i],v=e[i],u=n?h(v,n,s,{compact:!0,asString:!0,item:c}):v;return typeof u=="string"?u:String(u??"")}).filter(Boolean),l=!Array.isArray(t.listCardFields)&&t.listCardFields?.titleSeparator!=null?t.listCardFields.titleSeparator:" ";return r.join(l)||String(e.id??"")},[e,t.fields,S,t.listCardFields,s]),R=y(()=>A?.length&&A.filter(r=>typeof r=="string").filter(r=>!d(t.fields[r]?.type)).map(r=>{const l=t.fields[r],i=e[r],n=l?h(i,l,s,{compact:!0,asString:!0,item:c}):i;return typeof n=="string"?n:String(n??"")}).filter(Boolean).join(" ")||void 0,[e,t.fields,A,s]),E=y(()=>{if(!T?.length)return null;const r=T.map(l=>{const i=t.fields[l];if(!i||i.options?.displayValue?.(e[l],c,s)===null)return null;if(d(i.type)){const n=e[l];return n==null?null:o(P,{pictures:n,alt:String(B),aspectRatio:"16/9"},l)}return L("div",{children:[o(j,{level:"small",variant:"muted",children:Q(l,i,s)}),o(j,{children:h(e[l],i,s,{compact:!0,item:c})})]},l)}).filter(Boolean);return r.length>0?o(k,{direction:"column",gap:"tight",children:r}):null},[e,t.fields,T,B,s]),O=y(()=>{if(!g?.length)return;if(g.some(l=>d(t.fields[l]?.type))){const l=g.map(i=>{const n=t.fields[i];if(!n)return null;if(d(n.type)){const u=e[i];return u==null?null:o(P,{pictures:u,alt:"",aspectRatio:"1"},i)}const v=h(e[i],n,s,{compact:!0,item:c});return o("span",{children:v},i)});return o(k,{direction:"row",gap:"tight",align:"center",children:l.filter(Boolean)})}const r=g.map(l=>{const i=t.fields[l];return i?h(e[l],i,s,{compact:!0,item:c}):e[l]});return o(j,{level:"small",children:r.join(" \xB7 ")})},[e,t.fields,g,s]),q=U(t).delete,z=V||w?L("div",{style:{display:"flex",alignItems:"flex-start",gap:"var(--gap-xs)",pointerEvents:"auto"},onClick:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation(),children:[V,w&&o(J,{action:async()=>{await q(e.id)},confirmText:a("delete.confirm",{defaultValue:"Are you sure you want to delete this item?"}),confirmTitle:a("delete.title",{defaultValue:"Delete Item"}),loadingText:a("delete.loading",{defaultValue:"Deleting..."}),confirmLabel:a("actions.delete"),cancelLabel:a("actions.cancel"),variant:"destructive",icon:G,"aria-label":a("actions.delete"),children:a("actions.delete")})]}):null;return o(H,{title:String(B??""),subtitle:R,content:E??void 0,footer:O,clickable:!0,elevated:!0,href:m,onClick:f?()=>f(e.id):void 0,className:N,overlay:z??void 0,overlayPosition:"top-right",fullOverlay:M??void 0})}var X=I;export{I as CrudCard,X as default};
1
+ import{jsx as o,jsxs as D}from"react/jsx-runtime";import{useMemo as y}from"react";import{Card as G,Stack as N,Text as j,ActionButton as H}from"@donotdev/components";import{useTranslation as P,getListCardFieldNames as J}from"@donotdev/core";import{formatValue as F}from"./DisplayFieldRenderer";import{DisplayThumbnail as L}from"./DisplayThumbnail";import{translateFieldLabel as K}from"../forms/utils/translateFieldLabel";import{useCrud as Q}from"../useCrud";function d(t){return t==="image"||t==="images"}function U(t){return y(()=>{const e=t.listCardFields;if(e&&!Array.isArray(e))return{titleFields:e.title??[],subtitleFields:e.subtitle??[],contentFields:e.content??[],footerFields:e.footer??[]};const u=J(t),m=u.filter(p=>!d(t.fields[p]?.type)),C=u.filter(p=>d(t.fields[p]?.type)),b=m.length>0?[m[0]]:[],S=[...m.slice(1,4),...C];return{titleFields:b,subtitleFields:[],contentFields:S,footerFields:[]}},[t])}function M({item:t,entity:e,onClick:u,href:m,titleFields:C,subtitleFields:b,contentFields:S,footerFields:p,showDelete:w=!1,renderActions:k,renderOverlay:V,className:E}){const{t:s}=P([e.namespace,"crud"]),{t:a}=P("crud"),h=U(e),x=C??h.titleFields,A=b??h.subtitleFields,B=S??h.contentFields,g=p??h.footerFields,c=t,T=y(()=>{if(!x?.length)return t.id??"";const r=x.filter(i=>typeof i=="string").filter(i=>!d(e.fields[i]?.type)).map(i=>{const n=e.fields[i],v=t[i],f=n?F(v,n,s,{compact:!0,asString:!0,item:c}):v;return typeof f=="string"?f:String(f??"")}).filter(Boolean),l=!Array.isArray(e.listCardFields)&&e.listCardFields?.titleSeparator!=null?e.listCardFields.titleSeparator:" ";return r.join(l)||String(t.id??"")},[t,e.fields,x,e.listCardFields,s]),I=y(()=>A?.length&&A.filter(r=>typeof r=="string").filter(r=>!d(e.fields[r]?.type)).map(r=>{const l=e.fields[r],i=t[r],n=l?F(i,l,s,{compact:!0,asString:!0,item:c}):i;return typeof n=="string"?n:String(n??"")}).filter(Boolean).join(" ")||void 0,[t,e.fields,A,s]),O=y(()=>{if(!B?.length)return null;const r=B.map(l=>{const i=e.fields[l];if(!i||i.options?.displayValue?.(t[l],c,s)===null)return null;if(d(i.type)){const n=t[l];return n==null?null:o(L,{pictures:n,alt:String(T),aspectRatio:"16/9"},l)}return D("div",{children:[o(j,{level:"small",variant:"muted",children:K(l,i,s)}),o(j,{children:F(t[l],i,s,{compact:!0,item:c})})]},l)}).filter(Boolean);return r.length>0?o(N,{direction:"column",gap:"tight",children:r}):null},[t,e.fields,B,T,s]),R=y(()=>{if(!g?.length)return;if(g.some(l=>d(e.fields[l]?.type))){const l=g.map(i=>{const n=e.fields[i];if(!n)return null;if(d(n.type)){const f=t[i];return f==null?null:o(L,{pictures:f,alt:"",aspectRatio:"1"},i)}const v=F(t[i],n,s,{compact:!0,item:c});return o("span",{children:v},i)});return o(N,{direction:"row",gap:"tight",align:"center",children:l.filter(Boolean)})}const r=g.map(l=>{const i=e.fields[l];return i?F(t[l],i,s,{compact:!0,item:c}):t[l]});return o(j,{level:"small",children:r.join(" \xB7 ")})},[t,e.fields,g,s]),q=Q(e).remove,z=k||w?D("div",{style:{display:"flex",alignItems:"flex-start",gap:"var(--gap-sm)",pointerEvents:"auto"},onClick:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation(),children:[k,w&&o(H,{action:async()=>{await q(t.id)},confirmText:a("delete.confirm"),confirmTitle:a("delete.title"),loadingText:a("delete.loading"),confirmLabel:a("actions.delete"),cancelLabel:a("actions.cancel"),intent:"remove","aria-label":a("actions.delete"),children:a("actions.delete")})]}):null;return o(G,{title:String(T??""),subtitle:I,content:O??void 0,footer:R,clickable:!0,elevated:!0,href:m,onClick:u?()=>u(t.id):void 0,className:E,overlay:z??void 0,overlayPosition:"top-right",fullOverlay:V??void 0})}var W=M;export{M as CrudCard,W as default};
@@ -1 +1 @@
1
- "use client";import{jsx as e,jsxs as j,Fragment as ct}from"react/jsx-runtime";import{X as ht}from"lucide-react";import{useState as k}from"react";import{Button as x,Calendar as St,FloatingLabel as Dt,Sheet as T,Text as M}from"@donotdev/components";import{formatDate as ft}from"@donotdev/core";function $t({label:S,fieldType:xt,value:s,onChange:D,tCrud:l,locale:O="en"}){const[F,i]=k(!1),[C,f]=k(null),N=s?typeof s=="object"&&s!==null&&"min"in s?{min:s.min||"",max:s.max||""}:{min:"",max:""}:{min:"",max:""},Y=t=>{if(!t)return"";try{const n=new Date(t+"T00:00:00");return ft(n,O)}catch{return t}},W=()=>{const t=new Date;t.setHours(0,0,0,0);const n=t.getFullYear(),g=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),o=`${n}-${g}-${r}`,d=new Date(t);d.setDate(d.getDate()-1);const v=d.getFullYear(),$=String(d.getMonth()+1).padStart(2,"0"),B=String(d.getDate()).padStart(2,"0"),H=`${v}-${$}-${B}`,m=new Date(t);m.setDate(m.getDate()+1);const L=m.getFullYear(),X=String(m.getMonth()+1).padStart(2,"0"),q=String(m.getDate()).padStart(2,"0"),z=`${L}-${X}-${q}`,p=new Date(t);p.setDate(p.getDate()-7);const A=p.getFullYear(),G=String(p.getMonth()+1).padStart(2,"0"),J=String(p.getDate()).padStart(2,"0"),K=`${A}-${G}-${J}`,u=new Date(t);u.setDate(u.getDate()-30);const P=u.getFullYear(),Q=String(u.getMonth()+1).padStart(2,"0"),R=String(u.getDate()).padStart(2,"0"),U=`${P}-${Q}-${R}`,c=new Date(t);c.setDate(c.getDate()+7);const Z=c.getFullYear(),_=String(c.getMonth()+1).padStart(2,"0"),tt=String(c.getDate()).padStart(2,"0"),et=`${Z}-${_}-${tt}`,h=new Date(t);h.setDate(h.getDate()+30);const at=h.getFullYear(),nt=String(h.getMonth()+1).padStart(2,"0"),rt=String(h.getDate()).padStart(2,"0"),lt=`${at}-${nt}-${rt}`,y=new Date(t.getFullYear(),t.getMonth(),1),it=y.getFullYear(),dt=String(y.getMonth()+1).padStart(2,"0"),st=String(y.getDate()).padStart(2,"0"),gt=`${it}-${dt}-${st}`,w=new Date(t.getFullYear(),t.getMonth()+1,0),ot=w.getFullYear(),mt=String(w.getMonth()+1).padStart(2,"0"),pt=String(w.getDate()).padStart(2,"0"),ut=`${ot}-${mt}-${pt}`;return{today:o,yesterday:H,tomorrow:z,last7Days:K,last30Days:U,next7Days:et,next30Days:lt,thisMonthStart:gt,thisMonthEnd:ut}},a=N,E=W(),I=!!(a?.min||a?.max),b=t=>{const n=t==="start",g=n?a?.min:a?.max;return e("div",{style:{padding:"var(--gap-md)"},children:j("div",{style:{display:"flex",flexDirection:"column",gap:"var(--gap-md)"},children:[e("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--gap-tight)"},children:(n?["today","yesterday","last7Days","last30Days","thisMonthStart"]:["today","tomorrow","next7Days","next30Days","thisMonthEnd"]).map(r=>{const o=E[r];return e(x,{variant:"outline",onClick:()=>{D({min:n?o:a?.min||"",max:n?a?.max||"":o}),i(!1)},children:l(`filter.${r}`,{defaultValue:r})},r)})}),e(St,{selected:g?new Date(g+"T00:00:00"):void 0,mode:"single",onSelect:r=>{if(!r)return;const o=r.getFullYear(),d=String(r.getMonth()+1).padStart(2,"0"),v=String(r.getDate()).padStart(2,"0"),$=`${o}-${d}-${v}`;D({min:n?$:a?.min||"",max:n?a?.max||"":$}),i(!1)},defaultMonth:g?new Date(g+"T00:00:00"):new Date}),e(x,{variant:"ghost",display:"compact",onClick:()=>{D({min:n?"":a?.min||"",max:n&&a?.max||""}),i(!1)},children:l("filter.clear",{defaultValue:"Clear"})})]})})},V=j(ct,{children:[e(T,{trigger:e(x,{variant:"ghost",onClick:()=>{f("start"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingInlineStart:"var(--gap-md)",justifyContent:"flex-start"},children:a?.min?Y(a.min):e(M,{as:"span",level:"small",variant:"muted",children:l("filter.min",{defaultValue:"Min"})})}),title:`${S} - ${l("filter.min",{defaultValue:"Min"})}`,open:F&&C==="start",onOpenChange:t=>{i(t),t||f(null)},children:b("start")}),e(M,{level:"small",variant:"muted",className:"dndev-range-input-separator",children:"\u2013"}),e(T,{trigger:e(x,{variant:"ghost",onClick:()=>{f("end"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingInlineStart:"var(--gap-md)",justifyContent:"flex-start"},children:a?.max?Y(a.max):e(M,{as:"span",level:"small",variant:"muted",children:l("filter.max",{defaultValue:"Max"})})}),title:`${S} - ${l("filter.max",{defaultValue:"Max"})}`,open:F&&C==="end",onOpenChange:t=>{i(t),t||f(null)},children:b("end")}),e("button",{type:"button",className:"dndev-inline-action-btn",onClick:()=>{D(void 0)},disabled:!I,"aria-label":l("filter.clear",{defaultValue:"Clear"}),children:e(ht,{})})]});return S?e(Dt,{label:S,children:e("div",{className:"dndev-range-input",children:V})}):e("div",{className:"dndev-range-input",children:V})}export{$t as DateFilter};
1
+ "use client";import{jsx as e,jsxs as k,Fragment as ht}from"react/jsx-runtime";import{X as ut}from"lucide-react";import{useState as T}from"react";import{Button as x,Calendar as St,FloatingLabel as Dt,Sheet as N,Text as M}from"@donotdev/components";import{formatDate as $t}from"@donotdev/core";function ft({label:S,fieldType:xt,value:d,onChange:D,tCrud:l,locale:O="en"}){const[F,i]=T(!1),[C,$]=T(null),W=d?typeof d=="object"&&d!==null&&"min"in d?{min:d.min||"",max:d.max||""}:{min:"",max:""}:{min:"",max:""},Y=t=>{if(!t)return"";try{const n=new Date(t+"T00:00:00");return $t(n,O)}catch{return t}},E=()=>{const t=new Date;t.setHours(0,0,0,0);const n=t.getFullYear(),g=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),o=`${n}-${g}-${r}`,s=new Date(t);s.setDate(s.getDate()-1);const v=s.getFullYear(),f=String(s.getMonth()+1).padStart(2,"0"),H=String(s.getDate()).padStart(2,"0"),L=`${v}-${f}-${H}`,m=new Date(t);m.setDate(m.getDate()+1);const V=m.getFullYear(),X=String(m.getMonth()+1).padStart(2,"0"),q=String(m.getDate()).padStart(2,"0"),z=`${V}-${X}-${q}`,p=new Date(t);p.setDate(p.getDate()-7);const A=p.getFullYear(),G=String(p.getMonth()+1).padStart(2,"0"),J=String(p.getDate()).padStart(2,"0"),K=`${A}-${G}-${J}`,c=new Date(t);c.setDate(c.getDate()-30);const P=c.getFullYear(),Q=String(c.getMonth()+1).padStart(2,"0"),R=String(c.getDate()).padStart(2,"0"),U=`${P}-${Q}-${R}`,h=new Date(t);h.setDate(h.getDate()+7);const Z=h.getFullYear(),_=String(h.getMonth()+1).padStart(2,"0"),tt=String(h.getDate()).padStart(2,"0"),et=`${Z}-${_}-${tt}`,u=new Date(t);u.setDate(u.getDate()+30);const at=u.getFullYear(),nt=String(u.getMonth()+1).padStart(2,"0"),rt=String(u.getDate()).padStart(2,"0"),lt=`${at}-${nt}-${rt}`,y=new Date(t.getFullYear(),t.getMonth(),1),it=y.getFullYear(),st=String(y.getMonth()+1).padStart(2,"0"),dt=String(y.getDate()).padStart(2,"0"),gt=`${it}-${st}-${dt}`,w=new Date(t.getFullYear(),t.getMonth()+1,0),ot=w.getFullYear(),mt=String(w.getMonth()+1).padStart(2,"0"),pt=String(w.getDate()).padStart(2,"0"),ct=`${ot}-${mt}-${pt}`;return{today:o,yesterday:L,tomorrow:z,last7Days:K,last30Days:U,next7Days:et,next30Days:lt,thisMonthStart:gt,thisMonthEnd:ct}},a=W,I=E(),B=!!(a?.min||a?.max),b=t=>{const n=t==="start",g=n?a?.min:a?.max;return e("div",{style:{padding:"var(--gap-md)"},children:k("div",{style:{display:"flex",flexDirection:"column",gap:"var(--gap-md)"},children:[e("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--gap-sm)"},children:(n?["today","yesterday","last7Days","last30Days","thisMonthStart"]:["today","tomorrow","next7Days","next30Days","thisMonthEnd"]).map(r=>{const o=I[r];return e(x,{variant:"outline",onClick:()=>{D({min:n?o:a?.min||"",max:n?a?.max||"":o}),i(!1)},children:l(`filter.${r}`,{defaultValue:r})},r)})}),e(St,{selected:g?new Date(g+"T00:00:00"):void 0,mode:"single",onSelect:r=>{if(!r)return;const o=r.getFullYear(),s=String(r.getMonth()+1).padStart(2,"0"),v=String(r.getDate()).padStart(2,"0"),f=`${o}-${s}-${v}`;D({min:n?f:a?.min||"",max:n?a?.max||"":f}),i(!1)},defaultMonth:g?new Date(g+"T00:00:00"):new Date}),e(x,{variant:"ghost",display:"compact",onClick:()=>{D({min:n?"":a?.min||"",max:n&&a?.max||""}),i(!1)},children:l("filter.clear")})]})})},j=k(ht,{children:[e(N,{trigger:e(x,{variant:"ghost",onClick:()=>{$("start"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingInlineStart:"var(--gap-md)",justifyContent:"flex-start"},children:a?.min?Y(a.min):e(M,{as:"span",level:"small",variant:"muted",children:l("filter.min")})}),title:`${S} - ${l("filter.min")}`,open:F&&C==="start",onOpenChange:t=>{i(t),t||$(null)},children:b("start")}),e(M,{level:"small",variant:"muted",className:"dndev-range-input-separator",children:"\u2013"}),e(N,{trigger:e(x,{variant:"ghost",onClick:()=>{$("end"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingInlineStart:"var(--gap-md)",justifyContent:"flex-start"},children:a?.max?Y(a.max):e(M,{as:"span",level:"small",variant:"muted",children:l("filter.max")})}),title:`${S} - ${l("filter.max")}`,open:F&&C==="end",onOpenChange:t=>{i(t),t||$(null)},children:b("end")}),e("button",{type:"button",className:"dndev-inline-action-btn",onClick:()=>{D(void 0)},disabled:!B,"aria-label":l("filter.clear"),children:e(ut,{})})]});return S?e(Dt,{label:S,children:e("div",{className:"dndev-range-input",children:j})}):e("div",{className:"dndev-range-input",children:j})}export{ft as DateFilter};
@@ -15,13 +15,28 @@ export interface EntityFiltersProps<T extends Record<string, any> & {
15
15
  variant?: 'inline' | 'sidebar';
16
16
  /**
17
17
  * Override grid columns. Default for inline: as many columns of at least 14rem
18
- * as the container fits (the filter panel's own width, not the viewport); 1 for sidebar.
18
+ * as the container fits (the filter panel's own width, not the viewport), at most
19
+ * 2 below laptop; 1 for sidebar. Inline, the clear button sits beside the filters
20
+ * when they all fit on one row, else on its own full-width line below.
19
21
  */
20
22
  cols?: GridCols;
21
23
  /** Optional: Data array to extract unique values and min/max from (if not provided, fetches automatically) */
22
24
  data?: T[];
23
25
  /** Current viewer role — defaults to 'guest'. Fields with visibility above this role are hidden. */
24
26
  viewerRole?: string;
27
+ /**
28
+ * Key of the filter state in CrudStore (read it with `useCrudFilters({ collection: filterKey })`).
29
+ * Default: the entity's collection, shared with the lists of that collection.
30
+ * Give a separate key to filters that must not affect them (e.g. a picker dialog).
31
+ * @since 0.2.5
32
+ */
33
+ filterKey?: string;
34
+ /**
35
+ * Sync the filter state with the URL (`f_<field>` params). Default: on for the
36
+ * entity's collection key, off with a `filterKey` (see `useCrudFilters` `urlSync`).
37
+ * @since 0.3.0
38
+ */
39
+ urlSync?: boolean;
25
40
  }
26
41
  /**
27
42
 
@@ -31,7 +46,10 @@ export interface EntityFiltersProps<T extends Record<string, any> & {
31
46
 
32
47
  * Features:
33
48
 
34
- * - String/Select fields: Combobox with unique values
49
+ * - Select/radio/multiselect/reference fields: multi-select Combobox (exact match,
50
+ * OR within the field; reference options labelled like list cells; a field's
51
+ * `filter.wildcard` value is never offered and matches every option)
52
+ * - Text fields: Combobox with the unique values (substring match)
35
53
 
36
54
  * - Number fields: Min/Max inputs + Slider (2 rows)
37
55
 
@@ -39,12 +57,13 @@ export interface EntityFiltersProps<T extends Record<string, any> & {
39
57
 
40
58
  * - Filters wrap naturally with flex-wrap
41
59
 
42
- * - Clear individual filters or all filters
60
+ * - Clear individual filters (chips with option labels) or all filters
61
+ * - URL sync of the entity collection's state (`urlSync`, CRUD.md "Filters")
43
62
 
44
63
  */
45
64
  export declare function EntityFilters<T extends Record<string, any> & {
46
65
  id: string;
47
66
  } = Record<string, any> & {
48
67
  id: string;
49
- }>({ entity, data: dataProp, fieldsToFilter, variant, cols, viewerRole, }: EntityFiltersProps<T>): import("react").JSX.Element | null;
68
+ }>({ entity, data: dataProp, fieldsToFilter, variant, cols, viewerRole, filterKey, urlSync, }: EntityFiltersProps<T>): import("react").JSX.Element | null;
50
69
  //# sourceMappingURL=EntityFilters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityFilters.d.ts","sourceRoot":"","sources":["../../src/components/EntityFilters.tsx"],"names":[],"mappings":"AAsDA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAkBhD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AASvD,6FAA6F;AAC7F,MAAM,WAAW,kBAAkB,CAEjC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IACrE,EAAE,EAAE,MAAM,CAAC;CACZ;IAED,4BAA4B;IAC5B,MAAM,EAAE,SAAS,CAAC;IAElB,oFAAoF;IACpF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B,sFAAsF;IACtF,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAE/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IAEhB,8GAA8G;IAC9G,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;IACX,oGAAoG;IACpG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,wBAAgB,aAAa,CAE3B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IACrE,EAAE,EAAE,MAAM,CAAC;CACZ,EACD,EACA,MAAM,EACN,IAAI,EAAE,QAAQ,EACd,cAAc,EACd,OAAkB,EAClB,IAAI,EACJ,UAAoB,EACpB,SAAS,EACT,OAAO,GACR,EAAE,kBAAkB,CAAC,CAAC,CAAC,sCA64BvB"}
@@ -1 +1 @@
1
- "use client";import{jsx as u,jsxs as E}from"react/jsx-runtime";import{FilterX as ye}from"lucide-react";import{useMemo as M,useState as te,useRef as he,useEffect as ve}from"react";import{Button as be,Combobox as ie,Grid as xe,Rating as Fe,RangeInput as Ce,ScrollArea as Te,Slider as je,Stack as Y,Tag as G}from"@donotdev/components";import{useTranslation as re,handleError as ae,isFieldVisible as we}from"@donotdev/core";import{DateFilter as Ee}from"./DateFilter";import{YearFilter as Se}from"./YearFilter";import{getFilterType as le,isFilterable as Ae}from"../fieldTypeRegistry";import{translateFieldLabel as ne,translateLabel as D}from"../forms/utils";import{useCrudFilters as Ve}from"../hooks/useCrudFilters";import{useCrudCardList as Me}from"../useCrudCardList";import{matchesFilter as Ne}from"../utils/matchesFilter";import{matchesFilter as Oe}from"../utils/matchesFilter";const $e="repeat(auto-fill, minmax(min(100%, 14rem), 1fr))";function ke({entity:c,data:W,fieldsToFilter:N,variant:se="inline",cols:oe,viewerRole:X="guest"}){const z=se==="sidebar",{t:x,i18n:me}=re("crud"),{t:F}=re(c.namespace),ce=me?.language||"en",{data:ue}=Me(c,{enabled:!W}),C=W??(ue?.items||[]),{filters:T,setFilters:q}=Ve({collection:c.collection}),[J,B]=te({}),[de,K]=te({}),O=he({});ve(()=>()=>{Object.values(O.current).forEach(clearTimeout)},[]);const fe=(e,t,l)=>{B(a=>({...a,[e]:{min:t,max:l}})),O.current[e]&&clearTimeout(O.current[e]),O.current[e]=setTimeout(()=>{f(e,{min:t,max:l})},250)},j=M(()=>(N&&N.length>0?N:c.listFields||Object.keys(c.fields)).filter(e=>{const t=c.fields[e],l=t?.type||"text";return!(!Ae(l)||!we(t?.visibility??"guest",X))}),[N,c.listFields,c.fields,X]),U=M(()=>{const e={};return j.forEach(t=>{const l=Object.fromEntries(Object.entries(T).filter(([a])=>a!==t));if(Object.keys(l).length===0){e[t]=C;return}e[t]=C.filter(a=>Object.entries(l).every(([o,m])=>{const d=a[o],h=c.fields[o]?.type||"text";return Ne(d,m,h)}))}),e},[C,T,c.fields,j]),Z=M(()=>{const e={};return j.forEach(t=>{const l=c.fields[t];if(!l)return;const a=l.type||"text",o=le(a);if(!o){ae(new Error(`Field type "${a}" not registered in field type registry`),{userMessage:`Field type "${a}" is missing from registry`,context:{fieldType:a,fieldName:t,operation:"minmax_computation",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"});return}const m=o==="range"&&a==="year",d=o==="range"&&!m&&(a==="date"||a==="datetime-local"||a==="timestamp"||a==="time"||a==="week"||a==="month"),h=o==="range"&&!d&&!m,S=a==="price";if(h||m||S){const p=C.map(r=>r[t]).filter(r=>r!=null&&r!=="").map(r=>S&&typeof r=="object"&&r!==null?Number(r.amount):typeof r=="number"?r:Number(r)).filter(r=>!isNaN(r));p.length>0&&(e[t]={min:Math.min(...p),max:Math.max(...p)})}else if(d){const p=C.map(r=>r[t]).filter(r=>r!=null&&r!=="").map(r=>r instanceof Date?r:new Date(r)).filter(r=>!isNaN(r.getTime()));if(p.length>0){const r=new Date(Math.min(...p.map(w=>w.getTime()))),$=new Date(Math.max(...p.map(w=>w.getTime()))),v=r.toISOString().split("T")[0],A=$.toISOString().split("T")[0];e[t]={min:v||"",max:A||""}}}}),e},[C,c.fields,j]),f=(e,t)=>{const l={...T};if(!t||t==="")delete l[e];else if(Array.isArray(t))l[e]=t;else if(typeof t=="object"&&"min"in t){const a=t.min&&t.min!=="",o=t.max&&t.max!=="";!a&&!o?delete l[e]:l[e]=t}else l[e]=t;q(l)},pe=()=>{q({})},I=M(()=>j.length===0?null:j.map(e=>{const t=c.fields[e];if(!t)return null;const l=ne(e,t,F),a=t.type||"text",o=le(a);if(!o)return ae(new Error(`Field type "${a}" not registered in field type registry`),{userMessage:`Field type "${a}" is missing from registry`,context:{fieldType:a,fieldName:e,operation:"filter_ui_render",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"}),null;const m=o==="range"&&a==="year",d=o==="range"&&!m&&(a==="date"||a==="datetime-local"||a==="timestamp"||a==="time"||a==="week"||a==="month"),h=o==="range"&&!d&&!m,S=o==="select",p=o==="multiselect",r=T[e],$=typeof r=="object"&&r!==null&&"min"in r,v=$?r:{min:"",max:""},A={gridColumn:z?"span 1":"span 2"};if(o==="rating"){const s=t.validation?.max??5,n=typeof r=="string"&&r!==""?Number(r):0;return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(Fe,{value:n,max:s,"aria-label":l,onChange:i=>{f(e,i===n?void 0:String(i))}})},e)}if(h){const s=Z[e],n=s?.min??0,i=s?.max??100,g=v.min?Number(v.min):n,_=v.max?Number(v.max):i;return E(Y,{gap:"tight",style:A,children:[u(Ce,{type:"number",label:l,minPlaceholder:x("filter.min",{defaultValue:"Min"}),maxPlaceholder:x("filter.max",{defaultValue:"Max"}),minValue:J[e]?.min??v.min??"",maxValue:J[e]?.max??v.max??"",actualMin:n,actualMax:i,onChange:(y,b)=>fe(e,y,b),onClear:()=>{B(y=>{const b={...y};return delete b[e],b}),K(y=>{const b={...y};return delete b[e],b}),f(e,void 0)}}),u(je,{value:de[e]??[g,_],min:n,max:i,step:1,onValueChange:y=>K(b=>({...b,[e]:y})),onValueCommit:y=>{B(b=>({...b,[e]:{min:String(y[0]),max:String(y[1])}})),f(e,{min:String(y[0]),max:String(y[1])})}},`${e}-${v.min??""}-${v.max??""}`)]},e)}if(m){const s=Z[e];return u("div",{style:A,children:u(Se,{label:l,value:$?v:void 0,onChange:n=>f(e,n),tCrud:x,minYear:s?.min??t.validation?.min,maxYear:s?.max??t.validation?.max})},e)}if(d){const s=a==="week"||a==="month"?a:"date",n=(()=>{if(r){if(typeof r=="object"&&"min"in r){const i=r;return{min:i.min&&i.min.split("T")[0]||"",max:i.max&&i.max.split("T")[0]||""}}if(typeof r=="string"){const i=r.split("T")[0]||"";return{min:i,max:i}}}})();return u("div",{style:A,children:u(Ee,{label:l,fieldType:s,value:n,locale:ce,onChange:i=>{if(!i){f(e,void 0);return}typeof i=="object"&&"min"in i&&f(e,{min:i.min||"",max:i.max||""})},tCrud:x})},e)}const w=(S||p)&&t.validation&&"options"in t.validation&&t.validation?Array.isArray(t.validation.options)?t.validation.options:typeof t.validation.options=="function"?t.validation.options():[]:[],P=U[e]||C,k=new Set,ee=o==="address";P.forEach(s=>{const n=s[e];if(n!=null)if(ee&&typeof n=="object"&&"formatted_address"in n){const i=n;i.formatted_address&&k.add(String(i.formatted_address))}else k.add(String(n))});const R=new Map;P.forEach(s=>{const n=s[e];if(n!=null){const i=ee&&typeof n=="object"&&"formatted_address"in n?String(n.formatted_address):String(n);R.set(i,(R.get(i)||0)+1)}});const V=[{value:"all",label:x("filter.selectPlaceholder",{defaultValue:"All"}),count:P.length}];if(w.length>0){const s=[],n=[];w.forEach(i=>{const g=typeof i=="string"?i:i.value,_=typeof i=="string"?i:i.label;k.has(g)?s.push({value:g,label:_}):n.push({value:g,label:_})}),s.sort((i,g)=>i.label.localeCompare(g.label)),n.sort((i,g)=>i.label.localeCompare(g.label)),s.forEach(i=>{V.push({value:i.value,label:D(i.label,F),disabled:!1,count:R.get(i.value)??0})}),n.forEach(i=>{V.push({value:i.value,label:D(i.label,F),disabled:!0,count:0})})}else Array.from(k).sort().slice(0,100).forEach(s=>{V.push({value:s,label:s,count:R.get(s)??0})});if(p){const s=V.filter(i=>i.value!=="all"),n=Array.isArray(r)?r:[];return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(ie,{label:l,value:n,onValueChange:i=>{const g=Array.isArray(i)?i:[i];f(e,g.length>0?g:void 0)},options:s,placeholder:x("filter.placeholder",{defaultValue:"Filter..."}),multiple:!0,clearable:!0})},e)}return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(ie,{label:l,value:typeof r=="string"?r:void 0,onValueChange:s=>{f(e,s==="all"||!s?"":String(s))},options:V,placeholder:x("filter.placeholder",{defaultValue:"Filter..."}),clearable:!0})},e)}),[j,c.fields,C,T,F,x,U]);if(!I||I.length===0)return null;const ge=I.filter(Boolean),L=Object.keys(T).length>0,H=M(()=>{if(!L)return null;const e=[];return Object.entries(T).forEach(([t,l])=>{const a=c.fields[t];if(!a)return;const o=ne(t,a,F);if(typeof l=="string"){const m=a.validation&&"options"in a.validation?D(l,F):l;e.push(E(G,{size:"sm",variant:"outline",onRemove:()=>f(t,void 0),children:[o,": ",m]},t))}else if(Array.isArray(l))l.forEach((m,d)=>{e.push(E(G,{size:"sm",variant:"outline",onRemove:()=>{const h=l.filter((S,p)=>p!==d);f(t,h.length>0?h:void 0)},children:[o,": ",D(m,F)]},`${t}-${d}`))});else if(typeof l=="object"&&"min"in l){const m=l,d=[];m.min&&d.push(m.min),m.max&&d.push(m.max);const h=d.join(" - ");h&&e.push(E(G,{size:"sm",variant:"outline",onRemove:()=>f(t,void 0),children:[o,": ",h]},t))}}),e.length>0?e:null},[T,c.fields,F,x,L]),Q=E(Y,{direction:"column",gap:"tight",children:[H&&u(Y,{direction:"row",gap:"tight",style:{flexWrap:"wrap"},children:H}),E(xe,{cols:oe??(z?1:$e),children:[ge,u(be,{variant:"outline",icon:u(ye,{size:18}),onClick:pe,disabled:!L,style:{gridColumn:"1 / -1",gridRow:"span 1"},children:x("filter.clear",{defaultValue:"Clear Filters"})})]})]});return z?u(Te,{style:{maxHeight:"100%"},children:Q}):Q}export{ke as EntityFilters,Oe as matchesFilter};
1
+ "use client";import{jsx as u,jsxs as A}from"react/jsx-runtime";import{FilterX as _e}from"lucide-react";import{useMemo as _,useState as fe,useRef as Me,useEffect as Oe}from"react";import{Button as ke,Combobox as ue,Grid as de,Rating as Le,RangeInput as Ve,ScrollArea as De,Slider as ze,Stack as M,Tag as K}from"@donotdev/components";import{useTranslation as pe,handleError as ge,isFieldVisible as Be}from"@donotdev/core";import{DateFilter as Ie}from"./DateFilter";import{YearFilter as Pe}from"./YearFilter";import{getFilterType as O,isFilterable as Ye}from"../fieldTypeRegistry";import{translateFieldLabel as he,translateLabel as ye}from"../forms/utils";import{useCrudFilters as Ge}from"../hooks/useCrudFilters";import{useReferenceResolver as He}from"../hooks/useReferenceResolver";import{useCrudCardList as Ke}from"../useCrudCardList";import{matchesFilter as We}from"../utils/matchesFilter";import{matchesFilter as Xe}from"../utils/matchesFilter";const W="14rem",ve=`repeat(auto-fit, minmax(max(min(100%, ${W}), calc((100% - var(--gap-md)) / 2)), 1fr))`,xe=`repeat(auto-fit, minmax(min(100%, ${W}), 1fr))`,qe=[ve,ve,xe,xe],Ze={flex:"1 1 auto"},X="__dndev_filter_any__";function be(l){const T=l.validation;return(typeof T?.options=="function"?T.options():T?.options??[]).map(p=>typeof p=="string"?{value:p,label:p}:p)}function Je(l,T){if(l==null)return[];if(Array.isArray(l))return l.filter(p=>p!=null).map(String);if(T&&typeof l=="object"&&"formatted_address"in l){const p=l.formatted_address;return p?[String(p)]:[]}return[String(l)]}function Qe({entity:l,data:T,fieldsToFilter:p,variant:Fe="inline",cols:q,viewerRole:Z="guest",filterKey:Ce,urlSync:Te}){const k=Fe==="sidebar",{t:d,i18n:je}=pe("crud"),{t:$}=pe([l.namespace,"crud"]),we=je?.language||"en",{data:Se}=Ke(l,{enabled:!T}),j=T??(Se?.items||[]),{filters:w,setFilters:J}=Ge({collection:Ce??l.collection,urlSync:Te,entity:l}),[Q,I]=fe({}),[Ee,U]=fe({}),L=Me({});Oe(()=>()=>{Object.values(L.current).forEach(clearTimeout)},[]);const Ae=(e,t,n)=>{I(i=>({...i,[e]:{min:t,max:n}})),L.current[e]&&clearTimeout(L.current[e]),L.current[e]=setTimeout(()=>{h(e,{min:t,max:n})},250)},C=_(()=>(p&&p.length>0?p:l.listFields||Object.keys(l.fields)).filter(e=>{const t=l.fields[e],n=t?.type||"text";return!(!Ye(n)||!Be(t?.visibility??"guest",Z))}),[p,l.listFields,l.fields,Z]),$e=C.some(e=>O(l.fields[e]?.type||"text")==="reference"),P=He(l,$e),Y=(e,t)=>{if(O(e.type||"text")==="reference"){const i=e.validation?.reference;return(typeof i=="string"?P[i]?.[t]:void 0)??t}const n=be(e).find(i=>i.value===t);return n?ye(n.label,$):t},ee=_(()=>{const e={};return C.forEach(t=>{const n=Object.fromEntries(Object.entries(w).filter(([i])=>i!==t));if(Object.keys(n).length===0){e[t]=j;return}e[t]=j.filter(i=>Object.entries(n).every(([o,f])=>{const g=i[o],y=l.fields[o],S=y?.type||"text";return We(g,f,S,y?.filter)}))}),e},[j,w,l.fields,C]),te=_(()=>{const e={};return C.forEach(t=>{const n=l.fields[t];if(!n)return;const i=n.type||"text",o=O(i);if(!o){ge(new Error(`Field type "${i}" not registered in field type registry`),{userMessage:`Field type "${i}" is missing from registry`,context:{fieldType:i,fieldName:t,operation:"minmax_computation",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"});return}const f=o==="range"&&i==="year",g=o==="range"&&!f&&(i==="date"||i==="datetime-local"||i==="timestamp"||i==="time"||i==="week"||i==="month"),y=o==="range"&&!g&&!f,S=i==="price";if(y||f||S){const v=j.map(s=>s[t]).filter(s=>s!=null&&s!=="").map(s=>S&&typeof s=="object"&&s!==null?Number(s.amount):typeof s=="number"?s:Number(s)).filter(s=>!isNaN(s));v.length>0&&(e[t]={min:Math.min(...v),max:Math.max(...v)})}else if(g){const v=j.map(s=>s[t]).filter(s=>s!=null&&s!=="").map(s=>s instanceof Date?s:new Date(s)).filter(s=>!isNaN(s.getTime()));if(v.length>0){const s=new Date(Math.min(...v.map(E=>E.getTime()))),m=new Date(Math.max(...v.map(E=>E.getTime()))),V=s.toISOString().split("T")[0],b=m.toISOString().split("T")[0];e[t]={min:V||"",max:b||""}}}}),e},[j,l.fields,C]),h=(e,t)=>{const n={...w};if(!t||t==="")delete n[e];else if(Array.isArray(t))n[e]=t;else if(typeof t=="object"&&"min"in t){const i=t.min&&t.min!=="",o=t.max&&t.max!=="";!i&&!o?delete n[e]:n[e]=t}else n[e]=t;J(n)},Re=()=>{J({})},G=_(()=>C.length===0?null:C.map(e=>{const t=l.fields[e];if(!t)return null;const n=he(e,t,$),i=t.type||"text",o=O(i);if(!o)return ge(new Error(`Field type "${i}" not registered in field type registry`),{userMessage:`Field type "${i}" is missing from registry`,context:{fieldType:i,fieldName:e,operation:"filter_ui_render",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"}),null;const f=o==="range"&&i==="year",g=o==="range"&&!f&&(i==="date"||i==="datetime-local"||i==="timestamp"||i==="time"||i==="week"||i==="month"),y=o==="range"&&!g&&!f,S=o==="select",v=o==="multiselect",s=o==="reference",m=w[e],V=typeof m=="object"&&m!==null&&"min"in m,b=V?m:{min:"",max:""},E={gridColumn:k?"span 1":"span 2"};if(o==="rating"){const a=t.validation?.max??5,c=typeof m=="string"&&m!==""?Number(m):0;return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(Le,{value:c,max:a,"aria-label":n,onChange:r=>{h(e,r===c?void 0:String(r))}})},e)}if(y){const a=te[e],c=a?.min??0,r=a?.max??100,R=b.min?Number(b.min):c,B=b.max?Number(b.max):r;return A(M,{gap:"tight",style:E,children:[u(Ve,{type:"number",label:n,minPlaceholder:d("filter.min"),maxPlaceholder:d("filter.max"),minValue:Q[e]?.min??b.min??"",maxValue:Q[e]?.max??b.max??"",actualMin:c,actualMax:r,onChange:(x,F)=>Ae(e,x,F),onClear:()=>{I(x=>{const F={...x};return delete F[e],F}),U(x=>{const F={...x};return delete F[e],F}),h(e,void 0)}}),u(ze,{value:Ee[e]??[R,B],min:c,max:r,step:1,onValueChange:x=>U(F=>({...F,[e]:x})),onValueCommit:x=>{I(F=>({...F,[e]:{min:String(x[0]),max:String(x[1])}})),h(e,{min:String(x[0]),max:String(x[1])})}},`${e}-${b.min??""}-${b.max??""}`)]},e)}if(f){const a=te[e];return u("div",{style:E,children:u(Pe,{label:n,value:V?b:void 0,onChange:c=>h(e,c),tCrud:d,minYear:a?.min??t.validation?.min,maxYear:a?.max??t.validation?.max})},e)}if(g){const a=i==="week"||i==="month"?i:"date",c=(()=>{if(m){if(typeof m=="object"&&"min"in m){const r=m;return{min:r.min&&r.min.split("T")[0]||"",max:r.max&&r.max.split("T")[0]||""}}if(typeof m=="string"){const r=m.split("T")[0]||"";return{min:r,max:r}}}})();return u("div",{style:E,children:u(Ie,{label:n,fieldType:a,value:c,locale:we,onChange:r=>{if(!r){h(e,void 0);return}typeof r=="object"&&"min"in r&&h(e,{min:r.min||"",max:r.max||""})},tCrud:d})},e)}const D=t.filter?.wildcard,se=S||v?be(t).filter(a=>a.value!==D):[],oe=ee[e]||j,Ne=o==="address",z=new Map;let me=0;oe.forEach(a=>{const c=new Set(Je(a[e],Ne));if(D!==void 0&&c.has(D)){me+=1;return}c.forEach(r=>z.set(r,(z.get(r)??0)+1))});const ce=a=>(z.get(a)??0)+me,N=[{value:X,label:d("filter.selectPlaceholder"),count:oe.length}];if(se.length>0){const a=se.map(r=>({value:r.value,label:ye(r.label,$),count:ce(r.value)})),c=(r,R)=>r.label.localeCompare(R.label);a.filter(r=>r.count>0).sort(c).forEach(r=>N.push({...r,disabled:!1})),a.filter(r=>r.count===0).sort(c).forEach(r=>N.push({...r,disabled:!0}))}else Array.from(z.keys()).filter(a=>a!==D).map(a=>({value:a,label:s?Y(t,a):a,count:ce(a)})).sort((a,c)=>a.label.localeCompare(c.label)).slice(0,100).forEach(a=>N.push(a));if(S||v||s){const a=N.filter(r=>r.value!==X),c=Array.isArray(m)?m:typeof m=="string"&&m!==""?[m]:[];return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(ue,{label:n,value:c,onValueChange:r=>{const R=(Array.isArray(r)?r:[r]).filter(B=>typeof B=="string"&&B!=="");h(e,R.length>0?R:void 0)},options:a,placeholder:d("filter.placeholder"),selectedLabel:d("filters.selected",{count:c.length}),multiple:!0,clearable:!0,clearLabel:d("filter.clear")})},e)}return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(ue,{label:n,value:typeof m=="string"?m:void 0,onValueChange:a=>{h(e,a===X||!a?"":String(a))},options:N,placeholder:d("filter.placeholder"),clearable:!0,clearLabel:d("filter.clear")})},e)}),[C,l.fields,j,w,$,d,ee,P]),H=Object.keys(w).length>0,ie=_(()=>{if(!H)return null;const e=[];return Object.entries(w).forEach(([t,n])=>{const i=l.fields[t];if(!i)return;const o=he(t,i,$);if(typeof n=="string"){const f=Y(i,n);e.push(A(K,{size:"sm",variant:"outline",removeLabel:d("form.remove"),onRemove:()=>h(t,void 0),children:[o,": ",f]},t))}else if(Array.isArray(n))n.forEach((f,g)=>{e.push(A(K,{size:"sm",variant:"outline",removeLabel:d("form.remove"),onRemove:()=>{const y=n.filter((S,v)=>v!==g);h(t,y.length>0?y:void 0)},children:[o,": ",Y(i,f)]},`${t}-${g}`))});else if(typeof n=="object"&&"min"in n){const f=n,g=[];f.min&&g.push(f.min),f.max&&g.push(f.max);const y=g.join(" - ");y&&e.push(A(K,{size:"sm",variant:"outline",removeLabel:d("form.remove"),onRemove:()=>h(t,void 0),children:[o,": ",y]},t))}}),e.length>0?e:null},[w,l.fields,$,d,H,P]);if(!G||G.length===0)return null;const re=G.filter(Boolean),ne=u(ke,{variant:"outline",icon:u(_e,{size:18}),onClick:Re,disabled:!H,style:k?void 0:Ze,children:d("filter.clear")}),ae=C.reduce((e,t)=>{const n=l.fields[t];if(!n)return e;const i=O(n.type||"text");return i?e+(i==="range"?2:1):e},0),le=A(M,{direction:"column",gap:"tight",children:[ie&&u(M,{direction:"row",gap:"tight",style:{flexWrap:"wrap"},children:ie}),k?A(M,{direction:"column",gap:"medium",children:[u(de,{cols:q??1,children:re}),ne]}):A(M,{direction:"row",wrap:"wrap",align:"end",gap:"medium",children:[u(de,{cols:q??qe,style:{flex:`999 1 calc(${ae} * ${W} + ${ae-1} * var(--gap-md))`},children:re}),ne]})]});return k?u(De,{style:{maxHeight:"100%"},children:le}):le}export{Qe as EntityFilters,Xe as matchesFilter};
@@ -5,6 +5,22 @@ interface FormFieldRendererBaseProps<T extends FieldType = FieldType> {
5
5
  name: string;
6
6
  config: EntityField<T>;
7
7
  t: (key: string, options?: Record<string, any>) => string;
8
+ /**
9
+ * Offer only these values of the field's declared `validation.options`, in this order
10
+ * (select, multiselect, radio, combobox). For a form that lets the user pick a subset,
11
+ * e.g. the reasons a person may record while the database writes the others.
12
+ *
13
+ * Display only: form validation still accepts every declared value, and a stored value
14
+ * outside the subset is not offered. Throws when the field declares no static options
15
+ * or when a value is not one of them.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * <FormFieldRenderer name="reason" config={config} control={form.control} t={t}
20
+ * onlyOptions={['breakage', 'loss', 'theft']} />
21
+ * ```
22
+ */
23
+ onlyOptions?: readonly string[];
8
24
  }
9
25
  interface UncontrolledProps<T extends FieldType> extends FormFieldRendererBaseProps<T> {
10
26
  value: ValueTypeForField<T>;
@@ -12,17 +28,18 @@ interface UncontrolledProps<T extends FieldType> extends FormFieldRendererBasePr
12
28
  error?: string;
13
29
  control?: never;
14
30
  }
15
- interface ControlledProps<T extends FieldType, TFieldValues extends FieldValues = FieldValues> extends FormFieldRendererBaseProps<T> {
16
- control: Control<TFieldValues>;
31
+ interface ControlledProps<T extends FieldType, TFieldValues extends FieldValues = FieldValues, TTransformedValues = TFieldValues> extends FormFieldRendererBaseProps<T> {
32
+ /** The form's control (`form.control`: form state, submitted values) */
33
+ control: Control<TFieldValues, unknown, TTransformedValues>;
17
34
  value?: never;
18
35
  onChange?: never;
19
36
  error?: never;
20
37
  }
21
38
  /** Props for {@link FormFieldRenderer}, dispatches to the correct field component via FieldRegistry. */
22
- export type FormFieldRendererProps<T extends FieldType, TFieldValues extends FieldValues = FieldValues> = UncontrolledProps<T> | ControlledProps<T, TFieldValues>;
39
+ export type FormFieldRendererProps<T extends FieldType, TFieldValues extends FieldValues = FieldValues, TTransformedValues = TFieldValues> = UncontrolledProps<T> | ControlledProps<T, TFieldValues, TTransformedValues>;
23
40
  /**
24
41
  * FormFieldRenderer - renders fields via registry lookup
25
42
  */
26
- export declare function FormFieldRenderer<T extends FieldType, TFieldValues extends FieldValues = FieldValues>({ name, config, t, ...props }: FormFieldRendererProps<T, TFieldValues>): ReactElement;
43
+ export declare function FormFieldRenderer<T extends FieldType, TFieldValues extends FieldValues = FieldValues, TTransformedValues = TFieldValues>({ name, config, t, onlyOptions, ...props }: FormFieldRendererProps<T, TFieldValues, TTransformedValues>): ReactElement;
27
44
  export default FormFieldRenderer;
28
45
  //# sourceMappingURL=FormFieldRenderer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormFieldRenderer.d.ts","sourceRoot":"","sources":["../../src/components/FormFieldRenderer.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI5D,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAUhF,UAAU,0BAA0B,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAClE,IAA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AAK,CAAC;CACf;AAED,wGAAwG;AACxG,MAAM,MAAM,sBAAsB,CAChC,CAAC,SAAS,SAAS,EACnB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,kBAAkB,GAAG,YAAY,IAE/B,iBAAiB,CAAC,CAAC,CAAC,GACpB,eAAe,CAAC,CAAC,EAAE,YAAY,EAAE,kBAAkB,CAAC,CAAC;AAqCzD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,SAAS,SAAS,EACnB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,kBAAkB,GAAG,YAAY,EACjC,EACA,IAAI,EACJ,MAAM,EACN,CAAC,EACD,WAAW,EACX,GAAG,KAAK,EACT,EAAE,sBAAsB,CAAC,CAAC,EAAE,YAAY,EAAE,kBAAkB,CAAC,GAAG,YAAY,CA4F5E;AAED,eAAe,iBAAiB,CAAC"}
@@ -1 +1 @@
1
- "use client";import{jsx as r}from"react/jsx-runtime";import{Suspense as x}from"react";import{Skeleton as F}from"@donotdev/components";import{handleError as h}from"@donotdev/core";import{getFieldRegistry as T}from"../FieldRegistry";import{getMetadataRegistry as w}from"../fieldTypeRegistry.store";import{ControlledTextField as E}from"./controlled";import{TextFieldComponent as M}from"./form/fields";const S={height:"2.5rem",width:"100%"};function v({name:t,config:e,t:n,...l}){const s=o=>i=>{try{o(i)}catch(a){h(a,{userMessage:`Error updating field ${e.label||t}`,context:{fieldName:t,fieldType:e.type},severity:"warning"})}};w();const p=T(),d="control"in l&&l.control,f=e.type==="submit"||e.type==="reset";if(d&&!f){const{control:o}=l,i=e.options?.fieldSpecific?.placeholder,a={control:o,fieldConfig:{...e,label:e.label||t},t:n,placeholder:i,required:e.validation?.required===!0,onChange:s(()=>{})},u=p.getControlledComponent(e.type);return u?r(x,{fallback:r(F,{style:S}),children:r(u,{...a})}):(h(new Error(`Unregistered field type: ${e.type}`),{userMessage:n("errors.unsupportedFieldType",{type:e.type}),context:{fieldName:t,fieldType:e.type},severity:"warning"}),r(E,{...a,fieldConfig:{...e,type:"text"}}))}const C=d&&f?{name:t,config:e,t:n,value:void 0,onChange:()=>{},error:void 0}:l,{value:m,onChange:b,error:c}=C,g=s(b),y=p.getUncontrolledComponent(e.type);return y?r(y,{name:t,label:e.label||t,value:m,onChange:g,error:c,t:n,config:e,...e.options}):r(M,{label:e.label||t,value:m,onChange:o=>g(o.target.value),error:c||void 0,...e.options})}var N=v;export{v as FormFieldRenderer,N as default};
1
+ "use client";import{jsx as p}from"react/jsx-runtime";import{Suspense as v}from"react";import{Skeleton as w}from"@donotdev/components";import{handleError as b}from"@donotdev/core";import{getFieldRegistry as C}from"../FieldRegistry";import{getMetadataRegistry as F}from"../fieldTypeRegistry.store";function $(o,e,i){const n=o.validation?.options;if(!Array.isArray(n))throw new Error(`FormFieldRenderer: field "${e}" got onlyOptions but declares no static validation.options.`);const a=i.map(l=>{const s=n.find(r=>r.value===l);if(!s)throw new Error(`FormFieldRenderer: onlyOptions value "${l}" is not an option of field "${e}" (declared: ${n.map(r=>r.value).join(", ")}).`);return s});return{...o,validation:{...o.validation,options:a}}}const R={height:"2.5rem",width:"100%"};function u({name:o,config:e,t:i,onlyOptions:n,...a}){const l=n?$(e,o,n):e,s=t=>f=>{try{t(f)}catch(d){b(d,{userMessage:`Error updating field ${e.label||o}`,context:{fieldName:o,fieldType:e.type},severity:"warning"})}};F();const r=C(),c=()=>new Error(`FormFieldRenderer: field "${o}" has type "${e.type}", which has no registered component. Call registerFieldType({ type: '${e.type}', ... }) at app startup.`);if(e.type==="submit"||e.type==="reset"){const t=r.getUncontrolledComponent(e.type);if(!t)throw c();return p(t,{name:o,label:e.label||o,value:void 0,onChange:()=>{},t:i,config:e,...e.options})}if(a.control){const t=e.options?.fieldSpecific?.placeholder,f={control:a.control,fieldConfig:{...l,label:e.label||o},t:i,placeholder:t,required:e.validation?.required===!0,onChange:s(()=>{})},d=r.getControlledComponent(e.type);if(!d)throw c();return p(v,{fallback:p(w,{style:R}),children:p(d,{...f})})}const{value:g,onChange:y,error:h}=a,m=r.getUncontrolledComponent(e.type);if(!m)throw c();return p(m,{name:o,label:e.label||o,value:g,onChange:s(y),error:h,t:i,config:l,...e.options})}var E=u;export{u as FormFieldRenderer,E as default};
@@ -1 +1 @@
1
- {"version":3,"file":"FormLayout.d.ts","sourceRoot":"","sources":["../../src/components/FormLayout.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAEpE,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAYlE,qGAAqG;AACrG,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,WAAW;IACzD,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,QAAQ,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAC5C,iCAAiC;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,sCAAsC;IACtC,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC9B,oBAAoB;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yBAAyB;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,0BAA0B;IAC1B,OAAO,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IACzC,yBAAyB;IACzB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,UAAU,GAAI,CAAC,SAAS,WAAW,EAAE,mIAaxC,oBAAo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as d,jsxs as i,Fragment as N}from"react/jsx-runtime";import{useState as w}from"react";import{FormProvider as C}from"react-hook-form";import{Button as s,BUTTON_VARIANT as j,Spinner as k,cn as z,Stack as a,Grid as A}from"@donotdev/components";import{useTranslation as B}from"@donotdev/core";const F=({title:c,onSubmit:m,children:g,formMethods:f,loading:n=!1,submitText:u,cancelText:v,showCancel:p=!1,onCancel:h,variant:o="default",columns:b=1,description:l})=>{const{t:e}=B("crud"),[r,t]=w(!1),y=u||e("form.submit","Submit"),x=v||e("form.cancel","Cancel"),S=async T=>{t(!0);try{await m(T)}finally{t(!1)}},L={1:"dndev-grid-cols-1",2:"dndev-grid-cols-1 dndev-md:grid-cols-2",3:"dndev-grid-cols-1 dndev-md:grid-cols-2 dndev-md:grid-cols-3",4:"dndev-grid-cols-1 dndev-md:grid-cols-2 dndev-md:grid-cols-4"};return d(C,{...f,children:d("form",{onSubmit:S,className:z("dndev-mx-auto",{default:"dndev-surface",card:"dndev-surface",minimal:""}[o]),style:o!=="minimal"?{padding:"var(--gap-lg)"}:void 0,role:"form","aria-labelledby":"form-title",noValidate:!0,children:i(a,{gap:"large",children:[i(a,{gap:"tight",children:[d("h2",{id:"form-title",style:{fontSize:"var(--font-size-2xl)",fontWeight:600,color:"var(--foreground)"},children:c}),l&&d("p",{style:{color:"var(--muted-foreground)"},children:l})]}),d(A,{cols:b,className:"dndev-w-full dndev-min-w-0",children:g}),i(a,{direction:"row",align:"center",justify:"end",style:{paddingTop:"var(--gap-md)",borderTop:"1px solid var(--border)"},children:[p&&d(s,{type:"button",variant:j.OUTLINE,onClick:h,disabled:n||r,children:x}),d(s,{type:"submit",disabled:n||r,style:{minWidth:"120px"},children:n||r?i(N,{children:[d(k,{className:"me-component-gap"}),r?e("form.submitting","Submitting..."):e("form.loading","Loading...")]}):y})]})]})})})};var I=F;export{I as default};
1
+ "use client";import{jsx as d,jsxs as r}from"react/jsx-runtime";import{useState as w}from"react";import{FormProvider as N}from"react-hook-form";import{Button as s,BUTTON_VARIANT as C,cn as j,Stack as n,Grid as k}from"@donotdev/components";import{useTranslation as z}from"@donotdev/core";const I=({title:c,onSubmit:m,children:g,formMethods:f,loading:o=!1,submitText:u,cancelText:v,showCancel:p=!1,onCancel:h,variant:t="default",columns:b=1,description:a})=>{const{t:e}=z("crud"),[i,l]=w(!1),y=u||e("form.submit","Submit"),x=v||e("form.cancel","Cancel"),T=async S=>{l(!0);try{await m(S)}finally{l(!1)}},V={1:"dndev-grid-cols-1",2:"dndev-grid-cols-1 dndev-md:grid-cols-2",3:"dndev-grid-cols-1 dndev-md:grid-cols-2 dndev-md:grid-cols-3",4:"dndev-grid-cols-1 dndev-md:grid-cols-2 dndev-md:grid-cols-4"};return d(N,{...f,children:d("form",{onSubmit:T,className:j("dndev-mx-auto",{default:"dndev-surface",card:"dndev-surface",minimal:""}[t]),style:t!=="minimal"?{padding:"var(--gap-lg)"}:void 0,role:"form","aria-labelledby":"form-title",noValidate:!0,children:r(n,{gap:"large",children:[r(n,{gap:"tight",children:[d("h2",{id:"form-title",style:{fontSize:"var(--font-size-2xl)",fontWeight:600,color:"var(--foreground)"},children:c}),a&&d("p",{style:{color:"var(--muted-foreground)"},children:a})]}),d(k,{cols:b,className:"dndev-w-full dndev-min-w-0",children:g}),r(n,{direction:"row",align:"center",justify:"end",style:{paddingTop:"var(--gap-md)",borderTop:"1px solid var(--border)"},children:[p&&d(s,{type:"button",intent:"cancel",variant:C.OUTLINE,onClick:h,disabled:o||i,children:x}),d(s,{type:"submit",intent:"save",loading:o||i,loadingText:i?e("form.submitting","Submitting..."):e("form.loading","Loading..."),style:{minWidth:"120px"},children:y})]})]})})})};var L=I;export{L as default};