@transferwise/components 46.130.1 → 46.130.3
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/build/alert/Alert.js +4 -1
- package/build/alert/Alert.js.map +1 -1
- package/build/alert/Alert.mjs +4 -1
- package/build/alert/Alert.mjs.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.js +6 -4
- package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.mjs +6 -4
- package/build/criticalBanner/CriticalCommsBanner.mjs.map +1 -1
- package/build/dateInput/DateInput.js +12 -5
- package/build/dateInput/DateInput.js.map +1 -1
- package/build/dateInput/DateInput.mjs +11 -4
- package/build/dateInput/DateInput.mjs.map +1 -1
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.js +16 -8
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.js.map +1 -1
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.mjs +14 -6
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.mjs.map +1 -1
- package/build/index.js +12 -7
- package/build/index.js.map +1 -1
- package/build/index.mjs +9 -3
- package/build/index.mjs.map +1 -1
- package/build/inputs/{_BottomSheet.js → SelectInput/BottomSheet/SelectInputBottomSheet.js} +7 -7
- package/build/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.js.map +1 -0
- package/build/inputs/{_BottomSheet.mjs → SelectInput/BottomSheet/SelectInputBottomSheet.mjs} +7 -7
- package/build/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.mjs.map +1 -0
- package/build/inputs/{_ButtonInput.js → SelectInput/ButtonInput/SelectInputButtonInput.js} +5 -5
- package/build/inputs/SelectInput/ButtonInput/SelectInputButtonInput.js.map +1 -0
- package/build/inputs/{_ButtonInput.mjs → SelectInput/ButtonInput/SelectInputButtonInput.mjs} +5 -5
- package/build/inputs/SelectInput/ButtonInput/SelectInputButtonInput.mjs.map +1 -0
- package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.js +26 -0
- package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.js.map +1 -0
- package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.mjs +24 -0
- package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.mjs.map +1 -0
- package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.js +59 -0
- package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.js.map +1 -0
- package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.mjs +56 -0
- package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.mjs.map +1 -0
- package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.js +50 -0
- package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.js.map +1 -0
- package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.mjs +48 -0
- package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.mjs.map +1 -0
- package/build/inputs/SelectInput/ItemView/SelectInputItemView.js +47 -0
- package/build/inputs/SelectInput/ItemView/SelectInputItemView.js.map +1 -0
- package/build/inputs/SelectInput/ItemView/SelectInputItemView.mjs +45 -0
- package/build/inputs/SelectInput/ItemView/SelectInputItemView.mjs.map +1 -0
- package/build/inputs/SelectInput/Option/SelectInputOption.js +42 -0
- package/build/inputs/SelectInput/Option/SelectInputOption.js.map +1 -0
- package/build/inputs/SelectInput/Option/SelectInputOption.mjs +40 -0
- package/build/inputs/SelectInput/Option/SelectInputOption.mjs.map +1 -0
- package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.js +40 -0
- package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.js.map +1 -0
- package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.mjs +38 -0
- package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.mjs.map +1 -0
- package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.js +48 -0
- package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.js.map +1 -0
- package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.mjs +46 -0
- package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.mjs.map +1 -0
- package/build/inputs/SelectInput/Options/SelectInputOptions.js +300 -0
- package/build/inputs/SelectInput/Options/SelectInputOptions.js.map +1 -0
- package/build/inputs/SelectInput/Options/SelectInputOptions.mjs +298 -0
- package/build/inputs/SelectInput/Options/SelectInputOptions.mjs.map +1 -0
- package/build/inputs/{_Popover.js → SelectInput/Popover/SelectInputPopover.js} +7 -7
- package/build/inputs/SelectInput/Popover/SelectInputPopover.js.map +1 -0
- package/build/inputs/{_Popover.mjs → SelectInput/Popover/SelectInputPopover.mjs} +7 -7
- package/build/inputs/SelectInput/Popover/SelectInputPopover.mjs.map +1 -0
- package/build/inputs/SelectInput/SelectInput.contexts.js +29 -0
- package/build/inputs/SelectInput/SelectInput.contexts.js.map +1 -0
- package/build/inputs/SelectInput/SelectInput.contexts.mjs +24 -0
- package/build/inputs/SelectInput/SelectInput.contexts.mjs.map +1 -0
- package/build/inputs/SelectInput/SelectInput.js +222 -0
- package/build/inputs/SelectInput/SelectInput.js.map +1 -0
- package/build/inputs/SelectInput/SelectInput.messages.js.map +1 -0
- package/build/inputs/SelectInput/SelectInput.messages.mjs.map +1 -0
- package/build/inputs/SelectInput/SelectInput.mjs +216 -0
- package/build/inputs/SelectInput/SelectInput.mjs.map +1 -0
- package/build/inputs/SelectInput/SelectInput.utils.js +164 -0
- package/build/inputs/SelectInput/SelectInput.utils.js.map +1 -0
- package/build/inputs/SelectInput/SelectInput.utils.mjs +154 -0
- package/build/inputs/SelectInput/SelectInput.utils.mjs.map +1 -0
- package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js +42 -0
- package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js.map +1 -0
- package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs +36 -0
- package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs.map +1 -0
- package/build/main.css +99 -90
- package/build/moneyInput/MoneyInput.js +9 -2
- package/build/moneyInput/MoneyInput.js.map +1 -1
- package/build/moneyInput/MoneyInput.mjs +8 -1
- package/build/moneyInput/MoneyInput.mjs.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.js +10 -3
- package/build/phoneNumberInput/PhoneNumberInput.js.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.mjs +9 -2
- package/build/phoneNumberInput/PhoneNumberInput.mjs.map +1 -1
- package/build/styles/criticalBanner/CriticalCommsBanner.css +9 -0
- package/build/styles/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.css +96 -0
- package/build/styles/inputs/SelectInput/ButtonInput/SelectInputButtonInput.css +16 -0
- package/build/styles/inputs/SelectInput/ClearButton/SelectInputClearButton.css +46 -0
- package/build/styles/inputs/SelectInput/ItemView/SelectInputItemView.css +16 -0
- package/build/styles/inputs/SelectInput/Option/SelectInputOption.css +33 -0
- package/build/styles/inputs/SelectInput/OptionContent/SelectInputOptionContent.css +37 -0
- package/build/styles/inputs/SelectInput/Options/SelectInputOptions.css +81 -0
- package/build/styles/inputs/SelectInput/Popover/SelectInputPopover.css +46 -0
- package/build/styles/main.css +99 -90
- package/build/types/alert/Alert.d.ts +2 -0
- package/build/types/alert/Alert.d.ts.map +1 -1
- package/build/types/criticalBanner/CriticalCommsBanner.d.ts +1 -0
- package/build/types/criticalBanner/CriticalCommsBanner.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputs/{_BottomSheet.d.ts → SelectInput/BottomSheet/SelectInputBottomSheet.d.ts} +3 -3
- package/build/types/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/BottomSheet/index.d.ts +3 -0
- package/build/types/inputs/SelectInput/BottomSheet/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/ButtonInput/SelectInputButtonInput.d.ts +5 -0
- package/build/types/inputs/SelectInput/ButtonInput/SelectInputButtonInput.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/ButtonInput/index.d.ts +3 -0
- package/build/types/inputs/SelectInput/ButtonInput/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/ClearButton/SelectInputClearButton.d.ts +7 -0
- package/build/types/inputs/SelectInput/ClearButton/SelectInputClearButton.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/ClearButton/index.d.ts +3 -0
- package/build/types/inputs/SelectInput/ClearButton/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.d.ts +16 -0
- package/build/types/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/DefaultRenderTrigger/index.d.ts +2 -0
- package/build/types/inputs/SelectInput/DefaultRenderTrigger/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.d.ts +9 -0
- package/build/types/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/ItemView/GroupItemView/index.d.ts +3 -0
- package/build/types/inputs/SelectInput/ItemView/GroupItemView/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/ItemView/SelectInputItemView.d.ts +11 -0
- package/build/types/inputs/SelectInput/ItemView/SelectInputItemView.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/ItemView/index.d.ts +4 -0
- package/build/types/inputs/SelectInput/ItemView/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/Option/SelectInputOption.d.ts +11 -0
- package/build/types/inputs/SelectInput/Option/SelectInputOption.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/Option/index.d.ts +3 -0
- package/build/types/inputs/SelectInput/Option/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/OptionContent/SelectInputOptionContent.d.ts +13 -0
- package/build/types/inputs/SelectInput/OptionContent/SelectInputOptionContent.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/OptionContent/index.d.ts +3 -0
- package/build/types/inputs/SelectInput/OptionContent/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.d.ts +9 -0
- package/build/types/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/Options/OptionsContainer/index.d.ts +3 -0
- package/build/types/inputs/SelectInput/Options/OptionsContainer/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/Options/SelectInputOptions.d.ts +21 -0
- package/build/types/inputs/SelectInput/Options/SelectInputOptions.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/Options/index.d.ts +4 -0
- package/build/types/inputs/SelectInput/Options/index.d.ts.map +1 -0
- package/build/types/inputs/{_Popover.d.ts → SelectInput/Popover/SelectInputPopover.d.ts} +3 -3
- package/build/types/inputs/SelectInput/Popover/SelectInputPopover.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/Popover/index.d.ts +3 -0
- package/build/types/inputs/SelectInput/Popover/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/SelectInput.contexts.d.ts +33 -0
- package/build/types/inputs/SelectInput/SelectInput.contexts.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/SelectInput.d.ts +10 -0
- package/build/types/inputs/SelectInput/SelectInput.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/SelectInput.messages.d.ts.map +1 -0
- package/build/types/inputs/{SelectInput.d.ts → SelectInput/SelectInput.types.d.ts} +12 -38
- package/build/types/inputs/SelectInput/SelectInput.types.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/SelectInput.utils.d.ts +60 -0
- package/build/types/inputs/SelectInput/SelectInput.utils.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts +12 -0
- package/build/types/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/TriggerButton/index.d.ts +3 -0
- package/build/types/inputs/SelectInput/TriggerButton/index.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/components.d.ts +10 -0
- package/build/types/inputs/SelectInput/components.d.ts.map +1 -0
- package/build/types/inputs/SelectInput/index.d.ts +10 -0
- package/build/types/inputs/SelectInput/index.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/alert/Alert.tsx +6 -1
- package/src/criticalBanner/CriticalCommsBanner.css +9 -0
- package/src/criticalBanner/CriticalCommsBanner.less +13 -0
- package/src/criticalBanner/CriticalCommsBanner.test.story.tsx +15 -0
- package/src/criticalBanner/CriticalCommsBanner.test.tsx +28 -2
- package/src/criticalBanner/CriticalCommsBanner.tsx +10 -1
- package/src/index.ts +0 -1
- package/src/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.css +96 -0
- package/src/inputs/{_BottomSheet.tsx → SelectInput/BottomSheet/SelectInputBottomSheet.tsx} +7 -7
- package/src/inputs/SelectInput/BottomSheet/index.ts +2 -0
- package/src/inputs/SelectInput/ButtonInput/SelectInputButtonInput.css +16 -0
- package/src/inputs/{_ButtonInput.tsx → SelectInput/ButtonInput/SelectInputButtonInput.tsx} +5 -5
- package/src/inputs/SelectInput/ButtonInput/index.ts +2 -0
- package/src/inputs/SelectInput/ClearButton/SelectInputClearButton.css +46 -0
- package/src/inputs/SelectInput/ClearButton/SelectInputClearButton.less +39 -0
- package/src/inputs/SelectInput/ClearButton/SelectInputClearButton.tsx +27 -0
- package/src/inputs/SelectInput/ClearButton/index.ts +2 -0
- package/src/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.tsx +74 -0
- package/src/inputs/SelectInput/DefaultRenderTrigger/index.ts +5 -0
- package/src/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.tsx +61 -0
- package/src/inputs/SelectInput/ItemView/GroupItemView/index.ts +2 -0
- package/src/inputs/SelectInput/ItemView/SelectInputItemView.css +16 -0
- package/src/inputs/SelectInput/ItemView/SelectInputItemView.less +17 -0
- package/src/inputs/SelectInput/ItemView/SelectInputItemView.tsx +48 -0
- package/src/inputs/SelectInput/ItemView/index.ts +3 -0
- package/src/inputs/SelectInput/Option/SelectInputOption.css +33 -0
- package/src/inputs/SelectInput/Option/SelectInputOption.less +32 -0
- package/src/inputs/SelectInput/Option/SelectInputOption.tsx +57 -0
- package/src/inputs/SelectInput/Option/index.ts +2 -0
- package/src/inputs/SelectInput/OptionContent/SelectInputOptionContent.css +37 -0
- package/src/inputs/SelectInput/OptionContent/SelectInputOptionContent.less +38 -0
- package/src/inputs/SelectInput/OptionContent/SelectInputOptionContent.tsx +72 -0
- package/src/inputs/SelectInput/OptionContent/index.ts +2 -0
- package/src/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.tsx +59 -0
- package/src/inputs/SelectInput/Options/OptionsContainer/index.ts +2 -0
- package/src/inputs/SelectInput/Options/SelectInputOptions.css +81 -0
- package/src/inputs/SelectInput/Options/SelectInputOptions.less +77 -0
- package/src/inputs/SelectInput/Options/SelectInputOptions.tsx +411 -0
- package/src/inputs/SelectInput/Options/index.ts +3 -0
- package/src/inputs/SelectInput/Popover/SelectInputPopover.css +46 -0
- package/src/inputs/{_Popover.tsx → SelectInput/Popover/SelectInputPopover.tsx} +7 -7
- package/src/inputs/SelectInput/Popover/index.ts +2 -0
- package/src/inputs/SelectInput/SelectInput.contexts.tsx +40 -0
- package/src/inputs/SelectInput/SelectInput.less +22 -0
- package/src/inputs/{SelectInput.test.tsx → SelectInput/SelectInput.test.tsx} +9 -11
- package/src/inputs/SelectInput/SelectInput.tsx +257 -0
- package/src/inputs/SelectInput/SelectInput.types.ts +113 -0
- package/src/inputs/SelectInput/SelectInput.utils.ts +205 -0
- package/src/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx +36 -0
- package/src/inputs/SelectInput/TriggerButton/index.ts +5 -0
- package/src/inputs/{SelectInput.docs.mdx → SelectInput/_stories/SelectInput.docs.mdx} +0 -1
- package/src/inputs/{SelectInput.story.tsx → SelectInput/_stories/SelectInput.story.tsx} +11 -8
- package/src/inputs/{SelectInput.test.story.tsx → SelectInput/_stories/SelectInput.test.story.tsx} +6 -10
- package/src/inputs/SelectInput/components.ts +10 -0
- package/src/inputs/SelectInput/index.ts +12 -0
- package/src/main.css +99 -90
- package/src/main.less +1 -1
- package/build/inputs/SelectInput.js +0 -890
- package/build/inputs/SelectInput.js.map +0 -1
- package/build/inputs/SelectInput.messages.js.map +0 -1
- package/build/inputs/SelectInput.messages.mjs.map +0 -1
- package/build/inputs/SelectInput.mjs +0 -881
- package/build/inputs/SelectInput.mjs.map +0 -1
- package/build/inputs/_BottomSheet.js.map +0 -1
- package/build/inputs/_BottomSheet.mjs.map +0 -1
- package/build/inputs/_ButtonInput.js.map +0 -1
- package/build/inputs/_ButtonInput.mjs.map +0 -1
- package/build/inputs/_Popover.js.map +0 -1
- package/build/inputs/_Popover.mjs.map +0 -1
- package/build/types/inputs/SelectInput.d.ts.map +0 -1
- package/build/types/inputs/SelectInput.messages.d.ts.map +0 -1
- package/build/types/inputs/_BottomSheet.d.ts.map +0 -1
- package/build/types/inputs/_ButtonInput.d.ts +0 -5
- package/build/types/inputs/_ButtonInput.d.ts.map +0 -1
- package/build/types/inputs/_Popover.d.ts.map +0 -1
- package/src/inputs/SelectInput.less +0 -219
- package/src/inputs/SelectInput.tsx +0 -1269
- package/build/inputs/{SelectInput.messages.js → SelectInput/SelectInput.messages.js} +0 -0
- package/build/inputs/{SelectInput.messages.mjs → SelectInput/SelectInput.messages.mjs} +0 -0
- package/build/styles/inputs/{SelectInput.css → SelectInput/SelectInput.css} +90 -90
- package/build/types/inputs/{SelectInput.messages.d.ts → SelectInput/SelectInput.messages.d.ts} +0 -0
- package/src/inputs/{_BottomSheet.less → SelectInput/BottomSheet/SelectInputBottomSheet.less} +0 -0
- package/src/inputs/{_ButtonInput.less → SelectInput/ButtonInput/SelectInputButtonInput.less} +0 -0
- package/src/inputs/{_Popover.less → SelectInput/Popover/SelectInputPopover.less} +0 -0
- package/src/inputs/{SelectInput.css → SelectInput/SelectInput.css} +90 -90
- /package/src/inputs/{SelectInput.messages.ts → SelectInput/SelectInput.messages.ts} +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const MAX_ITEMS_WITHOUT_VIRTUALIZATION = 50;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a string to a normalized, searchable format by:
|
|
6
|
+
* - Trimming whitespace
|
|
7
|
+
* - Normalizing whitespace (convert multiple spaces to single space)
|
|
8
|
+
* - Converting to NFD normalization form to handle diacritics
|
|
9
|
+
* - Removing combining diacritical marks
|
|
10
|
+
* - Converting to lowercase
|
|
11
|
+
*/
|
|
12
|
+
function searchableString(value) {
|
|
13
|
+
return value.trim().replace(/\s+/gu, ' ')
|
|
14
|
+
// NFD converts an Å to A + ̊ (and other special characters)
|
|
15
|
+
.normalize('NFD')
|
|
16
|
+
// and then this replaces the ̊ with nothing (and other special characters)
|
|
17
|
+
.replace(/[\u0300-\u036f]/g, '').toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Extracts searchable strings from a value.
|
|
21
|
+
* - If the value is a string, returns a normalized version.
|
|
22
|
+
* - If the value is an object, extracts all string values and normalizes them.
|
|
23
|
+
* - Otherwise returns an empty array.
|
|
24
|
+
*/
|
|
25
|
+
function inferSearchableStrings(value) {
|
|
26
|
+
if (typeof value === 'string') {
|
|
27
|
+
return [searchableString(value)];
|
|
28
|
+
}
|
|
29
|
+
if (typeof value === 'object' && value != null) {
|
|
30
|
+
return Object.values(value).filter(innerValue => typeof innerValue === 'string').map(innerValue => searchableString(innerValue));
|
|
31
|
+
}
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sets the value of a duplicate option item to undefined, effectively hiding it when rendered.
|
|
36
|
+
*/
|
|
37
|
+
function dedupeSelectInputOptionItem(item, existingValues, compareValues) {
|
|
38
|
+
const isDuplicate = compareValues ? Array.from(existingValues).some(existingValue => compareValues(item.value, existingValue)) : existingValues.has(item.value);
|
|
39
|
+
if (!isDuplicate) {
|
|
40
|
+
existingValues.add(item.value);
|
|
41
|
+
return item;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
...item,
|
|
45
|
+
value: undefined
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sets the `value` of duplicate option items to `undefined`, hiding them when
|
|
50
|
+
* rendered. Indexes are kept intact within groups to preserve the active item
|
|
51
|
+
* between filter changes when possible.
|
|
52
|
+
*/
|
|
53
|
+
function dedupeSelectInputItems(items, compareValues) {
|
|
54
|
+
const existingValues = new Set();
|
|
55
|
+
return items.map(item => {
|
|
56
|
+
switch (item.type) {
|
|
57
|
+
case 'option':
|
|
58
|
+
{
|
|
59
|
+
return dedupeSelectInputOptionItem(item, existingValues, compareValues);
|
|
60
|
+
}
|
|
61
|
+
case 'group':
|
|
62
|
+
{
|
|
63
|
+
return {
|
|
64
|
+
...item,
|
|
65
|
+
options: item.options.map(option => dedupeSelectInputOptionItem(option, existingValues, compareValues))
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return item;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Checks if a SelectInputOptionItem matches the search needle.
|
|
74
|
+
*/
|
|
75
|
+
function selectInputOptionItemIncludesNeedle(item, needle) {
|
|
76
|
+
return inferSearchableStrings(item.filterMatchers ?? item.value).some(haystack => haystack.includes(needle));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Filters SelectInputItems based on the provided predicate function.
|
|
80
|
+
* For group items, it checks if any of their options match the predicate.
|
|
81
|
+
*/
|
|
82
|
+
function filterSelectInputItems(items, predicate) {
|
|
83
|
+
return items.filter(item => {
|
|
84
|
+
switch (item.type) {
|
|
85
|
+
case 'option':
|
|
86
|
+
{
|
|
87
|
+
return predicate(item);
|
|
88
|
+
}
|
|
89
|
+
case 'group':
|
|
90
|
+
{
|
|
91
|
+
return item.options.some(option => predicate(option));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Flattens and sorts filtered options using the provided comparator.
|
|
99
|
+
* Extracts all options from groups, filters out undefined values (deduplicated items),
|
|
100
|
+
* sorts them, and returns as a flat list of option items.
|
|
101
|
+
*/
|
|
102
|
+
function sortSelectInputItems(items, compareFn, searchQuery) {
|
|
103
|
+
const flattenedOption = items.flatMap(item => {
|
|
104
|
+
if (item.type === 'option') {
|
|
105
|
+
return item.value !== undefined ? [item] : [];
|
|
106
|
+
}
|
|
107
|
+
if (item.type === 'group') {
|
|
108
|
+
return item.options.filter(option => option.value !== undefined);
|
|
109
|
+
}
|
|
110
|
+
return [];
|
|
111
|
+
});
|
|
112
|
+
// eslint-disable-next-line functional/immutable-data
|
|
113
|
+
return flattenedOption.sort((a, b) => compareFn(a, b, searchQuery));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A prebuilt sort function for `sortFilteredOptions` that sorts options by relevance to the search query.
|
|
117
|
+
* Prioritizes: exact matches > starts with > contains > alphabetical.
|
|
118
|
+
*
|
|
119
|
+
* @param getLabel - Function to extract the label string from the option value. Defaults to using `title` property.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```tsx
|
|
123
|
+
* <SelectInput
|
|
124
|
+
* filterable
|
|
125
|
+
* sortFilteredOptions={sortByRelevance((value) => value.name)}
|
|
126
|
+
* // ...
|
|
127
|
+
* />
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
function sortByRelevance(getLabel = value => value.title) {
|
|
131
|
+
return (a, b, searchQuery) => {
|
|
132
|
+
const normalizedQuery = searchQuery.toLowerCase();
|
|
133
|
+
const labelA = getLabel(a.value).toLowerCase();
|
|
134
|
+
const labelB = getLabel(b.value).toLowerCase();
|
|
135
|
+
// Prioritize exact matches
|
|
136
|
+
const aExactMatch = labelA === normalizedQuery;
|
|
137
|
+
const bExactMatch = labelB === normalizedQuery;
|
|
138
|
+
if (aExactMatch && !bExactMatch) return -1;
|
|
139
|
+
if (!aExactMatch && bExactMatch) return 1;
|
|
140
|
+
// Then prioritize options where label starts with the search query
|
|
141
|
+
const aStartsWith = labelA.startsWith(normalizedQuery);
|
|
142
|
+
const bStartsWith = labelB.startsWith(normalizedQuery);
|
|
143
|
+
if (aStartsWith && !bStartsWith) return -1;
|
|
144
|
+
if (!aStartsWith && bStartsWith) return 1;
|
|
145
|
+
// Then prioritize options where label contains the search query
|
|
146
|
+
const aContains = labelA.includes(normalizedQuery);
|
|
147
|
+
const bContains = labelB.includes(normalizedQuery);
|
|
148
|
+
if (aContains && !bContains) return -1;
|
|
149
|
+
if (!aContains && bContains) return 1;
|
|
150
|
+
// Finally sort alphabetically
|
|
151
|
+
return labelA.localeCompare(labelB);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
exports.MAX_ITEMS_WITHOUT_VIRTUALIZATION = MAX_ITEMS_WITHOUT_VIRTUALIZATION;
|
|
156
|
+
exports.dedupeSelectInputItems = dedupeSelectInputItems;
|
|
157
|
+
exports.dedupeSelectInputOptionItem = dedupeSelectInputOptionItem;
|
|
158
|
+
exports.filterSelectInputItems = filterSelectInputItems;
|
|
159
|
+
exports.inferSearchableStrings = inferSearchableStrings;
|
|
160
|
+
exports.searchableString = searchableString;
|
|
161
|
+
exports.selectInputOptionItemIncludesNeedle = selectInputOptionItemIncludesNeedle;
|
|
162
|
+
exports.sortByRelevance = sortByRelevance;
|
|
163
|
+
exports.sortSelectInputItems = sortSelectInputItems;
|
|
164
|
+
//# sourceMappingURL=SelectInput.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectInput.utils.js","sources":["../../../src/inputs/SelectInput/SelectInput.utils.ts"],"sourcesContent":["import { SelectInputItem, SelectInputOptionItem } from './SelectInput.types';\n\nexport const MAX_ITEMS_WITHOUT_VIRTUALIZATION = 50;\n\n/**\n * Converts a string to a normalized, searchable format by:\n * - Trimming whitespace\n * - Normalizing whitespace (convert multiple spaces to single space)\n * - Converting to NFD normalization form to handle diacritics\n * - Removing combining diacritical marks\n * - Converting to lowercase\n */\nexport function searchableString(value: string) {\n return (\n value\n .trim()\n .replace(/\\s+/gu, ' ')\n // NFD converts an Å to A + ̊ (and other special characters)\n .normalize('NFD')\n // and then this replaces the ̊ with nothing (and other special characters)\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n );\n}\n\n/**\n * Extracts searchable strings from a value.\n * - If the value is a string, returns a normalized version.\n * - If the value is an object, extracts all string values and normalizes them.\n * - Otherwise returns an empty array.\n */\nexport function inferSearchableStrings(value: unknown) {\n if (typeof value === 'string') {\n return [searchableString(value)];\n }\n\n if (typeof value === 'object' && value != null) {\n return Object.values(value)\n .filter((innerValue) => typeof innerValue === 'string')\n .map((innerValue) => searchableString(innerValue));\n }\n\n return [];\n}\n\n/**\n * Sets the value of a duplicate option item to undefined, effectively hiding it when rendered.\n */\nexport function dedupeSelectInputOptionItem<T>(\n item: SelectInputOptionItem<T>,\n existingValues: Set<T>,\n compareValues?: (a: T, b: T) => boolean,\n): SelectInputOptionItem<T | undefined> {\n const isDuplicate = compareValues\n ? Array.from(existingValues).some((existingValue) => compareValues(item.value, existingValue))\n : existingValues.has(item.value);\n\n if (!isDuplicate) {\n existingValues.add(item.value);\n return item;\n }\n return { ...item, value: undefined };\n}\n\n/**\n * Sets the `value` of duplicate option items to `undefined`, hiding them when\n * rendered. Indexes are kept intact within groups to preserve the active item\n * between filter changes when possible.\n */\nexport function dedupeSelectInputItems<T>(\n items: readonly SelectInputItem<T>[],\n compareValues?: (a: T, b: T) => boolean,\n): SelectInputItem<T | undefined>[] {\n const existingValues = new Set<T>();\n\n return items.map((item) => {\n switch (item.type) {\n case 'option': {\n return dedupeSelectInputOptionItem(item, existingValues, compareValues);\n }\n case 'group': {\n return {\n ...item,\n options: item.options.map((option) =>\n dedupeSelectInputOptionItem(option, existingValues, compareValues),\n ),\n };\n }\n default:\n }\n return item;\n });\n}\n\n/**\n * Checks if a SelectInputOptionItem matches the search needle.\n */\nexport function selectInputOptionItemIncludesNeedle<T>(\n item: SelectInputOptionItem<T>,\n needle: string,\n) {\n return inferSearchableStrings(item.filterMatchers ?? item.value).some((haystack) =>\n haystack.includes(needle),\n );\n}\n\n/**\n * Filters SelectInputItems based on the provided predicate function.\n * For group items, it checks if any of their options match the predicate.\n */\nexport function filterSelectInputItems<T>(\n items: readonly SelectInputItem<T>[],\n predicate: (item: SelectInputOptionItem<T>) => boolean,\n) {\n return items.filter((item) => {\n switch (item.type) {\n case 'option': {\n return predicate(item);\n }\n case 'group': {\n return item.options.some((option) => predicate(option));\n }\n default:\n }\n return false;\n });\n}\n\n/**\n * Flattens and sorts filtered options using the provided comparator.\n * Extracts all options from groups, filters out undefined values (deduplicated items),\n * sorts them, and returns as a flat list of option items.\n */\nexport function sortSelectInputItems<T>(\n items: readonly SelectInputItem<T | undefined>[],\n compareFn: (\n a: SelectInputOptionItem<NonNullable<T>>,\n b: SelectInputOptionItem<NonNullable<T>>,\n searchQuery: string,\n ) => number,\n searchQuery: string,\n): SelectInputItem<NonNullable<T>>[] {\n const flattenedOption = items.flatMap((item) => {\n if (item.type === 'option') {\n return item.value !== undefined ? [item as SelectInputOptionItem<NonNullable<T>>] : [];\n }\n\n if (item.type === 'group') {\n return item.options.filter(\n (option): option is SelectInputOptionItem<NonNullable<T>> => option.value !== undefined,\n );\n }\n\n return [];\n });\n\n // eslint-disable-next-line functional/immutable-data\n return flattenedOption.sort((a, b) => compareFn(a, b, searchQuery));\n}\n\n/**\n * A prebuilt sort function for `sortFilteredOptions` that sorts options by relevance to the search query.\n * Prioritizes: exact matches > starts with > contains > alphabetical.\n *\n * @param getLabel - Function to extract the label string from the option value. Defaults to using `title` property.\n *\n * @example\n * ```tsx\n * <SelectInput\n * filterable\n * sortFilteredOptions={sortByRelevance((value) => value.name)}\n * // ...\n * />\n * ```\n */\nexport function sortByRelevance<T>(\n getLabel: (value: T) => string = (value) => (value as { title: string }).title,\n): (a: SelectInputOptionItem<T>, b: SelectInputOptionItem<T>, searchQuery: string) => number {\n return (a, b, searchQuery) => {\n const normalizedQuery = searchQuery.toLowerCase();\n const labelA = getLabel(a.value).toLowerCase();\n const labelB = getLabel(b.value).toLowerCase();\n\n // Prioritize exact matches\n const aExactMatch = labelA === normalizedQuery;\n const bExactMatch = labelB === normalizedQuery;\n if (aExactMatch && !bExactMatch) return -1;\n if (!aExactMatch && bExactMatch) return 1;\n\n // Then prioritize options where label starts with the search query\n const aStartsWith = labelA.startsWith(normalizedQuery);\n const bStartsWith = labelB.startsWith(normalizedQuery);\n if (aStartsWith && !bStartsWith) return -1;\n if (!aStartsWith && bStartsWith) return 1;\n\n // Then prioritize options where label contains the search query\n const aContains = labelA.includes(normalizedQuery);\n const bContains = labelB.includes(normalizedQuery);\n if (aContains && !bContains) return -1;\n if (!aContains && bContains) return 1;\n\n // Finally sort alphabetically\n return labelA.localeCompare(labelB);\n };\n}\n"],"names":["MAX_ITEMS_WITHOUT_VIRTUALIZATION","searchableString","value","trim","replace","normalize","toLowerCase","inferSearchableStrings","Object","values","filter","innerValue","map","dedupeSelectInputOptionItem","item","existingValues","compareValues","isDuplicate","Array","from","some","existingValue","has","add","undefined","dedupeSelectInputItems","items","Set","type","options","option","selectInputOptionItemIncludesNeedle","needle","filterMatchers","haystack","includes","filterSelectInputItems","predicate","sortSelectInputItems","compareFn","searchQuery","flattenedOption","flatMap","sort","a","b","sortByRelevance","getLabel","title","normalizedQuery","labelA","labelB","aExactMatch","bExactMatch","aStarts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W,EAAE;AAE9C;AACA,IAAA,MAAM8C,WAAW,GAAGF,MAAM,KAAKD,eAAe;AAC9C,IAAA,MAAMI,WAAW,GAAGF,MAAM,KAAKF,eAAe;AAC9C,IAAA,IAAIG,WAAW,IAAI,CAACC,WAAW,EAAE,OAAO,EAAE;AAC1C,IAAA,IAAI,CAACD,WAAW,IAAIC,WAAW,EAAE,OAAO,CAAC;AAEzC;AACA,IAAA,MAAMC,WAAW,GAAGJ,MAAM,CAACK,UAAU,CAACN,eAAe,CAAC;AACtD,IAAA,MAAMO,WAAW,GAAGL,MAAM,CAACI,UAAU,CAACN,eAAe,CAAC;AACtD,IAAA,IAAIK,WAAW,IAAI,CAACE,WAAW,EAAE,OAAO,EAAE;AAC1C,IAAA,IAAI,CAACF,WAAW,IAAIE,WAAW,EAAE,OAAO,CAAC;AAEzC;AACA,IAAA,MAAMC,SAAS,GAAGP,MAAM,CAACf,QAAQ,CAACc,eAAe,CAAC;AAClD,IAAA,MAAMS,SAAS,GAAGP,MAAM,CAAChB,QAAQ,CAACc,eAAe,CAAC;AAClD,IAAA,IAAIQ,SAAS,IAAI,CAACC,SAAS,EAAE,OAAO,EAAE;AACtC,IAAA,IAAI,CAACD,SAAS,IAAIC,SAAS,EAAE,OAAO,CAAC;AAErC;AACA,IAAA,OAAOR,MAAM,CAACS,aAAa,CAACR,MAAM,CAAC;EACrC,CAAC;AACH;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const MAX_ITEMS_WITHOUT_VIRTUALIZATION = 50;
|
|
2
|
+
/**
|
|
3
|
+
* Converts a string to a normalized, searchable format by:
|
|
4
|
+
* - Trimming whitespace
|
|
5
|
+
* - Normalizing whitespace (convert multiple spaces to single space)
|
|
6
|
+
* - Converting to NFD normalization form to handle diacritics
|
|
7
|
+
* - Removing combining diacritical marks
|
|
8
|
+
* - Converting to lowercase
|
|
9
|
+
*/
|
|
10
|
+
function searchableString(value) {
|
|
11
|
+
return value.trim().replace(/\s+/gu, ' ')
|
|
12
|
+
// NFD converts an Å to A + ̊ (and other special characters)
|
|
13
|
+
.normalize('NFD')
|
|
14
|
+
// and then this replaces the ̊ with nothing (and other special characters)
|
|
15
|
+
.replace(/[\u0300-\u036f]/g, '').toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extracts searchable strings from a value.
|
|
19
|
+
* - If the value is a string, returns a normalized version.
|
|
20
|
+
* - If the value is an object, extracts all string values and normalizes them.
|
|
21
|
+
* - Otherwise returns an empty array.
|
|
22
|
+
*/
|
|
23
|
+
function inferSearchableStrings(value) {
|
|
24
|
+
if (typeof value === 'string') {
|
|
25
|
+
return [searchableString(value)];
|
|
26
|
+
}
|
|
27
|
+
if (typeof value === 'object' && value != null) {
|
|
28
|
+
return Object.values(value).filter(innerValue => typeof innerValue === 'string').map(innerValue => searchableString(innerValue));
|
|
29
|
+
}
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sets the value of a duplicate option item to undefined, effectively hiding it when rendered.
|
|
34
|
+
*/
|
|
35
|
+
function dedupeSelectInputOptionItem(item, existingValues, compareValues) {
|
|
36
|
+
const isDuplicate = compareValues ? Array.from(existingValues).some(existingValue => compareValues(item.value, existingValue)) : existingValues.has(item.value);
|
|
37
|
+
if (!isDuplicate) {
|
|
38
|
+
existingValues.add(item.value);
|
|
39
|
+
return item;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
...item,
|
|
43
|
+
value: undefined
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sets the `value` of duplicate option items to `undefined`, hiding them when
|
|
48
|
+
* rendered. Indexes are kept intact within groups to preserve the active item
|
|
49
|
+
* between filter changes when possible.
|
|
50
|
+
*/
|
|
51
|
+
function dedupeSelectInputItems(items, compareValues) {
|
|
52
|
+
const existingValues = new Set();
|
|
53
|
+
return items.map(item => {
|
|
54
|
+
switch (item.type) {
|
|
55
|
+
case 'option':
|
|
56
|
+
{
|
|
57
|
+
return dedupeSelectInputOptionItem(item, existingValues, compareValues);
|
|
58
|
+
}
|
|
59
|
+
case 'group':
|
|
60
|
+
{
|
|
61
|
+
return {
|
|
62
|
+
...item,
|
|
63
|
+
options: item.options.map(option => dedupeSelectInputOptionItem(option, existingValues, compareValues))
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return item;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Checks if a SelectInputOptionItem matches the search needle.
|
|
72
|
+
*/
|
|
73
|
+
function selectInputOptionItemIncludesNeedle(item, needle) {
|
|
74
|
+
return inferSearchableStrings(item.filterMatchers ?? item.value).some(haystack => haystack.includes(needle));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Filters SelectInputItems based on the provided predicate function.
|
|
78
|
+
* For group items, it checks if any of their options match the predicate.
|
|
79
|
+
*/
|
|
80
|
+
function filterSelectInputItems(items, predicate) {
|
|
81
|
+
return items.filter(item => {
|
|
82
|
+
switch (item.type) {
|
|
83
|
+
case 'option':
|
|
84
|
+
{
|
|
85
|
+
return predicate(item);
|
|
86
|
+
}
|
|
87
|
+
case 'group':
|
|
88
|
+
{
|
|
89
|
+
return item.options.some(option => predicate(option));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Flattens and sorts filtered options using the provided comparator.
|
|
97
|
+
* Extracts all options from groups, filters out undefined values (deduplicated items),
|
|
98
|
+
* sorts them, and returns as a flat list of option items.
|
|
99
|
+
*/
|
|
100
|
+
function sortSelectInputItems(items, compareFn, searchQuery) {
|
|
101
|
+
const flattenedOption = items.flatMap(item => {
|
|
102
|
+
if (item.type === 'option') {
|
|
103
|
+
return item.value !== undefined ? [item] : [];
|
|
104
|
+
}
|
|
105
|
+
if (item.type === 'group') {
|
|
106
|
+
return item.options.filter(option => option.value !== undefined);
|
|
107
|
+
}
|
|
108
|
+
return [];
|
|
109
|
+
});
|
|
110
|
+
// eslint-disable-next-line functional/immutable-data
|
|
111
|
+
return flattenedOption.sort((a, b) => compareFn(a, b, searchQuery));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A prebuilt sort function for `sortFilteredOptions` that sorts options by relevance to the search query.
|
|
115
|
+
* Prioritizes: exact matches > starts with > contains > alphabetical.
|
|
116
|
+
*
|
|
117
|
+
* @param getLabel - Function to extract the label string from the option value. Defaults to using `title` property.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```tsx
|
|
121
|
+
* <SelectInput
|
|
122
|
+
* filterable
|
|
123
|
+
* sortFilteredOptions={sortByRelevance((value) => value.name)}
|
|
124
|
+
* // ...
|
|
125
|
+
* />
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
function sortByRelevance(getLabel = value => value.title) {
|
|
129
|
+
return (a, b, searchQuery) => {
|
|
130
|
+
const normalizedQuery = searchQuery.toLowerCase();
|
|
131
|
+
const labelA = getLabel(a.value).toLowerCase();
|
|
132
|
+
const labelB = getLabel(b.value).toLowerCase();
|
|
133
|
+
// Prioritize exact matches
|
|
134
|
+
const aExactMatch = labelA === normalizedQuery;
|
|
135
|
+
const bExactMatch = labelB === normalizedQuery;
|
|
136
|
+
if (aExactMatch && !bExactMatch) return -1;
|
|
137
|
+
if (!aExactMatch && bExactMatch) return 1;
|
|
138
|
+
// Then prioritize options where label starts with the search query
|
|
139
|
+
const aStartsWith = labelA.startsWith(normalizedQuery);
|
|
140
|
+
const bStartsWith = labelB.startsWith(normalizedQuery);
|
|
141
|
+
if (aStartsWith && !bStartsWith) return -1;
|
|
142
|
+
if (!aStartsWith && bStartsWith) return 1;
|
|
143
|
+
// Then prioritize options where label contains the search query
|
|
144
|
+
const aContains = labelA.includes(normalizedQuery);
|
|
145
|
+
const bContains = labelB.includes(normalizedQuery);
|
|
146
|
+
if (aContains && !bContains) return -1;
|
|
147
|
+
if (!aContains && bContains) return 1;
|
|
148
|
+
// Finally sort alphabetically
|
|
149
|
+
return labelA.localeCompare(labelB);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { MAX_ITEMS_WITHOUT_VIRTUALIZATION, dedupeSelectInputItems, dedupeSelectInputOptionItem, filterSelectInputItems, inferSearchableStrings, searchableString, selectInputOptionItemIncludesNeedle, sortByRelevance, sortSelectInputItems };
|
|
154
|
+
//# sourceMappingURL=SelectInput.utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectInput.utils.mjs","sources":["../../../src/inputs/SelectInput/SelectInput.utils.ts"],"sourcesContent":["import { SelectInputItem, SelectInputOptionItem } from './SelectInput.types';\n\nexport const MAX_ITEMS_WITHOUT_VIRTUALIZATION = 50;\n\n/**\n * Converts a string to a normalized, searchable format by:\n * - Trimming whitespace\n * - Normalizing whitespace (convert multiple spaces to single space)\n * - Converting to NFD normalization form to handle diacritics\n * - Removing combining diacritical marks\n * - Converting to lowercase\n */\nexport function searchableString(value: string) {\n return (\n value\n .trim()\n .replace(/\\s+/gu, ' ')\n // NFD converts an Å to A + ̊ (and other special characters)\n .normalize('NFD')\n // and then this replaces the ̊ with nothing (and other special characters)\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n );\n}\n\n/**\n * Extracts searchable strings from a value.\n * - If the value is a string, returns a normalized version.\n * - If the value is an object, extracts all string values and normalizes them.\n * - Otherwise returns an empty array.\n */\nexport function inferSearchableStrings(value: unknown) {\n if (typeof value === 'string') {\n return [searchableString(value)];\n }\n\n if (typeof value === 'object' && value != null) {\n return Object.values(value)\n .filter((innerValue) => typeof innerValue === 'string')\n .map((innerValue) => searchableString(innerValue));\n }\n\n return [];\n}\n\n/**\n * Sets the value of a duplicate option item to undefined, effectively hiding it when rendered.\n */\nexport function dedupeSelectInputOptionItem<T>(\n item: SelectInputOptionItem<T>,\n existingValues: Set<T>,\n compareValues?: (a: T, b: T) => boolean,\n): SelectInputOptionItem<T | undefined> {\n const isDuplicate = compareValues\n ? Array.from(existingValues).some((existingValue) => compareValues(item.value, existingValue))\n : existingValues.has(item.value);\n\n if (!isDuplicate) {\n existingValues.add(item.value);\n return item;\n }\n return { ...item, value: undefined };\n}\n\n/**\n * Sets the `value` of duplicate option items to `undefined`, hiding them when\n * rendered. Indexes are kept intact within groups to preserve the active item\n * between filter changes when possible.\n */\nexport function dedupeSelectInputItems<T>(\n items: readonly SelectInputItem<T>[],\n compareValues?: (a: T, b: T) => boolean,\n): SelectInputItem<T | undefined>[] {\n const existingValues = new Set<T>();\n\n return items.map((item) => {\n switch (item.type) {\n case 'option': {\n return dedupeSelectInputOptionItem(item, existingValues, compareValues);\n }\n case 'group': {\n return {\n ...item,\n options: item.options.map((option) =>\n dedupeSelectInputOptionItem(option, existingValues, compareValues),\n ),\n };\n }\n default:\n }\n return item;\n });\n}\n\n/**\n * Checks if a SelectInputOptionItem matches the search needle.\n */\nexport function selectInputOptionItemIncludesNeedle<T>(\n item: SelectInputOptionItem<T>,\n needle: string,\n) {\n return inferSearchableStrings(item.filterMatchers ?? item.value).some((haystack) =>\n haystack.includes(needle),\n );\n}\n\n/**\n * Filters SelectInputItems based on the provided predicate function.\n * For group items, it checks if any of their options match the predicate.\n */\nexport function filterSelectInputItems<T>(\n items: readonly SelectInputItem<T>[],\n predicate: (item: SelectInputOptionItem<T>) => boolean,\n) {\n return items.filter((item) => {\n switch (item.type) {\n case 'option': {\n return predicate(item);\n }\n case 'group': {\n return item.options.some((option) => predicate(option));\n }\n default:\n }\n return false;\n });\n}\n\n/**\n * Flattens and sorts filtered options using the provided comparator.\n * Extracts all options from groups, filters out undefined values (deduplicated items),\n * sorts them, and returns as a flat list of option items.\n */\nexport function sortSelectInputItems<T>(\n items: readonly SelectInputItem<T | undefined>[],\n compareFn: (\n a: SelectInputOptionItem<NonNullable<T>>,\n b: SelectInputOptionItem<NonNullable<T>>,\n searchQuery: string,\n ) => number,\n searchQuery: string,\n): SelectInputItem<NonNullable<T>>[] {\n const flattenedOption = items.flatMap((item) => {\n if (item.type === 'option') {\n return item.value !== undefined ? [item as SelectInputOptionItem<NonNullable<T>>] : [];\n }\n\n if (item.type === 'group') {\n return item.options.filter(\n (option): option is SelectInputOptionItem<NonNullable<T>> => option.value !== undefined,\n );\n }\n\n return [];\n });\n\n // eslint-disable-next-line functional/immutable-data\n return flattenedOption.sort((a, b) => compareFn(a, b, searchQuery));\n}\n\n/**\n * A prebuilt sort function for `sortFilteredOptions` that sorts options by relevance to the search query.\n * Prioritizes: exact matches > starts with > contains > alphabetical.\n *\n * @param getLabel - Function to extract the label string from the option value. Defaults to using `title` property.\n *\n * @example\n * ```tsx\n * <SelectInput\n * filterable\n * sortFilteredOptions={sortByRelevance((value) => value.name)}\n * // ...\n * />\n * ```\n */\nexport function sortByRelevance<T>(\n getLabel: (value: T) => string = (value) => (value as { title: string }).title,\n): (a: SelectInputOptionItem<T>, b: SelectInputOptionItem<T>, searchQuery: string) => number {\n return (a, b, searchQuery) => {\n const normalizedQuery = searchQuery.toLowerCase();\n const labelA = getLabel(a.value).toLowerCase();\n const labelB = getLabel(b.value).toLowerCase();\n\n // Prioritize exact matches\n const aExactMatch = labelA === normalizedQuery;\n const bExactMatch = labelB === normalizedQuery;\n if (aExactMatch && !bExactMatch) return -1;\n if (!aExactMatch && bExactMatch) return 1;\n\n // Then prioritize options where label starts with the search query\n const aStartsWith = labelA.startsWith(normalizedQuery);\n const bStartsWith = labelB.startsWith(normalizedQuery);\n if (aStartsWith && !bStartsWith) return -1;\n if (!aStartsWith && bStartsWith) return 1;\n\n // Then prioritize options where label contains the search query\n const aContains = labelA.includes(normalizedQuery);\n const bContains = labelB.includes(normalizedQuery);\n if (aContains && !bContains) return -1;\n if (!aContains && bContains) return 1;\n\n // Finally sort alphabetically\n return labelA.localeCompare(labelB);\n };\n}\n"],"names":["MAX_ITEMS_WITHOUT_VIRTUALIZATION","searchableString","value","trim","replace","normalize","toLowerCase","inferSearchableStrings","Object","values","filter","innerValue","map","dedupeSelectInputOptionItem","item","existingValues","compareValues","isDuplicate","Array","from","some","existingValue","has","add","undefined","dedupeSelectInputItems","items","Set","type","options","option","selectInputOptionItemIncludesNeedle","needle","filterMatchers","haystack","includes","filterSelectInputItems","predicate","sortSelectInputItems","compareFn","searchQuery","flattenedOption","flatMap","sort","a","b","sortByRelevance","getLabel","title","normalizedQuery","labelA","labelB","aExactMatch","bExactMatch","aStartsWith","startsWith","bStartsWith","aContains","bContains","localeCompare"],"mappings":"AAEO,MAAMA,gCAAgC,GAAG;AAEhD;;;;;;;AAOG;AACG,SAAUC,gBAAgBA,CAACC,KAAa,EAAA;EAC5C,OACEA,KAAK,CACFC,IAAI,EAAE,CACNC,OAAO,CAAC,OAAO,EAAE,GAAG;AACrB;GACCC,SAAS,CAAC,KAAK;AAChB;GACCD,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAC/BE,WAAW,EAAE;AAEpB;AAEA;;;;;AAKG;AACG,SAAUC,sBAAsBA,CAACL,KAAc,EAAA;AACnD,EAAA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;AAC7B,IAAA,OAAO,CAACD,gBAAgB,CAACC,KAAK,CAAC,CAAC;AAClC,EAAA;EAEA,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,IAAI,IAAI,EAAE;IAC9C,OAAOM,MAAM,CAACC,MAAM,CAACP,KAAK,CAAC,CACxBQ,MAAM,CAAEC,UAAU,IAAK,OAAOA,UAAU,KAAK,QAAQ,CAAC,CACtDC,GAAG,CAAED,UAAU,IAAKV,gBAAgB,CAACU,UAAU,CAAC,CAAC;AACtD,EAAA;AAEA,EAAA,OAAO,EAAE;AACX;AAEA;;AAEG;SACaE,2BAA2BA,CACzCC,IAA8B,EAC9BC,cAAsB,EACtBC,aAAuC,EAAA;AAEvC,EAAA,MAAMC,WAAW,GAAGD,aAAa,GAC7BE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strict';
|
|
2
|
+
|
|
3
|
+
var react = require('@headlessui/react');
|
|
4
|
+
var mergeProps = require('merge-props');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var PolymorphicWithOverrides = require('../../../common/polymorphicWithOverrides/PolymorphicWithOverrides.js');
|
|
7
|
+
var SelectInput_contexts = require('../SelectInput.contexts.js');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var mergeProps__default = /*#__PURE__*/_interopDefault(mergeProps);
|
|
13
|
+
|
|
14
|
+
function SelectInputTriggerButton({
|
|
15
|
+
as = 'button',
|
|
16
|
+
...restProps
|
|
17
|
+
}) {
|
|
18
|
+
const {
|
|
19
|
+
ref,
|
|
20
|
+
onClick,
|
|
21
|
+
onKeyDown,
|
|
22
|
+
size,
|
|
23
|
+
...interactionProps
|
|
24
|
+
} = React.useContext(SelectInput_contexts.SelectInputTriggerButtonPropsContext);
|
|
25
|
+
return /*#__PURE__*/jsxRuntime.jsx(react.ListboxButton, {
|
|
26
|
+
ref: ref,
|
|
27
|
+
as: PolymorphicWithOverrides.PolymorphicWithOverrides,
|
|
28
|
+
role: "combobox",
|
|
29
|
+
__overrides: {
|
|
30
|
+
as,
|
|
31
|
+
size,
|
|
32
|
+
...interactionProps
|
|
33
|
+
},
|
|
34
|
+
...mergeProps__default.default({
|
|
35
|
+
onClick,
|
|
36
|
+
onKeyDown
|
|
37
|
+
}, restProps)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.SelectInputTriggerButton = SelectInputTriggerButton;
|
|
42
|
+
//# sourceMappingURL=SelectInputTriggerButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectInputTriggerButton.js","sources":["../../../../src/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx"],"sourcesContent":["import { ListboxButton } from '@headlessui/react';\nimport mergeProps from 'merge-props';\nimport { useContext } from 'react';\nimport { PolymorphicWithOverrides } from '../../../common/polymorphicWithOverrides/PolymorphicWithOverrides';\nimport { Merge } from '../../../utils';\nimport { SelectInputTriggerButtonPropsContext } from '../SelectInput.contexts';\n\nexport type SelectInputTriggerButtonElementType = 'button' | React.ComponentType;\n\nexport type SelectInputTriggerButtonProps<\n T extends SelectInputTriggerButtonElementType = 'button',\n> = Merge<React.ComponentPropsWithoutRef<T>, { as?: T }>;\n\n/**\n * The trigger button component for SelectInput.\n * Uses Headless UI's ListboxButton with polymorphic support to allow\n * rendering as different element types.\n */\nexport function SelectInputTriggerButton<T extends SelectInputTriggerButtonElementType = 'button'>({\n as = 'button' as T,\n ...restProps\n}: SelectInputTriggerButtonProps<T>) {\n const { ref, onClick, onKeyDown, size, ...interactionProps } = useContext(\n SelectInputTriggerButtonPropsContext,\n );\n\n return (\n <ListboxButton\n ref={ref}\n as={PolymorphicWithOverrides}\n role=\"combobox\"\n __overrides={{ as, size, ...interactionProps } as Record<string, unknown>}\n {...mergeProps({ onClick, onKeyDown }, restProps)}\n />\n );\n}\n"],"names":["SelectInputTriggerButton","as","restProps","ref","onClick","onKeyDown","size","interactionProps","useContext","SelectInputTriggerButtonPropsContext","_jsx","ListboxButton","PolymorphicWithOverrides","role","__overrides","mergeProps"],"mappings":";;;;;;;;;;;;;AAkBM,SAAUA,wBAAwBA,CAA2D;AACjGC,EAAAA,EAAE,GAAG,QAAa;EAClB,GAAGC;AAAS,CACqB,EAAA;EACjC,MAAM;IAAEC,GAAG;IAAEC,OAAO;IAAEC,SAAS;IAAEC,IAAI;IAAE,GAAGC;AAAgB,GAAE,GAAGC,gBAAU,CACvEC,yDAAoC,CACrC;EAED,oBACEC,cAAA,CAACC,mBAAa,EAAA;AACZR,IAAAA,GAAG,EAAEA,GAAI;AACTF,IAAAA,EAAE,EAAEW,iDAAyB;AAC7BC,IAAAA,IAAI,EAAC,UAAU;AACfC,IAAAA,WAAW,EAAE;MAAEb,EAAE;MAAEK,IAAI;MAAE,GAAGC;KAA8C;AAAA,IAAA,GACtEQ,2BAAU,CAAC;MAAEX,OAAO;AAAEC,MAAAA;AAAS,KAAE,EAAEH,SAAS;AAAC,GAAC,CAClD;AAEN;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ListboxButton } from '@headlessui/react';
|
|
2
|
+
import mergeProps from 'merge-props';
|
|
3
|
+
import { useContext } from 'react';
|
|
4
|
+
import { PolymorphicWithOverrides } from '../../../common/polymorphicWithOverrides/PolymorphicWithOverrides.mjs';
|
|
5
|
+
import { SelectInputTriggerButtonPropsContext } from '../SelectInput.contexts.mjs';
|
|
6
|
+
import { jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
function SelectInputTriggerButton({
|
|
9
|
+
as = 'button',
|
|
10
|
+
...restProps
|
|
11
|
+
}) {
|
|
12
|
+
const {
|
|
13
|
+
ref,
|
|
14
|
+
onClick,
|
|
15
|
+
onKeyDown,
|
|
16
|
+
size,
|
|
17
|
+
...interactionProps
|
|
18
|
+
} = useContext(SelectInputTriggerButtonPropsContext);
|
|
19
|
+
return /*#__PURE__*/jsx(ListboxButton, {
|
|
20
|
+
ref: ref,
|
|
21
|
+
as: PolymorphicWithOverrides,
|
|
22
|
+
role: "combobox",
|
|
23
|
+
__overrides: {
|
|
24
|
+
as,
|
|
25
|
+
size,
|
|
26
|
+
...interactionProps
|
|
27
|
+
},
|
|
28
|
+
...mergeProps({
|
|
29
|
+
onClick,
|
|
30
|
+
onKeyDown
|
|
31
|
+
}, restProps)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { SelectInputTriggerButton };
|
|
36
|
+
//# sourceMappingURL=SelectInputTriggerButton.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectInputTriggerButton.mjs","sources":["../../../../src/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx"],"sourcesContent":["import { ListboxButton } from '@headlessui/react';\nimport mergeProps from 'merge-props';\nimport { useContext } from 'react';\nimport { PolymorphicWithOverrides } from '../../../common/polymorphicWithOverrides/PolymorphicWithOverrides';\nimport { Merge } from '../../../utils';\nimport { SelectInputTriggerButtonPropsContext } from '../SelectInput.contexts';\n\nexport type SelectInputTriggerButtonElementType = 'button' | React.ComponentType;\n\nexport type SelectInputTriggerButtonProps<\n T extends SelectInputTriggerButtonElementType = 'button',\n> = Merge<React.ComponentPropsWithoutRef<T>, { as?: T }>;\n\n/**\n * The trigger button component for SelectInput.\n * Uses Headless UI's ListboxButton with polymorphic support to allow\n * rendering as different element types.\n */\nexport function SelectInputTriggerButton<T extends SelectInputTriggerButtonElementType = 'button'>({\n as = 'button' as T,\n ...restProps\n}: SelectInputTriggerButtonProps<T>) {\n const { ref, onClick, onKeyDown, size, ...interactionProps } = useContext(\n SelectInputTriggerButtonPropsContext,\n );\n\n return (\n <ListboxButton\n ref={ref}\n as={PolymorphicWithOverrides}\n role=\"combobox\"\n __overrides={{ as, size, ...interactionProps } as Record<string, unknown>}\n {...mergeProps({ onClick, onKeyDown }, restProps)}\n />\n );\n}\n"],"names":["SelectInputTriggerButton","as","restProps","ref","onClick","onKeyDown","size","interactionProps","useContext","SelectInputTriggerButtonPropsContext","_jsx","ListboxButton","PolymorphicWithOverrides","role","__overrides","mergeProps"],"mappings":";;;;;;;AAkBM,SAAUA,wBAAwBA,CAA2D;AACjGC,EAAAA,EAAE,GAAG,QAAa;EAClB,GAAGC;AAAS,CACqB,EAAA;EACjC,MAAM;IAAEC,GAAG;IAAEC,OAAO;IAAEC,SAAS;IAAEC,IAAI;IAAE,GAAGC;AAAgB,GAAE,GAAGC,UAAU,CACvEC,oCAAoC,CACrC;EAED,oBACEC,GAAA,CAACC,aAAa,EAAA;AACZR,IAAAA,GAAG,EAAEA,GAAI;AACTF,IAAAA,EAAE,EAAEW,wBAAyB;AAC7BC,IAAAA,IAAI,EAAC,UAAU;AACfC,IAAAA,WAAW,EAAE;MAAEb,EAAE;MAAEK,IAAI;MAAE,GAAGC;KAA8C;AAAA,IAAA,GACtEQ,UAAU,CAAC;MAAEX,OAAO;AAAEC,MAAAA;AAAS,KAAE,EAAEH,SAAS;AAAC,GAAC,CAClD;AAEN;;;;"}
|