@dashadmin/dash-auto-admin 1.3.24 → 1.3.26

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 (176) hide show
  1. package/dist/DashAutoAdminComponentRegistry.js +64 -1
  2. package/dist/DashAutoAdminForm.js +137 -1
  3. package/dist/DashAutoAdminResizableDrawer.js +63 -1
  4. package/dist/DashAutoAdminSaveButton.js +57 -1
  5. package/dist/DashAutoCreate.js +102 -1
  6. package/dist/DashAutoDrawer.js +256 -1
  7. package/dist/DashAutoEdit.js +99 -1
  8. package/dist/DashAutoFiltersGenerator.js +193 -1
  9. package/dist/DashAutoFormGroups.js +118 -1
  10. package/dist/DashAutoFormLayout.js +68 -1
  11. package/dist/DashAutoFormMuiTabs.js +291 -1
  12. package/dist/DashAutoFormTabs.js +132 -1
  13. package/dist/DashAutoGroup.js +27 -1
  14. package/dist/DashAutoLayout.js +31 -1
  15. package/dist/DashAutoList.js +218 -1
  16. package/dist/DashAutoPostFilterForm.js +47 -1
  17. package/dist/DashAutoReferenceTab.js +10 -1
  18. package/dist/DashAutoResource.js +77 -1
  19. package/dist/DashAutoResourceLayout.js +16 -1
  20. package/dist/DashAutoShow.js +195 -1
  21. package/dist/DashAutoTabbedForm.js +244 -1
  22. package/dist/DashAutoTabbedForm.review.js +221 -1
  23. package/dist/DashAutoTabs.js +11 -1
  24. package/dist/DashFilterWrapper.js +62 -1
  25. package/dist/DashRedirect.js +56 -1
  26. package/dist/TabbedLayout.js +38 -1
  27. package/dist/common/DashAutoTitle.js +33 -1
  28. package/dist/common/components/FabButton.js +59 -1
  29. package/dist/common/components/TranslatedLabel.js +60 -1
  30. package/dist/common/settings/Settings.js +196 -1
  31. package/dist/common/settings/SettingsBarIcons.js +61 -1
  32. package/dist/context/DashAutoAdminFormContext.js +15 -1
  33. package/dist/hooks/useAutoAdminLoadingStateMediator.js +36 -1
  34. package/dist/hooks/useAutoAdminTranslate.js +61 -1
  35. package/dist/hooks/useHash.js +24 -1
  36. package/dist/hooks/useLogger.js +20 -1
  37. package/dist/hooks/useRoutePathPattern.js +20 -1
  38. package/dist/hooks/useVirtualHash.js +28 -1
  39. package/dist/index.js +77 -3406
  40. package/dist/list/DashAutoListActions.js +57 -1
  41. package/dist/list/DashAutoListDatagridWrapper.js +68 -1
  42. package/dist/list/DashAutoListDefaultActionsWrapper.js +14 -1
  43. package/dist/list/DashAutoListFilterFormWithButton.js +80 -1
  44. package/dist/list/DashAutoListTopToolbar.js +180 -1
  45. package/dist/mui/AttributeToField.js +576 -1
  46. package/dist/mui/AttributeToInput.js +630 -1
  47. package/dist/mui/AutoAdminResizableDrawer.js +63 -1
  48. package/dist/mui/AutoDataGrid.js +120 -1
  49. package/dist/mui/AutoReferenceFormTab.js +53 -1
  50. package/dist/mui/AutoReferenceTab.js +46 -1
  51. package/dist/mui/AutoTabs.js +19 -1
  52. package/dist/mui/components/ExtendedPagination.js +34 -1
  53. package/dist/mui/components/ListStringField.js +25 -1
  54. package/dist/providers/DashAuthProvider.js +215 -1
  55. package/dist/providers/DashDataProvider.js +310 -1
  56. package/dist/providers/index.js +10 -1
  57. package/dist/react-admin.d.js +0 -0
  58. package/dist/toolbar/buttons/BottomToolbarButtons.js +65 -1
  59. package/dist/toolbar/buttons/DashResourceButton.js +181 -1
  60. package/dist/toolbar/buttons/ListButtons.js +80 -1
  61. package/dist/toolbar/buttons/ToolbarButtons.js +135 -1
  62. package/dist/types/ActionCallback.d.js +0 -0
  63. package/dist/utils/SimpleLogger.js +52 -1
  64. package/dist/utils/enumToChoices.js +5 -1
  65. package/dist/utils/evalActionPermission.js +11 -1
  66. package/dist/utils/groupByTabs.js +21 -1
  67. package/dist/utils/hashedGroupByTabs.js +12 -1
  68. package/dist/utils/invertMap.js +12 -1
  69. package/dist/utils/isClassComponent.js +7 -1
  70. package/dist/utils/isComponent.js +29 -1
  71. package/dist/utils/isEnum.js +5 -1
  72. package/dist/utils/isFC.js +8 -1
  73. package/dist/utils/replaceParams.js +9 -1
  74. package/dist/utils/validate.js +19 -1
  75. package/dist/wrappers/UserAction.js +60 -1
  76. package/dist/wrappers/index.js +4 -1
  77. package/package.json +135 -120
  78. package/src/DashAutoAdminComponentRegistry.tsx +75 -0
  79. package/src/DashAutoAdminForm.tsx +155 -0
  80. package/src/DashAutoAdminResizableDrawer.tsx +69 -0
  81. package/src/DashAutoAdminSaveButton.tsx +116 -0
  82. package/src/DashAutoCreate.tsx +118 -0
  83. package/src/DashAutoDrawer.tsx +288 -0
  84. package/src/DashAutoEdit.tsx +109 -0
  85. package/src/DashAutoFiltersGenerator.tsx +208 -0
  86. package/src/DashAutoFormGroups.tsx +146 -0
  87. package/src/DashAutoFormLayout.tsx.review +113 -0
  88. package/src/DashAutoFormMuiTabs.tsx +368 -0
  89. package/src/DashAutoFormTabs.tsx +177 -0
  90. package/src/DashAutoGroup.tsx +42 -0
  91. package/src/DashAutoLayout.tsx +57 -0
  92. package/src/DashAutoList.tsx +237 -0
  93. package/src/DashAutoPostFilterForm.tsx +35 -0
  94. package/src/DashAutoReferenceTab.tsx +9 -0
  95. package/src/DashAutoResource.tsx +85 -0
  96. package/src/DashAutoResourceLayout.tsx +50 -0
  97. package/src/DashAutoShow.tsx +200 -0
  98. package/src/DashAutoTabbedForm.review.tsx +262 -0
  99. package/src/DashAutoTabbedForm.tsx +324 -0
  100. package/src/DashAutoTabs.tsx +19 -0
  101. package/src/DashFilterWrapper.tsx +43 -0
  102. package/src/DashRedirect.tsx +46 -0
  103. package/src/TabbedLayout.tsx +29 -0
  104. package/src/common/DashAutoTitle.tsx +24 -0
  105. package/src/common/components/FabButton.tsx +40 -0
  106. package/src/common/components/TranslatedLabel.tsx +81 -0
  107. package/src/common/settings/Settings.tsx +236 -0
  108. package/src/common/settings/SettingsBarIcons.tsx +72 -0
  109. package/src/context/DashAutoAdminFormContext.tsx +31 -0
  110. package/src/hooks/useAutoAdminLoadingStateMediator.tsx +42 -0
  111. package/src/hooks/useAutoAdminTranslate.tsx +106 -0
  112. package/src/hooks/useHash.tsx +27 -0
  113. package/src/hooks/useLogger.tsx +23 -0
  114. package/src/hooks/useRoutePathPattern.tsx +24 -0
  115. package/src/hooks/useVirtualHash.tsx +34 -0
  116. package/src/index.ts +85 -0
  117. package/src/interfaces/ICustomResourceSubComponent.ts +11 -0
  118. package/src/interfaces/IDashApplicationLayoutMainAction.ts +37 -0
  119. package/src/interfaces/IDashApplicationLayoutMenuItem.ts +24 -0
  120. package/src/interfaces/IDashAutoAdminAttribute.ts +104 -0
  121. package/src/interfaces/IDashAutoAdminCustomFieldComponent.ts +18 -0
  122. package/src/interfaces/IDashAutoAdminFormOptions.ts +22 -0
  123. package/src/interfaces/IDashAutoAdminListActions.ts +13 -0
  124. package/src/interfaces/IDashAutoAdminReference.ts +16 -0
  125. package/src/interfaces/IDashAutoAdminResourceConfig.ts +360 -0
  126. package/src/interfaces/IDashAutoForm.ts +24 -0
  127. package/src/interfaces/IDashAutoGridButton.ts +35 -0
  128. package/src/interfaces/IDashAutoShow.ts +12 -0
  129. package/src/interfaces/IGroupExtraData.ts +8 -0
  130. package/src/interfaces/IRecord.ts +7 -0
  131. package/src/interfaces/IReferenceFilter.ts +55 -0
  132. package/src/interfaces/IResourceComponent.ts +8 -0
  133. package/src/interfaces/IToolbarButton.ts +11 -0
  134. package/src/list/DashAutoListActions.tsx +88 -0
  135. package/src/list/DashAutoListDatagridWrapper.tsx +74 -0
  136. package/src/list/DashAutoListDefaultActionsWrapper.tsx +31 -0
  137. package/src/list/DashAutoListFilterFormWithButton.tsx +93 -0
  138. package/src/list/DashAutoListTopToolbar.tsx +240 -0
  139. package/src/mui/AttributeToField.tsx +657 -0
  140. package/src/mui/AttributeToInput.tsx +728 -0
  141. package/src/mui/AutoAdminResizableDrawer.tsx +69 -0
  142. package/src/mui/AutoDataGrid.tsx +127 -0
  143. package/src/mui/AutoReferenceFormTab.tsx +51 -0
  144. package/src/mui/AutoReferenceTab.tsx +45 -0
  145. package/src/mui/AutoTabs.tsx +32 -0
  146. package/src/mui/components/ExtendedPagination.tsx +23 -0
  147. package/src/mui/components/ListStringField.tsx +32 -0
  148. package/src/providers/DashAuthProvider.ts +341 -0
  149. package/src/providers/DashDataProvider.ts +466 -0
  150. package/src/providers/index.ts +17 -0
  151. package/src/toolbar/buttons/BottomToolbarButtons.tsx +59 -0
  152. package/src/toolbar/buttons/DashResourceButton.tsx +223 -0
  153. package/src/toolbar/buttons/ListButtons.tsx +137 -0
  154. package/src/toolbar/buttons/ToolbarButtons.tsx +186 -0
  155. package/src/utils/SimpleLogger.tsx +46 -0
  156. package/src/utils/enumToChoices.tsx +3 -0
  157. package/src/utils/evalActionPermission.tsx +14 -0
  158. package/src/utils/groupByTabs.tsx +23 -0
  159. package/src/utils/hashedGroupByTabs.tsx +16 -0
  160. package/src/utils/invertMap.tsx +10 -0
  161. package/src/utils/isClassComponent.tsx +9 -0
  162. package/src/utils/isComponent.tsx +45 -0
  163. package/src/utils/isEnum.tsx +3 -0
  164. package/src/utils/isFC.tsx +6 -0
  165. package/src/utils/replaceParams.tsx +6 -0
  166. package/src/utils/validate.tsx +24 -0
  167. package/src/wrappers/UserAction.tsx +67 -0
  168. package/src/wrappers/index.tsx +1 -0
  169. /package/{dist → src}/DashAutoAdminSaveButton.tsx.bkup +0 -0
  170. /package/{dist/DashAutoFormLayout.tsx.review → src/DashAutoFormLayout.tsx} +0 -0
  171. /package/{dist → src}/DashAutoFormTabs.review +0 -0
  172. /package/{dist → src}/DashAutoFormTabs.tsx.formcontext.wip +0 -0
  173. /package/{dist → src}/mui/AttributeToField.tsx.review +0 -0
  174. /package/{dist → src}/mui/AttributeToInput.tsx.review +0 -0
  175. /package/{dist → src}/react-admin.d.ts +0 -0
  176. /package/{dist → src}/types/ActionCallback.d.ts +0 -0
@@ -1 +1,630 @@
1
- import{Fragment as fe,jsx as r,jsxs as A}from"react/jsx-runtime";import{createElement as v}from"react";import{ArrayInput as L,ImageInput as W,FileInput as k,BooleanInput as U,DateInput as J,DateTimeInput as M,NumberInput as X,SelectArrayInput as D,SelectInput as C,ChipField as $,ImageField as q,PasswordInput as x,ReferenceArrayInput as T,ReferenceInput as S,SimpleFormIterator as K,SingleFieldList as V,TextInput as E,useRecordContext as j}from"react-admin";import{ErrorMessage as z}from"@hookform/error-message";import{InputAdornment as H,InputLabel as Q,Typography as Y}from"@mui/material";import Z from"@mui/icons-material/Visibility";import{UserAction as ee}from"../wrappers";import{FunctionField as re}from"react-admin";import{FileField as te}from"react-admin";import oe from"react";import R from"../utils/enumToChoices";import w from"../utils/isEnum";import{useLocation as ae,useParams as le}from"react-router";import N from"../utils/replaceParams";import{useEditContext as se}from"react-admin";import{useFormContext as ne}from"react-hook-form";import{useComponentRegistry as ce}from"../DashAutoAdminComponentRegistry";const s=({index:d,method:n,input:e,children:t,...l})=>{const y=e?.sortable===!0,{formState:{errors:g}}=ne();return n==="edit"?A("div",{className:`auto-admin-field auto-admin-field-${n}`,children:[r(re,{label:e?.label||e.attribute,sortable:y,...y&&{sortBy:e.listAttribute||e.attribute},render:o=>oe.cloneElement(t,{record:o})}),!e?.hideErrorMessage||e?.custom&&r(z,{errors:g,name:e.attribute,render:o=>o?r(Y,{className:"dash-admin-field-error",color:"error",children:typeof o.message=="string"?o.message:typeof o.message?.message=="string"?o.message?.message:JSON.stringify(o)}):null})]},d):r("div",{className:`auto-admin-field auto-admin-field-${n}`,children:t},d)},de=()=>{try{return se()}catch{return null}},me=()=>{try{return j()}catch{return null}},ie=(d,n)=>{const e=de(),t=me();return d==="edit"||n==="edit"?e:t},O=(d,n,e,t,l)=>{const{components:g}=ce(),o=l?.mode||"view",f=ie(d,l?.mode),P=ae(),F=le(),B=a=>{const m=g[a];return m?{custom:!0,type:"component",component:m}:{custom:!0,type:"component",component:()=>A(fe,{children:["No component for ",a]})}},I=n?.fieldWrapper&&typeof n.fieldWrapper=="function"?n.fieldWrapper:({_record:a,_method:m,_attribute:b,_resourceConfig:h,children:p})=>p;if(typeof e.type=="string"&&!e.type.includes(".")&&!Array.isArray(e.type))switch(e.type){case"string":case"text":case"String":e.type=String,e.slotProps={fullWidth:e?.fieldProps?.fullWidth??!0};break;case"textarea":e.type=String,e.multiple=!0,e.slotProps={fullWidth:e?.fieldProps?.fullWidth??!0},e.fieldProps={...e.fieldProps||{},multiline:e?.fieldProps?.multiline??!0,rows:e?.fieldProps?.rows??4};break;case"number":case"Number":case"integer":e.type=Number;break;case"boolean":case"Boolean":e.type=Boolean;break;case"date":case"Date":e.type=Date;break;default:if(e.custom=!0,typeof e?.component=="string"){const a=B(e.component);e={...e,...a}}}if(l&&l.useReadOnlyInputAsTextField&&e.readOnly)return r(s,{index:t,method:o,input:e,children:r(I,{label:e.label,source:e.listAttribute||e.attribute,...f&&{record:f},method:d,attribute:e,resourceConfig:n,children:v(E,{fullWidth:!0,...f&&{record:f},key:t,label:e.label,source:e.listAttribute||e.attribute,...e.fieldProps,editable:!1,InputProps:{readOnly:!0,endAdornment:r(H,{position:"start",children:r(Z,{})})}})},t)});if(l&&l.readOnlyComponent&&e.readOnly)return r(s,{index:t,method:o,input:e,children:v(I,{...f&&{record:f},method:d,attribute:e,key:t,label:e.label,source:e.listAttribute||e.attribute,resourceConfig:n},r(l.readOnlyComponent,{fullWidth:!0,...f&&{record:f},input:e,label:e.label,source:e.listAttribute||e.attribute,...e.fieldProps,editable:!1,InputProps:{readOnly:!0}},t))});if(e.label||(e.label=e.attribute),e.custom&&e.component||e.type==="component"&&e.component)return r(s,{index:t,method:o,input:e,children:r(ee,{record:f,method:o,attribute:e,resourceConfig:n},t)});if(Array.isArray(e.type)&&e.type.length>0){const a=e.type[0];if(w(a))return r(s,{index:t,method:o,input:e,children:r(D,{fullWidth:!0,label:e.label,source:e.attribute,choices:R(a),...e?.fieldProps,onChange:m=>{l?.handleChange&&l.handleChange(m),e.fieldProps?.onChange&&e.fieldProps.onChange(m)}},t)});if(typeof a=="string"){const m={...F,...(P.hash.match(/\d+/g)||[]).map(Number).reduce((c,u,G)=>(c[G]=u,c),{})},b=N(m,a),[h,p]=b.split("."),i=c=>(c?c[p]:"?")||"??";if(e&&e.multiple===!1&&e.component){const c=e.component;return r(s,{index:t,method:o,input:e,children:r(S,{fullWidth:!0,allowEmpty:!0,filter:!0,pagination:!1,label:e.label,reference:h,source:e.attribute,...e.componentProps,children:r(c,{optionText:i,method:d,attribute:e,onChange:u=>{l?.handleChange&&l.handleChange(u),e.fieldProps?.onChange&&e.fieldProps.onChange(u)},resourceConfig:n})},t)})}return r(s,{index:t,method:o,input:e,children:r(T,{fullWidth:!0,filter:!0,pagination:!1,label:e.label,reference:h,source:e.attribute,...e.componentProps,children:r(V,{...e.fieldProps,children:r($,{source:p})})},t)})}else{const m=e.type;return r(s,{index:t,method:o,input:e,children:r(L,{label:e.label,source:e.attribute,...e.componentProps,children:r(K,{children:m.map((b,h)=>O(d,n,b,h))})},t)})}}if(e&&e.type===W)return r(s,{index:t,method:o,input:e,children:r(W,{placeholder:"Arr\xE1stre una im\xE1gen o haga click aqu\xED para seleccionar",source:e.attribute,label:e.label,accept:"image/*",...e.fieldProps,children:r(q,{source:"src",title:"title"})},t)});if(e&&e.type===k&&(k,{source:e.attribute,label:e.label,...e.fieldProps,children:te}),typeof e.type=="string"){if(e.type==="select"&&Array.isArray(e.options)&&e.options.length>0){const i=e.options.map(c=>({id:c.id,name:c.name}));return r(s,{index:t,method:o,input:e,children:r(C,{fullWidth:!0,label:e.label,source:e.listAttribute||e.attribute,choices:i,...e.fieldProps,onChange:c=>{l?.handleChange&&l.handleChange(c),e.fieldProps?.onChange&&e.fieldProps.onChange(c)},...e.componentProps},t)})}if(e.type==="select"&&(!e.options||e.options.length===0))return console.warn(`Select field "${e.attribute}" has no options defined. Skipping render.`),null;const a={...F,...(P.pathname.match(/\d+/g)||[]).map(Number).reduce((i,c,u)=>(i[u]=c,i),{})},m=N(a,e.type),[b,h]=m.split("."),p=e.component||C;return e&&e.multiple===!1?r(s,{index:t,method:o,input:e,children:r(S,{allowEmpty:!0,filters:!0,label:e.label,source:e.listAttribute||e.attribute,reference:b,sort:{field:h,order:"ASC"},...e.componentProps,children:r(p,{optionText:h,method:d,attribute:e,label:e?.label||"",...e.fieldProps,onChange:i=>{l?.handleChange&&l.handleChange(i),e.fieldProps?.onChange&&e.fieldProps.onChange(i)},resourceConfig:n})},t)}):r(s,{index:t,method:o,input:e,children:r(T,{reference:b,source:e.listAttribute||e.attribute,...e.componentProps,children:r(D,{optionText:h,fullWidth:!0,label:e?.label||"",...e.fieldProps,onChange:i=>{l?.handleChange&&l.handleChange(i),e.fieldProps?.onChange&&e.fieldProps.onChange(i)}})},t)})}switch(e.type){case Number:return r(s,{index:t,method:o,input:e,children:r(X,{fullWidth:!0,label:e.label,source:e.attribute,...e.fieldProps,onChange:a=>{l?.handleChange&&l.handleChange(a),e.fieldProps?.onChange&&e.fieldProps.onChange(a)}},t)});case Boolean:return r(s,{index:t,method:o,input:e,children:A("div",{children:[e?.showLabel!==!1&&r(Q,{htmlFor:e.listAttribute||e.attribute,children:e.label}),r(U,{record:f,id:e.listAttribute||e.attribute,label:e.label,source:e.listAttribute||e.attribute,...e.fieldProps,onChange:a=>{l?.handleChange&&l.handleChange(a),e.fieldProps?.onChange&&e.fieldProps.onChange(a)}},t)]})});case Date:return e.fieldProps&&e.fieldProps.showTime?r(s,{index:t,method:o,input:e,children:r(M,{label:e.label,source:e.attribute,...e.fieldProps},t)}):r(s,{index:t,method:o,input:e,children:r(J,{label:e.label,source:e.attribute,...e.fieldProps,onChange:a=>{l?.handleChange&&l.handleChange(a),e.fieldProps?.onChange&&e.fieldProps.onChange(a)}},t)})}if(w(e.type))return r(s,{index:t,method:o,input:e,children:r(C,{label:e.label,source:e.attribute,choices:R(e.type),InputProps:e.fieldOptions,onChange:a=>{l?.handleChange&&l.handleChange(a),e.fieldProps?.onChange&&e.fieldProps.onChange(a)}},t)});if(e.isPassword){const a={key:t,label:e.label,source:e.attribute,...e.slotProps?{slotProps:e.slotProps}:{}};return r(s,{index:t,method:o,input:e,children:r(x,{...a})})}const _={label:e.label,source:e.listAttribute||e.attribute,...e.fieldProps,...e.slotProps?{slotProps:e.slotProps}:{},onChange:a=>{l?.handleChange&&l.handleChange(a),e.fieldProps?.onChange&&e.fieldProps.onChange(a)}};return r(s,{index:t,method:o,input:e,children:r(E,{..._})})};var Me=O;export{Me as default};
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
33
+ import { createElement } from "react";
34
+ import {
35
+ ArrayInput,
36
+ ImageInput,
37
+ FileInput,
38
+ BooleanInput,
39
+ DateInput,
40
+ DateTimeInput,
41
+ NumberInput,
42
+ SelectArrayInput,
43
+ SelectInput,
44
+ ChipField,
45
+ ImageField,
46
+ PasswordInput,
47
+ ReferenceArrayInput,
48
+ ReferenceInput,
49
+ SimpleFormIterator,
50
+ SingleFieldList,
51
+ TextInput,
52
+ useRecordContext
53
+ } from "react-admin";
54
+ import { ErrorMessage } from "@hookform/error-message";
55
+ import { InputAdornment, InputLabel, Typography } from "@mui/material";
56
+ import Visibility from "@mui/icons-material/Visibility";
57
+ import { UserAction } from "../wrappers";
58
+ import { FunctionField } from "react-admin";
59
+ import { FileField } from "react-admin";
60
+ import React from "react";
61
+ import enumToChoices from "../utils/enumToChoices";
62
+ import isEnum from "../utils/isEnum";
63
+ import { useLocation, useParams } from "react-router";
64
+ import replaceParams from "../utils/replaceParams";
65
+ import { useEditContext } from "react-admin";
66
+ import { useFormContext } from "react-hook-form";
67
+ import { useComponentRegistry } from "../DashAutoAdminComponentRegistry";
68
+ const FunctionFieldWrapper = (_a) => {
69
+ var _b = _a, {
70
+ index,
71
+ method,
72
+ input,
73
+ children
74
+ } = _b, _props = __objRest(_b, [
75
+ "index",
76
+ "method",
77
+ "input",
78
+ "children"
79
+ ]);
80
+ const sortable = (input == null ? void 0 : input.sortable) === true ? true : false;
81
+ const {
82
+ formState: { errors }
83
+ } = useFormContext();
84
+ if (method === "edit") {
85
+ return /* @__PURE__ */ jsxs(
86
+ "div",
87
+ {
88
+ className: `auto-admin-field auto-admin-field-${method}`,
89
+ children: [
90
+ /* @__PURE__ */ jsx(
91
+ FunctionField,
92
+ __spreadProps(__spreadValues({
93
+ label: (input == null ? void 0 : input.label) || input.attribute,
94
+ sortable
95
+ }, sortable && { sortBy: input.listAttribute || input.attribute }), {
96
+ render: (record) => {
97
+ return React.cloneElement(children, { record });
98
+ }
99
+ })
100
+ ),
101
+ !(input == null ? void 0 : input.hideErrorMessage) || (input == null ? void 0 : input.custom) && /* @__PURE__ */ jsx(
102
+ ErrorMessage,
103
+ {
104
+ errors,
105
+ name: input.attribute,
106
+ render: (error) => {
107
+ var _a2, _b2;
108
+ return error ? /* @__PURE__ */ jsx(Typography, { className: "dash-admin-field-error", color: "error", children: typeof error.message === "string" ? error.message : typeof ((_a2 = error.message) == null ? void 0 : _a2.message) === "string" ? (_b2 = error.message) == null ? void 0 : _b2.message : JSON.stringify(error) }) : null;
109
+ }
110
+ }
111
+ )
112
+ ]
113
+ },
114
+ index
115
+ );
116
+ }
117
+ return /* @__PURE__ */ jsx("div", { className: `auto-admin-field auto-admin-field-${method}`, children }, index);
118
+ };
119
+ const useSafeEditContext = () => {
120
+ try {
121
+ return useEditContext();
122
+ } catch (error) {
123
+ return null;
124
+ }
125
+ };
126
+ const useSafeRecordContext = () => {
127
+ try {
128
+ return useRecordContext();
129
+ } catch (error) {
130
+ return null;
131
+ }
132
+ };
133
+ const useRecordByMethod = (method, mode) => {
134
+ const editContext = useSafeEditContext();
135
+ const recordContext = useSafeRecordContext();
136
+ if (method === "edit" || mode === "edit") {
137
+ return editContext;
138
+ }
139
+ return recordContext;
140
+ };
141
+ const AttributeToInput = (method, resourceConfig, input, index, options) => {
142
+ var _a, _b, _c, _d, _e, _f, _g, _h;
143
+ const DEBUG = false;
144
+ const { components } = useComponentRegistry();
145
+ const mode = (options == null ? void 0 : options.mode) || "view";
146
+ const record = useRecordByMethod(method, options == null ? void 0 : options.mode);
147
+ const location = useLocation();
148
+ const params = useParams();
149
+ const typeComponentMapper = (type) => {
150
+ const component = components[type];
151
+ if (component) {
152
+ return { custom: true, type: "component", component };
153
+ }
154
+ return { custom: true, type: "component", component: () => /* @__PURE__ */ jsxs(Fragment, { children: [
155
+ "No component for ",
156
+ type
157
+ ] }) };
158
+ };
159
+ const ComponentWrapper = (resourceConfig == null ? void 0 : resourceConfig.fieldWrapper) && typeof resourceConfig.fieldWrapper === "function" ? resourceConfig.fieldWrapper : ({
160
+ _record,
161
+ _method,
162
+ _attribute,
163
+ _resourceConfig,
164
+ children
165
+ }) => children;
166
+ if (typeof input.type === "string" && !input.type.includes(".") && !Array.isArray(input.type)) {
167
+ switch (input.type) {
168
+ case "string":
169
+ case "text":
170
+ case "String":
171
+ input.type = String;
172
+ input.slotProps = {
173
+ fullWidth: (_b = (_a = input == null ? void 0 : input.fieldProps) == null ? void 0 : _a.fullWidth) != null ? _b : true
174
+ };
175
+ break;
176
+ case "textarea":
177
+ input.type = String;
178
+ input.multiple = true;
179
+ input.slotProps = {
180
+ fullWidth: (_d = (_c = input == null ? void 0 : input.fieldProps) == null ? void 0 : _c.fullWidth) != null ? _d : true
181
+ };
182
+ input.fieldProps = __spreadProps(__spreadValues({}, input.fieldProps || {}), {
183
+ multiline: (_f = (_e = input == null ? void 0 : input.fieldProps) == null ? void 0 : _e.multiline) != null ? _f : true,
184
+ rows: (_h = (_g = input == null ? void 0 : input.fieldProps) == null ? void 0 : _g.rows) != null ? _h : 4
185
+ });
186
+ break;
187
+ case "number":
188
+ case "Number":
189
+ case "integer":
190
+ input.type = Number;
191
+ break;
192
+ case "boolean":
193
+ case "Boolean":
194
+ input.type = Boolean;
195
+ break;
196
+ case "date":
197
+ case "Date":
198
+ input.type = Date;
199
+ break;
200
+ case "custom":
201
+ default:
202
+ input.custom = true;
203
+ DEBUG && console.log("\u{1F527} AttributeToInput - custom type detected, input.component:", input == null ? void 0 : input.component);
204
+ DEBUG && console.log("\u{1F527} AttributeToInput - components available:", Object.keys(components));
205
+ if (typeof (input == null ? void 0 : input.component) === "string") {
206
+ const mappedResult = typeComponentMapper(input.component);
207
+ DEBUG && console.log("\u{1F527} AttributeToInput - typeComponentMapper result:", mappedResult);
208
+ input = __spreadValues(__spreadValues({}, input), mappedResult);
209
+ DEBUG && console.log("\u{1F527} AttributeToInput - after merge, input.component:", input.component);
210
+ }
211
+ }
212
+ }
213
+ if (options && options.useReadOnlyInputAsTextField && input.readOnly) {
214
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
215
+ ComponentWrapper,
216
+ __spreadProps(__spreadValues({
217
+ label: input.label,
218
+ source: input.listAttribute || input.attribute
219
+ }, record && { record }), {
220
+ method,
221
+ attribute: input,
222
+ resourceConfig,
223
+ children: /* @__PURE__ */ createElement(
224
+ TextInput,
225
+ __spreadValues(__spreadProps(__spreadValues({
226
+ fullWidth: true
227
+ }, record && { record }), {
228
+ key: index,
229
+ label: input.label,
230
+ source: input.listAttribute || input.attribute
231
+ }), __spreadProps(__spreadValues({}, input.fieldProps), {
232
+ editable: false,
233
+ InputProps: {
234
+ readOnly: true,
235
+ endAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(Visibility, {}) })
236
+ }
237
+ }))
238
+ )
239
+ }),
240
+ index
241
+ ) });
242
+ } else if (options && options.readOnlyComponent && input.readOnly) {
243
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ createElement(
244
+ ComponentWrapper,
245
+ __spreadProps(__spreadValues({}, record && { record }), {
246
+ method,
247
+ attribute: input,
248
+ key: index,
249
+ label: input.label,
250
+ source: input.listAttribute || input.attribute,
251
+ resourceConfig
252
+ }),
253
+ /* @__PURE__ */ jsx(
254
+ options.readOnlyComponent,
255
+ __spreadValues(__spreadProps(__spreadValues({
256
+ fullWidth: true
257
+ }, record && { record }), {
258
+ input,
259
+ label: input.label,
260
+ source: input.listAttribute || input.attribute
261
+ }), __spreadProps(__spreadValues({}, input.fieldProps), {
262
+ editable: false,
263
+ InputProps: { readOnly: true }
264
+ })),
265
+ index
266
+ )
267
+ ) });
268
+ }
269
+ if (!input.label) input.label = input.attribute;
270
+ if (input.custom && input.component || input.type === "component" && input.component) {
271
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
272
+ UserAction,
273
+ {
274
+ record,
275
+ method: mode,
276
+ attribute: input,
277
+ resourceConfig
278
+ },
279
+ index
280
+ ) });
281
+ }
282
+ if (Array.isArray(input.type) && input.type.length > 0) {
283
+ const inputType = input.type[0];
284
+ if (isEnum(inputType)) {
285
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
286
+ SelectArrayInput,
287
+ __spreadProps(__spreadValues({
288
+ fullWidth: true,
289
+ label: input.label,
290
+ source: input.attribute,
291
+ choices: enumToChoices(inputType)
292
+ }, input == null ? void 0 : input.fieldProps), {
293
+ onChange: (e) => {
294
+ var _a2;
295
+ if (options == null ? void 0 : options.handleChange) {
296
+ options.handleChange(e);
297
+ }
298
+ if ((_a2 = input.fieldProps) == null ? void 0 : _a2.onChange) {
299
+ input.fieldProps.onChange(e);
300
+ }
301
+ }
302
+ }),
303
+ index
304
+ ) });
305
+ }
306
+ if (typeof inputType === "string") {
307
+ const _params = __spreadValues(__spreadValues({}, params), (location.hash.match(/\d+/g) || []).map(Number).reduce((acc, curr, currentIndex) => {
308
+ acc[currentIndex] = curr;
309
+ return acc;
310
+ }, {}));
311
+ const _inputType = replaceParams(_params, inputType);
312
+ const [reference, sourceName] = _inputType.split(".");
313
+ const safeIfNull = (choice) => (choice ? choice[sourceName] : "?") || "??";
314
+ if (input && input.multiple === false && input.component) {
315
+ const CustomComponent = input.component;
316
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
317
+ ReferenceInput,
318
+ __spreadProps(__spreadValues({
319
+ fullWidth: true,
320
+ allowEmpty: true,
321
+ filter: true,
322
+ pagination: false,
323
+ label: input.label,
324
+ reference,
325
+ source: input.attribute
326
+ }, input.componentProps), {
327
+ children: /* @__PURE__ */ jsx(
328
+ CustomComponent,
329
+ {
330
+ optionText: safeIfNull,
331
+ method,
332
+ attribute: input,
333
+ onChange: (e) => {
334
+ var _a2;
335
+ if (options == null ? void 0 : options.handleChange) {
336
+ options.handleChange(e);
337
+ }
338
+ if ((_a2 = input.fieldProps) == null ? void 0 : _a2.onChange) {
339
+ input.fieldProps.onChange(e);
340
+ }
341
+ },
342
+ resourceConfig
343
+ }
344
+ )
345
+ }),
346
+ index
347
+ ) });
348
+ }
349
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
350
+ ReferenceArrayInput,
351
+ __spreadProps(__spreadValues({
352
+ fullWidth: true,
353
+ filter: true,
354
+ pagination: false,
355
+ label: input.label,
356
+ reference,
357
+ source: input.attribute
358
+ }, input.componentProps), {
359
+ children: /* @__PURE__ */ jsx(SingleFieldList, __spreadProps(__spreadValues({}, input.fieldProps), { children: /* @__PURE__ */ jsx(ChipField, { source: sourceName }) }))
360
+ }),
361
+ index
362
+ ) });
363
+ } else {
364
+ const inputTypeArray = input.type;
365
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
366
+ ArrayInput,
367
+ __spreadProps(__spreadValues({
368
+ label: input.label,
369
+ source: input.attribute
370
+ }, input.componentProps), {
371
+ children: /* @__PURE__ */ jsx(SimpleFormIterator, { children: inputTypeArray.map(
372
+ (attribute, idx) => AttributeToInput(method, resourceConfig, attribute, idx)
373
+ ) })
374
+ }),
375
+ index
376
+ ) });
377
+ }
378
+ }
379
+ if (input && input.type === ImageInput) {
380
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
381
+ ImageInput,
382
+ __spreadProps(__spreadValues({
383
+ placeholder: "Arr\xE1stre una im\xE1gen o haga click aqu\xED para seleccionar",
384
+ source: input.attribute,
385
+ label: input.label,
386
+ accept: "image/*"
387
+ }, input.fieldProps), {
388
+ children: /* @__PURE__ */ jsx(ImageField, { source: "src", title: "title" })
389
+ }),
390
+ index
391
+ ) });
392
+ }
393
+ if (input && input.type === FileInput) {
394
+ /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
395
+ FileInput,
396
+ __spreadProps(__spreadValues({
397
+ placeholder: "Arr\xE1stre un archivo o haga click aqu\xED para seleccionar",
398
+ source: input.attribute,
399
+ label: input.label
400
+ }, input.fieldProps), {
401
+ children: /* @__PURE__ */ jsx(FileField, { source: "src", title: "title" })
402
+ }),
403
+ index
404
+ ) });
405
+ }
406
+ if (typeof input.type === "string") {
407
+ if (input.type === "select" && Array.isArray(input.options) && input.options.length > 0) {
408
+ const choices = input.options.map((opt) => ({
409
+ id: opt.id,
410
+ name: opt.name
411
+ }));
412
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
413
+ SelectInput,
414
+ __spreadValues(__spreadProps(__spreadValues({
415
+ fullWidth: true,
416
+ label: input.label,
417
+ source: input.listAttribute || input.attribute,
418
+ choices
419
+ }, input.fieldProps), {
420
+ onChange: (e) => {
421
+ var _a2;
422
+ if (options == null ? void 0 : options.handleChange) {
423
+ options.handleChange(e);
424
+ }
425
+ if ((_a2 = input.fieldProps) == null ? void 0 : _a2.onChange) {
426
+ input.fieldProps.onChange(e);
427
+ }
428
+ }
429
+ }), input.componentProps),
430
+ index
431
+ ) });
432
+ }
433
+ if (input.type === "select" && (!input.options || input.options.length === 0)) {
434
+ console.warn(`Select field "${input.attribute}" has no options defined. Skipping render.`);
435
+ return null;
436
+ }
437
+ const _params = __spreadValues(__spreadValues({}, params), (location.pathname.match(/\d+/g) || []).map(Number).reduce((acc, curr, currentIndex) => {
438
+ acc[currentIndex] = curr;
439
+ return acc;
440
+ }, {}));
441
+ const _inputType = replaceParams(_params, input.type);
442
+ const [reference, sourceName] = _inputType.split(".");
443
+ const CustomComponent = input.component || SelectInput;
444
+ if (input && input.multiple === false) {
445
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
446
+ ReferenceInput,
447
+ __spreadProps(__spreadValues({
448
+ allowEmpty: true,
449
+ filters: true,
450
+ label: input.label,
451
+ source: input.listAttribute || input.attribute,
452
+ reference,
453
+ sort: { field: sourceName, order: "ASC" }
454
+ }, input.componentProps), {
455
+ children: /* @__PURE__ */ jsx(
456
+ CustomComponent,
457
+ __spreadProps(__spreadValues({
458
+ optionText: sourceName,
459
+ method,
460
+ attribute: input,
461
+ label: (input == null ? void 0 : input.label) || ""
462
+ }, input.fieldProps), {
463
+ onChange: (e) => {
464
+ var _a2;
465
+ if (options == null ? void 0 : options.handleChange) {
466
+ options.handleChange(e);
467
+ }
468
+ if ((_a2 = input.fieldProps) == null ? void 0 : _a2.onChange) {
469
+ input.fieldProps.onChange(e);
470
+ }
471
+ },
472
+ resourceConfig
473
+ })
474
+ )
475
+ }),
476
+ index
477
+ ) });
478
+ }
479
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
480
+ ReferenceArrayInput,
481
+ __spreadProps(__spreadValues({
482
+ reference,
483
+ source: input.listAttribute || input.attribute
484
+ }, input.componentProps), {
485
+ children: /* @__PURE__ */ jsx(
486
+ SelectArrayInput,
487
+ __spreadProps(__spreadValues({
488
+ optionText: sourceName,
489
+ fullWidth: true,
490
+ label: (input == null ? void 0 : input.label) || ""
491
+ }, input.fieldProps), {
492
+ onChange: (e) => {
493
+ var _a2;
494
+ if (options == null ? void 0 : options.handleChange) {
495
+ options.handleChange(e);
496
+ }
497
+ if ((_a2 = input.fieldProps) == null ? void 0 : _a2.onChange) {
498
+ input.fieldProps.onChange(e);
499
+ }
500
+ }
501
+ })
502
+ )
503
+ }),
504
+ index
505
+ ) });
506
+ }
507
+ switch (input.type) {
508
+ case Number:
509
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
510
+ NumberInput,
511
+ __spreadProps(__spreadValues({
512
+ fullWidth: true,
513
+ label: input.label,
514
+ source: input.attribute
515
+ }, input.fieldProps), {
516
+ onChange: (e) => {
517
+ var _a2;
518
+ if (options == null ? void 0 : options.handleChange) {
519
+ options.handleChange(e);
520
+ }
521
+ if ((_a2 = input.fieldProps) == null ? void 0 : _a2.onChange) {
522
+ input.fieldProps.onChange(e);
523
+ }
524
+ }
525
+ }),
526
+ index
527
+ ) });
528
+ case Boolean:
529
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsxs("div", { children: [
530
+ (input == null ? void 0 : input.showLabel) !== false && /* @__PURE__ */ jsx(InputLabel, { htmlFor: input.listAttribute || input.attribute, children: input.label }),
531
+ /* @__PURE__ */ jsx(
532
+ BooleanInput,
533
+ __spreadProps(__spreadValues({
534
+ record,
535
+ id: input.listAttribute || input.attribute,
536
+ label: input.label,
537
+ source: input.listAttribute || input.attribute
538
+ }, input.fieldProps), {
539
+ onChange: (e) => {
540
+ var _a2;
541
+ if (options == null ? void 0 : options.handleChange) {
542
+ options.handleChange(e);
543
+ }
544
+ if ((_a2 = input.fieldProps) == null ? void 0 : _a2.onChange) {
545
+ input.fieldProps.onChange(e);
546
+ }
547
+ }
548
+ }),
549
+ index
550
+ )
551
+ ] }) });
552
+ case Date:
553
+ return input.fieldProps && input.fieldProps.showTime ? /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
554
+ DateTimeInput,
555
+ __spreadValues({
556
+ label: input.label,
557
+ source: input.attribute
558
+ }, input.fieldProps),
559
+ index
560
+ ) }) : /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
561
+ DateInput,
562
+ __spreadProps(__spreadValues({
563
+ label: input.label,
564
+ source: input.attribute
565
+ }, input.fieldProps), {
566
+ onChange: (e) => {
567
+ var _a2;
568
+ if (options == null ? void 0 : options.handleChange) {
569
+ options.handleChange(e);
570
+ }
571
+ if ((_a2 = input.fieldProps) == null ? void 0 : _a2.onChange) {
572
+ input.fieldProps.onChange(e);
573
+ }
574
+ }
575
+ }),
576
+ index
577
+ ) });
578
+ }
579
+ if (isEnum(input.type)) {
580
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
581
+ SelectInput,
582
+ {
583
+ label: input.label,
584
+ source: input.attribute,
585
+ choices: enumToChoices(input.type),
586
+ InputProps: input.fieldOptions,
587
+ onChange: (e) => {
588
+ var _a2;
589
+ if (options == null ? void 0 : options.handleChange) {
590
+ options.handleChange(e);
591
+ }
592
+ if ((_a2 = input.fieldProps) == null ? void 0 : _a2.onChange) {
593
+ input.fieldProps.onChange(e);
594
+ }
595
+ }
596
+ },
597
+ index
598
+ ) });
599
+ }
600
+ if (input.isPassword) {
601
+ const passwordProps = __spreadValues({
602
+ key: index,
603
+ label: input.label,
604
+ source: input.attribute
605
+ }, input.slotProps ? { slotProps: input.slotProps } : {});
606
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(PasswordInput, __spreadValues({}, passwordProps)) });
607
+ }
608
+ const textFieldProps = __spreadProps(__spreadValues(__spreadValues({
609
+ label: input.label,
610
+ source: input.listAttribute || input.attribute
611
+ }, input.fieldProps), input.slotProps ? { slotProps: input.slotProps } : {}), {
612
+ onChange: (e) => {
613
+ var _a2;
614
+ if (options == null ? void 0 : options.handleChange) {
615
+ options.handleChange(e);
616
+ }
617
+ if ((_a2 = input.fieldProps) == null ? void 0 : _a2.onChange) {
618
+ input.fieldProps.onChange(e);
619
+ }
620
+ }
621
+ });
622
+ return /* @__PURE__ */ jsx(FunctionFieldWrapper, { index, method: mode, input, children: /* @__PURE__ */ jsx(
623
+ TextInput,
624
+ __spreadValues({}, textFieldProps)
625
+ ) });
626
+ };
627
+ var AttributeToInput_default = AttributeToInput;
628
+ export {
629
+ AttributeToInput_default as default
630
+ };