@weniatall/dsh-file-viewer 0.3.13 → 0.3.14

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.
Files changed (2) hide show
  1. package/lib/client.js +40 -7
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -3629,15 +3629,50 @@ window.__ModuleLoader__.load({
3629
3629
  : null);
3630
3630
  }
3631
3631
 
3632
+ function isAbsolutePath(p) {
3633
+ if (typeof p !== "string" || p === "") return false;
3634
+ return /^[a-zA-Z]:[\\/]/.test(p) || p.startsWith("/") || p.startsWith("\\\\");
3635
+ }
3636
+
3632
3637
  function resolveAbsPath(rootPath, relPath) {
3633
3638
  if (!rootPath) return relPath || "";
3634
- const cleanRel = (relPath || "").replace(/^[\\/]+/, "");
3639
+ const cleanRel = (relPath || "").replace(/^\.[\\/]+/, "").replace(/^[\\/]+/, "");
3640
+ if (isAbsolutePath(cleanRel)) return cleanRel;
3635
3641
  if (rootPath.includes("\\")) {
3636
3642
  return rootPath.replace(/[\\/]+$/, "") + "\\" + cleanRel.replace(/\//g, "\\");
3637
3643
  }
3638
3644
  return rootPath.replace(/[\\/]+$/, "") + "/" + cleanRel.replace(/\\/g, "/");
3639
3645
  }
3640
3646
 
3647
+ function extractRelativeAndAbsolutePaths(item, rootPath) {
3648
+ if (!item) return { relPath: "", absPath: "" };
3649
+ let rel = item.path || "";
3650
+ if (isAbsolutePath(rel)) {
3651
+ // 如果 path 意外传了绝对路径,且位于 rootPath 之下,提取相对路径
3652
+ const normRoot = rootPath ? rootPath.replace(/\\/g, "/").replace(/\/+$/, "") : "";
3653
+ const normRel = rel.replace(/\\/g, "/");
3654
+ if (normRoot && (normRel.toLowerCase().startsWith(normRoot.toLowerCase() + "/") || normRel.startsWith(normRoot + "/"))) {
3655
+ rel = normRel.slice(normRoot.length + 1);
3656
+ }
3657
+ }
3658
+ if (!rel) {
3659
+ rel = item.name || "";
3660
+ }
3661
+ const cleanRel = String(rel).replace(/^\.[\\/]+/, "").replace(/^[\\/]+/, "");
3662
+
3663
+ // 绝对路径:优先考虑真实宿主路径 displayPath,或由 rootPath 与相对路径拼接
3664
+ let abs = "";
3665
+ if (isAbsolutePath(item.displayPath)) {
3666
+ abs = item.displayPath;
3667
+ } else if (isAbsolutePath(item.path)) {
3668
+ abs = item.path;
3669
+ } else {
3670
+ abs = resolveAbsPath(rootPath, cleanRel);
3671
+ }
3672
+
3673
+ return { relPath: cleanRel, absPath: abs };
3674
+ }
3675
+
3641
3676
  /** Path copy dropdown menu on viewer toolbar. */
3642
3677
  function PathCopyDropdown({ meta, root, onToast }) {
3643
3678
  const [open, setOpen] = react.useState(false);
@@ -3661,10 +3696,9 @@ window.__ModuleLoader__.load({
3661
3696
  };
3662
3697
  }, [open]);
3663
3698
 
3664
- if (!meta || (!meta.path && !meta.displayPath)) return null;
3699
+ if (!meta || (!meta.path && !meta.displayPath && !meta.name)) return null;
3665
3700
 
3666
- const relPath = meta.displayPath || meta.path || "";
3667
- const absPath = resolveAbsPath(root, relPath);
3701
+ const { relPath, absPath } = extractRelativeAndAbsolutePaths(meta, root);
3668
3702
 
3669
3703
  const handleCopy = (e, text, label) => {
3670
3704
  e.preventDefault();
@@ -4693,8 +4727,7 @@ window.__ModuleLoader__.load({
4693
4727
 
4694
4728
  if (!menu) return null;
4695
4729
  const { x, y, entry } = menu;
4696
- const relPath = entry.displayPath || entry.path;
4697
- const absPath = resolveAbsPath(rootPath, relPath);
4730
+ const { relPath, absPath } = extractRelativeAndAbsolutePaths(entry, rootPath);
4698
4731
 
4699
4732
  const handleCopyRel = (e) => {
4700
4733
  e.stopPropagation();
@@ -6736,7 +6769,7 @@ window.__ModuleLoader__.load({
6736
6769
  langOverrideKey, isKnownLanguageId, setLanguageCatalog, getLanguageCatalog: () => languageCatalog, LanguagePicker,
6737
6770
  MARKDOWN_LABELS, MARKDOWN_CODE_LABELS, READ_BLOCK_LABELS, JSON_TREE_LABELS, DIFF_BLOCK_LABELS, ErrorBoundary,
6738
6771
  openViewerForPath, wrapWorkspaceOpenPath, wrapConnectionRpc, wrapChangesOpenFetch, wrapSidebarRight, parseFileResource, setupGlobalFileClickInterceptor, extractClickedPath, normalizeClickedPath, looksLikeFilePath, isFileOpenControl, isFileMentionCode, renderRootOptions,
6739
- triggerDownload, performDownload, isDesktopShell, SvgIconDownload, SvgIconCopy, PathCopyDropdown, resolveAbsPath, SvgIconBranch, SvgIconCommit,
6772
+ triggerDownload, performDownload, isDesktopShell, SvgIconDownload, SvgIconCopy, PathCopyDropdown, resolveAbsPath, extractRelativeAndAbsolutePaths, isAbsolutePath, SvgIconBranch, SvgIconCommit,
6740
6773
  // Git panel: controller, views and the small formatters they share.
6741
6774
  GIT_PAGE_SIZE, createGitController, GitSidebar, CommitDetail, WorkspaceChangeDetail, DiffView, kindOfPath,
6742
6775
  formatCommitDate, formatCommitTimestamp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weniatall/dsh-file-viewer",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
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",