feat: 增加浏览器中粘贴上传的功能,并增加相应的演示功能
🤔 这个变动的性质是?
- [x] 新特性提交
- [ ] 日常 bug 修复
- [ ] 站点、文档改进
- [x] 演示代码改进
- [ ] 组件样式/交互改进
- [ ] TypeScript 定义更新
- [ ] 包体积优化
- [ ] 性能优化
- [ ] 功能增强
- [ ] 国际化改进
- [ ] 重构
- [ ] 代码风格优化
- [ ] 测试用例
- [ ] 分支合并
- [ ] 其他改动(是关于什么的改动?)
🔗 相关 Issue
💡 需求背景和解决方案
个人非常喜欢这个组件库,并用在了自己的小程序端和h5上(因为是多端,所以使用的 taro 版本)。在浏览器中上传时,经常需要一个粘贴上传的功能,之前基于 2.7.7 的版本通过 patch-package 的方式已经在自己的站点上实现了,但是一旦升级就需要重新 patch,所以提个 PR,希望能够将此功能合并到上游,望采纳,不胜感激!
可能需要做一些代码修改,求大佬指点!
- 为 uploader 增加浏览器上的粘贴上传功能
- 用法:启用粘贴上传即可:
<Uploader enablePasteUpload /> - 演示: pnpm dev 演示 Web 版本:
https://github.com/user-attachments/assets/cccb47b7-7f54-45fa-ab74-4a085691076f
pnpm dev:taro:h5 演示 taro 版本的 h5 端:
https://github.com/user-attachments/assets/bd63bdc4-d799-43bd-b496-3aa644ab9e22
☑️ 请求合并前的自查清单
⚠️ 请自检并全部勾选全部选项。⚠️
- [x] 文档已补充或无须补充
- [x] 代码演示已提供或无须提供
- [x] TypeScript 定义已补充或无须补充
- [x] fork仓库代码是否为最新避免文件冲突
- [x] Files changed 没有 package.json lock 等无关文件
Summary by CodeRabbit
Summary by CodeRabbit
-
新功能
- 新增粘贴上传功能,允许用户通过粘贴方式直接上传图片文件。
- 引入了新的示例组件,通过多语言展示该功能的使用效果。
- 优化了图片处理,支持上传前预览,提升用户体验。
-
文档
- 更新了文档,详细介绍了粘贴上传功能的使用方法,并添加了相关翻译内容。
-
测试
- 新增粘贴上传功能的测试用例,确保该功能的稳定性和正确性。
Walkthrough
本次变更主要为 Uploader 组件新增粘贴上传功能及其相关演示、文档更新和内部文件处理优化。新增的测试用例验证了粘贴上传行为,Demo 展示中引入了新组件 Demo15 并增加对多语言翻译的支持,同时文档中添加了 enablePasteUpload 属性说明。内部上传逻辑也调整为更好地处理图片预览及文件读取流程。
Changes
| 文件路径 | 变更摘要 |
|---|---|
src/packages/uploader/__tests__/uploader.spec.tsx |
新增“should handle paste upload”测试用例,模拟粘贴事件并验证 onChange 被调用及文件属性传递正确。 |
src/packages/uploader/demo.tsxsrc/packages/uploader/demo.taro.tsxsrc/packages/uploader/demos/h5/demo15.tsxsrc/packages/uploader/demos/taro/demo15.tsx |
在 Demo 中引入新组件 Demo15,添加 enablePasteUpload 功能展示及中、英、繁体翻译支持。 |
src/packages/uploader/doc.md |
更新文档,新增粘贴上传功能说明及在 Props 表中添加 enablePasteUpload 属性(默认值 false)。 |
src/packages/uploader/uploader.taro.tsx |
修改上传逻辑:使用空值合并运算符确保 file 对象正确传递,并在预览图片时用 FileReader 异步读取文件数据。新增 enablePasteUpload 属性及粘贴事件监听。 |
src/packages/uploader/uploader.tsx |
为 Uploader 组件新增 enablePasteUpload 属性及默认值,增加 handlePaste 回调监听粘贴事件,实现粘贴上传功能。调整文件读取后文件列表更新逻辑。 |
Suggested reviewers
- xiaoyatong
- oasis-cloud
Poem
我是一只快乐的小兔,
在代码森林里跳跃不停;
粘贴上传添新趣,
文件随风迎面亲;
每行代码皆心语,
未来跃然展宏图!
🐰 CodeRabbit 加油!
[!TIP]
⚡💬 Agentic Chat (Pro Plan, General Availability)
- We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Generate unit testing code for this file. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and generate unit testing code. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
修改uploader.taro.tsx文件是为了解决什么问题
是应该修改 uploader.tsx 对吗🥹?我以为 uploader.taro.tsx 是源文件,会被适配到不同的端。
修改uploader.taro.tsx文件是为了解决什么问题
是应该修改 uploader.tsx 对吗🥹?我以为 uploader.taro.tsx 是源文件,会被适配到不同的端。
这个功能看起来主要是针对H5端的。.tsx对应的是nutui-react纯H5的源码。taro.tsx对应的是nutui-react-taro,需要验证新增功能是否在多端可行
修改uploader.taro.tsx文件是为了解决什么问题
是应该修改 uploader.tsx 对吗🥹?我以为 uploader.taro.tsx 是源文件,会被适配到不同的端。
这个功能看起来主要是针对H5端的。.tsx对应的是nutui-react纯H5的源码。taro.tsx对应的是nutui-react-taro,需要验证新增功能是否在多端可行
@Alex-huxiyang 感谢说明!
我看了一下似乎只有浏览器支持读取剪贴板中的图片。不过,我希望加到 .taro.tsx 中,因为我目前使用的 taro 版本的 nut-ui。我在文档中增加了说明,enablePasteUpload 仅在浏览器中生效。
增加了 taro 版本的 h5 粘贴上传示例,并附上了录屏演示。