drf-react-by-schema 0.28.5 → 0.28.7

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 (227) hide show
  1. package/README.md +11 -0
  2. package/package.json +8 -21
  3. package/dist/@types/index.d.ts +0 -408
  4. package/dist/@types/index.d.ts.map +0 -1
  5. package/dist/@types/index.js +0 -9
  6. package/dist/@types/string-mask.d.ts +0 -10
  7. package/dist/@types/string-mask.d.ts.map +0 -1
  8. package/dist/@types/string-mask.js +0 -1
  9. package/dist/api.d.ts +0 -78
  10. package/dist/api.d.ts.map +0 -1
  11. package/dist/api.js +0 -1058
  12. package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts +0 -8
  13. package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts.map +0 -1
  14. package/dist/components/DataGridBySchemaEditable/BooleanInputCell.js +0 -86
  15. package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.d.ts +0 -12
  16. package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.d.ts.map +0 -1
  17. package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.js +0 -71
  18. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts +0 -9
  19. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts.map +0 -1
  20. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.js +0 -21
  21. package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +0 -26
  22. package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts.map +0 -1
  23. package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +0 -146
  24. package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts +0 -72
  25. package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +0 -1
  26. package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +0 -416
  27. package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts +0 -18
  28. package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts.map +0 -1
  29. package/dist/components/DataGridBySchemaEditable/DataGridMobile.js +0 -105
  30. package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts +0 -11
  31. package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts.map +0 -1
  32. package/dist/components/DataGridBySchemaEditable/FileInputCell.js +0 -155
  33. package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +0 -12
  34. package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts.map +0 -1
  35. package/dist/components/DataGridBySchemaEditable/FooterToolbar.js +0 -36
  36. package/dist/components/DataGridBySchemaEditable/GeoEditCell.d.ts +0 -10
  37. package/dist/components/DataGridBySchemaEditable/GeoEditCell.d.ts.map +0 -1
  38. package/dist/components/DataGridBySchemaEditable/GeoEditCell.js +0 -85
  39. package/dist/components/DataGridBySchemaEditable/GeoThumbCell.d.ts +0 -11
  40. package/dist/components/DataGridBySchemaEditable/GeoThumbCell.d.ts.map +0 -1
  41. package/dist/components/DataGridBySchemaEditable/GeoThumbCell.js +0 -87
  42. package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.d.ts +0 -18
  43. package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.d.ts.map +0 -1
  44. package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.js +0 -24
  45. package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts +0 -8
  46. package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts.map +0 -1
  47. package/dist/components/DataGridBySchemaEditable/GridDateInput.js +0 -166
  48. package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.d.ts +0 -6
  49. package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.d.ts.map +0 -1
  50. package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.js +0 -154
  51. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +0 -10
  52. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts.map +0 -1
  53. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.js +0 -78
  54. package/dist/components/DataGridBySchemaEditable/GridGenericInput.d.ts +0 -8
  55. package/dist/components/DataGridBySchemaEditable/GridGenericInput.d.ts.map +0 -1
  56. package/dist/components/DataGridBySchemaEditable/GridGenericInput.js +0 -30
  57. package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +0 -7
  58. package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts.map +0 -1
  59. package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +0 -74
  60. package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +0 -21
  61. package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts.map +0 -1
  62. package/dist/components/DataGridBySchemaEditable/InputInterval.js +0 -131
  63. package/dist/components/DataGridBySchemaEditable/MobileSearchBar.d.ts +0 -9
  64. package/dist/components/DataGridBySchemaEditable/MobileSearchBar.d.ts.map +0 -1
  65. package/dist/components/DataGridBySchemaEditable/MobileSearchBar.js +0 -70
  66. package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.d.ts +0 -7
  67. package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.d.ts.map +0 -1
  68. package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.js +0 -41
  69. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +0 -24
  70. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts.map +0 -1
  71. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +0 -259
  72. package/dist/components/DataGridBySchemaEditable/geoConstants.d.ts +0 -5
  73. package/dist/components/DataGridBySchemaEditable/geoConstants.d.ts.map +0 -1
  74. package/dist/components/DataGridBySchemaEditable/geoConstants.js +0 -6
  75. package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts +0 -33
  76. package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts.map +0 -1
  77. package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.js +0 -161
  78. package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts +0 -14
  79. package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts.map +0 -1
  80. package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.js +0 -69
  81. package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts +0 -9
  82. package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts.map +0 -1
  83. package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.js +0 -73
  84. package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts +0 -30
  85. package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts.map +0 -1
  86. package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.js +0 -199
  87. package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts +0 -33
  88. package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts.map +0 -1
  89. package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +0 -270
  90. package/dist/components/DataGridBySchemaEditable/utils.d.ts +0 -40
  91. package/dist/components/DataGridBySchemaEditable/utils.d.ts.map +0 -1
  92. package/dist/components/DataGridBySchemaEditable/utils.js +0 -181
  93. package/dist/components/DataGridBySchemaEditable.d.ts +0 -63
  94. package/dist/components/DataGridBySchemaEditable.d.ts.map +0 -1
  95. package/dist/components/DataGridBySchemaEditable.js +0 -172
  96. package/dist/components/DataTotals.d.ts +0 -12
  97. package/dist/components/DataTotals.d.ts.map +0 -1
  98. package/dist/components/DataTotals.js +0 -32
  99. package/dist/components/DataTotalsServer.d.ts +0 -10
  100. package/dist/components/DataTotalsServer.d.ts.map +0 -1
  101. package/dist/components/DataTotalsServer.js +0 -18
  102. package/dist/components/DialogActions.d.ts +0 -11
  103. package/dist/components/DialogActions.d.ts.map +0 -1
  104. package/dist/components/DialogActions.js +0 -20
  105. package/dist/components/FileTypeIcon.d.ts +0 -18
  106. package/dist/components/FileTypeIcon.d.ts.map +0 -1
  107. package/dist/components/FileTypeIcon.js +0 -48
  108. package/dist/components/GenericModelList.d.ts +0 -52
  109. package/dist/components/GenericModelList.d.ts.map +0 -1
  110. package/dist/components/GenericModelList.js +0 -194
  111. package/dist/components/GenericRelatedModelList.d.ts +0 -54
  112. package/dist/components/GenericRelatedModelList.d.ts.map +0 -1
  113. package/dist/components/GenericRelatedModelList.js +0 -181
  114. package/dist/components/GenericRelatedModelListTable.d.ts +0 -55
  115. package/dist/components/GenericRelatedModelListTable.d.ts.map +0 -1
  116. package/dist/components/GenericRelatedModelListTable.js +0 -31
  117. package/dist/components/Image.d.ts +0 -10
  118. package/dist/components/Image.d.ts.map +0 -1
  119. package/dist/components/Image.js +0 -111
  120. package/dist/components/details/DetailBySchema.d.ts +0 -4
  121. package/dist/components/details/DetailBySchema.d.ts.map +0 -1
  122. package/dist/components/details/DetailBySchema.js +0 -175
  123. package/dist/components/details/DetailFieldBySchema.d.ts +0 -4
  124. package/dist/components/details/DetailFieldBySchema.d.ts.map +0 -1
  125. package/dist/components/details/DetailFieldBySchema.js +0 -88
  126. package/dist/components/forms/DialogFormBySchema.d.ts +0 -22
  127. package/dist/components/forms/DialogFormBySchema.d.ts.map +0 -1
  128. package/dist/components/forms/DialogFormBySchema.js +0 -97
  129. package/dist/components/forms/FieldBySchema.d.ts +0 -4
  130. package/dist/components/forms/FieldBySchema.d.ts.map +0 -1
  131. package/dist/components/forms/FieldBySchema.js +0 -80
  132. package/dist/components/forms/Form.d.ts +0 -61
  133. package/dist/components/forms/Form.d.ts.map +0 -1
  134. package/dist/components/forms/Form.js +0 -264
  135. package/dist/components/forms/FormActions.d.ts +0 -20
  136. package/dist/components/forms/FormActions.d.ts.map +0 -1
  137. package/dist/components/forms/FormActions.js +0 -55
  138. package/dist/components/forms/FormBySchema.d.ts +0 -21
  139. package/dist/components/forms/FormBySchema.d.ts.map +0 -1
  140. package/dist/components/forms/FormBySchema.js +0 -280
  141. package/dist/components/forms/FormWatcher.d.ts +0 -10
  142. package/dist/components/forms/FormWatcher.d.ts.map +0 -1
  143. package/dist/components/forms/FormWatcher.js +0 -25
  144. package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +0 -13
  145. package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts.map +0 -1
  146. package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +0 -133
  147. package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +0 -4
  148. package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts.map +0 -1
  149. package/dist/components/forms/inputs/BooleanFieldBySchema.js +0 -39
  150. package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +0 -5
  151. package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts.map +0 -1
  152. package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +0 -54
  153. package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +0 -5
  154. package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts.map +0 -1
  155. package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +0 -47
  156. package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +0 -14
  157. package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts.map +0 -1
  158. package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +0 -272
  159. package/dist/components/forms/inputs/FileFieldBySchema.d.ts +0 -4
  160. package/dist/components/forms/inputs/FileFieldBySchema.d.ts.map +0 -1
  161. package/dist/components/forms/inputs/FileFieldBySchema.js +0 -144
  162. package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +0 -4
  163. package/dist/components/forms/inputs/FloatFieldBySchema.d.ts.map +0 -1
  164. package/dist/components/forms/inputs/FloatFieldBySchema.js +0 -64
  165. package/dist/components/forms/inputs/GeometryFieldBySchema.d.ts +0 -8
  166. package/dist/components/forms/inputs/GeometryFieldBySchema.d.ts.map +0 -1
  167. package/dist/components/forms/inputs/GeometryFieldBySchema.js +0 -57
  168. package/dist/components/forms/inputs/MapGeometryPicker.d.ts +0 -19
  169. package/dist/components/forms/inputs/MapGeometryPicker.d.ts.map +0 -1
  170. package/dist/components/forms/inputs/MapGeometryPicker.js +0 -322
  171. package/dist/components/forms/inputs/PatternFieldBySchema.d.ts +0 -4
  172. package/dist/components/forms/inputs/PatternFieldBySchema.d.ts.map +0 -1
  173. package/dist/components/forms/inputs/PatternFieldBySchema.js +0 -56
  174. package/dist/components/forms/inputs/TextFieldBySchema.d.ts +0 -4
  175. package/dist/components/forms/inputs/TextFieldBySchema.d.ts.map +0 -1
  176. package/dist/components/forms/inputs/TextFieldBySchema.js +0 -56
  177. package/dist/components/forms/inputs/leafletMarker.d.ts +0 -12
  178. package/dist/components/forms/inputs/leafletMarker.d.ts.map +0 -1
  179. package/dist/components/forms/inputs/leafletMarker.js +0 -52
  180. package/dist/context/APIWrapper.d.ts +0 -18
  181. package/dist/context/APIWrapper.d.ts.map +0 -1
  182. package/dist/context/APIWrapper.js +0 -584
  183. package/dist/context/APIWrapperContext.d.ts +0 -129
  184. package/dist/context/APIWrapperContext.d.ts.map +0 -1
  185. package/dist/context/APIWrapperContext.js +0 -60
  186. package/dist/context/DRFReactBySchemaContext.d.ts +0 -28
  187. package/dist/context/DRFReactBySchemaContext.d.ts.map +0 -1
  188. package/dist/context/DRFReactBySchemaContext.js +0 -20
  189. package/dist/context/DRFReactBySchemaProvider.d.ts +0 -5
  190. package/dist/context/DRFReactBySchemaProvider.d.ts.map +0 -1
  191. package/dist/context/DRFReactBySchemaProvider.js +0 -93
  192. package/dist/context/Overlays.d.ts +0 -5
  193. package/dist/context/Overlays.d.ts.map +0 -1
  194. package/dist/context/Overlays.js +0 -114
  195. package/dist/context/PrivateContext.d.ts +0 -10
  196. package/dist/context/PrivateContext.d.ts.map +0 -1
  197. package/dist/context/PrivateContext.js +0 -16
  198. package/dist/hooks/useDeepMemo.d.ts +0 -2
  199. package/dist/hooks/useDeepMemo.d.ts.map +0 -1
  200. package/dist/hooks/useDeepMemo.js +0 -13
  201. package/dist/hooks/useWhyDidYouUpdate.d.ts +0 -4
  202. package/dist/hooks/useWhyDidYouUpdate.d.ts.map +0 -1
  203. package/dist/hooks/useWhyDidYouUpdate.js +0 -26
  204. package/dist/index.d.ts +0 -35
  205. package/dist/index.d.ts.map +0 -1
  206. package/dist/index.js +0 -104
  207. package/dist/styles/grid.d.ts +0 -3
  208. package/dist/styles/grid.d.ts.map +0 -1
  209. package/dist/styles/grid.js +0 -38
  210. package/dist/styles/index.d.ts +0 -3
  211. package/dist/styles/index.d.ts.map +0 -1
  212. package/dist/styles/index.js +0 -38
  213. package/dist/styles/layout.d.ts +0 -23
  214. package/dist/styles/layout.d.ts.map +0 -1
  215. package/dist/styles/layout.js +0 -71
  216. package/dist/styles/texts.d.ts +0 -48
  217. package/dist/styles/texts.d.ts.map +0 -1
  218. package/dist/styles/texts.js +0 -55
  219. package/dist/styles/theme.d.ts +0 -29
  220. package/dist/styles/theme.d.ts.map +0 -1
  221. package/dist/styles/theme.js +0 -226
  222. package/dist/utils/index.d.ts +0 -2
  223. package/dist/utils/index.d.ts.map +0 -1
  224. package/dist/utils/index.js +0 -17
  225. package/dist/utils/utils.d.ts +0 -107
  226. package/dist/utils/utils.d.ts.map +0 -1
  227. package/dist/utils/utils.js +0 -957
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.default = FieldBySchema;
18
- const react_1 = __importDefault(require("react"));
19
- const DesktopDatePickerBySchema_1 = __importDefault(require("./inputs/DesktopDatePickerBySchema"));
20
- const DesktopDateTimePickerBySchema_1 = __importDefault(require("./inputs/DesktopDateTimePickerBySchema"));
21
- const EditableAutocompleteFieldBySchema_1 = __importDefault(require("./inputs/EditableAutocompleteFieldBySchema"));
22
- const AutocompleteFieldBySchema_1 = __importDefault(require("./inputs/AutocompleteFieldBySchema"));
23
- const BooleanFieldBySchema_1 = __importDefault(require("./inputs/BooleanFieldBySchema"));
24
- const FloatFieldBySchema_1 = __importDefault(require("./inputs/FloatFieldBySchema"));
25
- const TextFieldBySchema_1 = __importDefault(require("./inputs/TextFieldBySchema"));
26
- const FileFieldBySchema_1 = __importDefault(require("./inputs/FileFieldBySchema"));
27
- const PatternFieldBySchema_1 = __importDefault(require("./inputs/PatternFieldBySchema"));
28
- const GeometryFieldBySchema_1 = __importDefault(require("./inputs/GeometryFieldBySchema"));
29
- function FieldBySchema(_a) {
30
- var _b, _c, _d;
31
- var { name, schema, control, errors, multiline = false, setValue, getValues, fieldKey, labelKey = 'nome', index, optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, fieldsLayout, sx, options, isSemaphoric = false, label, onValueChange, decimalScale = 2, autoFocus } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "multiline", "setValue", "getValues", "fieldKey", "labelKey", "index", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "fieldsLayout", "sx", "options", "isSemaphoric", "label", "onValueChange", "decimalScale", "autoFocus"]);
32
- const fieldSchema = schema[name];
33
- // prevent switching from uncontrolled inputs (undefined) to controlled:
34
- // DISABLED, understand what is going on!
35
- // if (control._formValues[name] === undefined) {
36
- // return <></>;
37
- // }
38
- switch (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.type) {
39
- case 'date':
40
- return (react_1.default.createElement(DesktopDatePickerBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: multiline, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus }, other)));
41
- case 'datetime':
42
- return (react_1.default.createElement(DesktopDateTimePickerBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: multiline, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange }, other)));
43
- case 'nested object':
44
- case 'field':
45
- const relatedEditable = fieldSchema.related_editable;
46
- const multiple = fieldSchema.many || false;
47
- return (react_1.default.createElement(EditableAutocompleteFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, setValue: setValue, getValues: getValues, fieldKey: fieldKey, labelKey: labelKey, index: index, optionsAC: optionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: relatedEditable ? onEditModel : undefined, fieldsLayout: fieldsLayout, multiple: multiple, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus }, other)));
48
- case 'choice':
49
- return (react_1.default.createElement(AutocompleteFieldBySchema_1.default, { index: index, name: name, schema: schema, control: control, errors: errors, fieldKey: fieldKey, optionIdKey: "value", optionLabelKey: "display_name", options: options, isSemaphoric: isSemaphoric, label: label, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus }));
50
- case 'list':
51
- const multipleOptions = options || ((_b = fieldSchema.child) === null || _b === void 0 ? void 0 : _b.choices);
52
- return (react_1.default.createElement(AutocompleteFieldBySchema_1.default, { index: index, name: name, schema: schema, multiple: true, control: control, errors: errors, fieldKey: fieldKey, optionIdKey: "value", optionLabelKey: "display_name", options: multipleOptions, isSemaphoric: isSemaphoric, label: label, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus }));
53
- case 'boolean':
54
- return (react_1.default.createElement(BooleanFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus }, other)));
55
- case 'decimal':
56
- case 'float':
57
- return (react_1.default.createElement(FloatFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: multiline, fieldKey: fieldKey, index: index, onValueChange: onValueChange, decimalScale: decimalScale, label: label, sx: sx, autoFocus: autoFocus }, other)));
58
- case 'file':
59
- case 'file upload':
60
- case 'image':
61
- case 'image upload':
62
- return (react_1.default.createElement(FileFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus }, other)));
63
- case 'point':
64
- case 'polygon':
65
- case 'multipoint':
66
- case 'multipolygon':
67
- case 'geometrycollection':
68
- return (react_1.default.createElement(GeometryFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, geometry: fieldSchema.type, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus }, other)));
69
- case 'number':
70
- case 'integer':
71
- case 'password':
72
- default:
73
- if (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.pattern_format) {
74
- return (react_1.default.createElement(PatternFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus, type: (_c = fieldSchema.style) === null || _c === void 0 ? void 0 : _c.input_type }, other)));
75
- }
76
- const localMultiline = (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.model_multiline) === true || multiline;
77
- const minRows = localMultiline ? 3 : 0;
78
- return (react_1.default.createElement(TextFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: localMultiline, minRows: minRows, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus, type: (_d = fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.style) === null || _d === void 0 ? void 0 : _d.input_type }, other)));
79
- }
80
- }
@@ -1,61 +0,0 @@
1
- import React from 'react';
2
- import { AxiosError } from 'axios';
3
- import { UseFormRegister } from 'react-hook-form';
4
- import { AutocompleteItem, CommonFieldProps, CustomFormFieldLayouts, ExtraSxCommonFieldProps, FieldsProps, FormFieldLayout, FormSaveActions, Id, Item, OptionsAC, ExtraValidators, FieldKey, FormWatchObject, FieldList, TField, PartialItem } from '../../@types';
5
- import { FormActionsProps } from './FormActions';
6
- interface FormProps<T extends TField = void> extends Omit<CommonFieldProps<T>, 'fieldsLayout' | 'optionsAC'> {
7
- model: string;
8
- objId?: Id;
9
- defaults?: PartialItem<T>;
10
- objTitleField?: FieldKey<T>;
11
- /** Optional. If the dev wants to do something after saving. Gets the new Id */
12
- onSave?: (currentId: Id, newId: Id | AxiosError, buttonType: FormSaveActions) => void;
13
- /** Optional. If the dev wants to do something after deleting item. Gets the item's Id */
14
- onDelete?: (removedId: Id) => void;
15
- /** Optional. If the dev wants to do something after canceling the form editing. */
16
- onCancel?: React.MouseEventHandler<HTMLButtonElement>;
17
- navigate?: {
18
- (to: string): void;
19
- (delta: number): void;
20
- };
21
- /** Optional. Exit function. If not provided and also no exitPath provided,
22
- * navigate(exitPath) or history.back() will be used.
23
- */
24
- exit?: (newId?: Id) => void;
25
- saveAndContinue?: boolean;
26
- /** Optional. Path of the form.
27
- * Use {ID} to indicate where the objId is located (example: /your-path/{ID}/edit).
28
- * No {ID} means that the path ends with objId (example: /your-path/{ID}).
29
- * If not provided, the actual location will be considered, ending with {ID}:
30
- * actual-location-path/{ID} */
31
- editPath?: string;
32
- /** Optional. Path for exit. If none is defined and no 'exit' function is provided,
33
- * windows.history.back() will be used.
34
- */
35
- exitPath?: string;
36
- title?: string;
37
- labelSave?: string;
38
- labelSaveAndContinue?: string;
39
- labelSaveAndCreateNew?: string;
40
- labelCancel?: string;
41
- labelRemove?: string;
42
- fieldsLayout?: FormFieldLayout<T>[];
43
- customFieldFormLayouts?: CustomFormFieldLayouts<T>;
44
- hiddenFields?: FieldList<T>;
45
- register?: UseFormRegister<Item<T>>;
46
- optionsAC?: OptionsAC<T>;
47
- setOptionsAC?: (x: OptionsAC<T>) => void;
48
- isolatedGetAutoComplete?: (model: string) => Promise<AutocompleteItem[] | AxiosError>;
49
- fieldsProps?: FieldsProps<T>;
50
- relatedEditable?: boolean;
51
- autoFocusField?: FieldKey<T>;
52
- elevation?: number;
53
- CustomFormActions?: (props: FormActionsProps) => React.JSX.Element;
54
- extraValidators?: ExtraValidators<T>;
55
- watchValues?: FieldList<T>;
56
- onWatchChange?: (values: FormWatchObject<T>) => void;
57
- reloadStateStamp?: number | string;
58
- }
59
- declare function Form<T extends TField = void>({ model, objId, defaults, objTitleField, onSave, onDelete, onCancel, navigate, exit: customExit, saveAndContinue, editPath, exitPath, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, multiline, fieldKey, labelKey, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout, customFieldFormLayouts, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, CustomFormActions, extraValidators, sxRow, sxRowMultiple, sxSection, sxSectionTitle, watchValues, onWatchChange, reloadStateStamp, }: FormProps<T> & Omit<ExtraSxCommonFieldProps, 'sx' | 'sxField' | 'sxLabel' | 'sxValue' | 'sxValueList' | 'sxValueListItem' | 'sxValueListItemText'>): React.JSX.Element;
60
- export default Form;
61
- //# sourceMappingURL=Form.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/components/forms/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAEL,eAAe,EAMhB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,WAAW,EACX,eAAe,EACf,eAAe,EAEf,EAAE,E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AK,EACL,KAAK,EACL,QAAQ,EACR,aAAa,EAEb,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,IAAI,EAAE,UAAU,EAChB,eAAe,EAEf,QAAQ,EACR,QAAQ,EAER,KAAK,EACL,SAAS,EACT,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,WAAW,EAEX,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EACX,OAAO,EACP,YAAY,EACZ,KAAK,EACL,YAAY,EAEZ,YAAY,EACZ,sBAAsB,EAEtB,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,eAAe,EACf,cAAc,EACd,SAAS,EAET,iBAAiB,EACjB,eAAe,EAEf,KAAK,EACL,aAAa,EACb,SAAS,EACT,cAAc,EAEd,WAAW,EACX,aAAa,EAEb,gBAAgB,GACjB,EAAE,SAAS,CAAC,CAAC,CAAC,GACb,IAAI,CACF,uBAAuB,EACrB,IAAI,GACJ,SAAS,GACT,SAAS,GACT,SAAS,GACT,aAAa,GACb,iBAAiB,GACjB,qBAAqB,CACxB,qBAsVF;AAED,eAAe,IAAI,CAAC"}
@@ -1,264 +0,0 @@
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
- const react_1 = __importStar(require("react"));
49
- const axios_1 = __importDefault(require("axios"));
50
- const react_hook_form_1 = require("react-hook-form");
51
- const yup_1 = require("@hookform/resolvers/yup");
52
- const _types_1 = require("../../@types");
53
- const APIWrapperContext_1 = require("../../context/APIWrapperContext");
54
- const utils_1 = require("../../utils");
55
- const FormBySchema_1 = __importDefault(require("./FormBySchema"));
56
- const FormActions_1 = __importDefault(require("./FormActions"));
57
- const PrivateContext_1 = require("../../context/PrivateContext");
58
- const useDeepMemo_1 = require("../../hooks/useDeepMemo");
59
- const utils_2 = require("../DataGridBySchemaEditable/utils");
60
- const FormWatcher_1 = __importDefault(require("./FormWatcher"));
61
- function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCancel, navigate, exit: customExit, saveAndContinue, editPath, exitPath, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, multiline, fieldKey, labelKey, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout, customFieldFormLayouts, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, CustomFormActions, extraValidators, sxRow, sxRowMultiple, sxSection, sxSectionTitle, watchValues, onWatchChange, reloadStateStamp, }) {
62
- const loadingRef = (0, react_1.useRef)(false);
63
- const { setFormTools } = (0, PrivateContext_1.usePrivateContext)();
64
- const { pageForm, loadSinglePageData, onSubmit, formTools, resetPageForm } = (0, APIWrapperContext_1.useAPIWrapper)();
65
- const formToolsRef = (0, react_1.useRef)(formTools);
66
- const onSaveRef = (0, react_1.useRef)(onSave);
67
- const customExitRef = (0, react_1.useRef)(customExit);
68
- const methods = (0, react_hook_form_1.useForm)({
69
- mode: 'onBlur',
70
- // yupResolver infers against untyped base `Item`; reassert to generic `Item<T>`.
71
- resolver: (pageForm === null || pageForm === void 0 ? void 0 : pageForm.validationSchema)
72
- ? (0, yup_1.yupResolver)(pageForm.validationSchema)
73
- : undefined,
74
- });
75
- const { control, handleSubmit, reset, getValues, setValue, setError, formState: { errors, isDirty }, register, watch, } = methods;
76
- const stableDefaults = (0, useDeepMemo_1.useDeepMemo)(defaults);
77
- const stableExtraValidators = (0, useDeepMemo_1.useDeepMemo)(extraValidators);
78
- const FinalFormActions = CustomFormActions || FormActions_1.default;
79
- const conditionalVisible = (0, react_1.useMemo)(() => {
80
- return (0, utils_1.buildConditionalVisibleBySchema)(pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema);
81
- }, [pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema]);
82
- const watchedValues = watch(conditionalVisible.map((item) => item.source));
83
- const loadData = (0, react_1.useCallback)((newId) => __awaiter(this, void 0, void 0, function* () {
84
- loadingRef.current = true;
85
- const values = yield loadSinglePageData({
86
- model,
87
- objId: newId,
88
- defaults: stableDefaults,
89
- objTitleField,
90
- extraValidators: stableExtraValidators,
91
- });
92
- if (values && !axios_1.default.isAxiosError(values)) {
93
- reset(values);
94
- }
95
- loadingRef.current = false;
96
- }), [loadSinglePageData, model, stableDefaults, objTitleField, stableExtraValidators, reset]);
97
- const genericNavigate = (0, react_1.useCallback)((path) => {
98
- if (navigate) {
99
- if (typeof path === 'string') {
100
- navigate(path);
101
- return;
102
- }
103
- navigate(path);
104
- return;
105
- }
106
- if (typeof path === 'string') {
107
- window.location.href = path;
108
- return;
109
- }
110
- window.history.back();
111
- }, [navigate]);
112
- const exit = (0, react_1.useCallback)((id) => {
113
- if (customExitRef.current) {
114
- customExitRef.current(id);
115
- return;
116
- }
117
- if (exitPath) {
118
- genericNavigate((0, utils_2.buildExitPath)(exitPath, id));
119
- return;
120
- }
121
- // const parentPath = window.location.pathname.replace(/\/[^\/]+\/?$/, '/');
122
- // genericNavigate(parentPath);
123
- genericNavigate(-1);
124
- }, [exitPath, genericNavigate]);
125
- const localOnSubmit = (0, react_1.useCallback)((data, event) => __awaiter(this, void 0, void 0, function* () {
126
- var _a, _b;
127
- const currentId = objId || (0, utils_1.getTmpId)();
128
- const response = yield onSubmit(model, currentId, data, event);
129
- if (axios_1.default.isAxiosError(response)) {
130
- // Map DRF field validation errors (e.g. raised in a serializer's
131
- // `validate()`) onto the corresponding form fields so they are shown
132
- // underlined with the message right below them, just like yup errors.
133
- const fieldErrors = (0, utils_1.getFieldErrorsFromResponse)((_a = response.response) === null || _a === void 0 ? void 0 : _a.data, (_b = pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema) !== null && _b !== void 0 ? _b : undefined);
134
- const entries = Object.entries(fieldErrors);
135
- if (entries.length > 0) {
136
- entries.forEach(([field, { type, message }]) => {
137
- setError(field, { type, message });
138
- });
139
- }
140
- return;
141
- }
142
- const newId = response;
143
- const buttonType = (event === null || event === void 0 ? void 0 : event.nativeEvent.submitter.name) || _types_1.FormSaveActions.EXIT_ON_SAVE;
144
- switch (buttonType) {
145
- case _types_1.FormSaveActions.SAVE_AND_CREATE_NEW:
146
- loadData(undefined);
147
- break;
148
- case _types_1.FormSaveActions.SAVE_AND_CONTINUE:
149
- reset(Object.assign(Object.assign({}, data), { id: newId }));
150
- break;
151
- case _types_1.FormSaveActions.EXIT_ON_SAVE:
152
- default:
153
- resetPageForm();
154
- break;
155
- }
156
- // In case the user wants to do something else after saving
157
- if (onSaveRef.current) {
158
- onSaveRef.current(currentId, newId, buttonType);
159
- }
160
- const goToEdit = (id = 'novo') => {
161
- const populatedEditPath = editPath
162
- ? (0, utils_2.buildEditPath)(editPath, id)
163
- : `${window.location.pathname.replace(/\/[^\/]+\/?$/, '/')}${id}`;
164
- genericNavigate(populatedEditPath);
165
- };
166
- switch (buttonType) {
167
- case _types_1.FormSaveActions.SAVE_AND_CREATE_NEW:
168
- goToEdit();
169
- break;
170
- case _types_1.FormSaveActions.SAVE_AND_CONTINUE:
171
- goToEdit(newId);
172
- break;
173
- case _types_1.FormSaveActions.EXIT_ON_SAVE:
174
- default:
175
- exit(newId);
176
- break;
177
- }
178
- }), [
179
- loadData,
180
- model,
181
- objId,
182
- onSubmit,
183
- pageForm,
184
- reset,
185
- resetPageForm,
186
- exit,
187
- editPath,
188
- genericNavigate,
189
- setError,
190
- ]);
191
- const updateFormTools = (0, react_1.useCallback)(() => {
192
- const currentFormTools = formToolsRef.current;
193
- if (!currentFormTools ||
194
- currentFormTools.errors !== errors ||
195
- currentFormTools.isDirty !== isDirty ||
196
- currentFormTools.reset !== reset ||
197
- currentFormTools.getValues !== getValues ||
198
- currentFormTools.setValue !== setValue) {
199
- setFormTools({
200
- errors,
201
- reset,
202
- getValues,
203
- setValue,
204
- isDirty,
205
- });
206
- }
207
- }, [errors, getValues, isDirty, reset, setFormTools, setValue]);
208
- (0, react_1.useEffect)(() => {
209
- loadData(objId);
210
- }, [objId, loadData, reloadStateStamp]);
211
- // Why was I using this useEffect???
212
- // useEffect(() => {
213
- // if (!loadingRef.current && !pageForm?.model) {
214
- // loadData(objId);
215
- // }
216
- // }, [objId, pageForm?.model, pageForm?.id, loadData]);
217
- (0, react_1.useEffect)(() => {
218
- updateFormTools();
219
- }, [updateFormTools]);
220
- (0, react_1.useEffect)(() => {
221
- if (errors && Object.keys(errors).length > 0) {
222
- console.log({ errors });
223
- }
224
- }, [errors]);
225
- (0, react_1.useEffect)(() => {
226
- const handleBeforeUnload = (event) => {
227
- if (isDirty) {
228
- event.preventDefault();
229
- event.returnValue = '';
230
- return '';
231
- }
232
- };
233
- window.addEventListener('beforeunload', handleBeforeUnload);
234
- return () => {
235
- window.removeEventListener('beforeunload', handleBeforeUnload);
236
- };
237
- }, [isDirty]);
238
- (0, react_1.useEffect)(() => {
239
- formToolsRef.current = formTools;
240
- }, [formTools]);
241
- (0, react_1.useEffect)(() => {
242
- onSaveRef.current = onSave;
243
- }, [onSave]);
244
- (0, react_1.useEffect)(() => {
245
- customExitRef.current = customExit;
246
- }, [customExit]);
247
- (0, react_1.useEffect)(() => {
248
- return () => {
249
- resetPageForm();
250
- };
251
- }, [resetPageForm]);
252
- if (!(pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema) || (pageForm === null || pageForm === void 0 ? void 0 : pageForm.model) !== model) {
253
- return react_1.default.createElement(react_1.default.Fragment, null);
254
- }
255
- return (react_1.default.createElement(react_hook_form_1.FormProvider, Object.assign({}, methods),
256
- react_1.default.createElement("form", { onSubmit: handleSubmit(localOnSubmit) },
257
- react_1.default.createElement(FinalFormActions, { formDisabled: !isDirty, model: model, objId: objId, saveAndContinue: saveAndContinue, onCancel: onCancel, onDelete: onDelete, exit: exit, title: title, labelSave: labelSave, labelSaveAndContinue: labelSaveAndContinue, labelSaveAndCreateNew: labelSaveAndCreateNew, labelCancel: labelCancel, labelRemove: labelRemove }),
258
- react_1.default.createElement(FormBySchema_1.default, { fieldsLayout: fieldsLayout, hiddenFields: hiddenFields, control: control, register: register, errors: errors, schema: pageForm.schema, getValues: getValues, setValue: setValue, multiline: multiline, fieldKey: fieldKey, labelKey: labelKey, optionsAC: optionsAC, setOptionsAC: setOptionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, options: options, isSemaphoric: isSemaphoric, label: label, decimalScale: decimalScale, customFieldFormLayouts: customFieldFormLayouts, fieldsProps: fieldsProps, isolatedGetAutoComplete: isolatedGetAutoComplete, relatedEditable: relatedEditable, autoFocusField: autoFocusField, elevation: elevation, sxRow: sxRow, sxRowMultiple: sxRowMultiple, sxSection: sxSection, sxSectionTitle: sxSectionTitle, conditionalVisible: conditionalVisible, watchedValues: watchedValues }),
259
- watchValues && onWatchChange && (react_1.default.createElement(FormWatcher_1.default, {
260
- // FormWatcher only uses useWatch; align control to Control<GenericValue>.
261
- control: control, watch: watchValues, onChange: onWatchChange })),
262
- react_1.default.createElement(FinalFormActions, { bottom: true, formDisabled: !isDirty, model: model, objId: objId, saveAndContinue: saveAndContinue, onCancel: onCancel, onDelete: onDelete, exit: exit, title: title, labelSave: labelSave, labelSaveAndContinue: labelSaveAndContinue, labelSaveAndCreateNew: labelSaveAndCreateNew, labelCancel: labelCancel, labelRemove: labelRemove }))));
263
- }
264
- exports.default = Form;
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import { Id, TField } from '../../@types';
3
- export type FormActionsProps = {
4
- formDisabled?: boolean;
5
- model: string;
6
- objId?: Id;
7
- onCancel?: React.MouseEventHandler<HTMLButtonElement>;
8
- onDelete?: (removedId: Id) => void;
9
- exit: (id?: Id) => void;
10
- bottom?: boolean;
11
- saveAndContinue?: boolean;
12
- title?: string;
13
- labelSave?: string;
14
- labelSaveAndContinue?: string;
15
- labelSaveAndCreateNew?: string;
16
- labelCancel?: string;
17
- labelRemove?: string;
18
- };
19
- export default function FormActions<T extends TField = void>({ formDisabled, model, objId, onCancel, onDelete, exit, bottom, saveAndContinue, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, }: FormActionsProps): React.JSX.Element;
20
- //# sourceMappingURL=FormActions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormActions.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormActions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,EAAmB,EAAE,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,EAAE,CAAC;IACX,QAAQ,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IACtD,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,KAAK,IAAI,CAAC;IACnC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EAC3D,YAAY,EACZ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,eAAe,EACf,KAAK,EACL,SAAS,EACT,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,WAAW,GACZ,EAAE,gBAAgB,qBAiHlB"}
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = FormActions;
7
- const react_1 = __importDefault(require("react"));
8
- const Box_1 = __importDefault(require("@mui/material/Box"));
9
- const Button_1 = __importDefault(require("@mui/material/Button"));
10
- const Typography_1 = __importDefault(require("@mui/material/Typography"));
11
- const styles_1 = require("@mui/material/styles");
12
- const styles_2 = require("../../styles");
13
- const utils_1 = require("../../utils");
14
- const _types_1 = require("../../@types");
15
- const APIWrapperContext_1 = require("../../context/APIWrapperContext");
16
- const texts_1 = require("../../styles/texts");
17
- function FormActions({ formDisabled, model, objId, onCancel, onDelete, exit, bottom, saveAndContinue, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, }) {
18
- const { onDeleteModel, isMobile } = (0, APIWrapperContext_1.useAPIWrapper)();
19
- const texts = (0, texts_1.getThemeTexts)((0, styles_1.useTheme)());
20
- const formTexts = texts.forms;
21
- if (isMobile && !bottom) {
22
- return react_1.default.createElement(react_1.default.Fragment, null);
23
- }
24
- const finalSx = Object.assign(Object.assign({}, styles_2.Layout.flexRowGrow), (bottom && !(0, utils_1.isTmpId)(objId)
25
- ? {
26
- mb: 5,
27
- pb: 2,
28
- borderBottom: 'solid 1px #aaa',
29
- }
30
- : {}));
31
- const handleDelete = () => {
32
- if (objId && !(0, utils_1.isTmpId)(objId)) {
33
- onDeleteModel(model, objId);
34
- if (onDelete) {
35
- onDelete(objId);
36
- }
37
- exit(objId);
38
- }
39
- };
40
- const handleCancel = (event) => {
41
- if (onCancel) {
42
- onCancel(event);
43
- }
44
- exit(objId);
45
- };
46
- return (react_1.default.createElement(Box_1.default, { sx: finalSx },
47
- bottom ? (react_1.default.createElement(Button_1.default, { variant: "contained", type: "button", color: "error", size: "small", disabled: (0, utils_1.isTmpId)(objId) || !onDeleteModel, onClick: handleDelete }, labelRemove || formTexts.remove)) : title ? (react_1.default.createElement(Typography_1.default, { variant: "h5" }, title)) : (react_1.default.createElement(Box_1.default, null)),
48
- isMobile ? (react_1.default.createElement(Box_1.default, { sx: styles_2.Layout.flexRow },
49
- react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.EXIT_ON_SAVE, type: "submit", color: "primary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSave || formTexts.save))) : (react_1.default.createElement(Box_1.default, { sx: styles_2.Layout.flexRow },
50
- react_1.default.createElement(Button_1.default, { variant: "contained", color: "primary", size: "small", sx: { ml: 1 }, onClick: handleCancel }, labelCancel || formTexts.cancel),
51
- !isMobile && saveAndContinue && (react_1.default.createElement(react_1.default.Fragment, null,
52
- react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.SAVE_AND_CREATE_NEW, type: "submit", color: "secondary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSaveAndCreateNew || formTexts.saveAndCreateNew),
53
- react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.SAVE_AND_CONTINUE, type: "submit", color: "secondary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSaveAndContinue || formTexts.saveAndContinue))),
54
- react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.EXIT_ON_SAVE, type: "submit", color: "primary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSave || formTexts.save)))));
55
- }
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import { AxiosError } from 'axios';
3
- import { UseFormRegister } from 'react-hook-form';
4
- import { AutocompleteItem, ConditionalVisible, CustomFormFieldLayouts, ExtraSxCommonFieldProps, FieldBySchemaProps, FieldsProps, FormFieldLayout, GenericValue, Item, OptionsAC, FieldKey, FieldList, TField } from '../../@types';
5
- type FormBySchemaProps<T extends TField = void> = Omit<FieldBySchemaProps<T>, 'name'> & {
6
- fieldsLayout?: FormFieldLayout<T>[];
7
- customFieldFormLayouts?: CustomFormFieldLayouts<T>;
8
- hiddenFields?: FieldList<T>;
9
- register?: UseFormRegister<Item<T>>;
10
- setOptionsAC?: (x: OptionsAC<T>) => void;
11
- isolatedGetAutoComplete?: (model: string) => Promise<AutocompleteItem[] | AxiosError>;
12
- fieldsProps?: FieldsProps<T>;
13
- relatedEditable?: boolean;
14
- autoFocusField?: FieldKey<T>;
15
- elevation?: number;
16
- conditionalVisible?: ConditionalVisible[];
17
- watchedValues?: GenericValue[];
18
- };
19
- export default function FormBySchema<T extends TField = void>({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel: customOnEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout: fieldsLayoutInitial, customFieldFormLayouts, conditionalVisible, watchedValues, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, sxRow, sxRowMultiple, sxSection, sxSectionTitle, }: FormBySchemaProps<T> & Omit<ExtraSxCommonFieldProps, 'sx' | 'sxField' | 'sxLabel' | 'sxValue' | 'sxValueList' | 'sxValueListItem' | 'sxValueListItemText'>): React.JSX.Element;
20
- export {};
21
- //# sourceMappingURL=FormBySchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAiB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAUjE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,QAAQ,EAER,SAAS,EACT,MAAM,EACP,MAAM,cAAc,CAAC;AAQtB,KAAK,iBAAiB,CAAC,CAAC,S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