feat:Add useClipboard hook with clipboard management and tests#2845
Open
Majmunu wants to merge 4 commits intoalibaba:masterfrom
Open
feat:Add useClipboard hook with clipboard management and tests#2845Majmunu wants to merge 4 commits intoalibaba:masterfrom
useClipboard hook with clipboard management and tests#2845Majmunu wants to merge 4 commits intoalibaba:masterfrom
Conversation
This commit introduces the `useClipboard` hook for managing clipboard data, including support for copying and pasting various types, error handling, and permission checks. Comprehensive documentation, demos, unit tests, and error management are included to ensure robustness and usability.
Co-authored-by: 遇见同学 <1875694521@qq.com>
useClipboard hook with clipboard management and testsuseClipboard hook with clipboard management and tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 这个变动的性质是?
useClipboard)💡 需求背景和解决方案
需求背景
displayText),同时在剪贴板中携带真实 JSON 数据。解决方案:新增 Hook
useClipboard现代浏览器(优先):用 ClipboardItem 同时写两种 MIME:
text/plain → displayText(用户粘贴到输入框只会看到这段文字)
text/html → JSON(程序读取用,普通粘贴一般看不见)
降级方案(不支持 text/html 时):只写 text/plain,把 JSON Base64 编码后贴在末尾并打上标记:
${displayText}\n__CLIPBOARD_DATA__:${btoa(json)}
📝 更新日志
useClipboard,支持结构化复制/粘贴并在不支持场景优雅降级;提供isSupported与hasPermission;补充完整 Vitest 测试。无破坏性变更。☑️ 请求合并前的自查清单
文档已补充或无须补充
代码演示已提供或无须提供
TypeScript 定义已补充或无须补充
Changelog 已提供或无须提供