@fluentui-copilot/react-prompt-listbox 0.8.1-hotfix.1 → 0.8.1-hotfix.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +4 -4
- package/CHANGELOG.md +5 -5
- package/lib/PromptListbox.js +1 -0
- package/lib/PromptOption.js +1 -0
- package/lib/components/PromptListbox/PromptListbox.js +7 -5
- package/lib/components/PromptListbox/PromptListbox.types.js +2 -1
- package/lib/components/PromptListbox/index.js +1 -0
- package/lib/components/PromptListbox/renderPromptListbox.js +21 -17
- package/lib/components/PromptListbox/usePromptListbox.js +67 -53
- package/lib/components/PromptListbox/usePromptListboxContextValues.js +30 -22
- package/lib/components/PromptListbox/usePromptListboxStyles.styles.raw.js +25 -21
- package/lib/components/PromptOption/PromptOption.js +6 -4
- package/lib/components/PromptOption/PromptOption.types.js +2 -1
- package/lib/components/PromptOption/index.js +1 -0
- package/lib/components/PromptOption/renderPromptOption.js +6 -4
- package/lib/components/PromptOption/usePromptOption.js +84 -84
- package/lib/components/PromptOption/usePromptOptionStyles.styles.raw.js +60 -54
- package/lib/components/motion/PromptListboxMotion.js +50 -52
- package/lib/components/utils/OptionCollection.types.js +2 -1
- package/lib/components/utils/PromptListboxFunctionality.types.js +2 -1
- package/lib/components/utils/Selection.types.js +2 -1
- package/lib/components/utils/dropdownKeyActions.js +60 -49
- package/lib/components/utils/useListboxPositioning.js +24 -22
- package/lib/components/utils/useOptionCollection.js +32 -30
- package/lib/components/utils/usePromptListboxFunctionality.js +123 -121
- package/lib/components/utils/usePromptListboxFunctionalityV2.js +124 -109
- package/lib/components/utils/useSelection.js +49 -57
- package/lib/components/utils/useTriggerKeyDown.js +133 -124
- package/lib/index.js +1 -0
- package/lib/plugins/CursorPositionPlugin.js +39 -39
- package/lib-commonjs/PromptListbox.js +1 -0
- package/lib-commonjs/PromptOption.js +1 -0
- package/lib-commonjs/components/PromptListbox/PromptListbox.js +1 -1
- package/lib-commonjs/components/PromptListbox/PromptListbox.js.map +1 -1
- package/lib-commonjs/components/PromptListbox/PromptListbox.types.js +1 -0
- package/lib-commonjs/components/PromptListbox/index.js +1 -0
- package/lib-commonjs/components/PromptListbox/renderPromptListbox.js +1 -1
- package/lib-commonjs/components/PromptListbox/renderPromptListbox.js.map +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListbox.js +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListbox.js.map +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListboxContextValues.js +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListboxContextValues.js.map +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.raw.js +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/PromptOption/PromptOption.js +1 -1
- package/lib-commonjs/components/PromptOption/PromptOption.js.map +1 -1
- package/lib-commonjs/components/PromptOption/PromptOption.types.js +1 -0
- package/lib-commonjs/components/PromptOption/index.js +1 -0
- package/lib-commonjs/components/PromptOption/renderPromptOption.js +1 -1
- package/lib-commonjs/components/PromptOption/renderPromptOption.js.map +1 -1
- package/lib-commonjs/components/PromptOption/usePromptOption.js +1 -1
- package/lib-commonjs/components/PromptOption/usePromptOption.js.map +1 -1
- package/lib-commonjs/components/PromptOption/usePromptOptionStyles.styles.raw.js +1 -1
- package/lib-commonjs/components/PromptOption/usePromptOptionStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/motion/PromptListboxMotion.js +1 -1
- package/lib-commonjs/components/motion/PromptListboxMotion.js.map +1 -1
- package/lib-commonjs/components/utils/OptionCollection.types.js +1 -0
- package/lib-commonjs/components/utils/PromptListboxFunctionality.types.js +1 -0
- package/lib-commonjs/components/utils/Selection.types.js +1 -0
- package/lib-commonjs/components/utils/dropdownKeyActions.js +1 -1
- package/lib-commonjs/components/utils/dropdownKeyActions.js.map +1 -1
- package/lib-commonjs/components/utils/useListboxPositioning.js +1 -1
- package/lib-commonjs/components/utils/useListboxPositioning.js.map +1 -1
- package/lib-commonjs/components/utils/useOptionCollection.js +1 -1
- package/lib-commonjs/components/utils/useOptionCollection.js.map +1 -1
- package/lib-commonjs/components/utils/usePromptListboxFunctionality.js +1 -1
- package/lib-commonjs/components/utils/usePromptListboxFunctionality.js.map +1 -1
- package/lib-commonjs/components/utils/usePromptListboxFunctionalityV2.js +1 -1
- package/lib-commonjs/components/utils/usePromptListboxFunctionalityV2.js.map +1 -1
- package/lib-commonjs/components/utils/useSelection.js +1 -1
- package/lib-commonjs/components/utils/useSelection.js.map +1 -1
- package/lib-commonjs/components/utils/useTriggerKeyDown.js +1 -1
- package/lib-commonjs/components/utils/useTriggerKeyDown.js.map +1 -1
- package/lib-commonjs/index.js +1 -0
- package/lib-commonjs/plugins/CursorPositionPlugin.js +1 -1
- package/lib-commonjs/plugins/CursorPositionPlugin.js.map +1 -1
- package/package.json +10 -10
|
@@ -2,67 +2,73 @@ import { makeStyles, mergeClasses, shorthands } from '@fluentui/react-components
|
|
|
2
2
|
import { tokens } from '@fluentui-copilot/tokens';
|
|
3
3
|
import { ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE } from '@fluentui/react-aria';
|
|
4
4
|
export const promptOptionClassNames = {
|
|
5
|
-
|
|
5
|
+
root: 'fai-PromptOption'
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Styles for the root slot
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
':active': {
|
|
27
|
-
backgroundColor: tokens.colorNeutralBackground1Pressed,
|
|
28
|
-
color: tokens.colorNeutralForeground1Pressed
|
|
29
|
-
}
|
|
9
|
+
*/
|
|
10
|
+
const useStyles = makeStyles({
|
|
11
|
+
root: {
|
|
12
|
+
alignItems: 'center',
|
|
13
|
+
borderRadius: tokens.borderRadiusMedium,
|
|
14
|
+
color: tokens.colorNeutralForeground1,
|
|
15
|
+
columnGap: tokens.spacingHorizontalXS,
|
|
16
|
+
cursor: 'pointer',
|
|
17
|
+
display: 'flex',
|
|
18
|
+
fontFamily: tokens.fontFamilyBase,
|
|
19
|
+
fontSize: tokens.fontSizeBase300,
|
|
20
|
+
lineHeight: tokens.lineHeightBase300,
|
|
21
|
+
padding: `${tokens.spacingVerticalSNudge} ${tokens.spacingHorizontalS}`,
|
|
22
|
+
position: 'relative',
|
|
23
|
+
':hover': {
|
|
24
|
+
backgroundColor: tokens.colorNeutralBackground1Hover,
|
|
25
|
+
color: tokens.colorNeutralForeground1Hover
|
|
30
26
|
},
|
|
31
|
-
active: {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
':active': {
|
|
28
|
+
backgroundColor: tokens.colorNeutralBackground1Pressed,
|
|
29
|
+
color: tokens.colorNeutralForeground1Pressed
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
active: {
|
|
33
|
+
[`[${ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE}]::after`]: {
|
|
34
|
+
content: '""',
|
|
35
|
+
position: 'absolute',
|
|
36
|
+
pointerEvents: 'none',
|
|
37
|
+
zIndex: 1,
|
|
38
|
+
...shorthands.border(tokens.strokeWidthThick, `solid`, tokens.colorStrokeFocus2),
|
|
39
|
+
borderRadius: tokens.borderRadiusMedium,
|
|
40
|
+
top: '-2px',
|
|
41
|
+
bottom: '-2px',
|
|
42
|
+
left: '-2px',
|
|
43
|
+
right: '-2px'
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
disabled: {
|
|
47
|
+
color: tokens.colorNeutralForegroundDisabled,
|
|
48
|
+
':hover': {
|
|
49
|
+
backgroundColor: tokens.colorTransparentBackground,
|
|
50
|
+
color: tokens.colorNeutralForegroundDisabled
|
|
51
|
+
},
|
|
52
|
+
':active': {
|
|
53
|
+
backgroundColor: tokens.colorTransparentBackground,
|
|
54
|
+
color: tokens.colorNeutralForegroundDisabled
|
|
44
55
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
':hover': {
|
|
48
|
-
backgroundColor: tokens.colorTransparentBackground,
|
|
49
|
-
color: tokens.colorNeutralForegroundDisabled
|
|
50
|
-
},
|
|
51
|
-
':active': {
|
|
52
|
-
backgroundColor: tokens.colorTransparentBackground,
|
|
53
|
-
color: tokens.colorNeutralForegroundDisabled
|
|
54
|
-
},
|
|
55
|
-
'@media (forced-colors: active)': {
|
|
56
|
-
color: 'GrayText'
|
|
57
|
-
}
|
|
56
|
+
'@media (forced-colors: active)': {
|
|
57
|
+
color: 'GrayText'
|
|
58
58
|
}
|
|
59
|
+
}
|
|
59
60
|
});
|
|
60
61
|
/**
|
|
61
62
|
* Apply styling to the PromptOption slots based on the state
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
*/
|
|
64
|
+
export const usePromptOptionStyles_unstable = state => {
|
|
65
|
+
'use no memo';
|
|
66
|
+
|
|
67
|
+
const {
|
|
68
|
+
disabled
|
|
69
|
+
} = state;
|
|
70
|
+
const styles = useStyles();
|
|
71
|
+
state.root.className = mergeClasses(promptOptionClassNames.root, styles.root, styles.active, disabled && styles.disabled, state.root.className);
|
|
72
|
+
return state;
|
|
68
73
|
};
|
|
74
|
+
//# sourceMappingURL=usePromptOptionStyles.styles.raw.js.map
|
|
@@ -1,55 +1,53 @@
|
|
|
1
1
|
import { createPresenceComponent, motionTokens } from '@fluentui/react-components';
|
|
2
|
-
const collapseMotion = ({
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
keyframes: exitKeyframes
|
|
52
|
-
}
|
|
53
|
-
};
|
|
2
|
+
const collapseMotion = ({
|
|
3
|
+
element
|
|
4
|
+
}) => {
|
|
5
|
+
const fromOpacity = 0;
|
|
6
|
+
const toOpacity = 1;
|
|
7
|
+
const fromHeight = '0';
|
|
8
|
+
const toHeight = `${element.scrollHeight}px`;
|
|
9
|
+
const overflow = 'hidden';
|
|
10
|
+
const duration = motionTokens.durationNormal;
|
|
11
|
+
const easing = motionTokens.curveEasyEaseMax;
|
|
12
|
+
const enterKeyframes = [{
|
|
13
|
+
opacity: fromOpacity,
|
|
14
|
+
maxHeight: fromHeight,
|
|
15
|
+
overflow
|
|
16
|
+
},
|
|
17
|
+
// Transition to the height of the content, at 99.99% of the duration.
|
|
18
|
+
{
|
|
19
|
+
opacity: toOpacity,
|
|
20
|
+
maxHeight: toHeight,
|
|
21
|
+
offset: 0.9999,
|
|
22
|
+
overflow
|
|
23
|
+
},
|
|
24
|
+
// On completion, remove the maxHeight because the content might need to expand later.
|
|
25
|
+
{
|
|
26
|
+
opacity: toOpacity,
|
|
27
|
+
maxHeight: 'unset',
|
|
28
|
+
overflow
|
|
29
|
+
}];
|
|
30
|
+
const exitKeyframes = [{
|
|
31
|
+
opacity: toOpacity,
|
|
32
|
+
maxHeight: toHeight,
|
|
33
|
+
overflow
|
|
34
|
+
}, {
|
|
35
|
+
opacity: fromOpacity,
|
|
36
|
+
maxHeight: fromHeight,
|
|
37
|
+
overflow
|
|
38
|
+
}];
|
|
39
|
+
return {
|
|
40
|
+
enter: {
|
|
41
|
+
duration,
|
|
42
|
+
easing,
|
|
43
|
+
keyframes: enterKeyframes
|
|
44
|
+
},
|
|
45
|
+
exit: {
|
|
46
|
+
duration,
|
|
47
|
+
easing,
|
|
48
|
+
keyframes: exitKeyframes
|
|
49
|
+
}
|
|
50
|
+
};
|
|
54
51
|
};
|
|
55
52
|
export const PromptListboxMotion = createPresenceComponent(collapseMotion);
|
|
53
|
+
//# sourceMappingURL=PromptListboxMotion.js.map
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=PromptListboxFunctionality.types.js.map
|
|
@@ -1,57 +1,68 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Note, this is mainly brought from Fluent UI, only removed the closing and
|
|
3
3
|
* opening logic since that's not needed for this use case.
|
|
4
|
-
*/
|
|
4
|
+
*/import * as keys from '@fluentui/keyboard-keys';
|
|
5
5
|
/**
|
|
6
6
|
* Converts a keyboard interaction into a defined action
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
*/
|
|
8
|
+
export function getDropdownActionFromKey(e, options) {
|
|
9
|
+
const {
|
|
10
|
+
cursorPosition,
|
|
11
|
+
allowArrowUpNavigation,
|
|
12
|
+
isInSelectionMode
|
|
13
|
+
} = options;
|
|
14
|
+
const code = e.key;
|
|
15
|
+
const {
|
|
16
|
+
altKey,
|
|
17
|
+
ctrlKey,
|
|
18
|
+
key,
|
|
19
|
+
metaKey
|
|
20
|
+
} = e;
|
|
21
|
+
// typing action occurs whether open or closed
|
|
22
|
+
if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {
|
|
23
|
+
return 'Type';
|
|
24
|
+
}
|
|
25
|
+
// select or close actions
|
|
26
|
+
if (code === keys.ArrowUp && altKey || code === keys.Enter) {
|
|
27
|
+
return 'CloseSelect';
|
|
28
|
+
}
|
|
29
|
+
// navigation interactions
|
|
30
|
+
const atStart = allowArrowUpNavigation && (cursorPosition === 'start' || cursorPosition === 'start-end');
|
|
31
|
+
const atEnd = cursorPosition === 'end' || cursorPosition === 'start-end';
|
|
32
|
+
if (code === keys.ArrowDown) {
|
|
33
|
+
if (atEnd) {
|
|
34
|
+
return 'Next';
|
|
35
|
+
} else if (atStart && isInSelectionMode) {
|
|
36
|
+
return 'Next';
|
|
14
37
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
38
|
+
return 'Type';
|
|
39
|
+
}
|
|
40
|
+
if (code === keys.ArrowUp) {
|
|
41
|
+
if (atEnd && isInSelectionMode) {
|
|
42
|
+
return 'Previous';
|
|
43
|
+
} else if (atStart && !isInSelectionMode) {
|
|
44
|
+
return 'Next';
|
|
45
|
+
} else if (atStart && isInSelectionMode) {
|
|
46
|
+
return 'Previous';
|
|
18
47
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return 'Type';
|
|
39
|
-
}
|
|
40
|
-
if (code === keys.Home) {
|
|
41
|
-
return atEnd || atStart ? 'First' : 'Type';
|
|
42
|
-
}
|
|
43
|
-
if (code === keys.End) {
|
|
44
|
-
return atEnd || atStart ? 'Last' : 'Type';
|
|
45
|
-
}
|
|
46
|
-
if (code === keys.PageUp) {
|
|
47
|
-
return 'PageUp';
|
|
48
|
-
}
|
|
49
|
-
if (code === keys.PageDown) {
|
|
50
|
-
return 'PageDown';
|
|
51
|
-
}
|
|
52
|
-
if (code === keys.Tab) {
|
|
53
|
-
return 'Tab';
|
|
54
|
-
}
|
|
55
|
-
// if nothing matched, return none
|
|
56
|
-
return 'None';
|
|
48
|
+
return 'Type';
|
|
49
|
+
}
|
|
50
|
+
if (code === keys.Home) {
|
|
51
|
+
return atEnd || atStart ? 'First' : 'Type';
|
|
52
|
+
}
|
|
53
|
+
if (code === keys.End) {
|
|
54
|
+
return atEnd || atStart ? 'Last' : 'Type';
|
|
55
|
+
}
|
|
56
|
+
if (code === keys.PageUp) {
|
|
57
|
+
return 'PageUp';
|
|
58
|
+
}
|
|
59
|
+
if (code === keys.PageDown) {
|
|
60
|
+
return 'PageDown';
|
|
61
|
+
}
|
|
62
|
+
if (code === keys.Tab) {
|
|
63
|
+
return 'Tab';
|
|
64
|
+
}
|
|
65
|
+
// if nothing matched, return none
|
|
66
|
+
return 'None';
|
|
57
67
|
}
|
|
68
|
+
//# sourceMappingURL=dropdownKeyActions.js.map
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
// Brought from Fluent UI
|
|
2
2
|
import { resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';
|
|
3
3
|
export function useListboxPositioning(props) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
const {
|
|
5
|
+
positioning,
|
|
6
|
+
fluid
|
|
7
|
+
} = props;
|
|
8
|
+
const fallbackPositions = ['below'];
|
|
9
|
+
// popper options
|
|
10
|
+
const popperOptions = {
|
|
11
|
+
position: 'below',
|
|
12
|
+
align: 'start',
|
|
13
|
+
offset: {
|
|
14
|
+
crossAxis: 0,
|
|
15
|
+
mainAxis: 2
|
|
16
|
+
},
|
|
17
|
+
fallbackPositions: fallbackPositions,
|
|
18
|
+
matchTargetSize: fluid ? 'width' : undefined,
|
|
19
|
+
autoSize: true,
|
|
20
|
+
...resolvePositioningShorthand(positioning)
|
|
21
|
+
};
|
|
22
|
+
const {
|
|
23
|
+
containerRef: listboxRef,
|
|
24
|
+
targetRef: anchorRef
|
|
25
|
+
} = usePositioning(popperOptions);
|
|
26
|
+
return [listboxRef, anchorRef];
|
|
26
27
|
}
|
|
28
|
+
//# sourceMappingURL=useListboxPositioning.js.map
|
|
@@ -2,36 +2,38 @@
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
/**
|
|
4
4
|
* A hook for managing a collection of child Options
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
getCount,
|
|
24
|
-
getOptionById,
|
|
25
|
-
getOptionsMatchingValue
|
|
26
|
-
};
|
|
27
|
-
}, []);
|
|
28
|
-
const registerOption = React.useCallback((option)=>{
|
|
29
|
-
optionsById.current.set(option.id, option);
|
|
30
|
-
return ()=>optionsById.current.delete(option.id);
|
|
31
|
-
}, []);
|
|
5
|
+
*/
|
|
6
|
+
export const useOptionCollection = () => {
|
|
7
|
+
const optionsById = React.useRef(new Map());
|
|
8
|
+
const collectionAPI = React.useMemo(() => {
|
|
9
|
+
const getCount = () => optionsById.current.size;
|
|
10
|
+
// index searches are no longer used
|
|
11
|
+
const getOptionById = id => {
|
|
12
|
+
return optionsById.current.get(id);
|
|
13
|
+
};
|
|
14
|
+
const getOptionsMatchingValue = matcher => {
|
|
15
|
+
const matches = [];
|
|
16
|
+
for (const option of optionsById.current.values()) {
|
|
17
|
+
if (matcher(option.value)) {
|
|
18
|
+
matches.push(option);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return matches;
|
|
22
|
+
};
|
|
32
23
|
return {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
getCount,
|
|
25
|
+
getOptionById,
|
|
26
|
+
getOptionsMatchingValue
|
|
36
27
|
};
|
|
28
|
+
}, []);
|
|
29
|
+
const registerOption = React.useCallback(option => {
|
|
30
|
+
optionsById.current.set(option.id, option);
|
|
31
|
+
return () => optionsById.current.delete(option.id);
|
|
32
|
+
}, []);
|
|
33
|
+
return {
|
|
34
|
+
...collectionAPI,
|
|
35
|
+
options: Array.from(optionsById.current.values()),
|
|
36
|
+
registerOption
|
|
37
|
+
};
|
|
37
38
|
};
|
|
39
|
+
//# sourceMappingURL=useOptionCollection.js.map
|