drf-react-by-schema 0.28.8 → 0.28.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 (232) hide show
  1. package/dist/@types/index.d.ts +410 -0
  2. package/dist/@types/index.d.ts.map +1 -0
  3. package/dist/@types/index.js +9 -0
  4. package/dist/@types/string-mask.d.ts +10 -0
  5. package/dist/@types/string-mask.d.ts.map +1 -0
  6. package/dist/@types/string-mask.js +1 -0
  7. package/dist/api.d.ts +81 -0
  8. package/dist/api.d.ts.map +1 -0
  9. package/dist/api.js +1118 -0
  10. package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts +8 -0
  11. package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts.map +1 -0
  12. package/dist/components/DataGridBySchemaEditable/BooleanInputCell.js +86 -0
  13. package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.d.ts +12 -0
  14. package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.d.ts.map +1 -0
  15. package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.js +71 -0
  16. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts +9 -0
  17. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts.map +1 -0
  18. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.js +21 -0
  19. package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +26 -0
  20. package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts.map +1 -0
  21. package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +146 -0
  22. package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts +73 -0
  23. package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -0
  24. package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +421 -0
  25. package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts +18 -0
  26. package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts.map +1 -0
  27. package/dist/components/DataGridBySchemaEditable/DataGridMobile.js +105 -0
  28. package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts +11 -0
  29. package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts.map +1 -0
  30. package/dist/components/DataGridBySchemaEditable/FileInputCell.js +155 -0
  31. package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +12 -0
  32. package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts.map +1 -0
  33. package/dist/components/DataGridBySchemaEditable/FooterToolbar.js +36 -0
  34. package/dist/components/DataGridBySchemaEditable/GeoEditCell.d.ts +10 -0
  35. package/dist/components/DataGridBySchemaEditable/GeoEditCell.d.ts.map +1 -0
  36. package/dist/components/DataGridBySchemaEditable/GeoEditCell.js +85 -0
  37. package/dist/components/DataGridBySchemaEditable/GeoThumbCell.d.ts +11 -0
  38. package/dist/components/DataGridBySchemaEditable/GeoThumbCell.d.ts.map +1 -0
  39. package/dist/components/DataGridBySchemaEditable/GeoThumbCell.js +90 -0
  40. package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.d.ts +18 -0
  41. package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.d.ts.map +1 -0
  42. package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.js +24 -0
  43. package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts +8 -0
  44. package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts.map +1 -0
  45. package/dist/components/DataGridBySchemaEditable/GridDateInput.js +166 -0
  46. package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.d.ts +6 -0
  47. package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.d.ts.map +1 -0
  48. package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.js +154 -0
  49. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +10 -0
  50. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts.map +1 -0
  51. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.js +78 -0
  52. package/dist/components/DataGridBySchemaEditable/GridGenericInput.d.ts +8 -0
  53. package/dist/components/DataGridBySchemaEditable/GridGenericInput.d.ts.map +1 -0
  54. package/dist/components/DataGridBySchemaEditable/GridGenericInput.js +30 -0
  55. package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +7 -0
  56. package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts.map +1 -0
  57. package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +74 -0
  58. package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +21 -0
  59. package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts.map +1 -0
  60. package/dist/components/DataGridBySchemaEditable/InputInterval.js +131 -0
  61. package/dist/components/DataGridBySchemaEditable/MobileSearchBar.d.ts +9 -0
  62. package/dist/components/DataGridBySchemaEditable/MobileSearchBar.d.ts.map +1 -0
  63. package/dist/components/DataGridBySchemaEditable/MobileSearchBar.js +70 -0
  64. package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.d.ts +7 -0
  65. package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.d.ts.map +1 -0
  66. package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.js +41 -0
  67. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +24 -0
  68. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts.map +1 -0
  69. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +263 -0
  70. package/dist/components/DataGridBySchemaEditable/geoConstants.d.ts +5 -0
  71. package/dist/components/DataGridBySchemaEditable/geoConstants.d.ts.map +1 -0
  72. package/dist/components/DataGridBySchemaEditable/geoConstants.js +6 -0
  73. package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts +33 -0
  74. package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts.map +1 -0
  75. package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.js +161 -0
  76. package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts +14 -0
  77. package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts.map +1 -0
  78. package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.js +69 -0
  79. package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts +9 -0
  80. package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts.map +1 -0
  81. package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.js +73 -0
  82. package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts +30 -0
  83. package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts.map +1 -0
  84. package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.js +199 -0
  85. package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts +33 -0
  86. package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts.map +1 -0
  87. package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +270 -0
  88. package/dist/components/DataGridBySchemaEditable/utils.d.ts +40 -0
  89. package/dist/components/DataGridBySchemaEditable/utils.d.ts.map +1 -0
  90. package/dist/components/DataGridBySchemaEditable/utils.js +181 -0
  91. package/dist/components/DataGridBySchemaEditable.d.ts +64 -0
  92. package/dist/components/DataGridBySchemaEditable.d.ts.map +1 -0
  93. package/dist/components/DataGridBySchemaEditable.js +172 -0
  94. package/dist/components/DataTotals.d.ts +12 -0
  95. package/dist/components/DataTotals.d.ts.map +1 -0
  96. package/dist/components/DataTotals.js +32 -0
  97. package/dist/components/DataTotalsServer.d.ts +10 -0
  98. package/dist/components/DataTotalsServer.d.ts.map +1 -0
  99. package/dist/components/DataTotalsServer.js +18 -0
  100. package/dist/components/DialogActions.d.ts +11 -0
  101. package/dist/components/DialogActions.d.ts.map +1 -0
  102. package/dist/components/DialogActions.js +20 -0
  103. package/dist/components/FileTypeIcon.d.ts +18 -0
  104. package/dist/components/FileTypeIcon.d.ts.map +1 -0
  105. package/dist/components/FileTypeIcon.js +48 -0
  106. package/dist/components/GenericModelList.d.ts +53 -0
  107. package/dist/components/GenericModelList.d.ts.map +1 -0
  108. package/dist/components/GenericModelList.js +194 -0
  109. package/dist/components/GenericRelatedModelList.d.ts +55 -0
  110. package/dist/components/GenericRelatedModelList.d.ts.map +1 -0
  111. package/dist/components/GenericRelatedModelList.js +181 -0
  112. package/dist/components/GenericRelatedModelListTable.d.ts +56 -0
  113. package/dist/components/GenericRelatedModelListTable.d.ts.map +1 -0
  114. package/dist/components/GenericRelatedModelListTable.js +31 -0
  115. package/dist/components/Image.d.ts +10 -0
  116. package/dist/components/Image.d.ts.map +1 -0
  117. package/dist/components/Image.js +111 -0
  118. package/dist/components/details/DetailBySchema.d.ts +4 -0
  119. package/dist/components/details/DetailBySchema.d.ts.map +1 -0
  120. package/dist/components/details/DetailBySchema.js +175 -0
  121. package/dist/components/details/DetailFieldBySchema.d.ts +4 -0
  122. package/dist/components/details/DetailFieldBySchema.d.ts.map +1 -0
  123. package/dist/components/details/DetailFieldBySchema.js +88 -0
  124. package/dist/components/forms/ChangePasswordForm.d.ts +7 -0
  125. package/dist/components/forms/ChangePasswordForm.d.ts.map +1 -0
  126. package/dist/components/forms/ChangePasswordForm.js +93 -0
  127. package/dist/components/forms/DialogFormBySchema.d.ts +22 -0
  128. package/dist/components/forms/DialogFormBySchema.d.ts.map +1 -0
  129. package/dist/components/forms/DialogFormBySchema.js +97 -0
  130. package/dist/components/forms/FieldBySchema.d.ts +4 -0
  131. package/dist/components/forms/FieldBySchema.d.ts.map +1 -0
  132. package/dist/components/forms/FieldBySchema.js +80 -0
  133. package/dist/components/forms/ForgotPasswordForm.d.ts +11 -0
  134. package/dist/components/forms/ForgotPasswordForm.d.ts.map +1 -0
  135. package/dist/components/forms/ForgotPasswordForm.js +114 -0
  136. package/dist/components/forms/Form.d.ts +61 -0
  137. package/dist/components/forms/Form.d.ts.map +1 -0
  138. package/dist/components/forms/Form.js +264 -0
  139. package/dist/components/forms/FormActions.d.ts +20 -0
  140. package/dist/components/forms/FormActions.d.ts.map +1 -0
  141. package/dist/components/forms/FormActions.js +55 -0
  142. package/dist/components/forms/FormBySchema.d.ts +21 -0
  143. package/dist/components/forms/FormBySchema.d.ts.map +1 -0
  144. package/dist/components/forms/FormBySchema.js +280 -0
  145. package/dist/components/forms/FormWatcher.d.ts +10 -0
  146. package/dist/components/forms/FormWatcher.d.ts.map +1 -0
  147. package/dist/components/forms/FormWatcher.js +25 -0
  148. package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +13 -0
  149. package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts.map +1 -0
  150. package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +133 -0
  151. package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +4 -0
  152. package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts.map +1 -0
  153. package/dist/components/forms/inputs/BooleanFieldBySchema.js +39 -0
  154. package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +5 -0
  155. package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts.map +1 -0
  156. package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +54 -0
  157. package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +5 -0
  158. package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts.map +1 -0
  159. package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +47 -0
  160. package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +14 -0
  161. package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts.map +1 -0
  162. package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +272 -0
  163. package/dist/components/forms/inputs/FileFieldBySchema.d.ts +4 -0
  164. package/dist/components/forms/inputs/FileFieldBySchema.d.ts.map +1 -0
  165. package/dist/components/forms/inputs/FileFieldBySchema.js +144 -0
  166. package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +4 -0
  167. package/dist/components/forms/inputs/FloatFieldBySchema.d.ts.map +1 -0
  168. package/dist/components/forms/inputs/FloatFieldBySchema.js +64 -0
  169. package/dist/components/forms/inputs/GeometryFieldBySchema.d.ts +8 -0
  170. package/dist/components/forms/inputs/GeometryFieldBySchema.d.ts.map +1 -0
  171. package/dist/components/forms/inputs/GeometryFieldBySchema.js +61 -0
  172. package/dist/components/forms/inputs/MapGeometryPicker.d.ts +19 -0
  173. package/dist/components/forms/inputs/MapGeometryPicker.d.ts.map +1 -0
  174. package/dist/components/forms/inputs/MapGeometryPicker.js +347 -0
  175. package/dist/components/forms/inputs/PatternFieldBySchema.d.ts +4 -0
  176. package/dist/components/forms/inputs/PatternFieldBySchema.d.ts.map +1 -0
  177. package/dist/components/forms/inputs/PatternFieldBySchema.js +56 -0
  178. package/dist/components/forms/inputs/TextFieldBySchema.d.ts +4 -0
  179. package/dist/components/forms/inputs/TextFieldBySchema.d.ts.map +1 -0
  180. package/dist/components/forms/inputs/TextFieldBySchema.js +56 -0
  181. package/dist/components/forms/inputs/leafletMarker.d.ts +37 -0
  182. package/dist/components/forms/inputs/leafletMarker.d.ts.map +1 -0
  183. package/dist/components/forms/inputs/leafletMarker.js +72 -0
  184. package/dist/context/APIWrapper.d.ts +18 -0
  185. package/dist/context/APIWrapper.d.ts.map +1 -0
  186. package/dist/context/APIWrapper.js +593 -0
  187. package/dist/context/APIWrapperContext.d.ts +132 -0
  188. package/dist/context/APIWrapperContext.d.ts.map +1 -0
  189. package/dist/context/APIWrapperContext.js +63 -0
  190. package/dist/context/DRFReactBySchemaContext.d.ts +31 -0
  191. package/dist/context/DRFReactBySchemaContext.d.ts.map +1 -0
  192. package/dist/context/DRFReactBySchemaContext.js +20 -0
  193. package/dist/context/DRFReactBySchemaProvider.d.ts +5 -0
  194. package/dist/context/DRFReactBySchemaProvider.d.ts.map +1 -0
  195. package/dist/context/DRFReactBySchemaProvider.js +105 -0
  196. package/dist/context/Overlays.d.ts +5 -0
  197. package/dist/context/Overlays.d.ts.map +1 -0
  198. package/dist/context/Overlays.js +114 -0
  199. package/dist/context/PrivateContext.d.ts +10 -0
  200. package/dist/context/PrivateContext.d.ts.map +1 -0
  201. package/dist/context/PrivateContext.js +16 -0
  202. package/dist/hooks/useDeepMemo.d.ts +2 -0
  203. package/dist/hooks/useDeepMemo.d.ts.map +1 -0
  204. package/dist/hooks/useDeepMemo.js +13 -0
  205. package/dist/hooks/useWhyDidYouUpdate.d.ts +4 -0
  206. package/dist/hooks/useWhyDidYouUpdate.d.ts.map +1 -0
  207. package/dist/hooks/useWhyDidYouUpdate.js +26 -0
  208. package/dist/index.d.ts +37 -0
  209. package/dist/index.d.ts.map +1 -0
  210. package/dist/index.js +110 -0
  211. package/dist/styles/grid.d.ts +3 -0
  212. package/dist/styles/grid.d.ts.map +1 -0
  213. package/dist/styles/grid.js +38 -0
  214. package/dist/styles/index.d.ts +3 -0
  215. package/dist/styles/index.d.ts.map +1 -0
  216. package/dist/styles/index.js +38 -0
  217. package/dist/styles/layout.d.ts +23 -0
  218. package/dist/styles/layout.d.ts.map +1 -0
  219. package/dist/styles/layout.js +71 -0
  220. package/dist/styles/texts.d.ts +66 -0
  221. package/dist/styles/texts.d.ts.map +1 -0
  222. package/dist/styles/texts.js +73 -0
  223. package/dist/styles/theme.d.ts +29 -0
  224. package/dist/styles/theme.d.ts.map +1 -0
  225. package/dist/styles/theme.js +226 -0
  226. package/dist/utils/index.d.ts +2 -0
  227. package/dist/utils/index.d.ts.map +1 -0
  228. package/dist/utils/index.js +17 -0
  229. package/dist/utils/utils.d.ts +107 -0
  230. package/dist/utils/utils.d.ts.map +1 -0
  231. package/dist/utils/utils.js +957 -0
  232. package/package.json +1 -1
@@ -0,0 +1,957 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.convertToFormData = exports.slugify = exports.slugToCamelCase = exports.getPatternFormat = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.toChoiceItem = exports.getChoiceByValue = exports.emptyByType = void 0;
49
+ exports.enrichChoices = enrichChoices;
50
+ exports.populateValues = populateValues;
51
+ exports.buildGenericYupValidationSchema = buildGenericYupValidationSchema;
52
+ exports.loadSinglePageDataHelper = loadSinglePageDataHelper;
53
+ exports.getFieldErrorsFromResponse = getFieldErrorsFromResponse;
54
+ exports.reducer = reducer;
55
+ exports.buildDateFormatBySchema = buildDateFormatBySchema;
56
+ exports.mergeFilterItems = mergeFilterItems;
57
+ exports.initViewColumns = initViewColumns;
58
+ exports.deepEqual = deepEqual;
59
+ exports.shouldMemoUpdate = shouldMemoUpdate;
60
+ exports.formatFileSize = formatFileSize;
61
+ exports.getFieldsFromFieldsLayout = getFieldsFromFieldsLayout;
62
+ exports.isFieldRequired = isFieldRequired;
63
+ exports.extractFieldValue = extractFieldValue;
64
+ exports.buildConditionalVisibleBySchema = buildConditionalVisibleBySchema;
65
+ exports.showConditionalVisibleField = showConditionalVisibleField;
66
+ exports.showConditionalVisibleFieldObj = showConditionalVisibleFieldObj;
67
+ exports.getMapLibraries = getMapLibraries;
68
+ exports.geometryValueToString = geometryValueToString;
69
+ exports.parseGeoJSON = parseGeoJSON;
70
+ const dayjs_1 = __importDefault(require("dayjs"));
71
+ const Yup = __importStar(require("yup"));
72
+ const string_mask_1 = __importDefault(require("string-mask"));
73
+ const emptyByType = (field, forDatabase = false) => {
74
+ if (field.model_default) {
75
+ return field.model_default;
76
+ }
77
+ switch (field.type) {
78
+ case 'nested object':
79
+ // emptyByType must be an empty object for the database, but must be null for the mui-autocomplete component. So I had to make this ugly hack here, when we're preparing to sendo to the database:
80
+ return forDatabase ? {} : null;
81
+ case 'field':
82
+ if (field.child) {
83
+ return [];
84
+ }
85
+ return forDatabase ? undefined : null;
86
+ case 'list':
87
+ case 'multiple choice':
88
+ return [];
89
+ case 'string':
90
+ case 'email':
91
+ return '';
92
+ case 'integer':
93
+ return 0;
94
+ case 'array':
95
+ return [];
96
+ case 'boolean':
97
+ return false;
98
+ default:
99
+ return null;
100
+ }
101
+ };
102
+ exports.emptyByType = emptyByType;
103
+ const getChoiceByValue = (value, choices) => {
104
+ if (!choices) {
105
+ return null;
106
+ }
107
+ for (const choice of choices) {
108
+ if (choice.value === value) {
109
+ return choice.display_name;
110
+ }
111
+ }
112
+ };
113
+ exports.getChoiceByValue = getChoiceByValue;
114
+ // Shapes a raw choice value into a {value, display_name} object; objects that are
115
+ // already enriched pass through unchanged.
116
+ const toChoiceItem = (rawValue, choices) => typeof rawValue === 'object' && rawValue !== null
117
+ ? rawValue
118
+ : {
119
+ value: rawValue,
120
+ display_name: (0, exports.getChoiceByValue)(rawValue, choices),
121
+ };
122
+ exports.toChoiceItem = toChoiceItem;
123
+ // Backends return choice fields as raw values. Reshape a single 'choice' into a
124
+ // {value, display_name} object and a 'list'/'multiple choice' into an array of
125
+ // them, so forms and grid rows are consistent. list options live under
126
+ // field.child?.choices (FieldBySchema reads the same source).
127
+ function enrichChoices(rawData, schema) {
128
+ const out = Object.assign({}, rawData);
129
+ for (const [key, field] of Object.entries(schema)) {
130
+ if (!(key in rawData)) {
131
+ continue;
132
+ }
133
+ if ((field === null || field === void 0 ? void 0 : field.type) === 'choice') {
134
+ const rawValue = rawData[key];
135
+ out[key] = rawValue ? (0, exports.toChoiceItem)(rawValue, field.choices) : (0, exports.emptyByType)(field);
136
+ }
137
+ else if ((field === null || field === void 0 ? void 0 : field.type) === 'list' || (field === null || field === void 0 ? void 0 : field.type) === 'multiple choice') {
138
+ const rawValue = rawData[key];
139
+ if (Array.isArray(rawValue)) {
140
+ out[key] = rawValue.map((entry) => { var _a; return (0, exports.toChoiceItem)(entry, (_a = field.child) === null || _a === void 0 ? void 0 : _a.choices); });
141
+ }
142
+ }
143
+ }
144
+ return out;
145
+ }
146
+ function populateValues({ data, schema }) {
147
+ var _a;
148
+ const values = {};
149
+ for (const [key, field] of Object.entries(schema)) {
150
+ if (key === 'id' && (0, exports.isTmpId)(data[key])) {
151
+ continue;
152
+ }
153
+ if (!data[key] && data[key] !== false && data[key] !== 0) {
154
+ values[key] = (0, exports.emptyByType)(field);
155
+ continue;
156
+ }
157
+ if (field.type === 'field' && ((_a = field.child) === null || _a === void 0 ? void 0 : _a.children)) {
158
+ if (Array.isArray(data[key])) {
159
+ const arValues = [];
160
+ for (const row of data[key]) {
161
+ const value = populateValues({
162
+ data: row,
163
+ schema: field.child.children,
164
+ });
165
+ arValues.push(value);
166
+ }
167
+ values[key] = arValues;
168
+ continue;
169
+ }
170
+ values[key] = populateValues({
171
+ data: data[key],
172
+ schema: field.child.children,
173
+ });
174
+ continue;
175
+ }
176
+ if (field.type === 'choice') {
177
+ values[key] = data[key] ? (0, exports.toChoiceItem)(data[key], field.choices) : (0, exports.emptyByType)(field);
178
+ continue;
179
+ }
180
+ if (field.type === 'list' || field.type === 'multiple choice') {
181
+ values[key] = Array.isArray(data[key])
182
+ ? data[key].map((entry) => { var _a; return (0, exports.toChoiceItem)(entry, (_a = field.child) === null || _a === void 0 ? void 0 : _a.choices); })
183
+ : (0, exports.emptyByType)(field);
184
+ continue;
185
+ }
186
+ values[key] = data[key];
187
+ }
188
+ return values;
189
+ }
190
+ const getYupValidator = (type) => {
191
+ let yupFunc;
192
+ try {
193
+ switch (type) {
194
+ case 'slug':
195
+ yupFunc = Yup.string();
196
+ break;
197
+ case 'email':
198
+ yupFunc = Yup.string().email('Este campo deve ser um e-mail válido.');
199
+ break;
200
+ case 'integer':
201
+ yupFunc = Yup.number().integer('Este campo deve ser um número inteiro');
202
+ break;
203
+ case 'choice':
204
+ yupFunc = Yup.object();
205
+ break;
206
+ case 'list':
207
+ yupFunc = Yup.array();
208
+ break;
209
+ case 'field':
210
+ yupFunc = Yup.mixed();
211
+ break;
212
+ case 'nested object':
213
+ yupFunc = Yup.object();
214
+ break;
215
+ case 'date':
216
+ yupFunc = Yup.date();
217
+ break;
218
+ case 'string':
219
+ yupFunc = Yup.string();
220
+ break;
221
+ case 'number':
222
+ case 'float':
223
+ yupFunc = Yup.number();
224
+ break;
225
+ case 'decimal':
226
+ yupFunc = Yup.string();
227
+ break;
228
+ case 'boolean':
229
+ yupFunc = Yup.bool();
230
+ break;
231
+ case 'array':
232
+ case 'multiple choice':
233
+ yupFunc = Yup.array();
234
+ break;
235
+ case 'object':
236
+ case 'image':
237
+ case 'image upload':
238
+ case 'file':
239
+ case 'file upload':
240
+ yupFunc = Yup.object();
241
+ break;
242
+ // PostGIS geometry fields arrive as GeoJSON objects (e.g.
243
+ // { type: 'Point', coordinates: [...] }), so they must validate as
244
+ // objects rather than falling through to the default string schema.
245
+ case 'point':
246
+ case 'polygon':
247
+ case 'multipoint':
248
+ case 'multipolygon':
249
+ case 'geometrycollection':
250
+ yupFunc = Yup.object();
251
+ break;
252
+ // String-like types produced by SimpleMetadata but not needing
253
+ // specialized validation behave as plain strings:
254
+ case 'url':
255
+ case 'regex':
256
+ case 'time':
257
+ case 'duration':
258
+ case 'password':
259
+ yupFunc = Yup.string();
260
+ break;
261
+ default:
262
+ yupFunc = Yup.string();
263
+ break;
264
+ }
265
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
266
+ }
267
+ catch (e) {
268
+ yupFunc = Yup.string();
269
+ }
270
+ return yupFunc.transform((v) => (v === '' ? null : v)).nullable();
271
+ };
272
+ function buildGenericYupValidationSchema({ data, schema, many = false, skipFields = [], extraValidators, uiFields, }) {
273
+ var _a, _b;
274
+ const yupValidator = {};
275
+ for (const entry of Object.entries(schema)) {
276
+ const [field, fieldSchema] = entry;
277
+ if (!data || !(field in data) || field === 'id' || skipFields.includes(field)) {
278
+ continue;
279
+ }
280
+ // OneToMany or ManyToMany (built as an array-of-object schema):
281
+ if (fieldSchema.type === 'field' && ((_a = fieldSchema.child) === null || _a === void 0 ? void 0 : _a.children)) {
282
+ yupValidator[field] =
283
+ extraValidators && field in extraValidators
284
+ ? extraValidators[field]
285
+ : buildGenericYupValidationSchema({
286
+ schema: fieldSchema.child.children,
287
+ many: true,
288
+ data: data[field],
289
+ uiFields,
290
+ });
291
+ }
292
+ else {
293
+ yupValidator[field] =
294
+ extraValidators && field in extraValidators
295
+ ? extraValidators[field]
296
+ : getYupValidator(fieldSchema.type);
297
+ }
298
+ if (isFieldRequired(fieldSchema, (uiFields || []).includes(field))) {
299
+ yupValidator[field] = yupValidator[field].required('Este campo é obrigatório');
300
+ // For required many-fields the selected items live in an array, and yup's
301
+ // `.required()` still allows `[]`; enforce at least one selection instead.
302
+ if (fieldSchema.type === 'field' && ((_b = fieldSchema.child) === null || _b === void 0 ? void 0 : _b.children)) {
303
+ yupValidator[field] = // eslint-disable-next-line @typescript-eslint/no-explicit-any
304
+ yupValidator[field].min(1, 'Este campo é obrigatório');
305
+ }
306
+ }
307
+ if (fieldSchema.max_length && fieldSchema.type === 'string') {
308
+ yupValidator[field] = yupValidator[field].max(parseInt(fieldSchema.max_length), `Este campo só pode ter no máximo ${fieldSchema.max_length} caracteres`);
309
+ }
310
+ if (fieldSchema.max_digits && fieldSchema.type === 'decimal') {
311
+ const maxDigits = fieldSchema.max_digits;
312
+ yupValidator[field] = yupValidator[field].test('max-digits', `Este número pode ter no máximo ${maxDigits} dígitos`, (val) => {
313
+ if (!val) {
314
+ return true;
315
+ }
316
+ const digitCount = val.replace(/[^0-9]/g, '').length;
317
+ return digitCount <= maxDigits;
318
+ });
319
+ }
320
+ if (!fieldSchema.read_only && fieldSchema.validators_regex) {
321
+ for (const validator of fieldSchema.validators_regex) {
322
+ yupValidator[field] = yupValidator[field].matches(validator.regex, validator.message);
323
+ }
324
+ }
325
+ }
326
+ return many ? Yup.array().of(Yup.object().shape(yupValidator)) : Yup.object().shape(yupValidator);
327
+ }
328
+ function loadSinglePageDataHelper({ data, schema, columns, fieldsLayout, defaults, extraValidators, }) {
329
+ const mergedData = Object.assign({}, data);
330
+ if (defaults) {
331
+ for (const [field, value] of Object.entries(defaults)) {
332
+ if (!data[field] && typeof data[field] !== 'boolean') {
333
+ mergedData[field] = value;
334
+ }
335
+ }
336
+ }
337
+ const values = populateValues({ data: mergedData, schema });
338
+ const uiFields = fieldsLayout
339
+ ? getFieldsFromFieldsLayout(fieldsLayout)
340
+ : columns
341
+ ? Object.keys(columns)
342
+ : undefined;
343
+ const validationSchema = buildGenericYupValidationSchema({
344
+ data: values,
345
+ schema,
346
+ extraValidators,
347
+ uiFields,
348
+ });
349
+ const customFieldLabelsAr = fieldsLayout === null || fieldsLayout === void 0 ? void 0 : fieldsLayout.map((fieldLayout) => fieldLayout.customLabels);
350
+ const finalSchema = Object.assign({}, schema);
351
+ if (customFieldLabelsAr) {
352
+ for (const customFieldLabels of customFieldLabelsAr) {
353
+ if (!customFieldLabels) {
354
+ continue;
355
+ }
356
+ for (const key of Object.keys(customFieldLabels)) {
357
+ if (customFieldLabels[key] && (!uiFields || uiFields.includes(key))) {
358
+ finalSchema[key].label = customFieldLabels[key];
359
+ }
360
+ }
361
+ }
362
+ }
363
+ return { values, finalSchema, validationSchema };
364
+ }
365
+ const errorProps = ({ errors, fieldKey, fieldKeyProp, index, }) => {
366
+ let error;
367
+ let helperText;
368
+ if (index) {
369
+ const hasErrors = errors &&
370
+ errors[fieldKey] &&
371
+ errors[fieldKey][index] &&
372
+ Boolean(errors[fieldKey][index][fieldKeyProp]);
373
+ error = hasErrors;
374
+ helperText = hasErrors ? errors[fieldKey][index][fieldKeyProp].message : null;
375
+ return { error, helperText };
376
+ }
377
+ const hasErrors = errors && errors[fieldKey] && Boolean(errors[fieldKey][fieldKeyProp]);
378
+ error = hasErrors;
379
+ helperText = hasErrors ? errors[fieldKey][fieldKeyProp].message : null;
380
+ return { error, helperText };
381
+ };
382
+ exports.errorProps = errorProps;
383
+ /**
384
+ * Normalizes a DRF (Django REST Framework) validation error payload into a
385
+ * react-hook-form `setError`-compatible map: `{ fieldKey: { type, message } }`.
386
+ *
387
+ * DRF returns per-field errors both as `{ field: "message" }` and
388
+ * `{ field: ["message 1", "message 2"] }`, plus `{ non_field_errors: [...] }`.
389
+ * Only fields present in the given `schema` are mapped, so backend-only keys
390
+ * (or `non_field_errors`) are skipped and remain surfaced through the generic
391
+ * error message instead. This is what allows a `validate()` raised
392
+ * `ValidationError({"field": "..."})` to be rendered under the offending field,
393
+ * exactly like a yup validation error.
394
+ */
395
+ function getFieldErrorsFromResponse(response, schema) {
396
+ const result = {};
397
+ if (!response || typeof response !== 'object' || Array.isArray(response)) {
398
+ return result;
399
+ }
400
+ for (const [key, value] of Object.entries(response)) {
401
+ if (key === 'non_field_errors') {
402
+ continue;
403
+ }
404
+ if (schema && !(key in schema)) {
405
+ continue;
406
+ }
407
+ const message = Array.isArray(value) ? value[0] : value;
408
+ if (typeof message === 'string' && message.length > 0) {
409
+ result[key] = { type: 'server', message };
410
+ }
411
+ }
412
+ return result;
413
+ }
414
+ const getTmpId = () => {
415
+ return 'tmp' + Math.floor(Math.random() * 1000000);
416
+ };
417
+ exports.getTmpId = getTmpId;
418
+ const isTmpId = (id) => {
419
+ if (!id) {
420
+ return true;
421
+ }
422
+ return id === 'novo' || id.toString().slice(0, 3) === 'tmp';
423
+ };
424
+ exports.isTmpId = isTmpId;
425
+ function reducer(state, newState) {
426
+ if (newState === null) {
427
+ return null;
428
+ }
429
+ if (state === null) {
430
+ return newState;
431
+ }
432
+ return Object.assign(Object.assign({}, state), newState);
433
+ }
434
+ const getPatternFormat = (type) => {
435
+ let format = '';
436
+ switch (type) {
437
+ case 'telefone':
438
+ case 'fone':
439
+ case 'phone':
440
+ case 'contact':
441
+ case 'contato':
442
+ format = '(##)#####-####';
443
+ break;
444
+ case 'cpf':
445
+ format = '###.###.###-##';
446
+ break;
447
+ case 'cnpj':
448
+ format = '##.###.###/####-##';
449
+ break;
450
+ case 'cep':
451
+ format = '##.###-###';
452
+ break;
453
+ }
454
+ return format;
455
+ };
456
+ exports.getPatternFormat = getPatternFormat;
457
+ function buildDateFormatBySchema(dateViews) {
458
+ const defaultFormat = 'DD/MM/YYYY';
459
+ if (!dateViews) {
460
+ return defaultFormat;
461
+ }
462
+ const hasDay = dateViews.includes('day');
463
+ const hasMonth = dateViews.includes('month');
464
+ const hasYear = dateViews.includes('year');
465
+ if (hasDay && hasMonth && hasYear) {
466
+ return defaultFormat;
467
+ }
468
+ if (!hasDay && hasMonth && hasYear) {
469
+ return 'MM/YYYY';
470
+ }
471
+ if (!hasDay && !hasMonth && hasYear) {
472
+ return 'YYYY';
473
+ }
474
+ if (!hasDay && hasMonth && !hasYear) {
475
+ return 'MM';
476
+ }
477
+ if (hasDay && !hasMonth && !hasYear) {
478
+ return 'DD';
479
+ }
480
+ return defaultFormat;
481
+ }
482
+ const slugToCamelCase = (str, includeFirst = false) => {
483
+ if (!str) {
484
+ return '';
485
+ }
486
+ const ret = str.replace(/_([a-z])/g, function (g) {
487
+ return g[1].toUpperCase();
488
+ });
489
+ if (includeFirst) {
490
+ return ret[0].toUpperCase() + ret.slice(1);
491
+ }
492
+ return ret;
493
+ };
494
+ exports.slugToCamelCase = slugToCamelCase;
495
+ const slugify = (text) => {
496
+ if (!text) {
497
+ return '';
498
+ }
499
+ return text
500
+ .toString()
501
+ .normalize('NFD')
502
+ .replace(/[\u0300-\u036f]/g, '')
503
+ .toLowerCase()
504
+ .trim()
505
+ .replace(/\s+/g, '-')
506
+ .replace(/[^\w-]+/g, '')
507
+ .replace(/--+/g, '-');
508
+ };
509
+ exports.slugify = slugify;
510
+ function mergeFilterItems(defaultFilter, filter) {
511
+ if (!filter && defaultFilter) {
512
+ return defaultFilter;
513
+ }
514
+ if (!defaultFilter && filter) {
515
+ return filter;
516
+ }
517
+ if (filter && defaultFilter) {
518
+ const items = filter.items;
519
+ const defaultItems = defaultFilter.items;
520
+ const mergedItems = defaultItems.map((defaultItem) => {
521
+ const itemFound = items.find((item) => item.field === defaultItem.field);
522
+ if (itemFound) {
523
+ return itemFound;
524
+ }
525
+ return defaultItem;
526
+ });
527
+ const unMergedItems = items.filter((item) => !defaultItems.map((defaultItem) => defaultItem.field).includes(item.field));
528
+ return Object.assign(Object.assign({}, filter), { items: [...mergedItems, ...unMergedItems] });
529
+ }
530
+ return undefined;
531
+ }
532
+ function initViewColumns(_a) {
533
+ return __awaiter(this, arguments, void 0, function* ({ schema, columns, customColumnOperations, }) {
534
+ const colsPromises = columns.map((column) => __awaiter(this, void 0, void 0, function* () {
535
+ const field = column.field;
536
+ if (!schema[field]) {
537
+ return column;
538
+ }
539
+ const fieldSchema = schema[field];
540
+ // const isIndexField = indexField !== '' && field === indexField;
541
+ // let column = col;
542
+ // if (isIndexField) {
543
+ // col.isIndexField = true;
544
+ // }
545
+ switch (fieldSchema.type) {
546
+ case 'date':
547
+ column.type = 'date';
548
+ const dateFormat = buildDateFormatBySchema(fieldSchema.date_views);
549
+ column.valueFormatter = (value) => (value ? (0, dayjs_1.default)(value).format(dateFormat) : '');
550
+ break;
551
+ case 'datetime':
552
+ column.type = 'dateTime';
553
+ column.valueFormatter = (value) => (value ? (0, dayjs_1.default)(value).format('DD/MM/YYYY HH:mm') : '');
554
+ break;
555
+ case 'nested object':
556
+ column.valueFormatter = (value) => {
557
+ return !value ? '' : value.label;
558
+ };
559
+ break;
560
+ case 'field':
561
+ column.valueFormatter = (value) => {
562
+ return !value || !Array.isArray(value) ? '' : value.map((val) => val.label).join(', ');
563
+ };
564
+ break;
565
+ case 'choice':
566
+ column.valueFormatter = (value) => {
567
+ return !value ? '' : value.display_name;
568
+ };
569
+ break;
570
+ case 'list':
571
+ column.valueFormatter = (value) => {
572
+ return !value || !Array.isArray(value)
573
+ ? ''
574
+ : value.map((val) => val.display_name).join(', ');
575
+ };
576
+ break;
577
+ case 'boolean':
578
+ column.valueFormatter = (value) => {
579
+ return value ? 'Sim' : 'Não';
580
+ };
581
+ break;
582
+ case 'decimal':
583
+ case 'float':
584
+ const decimalScale = fieldSchema.decimal_places || 2;
585
+ column.type = 'number';
586
+ column.valueFormatter = (value) => {
587
+ return !value
588
+ ? ''
589
+ : parseFloat(value).toLocaleString('pt-BR', {
590
+ minimumFractionDigits: decimalScale,
591
+ maximumFractionDigits: decimalScale,
592
+ });
593
+ };
594
+ break;
595
+ case 'number':
596
+ case 'integer':
597
+ column.type = 'number';
598
+ if (fieldSchema.pattern_format) {
599
+ column.patternFormat = fieldSchema.pattern_format;
600
+ }
601
+ break;
602
+ case 'file upload':
603
+ case 'image upload':
604
+ column.valueFormatter = (value) => {
605
+ return !value ? '' : `${value.name.split('/').pop()} (${formatFileSize(value.size)})`;
606
+ };
607
+ break;
608
+ case 'point':
609
+ case 'polygon':
610
+ case 'multipoint':
611
+ case 'multipolygon':
612
+ case 'geometrycollection':
613
+ // PostGIS geometry (GeoJSON object) is not a renderable React child;
614
+ // stringify it for read-only views (detail page / mobile list).
615
+ column.valueFormatter = (value) => !value ? '' : typeof value === 'string' ? value : JSON.stringify(value);
616
+ break;
617
+ default:
618
+ if (fieldSchema.pattern_format) {
619
+ column.patternFormat = fieldSchema.pattern_format;
620
+ }
621
+ }
622
+ // format numbers:
623
+ if (column.patternFormat) {
624
+ column.valueFormatter = (value) => {
625
+ if (!value || typeof value !== 'string') {
626
+ return value;
627
+ }
628
+ const formattedValue = new string_mask_1.default(column.patternFormat, {}).apply(value);
629
+ return formattedValue;
630
+ };
631
+ }
632
+ // Custom column operations:
633
+ if (customColumnOperations) {
634
+ column = yield customColumnOperations(column);
635
+ }
636
+ // Finally!
637
+ return column;
638
+ }));
639
+ const finalCols = yield Promise.all(colsPromises);
640
+ return finalCols;
641
+ });
642
+ }
643
+ function deepEqual(a, b, maxIterations = 10000) {
644
+ const stack = [[a, b, 0]];
645
+ let iterations = 0;
646
+ while (stack.length > 0) {
647
+ iterations++;
648
+ if (iterations > maxIterations)
649
+ return false;
650
+ const [currentA, currentB] = stack.pop();
651
+ // 1. Strict equality (handles same reference, same primitives)
652
+ if (currentA === currentB)
653
+ continue;
654
+ // 2. Handle Functions (toString comparison)
655
+ if (typeof currentA === 'function' && typeof currentB === 'function') {
656
+ if (currentA.toString() !== currentB.toString())
657
+ return false;
658
+ continue;
659
+ }
660
+ // 3. Handle Dates (Object.keys doesn't work on Dates)
661
+ if (currentA instanceof Date && currentB instanceof Date) {
662
+ if (currentA.getTime() !== currentB.getTime())
663
+ return false;
664
+ continue;
665
+ }
666
+ // 4. Handle Null/Undefined/Primitives that failed the === check
667
+ if (currentA === null ||
668
+ currentB === null ||
669
+ typeof currentA !== 'object' ||
670
+ typeof currentB !== 'object') {
671
+ return false;
672
+ }
673
+ // 5. Handle Arrays
674
+ if (Array.isArray(currentA) && Array.isArray(currentB)) {
675
+ if (currentA.length !== currentB.length)
676
+ return false;
677
+ for (let i = currentA.length - 1; i >= 0; i--) {
678
+ stack.push([currentA[i], currentB[i], 0]);
679
+ }
680
+ continue;
681
+ }
682
+ // 6. Handle Objects
683
+ const keysA = Object.keys(currentA);
684
+ const keysB = Object.keys(currentB);
685
+ if (keysA.length !== keysB.length)
686
+ return false;
687
+ for (const key of keysA) {
688
+ if (!Object.prototype.hasOwnProperty.call(currentB, key))
689
+ return false;
690
+ stack.push([currentA[key], currentB[key], 0]);
691
+ }
692
+ }
693
+ return true;
694
+ }
695
+ function shouldMemoUpdate(prevProps, nextProps) {
696
+ const propKeys = new Set([...Object.keys(prevProps), ...Object.keys(nextProps)]);
697
+ for (const key of propKeys) {
698
+ if (typeof key === 'string' && key.startsWith('_'))
699
+ continue;
700
+ const prevVal = prevProps[key];
701
+ const nextVal = nextProps[key];
702
+ // Fast path for identical references
703
+ if (prevVal === nextVal)
704
+ continue;
705
+ // Handle null/undefined mismatches
706
+ if (prevVal == null || nextVal == null) {
707
+ return false;
708
+ }
709
+ // Special handling for functions
710
+ if (typeof prevVal === 'function' && typeof nextVal === 'function') {
711
+ if (prevVal.toString() !== nextVal.toString()) {
712
+ return false;
713
+ }
714
+ continue;
715
+ }
716
+ // Deep compare objects
717
+ if (typeof prevVal === 'object' && typeof nextVal === 'object') {
718
+ if (!deepEqual(prevVal, nextVal)) {
719
+ return false;
720
+ }
721
+ continue;
722
+ }
723
+ // Final comparison for primitives
724
+ if (prevVal !== nextVal) {
725
+ return false;
726
+ }
727
+ }
728
+ return true;
729
+ }
730
+ const convertToFormData = (data) => {
731
+ const formData = new FormData();
732
+ Object.entries(data).forEach(([key, value]) => {
733
+ if (value === null) {
734
+ formData.append(key, ''); // Handle null values
735
+ }
736
+ else if (Array.isArray(value)) {
737
+ value.forEach((item) => {
738
+ if (typeof item === 'object') {
739
+ formData.append(`${key}[]`, JSON.stringify(item));
740
+ }
741
+ });
742
+ }
743
+ else if (typeof value === 'object') {
744
+ formData.append(key, 'file' in value ? value.file : JSON.stringify(value));
745
+ }
746
+ else {
747
+ formData.append(key, value);
748
+ }
749
+ });
750
+ return formData;
751
+ };
752
+ exports.convertToFormData = convertToFormData;
753
+ function formatFileSize(bytes) {
754
+ if (bytes === 0)
755
+ return '0 B';
756
+ const units = ['B', 'KB', 'MB', 'GB'];
757
+ const k = 1024;
758
+ const dm = 1;
759
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
760
+ const value = bytes / Math.pow(k, i);
761
+ const formattedValue = value.toLocaleString('pt-BR', {
762
+ minimumFractionDigits: 0,
763
+ maximumFractionDigits: dm,
764
+ });
765
+ return `${formattedValue} ${units[i]}`;
766
+ }
767
+ function getFieldsFromFieldsLayout(fieldsLayout) {
768
+ const fields = [];
769
+ for (const section of fieldsLayout) {
770
+ if (!section.rows) {
771
+ continue;
772
+ }
773
+ for (const row of section.rows) {
774
+ if (typeof row === 'string') {
775
+ fields.push(row);
776
+ continue;
777
+ }
778
+ if (Array.isArray(row)) {
779
+ for (const field of row) {
780
+ if (typeof field === 'string') {
781
+ fields.push(field);
782
+ continue;
783
+ }
784
+ }
785
+ continue;
786
+ }
787
+ }
788
+ }
789
+ return fields;
790
+ }
791
+ function isFieldRequired(fieldSchema, isInForm) {
792
+ if (!fieldSchema || (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.type) === 'boolean') {
793
+ return false;
794
+ }
795
+ if (fieldSchema.required) {
796
+ return true;
797
+ }
798
+ if (fieldSchema.model_required) {
799
+ return true;
800
+ }
801
+ if (fieldSchema.ui_required && (typeof isInForm === 'undefined' || isInForm === true)) {
802
+ return true;
803
+ }
804
+ return false;
805
+ }
806
+ function extractFieldValue(genericValue) {
807
+ if (!genericValue) {
808
+ return null;
809
+ }
810
+ if (Array.isArray(genericValue)) {
811
+ return genericValue.map(({ value }) => (typeof value === 'object' ? value.value : value));
812
+ }
813
+ if (typeof genericValue === 'object') {
814
+ if ('id' in genericValue) {
815
+ return genericValue.id;
816
+ }
817
+ const value = genericValue.value;
818
+ if (typeof value === 'object') {
819
+ return value.value;
820
+ }
821
+ return value;
822
+ }
823
+ return genericValue;
824
+ }
825
+ function buildConditionalVisibleBySchema(schema) {
826
+ var _a;
827
+ const conditionalVisible = [];
828
+ if (!schema) {
829
+ return conditionalVisible;
830
+ }
831
+ for (const fieldKey of Object.keys(schema)) {
832
+ const thisConditionalVisible = (_a = schema[fieldKey]) === null || _a === void 0 ? void 0 : _a.conditional_visible;
833
+ if (!thisConditionalVisible || thisConditionalVisible.length === 0) {
834
+ continue;
835
+ }
836
+ if (typeof thisConditionalVisible[0] === 'string') {
837
+ conditionalVisible.push({
838
+ target: fieldKey,
839
+ source: thisConditionalVisible[0],
840
+ sourceValue: thisConditionalVisible[1],
841
+ });
842
+ continue;
843
+ }
844
+ for (const subConditionalVisible of thisConditionalVisible) {
845
+ if (typeof subConditionalVisible === 'string') {
846
+ continue;
847
+ }
848
+ conditionalVisible.push({
849
+ target: fieldKey,
850
+ source: subConditionalVisible[0],
851
+ sourceValue: subConditionalVisible[1],
852
+ });
853
+ }
854
+ }
855
+ return conditionalVisible;
856
+ }
857
+ function showConditionalVisibleField(field, conditionalVisible, values) {
858
+ if (typeof field !== 'string' ||
859
+ !conditionalVisible ||
860
+ conditionalVisible.filter((item) => item.target === field).length === 0 ||
861
+ !values) {
862
+ return true;
863
+ }
864
+ const sources = conditionalVisible
865
+ .map((item, index) => {
866
+ const refField = item.target;
867
+ const refValue = item.sourceValue;
868
+ const value = values[index];
869
+ return refField === field &&
870
+ (value === refValue ||
871
+ (value && value.value === refValue) ||
872
+ (Array.isArray(value) &&
873
+ value.find((singleValue) => singleValue === refValue ||
874
+ (typeof singleValue === 'object' && singleValue.value === refValue))))
875
+ ? item
876
+ : { target: false };
877
+ })
878
+ .filter((item) => item.target === field);
879
+ return sources.length > 0;
880
+ }
881
+ function showConditionalVisibleFieldObj(field, conditionalVisible, values) {
882
+ if (typeof field !== 'string' ||
883
+ !conditionalVisible ||
884
+ conditionalVisible.filter((item) => item.target === field).length === 0 ||
885
+ !values) {
886
+ return true;
887
+ }
888
+ const sources = conditionalVisible
889
+ .map((item) => {
890
+ const refField = item.target;
891
+ const refValue = item.sourceValue;
892
+ const value = extractFieldValue(values[item.source]);
893
+ return refField === field &&
894
+ (value === refValue || (Array.isArray(value) && value.includes(refValue)))
895
+ ? item
896
+ : { target: false };
897
+ })
898
+ .filter((item) => item.target === field);
899
+ return sources.length > 0;
900
+ }
901
+ // --- Optional OSM (leaflet) geometry support --------------------------------
902
+ // PostGIS geometry fields arrive from the backend as GeoJSON (type point /
903
+ // polygon / multipoint / multipolygon / geometrycollection). Editing them uses
904
+ // leaflet + leaflet-draw when those optional libraries are installed in the
905
+ // consuming app; otherwise the UI falls back to plain text editing.
906
+ /**
907
+ * Detect whether the consuming app has installed leaflet + leaflet-draw.
908
+ * Uses CJS require so that the bundler does not fail to build when they are
909
+ * absent; returns null so callers can fall back to text inputs.
910
+ */
911
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
912
+ function getMapLibraries() {
913
+ try {
914
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
915
+ const L = require('leaflet');
916
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
917
+ require('leaflet-draw');
918
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
919
+ require('react-leaflet');
920
+ if (L && L.map && L.Control && typeof L.Control.Draw === 'function') {
921
+ return L;
922
+ }
923
+ }
924
+ catch (_a) {
925
+ // leaflet / leaflet-draw / react-leaflet not installed -> no map support
926
+ }
927
+ return null;
928
+ }
929
+ /** Normalize a GeoJSON value (object, JSON string or null) to a string. */
930
+ function geometryValueToString(value) {
931
+ if (value === null || value === undefined)
932
+ return '';
933
+ if (typeof value === 'string')
934
+ return value;
935
+ try {
936
+ return JSON.stringify(value);
937
+ }
938
+ catch (_a) {
939
+ return '';
940
+ }
941
+ }
942
+ /** Parse a GeoJSON value (object or JSON string) into an object, or null. */
943
+ function parseGeoJSON(geoType, rawValue) {
944
+ const text = geometryValueToString(rawValue);
945
+ if (!text) {
946
+ return null;
947
+ }
948
+ try {
949
+ const parsed = JSON.parse(text);
950
+ return parsed && typeof parsed.type === 'string' && (0, exports.slugify)(parsed.type) === geoType
951
+ ? parsed
952
+ : null;
953
+ }
954
+ catch (_a) {
955
+ return null;
956
+ }
957
+ }