@synerise/ds-collector 1.4.26 → 1.4.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 (33) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/Collector.d.ts +6 -6
  3. package/dist/Collector.js +185 -261
  4. package/dist/Collector.styles.d.ts +17 -17
  5. package/dist/Collector.styles.js +63 -79
  6. package/dist/Collector.types.d.ts +4 -4
  7. package/dist/Collector.types.js +1 -1
  8. package/dist/Elements/ButtonPanel/ButtonPanel.d.ts +2 -2
  9. package/dist/Elements/ButtonPanel/ButtonPanel.js +21 -33
  10. package/dist/Elements/ButtonPanel/ButtonPanel.styles.d.ts +1 -1
  11. package/dist/Elements/ButtonPanel/ButtonPanel.styles.js +6 -3
  12. package/dist/Elements/ButtonPanel/ButtonPanel.types.d.ts +2 -2
  13. package/dist/Elements/ButtonPanel/ButtonPanel.types.js +1 -1
  14. package/dist/Elements/NavigationHint/NavigationHint.d.ts +2 -2
  15. package/dist/Elements/NavigationHint/NavigationHint.js +15 -11
  16. package/dist/Elements/NavigationHint/NavigationHint.types.d.ts +1 -1
  17. package/dist/Elements/NavigationHint/NavigationHint.types.js +1 -1
  18. package/dist/Elements/OptionsDropdown/OptionsDropdown.d.ts +2 -2
  19. package/dist/Elements/OptionsDropdown/OptionsDropdown.js +59 -73
  20. package/dist/Elements/OptionsDropdown/OptionsDropdown.types.d.ts +3 -3
  21. package/dist/Elements/OptionsDropdown/OptionsDropdown.types.js +1 -1
  22. package/dist/Elements/Values/Values.d.ts +2 -2
  23. package/dist/Elements/Values/Values.js +15 -21
  24. package/dist/Elements/Values/Values.types.d.ts +1 -1
  25. package/dist/Elements/Values/Values.types.js +1 -1
  26. package/dist/hooks/useTranslations.d.ts +1 -1
  27. package/dist/hooks/useTranslations.js +17 -26
  28. package/dist/index.js +4 -1
  29. package/dist/modules.d.js +1 -1
  30. package/dist/modules.d.ts +0 -0
  31. package/dist/utils.d.ts +2 -2
  32. package/dist/utils.js +27 -29
  33. package/package.json +12 -12
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
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.28](https://github.com/Synerise/synerise-design/compare/@synerise/ds-collector@1.4.27...@synerise/ds-collector@1.4.28) (2026-04-01)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-collector
9
+
10
+ ## [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)
11
+
12
+ **Note:** Version bump only for package @synerise/ds-collector
13
+
6
14
  ## [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
15
 
8
16
  **Note:** Version bump only for package @synerise/ds-collector
@@ -1,10 +1,10 @@
1
- import React from 'react';
2
- import { type CollectorProps } from './Collector.types';
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("./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>;
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
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import classNames from 'classnames';
3
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
- import { FormattedMessage } from 'react-intl';
5
- import { focusWithArrowKeys, useDelimiterEscape, useOnClickOutside } from '@synerise/ds-utils';
6
- import * as S from './Collector.styles';
7
- import ButtonPanel from './Elements/ButtonPanel/ButtonPanel';
8
- import NavigationHint from './Elements/NavigationHint/NavigationHint';
9
- import OptionsDropdown from './Elements/OptionsDropdown/OptionsDropdown';
10
- import Values from './Elements/Values/Values';
11
- import { useTranslations } from './hooks/useTranslations';
12
- import { filterOutEmptyStrings, filterOutNullishArrayItems, filterValueSuggestions, isOverflown, scrollWithHorizontalArrow } from './utils';
13
- var DROPDOWN_PADDING = 2 * 8;
14
- var COLLECTOR_CLASSNAME = 'ds-collector';
15
- var DEFAULT_VALUES_SEPARATOR = ';';
16
- var DEFAULT_VALUES_ESCAPE_OPEN_TAG = '```';
17
- var DEFAULT_VALUES_ESCAPE_CLOSE_TAG = '```';
18
- var Collector = function Collector(_ref) {
19
- var _classNames;
20
- var allowCustomValue = _ref.allowCustomValue,
21
- allowMultipleValues = _ref.allowMultipleValues,
22
- addButtonProps = _ref.addButtonProps,
23
- buttonPanelPrefix = _ref.buttonPanelPrefix,
24
- cancelButtonProps = _ref.cancelButtonProps,
25
- keepSearchQueryOnSelect = _ref.keepSearchQueryOnSelect,
26
- error = _ref.error,
27
- className = _ref.className,
28
- description = _ref.description,
29
- enableCustomFilteringSuggestions = _ref.enableCustomFilteringSuggestions,
30
- selected = _ref.selected,
31
- suggestions = _ref.suggestions,
32
- showNavigationHints = _ref.showNavigationHints,
33
- onConfirm = _ref.onConfirm,
34
- onCancel = _ref.onCancel,
35
- label = _ref.label,
36
- errorText = _ref.errorText,
37
- disabled = _ref.disabled,
38
- fixedHeight = _ref.fixedHeight,
39
- defaultTexts = _ref.texts,
40
- lookupConfig = _ref.lookupConfig,
41
- onItemAdd = _ref.onItemAdd,
42
- onItemDeselect = _ref.onItemDeselect,
43
- onItemSelect = _ref.onItemSelect,
44
- onMultipleItemsSelect = _ref.onMultipleItemsSelect,
45
- dropdownContent = _ref.dropdownContent,
46
- disableButtonPanel = _ref.disableButtonPanel,
47
- disableSearch = _ref.disableSearch,
48
- dropdownItemHeight = _ref.dropdownItemHeight,
49
- searchValue = _ref.searchValue,
50
- renderItem = _ref.renderItem,
51
- onSearchValueChange = _ref.onSearchValueChange,
52
- allowPaste = _ref.allowPaste,
53
- showCount = _ref.showCount,
54
- listHeader = _ref.listHeader,
55
- _ref$hideDropdownOnCl = _ref.hideDropdownOnClickOutside,
56
- hideDropdownOnClickOutside = _ref$hideDropdownOnCl === void 0 ? true : _ref$hideDropdownOnCl,
57
- _ref$valuesSeparator = _ref.valuesSeparator,
58
- valuesSeparator = _ref$valuesSeparator === void 0 ? DEFAULT_VALUES_SEPARATOR : _ref$valuesSeparator,
59
- _ref$valuesEscapeOpen = _ref.valuesEscapeOpenTag,
60
- valuesEscapeOpenTag = _ref$valuesEscapeOpen === void 0 ? DEFAULT_VALUES_ESCAPE_OPEN_TAG : _ref$valuesEscapeOpen,
61
- _ref$valuesEscapeClos = _ref.valuesEscapeCloseTag,
62
- valuesEscapeCloseTag = _ref$valuesEscapeClos === void 0 ? DEFAULT_VALUES_ESCAPE_CLOSE_TAG : _ref$valuesEscapeClos;
63
- var _useDelimiterEscape = useDelimiterEscape({
64
- openTag: valuesEscapeOpenTag,
65
- closeTag: valuesEscapeCloseTag,
66
- delimiter: valuesSeparator
67
- }),
68
- isValidEscapedString = _useDelimiterEscape.isValidEscapedString,
69
- splitWithEscape = _useDelimiterEscape.splitWithEscape;
70
- var texts = useTranslations(defaultTexts);
71
- var inputRef = useRef(null);
72
- var containerRef = useRef(null);
73
- var mainContentRef = useRef(null);
74
- var _useState = useState(false),
75
- isFocused = _useState[0],
76
- setFocused = _useState[1];
77
- var _useState2 = useState(false),
78
- isAddActive = _useState2[0],
79
- setIsAddActive = _useState2[1];
80
- var _useState3 = useState(false),
81
- showGradient = _useState3[0],
82
- setShowGradient = _useState3[1];
83
- var _useState4 = useState(0),
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
- var suggestionsIncludesItem = useCallback(function (item) {
111
- return filteredSuggestions.some(function (suggestion) {
112
- var _suggestion$filterLoo;
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
- var onFocusCallback = useCallback(function (event) {
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
- var filterSuggestions = useCallback(function (val) {
132
- var filtered = filterValueSuggestions(suggestions, selectedValues, val, filterLookupKey);
106
+ const filterSuggestions = useCallback((val) => {
107
+ const filtered = filterValueSuggestions(suggestions, selectedValues, val, filterLookupKey);
133
108
  setFilteredSuggestions(filtered);
134
109
  }, [suggestions, selectedValues, filterLookupKey]);
135
- var canCreateItemFromValue = useCallback(function () {
110
+ const canCreateItemFromValue = useCallback(() => {
136
111
  if (!value) {
137
112
  return false;
138
113
  }
139
- var item = createItem(value);
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(function () {
120
+ useEffect(() => {
146
121
  enableCustomFilteringSuggestions && setFilteredSuggestions(suggestions);
147
- // eslint-disable-next-line react-hooks/exhaustive-deps
148
122
  }, [suggestions]);
149
- useEffect(function () {
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(function () {
129
+ useEffect(() => {
156
130
  if (!searchValue && allowMultipleValues) {
157
- setValue('');
131
+ setValue("");
158
132
  return;
159
133
  }
160
- if (searchValue !== undefined && searchValue !== null) {
134
+ if (searchValue !== void 0 && searchValue !== null) {
161
135
  setValue(searchValue);
162
136
  }
163
137
  }, [allowMultipleValues, searchValue]);
164
- useEffect(function () {
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(function () {
145
+ useEffect(() => {
172
146
  if (!enableCustomFilteringSuggestions) {
173
147
  filterSuggestions(value);
174
148
  }
175
149
  }, [value, selectedValues, filterSuggestions, enableCustomFilteringSuggestions]);
176
- useEffect(function () {
150
+ useEffect(() => {
177
151
  setIsAddActive(Boolean(selected.length) || canCreateItemFromValue());
178
152
  }, [canCreateItemFromValue, selected]);
179
- var clear = useCallback(function () {
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
- var handlePaste = function handlePaste(event) {
159
+ const handlePaste = (event) => {
186
160
  if (allowMultipleValues && onItemAdd) {
187
- var pastedText = event.clipboardData.getData('text');
161
+ const pastedText = event.clipboardData.getData("text");
188
162
  if (pastedText.includes(valuesSeparator) && isValidEscapedString(pastedText)) {
189
- var pastedItems = splitWithEscape(pastedText);
190
- var newValues = filterOutNullishArrayItems(filterOutEmptyStrings(pastedItems).map(createItem));
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
- var addItem = function addItem() {
171
+ const addItem = () => {
198
172
  if (!value.trim()) {
199
173
  return;
200
174
  }
201
- var trimmedValue = value.startsWith(valuesEscapeOpenTag) ? value.slice(valuesEscapeOpenTag.length) : value;
202
- var newValue = createItem(trimmedValue);
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
- var handleKeyDown = function handleKeyDown(event) {
216
- if (allowMultipleValues && event.key === 'Backspace' && !value && !!(selectedValues != null && selectedValues.length)) {
217
- var lastElement = selected.pop();
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
- var handleKeyPress = function handleKeyPress(event) {
224
- if (event.key === 'Enter') {
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
- var handleKeyUp = function handleKeyUp(event) {
234
- var currentValue = event.target.value;
235
- var isEscaped = currentValue.startsWith(valuesEscapeOpenTag);
236
- var isClosedEscape = currentValue.endsWith(valuesEscapeCloseTag) && isEscaped && currentValue.length > valuesEscapeOpenTag.length + valuesEscapeCloseTag.length;
237
- var tempItems = splitWithEscape(currentValue);
238
- var containsSeparator = currentValue.includes(valuesSeparator);
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
- var isValid = isClosedEscape ? isValidEscapedString(currentValue) : currentValue.endsWith(valuesSeparator);
241
- var finalItems = isValid ? tempItems.slice() : tempItems.slice(0, -1);
242
- var finalQuery = isValid ? '' : tempItems.at(-1) || '';
243
- var newValues = filterOutNullishArrayItems(filterOutEmptyStrings(finalItems).map(createItem));
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
- var onCancelCallback = useCallback(function () {
224
+ const onCancelCallback = useCallback(() => {
251
225
  clear();
252
226
  onCancel && onCancel();
253
227
  }, [onCancel, clear]);
254
- var onConfirmCallback = useCallback(function () {
228
+ const onConfirmCallback = useCallback(() => {
255
229
  if (!onConfirm) {
256
230
  return;
257
231
  }
258
232
  if (allowMultipleValues) {
259
- var createdItem = value && createItem(value);
260
- var finalItems = createdItem ? [].concat(selectedValues, [createdItem]) : selectedValues;
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
- var suggestionsIncludesCurrentValue = suggestionsIncludesItem(value);
239
+ const suggestionsIncludesCurrentValue = suggestionsIncludesItem(value);
266
240
  if (allowCustomValue || suggestionsIncludesCurrentValue) {
267
- var newValue = onItemAdd && onItemAdd(value);
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
- var getContainerWidth = useCallback(function () {
273
- var _containerRef$current;
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
- var handleDropdownSelect = function handleDropdownSelect(item) {
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
- var handleInput = disableSearch ? undefined : function (event) {
289
- var isPasteEvent = 'inputType' in event.nativeEvent && event.nativeEvent.inputType === 'insertFromPaste' && allowMultipleValues && allowPaste && event.target.value.includes(valuesSeparator);
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, function () {
269
+ useOnClickOutside(containerRef, () => {
299
270
  hideDropdownOnClickOutside && setFocused(false);
300
271
  });
301
- var showError = error || !!errorText;
302
- var renderCountLabel = function renderCountLabel() {
303
- var total = selectedValues.length;
304
- var counterLabel = total === 1 ? /*#__PURE__*/React.createElement(FormattedMessage, {
305
- id: "DS.COLLECTOR.ITEM",
306
- defaultMessage: "Item"
307
- }) : /*#__PURE__*/React.createElement(FormattedMessage, {
308
- id: "DS.COLLECTOR.ITEMS",
309
- defaultMessage: "Items"
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
- var valuesContainer = /*#__PURE__*/React.createElement(S.MainContent, {
314
- fixedHeight: fixedHeight,
315
- onScroll: function onScroll(_ref2) {
316
- var currentTarget = _ref2.currentTarget;
317
- if (fixedHeight) {
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
- }, /*#__PURE__*/React.createElement(ButtonPanel, {
370
- onCancel: onCancelCallback,
371
- onConfirm: onConfirmCallback,
372
- disabled: !!disabled,
373
- showCancel: !!value || !!(selectedValues != null && selectedValues.length),
374
- texts: texts,
375
- addButtonProps: _extends({
376
- disabled: !isAddActive
377
- }, addButtonProps),
378
- cancelButtonProps: cancelButtonProps,
379
- buttonPanelPrefix: buttonPanelPrefix
380
- }))), /*#__PURE__*/React.createElement(OptionsDropdown, {
381
- options: filteredSuggestions,
382
- onItemAdd: addItem,
383
- lookupKey: displayLookupKey,
384
- dropdownItemHeight: dropdownItemHeight,
385
- value: value,
386
- visible: isFocused && !disabled && (filteredSuggestions.length > 0 || !!value && allowMultipleValues && allowCustomValue),
387
- onSelect: handleDropdownSelect,
388
- onClick: handleDropdownClick,
389
- renderItem: renderItem,
390
- showAddButton: allowCustomValue && allowMultipleValues,
391
- showNavigationHints: showNavigationHints,
392
- width: getContainerWidth(),
393
- customContent: dropdownContent,
394
- texts: texts,
395
- listHeader: listHeader
396
- }), (showError || description) && /*#__PURE__*/React.createElement(S.ContentBelow, null, showError && /*#__PURE__*/React.createElement(S.ErrorText, null, errorText), description && /*#__PURE__*/React.createElement(S.Description, null, description)));
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 default Collector;
324
+ export {
325
+ Collector as default
326
+ };