feat:Add useClipboard
hook with clipboard management and tests
#2845
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 已提供或无须提供