1 | import * as React from "react";
|
2 | import {
|
3 | SealedInitialState,
|
4 | useSealedState,
|
5 | } from "reakit-utils/useSealedState";
|
6 | import { applyState } from "reakit-utils/applyState";
|
7 | import { useIsomorphicEffect } from "reakit-utils/useIsomorphicEffect";
|
8 | import {
|
9 | unstable_IdState,
|
10 | unstable_IdActions,
|
11 | unstable_IdInitialState,
|
12 | unstable_useIdState,
|
13 | unstable_IdStateReturn,
|
14 | } from "../Id/IdState";
|
15 | import { reverse } from "./__utils/reverse";
|
16 | import { Item, Group, Orientation } from "./__utils/types";
|
17 | import { findDOMIndex } from "./__utils/findDOMIndex";
|
18 | import { findFirstEnabledItem } from "./__utils/findFirstEnabledItem";
|
19 | import { findEnabledItemById } from "./__utils/findEnabledItemById";
|
20 | import { verticalizeItems } from "./__utils/verticalizeItems";
|
21 | import { groupItems } from "./__utils/groupItems";
|
22 | import { flatten } from "./__utils/flatten";
|
23 | import { fillGroups } from "./__utils/fillGroups";
|
24 | import { getCurrentId } from "./__utils/getCurrentId";
|
25 | import { placeItemsAfter } from "./__utils/placeItemsAfter";
|
26 | import { getItemsInGroup } from "./__utils/getItemsInGroup";
|
27 | import { getOppositeOrientation } from "./__utils/getOppositeOrientation";
|
28 | import { addItemAtIndex } from "./__utils/addItemAtIndex";
|
29 | import { sortBasedOnDOMPosition } from "./__utils/sortBasedOnDOMPosition";
|
30 | import { useSortBasedOnDOMPosition } from "./__utils/useSortBasedOnDOMPosition";
|
31 |
|
32 | type CompositeReducerAction =
|
33 | | { type: "registerItem"; item: Item }
|
34 | | { type: "unregisterItem"; id: string | null }
|
35 | | { type: "registerGroup"; group: Group }
|
36 | | { type: "unregisterGroup"; id: string | null }
|
37 | | { type: "move"; id?: string | null }
|
38 | | { type: "next"; allTheWay?: boolean; hasNullItem?: boolean }
|
39 | | { type: "previous"; allTheWay?: boolean }
|
40 | | { type: "up"; allTheWay?: boolean }
|
41 | | { type: "down"; allTheWay?: boolean }
|
42 | | { type: "first" }
|
43 | | { type: "last" }
|
44 | | { type: "sort" }
|
45 | | {
|
46 | type: "setVirtual";
|
47 | virtual: React.SetStateAction<CompositeState["unstable_virtual"]>;
|
48 | }
|
49 | | {
|
50 | type: "setRTL";
|
51 | rtl: React.SetStateAction<CompositeState["rtl"]>;
|
52 | }
|
53 | | {
|
54 | type: "setOrientation";
|
55 | orientation?: React.SetStateAction<CompositeState["orientation"]>;
|
56 | }
|
57 | | {
|
58 | type: "setCurrentId";
|
59 | currentId?: React.SetStateAction<CompositeState["currentId"]>;
|
60 | }
|
61 | | {
|
62 | type: "setLoop";
|
63 | loop: React.SetStateAction<CompositeState["loop"]>;
|
64 | }
|
65 | | {
|
66 | type: "setWrap";
|
67 | wrap: React.SetStateAction<CompositeState["wrap"]>;
|
68 | }
|
69 | | {
|
70 | type: "setShift";
|
71 | shift: React.SetStateAction<CompositeState["shift"]>;
|
72 | }
|
73 | | { type: "reset" }
|
74 | | { type: "setItems"; items: CompositeState["items"] }
|
75 | | {
|
76 | type: "setIncludesBaseElement";
|
77 | includesBaseElement: React.SetStateAction<
|
78 | CompositeState["unstable_includesBaseElement"]
|
79 | >;
|
80 | };
|
81 |
|
82 | type CompositeReducerState = Omit<
|
83 | CompositeState,
|
84 | "unstable_hasActiveWidget" | keyof unstable_IdState
|
85 | > & {
|
86 | pastIds: string[];
|
87 | initialVirtual: CompositeState["unstable_virtual"];
|
88 | initialRTL: CompositeState["rtl"];
|
89 | initialOrientation: CompositeState["orientation"];
|
90 | initialCurrentId: CompositeState["currentId"];
|
91 | initialLoop: CompositeState["loop"];
|
92 | initialWrap: CompositeState["wrap"];
|
93 | initialShift: CompositeState["shift"];
|
94 | hasSetCurrentId?: boolean;
|
95 | };
|
96 |
|
97 | function reducer(
|
98 | state: CompositeReducerState,
|
99 | action: CompositeReducerAction
|
100 | ): CompositeReducerState {
|
101 | const {
|
102 | unstable_virtual: virtual,
|
103 | rtl,
|
104 | orientation,
|
105 | items,
|
106 | groups,
|
107 | currentId,
|
108 | loop,
|
109 | wrap,
|
110 | pastIds,
|
111 | shift,
|
112 | unstable_moves: moves,
|
113 | unstable_includesBaseElement: includesBaseElement,
|
114 | initialVirtual,
|
115 | initialRTL,
|
116 | initialOrientation,
|
117 | initialCurrentId,
|
118 | initialLoop,
|
119 | initialWrap,
|
120 | initialShift,
|
121 | hasSetCurrentId,
|
122 | } = state;
|
123 |
|
124 | switch (action.type) {
|
125 | case "registerGroup": {
|
126 | const { group } = action;
|
127 |
|
128 | if (groups.length === 0) {
|
129 | return { ...state, groups: [group] };
|
130 | }
|
131 |
|
132 | const index = findDOMIndex(groups, group);
|
133 | return { ...state, groups: addItemAtIndex(groups, group, index) };
|
134 | }
|
135 |
|
136 | case "unregisterGroup": {
|
137 | const { id } = action;
|
138 | const nextGroups = groups.filter((group) => group.id !== id);
|
139 |
|
140 | if (nextGroups.length === groups.length) {
|
141 | return state;
|
142 | }
|
143 | return { ...state, groups: nextGroups };
|
144 | }
|
145 |
|
146 | case "registerItem": {
|
147 | const { item } = action;
|
148 |
|
149 | const group = groups.find((r) =>
|
150 | r.ref.current?.contains(item.ref.current)
|
151 | );
|
152 |
|
153 | const nextItem = { groupId: group?.id, ...item };
|
154 | const index = findDOMIndex(items, nextItem);
|
155 | const nextState = {
|
156 | ...state,
|
157 | items: addItemAtIndex(items, nextItem, index),
|
158 | };
|
159 | if (!hasSetCurrentId && !moves && initialCurrentId === undefined) {
|
160 |
|
161 |
|
162 |
|
163 | return {
|
164 | ...nextState,
|
165 | currentId: findFirstEnabledItem(nextState.items)?.id,
|
166 | };
|
167 | }
|
168 | return nextState;
|
169 | }
|
170 |
|
171 | case "unregisterItem": {
|
172 | const { id } = action;
|
173 | const nextItems = items.filter((item) => item.id !== id);
|
174 |
|
175 | if (nextItems.length === items.length) {
|
176 | return state;
|
177 | }
|
178 |
|
179 | const nextPastIds = pastIds.filter((pastId) => pastId !== id);
|
180 | const nextState = {
|
181 | ...state,
|
182 | pastIds: nextPastIds,
|
183 | items: nextItems,
|
184 | };
|
185 |
|
186 | if (currentId && currentId === id) {
|
187 | const nextId = includesBaseElement
|
188 | ? null
|
189 | : getCurrentId({
|
190 | ...nextState,
|
191 | currentId: nextPastIds[0],
|
192 | });
|
193 | return { ...nextState, currentId: nextId };
|
194 | }
|
195 | return nextState;
|
196 | }
|
197 |
|
198 | case "move": {
|
199 | const { id } = action;
|
200 |
|
201 | if (id === undefined) {
|
202 | return state;
|
203 | }
|
204 |
|
205 |
|
206 | const filteredPastIds = pastIds.filter(
|
207 | (pastId) => pastId !== currentId && pastId !== id
|
208 | );
|
209 |
|
210 |
|
211 | const nextPastIds = currentId
|
212 | ? [currentId, ...filteredPastIds]
|
213 | : filteredPastIds;
|
214 | const nextState = { ...state, pastIds: nextPastIds };
|
215 |
|
216 | if (id === null) {
|
217 | return {
|
218 | ...nextState,
|
219 | unstable_moves: moves + 1,
|
220 | currentId: getCurrentId(nextState, id),
|
221 | };
|
222 | }
|
223 | const item = findEnabledItemById(items, id);
|
224 | return {
|
225 | ...nextState,
|
226 | unstable_moves: item ? moves + 1 : moves,
|
227 | currentId: getCurrentId(nextState, item?.id),
|
228 | };
|
229 | }
|
230 |
|
231 | case "next": {
|
232 |
|
233 | if (currentId == null) {
|
234 | return reducer(state, { ...action, type: "first" });
|
235 | }
|
236 |
|
237 | const isHorizontal = orientation !== "vertical";
|
238 | const isRTL = rtl && isHorizontal;
|
239 | const allItems = isRTL ? reverse(items) : items;
|
240 | const currentItem = allItems.find((item) => item.id === currentId);
|
241 |
|
242 | if (!currentItem) {
|
243 | return reducer(state, { ...action, type: "first" });
|
244 | }
|
245 | const isGrid = !!currentItem.groupId;
|
246 | const currentIndex = allItems.indexOf(currentItem);
|
247 | const nextItems = allItems.slice(currentIndex + 1);
|
248 | const nextItemsInGroup = getItemsInGroup(nextItems, currentItem.groupId);
|
249 |
|
250 | if (action.allTheWay) {
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | const nextItem = findFirstEnabledItem(
|
256 | isRTL
|
257 | ? getItemsInGroup(allItems, currentItem.groupId)
|
258 | : reverse(nextItemsInGroup)
|
259 | );
|
260 | return reducer(state, { ...action, type: "move", id: nextItem?.id });
|
261 | }
|
262 | const oppositeOrientation = getOppositeOrientation(
|
263 |
|
264 |
|
265 |
|
266 | isGrid ? orientation || "horizontal" : orientation
|
267 | );
|
268 | const canLoop = loop && loop !== oppositeOrientation;
|
269 | const canWrap = isGrid && wrap && wrap !== oppositeOrientation;
|
270 | const hasNullItem =
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 | action.hasNullItem || (!isGrid && canLoop && includesBaseElement);
|
278 |
|
279 | if (canLoop) {
|
280 | const loopItems =
|
281 | canWrap && !hasNullItem
|
282 | ? allItems
|
283 | : getItemsInGroup(allItems, currentItem.groupId);
|
284 |
|
285 | const sortedItems = placeItemsAfter(loopItems, currentId, hasNullItem);
|
286 | const nextItem = findFirstEnabledItem(sortedItems, currentId);
|
287 | return reducer(state, { ...action, type: "move", id: nextItem?.id });
|
288 | }
|
289 | if (canWrap) {
|
290 | const nextItem = findFirstEnabledItem(
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 | hasNullItem ? nextItemsInGroup : nextItems,
|
298 | currentId
|
299 | );
|
300 | const nextId = hasNullItem ? nextItem?.id || null : nextItem?.id;
|
301 | return reducer(state, { ...action, type: "move", id: nextId });
|
302 | }
|
303 | const nextItem = findFirstEnabledItem(nextItemsInGroup, currentId);
|
304 | if (!nextItem && hasNullItem) {
|
305 | return reducer(state, { ...action, type: "move", id: null });
|
306 | }
|
307 | return reducer(state, { ...action, type: "move", id: nextItem?.id });
|
308 | }
|
309 |
|
310 | case "previous": {
|
311 |
|
312 |
|
313 |
|
314 | const isGrid = !!groups.length;
|
315 | const hasNullItem = !isGrid && includesBaseElement;
|
316 | const nextState = reducer(
|
317 | { ...state, items: reverse(items) },
|
318 | { ...action, type: "next", hasNullItem }
|
319 | );
|
320 | return { ...nextState, items };
|
321 | }
|
322 |
|
323 | case "down": {
|
324 | const shouldShift = shift && !action.allTheWay;
|
325 |
|
326 |
|
327 |
|
328 | const verticalItems = verticalizeItems(
|
329 | flatten(fillGroups(groupItems(items), currentId, shouldShift))
|
330 | );
|
331 | const canLoop = loop && loop !== "horizontal";
|
332 |
|
333 |
|
334 | const hasNullItem = canLoop && includesBaseElement;
|
335 | const nextState = reducer(
|
336 | { ...state, orientation: "vertical", items: verticalItems },
|
337 | { ...action, type: "next", hasNullItem }
|
338 | );
|
339 | return { ...nextState, orientation, items };
|
340 | }
|
341 |
|
342 | case "up": {
|
343 | const shouldShift = shift && !action.allTheWay;
|
344 | const verticalItems = verticalizeItems(
|
345 | reverse(flatten(fillGroups(groupItems(items), currentId, shouldShift)))
|
346 | );
|
347 |
|
348 |
|
349 | const hasNullItem = includesBaseElement;
|
350 | const nextState = reducer(
|
351 | { ...state, orientation: "vertical", items: verticalItems },
|
352 | { ...action, type: "next", hasNullItem }
|
353 | );
|
354 | return { ...nextState, orientation, items };
|
355 | }
|
356 |
|
357 | case "first": {
|
358 | const firstItem = findFirstEnabledItem(items);
|
359 | return reducer(state, { ...action, type: "move", id: firstItem?.id });
|
360 | }
|
361 |
|
362 | case "last": {
|
363 | const nextState = reducer(
|
364 | { ...state, items: reverse(items) },
|
365 | { ...action, type: "first" }
|
366 | );
|
367 | return { ...nextState, items };
|
368 | }
|
369 |
|
370 | case "sort": {
|
371 | return {
|
372 | ...state,
|
373 | items: sortBasedOnDOMPosition(items),
|
374 | groups: sortBasedOnDOMPosition(groups),
|
375 | };
|
376 | }
|
377 |
|
378 | case "setVirtual":
|
379 | return {
|
380 | ...state,
|
381 | unstable_virtual: applyState(action.virtual, virtual),
|
382 | };
|
383 |
|
384 | case "setRTL":
|
385 | return { ...state, rtl: applyState(action.rtl, rtl) };
|
386 |
|
387 | case "setOrientation":
|
388 | return {
|
389 | ...state,
|
390 | orientation: applyState(action.orientation, orientation),
|
391 | };
|
392 |
|
393 | case "setCurrentId": {
|
394 | const nextCurrentId = getCurrentId({
|
395 | ...state,
|
396 | currentId: applyState(action.currentId, currentId),
|
397 | });
|
398 | return { ...state, currentId: nextCurrentId, hasSetCurrentId: true };
|
399 | }
|
400 |
|
401 | case "setLoop":
|
402 | return { ...state, loop: applyState(action.loop, loop) };
|
403 |
|
404 | case "setWrap":
|
405 | return { ...state, wrap: applyState(action.wrap, wrap) };
|
406 |
|
407 | case "setShift":
|
408 | return { ...state, shift: applyState(action.shift, shift) };
|
409 |
|
410 | case "setIncludesBaseElement": {
|
411 | return {
|
412 | ...state,
|
413 | unstable_includesBaseElement: applyState(
|
414 | action.includesBaseElement,
|
415 | includesBaseElement
|
416 | ),
|
417 | };
|
418 | }
|
419 |
|
420 | case "reset":
|
421 | return {
|
422 | ...state,
|
423 | unstable_virtual: initialVirtual,
|
424 | rtl: initialRTL,
|
425 | orientation: initialOrientation,
|
426 | currentId: getCurrentId({ ...state, currentId: initialCurrentId }),
|
427 | loop: initialLoop,
|
428 | wrap: initialWrap,
|
429 | shift: initialShift,
|
430 | unstable_moves: 0,
|
431 | pastIds: [],
|
432 | };
|
433 |
|
434 | case "setItems": {
|
435 | return { ...state, items: action.items };
|
436 | }
|
437 | default:
|
438 | throw new Error();
|
439 | }
|
440 | }
|
441 |
|
442 | function useAction<T extends (...args: any[]) => any>(fn: T) {
|
443 | return React.useCallback(fn, []);
|
444 | }
|
445 |
|
446 | function useIsUnmountedRef() {
|
447 | const isUnmountedRef = React.useRef(false);
|
448 | useIsomorphicEffect(() => {
|
449 | return () => {
|
450 | isUnmountedRef.current = true;
|
451 | };
|
452 | }, []);
|
453 | return isUnmountedRef;
|
454 | }
|
455 |
|
456 | export function useCompositeState(
|
457 | initialState: SealedInitialState<CompositeInitialState> = {}
|
458 | ): CompositeStateReturn {
|
459 | const {
|
460 | unstable_virtual: virtual = false,
|
461 | rtl = false,
|
462 | orientation,
|
463 | currentId,
|
464 | loop = false,
|
465 | wrap = false,
|
466 | shift = false,
|
467 | unstable_includesBaseElement,
|
468 | ...sealed
|
469 | } = useSealedState(initialState);
|
470 | const idState = unstable_useIdState(sealed);
|
471 | const [
|
472 | {
|
473 | pastIds,
|
474 | initialVirtual,
|
475 | initialRTL,
|
476 | initialOrientation,
|
477 | initialCurrentId,
|
478 | initialLoop,
|
479 | initialWrap,
|
480 | initialShift,
|
481 | hasSetCurrentId,
|
482 | ...state
|
483 | },
|
484 | dispatch,
|
485 | ] = React.useReducer(reducer, {
|
486 | unstable_virtual: virtual,
|
487 | rtl,
|
488 | orientation,
|
489 | items: [],
|
490 | groups: [],
|
491 | currentId,
|
492 | loop,
|
493 | wrap,
|
494 | shift,
|
495 | unstable_moves: 0,
|
496 | pastIds: [],
|
497 | unstable_includesBaseElement:
|
498 | unstable_includesBaseElement ?? currentId === null,
|
499 | initialVirtual: virtual,
|
500 | initialRTL: rtl,
|
501 | initialOrientation: orientation,
|
502 | initialCurrentId: currentId,
|
503 | initialLoop: loop,
|
504 | initialWrap: wrap,
|
505 | initialShift: shift,
|
506 | });
|
507 | const [hasActiveWidget, setHasActiveWidget] = React.useState(false);
|
508 |
|
509 |
|
510 |
|
511 |
|
512 | const isUnmountedRef = useIsUnmountedRef();
|
513 |
|
514 | const setItems = React.useCallback(
|
515 | (items: Item[]) => dispatch({ type: "setItems", items }),
|
516 | []
|
517 | );
|
518 | useSortBasedOnDOMPosition(state.items, setItems);
|
519 |
|
520 | return {
|
521 | ...idState,
|
522 | ...state,
|
523 | unstable_hasActiveWidget: hasActiveWidget,
|
524 | unstable_setHasActiveWidget: setHasActiveWidget,
|
525 | registerItem: useAction((item) => {
|
526 | if (isUnmountedRef.current) return;
|
527 | dispatch({ type: "registerItem", item });
|
528 | }),
|
529 | unregisterItem: useAction((id) => {
|
530 | if (isUnmountedRef.current) return;
|
531 | dispatch({ type: "unregisterItem", id });
|
532 | }),
|
533 | registerGroup: useAction((group) => {
|
534 | if (isUnmountedRef.current) return;
|
535 | dispatch({ type: "registerGroup", group });
|
536 | }),
|
537 | unregisterGroup: useAction((id) => {
|
538 | if (isUnmountedRef.current) return;
|
539 | dispatch({ type: "unregisterGroup", id });
|
540 | }),
|
541 | move: useAction((id) => dispatch({ type: "move", id })),
|
542 | next: useAction((allTheWay) => dispatch({ type: "next", allTheWay })),
|
543 | previous: useAction((allTheWay) =>
|
544 | dispatch({ type: "previous", allTheWay })
|
545 | ),
|
546 | up: useAction((allTheWay) => dispatch({ type: "up", allTheWay })),
|
547 | down: useAction((allTheWay) => dispatch({ type: "down", allTheWay })),
|
548 | first: useAction(() => dispatch({ type: "first" })),
|
549 | last: useAction(() => dispatch({ type: "last" })),
|
550 | sort: useAction(() => dispatch({ type: "sort" })),
|
551 | unstable_setVirtual: useAction((value) =>
|
552 | dispatch({ type: "setVirtual", virtual: value })
|
553 | ),
|
554 | setRTL: useAction((value) => dispatch({ type: "setRTL", rtl: value })),
|
555 | setOrientation: useAction((value) =>
|
556 | dispatch({ type: "setOrientation", orientation: value })
|
557 | ),
|
558 | setCurrentId: useAction((value) =>
|
559 | dispatch({ type: "setCurrentId", currentId: value })
|
560 | ),
|
561 | setLoop: useAction((value) => dispatch({ type: "setLoop", loop: value })),
|
562 | setWrap: useAction((value) => dispatch({ type: "setWrap", wrap: value })),
|
563 | setShift: useAction((value) =>
|
564 | dispatch({ type: "setShift", shift: value })
|
565 | ),
|
566 | unstable_setIncludesBaseElement: useAction((value) =>
|
567 | dispatch({ type: "setIncludesBaseElement", includesBaseElement: value })
|
568 | ),
|
569 | reset: useAction(() => dispatch({ type: "reset" })),
|
570 | };
|
571 | }
|
572 |
|
573 | export type CompositeState = unstable_IdState & {
|
574 | |
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 | unstable_virtual: boolean;
|
583 | |
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 | rtl: boolean;
|
590 | |
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 | orientation?: Orientation;
|
602 | |
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 | items: Item[];
|
614 | |
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 | groups: Group[];
|
626 | |
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 | currentId?: string | null;
|
644 | |
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 | loop: boolean | Orientation;
|
669 | |
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 | wrap: boolean | Orientation;
|
682 | |
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 | shift: boolean;
|
689 | |
690 |
|
691 |
|
692 |
|
693 |
|
694 | unstable_moves: number;
|
695 | |
696 |
|
697 |
|
698 |
|
699 | unstable_hasActiveWidget: boolean;
|
700 | |
701 |
|
702 |
|
703 |
|
704 | unstable_includesBaseElement: boolean;
|
705 | };
|
706 |
|
707 | export type CompositeActions = unstable_IdActions & {
|
708 | |
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 | registerItem: (item: Item) => void;
|
719 | |
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 | unregisterItem: (id: string) => void;
|
730 | |
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 | registerGroup: (group: Group) => void;
|
741 | |
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 | unregisterGroup: (id: string) => void;
|
752 | |
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 | move: (id: string | null) => void;
|
759 | |
760 |
|
761 |
|
762 | next: (unstable_allTheWay?: boolean) => void;
|
763 | |
764 |
|
765 |
|
766 | previous: (unstable_allTheWay?: boolean) => void;
|
767 | |
768 |
|
769 |
|
770 | up: (unstable_allTheWay?: boolean) => void;
|
771 | |
772 |
|
773 |
|
774 | down: (unstable_allTheWay?: boolean) => void;
|
775 | |
776 |
|
777 |
|
778 | first: () => void;
|
779 | |
780 |
|
781 |
|
782 | last: () => void;
|
783 | |
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 | sort: () => void;
|
790 | |
791 |
|
792 |
|
793 | unstable_setVirtual: React.Dispatch<
|
794 | React.SetStateAction<CompositeState["unstable_virtual"]>
|
795 | >;
|
796 | |
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 | setRTL: React.Dispatch<React.SetStateAction<CompositeState["rtl"]>>;
|
803 | |
804 |
|
805 |
|
806 | setOrientation: React.Dispatch<
|
807 | React.SetStateAction<CompositeState["orientation"]>
|
808 | >;
|
809 | |
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 | setCurrentId: React.Dispatch<
|
820 | React.SetStateAction<CompositeState["currentId"]>
|
821 | >;
|
822 | |
823 |
|
824 |
|
825 | setLoop: React.Dispatch<React.SetStateAction<CompositeState["loop"]>>;
|
826 | |
827 |
|
828 |
|
829 | setWrap: React.Dispatch<React.SetStateAction<CompositeState["wrap"]>>;
|
830 | |
831 |
|
832 |
|
833 | setShift: React.Dispatch<React.SetStateAction<CompositeState["shift"]>>;
|
834 | |
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 | reset: () => void;
|
849 | |
850 |
|
851 |
|
852 |
|
853 | unstable_setIncludesBaseElement: React.Dispatch<
|
854 | React.SetStateAction<CompositeState["unstable_includesBaseElement"]>
|
855 | >;
|
856 | |
857 |
|
858 |
|
859 |
|
860 | unstable_setHasActiveWidget: React.Dispatch<
|
861 | React.SetStateAction<CompositeState["unstable_hasActiveWidget"]>
|
862 | >;
|
863 | };
|
864 |
|
865 | export type CompositeInitialState = unstable_IdInitialState &
|
866 | Partial<
|
867 | Pick<
|
868 | CompositeState,
|
869 | | "unstable_virtual"
|
870 | | "rtl"
|
871 | | "orientation"
|
872 | | "currentId"
|
873 | | "loop"
|
874 | | "wrap"
|
875 | | "shift"
|
876 | | "unstable_includesBaseElement"
|
877 | >
|
878 | >;
|
879 |
|
880 | export type CompositeStateReturn = unstable_IdStateReturn &
|
881 | CompositeState &
|
882 | CompositeActions;
|