diff --git a/.gitignore b/.gitignore index c6ab88c2..8c1834c2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,10 @@ lib/ ~* yarn.lock package-lock.json -!tests/__mocks__/rc-util/lib \ No newline at end of file +!tests/__mocks__/rc-util/lib + +# umi +.umi +.umi-production +.umi-test +.env.local diff --git a/.umirc.ts b/.umirc.ts new file mode 100644 index 00000000..b5a40158 --- /dev/null +++ b/.umirc.ts @@ -0,0 +1,22 @@ +// more config: https://d.umijs.org/config +import { defineConfig } from 'dumi'; + +export default defineConfig({ + title: 'rc-virtual-list', + favicon: + 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', + logo: + 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', + outputPath: '.doc', + exportStatic: {}, + resolve: { + examples: ['none'], + }, + styles: [ + ` + .markdown table { + width: auto !important; + } + `, + ] +}); diff --git a/README.md b/README.md index d8d15875..c4577c39 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,7 @@ React Virtual List Component which worked with animation. -[![NPM version][npm-image]][npm-url] -[![build status][github-actions-image]][github-actions-url] -[![Test coverage][coveralls-image]][coveralls-url] -[![node version][node-image]][node-url] -[![npm download][download-image]][download-url] +[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][coveralls-image]][coveralls-url] [![node version][node-image]][node-url] [![npm download][download-image]][download-url] [npm-image]: http://img.shields.io/npm/v/rc-virtual-list.svg?style=flat-square [npm-url]: http://npmjs.org/package/rc-virtual-list diff --git a/docs/demo/animate.md b/docs/demo/animate.md new file mode 100644 index 00000000..61b8fb5d --- /dev/null +++ b/docs/demo/animate.md @@ -0,0 +1,3 @@ +## animate + + diff --git a/docs/demo/basic.md b/docs/demo/basic.md new file mode 100644 index 00000000..806f1426 --- /dev/null +++ b/docs/demo/basic.md @@ -0,0 +1,3 @@ +## basic + + diff --git a/docs/demo/height.md b/docs/demo/height.md new file mode 100644 index 00000000..7c041406 --- /dev/null +++ b/docs/demo/height.md @@ -0,0 +1,3 @@ +## height + + diff --git a/docs/demo/no-virtual.md b/docs/demo/no-virtual.md new file mode 100644 index 00000000..d139d2aa --- /dev/null +++ b/docs/demo/no-virtual.md @@ -0,0 +1,3 @@ +## no-virtual + + diff --git a/docs/demo/switch.md b/docs/demo/switch.md new file mode 100644 index 00000000..b80f4038 --- /dev/null +++ b/docs/demo/switch.md @@ -0,0 +1,3 @@ +## switch + + diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 00000000..8eb92fd2 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,5 @@ +--- +title: rc-virtual-list +--- + + diff --git a/now.json b/now.json index 7066da0e..397041a0 100644 --- a/now.json +++ b/now.json @@ -7,5 +7,8 @@ "use": "@now/static-build", "config": { "distDir": ".doc" } } + ], + "routes": [ + { "src": "/(.*)", "dest": "/dist/$1" } ] } \ No newline at end of file diff --git a/package.json b/package.json index ddc8b6db..b6912837 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ "main": "./lib/index", "module": "./es/index", "scripts": { - "start": "cross-env NODE_ENV=development father doc dev --storybook", - "build": "father doc build --storybook", + "start": "dumi dev", + "build": "dumi build", "compile": "father build", "prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish", "lint": "eslint src/ --ext .tsx,.ts", @@ -49,11 +49,13 @@ "@types/react-dom": "^16.8.4", "@types/warning": "^3.0.0", "cross-env": "^5.2.0", + "dumi": "^1.1.12", "enzyme": "^3.1.0", "enzyme-adapter-react-16": "^1.0.2", "enzyme-to-json": "^3.1.4", "eslint": "^7.6.0", "father": "^2.29.10", + "glob": "^7.1.6", "np": "^5.0.3", "rc-animate": "^2.9.1", "react": "^v16.9.0-alpha.0", diff --git a/src/List.tsx b/src/List.tsx index cd4720ea..a75536fe 100644 --- a/src/List.tsx +++ b/src/List.tsx @@ -3,7 +3,7 @@ import { useRef, useState } from 'react'; import classNames from 'classnames'; import Filler from './Filler'; import ScrollBar from './ScrollBar'; -import { RenderFunc, SharedConfig, GetKey } from './interface'; +import type { RenderFunc, SharedConfig, GetKey } from './interface'; import useChildren from './hooks/useChildren'; import useHeights from './hooks/useHeights'; import useScrollTo from './hooks/useScrollTo'; diff --git a/src/hooks/useChildren.tsx b/src/hooks/useChildren.tsx index ad8b8161..d22ea4c0 100644 --- a/src/hooks/useChildren.tsx +++ b/src/hooks/useChildren.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { SharedConfig, RenderFunc } from '../interface'; +import type { SharedConfig, RenderFunc } from '../interface'; import { Item } from '../Item'; export default function useChildren( diff --git a/src/hooks/useDiffItem.ts b/src/hooks/useDiffItem.ts index 88ac13ab..ac46a159 100644 --- a/src/hooks/useDiffItem.ts +++ b/src/hooks/useDiffItem.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { findListDiffIndex } from '../utils/algorithmUtil'; -import { GetKey } from '../interface'; +import type { GetKey } from '../interface'; export default function useDiffItem( data: T[], diff --git a/src/hooks/useHeights.tsx b/src/hooks/useHeights.tsx index cf5307ad..0cba1827 100644 --- a/src/hooks/useHeights.tsx +++ b/src/hooks/useHeights.tsx @@ -1,11 +1,9 @@ import * as React from 'react'; import { useRef } from 'react'; import findDOMNode from 'rc-util/lib/Dom/findDOMNode'; -import { GetKey } from '../interface'; +import type { GetKey } from '../interface'; import CacheMap from '../utils/CacheMap'; -type RefFunc = (instance: HTMLElement) => void; - export default function useHeights( getKey: GetKey, onItemAdd?: (item: T) => void, diff --git a/src/hooks/useScrollTo.tsx b/src/hooks/useScrollTo.tsx index 73352a82..49520378 100644 --- a/src/hooks/useScrollTo.tsx +++ b/src/hooks/useScrollTo.tsx @@ -1,9 +1,9 @@ /* eslint-disable no-param-reassign */ import * as React from 'react'; import raf from 'rc-util/lib/raf'; -import { ScrollTo } from '../List'; -import { GetKey } from '../interface'; -import CacheMap from '../utils/CacheMap'; +import type { ScrollTo } from '../List'; +import type { GetKey } from '../interface'; +import type CacheMap from '../utils/CacheMap'; export default function useScrollTo( containerRef: React.RefObject, diff --git a/src/mock.tsx b/src/mock.tsx index 2aa0ec7f..716f821c 100644 --- a/src/mock.tsx +++ b/src/mock.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; -import { RawList, ListProps, ListRef } from './List'; +import type { ListProps, ListRef } from './List'; +import { RawList } from './List'; const List = React.forwardRef((props: ListProps, ref: React.Ref) => RawList({ ...props, virtual: false }, ref), diff --git a/src/utils/CacheMap.ts b/src/utils/CacheMap.ts index 1c752bbe..3027abdd 100644 --- a/src/utils/CacheMap.ts +++ b/src/utils/CacheMap.ts @@ -1,4 +1,4 @@ -import React from 'react'; +import type React from 'react'; // Firefox has low performance of map. class CacheMap { diff --git a/src/utils/algorithmUtil.ts b/src/utils/algorithmUtil.ts index 8ab3e86d..8e7a97e8 100644 --- a/src/utils/algorithmUtil.ts +++ b/src/utils/algorithmUtil.ts @@ -1,4 +1,4 @@ -import * as React from 'react'; +import type * as React from 'react'; /** * Get index with specific start index one by one. e.g. * min: 3, max: 9, start: 6 diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..6be0af1a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "esnext", + "moduleResolution": "node", + "baseUrl": "./", + "jsx": "preserve", + "declaration": true, + "skipLibCheck": true, + "esModuleInterop": true, + "paths": { + "@/*": ["src/*"], + "@@/*": ["src/.umi/*"], + "rc-virtual-list": ["src/index.ts"] + } + } +} diff --git a/update-demo.js b/update-demo.js new file mode 100644 index 00000000..57d561c0 --- /dev/null +++ b/update-demo.js @@ -0,0 +1,29 @@ +/* + 用于 dumi 改造使用, + 可用于将 examples 的文件批量修改为 demo 引入形式, + 其他项目根据具体情况使用。 +*/ + +const fs = require('fs'); +const glob = require('glob'); + +const paths = glob.sync('./examples/*.tsx'); + +paths.forEach(path => { + const name = path.split('/').pop().split('.')[0]; + fs.writeFile( + `./docs/demo/${name}.md`, + `## ${name} + + +`, + 'utf8', + function(error) { + if(error){ + console.log(error); + return false; + } + console.log(`${name} 更新成功~`); + } + ) +});