@react-types/shared 3.17.0 → 3.18.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-types/shared",
3
- "version": "3.17.0",
3
+ "version": "3.18.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "types": "src/index.d.ts",
@@ -14,5 +14,5 @@
14
14
  "publishConfig": {
15
15
  "access": "public"
16
16
  },
17
- "gitHead": "a0efee84aa178cb1a202951dfd6d8de02b292307"
17
+ "gitHead": "9d1ba9bd8ebcd63bf3495ade16d349bcb71795ce"
18
18
  }
@@ -62,6 +62,11 @@ export interface CollectionBase<T> {
62
62
  disabledKeys?: Iterable<Key>
63
63
  }
64
64
 
65
+ export interface CollectionStateBase<T, C extends Collection<Node<T>> = Collection<Node<T>>> extends Partial<CollectionBase<T>> {
66
+ /** A pre-constructed collection to use instead of building one from items and children. */
67
+ collection?: C
68
+ }
69
+
65
70
  export interface Expandable {
66
71
  /** The currently expanded keys in the collection (controlled). */
67
72
  expandedKeys?: Iterable<Key>,
@@ -128,10 +133,10 @@ export interface Collection<T> extends Iterable<T> {
128
133
  getKeys(): Iterable<Key>,
129
134
 
130
135
  /** Get an item by its key. */
131
- getItem(key: Key): T,
136
+ getItem(key: Key): T | null,
132
137
 
133
138
  /** Get an item by the index of its key. */
134
- at(idx: number): T,
139
+ at(idx: number): T | null,
135
140
 
136
141
  /** Get the key that comes before the given key in the collection. */
137
142
  getKeyBefore(key: Key): Key | null,
@@ -143,7 +148,13 @@ export interface Collection<T> extends Iterable<T> {
143
148
  getFirstKey(): Key | null,
144
149
 
145
150
  /** Get the last key in the collection. */
146
- getLastKey(): Key | null
151
+ getLastKey(): Key | null,
152
+
153
+ /** Iterate over the child items of the given key. */
154
+ getChildren?(key: Key): Iterable<T>,
155
+
156
+ /** Returns a string representation of the item's contents. */
157
+ getTextValue?(key: Key): string
147
158
  }
148
159
 
149
160
  export interface Node<T> {
@@ -152,12 +163,15 @@ export interface Node<T> {
152
163
  /** A unique key for the node. */
153
164
  key: Key,
154
165
  /** The object value the node was created from. */
155
- value: T,
166
+ value: T | null,
156
167
  /** The level of depth this node is at in the heirarchy. */
157
168
  level: number,
158
169
  /** Whether this item has children, even if not loaded yet. */
159
170
  hasChildNodes: boolean,
160
- /** The loaded children of this node. */
171
+ /**
172
+ * The loaded children of this node.
173
+ * @deprecated Use `collection.getChildren(node.key)` instead.
174
+ */
161
175
  childNodes: Iterable<Node<T>>,
162
176
  /** The rendered contents of this node (e.g. JSX). */
163
177
  rendered: ReactNode,
@@ -170,11 +184,11 @@ export interface Node<T> {
170
184
  /** A function that should be called to wrap the rendered node. */
171
185
  wrapper?: (element: ReactElement) => ReactElement,
172
186
  /** The key of the parent node. */
173
- parentKey?: Key,
187
+ parentKey?: Key | null,
174
188
  /** The key of the node before this node. */
175
- prevKey?: Key,
189
+ prevKey?: Key | null,
176
190
  /** The key of the node after this node. */
177
- nextKey?: Key,
191
+ nextKey?: Key | null,
178
192
  /** Additional properties specific to a particular node type. */
179
193
  props?: any,
180
194
  /** @private */