@okam/stack-ui 1.42.1 → 1.42.3

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.
Files changed (181) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/components/ShareButton/interface.d.ts +0 -1
  3. package/index100.js +1 -1
  4. package/index100.mjs +1 -1
  5. package/index101.js +1 -1
  6. package/index101.mjs +1 -1
  7. package/index102.js +1 -1
  8. package/index102.mjs +1 -1
  9. package/index151.js +1 -1
  10. package/index151.mjs +1 -1
  11. package/index153.js +1 -1
  12. package/index153.mjs +4 -4
  13. package/index154.js +1 -1
  14. package/index154.mjs +2 -2
  15. package/index155.js +1 -1
  16. package/index155.mjs +1 -1
  17. package/index156.js +1 -1
  18. package/index156.mjs +1 -1
  19. package/index161.js +1 -1
  20. package/index161.mjs +2 -2
  21. package/index163.js +1 -1
  22. package/index163.mjs +2 -2
  23. package/index164.js +1 -1
  24. package/index164.mjs +5 -5
  25. package/index165.js +1 -1
  26. package/index165.mjs +3 -3
  27. package/index167.js +1 -1
  28. package/index167.mjs +2 -2
  29. package/index172.js +1 -1
  30. package/index172.mjs +2 -2
  31. package/index176.js +1 -1
  32. package/index176.mjs +4 -4
  33. package/index177.js +1 -1
  34. package/index177.mjs +1 -1
  35. package/index178.js +1 -1
  36. package/index178.mjs +2 -2
  37. package/index179.js +1 -1
  38. package/index179.mjs +3 -3
  39. package/index181.js +1 -1
  40. package/index181.mjs +3 -3
  41. package/index187.js +1 -1
  42. package/index187.mjs +5 -11
  43. package/index188.js +2 -1
  44. package/index188.mjs +49 -5
  45. package/index189.js +1 -2
  46. package/index189.mjs +11 -49
  47. package/index232.js +1 -1
  48. package/index232.mjs +132 -117
  49. package/index233.js +1 -1
  50. package/index233.mjs +196 -26
  51. package/index234.js +1 -1
  52. package/index234.mjs +18 -69
  53. package/index235.js +1 -1
  54. package/index235.mjs +4 -382
  55. package/index236.js +1 -1
  56. package/index236.mjs +28 -46
  57. package/index237.js +1 -1
  58. package/index237.mjs +50 -4
  59. package/index238.js +1 -1
  60. package/index238.mjs +52 -22
  61. package/index239.js +1 -1
  62. package/index239.mjs +46 -45
  63. package/index240.js +1 -1
  64. package/index240.mjs +96 -4
  65. package/index241.js +1 -1
  66. package/index241.mjs +5 -24
  67. package/index242.js +1 -1
  68. package/index242.mjs +6 -12
  69. package/index243.js +1 -1
  70. package/index243.mjs +41 -4
  71. package/index244.js +1 -1
  72. package/index244.mjs +72 -15
  73. package/index245.js +1 -1
  74. package/index245.mjs +14 -42
  75. package/index246.js +1 -1
  76. package/index246.mjs +66 -55
  77. package/index247.js +1 -1
  78. package/index247.mjs +7 -41
  79. package/index248.js +1 -1
  80. package/index248.mjs +10 -27
  81. package/index249.js +1 -1
  82. package/index249.mjs +46 -30
  83. package/index250.js +1 -1
  84. package/index250.mjs +124 -13
  85. package/index251.js +1 -1
  86. package/index251.mjs +73 -10
  87. package/index252.js +1 -1
  88. package/index252.mjs +378 -25
  89. package/index253.js +1 -1
  90. package/index253.mjs +45 -8
  91. package/index254.js +1 -1
  92. package/index254.mjs +24 -6
  93. package/index255.js +1 -1
  94. package/index255.mjs +24 -5
  95. package/index256.js +1 -1
  96. package/index256.mjs +12 -7
  97. package/index257.js +1 -1
  98. package/index257.mjs +4 -29
  99. package/index258.js +1 -1
  100. package/index258.mjs +14 -18
  101. package/index259.js +1 -1
  102. package/index259.mjs +42 -13
  103. package/index260.js +1 -1
  104. package/index260.mjs +54 -40
  105. package/index261.js +1 -1
  106. package/index261.mjs +27 -7
  107. package/index262.js +1 -1
  108. package/index262.mjs +29 -15
  109. package/index263.js +1 -1
  110. package/index263.mjs +11 -3
  111. package/index264.js +1 -1
  112. package/index264.mjs +9 -4
  113. package/index265.js +1 -1
  114. package/index265.mjs +5 -19
  115. package/index266.js +1 -1
  116. package/index266.mjs +7 -54
  117. package/index267.js +1 -1
  118. package/index267.mjs +25 -136
  119. package/index268.js +1 -1
  120. package/index268.mjs +17 -196
  121. package/index269.js +1 -1
  122. package/index269.mjs +12 -21
  123. package/index270.js +1 -1
  124. package/index270.mjs +41 -47
  125. package/index271.js +1 -1
  126. package/index271.mjs +7 -47
  127. package/index272.js +1 -1
  128. package/index272.mjs +15 -95
  129. package/index273.js +1 -1
  130. package/index273.mjs +3 -72
  131. package/index274.js +1 -1
  132. package/index274.mjs +4 -68
  133. package/index275.js +1 -1
  134. package/index275.mjs +19 -7
  135. package/index276.js +1 -1
  136. package/index276.mjs +27 -11
  137. package/index277.js +1 -1
  138. package/index277.mjs +31 -5
  139. package/index278.js +1 -1
  140. package/index278.mjs +5 -121
  141. package/index279.js +1 -1
  142. package/index279.mjs +121 -43
  143. package/index280.js +1 -1
  144. package/index280.mjs +43 -230
  145. package/index281.js +1 -1
  146. package/index281.mjs +226 -27
  147. package/index324.js +1 -1
  148. package/index324.mjs +7 -63
  149. package/index325.js +1 -1
  150. package/index325.mjs +28 -7
  151. package/index326.js +1 -1
  152. package/index326.mjs +89 -24
  153. package/index327.js +1 -1
  154. package/index327.mjs +58 -88
  155. package/index330.js +1 -1
  156. package/index330.mjs +3 -3
  157. package/index333.js +1 -1
  158. package/index333.mjs +5 -5
  159. package/index334.js +1 -1
  160. package/index334.mjs +2 -2
  161. package/index335.js +1 -1
  162. package/index335.mjs +5 -5
  163. package/index336.js +1 -1
  164. package/index336.mjs +65 -20
  165. package/index337.js +1 -1
  166. package/index337.mjs +53 -29
  167. package/index338.js +1 -1
  168. package/index338.mjs +51 -63
  169. package/index339.js +1 -1
  170. package/index339.mjs +271 -43
  171. package/index340.js +1 -1
  172. package/index340.mjs +18 -52
  173. package/index341.js +1 -1
  174. package/index341.mjs +21 -281
  175. package/index342.js +1 -1
  176. package/index342.mjs +29 -20
  177. package/index8.js +1 -1
  178. package/index8.mjs +32 -32
  179. package/index99.js +1 -1
  180. package/index99.mjs +1 -1
  181. package/package.json +1 -1
package/index339.mjs CHANGED
@@ -1,56 +1,284 @@
1
- class o {
2
- *[Symbol.iterator]() {
3
- yield* this.iterable;
1
+ import { Selection as n } from "./index346.mjs";
2
+ import { compareNodeOrder as r, getFirstItem as d, getChildNodes as u } from "./index347.mjs";
3
+ class h {
4
+ /**
5
+ * The type of selection that is allowed in the collection.
6
+ */
7
+ get selectionMode() {
8
+ return this.state.selectionMode;
4
9
  }
5
- get size() {
6
- return this.keyMap.size;
10
+ /**
11
+ * Whether the collection allows empty selection.
12
+ */
13
+ get disallowEmptySelection() {
14
+ return this.state.disallowEmptySelection;
7
15
  }
8
- getKeys() {
9
- return this.keyMap.keys();
16
+ /**
17
+ * The selection behavior for the collection.
18
+ */
19
+ get selectionBehavior() {
20
+ return this.state.selectionBehavior;
10
21
  }
11
- getKeyBefore(l) {
12
- let e = this.keyMap.get(l);
13
- var t;
14
- return e && (t = e.prevKey) !== null && t !== void 0 ? t : null;
22
+ /**
23
+ * Sets the selection behavior for the collection.
24
+ */
25
+ setSelectionBehavior(t) {
26
+ this.state.setSelectionBehavior(t);
15
27
  }
16
- getKeyAfter(l) {
17
- let e = this.keyMap.get(l);
18
- var t;
19
- return e && (t = e.nextKey) !== null && t !== void 0 ? t : null;
28
+ /**
29
+ * Whether the collection is currently focused.
30
+ */
31
+ get isFocused() {
32
+ return this.state.isFocused;
20
33
  }
21
- getFirstKey() {
22
- return this.firstKey;
34
+ /**
35
+ * Sets whether the collection is focused.
36
+ */
37
+ setFocused(t) {
38
+ this.state.setFocused(t);
23
39
  }
24
- getLastKey() {
25
- return this.lastKey;
40
+ /**
41
+ * The current focused key in the collection.
42
+ */
43
+ get focusedKey() {
44
+ return this.state.focusedKey;
26
45
  }
27
- getItem(l) {
46
+ /** Whether the first or last child of the focused key should receive focus. */
47
+ get childFocusStrategy() {
48
+ return this.state.childFocusStrategy;
49
+ }
50
+ /**
51
+ * Sets the focused key.
52
+ */
53
+ setFocusedKey(t, e) {
54
+ (t == null || this.collection.getItem(t)) && this.state.setFocusedKey(t, e);
55
+ }
56
+ /**
57
+ * The currently selected keys in the collection.
58
+ */
59
+ get selectedKeys() {
60
+ return this.state.selectedKeys === "all" ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
61
+ }
62
+ /**
63
+ * The raw selection value for the collection.
64
+ * Either 'all' for select all, or a set of keys.
65
+ */
66
+ get rawSelection() {
67
+ return this.state.selectedKeys;
68
+ }
69
+ /**
70
+ * Returns whether a key is selected.
71
+ */
72
+ isSelected(t) {
73
+ if (this.state.selectionMode === "none") return !1;
74
+ let e = this.getKey(t);
75
+ return e == null ? !1 : this.state.selectedKeys === "all" ? this.canSelectItem(e) : this.state.selectedKeys.has(e);
76
+ }
77
+ /**
78
+ * Whether the selection is empty.
79
+ */
80
+ get isEmpty() {
81
+ return this.state.selectedKeys !== "all" && this.state.selectedKeys.size === 0;
82
+ }
83
+ /**
84
+ * Whether all items in the collection are selected.
85
+ */
86
+ get isSelectAll() {
87
+ if (this.isEmpty) return !1;
88
+ if (this.state.selectedKeys === "all") return !0;
89
+ if (this._isSelectAll != null) return this._isSelectAll;
90
+ let t = this.getSelectAllKeys(), e = this.state.selectedKeys;
91
+ return this._isSelectAll = t.every((l) => e.has(l)), this._isSelectAll;
92
+ }
93
+ get firstSelectedKey() {
94
+ let t = null;
95
+ for (let l of this.state.selectedKeys) {
96
+ let s = this.collection.getItem(l);
97
+ (!t || s && r(this.collection, s, t) < 0) && (t = s);
98
+ }
99
+ var e;
100
+ return (e = t == null ? void 0 : t.key) !== null && e !== void 0 ? e : null;
101
+ }
102
+ get lastSelectedKey() {
103
+ let t = null;
104
+ for (let l of this.state.selectedKeys) {
105
+ let s = this.collection.getItem(l);
106
+ (!t || s && r(this.collection, s, t) > 0) && (t = s);
107
+ }
28
108
  var e;
29
- return (e = this.keyMap.get(l)) !== null && e !== void 0 ? e : null;
30
- }
31
- at(l) {
32
- const e = [
33
- ...this.getKeys()
34
- ];
35
- return this.getItem(e[l]);
36
- }
37
- getChildren(l) {
38
- let e = this.keyMap.get(l);
39
- return (e == null ? void 0 : e.childNodes) || [];
40
- }
41
- constructor(l) {
42
- this.keyMap = /* @__PURE__ */ new Map(), this.firstKey = null, this.lastKey = null, this.iterable = l;
43
- let e = (i) => {
44
- if (this.keyMap.set(i.key, i), i.childNodes && i.type === "section") for (let s of i.childNodes) e(s);
109
+ return (e = t == null ? void 0 : t.key) !== null && e !== void 0 ? e : null;
110
+ }
111
+ get disabledKeys() {
112
+ return this.state.disabledKeys;
113
+ }
114
+ get disabledBehavior() {
115
+ return this.state.disabledBehavior;
116
+ }
117
+ /**
118
+ * Extends the selection to the given key.
119
+ */
120
+ extendSelection(t) {
121
+ if (this.selectionMode === "none") return;
122
+ if (this.selectionMode === "single") {
123
+ this.replaceSelection(t);
124
+ return;
125
+ }
126
+ let e = this.getKey(t);
127
+ if (e == null) return;
128
+ let l;
129
+ if (this.state.selectedKeys === "all") l = new n([
130
+ e
131
+ ], e, e);
132
+ else {
133
+ let i = this.state.selectedKeys;
134
+ var s;
135
+ let a = (s = i.anchorKey) !== null && s !== void 0 ? s : e;
136
+ l = new n(i, a, e);
137
+ var o;
138
+ for (let c of this.getKeyRange(a, (o = i.currentKey) !== null && o !== void 0 ? o : e)) l.delete(c);
139
+ for (let c of this.getKeyRange(e, a)) this.canSelectItem(c) && l.add(c);
140
+ }
141
+ this.state.setSelectedKeys(l);
142
+ }
143
+ getKeyRange(t, e) {
144
+ let l = this.collection.getItem(t), s = this.collection.getItem(e);
145
+ return l && s ? r(this.collection, l, s) <= 0 ? this.getKeyRangeInternal(t, e) : this.getKeyRangeInternal(e, t) : [];
146
+ }
147
+ getKeyRangeInternal(t, e) {
148
+ var l;
149
+ if (!((l = this.layoutDelegate) === null || l === void 0) && l.getKeyRange) return this.layoutDelegate.getKeyRange(t, e);
150
+ let s = [], o = t;
151
+ for (; o != null; ) {
152
+ let i = this.collection.getItem(o);
153
+ if (i && (i.type === "item" || i.type === "cell" && this.allowsCellSelection) && s.push(o), o === e) return s;
154
+ o = this.collection.getKeyAfter(o);
155
+ }
156
+ return [];
157
+ }
158
+ getKey(t) {
159
+ let e = this.collection.getItem(t);
160
+ if (!e || e.type === "cell" && this.allowsCellSelection) return t;
161
+ for (; e && e.type !== "item" && e.parentKey != null; ) e = this.collection.getItem(e.parentKey);
162
+ return !e || e.type !== "item" ? null : e.key;
163
+ }
164
+ /**
165
+ * Toggles whether the given key is selected.
166
+ */
167
+ toggleSelection(t) {
168
+ if (this.selectionMode === "none") return;
169
+ if (this.selectionMode === "single" && !this.isSelected(t)) {
170
+ this.replaceSelection(t);
171
+ return;
172
+ }
173
+ let e = this.getKey(t);
174
+ if (e == null) return;
175
+ let l = new n(this.state.selectedKeys === "all" ? this.getSelectAllKeys() : this.state.selectedKeys);
176
+ l.has(e) ? l.delete(e) : this.canSelectItem(e) && (l.add(e), l.anchorKey = e, l.currentKey = e), !(this.disallowEmptySelection && l.size === 0) && this.state.setSelectedKeys(l);
177
+ }
178
+ /**
179
+ * Replaces the selection with only the given key.
180
+ */
181
+ replaceSelection(t) {
182
+ if (this.selectionMode === "none") return;
183
+ let e = this.getKey(t);
184
+ if (e == null) return;
185
+ let l = this.canSelectItem(e) ? new n([
186
+ e
187
+ ], e, e) : new n();
188
+ this.state.setSelectedKeys(l);
189
+ }
190
+ /**
191
+ * Replaces the selection with the given keys.
192
+ */
193
+ setSelectedKeys(t) {
194
+ if (this.selectionMode === "none") return;
195
+ let e = new n();
196
+ for (let l of t) {
197
+ let s = this.getKey(l);
198
+ if (s != null && (e.add(s), this.selectionMode === "single"))
199
+ break;
200
+ }
201
+ this.state.setSelectedKeys(e);
202
+ }
203
+ getSelectAllKeys() {
204
+ let t = [], e = (l) => {
205
+ for (; l != null; ) {
206
+ if (this.canSelectItem(l)) {
207
+ var s;
208
+ let i = this.collection.getItem(l);
209
+ (i == null ? void 0 : i.type) === "item" && t.push(l);
210
+ var o;
211
+ i != null && i.hasChildNodes && (this.allowsCellSelection || i.type !== "item") && e((o = (s = d(u(i, this.collection))) === null || s === void 0 ? void 0 : s.key) !== null && o !== void 0 ? o : null);
212
+ }
213
+ l = this.collection.getKeyAfter(l);
214
+ }
45
215
  };
46
- for (let i of l) e(i);
47
- let t = null, n = 0;
48
- for (let [i, s] of this.keyMap)
49
- t ? (t.nextKey = i, s.prevKey = t.key) : (this.firstKey = i, s.prevKey = void 0), s.type === "item" && (s.index = n++), t = s, t.nextKey = void 0;
50
- var r;
51
- this.lastKey = (r = t == null ? void 0 : t.key) !== null && r !== void 0 ? r : null;
216
+ return e(this.collection.getFirstKey()), t;
217
+ }
218
+ /**
219
+ * Selects all items in the collection.
220
+ */
221
+ selectAll() {
222
+ !this.isSelectAll && this.selectionMode === "multiple" && this.state.setSelectedKeys("all");
223
+ }
224
+ /**
225
+ * Removes all keys from the selection.
226
+ */
227
+ clearSelection() {
228
+ !this.disallowEmptySelection && (this.state.selectedKeys === "all" || this.state.selectedKeys.size > 0) && this.state.setSelectedKeys(new n());
229
+ }
230
+ /**
231
+ * Toggles between select all and an empty selection.
232
+ */
233
+ toggleSelectAll() {
234
+ this.isSelectAll ? this.clearSelection() : this.selectAll();
235
+ }
236
+ select(t, e) {
237
+ this.selectionMode !== "none" && (this.selectionMode === "single" ? this.isSelected(t) && !this.disallowEmptySelection ? this.toggleSelection(t) : this.replaceSelection(t) : this.selectionBehavior === "toggle" || e && (e.pointerType === "touch" || e.pointerType === "virtual") ? this.toggleSelection(t) : this.replaceSelection(t));
238
+ }
239
+ /**
240
+ * Returns whether the current selection is equal to the given selection.
241
+ */
242
+ isSelectionEqual(t) {
243
+ if (t === this.state.selectedKeys) return !0;
244
+ let e = this.selectedKeys;
245
+ if (t.size !== e.size) return !1;
246
+ for (let l of t)
247
+ if (!e.has(l)) return !1;
248
+ for (let l of e)
249
+ if (!t.has(l)) return !1;
250
+ return !0;
251
+ }
252
+ canSelectItem(t) {
253
+ var e;
254
+ if (this.state.selectionMode === "none" || this.state.disabledKeys.has(t)) return !1;
255
+ let l = this.collection.getItem(t);
256
+ return !(!l || !(l == null || (e = l.props) === null || e === void 0) && e.isDisabled || l.type === "cell" && !this.allowsCellSelection);
257
+ }
258
+ isDisabled(t) {
259
+ var e, l;
260
+ return this.state.disabledBehavior === "all" && (this.state.disabledKeys.has(t) || !!(!((l = this.collection.getItem(t)) === null || l === void 0 || (e = l.props) === null || e === void 0) && e.isDisabled));
261
+ }
262
+ isLink(t) {
263
+ var e, l;
264
+ return !!(!((l = this.collection.getItem(t)) === null || l === void 0 || (e = l.props) === null || e === void 0) && e.href);
265
+ }
266
+ getItemProps(t) {
267
+ var e;
268
+ return (e = this.collection.getItem(t)) === null || e === void 0 ? void 0 : e.props;
269
+ }
270
+ withCollection(t) {
271
+ return new h(t, this.state, {
272
+ allowsCellSelection: this.allowsCellSelection,
273
+ layoutDelegate: this.layoutDelegate || void 0
274
+ });
275
+ }
276
+ constructor(t, e, l) {
277
+ this.collection = t, this.state = e;
278
+ var s;
279
+ this.allowsCellSelection = (s = l == null ? void 0 : l.allowsCellSelection) !== null && s !== void 0 ? s : !1, this._isSelectAll = null, this.layoutDelegate = (l == null ? void 0 : l.layoutDelegate) || null;
52
280
  }
53
281
  }
54
282
  export {
55
- o as ListCollection
283
+ h as SelectionManager
56
284
  };
package/index340.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./index346.js"),F=require("./index233.js"),t=require("react");function M(e,o){if(e.size!==o.size)return!1;for(let c of e)if(!o.has(c))return!1;return!0}function R(e){let{selectionMode:o="none",disallowEmptySelection:c=!1,allowDuplicateSelectionEvents:K,selectionBehavior:s="toggle",disabledBehavior:b="all"}=e,r=t.useRef(!1),[,v]=t.useState(!1),u=t.useRef(null),a=t.useRef(null),[,h]=t.useState(null),g=t.useMemo(()=>S(e.selectedKeys),[e.selectedKeys]),w=t.useMemo(()=>S(e.defaultSelectedKeys,new y.Selection),[e.defaultSelectedKeys]),[i,B]=F.useControlledState(g,w,e.onSelectionChange),$=t.useMemo(()=>e.disabledKeys?new Set(e.disabledKeys):new Set,[e.disabledKeys]),[d,n]=t.useState(s);s==="replace"&&d==="toggle"&&typeof i=="object"&&i.size===0&&n("replace");let f=t.useRef(s);return t.useEffect(()=>{s!==f.current&&(n(s),f.current=s)},[s]),{selectionMode:o,disallowEmptySelection:c,selectionBehavior:d,setSelectionBehavior:n,get isFocused(){return r.current},setFocused(l){r.current=l,v(l)},get focusedKey(){return u.current},get childFocusStrategy(){return a.current},setFocusedKey(l,m="first"){u.current=l,a.current=m,h(l)},selectedKeys:i,setSelectedKeys(l){(K||!M(l,i))&&B(l)},disabledKeys:$,disabledBehavior:b}}function S(e,o){return e?e==="all"?"all":new y.Selection(e):o}exports.useMultipleSelectionState=R;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./index348.js"),n=require("react");function s(u,l,t){let i=n.useMemo(()=>new d.CollectionBuilder,[]),{children:r,items:o,collection:e}=u;return n.useMemo(()=>{if(e)return e;let c=i.build({children:r,items:o},t);return l(c)},[i,r,o,e,t,l])}exports.useCollection=s;
package/index340.mjs CHANGED
@@ -1,57 +1,23 @@
1
- import { Selection as K } from "./index346.mjs";
2
- import { useControlledState as M } from "./index233.mjs";
3
- import { useRef as a, useState as r, useMemo as n, useEffect as x } from "react";
4
- function R(e, s) {
5
- if (e.size !== s.size) return !1;
6
- for (let c of e)
7
- if (!s.has(c)) return !1;
8
- return !0;
9
- }
10
- function C(e) {
11
- let { selectionMode: s = "none", disallowEmptySelection: c = !1, allowDuplicateSelectionEvents: v, selectionBehavior: l = "toggle", disabledBehavior: $ = "all" } = e, d = a(!1), [, h] = r(!1), u = a(null), f = a(null), [, m] = r(null), g = n(() => b(e.selectedKeys), [
12
- e.selectedKeys
13
- ]), w = n(() => b(e.defaultSelectedKeys, new K()), [
14
- e.defaultSelectedKeys
15
- ]), [o, B] = M(g, w, e.onSelectionChange), F = n(() => e.disabledKeys ? new Set(e.disabledKeys) : /* @__PURE__ */ new Set(), [
16
- e.disabledKeys
17
- ]), [S, i] = r(l);
18
- l === "replace" && S === "toggle" && typeof o == "object" && o.size === 0 && i("replace");
19
- let y = a(l);
20
- return x(() => {
21
- l !== y.current && (i(l), y.current = l);
1
+ import { CollectionBuilder as u } from "./index348.mjs";
2
+ import { useMemo as n } from "react";
3
+ function b(d, l, r) {
4
+ let t = n(() => new u(), []), { children: i, items: o, collection: e } = d;
5
+ return n(() => {
6
+ if (e) return e;
7
+ let c = t.build({
8
+ children: i,
9
+ items: o
10
+ }, r);
11
+ return l(c);
22
12
  }, [
13
+ t,
14
+ i,
15
+ o,
16
+ e,
17
+ r,
23
18
  l
24
- ]), {
25
- selectionMode: s,
26
- disallowEmptySelection: c,
27
- selectionBehavior: S,
28
- setSelectionBehavior: i,
29
- get isFocused() {
30
- return d.current;
31
- },
32
- setFocused(t) {
33
- d.current = t, h(t);
34
- },
35
- get focusedKey() {
36
- return u.current;
37
- },
38
- get childFocusStrategy() {
39
- return f.current;
40
- },
41
- setFocusedKey(t, E = "first") {
42
- u.current = t, f.current = E, m(t);
43
- },
44
- selectedKeys: o,
45
- setSelectedKeys(t) {
46
- (v || !R(t, o)) && B(t);
47
- },
48
- disabledKeys: F,
49
- disabledBehavior: $
50
- };
51
- }
52
- function b(e, s) {
53
- return e ? e === "all" ? "all" : new K(e) : s;
19
+ ]);
54
20
  }
55
21
  export {
56
- C as useMultipleSelectionState
22
+ b as useCollection
57
23
  };
package/index341.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index346.js"),c=require("./index347.js");class h{get selectionMode(){return this.state.selectionMode}get disallowEmptySelection(){return this.state.disallowEmptySelection}get selectionBehavior(){return this.state.selectionBehavior}setSelectionBehavior(t){this.state.setSelectionBehavior(t)}get isFocused(){return this.state.isFocused}setFocused(t){this.state.setFocused(t)}get focusedKey(){return this.state.focusedKey}get childFocusStrategy(){return this.state.childFocusStrategy}setFocusedKey(t,e){(t==null||this.collection.getItem(t))&&this.state.setFocusedKey(t,e)}get selectedKeys(){return this.state.selectedKeys==="all"?new Set(this.getSelectAllKeys()):this.state.selectedKeys}get rawSelection(){return this.state.selectedKeys}isSelected(t){if(this.state.selectionMode==="none")return!1;let e=this.getKey(t);return e==null?!1:this.state.selectedKeys==="all"?this.canSelectItem(e):this.state.selectedKeys.has(e)}get isEmpty(){return this.state.selectedKeys!=="all"&&this.state.selectedKeys.size===0}get isSelectAll(){if(this.isEmpty)return!1;if(this.state.selectedKeys==="all")return!0;if(this._isSelectAll!=null)return this._isSelectAll;let t=this.getSelectAllKeys(),e=this.state.selectedKeys;return this._isSelectAll=t.every(l=>e.has(l)),this._isSelectAll}get firstSelectedKey(){let t=null;for(let l of this.state.selectedKeys){let i=this.collection.getItem(l);(!t||i&&c.compareNodeOrder(this.collection,i,t)<0)&&(t=i)}var e;return(e=t==null?void 0:t.key)!==null&&e!==void 0?e:null}get lastSelectedKey(){let t=null;for(let l of this.state.selectedKeys){let i=this.collection.getItem(l);(!t||i&&c.compareNodeOrder(this.collection,i,t)>0)&&(t=i)}var e;return(e=t==null?void 0:t.key)!==null&&e!==void 0?e:null}get disabledKeys(){return this.state.disabledKeys}get disabledBehavior(){return this.state.disabledBehavior}extendSelection(t){if(this.selectionMode==="none")return;if(this.selectionMode==="single"){this.replaceSelection(t);return}let e=this.getKey(t);if(e==null)return;let l;if(this.state.selectedKeys==="all")l=new n.Selection([e],e,e);else{let s=this.state.selectedKeys;var i;let a=(i=s.anchorKey)!==null&&i!==void 0?i:e;l=new n.Selection(s,a,e);var o;for(let r of this.getKeyRange(a,(o=s.currentKey)!==null&&o!==void 0?o:e))l.delete(r);for(let r of this.getKeyRange(e,a))this.canSelectItem(r)&&l.add(r)}this.state.setSelectedKeys(l)}getKeyRange(t,e){let l=this.collection.getItem(t),i=this.collection.getItem(e);return l&&i?c.compareNodeOrder(this.collection,l,i)<=0?this.getKeyRangeInternal(t,e):this.getKeyRangeInternal(e,t):[]}getKeyRangeInternal(t,e){var l;if(!((l=this.layoutDelegate)===null||l===void 0)&&l.getKeyRange)return this.layoutDelegate.getKeyRange(t,e);let i=[],o=t;for(;o!=null;){let s=this.collection.getItem(o);if(s&&(s.type==="item"||s.type==="cell"&&this.allowsCellSelection)&&i.push(o),o===e)return i;o=this.collection.getKeyAfter(o)}return[]}getKey(t){let e=this.collection.getItem(t);if(!e||e.type==="cell"&&this.allowsCellSelection)return t;for(;e&&e.type!=="item"&&e.parentKey!=null;)e=this.collection.getItem(e.parentKey);return!e||e.type!=="item"?null:e.key}toggleSelection(t){if(this.selectionMode==="none")return;if(this.selectionMode==="single"&&!this.isSelected(t)){this.replaceSelection(t);return}let e=this.getKey(t);if(e==null)return;let l=new n.Selection(this.state.selectedKeys==="all"?this.getSelectAllKeys():this.state.selectedKeys);l.has(e)?l.delete(e):this.canSelectItem(e)&&(l.add(e),l.anchorKey=e,l.currentKey=e),!(this.disallowEmptySelection&&l.size===0)&&this.state.setSelectedKeys(l)}replaceSelection(t){if(this.selectionMode==="none")return;let e=this.getKey(t);if(e==null)return;let l=this.canSelectItem(e)?new n.Selection([e],e,e):new n.Selection;this.state.setSelectedKeys(l)}setSelectedKeys(t){if(this.selectionMode==="none")return;let e=new n.Selection;for(let l of t){let i=this.getKey(l);if(i!=null&&(e.add(i),this.selectionMode==="single"))break}this.state.setSelectedKeys(e)}getSelectAllKeys(){let t=[],e=l=>{for(;l!=null;){if(this.canSelectItem(l)){var i;let s=this.collection.getItem(l);(s==null?void 0:s.type)==="item"&&t.push(l);var o;s!=null&&s.hasChildNodes&&(this.allowsCellSelection||s.type!=="item")&&e((o=(i=c.getFirstItem(c.getChildNodes(s,this.collection)))===null||i===void 0?void 0:i.key)!==null&&o!==void 0?o:null)}l=this.collection.getKeyAfter(l)}};return e(this.collection.getFirstKey()),t}selectAll(){!this.isSelectAll&&this.selectionMode==="multiple"&&this.state.setSelectedKeys("all")}clearSelection(){!this.disallowEmptySelection&&(this.state.selectedKeys==="all"||this.state.selectedKeys.size>0)&&this.state.setSelectedKeys(new n.Selection)}toggleSelectAll(){this.isSelectAll?this.clearSelection():this.selectAll()}select(t,e){this.selectionMode!=="none"&&(this.selectionMode==="single"?this.isSelected(t)&&!this.disallowEmptySelection?this.toggleSelection(t):this.replaceSelection(t):this.selectionBehavior==="toggle"||e&&(e.pointerType==="touch"||e.pointerType==="virtual")?this.toggleSelection(t):this.replaceSelection(t))}isSelectionEqual(t){if(t===this.state.selectedKeys)return!0;let e=this.selectedKeys;if(t.size!==e.size)return!1;for(let l of t)if(!e.has(l))return!1;for(let l of e)if(!t.has(l))return!1;return!0}canSelectItem(t){var e;if(this.state.selectionMode==="none"||this.state.disabledKeys.has(t))return!1;let l=this.collection.getItem(t);return!(!l||!(l==null||(e=l.props)===null||e===void 0)&&e.isDisabled||l.type==="cell"&&!this.allowsCellSelection)}isDisabled(t){var e,l;return this.state.disabledBehavior==="all"&&(this.state.disabledKeys.has(t)||!!(!((l=this.collection.getItem(t))===null||l===void 0||(e=l.props)===null||e===void 0)&&e.isDisabled))}isLink(t){var e,l;return!!(!((l=this.collection.getItem(t))===null||l===void 0||(e=l.props)===null||e===void 0)&&e.href)}getItemProps(t){var e;return(e=this.collection.getItem(t))===null||e===void 0?void 0:e.props}withCollection(t){return new h(t,this.state,{allowsCellSelection:this.allowsCellSelection,layoutDelegate:this.layoutDelegate||void 0})}constructor(t,e,l){this.collection=t,this.state=e;var i;this.allowsCellSelection=(i=l==null?void 0:l.allowsCellSelection)!==null&&i!==void 0?i:!1,this._isSelectAll=null,this.layoutDelegate=(l==null?void 0:l.layoutDelegate)||null}}exports.SelectionManager=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./index181.js"),i=require("./index243.js");function u(e){return i.isAppleDevice()?e.altKey:e.ctrlKey}function a(e,t){var o,f;let r=`[data-key="${CSS.escape(String(t))}"]`,n=(o=e.current)===null||o===void 0?void 0:o.dataset.collection;return n&&(r=`[data-collection="${CSS.escape(n)}"]${r}`),(f=e.current)===null||f===void 0?void 0:f.querySelector(r)}const c=new WeakMap;function d(e){let t=l.useId();return c.set(e,t),t}function $(e){return c.get(e)}exports.getCollectionId=$;exports.getItemElement=a;exports.isNonContiguousSelectionModifier=u;exports.useCollectionId=d;