@vuu-ui/vuu-ui-controls 0.8.7-debug → 0.8.8-debug
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/cjs/index.js +3790 -5243
- package/cjs/index.js.map +4 -4
- package/esm/index.js +3793 -5288
- package/esm/index.js.map +4 -4
- package/index.css +206 -577
- package/index.css.map +3 -3
- package/package.json +7 -6
- package/types/common-hooks/index.d.ts +1 -0
- package/types/{tree → common-hooks}/use-resize-observer.d.ts +1 -0
- package/types/drag-drop/drop-target-utils.d.ts +10 -1
- package/types/drag-drop/index.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/list/CheckboxIcon.d.ts +6 -0
- package/types/list/Highlighter.d.ts +7 -0
- package/types/list/List.d.ts +7 -0
- package/types/list/ListItem.d.ts +5 -0
- package/types/list/ListItemGroup.d.ts +6 -0
- package/types/list/ListItemHeader.d.ts +5 -0
- package/types/list/VirtualizedList.d.ts +7 -0
- package/types/list/common-hooks/collectionProvider.d.ts +13 -0
- package/types/list/common-hooks/collectionTypes.d.ts +56 -0
- package/types/list/common-hooks/index.d.ts +15 -0
- package/types/list/common-hooks/itemToString.d.ts +2 -0
- package/types/list/common-hooks/keyUtils.d.ts +15 -0
- package/types/list/common-hooks/list-dom-utils.d.ts +6 -0
- package/types/list/common-hooks/navigationTypes.d.ts +37 -0
- package/types/list/common-hooks/selectionTypes.d.ts +42 -0
- package/types/list/common-hooks/useCollapsibleGroups.d.ts +14 -0
- package/types/list/common-hooks/useCollectionItems.d.ts +2 -0
- package/types/list/common-hooks/useImperativeScrollingAPI.d.ts +14 -0
- package/types/list/common-hooks/useKeyboardNavigation.d.ts +4 -0
- package/types/list/common-hooks/useSelection.d.ts +8 -0
- package/types/list/common-hooks/useTypeahead.d.ts +15 -0
- package/types/list/common-hooks/useViewportTracking.d.ts +14 -0
- package/types/list/common-hooks/utils/collection-item-utils.d.ts +21 -0
- package/types/list/common-hooks/utils/filter-utils.d.ts +4 -0
- package/types/list/common-hooks/utils/index.d.ts +3 -0
- package/types/list/common-hooks/utils/isSelected.d.ts +2 -0
- package/types/list/index.d.ts +8 -0
- package/types/list/keyset.d.ts +9 -0
- package/types/list/listTypes.d.ts +206 -0
- package/types/list/useList.d.ts +3 -0
- package/types/list/useListHeight.d.ts +19 -0
- package/types/list/useScrollPosition.d.ts +19 -0
- package/types/list/useVirtualization.d.ts +15 -0
- package/types/utils/escapeRegExp.d.ts +1 -0
- package/types/utils/index.d.ts +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { CollectionItem, CollectionOptions } from "../collectionTypes";
|
|
3
|
+
export declare const sourceItemHasProp: (item: unknown, propertyName: string) => boolean;
|
|
4
|
+
export declare const isHeader: (item: unknown) => boolean;
|
|
5
|
+
export declare const isGroupNode: (item: unknown) => boolean;
|
|
6
|
+
export declare const isDisabled: (item: unknown) => boolean;
|
|
7
|
+
export declare const isFocusable: (item: unknown) => boolean;
|
|
8
|
+
export declare const countChildItems: <Item>(item: CollectionItem<Item>, items: CollectionItem<Item>[], idx: number) => number;
|
|
9
|
+
export declare const getChildLabel: (element: ReactElement<{
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
label?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
}>) => string | undefined;
|
|
14
|
+
export declare const childIsGroup: (child: ReactElement) => boolean;
|
|
15
|
+
export declare const getChildNodes: (element: ReactElement) => CollectionItem<ReactElement>[] | undefined;
|
|
16
|
+
type CollectionItemWithoutId<T> = Omit<CollectionItem<T>, "id">;
|
|
17
|
+
export declare const sourceItems: <T>(source?: readonly T[] | undefined, options?: CollectionOptions<T> | undefined) => CollectionItemWithoutId<T>[] | undefined;
|
|
18
|
+
export declare const childItems: (children: ReactNode) => CollectionItem<ReactElement>[] | undefined;
|
|
19
|
+
export declare const isParentPath: (parentPath: string, childPath: string) => boolean;
|
|
20
|
+
export declare function replaceCollectionItem<Item>(nodes: CollectionItem<Item>[], id: string, props: Partial<CollectionItem<Item>>): CollectionItem<Item>[];
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type GetFilterRegex = (inputValue: string) => RegExp;
|
|
2
|
+
export type FilterPredicate = (item: string) => boolean;
|
|
3
|
+
export declare const getDefaultFilterRegex: GetFilterRegex;
|
|
4
|
+
export declare const getDefaultFilter: (inputValue?: string, getFilterRegex?: GetFilterRegex) => (itemValue?: string) => boolean;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import React, { FocusEventHandler, ForwardedRef, HTMLAttributes, KeyboardEvent, KeyboardEventHandler, MouseEventHandler, PropsWithChildren, Ref, RefObject } from "react";
|
|
2
|
+
import { CollectionHookResult, CollectionItem, ListHandlers, NavigationHookResult, ScrollingAPI, SelectHandler, SelectionChangeHandler, SelectionHookResult, SelectionProps, SelectionStrategy, ViewportTrackingResult } from "./common-hooks";
|
|
3
|
+
import { DragHookResult, dragStrategy } from "../drag-drop";
|
|
4
|
+
import { ViewportRange } from "./useScrollPosition";
|
|
5
|
+
export type ComponentType<T = unknown> = (props: PropsWithChildren<T>) => JSX.Element;
|
|
6
|
+
export type ListItemType<T = unknown> = ComponentType<ListItemProps<T> & {
|
|
7
|
+
ref?: Ref<HTMLDivElement>;
|
|
8
|
+
}>;
|
|
9
|
+
export interface ListItemProps<T = unknown> extends HTMLAttributes<HTMLDivElement> {
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
item?: T;
|
|
13
|
+
itemHeight?: number;
|
|
14
|
+
itemTextHighlightPattern?: RegExp | string;
|
|
15
|
+
label?: string;
|
|
16
|
+
showCheckbox?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* selectable is a marker, used by List, not used by ListItem itself
|
|
19
|
+
*/
|
|
20
|
+
selectable?: boolean;
|
|
21
|
+
selected?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Will apply transform: translate style. Used for virtualised rendering,
|
|
24
|
+
* supplied by VirtualisedList.
|
|
25
|
+
*/
|
|
26
|
+
translate3d?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ListScrollHandles<Item> {
|
|
29
|
+
scrollToIndex: (itemIndex: number) => void;
|
|
30
|
+
scrollToItem: (item: Item) => void;
|
|
31
|
+
scrollTo: (scrollOffset: number) => void;
|
|
32
|
+
}
|
|
33
|
+
export interface ListProps<Item = string, Selection extends SelectionStrategy = "default"> extends SelectionProps<Item, Selection>, Omit<HTMLAttributes<HTMLDivElement>, "onSelect" | "defaultValue"> {
|
|
34
|
+
/**
|
|
35
|
+
* The component used to render a ListItem instead of the default. This must itself render a ListItem,
|
|
36
|
+
* must implement props that extend ListItemProps and must forward ListItem props to the ListItem.
|
|
37
|
+
*/
|
|
38
|
+
ListItem?: ListItemType<Item>;
|
|
39
|
+
/**
|
|
40
|
+
* The component used when there are no items.
|
|
41
|
+
*/
|
|
42
|
+
ListPlaceholder?: ComponentType<HTMLAttributes<unknown>>;
|
|
43
|
+
/**
|
|
44
|
+
* ListItems can be re-ordered by drag drop.
|
|
45
|
+
*/
|
|
46
|
+
allowDragDrop?: boolean | dragStrategy;
|
|
47
|
+
borderless?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Adds checkbox to list. Defaults to true for multiselect strategy. Only supported for
|
|
50
|
+
* multiple select strategies (multi selection and extended selection)
|
|
51
|
+
*/
|
|
52
|
+
checkable?: boolean;
|
|
53
|
+
className?: string;
|
|
54
|
+
collapsibleHeaders?: boolean;
|
|
55
|
+
defaultHighlightedIndex?: number;
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
disableFocus?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Use to turn off typeahead search functionality within List. Defaulst to false;
|
|
60
|
+
*/
|
|
61
|
+
disableTypeToSelect?: boolean;
|
|
62
|
+
displayedItemCount?: number;
|
|
63
|
+
emptyMessage?: string;
|
|
64
|
+
focusVisible?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Used for providing customized item height. It should return a number or a string if item height
|
|
67
|
+
* is in percentage. .
|
|
68
|
+
*
|
|
69
|
+
* @param {number} index The item index.
|
|
70
|
+
*/
|
|
71
|
+
getItemHeight?: (index: number) => number;
|
|
72
|
+
/**
|
|
73
|
+
* Used for providing customized item ids.
|
|
74
|
+
* deprecated
|
|
75
|
+
* @param {number} index The item index.
|
|
76
|
+
*/
|
|
77
|
+
getItemId?: (index: number) => string;
|
|
78
|
+
/**
|
|
79
|
+
* Height of the component.
|
|
80
|
+
*/
|
|
81
|
+
height?: number | string;
|
|
82
|
+
highlightedIndex?: number;
|
|
83
|
+
/**
|
|
84
|
+
* The total number of items.
|
|
85
|
+
*
|
|
86
|
+
* Used for keyboard navigation (when `End` key is pressed) and when the list is virtualized.
|
|
87
|
+
*/
|
|
88
|
+
itemCount?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Size of the gap between list items. Defaults to zero.
|
|
91
|
+
*/
|
|
92
|
+
itemGapSize?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Height of an item. I can be a number or a string if item height is in percentage. If omitted
|
|
95
|
+
* default height values from Salt theme will be used.
|
|
96
|
+
*
|
|
97
|
+
* Note that when using a percentage value, the list must have a height.
|
|
98
|
+
*/
|
|
99
|
+
itemHeight?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Used for providing text highlight.
|
|
102
|
+
*
|
|
103
|
+
* It can be a capturing regex or a string for a straightforward string matching.
|
|
104
|
+
*/
|
|
105
|
+
itemTextHighlightPattern?: RegExp | string;
|
|
106
|
+
/**
|
|
107
|
+
* Item `toString` function when list is not used declaratively and its items are objects
|
|
108
|
+
* instead of strings. The string value is also used in tooltip when item text is truncated.
|
|
109
|
+
*
|
|
110
|
+
* If omitted, component will look for a `label` property on the data object.
|
|
111
|
+
*
|
|
112
|
+
* @param {object} item The item.
|
|
113
|
+
*/
|
|
114
|
+
itemToString?: (item: Item) => string;
|
|
115
|
+
listHandlers?: ListHandlers;
|
|
116
|
+
/**
|
|
117
|
+
* Maximum list height.
|
|
118
|
+
*/
|
|
119
|
+
maxHeight?: number | string;
|
|
120
|
+
/**
|
|
121
|
+
* Maximum list width.
|
|
122
|
+
*/
|
|
123
|
+
maxWidth?: number | string;
|
|
124
|
+
/**
|
|
125
|
+
* Minimum list height.
|
|
126
|
+
*/
|
|
127
|
+
minHeight?: number | string;
|
|
128
|
+
/**
|
|
129
|
+
* Minimum list width.
|
|
130
|
+
*/
|
|
131
|
+
minWidth?: number | string;
|
|
132
|
+
onHighlight?: (index: number) => void;
|
|
133
|
+
onMoveListItem?: (fromIndex: number, toIndex: number) => void;
|
|
134
|
+
onViewportScroll?: (firstVisibleRowIndex: number, lastVisibleRowIndex: number) => void;
|
|
135
|
+
/**
|
|
136
|
+
* If `true`, the component will remember the last keyboard-interacted position
|
|
137
|
+
* and highlight it when list is focused again.
|
|
138
|
+
*/
|
|
139
|
+
restoreLastFocus?: boolean;
|
|
140
|
+
scrollingApiRef?: ForwardedRef<ScrollingAPI<Item>>;
|
|
141
|
+
/**
|
|
142
|
+
* The keyboard keys used to effect selection, defaults to SPACE and ENTER
|
|
143
|
+
* TODO maybe this belongs on the SelectionProps interface ?
|
|
144
|
+
*/
|
|
145
|
+
selectionKeys?: string[];
|
|
146
|
+
showEmptyMessage?: boolean;
|
|
147
|
+
source?: ReadonlyArray<Item>;
|
|
148
|
+
stickyHeaders?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* When set to `true`, 'Tab' key selects current highlighted item before focus is blurred away
|
|
151
|
+
* from the component. This would be the desirable behaviour for any dropdown menu based
|
|
152
|
+
* components like dropdown, combobox.
|
|
153
|
+
*
|
|
154
|
+
* @default false
|
|
155
|
+
*/
|
|
156
|
+
tabToSelect?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Width of the component.
|
|
159
|
+
*/
|
|
160
|
+
width?: number | string;
|
|
161
|
+
}
|
|
162
|
+
export interface ListControlProps {
|
|
163
|
+
"aria-activedescendant"?: string;
|
|
164
|
+
onBlur: FocusEventHandler;
|
|
165
|
+
onFocus: FocusEventHandler;
|
|
166
|
+
onKeyDown: KeyboardEventHandler;
|
|
167
|
+
onMouseDown?: MouseEventHandler;
|
|
168
|
+
onMouseDownCapture: MouseEventHandler;
|
|
169
|
+
onMouseLeave: MouseEventHandler;
|
|
170
|
+
}
|
|
171
|
+
export interface ListHookProps<Item, Selection extends SelectionStrategy> extends Omit<SelectionProps<CollectionItem<Item>, Selection>, "onSelect" | "onSelectionChange"> {
|
|
172
|
+
allowDragDrop?: boolean | dragStrategy;
|
|
173
|
+
collapsibleHeaders?: boolean;
|
|
174
|
+
collectionHook: CollectionHookResult<Item>;
|
|
175
|
+
containerRef: RefObject<HTMLElement>;
|
|
176
|
+
contentRef?: RefObject<HTMLElement>;
|
|
177
|
+
defaultHighlightedIndex?: number;
|
|
178
|
+
disabled?: boolean;
|
|
179
|
+
disableAriaActiveDescendant?: boolean;
|
|
180
|
+
disableHighlightOnFocus?: boolean;
|
|
181
|
+
disableTypeToSelect?: boolean;
|
|
182
|
+
focusVisible?: boolean;
|
|
183
|
+
highlightedIndex?: number;
|
|
184
|
+
id?: string;
|
|
185
|
+
label?: string;
|
|
186
|
+
listHandlers?: ListHandlers;
|
|
187
|
+
onHighlight?: (index: number) => void;
|
|
188
|
+
onKeyboardNavigation?: (event: React.KeyboardEvent, currentIndex: number) => void;
|
|
189
|
+
onKeyDown?: (evt: KeyboardEvent) => void;
|
|
190
|
+
onMoveListItem?: (fromIndex: number, toIndex: number) => void;
|
|
191
|
+
onSelect?: SelectHandler<Item>;
|
|
192
|
+
onSelectionChange?: SelectionChangeHandler<Item, Selection>;
|
|
193
|
+
restoreLastFocus?: boolean;
|
|
194
|
+
selectionKeys?: string[];
|
|
195
|
+
stickyHeaders?: boolean;
|
|
196
|
+
tabToSelect?: boolean;
|
|
197
|
+
viewportRange?: ViewportRange;
|
|
198
|
+
}
|
|
199
|
+
export interface ListHookResult<Item, Selection extends SelectionStrategy> extends Partial<ViewportTrackingResult<Item>>, Pick<SelectionHookResult<Item, Selection>, "selected" | "setSelected">, Partial<Omit<NavigationHookResult, "listProps">>, Omit<DragHookResult, "isDragging" | "isScrolling"> {
|
|
200
|
+
keyboardNavigation: RefObject<boolean>;
|
|
201
|
+
listHandlers: ListHandlers;
|
|
202
|
+
listItemHeaderHandlers: Partial<ListHandlers>;
|
|
203
|
+
listControlProps: ListControlProps;
|
|
204
|
+
setHighlightedIndex: (index: number) => void;
|
|
205
|
+
setIgnoreFocus: (ignoreFocus: boolean) => void;
|
|
206
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SelectionStrategy } from "./common-hooks";
|
|
2
|
+
import { ListHookProps, ListHookResult } from "./listTypes";
|
|
3
|
+
export declare const useList: <Item, Selection_1 extends SelectionStrategy = "default">({ allowDragDrop, collapsibleHeaders, collectionHook: dataHook, containerRef, contentRef, defaultHighlightedIndex, defaultSelected, disabled, disableAriaActiveDescendant, disableHighlightOnFocus, disableTypeToSelect, highlightedIndex: highlightedIndexProp, id, label, listHandlers: listHandlersProp, onHighlight, onKeyboardNavigation, onKeyDown, onMoveListItem, onSelect, onSelectionChange, restoreLastFocus, selected, selectionStrategy, selectionKeys, stickyHeaders, tabToSelect, viewportRange, }: ListHookProps<Item, Selection_1>) => ListHookResult<Item, Selection_1>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
export interface ListHeightHookProps {
|
|
3
|
+
borderless?: boolean;
|
|
4
|
+
displayedItemCount: number;
|
|
5
|
+
getItemHeight?: (index: number) => number;
|
|
6
|
+
height?: number | string;
|
|
7
|
+
itemCount: number;
|
|
8
|
+
itemGapSize: number;
|
|
9
|
+
itemHeight?: number;
|
|
10
|
+
rootRef: RefObject<HTMLElement>;
|
|
11
|
+
rowHeightRef: RefObject<HTMLElement | null>;
|
|
12
|
+
}
|
|
13
|
+
export interface HeightHookResult {
|
|
14
|
+
contentHeight: number;
|
|
15
|
+
listClientHeight?: number;
|
|
16
|
+
listItemHeight: number;
|
|
17
|
+
listHeight: number | string;
|
|
18
|
+
}
|
|
19
|
+
export declare const useListHeight: ({ borderless, displayedItemCount, getItemHeight, height, itemCount, itemGapSize, itemHeight: itemHeightProp, rootRef, rowHeightRef, }: ListHeightHookProps) => HeightHookResult;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { UIEvent } from "react";
|
|
2
|
+
export type ViewportRange = {
|
|
3
|
+
atEnd: boolean;
|
|
4
|
+
atStart: boolean;
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
};
|
|
8
|
+
interface ScrollPositionHookProps {
|
|
9
|
+
containerSize: number;
|
|
10
|
+
itemCount: number;
|
|
11
|
+
itemGapSize?: number;
|
|
12
|
+
itemSize: number;
|
|
13
|
+
onViewportScroll?: (firstVisibleItemIndex: number, lastVisibleitemIndex: number) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const useScrollPosition: ({ containerSize: listHeight, itemCount: listItemCount, itemGapSize: listItemGapSize, itemSize: listItemHeight, onViewportScroll, }: ScrollPositionHookProps) => {
|
|
16
|
+
onVerticalScroll: (e: UIEvent<HTMLElement>) => void;
|
|
17
|
+
viewportRange: ViewportRange;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CollectionItem } from "./common-hooks";
|
|
2
|
+
import { ViewportRange } from "./useScrollPosition";
|
|
3
|
+
/**
|
|
4
|
+
* [ item key, total height before the item, next row index, CollectionItem<Item>]
|
|
5
|
+
* e.g. first item: [0, 0, 1, data[0]]
|
|
6
|
+
*/
|
|
7
|
+
export type Row<Item> = [number, number, number, CollectionItem<Item>];
|
|
8
|
+
interface VirtualizationHookProps<Item> {
|
|
9
|
+
data: CollectionItem<Item>[];
|
|
10
|
+
listItemGapSize?: number;
|
|
11
|
+
listItemHeight: number;
|
|
12
|
+
viewportRange: ViewportRange;
|
|
13
|
+
}
|
|
14
|
+
export declare const useVirtualization: <Item>({ data, listItemGapSize, listItemHeight, viewportRange, }: VirtualizationHookProps<Item>) => Row<Item>[];
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeRegExp(string: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./escapeRegExp";
|