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