├── .eslintignore
├── .eslintrc.json
├── .fatherrc.ts
├── .gitignore
├── CHANGE_LOG.md
├── LICENSE
├── README.md
├── package.json
├── src
├── index.tsx
└── vt.tsx
├── test
├── CustomRows Hooks.jsx
├── Drag soring.css
├── Drag soring.jsx
├── Editable Rows.css
├── Editable Rows.tsx
├── expandable.tsx
├── fetch.tsx
├── indez.jsx
├── reload.tsx
├── scroll-to.tsx
├── table ajax.tsx
├── table#100.tsx
└── table1.tsx
├── tsconfig.json
└── yarn.lock
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules/*
2 | **/lib/*
3 | **/es/*
4 |
5 | dist/*
6 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "parser": "@typescript-eslint/parser",
3 | "plugins": ["@typescript-eslint"],
4 | "extends": [
5 | "eslint:recommended",
6 | "plugin:@typescript-eslint/eslint-recommended",
7 | "plugin:@typescript-eslint/recommended"
8 | ],
9 | "parserOptions": {
10 | "ecmaVersion": 2018,
11 | "sourceType": "module"
12 | },
13 | "env": {
14 | "browser": true,
15 | "es6": true,
16 | "worker": true,
17 | "node": true,
18 | "shared-node-browser": true,
19 | "commonjs": true
20 | },
21 | "rules": {
22 | "camelcase": "off",
23 | "semi": ["error", "never"],
24 | "@typescript-eslint/camelcase": "off",
25 | "no-console": ["error", { "allow": ["debug", "warn", "assert", "info"] }],
26 | "@typescript-eslint/class-name-casing": "off",
27 | "no-constant-condition": "off",
28 | "@typescript-eslint/explicit-function-return-type": "off",
29 | "@typescript-eslint/no-explicit-any": "off",
30 | "@typescript-eslint/no-unused-vars": ["warn", {
31 | "vars": "all",
32 | "args": "none",
33 | "ignoreRestSiblings": true
34 | }],
35 | "@typescript-eslint/no-non-null-assertion": "off",
36 | "@typescript-eslint/no-empty-function": "off"
37 | },
38 | "root": true
39 | }
--------------------------------------------------------------------------------
/.fatherrc.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'father'
2 | export default defineConfig({
3 | esm: {
4 | input: 'src',
5 | },
6 | cjs: {
7 | input: 'src',
8 | },
9 | // umd: {
10 | // output: 'dist',
11 | // }
12 | });
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_STORE
2 | node_modules
3 | *~
4 | *.log*
5 | package-lock.json
6 | dist
7 | .npmignore
8 | .vscode
9 | .idea
10 |
11 | lib
12 | es
--------------------------------------------------------------------------------
/CHANGE_LOG.md:
--------------------------------------------------------------------------------
1 | # 1.3.1
2 | 1. Fixed [#141](https://github.com/wubostc/virtualized-table-for-antd/issues/141).
3 | 2. Removed an unnecessary print `console.log`.
4 |
5 |
6 |
7 |
8 | # 1.3.0
9 | 1. Fixed a bug on safari.
10 | 1. Improved the performance.
11 | 1. Fixed [#136](https://github.com/wubostc/virtualized-table-for-antd/issues/136).
12 |
13 |
14 | # 1.2.2
15 | 1. Supported immutable records([#120](https://github.com/wubostc/virtualized-table-for-antd/issues/120))([#132](https://github.com/wubostc/virtualized-table-for-antd/issues/120)).
16 | 2. Fixed the return type(ts) of the `useVT`.
17 | 3. Supported antd-v5.
18 | 4. Improved the function `helper_diagnosis`.
19 |
20 | # 1.2.1
21 | 1. fixed [#126](https://github.com/wubostc/virtualized-table-for-antd/issues/126).
22 | 2. fixed [#125](https://github.com/wubostc/virtualized-table-for-antd/issues/125).
23 | 3. fixed [#122](https://github.com/wubostc/virtualized-table-for-antd/issues/122).
24 | 4. fixed a [bug](https://github.com/wubostc/virtualized-table-for-antd/commit/81b91bb68c2ba0bd3196487b708a5b59ec02f6b8).
25 |
26 | ## 1.2.0
27 | 1. Updated the building tools.
28 | 2. Supported the React18(#123).
29 |
30 |
31 | ## 1.1.6
32 | 1. Supported tree-structure.
33 |
34 | ## 1.1.5(zh)
35 | 1. 添加支持 `expandable`,(#106)
36 | [例子](https://github.com/wubostc/virtualized-table-for-antd/blob/master/test/expandable.tsx).
37 | 2. 表样式增加 `minWidth: 100%`(#114).
38 | 3. 修复`useVT`的`scroll`类型问题(#116).
39 | ## 1.1.5(en)
40 | 1. Added support for `expandable`,(#106)
41 | [refer](https://github.com/wubostc/virtualized-table-for-antd/blob/master/test/expandable.tsx).
42 | 2. Added table style `minWidth: 100%`(#114).
43 | 3. Fixed the `scroll` type problem of `useVT`(#116).
44 |
45 |
46 | ## 1.1.4(zh)
47 | 1. feat: `useVT` 返回 ref.
48 | 2. fix: 改进了 `scrollTo`,可以精确地滚动到指定位置.
49 | 3. feat: 新增 `scrollToIndex` 方法(#94),[例子](https://github.com/wubostc/virtualized-table-for-antd/blob/master/test/scroll-to.tsx#L74)
50 | ## 1.1.4(en)
51 | 1. feat: `useVT` can returns `ref` instead of the previous method.
52 | 2. fix: `scrollTo` has been improved, that can now scroll exactly to the specified position.
53 | 3. feat: added function `scrollToIndex`(#94), [refer](https://github.com/wubostc/virtualized-table-for-antd/blob/master/test/scroll-to.tsx#L74)
54 |
55 |
56 | ## 1.1.3(zh)
57 | 1. fix: 删除多余的导出 useOnce.
58 | 2. fix: 一个bug(#100).
59 | ## 1.1.3(en)
60 | 1. fix: `useOnce` of the exports has been deleted.
61 | 2. fix: a bug(#100).
62 |
63 |
64 |
65 | ## 1.1.2(zh)
66 | 1. fix: 初始化时空数据的崩溃问题(#84).
67 | ## 1.1.2(en)
68 | 1. fix: crashing problem by the empty data, it happened when the VT was initialized(#84).
69 |
70 |
71 | ## 1.1.1(zh)
72 | 1. fix: 空数据的渲染问题.
73 | ## 1.1.1(en)
74 | 1. fix: rendering of empty data.
75 |
76 |
77 | ## 1.1.0(zh)
78 | 1. feat: scrollTo方法,支持指定位置滚动(#75).
79 | 2. fix: 支持React17(#77).
80 | 3. fix: 修复onScroll参数在高DPI下isEnd无法为true的问题(#74).
81 |
82 |
83 | ## 1.0.0(zh)
84 | 1. 改进的虚拟化算法并全面支持antd4.
85 |
86 |
87 | ## 1.0.0(en)
88 | 1. the improved virtualization algorithm, and full supports antd4.
89 |
90 |
91 | ## 0.7.8(zh)
92 | 1. fix: 删除被标记为`deprecated`的接口和参数。
93 | + 接口:`getVTComponents`
94 | + 接口:`getVTContext`
95 | + 参数:`vt_opts.reflection`
96 | 1. refacotry: 一些细小重构。
97 |
98 |
99 | ## 0.7.8(en)
100 | 1. fix: delete the APIs and the params marked as `deprecated`.
101 | + API:`getVTComponents`
102 | + API:`getVTContext`
103 | + param:`vt_opts.reflection`
104 | 1. refacotry: some minor refactorings.
105 |
106 |
107 | ## 0.7.7
108 | 1. fix: `Cannot redefine property: __DIAGNOSIS__`(#55).
109 |
110 | ## 0.7.6
111 | 1. fix: ctx._React_ptr.forceUpdate is not a function.(#46)
112 |
113 |
114 | ## 0.7.5
115 | 1. improved diff algorithm, fix some bugs.
116 |
117 |
118 | ## 0.7.4
119 | 1. improved diff algorithm.
120 |
121 |
122 | ## 0.7.3
123 | 1. fix a bug.(#42)
124 |
125 |
126 | ## 0.7.2
127 | 1. fix some bugs, thanks @liubinis86.(#35 #34).
128 |
129 |
130 | ## 0.7.1
131 | 1. improve consistency to avoid incorrect rendering.
132 |
133 |
134 | ## 0.7.0
135 | 1. add a new Hooks API, `useVT`.
136 | 1. fix a bug that free the same index repeatedly.(#21)
137 |
138 |
139 | ## 0.6.3~0.6.4
140 | 1. fix some bugs.(#21)
141 |
142 |
143 |
144 | ## 0.6.2
145 | 1. an unmounted component will not update style.
146 | 1. fix a bug.(#25)
147 | 1. `getComponent` has been deprecated, use `setComponent` instead(#26).
148 | 1. adjusted log format.
149 |
150 |
151 | ## 0.6.1
152 | 1. removed debug info `console.log` (sorry, guys~).
153 |
154 |
155 | ## 0.6.0
156 | ### this is first stable version, and the main changes are:
157 | 1. removed `VTRefresh`.
158 | 1. removed `height`, now it depends entirely on `scroll.y`.
159 | 1. redesigned interface `VTScroll`.
160 | 1. much bugs was fixed.
161 | 1. fast, fast and more faster, with my best trying that all operations costs time about O(1).
162 | 1. browers required support `requestAnimationFrame`.
163 | > I suggest you to test this library carefully after installing it.
164 |
165 |
166 | ## 0.5.5
167 | 1. improving compatibility.
168 |
169 | ## 0.5.4
170 | 1. fix some bugs.
171 |
172 | ## 0.5.3
173 | 1. fix `debug` bug when the param `e` is `null`.
174 |
175 | ## 0.5.2
176 | 1. refactory `scrollHook`.
177 |
178 | ## 0.5.1
179 | 1. refactory `scrollHook` to optimize performance.
180 | 1. update README.md.
181 |
182 | ## 0.5.0
183 | 1. fix the definition of `vt_ctx`.
184 | 1. remove `VTWrapperRender` option.
185 | 1. remove `changedBits` option.
186 | 1. more friendly reading format for this file.
187 | 1. `debug` can shows `scrollTop`.
188 |
189 |
190 | ## 0.4.0
191 | 1. { debug: true, ... } to see more debugging details.
192 | 2. fix VTScroll bug.
193 | 3. using render-lock, VT can now renders stably.
194 | 4. improved throttling.
195 | 5. fix some problems in TS 3.5.
196 | 6. the default value of vt_opts.overscanRowCount is now 5.
197 |
198 |
199 | ## 0.4.0-beta.2
200 | 1. show the warning when you don't have 'height' as a field in the vt_opts.
201 | 2. add throttling to optimize scrolling.
202 | 3. change the styles ([#9](https://github.com/wubostc/virtualized-table-for-antd/issues/9 "Style Error"))
203 |
204 |
205 | ## 0.4.0-beta.1
206 | 1. support for the opt ColumnProps.fixed ([#5](https://github.com/wubostc/virtualized-table-for-antd/issues/5 "不支持 fixed"))
207 | 2. support for the fixed lists.
208 | 3. compatible with ie9-11.
209 |
210 |
211 | ## 0.3.4
212 | 1. fix VTScroll bug.
213 |
214 |
215 | ## 0.3.1
216 | 1. fix minor style bug that using offsetHeight instead of clientHeight ([#2](https://github.com/wubostc/virtualized-table-for-antd/issues/2 "offsetHeight instead of clientHeight"))
217 |
218 |
219 | ## 0.3.0
220 | 1. optimize the program logic
221 | 2. add debug feature
222 |
223 |
224 | ## 0.2.1 (ignored)
225 |
226 |
227 | ## 0.2.0
228 | 1. removed two interfaces in vt_opts ( VTScroll and VTRefresh)
229 |
230 |
231 | ## 0.1.0
232 | 1. by default, CACHE is enable, , set the prop destory to control whether the component is destroyed when it is uninstalled
233 |
234 |
235 | ## 0.0.9
236 | 1. rewrite const enum to enum
237 |
238 |
239 | ## 0.0.8
240 | 1. the interface vt_opts no longer requires too many params
241 |
242 |
243 | ## 0.0.7
244 | 1. now, the func VTScroll can correct restores last scroll state of antd table
245 |
246 |
247 | ## 0.0.6
248 | 1. add new API VTScroll (overload+2)
249 | ```typescript
250 |
251 | class MyComponent extends React.Component {
252 | ...
253 | render() {
254 |
259 | }
260 |
261 | componentDitMount() {
262 | VTScroll(1000, { top: 200 }) // to set
263 | const { top, left } = VTScroll(1000); // to get
264 | }
265 | }
266 |
267 | ```
268 | 2. add new API onScroll of the scroll event
269 | ```typescript
270 | console.log(left, top) })}
275 | />
276 | ```
277 |
278 |
279 | ## 0.0.5
280 | 1. add new API VTRefresh
281 | ```typescript
282 | export declare function VTRefresh(id: number): void;
283 | ```
284 | 2. remove the func shouldComponentUpdate of VTWrapper
285 | 3. remove the func shouldComponentUpdate of VTRow
286 |
287 |
288 | ## 0.0.4
289 | 1. Solve the initial rendering bug. ([#1](https://github.com/wubostc/virtualized-table-for-antd/issues/1 "能有个完整的demo吗"))
290 | 2. Update the README.md
291 |
292 |
293 | ## 0.0.3
294 | 1. Added missing type.
295 | ```typescript
296 | function VTComponents(vt_opts: vt_opts): TableComponents
297 | ```
298 | 2. Some bugs fixed.
299 |
300 |
301 | ## 0.0.1 ~ 0.0.2
302 | 1. init ver.
303 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # The virtualized table component for AntD4,fast, restorable and smallest size for gzip!
2 |
3 |
4 | 
5 | 
6 | 
7 |
8 |
9 | [](https://nodei.co/npm/virtualizedtableforantd4/)
10 |
11 | + Install
12 |
13 | ```shell
14 | npm i --save virtualizedtableforantd4
15 | ```
16 |
17 | + the opts of `useVT`([examples](https://github.com/wubostc/virtualized-table-for-antd/blob/master/test))
18 | ```typescript
19 | interface VtOpts {
20 | id?: number | string;
21 | /**
22 | * @default 5
23 | */
24 | overscanRowCount?: number;
25 |
26 | /**
27 | * this only needs the scroll.y
28 | */
29 | scroll: {
30 | y: number | string;
31 | };
32 |
33 | /**
34 | * wheel event(only works on native events).
35 | */
36 | onScroll?: ({ left, top, isEnd, }:
37 | { top: number; left: number; isEnd: boolean }) => void;
38 |
39 | initTop?: number;
40 |
41 | /**
42 | * Offset of the table when isEnd becomes true.
43 | * @default 0
44 | */
45 | offset?: number;
46 |
47 | /**
48 | * @default false
49 | */
50 | debug?: boolean;
51 |
52 |
53 | // pass -1 means scroll to the bottom of the table
54 | ref?: React.MutableRefObject<{
55 | scrollTo: (y: number) => void;
56 | scrollToIndex: (idx: number) => void;
57 | }>
58 | }
59 | ```
60 |
61 |
62 | + Quick start
63 | > You need to change your style like following if your Table.size is not default.
64 |
65 | ```less
66 | // size={'small'}
67 | ant-table [vt] > table > .ant-table-tbody > tr > td {
68 | padding: 8px;
69 | }
70 | ```
71 | ```typescript
72 | import React from 'react';
73 | import { Table } from 'antd';
74 | import { useVT } from 'virtualizedtableforantd4';
75 |
76 | const [ vt, set_components ] = useVT(() => ({ scroll: { y: 600 } }), []);
77 |
78 |
84 | ```
85 |
86 | + Scroll to
87 | - [scroll-to](https://github.com/wubostc/virtualized-table-for-antd/blob/master/test/scroll-to.tsx)
88 |
89 |
90 | + Restoring last state
91 |
92 | - [reload](https://github.com/wubostc/virtualized-table-for-antd/blob/master/test/reload.tsx)
93 |
94 |
95 | + Editable Table
96 |
97 | - [CustomRows Hooks](https://github.com/wubostc/virtualized-table-for-antd/blob/master/test/CustomRows%20Hooks.jsx)
98 | - [Editable Rows](https://github.com/wubostc/virtualized-table-for-antd/blob/master/test/Editable%20Rows.jsx)
99 |
100 | + Drag soring
101 |
102 | - [Drag soring](https://github.com/wubostc/virtualized-table-for-antd/blob/master/test/Drag%20soring.jsx)
103 |
104 | + expanded rows & tree-structure
105 | has been well supported!
106 |
107 | ## License
108 |
109 | [MIT](LICENSE)
110 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "virtualizedtableforantd4",
3 | "version": "1.3.1",
4 | "description": "The virtualized table component for ant design4/5, using typescript.",
5 | "keywords": [
6 | "antd",
7 | "virtualized table",
8 | "react",
9 | "react virtualized",
10 | "antd virtualized table",
11 | "infinity",
12 | "scroll",
13 | "virtual",
14 | "无限滚动表格",
15 | "虚拟表格",
16 | "无限滚动",
17 | "table"
18 | ],
19 | "main": "dist/cjs/index.js",
20 | "module": "dist/esm/index.js",
21 | "files": [
22 | "dist"
23 | ],
24 | "scripts": {
25 | "clean": "rimraf dist",
26 | "compile": "father build",
27 | "lint": "eslint src/ --ext .ts,.tsx",
28 | "build": "npm run lint && npm run compile",
29 | "doctor": "father doctor",
30 | "prepublishOnly": "father doctor && npm run build"
31 | },
32 | "repository": {
33 | "type": "git",
34 | "url": "https://github.com/wubostc/virtualized-table-for-antd"
35 | },
36 | "homepage": "https://github.com/wubostc/virtualized-table-for-antd",
37 | "author": {
38 | "name": "wubooo",
39 | "email": "913721086@qq.com"
40 | },
41 | "private": false,
42 | "license": "MIT",
43 | "devDependencies": {
44 | "@types/react": "^18.0.18",
45 | "@typescript-eslint/eslint-plugin": "^5.36.1",
46 | "@typescript-eslint/parser": "^5.36.1",
47 | "cross-env": "^7.0.3",
48 | "eslint": "^8.23.0",
49 | "eslint-loader": "^4.0.2",
50 | "father": "^4.0.3",
51 | "rimraf": "^3.0.2",
52 | "typescript": "^4.8.2"
53 | },
54 | "peerDependencies": {
55 | "antd": "^4.0.0 || ^5.0.0",
56 | "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
57 | "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
58 | },
59 | "browserslist": [
60 | "> 0.5%",
61 | "last 2 versions",
62 | "Firefox ESR",
63 | "not dead"
64 | ]
65 | }
66 |
--------------------------------------------------------------------------------
/src/index.tsx:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | The MIT License (MIT)
4 |
5 | Copyright (c) 2019 https://github.com/wubostc/
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 |
9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 | */
11 |
12 | /* eslint-disable no-console */
13 |
14 | import { TableComponents, _set_components, VtOpts, init } from './vt'
15 |
16 | const _brower = 1
17 | const _node = 2
18 |
19 | ;(function () {
20 | const env = typeof window === 'object' && window instanceof Window ? _brower : _node
21 | if (env & _brower) {
22 | if (!Object.hasOwnProperty.call(window, 'requestAnimationFrame') && !window.requestAnimationFrame)
23 | throw new Error('Please using the modern browers or appropriate polyfill!')
24 | }
25 | })()
26 |
27 |
28 |
29 | /**
30 | * @example
31 | *
32 | * function MyTableComponent() {
33 | *
34 | * // ... your code
35 | *
36 | *
37 | * const y = 600;
38 | * const [ vt, setComponents, vtRef ] = useVT(() => ({
39 | * scroll: {
40 | * y
41 | * }
42 | * }),
43 | * [y]);
44 | *
45 | * // useEffect(() => {
46 | * // setComponents({
47 | * // body: {
48 | * // cell: MyCell,
49 | * // }
50 | * // })
51 | * // });
52 | *
53 | * // useEffect(() => vtRef.current.toScroll(100), []);
54 | *
55 | * return (
56 | *
62 | * );
63 | * }
64 | */
65 | function useVT(fnOpts: () => VtOpts, deps: React.DependencyList):
66 | [
67 | TableComponents,
68 | (components: TableComponents) => void,
69 | Required['ref']
70 | ]
71 | {
72 | const ctx = init(fnOpts, deps || [])
73 |
74 |
75 | return [ctx._vtcomponents, (components: TableComponents) => _set_components(ctx, components), ctx.ref]
76 | }
77 |
78 |
79 | export { useVT }
80 |
--------------------------------------------------------------------------------
/src/vt.tsx:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-console */
2 |
3 | /*
4 | The MIT License (MIT)
5 |
6 | Copyright (c) 2019 https://github.com/wubostc/
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11 | */
12 |
13 |
14 | import { useRef, useState, useCallback, useContext, useEffect, useMemo, useImperativeHandle, useLayoutEffect } from 'react'
15 | import * as React from 'react'
16 |
17 |
18 | type CustomizeComponent = React.FC;
19 |
20 | export
21 | interface TableComponents {
22 | table?: CustomizeComponent;
23 | header?: {
24 | wrapper?: CustomizeComponent;
25 | row?: CustomizeComponent;
26 | cell?: CustomizeComponent;
27 | };
28 | body?: {
29 | wrapper?: CustomizeComponent;
30 | row?: CustomizeComponent;
31 | cell?: CustomizeComponent;
32 | };
33 | }
34 |
35 |
36 |
37 | /**
38 | * THE EVENTS OF SCROLLING.
39 | */
40 | const SCROLLEVT_NULL = (0<<0)
41 | const SCROLLEVT_INIT = (1<<0)
42 | const SCROLLEVT_RECOMPUTE = (1<<1)
43 | const SCROLLEVT_NATIVE = (1<<3)
44 | const SCROLLEVT_BY_HOOK = (1<<6)
45 |
46 |
47 | // any events will be `SCROLLEVT_BY_HOOK` if the `ctx.f_top === TOP_CONTINUE`.
48 | const TOP_CONTINUE = 0
49 | const TOP_DONE = 1
50 |
51 |
52 |
53 | interface RefObject {
54 | scrollTo: (y: number) => void;
55 | scrollToIndex: (idx: number) => void;
56 | }
57 |
58 | export
59 | interface VtOpts {
60 | id?: number | string;
61 | /**
62 | * @default 5
63 | */
64 | overscanRowCount?: number;
65 |
66 | /**
67 | * this only needs the scroll.y
68 | */
69 | scroll: {
70 | y: number | string;
71 | };
72 |
73 | /**
74 | * wheel event(only works on native events).
75 | */
76 | onScroll?: ({ left, top, isEnd, }:
77 | { top: number; left: number; isEnd: boolean }) => void;
78 |
79 | initTop?: number;
80 |
81 | /**
82 | * Offset of the table when isEnd becomes true.
83 | * @default 0
84 | */
85 | offset?: number;
86 |
87 | /**
88 | * @default false
89 | */
90 | debug?: boolean;
91 |
92 |
93 | // pass -1 means scroll to the bottom of the table
94 | ref?: React.MutableRefObject;
95 | }
96 |
97 | /**
98 | * `INIT` -> `LOADED` -> `RUNNING`
99 | */
100 | enum e_VT_STATE {
101 | INIT = 1,
102 | LOADED = 2,
103 | RUNNING = 4,
104 | }
105 |
106 |
107 |
108 | type SimEvent = {
109 | target: { scrollTop: number; scrollLeft: number };
110 | flag: number;
111 | end?: boolean;
112 | };
113 |
114 |
115 |
116 | interface VT_CONTEXT extends VtOpts {
117 | _y: number; // an actual height of the HTML element '.ant-table-body'.
118 | _scroll_y: number | string; // this is the same as the `Table.scroll.y`.
119 |
120 | _vtcomponents: TableComponents; // virtual layer.
121 | components: TableComponents; // implementation layer.
122 | vt_state: e_VT_STATE;
123 | possible_hight_per_tr: number;
124 |
125 | /* 0: needn't to recalculate, > 0: to add, < 0 to subtract */
126 | re_computed: number;
127 | row_height: number[];
128 | row_count: number;
129 | prev_row_count: number;
130 | wrap_inst: React.RefObject;
131 |
132 | // return the last state.
133 | VTScroll?: (param?: { top: number; left: number }) => { top: number; left: number };
134 |
135 |
136 | computed_h: number; // a cache for the WH.
137 | WH: number; // Wrapped Height.
138 | // it's the newest value of `wrap_inst`'s height to update.
139 |
140 | HND_PAINT: number; // a handle for Batch Repainting.
141 | HND_RAF: number; // a handler of requestAnimationFrame
142 |
143 |
144 | // stores the variables for the offset following.
145 | // |
146 | // |
147 | // top
148 | // children[index] - head
149 | // .
150 | // .
151 | // .
152 | // .
153 | // children[index] - tail <= children.len
154 | // |
155 | _offset_top: number/* int */;
156 | _offset_head: number/* int */;
157 | _offset_tail: number/* int */;
158 |
159 | top: number;
160 | left: number;
161 | evt: number;
162 | end: boolean;
163 |
164 | final_top: number;
165 | f_final_top: number;
166 |
167 | update_count: number;
168 |
169 | on_update_wrap_style: () => void; /* it will be called when the `_y` is 0. */
170 |
171 | indexMap: WeakMap