diff --git a/.dumirc.ts b/.dumirc.ts index 37524183..1151616f 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -1,8 +1,21 @@ import { defineConfig } from 'dumi'; +import path from 'path'; + +const basePath = process.env.GH_PAGES ? '/virtual-list/' : '/'; +const publicPath = basePath; export default defineConfig({ + alias: { + '@rc-component/virtual-list$': path.resolve(__dirname, 'src'), + '@rc-component/virtual-list/es': path.resolve(__dirname, 'src'), + }, + mfsu: false, + favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], themeConfig: { - name: 'Tree', + name: 'Virtual List', + logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', }, - outputPath: '.doc', + outputPath: 'docs-dist', + base: basePath, + publicPath, }); diff --git a/.fatherrc.ts b/.fatherrc.ts new file mode 100644 index 00000000..96268ae1 --- /dev/null +++ b/.fatherrc.ts @@ -0,0 +1,5 @@ +import { defineConfig } from 'father'; + +export default defineConfig({ + plugins: ['@rc-component/father-plugin'], +}); diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..758659af --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: ant-design +open_collective: ant-design diff --git a/.github/dependabot.yml b/.github/dependabot.yml index dc675c37..3b730ef9 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,41 +1,19 @@ version: 2 updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - time: "21:00" - open-pull-requests-limit: 10 - ignore: - - dependency-name: np - versions: - - 7.2.0 - - 7.3.0 - - 7.4.0 - - dependency-name: "@types/react" - versions: - - 17.0.0 - - 17.0.1 - - 17.0.2 - - 17.0.3 - - dependency-name: "@types/jest" - versions: - - 26.0.20 - - 26.0.21 - - 26.0.22 - - dependency-name: react - versions: - - 16.14.0 - - 17.0.1 - - dependency-name: "@types/react-dom" - versions: - - 17.0.0 - - 17.0.1 - - 17.0.2 - - dependency-name: typescript - versions: - - 4.1.3 - - 4.1.4 - - 4.1.5 - - 4.2.2 - - 4.2.3 + - package-ecosystem: npm + directory: '/' + schedule: + interval: weekly + day: monday + time: '21:00' + timezone: Asia/Shanghai + open-pull-requests-limit: 10 + + - package-ecosystem: github-actions + directory: '/' + schedule: + interval: weekly + day: monday + time: '21:00' + timezone: Asia/Shanghai + open-pull-requests-limit: 10 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f06c552e..4ddf3594 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,12 +1,12 @@ -name: "CodeQL" +name: CodeQL on: push: - branches: [ "master" ] + branches: [master] pull_request: - branches: [ "master" ] + branches: [master] schedule: - - cron: "48 4 * * 3" + - cron: '40 12 * * 0' jobs: analyze: @@ -20,22 +20,24 @@ jobs: strategy: fail-fast: false matrix: - language: [ javascript ] + language: [javascript] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v7 + with: + persist-credentials: false - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e with: languages: ${{ matrix.language }} queries: +security-and-quality - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e with: - category: "/language:${{ matrix.language }}" + category: '/language:${{ matrix.language }}' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 716559ca..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: test -on: [push, pull_request] -jobs: - test: - uses: react-component/rc-test/.github/workflows/test.yml@main - secrets: inherit diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml new file mode 100644 index 00000000..1d160790 --- /dev/null +++ b/.github/workflows/react-component-ci.yml @@ -0,0 +1,16 @@ +name: ✅ test + +on: + push: + branches: [master] + pull_request: + branches: [master] + +permissions: + contents: read + +jobs: + test: + uses: react-component/rc-test/.github/workflows/test-utoo.yml@main + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/react-doctor.yml b/.github/workflows/react-doctor.yml new file mode 100644 index 00000000..56430b6e --- /dev/null +++ b/.github/workflows/react-doctor.yml @@ -0,0 +1,24 @@ +name: React Doctor + +on: + pull_request: + branches: [master] + +permissions: + contents: read + pull-requests: write + +concurrency: + group: react-doctor-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + react-doctor: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - uses: millionco/react-doctor@0b4f4f4bd248a154e64eb508a48347f71154b3f3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml new file mode 100644 index 00000000..1a44351c --- /dev/null +++ b/.github/workflows/surge-preview.yml @@ -0,0 +1,47 @@ +name: Surge Preview + +on: + pull_request: + branches: [master] + +permissions: + contents: read + pull-requests: write + statuses: write + +concurrency: + group: surge-preview-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - name: Check Surge token + id: surge-token + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + run: | + if [ -n "$SURGE_TOKEN" ]; then + echo "enabled=true" >> "$GITHUB_OUTPUT" + else + echo "enabled=false" >> "$GITHUB_OUTPUT" + fi + - name: Install dependencies + if: ${{ steps.surge-token.outputs.enabled == 'true' }} + run: npm install --ignore-scripts --no-audit --loglevel=warn + - name: Build preview + if: ${{ steps.surge-token.outputs.enabled == 'true' }} + run: npm run build + - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec + if: ${{ steps.surge-token.outputs.enabled == 'true' }} + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + with: + dist: docs-dist + failOnError: false + github_token: ${{ secrets.GITHUB_TOKEN }} + surge_token: ${{ env.SURGE_TOKEN }} diff --git a/.gitignore b/.gitignore index 615c9938..d7e5aee8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,11 +11,15 @@ pnpm-lock.yaml !tests/__mocks__/rc-util/lib !tests/__mocks__/@rc-component/util/lib bun.lockb - # umi .umi .umi-production .umi-test .env.local - -.dumi \ No newline at end of file +.dumi/tmp +.dumi/tmp-production +lib +es +coverage +docs-dist +.vercel diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 00000000..2312dc58 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +npx lint-staged diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..c466d872 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,14 @@ +node_modules +coverage +docs-dist +dist +es +lib +.dumi/tmp +.dumi/tmp-production +.vercel +package-lock.json +pnpm-lock.yaml +yarn.lock +bun.lockb +*.log diff --git a/README.md b/README.md index fa110e03..0d63d5f0 100644 --- a/README.md +++ b/README.md @@ -1,79 +1,99 @@ -# @rc-component/virtual-list - -React Virtual List Component which works with animation. - -[![NPM version][npm-image]][npm-url] -[![npm download][download-image]][download-url] -[![build status][github-actions-image]][github-actions-url] -[![Codecov][codecov-image]][codecov-url] -[![bundle size][bundlephobia-image]][bundlephobia-url] -[![dumi][dumi-image]][dumi-url] - -[npm-image]: https://img.shields.io/npm/v/@rc-component/virtual-list.svg?style=flat-square -[npm-url]: https://npmjs.org/package/@rc-component/virtual-list -[travis-image]: https://img.shields.io/travis/react-component/virtual-list/master?style=flat-square -[travis-url]: https://travis-ci.com/react-component/virtual-list -[github-actions-image]: https://github.com/react-component/virtual-list/actions/workflows/main.yml/badge.svg -[github-actions-url]: https://github.com/react-component/virtual-list/actions/workflows/main.yml -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/virtual-list/master.svg?style=flat-square -[codecov-url]: https://app.codecov.io/gh/react-component/virtual-list -[david-url]: https://david-dm.org/react-component/virtual-list -[david-image]: https://david-dm.org/react-component/virtual-list/status.svg?style=flat-square -[david-dev-url]: https://david-dm.org/react-component/virtual-list?type=dev -[david-dev-image]: https://david-dm.org/react-component/virtual-list/dev-status.svg?style=flat-square -[download-image]: https://img.shields.io/npm/dm/@rc-component/virtual-list.svg?style=flat-square -[download-url]: https://npmjs.org/package/@rc-component/virtual-list -[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/virtual-list -[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/virtual-list -[dumi-url]: https://github.com/umijs/dumi -[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square - -## Online Preview - -https://virtual-list-react-component.vercel.app/ +
+

@rc-component/virtual-list

+

Ant Design Part of the Ant Design ecosystem.

+

📜 Virtual scrolling list component for React.

-## Development +

+ NPM version + npm downloads + build status + Codecov + bundle size + dumi +

+
+ +

English | 简体中文

-```bash -npm install -npm start -open http://localhost:8000/ -``` -## Feature +## Highlights -- Support react.js -- Support animation -- Support IE11+ +- Built for React and maintained by the rc-component team. +- Used by Ant Design and other React component libraries. +- Ships TypeScript declarations with both ES module and CommonJS outputs. +- Keeps examples, tests, and preview builds aligned with the package source. ## Install -[![@rc-component/virtual-list](https://nodei.co/npm/@rc-component/virtual-list.png)](https://npmjs.org/package/@rc-component/virtual-list) +```bash +npm install @rc-component/virtual-list +``` ## Usage ```tsx import List from '@rc-component/virtual-list'; - - {(index) =>
{index}
} -
; +const data = Array.from({ length: 1000 }).map((_, index) => ({ + id: index, + label: `Item ${index}`, +})); + +export default () => ( + + {(item) =>
{item.label}
} +
+); +``` + +## Examples + +Run the local dumi site: + +```bash +npm install +npm start ``` -# API +Then open `http://localhost:8000`. + +## API + +### List + +| Prop | Description | Type | Default | +| ---------- | ---------------------------------------------------------------------------------------------------------------------- | -------------------------------------- | ------- | +| children | Render function for each item. The third argument contains measuring props used by legacy browser compatibility paths. | `(item, index, props) => ReactElement` | - | +| component | Custom list container element. | `string` \| `ComponentType` | `div` | +| data | Items rendered by the virtual list. | `T[]` | - | +| disabled | Disable scroll position checks, usually while coordinating animation. | `boolean` | `false` | +| fullHeight | Whether the holder should keep full height. | `boolean` | `true` | +| height | Visible list height. | `number` | - | +| itemHeight | Minimum item height used to calculate the virtual range. | `number` | - | +| itemKey | Key field or key getter for items. | `string` \| `(item) => React.Key` | - | +| onScroll | Called when the list scrolls. | `React.UIEventHandler` | - | +| styles | Custom scrollbar part styles. | `object` | - | +| virtual | Enable virtual rendering. | `boolean` | `true` | + +## Development + +```bash +npm install +npm start +npm test +npm run build +``` + +The dumi site runs at `http://localhost:8000` by default. + +## Release + +```bash +npm run prepublishOnly +``` -## List +The release flow is handled by `@rc-component/np` through the `rc-np` command after the package build. -| Prop | Description | Type | Default | -| ---------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| children | Render props of item | (item, index, props) => ReactElement | - | -| component | Customize List dom element | string \| Component | div | -| data | Data list | Array | - | -| disabled | Disable scroll check. Usually used on animation control | boolean | false | -| height | List height | number | - | -| itemHeight | Item minimum height | number | - | -| itemKey | Match key with item | string | - | -| styles | style | { horizontalScrollBar?: React.CSSProperties; horizontalScrollBarThumb?: React.CSSProperties; verticalScrollBar?: React.CSSProperties; verticalScrollBarThumb?: React.CSSProperties; } | - | +## License -`children` provides additional `props` argument to support IE 11 scroll shaking. -It will set `style` to `visibility: hidden` when measuring. You can ignore this if no requirement on IE. +@rc-component/virtual-list is released under the [MIT](./LICENSE) license. diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 00000000..d0a3192e --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,99 @@ +
+

@rc-component/virtual-list

+

Ant Design Ant Design 生态的一部分。

+

📜 React 虚拟列表组件,用于高性能渲染长列表。

+ +

+ NPM version + npm downloads + build status + Codecov + bundle size + dumi +

+
+ +

English | 简体中文

+ + +## 特性 + +- 面向 React 构建,并由 rc-component 团队维护。 +- 被 Ant Design 使用和其他 React 组件库使用。 +- 提供 TypeScript 类型声明,同时输出 ES module 和 CommonJS 产物。 +- 示例、测试和预览构建与包源码保持一致。 + +## 安装 + +```bash +npm install @rc-component/virtual-list +``` + +## 使用 + +```tsx +import List from '@rc-component/virtual-list'; + +const data = Array.from({ length: 1000 }).map((_, index) => ({ + id: index, + label: `Item ${index}`, +})); + +export default () => ( + + {(item) =>
{item.label}
} +
+); +``` + +## 示例 + +运行本地 dumi 站点: + +```bash +npm install +npm start +``` + +然后打开 `http://localhost:8000`。 + +## API + +### List + +| 属性 | 说明 | 类型 | 默认值 | +| ---------- | ---------------------------------------------------------------------------------------------------------------------- | -------------------------------------- | ------- | +| children | 每一项的渲染函数。第三个参数包含旧浏览器兼容路径使用的测量 props。 | `(item, index, props) => ReactElement` | - | +| component | 自定义列表容器元素。 | `string` \| `ComponentType` | `div` | +| data | 虚拟列表渲染的数据项。 | `T[]` | - | +| disabled | 禁用滚动位置检查,通常用于配合动画。 | `boolean` | `false` | +| fullHeight | holder 是否保持完整高度。 | `boolean` | `true` | +| height | 可视列表高度。 | `number` | - | +| itemHeight | 用于计算虚拟范围的最小项高度。 | `number` | - | +| itemKey | 数据项 key 字段或 key 获取函数。 | `string` \| `(item) => React.Key` | - | +| onScroll | 列表滚动时调用。 | `React.UIEventHandler` | - | +| styles | 自定义滚动条部位样式。 | `object` | - | +| virtual | 启用虚拟渲染。 | `boolean` | `true` | + +## 本地开发 + +```bash +npm install +npm start +npm test +npm run build +``` + +dumi 站点默认运行在 `http://localhost:8000`。 + +## 发布 + +```bash +npm run prepublishOnly +``` + +包构建完成后,发布流程由 `@rc-component/np` 通过 `rc-np` 命令处理。 + +## 许可证 + +@rc-component/virtual-list 基于 [MIT](./LICENSE) 许可证发布。 diff --git a/docs/demo/horizontal-scroll.md b/docs/demo/horizontal-scroll.md index 7afcf130..8ae96f1e 100644 --- a/docs/demo/horizontal-scroll.md +++ b/docs/demo/horizontal-scroll.md @@ -5,4 +5,4 @@ nav: path: /demo --- - \ No newline at end of file + diff --git a/docs/index.md b/docs/index.md index 8eb92fd2..501296b5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,5 +1,5 @@ --- -title: rc-virtual-list +title: '@rc-component/virtual-list' --- diff --git a/package.json b/package.json index 2ed54719..62e4e0d9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@rc-component/virtual-list", "version": "1.2.0", - "description": "React Virtual List Component", + "description": "Virtual scrolling list component for React.", "engines": { "node": ">=8.x" }, @@ -10,7 +10,7 @@ "react-component", "virtual-list" ], - "homepage": "https://github.com/react-component/virtual-list", + "homepage": "https://react-component.github.io/virtual-list", "author": "smith3816@gmail.com", "repository": { "type": "git", @@ -28,38 +28,50 @@ "main": "./lib/index", "module": "./es/index", "scripts": { - "start": "dumi dev", - "build": "dumi build", + "build": "npm run compile && npm run docs:build", "compile": "father build", - "prepublishOnly": "npm run compile && rc-np", + "coverage": "rc-test --coverage", + "docs:build": "dumi build", + "docs:deploy": "gh-pages -d docs-dist", + "deploy": "npm run gh-pages", + "gh-pages": "npm run compile && cross-env GH_PAGES=1 npm run docs:build && npm run docs:deploy", "lint": "eslint src/ --ext .tsx,.ts", + "prepublishOnly": "npm run compile && rc-np", + "prettier": "prettier --write --ignore-unknown .", + "start": "dumi dev", "test": "rc-test", - "now-build": "npm run build" + "tsc": "tsc --noEmit", + "prepare": "husky" }, "peerDependencies": { "react": ">=18.0.0", "react-dom": ">=18.0.0" }, "devDependencies": { - "@rc-component/father-plugin": "^2.1.3", + "@rc-component/father-plugin": "^2.2.0", "@rc-component/np": "^1.0.4", - "@testing-library/jest-dom": "^5.17.0", - "@testing-library/react": "^13.4.0", - "@types/jest": "^30.0.0", - "@types/node": "^24.10.1", - "@types/react": "^18.0.8", - "@types/react-dom": "^18.0.3", - "@types/warning": "^3.0.0", - "dumi": "^2.2.17", - "eslint": "^8.56.0", - "eslint-plugin-unicorn": "^55.0.0", - "father": "^4.4.0", - "glob": "^7.1.6", + "@testing-library/jest-dom": "^6.9.1", + "@testing-library/react": "^15.0.7", + "@types/jest": "^29.5.14", + "@types/node": "^26.0.1", + "@types/react": "^18.3.31", + "@types/react-dom": "^18.3.7", + "@types/warning": "^3.0.4", + "dumi": "^2.4.35", + "eslint": "^8.57.1", + "eslint-plugin-unicorn": "^56.0.1", + "father": "^4.6.23", + "glob": "^13.0.6", "rc-animate": "^2.9.1", "rc-test": "^7.1.3", "react": "^18.3.1", "react-dom": "^18.3.1", - "typescript": "^5.0.0" + "typescript": "^5.9.3", + "cross-env": "^10.1.0", + "gh-pages": "^6.3.0", + "prettier": "^3.9.0", + "husky": "^9.1.7", + "lint-staged": "^16.4.0" }, "dependencies": { "@babel/runtime": "^7.20.0", @@ -69,5 +81,9 @@ }, "publishConfig": { "access": "public" - } + }, + "lint-staged": { + "*": "prettier --write --ignore-unknown" + }, + "types": "./es/index.d.ts" } diff --git a/tsconfig.json b/tsconfig.json index 30faa7c5..edc503cd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,11 +12,30 @@ "src/*" ], "@@/*": [ - "src/.umi/*" + ".dumi/tmp/*" ], - "rc-virtual-list": [ + "@rc-component/virtual-list": [ "src/index.ts" + ], + "@rc-component/virtual-list/es": [ + "src" + ], + "@rc-component/virtual-list/es/*": [ + "src/*" ] - } - } -} \ No newline at end of file + }, + "ignoreDeprecations": "5.0" + }, + "include": [ + ".dumirc.ts", + ".fatherrc.ts", + "src", + "tests", + "examples" + ], + "exclude": [ + "docs-dist", + "lib", + "es" + ] +} diff --git a/vercel.json b/vercel.json index 57c51ac8..5f9139ef 100644 --- a/vercel.json +++ b/vercel.json @@ -1,3 +1,6 @@ { - "framework": "umijs" -} \ No newline at end of file + "framework": "umijs", + "installCommand": "npm install", + "buildCommand": "npm run build", + "outputDirectory": "docs-dist" +}