@elliemae/ds-form-layout-autocomplete 3.16.0-next.7 → 3.16.0-next.8
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.
- package/dist/cjs/AutocompleteCTX.js +2 -22
- package/dist/cjs/AutocompleteCTX.js.map +2 -2
- package/dist/cjs/config/useAutocomplete.js +20 -48
- package/dist/cjs/config/useAutocomplete.js.map +3 -3
- package/dist/cjs/config/usePopoverLogic.js +105 -0
- package/dist/cjs/config/usePopoverLogic.js.map +7 -0
- package/dist/cjs/{sharedTypes.js → config/useRefs.js} +16 -3
- package/dist/cjs/config/useRefs.js.map +7 -0
- package/dist/cjs/config/useVirtualization.js +62 -0
- package/dist/cjs/config/useVirtualization.js.map +7 -0
- package/dist/cjs/parts/A11yFocusedOption.js +3 -3
- package/dist/cjs/parts/A11yFocusedOption.js.map +2 -2
- package/dist/cjs/parts/container/Container.js +16 -15
- package/dist/cjs/parts/container/Container.js.map +2 -2
- package/dist/cjs/parts/container/useKeyboardNavigation.js +15 -18
- package/dist/cjs/parts/container/useKeyboardNavigation.js.map +2 -2
- package/dist/cjs/parts/menu-list/MenuList.js +6 -3
- package/dist/cjs/parts/menu-list/MenuList.js.map +2 -2
- package/dist/cjs/parts/menu-list/useItemRenderer.js +5 -3
- package/dist/cjs/parts/menu-list/useItemRenderer.js.map +2 -2
- package/dist/cjs/react-desc-prop-types.js +7 -0
- package/dist/cjs/react-desc-prop-types.js.map +2 -2
- package/dist/esm/AutocompleteCTX.js +3 -23
- package/dist/esm/AutocompleteCTX.js.map +2 -2
- package/dist/esm/config/useAutocomplete.js +18 -46
- package/dist/esm/config/useAutocomplete.js.map +3 -3
- package/dist/esm/config/usePopoverLogic.js +79 -0
- package/dist/esm/config/usePopoverLogic.js.map +7 -0
- package/dist/esm/config/useRefs.js +11 -0
- package/dist/esm/config/useRefs.js.map +7 -0
- package/dist/esm/config/useVirtualization.js +36 -0
- package/dist/esm/config/useVirtualization.js.map +7 -0
- package/dist/esm/parts/A11yFocusedOption.js +3 -3
- package/dist/esm/parts/A11yFocusedOption.js.map +2 -2
- package/dist/esm/parts/container/Container.js +17 -16
- package/dist/esm/parts/container/Container.js.map +2 -2
- package/dist/esm/parts/container/useKeyboardNavigation.js +15 -18
- package/dist/esm/parts/container/useKeyboardNavigation.js.map +2 -2
- package/dist/esm/parts/menu-list/MenuList.js +6 -3
- package/dist/esm/parts/menu-list/MenuList.js.map +2 -2
- package/dist/esm/parts/menu-list/useItemRenderer.js +5 -3
- package/dist/esm/parts/menu-list/useItemRenderer.js.map +2 -2
- package/dist/esm/react-desc-prop-types.js +7 -0
- package/dist/esm/react-desc-prop-types.js.map +2 -2
- package/dist/types/AutocompleteCTX.d.ts +2 -4
- package/dist/types/config/useAutocomplete.d.ts +12 -2
- package/dist/types/config/usePopoverLogic.d.ts +12 -0
- package/dist/types/config/useRefs.d.ts +5 -0
- package/dist/types/react-desc-prop-types.d.ts +2 -1
- package/package.json +7 -7
- package/dist/cjs/sharedTypes.js.map +0 -7
- package/dist/esm/sharedTypes.js +0 -2
- package/dist/esm/sharedTypes.js.map +0 -7
- package/dist/types/sharedTypes.d.ts +0 -18
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/parts/container/useKeyboardNavigation.tsx", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport type React from 'react';\nimport { useCallback, useContext } from 'react';\nimport type { DSAutocompleteT } from '../../react-desc-prop-types';\nimport AutocompleteContext from '../../AutocompleteCTX';\nimport { findInCircularList } from '../../utils/listHelper';\n\nconst isOptionFocuseable = (opt: DSAutocompleteT.OptionTypes): boolean => !['section', 'separator'].includes(opt.type);\n\nexport const useKeyboardNavigation = () => {\n const {\n props: { onSelect, options },\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADKvB,mBAAwC;AAExC,6BAAgC;AAChC,wBAAmC;AAEnC,MAAM,qBAAqB,CAAC,QAA8C,CAAC,CAAC,WAAW,WAAW,EAAE,SAAS,IAAI,IAAI;AAE9G,MAAM,wBAAwB,MAAM;AACzC,QAAM;AAAA,IACJ,OAAO,EAAE,UAAU,QAAQ;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,QAAI,yBAAW,uBAAAA,OAAmB;AAElC,QAAM,mBAAmB,QAAQ,UAAU,CAAC,QAAQ,IAAI,SAAS,cAAc;AAC/E,QAAM,cAAc,QAAQ;AAAA,IAC1B,CAAC,SAAS,KAAK,SAAS,YAAY,KAAK,SAAS;AAAA,EACpD;AAEA,QAAM,qBAA+D;AAAA,IACnE,CAAC,MAAM;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport type React from 'react';\nimport { useCallback, useContext } from 'react';\nimport type { DSAutocompleteT } from '../../react-desc-prop-types';\nimport AutocompleteContext from '../../AutocompleteCTX';\nimport { findInCircularList } from '../../utils/listHelper';\n\nconst isOptionFocuseable = (opt: DSAutocompleteT.OptionTypes): boolean => !['section', 'separator'].includes(opt.type);\n\nexport const useKeyboardNavigation = () => {\n const {\n props: { onSelect, options },\n trackUserInteractingViaKeyboard,\n setForceClosePopover,\n isShowingPopover,\n focusOptionIdx,\n setCurrentOption,\n scrollOptionIntoView,\n } = useContext(AutocompleteContext);\n\n const currentItemIndex = options.findIndex((opt) => opt.dsId === focusOptionIdx);\n const currentItem = options.find(\n (item) => item.type === 'option' && item.dsId === focusOptionIdx,\n ) as DSAutocompleteT.ItemOption;\n\n const onInputKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n // =============================================================================\n // TRACK STATE OF POPOVER SHOWING OR NOT\n // =============================================================================\n trackUserInteractingViaKeyboard(e);\n\n if (e.key === 'Tab' || e.key === 'Escape') setForceClosePopover(true);\n\n // =============================================================================\n // ENTER AND SPACE KEY SELECT OPTIONS AND OPEN CLOSE THE POPOVER\n // =============================================================================\n if (e.key === 'Enter' && isShowingPopover) {\n e.preventDefault();\n onSelect(currentItem?.label, e);\n }\n\n // =============================================================================\n // ARROWS UP AND DOWN\n // =============================================================================\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n if (isShowingPopover) {\n const nextItemIndex = findInCircularList(options, currentItemIndex, isOptionFocuseable);\n setCurrentOption(options[nextItemIndex].dsId);\n scrollOptionIntoView(options[nextItemIndex].dsId);\n }\n }\n if (e.key === 'ArrowUp') {\n e.preventDefault();\n if (isShowingPopover) {\n const nextItemIndex = findInCircularList(options, currentItemIndex, isOptionFocuseable, -1);\n setCurrentOption(options[nextItemIndex].dsId);\n scrollOptionIntoView(options[nextItemIndex].dsId);\n }\n }\n },\n [\n trackUserInteractingViaKeyboard,\n setForceClosePopover,\n isShowingPopover,\n onSelect,\n currentItem?.label,\n options,\n currentItemIndex,\n setCurrentOption,\n scrollOptionIntoView,\n ],\n );\n\n return { onInputKeyDown };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADKvB,mBAAwC;AAExC,6BAAgC;AAChC,wBAAmC;AAEnC,MAAM,qBAAqB,CAAC,QAA8C,CAAC,CAAC,WAAW,WAAW,EAAE,SAAS,IAAI,IAAI;AAE9G,MAAM,wBAAwB,MAAM;AACzC,QAAM;AAAA,IACJ,OAAO,EAAE,UAAU,QAAQ;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,QAAI,yBAAW,uBAAAA,OAAmB;AAElC,QAAM,mBAAmB,QAAQ,UAAU,CAAC,QAAQ,IAAI,SAAS,cAAc;AAC/E,QAAM,cAAc,QAAQ;AAAA,IAC1B,CAAC,SAAS,KAAK,SAAS,YAAY,KAAK,SAAS;AAAA,EACpD;AAEA,QAAM,qBAA+D;AAAA,IACnE,CAAC,MAAM;AAIL,sCAAgC,CAAC;AAEjC,UAAI,EAAE,QAAQ,SAAS,EAAE,QAAQ;AAAU,6BAAqB,IAAI;AAKpE,UAAI,EAAE,QAAQ,WAAW,kBAAkB;AACzC,UAAE,eAAe;AACjB,iBAAS,aAAa,OAAO,CAAC;AAAA,MAChC;AAKA,UAAI,EAAE,QAAQ,aAAa;AACzB,UAAE,eAAe;AACjB,YAAI,kBAAkB;AACpB,gBAAM,oBAAgB,sCAAmB,SAAS,kBAAkB,kBAAkB;AACtF,2BAAiB,QAAQ,eAAe,IAAI;AAC5C,+BAAqB,QAAQ,eAAe,IAAI;AAAA,QAClD;AAAA,MACF;AACA,UAAI,EAAE,QAAQ,WAAW;AACvB,UAAE,eAAe;AACjB,YAAI,kBAAkB;AACpB,gBAAM,oBAAgB,sCAAmB,SAAS,kBAAkB,oBAAoB,EAAE;AAC1F,2BAAiB,QAAQ,eAAe,IAAI;AAC5C,+BAAqB,QAAQ,eAAe,IAAI;AAAA,QAClD;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,eAAe;AAC1B;",
|
|
6
6
|
"names": ["AutocompleteContext"]
|
|
7
7
|
}
|
|
@@ -40,7 +40,7 @@ const MenuList = () => {
|
|
|
40
40
|
referenceElement,
|
|
41
41
|
inputRef,
|
|
42
42
|
listRef,
|
|
43
|
-
|
|
43
|
+
isShowingPopover,
|
|
44
44
|
virtualListHelpers: { totalSize }
|
|
45
45
|
} = (0, import_react.useContext)(import_AutocompleteCTX.default);
|
|
46
46
|
const ItemRenderer = (0, import_useItemRenderer.useItemRenderer)();
|
|
@@ -48,11 +48,14 @@ const MenuList = () => {
|
|
|
48
48
|
inputRef.current?.focus();
|
|
49
49
|
}, [inputRef]);
|
|
50
50
|
const idList = (0, import_react.useMemo)(() => `${id ? `${id}-` : ""}listbox`, [id]);
|
|
51
|
+
const preventMouseDown = (0, import_react.useCallback)((e) => {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
}, []);
|
|
51
54
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
52
55
|
import_styled.StyledListWrapper,
|
|
53
56
|
{
|
|
54
57
|
tabIndex: -1,
|
|
55
|
-
onMouseDown:
|
|
58
|
+
onMouseDown: preventMouseDown,
|
|
56
59
|
minWidth: referenceElement?.offsetWidth,
|
|
57
60
|
id: idList,
|
|
58
61
|
role: "listbox",
|
|
@@ -60,7 +63,7 @@ const MenuList = () => {
|
|
|
60
63
|
import_styled.StyledList,
|
|
61
64
|
{
|
|
62
65
|
tabIndex: -1,
|
|
63
|
-
"aria-expanded":
|
|
66
|
+
"aria-expanded": isShowingPopover,
|
|
64
67
|
onFocus: handleOnFocus,
|
|
65
68
|
"data-testid": import_AutocompleteDataTestids.AutocompleteDataTestid.LIST,
|
|
66
69
|
style: { height: totalSize, margin: "8px 0px" },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/parts/menu-list/MenuList.tsx", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import React, { useContext, useMemo, useCallback } from 'react';\nimport { StyledListWrapper, StyledList, StyledVirtualListWrapper } from './styled';\nimport { AutocompleteDataTestid } from '../../AutocompleteDataTestids';\nimport AutocompleteContext from '../../AutocompleteCTX';\nimport { useItemRenderer } from './useItemRenderer';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
4
|
+
"sourcesContent": ["import React, { useContext, useMemo, useCallback } from 'react';\nimport { StyledListWrapper, StyledList, StyledVirtualListWrapper } from './styled';\nimport { AutocompleteDataTestid } from '../../AutocompleteDataTestids';\nimport AutocompleteContext from '../../AutocompleteCTX';\nimport { useItemRenderer } from './useItemRenderer';\n\nexport const MenuList = (): JSX.Element => {\n const {\n props: { options, id },\n referenceElement,\n inputRef,\n listRef,\n isShowingPopover,\n virtualListHelpers: { totalSize },\n } = useContext(AutocompleteContext);\n\n const ItemRenderer = useItemRenderer();\n\n const handleOnFocus = useCallback(() => {\n inputRef.current?.focus();\n }, [inputRef]);\n\n const idList = useMemo(() => `${id ? `${id}-` : ''}listbox`, [id]);\n const preventMouseDown: React.MouseEventHandler<HTMLDivElement> = useCallback((e) => {\n e.preventDefault();\n }, []);\n\n return (\n <StyledListWrapper\n tabIndex={-1}\n onMouseDown={preventMouseDown}\n minWidth={referenceElement?.offsetWidth}\n id={idList}\n role=\"listbox\"\n >\n {options.length > 0 && (\n <StyledVirtualListWrapper tabIndex={-1} ref={listRef}>\n <StyledList\n tabIndex={-1}\n aria-expanded={isShowingPopover}\n onFocus={handleOnFocus}\n data-testid={AutocompleteDataTestid.LIST}\n style={{ height: totalSize, margin: '8px 0px' }}\n >\n {ItemRenderer}\n </StyledList>\n </StyledVirtualListWrapper>\n )}\n </StyledListWrapper>\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADqCb;AArCV,mBAAwD;AACxD,oBAAwE;AACxE,qCAAuC;AACvC,6BAAgC;AAChC,6BAAgC;AAEzB,MAAM,WAAW,MAAmB;AACzC,QAAM;AAAA,IACJ,OAAO,EAAE,SAAS,GAAG;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,oBAAoB,EAAE,UAAU;AAAA,EAClC,QAAI,yBAAW,uBAAAA,OAAmB;AAElC,QAAM,mBAAe,wCAAgB;AAErC,QAAM,oBAAgB,0BAAY,MAAM;AACtC,aAAS,SAAS,MAAM;AAAA,EAC1B,GAAG,CAAC,QAAQ,CAAC;AAEb,QAAM,aAAS,sBAAQ,MAAM,GAAG,KAAK,GAAG,QAAQ,aAAa,CAAC,EAAE,CAAC;AACjE,QAAM,uBAA4D,0BAAY,CAAC,MAAM;AACnF,MAAE,eAAe;AAAA,EACnB,GAAG,CAAC,CAAC;AAEL,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU;AAAA,MACV,aAAa;AAAA,MACb,UAAU,kBAAkB;AAAA,MAC5B,IAAI;AAAA,MACJ,MAAK;AAAA,MAEJ,kBAAQ,SAAS,KAChB,4CAAC,0CAAyB,UAAU,IAAI,KAAK,SAC3C;AAAA,QAAC;AAAA;AAAA,UACC,UAAU;AAAA,UACV,iBAAe;AAAA,UACf,SAAS;AAAA,UACT,eAAa,sDAAuB;AAAA,UACpC,OAAO,EAAE,QAAQ,WAAW,QAAQ,UAAU;AAAA,UAE7C;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EAEJ;AAEJ;",
|
|
6
6
|
"names": ["AutocompleteContext"]
|
|
7
7
|
}
|
|
@@ -37,18 +37,20 @@ const useItemRenderer = () => {
|
|
|
37
37
|
const {
|
|
38
38
|
props: { options, onSelect },
|
|
39
39
|
inputRef,
|
|
40
|
-
|
|
40
|
+
setUserTypedSomething,
|
|
41
|
+
setUserJustSelectedAnOption,
|
|
41
42
|
focusOptionIdx,
|
|
42
43
|
virtualListHelpers
|
|
43
44
|
} = (0, import_react.useContext)(import_AutocompleteCTX.default);
|
|
44
45
|
const handleClick = (0, import_react.useCallback)(
|
|
45
46
|
(option, e) => {
|
|
46
47
|
onSelect(option.label, e);
|
|
47
|
-
|
|
48
|
+
setUserJustSelectedAnOption(true);
|
|
49
|
+
setUserTypedSomething(false);
|
|
48
50
|
e.stopPropagation();
|
|
49
51
|
e.preventDefault();
|
|
50
52
|
},
|
|
51
|
-
[onSelect,
|
|
53
|
+
[onSelect, setUserTypedSomething, setUserJustSelectedAnOption]
|
|
52
54
|
);
|
|
53
55
|
return (0, import_react.useMemo)(() => {
|
|
54
56
|
if (virtualListHelpers) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/parts/menu-list/useItemRenderer.tsx", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable react-hooks/exhaustive-deps */\nimport React, { useMemo, useContext, useCallback } from 'react';\nimport { SingleMenuItem, Section } from '@elliemae/ds-menu-items';\nimport AutocompleteContext from '../../AutocompleteCTX';\nimport { AutocompleteDataTestid } from '../../AutocompleteDataTestids';\nimport type { DSAutocompleteT } from '../../react-desc-prop-types';\n\nexport const useItemRenderer = (): Array<JSX.Element> | null => {\n const {\n props: { options, onSelect },\n inputRef,\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable react-hooks/exhaustive-deps */\nimport React, { useMemo, useContext, useCallback } from 'react';\nimport { SingleMenuItem, Section } from '@elliemae/ds-menu-items';\nimport AutocompleteContext from '../../AutocompleteCTX';\nimport { AutocompleteDataTestid } from '../../AutocompleteDataTestids';\nimport type { DSAutocompleteT } from '../../react-desc-prop-types';\n\nexport const useItemRenderer = (): Array<JSX.Element> | null => {\n const {\n props: { options, onSelect },\n inputRef,\n setUserTypedSomething,\n setUserJustSelectedAnOption,\n focusOptionIdx,\n virtualListHelpers,\n } = useContext(AutocompleteContext);\n\n const handleClick = useCallback(\n (option: DSAutocompleteT.ItemOption, e: React.MouseEvent<HTMLInputElement>) => {\n onSelect(option.label, e);\n setUserJustSelectedAnOption(true);\n setUserTypedSomething(false);\n e.stopPropagation();\n e.preventDefault();\n },\n [onSelect, setUserTypedSomething, setUserJustSelectedAnOption],\n );\n\n return useMemo(() => {\n if (virtualListHelpers) {\n return virtualListHelpers.virtualItems.map((vItem) => {\n const option = options[vItem.index];\n const generalProps = {\n wrapperStyles: { position: 'absolute', top: vItem.start, left: 0, width: '100%' },\n key: `${option.dsId}`,\n innerRef: vItem.measureRef,\n };\n if (option.type === 'section') {\n return <Section label={option.label} {...generalProps} />;\n }\n if (option.type === 'option') {\n return (\n <SingleMenuItem\n {...generalProps}\n value={option.value}\n label={option.label}\n dataTestid={AutocompleteDataTestid.OPTION}\n disabled={option.disabled}\n onClick={(e: React.MouseEvent<HTMLInputElement>) => handleClick(option, e)}\n isActive={option.dsId === focusOptionIdx}\n />\n );\n }\n return <></>;\n });\n }\n return null;\n }, [options, focusOptionIdx, inputRef, virtualListHelpers]);\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADsCN;AArCjB,mBAAwD;AACxD,2BAAwC;AACxC,6BAAgC;AAChC,qCAAuC;AAGhC,MAAM,kBAAkB,MAAiC;AAC9D,QAAM;AAAA,IACJ,OAAO,EAAE,SAAS,SAAS;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,QAAI,yBAAW,uBAAAA,OAAmB;AAElC,QAAM,kBAAc;AAAA,IAClB,CAAC,QAAoC,MAA0C;AAC7E,eAAS,OAAO,OAAO,CAAC;AACxB,kCAA4B,IAAI;AAChC,4BAAsB,KAAK;AAC3B,QAAE,gBAAgB;AAClB,QAAE,eAAe;AAAA,IACnB;AAAA,IACA,CAAC,UAAU,uBAAuB,2BAA2B;AAAA,EAC/D;AAEA,aAAO,sBAAQ,MAAM;AACnB,QAAI,oBAAoB;AACtB,aAAO,mBAAmB,aAAa,IAAI,CAAC,UAAU;AACpD,cAAM,SAAS,QAAQ,MAAM;AAC7B,cAAM,eAAe;AAAA,UACnB,eAAe,EAAE,UAAU,YAAY,KAAK,MAAM,OAAO,MAAM,GAAG,OAAO,OAAO;AAAA,UAChF,KAAK,GAAG,OAAO;AAAA,UACf,UAAU,MAAM;AAAA,QAClB;AACA,YAAI,OAAO,SAAS,WAAW;AAC7B,iBAAO,4CAAC,gCAAQ,OAAO,OAAO,OAAQ,GAAG,cAAc;AAAA,QACzD;AACA,YAAI,OAAO,SAAS,UAAU;AAC5B,iBACE;AAAA,YAAC;AAAA;AAAA,cACE,GAAG;AAAA,cACJ,OAAO,OAAO;AAAA,cACd,OAAO,OAAO;AAAA,cACd,YAAY,sDAAuB;AAAA,cACnC,UAAU,OAAO;AAAA,cACjB,SAAS,CAAC,MAA0C,YAAY,QAAQ,CAAC;AAAA,cACzE,UAAU,OAAO,SAAS;AAAA;AAAA,UAC5B;AAAA,QAEJ;AACA,eAAO,2EAAE;AAAA,MACX,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT,GAAG,CAAC,SAAS,gBAAgB,UAAU,kBAAkB,CAAC;AAC5D;",
|
|
6
6
|
"names": ["AutocompleteContext"]
|
|
7
7
|
}
|
|
@@ -24,11 +24,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var react_desc_prop_types_exports = {};
|
|
26
26
|
__export(react_desc_prop_types_exports, {
|
|
27
|
+
defaultProps: () => defaultProps,
|
|
27
28
|
propTypes: () => propTypes
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(react_desc_prop_types_exports);
|
|
30
31
|
var React = __toESM(require("react"));
|
|
31
32
|
var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
|
|
33
|
+
const defaultProps = {
|
|
34
|
+
zIndex: 10,
|
|
35
|
+
withoutPortal: false,
|
|
36
|
+
startPlacementPreference: "bottom-start",
|
|
37
|
+
placementOrderPreference: ["bottom-start", "bottom-end"]
|
|
38
|
+
};
|
|
32
39
|
const propTypes = {
|
|
33
40
|
options: import_ds_props_helpers.PropTypes.oneOfType([import_ds_props_helpers.PropTypes.array, import_ds_props_helpers.PropTypes.object]).isRequired.description("List of options").defaultValue([]),
|
|
34
41
|
filter: import_ds_props_helpers.PropTypes.string.isRequired.description("String value to filter the options").defaultValue(""),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/react-desc-prop-types.ts", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-unused-vars */\nimport type React from 'react';\nimport { PropTypes } from '@elliemae/ds-props-helpers';\n\nexport declare namespace DSAutocompleteT {\n export interface CommonItemOptions {\n dsId: string;\n disabled?: boolean;\n render?: React.ComponentType<unknown>;\n }\n export interface ItemSeparatorOptions extends CommonItemOptions {\n type: 'separator';\n }\n\n export interface ItemSectionOptions extends CommonItemOptions {\n type: 'section';\n label: string;\n }\n\n export interface ItemOption extends CommonItemOptions {\n value: string;\n label: string;\n type: 'option';\n }\n\n export type OptionTypes = ItemOption | ItemSectionOptions | ItemSeparatorOptions;\n\n export type SelectedOptionsT = ItemOption[] | ItemOption | null;\n\n export interface RequiredProps {\n options: OptionTypes[];\n children: React.ReactChild;\n filter: string;\n onSelect: (suggestedValue: string | number
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADGvB,8BAA0B;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-unused-vars */\nimport type React from 'react';\nimport { PropTypes } from '@elliemae/ds-props-helpers';\n\nexport declare namespace DSAutocompleteT {\n export interface CommonItemOptions {\n dsId: string;\n disabled?: boolean;\n render?: React.ComponentType<unknown>;\n }\n export interface ItemSeparatorOptions extends CommonItemOptions {\n type: 'separator';\n }\n\n export interface ItemSectionOptions extends CommonItemOptions {\n type: 'section';\n label: string;\n }\n\n export interface ItemOption extends CommonItemOptions {\n value: string;\n label: string;\n type: 'option';\n }\n\n export type OptionTypes = ItemOption | ItemSectionOptions | ItemSeparatorOptions;\n\n export type SelectedOptionsT = ItemOption[] | ItemOption | null;\n\n export interface RequiredProps {\n options: OptionTypes[];\n children: React.ReactChild;\n filter: string;\n onSelect: (\n suggestedValue: string | number,\n e: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLInputElement>,\n ) => void;\n }\n export interface DefaultProps {\n startPlacementPreference: string;\n placementOrderPreference: string[];\n withoutPortal: boolean;\n zIndex: number;\n }\n\n export interface Props extends Partial<DefaultProps>, RequiredProps {}\n\n export interface InternalProps extends DefaultProps, RequiredProps {}\n}\n\nexport const defaultProps: DSAutocompleteT.DefaultProps = {\n zIndex: 10,\n withoutPortal: false,\n startPlacementPreference: 'bottom-start',\n placementOrderPreference: ['bottom-start', 'bottom-end'],\n};\n\nexport const propTypes = {\n options: PropTypes.oneOfType([PropTypes.array, PropTypes.object])\n .isRequired.description('List of options')\n .defaultValue([]),\n filter: PropTypes.string.isRequired.description('String value to filter the options').defaultValue(''),\n onSelect: PropTypes.func.isRequired\n .description('function triggered when an option is selected it will send the options selected')\n .defaultValue(''),\n children: PropTypes.node.isRequired\n .description('React component to apply autocomplete functionality')\n .defaultValue(''),\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADGvB,8BAA0B;AAgDnB,MAAM,eAA6C;AAAA,EACxD,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,0BAA0B;AAAA,EAC1B,0BAA0B,CAAC,gBAAgB,YAAY;AACzD;AAEO,MAAM,YAAY;AAAA,EACvB,SAAS,kCAAU,UAAU,CAAC,kCAAU,OAAO,kCAAU,MAAM,CAAC,EAC7D,WAAW,YAAY,iBAAiB,EACxC,aAAa,CAAC,CAAC;AAAA,EAClB,QAAQ,kCAAU,OAAO,WAAW,YAAY,oCAAoC,EAAE,aAAa,EAAE;AAAA,EACrG,UAAU,kCAAU,KAAK,WACtB,YAAY,iFAAiF,EAC7F,aAAa,EAAE;AAAA,EAClB,UAAU,kCAAU,KAAK,WACtB,YAAY,qDAAqD,EACjE,aAAa,EAAE;AACpB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,30 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { createContext
|
|
3
|
-
const
|
|
4
|
-
};
|
|
5
|
-
const defaultProps = {
|
|
6
|
-
zIndex: 10,
|
|
7
|
-
withoutPortal: false,
|
|
8
|
-
startPlacementPreference: "bottom-start",
|
|
9
|
-
placementOrderPreference: ["bottom-start", "bottom-end"]
|
|
10
|
-
};
|
|
11
|
-
const defaultContext = {
|
|
12
|
-
props: defaultProps,
|
|
13
|
-
showPopover: false,
|
|
14
|
-
setShowPopover: noop,
|
|
15
|
-
scrollOptionIntoView: noop,
|
|
16
|
-
referenceElement: null,
|
|
17
|
-
setReferenceElement: noop,
|
|
18
|
-
inputRef: createRef(),
|
|
19
|
-
listRef: createRef(),
|
|
20
|
-
focusOptionIdx: "",
|
|
21
|
-
setCurrentOption: noop
|
|
22
|
-
};
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
const defaultContext = {};
|
|
23
4
|
const AutocompleteContext = createContext(defaultContext);
|
|
24
5
|
var AutocompleteCTX_default = AutocompleteContext;
|
|
25
6
|
export {
|
|
26
7
|
AutocompleteContext,
|
|
27
|
-
AutocompleteCTX_default as default
|
|
28
|
-
defaultProps
|
|
8
|
+
AutocompleteCTX_default as default
|
|
29
9
|
};
|
|
30
10
|
//# sourceMappingURL=AutocompleteCTX.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/AutocompleteCTX.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { createContext
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { createContext } from 'react';\nimport type { AutocompleteContextT } from './config/useAutocomplete';\n\nconst defaultContext = {} as AutocompleteContextT;\n/** Context for cross component communication */\nexport const AutocompleteContext = createContext<AutocompleteContextT>(defaultContext);\n\nexport default AutocompleteContext;\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,qBAAqB;AAG9B,MAAM,iBAAiB,CAAC;AAEjB,MAAM,sBAAsB,cAAoC,cAAc;AAErF,IAAO,0BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { useMemo, useState,
|
|
3
|
-
import { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-
|
|
4
|
-
import {
|
|
5
|
-
import { propTypes } from "../react-desc-prop-types";
|
|
6
|
-
import { defaultProps } from "../AutocompleteCTX";
|
|
2
|
+
import React2, { useMemo, useState, useRef } from "react";
|
|
3
|
+
import { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-utilities";
|
|
4
|
+
import { propTypes, defaultProps } from "../react-desc-prop-types";
|
|
7
5
|
import { getFirstOption } from "../utils/listHelper";
|
|
8
6
|
import { DSAutocompleteName } from "../DSAutocompleteDefinitions";
|
|
7
|
+
import { useRefs } from "./useRefs";
|
|
8
|
+
import { useVirtualization } from "./useVirtualization";
|
|
9
|
+
import { usePopoverLogic } from "./usePopoverLogic";
|
|
9
10
|
const useAutocomplete = (props) => {
|
|
10
11
|
const defaultPropsWithInnerRef = {
|
|
11
12
|
...defaultProps,
|
|
@@ -13,59 +14,30 @@ const useAutocomplete = (props) => {
|
|
|
13
14
|
};
|
|
14
15
|
const propsWithDefault = useMemoMergePropsWithDefault(props, defaultPropsWithInnerRef);
|
|
15
16
|
useValidateTypescriptPropTypes(propsWithDefault, propTypes, DSAutocompleteName);
|
|
16
|
-
const
|
|
17
|
+
const { options } = propsWithDefault;
|
|
17
18
|
const [referenceElement, setReferenceElement] = useState(null);
|
|
18
19
|
const [focusOptionIdx, setCurrentOption] = useState("");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
size: options.length,
|
|
24
|
-
parentRef: listRef,
|
|
25
|
-
overscan: 15,
|
|
26
|
-
paddingStart: 0
|
|
20
|
+
const references = useRefs();
|
|
21
|
+
const virtualizationManager = useVirtualization({
|
|
22
|
+
references,
|
|
23
|
+
propsWithDefault
|
|
27
24
|
});
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
virtualListHelpers.scrollToIndex(
|
|
31
|
-
options.findIndex((opt) => opt.dsId === dsId),
|
|
32
|
-
opts
|
|
33
|
-
);
|
|
34
|
-
},
|
|
35
|
-
[options, virtualListHelpers]
|
|
36
|
-
);
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
if (filter.length === 0 || options.length === 0) {
|
|
39
|
-
setShowPopover(false);
|
|
40
|
-
}
|
|
41
|
-
}, [filter, options.length, setShowPopover]);
|
|
42
|
-
useEffect(() => {
|
|
25
|
+
const popoverManager = usePopoverLogic(propsWithDefault);
|
|
26
|
+
React2.useEffect(() => {
|
|
43
27
|
setCurrentOption(getFirstOption(options));
|
|
44
|
-
}, [options
|
|
28
|
+
}, [options]);
|
|
45
29
|
const ctx = useMemo(
|
|
46
30
|
() => ({
|
|
47
31
|
props: { ...propsWithDefault },
|
|
48
|
-
virtualListHelpers,
|
|
49
|
-
showPopover,
|
|
50
32
|
referenceElement,
|
|
51
|
-
inputRef,
|
|
52
|
-
listRef,
|
|
53
33
|
focusOptionIdx,
|
|
54
34
|
setCurrentOption,
|
|
55
|
-
scrollOptionIntoView,
|
|
56
35
|
setReferenceElement,
|
|
57
|
-
|
|
36
|
+
...references,
|
|
37
|
+
...popoverManager,
|
|
38
|
+
...virtualizationManager
|
|
58
39
|
}),
|
|
59
|
-
[
|
|
60
|
-
scrollOptionIntoView,
|
|
61
|
-
propsWithDefault,
|
|
62
|
-
virtualListHelpers,
|
|
63
|
-
focusOptionIdx,
|
|
64
|
-
showPopover,
|
|
65
|
-
referenceElement,
|
|
66
|
-
inputRef,
|
|
67
|
-
listRef
|
|
68
|
-
]
|
|
40
|
+
[propsWithDefault, referenceElement, focusOptionIdx, popoverManager, references, virtualizationManager]
|
|
69
41
|
);
|
|
70
42
|
return ctx;
|
|
71
43
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useAutocomplete.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable import/prefer-default-export */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\nimport { useMemo, useState,
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACIvB,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable import/prefer-default-export */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\nimport React, { useMemo, useState, useRef } from 'react';\nimport { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-utilities';\nimport type { DSAutocompleteT } from '../react-desc-prop-types';\nimport { propTypes, defaultProps } from '../react-desc-prop-types';\nimport { getFirstOption } from '../utils/listHelper';\nimport { DSAutocompleteName } from '../DSAutocompleteDefinitions';\nimport { useRefs } from './useRefs';\nimport { useVirtualization } from './useVirtualization';\nimport { usePopoverLogic } from './usePopoverLogic';\n\nexport type AutocompleteContextT = ReturnType<typeof useRefs> &\n ReturnType<typeof useVirtualization> &\n ReturnType<typeof usePopoverLogic> & {\n props: DSAutocompleteT.InternalProps;\n referenceElement: HTMLElement | null;\n focusOptionIdx: string;\n setCurrentOption: React.Dispatch<React.SetStateAction<string>>;\n setReferenceElement: React.Dispatch<React.SetStateAction<HTMLElement | null>>;\n };\n\nexport const useAutocomplete = (props: DSAutocompleteT.Props): AutocompleteContextT => {\n const defaultPropsWithInnerRef = {\n ...defaultProps,\n innerRef: useRef(null),\n };\n const propsWithDefault = useMemoMergePropsWithDefault(props, defaultPropsWithInnerRef);\n useValidateTypescriptPropTypes(propsWithDefault, propTypes, DSAutocompleteName);\n\n const { options } = propsWithDefault;\n const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null);\n const [focusOptionIdx, setCurrentOption] = useState<string>('');\n\n const references = useRefs();\n\n const virtualizationManager = useVirtualization({\n references,\n propsWithDefault,\n });\n\n const popoverManager = usePopoverLogic(propsWithDefault);\n\n React.useEffect(() => {\n setCurrentOption(getFirstOption(options));\n }, [options]);\n\n const ctx = useMemo(\n () => ({\n props: { ...propsWithDefault },\n referenceElement,\n focusOptionIdx,\n setCurrentOption,\n setReferenceElement,\n ...references,\n ...popoverManager,\n ...virtualizationManager,\n }),\n [propsWithDefault, referenceElement, focusOptionIdx, popoverManager, references, virtualizationManager],\n );\n\n return ctx;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACIvB,OAAOA,UAAS,SAAS,UAAU,cAAc;AACjD,SAAS,8BAA8B,sCAAsC;AAE7E,SAAS,WAAW,oBAAoB;AACxC,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,eAAe;AACxB,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAYzB,MAAM,kBAAkB,CAAC,UAAuD;AACrF,QAAM,2BAA2B;AAAA,IAC/B,GAAG;AAAA,IACH,UAAU,OAAO,IAAI;AAAA,EACvB;AACA,QAAM,mBAAmB,6BAA6B,OAAO,wBAAwB;AACrF,iCAA+B,kBAAkB,WAAW,kBAAkB;AAE9E,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAA6B,IAAI;AACjF,QAAM,CAAC,gBAAgB,gBAAgB,IAAI,SAAiB,EAAE;AAE9D,QAAM,aAAa,QAAQ;AAE3B,QAAM,wBAAwB,kBAAkB;AAAA,IAC9C;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,iBAAiB,gBAAgB,gBAAgB;AAEvD,EAAAA,OAAM,UAAU,MAAM;AACpB,qBAAiB,eAAe,OAAO,CAAC;AAAA,EAC1C,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,MAAM;AAAA,IACV,OAAO;AAAA,MACL,OAAO,EAAE,GAAG,iBAAiB;AAAA,MAC7B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,MACH,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,IACA,CAAC,kBAAkB,kBAAkB,gBAAgB,gBAAgB,YAAY,qBAAqB;AAAA,EACxG;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2, { useState, useEffect } from "react";
|
|
3
|
+
const usePopoverLogic = (propsWithDefault) => {
|
|
4
|
+
const { options, filter } = propsWithDefault;
|
|
5
|
+
const [forceClosePopover, setForceClosePopover] = useState(false);
|
|
6
|
+
const [userTypedSomething, setUserTypedSomething] = useState(false);
|
|
7
|
+
const [userIsNavigatingWithArrows, setUserIsNavigatingWithArrows] = useState(false);
|
|
8
|
+
const [userJustSelectedAnOption, setUserJustSelectedAnOption] = useState(false);
|
|
9
|
+
const userSelectedAndDidNotType = userJustSelectedAnOption && !userTypedSomething;
|
|
10
|
+
const popoverHasAnythingToShow = options.length > 0 && filter.length > 0;
|
|
11
|
+
const isShowingPopover = !forceClosePopover && popoverHasAnythingToShow && !userSelectedAndDidNotType && (userTypedSomething || userIsNavigatingWithArrows);
|
|
12
|
+
const trackUserTyping = React2.useCallback(
|
|
13
|
+
(e) => {
|
|
14
|
+
const { key } = e;
|
|
15
|
+
if ([...e.key].length === 1 || key === "Backspace" || key === "Delete") {
|
|
16
|
+
setUserTypedSomething(true);
|
|
17
|
+
setForceClosePopover(false);
|
|
18
|
+
setUserJustSelectedAnOption(false);
|
|
19
|
+
} else {
|
|
20
|
+
setUserTypedSomething(false);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
[setUserTypedSomething]
|
|
24
|
+
);
|
|
25
|
+
const trackUserNavigatingWithArrows = React2.useCallback(
|
|
26
|
+
(e) => {
|
|
27
|
+
const { key } = e;
|
|
28
|
+
if (isShowingPopover && (key === "ArrowUp" || key === "ArrowDown")) {
|
|
29
|
+
setUserIsNavigatingWithArrows(true);
|
|
30
|
+
} else {
|
|
31
|
+
setUserIsNavigatingWithArrows(false);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
[isShowingPopover]
|
|
35
|
+
);
|
|
36
|
+
const trackUserSelectingAnOption = React2.useCallback(
|
|
37
|
+
(e) => {
|
|
38
|
+
const { key } = e;
|
|
39
|
+
if (key === "Enter" && isShowingPopover) {
|
|
40
|
+
setUserJustSelectedAnOption(true);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
[isShowingPopover]
|
|
44
|
+
);
|
|
45
|
+
const trackUserInteractingViaKeyboard = React2.useCallback(
|
|
46
|
+
(e) => {
|
|
47
|
+
trackUserTyping(e);
|
|
48
|
+
trackUserNavigatingWithArrows(e);
|
|
49
|
+
trackUserSelectingAnOption(e);
|
|
50
|
+
},
|
|
51
|
+
[trackUserTyping, trackUserNavigatingWithArrows, trackUserSelectingAnOption]
|
|
52
|
+
);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const closePopper = () => {
|
|
55
|
+
setForceClosePopover(true);
|
|
56
|
+
};
|
|
57
|
+
window.addEventListener("blur", closePopper);
|
|
58
|
+
return () => {
|
|
59
|
+
window.removeEventListener("blur", closePopper);
|
|
60
|
+
};
|
|
61
|
+
}, []);
|
|
62
|
+
return React2.useMemo(
|
|
63
|
+
() => ({
|
|
64
|
+
isShowingPopover,
|
|
65
|
+
forceClosePopover,
|
|
66
|
+
setForceClosePopover,
|
|
67
|
+
userTypedSomething,
|
|
68
|
+
setUserTypedSomething,
|
|
69
|
+
setUserJustSelectedAnOption,
|
|
70
|
+
setUserIsNavigatingWithArrows,
|
|
71
|
+
trackUserInteractingViaKeyboard
|
|
72
|
+
}),
|
|
73
|
+
[isShowingPopover, forceClosePopover, userTypedSomething, trackUserInteractingViaKeyboard]
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
export {
|
|
77
|
+
usePopoverLogic
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=usePopoverLogic.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/usePopoverLogic.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useState, useEffect } from 'react';\nimport type { DSAutocompleteT } from '../react-desc-prop-types';\n\n// we want to own all the popover logic in a single place\n// we handle global events via window.addEventListener/RemoveEventListener\n// the logic to show/hide the popover accounts for\n// show:\n// - the user just typed something (excluding special keys like arrows, enter, etc)\n// - any options are available\n// - the user did not just select an option\n// N.B. this must react to options.length changing in an async way\n// hide:\n// - the user just selected an option and did not type anything after\n// - no options are available\n// - the focus is not on the input\n// - the user pressed the escape key\nexport const usePopoverLogic = (propsWithDefault: DSAutocompleteT.InternalProps) => {\n const { options, filter } = propsWithDefault;\n\n const [forceClosePopover, setForceClosePopover] = useState<boolean>(false);\n\n const [userTypedSomething, setUserTypedSomething] = useState<boolean>(false);\n const [userIsNavigatingWithArrows, setUserIsNavigatingWithArrows] = useState<boolean>(false);\n const [userJustSelectedAnOption, setUserJustSelectedAnOption] = useState<boolean>(false);\n\n const userSelectedAndDidNotType = userJustSelectedAnOption && !userTypedSomething;\n const popoverHasAnythingToShow = options.length > 0 && filter.length > 0;\n\n const isShowingPopover =\n !forceClosePopover && // user pressed escape (or other interaction that forces close) --> hide popover\n popoverHasAnythingToShow && // nothing to show --> hide popover\n !userSelectedAndDidNotType && // user just selected an option --> hide popover\n (userTypedSomething || // user typed something --> show popover\n userIsNavigatingWithArrows); // user is navigating with arrows --> show popover\n\n const trackUserTyping: React.KeyboardEventHandler<HTMLInputElement> = React.useCallback(\n (e) => {\n const { key } = e;\n // [...e.key].length === 1 -> \"printable\" characters including https://mathiasbynens.be/notes/javascript-unicode\n if ([...e.key].length === 1 || key === 'Backspace' || key === 'Delete') {\n setUserTypedSomething(true);\n setForceClosePopover(false);\n setUserJustSelectedAnOption(false);\n } else {\n setUserTypedSomething(false);\n }\n },\n [setUserTypedSomething],\n );\n const trackUserNavigatingWithArrows: React.KeyboardEventHandler<HTMLInputElement> = React.useCallback(\n (e) => {\n const { key } = e;\n if (isShowingPopover && (key === 'ArrowUp' || key === 'ArrowDown')) {\n setUserIsNavigatingWithArrows(true);\n } else {\n setUserIsNavigatingWithArrows(false);\n }\n },\n [isShowingPopover],\n );\n\n const trackUserSelectingAnOption: React.KeyboardEventHandler<HTMLInputElement> = React.useCallback(\n (e) => {\n const { key } = e;\n if (key === 'Enter' && isShowingPopover) {\n setUserJustSelectedAnOption(true);\n }\n },\n [isShowingPopover],\n );\n\n const trackUserInteractingViaKeyboard: React.KeyboardEventHandler<HTMLInputElement> = React.useCallback(\n (e) => {\n trackUserTyping(e);\n trackUserNavigatingWithArrows(e);\n trackUserSelectingAnOption(e);\n },\n [trackUserTyping, trackUserNavigatingWithArrows, trackUserSelectingAnOption],\n );\n\n // when the webpage is blurred, we want to close the popover\n // should be fixing iframes interactions?\n useEffect(() => {\n const closePopper = () => {\n setForceClosePopover(true);\n };\n window.addEventListener('blur', closePopper);\n\n return () => {\n window.removeEventListener('blur', closePopper);\n };\n }, []);\n\n return React.useMemo(\n () => ({\n isShowingPopover,\n forceClosePopover,\n setForceClosePopover,\n userTypedSomething,\n setUserTypedSomething,\n setUserJustSelectedAnOption,\n setUserIsNavigatingWithArrows,\n trackUserInteractingViaKeyboard,\n }),\n [isShowingPopover, forceClosePopover, userTypedSomething, trackUserInteractingViaKeyboard],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,OAAOA,UAAS,UAAU,iBAAiB;AAgBpC,MAAM,kBAAkB,CAAC,qBAAoD;AAClF,QAAM,EAAE,SAAS,OAAO,IAAI;AAE5B,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAAkB,KAAK;AAEzE,QAAM,CAAC,oBAAoB,qBAAqB,IAAI,SAAkB,KAAK;AAC3E,QAAM,CAAC,4BAA4B,6BAA6B,IAAI,SAAkB,KAAK;AAC3F,QAAM,CAAC,0BAA0B,2BAA2B,IAAI,SAAkB,KAAK;AAEvF,QAAM,4BAA4B,4BAA4B,CAAC;AAC/D,QAAM,2BAA2B,QAAQ,SAAS,KAAK,OAAO,SAAS;AAEvE,QAAM,mBACJ,CAAC,qBACD,4BACA,CAAC,8BACA,sBACC;AAEJ,QAAM,kBAAgEA,OAAM;AAAA,IAC1E,CAAC,MAAM;AACL,YAAM,EAAE,IAAI,IAAI;AAEhB,UAAI,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,KAAK,QAAQ,eAAe,QAAQ,UAAU;AACtE,8BAAsB,IAAI;AAC1B,6BAAqB,KAAK;AAC1B,oCAA4B,KAAK;AAAA,MACnC,OAAO;AACL,8BAAsB,KAAK;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,CAAC,qBAAqB;AAAA,EACxB;AACA,QAAM,gCAA8EA,OAAM;AAAA,IACxF,CAAC,MAAM;AACL,YAAM,EAAE,IAAI,IAAI;AAChB,UAAI,qBAAqB,QAAQ,aAAa,QAAQ,cAAc;AAClE,sCAA8B,IAAI;AAAA,MACpC,OAAO;AACL,sCAA8B,KAAK;AAAA,MACrC;AAAA,IACF;AAAA,IACA,CAAC,gBAAgB;AAAA,EACnB;AAEA,QAAM,6BAA2EA,OAAM;AAAA,IACrF,CAAC,MAAM;AACL,YAAM,EAAE,IAAI,IAAI;AAChB,UAAI,QAAQ,WAAW,kBAAkB;AACvC,oCAA4B,IAAI;AAAA,MAClC;AAAA,IACF;AAAA,IACA,CAAC,gBAAgB;AAAA,EACnB;AAEA,QAAM,kCAAgFA,OAAM;AAAA,IAC1F,CAAC,MAAM;AACL,sBAAgB,CAAC;AACjB,oCAA8B,CAAC;AAC/B,iCAA2B,CAAC;AAAA,IAC9B;AAAA,IACA,CAAC,iBAAiB,+BAA+B,0BAA0B;AAAA,EAC7E;AAIA,YAAU,MAAM;AACd,UAAM,cAAc,MAAM;AACxB,2BAAqB,IAAI;AAAA,IAC3B;AACA,WAAO,iBAAiB,QAAQ,WAAW;AAE3C,WAAO,MAAM;AACX,aAAO,oBAAoB,QAAQ,WAAW;AAAA,IAChD;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAOA,OAAM;AAAA,IACX,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,CAAC,kBAAkB,mBAAmB,oBAAoB,+BAA+B;AAAA,EAC3F;AACF;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2, { useRef } from "react";
|
|
3
|
+
const useRefs = () => {
|
|
4
|
+
const inputRef = useRef(null);
|
|
5
|
+
const listRef = useRef(null);
|
|
6
|
+
return React2.useMemo(() => ({ inputRef, listRef }), [inputRef, listRef]);
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
useRefs
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useRefs.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useRefs.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useRef } from 'react';\n\nexport const useRefs = () => {\n const inputRef = useRef<HTMLInputElement>(null);\n const listRef = useRef<HTMLDivElement>(null);\n return React.useMemo(() => ({ inputRef, listRef }), [inputRef, listRef]);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,OAAOA,UAAS,cAAc;AAEvB,MAAM,UAAU,MAAM;AAC3B,QAAM,WAAW,OAAyB,IAAI;AAC9C,QAAM,UAAU,OAAuB,IAAI;AAC3C,SAAOA,OAAM,QAAQ,OAAO,EAAE,UAAU,QAAQ,IAAI,CAAC,UAAU,OAAO,CAAC;AACzE;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2, { useCallback } from "react";
|
|
3
|
+
import { useVirtual } from "react-virtual";
|
|
4
|
+
const useVirtualization = ({
|
|
5
|
+
references,
|
|
6
|
+
propsWithDefault
|
|
7
|
+
}) => {
|
|
8
|
+
const { options } = propsWithDefault;
|
|
9
|
+
const { listRef } = references;
|
|
10
|
+
const virtualListHelpers = useVirtual({
|
|
11
|
+
size: options.length,
|
|
12
|
+
parentRef: listRef,
|
|
13
|
+
overscan: 15,
|
|
14
|
+
paddingStart: 0
|
|
15
|
+
});
|
|
16
|
+
const scrollOptionIntoView = useCallback(
|
|
17
|
+
(dsId, opts = { align: "center" }) => {
|
|
18
|
+
virtualListHelpers.scrollToIndex(
|
|
19
|
+
options.findIndex((opt) => opt.dsId === dsId),
|
|
20
|
+
opts
|
|
21
|
+
);
|
|
22
|
+
},
|
|
23
|
+
[options, virtualListHelpers]
|
|
24
|
+
);
|
|
25
|
+
return React2.useMemo(
|
|
26
|
+
() => ({
|
|
27
|
+
virtualListHelpers,
|
|
28
|
+
scrollOptionIntoView
|
|
29
|
+
}),
|
|
30
|
+
[virtualListHelpers, scrollOptionIntoView]
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
useVirtualization
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=useVirtualization.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useVirtualization.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useCallback } from 'react';\nimport { useVirtual } from 'react-virtual';\nimport type {} from 'react-virtual';\nimport type { DSAutocompleteT } from '../react-desc-prop-types';\nimport type { useRefs } from './useRefs';\n\nexport const useVirtualization = ({\n references,\n propsWithDefault,\n}: {\n references: ReturnType<typeof useRefs>;\n propsWithDefault: DSAutocompleteT.InternalProps;\n}) => {\n const { options } = propsWithDefault;\n const { listRef } = references;\n\n // ===========================================================================\n // Virtualization setup\n // ===========================================================================\n const virtualListHelpers: ReturnType<typeof useVirtual> = useVirtual({\n size: options.length,\n parentRef: listRef,\n overscan: 15,\n paddingStart: 0,\n });\n\n // ===========================================================================\n // Scroll into view function\n // ===========================================================================\n const scrollOptionIntoView = useCallback(\n (dsId: string, opts = { align: 'center' }) => {\n virtualListHelpers.scrollToIndex(\n options.findIndex((opt) => opt.dsId === dsId),\n opts,\n );\n },\n [options, virtualListHelpers],\n );\n\n return React.useMemo(\n () => ({\n virtualListHelpers,\n scrollOptionIntoView,\n }),\n [virtualListHelpers, scrollOptionIntoView],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,OAAOA,UAAS,mBAAmB;AACnC,SAAS,kBAAkB;AAKpB,MAAM,oBAAoB,CAAC;AAAA,EAChC;AAAA,EACA;AACF,MAGM;AACJ,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,EAAE,QAAQ,IAAI;AAKpB,QAAM,qBAAoD,WAAW;AAAA,IACnE,MAAM,QAAQ;AAAA,IACd,WAAW;AAAA,IACX,UAAU;AAAA,IACV,cAAc;AAAA,EAChB,CAAC;AAKD,QAAM,uBAAuB;AAAA,IAC3B,CAAC,MAAc,OAAO,EAAE,OAAO,SAAS,MAAM;AAC5C,yBAAmB;AAAA,QACjB,QAAQ,UAAU,CAAC,QAAQ,IAAI,SAAS,IAAI;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,SAAS,kBAAkB;AAAA,EAC9B;AAEA,SAAOA,OAAM;AAAA,IACX,OAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,IACA,CAAC,oBAAoB,oBAAoB;AAAA,EAC3C;AACF;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -15,15 +15,15 @@ const A11yFocusedOption = () => {
|
|
|
15
15
|
const {
|
|
16
16
|
props: { options },
|
|
17
17
|
focusOptionIdx,
|
|
18
|
-
|
|
18
|
+
isShowingPopover
|
|
19
19
|
} = useContext(AutocompleteContext);
|
|
20
20
|
return useMemo(() => {
|
|
21
21
|
const selectabledOptions = getSelectableOptions(options);
|
|
22
22
|
const focusOption = options.find((option) => !isSeparator(option) && option.dsId === focusOptionIdx);
|
|
23
23
|
const focusSelectableOptionIdx = selectabledOptions.findIndex((option) => option.dsId === focusOptionIdx);
|
|
24
|
-
return /* @__PURE__ */ jsx(StyledA11ySelectedValues, { "aria-live": "polite", children: !isSeparator(focusOption) &&
|
|
24
|
+
return /* @__PURE__ */ jsx(StyledA11ySelectedValues, { "aria-live": "polite", children: !isSeparator(focusOption) && isShowingPopover && focusOption && `option ${focusOption.label} focused.${focusSelectableOptionIdx + 1} of ${selectabledOptions.length}
|
|
25
25
|
` });
|
|
26
|
-
}, [options,
|
|
26
|
+
}, [options, isShowingPopover, focusOptionIdx]);
|
|
27
27
|
};
|
|
28
28
|
export {
|
|
29
29
|
A11yFocusedOption,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/parts/A11yFocusedOption.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useMemo } from 'react';\nimport { styled } from '@elliemae/ds-system';\nimport AutocompleteContext from '../AutocompleteCTX';\nimport { getSelectableOptions } from '../utils/listHelper';\nimport type { DSAutocompleteT } from '../react-desc-prop-types';\nexport const isSeparator = (el: DSAutocompleteT.OptionTypes | undefined): el is DSAutocompleteT.ItemSeparatorOptions =>\n el?.type === 'separator';\n\nexport const StyledA11ySelectedValues = styled.span`\n width: 1px;\n height: 1px;\n position: absolute;\n clip: rect(1px, 1px, 1px, 1px);\n`;\n\nexport const A11yFocusedOption: React.ComponentType = () => {\n const {\n props: { options },\n focusOptionIdx,\n
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;AC4BjB;AA5BN,SAAgB,YAAY,eAAe;AAC3C,SAAS,cAAc;AACvB,OAAO,yBAAyB;AAChC,SAAS,4BAA4B;AAE9B,MAAM,cAAc,CAAC,OAC1B,IAAI,SAAS;AAER,MAAM,2BAA2B,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAOxC,MAAM,oBAAyC,MAAM;AAC1D,QAAM;AAAA,IACJ,OAAO,EAAE,QAAQ;AAAA,IACjB;AAAA,IACA;AAAA,EACF,IAAI,WAAW,mBAAmB;AAElC,SAAO,QAAQ,MAAM;AACnB,UAAM,qBAAqB,qBAAqB,OAAO;AACvD,UAAM,cAAc,QAAQ,KAAK,CAAC,WAAW,CAAC,YAAY,MAAM,KAAK,OAAO,SAAS,cAAc;AACnG,UAAM,2BAA2B,mBAAmB,UAAU,CAAC,WAAW,OAAO,SAAS,cAAc;AAExG,WACE,oBAAC,4BAAyB,aAAU,UACjC,WAAC,YAAY,WAAW,KACvB,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useMemo } from 'react';\nimport { styled } from '@elliemae/ds-system';\nimport AutocompleteContext from '../AutocompleteCTX';\nimport { getSelectableOptions } from '../utils/listHelper';\nimport type { DSAutocompleteT } from '../react-desc-prop-types';\nexport const isSeparator = (el: DSAutocompleteT.OptionTypes | undefined): el is DSAutocompleteT.ItemSeparatorOptions =>\n el?.type === 'separator';\n\nexport const StyledA11ySelectedValues = styled.span`\n width: 1px;\n height: 1px;\n position: absolute;\n clip: rect(1px, 1px, 1px, 1px);\n`;\n\nexport const A11yFocusedOption: React.ComponentType = () => {\n const {\n props: { options },\n focusOptionIdx,\n isShowingPopover,\n } = useContext(AutocompleteContext);\n\n return useMemo(() => {\n const selectabledOptions = getSelectableOptions(options);\n const focusOption = options.find((option) => !isSeparator(option) && option.dsId === focusOptionIdx);\n const focusSelectableOptionIdx = selectabledOptions.findIndex((option) => option.dsId === focusOptionIdx);\n\n return (\n <StyledA11ySelectedValues aria-live=\"polite\">\n {!isSeparator(focusOption) &&\n isShowingPopover &&\n focusOption &&\n `option ${focusOption.label} focused.${focusSelectableOptionIdx + 1} of ${selectabledOptions.length}\n `}\n </StyledA11ySelectedValues>\n );\n }, [options, isShowingPopover, focusOptionIdx]);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AC4BjB;AA5BN,SAAgB,YAAY,eAAe;AAC3C,SAAS,cAAc;AACvB,OAAO,yBAAyB;AAChC,SAAS,4BAA4B;AAE9B,MAAM,cAAc,CAAC,OAC1B,IAAI,SAAS;AAER,MAAM,2BAA2B,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAOxC,MAAM,oBAAyC,MAAM;AAC1D,QAAM;AAAA,IACJ,OAAO,EAAE,QAAQ;AAAA,IACjB;AAAA,IACA;AAAA,EACF,IAAI,WAAW,mBAAmB;AAElC,SAAO,QAAQ,MAAM;AACnB,UAAM,qBAAqB,qBAAqB,OAAO;AACvD,UAAM,cAAc,QAAQ,KAAK,CAAC,WAAW,CAAC,YAAY,MAAM,KAAK,OAAO,SAAS,cAAc;AACnG,UAAM,2BAA2B,mBAAmB,UAAU,CAAC,WAAW,OAAO,SAAS,cAAc;AAExG,WACE,oBAAC,4BAAyB,aAAU,UACjC,WAAC,YAAY,WAAW,KACvB,oBACA,eACA,UAAU,YAAY,iBAAiB,2BAA2B,QAAQ,mBAAmB;AAAA,cAEjG;AAAA,EAEJ,GAAG,CAAC,SAAS,kBAAkB,cAAc,CAAC;AAChD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|