@youp-grid/react 0.1.0
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/README.md +12 -0
- package/dist/YoupGrid.d.ts +863 -0
- package/dist/YoupGrid.js +1621 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/styles.css +682 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.js +1 -0
- package/dist/useYoupGrid.d.ts +2 -0
- package/dist/useYoupGrid.js +97 -0
- package/package.json +36 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { AggregationRule, ColumnDef, ColumnPin, CursorPaginationState, GridRowId, GridRowModelType, GridState, RemoteCacheState, ResolvedColumnDef, RowModel, RowGroupingState, RowNode } from "@youp-grid/core";
|
|
2
|
+
import type { CSSProperties, MouseEvent as ReactMouseEvent, ReactNode } from "react";
|
|
3
|
+
export type YoupGridStateChange<TRow> = {
|
|
4
|
+
state: GridState;
|
|
5
|
+
rowModel: RowModel<TRow>;
|
|
6
|
+
};
|
|
7
|
+
export type YoupGridCellValueChange<TRow> = {
|
|
8
|
+
row: TRow;
|
|
9
|
+
rowId: GridRowId;
|
|
10
|
+
rowIndex: number;
|
|
11
|
+
column: ResolvedColumnDef<TRow>;
|
|
12
|
+
columnId: string;
|
|
13
|
+
value: unknown;
|
|
14
|
+
previousValue: unknown;
|
|
15
|
+
source: YoupGridCellValueChangeSource;
|
|
16
|
+
};
|
|
17
|
+
export type YoupGridCellValueChangeSource = "edit" | "paste" | "fill" | "undo" | "redo";
|
|
18
|
+
export type YoupGridDensity = "compact" | "standard" | "comfortable";
|
|
19
|
+
export type YoupGridRowEvent<TRow> = {
|
|
20
|
+
row: TRow;
|
|
21
|
+
rowNode: RowNode<TRow>;
|
|
22
|
+
rowId: GridRowId;
|
|
23
|
+
rowIndex: number;
|
|
24
|
+
event: ReactMouseEvent<HTMLDivElement>;
|
|
25
|
+
};
|
|
26
|
+
export type YoupGridRowsEndReachedEvent<TRow> = {
|
|
27
|
+
state: GridState;
|
|
28
|
+
rowModel: RowModel<TRow>;
|
|
29
|
+
rowCount: number;
|
|
30
|
+
lastVisibleRowIndex: number;
|
|
31
|
+
threshold: number;
|
|
32
|
+
remainingRows: number;
|
|
33
|
+
};
|
|
34
|
+
export type YoupGridOptions<TRow> = {
|
|
35
|
+
rows: readonly TRow[];
|
|
36
|
+
columns: readonly ColumnDef<TRow>[];
|
|
37
|
+
state?: GridState;
|
|
38
|
+
defaultState?: GridState;
|
|
39
|
+
onStateChange?: (change: YoupGridStateChange<TRow>) => void;
|
|
40
|
+
getRowId?: (row: TRow, index: number) => GridRowId;
|
|
41
|
+
rowModelType?: GridRowModelType;
|
|
42
|
+
serverRowCount?: number;
|
|
43
|
+
serverFilteredRowCount?: number;
|
|
44
|
+
rowHeight?: number;
|
|
45
|
+
overscan?: number;
|
|
46
|
+
infiniteScroll?: boolean;
|
|
47
|
+
infiniteScrollThreshold?: number;
|
|
48
|
+
infiniteScrollLoading?: boolean;
|
|
49
|
+
hasMoreRows?: boolean;
|
|
50
|
+
};
|
|
51
|
+
export type YoupGridController<TRow> = {
|
|
52
|
+
state: GridState;
|
|
53
|
+
rowModel: RowModel<TRow>;
|
|
54
|
+
setState: (state: GridState) => void;
|
|
55
|
+
toggleSort: (columnId: string, multi?: boolean) => void;
|
|
56
|
+
setSort: (columnId: string, direction: "asc" | "desc", multi?: boolean) => void;
|
|
57
|
+
clearSort: (columnId: string) => void;
|
|
58
|
+
setFilter: (columnId: string, value: unknown) => void;
|
|
59
|
+
clearFilter: (columnId: string) => void;
|
|
60
|
+
setPage: (pageIndex: number) => void;
|
|
61
|
+
setPageSize: (pageSize: number) => void;
|
|
62
|
+
setCursorPage: (cursor: string | undefined) => void;
|
|
63
|
+
setCursorPageSize: (pageSize: number) => void;
|
|
64
|
+
setCursorPagination: (cursorPagination: CursorPaginationState) => void;
|
|
65
|
+
setAggregation: (aggregation: readonly AggregationRule[]) => void;
|
|
66
|
+
setRowGrouping: (rowGrouping: RowGroupingState | undefined) => void;
|
|
67
|
+
toggleRowGroupExpanded: (groupId: string) => void;
|
|
68
|
+
startRemoteRequest: (requestId: string) => void;
|
|
69
|
+
finishRemoteRequest: (requestId: string) => void;
|
|
70
|
+
failRemoteRequest: (requestId: string, error?: string) => void;
|
|
71
|
+
cancelRemoteRequest: (requestId?: string) => void;
|
|
72
|
+
setRemoteCache: (remoteCache: RemoteCacheState) => void;
|
|
73
|
+
invalidateRemoteCache: (key?: string) => void;
|
|
74
|
+
acknowledgeRemoteCache: (key?: string) => void;
|
|
75
|
+
setColumnHidden: (columnId: string, hidden: boolean) => void;
|
|
76
|
+
setColumnPinned: (columnId: string, pinned: ColumnPin | undefined) => void;
|
|
77
|
+
setColumnWidth: (columnId: string, width: number) => void;
|
|
78
|
+
setRowSelected: (rowId: GridRowId, selected: boolean) => void;
|
|
79
|
+
setSelectedRows: (rowIds: readonly GridRowId[]) => void;
|
|
80
|
+
toggleRowSelected: (rowId: GridRowId) => void;
|
|
81
|
+
};
|
|
82
|
+
export type YoupGridProps<TRow> = YoupGridOptions<TRow> & {
|
|
83
|
+
className?: string;
|
|
84
|
+
style?: CSSProperties;
|
|
85
|
+
height?: number | string;
|
|
86
|
+
editable?: boolean;
|
|
87
|
+
showColumnChooser?: boolean;
|
|
88
|
+
showColumnMenu?: boolean;
|
|
89
|
+
showCsvExport?: boolean;
|
|
90
|
+
showDensityControl?: boolean;
|
|
91
|
+
showFilters?: boolean;
|
|
92
|
+
showAggregationFooter?: boolean;
|
|
93
|
+
showPagination?: boolean;
|
|
94
|
+
showRowSelectionColumn?: boolean;
|
|
95
|
+
csvFileName?: string;
|
|
96
|
+
density?: YoupGridDensity;
|
|
97
|
+
defaultDensity?: YoupGridDensity;
|
|
98
|
+
onDensityChange?: (density: YoupGridDensity) => void;
|
|
99
|
+
loading?: boolean;
|
|
100
|
+
loadingContent?: ReactNode;
|
|
101
|
+
error?: boolean;
|
|
102
|
+
errorContent?: ReactNode;
|
|
103
|
+
renderCell?: (context: YoupGridCellContext<TRow>) => ReactNode;
|
|
104
|
+
renderHeader?: (context: YoupGridHeaderContext<TRow>) => ReactNode;
|
|
105
|
+
onCellValueChange?: (change: YoupGridCellValueChange<TRow>) => void;
|
|
106
|
+
onRowClick?: (event: YoupGridRowEvent<TRow>) => void;
|
|
107
|
+
onRowDoubleClick?: (event: YoupGridRowEvent<TRow>) => void;
|
|
108
|
+
onRowsEndReached?: (event: YoupGridRowsEndReachedEvent<TRow>) => void;
|
|
109
|
+
emptyContent?: ReactNode;
|
|
110
|
+
};
|
|
111
|
+
export type YoupGridCellContext<TRow> = {
|
|
112
|
+
row: RowNode<TRow>;
|
|
113
|
+
column: ResolvedColumnDef<TRow>;
|
|
114
|
+
value: unknown;
|
|
115
|
+
editing: boolean;
|
|
116
|
+
focused: boolean;
|
|
117
|
+
};
|
|
118
|
+
export type YoupGridHeaderContext<TRow> = {
|
|
119
|
+
column: ResolvedColumnDef<TRow>;
|
|
120
|
+
sorted: "asc" | "desc" | undefined;
|
|
121
|
+
toggleSort: () => void;
|
|
122
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { acknowledgeRemoteCache as acknowledgeCoreRemoteCache, buildRowModel, cancelRemoteRequest as cancelCoreRemoteRequest, clearFilter as clearCoreFilter, clearSort as clearCoreSort, createGridState, failRemoteRequest as failCoreRemoteRequest, finishRemoteRequest as finishCoreRemoteRequest, invalidateRemoteCache as invalidateCoreRemoteCache, setColumnHidden as setCoreColumnHidden, setColumnPinned as setCoreColumnPinned, setColumnWidth as setCoreColumnWidth, setCursorPage as setCoreCursorPage, setCursorPageSize as setCoreCursorPageSize, setCursorPagination as setCoreCursorPagination, setAggregation as setCoreAggregation, setFilter as setCoreFilter, setPagination, setRemoteCache as setCoreRemoteCache, setRowGrouping as setCoreRowGrouping, setRowSelected as setCoreRowSelected, setSelectedRows as setCoreSelectedRows, setSort as setCoreSort, startRemoteRequest as startCoreRemoteRequest, toggleRowGroupExpanded as toggleCoreRowGroupExpanded, toggleRowSelected as toggleCoreRowSelected, toggleSort as toggleCoreSort, } from "@youp-grid/core";
|
|
2
|
+
import { useCallback, useMemo, useState } from "react";
|
|
3
|
+
export function useYoupGrid(options) {
|
|
4
|
+
const isControlled = options.state !== undefined;
|
|
5
|
+
const [internalState, setInternalState] = useState(() => {
|
|
6
|
+
return createGridState(options.defaultState);
|
|
7
|
+
});
|
|
8
|
+
const state = isControlled ? createGridState(options.state) : internalState;
|
|
9
|
+
const rowModel = useMemo(() => {
|
|
10
|
+
return buildRowModel({
|
|
11
|
+
rows: options.rows,
|
|
12
|
+
columns: options.columns,
|
|
13
|
+
state,
|
|
14
|
+
getRowId: options.getRowId,
|
|
15
|
+
rowModelType: options.rowModelType,
|
|
16
|
+
serverRowCount: options.serverRowCount,
|
|
17
|
+
serverFilteredRowCount: options.serverFilteredRowCount,
|
|
18
|
+
});
|
|
19
|
+
}, [
|
|
20
|
+
options.rows,
|
|
21
|
+
options.columns,
|
|
22
|
+
options.getRowId,
|
|
23
|
+
options.rowModelType,
|
|
24
|
+
options.serverRowCount,
|
|
25
|
+
options.serverFilteredRowCount,
|
|
26
|
+
state,
|
|
27
|
+
]);
|
|
28
|
+
const commitState = useCallback((nextState) => {
|
|
29
|
+
const nextRowModel = buildRowModel({
|
|
30
|
+
rows: options.rows,
|
|
31
|
+
columns: options.columns,
|
|
32
|
+
state: nextState,
|
|
33
|
+
getRowId: options.getRowId,
|
|
34
|
+
rowModelType: options.rowModelType,
|
|
35
|
+
serverRowCount: options.serverRowCount,
|
|
36
|
+
serverFilteredRowCount: options.serverFilteredRowCount,
|
|
37
|
+
});
|
|
38
|
+
if (!isControlled) {
|
|
39
|
+
setInternalState(nextState);
|
|
40
|
+
}
|
|
41
|
+
options.onStateChange?.({
|
|
42
|
+
state: nextState,
|
|
43
|
+
rowModel: nextRowModel,
|
|
44
|
+
});
|
|
45
|
+
}, [isControlled, options]);
|
|
46
|
+
const setPage = useCallback((pageIndex) => {
|
|
47
|
+
commitState(setPagination(state, {
|
|
48
|
+
pageIndex,
|
|
49
|
+
pageSize: state.pagination?.pageSize ?? 50,
|
|
50
|
+
}));
|
|
51
|
+
}, [commitState, state]);
|
|
52
|
+
const setPageSize = useCallback((pageSize) => {
|
|
53
|
+
commitState(setPagination(state, {
|
|
54
|
+
pageIndex: 0,
|
|
55
|
+
pageSize,
|
|
56
|
+
}));
|
|
57
|
+
}, [commitState, state]);
|
|
58
|
+
return {
|
|
59
|
+
state,
|
|
60
|
+
rowModel,
|
|
61
|
+
setState: commitState,
|
|
62
|
+
toggleSort: (columnId, multi) => commitState(toggleCoreSort(state, columnId, { multi })),
|
|
63
|
+
setSort: (columnId, direction, multi) => commitState(setCoreSort(state, columnId, direction, { multi })),
|
|
64
|
+
clearSort: (columnId) => commitState(clearCoreSort(state, columnId)),
|
|
65
|
+
setFilter: (columnId, value) => {
|
|
66
|
+
commitState(setCoreFilter(state, { columnId, operator: "contains", value }));
|
|
67
|
+
},
|
|
68
|
+
clearFilter: (columnId) => commitState(clearCoreFilter(state, columnId)),
|
|
69
|
+
setPage,
|
|
70
|
+
setPageSize,
|
|
71
|
+
setCursorPage: (cursor) => commitState(setCoreCursorPage(state, cursor)),
|
|
72
|
+
setCursorPageSize: (pageSize) => commitState(setCoreCursorPageSize(state, pageSize)),
|
|
73
|
+
setCursorPagination: (cursorPagination) => commitState(setCoreCursorPagination(state, cursorPagination)),
|
|
74
|
+
setAggregation: (aggregation) => commitState(setCoreAggregation(state, aggregation)),
|
|
75
|
+
setRowGrouping: (rowGrouping) => commitState(setCoreRowGrouping(state, rowGrouping)),
|
|
76
|
+
toggleRowGroupExpanded: (groupId) => commitState(toggleCoreRowGroupExpanded(state, groupId)),
|
|
77
|
+
startRemoteRequest: (requestId) => commitState(startCoreRemoteRequest(state, requestId)),
|
|
78
|
+
finishRemoteRequest: (requestId) => commitState(finishCoreRemoteRequest(state, requestId)),
|
|
79
|
+
failRemoteRequest: (requestId, error) => commitState(failCoreRemoteRequest(state, requestId, error)),
|
|
80
|
+
cancelRemoteRequest: (requestId) => commitState(cancelCoreRemoteRequest(state, requestId)),
|
|
81
|
+
setRemoteCache: (remoteCache) => commitState(setCoreRemoteCache(state, remoteCache)),
|
|
82
|
+
invalidateRemoteCache: (key) => commitState(invalidateCoreRemoteCache(state, key)),
|
|
83
|
+
acknowledgeRemoteCache: (key) => commitState(acknowledgeCoreRemoteCache(state, key)),
|
|
84
|
+
setColumnHidden: (columnId, hidden) => {
|
|
85
|
+
commitState(setCoreColumnHidden(state, columnId, hidden));
|
|
86
|
+
},
|
|
87
|
+
setColumnPinned: (columnId, pinned) => {
|
|
88
|
+
commitState(setCoreColumnPinned(state, columnId, pinned));
|
|
89
|
+
},
|
|
90
|
+
setColumnWidth: (columnId, width) => {
|
|
91
|
+
commitState(setCoreColumnWidth(state, columnId, width));
|
|
92
|
+
},
|
|
93
|
+
setRowSelected: (rowId, selected) => commitState(setCoreRowSelected(state, rowId, selected)),
|
|
94
|
+
setSelectedRows: (rowIds) => commitState(setCoreSelectedRows(state, rowIds)),
|
|
95
|
+
toggleRowSelected: (rowId) => commitState(toggleCoreRowSelected(state, rowId)),
|
|
96
|
+
};
|
|
97
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@youp-grid/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React adapter for Youp Grid.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./styles.css": "./dist/styles.css"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+ssh://git@github.com/SeungyoupBaek/youp-grid.git",
|
|
22
|
+
"directory": "packages/react"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.build.json && cp src/styles.css dist/styles.css"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@youp-grid/core": "0.1.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": ">=18.2.0"
|
|
35
|
+
}
|
|
36
|
+
}
|