@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.
Files changed (77) hide show
  1. package/CHANGELOG.json +4 -4
  2. package/CHANGELOG.md +5 -5
  3. package/lib/PromptListbox.js +1 -0
  4. package/lib/PromptOption.js +1 -0
  5. package/lib/components/PromptListbox/PromptListbox.js +7 -5
  6. package/lib/components/PromptListbox/PromptListbox.types.js +2 -1
  7. package/lib/components/PromptListbox/index.js +1 -0
  8. package/lib/components/PromptListbox/renderPromptListbox.js +21 -17
  9. package/lib/components/PromptListbox/usePromptListbox.js +67 -53
  10. package/lib/components/PromptListbox/usePromptListboxContextValues.js +30 -22
  11. package/lib/components/PromptListbox/usePromptListboxStyles.styles.raw.js +25 -21
  12. package/lib/components/PromptOption/PromptOption.js +6 -4
  13. package/lib/components/PromptOption/PromptOption.types.js +2 -1
  14. package/lib/components/PromptOption/index.js +1 -0
  15. package/lib/components/PromptOption/renderPromptOption.js +6 -4
  16. package/lib/components/PromptOption/usePromptOption.js +84 -84
  17. package/lib/components/PromptOption/usePromptOptionStyles.styles.raw.js +60 -54
  18. package/lib/components/motion/PromptListboxMotion.js +50 -52
  19. package/lib/components/utils/OptionCollection.types.js +2 -1
  20. package/lib/components/utils/PromptListboxFunctionality.types.js +2 -1
  21. package/lib/components/utils/Selection.types.js +2 -1
  22. package/lib/components/utils/dropdownKeyActions.js +60 -49
  23. package/lib/components/utils/useListboxPositioning.js +24 -22
  24. package/lib/components/utils/useOptionCollection.js +32 -30
  25. package/lib/components/utils/usePromptListboxFunctionality.js +123 -121
  26. package/lib/components/utils/usePromptListboxFunctionalityV2.js +124 -109
  27. package/lib/components/utils/useSelection.js +49 -57
  28. package/lib/components/utils/useTriggerKeyDown.js +133 -124
  29. package/lib/index.js +1 -0
  30. package/lib/plugins/CursorPositionPlugin.js +39 -39
  31. package/lib-commonjs/PromptListbox.js +1 -0
  32. package/lib-commonjs/PromptOption.js +1 -0
  33. package/lib-commonjs/components/PromptListbox/PromptListbox.js +1 -1
  34. package/lib-commonjs/components/PromptListbox/PromptListbox.js.map +1 -1
  35. package/lib-commonjs/components/PromptListbox/PromptListbox.types.js +1 -0
  36. package/lib-commonjs/components/PromptListbox/index.js +1 -0
  37. package/lib-commonjs/components/PromptListbox/renderPromptListbox.js +1 -1
  38. package/lib-commonjs/components/PromptListbox/renderPromptListbox.js.map +1 -1
  39. package/lib-commonjs/components/PromptListbox/usePromptListbox.js +1 -1
  40. package/lib-commonjs/components/PromptListbox/usePromptListbox.js.map +1 -1
  41. package/lib-commonjs/components/PromptListbox/usePromptListboxContextValues.js +1 -1
  42. package/lib-commonjs/components/PromptListbox/usePromptListboxContextValues.js.map +1 -1
  43. package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.raw.js +1 -1
  44. package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.raw.js.map +1 -1
  45. package/lib-commonjs/components/PromptOption/PromptOption.js +1 -1
  46. package/lib-commonjs/components/PromptOption/PromptOption.js.map +1 -1
  47. package/lib-commonjs/components/PromptOption/PromptOption.types.js +1 -0
  48. package/lib-commonjs/components/PromptOption/index.js +1 -0
  49. package/lib-commonjs/components/PromptOption/renderPromptOption.js +1 -1
  50. package/lib-commonjs/components/PromptOption/renderPromptOption.js.map +1 -1
  51. package/lib-commonjs/components/PromptOption/usePromptOption.js +1 -1
  52. package/lib-commonjs/components/PromptOption/usePromptOption.js.map +1 -1
  53. package/lib-commonjs/components/PromptOption/usePromptOptionStyles.styles.raw.js +1 -1
  54. package/lib-commonjs/components/PromptOption/usePromptOptionStyles.styles.raw.js.map +1 -1
  55. package/lib-commonjs/components/motion/PromptListboxMotion.js +1 -1
  56. package/lib-commonjs/components/motion/PromptListboxMotion.js.map +1 -1
  57. package/lib-commonjs/components/utils/OptionCollection.types.js +1 -0
  58. package/lib-commonjs/components/utils/PromptListboxFunctionality.types.js +1 -0
  59. package/lib-commonjs/components/utils/Selection.types.js +1 -0
  60. package/lib-commonjs/components/utils/dropdownKeyActions.js +1 -1
  61. package/lib-commonjs/components/utils/dropdownKeyActions.js.map +1 -1
  62. package/lib-commonjs/components/utils/useListboxPositioning.js +1 -1
  63. package/lib-commonjs/components/utils/useListboxPositioning.js.map +1 -1
  64. package/lib-commonjs/components/utils/useOptionCollection.js +1 -1
  65. package/lib-commonjs/components/utils/useOptionCollection.js.map +1 -1
  66. package/lib-commonjs/components/utils/usePromptListboxFunctionality.js +1 -1
  67. package/lib-commonjs/components/utils/usePromptListboxFunctionality.js.map +1 -1
  68. package/lib-commonjs/components/utils/usePromptListboxFunctionalityV2.js +1 -1
  69. package/lib-commonjs/components/utils/usePromptListboxFunctionalityV2.js.map +1 -1
  70. package/lib-commonjs/components/utils/useSelection.js +1 -1
  71. package/lib-commonjs/components/utils/useSelection.js.map +1 -1
  72. package/lib-commonjs/components/utils/useTriggerKeyDown.js +1 -1
  73. package/lib-commonjs/components/utils/useTriggerKeyDown.js.map +1 -1
  74. package/lib-commonjs/index.js +1 -0
  75. package/lib-commonjs/plugins/CursorPositionPlugin.js +1 -1
  76. package/lib-commonjs/plugins/CursorPositionPlugin.js.map +1 -1
  77. 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
- root: 'fai-PromptOption'
5
+ root: 'fai-PromptOption'
6
6
  };
7
7
  /**
8
8
  * Styles for the root slot
9
- */ const useStyles = makeStyles({
10
- root: {
11
- alignItems: 'center',
12
- borderRadius: tokens.borderRadiusMedium,
13
- color: tokens.colorNeutralForeground1,
14
- columnGap: tokens.spacingHorizontalXS,
15
- cursor: 'pointer',
16
- display: 'flex',
17
- fontFamily: tokens.fontFamilyBase,
18
- fontSize: tokens.fontSizeBase300,
19
- lineHeight: tokens.lineHeightBase300,
20
- padding: `${tokens.spacingVerticalSNudge} ${tokens.spacingHorizontalS}`,
21
- position: 'relative',
22
- ':hover': {
23
- backgroundColor: tokens.colorNeutralBackground1Hover,
24
- color: tokens.colorNeutralForeground1Hover
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
- [`[${ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE}]::after`]: {
33
- content: '""',
34
- position: 'absolute',
35
- pointerEvents: 'none',
36
- zIndex: 1,
37
- ...shorthands.border(tokens.strokeWidthThick, `solid`, tokens.colorStrokeFocus2),
38
- borderRadius: tokens.borderRadiusMedium,
39
- top: '-2px',
40
- bottom: '-2px',
41
- left: '-2px',
42
- right: '-2px'
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
- disabled: {
46
- color: tokens.colorNeutralForegroundDisabled,
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
- */ export const usePromptOptionStyles_unstable = (state)=>{
63
- 'use no memo';
64
- const { disabled } = state;
65
- const styles = useStyles();
66
- state.root.className = mergeClasses(promptOptionClassNames.root, styles.root, styles.active, disabled && styles.disabled, state.root.className);
67
- return state;
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 = ({ element })=>{
3
- const fromOpacity = 0;
4
- const toOpacity = 1;
5
- const fromHeight = '0';
6
- const toHeight = `${element.scrollHeight}px`;
7
- const overflow = 'hidden';
8
- const duration = motionTokens.durationNormal;
9
- const easing = motionTokens.curveEasyEaseMax;
10
- const enterKeyframes = [
11
- {
12
- opacity: fromOpacity,
13
- maxHeight: fromHeight,
14
- overflow
15
- },
16
- // Transition to the height of the content, at 99.99% of the duration.
17
- {
18
- opacity: toOpacity,
19
- maxHeight: toHeight,
20
- offset: 0.9999,
21
- overflow
22
- },
23
- // On completion, remove the maxHeight because the content might need to expand later.
24
- {
25
- opacity: toOpacity,
26
- maxHeight: 'unset',
27
- overflow
28
- }
29
- ];
30
- const exitKeyframes = [
31
- {
32
- opacity: toOpacity,
33
- maxHeight: toHeight,
34
- overflow
35
- },
36
- {
37
- opacity: fromOpacity,
38
- maxHeight: fromHeight,
39
- overflow
40
- }
41
- ];
42
- return {
43
- enter: {
44
- duration,
45
- easing,
46
- keyframes: enterKeyframes
47
- },
48
- exit: {
49
- duration,
50
- easing,
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,2 +1,3 @@
1
1
  // Brought from Fluent UI
2
- export { };
2
+ export {};
3
+ //# sourceMappingURL=OptionCollection.types.js.map
@@ -1 +1,2 @@
1
- export { };
1
+ export {};
2
+ //# sourceMappingURL=PromptListboxFunctionality.types.js.map
@@ -1,2 +1,3 @@
1
1
  // Brought from Fluent UI
2
- /** Possible event types for onOptionSelect */ export { };
2
+ /** Possible event types for onOptionSelect */export {};
3
+ //# sourceMappingURL=Selection.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
- */ import * as keys from '@fluentui/keyboard-keys';
4
+ */import * as keys from '@fluentui/keyboard-keys';
5
5
  /**
6
6
  * Converts a keyboard interaction into a defined action
7
- */ export function getDropdownActionFromKey(e, options) {
8
- const { cursorPosition, allowArrowUpNavigation, isInSelectionMode } = options;
9
- const code = e.key;
10
- const { altKey, ctrlKey, key, metaKey } = e;
11
- // typing action occurs whether open or closed
12
- if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {
13
- return 'Type';
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
- // select or close actions
16
- if (code === keys.ArrowUp && altKey || code === keys.Enter) {
17
- return 'CloseSelect';
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
- // navigation interactions
20
- const atStart = allowArrowUpNavigation && (cursorPosition === 'start' || cursorPosition === 'start-end');
21
- const atEnd = cursorPosition === 'end' || cursorPosition === 'start-end';
22
- if (code === keys.ArrowDown) {
23
- if (atEnd) {
24
- return 'Next';
25
- } else if (atStart && isInSelectionMode) {
26
- return 'Next';
27
- }
28
- return 'Type';
29
- }
30
- if (code === keys.ArrowUp) {
31
- if (atEnd && isInSelectionMode) {
32
- return 'Previous';
33
- } else if (atStart && !isInSelectionMode) {
34
- return 'Next';
35
- } else if (atStart && isInSelectionMode) {
36
- return 'Previous';
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
- const { positioning, fluid } = props;
5
- const fallbackPositions = [
6
- 'below'
7
- ];
8
- // popper options
9
- const popperOptions = {
10
- position: 'below',
11
- align: 'start',
12
- offset: {
13
- crossAxis: 0,
14
- mainAxis: 2
15
- },
16
- fallbackPositions: fallbackPositions,
17
- matchTargetSize: fluid ? 'width' : undefined,
18
- autoSize: true,
19
- ...resolvePositioningShorthand(positioning)
20
- };
21
- const { containerRef: listboxRef, targetRef: anchorRef } = usePositioning(popperOptions);
22
- return [
23
- listboxRef,
24
- anchorRef
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
- */ export const useOptionCollection = ()=>{
6
- const optionsById = React.useRef(new Map());
7
- const collectionAPI = React.useMemo(()=>{
8
- const getCount = ()=>optionsById.current.size;
9
- // index searches are no longer used
10
- const getOptionById = (id)=>{
11
- return optionsById.current.get(id);
12
- };
13
- const getOptionsMatchingValue = (matcher)=>{
14
- const matches = [];
15
- for (const option of optionsById.current.values()){
16
- if (matcher(option.value)) {
17
- matches.push(option);
18
- }
19
- }
20
- return matches;
21
- };
22
- return {
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
- ...collectionAPI,
34
- options: Array.from(optionsById.current.values()),
35
- registerOption
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