dsh-chat-link-actions 0.2.5 → 0.2.6
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/client.js +43 -12
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -477,6 +477,37 @@ window.__ModuleLoader__.load({
|
|
|
477
477
|
"@keyframes dcla-in{from{opacity:0;transform:translateY(-2px);}to{opacity:1;transform:none;}}"
|
|
478
478
|
].join("");
|
|
479
479
|
|
|
480
|
+
/** 界面语言跟着宿主走:宿主把当前语言写在 <html lang> 上。 */ // ui-copy-ignore
|
|
481
|
+
var TEXT = {
|
|
482
|
+
zh: { // ui-copy-ignore
|
|
483
|
+
menu: "文件操作", // ui-copy-ignore
|
|
484
|
+
quote: "引用到对话", // ui-copy-ignore
|
|
485
|
+
reveal: "在文件管理器中查看", // ui-copy-ignore
|
|
486
|
+
copy: "复制路径", // ui-copy-ignore
|
|
487
|
+
copiedPath: "已复制路径", // ui-copy-ignore
|
|
488
|
+
copiedQuote: "已复制引用", // ui-copy-ignore
|
|
489
|
+
missing: "目标文件不存在", // ui-copy-ignore
|
|
490
|
+
managerFailed: "无法打开文件管理器" // ui-copy-ignore
|
|
491
|
+
},
|
|
492
|
+
en: { // ui-copy-ignore
|
|
493
|
+
menu: "File actions", // ui-copy-ignore
|
|
494
|
+
quote: "Quote in chat", // ui-copy-ignore
|
|
495
|
+
reveal: "Show in file manager", // ui-copy-ignore
|
|
496
|
+
copy: "Copy path", // ui-copy-ignore
|
|
497
|
+
copiedPath: "Path copied", // ui-copy-ignore
|
|
498
|
+
copiedQuote: "Reference copied", // ui-copy-ignore
|
|
499
|
+
missing: "File not found", // ui-copy-ignore
|
|
500
|
+
managerFailed: "Could not open the file manager" // ui-copy-ignore
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
function strings() {
|
|
505
|
+
var element = document.documentElement;
|
|
506
|
+
var lang = element === null ? "" : element.getAttribute("lang");
|
|
507
|
+
var tag = typeof lang === "string" && lang !== "" ? lang : (typeof navigator === "undefined" ? "" : navigator.language);
|
|
508
|
+
return /^zh/i.test(String(tag === null || tag === undefined ? "" : tag)) ? TEXT.zh : TEXT.en;
|
|
509
|
+
}
|
|
510
|
+
|
|
480
511
|
function ensureStyle() {
|
|
481
512
|
if (document.getElementById(STYLE_ID) !== null) return;
|
|
482
513
|
var style = document.createElement("style");
|
|
@@ -599,7 +630,7 @@ window.__ModuleLoader__.load({
|
|
|
599
630
|
var panel = document.createElement("div");
|
|
600
631
|
panel.className = "dcla-menu";
|
|
601
632
|
panel.setAttribute("role", "menu");
|
|
602
|
-
panel.setAttribute("aria-label",
|
|
633
|
+
panel.setAttribute("aria-label", strings().menu);
|
|
603
634
|
|
|
604
635
|
var caption = document.createElement("div");
|
|
605
636
|
caption.className = "dcla-path";
|
|
@@ -651,23 +682,23 @@ window.__ModuleLoader__.load({
|
|
|
651
682
|
var settings = options === null || options === undefined ? {} : options;
|
|
652
683
|
|
|
653
684
|
var items = [
|
|
654
|
-
{ id: "quote", label:
|
|
685
|
+
{ id: "quote", label: strings().quote, icon: "quote", run: function () {
|
|
655
686
|
probePath(path, function (kind) {
|
|
656
687
|
var directory = kind === "directory" ? true : kind === "file" ? false : settings.directory;
|
|
657
688
|
if (directory === undefined && kind !== "file" && kind !== "directory") directory = guessDirectory(path);
|
|
658
689
|
var inserted = quoteIntoComposer(path, directory);
|
|
659
690
|
if (inserted) return;
|
|
660
691
|
navigator.clipboard.writeText(referenceText(path)).then(function () {
|
|
661
|
-
toast(
|
|
692
|
+
toast(strings().copiedQuote);
|
|
662
693
|
}, function () {});
|
|
663
694
|
});
|
|
664
695
|
} },
|
|
665
|
-
{ id: "reveal", label:
|
|
696
|
+
{ id: "reveal", label: strings().reveal, icon: "reveal", run: function () {
|
|
666
697
|
reveal(path);
|
|
667
698
|
} },
|
|
668
|
-
{ id: "copy", label:
|
|
699
|
+
{ id: "copy", label: strings().copy, icon: "copy", run: function () {
|
|
669
700
|
navigator.clipboard.writeText(path).then(function () {
|
|
670
|
-
toast(
|
|
701
|
+
toast(strings().copiedPath);
|
|
671
702
|
}, function () {});
|
|
672
703
|
} }
|
|
673
704
|
];
|
|
@@ -837,7 +868,7 @@ window.__ModuleLoader__.load({
|
|
|
837
868
|
function reveal(path) {
|
|
838
869
|
probePath(path, function (kind) {
|
|
839
870
|
if (kind === "missing") {
|
|
840
|
-
toast(
|
|
871
|
+
toast(strings().missing);
|
|
841
872
|
return;
|
|
842
873
|
}
|
|
843
874
|
revealViaRoute(path);
|
|
@@ -849,7 +880,7 @@ window.__ModuleLoader__.load({
|
|
|
849
880
|
fetch("/chat-link-actions?action=reveal&path=" + encodeURIComponent(path), { method: "POST" }).then(function (response) {
|
|
850
881
|
if (response.ok) return;
|
|
851
882
|
if (response.status === 404) {
|
|
852
|
-
toast(
|
|
883
|
+
toast(strings().missing);
|
|
853
884
|
return;
|
|
854
885
|
}
|
|
855
886
|
revealRemote(path);
|
|
@@ -863,18 +894,18 @@ window.__ModuleLoader__.load({
|
|
|
863
894
|
var remote = sessionRemote();
|
|
864
895
|
var session = remote === null ? null : remote.session;
|
|
865
896
|
if (session === null || session === undefined || typeof session.openWorkspacePath !== "function") {
|
|
866
|
-
toast(
|
|
897
|
+
toast(strings().managerFailed);
|
|
867
898
|
return;
|
|
868
899
|
}
|
|
869
900
|
try {
|
|
870
901
|
session.openWorkspacePath({ path: path, action: "reveal" }).then(function (result) {
|
|
871
902
|
if (result !== null && result !== undefined && result.ok === true) return;
|
|
872
|
-
toast(isUnreachablePath(result === null || result === undefined ? null : result.error) ?
|
|
903
|
+
toast(isUnreachablePath(result === null || result === undefined ? null : result.error) ? strings().missing : strings().managerFailed);
|
|
873
904
|
}, function (error) {
|
|
874
|
-
toast(isUnreachablePath(error) ?
|
|
905
|
+
toast(isUnreachablePath(error) ? strings().missing : strings().managerFailed);
|
|
875
906
|
});
|
|
876
907
|
} catch (error) {
|
|
877
|
-
toast(
|
|
908
|
+
toast(strings().managerFailed);
|
|
878
909
|
}
|
|
879
910
|
}
|
|
880
911
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-chat-link-actions",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Right-click actions on file links in the DSH transcript: quote the path into the composer, or reveal the file in the OS file manager. Menus are drawn in the app's own style, never the system one.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|