@fluentui/react-combobox 9.7.5 → 9.9.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 (90) hide show
  1. package/CHANGELOG.md +44 -5
  2. package/dist/index.d.ts +79 -14
  3. package/lib/components/Combobox/Combobox.types.js.map +1 -1
  4. package/lib/components/Combobox/renderCombobox.js +19 -11
  5. package/lib/components/Combobox/renderCombobox.js.map +1 -1
  6. package/lib/components/Combobox/useCombobox.js +12 -4
  7. package/lib/components/Combobox/useCombobox.js.map +1 -1
  8. package/lib/components/Combobox/useInputTriggerSlot.js +14 -12
  9. package/lib/components/Combobox/useInputTriggerSlot.js.map +1 -1
  10. package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
  11. package/lib/components/Dropdown/renderDropdown.js +21 -13
  12. package/lib/components/Dropdown/renderDropdown.js.map +1 -1
  13. package/lib/components/Dropdown/useButtonTriggerSlot.js +51 -31
  14. package/lib/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
  15. package/lib/components/Dropdown/useDropdown.js +14 -4
  16. package/lib/components/Dropdown/useDropdown.js.map +1 -1
  17. package/lib/components/Listbox/Listbox.types.js.map +1 -1
  18. package/lib/components/Listbox/renderListbox.js +7 -3
  19. package/lib/components/Listbox/renderListbox.js.map +1 -1
  20. package/lib/components/Listbox/useListbox.js +52 -44
  21. package/lib/components/Listbox/useListbox.js.map +1 -1
  22. package/lib/components/Option/Option.types.js.map +1 -1
  23. package/lib/components/Option/useOption.js +14 -24
  24. package/lib/components/Option/useOption.js.map +1 -1
  25. package/lib/components/Option/useOptionStyles.styles.js +27 -28
  26. package/lib/components/Option/useOptionStyles.styles.js.map +1 -1
  27. package/lib/contexts/ComboboxContext.js +9 -1
  28. package/lib/contexts/ComboboxContext.js.map +1 -1
  29. package/lib/contexts/ListboxContext.js +9 -4
  30. package/lib/contexts/ListboxContext.js.map +1 -1
  31. package/lib/contexts/useComboboxContextValues.js +22 -5
  32. package/lib/contexts/useComboboxContextValues.js.map +1 -1
  33. package/lib/contexts/useListboxContextValues.js +19 -10
  34. package/lib/contexts/useListboxContextValues.js.map +1 -1
  35. package/lib/index.js +2 -1
  36. package/lib/index.js.map +1 -1
  37. package/lib/utils/ComboboxBase.types.js.map +1 -1
  38. package/lib/utils/OptionCollection.types.js.map +1 -1
  39. package/lib/utils/Selection.types.js.map +1 -1
  40. package/lib/utils/dropdownKeyActions.js +0 -21
  41. package/lib/utils/dropdownKeyActions.js.map +1 -1
  42. package/lib/utils/useComboboxBaseState.js +60 -17
  43. package/lib/utils/useComboboxBaseState.js.map +1 -1
  44. package/lib/utils/useListboxSlot.js.map +1 -1
  45. package/lib/utils/useOptionCollection.js +18 -45
  46. package/lib/utils/useOptionCollection.js.map +1 -1
  47. package/lib/utils/useTriggerSlot.js +86 -33
  48. package/lib/utils/useTriggerSlot.js.map +1 -1
  49. package/lib-commonjs/components/Combobox/renderCombobox.js +19 -11
  50. package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
  51. package/lib-commonjs/components/Combobox/useCombobox.js +12 -4
  52. package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
  53. package/lib-commonjs/components/Combobox/useInputTriggerSlot.js +14 -12
  54. package/lib-commonjs/components/Combobox/useInputTriggerSlot.js.map +1 -1
  55. package/lib-commonjs/components/Dropdown/renderDropdown.js +21 -13
  56. package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
  57. package/lib-commonjs/components/Dropdown/useButtonTriggerSlot.js +51 -31
  58. package/lib-commonjs/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
  59. package/lib-commonjs/components/Dropdown/useDropdown.js +14 -4
  60. package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
  61. package/lib-commonjs/components/Listbox/renderListbox.js +7 -3
  62. package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
  63. package/lib-commonjs/components/Listbox/useListbox.js +49 -41
  64. package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
  65. package/lib-commonjs/components/Option/useOption.js +13 -23
  66. package/lib-commonjs/components/Option/useOption.js.map +1 -1
  67. package/lib-commonjs/components/Option/useOptionStyles.styles.js +85 -85
  68. package/lib-commonjs/components/Option/useOptionStyles.styles.js.map +1 -1
  69. package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
  70. package/lib-commonjs/contexts/ListboxContext.js +12 -2
  71. package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
  72. package/lib-commonjs/contexts/useComboboxContextValues.js +23 -5
  73. package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
  74. package/lib-commonjs/contexts/useListboxContextValues.js +19 -9
  75. package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
  76. package/lib-commonjs/index.js +4 -0
  77. package/lib-commonjs/index.js.map +1 -1
  78. package/lib-commonjs/utils/dropdownKeyActions.js +3 -30
  79. package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
  80. package/lib-commonjs/utils/useComboboxBaseState.js +59 -16
  81. package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
  82. package/lib-commonjs/utils/useOptionCollection.js +18 -45
  83. package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
  84. package/lib-commonjs/utils/useTriggerSlot.js +84 -31
  85. package/lib-commonjs/utils/useTriggerSlot.js.map +1 -1
  86. package/package.json +10 -9
  87. package/lib/utils/useScrollOptionsIntoView.js +0 -29
  88. package/lib/utils/useScrollOptionsIntoView.js.map +0 -1
  89. package/lib-commonjs/utils/useScrollOptionsIntoView.js +0 -40
  90. package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +0 -1
@@ -11,23 +11,26 @@ Object.defineProperty(exports, "useOptionCollection", {
11
11
  const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
12
  const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
13
  const useOptionCollection = ()=>{
14
- const nodes = _react.useRef([]);
14
+ const optionsById = _react.useRef(new Map());
15
15
  const collectionAPI = _react.useMemo(()=>{
16
- const getCount = ()=>nodes.current.length;
17
- const getOptionAtIndex = (index)=>{
18
- var _nodes_current_index;
19
- return (_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option;
20
- };
21
- const getIndexOfId = (id)=>nodes.current.findIndex((node)=>node.option.id === id);
16
+ const getCount = ()=>optionsById.current.size;
17
+ // index searches are no longer used
18
+ const getOptionAtIndex = ()=>undefined;
19
+ const getIndexOfId = ()=>-1;
22
20
  const getOptionById = (id)=>{
23
- const item = nodes.current.find((node)=>node.option.id === id);
24
- return item === null || item === void 0 ? void 0 : item.option;
21
+ return optionsById.current.get(id);
25
22
  };
26
23
  const getOptionsMatchingText = (matcher)=>{
27
- return nodes.current.filter((node)=>matcher(node.option.text)).map((node)=>node.option);
24
+ return Array.from(optionsById.current.values()).filter(({ text })=>matcher(text));
28
25
  };
29
26
  const getOptionsMatchingValue = (matcher)=>{
30
- return nodes.current.filter((node)=>matcher(node.option.value)).map((node)=>node.option);
27
+ const matches = [];
28
+ for (const option of optionsById.current.values()){
29
+ if (matcher(option.value)) {
30
+ matches.push(option);
31
+ }
32
+ }
33
+ return matches;
31
34
  };
32
35
  return {
33
36
  getCount,
@@ -38,43 +41,13 @@ const useOptionCollection = ()=>{
38
41
  getOptionsMatchingValue
39
42
  };
40
43
  }, []);
41
- const registerOption = _react.useCallback((option, element)=>{
42
- var _nodes_current_index;
43
- const index = nodes.current.findIndex((node)=>{
44
- if (!node.element || !element) {
45
- return false;
46
- }
47
- if (node.option.id === option.id) {
48
- return true;
49
- }
50
- // use the DOM method compareDocumentPosition to order the current node against registered nodes
51
- // eslint-disable-next-line no-bitwise
52
- return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;
53
- });
54
- // do not register the option if it already exists
55
- if (((_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option.id) !== option.id) {
56
- const newItem = {
57
- element,
58
- option
59
- };
60
- // If an index is not found we will push the element to the end.
61
- if (index === -1) {
62
- nodes.current = [
63
- ...nodes.current,
64
- newItem
65
- ];
66
- } else {
67
- nodes.current.splice(index, 0, newItem);
68
- }
69
- }
70
- // return the unregister function
71
- return ()=>{
72
- nodes.current = nodes.current.filter((node)=>node.option.id !== option.id);
73
- };
44
+ const registerOption = _react.useCallback((option)=>{
45
+ optionsById.current.set(option.id, option);
46
+ return ()=>optionsById.current.delete(option.id);
74
47
  }, []);
75
48
  return {
76
49
  ...collectionAPI,
77
- options: nodes.current.map((node)=>node.option),
50
+ options: Array.from(optionsById.current.values()),
78
51
  registerOption
79
52
  };
80
53
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["useOptionCollection.js"],"sourcesContent":["import * as React from 'react';\n/**\n * A hook for managing a collection of child Options\n */ export const useOptionCollection = ()=>{\n const nodes = React.useRef([]);\n const collectionAPI = React.useMemo(()=>{\n const getCount = ()=>nodes.current.length;\n const getOptionAtIndex = (index)=>{\n var _nodes_current_index;\n return (_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option;\n };\n const getIndexOfId = (id)=>nodes.current.findIndex((node)=>node.option.id === id);\n const getOptionById = (id)=>{\n const item = nodes.current.find((node)=>node.option.id === id);\n return item === null || item === void 0 ? void 0 : item.option;\n };\n const getOptionsMatchingText = (matcher)=>{\n return nodes.current.filter((node)=>matcher(node.option.text)).map((node)=>node.option);\n };\n const getOptionsMatchingValue = (matcher)=>{\n return nodes.current.filter((node)=>matcher(node.option.value)).map((node)=>node.option);\n };\n return {\n getCount,\n getOptionAtIndex,\n getIndexOfId,\n getOptionById,\n getOptionsMatchingText,\n getOptionsMatchingValue\n };\n }, []);\n const registerOption = React.useCallback((option, element)=>{\n var _nodes_current_index;\n const index = nodes.current.findIndex((node)=>{\n if (!node.element || !element) {\n return false;\n }\n if (node.option.id === option.id) {\n return true;\n }\n // use the DOM method compareDocumentPosition to order the current node against registered nodes\n // eslint-disable-next-line no-bitwise\n return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;\n });\n // do not register the option if it already exists\n if (((_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option.id) !== option.id) {\n const newItem = {\n element,\n option\n };\n // If an index is not found we will push the element to the end.\n if (index === -1) {\n nodes.current = [\n ...nodes.current,\n newItem\n ];\n } else {\n nodes.current.splice(index, 0, newItem);\n }\n }\n // return the unregister function\n return ()=>{\n nodes.current = nodes.current.filter((node)=>node.option.id !== option.id);\n };\n }, []);\n return {\n ...collectionAPI,\n options: nodes.current.map((node)=>node.option),\n registerOption\n };\n};\n"],"names":["useOptionCollection","nodes","React","useRef","collectionAPI","useMemo","getCount","current","length","getOptionAtIndex","index","_nodes_current_index","option","getIndexOfId","id","findIndex","node","getOptionById","item","find","getOptionsMatchingText","matcher","filter","text","map","getOptionsMatchingValue","value","registerOption","useCallback","element","compareDocumentPosition","Node","DOCUMENT_POSITION_PRECEDING","newItem","splice","options"],"mappings":";;;;+BAGiBA;;;eAAAA;;;;iEAHM;AAGZ,MAAMA,sBAAsB;IACnC,MAAMC,QAAQC,OAAMC,MAAM,CAAC,EAAE;IAC7B,MAAMC,gBAAgBF,OAAMG,OAAO,CAAC;QAChC,MAAMC,WAAW,IAAIL,MAAMM,OAAO,CAACC,MAAM;QACzC,MAAMC,mBAAmB,CAACC;YACtB,IAAIC;YACJ,OAAO,AAACA,CAAAA,uBAAuBV,MAAMM,OAAO,CAACG,MAAM,AAAD,MAAO,QAAQC,yBAAyB,KAAK,IAAI,KAAK,IAAIA,qBAAqBC,MAAM;QAC3I;QACA,MAAMC,eAAe,CAACC,KAAKb,MAAMM,OAAO,CAACQ,SAAS,CAAC,CAACC,OAAOA,KAAKJ,MAAM,CAACE,EAAE,KAAKA;QAC9E,MAAMG,gBAAgB,CAACH;YACnB,MAAMI,OAAOjB,MAAMM,OAAO,CAACY,IAAI,CAAC,CAACH,OAAOA,KAA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AG;uBACTN,MAAMM,OAAO;oBAChB0B;iBACH;YACL,OAAO;gBACHhC,MAAMM,OAAO,CAAC2B,MAAM,CAACxB,OAAO,GAAGuB;YACnC;QACJ;QACA,iCAAiC;QACjC,OAAO;YACHhC,MAAMM,OAAO,GAAGN,MAAMM,OAAO,CAACe,MAAM,CAAC,CAACN,OAAOA,KAAKJ,MAAM,CAACE,EAAE,KAAKF,OAAOE,EAAE;QAC7E;IACJ,GAAG,EAAE;IACL,OAAO;QACH,GAAGV,aAAa;QAChB+B,SAASlC,MAAMM,OAAO,CAACiB,GAAG,CAAC,CAACR,OAAOA,KAAKJ,MAAM;QAC9Ce;IACJ;AACJ"}
1
+ {"version":3,"sources":["useOptionCollection.js"],"sourcesContent":["import * as React from 'react';\n/**\n * A hook for managing a collection of child Options\n */ export const useOptionCollection = ()=>{\n const optionsById = React.useRef(new Map());\n const collectionAPI = React.useMemo(()=>{\n const getCount = ()=>optionsById.current.size;\n // index searches are no longer used\n const getOptionAtIndex = ()=>undefined;\n const getIndexOfId = ()=>-1;\n const getOptionById = (id)=>{\n return optionsById.current.get(id);\n };\n const getOptionsMatchingText = (matcher)=>{\n return Array.from(optionsById.current.values()).filter(({ text })=>matcher(text));\n };\n const getOptionsMatchingValue = (matcher)=>{\n const matches = [];\n for (const option of optionsById.current.values()){\n if (matcher(option.value)) {\n matches.push(option);\n }\n }\n return matches;\n };\n return {\n getCount,\n getOptionAtIndex,\n getIndexOfId,\n getOptionById,\n getOptionsMatchingText,\n getOptionsMatchingValue\n };\n }, []);\n const registerOption = React.useCallback((option)=>{\n optionsById.current.set(option.id, option);\n return ()=>optionsById.current.delete(option.id);\n }, []);\n return {\n ...collectionAPI,\n options: Array.from(optionsById.current.values()),\n registerOption\n };\n};\n"],"names":["useOptionCollection","optionsById","React","useRef","Map","collectionAPI","useMemo","getCount","current","size","getOptionAtIndex","undefined","getIndexOfId","getOptionById","id","get","getOptionsMatchingText","matcher","Array","from","values","filter","text","getOptionsMatchingValue","matches","option","value","push","registerOption","useCallback","set","delete","options"],"mappings":";;;;+BAGiBA;;;eAAAA;;;;iEAHM;AAGZ,MAAMA,sBAAsB;IACnC,MAAMC,cAAcC,OAAMC,MAAM,CAAC,IAAIC;IACrC,MAAMC,gBAAgBH,OAAMI,OAAO,CAAC;QAChC,MAAMC,WAAW,IAAIN,YAAYO,OAAO,CAACC,IAAI;QAC7C,oCAAoC;QACpC,MAAMC,mBAAmB,IAAIC;QAC7B,MAAMC,eAAe,IAAI,CAAC;QAC1B,MAAMC,gBAAgB,CAACC;YACnB,OAAOb,YAAYO,OAAO,CAACO,GAAG,CAACD;QACnC;QACA,MAAME,yBAAyB,CAACC;YAC5B,OAAOC,MAAMC,IAAI,CAAClB,YAAYO,OAAO,CAACY,MAAM,IAAIC,MAAM,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAGL,QAAQK;QAC/E;QACA,MAAMC,0BAA0B,CAACN;YAC7B,MAAMO,UAAU,EAAE;YAClB,KAAK,MAAMC,UAAUxB,YAAYO,OAAO,CAACY,MAAM,GAAG;gBAC9C,IAAIH,QAAQQ,OAAOC,KAAK,GAAG;oBACvBF,QAAQG,IAAI,CAACF;gBACjB;YACJ;YACA,OAAOD;QACX;QACA,OAAO;YACHjB;YACAG;YACAE;YACAC;YACAG;YACAO;QACJ;IACJ,GAAG,EAAE;IACL,MAAMK,iBAAiB1B,OAAM2B,WAAW,CAAC,CAACJ;QACtCxB,YAAYO,OAAO,CAACsB,GAAG,CAACL,OAAOX,EAAE,EAAEW;QACnC,OAAO,IAAIxB,YAAYO,OAAO,CAACuB,MAAM,CAACN,OAAOX,EAAE;IACnD,GAAG,EAAE;IACL,OAAO;QACH,GAAGT,aAAa;QAChB2B,SAASd,MAAMC,IAAI,CAAClB,YAAYO,OAAO,CAACY,MAAM;QAC9CQ;IACJ;AACJ"}
@@ -10,15 +10,15 @@ Object.defineProperty(exports, "useTriggerSlot", {
10
10
  });
11
11
  const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
12
  const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
+ const _reacttabster = require("@fluentui/react-tabster");
13
14
  const _reactutilities = require("@fluentui/react-utilities");
14
15
  const _dropdownKeyActions = require("../utils/dropdownKeyActions");
15
16
  function useTriggerSlot(triggerSlotFromProp, ref, options) {
16
- const { state: { activeOption, getCount, getIndexOfId, getOptionAtIndex, open, selectOption, setActiveOption, setFocusVisible, setOpen, multiselect, setHasFocus }, defaultProps, elementType } = options;
17
+ const { state: { open, setOpen, setHasFocus }, defaultProps, elementType, activeDescendantController } = options;
17
18
  const trigger = _reactutilities.slot.always(triggerSlotFromProp, {
18
19
  defaultProps: {
19
20
  type: 'text',
20
21
  'aria-expanded': open,
21
- 'aria-activedescendant': open ? activeOption === null || activeOption === void 0 ? void 0 : activeOption.id : undefined,
22
22
  role: 'combobox',
23
23
  ...typeof defaultProps === 'object' && defaultProps
24
24
  },
@@ -41,49 +41,102 @@ function useTriggerSlot(triggerSlotFromProp, ref, options) {
41
41
  setOpen(event, !open);
42
42
  }, trigger.onClick);
43
43
  // handle combobox keyboard interaction
44
- trigger.onKeyDown = (0, _reactutilities.mergeCallbacks)((event)=>{
45
- const action = (0, _dropdownKeyActions.getDropdownActionFromKey)(event, {
44
+ trigger.onKeyDown = (0, _reactutilities.mergeCallbacks)(useTriggerKeydown({
45
+ activeDescendantController,
46
+ ...options.state
47
+ }), trigger.onKeyDown);
48
+ return trigger;
49
+ }
50
+ function useTriggerKeydown(options) {
51
+ const { activeDescendantController, getOptionById, setOpen, selectOption, multiselect, open } = options;
52
+ const getActiveOption = _react.useCallback(()=>{
53
+ const activeOptionId = activeDescendantController.active();
54
+ return activeOptionId ? getOptionById(activeOptionId) : undefined;
55
+ }, [
56
+ activeDescendantController,
57
+ getOptionById
58
+ ]);
59
+ const first = ()=>{
60
+ activeDescendantController.first();
61
+ };
62
+ const next = (activeOption)=>{
63
+ if (activeOption) {
64
+ activeDescendantController.next();
65
+ } else {
66
+ activeDescendantController.first();
67
+ }
68
+ };
69
+ const previous = (activeOption)=>{
70
+ if (activeOption) {
71
+ activeDescendantController.prev();
72
+ } else {
73
+ activeDescendantController.first();
74
+ }
75
+ };
76
+ const pageUp = ()=>{
77
+ for(let i = 0; i < 10; i++){
78
+ activeDescendantController.prev();
79
+ }
80
+ };
81
+ const pageDown = ()=>{
82
+ for(let i = 0; i < 10; i++){
83
+ activeDescendantController.next();
84
+ }
85
+ };
86
+ const setKeyboardNavigation = (0, _reacttabster.useSetKeyboardNavigation)();
87
+ return (0, _reactutilities.useEventCallback)((e)=>{
88
+ const action = (0, _dropdownKeyActions.getDropdownActionFromKey)(e, {
46
89
  open,
47
90
  multiselect
48
91
  });
49
- const maxIndex = getCount() - 1;
50
- const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;
51
- let newIndex = activeIndex;
92
+ const activeOption = getActiveOption();
52
93
  switch(action){
94
+ case 'First':
95
+ case 'Next':
96
+ case 'Previous':
97
+ case 'PageDown':
98
+ case 'PageUp':
53
99
  case 'Open':
54
- event.preventDefault();
55
- setFocusVisible(true);
56
- setOpen(event, true);
100
+ case 'Close':
101
+ case 'CloseSelect':
102
+ case 'Select':
103
+ e.preventDefault();
104
+ break;
105
+ }
106
+ setKeyboardNavigation(true);
107
+ switch(action){
108
+ case 'First':
109
+ first();
110
+ break;
111
+ case 'Next':
112
+ next(activeOption);
113
+ break;
114
+ case 'Previous':
115
+ previous(activeOption);
116
+ break;
117
+ case 'PageDown':
118
+ pageDown();
119
+ break;
120
+ case 'PageUp':
121
+ pageUp();
122
+ break;
123
+ case 'Open':
124
+ setOpen(e, true);
57
125
  break;
58
126
  case 'Close':
59
127
  // stop propagation for escape key to avoid dismissing any parent popups
60
- event.stopPropagation();
61
- event.preventDefault();
62
- setOpen(event, false);
128
+ e.stopPropagation();
129
+ setOpen(e, false);
63
130
  break;
64
131
  case 'CloseSelect':
65
- !multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(event, false);
132
+ !multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(e, false);
66
133
  // fallthrough
67
134
  case 'Select':
68
- activeOption && selectOption(event, activeOption);
69
- event.preventDefault();
135
+ activeOption && selectOption(e, activeOption);
70
136
  break;
71
137
  case 'Tab':
72
- !multiselect && activeOption && selectOption(event, activeOption);
138
+ !multiselect && activeOption && selectOption(e, activeOption);
73
139
  break;
74
- default:
75
- newIndex = (0, _dropdownKeyActions.getIndexFromAction)(action, activeIndex, maxIndex);
76
- }
77
- if (newIndex !== activeIndex) {
78
- // prevent default page scroll/keyboard action if the index changed
79
- event.preventDefault();
80
- setActiveOption(getOptionAtIndex(newIndex));
81
- setFocusVisible(true);
82
140
  }
83
- }, trigger.onKeyDown);
84
- trigger.onMouseOver = (0, _reactutilities.mergeCallbacks)((event)=>{
85
- setFocusVisible(false);
86
- }, trigger.onMouseOver);
87
- // TODO fix cast
88
- return trigger;
141
+ });
89
142
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["useTriggerSlot.js"],"sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, slot, useMergedRefs } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownKeyActions';\n/**\n * Shared trigger behaviour for combobox and dropdown\n * @returns trigger slot with desired behaviour and props\n */ export function useTriggerSlot(triggerSlotFromProp, ref, options) {\n const { state: { activeOption, getCount, getIndexOfId, getOptionAtIndex, open, selectOption, setActiveOption, setFocusVisible, setOpen, multiselect, setHasFocus }, defaultProps, elementType } = options;\n const trigger = slot.always(triggerSlotFromProp, {\n defaultProps: {\n type: 'text',\n 'aria-expanded': open,\n 'aria-activedescendant': open ? activeOption === null || activeOption === void 0 ? void 0 : activeOption.id : undefined,\n role: 'combobox',\n ...typeof defaultProps === 'object' && defaultProps\n },\n elementType\n });\n // handle trigger focus/blur\n const triggerRef = React.useRef(null);\n trigger.ref = useMergedRefs(triggerRef, trigger.ref, ref);\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event)=>{\n setOpen(event, false);\n setHasFocus(false);\n }, trigger.onBlur);\n trigger.onFocus = mergeCallbacks((event)=>{\n if (event.target === event.currentTarget) {\n setHasFocus(true);\n }\n }, trigger.onFocus);\n trigger.onClick = mergeCallbacks((event)=>{\n setOpen(event, !open);\n }, trigger.onClick);\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks((event)=>{\n const action = getDropdownActionFromKey(event, {\n open,\n multiselect\n });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n switch(action){\n case 'Open':\n event.preventDefault();\n setFocusVisible(true);\n setOpen(event, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n event.stopPropagation();\n event.preventDefault();\n setOpen(event, false);\n break;\n case 'CloseSelect':\n !multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(event, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(event, activeOption);\n event.preventDefault();\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\n if (newIndex !== activeIndex) {\n // prevent default page scroll/keyboard action if the index changed\n event.preventDefault();\n setActiveOption(getOptionAtIndex(newIndex));\n setFocusVisible(true);\n }\n }, trigger.onKeyDown);\n trigger.onMouseOver = mergeCallbacks((event)=>{\n setFocusVisible(false);\n }, trigger.onMouseOver);\n // TODO fix cast\n return trigger;\n}\n"],"names":["useTriggerSlot","triggerSlotFromProp","ref","options","state","activeOption","getCount","getIndexOfId","getOptionAtIndex","open","selectOption","setActiveOption","setFocusVisible","setOpen","multiselect","setHasFocus","defaultProps","elementType","trigger","slot","always","type","id","undefined","role","triggerRef","React","useRef","useMergedRefs","onBlur","mergeCallbacks","event","onFocus","target","currentTarget","onClick","onKeyDown","action","getDropdownActionFromKey","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GAAGN,IAAAA,8BAAc,EAAC,CAACC;QAChC,MAAMM,SAASC,IAAAA,4CAAwB,EAACP,OAAO;YAC3CtB;YACAK;QACJ;QACA,MAAMyB,WAAWjC,aAAa;QAC9B,MAAMkC,cAAcnC,eAAeE,aAAaF,aAAaiB,EAAE,IAAI,CAAC;QACpE,IAAImB,WAAWD;QACf,OAAOH;YACH,KAAK;gBACDN,MAAMW,cAAc;gBACpB9B,gBAAgB;gBAChBC,QAAQkB,OAAO;gBACf;YACJ,KAAK;gBACD,wEAAwE;gBACxEA,MAAMY,eAAe;gBACrBZ,MAAMW,cAAc;gBACpB7B,QAAQkB,OAAO;gBACf;YACJ,KAAK;gBACD,CAACjB,eAAe,CAAET,CAAAA,iBAAiB,QAAQA,iBAAiB,KAAK,IAAI,KAAK,IAAIA,aAAauC,QAAQ,AAAD,KAAM/B,QAAQkB,OAAO;YAC3H,cAAc;YACd,KAAK;gBACD1B,gBAAgBK,aAAaqB,OAAO1B;gBACpC0B,MAAMW,cAAc;gBACpB;YACJ,KAAK;gBACD,CAAC5B,eAAeT,gBAAgBK,aAAaqB,OAAO1B;gBACpD;YACJ;gBACIoC,WAAWI,IAAAA,sCAAkB,EAACR,QAAQG,aAAaD;QAC3D;QACA,IAAIE,aAAaD,aAAa;YAC1B,mEAAmE;YACnET,MAAMW,cAAc;YACpB/B,gBAAgBH,iBAAiBiC;YACjC7B,gBAAgB;QACpB;IACJ,GAAGM,QAAQkB,SAAS;IACpBlB,QAAQ4B,WAAW,GAAGhB,IAAAA,8BAAc,EAAC,CAACC;QAClCnB,gBAAgB;IACpB,GAAGM,QAAQ4B,WAAW;IACtB,gBAAgB;IAChB,OAAO5B;AACX"}
1
+ {"version":3,"sources":["useTriggerSlot.js"],"sourcesContent":["import * as React from 'react';\nimport { useSetKeyboardNavigation } from '@fluentui/react-tabster';\nimport { mergeCallbacks, slot, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from '../utils/dropdownKeyActions';\n/**\n * Shared trigger behaviour for combobox and dropdown\n * @returns trigger slot with desired behaviour and props\n */ export function useTriggerSlot(triggerSlotFromProp, ref, options) {\n const { state: { open, setOpen, setHasFocus }, defaultProps, elementType, activeDescendantController } = options;\n const trigger = slot.always(triggerSlotFromProp, {\n defaultProps: {\n type: 'text',\n 'aria-expanded': open,\n role: 'combobox',\n ...typeof defaultProps === 'object' && defaultProps\n },\n elementType\n });\n // handle trigger focus/blur\n const triggerRef = React.useRef(null);\n trigger.ref = useMergedRefs(triggerRef, trigger.ref, ref);\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event)=>{\n setOpen(event, false);\n setHasFocus(false);\n }, trigger.onBlur);\n trigger.onFocus = mergeCallbacks((event)=>{\n if (event.target === event.currentTarget) {\n setHasFocus(true);\n }\n }, trigger.onFocus);\n trigger.onClick = mergeCallbacks((event)=>{\n setOpen(event, !open);\n }, trigger.onClick);\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks(useTriggerKeydown({\n activeDescendantController,\n ...options.state\n }), trigger.onKeyDown);\n return trigger;\n}\nfunction useTriggerKeydown(options) {\n const { activeDescendantController, getOptionById, setOpen, selectOption, multiselect, open } = options;\n const getActiveOption = React.useCallback(()=>{\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [\n activeDescendantController,\n getOptionById\n ]);\n const first = ()=>{\n activeDescendantController.first();\n };\n const next = (activeOption)=>{\n if (activeOption) {\n activeDescendantController.next();\n } else {\n activeDescendantController.first();\n }\n };\n const previous = (activeOption)=>{\n if (activeOption) {\n activeDescendantController.prev();\n } else {\n activeDescendantController.first();\n }\n };\n const pageUp = ()=>{\n for(let i = 0; i < 10; i++){\n activeDescendantController.prev();\n }\n };\n const pageDown = ()=>{\n for(let i = 0; i < 10; i++){\n activeDescendantController.next();\n }\n };\n const setKeyboardNavigation = useSetKeyboardNavigation();\n return useEventCallback((e)=>{\n const action = getDropdownActionFromKey(e, {\n open,\n multiselect\n });\n const activeOption = getActiveOption();\n switch(action){\n case 'First':\n case 'Next':\n case 'Previous':\n case 'PageDown':\n case 'PageUp':\n case 'Open':\n case 'Close':\n case 'CloseSelect':\n case 'Select':\n e.preventDefault();\n break;\n }\n setKeyboardNavigation(true);\n switch(action){\n case 'First':\n first();\n break;\n case 'Next':\n next(activeOption);\n break;\n case 'Previous':\n previous(activeOption);\n break;\n case 'PageDown':\n pageDown();\n break;\n case 'PageUp':\n pageUp();\n break;\n case 'Open':\n setOpen(e, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n e.stopPropagation();\n setOpen(e, false);\n break;\n case 'CloseSelect':\n !multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(e, false);\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":["useTriggerSlot","triggerSlotFromProp","ref","options","state","open","setOpen","setHasFocus","defaultProps","elementType","activeDescendantController","trigger","slot","always","type","role","triggerRef","React","useRef","useMergedRefs","onBlur","mergeCallbacks","event","onFocus","target","currentTarget","onClick","onKeyDown","useTriggerKeydown","getOptionById","selectOption","multiselect","getActiveOption","useCallback","activeOptionId","active","undefined","first","next","activeOption","previous","prev","pageUp","i","pageDown","setKeyboardNavigation","useSetKeyboardNavigation","useEventCallback","e","action","getDropdownActionFromKey","preventDefault","stopPropagation","disabled"],"mappings":";;;;+BAOoBA;;;eAAAA;;;;iEAPG;8BACkB;gCAC6B;oCAC7B;AAI9B,SAASA,eAAeC,mBAAmB,EAAEC,GAAG,EAAEC,OAAO;IAChE,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAEC,OAAO,EAAEC,WAAW,EAAE,EAAEC,YAAY,EAAEC,WAAW,EAAEC,0BAA0B,EAAE,GAAGP;IACzG,MAAMQ,UAAUC,oBAAI,CAACC,MAAM,CAACZ,qBAAqB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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-combobox",
3
- "version": "9.7.5",
3
+ "version": "9.9.0",
4
4
  "description": "Fluent UI React Combobox component",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -33,17 +33,18 @@
33
33
  "@fluentui/scripts-tasks": "*"
34
34
  },
35
35
  "dependencies": {
36
+ "@fluentui/react-aria": "^9.9.1",
36
37
  "@fluentui/keyboard-keys": "^9.0.7",
37
- "@fluentui/react-context-selector": "^9.1.51",
38
- "@fluentui/react-field": "^9.1.53",
38
+ "@fluentui/react-context-selector": "^9.1.53",
39
+ "@fluentui/react-field": "^9.1.55",
39
40
  "@fluentui/react-icons": "^2.0.224",
40
- "@fluentui/react-jsx-runtime": "^9.0.29",
41
- "@fluentui/react-portal": "^9.4.13",
42
- "@fluentui/react-positioning": "^9.13.3",
43
- "@fluentui/react-shared-contexts": "^9.14.0",
44
- "@fluentui/react-tabster": "^9.19.0",
41
+ "@fluentui/react-jsx-runtime": "^9.0.31",
42
+ "@fluentui/react-portal": "^9.4.15",
43
+ "@fluentui/react-positioning": "^9.13.5",
44
+ "@fluentui/react-shared-contexts": "^9.14.1",
45
+ "@fluentui/react-tabster": "^9.19.2",
45
46
  "@fluentui/react-theme": "^9.1.16",
46
- "@fluentui/react-utilities": "^9.18.0",
47
+ "@fluentui/react-utilities": "^9.18.2",
47
48
  "@griffel/react": "^1.5.14",
48
49
  "@swc/helpers": "^0.5.1"
49
50
  },
@@ -1,29 +0,0 @@
1
- import * as React from 'react';
2
- import { canUseDOM } from '@fluentui/react-utilities';
3
- export function useScrollOptionsIntoView(state) {
4
- const { activeOption } = state;
5
- const scrollContainerRef = React.useRef(null);
6
- React.useEffect(()=>{
7
- if (scrollContainerRef.current && activeOption && canUseDOM()) {
8
- const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`);
9
- if (!activeOptionElement) {
10
- return;
11
- }
12
- const { offsetHeight, offsetTop } = activeOptionElement;
13
- const { offsetHeight: parentOffsetHeight, scrollTop } = scrollContainerRef.current;
14
- const isAbove = offsetTop < scrollTop;
15
- const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
16
- // add a small buffer for general visual nicety
17
- // it looks slightly better if the option has some space from the top/bottom while arrowing
18
- const buffer = 2;
19
- if (isAbove) {
20
- scrollContainerRef.current.scrollTo(0, offsetTop - buffer);
21
- } else if (isBelow) {
22
- scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);
23
- }
24
- }
25
- }, [
26
- activeOption
27
- ]);
28
- return scrollContainerRef;
29
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useScrollOptionsIntoView.ts"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '@fluentui/react-utilities';\nimport { ListboxState } from '../Listbox';\n\nexport function useScrollOptionsIntoView(state: ListboxState): React.Ref<HTMLDivElement> {\n const { activeOption } = state;\n const scrollContainerRef = React.useRef<HTMLDivElement>(null);\n\n React.useEffect(() => {\n if (scrollContainerRef.current && activeOption && canUseDOM()) {\n const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`) as HTMLElement;\n\n if (!activeOptionElement) {\n return;\n }\n\n const { offsetHeight, offsetTop } = activeOptionElement;\n const { offsetHeight: parentOffsetHeight, scrollTop } = scrollContainerRef.current;\n\n const isAbove = offsetTop < scrollTop;\n const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;\n\n // add a small buffer for general visual nicety\n // it looks slightly better if the option has some space from the top/bottom while arrowing\n const buffer = 2;\n\n if (isAbove) {\n scrollContainerRef.current.scrollTo(0, offsetTop - buffer);\n } else if (isBelow) {\n scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);\n }\n }\n }, [activeOption]);\n\n return scrollContainerRef;\n}\n"],"names":["React","canUseDOM","useScrollOptionsIntoView","state","activeOption","scrollContainerRef","useRef","useEffect","current","activeOptionElement","querySelector","id","offsetHeight","offsetTop","parentOffsetHeight","scrollTop","isAbove","isBelow","buffer","scrollTo"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,SAAS,QAAQ,4BAA4B;AAGtD,OAAO,SAASC,yBAAyBC,KAAmB;IAC1D,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,qBAAqBL,MAAMM,MAAM,CAAiB;IAExDN,MAAMO,SAAS,CAAC;QACd,IAAIF,mBAAmBG,OAAO,IAAIJ,gBAAgBH,aAAa;YAC7D,MAAMQ,sBAAsBJ,mBAAmBG,OAAO,CAACE,aAAa,CAAC,CAAC,CAAC,EAAEN,aAAaO,EAAE,CAAC,CAAC;YAE1F,IAAI,CAACF,qBAAqB;gBACxB;YACF;YAEA,MAAM,EAAEG,YAAY,EAAEC,SAAS,EAAE,GAAGJ;YACpC,MAAM,EAAEG,cAAcE,kBAAkB,EAAEC,SAAS,EAAE,GAAGV,mBAAmBG,OAAO;YAElF,MAAMQ,UAAUH,YAAYE;YAC5B,MAAME,UAAUJ,YAAYD,eAAeG,YAAYD;YAEvD,+CAA+C;YAC/C,2FAA2F;YAC3F,MAAMI,SAAS;YAEf,IAAIF,SAAS;gBACXX,mBAAmBG,OAAO,CAACW,QAAQ,CAAC,GAAGN,YAAYK;YACrD,OAAO,IAAID,SAAS;gBAClBZ,mBAAmBG,OAAO,CAACW,QAAQ,CAAC,GAAGN,YAAYC,qBAAqBF,eAAeM;YACzF;QACF;IACF,GAAG;QAACd;KAAa;IAEjB,OAAOC;AACT"}
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "useScrollOptionsIntoView", {
6
- enumerable: true,
7
- get: function() {
8
- return useScrollOptionsIntoView;
9
- }
10
- });
11
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
- const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
- const _reactutilities = require("@fluentui/react-utilities");
14
- function useScrollOptionsIntoView(state) {
15
- const { activeOption } = state;
16
- const scrollContainerRef = _react.useRef(null);
17
- _react.useEffect(()=>{
18
- if (scrollContainerRef.current && activeOption && (0, _reactutilities.canUseDOM)()) {
19
- const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`);
20
- if (!activeOptionElement) {
21
- return;
22
- }
23
- const { offsetHeight, offsetTop } = activeOptionElement;
24
- const { offsetHeight: parentOffsetHeight, scrollTop } = scrollContainerRef.current;
25
- const isAbove = offsetTop < scrollTop;
26
- const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
27
- // add a small buffer for general visual nicety
28
- // it looks slightly better if the option has some space from the top/bottom while arrowing
29
- const buffer = 2;
30
- if (isAbove) {
31
- scrollContainerRef.current.scrollTo(0, offsetTop - buffer);
32
- } else if (isBelow) {
33
- scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);
34
- }
35
- }
36
- }, [
37
- activeOption
38
- ]);
39
- return scrollContainerRef;
40
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useScrollOptionsIntoView.js"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '@fluentui/react-utilities';\nexport function useScrollOptionsIntoView(state) {\n const { activeOption } = state;\n const scrollContainerRef = React.useRef(null);\n React.useEffect(()=>{\n if (scrollContainerRef.current && activeOption && canUseDOM()) {\n const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`);\n if (!activeOptionElement) {\n return;\n }\n const { offsetHeight, offsetTop } = activeOptionElement;\n const { offsetHeight: parentOffsetHeight, scrollTop } = scrollContainerRef.current;\n const isAbove = offsetTop < scrollTop;\n const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;\n // add a small buffer for general visual nicety\n // it looks slightly better if the option has some space from the top/bottom while arrowing\n const buffer = 2;\n if (isAbove) {\n scrollContainerRef.current.scrollTo(0, offsetTop - buffer);\n } else if (isBelow) {\n scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);\n }\n }\n }, [\n activeOption\n ]);\n return scrollContainerRef;\n}\n"],"names":["useScrollOptionsIntoView","state","activeOption","scrollContainerRef","React","useRef","useEffect","current","canUseDOM","activeOptionElement","querySelector","id","offsetHeight","offsetTop","parentOffsetHeight","scrollTop","isAbove","isBelow","buffer","scrollTo"],"mappings":";;;;+BAEgBA;;;eAAAA;;;;iEAFO;gCACG;AACnB,SAASA,yBAAyBC,KAAK;IAC1C,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,qBAAqBC,OAAMC,MAAM,CAAC;IACxCD,OAAME,SAAS,CAAC;QACZ,IAAIH,mBAAmBI,OAAO,IAAIL,gBAAgBM,IAAAA,yBAAS,KAAI;YAC3D,MAAMC,sBAAsBN,mBAAmBI,OAAO,CAACG,aAAa,CAAC,CAAC,CAAC,EAAER,aAAaS,EAAE,CAAC,CAAC;YAC1F,IAAI,CAACF,qBAAqB;gBACtB;YACJ;YACA,MAAM,EAAEG,YAAY,EAAEC,SAAS,EAAE,GAAGJ;YACpC,MAAM,EAAEG,cAAcE,kBAAkB,EAAEC,SAAS,EAAE,GAAGZ,mBAAmBI,OAAO;YAClF,MAAMS,UAAUH,YAAYE;YAC5B,MAAME,UAAUJ,YAAYD,eAAeG,YAAYD;YACvD,+CAA+C;YAC/C,2FAA2F;YAC3F,MAAMI,SAAS;YACf,IAAIF,SAAS;gBACTb,mBAAmBI,OAAO,CAACY,QAAQ,CAAC,GAAGN,YAAYK;YACvD,OAAO,IAAID,SAAS;gBAChBd,mBAAmBI,OAAO,CAACY,QAAQ,CAAC,GAAGN,YAAYC,qBAAqBF,eAAeM;YAC3F;QACJ;IACJ,GAAG;QACChB;KACH;IACD,OAAOC;AACX"}