diff --git a/.dumirc b/.dumirc index 2d5ba2b..ba410f7 100644 --- a/.dumirc +++ b/.dumirc @@ -3,8 +3,8 @@ import path from 'path'; export default defineConfig({ alias: { - 'rc-upload$': path.resolve('src'), - 'rc-upload/es': path.resolve('src'), + '@rc-component/upload$': path.resolve('src'), + '@rc-component/upload/es': path.resolve('src'), }, mfsu: false, favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], diff --git a/README.md b/README.md index 29c60c3..59e0a9c 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,11 @@ -# rc-upload +# @rc-component/upload React Upload -[![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 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]: http://img.shields.io/npm/v/rc-upload.svg?style=flat-square -[npm-url]: http://npmjs.org/package/rc-upload +[npm-image]: http://img.shields.io/npm/v/@rc-component/upload.svg?style=flat-square +[npm-url]: http://npmjs.org/package/@rc-component/upload [travis-image]: https://img.shields.io/travis/react-component/upload/master?style=flat-square [travis-url]: https://travis-ci.com/react-component/upload [github-actions-image]: https://github.com/react-component/upload/workflows/CI/badge.svg @@ -21,10 +16,10 @@ React Upload [david-image]: https://david-dm.org/react-component/upload/status.svg?style=flat-square [david-dev-url]: https://david-dm.org/react-component/upload?type=dev [david-dev-image]: https://david-dm.org/react-component/upload/dev-status.svg?style=flat-square -[download-image]: https://img.shields.io/npm/dm/rc-upload.svg?style=flat-square -[download-url]: https://npmjs.org/package/rc-upload -[bundlephobia-url]: https://bundlephobia.com/package/rc-upload -[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-upload +[download-image]: https://img.shields.io/npm/dm/@rc-component/upload.svg?style=flat-square +[download-url]: https://npmjs.org/package/@rc-component/upload +[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/upload +[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/upload [dumi-url]: https://github.com/umijs/dumi [dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square @@ -43,16 +38,16 @@ online example: https://upload.react-component.vercel.app/ ## Feature -* support IE11+, Chrome, Firefox, Safari +- support IE11+, Chrome, Firefox, Safari ## install -[![rc-upload](https://nodei.co/npm/rc-upload.png)](https://npmjs.org/package/rc-upload) +[![@rc-component/upload](https://nodei.co/npm/@rc-component/upload.png)](https://npmjs.org/package/@rc-component/upload) ## Usage ```js -var Upload = require('rc-upload'); +var Upload = require('@rc-component/upload'); var React = require('react'); React.render(, container); ``` @@ -61,30 +56,30 @@ React.render(, container); ### props -|name|type|default| description| -|-----|---|--------|----| -|name | string | file| file param post to server | -|style | object | {}| root component inline style | -|className | string | - | root component className | -|disabled | boolean | false | whether disabled | -|component | "div"|"span" | "span"| wrap component name | -|action| string | function(file): string | Promise<string> | | form action url | -|method | string | post | request method | -|directory| boolean | false | support upload whole directory | -|data| object/function(file) | | other data object to post or a function which returns a data object(a promise object which resolve a data object) | -|headers| object | {} | http headers to post, available in modern browsers | -|accept | string | | input accept attribute | -|capture | string | | input capture attribute | -|multiple | boolean | false | only support ie10+| -|onStart | function| | start upload file | -|onError| function| | error callback | -|onSuccess | function | | success callback | -|onProgress | function || progress callback, only for modern browsers| -|beforeUpload| function |null| before upload check, return false or a rejected Promise will stop upload, only for modern browsers| -|customRequest | function | null | provide an override for the default xhr behavior for additional customization| -|withCredentials | boolean | false | ajax upload with cookie send | -|openFileDialogOnClick | boolean | true | useful for drag only upload as it does not trigger on enter key or click event | -|pastable | boolean | false | support paste upload | +| name | type | default | description | +| --- | --- | --- | --- | +| name | string | file | file param post to server | +| style | object | {} | root component inline style | +| className | string | - | root component className | +| disabled | boolean | false | whether disabled | +| component | "div" \| "span" | "span" | wrap component name | +| action | string | function(file): string | Promise<string> | | form action url | +| method | string | post | request method | +| directory | boolean | false | support upload whole directory | +| data | object/function(file) | | other data object to post or a function which returns a data object(a promise object which resolve a data object) | +| headers | object | {} | http headers to post, available in modern browsers | +| accept | string | | input accept attribute | +| capture | string | | input capture attribute | +| multiple | boolean | false | only support ie10+ | +| onStart | function | | start upload file | +| onError | function | | error callback | +| onSuccess | function | | success callback | +| onProgress | function | | progress callback, only for modern browsers | +| beforeUpload | function | null | before upload check, return false or a rejected Promise will stop upload, only for modern browsers | +| customRequest | function | null | provide an override for the default xhr behavior for additional customization | +| withCredentials | boolean | false | ajax upload with cookie send | +| openFileDialogOnClick | boolean | true | useful for drag only upload as it does not trigger on enter key or click event | +| pastable | boolean | false | support paste upload | #### onError arguments @@ -96,9 +91,7 @@ React.render(, container); 1. `result`: response body 2. `file`: upload file -3. `xhr`: xhr header, only for modern browsers which support AJAX upload. since - 2.4.0 - +3. `xhr`: xhr header, only for modern browsers which support AJAX upload. since 2.4.0 ### customRequest @@ -106,16 +99,15 @@ Allows for advanced customization by overriding default behavior in AjaxUploader customRequest callback is passed an object with: -* `onProgress: (event: { percent: number }): void` -* `onError: (event: Error, body?: Object): void` -* `onSuccess: (body: Object): void` -* `data: Object` -* `filename: String` -* `file: File` -* `withCredentials: Boolean` -* `action: String` -* `headers: Object` - +- `onProgress: (event: { percent: number }): void` +- `onError: (event: Error, body?: Object): void` +- `onSuccess: (body: Object): void` +- `data: Object` +- `filename: String` +- `file: File` +- `withCredentials: Boolean` +- `action: String` +- `headers: Object` ### methods @@ -123,4 +115,4 @@ abort(file?: File) => void: abort the uploading file ## License -rc-upload is released under the MIT license. +@rc-component/upload is released under the MIT license. diff --git a/docs/examples/asyncAction.tsx b/docs/examples/asyncAction.tsx index c523cf3..84a4779 100644 --- a/docs/examples/asyncAction.tsx +++ b/docs/examples/asyncAction.tsx @@ -1,6 +1,6 @@ /* eslint no-console:0 */ import React from 'react'; -import Upload from 'rc-upload'; +import Upload from '@rc-component/upload'; const props = { action: () => { diff --git a/docs/examples/beforeUpload.tsx b/docs/examples/beforeUpload.tsx index bb27816..38f645a 100644 --- a/docs/examples/beforeUpload.tsx +++ b/docs/examples/beforeUpload.tsx @@ -1,7 +1,7 @@ /* eslint no-console:0 */ import type { Action, RcFile } from '@/interface'; -import Upload from 'rc-upload'; +import Upload from '@rc-component/upload'; const props = { action: '/upload.do' as Action, diff --git a/docs/examples/customRequest.tsx b/docs/examples/customRequest.tsx index afe58fd..2ea9953 100644 --- a/docs/examples/customRequest.tsx +++ b/docs/examples/customRequest.tsx @@ -1,7 +1,7 @@ /* eslint no-console:0 */ import React from 'react'; import axios from 'axios'; -import Upload from 'rc-upload'; +import Upload from '@rc-component/upload'; import { UploadRequestOption } from '@/interface'; const uploadProps = { diff --git a/docs/examples/directoryUpload.tsx b/docs/examples/directoryUpload.tsx index c2c749b..19641b7 100644 --- a/docs/examples/directoryUpload.tsx +++ b/docs/examples/directoryUpload.tsx @@ -1,7 +1,7 @@ /* eslint no-console:0 */ import React from 'react'; -import Upload from 'rc-upload'; +import Upload from '@rc-component/upload'; const Test = () => { const uploaderProps = { diff --git a/docs/examples/drag.tsx b/docs/examples/drag.tsx index caf08e4..626dfe7 100644 --- a/docs/examples/drag.tsx +++ b/docs/examples/drag.tsx @@ -1,6 +1,6 @@ /* eslint no-console:0 */ import React from 'react'; -import Upload from 'rc-upload'; +import Upload from '@rc-component/upload'; const props = { action: '/upload.do', diff --git a/docs/examples/dragDirectory.tsx b/docs/examples/dragDirectory.tsx index 487e323..b74c8fa 100644 --- a/docs/examples/dragDirectory.tsx +++ b/docs/examples/dragDirectory.tsx @@ -1,6 +1,6 @@ /* eslint no-console:0 */ import React from 'react'; -import Upload from 'rc-upload'; +import Upload from '@rc-component/upload'; const props = { action: '/upload.do', diff --git a/docs/examples/paste.tsx b/docs/examples/paste.tsx index b7c9506..3bdc7b8 100644 --- a/docs/examples/paste.tsx +++ b/docs/examples/paste.tsx @@ -1,6 +1,6 @@ /* eslint no-console:0 */ import React from 'react'; -import Upload from 'rc-upload'; +import Upload from '@rc-component/upload'; const props = { action: '/upload.do', diff --git a/docs/examples/pasteDirectory.tsx b/docs/examples/pasteDirectory.tsx index 3bb7aef..875591d 100644 --- a/docs/examples/pasteDirectory.tsx +++ b/docs/examples/pasteDirectory.tsx @@ -1,6 +1,6 @@ /* eslint no-console:0 */ import React from 'react'; -import Upload from 'rc-upload'; +import Upload from '@rc-component/upload'; const props = { action: '/upload.do', diff --git a/docs/examples/simple.tsx b/docs/examples/simple.tsx index c11d91a..cffb2a6 100644 --- a/docs/examples/simple.tsx +++ b/docs/examples/simple.tsx @@ -1,6 +1,6 @@ /* eslint no-console:0 */ -import Upload, { type UploadProps } from 'rc-upload'; +import Upload, { type UploadProps } from '@rc-component/upload'; import React from 'react'; const style = ` diff --git a/docs/index.md b/docs/index.md index 5d590b8..eee2f14 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,5 +1,5 @@ --- -title: rc-upload +title: @rc-component/upload --- \ No newline at end of file diff --git a/now.json b/now.json deleted file mode 100644 index c3e54f8..0000000 --- a/now.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": 2, - "name": "rc-upload", - "builds": [ - { - "src": "package.json", - "use": "@now/static-build", - "config": { "distDir": "dist" } - } - ] -} diff --git a/package.json b/package.json index 4956c38..5ff9af7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "rc-upload", - "version": "4.11.0", + "name": "@rc-component/upload", + "version": "1.0.0", "description": "upload ui component for react", "keywords": [ "react", @@ -30,19 +30,19 @@ "docs:deploy": "npm run docs:build && gh-pages -d dist", "lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md", "now-build": "npm run docs:build", - "prepublishOnly": "npm run compile && np --yolo --no-publish", + "prepublishOnly": "npm run compile && rc-np", "prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"", "postpublish": "npm run docs:deploy", "start": "dumi dev", "test": "rc-test" }, "dependencies": { - "@babel/runtime": "^7.18.3", - "classnames": "^2.2.5", - "rc-util": "^5.2.0" + "@rc-component/util": "^1.3.0", + "classnames": "^2.2.5" }, "devDependencies": { - "@rc-component/father-plugin": "^1.0.0", + "@rc-component/father-plugin": "^2.0.2", + "@rc-component/np": "^1.0.4", "@testing-library/jest-dom": "^6.1.5", "@testing-library/react": "^16.2.0", "@types/jest": "^30.0.0", @@ -58,7 +58,6 @@ "father": "^4.0.0", "fs-extra": "^11.2.0", "gh-pages": "^6.1.1", - "np": "^10.0.7", "raf": "^3.4.0", "rc-test": "^7.0.13", "react": "^18.0.0", diff --git a/src/AjaxUploader.tsx b/src/AjaxUploader.tsx index 6ba8fc1..f5551e9 100644 --- a/src/AjaxUploader.tsx +++ b/src/AjaxUploader.tsx @@ -1,6 +1,6 @@ /* eslint react/no-is-mounted:0,react/sort-comp:0,react/prop-types:0 */ import clsx from 'classnames'; -import pickAttrs from 'rc-util/lib/pickAttrs'; +import pickAttrs from '@rc-component/util/lib/pickAttrs'; import React, { Component } from 'react'; import attrAccept from './attr-accept'; import type { diff --git a/src/attr-accept.ts b/src/attr-accept.ts index 7d1caec..d16c2b6 100644 --- a/src/attr-accept.ts +++ b/src/attr-accept.ts @@ -1,4 +1,4 @@ -import warning from 'rc-util/lib/warning'; +import { warning } from '@rc-component/util'; import type { RcFile } from './interface'; export default (file: RcFile, acceptedFiles: string | string[]) => { diff --git a/tests/uploader.spec.tsx b/tests/uploader.spec.tsx index 71eb777..c688368 100644 --- a/tests/uploader.spec.tsx +++ b/tests/uploader.spec.tsx @@ -1,5 +1,5 @@ import { fireEvent, render } from '@testing-library/react'; -import { resetWarned } from 'rc-util/lib/warning'; +import { resetWarned } from '@rc-component/util/lib/warning'; import React from 'react'; import sinon from 'sinon'; import { format } from 'util'; diff --git a/tsconfig.json b/tsconfig.json index 3ea7e93..604e96a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,21 +8,10 @@ "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": [ - "src/*" - ], - "@@/*": [ - "src/.umi/*" - ], - "rc-upload": [ - "src/index.ts" - ] + "@/*": ["src/*"], + "@@/*": ["src/.umi/*"], + "@rc-component/upload": ["src/index.ts"] } }, - "include": [ - ".dumirc.ts", - "./src/**/*.ts", - "./src/**/*.tsx", - "./docs/**/*.tsx" - ] -} \ No newline at end of file + "include": [".dumirc.ts", "./src/**/*.ts", "./src/**/*.tsx", "./docs/**/*.tsx"] +}