add hw2
This commit is contained in:
21
node_modules/@tanstack/react-virtual/LICENSE
generated
vendored
Normal file
21
node_modules/@tanstack/react-virtual/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-present Tanner Linsley
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
76
node_modules/@tanstack/react-virtual/dist/cjs/index.cjs
generated
vendored
Normal file
76
node_modules/@tanstack/react-virtual/dist/cjs/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const React = require("react");
|
||||
const reactDom = require("react-dom");
|
||||
const virtualCore = require("@tanstack/virtual-core");
|
||||
function _interopNamespaceDefault(e) {
|
||||
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
||||
if (e) {
|
||||
for (const k in e) {
|
||||
if (k !== "default") {
|
||||
const d = Object.getOwnPropertyDescriptor(e, k);
|
||||
Object.defineProperty(n, k, d.get ? d : {
|
||||
enumerable: true,
|
||||
get: () => e[k]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
n.default = e;
|
||||
return Object.freeze(n);
|
||||
}
|
||||
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
||||
const useIsomorphicLayoutEffect = typeof document !== "undefined" ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
||||
function useVirtualizerBase(options) {
|
||||
const rerender = React__namespace.useReducer(() => ({}), {})[1];
|
||||
const resolvedOptions = {
|
||||
...options,
|
||||
onChange: (instance2, sync) => {
|
||||
var _a;
|
||||
if (sync) {
|
||||
reactDom.flushSync(rerender);
|
||||
} else {
|
||||
rerender();
|
||||
}
|
||||
(_a = options.onChange) == null ? void 0 : _a.call(options, instance2, sync);
|
||||
}
|
||||
};
|
||||
const [instance] = React__namespace.useState(
|
||||
() => new virtualCore.Virtualizer(resolvedOptions)
|
||||
);
|
||||
instance.setOptions(resolvedOptions);
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
return instance._didMount();
|
||||
}, []);
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
return instance._willUpdate();
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
function useVirtualizer(options) {
|
||||
return useVirtualizerBase({
|
||||
observeElementRect: virtualCore.observeElementRect,
|
||||
observeElementOffset: virtualCore.observeElementOffset,
|
||||
scrollToFn: virtualCore.elementScroll,
|
||||
...options
|
||||
});
|
||||
}
|
||||
function useWindowVirtualizer(options) {
|
||||
return useVirtualizerBase({
|
||||
getScrollElement: () => typeof document !== "undefined" ? window : null,
|
||||
observeElementRect: virtualCore.observeWindowRect,
|
||||
observeElementOffset: virtualCore.observeWindowOffset,
|
||||
scrollToFn: virtualCore.windowScroll,
|
||||
initialOffset: () => typeof document !== "undefined" ? window.scrollY : 0,
|
||||
...options
|
||||
});
|
||||
}
|
||||
exports.useVirtualizer = useVirtualizer;
|
||||
exports.useWindowVirtualizer = useWindowVirtualizer;
|
||||
Object.keys(virtualCore).forEach((k) => {
|
||||
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
||||
enumerable: true,
|
||||
get: () => virtualCore[k]
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=index.cjs.map
|
||||
1
node_modules/@tanstack/react-virtual/dist/cjs/index.cjs.map
generated
vendored
Normal file
1
node_modules/@tanstack/react-virtual/dist/cjs/index.cjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.cjs","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { flushSync } from 'react-dom'\nimport {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nconst useIsomorphicLayoutEffect =\n typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n): Virtualizer<TScrollElement, TItemElement> {\n const rerender = React.useReducer(() => ({}), {})[1]\n\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...options,\n onChange: (instance, sync) => {\n if (sync) {\n flushSync(rerender)\n } else {\n rerender()\n }\n options.onChange?.(instance, sync)\n },\n }\n\n const [instance] = React.useState(\n () => new Virtualizer<TScrollElement, TItemElement>(resolvedOptions),\n )\n\n instance.setOptions(resolvedOptions)\n\n useIsomorphicLayoutEffect(() => {\n return instance._didMount()\n }, [])\n\n useIsomorphicLayoutEffect(() => {\n return instance._willUpdate()\n })\n\n return instance\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n): Virtualizer<TScrollElement, TItemElement> {\n return useVirtualizerBase<TScrollElement, TItemElement>({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...options,\n })\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n): Virtualizer<Window, TItemElement> {\n return useVirtualizerBase<Window, TItemElement>({\n getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () => (typeof document !== 'undefined' ? window.scrollY : 0),\n ...options,\n })\n}\n"],"names":["React","instance","flushSync","Virtualizer","observeElementRect","observeElementOffset","elementScroll","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,4BACJ,OAAO,aAAa,cAAcA,iBAAM,kBAAkBA,iBAAM;AAElE,SAAS,mBAIP,SAC2C;AACrC,QAAA,WAAWA,iBAAM,WAAW,OAAO,CAAA,IAAK,CAAA,CAAE,EAAE,CAAC;AAEnD,QAAM,kBAAoE;AAAA,IACxE,GAAG;AAAA,IACH,UAAU,CAACC,WAAU,SAAS;;AAC5B,UAAI,MAAM;AACRC,iBAAAA,UAAU,QAAQ;AAAA,MAAA,OACb;AACI,iBAAA;AAAA,MAAA;AAEH,oBAAA,aAAA,iCAAWD,WAAU;AAAA,IAAI;AAAA,EAErC;AAEM,QAAA,CAAC,QAAQ,IAAID,iBAAM;AAAA,IACvB,MAAM,IAAIG,YAAA,YAA0C,eAAe;AAAA,EACrE;AAEA,WAAS,WAAW,eAAe;AAEnC,4BAA0B,MAAM;AAC9B,WAAO,SAAS,UAAU;AAAA,EAC5B,GAAG,EAAE;AAEL,4BAA0B,MAAM;AAC9B,WAAO,SAAS,YAAY;AAAA,EAAA,CAC7B;AAEM,SAAA;AACT;AAEO,SAAS,eAId,SAI2C;AAC3C,SAAO,mBAAiD;AAAA,IAAA,oBACtDC,YAAA;AAAA,IAAA,sBACAC,YAAA;AAAA,IACA,YAAYC,YAAA;AAAA,IACZ,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,qBACd,SAOmC;AACnC,SAAO,mBAAyC;AAAA,IAC9C,kBAAkB,MAAO,OAAO,aAAa,cAAc,SAAS;AAAA,IACpE,oBAAoBC,YAAA;AAAA,IACpB,sBAAsBC,YAAA;AAAA,IACtB,YAAYC,YAAA;AAAA,IACZ,eAAe,MAAO,OAAO,aAAa,cAAc,OAAO,UAAU;AAAA,IACzE,GAAG;AAAA,EAAA,CACJ;AACH;;;;;;;;;"}
|
||||
4
node_modules/@tanstack/react-virtual/dist/cjs/index.d.cts
generated
vendored
Normal file
4
node_modules/@tanstack/react-virtual/dist/cjs/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Virtualizer, PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core';
|
||||
export * from '@tanstack/virtual-core';
|
||||
export declare function useVirtualizer<TScrollElement extends Element, TItemElement extends Element>(options: PartialKeys<VirtualizerOptions<TScrollElement, TItemElement>, 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>): Virtualizer<TScrollElement, TItemElement>;
|
||||
export declare function useWindowVirtualizer<TItemElement extends Element>(options: PartialKeys<VirtualizerOptions<Window, TItemElement>, 'getScrollElement' | 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>): Virtualizer<Window, TItemElement>;
|
||||
4
node_modules/@tanstack/react-virtual/dist/esm/index.d.ts
generated
vendored
Normal file
4
node_modules/@tanstack/react-virtual/dist/esm/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Virtualizer, PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core';
|
||||
export * from '@tanstack/virtual-core';
|
||||
export declare function useVirtualizer<TScrollElement extends Element, TItemElement extends Element>(options: PartialKeys<VirtualizerOptions<TScrollElement, TItemElement>, 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>): Virtualizer<TScrollElement, TItemElement>;
|
||||
export declare function useWindowVirtualizer<TItemElement extends Element>(options: PartialKeys<VirtualizerOptions<Window, TItemElement>, 'getScrollElement' | 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>): Virtualizer<Window, TItemElement>;
|
||||
54
node_modules/@tanstack/react-virtual/dist/esm/index.js
generated
vendored
Normal file
54
node_modules/@tanstack/react-virtual/dist/esm/index.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as React from "react";
|
||||
import { flushSync } from "react-dom";
|
||||
import { Virtualizer, elementScroll, observeElementOffset, observeElementRect, windowScroll, observeWindowOffset, observeWindowRect } from "@tanstack/virtual-core";
|
||||
export * from "@tanstack/virtual-core";
|
||||
const useIsomorphicLayoutEffect = typeof document !== "undefined" ? React.useLayoutEffect : React.useEffect;
|
||||
function useVirtualizerBase(options) {
|
||||
const rerender = React.useReducer(() => ({}), {})[1];
|
||||
const resolvedOptions = {
|
||||
...options,
|
||||
onChange: (instance2, sync) => {
|
||||
var _a;
|
||||
if (sync) {
|
||||
flushSync(rerender);
|
||||
} else {
|
||||
rerender();
|
||||
}
|
||||
(_a = options.onChange) == null ? void 0 : _a.call(options, instance2, sync);
|
||||
}
|
||||
};
|
||||
const [instance] = React.useState(
|
||||
() => new Virtualizer(resolvedOptions)
|
||||
);
|
||||
instance.setOptions(resolvedOptions);
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
return instance._didMount();
|
||||
}, []);
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
return instance._willUpdate();
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
function useVirtualizer(options) {
|
||||
return useVirtualizerBase({
|
||||
observeElementRect,
|
||||
observeElementOffset,
|
||||
scrollToFn: elementScroll,
|
||||
...options
|
||||
});
|
||||
}
|
||||
function useWindowVirtualizer(options) {
|
||||
return useVirtualizerBase({
|
||||
getScrollElement: () => typeof document !== "undefined" ? window : null,
|
||||
observeElementRect: observeWindowRect,
|
||||
observeElementOffset: observeWindowOffset,
|
||||
scrollToFn: windowScroll,
|
||||
initialOffset: () => typeof document !== "undefined" ? window.scrollY : 0,
|
||||
...options
|
||||
});
|
||||
}
|
||||
export {
|
||||
useVirtualizer,
|
||||
useWindowVirtualizer
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@tanstack/react-virtual/dist/esm/index.js.map
generated
vendored
Normal file
1
node_modules/@tanstack/react-virtual/dist/esm/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { flushSync } from 'react-dom'\nimport {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nconst useIsomorphicLayoutEffect =\n typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n): Virtualizer<TScrollElement, TItemElement> {\n const rerender = React.useReducer(() => ({}), {})[1]\n\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...options,\n onChange: (instance, sync) => {\n if (sync) {\n flushSync(rerender)\n } else {\n rerender()\n }\n options.onChange?.(instance, sync)\n },\n }\n\n const [instance] = React.useState(\n () => new Virtualizer<TScrollElement, TItemElement>(resolvedOptions),\n )\n\n instance.setOptions(resolvedOptions)\n\n useIsomorphicLayoutEffect(() => {\n return instance._didMount()\n }, [])\n\n useIsomorphicLayoutEffect(() => {\n return instance._willUpdate()\n })\n\n return instance\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n): Virtualizer<TScrollElement, TItemElement> {\n return useVirtualizerBase<TScrollElement, TItemElement>({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...options,\n })\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n): Virtualizer<Window, TItemElement> {\n return useVirtualizerBase<Window, TItemElement>({\n getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () => (typeof document !== 'undefined' ? window.scrollY : 0),\n ...options,\n })\n}\n"],"names":["instance"],"mappings":";;;;AAeA,MAAM,4BACJ,OAAO,aAAa,cAAc,MAAM,kBAAkB,MAAM;AAElE,SAAS,mBAIP,SAC2C;AACrC,QAAA,WAAW,MAAM,WAAW,OAAO,CAAA,IAAK,CAAA,CAAE,EAAE,CAAC;AAEnD,QAAM,kBAAoE;AAAA,IACxE,GAAG;AAAA,IACH,UAAU,CAACA,WAAU,SAAS;;AAC5B,UAAI,MAAM;AACR,kBAAU,QAAQ;AAAA,MAAA,OACb;AACI,iBAAA;AAAA,MAAA;AAEH,oBAAA,aAAA,iCAAWA,WAAU;AAAA,IAAI;AAAA,EAErC;AAEM,QAAA,CAAC,QAAQ,IAAI,MAAM;AAAA,IACvB,MAAM,IAAI,YAA0C,eAAe;AAAA,EACrE;AAEA,WAAS,WAAW,eAAe;AAEnC,4BAA0B,MAAM;AAC9B,WAAO,SAAS,UAAU;AAAA,EAC5B,GAAG,EAAE;AAEL,4BAA0B,MAAM;AAC9B,WAAO,SAAS,YAAY;AAAA,EAAA,CAC7B;AAEM,SAAA;AACT;AAEO,SAAS,eAId,SAI2C;AAC3C,SAAO,mBAAiD;AAAA,IACtD;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,qBACd,SAOmC;AACnC,SAAO,mBAAyC;AAAA,IAC9C,kBAAkB,MAAO,OAAO,aAAa,cAAc,SAAS;AAAA,IACpE,oBAAoB;AAAA,IACpB,sBAAsB;AAAA,IACtB,YAAY;AAAA,IACZ,eAAe,MAAO,OAAO,aAAa,cAAc,OAAO,UAAU;AAAA,IACzE,GAAG;AAAA,EAAA,CACJ;AACH;"}
|
||||
73
node_modules/@tanstack/react-virtual/package.json
generated
vendored
Normal file
73
node_modules/@tanstack/react-virtual/package.json
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"name": "@tanstack/react-virtual",
|
||||
"version": "3.13.12",
|
||||
"description": "Headless UI for virtualizing scrollable elements in React",
|
||||
"author": "Tanner Linsley",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/TanStack/virtual.git",
|
||||
"directory": "packages/react-virtual"
|
||||
},
|
||||
"homepage": "https://tanstack.com/virtual",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/tannerlinsley"
|
||||
},
|
||||
"keywords": [
|
||||
"react",
|
||||
"vue",
|
||||
"solid",
|
||||
"virtual",
|
||||
"virtual-core",
|
||||
"datagrid"
|
||||
],
|
||||
"type": "module",
|
||||
"types": "dist/esm/index.d.ts",
|
||||
"main": "dist/cjs/index.cjs",
|
||||
"module": "dist/esm/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/cjs/index.d.cts",
|
||||
"default": "./dist/cjs/index.cjs"
|
||||
}
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"dependencies": {
|
||||
"@tanstack/virtual-core": "3.13.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/react": "^16.3.0",
|
||||
"@types/react": "^18.3.23",
|
||||
"@types/react-dom": "^18.3.7",
|
||||
"@vitejs/plugin-react": "^4.5.2",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"resize-observer-polyfill": "^1.5.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
||||
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "premove ./dist ./coverage",
|
||||
"test:eslint": "eslint ./src",
|
||||
"test:types": "tsc",
|
||||
"test:lib": "vitest",
|
||||
"test:lib:dev": "pnpm run test:lib --watch",
|
||||
"test:build": "publint --strict",
|
||||
"build": "vite build",
|
||||
"test:e2e": "playwright test"
|
||||
}
|
||||
}
|
||||
90
node_modules/@tanstack/react-virtual/src/index.tsx
generated
vendored
Normal file
90
node_modules/@tanstack/react-virtual/src/index.tsx
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
import * as React from 'react'
|
||||
import { flushSync } from 'react-dom'
|
||||
import {
|
||||
Virtualizer,
|
||||
elementScroll,
|
||||
observeElementOffset,
|
||||
observeElementRect,
|
||||
observeWindowOffset,
|
||||
observeWindowRect,
|
||||
windowScroll,
|
||||
} from '@tanstack/virtual-core'
|
||||
import type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'
|
||||
|
||||
export * from '@tanstack/virtual-core'
|
||||
|
||||
const useIsomorphicLayoutEffect =
|
||||
typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect
|
||||
|
||||
function useVirtualizerBase<
|
||||
TScrollElement extends Element | Window,
|
||||
TItemElement extends Element,
|
||||
>(
|
||||
options: VirtualizerOptions<TScrollElement, TItemElement>,
|
||||
): Virtualizer<TScrollElement, TItemElement> {
|
||||
const rerender = React.useReducer(() => ({}), {})[1]
|
||||
|
||||
const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {
|
||||
...options,
|
||||
onChange: (instance, sync) => {
|
||||
if (sync) {
|
||||
flushSync(rerender)
|
||||
} else {
|
||||
rerender()
|
||||
}
|
||||
options.onChange?.(instance, sync)
|
||||
},
|
||||
}
|
||||
|
||||
const [instance] = React.useState(
|
||||
() => new Virtualizer<TScrollElement, TItemElement>(resolvedOptions),
|
||||
)
|
||||
|
||||
instance.setOptions(resolvedOptions)
|
||||
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
return instance._didMount()
|
||||
}, [])
|
||||
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
return instance._willUpdate()
|
||||
})
|
||||
|
||||
return instance
|
||||
}
|
||||
|
||||
export function useVirtualizer<
|
||||
TScrollElement extends Element,
|
||||
TItemElement extends Element,
|
||||
>(
|
||||
options: PartialKeys<
|
||||
VirtualizerOptions<TScrollElement, TItemElement>,
|
||||
'observeElementRect' | 'observeElementOffset' | 'scrollToFn'
|
||||
>,
|
||||
): Virtualizer<TScrollElement, TItemElement> {
|
||||
return useVirtualizerBase<TScrollElement, TItemElement>({
|
||||
observeElementRect: observeElementRect,
|
||||
observeElementOffset: observeElementOffset,
|
||||
scrollToFn: elementScroll,
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export function useWindowVirtualizer<TItemElement extends Element>(
|
||||
options: PartialKeys<
|
||||
VirtualizerOptions<Window, TItemElement>,
|
||||
| 'getScrollElement'
|
||||
| 'observeElementRect'
|
||||
| 'observeElementOffset'
|
||||
| 'scrollToFn'
|
||||
>,
|
||||
): Virtualizer<Window, TItemElement> {
|
||||
return useVirtualizerBase<Window, TItemElement>({
|
||||
getScrollElement: () => (typeof document !== 'undefined' ? window : null),
|
||||
observeElementRect: observeWindowRect,
|
||||
observeElementOffset: observeWindowOffset,
|
||||
scrollToFn: windowScroll,
|
||||
initialOffset: () => (typeof document !== 'undefined' ? window.scrollY : 0),
|
||||
...options,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user