@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,72 @@
1
+ // Brought from Fluent UI
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "useSelection", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return useSelection;
10
+ }
11
+ });
12
+ const _react = require("react");
13
+ const _reactutilities = require("@fluentui/react-utilities");
14
+ const useSelection = (props)=>{
15
+ const { defaultSelectedOptions, multiselect, onOptionSelect } = props;
16
+ const [selectedOptions, setSelectedOptions] = (0, _reactutilities.useControllableState)({
17
+ state: props.selectedOptions,
18
+ defaultState: defaultSelectedOptions,
19
+ initialState: []
20
+ });
21
+ const selectOption = (0, _react.useCallback)((event, option)=>{
22
+ // if the option is disabled, do nothing
23
+ if (option.disabled) {
24
+ return;
25
+ }
26
+ // for single-select, always return the selected option
27
+ let newSelection = [
28
+ option.value
29
+ ];
30
+ // toggle selected state of the option for multiselect
31
+ if (multiselect) {
32
+ const selectedIndex = selectedOptions.findIndex((o)=>o === option.value);
33
+ if (selectedIndex > -1) {
34
+ // deselect option
35
+ newSelection = [
36
+ ...selectedOptions.slice(0, selectedIndex),
37
+ ...selectedOptions.slice(selectedIndex + 1)
38
+ ];
39
+ } else {
40
+ // select option
41
+ newSelection = [
42
+ ...selectedOptions,
43
+ option.value
44
+ ];
45
+ }
46
+ }
47
+ setSelectedOptions(newSelection);
48
+ onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, {
49
+ optionValue: option.value,
50
+ optionText: option.text,
51
+ selectedOptions: newSelection
52
+ });
53
+ }, [
54
+ onOptionSelect,
55
+ multiselect,
56
+ selectedOptions,
57
+ setSelectedOptions
58
+ ]);
59
+ const clearSelection = (event)=>{
60
+ setSelectedOptions([]);
61
+ onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, {
62
+ optionValue: undefined,
63
+ optionText: undefined,
64
+ selectedOptions: []
65
+ });
66
+ };
67
+ return {
68
+ clearSelection,
69
+ selectOption,
70
+ selectedOptions
71
+ };
72
+ }; //# sourceMappingURL=useSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useSelection.ts"],"sourcesContent":["// Brought from Fluent UI\n\nimport { useCallback } from 'react';\nimport { useControllableState } from '@fluentui/react-utilities';\nimport type { OptionValue } from './OptionCollection.types';\nimport type { SelectionEvents, SelectionProps, SelectionState } from './Selection.types';\n\nexport const useSelection = (props: SelectionProps): SelectionState => {\n const { defaultSelectedOptions, multiselect, onOptionSelect } = props;\n\n const [selectedOptions, setSelectedOptions] = useControllableState({\n state: props.selectedOptions,\n defaultState: defaultSelectedOptions,\n initialState: [],\n });\n\n const selectOption = useCallback(\n (event: SelectionEvents, option: OptionValue) => {\n // if the option is disabled, do nothing\n if (option.disabled) {\n return;\n }\n\n // for single-select, always return the selected option\n let newSelection = [option.value];\n\n // toggle selected state of the option for multiselect\n if (multiselect) {\n const selectedIndex = selectedOptions.findIndex(o => o === option.value);\n if (selectedIndex > -1) {\n // deselect option\n newSelection = [...selectedOptions.slice(0, selectedIndex), ...selectedOptions.slice(selectedIndex + 1)];\n } else {\n // select option\n newSelection = [...selectedOptions, option.value];\n }\n }\n\n setSelectedOptions(newSelection);\n onOptionSelect?.(event, { optionValue: option.value, optionText: option.text, selectedOptions: newSelection });\n },\n [onOptionSelect, multiselect, selectedOptions, setSelectedOptions],\n );\n\n const clearSelection = (event: SelectionEvents) => {\n setSelectedOptions([]);\n onOptionSelect?.(event, { optionValue: undefined, optionText: undefined, selectedOptions: [] });\n };\n\n return { clearSelection, selectOption, selectedOptions };\n};\n"],"names":["useSelection","props","defaultSelectedOptions","selectedOptions","defaultState","setSelectedOptions","useControllableState","state","selectOption","useCallback","option","disabled","event","newSelection","multiselect","value","findIndex","selectedIndex","o","slice","onOptionSelect","text","optionValue","undefined","clearSelection"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yBAAyB;;;;;+BAOZA;;;eAAAA;;;uBALe;gCACS;AAI9B,MAAMA,eAAeC,CAAAA;UAC1B,EAEAC,sBAAOC,aACEF,gBACPG;UAEF,CAAAD,iBAAAE,mBAAA,GAAAC,IAAAA,oCAAA,EAAA;QAEAC,OAAMC,MAAAA,eAAeC;sBAEjBP;sBACIQ,EAAOC;;UAEXH,eAAAC,IAAAA,kBAAA,EAAA,CAAAG,OAAAF;gDAEA;YACAA,OAAIG,QAAAA,EAAAA;;;+DAEJ;YACAA,eAAIC;YAAAA,OAAaC,KAAA;SAAA;8DACuBC;yBAClCC;kCACFd,gBAAkBa,SAAA,CAAAE,CAAAA,IAAAA,MAAAR,OAAAK,KAAA;gCAClBF,CAAAA,GAAAA;kCAAmBV;+BAA4CA;uBAAAA,gBAAgBgB,KAAMF,CAAAA,GAAAA;uBAAgBd,gBAAAgB,KAAA,CAAAF,gBAAA;iBAAA;;gCAChG;+BACL;uBAAAd;oBAAgBO,OAAAK,KAAA;iBAAA;;;2BACoBL;2BAAa,QAAAU,mBAAA,KAAA,IAAA,KAAA,IAAAA,eAAAR,OAAA;yBACnDF,OAAAK,KAAA;wBACFL,OAAAW,IAAA;6BAEAhB;;;;QAC0BiB;QAAoBP;QAAKV;KAAA;2BAAcK,CAAAA;2BAAaP,EAAAA;2BAA8B,QAAAiB,mBAAA,KAAA,IAAA,KAAA,IAAAA,eAAAR,OAAA;YAC9GU,aACAC;wBAACH;6BAAgBN,EAAAA;;;WAAiD;QAGpEU;;;;2CAE8F"}
@@ -0,0 +1,134 @@
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 and added the bluring
4
+ * functionality.
5
+ */ "use strict";
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ Object.defineProperty(exports, "useTriggerKeydown", {
10
+ enumerable: true,
11
+ get: function() {
12
+ return useTriggerKeydown;
13
+ }
14
+ });
15
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
16
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
17
+ const _reacttabster = require("@fluentui/react-tabster");
18
+ const _reactutilities = require("@fluentui/react-utilities");
19
+ const _dropdownKeyActions = require("./dropdownKeyActions");
20
+ function useTriggerKeydown(options) {
21
+ const { activeDescendantController, getOptionById, selectOption, multiselect, open, isInLastPosition, onBlur } = options;
22
+ const getActiveOption = _react.useCallback(()=>{
23
+ const activeOptionId = activeDescendantController.active();
24
+ return activeOptionId ? getOptionById(activeOptionId) : undefined;
25
+ }, [
26
+ activeDescendantController,
27
+ getOptionById
28
+ ]);
29
+ const first = ()=>{
30
+ activeDescendantController.first();
31
+ };
32
+ const last = ()=>{
33
+ activeDescendantController.last();
34
+ };
35
+ const blur = ()=>{
36
+ activeDescendantController.blur();
37
+ onBlur();
38
+ };
39
+ const next = (activeOption)=>{
40
+ if (activeOption) {
41
+ activeDescendantController.next();
42
+ } else {
43
+ activeDescendantController.first();
44
+ }
45
+ };
46
+ const previous = (activeOption)=>{
47
+ if (activeOption) {
48
+ activeDescendantController.prev();
49
+ } else {
50
+ activeDescendantController.first();
51
+ }
52
+ };
53
+ const pageUp = ()=>{
54
+ for(let i = 0; i < 10; i++){
55
+ activeDescendantController.prev();
56
+ }
57
+ };
58
+ const pageDown = ()=>{
59
+ for(let i = 0; i < 10; i++){
60
+ activeDescendantController.next();
61
+ }
62
+ };
63
+ const setKeyboardNavigation = (0, _reacttabster.useSetKeyboardNavigation)();
64
+ return (0, _reactutilities.useEventCallback)((e)=>{
65
+ const action = (0, _dropdownKeyActions.getDropdownActionFromKey)(e, {
66
+ open,
67
+ multiselect,
68
+ isInLastPosition
69
+ });
70
+ const activeOption = getActiveOption();
71
+ const firstOption = activeDescendantController.first({
72
+ passive: true
73
+ });
74
+ switch(action){
75
+ case 'Last':
76
+ case 'First':
77
+ case 'PageDown':
78
+ case 'PageUp':
79
+ case 'CloseSelect':
80
+ case 'Select':
81
+ e.preventDefault();
82
+ break;
83
+ case 'Previous':
84
+ // when active option is the first option and the action was "Previous",
85
+ // this means we were in the first option and we are "leaving" the listbox
86
+ if ((activeOption === null || activeOption === void 0 ? void 0 : activeOption.id) === firstOption) {
87
+ blur();
88
+ e.preventDefault();
89
+ } else if (activeOption) {
90
+ e.preventDefault();
91
+ }
92
+ break;
93
+ case 'Next':
94
+ e.preventDefault();
95
+ break;
96
+ }
97
+ setKeyboardNavigation(true);
98
+ switch(action){
99
+ case 'First':
100
+ first();
101
+ break;
102
+ case 'Last':
103
+ last();
104
+ break;
105
+ case 'Next':
106
+ next(activeOption);
107
+ break;
108
+ case 'Previous':
109
+ if (activeOption && activeOption.id !== firstOption) {
110
+ previous(activeOption);
111
+ } else {
112
+ blur();
113
+ }
114
+ break;
115
+ case 'PageDown':
116
+ pageDown();
117
+ break;
118
+ case 'PageUp':
119
+ pageUp();
120
+ break;
121
+ case 'CloseSelect':
122
+ if (!multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled)) {
123
+ blur();
124
+ }
125
+ // fallthrough
126
+ case 'Select':
127
+ activeOption && selectOption(e, activeOption);
128
+ break;
129
+ case 'Tab':
130
+ !multiselect && activeOption && selectOption(e, activeOption);
131
+ break;
132
+ }
133
+ });
134
+ } //# sourceMappingURL=useTriggerKeyDown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useTriggerKeyDown.ts"],"sourcesContent":["/**\n * Note, this is mainly brought from Fluent UI, only removed the closing and\n * opening logic since that's not needed for this use case and added the bluring\n * functionality.\n */\n\nimport * as React from 'react';\nimport { useSetKeyboardNavigation } from '@fluentui/react-tabster';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from './dropdownKeyActions';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport type { OptionCollectionState, OptionValue } from './OptionCollection.types';\nimport type { SelectionProps, SelectionState } from './Selection.types';\n\nexport function useTriggerKeydown(\n options: {\n activeDescendantController: ActiveDescendantImperativeRef;\n isInLastPosition: boolean;\n open: boolean;\n onBlur: () => void;\n } & OptionCollectionState &\n Pick<SelectionProps, 'multiselect'> &\n Pick<SelectionState, 'selectOption'>,\n) {\n const { activeDescendantController, getOptionById, selectOption, multiselect, open, isInLastPosition, onBlur } =\n options;\n\n const getActiveOption = React.useCallback(() => {\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [activeDescendantController, getOptionById]);\n\n const first = () => {\n activeDescendantController.first();\n };\n\n const last = () => {\n activeDescendantController.last();\n };\n\n const blur = () => {\n activeDescendantController.blur();\n onBlur();\n };\n\n const next = (activeOption: OptionValue | undefined) => {\n if (activeOption) {\n activeDescendantController.next();\n } else {\n activeDescendantController.first();\n }\n };\n\n const previous = (activeOption: OptionValue | undefined) => {\n if (activeOption) {\n activeDescendantController.prev();\n } else {\n activeDescendantController.first();\n }\n };\n\n const pageUp = () => {\n for (let i = 0; i < 10; i++) {\n activeDescendantController.prev();\n }\n };\n\n const pageDown = () => {\n for (let i = 0; i < 10; i++) {\n activeDescendantController.next();\n }\n };\n\n const setKeyboardNavigation = useSetKeyboardNavigation();\n return useEventCallback((e: React.KeyboardEvent<HTMLSpanElement>) => {\n const action = getDropdownActionFromKey(e, { open, multiselect, isInLastPosition });\n const activeOption = getActiveOption();\n const firstOption = activeDescendantController.first({ passive: true });\n\n switch (action) {\n case 'Last':\n case 'First':\n case 'PageDown':\n case 'PageUp':\n case 'CloseSelect':\n case 'Select':\n e.preventDefault();\n break;\n case 'Previous':\n // when active option is the first option and the action was \"Previous\",\n // this means we were in the first option and we are \"leaving\" the listbox\n if (activeOption?.id === firstOption) {\n blur();\n e.preventDefault();\n } else if (activeOption) {\n e.preventDefault();\n }\n break;\n case 'Next':\n e.preventDefault();\n break;\n }\n\n setKeyboardNavigation(true);\n\n switch (action) {\n case 'First':\n first();\n break;\n case 'Last':\n last();\n break;\n case 'Next':\n next(activeOption);\n break;\n case 'Previous':\n if (activeOption && activeOption.id !== firstOption) {\n previous(activeOption);\n } else {\n blur();\n }\n break;\n case 'PageDown':\n pageDown();\n break;\n case 'PageUp':\n pageUp();\n break;\n case 'CloseSelect':\n if (!multiselect && !activeOption?.disabled) {\n blur();\n }\n // fallthrough\n case 'Select':\n activeOption && selectOption(e, activeOption);\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(e, activeOption);\n break;\n }\n });\n}\n"],"names":["useTriggerKeydown","React","options","activeDescendantController","activeOptionId","multiselect","getOptionById","active","last","undefined","first","onBlur","blur","activeOption","next","previous","prev","pageUp","pageDown","i","setKeyboardNavigation","useEventCallback","e","getDropdownActionFromKey","isInLastPosition","action","getActiveOption","id","firstOption","preventDefault","selectOption"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;;;CAIC;;;;+BAUeA;;;eAAAA;;;;iEARJC;8BAC6B;gCACR;oCACQ;AAKlC,SAASD,kBACdE,OAOsC;UAEtC,EAGAC,0BAAwBF,eAChBG,cACCA,EACTC,WAAG,MAACF,kBAA4BG,QAAc,KAE9CJ;UACEC,kBAAAA,OAAAA,WAAgC,CAAA;QAClC,MAAAC,iBAAAD,2BAAAI,MAAA;QAEA,OAAMC,iBAAOF,cAAAF,kBAAAK;;;QACXN;KAA+B;UACjCO,QAAA;QAEAP,2BAAaO,KAAA;;UAEXC,OAAAA;QACFR,2BAAAK,IAAA;;UAGEI,OAAIC;mCACFV,IAAAA;;;UAGFW,OAAAD,CAAAA;QACF,IAAAA,cAAA;YAEAV,2BAAkBU,IAAAA;eAChB;uCACEV,KAAAA;;;UAGFY,WAAAF,CAAAA;QACF,IAAAA,cAAA;YAEAV,2BAAea,IAAA;eACb;uCACEb,KAAAA;;;UAIJc,SAAMC;YACJ,IAAKC,IAAIA,GAAIA,IAAGA,IAAIA,IAAIA;uCACtBhB,IAAAA;;;UAIJe,WAAME;QACN,IAAA,IAAOC,IAAAA,GAAAA,IAAAA,IAAiBF,IAACG;uCACRC,IAAAA;;;kCAAiDC,IAAAA,sCAAAA;WAAiBH,IAAAA,gCAAA,EAAAC,CAAAA;cACjFG,SAAMZ,IAAAA,4CAAea,EAAAA,GAAAA;;;;;6BAIdA;4BACAvB,2BAAAO,KAAA,CAAA;qBACL;;eAEAe;;;;;;;gCAOMZ;;;wFAGqB;0FACP;sCAClB,QAAAA,iBAAA,KAAA,IAAA,KAAA,IAAAA,aAAAc,EAAA,MAAAC,aAAA;;sBAEFC,cAAK;2BACDA,cAAc;oCAChB;gBACJ;gBAEAT;iBAEA;gCACO;;;8BAGA;;;;;;;;;;;;oCAYHP,aAAAc,EAAA,KAAAC,aAAA;6BACGf;;;;;;;;;;;;oCAYHA,CAAAA,CAAAA,iBAA6BS,QAAGT,iBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,aAAAA,QAAAA,GAAAA;;;0BAG/BR;;gBAELQ,gBAAAiB,aAAAR,GAAAT;gBACF;YACF,KAAA"}
@@ -0,0 +1,37 @@
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
+ PromptListbox: function() {
13
+ return _PromptListbox.PromptListbox;
14
+ },
15
+ TextCursorPositionPlugin: function() {
16
+ return _TextCursorPositionPlugin.TextCursorPositionPlugin;
17
+ },
18
+ promptListboxClassNames: function() {
19
+ return _PromptListbox.promptListboxClassNames;
20
+ },
21
+ renderPromptListbox_unstable: function() {
22
+ return _PromptListbox.renderPromptListbox_unstable;
23
+ },
24
+ usePromptListboxFunctionality: function() {
25
+ return _usePromptListboxFunctionality.usePromptListboxFunctionality;
26
+ },
27
+ usePromptListboxStyles_unstable: function() {
28
+ return _PromptListbox.usePromptListboxStyles_unstable;
29
+ },
30
+ usePromptListbox_unstable: function() {
31
+ return _PromptListbox.usePromptListbox_unstable;
32
+ }
33
+ });
34
+ const _PromptListbox = require("./PromptListbox");
35
+ const _usePromptListboxFunctionality = require("./components/utils/usePromptListboxFunctionality");
36
+ const _TextCursorPositionPlugin = require("./plugins/TextCursorPositionPlugin");
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export type { PromptListboxProps, PromptListboxSlots, PromptListboxState } from './PromptListbox';\nexport {\n PromptListbox,\n promptListboxClassNames,\n renderPromptListbox_unstable,\n usePromptListboxStyles_unstable,\n usePromptListbox_unstable,\n} from './PromptListbox';\n\nexport { usePromptListboxFunctionality } from './components/utils/usePromptListboxFunctionality';\nexport type {\n OnOpenChangeData,\n ProcessedPromptListboxProps,\n UsePromptListboxFunctionality,\n UsePromptListboxFunctionalityParams,\n} from './components/utils/PromptListboxFunctionality.types';\n\nexport type { TextCursorPositionPluginProps } from './plugins/TextCursorPositionPlugin';\nexport { TextCursorPositionPlugin } from './plugins/TextCursorPositionPlugin';\n"],"names":["PromptListbox","TextCursorPositionPlugin","promptListboxClassNames","renderPromptListbox_unstable","usePromptListboxFunctionality","usePromptListboxStyles_unstable","usePromptListbox_unstable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAEEA,aAAa;eAAbA,4BAAa;;IAgBNC,wBAAwB;eAAxBA,kDAAwB;;IAf/BC,uBAAuB;eAAvBA,sCAAuB;;IACvBC,4BAA4B;eAA5BA,2CAA4B;;IAKrBC,6BAA6B;eAA7BA,4DAA6B;;IAJpCC,+BAA+B;eAA/BA,8CAA+B;;IAC/BC,yBAAyB;eAAzBA,wCAAyB;;;+BACpB;+CAEuC;0CASL"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "TextCursorPositionPlugin", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return TextCursorPositionPlugin;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _chatinputplugins = require("@fluentui-copilot/chat-input-plugins");
13
+ const _reacttexteditor = require("@fluentui-copilot/react-text-editor");
14
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
15
+ const TextCursorPositionPlugin = ({ setIsInLastPosition })=>{
16
+ const [editor] = (0, _reacttexteditor.useLexicalComposerContext)();
17
+ const keypressHandler = (_ev)=>{
18
+ const root = (0, _reacttexteditor.$getRoot)();
19
+ const leafNodes = (0, _reacttexteditor.$getLeafNodes)(root);
20
+ const lastLeafNode = leafNodes.length === 0 ? undefined : leafNodes[leafNodes.length - 1];
21
+ const selection = (0, _reacttexteditor.$getSelection)();
22
+ if (selection === null || !(0, _reacttexteditor.$isRangeSelection)(selection) || !selection.isCollapsed()) {
23
+ setIsInLastPosition(false);
24
+ return false;
25
+ }
26
+ const selectionNodes = selection.getNodes();
27
+ // if we don't have a lead node, then we don't have any nodes, so we are in the last position
28
+ if (selectionNodes.length === 0 || !lastLeafNode) {
29
+ setIsInLastPosition(true);
30
+ return false;
31
+ }
32
+ const lastSelectionNode = selectionNodes[selectionNodes.length - 1];
33
+ // if the selection node is a sentinel and it matches the sentinel at the end
34
+ if ((0, _chatinputplugins.$isSentinelNode)(lastSelectionNode) && lastSelectionNode.is(lastLeafNode)) {
35
+ setIsInLastPosition(true);
36
+ return false;
37
+ } else if ((0, _chatinputplugins.$isSentinelNode)(lastSelectionNode.getNextSibling()) && selection.focus.offset === lastSelectionNode.getTextContentSize()) {
38
+ setIsInLastPosition(true);
39
+ return false;
40
+ }
41
+ setIsInLastPosition(false);
42
+ return false;
43
+ };
44
+ _react.useEffect(()=>{
45
+ return (0, _reacttexteditor.mergeRegister)(editor.registerCommand(_reacttexteditor.KEY_ARROW_DOWN_COMMAND, keypressHandler, _reacttexteditor.COMMAND_PRIORITY_CRITICAL), editor.registerCommand(_reacttexteditor.KEY_ARROW_UP_COMMAND, keypressHandler, _reacttexteditor.COMMAND_PRIORITY_CRITICAL));
46
+ // We are disabling exhaustive-deps because we only want to register the command once on mount and the
47
+ // the teardown function when unmounting
48
+ // eslint-disable-next-line react-compiler/react-compiler
49
+ // eslint-disable-next-line react-hooks/exhaustive-deps
50
+ }, []);
51
+ return null;
52
+ }; //# sourceMappingURL=TextCursorPositionPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["TextCursorPositionPlugin.ts"],"sourcesContent":["import { $isSentinelNode } from '@fluentui-copilot/chat-input-plugins';\nimport {\n COMMAND_PRIORITY_CRITICAL,\n KEY_ARROW_DOWN_COMMAND,\n KEY_ARROW_UP_COMMAND,\n $getSelection,\n useLexicalComposerContext,\n $getLeafNodes,\n $getRoot,\n $isRangeSelection,\n mergeRegister,\n} from '@fluentui-copilot/react-text-editor';\nimport * as React from 'react';\n\nexport type TextCursorPositionPluginProps = {\n setIsInLastPosition: (isInLastPosition: boolean) => void;\n};\n\nexport const TextCursorPositionPlugin: React.FunctionComponent<TextCursorPositionPluginProps> = ({\n setIsInLastPosition,\n}) => {\n const [editor] = useLexicalComposerContext();\n\n const keypressHandler = (_ev: KeyboardEvent) => {\n const root = $getRoot();\n const leafNodes = $getLeafNodes(root);\n const lastLeafNode = leafNodes.length === 0 ? undefined : leafNodes[leafNodes.length - 1];\n const selection = $getSelection();\n if (selection === null || !$isRangeSelection(selection) || !selection.isCollapsed()) {\n setIsInLastPosition(false);\n return false;\n }\n\n const selectionNodes = selection.getNodes();\n // if we don't have a lead node, then we don't have any nodes, so we are in the last position\n if (selectionNodes.length === 0 || !lastLeafNode) {\n setIsInLastPosition(true);\n return false;\n }\n const lastSelectionNode = selectionNodes[selectionNodes.length - 1];\n\n // if the selection node is a sentinel and it matches the sentinel at the end\n if ($isSentinelNode(lastSelectionNode) && lastSelectionNode.is(lastLeafNode)) {\n setIsInLastPosition(true);\n return false;\n }\n // else if the selection node is not a sentinel, check that the next sibling node is a sentinel\n // and check if the focus offset is in the last position of the node.\n else if (\n $isSentinelNode(lastSelectionNode.getNextSibling()) &&\n selection.focus.offset === lastSelectionNode.getTextContentSize()\n ) {\n setIsInLastPosition(true);\n return false;\n }\n\n setIsInLastPosition(false);\n return false;\n };\n\n React.useEffect(() => {\n return mergeRegister(\n editor.registerCommand(KEY_ARROW_DOWN_COMMAND, keypressHandler, COMMAND_PRIORITY_CRITICAL),\n editor.registerCommand(KEY_ARROW_UP_COMMAND, keypressHandler, COMMAND_PRIORITY_CRITICAL),\n );\n // We are disabling exhaustive-deps because we only want to register the command once on mount and the\n // the teardown function when unmounting\n // eslint-disable-next-line react-compiler/react-compiler\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return null;\n};\n"],"names":["TextCursorPositionPlugin","useLexicalComposerContext","editor","root","$getRoot","keypressHandler","$getLeafNodes","lastLeafNode","leafNodes","selection","$getSelection","$isRangeSelection","isCollapsed","setIsInLastPosition","selectionNodes","length","getNodes","lastSelectionNode","is","$isSentinelNode","getNextSibling","focus","offset","getTextContentSize","React","useEffect","mergeRegister","registerCommand","KEY_ARROW_DOWN_COMMAND","COMMAND_PRIORITY_CRITICAL","KEY_ARROW_UP_COMMAND"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAkBaA;;;eAAAA;;;;kCAlBmB;iCAWzB;iEACgB;AAMhB,MAAMA,2BAAmF,CAAC,qBAG9EC;UAGf,CAAAC,OAAMC,GAAAA,IAAAA,0CAAOC;UACbC,kBAAkBC,CAAAA;cAClBH,OAAMI,IAAAA,yBAAAA;cACNC,YAAMC,IAAAA,8BAAYC,EAAAA;cAClBH,eAAIE,UAAuBE,MAAAA,KAAAA,IAAAA,YAAkBF,SAAeA,CAAAA,UAAUG,MAAAA,GAAW,EAAI;0BACnFC,IAAAA,8BAAoB;0BACb,QAAA,CAAAF,IAAAA,kCAAA,EAAAF,cAAA,CAAAA,UAAAG,WAAA,IAAA;gCACT;mBAEA;;cAEAE,iBAAmBC,UAAMC,QAAWT;qGACd;2BACbQ,MAAA,KAAA,KAAA,CAAAR,cAAA;gCACT;mBACA;;cAGAU,oBAAoBA,cAAAA,CAAAA,eAAsBA,MAAAA,GAAkBC,EAAGX;qFACzC;iDACb,EAAAU,sBAAAA,kBAAAC,EAAA,CAAAX,eAAA;gCAKPY;mBAGAN;mBACAM,IAAAA,iCAAO,EAAAF,kBAAAG,cAAA,OAAAX,UAAAY,KAAA,CAAAC,MAAA,KAAAL,kBAAAM,kBAAA,IAAA;gCACT;mBAEAV;;QAEFA,oBAAA;QAEAW,OAAMC;;WAKJA,SAAA,CAAA;QACA,OAAAC,IAAAA,8BAAA,EAAAxB,OAAAyB,eAAwC,CAAAC,uCAAA,EAAAvB,iBAAAwB,0CAAA,GAAA3B,OAAAyB,eAAA,CAAAG,qCAAA,EAAAzB,iBAAAwB,0CAAA;IACxC,sGAAyD;IACzD,wCAAA;IACF,yDAAK;IAEL,uDAAO;IACP,GAAA,EAAA"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@fluentui-copilot/react-prompt-listbox",
3
+ "version": "0.0.0-nightly-20240719-0406-ee8d99d6.1",
4
+ "description": "PromptListbox for input components using EditorInput.",
5
+ "main": "lib-commonjs/index.js",
6
+ "module": "lib/index.js",
7
+ "typings": "./dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/microsoft/fluentai"
12
+ },
13
+ "license": "MIT",
14
+ "dependencies": {
15
+ "@fluentui-copilot/chat-input-plugins": "0.0.0-nightly-20240719-0406-ee8d99d6.1",
16
+ "@fluentui-copilot/react-chat-input-plugins": "0.0.0-nightly-20240719-0406-ee8d99d6.1",
17
+ "@fluentui-copilot/react-editor-input": "0.0.0-nightly-20240719-0406-ee8d99d6.1",
18
+ "@fluentui-copilot/react-provider": "0.0.0-nightly-20240719-0406-ee8d99d6.1",
19
+ "@fluentui-copilot/react-text-editor": "0.0.0-nightly-20240719-0406-ee8d99d6.1",
20
+ "@fluentui-copilot/text-editor": "0.0.0-nightly-20240719-0406-ee8d99d6.1",
21
+ "@swc/helpers": "^0.5.1"
22
+ },
23
+ "peerDependencies": {
24
+ "@fluentui/keyboard-keys": ">=9.0.7 <10.0.0",
25
+ "@fluentui/react-aria": ">=9.13.0 <10.0.0",
26
+ "@fluentui/react-combobox": ">=9.13.0 <10.0.0",
27
+ "@fluentui/react-components": ">=9.54.4 <10.0.0",
28
+ "@fluentui/react-icons": ">=2.0.247 <3.0.0",
29
+ "@fluentui/react-jsx-runtime": ">=9.0.40 <10.0.0",
30
+ "@fluentui/react-positioning": ">=9.15.4 <10.0.0",
31
+ "@fluentui/react-shared-contexts": ">=9.19.0 <10.0.0",
32
+ "@fluentui/react-tabster": ">=9.22.1 <10.0.0",
33
+ "@fluentui/react-utilities": ">=9.18.11 <10.0.0",
34
+ "@types/react": ">=16.14.0 <19.0.0",
35
+ "@types/react-dom": ">=16.9.8 <19.0.0",
36
+ "react": ">=16.14.0 <19.0.0",
37
+ "react-dom": ">=16.14.0 <19.0.0"
38
+ },
39
+ "beachball": {},
40
+ "exports": {
41
+ ".": {
42
+ "types": "./dist/index.d.ts",
43
+ "node": "./lib-commonjs/index.js",
44
+ "import": "./lib/index.js",
45
+ "require": "./lib-commonjs/index.js"
46
+ },
47
+ "./package.json": "./package.json"
48
+ }
49
+ }