@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.
- package/dist/components/AuditLog/AuditLog.js +345 -1
- package/dist/components/AuditLog/index.js +4 -1
- package/dist/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.js +630 -3
- package/dist/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.js +53 -1
- package/dist/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.js +647 -3
- package/dist/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.js +53 -1
- package/dist/components/Json/Json.js +235 -1
- package/dist/components/JsonColorSelector/JsonColorSelector.js +1172 -1
- package/dist/components/JsonColorSelector/JsonColorSelectorEnhanced.js +863 -2
- package/dist/components/JsonColorSelector/JsonCssVarValues.js +738 -1
- package/dist/components/JsonColorSelector/components/ColorEditDialog.js +426 -1
- package/dist/components/JsonColorSelector/components/ColorPaletteItem.js +75 -1
- package/dist/components/JsonColorSelector/components/ImageColorExtractor.js +283 -1
- package/dist/components/JsonColorSelector/helpers/functions.js +101 -1
- package/dist/components/JsonColorSelector/useAsyncColorThief.js +105 -1
- package/dist/components/ListActive/ListActive.js +126 -1
- package/dist/components/ListActive/ListBoolean.js +124 -1
- package/dist/components/NotificationPreferences/NotificationPreferences.js +317 -1
- package/dist/components/NotificationPreferences/index.js +7 -1
- package/dist/components/SearchableSelects/RASearchableSelect.js +236 -1
- package/dist/components/SearchableSelects/RASearchableSelectCheckboxes.js +479 -1
- package/dist/components/SearchableSelects/RASearchableSelectChips.js +465 -1
- package/dist/components/SearchableSelects/RASearchableSelectChipsRecordContext.js +295 -1
- package/dist/components/SearchableSelects/SearchableSelect.js +202 -1
- package/dist/components/SearchableSelects/SearchableSelectCheckboxes.js +290 -1
- package/dist/components/SortableDataGrid/SortableDataGrid.js +72 -1
- package/dist/components/SortableDataGrid/SortableDataGridBody.js +167 -1
- package/dist/components/SortableDataGrid/SortableDataGridHeader.js +109 -1
- package/dist/components/SortableDataGrid/SortableDataGridRow.js +283 -1
- package/dist/components/Upload/SingleImageUploader.js +40 -1
- package/dist/components/custom/PackageCopyMethod.js +78 -1
- package/dist/components/custom/PackageRadioButtonGroup.js +45 -1
- package/dist/components/dialog/Basic.js +8 -1
- package/dist/components/dialog/Correct.js +14 -1
- package/dist/components/dialog/Error.js +14 -1
- package/dist/components/dialog/Info.js +14 -1
- package/dist/components/dialog/InfoV2.js +21 -1
- package/dist/components/dialog/NotFound.js +14 -1
- package/dist/components/dialog/QuickSearch.js +117 -1
- package/dist/components/notifications/NotificationsCenter.js +597 -1
- package/dist/components/notifications/index.js +24 -1
- package/dist/components/tables/PaginationComponent.js +36 -1
- package/dist/components/theme/AppLoadingFallback.js +38 -2
- package/dist/components/theme/ErrorBoundary.js +52 -1
- package/dist/components/theme/InitialLoader.js +13 -1
- package/dist/components/theme/NotFound.js +136 -1
- package/dist/components/theme/NotResults.js +38 -1
- package/dist/hooks/useDraggable.js +6 -1
- package/dist/hooks/useNotifications.js +8 -1
- package/dist/hooks/useQuickSearch.js +26 -1
- package/dist/index.js +66 -5567
- package/dist/utils/setNativeValue.js +17 -1
- package/package.json +149 -132
- package/src/components/AuditLog/AuditLog.tsx +476 -0
- package/src/components/AuditLog/index.ts +2 -0
- package/src/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.tsx +917 -0
- package/src/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.tsx +39 -0
- package/src/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.tsx +916 -0
- package/src/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.tsx +44 -0
- package/src/components/Json/Json.tsx +312 -0
- package/src/components/JsonColorSelector/JsonColorSelector.tsx +1435 -0
- package/src/components/JsonColorSelector/JsonColorSelectorEnhanced.tsx +1029 -0
- package/src/components/JsonColorSelector/JsonCssVarValues.tsx +863 -0
- package/src/components/JsonColorSelector/components/ColorEditDialog.tsx +491 -0
- package/src/components/JsonColorSelector/components/ColorPaletteItem.tsx +80 -0
- package/src/components/JsonColorSelector/components/ImageColorExtractor.tsx +328 -0
- package/src/components/JsonColorSelector/helpers/functions.tsx +123 -0
- package/src/components/JsonColorSelector/interfaces/interfaces.tsx +22 -0
- package/src/components/JsonColorSelector/useAsyncColorThief.tsx +97 -0
- package/src/components/ListActive/ListActive.tsx +106 -0
- package/src/components/ListActive/ListBoolean.tsx +96 -0
- package/src/components/NotificationPreferences/NotificationPreferences.tsx +463 -0
- package/src/components/NotificationPreferences/index.tsx +2 -0
- package/src/components/SearchableSelects/RASearchableSelect.tsx +300 -0
- package/src/components/SearchableSelects/RASearchableSelectCheckboxes.tsx +604 -0
- package/src/components/SearchableSelects/RASearchableSelectChips.tsx +558 -0
- package/src/components/SearchableSelects/RASearchableSelectChipsRecordContext.tsx +362 -0
- package/src/components/SearchableSelects/SearchableSelect.tsx +321 -0
- package/src/components/SearchableSelects/SearchableSelectCheckboxes.tsx +355 -0
- package/src/components/SortableDataGrid/SortableDataGrid.tsx +56 -0
- package/src/components/SortableDataGrid/SortableDataGridBody.tsx +175 -0
- package/src/components/SortableDataGrid/SortableDataGridHeader.tsx +171 -0
- package/src/components/SortableDataGrid/SortableDataGridRow.tsx +247 -0
- package/src/components/Upload/SingleImageUploader.tsx +55 -0
- package/src/components/custom/PackageCopyMethod.tsx +109 -0
- package/src/components/custom/PackageRadioButtonGroup.tsx +47 -0
- package/src/components/dialog/Basic.tsx +11 -0
- package/src/components/dialog/Correct.tsx +16 -0
- package/src/components/dialog/Error.tsx +15 -0
- package/src/components/dialog/Info.tsx +15 -0
- package/src/components/dialog/InfoV2.tsx +35 -0
- package/src/components/dialog/NotFound.tsx +18 -0
- package/src/components/dialog/QuickSearch.tsx +115 -0
- package/src/components/notifications/NotificationsCenter.tsx +792 -0
- package/src/components/notifications/index.ts +42 -0
- package/src/components/tables/PaginationComponent.tsx +17 -0
- package/src/components/theme/AppLoadingFallback.tsx +42 -0
- package/src/components/theme/ErrorBoundary.tsx +57 -0
- package/src/components/theme/InitialLoader.tsx +16 -0
- package/src/components/theme/NotFound.tsx +124 -0
- package/src/components/theme/NotResults.tsx +54 -0
- package/src/hooks/useDraggable.ts +11 -0
- package/src/hooks/useNotifications.ts +14 -0
- package/src/hooks/useQuickSearch.tsx +29 -0
- package/src/index.tsx +77 -0
- package/src/utils/setNativeValue.tsx +23 -0
- package/dist/color-thief-CTwGFhOB.js +0 -272
- /package/{dist → src}/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayAutoSearch.tsx.wip +0 -0
- /package/{dist → src}/components/JsonColorSelector/JsonColorSelector.tsx.bkup +0 -0
- /package/{dist → src}/components/SortableDataGrid/README.md +0 -0
- /package/{dist → src}/styles/index.less +0 -0
|
@@ -1,3 +1,647 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
};
|