@react-stately/selection 3.0.0-alpha.1 → 3.0.0-nightly-4980928d3-240906

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/types.d.ts CHANGED
@@ -1,52 +1,213 @@
1
- import { Key } from "react";
2
- import { SelectionMode, MultipleSelection } from "@react-types/shared";
3
- import { Collection } from "@react-stately/collections";
1
+ import { DisabledBehavior, FocusStrategy, Key, LongPressEvent, PressEvent, Selection, SelectionBehavior, SelectionMode, MultipleSelection, Collection, Node } from "@react-types/shared";
4
2
  export interface FocusState {
5
- isFocused: boolean;
3
+ /** Whether the collection is currently focused. */
4
+ readonly isFocused: boolean;
5
+ /** Sets whether the collection is focused. */
6
6
  setFocused(isFocused: boolean): void;
7
- focusedKey: Key;
8
- setFocusedKey(key: Key): void;
7
+ /** The current focused key in the collection. */
8
+ readonly focusedKey: Key;
9
+ /** Whether the first or last child of the focused key should receive focus. */
10
+ readonly childFocusStrategy: FocusStrategy;
11
+ /** Sets the focused key, and optionally, whether the first or last child of that key should receive focus. */
12
+ setFocusedKey(key: Key | null, child?: FocusStrategy): void;
9
13
  }
10
14
  export interface SingleSelectionState extends FocusState {
11
- selectedKey: Key;
12
- setSelectedKey(key: Key): void;
15
+ /** Whether the collection allows empty selection. */
16
+ readonly disallowEmptySelection?: boolean;
17
+ /** The currently selected key in the collection. */
18
+ readonly selectedKey: Key;
19
+ /** Sets the selected key in the collection. */
20
+ setSelectedKey(key: Key | null): void;
13
21
  }
14
22
  export interface MultipleSelectionState extends FocusState {
15
- selectionMode: SelectionMode;
16
- selectedKeys: Set<Key>;
17
- setSelectedKeys(keys: Set<Key> | ((v: Set<Key>) => Set<Key>)): void;
23
+ /** The type of selection that is allowed in the collection. */
24
+ readonly selectionMode: SelectionMode;
25
+ /** The selection behavior for the collection. */
26
+ readonly selectionBehavior: SelectionBehavior;
27
+ /** Sets the selection behavior for the collection. */
28
+ setSelectionBehavior(selectionBehavior: SelectionBehavior): void;
29
+ /** Whether the collection allows empty selection. */
30
+ readonly disallowEmptySelection: boolean;
31
+ /** The currently selected keys in the collection. */
32
+ readonly selectedKeys: Selection;
33
+ /** Sets the selected keys in the collection. */
34
+ setSelectedKeys(keys: Selection): void;
35
+ /** The currently disabled keys in the collection. */
36
+ readonly disabledKeys: Set<Key>;
37
+ /** Whether `disabledKeys` applies to selection, actions, or both. */
38
+ readonly disabledBehavior: DisabledBehavior;
18
39
  }
19
- export interface MultipleSelectionManager extends MultipleSelectionState {
40
+ export interface MultipleSelectionManager extends FocusState {
41
+ /** The type of selection that is allowed in the collection. */
42
+ readonly selectionMode: SelectionMode;
43
+ /** The selection behavior for the collection. */
44
+ readonly selectionBehavior: SelectionBehavior;
45
+ /** Whether the collection allows empty selection. */
46
+ readonly disallowEmptySelection?: boolean;
47
+ /** The currently selected keys in the collection. */
48
+ readonly selectedKeys: Set<Key>;
49
+ /** Whether the selection is empty. */
50
+ readonly isEmpty: boolean;
51
+ /** Whether all items in the collection are selected. */
52
+ readonly isSelectAll: boolean;
53
+ /** The first selected key in the collection. */
54
+ readonly firstSelectedKey: Key | null;
55
+ /** The last selected key in the collection. */
56
+ readonly lastSelectedKey: Key | null;
57
+ /** The currently disabled keys in the collection. */
58
+ readonly disabledKeys: Set<Key>;
59
+ /** Whether `disabledKeys` applies to selection, actions, or both. */
60
+ readonly disabledBehavior: DisabledBehavior;
61
+ /** Returns whether a key is selected. */
62
+ isSelected(key: Key): boolean;
63
+ /** Returns whether the current selection is equal to the given selection. */
64
+ isSelectionEqual(selection: Set<Key>): boolean;
65
+ /** Extends the selection to the given key. */
20
66
  extendSelection(toKey: Key): void;
67
+ /** Toggles whether the given key is selected. */
21
68
  toggleSelection(key: Key): void;
69
+ /** Replaces the selection with only the given key. */
22
70
  replaceSelection(key: Key): void;
71
+ /** Replaces the selection with the given keys. */
72
+ setSelectedKeys(keys: Iterable<Key>): void;
73
+ /** Selects all items in the collection. */
23
74
  selectAll(): void;
75
+ /** Removes all keys from the selection. */
24
76
  clearSelection(): void;
77
+ /** Toggles between select all and an empty selection. */
78
+ toggleSelectAll(): void;
79
+ /**
80
+ * Toggles, replaces, or extends selection to the given key depending
81
+ * on the pointer event and collection's selection mode.
82
+ */
83
+ select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void;
84
+ /** Returns whether the given key can be selected. */
85
+ canSelectItem(key: Key): boolean;
86
+ /** Returns whether the given key is non-interactive, i.e. both selection and actions are disabled. */
87
+ isDisabled(key: Key): boolean;
88
+ /** Sets the selection behavior for the collection. */
89
+ setSelectionBehavior(selectionBehavior: SelectionBehavior): void;
90
+ /** Returns whether the given key is a hyperlink. */
91
+ isLink(key: Key): boolean;
92
+ /** Returns the props for the given item. */
93
+ getItemProps(key: Key): any;
94
+ }
95
+ export interface MultipleSelectionStateProps extends MultipleSelection {
96
+ /** How multiple selection should behave in the collection. */
97
+ selectionBehavior?: SelectionBehavior;
98
+ /** Whether onSelectionChange should fire even if the new set of keys is the same as the last. */
99
+ allowDuplicateSelectionEvents?: boolean;
100
+ /** Whether `disabledKeys` applies to all interactions, or only selection. */
101
+ disabledBehavior?: DisabledBehavior;
25
102
  }
26
103
  /**
27
- * A Selection is a special Set containing Keys, which also has an anchor
28
- * and current selected key for use when range selecting.
104
+ * Manages state for multiple selection and focus in a collection.
29
105
  */
30
- declare class Selection extends Set<Key> {
31
- anchorKey: Key;
32
- currentKey: Key;
33
- constructor(keys?: Iterable<Key> | Selection, anchorKey?: Key, currentKey?: Key);
106
+ export function useMultipleSelectionState(props: MultipleSelectionStateProps): MultipleSelectionState;
107
+ interface SelectionManagerOptions {
108
+ allowsCellSelection?: boolean;
34
109
  }
35
- export function useMultipleSelectionState(props: MultipleSelection): MultipleSelectionState;
110
+ /**
111
+ * An interface for reading and updating multiple selection state.
112
+ */
36
113
  export class SelectionManager implements MultipleSelectionManager {
37
- constructor(collection: Collection<unknown>, state: MultipleSelectionState);
38
- readonly selectionMode: import("@react-types/shared").SelectionMode;
39
- readonly isFocused: boolean;
114
+ constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions);
115
+ /**
116
+ * The type of selection that is allowed in the collection.
117
+ */
118
+ get selectionMode(): SelectionMode;
119
+ /**
120
+ * Whether the collection allows empty selection.
121
+ */
122
+ get disallowEmptySelection(): boolean;
123
+ /**
124
+ * The selection behavior for the collection.
125
+ */
126
+ get selectionBehavior(): SelectionBehavior;
127
+ /**
128
+ * Sets the selection behavior for the collection.
129
+ */
130
+ setSelectionBehavior(selectionBehavior: SelectionBehavior): void;
131
+ /**
132
+ * Whether the collection is currently focused.
133
+ */
134
+ get isFocused(): boolean;
135
+ /**
136
+ * Sets whether the collection is focused.
137
+ */
40
138
  setFocused(isFocused: boolean): void;
41
- readonly focusedKey: Key;
42
- setFocusedKey(key: Key): void;
43
- readonly selectedKeys: Set<Key>;
44
- setSelectedKeys(keys: Selection): void;
139
+ /**
140
+ * The current focused key in the collection.
141
+ */
142
+ get focusedKey(): Key;
143
+ /** Whether the first or last child of the focused key should receive focus. */
144
+ get childFocusStrategy(): FocusStrategy;
145
+ /**
146
+ * Sets the focused key.
147
+ */
148
+ setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void;
149
+ /**
150
+ * The currently selected keys in the collection.
151
+ */
152
+ get selectedKeys(): Set<Key>;
153
+ /**
154
+ * The raw selection value for the collection.
155
+ * Either 'all' for select all, or a set of keys.
156
+ */
157
+ get rawSelection(): Selection;
158
+ /**
159
+ * Returns whether a key is selected.
160
+ */
161
+ isSelected(key: Key): boolean;
162
+ /**
163
+ * Whether the selection is empty.
164
+ */
165
+ get isEmpty(): boolean;
166
+ /**
167
+ * Whether all items in the collection are selected.
168
+ */
169
+ get isSelectAll(): boolean;
170
+ get firstSelectedKey(): Key | null;
171
+ get lastSelectedKey(): Key | null;
172
+ get disabledKeys(): Set<Key>;
173
+ get disabledBehavior(): DisabledBehavior;
174
+ /**
175
+ * Extends the selection to the given key.
176
+ */
45
177
  extendSelection(toKey: Key): void;
178
+ /**
179
+ * Toggles whether the given key is selected.
180
+ */
46
181
  toggleSelection(key: Key): void;
182
+ /**
183
+ * Replaces the selection with only the given key.
184
+ */
47
185
  replaceSelection(key: Key): void;
186
+ /**
187
+ * Replaces the selection with the given keys.
188
+ */
189
+ setSelectedKeys(keys: Iterable<Key>): void;
190
+ /**
191
+ * Selects all items in the collection.
192
+ */
48
193
  selectAll(): void;
194
+ /**
195
+ * Removes all keys from the selection.
196
+ */
49
197
  clearSelection(): void;
198
+ /**
199
+ * Toggles between select all and an empty selection.
200
+ */
201
+ toggleSelectAll(): void;
202
+ select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void;
203
+ /**
204
+ * Returns whether the current selection is equal to the given selection.
205
+ */
206
+ isSelectionEqual(selection: Set<Key>): boolean;
207
+ canSelectItem(key: Key): boolean;
208
+ isDisabled(key: Key): boolean;
209
+ isLink(key: Key): boolean;
210
+ getItemProps(key: Key): any;
50
211
  }
51
212
 
52
213
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/govett/dev/react-spectrum/packages/@react-stately/selection/src/packages/@react-stately/selection/src/types.ts","/Users/govett/dev/react-spectrum/packages/@react-stately/selection/src/packages/@react-stately/selection/src/Selection.ts","/Users/govett/dev/react-spectrum/packages/@react-stately/selection/src/packages/@react-stately/selection/src/useMultipleSelectionState.ts","/Users/govett/dev/react-spectrum/packages/@react-stately/selection/src/packages/@react-stately/selection/src/SelectionManager.ts"],"names":[],"mappings":";;;AAeA;IACE,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IACrC,UAAU,EAAE,GAAG,CAAC;IAChB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;CAC/B;AAED,qCAAsC,SAAQ,UAAU;IACtD,WAAW,EAAE,GAAG,CAAC;IACjB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,I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;IAatB,UAAU,CAAC,GAAG,EAAE,GAAG;IAInB,MAAM,CAAC,GAAG,EAAE,GAAG;IAIf,YAAY,CAAC,GAAG,EAAE,GAAG;CAGtB","sources":["packages/@react-stately/selection/src/packages/@react-stately/selection/src/types.ts","packages/@react-stately/selection/src/packages/@react-stately/selection/src/Selection.ts","packages/@react-stately/selection/src/packages/@react-stately/selection/src/useMultipleSelectionState.ts","packages/@react-stately/selection/src/packages/@react-stately/selection/src/SelectionManager.ts","packages/@react-stately/selection/src/packages/@react-stately/selection/src/index.ts","packages/@react-stately/selection/src/index.ts"],"sourcesContent":[null,null,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 type {MultipleSelectionStateProps} from './useMultipleSelectionState';\nexport type {FocusState, SingleSelectionState, MultipleSelectionState, MultipleSelectionManager} from './types';\nexport {useMultipleSelectionState} from './useMultipleSelectionState';\nexport {SelectionManager} from './SelectionManager';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -0,0 +1,101 @@
1
+ var $21c847070f1f9569$exports = require("./Selection.main.js");
2
+ var $byFPT$reactstatelyutils = require("@react-stately/utils");
3
+ var $byFPT$react = require("react");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "useMultipleSelectionState", () => $1adc19da2128bba9$export$253fe78d46329472);
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ function $1adc19da2128bba9$var$equalSets(setA, setB) {
25
+ if (setA.size !== setB.size) return false;
26
+ for (let item of setA){
27
+ if (!setB.has(item)) return false;
28
+ }
29
+ return true;
30
+ }
31
+ function $1adc19da2128bba9$export$253fe78d46329472(props) {
32
+ let { selectionMode: selectionMode = 'none', disallowEmptySelection: disallowEmptySelection, allowDuplicateSelectionEvents: allowDuplicateSelectionEvents, selectionBehavior: selectionBehaviorProp = 'toggle', disabledBehavior: disabledBehavior = 'all' } = props;
33
+ // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.
34
+ // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).
35
+ let isFocusedRef = (0, $byFPT$react.useRef)(false);
36
+ let [, setFocused] = (0, $byFPT$react.useState)(false);
37
+ let focusedKeyRef = (0, $byFPT$react.useRef)(null);
38
+ let childFocusStrategyRef = (0, $byFPT$react.useRef)(null);
39
+ let [, setFocusedKey] = (0, $byFPT$react.useState)(null);
40
+ let selectedKeysProp = (0, $byFPT$react.useMemo)(()=>$1adc19da2128bba9$var$convertSelection(props.selectedKeys), [
41
+ props.selectedKeys
42
+ ]);
43
+ let defaultSelectedKeys = (0, $byFPT$react.useMemo)(()=>$1adc19da2128bba9$var$convertSelection(props.defaultSelectedKeys, new (0, $21c847070f1f9569$exports.Selection)()), [
44
+ props.defaultSelectedKeys
45
+ ]);
46
+ let [selectedKeys, setSelectedKeys] = (0, $byFPT$reactstatelyutils.useControlledState)(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
47
+ let disabledKeysProp = (0, $byFPT$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
48
+ props.disabledKeys
49
+ ]);
50
+ let [selectionBehavior, setSelectionBehavior] = (0, $byFPT$react.useState)(selectionBehaviorProp);
51
+ // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press
52
+ // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
53
+ if (selectionBehaviorProp === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) setSelectionBehavior('replace');
54
+ // If the selectionBehavior prop changes, update the state as well.
55
+ let lastSelectionBehavior = (0, $byFPT$react.useRef)(selectionBehaviorProp);
56
+ (0, $byFPT$react.useEffect)(()=>{
57
+ if (selectionBehaviorProp !== lastSelectionBehavior.current) {
58
+ setSelectionBehavior(selectionBehaviorProp);
59
+ lastSelectionBehavior.current = selectionBehaviorProp;
60
+ }
61
+ }, [
62
+ selectionBehaviorProp
63
+ ]);
64
+ return {
65
+ selectionMode: selectionMode,
66
+ disallowEmptySelection: disallowEmptySelection,
67
+ selectionBehavior: selectionBehavior,
68
+ setSelectionBehavior: setSelectionBehavior,
69
+ get isFocused () {
70
+ return isFocusedRef.current;
71
+ },
72
+ setFocused (f) {
73
+ isFocusedRef.current = f;
74
+ setFocused(f);
75
+ },
76
+ get focusedKey () {
77
+ return focusedKeyRef.current;
78
+ },
79
+ get childFocusStrategy () {
80
+ return childFocusStrategyRef.current;
81
+ },
82
+ setFocusedKey (k, childFocusStrategy = 'first') {
83
+ focusedKeyRef.current = k;
84
+ childFocusStrategyRef.current = childFocusStrategy;
85
+ setFocusedKey(k);
86
+ },
87
+ selectedKeys: selectedKeys,
88
+ setSelectedKeys (keys) {
89
+ if (allowDuplicateSelectionEvents || !$1adc19da2128bba9$var$equalSets(keys, selectedKeys)) setSelectedKeys(keys);
90
+ },
91
+ disabledKeys: disabledKeysProp,
92
+ disabledBehavior: disabledBehavior
93
+ };
94
+ }
95
+ function $1adc19da2128bba9$var$convertSelection(selection, defaultValue) {
96
+ if (!selection) return defaultValue;
97
+ return selection === 'all' ? 'all' : new (0, $21c847070f1f9569$exports.Selection)(selection);
98
+ }
99
+
100
+
101
+ //# sourceMappingURL=useMultipleSelectionState.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAQD,SAAS,gCAAU,IAAI,EAAE,IAAI;IAC3B,IAAI,KAAK,IAAI,KAAK,KAAK,IAAI,EACzB,OAAO;IAGT,KAAK,IAAI,QAAQ,KAAM;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,OACZ,OAAO;IAEX;IAEA,OAAO;AACT;AAcO,SAAS,0CAA0B,KAAkC;IAC1E,IAAI,iBACF,gBAAgB,gCAChB,sBAAsB,iCACtB,6BAA6B,EAC7B,mBAAmB,wBAAwB,QAAQ,oBACnD,mBAAmB,OACpB,GAAG;IAEJ,8FAA8F;IAC9F,kGAAkG;IAClG,IAAI,eAAe,CAAA,GAAA,mBAAK,EAAE;IAC1B,IAAI,GAAG,WAAW,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC9B,IAAI,gBAAgB,CAAA,GAAA,mBAAK,EAAE;IAC3B,IAAI,wBAAwB,CAAA,GAAA,mBAAK,EAAE;IACnC,IAAI,GAAG,cAAc,GAAG,CAAA,GAAA,qBAAO,EAAE;IACjC,IAAI,mBAAmB,CAAA,GAAA,oBAAM,EAAE,IAAM,uCAAiB,MAAM,YAAY,GAAG;QAAC,MAAM,YAAY;KAAC;IAC/F,IAAI,sBAAsB,CAAA,GAAA,oBAAM,EAAE,IAAM,uCAAiB,MAAM,mBAAmB,EAAE,IAAI,CAAA,GAAA,mCAAQ,MAAM;QAAC,MAAM,mBAAmB;KAAC;IACjI,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,2CAAiB,EACrD,kBACA,qBACA,MAAM,iBAAiB;IAEzB,IAAI,mBAAmB,CAAA,GAAA,oBAAM,EAAE,IAC7B,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OACvD;QAAC,MAAM,YAAY;KAAC;IACtB,IAAI,CAAC,mBAAmB,qBAAqB,GAAG,CAAA,GAAA,qBAAO,EAAE;IAEzD,2GAA2G;IAC3G,oGAAoG;IACpG,IAAI,0BAA0B,aAAa,sBAAsB,YAAY,OAAO,iBAAiB,YAAY,aAAa,IAAI,KAAK,GACrI,qBAAqB;IAGvB,mEAAmE;IACnE,IAAI,wBAAwB,CAAA,GAAA,mBAAK,EAAE;IACnC,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,0BAA0B,sBAAsB,OAAO,EAAE;YAC3D,qBAAqB;YACrB,sBAAsB,OAAO,GAAG;QAClC;IACF,GAAG;QAAC;KAAsB;IAE1B,OAAO;uBACL;gCACA;2BACA;8BACA;QACA,IAAI,aAAY;YACd,OAAO,aAAa,OAAO;QAC7B;QACA,YAAW,CAAC;YACV,aAAa,OAAO,GAAG;YACvB,WAAW;QACb;QACA,IAAI,cAAa;YACf,OAAO,cAAc,OAAO;QAC9B;QACA,IAAI,sBAAqB;YACvB,OAAO,sBAAsB,OAAO;QACtC;QACA,eAAc,CAAC,EAAE,qBAAqB,OAAO;YAC3C,cAAc,OAAO,GAAG;YACxB,sBAAsB,OAAO,GAAG;YAChC,cAAc;QAChB;sBACA;QACA,iBAAgB,IAAI;YAClB,IAAI,iCAAiC,CAAC,gCAAU,MAAM,eACpD,gBAAgB;QAEpB;QACA,cAAc;0BACd;IACF;AACF;AAEA,SAAS,uCAAiB,SAAgC,EAAE,YAAwB;IAClF,IAAI,CAAC,WACH,OAAO;IAGT,OAAO,cAAc,QACjB,QACA,IAAI,CAAA,GAAA,mCAAQ,EAAE;AACpB","sources":["packages/@react-stately/selection/src/useMultipleSelectionState.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 {DisabledBehavior, Key, MultipleSelection, SelectionBehavior, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\n\nfunction equalSets(setA, setB) {\n if (setA.size !== setB.size) {\n return false;\n }\n\n for (let item of setA) {\n if (!setB.has(item)) {\n return false;\n }\n }\n\n return true;\n}\n\nexport interface MultipleSelectionStateProps extends MultipleSelection {\n /** How multiple selection should behave in the collection. */\n selectionBehavior?: SelectionBehavior,\n /** Whether onSelectionChange should fire even if the new set of keys is the same as the last. */\n allowDuplicateSelectionEvents?: boolean,\n /** Whether `disabledKeys` applies to all interactions, or only selection. */\n disabledBehavior?: DisabledBehavior\n}\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(props: MultipleSelectionStateProps): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection,\n allowDuplicateSelectionEvents,\n selectionBehavior: selectionBehaviorProp = 'toggle',\n disabledBehavior = 'all'\n } = props;\n\n // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n let isFocusedRef = useRef(false);\n let [, setFocused] = useState(false);\n let focusedKeyRef = useRef(null);\n let childFocusStrategyRef = useRef(null);\n let [, setFocusedKey] = useState(null);\n let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n let defaultSelectedKeys = useMemo(() => convertSelection(props.defaultSelectedKeys, new Selection()), [props.defaultSelectedKeys]);\n let [selectedKeys, setSelectedKeys] = useControlledState(\n selectedKeysProp,\n defaultSelectedKeys,\n props.onSelectionChange\n );\n let disabledKeysProp = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n let [selectionBehavior, setSelectionBehavior] = useState(selectionBehaviorProp);\n\n // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press\n // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.\n if (selectionBehaviorProp === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) {\n setSelectionBehavior('replace');\n }\n\n // If the selectionBehavior prop changes, update the state as well.\n let lastSelectionBehavior = useRef(selectionBehaviorProp);\n useEffect(() => {\n if (selectionBehaviorProp !== lastSelectionBehavior.current) {\n setSelectionBehavior(selectionBehaviorProp);\n lastSelectionBehavior.current = selectionBehaviorProp;\n }\n }, [selectionBehaviorProp]);\n\n return {\n selectionMode,\n disallowEmptySelection,\n selectionBehavior,\n setSelectionBehavior,\n get isFocused() {\n return isFocusedRef.current;\n },\n setFocused(f) {\n isFocusedRef.current = f;\n setFocused(f);\n },\n get focusedKey() {\n return focusedKeyRef.current;\n },\n get childFocusStrategy() {\n return childFocusStrategyRef.current;\n },\n setFocusedKey(k, childFocusStrategy = 'first') {\n focusedKeyRef.current = k;\n childFocusStrategyRef.current = childFocusStrategy;\n setFocusedKey(k);\n },\n selectedKeys,\n setSelectedKeys(keys) {\n if (allowDuplicateSelectionEvents || !equalSets(keys, selectedKeys)) {\n setSelectedKeys(keys);\n }\n },\n disabledKeys: disabledKeysProp,\n disabledBehavior\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Set<Key> {\n if (!selection) {\n return defaultValue;\n }\n\n return selection === 'all'\n ? 'all'\n : new Selection(selection);\n}\n"],"names":[],"version":3,"file":"useMultipleSelectionState.main.js.map"}
@@ -0,0 +1,96 @@
1
+ import {Selection as $e40ea825a81a3709$export$52baac22726c72bf} from "./Selection.mjs";
2
+ import {useControlledState as $6tM1y$useControlledState} from "@react-stately/utils";
3
+ import {useRef as $6tM1y$useRef, useState as $6tM1y$useState, useMemo as $6tM1y$useMemo, useEffect as $6tM1y$useEffect} from "react";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $7af3f5b51489e0b5$var$equalSets(setA, setB) {
19
+ if (setA.size !== setB.size) return false;
20
+ for (let item of setA){
21
+ if (!setB.has(item)) return false;
22
+ }
23
+ return true;
24
+ }
25
+ function $7af3f5b51489e0b5$export$253fe78d46329472(props) {
26
+ let { selectionMode: selectionMode = 'none', disallowEmptySelection: disallowEmptySelection, allowDuplicateSelectionEvents: allowDuplicateSelectionEvents, selectionBehavior: selectionBehaviorProp = 'toggle', disabledBehavior: disabledBehavior = 'all' } = props;
27
+ // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.
28
+ // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).
29
+ let isFocusedRef = (0, $6tM1y$useRef)(false);
30
+ let [, setFocused] = (0, $6tM1y$useState)(false);
31
+ let focusedKeyRef = (0, $6tM1y$useRef)(null);
32
+ let childFocusStrategyRef = (0, $6tM1y$useRef)(null);
33
+ let [, setFocusedKey] = (0, $6tM1y$useState)(null);
34
+ let selectedKeysProp = (0, $6tM1y$useMemo)(()=>$7af3f5b51489e0b5$var$convertSelection(props.selectedKeys), [
35
+ props.selectedKeys
36
+ ]);
37
+ let defaultSelectedKeys = (0, $6tM1y$useMemo)(()=>$7af3f5b51489e0b5$var$convertSelection(props.defaultSelectedKeys, new (0, $e40ea825a81a3709$export$52baac22726c72bf)()), [
38
+ props.defaultSelectedKeys
39
+ ]);
40
+ let [selectedKeys, setSelectedKeys] = (0, $6tM1y$useControlledState)(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
41
+ let disabledKeysProp = (0, $6tM1y$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
42
+ props.disabledKeys
43
+ ]);
44
+ let [selectionBehavior, setSelectionBehavior] = (0, $6tM1y$useState)(selectionBehaviorProp);
45
+ // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press
46
+ // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
47
+ if (selectionBehaviorProp === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) setSelectionBehavior('replace');
48
+ // If the selectionBehavior prop changes, update the state as well.
49
+ let lastSelectionBehavior = (0, $6tM1y$useRef)(selectionBehaviorProp);
50
+ (0, $6tM1y$useEffect)(()=>{
51
+ if (selectionBehaviorProp !== lastSelectionBehavior.current) {
52
+ setSelectionBehavior(selectionBehaviorProp);
53
+ lastSelectionBehavior.current = selectionBehaviorProp;
54
+ }
55
+ }, [
56
+ selectionBehaviorProp
57
+ ]);
58
+ return {
59
+ selectionMode: selectionMode,
60
+ disallowEmptySelection: disallowEmptySelection,
61
+ selectionBehavior: selectionBehavior,
62
+ setSelectionBehavior: setSelectionBehavior,
63
+ get isFocused () {
64
+ return isFocusedRef.current;
65
+ },
66
+ setFocused (f) {
67
+ isFocusedRef.current = f;
68
+ setFocused(f);
69
+ },
70
+ get focusedKey () {
71
+ return focusedKeyRef.current;
72
+ },
73
+ get childFocusStrategy () {
74
+ return childFocusStrategyRef.current;
75
+ },
76
+ setFocusedKey (k, childFocusStrategy = 'first') {
77
+ focusedKeyRef.current = k;
78
+ childFocusStrategyRef.current = childFocusStrategy;
79
+ setFocusedKey(k);
80
+ },
81
+ selectedKeys: selectedKeys,
82
+ setSelectedKeys (keys) {
83
+ if (allowDuplicateSelectionEvents || !$7af3f5b51489e0b5$var$equalSets(keys, selectedKeys)) setSelectedKeys(keys);
84
+ },
85
+ disabledKeys: disabledKeysProp,
86
+ disabledBehavior: disabledBehavior
87
+ };
88
+ }
89
+ function $7af3f5b51489e0b5$var$convertSelection(selection, defaultValue) {
90
+ if (!selection) return defaultValue;
91
+ return selection === 'all' ? 'all' : new (0, $e40ea825a81a3709$export$52baac22726c72bf)(selection);
92
+ }
93
+
94
+
95
+ export {$7af3f5b51489e0b5$export$253fe78d46329472 as useMultipleSelectionState};
96
+ //# sourceMappingURL=useMultipleSelectionState.module.js.map
@@ -0,0 +1,96 @@
1
+ import {Selection as $e40ea825a81a3709$export$52baac22726c72bf} from "./Selection.module.js";
2
+ import {useControlledState as $6tM1y$useControlledState} from "@react-stately/utils";
3
+ import {useRef as $6tM1y$useRef, useState as $6tM1y$useState, useMemo as $6tM1y$useMemo, useEffect as $6tM1y$useEffect} from "react";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $7af3f5b51489e0b5$var$equalSets(setA, setB) {
19
+ if (setA.size !== setB.size) return false;
20
+ for (let item of setA){
21
+ if (!setB.has(item)) return false;
22
+ }
23
+ return true;
24
+ }
25
+ function $7af3f5b51489e0b5$export$253fe78d46329472(props) {
26
+ let { selectionMode: selectionMode = 'none', disallowEmptySelection: disallowEmptySelection, allowDuplicateSelectionEvents: allowDuplicateSelectionEvents, selectionBehavior: selectionBehaviorProp = 'toggle', disabledBehavior: disabledBehavior = 'all' } = props;
27
+ // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.
28
+ // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).
29
+ let isFocusedRef = (0, $6tM1y$useRef)(false);
30
+ let [, setFocused] = (0, $6tM1y$useState)(false);
31
+ let focusedKeyRef = (0, $6tM1y$useRef)(null);
32
+ let childFocusStrategyRef = (0, $6tM1y$useRef)(null);
33
+ let [, setFocusedKey] = (0, $6tM1y$useState)(null);
34
+ let selectedKeysProp = (0, $6tM1y$useMemo)(()=>$7af3f5b51489e0b5$var$convertSelection(props.selectedKeys), [
35
+ props.selectedKeys
36
+ ]);
37
+ let defaultSelectedKeys = (0, $6tM1y$useMemo)(()=>$7af3f5b51489e0b5$var$convertSelection(props.defaultSelectedKeys, new (0, $e40ea825a81a3709$export$52baac22726c72bf)()), [
38
+ props.defaultSelectedKeys
39
+ ]);
40
+ let [selectedKeys, setSelectedKeys] = (0, $6tM1y$useControlledState)(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
41
+ let disabledKeysProp = (0, $6tM1y$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
42
+ props.disabledKeys
43
+ ]);
44
+ let [selectionBehavior, setSelectionBehavior] = (0, $6tM1y$useState)(selectionBehaviorProp);
45
+ // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press
46
+ // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
47
+ if (selectionBehaviorProp === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) setSelectionBehavior('replace');
48
+ // If the selectionBehavior prop changes, update the state as well.
49
+ let lastSelectionBehavior = (0, $6tM1y$useRef)(selectionBehaviorProp);
50
+ (0, $6tM1y$useEffect)(()=>{
51
+ if (selectionBehaviorProp !== lastSelectionBehavior.current) {
52
+ setSelectionBehavior(selectionBehaviorProp);
53
+ lastSelectionBehavior.current = selectionBehaviorProp;
54
+ }
55
+ }, [
56
+ selectionBehaviorProp
57
+ ]);
58
+ return {
59
+ selectionMode: selectionMode,
60
+ disallowEmptySelection: disallowEmptySelection,
61
+ selectionBehavior: selectionBehavior,
62
+ setSelectionBehavior: setSelectionBehavior,
63
+ get isFocused () {
64
+ return isFocusedRef.current;
65
+ },
66
+ setFocused (f) {
67
+ isFocusedRef.current = f;
68
+ setFocused(f);
69
+ },
70
+ get focusedKey () {
71
+ return focusedKeyRef.current;
72
+ },
73
+ get childFocusStrategy () {
74
+ return childFocusStrategyRef.current;
75
+ },
76
+ setFocusedKey (k, childFocusStrategy = 'first') {
77
+ focusedKeyRef.current = k;
78
+ childFocusStrategyRef.current = childFocusStrategy;
79
+ setFocusedKey(k);
80
+ },
81
+ selectedKeys: selectedKeys,
82
+ setSelectedKeys (keys) {
83
+ if (allowDuplicateSelectionEvents || !$7af3f5b51489e0b5$var$equalSets(keys, selectedKeys)) setSelectedKeys(keys);
84
+ },
85
+ disabledKeys: disabledKeysProp,
86
+ disabledBehavior: disabledBehavior
87
+ };
88
+ }
89
+ function $7af3f5b51489e0b5$var$convertSelection(selection, defaultValue) {
90
+ if (!selection) return defaultValue;
91
+ return selection === 'all' ? 'all' : new (0, $e40ea825a81a3709$export$52baac22726c72bf)(selection);
92
+ }
93
+
94
+
95
+ export {$7af3f5b51489e0b5$export$253fe78d46329472 as useMultipleSelectionState};
96
+ //# sourceMappingURL=useMultipleSelectionState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAQD,SAAS,gCAAU,IAAI,EAAE,IAAI;IAC3B,IAAI,KAAK,IAAI,KAAK,KAAK,IAAI,EACzB,OAAO;IAGT,KAAK,IAAI,QAAQ,KAAM;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,OACZ,OAAO;IAEX;IAEA,OAAO;AACT;AAcO,SAAS,0CAA0B,KAAkC;IAC1E,IAAI,iBACF,gBAAgB,gCAChB,sBAAsB,iCACtB,6BAA6B,EAC7B,mBAAmB,wBAAwB,QAAQ,oBACnD,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AO;QAC7B;QACA,YAAW,CAAC;YACV,aAAa,OAAO,GAAG;YACvB,WAAW;QACb;QACA,IAAI,cAAa;YACf,OAAO,cAAc,OAAO;QAC9B;QACA,IAAI,sBAAqB;YACvB,OAAO,sBAAsB,OAAO;QACtC;QACA,eAAc,CAAC,EAAE,qBAAqB,OAAO;YAC3C,cAAc,OAAO,GAAG;YACxB,sBAAsB,OAAO,GAAG;YAChC,cAAc;QAChB;sBACA;QACA,iBAAgB,IAAI;YAClB,IAAI,iCAAiC,CAAC,gCAAU,MAAM,eACpD,gBAAgB;QAEpB;QACA,cAAc;0BACd;IACF;AACF;AAEA,SAAS,uCAAiB,SAAgC,EAAE,YAAwB;IAClF,IAAI,CAAC,WACH,OAAO;IAGT,OAAO,cAAc,QACjB,QACA,IAAI,CAAA,GAAA,yCAAQ,EAAE;AACpB","sources":["packages/@react-stately/selection/src/useMultipleSelectionState.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 {DisabledBehavior, Key, MultipleSelection, SelectionBehavior, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\n\nfunction equalSets(setA, setB) {\n if (setA.size !== setB.size) {\n return false;\n }\n\n for (let item of setA) {\n if (!setB.has(item)) {\n return false;\n }\n }\n\n return true;\n}\n\nexport interface MultipleSelectionStateProps extends MultipleSelection {\n /** How multiple selection should behave in the collection. */\n selectionBehavior?: SelectionBehavior,\n /** Whether onSelectionChange should fire even if the new set of keys is the same as the last. */\n allowDuplicateSelectionEvents?: boolean,\n /** Whether `disabledKeys` applies to all interactions, or only selection. */\n disabledBehavior?: DisabledBehavior\n}\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(props: MultipleSelectionStateProps): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection,\n allowDuplicateSelectionEvents,\n selectionBehavior: selectionBehaviorProp = 'toggle',\n disabledBehavior = 'all'\n } = props;\n\n // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n let isFocusedRef = useRef(false);\n let [, setFocused] = useState(false);\n let focusedKeyRef = useRef(null);\n let childFocusStrategyRef = useRef(null);\n let [, setFocusedKey] = useState(null);\n let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n let defaultSelectedKeys = useMemo(() => convertSelection(props.defaultSelectedKeys, new Selection()), [props.defaultSelectedKeys]);\n let [selectedKeys, setSelectedKeys] = useControlledState(\n selectedKeysProp,\n defaultSelectedKeys,\n props.onSelectionChange\n );\n let disabledKeysProp = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n let [selectionBehavior, setSelectionBehavior] = useState(selectionBehaviorProp);\n\n // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press\n // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.\n if (selectionBehaviorProp === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) {\n setSelectionBehavior('replace');\n }\n\n // If the selectionBehavior prop changes, update the state as well.\n let lastSelectionBehavior = useRef(selectionBehaviorProp);\n useEffect(() => {\n if (selectionBehaviorProp !== lastSelectionBehavior.current) {\n setSelectionBehavior(selectionBehaviorProp);\n lastSelectionBehavior.current = selectionBehaviorProp;\n }\n }, [selectionBehaviorProp]);\n\n return {\n selectionMode,\n disallowEmptySelection,\n selectionBehavior,\n setSelectionBehavior,\n get isFocused() {\n return isFocusedRef.current;\n },\n setFocused(f) {\n isFocusedRef.current = f;\n setFocused(f);\n },\n get focusedKey() {\n return focusedKeyRef.current;\n },\n get childFocusStrategy() {\n return childFocusStrategyRef.current;\n },\n setFocusedKey(k, childFocusStrategy = 'first') {\n focusedKeyRef.current = k;\n childFocusStrategyRef.current = childFocusStrategy;\n setFocusedKey(k);\n },\n selectedKeys,\n setSelectedKeys(keys) {\n if (allowDuplicateSelectionEvents || !equalSets(keys, selectedKeys)) {\n setSelectedKeys(keys);\n }\n },\n disabledKeys: disabledKeysProp,\n disabledBehavior\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Set<Key> {\n if (!selection) {\n return defaultValue;\n }\n\n return selection === 'all'\n ? 'all'\n : new Selection(selection);\n}\n"],"names":[],"version":3,"file":"useMultipleSelectionState.module.js.map"}
package/package.json CHANGED
@@ -1,30 +1,37 @@
1
1
  {
2
2
  "name": "@react-stately/selection",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-nightly-4980928d3-240906",
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
+ "exports": {
9
+ "types": "./dist/types.d.ts",
10
+ "import": "./dist/import.mjs",
11
+ "require": "./dist/main.js"
12
+ },
8
13
  "types": "dist/types.d.ts",
9
14
  "source": "src/index.ts",
10
15
  "files": [
11
- "dist"
16
+ "dist",
17
+ "src"
12
18
  ],
13
19
  "sideEffects": false,
14
20
  "repository": {
15
21
  "type": "git",
16
- "url": "https://github.com/adobe-private/react-spectrum-v3"
22
+ "url": "https://github.com/adobe/react-spectrum"
17
23
  },
18
24
  "dependencies": {
19
- "@babel/runtime": "^7.6.2",
20
- "@react-stately/collections": "^3.0.0-alpha.1",
21
- "@react-stately/utils": "^3.0.0-rc.2"
25
+ "@react-stately/collections": "^3.0.0-nightly-4980928d3-240906",
26
+ "@react-stately/utils": "^3.0.0-nightly-4980928d3-240906",
27
+ "@react-types/shared": "^3.0.0-nightly-4980928d3-240906",
28
+ "@swc/helpers": "^0.5.0"
22
29
  },
23
30
  "peerDependencies": {
24
- "react": "^16.8.0"
31
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
25
32
  },
26
33
  "publishConfig": {
27
34
  "access": "public"
28
35
  },
29
- "gitHead": "207e6ee9076905c96638a7f81a367758872e1410"
30
- }
36
+ "stableVersion": "3.16.2"
37
+ }