@artenx/dshb 0.1.51 → 0.1.53
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
CHANGED
|
@@ -2291,6 +2291,45 @@ window.__ModuleLoader__.load({
|
|
|
2291
2291
|
[data-dshb-remote-overlay] > header { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid color-mix(in srgb, currentColor 12%, transparent); font-size: 12px; opacity: .85; }
|
|
2292
2292
|
[data-dshb-remote-overlay] > header button { cursor: pointer; }
|
|
2293
2293
|
[data-dshb-remote-overlay] > iframe { flex: 1; width: 100%; border: 0; background: transparent; }
|
|
2294
|
+
`;
|
|
2295
|
+
const REMOTE_CATALOG_PANEL_STYLE = `
|
|
2296
|
+
[data-dshb-remote-catalog="open"] {
|
|
2297
|
+
display: inline-flex; align-items: center; justify-content: center;
|
|
2298
|
+
width: 32px; height: 32px; border: none; border-radius: 8px; background: none;
|
|
2299
|
+
color: inherit; cursor: pointer; opacity: .7; padding: 0;
|
|
2300
|
+
}
|
|
2301
|
+
[data-dshb-remote-catalog="open"]:hover { opacity: 1; background: var(--dsw-alias-interactive-bg-hover, rgba(127,127,127,.18)); }
|
|
2302
|
+
[data-dshb-remote-catalog-panel] {
|
|
2303
|
+
position: fixed; left: 0; top: 0; bottom: 0; width: min(340px, 92vw); z-index: 2147482900;
|
|
2304
|
+
background: var(--dsw-alias-bg-layer-1, #15171b); color: var(--dsw-alias-label-primary, #e8eaed);
|
|
2305
|
+
border-right: 1px solid var(--dsw-alias-border-l2, rgba(255,255,255,.08));
|
|
2306
|
+
box-shadow: 8px 0 28px rgba(0,0,0,.35); display: flex; flex-direction: column;
|
|
2307
|
+
font-size: 13px; overflow: hidden;
|
|
2308
|
+
}
|
|
2309
|
+
[data-dshb-remote-catalog-panel] > header {
|
|
2310
|
+
display: flex; align-items: center; gap: 8px; padding: 10px 12px;
|
|
2311
|
+
border-bottom: 1px solid var(--dsw-alias-border-l2, rgba(255,255,255,.08)); flex: none;
|
|
2312
|
+
}
|
|
2313
|
+
[data-dshb-remote-catalog-panel] > header .title { font-weight: 600; flex: 1; }
|
|
2314
|
+
[data-dshb-remote-catalog-panel] > header button { cursor: pointer; background: none; border: none; color: inherit; padding: 4px; }
|
|
2315
|
+
[data-dshb-remote-catalog-body] { flex: 1; overflow-y: auto; padding: 8px 6px 16px; }
|
|
2316
|
+
[data-dshb-remote-catalog-body] .peer { margin: 6px 4px 12px; }
|
|
2317
|
+
[data-dshb-remote-catalog-body] .peer-name { font-weight: 600; padding: 4px 8px; display: flex; align-items: center; gap: 6px; }
|
|
2318
|
+
[data-dshb-remote-catalog-body] .peer-meta { opacity: .55; font-size: 11px; font-weight: 400; }
|
|
2319
|
+
[data-dshb-remote-catalog-body] .ws { margin: 2px 0 2px 10px; }
|
|
2320
|
+
[data-dshb-remote-catalog-body] .ws-title { padding: 4px 8px; opacity: .8; display: flex; gap: 6px; align-items: baseline; }
|
|
2321
|
+
[data-dshb-remote-catalog-body] .ws-path { font-size: 11px; opacity: .5; font-family: ui-monospace, Menlo, Consolas, monospace; }
|
|
2322
|
+
[data-dshb-remote-catalog-body] .sess {
|
|
2323
|
+
display: flex; align-items: center; gap: 8px; width: calc(100% - 18px); margin: 1px 0 1px 18px;
|
|
2324
|
+
padding: 5px 8px; border: none; border-radius: 8px; background: none; color: inherit;
|
|
2325
|
+
text-align: left; cursor: pointer; font-size: 13px;
|
|
2326
|
+
}
|
|
2327
|
+
[data-dshb-remote-catalog-body] .sess:hover { background: var(--dsw-alias-interactive-bg-hover, rgba(255,255,255,.08)); }
|
|
2328
|
+
[data-dshb-remote-catalog-body] .sess .s-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2329
|
+
[data-dshb-remote-catalog-body] .sess .s-size { font-size: 11px; opacity: .45; flex: none; }
|
|
2330
|
+
[data-dshb-remote-catalog-body] .empty { padding: 8px 12px; opacity: .55; }
|
|
2331
|
+
[data-dshb-remote-catalog-body] .err { padding: 6px 10px; margin: 4px 8px; border-radius: 8px; background: var(--dsw-alias-state-error-tertiary, rgba(220,60,60,.15)); font-size: 12px; }
|
|
2332
|
+
[data-dshb-remote-catalog-backdrop] { position: fixed; inset: 0; z-index: 2147482800; background: rgba(0,0,0,.32); }
|
|
2294
2333
|
`;
|
|
2295
2334
|
function RemoteSessionOverlay({ peerId, onClose }) {
|
|
2296
2335
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -2337,6 +2376,251 @@ window.__ModuleLoader__.load({
|
|
|
2337
2376
|
}, RemoteSessionRowAction));
|
|
2338
2377
|
}
|
|
2339
2378
|
//#endregion
|
|
2379
|
+
//#region src/client/remote-catalog.tsx
|
|
2380
|
+
function formatSize(bytes) {
|
|
2381
|
+
if (bytes === void 0 || !Number.isFinite(bytes)) return "";
|
|
2382
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
2383
|
+
if (bytes < 1048576) return `${(bytes / 1024).toFixed(0)}K`;
|
|
2384
|
+
return `${(bytes / 1024 / 1024).toFixed(1)}M`;
|
|
2385
|
+
}
|
|
2386
|
+
function wsKey(origin) {
|
|
2387
|
+
return origin ? `${origin.originInstanceId}/${origin.originEntityId}` : "";
|
|
2388
|
+
}
|
|
2389
|
+
async function fetchPeerCatalog(peerId) {
|
|
2390
|
+
const res = await fetch(`/api/dshb/sync/peers/${encodeURIComponent(peerId)}/catalog`, { cache: "no-store" });
|
|
2391
|
+
const body = await res.json().catch(() => void 0);
|
|
2392
|
+
if (!res.ok || !body?.catalog) throw new Error(body?.code ? `${body.code}${body.error ? `:${body.error}` : ""}` : `HTTP ${res.status}`);
|
|
2393
|
+
return body.catalog;
|
|
2394
|
+
}
|
|
2395
|
+
function CatalogPanel({ peers, onClose }) {
|
|
2396
|
+
const [entries, setEntries] = (0, react.useState)(void 0);
|
|
2397
|
+
const [openSession, setOpenSession] = (0, react.useState)(void 0);
|
|
2398
|
+
const [reloadKey, setReloadKey] = (0, react.useState)(0);
|
|
2399
|
+
(0, react.useEffect)(() => {
|
|
2400
|
+
let cancelled = false;
|
|
2401
|
+
setEntries(void 0);
|
|
2402
|
+
const targets = peers.filter((peer) => peer.enabled);
|
|
2403
|
+
Promise.all(targets.map(async (peer) => {
|
|
2404
|
+
try {
|
|
2405
|
+
return {
|
|
2406
|
+
peer,
|
|
2407
|
+
catalog: await fetchPeerCatalog(peer.id)
|
|
2408
|
+
};
|
|
2409
|
+
} catch (error) {
|
|
2410
|
+
return {
|
|
2411
|
+
peer,
|
|
2412
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2413
|
+
};
|
|
2414
|
+
}
|
|
2415
|
+
})).then((result) => {
|
|
2416
|
+
if (!cancelled) setEntries(result);
|
|
2417
|
+
});
|
|
2418
|
+
return () => {
|
|
2419
|
+
cancelled = true;
|
|
2420
|
+
};
|
|
2421
|
+
}, [peers, reloadKey]);
|
|
2422
|
+
if (openSession) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RemoteSessionOverlay, {
|
|
2423
|
+
peerId: openSession.peerId,
|
|
2424
|
+
onClose: () => setOpenSession(void 0)
|
|
2425
|
+
});
|
|
2426
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2427
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: REMOTE_CATALOG_PANEL_STYLE }),
|
|
2428
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2429
|
+
"data-dshb-remote-catalog-backdrop": true,
|
|
2430
|
+
onClick: onClose
|
|
2431
|
+
}),
|
|
2432
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2433
|
+
"data-dshb-remote-catalog-panel": true,
|
|
2434
|
+
role: "dialog",
|
|
2435
|
+
"aria-label": "远端目录",
|
|
2436
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", { children: [
|
|
2437
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2438
|
+
className: "title",
|
|
2439
|
+
children: "远端目录"
|
|
2440
|
+
}),
|
|
2441
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2442
|
+
type: "button",
|
|
2443
|
+
"aria-label": "刷新",
|
|
2444
|
+
title: "重新拉取目录",
|
|
2445
|
+
onClick: () => setReloadKey((k) => k + 1),
|
|
2446
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
2447
|
+
width: "14",
|
|
2448
|
+
height: "14",
|
|
2449
|
+
viewBox: "0 0 16 16",
|
|
2450
|
+
fill: "none",
|
|
2451
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2452
|
+
"aria-hidden": "true",
|
|
2453
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
2454
|
+
d: "M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2.5V6h-3.5",
|
|
2455
|
+
stroke: "currentColor",
|
|
2456
|
+
strokeWidth: "1.5",
|
|
2457
|
+
strokeLinecap: "round",
|
|
2458
|
+
strokeLinejoin: "round"
|
|
2459
|
+
})
|
|
2460
|
+
})
|
|
2461
|
+
}),
|
|
2462
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2463
|
+
type: "button",
|
|
2464
|
+
"aria-label": "关闭",
|
|
2465
|
+
title: "关闭",
|
|
2466
|
+
onClick: onClose,
|
|
2467
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
2468
|
+
width: "14",
|
|
2469
|
+
height: "14",
|
|
2470
|
+
viewBox: "0 0 16 16",
|
|
2471
|
+
fill: "none",
|
|
2472
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2473
|
+
"aria-hidden": "true",
|
|
2474
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
2475
|
+
d: "M4 4l8 8M12 4l-8 8",
|
|
2476
|
+
stroke: "currentColor",
|
|
2477
|
+
strokeWidth: "1.5",
|
|
2478
|
+
strokeLinecap: "round"
|
|
2479
|
+
})
|
|
2480
|
+
})
|
|
2481
|
+
})
|
|
2482
|
+
] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2483
|
+
"data-dshb-remote-catalog-body": true,
|
|
2484
|
+
children: [
|
|
2485
|
+
entries === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2486
|
+
className: "empty",
|
|
2487
|
+
children: "正在拉取远端目录…"
|
|
2488
|
+
}) : null,
|
|
2489
|
+
entries?.map((entry) => {
|
|
2490
|
+
const sessions = (entry.catalog?.sessions ?? []).filter((session) => !session.deleted);
|
|
2491
|
+
const workspaces = entry.catalog?.workspaces ?? [];
|
|
2492
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
2493
|
+
for (const workspace of workspaces) grouped.set(wsKey(workspace.origin), {
|
|
2494
|
+
title: workspace.title || workspace.remotePath,
|
|
2495
|
+
remotePath: workspace.remotePath,
|
|
2496
|
+
sessions: []
|
|
2497
|
+
});
|
|
2498
|
+
for (const session of sessions) {
|
|
2499
|
+
const key = wsKey(session.workspaceOrigin);
|
|
2500
|
+
const bucket = grouped.get(key);
|
|
2501
|
+
if (bucket) bucket.sessions.push(session);
|
|
2502
|
+
else grouped.set(key, {
|
|
2503
|
+
title: session.workspaceRemotePath || "未分组",
|
|
2504
|
+
remotePath: session.workspaceRemotePath ?? "",
|
|
2505
|
+
sessions: [session]
|
|
2506
|
+
});
|
|
2507
|
+
}
|
|
2508
|
+
const orphanKey = wsKey(void 0);
|
|
2509
|
+
const orphan = grouped.get(orphanKey);
|
|
2510
|
+
if (orphan && orphan.sessions.length === 0) grouped.delete(orphanKey);
|
|
2511
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2512
|
+
className: "peer",
|
|
2513
|
+
children: [
|
|
2514
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2515
|
+
className: "peer-name",
|
|
2516
|
+
children: [entry.peer.name || entry.peer.id, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2517
|
+
className: "peer-meta",
|
|
2518
|
+
children: entry.catalog ? `${workspaces.length} 工作区 · ${sessions.length} 会话` : ""
|
|
2519
|
+
})]
|
|
2520
|
+
}),
|
|
2521
|
+
entry.error ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2522
|
+
className: "err",
|
|
2523
|
+
children: entry.error
|
|
2524
|
+
}) : null,
|
|
2525
|
+
entry.catalog && grouped.size === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2526
|
+
className: "empty",
|
|
2527
|
+
children: "远端暂无工作区或会话"
|
|
2528
|
+
}) : null,
|
|
2529
|
+
[...grouped.entries()].map(([key, group]) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2530
|
+
className: "ws",
|
|
2531
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2532
|
+
className: "ws-title",
|
|
2533
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: group.title }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2534
|
+
className: "ws-path",
|
|
2535
|
+
children: group.remotePath
|
|
2536
|
+
})]
|
|
2537
|
+
}), group.sessions.map((session) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
2538
|
+
type: "button",
|
|
2539
|
+
className: "sess",
|
|
2540
|
+
title: `打开远端会话(实时操作 ${entry.peer.name})`,
|
|
2541
|
+
onClick: () => setOpenSession({
|
|
2542
|
+
peerId: entry.peer.id,
|
|
2543
|
+
title: session.title ?? session.sessionId
|
|
2544
|
+
}),
|
|
2545
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2546
|
+
className: "s-title",
|
|
2547
|
+
children: session.title || session.sessionId
|
|
2548
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2549
|
+
className: "s-size",
|
|
2550
|
+
children: formatSize(session.sizeBytes)
|
|
2551
|
+
})]
|
|
2552
|
+
}, session.origin.originEntityId || session.sessionId))]
|
|
2553
|
+
}, key))
|
|
2554
|
+
]
|
|
2555
|
+
}, entry.peer.id);
|
|
2556
|
+
}),
|
|
2557
|
+
entries !== void 0 && entries.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2558
|
+
className: "empty",
|
|
2559
|
+
children: "尚无已启用的同步节点"
|
|
2560
|
+
}) : null
|
|
2561
|
+
]
|
|
2562
|
+
})]
|
|
2563
|
+
})
|
|
2564
|
+
] });
|
|
2565
|
+
}
|
|
2566
|
+
/** 侧栏 footer 的「远端」按钮:打开远端目录浮层。 */
|
|
2567
|
+
function RemoteCatalogButton() {
|
|
2568
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
2569
|
+
const [peers, setPeers] = (0, react.useState)([]);
|
|
2570
|
+
const loadPeers = (0, react.useCallback)(async () => {
|
|
2571
|
+
try {
|
|
2572
|
+
const body = await (await fetch("/api/dshb/sync/peers", { cache: "no-store" })).json().catch(() => void 0);
|
|
2573
|
+
if (body?.peers) setPeers(body.peers);
|
|
2574
|
+
} catch {}
|
|
2575
|
+
}, []);
|
|
2576
|
+
(0, react.useEffect)(() => {
|
|
2577
|
+
if (open) loadPeers();
|
|
2578
|
+
}, [open, loadPeers]);
|
|
2579
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2580
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: REMOTE_CATALOG_PANEL_STYLE }),
|
|
2581
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2582
|
+
type: "button",
|
|
2583
|
+
"data-dshb-remote-catalog": "open",
|
|
2584
|
+
"aria-label": "远端目录",
|
|
2585
|
+
title: "远端目录(浏览同步节点的远端工作区与会话)",
|
|
2586
|
+
onClick: () => setOpen(true),
|
|
2587
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
2588
|
+
width: "15",
|
|
2589
|
+
height: "15",
|
|
2590
|
+
viewBox: "0 0 16 16",
|
|
2591
|
+
fill: "none",
|
|
2592
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2593
|
+
"aria-hidden": "true",
|
|
2594
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
2595
|
+
cx: "8",
|
|
2596
|
+
cy: "8",
|
|
2597
|
+
r: "6.25",
|
|
2598
|
+
stroke: "currentColor",
|
|
2599
|
+
strokeWidth: "1.4"
|
|
2600
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
2601
|
+
d: "M2 6.5h12M2 9.5h12M8 1.9c-1.8 1.7-2.8 3.8-2.8 6.1s1 4.4 2.8 6.1c1.8-1.7 2.8-3.8 2.8-6.1s-1-4.4-2.8-6.1Z",
|
|
2602
|
+
stroke: "currentColor",
|
|
2603
|
+
strokeWidth: "1.2"
|
|
2604
|
+
})]
|
|
2605
|
+
})
|
|
2606
|
+
}),
|
|
2607
|
+
open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CatalogPanel, {
|
|
2608
|
+
peers,
|
|
2609
|
+
onClose: () => setOpen(false)
|
|
2610
|
+
}) : null
|
|
2611
|
+
] });
|
|
2612
|
+
}
|
|
2613
|
+
/** 注册侧栏远端目录入口(footer 操作区)。 */
|
|
2614
|
+
function installRemoteCatalogEntry(ctx) {
|
|
2615
|
+
const slots = ctx.slots;
|
|
2616
|
+
if (!slots) return;
|
|
2617
|
+
slots.inject("sidebar.footer.action", () => slots.register({
|
|
2618
|
+
name: "sidebar.footer.action",
|
|
2619
|
+
id: "dshb-remote-catalog",
|
|
2620
|
+
order: 40
|
|
2621
|
+
}, RemoteCatalogButton));
|
|
2622
|
+
}
|
|
2623
|
+
//#endregion
|
|
2340
2624
|
//#region src/client/sync-selection-picker.tsx
|
|
2341
2625
|
function originKey(origin) {
|
|
2342
2626
|
return JSON.stringify([origin.originInstanceId, origin.originEntityId]);
|
|
@@ -2728,7 +3012,8 @@ window.__ModuleLoader__.load({
|
|
|
2728
3012
|
function resultSummary(peer) {
|
|
2729
3013
|
const result = peer.progress?.lastResult;
|
|
2730
3014
|
if (!result) return void 0;
|
|
2731
|
-
|
|
3015
|
+
const sessionPart = result.skippedSessions > 0 ? `(其中会话 ${result.skippedSessions})` : "";
|
|
3016
|
+
return `节点导入 ${result.imported}、导出 ${result.exported};会话导入 ${result.importedSessions}、导出 ${result.exportedSessions};跳过 ${result.skipped}${sessionPart}`;
|
|
2732
3017
|
}
|
|
2733
3018
|
async function readJsonResponse(response, fallback) {
|
|
2734
3019
|
try {
|
|
@@ -5348,6 +5633,7 @@ window.__ModuleLoader__.load({
|
|
|
5348
5633
|
priority: -10
|
|
5349
5634
|
}, DirectoryFlowOccupant));
|
|
5350
5635
|
installRemoteSessionEntry(sub);
|
|
5636
|
+
installRemoteCatalogEntry(sub);
|
|
5351
5637
|
}
|
|
5352
5638
|
});
|
|
5353
5639
|
const ICON_SVG = {
|