@dashadmin/dash-components 1.3.25 → 1.3.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/components/AuditLog/AuditLog.js +345 -1
  2. package/dist/components/AuditLog/index.js +4 -1
  3. package/dist/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.js +630 -3
  4. package/dist/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.js +53 -1
  5. package/dist/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.js +647 -3
  6. package/dist/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.js +53 -1
  7. package/dist/components/Json/Json.js +235 -1
  8. package/dist/components/JsonColorSelector/JsonColorSelector.js +1172 -1
  9. package/dist/components/JsonColorSelector/JsonColorSelectorEnhanced.js +863 -2
  10. package/dist/components/JsonColorSelector/JsonCssVarValues.js +738 -1
  11. package/dist/components/JsonColorSelector/components/ColorEditDialog.js +426 -1
  12. package/dist/components/JsonColorSelector/components/ColorPaletteItem.js +75 -1
  13. package/dist/components/JsonColorSelector/components/ImageColorExtractor.js +283 -1
  14. package/dist/components/JsonColorSelector/helpers/functions.js +101 -1
  15. package/dist/components/JsonColorSelector/useAsyncColorThief.js +105 -1
  16. package/dist/components/ListActive/ListActive.js +126 -1
  17. package/dist/components/ListActive/ListBoolean.js +124 -1
  18. package/dist/components/NotificationPreferences/NotificationPreferences.js +317 -1
  19. package/dist/components/NotificationPreferences/index.js +7 -1
  20. package/dist/components/SearchableSelects/RASearchableSelect.js +236 -1
  21. package/dist/components/SearchableSelects/RASearchableSelectCheckboxes.js +479 -1
  22. package/dist/components/SearchableSelects/RASearchableSelectChips.js +465 -1
  23. package/dist/components/SearchableSelects/RASearchableSelectChipsRecordContext.js +295 -1
  24. package/dist/components/SearchableSelects/SearchableSelect.js +202 -1
  25. package/dist/components/SearchableSelects/SearchableSelectCheckboxes.js +290 -1
  26. package/dist/components/SortableDataGrid/SortableDataGrid.js +72 -1
  27. package/dist/components/SortableDataGrid/SortableDataGridBody.js +167 -1
  28. package/dist/components/SortableDataGrid/SortableDataGridHeader.js +109 -1
  29. package/dist/components/SortableDataGrid/SortableDataGridRow.js +283 -1
  30. package/dist/components/Upload/SingleImageUploader.js +40 -1
  31. package/dist/components/custom/PackageCopyMethod.js +78 -1
  32. package/dist/components/custom/PackageRadioButtonGroup.js +45 -1
  33. package/dist/components/dialog/Basic.js +8 -1
  34. package/dist/components/dialog/Correct.js +14 -1
  35. package/dist/components/dialog/Error.js +14 -1
  36. package/dist/components/dialog/Info.js +14 -1
  37. package/dist/components/dialog/InfoV2.js +21 -1
  38. package/dist/components/dialog/NotFound.js +14 -1
  39. package/dist/components/dialog/QuickSearch.js +117 -1
  40. package/dist/components/notifications/NotificationsCenter.js +597 -1
  41. package/dist/components/notifications/index.js +24 -1
  42. package/dist/components/tables/PaginationComponent.js +36 -1
  43. package/dist/components/theme/AppLoadingFallback.js +38 -2
  44. package/dist/components/theme/ErrorBoundary.js +52 -1
  45. package/dist/components/theme/InitialLoader.js +13 -1
  46. package/dist/components/theme/NotFound.js +136 -1
  47. package/dist/components/theme/NotResults.js +38 -1
  48. package/dist/hooks/useDraggable.js +6 -1
  49. package/dist/hooks/useNotifications.js +8 -1
  50. package/dist/hooks/useQuickSearch.js +26 -1
  51. package/dist/index.js +66 -5567
  52. package/dist/utils/setNativeValue.js +17 -1
  53. package/package.json +149 -132
  54. package/src/components/AuditLog/AuditLog.tsx +476 -0
  55. package/src/components/AuditLog/index.ts +2 -0
  56. package/src/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.tsx +917 -0
  57. package/src/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.tsx +39 -0
  58. package/src/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.tsx +916 -0
  59. package/src/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.tsx +44 -0
  60. package/src/components/Json/Json.tsx +312 -0
  61. package/src/components/JsonColorSelector/JsonColorSelector.tsx +1435 -0
  62. package/src/components/JsonColorSelector/JsonColorSelectorEnhanced.tsx +1029 -0
  63. package/src/components/JsonColorSelector/JsonCssVarValues.tsx +863 -0
  64. package/src/components/JsonColorSelector/components/ColorEditDialog.tsx +491 -0
  65. package/src/components/JsonColorSelector/components/ColorPaletteItem.tsx +80 -0
  66. package/src/components/JsonColorSelector/components/ImageColorExtractor.tsx +328 -0
  67. package/src/components/JsonColorSelector/helpers/functions.tsx +123 -0
  68. package/src/components/JsonColorSelector/interfaces/interfaces.tsx +22 -0
  69. package/src/components/JsonColorSelector/useAsyncColorThief.tsx +97 -0
  70. package/src/components/ListActive/ListActive.tsx +106 -0
  71. package/src/components/ListActive/ListBoolean.tsx +96 -0
  72. package/src/components/NotificationPreferences/NotificationPreferences.tsx +463 -0
  73. package/src/components/NotificationPreferences/index.tsx +2 -0
  74. package/src/components/SearchableSelects/RASearchableSelect.tsx +300 -0
  75. package/src/components/SearchableSelects/RASearchableSelectCheckboxes.tsx +604 -0
  76. package/src/components/SearchableSelects/RASearchableSelectChips.tsx +558 -0
  77. package/src/components/SearchableSelects/RASearchableSelectChipsRecordContext.tsx +362 -0
  78. package/src/components/SearchableSelects/SearchableSelect.tsx +321 -0
  79. package/src/components/SearchableSelects/SearchableSelectCheckboxes.tsx +355 -0
  80. package/src/components/SortableDataGrid/SortableDataGrid.tsx +56 -0
  81. package/src/components/SortableDataGrid/SortableDataGridBody.tsx +175 -0
  82. package/src/components/SortableDataGrid/SortableDataGridHeader.tsx +171 -0
  83. package/src/components/SortableDataGrid/SortableDataGridRow.tsx +247 -0
  84. package/src/components/Upload/SingleImageUploader.tsx +55 -0
  85. package/src/components/custom/PackageCopyMethod.tsx +109 -0
  86. package/src/components/custom/PackageRadioButtonGroup.tsx +47 -0
  87. package/src/components/dialog/Basic.tsx +11 -0
  88. package/src/components/dialog/Correct.tsx +16 -0
  89. package/src/components/dialog/Error.tsx +15 -0
  90. package/src/components/dialog/Info.tsx +15 -0
  91. package/src/components/dialog/InfoV2.tsx +35 -0
  92. package/src/components/dialog/NotFound.tsx +18 -0
  93. package/src/components/dialog/QuickSearch.tsx +115 -0
  94. package/src/components/notifications/NotificationsCenter.tsx +792 -0
  95. package/src/components/notifications/index.ts +42 -0
  96. package/src/components/tables/PaginationComponent.tsx +17 -0
  97. package/src/components/theme/AppLoadingFallback.tsx +42 -0
  98. package/src/components/theme/ErrorBoundary.tsx +57 -0
  99. package/src/components/theme/InitialLoader.tsx +16 -0
  100. package/src/components/theme/NotFound.tsx +124 -0
  101. package/src/components/theme/NotResults.tsx +54 -0
  102. package/src/hooks/useDraggable.ts +11 -0
  103. package/src/hooks/useNotifications.ts +14 -0
  104. package/src/hooks/useQuickSearch.tsx +29 -0
  105. package/src/index.tsx +77 -0
  106. package/src/utils/setNativeValue.tsx +23 -0
  107. package/dist/color-thief-CTwGFhOB.js +0 -272
  108. /package/{dist → src}/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayAutoSearch.tsx.wip +0 -0
  109. /package/{dist → src}/components/JsonColorSelector/JsonColorSelector.tsx.bkup +0 -0
  110. /package/{dist → src}/components/SortableDataGrid/README.md +0 -0
  111. /package/{dist → src}/styles/index.less +0 -0
@@ -1,3 +1,647 @@
1
- import{Fragment as Qt,jsx as g,jsxs as xe}from"react/jsx-runtime";import{isValidElement as $,useCallback as z,useEffect as F,useMemo as me,useRef as X,useState as G}from"react";import{isEqual as lt,get as C,debounce as ut}from"lodash";import ct from"clsx";import{Autocomplete as dt,Checkbox as pt,Chip as ft,TextField as gt,Tooltip as mt,createFilterOptions as ht}from"@mui/material";import{styled as yt}from"@mui/material/styles";import{FieldTitle as xt,useChoicesContext as Ct,useInput as Tt,useSuggestions as St,useTimeout as bt,useTranslate as Rt,warning as Ot,useGetRecordRepresentation as It,useEvent as vt,sanitizeInputRestProps as Ft}from"react-admin";import{InputHelperText as Pt,useSupportCreateSuggestion as At}from"react-admin";import Et from"@mui/icons-material/CheckBoxOutlineBlank";import kt from"@mui/icons-material/CheckBox";const wt=g(Et,{fontSize:"small"}),Mt=g(kt,{fontSize:"small"}),Lt=o=>({q:o}),he="RaAutocompleteInput",qt=ht(),ye={textField:`${he}-textField`},zt=yt(dt,{name:he,overridesResolver:(o,r)=>r.root})(({theme:o})=>({[`& .${ye.textField}`]:{minWidth:o.spacing(20)}})),K=(o=[],r,s="id",l)=>l?(Array.isArray(r??[])?r:[r]).map(a=>o.find(m=>String(a)===String(C(m,s)))).filter(a=>!!a):o.find(a=>String(C(a,s))===String(r))||"",Bt=(o,r,s="id",l)=>{if(l){const a=o??[],m=r??[];return a.length!==m.length?!1:!a.map(u=>m.some(B=>C(B,s)===C(u,s))).some(u=>u===!1)}return C(o,s)===C(r,s)},Dt=(o,{choices:r,multiple:s,optionValue:l})=>{const a=X(K(r,o,l,s)),[m,E]=G(()=>K(r,o,l,s));return F(()=>{const u=K(r,o,l,s);Bt(a.current,u,l,s)||(a.current=u,E(u))},[r,o,s,l]),m||null},_t=o=>{const{choices:r,className:s,blurOnSelect:l=!1,clearOnBlur:a=!1,selectOnFocus:m=!0,openOnFocus:E=!0,renderTags:u,disableCloseOnSelect:B=!0,filterSelectedOptions:Ce=!1,renderOption:Nt=null,clearText:j="ra.action.clear_input_value",closeText:J="ra.action.close",create:k,createLabel:Te,createItemLabel:Se,createValue:be,debounce:Y=250,defaultValue:Re,emptyText:b,emptyValue:h="",field:Oe,format:Ie,helperText:Z,id:ve,inputText:P,isFetching:Fe,isLoading:Pe,isRequired:Ae,label:Ee,limitChoicesToValue:w,matchSuggestion:R,margin:ke,fieldState:we,filterToQuery:Me=Lt,formState:Le,multiple:d=!1,noOptionsText:O,onBlur:qe,onChange:ze,onCreate:M,openText:ee="ra.action.open",optionText:i,optionValue:I,parse:Be,resource:te,shouldRenderSuggestions:L,setFilter:D,size:De,source:_e,suggestionLimit:_=1/0,TextFieldProps:Qe,translateChoice:Ne,validate:Ve,variant:We,...ne}=o,He=vt(Me),q=X(null),{allChoices:Q,isLoading:Ue,error:N,resource:oe,source:V,setFilters:re,isFromReference:T}=Ct({choices:r,isFetching:Fe,isLoading:Pe,resource:te,source:_e}),v=Rt(),{id:$e,field:c,isRequired:W,fieldState:{error:Xe,invalid:ie,isTouched:se},formState:{isSubmitted:ae}}=Tt({defaultValue:Re,id:ve,field:Oe,fieldState:we,formState:Le,isRequired:Ae,onBlur:qe,onChange:ze,parse:Be,format:Ie,resource:oe,source:V,validate:Ve,...ne}),p=me(()=>b==null||W||d?Q:[{[I||"id"]:h,[typeof i=="string"?i:"name"]:v(b,{_:b})}].concat(Q),[Q,h,b,W,d,i,I,v]),f=Dt(c.value,{choices:p,multiple:d,optionValue:I});F(()=>{if(h==null)throw new Error("emptyValue being set to null or undefined is not supported. Use parse to turn the empty string into null.")},[h]),F(()=>{if($(i)&&b!=null)throw new Error("optionText of type React element is not supported when setting emptyText");if($(i)&&P==null)throw new Error(`
2
- If you provided a React element for the optionText prop, you must also provide the inputText prop (used for the text input)`);if($(i)&&!T&&R==null)throw new Error(`
3
- If you provided a React element for the optionText prop, you must also provide the matchSuggestion prop (used to match the user input with a choice)`)},[i,P,R,b,T]),F(()=>{Ot(L!=null&&O==null,"When providing a shouldRenderSuggestions function, we recommend you also provide the noOptionsText prop and set it to a text explaining users why no options are displayed. It supports translation keys.")},[L,O]);const Ge=It(oe),{getChoiceText:le,getChoiceValue:A,getSuggestions:ue}=St({choices:p,limitChoicesToValue:w,matchSuggestion:R,optionText:i??(T?Ge:void 0),optionValue:I,selectedItem:f,suggestionLimit:_,translateChoice:Ne??!T}),[S,ce]=G(""),[H,de]=G(null),Ke=e=>{let t;if(d?Array.isArray(e)?t=e.map(A):t=[...c.value??[],A(e)]:t=A(e)??h,q.current[1]==="clear"){c.onChange(t);return}if(q.current[0].currentTarget.nodeName==="svg"){c.onChange(t);return}if(q.current[1]==="removeOption"){de(n=>t.filter(x=>!new Set(H).has(x)));return}de(n=>Array.from(n?new Set([...n,...t]):new Set([...t])))},pe=z(ut(e=>{if(D)return D(e);r||re(He(e),[],!0)},Y),[Y,re,D]),fe=X(c.value);F(()=>{lt(fe.current,c.value)||(fe.current=c.value,pe(""))},[c.value]);const{getCreateItem:je,handleChange:Je,createElement:Ye,createId:ge}=At({create:k,createLabel:Te,createItemLabel:Se,createValue:be,handleChange:Ke,filter:S,onCreate:M,optionText:i}),y=z((e,t=!1)=>e==null?"":typeof e=="string"?e:e?.id===ge?C(e,typeof i=="string"?i:"name"):!t&&e[I||"id"]===h?C(e,typeof i=="string"?i:"name"):!t&&P!==void 0?P(e):le(e),[le,P,ge,i,I,h]);F(()=>{if(!d){const e=y(f);if(typeof e=="string")ce(e);else throw new Error("When optionText returns a React element, you must also provide the inputText prop")}},[y,d,f]);const U=z(e=>{let t;return d?t=f.map(n=>y(n)):t=[y(f)],t.includes(e)},[y,d,f]),Ze=z(e=>{const t=p?p.some(n=>y(n)===e):!1;return U(e)||t},[p,y,U]),et=(e,t,n)=>{(e?.type==="change"||!U(t))&&(ce(t),pe(t))},tt=(e,t)=>{let n=T||R||w?e:qt(e,t);const{inputValue:x}=t;return(M||k)&&x!==""&&!Ze(S)&&(n=n.concat(je(x))),n},nt=(e,t,n)=>{q.current=[e,n],Je(t!==null?t:h)},ot=bt(1e3,S),rt=me(()=>!T&&(R||w)?ue(S):p?.slice(0,_)||[],[p,S,ue,w,R,_,T]),it=(e,t)=>String(A(e))===String(A(t)),st=!!N||Z!==!1||(se||ae)&&ie;return xe(Qt,{children:[g(zt,{className:ct("ra-input",`ra-input-${V}`,s),clearText:v(j,{_:j}),closeText:v(J,{_:J}),openText:v(ee,{_:ee}),id:$e,isOptionEqualToValue:it,blurOnSelect:l,clearOnBlur:a,selectOnFocus:m,openOnFocus:E,disableCloseOnSelect:B,filterSelectedOptions:Ce,renderInput:e=>g(gt,{name:c.name,label:g(xt,{label:Ee,source:V,resource:te,isRequired:W}),error:!!N||(se||ae)&&ie,helperText:st?g(Pt,{error:Xe?.message||N?.message,helperText:Z}):null,margin:ke,variant:We,className:ye.textField,...Qe,...e,size:De}),multiple:d,renderTags:u||((e,t)=>{const n=i;return g(mt,{title:e.map(x=>x[n]).join(" , "),children:g(ft,{label:e[0][n]+(e.length>1?" +"+(e.length-1):""),sx:{".MuiSvgIcon-root":{zIndex:100}},variant:"filled",size:"small"})})}),noOptionsText:typeof O=="string"?v(O,{_:O}):O,...Ft(ne),freeSolo:!!k||!!M,handleHomeEndKeys:!!k||!!M,filterOptions:tt,options:L==null||L(S)?rt:[],getOptionLabel:y,inputValue:S,loading:Ue&&(!p||p.length===0)&&ot,value:f,onChange:(e,t,n)=>{nt(e,t,n)},onInputChange:et,clearOnEscape:!1,renderOption:(e,t,{selected:n})=>{const x=f&&f.find(at=>at.id===t.id)?!0:n;return xe("li",{...e,children:[g(pt,{icon:wt,checkedIcon:Mt,style:{marginRight:8},defaultChecked:x}),t[i]]})},onClose:()=>{H&&c.onChange(H)}}),Ye]})};var ln=_t;export{ye as AutocompleteInputClasses,ln 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
+ isValidElement,
35
+ useCallback,
36
+ useEffect,
37
+ useMemo,
38
+ useRef,
39
+ useState
40
+ } from "react";
41
+ import { isEqual, get, debounce } from "lodash";
42
+ import clsx from "clsx";
43
+ import {
44
+ Autocomplete,
45
+ Checkbox,
46
+ Chip,
47
+ TextField,
48
+ Tooltip,
49
+ createFilterOptions
50
+ } from "@mui/material";
51
+ import { styled } from "@mui/material/styles";
52
+ import {
53
+ FieldTitle,
54
+ useChoicesContext,
55
+ useInput,
56
+ useSuggestions,
57
+ useTimeout,
58
+ useTranslate,
59
+ warning,
60
+ useGetRecordRepresentation,
61
+ useEvent,
62
+ sanitizeInputRestProps
63
+ } from "react-admin";
64
+ import {
65
+ InputHelperText,
66
+ useSupportCreateSuggestion
67
+ } from "react-admin";
68
+ import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank";
69
+ import CheckBoxIcon from "@mui/icons-material/CheckBox";
70
+ const icon = /* @__PURE__ */ jsx(CheckBoxOutlineBlankIcon, { fontSize: "small" });
71
+ const checkedIcon = /* @__PURE__ */ jsx(CheckBoxIcon, { fontSize: "small" });
72
+ const DefaultFilterToQuery = (searchText) => ({ q: searchText });
73
+ const PREFIX = "RaAutocompleteInput";
74
+ const defaultFilterOptions = createFilterOptions();
75
+ const AutocompleteInputClasses = {
76
+ textField: `${PREFIX}-textField`
77
+ };
78
+ const StyledAutocomplete = styled(Autocomplete, {
79
+ name: PREFIX,
80
+ overridesResolver: (props, styles) => styles.root
81
+ })(({ theme }) => ({
82
+ [`& .${AutocompleteInputClasses.textField}`]: {
83
+ minWidth: theme.spacing(20)
84
+ }
85
+ }));
86
+ const getSelectedItems = (choices = [], value, optionValue = "id", multiple) => {
87
+ if (multiple) {
88
+ return (Array.isArray(value != null ? value : []) ? value : [value]).map(
89
+ (item) => choices.find(
90
+ (choice) => String(item) === String(get(choice, optionValue))
91
+ )
92
+ ).filter((item) => !!item);
93
+ }
94
+ return choices.find(
95
+ (choice) => String(get(choice, optionValue)) === String(value)
96
+ ) || "";
97
+ };
98
+ const areSelectedItemsEqual = (selectedChoice, newSelectedChoice, optionValue = "id", multiple) => {
99
+ if (multiple) {
100
+ const selectedChoiceArray = selectedChoice != null ? selectedChoice : [];
101
+ const newSelectedChoiceArray = newSelectedChoice != null ? newSelectedChoice : [];
102
+ if (selectedChoiceArray.length !== newSelectedChoiceArray.length) {
103
+ return false;
104
+ }
105
+ const equalityArray = selectedChoiceArray.map(
106
+ (choice) => newSelectedChoiceArray.some(
107
+ (newChoice) => get(newChoice, optionValue) === get(choice, optionValue)
108
+ )
109
+ );
110
+ return !equalityArray.some((item) => item === false);
111
+ }
112
+ return get(selectedChoice, optionValue) === get(newSelectedChoice, optionValue);
113
+ };
114
+ const useSelectedChoice = (value, {
115
+ choices,
116
+ multiple,
117
+ optionValue
118
+ }) => {
119
+ const selectedChoiceRef = useRef(
120
+ getSelectedItems(choices, value, optionValue, multiple)
121
+ );
122
+ const [selectedChoice, setSelectedChoice] = useState(
123
+ () => getSelectedItems(choices, value, optionValue, multiple)
124
+ );
125
+ useEffect(() => {
126
+ const newSelectedItems = getSelectedItems(
127
+ choices,
128
+ value,
129
+ optionValue,
130
+ multiple
131
+ );
132
+ if (!areSelectedItemsEqual(
133
+ selectedChoiceRef.current,
134
+ newSelectedItems,
135
+ optionValue,
136
+ multiple
137
+ )) {
138
+ selectedChoiceRef.current = newSelectedItems;
139
+ setSelectedChoice(newSelectedItems);
140
+ }
141
+ }, [choices, value, multiple, optionValue]);
142
+ return selectedChoice || null;
143
+ };
144
+ const AutocompleteCheckBoxInput = (props) => {
145
+ const _a = props, {
146
+ choices: choicesProp,
147
+ className,
148
+ blurOnSelect = false,
149
+ clearOnBlur = false,
150
+ selectOnFocus = true,
151
+ openOnFocus = true,
152
+ renderTags,
153
+ disableCloseOnSelect = true,
154
+ filterSelectedOptions = false,
155
+ renderOption: renderOption = null,
156
+ clearText = "ra.action.clear_input_value",
157
+ closeText = "ra.action.close",
158
+ create,
159
+ createLabel,
160
+ createItemLabel,
161
+ createValue,
162
+ debounce: debounceDelay = 250,
163
+ defaultValue,
164
+ emptyText,
165
+ emptyValue = "",
166
+ field: fieldOverride,
167
+ format,
168
+ helperText,
169
+ id: idOverride,
170
+ inputText,
171
+ isFetching: isFetchingProp,
172
+ isLoading: isLoadingProp,
173
+ isRequired: isRequiredOverride,
174
+ label,
175
+ limitChoicesToValue,
176
+ matchSuggestion,
177
+ margin,
178
+ fieldState: fieldStateOverride,
179
+ filterToQuery: filterToQueryProp = DefaultFilterToQuery,
180
+ formState: formStateOverride,
181
+ multiple = false,
182
+ noOptionsText,
183
+ onBlur,
184
+ onChange,
185
+ onCreate,
186
+ openText = "ra.action.open",
187
+ optionText,
188
+ optionValue,
189
+ parse,
190
+ resource: resourceProp,
191
+ shouldRenderSuggestions,
192
+ setFilter,
193
+ size,
194
+ source: sourceProp,
195
+ suggestionLimit = Infinity,
196
+ TextFieldProps: TextFieldProps2,
197
+ translateChoice,
198
+ validate,
199
+ variant
200
+ } = _a, rest = __objRest(_a, [
201
+ "choices",
202
+ "className",
203
+ "blurOnSelect",
204
+ "clearOnBlur",
205
+ "selectOnFocus",
206
+ "openOnFocus",
207
+ "renderTags",
208
+ "disableCloseOnSelect",
209
+ "filterSelectedOptions",
210
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
211
+ "renderOption",
212
+ "clearText",
213
+ "closeText",
214
+ "create",
215
+ "createLabel",
216
+ "createItemLabel",
217
+ "createValue",
218
+ "debounce",
219
+ "defaultValue",
220
+ "emptyText",
221
+ "emptyValue",
222
+ "field",
223
+ "format",
224
+ "helperText",
225
+ "id",
226
+ "inputText",
227
+ "isFetching",
228
+ "isLoading",
229
+ "isRequired",
230
+ "label",
231
+ "limitChoicesToValue",
232
+ "matchSuggestion",
233
+ "margin",
234
+ "fieldState",
235
+ "filterToQuery",
236
+ "formState",
237
+ "multiple",
238
+ "noOptionsText",
239
+ "onBlur",
240
+ "onChange",
241
+ "onCreate",
242
+ "openText",
243
+ "optionText",
244
+ "optionValue",
245
+ "parse",
246
+ "resource",
247
+ "shouldRenderSuggestions",
248
+ "setFilter",
249
+ "size",
250
+ "source",
251
+ "suggestionLimit",
252
+ // eslint-disable-next-line @typescript-eslint/no-shadow
253
+ "TextFieldProps",
254
+ "translateChoice",
255
+ "validate",
256
+ "variant"
257
+ ]);
258
+ const filterToQuery = useEvent(filterToQueryProp);
259
+ const lastOnChangeEvent = useRef(null);
260
+ const {
261
+ allChoices,
262
+ isLoading,
263
+ error: fetchError,
264
+ resource,
265
+ source,
266
+ setFilters,
267
+ isFromReference
268
+ } = useChoicesContext({
269
+ choices: choicesProp,
270
+ isFetching: isFetchingProp,
271
+ isLoading: isLoadingProp,
272
+ resource: resourceProp,
273
+ source: sourceProp
274
+ });
275
+ const translate = useTranslate();
276
+ const {
277
+ id,
278
+ field,
279
+ isRequired,
280
+ fieldState: { error, invalid, isTouched },
281
+ formState: { isSubmitted }
282
+ } = useInput(__spreadValues({
283
+ defaultValue,
284
+ id: idOverride,
285
+ field: fieldOverride,
286
+ fieldState: fieldStateOverride,
287
+ formState: formStateOverride,
288
+ isRequired: isRequiredOverride,
289
+ onBlur,
290
+ onChange,
291
+ parse,
292
+ format,
293
+ resource,
294
+ source,
295
+ validate
296
+ }, rest));
297
+ const finalChoices = useMemo(
298
+ () => (
299
+ // eslint-disable-next-line eqeqeq
300
+ emptyText == void 0 || isRequired || multiple ? allChoices : [
301
+ {
302
+ [optionValue || "id"]: emptyValue,
303
+ [typeof optionText === "string" ? optionText : "name"]: translate(
304
+ emptyText,
305
+ {
306
+ _: emptyText
307
+ }
308
+ )
309
+ }
310
+ ].concat(allChoices)
311
+ ),
312
+ [
313
+ allChoices,
314
+ emptyValue,
315
+ emptyText,
316
+ isRequired,
317
+ multiple,
318
+ optionText,
319
+ optionValue,
320
+ translate
321
+ ]
322
+ );
323
+ const selectedChoice = useSelectedChoice(field.value, {
324
+ choices: finalChoices,
325
+ // @ts-ignore Expected.
326
+ multiple,
327
+ optionValue
328
+ });
329
+ useEffect(() => {
330
+ if (emptyValue == null) {
331
+ throw new Error(
332
+ "emptyValue being set to null or undefined is not supported. Use parse to turn the empty string into null."
333
+ );
334
+ }
335
+ }, [emptyValue]);
336
+ useEffect(() => {
337
+ if (isValidElement(optionText) && emptyText != void 0) {
338
+ throw new Error(
339
+ "optionText of type React element is not supported when setting emptyText"
340
+ );
341
+ }
342
+ if (isValidElement(optionText) && inputText == void 0) {
343
+ throw new Error(`
344
+ If you provided a React element for the optionText prop, you must also provide the inputText prop (used for the text input)`);
345
+ }
346
+ if (isValidElement(optionText) && !isFromReference && // eslint-disable-next-line eqeqeq
347
+ matchSuggestion == void 0) {
348
+ throw new Error(`
349
+ If you provided a React element for the optionText prop, you must also provide the matchSuggestion prop (used to match the user input with a choice)`);
350
+ }
351
+ }, [optionText, inputText, matchSuggestion, emptyText, isFromReference]);
352
+ useEffect(() => {
353
+ warning(
354
+ /* eslint-disable eqeqeq */
355
+ shouldRenderSuggestions != void 0 && noOptionsText == void 0,
356
+ "When providing a shouldRenderSuggestions function, we recommend you also provide the noOptionsText prop and set it to a text explaining users why no options are displayed. It supports translation keys."
357
+ );
358
+ }, [shouldRenderSuggestions, noOptionsText]);
359
+ const getRecordRepresentation = useGetRecordRepresentation(resource);
360
+ const { getChoiceText, getChoiceValue, getSuggestions } = useSuggestions({
361
+ choices: finalChoices,
362
+ limitChoicesToValue,
363
+ matchSuggestion,
364
+ optionText: optionText != null ? optionText : isFromReference ? getRecordRepresentation : void 0,
365
+ optionValue,
366
+ selectedItem: selectedChoice,
367
+ suggestionLimit,
368
+ translateChoice: translateChoice != null ? translateChoice : !isFromReference
369
+ });
370
+ const [filterValue, setFilterValue] = useState("");
371
+ const [pendingState, setPendingState] = useState(null);
372
+ const handleChange = (newValue) => {
373
+ var _a2, _b;
374
+ let processedValue;
375
+ if (multiple) {
376
+ if (Array.isArray(newValue)) {
377
+ processedValue = newValue.map(getChoiceValue);
378
+ } else {
379
+ processedValue = [...(_a2 = field.value) != null ? _a2 : [], getChoiceValue(newValue)];
380
+ }
381
+ } else {
382
+ processedValue = (_b = getChoiceValue(newValue)) != null ? _b : emptyValue;
383
+ }
384
+ if (lastOnChangeEvent.current[1] === "clear") {
385
+ field.onChange(processedValue);
386
+ return;
387
+ }
388
+ if (lastOnChangeEvent.current[0].currentTarget.nodeName === "svg") {
389
+ field.onChange(processedValue);
390
+ return;
391
+ }
392
+ if (lastOnChangeEvent.current[1] === "removeOption") {
393
+ setPendingState(
394
+ (_) => processedValue.filter((x) => !new Set(pendingState).has(x))
395
+ );
396
+ return;
397
+ }
398
+ setPendingState(
399
+ (prevState) => prevState ? Array.from(/* @__PURE__ */ new Set([...prevState, ...processedValue])) : Array.from(/* @__PURE__ */ new Set([...processedValue]))
400
+ );
401
+ };
402
+ const debouncedSetFilter = useCallback(
403
+ debounce((filter) => {
404
+ if (setFilter) {
405
+ return setFilter(filter);
406
+ }
407
+ if (choicesProp) {
408
+ return;
409
+ }
410
+ setFilters(filterToQuery(filter), [], true);
411
+ }, debounceDelay),
412
+ [debounceDelay, setFilters, setFilter]
413
+ );
414
+ const currentValue = useRef(field.value);
415
+ useEffect(() => {
416
+ if (!isEqual(currentValue.current, field.value)) {
417
+ currentValue.current = field.value;
418
+ debouncedSetFilter("");
419
+ }
420
+ }, [field.value]);
421
+ const {
422
+ getCreateItem,
423
+ handleChange: handleChangeWithCreateSupport,
424
+ createElement,
425
+ createId
426
+ } = useSupportCreateSuggestion({
427
+ create,
428
+ createLabel,
429
+ createItemLabel,
430
+ createValue,
431
+ handleChange,
432
+ filter: filterValue,
433
+ onCreate,
434
+ optionText
435
+ });
436
+ const getOptionLabel = useCallback(
437
+ (option, isListItem = false) => {
438
+ if (option == void 0) {
439
+ return "";
440
+ }
441
+ if (typeof option === "string") {
442
+ return option;
443
+ }
444
+ if ((option == null ? void 0 : option.id) === createId) {
445
+ return get(
446
+ option,
447
+ typeof optionText === "string" ? optionText : "name"
448
+ );
449
+ }
450
+ if (!isListItem && option[optionValue || "id"] === emptyValue) {
451
+ return get(
452
+ option,
453
+ typeof optionText === "string" ? optionText : "name"
454
+ );
455
+ }
456
+ if (!isListItem && inputText !== void 0) {
457
+ return inputText(option);
458
+ }
459
+ return getChoiceText(option);
460
+ },
461
+ [getChoiceText, inputText, createId, optionText, optionValue, emptyValue]
462
+ );
463
+ useEffect(() => {
464
+ if (!multiple) {
465
+ const optionLabel = getOptionLabel(selectedChoice);
466
+ if (typeof optionLabel === "string") {
467
+ setFilterValue(optionLabel);
468
+ } else {
469
+ throw new Error(
470
+ "When optionText returns a React element, you must also provide the inputText prop"
471
+ );
472
+ }
473
+ }
474
+ }, [getOptionLabel, multiple, selectedChoice]);
475
+ const doesQueryMatchSelection = useCallback(
476
+ (filter) => {
477
+ let selectedItemTexts;
478
+ if (multiple) {
479
+ selectedItemTexts = selectedChoice.map((item) => getOptionLabel(item));
480
+ } else {
481
+ selectedItemTexts = [getOptionLabel(selectedChoice)];
482
+ }
483
+ return selectedItemTexts.includes(filter);
484
+ },
485
+ [getOptionLabel, multiple, selectedChoice]
486
+ );
487
+ const doesQueryMatchSuggestion = useCallback(
488
+ (filter) => {
489
+ const hasOption = finalChoices ? finalChoices.some((choice) => getOptionLabel(choice) === filter) : false;
490
+ return doesQueryMatchSelection(filter) || hasOption;
491
+ },
492
+ [finalChoices, getOptionLabel, doesQueryMatchSelection]
493
+ );
494
+ const handleInputChange = (event, newInputValue, _reason) => {
495
+ if ((event == null ? void 0 : event.type) === "change" || !doesQueryMatchSelection(newInputValue)) {
496
+ setFilterValue(newInputValue);
497
+ debouncedSetFilter(newInputValue);
498
+ }
499
+ };
500
+ const filterOptions = (options, params) => {
501
+ let filteredOptions = isFromReference || // When used inside a reference, AutocompleteInput shouldn't do the filtering as it's done by the reference input
502
+ matchSuggestion || // When using element as optionText (and matchSuggestion), options are filtered by getSuggestions, so they shouldn't be filtered here
503
+ limitChoicesToValue ? options : defaultFilterOptions(options, params);
504
+ const { inputValue } = params;
505
+ if ((onCreate || create) && inputValue !== "" && !doesQueryMatchSuggestion(filterValue)) {
506
+ filteredOptions = filteredOptions.concat(getCreateItem(inputValue));
507
+ }
508
+ return filteredOptions;
509
+ };
510
+ const handleAutocompleteChange = (event, newValue, _reason) => {
511
+ lastOnChangeEvent.current = [event, _reason];
512
+ handleChangeWithCreateSupport(newValue !== null ? newValue : emptyValue);
513
+ };
514
+ const oneSecondHasPassed = useTimeout(1e3, filterValue);
515
+ const suggestions = useMemo(() => {
516
+ if (!isFromReference && (matchSuggestion || limitChoicesToValue)) {
517
+ return getSuggestions(filterValue);
518
+ }
519
+ return (finalChoices == null ? void 0 : finalChoices.slice(0, suggestionLimit)) || [];
520
+ }, [
521
+ finalChoices,
522
+ filterValue,
523
+ getSuggestions,
524
+ limitChoicesToValue,
525
+ matchSuggestion,
526
+ suggestionLimit,
527
+ isFromReference
528
+ ]);
529
+ const isOptionEqualToValue = (option, value) => {
530
+ return String(getChoiceValue(option)) === String(getChoiceValue(value));
531
+ };
532
+ const renderHelperText = !!fetchError || helperText !== false || (isTouched || isSubmitted) && invalid;
533
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
534
+ /* @__PURE__ */ jsx(
535
+ StyledAutocomplete,
536
+ __spreadProps(__spreadValues({
537
+ className: clsx("ra-input", `ra-input-${source}`, className),
538
+ clearText: translate(clearText, { _: clearText }),
539
+ closeText: translate(closeText, { _: closeText }),
540
+ openText: translate(openText, { _: openText }),
541
+ id,
542
+ isOptionEqualToValue,
543
+ blurOnSelect,
544
+ clearOnBlur,
545
+ selectOnFocus,
546
+ openOnFocus,
547
+ disableCloseOnSelect,
548
+ filterSelectedOptions,
549
+ renderInput: (params) => /* @__PURE__ */ jsx(
550
+ TextField,
551
+ __spreadProps(__spreadValues(__spreadValues({
552
+ name: field.name,
553
+ label: /* @__PURE__ */ jsx(
554
+ FieldTitle,
555
+ {
556
+ label,
557
+ source,
558
+ resource: resourceProp,
559
+ isRequired
560
+ }
561
+ ),
562
+ error: !!fetchError || (isTouched || isSubmitted) && invalid,
563
+ helperText: renderHelperText ? /* @__PURE__ */ jsx(
564
+ InputHelperText,
565
+ {
566
+ error: (error == null ? void 0 : error.message) || (fetchError == null ? void 0 : fetchError.message),
567
+ helperText
568
+ }
569
+ ) : null,
570
+ margin,
571
+ variant,
572
+ className: AutocompleteInputClasses.textField
573
+ }, TextFieldProps2), params), {
574
+ size
575
+ })
576
+ ),
577
+ multiple,
578
+ renderTags: renderTags ? renderTags : (value, getTagProps) => {
579
+ const attribute = optionText;
580
+ return /* @__PURE__ */ jsx(
581
+ Tooltip,
582
+ {
583
+ title: value.map((item) => item[attribute]).join(" , "),
584
+ children: /* @__PURE__ */ jsx(
585
+ Chip,
586
+ {
587
+ label: value[0][attribute] + (value.length > 1 ? " +" + (value.length - 1) : ""),
588
+ sx: {
589
+ ".MuiSvgIcon-root": {
590
+ // FIXME: Workaround to allow choices deletion
591
+ // Maybe related to storybook and mui using different versions of emotion
592
+ zIndex: 100
593
+ }
594
+ },
595
+ variant: "filled",
596
+ size: "small"
597
+ }
598
+ )
599
+ }
600
+ );
601
+ },
602
+ noOptionsText: typeof noOptionsText === "string" ? translate(noOptionsText, { _: noOptionsText }) : noOptionsText
603
+ }, sanitizeInputRestProps(rest)), {
604
+ freeSolo: !!create || !!onCreate,
605
+ handleHomeEndKeys: !!create || !!onCreate,
606
+ filterOptions,
607
+ options: shouldRenderSuggestions == void 0 || // eslint-disable-line eqeqeq
608
+ shouldRenderSuggestions(filterValue) ? suggestions : [],
609
+ getOptionLabel,
610
+ inputValue: filterValue,
611
+ loading: isLoading && (!finalChoices || finalChoices.length === 0) && oneSecondHasPassed,
612
+ value: selectedChoice,
613
+ onChange: (e, val, reason) => {
614
+ handleAutocompleteChange(e, val, reason);
615
+ },
616
+ onInputChange: handleInputChange,
617
+ clearOnEscape: false,
618
+ renderOption: (p, option, { selected }) => {
619
+ const sel = selectedChoice && selectedChoice.find((ele) => ele.id === option.id) ? true : selected;
620
+ return /* @__PURE__ */ jsxs("li", __spreadProps(__spreadValues({}, p), { children: [
621
+ /* @__PURE__ */ jsx(
622
+ Checkbox,
623
+ {
624
+ icon,
625
+ checkedIcon,
626
+ style: { marginRight: 8 },
627
+ defaultChecked: sel
628
+ }
629
+ ),
630
+ option[optionText]
631
+ ] }));
632
+ },
633
+ onClose: () => {
634
+ if (pendingState) {
635
+ field.onChange(pendingState);
636
+ }
637
+ }
638
+ })
639
+ ),
640
+ createElement
641
+ ] });
642
+ };
643
+ var AutoCompleteCheckBoxInput_default = AutocompleteCheckBoxInput;
644
+ export {
645
+ AutocompleteInputClasses,
646
+ AutoCompleteCheckBoxInput_default as default
647
+ };