@weniatall/dsh-file-viewer 0.3.2 → 0.3.3
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/README.md +3 -1
- package/lib/client.js +82 -33
- package/lib/index.js +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,7 +86,9 @@ dsh plugin --profile web add <release-tgz-url>
|
|
|
86
86
|
- **提交记录**:按 30 条一页加载,显示标题、短 SHA、作者与日期,底部「加载更多」按需追加,并显示「已显示 N / 总数」。
|
|
87
87
|
- **改动文件列表**:点击任一提交,右侧显示该提交的完整信息(标题、完整 SHA、作者、时间、正文)与相对**第一父提交**的改动文件列表(合并提交同理;根提交与空树比对)。`A / M / D / R / C` 等状态用颜色区分。
|
|
88
88
|
- **该提交的 diff**:提交详情有「变更文件 / 改动内容」两个页签,后者是该提交针对同一基准(第一父提交)的完整 patch,按文件分段并各自标注 `+N -M`。两个页签取的是同一对 revision,不会出现列表与 diff 基准不一致的情况。
|
|
89
|
-
- **跳转到文件**:点击改动文件会在右侧已有的预览器里打开**该提交中的版本**,而不是工作区当前内容——两者恰恰在历史最有价值的时候不同。被该提交删除的文件从父提交读取,所以删除行也能打开;重命名显示旧路径的内容。预览顶部会标明来源提交,避免被误认为当前文件。`‹`
|
|
89
|
+
- **跳转到文件**:点击改动文件会在右侧已有的预览器里打开**该提交中的版本**,而不是工作区当前内容——两者恰恰在历史最有价值的时候不同。被该提交删除的文件从父提交读取,所以删除行也能打开;重命名显示旧路径的内容。预览顶部会标明来源提交,避免被误认为当前文件。`‹` 返回 「变更文件」列表继续浏览。
|
|
90
|
+
|
|
91
|
+
打开后有两个页签:**改动**(这个提交对该文件做了什么,默认显示)和**完整内容**(该版本文件的全文,可翻页、切换语法高亮)。重命名的 diff 会保留为「重命名」而不是退化成「删除 + 新增」——宿主端把新旧两侧路径一起交给 git,否则 `-M` 无法配对。
|
|
90
92
|
|
|
91
93
|
只读操作(列出仓库、分支、历史、改动文件)不会修改仓库;面板中唯一的写操作是用户显式点击「检出」。
|
|
92
94
|
|
package/lib/client.js
CHANGED
|
@@ -3347,6 +3347,9 @@ window.__ModuleLoader__.load({
|
|
|
3347
3347
|
// from the working tree: the two differ exactly when the history is
|
|
3348
3348
|
// interesting, and a deleted file has no working-tree copy at all.
|
|
3349
3349
|
const fromCommit = typeof commit === "string" && commit !== "";
|
|
3350
|
+
// Whether the reader has picked a view themselves. The automatic landing
|
|
3351
|
+
// on the diff happens once per mount and then stays out of the way.
|
|
3352
|
+
const viewChosen = react.useRef(false);
|
|
3350
3353
|
|
|
3351
3354
|
react.useEffect(() => {
|
|
3352
3355
|
let live = true;
|
|
@@ -3366,10 +3369,40 @@ window.__ModuleLoader__.load({
|
|
|
3366
3369
|
}).catch((error) => {
|
|
3367
3370
|
if (live) setState({ status: "error", data: null, error });
|
|
3368
3371
|
});
|
|
3369
|
-
//
|
|
3370
|
-
//
|
|
3372
|
+
// A historical file is diffed against its own commit, not against the
|
|
3373
|
+
// index: the working-tree comparison would answer a different
|
|
3374
|
+
// question and show changes made after this commit.
|
|
3375
|
+
const diffSha = typeof meta.diffSha === "string" && meta.diffSha !== "" ? meta.diffSha : "";
|
|
3371
3376
|
if (fromCommit) {
|
|
3372
|
-
|
|
3377
|
+
if (diffSha === "") {
|
|
3378
|
+
setDiffData(null);
|
|
3379
|
+
return () => { live = false; };
|
|
3380
|
+
}
|
|
3381
|
+
request("gitCommitDiff", {
|
|
3382
|
+
root,
|
|
3383
|
+
repo,
|
|
3384
|
+
sha: diffSha,
|
|
3385
|
+
path: meta.rowPath || meta.path,
|
|
3386
|
+
...(meta.oldPath ? { oldPath: meta.oldPath } : {}),
|
|
3387
|
+
}).then((val) => {
|
|
3388
|
+
if (!live) return;
|
|
3389
|
+
// `gitCommitDiff` returns per-file sections; this view shows the
|
|
3390
|
+
// one file it asked for.
|
|
3391
|
+
const first = val !== null && Array.isArray(val.files) ? val.files[0] : null;
|
|
3392
|
+
const loaded = first === null || first === undefined
|
|
3393
|
+
? null
|
|
3394
|
+
: { hasDiff: first.rows.length > 0, rows: first.rows, diffs: [], summary: { added: first.added, removed: first.removed } };
|
|
3395
|
+
setDiffData(loaded);
|
|
3396
|
+
// The reader opened this file *from* the change list, so the
|
|
3397
|
+
// change is what they came to see; the full text is one press
|
|
3398
|
+
// away and their own choice wins from then on.
|
|
3399
|
+
if (!viewChosen.current && loaded !== null && loaded.hasDiff) {
|
|
3400
|
+
viewChosen.current = true;
|
|
3401
|
+
setDiffMode(true);
|
|
3402
|
+
}
|
|
3403
|
+
}).catch(() => {
|
|
3404
|
+
if (live) setDiffData(null);
|
|
3405
|
+
});
|
|
3373
3406
|
return () => { live = false; };
|
|
3374
3407
|
}
|
|
3375
3408
|
request("diff", { root, path: meta.path }).then((val) => {
|
|
@@ -3378,7 +3411,7 @@ window.__ModuleLoader__.load({
|
|
|
3378
3411
|
if (live) setDiffData(null);
|
|
3379
3412
|
});
|
|
3380
3413
|
return () => { live = false; };
|
|
3381
|
-
}, [root, meta.path, offset, lang, fromCommit, commit, repo]);
|
|
3414
|
+
}, [root, meta.path, offset, lang, fromCommit, commit, repo, meta.diffSha, meta.rowPath, meta.oldPath]);
|
|
3382
3415
|
|
|
3383
3416
|
if (state.status === "error") {
|
|
3384
3417
|
return react.createElement("div", { className: "fv-note fv-error" }, messageOf(state.error));
|
|
@@ -3389,7 +3422,10 @@ window.__ModuleLoader__.load({
|
|
|
3389
3422
|
// A rendered preview needs the whole document. Past the host's preview
|
|
3390
3423
|
// budget only windowed lines arrive, so the source view is all there is.
|
|
3391
3424
|
const canPreview = (data.kind === "markdown" || data.kind === "json") && typeof data.text === "string";
|
|
3392
|
-
const hasDiff = Boolean(diffData && diffData.hasDiff &&
|
|
3425
|
+
const hasDiff = Boolean(diffData && diffData.hasDiff && (
|
|
3426
|
+
(Array.isArray(diffData.rows) && diffData.rows.length > 0)
|
|
3427
|
+
|| (Array.isArray(diffData.diffs) && diffData.diffs.length > 0)
|
|
3428
|
+
));
|
|
3393
3429
|
const diffSummary = diffData && diffData.summary;
|
|
3394
3430
|
const showTabs = canPreview || hasDiff;
|
|
3395
3431
|
|
|
@@ -3465,36 +3501,42 @@ window.__ModuleLoader__.load({
|
|
|
3465
3501
|
// Only the source view scrolls sideways; a rendered preview already
|
|
3466
3502
|
// reflows, so the attribute is pointless there and would just confuse.
|
|
3467
3503
|
const wrapping = wrap && (!canPreview || raw);
|
|
3504
|
+
// Both answers belong to the same question when a file is opened from a
|
|
3505
|
+
// commit: "what changed here" and "what does it contain". The diff leads
|
|
3506
|
+
// in that case, because it is what the reader came for; opening the
|
|
3507
|
+
// working-tree copy keeps the content tab first.
|
|
3508
|
+
const diffTab = hasDiff
|
|
3509
|
+
? react.createElement("button", {
|
|
3510
|
+
key: "diff",
|
|
3511
|
+
type: "button", className: "fv-tab fv-tab-diff", "aria-selected": diffMode ? "true" : "false",
|
|
3512
|
+
onClick: () => { viewChosen.current = true; setDiffMode(true); },
|
|
3513
|
+
},
|
|
3514
|
+
"改动",
|
|
3515
|
+
diffSummary && (diffSummary.added > 0 || diffSummary.removed > 0)
|
|
3516
|
+
? react.createElement("span", { className: "fv-diff-stat" },
|
|
3517
|
+
diffSummary.added > 0 ? react.createElement("span", { className: "fv-diff-add" }, `+${diffSummary.added}`) : null,
|
|
3518
|
+
(diffSummary.added > 0 && diffSummary.removed > 0) ? " " : "",
|
|
3519
|
+
diffSummary.removed > 0 ? react.createElement("span", { className: "fv-diff-del" }, `-${diffSummary.removed}`) : null)
|
|
3520
|
+
: null)
|
|
3521
|
+
: null;
|
|
3522
|
+
const contentTab = react.createElement("button", {
|
|
3523
|
+
key: "content",
|
|
3524
|
+
type: "button", className: "fv-tab", "aria-selected": (!raw && !diffMode) ? "true" : "false",
|
|
3525
|
+
onClick: () => { viewChosen.current = true; setRaw(false); setDiffMode(false); },
|
|
3526
|
+
}, canPreview ? (data.kind === "markdown" ? "预览" : "结构") : (fromCommit ? "完整内容" : "内容"));
|
|
3527
|
+
const sourceTab = canPreview
|
|
3528
|
+
? react.createElement("button", {
|
|
3529
|
+
key: "source",
|
|
3530
|
+
type: "button", className: "fv-tab", "aria-selected": (raw && !diffMode) ? "true" : "false",
|
|
3531
|
+
onClick: () => { viewChosen.current = true; setRaw(true); setDiffMode(false); },
|
|
3532
|
+
}, "源码")
|
|
3533
|
+
: null;
|
|
3534
|
+
|
|
3468
3535
|
const tabs = showTabs
|
|
3469
3536
|
? react.createElement("div", { className: "fv-sheet-tabs", role: "tablist" },
|
|
3470
|
-
|
|
3471
|
-
?
|
|
3472
|
-
|
|
3473
|
-
onClick: () => { setRaw(false); setDiffMode(false); },
|
|
3474
|
-
}, data.kind === "markdown" ? "预览" : "结构")
|
|
3475
|
-
: react.createElement("button", {
|
|
3476
|
-
type: "button", className: "fv-tab", "aria-selected": (!raw && !diffMode) ? "true" : "false",
|
|
3477
|
-
onClick: () => { setRaw(false); setDiffMode(false); },
|
|
3478
|
-
}, "内容"),
|
|
3479
|
-
canPreview
|
|
3480
|
-
? react.createElement("button", {
|
|
3481
|
-
type: "button", className: "fv-tab", "aria-selected": (raw && !diffMode) ? "true" : "false",
|
|
3482
|
-
onClick: () => { setRaw(true); setDiffMode(false); },
|
|
3483
|
-
}, "源码")
|
|
3484
|
-
: null,
|
|
3485
|
-
hasDiff
|
|
3486
|
-
? react.createElement("button", {
|
|
3487
|
-
type: "button", className: "fv-tab fv-tab-diff", "aria-selected": diffMode ? "true" : "false",
|
|
3488
|
-
onClick: () => setDiffMode(true),
|
|
3489
|
-
},
|
|
3490
|
-
"改动",
|
|
3491
|
-
diffSummary && (diffSummary.added > 0 || diffSummary.removed > 0)
|
|
3492
|
-
? react.createElement("span", { className: "fv-diff-stat" },
|
|
3493
|
-
diffSummary.added > 0 ? react.createElement("span", { className: "fv-diff-add" }, `+${diffSummary.added}`) : null,
|
|
3494
|
-
(diffSummary.added > 0 && diffSummary.removed > 0) ? " " : "",
|
|
3495
|
-
diffSummary.removed > 0 ? react.createElement("span", { className: "fv-diff-del" }, `-${diffSummary.removed}`) : null)
|
|
3496
|
-
: null)
|
|
3497
|
-
: null)
|
|
3537
|
+
...(fromCommit && diffTab !== null
|
|
3538
|
+
? [diffTab, contentTab, sourceTab]
|
|
3539
|
+
: [contentTab, sourceTab, diffTab]).filter((tab) => tab !== null))
|
|
3498
3540
|
: null;
|
|
3499
3541
|
return react.createElement(react.Fragment, null,
|
|
3500
3542
|
tabs,
|
|
@@ -4456,6 +4498,13 @@ window.__ModuleLoader__.load({
|
|
|
4456
4498
|
displayPath: baseNameOf(blobPath) + " @ " + readSha.slice(0, 7),
|
|
4457
4499
|
kind: component,
|
|
4458
4500
|
commit: readSha,
|
|
4501
|
+
// Opening a changed file must offer both halves of the question:
|
|
4502
|
+
// what this commit changed in it, and what the file looks like.
|
|
4503
|
+
// `diffSha` is the commit being viewed (the blob may come from
|
|
4504
|
+
// its parent for a deletion), and `oldPath` is what lets the host
|
|
4505
|
+
// keep rename detection intact when filtering the patch.
|
|
4506
|
+
diffSha: sha,
|
|
4507
|
+
oldPath: typeof file.oldPath === "string" && file.oldPath !== "" ? file.oldPath : null,
|
|
4459
4508
|
// The commit records whether the file was added, modified or
|
|
4460
4509
|
// deleted; the preview says so instead of looking like a normal
|
|
4461
4510
|
// working-tree file.
|
package/lib/index.js
CHANGED
|
@@ -1931,11 +1931,24 @@ export async function readGitCommitDiff(ctx, options, payload, signal) {
|
|
|
1931
1931
|
if (wanted === null && typeof payload?.path === 'string' && payload.path !== '') {
|
|
1932
1932
|
throw new ViewerError('outside-root', '该文件不在当前根目录内')
|
|
1933
1933
|
}
|
|
1934
|
+
// A rename has two paths, and filtering by only one of them defeats rename
|
|
1935
|
+
// detection: git then reports the pair as an unrelated delete plus an add
|
|
1936
|
+
// (measured — `-- new-name` prints "new file mode", `-- old-name` prints
|
|
1937
|
+
// "deleted file mode"). Passing both keeps `-M` able to pair them.
|
|
1938
|
+
const wantedOld = typeof payload?.oldPath === 'string' && payload.oldPath !== ''
|
|
1939
|
+
? repoRelativeFromRoot(placement, payload.oldPath)
|
|
1940
|
+
: null
|
|
1941
|
+
if (wantedOld === null && typeof payload?.oldPath === 'string' && payload.oldPath !== '') {
|
|
1942
|
+
throw new ViewerError('outside-root', '该文件不在当前根目录内')
|
|
1943
|
+
}
|
|
1934
1944
|
|
|
1935
1945
|
const base = hasParent
|
|
1936
1946
|
? ['diff', '--no-color', '-M', parentSha, sha]
|
|
1937
1947
|
: ['show', '--no-color', '--format=', '--first-parent', sha]
|
|
1938
|
-
const
|
|
1948
|
+
const paths = wanted === null
|
|
1949
|
+
? []
|
|
1950
|
+
: [...new Set([wanted, ...(wantedOld === null ? [] : [wantedOld])])]
|
|
1951
|
+
const args = paths.length === 0 ? base : [...base, '--', ...paths]
|
|
1939
1952
|
const result = await run(repo.toplevel, args, signal)
|
|
1940
1953
|
if (result?.ok !== true) throw new ViewerError('git-failed', '无法读取该提交的改动内容')
|
|
1941
1954
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weniatall/dsh-file-viewer",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Workspace file viewer and Git panel for DeepSeek Harness: file tree, syntax-highlighted code, images, PDF, Excel and Word, plus local/remote branches, paged commit history, commit diffs, working-tree changes and changed-file navigation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|