@fluentui-copilot/react-prompt-listbox 0.0.4 → 0.2.0

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 (48) hide show
  1. package/CHANGELOG.json +95 -1
  2. package/CHANGELOG.md +30 -1
  3. package/dist/index.d.ts +18 -63
  4. package/lib/components/PromptListbox/usePromptListboxStyles.styles.js +9 -6
  5. package/lib/components/PromptListbox/usePromptListboxStyles.styles.js.map +1 -1
  6. package/lib/components/PromptOption/usePromptOption.js +0 -5
  7. package/lib/components/PromptOption/usePromptOption.js.map +1 -1
  8. package/lib/components/PromptOption/usePromptOptionStyles.styles.js +22 -13
  9. package/lib/components/PromptOption/usePromptOptionStyles.styles.js.map +1 -1
  10. package/lib/components/utils/PromptListboxFunctionality.types.js.map +1 -1
  11. package/lib/components/utils/dropdownKeyActions.js +21 -5
  12. package/lib/components/utils/dropdownKeyActions.js.map +1 -1
  13. package/lib/components/utils/{useComboboxPositioning.js → useListboxPositioning.js} +3 -2
  14. package/lib/components/utils/useListboxPositioning.js.map +1 -0
  15. package/lib/components/utils/usePromptListboxFunctionality.js +28 -36
  16. package/lib/components/utils/usePromptListboxFunctionality.js.map +1 -1
  17. package/lib/components/utils/useTriggerKeyDown.js +31 -11
  18. package/lib/components/utils/useTriggerKeyDown.js.map +1 -1
  19. package/lib/index.js +0 -1
  20. package/lib/index.js.map +1 -1
  21. package/lib/plugins/CursorPositionPlugin.js +43 -0
  22. package/lib/plugins/CursorPositionPlugin.js.map +1 -0
  23. package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.js +11 -20
  24. package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.js.map +1 -1
  25. package/lib-commonjs/components/PromptOption/usePromptOption.js +0 -3
  26. package/lib-commonjs/components/PromptOption/usePromptOption.js.map +1 -1
  27. package/lib-commonjs/components/PromptOption/usePromptOptionStyles.styles.js +33 -54
  28. package/lib-commonjs/components/PromptOption/usePromptOptionStyles.styles.js.map +1 -1
  29. package/lib-commonjs/components/utils/PromptListboxFunctionality.types.js.map +1 -1
  30. package/lib-commonjs/components/utils/dropdownKeyActions.js +19 -5
  31. package/lib-commonjs/components/utils/dropdownKeyActions.js.map +1 -1
  32. package/lib-commonjs/components/utils/{useComboboxPositioning.js → useListboxPositioning.js} +5 -4
  33. package/lib-commonjs/components/utils/useListboxPositioning.js.map +1 -0
  34. package/lib-commonjs/components/utils/usePromptListboxFunctionality.js +30 -34
  35. package/lib-commonjs/components/utils/usePromptListboxFunctionality.js.map +1 -1
  36. package/lib-commonjs/components/utils/useTriggerKeyDown.js +27 -10
  37. package/lib-commonjs/components/utils/useTriggerKeyDown.js.map +1 -1
  38. package/lib-commonjs/index.js +0 -4
  39. package/lib-commonjs/index.js.map +1 -1
  40. package/lib-commonjs/plugins/CursorPositionPlugin.js +54 -0
  41. package/lib-commonjs/plugins/CursorPositionPlugin.js.map +1 -0
  42. package/package.json +17 -18
  43. package/lib/components/utils/useComboboxPositioning.js.map +0 -1
  44. package/lib/plugins/TextCursorPositionPlugin.js +0 -44
  45. package/lib/plugins/TextCursorPositionPlugin.js.map +0 -1
  46. package/lib-commonjs/components/utils/useComboboxPositioning.js.map +0 -1
  47. package/lib-commonjs/plugins/TextCursorPositionPlugin.js +0 -52
  48. package/lib-commonjs/plugins/TextCursorPositionPlugin.js.map +0 -1
@@ -1,12 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import { useActiveDescendant } from '@fluentui/react-aria';
3
- import { mergeCallbacks, useControllableState, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
4
- import { getDropdownActionFromKey } from './dropdownKeyActions';
5
- import { TextCursorPositionPlugin } from '../../plugins/TextCursorPositionPlugin';
3
+ import { useControllableState, useMergedRefs } from '@fluentui/react-utilities';
4
+ import { CursorPositionPlugin } from '../../plugins/CursorPositionPlugin';
6
5
  import { useOptionCollection } from './useOptionCollection';
7
6
  import { useSelection } from './useSelection';
8
- import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp } from '@fluentui/keyboard-keys';
9
- import { useComboboxPositioning } from './useComboboxPositioning';
7
+ import { useListboxPositioning } from './useListboxPositioning';
10
8
  import { useTriggerKeydown } from './useTriggerKeyDown';
11
9
  import { PromptListbox } from '../PromptListbox';
12
10
  import { promptOptionClassNames } from '../PromptOption';
@@ -16,7 +14,8 @@ export function usePromptListboxFunctionality(params) {
16
14
  onOpenChange,
17
15
  onSelectionModeChange,
18
16
  listboxProps,
19
- fluid = false
17
+ fluid = false,
18
+ allowArrowUpNavigation = false
20
19
  } = params;
21
20
  const {
22
21
  listboxRef: activeDescendantListboxRef,
@@ -35,13 +34,23 @@ export function usePromptListboxFunctionality(params) {
35
34
  const {
36
35
  getOptionById
37
36
  } = optionCollection;
38
- const [isInLastPosition, setIsInLastPosition] = React.useState(true);
37
+ const [cursorPosition, setCursorPosition] = React.useState('end');
39
38
  const [isInSelectionMode, setIsInSelectionMode] = React.useState(false);
40
39
  const [open, setOpen] = useControllableState({
41
40
  state: params.open,
42
41
  defaultState: params.defaultOpen,
43
42
  initialState: false
44
43
  });
44
+ const setSelectionMode = React.useCallback(selectionMode => {
45
+ if (selectionMode === false) {
46
+ activeDescendantController.blur();
47
+ setHideActiveDescendant(true);
48
+ } else {
49
+ setHideActiveDescendant(false);
50
+ }
51
+ setIsInSelectionMode(selectionMode);
52
+ onSelectionModeChange === null || onSelectionModeChange === void 0 ? void 0 : onSelectionModeChange(selectionMode);
53
+ }, [activeDescendantController, onSelectionModeChange]);
45
54
  const onBlur = event => {
46
55
  setOpen(false);
47
56
  onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
@@ -49,6 +58,7 @@ export function usePromptListboxFunctionality(params) {
49
58
  type: 'focus',
50
59
  open: false
51
60
  });
61
+ setSelectionMode(false);
52
62
  };
53
63
  const onFocus = event => {
54
64
  if (event.target === event.currentTarget) {
@@ -60,49 +70,31 @@ export function usePromptListboxFunctionality(params) {
60
70
  });
61
71
  }
62
72
  };
63
- const cursorPositionPlugin = /*#__PURE__*/React.createElement(TextCursorPositionPlugin, {
64
- setIsInLastPosition: setIsInLastPosition
73
+ const cursorPositionPlugin = /*#__PURE__*/React.createElement(CursorPositionPlugin, {
74
+ setCursorPosition: setCursorPosition
65
75
  });
66
76
  const onListboxBlur = React.useCallback(() => {
67
- setIsInSelectionMode(false);
77
+ setSelectionMode(false);
68
78
  onSelectionModeChange === null || onSelectionModeChange === void 0 ? void 0 : onSelectionModeChange(false);
69
- }, [onSelectionModeChange]);
79
+ }, [onSelectionModeChange, setSelectionMode]);
70
80
  // handle combobox keyboard interaction
71
81
  const onKeyDown = useTriggerKeydown({
72
82
  ...optionCollection,
83
+ allowArrowUpNavigation,
73
84
  activeDescendantController,
74
85
  getOptionById,
75
86
  onBlur: onListboxBlur,
76
87
  selectOption,
77
- isInLastPosition,
88
+ cursorPosition,
78
89
  open,
79
- multiselect: false
90
+ multiselect: false,
91
+ isInSelectionMode,
92
+ setSelectionMode
80
93
  });
81
94
  // NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set
82
95
  // To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows
83
96
  // ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888
84
97
  const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);
85
- /**
86
- * Freeform combobox should not select
87
- */
88
- const onInputTriggerKeyDown = useEventCallback(event => {
89
- // update typing state to true if the user is typing
90
- const action = getDropdownActionFromKey(event, {
91
- open,
92
- multiselect: false,
93
- isInLastPosition
94
- });
95
- if (event.key === ArrowLeft || event.key === ArrowRight || !isInLastPosition && (event.key === ArrowDown || event.key === ArrowUp) || action === 'Type' && isInLastPosition || action === 'Type') {
96
- activeDescendantController.blur();
97
- setHideActiveDescendant(true);
98
- setIsInSelectionMode(false);
99
- onSelectionModeChange === null || onSelectionModeChange === void 0 ? void 0 : onSelectionModeChange(false);
100
- } else if (action === 'Next' || action === 'Previous' || action === 'First' || action === 'Last' || action === 'PageUp' || action === 'PageDown') {
101
- setHideActiveDescendant(false);
102
- setIsInSelectionMode(true);
103
- onSelectionModeChange === null || onSelectionModeChange === void 0 ? void 0 : onSelectionModeChange(true);
104
- }
105
- });
106
98
  React.useEffect(() => {
107
99
  if (hideActiveDescendant) {
108
100
  var _triggerRef_current;
@@ -114,7 +106,7 @@ export function usePromptListboxFunctionality(params) {
114
106
  // eslint-disable-next-line react-compiler/react-compiler
115
107
  // eslint-disable-next-line react-hooks/exhaustive-deps
116
108
  }, [hideActiveDescendant]);
117
- const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning({
109
+ const [comboboxPopupRef, comboboxTargetRef] = useListboxPositioning({
118
110
  positioning,
119
111
  fluid
120
112
  });
@@ -135,7 +127,7 @@ export function usePromptListboxFunctionality(params) {
135
127
  ref: triggerRef,
136
128
  onBlur,
137
129
  onFocus,
138
- onKeyDown: useEventCallback(mergeCallbacks(onKeyDown, onInputTriggerKeyDown)),
130
+ onKeyDown,
139
131
  isInSelectionMode
140
132
  },
141
133
  containerRef: comboboxTargetRef,
@@ -1 +1 @@
1
- {"version":3,"sources":["usePromptListboxFunctionality.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useActiveDescendant } from '@fluentui/react-aria';\nimport { mergeCallbacks, useControllableState, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from './dropdownKeyActions';\nimport { TextCursorPositionPlugin } from '../../plugins/TextCursorPositionPlugin';\nimport { useOptionCollection } from './useOptionCollection';\nimport { useSelection } from './useSelection';\nimport { ArrowDown, ArrowLeft, ArrowRight, ArrowUp } from '@fluentui/keyboard-keys';\nimport { useComboboxPositioning } from './useComboboxPositioning';\nimport { useTriggerKeydown } from './useTriggerKeyDown';\nimport { PromptListbox } from '../PromptListbox';\nimport { promptOptionClassNames } from '../PromptOption';\nimport type { EditorInputProps } from '@fluentui-copilot/react-editor-input';\nimport type {\n UsePromptListboxFunctionalityParams,\n UsePromptListboxFunctionality,\n} from './PromptListboxFunctionality.types';\n\nexport function usePromptListboxFunctionality(\n params: UsePromptListboxFunctionalityParams,\n): UsePromptListboxFunctionality {\n const { positioning, onOpenChange, onSelectionModeChange, listboxProps, fluid = false } = params;\n const {\n listboxRef: activeDescendantListboxRef,\n activeParentRef,\n controller: activeDescendantController,\n } = useActiveDescendant<HTMLSpanElement, HTMLDivElement>({\n matchOption: el => el.classList.contains(promptOptionClassNames.root),\n });\n // useMergedRefs to normalize the ref into a React.RefObject type\n const triggerRef = useMergedRefs(activeParentRef);\n const selectionState = useSelection(listboxProps ?? {});\n const { selectOption } = selectionState;\n const optionCollection = useOptionCollection();\n const { getOptionById } = optionCollection;\n const [isInLastPosition, setIsInLastPosition] = React.useState(true);\n const [isInSelectionMode, setIsInSelectionMode] = React.useState(false);\n const [open, setOpen] = useControllableState({\n state: params.open,\n defaultState: params.defaultOpen,\n initialState: false,\n });\n\n const onBlur = (event: React.FocusEvent<HTMLSpanElement>) => {\n setOpen(false);\n onOpenChange?.(event, { event, type: 'focus', open: false });\n };\n\n const onFocus = (event: React.FocusEvent<HTMLSpanElement>) => {\n if (event.target === event.currentTarget) {\n setOpen(true);\n onOpenChange?.(event, { event, type: 'focus', open: true });\n }\n };\n\n const cursorPositionPlugin = <TextCursorPositionPlugin setIsInLastPosition={setIsInLastPosition} />;\n\n const onListboxBlur = React.useCallback(() => {\n setIsInSelectionMode(false);\n onSelectionModeChange?.(false);\n }, [onSelectionModeChange]);\n\n // handle combobox keyboard interaction\n const onKeyDown = useTriggerKeydown({\n ...optionCollection,\n activeDescendantController,\n getOptionById,\n onBlur: onListboxBlur,\n selectOption,\n isInLastPosition,\n open,\n multiselect: false,\n });\n\n // NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set\n // To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows\n // ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888\n const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);\n\n /**\n * Freeform combobox should not select\n */\n const onInputTriggerKeyDown: EditorInputProps['onKeyDown'] = useEventCallback(event => {\n // update typing state to true if the user is typing\n const action = getDropdownActionFromKey(event, { open, multiselect: false, isInLastPosition });\n if (\n event.key === ArrowLeft ||\n event.key === ArrowRight ||\n (!isInLastPosition && (event.key === ArrowDown || event.key === ArrowUp)) ||\n (action === 'Type' && isInLastPosition) ||\n action === 'Type'\n ) {\n activeDescendantController.blur();\n setHideActiveDescendant(true);\n setIsInSelectionMode(false);\n onSelectionModeChange?.(false);\n } else if (\n action === 'Next' ||\n action === 'Previous' ||\n action === 'First' ||\n action === 'Last' ||\n action === 'PageUp' ||\n action === 'PageDown'\n ) {\n setHideActiveDescendant(false);\n setIsInSelectionMode(true);\n onSelectionModeChange?.(true);\n }\n });\n\n React.useEffect(() => {\n if (hideActiveDescendant) {\n triggerRef.current?.removeAttribute('aria-activedescendant');\n }\n // We only want to run this when the hideActiveDescendant changes, if the triggerRef\n // is undefined, there's no need to remove theAttribute and we shouldn't be adding\n // refs as dependencies since it can blow up the number of runs.\n // eslint-disable-next-line react-compiler/react-compiler\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [hideActiveDescendant]);\n\n const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning({ positioning, fluid });\n\n const listboxMergedRef = useMergedRefs(comboboxPopupRef, activeDescendantListboxRef, listboxProps?.ref);\n const listbox = React.useMemo(() => {\n return (\n <PromptListbox\n open={open}\n {...listboxProps}\n {...optionCollection}\n {...selectionState}\n ref={listboxMergedRef}\n activeDescendantController={activeDescendantController}\n />\n );\n }, [activeDescendantController, listboxMergedRef, listboxProps, open, optionCollection, selectionState]);\n\n return {\n promptListbox: listbox,\n triggerProps: {\n ref: triggerRef,\n onBlur,\n onFocus,\n onKeyDown: useEventCallback(mergeCallbacks(onKeyDown, onInputTriggerKeyDown)),\n isInSelectionMode,\n },\n containerRef: comboboxTargetRef,\n cursorPositionPlugin,\n };\n}\n"],"names":["React","useActiveDescendant","mergeCallbacks","useControllableState","useEventCallback","useMergedRefs","getDropdownActionFromKey","TextCursorPositionPlugin","useOptionCollection","useSelection","ArrowDown","ArrowLeft","ArrowRight","ArrowUp","useComboboxPositioning","useTriggerKeydown","PromptListbox","promptOptionClassNames","usePromptListboxFunctionality","params","positioning","onOpenChange","onSelectionModeChange","listboxProps","fluid","listboxRef","activeDescendantListboxRef","activeParentRef","controller","activeDescendantController","matchOption","el","classList","contains","root","triggerRef","selectionState","selectOption","optionCollection","getOptionById","isInLastPosition","setIsInLastPosition","useState","isInSelectionMode","setIsInSelectionMode","open","setOpen","state","defaultState","defaultOpen","initialState","onBlur","event","type","onFocus","target","currentTarget","cursorPositionPlugin","onListboxBlur","useCallback","onKeyDown","multiselect","hideActiveDescendant","setHideActiveDescendant","onInputTriggerKeyDown","action","key","blur","useEffect","current","removeAttribute","comboboxPopupRef","comboboxTargetRef","listboxMergedRef","ref","listbox","useMemo","promptListbox","triggerProps","containerRef"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,cAAc,EAAEC,oBAAoB,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAClH,SAASC,wBAAwB,QAAQ,uBAAuB;AAChE,SAASC,wBAAwB,QAAQ,yCAAyC;AAClF,SAASC,mBAAmB,QAAQ,wBAAwB;AAC5D,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,SAAS,EAAEC,SAAS,EAAEC,UAAU,EAAEC,OAAO,QAAQ,0BAA0B;AACpF,SAASC,sBAAsB,QAAQ,2BAA2B;AAClE,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,aAAa,QAA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M;IAE1F,MAAMiD,mBAAmBpE,cAAckE,kBAAkB7C,4BAA4BH,yBAAAA,mCAAAA,aAAcmD,GAAG;IACtG,MAAMC,UAAU3E,MAAM4E,OAAO,CAAC;QAC5B,qBACE,oBAAC5D;YACC6B,MAAMA;YACL,GAAGtB,YAAY;YACf,GAAGe,gBAAgB;YACnB,GAAGF,cAAc;YAClBsC,KAAKD;YACL5C,4BAA4BA;;IAGlC,GAAG;QAACA;QAA4B4C;QAAkBlD;QAAcsB;QAAMP;QAAkBF;KAAe;IAEvG,OAAO;QACLyC,eAAeF;QACfG,cAAc;YACZJ,KAAKvC;YACLgB;YACAG;YACAM,WAAWxD,iBAAiBF,eAAe0D,WAAWI;YACtDrB;QACF;QACAoC,cAAcP;QACdf;IACF;AACF"}
1
+ {"version":3,"sources":["usePromptListboxFunctionality.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useActiveDescendant } from '@fluentui/react-aria';\nimport { useControllableState, useMergedRefs } from '@fluentui/react-utilities';\nimport { CursorPositionPlugin } from '../../plugins/CursorPositionPlugin';\nimport { useOptionCollection } from './useOptionCollection';\nimport { useSelection } from './useSelection';\nimport { useListboxPositioning } from './useListboxPositioning';\nimport { useTriggerKeydown } from './useTriggerKeyDown';\nimport { PromptListbox } from '../PromptListbox';\nimport { promptOptionClassNames } from '../PromptOption';\nimport type { CursorPosition } from '../../plugins/CursorPositionPlugin';\nimport type {\n UsePromptListboxFunctionalityParams,\n UsePromptListboxFunctionality,\n} from './PromptListboxFunctionality.types';\n\nexport function usePromptListboxFunctionality(\n params: UsePromptListboxFunctionalityParams,\n): UsePromptListboxFunctionality {\n const {\n positioning,\n onOpenChange,\n onSelectionModeChange,\n listboxProps,\n fluid = false,\n allowArrowUpNavigation = false,\n } = params;\n const {\n listboxRef: activeDescendantListboxRef,\n activeParentRef,\n controller: activeDescendantController,\n } = useActiveDescendant<HTMLSpanElement, HTMLDivElement>({\n matchOption: el => el.classList.contains(promptOptionClassNames.root),\n });\n // useMergedRefs to normalize the ref into a React.RefObject type\n const triggerRef = useMergedRefs(activeParentRef);\n const selectionState = useSelection(listboxProps ?? {});\n const { selectOption } = selectionState;\n const optionCollection = useOptionCollection();\n const { getOptionById } = optionCollection;\n const [cursorPosition, setCursorPosition] = React.useState<CursorPosition>('end');\n const [isInSelectionMode, setIsInSelectionMode] = React.useState(false);\n const [open, setOpen] = useControllableState({\n state: params.open,\n defaultState: params.defaultOpen,\n initialState: false,\n });\n\n const setSelectionMode = React.useCallback(\n (selectionMode: boolean) => {\n if (selectionMode === false) {\n activeDescendantController.blur();\n setHideActiveDescendant(true);\n } else {\n setHideActiveDescendant(false);\n }\n\n setIsInSelectionMode(selectionMode);\n onSelectionModeChange?.(selectionMode);\n },\n [activeDescendantController, onSelectionModeChange],\n );\n\n const onBlur = (event: React.FocusEvent<HTMLSpanElement>) => {\n setOpen(false);\n onOpenChange?.(event, { event, type: 'focus', open: false });\n setSelectionMode(false);\n };\n\n const onFocus = (event: React.FocusEvent<HTMLSpanElement>) => {\n if (event.target === event.currentTarget) {\n setOpen(true);\n onOpenChange?.(event, { event, type: 'focus', open: true });\n }\n };\n\n const cursorPositionPlugin = <CursorPositionPlugin setCursorPosition={setCursorPosition} />;\n\n const onListboxBlur = React.useCallback(() => {\n setSelectionMode(false);\n onSelectionModeChange?.(false);\n }, [onSelectionModeChange, setSelectionMode]);\n\n // handle combobox keyboard interaction\n const onKeyDown = useTriggerKeydown({\n ...optionCollection,\n allowArrowUpNavigation,\n activeDescendantController,\n getOptionById,\n onBlur: onListboxBlur,\n selectOption,\n cursorPosition,\n open,\n multiselect: false,\n isInSelectionMode,\n setSelectionMode,\n });\n\n // NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set\n // To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows\n // ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888\n const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);\n\n React.useEffect(() => {\n if (hideActiveDescendant) {\n triggerRef.current?.removeAttribute('aria-activedescendant');\n }\n // We only want to run this when the hideActiveDescendant changes, if the triggerRef\n // is undefined, there's no need to remove theAttribute and we shouldn't be adding\n // refs as dependencies since it can blow up the number of runs.\n // eslint-disable-next-line react-compiler/react-compiler\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [hideActiveDescendant]);\n\n const [comboboxPopupRef, comboboxTargetRef] = useListboxPositioning({ positioning, fluid });\n\n const listboxMergedRef = useMergedRefs(comboboxPopupRef, activeDescendantListboxRef, listboxProps?.ref);\n const listbox = React.useMemo(() => {\n return (\n <PromptListbox\n open={open}\n {...listboxProps}\n {...optionCollection}\n {...selectionState}\n ref={listboxMergedRef}\n activeDescendantController={activeDescendantController}\n />\n );\n }, [activeDescendantController, listboxMergedRef, listboxProps, open, optionCollection, selectionState]);\n\n return {\n promptListbox: listbox,\n triggerProps: {\n ref: triggerRef,\n onBlur,\n onFocus,\n onKeyDown,\n isInSelectionMode,\n },\n containerRef: comboboxTargetRef,\n cursorPositionPlugin,\n };\n}\n"],"names":["React","useActiveDescendant","useControllableState","useMergedRefs","CursorPositionPlugin","useOptionCollection","useSelection","useListboxPositioning","useTriggerKeydown","PromptListbox","promptOptionClassNames","usePromptListboxFunctionality","params","positioning","onOpenChange","onSelectionModeChange","listboxProps","fluid","allowArrowUpNavigation","listboxRef","activeDescendantListboxRef","activeParentRef","controller","activeDescendantController","matchOption","el","classList","contains","root","triggerRef","selectionState","selectOption","optionCollection","getOptionById","cursorPosition","setCursorPosition","useState","isInSelectionMode","setIsInSelectionMode","open","setOpen","state","defaultState","defaultOpen","initialState","setSelectionMode","useCallback","selectionMode","blur","setHideActiveDescendant","onBlur","event","type","onFocus","target","currentTarget","cursorPositionPlugin","onListboxBlur","onKeyDown","multiselect","hideActiveDescendant","useEffect","current","removeAttribute","comboboxPopupRef","comboboxTargetRef","listboxMergedRef","ref","listbox","useMemo","promptListbox","triggerProps","containerRef"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;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C;IACA,oFAAoF;IACpF,kFAAkF;IAClF,gEAAgE;IAChE,yDAAyD;IACzD,uDAAuD;IACzD,GAAG;QAACH;KAAqB;IAEzB,MAAM,CAACI,kBAAkBC,kBAAkB,GAAG1D,sBAAsB;QAAEM;QAAaI;IAAM;IAEzF,MAAMiD,mBAAmB/D,cAAc6D,kBAAkB5C,4BAA4BJ,yBAAAA,mCAAAA,aAAcmD,GAAG;IACtG,MAAMC,UAAUpE,MAAMqE,OAAO,CAAC;QAC5B,qBACE,oBAAC5D;YACC8B,MAAMA;YACL,GAAGvB,YAAY;YACf,GAAGgB,gBAAgB;YACnB,GAAGF,cAAc;YAClBqC,KAAKD;YACL3C,4BAA4BA;;IAGlC,GAAG;QAACA;QAA4B2C;QAAkBlD;QAAcuB;QAAMP;QAAkBF;KAAe;IAEvG,OAAO;QACLwC,eAAeF;QACfG,cAAc;YACZJ,KAAKtC;YACLqB;YACAG;YACAK;YACArB;QACF;QACAmC,cAAcP;QACdT;IACF;AACF"}
@@ -6,6 +6,7 @@
6
6
  import { useSetKeyboardNavigation } from '@fluentui/react-tabster';
7
7
  import { useEventCallback } from '@fluentui/react-utilities';
8
8
  import { getDropdownActionFromKey } from './dropdownKeyActions';
9
+ import { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';
9
10
  export function useTriggerKeydown(options) {
10
11
  const {
11
12
  activeDescendantController,
@@ -13,8 +14,11 @@ export function useTriggerKeydown(options) {
13
14
  selectOption,
14
15
  multiselect,
15
16
  open,
16
- isInLastPosition,
17
- onBlur
17
+ cursorPosition,
18
+ onBlur,
19
+ allowArrowUpNavigation,
20
+ isInSelectionMode,
21
+ setSelectionMode
18
22
  } = options;
19
23
  const getActiveOption = React.useCallback(() => {
20
24
  const activeOptionId = activeDescendantController.active();
@@ -59,12 +63,19 @@ export function useTriggerKeydown(options) {
59
63
  const action = getDropdownActionFromKey(e, {
60
64
  open,
61
65
  multiselect,
62
- isInLastPosition
66
+ cursorPosition,
67
+ allowArrowUpNavigation,
68
+ isInSelectionMode
63
69
  });
64
70
  const activeOption = getActiveOption();
65
71
  const firstOption = activeDescendantController.first({
66
72
  passive: true
67
73
  });
74
+ if (e.key === ArrowLeft || e.key === ArrowRight || action === 'Type') {
75
+ setSelectionMode(false);
76
+ } else if (action === 'Next' || action === 'Previous' || action === 'First' || action === 'Last' || action === 'PageUp' || action === 'PageDown') {
77
+ setSelectionMode(true);
78
+ }
68
79
  switch (action) {
69
80
  case 'Last':
70
81
  case 'First':
@@ -75,14 +86,7 @@ export function useTriggerKeydown(options) {
75
86
  e.preventDefault();
76
87
  break;
77
88
  case 'Previous':
78
- // when active option is the first option and the action was "Previous",
79
- // this means we were in the first option and we are "leaving" the listbox
80
- if ((activeOption === null || activeOption === void 0 ? void 0 : activeOption.id) === firstOption) {
81
- blur();
82
- e.preventDefault();
83
- } else if (activeOption) {
84
- e.preventDefault();
85
- }
89
+ e.preventDefault();
86
90
  break;
87
91
  case 'Next':
88
92
  e.preventDefault();
@@ -92,18 +96,33 @@ export function useTriggerKeydown(options) {
92
96
  switch (action) {
93
97
  case 'First':
94
98
  first();
99
+ if (!isInSelectionMode) {
100
+ setSelectionMode(true);
101
+ }
95
102
  break;
96
103
  case 'Last':
97
104
  last();
105
+ if (!isInSelectionMode) {
106
+ setSelectionMode(true);
107
+ }
98
108
  break;
99
109
  case 'Next':
100
110
  next(activeOption);
111
+ if (!isInSelectionMode) {
112
+ setSelectionMode(true);
113
+ }
101
114
  break;
102
115
  case 'Previous':
116
+ // when active option is the first option and the action was "Previous",
117
+ // this means we were in the first option and we are "leaving" the listbox
103
118
  if (activeOption && activeOption.id !== firstOption) {
104
119
  previous(activeOption);
120
+ if (!isInSelectionMode) {
121
+ setSelectionMode(true);
122
+ }
105
123
  } else {
106
124
  blur();
125
+ setSelectionMode(false);
107
126
  }
108
127
  break;
109
128
  case 'PageDown':
@@ -115,6 +134,7 @@ export function useTriggerKeydown(options) {
115
134
  case 'CloseSelect':
116
135
  if (!multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled)) {
117
136
  blur();
137
+ setSelectionMode(false);
118
138
  }
119
139
  // fallthrough
120
140
  case 'Select':
@@ -1 +1 @@
1
- {"version":3,"sources":["useTriggerKeyDown.ts"],"sourcesContent":["/**\n * Note, this is mainly brought from Fluent UI, only removed the closing and\n * opening logic since that's not needed for this use case and added the bluring\n * functionality.\n */\n\nimport * as React from 'react';\nimport { useSetKeyboardNavigation } from '@fluentui/react-tabster';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from './dropdownKeyActions';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport type { OptionCollectionState, OptionValue } from './OptionCollection.types';\nimport type { SelectionProps, SelectionState } from './Selection.types';\n\nexport function useTriggerKeydown(\n options: {\n activeDescendantController: ActiveDescendantImperativeRef;\n isInLastPosition: boolean;\n open: boolean;\n onBlur: () => void;\n } & OptionCollectionState &\n Pick<SelectionProps, 'multiselect'> &\n Pick<SelectionState, 'selectOption'>,\n) {\n const { activeDescendantController, getOptionById, selectOption, multiselect, open, isInLastPosition, onBlur } =\n options;\n\n const getActiveOption = React.useCallback(() => {\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [activeDescendantController, getOptionById]);\n\n const first = () => {\n activeDescendantController.first();\n };\n\n const last = () => {\n activeDescendantController.last();\n };\n\n const blur = () => {\n activeDescendantController.blur();\n onBlur();\n };\n\n const next = (activeOption: OptionValue | undefined) => {\n if (activeOption) {\n activeDescendantController.next();\n } else {\n activeDescendantController.first();\n }\n };\n\n const previous = (activeOption: OptionValue | undefined) => {\n if (activeOption) {\n activeDescendantController.prev();\n } else {\n activeDescendantController.first();\n }\n };\n\n const pageUp = () => {\n for (let i = 0; i < 10; i++) {\n activeDescendantController.prev();\n }\n };\n\n const pageDown = () => {\n for (let i = 0; i < 10; i++) {\n activeDescendantController.next();\n }\n };\n\n const setKeyboardNavigation = useSetKeyboardNavigation();\n return useEventCallback((e: React.KeyboardEvent<HTMLSpanElement>) => {\n const action = getDropdownActionFromKey(e, { open, multiselect, isInLastPosition });\n const activeOption = getActiveOption();\n const firstOption = activeDescendantController.first({ passive: true });\n\n switch (action) {\n case 'Last':\n case 'First':\n case 'PageDown':\n case 'PageUp':\n case 'CloseSelect':\n case 'Select':\n e.preventDefault();\n break;\n case 'Previous':\n // when active option is the first option and the action was \"Previous\",\n // this means we were in the first option and we are \"leaving\" the listbox\n if (activeOption?.id === firstOption) {\n blur();\n e.preventDefault();\n } else if (activeOption) {\n e.preventDefault();\n }\n break;\n case 'Next':\n e.preventDefault();\n break;\n }\n\n setKeyboardNavigation(true);\n\n switch (action) {\n case 'First':\n first();\n break;\n case 'Last':\n last();\n break;\n case 'Next':\n next(activeOption);\n break;\n case 'Previous':\n if (activeOption && activeOption.id !== firstOption) {\n previous(activeOption);\n } else {\n blur();\n }\n break;\n case 'PageDown':\n pageDown();\n break;\n case 'PageUp':\n pageUp();\n break;\n case 'CloseSelect':\n if (!multiselect && !activeOption?.disabled) {\n blur();\n }\n // fallthrough\n case 'Select':\n activeOption && selectOption(e, activeOption);\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(e, activeOption);\n break;\n }\n });\n}\n"],"names":["React","useSetKeyboardNavigation","useEventCallback","getDropdownActionFromKey","useTriggerKeydown","options","activeDescendantController","getOptionById","selectOption","multiselect","open","isInLastPosition","onBlur","getActiveOption","useCallback","activeOptionId","active","undefined","first","last","blur","next","activeOption","previous","prev","pageUp","i","pageDown","setKeyboardNavigation","e","action","firstOption","passive","preventDefault","id","disabled"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;;;CAIC,GAED,YAAYA,WAAW,QAAQ;AAC/B,SAASC,wBAAwB,QAAQ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K;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;gBACHD,EAAEI,cAAc;gBAChB;YACF,KAAK;gBACH,wEAAwE;gBACxE,0EAA0E;gBAC1E,IAAIX,CAAAA,yBAAAA,mCAAAA,aAAcY,EAAE,MAAKH,aAAa;oBACpCX;oBACAS,EAAEI,cAAc;gBAClB,OAAO,IAAIX,cAAc;oBACvBO,EAAEI,cAAc;gBAClB;gBACA;YACF,KAAK;gBACHJ,EAAEI,cAAc;gBAChB;QACJ;QAEAL,sBAAsB;QAEtB,OAAQE;YACN,KAAK;gBACHZ;gBACA;YACF,KAAK;gBACHC;gBACA;YACF,KAAK;gBACHE,KAAKC;gBACL;YACF,KAAK;gBACH,IAAIA,gBAAgBA,aAAaY,EAAE,KAAKH,aAAa;oBACnDR,SAASD;gBACX,OAAO;oBACLF;gBACF;gBACA;YACF,KAAK;gBACHO;gBACA;YACF,KAAK;gBACHF;gBACA;YACF,KAAK;gBACH,IAAI,CAAChB,eAAe,EAACa,yBAAAA,mCAAAA,aAAca,QAAQ,GAAE;oBAC3Cf;gBACF;YACF,cAAc;YACd,KAAK;gBACHE,gBAAgBd,aAAaqB,GAAGP;gBAChC;YACF,KAAK;gBACH,CAACb,eAAea,gBAAgBd,aAAaqB,GAAGP;gBAChD;QACJ;IACF;AACF"}
1
+ {"version":3,"sources":["useTriggerKeyDown.ts"],"sourcesContent":["/**\n * Note, this is mainly brought from Fluent UI, only removed the closing and\n * opening logic since that's not needed for this use case and added the bluring\n * functionality.\n */\n\nimport * as React from 'react';\nimport { useSetKeyboardNavigation } from '@fluentui/react-tabster';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from './dropdownKeyActions';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport type { OptionCollectionState, OptionValue } from './OptionCollection.types';\nimport type { SelectionProps, SelectionState } from './Selection.types';\nimport type { CursorPosition } from '../../plugins/CursorPositionPlugin';\n\nexport function useTriggerKeydown(\n options: {\n activeDescendantController: ActiveDescendantImperativeRef;\n cursorPosition: CursorPosition;\n open: boolean;\n onBlur: () => void;\n allowArrowUpNavigation: boolean;\n isInSelectionMode: boolean;\n setSelectionMode: (selectionMode: boolean) => void;\n } & OptionCollectionState &\n Pick<SelectionProps, 'multiselect'> &\n Pick<SelectionState, 'selectOption'>,\n) {\n const {\n activeDescendantController,\n getOptionById,\n selectOption,\n multiselect,\n open,\n cursorPosition,\n onBlur,\n allowArrowUpNavigation,\n isInSelectionMode,\n setSelectionMode,\n } = options;\n\n const getActiveOption = React.useCallback(() => {\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [activeDescendantController, getOptionById]);\n\n const first = () => {\n activeDescendantController.first();\n };\n\n const last = () => {\n activeDescendantController.last();\n };\n\n const blur = () => {\n activeDescendantController.blur();\n onBlur();\n };\n\n const next = (activeOption: OptionValue | undefined) => {\n if (activeOption) {\n activeDescendantController.next();\n } else {\n activeDescendantController.first();\n }\n };\n\n const previous = (activeOption: OptionValue | undefined) => {\n if (activeOption) {\n activeDescendantController.prev();\n } else {\n activeDescendantController.first();\n }\n };\n\n const pageUp = () => {\n for (let i = 0; i < 10; i++) {\n activeDescendantController.prev();\n }\n };\n\n const pageDown = () => {\n for (let i = 0; i < 10; i++) {\n activeDescendantController.next();\n }\n };\n\n const setKeyboardNavigation = useSetKeyboardNavigation();\n return useEventCallback((e: React.KeyboardEvent<HTMLSpanElement>) => {\n const action = getDropdownActionFromKey(e, {\n open,\n multiselect,\n cursorPosition,\n allowArrowUpNavigation,\n isInSelectionMode,\n });\n const activeOption = getActiveOption();\n const firstOption = activeDescendantController.first({ passive: true });\n\n if (e.key === ArrowLeft || e.key === ArrowRight || action === 'Type') {\n setSelectionMode(false);\n } else if (\n action === 'Next' ||\n action === 'Previous' ||\n action === 'First' ||\n action === 'Last' ||\n action === 'PageUp' ||\n action === 'PageDown'\n ) {\n setSelectionMode(true);\n }\n\n switch (action) {\n case 'Last':\n case 'First':\n case 'PageDown':\n case 'PageUp':\n case 'CloseSelect':\n case 'Select':\n e.preventDefault();\n break;\n case 'Previous':\n e.preventDefault();\n break;\n case 'Next':\n e.preventDefault();\n break;\n }\n\n setKeyboardNavigation(true);\n\n switch (action) {\n case 'First':\n first();\n if (!isInSelectionMode) {\n setSelectionMode(true);\n }\n break;\n case 'Last':\n last();\n if (!isInSelectionMode) {\n setSelectionMode(true);\n }\n break;\n case 'Next':\n next(activeOption);\n if (!isInSelectionMode) {\n setSelectionMode(true);\n }\n break;\n case 'Previous':\n // when active option is the first option and the action was \"Previous\",\n // this means we were in the first option and we are \"leaving\" the listbox\n if (activeOption && activeOption.id !== firstOption) {\n previous(activeOption);\n if (!isInSelectionMode) {\n setSelectionMode(true);\n }\n } else {\n blur();\n setSelectionMode(false);\n }\n break;\n case 'PageDown':\n pageDown();\n break;\n case 'PageUp':\n pageUp();\n break;\n case 'CloseSelect':\n if (!multiselect && !activeOption?.disabled) {\n blur();\n setSelectionMode(false);\n }\n // fallthrough\n case 'Select':\n activeOption && selectOption(e, activeOption);\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(e, activeOption);\n break;\n }\n });\n}\n"],"names":["React","useSetKeyboardNavigation","useEventCallback","getDropdownActionFromKey","ArrowLeft","ArrowRight","useTriggerKeydown","options","activeDescendantController","getOptionById","selectOption","multiselect","open","cursorPosition","onBlur","allowArrowUpNavigation","isInSelectionMode","setSelectionMode","getActiveOption","useCallback","activeOptionId","active","undefined","first","last","blur","next","activeOption","previous","prev","pageUp","i","pageDown","setKeyboardNavigation","e","action","firstOption","passive","key","preventDefault","id","disabled"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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P;gBAChC;YACF,KAAK;gBACH,CAAChB,eAAegB,gBAAgBjB,aAAawB,GAAGP;gBAChD;QACJ;IACF;AACF"}
package/lib/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export { PromptListbox, promptListboxClassNames, renderPromptListbox_unstable, usePromptListboxStyles_unstable, usePromptListbox_unstable } from './PromptListbox';
2
2
  export { usePromptListboxFunctionality } from './components/utils/usePromptListboxFunctionality';
3
- export { TextCursorPositionPlugin } from './plugins/TextCursorPositionPlugin';
4
3
  export { PromptOption, promptOptionClassNames, renderPromptOption_unstable, usePromptOptionStyles_unstable, usePromptOption_unstable } from './PromptOption';
5
4
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export type { PromptListboxProps, PromptListboxSlots, PromptListboxState } from './PromptListbox';\nexport {\n PromptListbox,\n promptListboxClassNames,\n renderPromptListbox_unstable,\n usePromptListboxStyles_unstable,\n usePromptListbox_unstable,\n} from './PromptListbox';\n\nexport { usePromptListboxFunctionality } from './components/utils/usePromptListboxFunctionality';\nexport type {\n OnOpenChangeData,\n ProcessedPromptListboxProps,\n UsePromptListboxFunctionality,\n UsePromptListboxFunctionalityParams,\n} from './components/utils/PromptListboxFunctionality.types';\n\nexport type { TextCursorPositionPluginProps } from './plugins/TextCursorPositionPlugin';\nexport { TextCursorPositionPlugin } from './plugins/TextCursorPositionPlugin';\n\nexport type { PromptOptionProps, PromptOptionSlots, PromptOptionState } from './PromptOption';\nexport {\n PromptOption,\n promptOptionClassNames,\n renderPromptOption_unstable,\n usePromptOptionStyles_unstable,\n usePromptOption_unstable,\n} from './PromptOption';\n"],"names":["PromptListbox","promptListboxClassNames","renderPromptListbox_unstable","usePromptListboxStyles_unstable","usePromptListbox_unstable","usePromptListboxFunctionality","TextCursorPositionPlugin","PromptOption","promptOptionClassNames","renderPromptOption_unstable","usePromptOptionStyles_unstable","usePromptOption_unstable"],"rangeMappings":";;;","mappings":"AACA,SACEA,aAAa,EACbC,uBAAuB,EACvBC,4BAA4B,EAC5BC,+BAA+B,EAC/BC,yBAAyB,QACpB,kBAAkB;AAEzB,SAASC,6BAA6B,QAAQ,mDAAmD;AASjG,SAASC,wBAAwB,QAAQ,qCAAqC;AAG9E,SACEC,YAAY,EACZC,sBAAsB,EACtBC,2BAA2B,EAC3BC,8BAA8B,EAC9BC,wBAAwB,QACnB,iBAAiB"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export type { PromptListboxProps, PromptListboxSlots, PromptListboxState } from './PromptListbox';\nexport {\n PromptListbox,\n promptListboxClassNames,\n renderPromptListbox_unstable,\n usePromptListboxStyles_unstable,\n usePromptListbox_unstable,\n} from './PromptListbox';\n\nexport { usePromptListboxFunctionality } from './components/utils/usePromptListboxFunctionality';\nexport type {\n OnOpenChangeData,\n ProcessedPromptListboxProps,\n UsePromptListboxFunctionality,\n UsePromptListboxFunctionalityParams,\n} from './components/utils/PromptListboxFunctionality.types';\n\nexport type { PromptOptionProps, PromptOptionSlots, PromptOptionState } from './PromptOption';\nexport {\n PromptOption,\n promptOptionClassNames,\n renderPromptOption_unstable,\n usePromptOptionStyles_unstable,\n usePromptOption_unstable,\n} from './PromptOption';\n"],"names":["PromptListbox","promptListboxClassNames","renderPromptListbox_unstable","usePromptListboxStyles_unstable","usePromptListbox_unstable","usePromptListboxFunctionality","PromptOption","promptOptionClassNames","renderPromptOption_unstable","usePromptOptionStyles_unstable","usePromptOption_unstable"],"rangeMappings":";;","mappings":"AACA,SACEA,aAAa,EACbC,uBAAuB,EACvBC,4BAA4B,EAC5BC,+BAA+B,EAC/BC,yBAAyB,QACpB,kBAAkB;AAEzB,SAASC,6BAA6B,QAAQ,mDAAmD;AASjG,SACEC,YAAY,EACZC,sBAAsB,EACtBC,2BAA2B,EAC3BC,8BAA8B,EAC9BC,wBAAwB,QACnB,iBAAiB"}
@@ -0,0 +1,43 @@
1
+ import { $isSentinelNode } from '@fluentui-copilot/chat-input-plugins';
2
+ import { SELECTION_CHANGE_COMMAND, $getSelection, useLexicalComposerContext, $isRangeSelection, $isElementNode, COMMAND_PRIORITY_HIGH } from '@fluentui-copilot/react-text-editor';
3
+ import * as React from 'react';
4
+ export const CursorPositionPlugin = ({
5
+ setCursorPosition
6
+ }) => {
7
+ const [editor] = useLexicalComposerContext();
8
+ React.useEffect(() => {
9
+ const $selectionChangeHandler = () => {
10
+ const selection = $getSelection();
11
+ // If selection is null, the cursor is not active in the editor and we should just noop
12
+ if (selection === null || !$isRangeSelection(selection) || !selection.isCollapsed()) {
13
+ setCursorPosition('between-text');
14
+ return false;
15
+ }
16
+ // Should only be one node in the selection because the selection is collapsed
17
+ const selectedNode = selection.getNodes().at(0);
18
+ // If there's no selected node, focus isn't in the editor
19
+ if (!selectedNode) {
20
+ return false;
21
+ }
22
+ // If there are no leaf nodes, the paragraph node will be selected
23
+ if ($isElementNode(selectedNode)) {
24
+ setCursorPosition('start-end');
25
+ return false;
26
+ } else if ($isSentinelNode(selectedNode) && !selectedNode.getNextSibling()) {
27
+ setCursorPosition('end');
28
+ return false;
29
+ } else if ($isSentinelNode(selectedNode.getNextSibling()) && selection.focus.offset === selectedNode.getTextContentSize()) {
30
+ setCursorPosition('end');
31
+ return false;
32
+ } else if (selectedNode.getPreviousSibling() === null && selection.focus.offset === 0) {
33
+ setCursorPosition('start');
34
+ return false;
35
+ }
36
+ setCursorPosition('between-text');
37
+ return false;
38
+ };
39
+ return editor.registerCommand(SELECTION_CHANGE_COMMAND, $selectionChangeHandler, COMMAND_PRIORITY_HIGH);
40
+ }, [editor, setCursorPosition]);
41
+ return null;
42
+ };
43
+ //# sourceMappingURL=CursorPositionPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["CursorPositionPlugin.ts"],"sourcesContent":["import { $isSentinelNode } from '@fluentui-copilot/chat-input-plugins';\nimport {\n SELECTION_CHANGE_COMMAND,\n $getSelection,\n useLexicalComposerContext,\n $isRangeSelection,\n $isElementNode,\n COMMAND_PRIORITY_HIGH,\n} from '@fluentui-copilot/react-text-editor';\nimport * as React from 'react';\n\n/**\n * Position the cursor is in based on it's content. The goal\n * is to track whether the cursor is at the end of the input\n * or between text.\n */\nexport type CursorPosition = 'start' | 'between-text' | 'end' | 'start-end';\n\nexport type CursorPositionPluginProps = {\n setCursorPosition: (position: CursorPosition) => void;\n};\n\nexport const CursorPositionPlugin: React.FunctionComponent<CursorPositionPluginProps> = ({ setCursorPosition }) => {\n const [editor] = useLexicalComposerContext();\n\n React.useEffect(() => {\n const $selectionChangeHandler = () => {\n const selection = $getSelection();\n // If selection is null, the cursor is not active in the editor and we should just noop\n if (selection === null || !$isRangeSelection(selection) || !selection.isCollapsed()) {\n setCursorPosition('between-text');\n return false;\n }\n\n // Should only be one node in the selection because the selection is collapsed\n const selectedNode = selection.getNodes().at(0);\n // If there's no selected node, focus isn't in the editor\n if (!selectedNode) {\n return false;\n }\n\n // If there are no leaf nodes, the paragraph node will be selected\n if ($isElementNode(selectedNode)) {\n setCursorPosition('start-end');\n return false;\n }\n\n // if the selection node is a sentinel and it matches the sentinel at the end\n else if ($isSentinelNode(selectedNode) && !selectedNode.getNextSibling()) {\n setCursorPosition('end');\n return false;\n }\n\n // else if the selection node is not a sentinel, check that the next sibling node is a sentinel\n // and check if the focus offset is in the last position of the node.\n else if (\n $isSentinelNode(selectedNode.getNextSibling()) &&\n selection.focus.offset === selectedNode.getTextContentSize()\n ) {\n setCursorPosition('end');\n return false;\n }\n\n // else if the selection node is not at the end and is not a sentinel, check if there's a previous\n // sibling and that we are at the start. If that's the case we are at the start.\n else if (selectedNode.getPreviousSibling() === null && selection.focus.offset === 0) {\n setCursorPosition('start');\n return false;\n }\n\n setCursorPosition('between-text');\n return false;\n };\n\n return editor.registerCommand(SELECTION_CHANGE_COMMAND, $selectionChangeHandler, COMMAND_PRIORITY_HIGH);\n }, [editor, setCursorPosition]);\n\n return null;\n};\n"],"names":["$isSentinelNode","SELECTION_CHANGE_COMMAND","$getSelection","useLexicalComposerContext","$isRangeSelection","$isElementNode","COMMAND_PRIORITY_HIGH","React","CursorPositionPlugin","setCursorPosition","editor","useEffect","$selectionChangeHandler","selection","isCollapsed","selectedNode","getNodes","at","getNextSibling","focus","offset","getTextContentSize","getPreviousSibling","registerCommand"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,eAAe,QAAQ,uCAAuC;AACvE,SACEC,wBAAwB,EACxBC,aAAa,EACbC,yBAAyB,EACzBC,iBAAiB,EACjBC,cAAc,EACdC,qBAAqB,QAChB,sCAAsC;AAC7C,YAAYC,WAAW,QAAQ;AAa/B,OAAO,MAAMC,uBAA2E,CAAC,EAAEC,iBAAiB,EAAE;IAC5G,MAAM,CAACC,OAAO,GAAGP;IAEjBI,MAAMI,SAAS,CAAC;QACd,MAAMC,0BAA0B;YAC9B,MAAMC,YAAYX;YAClB,uFAAuF;YACvF,IAAIW,cAAc,QAAQ,CAACT,kBAAkBS,cAAc,CAACA,UAAUC,WAAW,IAAI;gBACnFL,kBAAkB;gBAClB,OAAO;YACT;YAEA,8EAA8E;YAC9E,MAAMM,eAAeF,UAAUG,QAAQ,GAAGC,EAAE,CAAC;YAC7C,yDAAyD;YACzD,IAAI,CAACF,cAAc;gBACjB,OAAO;YACT;YAEA,kEAAkE;YAClE,IAAIV,eAAeU,eAAe;gBAChCN,kBAAkB;gBAClB,OAAO;YACT,OAGK,IAAIT,gBAAgBe,iBAAiB,CAACA,aAAaG,cAAc,IAAI;gBACxET,kBAAkB;gBAClB,OAAO;YACT,OAIK,IACHT,gBAAgBe,aAAaG,cAAc,OAC3CL,UAAUM,KAAK,CAACC,MAAM,KAAKL,aAAaM,kBAAkB,IAC1D;gBACAZ,kBAAkB;gBAClB,OAAO;YACT,OAIK,IAAIM,aAAaO,kBAAkB,OAAO,QAAQT,UAAUM,KAAK,CAACC,MAAM,KAAK,GAAG;gBACnFX,kBAAkB;gBAClB,OAAO;YACT;YAEAA,kBAAkB;YAClB,OAAO;QACT;QAEA,OAAOC,OAAOa,eAAe,CAACtB,0BAA0BW,yBAAyBN;IACnF,GAAG;QAACI;QAAQD;KAAkB;IAE9B,OAAO;AACT,EAAE"}
@@ -25,22 +25,11 @@ const promptListboxClassNames = {
25
25
  */ const useStyles = (0, _reactcomponents.__styles)({
26
26
  listbox: {
27
27
  E5pizo: "f1hg901r",
28
- Bbmb7ep: [
29
- "f1aa9q02",
30
- "f16jpd5f"
31
- ],
32
- Beyfa6y: [
33
- "f16jpd5f",
34
- "f1aa9q02"
35
- ],
36
- B7oj6ja: [
37
- "f1jar5jt",
38
- "fyu767a"
39
- ],
40
- Btl43ni: [
41
- "fyu767a",
42
- "f1jar5jt"
43
- ],
28
+ Beyfa6y: 0,
29
+ Bbmb7ep: 0,
30
+ Btl43ni: 0,
31
+ B7oj6ja: 0,
32
+ Dimara: "ft85np5",
44
33
  Bxyxcbc: "fmmk62d",
45
34
  B7ck84d: "f1ewtqcl"
46
35
  },
@@ -53,10 +42,12 @@ const promptListboxClassNames = {
53
42
  }, {
54
43
  d: [
55
44
  ".f1hg901r{box-shadow:var(--shadow16);}",
56
- ".f1aa9q02{border-bottom-right-radius:var(--borderRadiusMedium);}",
57
- ".f16jpd5f{border-bottom-left-radius:var(--borderRadiusMedium);}",
58
- ".f1jar5jt{border-top-right-radius:var(--borderRadiusMedium);}",
59
- ".fyu767a{border-top-left-radius:var(--borderRadiusMedium);}",
45
+ [
46
+ ".ft85np5{border-radius:var(--borderRadiusMedium);}",
47
+ {
48
+ p: -1
49
+ }
50
+ ],
60
51
  ".fmmk62d{max-height:80vh;}",
61
52
  ".f1ewtqcl{box-sizing:border-box;}",
62
53
  ".fjseox{display:none;}",
@@ -1 +1 @@
1
- {"version":3,"sources":["usePromptListboxStyles.styles.ts"],"sourcesContent":["import { makeStyles, mergeClasses, shorthands, tokens } from '@fluentui/react-components';\nimport type { PromptListboxSlots, PromptListboxState } from './PromptListbox.types';\nimport type { SlotClassNames } from '@fluentui/react-components';\n\nexport const promptListboxClassNames: SlotClassNames<PromptListboxSlots> = {\n root: 'fai-PromptListbox',\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n listbox: {\n boxShadow: tokens.shadow16,\n ...shorthands.borderRadius(tokens.borderRadiusMedium),\n maxHeight: '80vh',\n boxSizing: 'border-box',\n },\n\n listboxCollapsed: {\n display: 'none',\n },\n\n // When rendering inline, the popupSurface will be rendered under relatively positioned elements such as Input.\n // This is due to the surface being positioned as absolute, therefore zIndex: 1 ensures that won't happen.\n inlineListbox: {\n zIndex: 1,\n },\n});\n\n/**\n * Apply styling to the PromptListbox slots based on the state\n */\nexport const usePromptListboxStyles_unstable = (state: PromptListboxState): PromptListboxState => {\n 'use no memo';\n\n const styles = useStyles();\n state.root.className = mergeClasses(\n promptListboxClassNames.root,\n styles.listbox,\n state.inlinePopup && styles.inlineListbox,\n !state.open && styles.listboxCollapsed,\n state.root.className,\n );\n\n return state;\n};\n"],"names":["promptListboxClassNames","usePromptListboxStyles_unstable","root","listbox","__styles","boxShadow","shorthands","maxHeight","boxSizing","B7oj6ja","listboxCollapsed","display","B7ck84d","inlineListbox","Bj3rh1h","d","state"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAIaA,uBAAAA;eAAAA;;IA0CXC,+BAAA;eAAAA;;;iCA9CmD;AAI9C,MAAMD,0BAA8D;UACzEE;AACF;AAEA;;CAEC,SAECC,YAASC,IAAAA,yBAAA,EAAA;aACPC;gBACGC;iBACHC;YAAAA;YAAW;SAAA;iBACXC;YAAAA;YAAW;SAAA;QACbC,SAAA;YAAA;YAAA;SAAA;QAEAC,SAAAA;YAAAA;YAAkB;SAAA;iBAChBC;QACFC,SAAA;;sBAGA;QACAC,QAAAA;;mBAEA;QACFC,SAAA;IAEA;;IAECC,GACD;QAAA;QAAad;QAAmCe;QAAAA;QAAAA;QAAAA;QAAAA;QAAAA;QAAAA;KAAAA;;AAa9C,MAAAf,kCAAAe,CAAAA"}
1
+ {"version":3,"sources":["usePromptListboxStyles.styles.ts"],"sourcesContent":["import { makeStyles, mergeClasses, tokens } from '@fluentui/react-components';\nimport type { PromptListboxSlots, PromptListboxState } from './PromptListbox.types';\nimport type { SlotClassNames } from '@fluentui/react-components';\n\nexport const promptListboxClassNames: SlotClassNames<PromptListboxSlots> = {\n root: 'fai-PromptListbox',\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n listbox: {\n boxShadow: tokens.shadow16,\n borderRadius: tokens.borderRadiusMedium,\n maxHeight: '80vh',\n boxSizing: 'border-box',\n },\n\n listboxCollapsed: {\n display: 'none',\n },\n\n // When rendering inline, the popupSurface will be rendered under relatively positioned elements such as Input.\n // This is due to the surface being positioned as absolute, therefore zIndex: 1 ensures that won't happen.\n inlineListbox: {\n zIndex: 1,\n },\n});\n\n/**\n * Apply styling to the PromptListbox slots based on the state\n */\nexport const usePromptListboxStyles_unstable = (state: PromptListboxState): PromptListboxState => {\n 'use no memo';\n\n const styles = useStyles();\n state.root.className = mergeClasses(\n promptListboxClassNames.root,\n styles.listbox,\n state.inlinePopup && styles.inlineListbox,\n !state.open && styles.listboxCollapsed,\n state.root.className,\n );\n\n return state;\n};\n"],"names":["promptListboxClassNames","root","listbox","__styles","boxShadow","borderRadius","maxHeight","boxSizing","Btl43ni","listboxCollapsed","display","Bxyxcbc","B7ck84d","zIndex","inlineListbox","Bj3rh1h","p","state","mergeClasses","styles","inlinePopup"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAIaA,uBAAAA;eAAAA;;;;;;iCAJ4B;AAIlC,MAAMA,0BAA8D;UACzEC;AACF;AAEA;;CAEC,SAECC,YAASC,IAAAA,yBAAA,EAAA;aACPC;gBACAC;iBACAC;iBACAC;QACFC,SAAA;QAEAC,SAAAA;gBACEC;QACFC,SAAA;QAEAC,SAAA;;sBAEe;gBACbC;;IAEJC,eAAA;QAEAC,SAAA;;GAEC;OAEC;QAAA;QAAA;YAAA;YAAA;gBAEAC,GAAA,CAAA;;SACAC;QAAAA;QAAuBC;QAErBC;QACMC;KAAsBN"}
@@ -12,7 +12,6 @@ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildc
12
12
  const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
13
  const _reactcomponents = require("@fluentui/react-components");
14
14
  const _reactcombobox = require("@fluentui/react-combobox");
15
- const _reactaria = require("@fluentui/react-aria");
16
15
  const usePromptOption_unstable = (props, ref)=>{
17
16
  const { children, disabled, text, value } = props;
18
17
  const optionRef = _react.useRef(null);
@@ -33,7 +32,6 @@ const usePromptOption_unstable = (props, ref)=>{
33
32
  optionValue
34
33
  ]);
35
34
  // context values
36
- const { controller: activeDescendantController } = (0, _reactaria.useActiveDescendantContext)();
37
35
  const registerOption = (0, _reactcombobox.useListboxContext_unstable)((ctx)=>ctx.registerOption);
38
36
  const selected = (0, _reactcombobox.useListboxContext_unstable)((ctx)=>{
39
37
  const selectedOptions = ctx.selectedOptions;
@@ -47,7 +45,6 @@ const usePromptOption_unstable = (props, ref)=>{
47
45
  event.preventDefault();
48
46
  return;
49
47
  }
50
- activeDescendantController.focus(id);
51
48
  // handle selection change
52
49
  selectOption(event, optionData);
53
50
  onOptionClick(event);
@@ -1 +1 @@
1
- {"version":3,"sources":["usePromptOption.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getIntrinsicElementProps, slot, useId, useMergedRefs } from '@fluentui/react-components';\nimport { useListboxContext_unstable } from '@fluentui/react-combobox';\nimport { useActiveDescendantContext } from '@fluentui/react-aria';\nimport type { PromptOptionProps, PromptOptionState } from './PromptOption.types';\nimport type { OptionValue } from '../utils/OptionCollection.types';\n\n// If you add JSX to this file, be sure to change the file type to .tsx\n\n/**\n * Create the state required to render PromptOption.\n *\n * The returned state can be modified with hooks such as usePromptOptionStyles_unstable,\n * before being passed to renderPromptOption_unstable.\n *\n * @param props - props from this instance of PromptOption\n * @param ref - reference to root HTMLElement of PromptOption\n */\nexport const usePromptOption_unstable = (\n props: PromptOptionProps,\n ref: React.Ref<HTMLDivElement>,\n): PromptOptionState => {\n const { children, disabled, text, value } = props;\n const optionRef = React.useRef<HTMLDivElement>(null);\n const optionText = getTextString(text, children);\n const optionValue = value ?? optionText;\n\n // use the id if provided, otherwise use a generated id\n const id = useId('fluent-option', props.id);\n\n // data used for context registration & events\n const optionData = React.useMemo<OptionValue>(\n () => ({ id, disabled, text: optionText, value: optionValue }),\n [id, disabled, optionText, optionValue],\n );\n\n // context values\n const { controller: activeDescendantController } = useActiveDescendantContext();\n const registerOption = useListboxContext_unstable(ctx => ctx.registerOption);\n const selected = useListboxContext_unstable(ctx => {\n const selectedOptions = ctx.selectedOptions;\n\n return optionValue !== undefined && selectedOptions.find(o => o === optionValue) !== undefined;\n });\n const selectOption = useListboxContext_unstable(ctx => ctx.selectOption);\n const onOptionClick = useListboxContext_unstable(ctx => ctx.onOptionClick);\n\n const onClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (disabled) {\n event.preventDefault();\n return;\n }\n\n activeDescendantController.focus(id);\n\n // handle selection change\n selectOption(event, optionData);\n\n onOptionClick(event);\n props.onClick?.(event);\n };\n\n // register option data with context\n React.useEffect(() => {\n if (id && optionRef.current) {\n return registerOption(optionData, optionRef.current);\n }\n }, [id, optionData, registerOption]);\n\n return {\n components: {\n root: 'div',\n },\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref: useMergedRefs(ref, optionRef),\n 'aria-disabled': disabled ? true : undefined,\n id,\n role: 'menuitem',\n ...props,\n onClick,\n }),\n { elementType: 'div' },\n ),\n disabled,\n selected,\n };\n};\n\nfunction getTextString(text: string | undefined, children: React.ReactNode) {\n if (text !== undefined) {\n return text;\n }\n\n let textString = '';\n let hasNonStringChild = false;\n React.Children.forEach(children, child => {\n if (typeof child === 'string') {\n textString += child;\n } else {\n hasNonStringChild = true;\n }\n });\n\n // warn if an Option has non-string children and no text prop\n if (hasNonStringChild) {\n // eslint-disable-next-line no-console\n console.warn('Provide a `text` prop to Option components when they contain non-string children.');\n }\n\n return textString;\n}\n"],"names":["children","value","props","optionText","disabled","optionValue","text","optionRef","optionData","React","useMemo","id","controller","selected","useListboxContext_unstable","ctx","registerOption","selectedOptions","find","selectOption","onOptionClick","undefined","preventDefault","activeDescendantController","event","onClick","_props_onClick","call","useEffect","current","components","slot","always","getIntrinsicElementProps","root","ref","useMergedRefs","role","getTextString","textString","hasNonStringChild","child","Children","forEach","warn"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAsBUA;;;eAAAA;;;;iEAtBa;iCAC8C;+BAC1B;2BACA;AAmBzC,MAAQA,2BAA0BC,CAAAA,OAAUC;UAC5C,EACAF,QAAMG,EACNC,QAAMC,EAENC,IAAA,EACAL,KAAA,KAEAC;UACAK,YAAMC,OAAaC,MAAMC,CAAAA;uBACdC,cAAAA,MAAAA;wBAAIP,UAAAA,QAAAA,UAAAA,KAAAA,IAAAA,QAAAA;2DAAgBD;eAAYF,IAAAA,sBAAAA,EAAOI,iBAAAA,MAAAA,EAAAA;kDAChD;UAACM,aAAAA,OAAAA,OAAAA,CAAAA,IAAAA,CAAAA;;;kBAA0BN;mBAAYA;YAGzC;QAAAM;QAAAP;QAAiBD;QAAAE;KAAA;qBACTO;UACR,EACAA,YAAMC,0BAAWC,8CACSC;UAExBC,iBAAOX,IAAAA,yCAA6BY,EAAAA,CAAAA,MAAAA,IAAgBC,cAAgBb;UACtEQ,WAAAC,IAAAA,yCAAA,EAAAC,CAAAA;QACA,MAAMI,kBAAeL,IAAAA,eAAAA;QACrB,OAAMM,gBAAgBN,aAAAA,gBAA2BC,IAAOA,CAAAA,CAAAA,IAAIK,MAAAA,iBAAaC;;yBAcvEnB,IAAAA,yCAAAA,EAAAA,CAAAA,MAAAA,IAAAA,YAAAA;UAXAkB,gBAAcN,IAAAA,yCAAA,EAAAC,CAAAA,MAAAA,IAAAK,aAAA;oBACNE,CAAAA;;YAERlB,UAAA;kBAEAmB,cAAAA;;;mCAKcC,KAAAA,CAAAA;kCACdtB;QACFiB,aAAAK,OAAAhB;QAEAY,cAAAI;QACAf,CAAAA,iBAAgBP,MAAAuB,OAAA,MAAA,QAAAC,mBAAA,KAAA,IAAA,KAAA,IAAAA,eAAAC,IAAA,CAAAzB,OAAAsB;;wCAEUhB;WACxBoB,SAAA,CAAA;QACF,IAAGjB,MAAAJ,UAAAsB,OAAA,EAAA;mBAAClB,eAAAA,YAAAA,UAAAA,OAAAA;;;;QAAgBK;QAAAA;KAAAA;WAAe;QAEnCc,YAAO;kBACLA;;cAEAC,qBAAA,CAAAC,MAAA,CAAAC,IAAAA,yCAAA,EAAA,OAAA;iBACAC,IAAAA,8BAAWF,EAAMG,KACfF;6BACOG,WAAcD,OAAK5B;;kBAExBI;oBACA0B;;;yBAIF;;;;;;AAKN,SAAEC,cAAAhC,IAAA,EAAAN,QAAA;IAEF,IAAAM,SAASgC,WAAchC;QACrB,OAAIA;;QAEJiC,aAAA;QAEAC,oBAAiB;WACbA,QAAAA,CAAAA,OAAAA,CAAAA,UAAoBC,CAAAA;QACxBhC,IAAAA,OAAMiC,UAASC,UAAQ3C;0BACVyC;;gCAEJ;;;iEAGT;QAEAD,mBAAA;QACA,sCAAuB;gBACrBI,IAAA,CAAA;;WAEFL;EAGF,2CAAA"}
1
+ {"version":3,"sources":["usePromptOption.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getIntrinsicElementProps, slot, useId, useMergedRefs } from '@fluentui/react-components';\nimport { useListboxContext_unstable } from '@fluentui/react-combobox';\nimport type { PromptOptionProps, PromptOptionState } from './PromptOption.types';\nimport type { OptionValue } from '../utils/OptionCollection.types';\n\n// If you add JSX to this file, be sure to change the file type to .tsx\n\n/**\n * Create the state required to render PromptOption.\n *\n * The returned state can be modified with hooks such as usePromptOptionStyles_unstable,\n * before being passed to renderPromptOption_unstable.\n *\n * @param props - props from this instance of PromptOption\n * @param ref - reference to root HTMLElement of PromptOption\n */\nexport const usePromptOption_unstable = (\n props: PromptOptionProps,\n ref: React.Ref<HTMLDivElement>,\n): PromptOptionState => {\n const { children, disabled, text, value } = props;\n const optionRef = React.useRef<HTMLDivElement>(null);\n const optionText = getTextString(text, children);\n const optionValue = value ?? optionText;\n\n // use the id if provided, otherwise use a generated id\n const id = useId('fluent-option', props.id);\n\n // data used for context registration & events\n const optionData = React.useMemo<OptionValue>(\n () => ({ id, disabled, text: optionText, value: optionValue }),\n [id, disabled, optionText, optionValue],\n );\n\n // context values\n const registerOption = useListboxContext_unstable(ctx => ctx.registerOption);\n const selected = useListboxContext_unstable(ctx => {\n const selectedOptions = ctx.selectedOptions;\n\n return optionValue !== undefined && selectedOptions.find(o => o === optionValue) !== undefined;\n });\n const selectOption = useListboxContext_unstable(ctx => ctx.selectOption);\n const onOptionClick = useListboxContext_unstable(ctx => ctx.onOptionClick);\n\n const onClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (disabled) {\n event.preventDefault();\n return;\n }\n\n // handle selection change\n selectOption(event, optionData);\n\n onOptionClick(event);\n props.onClick?.(event);\n };\n\n // register option data with context\n React.useEffect(() => {\n if (id && optionRef.current) {\n return registerOption(optionData, optionRef.current);\n }\n }, [id, optionData, registerOption]);\n\n return {\n components: {\n root: 'div',\n },\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref: useMergedRefs(ref, optionRef),\n 'aria-disabled': disabled ? true : undefined,\n id,\n role: 'menuitem',\n ...props,\n onClick,\n }),\n { elementType: 'div' },\n ),\n disabled,\n selected,\n };\n};\n\nfunction getTextString(text: string | undefined, children: React.ReactNode) {\n if (text !== undefined) {\n return text;\n }\n\n let textString = '';\n let hasNonStringChild = false;\n React.Children.forEach(children, child => {\n if (typeof child === 'string') {\n textString += child;\n } else {\n hasNonStringChild = true;\n }\n });\n\n // warn if an Option has non-string children and no text prop\n if (hasNonStringChild) {\n // eslint-disable-next-line no-console\n console.warn('Provide a `text` prop to Option components when they contain non-string children.');\n }\n\n return textString;\n}\n"],"names":["children","value","props","optionText","disabled","optionValue","text","optionRef","optionData","React","useMemo","id","registerOption","useListboxContext_unstable","ctx","selected","selectedOptions","undefined","find","o","selectOption","onOptionClick","event","_props_onClick","preventDefault","onClick","call","useEffect","current","root","components","getIntrinsicElementProps","ref","textString","Children","forEach","child","hasNonStringChild","console","warn"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAqBUA;;;eAAAA;;;;iEArBa;iCAC8C;+BAC1B;AAmBzC,MAAQA,2BAA0BC,CAAAA,OAAUC;UAC5C,EACAF,QAAMG,EACNC,QAAMC,EAENC,IAAA,EACAL,KAAA,KAEAC;UACAK,YAAMC,OAAaC,MAAMC,CAAAA;uBACdC,cAAAA,MAAAA;wBAAIP,UAAAA,QAAAA,UAAAA,KAAAA,IAAAA,QAAAA;2DAAgBD;eAAYF,IAAAA,sBAAAA,EAAOI,iBAAAA,MAAAA,EAAAA;kDAChD;UAACM,aAAAA,OAAAA,OAAAA,CAAAA,IAAAA,CAAAA;;;kBAA0BN;mBAAYA;YAGzC;QAAAM;QAAAP;QAAiBD;QAAAE;KAAA;qBACXO;UACNA,iBAAiBC,IAAAA,yCAA2BC,EAAAA,CAAAA,MAAAA,IAAAA,cAAAA;UAC1CC,WAAMC,IAAAA,yCAAsBA,EAAAA,CAAAA;cAE5BA,kBAAOX,IAAgBY,eAAaD;QACtC,OAAAX,gBAAAY,aAAAD,gBAAAE,IAAA,CAAAC,CAAAA,IAAAA,MAAAd,iBAAAY;;UAEAG,eAAM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