@fluentui-copilot/react-prompt-listbox 0.0.0-nightly-20240719-0406-ee8d99d6.1

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 (82) hide show
  1. package/CHANGELOG.json +56 -0
  2. package/CHANGELOG.md +19 -0
  3. package/LICENSE +23 -0
  4. package/README.md +5 -0
  5. package/dist/index.d.ts +230 -0
  6. package/lib/PromptListbox.js +2 -0
  7. package/lib/PromptListbox.js.map +1 -0
  8. package/lib/components/PromptListbox/PromptListbox.js +14 -0
  9. package/lib/components/PromptListbox/PromptListbox.js.map +1 -0
  10. package/lib/components/PromptListbox/PromptListbox.types.js +2 -0
  11. package/lib/components/PromptListbox/PromptListbox.types.js.map +1 -0
  12. package/lib/components/PromptListbox/index.js +6 -0
  13. package/lib/components/PromptListbox/index.js.map +1 -0
  14. package/lib/components/PromptListbox/renderPromptListbox.js +20 -0
  15. package/lib/components/PromptListbox/renderPromptListbox.js.map +1 -0
  16. package/lib/components/PromptListbox/usePromptListbox.js +81 -0
  17. package/lib/components/PromptListbox/usePromptListbox.js.map +1 -0
  18. package/lib/components/PromptListbox/usePromptListboxContextValues.js +33 -0
  19. package/lib/components/PromptListbox/usePromptListboxContextValues.js.map +1 -0
  20. package/lib/components/PromptListbox/usePromptListboxStyles.styles.js +37 -0
  21. package/lib/components/PromptListbox/usePromptListboxStyles.styles.js.map +1 -0
  22. package/lib/components/utils/OptionCollection.types.js +3 -0
  23. package/lib/components/utils/OptionCollection.types.js.map +1 -0
  24. package/lib/components/utils/PromptListboxFunctionality.types.js +2 -0
  25. package/lib/components/utils/PromptListboxFunctionality.types.js.map +1 -0
  26. package/lib/components/utils/Selection.types.js +3 -0
  27. package/lib/components/utils/Selection.types.js.map +1 -0
  28. package/lib/components/utils/dropdownKeyActions.js +52 -0
  29. package/lib/components/utils/dropdownKeyActions.js.map +1 -0
  30. package/lib/components/utils/useComboboxPositioning.js +25 -0
  31. package/lib/components/utils/useComboboxPositioning.js.map +1 -0
  32. package/lib/components/utils/useOptionCollection.js +39 -0
  33. package/lib/components/utils/useOptionCollection.js.map +1 -0
  34. package/lib/components/utils/usePromptListboxFunctionality.js +143 -0
  35. package/lib/components/utils/usePromptListboxFunctionality.js.map +1 -0
  36. package/lib/components/utils/useSelection.js +54 -0
  37. package/lib/components/utils/useSelection.js.map +1 -0
  38. package/lib/components/utils/useTriggerKeyDown.js +129 -0
  39. package/lib/components/utils/useTriggerKeyDown.js.map +1 -0
  40. package/lib/index.js +4 -0
  41. package/lib/index.js.map +1 -0
  42. package/lib/plugins/TextCursorPositionPlugin.js +44 -0
  43. package/lib/plugins/TextCursorPositionPlugin.js.map +1 -0
  44. package/lib-commonjs/PromptListbox.js +7 -0
  45. package/lib-commonjs/PromptListbox.js.map +1 -0
  46. package/lib-commonjs/components/PromptListbox/PromptListbox.js +23 -0
  47. package/lib-commonjs/components/PromptListbox/PromptListbox.js.map +1 -0
  48. package/lib-commonjs/components/PromptListbox/PromptListbox.types.js +5 -0
  49. package/lib-commonjs/components/PromptListbox/PromptListbox.types.js.map +1 -0
  50. package/lib-commonjs/components/PromptListbox/index.js +11 -0
  51. package/lib-commonjs/components/PromptListbox/index.js.map +1 -0
  52. package/lib-commonjs/components/PromptListbox/renderPromptListbox.js +26 -0
  53. package/lib-commonjs/components/PromptListbox/renderPromptListbox.js.map +1 -0
  54. package/lib-commonjs/components/PromptListbox/usePromptListbox.js +68 -0
  55. package/lib-commonjs/components/PromptListbox/usePromptListbox.js.map +1 -0
  56. package/lib-commonjs/components/PromptListbox/usePromptListboxContextValues.js +36 -0
  57. package/lib-commonjs/components/PromptListbox/usePromptListboxContextValues.js.map +1 -0
  58. package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.js +71 -0
  59. package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.js.map +1 -0
  60. package/lib-commonjs/components/utils/OptionCollection.types.js +6 -0
  61. package/lib-commonjs/components/utils/OptionCollection.types.js.map +1 -0
  62. package/lib-commonjs/components/utils/PromptListboxFunctionality.types.js +5 -0
  63. package/lib-commonjs/components/utils/PromptListboxFunctionality.types.js.map +1 -0
  64. package/lib-commonjs/components/utils/Selection.types.js +6 -0
  65. package/lib-commonjs/components/utils/Selection.types.js.map +1 -0
  66. package/lib-commonjs/components/utils/dropdownKeyActions.js +52 -0
  67. package/lib-commonjs/components/utils/dropdownKeyActions.js.map +1 -0
  68. package/lib-commonjs/components/utils/useComboboxPositioning.js +32 -0
  69. package/lib-commonjs/components/utils/useComboboxPositioning.js.map +1 -0
  70. package/lib-commonjs/components/utils/useOptionCollection.js +46 -0
  71. package/lib-commonjs/components/utils/useOptionCollection.js.map +1 -0
  72. package/lib-commonjs/components/utils/usePromptListboxFunctionality.js +150 -0
  73. package/lib-commonjs/components/utils/usePromptListboxFunctionality.js.map +1 -0
  74. package/lib-commonjs/components/utils/useSelection.js +72 -0
  75. package/lib-commonjs/components/utils/useSelection.js.map +1 -0
  76. package/lib-commonjs/components/utils/useTriggerKeyDown.js +134 -0
  77. package/lib-commonjs/components/utils/useTriggerKeyDown.js.map +1 -0
  78. package/lib-commonjs/index.js +37 -0
  79. package/lib-commonjs/index.js.map +1 -0
  80. package/lib-commonjs/plugins/TextCursorPositionPlugin.js +52 -0
  81. package/lib-commonjs/plugins/TextCursorPositionPlugin.js.map +1 -0
  82. package/package.json +49 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["PromptListbox.types.ts"],"sourcesContent":["import type { ActiveDescendantContextValue } from '@fluentui/react-aria';\nimport type {\n ComboboxProps,\n ComponentProps,\n ComponentState,\n Listbox,\n ListboxContextValue,\n PortalProps,\n Slot,\n} from '@fluentui/react-components';\nimport type { PromptListboxContextState } from './usePromptListboxContextValues';\nimport type { OptionCollectionState } from '../utils/OptionCollection.types';\nimport type { SelectionState } from '../utils/Selection.types';\n\nexport type PromptListboxSlots = {\n root: Slot<typeof Listbox>;\n};\n\n/**\n * PromptListbox Props\n */\nexport type PromptListboxProps = ComponentProps<PromptListboxSlots> &\n Pick<PortalProps, 'mountNode'> &\n OptionCollectionState &\n SelectionState &\n Pick<PromptListboxContextState, 'activeDescendantController'> &\n Pick<ComboboxProps, 'onActiveOptionChange'> & {\n /**\n * Whether to listbox should be rendered.\n *\n * @default false\n */\n open?: boolean;\n /**\n * Whether to render the listbox inline or in a portal.\n *\n * @default false\n */\n inlinePopup?: boolean;\n };\n\n/**\n * State used in rendering PromptListbox\n */\nexport type PromptListboxState = ComponentState<PromptListboxSlots> &\n PromptListboxContextState &\n Required<Pick<PromptListboxProps, 'open' | 'inlinePopup'>> &\n Pick<PromptListboxProps, 'mountNode'>;\n\nexport type PromptListboxContextValues = {\n listbox: ListboxContextValue;\n activeDescendant: ActiveDescendantContextValue;\n};\n"],"names":[],"rangeMappings":"","mappings":""}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _export_star = require("@swc/helpers/_/_export_star");
6
+ _export_star._(require("./PromptListbox"), exports);
7
+ _export_star._(require("./PromptListbox.types"), exports);
8
+ _export_star._(require("./renderPromptListbox"), exports);
9
+ _export_star._(require("./usePromptListbox"), exports);
10
+ _export_star._(require("./usePromptListboxStyles.styles"), exports);
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './PromptListbox';\nexport * from './PromptListbox.types';\nexport * from './renderPromptListbox';\nexport * from './usePromptListbox';\nexport * from './usePromptListboxStyles.styles';\n"],"names":[],"rangeMappings":";;;;;;;;;","mappings":";;;;;uBAAc;uBACA;uBACA;uBACA;uBACA"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "renderPromptListbox_unstable", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return renderPromptListbox_unstable;
9
+ }
10
+ });
11
+ const _jsxruntime = require("@fluentui/react-jsx-runtime/jsx-runtime");
12
+ const _reactcomponents = require("@fluentui/react-components");
13
+ const _reactaria = require("@fluentui/react-aria");
14
+ const renderPromptListbox_unstable = (state, contextValues)=>{
15
+ (0, _reactcomponents.assertSlots)(state);
16
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactcomponents.ListboxProvider, {
17
+ value: contextValues.listbox,
18
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactaria.ActiveDescendantContextProvider, {
19
+ value: contextValues.activeDescendant,
20
+ children: state.open && (state.inlinePopup ? /*#__PURE__*/ (0, _jsxruntime.jsx)(state.root, {}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactcomponents.Portal, {
21
+ mountNode: state.mountNode,
22
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(state.root, {})
23
+ }))
24
+ })
25
+ });
26
+ }; //# sourceMappingURL=renderPromptListbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["renderPromptListbox.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\n\nimport { assertSlots, ListboxProvider, Portal } from '@fluentui/react-components';\nimport { ActiveDescendantContextProvider } from '@fluentui/react-aria';\nimport type { PromptListboxState, PromptListboxSlots, PromptListboxContextValues } from './PromptListbox.types';\n\n/**\n * Render the final JSX of PromptListbox\n */\nexport const renderPromptListbox_unstable = (state: PromptListboxState, contextValues: PromptListboxContextValues) => {\n assertSlots<PromptListboxSlots>(state);\n\n return (\n <ListboxProvider value={contextValues.listbox}>\n <ActiveDescendantContextProvider value={contextValues.activeDescendant}>\n {state.open &&\n (state.inlinePopup ? (\n <state.root />\n ) : (\n <Portal mountNode={state.mountNode}>\n <state.root />\n </Portal>\n ))}\n </ActiveDescendantContextProvider>\n </ListboxProvider>\n );\n};\n"],"names":["assertSlots","state","value","contextValues","listbox","inlinePopup","mountNode","_jsx","root","Portal"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAWEA;;;eAAAA;;;4BAXwB;iCAG2B;2BACL;AAO9CA,MAAAA,+BAAgCC,CAAAA,OAAAA;oCAEhC,EAAAA;WACmBC,WAAOC,GAAAA,IAAAA,eAAAA,EAAAA,gCAAqB,EAAA;6BAC3CC,OAAA;kBAAiCF,WAAOC,GAAAA,IAAAA,eAAAA,EAAAA,0CAA8B,EAAA;iCACnEF,gBACQI;sBAGGC,MAAAA,IAAAA,IAAWL,CAAAA,MAAMK,WAAS,GAAA,WAAA,GAAAC,IAAAA,eAAA,EAAAN,MAAAO,IAAA,EAAA,CAAA,KAAA,WAAA,GAAAD,IAAAA,eAAA,EAAAE,uBAAA,EAAA;0CAChC;0BAEJ,WAAA,GAAAF,IAAAA,eAAA,EAAAN,MAAAO,IAAA,EAAA,CAAA;;;IAIR"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "usePromptListbox_unstable", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return usePromptListbox_unstable;
9
+ }
10
+ });
11
+ const _reactcomponents = require("@fluentui/react-components");
12
+ const _reactutilities = require("@fluentui/react-utilities");
13
+ const usePromptListbox_unstable = (props, ref)=>{
14
+ const { id, onActiveOptionChange, inlinePopup = false, mountNode = undefined, open = true, activeDescendantController, getOptionById, getOptionsMatchingValue, selectedOptions, selectOption, registerOption } = props;
15
+ const listboxId = (0, _reactutilities.useId)('prompt-listbox', id);
16
+ const onActiveDescendantChange = (0, _reactutilities.useEventCallback)((event)=>{
17
+ const previousOption = event.detail.previousId ? getOptionById(event.detail.previousId) : null;
18
+ const nextOption = getOptionById(event.detail.id);
19
+ onActiveOptionChange === null || onActiveOptionChange === void 0 ? void 0 : onActiveOptionChange(event, {
20
+ event,
21
+ type: 'change',
22
+ previousOption,
23
+ nextOption
24
+ });
25
+ });
26
+ const state = {
27
+ ...deprecatedPropsDefaults,
28
+ open,
29
+ getOptionById,
30
+ getOptionsMatchingValue,
31
+ selectedOptions,
32
+ selectOption,
33
+ registerOption,
34
+ onActiveDescendantChange,
35
+ activeDescendantController,
36
+ inlinePopup,
37
+ mountNode,
38
+ components: {
39
+ root: _reactcomponents.Listbox
40
+ },
41
+ root: _reactcomponents.slot.always({
42
+ ...props,
43
+ selectedOptions
44
+ }, {
45
+ defaultProps: {
46
+ disableAutoFocus: true,
47
+ id: listboxId,
48
+ tabIndex: undefined
49
+ },
50
+ elementType: _reactcomponents.Listbox
51
+ })
52
+ };
53
+ state.root.ref = (0, _reactcomponents.useMergedRefs)(ref, state.root.ref);
54
+ state.root.onMouseDown = (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)((event)=>{
55
+ event.preventDefault();
56
+ }, state.root.onMouseDown));
57
+ state.root.onClick = (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)((event)=>{
58
+ event.preventDefault();
59
+ }, state.root.onClick));
60
+ return state;
61
+ };
62
+ const noop = ()=>null;
63
+ const deprecatedPropsDefaults = {
64
+ activeOption: undefined,
65
+ focusVisible: false,
66
+ setActiveOption: noop,
67
+ onOptionClick: noop
68
+ }; //# sourceMappingURL=usePromptListbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["usePromptListbox.ts"],"sourcesContent":["import { Listbox, slot, useMergedRefs } from '@fluentui/react-components';\nimport { mergeCallbacks, useEventCallback, useId } from '@fluentui/react-utilities';\nimport type * as React from 'react';\nimport type { PromptListboxProps, PromptListboxState } from './PromptListbox.types';\nimport type { PromptListboxContextState } from './usePromptListboxContextValues';\nimport type { ActiveDescendantChangeEvent } from '@fluentui/react-aria';\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 PromptListbox.\n *\n * The returned state can be modified with hooks such as usePromptListboxStyles_unstable,\n * before being passed to renderPromptListbox_unstable.\n *\n * @param props - props from this instance of PromptListbox\n * @param ref - reference to root HTMLElement of PromptListbox\n */\nexport const usePromptListbox_unstable = (\n props: PromptListboxProps,\n ref: React.Ref<HTMLDivElement>,\n): PromptListboxState => {\n const {\n id,\n onActiveOptionChange,\n inlinePopup = false,\n mountNode = undefined,\n open = true,\n activeDescendantController,\n getOptionById,\n getOptionsMatchingValue,\n selectedOptions,\n selectOption,\n registerOption,\n } = props;\n const listboxId = useId('prompt-listbox', id);\n\n const onActiveDescendantChange = useEventCallback((event: ActiveDescendantChangeEvent) => {\n const previousOption = event.detail.previousId ? getOptionById(event.detail.previousId) : null;\n const nextOption = getOptionById(event.detail.id);\n onActiveOptionChange?.(event, { event, type: 'change', previousOption, nextOption });\n });\n\n const state: PromptListboxState = {\n ...deprecatedPropsDefaults,\n open,\n getOptionById,\n getOptionsMatchingValue,\n selectedOptions,\n selectOption,\n registerOption,\n onActiveDescendantChange,\n activeDescendantController,\n inlinePopup,\n mountNode,\n\n components: {\n root: Listbox,\n },\n\n root: slot.always(\n { ...props, selectedOptions },\n {\n defaultProps: {\n disableAutoFocus: true,\n id: listboxId,\n tabIndex: undefined,\n },\n elementType: Listbox,\n },\n ),\n };\n\n state.root.ref = useMergedRefs(ref, state.root.ref);\n state.root.onMouseDown = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n event.preventDefault();\n }, state.root.onMouseDown),\n );\n\n state.root.onClick = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n event.preventDefault();\n }, state.root.onClick),\n );\n\n return state;\n};\n\nconst noop = () => null;\n\nconst deprecatedPropsDefaults: Pick<\n PromptListboxContextState,\n 'activeOption' | 'focusVisible' | 'setActiveOption' | 'onOptionClick'\n> = {\n activeOption: undefined,\n focusVisible: false,\n setActiveOption: noop,\n onOptionClick: noop,\n};\n"],"names":["id","inlinePopup","previousOption","nextOption","onActiveOptionChange","event","selectOption","registerOption","open","getOptionById","getOptionsMatchingValue","selectedOptions","onActiveDescendantChange","root","Listbox","state","onMouseDown","preventDefault","tabIndex","undefined","noop","deprecatedPropsDefaults","activeOption","setActiveOption","onOptionClick"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAuBIA;;;eAAAA;;;iCAvByC;gCACW;AAqBtD,MACEA,4BAEAC,CAAAA,OAAAA;UAUF,EAEAD,EAAA,sBACQE,gBACAC,KAAAA,cACNC,SAAAA,aAAgCC,4BAAa,eAAUH,yBAAgBC,iBAAW,EACpFG,YAAA,EAEAC,cAAkC;UAEhCC,YAAAA,IAAAA,qBAAAA,EAAAA,kBAAAA;UACAC,2BAAAA,IAAAA,gCAAAA,EAAAA,CAAAA;cACAC,iBAAAA,MAAAA,MAAAA,CAAAA,UAAAA,GAAAA,cAAAA,MAAAA,MAAAA,CAAAA,UAAAA,IAAAA;cACAC,aAAAA,cAAAA,MAAAA,MAAAA,CAAAA,EAAAA;iCACAL,QAAAA,yBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,qBAAAA,OAAAA;;kBAEAM;;;;;kBAMEC;kCACF;;;;;;;;;;;oBAWE;YAEJA,MAAAC,wBAAA;QAEAC;QACAA,MAAMF,qBAAI,CAACG,MAAAA,CAAAA;eAEPX,KAAMY;YACRN;QAGFI,GAAAA;0BAEUE;gBACLF,kBAAkB;gBAGvBf,IAAOe;gBACPG,UAAAC;YAEIC;YAEAC,aAAAA,wBAAAA;QAIJC;;UAEAC,IAAAA,CAAAA,GAAAA,GAAAA,IAAAA,8BAAiBH,EAAAA,KAAAA,MAAAA,IAAAA,CAAAA,GAAAA;UACjBI,IAAAA,CAAAA,WAAeJ,GAAAA,IAAAA,gCAAAA,EAAAA,IAAAA,8BAAAA,EAAAA,CAAAA;QACjBf,MAAAY,cAAA"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "usePromptListboxContextValues", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return usePromptListboxContextValues;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
+ function usePromptListboxContextValues(state) {
14
+ const { getOptionById, getOptionsMatchingValue, registerOption, selectedOptions, selectOption, activeDescendantController, onOptionClick, onActiveDescendantChange } = state;
15
+ const activeDescendant = _react.useMemo(()=>({
16
+ controller: activeDescendantController
17
+ }), [
18
+ activeDescendantController
19
+ ]);
20
+ const listbox = {
21
+ activeOption: undefined,
22
+ focusVisible: false,
23
+ getOptionById,
24
+ getOptionsMatchingValue,
25
+ registerOption,
26
+ selectedOptions,
27
+ selectOption,
28
+ setActiveOption: ()=>null,
29
+ onOptionClick,
30
+ onActiveDescendantChange
31
+ };
32
+ return {
33
+ activeDescendant,
34
+ listbox
35
+ };
36
+ } //# sourceMappingURL=usePromptListboxContextValues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["usePromptListboxContextValues.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComboboxBaseState, ComboboxState, ListboxContextValue } from '@fluentui/react-combobox';\nimport type { PromptListboxContextValues } from './PromptListbox.types';\n\nexport type PromptListboxContextState = Pick<ComboboxBaseState, keyof ListboxContextValue> &\n Pick<ComboboxState, 'activeDescendantController'>;\n\nexport function usePromptListboxContextValues(state: PromptListboxContextState): PromptListboxContextValues {\n const {\n getOptionById,\n getOptionsMatchingValue,\n registerOption,\n selectedOptions,\n selectOption,\n activeDescendantController,\n onOptionClick,\n onActiveDescendantChange,\n } = state;\n\n const activeDescendant = React.useMemo(\n () => ({\n controller: activeDescendantController,\n }),\n [activeDescendantController],\n );\n\n const listbox = {\n activeOption: undefined,\n focusVisible: false,\n getOptionById,\n getOptionsMatchingValue,\n registerOption,\n selectedOptions,\n selectOption,\n setActiveOption: () => null,\n onOptionClick,\n onActiveDescendantChange,\n };\n\n return {\n activeDescendant,\n listbox,\n };\n}\n"],"names":["usePromptListboxContextValues","state","getOptionById","activeDescendant","activeDescendantController","activeOption","getOptionsMatchingValue","registerOption","selectedOptions","selectOption","setActiveOption","onOptionClick"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAOgBA;;;eAAAA;;;;iEAPO;AAOhB,SAASA,8BAA8BC,KAAgC;UAC5E,EAWAC,aAAMC,yBAEUC,gBAEd,iBAACA,cAA2B,EAG9BA,0BAAgB,eACdC,0BACc;UAEdC,mBAAAA,OAAAA,OAAAA,CAAAA,IAAAA,CAAAA;wBACAC;;;KACAC;UACAC,UAAAA;sBACAC;sBACAC;;QAEFL;QAEAC;;;QAGAG,iBAAA,IAAA;QACFC"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ promptListboxClassNames: function() {
13
+ return promptListboxClassNames;
14
+ },
15
+ usePromptListboxStyles_unstable: function() {
16
+ return usePromptListboxStyles_unstable;
17
+ }
18
+ });
19
+ const _reactcomponents = require("@fluentui/react-components");
20
+ const promptListboxClassNames = {
21
+ root: 'fai-PromptListbox'
22
+ };
23
+ /**
24
+ * Styles for the root slot
25
+ */ const useStyles = (0, _reactcomponents.__styles)({
26
+ listbox: {
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
+ ],
44
+ Bxyxcbc: "fmmk62d",
45
+ B7ck84d: "f1ewtqcl"
46
+ },
47
+ listboxCollapsed: {
48
+ mc9l5x: "fjseox"
49
+ },
50
+ inlineListbox: {
51
+ Bj3rh1h: "f19g0ac"
52
+ }
53
+ }, {
54
+ d: [
55
+ ".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);}",
60
+ ".fmmk62d{max-height:80vh;}",
61
+ ".f1ewtqcl{box-sizing:border-box;}",
62
+ ".fjseox{display:none;}",
63
+ ".f19g0ac{z-index:1;}"
64
+ ]
65
+ });
66
+ const usePromptListboxStyles_unstable = (state)=>{
67
+ 'use no memo';
68
+ const styles = useStyles();
69
+ state.root.className = (0, _reactcomponents.mergeClasses)(promptListboxClassNames.root, styles.listbox, state.inlinePopup && styles.inlineListbox, !state.open && styles.listboxCollapsed, state.root.className);
70
+ return state;
71
+ }; //# sourceMappingURL=usePromptListboxStyles.styles.js.map
@@ -0,0 +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"}
@@ -0,0 +1,6 @@
1
+ // Brought from Fluent UI
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=OptionCollection.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["OptionCollection.types.ts"],"sourcesContent":["// Brought from Fluent UI\n\nexport type OptionValue = {\n /** The disabled state of the option. */\n disabled?: boolean;\n\n /** The `id` attribute of the option. */\n id: string;\n\n /** The `text` string for the option. */\n text: string;\n\n /** The value string of the option. */\n value: string;\n};\n\nexport type OptionCollectionState = {\n /** The total number of options in the collection. */\n getCount: () => number;\n\n /** Returns the option data by key. */\n getOptionById(id: string): OptionValue | undefined;\n\n /** Returns an array of options filtered by a value matching function against the option's value string. */\n getOptionsMatchingValue(matcher: (value: string) => boolean): OptionValue[];\n\n /** The unordered option data. */\n options: OptionValue[];\n\n /** A function that child options call to register their values. Returns a function to unregister the option. */\n registerOption: (option: OptionValue, element: HTMLElement) => () => void;\n};\n"],"names":[],"rangeMappings":"","mappings":"AAAA,yBAAyB"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ //# sourceMappingURL=PromptListboxFunctionality.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["PromptListboxFunctionality.types.ts"],"sourcesContent":["import type React from 'react';\nimport type { PromptListboxProps } from '../../components/PromptListbox';\nimport type { PositioningShorthand } from '@fluentui/react-components';\nimport type { EventData, EventHandler } from '@fluentui/react-utilities';\nimport type { EditorInputProps } from '@fluentui-copilot/react-editor-input';\n\n// Note: While we are removing multiselect, we are keeping the logic and disabling it\n// in case it's needed in the future.\nexport type ProcessedPromptListboxProps = Partial<\n Omit<PromptListboxProps, 'activeDescendantController' | 'multiselect'>\n> & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ref?: React.MutableRefObject<any>;\n};\n\nexport type UsePromptListboxFunctionality = {\n /**\n * Component to be rendered in the Input component. This should be passed to the listbox prop.\n */\n promptListbox: JSX.Element;\n /**\n * Props to be spread in the PromptInput, these props are needed for the keyboard behavior to\n * work correctly.\n */\n triggerProps: {\n ref: React.RefObject<HTMLSpanElement>;\n /**\n * Whether the listbox is being used to go through options or the user is currently typing.\n */\n isInSelectionMode: boolean;\n } & Required<Pick<EditorInputProps, 'onBlur' | 'onFocus' | 'onKeyDown'>>;\n /**\n * Ref used to point which element the listbox should be anchored to. Most use cases\n * will provide this prop to the PromptInput's EditorInput (since this is the root slot,\n * this is provided directly to the component and not the slot).\n *\n * Note: If the targetRef is the same as the trigger, the ref provided in triggerProps needs\n * to be merged with this one using `useMergedRefs(targetRef, triggerProps.ref);`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n targetRef: React.MutableRefObject<any>;\n /**\n * Plugin used to tell where the cursor is in the EditorInput, this is important for the\n * keyboard behavior. This should be passed as children in the PromptInput.\n */\n cursorPositionPlugin: JSX.Element;\n};\n\nexport type UsePromptListboxFunctionalityParams = {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: EventHandler<OnOpenChangeData>;\n onSelectionModeChange?: (isInSelectionMode: boolean) => void;\n positioning?: PositioningShorthand;\n /**\n * Props to be passed to the ListboxComponent\n */\n listboxProps?: ProcessedPromptListboxProps;\n};\n\nexport type OnOpenChangeData = (\n | EventData<'click', React.MouseEvent<HTMLSpanElement>>\n | EventData<'focus', React.FocusEvent<HTMLSpanElement>>\n | EventData<'keyboard', React.KeyboardEvent<HTMLSpanElement>>\n) & {\n open: boolean;\n};\n"],"names":[],"rangeMappings":"","mappings":""}
@@ -0,0 +1,6 @@
1
+ // Brought from Fluent UI
2
+ /** Possible event types for onOptionSelect */ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=Selection.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["Selection.types.ts"],"sourcesContent":["// Brought from Fluent UI\n\nimport type * as React from 'react';\nimport type { OptionValue } from './OptionCollection.types';\n\nexport type SelectionProps = {\n /**\n * For an uncontrolled component, sets the initial selection.\n * If this is set, the `defaultValue` prop MUST also be set.\n */\n defaultSelectedOptions?: string[];\n\n /**\n * Sets the selection type to multiselect.\n * Set this to true for multiselect, even if fully controlling selection state.\n * This enables styles and accessibility properties to be set.\n * @default false\n */\n multiselect?: boolean;\n\n /** Callback when an option is selected */\n onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void;\n\n /**\n * An array of selected option keys.\n * Use this with `onOptionSelect` to directly control the selected option(s)\n * If this is set, the `value` prop MUST also be controlled.\n */\n selectedOptions?: string[];\n};\n\n/** Values returned by the useSelection hook */\nexport type SelectionState = {\n clearSelection: (event: SelectionEvents) => void;\n selectedOptions: string[];\n selectOption: (event: SelectionEvents, option: OptionValue) => void;\n};\n\n/**\n * Data for the onOptionSelect callback.\n * `optionValue` and `optionText` will be undefined if multiple options are modified at once.\n */\nexport type OptionOnSelectData = {\n optionValue: string | undefined;\n optionText: string | undefined;\n selectedOptions: string[];\n};\n\n/** Possible event types for onOptionSelect */\nexport type SelectionEvents =\n | React.ChangeEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement>;\n"],"names":[],"rangeMappings":";","mappings":"AAAA,yBAAyB;AAgDzB,4CAA4C"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Note, this is mainly brought from Fluent UI, only removed the closing and
3
+ * opening logic since that's not needed for this use case.
4
+ */ "use strict";
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ Object.defineProperty(exports, "getDropdownActionFromKey", {
9
+ enumerable: true,
10
+ get: function() {
11
+ return getDropdownActionFromKey;
12
+ }
13
+ });
14
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
15
+ const _keyboardkeys = /*#__PURE__*/ _interop_require_wildcard._(require("@fluentui/keyboard-keys"));
16
+ function getDropdownActionFromKey(e, options) {
17
+ const { isInLastPosition } = options;
18
+ const code = e.key;
19
+ const { altKey, ctrlKey, key, metaKey } = e;
20
+ // typing action occurs whether open or closed
21
+ if (key.length === 1 && code !== _keyboardkeys.Space && !altKey && !ctrlKey && !metaKey) {
22
+ return 'Type';
23
+ }
24
+ // select or close actions
25
+ if (code === _keyboardkeys.ArrowUp && altKey || code === _keyboardkeys.Enter) {
26
+ return 'CloseSelect';
27
+ }
28
+ // navigation interactions
29
+ if (code === _keyboardkeys.ArrowDown) {
30
+ return isInLastPosition ? 'Next' : 'Type';
31
+ }
32
+ if (code === _keyboardkeys.ArrowUp) {
33
+ return isInLastPosition ? 'Previous' : 'Type';
34
+ }
35
+ if (code === _keyboardkeys.Home) {
36
+ return 'First';
37
+ }
38
+ if (code === _keyboardkeys.End) {
39
+ return 'Last';
40
+ }
41
+ if (code === _keyboardkeys.PageUp) {
42
+ return 'PageUp';
43
+ }
44
+ if (code === _keyboardkeys.PageDown) {
45
+ return 'PageDown';
46
+ }
47
+ if (code === _keyboardkeys.Tab) {
48
+ return 'Tab';
49
+ }
50
+ // if nothing matched, return none
51
+ return 'None';
52
+ } //# sourceMappingURL=dropdownKeyActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["dropdownKeyActions.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.\n */\n\nimport * as keys from '@fluentui/keyboard-keys';\nimport type * as React from 'react';\n\n/**\n * enum of actions available in any type of managed dropdown control\n * e.g. combobox, select, datepicker, menu\n */\nexport type DropdownActions =\n | 'CloseSelect'\n | 'First'\n | 'Last'\n | 'Next'\n | 'None'\n | 'PageDown'\n | 'PageUp'\n | 'Previous'\n | 'Select'\n | 'Tab'\n | 'Type';\n\nexport interface DropdownActionOptions {\n open?: boolean;\n multiselect?: boolean;\n isInLastPosition: boolean;\n}\n\n/**\n * Converts a keyboard interaction into a defined action\n */\nexport function getDropdownActionFromKey(\n e: KeyboardEvent | React.KeyboardEvent,\n options: DropdownActionOptions,\n): DropdownActions {\n const { isInLastPosition } = options;\n const code = e.key;\n const { altKey, ctrlKey, key, metaKey } = e;\n\n // typing action occurs whether open or closed\n if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {\n return 'Type';\n }\n\n // select or close actions\n if ((code === keys.ArrowUp && altKey) || code === keys.Enter) {\n return 'CloseSelect';\n }\n\n // navigation interactions\n if (code === keys.ArrowDown) {\n return isInLastPosition ? 'Next' : 'Type';\n }\n if (code === keys.ArrowUp) {\n return isInLastPosition ? 'Previous' : 'Type';\n }\n if (code === keys.Home) {\n return 'First';\n }\n if (code === keys.End) {\n return 'Last';\n }\n if (code === keys.PageUp) {\n return 'PageUp';\n }\n if (code === keys.PageDown) {\n return 'PageDown';\n }\n if (code === keys.Tab) {\n return 'Tab';\n }\n\n // if nothing matched, return none\n return 'None';\n}\n"],"names":["isInLastPosition","keys","options","ctrlKey","key","length","altKey","e","code","ArrowDown","Space","metaKey","ArrowUp","Enter","Home","End","PageUp","PageDown"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;;CAGC;;;;+BAmCSA;;;eAAAA;;;;wEAjCEC;AAiCV,SAAQD,yBAAqBE,CAAAA,EAAAA,OAAAA;UAC7B,EACAF,gBAAgBG,KAEhBD;UACIE,OAAIC,EAAAA,GAAM;UACZ,EACFC,MAAA,EAEAH,OAAA,EACAC,GAAA,SACE,KACFG;kDAE0B;QAC1BH,IAAII,MAAAA,KAASP,KAAKQ,SAAWR,cAAAS,KAAA,IAAA,CAAAJ,UAAA,CAAAH,WAAA,CAAAQ,SAAA;eAC3B;;8BAEgBC;iBACTZ,cAAAA,OAAAA,IAAAA,UAAmBQ,SAAaP,cAAAY,KAAA,EAAA;QACzC,OAAA;;8BAES;QACTL,SAAAP,cAAAQ,SAAA,EAAA;QACA,OAAID,mBAAmB,SAAA;;QAEvBA,SAAAP,cAAAW,OAAA,EAAA;QACA,OAAIJ,mBAAsB,aAAA;;QAE1BA,SAAAP,cAAAa,IAAA,EAAA;QACA,OAAIN;;QAEJA,SAAAP,cAAAc,GAAA,EAAA;QACA,OAAIP;;QAEJA,SAAAP,cAAAe,MAAA,EAAA;QAEA,OAAA;;IAEF,IAAAR,SAAAP,cAAAgB,QAAA,EAAA"}
@@ -0,0 +1,32 @@
1
+ // Brought from Fluent UI
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "useComboboxPositioning", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return useComboboxPositioning;
10
+ }
11
+ });
12
+ const _reactpositioning = require("@fluentui/react-positioning");
13
+ function useComboboxPositioning(props) {
14
+ const { positioning } = props;
15
+ // popper options
16
+ const popperOptions = {
17
+ position: 'below',
18
+ align: 'start',
19
+ offset: {
20
+ crossAxis: 0,
21
+ mainAxis: 2
22
+ },
23
+ fallbackPositions: [],
24
+ matchTargetSize: 'width',
25
+ ...(0, _reactpositioning.resolvePositioningShorthand)(positioning)
26
+ };
27
+ const { targetRef, containerRef } = (0, _reactpositioning.usePositioning)(popperOptions);
28
+ return [
29
+ containerRef,
30
+ targetRef
31
+ ];
32
+ } //# sourceMappingURL=useComboboxPositioning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useComboboxPositioning.ts"],"sourcesContent":["// Brought from Fluent UI\n\nimport { resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport type * as React from 'react';\nimport type { ComboboxBaseProps } from '@fluentui/react-combobox';\n\nexport function useComboboxPositioning(props: ComboboxBaseProps): [\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n listboxRef: React.MutableRefObject<any>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n triggerRef: React.MutableRefObject<any>,\n] {\n const { positioning } = props;\n\n // popper options\n const popperOptions = {\n position: 'below' as const,\n align: 'start' as const,\n offset: { crossAxis: 0, mainAxis: 2 },\n fallbackPositions: [],\n matchTargetSize: 'width' as const,\n ...resolvePositioningShorthand(positioning),\n };\n\n const { targetRef, containerRef } = usePositioning(popperOptions);\n\n return [containerRef, targetRef];\n}\n"],"names":["useComboboxPositioning","props","positioning","align","offset","mainAxis","fallbackPositions","resolvePositioningShorthand","matchTargetSize","containerRef","usePositioning","targetRef","popperOptions"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yBAAyB;;;;;+BAMTA;;;eAAAA;;;kCAJ4C;AAIrD,SAASA,uBAAuBC,KAAwB;UAM7D,EAEAC,WAAA,KACAD;qBACY;UACVE,gBAAO;kBACPC;;gBAAwBC;uBAAY;sBACpCC;;2BAEGC,EAAAA;QACLC,iBAAA;QAEA,GAAAD,IAAAA,6CAAmBE,EAAYP,YAAKQ;;UAE5BD,WAAcE,cAAU,EAClC,GAAAD,IAAAA,gCAAA,EAAAE"}
@@ -0,0 +1,46 @@
1
+ // Brought from Fluent UI
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "useOptionCollection", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return useOptionCollection;
10
+ }
11
+ });
12
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
13
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
14
+ const useOptionCollection = ()=>{
15
+ const optionsById = _react.useRef(new Map());
16
+ const collectionAPI = _react.useMemo(()=>{
17
+ const getCount = ()=>optionsById.current.size;
18
+ // index searches are no longer used
19
+ const getOptionById = (id)=>{
20
+ return optionsById.current.get(id);
21
+ };
22
+ const getOptionsMatchingValue = (matcher)=>{
23
+ const matches = [];
24
+ for (const option of optionsById.current.values()){
25
+ if (matcher(option.value)) {
26
+ matches.push(option);
27
+ }
28
+ }
29
+ return matches;
30
+ };
31
+ return {
32
+ getCount,
33
+ getOptionById,
34
+ getOptionsMatchingValue
35
+ };
36
+ }, []);
37
+ const registerOption = _react.useCallback((option)=>{
38
+ optionsById.current.set(option.id, option);
39
+ return ()=>optionsById.current.delete(option.id);
40
+ }, []);
41
+ return {
42
+ ...collectionAPI,
43
+ options: Array.from(optionsById.current.values()),
44
+ registerOption
45
+ };
46
+ }; //# sourceMappingURL=useOptionCollection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useOptionCollection.ts"],"sourcesContent":["// Brought from Fluent UI\n\nimport * as React from 'react';\nimport type { OptionCollectionState, OptionValue } from './OptionCollection.types';\n\n/**\n * A hook for managing a collection of child Options\n */\nexport const useOptionCollection = (): OptionCollectionState => {\n const optionsById = React.useRef(new Map<string, OptionValue>());\n\n const collectionAPI = React.useMemo(() => {\n const getCount = () => optionsById.current.size;\n\n // index searches are no longer used\n\n const getOptionById = (id: string) => {\n return optionsById.current.get(id);\n };\n\n const getOptionsMatchingValue = (matcher: (value: string) => boolean) => {\n const matches: OptionValue[] = [];\n for (const option of optionsById.current.values()) {\n if (matcher(option.value)) {\n matches.push(option);\n }\n }\n\n return matches;\n };\n\n return {\n getCount,\n getOptionById,\n getOptionsMatchingValue,\n };\n }, []);\n\n const registerOption = React.useCallback((option: OptionValue) => {\n optionsById.current.set(option.id, option);\n\n return () => optionsById.current.delete(option.id);\n }, []);\n\n return {\n ...collectionAPI,\n options: Array.from(optionsById.current.values()),\n registerOption,\n };\n};\n"],"names":["optionsById","useRef","collectionAPI","React","useMemo","Map","getCount","current","size","id","get","matcher","matches","option","value","values","push","useCallback","delete","Array","registerOption"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yBAAyB;;;;;+BASjBA;;;eAAAA;;;;iEAPe;AAOrB,MAAMA,sBAAoBC;UAE1BD,cAAME,OAAgBC,MAAMC,CAAAA,IAAOC;UACjCH,gBAAMI,OAAiBN,OAAAA,CAAAA;cAEvBM,WAAA,IAAAN,YAAAO,OAAoC,CAAAC,IAAA;4CAEbC;8BACdT,CAAAA;mBACTA,YAAAO,OAAA,CAAAG,GAAA,CAAAD;;wCAGmCE,CAAAA;kBACjCC,UAAK,EAAMC;uBACTA,UAAIF,YAAeG,OAAQ,CAAAC,MAAA,GAAA;4BACzBH,OAAAA,KAAY,GAACC;4BACfG,IAAA,CAAAH;;;mBAIJD;;;;;;QAOF;OAEA,EAAA;UACEZ,iBAAYO,OAAWU,WAAU,CAAEJ,CAAAA;oBAE5BN,OAAMP,CAAAA,GAAAA,CAAAA,OAAYO,EAAAA,EAAQW;QACnC,OAAK,IAAAlB,YAAAO,OAAA,CAAAW,MAAA,CAAAL,OAAAJ,EAAA;OAEL,EAAA;WACE;wBACSU;iBACTC,MAAAA,IAAAA,CAAAA,YAAAA,OAAAA,CAAAA,MAAAA;QACFA;IACA"}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "usePromptListboxFunctionality", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return usePromptListboxFunctionality;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
+ const _reactaria = require("@fluentui/react-aria");
14
+ const _reactcomponents = require("@fluentui/react-components");
15
+ const _reactutilities = require("@fluentui/react-utilities");
16
+ const _dropdownKeyActions = require("./dropdownKeyActions");
17
+ const _TextCursorPositionPlugin = require("../../plugins/TextCursorPositionPlugin");
18
+ const _useOptionCollection = require("./useOptionCollection");
19
+ const _useSelection = require("./useSelection");
20
+ const _keyboardkeys = require("@fluentui/keyboard-keys");
21
+ const _useComboboxPositioning = require("./useComboboxPositioning");
22
+ const _useTriggerKeyDown = require("./useTriggerKeyDown");
23
+ const _PromptListbox = require("../PromptListbox");
24
+ function usePromptListboxFunctionality(params) {
25
+ const { positioning, onOpenChange, onSelectionModeChange, listboxProps } = params;
26
+ const { listboxRef: activeDescendantListboxRef, activeParentRef, controller: activeDescendantController } = (0, _reactaria.useActiveDescendant)({
27
+ matchOption: (el)=>el.classList.contains(_reactcomponents.optionClassNames.root)
28
+ });
29
+ // useMergedRefs to normalize the ref into a React.RefObject type
30
+ const triggerRef = (0, _reactutilities.useMergedRefs)(activeParentRef);
31
+ const selectionState = (0, _useSelection.useSelection)(listboxProps !== null && listboxProps !== void 0 ? listboxProps : {});
32
+ const { selectOption } = selectionState;
33
+ const optionCollection = (0, _useOptionCollection.useOptionCollection)();
34
+ const { getOptionById } = optionCollection;
35
+ const [isInLastPosition, setIsInLastPosition] = _react.useState(true);
36
+ const [isInSelectionMode, setIsInSelectionMode] = _react.useState(false);
37
+ const [open, setOpen] = (0, _reactutilities.useControllableState)({
38
+ state: params.open,
39
+ defaultState: params.defaultOpen,
40
+ initialState: false
41
+ });
42
+ const onBlur = (event)=>{
43
+ setOpen(false);
44
+ onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
45
+ event,
46
+ type: 'focus',
47
+ open: false
48
+ });
49
+ };
50
+ const onFocus = (event)=>{
51
+ if (event.target === event.currentTarget) {
52
+ setOpen(true);
53
+ onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
54
+ event,
55
+ type: 'focus',
56
+ open: true
57
+ });
58
+ }
59
+ };
60
+ const cursorPositionPlugin = /*#__PURE__*/ _react.createElement(_TextCursorPositionPlugin.TextCursorPositionPlugin, {
61
+ setIsInLastPosition: setIsInLastPosition
62
+ });
63
+ const onListboxBlur = _react.useCallback(()=>{
64
+ setIsInSelectionMode(false);
65
+ onSelectionModeChange === null || onSelectionModeChange === void 0 ? void 0 : onSelectionModeChange(false);
66
+ }, [
67
+ onSelectionModeChange
68
+ ]);
69
+ // handle combobox keyboard interaction
70
+ const onKeyDown = (0, _useTriggerKeyDown.useTriggerKeydown)({
71
+ ...optionCollection,
72
+ activeDescendantController,
73
+ getOptionById,
74
+ onBlur: onListboxBlur,
75
+ selectOption,
76
+ isInLastPosition,
77
+ open,
78
+ multiselect: false
79
+ });
80
+ // NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set
81
+ // To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows
82
+ // ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888
83
+ const [hideActiveDescendant, setHideActiveDescendant] = _react.useState(false);
84
+ /**
85
+ * Freeform combobox should not select
86
+ */ const onInputTriggerKeyDown = (0, _reactutilities.useEventCallback)((event)=>{
87
+ // update typing state to true if the user is typing
88
+ const action = (0, _dropdownKeyActions.getDropdownActionFromKey)(event, {
89
+ open,
90
+ multiselect: false,
91
+ isInLastPosition
92
+ });
93
+ if (event.key === _keyboardkeys.ArrowLeft || event.key === _keyboardkeys.ArrowRight || !isInLastPosition && (event.key === _keyboardkeys.ArrowDown || event.key === _keyboardkeys.ArrowUp) || action === 'Type' && isInLastPosition || action === 'Type') {
94
+ activeDescendantController.blur();
95
+ setHideActiveDescendant(true);
96
+ setIsInSelectionMode(false);
97
+ onSelectionModeChange === null || onSelectionModeChange === void 0 ? void 0 : onSelectionModeChange(false);
98
+ } else if (action === 'Next' || action === 'Previous' || action === 'First' || action === 'Last' || action === 'PageUp' || action === 'PageDown') {
99
+ setHideActiveDescendant(false);
100
+ setIsInSelectionMode(true);
101
+ onSelectionModeChange === null || onSelectionModeChange === void 0 ? void 0 : onSelectionModeChange(true);
102
+ }
103
+ });
104
+ _react.useEffect(()=>{
105
+ if (hideActiveDescendant) {
106
+ var _triggerRef_current;
107
+ (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.removeAttribute('aria-activedescendant');
108
+ }
109
+ // We only want to run this when the hideActiveDescendant changes, if the triggerRef
110
+ // is undefined, there's no need to remove theAttribute and we shouldn't be adding
111
+ // refs as dependencies since it can blow up the number of runs.
112
+ // eslint-disable-next-line react-compiler/react-compiler
113
+ // eslint-disable-next-line react-hooks/exhaustive-deps
114
+ }, [
115
+ hideActiveDescendant
116
+ ]);
117
+ const [comboboxPopupRef, comboboxTargetRef] = (0, _useComboboxPositioning.useComboboxPositioning)({
118
+ positioning
119
+ });
120
+ const listboxMergedRef = (0, _reactutilities.useMergedRefs)(comboboxPopupRef, activeDescendantListboxRef, listboxProps === null || listboxProps === void 0 ? void 0 : listboxProps.ref);
121
+ const listbox = _react.useMemo(()=>{
122
+ return /*#__PURE__*/ _react.createElement(_PromptListbox.PromptListbox, {
123
+ open: open,
124
+ ...listboxProps,
125
+ ...optionCollection,
126
+ ...selectionState,
127
+ ref: listboxMergedRef,
128
+ activeDescendantController: activeDescendantController
129
+ });
130
+ }, [
131
+ activeDescendantController,
132
+ listboxMergedRef,
133
+ listboxProps,
134
+ open,
135
+ optionCollection,
136
+ selectionState
137
+ ]);
138
+ return {
139
+ promptListbox: listbox,
140
+ triggerProps: {
141
+ ref: triggerRef,
142
+ onBlur,
143
+ onFocus,
144
+ onKeyDown: (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)(onKeyDown, onInputTriggerKeyDown)),
145
+ isInSelectionMode
146
+ },
147
+ targetRef: comboboxTargetRef,
148
+ cursorPositionPlugin
149
+ };
150
+ } //# sourceMappingURL=usePromptListboxFunctionality.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["usePromptListboxFunctionality.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useActiveDescendant } from '@fluentui/react-aria';\nimport { optionClassNames } from '@fluentui/react-components';\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 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 } = params;\n const {\n listboxRef: activeDescendantListboxRef,\n activeParentRef,\n controller: activeDescendantController,\n } = useActiveDescendant<HTMLSpanElement, HTMLDivElement>({\n matchOption: el => el.classList.contains(optionClassNames.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 });\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 targetRef: comboboxTargetRef,\n cursorPositionPlugin,\n };\n}\n"],"names":["usePromptListboxFunctionality","params","positioning","listboxRef","matchOption","onSelectionModeChange","listboxProps","selectOption","selectionState","activeParentRef","optionCollection","controller","getOptionById","useActiveDescendant","isInLastPosition","isInSelectionMode","setIsInSelectionMode","useState","defaultState","defaultOpen","initialState","useSelection","onBlur","onOpenChange","type","setIsInLastPosition","React","open","onFocus","event","target","setOpen","cursorPositionPlugin","onListboxBlur","currentTarget","onKeyDown","useTriggerKeydown","activeDescendantController","onInputTriggerKeyDown","useEventCallback","action","hideActiveDescendant","key","ArrowRight","ArrowDown","ArrowUp","triggerRef","setHideActiveDescendant","useEffect","comboboxTargetRef","_triggerRef_current","current","removeAttribute","PromptListbox","listboxMergedRef","useMergedRefs","comboboxPopupRef","activeDescendantListboxRef","ref","targetRef"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAkBgBA;;;eAAAA;;;;iEAlBO;2BACa;iCACH;gCACqD;oCAC7C;0CACA;qCACL;8BACP;8BAC6B;wCACnB;mCACL;+BACJ;AAOvB,SAASA,8BACdC,MAA2C;UAE3C,EACAC,WACEC,cAIAC,EACFC,qBAAA,EACAC,YAAA,KACAL;UACA,EACAE,YAAQI,0BAAiBC,EACzBC,eAAMC,EACNC,YAAQC,0BAAkBF,KAC1BG,IAAAA,8BAAOC,EAAAA;QACPV,aAAOW,CAAAA,KAAAA,GAAAA,SAAmBC,CAAAA,QAAAA,CAAAA,iCAA8BC,CAAAA,IAAAA;;qEAEpC;UAClBC,aAAAA,IAAAA,6BAAqBC,EAAAA;UACrBC,iBAAcC,IAAAA,0BAAA,EAAAf,iBAAA,QAAAA,iBAAA,KAAA,IAAAA,eAAA,CAAA;UAChB,EAEAC,YAAMe;UAEJC,mBAAAA,IAAAA,wCAAAA;yBAA+BC;UAA2B,CAAAV,kBAAAW,oBAAA,GAAAC,OAAAT,QAAA,CAAA;UAC5D,CAAAF,mBAAAC,qBAAA,GAAAU,OAAAT,QAAA,CAAA;UAEA,CAAAU,MAAMC,QAAWC,GAAAA,IAAAA,oCAAAA,EAAAA;eACf5B,OAAU6B,IAAAA;sBACRC,OAAQZ,WAAA;sBACRI;;mBAA+BC,CAAAA;;yBAA0B,QAAAD,iBAAA,KAAA,IAAA,KAAA,IAAAA,aAAAM,OAAA;;YAE7DL,MAAA;YAEAG,MAAMK;;;UAENJ,UAAMK,CAAAA;YACJjB,MAAAA,MAAAA,KAAAA,MAAqBkB,aAAA,EAAA;oBACrB7B;YACFkB,iBAAG,QAAAA,iBAAA,KAAA,IAAA,KAAA,IAAAA,aAAAM,OAAA;gBAACxB;gBAAsBmB,MAAA;gBAE1BG,MAAA;YACA;;;UAGEf,uBAAAA,WAAAA,GAAAA,OAAAA,aAAAA,CAAAA,kDAAAA,EAAAA;6BACQqB;;UAERnB,gBAAAA,OAAAA,WAAAA,CAAAA;6BACAa;kCACa,QAAAtB,0BAAA,KAAA,IAAA,KAAA,IAAAA,sBAAA;OACf;QAAAA;KAAA;2CAEA;UACA8B,YAAAC,IAAAA,oCAAA,EAAA;QACA,GAAA1B,gBAAA;QACA2B;QAEAzB;;QAECL;;;qBAGkDoB;;2GAA0Bb;8GAAiB;sFAIxFA;iCAIFuB,wBAA+B,GAAAX,OAAAT,QAAA,CAAA;;;WAIjCqB,wBACaC,IAAAA,gCACXC,EAAAA,CAAAA;4DAMwB;uBACxBxB,IAAAA,4CAAqB,EAAAa,OAAA;;yBAEvB;YACFf;QAEAY;YACEG,MAAIY,GAAAA,KAAAA,uBAAAA,IAAsBZ,MAAAa,GAAA,KAAAC,wBAAA,IAAA,CAAA7B,oBAAAe,CAAAA,MAAAa,GAAA,KAAAE,uBAAA,IAAAf,MAAAa,GAAA,KAAAG,qBAAA,KAAAL,WAAA,UAAA1B,oBAAA0B,WAAA,QAAA;uCACxBM,IAAAA;oCAAAA;iCACF;YACAzC,0BAAA,QAAAA,0BAAA,KAAA,IAAA,KAAA,IAAAA,sBAAoF;QACpF,OAAA,IAAAmC,WAAA,UAAAA,WAAA,cAAAA,WAAA,WAAAA,WAAkF,UAAAA,WAAA,YAAAA,WAAA,YAAA;YAClFO,wBAAA;YACA/B,qBAAA;YACAX,0BAAA,QAAAA,0BAAuD,KAAA,IAAA,KAAA,IAAAA,sBAAA;QACzD;;WAAyB2C,SAAA,CAAA;QAEzB,IAAAP,sBAAyBQ;gBAA8C/C;YAAYgD,CAAAA,sBAAAJ,WAAAK,OAAA,MAAA,QAAAD,wBAAA,KAAA,IAAA,KAAA,IAAAA,oBAAAE,eAAA,CAAA;QAEnF;IACA,oFAA8B;sFAEzBC;oEACO1B;6DACU;2DACI;;;KAChBnB;6BACC8C,kBAAAA,GAAAA,IAAAA,8CAAAA,EAAAA;;;UAIRA,mBAAAC,IAAAA,6BAAA,EAAAC,kBAAAC,4BAAAnD,iBAAA,QAAAA,iBAAA,KAAA,IAAA,KAAA,IAAAA,aAAAoD,GAAA;UAACrB,UAAAA,OAAAA,OAAAA,CAAAA;eAA4BiB,WAAAA,GAAAA,OAAAA,aAAAA,CAAAA,4BAAAA,EAAAA;kBAAkBhD;eAAcqB,YAAAA;eAAMjB,gBAAAA;eAAkBF,cAAAA;YAAekD,KAAAJ;YAEvGjB,4BAAOA;;;;QAESiB;QAAAhD;QAAAqB;QAAAjB;QAAAF;KAAA;;uBAEZc;sBACAM;;;;uBAIF+B,IAAAA,gCAAWV,EAAAA,IAAAA,8BAAAA,EAAAA,WAAAA;;QAEb;QACFU,WAAAV"}