@react-stately/menu 3.5.8-nightly.4324 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js.map +1 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +6 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +1 -1
- package/src/useMenuTriggerState.ts +8 -6
- package/src/useSubmenuTriggerState.ts +2 -2
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AAuCM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,sBAAsB,CAAA,GAAA,kDAAqB,EAAE;IACjD,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAiB;IAChE,IAAI,CAAC,mBAAmB,qBAAqB,GAAG,CAAA,GAAA,qBAAO,EAAS,EAAE;IAElE,IAAI,WAAW;QACb,qBAAqB,EAAE;QACvB,oBAAoB,KAAK;IAC3B;IAEA,IAAI,cAAc,CAAC,YAAiB;QAClC,qBAAqB,CAAA;YACnB,IAAI,QAAQ,SAAS,MAAM,EACzB,OAAO;YAGT,OAAO;mBAAI,SAAS,KAAK,CAAC,GAAG;gBAAQ;aAAW;QAClD;IACF;IAEA,IAAI,eAAe,CAAC,YAAiB;QACnC,qBAAqB,CAAA;YACnB,IAAI,MAAM,QAAQ,CAAC,MAAM;YACzB,IAAI,QAAQ,YACV,OAAO,SAAS,KAAK,CAAC,GAAG;iBAEzB,OAAO;QAEX;IACF;IAEA,OAAO;uBACL;QACA,GAAG,mBAAmB;QACtB,MAAK,gBAA+B,IAAI;YACtC,iBAAiB;YACjB,oBAAoB,IAAI;QAC1B;QACA,QAAO,gBAA+B,IAAI;YACxC,iBA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.ts","packages/@react-stately/menu/src/useSubmenuTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useMenuTriggerState} from './useMenuTriggerState';\nexport {UNSTABLE_useSubmenuTriggerState} from './useSubmenuTriggerState';\n\nexport type {MenuTriggerProps} from '@react-types/menu';\nexport type {MenuTriggerState, RootMenuTriggerState} from './useMenuTriggerState';\nexport type {SubmenuTriggerProps, SubmenuTriggerState} from './useSubmenuTriggerState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusStrategy, Key} from '@react-types/shared';\nimport {MenuTriggerProps} from '@react-types/menu';\nimport {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';\nimport {useState} from 'react';\n\nexport interface MenuTriggerState extends OverlayTriggerState {\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy,\n\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null): void,\n\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null): void\n}\n\nexport interface RootMenuTriggerState extends MenuTriggerState {\n /** Opens a specific submenu tied to a specific menu item at a specific level. */\n UNSTABLE_openSubmenu: (triggerKey: Key, level: number) => void,\n\n /** Closes a specific submenu tied to a specific menu item at a specific level. */\n UNSTABLE_closeSubmenu: (triggerKey: Key, level: number) => void,\n\n /** An array of open submenu trigger keys within the menu tree.\n * The index of key within array matches the submenu level in the tree.\n */\n UNSTABLE_expandedKeysStack: Key[],\n\n /** Closes the menu and all submenus in the menu tree. */\n close: () => void\n}\n\n/**\n * Manages state for a menu trigger. Tracks whether the menu is currently open,\n * and controls which item will receive focus when it opens. Also tracks the open submenus within\n * the menu tree via their trigger keys.\n */\nexport function useMenuTriggerState(props: MenuTriggerProps): RootMenuTriggerState {\n let overlayTriggerState = useOverlayTriggerState(props);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy>(null);\n let [expandedKeysStack, setExpandedKeysStack] = useState<Key[]>([]);\n\n let closeAll = () => {\n setExpandedKeysStack([]);\n overlayTriggerState.close();\n };\n\n let openSubmenu = (triggerKey: Key, level: number) => {\n setExpandedKeysStack(oldStack => {\n if (level > oldStack.length) {\n return oldStack;\n }\n\n return [...oldStack.slice(0, level), triggerKey];\n });\n };\n\n let closeSubmenu = (triggerKey: Key, level: number) => {\n setExpandedKeysStack(oldStack => {\n let key = oldStack[level];\n if (key === triggerKey) {\n return oldStack.slice(0, level);\n } else {\n return oldStack;\n }\n });\n };\n\n return {\n focusStrategy,\n ...overlayTriggerState,\n open(focusStrategy: FocusStrategy = null) {\n setFocusStrategy(focusStrategy);\n overlayTriggerState.open();\n },\n toggle(focusStrategy: FocusStrategy = null) {\n setFocusStrategy(focusStrategy);\n overlayTriggerState.toggle();\n },\n close() {\n closeAll();\n },\n UNSTABLE_expandedKeysStack: expandedKeysStack,\n UNSTABLE_openSubmenu: openSubmenu,\n UNSTABLE_closeSubmenu: closeSubmenu\n };\n}\n","/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusStrategy, Key} from '@react-types/shared';\nimport type {OverlayTriggerState} from '@react-stately/overlays';\nimport {RootMenuTriggerState} from './useMenuTriggerState';\nimport {useCallback, useMemo, useState} from 'react';\n\nexport interface SubmenuTriggerProps {\n /** Key of the trigger item. */\n triggerKey: Key\n}\n\nexport interface SubmenuTriggerState extends OverlayTriggerState {\n /** Whether the submenu is currently open. */\n isOpen: boolean,\n /** Controls which item will be auto focused when the submenu opens. */\n focusStrategy: FocusStrategy | null,\n /** Opens the submenu. */\n open: (focusStrategy?: FocusStrategy | null) => void,\n /** Closes the submenu. */\n close: () => void,\n /** Closes all menus and submenus in the menu tree. */\n closeAll: () => void,\n /** The level of the submenu. */\n submenuLevel: number,\n /** Toggles the submenu. */\n toggle: (focusStrategy?: FocusStrategy | null) => void,\n /** @private */\n setOpen: () => void\n}\n\n/**\n * Manages state for a submenu trigger. Tracks whether the submenu is currently open, the level of the submenu, and\n * controls which item will receive focus when it opens.\n */\nexport function UNSTABLE_useSubmenuTriggerState(props: SubmenuTriggerProps, state: RootMenuTriggerState): SubmenuTriggerState {\n let {triggerKey} = props;\n let {UNSTABLE_expandedKeysStack, UNSTABLE_openSubmenu, UNSTABLE_closeSubmenu, close: closeAll} = state;\n let [submenuLevel] = useState(UNSTABLE_expandedKeysStack?.length);\n let isOpen = useMemo(() => UNSTABLE_expandedKeysStack[submenuLevel] === triggerKey, [UNSTABLE_expandedKeysStack, triggerKey, submenuLevel]);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy>(null);\n\n let open = useCallback((focusStrategy: FocusStrategy = null) => {\n setFocusStrategy(focusStrategy);\n UNSTABLE_openSubmenu(triggerKey, submenuLevel);\n }, [UNSTABLE_openSubmenu, submenuLevel, triggerKey]);\n\n let close = useCallback(() => {\n setFocusStrategy(null);\n UNSTABLE_closeSubmenu(triggerKey, submenuLevel);\n }, [UNSTABLE_closeSubmenu, submenuLevel, triggerKey]);\n\n let toggle = useCallback((focusStrategy: FocusStrategy = null) => {\n setFocusStrategy(focusStrategy);\n if (isOpen) {\n close();\n } else {\n open(focusStrategy);\n }\n }, [close, open, isOpen]);\n\n return useMemo(() => ({\n focusStrategy,\n isOpen,\n open,\n close,\n closeAll,\n submenuLevel,\n // TODO: Placeholders that aren't used but give us parity with OverlayTriggerState so we can use this in Popover. Refactor if we update Popover via\n // https://github.com/adobe/react-spectrum/pull/4976#discussion_r1336472863\n setOpen: () => {},\n toggle\n }), [isOpen, open, close, closeAll, focusStrategy, toggle, submenuLevel]);\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AAuCM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,sBAAsB,CAAA,GAAA,6BAAqB,EAAE;IACjD,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAChE,IAAI,CAAC,mBAAmB,qBAAqB,GAAG,CAAA,GAAA,eAAO,EAAS,EAAE;IAElE,IAAI,WAAW;QACb,qBAAqB,EAAE;QACvB,oBAAoB,KAAK;IAC3B;IAEA,IAAI,cAAc,CAAC,YAAiB;QAClC,qBAAqB,CAAA;YACnB,IAAI,QAAQ,SAAS,MAAM,EACzB,OAAO;YAGT,OAAO;mBAAI,SAAS,KAAK,CAAC,GAAG;gBAAQ;aAAW;QAClD;IACF;IAEA,IAAI,eAAe,CAAC,YAAiB;QACnC,qBAAqB,CAAA;YACnB,IAAI,MAAM,QAAQ,CAAC,MAAM;YACzB,IAAI,QAAQ,YACV,OAAO,SAAS,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AmJ;YACnJ,2EAA2E;YAC3E,SAAS,KAAO;oBAChB;QACF,CAAA,GAAI;QAAC;QAAQ;QAAM;QAAO;QAAU;QAAe;QAAQ;KAAa;AAC1E;","sources":["packages/@react-stately/menu/src/index.ts","packages/@react-stately/menu/src/useMenuTriggerState.ts","packages/@react-stately/menu/src/useSubmenuTriggerState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useMenuTriggerState} from './useMenuTriggerState';\nexport {UNSTABLE_useSubmenuTriggerState} from './useSubmenuTriggerState';\n\nexport type {MenuTriggerProps} from '@react-types/menu';\nexport type {MenuTriggerState, RootMenuTriggerState} from './useMenuTriggerState';\nexport type {SubmenuTriggerProps, SubmenuTriggerState} from './useSubmenuTriggerState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusStrategy, Key} from '@react-types/shared';\nimport {MenuTriggerProps} from '@react-types/menu';\nimport {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';\nimport {useState} from 'react';\n\nexport interface MenuTriggerState extends OverlayTriggerState {\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy,\n\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null): void,\n\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null): void\n}\n\nexport interface RootMenuTriggerState extends MenuTriggerState {\n /** Opens a specific submenu tied to a specific menu item at a specific level. */\n UNSTABLE_openSubmenu: (triggerKey: Key, level: number) => void,\n\n /** Closes a specific submenu tied to a specific menu item at a specific level. */\n UNSTABLE_closeSubmenu: (triggerKey: Key, level: number) => void,\n\n /** An array of open submenu trigger keys within the menu tree.\n * The index of key within array matches the submenu level in the tree.\n */\n UNSTABLE_expandedKeysStack: Key[],\n\n /** Closes the menu and all submenus in the menu tree. */\n close: () => void\n}\n\n/**\n * Manages state for a menu trigger. Tracks whether the menu is currently open,\n * and controls which item will receive focus when it opens. Also tracks the open submenus within\n * the menu tree via their trigger keys.\n */\nexport function useMenuTriggerState(props: MenuTriggerProps): RootMenuTriggerState {\n let overlayTriggerState = useOverlayTriggerState(props);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy>(null);\n let [expandedKeysStack, setExpandedKeysStack] = useState<Key[]>([]);\n\n let closeAll = () => {\n setExpandedKeysStack([]);\n overlayTriggerState.close();\n };\n\n let openSubmenu = (triggerKey: Key, level: number) => {\n setExpandedKeysStack(oldStack => {\n if (level > oldStack.length) {\n return oldStack;\n }\n\n return [...oldStack.slice(0, level), triggerKey];\n });\n };\n\n let closeSubmenu = (triggerKey: Key, level: number) => {\n setExpandedKeysStack(oldStack => {\n let key = oldStack[level];\n if (key === triggerKey) {\n return oldStack.slice(0, level);\n } else {\n return oldStack;\n }\n });\n };\n\n return {\n focusStrategy,\n ...overlayTriggerState,\n open(focusStrategy: FocusStrategy = null) {\n setFocusStrategy(focusStrategy);\n overlayTriggerState.open();\n },\n toggle(focusStrategy: FocusStrategy = null) {\n setFocusStrategy(focusStrategy);\n overlayTriggerState.toggle();\n },\n close() {\n closeAll();\n },\n UNSTABLE_expandedKeysStack: expandedKeysStack,\n UNSTABLE_openSubmenu: openSubmenu,\n UNSTABLE_closeSubmenu: closeSubmenu\n };\n}\n","/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusStrategy, Key} from '@react-types/shared';\nimport type {OverlayTriggerState} from '@react-stately/overlays';\nimport {RootMenuTriggerState} from './useMenuTriggerState';\nimport {useCallback, useMemo, useState} from 'react';\n\nexport interface SubmenuTriggerProps {\n /** Key of the trigger item. */\n triggerKey: Key\n}\n\nexport interface SubmenuTriggerState extends OverlayTriggerState {\n /** Whether the submenu is currently open. */\n isOpen: boolean,\n /** Controls which item will be auto focused when the submenu opens. */\n focusStrategy: FocusStrategy | null,\n /** Opens the submenu. */\n open: (focusStrategy?: FocusStrategy | null) => void,\n /** Closes the submenu. */\n close: () => void,\n /** Closes all menus and submenus in the menu tree. */\n closeAll: () => void,\n /** The level of the submenu. */\n submenuLevel: number,\n /** Toggles the submenu. */\n toggle: (focusStrategy?: FocusStrategy | null) => void,\n /** @private */\n setOpen: () => void\n}\n\n/**\n * Manages state for a submenu trigger. Tracks whether the submenu is currently open, the level of the submenu, and\n * controls which item will receive focus when it opens.\n */\nexport function UNSTABLE_useSubmenuTriggerState(props: SubmenuTriggerProps, state: RootMenuTriggerState): SubmenuTriggerState {\n let {triggerKey} = props;\n let {UNSTABLE_expandedKeysStack, UNSTABLE_openSubmenu, UNSTABLE_closeSubmenu, close: closeAll} = state;\n let [submenuLevel] = useState(UNSTABLE_expandedKeysStack?.length);\n let isOpen = useMemo(() => UNSTABLE_expandedKeysStack[submenuLevel] === triggerKey, [UNSTABLE_expandedKeysStack, triggerKey, submenuLevel]);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy>(null);\n\n let open = useCallback((focusStrategy: FocusStrategy = null) => {\n setFocusStrategy(focusStrategy);\n UNSTABLE_openSubmenu(triggerKey, submenuLevel);\n }, [UNSTABLE_openSubmenu, submenuLevel, triggerKey]);\n\n let close = useCallback(() => {\n setFocusStrategy(null);\n UNSTABLE_closeSubmenu(triggerKey, submenuLevel);\n }, [UNSTABLE_closeSubmenu, submenuLevel, triggerKey]);\n\n let toggle = useCallback((focusStrategy: FocusStrategy = null) => {\n setFocusStrategy(focusStrategy);\n if (isOpen) {\n close();\n } else {\n open(focusStrategy);\n }\n }, [close, open, isOpen]);\n\n return useMemo(() => ({\n focusStrategy,\n isOpen,\n open,\n close,\n closeAll,\n submenuLevel,\n // TODO: Placeholders that aren't used but give us parity with OverlayTriggerState so we can use this in Popover. Refactor if we update Popover via\n // https://github.com/adobe/react-spectrum/pull/4976#discussion_r1336472863\n setOpen: () => {},\n toggle\n }), [isOpen, open, close, closeAll, focusStrategy, toggle, submenuLevel]);\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export interface MenuTriggerState extends OverlayTriggerState {
|
|
|
8
8
|
open(focusStrategy?: FocusStrategy | null): void;
|
|
9
9
|
/** Toggles the menu. */
|
|
10
10
|
toggle(focusStrategy?: FocusStrategy | null): void;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
export interface RootMenuTriggerState extends MenuTriggerState {
|
|
13
13
|
/** Opens a specific submenu tied to a specific menu item at a specific level. */
|
|
14
14
|
UNSTABLE_openSubmenu: (triggerKey: Key, level: number) => void;
|
|
15
15
|
/** Closes a specific submenu tied to a specific menu item at a specific level. */
|
|
@@ -18,13 +18,15 @@ export interface MenuTriggerState extends OverlayTriggerState {
|
|
|
18
18
|
* The index of key within array matches the submenu level in the tree.
|
|
19
19
|
*/
|
|
20
20
|
UNSTABLE_expandedKeysStack: Key[];
|
|
21
|
+
/** Closes the menu and all submenus in the menu tree. */
|
|
22
|
+
close: () => void;
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Manages state for a menu trigger. Tracks whether the menu is currently open,
|
|
24
26
|
* and controls which item will receive focus when it opens. Also tracks the open submenus within
|
|
25
27
|
* the menu tree via their trigger keys.
|
|
26
28
|
*/
|
|
27
|
-
export function useMenuTriggerState(props: MenuTriggerProps):
|
|
29
|
+
export function useMenuTriggerState(props: MenuTriggerProps): RootMenuTriggerState;
|
|
28
30
|
export interface SubmenuTriggerProps {
|
|
29
31
|
/** Key of the trigger item. */
|
|
30
32
|
triggerKey: Key;
|
|
@@ -51,7 +53,7 @@ export interface SubmenuTriggerState extends OverlayTriggerState {
|
|
|
51
53
|
* Manages state for a submenu trigger. Tracks whether the submenu is currently open, the level of the submenu, and
|
|
52
54
|
* controls which item will receive focus when it opens.
|
|
53
55
|
*/
|
|
54
|
-
export function UNSTABLE_useSubmenuTriggerState(props: SubmenuTriggerProps, state:
|
|
56
|
+
export function UNSTABLE_useSubmenuTriggerState(props: SubmenuTriggerProps, state: RootMenuTriggerState): SubmenuTriggerState;
|
|
55
57
|
export type { MenuTriggerProps } from '@react-types/menu';
|
|
56
58
|
|
|
57
59
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAiBA,iCAAkC,SAAQ,mBAAmB;IAC3D,oEAAoE;IACpE,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IAEtC,sBAAsB;IACtB,IAAI,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC;IAEjD,wBAAwB;IACxB,MAAM,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,
|
|
1
|
+
{"mappings":";;;AAiBA,iCAAkC,SAAQ,mBAAmB;IAC3D,oEAAoE;IACpE,QAAQ,CAAC,aAAa,EAAE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EAAE,KAAK,EAAE,oBAAoB,GAAG,mBAAmB,CAsC5H;ACpED,YAAY,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC","sources":["packages/@react-stately/menu/src/packages/@react-stately/menu/src/useMenuTriggerState.ts","packages/@react-stately/menu/src/packages/@react-stately/menu/src/useSubmenuTriggerState.ts","packages/@react-stately/menu/src/packages/@react-stately/menu/src/index.ts","packages/@react-stately/menu/src/index.ts"],"sourcesContent":[null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useMenuTriggerState} from './useMenuTriggerState';\nexport {UNSTABLE_useSubmenuTriggerState} from './useSubmenuTriggerState';\n\nexport type {MenuTriggerProps} from '@react-types/menu';\nexport type {MenuTriggerState, RootMenuTriggerState} from './useMenuTriggerState';\nexport type {SubmenuTriggerProps, SubmenuTriggerState} from './useSubmenuTriggerState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/menu",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-stately/overlays": "3.6.
|
|
26
|
-
"@react-types/menu": "3.9.
|
|
27
|
-
"@react-types/shared": "3.
|
|
25
|
+
"@react-stately/overlays": "^3.6.4",
|
|
26
|
+
"@react-types/menu": "^3.9.6",
|
|
27
|
+
"@react-types/shared": "^3.22.0",
|
|
28
28
|
"@swc/helpers": "^0.5.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "86b38c87868ce7f262e0df905e5ac4eb2653791d"
|
|
37
37
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,5 +14,5 @@ export {useMenuTriggerState} from './useMenuTriggerState';
|
|
|
14
14
|
export {UNSTABLE_useSubmenuTriggerState} from './useSubmenuTriggerState';
|
|
15
15
|
|
|
16
16
|
export type {MenuTriggerProps} from '@react-types/menu';
|
|
17
|
-
export type {MenuTriggerState} from './useMenuTriggerState';
|
|
17
|
+
export type {MenuTriggerState, RootMenuTriggerState} from './useMenuTriggerState';
|
|
18
18
|
export type {SubmenuTriggerProps, SubmenuTriggerState} from './useSubmenuTriggerState';
|
|
@@ -23,11 +23,10 @@ export interface MenuTriggerState extends OverlayTriggerState {
|
|
|
23
23
|
open(focusStrategy?: FocusStrategy | null): void,
|
|
24
24
|
|
|
25
25
|
/** Toggles the menu. */
|
|
26
|
-
toggle(focusStrategy?: FocusStrategy | null): void
|
|
27
|
-
|
|
28
|
-
/** Closes the menu and all submenus in the menu tree. */
|
|
29
|
-
close: () => void,
|
|
26
|
+
toggle(focusStrategy?: FocusStrategy | null): void
|
|
27
|
+
}
|
|
30
28
|
|
|
29
|
+
export interface RootMenuTriggerState extends MenuTriggerState {
|
|
31
30
|
/** Opens a specific submenu tied to a specific menu item at a specific level. */
|
|
32
31
|
UNSTABLE_openSubmenu: (triggerKey: Key, level: number) => void,
|
|
33
32
|
|
|
@@ -37,7 +36,10 @@ export interface MenuTriggerState extends OverlayTriggerState {
|
|
|
37
36
|
/** An array of open submenu trigger keys within the menu tree.
|
|
38
37
|
* The index of key within array matches the submenu level in the tree.
|
|
39
38
|
*/
|
|
40
|
-
UNSTABLE_expandedKeysStack: Key[]
|
|
39
|
+
UNSTABLE_expandedKeysStack: Key[],
|
|
40
|
+
|
|
41
|
+
/** Closes the menu and all submenus in the menu tree. */
|
|
42
|
+
close: () => void
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
/**
|
|
@@ -45,7 +47,7 @@ export interface MenuTriggerState extends OverlayTriggerState {
|
|
|
45
47
|
* and controls which item will receive focus when it opens. Also tracks the open submenus within
|
|
46
48
|
* the menu tree via their trigger keys.
|
|
47
49
|
*/
|
|
48
|
-
export function useMenuTriggerState(props: MenuTriggerProps):
|
|
50
|
+
export function useMenuTriggerState(props: MenuTriggerProps): RootMenuTriggerState {
|
|
49
51
|
let overlayTriggerState = useOverlayTriggerState(props);
|
|
50
52
|
let [focusStrategy, setFocusStrategy] = useState<FocusStrategy>(null);
|
|
51
53
|
let [expandedKeysStack, setExpandedKeysStack] = useState<Key[]>([]);
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {FocusStrategy, Key} from '@react-types/shared';
|
|
14
|
-
import type {MenuTriggerState} from './useMenuTriggerState';
|
|
15
14
|
import type {OverlayTriggerState} from '@react-stately/overlays';
|
|
15
|
+
import {RootMenuTriggerState} from './useMenuTriggerState';
|
|
16
16
|
import {useCallback, useMemo, useState} from 'react';
|
|
17
17
|
|
|
18
18
|
export interface SubmenuTriggerProps {
|
|
@@ -43,7 +43,7 @@ export interface SubmenuTriggerState extends OverlayTriggerState {
|
|
|
43
43
|
* Manages state for a submenu trigger. Tracks whether the submenu is currently open, the level of the submenu, and
|
|
44
44
|
* controls which item will receive focus when it opens.
|
|
45
45
|
*/
|
|
46
|
-
export function UNSTABLE_useSubmenuTriggerState(props: SubmenuTriggerProps, state:
|
|
46
|
+
export function UNSTABLE_useSubmenuTriggerState(props: SubmenuTriggerProps, state: RootMenuTriggerState): SubmenuTriggerState {
|
|
47
47
|
let {triggerKey} = props;
|
|
48
48
|
let {UNSTABLE_expandedKeysStack, UNSTABLE_openSubmenu, UNSTABLE_closeSubmenu, close: closeAll} = state;
|
|
49
49
|
let [submenuLevel] = useState(UNSTABLE_expandedKeysStack?.length);
|