@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,295 @@
1
- import{Fragment as v,jsx as i,jsxs as se}from"react/jsx-runtime";import{Autocomplete as Y,Box as T,Chip as B,CircularProgress as Z,TextField as M}from"@mui/material";import{useEffect as O,useState as d}from"react";import{useFormContext as K}from"react-hook-form";import{useGetList as ee}from"react-admin";import{useRecordContext as E}from"react-admin";import{LoadingIndicator as te}from"react-admin";const oe=({method:a,attribute:m,isMultiple:n=!1,searchResults:f=50,minSearch:A=3,timerSearch:I=500,resource:D,selectLabel:P,renderText:S,transformData:ie=C=>C,queryFilter:q="q",defaultValues:l=void 0,isEmpty:ae=!1,filter:N,isOptionEqualToValue:$=void 0,viewAttribute:le=null,valueKeyId:c="id",useBaseAttributeName:ce=!1,useListAttributeForController:ue=!1,transformOption:L})=>{const{setValue:C,watch:j}=K(),r=E(),s=m.attribute,p=m.listAttribute||m.attribute;console.log("Attribute config:",{saveAttributeName:s,displayAttributeName:p,record:r?{[s]:r[s],[p]:r[p]}:null});const[z,k]=d(!1),[F,V]=d(!1),[y,_]=d([]),[G,H]=d(""),[b,x]=d([]),[Q,U]=d(void 0),h=j(s),R=(e,t)=>typeof L=="function"?L(e,y,t):e,W=(()=>{let e=r?.[s];return e?(Array.isArray(e)||(e=[e]),e.filter(Boolean)):[]})(),{data:g,total:me,isLoading:w,error:de}=ee(D,{meta:{removeSortFilters:!0},filter:{[q]:G,...N,includes:W}});O(()=>{if(g){const t=(Array.isArray(g)?g:Object.values(g)).map((o,u)=>({...o,key:`option-${o[c]||u}`}));_(t)}},[g,c]),O(()=>{if(F)return;console.log("Initializing default values...");let e=[],t=n?[]:null;if(l===null&&r){if(r[p]&&Array.isArray(r[p]))e=r[p],t=r[p].map(o=>o[c]);else if(r[s]){const o=Array.isArray(r[s])?r[s]:[r[s]];t=n?o:o[0]}}else l!=null&&(Array.isArray(l)?(e=l,t=l.map(o=>typeof o=="object"?o[c]:o)):(e=[l],t=typeof l=="object"?l[c]:l));console.log("Initial values:",{initialSelectedOptions:e,initialFormValue:t}),x(e),C(s,t),V(!0)},[r,l,F,s,p,c,n]),O(()=>{if(y.length>0&&b.length===0&&h){const t=(Array.isArray(h)?h:[h]).map(o=>y.find(u=>u[c]===o)).filter(Boolean);t.length>0&&(console.log("Setting selected options from parsed options:",t),x(t))}},[y,b,h,c]);const J=(e,t=500)=>{clearTimeout(Q),U(setTimeout(()=>{e()},t))},X=e=>{console.log("Updating field value:",e),x(e||[]);const t=(e||[]).map(u=>u[c]),o=n?t:t[0]||null;console.log("Saving to form:",{attribute:s,value:o}),C(s,o)};return F?i(v,{children:i(Y,{multiple:n,loading:w,fullWidth:!0,freeSolo:!1,options:y,open:z,onOpen:()=>k(!0),onClose:()=>k(!1),value:n?b:b[0]||null,isOptionEqualToValue:$,autoHighlight:!0,getOptionLabel:e=>e&&S(R(e,"optionlabel"),"optionlabel")||"",renderOption:(e,t)=>{const{key:o,...u}=e;return i(T,{component:"li",sx:{"& > img":{mr:2,flexShrink:0}},...u,children:S(R(t,"option"),"option")},t.key||`option-${t[c]}`)},renderTags:(e,t)=>e.map((o,u)=>i(B,{label:S(R(o,"chip"),"chip"),...t({index:u})},`chip-${o[c]||u}`)),onChange:(e,t)=>{X(n?t:t?[t]:[])},renderInput:e=>i(M,{...e,label:P,variant:"outlined",onChange:t=>{const o=t.target.value;o&&o!==""&&o.length>=A&&J(()=>H(o),I)},InputProps:{...e.InputProps,autoComplete:"new-password",endAdornment:se(v,{children:[w&&i(Z,{color:"inherit",size:20}),e.InputProps.endAdornment]})}})},`autocomplete-${s}`)}):i(te,{})},ne=({attribute:a,resourceConfig:m})=>{const n=E(),f=Array.isArray(n[a.listAttribute||a.attribute])?n[a.listAttribute||a.attribute]:[n[a.listAttribute||a.attribute]];return i(v,{children:n&&i(T,{sx:{width:"100%"},children:f.map(A=>i(B,{label:A.name,sx:{margin:.5}},A.id))})})},re=({method:a,attribute:m,resourceConfig:n,...f})=>{switch(a){case"edit":case"create":return i(oe,{resourceConfig:n,attribute:m,method:a,...f});case"view":case"list":return i(ne,{resourceConfig:n,attribute:m,method:a,...f});default:return null}};var Oe=re;export{oe as SearchableSelectChipsControlRecordContextEdit,ne as SearchableSelectChipsControlRecordContextView,Oe 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 { useFormContext } from "react-hook-form";
42
+ import { useGetList } from "react-admin";
43
+ import { useRecordContext } from "react-admin";
44
+ import { LoadingIndicator } from "react-admin";
45
+ const SearchableSelectChipsControlRecordContextEdit = ({
46
+ method,
47
+ attribute,
48
+ isMultiple = false,
49
+ searchResults = 50,
50
+ minSearch = 3,
51
+ timerSearch = 500,
52
+ resource,
53
+ selectLabel,
54
+ renderText,
55
+ transformData = (val) => val,
56
+ queryFilter = "q",
57
+ defaultValues = void 0,
58
+ isEmpty = false,
59
+ filter,
60
+ isOptionEqualToValue = void 0,
61
+ viewAttribute = null,
62
+ valueKeyId = "id",
63
+ useBaseAttributeName = false,
64
+ useListAttributeForController = false,
65
+ transformOption
66
+ }) => {
67
+ const { setValue, watch } = useFormContext();
68
+ const record = useRecordContext();
69
+ const saveAttributeName = attribute.attribute;
70
+ const displayAttributeName = attribute.listAttribute || attribute.attribute;
71
+ console.log("Attribute config:", {
72
+ saveAttributeName,
73
+ displayAttributeName,
74
+ record: record ? {
75
+ [saveAttributeName]: record[saveAttributeName],
76
+ [displayAttributeName]: record[displayAttributeName]
77
+ } : null
78
+ });
79
+ const [open, setOpen] = useState(false);
80
+ const [fullyLoaded, setFullyLoaded] = useState(false);
81
+ const [parsedOptions, setParsedOptions] = useState([]);
82
+ const [q, setQ] = useState("");
83
+ const [selectedOptions, setSelectedOptions] = useState([]);
84
+ const [timeOutSearch, setTimeOutSearch] = useState(void 0);
85
+ const currentFormValue = watch(saveAttributeName);
86
+ const _transformOption = (option, caller) => {
87
+ if (typeof transformOption === "function") {
88
+ return transformOption(option, parsedOptions, caller);
89
+ }
90
+ return option;
91
+ };
92
+ const getIncludes = () => {
93
+ let recordValue = record == null ? void 0 : record[saveAttributeName];
94
+ if (!recordValue) return [];
95
+ if (!Array.isArray(recordValue)) {
96
+ recordValue = [recordValue];
97
+ }
98
+ return recordValue.filter(Boolean);
99
+ };
100
+ const includes = getIncludes();
101
+ const {
102
+ data: resourceSearchResults,
103
+ total: totalSearchResults,
104
+ isLoading: isResourceSearchLoading,
105
+ error: isResourceSearchErrored
106
+ } = useGetList(resource, {
107
+ meta: { removeSortFilters: true },
108
+ filter: __spreadProps(__spreadValues({ [queryFilter]: q }, filter), { includes })
109
+ });
110
+ useEffect(() => {
111
+ if (resourceSearchResults) {
112
+ const resultsArray = Array.isArray(resourceSearchResults) ? resourceSearchResults : Object.values(resourceSearchResults);
113
+ const _parsedOptions = resultsArray.map((ele, index) => __spreadProps(__spreadValues({}, ele), {
114
+ key: `option-${ele[valueKeyId] || index}`
115
+ }));
116
+ setParsedOptions(_parsedOptions);
117
+ }
118
+ }, [resourceSearchResults, valueKeyId]);
119
+ useEffect(() => {
120
+ if (fullyLoaded) return;
121
+ console.log("Initializing default values...");
122
+ let initialSelectedOptions = [];
123
+ let initialFormValue = isMultiple ? [] : null;
124
+ if (defaultValues === null && record) {
125
+ if (record[displayAttributeName] && Array.isArray(record[displayAttributeName])) {
126
+ initialSelectedOptions = record[displayAttributeName];
127
+ initialFormValue = record[displayAttributeName].map((item) => item[valueKeyId]);
128
+ } else if (record[saveAttributeName]) {
129
+ const ids = Array.isArray(record[saveAttributeName]) ? record[saveAttributeName] : [record[saveAttributeName]];
130
+ initialFormValue = isMultiple ? ids : ids[0];
131
+ }
132
+ } else if (defaultValues !== void 0 && defaultValues !== null) {
133
+ if (Array.isArray(defaultValues)) {
134
+ initialSelectedOptions = defaultValues;
135
+ initialFormValue = defaultValues.map(
136
+ (item) => typeof item === "object" ? item[valueKeyId] : item
137
+ );
138
+ } else {
139
+ initialSelectedOptions = [defaultValues];
140
+ initialFormValue = typeof defaultValues === "object" ? defaultValues[valueKeyId] : defaultValues;
141
+ }
142
+ }
143
+ console.log("Initial values:", {
144
+ initialSelectedOptions,
145
+ initialFormValue
146
+ });
147
+ setSelectedOptions(initialSelectedOptions);
148
+ setValue(saveAttributeName, initialFormValue);
149
+ setFullyLoaded(true);
150
+ }, [record, defaultValues, fullyLoaded, saveAttributeName, displayAttributeName, valueKeyId, isMultiple]);
151
+ useEffect(() => {
152
+ if (parsedOptions.length > 0 && selectedOptions.length === 0 && currentFormValue) {
153
+ const formValueArray = Array.isArray(currentFormValue) ? currentFormValue : [currentFormValue];
154
+ const matchedOptions = formValueArray.map(
155
+ (id) => parsedOptions.find((option) => option[valueKeyId] === id)
156
+ ).filter(Boolean);
157
+ if (matchedOptions.length > 0) {
158
+ console.log("Setting selected options from parsed options:", matchedOptions);
159
+ setSelectedOptions(matchedOptions);
160
+ }
161
+ }
162
+ }, [parsedOptions, selectedOptions, currentFormValue, valueKeyId]);
163
+ const debounce = (fn, delay = 500) => {
164
+ clearTimeout(timeOutSearch);
165
+ setTimeOutSearch(
166
+ setTimeout(() => {
167
+ fn();
168
+ }, delay)
169
+ );
170
+ };
171
+ const updateFieldValue = (newSelectedOptions) => {
172
+ console.log("Updating field value:", newSelectedOptions);
173
+ setSelectedOptions(newSelectedOptions || []);
174
+ const idsToSave = (newSelectedOptions || []).map((option) => option[valueKeyId]);
175
+ const valueToSave = isMultiple ? idsToSave : idsToSave[0] || null;
176
+ console.log("Saving to form:", { attribute: saveAttributeName, value: valueToSave });
177
+ setValue(saveAttributeName, valueToSave);
178
+ };
179
+ if (!fullyLoaded) return /* @__PURE__ */ jsx(LoadingIndicator, {});
180
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
181
+ Autocomplete,
182
+ {
183
+ multiple: isMultiple,
184
+ loading: isResourceSearchLoading,
185
+ fullWidth: true,
186
+ freeSolo: false,
187
+ options: parsedOptions,
188
+ open,
189
+ onOpen: () => setOpen(true),
190
+ onClose: () => setOpen(false),
191
+ value: isMultiple ? selectedOptions : selectedOptions[0] || null,
192
+ isOptionEqualToValue,
193
+ autoHighlight: true,
194
+ getOptionLabel: (option) => {
195
+ if (!option) return "";
196
+ return renderText(_transformOption(option, "optionlabel"), "optionlabel") || "";
197
+ },
198
+ renderOption: (props, option) => {
199
+ const _a = props, { key } = _a, newProps = __objRest(_a, ["key"]);
200
+ return /* @__PURE__ */ jsx(
201
+ Box,
202
+ __spreadProps(__spreadValues({
203
+ component: "li",
204
+ sx: { "& > img": { mr: 2, flexShrink: 0 } }
205
+ }, newProps), {
206
+ children: renderText(_transformOption(option, "option"), "option")
207
+ }),
208
+ option.key || `option-${option[valueKeyId]}`
209
+ );
210
+ },
211
+ renderTags: (tagValue, getTagProps) => {
212
+ return tagValue.map((option, index) => /* @__PURE__ */ jsx(
213
+ Chip,
214
+ __spreadValues({
215
+ label: renderText(_transformOption(option, "chip"), "chip")
216
+ }, getTagProps({ index })),
217
+ `chip-${option[valueKeyId] || index}`
218
+ ));
219
+ },
220
+ onChange: (event, rawValue) => {
221
+ const newValue = isMultiple ? rawValue : rawValue ? [rawValue] : [];
222
+ updateFieldValue(newValue);
223
+ },
224
+ renderInput: (params) => /* @__PURE__ */ jsx(
225
+ TextField,
226
+ __spreadProps(__spreadValues({}, params), {
227
+ label: selectLabel,
228
+ variant: "outlined",
229
+ onChange: (ev) => {
230
+ const searchValue = ev.target.value;
231
+ if (searchValue && searchValue !== "" && searchValue.length >= minSearch) {
232
+ debounce(() => setQ(searchValue), timerSearch);
233
+ }
234
+ },
235
+ InputProps: __spreadProps(__spreadValues({}, params.InputProps), {
236
+ autoComplete: "new-password",
237
+ endAdornment: /* @__PURE__ */ jsxs(Fragment, { children: [
238
+ isResourceSearchLoading && /* @__PURE__ */ jsx(CircularProgress, { color: "inherit", size: 20 }),
239
+ params.InputProps.endAdornment
240
+ ] })
241
+ })
242
+ })
243
+ )
244
+ },
245
+ `autocomplete-${saveAttributeName}`
246
+ ) });
247
+ };
248
+ const SearchableSelectChipsControlRecordContextView = ({
249
+ attribute,
250
+ resourceConfig
251
+ }) => {
252
+ const record = useRecordContext();
253
+ const values = Array.isArray(record[attribute.listAttribute || attribute.attribute]) ? record[attribute.listAttribute || attribute.attribute] : [record[attribute.listAttribute || attribute.attribute]];
254
+ return /* @__PURE__ */ jsx(Fragment, { children: record && /* @__PURE__ */ jsx(Box, { sx: { width: "100%" }, children: values.map((item) => /* @__PURE__ */ jsx(
255
+ Chip,
256
+ {
257
+ label: item.name,
258
+ sx: { margin: 0.5 }
259
+ },
260
+ item.id
261
+ )) }) });
262
+ };
263
+ const SearchableSelectChipsControlRecordContext = (_a) => {
264
+ var _b = _a, { method, attribute, resourceConfig } = _b, props = __objRest(_b, ["method", "attribute", "resourceConfig"]);
265
+ switch (method) {
266
+ case "edit":
267
+ case "create":
268
+ return /* @__PURE__ */ jsx(
269
+ SearchableSelectChipsControlRecordContextEdit,
270
+ __spreadValues({
271
+ resourceConfig,
272
+ attribute,
273
+ method
274
+ }, props)
275
+ );
276
+ case "view":
277
+ case "list":
278
+ return /* @__PURE__ */ jsx(
279
+ SearchableSelectChipsControlRecordContextView,
280
+ __spreadValues({
281
+ resourceConfig,
282
+ attribute,
283
+ method
284
+ }, props)
285
+ );
286
+ default:
287
+ return null;
288
+ }
289
+ };
290
+ var RASearchableSelectChipsRecordContext_default = SearchableSelectChipsControlRecordContext;
291
+ export {
292
+ SearchableSelectChipsControlRecordContextEdit,
293
+ SearchableSelectChipsControlRecordContextView,
294
+ RASearchableSelectChipsRecordContext_default as default
295
+ };
@@ -1 +1,202 @@
1
- import{Fragment as b,jsx as o,jsxs as C}from"react/jsx-runtime";import{Autocomplete as K,Box as Q,CircularProgress as A,TextField as X}from"@mui/material";import{useEffect as G,useState as c}from"react";import{useController as H}from"react-hook-form";import{useGetList as R}from"react-admin";import{isArray as _}from"lodash";const j=function({...D}){const{isMultiple:u=!1,minSearch:V=3,timerSearch:E=500,resource:F,selectLabel:I,renderText:d,transformData:g,queryFilter:P="q",defaultValues:r=void 0,elementKeyId:v="id",isEmpty:k=!1,filter:q,isOptionEqualToValue:h=(e,t)=>t===e,renderAttribute:f=null,name:S,onChange:x,renderInputTextFieldProps:M}=D,[O,T]=c(!1),[a,m]=c(null),[y,L]=c(""),l=H({name:S,defaultValue:r||null}),w=r&&_(r)?r.map(e=>e[v]?e[v]:e):r,{data:p,isLoading:s}=R(F,{filter:{[P]:y,...q,includes:w}},{refetchOnWindowFocus:!1});G(()=>(p&&!s&&(a&&m([...a,...p.map(e=>({...e,key:"option"+e.id}))]),m(p.map(e=>({...e,key:"option"+e.id})))),()=>m([])),[p,s]);const[B,W]=c(void 0),z=(e,t=500)=>{clearTimeout(B),W(setTimeout(()=>{e()},t))},J=(()=>{let e=null;return u&&(e=[]),u&&l.field.value&&Array.isArray(l.field.value)&&(e=l.field.value),u&&l.field.value&&!Array.isArray(l.field.value)&&(e=[l.field.value]),!u&&l.field.value&&(e=l.field.value),e})();return C(b,{children:[s&&!a?o(A,{color:"inherit",size:20}):o(b,{}),a&&o(K,{multiple:u,loading:s&&O,fullWidth:!0,freeSolo:!0,options:a,open:O,onOpen:()=>T(!0),onClose:()=>T(!1),defaultValue:J,isOptionEqualToValue:h,autoHighlight:!0,getOptionLabel:e=>{const t=Array.isArray(e)?e:a&&a.find(i=>h(i,l.field.value));if(!t)return y;const n=f&&!d?t[f]:d(t);return n||y},renderOption:(e,t)=>{const{key:n,...i}=e;return o(Q,{component:"li",sx:{"& > img":{mr:2,flexShrink:0}},...i,children:f&&!d?t[f]:d(t)},t.key)},onChange:(e,t)=>{let n=t;Array.isArray(t)&&(n=k?[...t,...l.field.value]:[...new Map(n.map(i=>[i.id,i])).values()]),g?l.field.onChange(g(n)):l.field.onChange(n),x&&x(n)},renderInput:e=>o(X,{...e,label:I,variant:"outlined",onChange:t=>{const n=t.target.value;n&&n!==""&&n.length>=V&&z(()=>L(n),E)},InputProps:{...e.InputProps,autoComplete:"new-password",endAdornment:C(b,{children:[s?o(A,{color:"inherit",size:20}):null,e.InputProps.endAdornment]})},...M},e.id)},"autocomplete-"+S)]})};var re=j;export{re 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
+ CircularProgress,
37
+ TextField
38
+ } from "@mui/material";
39
+ import { useEffect, useState } from "react";
40
+ import { useController } from "react-hook-form";
41
+ import { useGetList } from "react-admin";
42
+ import { isArray } from "lodash";
43
+ const SearchableSelect = function WrappedAutoComplete(_a) {
44
+ var props = __objRest(_a, []);
45
+ const {
46
+ isMultiple = false,
47
+ //pagination = true,
48
+ //searchResults = 50,
49
+ minSearch = 3,
50
+ timerSearch = 500,
51
+ resource,
52
+ selectLabel,
53
+ renderText,
54
+ transformData,
55
+ queryFilter = "q",
56
+ defaultValues = void 0,
57
+ elementKeyId = "id",
58
+ isEmpty = false,
59
+ filter,
60
+ isOptionEqualToValue = (option, value) => value === option,
61
+ renderAttribute = null,
62
+ name,
63
+ onChange,
64
+ renderInputTextFieldProps
65
+ //..._rest
66
+ } = props;
67
+ const [open, setOpen] = useState(false);
68
+ const [parsedOptions, setParsedOptions] = useState(null);
69
+ const [q, setQ] = useState("");
70
+ const field = useController({
71
+ name,
72
+ defaultValue: defaultValues ? defaultValues : null
73
+ });
74
+ const includes = defaultValues && isArray(defaultValues) ? defaultValues.map((element) => element[elementKeyId] ? element[elementKeyId] : element) : defaultValues;
75
+ const {
76
+ data: resourceData,
77
+ isLoading
78
+ } = useGetList(
79
+ resource,
80
+ {
81
+ filter: __spreadProps(__spreadValues({ [queryFilter]: q }, filter), { includes })
82
+ },
83
+ { refetchOnWindowFocus: false }
84
+ );
85
+ useEffect(() => {
86
+ if (resourceData && !isLoading) {
87
+ if (parsedOptions)
88
+ setParsedOptions([
89
+ ...parsedOptions,
90
+ ...resourceData.map((ele) => {
91
+ return __spreadProps(__spreadValues({}, ele), { key: "option" + ele.id });
92
+ })
93
+ ]);
94
+ setParsedOptions(
95
+ resourceData.map((ele) => {
96
+ return __spreadProps(__spreadValues({}, ele), { key: "option" + ele.id });
97
+ })
98
+ );
99
+ }
100
+ return () => setParsedOptions([]);
101
+ }, [resourceData, isLoading]);
102
+ const [timeOutSearch, setTimeOutSearch] = useState(void 0);
103
+ const debounce = (fn, delay = 500) => {
104
+ clearTimeout(timeOutSearch);
105
+ setTimeOutSearch(
106
+ setTimeout(() => {
107
+ fn();
108
+ }, delay)
109
+ );
110
+ };
111
+ const calculateDefaultValue = () => {
112
+ let value = null;
113
+ if (isMultiple) value = [];
114
+ if (isMultiple && field.field.value && Array.isArray(field.field.value))
115
+ value = field.field.value;
116
+ if (isMultiple && field.field.value && !Array.isArray(field.field.value))
117
+ value = [field.field.value];
118
+ if (!isMultiple && field.field.value) value = field.field.value;
119
+ return value;
120
+ };
121
+ const defaultValue = calculateDefaultValue();
122
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
123
+ isLoading && !parsedOptions ? /* @__PURE__ */ jsx(CircularProgress, { color: "inherit", size: 20 }) : /* @__PURE__ */ jsx(Fragment, {}),
124
+ parsedOptions && /* @__PURE__ */ jsx(
125
+ Autocomplete,
126
+ {
127
+ multiple: isMultiple,
128
+ loading: isLoading && open,
129
+ fullWidth: true,
130
+ freeSolo: true,
131
+ options: parsedOptions,
132
+ open,
133
+ onOpen: () => setOpen(true),
134
+ onClose: () => setOpen(false),
135
+ defaultValue,
136
+ isOptionEqualToValue,
137
+ autoHighlight: true,
138
+ getOptionLabel: (option) => {
139
+ const _option = !Array.isArray(option) ? parsedOptions && parsedOptions.find((ele) => isOptionEqualToValue(ele, field.field.value)) : option;
140
+ if (!_option) return q;
141
+ const r = renderAttribute && !renderText ? _option[renderAttribute] : renderText(_option);
142
+ if (!r) return q;
143
+ return r;
144
+ },
145
+ renderOption: (p, option) => {
146
+ const _a2 = p, { key } = _a2, newProps = __objRest(_a2, ["key"]);
147
+ return /* @__PURE__ */ jsx(
148
+ Box,
149
+ __spreadProps(__spreadValues({
150
+ component: "li",
151
+ sx: { "& > img": { mr: 2, flexShrink: 0 } }
152
+ }, newProps), {
153
+ children: renderAttribute && !renderText ? option[renderAttribute] : renderText(option)
154
+ }),
155
+ option.key
156
+ );
157
+ },
158
+ onChange: (event, rawValue) => {
159
+ let newValue = rawValue;
160
+ if (Array.isArray(rawValue)) {
161
+ newValue = isEmpty ? [...rawValue, ...field.field.value] : [...new Map(newValue.map((v) => [v.id, v])).values()];
162
+ }
163
+ if (transformData) {
164
+ field.field.onChange(transformData(newValue));
165
+ } else {
166
+ field.field.onChange(newValue);
167
+ }
168
+ if (onChange) {
169
+ onChange(newValue);
170
+ }
171
+ },
172
+ renderInput: (params) => {
173
+ return /* @__PURE__ */ jsx(
174
+ TextField,
175
+ __spreadValues(__spreadProps(__spreadValues({}, params), {
176
+ label: selectLabel,
177
+ variant: "outlined",
178
+ onChange: (ev) => {
179
+ const searchValue = ev.target.value;
180
+ if (searchValue && searchValue !== "" && searchValue.length >= minSearch)
181
+ debounce(() => setQ(searchValue), timerSearch);
182
+ },
183
+ InputProps: __spreadProps(__spreadValues({}, params.InputProps), {
184
+ autoComplete: "new-password",
185
+ endAdornment: /* @__PURE__ */ jsxs(Fragment, { children: [
186
+ isLoading ? /* @__PURE__ */ jsx(CircularProgress, { color: "inherit", size: 20 }) : null,
187
+ params.InputProps.endAdornment
188
+ ] })
189
+ })
190
+ }), renderInputTextFieldProps),
191
+ params.id
192
+ );
193
+ }
194
+ },
195
+ "autocomplete-" + name
196
+ )
197
+ ] });
198
+ };
199
+ var SearchableSelect_default = SearchableSelect;
200
+ export {
201
+ SearchableSelect_default as default
202
+ };