@artenx/dshb 0.1.55 → 0.1.57
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/lib/client.js +497 -6
- package/lib/client.js.map +1 -1
- package/lib/core/index.js +9 -2
- package/lib/core/index.js.map +1 -1
- package/lib/core/routes.js +4 -0
- package/lib/core/routes.js.map +1 -1
- package/lib/core/sync/coordinator.js +54 -26
- package/lib/core/sync/coordinator.js.map +1 -1
- package/lib/core/sync/internal-routes.js +36 -5
- package/lib/core/sync/internal-routes.js.map +1 -1
- package/lib/core/sync/node-sync.js +2 -4
- package/lib/core/sync/node-sync.js.map +1 -1
- package/lib/core/sync/offline-archive.js +1 -1
- package/lib/core/sync/offline-routes.js +1 -1
- package/lib/core/sync/remote-helper.js +6 -4
- package/lib/core/sync/remote-helper.js.map +1 -1
- package/lib/core/sync/session-open-routes.js +1 -1
- package/lib/core/sync/session-routes.js +1 -1
- package/lib/core/sync/session-sync.js +1 -1
- package/lib/core/workspace-bindings.js +62 -24
- package/lib/core/workspace-bindings.js.map +1 -1
- package/lib/{session-sync-Bsv3Qnof.js → session-sync-DrilvkP1.js} +16 -3
- package/lib/{session-sync-Bsv3Qnof.js.map → session-sync-DrilvkP1.js.map} +1 -1
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -622,6 +622,7 @@ window.__ModuleLoader__.load({
|
|
|
622
622
|
return;
|
|
623
623
|
}
|
|
624
624
|
pickedPath = data.mirrorPath;
|
|
625
|
+
window.dispatchEvent(new Event("dshb:workspace-bindings-changed"));
|
|
625
626
|
}
|
|
626
627
|
props.onPicked(pickedPath);
|
|
627
628
|
if (pendingInstruction !== void 0 && pendingInstruction.trim()) savePendingInstruction(pickedPath, pendingInstruction);
|
|
@@ -2006,6 +2007,114 @@ window.__ModuleLoader__.load({
|
|
|
2006
2007
|
}, DrawerToggle));
|
|
2007
2008
|
}
|
|
2008
2009
|
//#endregion
|
|
2010
|
+
//#region src/client/menu-position.ts
|
|
2011
|
+
function shouldForceMenuPosition(side, supportsAnchorPositioning) {
|
|
2012
|
+
return !supportsAnchorPositioning || side === "top";
|
|
2013
|
+
}
|
|
2014
|
+
function computeMenuPosition(anchor, menu, side, align, viewport, gap = 8, margin = 8) {
|
|
2015
|
+
let left = anchor.left;
|
|
2016
|
+
let top = anchor.top;
|
|
2017
|
+
if (side === "top" || side === "bottom") {
|
|
2018
|
+
top = side === "top" ? anchor.top - menu.height - gap : anchor.bottom + gap;
|
|
2019
|
+
left = align === "end" ? anchor.right - menu.width : align === "center" ? anchor.left + (anchor.width - menu.width) / 2 : anchor.left;
|
|
2020
|
+
if (top < margin) top = anchor.bottom + gap;
|
|
2021
|
+
if (top + menu.height > viewport.height - margin) top = anchor.top - menu.height - gap;
|
|
2022
|
+
} else {
|
|
2023
|
+
left = side === "left" ? anchor.left - menu.width - gap : anchor.right + gap;
|
|
2024
|
+
top = align === "end" ? anchor.bottom - menu.height : align === "center" ? anchor.top + (anchor.height - menu.height) / 2 : anchor.top;
|
|
2025
|
+
if (left < margin) left = anchor.right + gap;
|
|
2026
|
+
if (left + menu.width > viewport.width - margin) left = anchor.left - menu.width - gap;
|
|
2027
|
+
}
|
|
2028
|
+
return {
|
|
2029
|
+
left: Math.max(margin, Math.min(left, viewport.width - menu.width - margin)),
|
|
2030
|
+
top: Math.max(margin, Math.min(top, viewport.height - menu.height - margin))
|
|
2031
|
+
};
|
|
2032
|
+
}
|
|
2033
|
+
//#endregion
|
|
2034
|
+
//#region src/client/menu-anchor-fallback.ts
|
|
2035
|
+
const POSITIONED_ATTRIBUTE = "data-dshb-menu-positioned";
|
|
2036
|
+
function supportsAnchorPositioning() {
|
|
2037
|
+
return typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("anchor-name: --dshb-test") && CSS.supports("position-anchor: --dshb-test") && CSS.supports("top: anchor(top)");
|
|
2038
|
+
}
|
|
2039
|
+
function toRect(element) {
|
|
2040
|
+
const rect = element.getBoundingClientRect();
|
|
2041
|
+
return {
|
|
2042
|
+
top: rect.top,
|
|
2043
|
+
bottom: rect.bottom,
|
|
2044
|
+
left: rect.left,
|
|
2045
|
+
right: rect.right,
|
|
2046
|
+
width: rect.width,
|
|
2047
|
+
height: rect.height
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
function installMenuAnchorFallback() {
|
|
2051
|
+
const anchorPositioningSupported = supportsAnchorPositioning();
|
|
2052
|
+
const anchors = /* @__PURE__ */ new WeakMap();
|
|
2053
|
+
let raf = 0;
|
|
2054
|
+
const findAnchor = (menu) => {
|
|
2055
|
+
const cached = anchors.get(menu);
|
|
2056
|
+
if (cached?.isConnected) return cached;
|
|
2057
|
+
const name = menu.style.getPropertyValue("position-anchor").trim();
|
|
2058
|
+
if (!name) return void 0;
|
|
2059
|
+
for (const element of Array.from(document.querySelectorAll("[style]"))) {
|
|
2060
|
+
if (element.style.getPropertyValue("anchor-name").trim() !== name) continue;
|
|
2061
|
+
anchors.set(menu, element);
|
|
2062
|
+
return element;
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
2065
|
+
const positionMenu = (menu) => {
|
|
2066
|
+
if (menu.getAttribute("aria-hidden") === "true") return;
|
|
2067
|
+
const anchor = findAnchor(menu);
|
|
2068
|
+
if (!anchor) return;
|
|
2069
|
+
const target = anchor.matches("button") ? anchor : anchor.querySelector("button") ?? anchor;
|
|
2070
|
+
const side = menu.dataset.anchorSide ?? "bottom";
|
|
2071
|
+
const align = menu.dataset.anchorAlign ?? "start";
|
|
2072
|
+
const position = computeMenuPosition(toRect(target), toRect(menu), side, align, {
|
|
2073
|
+
width: window.innerWidth,
|
|
2074
|
+
height: window.innerHeight
|
|
2075
|
+
});
|
|
2076
|
+
menu.style.position = "fixed";
|
|
2077
|
+
menu.style.left = `${position.left}px`;
|
|
2078
|
+
menu.style.top = `${position.top}px`;
|
|
2079
|
+
menu.style.setProperty("position-anchor", "none");
|
|
2080
|
+
menu.setAttribute(POSITIONED_ATTRIBUTE, "");
|
|
2081
|
+
};
|
|
2082
|
+
const positionAll = () => {
|
|
2083
|
+
for (const menu of Array.from(document.querySelectorAll("[role=\"menu\"][data-anchor-side]"))) {
|
|
2084
|
+
if (!shouldForceMenuPosition(menu.dataset.anchorSide ?? "bottom", anchorPositioningSupported)) continue;
|
|
2085
|
+
positionMenu(menu);
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
const schedule = () => {
|
|
2089
|
+
if (raf !== 0) return;
|
|
2090
|
+
raf = requestAnimationFrame(() => {
|
|
2091
|
+
raf = 0;
|
|
2092
|
+
positionAll();
|
|
2093
|
+
});
|
|
2094
|
+
};
|
|
2095
|
+
const observer = new MutationObserver(schedule);
|
|
2096
|
+
observer.observe(document.body, {
|
|
2097
|
+
childList: true,
|
|
2098
|
+
subtree: true
|
|
2099
|
+
});
|
|
2100
|
+
window.addEventListener("scroll", schedule, true);
|
|
2101
|
+
window.addEventListener("resize", schedule);
|
|
2102
|
+
schedule();
|
|
2103
|
+
return () => {
|
|
2104
|
+
observer.disconnect();
|
|
2105
|
+
if (raf !== 0) cancelAnimationFrame(raf);
|
|
2106
|
+
window.removeEventListener("scroll", schedule, true);
|
|
2107
|
+
window.removeEventListener("resize", schedule);
|
|
2108
|
+
for (const menu of Array.from(document.querySelectorAll(`[${POSITIONED_ATTRIBUTE}]`))) {
|
|
2109
|
+
menu.style.removeProperty("position");
|
|
2110
|
+
menu.style.removeProperty("left");
|
|
2111
|
+
menu.style.removeProperty("top");
|
|
2112
|
+
menu.style.removeProperty("position-anchor");
|
|
2113
|
+
menu.removeAttribute(POSITIONED_ATTRIBUTE);
|
|
2114
|
+
}
|
|
2115
|
+
};
|
|
2116
|
+
}
|
|
2117
|
+
//#endregion
|
|
2009
2118
|
//#region src/client/workspace-instruction-menu.tsx
|
|
2010
2119
|
let injectedRegistry;
|
|
2011
2120
|
function setWorkspaceRegistry(reg) {
|
|
@@ -2385,6 +2494,11 @@ window.__ModuleLoader__.load({
|
|
|
2385
2494
|
}, RemoteSessionRowAction));
|
|
2386
2495
|
}
|
|
2387
2496
|
//#endregion
|
|
2497
|
+
//#region src/client/remote-catalog-model.ts
|
|
2498
|
+
function eligibleRemoteCatalogPeers(peers) {
|
|
2499
|
+
return peers.filter((peer) => peer.enabled && !(peer.mode === "full" && peer.syncSessions));
|
|
2500
|
+
}
|
|
2501
|
+
//#endregion
|
|
2388
2502
|
//#region src/client/remote-catalog.tsx
|
|
2389
2503
|
function formatSize(bytes) {
|
|
2390
2504
|
if (bytes === void 0 || !Number.isFinite(bytes)) return "";
|
|
@@ -2583,9 +2697,19 @@ window.__ModuleLoader__.load({
|
|
|
2583
2697
|
if (body?.peers) setPeers(body.peers);
|
|
2584
2698
|
} catch {}
|
|
2585
2699
|
}, []);
|
|
2700
|
+
(0, react.useEffect)(() => {
|
|
2701
|
+
loadPeers();
|
|
2702
|
+
const onPeersChanged = () => {
|
|
2703
|
+
loadPeers();
|
|
2704
|
+
};
|
|
2705
|
+
window.addEventListener("dshb:sync-peers-changed", onPeersChanged);
|
|
2706
|
+
return () => window.removeEventListener("dshb:sync-peers-changed", onPeersChanged);
|
|
2707
|
+
}, [loadPeers]);
|
|
2586
2708
|
(0, react.useEffect)(() => {
|
|
2587
2709
|
if (open) loadPeers();
|
|
2588
2710
|
}, [open, loadPeers]);
|
|
2711
|
+
const eligiblePeers = eligibleRemoteCatalogPeers(peers);
|
|
2712
|
+
if (eligiblePeers.length === 0) return null;
|
|
2589
2713
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2590
2714
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: REMOTE_CATALOG_PANEL_STYLE }),
|
|
2591
2715
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
@@ -2615,7 +2739,7 @@ window.__ModuleLoader__.load({
|
|
|
2615
2739
|
})
|
|
2616
2740
|
}),
|
|
2617
2741
|
open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CatalogPanel, {
|
|
2618
|
-
peers,
|
|
2742
|
+
peers: eligiblePeers,
|
|
2619
2743
|
onClose: () => setOpen(false)
|
|
2620
2744
|
}) : null
|
|
2621
2745
|
] });
|
|
@@ -2637,7 +2761,7 @@ window.__ModuleLoader__.load({
|
|
|
2637
2761
|
function wsKey(origin) {
|
|
2638
2762
|
return origin ? `${origin.originInstanceId}/${origin.originEntityId}` : "";
|
|
2639
2763
|
}
|
|
2640
|
-
async function fetchJson(url, init) {
|
|
2764
|
+
async function fetchJson$1(url, init) {
|
|
2641
2765
|
const res = await fetch(url, {
|
|
2642
2766
|
cache: "no-store",
|
|
2643
2767
|
...init
|
|
@@ -2790,7 +2914,7 @@ window.__ModuleLoader__.load({
|
|
|
2790
2914
|
const dismiss = showToast("正在导入远端会话…");
|
|
2791
2915
|
(async () => {
|
|
2792
2916
|
try {
|
|
2793
|
-
const result = await fetchJson("/api/dshb/sync/open-session", {
|
|
2917
|
+
const result = await fetchJson$1("/api/dshb/sync/open-session", {
|
|
2794
2918
|
method: "POST",
|
|
2795
2919
|
headers: { "content-type": "application/json" },
|
|
2796
2920
|
body: JSON.stringify({
|
|
@@ -2827,11 +2951,11 @@ window.__ModuleLoader__.load({
|
|
|
2827
2951
|
};
|
|
2828
2952
|
const load = async () => {
|
|
2829
2953
|
try {
|
|
2830
|
-
const { peers } = await fetchJson("/api/dshb/sync/peers");
|
|
2954
|
+
const { peers } = await fetchJson$1("/api/dshb/sync/peers");
|
|
2831
2955
|
const targets = (peers ?? []).filter((p) => p.enabled && !(p.mode === "full" && p.syncSessions));
|
|
2832
2956
|
const result = await Promise.all(targets.map(async (peer) => {
|
|
2833
2957
|
try {
|
|
2834
|
-
const { catalog } = await fetchJson(`/api/dshb/sync/peers/${encodeURIComponent(peer.id)}/catalog`);
|
|
2958
|
+
const { catalog } = await fetchJson$1(`/api/dshb/sync/peers/${encodeURIComponent(peer.id)}/catalog`);
|
|
2835
2959
|
return {
|
|
2836
2960
|
peer,
|
|
2837
2961
|
catalog
|
|
@@ -2901,6 +3025,368 @@ window.__ModuleLoader__.load({
|
|
|
2901
3025
|
};
|
|
2902
3026
|
}
|
|
2903
3027
|
//#endregion
|
|
3028
|
+
//#region src/client/workspace-node-badge-model.ts
|
|
3029
|
+
function normalizeWorkspacePath(path) {
|
|
3030
|
+
const collapsed = path.replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
3031
|
+
const trimmed = collapsed.length > 1 ? collapsed.replace(/\/+$/, "") : collapsed;
|
|
3032
|
+
return /^[A-Za-z]:/.test(trimmed) ? trimmed[0].toLowerCase() + trimmed.slice(1) : trimmed;
|
|
3033
|
+
}
|
|
3034
|
+
function nodeTypeLabel(type) {
|
|
3035
|
+
switch (type) {
|
|
3036
|
+
case "local-host": return "本地宿主";
|
|
3037
|
+
case "local-docker": return "本地 Docker";
|
|
3038
|
+
case "remote-ssh": return "远程 SSH";
|
|
3039
|
+
case "remote-docker": return "远程 Docker";
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
function nodeStatusLabel(node) {
|
|
3043
|
+
if (node.sync?.pendingRemoval) return "待删除";
|
|
3044
|
+
if (node.sync?.credentialsRequired) return "凭据不足";
|
|
3045
|
+
if (node.provision?.state === "failed") return "供给失败";
|
|
3046
|
+
if (node.provision?.state === "provisioning") return "供给中";
|
|
3047
|
+
if (node.status?.reachable === true) return "在线";
|
|
3048
|
+
if (node.status?.reachable === false) return "离线";
|
|
3049
|
+
return "未知";
|
|
3050
|
+
}
|
|
3051
|
+
function nodeBadgeTone(node) {
|
|
3052
|
+
if (node.sync?.pendingRemoval || node.sync?.credentialsRequired) return "warning";
|
|
3053
|
+
if (node.provision?.state === "failed" || node.status?.reachable === false) return "error";
|
|
3054
|
+
if (node.provision?.state === "provisioning" || node.status?.reachable === void 0) return "muted";
|
|
3055
|
+
return "normal";
|
|
3056
|
+
}
|
|
3057
|
+
function resolveWorkspaceNodeBadge(workspace, bindings, nodes) {
|
|
3058
|
+
const idMatches = workspace.workspaceId ? bindings.filter((binding) => binding.workspaceId === workspace.workspaceId) : [];
|
|
3059
|
+
const pathMatches = workspace.path ? bindings.filter((binding) => normalizeWorkspacePath(binding.mirrorPath) === normalizeWorkspacePath(workspace.path)) : [];
|
|
3060
|
+
const matches = idMatches.length > 0 ? idMatches : pathMatches;
|
|
3061
|
+
if (matches.length === 0) return { kind: "unbound" };
|
|
3062
|
+
if (matches.length > 1) return {
|
|
3063
|
+
kind: "conflict",
|
|
3064
|
+
bindings: matches.map((binding) => ({ ...binding })),
|
|
3065
|
+
nodes: matches.flatMap((binding) => {
|
|
3066
|
+
const node = nodes.find((candidate) => candidate.id === binding.nodeId);
|
|
3067
|
+
return node ? [node] : [];
|
|
3068
|
+
})
|
|
3069
|
+
};
|
|
3070
|
+
const binding = matches[0];
|
|
3071
|
+
const node = nodes.find((candidate) => candidate.id === binding.nodeId);
|
|
3072
|
+
return node ? {
|
|
3073
|
+
kind: "bound",
|
|
3074
|
+
node,
|
|
3075
|
+
binding: { ...binding }
|
|
3076
|
+
} : {
|
|
3077
|
+
kind: "missing-node",
|
|
3078
|
+
nodeId: binding.nodeId,
|
|
3079
|
+
binding: { ...binding }
|
|
3080
|
+
};
|
|
3081
|
+
}
|
|
3082
|
+
function nodeBadgeDetails(state) {
|
|
3083
|
+
if (state.kind === "unbound") return "";
|
|
3084
|
+
if (state.kind === "missing-node") return [
|
|
3085
|
+
"节点已失效",
|
|
3086
|
+
`节点 ID:${state.nodeId}`,
|
|
3087
|
+
`远端路径:${state.binding.remotePath}`
|
|
3088
|
+
].join("\n");
|
|
3089
|
+
if (state.kind === "conflict") {
|
|
3090
|
+
const lines = ["绑定冲突", `匹配到 ${state.bindings.length} 条绑定`];
|
|
3091
|
+
state.bindings.forEach((binding, index) => {
|
|
3092
|
+
const node = state.nodes.find((candidate) => candidate.id === binding.nodeId);
|
|
3093
|
+
lines.push(`${index + 1}. ${node?.name ?? binding.nodeId} · ${binding.remotePath}`);
|
|
3094
|
+
});
|
|
3095
|
+
return lines.join("\n");
|
|
3096
|
+
}
|
|
3097
|
+
const lines = [
|
|
3098
|
+
state.node.name,
|
|
3099
|
+
`${nodeTypeLabel(state.node.type)} · ${nodeStatusLabel(state.node)}`,
|
|
3100
|
+
`远端路径:${state.binding.remotePath}`
|
|
3101
|
+
];
|
|
3102
|
+
if (state.node.sync?.sourceName) lines.push(`来源:${state.node.sync.sourceName}`);
|
|
3103
|
+
if (state.node.status?.error) lines.push(`状态说明:${state.node.status.error}`);
|
|
3104
|
+
return lines.join("\n");
|
|
3105
|
+
}
|
|
3106
|
+
//#endregion
|
|
3107
|
+
//#region src/client/workspace-node-badge.ts
|
|
3108
|
+
const BADGE_ATTRIBUTE = "data-dshb-workspace-node-badge";
|
|
3109
|
+
const SIGNATURE_ATTRIBUTE = "data-dshb-workspace-node-badge-signature";
|
|
3110
|
+
const TOOLTIP_ID = "dshb-workspace-node-tooltip";
|
|
3111
|
+
const NODE_ICON = "<svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.35\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M4.5 12.5h7a2.5 2.5 0 0 0 .35-4.97A4 4 0 0 0 4.2 6.6 3 3 0 0 0 4.5 12.5Z\" fill=\"currentColor\" fill-opacity=\".18\"/></svg>";
|
|
3112
|
+
const WARNING_ICON = "<svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M8 2.75 14.25 13H1.75L8 2.75Z\"/><path d=\"M8 6.25v3.25M8 11.5v.25\"/></svg>";
|
|
3113
|
+
function ensureStyle() {
|
|
3114
|
+
const existing = document.querySelector("style[data-dshb-workspace-node-badge-style]");
|
|
3115
|
+
if (existing) return existing;
|
|
3116
|
+
const style = document.createElement("style");
|
|
3117
|
+
style.dataset.dshbWorkspaceNodeBadgeStyle = "";
|
|
3118
|
+
style.textContent = `
|
|
3119
|
+
.dshb-workspace-node-badge{--dshb-node-accent:var(--dsw-alias-label-secondary);display:inline-flex;align-items:center;justify-content:center;flex:none;width:16px;height:16px;padding:0;border:0;background:transparent;color:var(--dshb-node-accent);cursor:default;user-select:none;vertical-align:middle;opacity:.9;transition:opacity .12s ease}
|
|
3120
|
+
.dshb-workspace-node-badge[data-node-type="local-host"]{--dshb-node-accent:var(--dsw-alias-label-tertiary)}
|
|
3121
|
+
.dshb-workspace-node-badge[data-node-type="local-docker"]{--dshb-node-accent:var(--dsw-alias-state-business-primary)}
|
|
3122
|
+
.dshb-workspace-node-badge[data-node-type="remote-ssh"]{--dshb-node-accent:var(--dsw-alias-state-success-primary)}
|
|
3123
|
+
.dshb-workspace-node-badge[data-node-type="remote-docker"]{--dshb-node-accent:var(--dsw-alias-brand-primary,var(--dsw-alias-state-business-primary))}
|
|
3124
|
+
.dshb-workspace-node-badge svg{width:15px;height:15px;flex:none}
|
|
3125
|
+
.dshb-workspace-node-badge:hover{opacity:1}
|
|
3126
|
+
.dshb-workspace-node-badge[data-tone="muted"]{--dshb-node-accent:var(--dsw-alias-label-tertiary)}
|
|
3127
|
+
.dshb-workspace-node-badge[data-tone="warning"]{--dshb-node-accent:var(--dsw-alias-state-warn-label)}
|
|
3128
|
+
.dshb-workspace-node-badge[data-tone="error"]{--dshb-node-accent:var(--dsw-alias-state-error-primary)}
|
|
3129
|
+
.dshb-workspace-node-badge:focus-visible{outline:2px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px;border-radius:4px}
|
|
3130
|
+
.dshb-workspace-node-tooltip{position:fixed;z-index:1200;display:none;max-width:min(320px,calc(100vw - 16px));padding:8px 10px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);box-shadow:0 4px 16px rgba(0,0,0,.28);font-size:12px;line-height:1.5;white-space:pre-line;pointer-events:none}
|
|
3131
|
+
.dshb-workspace-node-tooltip[aria-hidden="false"]{display:block}
|
|
3132
|
+
`;
|
|
3133
|
+
document.head.appendChild(style);
|
|
3134
|
+
return style;
|
|
3135
|
+
}
|
|
3136
|
+
async function fetchJson(url) {
|
|
3137
|
+
try {
|
|
3138
|
+
const response = await fetch(url, { cache: "no-store" });
|
|
3139
|
+
if (!response.ok) return void 0;
|
|
3140
|
+
return await response.json();
|
|
3141
|
+
} catch {
|
|
3142
|
+
return;
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
function isNode(value) {
|
|
3146
|
+
if (value === null || typeof value !== "object") return false;
|
|
3147
|
+
const node = value;
|
|
3148
|
+
return typeof node.id === "string" && typeof node.name === "string" && (node.type === "local-host" || node.type === "local-docker" || node.type === "remote-ssh" || node.type === "remote-docker");
|
|
3149
|
+
}
|
|
3150
|
+
function isBinding(value) {
|
|
3151
|
+
if (value === null || typeof value !== "object") return false;
|
|
3152
|
+
const binding = value;
|
|
3153
|
+
return typeof binding.mirrorPath === "string" && typeof binding.nodeId === "string" && typeof binding.remotePath === "string" && (binding.workspaceId === void 0 || typeof binding.workspaceId === "string");
|
|
3154
|
+
}
|
|
3155
|
+
function badgeTone(state) {
|
|
3156
|
+
if (state.kind === "bound") return nodeBadgeTone(state.node);
|
|
3157
|
+
if (state.kind === "conflict") return "warning";
|
|
3158
|
+
if (state.kind === "missing-node") return "error";
|
|
3159
|
+
return "muted";
|
|
3160
|
+
}
|
|
3161
|
+
function badgeContent(state) {
|
|
3162
|
+
if (state.kind === "bound") return {
|
|
3163
|
+
icon: NODE_ICON,
|
|
3164
|
+
label: ""
|
|
3165
|
+
};
|
|
3166
|
+
if (state.kind === "missing-node") return {
|
|
3167
|
+
icon: WARNING_ICON,
|
|
3168
|
+
label: ""
|
|
3169
|
+
};
|
|
3170
|
+
if (state.kind === "conflict") return {
|
|
3171
|
+
icon: WARNING_ICON,
|
|
3172
|
+
label: ""
|
|
3173
|
+
};
|
|
3174
|
+
return {
|
|
3175
|
+
icon: "",
|
|
3176
|
+
label: ""
|
|
3177
|
+
};
|
|
3178
|
+
}
|
|
3179
|
+
function badgeSignature(state) {
|
|
3180
|
+
if (state.kind === "unbound") return "unbound";
|
|
3181
|
+
if (state.kind === "missing-node") return JSON.stringify([
|
|
3182
|
+
"missing-node",
|
|
3183
|
+
state.nodeId,
|
|
3184
|
+
state.binding.mirrorPath,
|
|
3185
|
+
state.binding.remotePath
|
|
3186
|
+
]);
|
|
3187
|
+
if (state.kind === "conflict") return JSON.stringify([
|
|
3188
|
+
"conflict",
|
|
3189
|
+
state.bindings.map((binding) => [
|
|
3190
|
+
binding.nodeId,
|
|
3191
|
+
binding.mirrorPath,
|
|
3192
|
+
binding.remotePath,
|
|
3193
|
+
binding.workspaceId
|
|
3194
|
+
]),
|
|
3195
|
+
state.nodes.map((node) => [node.id, node.name])
|
|
3196
|
+
]);
|
|
3197
|
+
return JSON.stringify([
|
|
3198
|
+
"bound",
|
|
3199
|
+
state.node.id,
|
|
3200
|
+
state.node.name,
|
|
3201
|
+
state.node.type,
|
|
3202
|
+
state.node.status?.reachable,
|
|
3203
|
+
state.node.status?.error,
|
|
3204
|
+
state.node.sync?.pendingRemoval,
|
|
3205
|
+
state.node.sync?.credentialsRequired,
|
|
3206
|
+
state.node.sync?.sourceName,
|
|
3207
|
+
state.node.provision?.state,
|
|
3208
|
+
state.node.provision?.error,
|
|
3209
|
+
state.binding.mirrorPath,
|
|
3210
|
+
state.binding.remotePath,
|
|
3211
|
+
state.binding.workspaceId
|
|
3212
|
+
]);
|
|
3213
|
+
}
|
|
3214
|
+
function installWorkspaceNodeBadges(ctx) {
|
|
3215
|
+
let disposed = false;
|
|
3216
|
+
let loaded = false;
|
|
3217
|
+
let nodes = [];
|
|
3218
|
+
let bindings = [];
|
|
3219
|
+
let refreshToken = 0;
|
|
3220
|
+
let raf = 0;
|
|
3221
|
+
let tooltip;
|
|
3222
|
+
let activeBadge;
|
|
3223
|
+
const style = ensureStyle();
|
|
3224
|
+
const workspaces = ctx.workspaces;
|
|
3225
|
+
const hideTooltip = () => {
|
|
3226
|
+
activeBadge?.removeAttribute("aria-describedby");
|
|
3227
|
+
tooltip?.setAttribute("aria-hidden", "true");
|
|
3228
|
+
activeBadge = void 0;
|
|
3229
|
+
};
|
|
3230
|
+
const positionTooltip = () => {
|
|
3231
|
+
if (!tooltip || !activeBadge) return;
|
|
3232
|
+
const anchor = activeBadge.getBoundingClientRect();
|
|
3233
|
+
const tip = tooltip.getBoundingClientRect();
|
|
3234
|
+
const margin = 8;
|
|
3235
|
+
let top = anchor.bottom + 6;
|
|
3236
|
+
if (top + tip.height > window.innerHeight - margin) top = anchor.top - tip.height - 6;
|
|
3237
|
+
if (top < margin) top = anchor.bottom + 6;
|
|
3238
|
+
const left = Math.max(margin, Math.min(anchor.left, window.innerWidth - tip.width - margin));
|
|
3239
|
+
tooltip.style.left = `${left}px`;
|
|
3240
|
+
tooltip.style.top = `${top}px`;
|
|
3241
|
+
};
|
|
3242
|
+
const showTooltip = (badge, text) => {
|
|
3243
|
+
if (!text) return;
|
|
3244
|
+
if (!tooltip) {
|
|
3245
|
+
tooltip = document.createElement("div");
|
|
3246
|
+
tooltip.id = TOOLTIP_ID;
|
|
3247
|
+
tooltip.className = "dshb-workspace-node-tooltip";
|
|
3248
|
+
tooltip.setAttribute("role", "tooltip");
|
|
3249
|
+
tooltip.setAttribute("aria-hidden", "true");
|
|
3250
|
+
document.body.appendChild(tooltip);
|
|
3251
|
+
}
|
|
3252
|
+
activeBadge = badge;
|
|
3253
|
+
tooltip.textContent = text;
|
|
3254
|
+
tooltip.setAttribute("aria-hidden", "false");
|
|
3255
|
+
badge.setAttribute("aria-describedby", TOOLTIP_ID);
|
|
3256
|
+
positionTooltip();
|
|
3257
|
+
};
|
|
3258
|
+
const applyRowBadge = (row, state) => {
|
|
3259
|
+
const existing = row.querySelector(`:scope > [${BADGE_ATTRIBUTE}]`);
|
|
3260
|
+
if (state.kind === "unbound") {
|
|
3261
|
+
if (existing && activeBadge === existing) hideTooltip();
|
|
3262
|
+
existing?.remove();
|
|
3263
|
+
row.removeAttribute(SIGNATURE_ATTRIBUTE);
|
|
3264
|
+
return;
|
|
3265
|
+
}
|
|
3266
|
+
const signature = badgeSignature(state);
|
|
3267
|
+
if (existing && row.getAttribute(SIGNATURE_ATTRIBUTE) === signature) return;
|
|
3268
|
+
const anchor = row.querySelector("[class*=\"projectText\"]");
|
|
3269
|
+
if (!anchor || anchor.parentElement !== row) {
|
|
3270
|
+
if (existing && activeBadge === existing) hideTooltip();
|
|
3271
|
+
existing?.remove();
|
|
3272
|
+
row.removeAttribute(SIGNATURE_ATTRIBUTE);
|
|
3273
|
+
return;
|
|
3274
|
+
}
|
|
3275
|
+
const hadFocus = existing === document.activeElement;
|
|
3276
|
+
if (existing && activeBadge === existing) hideTooltip();
|
|
3277
|
+
existing?.remove();
|
|
3278
|
+
const details = nodeBadgeDetails(state);
|
|
3279
|
+
const content = badgeContent(state);
|
|
3280
|
+
const badge = document.createElement("span");
|
|
3281
|
+
badge.className = "dshb-workspace-node-badge";
|
|
3282
|
+
badge.setAttribute(BADGE_ATTRIBUTE, "");
|
|
3283
|
+
badge.setAttribute("role", "img");
|
|
3284
|
+
badge.setAttribute("aria-label", details);
|
|
3285
|
+
badge.dataset.state = state.kind;
|
|
3286
|
+
badge.dataset.tone = badgeTone(state);
|
|
3287
|
+
if (state.kind === "bound") badge.dataset.nodeType = state.node.type;
|
|
3288
|
+
badge.tabIndex = 0;
|
|
3289
|
+
const icon = document.createElement("span");
|
|
3290
|
+
icon.setAttribute("aria-hidden", "true");
|
|
3291
|
+
icon.innerHTML = content.icon;
|
|
3292
|
+
badge.append(icon);
|
|
3293
|
+
if (content.label) {
|
|
3294
|
+
const label = document.createElement("span");
|
|
3295
|
+
label.textContent = content.label;
|
|
3296
|
+
badge.append(label);
|
|
3297
|
+
}
|
|
3298
|
+
badge.addEventListener("click", (event) => event.stopPropagation());
|
|
3299
|
+
badge.addEventListener("mouseenter", () => showTooltip(badge, details));
|
|
3300
|
+
badge.addEventListener("mouseleave", () => {
|
|
3301
|
+
if (activeBadge === badge) hideTooltip();
|
|
3302
|
+
});
|
|
3303
|
+
badge.addEventListener("focus", () => showTooltip(badge, details));
|
|
3304
|
+
badge.addEventListener("blur", () => {
|
|
3305
|
+
if (activeBadge === badge) hideTooltip();
|
|
3306
|
+
});
|
|
3307
|
+
badge.addEventListener("keydown", (event) => {
|
|
3308
|
+
if (event.key === "Escape") {
|
|
3309
|
+
event.stopPropagation();
|
|
3310
|
+
hideTooltip();
|
|
3311
|
+
}
|
|
3312
|
+
});
|
|
3313
|
+
row.insertBefore(badge, anchor);
|
|
3314
|
+
row.setAttribute(SIGNATURE_ATTRIBUTE, signature);
|
|
3315
|
+
if (hadFocus) badge.focus();
|
|
3316
|
+
};
|
|
3317
|
+
const scan = () => {
|
|
3318
|
+
if (!loaded || !workspaces) return;
|
|
3319
|
+
if (activeBadge && !activeBadge.isConnected) hideTooltip();
|
|
3320
|
+
const items = workspaces.list.getSnapshot().items;
|
|
3321
|
+
const byId = new Map(items.map((workspace) => [workspace.workspaceId, workspace]));
|
|
3322
|
+
for (const row of Array.from(document.querySelectorAll("[data-row-key^=\"workspace:\"]"))) {
|
|
3323
|
+
if (row.closest("[data-dshb-remote-workspaces]")) continue;
|
|
3324
|
+
const workspaceId = (row.getAttribute("data-row-key") ?? "").slice(10);
|
|
3325
|
+
if (!workspaceId) continue;
|
|
3326
|
+
const workspace = byId.get(workspaceId);
|
|
3327
|
+
if (!workspace) continue;
|
|
3328
|
+
applyRowBadge(row, resolveWorkspaceNodeBadge(workspace, bindings, nodes));
|
|
3329
|
+
}
|
|
3330
|
+
};
|
|
3331
|
+
const schedule = () => {
|
|
3332
|
+
if (disposed || raf !== 0) return;
|
|
3333
|
+
raf = requestAnimationFrame(() => {
|
|
3334
|
+
raf = 0;
|
|
3335
|
+
scan();
|
|
3336
|
+
});
|
|
3337
|
+
};
|
|
3338
|
+
const refresh = async () => {
|
|
3339
|
+
const token = ++refreshToken;
|
|
3340
|
+
const [nodeBody, bindingBody] = await Promise.all([fetchJson("/api/dshb/nodes"), fetchJson("/api/dshb/workspaces")]);
|
|
3341
|
+
if (disposed || token !== refreshToken || !nodeBody || !bindingBody) return;
|
|
3342
|
+
if (!Array.isArray(nodeBody.nodes) || !Array.isArray(bindingBody.bindings)) return;
|
|
3343
|
+
nodes = nodeBody.nodes.filter(isNode);
|
|
3344
|
+
bindings = bindingBody.bindings.filter(isBinding);
|
|
3345
|
+
loaded = true;
|
|
3346
|
+
schedule();
|
|
3347
|
+
};
|
|
3348
|
+
const onRefresh = () => {
|
|
3349
|
+
refresh();
|
|
3350
|
+
};
|
|
3351
|
+
const onScroll = () => {
|
|
3352
|
+
hideTooltip();
|
|
3353
|
+
};
|
|
3354
|
+
const observer = new MutationObserver(schedule);
|
|
3355
|
+
observer.observe(document.body, {
|
|
3356
|
+
childList: true,
|
|
3357
|
+
subtree: true
|
|
3358
|
+
});
|
|
3359
|
+
const unsubscribe = workspaces?.list.subscribe(schedule);
|
|
3360
|
+
window.addEventListener("focus", onRefresh);
|
|
3361
|
+
window.addEventListener("dshb:nodes-changed", onRefresh);
|
|
3362
|
+
window.addEventListener("dshb:workspace-bindings-changed", onRefresh);
|
|
3363
|
+
window.addEventListener("dshb:sync-peers-changed", onRefresh);
|
|
3364
|
+
window.addEventListener("scroll", onScroll, true);
|
|
3365
|
+
window.addEventListener("resize", onScroll);
|
|
3366
|
+
const timer = setInterval(onRefresh, 6e4);
|
|
3367
|
+
schedule();
|
|
3368
|
+
refresh();
|
|
3369
|
+
return () => {
|
|
3370
|
+
disposed = true;
|
|
3371
|
+
refreshToken += 1;
|
|
3372
|
+
observer.disconnect();
|
|
3373
|
+
unsubscribe?.();
|
|
3374
|
+
if (raf !== 0) cancelAnimationFrame(raf);
|
|
3375
|
+
clearInterval(timer);
|
|
3376
|
+
window.removeEventListener("focus", onRefresh);
|
|
3377
|
+
window.removeEventListener("dshb:nodes-changed", onRefresh);
|
|
3378
|
+
window.removeEventListener("dshb:workspace-bindings-changed", onRefresh);
|
|
3379
|
+
window.removeEventListener("dshb:sync-peers-changed", onRefresh);
|
|
3380
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
3381
|
+
window.removeEventListener("resize", onScroll);
|
|
3382
|
+
hideTooltip();
|
|
3383
|
+
tooltip?.remove();
|
|
3384
|
+
for (const badge of Array.from(document.querySelectorAll(`[${BADGE_ATTRIBUTE}]`))) badge.remove();
|
|
3385
|
+
for (const row of Array.from(document.querySelectorAll(`[${SIGNATURE_ATTRIBUTE}]`))) row.removeAttribute(SIGNATURE_ATTRIBUTE);
|
|
3386
|
+
style.remove();
|
|
3387
|
+
};
|
|
3388
|
+
}
|
|
3389
|
+
//#endregion
|
|
2904
3390
|
//#region src/client/remote-session-bootstrap.ts
|
|
2905
3391
|
/**
|
|
2906
3392
|
* 远端会话定位引导:本地端经 relay 打开远端 DSH 时通过
|
|
@@ -5039,7 +5525,10 @@ window.__ModuleLoader__.load({
|
|
|
5039
5525
|
setNotice(n);
|
|
5040
5526
|
if (n) setTimeout(() => setNotice(void 0), 6e3);
|
|
5041
5527
|
}, []);
|
|
5042
|
-
const reload = (0, react.useCallback)(() =>
|
|
5528
|
+
const reload = (0, react.useCallback)(() => {
|
|
5529
|
+
setReloadKey((k) => k + 1);
|
|
5530
|
+
window.dispatchEvent(new Event("dshb:nodes-changed"));
|
|
5531
|
+
}, []);
|
|
5043
5532
|
(0, react.useEffect)(() => {
|
|
5044
5533
|
(async () => {
|
|
5045
5534
|
try {
|
|
@@ -6002,8 +6491,10 @@ window.__ModuleLoader__.load({
|
|
|
6002
6491
|
`;
|
|
6003
6492
|
document.head.appendChild(globalStyle);
|
|
6004
6493
|
installMobile(ctx);
|
|
6494
|
+
installMenuAnchorFallback();
|
|
6005
6495
|
openRemoteSessionFromHash(ctx);
|
|
6006
6496
|
registerWorkspaceInstructionMenu(ctx);
|
|
6497
|
+
installWorkspaceNodeBadges(ctx);
|
|
6007
6498
|
ctx.plugin({
|
|
6008
6499
|
inject: ["slots"],
|
|
6009
6500
|
apply: (sub) => {
|