@synerise/ds-collector 1.4.26 → 1.4.27
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/CHANGELOG.md +4 -0
- package/dist/Collector.d.ts +6 -6
- package/dist/Collector.js +185 -261
- package/dist/Collector.styles.d.ts +17 -17
- package/dist/Collector.styles.js +63 -79
- package/dist/Collector.types.d.ts +4 -4
- package/dist/Collector.types.js +1 -1
- package/dist/Elements/ButtonPanel/ButtonPanel.d.ts +2 -2
- package/dist/Elements/ButtonPanel/ButtonPanel.js +21 -33
- package/dist/Elements/ButtonPanel/ButtonPanel.styles.d.ts +1 -1
- package/dist/Elements/ButtonPanel/ButtonPanel.styles.js +6 -3
- package/dist/Elements/ButtonPanel/ButtonPanel.types.d.ts +2 -2
- package/dist/Elements/ButtonPanel/ButtonPanel.types.js +1 -1
- package/dist/Elements/NavigationHint/NavigationHint.d.ts +2 -2
- package/dist/Elements/NavigationHint/NavigationHint.js +15 -11
- package/dist/Elements/NavigationHint/NavigationHint.types.d.ts +1 -1
- package/dist/Elements/NavigationHint/NavigationHint.types.js +1 -1
- package/dist/Elements/OptionsDropdown/OptionsDropdown.d.ts +2 -2
- package/dist/Elements/OptionsDropdown/OptionsDropdown.js +59 -73
- package/dist/Elements/OptionsDropdown/OptionsDropdown.types.d.ts +3 -3
- package/dist/Elements/OptionsDropdown/OptionsDropdown.types.js +1 -1
- package/dist/Elements/Values/Values.d.ts +2 -2
- package/dist/Elements/Values/Values.js +15 -21
- package/dist/Elements/Values/Values.types.d.ts +1 -1
- package/dist/Elements/Values/Values.types.js +1 -1
- package/dist/hooks/useTranslations.d.ts +1 -1
- package/dist/hooks/useTranslations.js +17 -26
- package/dist/index.js +4 -1
- package/dist/modules.d.js +1 -1
- package/dist/modules.d.ts +0 -0
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +27 -29
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.4.27](https://github.com/Synerise/synerise-design/compare/@synerise/ds-collector@1.4.26...@synerise/ds-collector@1.4.27) (2026-03-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-collector
|
|
9
|
+
|
|
6
10
|
## [1.4.26](https://github.com/Synerise/synerise-design/compare/@synerise/ds-collector@1.4.25...@synerise/ds-collector@1.4.26) (2026-03-20)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @synerise/ds-collector
|
package/dist/Collector.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { CollectorProps } from './Collector.types';
|
|
3
3
|
declare const Collector: {
|
|
4
4
|
({ allowCustomValue, allowMultipleValues, addButtonProps, buttonPanelPrefix, cancelButtonProps, keepSearchQueryOnSelect, error, className, description, enableCustomFilteringSuggestions, selected, suggestions, showNavigationHints, onConfirm, onCancel, label, errorText, disabled, fixedHeight, texts: defaultTexts, lookupConfig, onItemAdd, onItemDeselect, onItemSelect, onMultipleItemsSelect, dropdownContent, disableButtonPanel, disableSearch, dropdownItemHeight, searchValue, renderItem, onSearchValueChange, allowPaste, showCount, listHeader, hideDropdownOnClickOutside, valuesSeparator, valuesEscapeOpenTag, valuesEscapeCloseTag, }: CollectorProps): React.JSX.Element;
|
|
5
|
-
Values: ({ values, onDeselect, disabled, focused, displayLookupKey, }: import(
|
|
6
|
-
ButtonPanel: ({ onConfirm, onCancel, disabled, showCancel, texts, addButtonProps, cancelButtonProps, buttonPanelPrefix, }: import(
|
|
7
|
-
OptionsDropdown: ({ showAddButton, options, visible, value, onSelect, onClick, width, onItemAdd, showNavigationHints, lookupKey, texts, customContent, renderItem, dropdownItemHeight, scrollbarProps, listHeader, }: import(
|
|
8
|
-
NavigationHint: React.FC<import(
|
|
5
|
+
Values: ({ values, onDeselect, disabled, focused, displayLookupKey, }: import('./Elements/Values/Values.types').ValuesProps) => React.JSX.Element;
|
|
6
|
+
ButtonPanel: ({ onConfirm, onCancel, disabled, showCancel, texts, addButtonProps, cancelButtonProps, buttonPanelPrefix, }: import('./Elements/ButtonPanel/ButtonPanel.types').ButtonPanelProps) => React.JSX.Element;
|
|
7
|
+
OptionsDropdown: ({ showAddButton, options, visible, value, onSelect, onClick, width, onItemAdd, showNavigationHints, lookupKey, texts, customContent, renderItem, dropdownItemHeight, scrollbarProps, listHeader, }: import('./Elements/OptionsDropdown/OptionsDropdown.types').OptionsDropdownProps) => React.JSX.Element;
|
|
8
|
+
NavigationHint: React.FC<import('./Elements/NavigationHint/NavigationHint.types').NavigationHintProps>;
|
|
9
9
|
};
|
|
10
10
|
export default Collector;
|
package/dist/Collector.js
CHANGED
|
@@ -1,126 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
import classNames from
|
|
3
|
-
import
|
|
4
|
-
import { FormattedMessage } from
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import ButtonPanel from
|
|
8
|
-
import NavigationHint from
|
|
9
|
-
import OptionsDropdown from
|
|
10
|
-
import Values from
|
|
11
|
-
import { useTranslations } from
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
scrollLeft = _useState4[0],
|
|
85
|
-
setScrollLeft = _useState4[1];
|
|
86
|
-
var _useState5 = useState(searchValue || ''),
|
|
87
|
-
value = _useState5[0],
|
|
88
|
-
setValue = _useState5[1];
|
|
89
|
-
var _useState6 = useState(selected && allowMultipleValues ? selected : []),
|
|
90
|
-
selectedValues = _useState6[0],
|
|
91
|
-
setSelectedValues = _useState6[1];
|
|
92
|
-
var _useState7 = useState(suggestions || []),
|
|
93
|
-
filteredSuggestions = _useState7[0],
|
|
94
|
-
setFilteredSuggestions = _useState7[1];
|
|
95
|
-
var filterLookupKey = useMemo(function () {
|
|
96
|
-
return (lookupConfig == null ? void 0 : lookupConfig.filter) || 'text';
|
|
97
|
-
}, [lookupConfig]);
|
|
98
|
-
var displayLookupKey = useMemo(function () {
|
|
99
|
-
return (lookupConfig == null ? void 0 : lookupConfig.display) || 'text';
|
|
100
|
-
}, [lookupConfig]);
|
|
101
|
-
var focusInput = useCallback(function () {
|
|
102
|
-
setTimeout(function () {
|
|
103
|
-
if (inputRef != null && inputRef.current) {
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import { useRef, useState, useMemo, useCallback, useEffect } from "react";
|
|
4
|
+
import { FormattedMessage } from "react-intl";
|
|
5
|
+
import { useDelimiterEscape, useOnClickOutside, focusWithArrowKeys } from "@synerise/ds-utils";
|
|
6
|
+
import { MainContent, SearchWrapper, Placeholder, Input, Container, CollectorInput, RightSide, Counter, Scrollbar } from "./Collector.styles.js";
|
|
7
|
+
import ButtonPanel from "./Elements/ButtonPanel/ButtonPanel.js";
|
|
8
|
+
import NavigationHint from "./Elements/NavigationHint/NavigationHint.js";
|
|
9
|
+
import OptionsDropdown from "./Elements/OptionsDropdown/OptionsDropdown.js";
|
|
10
|
+
import Values from "./Elements/Values/Values.js";
|
|
11
|
+
import { useTranslations } from "./hooks/useTranslations.js";
|
|
12
|
+
import { filterValueSuggestions, isOverflown, scrollWithHorizontalArrow, filterOutNullishArrayItems, filterOutEmptyStrings } from "./utils.js";
|
|
13
|
+
import { ContentAbove, Label, ContentBelow, ErrorText, Description } from "@synerise/ds-input/dist/InputMultivalue/InputMultivalue.styles";
|
|
14
|
+
const DROPDOWN_PADDING = 2 * 8;
|
|
15
|
+
const COLLECTOR_CLASSNAME = "ds-collector";
|
|
16
|
+
const DEFAULT_VALUES_SEPARATOR = ";";
|
|
17
|
+
const DEFAULT_VALUES_ESCAPE_OPEN_TAG = "```";
|
|
18
|
+
const DEFAULT_VALUES_ESCAPE_CLOSE_TAG = "```";
|
|
19
|
+
const Collector = ({
|
|
20
|
+
allowCustomValue,
|
|
21
|
+
allowMultipleValues,
|
|
22
|
+
addButtonProps,
|
|
23
|
+
buttonPanelPrefix,
|
|
24
|
+
cancelButtonProps,
|
|
25
|
+
keepSearchQueryOnSelect,
|
|
26
|
+
error,
|
|
27
|
+
className,
|
|
28
|
+
description,
|
|
29
|
+
enableCustomFilteringSuggestions,
|
|
30
|
+
selected,
|
|
31
|
+
suggestions,
|
|
32
|
+
showNavigationHints,
|
|
33
|
+
onConfirm,
|
|
34
|
+
onCancel,
|
|
35
|
+
label,
|
|
36
|
+
errorText,
|
|
37
|
+
disabled,
|
|
38
|
+
fixedHeight,
|
|
39
|
+
texts: defaultTexts,
|
|
40
|
+
lookupConfig,
|
|
41
|
+
onItemAdd,
|
|
42
|
+
onItemDeselect,
|
|
43
|
+
onItemSelect,
|
|
44
|
+
onMultipleItemsSelect,
|
|
45
|
+
dropdownContent,
|
|
46
|
+
disableButtonPanel,
|
|
47
|
+
disableSearch,
|
|
48
|
+
dropdownItemHeight,
|
|
49
|
+
searchValue,
|
|
50
|
+
renderItem,
|
|
51
|
+
onSearchValueChange,
|
|
52
|
+
allowPaste,
|
|
53
|
+
showCount,
|
|
54
|
+
listHeader,
|
|
55
|
+
hideDropdownOnClickOutside = true,
|
|
56
|
+
valuesSeparator = DEFAULT_VALUES_SEPARATOR,
|
|
57
|
+
valuesEscapeOpenTag = DEFAULT_VALUES_ESCAPE_OPEN_TAG,
|
|
58
|
+
valuesEscapeCloseTag = DEFAULT_VALUES_ESCAPE_CLOSE_TAG
|
|
59
|
+
}) => {
|
|
60
|
+
const {
|
|
61
|
+
isValidEscapedString,
|
|
62
|
+
splitWithEscape
|
|
63
|
+
} = useDelimiterEscape({
|
|
64
|
+
openTag: valuesEscapeOpenTag,
|
|
65
|
+
closeTag: valuesEscapeCloseTag,
|
|
66
|
+
delimiter: valuesSeparator
|
|
67
|
+
});
|
|
68
|
+
const texts = useTranslations(defaultTexts);
|
|
69
|
+
const inputRef = useRef(null);
|
|
70
|
+
const containerRef = useRef(null);
|
|
71
|
+
const mainContentRef = useRef(null);
|
|
72
|
+
const [isFocused, setFocused] = useState(false);
|
|
73
|
+
const [isAddActive, setIsAddActive] = useState(false);
|
|
74
|
+
const [showGradient, setShowGradient] = useState(false);
|
|
75
|
+
const [scrollLeft, setScrollLeft] = useState(0);
|
|
76
|
+
const [value, setValue] = useState(searchValue || "");
|
|
77
|
+
const [selectedValues, setSelectedValues] = useState(selected && allowMultipleValues ? selected : []);
|
|
78
|
+
const [filteredSuggestions, setFilteredSuggestions] = useState(suggestions || []);
|
|
79
|
+
const filterLookupKey = useMemo(() => lookupConfig?.filter || "text", [lookupConfig]);
|
|
80
|
+
const displayLookupKey = useMemo(() => lookupConfig?.display || "text", [lookupConfig]);
|
|
81
|
+
const focusInput = useCallback(() => {
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
if (inputRef?.current) {
|
|
104
84
|
inputRef.current.focus({
|
|
105
85
|
preventScroll: true
|
|
106
86
|
});
|
|
107
87
|
}
|
|
108
88
|
}, 0);
|
|
109
89
|
}, [inputRef]);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return ((_suggestion$filterLoo = suggestion[filterLookupKey]) == null || (_suggestion$filterLoo = _suggestion$filterLoo.trim()) == null ? void 0 : _suggestion$filterLoo.toLowerCase()) === item.trim().toLowerCase();
|
|
114
|
-
});
|
|
115
|
-
}, [filterLookupKey, filteredSuggestions]);
|
|
116
|
-
var createItem = useCallback(function (text) {
|
|
117
|
-
var suggestionsIncludesCurrentValue = suggestionsIncludesItem(text);
|
|
90
|
+
const suggestionsIncludesItem = useCallback((item) => filteredSuggestions.some((suggestion) => suggestion[filterLookupKey]?.trim()?.toLowerCase() === item.trim().toLowerCase()), [filterLookupKey, filteredSuggestions]);
|
|
91
|
+
const createItem = useCallback((text) => {
|
|
92
|
+
const suggestionsIncludesCurrentValue = suggestionsIncludesItem(text);
|
|
118
93
|
if (allowCustomValue || suggestionsIncludesCurrentValue) {
|
|
119
94
|
return onItemAdd && onItemAdd(text);
|
|
120
95
|
}
|
|
121
96
|
return null;
|
|
122
97
|
}, [allowCustomValue, onItemAdd, suggestionsIncludesItem]);
|
|
123
|
-
|
|
98
|
+
const onFocusCallback = useCallback((event) => {
|
|
124
99
|
event.preventDefault();
|
|
125
100
|
if (event.target.classList.contains(COLLECTOR_CLASSNAME)) {
|
|
126
101
|
focusInput();
|
|
@@ -128,100 +103,99 @@ var Collector = function Collector(_ref) {
|
|
|
128
103
|
setFocused(true);
|
|
129
104
|
}
|
|
130
105
|
}, [focusInput]);
|
|
131
|
-
|
|
132
|
-
|
|
106
|
+
const filterSuggestions = useCallback((val) => {
|
|
107
|
+
const filtered = filterValueSuggestions(suggestions, selectedValues, val, filterLookupKey);
|
|
133
108
|
setFilteredSuggestions(filtered);
|
|
134
109
|
}, [suggestions, selectedValues, filterLookupKey]);
|
|
135
|
-
|
|
110
|
+
const canCreateItemFromValue = useCallback(() => {
|
|
136
111
|
if (!value) {
|
|
137
112
|
return false;
|
|
138
113
|
}
|
|
139
|
-
|
|
114
|
+
const item = createItem(value);
|
|
140
115
|
if (item) {
|
|
141
116
|
return true;
|
|
142
117
|
}
|
|
143
118
|
return false;
|
|
144
119
|
}, [createItem, value]);
|
|
145
|
-
useEffect(
|
|
120
|
+
useEffect(() => {
|
|
146
121
|
enableCustomFilteringSuggestions && setFilteredSuggestions(suggestions);
|
|
147
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
148
122
|
}, [suggestions]);
|
|
149
|
-
useEffect(
|
|
123
|
+
useEffect(() => {
|
|
150
124
|
setSelectedValues(selected && allowMultipleValues ? selected : []);
|
|
151
125
|
if (!enableCustomFilteringSuggestions) {
|
|
152
126
|
setFilteredSuggestions([]);
|
|
153
127
|
}
|
|
154
128
|
}, [allowMultipleValues, allowCustomValue, selected, enableCustomFilteringSuggestions]);
|
|
155
|
-
useEffect(
|
|
129
|
+
useEffect(() => {
|
|
156
130
|
if (!searchValue && allowMultipleValues) {
|
|
157
|
-
setValue(
|
|
131
|
+
setValue("");
|
|
158
132
|
return;
|
|
159
133
|
}
|
|
160
|
-
if (searchValue !==
|
|
134
|
+
if (searchValue !== void 0 && searchValue !== null) {
|
|
161
135
|
setValue(searchValue);
|
|
162
136
|
}
|
|
163
137
|
}, [allowMultipleValues, searchValue]);
|
|
164
|
-
useEffect(
|
|
138
|
+
useEffect(() => {
|
|
165
139
|
if (fixedHeight) {
|
|
166
140
|
setShowGradient(isOverflown(mainContentRef));
|
|
167
141
|
} else {
|
|
168
142
|
setShowGradient(false);
|
|
169
143
|
}
|
|
170
144
|
}, [selectedValues, mainContentRef, fixedHeight]);
|
|
171
|
-
useEffect(
|
|
145
|
+
useEffect(() => {
|
|
172
146
|
if (!enableCustomFilteringSuggestions) {
|
|
173
147
|
filterSuggestions(value);
|
|
174
148
|
}
|
|
175
149
|
}, [value, selectedValues, filterSuggestions, enableCustomFilteringSuggestions]);
|
|
176
|
-
useEffect(
|
|
150
|
+
useEffect(() => {
|
|
177
151
|
setIsAddActive(Boolean(selected.length) || canCreateItemFromValue());
|
|
178
152
|
}, [canCreateItemFromValue, selected]);
|
|
179
|
-
|
|
153
|
+
const clear = useCallback(() => {
|
|
180
154
|
setSelectedValues([]);
|
|
181
|
-
setValue(
|
|
155
|
+
setValue("");
|
|
182
156
|
setFocused(false);
|
|
183
157
|
inputRef.current && inputRef.current.blur();
|
|
184
158
|
}, []);
|
|
185
|
-
|
|
159
|
+
const handlePaste = (event) => {
|
|
186
160
|
if (allowMultipleValues && onItemAdd) {
|
|
187
|
-
|
|
161
|
+
const pastedText = event.clipboardData.getData("text");
|
|
188
162
|
if (pastedText.includes(valuesSeparator) && isValidEscapedString(pastedText)) {
|
|
189
|
-
|
|
190
|
-
|
|
163
|
+
const pastedItems = splitWithEscape(pastedText);
|
|
164
|
+
const newValues = filterOutNullishArrayItems(filterOutEmptyStrings(pastedItems).map(createItem));
|
|
191
165
|
if (newValues.length) {
|
|
192
166
|
onMultipleItemsSelect && onMultipleItemsSelect(newValues);
|
|
193
167
|
}
|
|
194
168
|
}
|
|
195
169
|
}
|
|
196
170
|
};
|
|
197
|
-
|
|
171
|
+
const addItem = () => {
|
|
198
172
|
if (!value.trim()) {
|
|
199
173
|
return;
|
|
200
174
|
}
|
|
201
|
-
|
|
202
|
-
|
|
175
|
+
const trimmedValue = value.startsWith(valuesEscapeOpenTag) ? value.slice(valuesEscapeOpenTag.length) : value;
|
|
176
|
+
const newValue = createItem(trimmedValue);
|
|
203
177
|
if (!newValue) {
|
|
204
|
-
setValue(
|
|
178
|
+
setValue("");
|
|
205
179
|
return;
|
|
206
180
|
}
|
|
207
181
|
if (allowMultipleValues) {
|
|
208
182
|
onItemSelect(newValue);
|
|
209
|
-
setValue(
|
|
183
|
+
setValue("");
|
|
210
184
|
} else if (onConfirm) {
|
|
211
185
|
onConfirm([newValue]);
|
|
212
186
|
!keepSearchQueryOnSelect && clear();
|
|
213
187
|
}
|
|
214
188
|
};
|
|
215
|
-
|
|
216
|
-
if (allowMultipleValues && event.key ===
|
|
217
|
-
|
|
189
|
+
const handleKeyDown = (event) => {
|
|
190
|
+
if (allowMultipleValues && event.key === "Backspace" && !value && !!selectedValues?.length) {
|
|
191
|
+
const lastElement = selected.pop();
|
|
218
192
|
if (lastElement && onItemDeselect) {
|
|
219
193
|
onItemDeselect(lastElement);
|
|
220
194
|
}
|
|
221
195
|
}
|
|
222
196
|
};
|
|
223
|
-
|
|
224
|
-
if (event.key ===
|
|
197
|
+
const handleKeyPress = (event) => {
|
|
198
|
+
if (event.key === "Enter") {
|
|
225
199
|
event.preventDefault();
|
|
226
200
|
if (value) {
|
|
227
201
|
addItem();
|
|
@@ -230,53 +204,50 @@ var Collector = function Collector(_ref) {
|
|
|
230
204
|
}
|
|
231
205
|
}
|
|
232
206
|
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
207
|
+
const handleKeyUp = (event) => {
|
|
208
|
+
const currentValue = event.target.value;
|
|
209
|
+
const isEscaped = currentValue.startsWith(valuesEscapeOpenTag);
|
|
210
|
+
const isClosedEscape = currentValue.endsWith(valuesEscapeCloseTag) && isEscaped && currentValue.length > valuesEscapeOpenTag.length + valuesEscapeCloseTag.length;
|
|
211
|
+
const tempItems = splitWithEscape(currentValue);
|
|
212
|
+
const containsSeparator = currentValue.includes(valuesSeparator);
|
|
239
213
|
if (isClosedEscape || containsSeparator && !isEscaped || tempItems.length > 1) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
214
|
+
const isValid = isClosedEscape ? isValidEscapedString(currentValue) : currentValue.endsWith(valuesSeparator);
|
|
215
|
+
const finalItems = isValid ? tempItems.slice() : tempItems.slice(0, -1);
|
|
216
|
+
const finalQuery = isValid ? "" : tempItems.at(-1) || "";
|
|
217
|
+
const newValues = filterOutNullishArrayItems(filterOutEmptyStrings(finalItems).map(createItem));
|
|
244
218
|
if (newValues.length) {
|
|
245
219
|
onMultipleItemsSelect && onMultipleItemsSelect(newValues);
|
|
246
220
|
}
|
|
247
221
|
setValue(finalQuery);
|
|
248
222
|
}
|
|
249
223
|
};
|
|
250
|
-
|
|
224
|
+
const onCancelCallback = useCallback(() => {
|
|
251
225
|
clear();
|
|
252
226
|
onCancel && onCancel();
|
|
253
227
|
}, [onCancel, clear]);
|
|
254
|
-
|
|
228
|
+
const onConfirmCallback = useCallback(() => {
|
|
255
229
|
if (!onConfirm) {
|
|
256
230
|
return;
|
|
257
231
|
}
|
|
258
232
|
if (allowMultipleValues) {
|
|
259
|
-
|
|
260
|
-
|
|
233
|
+
const createdItem = value && createItem(value);
|
|
234
|
+
const finalItems = createdItem ? [...selectedValues, createdItem] : selectedValues;
|
|
261
235
|
onConfirm(finalItems);
|
|
262
236
|
clear();
|
|
263
237
|
return;
|
|
264
238
|
}
|
|
265
|
-
|
|
239
|
+
const suggestionsIncludesCurrentValue = suggestionsIncludesItem(value);
|
|
266
240
|
if (allowCustomValue || suggestionsIncludesCurrentValue) {
|
|
267
|
-
|
|
241
|
+
const newValue = onItemAdd && onItemAdd(value);
|
|
268
242
|
newValue && onConfirm([newValue]);
|
|
269
243
|
clear();
|
|
270
244
|
}
|
|
271
245
|
}, [allowMultipleValues, suggestionsIncludesItem, value, allowCustomValue, createItem, selectedValues, onConfirm, clear, onItemAdd]);
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
return Number((_containerRef$current = containerRef.current) == null ? void 0 : _containerRef$current.offsetWidth) - DROPDOWN_PADDING;
|
|
275
|
-
}, [containerRef]);
|
|
276
|
-
var handleDropdownClick = function handleDropdownClick() {
|
|
246
|
+
const getContainerWidth = useCallback(() => Number(containerRef.current?.offsetWidth) - DROPDOWN_PADDING, [containerRef]);
|
|
247
|
+
const handleDropdownClick = () => {
|
|
277
248
|
focusInput();
|
|
278
249
|
};
|
|
279
|
-
|
|
250
|
+
const handleDropdownSelect = (item) => {
|
|
280
251
|
onItemSelect && onItemSelect(item);
|
|
281
252
|
if (!allowMultipleValues && !keepSearchQueryOnSelect && item[filterLookupKey]) {
|
|
282
253
|
setValue(item[filterLookupKey]);
|
|
@@ -285,8 +256,8 @@ var Collector = function Collector(_ref) {
|
|
|
285
256
|
}
|
|
286
257
|
focusInput();
|
|
287
258
|
};
|
|
288
|
-
|
|
289
|
-
|
|
259
|
+
const handleInput = disableSearch ? void 0 : (event) => {
|
|
260
|
+
const isPasteEvent = "inputType" in event.nativeEvent && event.nativeEvent.inputType === "insertFromPaste" && allowMultipleValues && allowPaste && event.target.value.includes(valuesSeparator);
|
|
290
261
|
if (!isPasteEvent) {
|
|
291
262
|
onSearchValueChange && onSearchValueChange(event.target.value);
|
|
292
263
|
setValue(event.target.value);
|
|
@@ -295,108 +266,61 @@ var Collector = function Collector(_ref) {
|
|
|
295
266
|
}
|
|
296
267
|
}
|
|
297
268
|
};
|
|
298
|
-
useOnClickOutside(containerRef,
|
|
269
|
+
useOnClickOutside(containerRef, () => {
|
|
299
270
|
hideDropdownOnClickOutside && setFocused(false);
|
|
300
271
|
});
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
});
|
|
311
|
-
return /*#__PURE__*/React.createElement(S.Counter, null, total, " ", counterLabel);
|
|
272
|
+
const showError = error || !!errorText;
|
|
273
|
+
const renderCountLabel = () => {
|
|
274
|
+
const total = selectedValues.length;
|
|
275
|
+
const counterLabel = total === 1 ? /* @__PURE__ */ jsx(FormattedMessage, { id: "DS.COLLECTOR.ITEM", defaultMessage: "Item" }) : /* @__PURE__ */ jsx(FormattedMessage, { id: "DS.COLLECTOR.ITEMS", defaultMessage: "Items" });
|
|
276
|
+
return /* @__PURE__ */ jsxs(Counter, { children: [
|
|
277
|
+
total,
|
|
278
|
+
" ",
|
|
279
|
+
counterLabel
|
|
280
|
+
] });
|
|
312
281
|
};
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
setScrollLeft(currentTarget.scrollLeft);
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
hasValues: !!(selectedValues != null && selectedValues.length),
|
|
322
|
-
ref: mainContentRef,
|
|
323
|
-
gradientOverlap: showGradient && scrollLeft > 0,
|
|
324
|
-
focus: isFocused
|
|
325
|
-
}, /*#__PURE__*/React.createElement(Values, {
|
|
326
|
-
values: selectedValues,
|
|
327
|
-
onDeselect: onItemDeselect,
|
|
328
|
-
focused: isFocused,
|
|
329
|
-
disabled: !!disabled,
|
|
330
|
-
displayLookupKey: displayLookupKey
|
|
331
|
-
}), /*#__PURE__*/React.createElement(S.SearchWrapper, null, !(selectedValues != null && selectedValues.length) && !value && /*#__PURE__*/React.createElement(S.Placeholder, null, texts == null ? void 0 : texts.placeholder), /*#__PURE__*/React.createElement(S.Input, {
|
|
332
|
-
onPaste: handlePaste,
|
|
333
|
-
onKeyPress: handleKeyPress,
|
|
334
|
-
onKeyDown: handleKeyDown,
|
|
335
|
-
onKeyUp: handleKeyUp,
|
|
336
|
-
ref: inputRef,
|
|
337
|
-
value: value,
|
|
338
|
-
onInput: handleInput,
|
|
339
|
-
disabled: disabled,
|
|
340
|
-
transparent: !!disableSearch,
|
|
341
|
-
hidden: !!disableSearch && !!selectedValues.length,
|
|
342
|
-
hasValues: !!(selectedValues != null && selectedValues.length),
|
|
343
|
-
"data-testid": "ds-collector-input"
|
|
344
|
-
})));
|
|
345
|
-
var innerContent = fixedHeight ? valuesContainer : /*#__PURE__*/React.createElement(S.Scrollbar, {
|
|
346
|
-
absolute: true,
|
|
347
|
-
maxHeight: 160
|
|
348
|
-
}, valuesContainer);
|
|
349
|
-
return /*#__PURE__*/React.createElement(S.Container, {
|
|
350
|
-
ref: containerRef,
|
|
351
|
-
onKeyDown: function onKeyDown(event) {
|
|
352
|
-
focusWithArrowKeys(event, 'ds-list-item', focusInput);
|
|
353
|
-
!value && scrollWithHorizontalArrow(mainContentRef, event);
|
|
354
|
-
}
|
|
355
|
-
}, (label || showCount) && /*#__PURE__*/React.createElement(S.ContentAbove, null, label && /*#__PURE__*/React.createElement(S.Label, null, label), showCount && renderCountLabel()), /*#__PURE__*/React.createElement(S.CollectorInput, {
|
|
356
|
-
className: classNames(COLLECTOR_CLASSNAME, (_classNames = {}, _classNames[className] = !!className, _classNames)),
|
|
357
|
-
tabIndex: 0,
|
|
358
|
-
focus: isFocused,
|
|
359
|
-
onFocus: onFocusCallback,
|
|
360
|
-
onClick: onFocusCallback,
|
|
361
|
-
error: showError,
|
|
362
|
-
disabled: disabled
|
|
363
|
-
}, innerContent, !disableButtonPanel && /*#__PURE__*/React.createElement(S.RightSide, {
|
|
364
|
-
gradientOverlap: showGradient && !value,
|
|
365
|
-
focus: isFocused,
|
|
366
|
-
onClick: function onClick(event) {
|
|
367
|
-
return event.stopPropagation();
|
|
282
|
+
const valuesContainer = /* @__PURE__ */ jsxs(MainContent, { fixedHeight, onScroll: ({
|
|
283
|
+
currentTarget
|
|
284
|
+
}) => {
|
|
285
|
+
if (fixedHeight) {
|
|
286
|
+
setScrollLeft(currentTarget.scrollLeft);
|
|
368
287
|
}
|
|
369
|
-
},
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
288
|
+
}, hasValues: !!selectedValues?.length, ref: mainContentRef, gradientOverlap: showGradient && scrollLeft > 0, focus: isFocused, children: [
|
|
289
|
+
/* @__PURE__ */ jsx(Values, { values: selectedValues, onDeselect: onItemDeselect, focused: isFocused, disabled: !!disabled, displayLookupKey }),
|
|
290
|
+
/* @__PURE__ */ jsxs(SearchWrapper, { children: [
|
|
291
|
+
!selectedValues?.length && !value && /* @__PURE__ */ jsx(Placeholder, { children: texts?.placeholder }),
|
|
292
|
+
/* @__PURE__ */ jsx(Input, { onPaste: handlePaste, onKeyPress: handleKeyPress, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, ref: inputRef, value, onInput: handleInput, disabled, transparent: !!disableSearch, hidden: !!disableSearch && !!selectedValues.length, hasValues: !!selectedValues?.length, "data-testid": "ds-collector-input" })
|
|
293
|
+
] })
|
|
294
|
+
] });
|
|
295
|
+
const innerContent = fixedHeight ? valuesContainer : /* @__PURE__ */ jsx(Scrollbar, { absolute: true, maxHeight: 160, children: valuesContainer });
|
|
296
|
+
return /* @__PURE__ */ jsxs(Container, { ref: containerRef, onKeyDown: (event) => {
|
|
297
|
+
focusWithArrowKeys(event, "ds-list-item", focusInput);
|
|
298
|
+
!value && scrollWithHorizontalArrow(mainContentRef, event);
|
|
299
|
+
}, children: [
|
|
300
|
+
(label || showCount) && /* @__PURE__ */ jsxs(ContentAbove, { children: [
|
|
301
|
+
label && /* @__PURE__ */ jsx(Label, { children: label }),
|
|
302
|
+
showCount && renderCountLabel()
|
|
303
|
+
] }),
|
|
304
|
+
/* @__PURE__ */ jsxs(CollectorInput, { className: classNames(COLLECTOR_CLASSNAME, {
|
|
305
|
+
[className]: !!className
|
|
306
|
+
}), tabIndex: 0, focus: isFocused, onFocus: onFocusCallback, onClick: onFocusCallback, error: showError, disabled, children: [
|
|
307
|
+
innerContent,
|
|
308
|
+
!disableButtonPanel && /* @__PURE__ */ jsx(RightSide, { gradientOverlap: showGradient && !value, focus: isFocused, onClick: (event) => event.stopPropagation(), children: /* @__PURE__ */ jsx(ButtonPanel, { onCancel: onCancelCallback, onConfirm: onConfirmCallback, disabled: !!disabled, showCancel: !!value || !!selectedValues?.length, texts, addButtonProps: {
|
|
309
|
+
disabled: !isAddActive,
|
|
310
|
+
...addButtonProps
|
|
311
|
+
}, cancelButtonProps, buttonPanelPrefix }) })
|
|
312
|
+
] }),
|
|
313
|
+
/* @__PURE__ */ jsx(OptionsDropdown, { options: filteredSuggestions, onItemAdd: addItem, lookupKey: displayLookupKey, dropdownItemHeight, value, visible: isFocused && !disabled && (filteredSuggestions.length > 0 || !!value && allowMultipleValues && allowCustomValue), onSelect: handleDropdownSelect, onClick: handleDropdownClick, renderItem, showAddButton: allowCustomValue && allowMultipleValues, showNavigationHints, width: getContainerWidth(), customContent: dropdownContent, texts, listHeader }),
|
|
314
|
+
(showError || description) && /* @__PURE__ */ jsxs(ContentBelow, { children: [
|
|
315
|
+
showError && /* @__PURE__ */ jsx(ErrorText, { children: errorText }),
|
|
316
|
+
description && /* @__PURE__ */ jsx(Description, { children: description })
|
|
317
|
+
] })
|
|
318
|
+
] });
|
|
397
319
|
};
|
|
398
320
|
Collector.Values = Values;
|
|
399
321
|
Collector.ButtonPanel = ButtonPanel;
|
|
400
322
|
Collector.OptionsDropdown = OptionsDropdown;
|
|
401
323
|
Collector.NavigationHint = NavigationHint;
|
|
402
|
-
export
|
|
324
|
+
export {
|
|
325
|
+
Collector as default
|
|
326
|
+
};
|