dsh-linked-workspace 0.33.0 → 0.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/docs/API.md +4 -2
- package/docs/VERIFY.md +41 -0
- package/lib/client.js +282 -96
- package/lib/index.js +125 -7
- package/lib/office.js +118 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.34.1 — 2026-12-02
|
|
4
|
+
|
|
5
|
+
- **Word / Excel / PowerPoint 现在能直接看了**:文档面板不再把 .docx/.xlsx/.pptx 拆成段落、单元格、文字块来编辑,
|
|
6
|
+
而是交给 LibreOffice 转成 PDF、再按页渲染成图片 —— 版式、表格、配色、公式位置都保持原样,只读。
|
|
7
|
+
工具栏有 ‹ 页码 › 与「重新加载」;同一份文件第二次打开走缓存(首次约 8–11 秒,之后约 0.5 秒一页)。
|
|
8
|
+
- **网页(HTML)可以编辑了**:HTML 标签页多了「编辑 / 预览」切换,编辑用的是源码文本框,`Ctrl/⌘+S` 保存,
|
|
9
|
+
预览仍在 `sandbox="allow-scripts"` 的 iframe 里跑,不碰 DSH 界面。保存走 `fs.write` / `local.write`,
|
|
10
|
+
带 `expectedMtime` 冲突检查。
|
|
11
|
+
- **依赖说明**:Office 预览需要本机有 LibreOffice(`soffice`);没有时该标签页会明确说明「这台机器上没有
|
|
12
|
+
LibreOffice」,不再默默显示文字视图。可用 `DSH_LINKED_WORKSPACE_SOFFICE` 指定路径。
|
|
13
|
+
- **Host**:新增 `docs.officePage { path, page }`(转换 + 分页渲染,按内容哈希缓存 PDF),`apiRevision` 16 → 17。
|
|
14
|
+
|
|
15
|
+
- **Markdown 编辑模式也能批量替换了**:在文档面板点「编辑」后按 `Ctrl/⌘+F`,查找条里多了替换框、「替换」
|
|
16
|
+
与「全部替换」。匹配规则与查找一致(不区分大小写的纯文本,不支持正则);「替换」只改当前命中并保持光标位置,
|
|
17
|
+
「全部替换」从后往前改,避免偏移互相影响。改完仍是原来的保存路径(`Ctrl/⌘+S` 或「保存」)。
|
|
18
|
+
|
|
19
|
+
## 0.34.0 — 2026-12-01
|
|
20
|
+
|
|
21
|
+
- **工作区外下载不会再点出两份**:下载期间按钮变成「下载中…」并禁用,结束后恢复;下载完成的页脚多一个
|
|
22
|
+
「打开所在文件夹」,直接定位到刚保存的文件(Host 新增 `local.reveal`,Windows 用 `explorer /select,`)。
|
|
23
|
+
- **工作区外图片的内联预览上限收到 8 MB**:超过就提示下载,而不是把 24 MB 的 base64 塞进内存;图片数据解不开时
|
|
24
|
+
面板给出「图片数据无法解码,请下载后查看。」,不再是一片空白。
|
|
25
|
+
- **「只在当前目录搜」对额外根目录也成立**:`fs.grep` 的 `includeOutside` 现在把同一个相对目录套到每个额外根,
|
|
26
|
+
某个根没有这个目录就跳过(不再让整次搜索失败);结果回报扫过几个根、丢了几个(超出 5 个上限时面板会说明)。
|
|
27
|
+
- **槽位满的提示不再只在目录面板里**:面板没打开时(例如直接在会话里点链接)改由框架级 toast 说明
|
|
28
|
+
「文件标签位已满(24 个)」。
|
|
29
|
+
- **目录栏头部折叠按钮有了 `aria-label`**,读屏能念出它。
|
|
30
|
+
- **Host**:新增 `local.reveal { path }`;`media.readOutside` 的内联上限改为 8 MB;`fs.grep` 新增
|
|
31
|
+
`outsideRoots`/`outsideDropped`/`outsideSkipped` 三个回报字段。
|
|
32
|
+
|
|
3
33
|
## 0.33.0 — 2026-11-30
|
|
4
34
|
|
|
5
35
|
- **工作区外的文件终于能拿出来、图片也能看了**:只读标签的工具栏多了「下载到默认文件夹」(落到
|
package/docs/API.md
CHANGED
|
@@ -26,6 +26,7 @@ Codes: `BAD_REQUEST`, `NOT_FOUND`, `SSH_CONNECT`, `AUTH_FAILED`,
|
|
|
26
26
|
| `docs.create` | `{ path, kind?, linkedId?, remoteId? }` | `{ kind, path, size, mtime }` |
|
|
27
27
|
| `docs.mdPreview` | `{ path, text?, linkedId?, remoteId? }` | `{ kind: 'markdown-preview', html }` (rendered in-process; the fragment carries the KaTeX stylesheet and expects the plugin's `/dsh-linked-workspace/assets/katex/` fonts; the last 3 renders are cached by content hash) or `{ kind: 'markdown-preview-too-large', chars \| bytes, limit }` for a document above 512 Ki characters — the viewer must show the editor instead |
|
|
28
28
|
| `docs.mdPdf` | `{ path, text?, linkedId?, remoteId? }` | `{ kind: "pdf", path, size, mtime }` |
|
|
29
|
+
| `docs.officePage` | `{ path, linkedId?/remoteId?, page }` | `{ kind, engine, pageCount, pages[{ index, png }] }` (docx/xlsx/pptx only: converts to PDF with LibreOffice, caches the PDF per content hash, renders the page as a PNG) |
|
|
29
30
|
|
|
30
31
|
## Records
|
|
31
32
|
|
|
@@ -78,7 +79,7 @@ scope root, or absolute inside it.
|
|
|
78
79
|
| `fs.list` | `{ linkedId?/remoteId?, path, limit?, offset? }` | `{ path, entries: RemoteEntry[], total, offset, limit, hasMore }` (default 500, max 5000). Listings are cached for 5 s for `offset > 0`; writes, mkdir, rename, move, delete, copy and transfers invalidate the cache. |
|
|
79
80
|
| `fs.read` | `{ linkedId?/remoteId?, path, maxBytes? }` | `FileRead` |
|
|
80
81
|
| `media.read` | `{ linkedId?/remoteId?, path }` | `{ path, size, mtime, mime, base64 }` (PNG/JPG/GIF/WebP/BMP/ICO/AVIF/SVG, max 24 MB) |
|
|
81
|
-
| `media.readOutside` | `{ linkedId?/remoteId?, path }` | `{ path, size, mtime, mime, base64 }` (same types
|
|
82
|
+
| `media.readOutside` | `{ linkedId?/remoteId?, path }` | `{ path, size, mtime, mime, base64 }` (same types as `media.read`, inline only up to 8 MB; past that it answers `FS_TOO_LARGE` and the viewer offers the download) |
|
|
82
83
|
| `fs.write` | `{ linkedId?/remoteId?, path, content, expectedMtime?, createOnly? }` | `{ path, size, mtime }` (`createOnly: true`: existing target → 409) |
|
|
83
84
|
| `fs.stat` | `{ linkedId?/remoteId?, path }` | `{ path, relative, type, size, mtime, mode }` |
|
|
84
85
|
| `fs.mkdir` | `{ linkedId?/remoteId?, path, createOnly? }` | `{}` (`createOnly: true`: existing target → 409) |
|
|
@@ -101,6 +102,7 @@ scope root, or absolute inside it.
|
|
|
101
102
|
| `local.list` | `{ path, limit?, offset? }` | `{ path, entries: [{ name, path, type, size, mtime }], total, offset, limit, hasMore }` |
|
|
102
103
|
| `local.openExternal` | `{ path }` | `{ opened, path }` |
|
|
103
104
|
| `local.openUrl` | `{ url }` | `{ opened, url }` (only `http:`, `https:`, `mailto:` and `tel:`; the preview hands external links here instead of navigating — anything else is `BAD_REQUEST`) |
|
|
105
|
+
| `local.reveal` | `{ path }` | `{ opened, folder }` (absolute local path; opens the file manager with the file selected, or the folder itself) |
|
|
104
106
|
| `terminal.open` | `{ linkedId?/remoteId?, side: 'remote'\|'local', path? }` | `{ opened, side, path, host? }` (`path` must stay inside the workspace; remote workspaces only support `side: 'remote'`) |
|
|
105
107
|
| `fs.openExternal` | `{ linkedId?/remoteId?, path }` | `{ opened, localPath, size }` |
|
|
106
108
|
| `localWorkspace.create` | `{ path, name? }` | `{ workspaceId, title, path }` |
|
|
@@ -109,7 +111,7 @@ scope root, or absolute inside it.
|
|
|
109
111
|
| `skills.read` | `{ linkedId, name }` | `{ name, description, content, path }` |
|
|
110
112
|
| `git.status` | `{ linkedId?/remoteId?, side: 'remote'|'local' }` | `{ ok, repo, root, branch, changes, error? }` (remote workspaces only support `side: 'remote'`) |
|
|
111
113
|
| `fs.search` | `{ linkedId?/remoteId?, side, query, maxResults? }` | `{ ok, query, entries, truncated }` (matches **file names**, not contents; use `fs.grep` for contents) |
|
|
112
|
-
| `fs.grep` | `{ linkedId?/remoteId?, side, query, maxResults?, path?, ignoreCase?, regex?, includeIgnored?, resultMode?, includeOutside?, maxFiles?, maxFileBytes?, timeoutMs?, jobId? }` | `{ ok, query, entries: [{ path, relative, size, line, preview, matches }], truncated, truncatedReason, scannedFiles, scannedBytes, skippedFiles }` (searches file **contents**; `path` narrows the scan to a sub-folder; `ignoreCase` defaults to `true`; `regex` treats `query` as a regular expression; `includeIgnored: true` also walks usually ignored folders such as `node_modules`/`.venv`/`dist` (`.git`/`.hg`/`.svn` always stay out); `resultMode: 'files'` lists file names only (`line: 0`, empty `preview`, `matches` = hit count); `maxFiles` (default 2000), `maxFileBytes` (default 1 MB) and `timeoutMs` (default 5 s, max 10 s) raise or lower the sweep; limits are 1 MB per file, 2000 files, 8 MB and 5 s for both sides, and `truncatedReason` is one of `files`, `bytes`, `deadline`, `results`, `cancelled`; max 1000 rows; `includeOutside: true` also sweeps the extra roots and marks those hits with `outsideRoot`) |
|
|
114
|
+
| `fs.grep` | `{ linkedId?/remoteId?, side, query, maxResults?, path?, ignoreCase?, regex?, includeIgnored?, resultMode?, includeOutside?, maxFiles?, maxFileBytes?, timeoutMs?, jobId? }` | `{ ok, query, entries: [{ path, relative, size, line, preview, matches }], truncated, truncatedReason, scannedFiles, scannedBytes, skippedFiles }` (searches file **contents**; `path` narrows the scan to a sub-folder; `ignoreCase` defaults to `true`; `regex` treats `query` as a regular expression; `includeIgnored: true` also walks usually ignored folders such as `node_modules`/`.venv`/`dist` (`.git`/`.hg`/`.svn` always stay out); `resultMode: 'files'` lists file names only (`line: 0`, empty `preview`, `matches` = hit count); `maxFiles` (default 2000), `maxFileBytes` (default 1 MB) and `timeoutMs` (default 5 s, max 10 s) raise or lower the sweep; limits are 1 MB per file, 2000 files, 8 MB and 5 s for both sides, and `truncatedReason` is one of `files`, `bytes`, `deadline`, `results`, `cancelled`; max 1000 rows; `includeOutside: true` also sweeps the extra roots and marks those hits with `outsideRoot`, and the answer carries `outsideRoots` / `outsideDropped` / `outsideSkipped`) |
|
|
113
115
|
| `fs.grepCancel` | `{ jobId }` | `{ cancelled }` (marks the job started by `fs.grep`'s `jobId`; the Host checks it between files and answers `truncatedReason: 'cancelled'`) |
|
|
114
116
|
| `linked.plan` | `{ id, maxFiles? }` | `{ linkedId, localPath, remotePath, added, changed, conflict, removed, unchanged, pending, truncated, skipped, maxFiles }` (each entry carries `relative`, `size`, `localHash`, `remoteHash`; a file that moved on both sides since the last push lands in `conflict`) |
|
|
115
117
|
| `linked.push` | `{ id, paths?, dryRun?, conflict?, jobId? }` | `{ linkedId, dryRun, conflict, files, pushed, skipped, conflictsLeft, bytes, cancelled }` (`conflict` is `skip` by default; every file is written as a temporary file and renamed into place; `paths` entries may be files or folders — a folder matches everything under it — and every planned entry carries `localMtime` / `remoteMtime`) |
|
package/docs/VERIFY.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Manual verification checklist
|
|
2
2
|
|
|
3
|
+
## Office 渲染预览与 HTML 编辑(未发布)
|
|
4
|
+
|
|
5
|
+
1. **准备**:本机需装 LibreOffice(`C:\Program Files\LibreOffice\program\soffice.exe`)。没有时打开 Office 文件应显示
|
|
6
|
+
「这台机器上没有 LibreOffice,无法渲染 Office 文档」,而不是空白或文字视图。
|
|
7
|
+
2. 在目录栏打开一个 `.pptx`(3 页、含标题/项目符号/表格):应直接看到**渲染后的第 1 页**,标题居中、表格带表头底色;
|
|
8
|
+
工具栏右侧有 `‹ 1 / 3 ›` 与「重新加载」,**没有**「保存」按钮。
|
|
9
|
+
3. 点 `›` 翻到第 2、3 页:每页约 0.5 秒(已转换过),版式与 PowerPoint 里一致。
|
|
10
|
+
4. 打开一个 `.docx`:标题、正文、列表、表格都应正确渲染;打开 `.xlsx`:两个 sheet 各一页、列宽与换行正确。
|
|
11
|
+
5. 关掉再打开同一个文件:不走重新转换(< 1 秒出图)。
|
|
12
|
+
6. 打开一个 `.html`:默认预览(iframe),点「编辑」切到源码文本框,改一行后 `Ctrl/⌘+S`(或点「保存」),
|
|
13
|
+
状态栏「未保存」消失、出现「已保存」;再点「预览」应看到改动。
|
|
14
|
+
7. 让 `.html` 在别处被改动后再保存:应报冲突并要求重新加载(`expectedMtime` 生效)。
|
|
15
|
+
8. Markdown 行为不变:默认预览、可切编辑、`Ctrl/⌘+F` 有查找与替换。
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Markdown 编辑模式的替换(未发布)
|
|
19
|
+
|
|
20
|
+
1. 在目录栏打开一个 `.md`,点工具栏「编辑」进入编辑模式,按 `Ctrl/⌘+F`:查找条里应有第二个输入框(替换)
|
|
21
|
+
和「替换」「全部替换」两个按钮。
|
|
22
|
+
2. 查找框输入 `alpha`:计数器显示命中数(不区分大小写,`ALPHA` 也算)。
|
|
23
|
+
3. 替换框输入 `OMEGA`,点「全部替换」:正文里所有命中都变成 `OMEGA`,计数器变「无匹配」。
|
|
24
|
+
4. 再查 `gamma`、替换为 `delta`,点「替换」(或在替换框按 Enter):只改当前这一处,光标落在 `delta` 之后。
|
|
25
|
+
5. `Ctrl/⌘+S` 或点「保存」:重新打开该文件确认改动已写回远端。
|
|
26
|
+
6. 预览模式下按 `Ctrl/⌘+F` 不应弹出查找条(替换只在编辑模式可用)。
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## 工作区外:下载、图片与额外根目录搜索(未发布)
|
|
30
|
+
|
|
31
|
+
1. 额外根目录里放一个 3 MB 以上的 `big.txt`,点击它的聊天链接,然后连点两次「下载到默认文件夹」:
|
|
32
|
+
按钮立刻变「下载中…」并禁用,`~/Downloads` 里**只出现一份**文件。
|
|
33
|
+
2. 下载完成后页脚出现「打开所在文件夹」,点它应当用资源管理器定位到该文件。
|
|
34
|
+
3. 额外根目录里放一张 **9 MB** 的 PNG:面板显示「图片超过 8 MB,无法内联预览,请下载后查看」,同排有下载按钮。
|
|
35
|
+
4. 放一张 1 MB 的 PNG:正常内联预览;把文件内容改成非图片字节(保留 .png 后缀)后重开,应显示
|
|
36
|
+
「图片数据无法解码,请下载后查看。」而不是空白。
|
|
37
|
+
5. 额外根目录 A 下有 `sub/x.txt`,B 下没有 `sub/`:打开「+/」并在搜索栏限定到 `sub`,结果只来自 A,
|
|
38
|
+
且不报错;若配置了 6 个额外根目录,结果区多一行「还有 N 个额外根目录没有扫(上限 5 个)」。
|
|
39
|
+
6. 关掉目录面板,在会话里连续点开 25 个不同的聊天文件链接:第 25 个应在页面底部弹出
|
|
40
|
+
「文件标签位已满(24 个)。先关掉一个再点。」(框架级 toast,5 秒后消失)。
|
|
41
|
+
7. 目录栏头部的折叠按钮:读屏应念出「开启/关闭联动工作区目录面板」。
|
|
42
|
+
|
|
43
|
+
|
|
3
44
|
## 工作区外的下载、图片与搜索(未发布)
|
|
4
45
|
|
|
5
46
|
1. 联动工作区根目录在 `/shared_data_ssd1/huangjh`,额外根目录里放 `/shared_data_hdd1/huangjh/x/pic.png`(≥ 1 像素真图)
|
package/lib/client.js
CHANGED
|
@@ -2837,6 +2837,7 @@ function isInsideRoot(root, target) {
|
|
|
2837
2837
|
docPdfAuthor: '作者',
|
|
2838
2838
|
docPageOf: '第 {page} / {total} 页',
|
|
2839
2839
|
docExportDone: '已导出 PDF:{path}',
|
|
2840
|
+
docRenderEmpty: '这一页没有渲染出内容,点「重新加载」再试一次。',
|
|
2840
2841
|
docPreviewFailed: '预览失败',
|
|
2841
2842
|
previewTooLarge: '这个文件太大({{chars}} 字符,上限 {{limit}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
|
|
2842
2843
|
previewTooLargeBytes: '这个文件太大({{bytes}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
|
|
@@ -2852,6 +2853,10 @@ function isInsideRoot(root, target) {
|
|
|
2852
2853
|
outsideMtime: '修改于 {{when}}',
|
|
2853
2854
|
outsideCeiling: '已达到 {{size}} 的读取上限,剩下的内容请下载后查看。',
|
|
2854
2855
|
outsideDownload: '下载到默认文件夹',
|
|
2856
|
+
outsideDownloading: '下载中…',
|
|
2857
|
+
outsideReveal: '打开所在文件夹',
|
|
2858
|
+
imageBroken: '图片数据无法解码,请下载后查看。',
|
|
2859
|
+
searchOutsideDropped: '还有 {{count}} 个额外根目录没有扫(上限 5 个)。',
|
|
2855
2860
|
outsideDownloaded: '已下载到 {{path}}',
|
|
2856
2861
|
tabsFull: '文件标签位已满({{count}} 个)。先关掉一个再点。',
|
|
2857
2862
|
linkOutside: '这个链接指向工作区之外,没有打开:{{path}}',
|
|
@@ -3457,6 +3462,7 @@ function isInsideRoot(root, target) {
|
|
|
3457
3462
|
docPdfAuthor: 'Author',
|
|
3458
3463
|
docPageOf: 'Page {page} / {total}',
|
|
3459
3464
|
docExportDone: 'Exported PDF: {path}',
|
|
3465
|
+
docRenderEmpty: 'This page rendered empty; try reloading it.',
|
|
3460
3466
|
docPreviewFailed: 'Preview failed',
|
|
3461
3467
|
previewTooLarge: 'Too large to preview ({{chars}} characters, the ceiling is {{limit}}). Read it in the editor, or download it and open it elsewhere.',
|
|
3462
3468
|
previewTooLargeBytes: 'Too large to preview ({{bytes}}). Read it in the editor, or download it and open it elsewhere.',
|
|
@@ -3472,6 +3478,10 @@ function isInsideRoot(root, target) {
|
|
|
3472
3478
|
outsideMtime: 'Modified {{when}}',
|
|
3473
3479
|
outsideCeiling: 'Reached the {{size}} reading ceiling; download the file for the rest.',
|
|
3474
3480
|
outsideDownload: 'Download to the default folder',
|
|
3481
|
+
outsideDownloading: 'Downloading…',
|
|
3482
|
+
outsideReveal: 'Open the folder',
|
|
3483
|
+
imageBroken: 'The image data could not be decoded; download it instead.',
|
|
3484
|
+
searchOutsideDropped: '{{count}} more extra roots were left out (the sweep stops at 5).',
|
|
3475
3485
|
outsideDownloaded: 'Saved to {{path}}',
|
|
3476
3486
|
tabsFull: 'Every file tab is in use ({{count}}). Close one and try again.',
|
|
3477
3487
|
linkOutside: 'That link points outside the workspace, so it was left alone: {{path}}',
|
|
@@ -3860,7 +3870,7 @@ function isInsideRoot(root, target) {
|
|
|
3860
3870
|
* Host methods the running DSH process does not have yet, the directory
|
|
3861
3871
|
* pane says so instead of surfacing an unrelated error.
|
|
3862
3872
|
*/
|
|
3863
|
-
var HOST_API_REVISION =
|
|
3873
|
+
var HOST_API_REVISION = 17;
|
|
3864
3874
|
var hostInfoProbe = null;
|
|
3865
3875
|
|
|
3866
3876
|
function probeHostInfo() {
|
|
@@ -4461,6 +4471,7 @@ function isInsideRoot(root, target) {
|
|
|
4461
4471
|
'.rw-doc-body{display:flex;flex-direction:column;flex:1 1 auto;min-height:0;overflow:auto;padding:10px}',
|
|
4462
4472
|
'.rw-outside-actions{display:flex;flex-direction:column;gap:8px;padding:4px 0}',
|
|
4463
4473
|
'.rw-outside-footer{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:8px 0 2px;border-top:1px solid var(--dsw-alias-border-l1);margin-top:8px;flex:none}',
|
|
4474
|
+
'.rw-toast{position:fixed;left:50%;bottom:24px;transform:translateX(-50%);z-index:70;max-width:70vw;padding:8px 14px;border-radius:8px;background:var(--dsw-alias-bg-layer-3,#2c2c2e);color:var(--dsw-alias-label-primary);box-shadow:0 8px 24px rgba(0,0,0,.28);font-size:12px;line-height:18px}',
|
|
4464
4475
|
'.rw-outside-image{display:block;max-width:100%;max-height:100%;margin:0 auto;object-fit:contain}',
|
|
4465
4476
|
'.rw-outside-text{margin:0;font-family:var(--dsw-alias-font-mono,ui-monospace,SFMono-Regular,Menlo,monospace);font-size:12px;line-height:1.5;white-space:pre-wrap;word-break:break-word;flex:1 1 auto;min-height:0}',
|
|
4466
4477
|
'.rw-doc-textarea{width:100%;min-height:260px;flex:1 1 auto;resize:none;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:10px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:12.5px/18px ui-monospace,"Cascadia Code",Consolas,monospace;outline:none;box-sizing:border-box}',
|
|
@@ -4471,6 +4482,8 @@ function isInsideRoot(root, target) {
|
|
|
4471
4482
|
'.rw-doc-preview th,.rw-doc-preview td{border:1px solid var(--dsw-alias-border-l2);padding:5px 8px}',
|
|
4472
4483
|
'.rw-doc-preview img{max-width:100%}',
|
|
4473
4484
|
'.rw-doc-preview blockquote{border-left:3px solid var(--dsw-alias-border-l2);margin:0;padding-left:10px;color:var(--dsw-alias-label-secondary)}',
|
|
4485
|
+
'.rw-html-source{flex:1 1 auto;min-height:0;resize:none;border:0;border-radius:0;font-family:var(--dsw-alias-font-mono,ui-monospace,SFMono-Regular,Menlo,monospace);font-size:12px;line-height:1.55}',
|
|
4486
|
+
'.rw-doc-page{display:block;margin:0 auto;max-width:100%;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.18);border-radius:2px}',
|
|
4474
4487
|
'.rw-doc-pdf-page{display:block;max-width:100%;margin:0 auto 10px;border:1px solid var(--dsw-alias-border-l2);box-shadow:0 2px 10px rgba(0,0,0,.08);background:#fff}',
|
|
4475
4488
|
'.rw-doc-field{display:flex;align-items:center;gap:8px;margin:6px 0}',
|
|
4476
4489
|
'.rw-doc-field label{font-size:11.5px;color:var(--dsw-alias-label-tertiary);min-width:38px}',
|
|
@@ -5913,39 +5926,62 @@ function isInsideRoot(root, target) {
|
|
|
5913
5926
|
var scope = props.scope;
|
|
5914
5927
|
var local = props.local === true;
|
|
5915
5928
|
var filePath = props.path;
|
|
5916
|
-
var state = useState({ loading: true, error: null, data: null });
|
|
5929
|
+
var state = useState({ loading: true, error: null, data: null, editing: false, draft: '', saving: false, notice: '', dirty: false });
|
|
5917
5930
|
var view = state[0];
|
|
5918
5931
|
var setView = state[1];
|
|
5919
5932
|
var params = scopeParams(scope);
|
|
5920
5933
|
|
|
5934
|
+
function patch(next) { setView(function (previous) { return Object.assign({}, previous, next); }); }
|
|
5935
|
+
|
|
5921
5936
|
var load = useCallback(function () {
|
|
5922
5937
|
if (!filePath || (!local && !scope)) {
|
|
5923
|
-
setView({ loading: false, error: new Error(t('noWorkspace')), data: null });
|
|
5938
|
+
setView({ loading: false, error: new Error(t('noWorkspace')), data: null, editing: false, draft: '', saving: false, notice: '', dirty: false });
|
|
5924
5939
|
return;
|
|
5925
5940
|
}
|
|
5926
|
-
setView({ loading: true, error: null
|
|
5941
|
+
setView(function (previous) { return Object.assign({}, previous, { loading: true, error: null }); });
|
|
5927
5942
|
var request = local ? { path: filePath, preview: true } : Object.assign({ path: filePath, preview: true }, params);
|
|
5928
5943
|
apiCall(local ? 'local.read' : 'fs.read', request).then(function (result) {
|
|
5929
5944
|
if (result.tooLarge || result.truncated) {
|
|
5930
5945
|
setView({
|
|
5931
5946
|
loading: false,
|
|
5932
5947
|
error: new Error(t('htmlPreviewTooLarge', { size: formatBytes(result.size), limit: formatBytes(PREVIEW_MAX_BYTES) })),
|
|
5933
|
-
data: null,
|
|
5948
|
+
data: null, editing: false, draft: '', saving: false, notice: '', dirty: false,
|
|
5934
5949
|
});
|
|
5935
5950
|
return;
|
|
5936
5951
|
}
|
|
5937
5952
|
if (result.binary) {
|
|
5938
|
-
setView({ loading: false, error: new Error(t('htmlPreviewBinary')), data: null });
|
|
5953
|
+
setView({ loading: false, error: new Error(t('htmlPreviewBinary')), data: null, editing: false, draft: '', saving: false, notice: '', dirty: false });
|
|
5939
5954
|
return;
|
|
5940
5955
|
}
|
|
5941
|
-
setView({
|
|
5956
|
+
setView({
|
|
5957
|
+
loading: false, error: null, data: result,
|
|
5958
|
+
draft: typeof result.content === 'string' ? result.content : '',
|
|
5959
|
+
editing: false, saving: false, notice: '', dirty: false,
|
|
5960
|
+
});
|
|
5942
5961
|
}).catch(function (error) {
|
|
5943
|
-
setView({ loading: false, error: error, data: null });
|
|
5962
|
+
setView({ loading: false, error: error, data: null, editing: false, draft: '', saving: false, notice: '', dirty: false });
|
|
5944
5963
|
});
|
|
5945
5964
|
}, [scopeKeyOf(scope), filePath, local]);
|
|
5946
5965
|
|
|
5947
5966
|
useEffect(function () { load(); }, [load]);
|
|
5948
5967
|
|
|
5968
|
+
function save() {
|
|
5969
|
+
if (view.saving || !view.dirty) return;
|
|
5970
|
+
patch({ saving: true, error: null, notice: '' });
|
|
5971
|
+
var request = local
|
|
5972
|
+
? { path: filePath, content: view.draft, expectedMtime: view.data ? view.data.mtime : undefined }
|
|
5973
|
+
: Object.assign({ path: filePath, content: view.draft, expectedMtime: view.data ? view.data.mtime : undefined }, params);
|
|
5974
|
+
apiCall(local ? 'local.write' : 'fs.write', request).then(function (result) {
|
|
5975
|
+
patch({
|
|
5976
|
+
saving: false, dirty: false, notice: t('saved'),
|
|
5977
|
+
data: Object.assign({}, view.data, { content: view.draft, size: result.size, mtime: result.mtime }),
|
|
5978
|
+
});
|
|
5979
|
+
if (typeof props.onSaved === 'function') props.onSaved();
|
|
5980
|
+
}).catch(function (error) {
|
|
5981
|
+
patch({ saving: false, error: error });
|
|
5982
|
+
});
|
|
5983
|
+
}
|
|
5984
|
+
|
|
5949
5985
|
var name = basename(filePath) || t('fileTabTitle');
|
|
5950
5986
|
var header = h('div', { className: 'rw-image-head' },
|
|
5951
5987
|
h(FileGlyph, { name: name, size: 15 }),
|
|
@@ -5953,35 +5989,61 @@ function isInsideRoot(root, target) {
|
|
|
5953
5989
|
h('span', { className: 'rw-editor-name', title: name }, name),
|
|
5954
5990
|
h('span', { className: 'rw-editor-path', title: filePath }, filePath)),
|
|
5955
5991
|
h('div', { className: 'rw-actions' },
|
|
5992
|
+
h('button', {
|
|
5993
|
+
type: 'button',
|
|
5994
|
+
className: 'rw-btn rw-btn-sm',
|
|
5995
|
+
onClick: function () { patch({ editing: !view.editing, notice: '' }); },
|
|
5996
|
+
disabled: view.loading,
|
|
5997
|
+
}, view.editing ? t('docPreview') : t('docEdit')),
|
|
5998
|
+
view.editing
|
|
5999
|
+
? h('button', { type: 'button', className: 'rw-btn rw-btn-sm rw-btn-primary', onClick: save, disabled: view.saving || !view.dirty }, view.saving ? Spinner(12) : IconSave(12), view.saving ? t('saving') : t('save'))
|
|
6000
|
+
: null,
|
|
5956
6001
|
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: load, disabled: view.loading }, IconRefresh(12), t('reload'))));
|
|
5957
6002
|
|
|
5958
6003
|
if (view.loading) {
|
|
5959
6004
|
return h('div', { className: 'rw-html-preview' }, header,
|
|
5960
6005
|
h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')));
|
|
5961
6006
|
}
|
|
5962
|
-
if (view.error) {
|
|
6007
|
+
if (view.error && !view.data) {
|
|
5963
6008
|
return h('div', { className: 'rw-html-preview' }, header,
|
|
5964
6009
|
h('div', { className: 'rw-editor-message' },
|
|
5965
6010
|
h(Banner, { kind: 'error' }, t('htmlLoadError') + ':' + messageOf(view.error, t, locale)),
|
|
5966
6011
|
h('button', { type: 'button', className: 'rw-btn', onClick: load }, IconRefresh(13), t('retry'))));
|
|
5967
6012
|
}
|
|
5968
|
-
var data = view.data;
|
|
6013
|
+
var data = view.data || {};
|
|
6014
|
+
var stage = view.editing
|
|
6015
|
+
? h('textarea', {
|
|
6016
|
+
className: 'rw-doc-textarea rw-html-source',
|
|
6017
|
+
value: view.draft,
|
|
6018
|
+
spellCheck: false,
|
|
6019
|
+
onChange: function (event) { patch({ draft: event.currentTarget.value, dirty: true, notice: '' }); },
|
|
6020
|
+
onKeyDown: function (event) {
|
|
6021
|
+
if ((event.ctrlKey || event.metaKey) && (event.key === 's' || event.key === 'S')) {
|
|
6022
|
+
event.preventDefault();
|
|
6023
|
+
save();
|
|
6024
|
+
}
|
|
6025
|
+
},
|
|
6026
|
+
})
|
|
6027
|
+
: h('iframe', {
|
|
6028
|
+
className: 'rw-html-frame',
|
|
6029
|
+
title: name,
|
|
6030
|
+
// allow-scripts runs the page's own JS (charts need it) inside an
|
|
6031
|
+
// opaque origin: no access to the DSH UI, its storage or the tree.
|
|
6032
|
+
sandbox: 'allow-scripts',
|
|
6033
|
+
srcDoc: typeof view.draft === 'string' ? view.draft : (data.content || ''),
|
|
6034
|
+
});
|
|
6035
|
+
|
|
5969
6036
|
return h('div', { className: 'rw-html-preview' },
|
|
5970
6037
|
header,
|
|
5971
|
-
h('div', {
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
title: name,
|
|
5975
|
-
// allow-scripts runs the page's own JS (charts need it) inside an
|
|
5976
|
-
// opaque origin: no access to the DSH UI, its storage or the tree.
|
|
5977
|
-
sandbox: 'allow-scripts',
|
|
5978
|
-
srcDoc: data.content || '',
|
|
5979
|
-
})),
|
|
6038
|
+
view.notice ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'success' }, view.notice)) : null,
|
|
6039
|
+
view.error && view.data ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'error' }, messageOf(view.error, t, locale))) : null,
|
|
6040
|
+
h('div', { className: 'rw-html-stage' }, stage),
|
|
5980
6041
|
h('div', { className: 'rw-editor-status' },
|
|
5981
6042
|
h('span', { className: 'rw-status-chip' }, 'HTML'),
|
|
5982
|
-
h('span', { className: 'rw-status-chip' }, formatBytes(
|
|
6043
|
+
h('span', { className: 'rw-status-chip' }, formatBytes(Buffer.byteLength(view.draft || '', 'utf8'))),
|
|
6044
|
+
view.dirty ? h('span', { className: 'rw-status-chip rw-status-warn' }, t('dirty')) : null,
|
|
5983
6045
|
h('span', { className: 'rw-fill', style: { flex: '1 1 auto' } }),
|
|
5984
|
-
h('span', { className: 'rw-status-chip' }, t('htmlSandboxed'))));
|
|
6046
|
+
h('span', { className: 'rw-status-chip' }, view.editing ? t('docEdit') : t('htmlSandboxed'))));
|
|
5985
6047
|
}
|
|
5986
6048
|
|
|
5987
6049
|
// ── editor ─────────────────────────────────────────────────────────────
|
|
@@ -7092,6 +7154,9 @@ function isInsideRoot(root, target) {
|
|
|
7092
7154
|
state.loading ? h('div', { className: 'rw-hint-row' }, Spinner(12), t('loading')) : null,
|
|
7093
7155
|
!state.loading && total === 0 ? h('div', { className: 'rw-hint-row' }, t('searchEmpty')) : null,
|
|
7094
7156
|
!state.loading && state.truncated ? h('div', { className: 'rw-hint-row' }, t(reasonKey)) : null,
|
|
7157
|
+
!state.loading && Number(state.outsideDropped) > 0
|
|
7158
|
+
? h('div', { className: 'rw-hint-row' }, t('searchOutsideDropped', { count: String(state.outsideDropped) }))
|
|
7159
|
+
: null,
|
|
7095
7160
|
groups.map(function (group) {
|
|
7096
7161
|
if (group.entries.length === 0) return null;
|
|
7097
7162
|
return h('div', { key: group.side, className: 'rw-change-group' },
|
|
@@ -7301,6 +7366,17 @@ function isInsideRoot(root, target) {
|
|
|
7301
7366
|
// F6: the settings page can replay the card, so the flag is cleared and an
|
|
7302
7367
|
// event wakes the overlay instead of the user hunting for local storage.
|
|
7303
7368
|
var WELCOME_EVENT = 'dsh-linked-workspace:welcome-open';
|
|
7369
|
+
var TOAST_EVENT = 'dsh-linked-workspace:toast';
|
|
7370
|
+
|
|
7371
|
+
// A one-line message for things that happen outside any panel (a chat link
|
|
7372
|
+
// with every file slot taken, for instance).
|
|
7373
|
+
function notifyToast(key, vars) {
|
|
7374
|
+
try {
|
|
7375
|
+
window.dispatchEvent(new CustomEvent(TOAST_EVENT, { detail: { key: key, vars: vars || {} } }));
|
|
7376
|
+
} catch (error) {
|
|
7377
|
+
/* no window (tests) */
|
|
7378
|
+
}
|
|
7379
|
+
}
|
|
7304
7380
|
var SHOW_HIDDEN_KEY = 'dsh-linked-workspace:show-hidden';
|
|
7305
7381
|
|
|
7306
7382
|
function readShowHidden() {
|
|
@@ -7372,7 +7448,34 @@ function rememberShowHidden(value) {
|
|
|
7372
7448
|
h('div', { className: 'rw-welcome-row-where' }, props.where));
|
|
7373
7449
|
}
|
|
7374
7450
|
|
|
7375
|
-
function
|
|
7451
|
+
function ToastHost(props) {
|
|
7452
|
+
var locale = useLocale(props.ctx);
|
|
7453
|
+
var t = useMemo(function () { return makeT(locale); }, [locale]);
|
|
7454
|
+
var stateRef = useState(null);
|
|
7455
|
+
var toast = stateRef[0];
|
|
7456
|
+
var setToast = stateRef[1];
|
|
7457
|
+
|
|
7458
|
+
useEffect(function () {
|
|
7459
|
+
function onToast(event) {
|
|
7460
|
+
var detail = (event && event.detail) || {};
|
|
7461
|
+
if (!detail.key) return;
|
|
7462
|
+
setToast({ text: t(detail.key, detail.vars || {}), at: Date.now() });
|
|
7463
|
+
}
|
|
7464
|
+
window.addEventListener(TOAST_EVENT, onToast);
|
|
7465
|
+
return function () { window.removeEventListener(TOAST_EVENT, onToast); };
|
|
7466
|
+
}, [t]);
|
|
7467
|
+
|
|
7468
|
+
useEffect(function () {
|
|
7469
|
+
if (!toast) return undefined;
|
|
7470
|
+
var timer = setTimeout(function () { setToast(null); }, 5000);
|
|
7471
|
+
return function () { clearTimeout(timer); };
|
|
7472
|
+
}, [toast && toast.at]);
|
|
7473
|
+
|
|
7474
|
+
if (!toast) return null;
|
|
7475
|
+
return h('div', { className: 'rw-toast', role: 'status', 'aria-live': 'polite' }, toast.text);
|
|
7476
|
+
}
|
|
7477
|
+
|
|
7478
|
+
function WelcomeCard(props) {
|
|
7376
7479
|
var locale = useLocale(props.ctx);
|
|
7377
7480
|
var t = useMemo(function () { return makeT(locale); }, [locale]);
|
|
7378
7481
|
var state = useState(function () { return !welcomeSeen(); });
|
|
@@ -8002,6 +8105,9 @@ function rememberShowHidden(value) {
|
|
|
8002
8105
|
var onOpenLink = props.onOpenLink;
|
|
8003
8106
|
var settings = useRuntimeSettings();
|
|
8004
8107
|
var kind = documentKindOf(path);
|
|
8108
|
+
// Word/Excel/PowerPoint are rendered through a PDF: the preview keeps the real
|
|
8109
|
+
// layout and is read-only, because the PDF cannot be written back as .docx.
|
|
8110
|
+
var officeKind = kind === 'docx' || kind === 'xlsx' || kind === 'pptx';
|
|
8005
8111
|
var viewKey = (local ? 'local' : ((scope && scope.kind ? scope.kind : 'remote') + ':' + ((scope && scope.id) || ''))) + '|' + path;
|
|
8006
8112
|
var rememberedView = recallView(viewKey);
|
|
8007
8113
|
var stateRef = useState({
|
|
@@ -8012,7 +8118,8 @@ function rememberShowHidden(value) {
|
|
|
8012
8118
|
sheet: rememberedView ? Number(rememberedView.sheet) || 0 : 0,
|
|
8013
8119
|
slide: rememberedView ? Number(rememberedView.slide) || 0 : 0,
|
|
8014
8120
|
updates: {}, pptxUpdates: {}, rotations: {}, deleted: {}, pdfLoading: false, notice: '', warn: '',
|
|
8015
|
-
findOpen: false, findQuery: '', findIndex: 0,
|
|
8121
|
+
findOpen: false, findQuery: '', findIndex: 0, findReplace: '',
|
|
8122
|
+
office: null,
|
|
8016
8123
|
});
|
|
8017
8124
|
var state = stateRef[0];
|
|
8018
8125
|
var setState = stateRef[1];
|
|
@@ -8099,7 +8206,39 @@ function rememberShowHidden(value) {
|
|
|
8099
8206
|
if (anchorOf(event)) event.preventDefault();
|
|
8100
8207
|
}
|
|
8101
8208
|
|
|
8209
|
+
function loadOffice(index) {
|
|
8210
|
+
patch({ loading: true, error: '', notice: '', warn: '' });
|
|
8211
|
+
return apiCall('docs.officePage', params({ page: index })).then(function (result) {
|
|
8212
|
+
var rendered = (result.pages && result.pages[0]) || {};
|
|
8213
|
+
patch({
|
|
8214
|
+
loading: false,
|
|
8215
|
+
office: { png: rendered.png || '', page: Number(rendered.index) || 0, pageCount: Number(result.pageCount) || 0, engine: result.engine || '' },
|
|
8216
|
+
page: Number(rendered.index) || 0,
|
|
8217
|
+
});
|
|
8218
|
+
}).catch(function (error) {
|
|
8219
|
+
patch({ loading: false, error: messageOf(error, t, locale) });
|
|
8220
|
+
if (error && error.code === 'FS_NOT_FOUND' && typeof props.onMissing === 'function') props.onMissing(path);
|
|
8221
|
+
});
|
|
8222
|
+
}
|
|
8223
|
+
|
|
8224
|
+
function goOfficePage(index) {
|
|
8225
|
+
if (!state.office) return;
|
|
8226
|
+
if (index < 0 || index >= state.office.pageCount || index === state.office.page) return;
|
|
8227
|
+
patch({ pdfLoading: true });
|
|
8228
|
+
apiCall('docs.officePage', params({ page: index })).then(function (result) {
|
|
8229
|
+
var rendered = (result.pages && result.pages[0]) || {};
|
|
8230
|
+
patch({
|
|
8231
|
+
pdfLoading: false,
|
|
8232
|
+
page: Number(rendered.index) || 0,
|
|
8233
|
+
office: Object.assign({}, state.office, { png: rendered.png || state.office.png, page: Number(rendered.index) || 0 }),
|
|
8234
|
+
});
|
|
8235
|
+
}).catch(function (error) {
|
|
8236
|
+
patch({ pdfLoading: false, error: messageOf(error, t, locale) });
|
|
8237
|
+
});
|
|
8238
|
+
}
|
|
8239
|
+
|
|
8102
8240
|
function load() {
|
|
8241
|
+
if (officeKind) return loadOffice(Number((recallView(viewKey) || {}).page) || 0);
|
|
8103
8242
|
patch({ loading: true, error: '', notice: '', warn: '' });
|
|
8104
8243
|
apiCall('docs.read', params()).then(function (result) {
|
|
8105
8244
|
var remembered = recallView(viewKey);
|
|
@@ -8161,6 +8300,7 @@ function rememberShowHidden(value) {
|
|
|
8161
8300
|
}, [state.dirty]);
|
|
8162
8301
|
|
|
8163
8302
|
function save() {
|
|
8303
|
+
if (officeKind) return Promise.resolve(false);
|
|
8164
8304
|
if (state.saving) return Promise.resolve(false);
|
|
8165
8305
|
patch({ saving: true, error: '', notice: '' });
|
|
8166
8306
|
var data = {};
|
|
@@ -8256,6 +8396,38 @@ function rememberShowHidden(value) {
|
|
|
8256
8396
|
if (docTextareaRef.current) docTextareaRef.current.focus();
|
|
8257
8397
|
}
|
|
8258
8398
|
|
|
8399
|
+
// Same matching rule as docMatches: plain case-insensitive text, no
|
|
8400
|
+
// regex, so the replacement stays predictable.
|
|
8401
|
+
function replaceRange(text, at, length) {
|
|
8402
|
+
return text.slice(0, at) + state.findReplace + text.slice(at + length);
|
|
8403
|
+
}
|
|
8404
|
+
|
|
8405
|
+
function replaceDocCurrent() {
|
|
8406
|
+
var matches = docMatches();
|
|
8407
|
+
if (matches.length === 0) return;
|
|
8408
|
+
var index = Math.min(Math.max(state.findIndex, 0), matches.length - 1);
|
|
8409
|
+
var at = matches[index];
|
|
8410
|
+
var nextText = replaceRange(state.text, at, state.findQuery.length);
|
|
8411
|
+
patch({ text: nextText, dirty: true, html: '', findIndex: index });
|
|
8412
|
+
var area = docTextareaRef.current;
|
|
8413
|
+
if (area) {
|
|
8414
|
+
area.focus();
|
|
8415
|
+
var caret = at + state.findReplace.length;
|
|
8416
|
+
area.setSelectionRange(caret, caret);
|
|
8417
|
+
}
|
|
8418
|
+
}
|
|
8419
|
+
|
|
8420
|
+
function replaceDocAll() {
|
|
8421
|
+
var matches = docMatches();
|
|
8422
|
+
if (matches.length === 0) return;
|
|
8423
|
+
var text = state.text;
|
|
8424
|
+
// Back to front: the earlier offsets stay valid while splicing.
|
|
8425
|
+
for (var cursor = matches.length - 1; cursor >= 0; cursor -= 1) {
|
|
8426
|
+
text = replaceRange(text, matches[cursor], state.findQuery.length);
|
|
8427
|
+
}
|
|
8428
|
+
patch({ text: text, dirty: true, html: '', findIndex: 0 });
|
|
8429
|
+
}
|
|
8430
|
+
|
|
8259
8431
|
useEffect(function () {
|
|
8260
8432
|
if (!settings.autoSave || !state.dirty || state.saving) return undefined;
|
|
8261
8433
|
var timer = setTimeout(function () { saveRef.current(); }, 900);
|
|
@@ -8346,7 +8518,15 @@ function rememberShowHidden(value) {
|
|
|
8346
8518
|
h('span', { className: 'rw-hint', style: { flex: '1 1 auto', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: path }, path),
|
|
8347
8519
|
kind === 'markdown' ? h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: showPreview }, state.preview ? t('docEdit') : t('docPreview')) : null,
|
|
8348
8520
|
kind === 'markdown' ? h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: exportPdf, disabled: state.saving }, IconDownload(12), t('exportPdf')) : null,
|
|
8349
|
-
|
|
8521
|
+
officeKind && state.office
|
|
8522
|
+
? h('div', { className: 'rw-inline' },
|
|
8523
|
+
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: state.pdfLoading || state.office.page <= 0, onClick: function () { goOfficePage(state.office.page - 1); } }, '‹'),
|
|
8524
|
+
h('span', { className: 'rw-hint' }, (state.office.page + 1) + ' / ' + Math.max(state.office.pageCount, 1)),
|
|
8525
|
+
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: state.pdfLoading || state.office.page >= state.office.pageCount - 1, onClick: function () { goOfficePage(state.office.page + 1); } }, '›'))
|
|
8526
|
+
: null,
|
|
8527
|
+
officeKind
|
|
8528
|
+
? h('button', { type: 'button', className: 'rw-btn rw-btn-sm', onClick: function () { loadOffice(state.office ? state.office.page : 0); }, disabled: state.loading || state.pdfLoading }, IconRefresh(13), t('reload'))
|
|
8529
|
+
: h('button', { type: 'button', className: 'rw-btn rw-btn-sm rw-btn-primary', onClick: save, disabled: state.saving || !state.dirty }, state.saving ? Spinner(12) : IconSave(12), state.saving ? t('saving') : t('save')));
|
|
8350
8530
|
|
|
8351
8531
|
if (state.loading) {
|
|
8352
8532
|
return h('div', { className: 'rw-doc' }, toolbar, h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')));
|
|
@@ -8388,6 +8568,20 @@ function rememberShowHidden(value) {
|
|
|
8388
8568
|
})()),
|
|
8389
8569
|
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('findPrev'), onClick: function () { stepDocMatch(-1); } }, h('span', { style: { display: 'inline-flex', transform: 'rotate(180deg)' } }, IconChevron(12))),
|
|
8390
8570
|
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', title: t('findNext'), onClick: function () { stepDocMatch(1); } }, IconChevron(12)),
|
|
8571
|
+
h('input', {
|
|
8572
|
+
className: 'rw-input',
|
|
8573
|
+
value: state.findReplace,
|
|
8574
|
+
placeholder: t('replacePlaceholder'),
|
|
8575
|
+
'aria-label': t('replacePlaceholder'),
|
|
8576
|
+
spellCheck: false,
|
|
8577
|
+
onChange: function (event) { patch({ findReplace: event.currentTarget.value }); },
|
|
8578
|
+
onKeyDown: function (event) {
|
|
8579
|
+
if (event.key === 'Enter') { event.preventDefault(); replaceDocCurrent(); }
|
|
8580
|
+
if (event.key === 'Escape') { event.preventDefault(); closeDocFind(); }
|
|
8581
|
+
},
|
|
8582
|
+
}),
|
|
8583
|
+
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: docMatches().length === 0, onClick: replaceDocCurrent }, t('replaceOne')),
|
|
8584
|
+
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: docMatches().length === 0, onClick: replaceDocAll }, t('replaceAll')),
|
|
8391
8585
|
h('button', { type: 'button', className: 'rw-icon-btn', title: t('close'), onClick: closeDocFind }, IconClose(12)))
|
|
8392
8586
|
: null,
|
|
8393
8587
|
h('textarea', {
|
|
@@ -8414,70 +8608,14 @@ function rememberShowHidden(value) {
|
|
|
8414
8608
|
h('button', { type: 'button', className: 'rw-btn rw-btn-sm rw-btn-danger', disabled: total <= 1, onClick: function () { var deleted = Object.assign({}, state.deleted); deleted[state.page] = true; var next = state.page + 1; while (next < total && deleted[next]) next += 1; if (next >= total) { next = state.page - 1; while (next >= 0 && deleted[next]) next -= 1; } var nextPage = next >= 0 ? next : state.page; patch({ deleted: deleted, dirty: true, page: nextPage }); if (next >= 0 && !((state.data.pages || []).some(function (page) { return page.index === next; }))) goPdfPage(next); } }, t('docDeletePage')))),
|
|
8415
8609
|
state.pdfLoading ? h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')) : null,
|
|
8416
8610
|
current ? h('img', { className: 'rw-doc-pdf-page', src: current.png, style: { transform: 'rotate(' + ((state.rotations[current.index] || current.rotation || 0) % 360) + 'deg)' } }) : null);
|
|
8417
|
-
} else if (
|
|
8418
|
-
|
|
8419
|
-
|
|
8420
|
-
body = h('div', { className: 'rw-doc-body' },
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
}),
|
|
8426
|
-
tables.map(function (rows, tableIndex) {
|
|
8427
|
-
return h('div', { key: 't' + tableIndex },
|
|
8428
|
-
h('div', { className: 'rw-doc-block-label' }, t('docTable') + ' ' + (tableIndex + 1)),
|
|
8429
|
-
h('table', { className: 'rw-doc-table' }, h('tbody', null,
|
|
8430
|
-
rows.map(function (row, rowIndex) {
|
|
8431
|
-
return h('tr', { key: rowIndex }, row.map(function (cell, cellIndex) {
|
|
8432
|
-
return h('td', { key: cellIndex }, h('input', { value: cell || '', onChange: function (event) { updateTableCell(tableIndex, rowIndex, cellIndex, event.currentTarget.value); } }));
|
|
8433
|
-
}));
|
|
8434
|
-
}))));
|
|
8435
|
-
}));
|
|
8436
|
-
} else if (kind === 'xlsx' && state.data) {
|
|
8437
|
-
var sheets = state.data.sheets || [];
|
|
8438
|
-
var active = sheets[Math.min(state.sheet, Math.max(sheets.length - 1, 0))] || { name: '', rows: [] };
|
|
8439
|
-
var columns = Math.max(active.maxCol || 0, 8);
|
|
8440
|
-
var header = h('tr', null, h('th', null, ''), Array.from({ length: columns }, function (_, index) { return h('th', { key: index }, String.fromCharCode(65 + index)); }));
|
|
8441
|
-
var gridRows = (active.rows || []).map(function (row, rowIndex) {
|
|
8442
|
-
return h('tr', { key: rowIndex },
|
|
8443
|
-
h('th', null, String(rowIndex + 1)),
|
|
8444
|
-
Array.from({ length: columns }, function (_, colIndex) {
|
|
8445
|
-
var cell = String.fromCharCode(65 + colIndex) + (rowIndex + 1);
|
|
8446
|
-
var value = row[colIndex];
|
|
8447
|
-
return h('td', { key: colIndex }, h('input', {
|
|
8448
|
-
value: value === null || value === undefined ? '' : String(value),
|
|
8449
|
-
onChange: function (event) { updateCell(active.name, cell, event.currentTarget.value); },
|
|
8450
|
-
}));
|
|
8451
|
-
}));
|
|
8452
|
-
});
|
|
8453
|
-
body = h('div', { className: 'rw-doc-body', style: { padding: 0, overflow: 'hidden' } },
|
|
8454
|
-
h('div', { className: 'rw-doc-tabs' }, sheets.map(function (sheet, index) {
|
|
8455
|
-
return h('button', { key: sheet.name, type: 'button', className: 'rw-doc-tab' + (index === state.sheet ? ' is-on' : ''), onClick: function () { patch({ sheet: index }); } }, sheet.name);
|
|
8456
|
-
})),
|
|
8457
|
-
active.truncated
|
|
8458
|
-
? h('div', { className: 'rw-doc-note' }, t('sheetTruncated', { rows: active.maxRow || 0, cols: active.maxCol || 0 }))
|
|
8459
|
-
: null,
|
|
8460
|
-
(state.data.sheetCount || sheets.length) > sheets.length
|
|
8461
|
-
? h('div', { className: 'rw-doc-note' }, t('sheetMore'))
|
|
8462
|
-
: null,
|
|
8463
|
-
h('div', { style: { flex: '1 1 auto', overflow: 'auto', padding: 8 } },
|
|
8464
|
-
h('table', { className: 'rw-doc-grid' },
|
|
8465
|
-
h('thead', null, header),
|
|
8466
|
-
h('tbody', null, gridRows))));
|
|
8467
|
-
} else if (kind === 'pptx' && state.data) {
|
|
8468
|
-
var slides = state.data.slides || [];
|
|
8469
|
-
var slide = slides[Math.min(state.slide, Math.max(slides.length - 1, 0))] || { texts: [] };
|
|
8470
|
-
body = h('div', { className: 'rw-doc-body' },
|
|
8471
|
-
h('div', { className: 'rw-inline', style: { justifyContent: 'space-between', marginBottom: 6 } },
|
|
8472
|
-
h('div', { className: 'rw-inline' },
|
|
8473
|
-
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: state.slide <= 0, onClick: function () { patch({ slide: state.slide - 1 }); } }, '‹'),
|
|
8474
|
-
h('span', { className: 'rw-hint' }, (state.slide + 1) + ' / ' + slides.length),
|
|
8475
|
-
h('button', { type: 'button', className: 'rw-btn rw-btn-sm', disabled: state.slide >= slides.length - 1, onClick: function () { patch({ slide: state.slide + 1 }); } }, '›'))),
|
|
8476
|
-
(slide.texts || []).map(function (item) {
|
|
8477
|
-
return h('div', { key: item.shape, className: 'rw-doc-block' },
|
|
8478
|
-
h('div', { className: 'rw-doc-block-label' }, (item.name || t('docSlide')) + ' · ' + item.shape),
|
|
8479
|
-
h('textarea', { value: (state.pptxUpdates[state.slide + ':' + item.shape] || item).text || '', onChange: function (event) { updateSlideText(state.slide, item.shape, event.currentTarget.value); } }));
|
|
8480
|
-
}));
|
|
8611
|
+
} else if (officeKind && state.office) {
|
|
8612
|
+
// A rendered page is the whole point: the layout came out of LibreOffice,
|
|
8613
|
+
// so nothing here re-flows the document.
|
|
8614
|
+
body = h('div', { className: 'rw-doc-body', ref: docBodyRef, onScroll: rememberScroll },
|
|
8615
|
+
state.pdfLoading ? h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')) : null,
|
|
8616
|
+
state.office.png
|
|
8617
|
+
? h('img', { className: 'rw-doc-page', alt: basename(path), src: state.office.png })
|
|
8618
|
+
: h('div', { className: 'rw-editor-message' }, t('docRenderEmpty')));
|
|
8481
8619
|
}
|
|
8482
8620
|
|
|
8483
8621
|
return h('div', { className: 'rw-doc' }, toolbar,
|
|
@@ -10360,6 +10498,7 @@ function rememberShowHidden(value) {
|
|
|
10360
10498
|
}),
|
|
10361
10499
|
local: results[1] && results[1].entries ? results[1].entries : [],
|
|
10362
10500
|
truncated: Boolean((results[0] && results[0].truncated) || (results[1] && results[1].truncated)),
|
|
10501
|
+
outsideDropped: Number(results[0] && results[0].outsideDropped) || 0,
|
|
10363
10502
|
truncatedReason: (results[0] && results[0].truncatedReason) || (results[1] && results[1].truncatedReason) || '',
|
|
10364
10503
|
error: (results[0] && results[0].error) || (results[1] && results[1].error) || null,
|
|
10365
10504
|
});
|
|
@@ -10786,7 +10925,13 @@ function rememberShowHidden(value) {
|
|
|
10786
10925
|
? h('span', { className: 'rw-autopush-when' }, new Date(autoPush.lastPushAt).toLocaleTimeString())
|
|
10787
10926
|
: null)
|
|
10788
10927
|
: null,
|
|
10789
|
-
h('button', {
|
|
10928
|
+
h('button', {
|
|
10929
|
+
type: 'button',
|
|
10930
|
+
className: 'rw-icon-btn',
|
|
10931
|
+
title: t('toggleDirectory'),
|
|
10932
|
+
'aria-label': t('toggleDirectory'),
|
|
10933
|
+
onClick: function () { setDirectoryOpen(false); },
|
|
10934
|
+
}, IconClose(11))),
|
|
10790
10935
|
h('div', { className: 'rw-directory-body' }, body))
|
|
10791
10936
|
: null),
|
|
10792
10937
|
ctxMenu ? h(ContextMenu, { menu: ctxMenu, items: buildContextItems(ctxMenu), t: t, onClose: closeContextMenu }) : null,
|
|
@@ -10807,6 +10952,12 @@ function rememberShowHidden(value) {
|
|
|
10807
10952
|
var busyRef = useState(false);
|
|
10808
10953
|
var busy = busyRef[0];
|
|
10809
10954
|
var setBusy = busyRef[1];
|
|
10955
|
+
var downloadingRef = useState(false);
|
|
10956
|
+
var downloading = downloadingRef[0];
|
|
10957
|
+
var setDownloading = downloadingRef[1];
|
|
10958
|
+
var savedRef = useState('');
|
|
10959
|
+
var savedPath = savedRef[0];
|
|
10960
|
+
var setSavedPath = savedRef[1];
|
|
10810
10961
|
var noteRef = useState('');
|
|
10811
10962
|
var note = noteRef[0];
|
|
10812
10963
|
var setNote = noteRef[1];
|
|
@@ -10875,21 +11026,27 @@ function rememberShowHidden(value) {
|
|
|
10875
11026
|
}
|
|
10876
11027
|
|
|
10877
11028
|
function download() {
|
|
10878
|
-
if (
|
|
10879
|
-
|
|
11029
|
+
if (downloading) return;
|
|
11030
|
+
setDownloading(true);
|
|
10880
11031
|
setNote('');
|
|
10881
11032
|
apiCall('fs.downloadOutside', Object.assign({ path: filePath }, scopeParams(scope))).then(function (result) {
|
|
10882
|
-
|
|
11033
|
+
setDownloading(false);
|
|
10883
11034
|
var saved = result && result.path ? String(result.path) : '';
|
|
11035
|
+
setSavedPath(saved);
|
|
10884
11036
|
setNote(t('outsideDownloaded', { path: saved }));
|
|
10885
11037
|
}, function (error) {
|
|
10886
|
-
|
|
11038
|
+
setDownloading(false);
|
|
10887
11039
|
setLoad(function (previous) {
|
|
10888
11040
|
return { loading: false, more: false, error: error, data: previous.data };
|
|
10889
11041
|
});
|
|
10890
11042
|
});
|
|
10891
11043
|
}
|
|
10892
11044
|
|
|
11045
|
+
function revealSaved() {
|
|
11046
|
+
if (savedPath === '') return;
|
|
11047
|
+
apiCall('local.reveal', { path: savedPath }).catch(function () { /* the file manager may refuse */ });
|
|
11048
|
+
}
|
|
11049
|
+
|
|
10893
11050
|
function addRoot() {
|
|
10894
11051
|
if (busy) return;
|
|
10895
11052
|
setBusy(true);
|
|
@@ -10921,8 +11078,9 @@ function rememberShowHidden(value) {
|
|
|
10921
11078
|
className: 'rw-btn rw-btn-sm',
|
|
10922
11079
|
title: t('outsideDownload'),
|
|
10923
11080
|
'aria-label': t('outsideDownload'),
|
|
11081
|
+
disabled: downloading,
|
|
10924
11082
|
onClick: download,
|
|
10925
|
-
}, t('outsideDownload')),
|
|
11083
|
+
}, t(downloading ? 'outsideDownloading' : 'outsideDownload')),
|
|
10926
11084
|
h('button', {
|
|
10927
11085
|
className: 'rw-btn rw-btn-sm',
|
|
10928
11086
|
title: t('outsideReload'),
|
|
@@ -10957,6 +11115,12 @@ function rememberShowHidden(value) {
|
|
|
10957
11115
|
? h('span', { className: 'rw-hint' }, t('outsideMtime', { when: new Date(data.mtime).toLocaleString() }))
|
|
10958
11116
|
: null,
|
|
10959
11117
|
note ? h('span', { className: 'rw-hint' }, note) : null,
|
|
11118
|
+
savedPath !== '' ? h('button', {
|
|
11119
|
+
className: 'rw-btn rw-btn-sm rw-btn-ghost',
|
|
11120
|
+
title: t('outsideReveal'),
|
|
11121
|
+
'aria-label': t('outsideReveal'),
|
|
11122
|
+
onClick: revealSaved,
|
|
11123
|
+
}, t('outsideReveal')) : null,
|
|
10960
11124
|
canMore
|
|
10961
11125
|
? h('button', { className: 'rw-btn rw-btn-sm', disabled: load.more, onClick: loadMore },
|
|
10962
11126
|
load.more ? t('loading') : t('outsideLoadMore'))
|
|
@@ -10972,6 +11136,9 @@ function rememberShowHidden(value) {
|
|
|
10972
11136
|
className: 'rw-outside-image',
|
|
10973
11137
|
alt: basename(filePath),
|
|
10974
11138
|
src: 'data:' + String(image.data.mime || 'application/octet-stream') + ';base64,' + String(image.data.base64 || ''),
|
|
11139
|
+
onError: function () {
|
|
11140
|
+
setImage({ loading: false, error: { code: 'FS_DECODE', message: t('imageBroken') }, data: null });
|
|
11141
|
+
},
|
|
10975
11142
|
})
|
|
10976
11143
|
: h('div', { className: 'rw-doc-loading' }, h('div', { className: 'rw-spinner' }), h('span', null, t('loading')));
|
|
10977
11144
|
body = h('div', { className: 'rw-doc-body' }, picture, footer);
|
|
@@ -14192,8 +14359,12 @@ function rememberShowHidden(value) {
|
|
|
14192
14359
|
// With every slot busy the click is claimed but has nowhere to land: the
|
|
14193
14360
|
// native viewer would only show "file not found", so report it as handled
|
|
14194
14361
|
// and let the panel say why nothing opened.
|
|
14195
|
-
if (!opened && slotFull === true
|
|
14196
|
-
|
|
14362
|
+
if (!opened && slotFull === true) {
|
|
14363
|
+
if (typeof slotFullNotice === 'function') {
|
|
14364
|
+
try { slotFullNotice(); } catch (error) { /* the panel may be gone */ }
|
|
14365
|
+
} else {
|
|
14366
|
+
notifyToast('tabsFull', { count: String(FILE_SLOT_COUNT) });
|
|
14367
|
+
}
|
|
14197
14368
|
}
|
|
14198
14369
|
return opened || slotFull === true;
|
|
14199
14370
|
}
|
|
@@ -14487,6 +14658,21 @@ function rememberShowHidden(value) {
|
|
|
14487
14658
|
console.error('[dsh-linked-workspace] welcome card registration failed', error && error.message ? error.message : error);
|
|
14488
14659
|
}
|
|
14489
14660
|
|
|
14661
|
+
try {
|
|
14662
|
+
ctx.slots.inject('shell.overlay', function () {
|
|
14663
|
+
return ctx.slots.register({
|
|
14664
|
+
name: 'shell.overlay',
|
|
14665
|
+
id: 'linked-workspace-toast',
|
|
14666
|
+
order: 81,
|
|
14667
|
+
label: function () { return makeT(readLocale(ctx))('tabsFull'); },
|
|
14668
|
+
}, function (props) {
|
|
14669
|
+
return h(ToastHost, Object.assign({}, props, { ctx: ctx }));
|
|
14670
|
+
});
|
|
14671
|
+
});
|
|
14672
|
+
} catch (error) {
|
|
14673
|
+
console.error('[dsh-linked-workspace] toast registration failed', error && error.message ? error.message : error);
|
|
14674
|
+
}
|
|
14675
|
+
|
|
14490
14676
|
try {
|
|
14491
14677
|
ctx.slots.inject('settings.section', function () {
|
|
14492
14678
|
return ctx.slots.register({
|
package/lib/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import { fileURLToPath } from 'node:url'
|
|
|
26
26
|
import { createRequire } from 'node:module'
|
|
27
27
|
import { forgetKnownHost, listHosts, listKnownHosts, RemoteHost, SshError, writeLocalCredential } from './ssh.js'
|
|
28
28
|
import { renderMarkdownFragment } from './markdown.js'
|
|
29
|
+
import { convertOfficeToPdf, sofficePath } from './office.js'
|
|
29
30
|
import * as linkedFs from './linked.js'
|
|
30
31
|
import * as git from './git.js'
|
|
31
32
|
|
|
@@ -41,7 +42,7 @@ export const inject = ['webServer', 'tools', 'systemPrompt', 'workingDirectory']
|
|
|
41
42
|
* is still running an older copy of the Host — refreshing the page only swaps
|
|
42
43
|
* the browser bundle, so the two halves can drift by one restart.
|
|
43
44
|
*/
|
|
44
|
-
const API_REVISION =
|
|
45
|
+
const API_REVISION = 17
|
|
45
46
|
|
|
46
47
|
/** When this copy of the Host was loaded; shown by `meta.info`. */
|
|
47
48
|
const STARTED_AT = new Date().toISOString()
|
|
@@ -147,6 +148,9 @@ const PEEK_LIMIT = 512 * 1024
|
|
|
147
148
|
const READ_CAP = 8 * 1024 * 1024
|
|
148
149
|
const MAX_WRITE_BYTES = 8 * 1024 * 1024
|
|
149
150
|
const MAX_MEDIA_BYTES = 24 * 1024 * 1024
|
|
151
|
+
// Inline previews carry a base64 copy inside a JS string, so they are capped
|
|
152
|
+
// well below the hard media limit; past this the viewer points at the download.
|
|
153
|
+
const MAX_INLINE_IMAGE_BYTES = 8 * 1024 * 1024
|
|
150
154
|
// ── remote command execution (0.17.0) ───────────────────────────────────────/** Longest command line accepted; anything longer is almost always a paste error. */
|
|
151
155
|
const EXEC_MAX_COMMAND = 8000
|
|
152
156
|
const EXEC_TIMEOUT_DEFAULT = 60_000
|
|
@@ -2839,7 +2843,50 @@ export function apply(ctx) {
|
|
|
2839
2843
|
return kind
|
|
2840
2844
|
}
|
|
2841
2845
|
|
|
2842
|
-
|
|
2846
|
+
// Office previews: one PDF per (content) hash, kept next to the plugin data so a
|
|
2847
|
+
// second open of the same document renders instantly.
|
|
2848
|
+
const officePdfCache = new Map()
|
|
2849
|
+
|
|
2850
|
+
function officeRenderDir() {
|
|
2851
|
+
const directory = join(tmpdir(), 'dsh-linked-workspace-office')
|
|
2852
|
+
mkdirSync(directory, { recursive: true })
|
|
2853
|
+
return directory
|
|
2854
|
+
}
|
|
2855
|
+
|
|
2856
|
+
async function officePdfFor(bytes, ext) {
|
|
2857
|
+
const key = createHash('sha1').update(bytes).digest('hex')
|
|
2858
|
+
const known = officePdfCache.get(key)
|
|
2859
|
+
if (known && existsSync(known)) return known
|
|
2860
|
+
const file = join(officeRenderDir(), key + '.pdf')
|
|
2861
|
+
if (existsSync(file)) {
|
|
2862
|
+
officePdfCache.set(key, file)
|
|
2863
|
+
return file
|
|
2864
|
+
}
|
|
2865
|
+
const pending = officePdfPending.get(key)
|
|
2866
|
+
if (pending) return await pending
|
|
2867
|
+
const job = (async () => {
|
|
2868
|
+
const converted = await convertOfficeToPdf(bytes, ext)
|
|
2869
|
+
writeFileSync(file, converted.pdf)
|
|
2870
|
+
officePdfCache.set(key, file)
|
|
2871
|
+
if (officePdfCache.size > 12) {
|
|
2872
|
+
const oldest = officePdfCache.keys().next().value
|
|
2873
|
+
const oldestFile = officePdfCache.get(oldest)
|
|
2874
|
+
officePdfCache.delete(oldest)
|
|
2875
|
+
try { rmSync(oldestFile, { force: true }) } catch { /* best effort */ }
|
|
2876
|
+
}
|
|
2877
|
+
return file
|
|
2878
|
+
})()
|
|
2879
|
+
officePdfPending.set(key, job)
|
|
2880
|
+
try {
|
|
2881
|
+
return await job
|
|
2882
|
+
} finally {
|
|
2883
|
+
officePdfPending.delete(key)
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
const officePdfPending = new Map()
|
|
2888
|
+
|
|
2889
|
+
async function docStat(target) {
|
|
2843
2890
|
if (!target.remote) {
|
|
2844
2891
|
try { const info = await fsStat(target.path); return info } catch { return null }
|
|
2845
2892
|
}
|
|
@@ -2856,7 +2903,9 @@ export function apply(ctx) {
|
|
|
2856
2903
|
const GREP_DEADLINE_MS = 5000
|
|
2857
2904
|
const GREP_DEADLINE_MAX = 10000
|
|
2858
2905
|
const GREP_PREVIEW_CHARS = 120
|
|
2859
|
-
|
|
2906
|
+
// How many extra roots one content search may sweep.
|
|
2907
|
+
const OUTSIDE_GREP_ROOTS = 5
|
|
2908
|
+
const GREP_MAX_QUERY = 200
|
|
2860
2909
|
|
|
2861
2910
|
// Path completion (`fs.references`) is about names, not contents, so it walks
|
|
2862
2911
|
// more entries but reads no files.
|
|
@@ -3883,6 +3932,29 @@ export function apply(ctx) {
|
|
|
3883
3932
|
}
|
|
3884
3933
|
},
|
|
3885
3934
|
|
|
3935
|
+
/**
|
|
3936
|
+
* Render one page of a Word/Excel/PowerPoint document. The preview is
|
|
3937
|
+
* read-only on purpose: a converted PDF is the only way to keep the layout
|
|
3938
|
+
* intact, and it cannot be written back into the original file.
|
|
3939
|
+
*/
|
|
3940
|
+
async 'docs.officePage'(params = {}) {
|
|
3941
|
+
const target = await docTarget(params)
|
|
3942
|
+
const kind = assertDocKind(target.path)
|
|
3943
|
+
if (kind !== 'docx' && kind !== 'xlsx' && kind !== 'pptx') {
|
|
3944
|
+
throw new ApiError('BAD_REQUEST', '只有 Word、Excel 与 PowerPoint 需要这种渲染')
|
|
3945
|
+
}
|
|
3946
|
+
const page = Number(params.page)
|
|
3947
|
+
if (!Number.isInteger(page) || page < 0) throw new ApiError('BAD_REQUEST', '页码无效')
|
|
3948
|
+
const engine = sofficePath() === '' ? '' : 'libreoffice'
|
|
3949
|
+
if (engine === '') {
|
|
3950
|
+
throw new ApiError('NO_RENDERER', '这台机器上没有 LibreOffice,无法渲染 Office 文档')
|
|
3951
|
+
}
|
|
3952
|
+
const current = await readDocBytes(target, target)
|
|
3953
|
+
const pdf = await officePdfFor(current.data, kind)
|
|
3954
|
+
const rendered = await runDocTool(['read', '--kind', 'pdf', '--file', pdf, '--page', String(page)])
|
|
3955
|
+
return { kind, engine, path: target.path, mtime: current.mtime, ...rendered }
|
|
3956
|
+
},
|
|
3957
|
+
|
|
3886
3958
|
async 'docs.pdfPage'(params = {}) {
|
|
3887
3959
|
const target = await docTarget(params)
|
|
3888
3960
|
assertDocKind(target.path, 'pdf')
|
|
@@ -4281,8 +4353,8 @@ export function apply(ctx) {
|
|
|
4281
4353
|
if (!mime) throw new ApiError('BAD_REQUEST', '该文件不是支持的图片格式')
|
|
4282
4354
|
const stat = await scope.remote.stat(target)
|
|
4283
4355
|
if (stat.type === 'dir') throw new ApiError('FS_IS_DIR', '目标是目录,无法预览')
|
|
4284
|
-
if (stat.size >
|
|
4285
|
-
const read = await scope.remote.readFile(target, { maxBytes:
|
|
4356
|
+
if (stat.size > MAX_INLINE_IMAGE_BYTES) throw new ApiError('FS_TOO_LARGE', '图片超过 8 MB,无法内联预览,请下载后查看')
|
|
4357
|
+
const read = await scope.remote.readFile(target, { maxBytes: MAX_INLINE_IMAGE_BYTES })
|
|
4286
4358
|
return { path: target, size: stat.size, mtime: stat.mtime, mime, base64: read.data.toString('base64') }
|
|
4287
4359
|
},
|
|
4288
4360
|
|
|
@@ -4734,6 +4806,31 @@ export function apply(ctx) {
|
|
|
4734
4806
|
// A link inside a remote document cannot be followed by the window that
|
|
4735
4807
|
// shows the preview: the SPA has no route for it and goes blank. External
|
|
4736
4808
|
// links are handed to the system browser instead.
|
|
4809
|
+
async 'local.reveal'(params = {}) {
|
|
4810
|
+
const rawPath = typeof params.path === 'string' ? params.path.trim() : ''
|
|
4811
|
+
if (rawPath === '' || !isAbsolute(rawPath)) throw new ApiError('BAD_REQUEST', '本地路径必须是绝对路径')
|
|
4812
|
+
const target = resolve(rawPath)
|
|
4813
|
+
let info
|
|
4814
|
+
try {
|
|
4815
|
+
info = await fsStat(target)
|
|
4816
|
+
} catch (error) {
|
|
4817
|
+
throw mapLocalFsError(error)
|
|
4818
|
+
}
|
|
4819
|
+
const folder = info.isDirectory() ? target : dirname(target)
|
|
4820
|
+
const command = process.platform === 'win32' ? 'explorer.exe' : process.platform === 'darwin' ? 'open' : 'xdg-open'
|
|
4821
|
+
const args = process.platform === 'win32' && !info.isDirectory() ? ['/select,', target] : [info.isDirectory() ? target : folder]
|
|
4822
|
+
let started = false
|
|
4823
|
+
try {
|
|
4824
|
+
const child = spawn(command, args, { detached: true, stdio: 'ignore', windowsHide: true })
|
|
4825
|
+
child.unref()
|
|
4826
|
+
started = true
|
|
4827
|
+
} catch (error) {
|
|
4828
|
+
started = false
|
|
4829
|
+
}
|
|
4830
|
+
if (!started) throw new ApiError('INTERNAL', '无法打开文件管理器')
|
|
4831
|
+
return { opened: true, folder }
|
|
4832
|
+
},
|
|
4833
|
+
|
|
4737
4834
|
async 'local.openUrl'(params = {}) {
|
|
4738
4835
|
const raw = typeof params.url === 'string' ? params.url.trim() : ''
|
|
4739
4836
|
if (!/^(?:https?|mailto|tel):/i.test(raw)) throw new ApiError('BAD_REQUEST', '只支持 http、https、mailto 与 tel 链接')
|
|
@@ -4861,16 +4958,34 @@ export function apply(ctx) {
|
|
|
4861
4958
|
if (side === 'remote') {
|
|
4862
4959
|
const found = await contentSearchRemote(scope.remote, scope.root, query, maxResults, options)
|
|
4863
4960
|
if (params.includeOutside !== true) return found
|
|
4864
|
-
const
|
|
4865
|
-
if (
|
|
4961
|
+
const allRoots = extraRoots()
|
|
4962
|
+
if (allRoots.length === 0) return found
|
|
4963
|
+
// "Only this folder" has to mean the same relative folder under every
|
|
4964
|
+
// extra root; a root that has no such folder is skipped, not failed.
|
|
4965
|
+
const relative = typeof options.path === 'string' ? options.path.trim().replace(/^\/+/, '') : ''
|
|
4966
|
+
const roots = allRoots.slice(0, OUTSIDE_GREP_ROOTS)
|
|
4866
4967
|
const merged = found.entries.slice()
|
|
4867
4968
|
let truncated = found.truncated
|
|
4868
4969
|
let scanned = found.scannedFiles
|
|
4970
|
+
let outsideSkipped = 0
|
|
4869
4971
|
for (const root of roots) {
|
|
4870
4972
|
if (merged.length >= maxResults) {
|
|
4871
4973
|
truncated = true
|
|
4872
4974
|
break
|
|
4873
4975
|
}
|
|
4976
|
+
if (relative !== '') {
|
|
4977
|
+
let info
|
|
4978
|
+
try {
|
|
4979
|
+
info = await scope.remote.stat(posix.join(root, relative))
|
|
4980
|
+
} catch (error) {
|
|
4981
|
+
outsideSkipped += 1
|
|
4982
|
+
continue
|
|
4983
|
+
}
|
|
4984
|
+
if (info.type !== 'dir') {
|
|
4985
|
+
outsideSkipped += 1
|
|
4986
|
+
continue
|
|
4987
|
+
}
|
|
4988
|
+
}
|
|
4874
4989
|
const part = await contentSearchRemote(scope.remote, root, query, maxResults - merged.length, options)
|
|
4875
4990
|
scanned += part.scannedFiles
|
|
4876
4991
|
if (part.truncated) truncated = true
|
|
@@ -4890,6 +5005,9 @@ export function apply(ctx) {
|
|
|
4890
5005
|
scannedFiles: scanned,
|
|
4891
5006
|
scannedBytes: found.scannedBytes,
|
|
4892
5007
|
skippedFiles: found.skippedFiles,
|
|
5008
|
+
outsideRoots: roots.length,
|
|
5009
|
+
outsideDropped: Math.max(0, allRoots.length - roots.length),
|
|
5010
|
+
outsideSkipped,
|
|
4893
5011
|
}
|
|
4894
5012
|
}
|
|
4895
5013
|
if (scope.kind !== 'linked') throw new ApiError('BAD_REQUEST', '只有联动工作区有本地目录')
|
package/lib/office.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Convert Office documents to PDF with a headless LibreOffice.
|
|
2
|
+
//
|
|
3
|
+
// Why a subprocess: the PDF is only a stepping stone — PyMuPDF renders its pages
|
|
4
|
+
// for the read-only preview, and a real office engine is the only way to keep
|
|
5
|
+
// Word/Excel/PowerPoint layout intact. LibreOffice is started per conversion
|
|
6
|
+
// with its own profile directory, because two instances sharing one profile
|
|
7
|
+
// block each other and the first one wins.
|
|
8
|
+
|
|
9
|
+
import { spawn } from 'node:child_process'
|
|
10
|
+
import { existsSync } from 'node:fs'
|
|
11
|
+
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
12
|
+
import { tmpdir } from 'node:os'
|
|
13
|
+
import { join } from 'node:path'
|
|
14
|
+
|
|
15
|
+
const WINDOWS_PATHS = [
|
|
16
|
+
'C:\\Program Files\\LibreOffice\\program\\soffice.exe',
|
|
17
|
+
'C:\\Program Files (x86)\\LibreOffice\\program\\soffice.exe',
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
let cachedPath
|
|
21
|
+
|
|
22
|
+
/** The LibreOffice binary, or '' when this machine has none. */
|
|
23
|
+
export function sofficePath() {
|
|
24
|
+
if (cachedPath !== undefined) return cachedPath
|
|
25
|
+
const fromEnv = typeof process.env.DSH_LINKED_WORKSPACE_SOFFICE === 'string'
|
|
26
|
+
? process.env.DSH_LINKED_WORKSPACE_SOFFICE.trim()
|
|
27
|
+
: ''
|
|
28
|
+
if (fromEnv !== '' && existsSync(fromEnv)) {
|
|
29
|
+
cachedPath = fromEnv
|
|
30
|
+
return cachedPath
|
|
31
|
+
}
|
|
32
|
+
if (process.platform === 'win32') {
|
|
33
|
+
cachedPath = WINDOWS_PATHS.find((item) => existsSync(item)) || ''
|
|
34
|
+
return cachedPath
|
|
35
|
+
}
|
|
36
|
+
const names = process.platform === 'darwin'
|
|
37
|
+
? ['/Applications/LibreOffice.app/Contents/MacOS/soffice', '/usr/local/bin/soffice']
|
|
38
|
+
: ['/usr/bin/soffice', '/usr/local/bin/soffice', '/snap/bin/libreoffice']
|
|
39
|
+
cachedPath = names.find((item) => existsSync(item)) || ''
|
|
40
|
+
return cachedPath
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function run(command, args, timeoutMs) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
let child
|
|
46
|
+
try {
|
|
47
|
+
child = spawn(command, args, { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] })
|
|
48
|
+
} catch (error) {
|
|
49
|
+
reject(error)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
let stderr = ''
|
|
53
|
+
const timer = setTimeout(() => {
|
|
54
|
+
// LibreOffice ignores SIGTERM on Windows; the tree kill is the only way out.
|
|
55
|
+
try {
|
|
56
|
+
if (process.platform === 'win32') {
|
|
57
|
+
spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' })
|
|
58
|
+
} else {
|
|
59
|
+
child.kill('SIGKILL')
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
/* already gone */
|
|
63
|
+
}
|
|
64
|
+
reject(new Error(`soffice timed out after ${timeoutMs} ms`))
|
|
65
|
+
}, timeoutMs)
|
|
66
|
+
child.stderr.on('data', (chunk) => {
|
|
67
|
+
if (stderr.length < 4000) stderr += chunk.toString('utf8')
|
|
68
|
+
})
|
|
69
|
+
child.on('error', (error) => {
|
|
70
|
+
clearTimeout(timer)
|
|
71
|
+
reject(error)
|
|
72
|
+
})
|
|
73
|
+
child.on('close', (code) => {
|
|
74
|
+
clearTimeout(timer)
|
|
75
|
+
if (code === 0) resolve(stderr)
|
|
76
|
+
else reject(new Error(`soffice exited ${code}: ${stderr.trim().slice(-400)}`))
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Convert one Office document (given as bytes) to PDF.
|
|
83
|
+
* Returns { pdf: Buffer, engine: 'libreoffice' }; throws when nothing can render.
|
|
84
|
+
*/
|
|
85
|
+
export async function convertOfficeToPdf(bytes, ext, options = {}) {
|
|
86
|
+
const binary = sofficePath()
|
|
87
|
+
if (binary === '') {
|
|
88
|
+
const error = new Error('这台机器上没有 LibreOffice,无法渲染 Office 文档')
|
|
89
|
+
error.code = 'NO_RENDERER'
|
|
90
|
+
throw error
|
|
91
|
+
}
|
|
92
|
+
const timeoutMs = Number(options.timeoutMs) > 0 ? Number(options.timeoutMs) : 120_000
|
|
93
|
+
const work = await mkdtemp(join(tmpdir(), 'dsh-office-'))
|
|
94
|
+
try {
|
|
95
|
+
const source = join(work, `source.${ext}`)
|
|
96
|
+
const profile = join(work, 'profile')
|
|
97
|
+
await writeFile(source, bytes)
|
|
98
|
+
await run(binary, [
|
|
99
|
+
`-env:UserInstallation=file:///${profile.replace(/\\/g, '/')}`,
|
|
100
|
+
'--headless',
|
|
101
|
+
'--norestore',
|
|
102
|
+
'--nologo',
|
|
103
|
+
'--nolockcheck',
|
|
104
|
+
'--nodefault',
|
|
105
|
+
'--convert-to',
|
|
106
|
+
'pdf',
|
|
107
|
+
'--outdir',
|
|
108
|
+
work,
|
|
109
|
+
source,
|
|
110
|
+
], timeoutMs)
|
|
111
|
+
const pdfPath = join(work, 'source.pdf')
|
|
112
|
+
if (!existsSync(pdfPath)) throw new Error('LibreOffice 没有产出 PDF')
|
|
113
|
+
const pdf = await readFile(pdfPath)
|
|
114
|
+
return { pdf, engine: 'libreoffice' }
|
|
115
|
+
} finally {
|
|
116
|
+
await rm(work, { recursive: true, force: true }).catch(() => {})
|
|
117
|
+
}
|
|
118
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-linked-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.1",
|
|
4
4
|
"description": "Linked local ⇄ remote workspaces and remote workspaces for DeepSeek Harness: theme-aware split editor, file-type icons, and agent tools that edit remote files directly.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|