@elliemae/ds-menu-button 3.80.0-next.57 → 3.80.0-next.58
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/config/useLatestValueReferenciallyStable.js +43 -0
- package/dist/cjs/config/useLatestValueReferenciallyStable.js.map +7 -0
- package/dist/cjs/config/useSideEffectSyntheticEvent.js +44 -0
- package/dist/cjs/config/useSideEffectSyntheticEvent.js.map +7 -0
- package/dist/cjs/config/useSplitInherithedProps.js +6 -0
- package/dist/cjs/config/useSplitInherithedProps.js.map +2 -2
- package/dist/cjs/parts/DSFlyoutMenu/DSFlyoutMenu.js +17 -19
- package/dist/cjs/parts/DSFlyoutMenu/DSFlyoutMenu.js.map +2 -2
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js +4 -3
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js.map +2 -2
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js +6 -0
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js.map +2 -2
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js +27 -12
- package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js.map +2 -2
- package/dist/cjs/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js +14 -9
- package/dist/cjs/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js.map +2 -2
- package/dist/cjs/react-desc-prop-types.js +10 -1
- package/dist/cjs/react-desc-prop-types.js.map +2 -2
- package/dist/esm/config/useLatestValueReferenciallyStable.js +13 -0
- package/dist/esm/config/useLatestValueReferenciallyStable.js.map +7 -0
- package/dist/esm/config/useSideEffectSyntheticEvent.js +14 -0
- package/dist/esm/config/useSideEffectSyntheticEvent.js.map +7 -0
- package/dist/esm/config/useSplitInherithedProps.js +6 -0
- package/dist/esm/config/useSplitInherithedProps.js.map +2 -2
- package/dist/esm/parts/DSFlyoutMenu/DSFlyoutMenu.js +17 -19
- package/dist/esm/parts/DSFlyoutMenu/DSFlyoutMenu.js.map +2 -2
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js +4 -3
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js.map +2 -2
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js +6 -0
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js.map +2 -2
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js +27 -12
- package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js.map +2 -2
- package/dist/esm/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js +14 -9
- package/dist/esm/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js.map +2 -2
- package/dist/esm/react-desc-prop-types.js +10 -1
- package/dist/esm/react-desc-prop-types.js.map +2 -2
- package/dist/types/config/useLatestValueReferenciallyStable.d.ts +4 -0
- package/dist/types/config/useSideEffectSyntheticEvent.d.ts +9 -0
- package/dist/types/config/useSplitInherithedProps.d.ts +2 -0
- package/dist/types/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.d.ts +1 -0
- package/dist/types/react-desc-prop-types.d.ts +10 -1
- package/package.json +13 -12
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2 from "react";
|
|
3
|
+
import { useLatestValueReferenciallyStable } from "./useLatestValueReferenciallyStable.js";
|
|
4
|
+
const useSideEffectSyntheticEvent = (dependency, callback, callbackOpts) => {
|
|
5
|
+
const refCb = useLatestValueReferenciallyStable(callback);
|
|
6
|
+
const refCbOpts = useLatestValueReferenciallyStable(callbackOpts);
|
|
7
|
+
React2.useEffect(() => {
|
|
8
|
+
refCb?.current?.(dependency, refCbOpts.current);
|
|
9
|
+
}, [dependency, refCb, refCbOpts]);
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
useSideEffectSyntheticEvent
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=useSideEffectSyntheticEvent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useSideEffectSyntheticEvent.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { useLatestValueReferenciallyStable } from './useLatestValueReferenciallyStable.js';\n/**\n * This is a custom hook that allows us to simulate a synthetic event. This ensure we only trigger a side effect when a specific variable(dependency) changes.\n * @param {any} dependency - the variable that we want to listen to\n * @param {Function} callback - the callback that we want to execute when the dependency changes\n * @param {object} callbackOpts - the options to be passed to the callback function\n * @returns {void}\n * @invoke useLatestValueReferenciallyStable\n */\nexport const useSideEffectSyntheticEvent = <T, CBOpts>(\n dependency: T,\n callback: (latestVal: T, opts: CBOpts) => void,\n callbackOpts: CBOpts,\n) => {\n const refCb = useLatestValueReferenciallyStable(callback);\n const refCbOpts = useLatestValueReferenciallyStable(callbackOpts);\n // this is the useEffect that simulates the event\n React.useEffect(() => {\n refCb?.current?.(dependency, refCbOpts.current);\n // the point of this custom hook is making sure we only listen to the dependency and nothing else\n // without violating the rules of hooks/exhaustive-deps rule and making it explicit that we want to simulate an event\n // refCb & refCbOpts are forced to be referentially stable, so we can safely put it in the dependency array\n }, [dependency, refCb, refCbOpts]);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,OAAOA,YAAW;AAClB,SAAS,yCAAyC;AAS3C,MAAM,8BAA8B,CACzC,YACA,UACA,iBACG;AACH,QAAM,QAAQ,kCAAkC,QAAQ;AACxD,QAAM,YAAY,kCAAkC,YAAY;AAEhE,EAAAA,OAAM,UAAU,MAAM;AACpB,WAAO,UAAU,YAAY,UAAU,OAAO;AAAA,EAIhD,GAAG,CAAC,YAAY,OAAO,SAAS,CAAC;AACnC;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -39,6 +39,7 @@ const useSplitInherithedProps = ({
|
|
|
39
39
|
isSkeleton,
|
|
40
40
|
ItemRenderer,
|
|
41
41
|
floatingConfig,
|
|
42
|
+
firstOpenAxis,
|
|
42
43
|
innerRef,
|
|
43
44
|
selectedItems,
|
|
44
45
|
onDisplayedSubmenuChange,
|
|
@@ -46,6 +47,7 @@ const useSplitInherithedProps = ({
|
|
|
46
47
|
onActivateItem,
|
|
47
48
|
onOpen,
|
|
48
49
|
onClose,
|
|
50
|
+
onItemKeyDown,
|
|
49
51
|
a11yDangerouslyConsumerOwnedMenuOpenState,
|
|
50
52
|
maxHeight,
|
|
51
53
|
// this is not shared with anything at all, it's instead a property of the "root" node, each node (with a submenu) can have its own maxHeight
|
|
@@ -84,6 +86,7 @@ const useSplitInherithedProps = ({
|
|
|
84
86
|
isLoading,
|
|
85
87
|
isSkeleton,
|
|
86
88
|
ItemRenderer,
|
|
89
|
+
firstOpenAxis,
|
|
87
90
|
...floatingConfig !== void 0 ? { floatingConfig } : {}
|
|
88
91
|
}),
|
|
89
92
|
[
|
|
@@ -95,6 +98,7 @@ const useSplitInherithedProps = ({
|
|
|
95
98
|
isLoading,
|
|
96
99
|
isSkeleton,
|
|
97
100
|
ItemRenderer,
|
|
101
|
+
firstOpenAxis,
|
|
98
102
|
floatingConfig
|
|
99
103
|
]
|
|
100
104
|
);
|
|
@@ -110,6 +114,7 @@ const useSplitInherithedProps = ({
|
|
|
110
114
|
onActivateItem,
|
|
111
115
|
onOpen,
|
|
112
116
|
onClose: onCloseAndDismissal,
|
|
117
|
+
onItemKeyDown,
|
|
113
118
|
a11yDangerouslyConsumerOwnedMenuOpenState
|
|
114
119
|
},
|
|
115
120
|
opinionatedButtonProps: {
|
|
@@ -127,6 +132,7 @@ const useSplitInherithedProps = ({
|
|
|
127
132
|
onActivateItem,
|
|
128
133
|
onOpen,
|
|
129
134
|
onCloseAndDismissal,
|
|
135
|
+
onItemKeyDown,
|
|
130
136
|
a11yDangerouslyConsumerOwnedMenuOpenState,
|
|
131
137
|
buttonInheritedProps,
|
|
132
138
|
innerRefSnatchingNode,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useSplitInherithedProps.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* *******************************************************\n * From official source definition\n *\n * Menu Button Pattern\n * About This Pattern:\n * A menu button is a button\n * that opens a menu\n * (as described in the Menu and Menubar Pattern).\n *\n * Since the menu button is a button, it inherits all the props from the Button component.\n * Since the menu button MUST have a menu, it also have a set of specific props used to handle the menu.\n * Because we build with atomic composition in mind, the \"logic layer\" is separated and has a yet another set of props.\n *\n * This is effectively an OOP \"extension\" of the Button component,\n * so it has the same props,\n * BUT also a few more to handle the specific behavior of the menu.\n *\n * this hooks is meant to take all the DSMenuButtonT.InternalProps with default already merged\n * and spit out menuSpecificProps & buttonInheritedProps\n ******************************************************* */\nimport type {} from '@elliemae/ds-system';\nimport type {} from '@elliemae/pui-theme';\nimport React from 'react';\nimport { type DSMenuButtonT } from '../react-desc-prop-types.js';\nimport { isObjectAMenuNode, isSelectionableNode } from '../utils/nodesTypeguardsAndGetters.js';\nimport { resolveRef } from '../utils/resolveRef.js';\n\n/**\n * Converts selected options to a map of selected nodes.\n * @param {DSMenuButtonT.SelectionableMenuNodes[]} selectedItems - The selected options, as provided by the user (either items or nodes).\n * @param {DSMenuButtonT.MenuNode} treeRootNode - The root node of the menu tree.\n * @returns {DSMenuButtonT.SelectionableMenuNodes[]} - The map of selected nodes.\n * @throws Will throw an error if a selected option is not found in the tree.\n */\nconst convertSelectedOptionsToNodes = (\n selectedItems: DSMenuButtonT.SelectionableMenuNodes[] | DSMenuButtonT.SelectionableMenuItemInterface[],\n treeRootNode: DSMenuButtonT.MenuNode,\n): DSMenuButtonT.SelectionableMenuNodes[] => {\n const convertedSelection: DSMenuButtonT.SelectionableMenuNodes[] = [];\n\n selectedItems.forEach((selectedItem) => {\n const needsConversion = !isObjectAMenuNode(selectedItem);\n if (!needsConversion) {\n convertedSelection.push(selectedItem);\n return;\n }\n\n const { dsId } = selectedItem;\n const selectedNode = treeRootNode.findNode((node: DSMenuButtonT.MenuNode) => node.dsId === dsId);\n if (!selectedNode) {\n throw new Error(`Selected option with dsId ${dsId} not found in the menu tree.`);\n }\n if (!isSelectionableNode(selectedNode)) {\n // eslint-disable-next-line no-console\n console.warn(`Selected option with dsId ${dsId} is not a selectionable node and will be ignored.`);\n return;\n }\n convertedSelection.push(selectedNode);\n });\n\n return convertedSelection;\n};\n\ntype UseSplitInherithedPropsConfig = {\n propsWithDefault: DSMenuButtonT.InternalProps;\n focusableNodes: DSMenuButtonT.PseudoFocusableMenuNodes[];\n treeRootNode: DSMenuButtonT.MenuNode;\n};\nexport const useSplitInherithedProps = ({\n propsWithDefault,\n focusableNodes,\n treeRootNode,\n}: UseSplitInherithedPropsConfig) => {\n const buttonDOMNodeRef = React.useRef<HTMLElement | null>(null);\n // when this component has been wrote\n // =============================================================================\n // MENU BUTTON props are:\n // Required\n // optionsTree, menuSpecificProps\n // Default (we already have a value because props for this hook are already merged with default props)\n // onClickOutside, onOptionClick, openedSubmenus, onSubmenuToggle, isLoading, isSkeleton, selectedOptions\n // Optional (may or may not be present)\n // ItemRenderer\n // =============================================================================\n // Props for the DSMenuBehaviouralContextProvider\n // =============================================================================\n // Required\n // selectedItems, onItemSelected, onActivateItem,\n // Optional\n // onDisplayedSubmenuChange, onOpen, onClose\n\n const {\n options,\n onClickOutside,\n onOptionClick,\n openedSubmenus,\n onSubmenuToggle,\n isLoading,\n isSkeleton,\n ItemRenderer,\n floatingConfig,\n innerRef,\n selectedItems,\n onDisplayedSubmenuChange,\n onItemSelected,\n onActivateItem,\n onOpen,\n onClose,\n a11yDangerouslyConsumerOwnedMenuOpenState,\n maxHeight, // this is not shared with anything at all, it's instead a property of the \"root\" node, each node (with a submenu) can have its own maxHeight\n ...buttonInheritedProps\n } = propsWithDefault;\n\n // the button is allowed to receive innerRef, but we also need to invoke the setButtonDOMNode to store the button node\n // so we create a functional ref to do both\n const innerRefSnatchingNode: Required<DSMenuButtonT.Props>['innerRef'] = React.useCallback(\n (node: HTMLButtonElement) => {\n buttonDOMNodeRef.current = node;\n if (innerRef) {\n resolveRef(innerRef, node);\n }\n },\n [innerRef],\n );\n // in the WIDGET API, the user can provide selectedItems as an array of \"items\" or an array of \"nodes\"\n // the component needs the \"nodes\" to handle the logic and rendering & accessibility\n // if the user provides \"items\", we convert them to \"nodes\" here\n const selectedNodesMap = React.useMemo(() => {\n if (selectedItems) {\n return convertSelectedOptionsToNodes(selectedItems, treeRootNode);\n }\n return [];\n }, [selectedItems, treeRootNode]);\n\n // `onClickOutside` is the dismissal channel \u2014 a pointer interaction outside the menu, or the Escape key \u2014\n // it is a subset of the close intents, so it is derived from `onClose`'s `reason` instead of a second code path\n const onCloseAndDismissal = React.useCallback<Required<DSMenuButtonT.MenuBehaviouralLayerOptionalProps>['onClose']>(\n (metainfo) => {\n if (onClose) onClose(metainfo);\n if (metainfo.reason === 'outside-click' || metainfo.reason === 'escape')\n onClickOutside(metainfo.event as Parameters<typeof onClickOutside>[0]);\n },\n [onClose, onClickOutside],\n );\n\n const menuSpecificProps = React.useMemo(\n () => ({\n options,\n onClickOutside,\n onOptionClick,\n openedSubmenus,\n onSubmenuToggle,\n isLoading,\n isSkeleton,\n ItemRenderer,\n ...(floatingConfig !== undefined ? { floatingConfig } : {}),\n }),\n [\n options,\n onClickOutside,\n onOptionClick,\n openedSubmenus,\n onSubmenuToggle,\n isLoading,\n isSkeleton,\n ItemRenderer,\n floatingConfig,\n ],\n );\n\n return React.useMemo(\n () => ({\n menuBehaviouralLayerProps: {\n buttonDOMNodeRef,\n selectedNodes: selectedNodesMap,\n focusableNodes,\n optionsTree: treeRootNode,\n onDisplayedSubmenuChange,\n onItemSelected,\n onActivateItem,\n onOpen,\n onClose: onCloseAndDismissal,\n a11yDangerouslyConsumerOwnedMenuOpenState,\n },\n opinionatedButtonProps: {\n ...(buttonInheritedProps as DSMenuButtonT.ButtonInheritedProps),\n innerRef: innerRefSnatchingNode,\n menuSpecificProps,\n },\n }),\n [\n selectedNodesMap,\n focusableNodes,\n treeRootNode,\n onDisplayedSubmenuChange,\n onItemSelected,\n onActivateItem,\n onOpen,\n onCloseAndDismissal,\n a11yDangerouslyConsumerOwnedMenuOpenState,\n buttonInheritedProps,\n innerRefSnatchingNode,\n menuSpecificProps,\n ],\n );\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACsBvB,OAAOA,YAAW;AAElB,SAAS,mBAAmB,2BAA2B;AACvD,SAAS,kBAAkB;AAS3B,MAAM,gCAAgC,CACpC,eACA,iBAC2C;AAC3C,QAAM,qBAA6D,CAAC;AAEpE,gBAAc,QAAQ,CAAC,iBAAiB;AACtC,UAAM,kBAAkB,CAAC,kBAAkB,YAAY;AACvD,QAAI,CAAC,iBAAiB;AACpB,yBAAmB,KAAK,YAAY;AACpC;AAAA,IACF;AAEA,UAAM,EAAE,KAAK,IAAI;AACjB,UAAM,eAAe,aAAa,SAAS,CAAC,SAAiC,KAAK,SAAS,IAAI;AAC/F,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,MAAM,6BAA6B,IAAI,8BAA8B;AAAA,IACjF;AACA,QAAI,CAAC,oBAAoB,YAAY,GAAG;AAEtC,cAAQ,KAAK,6BAA6B,IAAI,mDAAmD;AACjG;AAAA,IACF;AACA,uBAAmB,KAAK,YAAY;AAAA,EACtC,CAAC;AAED,SAAO;AACT;AAOO,MAAM,0BAA0B,CAAC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AACF,MAAqC;AACnC,QAAM,mBAAmBA,OA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,eAAe;AAAA,QACf;AAAA,QACA,aAAa;AAAA,QACb;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS;AAAA,QACT;AAAA,MACF;AAAA,MACA,wBAAwB;AAAA,QACtB,GAAI;AAAA,QACJ,UAAU;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* *******************************************************\n * From official source definition\n *\n * Menu Button Pattern\n * About This Pattern:\n * A menu button is a button\n * that opens a menu\n * (as described in the Menu and Menubar Pattern).\n *\n * Since the menu button is a button, it inherits all the props from the Button component.\n * Since the menu button MUST have a menu, it also have a set of specific props used to handle the menu.\n * Because we build with atomic composition in mind, the \"logic layer\" is separated and has a yet another set of props.\n *\n * This is effectively an OOP \"extension\" of the Button component,\n * so it has the same props,\n * BUT also a few more to handle the specific behavior of the menu.\n *\n * this hooks is meant to take all the DSMenuButtonT.InternalProps with default already merged\n * and spit out menuSpecificProps & buttonInheritedProps\n ******************************************************* */\nimport type {} from '@elliemae/ds-system';\nimport type {} from '@elliemae/pui-theme';\nimport React from 'react';\nimport { type DSMenuButtonT } from '../react-desc-prop-types.js';\nimport { isObjectAMenuNode, isSelectionableNode } from '../utils/nodesTypeguardsAndGetters.js';\nimport { resolveRef } from '../utils/resolveRef.js';\n\n/**\n * Converts selected options to a map of selected nodes.\n * @param {DSMenuButtonT.SelectionableMenuNodes[]} selectedItems - The selected options, as provided by the user (either items or nodes).\n * @param {DSMenuButtonT.MenuNode} treeRootNode - The root node of the menu tree.\n * @returns {DSMenuButtonT.SelectionableMenuNodes[]} - The map of selected nodes.\n * @throws Will throw an error if a selected option is not found in the tree.\n */\nconst convertSelectedOptionsToNodes = (\n selectedItems: DSMenuButtonT.SelectionableMenuNodes[] | DSMenuButtonT.SelectionableMenuItemInterface[],\n treeRootNode: DSMenuButtonT.MenuNode,\n): DSMenuButtonT.SelectionableMenuNodes[] => {\n const convertedSelection: DSMenuButtonT.SelectionableMenuNodes[] = [];\n\n selectedItems.forEach((selectedItem) => {\n const needsConversion = !isObjectAMenuNode(selectedItem);\n if (!needsConversion) {\n convertedSelection.push(selectedItem);\n return;\n }\n\n const { dsId } = selectedItem;\n const selectedNode = treeRootNode.findNode((node: DSMenuButtonT.MenuNode) => node.dsId === dsId);\n if (!selectedNode) {\n throw new Error(`Selected option with dsId ${dsId} not found in the menu tree.`);\n }\n if (!isSelectionableNode(selectedNode)) {\n // eslint-disable-next-line no-console\n console.warn(`Selected option with dsId ${dsId} is not a selectionable node and will be ignored.`);\n return;\n }\n convertedSelection.push(selectedNode);\n });\n\n return convertedSelection;\n};\n\ntype UseSplitInherithedPropsConfig = {\n propsWithDefault: DSMenuButtonT.InternalProps;\n focusableNodes: DSMenuButtonT.PseudoFocusableMenuNodes[];\n treeRootNode: DSMenuButtonT.MenuNode;\n};\nexport const useSplitInherithedProps = ({\n propsWithDefault,\n focusableNodes,\n treeRootNode,\n}: UseSplitInherithedPropsConfig) => {\n const buttonDOMNodeRef = React.useRef<HTMLElement | null>(null);\n // when this component has been wrote\n // =============================================================================\n // MENU BUTTON props are:\n // Required\n // optionsTree, menuSpecificProps\n // Default (we already have a value because props for this hook are already merged with default props)\n // onClickOutside, onOptionClick, openedSubmenus, onSubmenuToggle, isLoading, isSkeleton, selectedOptions\n // Optional (may or may not be present)\n // ItemRenderer\n // =============================================================================\n // Props for the DSMenuBehaviouralContextProvider\n // =============================================================================\n // Required\n // selectedItems, onItemSelected, onActivateItem,\n // Optional\n // onDisplayedSubmenuChange, onOpen, onClose, onItemKeyDown\n\n const {\n options,\n onClickOutside,\n onOptionClick,\n openedSubmenus,\n onSubmenuToggle,\n isLoading,\n isSkeleton,\n ItemRenderer,\n floatingConfig,\n firstOpenAxis,\n innerRef,\n selectedItems,\n onDisplayedSubmenuChange,\n onItemSelected,\n onActivateItem,\n onOpen,\n onClose,\n onItemKeyDown,\n a11yDangerouslyConsumerOwnedMenuOpenState,\n maxHeight, // this is not shared with anything at all, it's instead a property of the \"root\" node, each node (with a submenu) can have its own maxHeight\n ...buttonInheritedProps\n } = propsWithDefault;\n\n // the button is allowed to receive innerRef, but we also need to invoke the setButtonDOMNode to store the button node\n // so we create a functional ref to do both\n const innerRefSnatchingNode: Required<DSMenuButtonT.Props>['innerRef'] = React.useCallback(\n (node: HTMLButtonElement) => {\n buttonDOMNodeRef.current = node;\n if (innerRef) {\n resolveRef(innerRef, node);\n }\n },\n [innerRef],\n );\n // in the WIDGET API, the user can provide selectedItems as an array of \"items\" or an array of \"nodes\"\n // the component needs the \"nodes\" to handle the logic and rendering & accessibility\n // if the user provides \"items\", we convert them to \"nodes\" here\n const selectedNodesMap = React.useMemo(() => {\n if (selectedItems) {\n return convertSelectedOptionsToNodes(selectedItems, treeRootNode);\n }\n return [];\n }, [selectedItems, treeRootNode]);\n\n // `onClickOutside` is the dismissal channel \u2014 a pointer interaction outside the menu, or the Escape key \u2014\n // it is a subset of the close intents, so it is derived from `onClose`'s `reason` instead of a second code path\n const onCloseAndDismissal = React.useCallback<Required<DSMenuButtonT.MenuBehaviouralLayerOptionalProps>['onClose']>(\n (metainfo) => {\n if (onClose) onClose(metainfo);\n if (metainfo.reason === 'outside-click' || metainfo.reason === 'escape')\n onClickOutside(metainfo.event as Parameters<typeof onClickOutside>[0]);\n },\n [onClose, onClickOutside],\n );\n\n const menuSpecificProps = React.useMemo(\n () => ({\n options,\n onClickOutside,\n onOptionClick,\n openedSubmenus,\n onSubmenuToggle,\n isLoading,\n isSkeleton,\n ItemRenderer,\n firstOpenAxis,\n ...(floatingConfig !== undefined ? { floatingConfig } : {}),\n }),\n [\n options,\n onClickOutside,\n onOptionClick,\n openedSubmenus,\n onSubmenuToggle,\n isLoading,\n isSkeleton,\n ItemRenderer,\n firstOpenAxis,\n floatingConfig,\n ],\n );\n\n return React.useMemo(\n () => ({\n menuBehaviouralLayerProps: {\n buttonDOMNodeRef,\n selectedNodes: selectedNodesMap,\n focusableNodes,\n optionsTree: treeRootNode,\n onDisplayedSubmenuChange,\n onItemSelected,\n onActivateItem,\n onOpen,\n onClose: onCloseAndDismissal,\n onItemKeyDown,\n a11yDangerouslyConsumerOwnedMenuOpenState,\n },\n opinionatedButtonProps: {\n ...(buttonInheritedProps as DSMenuButtonT.ButtonInheritedProps),\n innerRef: innerRefSnatchingNode,\n menuSpecificProps,\n },\n }),\n [\n selectedNodesMap,\n focusableNodes,\n treeRootNode,\n onDisplayedSubmenuChange,\n onItemSelected,\n onActivateItem,\n onOpen,\n onCloseAndDismissal,\n onItemKeyDown,\n a11yDangerouslyConsumerOwnedMenuOpenState,\n buttonInheritedProps,\n innerRefSnatchingNode,\n menuSpecificProps,\n ],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACsBvB,OAAOA,YAAW;AAElB,SAAS,mBAAmB,2BAA2B;AACvD,SAAS,kBAAkB;AAS3B,MAAM,gCAAgC,CACpC,eACA,iBAC2C;AAC3C,QAAM,qBAA6D,CAAC;AAEpE,gBAAc,QAAQ,CAAC,iBAAiB;AACtC,UAAM,kBAAkB,CAAC,kBAAkB,YAAY;AACvD,QAAI,CAAC,iBAAiB;AACpB,yBAAmB,KAAK,YAAY;AACpC;AAAA,IACF;AAEA,UAAM,EAAE,KAAK,IAAI;AACjB,UAAM,eAAe,aAAa,SAAS,CAAC,SAAiC,KAAK,SAAS,IAAI;AAC/F,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,MAAM,6BAA6B,IAAI,8BAA8B;AAAA,IACjF;AACA,QAAI,CAAC,oBAAoB,YAAY,GAAG;AAEtC,cAAQ,KAAK,6BAA6B,IAAI,mDAAmD;AACjG;AAAA,IACF;AACA,uBAAmB,KAAK,YAAY;AAAA,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ACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAOA,OAAM;AAAA,IACX,OAAO;AAAA,MACL,2BAA2B;AAAA,QACzB;AAAA,QACA,eAAe;AAAA,QACf;AAAA,QACA,aAAa;AAAA,QACb;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,MACA,wBAAwB;AAAA,QACtB,GAAI;AAAA,QACJ,UAAU;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -13,6 +13,7 @@ import { DSFlyoutMenuName, FLYOUT_MENU_SLOTS } from "./constants/index.js";
|
|
|
13
13
|
import { DSFlyoutMenuPropTypesSchema } from "./react-desc-prop-types.js";
|
|
14
14
|
import { getAriaSetSizeAndPosInSetBySiblingList, isRootNode } from "../../utils/nodesTypeguardsAndGetters.js";
|
|
15
15
|
import { MenuButtonContextProvider } from "../../MenuButtonContextProviderCTX.js";
|
|
16
|
+
import { useSideEffectSyntheticEvent } from "../../config/useSideEffectSyntheticEvent.js";
|
|
16
17
|
const StyledWrapper = styled(Grid, {
|
|
17
18
|
name: DSFlyoutMenuName,
|
|
18
19
|
slot: FLYOUT_MENU_SLOTS.ROOT
|
|
@@ -33,6 +34,14 @@ const StyledMenu = styled("div", { name: DSFlyoutMenuName, slot: FLYOUT_MENU_SLO
|
|
|
33
34
|
margin: 0;
|
|
34
35
|
`;
|
|
35
36
|
const NoComponentPlaceholder = () => null;
|
|
37
|
+
const handleMenuOpenStateChange = (isMenuOpen, opts) => {
|
|
38
|
+
const { itemNode, focusableNodes, openIntentPendingRef, trackFocusFirstChildItem, isOpenStateOwnedByConsumer } = opts;
|
|
39
|
+
if (!isMenuOpen || !isRootNode(itemNode)) return;
|
|
40
|
+
const wasIntentArmed = openIntentPendingRef.current;
|
|
41
|
+
openIntentPendingRef.current = false;
|
|
42
|
+
if (isOpenStateOwnedByConsumer && !wasIntentArmed && focusableNodes.length > 0)
|
|
43
|
+
trackFocusFirstChildItem(itemNode);
|
|
44
|
+
};
|
|
36
45
|
const DSFlyoutMenu = (props) => {
|
|
37
46
|
const { propsWithDefault, xstyledProps } = useFlyoutMenu(props);
|
|
38
47
|
const {
|
|
@@ -43,11 +52,9 @@ const DSFlyoutMenu = (props) => {
|
|
|
43
52
|
globalEventsHelpers: { mainMenuRef, handleSubmenusRefChange },
|
|
44
53
|
openIntentPendingRef,
|
|
45
54
|
menuItemEventsHandlers: { handleMenuTabKeyDownCapture },
|
|
46
|
-
focusRegion,
|
|
47
55
|
trackFocusFirstChildItem,
|
|
48
56
|
propsWithDefault: { focusableNodes, a11yDangerouslyConsumerOwnedMenuOpenState }
|
|
49
57
|
} = React2.useContext(MenuBehaviouralContextProviderContext);
|
|
50
|
-
const lastMountedRootNodeRef = React2.useRef(null);
|
|
51
58
|
const [didAnimationEnd, setDidAnimationEnd] = React2.useState(false);
|
|
52
59
|
const { setFloatingRef, floatingStyles, floatingContext, ItemRenderer, isMenuOpen, itemNode } = propsWithDefault;
|
|
53
60
|
const ariaPositionsByDsId = React2.useMemo(
|
|
@@ -59,28 +66,19 @@ const DSFlyoutMenu = (props) => {
|
|
|
59
66
|
(node) => {
|
|
60
67
|
if (isRootNode(itemNode)) {
|
|
61
68
|
mainMenuRef.current = node;
|
|
62
|
-
if (node && node !== lastMountedRootNodeRef.current) {
|
|
63
|
-
lastMountedRootNodeRef.current = node;
|
|
64
|
-
const wasIntentArmed = openIntentPendingRef.current;
|
|
65
|
-
openIntentPendingRef.current = false;
|
|
66
|
-
if (a11yDangerouslyConsumerOwnedMenuOpenState !== void 0 && !wasIntentArmed && !focusRegion.startsWith("item-") && focusableNodes.length > 0)
|
|
67
|
-
trackFocusFirstChildItem(itemNode);
|
|
68
|
-
}
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
71
|
handleSubmenusRefChange(node, itemNode.dsId);
|
|
72
72
|
},
|
|
73
|
-
[
|
|
74
|
-
a11yDangerouslyConsumerOwnedMenuOpenState,
|
|
75
|
-
focusableNodes,
|
|
76
|
-
focusRegion,
|
|
77
|
-
handleSubmenusRefChange,
|
|
78
|
-
itemNode,
|
|
79
|
-
mainMenuRef,
|
|
80
|
-
openIntentPendingRef,
|
|
81
|
-
trackFocusFirstChildItem
|
|
82
|
-
]
|
|
73
|
+
[handleSubmenusRefChange, itemNode, mainMenuRef]
|
|
83
74
|
);
|
|
75
|
+
useSideEffectSyntheticEvent(isMenuOpen, handleMenuOpenStateChange, {
|
|
76
|
+
itemNode,
|
|
77
|
+
focusableNodes,
|
|
78
|
+
openIntentPendingRef,
|
|
79
|
+
trackFocusFirstChildItem,
|
|
80
|
+
isOpenStateOwnedByConsumer: a11yDangerouslyConsumerOwnedMenuOpenState !== void 0
|
|
81
|
+
});
|
|
84
82
|
const handleAnimationStartTrigger = React2.useCallback(() => {
|
|
85
83
|
setDidAnimationEnd(false);
|
|
86
84
|
}, []);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/DSFlyoutMenu/DSFlyoutMenu.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { FloatingWrapper } from '@elliemae/ds-floating-context';\nimport { Grid } from '@elliemae/ds-grid';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { styled, xStyledCommonProps } from '@elliemae/ds-system';\n\nimport React from 'react';\nimport { type DSMenuButtonT, menuSpecificDefaultProps } from '../../react-desc-prop-types.js';\nimport { MenuBehaviouralContextProviderContext } from '../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport { DSMenuItemRendererFactory } from '../DSMenuItemRendererFactory/index.js';\nimport { useFlyoutMenu } from './config/useFlyoutMenu.js';\nimport { DSFlyoutMenuName, FLYOUT_MENU_SLOTS } from './constants/index.js';\nimport { DSFlyoutMenuPropTypesSchema, type DSFlyoutMenuT } from './react-desc-prop-types.js';\nimport { getAriaSetSizeAndPosInSetBySiblingList, isRootNode } from '../../utils/nodesTypeguardsAndGetters.js';\nimport { MenuButtonContextProvider } from '../../MenuButtonContextProviderCTX.js';\nconst StyledWrapper = styled(Grid, {\n name: DSFlyoutMenuName,\n slot: FLYOUT_MENU_SLOTS.ROOT,\n})`\n min-width: 1px;\n background-color: white;\n padding: ${({ theme }) => theme.space.xxxs} 0;\n ${xStyledCommonProps}\n`;\n\nconst StyledFloatingWrapper = styled(FloatingWrapper, {\n name: DSFlyoutMenuName,\n slot: FLYOUT_MENU_SLOTS.FLOATING_WRAPPER,\n})``;\n\nconst StyledMenu = styled('div', { name: DSFlyoutMenuName, slot: FLYOUT_MENU_SLOTS.LIST_WRAPPER })<{\n $maxHeight: string | number;\n}>`\n max-height: ${({ $maxHeight }) => (typeof $maxHeight === 'number' ? `${$maxHeight}px` : $maxHeight)};\n overflow-y: auto;\n padding: 0;\n margin: 0;\n`;\n\nconst NoComponentPlaceholder = () => null;\n\nconst DSFlyoutMenu: React.ComponentType<DSFlyoutMenuT.Props> = (props) => {\n const { propsWithDefault, xstyledProps } = useFlyoutMenu(props);\n const {\n ownerProps: { getOwnerProps, getOwnerPropsArguments },\n } = React.useContext(MenuButtonContextProvider);\n const {\n instanceUid,\n globalEventsHelpers: { mainMenuRef, handleSubmenusRefChange },\n openIntentPendingRef,\n menuItemEventsHandlers: { handleMenuTabKeyDownCapture },\n
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { FloatingWrapper } from '@elliemae/ds-floating-context';\nimport { Grid } from '@elliemae/ds-grid';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { styled, xStyledCommonProps } from '@elliemae/ds-system';\n\nimport React from 'react';\nimport { type DSMenuButtonT, menuSpecificDefaultProps } from '../../react-desc-prop-types.js';\nimport { MenuBehaviouralContextProviderContext } from '../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport { DSMenuItemRendererFactory } from '../DSMenuItemRendererFactory/index.js';\nimport { useFlyoutMenu } from './config/useFlyoutMenu.js';\nimport { DSFlyoutMenuName, FLYOUT_MENU_SLOTS } from './constants/index.js';\nimport { DSFlyoutMenuPropTypesSchema, type DSFlyoutMenuT } from './react-desc-prop-types.js';\nimport { getAriaSetSizeAndPosInSetBySiblingList, isRootNode } from '../../utils/nodesTypeguardsAndGetters.js';\nimport { MenuButtonContextProvider } from '../../MenuButtonContextProviderCTX.js';\nimport { useSideEffectSyntheticEvent } from '../../config/useSideEffectSyntheticEvent.js';\nimport type { MenuBehaviouralContextProviderCTX } from '../DSMenuBehaviouralContextProvider/config/useMenuBehaviouralContextProvider.js';\nconst StyledWrapper = styled(Grid, {\n name: DSFlyoutMenuName,\n slot: FLYOUT_MENU_SLOTS.ROOT,\n})`\n min-width: 1px;\n background-color: white;\n padding: ${({ theme }) => theme.space.xxxs} 0;\n ${xStyledCommonProps}\n`;\n\nconst StyledFloatingWrapper = styled(FloatingWrapper, {\n name: DSFlyoutMenuName,\n slot: FLYOUT_MENU_SLOTS.FLOATING_WRAPPER,\n})``;\n\nconst StyledMenu = styled('div', { name: DSFlyoutMenuName, slot: FLYOUT_MENU_SLOTS.LIST_WRAPPER })<{\n $maxHeight: string | number;\n}>`\n max-height: ${({ $maxHeight }) => (typeof $maxHeight === 'number' ? `${$maxHeight}px` : $maxHeight)};\n overflow-y: auto;\n padding: 0;\n margin: 0;\n`;\n\nconst NoComponentPlaceholder = () => null;\n\ntype MenuOpenStateChangeOpts = {\n itemNode: DSFlyoutMenuT.Props['itemNode'];\n focusableNodes: MenuBehaviouralContextProviderCTX['propsWithDefault']['focusableNodes'];\n openIntentPendingRef: MenuBehaviouralContextProviderCTX['openIntentPendingRef'];\n trackFocusFirstChildItem: MenuBehaviouralContextProviderCTX['trackFocusFirstChildItem'];\n isOpenStateOwnedByConsumer: boolean;\n};\n\n// Runs when the open state changes (and once on mount), so only an open reaches past the first line: a closed -> open\n// edge, or a menu that mounts already open. The flyout of a closed menu stays mounted, so a mount is not an open.\n// An open INTENT of the widget (click, ArrowDown/Up) already declared where the focus goes. When the consumer owns the\n// open state, a menu can also be opened by something that never went through the widget's own intents (an external\n// button, a menubar switching menus...), so nobody declared it: declare the default intent, like every open does,\n// \"the first item\", never the item the menu had focused when it was closed.\n// The items focus themselves from their own ref callbacks, as they do for every other focus intent.\nconst handleMenuOpenStateChange = (isMenuOpen: boolean, opts: MenuOpenStateChangeOpts) => {\n const { itemNode, focusableNodes, openIntentPendingRef, trackFocusFirstChildItem, isOpenStateOwnedByConsumer } = opts;\n if (!isMenuOpen || !isRootNode(itemNode)) return;\n const wasIntentArmed = openIntentPendingRef.current;\n // eslint-disable-next-line no-param-reassign\n openIntentPendingRef.current = false;\n if (isOpenStateOwnedByConsumer && !wasIntentArmed && focusableNodes.length > 0)\n trackFocusFirstChildItem(itemNode as unknown as DSMenuButtonT.PseudoFocusableMenuNodes);\n};\n\nconst DSFlyoutMenu: React.ComponentType<DSFlyoutMenuT.Props> = (props) => {\n const { propsWithDefault, xstyledProps } = useFlyoutMenu(props);\n const {\n ownerProps: { getOwnerProps, getOwnerPropsArguments },\n } = React.useContext(MenuButtonContextProvider);\n const {\n instanceUid,\n globalEventsHelpers: { mainMenuRef, handleSubmenusRefChange },\n openIntentPendingRef,\n menuItemEventsHandlers: { handleMenuTabKeyDownCapture },\n trackFocusFirstChildItem,\n propsWithDefault: { focusableNodes, a11yDangerouslyConsumerOwnedMenuOpenState },\n } = React.useContext(MenuBehaviouralContextProviderContext);\n const [didAnimationEnd, setDidAnimationEnd] = React.useState(false);\n\n const { setFloatingRef, floatingStyles, floatingContext, ItemRenderer, isMenuOpen, itemNode } = propsWithDefault;\n const ariaPositionsByDsId = React.useMemo(\n // DSTree doesn't support children having a polymorphic type, so we need to cast it manually (same as below)\n () => getAriaSetSizeAndPosInSetBySiblingList(itemNode.children as DSMenuButtonT.MenuNode[]),\n [itemNode.children],\n );\n const handleRefChange = React.useCallback(\n (node: HTMLDivElement) => {\n if (isRootNode(itemNode)) {\n mainMenuRef.current = node;\n return;\n }\n handleSubmenusRefChange(node, itemNode.dsId);\n },\n [handleSubmenusRefChange, itemNode, mainMenuRef],\n );\n\n // The open state is owned by someone else when `a11yDangerouslyConsumerOwnedMenuOpenState` is set: from this component\n // nothing observable tells how or why it flipped, so reacting to it is a sync with external state, the one case where\n // a side effect is the right tool (see `useSideEffectSyntheticEvent`). It is kept to this single call.\n useSideEffectSyntheticEvent(isMenuOpen, handleMenuOpenStateChange, {\n itemNode,\n focusableNodes,\n openIntentPendingRef,\n trackFocusFirstChildItem,\n isOpenStateOwnedByConsumer: a11yDangerouslyConsumerOwnedMenuOpenState !== undefined,\n });\n\n const handleAnimationStartTrigger = React.useCallback(() => {\n setDidAnimationEnd(false);\n }, []);\n const handleAnimationEnd = React.useCallback(() => {\n setDidAnimationEnd(true);\n }, []);\n\n return (\n <StyledFloatingWrapper\n innerRef={setFloatingRef}\n floatingStyles={floatingStyles}\n isOpen={isMenuOpen}\n context={floatingContext}\n onAnimationStartTriggered={handleAnimationStartTrigger}\n onAnimationEnd={handleAnimationEnd}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n // Adding a data-testid for legacy e2e tests\n data-testid=\"ds-floating-wrapper-root\"\n >\n <StyledWrapper getOwnerProps={getOwnerProps} getOwnerPropsArguments={getOwnerPropsArguments} {...xstyledProps}>\n <StyledMenu\n role=\"menu\"\n // Tab is handled in the capture phase of the ROOT menu only: nested submenus are React descendants of it (their\n // events reach it too), attaching it to them as well would run the handler twice per keypress\n onKeyDownCapture={isRootNode(itemNode) ? handleMenuTabKeyDownCapture : undefined}\n innerRef={handleRefChange}\n $maxHeight={itemNode.plainItem.maxHeight ?? menuSpecificDefaultProps.maxHeight}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n {itemNode.children.map((optionNode) => {\n const ariaPosition = ariaPositionsByDsId.get(optionNode.dsId);\n return (\n <DSMenuItemRendererFactory\n key={`flyout-menu-item-${optionNode.dsId}-${instanceUid}`}\n // DSTree doesn't support children having a polymorphic type, so we need to cast it manually\n itemNode={optionNode as DSMenuButtonT.MenuNode}\n ItemRenderer={ItemRenderer}\n // we are passing the DSFlyoutMenu component as a prop to the DSMenuItemRendererFactory\n // this solves the circular-ish dependency\n // the conditional `didAnimationEnd` solves the visual artefact of nested FloatingWrapper wrongly positioned due to animation\n FlyoutMenuCircularDepInject={didAnimationEnd ? DSFlyoutMenu : NoComponentPlaceholder}\n aria-posinset={ariaPosition?.ariaPosInSet}\n aria-setsize={ariaPosition?.ariaSetSize}\n />\n );\n })}\n </StyledMenu>\n </StyledWrapper>\n </StyledFloatingWrapper>\n );\n};\n\nDSFlyoutMenu.displayName = DSFlyoutMenuName;\nconst DSFlyoutMenuWithSchema = describe(DSFlyoutMenu);\nDSFlyoutMenuWithSchema.propTypes = DSFlyoutMenuPropTypesSchema;\n\nexport { DSFlyoutMenu, DSFlyoutMenuWithSchema };\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACgJT;AAhJd,SAAS,uBAAuB;AAChC,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,QAAQ,0BAA0B;AAE3C,OAAOA,YAAW;AAClB,SAA6B,gCAAgC;AAC7D,SAAS,6CAA6C;AACtD,SAAS,iCAAiC;AAC1C,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,mCAAuD;AAChE,SAA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D,mBACE;AAAA,cAAC;AAAA;AAAA,gBAGC,UAAU;AAAA,gBACV;AAAA,gBAIA,6BAA6B,kBAAkB,eAAe;AAAA,gBAC9D,iBAAe,cAAc;AAAA,gBAC7B,gBAAc,cAAc;AAAA;AAAA,cATvB,oBAAoB,WAAW,IAAI,IAAI,WAAW;AAAA,YAUzD;AAAA,UAEJ,CAAC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;AAEA,aAAa,cAAc;AAC3B,MAAM,yBAAyB,SAAS,YAAY;AACpD,uBAAuB,YAAY;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -14,12 +14,13 @@ const DSMenuBehaviouralContextProvider = (props) => {
|
|
|
14
14
|
const {
|
|
15
15
|
trackFocusRegionReset,
|
|
16
16
|
propsWithDefault: { children },
|
|
17
|
-
preventBlurReset
|
|
17
|
+
preventBlurReset,
|
|
18
|
+
isMenuOpen
|
|
18
19
|
} = ctx;
|
|
19
20
|
const config = React2.useMemo(
|
|
20
21
|
() => ({
|
|
21
22
|
onBlur: () => {
|
|
22
|
-
if (!preventBlurReset.current) {
|
|
23
|
+
if (!preventBlurReset.current && !isMenuOpen) {
|
|
23
24
|
trackFocusRegionReset();
|
|
24
25
|
setTimeout(() => {
|
|
25
26
|
preventBlurReset.current = false;
|
|
@@ -27,7 +28,7 @@ const DSMenuBehaviouralContextProvider = (props) => {
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
}),
|
|
30
|
-
[preventBlurReset, trackFocusRegionReset]
|
|
31
|
+
[isMenuOpen, preventBlurReset, trackFocusRegionReset]
|
|
31
32
|
);
|
|
32
33
|
const handleOnBlurOut = useOnBlurOut(config);
|
|
33
34
|
return /* @__PURE__ */ jsx(MenuBehaviouralContextProviderContext.Provider, { value: ctx, children: /* @__PURE__ */ jsx("div", { onBlur: handleOnBlurOut, children }) });
|
package/dist/esm/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "// this not interactive per se, the implementation is listening the bubble phase of the events\n// from the children, this is the MVC pattern in action\n/* eslint-disable jsx-a11y/no-static-element-interactions */\nimport React from 'react';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { useOnBlurOut } from '@elliemae/ds-hooks-on-blur-out';\nimport {\n type DSMenuBehaviouralContextProviderT,\n DSMenuBehaviouralContextProviderPropTypesSchema,\n} from './react-desc-prop-types.js';\nimport { useMenuBehaviouralContextProvider } from './config/useMenuBehaviouralContextProvider.js';\nimport { MenuBehaviouralContextProviderContext } from './MenuBehaviouralContextProviderCTX.js';\nimport { DSMenuBehaviouralContextProviderName } from './constants/index.js';\n\nconst DSMenuBehaviouralContextProvider: React.ComponentType<DSMenuBehaviouralContextProviderT.Props> = (props) => {\n const ctx = useMenuBehaviouralContextProvider(props);\n const {\n trackFocusRegionReset,\n propsWithDefault: { children },\n preventBlurReset,\n } = ctx;\n\n const config = React.useMemo(\n () => ({\n onBlur: () => {\n // we have a portal, the portal temporarily steals the focus\n // invoking the blur event\n // when the blur event is invoked because the focus is stolen we do not want to reset the focus\n // any other blur event should reset the focus\n if (!preventBlurReset.current) {\n trackFocusRegionReset();\n setTimeout(() => {\n preventBlurReset.current = false;\n });\n }\n },\n }),\n [preventBlurReset, trackFocusRegionReset],\n );\n const handleOnBlurOut = useOnBlurOut(config);\n return (\n <MenuBehaviouralContextProviderContext.Provider value={ctx}>\n <div onBlur={handleOnBlurOut}>{children}</div>\n </MenuBehaviouralContextProviderContext.Provider>\n );\n};\n\nDSMenuBehaviouralContextProvider.displayName = DSMenuBehaviouralContextProviderName;\nconst DSMenuBehaviouralContextProviderWithSchema = describe(DSMenuBehaviouralContextProvider);\nDSMenuBehaviouralContextProviderWithSchema.propTypes = DSMenuBehaviouralContextProviderPropTypesSchema;\n\nexport { DSMenuBehaviouralContextProvider, DSMenuBehaviouralContextProviderWithSchema };\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "// this not interactive per se, the implementation is listening the bubble phase of the events\n// from the children, this is the MVC pattern in action\n/* eslint-disable jsx-a11y/no-static-element-interactions */\nimport React from 'react';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { useOnBlurOut } from '@elliemae/ds-hooks-on-blur-out';\nimport {\n type DSMenuBehaviouralContextProviderT,\n DSMenuBehaviouralContextProviderPropTypesSchema,\n} from './react-desc-prop-types.js';\nimport { useMenuBehaviouralContextProvider } from './config/useMenuBehaviouralContextProvider.js';\nimport { MenuBehaviouralContextProviderContext } from './MenuBehaviouralContextProviderCTX.js';\nimport { DSMenuBehaviouralContextProviderName } from './constants/index.js';\n\nconst DSMenuBehaviouralContextProvider: React.ComponentType<DSMenuBehaviouralContextProviderT.Props> = (props) => {\n const ctx = useMenuBehaviouralContextProvider(props);\n const {\n trackFocusRegionReset,\n propsWithDefault: { children },\n preventBlurReset,\n isMenuOpen,\n } = ctx;\n\n const config = React.useMemo(\n () => ({\n onBlur: () => {\n // we have a portal, the portal temporarily steals the focus\n // invoking the blur event\n // when the blur event is invoked because the focus is stolen we do not want to reset the focus\n // any other blur event should reset the focus\n // `preventBlurReset` is armed by the menu's own open intents, so a menu that the consumer opened by owning its\n // open state (a11yDangerouslyConsumerOwnedMenuOpenState) never armed it: while the menu is open, whoever\n // opened it, a blur is the portal stealing the focus and must not reset the focus tracker either\n if (!preventBlurReset.current && !isMenuOpen) {\n trackFocusRegionReset();\n setTimeout(() => {\n preventBlurReset.current = false;\n });\n }\n },\n }),\n [isMenuOpen, preventBlurReset, trackFocusRegionReset],\n );\n const handleOnBlurOut = useOnBlurOut(config);\n return (\n <MenuBehaviouralContextProviderContext.Provider value={ctx}>\n <div onBlur={handleOnBlurOut}>{children}</div>\n </MenuBehaviouralContextProviderContext.Provider>\n );\n};\n\nDSMenuBehaviouralContextProvider.displayName = DSMenuBehaviouralContextProviderName;\nconst DSMenuBehaviouralContextProviderWithSchema = describe(DSMenuBehaviouralContextProvider);\nDSMenuBehaviouralContextProviderWithSchema.propTypes = DSMenuBehaviouralContextProviderPropTypesSchema;\n\nexport { DSMenuBehaviouralContextProvider, DSMenuBehaviouralContextProviderWithSchema };\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AC8CjB;AA3CN,OAAOA,YAAW;AAClB,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yCAAyC;AAClD,SAAS,6CAA6C;AACtD,SAAS,4CAA4C;AAErD,MAAM,mCAAiG,CAAC,UAAU;AAChH,QAAM,MAAM,kCAAkC,KAAK;AACnD,QAAM;AAAA,IACJ;AAAA,IACA,kBAAkB,EAAE,SAAS;AAAA,IAC7B;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,SAASA,OAAM;AAAA,IACnB,OAAO;AAAA,MACL,QAAQ,MAAM;AAQZ,YAAI,CAAC,iBAAiB,WAAW,CAAC,YAAY;AAC5C,gCAAsB;AACtB,qBAAW,MAAM;AACf,6BAAiB,UAAU;AAAA,UAC7B,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,YAAY,kBAAkB,qBAAqB;AAAA,EACtD;AACA,QAAM,kBAAkB,aAAa,MAAM;AAC3C,SACE,oBAAC,sCAAsC,UAAtC,EAA+C,OAAO,KACrD,8BAAC,SAAI,QAAQ,iBAAkB,UAAS,GAC1C;AAEJ;AAEA,iCAAiC,cAAc;AAC/C,MAAM,6CAA6C,SAAS,gCAAgC;AAC5F,2CAA2C,YAAY;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -13,6 +13,7 @@ import { getFocusableSiblingsList } from "../utils/nodeGettersByCriterias.js";
|
|
|
13
13
|
const useFocusTracker = () => {
|
|
14
14
|
const shouldFocusImmediately = React2.useRef(false);
|
|
15
15
|
const shouldRefocusTrigger = React2.useRef(true);
|
|
16
|
+
const [triggerFocusRequestId, setTriggerFocusRequestId] = React2.useState(0);
|
|
16
17
|
const [focusRegion, setFocusRegion] = React2.useState("");
|
|
17
18
|
const focusedRegionPerformanceHelper = React2.useRef("");
|
|
18
19
|
const preventBlurReset = React2.useRef(false);
|
|
@@ -27,6 +28,9 @@ const useFocusTracker = () => {
|
|
|
27
28
|
focusedElementItemNode.current = focusNode;
|
|
28
29
|
shouldFocusImmediately.current = flags?.shouldFocusImmediately ?? false;
|
|
29
30
|
shouldRefocusTrigger.current = flags?.refocusTrigger ?? true;
|
|
31
|
+
if (newFocusRegion === MENU_FOCUS_REGIONS.TRIGGER && shouldRefocusTrigger.current) {
|
|
32
|
+
setTriggerFocusRequestId((previousRequestId) => previousRequestId + 1);
|
|
33
|
+
}
|
|
30
34
|
return focusNode;
|
|
31
35
|
},
|
|
32
36
|
50,
|
|
@@ -140,6 +144,7 @@ const useFocusTracker = () => {
|
|
|
140
144
|
() => ({
|
|
141
145
|
preventBlurReset,
|
|
142
146
|
focusRegion,
|
|
147
|
+
triggerFocusRequestId,
|
|
143
148
|
focusedElementItemNode,
|
|
144
149
|
shouldFocusImmediately,
|
|
145
150
|
shouldRefocusTrigger,
|
|
@@ -154,6 +159,7 @@ const useFocusTracker = () => {
|
|
|
154
159
|
}),
|
|
155
160
|
[
|
|
156
161
|
focusRegion,
|
|
162
|
+
triggerFocusRequestId,
|
|
157
163
|
trackFocusFirstChildItem,
|
|
158
164
|
trackFocusLastChildItem,
|
|
159
165
|
trackFocusNextItem,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable no-console */\n/* eslint-disable max-lines */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\n/* eslint-disable prettier/prettier */\nimport { throttle } from 'lodash-es';\nimport React from 'react';\nimport type { DSMenuButtonT } from '../../../react-desc-prop-types.js';\nimport {\n isFocusableNode,\n isGroup,\n isMenuNodeAllowedToHaveChildren,\n isRootNode,\n} from '../../../utils/nodesTypeguardsAndGetters.js';\nimport { TREE_STRUCTURE_ERRORS } from '../constants/Errors.js';\nimport { MENU_FOCUS_REGIONS } from '../constants/index.js';\nimport { getFocusableSiblingsList } from '../utils/nodeGettersByCriterias.js';\n\ntype MenuFocusRegionsValues = (typeof MENU_FOCUS_REGIONS)[keyof typeof MENU_FOCUS_REGIONS];\n// if MenuFocusRegionsValues may be a string or a function that returns a string, we want only the resolved strings\ntype ValidRegionsValues<T extends MenuFocusRegionsValues = MenuFocusRegionsValues> = T extends string\n ? T\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends (...args: any) => any\n ? ReturnType<T>\n : never;\n\nexport const useFocusTracker = () => {\n const shouldFocusImmediately = React.useRef(false);\n /*\n * Separates \"recording that focus is on the trigger\" from \"requesting focus return\n * to the trigger\": the trigger's own focus event tracks the region passively, while\n * menu-driven intents (close, keyboard nav) actively refocus. Without the split, the\n * deferred refocus can land after focus already legitimately moved on (e.g. the user\n * Tabbed away) and steal it back.\n */\n const shouldRefocusTrigger = React.useRef(true);\n const [focusRegion, setFocusRegion] = React.useState<ValidRegionsValues>('');\n // we want to keep the focus region trackers as stable as possible to avoid unnecessary re-renders\n // there is no need to change the trackers reference when the focus region changes,\n // since changing the focus region is always triggered by a final user interaction (so after reacts reconciliation)\n const focusedRegionPerformanceHelper = React.useRef('') as React.MutableRefObject<ValidRegionsValues>;\n const preventBlurReset = React.useRef(false);\n\n const focusedElementItemNode = React.useRef(\n null,\n ) as React.MutableRefObject<DSMenuButtonT.PseudoFocusableMenuNodes | null>;\n\n // typescript with debounce doesn't work well, so we need to disable the exhaustive deps rule here\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const racingConditionDebounceTrackFocus = React.useCallback(\n throttle(\n (\n newFocusRegion: ValidRegionsValues,\n focusNode: DSMenuButtonT.PseudoFocusableMenuNodes | null,\n flags?: { shouldFocusImmediately?: boolean; refocusTrigger?: boolean },\n ) => {\n setFocusRegion(newFocusRegion);\n focusedRegionPerformanceHelper.current = newFocusRegion;\n focusedElementItemNode.current = focusNode;\n\n shouldFocusImmediately.current = flags?.shouldFocusImmediately ?? false;\n shouldRefocusTrigger.current = flags?.refocusTrigger ?? true;\n\n return focusNode;\n },\n 50,\n { leading: true, trailing: true },\n ),\n [],\n );\n\n const trackFocusTrigger = React.useCallback(\n (options: { shouldFocusImmediately?: boolean; refocusTrigger?: boolean } = {}) =>\n racingConditionDebounceTrackFocus(MENU_FOCUS_REGIONS.TRIGGER, null, options),\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusNode = React.useCallback(\n (nodeToFocus: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n const newFocusRegion = MENU_FOCUS_REGIONS.ITEM_BY_DSID(nodeToFocus.dsId);\n racingConditionDebounceTrackFocus(newFocusRegion, nodeToFocus);\n },\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusRegionReset = React.useCallback(\n () => racingConditionDebounceTrackFocus(MENU_FOCUS_REGIONS.RESET, null),\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusFirstChildItem = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n if (!isMenuNodeAllowedToHaveChildren(itemNode)) {\n console.log('focus first child item > itemNode', itemNode);\n throw TREE_STRUCTURE_ERRORS.NODE_CANNOT_HAVE_CHILDREN;\n }\n if (itemNode.children.length === 0) {\n console.log(itemNode);\n throw new Error('No children found in the item node');\n }\n const focusableChildrenNodes = getFocusableSiblingsList(itemNode.children[0]);\n if (focusableChildrenNodes.length === 0) {\n console.log('focus first child item > itemNode', itemNode);\n throw new Error('No focusable nodes found in the children of the item node');\n }\n\n const newFocusedNode = focusableChildrenNodes[0];\n return racingConditionDebounceTrackFocus(MENU_FOCUS_REGIONS.ITEM_BY_DSID(newFocusedNode.dsId), newFocusedNode);\n },\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusLastChildItem = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n if (!isMenuNodeAllowedToHaveChildren(itemNode)) {\n console.log('focus last child item > itemNode', itemNode);\n throw new Error('Item node is not allowed to have children');\n }\n if (itemNode.children.length === 0) {\n console.log(itemNode);\n throw new Error('No children found in the item node');\n }\n const focusableChildrenNodes = getFocusableSiblingsList(itemNode.children[0]);\n if (focusableChildrenNodes.length === 0) {\n console.log('focus last child item > itemNode', itemNode);\n throw new Error('No focusable nodes found in the children of the item node');\n }\n return racingConditionDebounceTrackFocus(\n MENU_FOCUS_REGIONS.ITEM_BY_DSID(focusableChildrenNodes[focusableChildrenNodes.length - 1].dsId),\n focusableChildrenNodes[focusableChildrenNodes.length - 1],\n );\n },\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusNextItem = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n const focusableSiblingsNodes = getFocusableSiblingsList(itemNode);\n // we find the current item node index in the focusableSiblingsNodes array\n const currIndex = focusableSiblingsNodes.findIndex((node) => node.dsId === itemNode.dsId);\n\n const nextIndex = currIndex + 1 < focusableSiblingsNodes.length ? currIndex + 1 : 0;\n const newFocusedNode = focusableSiblingsNodes[nextIndex];\n return racingConditionDebounceTrackFocus(MENU_FOCUS_REGIONS.ITEM_BY_DSID(newFocusedNode.dsId), newFocusedNode);\n },\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusPreviousItem = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n const focusableSiblingsNodes = getFocusableSiblingsList(itemNode);\n // we find the current item node index in the focusableSiblingsNodes array\n const currIndex = focusableSiblingsNodes.findIndex((node) => node.dsId === itemNode.dsId);\n\n const previousIndex = currIndex - 1 >= 0 ? currIndex - 1 : focusableSiblingsNodes.length - 1;\n const newFocusNode = focusableSiblingsNodes[previousIndex];\n return racingConditionDebounceTrackFocus(MENU_FOCUS_REGIONS.ITEM_BY_DSID(newFocusNode.dsId), newFocusNode);\n },\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusParentItem = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n const { parent } = itemNode;\n // this typecast is required because we are reading the parent property from the itemNode\n // while this function can receive any PseudoFocusableMenuNodes,\n // the parent property may be a non-pseudo focusable node (specifically when the parent property is group node)\n const parentNode = parent;\n if (!parentNode) {\n console.log('focus parent item', { itemNode, parentNode });\n throw new Error(`No parent node found for the item node`);\n }\n\n let nodeToFocus: DSMenuButtonT.PseudoFocusableMenuNodes | null = parentNode;\n // if parent is SingleSelectGroupNode then we can't focus it\n if (isGroup(parentNode)) {\n const groupParent = parentNode.parent;\n if (!isFocusableNode(groupParent) && !isRootNode(groupParent)) {\n console.log('focus parent item', { itemNode, parentNode, groupParent });\n throw new Error('No focusable parent node found for the item node');\n }\n nodeToFocus = groupParent;\n }\n\n const focusableNode = isRootNode(nodeToFocus) ? null : nodeToFocus;\n const newFocusNode = focusableNode;\n if (!newFocusNode) trackFocusTrigger();\n else trackFocusNode(newFocusNode);\n\n return focusableNode;\n },\n [trackFocusNode, trackFocusTrigger],\n );\n\n return React.useMemo(\n () => ({\n preventBlurReset,\n focusRegion,\n focusedElementItemNode,\n shouldFocusImmediately,\n shouldRefocusTrigger,\n trackFocusTrigger,\n trackFocusNode,\n trackFocusRegionReset,\n trackFocusFirstChildItem,\n trackFocusLastChildItem,\n trackFocusNextItem,\n trackFocusPreviousItem,\n trackFocusParentItem,\n }),\n [\n focusRegion,\n trackFocusFirstChildItem,\n trackFocusLastChildItem,\n trackFocusNextItem,\n trackFocusNode,\n trackFocusParentItem,\n trackFocusPreviousItem,\n trackFocusRegionReset,\n trackFocusTrigger,\n ],\n );\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACKvB,SAAS,gBAAgB;AACzB,OAAOA,YAAW;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,6BAA6B;AACtC,SAAS,0BAA0B;AACnC,SAAS,gCAAgC;AAWlC,MAAM,kBAAkB,MAAM;AACnC,QAAM,yBAAyBA,OAAM,OAAO,KAAK;AAQjD,QAAM,uBAAuBA,OAAM,OAAO,IAAI;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable no-console */\n/* eslint-disable max-lines */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\n/* eslint-disable prettier/prettier */\nimport { throttle } from 'lodash-es';\nimport React from 'react';\nimport type { DSMenuButtonT } from '../../../react-desc-prop-types.js';\nimport {\n isFocusableNode,\n isGroup,\n isMenuNodeAllowedToHaveChildren,\n isRootNode,\n} from '../../../utils/nodesTypeguardsAndGetters.js';\nimport { TREE_STRUCTURE_ERRORS } from '../constants/Errors.js';\nimport { MENU_FOCUS_REGIONS } from '../constants/index.js';\nimport { getFocusableSiblingsList } from '../utils/nodeGettersByCriterias.js';\n\ntype MenuFocusRegionsValues = (typeof MENU_FOCUS_REGIONS)[keyof typeof MENU_FOCUS_REGIONS];\n// if MenuFocusRegionsValues may be a string or a function that returns a string, we want only the resolved strings\ntype ValidRegionsValues<T extends MenuFocusRegionsValues = MenuFocusRegionsValues> = T extends string\n ? T\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends (...args: any) => any\n ? ReturnType<T>\n : never;\n\nexport const useFocusTracker = () => {\n const shouldFocusImmediately = React.useRef(false);\n /*\n * Separates \"recording that focus is on the trigger\" from \"requesting focus return\n * to the trigger\": the trigger's own focus event tracks the region passively, while\n * menu-driven intents (close, keyboard nav) actively refocus. Without the split, the\n * deferred refocus can land after focus already legitimately moved on (e.g. the user\n * Tabbed away) and steal it back.\n */\n const shouldRefocusTrigger = React.useRef(true);\n /*\n * Identity of the latest request to return focus to the trigger. The trigger keys its ref callback on it, so each\n * request re-invokes the callback exactly once (React calls a ref callback again only when its reference changes).\n * It is deliberately NOT derived by comparing the focus region against a value stored during render: that\n * comparison is not idempotent, so React's StrictMode double render consumed it and the refocus never happened.\n */\n const [triggerFocusRequestId, setTriggerFocusRequestId] = React.useState(0);\n const [focusRegion, setFocusRegion] = React.useState<ValidRegionsValues>('');\n // we want to keep the focus region trackers as stable as possible to avoid unnecessary re-renders\n // there is no need to change the trackers reference when the focus region changes,\n // since changing the focus region is always triggered by a final user interaction (so after reacts reconciliation)\n const focusedRegionPerformanceHelper = React.useRef('') as React.MutableRefObject<ValidRegionsValues>;\n const preventBlurReset = React.useRef(false);\n\n const focusedElementItemNode = React.useRef(\n null,\n ) as React.MutableRefObject<DSMenuButtonT.PseudoFocusableMenuNodes | null>;\n\n // typescript with debounce doesn't work well, so we need to disable the exhaustive deps rule here\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const racingConditionDebounceTrackFocus = React.useCallback(\n throttle(\n (\n newFocusRegion: ValidRegionsValues,\n focusNode: DSMenuButtonT.PseudoFocusableMenuNodes | null,\n flags?: { shouldFocusImmediately?: boolean; refocusTrigger?: boolean },\n ) => {\n setFocusRegion(newFocusRegion);\n focusedRegionPerformanceHelper.current = newFocusRegion;\n focusedElementItemNode.current = focusNode;\n\n shouldFocusImmediately.current = flags?.shouldFocusImmediately ?? false;\n shouldRefocusTrigger.current = flags?.refocusTrigger ?? true;\n if (newFocusRegion === MENU_FOCUS_REGIONS.TRIGGER && shouldRefocusTrigger.current) {\n setTriggerFocusRequestId((previousRequestId) => previousRequestId + 1);\n }\n\n return focusNode;\n },\n 50,\n { leading: true, trailing: true },\n ),\n [],\n );\n\n const trackFocusTrigger = React.useCallback(\n (options: { shouldFocusImmediately?: boolean; refocusTrigger?: boolean } = {}) =>\n racingConditionDebounceTrackFocus(MENU_FOCUS_REGIONS.TRIGGER, null, options),\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusNode = React.useCallback(\n (nodeToFocus: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n const newFocusRegion = MENU_FOCUS_REGIONS.ITEM_BY_DSID(nodeToFocus.dsId);\n racingConditionDebounceTrackFocus(newFocusRegion, nodeToFocus);\n },\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusRegionReset = React.useCallback(\n () => racingConditionDebounceTrackFocus(MENU_FOCUS_REGIONS.RESET, null),\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusFirstChildItem = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n if (!isMenuNodeAllowedToHaveChildren(itemNode)) {\n console.log('focus first child item > itemNode', itemNode);\n throw TREE_STRUCTURE_ERRORS.NODE_CANNOT_HAVE_CHILDREN;\n }\n if (itemNode.children.length === 0) {\n console.log(itemNode);\n throw new Error('No children found in the item node');\n }\n const focusableChildrenNodes = getFocusableSiblingsList(itemNode.children[0]);\n if (focusableChildrenNodes.length === 0) {\n console.log('focus first child item > itemNode', itemNode);\n throw new Error('No focusable nodes found in the children of the item node');\n }\n\n const newFocusedNode = focusableChildrenNodes[0];\n return racingConditionDebounceTrackFocus(MENU_FOCUS_REGIONS.ITEM_BY_DSID(newFocusedNode.dsId), newFocusedNode);\n },\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusLastChildItem = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n if (!isMenuNodeAllowedToHaveChildren(itemNode)) {\n console.log('focus last child item > itemNode', itemNode);\n throw new Error('Item node is not allowed to have children');\n }\n if (itemNode.children.length === 0) {\n console.log(itemNode);\n throw new Error('No children found in the item node');\n }\n const focusableChildrenNodes = getFocusableSiblingsList(itemNode.children[0]);\n if (focusableChildrenNodes.length === 0) {\n console.log('focus last child item > itemNode', itemNode);\n throw new Error('No focusable nodes found in the children of the item node');\n }\n return racingConditionDebounceTrackFocus(\n MENU_FOCUS_REGIONS.ITEM_BY_DSID(focusableChildrenNodes[focusableChildrenNodes.length - 1].dsId),\n focusableChildrenNodes[focusableChildrenNodes.length - 1],\n );\n },\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusNextItem = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n const focusableSiblingsNodes = getFocusableSiblingsList(itemNode);\n // we find the current item node index in the focusableSiblingsNodes array\n const currIndex = focusableSiblingsNodes.findIndex((node) => node.dsId === itemNode.dsId);\n\n const nextIndex = currIndex + 1 < focusableSiblingsNodes.length ? currIndex + 1 : 0;\n const newFocusedNode = focusableSiblingsNodes[nextIndex];\n return racingConditionDebounceTrackFocus(MENU_FOCUS_REGIONS.ITEM_BY_DSID(newFocusedNode.dsId), newFocusedNode);\n },\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusPreviousItem = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n const focusableSiblingsNodes = getFocusableSiblingsList(itemNode);\n // we find the current item node index in the focusableSiblingsNodes array\n const currIndex = focusableSiblingsNodes.findIndex((node) => node.dsId === itemNode.dsId);\n\n const previousIndex = currIndex - 1 >= 0 ? currIndex - 1 : focusableSiblingsNodes.length - 1;\n const newFocusNode = focusableSiblingsNodes[previousIndex];\n return racingConditionDebounceTrackFocus(MENU_FOCUS_REGIONS.ITEM_BY_DSID(newFocusNode.dsId), newFocusNode);\n },\n [racingConditionDebounceTrackFocus],\n );\n\n const trackFocusParentItem = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n const { parent } = itemNode;\n // this typecast is required because we are reading the parent property from the itemNode\n // while this function can receive any PseudoFocusableMenuNodes,\n // the parent property may be a non-pseudo focusable node (specifically when the parent property is group node)\n const parentNode = parent;\n if (!parentNode) {\n console.log('focus parent item', { itemNode, parentNode });\n throw new Error(`No parent node found for the item node`);\n }\n\n let nodeToFocus: DSMenuButtonT.PseudoFocusableMenuNodes | null = parentNode;\n // if parent is SingleSelectGroupNode then we can't focus it\n if (isGroup(parentNode)) {\n const groupParent = parentNode.parent;\n if (!isFocusableNode(groupParent) && !isRootNode(groupParent)) {\n console.log('focus parent item', { itemNode, parentNode, groupParent });\n throw new Error('No focusable parent node found for the item node');\n }\n nodeToFocus = groupParent;\n }\n\n const focusableNode = isRootNode(nodeToFocus) ? null : nodeToFocus;\n const newFocusNode = focusableNode;\n if (!newFocusNode) trackFocusTrigger();\n else trackFocusNode(newFocusNode);\n\n return focusableNode;\n },\n [trackFocusNode, trackFocusTrigger],\n );\n\n return React.useMemo(\n () => ({\n preventBlurReset,\n focusRegion,\n triggerFocusRequestId,\n focusedElementItemNode,\n shouldFocusImmediately,\n shouldRefocusTrigger,\n trackFocusTrigger,\n trackFocusNode,\n trackFocusRegionReset,\n trackFocusFirstChildItem,\n trackFocusLastChildItem,\n trackFocusNextItem,\n trackFocusPreviousItem,\n trackFocusParentItem,\n }),\n [\n focusRegion,\n triggerFocusRequestId,\n trackFocusFirstChildItem,\n trackFocusLastChildItem,\n trackFocusNextItem,\n trackFocusNode,\n trackFocusParentItem,\n trackFocusPreviousItem,\n trackFocusRegionReset,\n trackFocusTrigger,\n ],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACKvB,SAAS,gBAAgB;AACzB,OAAOA,YAAW;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,6BAA6B;AACtC,SAAS,0BAA0B;AACnC,SAAS,gCAAgC;AAWlC,MAAM,kBAAkB,MAAM;AACnC,QAAM,yBAAyBA,OAAM,OAAO,KAAK;AAQjD,QAAM,uBAAuBA,OAAM,OAAO,IAAI;AAO9C,QAAM,CAAC,uBAAuB,wBAAwB,IAAIA,OAAM,SAAS,C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;AAAA,IACX,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -22,7 +22,7 @@ const useMenuItemEventsHandlers = ({
|
|
|
22
22
|
menuOpenStatus,
|
|
23
23
|
handleChangeOpenedSubItems
|
|
24
24
|
}) => {
|
|
25
|
-
const { onItemSelected, onActivateItem, selectedNodes, buttonDOMNodeRef } = propsWithDefault;
|
|
25
|
+
const { onItemSelected, onActivateItem, onItemKeyDown, selectedNodes, buttonDOMNodeRef } = propsWithDefault;
|
|
26
26
|
const { onOpinionatedClose } = menuOpenStatus;
|
|
27
27
|
const {
|
|
28
28
|
trackFocusFirstChildItem,
|
|
@@ -153,9 +153,7 @@ const useMenuItemEventsHandlers = ({
|
|
|
153
153
|
if (isWithSubmenuNode(pseudoFocusedItemNode)) {
|
|
154
154
|
openSubmenu({ itemNode: pseudoFocusedItemNode, event });
|
|
155
155
|
trackFocusFirstChildItem(pseudoFocusedItemNode);
|
|
156
|
-
return;
|
|
157
156
|
}
|
|
158
|
-
return;
|
|
159
157
|
},
|
|
160
158
|
[openSubmenu, trackFocusFirstChildItem]
|
|
161
159
|
);
|
|
@@ -180,29 +178,48 @@ const useMenuItemEventsHandlers = ({
|
|
|
180
178
|
const handleFocusableMenuItemKeyDown = React2.useCallback(
|
|
181
179
|
(event) => {
|
|
182
180
|
if (event.key === "Tab") return;
|
|
181
|
+
const consumeKey = () => {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
event.stopPropagation();
|
|
184
|
+
};
|
|
183
185
|
const pseudoFocusedItemNode = focusedElementItemNode.current;
|
|
184
186
|
if (pseudoFocusedItemNode === null) throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_NODE_NOT_SET;
|
|
185
187
|
if (pseudoFocusedItemNode.plainItem.onKeyDown) pseudoFocusedItemNode.plainItem.onKeyDown(event);
|
|
188
|
+
if (onItemKeyDown) {
|
|
189
|
+
onItemKeyDown({
|
|
190
|
+
itemNode: pseudoFocusedItemNode,
|
|
191
|
+
event,
|
|
192
|
+
nestLevel: getSubMenusPath(pseudoFocusedItemNode).length,
|
|
193
|
+
hasSubmenu: isWithSubmenuNode(pseudoFocusedItemNode)
|
|
194
|
+
});
|
|
195
|
+
}
|
|
186
196
|
if (event.key === "ArrowDown") {
|
|
187
|
-
|
|
197
|
+
consumeKey();
|
|
188
198
|
trackFocusNextItem(pseudoFocusedItemNode);
|
|
189
199
|
return;
|
|
190
200
|
}
|
|
191
201
|
if (event.key === "ArrowUp") {
|
|
192
|
-
|
|
202
|
+
consumeKey();
|
|
193
203
|
trackFocusPreviousItem(pseudoFocusedItemNode);
|
|
194
204
|
return;
|
|
195
205
|
}
|
|
196
206
|
if (event.key === "ArrowLeft") {
|
|
197
|
-
|
|
207
|
+
consumeKey();
|
|
198
208
|
handleMenuItemLeftArrowKeyDown({ pseudoFocusedItemNode, event });
|
|
199
209
|
return;
|
|
200
210
|
}
|
|
211
|
+
if (event.key === "ArrowRight") {
|
|
212
|
+
consumeKey();
|
|
213
|
+
if (!pseudoFocusedItemNode.plainItem.disabled)
|
|
214
|
+
handleMenuItemRightArrowKeyDown({ pseudoFocusedItemNode, event });
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
201
217
|
if (event.key === "Home") {
|
|
202
218
|
if (!pseudoFocusedItemNode.parent) {
|
|
203
219
|
console.log("handleFocusableMenuItemKeyDown -> Home > focused item node", pseudoFocusedItemNode);
|
|
204
220
|
throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_HAS_NO_PARENT;
|
|
205
221
|
}
|
|
222
|
+
consumeKey();
|
|
206
223
|
trackFocusFirstChildItem(pseudoFocusedItemNode.parent);
|
|
207
224
|
return;
|
|
208
225
|
}
|
|
@@ -211,6 +228,7 @@ const useMenuItemEventsHandlers = ({
|
|
|
211
228
|
console.log("handleFocusableMenuItemKeyDown -> Home > focused item node", pseudoFocusedItemNode);
|
|
212
229
|
throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_HAS_NO_PARENT;
|
|
213
230
|
}
|
|
231
|
+
consumeKey();
|
|
214
232
|
trackFocusLastChildItem(pseudoFocusedItemNode.parent);
|
|
215
233
|
return;
|
|
216
234
|
}
|
|
@@ -231,22 +249,19 @@ const useMenuItemEventsHandlers = ({
|
|
|
231
249
|
}
|
|
232
250
|
if (pseudoFocusedItemNode.plainItem.disabled) return;
|
|
233
251
|
if (event.key === "Enter") {
|
|
252
|
+
event.stopPropagation();
|
|
234
253
|
handleMenuItemEnterKeyDown({ pseudoFocusedItemNode, event });
|
|
235
254
|
return;
|
|
236
255
|
}
|
|
237
256
|
if (event.key === " ") {
|
|
238
|
-
|
|
257
|
+
consumeKey();
|
|
239
258
|
handleMenuItemSpaceKeyDown({ pseudoFocusedItemNode, event });
|
|
240
259
|
return;
|
|
241
260
|
}
|
|
242
|
-
if (event.key === "ArrowRight") {
|
|
243
|
-
event?.preventDefault();
|
|
244
|
-
handleMenuItemRightArrowKeyDown({ pseudoFocusedItemNode, event });
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
261
|
},
|
|
248
262
|
[
|
|
249
263
|
focusedElementItemNode,
|
|
264
|
+
onItemKeyDown,
|
|
250
265
|
trackFocusTrigger,
|
|
251
266
|
trackFocusNextItem,
|
|
252
267
|
trackFocusPreviousItem,
|