@react-stately/tabs 3.8.9 → 3.9.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,4 +1,4 @@
1
- import {useTabListState as $76f919a04c5a7d14$export$4ba071daf4e486} from "./useTabListState.mjs";
1
+ import {useTabListState as $e72d863df7a788cb$re_export$useTabListState} from "react-stately/useTabListState";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useTabListState as $76f919a04c5a7d14$export$4ba071daf4e486} from "./useT
13
13
  */
14
14
 
15
15
 
16
- export {$76f919a04c5a7d14$export$4ba071daf4e486 as useTabListState};
16
+ export {$e72d863df7a788cb$re_export$useTabListState as useTabListState};
17
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
- var $817f925d289daf81$exports = require("./useTabListState.main.js");
1
+ var $9YfsR$reactstatelyuseTabListState = require("react-stately/useTabListState");
2
2
 
3
3
 
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
7
 
8
- $parcel$export(module.exports, "useTabListState", () => $817f925d289daf81$exports.useTabListState);
8
+ $parcel$export(module.exports, "useTabListState", function () { return $9YfsR$reactstatelyuseTabListState.useTabListState; });
9
9
  /*
10
10
  * Copyright 2020 Adobe. All rights reserved.
11
11
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/tabs/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 {useTabListState} from './useTabListState';\n\nexport type {TabListProps} from '@react-types/tabs';\nexport type {TabListStateOptions, TabListState} from './useTabListState';\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/tabs/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 {useTabListState} from 'react-stately/useTabListState';\n\nexport type {TabListProps, TabListStateOptions, TabListState} from 'react-stately/useTabListState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {useTabListState as $76f919a04c5a7d14$export$4ba071daf4e486} from "./useTabListState.module.js";
1
+ import {useTabListState as $e72d863df7a788cb$re_export$useTabListState} from "react-stately/useTabListState";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useTabListState as $76f919a04c5a7d14$export$4ba071daf4e486} from "./useT
13
13
  */
14
14
 
15
15
 
16
- export {$76f919a04c5a7d14$export$4ba071daf4e486 as useTabListState};
16
+ export {$e72d863df7a788cb$re_export$useTabListState as useTabListState};
17
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/tabs/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 {useTabListState} from './useTabListState';\n\nexport type {TabListProps} from '@react-types/tabs';\nexport type {TabListStateOptions, TabListState} from './useTabListState';\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/tabs/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 {useTabListState} from 'react-stately/useTabListState';\n\nexport type {TabListProps, TabListStateOptions, TabListState} from 'react-stately/useTabListState';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,2 @@
1
+ export { useTabListState } from 'react-stately/useTabListState';
2
+ export type { TabListProps, TabListStateOptions, TabListState } from 'react-stately/useTabListState';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-stately/tabs",
3
- "version": "3.8.9",
3
+ "version": "3.9.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/list": "^3.13.4",
30
- "@react-types/shared": "^3.33.1",
31
- "@react-types/tabs": "^3.3.22",
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": "8df187370053aa35f553cb388ad670f65e1ab371"
39
+ "targets": {
40
+ "types": false
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
41
43
  }
package/src/index.ts CHANGED
@@ -10,7 +10,6 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export {useTabListState} from './useTabListState';
13
+ export {useTabListState} from 'react-stately/useTabListState';
14
14
 
15
- export type {TabListProps} from '@react-types/tabs';
16
- export type {TabListStateOptions, TabListState} from './useTabListState';
15
+ export type {TabListProps, TabListStateOptions, TabListState} from 'react-stately/useTabListState';
package/dist/types.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import { CollectionStateBase } from "@react-types/shared";
2
- import { SingleSelectListState } from "@react-stately/list";
3
- import { TabListProps } from "@react-types/tabs";
4
- export interface TabListStateOptions<T> extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {
5
- }
6
- export interface TabListState<T> extends SingleSelectListState<T> {
7
- /** Whether the tab list is disabled. */
8
- isDisabled: boolean;
9
- }
10
- /**
11
- * Provides state management for a Tabs component. Tabs include a TabList which tracks
12
- * which tab is currently selected and displays the content associated with that Tab in a TabPanel.
13
- */
14
- export function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T>;
15
- export type { TabListProps } from '@react-types/tabs';
16
-
17
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AAiBA,qCAAqC,CAAC,CAAE,SAAQ,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,oBAAoB,CAAC,CAAC;CAAG;AAE5G,8BAA8B,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC;IAC/D,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAA;CACpB;AAED;;;GAGG;AACH,gCAAgC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAyChG;ACvDD,YAAY,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC","sources":["packages/@react-stately/tabs/src/packages/@react-stately/tabs/src/useTabListState.ts","packages/@react-stately/tabs/src/packages/@react-stately/tabs/src/index.ts","packages/@react-stately/tabs/src/index.ts"],"sourcesContent":[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 {useTabListState} from './useTabListState';\n\nexport type {TabListProps} from '@react-types/tabs';\nexport type {TabListStateOptions, TabListState} from './useTabListState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1,68 +0,0 @@
1
- var $3yB4p$reactstatelylist = require("@react-stately/list");
2
- var $3yB4p$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, "useTabListState", () => $817f925d289daf81$export$4ba071daf4e486);
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 $817f925d289daf81$export$4ba071daf4e486(props) {
23
- var _props_defaultSelectedKey, _ref;
24
- let state = (0, $3yB4p$reactstatelylist.useSingleSelectListState)({
25
- ...props,
26
- onSelectionChange: props.onSelectionChange ? (key)=>{
27
- var _props_onSelectionChange;
28
- if (key != null) (_props_onSelectionChange = props.onSelectionChange) === null || _props_onSelectionChange === void 0 ? void 0 : _props_onSelectionChange.call(props, key);
29
- } : undefined,
30
- suppressTextValueWarning: true,
31
- defaultSelectedKey: (_ref = (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : $817f925d289daf81$var$findDefaultSelectedKey(props.collection, props.disabledKeys ? new Set(props.disabledKeys) : new Set())) !== null && _ref !== void 0 ? _ref : undefined
32
- });
33
- let { selectionManager: selectionManager, collection: collection, selectedKey: currentSelectedKey } = state;
34
- let lastSelectedKey = (0, $3yB4p$react.useRef)(currentSelectedKey);
35
- (0, $3yB4p$react.useEffect)(()=>{
36
- // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
37
- let selectedKey = currentSelectedKey;
38
- if (props.selectedKey == null && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {
39
- selectedKey = $817f925d289daf81$var$findDefaultSelectedKey(collection, state.disabledKeys);
40
- if (selectedKey != null) // directly set selection because replace/toggle selection won't consider disabled keys
41
- selectionManager.setSelectedKeys([
42
- selectedKey
43
- ]);
44
- }
45
- // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.
46
- if (selectedKey != null && selectionManager.focusedKey == null || !selectionManager.isFocused && selectedKey !== lastSelectedKey.current) selectionManager.setFocusedKey(selectedKey);
47
- lastSelectedKey.current = selectedKey;
48
- });
49
- return {
50
- ...state,
51
- isDisabled: props.isDisabled || false
52
- };
53
- }
54
- function $817f925d289daf81$var$findDefaultSelectedKey(collection, disabledKeys) {
55
- let selectedKey = null;
56
- if (collection) {
57
- var _collection_getItem_props, _collection_getItem, _collection_getItem_props1, _collection_getItem1;
58
- selectedKey = collection.getFirstKey();
59
- // loop over tabs until we find one that isn't disabled and select that
60
- while(selectedKey != null && (disabledKeys.has(selectedKey) || ((_collection_getItem = collection.getItem(selectedKey)) === null || _collection_getItem === void 0 ? void 0 : (_collection_getItem_props = _collection_getItem.props) === null || _collection_getItem_props === void 0 ? void 0 : _collection_getItem_props.isDisabled)) && selectedKey !== collection.getLastKey())selectedKey = collection.getKeyAfter(selectedKey);
61
- // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
62
- if (selectedKey != null && (disabledKeys.has(selectedKey) || ((_collection_getItem1 = collection.getItem(selectedKey)) === null || _collection_getItem1 === void 0 ? void 0 : (_collection_getItem_props1 = _collection_getItem1.props) === null || _collection_getItem_props1 === void 0 ? void 0 : _collection_getItem_props1.isDisabled)) && selectedKey === collection.getLastKey()) selectedKey = collection.getFirst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;AAEA,SAAS,6CAA0B,UAA2C,EAAE,YAAsB;IACpG,IAAI,cAA0B;IAC9B,IAAI,YAAY;YAGkD,2BAAA,qBAIH,4BAAA;QAN7D,cAAc,WAAW,WAAW;QACpC,uEAAuE;QACvE,MAAO,eAAe,QAAS,CAAA,aAAa,GAAG,CAAC,kBAAgB,sBAAA,WAAW,OAAO,CAAC,0BAAnB,2CAAA,4BAAA,oBAAiC,KAAK,cAAtC,gDAAA,0BAAwC,UAAU,CAAD,KAAM,gBAAgB,WAAW,UAAU,GAC1J,cAAc,WAAW,WAAW,CAAC;QAEvC,oHAAoH;QACpH,IAAI,eAAe,QAAS,CAAA,aAAa,GAAG,CAAC,kBAAgB,uBAAA,WAAW,OAAO,CAAC,0BAAnB,4CAAA,6BAAA,qBAAiC,KAAK,cAAtC,iDAAA,2BAAwC,UAAU,CAAD,KAAM,gBAAgB,WAAW,UAAU,IACvJ,cAAc,WAAW,WAAW;IAExC;IAEA,OAAO;AACT","sources":["packages/@react-stately/tabs/src/useTabListState.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 {Collection, CollectionStateBase, Key, Node} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {TabListProps} from '@react-types/tabs';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListStateOptions<T> extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n onSelectionChange: props.onSelectionChange ? (key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }) : undefined,\n suppressTextValueWarning: true,\n defaultSelectedKey: props.defaultSelectedKey ?? findDefaultSelectedKey(props.collection, props.disabledKeys ? new Set(props.disabledKeys) : new Set()) ?? undefined\n });\n\n let {\n selectionManager,\n collection,\n selectedKey: currentSelectedKey\n } = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (props.selectedKey == null && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {\n selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (selectedKey != null && selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n\nfunction findDefaultSelectedKey<T>(collection: Collection<Node<T>> | undefined, disabledKeys: Set<Key>) {\n let selectedKey: Key | null = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey !== collection.getLastKey()) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey === collection.getLastKey()) {\n selectedKey = collection.getFirstKey();\n }\n }\n\n return selectedKey;\n}\n"],"names":[],"version":3,"file":"useTabListState.main.js.map"}
@@ -1,63 +0,0 @@
1
- import {useSingleSelectListState as $fgY1A$useSingleSelectListState} from "@react-stately/list";
2
- import {useRef as $fgY1A$useRef, useEffect as $fgY1A$useEffect} 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 $76f919a04c5a7d14$export$4ba071daf4e486(props) {
17
- var _props_defaultSelectedKey, _ref;
18
- let state = (0, $fgY1A$useSingleSelectListState)({
19
- ...props,
20
- onSelectionChange: props.onSelectionChange ? (key)=>{
21
- var _props_onSelectionChange;
22
- if (key != null) (_props_onSelectionChange = props.onSelectionChange) === null || _props_onSelectionChange === void 0 ? void 0 : _props_onSelectionChange.call(props, key);
23
- } : undefined,
24
- suppressTextValueWarning: true,
25
- defaultSelectedKey: (_ref = (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : $76f919a04c5a7d14$var$findDefaultSelectedKey(props.collection, props.disabledKeys ? new Set(props.disabledKeys) : new Set())) !== null && _ref !== void 0 ? _ref : undefined
26
- });
27
- let { selectionManager: selectionManager, collection: collection, selectedKey: currentSelectedKey } = state;
28
- let lastSelectedKey = (0, $fgY1A$useRef)(currentSelectedKey);
29
- (0, $fgY1A$useEffect)(()=>{
30
- // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
31
- let selectedKey = currentSelectedKey;
32
- if (props.selectedKey == null && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {
33
- selectedKey = $76f919a04c5a7d14$var$findDefaultSelectedKey(collection, state.disabledKeys);
34
- if (selectedKey != null) // directly set selection because replace/toggle selection won't consider disabled keys
35
- selectionManager.setSelectedKeys([
36
- selectedKey
37
- ]);
38
- }
39
- // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.
40
- if (selectedKey != null && selectionManager.focusedKey == null || !selectionManager.isFocused && selectedKey !== lastSelectedKey.current) selectionManager.setFocusedKey(selectedKey);
41
- lastSelectedKey.current = selectedKey;
42
- });
43
- return {
44
- ...state,
45
- isDisabled: props.isDisabled || false
46
- };
47
- }
48
- function $76f919a04c5a7d14$var$findDefaultSelectedKey(collection, disabledKeys) {
49
- let selectedKey = null;
50
- if (collection) {
51
- var _collection_getItem_props, _collection_getItem, _collection_getItem_props1, _collection_getItem1;
52
- selectedKey = collection.getFirstKey();
53
- // loop over tabs until we find one that isn't disabled and select that
54
- while(selectedKey != null && (disabledKeys.has(selectedKey) || ((_collection_getItem = collection.getItem(selectedKey)) === null || _collection_getItem === void 0 ? void 0 : (_collection_getItem_props = _collection_getItem.props) === null || _collection_getItem_props === void 0 ? void 0 : _collection_getItem_props.isDisabled)) && selectedKey !== collection.getLastKey())selectedKey = collection.getKeyAfter(selectedKey);
55
- // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
56
- if (selectedKey != null && (disabledKeys.has(selectedKey) || ((_collection_getItem1 = collection.getItem(selectedKey)) === null || _collection_getItem1 === void 0 ? void 0 : (_collection_getItem_props1 = _collection_getItem1.props) === null || _collection_getItem_props1 === void 0 ? void 0 : _collection_getItem_props1.isDisabled)) && selectedKey === collection.getLastKey()) selectedKey = collection.getFirstKey();
57
- }
58
- return selectedKey;
59
- }
60
-
61
-
62
- export {$76f919a04c5a7d14$export$4ba071daf4e486 as useTabListState};
63
- //# sourceMappingURL=useTabListState.module.js.map
@@ -1,63 +0,0 @@
1
- import {useSingleSelectListState as $fgY1A$useSingleSelectListState} from "@react-stately/list";
2
- import {useRef as $fgY1A$useRef, useEffect as $fgY1A$useEffect} 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 $76f919a04c5a7d14$export$4ba071daf4e486(props) {
17
- var _props_defaultSelectedKey, _ref;
18
- let state = (0, $fgY1A$useSingleSelectListState)({
19
- ...props,
20
- onSelectionChange: props.onSelectionChange ? (key)=>{
21
- var _props_onSelectionChange;
22
- if (key != null) (_props_onSelectionChange = props.onSelectionChange) === null || _props_onSelectionChange === void 0 ? void 0 : _props_onSelectionChange.call(props, key);
23
- } : undefined,
24
- suppressTextValueWarning: true,
25
- defaultSelectedKey: (_ref = (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : $76f919a04c5a7d14$var$findDefaultSelectedKey(props.collection, props.disabledKeys ? new Set(props.disabledKeys) : new Set())) !== null && _ref !== void 0 ? _ref : undefined
26
- });
27
- let { selectionManager: selectionManager, collection: collection, selectedKey: currentSelectedKey } = state;
28
- let lastSelectedKey = (0, $fgY1A$useRef)(currentSelectedKey);
29
- (0, $fgY1A$useEffect)(()=>{
30
- // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
31
- let selectedKey = currentSelectedKey;
32
- if (props.selectedKey == null && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {
33
- selectedKey = $76f919a04c5a7d14$var$findDefaultSelectedKey(collection, state.disabledKeys);
34
- if (selectedKey != null) // directly set selection because replace/toggle selection won't consider disabled keys
35
- selectionManager.setSelectedKeys([
36
- selectedKey
37
- ]);
38
- }
39
- // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.
40
- if (selectedKey != null && selectionManager.focusedKey == null || !selectionManager.isFocused && selectedKey !== lastSelectedKey.current) selectionManager.setFocusedKey(selectedKey);
41
- lastSelectedKey.current = selectedKey;
42
- });
43
- return {
44
- ...state,
45
- isDisabled: props.isDisabled || false
46
- };
47
- }
48
- function $76f919a04c5a7d14$var$findDefaultSelectedKey(collection, disabledKeys) {
49
- let selectedKey = null;
50
- if (collection) {
51
- var _collection_getItem_props, _collection_getItem, _collection_getItem_props1, _collection_getItem1;
52
- selectedKey = collection.getFirstKey();
53
- // loop over tabs until we find one that isn't disabled and select that
54
- while(selectedKey != null && (disabledKeys.has(selectedKey) || ((_collection_getItem = collection.getItem(selectedKey)) === null || _collection_getItem === void 0 ? void 0 : (_collection_getItem_props = _collection_getItem.props) === null || _collection_getItem_props === void 0 ? void 0 : _collection_getItem_props.isDisabled)) && selectedKey !== collection.getLastKey())selectedKey = collection.getKeyAfter(selectedKey);
55
- // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
56
- if (selectedKey != null && (disabledKeys.has(selectedKey) || ((_collection_getItem1 = collection.getItem(selectedKey)) === null || _collection_getItem1 === void 0 ? void 0 : (_collection_getItem_props1 = _collection_getItem1.props) === null || _collection_getItem_props1 === void 0 ? void 0 : _collection_getItem_props1.isDisabled)) && selectedKey === collection.getLastKey()) selectedKey = collection.getFirstKey();
57
- }
58
- return selectedKey;
59
- }
60
-
61
-
62
- export {$76f919a04c5a7d14$export$4ba071daf4e486 as useTabListState};
63
- //# sourceMappingURL=useTabListState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAkBM,SAAS,wCAAkC,KAA6B;QASvD,2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S,CAAA,aAAa,GAAG,CAAC,kBAAgB,sBAAA,WAAW,OAAO,CAAC,0BAAnB,2CAAA,4BAAA,oBAAiC,KAAK,cAAtC,gDAAA,0BAAwC,UAAU,CAAD,KAAM,gBAAgB,WAAW,UAAU,GAC1J,cAAc,WAAW,WAAW,CAAC;QAEvC,oHAAoH;QACpH,IAAI,eAAe,QAAS,CAAA,aAAa,GAAG,CAAC,kBAAgB,uBAAA,WAAW,OAAO,CAAC,0BAAnB,4CAAA,6BAAA,qBAAiC,KAAK,cAAtC,iDAAA,2BAAwC,UAAU,CAAD,KAAM,gBAAgB,WAAW,UAAU,IACvJ,cAAc,WAAW,WAAW;IAExC;IAEA,OAAO;AACT","sources":["packages/@react-stately/tabs/src/useTabListState.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 {Collection, CollectionStateBase, Key, Node} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {TabListProps} from '@react-types/tabs';\nimport {useEffect, useRef} from 'react';\n\nexport interface TabListStateOptions<T> extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}\n\nexport interface TabListState<T> extends SingleSelectListState<T> {\n /** Whether the tab list is disabled. */\n isDisabled: boolean\n}\n\n/**\n * Provides state management for a Tabs component. Tabs include a TabList which tracks\n * which tab is currently selected and displays the content associated with that Tab in a TabPanel.\n */\nexport function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {\n let state = useSingleSelectListState<T>({\n ...props,\n onSelectionChange: props.onSelectionChange ? (key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }) : undefined,\n suppressTextValueWarning: true,\n defaultSelectedKey: props.defaultSelectedKey ?? findDefaultSelectedKey(props.collection, props.disabledKeys ? new Set(props.disabledKeys) : new Set()) ?? undefined\n });\n\n let {\n selectionManager,\n collection,\n selectedKey: currentSelectedKey\n } = state;\n\n let lastSelectedKey = useRef(currentSelectedKey);\n useEffect(() => {\n // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = currentSelectedKey;\n if (props.selectedKey == null && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {\n selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);\n if (selectedKey != null) {\n // directly set selection because replace/toggle selection won't consider disabled keys\n selectionManager.setSelectedKeys([selectedKey]);\n }\n }\n\n // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.\n if (selectedKey != null && selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {\n selectionManager.setFocusedKey(selectedKey);\n }\n lastSelectedKey.current = selectedKey;\n });\n\n return {\n ...state,\n isDisabled: props.isDisabled || false\n };\n}\n\nfunction findDefaultSelectedKey<T>(collection: Collection<Node<T>> | undefined, disabledKeys: Set<Key>) {\n let selectedKey: Key | null = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over tabs until we find one that isn't disabled and select that\n while (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey !== collection.getLastKey()) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last\n if (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey === collection.getLastKey()) {\n selectedKey = collection.getFirstKey();\n }\n }\n\n return selectedKey;\n}\n"],"names":[],"version":3,"file":"useTabListState.module.js.map"}
@@ -1,87 +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 {Collection, CollectionStateBase, Key, Node} from '@react-types/shared';
14
- import {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';
15
- import {TabListProps} from '@react-types/tabs';
16
- import {useEffect, useRef} from 'react';
17
-
18
- export interface TabListStateOptions<T> extends Omit<TabListProps<T>, 'children'>, CollectionStateBase<T> {}
19
-
20
- export interface TabListState<T> extends SingleSelectListState<T> {
21
- /** Whether the tab list is disabled. */
22
- isDisabled: boolean
23
- }
24
-
25
- /**
26
- * Provides state management for a Tabs component. Tabs include a TabList which tracks
27
- * which tab is currently selected and displays the content associated with that Tab in a TabPanel.
28
- */
29
- export function useTabListState<T extends object>(props: TabListStateOptions<T>): TabListState<T> {
30
- let state = useSingleSelectListState<T>({
31
- ...props,
32
- onSelectionChange: props.onSelectionChange ? (key => {
33
- if (key != null) {
34
- props.onSelectionChange?.(key);
35
- }
36
- }) : undefined,
37
- suppressTextValueWarning: true,
38
- defaultSelectedKey: props.defaultSelectedKey ?? findDefaultSelectedKey(props.collection, props.disabledKeys ? new Set(props.disabledKeys) : new Set()) ?? undefined
39
- });
40
-
41
- let {
42
- selectionManager,
43
- collection,
44
- selectedKey: currentSelectedKey
45
- } = state;
46
-
47
- let lastSelectedKey = useRef(currentSelectedKey);
48
- useEffect(() => {
49
- // Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
50
- let selectedKey = currentSelectedKey;
51
- if (props.selectedKey == null && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {
52
- selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);
53
- if (selectedKey != null) {
54
- // directly set selection because replace/toggle selection won't consider disabled keys
55
- selectionManager.setSelectedKeys([selectedKey]);
56
- }
57
- }
58
-
59
- // If the tablist doesn't have focus and the selected key changes or if there isn't a focused key yet, change focused key to the selected key if it exists.
60
- if (selectedKey != null && selectionManager.focusedKey == null || (!selectionManager.isFocused && selectedKey !== lastSelectedKey.current)) {
61
- selectionManager.setFocusedKey(selectedKey);
62
- }
63
- lastSelectedKey.current = selectedKey;
64
- });
65
-
66
- return {
67
- ...state,
68
- isDisabled: props.isDisabled || false
69
- };
70
- }
71
-
72
- function findDefaultSelectedKey<T>(collection: Collection<Node<T>> | undefined, disabledKeys: Set<Key>) {
73
- let selectedKey: Key | null = null;
74
- if (collection) {
75
- selectedKey = collection.getFirstKey();
76
- // loop over tabs until we find one that isn't disabled and select that
77
- while (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey !== collection.getLastKey()) {
78
- selectedKey = collection.getKeyAfter(selectedKey);
79
- }
80
- // if this check is true, then every item is disabled, it makes more sense to default to the first key than the last
81
- if (selectedKey != null && (disabledKeys.has(selectedKey) || collection.getItem(selectedKey)?.props?.isDisabled) && selectedKey === collection.getLastKey()) {
82
- selectedKey = collection.getFirstKey();
83
- }
84
- }
85
-
86
- return selectedKey;
87
- }