@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,465 @@
1
- import{Fragment as ie,jsx as u,jsxs as G}from"react/jsx-runtime";import{Autocomplete as K,Box as E,Chip as ee,CircularProgress as te,TextField as re}from"@mui/material";import{useEffect as B,useState as y}from"react";import{useGetList as oe}from"react-admin";import{LoadingIndicator as ne}from"react-admin";const ae=({isMultiple:l=!1,searchResults:c=50,minSearch:s=2,minOptions:p=10,timerSearch:j=500,resource:i,selectLabel:L,renderText:I,transformData:se=U=>U,queryFilter:T="q",defaultValues:P=void 0,value:C,onChange:O,isEmpty:le=!1,filter:z,isOptionEqualToValue:_,viewAttribute:d=null,valueKeyId:h="id",transformOption:F,disabled:X=!1,placeholder:$="",emptyText:ce="",fullWidth:H=!0,enableMixedResults:m=!1})=>{const[U,k]=y(!1),[N,w]=y(!1),[f,J]=y([]),[r,Q]=y(""),[x,D]=y([]),[M,Y]=y(void 0),A=(e,t)=>typeof F=="function"?F(e,f,t):e,W=(()=>{const e=C||P;if(!e)return[];if(Array.isArray(e))return e.map(n=>typeof n=="object"?n[h]:n).filter(Boolean);const t=typeof e=="object"?e[h]:e;return t?[t]:[]})(),Z=(()=>{const e={...z};if(W.length>0&&(e.includes=W),console.log("\u{1F527} SearchableSelectChips DEBUG - buildFilterParams called:",{resource:i,enableMixedResults:m,searchQuery:r,hasSearch:r&&r.length>=s,timestamp:new Date().toISOString()}),m){const t=p;e.mixedResults=t,console.log("\u{1F525} SearchableSelectChips DEBUG - Mixed results enabled via query param:",{resource:i,mixedResults:t,searchQuery:r,hasSearch:r&&r.length>=s,baseFilter:e,timestamp:new Date().toISOString()}),r&&r.length>=s&&(e[T]=r),e.limit=c}else r&&r.length>=s?(e[T]=r,e.mixed_results=!0,e.min_options=p,e.limit=c,console.log("\u{1F50D} SearchableSelectChips DEBUG - Legacy mixed results enabled:",{resource:i,searchQuery:r,minOptions:p,searchResults:c,mixed_results:!0,baseFilter:e,timestamp:new Date().toISOString()})):e.limit=Math.max(p,c);return console.log("\u{1F680} SearchableSelectChips DEBUG - Final filter params:",{resource:i,filterParams:e,enableMixedResults:m,timestamp:new Date().toISOString()}),e})(),{data:b,isLoading:q,error:ge}=oe(i,{meta:{removeSortFilters:!0},filter:Z});B(()=>{if(b){const e=Array.isArray(b)?b:Object.values(b);console.log("\u{1F4CA} SearchableSelectChips DEBUG - Processing results:",{resource:i,totalResults:e.length,searchQuery:r,hasSearch:r&&r.length>=s,enableMixedResults:m,timestamp:new Date().toISOString()});let t=e.map((o,a)=>{const S=r&&r.length>=s?o[d]&&o[d].toLowerCase().includes(r.toLowerCase()):!0;return{...o,key:`option-${o[h]||a}`,isSearchMatch:S,priority:S?1:2}});t.sort((o,a)=>{if(o.priority!==a.priority)return o.priority-a.priority;const S=o[d]||o.name||"",R=a[d]||a.name||"";return S.localeCompare(R)});const n=t.filter(o=>o.isSearchMatch),g=t.filter(o=>!o.isSearchMatch);console.log("\u{1F3AF} SearchableSelectChips DEBUG - Results breakdown:",{resource:i,searchQuery:r,totalProcessed:t.length,searchMatches:n.length,nonMatches:g.length,enableMixedResults:m,mixedResultsParam:m?p:"disabled",timestamp:new Date().toISOString()}),t.length>c&&(t=t.slice(0,c)),J(t)}},[b,h,r,s,d,c,p,m]),B(()=>{console.log("\u{1F50D} SearchableSelectChips DEBUG - Component initialized with resource:",{resource:i,resourceType:typeof i,selectLabel:L,isMultiple:l,minOptions:p,searchResults:c,minSearch:s,timestamp:new Date().toISOString()})},[]),B(()=>{const e=C!==void 0?C:P;if(console.log("\u{1F3AF} SearchableSelectChips DEBUG - Value changed:",{resource:i,currentValue:e,valueType:typeof e,isArray:Array.isArray(e),isMultiple:l,timestamp:new Date().toISOString()}),e==null){D([]),w(!0);return}let t=[];l?Array.isArray(e)?t=e:e&&(t=[e]):e&&(t=[e]),console.log("\u{1F3AF} SearchableSelectChips DEBUG - Selected options set:",{resource:i,currentValue:e,initialSelectedOptions:t,isMultiple:l,timestamp:new Date().toISOString()}),D(t),w(!0)},[C,P,l]),B(()=>{if(f.length>0&&x.length>0){const e=x.map(t=>{if(typeof t=="object"&&t[d])return t;const n=typeof t=="object"?t[h]:t;return f.find(g=>g[h]===n)||t});D(e)}},[f,d,h]);const v=(e,t=500)=>{clearTimeout(M),Y(setTimeout(()=>{e()},t))},V=e=>{D(e||[]),O&&O(l?e||[]:e&&e.length>0?e[0]:null)};return N?u(K,{multiple:l,loading:q,fullWidth:H,freeSolo:!1,options:f,open:U,onOpen:()=>k(!0),onClose:()=>k(!1),value:l?x:x[0]||null,isOptionEqualToValue:_,autoHighlight:!0,disabled:X,getOptionLabel:e=>e&&I(A(e,"optionlabel"),"optionlabel")||"",renderOption:(e,t)=>{const{key:n,...g}=e,o=t.isSearchMatch,a=r&&r.length>=s;return G(E,{component:"li",sx:{"& > img":{mr:2,flexShrink:0},fontWeight:a&&o?"bold":"normal",opacity:a&&!o?.7:1,borderLeft:a&&o?"3px solid #1976d2":"none",paddingLeft:a&&o?1:2,backgroundColor:a&&o?"rgba(25, 118, 210, 0.04)":"transparent",borderTop:a&&!o&&t.priority===2?"1px solid rgba(0,0,0,0.1)":"none",marginTop:a&&!o&&t.priority===2?.5:0},...g,children:[a&&t.priority===2&&f.indexOf(t)===f.findIndex(S=>S.priority===2)&&u(E,{sx:{position:"absolute",top:-20,left:0,right:0,fontSize:"0.7rem",color:"text.secondary",backgroundColor:"background.paper",padding:"2px 8px",borderBottom:"1px solid rgba(0,0,0,0.1)",fontWeight:"bold"},children:"Otras opciones"}),I(A(t,"option"),"option"),a&&o&&G(E,{component:"span",sx:{ml:"auto",fontSize:"0.75rem",color:"#1976d2",fontWeight:"bold",display:"flex",alignItems:"center",gap:.5},children:[u(E,{component:"span",sx:{width:6,height:6,borderRadius:"50%",backgroundColor:"#1976d2"}}),"Coincidencia"]})]},t.key||`option-${t[h]}`)},renderValue:(e,t)=>e.map((n,g)=>{const o=t({index:g});return u(ee,{label:I(A(n,"chip"),"chip"),...o},`chip-${n[h]||g}`)}),onChange:(e,t)=>{console.log("\u{1F504} SearchableSelectChips DEBUG - Autocomplete onChange:",{resource:i,rawValue:t,isMultiple:l,timestamp:new Date().toISOString()}),V(l?Array.isArray(t)?t:[]:t?[t]:[])},renderInput:e=>u(re,{...e,label:L,variant:"outlined",placeholder:$,onChange:t=>{const n=t.target.value;console.log("\u{1F50D} SearchableSelectChips DEBUG - Search input changed:",{resource:i,searchValue:n,searchLength:n.length,minSearch:s,willTriggerSearch:n.length>=s,timestamp:new Date().toISOString()}),n&&n!==""&&n.length>=s?v(()=>{console.log("\u{1F680} SearchableSelectChips DEBUG - Triggering search:",{resource:i,searchValue:n,minOptions:p,searchResults:c,timestamp:new Date().toISOString()}),Q(n)},j):n===""&&(console.log("\u{1F504} SearchableSelectChips DEBUG - Clearing search:",{resource:i,timestamp:new Date().toISOString()}),Q(""))},slotProps:{input:{...e.InputProps,autoComplete:"new-password",endAdornment:G(ie,{children:[q&&u(te,{color:"inherit",size:20}),e.InputProps.endAdornment]})}}}),ListboxProps:{sx:{maxHeight:400,"& .MuiAutocomplete-option":{position:"relative"}}}}):u(ne,{})};var Ce=ae;export{ae as SearchableSelectChips,Ce 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 {
34
+ Autocomplete,
35
+ Box,
36
+ Chip,
37
+ CircularProgress,
38
+ TextField
39
+ } from "@mui/material";
40
+ import { useEffect, useState } from "react";
41
+ import { useGetList } from "react-admin";
42
+ import { LoadingIndicator } from "react-admin";
43
+ const SearchableSelectChips = ({
44
+ isMultiple = false,
45
+ searchResults = 50,
46
+ minSearch = 2,
47
+ minOptions = 10,
48
+ timerSearch = 500,
49
+ resource,
50
+ selectLabel,
51
+ renderText,
52
+ transformData = (val) => val,
53
+ queryFilter = "q",
54
+ defaultValues = void 0,
55
+ value,
56
+ onChange,
57
+ isEmpty = false,
58
+ filter,
59
+ isOptionEqualToValue,
60
+ viewAttribute = null,
61
+ valueKeyId = "id",
62
+ transformOption,
63
+ disabled = false,
64
+ placeholder = "",
65
+ emptyText = "",
66
+ fullWidth = true,
67
+ // 🔥 NEW: Mixed results props
68
+ enableMixedResults = false
69
+ }) => {
70
+ const [open, setOpen] = useState(false);
71
+ const [fullyLoaded, setFullyLoaded] = useState(false);
72
+ const [parsedOptions, setParsedOptions] = useState([]);
73
+ const [q, setQ] = useState("");
74
+ const [selectedOptions, setSelectedOptions] = useState([]);
75
+ const [timeOutSearch, setTimeOutSearch] = useState(void 0);
76
+ const _transformOption = (option, caller) => {
77
+ if (typeof transformOption === "function") {
78
+ return transformOption(option, parsedOptions, caller);
79
+ }
80
+ return option;
81
+ };
82
+ const getIncludes = () => {
83
+ const currentValue = value || defaultValues;
84
+ if (!currentValue) return [];
85
+ if (Array.isArray(currentValue)) {
86
+ return currentValue.map(
87
+ (item) => typeof item === "object" ? item[valueKeyId] : item
88
+ ).filter(Boolean);
89
+ }
90
+ const id = typeof currentValue === "object" ? currentValue[valueKeyId] : currentValue;
91
+ return id ? [id] : [];
92
+ };
93
+ const includes = getIncludes();
94
+ const buildFilterParams = () => {
95
+ const baseFilter = __spreadValues({}, filter);
96
+ if (includes.length > 0) {
97
+ baseFilter.includes = includes;
98
+ }
99
+ console.log("\u{1F527} SearchableSelectChips DEBUG - buildFilterParams called:", {
100
+ resource,
101
+ enableMixedResults,
102
+ searchQuery: q,
103
+ hasSearch: q && q.length >= minSearch,
104
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
105
+ });
106
+ if (enableMixedResults) {
107
+ const mixedResultsValue = minOptions;
108
+ baseFilter.mixedResults = mixedResultsValue;
109
+ console.log("\u{1F525} SearchableSelectChips DEBUG - Mixed results enabled via query param:", {
110
+ resource,
111
+ mixedResults: mixedResultsValue,
112
+ searchQuery: q,
113
+ hasSearch: q && q.length >= minSearch,
114
+ baseFilter,
115
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
116
+ });
117
+ if (q && q.length >= minSearch) {
118
+ baseFilter[queryFilter] = q;
119
+ }
120
+ baseFilter.limit = searchResults;
121
+ } else {
122
+ if (q && q.length >= minSearch) {
123
+ baseFilter[queryFilter] = q;
124
+ baseFilter.mixed_results = true;
125
+ baseFilter.min_options = minOptions;
126
+ baseFilter.limit = searchResults;
127
+ console.log("\u{1F50D} SearchableSelectChips DEBUG - Legacy mixed results enabled:", {
128
+ resource,
129
+ searchQuery: q,
130
+ minOptions,
131
+ searchResults,
132
+ mixed_results: true,
133
+ baseFilter,
134
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
135
+ });
136
+ } else if (q === "") {
137
+ baseFilter.limit = Math.max(minOptions, searchResults);
138
+ } else {
139
+ baseFilter.limit = Math.max(minOptions, searchResults);
140
+ }
141
+ }
142
+ console.log("\u{1F680} SearchableSelectChips DEBUG - Final filter params:", {
143
+ resource,
144
+ filterParams: baseFilter,
145
+ enableMixedResults,
146
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
147
+ });
148
+ return baseFilter;
149
+ };
150
+ const filterParams = buildFilterParams();
151
+ const {
152
+ data: resourceSearchResults,
153
+ isLoading: isResourceSearchLoading,
154
+ error: isResourceSearchErrored
155
+ } = useGetList(resource, {
156
+ meta: { removeSortFilters: true },
157
+ filter: filterParams
158
+ });
159
+ useEffect(() => {
160
+ if (resourceSearchResults) {
161
+ const resultsArray = Array.isArray(resourceSearchResults) ? resourceSearchResults : Object.values(resourceSearchResults);
162
+ console.log("\u{1F4CA} SearchableSelectChips DEBUG - Processing results:", {
163
+ resource,
164
+ totalResults: resultsArray.length,
165
+ searchQuery: q,
166
+ hasSearch: q && q.length >= minSearch,
167
+ enableMixedResults,
168
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
169
+ });
170
+ let processedOptions = resultsArray.map((ele, index) => {
171
+ const isSearchMatch = q && q.length >= minSearch ? ele[viewAttribute] && ele[viewAttribute].toLowerCase().includes(q.toLowerCase()) : true;
172
+ return __spreadProps(__spreadValues({}, ele), {
173
+ key: `option-${ele[valueKeyId] || index}`,
174
+ isSearchMatch,
175
+ priority: isSearchMatch ? 1 : 2
176
+ });
177
+ });
178
+ processedOptions.sort((a, b) => {
179
+ if (a.priority !== b.priority) {
180
+ return a.priority - b.priority;
181
+ }
182
+ const nameA = a[viewAttribute] || a.name || "";
183
+ const nameB = b[viewAttribute] || b.name || "";
184
+ return nameA.localeCompare(nameB);
185
+ });
186
+ const searchMatches = processedOptions.filter((opt) => opt.isSearchMatch);
187
+ const nonMatches = processedOptions.filter((opt) => !opt.isSearchMatch);
188
+ console.log("\u{1F3AF} SearchableSelectChips DEBUG - Results breakdown:", {
189
+ resource,
190
+ searchQuery: q,
191
+ totalProcessed: processedOptions.length,
192
+ searchMatches: searchMatches.length,
193
+ nonMatches: nonMatches.length,
194
+ enableMixedResults,
195
+ mixedResultsParam: enableMixedResults ? minOptions : "disabled",
196
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
197
+ });
198
+ if (processedOptions.length > searchResults) {
199
+ processedOptions = processedOptions.slice(0, searchResults);
200
+ }
201
+ setParsedOptions(processedOptions);
202
+ }
203
+ }, [resourceSearchResults, valueKeyId, q, minSearch, viewAttribute, searchResults, minOptions, enableMixedResults]);
204
+ useEffect(() => {
205
+ console.log("\u{1F50D} SearchableSelectChips DEBUG - Component initialized with resource:", {
206
+ resource,
207
+ resourceType: typeof resource,
208
+ selectLabel,
209
+ isMultiple,
210
+ minOptions,
211
+ searchResults,
212
+ minSearch,
213
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
214
+ });
215
+ }, []);
216
+ useEffect(() => {
217
+ const currentValue = value !== void 0 ? value : defaultValues;
218
+ console.log("\u{1F3AF} SearchableSelectChips DEBUG - Value changed:", {
219
+ resource,
220
+ currentValue,
221
+ valueType: typeof currentValue,
222
+ isArray: Array.isArray(currentValue),
223
+ isMultiple,
224
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
225
+ });
226
+ if (currentValue === null || currentValue === void 0) {
227
+ setSelectedOptions([]);
228
+ setFullyLoaded(true);
229
+ return;
230
+ }
231
+ let initialSelectedOptions = [];
232
+ if (isMultiple) {
233
+ if (Array.isArray(currentValue)) {
234
+ initialSelectedOptions = currentValue;
235
+ } else if (currentValue) {
236
+ initialSelectedOptions = [currentValue];
237
+ }
238
+ } else {
239
+ if (currentValue) {
240
+ initialSelectedOptions = [currentValue];
241
+ }
242
+ }
243
+ console.log("\u{1F3AF} SearchableSelectChips DEBUG - Selected options set:", {
244
+ resource,
245
+ currentValue,
246
+ initialSelectedOptions,
247
+ isMultiple,
248
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
249
+ });
250
+ setSelectedOptions(initialSelectedOptions);
251
+ setFullyLoaded(true);
252
+ }, [value, defaultValues, isMultiple]);
253
+ useEffect(() => {
254
+ if (parsedOptions.length > 0 && selectedOptions.length > 0) {
255
+ const updatedOptions = selectedOptions.map((selectedOption) => {
256
+ if (typeof selectedOption === "object" && selectedOption[viewAttribute]) {
257
+ return selectedOption;
258
+ }
259
+ const id = typeof selectedOption === "object" ? selectedOption[valueKeyId] : selectedOption;
260
+ return parsedOptions.find((option) => option[valueKeyId] === id) || selectedOption;
261
+ });
262
+ setSelectedOptions(updatedOptions);
263
+ }
264
+ }, [parsedOptions, viewAttribute, valueKeyId]);
265
+ const debounce = (fn, delay = 500) => {
266
+ clearTimeout(timeOutSearch);
267
+ setTimeOutSearch(
268
+ setTimeout(() => {
269
+ fn();
270
+ }, delay)
271
+ );
272
+ };
273
+ const updateFieldValue = (newSelectedOptions) => {
274
+ setSelectedOptions(newSelectedOptions || []);
275
+ if (onChange) {
276
+ if (isMultiple) {
277
+ onChange(newSelectedOptions || []);
278
+ } else {
279
+ onChange(newSelectedOptions && newSelectedOptions.length > 0 ? newSelectedOptions[0] : null);
280
+ }
281
+ }
282
+ };
283
+ if (!fullyLoaded) return /* @__PURE__ */ jsx(LoadingIndicator, {});
284
+ return /* @__PURE__ */ jsx(
285
+ Autocomplete,
286
+ {
287
+ multiple: isMultiple,
288
+ loading: isResourceSearchLoading,
289
+ fullWidth,
290
+ freeSolo: false,
291
+ options: parsedOptions,
292
+ open,
293
+ onOpen: () => setOpen(true),
294
+ onClose: () => setOpen(false),
295
+ value: isMultiple ? selectedOptions : selectedOptions[0] || null,
296
+ isOptionEqualToValue,
297
+ autoHighlight: true,
298
+ disabled,
299
+ getOptionLabel: (option) => {
300
+ if (!option) return "";
301
+ return renderText(_transformOption(option, "optionlabel"), "optionlabel") || "";
302
+ },
303
+ renderOption: (props, option) => {
304
+ const _a = props, { key } = _a, newProps = __objRest(_a, ["key"]);
305
+ const isSearchMatch = option.isSearchMatch;
306
+ const hasSearchQuery = q && q.length >= minSearch;
307
+ return /* @__PURE__ */ jsxs(
308
+ Box,
309
+ __spreadProps(__spreadValues({
310
+ component: "li",
311
+ sx: {
312
+ "& > img": { mr: 2, flexShrink: 0 },
313
+ // 🔥 ENHANCED: Better visual distinction for mixed results
314
+ fontWeight: hasSearchQuery && isSearchMatch ? "bold" : "normal",
315
+ opacity: hasSearchQuery && !isSearchMatch ? 0.7 : 1,
316
+ borderLeft: hasSearchQuery && isSearchMatch ? "3px solid #1976d2" : "none",
317
+ paddingLeft: hasSearchQuery && isSearchMatch ? 1 : 2,
318
+ backgroundColor: hasSearchQuery && isSearchMatch ? "rgba(25, 118, 210, 0.04)" : "transparent",
319
+ // 🔥 NEW: Add subtle separator between search matches and other options
320
+ borderTop: hasSearchQuery && !isSearchMatch && option.priority === 2 ? "1px solid rgba(0,0,0,0.1)" : "none",
321
+ marginTop: hasSearchQuery && !isSearchMatch && option.priority === 2 ? 0.5 : 0
322
+ }
323
+ }, newProps), {
324
+ children: [
325
+ hasSearchQuery && option.priority === 2 && parsedOptions.indexOf(option) === parsedOptions.findIndex((opt) => opt.priority === 2) && /* @__PURE__ */ jsx(
326
+ Box,
327
+ {
328
+ sx: {
329
+ position: "absolute",
330
+ top: -20,
331
+ left: 0,
332
+ right: 0,
333
+ fontSize: "0.7rem",
334
+ color: "text.secondary",
335
+ backgroundColor: "background.paper",
336
+ padding: "2px 8px",
337
+ borderBottom: "1px solid rgba(0,0,0,0.1)",
338
+ fontWeight: "bold"
339
+ },
340
+ children: "Otras opciones"
341
+ }
342
+ ),
343
+ renderText(_transformOption(option, "option"), "option"),
344
+ hasSearchQuery && isSearchMatch && /* @__PURE__ */ jsxs(
345
+ Box,
346
+ {
347
+ component: "span",
348
+ sx: {
349
+ ml: "auto",
350
+ fontSize: "0.75rem",
351
+ color: "#1976d2",
352
+ fontWeight: "bold",
353
+ display: "flex",
354
+ alignItems: "center",
355
+ gap: 0.5
356
+ },
357
+ children: [
358
+ /* @__PURE__ */ jsx(
359
+ Box,
360
+ {
361
+ component: "span",
362
+ sx: {
363
+ width: 6,
364
+ height: 6,
365
+ borderRadius: "50%",
366
+ backgroundColor: "#1976d2"
367
+ }
368
+ }
369
+ ),
370
+ "Coincidencia"
371
+ ]
372
+ }
373
+ )
374
+ ]
375
+ }),
376
+ option.key || `option-${option[valueKeyId]}`
377
+ );
378
+ },
379
+ renderValue: (tagValue, getTagProps) => {
380
+ return tagValue.map((option, index) => {
381
+ const chipProps = getTagProps({ index });
382
+ return /* @__PURE__ */ jsx(
383
+ Chip,
384
+ __spreadValues({
385
+ label: renderText(_transformOption(option, "chip"), "chip")
386
+ }, chipProps),
387
+ `chip-${option[valueKeyId] || index}`
388
+ );
389
+ });
390
+ },
391
+ onChange: (event, rawValue) => {
392
+ console.log("\u{1F504} SearchableSelectChips DEBUG - Autocomplete onChange:", {
393
+ resource,
394
+ rawValue,
395
+ isMultiple,
396
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
397
+ });
398
+ if (isMultiple) {
399
+ updateFieldValue(Array.isArray(rawValue) ? rawValue : []);
400
+ } else {
401
+ updateFieldValue(rawValue ? [rawValue] : []);
402
+ }
403
+ },
404
+ renderInput: (params) => /* @__PURE__ */ jsx(
405
+ TextField,
406
+ __spreadProps(__spreadValues({}, params), {
407
+ label: selectLabel,
408
+ variant: "outlined",
409
+ placeholder,
410
+ onChange: (ev) => {
411
+ const searchValue = ev.target.value;
412
+ console.log("\u{1F50D} SearchableSelectChips DEBUG - Search input changed:", {
413
+ resource,
414
+ searchValue,
415
+ searchLength: searchValue.length,
416
+ minSearch,
417
+ willTriggerSearch: searchValue.length >= minSearch,
418
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
419
+ });
420
+ if (searchValue && searchValue !== "" && searchValue.length >= minSearch) {
421
+ debounce(() => {
422
+ console.log("\u{1F680} SearchableSelectChips DEBUG - Triggering search:", {
423
+ resource,
424
+ searchValue,
425
+ minOptions,
426
+ searchResults,
427
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
428
+ });
429
+ setQ(searchValue);
430
+ }, timerSearch);
431
+ } else if (searchValue === "") {
432
+ console.log("\u{1F504} SearchableSelectChips DEBUG - Clearing search:", {
433
+ resource,
434
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
435
+ });
436
+ setQ("");
437
+ }
438
+ },
439
+ slotProps: {
440
+ input: __spreadProps(__spreadValues({}, params.InputProps), {
441
+ autoComplete: "new-password",
442
+ endAdornment: /* @__PURE__ */ jsxs(Fragment, { children: [
443
+ isResourceSearchLoading && /* @__PURE__ */ jsx(CircularProgress, { color: "inherit", size: 20 }),
444
+ params.InputProps.endAdornment
445
+ ] })
446
+ })
447
+ }
448
+ })
449
+ ),
450
+ ListboxProps: {
451
+ sx: {
452
+ maxHeight: 400,
453
+ "& .MuiAutocomplete-option": {
454
+ position: "relative"
455
+ }
456
+ }
457
+ }
458
+ }
459
+ );
460
+ };
461
+ var RASearchableSelectChips_default = SearchableSelectChips;
462
+ export {
463
+ SearchableSelectChips,
464
+ RASearchableSelectChips_default as default
465
+ };