@react-stately/menu 3.9.10 → 3.10.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/import.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import {useMenuTriggerState as $a28c903ee9ad8dc5$export$79fefeb1c2091ac3} from "./useMenuTriggerState.mjs";
2
- import {useSubmenuTriggerState as $e5614764aa47eb35$export$cfc51cf86138bf98} from "./useSubmenuTriggerState.mjs";
1
+ import {useMenuTriggerState as $31c19150b3b0e967$re_export$useMenuTriggerState, useSubmenuTriggerState as $31c19150b3b0e967$re_export$useSubmenuTriggerState} from "react-stately/useMenuTriggerState";
3
2
 
4
3
  /*
5
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -14,6 +13,5 @@ import {useSubmenuTriggerState as $e5614764aa47eb35$export$cfc51cf86138bf98} fro
14
13
  */
15
14
 
16
15
 
17
-
18
- export {$a28c903ee9ad8dc5$export$79fefeb1c2091ac3 as useMenuTriggerState, $e5614764aa47eb35$export$cfc51cf86138bf98 as useSubmenuTriggerState};
16
+ export {$31c19150b3b0e967$re_export$useMenuTriggerState as useMenuTriggerState, $31c19150b3b0e967$re_export$useSubmenuTriggerState as useSubmenuTriggerState};
19
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,13 +1,12 @@
1
- var $f39cdb649cd48930$exports = require("./useMenuTriggerState.main.js");
2
- var $38ab7fb105c54ad2$exports = require("./useSubmenuTriggerState.main.js");
1
+ var $cIjgT$reactstatelyuseMenuTriggerState = require("react-stately/useMenuTriggerState");
3
2
 
4
3
 
5
4
  function $parcel$export(e, n, v, s) {
6
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
6
  }
8
7
 
9
- $parcel$export(module.exports, "useMenuTriggerState", () => $f39cdb649cd48930$exports.useMenuTriggerState);
10
- $parcel$export(module.exports, "useSubmenuTriggerState", () => $38ab7fb105c54ad2$exports.useSubmenuTriggerState);
8
+ $parcel$export(module.exports, "useMenuTriggerState", function () { return $cIjgT$reactstatelyuseMenuTriggerState.useMenuTriggerState; });
9
+ $parcel$export(module.exports, "useSubmenuTriggerState", function () { return $cIjgT$reactstatelyuseMenuTriggerState.useSubmenuTriggerState; });
11
10
  /*
12
11
  * Copyright 2020 Adobe. All rights reserved.
13
12
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -21,5 +20,4 @@ $parcel$export(module.exports, "useSubmenuTriggerState", () => $38ab7fb105c54ad2
21
20
  */
22
21
 
23
22
 
24
-
25
23
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
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 {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"}
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, useSubmenuTriggerState} from 'react-stately/useMenuTriggerState';\n\nexport type {MenuTriggerProps, MenuTriggerType, MenuTriggerState, RootMenuTriggerState, SubmenuTriggerProps, SubmenuTriggerState} from 'react-stately/useMenuTriggerState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,5 +1,4 @@
1
- import {useMenuTriggerState as $a28c903ee9ad8dc5$export$79fefeb1c2091ac3} from "./useMenuTriggerState.module.js";
2
- import {useSubmenuTriggerState as $e5614764aa47eb35$export$cfc51cf86138bf98} from "./useSubmenuTriggerState.module.js";
1
+ import {useMenuTriggerState as $31c19150b3b0e967$re_export$useMenuTriggerState, useSubmenuTriggerState as $31c19150b3b0e967$re_export$useSubmenuTriggerState} from "react-stately/useMenuTriggerState";
3
2
 
4
3
  /*
5
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -14,6 +13,5 @@ import {useSubmenuTriggerState as $e5614764aa47eb35$export$cfc51cf86138bf98} fro
14
13
  */
15
14
 
16
15
 
17
-
18
- export {$a28c903ee9ad8dc5$export$79fefeb1c2091ac3 as useMenuTriggerState, $e5614764aa47eb35$export$cfc51cf86138bf98 as useSubmenuTriggerState};
16
+ export {$31c19150b3b0e967$re_export$useMenuTriggerState as useMenuTriggerState, $31c19150b3b0e967$re_export$useSubmenuTriggerState as useSubmenuTriggerState};
19
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
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 {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"}
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, useSubmenuTriggerState} from 'react-stately/useMenuTriggerState';\n\nexport type {MenuTriggerProps, MenuTriggerType, MenuTriggerState, RootMenuTriggerState, SubmenuTriggerProps, SubmenuTriggerState} from 'react-stately/useMenuTriggerState';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,2 @@
1
+ export { useMenuTriggerState, useSubmenuTriggerState } from 'react-stately/useMenuTriggerState';
2
+ export type { MenuTriggerProps, MenuTriggerType, MenuTriggerState, RootMenuTriggerState, SubmenuTriggerProps, SubmenuTriggerState } from 'react-stately/useMenuTriggerState';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-stately/menu",
3
- "version": "3.9.10",
3
+ "version": "3.10.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "exports": {
9
- "source": "./src/index.ts",
10
- "types": [
11
- "./dist/types.d.ts",
12
- "./src/index.ts"
13
- ],
14
- "import": "./dist/import.mjs",
15
- "require": "./dist/main.js"
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/import.mjs",
13
+ "require": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
16
  },
17
- "types": "dist/types.d.ts",
17
+ "types": "dist/types/src/index.d.ts",
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "dist",
@@ -26,16 +26,18 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-stately/overlays": "^3.6.22",
30
- "@react-types/menu": "^3.10.6",
31
- "@react-types/shared": "^3.33.0",
32
- "@swc/helpers": "^0.5.0"
29
+ "@swc/helpers": "^0.5.0",
30
+ "react-stately": "3.46.0"
33
31
  },
34
32
  "peerDependencies": {
35
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
33
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
34
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
36
35
  },
37
36
  "publishConfig": {
38
37
  "access": "public"
39
38
  },
40
- "gitHead": "66e51757606b43a89ed02c574ca24517323a2ab9"
39
+ "targets": {
40
+ "types": false
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
41
43
  }
package/src/index.ts CHANGED
@@ -10,9 +10,6 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export {useMenuTriggerState} from './useMenuTriggerState';
14
- export {useSubmenuTriggerState} from './useSubmenuTriggerState';
13
+ export {useMenuTriggerState, useSubmenuTriggerState} from 'react-stately/useMenuTriggerState';
15
14
 
16
- export type {MenuTriggerProps} from '@react-types/menu';
17
- export type {MenuTriggerState, RootMenuTriggerState} from './useMenuTriggerState';
18
- export type {SubmenuTriggerProps, SubmenuTriggerState} from './useSubmenuTriggerState';
15
+ export type {MenuTriggerProps, MenuTriggerType, MenuTriggerState, RootMenuTriggerState, SubmenuTriggerProps, SubmenuTriggerState} from 'react-stately/useMenuTriggerState';
package/dist/types.d.ts DELETED
@@ -1,59 +0,0 @@
1
- import { FocusStrategy, Key } from "@react-types/shared";
2
- import { MenuTriggerProps } from "@react-types/menu";
3
- import { OverlayTriggerState } from "@react-stately/overlays";
4
- export interface MenuTriggerState extends OverlayTriggerState {
5
- /** Controls which item will be auto focused when the menu opens. */
6
- readonly focusStrategy: FocusStrategy | null;
7
- /** Opens the menu. */
8
- open(focusStrategy?: FocusStrategy | null): void;
9
- /** Toggles the menu. */
10
- toggle(focusStrategy?: FocusStrategy | null): void;
11
- }
12
- export interface RootMenuTriggerState extends MenuTriggerState {
13
- /** Opens a specific submenu tied to a specific menu item at a specific level. */
14
- openSubmenu: (triggerKey: Key, level: number) => void;
15
- /** Closes a specific submenu tied to a specific menu item at a specific level. */
16
- closeSubmenu: (triggerKey: Key, level: number) => void;
17
- /** An array of open submenu trigger keys within the menu tree.
18
- * The index of key within array matches the submenu level in the tree.
19
- */
20
- expandedKeysStack: Key[];
21
- /** Closes the menu and all submenus in the menu tree. */
22
- close: () => void;
23
- }
24
- /**
25
- * Manages state for a menu trigger. Tracks whether the menu is currently open,
26
- * and controls which item will receive focus when it opens. Also tracks the open submenus within
27
- * the menu tree via their trigger keys.
28
- */
29
- export function useMenuTriggerState(props: MenuTriggerProps): RootMenuTriggerState;
30
- export interface SubmenuTriggerProps {
31
- /** Key of the trigger item. */
32
- triggerKey: Key;
33
- }
34
- export interface SubmenuTriggerState extends OverlayTriggerState {
35
- /** Whether the submenu is currently open. */
36
- isOpen: boolean;
37
- /** Controls which item will be auto focused when the submenu opens. */
38
- focusStrategy: FocusStrategy | null;
39
- /** Opens the submenu. */
40
- open: (focusStrategy?: FocusStrategy | null) => void;
41
- /** Closes the submenu. */
42
- close: () => void;
43
- /** Closes all menus and submenus in the menu tree. */
44
- closeAll: () => void;
45
- /** The level of the submenu. */
46
- submenuLevel: number;
47
- /** Toggles the submenu. */
48
- toggle: (focusStrategy?: FocusStrategy | null) => void;
49
- /** @private */
50
- setOpen: () => void;
51
- }
52
- /**
53
- * Manages state for a submenu trigger. Tracks whether the submenu is currently open, the level of the submenu, and
54
- * controls which item will receive focus when it opens.
55
- */
56
- export function useSubmenuTriggerState(props: SubmenuTriggerProps, state: RootMenuTriggerState): SubmenuTriggerState;
57
- export type { MenuTriggerProps } from '@react-types/menu';
58
-
59
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AAiBA,iCAAkC,SAAQ,mBAAmB;IAC3D,oEAAoE;IACpE,QAAQ,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAE7C,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,CAAA;CACnD;AAED,qCAAsC,SAAQ,gBAAgB;IAC5D,iFAAiF;IACjF,WAAW,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAEtD,kFAAkF;IAClF,YAAY,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAEvD;;OAEG;IACH,iBAAiB,EAAE,GAAG,EAAE,CAAC;IAEzB,yDAAyD;IACzD,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED;;;;GAIG;AACH,oCAAoC,KAAK,EAAE,gBAAgB,GAAG,oBAAoB,CAiDjF;ACjFD;IACE,+BAA+B;IAC/B,UAAU,EAAE,GAAG,CAAA;CAChB;AAED,oCAAqC,SAAQ,mBAAmB;IAC9D,6CAA6C;IAC7C,MAAM,EAAE,OAAO,CAAC;IAChB,uEAAuE;IACvE,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IACpC,yBAAyB;IACzB,IAAI,EAAE,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,KAAK,IAAI,CAAC;IACrD,0BAA0B;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,gCAAgC;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,MAAM,EAAE,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,KAAK,IAAI,CAAC;IACvD,eAAe;IACf,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED;;;GAGG;AACH,uCAAuC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,oBAAoB,GAAG,mBAAmB,CAsCnH;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 {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"}
@@ -1,67 +0,0 @@
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
- expandedKeysStack: expandedKeysStack,
61
- openSubmenu: openSubmenu,
62
- closeSubmenu: closeSubmenu
63
- };
64
- }
65
-
66
-
67
- //# sourceMappingURL=useMenuTriggerState.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAuCM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,sBAAsB,CAAA,GAAA,kDAAqB,EAAE;IACjD,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAwB;IACvE,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,gBAAsC,IAAI;YAC7C,iBAAiB;YACjB,oBAAoB,IAAI;QAC1B;QACA,QAAO,gBAAsC,IAAI;YAC/C,iBAAiB;YACjB,oBAAoB,MAAM;QAC5B;QACA;YACE;QACF;2BACA;qBACA;sBACA;IACF;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 | null,\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 openSubmenu: (triggerKey: Key, level: number) => void,\n\n /** Closes a specific submenu tied to a specific menu item at a specific level. */\n 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 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>(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 = null) {\n setFocusStrategy(focusStrategy);\n overlayTriggerState.open();\n },\n toggle(focusStrategy: FocusStrategy | null = null) {\n setFocusStrategy(focusStrategy);\n overlayTriggerState.toggle();\n },\n close() {\n closeAll();\n },\n expandedKeysStack,\n openSubmenu,\n closeSubmenu\n };\n}\n"],"names":[],"version":3,"file":"useMenuTriggerState.main.js.map"}
@@ -1,62 +0,0 @@
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
- expandedKeysStack: expandedKeysStack,
55
- openSubmenu: openSubmenu,
56
- closeSubmenu: closeSubmenu
57
- };
58
- }
59
-
60
-
61
- export {$a28c903ee9ad8dc5$export$79fefeb1c2091ac3 as useMenuTriggerState};
62
- //# sourceMappingURL=useMenuTriggerState.module.js.map
@@ -1,62 +0,0 @@
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
- expandedKeysStack: expandedKeysStack,
55
- openSubmenu: openSubmenu,
56
- closeSubmenu: closeSubmenu
57
- };
58
- }
59
-
60
-
61
- export {$a28c903ee9ad8dc5$export$79fefeb1c2091ac3 as useMenuTriggerState};
62
- //# sourceMappingURL=useMenuTriggerState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAuCM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,sBAAsB,CAAA,GAAA,6BAAqB,EAAE;IACjD,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAwB;IACvE,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,gBAAsC,IAAI;YAC7C,iBAAiB;YACjB,oBAAoB,IAAI;QAC1B;QACA,QAAO,gBAAsC,IAAI;YAC/C,iBAAiB;YACjB,oBAAoB,MAAM;QAC5B;QACA;YACE;QACF;2BACA;qBACA;sBACA;IACF;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 | null,\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 openSubmenu: (triggerKey: Key, level: number) => void,\n\n /** Closes a specific submenu tied to a specific menu item at a specific level. */\n 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 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>(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 = null) {\n setFocusStrategy(focusStrategy);\n overlayTriggerState.open();\n },\n toggle(focusStrategy: FocusStrategy | null = null) {\n setFocusStrategy(focusStrategy);\n overlayTriggerState.toggle();\n },\n close() {\n closeAll();\n },\n expandedKeysStack,\n openSubmenu,\n closeSubmenu\n };\n}\n"],"names":[],"version":3,"file":"useMenuTriggerState.module.js.map"}
@@ -1,78 +0,0 @@
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, "useSubmenuTriggerState", () => $38ab7fb105c54ad2$export$cfc51cf86138bf98);
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$cfc51cf86138bf98(props, state) {
21
- let { triggerKey: triggerKey } = props;
22
- let { expandedKeysStack: expandedKeysStack, openSubmenu: openSubmenu, closeSubmenu: closeSubmenu, close: closeAll } = state;
23
- let [submenuLevel] = (0, $9cbje$react.useState)(expandedKeysStack === null || expandedKeysStack === void 0 ? void 0 : expandedKeysStack.length);
24
- let isOpen = (0, $9cbje$react.useMemo)(()=>expandedKeysStack[submenuLevel] === triggerKey, [
25
- expandedKeysStack,
26
- triggerKey,
27
- submenuLevel
28
- ]);
29
- let [focusStrategy, setFocusStrategy] = (0, $9cbje$react.useState)(null);
30
- let open = (0, $9cbje$react.useCallback)((focusStrategy)=>{
31
- setFocusStrategy(focusStrategy !== null && focusStrategy !== void 0 ? focusStrategy : null);
32
- openSubmenu(triggerKey, submenuLevel);
33
- }, [
34
- openSubmenu,
35
- submenuLevel,
36
- triggerKey
37
- ]);
38
- let close = (0, $9cbje$react.useCallback)(()=>{
39
- setFocusStrategy(null);
40
- closeSubmenu(triggerKey, submenuLevel);
41
- }, [
42
- closeSubmenu,
43
- submenuLevel,
44
- triggerKey
45
- ]);
46
- let toggle = (0, $9cbje$react.useCallback)((focusStrategy)=>{
47
- setFocusStrategy(focusStrategy !== null && focusStrategy !== void 0 ? focusStrategy : null);
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
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAmCM,SAAS,0CAAuB,KAA0B,EAAE,KAA2B;IAC5F,IAAI,cAAC,UAAU,EAAC,GAAG;IACnB,IAAI,qBAAC,iBAAiB,eAAE,WAAW,gBAAE,YAAY,EAAE,OAAO,QAAQ,EAAC,GAAG;IACtE,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE,8BAAA,wCAAA,kBAAmB,MAAM;IACvD,IAAI,SAAS,CAAA,GAAA,oBAAM,EAAE,IAAM,iBAAiB,CAAC,aAAa,KAAK,YAAY;QAAC;QAAmB;QAAY;KAAa;IACxH,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAwB;IAEvE,IAAI,OAAO,CAAA,GAAA,wBAAU,EAAE,CAAC;QACtB,iBAAiB,0BAAA,2BAAA,gBAAiB;QAClC,YAAY,YAAY;IAC1B,GAAG;QAAC;QAAa;QAAc;KAAW;IAE1C,IAAI,QAAQ,CAAA,GAAA,wBAAU,EAAE;QACtB,iBAAiB;QACjB,aAAa,YAAY;IAC3B,GAAG;QAAC;QAAc;QAAc;KAAW;IAE3C,IAAI,SAAS,CAAA,GAAA,wBAAU,EAAE,CAAC;QACxB,iBAAiB,0BAAA,2BAAA,gBAAiB;QAClC,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 useSubmenuTriggerState(props: SubmenuTriggerProps, state: RootMenuTriggerState): SubmenuTriggerState {\n let {triggerKey} = props;\n let {expandedKeysStack, openSubmenu, closeSubmenu, close: closeAll} = state;\n let [submenuLevel] = useState(expandedKeysStack?.length);\n let isOpen = useMemo(() => expandedKeysStack[submenuLevel] === triggerKey, [expandedKeysStack, triggerKey, submenuLevel]);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n\n let open = useCallback((focusStrategy?: FocusStrategy | null) => {\n setFocusStrategy(focusStrategy ?? null);\n openSubmenu(triggerKey, submenuLevel);\n }, [openSubmenu, submenuLevel, triggerKey]);\n\n let close = useCallback(() => {\n setFocusStrategy(null);\n closeSubmenu(triggerKey, submenuLevel);\n }, [closeSubmenu, submenuLevel, triggerKey]);\n\n let toggle = useCallback((focusStrategy?: FocusStrategy | null) => {\n setFocusStrategy(focusStrategy ?? null);\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"}
@@ -1,73 +0,0 @@
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$cfc51cf86138bf98(props, state) {
15
- let { triggerKey: triggerKey } = props;
16
- let { expandedKeysStack: expandedKeysStack, openSubmenu: openSubmenu, closeSubmenu: closeSubmenu, close: closeAll } = state;
17
- let [submenuLevel] = (0, $7exkJ$useState)(expandedKeysStack === null || expandedKeysStack === void 0 ? void 0 : expandedKeysStack.length);
18
- let isOpen = (0, $7exkJ$useMemo)(()=>expandedKeysStack[submenuLevel] === triggerKey, [
19
- expandedKeysStack,
20
- triggerKey,
21
- submenuLevel
22
- ]);
23
- let [focusStrategy, setFocusStrategy] = (0, $7exkJ$useState)(null);
24
- let open = (0, $7exkJ$useCallback)((focusStrategy)=>{
25
- setFocusStrategy(focusStrategy !== null && focusStrategy !== void 0 ? focusStrategy : null);
26
- openSubmenu(triggerKey, submenuLevel);
27
- }, [
28
- openSubmenu,
29
- submenuLevel,
30
- triggerKey
31
- ]);
32
- let close = (0, $7exkJ$useCallback)(()=>{
33
- setFocusStrategy(null);
34
- closeSubmenu(triggerKey, submenuLevel);
35
- }, [
36
- closeSubmenu,
37
- submenuLevel,
38
- triggerKey
39
- ]);
40
- let toggle = (0, $7exkJ$useCallback)((focusStrategy)=>{
41
- setFocusStrategy(focusStrategy !== null && focusStrategy !== void 0 ? focusStrategy : null);
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$cfc51cf86138bf98 as useSubmenuTriggerState};
73
- //# sourceMappingURL=useSubmenuTriggerState.module.js.map
@@ -1,73 +0,0 @@
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$cfc51cf86138bf98(props, state) {
15
- let { triggerKey: triggerKey } = props;
16
- let { expandedKeysStack: expandedKeysStack, openSubmenu: openSubmenu, closeSubmenu: closeSubmenu, close: closeAll } = state;
17
- let [submenuLevel] = (0, $7exkJ$useState)(expandedKeysStack === null || expandedKeysStack === void 0 ? void 0 : expandedKeysStack.length);
18
- let isOpen = (0, $7exkJ$useMemo)(()=>expandedKeysStack[submenuLevel] === triggerKey, [
19
- expandedKeysStack,
20
- triggerKey,
21
- submenuLevel
22
- ]);
23
- let [focusStrategy, setFocusStrategy] = (0, $7exkJ$useState)(null);
24
- let open = (0, $7exkJ$useCallback)((focusStrategy)=>{
25
- setFocusStrategy(focusStrategy !== null && focusStrategy !== void 0 ? focusStrategy : null);
26
- openSubmenu(triggerKey, submenuLevel);
27
- }, [
28
- openSubmenu,
29
- submenuLevel,
30
- triggerKey
31
- ]);
32
- let close = (0, $7exkJ$useCallback)(()=>{
33
- setFocusStrategy(null);
34
- closeSubmenu(triggerKey, submenuLevel);
35
- }, [
36
- closeSubmenu,
37
- submenuLevel,
38
- triggerKey
39
- ]);
40
- let toggle = (0, $7exkJ$useCallback)((focusStrategy)=>{
41
- setFocusStrategy(focusStrategy !== null && focusStrategy !== void 0 ? focusStrategy : null);
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$cfc51cf86138bf98 as useSubmenuTriggerState};
73
- //# sourceMappingURL=useSubmenuTriggerState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAmCM,SAAS,0CAAuB,KAA0B,EAAE,KAA2B;IAC5F,IAAI,cAAC,UAAU,EAAC,GAAG;IACnB,IAAI,qBAAC,iBAAiB,eAAE,WAAW,gBAAE,YAAY,EAAE,OAAO,QAAQ,EAAC,GAAG;IACtE,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE,8BAAA,wCAAA,kBAAmB,MAAM;IACvD,IAAI,SAAS,CAAA,GAAA,cAAM,EAAE,IAAM,iBAAiB,CAAC,aAAa,KAAK,YAAY;QAAC;QAAmB;QAAY;KAAa;IACxH,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAwB;IAEvE,IAAI,OAAO,CAAA,GAAA,kBAAU,EAAE,CAAC;QACtB,iBAAiB,0BAAA,2BAAA,gBAAiB;QAClC,YAAY,YAAY;IAC1B,GAAG;QAAC;QAAa;QAAc;KAAW;IAE1C,IAAI,QAAQ,CAAA,GAAA,kBAAU,EAAE;QACtB,iBAAiB;QACjB,aAAa,YAAY;IAC3B,GAAG;QAAC;QAAc;QAAc;KAAW;IAE3C,IAAI,SAAS,CAAA,GAAA,kBAAU,EAAE,CAAC;QACxB,iBAAiB,0BAAA,2BAAA,gBAAiB;QAClC,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 useSubmenuTriggerState(props: SubmenuTriggerProps, state: RootMenuTriggerState): SubmenuTriggerState {\n let {triggerKey} = props;\n let {expandedKeysStack, openSubmenu, closeSubmenu, close: closeAll} = state;\n let [submenuLevel] = useState(expandedKeysStack?.length);\n let isOpen = useMemo(() => expandedKeysStack[submenuLevel] === triggerKey, [expandedKeysStack, triggerKey, submenuLevel]);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n\n let open = useCallback((focusStrategy?: FocusStrategy | null) => {\n setFocusStrategy(focusStrategy ?? null);\n openSubmenu(triggerKey, submenuLevel);\n }, [openSubmenu, submenuLevel, triggerKey]);\n\n let close = useCallback(() => {\n setFocusStrategy(null);\n closeSubmenu(triggerKey, submenuLevel);\n }, [closeSubmenu, submenuLevel, triggerKey]);\n\n let toggle = useCallback((focusStrategy?: FocusStrategy | null) => {\n setFocusStrategy(focusStrategy ?? null);\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"}
@@ -1,99 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {FocusStrategy, Key} from '@react-types/shared';
14
- import {MenuTriggerProps} from '@react-types/menu';
15
- import {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';
16
- import {useState} from 'react';
17
-
18
- export interface MenuTriggerState extends OverlayTriggerState {
19
- /** Controls which item will be auto focused when the menu opens. */
20
- readonly focusStrategy: FocusStrategy | null,
21
-
22
- /** Opens the menu. */
23
- open(focusStrategy?: FocusStrategy | null): void,
24
-
25
- /** Toggles the menu. */
26
- toggle(focusStrategy?: FocusStrategy | null): void
27
- }
28
-
29
- export interface RootMenuTriggerState extends MenuTriggerState {
30
- /** Opens a specific submenu tied to a specific menu item at a specific level. */
31
- openSubmenu: (triggerKey: Key, level: number) => void,
32
-
33
- /** Closes a specific submenu tied to a specific menu item at a specific level. */
34
- closeSubmenu: (triggerKey: Key, level: number) => void,
35
-
36
- /** An array of open submenu trigger keys within the menu tree.
37
- * The index of key within array matches the submenu level in the tree.
38
- */
39
- expandedKeysStack: Key[],
40
-
41
- /** Closes the menu and all submenus in the menu tree. */
42
- close: () => void
43
- }
44
-
45
- /**
46
- * Manages state for a menu trigger. Tracks whether the menu is currently open,
47
- * and controls which item will receive focus when it opens. Also tracks the open submenus within
48
- * the menu tree via their trigger keys.
49
- */
50
- export function useMenuTriggerState(props: MenuTriggerProps): RootMenuTriggerState {
51
- let overlayTriggerState = useOverlayTriggerState(props);
52
- let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);
53
- let [expandedKeysStack, setExpandedKeysStack] = useState<Key[]>([]);
54
-
55
- let closeAll = () => {
56
- setExpandedKeysStack([]);
57
- overlayTriggerState.close();
58
- };
59
-
60
- let openSubmenu = (triggerKey: Key, level: number) => {
61
- setExpandedKeysStack(oldStack => {
62
- if (level > oldStack.length) {
63
- return oldStack;
64
- }
65
-
66
- return [...oldStack.slice(0, level), triggerKey];
67
- });
68
- };
69
-
70
- let closeSubmenu = (triggerKey: Key, level: number) => {
71
- setExpandedKeysStack(oldStack => {
72
- let key = oldStack[level];
73
- if (key === triggerKey) {
74
- return oldStack.slice(0, level);
75
- } else {
76
- return oldStack;
77
- }
78
- });
79
- };
80
-
81
- return {
82
- focusStrategy,
83
- ...overlayTriggerState,
84
- open(focusStrategy: FocusStrategy | null = null) {
85
- setFocusStrategy(focusStrategy);
86
- overlayTriggerState.open();
87
- },
88
- toggle(focusStrategy: FocusStrategy | null = null) {
89
- setFocusStrategy(focusStrategy);
90
- overlayTriggerState.toggle();
91
- },
92
- close() {
93
- closeAll();
94
- },
95
- expandedKeysStack,
96
- openSubmenu,
97
- closeSubmenu
98
- };
99
- }
@@ -1,84 +0,0 @@
1
- /*
2
- * Copyright 2023 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {FocusStrategy, Key} from '@react-types/shared';
14
- import type {OverlayTriggerState} from '@react-stately/overlays';
15
- import {RootMenuTriggerState} from './useMenuTriggerState';
16
- import {useCallback, useMemo, useState} from 'react';
17
-
18
- export interface SubmenuTriggerProps {
19
- /** Key of the trigger item. */
20
- triggerKey: Key
21
- }
22
-
23
- export interface SubmenuTriggerState extends OverlayTriggerState {
24
- /** Whether the submenu is currently open. */
25
- isOpen: boolean,
26
- /** Controls which item will be auto focused when the submenu opens. */
27
- focusStrategy: FocusStrategy | null,
28
- /** Opens the submenu. */
29
- open: (focusStrategy?: FocusStrategy | null) => void,
30
- /** Closes the submenu. */
31
- close: () => void,
32
- /** Closes all menus and submenus in the menu tree. */
33
- closeAll: () => void,
34
- /** The level of the submenu. */
35
- submenuLevel: number,
36
- /** Toggles the submenu. */
37
- toggle: (focusStrategy?: FocusStrategy | null) => void,
38
- /** @private */
39
- setOpen: () => void
40
- }
41
-
42
- /**
43
- * Manages state for a submenu trigger. Tracks whether the submenu is currently open, the level of the submenu, and
44
- * controls which item will receive focus when it opens.
45
- */
46
- export function useSubmenuTriggerState(props: SubmenuTriggerProps, state: RootMenuTriggerState): SubmenuTriggerState {
47
- let {triggerKey} = props;
48
- let {expandedKeysStack, openSubmenu, closeSubmenu, close: closeAll} = state;
49
- let [submenuLevel] = useState(expandedKeysStack?.length);
50
- let isOpen = useMemo(() => expandedKeysStack[submenuLevel] === triggerKey, [expandedKeysStack, triggerKey, submenuLevel]);
51
- let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);
52
-
53
- let open = useCallback((focusStrategy?: FocusStrategy | null) => {
54
- setFocusStrategy(focusStrategy ?? null);
55
- openSubmenu(triggerKey, submenuLevel);
56
- }, [openSubmenu, submenuLevel, triggerKey]);
57
-
58
- let close = useCallback(() => {
59
- setFocusStrategy(null);
60
- closeSubmenu(triggerKey, submenuLevel);
61
- }, [closeSubmenu, submenuLevel, triggerKey]);
62
-
63
- let toggle = useCallback((focusStrategy?: FocusStrategy | null) => {
64
- setFocusStrategy(focusStrategy ?? null);
65
- if (isOpen) {
66
- close();
67
- } else {
68
- open(focusStrategy);
69
- }
70
- }, [close, open, isOpen]);
71
-
72
- return useMemo(() => ({
73
- focusStrategy,
74
- isOpen,
75
- open,
76
- close,
77
- closeAll,
78
- submenuLevel,
79
- // 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
80
- // https://github.com/adobe/react-spectrum/pull/4976#discussion_r1336472863
81
- setOpen: () => {},
82
- toggle
83
- }), [isOpen, open, close, closeAll, focusStrategy, toggle, submenuLevel]);
84
- }