@react-stately/tree 3.6.0 → 3.7.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,8 +1,7 @@
1
- import {useMemo as $1OoTj$useMemo, useEffect as $1OoTj$useEffect} from "react";
1
+ import {useMemo as $1OoTj$useMemo, useCallback as $1OoTj$useCallback, useEffect as $1OoTj$useEffect} from "react";
2
2
  import {useMultipleSelectionState as $1OoTj$useMultipleSelectionState, SelectionManager as $1OoTj$SelectionManager} from "@react-stately/selection";
3
3
  import {useCollection as $1OoTj$useCollection} from "@react-stately/collections";
4
4
  import {useControlledState as $1OoTj$useControlledState} from "@react-stately/utils";
5
- import $1OoTj$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
6
5
 
7
6
  /*
8
7
  * Copyright 2020 Adobe. All rights reserved.
@@ -36,10 +35,8 @@ import $1OoTj$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_pr
36
35
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
37
36
  * OF ANY KIND, either express or implied. See the License for the specific language
38
37
  * governing permissions and limitations under the License.
39
- */
40
- let $05ca4cd7c4a5a999$var$_Symbol_iterator = Symbol.iterator;
41
- class $05ca4cd7c4a5a999$export$863faf230ee2118a {
42
- *[$05ca4cd7c4a5a999$var$_Symbol_iterator]() {
38
+ */ class $05ca4cd7c4a5a999$export$863faf230ee2118a {
39
+ *[Symbol.iterator]() {
43
40
  yield* this.iterable;
44
41
  }
45
42
  get size() {
@@ -72,7 +69,7 @@ class $05ca4cd7c4a5a999$export$863faf230ee2118a {
72
69
  return this.getItem(keys[idx]);
73
70
  }
74
71
  constructor(nodes, { expandedKeys: expandedKeys } = {}){
75
- (0, $1OoTj$swchelperssrc_define_propertymjs)(this, "keyMap", new Map());
72
+ this.keyMap = new Map();
76
73
  this.iterable = nodes;
77
74
  expandedKeys = expandedKeys || new Set();
78
75
  let visit = (node)=>{
@@ -82,16 +79,16 @@ class $05ca4cd7c4a5a999$export$863faf230ee2118a {
82
79
  for (let node of nodes)visit(node);
83
80
  let last;
84
81
  let index = 0;
85
- for (let [key, node1] of this.keyMap){
82
+ for (let [key, node] of this.keyMap){
86
83
  if (last) {
87
84
  last.nextKey = key;
88
- node1.prevKey = last.key;
85
+ node.prevKey = last.key;
89
86
  } else {
90
87
  this.firstKey = key;
91
- node1.prevKey = undefined;
88
+ node.prevKey = undefined;
92
89
  }
93
- if (node1.type === "item") node1.index = index++;
94
- last = node1;
90
+ if (node.type === "item") node.index = index++;
91
+ last = node;
95
92
  // Set nextKey as undefined since this might be the last node
96
93
  // If it isn't the last node, last.nextKey will properly set at start of new loop
97
94
  last.nextKey = undefined;
@@ -109,11 +106,11 @@ function $875d6693e12af071$export$728d6ba534403756(props) {
109
106
  let disabledKeys = (0, $1OoTj$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
110
107
  props.disabledKeys
111
108
  ]);
112
- let tree = (0, $1OoTj$useCollection)(props, (nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
109
+ let tree = (0, $1OoTj$useCollection)(props, (0, $1OoTj$useCallback)((nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
113
110
  expandedKeys: expandedKeys
114
- }), null, [
111
+ }), [
115
112
  expandedKeys
116
- ]);
113
+ ]), null);
117
114
  // Reset focused key if that item is deleted from the collection.
118
115
  (0, $1OoTj$useEffect)(()=>{
119
116
  if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
@@ -130,6 +127,7 @@ function $875d6693e12af071$export$728d6ba534403756(props) {
130
127
  expandedKeys: expandedKeys,
131
128
  disabledKeys: disabledKeys,
132
129
  toggleKey: onToggle,
130
+ setExpandedKeys: setExpandedKeys,
133
131
  selectionManager: new (0, $1OoTj$SelectionManager)(tree, selectionState)
134
132
  };
135
133
  }
package/dist/main.js CHANGED
@@ -2,14 +2,10 @@ var $cfIzB$react = require("react");
2
2
  var $cfIzB$reactstatelyselection = require("@react-stately/selection");
3
3
  var $cfIzB$reactstatelycollections = require("@react-stately/collections");
4
4
  var $cfIzB$reactstatelyutils = require("@react-stately/utils");
5
- var $cfIzB$swchelperslib_define_propertyjs = require("@swc/helpers/lib/_define_property.js");
6
5
 
7
6
  function $parcel$export(e, n, v, s) {
8
7
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
8
  }
10
- function $parcel$interopDefault(a) {
11
- return a && a.__esModule ? a.default : a;
12
- }
13
9
 
14
10
  $parcel$export(module.exports, "useTreeState", () => $38effb299000faaf$export$728d6ba534403756);
15
11
  $parcel$export(module.exports, "TreeCollection", () => $fae56b53b03726ff$export$863faf230ee2118a);
@@ -45,10 +41,8 @@ $parcel$export(module.exports, "TreeCollection", () => $fae56b53b03726ff$export$
45
41
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
46
42
  * OF ANY KIND, either express or implied. See the License for the specific language
47
43
  * governing permissions and limitations under the License.
48
- */
49
- let $fae56b53b03726ff$var$_Symbol_iterator = Symbol.iterator;
50
- class $fae56b53b03726ff$export$863faf230ee2118a {
51
- *[$fae56b53b03726ff$var$_Symbol_iterator]() {
44
+ */ class $fae56b53b03726ff$export$863faf230ee2118a {
45
+ *[Symbol.iterator]() {
52
46
  yield* this.iterable;
53
47
  }
54
48
  get size() {
@@ -81,7 +75,7 @@ class $fae56b53b03726ff$export$863faf230ee2118a {
81
75
  return this.getItem(keys[idx]);
82
76
  }
83
77
  constructor(nodes, { expandedKeys: expandedKeys } = {}){
84
- (0, ($parcel$interopDefault($cfIzB$swchelperslib_define_propertyjs)))(this, "keyMap", new Map());
78
+ this.keyMap = new Map();
85
79
  this.iterable = nodes;
86
80
  expandedKeys = expandedKeys || new Set();
87
81
  let visit = (node)=>{
@@ -91,16 +85,16 @@ class $fae56b53b03726ff$export$863faf230ee2118a {
91
85
  for (let node of nodes)visit(node);
92
86
  let last;
93
87
  let index = 0;
94
- for (let [key, node1] of this.keyMap){
88
+ for (let [key, node] of this.keyMap){
95
89
  if (last) {
96
90
  last.nextKey = key;
97
- node1.prevKey = last.key;
91
+ node.prevKey = last.key;
98
92
  } else {
99
93
  this.firstKey = key;
100
- node1.prevKey = undefined;
94
+ node.prevKey = undefined;
101
95
  }
102
- if (node1.type === "item") node1.index = index++;
103
- last = node1;
96
+ if (node.type === "item") node.index = index++;
97
+ last = node;
104
98
  // Set nextKey as undefined since this might be the last node
105
99
  // If it isn't the last node, last.nextKey will properly set at start of new loop
106
100
  last.nextKey = undefined;
@@ -118,11 +112,11 @@ function $38effb299000faaf$export$728d6ba534403756(props) {
118
112
  let disabledKeys = (0, $cfIzB$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
119
113
  props.disabledKeys
120
114
  ]);
121
- let tree = (0, $cfIzB$reactstatelycollections.useCollection)(props, (nodes)=>new (0, $fae56b53b03726ff$export$863faf230ee2118a)(nodes, {
115
+ let tree = (0, $cfIzB$reactstatelycollections.useCollection)(props, (0, $cfIzB$react.useCallback)((nodes)=>new (0, $fae56b53b03726ff$export$863faf230ee2118a)(nodes, {
122
116
  expandedKeys: expandedKeys
123
- }), null, [
117
+ }), [
124
118
  expandedKeys
125
- ]);
119
+ ]), null);
126
120
  // Reset focused key if that item is deleted from the collection.
127
121
  (0, $cfIzB$react.useEffect)(()=>{
128
122
  if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
@@ -139,6 +133,7 @@ function $38effb299000faaf$export$728d6ba534403756(props) {
139
133
  expandedKeys: expandedKeys,
140
134
  disabledKeys: disabledKeys,
141
135
  toggleKey: onToggle,
136
+ setExpandedKeys: setExpandedKeys,
142
137
  selectionManager: new (0, $cfIzB$reactstatelyselection.SelectionManager)(tree, selectionState)
143
138
  };
144
139
  }
package/dist/main.js.map CHANGED
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,sBAAS,AAAD,EAAE,IAAM;QACd,IAAI,eAAe,UAAU,IAAI,IAAI,IAAI,CAAC,KAAK,OAAO,CAAC,eAAe,UAAU,GAC9E,eAAe,aAAa,CAAC,IAAI;IAErC,uDAAuD;IACvD,GAAG;QAAC;QAAM,eAAe,UAAU;KAAC;IAEpC,IAAI,WAAW,CAAC,MAAa;QAC3B,gBAAgB,gCAAU,cAAc;IAC1C;IAEA,OAAO;QACL,YAAY;sBACZ;sBACA;QACA,WAAW;QACX,kBAAkB,IAAI,CAAA,GAAA,6CAAe,EAAE,MAAM;IAC/C;AACF;AAEA,SAAS,gCAAU,GAAa,EAAE,GAAQ,EAAY;IACpD,IAAI,MAAM,IAAI,IAAI;IAClB,IAAI,IAAI,GAAG,CAAC,MACV,IAAI,MAAM,CAAC;SAEX,IAAI,GAAG,CAAC;IAGV,OAAO;AACT;;CD3EC,GACD","sources":["packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/TreeCollection.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 */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Expandable, MultipleSelection, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {}\nexport interface TreeState<T> {\n /** A collection of items in the tree. */\n readonly collection: Collection<Node<T>>,\n\n /** A set of keys for items that are disabled. */\n readonly disabledKeys: Set<Key>,\n\n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>,\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** A selection manager to read and update multiple selection state. */\n readonly selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for tree-like components. Handles building a collection\n * of items from props, item expanded state, and manages multiple selection state.\n */\nexport function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T> {\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.onExpandedChange\n );\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let tree = useCollection(props, nodes => new TreeCollection(nodes, {expandedKeys}), null, [expandedKeys]);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\n selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node} from '@react-types/shared';\nimport {Key} from 'react';\n\nexport class TreeCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {\n this.iterable = nodes;\n expandedKeys = expandedKeys || new Set();\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;ACVD;;;;;;;;;;CAUC,GAKM,MAAM;IAiDX,CAAC,CAAC,OAAO,SAAS,GAAG;QACnB,OAAO,IAAI,CAAC;IACd;IAEA,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,UAAU;QACR,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,aAAa,GAAQ,EAAE;QACrB,IAAI,OAAO,IAAI,CAAC,OAAO,IAAI;QAC3B,OAAO,OAAO,KAAK,UAAU;IAC/B;IAEA,YAAY,GAAQ,EAAE;QACpB,IAAI,OAAO,IAAI,CAAC,OAAO,IAAI;QAC3B,OAAO,OAAO,KAAK,UAAU;IAC/B;IAEA,cAAc;QACZ,OAAO,IAAI,CAAC;IACd;IAEA,aAAa;QACX,OAAO,IAAI,CAAC;IACd;IAEA,QAAQ,GAAQ,EAAE;QAChB,OAAO,IAAI,CAAC,OAAO,IAAI;IACzB;IAEA,GAAG,GAAW,EAAE;QACd,MAAM,OAAO;eAAI,IAAI,CAAC;SAAU;QAChC,OAAO,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI;IAC/B;IAhFA,YAAY,KAAwB,EAAE,gBAAC,aAAY,EAA4B,GAAG,CAAC,CAAC,CAAE;aAL9E,SAA4B,IAAI;QAMtC,IAAI,CAAC,WAAW;QAChB,eAAe,gBAAgB,IAAI;QAEnC,IAAI,QAAQ,CAA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ACpE,eAAe,cAAc;IAEjC,uDAAuD;IACvD,GAAG;QAAC;QAAM,eAAe;KAAW;IAEpC,IAAI,WAAW,CAAC;QACd,gBAAgB,gCAAU,cAAc;IAC1C;IAEA,OAAO;QACL,YAAY;sBACZ;sBACA;QACA,WAAW;yBACX;QACA,kBAAkB,IAAI,CAAA,GAAA,6CAAe,EAAE,MAAM;IAC/C;AACF;AAEA,SAAS,gCAAU,GAAa,EAAE,GAAQ;IACxC,IAAI,MAAM,IAAI,IAAI;IAClB,IAAI,IAAI,IAAI,MACV,IAAI,OAAO;SAEX,IAAI,IAAI;IAGV,OAAO;AACT;;CD/EC","sources":["packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/TreeCollection.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 */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Expandable, MultipleSelection, Node} from '@react-types/shared';\nimport {Key, useCallback, useEffect, useMemo} from 'react';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {}\nexport interface TreeState<T> {\n /** A collection of items in the tree. */\n readonly collection: Collection<Node<T>>,\n\n /** A set of keys for items that are disabled. */\n readonly disabledKeys: Set<Key>,\n\n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>,\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Replaces the set of expanded keys. */\n setExpandedKeys(keys: Set<Key>): void,\n\n /** A selection manager to read and update multiple selection state. */\n readonly selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for tree-like components. Handles building a collection\n * of items from props, item expanded state, and manages multiple selection state.\n */\nexport function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T> {\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.onExpandedChange\n );\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let tree = useCollection(props, useCallback(nodes => new TreeCollection(nodes, {expandedKeys}), [expandedKeys]), null);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\n setExpandedKeys,\n selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node} from '@react-types/shared';\nimport {Key} from 'react';\n\nexport class TreeCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {\n this.iterable = nodes;\n expandedKeys = expandedKeys || new Set();\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,8 +1,7 @@
1
- import {useMemo as $1OoTj$useMemo, useEffect as $1OoTj$useEffect} from "react";
1
+ import {useMemo as $1OoTj$useMemo, useCallback as $1OoTj$useCallback, useEffect as $1OoTj$useEffect} from "react";
2
2
  import {useMultipleSelectionState as $1OoTj$useMultipleSelectionState, SelectionManager as $1OoTj$SelectionManager} from "@react-stately/selection";
3
3
  import {useCollection as $1OoTj$useCollection} from "@react-stately/collections";
4
4
  import {useControlledState as $1OoTj$useControlledState} from "@react-stately/utils";
5
- import $1OoTj$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
6
5
 
7
6
  /*
8
7
  * Copyright 2020 Adobe. All rights reserved.
@@ -36,10 +35,8 @@ import $1OoTj$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_pr
36
35
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
37
36
  * OF ANY KIND, either express or implied. See the License for the specific language
38
37
  * governing permissions and limitations under the License.
39
- */
40
- let $05ca4cd7c4a5a999$var$_Symbol_iterator = Symbol.iterator;
41
- class $05ca4cd7c4a5a999$export$863faf230ee2118a {
42
- *[$05ca4cd7c4a5a999$var$_Symbol_iterator]() {
38
+ */ class $05ca4cd7c4a5a999$export$863faf230ee2118a {
39
+ *[Symbol.iterator]() {
43
40
  yield* this.iterable;
44
41
  }
45
42
  get size() {
@@ -72,7 +69,7 @@ class $05ca4cd7c4a5a999$export$863faf230ee2118a {
72
69
  return this.getItem(keys[idx]);
73
70
  }
74
71
  constructor(nodes, { expandedKeys: expandedKeys } = {}){
75
- (0, $1OoTj$swchelperssrc_define_propertymjs)(this, "keyMap", new Map());
72
+ this.keyMap = new Map();
76
73
  this.iterable = nodes;
77
74
  expandedKeys = expandedKeys || new Set();
78
75
  let visit = (node)=>{
@@ -82,16 +79,16 @@ class $05ca4cd7c4a5a999$export$863faf230ee2118a {
82
79
  for (let node of nodes)visit(node);
83
80
  let last;
84
81
  let index = 0;
85
- for (let [key, node1] of this.keyMap){
82
+ for (let [key, node] of this.keyMap){
86
83
  if (last) {
87
84
  last.nextKey = key;
88
- node1.prevKey = last.key;
85
+ node.prevKey = last.key;
89
86
  } else {
90
87
  this.firstKey = key;
91
- node1.prevKey = undefined;
88
+ node.prevKey = undefined;
92
89
  }
93
- if (node1.type === "item") node1.index = index++;
94
- last = node1;
90
+ if (node.type === "item") node.index = index++;
91
+ last = node;
95
92
  // Set nextKey as undefined since this might be the last node
96
93
  // If it isn't the last node, last.nextKey will properly set at start of new loop
97
94
  last.nextKey = undefined;
@@ -109,11 +106,11 @@ function $875d6693e12af071$export$728d6ba534403756(props) {
109
106
  let disabledKeys = (0, $1OoTj$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
110
107
  props.disabledKeys
111
108
  ]);
112
- let tree = (0, $1OoTj$useCollection)(props, (nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
109
+ let tree = (0, $1OoTj$useCollection)(props, (0, $1OoTj$useCallback)((nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
113
110
  expandedKeys: expandedKeys
114
- }), null, [
111
+ }), [
115
112
  expandedKeys
116
- ]);
113
+ ]), null);
117
114
  // Reset focused key if that item is deleted from the collection.
118
115
  (0, $1OoTj$useEffect)(()=>{
119
116
  if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
@@ -130,6 +127,7 @@ function $875d6693e12af071$export$728d6ba534403756(props) {
130
127
  expandedKeys: expandedKeys,
131
128
  disabledKeys: disabledKeys,
132
129
  toggleKey: onToggle,
130
+ setExpandedKeys: setExpandedKeys,
133
131
  selectionManager: new (0, $1OoTj$SelectionManager)(tree, selectionState)
134
132
  };
135
133
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;ACZA;;;;;;;;;;CAUC,GAED;IAoDI,yCAAA,OAAO,QAAQ;AAjDZ,MAAM;IAiDX,CAAC,CAAC,uCAAgB,GAAG;QACnB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAE;QACrB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAAO,GAAG,IAAI;IACnC;IAEA,YAAY,GAAQ,EAAE;QACpB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAAO,GAAG,IAAI;IACnC;IAEA,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,aAAa;QACX,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,QAAQ,GAAQ,EAAE;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB;IAEA,GAAG,GAAW,EAAE;QACd,MAAM,OAAO;eAAI,IAAI,CAAC,OAAO;SAAG;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;IAC/B;IAhFA,YAAY,KAAwB,EAAE,gBAAC,aAAY,EAA4B,GAAG,CAAC,CAAC,CAAE;QALtF,mDAAQ,UAA4B,IAAI;QAMtC,IAAI,CAAC,QAAQ,GAAG;QAChB,eAAe,gBAAgB,IAAI;QAEnC,IAAI,QAAQ,CAAC,OAAkB;Y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IAAI,CAAA,GAAA,yCAAc,AAAD,EAAE,OAAO;0BAAC;QAAY,IAAI,IAAI,EAAE;QAAC;KAAa;IAExG,iEAAiE;IACjE,CAAA,GAAA,gBAAS,AAAD,EAAE,IAAM;QACd,IAAI,eAAe,UAAU,IAAI,IAAI,IAAI,CAAC,KAAK,OAAO,CAAC,eAAe,UAAU,GAC9E,eAAe,aAAa,CAAC,IAAI;IAErC,uDAAuD;IACvD,GAAG;QAAC;QAAM,eAAe,UAAU;KAAC;IAEpC,IAAI,WAAW,CAAC,MAAa;QAC3B,gBAAgB,gCAAU,cAAc;IAC1C;IAEA,OAAO;QACL,YAAY;sBACZ;sBACA;QACA,WAAW;QACX,kBAAkB,IAAI,CAAA,GAAA,uBAAe,EAAE,MAAM;IAC/C;AACF;AAEA,SAAS,gCAAU,GAAa,EAAE,GAAQ,EAAY;IACpD,IAAI,MAAM,IAAI,IAAI;IAClB,IAAI,IAAI,GAAG,CAAC,MACV,IAAI,MAAM,CAAC;SAEX,IAAI,GAAG,CAAC;IAGV,OAAO;AACT;;CD3EC,GACD","sources":["packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/TreeCollection.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 */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Expandable, MultipleSelection, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {}\nexport interface TreeState<T> {\n /** A collection of items in the tree. */\n readonly collection: Collection<Node<T>>,\n\n /** A set of keys for items that are disabled. */\n readonly disabledKeys: Set<Key>,\n\n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>,\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** A selection manager to read and update multiple selection state. */\n readonly selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for tree-like components. Handles building a collection\n * of items from props, item expanded state, and manages multiple selection state.\n */\nexport function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T> {\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.onExpandedChange\n );\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let tree = useCollection(props, nodes => new TreeCollection(nodes, {expandedKeys}), null, [expandedKeys]);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\n selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node} from '@react-types/shared';\nimport {Key} from 'react';\n\nexport class TreeCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {\n this.iterable = nodes;\n expandedKeys = expandedKeys || new Set();\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;ACVD;;;;;;;;;;CAUC,GAKM,MAAM;IAiDX,CAAC,CAAC,OAAO,SAAS,GAAG;QACnB,OAAO,IAAI,CAAC;IACd;IAEA,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,UAAU;QACR,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,aAAa,GAAQ,EAAE;QACrB,IAAI,OAAO,IAAI,CAAC,OAAO,IAAI;QAC3B,OAAO,OAAO,KAAK,UAAU;IAC/B;IAEA,YAAY,GAAQ,EAAE;QACpB,IAAI,OAAO,IAAI,CAAC,OAAO,IAAI;QAC3B,OAAO,OAAO,KAAK,UAAU;IAC/B;IAEA,cAAc;QACZ,OAAO,IAAI,CAAC;IACd;IAEA,aAAa;QACX,OAAO,IAAI,CAAC;IACd;IAEA,QAAQ,GAAQ,EAAE;QAChB,OAAO,IAAI,CAAC,OAAO,IAAI;IACzB;IAEA,GAAG,GAAW,EAAE;QACd,MAAM,OAAO;eAAI,IAAI,CAAC;SAAU;QAChC,OAAO,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI;IAC/B;IAhFA,YAAY,KAAwB,EAAE,gBAAC,aAAY,EAA4B,GAAG,CAA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AAG;IAEjH,iEAAiE;IACjE,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,eAAe,cAAc,QAAQ,CAAC,KAAK,QAAQ,eAAe,aACpE,eAAe,cAAc;IAEjC,uDAAuD;IACvD,GAAG;QAAC;QAAM,eAAe;KAAW;IAEpC,IAAI,WAAW,CAAC;QACd,gBAAgB,gCAAU,cAAc;IAC1C;IAEA,OAAO;QACL,YAAY;sBACZ;sBACA;QACA,WAAW;yBACX;QACA,kBAAkB,IAAI,CAAA,GAAA,uBAAe,EAAE,MAAM;IAC/C;AACF;AAEA,SAAS,gCAAU,GAAa,EAAE,GAAQ;IACxC,IAAI,MAAM,IAAI,IAAI;IAClB,IAAI,IAAI,IAAI,MACV,IAAI,OAAO;SAEX,IAAI,IAAI;IAGV,OAAO;AACT;;CD/EC","sources":["packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/TreeCollection.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 */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Expandable, MultipleSelection, Node} from '@react-types/shared';\nimport {Key, useCallback, useEffect, useMemo} from 'react';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {}\nexport interface TreeState<T> {\n /** A collection of items in the tree. */\n readonly collection: Collection<Node<T>>,\n\n /** A set of keys for items that are disabled. */\n readonly disabledKeys: Set<Key>,\n\n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>,\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Replaces the set of expanded keys. */\n setExpandedKeys(keys: Set<Key>): void,\n\n /** A selection manager to read and update multiple selection state. */\n readonly selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for tree-like components. Handles building a collection\n * of items from props, item expanded state, and manages multiple selection state.\n */\nexport function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T> {\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.onExpandedChange\n );\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let tree = useCollection(props, useCallback(nodes => new TreeCollection(nodes, {expandedKeys}), [expandedKeys]), null);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\n setExpandedKeys,\n selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node} from '@react-types/shared';\nimport {Key} from 'react';\n\nexport class TreeCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {\n this.iterable = nodes;\n expandedKeys = expandedKeys || new Set();\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -26,6 +26,8 @@ export interface TreeState<T> {
26
26
  readonly expandedKeys: Set<Key>;
27
27
  /** Toggles the expanded state for an item by its key. */
28
28
  toggleKey(key: Key): void;
29
+ /** Replaces the set of expanded keys. */
30
+ setExpandedKeys(keys: Set<Key>): void;
29
31
  /** A selection manager to read and update multiple selection state. */
30
32
  readonly selectionManager: SelectionManager;
31
33
  }
@@ -1 +1 @@
1
- {"mappings":";;;AAeA,4BAA4B,CAAC,CAAE,YAAW,WAAW,KAAK,CAAC,CAAC,CAAC;gBAM/C,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAC,YAAY,EAAC,GAAE;QAAC,YAAY,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;KAAM;IA2CnF,CAAC,MAAM,CAAC,QAAQ,CAAC;IAIlB,IAAI,IAAI,WAEP;IAED,OAAO;IAIP,YAAY,CAAC,GAAG,EAAE,GAAG;IAKrB,WAAW,CAAC,GAAG,EAAE,GAAG;IAKpB,WAAW;IAIX,UAAU;IAIV,OAAO,CAAC,GAAG,EAAE,GAAG;IAIhB,EAAE,CAAC,GAAG,EAAE,MAAM;CAIf;ACnFD,2BAA2B,CAAC,CAAE,SAAQ,oBAAoB,CAAC,CAAC,EAAE,UAAU,EAAE,iBAAiB;CAAG;AAC9F,2BAA2B,CAAC;IAC1B,yCAAyC;IACzC,QAAQ,CAAC,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC;IAEzC,iDAAiD;IACjD,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEhC,iDAAiD;IACjD,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEhC,yDAAyD;IACzD,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAE1B,uEAAuE;IACvE,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAA;CAC5C;AAED;;;GAGG;AACH,6BAA6B,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAiChF","sources":["packages/@react-stately/tree/src/packages/@react-stately/tree/src/TreeCollection.ts","packages/@react-stately/tree/src/packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/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 */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;AAeA,4BAA4B,CAAC,CAAE,YAAW,WAAW,KAAK,CAAC,CAAC,CAAC;gBAM/C,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAC,YAAY,EAAC,GAAE;QAAC,YAAY,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;KAAM;IA2CnF,CAAC,MAAM,CAAC,QAAQ,CAAC;IAIlB,IAAI,IAAI,WAEP;IAED,OAAO;IAIP,YAAY,CAAC,GAAG,EAAE,GAAG;IAKrB,WAAW,CAAC,GAAG,EAAE,GAAG;IAKpB,WAAW;IAIX,UAAU;IAIV,OAAO,CAAC,GAAG,EAAE,GAAG;IAIhB,EAAE,CAAC,GAAG,EAAE,MAAM;CAIf;ACnFD,2BAA2B,CAAC,CAAE,SAAQ,oBAAoB,CAAC,CAAC,EAAE,UAAU,EAAE,iBAAiB;CAAG;AAC9F,2BAA2B,CAAC;IAC1B,yCAAyC;IACzC,QAAQ,CAAC,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC;IAEzC,iDAAiD;IACjD,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEhC,iDAAiD;IACjD,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEhC,yDAAyD;IACzD,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAE1B,yCAAyC;IACzC,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAEtC,uEAAuE;IACvE,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAA;CAC5C;AAED;;;GAGG;AACH,6BAA6B,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAkChF","sources":["packages/@react-stately/tree/src/packages/@react-stately/tree/src/TreeCollection.ts","packages/@react-stately/tree/src/packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/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 */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/tree",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,11 +22,11 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/collections": "^3.7.0",
26
- "@react-stately/selection": "^3.13.0",
27
- "@react-stately/utils": "^3.6.0",
28
- "@react-types/shared": "^3.18.0",
29
- "@swc/helpers": "^0.4.14"
25
+ "@react-stately/collections": "^3.9.0",
26
+ "@react-stately/selection": "^3.13.2",
27
+ "@react-stately/utils": "^3.7.0",
28
+ "@react-types/shared": "^3.18.1",
29
+ "@swc/helpers": "^0.5.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
@@ -34,5 +34,5 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "9d1ba9bd8ebcd63bf3495ade16d349bcb71795ce"
37
+ "gitHead": "504e40e0a50c1b20ed0fb3ba9561a263b6d5565e"
38
38
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {Collection, CollectionStateBase, Expandable, MultipleSelection, Node} from '@react-types/shared';
14
- import {Key, useEffect, useMemo} from 'react';
14
+ import {Key, useCallback, useEffect, useMemo} from 'react';
15
15
  import {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';
16
16
  import {TreeCollection} from './TreeCollection';
17
17
  import {useCollection} from '@react-stately/collections';
@@ -31,6 +31,9 @@ export interface TreeState<T> {
31
31
  /** Toggles the expanded state for an item by its key. */
32
32
  toggleKey(key: Key): void,
33
33
 
34
+ /** Replaces the set of expanded keys. */
35
+ setExpandedKeys(keys: Set<Key>): void,
36
+
34
37
  /** A selection manager to read and update multiple selection state. */
35
38
  readonly selectionManager: SelectionManager
36
39
  }
@@ -51,7 +54,7 @@ export function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T
51
54
  props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()
52
55
  , [props.disabledKeys]);
53
56
 
54
- let tree = useCollection(props, nodes => new TreeCollection(nodes, {expandedKeys}), null, [expandedKeys]);
57
+ let tree = useCollection(props, useCallback(nodes => new TreeCollection(nodes, {expandedKeys}), [expandedKeys]), null);
55
58
 
56
59
  // Reset focused key if that item is deleted from the collection.
57
60
  useEffect(() => {
@@ -70,6 +73,7 @@ export function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T
70
73
  expandedKeys,
71
74
  disabledKeys,
72
75
  toggleKey: onToggle,
76
+ setExpandedKeys,
73
77
  selectionManager: new SelectionManager(tree, selectionState)
74
78
  };
75
79
  }