@react-stately/menu 3.6.2-nightly.4555 → 3.6.2-nightly.4558

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/import.mjs CHANGED
@@ -1,17 +1,7 @@
1
- import {useOverlayTriggerState as $9Xvoh$useOverlayTriggerState} from "@react-stately/overlays";
2
- import {useState as $9Xvoh$useState, useMemo as $9Xvoh$useMemo, useCallback as $9Xvoh$useCallback} from "react";
1
+ import {useMenuTriggerState as $a28c903ee9ad8dc5$export$79fefeb1c2091ac3} from "./useMenuTriggerState.mjs";
2
+ import {UNSTABLE_useSubmenuTriggerState as $e5614764aa47eb35$export$d39fdbfa42246ac4} from "./useSubmenuTriggerState.mjs";
3
3
 
4
4
  /*
5
- * Copyright 2020 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */ /*
15
5
  * Copyright 2020 Adobe. All rights reserved.
16
6
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
17
7
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -23,120 +13,6 @@ import {useState as $9Xvoh$useState, useMemo as $9Xvoh$useMemo, useCallback as $
23
13
  * governing permissions and limitations under the License.
24
14
  */
25
15
 
26
- function $a28c903ee9ad8dc5$export$79fefeb1c2091ac3(props) {
27
- let overlayTriggerState = (0, $9Xvoh$useOverlayTriggerState)(props);
28
- let [focusStrategy, setFocusStrategy] = (0, $9Xvoh$useState)(null);
29
- let [expandedKeysStack, setExpandedKeysStack] = (0, $9Xvoh$useState)([]);
30
- let closeAll = ()=>{
31
- setExpandedKeysStack([]);
32
- overlayTriggerState.close();
33
- };
34
- let openSubmenu = (triggerKey, level)=>{
35
- setExpandedKeysStack((oldStack)=>{
36
- if (level > oldStack.length) return oldStack;
37
- return [
38
- ...oldStack.slice(0, level),
39
- triggerKey
40
- ];
41
- });
42
- };
43
- let closeSubmenu = (triggerKey, level)=>{
44
- setExpandedKeysStack((oldStack)=>{
45
- let key = oldStack[level];
46
- if (key === triggerKey) return oldStack.slice(0, level);
47
- else return oldStack;
48
- });
49
- };
50
- return {
51
- focusStrategy: focusStrategy,
52
- ...overlayTriggerState,
53
- open (focusStrategy = null) {
54
- setFocusStrategy(focusStrategy);
55
- overlayTriggerState.open();
56
- },
57
- toggle (focusStrategy = null) {
58
- setFocusStrategy(focusStrategy);
59
- overlayTriggerState.toggle();
60
- },
61
- close () {
62
- closeAll();
63
- },
64
- UNSTABLE_expandedKeysStack: expandedKeysStack,
65
- UNSTABLE_openSubmenu: openSubmenu,
66
- UNSTABLE_closeSubmenu: closeSubmenu
67
- };
68
- }
69
-
70
-
71
- /*
72
- * Copyright 2023 Adobe. All rights reserved.
73
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
74
- * you may not use this file except in compliance with the License. You may obtain a copy
75
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
76
- *
77
- * Unless required by applicable law or agreed to in writing, software distributed under
78
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
79
- * OF ANY KIND, either express or implied. See the License for the specific language
80
- * governing permissions and limitations under the License.
81
- */
82
- function $e5614764aa47eb35$export$d39fdbfa42246ac4(props, state) {
83
- let { triggerKey: triggerKey } = props;
84
- let { UNSTABLE_expandedKeysStack: UNSTABLE_expandedKeysStack, UNSTABLE_openSubmenu: UNSTABLE_openSubmenu, UNSTABLE_closeSubmenu: UNSTABLE_closeSubmenu, close: closeAll } = state;
85
- let [submenuLevel] = (0, $9Xvoh$useState)(UNSTABLE_expandedKeysStack === null || UNSTABLE_expandedKeysStack === void 0 ? void 0 : UNSTABLE_expandedKeysStack.length);
86
- let isOpen = (0, $9Xvoh$useMemo)(()=>UNSTABLE_expandedKeysStack[submenuLevel] === triggerKey, [
87
- UNSTABLE_expandedKeysStack,
88
- triggerKey,
89
- submenuLevel
90
- ]);
91
- let [focusStrategy, setFocusStrategy] = (0, $9Xvoh$useState)(null);
92
- let open = (0, $9Xvoh$useCallback)((focusStrategy = null)=>{
93
- setFocusStrategy(focusStrategy);
94
- UNSTABLE_openSubmenu(triggerKey, submenuLevel);
95
- }, [
96
- UNSTABLE_openSubmenu,
97
- submenuLevel,
98
- triggerKey
99
- ]);
100
- let close = (0, $9Xvoh$useCallback)(()=>{
101
- setFocusStrategy(null);
102
- UNSTABLE_closeSubmenu(triggerKey, submenuLevel);
103
- }, [
104
- UNSTABLE_closeSubmenu,
105
- submenuLevel,
106
- triggerKey
107
- ]);
108
- let toggle = (0, $9Xvoh$useCallback)((focusStrategy = null)=>{
109
- setFocusStrategy(focusStrategy);
110
- if (isOpen) close();
111
- else open(focusStrategy);
112
- }, [
113
- close,
114
- open,
115
- isOpen
116
- ]);
117
- return (0, $9Xvoh$useMemo)(()=>({
118
- focusStrategy: focusStrategy,
119
- isOpen: isOpen,
120
- open: open,
121
- close: close,
122
- closeAll: closeAll,
123
- submenuLevel: submenuLevel,
124
- // 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
125
- // https://github.com/adobe/react-spectrum/pull/4976#discussion_r1336472863
126
- setOpen: ()=>{},
127
- toggle: toggle
128
- }), [
129
- isOpen,
130
- open,
131
- close,
132
- closeAll,
133
- focusStrategy,
134
- toggle,
135
- submenuLevel
136
- ]);
137
- }
138
-
139
-
140
16
 
141
17
 
142
18
  export {$a28c903ee9ad8dc5$export$79fefeb1c2091ac3 as useMenuTriggerState, $e5614764aa47eb35$export$d39fdbfa42246ac4 as UNSTABLE_useSubmenuTriggerState};
package/dist/main.js CHANGED
@@ -1,24 +1,14 @@
1
- var $cAWze$reactstatelyoverlays = require("@react-stately/overlays");
2
- var $cAWze$react = require("react");
1
+ var $f39cdb649cd48930$exports = require("./useMenuTriggerState.main.js");
2
+ var $38ab7fb105c54ad2$exports = require("./useSubmenuTriggerState.main.js");
3
3
 
4
4
 
5
5
  function $parcel$export(e, n, v, s) {
6
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
7
  }
8
8
 
9
- $parcel$export(module.exports, "useMenuTriggerState", () => $f39cdb649cd48930$export$79fefeb1c2091ac3);
10
- $parcel$export(module.exports, "UNSTABLE_useSubmenuTriggerState", () => $38ab7fb105c54ad2$export$d39fdbfa42246ac4);
9
+ $parcel$export(module.exports, "useMenuTriggerState", () => $f39cdb649cd48930$exports.useMenuTriggerState);
10
+ $parcel$export(module.exports, "UNSTABLE_useSubmenuTriggerState", () => $38ab7fb105c54ad2$exports.UNSTABLE_useSubmenuTriggerState);
11
11
  /*
12
- * Copyright 2020 Adobe. All rights reserved.
13
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License. You may obtain a copy
15
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software distributed under
18
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
- * OF ANY KIND, either express or implied. See the License for the specific language
20
- * governing permissions and limitations under the License.
21
- */ /*
22
12
  * Copyright 2020 Adobe. All rights reserved.
23
13
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
24
14
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -30,120 +20,6 @@ $parcel$export(module.exports, "UNSTABLE_useSubmenuTriggerState", () => $38ab7fb
30
20
  * governing permissions and limitations under the License.
31
21
  */
32
22
 
33
- function $f39cdb649cd48930$export$79fefeb1c2091ac3(props) {
34
- let overlayTriggerState = (0, $cAWze$reactstatelyoverlays.useOverlayTriggerState)(props);
35
- let [focusStrategy, setFocusStrategy] = (0, $cAWze$react.useState)(null);
36
- let [expandedKeysStack, setExpandedKeysStack] = (0, $cAWze$react.useState)([]);
37
- let closeAll = ()=>{
38
- setExpandedKeysStack([]);
39
- overlayTriggerState.close();
40
- };
41
- let openSubmenu = (triggerKey, level)=>{
42
- setExpandedKeysStack((oldStack)=>{
43
- if (level > oldStack.length) return oldStack;
44
- return [
45
- ...oldStack.slice(0, level),
46
- triggerKey
47
- ];
48
- });
49
- };
50
- let closeSubmenu = (triggerKey, level)=>{
51
- setExpandedKeysStack((oldStack)=>{
52
- let key = oldStack[level];
53
- if (key === triggerKey) return oldStack.slice(0, level);
54
- else return oldStack;
55
- });
56
- };
57
- return {
58
- focusStrategy: focusStrategy,
59
- ...overlayTriggerState,
60
- open (focusStrategy = null) {
61
- setFocusStrategy(focusStrategy);
62
- overlayTriggerState.open();
63
- },
64
- toggle (focusStrategy = null) {
65
- setFocusStrategy(focusStrategy);
66
- overlayTriggerState.toggle();
67
- },
68
- close () {
69
- closeAll();
70
- },
71
- UNSTABLE_expandedKeysStack: expandedKeysStack,
72
- UNSTABLE_openSubmenu: openSubmenu,
73
- UNSTABLE_closeSubmenu: closeSubmenu
74
- };
75
- }
76
-
77
-
78
- /*
79
- * Copyright 2023 Adobe. All rights reserved.
80
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
81
- * you may not use this file except in compliance with the License. You may obtain a copy
82
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
83
- *
84
- * Unless required by applicable law or agreed to in writing, software distributed under
85
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
86
- * OF ANY KIND, either express or implied. See the License for the specific language
87
- * governing permissions and limitations under the License.
88
- */
89
- function $38ab7fb105c54ad2$export$d39fdbfa42246ac4(props, state) {
90
- let { triggerKey: triggerKey } = props;
91
- let { UNSTABLE_expandedKeysStack: UNSTABLE_expandedKeysStack, UNSTABLE_openSubmenu: UNSTABLE_openSubmenu, UNSTABLE_closeSubmenu: UNSTABLE_closeSubmenu, close: closeAll } = state;
92
- let [submenuLevel] = (0, $cAWze$react.useState)(UNSTABLE_expandedKeysStack === null || UNSTABLE_expandedKeysStack === void 0 ? void 0 : UNSTABLE_expandedKeysStack.length);
93
- let isOpen = (0, $cAWze$react.useMemo)(()=>UNSTABLE_expandedKeysStack[submenuLevel] === triggerKey, [
94
- UNSTABLE_expandedKeysStack,
95
- triggerKey,
96
- submenuLevel
97
- ]);
98
- let [focusStrategy, setFocusStrategy] = (0, $cAWze$react.useState)(null);
99
- let open = (0, $cAWze$react.useCallback)((focusStrategy = null)=>{
100
- setFocusStrategy(focusStrategy);
101
- UNSTABLE_openSubmenu(triggerKey, submenuLevel);
102
- }, [
103
- UNSTABLE_openSubmenu,
104
- submenuLevel,
105
- triggerKey
106
- ]);
107
- let close = (0, $cAWze$react.useCallback)(()=>{
108
- setFocusStrategy(null);
109
- UNSTABLE_closeSubmenu(triggerKey, submenuLevel);
110
- }, [
111
- UNSTABLE_closeSubmenu,
112
- submenuLevel,
113
- triggerKey
114
- ]);
115
- let toggle = (0, $cAWze$react.useCallback)((focusStrategy = null)=>{
116
- setFocusStrategy(focusStrategy);
117
- if (isOpen) close();
118
- else open(focusStrategy);
119
- }, [
120
- close,
121
- open,
122
- isOpen
123
- ]);
124
- return (0, $cAWze$react.useMemo)(()=>({
125
- focusStrategy: focusStrategy,
126
- isOpen: isOpen,
127
- open: open,
128
- close: close,
129
- closeAll: closeAll,
130
- submenuLevel: submenuLevel,
131
- // 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
132
- // https://github.com/adobe/react-spectrum/pull/4976#discussion_r1336472863
133
- setOpen: ()=>{},
134
- toggle: toggle
135
- }), [
136
- isOpen,
137
- open,
138
- close,
139
- closeAll,
140
- focusStrategy,
141
- toggle,
142
- submenuLevel
143
- ]);
144
- }
145
-
146
-
147
23
 
148
24
 
149
25
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
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,iBAAiB;YACjB,oBAAoB,MAAM;QAC5B;QACA;YACE;QACF;QACA,4BAA4B;QAC5B,sBAAsB;QACtB,uBAAuB;IACzB;AACF;;CDxFC;AEVD;;;;;;;;;;CAUC;AAmCM,SAAS,0CAAgC,KAA0B,EAAE,KAA2B;IACrG,IAAI,cAAC,UAAU,EAAC,GAAG;IACnB,IAAI,8BAAC,0BAA0B,wBAAE,oBAAoB,yBAAE,qBAAqB,EAAE,OAAO,QAAQ,EAAC,GAAG;IACjG,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE,uCAAA,iDAAA,2BAA4B,MAAM;IAChE,IAAI,SAAS,CAAA,GAAA,oBAAM,EAAE,IAAM,0BAA0B,CAAC,aAAa,KAAK,YAAY;QAAC;QAA4B;QAAY;KAAa;IAC1I,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAiB;IAEhE,IAAI,OAAO,CAAA,GAAA,wBAAU,EAAE,CAAC,gBAA+B,IAAI;QACzD,iBAAiB;QACjB,qBAAqB,YAAY;IACnC,GAAG;QAAC;QAAsB;QAAc;KAAW;IAEnD,IAAI,QAAQ,CAAA,GAAA,wBAAU,EAAE;QACtB,iBAAiB;QACjB,sBAAsB,YAAY;IACpC,GAAG;QAAC;QAAuB;QAAc;KAAW;IAEpD,IAAI,SAAS,CAAA,GAAA,wBAAU,EAAE,CAAC,gBAA+B,IAAI;QAC3D,iBAAiB;QACjB,IAAI,QACF;aAEA,KAAK;IAET,GAAG;QAAC;QAAO;QAAM;KAAO;IAExB,OAAO,CAAA,GAAA,oBAAM,EAAE,IAAO,CAAA;2BACpB;oBACA;kBACA;mBACA;sBACA;0BACA;YACA,mJAAmJ;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":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/menu/src/index.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"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,17 +1,7 @@
1
- import {useOverlayTriggerState as $9Xvoh$useOverlayTriggerState} from "@react-stately/overlays";
2
- import {useState as $9Xvoh$useState, useMemo as $9Xvoh$useMemo, useCallback as $9Xvoh$useCallback} from "react";
1
+ import {useMenuTriggerState as $a28c903ee9ad8dc5$export$79fefeb1c2091ac3} from "./useMenuTriggerState.module.js";
2
+ import {UNSTABLE_useSubmenuTriggerState as $e5614764aa47eb35$export$d39fdbfa42246ac4} from "./useSubmenuTriggerState.module.js";
3
3
 
4
4
  /*
5
- * Copyright 2020 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */ /*
15
5
  * Copyright 2020 Adobe. All rights reserved.
16
6
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
17
7
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -23,120 +13,6 @@ import {useState as $9Xvoh$useState, useMemo as $9Xvoh$useMemo, useCallback as $
23
13
  * governing permissions and limitations under the License.
24
14
  */
25
15
 
26
- function $a28c903ee9ad8dc5$export$79fefeb1c2091ac3(props) {
27
- let overlayTriggerState = (0, $9Xvoh$useOverlayTriggerState)(props);
28
- let [focusStrategy, setFocusStrategy] = (0, $9Xvoh$useState)(null);
29
- let [expandedKeysStack, setExpandedKeysStack] = (0, $9Xvoh$useState)([]);
30
- let closeAll = ()=>{
31
- setExpandedKeysStack([]);
32
- overlayTriggerState.close();
33
- };
34
- let openSubmenu = (triggerKey, level)=>{
35
- setExpandedKeysStack((oldStack)=>{
36
- if (level > oldStack.length) return oldStack;
37
- return [
38
- ...oldStack.slice(0, level),
39
- triggerKey
40
- ];
41
- });
42
- };
43
- let closeSubmenu = (triggerKey, level)=>{
44
- setExpandedKeysStack((oldStack)=>{
45
- let key = oldStack[level];
46
- if (key === triggerKey) return oldStack.slice(0, level);
47
- else return oldStack;
48
- });
49
- };
50
- return {
51
- focusStrategy: focusStrategy,
52
- ...overlayTriggerState,
53
- open (focusStrategy = null) {
54
- setFocusStrategy(focusStrategy);
55
- overlayTriggerState.open();
56
- },
57
- toggle (focusStrategy = null) {
58
- setFocusStrategy(focusStrategy);
59
- overlayTriggerState.toggle();
60
- },
61
- close () {
62
- closeAll();
63
- },
64
- UNSTABLE_expandedKeysStack: expandedKeysStack,
65
- UNSTABLE_openSubmenu: openSubmenu,
66
- UNSTABLE_closeSubmenu: closeSubmenu
67
- };
68
- }
69
-
70
-
71
- /*
72
- * Copyright 2023 Adobe. All rights reserved.
73
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
74
- * you may not use this file except in compliance with the License. You may obtain a copy
75
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
76
- *
77
- * Unless required by applicable law or agreed to in writing, software distributed under
78
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
79
- * OF ANY KIND, either express or implied. See the License for the specific language
80
- * governing permissions and limitations under the License.
81
- */
82
- function $e5614764aa47eb35$export$d39fdbfa42246ac4(props, state) {
83
- let { triggerKey: triggerKey } = props;
84
- let { UNSTABLE_expandedKeysStack: UNSTABLE_expandedKeysStack, UNSTABLE_openSubmenu: UNSTABLE_openSubmenu, UNSTABLE_closeSubmenu: UNSTABLE_closeSubmenu, close: closeAll } = state;
85
- let [submenuLevel] = (0, $9Xvoh$useState)(UNSTABLE_expandedKeysStack === null || UNSTABLE_expandedKeysStack === void 0 ? void 0 : UNSTABLE_expandedKeysStack.length);
86
- let isOpen = (0, $9Xvoh$useMemo)(()=>UNSTABLE_expandedKeysStack[submenuLevel] === triggerKey, [
87
- UNSTABLE_expandedKeysStack,
88
- triggerKey,
89
- submenuLevel
90
- ]);
91
- let [focusStrategy, setFocusStrategy] = (0, $9Xvoh$useState)(null);
92
- let open = (0, $9Xvoh$useCallback)((focusStrategy = null)=>{
93
- setFocusStrategy(focusStrategy);
94
- UNSTABLE_openSubmenu(triggerKey, submenuLevel);
95
- }, [
96
- UNSTABLE_openSubmenu,
97
- submenuLevel,
98
- triggerKey
99
- ]);
100
- let close = (0, $9Xvoh$useCallback)(()=>{
101
- setFocusStrategy(null);
102
- UNSTABLE_closeSubmenu(triggerKey, submenuLevel);
103
- }, [
104
- UNSTABLE_closeSubmenu,
105
- submenuLevel,
106
- triggerKey
107
- ]);
108
- let toggle = (0, $9Xvoh$useCallback)((focusStrategy = null)=>{
109
- setFocusStrategy(focusStrategy);
110
- if (isOpen) close();
111
- else open(focusStrategy);
112
- }, [
113
- close,
114
- open,
115
- isOpen
116
- ]);
117
- return (0, $9Xvoh$useMemo)(()=>({
118
- focusStrategy: focusStrategy,
119
- isOpen: isOpen,
120
- open: open,
121
- close: close,
122
- closeAll: closeAll,
123
- submenuLevel: submenuLevel,
124
- // 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
125
- // https://github.com/adobe/react-spectrum/pull/4976#discussion_r1336472863
126
- setOpen: ()=>{},
127
- toggle: toggle
128
- }), [
129
- isOpen,
130
- open,
131
- close,
132
- closeAll,
133
- focusStrategy,
134
- toggle,
135
- submenuLevel
136
- ]);
137
- }
138
-
139
-
140
16
 
141
17
 
142
18
  export {$a28c903ee9ad8dc5$export$79fefeb1c2091ac3 as useMenuTriggerState, $e5614764aa47eb35$export$d39fdbfa42246ac4 as UNSTABLE_useSubmenuTriggerState};
@@ -1 +1 @@
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,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,iBAAiB;YACjB,oBAAoB,MAAM;QAC5B;QACA;YACE;QACF;QACA,4BAA4B;QAC5B,sBAAsB;QACtB,uBAAuB;IACzB;AACF;;CDxFC;AEVD;;;;;;;;;;CAUC;AAmCM,SAAS,0CAAgC,KAA0B,EAAE,KAA2B;IACrG,IAAI,cAAC,UAAU,EAAC,GAAG;IACnB,IAAI,8BAAC,0BAA0B,wBAAE,oBAAoB,yBAAE,qBAAqB,EAAE,OAAO,QAAQ,EAAC,GAAG;IACjG,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE,uCAAA,iDAAA,2BAA4B,MAAM;IAChE,IAAI,SAAS,CAAA,GAAA,cAAM,EAAE,IAAM,0BAA0B,CAAC,aAAa,KAAK,YAAY;QAAC;QAA4B;QAAY;KAAa;IAC1I,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAEhE,IAAI,OAAO,CAAA,GAAA,kBAAU,EAAE,CAAC,gBAA+B,IAAI;QACzD,iBAAiB;QACjB,qBAAqB,YAAY;IACnC,GAAG;QAAC;QAAsB;QAAc;KAAW;IAEnD,IAAI,QAAQ,CAAA,GAAA,kBAAU,EAAE;QACtB,iBAAiB;QACjB,sBAAsB,YAAY;IACpC,GAAG;QAAC;QAAuB;QAAc;KAAW;IAEpD,IAAI,SAAS,CAAA,GAAA,kBAAU,EAAE,CAAC,gBAA+B,IAAI;QAC3D,iBAAiB;QACjB,IAAI,QACF;aAEA,KAAK;IAET,GAAG;QAAC;QAAO;QAAM;KAAO;IAExB,OAAO,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;2BACpB;oBACA;kBACA;mBACA;sBACA;0BACA;YACA,mJAAmJ;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"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/menu/src/index.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"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,67 @@
1
+ var $7hdEs$reactstatelyoverlays = require("@react-stately/overlays");
2
+ var $7hdEs$react = require("react");
3
+
4
+
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
+ }
8
+
9
+ $parcel$export(module.exports, "useMenuTriggerState", () => $f39cdb649cd48930$export$79fefeb1c2091ac3);
10
+ /*
11
+ * Copyright 2020 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+ function $f39cdb649cd48930$export$79fefeb1c2091ac3(props) {
23
+ let overlayTriggerState = (0, $7hdEs$reactstatelyoverlays.useOverlayTriggerState)(props);
24
+ let [focusStrategy, setFocusStrategy] = (0, $7hdEs$react.useState)(null);
25
+ let [expandedKeysStack, setExpandedKeysStack] = (0, $7hdEs$react.useState)([]);
26
+ let closeAll = ()=>{
27
+ setExpandedKeysStack([]);
28
+ overlayTriggerState.close();
29
+ };
30
+ let openSubmenu = (triggerKey, level)=>{
31
+ setExpandedKeysStack((oldStack)=>{
32
+ if (level > oldStack.length) return oldStack;
33
+ return [
34
+ ...oldStack.slice(0, level),
35
+ triggerKey
36
+ ];
37
+ });
38
+ };
39
+ let closeSubmenu = (triggerKey, level)=>{
40
+ setExpandedKeysStack((oldStack)=>{
41
+ let key = oldStack[level];
42
+ if (key === triggerKey) return oldStack.slice(0, level);
43
+ else return oldStack;
44
+ });
45
+ };
46
+ return {
47
+ focusStrategy: focusStrategy,
48
+ ...overlayTriggerState,
49
+ open (focusStrategy = null) {
50
+ setFocusStrategy(focusStrategy);
51
+ overlayTriggerState.open();
52
+ },
53
+ toggle (focusStrategy = null) {
54
+ setFocusStrategy(focusStrategy);
55
+ overlayTriggerState.toggle();
56
+ },
57
+ close () {
58
+ closeAll();
59
+ },
60
+ UNSTABLE_expandedKeysStack: expandedKeysStack,
61
+ UNSTABLE_openSubmenu: openSubmenu,
62
+ UNSTABLE_closeSubmenu: closeSubmenu
63
+ };
64
+ }
65
+
66
+
67
+ //# sourceMappingURL=useMenuTriggerState.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;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,iBAAiB;YACjB,oBAAoB,MAAM;QAC5B;QACA;YACE;QACF;QACA,4BAA4B;QAC5B,sBAAsB;QACtB,uBAAuB;IACzB;AACF","sources":["packages/@react-stately/menu/src/useMenuTriggerState.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\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"],"names":[],"version":3,"file":"useMenuTriggerState.main.js.map"}
@@ -0,0 +1,62 @@
1
+ import {useOverlayTriggerState as $8bn9m$useOverlayTriggerState} from "@react-stately/overlays";
2
+ import {useState as $8bn9m$useState} from "react";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ function $a28c903ee9ad8dc5$export$79fefeb1c2091ac3(props) {
17
+ let overlayTriggerState = (0, $8bn9m$useOverlayTriggerState)(props);
18
+ let [focusStrategy, setFocusStrategy] = (0, $8bn9m$useState)(null);
19
+ let [expandedKeysStack, setExpandedKeysStack] = (0, $8bn9m$useState)([]);
20
+ let closeAll = ()=>{
21
+ setExpandedKeysStack([]);
22
+ overlayTriggerState.close();
23
+ };
24
+ let openSubmenu = (triggerKey, level)=>{
25
+ setExpandedKeysStack((oldStack)=>{
26
+ if (level > oldStack.length) return oldStack;
27
+ return [
28
+ ...oldStack.slice(0, level),
29
+ triggerKey
30
+ ];
31
+ });
32
+ };
33
+ let closeSubmenu = (triggerKey, level)=>{
34
+ setExpandedKeysStack((oldStack)=>{
35
+ let key = oldStack[level];
36
+ if (key === triggerKey) return oldStack.slice(0, level);
37
+ else return oldStack;
38
+ });
39
+ };
40
+ return {
41
+ focusStrategy: focusStrategy,
42
+ ...overlayTriggerState,
43
+ open (focusStrategy = null) {
44
+ setFocusStrategy(focusStrategy);
45
+ overlayTriggerState.open();
46
+ },
47
+ toggle (focusStrategy = null) {
48
+ setFocusStrategy(focusStrategy);
49
+ overlayTriggerState.toggle();
50
+ },
51
+ close () {
52
+ closeAll();
53
+ },
54
+ UNSTABLE_expandedKeysStack: expandedKeysStack,
55
+ UNSTABLE_openSubmenu: openSubmenu,
56
+ UNSTABLE_closeSubmenu: closeSubmenu
57
+ };
58
+ }
59
+
60
+
61
+ export {$a28c903ee9ad8dc5$export$79fefeb1c2091ac3 as useMenuTriggerState};
62
+ //# sourceMappingURL=useMenuTriggerState.mjs.map
@@ -0,0 +1,62 @@
1
+ import {useOverlayTriggerState as $8bn9m$useOverlayTriggerState} from "@react-stately/overlays";
2
+ import {useState as $8bn9m$useState} from "react";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ function $a28c903ee9ad8dc5$export$79fefeb1c2091ac3(props) {
17
+ let overlayTriggerState = (0, $8bn9m$useOverlayTriggerState)(props);
18
+ let [focusStrategy, setFocusStrategy] = (0, $8bn9m$useState)(null);
19
+ let [expandedKeysStack, setExpandedKeysStack] = (0, $8bn9m$useState)([]);
20
+ let closeAll = ()=>{
21
+ setExpandedKeysStack([]);
22
+ overlayTriggerState.close();
23
+ };
24
+ let openSubmenu = (triggerKey, level)=>{
25
+ setExpandedKeysStack((oldStack)=>{
26
+ if (level > oldStack.length) return oldStack;
27
+ return [
28
+ ...oldStack.slice(0, level),
29
+ triggerKey
30
+ ];
31
+ });
32
+ };
33
+ let closeSubmenu = (triggerKey, level)=>{
34
+ setExpandedKeysStack((oldStack)=>{
35
+ let key = oldStack[level];
36
+ if (key === triggerKey) return oldStack.slice(0, level);
37
+ else return oldStack;
38
+ });
39
+ };
40
+ return {
41
+ focusStrategy: focusStrategy,
42
+ ...overlayTriggerState,
43
+ open (focusStrategy = null) {
44
+ setFocusStrategy(focusStrategy);
45
+ overlayTriggerState.open();
46
+ },
47
+ toggle (focusStrategy = null) {
48
+ setFocusStrategy(focusStrategy);
49
+ overlayTriggerState.toggle();
50
+ },
51
+ close () {
52
+ closeAll();
53
+ },
54
+ UNSTABLE_expandedKeysStack: expandedKeysStack,
55
+ UNSTABLE_openSubmenu: openSubmenu,
56
+ UNSTABLE_closeSubmenu: closeSubmenu
57
+ };
58
+ }
59
+
60
+
61
+ export {$a28c903ee9ad8dc5$export$79fefeb1c2091ac3 as useMenuTriggerState};
62
+ //# sourceMappingURL=useMenuTriggerState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;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,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,iBAAiB;YACjB,oBAAoB,MAAM;QAC5B;QACA;YACE;QACF;QACA,4BAA4B;QAC5B,sBAAsB;QACtB,uBAAuB;IACzB;AACF","sources":["packages/@react-stately/menu/src/useMenuTriggerState.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\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"],"names":[],"version":3,"file":"useMenuTriggerState.module.js.map"}
@@ -0,0 +1,78 @@
1
+ var $9cbje$react = require("react");
2
+
3
+
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ $parcel$export(module.exports, "UNSTABLE_useSubmenuTriggerState", () => $38ab7fb105c54ad2$export$d39fdbfa42246ac4);
9
+ /*
10
+ * Copyright 2023 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+ function $38ab7fb105c54ad2$export$d39fdbfa42246ac4(props, state) {
21
+ let { triggerKey: triggerKey } = props;
22
+ let { UNSTABLE_expandedKeysStack: UNSTABLE_expandedKeysStack, UNSTABLE_openSubmenu: UNSTABLE_openSubmenu, UNSTABLE_closeSubmenu: UNSTABLE_closeSubmenu, close: closeAll } = state;
23
+ let [submenuLevel] = (0, $9cbje$react.useState)(UNSTABLE_expandedKeysStack === null || UNSTABLE_expandedKeysStack === void 0 ? void 0 : UNSTABLE_expandedKeysStack.length);
24
+ let isOpen = (0, $9cbje$react.useMemo)(()=>UNSTABLE_expandedKeysStack[submenuLevel] === triggerKey, [
25
+ UNSTABLE_expandedKeysStack,
26
+ triggerKey,
27
+ submenuLevel
28
+ ]);
29
+ let [focusStrategy, setFocusStrategy] = (0, $9cbje$react.useState)(null);
30
+ let open = (0, $9cbje$react.useCallback)((focusStrategy = null)=>{
31
+ setFocusStrategy(focusStrategy);
32
+ UNSTABLE_openSubmenu(triggerKey, submenuLevel);
33
+ }, [
34
+ UNSTABLE_openSubmenu,
35
+ submenuLevel,
36
+ triggerKey
37
+ ]);
38
+ let close = (0, $9cbje$react.useCallback)(()=>{
39
+ setFocusStrategy(null);
40
+ UNSTABLE_closeSubmenu(triggerKey, submenuLevel);
41
+ }, [
42
+ UNSTABLE_closeSubmenu,
43
+ submenuLevel,
44
+ triggerKey
45
+ ]);
46
+ let toggle = (0, $9cbje$react.useCallback)((focusStrategy = null)=>{
47
+ setFocusStrategy(focusStrategy);
48
+ if (isOpen) close();
49
+ else open(focusStrategy);
50
+ }, [
51
+ close,
52
+ open,
53
+ isOpen
54
+ ]);
55
+ return (0, $9cbje$react.useMemo)(()=>({
56
+ focusStrategy: focusStrategy,
57
+ isOpen: isOpen,
58
+ open: open,
59
+ close: close,
60
+ closeAll: closeAll,
61
+ submenuLevel: submenuLevel,
62
+ // 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
63
+ // https://github.com/adobe/react-spectrum/pull/4976#discussion_r1336472863
64
+ setOpen: ()=>{},
65
+ toggle: toggle
66
+ }), [
67
+ isOpen,
68
+ open,
69
+ close,
70
+ closeAll,
71
+ focusStrategy,
72
+ toggle,
73
+ submenuLevel
74
+ ]);
75
+ }
76
+
77
+
78
+ //# sourceMappingURL=useSubmenuTriggerState.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAmCM,SAAS,0CAAgC,KAA0B,EAAE,KAA2B;IACrG,IAAI,cAAC,UAAU,EAAC,GAAG;IACnB,IAAI,8BAAC,0BAA0B,wBAAE,oBAAoB,yBAAE,qBAAqB,EAAE,OAAO,QAAQ,EAAC,GAAG;IACjG,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE,uCAAA,iDAAA,2BAA4B,MAAM;IAChE,IAAI,SAAS,CAAA,GAAA,oBAAM,EAAE,IAAM,0BAA0B,CAAC,aAAa,KAAK,YAAY;QAAC;QAA4B;QAAY;KAAa;IAC1I,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAiB;IAEhE,IAAI,OAAO,CAAA,GAAA,wBAAU,EAAE,CAAC,gBAA+B,IAAI;QACzD,iBAAiB;QACjB,qBAAqB,YAAY;IACnC,GAAG;QAAC;QAAsB;QAAc;KAAW;IAEnD,IAAI,QAAQ,CAAA,GAAA,wBAAU,EAAE;QACtB,iBAAiB;QACjB,sBAAsB,YAAY;IACpC,GAAG;QAAC;QAAuB;QAAc;KAAW;IAEpD,IAAI,SAAS,CAAA,GAAA,wBAAU,EAAE,CAAC,gBAA+B,IAAI;QAC3D,iBAAiB;QACjB,IAAI,QACF;aAEA,KAAK;IAET,GAAG;QAAC;QAAO;QAAM;KAAO;IAExB,OAAO,CAAA,GAAA,oBAAM,EAAE,IAAO,CAAA;2BACpB;oBACA;kBACA;mBACA;sBACA;0BACA;YACA,mJAAmJ;YACnJ,2EAA2E;YAC3E,SAAS,KAAO;oBAChB;QACF,CAAA,GAAI;QAAC;QAAQ;QAAM;QAAO;QAAU;QAAe;QAAQ;KAAa;AAC1E","sources":["packages/@react-stately/menu/src/useSubmenuTriggerState.ts"],"sourcesContent":["/*\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":"useSubmenuTriggerState.main.js.map"}
@@ -0,0 +1,73 @@
1
+ import {useState as $7exkJ$useState, useMemo as $7exkJ$useMemo, useCallback as $7exkJ$useCallback} from "react";
2
+
3
+ /*
4
+ * Copyright 2023 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ function $e5614764aa47eb35$export$d39fdbfa42246ac4(props, state) {
15
+ let { triggerKey: triggerKey } = props;
16
+ let { UNSTABLE_expandedKeysStack: UNSTABLE_expandedKeysStack, UNSTABLE_openSubmenu: UNSTABLE_openSubmenu, UNSTABLE_closeSubmenu: UNSTABLE_closeSubmenu, close: closeAll } = state;
17
+ let [submenuLevel] = (0, $7exkJ$useState)(UNSTABLE_expandedKeysStack === null || UNSTABLE_expandedKeysStack === void 0 ? void 0 : UNSTABLE_expandedKeysStack.length);
18
+ let isOpen = (0, $7exkJ$useMemo)(()=>UNSTABLE_expandedKeysStack[submenuLevel] === triggerKey, [
19
+ UNSTABLE_expandedKeysStack,
20
+ triggerKey,
21
+ submenuLevel
22
+ ]);
23
+ let [focusStrategy, setFocusStrategy] = (0, $7exkJ$useState)(null);
24
+ let open = (0, $7exkJ$useCallback)((focusStrategy = null)=>{
25
+ setFocusStrategy(focusStrategy);
26
+ UNSTABLE_openSubmenu(triggerKey, submenuLevel);
27
+ }, [
28
+ UNSTABLE_openSubmenu,
29
+ submenuLevel,
30
+ triggerKey
31
+ ]);
32
+ let close = (0, $7exkJ$useCallback)(()=>{
33
+ setFocusStrategy(null);
34
+ UNSTABLE_closeSubmenu(triggerKey, submenuLevel);
35
+ }, [
36
+ UNSTABLE_closeSubmenu,
37
+ submenuLevel,
38
+ triggerKey
39
+ ]);
40
+ let toggle = (0, $7exkJ$useCallback)((focusStrategy = null)=>{
41
+ setFocusStrategy(focusStrategy);
42
+ if (isOpen) close();
43
+ else open(focusStrategy);
44
+ }, [
45
+ close,
46
+ open,
47
+ isOpen
48
+ ]);
49
+ return (0, $7exkJ$useMemo)(()=>({
50
+ focusStrategy: focusStrategy,
51
+ isOpen: isOpen,
52
+ open: open,
53
+ close: close,
54
+ closeAll: closeAll,
55
+ submenuLevel: submenuLevel,
56
+ // 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
57
+ // https://github.com/adobe/react-spectrum/pull/4976#discussion_r1336472863
58
+ setOpen: ()=>{},
59
+ toggle: toggle
60
+ }), [
61
+ isOpen,
62
+ open,
63
+ close,
64
+ closeAll,
65
+ focusStrategy,
66
+ toggle,
67
+ submenuLevel
68
+ ]);
69
+ }
70
+
71
+
72
+ export {$e5614764aa47eb35$export$d39fdbfa42246ac4 as UNSTABLE_useSubmenuTriggerState};
73
+ //# sourceMappingURL=useSubmenuTriggerState.mjs.map
@@ -0,0 +1,73 @@
1
+ import {useState as $7exkJ$useState, useMemo as $7exkJ$useMemo, useCallback as $7exkJ$useCallback} from "react";
2
+
3
+ /*
4
+ * Copyright 2023 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ function $e5614764aa47eb35$export$d39fdbfa42246ac4(props, state) {
15
+ let { triggerKey: triggerKey } = props;
16
+ let { UNSTABLE_expandedKeysStack: UNSTABLE_expandedKeysStack, UNSTABLE_openSubmenu: UNSTABLE_openSubmenu, UNSTABLE_closeSubmenu: UNSTABLE_closeSubmenu, close: closeAll } = state;
17
+ let [submenuLevel] = (0, $7exkJ$useState)(UNSTABLE_expandedKeysStack === null || UNSTABLE_expandedKeysStack === void 0 ? void 0 : UNSTABLE_expandedKeysStack.length);
18
+ let isOpen = (0, $7exkJ$useMemo)(()=>UNSTABLE_expandedKeysStack[submenuLevel] === triggerKey, [
19
+ UNSTABLE_expandedKeysStack,
20
+ triggerKey,
21
+ submenuLevel
22
+ ]);
23
+ let [focusStrategy, setFocusStrategy] = (0, $7exkJ$useState)(null);
24
+ let open = (0, $7exkJ$useCallback)((focusStrategy = null)=>{
25
+ setFocusStrategy(focusStrategy);
26
+ UNSTABLE_openSubmenu(triggerKey, submenuLevel);
27
+ }, [
28
+ UNSTABLE_openSubmenu,
29
+ submenuLevel,
30
+ triggerKey
31
+ ]);
32
+ let close = (0, $7exkJ$useCallback)(()=>{
33
+ setFocusStrategy(null);
34
+ UNSTABLE_closeSubmenu(triggerKey, submenuLevel);
35
+ }, [
36
+ UNSTABLE_closeSubmenu,
37
+ submenuLevel,
38
+ triggerKey
39
+ ]);
40
+ let toggle = (0, $7exkJ$useCallback)((focusStrategy = null)=>{
41
+ setFocusStrategy(focusStrategy);
42
+ if (isOpen) close();
43
+ else open(focusStrategy);
44
+ }, [
45
+ close,
46
+ open,
47
+ isOpen
48
+ ]);
49
+ return (0, $7exkJ$useMemo)(()=>({
50
+ focusStrategy: focusStrategy,
51
+ isOpen: isOpen,
52
+ open: open,
53
+ close: close,
54
+ closeAll: closeAll,
55
+ submenuLevel: submenuLevel,
56
+ // 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
57
+ // https://github.com/adobe/react-spectrum/pull/4976#discussion_r1336472863
58
+ setOpen: ()=>{},
59
+ toggle: toggle
60
+ }), [
61
+ isOpen,
62
+ open,
63
+ close,
64
+ closeAll,
65
+ focusStrategy,
66
+ toggle,
67
+ submenuLevel
68
+ ]);
69
+ }
70
+
71
+
72
+ export {$e5614764aa47eb35$export$d39fdbfa42246ac4 as UNSTABLE_useSubmenuTriggerState};
73
+ //# sourceMappingURL=useSubmenuTriggerState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAmCM,SAAS,0CAAgC,KAA0B,EAAE,KAA2B;IACrG,IAAI,cAAC,UAAU,EAAC,GAAG;IACnB,IAAI,8BAAC,0BAA0B,wBAAE,oBAAoB,yBAAE,qBAAqB,EAAE,OAAO,QAAQ,EAAC,GAAG;IACjG,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE,uCAAA,iDAAA,2BAA4B,MAAM;IAChE,IAAI,SAAS,CAAA,GAAA,cAAM,EAAE,IAAM,0BAA0B,CAAC,aAAa,KAAK,YAAY;QAAC;QAA4B;QAAY;KAAa;IAC1I,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAiB;IAEhE,IAAI,OAAO,CAAA,GAAA,kBAAU,EAAE,CAAC,gBAA+B,IAAI;QACzD,iBAAiB;QACjB,qBAAqB,YAAY;IACnC,GAAG;QAAC;QAAsB;QAAc;KAAW;IAEnD,IAAI,QAAQ,CAAA,GAAA,kBAAU,EAAE;QACtB,iBAAiB;QACjB,sBAAsB,YAAY;IACpC,GAAG;QAAC;QAAuB;QAAc;KAAW;IAEpD,IAAI,SAAS,CAAA,GAAA,kBAAU,EAAE,CAAC,gBAA+B,IAAI;QAC3D,iBAAiB;QACjB,IAAI,QACF;aAEA,KAAK;IAET,GAAG;QAAC;QAAO;QAAM;KAAO;IAExB,OAAO,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;2BACpB;oBACA;kBACA;mBACA;sBACA;0BACA;YACA,mJAAmJ;YACnJ,2EAA2E;YAC3E,SAAS,KAAO;oBAChB;QACF,CAAA,GAAI;QAAC;QAAQ;QAAM;QAAO;QAAU;QAAe;QAAQ;KAAa;AAC1E","sources":["packages/@react-stately/menu/src/useSubmenuTriggerState.ts"],"sourcesContent":["/*\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":"useSubmenuTriggerState.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/menu",
3
- "version": "3.6.2-nightly.4555+81162ea39",
3
+ "version": "3.6.2-nightly.4558+c5e4b3701",
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.6-nightly.4555+81162ea39",
26
- "@react-types/menu": "3.9.8-nightly.4555+81162ea39",
27
- "@react-types/shared": "3.0.0-nightly.2843+81162ea39",
25
+ "@react-stately/overlays": "3.6.6-nightly.4558+c5e4b3701",
26
+ "@react-types/menu": "3.9.8-nightly.4558+c5e4b3701",
27
+ "@react-types/shared": "3.0.0-nightly.2846+c5e4b3701",
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": "81162ea392926d06ec3d25c228e6f9b6b5479d59"
36
+ "gitHead": "c5e4b3701fdb89eb551f1b3697ac253f06ef68fa"
37
37
  }