@dashadmin/dash-components 1.3.25 → 1.3.28

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 (112) hide show
  1. package/README.md +35 -0
  2. package/dist/components/AuditLog/AuditLog.js +345 -1
  3. package/dist/components/AuditLog/index.js +4 -1
  4. package/dist/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.js +630 -3
  5. package/dist/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.js +53 -1
  6. package/dist/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.js +647 -3
  7. package/dist/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.js +53 -1
  8. package/dist/components/Json/Json.js +235 -1
  9. package/dist/components/JsonColorSelector/JsonColorSelector.js +1172 -1
  10. package/dist/components/JsonColorSelector/JsonColorSelectorEnhanced.js +863 -2
  11. package/dist/components/JsonColorSelector/JsonCssVarValues.js +738 -1
  12. package/dist/components/JsonColorSelector/components/ColorEditDialog.js +426 -1
  13. package/dist/components/JsonColorSelector/components/ColorPaletteItem.js +75 -1
  14. package/dist/components/JsonColorSelector/components/ImageColorExtractor.js +283 -1
  15. package/dist/components/JsonColorSelector/helpers/functions.js +101 -1
  16. package/dist/components/JsonColorSelector/useAsyncColorThief.js +105 -1
  17. package/dist/components/ListActive/ListActive.js +126 -1
  18. package/dist/components/ListActive/ListBoolean.js +124 -1
  19. package/dist/components/NotificationPreferences/NotificationPreferences.js +317 -1
  20. package/dist/components/NotificationPreferences/index.js +7 -1
  21. package/dist/components/SearchableSelects/RASearchableSelect.js +236 -1
  22. package/dist/components/SearchableSelects/RASearchableSelectCheckboxes.js +479 -1
  23. package/dist/components/SearchableSelects/RASearchableSelectChips.js +465 -1
  24. package/dist/components/SearchableSelects/RASearchableSelectChipsRecordContext.js +295 -1
  25. package/dist/components/SearchableSelects/SearchableSelect.js +202 -1
  26. package/dist/components/SearchableSelects/SearchableSelectCheckboxes.js +290 -1
  27. package/dist/components/SortableDataGrid/SortableDataGrid.js +72 -1
  28. package/dist/components/SortableDataGrid/SortableDataGridBody.js +167 -1
  29. package/dist/components/SortableDataGrid/SortableDataGridHeader.js +109 -1
  30. package/dist/components/SortableDataGrid/SortableDataGridRow.js +283 -1
  31. package/dist/components/Upload/SingleImageUploader.js +40 -1
  32. package/dist/components/custom/PackageCopyMethod.js +78 -1
  33. package/dist/components/custom/PackageRadioButtonGroup.js +45 -1
  34. package/dist/components/dialog/Basic.js +8 -1
  35. package/dist/components/dialog/Correct.js +14 -1
  36. package/dist/components/dialog/Error.js +14 -1
  37. package/dist/components/dialog/Info.js +14 -1
  38. package/dist/components/dialog/InfoV2.js +21 -1
  39. package/dist/components/dialog/NotFound.js +14 -1
  40. package/dist/components/dialog/QuickSearch.js +117 -1
  41. package/dist/components/notifications/NotificationsCenter.js +597 -1
  42. package/dist/components/notifications/index.js +24 -1
  43. package/dist/components/tables/PaginationComponent.js +36 -1
  44. package/dist/components/theme/AppLoadingFallback.js +38 -2
  45. package/dist/components/theme/ErrorBoundary.js +52 -1
  46. package/dist/components/theme/InitialLoader.js +13 -1
  47. package/dist/components/theme/NotFound.js +136 -1
  48. package/dist/components/theme/NotResults.js +38 -1
  49. package/dist/hooks/useDraggable.js +6 -1
  50. package/dist/hooks/useNotifications.js +8 -1
  51. package/dist/hooks/useQuickSearch.js +26 -1
  52. package/dist/index.js +66 -5567
  53. package/dist/utils/setNativeValue.js +17 -1
  54. package/package.json +148 -132
  55. package/src/components/AuditLog/AuditLog.tsx +476 -0
  56. package/src/components/AuditLog/index.ts +2 -0
  57. package/src/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.tsx +917 -0
  58. package/src/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.tsx +39 -0
  59. package/src/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.tsx +916 -0
  60. package/src/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.tsx +44 -0
  61. package/src/components/Json/Json.tsx +312 -0
  62. package/src/components/JsonColorSelector/JsonColorSelector.tsx +1435 -0
  63. package/src/components/JsonColorSelector/JsonColorSelectorEnhanced.tsx +1029 -0
  64. package/src/components/JsonColorSelector/JsonCssVarValues.tsx +863 -0
  65. package/src/components/JsonColorSelector/components/ColorEditDialog.tsx +491 -0
  66. package/src/components/JsonColorSelector/components/ColorPaletteItem.tsx +80 -0
  67. package/src/components/JsonColorSelector/components/ImageColorExtractor.tsx +328 -0
  68. package/src/components/JsonColorSelector/helpers/functions.tsx +123 -0
  69. package/src/components/JsonColorSelector/interfaces/interfaces.tsx +22 -0
  70. package/src/components/JsonColorSelector/useAsyncColorThief.tsx +97 -0
  71. package/src/components/ListActive/ListActive.tsx +106 -0
  72. package/src/components/ListActive/ListBoolean.tsx +96 -0
  73. package/src/components/NotificationPreferences/NotificationPreferences.tsx +463 -0
  74. package/src/components/NotificationPreferences/index.tsx +2 -0
  75. package/src/components/SearchableSelects/RASearchableSelect.tsx +300 -0
  76. package/src/components/SearchableSelects/RASearchableSelectCheckboxes.tsx +604 -0
  77. package/src/components/SearchableSelects/RASearchableSelectChips.tsx +558 -0
  78. package/src/components/SearchableSelects/RASearchableSelectChipsRecordContext.tsx +362 -0
  79. package/src/components/SearchableSelects/SearchableSelect.tsx +321 -0
  80. package/src/components/SearchableSelects/SearchableSelectCheckboxes.tsx +355 -0
  81. package/src/components/SortableDataGrid/SortableDataGrid.tsx +56 -0
  82. package/src/components/SortableDataGrid/SortableDataGridBody.tsx +175 -0
  83. package/src/components/SortableDataGrid/SortableDataGridHeader.tsx +171 -0
  84. package/src/components/SortableDataGrid/SortableDataGridRow.tsx +247 -0
  85. package/src/components/Upload/SingleImageUploader.tsx +55 -0
  86. package/src/components/custom/PackageCopyMethod.tsx +109 -0
  87. package/src/components/custom/PackageRadioButtonGroup.tsx +47 -0
  88. package/src/components/dialog/Basic.tsx +11 -0
  89. package/src/components/dialog/Correct.tsx +16 -0
  90. package/src/components/dialog/Error.tsx +15 -0
  91. package/src/components/dialog/Info.tsx +15 -0
  92. package/src/components/dialog/InfoV2.tsx +35 -0
  93. package/src/components/dialog/NotFound.tsx +18 -0
  94. package/src/components/dialog/QuickSearch.tsx +115 -0
  95. package/src/components/notifications/NotificationsCenter.tsx +792 -0
  96. package/src/components/notifications/index.ts +42 -0
  97. package/src/components/tables/PaginationComponent.tsx +17 -0
  98. package/src/components/theme/AppLoadingFallback.tsx +42 -0
  99. package/src/components/theme/ErrorBoundary.tsx +57 -0
  100. package/src/components/theme/InitialLoader.tsx +16 -0
  101. package/src/components/theme/NotFound.tsx +124 -0
  102. package/src/components/theme/NotResults.tsx +54 -0
  103. package/src/hooks/useDraggable.ts +11 -0
  104. package/src/hooks/useNotifications.ts +14 -0
  105. package/src/hooks/useQuickSearch.tsx +29 -0
  106. package/src/index.tsx +77 -0
  107. package/src/utils/setNativeValue.tsx +23 -0
  108. package/dist/color-thief-CTwGFhOB.js +0 -272
  109. /package/{dist → src}/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayAutoSearch.tsx.wip +0 -0
  110. /package/{dist → src}/components/JsonColorSelector/JsonColorSelector.tsx.bkup +0 -0
  111. /package/{dist → src}/components/SortableDataGrid/README.md +0 -0
  112. /package/{dist → src}/styles/index.less +0 -0
@@ -1 +1,479 @@
1
- import{jsx as n,jsxs as p}from"react/jsx-runtime";import{Box as u,Checkbox as G,CircularProgress as ge,TextField as J,Typography as b,Chip as U,List as be,ListItem as z,ListItemButton as X,ListItemIcon as Y,ListItemText as E,Paper as xe,Popper as Se,ClickAwayListener as Ie,InputAdornment as P,IconButton as Z}from"@mui/material";import{useEffect as M,useState as m,useRef as Le}from"react";import{useGetList as Ce}from"react-admin";import{LoadingIndicator as ke}from"react-admin";import Be from"@mui/icons-material/Search";import Te from"@mui/icons-material/Clear";import Ae from"@mui/icons-material/ExpandMore";import Oe from"@mui/icons-material/ExpandLess";const je=({isMultiple:we=!0,searchResults:x=50,minSearch:S=1,minOptions:F=10,timerSearch:K=300,resource:ee,selectLabel:te,renderText:C,transformData:ze=y=>y,queryFilter:ne="q",defaultValues:k=void 0,value:L,onChange:f,isEmpty:Ee=!1,filter:oe,isOptionEqualToValue:Pe,viewAttribute:d=null,valueKeyId:a="id",transformOption:v,disabled:V=!1,placeholder:re="",emptyText:Me="",fullWidth:D=!0,maxHeight:W=300,showSelectAll:se=!0,showSelectedCount:$=!0})=>{const[y,B]=m(!1),[ie,R]=m(!1),[l,ae]=m([]),[c,T]=m(""),[s,h]=m([]),[le,ce]=m(void 0),A=Le(null),[q,H]=m(""),O=(e,t)=>typeof v=="function"?v(e,l,t):e,_=(()=>{const e=L||k;if(!e)return[];if(Array.isArray(e))return e.map(r=>typeof r=="object"?r[a]:r).filter(Boolean);const t=typeof e=="object"?e[a]:e;return t?[t]:[]})(),pe=()=>{const e={...oe};return _.length>0&&(e.includes=_),c&&c.length>=S?(e[ne]=c,e.mixed_results=!0,e.min_options=F,e.limit=x):e.limit=Math.max(F,x),e},{data:I,isLoading:N,error:ve}=Ce(ee,{meta:{removeSortFilters:!0},filter:pe()});M(()=>{if(I){let t=(Array.isArray(I)?I:Object.values(I)).map((r,o)=>{const i=c&&c.length>=S?r[d]&&r[d].toLowerCase().includes(c.toLowerCase()):!0;return{...r,key:`option-${r[a]||o}`,isSearchMatch:i,priority:i?1:2}});t.sort((r,o)=>{if(r.priority!==o.priority)return r.priority-o.priority;const i=r[d]||r.name||"",w=o[d]||o.name||"";return i.localeCompare(w)}),t.length>x&&(t=t.slice(0,x)),ae(t)}},[I,a,c,S,d,x]),M(()=>{const e=L!==void 0?L:k;if(e==null){h([]),R(!0);return}let t=[];Array.isArray(e)?t=e:e&&(t=[e]),h(t),R(!0)},[L,k]),M(()=>{if(l.length>0&&s.length>0){const e=s.map(t=>{if(typeof t=="object"&&t[d])return t;const r=typeof t=="object"?t[a]:t;return l.find(o=>o[a]===r)||t});h(e)}},[l,d,a]);const de=(e,t=300)=>{clearTimeout(le),ce(setTimeout(()=>{e()},t))},ue=e=>{const t=e.target.value;H(t),t&&t!==""&&t.length>=S?de(()=>T(t),K):t===""&&T("")},me=()=>{H(""),T("")},g=e=>s.some(t=>{const r=typeof t=="object"?t[a]:t,o=typeof e=="object"?e[a]:e;return r===o}),Q=e=>{const t=g(e);let r;t?r=s.filter(o=>{const i=typeof o=="object"?o[a]:o,w=typeof e=="object"?e[a]:e;return i!==w}):r=[...s,e],h(r),f&&f(r)},fe=()=>{if(l.every(t=>g(t))){const t=l.map(o=>typeof o=="object"?o[a]:o),r=s.filter(o=>{const i=typeof o=="object"?o[a]:o;return!t.includes(i)});h(r),f&&f(r)}else{const t=l.filter(o=>!g(o)),r=[...s,...t];h(r),f&&f(r)}},ye=()=>s.length===0?re||"Seleccionar opciones...":$&&s.length>2?`${s.length} elementos seleccionados`:s.slice(0,2).map(e=>C(O(e,"display"),"display")).join(", ")+(s.length>2?`, +${s.length-2} m\xE1s`:""),j=l.length>0&&l.every(e=>g(e)),he=l.some(e=>g(e));return ie?p(u,{ref:A,sx:{position:"relative",width:D?"100%":"auto"},children:[n(J,{fullWidth:D,label:te,value:ye(),onClick:()=>B(!y),disabled:V,variant:"outlined",InputProps:{readOnly:!0,endAdornment:n(P,{position:"end",children:n(Z,{onClick:e=>{e.stopPropagation(),B(!y)},edge:"end",size:"small",children:y?n(Oe,{}):n(Ae,{})})})},sx:{cursor:"pointer","& .MuiInputBase-input":{cursor:"pointer"}}}),s.length>0&&p(u,{sx:{mt:1,display:"flex",flexWrap:"wrap",gap:.5},children:[s.slice(0,5).map((e,t)=>n(U,{label:C(O(e,"chip"),"chip"),size:"small",onDelete:()=>Q(e),disabled:V},`chip-${e[a]||t}`)),s.length>5&&n(U,{label:`+${s.length-5} m\xE1s`,size:"small",variant:"outlined"})]}),n(Se,{open:y,anchorEl:A.current,placement:"bottom-start",style:{zIndex:1300,width:A.current?.offsetWidth},children:n(Ie,{onClickAway:()=>B(!1),children:p(xe,{elevation:8,sx:{maxHeight:W+100,width:"100%",overflow:"hidden",display:"flex",flexDirection:"column"},children:[n(u,{sx:{p:2,borderBottom:"1px solid #e0e0e0"},children:n(J,{fullWidth:!0,size:"small",placeholder:"Buscar...",value:q,onChange:ue,InputProps:{startAdornment:n(P,{position:"start",children:n(Be,{fontSize:"small"})}),endAdornment:q&&n(P,{position:"end",children:n(Z,{size:"small",onClick:me,children:n(Te,{fontSize:"small"})})})}})}),se&&l.length>0&&n(u,{sx:{borderBottom:"1px solid #e0e0e0"},children:n(z,{disablePadding:!0,children:p(X,{onClick:fe,dense:!0,children:[n(Y,{children:n(G,{checked:j,indeterminate:he&&!j,size:"small"})}),n(E,{primary:p(b,{variant:"body2",fontWeight:"bold",children:[j?"Deseleccionar todo":"Seleccionar todo",c&&` (${l.length} resultados)`]})})]})})}),N&&p(u,{sx:{p:2,display:"flex",justifyContent:"center",alignItems:"center"},children:[n(ge,{size:20}),n(b,{variant:"body2",sx:{ml:1},children:"Cargando opciones..."})]}),!N&&n(be,{sx:{maxHeight:W,overflow:"auto",py:0},children:l.length===0?n(z,{children:n(E,{primary:n(b,{variant:"body2",color:"text.secondary",textAlign:"center",children:c?"No se encontraron resultados":"No hay opciones disponibles"})})}):l.map((e,t)=>{const r=g(e),o=e.isSearchMatch,i=c&&c.length>=S;return n(z,{disablePadding:!0,children:p(X,{onClick:()=>Q(e),dense:!0,sx:{backgroundColor:i&&o?"rgba(25, 118, 210, 0.04)":"transparent",borderLeft:i&&o?"3px solid #1976d2":"none",paddingLeft:i&&o?1:2,"&:hover":{backgroundColor:i&&o?"rgba(25, 118, 210, 0.08)":"rgba(0, 0, 0, 0.04)"}},children:[n(Y,{children:n(G,{checked:r,size:"small",tabIndex:-1,disableRipple:!0})}),n(E,{primary:p(u,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[n(b,{variant:"body2",sx:{fontWeight:i&&o?"bold":"normal",opacity:i&&!o?.7:1},children:C(O(e,"option"),"option")}),i&&o&&n(b,{variant:"caption",sx:{color:"#1976d2",fontWeight:"bold",fontSize:"0.75rem"},children:"\u2713"})]})})]})},e.key||`option-${t}`)})}),$&&s.length>0&&n(u,{sx:{p:1,borderTop:"1px solid #e0e0e0",backgroundColor:"#f5f5f5"},children:p(b,{variant:"caption",color:"text.secondary",children:[s.length," elemento",s.length!==1?"s":""," seleccionado",s.length!==1?"s":""]})})]})})})]}):n(ke,{})};var Je=je;export{je as SearchableSelectCheckboxes,Je 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
+ import { jsx, jsxs } from "react/jsx-runtime";
21
+ import {
22
+ Box,
23
+ Checkbox,
24
+ CircularProgress,
25
+ TextField,
26
+ Typography,
27
+ Chip,
28
+ List,
29
+ ListItem,
30
+ ListItemButton,
31
+ ListItemIcon,
32
+ ListItemText,
33
+ Paper,
34
+ Popper,
35
+ ClickAwayListener,
36
+ InputAdornment,
37
+ IconButton
38
+ } from "@mui/material";
39
+ import { useEffect, useState, useRef } from "react";
40
+ import { useGetList } from "react-admin";
41
+ import { LoadingIndicator } from "react-admin";
42
+ import SearchIcon from "@mui/icons-material/Search";
43
+ import ClearIcon from "@mui/icons-material/Clear";
44
+ import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
45
+ import ExpandLessIcon from "@mui/icons-material/ExpandLess";
46
+ const SearchableSelectCheckboxes = ({
47
+ isMultiple = true,
48
+ // Default to true for checkbox version
49
+ searchResults = 50,
50
+ minSearch = 1,
51
+ minOptions = 10,
52
+ timerSearch = 300,
53
+ resource,
54
+ selectLabel,
55
+ renderText,
56
+ transformData = (val) => val,
57
+ queryFilter = "q",
58
+ defaultValues = void 0,
59
+ value,
60
+ onChange,
61
+ isEmpty = false,
62
+ filter,
63
+ isOptionEqualToValue,
64
+ viewAttribute = null,
65
+ valueKeyId = "id",
66
+ transformOption,
67
+ disabled = false,
68
+ placeholder = "",
69
+ emptyText = "",
70
+ fullWidth = true,
71
+ maxHeight = 300,
72
+ showSelectAll = true,
73
+ showSelectedCount = true
74
+ }) => {
75
+ var _a;
76
+ const [open, setOpen] = useState(false);
77
+ const [fullyLoaded, setFullyLoaded] = useState(false);
78
+ const [parsedOptions, setParsedOptions] = useState([]);
79
+ const [q, setQ] = useState("");
80
+ const [selectedOptions, setSelectedOptions] = useState([]);
81
+ const [timeOutSearch, setTimeOutSearch] = useState(void 0);
82
+ const anchorRef = useRef(null);
83
+ const [searchInputValue, setSearchInputValue] = useState("");
84
+ const _transformOption = (option, caller) => {
85
+ if (typeof transformOption === "function") {
86
+ return transformOption(option, parsedOptions, caller);
87
+ }
88
+ return option;
89
+ };
90
+ const getIncludes = () => {
91
+ const currentValue = value || defaultValues;
92
+ if (!currentValue) return [];
93
+ if (Array.isArray(currentValue)) {
94
+ return currentValue.map(
95
+ (item) => typeof item === "object" ? item[valueKeyId] : item
96
+ ).filter(Boolean);
97
+ }
98
+ const id = typeof currentValue === "object" ? currentValue[valueKeyId] : currentValue;
99
+ return id ? [id] : [];
100
+ };
101
+ const includes = getIncludes();
102
+ const buildFilterParams = () => {
103
+ const baseFilter = __spreadValues({}, filter);
104
+ if (includes.length > 0) {
105
+ baseFilter.includes = includes;
106
+ }
107
+ if (q && q.length >= minSearch) {
108
+ baseFilter[queryFilter] = q;
109
+ baseFilter.mixed_results = true;
110
+ baseFilter.min_options = minOptions;
111
+ baseFilter.limit = searchResults;
112
+ } else {
113
+ baseFilter.limit = Math.max(minOptions, searchResults);
114
+ }
115
+ return baseFilter;
116
+ };
117
+ const {
118
+ data: resourceSearchResults,
119
+ isLoading: isResourceSearchLoading,
120
+ error: isResourceSearchErrored
121
+ } = useGetList(resource, {
122
+ meta: { removeSortFilters: true },
123
+ filter: buildFilterParams()
124
+ });
125
+ useEffect(() => {
126
+ if (resourceSearchResults) {
127
+ const resultsArray = Array.isArray(resourceSearchResults) ? resourceSearchResults : Object.values(resourceSearchResults);
128
+ let processedOptions = resultsArray.map((ele, index) => {
129
+ const isSearchMatch = q && q.length >= minSearch ? ele[viewAttribute] && ele[viewAttribute].toLowerCase().includes(q.toLowerCase()) : true;
130
+ return __spreadProps(__spreadValues({}, ele), {
131
+ key: `option-${ele[valueKeyId] || index}`,
132
+ isSearchMatch,
133
+ priority: isSearchMatch ? 1 : 2
134
+ });
135
+ });
136
+ processedOptions.sort((a, b) => {
137
+ if (a.priority !== b.priority) {
138
+ return a.priority - b.priority;
139
+ }
140
+ const nameA = a[viewAttribute] || a.name || "";
141
+ const nameB = b[viewAttribute] || b.name || "";
142
+ return nameA.localeCompare(nameB);
143
+ });
144
+ if (processedOptions.length > searchResults) {
145
+ processedOptions = processedOptions.slice(0, searchResults);
146
+ }
147
+ setParsedOptions(processedOptions);
148
+ }
149
+ }, [resourceSearchResults, valueKeyId, q, minSearch, viewAttribute, searchResults]);
150
+ useEffect(() => {
151
+ const currentValue = value !== void 0 ? value : defaultValues;
152
+ if (currentValue === null || currentValue === void 0) {
153
+ setSelectedOptions([]);
154
+ setFullyLoaded(true);
155
+ return;
156
+ }
157
+ let initialSelectedOptions = [];
158
+ if (Array.isArray(currentValue)) {
159
+ initialSelectedOptions = currentValue;
160
+ } else if (currentValue) {
161
+ initialSelectedOptions = [currentValue];
162
+ }
163
+ setSelectedOptions(initialSelectedOptions);
164
+ setFullyLoaded(true);
165
+ }, [value, defaultValues]);
166
+ useEffect(() => {
167
+ if (parsedOptions.length > 0 && selectedOptions.length > 0) {
168
+ const updatedOptions = selectedOptions.map((selectedOption) => {
169
+ if (typeof selectedOption === "object" && selectedOption[viewAttribute]) {
170
+ return selectedOption;
171
+ }
172
+ const id = typeof selectedOption === "object" ? selectedOption[valueKeyId] : selectedOption;
173
+ return parsedOptions.find((option) => option[valueKeyId] === id) || selectedOption;
174
+ });
175
+ setSelectedOptions(updatedOptions);
176
+ }
177
+ }, [parsedOptions, viewAttribute, valueKeyId]);
178
+ const debounce = (fn, delay = 300) => {
179
+ clearTimeout(timeOutSearch);
180
+ setTimeOutSearch(
181
+ setTimeout(() => {
182
+ fn();
183
+ }, delay)
184
+ );
185
+ };
186
+ const handleSearchChange = (event) => {
187
+ const searchValue = event.target.value;
188
+ setSearchInputValue(searchValue);
189
+ if (searchValue && searchValue !== "" && searchValue.length >= minSearch) {
190
+ debounce(() => setQ(searchValue), timerSearch);
191
+ } else if (searchValue === "") {
192
+ setQ("");
193
+ }
194
+ };
195
+ const handleClearSearch = () => {
196
+ setSearchInputValue("");
197
+ setQ("");
198
+ };
199
+ const isOptionSelected = (option) => {
200
+ return selectedOptions.some((selected) => {
201
+ const selectedId = typeof selected === "object" ? selected[valueKeyId] : selected;
202
+ const optionId = typeof option === "object" ? option[valueKeyId] : option;
203
+ return selectedId === optionId;
204
+ });
205
+ };
206
+ const handleOptionToggle = (option) => {
207
+ const isSelected = isOptionSelected(option);
208
+ let newSelectedOptions;
209
+ if (isSelected) {
210
+ newSelectedOptions = selectedOptions.filter((selected) => {
211
+ const selectedId = typeof selected === "object" ? selected[valueKeyId] : selected;
212
+ const optionId = typeof option === "object" ? option[valueKeyId] : option;
213
+ return selectedId !== optionId;
214
+ });
215
+ } else {
216
+ newSelectedOptions = [...selectedOptions, option];
217
+ }
218
+ setSelectedOptions(newSelectedOptions);
219
+ if (onChange) {
220
+ onChange(newSelectedOptions);
221
+ }
222
+ };
223
+ const handleSelectAll = () => {
224
+ const allSelected = parsedOptions.every((option) => isOptionSelected(option));
225
+ if (allSelected) {
226
+ const visibleIds = parsedOptions.map(
227
+ (option) => typeof option === "object" ? option[valueKeyId] : option
228
+ );
229
+ const newSelectedOptions = selectedOptions.filter((selected) => {
230
+ const selectedId = typeof selected === "object" ? selected[valueKeyId] : selected;
231
+ return !visibleIds.includes(selectedId);
232
+ });
233
+ setSelectedOptions(newSelectedOptions);
234
+ if (onChange) {
235
+ onChange(newSelectedOptions);
236
+ }
237
+ } else {
238
+ const newOptions = parsedOptions.filter((option) => !isOptionSelected(option));
239
+ const newSelectedOptions = [...selectedOptions, ...newOptions];
240
+ setSelectedOptions(newSelectedOptions);
241
+ if (onChange) {
242
+ onChange(newSelectedOptions);
243
+ }
244
+ }
245
+ };
246
+ const getSelectedDisplayText = () => {
247
+ if (selectedOptions.length === 0) {
248
+ return placeholder || "Seleccionar opciones...";
249
+ }
250
+ if (showSelectedCount && selectedOptions.length > 2) {
251
+ return `${selectedOptions.length} elementos seleccionados`;
252
+ }
253
+ return selectedOptions.slice(0, 2).map((option) => renderText(_transformOption(option, "display"), "display")).join(", ") + (selectedOptions.length > 2 ? `, +${selectedOptions.length - 2} m\xE1s` : "");
254
+ };
255
+ const allVisibleSelected = parsedOptions.length > 0 && parsedOptions.every((option) => isOptionSelected(option));
256
+ const someVisibleSelected = parsedOptions.some((option) => isOptionSelected(option));
257
+ if (!fullyLoaded) return /* @__PURE__ */ jsx(LoadingIndicator, {});
258
+ return /* @__PURE__ */ jsxs(Box, { ref: anchorRef, sx: { position: "relative", width: fullWidth ? "100%" : "auto" }, children: [
259
+ /* @__PURE__ */ jsx(
260
+ TextField,
261
+ {
262
+ fullWidth,
263
+ label: selectLabel,
264
+ value: getSelectedDisplayText(),
265
+ onClick: () => setOpen(!open),
266
+ disabled,
267
+ variant: "outlined",
268
+ InputProps: {
269
+ readOnly: true,
270
+ endAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(
271
+ IconButton,
272
+ {
273
+ onClick: (e) => {
274
+ e.stopPropagation();
275
+ setOpen(!open);
276
+ },
277
+ edge: "end",
278
+ size: "small",
279
+ children: open ? /* @__PURE__ */ jsx(ExpandLessIcon, {}) : /* @__PURE__ */ jsx(ExpandMoreIcon, {})
280
+ }
281
+ ) })
282
+ },
283
+ sx: {
284
+ cursor: "pointer",
285
+ "& .MuiInputBase-input": {
286
+ cursor: "pointer"
287
+ }
288
+ }
289
+ }
290
+ ),
291
+ selectedOptions.length > 0 && /* @__PURE__ */ jsxs(Box, { sx: { mt: 1, display: "flex", flexWrap: "wrap", gap: 0.5 }, children: [
292
+ selectedOptions.slice(0, 5).map((option, index) => /* @__PURE__ */ jsx(
293
+ Chip,
294
+ {
295
+ label: renderText(_transformOption(option, "chip"), "chip"),
296
+ size: "small",
297
+ onDelete: () => handleOptionToggle(option),
298
+ disabled
299
+ },
300
+ `chip-${option[valueKeyId] || index}`
301
+ )),
302
+ selectedOptions.length > 5 && /* @__PURE__ */ jsx(
303
+ Chip,
304
+ {
305
+ label: `+${selectedOptions.length - 5} m\xE1s`,
306
+ size: "small",
307
+ variant: "outlined"
308
+ }
309
+ )
310
+ ] }),
311
+ /* @__PURE__ */ jsx(
312
+ Popper,
313
+ {
314
+ open,
315
+ anchorEl: anchorRef.current,
316
+ placement: "bottom-start",
317
+ style: { zIndex: 1300, width: (_a = anchorRef.current) == null ? void 0 : _a.offsetWidth },
318
+ children: /* @__PURE__ */ jsx(ClickAwayListener, { onClickAway: () => setOpen(false), children: /* @__PURE__ */ jsxs(
319
+ Paper,
320
+ {
321
+ elevation: 8,
322
+ sx: {
323
+ maxHeight: maxHeight + 100,
324
+ width: "100%",
325
+ overflow: "hidden",
326
+ display: "flex",
327
+ flexDirection: "column"
328
+ },
329
+ children: [
330
+ /* @__PURE__ */ jsx(Box, { sx: { p: 2, borderBottom: "1px solid #e0e0e0" }, children: /* @__PURE__ */ jsx(
331
+ TextField,
332
+ {
333
+ fullWidth: true,
334
+ size: "small",
335
+ placeholder: "Buscar...",
336
+ value: searchInputValue,
337
+ onChange: handleSearchChange,
338
+ InputProps: {
339
+ startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(SearchIcon, { fontSize: "small" }) }),
340
+ endAdornment: searchInputValue && /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(
341
+ IconButton,
342
+ {
343
+ size: "small",
344
+ onClick: handleClearSearch,
345
+ children: /* @__PURE__ */ jsx(ClearIcon, { fontSize: "small" })
346
+ }
347
+ ) })
348
+ }
349
+ }
350
+ ) }),
351
+ showSelectAll && parsedOptions.length > 0 && /* @__PURE__ */ jsx(Box, { sx: { borderBottom: "1px solid #e0e0e0" }, children: /* @__PURE__ */ jsx(ListItem, { disablePadding: true, children: /* @__PURE__ */ jsxs(ListItemButton, { onClick: handleSelectAll, dense: true, children: [
352
+ /* @__PURE__ */ jsx(ListItemIcon, { children: /* @__PURE__ */ jsx(
353
+ Checkbox,
354
+ {
355
+ checked: allVisibleSelected,
356
+ indeterminate: someVisibleSelected && !allVisibleSelected,
357
+ size: "small"
358
+ }
359
+ ) }),
360
+ /* @__PURE__ */ jsx(
361
+ ListItemText,
362
+ {
363
+ primary: /* @__PURE__ */ jsxs(Typography, { variant: "body2", fontWeight: "bold", children: [
364
+ allVisibleSelected ? "Deseleccionar todo" : "Seleccionar todo",
365
+ q && ` (${parsedOptions.length} resultados)`
366
+ ] })
367
+ }
368
+ )
369
+ ] }) }) }),
370
+ isResourceSearchLoading && /* @__PURE__ */ jsxs(Box, { sx: { p: 2, display: "flex", justifyContent: "center", alignItems: "center" }, children: [
371
+ /* @__PURE__ */ jsx(CircularProgress, { size: 20 }),
372
+ /* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { ml: 1 }, children: "Cargando opciones..." })
373
+ ] }),
374
+ !isResourceSearchLoading && /* @__PURE__ */ jsx(
375
+ List,
376
+ {
377
+ sx: {
378
+ maxHeight,
379
+ overflow: "auto",
380
+ py: 0
381
+ },
382
+ children: parsedOptions.length === 0 ? /* @__PURE__ */ jsx(ListItem, { children: /* @__PURE__ */ jsx(
383
+ ListItemText,
384
+ {
385
+ primary: /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "text.secondary", textAlign: "center", children: q ? "No se encontraron resultados" : "No hay opciones disponibles" })
386
+ }
387
+ ) }) : parsedOptions.map((option, index) => {
388
+ const isSelected = isOptionSelected(option);
389
+ const isSearchMatch = option.isSearchMatch;
390
+ const hasSearchQuery = q && q.length >= minSearch;
391
+ return /* @__PURE__ */ jsx(ListItem, { disablePadding: true, children: /* @__PURE__ */ jsxs(
392
+ ListItemButton,
393
+ {
394
+ onClick: () => handleOptionToggle(option),
395
+ dense: true,
396
+ sx: {
397
+ // Style search matches differently
398
+ backgroundColor: hasSearchQuery && isSearchMatch ? "rgba(25, 118, 210, 0.04)" : "transparent",
399
+ borderLeft: hasSearchQuery && isSearchMatch ? "3px solid #1976d2" : "none",
400
+ paddingLeft: hasSearchQuery && isSearchMatch ? 1 : 2,
401
+ "&:hover": {
402
+ backgroundColor: hasSearchQuery && isSearchMatch ? "rgba(25, 118, 210, 0.08)" : "rgba(0, 0, 0, 0.04)"
403
+ }
404
+ },
405
+ children: [
406
+ /* @__PURE__ */ jsx(ListItemIcon, { children: /* @__PURE__ */ jsx(
407
+ Checkbox,
408
+ {
409
+ checked: isSelected,
410
+ size: "small",
411
+ tabIndex: -1,
412
+ disableRipple: true
413
+ }
414
+ ) }),
415
+ /* @__PURE__ */ jsx(
416
+ ListItemText,
417
+ {
418
+ primary: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
419
+ /* @__PURE__ */ jsx(
420
+ Typography,
421
+ {
422
+ variant: "body2",
423
+ sx: {
424
+ fontWeight: hasSearchQuery && isSearchMatch ? "bold" : "normal",
425
+ opacity: hasSearchQuery && !isSearchMatch ? 0.7 : 1
426
+ },
427
+ children: renderText(_transformOption(option, "option"), "option")
428
+ }
429
+ ),
430
+ hasSearchQuery && isSearchMatch && /* @__PURE__ */ jsx(
431
+ Typography,
432
+ {
433
+ variant: "caption",
434
+ sx: {
435
+ color: "#1976d2",
436
+ fontWeight: "bold",
437
+ fontSize: "0.75rem"
438
+ },
439
+ children: "\u2713"
440
+ }
441
+ )
442
+ ] })
443
+ }
444
+ )
445
+ ]
446
+ }
447
+ ) }, option.key || `option-${index}`);
448
+ })
449
+ }
450
+ ),
451
+ showSelectedCount && selectedOptions.length > 0 && /* @__PURE__ */ jsx(
452
+ Box,
453
+ {
454
+ sx: {
455
+ p: 1,
456
+ borderTop: "1px solid #e0e0e0",
457
+ backgroundColor: "#f5f5f5"
458
+ },
459
+ children: /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "text.secondary", children: [
460
+ selectedOptions.length,
461
+ " elemento",
462
+ selectedOptions.length !== 1 ? "s" : "",
463
+ " seleccionado",
464
+ selectedOptions.length !== 1 ? "s" : ""
465
+ ] })
466
+ }
467
+ )
468
+ ]
469
+ }
470
+ ) })
471
+ }
472
+ )
473
+ ] });
474
+ };
475
+ var RASearchableSelectCheckboxes_default = SearchableSelectCheckboxes;
476
+ export {
477
+ SearchableSelectCheckboxes,
478
+ RASearchableSelectCheckboxes_default as default
479
+ };