@procore/core-react 11.5.0-rc.3 → 11.5.0-rc.5

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 (98) hide show
  1. package/dist/MultiSelect/MultiSelect.styles.d.ts +1 -1
  2. package/dist/NumberInput/NumberInput.d.ts +2 -1
  3. package/dist/NumberInput/NumberInput.js +32 -3
  4. package/dist/NumberInput/NumberInput.js.map +1 -1
  5. package/dist/NumberInput/NumberInput.types.d.ts +12 -0
  6. package/dist/NumberInput/NumberInput.utils.d.ts +2 -1
  7. package/dist/NumberInput/NumberInput.utils.js +25 -14
  8. package/dist/NumberInput/NumberInput.utils.js.map +1 -1
  9. package/dist/SuperSelect/SuperSelect.d.ts +57 -0
  10. package/dist/SuperSelect/SuperSelect.js +159 -0
  11. package/dist/SuperSelect/SuperSelect.js.map +1 -0
  12. package/dist/SuperSelect/SuperSelect.styles.d.ts +6 -0
  13. package/dist/SuperSelect/SuperSelect.styles.js +13 -0
  14. package/dist/SuperSelect/SuperSelect.styles.js.map +1 -0
  15. package/dist/SuperSelect/SuperSelect.types.d.ts +95 -0
  16. package/dist/SuperSelect/SuperSelect.types.js +2 -0
  17. package/dist/SuperSelect/SuperSelect.types.js.map +1 -0
  18. package/dist/SuperSelect/useSuperSelect.d.ts +61 -0
  19. package/dist/SuperSelect/useSuperSelect.js +474 -0
  20. package/dist/SuperSelect/useSuperSelect.js.map +1 -0
  21. package/dist/Typeahead/Typeahead.js +1 -1
  22. package/dist/Typeahead/Typeahead.js.map +1 -1
  23. package/dist/_typedoc/Avatar/Avatar.types.json +17 -17
  24. package/dist/_typedoc/AvatarStack/AvatarStack.types.json +22 -22
  25. package/dist/_typedoc/Badge/Badge.types.json +6 -6
  26. package/dist/_typedoc/Banner/Banner.types.json +12 -12
  27. package/dist/_typedoc/Box/Box.types.json +68 -68
  28. package/dist/_typedoc/Breadcrumbs/Breadcrumbs.types.json +7 -7
  29. package/dist/_typedoc/Button/Button.types.json +11 -11
  30. package/dist/_typedoc/Calendar/Calendar.types.json +80 -80
  31. package/dist/_typedoc/Card/Card.types.json +6 -6
  32. package/dist/_typedoc/Checkbox/Checkbox.types.json +7 -7
  33. package/dist/_typedoc/ContactItem/ContactItem.types.json +9 -9
  34. package/dist/_typedoc/DateInput/DateInput.types.json +35 -35
  35. package/dist/_typedoc/DateSelect/DateSelect.types.json +13 -13
  36. package/dist/_typedoc/DetailPage/DetailPage.types.json +4 -4
  37. package/dist/_typedoc/Dropdown/Dropdown.types.json +36 -36
  38. package/dist/_typedoc/DropdownFlyout/DropdownFlyout.types.json +29 -29
  39. package/dist/_typedoc/Dropzone/Dropzone.types.json +41 -41
  40. package/dist/_typedoc/EmptyState/EmptyState.types.json +14 -14
  41. package/dist/_typedoc/FileList/FileList.types.json +9 -9
  42. package/dist/_typedoc/FileSelect/FileSelect.types.json +26 -26
  43. package/dist/_typedoc/FileSelect/GridSource/GridSource.types.json +20 -20
  44. package/dist/_typedoc/FileSelect/LocalSource/LocalSource.types.json +14 -14
  45. package/dist/_typedoc/FileSelect/TreeSource/TreeSource.types.json +9 -9
  46. package/dist/_typedoc/Flex/Flex.types.json +27 -27
  47. package/dist/_typedoc/FlexList/FlexList.types.json +30 -30
  48. package/dist/_typedoc/Form/Form.types.json +694 -694
  49. package/dist/_typedoc/Grid/Grid.types.json +8 -8
  50. package/dist/_typedoc/GroupSelect/GroupSelect.types.json +52 -52
  51. package/dist/_typedoc/Input/Input.types.json +2 -2
  52. package/dist/_typedoc/Link/Link.types.json +4 -4
  53. package/dist/_typedoc/ListPage/ListPage.types.json +13 -13
  54. package/dist/_typedoc/Menu/Menu.types.json +62 -62
  55. package/dist/_typedoc/MenuImperative/MenuImperative.types.json +71 -71
  56. package/dist/_typedoc/Modal/Modal.types.json +27 -27
  57. package/dist/_typedoc/MultiSelect/MultiSelect.types.json +31 -31
  58. package/dist/_typedoc/Notation/Notation.types.json +4 -4
  59. package/dist/_typedoc/NumberInput/NumberInput.types.json +124 -36
  60. package/dist/_typedoc/PageLayout/PageLayout.types.json +7 -7
  61. package/dist/_typedoc/Pagination/Pagination.types.json +7 -7
  62. package/dist/_typedoc/Panel/Panel.types.json +27 -27
  63. package/dist/_typedoc/Pill/Pill.types.json +1 -1
  64. package/dist/_typedoc/PillSelect/PillSelect.types.json +46 -46
  65. package/dist/_typedoc/Popover/Popover.types.json +10 -10
  66. package/dist/_typedoc/ProgressBar/ProgressBar.types.json +5 -5
  67. package/dist/_typedoc/RadioButton/RadioButton.types.json +6 -6
  68. package/dist/_typedoc/Required/Required.types.json +5 -5
  69. package/dist/_typedoc/Search/Search.types.json +18 -18
  70. package/dist/_typedoc/Section/Section.types.json +14 -14
  71. package/dist/_typedoc/SegmentedController/SegmentedController.types.json +20 -20
  72. package/dist/_typedoc/Select/Select.types.json +31 -31
  73. package/dist/_typedoc/Slider/Slider.types.json +6 -6
  74. package/dist/_typedoc/Spinner/Spinner.types.json +9 -9
  75. package/dist/_typedoc/Switch/Switch.types.json +3 -3
  76. package/dist/_typedoc/Table/Table.types.json +94 -94
  77. package/dist/_typedoc/Tabs/Tabs.types.json +15 -15
  78. package/dist/_typedoc/Tearsheet/Tearsheet.types.json +10 -10
  79. package/dist/_typedoc/TextArea/TextArea.types.json +3 -3
  80. package/dist/_typedoc/TextEditor/TextEditor.types.json +7 -7
  81. package/dist/_typedoc/TextEditorOutput/TextEditorOutput.types.json +3 -3
  82. package/dist/_typedoc/Thumbnail/Thumbnail.types.json +25 -25
  83. package/dist/_typedoc/TieredDropdown/TieredDropdown.types.json +42 -42
  84. package/dist/_typedoc/TieredSelect/TieredSelect.types.json +28 -28
  85. package/dist/_typedoc/Tile/Tile.types.json +30 -30
  86. package/dist/_typedoc/Toast/Toast.types.json +4 -4
  87. package/dist/_typedoc/ToggleButton/ToggleButton.types.json +3 -3
  88. package/dist/_typedoc/Token/Token.types.json +4 -4
  89. package/dist/_typedoc/ToolHeader/ToolHeader.types.json +8 -8
  90. package/dist/_typedoc/Tooltip/Tooltip.types.json +13 -13
  91. package/dist/_typedoc/Tree/Tree.types.json +86 -86
  92. package/dist/_typedoc/Typeahead/Typeahead.types.json +2 -2
  93. package/dist/_typedoc/Typography/Typography.types.json +8 -8
  94. package/dist/_typedoc/_utils/types.json +3 -3
  95. package/dist/index.d.ts +1 -0
  96. package/dist/index.js +1 -0
  97. package/dist/index.js.map +1 -1
  98. package/package.json +12 -2
@@ -0,0 +1,13 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ import { Virtuoso } from 'react-virtuoso';
6
+ import styled from 'styled-components';
7
+ import { Card } from '../Card/Card';
8
+ import { getEllipsis } from '../_styles/mixins';
9
+ export var StyledOverlay = styled(Card)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n"], ["\n display: flex;\n flex-direction: column;\n"])));
10
+ export var StyledVirtuoso = styled(Virtuoso)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n flex: 1 1 auto;\n"], ["\n flex: 1 1 auto;\n"])));
11
+ export var StyledEllipses = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n ", "\n display: inline-flex;\n\n > div {\n display: inline-flex;\n width: 100%;\n }\n"], ["\n ", "\n display: inline-flex;\n\n > div {\n display: inline-flex;\n width: 100%;\n }\n"])), getEllipsis());
12
+ var templateObject_1, templateObject_2, templateObject_3;
13
+ //# sourceMappingURL=SuperSelect.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SuperSelect.styles.js","sourceRoot":"","sources":["../../src/SuperSelect/SuperSelect.styles.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,MAAM,MAAM,mBAAmB,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,MAAM,CAAC,IAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,oHAAA,iDAGxC,IAAA,CAAA;AAED,MAAM,CAAC,IAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAC,0FAAA,uBAE7C,IAAA,CAAA;AAED,MAAM,CAAC,IAAM,cAAc,GAAG,MAAM,CAAC,GAAG,uKAAA,MACpC,EAAa,4FAOhB,KAPG,WAAW,EAAE,CAOhB,CAAA"}
@@ -0,0 +1,95 @@
1
+ import React from 'react';
2
+ import { useSuperSelect } from './useSuperSelect';
3
+ export interface SuperSelectProps {
4
+ block?: boolean;
5
+ components?: {
6
+ Label?: React.FC<{
7
+ selectApi: SuperSelectApi;
8
+ }>;
9
+ MenuItemLabel?: React.FC<{
10
+ selectApi: SuperSelectApi;
11
+ option: any;
12
+ }>;
13
+ Token?: React.FC<{
14
+ selectApi: SuperSelectApi;
15
+ option: any;
16
+ index: number;
17
+ focused: boolean;
18
+ }>;
19
+ };
20
+ defaultValue?: SuperSelectValue;
21
+ disabled?: boolean;
22
+ emptyMessage: string;
23
+ error?: boolean;
24
+ footer?: React.ReactElement;
25
+ getOptionGroup?: (option: any) => string;
26
+ getOptionIsBatch?: (option: any) => boolean;
27
+ getOptionIsDisabled?: (option: any) => boolean;
28
+ getOptionLabel?: (option: any) => string;
29
+ getOptionValue?: (option: any) => SuperSelectValuePrimitive;
30
+ header?: React.ReactElement;
31
+ loading?: boolean;
32
+ multiple?: boolean;
33
+ multipleOptions?: any[];
34
+ multipleOptionsLabel?: string;
35
+ onChange?: (value: SuperSelectValue) => void;
36
+ options: Record<string, any>[];
37
+ placeholder?: string;
38
+ search?: boolean;
39
+ tabIndex?: number;
40
+ value?: SuperSelectValue;
41
+ }
42
+ export interface TokenNavigationProps {
43
+ activeIndex?: number | null;
44
+ enabled?: boolean;
45
+ onChange?: (value: SuperSelectValue) => void;
46
+ onNavigate?: (index: number | null) => void;
47
+ value?: SuperSelectValue;
48
+ }
49
+ export interface KeyboardSelectionProps {
50
+ enabled?: boolean;
51
+ onSelect?: () => void;
52
+ }
53
+ export declare type SuperSelectValuePrimitive = boolean | string | number;
54
+ export declare type SuperSelectValue = SuperSelectValuePrimitive | Array<SuperSelectValuePrimitive> | null;
55
+ export declare type SuperSelectOption = any;
56
+ export interface SuperSelectConfig {
57
+ components?: {
58
+ Label?: React.FC<{
59
+ selectApi: SuperSelectApi;
60
+ }>;
61
+ MenuItemLabel?: React.FC<{
62
+ selectApi: SuperSelectApi;
63
+ option: any;
64
+ }>;
65
+ Token?: React.FC<{
66
+ selectApi: SuperSelectApi;
67
+ option: any;
68
+ index: number;
69
+ focused: boolean;
70
+ }>;
71
+ };
72
+ defaultValue?: SuperSelectValue;
73
+ disabled?: boolean;
74
+ getOptionGroup?: (option: SuperSelectOption) => string;
75
+ getOptionIsBatch?: (option: SuperSelectOption) => boolean;
76
+ getOptionIsDisabled?: (option: SuperSelectOption) => boolean;
77
+ getOptionLabel?: (option: SuperSelectOption) => string;
78
+ getOptionValue?: (option: SuperSelectOption) => SuperSelectValuePrimitive;
79
+ multiple?: boolean;
80
+ onChange?: (value: SuperSelectValue) => void;
81
+ options?: Array<any>;
82
+ search?: boolean;
83
+ value?: SuperSelectValue;
84
+ }
85
+ export declare type SuperSelectApi = ReturnType<typeof useSuperSelect>;
86
+ export interface SuperSelectReferenceProps {
87
+ selectApi: SuperSelectApi;
88
+ block?: boolean;
89
+ disabled?: boolean;
90
+ error?: boolean;
91
+ loading?: boolean;
92
+ placeholder?: string;
93
+ search?: boolean;
94
+ tabIndex?: number;
95
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=SuperSelect.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SuperSelect.types.js","sourceRoot":"","sources":["../../src/SuperSelect/SuperSelect.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,61 @@
1
+ /// <reference types="lodash" />
2
+ import React from 'react';
3
+ import { VirtuosoHandle } from 'react-virtuoso';
4
+ import { TypeaheadInputProps, TypeaheadProps } from '../Typeahead/Typeahead.types';
5
+ import { SuperSelectConfig, SuperSelectOption, SuperSelectValue, SuperSelectValuePrimitive } from './SuperSelect.types';
6
+ declare function getOptionIsOptgroup(item: any): boolean;
7
+ export declare function useSuperSelect({ components, defaultValue, disabled, getOptionGroup, getOptionIsBatch, getOptionIsDisabled, getOptionLabel, getOptionValue, multiple, onChange, options: sourceOptions, search, value: value_, }: SuperSelectConfig): {
8
+ activeMenuIndex: number | null;
9
+ activeTokenIndex: number | null;
10
+ components: {
11
+ Label?: React.FC<{
12
+ selectApi: any;
13
+ }> | undefined;
14
+ MenuItemLabel?: React.FC<{
15
+ selectApi: any;
16
+ option: any;
17
+ }> | undefined;
18
+ Token?: React.FC<{
19
+ selectApi: any;
20
+ option: any;
21
+ index: number;
22
+ focused: boolean;
23
+ }> | undefined;
24
+ } | undefined;
25
+ floating: import("@floating-ui/react-dom-interactions").UseFloatingReturn<HTMLElement>;
26
+ getClearProps: () => React.AriaAttributes & React.HTMLAttributes<HTMLElement>;
27
+ getFloatingProps: (userProps?: any) => Record<string, unknown>;
28
+ getItemProps: (userProps?: any) => Record<string, unknown>;
29
+ getMultiInputProps: () => React.AriaAttributes & React.InputHTMLAttributes<HTMLInputElement>;
30
+ getOptionGroup: (option: any) => string;
31
+ getOptionIsBatch: (option: any) => boolean;
32
+ getOptionIsDisabled: (option: any) => boolean;
33
+ getOptionIsOptgroup: typeof getOptionIsOptgroup;
34
+ getOptionLabel: (option: any) => string;
35
+ getOptionValue: (option: any) => SuperSelectValuePrimitive;
36
+ getReferenceProps: (userProps?: any) => Record<string, unknown>;
37
+ getTokenClearProps: (index: number) => React.AriaAttributes & React.SVGAttributes<SVGElement>;
38
+ getTypeaheadProps: () => React.AriaAttributes & TypeaheadInputProps & TypeaheadProps;
39
+ isEmpty: () => boolean;
40
+ isSelected: (option: any) => boolean;
41
+ listId: string;
42
+ maxHeight: number;
43
+ multiple: boolean;
44
+ navigationListRef: React.MutableRefObject<(HTMLElement | null)[]>;
45
+ onSelect: (option: SuperSelectOption) => void;
46
+ open: boolean;
47
+ sourceOptions: any[];
48
+ options: any[];
49
+ overlayId: string;
50
+ searchValue: string;
51
+ selectedIndex: number;
52
+ selectedOption: any;
53
+ selectedLabel: string;
54
+ setOpen: React.Dispatch<React.SetStateAction<boolean>>;
55
+ setPointer: React.Dispatch<React.SetStateAction<boolean>>;
56
+ setSearchValue: import("lodash").DebouncedFunc<React.Dispatch<React.SetStateAction<string>>>;
57
+ value: SuperSelectValue;
58
+ virtuoso: React.RefObject<VirtuosoHandle>;
59
+ width: number;
60
+ };
61
+ export {};
@@ -0,0 +1,474 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ import { autoUpdate, flip, offset, size, useClick, useDismiss, useFloating, useInteractions, useListNavigation, } from '@floating-ui/react-dom-interactions';
22
+ import { useId } from '@react-aria/utils';
23
+ import debounce from 'lodash.debounce';
24
+ import groupBy from 'lodash.groupby';
25
+ import uniq from 'lodash.uniq';
26
+ import React from 'react';
27
+ var optgroupSymbol = Symbol('Optgroup');
28
+ function noop() { }
29
+ function compareStrings(a, b) {
30
+ return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' });
31
+ }
32
+ function isMultiple(multiple, value) {
33
+ return multiple && Array.isArray(value);
34
+ }
35
+ function getOptionIsOptgroup(item) {
36
+ return Boolean(item[optgroupSymbol]);
37
+ }
38
+ function defaultGetOptionValue(option) {
39
+ return option === null || option === void 0 ? void 0 : option.value;
40
+ }
41
+ function defaultGetOptionIsBatch(option) {
42
+ return Array.isArray(option === null || option === void 0 ? void 0 : option.value);
43
+ }
44
+ function defaultGetOptionIsDisabled(option) {
45
+ var _a;
46
+ return (_a = option === null || option === void 0 ? void 0 : option.disabled) !== null && _a !== void 0 ? _a : false;
47
+ }
48
+ function defaultGetOptionGroup(option) {
49
+ var _a;
50
+ return (_a = option === null || option === void 0 ? void 0 : option.group) !== null && _a !== void 0 ? _a : '';
51
+ }
52
+ function defaultGetOptionLabel(option) {
53
+ var _a;
54
+ return (_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : '';
55
+ }
56
+ function useCustomReferenceProps(context, _a) {
57
+ var _b = _a.search, search = _b === void 0 ? true : _b, overlayId = _a.overlayId, listId = _a.listId, _c = _a.open, open = _c === void 0 ? false : _c, _d = _a.onChangePointer, onChangePointer = _d === void 0 ? noop : _d;
58
+ return {
59
+ reference: {
60
+ role: 'combobox',
61
+ 'aria-controls': search ? overlayId : listId,
62
+ 'aria-haspopup': search ? 'dialog' : 'listbox',
63
+ 'aria-expanded': open,
64
+ onKeyDown: function () {
65
+ onChangePointer(false);
66
+ },
67
+ },
68
+ };
69
+ }
70
+ function useCustomFloatingProps(context, _a) {
71
+ var _b = _a.search, search = _b === void 0 ? true : _b, onChangePointer = _a.onChangePointer;
72
+ return {
73
+ floating: {
74
+ role: search ? 'dialog' : 'none',
75
+ onKeyDown: function () {
76
+ onChangePointer(false);
77
+ },
78
+ onPointerMove: function () {
79
+ onChangePointer(true);
80
+ },
81
+ },
82
+ };
83
+ }
84
+ function useTokenNavigation(context, _a) {
85
+ var _b = _a === void 0 ? {} : _a, _c = _b.enabled, enabled = _c === void 0 ? true : _c, _d = _b.value, value = _d === void 0 ? [] : _d, _e = _b.activeIndex, activeIndex = _e === void 0 ? null : _e, _f = _b.onNavigate, onNavigate = _f === void 0 ? noop : _f, _g = _b.onChange, onChange = _g === void 0 ? noop : _g;
86
+ return {
87
+ reference: {
88
+ onKeyDown: function (e) {
89
+ if (!enabled || !Array.isArray(value)) {
90
+ return;
91
+ }
92
+ if (e.key === 'ArrowLeft') {
93
+ if (activeIndex !== null) {
94
+ onNavigate(Math.max(0, activeIndex - 1));
95
+ }
96
+ else if (value.length > 0) {
97
+ onNavigate(value.length - 1);
98
+ }
99
+ }
100
+ else if (e.key === 'ArrowRight') {
101
+ if (activeIndex !== null) {
102
+ if (activeIndex === value.length - 1) {
103
+ onNavigate(null);
104
+ }
105
+ else {
106
+ onNavigate(activeIndex + 1);
107
+ }
108
+ }
109
+ }
110
+ else if (e.key === 'Backspace') {
111
+ if (!e.repeat) {
112
+ if (activeIndex !== null) {
113
+ var nextVal = value.filter(function (_, i) { return i !== activeIndex; });
114
+ onChange(nextVal);
115
+ if (activeIndex >= nextVal.length) {
116
+ onNavigate(null);
117
+ }
118
+ }
119
+ else if (value.length > 0) {
120
+ onChange(value.filter(function (_, i) { return i !== value.length - 1; }));
121
+ }
122
+ }
123
+ }
124
+ },
125
+ },
126
+ };
127
+ }
128
+ function useKeyboardSelection(context, _a) {
129
+ var _b = _a === void 0 ? {} : _a, _c = _b.enabled, enabled = _c === void 0 ? true : _c, _d = _b.onSelect, onSelect = _d === void 0 ? function () { } : _d;
130
+ function onKeyDown(e) {
131
+ if (!enabled) {
132
+ return;
133
+ }
134
+ if (e.key === 'Enter') {
135
+ onSelect();
136
+ }
137
+ }
138
+ return {
139
+ reference: {
140
+ onKeyDown: onKeyDown,
141
+ },
142
+ floating: {
143
+ onKeyDown: onKeyDown,
144
+ },
145
+ };
146
+ }
147
+ export function useSuperSelect(_a) {
148
+ var components = _a.components, defaultValue = _a.defaultValue, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.getOptionGroup, getOptionGroup = _c === void 0 ? defaultGetOptionGroup : _c, _d = _a.getOptionIsBatch, getOptionIsBatch = _d === void 0 ? defaultGetOptionIsBatch : _d, _e = _a.getOptionIsDisabled, getOptionIsDisabled = _e === void 0 ? defaultGetOptionIsDisabled : _e, _f = _a.getOptionLabel, getOptionLabel = _f === void 0 ? defaultGetOptionLabel : _f, _g = _a.getOptionValue, getOptionValue = _g === void 0 ? defaultGetOptionValue : _g, _h = _a.multiple, multiple = _h === void 0 ? false : _h, onChange = _a.onChange, _j = _a.options, sourceOptions = _j === void 0 ? [] : _j, _k = _a.search, search = _k === void 0 ? true : _k, value_ = _a.value;
149
+ var initialValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : (multiple ? [] : null);
150
+ var _l = React.useState(initialValue), val = _l[0], setVal = _l[1];
151
+ var value = value_ !== undefined ? value_ : val;
152
+ function setValue(v) {
153
+ if (!value_) {
154
+ setVal(function () { return v; });
155
+ }
156
+ if (onChange) {
157
+ onChange(v);
158
+ }
159
+ }
160
+ var _m = React.useState(''), searchValue = _m[0], setSearchValue_ = _m[1];
161
+ var setSearchValue = debounce(setSearchValue_, 250); // TODO use React 18 useDeferredValue
162
+ var _o = React.useState(false), open = _o[0], setOpen = _o[1];
163
+ var _p = React.useState(false), pointer = _p[0], setPointer = _p[1];
164
+ var _q = React.useState(248), width = _q[0], setWidth = _q[1];
165
+ var _r = React.useState(248), maxHeight = _r[0], setMaxHeight = _r[1];
166
+ var _s = React.useState(null), activeMenuIndex = _s[0], setActiveMenuIndex = _s[1];
167
+ var _t = React.useState(null), activeTokenIndex = _t[0], setActiveTokenIndex = _t[1];
168
+ var navigationListRef = React.useRef([]);
169
+ var virtuoso = React.useRef(null);
170
+ var overlayId = useId(); // TODO use React 18 useId
171
+ var listId = useId(); // TODO use React 18 useId
172
+ var options = React.useMemo(function () {
173
+ // TODO allow user to override this behavior
174
+ function groupAndSort(opts) {
175
+ var grouped = groupBy(opts, getOptionGroup);
176
+ return Object.keys(grouped)
177
+ .sort(function (a, b) { return compareStrings(a, b); })
178
+ .map(function (group) {
179
+ var _a;
180
+ var groupOptions = grouped[group] || [];
181
+ var groupOptionsSorted = groupOptions.sort(function (a, b) {
182
+ return compareStrings(getOptionLabel(a), getOptionLabel(b));
183
+ });
184
+ var opts = group
185
+ ? [(_a = {}, _a[optgroupSymbol] = true, _a.label = group, _a.group = group, _a)]
186
+ : [];
187
+ return opts.concat(groupOptionsSorted);
188
+ })
189
+ .flat();
190
+ }
191
+ var _a = sourceOptions.reduce(function (_a, opt) {
192
+ var batched = _a[0], unbatched = _a[1];
193
+ var match = getOptionLabel(opt)
194
+ .toLowerCase()
195
+ .includes(searchValue.toLowerCase());
196
+ if (match) {
197
+ if (isMultiple(multiple, value)) {
198
+ if (getOptionIsBatch(opt)) {
199
+ var val_1 = getOptionValue(opt);
200
+ var disabled_1 = Array.isArray(val_1) && val_1.every(function (v) { return value.includes(v); });
201
+ batched.push(__assign(__assign({}, opt), { disabled: disabled_1 }));
202
+ }
203
+ else {
204
+ unbatched.push(opt);
205
+ }
206
+ }
207
+ else {
208
+ unbatched.push(opt);
209
+ }
210
+ }
211
+ return [batched, unbatched];
212
+ }, [[], []]), batchOptions = _a[0], options = _a[1];
213
+ // group and sort all the options, putting batched options at the top
214
+ return groupAndSort(batchOptions).concat(groupAndSort(options));
215
+ }, [multiple, searchValue, sourceOptions, value]);
216
+ var groupIndices = React.useMemo(function () {
217
+ return options.reduce(function (acc, opt, i) {
218
+ if (getOptionIsOptgroup(opt)) {
219
+ acc.push(i);
220
+ }
221
+ return acc;
222
+ }, []);
223
+ }, [options]);
224
+ var selectedIndex = React.useMemo(function () {
225
+ return options.findIndex(function (option) { return isSelectableOption(option) && getOptionValue(option) === value; });
226
+ }, [options, value]);
227
+ var selectedOption = React.useMemo(function () {
228
+ return options.find(function (option) { return getOptionValue(option) === value; });
229
+ }, [sourceOptions, value]);
230
+ var selectedLabel = React.useMemo(function () {
231
+ return selectedOption ? getOptionLabel(selectedOption) : '';
232
+ }, [selectedOption]);
233
+ function isSelectableOption(o) {
234
+ return !getOptionIsOptgroup(o) && !getOptionIsDisabled(o);
235
+ }
236
+ function getFirstSelectableOptionIndex() {
237
+ return options.findIndex(isSelectableOption);
238
+ }
239
+ function onSelect(option) {
240
+ if (getOptionIsDisabled(option)) {
241
+ return;
242
+ }
243
+ var optionValue = getOptionValue(option);
244
+ if (isMultiple(multiple, value)) {
245
+ if (Array.isArray(optionValue)) {
246
+ setValue(uniq(__spreadArray(__spreadArray([], value, true), optionValue, true)));
247
+ }
248
+ else {
249
+ setValue(value.includes(optionValue)
250
+ ? value.filter(function (val) { return val !== optionValue; })
251
+ : __spreadArray(__spreadArray([], value, true), [optionValue], false));
252
+ }
253
+ }
254
+ else {
255
+ setValue(optionValue);
256
+ }
257
+ }
258
+ function onKeyboardSelect() {
259
+ if (activeMenuIndex) {
260
+ var option = options[activeMenuIndex];
261
+ if (option) {
262
+ onSelect(option);
263
+ }
264
+ }
265
+ }
266
+ function isSelected(option) {
267
+ return Array.isArray(value)
268
+ ? value.includes(getOptionValue(option))
269
+ : value === getOptionValue(option);
270
+ }
271
+ function isEmpty() {
272
+ return Array.isArray(value) ? value.length === 0 : value === null;
273
+ }
274
+ var floating = useFloating({
275
+ open: open,
276
+ onOpenChange: setOpen,
277
+ whileElementsMounted: autoUpdate,
278
+ strategy: 'fixed',
279
+ middleware: [
280
+ offset(2),
281
+ flip(),
282
+ size({
283
+ apply: function (_a) {
284
+ var availableHeight = _a.availableHeight, elements = _a.elements;
285
+ setWidth(function () { return elements.reference.getBoundingClientRect().width; });
286
+ setMaxHeight(function () { return availableHeight; });
287
+ },
288
+ padding: 10,
289
+ }),
290
+ ],
291
+ });
292
+ var _u = useInteractions([
293
+ useClick(floating.context, {
294
+ enabled: !disabled,
295
+ keyboardHandlers: false,
296
+ }),
297
+ useDismiss(floating.context, {
298
+ enabled: !disabled,
299
+ }),
300
+ useListNavigation(floating.context, {
301
+ activeIndex: activeMenuIndex,
302
+ disabledIndices: groupIndices,
303
+ enabled: !disabled,
304
+ listRef: navigationListRef,
305
+ loop: true,
306
+ onNavigate: function (i) { return setActiveMenuIndex(function () { return i; }); },
307
+ selectedIndex: selectedIndex,
308
+ virtual: true,
309
+ }),
310
+ useTokenNavigation(floating.context, {
311
+ activeIndex: activeTokenIndex,
312
+ enabled: !disabled && multiple && searchValue === '',
313
+ onChange: setValue,
314
+ onNavigate: function (i) { return setActiveTokenIndex(function () { return i; }); },
315
+ value: value,
316
+ }),
317
+ useKeyboardSelection(floating.context, {
318
+ enabled: !disabled,
319
+ onSelect: onKeyboardSelect,
320
+ }),
321
+ useCustomReferenceProps(floating.context, {
322
+ listId: listId,
323
+ onChangePointer: function (p) { return setPointer(function () { return p; }); },
324
+ open: open,
325
+ overlayId: overlayId,
326
+ search: search,
327
+ }),
328
+ useCustomFloatingProps(floating.context, {
329
+ onChangePointer: function (p) { return setPointer(function () { return p; }); },
330
+ search: search,
331
+ }),
332
+ ]), getReferenceProps = _u.getReferenceProps, getFloatingProps = _u.getFloatingProps, getItemProps = _u.getItemProps;
333
+ function getMultiInputProps() {
334
+ return {
335
+ disabled: disabled,
336
+ 'aria-controls': listId,
337
+ onKeyDown: function (e) {
338
+ var _a;
339
+ if (e.key === 'Tab') {
340
+ if (open) {
341
+ e.preventDefault();
342
+ e.stopPropagation();
343
+ (_a = floating.refs.floating.current) === null || _a === void 0 ? void 0 : _a.focus();
344
+ }
345
+ }
346
+ },
347
+ onChange: function (e) {
348
+ setSearchValue(e.currentTarget.value);
349
+ setActiveTokenIndex(null);
350
+ },
351
+ style: {
352
+ opacity: activeTokenIndex === null ? 1 : 0,
353
+ },
354
+ };
355
+ }
356
+ function getTypeaheadProps() {
357
+ return {
358
+ 'aria-controls': listId,
359
+ onChange: function (value) {
360
+ setSearchValue(value);
361
+ setActiveTokenIndex(null);
362
+ },
363
+ };
364
+ }
365
+ function getTokenClearProps(index) {
366
+ return {
367
+ onClick: function (e) {
368
+ // prevent the menu from closing
369
+ e.stopPropagation();
370
+ if (isMultiple(multiple, value)) {
371
+ setValue(value.filter(function (_, i) { return i !== index; }));
372
+ }
373
+ },
374
+ };
375
+ }
376
+ function getClearProps() {
377
+ return {
378
+ onClick: function (e) {
379
+ // prevent the menu from closing
380
+ e.stopPropagation();
381
+ setValue(multiple ? [] : null);
382
+ setOpen(function () { return true; });
383
+ },
384
+ };
385
+ }
386
+ // run effect when the `open` state changes
387
+ //
388
+ // if it was closed and is now open, reset the highlighted index to be
389
+ // the first selectable option
390
+ //
391
+ // if it was open and is now closed, reset the search value
392
+ React.useEffect(function () {
393
+ if (open) {
394
+ setActiveMenuIndex(function () {
395
+ return selectedIndex >= 0 ? selectedIndex : getFirstSelectableOptionIndex();
396
+ });
397
+ }
398
+ else {
399
+ setSearchValue(function () { return ''; });
400
+ }
401
+ }, [open]);
402
+ // run the effect when user enters a serach value
403
+ //
404
+ // if the select is currently open then reset highlighted item to be the first
405
+ // selectable option
406
+ React.useEffect(function () {
407
+ if (open) {
408
+ setActiveMenuIndex(function () { return getFirstSelectableOptionIndex(); });
409
+ }
410
+ }, [searchValue]);
411
+ // when we change the value then close the overlay, but only if we have
412
+ // actually selected a value
413
+ //
414
+ // multiple mode forces the overlay to stay open
415
+ React.useEffect(function () {
416
+ if (!multiple && value !== null) {
417
+ setOpen(function () { return false; });
418
+ }
419
+ }, [value]);
420
+ // recreate the array to hold dom refs when our options change
421
+ React.useEffect(function () {
422
+ navigationListRef.current = __spreadArray([], Array(options.length).fill(null), true);
423
+ }, [options]);
424
+ // scroll virtuoso list activeMenuIndex into view when the index changes
425
+ React.useLayoutEffect(function () {
426
+ var _a;
427
+ if (activeMenuIndex !== null) {
428
+ if (!pointer) {
429
+ (_a = virtuoso.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ index: activeMenuIndex });
430
+ }
431
+ }
432
+ }, [activeMenuIndex, open]);
433
+ return {
434
+ activeMenuIndex: activeMenuIndex,
435
+ activeTokenIndex: activeTokenIndex,
436
+ components: components,
437
+ floating: floating,
438
+ getClearProps: getClearProps,
439
+ getFloatingProps: getFloatingProps,
440
+ getItemProps: getItemProps,
441
+ getMultiInputProps: getMultiInputProps,
442
+ getOptionGroup: getOptionGroup,
443
+ getOptionIsBatch: getOptionIsBatch,
444
+ getOptionIsDisabled: getOptionIsDisabled,
445
+ getOptionIsOptgroup: getOptionIsOptgroup,
446
+ getOptionLabel: getOptionLabel,
447
+ getOptionValue: getOptionValue,
448
+ getReferenceProps: getReferenceProps,
449
+ getTokenClearProps: getTokenClearProps,
450
+ getTypeaheadProps: getTypeaheadProps,
451
+ isEmpty: isEmpty,
452
+ isSelected: isSelected,
453
+ listId: listId,
454
+ maxHeight: maxHeight,
455
+ multiple: multiple,
456
+ navigationListRef: navigationListRef,
457
+ onSelect: onSelect,
458
+ open: open,
459
+ sourceOptions: sourceOptions,
460
+ options: options,
461
+ overlayId: overlayId,
462
+ searchValue: searchValue,
463
+ selectedIndex: selectedIndex,
464
+ selectedOption: selectedOption,
465
+ selectedLabel: selectedLabel,
466
+ setOpen: setOpen,
467
+ setPointer: setPointer,
468
+ setSearchValue: setSearchValue,
469
+ value: value,
470
+ virtuoso: virtuoso,
471
+ width: width,
472
+ };
473
+ }
474
+ //# sourceMappingURL=useSuperSelect.js.map