New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 fix: dragging text mistakenly as image #2111
base: main
Are you sure you want to change the base?
Conversation
@sxjeru is attempting to deploy a commit to the LobeHub Team on Vercel. A member of the Team first needs to authorize it. |
👍 @sxjeru Thank you for raising your pull request and contributing to our Community |
CI 挂了,merge 下 main |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2111 +/- ##
=======================================
Coverage 92.88% 92.88%
=======================================
Files 302 302
Lines 17643 17643
Branches 1273 1273
=======================================
Hits 16388 16388
Misses 1255 1255 ☔ View full report in Codecov by Sentry. |
@sxjeru 录个 before 和 after 的视频做个示意吧? |
Hold on. |
展开视频before.mp4after.mp4虽然视频中用的是 file:///,但效果与网页图片一样。 另外往里拖本地文件或图片,依旧都会显示“上传图片”的 overlay 提示。 |
能做到其他网页拖入的图片,仍然和之前的展示一样不?我觉得为了文字部分能拖动而牺牲图片拖动的展示,感觉不太合适。 |
Can pictures dragged from other web pages still be displayed the same as before? I don’t think it’s appropriate to sacrifice the dragging of images for the sake of dragging text. |
这可能很难,因为 dragenter 时无法获取拖拽内容的 html,光靠 kind 与 type 不能区分 text 与 image。 兹认为一般逻辑也是图片拖动到文本框即上传。(例如 Github) |
This may be difficult because the html of the dragged content cannot be obtained during dragenter, and text and image cannot be distinguished by kind and type alone. |
已实现需求。 |
Requirements realized. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
有录屏吗?为啥我试了下好像不行呢 |
Is there any screen recording? Why doesn't it seem to work when I try it? |
刚刚用上面的 Preview 构建再试了一次(拖拽网页图片),是可以的。 当然拖拽 lobehub 自己页内的头像图片等是无效的,需要其他网页的图片。 |
I just tried it again using the Preview build above (drag and drop web images), and it works. |
@sxjeru 那我这个操作有问题么?试下来是无效的 Area.mp4 |
排查了一会,需要把浮于下方的 Vercel Bar 禁用才行。(Preview 构建特有,Vercel 自带) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外 e.dataTransfer?.items && e.dataTransfer.items.length > 0
这个判断能否抽成一个组件里的函数,并说明下含义?我对 drag 原生事件的了解不算深入,最好能加下注释说明下意图
e.preventDefault(); | ||
// reset counter | ||
dragCounter.current = 0; | ||
if (e.dataTransfer?.items && e.dataTransfer.items.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if 的风格,如果可以的话建议改成如果不匹配就 return 这种,而不是 if 里匹配再执行。
因为 if 里执行会导致括号层级加深一级,对查看代码上会有一定的语法干扰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if 嵌套处理了一下。 17f136a
本身的判断没有改,因为以后可能计划实现拖拽图片链接也能上传,从而支持 macOS 和 Firefox 。
这样目前的判断条件是可用的,当然还需思考这个条件是否可以忽略,因为似乎不存在拖拽了但 items 为空的情况。
该判断原本便存在,这边也没多想就保留了。 这边还是想再问一下,macOS chrome 能否成功嵌入拖拽的网页图片?(原始代码下,拖拽提示正常显示时) |
This judgment already exists, this Bian kept it without much thought. I still want to ask again, can macOS chrome successfully embed drag-and-drop web images? (Under the original code, when the drag prompt is displayed normally) |
这个我测了下好像的确是不行 另外 rebase 下 main 吧,昨天有个目录迁移的变更:#2295 |
I tested this and it seems that it does not work. |
既然目前确认只有拖拽内容中的 Files 被上传,应当把文字拖拽扩展到所有浏览器。 |
Since it is currently confirmed that only the Files in the dragged content are uploaded, text dragging should be extended to all browsers. |
src/app/(main)/chat/(desktop)/features/ChatInput/Footer/DragUpload.tsx
Outdated
Show resolved
Hide resolved
@sxjeru 麻烦 rebase 下,然后我再构建下最后看一眼 |
@sxjeru Please rebase, and then I will build it and take a final look. |
ok 了,之前的 preview 测试了 win 的 chrome 与 Firefox,行为达成预期,应该可以合并了。 |
OK, the previous preview tested Win's Chrome and Firefox, the behavior is as expected, and it should be possible to merge. |
删掉吧 |
Delete it |
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
原本使用
支持上传图片或文件的模型
时,不论拖入任何元素,还是拖动聊天时的文字,都会出现“上传图片”提示页,导致无法将拖拽的文字插入聊天框。本修改使得拖拽上传只对本地文件生效。
特别的,当拖拽网页图片时,不会出现“上传图片”提示页。但拖拽到文本框后松开,能正常附上图片。
📝 补充信息 | Additional Information
不知是否需要公开 vercel 部署供验证,本人已测试多种情况,应当无异常。