@noraent/nora-datagrid 0.0.30 → 0.0.32
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/lib/cjs/App.js +6 -2
- package/lib/cjs/buildPackage.json +1 -1
- package/lib/cjs/hooks/external/usePublicTest.js +13 -9
- package/lib/cjs/hooks/internal/useInternalPrivateApi.js +31 -1
- package/lib/cjs/types/dataGridProps.d.ts +25 -2
- package/lib/esm/App.js +6 -2
- package/lib/esm/buildPackage.json +1 -1
- package/lib/esm/hooks/external/usePublicTest.js +13 -9
- package/lib/esm/hooks/internal/useInternalPrivateApi.js +31 -1
- package/lib/esm/types/dataGridProps.d.ts +25 -2
- package/package.json +1 -1
package/lib/cjs/App.js
CHANGED
|
@@ -20,7 +20,7 @@ const RenderCell = (params) => {
|
|
|
20
20
|
for (let i = 0; i < 1; i++) {
|
|
21
21
|
tt += 233300 * i;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
Array.from({ length: 1 }, (_, i) => {
|
|
24
24
|
return {
|
|
25
25
|
id: i,
|
|
26
26
|
code: `${tt} -test-${i}`,
|
|
@@ -164,7 +164,7 @@ function App() {
|
|
|
164
164
|
const ref = useGridApiRef();
|
|
165
165
|
const [dataSource, setDataSource] = useState([]);
|
|
166
166
|
const handleDataSource = () => {
|
|
167
|
-
const data = Array.from({ length:
|
|
167
|
+
const data = Array.from({ length: 1000000 }, (_, i) => {
|
|
168
168
|
return {
|
|
169
169
|
id: i,
|
|
170
170
|
code: `test-${i}`,
|
|
@@ -180,6 +180,10 @@ function App() {
|
|
|
180
180
|
setDataSource(data);
|
|
181
181
|
};
|
|
182
182
|
return (_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => {
|
|
183
|
+
ref.current.scrollToRowIndex(414);
|
|
184
|
+
}, children: "414 \uC774\uB3D9" }), _jsx("button", { onClick: () => {
|
|
185
|
+
ref.current.scrollToRowIndex(1000000);
|
|
186
|
+
}, children: "1000000 \uC774\uB3D9" }), _jsx("button", { onClick: () => {
|
|
183
187
|
handleDataSource();
|
|
184
188
|
}, children: "\uB370\uC774\uD130 set" }), _jsx("button", { onClick: () => {
|
|
185
189
|
const data = ref.current.getData();
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
// import {
|
|
3
|
-
// DataGridPrivateApi,
|
|
4
|
-
// DataGridPublicApi,
|
|
5
|
-
// GirdApiCommon,
|
|
6
|
-
// } from "@/core/types/dataGridProps";
|
|
7
2
|
import { useGridApiMethod } from "../useGridApiMethod";
|
|
3
|
+
import { classes } from "../../types/classes";
|
|
8
4
|
export default function usePublicTest(apiRef) {
|
|
9
5
|
const getData = React.useCallback(() => {
|
|
10
6
|
return apiRef.current.store.state.dataSource;
|
|
11
7
|
}, []);
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const scrollToRowIndex = React.useCallback((rowIndex) => {
|
|
9
|
+
// 가변 X
|
|
10
|
+
// const top = rowIndex * 32 - 32;
|
|
11
|
+
apiRef.current.initHeightCache();
|
|
12
|
+
if (apiRef.current.store.gridContainer.current) {
|
|
13
|
+
const body = apiRef.current.store.gridContainer.current.querySelector(`.${classes.TableClasses.body.scroll.root}`);
|
|
14
|
+
if (body) {
|
|
15
|
+
const top = apiRef.current.getScrollTop(rowIndex);
|
|
16
|
+
body.scrollTop = top;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
}, []);
|
|
16
20
|
const addCellRange = React.useCallback((cellRange) => {
|
|
17
21
|
const updatedCellRange = structuredClone(apiRef.current.store.__cellRange);
|
|
18
22
|
updatedCellRange.push(cellRange);
|
|
19
23
|
apiRef.current = Object.assign(Object.assign({}, apiRef.current), { store: Object.assign(Object.assign({}, apiRef.current.store), { __cellRange: updatedCellRange }) });
|
|
20
24
|
}, []);
|
|
21
|
-
const apiMethods = {
|
|
25
|
+
const apiMethods = { addCellRange, getData, scrollToRowIndex };
|
|
22
26
|
useGridApiMethod(apiRef, apiMethods, "public");
|
|
23
27
|
}
|
|
@@ -75,10 +75,13 @@ export default function useInternalPrivateApi(apiRef) {
|
|
|
75
75
|
return defaultValues[key];
|
|
76
76
|
}
|
|
77
77
|
const scrollToRowIndex = React.useCallback((rowIndex) => {
|
|
78
|
-
|
|
78
|
+
// 가변 X
|
|
79
|
+
// const top = rowIndex * 32 - 32;
|
|
80
|
+
apiRef.current.initHeightCache();
|
|
79
81
|
if (apiRef.current.store.gridContainer.current) {
|
|
80
82
|
const body = apiRef.current.store.gridContainer.current.querySelector(`.${classes.TableClasses.body.scroll.root}`);
|
|
81
83
|
if (body) {
|
|
84
|
+
const top = getScrollTop(rowIndex);
|
|
82
85
|
body.scrollTop = top;
|
|
83
86
|
}
|
|
84
87
|
}
|
|
@@ -111,6 +114,31 @@ export default function useInternalPrivateApi(apiRef) {
|
|
|
111
114
|
store.state.dataSource[rowIndex] = Object.assign(Object.assign({}, store.state.dataSource[rowIndex]), { [fieldId]: value });
|
|
112
115
|
return store.state.dataSource;
|
|
113
116
|
}), []);
|
|
117
|
+
const initHeightCache = React.useCallback(() => {
|
|
118
|
+
let sum = 0;
|
|
119
|
+
const heightCache = apiRef.current.store.state.dataSource.map((row) => {
|
|
120
|
+
var _a;
|
|
121
|
+
sum += (_a = row.height) !== null && _a !== void 0 ? _a : 32;
|
|
122
|
+
return sum;
|
|
123
|
+
});
|
|
124
|
+
apiRef.current.store.heightCache = heightCache;
|
|
125
|
+
}, []);
|
|
126
|
+
const getScrollTop = React.useCallback((rowIndex) => {
|
|
127
|
+
let low = 0;
|
|
128
|
+
let high = apiRef.current.store.heightCache.length - 1;
|
|
129
|
+
let result = 0;
|
|
130
|
+
while (low <= high) {
|
|
131
|
+
const mid = Math.floor((low + high) / 2);
|
|
132
|
+
if (mid < rowIndex) {
|
|
133
|
+
result = apiRef.current.store.heightCache[mid];
|
|
134
|
+
low = mid + 1;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
high = mid - 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}, []);
|
|
114
142
|
const apiMethods = {
|
|
115
143
|
setText,
|
|
116
144
|
setGridContainer,
|
|
@@ -122,6 +150,8 @@ export default function useInternalPrivateApi(apiRef) {
|
|
|
122
150
|
setEditStatus,
|
|
123
151
|
cellByRowIndex,
|
|
124
152
|
setBasicStore,
|
|
153
|
+
initHeightCache,
|
|
154
|
+
getScrollTop,
|
|
125
155
|
};
|
|
126
156
|
useGridApiMethod(apiRef, apiMethods, "private");
|
|
127
157
|
return {};
|
|
@@ -54,6 +54,7 @@ export interface DataGridOptionPropsModel {
|
|
|
54
54
|
*/
|
|
55
55
|
interface DataGridBasicStorePropsModel {
|
|
56
56
|
gridContainer: React.RefObject<HTMLDivElement>;
|
|
57
|
+
heightCache: number[];
|
|
57
58
|
__cellRange: Array<CellRangeDef>;
|
|
58
59
|
__cellRangeTemp: CellRangeTempDef;
|
|
59
60
|
}
|
|
@@ -91,6 +92,12 @@ export interface DataGridPrivateApiModel {
|
|
|
91
92
|
* @namespace NoraDataGrid.DataGridPrivateApiModel.setBasicProps
|
|
92
93
|
*/
|
|
93
94
|
setBasicStore: (props: DataGridBasicProps) => DataGridStoreDef["state"];
|
|
95
|
+
/**
|
|
96
|
+
* 특정 행(row)의 스크롤 위치를 가져옵니다.
|
|
97
|
+
* @private
|
|
98
|
+
* @namespace NoraDataGrid.DataGridPrivateApiModel.getScrollTop
|
|
99
|
+
*/
|
|
100
|
+
getScrollTop: (rowIndex: number) => number;
|
|
94
101
|
/**
|
|
95
102
|
* 특정 행(row)의 위치로 스크롤을 이동합니다.
|
|
96
103
|
* @private
|
|
@@ -116,18 +123,34 @@ export interface DataGridPrivateApiModel {
|
|
|
116
123
|
* 셀 모드를 변경합니다.
|
|
117
124
|
*/
|
|
118
125
|
setEditStatus: (editStatus: DataGridStoreDef["state"]["editStatus"]) => Promise<DataGridStoreDef["state"]["editStatus"]>;
|
|
126
|
+
/**
|
|
127
|
+
* 데이터에 있는 모든 행 높이를 초기화 합니다.
|
|
128
|
+
* @private
|
|
129
|
+
* @namespace NoraDataGrid.DataGridPublicApiModel.getData
|
|
130
|
+
*/
|
|
131
|
+
initHeightCache: () => void;
|
|
119
132
|
cellByRowIndex: (rowIndex: number, fieldId: keyof DataGridPrivateDataSourceModel, value: string | number | undefined) => Promise<DataGridStoreDef["state"]["dataSource"]>;
|
|
120
133
|
}
|
|
121
134
|
export interface DataGridPublicApiModel {
|
|
122
|
-
setTextPublic: (data: any) => void;
|
|
123
135
|
/**
|
|
124
136
|
* 선택할 셀의 범위를 추가합니다.
|
|
125
137
|
* @param cellRange
|
|
126
138
|
* @returns
|
|
127
139
|
*/
|
|
128
140
|
addCellRange: (cellRange: CellRangeDef) => void;
|
|
129
|
-
|
|
141
|
+
/**
|
|
142
|
+
* 현재 데이터를 가져옵니다.
|
|
143
|
+
* @public
|
|
144
|
+
* @namespace NoraDataGrid.DataGridPublicApiModel.getData
|
|
145
|
+
*/
|
|
130
146
|
getData: <R extends DataGridBasicPropsModel["dataSource"] = DataGridBasicPropsModel["dataSource"]>() => R;
|
|
147
|
+
/**
|
|
148
|
+
* 특정 행(row)의 위치로 스크롤을 이동합니다.
|
|
149
|
+
* @public
|
|
150
|
+
* @namespace NoraDataGrid.DataGridPublicApiModel.scrollToRowIndex
|
|
151
|
+
*/
|
|
152
|
+
scrollToRowIndex: (rowIndex: number) => void;
|
|
153
|
+
forceUpdate: () => void;
|
|
131
154
|
}
|
|
132
155
|
export type CommonApi = React.MutableRefObject<DataGridPrivateApi | null>;
|
|
133
156
|
export type GirdApi = DataGridPublicApi;
|
package/lib/esm/App.js
CHANGED
|
@@ -20,7 +20,7 @@ const RenderCell = (params) => {
|
|
|
20
20
|
for (let i = 0; i < 1; i++) {
|
|
21
21
|
tt += 233300 * i;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
Array.from({ length: 1 }, (_, i) => {
|
|
24
24
|
return {
|
|
25
25
|
id: i,
|
|
26
26
|
code: `${tt} -test-${i}`,
|
|
@@ -164,7 +164,7 @@ function App() {
|
|
|
164
164
|
const ref = useGridApiRef();
|
|
165
165
|
const [dataSource, setDataSource] = useState([]);
|
|
166
166
|
const handleDataSource = () => {
|
|
167
|
-
const data = Array.from({ length:
|
|
167
|
+
const data = Array.from({ length: 1000000 }, (_, i) => {
|
|
168
168
|
return {
|
|
169
169
|
id: i,
|
|
170
170
|
code: `test-${i}`,
|
|
@@ -180,6 +180,10 @@ function App() {
|
|
|
180
180
|
setDataSource(data);
|
|
181
181
|
};
|
|
182
182
|
return (_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => {
|
|
183
|
+
ref.current.scrollToRowIndex(414);
|
|
184
|
+
}, children: "414 \uC774\uB3D9" }), _jsx("button", { onClick: () => {
|
|
185
|
+
ref.current.scrollToRowIndex(1000000);
|
|
186
|
+
}, children: "1000000 \uC774\uB3D9" }), _jsx("button", { onClick: () => {
|
|
183
187
|
handleDataSource();
|
|
184
188
|
}, children: "\uB370\uC774\uD130 set" }), _jsx("button", { onClick: () => {
|
|
185
189
|
const data = ref.current.getData();
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
// import {
|
|
3
|
-
// DataGridPrivateApi,
|
|
4
|
-
// DataGridPublicApi,
|
|
5
|
-
// GirdApiCommon,
|
|
6
|
-
// } from "@/core/types/dataGridProps";
|
|
7
2
|
import { useGridApiMethod } from "../useGridApiMethod";
|
|
3
|
+
import { classes } from "../../types/classes";
|
|
8
4
|
export default function usePublicTest(apiRef) {
|
|
9
5
|
const getData = React.useCallback(() => {
|
|
10
6
|
return apiRef.current.store.state.dataSource;
|
|
11
7
|
}, []);
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const scrollToRowIndex = React.useCallback((rowIndex) => {
|
|
9
|
+
// 가변 X
|
|
10
|
+
// const top = rowIndex * 32 - 32;
|
|
11
|
+
apiRef.current.initHeightCache();
|
|
12
|
+
if (apiRef.current.store.gridContainer.current) {
|
|
13
|
+
const body = apiRef.current.store.gridContainer.current.querySelector(`.${classes.TableClasses.body.scroll.root}`);
|
|
14
|
+
if (body) {
|
|
15
|
+
const top = apiRef.current.getScrollTop(rowIndex);
|
|
16
|
+
body.scrollTop = top;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
}, []);
|
|
16
20
|
const addCellRange = React.useCallback((cellRange) => {
|
|
17
21
|
const updatedCellRange = structuredClone(apiRef.current.store.__cellRange);
|
|
18
22
|
updatedCellRange.push(cellRange);
|
|
19
23
|
apiRef.current = Object.assign(Object.assign({}, apiRef.current), { store: Object.assign(Object.assign({}, apiRef.current.store), { __cellRange: updatedCellRange }) });
|
|
20
24
|
}, []);
|
|
21
|
-
const apiMethods = {
|
|
25
|
+
const apiMethods = { addCellRange, getData, scrollToRowIndex };
|
|
22
26
|
useGridApiMethod(apiRef, apiMethods, "public");
|
|
23
27
|
}
|
|
@@ -75,10 +75,13 @@ export default function useInternalPrivateApi(apiRef) {
|
|
|
75
75
|
return defaultValues[key];
|
|
76
76
|
}
|
|
77
77
|
const scrollToRowIndex = React.useCallback((rowIndex) => {
|
|
78
|
-
|
|
78
|
+
// 가변 X
|
|
79
|
+
// const top = rowIndex * 32 - 32;
|
|
80
|
+
apiRef.current.initHeightCache();
|
|
79
81
|
if (apiRef.current.store.gridContainer.current) {
|
|
80
82
|
const body = apiRef.current.store.gridContainer.current.querySelector(`.${classes.TableClasses.body.scroll.root}`);
|
|
81
83
|
if (body) {
|
|
84
|
+
const top = getScrollTop(rowIndex);
|
|
82
85
|
body.scrollTop = top;
|
|
83
86
|
}
|
|
84
87
|
}
|
|
@@ -111,6 +114,31 @@ export default function useInternalPrivateApi(apiRef) {
|
|
|
111
114
|
store.state.dataSource[rowIndex] = Object.assign(Object.assign({}, store.state.dataSource[rowIndex]), { [fieldId]: value });
|
|
112
115
|
return store.state.dataSource;
|
|
113
116
|
}), []);
|
|
117
|
+
const initHeightCache = React.useCallback(() => {
|
|
118
|
+
let sum = 0;
|
|
119
|
+
const heightCache = apiRef.current.store.state.dataSource.map((row) => {
|
|
120
|
+
var _a;
|
|
121
|
+
sum += (_a = row.height) !== null && _a !== void 0 ? _a : 32;
|
|
122
|
+
return sum;
|
|
123
|
+
});
|
|
124
|
+
apiRef.current.store.heightCache = heightCache;
|
|
125
|
+
}, []);
|
|
126
|
+
const getScrollTop = React.useCallback((rowIndex) => {
|
|
127
|
+
let low = 0;
|
|
128
|
+
let high = apiRef.current.store.heightCache.length - 1;
|
|
129
|
+
let result = 0;
|
|
130
|
+
while (low <= high) {
|
|
131
|
+
const mid = Math.floor((low + high) / 2);
|
|
132
|
+
if (mid < rowIndex) {
|
|
133
|
+
result = apiRef.current.store.heightCache[mid];
|
|
134
|
+
low = mid + 1;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
high = mid - 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}, []);
|
|
114
142
|
const apiMethods = {
|
|
115
143
|
setText,
|
|
116
144
|
setGridContainer,
|
|
@@ -122,6 +150,8 @@ export default function useInternalPrivateApi(apiRef) {
|
|
|
122
150
|
setEditStatus,
|
|
123
151
|
cellByRowIndex,
|
|
124
152
|
setBasicStore,
|
|
153
|
+
initHeightCache,
|
|
154
|
+
getScrollTop,
|
|
125
155
|
};
|
|
126
156
|
useGridApiMethod(apiRef, apiMethods, "private");
|
|
127
157
|
return {};
|
|
@@ -54,6 +54,7 @@ export interface DataGridOptionPropsModel {
|
|
|
54
54
|
*/
|
|
55
55
|
interface DataGridBasicStorePropsModel {
|
|
56
56
|
gridContainer: React.RefObject<HTMLDivElement>;
|
|
57
|
+
heightCache: number[];
|
|
57
58
|
__cellRange: Array<CellRangeDef>;
|
|
58
59
|
__cellRangeTemp: CellRangeTempDef;
|
|
59
60
|
}
|
|
@@ -91,6 +92,12 @@ export interface DataGridPrivateApiModel {
|
|
|
91
92
|
* @namespace NoraDataGrid.DataGridPrivateApiModel.setBasicProps
|
|
92
93
|
*/
|
|
93
94
|
setBasicStore: (props: DataGridBasicProps) => DataGridStoreDef["state"];
|
|
95
|
+
/**
|
|
96
|
+
* 특정 행(row)의 스크롤 위치를 가져옵니다.
|
|
97
|
+
* @private
|
|
98
|
+
* @namespace NoraDataGrid.DataGridPrivateApiModel.getScrollTop
|
|
99
|
+
*/
|
|
100
|
+
getScrollTop: (rowIndex: number) => number;
|
|
94
101
|
/**
|
|
95
102
|
* 특정 행(row)의 위치로 스크롤을 이동합니다.
|
|
96
103
|
* @private
|
|
@@ -116,18 +123,34 @@ export interface DataGridPrivateApiModel {
|
|
|
116
123
|
* 셀 모드를 변경합니다.
|
|
117
124
|
*/
|
|
118
125
|
setEditStatus: (editStatus: DataGridStoreDef["state"]["editStatus"]) => Promise<DataGridStoreDef["state"]["editStatus"]>;
|
|
126
|
+
/**
|
|
127
|
+
* 데이터에 있는 모든 행 높이를 초기화 합니다.
|
|
128
|
+
* @private
|
|
129
|
+
* @namespace NoraDataGrid.DataGridPublicApiModel.getData
|
|
130
|
+
*/
|
|
131
|
+
initHeightCache: () => void;
|
|
119
132
|
cellByRowIndex: (rowIndex: number, fieldId: keyof DataGridPrivateDataSourceModel, value: string | number | undefined) => Promise<DataGridStoreDef["state"]["dataSource"]>;
|
|
120
133
|
}
|
|
121
134
|
export interface DataGridPublicApiModel {
|
|
122
|
-
setTextPublic: (data: any) => void;
|
|
123
135
|
/**
|
|
124
136
|
* 선택할 셀의 범위를 추가합니다.
|
|
125
137
|
* @param cellRange
|
|
126
138
|
* @returns
|
|
127
139
|
*/
|
|
128
140
|
addCellRange: (cellRange: CellRangeDef) => void;
|
|
129
|
-
|
|
141
|
+
/**
|
|
142
|
+
* 현재 데이터를 가져옵니다.
|
|
143
|
+
* @public
|
|
144
|
+
* @namespace NoraDataGrid.DataGridPublicApiModel.getData
|
|
145
|
+
*/
|
|
130
146
|
getData: <R extends DataGridBasicPropsModel["dataSource"] = DataGridBasicPropsModel["dataSource"]>() => R;
|
|
147
|
+
/**
|
|
148
|
+
* 특정 행(row)의 위치로 스크롤을 이동합니다.
|
|
149
|
+
* @public
|
|
150
|
+
* @namespace NoraDataGrid.DataGridPublicApiModel.scrollToRowIndex
|
|
151
|
+
*/
|
|
152
|
+
scrollToRowIndex: (rowIndex: number) => void;
|
|
153
|
+
forceUpdate: () => void;
|
|
131
154
|
}
|
|
132
155
|
export type CommonApi = React.MutableRefObject<DataGridPrivateApi | null>;
|
|
133
156
|
export type GirdApi = DataGridPublicApi;
|