@bccampus/ui-components 0.4.1 → 0.4.2

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 (29) hide show
  1. package/dist/AbstractFocusProvider-CxvlcEki.js +29 -0
  2. package/dist/AbstractSelectionProvider-BtaROstC.js +30 -0
  3. package/dist/CompositeDataItem-DuHOHCWy.js +158 -0
  4. package/dist/ListboxFocusProvider.d.ts +149 -0
  5. package/dist/ListboxFocusProvider.js +53 -0
  6. package/dist/MultipleSelectionProvider.d.ts +141 -0
  7. package/dist/MultipleSelectionProvider.js +19 -0
  8. package/dist/SingleSelectionProvider.d.ts +141 -0
  9. package/dist/SingleSelectionProvider.js +23 -0
  10. package/dist/composite-component-DSUbd1XS.js +122 -0
  11. package/dist/composite.d.ts +108 -51
  12. package/dist/composite.js +57 -447
  13. package/dist/listbox.d.ts +171 -0
  14. package/dist/listbox.js +76 -0
  15. package/package.json +5 -1
  16. package/src/components/ui/composite/CompositeData.ts +22 -114
  17. package/src/components/ui/composite/FocusProvider/AbstractFocusProvider.ts +83 -0
  18. package/src/components/ui/composite/FocusProvider/ListboxFocusProvider.ts +74 -0
  19. package/src/components/ui/composite/SelectionProvider/AbstractSelectionProvider.ts +45 -0
  20. package/src/components/ui/composite/SelectionProvider/MultipleSelectionProvider.ts +28 -0
  21. package/src/components/ui/composite/SelectionProvider/SingleSelectionProvider.ts +37 -0
  22. package/src/components/ui/composite/composite-component-item.tsx +12 -10
  23. package/src/components/ui/composite/composite-component.tsx +39 -68
  24. package/src/components/ui/composite/index.ts +4 -1
  25. package/src/components/ui/composite/listbox.tsx +61 -0
  26. package/src/components/ui/composite/types.ts +51 -30
  27. package/src/hooks/use-keyboard-event.ts +31 -42
  28. package/vite.config.ts +4 -0
  29. package/src/components/ui/composite/composite-data-context.tsx +0 -31
package/dist/composite.js CHANGED
@@ -1,472 +1,82 @@
1
- import { jsx as b, jsxs as q } from "react/jsx-runtime";
2
- import { useMemo as w, createContext as L, useContext as N, useRef as E, useCallback as p, useSyncExternalStore as $, useId as M, useImperativeHandle as A } from "react";
3
- const O = (o, t) => {
4
- const e = { ...o };
5
- return t.forEach((s) => {
6
- const n = s.split("."), l = n.pop();
7
- if (l) {
8
- const i = n.reduce((r, d) => r && d in r ? r[d] : void 0, e);
9
- i && l in i && delete i[l];
10
- }
11
- }), e;
12
- };
13
- let R = Symbol("clean"), c = [], f = 0;
14
- const g = 4;
15
- let K = (o) => {
16
- let t = [], e = {
17
- get() {
18
- return e.lc || e.listen(() => {
19
- })(), e.value;
20
- },
21
- lc: 0,
22
- listen(s) {
23
- return e.lc = t.push(s), () => {
24
- for (let l = f + g; l < c.length; )
25
- c[l] === s ? c.splice(l, g) : l += g;
26
- let n = t.indexOf(s);
27
- ~n && (t.splice(n, 1), --e.lc || e.off());
28
- };
29
- },
30
- notify(s, n) {
31
- let l = !c.length;
32
- for (let i of t)
33
- c.push(i, e.value, s, n);
34
- if (l) {
35
- for (f = 0; f < c.length; f += g)
36
- c[f](
37
- c[f + 1],
38
- c[f + 2],
39
- c[f + 3]
40
- );
41
- c.length = 0;
42
- }
43
- },
44
- /* It will be called on last listener unsubscribing.
45
- We will redefine it in onMount and onStop. */
46
- off() {
47
- },
48
- set(s) {
49
- let n = e.value;
50
- n !== s && (e.value = s, e.notify(n));
51
- },
52
- subscribe(s) {
53
- let n = e.listen(s);
54
- return s(e.value), n;
55
- },
56
- value: o
57
- };
58
- return process.env.NODE_ENV !== "production" && (e[R] = () => {
59
- t = [], e.lc = 0, e.off();
60
- }), e;
61
- };
62
- function U(o, t, e) {
63
- let s = new Set(t).add(void 0);
64
- return o.listen((n, l, i) => {
65
- s.has(i) && e(n, l, i);
66
- });
67
- }
68
- let S = (o = {}) => {
69
- let t = K(o);
70
- return t.setKey = function(e, s) {
71
- let n = t.value;
72
- typeof s > "u" && e in t.value ? (t.value = { ...t.value }, delete t.value[e], t.notify(n, e)) : t.value[e] !== s && (t.value = {
73
- ...t.value,
74
- [e]: s
75
- }, t.notify(n, e));
76
- }, t;
77
- };
78
- class u {
79
- #e;
80
- parent = null;
81
- children;
82
- level;
83
- data;
84
- state;
85
- pointers;
86
- childrenProp;
87
- constructor(t, e, s) {
88
- this.#e = e.getItemKey(t), this.data = S(O(t, [e.itemChildrenProp])), this.state = S({
89
- focused: !1,
90
- selected: !1,
91
- disabled: !1,
92
- ...e.initialState
93
- }), this.pointers = {}, this.parent = s, this.level = s ? s.level + 1 : 0, this.childrenProp = e.itemChildrenProp;
94
- const n = e.getItemChildren(t);
95
- n && (this.children = n.map((l) => new u(l, e, this)));
96
- }
97
- get key() {
98
- return this.#e;
99
- }
100
- *[Symbol.iterator]() {
101
- if (this.key !== "ALL" && (yield this), this.children)
102
- for (const t of this.children)
103
- for (const e of t) yield e;
104
- }
105
- toJSON() {
106
- const t = { ...this.data.get() };
107
- if (this.children) {
108
- t[this.childrenProp] = [];
109
- for (const e of this.children)
110
- t[this.childrenProp].push(e.toJSON());
111
- }
112
- return t;
113
- }
114
- descendants() {
115
- if (!this.children) return [];
116
- const t = [];
117
- return this.children.forEach(
118
- (e) => {
119
- t.push(e);
120
- const s = e.descendants();
121
- s && t.push(...s);
122
- }
123
- ), t;
124
- }
125
- ancestors() {
126
- const t = [];
127
- let e = this.parent;
128
- for (; e; )
129
- t.push(e), e = e.parent;
130
- return t;
131
- }
132
- toggleSelect(t = !1) {
133
- this.state.get().selected ? this.deselect(t) : this.select(t);
134
- }
135
- select(t = !1) {
136
- if (this.state.setKey("selected", !0), t && this.children) {
137
- const e = this.children.map((s) => s.select(!0)).flat();
138
- return [this.key, ...e];
139
- }
140
- return [this.key];
141
- }
142
- deselect(t = !1) {
143
- if (this.state.setKey("selected", !1), t && this.children) {
144
- const e = this.children.map((s) => s.deselect(!0)).flat();
145
- return [this.key, ...e];
146
- }
147
- return [this.key];
148
- }
149
- disable(t = !1) {
150
- if (this.state.setKey("disabled", !0), t && this.children) {
151
- const e = this.children.map((s) => s.disable(!0)).flat();
152
- return [this.key, ...e];
153
- }
154
- return [this.key];
155
- }
156
- enable(t = !1) {
157
- if (this.state.setKey("disabled", !1), t && this.children) {
158
- const e = this.children.map((s) => s.enable(!0)).flat();
159
- return [this.key, ...e];
160
- }
161
- return [this.key];
162
- }
163
- }
164
- const j = /* @__PURE__ */ new Set(["ctrl", "shift", "alt", "meta"]), C = {
165
- " ": "space"
166
- };
167
- function J(o, t) {
168
- if (o.size !== t.size) return !1;
169
- for (const e of t)
170
- if (!o.has(e)) return !1;
171
- return !0;
172
- }
173
- function Q(o) {
174
- const t = [];
175
- for (const [e, s] of Object.entries(o)) {
176
- const n = e.toLowerCase().trim().split(/\s*\+\s*/);
177
- n.length === 1 && j.has(n[0]) ? console.error(`[useKeyboardEvent] \`${e}\`: A key sequence cannot be only a modifier key.`) : n.includes("") ? console.error(`[useKeyboardEvent] \`${e}\`: Unknown key defined in the sequence.`) : t.push({
178
- sequence: new Set(n),
179
- handler: s
180
- });
181
- }
182
- return t;
183
- }
184
- const v = {
185
- eventKeyProp: "key"
186
- };
187
- function z(o, t = v) {
188
- const e = { ...t, ...v }, s = Q(o);
189
- return (n) => {
190
- const l = /* @__PURE__ */ new Set(), i = n[e.eventKeyProp];
191
- n.ctrlKey && l.add("ctrl"), n.shiftKey && l.add("shift"), n.altKey && l.add("alt"), n.metaKey && l.add("meta"), C[i] ? l.add(C[i]) : l.add(i.toLowerCase());
192
- const r = s.find((d) => J(l, d.sequence));
193
- r && (n.preventDefault(), n.stopPropagation(), r.handler(n));
194
- };
195
- }
196
- function T(o, t) {
197
- return w(() => z(o, t), [o, t]);
198
- }
199
- function I(o, t) {
200
- const e = new Set(o);
201
- for (const s of t)
202
- e.add(s);
203
- return e;
204
- }
205
- function Y(o, t) {
206
- const e = new Set(o);
207
- for (const s of t)
208
- e.delete(s);
209
- return e;
210
- }
211
- class G {
1
+ import { C as m, a as u } from "./composite-component-DSUbd1XS.js";
2
+ import { C as s } from "./CompositeDataItem-DuHOHCWy.js";
3
+ import { u as n } from "./AbstractSelectionProvider-BtaROstC.js";
4
+ import { A as P } from "./AbstractSelectionProvider-BtaROstC.js";
5
+ import { A as v } from "./AbstractFocusProvider-CxvlcEki.js";
6
+ class l {
212
7
  #e;
213
8
  lookup = /* @__PURE__ */ new Map();
214
- firstFocusableItem;
215
- focusedItem = K(null);
216
- disabledKeys = K(/* @__PURE__ */ new Set());
217
- selectedKeys = K(/* @__PURE__ */ new Set());
9
+ focusProvider;
10
+ selectionProvider;
11
+ disabledKeys = /* @__PURE__ */ new Set();
218
12
  root;
219
- constructor(t, e) {
13
+ constructor(e, t, i) {
220
14
  this.#e = {
221
15
  itemKeyProp: "key",
222
16
  itemChildrenProp: "children",
223
17
  disabledKeys: [],
224
18
  selectedKeys: [],
225
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
226
- getItemKey: (s) => s[this.#e.itemKeyProp],
20
+ getItemKey: (o) => o[this.#e.itemKeyProp],
227
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
228
- getItemChildren: (s) => s[this.#e.itemChildrenProp] ? s[this.#e.itemChildrenProp] : void 0,
229
- ...e
230
- }, this.init(t);
22
+ getItemChildren: (o) => o[this.#e.itemChildrenProp] ? o[this.#e.itemChildrenProp] : void 0,
23
+ ...i
24
+ }, this.focusProvider = t.focusProvider, this.selectionProvider = t.selectionProvider, this.init(e);
231
25
  }
232
26
  *[Symbol.iterator]() {
233
27
  if (this.root.children)
234
- for (const t of this.root.children)
235
- yield t;
28
+ for (const e of this.root.children)
29
+ yield e;
236
30
  }
237
31
  toJSON() {
238
32
  return this.root.toJSON()[this.#e.itemChildrenProp];
239
33
  }
240
- init(t) {
241
- this.root = new u(
242
- { [this.#e.itemKeyProp]: "ALL", [this.#e.itemChildrenProp]: t },
34
+ init(e) {
35
+ this.root = new s(
36
+ { [this.#e.itemKeyProp]: "ALL", [this.#e.itemChildrenProp]: e },
243
37
  this.#e,
244
38
  null
245
- ), this.lookup = new Map([...this.root].map((s) => [s.key, s])), this.#e.disabledKeys.forEach((s) => this.disable(s)), this.#e.selectedKeys.forEach((s) => this.select(s)), this.firstFocusableItem = this.getFirstFocusableItem() ?? null, this.firstFocusableItem && (this.firstFocusableItem.state.setKey("focused", !0), this.focusedItem.set(this.firstFocusableItem));
246
- const e = [...this.lookup];
247
- for (let s = 0; s < e.length; s++) {
248
- const [n, l] = e[s];
249
- if (this.isFocusable(l) && s < e.length - 1) {
250
- let i = s === e.length - 1 ? 0 : s + 1;
251
- for (; i < e.length && !this.isFocusable(e[i][1]); )
252
- i = (i + 1) % e.length;
253
- l.pointers.down = e[i][0], e[i][1].pointers.up = n;
254
- }
39
+ ), this.lookup = new Map([...this.root].map((t) => [t.key, t])), this.#e.disabledKeys.forEach((t) => this.#t(t)), this.selectionProvider && this.selectionProvider.init(this, this.#e), this.focusProvider.init(this, this.#e);
40
+ }
41
+ item(e) {
42
+ return this.lookup.get(e);
43
+ }
44
+ descendants(e) {
45
+ const t = this.lookup.get(e);
46
+ if (t)
47
+ return t.descendants();
48
+ }
49
+ ancestors(e) {
50
+ const t = this.lookup.get(e);
51
+ if (t)
52
+ return t.ancestors();
53
+ }
54
+ #t(e, t = !1) {
55
+ const i = e instanceof s ? e : this.lookup.get(e);
56
+ if (!i) return;
57
+ const o = i.disable(t);
58
+ this.disabledKeys = n(this.disabledKeys, o);
59
+ }
60
+ updateItem(e, t) {
61
+ const i = this.lookup.get(e);
62
+ if (i) {
63
+ const o = {
64
+ ...i.data.get(),
65
+ ...typeof t == "function" ? t(i.data.get()) : t
66
+ }, r = this.#e.getItemKey(o);
67
+ if (i.key !== r) throw "Item key cannot be updated!";
68
+ this.#i(e), i.data.set(o);
255
69
  }
256
70
  }
257
- isFocusable(t) {
258
- return !t.state.get().disabled;
259
- }
260
- getFirstFocusableItem() {
261
- let t = this.lookup.values().next();
262
- for (; t.value && !this.isFocusable(t.value); )
263
- t = this.lookup.values().next();
264
- return t.value;
265
- }
266
- item(t) {
267
- return this.lookup.get(t);
268
- }
269
- descendants(t) {
270
- const e = this.lookup.get(t);
271
- if (e)
272
- return e.descendants();
273
- }
274
- ancestors(t) {
275
- const e = this.lookup.get(t);
276
- if (e)
277
- return e.ancestors();
278
- }
279
- focus(t) {
280
- const e = t instanceof u ? t : this.lookup.get(t);
281
- if (e) {
282
- if (this.focusedItem.get()) {
283
- if (e.key === this.focusedItem.get()?.key) return;
284
- this.focusedItem.get().state.setKey("focused", !1);
285
- }
286
- e.state.setKey("focused", !0), this.focusedItem.set(e);
287
- }
288
- }
289
- toggleSelect(t, e = !1) {
290
- const s = t instanceof u ? t : this.lookup.get(t);
291
- s && (s.state.get().selected ? this.deselect(s, e) : this.select(s, e));
292
- }
293
- select(t, e = !1) {
294
- const s = t instanceof u ? t : this.lookup.get(t);
295
- if (!s) return;
296
- const n = s.select(e);
297
- this.selectedKeys.set(I(this.selectedKeys.get(), n));
298
- }
299
- deselect(t, e = !1) {
300
- const s = t instanceof u ? t : this.lookup.get(t);
301
- if (!s) return;
302
- const n = s.deselect(e);
303
- this.selectedKeys.set(Y(this.selectedKeys.get(), n));
304
- }
305
- disable(t, e = !1) {
306
- const s = t instanceof u ? t : this.lookup.get(t);
307
- if (!s) return;
308
- const n = s.disable(e);
309
- this.disabledKeys.set(I(this.selectedKeys.get(), n));
71
+ #i(e) {
72
+ this.selectionProvider && this.selectionProvider.selectedKeys.get().has(e) && this.selectionProvider.selectedKeys.set(/* @__PURE__ */ new Set([...this.selectionProvider.selectedKeys.get()]));
310
73
  }
311
- enable(t, e = !1) {
312
- const s = t instanceof u ? t : this.lookup.get(t);
313
- if (!s) return;
314
- const n = s.enable(e);
315
- this.disabledKeys.set(I(this.selectedKeys.get(), n));
316
- }
317
- updateItem(t, e) {
318
- const s = this.lookup.get(t);
319
- if (s) {
320
- const n = {
321
- ...s.data.get(),
322
- ...typeof e == "function" ? e(s.data.get()) : e
323
- }, l = this.#e.getItemKey(n);
324
- if (s.key !== l) throw "Item key cannot be updated!";
325
- this.#t(t), s.data.set(n);
326
- }
327
- }
328
- #t(t) {
329
- this.selectedKeys.get().has(t) && this.selectedKeys.set(/* @__PURE__ */ new Set([...this.selectedKeys.get()]));
330
- }
331
- }
332
- const P = L(void 0);
333
- function H() {
334
- const o = N(P);
335
- if (!o)
336
- throw new Error("No CompositeDataContext has been set, use CompositeDataContext to provide a context");
337
- return o;
338
- }
339
- function X({
340
- data: o,
341
- children: t,
342
- ...e
343
- }) {
344
- const s = w(() => new G(o, e), [o, e]);
345
- return /* @__PURE__ */ b(P, { value: s, children: t });
346
- }
347
- let k = (o, t) => (e) => {
348
- o.current !== e && (o.current = e, t());
349
- };
350
- function x(o, { keys: t, deps: e = [o, t] } = {}) {
351
- let s = E();
352
- s.current = o.get();
353
- let n = p((i) => (k(s, i)(o.value), t?.length > 0 ? U(o, t, k(s, i)) : o.listen(k(s, i))), e), l = () => s.current;
354
- return $(n, l, l);
355
- }
356
- function D({
357
- id: o,
358
- className: t,
359
- item: e,
360
- mouseEventHandler: s,
361
- keyboardEventHandler: n,
362
- render: l
363
- }) {
364
- const i = x(e.data), r = x(e.state), d = w(() => r.disabled ? {} : {
365
- mouseEventHandler: () => s?.(e),
366
- keyboardEventHandler: () => n?.(e)
367
- }, [r.disabled, e, n, s]);
368
- return /* @__PURE__ */ q(
369
- "div",
370
- {
371
- id: o,
372
- role: "option",
373
- "aria-disabled": r.disabled,
374
- "data-key": e.key,
375
- tabIndex: r.disabled ? void 0 : r.focused ? 0 : -1,
376
- className: t,
377
- children: [
378
- l({ data: i, key: e.key, level: e.level }, r, d),
379
- e.children && e.children.length > 0 && [...e.children].map((a) => /* @__PURE__ */ b(
380
- D,
381
- {
382
- id: `${o}-${e.key}`,
383
- item: a,
384
- render: l,
385
- className: t,
386
- mouseEventHandler: s,
387
- keyboardEventHandler: n
388
- },
389
- a.key
390
- ))
391
- ]
392
- }
393
- );
394
- }
395
- function V(o) {
396
- return o ?? M();
397
- }
398
- function Z({
399
- renderItem: o,
400
- className: t,
401
- itemClassName: e,
402
- ref: s,
403
- id: n,
404
- ...l
405
- }) {
406
- const i = H(), r = E(null), d = V(n), a = p(
407
- (h) => {
408
- i.focus(h);
409
- },
410
- [i]
411
- ), y = p(() => {
412
- i.focusedItem.get()?.pointers.down && a(i.focusedItem.get().pointers.down);
413
- }, [i, a]), m = p(() => {
414
- i.focusedItem.get()?.pointers.up && a(i.focusedItem.get().pointers.up);
415
- }, [i, a]), F = T({
416
- ArrowUp: m,
417
- ArrowLeft: m,
418
- ArrowDown: y,
419
- ArrowRight: y,
420
- Space: () => {
421
- i.focusedItem.get() && i.toggleSelect(i.focusedItem.get());
422
- }
423
- }), _ = p(
424
- (h) => {
425
- a(h.key), i.toggleSelect(h);
426
- },
427
- [i, a]
428
- );
429
- return A(
430
- s,
431
- () => ({
432
- focusDown() {
433
- y();
434
- },
435
- focusUp() {
436
- m();
437
- },
438
- select() {
439
- i.focusedItem.get() && i.toggleSelect(i.focusedItem.get());
440
- }
441
- }),
442
- [i, y, m]
443
- ), /* @__PURE__ */ b(
444
- "div",
445
- {
446
- ref: r,
447
- id: d,
448
- className: t,
449
- tabIndex: -1,
450
- role: "listbox",
451
- onKeyDown: F,
452
- ...l,
453
- children: [...i].map((h) => /* @__PURE__ */ b(
454
- D,
455
- {
456
- className: e,
457
- id: `${d}-${h.key}`,
458
- item: h,
459
- render: o,
460
- mouseEventHandler: _
461
- },
462
- h.key
463
- ))
464
- }
465
- );
466
74
  }
467
75
  export {
468
- Z as CompositeComponent,
469
- X as CompositeComponentContext,
470
- D as CompositeComponentItem,
471
- H as useCompositeContext
76
+ v as AbstractFocusProvider,
77
+ P as AbstractSelectionProvider,
78
+ m as CompositeComponent,
79
+ u as CompositeComponentItem,
80
+ l as CompositeData,
81
+ s as CompositeDataItem
472
82
  };
@@ -0,0 +1,171 @@
1
+ import { JSX } from 'react/jsx-runtime';
2
+ import { KeyboardEventHandler } from 'react';
3
+ import { MouseEventHandler } from 'react';
4
+ import { PreinitializedMapStore } from 'nanostores';
5
+ import { PreinitializedWritableAtom } from 'nanostores';
6
+ import { ReactNode } from 'react';
7
+
8
+ declare abstract class AbstractFocusProvider<T extends object> implements FocusProvider {
9
+ protected data: CompositeData<T>;
10
+ protected dataOptions: CompositeDataOptions<T>;
11
+ firstFocusableItem: CompositeDataItem<T> | null;
12
+ lastFocusableItem: CompositeDataItem<T> | null;
13
+ focusedItem: PreinitializedWritableAtom<CompositeDataItem<T> | null>;
14
+ init(data: CompositeData<T>, dataOptions: CompositeDataOptions<T>): void;
15
+ isFocusable(itemAtom: CompositeDataItem<T>): boolean;
16
+ focus(itemKey: CompositeItemKey): void;
17
+ focus(item: CompositeDataItem<T>): void;
18
+ abstract setFocusPointers(): readonly [first: CompositeDataItem<T> | null, last: CompositeDataItem<T> | null];
19
+ abstract focusUp(): void;
20
+ abstract focusDown(): void;
21
+ abstract focusLeft(): void;
22
+ abstract focusRight(): void;
23
+ abstract focusPageUp(): void;
24
+ abstract focesPageDown(): void;
25
+ abstract focusToFirst(): void;
26
+ abstract focusToLast(): void;
27
+ abstract focusToFirstInRow(): void;
28
+ abstract focusToLastInRow(): void;
29
+ abstract focusToTypeAheadMatch(): void;
30
+ }
31
+
32
+ declare abstract class AbstractSelectionProvider<T extends object> {
33
+ protected data: CompositeData<T>;
34
+ protected dataOptions: CompositeDataOptions<T>;
35
+ selectedKeys: PreinitializedWritableAtom<Set<CompositeItemKey>>;
36
+ init(data: CompositeData<T>, dataOptions: CompositeDataOptions<T>): void;
37
+ abstract select(itemKey?: CompositeItemKey, recursive?: boolean): void;
38
+ abstract select(item: CompositeDataItem<T>, recursive?: boolean): void;
39
+ abstract select(item?: CompositeDataItem<T> | CompositeItemKey, recursive?: boolean): void;
40
+ abstract deselect(itemKey?: CompositeItemKey, recursive?: boolean): void;
41
+ abstract deselect(item: CompositeDataItem<T>, recursive?: boolean): void;
42
+ abstract deselect(item?: CompositeDataItem<T> | CompositeItemKey, recursive?: boolean): void;
43
+ toggleSelect(itemKey?: CompositeItemKey, recursive?: boolean): void;
44
+ toggleSelect(item: CompositeDataItem<T>, recursive?: boolean): void;
45
+ }
46
+
47
+ declare interface BaseCompositeProps<T extends object> extends React.ComponentPropsWithoutRef<"div"> {
48
+ data: CompositeData<T>;
49
+ className?: string;
50
+ ref?: React.Ref<HTMLDivElement>;
51
+ handleRef?: React.Ref<CompositeHandle>;
52
+ renderItem: CompositeItemRenderFn<T>;
53
+ itemClassName?: string;
54
+ }
55
+
56
+ declare class CompositeData<T extends object> implements Iterable<CompositeDataItem<T>> {
57
+ #private;
58
+ lookup: Map<CompositeItemKey, CompositeDataItem<T>>;
59
+ focusProvider: AbstractFocusProvider<T>;
60
+ selectionProvider?: AbstractSelectionProvider<T>;
61
+ disabledKeys: Set<CompositeItemKey>;
62
+ root: CompositeDataItem<T>;
63
+ constructor(items: T[], providerOptions: CompositeProviderOptions<T>, options?: CompositeOptions);
64
+ [Symbol.iterator](): Iterator<CompositeDataItem<T>>;
65
+ toJSON(): T[];
66
+ init(items: T[]): void;
67
+ item(key: CompositeItemKey): CompositeDataItem<T> | undefined;
68
+ descendants(itemKey: CompositeItemKey): CompositeDataItem<T>[] | undefined;
69
+ ancestors(itemKey: CompositeItemKey): CompositeDataItem<T>[] | undefined;
70
+ updateItem(key: CompositeItemKey, data: Partial<T> | ((item: T) => Partial<T>)): void;
71
+ }
72
+
73
+ declare class CompositeDataItem<T extends object> implements Iterable<CompositeDataItem<T>> {
74
+ #private;
75
+ parent: CompositeDataItem<T> | null;
76
+ children?: CompositeDataItem<T>[];
77
+ level: number;
78
+ data: PreinitializedMapStore<T>;
79
+ state: PreinitializedMapStore<CompositeDataItemState>;
80
+ pointers: {
81
+ left?: CompositeItemKey;
82
+ right?: CompositeItemKey;
83
+ up?: CompositeItemKey;
84
+ down?: CompositeItemKey;
85
+ };
86
+ childrenProp: string;
87
+ constructor(item: T, options: CompositeDataItemOptions<T>, parent: CompositeDataItem<T> | null);
88
+ get key(): CompositeItemKey;
89
+ [Symbol.iterator](): Iterator<CompositeDataItem<T>>;
90
+ toJSON(): T;
91
+ descendants(): CompositeDataItem<T>[];
92
+ ancestors(): CompositeDataItem<T>[];
93
+ toggleSelect(recursive?: boolean): void;
94
+ select(recursive?: boolean): CompositeItemKey[];
95
+ deselect(recursive?: boolean): CompositeItemKey[];
96
+ disable(recursive?: boolean): CompositeItemKey[];
97
+ enable(recursive?: boolean): CompositeItemKey[];
98
+ }
99
+
100
+ declare type CompositeDataItemOptions<T> = CompositeDataPropGetters<T> & {
101
+ initialState?: CompositeDataItemState;
102
+ itemChildrenProp: string;
103
+ };
104
+
105
+ declare interface CompositeDataItemState {
106
+ focused: boolean;
107
+ selected: boolean;
108
+ disabled: boolean;
109
+ }
110
+
111
+ declare type CompositeDataOptions<T> = Required<CompositeOptions> & CompositeDataPropGetters<T>;
112
+
113
+ declare interface CompositeDataPropGetters<T> {
114
+ getItemKey: (item: T) => CompositeItemKey;
115
+ getItemChildren: (item: T) => T[] | undefined;
116
+ }
117
+
118
+ declare interface CompositeEventHandlers {
119
+ mouseEventHandler?: MouseEventHandler<HTMLElement>;
120
+ keyboardEventHandler?: KeyboardEventHandler<HTMLElement>;
121
+ }
122
+
123
+ declare interface CompositeHandle {
124
+ focusProvider: FocusProvider;
125
+ selectionProvider?: SelectionProvider;
126
+ }
127
+
128
+ declare type CompositeItemKey = string | number;
129
+
130
+ declare type CompositeItemRenderFn<T extends object> = (item: {
131
+ data: T;
132
+ level: number;
133
+ key: CompositeItemKey;
134
+ }, state: CompositeDataItemState, eventHandlers: CompositeEventHandlers) => ReactNode;
135
+
136
+ declare interface CompositeOptions {
137
+ disabledKeys?: CompositeItemKey[];
138
+ selectedKeys?: CompositeItemKey[];
139
+ itemKeyProp?: string;
140
+ itemChildrenProp?: string;
141
+ }
142
+
143
+ declare interface CompositeProviderOptions<T extends object> {
144
+ focusProvider: AbstractFocusProvider<T>;
145
+ selectionProvider?: AbstractSelectionProvider<T>;
146
+ }
147
+
148
+ declare interface FocusProvider {
149
+ focus(itemKey: CompositeItemKey): void;
150
+ focusUp(): void;
151
+ focusDown(): void;
152
+ focusLeft(): void;
153
+ focusRight(): void;
154
+ focusPageUp(): void;
155
+ focesPageDown(): void;
156
+ focusToFirst(): void;
157
+ focusToLast(): void;
158
+ focusToFirstInRow(): void;
159
+ focusToLastInRow(): void;
160
+ focusToTypeAheadMatch(): void;
161
+ }
162
+
163
+ export declare function Listbox<T extends object>({ data, ...props }: BaseCompositeProps<T>): JSX.Element;
164
+
165
+ declare interface SelectionProvider {
166
+ select(itemKey?: CompositeItemKey, recursive?: boolean): void;
167
+ deselect(itemKey?: CompositeItemKey, recursive?: boolean): void;
168
+ toggleSelect(itemKey?: CompositeItemKey, recursive?: boolean): void;
169
+ }
170
+
171
+ export { }