npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@little_monkey/dsh-image-actions

v1.2.0

Published

Right-click actions for conversation images: copy the picture, save it as a file, or reveal its local source file.

Readme

dsh-image-actions

DSH 客户端插件:右键会话里的任意图片,弹出「复制图片 / 另存为 / 在文件夹中显示」菜单。

为什么需要它

桌面端是 Electron,宿主自带的右键菜单只处理可编辑区域和选中文字(lib/main.js 的 context-menu 监听:isEditable 或 selectionText 非空才建菜单),图片既不可编辑也没有选中文本,所以右键没有任何菜单,也就没有浏览器里的「复制图片」。同时宿主只调用 clipboard.writeText,从不把位图写进剪贴板。

本插件在渲染层补上三个动作:

  • 复制图片:取图片字节(会话图片是 blob: URL)→ 必要时用 canvas 转成 PNG → navigator.clipboard.write([new ClipboardItem({ 'image/png': png })]),可直接粘贴进微信、Word、PPT、设计工具。
  • 另存为:取字节 → <a download> 触发保存;桌面端应用会话没有拦截 will-download,会弹系统「另存为」对话框。文件名优先用图片的 alt(read_image 的图通常是原文件名),否则用 image-YYYYMMDD-HHmmss.png。
  • 在文件夹中显示:把图片对应的本地原文件交给宿主的原生打开器——remote.session.openWorkspacePath({ path, action: 'reveal' }),由宿主校验路径映射后在资源管理器里定位该文件。

本地路径怎么找

在文件夹中显示 只在能确定原文件路径时出现,避免出现点了没反应的死菜单:

  1. 图片 URL 自带路径:dsh-app://app/api/file?path=…(文档预览 / 本地文件内嵌图)或 file: URL,直接解析。
  2. 向上的最近祖先里带路径的 title:read_image 行的路径元素把原始路径放在 title 上(本机装了 dsh-inline-image-read 时就在「读取图片 · 路径」那一行),插件从图片向上最多 8 层找第一个「以图片扩展名结尾的路径」。
  3. 行内文本:在向上 2–4 层内用绝对路径正则兜底(D:\…\foo.png、\\server\…)。
  4. 相对路径用当前会话的 cwd 拼成绝对路径(会话快照里 retainedBy.mainView > 0 的那一条)。

拿不到路径就不显示该项:用户上传/粘贴的图片只存在于 ~/.dsh/attachments(内容寻址、无扩展名,且与会话里显示的那张不是同一个 URL),MCP 等工具生成的图片同理。

使用

  1. 安装后无需刷新(HMR 会加载客户端半边);若页面仍是旧状态,刷新一次。
  2. 在会话里的图片上点右键(官方工具卡、read_image 行内图、用户附图、点开的大图灯箱都算)。
  3. 菜单出现在鼠标位置:
    • 复制图片 → 提示「图片已复制到剪贴板」。
    • 另存为 → 系统保存对话框。
    • 在文件夹中显示 → 资源管理器定位;宿主拒绝时提示「无法在文件夹中定位这个文件」。
  4. 点菜单外、Esc、滚动、窗口失焦、再次右键别处都会关闭菜单。

实现

  • 槽位:shell.overlay(root 级 list 槽,replaceRisk: none),只挂一个固定的空浮层,不替换任何官方 UI。
  • 触发:文档级 contextmenu 事件委托,只有命中「内容图片」时才 preventDefault();输入框、选中文字等其它区域的右键仍走宿主原生菜单,不受影响。
  • 命中过滤:img 且渲染尺寸 ≥ 40px、原始尺寸 ≥ 32px、src 协议为 blob: / data:image/ / dsh-app: / http(s): / file:,避免命中图标、头像、品牌标。
  • 菜单:position: fixed 定位到鼠标点,useLayoutEffect 里按实际尺寸做视口边缘回弹(8px 边距);支持 ↑ / ↓ / Home / End 移动焦点、Enter 触发、Esc 关闭并把焦点还给打开前的元素。
  • 能力探测:remote.session.canOpenWorkspacePath() 挂在插件 apply 里探测一次;返回 false 时整个「在文件夹中显示」项隐藏。
  • 样式:只用 --dsw-alias-* 主题 token(带兜底值),不 require 任何宿主组件包。
  • 文案:ctx.locale.register('imageActions', { zh, en }),随界面语言切换。
  • 转义:给任意图片加 data-dsh-image-actions-ignore 属性即可让本插件跳过它。

已知限制

  • 只对 img 元素生效:canvas、video、CSS background-image 不显示菜单。
  • 只有能解析出「本地原文件」的图片才有「在文件夹中显示」;用户附图与工具生成图没有可定位的源文件。
  • 宿主会按合成文件系统的映射校验路径,映射不到(例如路径已被删除、或不在 Host 可解析的范围内)会提示定位失败。
  • 跨域且未开 CORS 的图片取不到字节,复制会失败并提示改用「另存为」(<a download> 仍可用)。
  • GIF 复制后会变成静态 PNG(剪贴板只收 image/png)。
  • 这是自绘的 DOM 菜单,不是系统原生菜单:外观、阴影、键盘行为由本插件负责,和原生菜单不完全一致。
  • 宿主升级若改动 shell.overlay 槽位、ctx.locale 或 Session Remote 契约,本插件需要跟进。

安装 / 卸载

  • 安装:plugin_manager action=install_bundle target=<本目录绝对路径>
  • 卸载:plugin_manager action=remove_bundle target=@little_monkey/dsh-image-actions