@donotdev/crud 0.0.8 → 0.0.10

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 (370) hide show
  1. package/dist/CrudService.d.ts +30 -60
  2. package/dist/CrudService.d.ts.map +1 -1
  3. package/dist/CrudService.js +1 -1
  4. package/dist/CrudStore.d.ts +1 -94
  5. package/dist/CrudStore.d.ts.map +1 -1
  6. package/dist/CrudStore.js +1 -1
  7. package/dist/FieldRegistry.js +1 -1
  8. package/dist/adapters/FirestoreAdapter.d.ts +3 -1
  9. package/dist/adapters/FirestoreAdapter.d.ts.map +1 -1
  10. package/dist/adapters/FirestoreAdapter.js +1 -1
  11. package/dist/adapters/FunctionsAdapter.d.ts +8 -1
  12. package/dist/adapters/FunctionsAdapter.d.ts.map +1 -1
  13. package/dist/adapters/FunctionsAdapter.js +1 -1
  14. package/dist/adapters/index.js +1 -1
  15. package/dist/builtinFieldTypes.d.ts +17 -4
  16. package/dist/builtinFieldTypes.d.ts.map +1 -1
  17. package/dist/builtinFieldTypes.js +1 -1
  18. package/dist/components/CrudButton.js +1 -1
  19. package/dist/components/DisplayFieldRenderer.d.ts +2 -0
  20. package/dist/components/DisplayFieldRenderer.d.ts.map +1 -1
  21. package/dist/components/DisplayFieldRenderer.js +1 -1
  22. package/dist/components/EntityDisplayRenderer.d.ts +3 -3
  23. package/dist/components/EntityDisplayRenderer.d.ts.map +1 -1
  24. package/dist/components/EntityDisplayRenderer.js +1 -1
  25. package/dist/components/EntityFilters.d.ts +61 -0
  26. package/dist/components/EntityFilters.d.ts.map +1 -0
  27. package/dist/components/EntityFilters.js +1 -0
  28. package/dist/components/EntityFormRenderer.d.ts +22 -1
  29. package/dist/components/EntityFormRenderer.d.ts.map +1 -1
  30. package/dist/components/EntityFormRenderer.js +1 -1
  31. package/dist/components/FormFieldRenderer.d.ts.map +1 -1
  32. package/dist/components/FormFieldRenderer.js +1 -1
  33. package/dist/components/FormLayout.js +1 -1
  34. package/dist/components/controlled/complex/ControlledAddressField.d.ts +3 -0
  35. package/dist/components/controlled/complex/ControlledAddressField.d.ts.map +1 -1
  36. package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
  37. package/dist/components/controlled/complex/ControlledDateField.d.ts +3 -0
  38. package/dist/components/controlled/complex/ControlledDateField.d.ts.map +1 -1
  39. package/dist/components/controlled/complex/ControlledDateField.js +1 -1
  40. package/dist/components/controlled/complex/ControlledGeoPointField.d.ts +3 -0
  41. package/dist/components/controlled/complex/ControlledGeoPointField.d.ts.map +1 -1
  42. package/dist/components/controlled/complex/ControlledGeoPointField.js +1 -1
  43. package/dist/components/controlled/complex/ControlledMapField.d.ts +3 -0
  44. package/dist/components/controlled/complex/ControlledMapField.d.ts.map +1 -1
  45. package/dist/components/controlled/complex/ControlledMapField.js +1 -1
  46. package/dist/components/controlled/complex/ControlledMultiInputField.d.ts +3 -0
  47. package/dist/components/controlled/complex/ControlledMultiInputField.d.ts.map +1 -1
  48. package/dist/components/controlled/complex/ControlledMultiInputField.js +1 -1
  49. package/dist/components/controlled/complex/ControlledRichTextField.d.ts +3 -0
  50. package/dist/components/controlled/complex/ControlledRichTextField.d.ts.map +1 -1
  51. package/dist/components/controlled/complex/ControlledRichTextField.js +1 -1
  52. package/dist/components/controlled/complex/ControlledTimestampField.d.ts +3 -0
  53. package/dist/components/controlled/complex/ControlledTimestampField.d.ts.map +1 -1
  54. package/dist/components/controlled/complex/ControlledTimestampField.js +1 -1
  55. package/dist/components/controlled/complex/index.d.ts.map +1 -1
  56. package/dist/components/controlled/complex/index.js +1 -1
  57. package/dist/components/controlled/file/ControlledDocumentField.d.ts +3 -0
  58. package/dist/components/controlled/file/ControlledDocumentField.d.ts.map +1 -1
  59. package/dist/components/controlled/file/ControlledDocumentField.js +1 -1
  60. package/dist/components/controlled/file/ControlledFileField.d.ts +3 -0
  61. package/dist/components/controlled/file/ControlledFileField.d.ts.map +1 -1
  62. package/dist/components/controlled/file/ControlledFileField.js +1 -1
  63. package/dist/components/controlled/file/ControlledImageField.d.ts +3 -0
  64. package/dist/components/controlled/file/ControlledImageField.d.ts.map +1 -1
  65. package/dist/components/controlled/file/ControlledImageField.js +1 -1
  66. package/dist/components/controlled/file/ControlledMultiDocumentField.d.ts +3 -0
  67. package/dist/components/controlled/file/ControlledMultiDocumentField.d.ts.map +1 -1
  68. package/dist/components/controlled/file/ControlledMultiDocumentField.js +1 -1
  69. package/dist/components/controlled/file/ControlledMultiFileField.d.ts +3 -0
  70. package/dist/components/controlled/file/ControlledMultiFileField.d.ts.map +1 -1
  71. package/dist/components/controlled/file/ControlledMultiFileField.js +1 -1
  72. package/dist/components/controlled/file/ControlledMultiImageField.d.ts +3 -0
  73. package/dist/components/controlled/file/ControlledMultiImageField.d.ts.map +1 -1
  74. package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
  75. package/dist/components/controlled/file/index.d.ts.map +1 -1
  76. package/dist/components/controlled/file/index.js +1 -1
  77. package/dist/components/controlled/index.d.ts +4 -0
  78. package/dist/components/controlled/index.d.ts.map +1 -1
  79. package/dist/components/controlled/index.js +1 -1
  80. package/dist/components/controlled/input/ControlledCheckboxField.d.ts +3 -0
  81. package/dist/components/controlled/input/ControlledCheckboxField.d.ts.map +1 -1
  82. package/dist/components/controlled/input/ControlledCheckboxField.js +1 -1
  83. package/dist/components/controlled/input/ControlledCurrencyField.d.ts +8 -0
  84. package/dist/components/controlled/input/ControlledCurrencyField.d.ts.map +1 -0
  85. package/dist/components/controlled/input/ControlledCurrencyField.js +1 -0
  86. package/dist/components/controlled/input/ControlledGdprConsentField.d.ts +8 -0
  87. package/dist/components/controlled/input/ControlledGdprConsentField.d.ts.map +1 -0
  88. package/dist/components/controlled/input/ControlledGdprConsentField.js +1 -0
  89. package/dist/components/controlled/input/ControlledNumberField.d.ts +3 -0
  90. package/dist/components/controlled/input/ControlledNumberField.d.ts.map +1 -1
  91. package/dist/components/controlled/input/ControlledNumberField.js +1 -1
  92. package/dist/components/controlled/input/ControlledPasswordField.d.ts +3 -0
  93. package/dist/components/controlled/input/ControlledPasswordField.d.ts.map +1 -1
  94. package/dist/components/controlled/input/ControlledPasswordField.js +1 -1
  95. package/dist/components/controlled/input/ControlledPhoneField.d.ts +3 -0
  96. package/dist/components/controlled/input/ControlledPhoneField.d.ts.map +1 -1
  97. package/dist/components/controlled/input/ControlledPhoneField.js +1 -1
  98. package/dist/components/controlled/input/ControlledPriceField.d.ts +8 -0
  99. package/dist/components/controlled/input/ControlledPriceField.d.ts.map +1 -0
  100. package/dist/components/controlled/input/ControlledPriceField.js +1 -0
  101. package/dist/components/controlled/input/ControlledRangeField.d.ts +3 -0
  102. package/dist/components/controlled/input/ControlledRangeField.d.ts.map +1 -1
  103. package/dist/components/controlled/input/ControlledRangeField.js +1 -1
  104. package/dist/components/controlled/input/ControlledRatingField.d.ts +8 -0
  105. package/dist/components/controlled/input/ControlledRatingField.d.ts.map +1 -0
  106. package/dist/components/controlled/input/ControlledRatingField.js +1 -0
  107. package/dist/components/controlled/input/ControlledSwitchField.d.ts +3 -0
  108. package/dist/components/controlled/input/ControlledSwitchField.d.ts.map +1 -1
  109. package/dist/components/controlled/input/ControlledSwitchField.js +1 -1
  110. package/dist/components/controlled/input/ControlledTextField.d.ts +3 -0
  111. package/dist/components/controlled/input/ControlledTextField.d.ts.map +1 -1
  112. package/dist/components/controlled/input/ControlledTextField.js +1 -1
  113. package/dist/components/controlled/input/ControlledTextareaField.d.ts +3 -0
  114. package/dist/components/controlled/input/ControlledTextareaField.d.ts.map +1 -1
  115. package/dist/components/controlled/input/ControlledTextareaField.js +1 -1
  116. package/dist/components/controlled/input/index.d.ts +4 -0
  117. package/dist/components/controlled/input/index.d.ts.map +1 -1
  118. package/dist/components/controlled/input/index.js +1 -1
  119. package/dist/components/controlled/select/ControlledComboboxField.d.ts +4 -0
  120. package/dist/components/controlled/select/ControlledComboboxField.d.ts.map +1 -1
  121. package/dist/components/controlled/select/ControlledComboboxField.js +1 -1
  122. package/dist/components/controlled/select/ControlledDropdownField.d.ts +4 -0
  123. package/dist/components/controlled/select/ControlledDropdownField.d.ts.map +1 -1
  124. package/dist/components/controlled/select/ControlledDropdownField.js +1 -1
  125. package/dist/components/controlled/select/ControlledMultiDropdownField.d.ts +4 -0
  126. package/dist/components/controlled/select/ControlledMultiDropdownField.d.ts.map +1 -1
  127. package/dist/components/controlled/select/ControlledMultiDropdownField.js +1 -1
  128. package/dist/components/controlled/select/ControlledRadioField.d.ts +4 -0
  129. package/dist/components/controlled/select/ControlledRadioField.d.ts.map +1 -1
  130. package/dist/components/controlled/select/ControlledRadioField.js +1 -1
  131. package/dist/components/controlled/select/ControlledYearField.d.ts +9 -0
  132. package/dist/components/controlled/select/ControlledYearField.d.ts.map +1 -0
  133. package/dist/components/controlled/select/ControlledYearField.js +1 -0
  134. package/dist/components/controlled/select/index.d.ts +1 -0
  135. package/dist/components/controlled/select/index.d.ts.map +1 -1
  136. package/dist/components/controlled/select/index.js +1 -1
  137. package/dist/components/controlled/types.d.ts +6 -0
  138. package/dist/components/controlled/types.d.ts.map +1 -1
  139. package/dist/components/controlled/types.js +1 -1
  140. package/dist/components/fields/display/AvatarFieldDisplay.d.ts +23 -0
  141. package/dist/components/fields/display/AvatarFieldDisplay.d.ts.map +1 -0
  142. package/dist/components/fields/display/AvatarFieldDisplay.js +1 -0
  143. package/dist/components/fields/display/BadgeFieldDisplay.d.ts +21 -0
  144. package/dist/components/fields/display/BadgeFieldDisplay.d.ts.map +1 -0
  145. package/dist/components/fields/display/BadgeFieldDisplay.js +1 -0
  146. package/dist/components/fields/display/ButtonFieldDisplay.d.ts +29 -0
  147. package/dist/components/fields/display/ButtonFieldDisplay.d.ts.map +1 -0
  148. package/dist/components/fields/display/ButtonFieldDisplay.js +1 -0
  149. package/dist/components/fields/display/CheckboxFieldDisplay.d.ts +21 -0
  150. package/dist/components/fields/display/CheckboxFieldDisplay.d.ts.map +1 -0
  151. package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -0
  152. package/dist/components/fields/display/DateFieldDisplay.d.ts +24 -0
  153. package/dist/components/fields/display/DateFieldDisplay.d.ts.map +1 -0
  154. package/dist/components/fields/display/DateFieldDisplay.js +1 -0
  155. package/dist/components/fields/display/DropdownDisplay.d.ts +21 -0
  156. package/dist/components/fields/display/DropdownDisplay.d.ts.map +1 -0
  157. package/dist/components/fields/display/DropdownDisplay.js +1 -0
  158. package/dist/components/fields/display/FileFieldDisplay.d.ts +21 -0
  159. package/dist/components/fields/display/FileFieldDisplay.d.ts.map +1 -0
  160. package/dist/components/fields/display/FileFieldDisplay.js +1 -0
  161. package/dist/components/fields/display/GeoPointFieldDisplay.d.ts +25 -0
  162. package/dist/components/fields/display/GeoPointFieldDisplay.d.ts.map +1 -0
  163. package/dist/components/fields/display/GeoPointFieldDisplay.js +1 -0
  164. package/dist/components/fields/display/HiddenFieldDisplay.d.ts +30 -0
  165. package/dist/components/fields/display/HiddenFieldDisplay.d.ts.map +1 -0
  166. package/dist/components/fields/display/HiddenFieldDisplay.js +1 -0
  167. package/dist/components/fields/display/ImageFieldDisplay.d.ts +24 -0
  168. package/dist/components/fields/display/ImageFieldDisplay.d.ts.map +1 -0
  169. package/dist/components/fields/display/ImageFieldDisplay.js +1 -0
  170. package/dist/components/fields/display/LinkFieldDisplay.d.ts +22 -0
  171. package/dist/components/fields/display/LinkFieldDisplay.d.ts.map +1 -0
  172. package/dist/components/fields/display/LinkFieldDisplay.js +1 -0
  173. package/dist/components/fields/display/MapFieldDisplay.d.ts +25 -0
  174. package/dist/components/fields/display/MapFieldDisplay.d.ts.map +1 -0
  175. package/dist/components/fields/display/MapFieldDisplay.js +1 -0
  176. package/dist/components/fields/display/MultiDropdownDisplay.d.ts +22 -0
  177. package/dist/components/fields/display/MultiDropdownDisplay.d.ts.map +1 -0
  178. package/dist/components/fields/display/MultiDropdownDisplay.js +1 -0
  179. package/dist/components/fields/display/MultiInputTextFieldDisplay.d.ts +22 -0
  180. package/dist/components/fields/display/MultiInputTextFieldDisplay.d.ts.map +1 -0
  181. package/dist/components/fields/display/MultiInputTextFieldDisplay.js +1 -0
  182. package/dist/components/fields/display/NumberFieldDisplay.d.ts +24 -0
  183. package/dist/components/fields/display/NumberFieldDisplay.d.ts.map +1 -0
  184. package/dist/components/fields/display/NumberFieldDisplay.js +1 -0
  185. package/dist/components/fields/display/PasswordFieldDisplay.d.ts +24 -0
  186. package/dist/components/fields/display/PasswordFieldDisplay.d.ts.map +1 -0
  187. package/dist/components/fields/display/PasswordFieldDisplay.js +1 -0
  188. package/dist/components/fields/display/PhoneNumberDisplay.d.ts +22 -0
  189. package/dist/components/fields/display/PhoneNumberDisplay.d.ts.map +1 -0
  190. package/dist/components/fields/display/PhoneNumberDisplay.js +1 -0
  191. package/dist/components/fields/display/RadioFieldDisplay.d.ts +22 -0
  192. package/dist/components/fields/display/RadioFieldDisplay.d.ts.map +1 -0
  193. package/dist/components/fields/display/RadioFieldDisplay.js +1 -0
  194. package/dist/components/fields/display/RangeFieldDisplay.d.ts +22 -0
  195. package/dist/components/fields/display/RangeFieldDisplay.d.ts.map +1 -0
  196. package/dist/components/fields/display/RangeFieldDisplay.js +1 -0
  197. package/dist/components/fields/display/ReferenceFieldDisplay.d.ts +22 -0
  198. package/dist/components/fields/display/ReferenceFieldDisplay.d.ts.map +1 -0
  199. package/dist/components/fields/display/ReferenceFieldDisplay.js +1 -0
  200. package/dist/components/fields/display/RichTextDisplay.d.ts +25 -0
  201. package/dist/components/fields/display/RichTextDisplay.d.ts.map +1 -0
  202. package/dist/components/fields/display/RichTextDisplay.js +61 -0
  203. package/dist/components/fields/display/TextAreaDisplay.d.ts +22 -0
  204. package/dist/components/fields/display/TextAreaDisplay.d.ts.map +1 -0
  205. package/dist/components/fields/display/TextAreaDisplay.js +1 -0
  206. package/dist/components/fields/display/TextFieldDisplay.d.ts +42 -0
  207. package/dist/components/fields/display/TextFieldDisplay.d.ts.map +1 -0
  208. package/dist/components/fields/display/TextFieldDisplay.js +1 -0
  209. package/dist/components/fields/display/TimestampFieldDisplay.d.ts +22 -0
  210. package/dist/components/fields/display/TimestampFieldDisplay.d.ts.map +1 -0
  211. package/dist/components/fields/display/TimestampFieldDisplay.js +1 -0
  212. package/dist/components/fields/display/index.d.ts +32 -0
  213. package/dist/components/fields/display/index.d.ts.map +1 -0
  214. package/dist/components/fields/display/index.js +1 -0
  215. package/dist/components/form/fields/AddressFieldComponent.js +1 -1
  216. package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
  217. package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
  218. package/dist/components/form/fields/ButtonFieldComponent.js +1 -1
  219. package/dist/components/form/fields/CheckboxFieldComponent.d.ts +3 -3
  220. package/dist/components/form/fields/CheckboxFieldComponent.d.ts.map +1 -1
  221. package/dist/components/form/fields/CheckboxFieldComponent.js +1 -1
  222. package/dist/components/form/fields/ComboboxComponent.d.ts +6 -0
  223. package/dist/components/form/fields/ComboboxComponent.d.ts.map +1 -1
  224. package/dist/components/form/fields/ComboboxComponent.js +1 -1
  225. package/dist/components/form/fields/CurrencyFieldComponent.js +1 -1
  226. package/dist/components/form/fields/DateFieldComponent.js +1 -1
  227. package/dist/components/form/fields/DocumentFieldComponent.d.ts.map +1 -1
  228. package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
  229. package/dist/components/form/fields/DropdownComponent.js +1 -1
  230. package/dist/components/form/fields/FileFieldComponent.d.ts.map +1 -1
  231. package/dist/components/form/fields/FileFieldComponent.js +1 -1
  232. package/dist/components/form/fields/GdprConsentFieldComponent.d.ts +26 -0
  233. package/dist/components/form/fields/GdprConsentFieldComponent.d.ts.map +1 -0
  234. package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -0
  235. package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
  236. package/dist/components/form/fields/HiddenFieldComponent.js +1 -1
  237. package/dist/components/form/fields/ImageFieldComponent.d.ts +3 -2
  238. package/dist/components/form/fields/ImageFieldComponent.d.ts.map +1 -1
  239. package/dist/components/form/fields/ImageFieldComponent.js +1 -1
  240. package/dist/components/form/fields/MapFieldComponent.js +1 -1
  241. package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
  242. package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
  243. package/dist/components/form/fields/NumberFieldComponent.js +1 -1
  244. package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
  245. package/dist/components/form/fields/PhoneNumberComponent.d.ts.map +1 -1
  246. package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
  247. package/dist/components/form/fields/PriceFieldComponent.d.ts +34 -0
  248. package/dist/components/form/fields/PriceFieldComponent.d.ts.map +1 -0
  249. package/dist/components/form/fields/PriceFieldComponent.js +1 -0
  250. package/dist/components/form/fields/RadioFieldComponent.js +1 -1
  251. package/dist/components/form/fields/RangeFieldComponent.js +1 -1
  252. package/dist/components/form/fields/RatingFieldComponent.d.ts +37 -0
  253. package/dist/components/form/fields/RatingFieldComponent.d.ts.map +1 -0
  254. package/dist/components/form/fields/RatingFieldComponent.js +1 -0
  255. package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
  256. package/dist/components/form/fields/RichTextComponent.d.ts +2 -21
  257. package/dist/components/form/fields/RichTextComponent.d.ts.map +1 -1
  258. package/dist/components/form/fields/RichTextComponent.js +1 -1
  259. package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
  260. package/dist/components/form/fields/TextAreaComponent.d.ts.map +1 -1
  261. package/dist/components/form/fields/TextAreaComponent.js +1 -1
  262. package/dist/components/form/fields/TextFieldComponent.js +1 -1
  263. package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
  264. package/dist/components/form/fields/index.d.ts +7 -1
  265. package/dist/components/form/fields/index.d.ts.map +1 -1
  266. package/dist/components/form/fields/index.js +1 -1
  267. package/dist/components/form/fields/internal/TiptapEditor.d.ts +1 -1
  268. package/dist/components/form/fields/internal/TiptapEditor.d.ts.map +1 -1
  269. package/dist/components/form/fields/internal/TiptapEditor.js +2 -2
  270. package/dist/components/form/fields/types.d.ts +33 -0
  271. package/dist/components/form/fields/types.d.ts.map +1 -0
  272. package/dist/components/form/fields/types.js +0 -0
  273. package/dist/components/form/internal/ImageViewerDialog.d.ts +2 -1
  274. package/dist/components/form/internal/ImageViewerDialog.d.ts.map +1 -1
  275. package/dist/components/form/internal/ImageViewerDialog.js +1 -1
  276. package/dist/components/index.d.ts +4 -8
  277. package/dist/components/index.d.ts.map +1 -1
  278. package/dist/components/index.js +1 -1
  279. package/dist/contexts/UploadContext.d.ts.map +1 -1
  280. package/dist/contexts/UploadContext.js +1 -1
  281. package/dist/contexts/index.js +1 -1
  282. package/dist/fieldTypeRegistry.d.ts +92 -0
  283. package/dist/fieldTypeRegistry.d.ts.map +1 -0
  284. package/dist/fieldTypeRegistry.js +1 -0
  285. package/dist/forms/hooks/index.js +1 -1
  286. package/dist/forms/hooks/useController.js +1 -1
  287. package/dist/forms/hooks/useEntityField.js +1 -1
  288. package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
  289. package/dist/forms/hooks/useEntityForm.js +1 -1
  290. package/dist/forms/index.d.ts +2 -2
  291. package/dist/forms/index.d.ts.map +1 -1
  292. package/dist/forms/index.js +1 -1
  293. package/dist/forms/types.d.ts +15 -0
  294. package/dist/forms/types.d.ts.map +1 -1
  295. package/dist/forms/utils/getFieldsForOperation.js +1 -1
  296. package/dist/forms/utils/index.d.ts +0 -2
  297. package/dist/forms/utils/index.d.ts.map +1 -1
  298. package/dist/forms/utils/index.js +1 -1
  299. package/dist/forms/utils/isFieldEditable.js +1 -1
  300. package/dist/forms/utils/translateFieldLabel.js +1 -1
  301. package/dist/forms/utils/validateEntity.js +1 -1
  302. package/dist/hooks/index.d.ts +5 -0
  303. package/dist/hooks/index.d.ts.map +1 -1
  304. package/dist/hooks/index.js +1 -1
  305. package/dist/hooks/useEntityFavorites.d.ts +53 -0
  306. package/dist/hooks/useEntityFavorites.d.ts.map +1 -0
  307. package/dist/hooks/useEntityFavorites.js +1 -0
  308. package/dist/hooks/useFileUpload.d.ts.map +1 -1
  309. package/dist/hooks/useFileUpload.js +1 -1
  310. package/dist/hooks/useFormNavigationGuard.d.ts +34 -0
  311. package/dist/hooks/useFormNavigationGuard.d.ts.map +1 -0
  312. package/dist/hooks/useFormNavigationGuard.js +1 -0
  313. package/dist/hooks/useRelatedItems.d.ts +37 -0
  314. package/dist/hooks/useRelatedItems.d.ts.map +1 -0
  315. package/dist/hooks/useRelatedItems.js +1 -0
  316. package/dist/hooks/useUnsavedChangesWarning.d.ts +51 -0
  317. package/dist/hooks/useUnsavedChangesWarning.d.ts.map +1 -0
  318. package/dist/hooks/useUnsavedChangesWarning.js +1 -0
  319. package/dist/index.d.ts +9 -6
  320. package/dist/index.d.ts.map +1 -1
  321. package/dist/index.js +1 -1
  322. package/dist/registerBuiltinFieldTypes.d.ts +6 -0
  323. package/dist/registerBuiltinFieldTypes.d.ts.map +1 -0
  324. package/dist/registerBuiltinFieldTypes.js +1 -0
  325. package/dist/stores/FormStore.d.ts +17 -0
  326. package/dist/stores/FormStore.d.ts.map +1 -1
  327. package/dist/stores/FormStore.js +1 -1
  328. package/dist/stores/UploadStore.js +1 -1
  329. package/dist/stores/index.d.ts +1 -1
  330. package/dist/stores/index.d.ts.map +1 -1
  331. package/dist/stores/index.js +1 -1
  332. package/dist/tsconfig.tsbuildinfo +1 -1
  333. package/dist/types.d.ts +202 -0
  334. package/dist/types.d.ts.map +1 -0
  335. package/dist/types.js +0 -0
  336. package/dist/useBaseCrudList.d.ts +53 -0
  337. package/dist/useBaseCrudList.d.ts.map +1 -0
  338. package/dist/useBaseCrudList.js +1 -0
  339. package/dist/useCrud.d.ts +4 -8
  340. package/dist/useCrud.d.ts.map +1 -1
  341. package/dist/useCrud.js +1 -1
  342. package/dist/useCrudCardList.d.ts +10 -4
  343. package/dist/useCrudCardList.d.ts.map +1 -1
  344. package/dist/useCrudCardList.js +1 -1
  345. package/dist/useCrudList.d.ts +19 -5
  346. package/dist/useCrudList.d.ts.map +1 -1
  347. package/dist/useCrudList.js +1 -1
  348. package/dist/utils/collections.js +1 -1
  349. package/dist/utils/fileStorage.js +1 -1
  350. package/dist/utils/imageProcessing.js +1 -1
  351. package/dist/utils/imageStorage.js +1 -1
  352. package/dist/utils/imageUtils.js +1 -1
  353. package/dist/utils/mergeWithOptimistic.d.ts +5 -6
  354. package/dist/utils/mergeWithOptimistic.d.ts.map +1 -1
  355. package/dist/utils/mergeWithOptimistic.js +1 -1
  356. package/dist/utils/scopeUtils.d.ts +38 -0
  357. package/dist/utils/scopeUtils.d.ts.map +1 -0
  358. package/dist/utils/scopeUtils.js +1 -0
  359. package/dist/utils/uploadValidation.d.ts.map +1 -1
  360. package/dist/utils/uploadValidation.js +1 -1
  361. package/package.json +24 -17
  362. package/dist/components/EntityCardList.d.ts +0 -27
  363. package/dist/components/EntityCardList.d.ts.map +0 -1
  364. package/dist/components/EntityCardList.js +0 -1
  365. package/dist/components/EntityList.d.ts +0 -24
  366. package/dist/components/EntityList.d.ts.map +0 -1
  367. package/dist/components/EntityList.js +0 -1
  368. package/dist/forms/utils/optionHelpers.d.ts +0 -54
  369. package/dist/forms/utils/optionHelpers.d.ts.map +0 -1
  370. package/dist/forms/utils/optionHelpers.js +0 -1
@@ -1,56 +1,8 @@
1
1
  import type { dndevSchema, QueryClient } from '@donotdev/core';
2
+ import type { BackendType, CrudStoreApi, CrudServiceInterface, CacheOptions, MutationOptions } from './types';
2
3
  import type { QueryOptions } from './adapters/FirestoreAdapter';
3
- import type { BackendType, CrudState, CrudActions } from './CrudStore';
4
- /** Store API type for CrudService - typed instead of any */
5
- type CrudStoreApi = {
6
- getState: () => CrudState & CrudActions;
7
- };
8
- /** Cache options for read operations */
9
- export interface CacheOptions {
10
- /** Bypass cache and fetch directly from adapter */
11
- noCache?: boolean;
12
- /** Custom stale time in ms (default: Infinity) */
13
- staleTime?: number;
14
- }
15
- export type { QueryOptions };
16
- export interface CrudServiceInterface {
17
- initialize(backend: BackendType): Promise<void>;
18
- setStore(store: CrudStoreApi): void;
19
- /** Schema accepts unknown since OperationSchemas stores dndevSchema<unknown>. T is for return type. */
20
- getListQueryOptions<T>(collection: string, queryOptions: QueryOptions, schema: dndevSchema<unknown>, cacheOptions?: CacheOptions, schemaType?: 'list' | 'listCard'): {
21
- queryKey: readonly string[];
22
- queryFn: () => Promise<T[]>;
23
- staleTime: number;
24
- };
25
- /** Schema accepts unknown since OperationSchemas stores dndevSchema<unknown>. T is for return type. */
26
- getDocQueryOptions<T>(collection: string, id: string, schema: dndevSchema<unknown>, cacheOptions?: CacheOptions): {
27
- queryKey: readonly string[];
28
- queryFn: () => Promise<T | null>;
29
- staleTime: number;
30
- };
31
- get<T>(collection: string, id: string, schema: dndevSchema<T>, options?: CacheOptions): Promise<T | null>;
32
- query<T>(collection: string, options: QueryOptions, schema: dndevSchema<T>, cacheOptions?: CacheOptions, schemaType?: 'list' | 'listCard'): Promise<T[]>;
33
- set<T>(collection: string, id: string, data: T, schema: dndevSchema<T>): Promise<void>;
34
- update<T>(collection: string, id: string, data: Partial<T>): Promise<void>;
35
- delete(collection: string, id: string): Promise<void>;
36
- add<T>(collection: string, data: T, schema: dndevSchema<T>): Promise<string>;
37
- subscribe<T>(collection: string, id: string, callback: (data: T | null, error?: Error) => void, schema: dndevSchema<T>): () => void;
38
- subscribeToCollection<T>(collection: string, options: QueryOptions, callback: (data: T[], error?: Error) => void, schema: dndevSchema<T>): () => void;
39
- /** Add with optimistic update - shows item immediately, confirms/rolls back after server */
40
- addOptimistic<T extends {
41
- id?: string;
42
- }>(collection: string, data: T, schema: dndevSchema<T>): Promise<T & {
43
- id: string;
44
- }>;
45
- /** Update with optimistic update - shows change immediately, confirms/rolls back after server */
46
- updateOptimistic<T>(collection: string, id: string, data: Partial<T>, schema: dndevSchema<T>): Promise<T>;
47
- /** Delete with optimistic update - hides item immediately, confirms/restores after server */
48
- deleteOptimistic(collection: string, id: string): Promise<void>;
49
- /** Invalidate all cached queries for a collection */
50
- invalidateCollection(collection: string): Promise<void>;
51
- /** Get the shared QueryClient instance from @donotdev/core */
52
- getQueryClient(): QueryClient;
53
- }
4
+ import type { PaginatedQueryResult } from './adapters/FunctionsAdapter';
5
+ export type { QueryOptions, CacheOptions };
54
6
  /**
55
7
  * Complete CRUD orchestrator with TanStack Query caching
56
8
  *
@@ -62,6 +14,13 @@ declare class CrudService implements CrudServiceInterface {
62
14
  private adapter;
63
15
  private backend;
64
16
  private store;
17
+ /**
18
+ * Determine if success toast should be shown based on per-call options and global setting
19
+ * - options.showSuccessToast=true → always show
20
+ * - options.showSuccessToast=false → never show
21
+ * - options.showSuccessToast=undefined → use global !hideSuccessToasts
22
+ */
23
+ private _shouldShowSuccessToast;
65
24
  setStore(store: CrudStoreApi): void;
66
25
  initialize(backend: BackendType): Promise<void>;
67
26
  /**
@@ -76,7 +35,7 @@ declare class CrudService implements CrudServiceInterface {
76
35
  */
77
36
  getListQueryOptions<T>(collection: string, queryOptions: QueryOptions, schema: dndevSchema<unknown>, cacheOptions?: CacheOptions, schemaType?: 'list' | 'listCard'): {
78
37
  queryKey: readonly ["crud", string, "query", "list" | "listCard", string];
79
- queryFn: () => Promise<T[]>;
38
+ queryFn: () => Promise<PaginatedQueryResult<T>>;
80
39
  staleTime: number;
81
40
  };
82
41
  /**
@@ -99,6 +58,11 @@ declare class CrudService implements CrudServiceInterface {
99
58
  * Automatically syncs both list and document caches for consistency.
100
59
  */
101
60
  private _updateListCaches;
61
+ /**
62
+ * Get an item from any list cache for this collection.
63
+ * Used to get previous data for optimistic operations when individual GET cache is empty.
64
+ */
65
+ private _getItemFromListCache;
102
66
  /**
103
67
  * Invalidate all cached queries for a collection
104
68
  */
@@ -106,22 +70,28 @@ declare class CrudService implements CrudServiceInterface {
106
70
  get<T>(collection: string, id: string, schema: dndevSchema<T>, options?: CacheOptions): Promise<T | null>;
107
71
  /** Internal: fetch from adapter with store updates */
108
72
  private _getFromAdapter;
109
- query<T>(collection: string, options: QueryOptions, schema: dndevSchema<T>, cacheOptions?: CacheOptions, schemaType?: 'list' | 'listCard'): Promise<T[]>;
73
+ query<T>(collection: string, options: QueryOptions, schema: dndevSchema<T>, cacheOptions?: CacheOptions, schemaType?: 'list' | 'listCard'): Promise<PaginatedQueryResult<T>>;
110
74
  /** Internal: query from adapter with store updates */
111
75
  private _queryFromAdapter;
112
- set<T>(collection: string, id: string, data: T, schema: dndevSchema<T>): Promise<void>;
113
- update<T>(collection: string, id: string, data: Partial<T>): Promise<void>;
114
- delete(collection: string, id: string): Promise<void>;
115
- add<T>(collection: string, data: T, schema: dndevSchema<T>): Promise<string>;
76
+ /**
77
+ * Helper to get translated entity name from collection
78
+ * Tries entity-{collection}:name and entity-{singular}:name patterns
79
+ * Falls back to collection name if translation not found
80
+ */
81
+ private _getEntityName;
82
+ set<T>(collection: string, id: string, data: T, schema: dndevSchema<T>, options?: MutationOptions): Promise<void>;
83
+ update<T>(collection: string, id: string, data: Partial<T>, options?: MutationOptions): Promise<void>;
84
+ delete(collection: string, id: string, options?: MutationOptions): Promise<void>;
85
+ add<T>(collection: string, data: T, schema: dndevSchema<T>, options?: MutationOptions): Promise<string>;
116
86
  subscribe<T>(collection: string, id: string, callback: (data: T | null, error?: Error) => void, schema: dndevSchema<T>): () => void;
117
87
  subscribeToCollection<T>(collection: string, options: QueryOptions, callback: (data: T[], error?: Error) => void, schema: dndevSchema<T>): () => void;
118
88
  addOptimistic<T extends {
119
89
  id?: string;
120
- }>(collection: string, data: T, schema: dndevSchema<T>): Promise<T & {
90
+ }>(collection: string, data: T, schema: dndevSchema<T>, options?: MutationOptions): Promise<T & {
121
91
  id: string;
122
92
  }>;
123
- updateOptimistic<T>(collection: string, id: string, data: Partial<T>, schema: dndevSchema<T>): Promise<T>;
124
- deleteOptimistic(collection: string, id: string): Promise<void>;
93
+ updateOptimistic<T>(collection: string, id: string, data: Partial<T>, schema: dndevSchema<T>, options?: MutationOptions): Promise<T>;
94
+ deleteOptimistic(collection: string, id: string, options?: MutationOptions): Promise<void>;
125
95
  }
126
96
  /**
127
97
  * Get or create CrudService singleton instance
@@ -1 +1 @@
1
- {"version":3,"file":"CrudService.d.ts","sourceRoot":"","sources":["../src/CrudService.ts"],"names":[],"mappings":"AA6BA,OAAQ,KAAK,EAAC,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAK/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEvE,4DAA4D;AAC5D,KAAK,YAAY,GAAG;IAClB,QAAQ,EAAE,MAAM,SAAS,GAAG,WAAW,CAAC;CACzC,CAAC;AAQF,wCAAwC;AACxC,MAAM,WAAW,YAAY;IAC3B,mDAAmD;IACnD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAGpC,uGAAuG;IACvG,mBAAmB,CAAC,CAAC,EACnB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,EAAE,YAAY,EAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU,GAC/B;QACD,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;QAC5B,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;QAC5B,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,uGAAuG;IACvG,kBAAkB,CAAC,CAAC,EAClB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,WAAW,C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xB,OAAO,CAAC,CAAC,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IA8DxB,gBAAgB,CAAC,CAAC,EACtB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,CAAC,CAAC;IAoEP,gBAAgB,CACpB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC;CA2DjB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,mBAE1B,CAAC"}
@@ -1 +1 @@
1
- import{toast as f}from"@donotdev/components";import{createSingleton as p,handleError as u,getQueryClient as g}from"@donotdev/core";import{FirestoreAdapter as y}from"./adapters/FirestoreAdapter";import{FunctionsAdapter as w}from"./adapters/FunctionsAdapter";const d=1/0,z=1e3*60*30;class S{adapter=null;backend=null;store=null;setStore(t){this.store=t}async initialize(t){if(!(this.backend===t&&this.adapter)){if(this.backend=t,t==="functions")this.adapter=new w;else if(t==="firestore")this.adapter=new y;else throw new Error(`Unknown backend: ${t}`);this.store&&(this.store.getState().setBackend(t),this.store.getState().setCrudService(this))}}getQueryClient(){return g()}getListQueryOptions(t,e,s,a,r="list"){const i=this.adapter,h=()=>this.initialize("firestore");return{queryKey:["crud",t,"query",r,JSON.stringify(e)],queryFn:async()=>{if(i||await h(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.query(t,e,s)},staleTime:a?.staleTime??d}}getDocQueryOptions(t,e,s,a){const r=this.adapter,i=()=>this.initialize("firestore");return{queryKey:["crud",t,"get",e],queryFn:async()=>{if(r||await i(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.get(t,e,s)},staleTime:a?.staleTime??d}}_updateGetCache(t,e,s,a){const r=this.getQueryClient(),i=["crud",t,"get",e];a==="delete"?r.removeQueries({queryKey:i}):(a==="update"||a==="add")&&s&&r.setQueryData(i,h=>h?{...h,...s}:s)}_updateListCaches(t,e,s,a){const r=this.getQueryClient();this._updateGetCache(t,e,s,a),r.setQueriesData({queryKey:["crud",t]},i=>Array.isArray(i)?a==="delete"?i.filter(h=>h.id!==e):a==="add"&&s?[...i,{...s,id:e}]:a==="update"&&s&&i.some(o=>o.id===e)?i.map(o=>o.id===e?{...o,...s}:o):i:i)}async invalidateCollection(t){await this.getQueryClient().invalidateQueries({queryKey:["crud",t]})}async get(t,e,s,a){if(this.adapter||await this.initialize("firestore"),a?.noCache)return this._getFromAdapter(t,e,s);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"get",e],queryFn:()=>this._getFromAdapter(t,e,s,!1),staleTime:a?.staleTime??d})}catch(r){const i=u(r,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _getFromAdapter(t,e,s,a=!0){this.store&&a&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");const r=await this.adapter.get(t,e,s);return this.store&&r&&this.store.getState().setData(t,e,r),r}catch(r){const i=u(r,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}async query(t,e,s,a,r="list"){if(this.adapter||await this.initialize("firestore"),a?.noCache)return this._queryFromAdapter(t,e,s);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"query",r,JSON.stringify(e)],queryFn:()=>this._queryFromAdapter(t,e,s,!1),staleTime:a?.staleTime??d})}catch(i){const h=u(i,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _queryFromAdapter(t,e,s,a=!0){this.store&&a&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");const r=await this.adapter.query(t,e,s);if(this.store){const i=[];for(const h of r){const o=h;o.id&&i.push({id:o.id,data:h})}i.length>0&&this.store.getState().setDataBatch(t,i)}return r}catch(r){const i=u(r,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}async set(t,e,s,a){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const r=this.store?.getState().getData(t,e);this.store&&this.store.getState().updateOptimistic(t,e,s,r);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.set(t,e,s,a),this.store&&(this.store.getState().confirmUpdate(t,e),this.store.getState().setData(t,e,s)),this._updateListCaches(t,e,s,"update"),f("success",`${t} saved successfully`)}catch(i){this.store&&this.store.getState().rejectUpdate(t,e);const h=u(i,{userMessage:`Failed to save ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async update(t,e,s){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));let a=null;this.store&&(a=this.store.getState().getData(t,e));const r=a?{...a,...s}:{...s,id:e};this.store&&a&&this.store.getState().updateOptimistic(t,e,r,a);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.update(t,e,s),this.store&&(this.store.getState().confirmUpdate(t,e),this.store.getState().setData(t,e,r)),this._updateListCaches(t,e,r,"update"),f("success",`${t} updated successfully`)}catch(i){this.store&&this.store.getState().rejectUpdate(t,e);const h=u(i,{userMessage:`Failed to update ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async delete(t,e){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=this.store?.getState().getData(t,e);this.store&&s&&this.store.getState().deleteOptimistic(t,e,s);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.delete(t,e),this.store&&this.store.getState().confirmDelete(t,e),this._updateListCaches(t,e,null,"delete"),f("success",`${t} deleted successfully`)}catch(a){this.store&&this.store.getState().rejectDelete(t,e);const r=u(a,{userMessage:`Failed to delete ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,r),r}finally{this.store&&this.store.getState().setLoading(t,!1)}}async add(t,e,s){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const a=`temp_${crypto.randomUUID()}`;this.store&&this.store.getState().addOptimistic(t,a,{...e,id:a});try{if(!this.adapter)throw new Error("Adapter not initialized");const r=await this.adapter.add(t,e,s);return this.store&&this.store.getState().confirmOptimistic(t,a,r,{...e,id:r}),this._updateListCaches(t,r,{...e,id:r},"add"),f("success",`${t} created successfully`),r}catch(r){this.store&&this.store.getState().rejectOptimistic(t,a);const i=u(r,{userMessage:`Failed to create ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}subscribe(t,e,s,a){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribe(t,e,(r,i)=>{r&&this.store&&this.store.getState().setData(t,e,r),r&&this.getQueryClient().setQueryData(["crud",t,"get",e],r),s(r,i)},a):(s(null,new Error("Adapter not initialized")),()=>{})}catch(r){return s(null,u(r)),()=>{}}}subscribeToCollection(t,e,s,a){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribeToCollection(t,e,(r,i)=>{if(r&&this.store){const h=[];for(const o of r){const n=o;n.id&&h.push({id:n.id,data:o})}h.length>0&&this.store.getState().setDataBatch(t,h)}r&&this.getQueryClient().setQueryData(["crud",t,"query",JSON.stringify(e)],r),s(r,i)},a):(s([],new Error("Adapter not initialized")),()=>{})}catch(r){return s([],u(r)),()=>{}}}async addOptimistic(t,e,s){this.adapter||await this.initialize("firestore");const a=`temp_${crypto.randomUUID()}`,r={...e,id:a,_optimistic:!0};this.store&&this.store.getState().addOptimistic(t,a,r);try{if(!this.adapter)throw new Error("Adapter not initialized");const i=await this.adapter.add(t,e,s),h={...e,id:i};return this.store&&this.store.getState().confirmOptimistic(t,a,i,h),this._updateListCaches(t,i,h,"add"),f("success",`${t} created successfully`),h}catch(i){throw this.store&&this.store.getState().rejectOptimistic(t,a),u(i,{userMessage:`Failed to create ${t}`,showNotification:!0})}}async updateOptimistic(t,e,s,a){this.adapter||await this.initialize("firestore");let r=null;this.store&&(r=this.store.getState().getData(t,e));const i=r?{...r,...s,_optimistic:!0}:{...s,id:e,_optimistic:!0};this.store&&r&&this.store.getState().updateOptimistic(t,e,i,r);try{if(!this.adapter)throw new Error("Adapter not initialized");return await this.adapter.update(t,e,s),this.store&&(this.store.getState().confirmUpdate(t,e),this.store.getState().setData(t,e,{...i,_optimistic:void 0})),this._updateListCaches(t,e,i,"update"),f("success",`${t} updated successfully`),i}catch(h){throw this.store&&this.store.getState().rejectUpdate(t,e),u(h,{userMessage:`Failed to update ${t}`,showNotification:!0})}}async deleteOptimistic(t,e){this.adapter||await this.initialize("firestore");let s=null;this.store&&(s=this.store.getState().getData(t,e)),this.store&&s&&this.store.getState().deleteOptimistic(t,e,s);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.delete(t,e),this.store&&this.store.getState().confirmDelete(t,e),this._updateListCaches(t,e,null,"delete"),f("success",`${t} deleted successfully`)}catch(a){throw this.store&&this.store.getState().rejectDelete(t,e),u(a,{userMessage:`Failed to delete ${t}`,showNotification:!0})}}}const A=p(()=>new S);export{A as getCrudService};
1
+ import{toast as u}from"@donotdev/components";import{createSingleton as p,handleError as n,getQueryClient as y,getI18nInstance as c}from"@donotdev/core";import{FirestoreAdapter as m}from"./adapters/FirestoreAdapter";import{FunctionsAdapter as f}from"./adapters/FunctionsAdapter";const l=1/0,F=1e3*60*30;class S{adapter=null;backend=null;store=null;_shouldShowSuccessToast(t){return t?.showSuccessToast===!0?!0:t?.showSuccessToast===!1?!1:!this.store?.getState().hideSuccessToasts}setStore(t){this.store=t}async initialize(t){if(!(this.backend===t&&this.adapter)){if(this.backend=t,t==="functions")this.adapter=new f;else if(t==="firestore")this.adapter=new m;else throw new Error(`Unknown backend: ${t}`);this.store&&(this.store.getState().setBackend(t),this.store.getState().setCrudService(this))}}getQueryClient(){return y()}getListQueryOptions(t,e,r,a,s="list"){const i=this.adapter,o=()=>this.initialize("firestore");return{queryKey:["crud",t,"query",s,JSON.stringify(e)],queryFn:async()=>{if(i||await o(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.query(t,e,r,s)},staleTime:a?.staleTime??l}}getDocQueryOptions(t,e,r,a){const s=this.adapter,i=()=>this.initialize("firestore");return{queryKey:["crud",t,"get",e],queryFn:async()=>{if(s||await i(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.get(t,e,r)},staleTime:a?.staleTime??l}}_updateGetCache(t,e,r,a){const s=this.getQueryClient(),i=["crud",t,"get",e];a==="delete"?s.removeQueries({queryKey:i}):(a==="update"||a==="add")&&r&&s.setQueryData(i,o=>o?{...o,...r}:r)}_updateListCaches(t,e,r,a){const s=this.getQueryClient();this._updateGetCache(t,e,r,a),s.setQueriesData({queryKey:["crud",t]},i=>{if(i&&typeof i=="object"&&"items"in i){const o=i;let h=o.items;return a==="delete"?(h=o.items.filter(d=>d.id!==e),{...o,items:h,total:(o.total??h.length)-1}):a==="add"&&r?(h=[...o.items,{...r,id:e}],{...o,items:h,total:(o.total??o.items.length)+1}):a==="update"&&r&&o.items.some(d=>d.id===e)?(h=o.items.map(d=>d.id===e?{...d,...r}:d),{...o,items:h}):i}if(Array.isArray(i)){if(a==="delete")return i.filter(o=>o.id!==e);if(a==="add"&&r)return[...i,{...r,id:e}];if(a==="update"&&r)return i.some(o=>o.id===e)?i.map(o=>o.id===e?{...o,...r}:o):i}return i})}_getItemFromListCache(t,e){const r=this.getQueryClient().getQueriesData({queryKey:["crud",t]});for(const[,a]of r)if(a?.items){const s=a.items.find(i=>i.id===e);if(s)return s}return null}async invalidateCollection(t){await this.getQueryClient().invalidateQueries({queryKey:["crud",t]})}async get(t,e,r,a){if(this.adapter||await this.initialize("firestore"),a?.noCache)return this._getFromAdapter(t,e,r);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"get",e],queryFn:()=>this._getFromAdapter(t,e,r,!1),staleTime:a?.staleTime??l})}catch(s){const i=n(s,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _getFromAdapter(t,e,r,a=!0){this.store&&a&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");return await this.adapter.get(t,e,r)}catch(s){const i=n(s,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}async query(t,e,r,a,s="list"){if(this.adapter||await this.initialize("firestore"),a?.noCache)return this._queryFromAdapter(t,e,r,!0,s);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"query",s,JSON.stringify(e)],queryFn:()=>this._queryFromAdapter(t,e,r,!1,s),staleTime:a?.staleTime??l})}catch(i){const o=n(i,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,o),o}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _queryFromAdapter(t,e,r,a=!0,s="list"){this.store&&a&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");return await this.adapter.query(t,e,r,s)}catch(i){const o=n(i,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,o),o}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}_getEntityName(t){const e=c();let r=`entity-${t}`,a=e.t("name",{ns:r,defaultValue:null});return a&&a!=="name"&&a!==`${r}:name`||t.endsWith("s")&&t.length>1&&(r=`entity-${t.slice(0,-1)}`,a=e.t("name",{ns:r,defaultValue:null}),a&&a!=="name"&&a!==`${r}:name`)?a:t}async set(t,e,r,a,s){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const i=this.getQueryClient().getQueryData(["crud",t,"get",e])??null;this.store&&this.store.getState().updateOptimistic(t,e,r,i);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.set(t,e,r,a),this._updateListCaches(t,e,r,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(s)){const o=c(),h=this._getEntityName(t);u("success",o.t("messages.updateSuccess",{ns:"crud",entity:h}))}}catch(o){i&&this._updateListCaches(t,e,i,"update"),this.store&&this.store.getState().rejectUpdate(t,e);const h=n(o,{userMessage:`Failed to save ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async update(t,e,r,a){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),i=s?{...s,...r}:{...r,id:e};this.store&&s&&this.store.getState().updateOptimistic(t,e,i,s);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.update(t,e,r),this._updateListCaches(t,e,i,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(a)){const o=c(),h=this._getEntityName(t);u("success",o.t("messages.updateSuccess",{ns:"crud",entity:h}))}}catch(o){s&&this._updateListCaches(t,e,s,"update"),this.store&&this.store.getState().rejectUpdate(t,e);const h=n(o,{userMessage:`Failed to update ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async delete(t,e,r){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const a=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&a&&this.store.getState().deleteOptimistic(t,e,a);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.delete(t,e),this._updateListCaches(t,e,null,"delete"),this.store&&this.store.getState().confirmDelete(t,e),this._shouldShowSuccessToast(r)){const s=c(),i=this._getEntityName(t);u("success",s.t("messages.deleteSuccess",{ns:"crud",entity:i}))}}catch(s){a&&this._updateListCaches(t,e,a,"add"),this.store&&this.store.getState().rejectDelete(t,e);const i=n(s,{userMessage:`Failed to delete ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}async add(t,e,r,a){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=`temp_${crypto.randomUUID()}`;this.store&&this.store.getState().addOptimistic(t,s,{...e,id:s});try{if(!this.adapter)throw new Error("Adapter not initialized");const i=await this.adapter.add(t,e,r);if(this._updateListCaches(t,s,null,"delete"),this._updateListCaches(t,i,{...e,id:i},"add"),this.store&&this.store.getState().confirmOptimistic(t,s,i,{...e,id:i}),this._shouldShowSuccessToast(a)){const o=c(),h=this._getEntityName(t);u("success",o.t("messages.createSuccess",{ns:"crud",entity:h}))}return i}catch(i){this._updateListCaches(t,s,null,"delete"),this.store&&this.store.getState().rejectOptimistic(t,s);const o=n(i,{userMessage:`Failed to create ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,o),o}finally{this.store&&this.store.getState().setLoading(t,!1)}}subscribe(t,e,r,a){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribe(t,e,(s,i)=>{s&&this.getQueryClient().setQueryData(["crud",t,"get",e],s),r(s,i)},a):(r(null,new Error("Adapter not initialized")),()=>{})}catch(s){return r(null,n(s)),()=>{}}}subscribeToCollection(t,e,r,a){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribeToCollection(t,e,(s,i)=>{s&&this.getQueryClient().setQueryData(["crud",t,"query",JSON.stringify(e)],{items:s}),r(s,i)},a):(r([],new Error("Adapter not initialized")),()=>{})}catch(s){return r([],n(s)),()=>{}}}async addOptimistic(t,e,r,a){this.adapter||await this.initialize("firestore");const s=`temp_${crypto.randomUUID()}`,i={...e,id:s,_optimistic:!0};this.store&&this.store.getState().addOptimistic(t,s,i);try{if(!this.adapter)throw new Error("Adapter not initialized");const o=await this.adapter.add(t,e,r),h={...e,id:o};if(this._updateListCaches(t,s,null,"delete"),this._updateListCaches(t,o,h,"add"),this.store&&this.store.getState().confirmOptimistic(t,s,o,h),this._shouldShowSuccessToast(a)){const d=c(),g=this._getEntityName(t);u("success",d.t("messages.createSuccess",{ns:"crud",entity:g}))}return h}catch(o){throw this._updateListCaches(t,s,null,"delete"),this.store&&this.store.getState().rejectOptimistic(t,s),n(o,{userMessage:`Failed to create ${t}`,showNotification:!0})}}async updateOptimistic(t,e,r,a,s){this.adapter||await this.initialize("firestore");const i=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),o=i?{...i,...r,_optimistic:!0}:{...r,id:e,_optimistic:!0};this.store&&i&&this.store.getState().updateOptimistic(t,e,o,i);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.update(t,e,r);const h={...o,_optimistic:void 0};if(this._updateListCaches(t,e,h,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(s)){const d=c(),g=this._getEntityName(t);u("success",d.t("messages.updateSuccess",{ns:"crud",entity:g}))}return h}catch(h){throw i&&this._updateListCaches(t,e,i,"update"),this.store&&this.store.getState().rejectUpdate(t,e),n(h,{userMessage:`Failed to update ${t}`,showNotification:!0})}}async deleteOptimistic(t,e,r){this.adapter||await this.initialize("firestore");const a=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&a&&this.store.getState().deleteOptimistic(t,e,a);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.delete(t,e),this._updateListCaches(t,e,null,"delete"),this.store&&this.store.getState().confirmDelete(t,e),this._shouldShowSuccessToast(r)){const s=c(),i=this._getEntityName(t);u("success",s.t("messages.deleteSuccess",{ns:"crud",entity:i}))}}catch(s){throw a&&this._updateListCaches(t,e,a,"add"),this.store&&this.store.getState().rejectDelete(t,e),n(s,{userMessage:`Failed to delete ${t}`,showNotification:!0})}}}const w=p(()=>new S);export{w as getCrudService};
@@ -1,97 +1,4 @@
1
- import type { CrudServiceInterface } from './CrudService';
2
- /**
3
- * Backend type for CRUD operations
4
- *
5
- * @version 0.0.1
6
- * @since 0.0.1
7
- * @author AMBROISE PARK Consulting
8
- */
9
- export type BackendType = 'functions' | 'firestore';
10
- /**
11
- * Optimistic operation status
12
- */
13
- export type OptimisticStatus = 'pending' | 'confirmed' | 'failed';
14
- /**
15
- * Optimistic operation metadata
16
- */
17
- export interface OptimisticMeta {
18
- tempId: string;
19
- originalData: unknown | null;
20
- status: OptimisticStatus;
21
- operation: 'add' | 'update' | 'delete';
22
- }
23
- /**
24
- * CRUD store state interface
25
- *
26
- * @version 0.0.2
27
- * @since 0.0.1
28
- * @author AMBROISE PARK Consulting
29
- */
30
- export interface CrudState {
31
- backend: BackendType | null;
32
- crudService: CrudServiceInterface | null;
33
- collections: Record<string, {
34
- loading: boolean;
35
- error: Error | null;
36
- data: Record<string, unknown>;
37
- lastUpdated: number;
38
- /** Optimistic operation metadata keyed by document id */
39
- optimistic: Record<string, OptimisticMeta>;
40
- }>;
41
- }
42
- /**
43
- * CRUD store actions interface
44
- *
45
- * @version 0.0.2
46
- * @since 0.0.1
47
- * @author AMBROISE PARK Consulting
48
- */
49
- export interface CrudActions {
50
- setCrudService: (service: CrudServiceInterface) => void;
51
- setBackend: (backend: BackendType) => void;
52
- setLoading: (collection: string, loading: boolean) => void;
53
- setError: (collection: string, error: Error | null) => void;
54
- setData: (collection: string, id: string, data: unknown) => void;
55
- /** Batch update multiple documents in a single state update (performance) */
56
- setDataBatch: (collection: string, items: Array<{
57
- id: string;
58
- data: unknown;
59
- }>) => void;
60
- removeData: (collection: string, id: string) => void;
61
- clearCollection: (collection: string) => void;
62
- clearError: (collection: string) => void;
63
- /** Add item optimistically (before server confirms) */
64
- addOptimistic: (collection: string, tempId: string, data: unknown) => void;
65
- /** Confirm optimistic add - replace temp item with real item */
66
- confirmOptimistic: (collection: string, tempId: string, realId: string, realData: unknown) => void;
67
- /** Reject optimistic add - remove temp item */
68
- rejectOptimistic: (collection: string, tempId: string) => void;
69
- /** Update item optimistically */
70
- updateOptimistic: (collection: string, id: string, data: unknown, originalData: unknown) => void;
71
- /** Confirm optimistic update */
72
- confirmUpdate: (collection: string, id: string) => void;
73
- /** Reject optimistic update - restore original data */
74
- rejectUpdate: (collection: string, id: string) => void;
75
- /** Delete item optimistically (hide but keep for rollback) */
76
- deleteOptimistic: (collection: string, id: string, originalData: unknown) => void;
77
- /** Confirm optimistic delete - remove completely */
78
- confirmDelete: (collection: string, id: string) => void;
79
- /** Reject optimistic delete - restore item */
80
- rejectDelete: (collection: string, id: string) => void;
81
- getLoading: (collection: string) => boolean;
82
- getError: (collection: string) => Error | null;
83
- getData: (collection: string, id: string) => unknown | null;
84
- /** Check if item is optimistic (not yet confirmed by server) */
85
- isOptimistic: (collection: string, id: string) => boolean;
86
- /** Get optimistic status for an item */
87
- getOptimisticStatus: (collection: string, id: string) => OptimisticStatus | null;
88
- /** Get all items in collection (including optimistic, excluding deleted) */
89
- getCollectionData: (collection: string) => Array<{
90
- id: string;
91
- data: unknown;
92
- isOptimistic: boolean;
93
- }>;
94
- }
1
+ import type { CrudState, CrudActions } from './types';
95
2
  /**
96
3
  * CRUD store hook for accessing CRUD state and actions
97
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"CrudStore.d.ts","sourceRoot":"","sources":["../src/CrudStore.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACxC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IAExB,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAGzC,WAAW,EAAE,MAAM,CACjB,MAAM,EACN;QACE,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9B,WAAW,EAAE,MAAM,CAAC;QACpB,yDAAyD;QACzD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;KAC5C,CACF,CAAC;CACH;AAQD;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAE1B,cAAc,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACxD,UAAU,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IAG3C,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,O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AAW,EAIZ,MAAM,SAAS,CAAC;AA0BjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,iIAqZvB,CAAC"}
package/dist/CrudStore.js CHANGED
@@ -1 +1 @@
1
- import{createDoNotDevStore as d}from"@donotdev/core";const m={backend:null,crudService:null,collections:{}},D=d({name:"crud-store",createStore:(l,r)=>({...m,setCrudService:t=>{l({crudService:t})},setBackend:t=>{l({backend:t})},setLoading:(t,i)=>{l(c=>{const o=c.collections[t]||{loading:!1,error:null,data:{},lastUpdated:0,optimistic:{}};return{collections:{...c.collections,[t]:{...o,loading:i}}}})},setError:(t,i)=>{l(c=>{const o=c.collections[t]||{loading:!1,error:null,data:{},lastUpdated:0,optimistic:{}};return{collections:{...c.collections,[t]:{...o,error:i,loading:!1}}}})},setData:(t,i,c)=>{l(o=>{const n=o.collections[t]||{loading:!1,error:null,data:{},lastUpdated:0,optimistic:{}};return{collections:{...o.collections,[t]:{...n,data:{...n.data,[i]:c},lastUpdated:Date.now(),error:null}}}})},setDataBatch:(t,i)=>{i.length!==0&&l(c=>{const o=c.collections[t]||{loading:!1,error:null,data:{},lastUpdated:0,optimistic:{}},n={...o.data};for(const{id:e,data:a}of i)n[e]=a;return{collections:{...c.collections,[t]:{...o,data:n,lastUpdated:Date.now(),error:null}}}})},removeData:(t,i)=>{l(c=>{const o=c.collections[t];if(!o)return c;const{[i]:n,...e}=o.data;return{collections:{...c.collections,[t]:{...o,data:e,lastUpdated:Date.now()}}}})},clearCollection:t=>{l(i=>{const{[t]:c,...o}=i.collections;return{collections:o}})},clearError:t=>{l(i=>{const c=i.collections[t];return c?{collections:{...i.collections,[t]:{...c,error:null}}}:i})},addOptimistic:(t,i,c)=>{l(o=>{const n=o.collections[t]||{loading:!1,error:null,data:{},lastUpdated:0,optimistic:{}};return{collections:{...o.collections,[t]:{...n,data:{...n.data,[i]:c},optimistic:{...n.optimistic,[i]:{tempId:i,originalData:null,status:"pending",operation:"add"}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,i,c,o)=>{l(n=>{const e=n.collections[t];if(!e)return n;const{[i]:a,...s}=e.data,{[i]:u,...p}=e.optimistic;return{collections:{...n.collections,[t]:{...e,data:{...s,[c]:o},optimistic:p,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,i)=>{l(c=>{const o=c.collections[t];if(!o)return c;const{[i]:n,...e}=o.data,{[i]:a,...s}=o.optimistic;return{collections:{...c.collections,[t]:{...o,data:e,optimistic:s,lastUpdated:Date.now()}}}})},updateOptimistic:(t,i,c,o)=>{l(n=>{const e=n.collections[t]||{loading:!1,error:null,data:{},lastUpdated:0,optimistic:{}};return{collections:{...n.collections,[t]:{...e,data:{...e.data,[i]:c},optimistic:{...e.optimistic,[i]:{tempId:i,originalData:o,status:"pending",operation:"update"}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,i)=>{l(c=>{const o=c.collections[t];if(!o)return c;const{[i]:n,...e}=o.optimistic;return{collections:{...c.collections,[t]:{...o,optimistic:e}}}})},rejectUpdate:(t,i)=>{l(c=>{const o=c.collections[t];if(!o)return c;const n=o.optimistic[i];if(!n||n.operation!=="update")return c;const{[i]:e,...a}=o.optimistic;return{collections:{...c.collections,[t]:{...o,data:{...o.data,[i]:n.originalData},optimistic:a,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,i,c)=>{l(o=>{const n=o.collections[t];if(!n)return o;const{[i]:e,...a}=n.data;return{collections:{...o.collections,[t]:{...n,data:a,optimistic:{...n.optimistic,[i]:{tempId:i,originalData:c,status:"pending",operation:"delete"}},lastUpdated:Date.now()}}}})},confirmDelete:(t,i)=>{l(c=>{const o=c.collections[t];if(!o)return c;const{[i]:n,...e}=o.optimistic;return{collections:{...c.collections,[t]:{...o,optimistic:e}}}})},rejectDelete:(t,i)=>{l(c=>{const o=c.collections[t];if(!o)return c;const n=o.optimistic[i];if(!n||n.operation!=="delete")return c;const{[i]:e,...a}=o.optimistic;return{collections:{...c.collections,[t]:{...o,data:{...o.data,[i]:n.originalData},optimistic:a,lastUpdated:Date.now()}}}})},getLoading:t=>r().collections[t]?.loading||!1,getError:t=>r().collections[t]?.error||null,getData:(t,i)=>r().collections[t]?.data[i]||null,isOptimistic:(t,i)=>r().collections[t]?.optimistic[i]?.status==="pending",getOptimisticStatus:(t,i)=>r().collections[t]?.optimistic[i]?.status??null,getCollectionData:t=>{const i=r().collections[t];return i?Object.entries(i.data).map(([c,o])=>({id:c,data:o,isOptimistic:i.optimistic[c]?.status==="pending"})):[]}})});export{D as useCrudStore};
1
+ import{createDoNotDevStore as u}from"@donotdev/core";const d={filters:{},showFavoritesOnly:!1};function r(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...d}}}const m={backend:null,crudService:null,hideSuccessToasts:!1,collections:{}},g=u({name:"crud-store",createStore:(l,n)=>({...m,setCrudService:t=>{l({crudService:t})},setBackend:t=>{l({backend:t})},setHideSuccessToasts:t=>{l({hideSuccessToasts:t})},setLoading:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,loading:e}}}})},setError:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,error:e,loading:!1}}}})},setFilters:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,ui:{...i.ui,filters:e}}}}})},setShowFavoritesOnly:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,ui:{...i.ui,showFavoritesOnly:e}}}}})},getFilters:t=>n().collections[t]?.ui?.filters||{},getShowFavoritesOnly:t=>n().collections[t]?.ui?.showFavoritesOnly||!1,clearCollection:t=>{l(e=>{const{[t]:o,...i}=e.collections;return{collections:i}})},clearError:t=>{l(e=>{const o=e.collections[t];return o?{collections:{...e.collections,[t]:{...o,error:null}}}:e})},addOptimistic:(t,e,o)=>{l(i=>{const c=i.collections[t]||r();return{collections:{...i.collections,[t]:{...c,optimistic:{...c.optimistic,[e]:{tempId:e,originalData:null,optimisticData:o,status:"pending",operation:"add"}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,e,o,i)=>{l(c=>{const s=c.collections[t];if(!s)return c;const{[e]:a,...p}=s.optimistic;return{collections:{...c.collections,[t]:{...s,optimistic:p,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const{[e]:c,...s}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:s,lastUpdated:Date.now()}}}})},updateOptimistic:(t,e,o,i)=>{l(c=>{const s=c.collections[t]||r();return{collections:{...c.collections,[t]:{...s,optimistic:{...s.optimistic,[e]:{tempId:e,originalData:i,optimisticData:o,status:"pending",operation:"update"}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const{[e]:c,...s}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:s}}}})},rejectUpdate:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const c=i.optimistic[e];if(!c||c.operation!=="update")return o;const{[e]:s,...a}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:a,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,e,o)=>{l(i=>{const c=i.collections[t];return c?{collections:{...i.collections,[t]:{...c,optimistic:{...c.optimistic,[e]:{tempId:e,originalData:o,optimisticData:null,status:"pending",operation:"delete"}},lastUpdated:Date.now()}}}:i})},confirmDelete:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const{[e]:c,...s}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:s}}}})},rejectDelete:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const c=i.optimistic[e];if(!c||c.operation!=="delete")return o;const{[e]:s,...a}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:a,lastUpdated:Date.now()}}}})},getLoading:t=>n().collections[t]?.loading||!1,getError:t=>n().collections[t]?.error||null,isOptimistic:(t,e)=>n().collections[t]?.optimistic[e]?.status==="pending",getOptimisticStatus:(t,e)=>n().collections[t]?.optimistic[e]?.status??null,getOptimisticData:(t,e)=>n().collections[t]?.optimistic[e]?.optimisticData??null})});export{g as useCrudStore};
@@ -1 +1 @@
1
- "use client";class i{components=new Map;registerComponent(e,n,o){this.components.set(e,{controlled:n,uncontrolled:o})}register(e){const{type:n,controlledComponent:o,uncontrolledComponent:l}=e;this.components.set(n,{controlled:o,uncontrolled:l})}getControlledComponent(e){return this.components.get(e)?.controlled}getUncontrolledComponent(e){return this.components.get(e)?.uncontrolled}has(e){return this.components.has(e)}getRegisteredTypes(){return Array.from(this.components.keys())}clear(){this.components.clear()}}let r=null;function s(){return r||(r=new i),r}function c(t){s().register(t)}function p(t){return s().has(t)}export{s as getFieldRegistry,p as isFieldTypeRegistered,c as registerFieldType};
1
+ "use client";class c{components=new Map;registerComponent(e,t,o){this.components.set(e,{controlled:t,uncontrolled:o})}register(e){const{type:t,controlledComponent:o,uncontrolledComponent:l}=e;this.components.set(t,{controlled:o,uncontrolled:l})}getControlledComponent(e){return this.components.get(e)?.controlled}getUncontrolledComponent(e){return this.components.get(e)?.uncontrolled}has(e){return this.components.has(e)}getRegisteredTypes(){return Array.from(this.components.keys())}clear(){this.components.clear()}}let r=null;function s(){return r||(r=new c),r}function i(n){s().register(n)}function p(n){return s().has(n)}export{s as getFieldRegistry,p as isFieldTypeRegistered,i as registerFieldType};
@@ -1,5 +1,6 @@
1
1
  import type { dndevSchema } from '@donotdev/core';
2
2
  import { type Unsubscribe, type FirestoreError } from '@donotdev/firebase';
3
+ import type { PaginatedQueryResult } from './FunctionsAdapter';
3
4
  /**
4
5
  * Firestore query operators
5
6
  */
@@ -22,6 +23,7 @@ export interface QueryOptions {
22
23
  direction?: 'asc' | 'desc';
23
24
  }>;
24
25
  limit?: number;
26
+ startAfterId?: string;
25
27
  }
26
28
  /**
27
29
  * Subscription callback for document subscriptions
@@ -56,7 +58,7 @@ export declare class FirestoreAdapter {
56
58
  update<T>(collectionName: string, id: string, data: Partial<T>): Promise<void>;
57
59
  delete(collectionName: string, id: string): Promise<void>;
58
60
  add<T>(collectionName: string, data: T, schema: dndevSchema<T>): Promise<string>;
59
- query<T>(collectionName: string, options: QueryOptions, schema: dndevSchema<unknown>): Promise<T[]>;
61
+ query<T>(collectionName: string, options: QueryOptions, schema: dndevSchema<unknown>, _schemaType?: 'list' | 'listCard'): Promise<PaginatedQueryResult<T>>;
60
62
  subscribe<T>(collectionName: string, id: string, callback: SubscriptionCallback<T>, schema: dndevSchema<unknown>): Unsubscribe;
61
63
  subscribeToCollection<T>(collectionName: string, options: QueryOptions, callback: CollectionSubscriptionCallback<T>, schema: dndevSchema<unknown>): Unsubscribe;
62
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FirestoreAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FirestoreAdapter.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAqBL,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAQ5B;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,IAAI,GACJ,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,gBAAgB,GAChB,IAAI,GACJ,QAAQ,CAAC;AAEb;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,iBAAiB,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC9E,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;CAChB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,CAAC,CA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B,CAAC,CAAC,CAAC,CAAC;IA6FnC,SAAS,CAAC,CAAC,EACT,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,EACjC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,WAAW;IA8Bd,qBAAqB,CAAC,CAAC,EACrB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,8BAA8B,CAAC,CAAC,CAAC,EAC3C,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,WAAW;CAgDf"}
@@ -1 +1 @@
1
- import*as f from"valibot";import{handleError as p}from"@donotdev/core";import{getFirestore as R,getFirebaseSDK as I,doc as l,getDoc as B,getDocs as q,setDoc as x,updateDoc as C,deleteDoc as E,addDoc as v,collection as S,query as F,where as g,orderBy as w,limit as m,onSnapshot as A}from"@donotdev/firebase";import{transformFirestoreData as h,prepareForFirestore as y}from"@donotdev/firebase";class L{firestore;ensureFirestore(){if(this.firestore)return!0;try{return this.firestore=R(),!0}catch{return!1}}getCollectionRef(s){return!this.ensureFirestore()||!this.firestore?null:S(this.firestore,s)}async get(s,e,r){if(!this.ensureFirestore()||!this.firestore)return null;try{const i=l(this.firestore,s,e),t=await B(i);if(!t.exists())return null;let o=t.data();return o=h(o),{...f.parse(r,o),id:e}}catch(i){return p(i,{context:{operation:"FirestoreAdapter.get",collection:s,docId:e},severity:"warning"}),null}}async set(s,e,r,i){if(!(!this.ensureFirestore()||!this.firestore))try{f.parse(i,r);const t=l(this.firestore,s,e),o=y(r);await x(t,o)}catch(t){throw t}}async update(s,e,r){if(!(!this.ensureFirestore()||!this.firestore))try{const i=l(this.firestore,s,e),t=y(r);await C(i,t)}catch(i){throw i}}async delete(s,e){if(!(!this.ensureFirestore()||!this.firestore))try{const r=l(this.firestore,s,e);await E(r)}catch(r){throw r}}async add(s,e,r){if(!this.ensureFirestore())return"";try{f.parse(r,e);const i=this.getCollectionRef(s);if(!i)return"";const t=new Date().toISOString(),o=I().getCurrentUser()?.uid||"anonymous",c={...e,createdAt:t,updatedAt:t,createdById:o,updatedById:o},a=y(c);return(await v(i,a)).id}catch(i){throw i}}async query(s,e,r){if(!this.ensureFirestore())return[];const i=this.getCollectionRef(s);if(!i)return[];try{const t=[];if(e.where)for(const n of e.where)t.push(g(n.field,n.operator,n.value));if(e.orderBy)for(const n of e.orderBy)t.push(w(n.field,n.direction||"asc"));e.limit&&t.push(m(e.limit));const o=F(i,...t),c=await q(o),a=[];return c.forEach(n=>{try{let d=n.data();if(!d)return;d=h(d);const u=f.parse(r,d);a.push({...u,id:n.id})}catch(d){p(d,{context:{operation:"FirestoreAdapter.query.parse",docId:n.id,collection:s},showNotification:!1})}}),a}catch(t){throw p(t,{context:{operation:"FirestoreAdapter.query",collection:s,options:e}}),t}}subscribe(s,e,r,i){if(!this.ensureFirestore()||!this.firestore)return()=>{};const t=l(this.firestore,s,e);return A(t,o=>{try{if(!o.exists()){r(null);return}let c=o.data();c=h(c);const a=f.parse(i,c);r({...a,id:e})}catch(c){r(null,c)}},o=>{r(null,o)})}subscribeToCollection(s,e,r,i){if(!this.ensureFirestore())return()=>{};const t=this.getCollectionRef(s);if(!t)return()=>{};try{const o=[];if(e.where)for(const a of e.where)o.push(g(a.field,a.operator,a.value));if(e.orderBy)for(const a of e.orderBy)o.push(w(a.field,a.direction||"asc"));e.limit&&o.push(m(e.limit));const c=F(t,...o);return A(c,a=>{try{const n=[];a.forEach(d=>{let u=d.data();u=h(u);const D=f.parse(i,u);n.push({...D,id:d.id})}),r(n)}catch(n){r([],n)}},a=>{r([],a)})}catch(o){return r([],o),()=>{}}}}export{L as FirestoreAdapter};
1
+ import*as d from"valibot";import{handleError as w}from"@donotdev/core";import{getFirestore as b,getFirebaseSDK as v,doc as p,getDoc as g,getDocs as q,setDoc as R,updateDoc as S,deleteDoc as E,addDoc as M,collection as V,query as A,where as D,orderBy as x,limit as B,startAfter as z,onSnapshot as I}from"@donotdev/firebase";import{transformFirestoreData as m,prepareForFirestore as F}from"@donotdev/firebase";class K{firestore;ensureFirestore(){if(this.firestore)return!0;try{return this.firestore=b(),!0}catch{return!1}}getCollectionRef(s){return!this.ensureFirestore()||!this.firestore?null:V(this.firestore,s)}async get(s,t,e){if(!this.ensureFirestore()||!this.firestore)return null;try{const o=p(this.firestore,s,t),i=await g(o);if(!i.exists())return null;let r=i.data();return r=m(r),{...d.parse(e,r),id:t}}catch(o){return w(o,{context:{operation:"FirestoreAdapter.get",collection:s,docId:t},severity:"warning"}),null}}async set(s,t,e,o){if(!(!this.ensureFirestore()||!this.firestore))try{d.parse(o,e);const i=p(this.firestore,s,t),r=F(e);await R(i,r)}catch(i){throw i}}async update(s,t,e){if(!(!this.ensureFirestore()||!this.firestore))try{const o=p(this.firestore,s,t),i=F(e);await S(o,i)}catch(o){throw o}}async delete(s,t){if(!(!this.ensureFirestore()||!this.firestore))try{const e=p(this.firestore,s,t);await E(e)}catch(e){throw e}}async add(s,t,e){if(!this.ensureFirestore())return"";try{d.parse(e,t);const o=this.getCollectionRef(s);if(!o)return"";const i=new Date().toISOString(),r=v().getCurrentUser()?.uid||"anonymous",c={...t,createdAt:i,updatedAt:i,createdById:r,updatedById:r},a=F(c);return(await M(o,a)).id}catch(o){throw o}}async query(s,t,e,o="list"){if(!this.ensureFirestore())return{items:[]};const i=this.getCollectionRef(s);if(!i)return{items:[]};try{const r=[];if(t.where)for(const n of t.where)r.push(D(n.field,n.operator,n.value));if(t.orderBy)for(const n of t.orderBy)r.push(x(n.field,n.direction||"asc"));if(t.startAfterId){const n=await g(p(i,t.startAfterId));n.exists()&&r.push(z(n))}const c=t.limit?t.limit+1:void 0;c&&r.push(B(c));const a=A(i,...r),h=await q(a),u=[];let l=null;h.forEach(n=>{try{let f=n.data();if(!f)return;f=m(f);const C=d.parse(e,f);u.push({...C,id:n.id}),l=n.id}catch(f){w(f,{context:{operation:"FirestoreAdapter.query.parse",docId:n.id,collection:s},showNotification:!1})}});const y=c?u.length>(t.limit||0):!1;return{items:y?u.slice(0,t.limit):u,hasMore:y,lastVisible:l,total:void 0}}catch(r){throw w(r,{context:{operation:"FirestoreAdapter.query",collection:s,options:t}}),r}}subscribe(s,t,e,o){if(!this.ensureFirestore()||!this.firestore)return()=>{};const i=p(this.firestore,s,t);return I(i,r=>{try{if(!r.exists()){e(null);return}let c=r.data();c=m(c);const a=d.parse(o,c);e({...a,id:t})}catch(c){e(null,c)}},r=>{e(null,r)})}subscribeToCollection(s,t,e,o){if(!this.ensureFirestore())return()=>{};const i=this.getCollectionRef(s);if(!i)return()=>{};try{const r=[];if(t.where)for(const a of t.where)r.push(D(a.field,a.operator,a.value));if(t.orderBy)for(const a of t.orderBy)r.push(x(a.field,a.direction||"asc"));t.limit&&r.push(B(t.limit));const c=A(i,...r);return I(c,a=>{try{const h=[];a.forEach(u=>{let l=u.data();l=m(l);const y=d.parse(o,l);h.push({...y,id:u.id})}),e(h)}catch(h){e([],h)}},a=>{e([],a)})}catch(r){return e([],r),()=>{}}}}export{K as FirestoreAdapter};
@@ -17,6 +17,13 @@ export interface FunctionsQueryOptions {
17
17
  direction?: 'asc' | 'desc';
18
18
  }>;
19
19
  limit?: number;
20
+ startAfterId?: string;
21
+ }
22
+ export interface PaginatedQueryResult<T> {
23
+ items: T[];
24
+ total?: number;
25
+ hasMore?: boolean;
26
+ lastVisible?: string | null;
20
27
  }
21
28
  /**
22
29
  * Functions backend adapter
@@ -37,7 +44,7 @@ export declare class FunctionsAdapter {
37
44
  update<T>(collectionName: string, id: string, data: Partial<T>): Promise<void>;
38
45
  delete(collectionName: string, id: string): Promise<void>;
39
46
  add<T>(collectionName: string, data: T, schema: dndevSchema<T>): Promise<string>;
40
- query<T>(collectionName: string, options: FunctionsQueryOptions, schema: dndevSchema<unknown>): Promise<T[]>;
47
+ query<T>(collectionName: string, options: FunctionsQueryOptions, schema: dndevSchema<unknown>, schemaType?: 'list' | 'listCard'): Promise<PaginatedQueryResult<T>>;
41
48
  listCard<T>(collectionName: string, options: FunctionsQueryOptions, schema: dndevSchema<T>): Promise<T[]>;
42
49
  subscribe<T>(): () => void;
43
50
  subscribeToCollection<T>(): () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionsAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FunctionsAdapter.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;IAC5D,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;CAChB;AAED;;;;;;;;GAQG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,MAAM,CAAS;;YAOT,eAAe;IAUvB,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;IAed,GAAG,CAAC,CAAC,EACT,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,IAAI,CAAC;IAeV,MAAM,CAAC,CAAC,EACZ,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GACf,OAAO,CAAC,IAAI,CAAC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B,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,EAAE,CAAC;IAgDf,SAAS,CAAC,CAAC,KAAK,MAAM,IAAI;IAM1B,qBAAqB,CAAC,CAAC,KAAK,MAAM,IAAI;CAKvC"}
@@ -1 +1 @@
1
- import{httpsCallable as a}from"firebase/functions";import*as o from"valibot";import{getPlatformEnvVar as h}from"@donotdev/core";import{getFirebaseFunctions as l}from"@donotdev/firebase";class F{functions;region;constructor(){this.region=h("FIREBASE_FUNCTIONS_REGION")||"europe-west1"}async ensureFunctions(){if(this.functions)return!0;try{return this.functions=await l(this.region),!0}catch{return!1}}async get(n,t,s){if(!await this.ensureFunctions())return null;try{const r=`get_${n}`;return(await a(this.functions,r)({id:t})).data}catch(r){throw r}}async set(n,t,s,r){if(await this.ensureFunctions())try{o.parse(r,s);const e=`update_${n}`;await a(this.functions,e)({id:t,payload:s})}catch(e){throw e}}async update(n,t,s){if(await this.ensureFunctions())try{const r=`update_${n}`;await a(this.functions,r)({id:t,payload:s})}catch(r){throw r}}async delete(n,t){if(await this.ensureFunctions())try{const s=`delete_${n}`;await a(this.functions,s)({id:t})}catch(s){throw s}}async add(n,t,s){if(!await this.ensureFunctions())return"";try{o.parse(s,t);const r=`create_${n}`;return(await a(this.functions,r)({payload:t})).data.id}catch(r){throw r}}async query(n,t,s){if(!await this.ensureFunctions())return[];try{const r=`list_${n}`,e={};return t.where&&(e.where=t.where.map(i=>[i.field,i.operator,i.value])),t.orderBy&&(e.orderBy=t.orderBy.map(i=>[i.field,i.direction||"asc"])),t.limit&&(e.limit=t.limit),(await a(this.functions,r)(e)).data.items}catch(r){throw r}}async listCard(n,t,s){if(!await this.ensureFunctions())return[];try{const r=`listCard_${n}`,e={};return t.where&&(e.where=t.where.map(i=>[i.field,i.operator,i.value])),t.orderBy&&(e.orderBy=t.orderBy.map(i=>[i.field,i.direction||"asc"])),t.limit&&(e.limit=t.limit),(await a(this.functions,r)(e)).data.items}catch(r){throw r}}subscribe(){throw new Error("Subscriptions are not supported with Functions backend. Use Firestore backend for real-time features.")}subscribeToCollection(){throw new Error("Subscriptions are not supported with Functions backend. Use Firestore backend for real-time features.")}}export{F as FunctionsAdapter};
1
+ import{httpsCallable as n}from"firebase/functions";import*as u from"valibot";import{getPlatformEnvVar as d}from"@donotdev/core";import{getFirebaseFunctions as h}from"@donotdev/firebase";class l{functions;region;constructor(){this.region=d("FIREBASE_FUNCTIONS_REGION")||"europe-west1"}async ensureFunctions(){if(this.functions)return!0;try{return this.functions=await h(this.region),!0}catch{return!1}}async get(i,t,a){if(!await this.ensureFunctions())return null;try{const r=`get_${i}`;return(await n(this.functions,r)({id:t})).data}catch(r){throw r}}async set(i,t,a,r){if(await this.ensureFunctions())try{u.parse(r,a);const e=`update_${i}`;await n(this.functions,e)({id:t,payload:a})}catch(e){throw e}}async update(i,t,a){if(await this.ensureFunctions())try{const r=`update_${i}`;await n(this.functions,r)({id:t,payload:a})}catch(r){throw r}}async delete(i,t){if(await this.ensureFunctions())try{const a=`delete_${i}`;await n(this.functions,a)({id:t})}catch(a){throw a}}async add(i,t,a){if(!await this.ensureFunctions())return"";try{u.parse(a,t);const r=`create_${i}`;return(await n(this.functions,r)({payload:t})).data.id}catch(r){throw r}}async query(i,t,a,r="list"){if(!await this.ensureFunctions())return{items:[]};try{const e=r==="listCard"?`listCard_${i}`:`list_${i}`,s={};t.where&&(s.where=t.where.map(o=>[o.field,o.operator,o.value])),t.orderBy&&(s.orderBy=t.orderBy.map(o=>[o.field,o.direction||"asc"])),t.limit&&(s.limit=t.limit),t.startAfterId&&(s.startAfterId=t.startAfterId);const c=await n(this.functions,e)(s);return{items:c.data.items,total:c.data.count,hasMore:c.data.hasMore,lastVisible:c.data.lastVisible}}catch(e){throw e}}async listCard(i,t,a){if(!await this.ensureFunctions())return[];try{const r=`listCard_${i}`,e={};return t.where&&(e.where=t.where.map(s=>[s.field,s.operator,s.value])),t.orderBy&&(e.orderBy=t.orderBy.map(s=>[s.field,s.direction||"asc"])),t.limit&&(e.limit=t.limit),(await n(this.functions,r)(e)).data.items}catch(r){throw r}}subscribe(){throw new Error("Subscriptions are not supported with Functions backend. Use Firestore backend for real-time features.")}subscribeToCollection(){throw new Error("Subscriptions are not supported with Functions backend. Use Firestore backend for real-time features.")}}export{l as FunctionsAdapter};
@@ -1 +1 @@
1
- export*from"./FirestoreAdapter";import{FunctionsAdapter as e}from"./FunctionsAdapter";export{e as FunctionsAdapter};
1
+ export*from"./FirestoreAdapter";import{FunctionsAdapter as o}from"./FunctionsAdapter";export{o as FunctionsAdapter};
@@ -1,9 +1,22 @@
1
1
  /**
2
- * Register built-in field types (UI components only)
2
+ * @fileoverview Built-in Field Type Registrations
3
+ * @description Legacy wrapper - now delegates to unified registry.
3
4
  *
4
- * **Note for Consumers:**
5
- * This function demonstrates the registration pattern. For your own custom field types,
6
- * use `registerFieldType()` from `@donotdev/crud` instead. See SETUP_CRUD.md for examples.
5
+ * **For Framework Consumers:**
6
+ * This file is kept for backward compatibility. The actual registration happens
7
+ * in registerBuiltinFieldTypes.ts via the unified field type registry.
8
+ *
9
+ * For your own custom field types, use `registerFieldType()` from `@donotdev/crud`.
10
+ * See SETUP_CRUD.md for examples.
11
+ *
12
+ * @version 0.0.2
13
+ * @since 0.0.1
14
+ * @author AMBROISE PARK Consulting
15
+ */
16
+ import './registerBuiltinFieldTypes';
17
+ /**
18
+ * @deprecated Registration now handled by unified registry
19
+ * Kept for backward compatibility
7
20
  */
8
21
  export declare function registerBuiltinFieldTypes(): void;
9
22
  //# sourceMappingURL=builtinFieldTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builtinFieldTypes.d.ts","sourceRoot":"","sources":["../src/builtinFieldTypes.tsx"],"names":[],"mappings":"AAyKA;;;;;;GAMG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAyGhD"}
1
+ {"version":3,"file":"builtinFieldTypes.d.ts","sourceRoot":"","sources":["../src/builtinFieldTypes.tsx"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,6BAA6B,CAAC;AAErC;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAGhD"}
@@ -1 +1 @@
1
- "use client";import{jsx as s}from"react/jsx-runtime";import{ControlledCheckboxField as g,ControlledComboboxField as u,ControlledDateField as m,ControlledDropdownField as F,ControlledFileField as f,ControlledMultiFileField as h,ControlledDocumentField as b,ControlledMultiDocumentField as x,ControlledGeoPointField as v,ControlledImageField as T,ControlledMapField as U,ControlledMultiDropdownField as w,ControlledMultiInputField as R,ControlledNumberField as y,ControlledPasswordField as M,ControlledPhoneField as k,ControlledRangeField as D,ControlledRadioField as A,ControlledTextField as d,ControlledTextareaField as B,ControlledRichTextField as I,ControlledTimestampField as P,ControlledAddressField as j,ControlledSwitchField as H,ControlledMultiImageField as S}from"./components/controlled";import{AvatarFieldComponent as G,BadgeFieldComponent as N,ButtonFieldComponent as p,HiddenFieldComponent as _,TextAreaComponent as q,RichTextComponent as z,TextFieldComponent as E}from"./components/form/fields";import{getFieldRegistry as J}from"./FieldRegistry";const K=e=>{const{name:t,value:o,onChange:r,error:n,t:i,config:l,...a}=e;return s(G,{config:l,value:o,onChange:r,error:!!n,helperText:n||void 0,t:i,...l.options,...a})},L=e=>{const{name:t,value:o,onChange:r,error:n,t:i,config:l,...a}=e;return s(N,{config:l,value:o,onChange:r,error:!!n,helperText:n||void 0,t:i,...l.options,...a})},O=e=>{const{name:t,label:o,onChange:r,config:n}=e;return s(p,{label:o||t,type:"submit",onClick:()=>r(void 0),...n.options})},Q=e=>{const{name:t,label:o,onChange:r,config:n}=e;return s(p,{label:o||t,type:"reset",onClick:()=>r(void 0),...n.options})},V=e=>{const{name:t,value:o}=e;return s(_,{name:t,value:o})},W=e=>{const{name:t,label:o,value:r,onChange:n,error:i,config:l}=e;return s(q,{label:o||t,value:r,onChange:n,error:i||void 0,...l.options})},X=e=>{const{name:t,label:o,value:r,onChange:n,error:i,config:l}=e;return s(z,{label:o||t,value:r,onChange:n,error:i||void 0,...l.options})},C=e=>{const{name:t,label:o,value:r,onChange:n,error:i,config:l}=e;return s(E,{label:o||t,value:r,onChange:n,error:i||void 0,...l.options})};let c=!1;function Y(){if(c)return;c=!0;const e=J();e.registerComponent("text",d,C),e.registerComponent("email",d,C),e.registerComponent("url",d,C),e.registerComponent("color",d,C),e.registerComponent("textarea",B,W),e.registerComponent("richtext",I,X),e.registerComponent("password",M),e.registerComponent("number",y),e.registerComponent("range",D),e.registerComponent("boolean",g),e.registerComponent("checkbox",g),e.registerComponent("switch",H),e.registerComponent("date",m),e.registerComponent("datetime-local",m),e.registerComponent("time",m),e.registerComponent("week",m),e.registerComponent("month",m),e.registerComponent("timestamp",P),e.registerComponent("file",f),e.registerComponent("files",h),e.registerComponent("document",b),e.registerComponent("documents",x),e.registerComponent("image",T),e.registerComponent("images",S),e.registerComponent("geopoint",v),e.registerComponent("address",j),e.registerComponent("map",U),e.registerComponent("array",R),e.registerComponent("select",F),e.registerComponent("combobox",u),e.registerComponent("multiselect",w),e.registerComponent("radio",A),e.registerComponent("tel",k),e.registerComponent("avatar",d,K),e.registerComponent("badge",d,L),e.registerComponent("hidden",d,V),e.registerComponent("submit",d,O),e.registerComponent("reset",d,Q)}Y();export{Y as registerBuiltinFieldTypes};
1
+ "use client";import"./registerBuiltinFieldTypes";function i(){}export{i as registerBuiltinFieldTypes};
@@ -1 +1 @@
1
- "use client";import{jsx as n}from"react/jsx-runtime";import{ActionButton as d}from"@donotdev/components";import{useCrudStore as l}from"../CrudStore";function a({requiresAuth:t=!0,user:e,disabled:r=!1,children:i,...o}){const s=l(u=>!!u.crudService);return n(d,{...o,disabled:r||!s||t&&!e,children:i})}var p=a;export{p as default};
1
+ "use client";import{jsx as d}from"react/jsx-runtime";import{ActionButton as n}from"@donotdev/components";import{useCrudStore as a}from"../CrudStore";function c({requiresAuth:r=!0,user:e,disabled:t=!1,children:s,...i}){const o=a(u=>!!u.crudService);return d(n,{...i,disabled:t||!o||r&&!e,children:s})}var l=c;export{l as default};
@@ -18,10 +18,12 @@ export interface DisplayFieldRendererProps<T extends FieldType = FieldType> {
18
18
  * @param t - Translation function
19
19
  * @param options - Formatting options
20
20
  * @param options.compact - Use compact formatting (smaller images, plain spans for empty)
21
+ * @param options.asString - Prefer string output when possible (e.g. for price in text placeholders)
21
22
  * @returns Formatted value as string or ReactElement
22
23
  */
23
24
  export declare function formatValue(value: any, config: EntityField, t: (key: string, options?: Record<string, any>) => string, options?: {
24
25
  compact?: boolean;
26
+ asString?: boolean;
25
27
  }): string | ReactElement;
26
28
  /**
27
29
  * DisplayFieldRenderer - Renders a field value as read-only display
@@ -1 +1 @@
1
- {"version":3,"file":"DisplayFieldRenderer.d.ts","sourceRoot":"","sources":["../../src/components/DisplayFieldRenderer.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,MAAM,WAAW,yBAAyB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IACxE,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACvB,0BAA0B;IAC1B,KAAK,EAAE,GAAG,CAAC;IACX,2BAA2B;IAC3B,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC;CAC3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,EACzD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;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,EACpE,IAAI,EACJ,MAAM,EACN,KAAK,EACL,CAAC,GACF,EAAE,yBAAyB,CAAC,CAAC,CAAC,GAAG,YAAY,CAyC7C;AAED,eAAe,oBAAoB,CAAC"}
@@ -1 +1 @@
1
- "use client";import{jsx as e,jsxs as o}from"react/jsx-runtime";import{Text as i,Stack as d}from"@donotdev/components";import{translateFieldLabel as y,translateLabel as g}from"../forms/utils";function b(r,c,l,m){const n=m?.compact??!1;if(r==null||r==="")return n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"});switch(c.type){case"timestamp":case"date":case"datetime-local":try{const t=r instanceof Date?r:new Date(r);return c.type==="date"?t.toLocaleDateString():t.toLocaleString()}catch{return String(r)}case"boolean":case"checkbox":return r?"Yes":"No";case"number":case"range":return typeof r=="number"?r.toLocaleString():String(r);case"select":case"radio":const p=c.validation?.options;if(Array.isArray(p)){const a=p.find(s=>s.value===r)?.label;return a?g(a,l):String(r)}return String(r);case"multiselect":if(Array.isArray(r)){const t=c.validation?.options;if(Array.isArray(t))return r.map(s=>{const h=t.find(u=>u.value===s)?.label;return h?g(h,l):s}).join(", ")}return String(r);case"image":case"images":if(typeof r=="string")return e("img",{src:r,alt:c.label||"",style:{width:n?"40px":void 0,height:n?"40px":void 0,maxWidth:n?void 0:"200px",maxHeight:n?void 0:"150px",objectFit:"cover",borderRadius:"var(--radius-sm)"}});if(Array.isArray(r)&&r.length>0){const t=r[0],a=typeof t=="object"&&t.thumbUrl?t.thumbUrl:t;return n?o("div",{style:{display:"flex",alignItems:"center",gap:"var(--gap-xs)"},children:[e("img",{src:a,alt:"",style:{width:"40px",height:"40px",objectFit:"cover",borderRadius:"var(--radius-sm)"}}),r.length>1&&o("span",{style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:["+",r.length-1]})]}):o(d,{direction:"row",gap:"tight",style:{flexWrap:"wrap"},children:[r.slice(0,4).map((s,f)=>{const h=typeof s=="object"&&s.thumbUrl?s.thumbUrl:s;return e("img",{src:h,alt:`${c.label} ${f+1}`,style:{width:"60px",height:"60px",objectFit:"cover",borderRadius:"var(--radius-sm)"}},f)}),r.length>4&&o(i,{variant:"muted",children:["+",r.length-4," more"]})]})}return n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"});case"files":case"documents":return Array.isArray(r)?r.length===0?n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"}):e(d,{gap:"tight",children:r.map((t,a)=>o("a",{href:t.url||t,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none",display:"flex",alignItems:"center",fontSize:"var(--font-size-sm)"},children:[t.filename||`File ${a+1}`,t.size&&o(i,{level:"caption",variant:"muted",style:{marginLeft:"var(--gap-sm)"},children:["(",Math.round(t.size/1024)," KB)"]})]},a))}):n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"});case"file":case"document":if(r){const t=typeof r=="string"?r:r.url,a=typeof r=="string"?"View file":r.filename||"View file";return o("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none"},children:[a,typeof r=="object"&&r.size&&o("span",{style:{color:"var(--muted-foreground)",marginLeft:"var(--gap-sm)"},children:["(",Math.round(r.size/1024)," KB)"]})]})}return n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"});case"reference":return String(r);case"geopoint":return r&&typeof r=="object"&&"lat"in r&&"lng"in r?`${r.lat.toFixed(6)}, ${r.lng.toFixed(6)}`:n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"});case"address":return r&&typeof r=="object"&&"formatted_address"in r?r.formatted_address:String(r);case"map":if(r&&typeof r=="object"){const t=Object.entries(r);return t.length===0?n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"}):o(d,{direction:"column",gap:"tight",children:[t.slice(0,5).map(([a,s])=>o(i,{style:{fontSize:"var(--font-size-sm)"},children:[o("strong",{children:[a,":"]})," ",String(s)]},a)),t.length>5&&o(i,{variant:"muted",children:["+",t.length-5," more"]})]})}return n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"});case"array":return Array.isArray(r)?r.length===0?n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"}):r.join(", "):n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"});case"password":return"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";case"email":return e("a",{href:`mailto:${r}`,style:{color:"var(--primary)"},onClick:t=>t.stopPropagation(),children:r});case"tel":return e("a",{href:`tel:${r}`,style:{color:"var(--primary)"},onClick:t=>t.stopPropagation(),children:r});case"url":return e("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)"},children:r});case"color":return o(d,{direction:"row",gap:"tight",align:"center",children:[e("div",{style:{width:"20px",height:"20px",backgroundColor:r,borderRadius:"var(--radius-sm)",border:"1px solid var(--border)"}}),e(i,{children:r})]});case"textarea":case"text":return String(r);case"richtext":return r&&typeof r=="string"?n?r.replace(/<[^>]*>/g,"").trim()||e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e("div",{dangerouslySetInnerHTML:{__html:r},style:{padding:"var(--gap-sm)",fontSize:"var(--font-size-sm)",lineHeight:"1.6"}}):n?e("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):e(i,{variant:"muted",children:"\u2014"});default:return String(r)}}function x({name:r,config:c,value:l,t:m}){const n=b(l,c,m,{compact:!1}),p=y(r,c,m);return o(d,{direction:"row",align:"baseline",style:{marginBottom:"var(--gap-sm)",padding:"var(--gap-sm)",minHeight:"38px",alignItems:"center"},children:[o(i,{variant:"muted",style:{fontSize:"var(--font-size-sm)",fontWeight:500,minWidth:"fit-content",flexShrink:0},children:[p,":"]}),e("div",{style:{flex:1,display:"flex",alignItems:"center"},children:typeof n=="string"?e(i,{children:n}):n})]})}var w=x;export{x as DisplayFieldRenderer,w as default,b as formatValue};
1
+ "use client";import{jsx as r,jsxs as s}from"react/jsx-runtime";import{Text as a,Stack as c}from"@donotdev/components";import{handleError as d}from"@donotdev/core";import{translateFieldLabel as u}from"../forms/utils";import{getDisplayFormatter as y}from"../fieldTypeRegistry";function m(t,e,o,n){const i=n?.compact??!1;if(t==null||t==="")return i?r("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):r(a,{variant:"muted",children:"\u2014"});const l=y(e.type);if(l)try{return l(t,e,o,n)}catch(f){return d(f,{userMessage:`Error formatting field "${e.label||e.name}"`,context:{fieldType:e.type,fieldName:e.label||"unknown",operation:"display_format"},severity:"warning"}),i?r("span",{style:{color:"var(--muted-foreground)"},children:String(t)}):r(a,{variant:"muted",children:String(t)})}return d(new Error(`Display formatter not registered for field type: ${e.type}`),{userMessage:`Field type "${e.type}" is missing display formatter`,context:{fieldType:e.type,fieldName:e.label||"unknown",operation:"display_format",fix:"Add displayFormatter to registerBuiltinFieldType() in registerBuiltinFieldTypes.tsx"},severity:"warning"}),i?r("span",{style:{color:"var(--muted-foreground)"},children:String(t)}):r(a,{variant:"muted",children:String(t)})}function p({name:t,config:e,value:o,t:n}){const i=m(o,e,n,{compact:!1}),l=u(t,e,n);return s(c,{direction:"row",align:"baseline",style:{marginBottom:"var(--gap-sm)",padding:"var(--gap-sm)",minHeight:"38px",alignItems:"center"},children:[s(a,{variant:"muted",style:{fontSize:"var(--font-size-sm)",fontWeight:500,minWidth:"fit-content",flexShrink:0},children:[l,":"]}),r("div",{style:{flex:1,display:"flex",alignItems:"center"},children:typeof i=="string"?r(a,{children:i}):i})]})}var g=p;export{p as DisplayFieldRenderer,g as default,m as formatValue};