@react-fabric/data 1.0.0-beta.1 → 1.0.0-beta.12
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/dist/cjs/checklist/CheckList.js +143 -0
- package/dist/cjs/histogram/Histogram.js +14 -5
- package/dist/cjs/hooks/useSelectableList.js +54 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/table/BodyCell.js +35 -3
- package/dist/cjs/table/BodyRow.js +107 -0
- package/dist/cjs/table/HeaderCell.js +4 -3
- package/dist/cjs/table/Table.js +84 -49
- package/dist/cjs/table/useVirtualTable.js +16 -2
- package/dist/cjs/tree/TreePanel.js +14 -2
- package/dist/cjs/tree/useTree.js +7 -0
- package/dist/cjs/virtual/Gallery.js +11 -4
- package/dist/cjs/virtual/List.js +11 -4
- package/dist/esm/checklist/CheckList.js +143 -0
- package/dist/esm/histogram/Histogram.js +14 -5
- package/dist/esm/hooks/useSelectableList.js +54 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/table/BodyCell.js +35 -3
- package/dist/esm/table/BodyRow.js +107 -0
- package/dist/esm/table/HeaderCell.js +4 -3
- package/dist/esm/table/Table.js +85 -50
- package/dist/esm/table/useVirtualTable.js +16 -2
- package/dist/esm/tree/TreePanel.js +15 -3
- package/dist/esm/tree/useTree.js +7 -0
- package/dist/esm/virtual/Gallery.js +11 -4
- package/dist/esm/virtual/List.js +11 -4
- package/dist/types/checklist/CheckList.d.ts +30 -0
- package/dist/types/histogram/Histogram.d.ts +3 -3
- package/dist/types/hooks/useSelectableList.d.ts +28 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/table/AddColumn.d.ts +2 -2
- package/dist/types/table/BodyCell.d.ts +4 -3
- package/dist/types/table/BodyRow.d.ts +20 -0
- package/dist/types/table/EmptyCell.d.ts +2 -2
- package/dist/types/table/HeaderCell.d.ts +2 -2
- package/dist/types/table/Table.d.ts +1 -1
- package/dist/types/table/types.d.ts +19 -7
- package/dist/types/table/useTableColumns.d.ts +6 -6
- package/dist/types/table/useVirtualTable.d.ts +5 -1
- package/dist/types/tree/TreePanel.d.ts +1 -1
- package/dist/types/tree/types.d.ts +6 -2
- package/dist/types/tree/useTree.d.ts +1 -0
- package/dist/types/virtual/Gallery.d.ts +3 -2
- package/dist/types/virtual/List.d.ts +3 -2
- package/package.json +6 -5
- package/src/checklist/CheckList.tsx +222 -0
- package/src/histogram/Histogram.tsx +7 -2
- package/src/hooks/useSelectableList.ts +94 -0
- package/src/index.ts +3 -0
- package/src/table/AddColumn.tsx +2 -2
- package/src/table/BodyCell.tsx +30 -3
- package/src/table/BodyRow.tsx +142 -0
- package/src/table/EmptyCell.tsx +2 -2
- package/src/table/HeaderCell.tsx +4 -3
- package/src/table/Table.tsx +103 -56
- package/src/table/types.ts +23 -6
- package/src/table/useTableColumns.ts +7 -7
- package/src/table/useVirtualTable.ts +19 -5
- package/src/tree/TreePanel.tsx +12 -1
- package/src/tree/types.ts +8 -1
- package/src/tree/useTree.ts +5 -0
- package/src/virtual/Gallery.tsx +4 -1
- package/src/virtual/List.tsx +4 -1
package/src/table/types.ts
CHANGED
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
25
|
type CssProp,
|
|
26
|
+
type Elements,
|
|
26
27
|
type IconProps,
|
|
28
|
+
type RefProp,
|
|
27
29
|
type TestProps,
|
|
28
30
|
} from "@react-fabric/core/dist/types/types";
|
|
29
31
|
import { type ReactElement } from "react";
|
|
@@ -32,12 +34,13 @@ export const COL_MIN_WIDTH = "3rem";
|
|
|
32
34
|
export const COL_MAX_WIDTH = "64rem";
|
|
33
35
|
export const COL_DEFAULT_WIDTH = "12rem";
|
|
34
36
|
|
|
35
|
-
export interface
|
|
37
|
+
export interface TableColumn<T = KeyValue>
|
|
36
38
|
extends CssProp,
|
|
37
39
|
IconProps,
|
|
38
40
|
TestProps {
|
|
39
|
-
id: keyof T;
|
|
41
|
+
id: keyof T | string;
|
|
40
42
|
label?: string;
|
|
43
|
+
tooltip?: string;
|
|
41
44
|
actions?: ReactElement;
|
|
42
45
|
align?: "start" | "center" | "end";
|
|
43
46
|
locked?: "start" | "end";
|
|
@@ -59,13 +62,21 @@ export interface ColumnType<T = KeyValue>
|
|
|
59
62
|
| "time"
|
|
60
63
|
| "unknown";
|
|
61
64
|
format?: string;
|
|
62
|
-
|
|
65
|
+
valueMap?: KeyValue;
|
|
66
|
+
renderer?: (value: AnyObject, data: T, index: number) => Elements<AnyObject>;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
export interface
|
|
66
|
-
|
|
69
|
+
export interface TableRef {
|
|
70
|
+
hilight: (row: number) => void;
|
|
71
|
+
unhilight: () => void;
|
|
72
|
+
scrollTo: (row: number) => void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface TableProps<T = KeyValue> extends RefProp<TableRef> {
|
|
76
|
+
columns: Array<TableColumn<T>>;
|
|
67
77
|
data: T[];
|
|
68
|
-
keyProperty
|
|
78
|
+
keyProperty?: keyof T;
|
|
79
|
+
emptyDisplay?: ReactElement;
|
|
69
80
|
/**
|
|
70
81
|
* checkable rows
|
|
71
82
|
*/
|
|
@@ -81,4 +92,10 @@ export interface TableProps<T = KeyValue> {
|
|
|
81
92
|
hideableColumns?: boolean;
|
|
82
93
|
|
|
83
94
|
onRowClick?: (data: T) => void;
|
|
95
|
+
|
|
96
|
+
initialScroll?: number;
|
|
97
|
+
onScroll?: (firstItem: number) => void;
|
|
98
|
+
|
|
99
|
+
canExpand?: (record: T) => boolean;
|
|
100
|
+
children?: (record: T) => Elements<AnyObject>;
|
|
84
101
|
}
|
|
@@ -23,20 +23,20 @@
|
|
|
23
23
|
|
|
24
24
|
import { groupBy } from "@react-fabric/utilities";
|
|
25
25
|
import { useEffect, useReducer } from "react";
|
|
26
|
-
import { type
|
|
26
|
+
import { type TableColumn } from "./types";
|
|
27
27
|
|
|
28
28
|
interface ColumnState {
|
|
29
|
-
columns:
|
|
30
|
-
start:
|
|
31
|
-
end:
|
|
32
|
-
cols:
|
|
29
|
+
columns: TableColumn[];
|
|
30
|
+
start: TableColumn[];
|
|
31
|
+
end: TableColumn[];
|
|
32
|
+
cols: TableColumn[];
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
type ColumnActions =
|
|
36
|
-
| { type: "columns"; columns:
|
|
36
|
+
| { type: "columns"; columns: TableColumn[] }
|
|
37
37
|
| { type: "hide"; id: string };
|
|
38
38
|
|
|
39
|
-
export const useTableColumns = (columns:
|
|
39
|
+
export const useTableColumns = (columns: TableColumn[]) => {
|
|
40
40
|
const [state, dispatch] = useReducer(
|
|
41
41
|
(state: ColumnState, action: ColumnActions) => {
|
|
42
42
|
if (action.type === "columns") {
|
|
@@ -25,16 +25,20 @@ import { useVirtualizer } from "@tanstack/react-virtual";
|
|
|
25
25
|
import { useCallback, useReducer, useRef } from "react";
|
|
26
26
|
|
|
27
27
|
interface DataState {
|
|
28
|
+
expanded: Key[];
|
|
28
29
|
checked: Key[];
|
|
29
30
|
allChecked: 0 | 1 | 2;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
type DataAction =
|
|
33
|
+
type DataAction =
|
|
34
|
+
| { type: "expand"; key: Key }
|
|
35
|
+
| { type: "check"; key: Key }
|
|
36
|
+
| { type: "checkall" };
|
|
33
37
|
|
|
34
38
|
export const useVirtualTable = (
|
|
35
39
|
data: KeyValue[],
|
|
36
|
-
keyProperty
|
|
37
|
-
onCheckChanged
|
|
40
|
+
keyProperty?: Key,
|
|
41
|
+
onCheckChanged?: (checked: Key[]) => void,
|
|
38
42
|
) => {
|
|
39
43
|
// TODO: refactor data into item list, apply grouping if groupColumn provided
|
|
40
44
|
// TODO: when grouping maintain map of group with children, {___GROUP___:true, label, items, open}
|
|
@@ -48,19 +52,25 @@ export const useVirtualTable = (
|
|
|
48
52
|
|
|
49
53
|
const [state, dispatch] = useReducer(
|
|
50
54
|
(state: DataState, action: DataAction) => {
|
|
55
|
+
if (action.type === "expand") {
|
|
56
|
+
if (state.expanded.includes(action.key))
|
|
57
|
+
state.expanded.splice(state.expanded.indexOf(action.key), 1);
|
|
58
|
+
else state.expanded.push(action.key);
|
|
59
|
+
}
|
|
51
60
|
if (action.type === "check") {
|
|
52
61
|
if (state.checked.includes(action.key))
|
|
53
62
|
state.checked.splice(state.checked.indexOf(action.key), 1);
|
|
54
63
|
else state.checked.push(action.key);
|
|
64
|
+
onCheckChanged?.(state.checked);
|
|
55
65
|
}
|
|
56
66
|
if (action.type === "checkall") {
|
|
57
67
|
if (state.allChecked !== 0) {
|
|
58
68
|
state.checked = [];
|
|
59
|
-
} else {
|
|
69
|
+
} else if (keyProperty) {
|
|
60
70
|
state.checked = data.map((item) => item[keyProperty]);
|
|
61
71
|
}
|
|
72
|
+
onCheckChanged?.(state.checked);
|
|
62
73
|
}
|
|
63
|
-
onCheckChanged(state.checked);
|
|
64
74
|
return {
|
|
65
75
|
...state,
|
|
66
76
|
allChecked:
|
|
@@ -73,6 +83,7 @@ export const useVirtualTable = (
|
|
|
73
83
|
},
|
|
74
84
|
{
|
|
75
85
|
checked: [],
|
|
86
|
+
expanded: [],
|
|
76
87
|
allChecked: 0,
|
|
77
88
|
},
|
|
78
89
|
);
|
|
@@ -91,8 +102,11 @@ export const useVirtualTable = (
|
|
|
91
102
|
items: virtualItems,
|
|
92
103
|
checkState: state,
|
|
93
104
|
getData,
|
|
105
|
+
virtualizer,
|
|
106
|
+
top: virtualizer.range?.startIndex,
|
|
94
107
|
totalSize: virtualizer.getTotalSize,
|
|
95
108
|
measureElement: virtualizer.measureElement,
|
|
109
|
+
toggleExpand: (key: Key) => dispatch({ type: "expand", key }),
|
|
96
110
|
toggleChecked: (key: Key) => dispatch({ type: "check", key }),
|
|
97
111
|
toggleAllChecked: () => dispatch({ type: "checkall" }),
|
|
98
112
|
};
|
package/src/tree/TreePanel.tsx
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
} from "@react-fabric/core";
|
|
32
32
|
import { Search } from "@react-fabric/form";
|
|
33
33
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
34
|
-
import { useMemo, useRef } from "react";
|
|
34
|
+
import { useImperativeHandle, useMemo, useRef } from "react";
|
|
35
35
|
import { TreeNode } from "./TreeNode";
|
|
36
36
|
import { iconCollapseAll, iconExpandAll, type TreePanelProps } from "./types";
|
|
37
37
|
import { useTree } from "./useTree";
|
|
@@ -39,6 +39,7 @@ import { useTree } from "./useTree";
|
|
|
39
39
|
// TODO: implement keyboard handler for navigating tree
|
|
40
40
|
|
|
41
41
|
export const TreePanel = <T extends KeyValue>({
|
|
42
|
+
ref,
|
|
42
43
|
items,
|
|
43
44
|
selected,
|
|
44
45
|
checked,
|
|
@@ -64,6 +65,7 @@ export const TreePanel = <T extends KeyValue>({
|
|
|
64
65
|
expandAll,
|
|
65
66
|
collapseAll,
|
|
66
67
|
select,
|
|
68
|
+
expand,
|
|
67
69
|
onFilter,
|
|
68
70
|
} = useTree({
|
|
69
71
|
items,
|
|
@@ -93,6 +95,15 @@ export const TreePanel = <T extends KeyValue>({
|
|
|
93
95
|
return [CoreIcons.expand, CoreIcons.collapse];
|
|
94
96
|
}, [expander]);
|
|
95
97
|
|
|
98
|
+
useImperativeHandle(
|
|
99
|
+
ref,
|
|
100
|
+
() => ({
|
|
101
|
+
open: (id: string) => expand(id),
|
|
102
|
+
select: (id: string) => expand(id),
|
|
103
|
+
}),
|
|
104
|
+
[],
|
|
105
|
+
);
|
|
106
|
+
|
|
96
107
|
return (
|
|
97
108
|
<Section>
|
|
98
109
|
<Header
|
package/src/tree/types.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
type CssProp,
|
|
28
28
|
type Elements,
|
|
29
29
|
type IconProps,
|
|
30
|
+
type RefProp,
|
|
30
31
|
type TestProps,
|
|
31
32
|
} from "@react-fabric/core/dist/types/types";
|
|
32
33
|
|
|
@@ -105,8 +106,14 @@ export interface TreeNodeProps extends ChildProp {
|
|
|
105
106
|
onChecked: (id: string) => void;
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
export interface TreeRef {
|
|
110
|
+
select: (id: string) => void;
|
|
111
|
+
open: (id: string) => void;
|
|
112
|
+
}
|
|
113
|
+
|
|
108
114
|
export interface TreePanelProps<T extends KeyValue = KeyValue>
|
|
109
|
-
extends TestProps
|
|
115
|
+
extends TestProps,
|
|
116
|
+
RefProp<TreeRef> {
|
|
110
117
|
items?: Array<TreeNodeType<T>>;
|
|
111
118
|
/**
|
|
112
119
|
* make tree searchable
|
package/src/tree/useTree.ts
CHANGED
|
@@ -203,6 +203,10 @@ export const useTree = <T extends KeyValue>({
|
|
|
203
203
|
dispatch({ type: "select", id });
|
|
204
204
|
}, []);
|
|
205
205
|
|
|
206
|
+
const expand = useCallback((id: string) => {
|
|
207
|
+
dispatch({ type: "expand", id });
|
|
208
|
+
}, []);
|
|
209
|
+
|
|
206
210
|
const expandAll = useCallback(() => {
|
|
207
211
|
dispatch({ type: "expandAll" });
|
|
208
212
|
}, []);
|
|
@@ -222,6 +226,7 @@ export const useTree = <T extends KeyValue>({
|
|
|
222
226
|
collapseAll,
|
|
223
227
|
toggleCheck,
|
|
224
228
|
select,
|
|
229
|
+
expand,
|
|
225
230
|
onFilter,
|
|
226
231
|
};
|
|
227
232
|
};
|
package/src/virtual/Gallery.tsx
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { Skeleton, useDebounce, useEffectDebugger } from "@react-fabric/core";
|
|
25
|
+
import { type TestProps } from "@react-fabric/core/dist/types/types";
|
|
25
26
|
import { debounce } from "@react-fabric/utilities";
|
|
26
27
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
27
28
|
import classNames from "classnames";
|
|
@@ -47,7 +48,7 @@ export interface VirtualGalleryRef {
|
|
|
47
48
|
unhilight: () => void;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
export interface VirtualGalleryProps<T> {
|
|
51
|
+
export interface VirtualGalleryProps<T> extends TestProps {
|
|
51
52
|
children: (props: {
|
|
52
53
|
data: T;
|
|
53
54
|
index: number;
|
|
@@ -108,6 +109,7 @@ const _VirtualGallery = <T extends KeyValue>({
|
|
|
108
109
|
onLoadMore,
|
|
109
110
|
onScroll,
|
|
110
111
|
galleryRef,
|
|
112
|
+
...aria
|
|
111
113
|
}: VirtualGalleryProps<T>) => {
|
|
112
114
|
const count = useDeferredValue(items.length);
|
|
113
115
|
const extraSize = useMemo(() => (onLoadMore ? 64 : 0), [onLoadMore]);
|
|
@@ -275,6 +277,7 @@ const _VirtualGallery = <T extends KeyValue>({
|
|
|
275
277
|
className={classNames(
|
|
276
278
|
"area-content bg-base overflow-auto contain-strict",
|
|
277
279
|
)}
|
|
280
|
+
{...aria}
|
|
278
281
|
>
|
|
279
282
|
<div
|
|
280
283
|
className={classNames(
|
package/src/virtual/List.tsx
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
import { Skeleton, useDebounce } from "@react-fabric/core";
|
|
32
|
+
import { type TestProps } from "@react-fabric/core/dist/types/types";
|
|
32
33
|
import { debounce } from "@react-fabric/utilities";
|
|
33
34
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
34
35
|
import classNames from "classnames";
|
|
@@ -54,7 +55,7 @@ export interface VirtualListRef {
|
|
|
54
55
|
unhilight: () => void;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
export interface VirtualListProps<T> {
|
|
58
|
+
export interface VirtualListProps<T> extends TestProps {
|
|
58
59
|
children: (props: {
|
|
59
60
|
data: T;
|
|
60
61
|
index: number;
|
|
@@ -120,6 +121,7 @@ const _VirtualList = <T extends KeyValue>({
|
|
|
120
121
|
onLoadMore,
|
|
121
122
|
onScroll,
|
|
122
123
|
listRef,
|
|
124
|
+
...aria
|
|
123
125
|
}: VirtualListProps<T>) => {
|
|
124
126
|
const count = useDeferredValue(items.length);
|
|
125
127
|
const extraSize = useMemo(() => (onLoadMore ? 64 : 0), [onLoadMore]);
|
|
@@ -258,6 +260,7 @@ const _VirtualList = <T extends KeyValue>({
|
|
|
258
260
|
className={classNames(
|
|
259
261
|
"area-content bg-base overflow-auto contain-strict",
|
|
260
262
|
)}
|
|
263
|
+
{...aria}
|
|
261
264
|
>
|
|
262
265
|
<div
|
|
263
266
|
className={classNames(
|