@artenx/dshb 0.1.56 → 0.1.58

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
@@ -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);
@@ -1039,6 +1040,13 @@ window.__ModuleLoader__.load({
1039
1040
  });
1040
1041
  }
1041
1042
  //#endregion
1043
+ //#region src/client/mobile-layout.ts
1044
+ const MOBILE_QUERY = "(max-width: 1023px) and (any-pointer: coarse), (max-width: 767px) and (hover: none)";
1045
+ const UPSTREAM_DRAWER_QUERY = "(max-width: 767px)";
1046
+ function shouldUseUpstreamDrawer(viewportWidth, stylesAvailable) {
1047
+ return stylesAvailable && viewportWidth < 768;
1048
+ }
1049
+ //#endregion
1042
1050
  //#region src/client/mobile.tsx
1043
1051
  /**
1044
1052
  * dshb 移动端屏幕适配(参考 dsh-web-mobile 实现,仅保留页面适配与目录抽屉
@@ -1050,7 +1058,6 @@ window.__ModuleLoader__.load({
1050
1058
  * ctx.layout.toggleSidebar()。窄屏判定与上游一致(<1024 且粗指针,避免桌面
1051
1059
  * 小窗误触发)。
1052
1060
  */
1053
- const MOBILE_QUERY = "(max-width: 1023px) and (pointer: coarse)";
1054
1061
  /** 纯视口宽度判定:与放宽后的 MOBILE_CSS 媒体查询一致(不依赖 pointer 类型)。 */
1055
1062
  const NARROW_QUERY = "(max-width: 1023px)";
1056
1063
  const FRAME_ATTR = "data-dshb-mobile";
@@ -1060,7 +1067,7 @@ window.__ModuleLoader__.load({
1060
1067
  常报 pointer:fine,绑定 coarse 会让全部窄屏修复失效。抽屉相关选择器都挂在
1061
1068
  [data-dshb-mobile] 标记上,标记由 JS 的 coarse 判定添加,故放宽 CSS 不会误开抽屉。 */
1062
1069
  @media (max-width: 1023px) {
1063
- html, body { touch-action: pan-y pinch-zoom !important; overscroll-behavior-x: none !important; -webkit-text-size-adjust: 100% !important; text-size-adjust: 100% !important; }
1070
+ html, body { touch-action: manipulation !important; overscroll-behavior-x: none !important; -webkit-text-size-adjust: 100% !important; text-size-adjust: 100% !important; }
1064
1071
 
1065
1072
  [${FRAME_ATTR}="frame"] {
1066
1073
  box-sizing: border-box !important;
@@ -1068,20 +1075,28 @@ window.__ModuleLoader__.load({
1068
1075
  grid-template-columns: minmax(0, 1fr) 0 0 !important;
1069
1076
  padding-top: env(safe-area-inset-top, 0px) !important;
1070
1077
  }
1078
+ [${FRAME_ATTR}="frame-native"] {
1079
+ box-sizing: border-box !important;
1080
+ padding-top: env(safe-area-inset-top, 0px) !important;
1081
+ padding-left: env(safe-area-inset-left, 0px) !important;
1082
+ padding-right: env(safe-area-inset-right, 0px) !important;
1083
+ }
1071
1084
 
1072
1085
  /* 侧边栏列 -> 抽屉:默认移出屏幕,展开(无 collapsed)时滑入 */
1073
1086
  [${FRAME_ATTR}="frame"] > :first-child {
1074
1087
  position: absolute !important;
1075
1088
  inset: 0 auto 0 0 !important;
1089
+ box-sizing: border-box;
1076
1090
  width: max-content;
1077
- max-width: 92vw;
1091
+ min-width: min(280px, 92vw);
1092
+ max-width: min(92vw, 380px);
1078
1093
  z-index: 40 !important;
1079
1094
  transform: translateX(-110%);
1080
1095
  transition: transform .28s ease-in-out;
1081
1096
  background: var(--dsw-alias-bg-base, #ffffff);
1082
- padding-top: env(safe-area-inset-top, 0px) !important;
1097
+ padding: max(env(safe-area-inset-top, 0px), 12px) max(env(safe-area-inset-right, 0px), 12px) max(env(safe-area-inset-bottom, 0px), 12px) max(env(safe-area-inset-left, 0px), 12px) !important;
1083
1098
  border-right: none !important;
1084
- touch-action: pan-y pinch-zoom !important;
1099
+ touch-action: manipulation !important;
1085
1100
  }
1086
1101
  [${FRAME_ATTR}="frame"]:not([${COLLAPSED_ATTR}]) > :first-child { transform: none !important; }
1087
1102
  @media (prefers-reduced-motion: reduce) {
@@ -1094,12 +1109,15 @@ window.__ModuleLoader__.load({
1094
1109
  /* 对话区:去桌面滚动条占位,收窄 gutter,字号降一档 */
1095
1110
  [data-phase] [class*="_scrollBody"] { scrollbar-gutter: auto !important; scrollbar-width: none; }
1096
1111
  [data-phase] [class*="_scrollBody"]::-webkit-scrollbar { display: none !important; width: 0; height: 0; }
1097
- [data-phase] [class*="_scroll"]:not([class*="_scrollBody"]):has(p) { padding-left: 20px; padding-right: 20px; font-size: 15px !important; }
1112
+ [data-phase] [class*="_scroll"]:not([class*="_scrollBody"]):has(p) { padding-left: clamp(12px, 4vw, 20px); padding-right: clamp(12px, 4vw, 20px); font-size: 15px !important; }
1098
1113
  [data-phase] [class*="_scroll"]:not([class*="_scrollBody"]):has(p) p,
1099
1114
  [data-phase] [class*="_scroll"]:not([class*="_scrollBody"]):has(p) li,
1100
1115
  [data-phase] [class*="_scroll"]:not([class*="_scrollBody"]):has(p) [class*="_text_"] { font-size: 15px !important; }
1116
+ [data-phase] p, [data-phase] li { overflow-wrap: anywhere; }
1101
1117
  [data-phase] table { width: 100%; max-width: 100%; }
1102
1118
  [data-phase] th, [data-phase] td { max-width: none; min-width: 0; }
1119
+ [data-phase] [class*="tableScroll"] { max-width: 100% !important; overflow-x: auto !important; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; touch-action: manipulation !important; }
1120
+ [data-phase] [class*="tableScroll"]::-webkit-scrollbar { display: none !important; }
1103
1121
  [data-phase] [class*="_scroll"]:not([class*="_scrollBody"]) img { width: auto !important; max-width: 100% !important; height: auto !important; max-height: 220px !important; }
1104
1122
  [data-phase] [class*="_userStack"], [data-phase] [class*="_userStack"] [class*="_bubble"] { box-sizing: border-box; width: fit-content; max-width: 100%; }
1105
1123
  [data-phase] [class*="_actions"] { overflow: hidden; }
@@ -1131,7 +1149,7 @@ window.__ModuleLoader__.load({
1131
1149
  /* footer 容器各项间距 16px 偏松 */
1132
1150
  [data-phase] [class*="_root"][class*="osXY9a"] { gap: 8px !important; }
1133
1151
  /* footer 统计行窄屏可横向滑动看全,不溢出页面 */
1134
- [data-phase] [class*="_actions"] { max-width: 100% !important; overflow-x: auto !important; scrollbar-width: none; touch-action: pan-x pan-y pinch-zoom !important; }
1152
+ [data-phase] [class*="_actions"] { max-width: 100% !important; overflow-x: auto !important; overscroll-behavior-x: contain; scrollbar-width: none; touch-action: manipulation !important; }
1135
1153
  [data-phase] [class*="_actions"]::-webkit-scrollbar { display: none; }
1136
1154
 
1137
1155
  /* 模型切换菜单:名称完整展示,长名称在菜单项内换行。 */
@@ -1172,9 +1190,10 @@ window.__ModuleLoader__.load({
1172
1190
  min-width: 0 !important;
1173
1191
  max-width: 100% !important;
1174
1192
  overflow-x: auto !important;
1193
+ overscroll-behavior-x: contain;
1175
1194
  -webkit-overflow-scrolling: touch;
1176
1195
  scrollbar-width: none;
1177
- touch-action: pan-x pan-y pinch-zoom !important;
1196
+ touch-action: manipulation !important;
1178
1197
  }
1179
1198
  [data-phase] [class*="resultBlockText"]::-webkit-scrollbar,
1180
1199
  [data-phase] [class*="payload"]::-webkit-scrollbar,
@@ -1190,9 +1209,10 @@ window.__ModuleLoader__.load({
1190
1209
  min-width: 0 !important;
1191
1210
  max-width: 100% !important;
1192
1211
  overflow-x: auto !important;
1212
+ overscroll-behavior-x: contain;
1193
1213
  -webkit-overflow-scrolling: touch;
1194
1214
  scrollbar-width: none;
1195
- touch-action: pan-x pan-y pinch-zoom !important;
1215
+ touch-action: manipulation !important;
1196
1216
  }
1197
1217
  [data-phase] [class*="jsonPayload"]::-webkit-scrollbar,
1198
1218
  [data-phase] [class*="jsonPreview"]::-webkit-scrollbar,
@@ -1213,9 +1233,10 @@ window.__ModuleLoader__.load({
1213
1233
  min-width: 0 !important;
1214
1234
  max-width: 100% !important;
1215
1235
  overflow-x: auto !important;
1236
+ overscroll-behavior-x: contain;
1216
1237
  -webkit-overflow-scrolling: touch;
1217
1238
  scrollbar-width: none;
1218
- touch-action: pan-x pan-y pinch-zoom !important;
1239
+ touch-action: manipulation !important;
1219
1240
  }
1220
1241
  /* xterm uses a transparent helper textarea for all terminal input. Keep it
1221
1242
  focusable and non-zero-sized so mobile browsers can present their keyboard. */
@@ -1242,7 +1263,7 @@ window.__ModuleLoader__.load({
1242
1263
  max-width: 100% !important;
1243
1264
  overflow-x: auto !important;
1244
1265
  overscroll-behavior-x: contain;
1245
- touch-action: pan-x pan-y pinch-zoom !important;
1266
+ touch-action: manipulation !important;
1246
1267
  }
1247
1268
  [data-phase] [class*="_prompt_1gdtu_"],
1248
1269
  [data-phase] [class*="_promptLine_1gdtu_"],
@@ -1262,9 +1283,10 @@ window.__ModuleLoader__.load({
1262
1283
  [data-phase] [class*="_copyButton_1gdtu_"] { position: sticky !important; right: 0; }
1263
1284
  [data-phase] [class*="_output_1gdtu_"] {
1264
1285
  overflow-x: auto !important;
1286
+ overscroll-behavior-x: contain;
1265
1287
  -webkit-overflow-scrolling: touch;
1266
1288
  scrollbar-width: none;
1267
- touch-action: pan-x pan-y pinch-zoom !important;
1289
+ touch-action: manipulation !important;
1268
1290
  }
1269
1291
  [data-phase] [class*="_output_1gdtu_"]::-webkit-scrollbar { display: none !important; }
1270
1292
  [data-phase] [class*="_line_1gdtu_"] {
@@ -1277,7 +1299,7 @@ window.__ModuleLoader__.load({
1277
1299
  [data-phase] [class*="_copyButton_"] { touch-action: manipulation !important; }
1278
1300
  [data-phase] [class*="_copyAnchor_"],
1279
1301
  [data-phase] [class*="_body_1ye18_"],
1280
- [data-phase] [class*="_root_4qrvp_"] { touch-action: pan-x pan-y pinch-zoom !important; }
1302
+ [data-phase] [class*="_root_4qrvp_"] { touch-action: manipulation !important; }
1281
1303
 
1282
1304
  /* 上下文用量弹窗(ContextMeter .JObwrW_panel):上游 dsh-client-ui-trajectory 的
1283
1305
  [class*="panel"] 全局规则给它加了 max-width:100%!important,命中本弹窗,使宽度
@@ -1285,7 +1307,7 @@ window.__ModuleLoader__.load({
1285
1307
  .JObwrW_panel { max-width: none !important; overflow-x: visible !important; }
1286
1308
 
1287
1309
  /* 头部:标题省略,tab 条横向滚动 */
1288
- [${FRAME_ATTR}="frame"] [data-phase] header { padding-left: 44px; padding-right: 8px; }
1310
+ [${FRAME_ATTR}="frame"] [data-phase] header { padding-left: calc(44px + env(safe-area-inset-left, 0px)); padding-right: max(8px, env(safe-area-inset-right, 0px)); }
1289
1311
  [${FRAME_ATTR}="frame"] [data-phase] header [class*="_crumbs"] { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap !important; }
1290
1312
  [${FRAME_ATTR}="frame"] [data-phase] header [role="tablist"] { flex-wrap: nowrap; gap: 0 16px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
1291
1313
  [${FRAME_ATTR}="frame"] [data-phase] header [role="tablist"]::-webkit-scrollbar { display: none; }
@@ -1294,10 +1316,10 @@ window.__ModuleLoader__.load({
1294
1316
  /* 设置对话框:窄屏近全宽 sheet(排除导出等普通对话框与目录选择器) */
1295
1317
  [aria-modal="true"]:has(> :first-child > :last-child > button):not(:has([role="navigation"])):not(:has([class*="ZuhsRW"])) {
1296
1318
  position: absolute !important;
1297
- left: 8px !important;
1319
+ left: max(8px, env(safe-area-inset-left, 0px)) !important;
1298
1320
  top: calc(env(safe-area-inset-top, 0px) + 12px) !important;
1299
- width: calc(100vw - 16px) !important;
1300
- max-width: calc(100vw - 16px) !important;
1321
+ width: calc(100vw - max(8px, env(safe-area-inset-left, 0px)) - max(8px, env(safe-area-inset-right, 0px))) !important;
1322
+ max-width: calc(100vw - max(8px, env(safe-area-inset-left, 0px)) - max(8px, env(safe-area-inset-right, 0px))) !important;
1301
1323
  height: auto !important;
1302
1324
  max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px)) !important;
1303
1325
  flex-direction: column !important;
@@ -1315,6 +1337,11 @@ window.__ModuleLoader__.load({
1315
1337
  [aria-modal="true"]:has(> :first-child > :last-child > button):not(:has([role="navigation"])):not(:has([class*="ZuhsRW"])) > :first-child > :first-child { display: none !important; }
1316
1338
  [aria-modal="true"] [class*="_navList"] { flex: 1 1 auto; min-width: 0; flex-direction: row !important; flex-wrap: wrap; gap: 6px; overflow: visible; }
1317
1339
  [aria-modal="true"] [class*="_navList"] > button { flex-shrink: 0; white-space: nowrap; }
1340
+ @media (max-width: 600px) {
1341
+ [aria-modal="true"] [class*="_navList"] { flex-wrap: nowrap !important; overflow-x: auto !important; overscroll-behavior-x: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch; touch-action: manipulation !important; }
1342
+ [aria-modal="true"] [class*="_navList"]::-webkit-scrollbar { display: none !important; }
1343
+ [aria-modal="true"] [class*="_navList"] > button { min-height: 44px; padding: 8px 12px; }
1344
+ }
1318
1345
  /* 外观模式卡片横排 */
1319
1346
  [aria-modal="true"] [class*="_cubeRow"] { gap: 6px; }
1320
1347
  [aria-modal="true"] [class*="_cubeRow"] > * { flex: 1 1 0; flex-direction: row !important; align-items: center; justify-content: center; gap: 6px; padding: 10px 8px; min-height: 0; }
@@ -1326,12 +1353,12 @@ window.__ModuleLoader__.load({
1326
1353
  /* 切换按钮:固定头部左侧 */
1327
1354
  [${FRAME_ATTR}="toggle"] {
1328
1355
  position: absolute !important;
1329
- left: 8px !important;
1330
- top: 12px !important;
1356
+ left: max(8px, env(safe-area-inset-left, 0px)) !important;
1357
+ top: calc(env(safe-area-inset-top, 0px) + 12px) !important;
1331
1358
  z-index: 2 !important;
1332
1359
  display: inline-flex !important;
1333
1360
  align-items: center; justify-content: center;
1334
- width: 32px; height: 32px;
1361
+ width: 36px; height: 36px;
1335
1362
  padding: 0; border: none; background: none; cursor: pointer; color: inherit;
1336
1363
  -webkit-tap-highlight-color: transparent;
1337
1364
  }
@@ -1344,13 +1371,15 @@ window.__ModuleLoader__.load({
1344
1371
  inset: -7px;
1345
1372
  }
1346
1373
  [class*="_iconButton"] { position: relative !important; }
1374
+ [data-phase] button, [data-phase] [role="button"], [aria-modal="true"] button { -webkit-tap-highlight-color: transparent; touch-action: manipulation !important; }
1375
+ [data-phase] button:active:not(:disabled), [data-phase] [role="button"]:active, [aria-modal="true"] button:active:not(:disabled) { opacity: .72; }
1347
1376
 
1348
1377
  /* 首页/hero(无活跃会话,session header 不存在)的抽屉切换 FAB:
1349
1378
  浮在顶部相机带下方,避免与 hero 头部内容重叠 */
1350
1379
  [${FRAME_ATTR}="fab"] {
1351
1380
  position: absolute !important;
1352
1381
  top: calc(env(safe-area-inset-top, 0px) + 72px) !important;
1353
- left: 10px !important;
1382
+ left: max(10px, env(safe-area-inset-left, 0px)) !important;
1354
1383
  z-index: 21 !important;
1355
1384
  display: inline-flex !important;
1356
1385
  align-items: center; justify-content: center;
@@ -1374,10 +1403,13 @@ window.__ModuleLoader__.load({
1374
1403
  /* 底部安全区(iPhone home 条):viewport-fit=cover 后浏览器 UI 退出底部,
1375
1404
  home 指示条叠在 composer / 抽屉 / 设置 sheet 上,遮挡发送按钮与会话列表末项。 */
1376
1405
  [class*="composerSeat"], [data-composer-seat] {
1406
+ box-sizing: border-box;
1377
1407
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 4px) !important;
1408
+ padding-left: env(safe-area-inset-left, 0px) !important;
1409
+ padding-right: env(safe-area-inset-right, 0px) !important;
1378
1410
  }
1379
1411
  [${FRAME_ATTR}="frame"] > :first-child {
1380
- padding-bottom: env(safe-area-inset-bottom, 0px) !important;
1412
+ padding-bottom: max(env(safe-area-inset-bottom, 0px), 12px) !important;
1381
1413
  }
1382
1414
  [aria-modal="true"]:has(> :first-child > :last-child > button):not(:has([role="navigation"])):not(:has([class*="ZuhsRW"])) {
1383
1415
  max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
@@ -1387,11 +1419,19 @@ window.__ModuleLoader__.load({
1387
1419
  }
1388
1420
 
1389
1421
  /* 会话行触控高度 */
1390
- [class*="sessionRow"] { min-height: 44px !important; }
1422
+ [class*="sessionRow"] { min-height: 48px !important; }
1423
+
1424
+ @media (max-height: 500px) and (orientation: landscape) {
1425
+ [aria-modal="true"]:has(> :first-child > :last-child > button):not(:has([role="navigation"])):not(:has([class*="ZuhsRW"])) {
1426
+ top: max(8px, env(safe-area-inset-top, 0px)) !important;
1427
+ max-height: calc(100dvh - max(8px, env(safe-area-inset-top, 0px)) - max(8px, env(safe-area-inset-bottom, 0px))) !important;
1428
+ }
1429
+ [${FRAME_ATTR}="fab"] { width: 40px; height: 40px; }
1430
+ }
1391
1431
  }
1392
1432
 
1393
- /* 宽屏 / 鼠标指针:隐藏切换按钮 */
1394
- @media (min-width: 1024px), (pointer: fine) {
1433
+ /* 桌面或精细指针且支持悬停的窄窗:隐藏切换按钮 */
1434
+ @media (min-width: 1024px), (max-width: 1023px) and (hover: hover) and (pointer: fine) and (any-pointer: fine) {
1395
1435
  [${FRAME_ATTR}="toggle"], [${FRAME_ATTR}="fab"] { display: none !important; }
1396
1436
  }
1397
1437
  `;
@@ -1409,14 +1449,15 @@ window.__ModuleLoader__.load({
1409
1449
  * centerCol 固定 grid-area:1/2,dshb 的 minmax(0,1fr) 0 0 会把第 2 列压成
1410
1450
  * 0 宽,会话区整体移出屏幕(手机白屏根因)。
1411
1451
  */
1412
- let upstreamDrawerCache = null;
1452
+ let upstreamDrawerStylesAvailable = false;
1413
1453
  function upstreamHandlesDrawer() {
1414
- if (upstreamDrawerCache !== null) return upstreamDrawerCache;
1415
- for (const tag of document.querySelectorAll("style")) if ((tag.textContent ?? "").includes("data-sidebar-drawer")) {
1416
- upstreamDrawerCache = true;
1417
- return true;
1454
+ if (!upstreamDrawerStylesAvailable) {
1455
+ for (const tag of document.querySelectorAll("style")) if ((tag.textContent ?? "").includes("data-sidebar-drawer")) {
1456
+ upstreamDrawerStylesAvailable = true;
1457
+ break;
1458
+ }
1418
1459
  }
1419
- return false;
1460
+ return shouldUseUpstreamDrawer(window.innerWidth, upstreamDrawerStylesAvailable);
1420
1461
  }
1421
1462
  /** viewport-fit=cover:让 safe-area-inset 生效,内容避开刘海/状态栏。 */
1422
1463
  function installViewport(ctx) {
@@ -1477,9 +1518,11 @@ window.__ModuleLoader__.load({
1477
1518
  else clear();
1478
1519
  };
1479
1520
  narrow.addEventListener("change", onChange);
1521
+ window.addEventListener("resize", ensure);
1480
1522
  return () => {
1481
1523
  mo.disconnect();
1482
1524
  narrow.removeEventListener("change", onChange);
1525
+ window.removeEventListener("resize", ensure);
1483
1526
  clear();
1484
1527
  };
1485
1528
  }, "dshb-mobile: frame marker");
@@ -1538,11 +1581,13 @@ window.__ModuleLoader__.load({
1538
1581
  document.addEventListener("keydown", onKeyDown, true);
1539
1582
  document.addEventListener("click", onClick, true);
1540
1583
  narrow.addEventListener("change", sync);
1584
+ window.addEventListener("resize", sync);
1541
1585
  return () => {
1542
1586
  mo.disconnect();
1543
1587
  document.removeEventListener("keydown", onKeyDown, true);
1544
1588
  document.removeEventListener("click", onClick, true);
1545
1589
  narrow.removeEventListener("change", sync);
1590
+ window.removeEventListener("resize", sync);
1546
1591
  backdrop?.remove();
1547
1592
  };
1548
1593
  }, "dshb-mobile: drawer interactions");
@@ -1889,19 +1934,40 @@ window.__ModuleLoader__.load({
1889
1934
  /** 目录抽屉切换按钮(仅切换,不含文件浏览/日志导出等功能按钮)。 */
1890
1935
  function DrawerToggle({ toggleSidebar }) {
1891
1936
  const [native, setNative] = (0, react.useState)(upstreamHandlesDrawer());
1937
+ const [expanded, setExpanded] = (0, react.useState)(false);
1938
+ (0, react.useEffect)(() => {
1939
+ const drawerQuery = window.matchMedia(UPSTREAM_DRAWER_QUERY);
1940
+ const sync = () => setNative(upstreamHandlesDrawer());
1941
+ const timer = window.setTimeout(sync, 600);
1942
+ drawerQuery.addEventListener("change", sync);
1943
+ window.addEventListener("resize", sync);
1944
+ return () => {
1945
+ window.clearTimeout(timer);
1946
+ drawerQuery.removeEventListener("change", sync);
1947
+ window.removeEventListener("resize", sync);
1948
+ };
1949
+ }, []);
1892
1950
  (0, react.useEffect)(() => {
1893
- if (native) return;
1894
- const timer = window.setTimeout(() => {
1895
- if (upstreamHandlesDrawer()) setNative(true);
1896
- }, 600);
1897
- return () => window.clearTimeout(timer);
1898
- }, [native]);
1951
+ const sync = () => {
1952
+ const frame = getFrame();
1953
+ setExpanded(frame !== null && !frame.hasAttribute(COLLAPSED_ATTR));
1954
+ };
1955
+ sync();
1956
+ const observer = new MutationObserver(sync);
1957
+ observer.observe(document.documentElement, {
1958
+ attributes: true,
1959
+ attributeFilter: [COLLAPSED_ATTR],
1960
+ subtree: true
1961
+ });
1962
+ return () => observer.disconnect();
1963
+ }, []);
1899
1964
  if (native) return null;
1900
1965
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1901
1966
  type: "button",
1902
1967
  "data-dshb-mobile": "toggle",
1903
- "aria-label": "打开目录",
1904
- title: "打开目录",
1968
+ "aria-label": expanded ? "关闭目录" : "打开目录",
1969
+ "aria-expanded": expanded,
1970
+ title: expanded ? "关闭目录" : "打开目录",
1905
1971
  onClick: () => toggleSidebar(),
1906
1972
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1907
1973
  width: "16",
@@ -1974,9 +2040,11 @@ window.__ModuleLoader__.load({
1974
2040
  ]
1975
2041
  });
1976
2042
  narrow.addEventListener("change", sync);
2043
+ window.addEventListener("resize", sync);
1977
2044
  return () => {
1978
2045
  mo.disconnect();
1979
2046
  narrow.removeEventListener("change", sync);
2047
+ window.removeEventListener("resize", sync);
1980
2048
  fab?.remove();
1981
2049
  };
1982
2050
  }, "dshb-mobile: hero fab");
@@ -2006,6 +2074,154 @@ window.__ModuleLoader__.load({
2006
2074
  }, DrawerToggle));
2007
2075
  }
2008
2076
  //#endregion
2077
+ //#region src/client/menu-position.ts
2078
+ function shouldForceMenuPosition(side, supportsAnchorPositioning, forceAll = false) {
2079
+ return forceAll || !supportsAnchorPositioning || side === "top";
2080
+ }
2081
+ function computeMenuPosition(anchor, menu, side, align, viewport, gap = 8, margin = 8) {
2082
+ let left = anchor.left;
2083
+ let top = anchor.top;
2084
+ if (side === "top" || side === "bottom") {
2085
+ top = side === "top" ? anchor.top - menu.height - gap : anchor.bottom + gap;
2086
+ left = align === "end" ? anchor.right - menu.width : align === "center" ? anchor.left + (anchor.width - menu.width) / 2 : anchor.left;
2087
+ if (top < margin) top = anchor.bottom + gap;
2088
+ if (top + menu.height > viewport.height - margin) top = anchor.top - menu.height - gap;
2089
+ } else {
2090
+ left = side === "left" ? anchor.left - menu.width - gap : anchor.right + gap;
2091
+ top = align === "end" ? anchor.bottom - menu.height : align === "center" ? anchor.top + (anchor.height - menu.height) / 2 : anchor.top;
2092
+ if (left < margin) left = anchor.right + gap;
2093
+ if (left + menu.width > viewport.width - margin) left = anchor.left - menu.width - gap;
2094
+ }
2095
+ return {
2096
+ left: Math.max(margin, Math.min(left, viewport.width - menu.width - margin)),
2097
+ top: Math.max(margin, Math.min(top, viewport.height - menu.height - margin))
2098
+ };
2099
+ }
2100
+ //#endregion
2101
+ //#region src/client/menu-anchor-fallback.ts
2102
+ const POSITIONED_ATTRIBUTE = "data-dshb-menu-positioned";
2103
+ function supportsAnchorPositioning() {
2104
+ 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)");
2105
+ }
2106
+ function toRect(element) {
2107
+ const rect = element.getBoundingClientRect();
2108
+ return {
2109
+ top: rect.top,
2110
+ bottom: rect.bottom,
2111
+ left: rect.left,
2112
+ right: rect.right,
2113
+ width: rect.width,
2114
+ height: rect.height
2115
+ };
2116
+ }
2117
+ function setStyleIfChanged(element, property, value) {
2118
+ if (element.style.getPropertyValue(property) === value) return;
2119
+ element.style.setProperty(property, value);
2120
+ }
2121
+ function installMenuAnchorFallback() {
2122
+ const anchorPositioningSupported = supportsAnchorPositioning();
2123
+ const mobile = window.matchMedia(MOBILE_QUERY);
2124
+ const anchors = /* @__PURE__ */ new WeakMap();
2125
+ const resizeObserver = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(() => schedule());
2126
+ let raf = 0;
2127
+ const findFallbackTrigger = (side) => {
2128
+ const expanded = Array.from(document.querySelectorAll("button[aria-haspopup=\"menu\"][aria-expanded=\"true\"]")).filter((element) => element.getClientRects().length > 0);
2129
+ const outsideMenu = expanded.filter((element) => element.closest("[role=\"menu\"]") === null);
2130
+ const insideMenu = expanded.filter((element) => element.closest("[role=\"menu\"]") !== null);
2131
+ if (side === "left" || side === "right") return insideMenu.at(-1) ?? outsideMenu.at(-1);
2132
+ return outsideMenu.at(-1) ?? insideMenu.at(-1);
2133
+ };
2134
+ const findAnchor = (menu, side) => {
2135
+ const name = menu.style.getPropertyValue("position-anchor").trim();
2136
+ const cached = anchors.get(menu);
2137
+ if (cached?.isConnected && (!name || cached.style.getPropertyValue("anchor-name").trim() === name)) return cached;
2138
+ if (name) for (const element of Array.from(document.querySelectorAll("[style]"))) {
2139
+ if (element.style.getPropertyValue("anchor-name").trim() !== name) continue;
2140
+ anchors.set(menu, element);
2141
+ return element;
2142
+ }
2143
+ const trigger = findFallbackTrigger(side);
2144
+ if (trigger) anchors.set(menu, trigger);
2145
+ return trigger;
2146
+ };
2147
+ const positionMenu = (menu) => {
2148
+ if (menu.getAttribute("aria-hidden") === "true") return;
2149
+ const side = menu.dataset.anchorSide ?? "bottom";
2150
+ const anchor = findAnchor(menu, side);
2151
+ if (!anchor) return;
2152
+ const target = anchor.matches("button") ? anchor : anchor.querySelector("button") ?? anchor;
2153
+ const align = menu.dataset.anchorAlign ?? "start";
2154
+ const position = computeMenuPosition(toRect(target), toRect(menu), side, align, {
2155
+ width: window.innerWidth,
2156
+ height: window.innerHeight
2157
+ });
2158
+ setStyleIfChanged(menu, "position", "fixed");
2159
+ setStyleIfChanged(menu, "left", `${position.left}px`);
2160
+ setStyleIfChanged(menu, "top", `${position.top}px`);
2161
+ setStyleIfChanged(menu, "bottom", "auto");
2162
+ setStyleIfChanged(menu, "right", "auto");
2163
+ setStyleIfChanged(menu, "position-anchor", "none");
2164
+ setStyleIfChanged(menu, "position-area", "none");
2165
+ setStyleIfChanged(menu, "position-try-fallbacks", "none");
2166
+ setStyleIfChanged(menu, "align-self", "auto");
2167
+ setStyleIfChanged(menu, "justify-self", "auto");
2168
+ menu.setAttribute(POSITIONED_ATTRIBUTE, "");
2169
+ };
2170
+ const positionAll = () => {
2171
+ for (const menu of Array.from(document.querySelectorAll("[role=\"menu\"][data-anchor-side]"))) {
2172
+ if (!shouldForceMenuPosition(menu.dataset.anchorSide ?? "bottom", anchorPositioningSupported, mobile.matches)) continue;
2173
+ resizeObserver?.observe(menu);
2174
+ positionMenu(menu);
2175
+ }
2176
+ };
2177
+ const schedule = () => {
2178
+ if (raf !== 0) return;
2179
+ raf = requestAnimationFrame(() => {
2180
+ raf = 0;
2181
+ positionAll();
2182
+ });
2183
+ };
2184
+ const observer = new MutationObserver(schedule);
2185
+ observer.observe(document.body, {
2186
+ childList: true,
2187
+ subtree: true,
2188
+ attributes: true,
2189
+ attributeFilter: [
2190
+ "style",
2191
+ "data-anchor-side",
2192
+ "data-anchor-align",
2193
+ "role",
2194
+ "aria-hidden",
2195
+ "aria-expanded",
2196
+ "aria-haspopup",
2197
+ "aria-controls"
2198
+ ]
2199
+ });
2200
+ window.addEventListener("scroll", schedule, true);
2201
+ window.addEventListener("resize", schedule);
2202
+ document.addEventListener("transitionend", schedule, true);
2203
+ document.addEventListener("animationend", schedule, true);
2204
+ mobile.addEventListener("change", schedule);
2205
+ schedule();
2206
+ return () => {
2207
+ observer.disconnect();
2208
+ resizeObserver?.disconnect();
2209
+ if (raf !== 0) cancelAnimationFrame(raf);
2210
+ window.removeEventListener("scroll", schedule, true);
2211
+ window.removeEventListener("resize", schedule);
2212
+ document.removeEventListener("transitionend", schedule, true);
2213
+ document.removeEventListener("animationend", schedule, true);
2214
+ mobile.removeEventListener("change", schedule);
2215
+ for (const menu of Array.from(document.querySelectorAll(`[${POSITIONED_ATTRIBUTE}]`))) {
2216
+ menu.style.removeProperty("position");
2217
+ menu.style.removeProperty("left");
2218
+ menu.style.removeProperty("top");
2219
+ menu.style.removeProperty("position-anchor");
2220
+ menu.removeAttribute(POSITIONED_ATTRIBUTE);
2221
+ }
2222
+ };
2223
+ }
2224
+ //#endregion
2009
2225
  //#region src/client/workspace-instruction-menu.tsx
2010
2226
  let injectedRegistry;
2011
2227
  function setWorkspaceRegistry(reg) {
@@ -2385,6 +2601,11 @@ window.__ModuleLoader__.load({
2385
2601
  }, RemoteSessionRowAction));
2386
2602
  }
2387
2603
  //#endregion
2604
+ //#region src/client/remote-catalog-model.ts
2605
+ function eligibleRemoteCatalogPeers(peers) {
2606
+ return peers.filter((peer) => peer.enabled && !(peer.mode === "full" && peer.syncSessions));
2607
+ }
2608
+ //#endregion
2388
2609
  //#region src/client/remote-catalog.tsx
2389
2610
  function formatSize(bytes) {
2390
2611
  if (bytes === void 0 || !Number.isFinite(bytes)) return "";
@@ -2583,9 +2804,19 @@ window.__ModuleLoader__.load({
2583
2804
  if (body?.peers) setPeers(body.peers);
2584
2805
  } catch {}
2585
2806
  }, []);
2807
+ (0, react.useEffect)(() => {
2808
+ loadPeers();
2809
+ const onPeersChanged = () => {
2810
+ loadPeers();
2811
+ };
2812
+ window.addEventListener("dshb:sync-peers-changed", onPeersChanged);
2813
+ return () => window.removeEventListener("dshb:sync-peers-changed", onPeersChanged);
2814
+ }, [loadPeers]);
2586
2815
  (0, react.useEffect)(() => {
2587
2816
  if (open) loadPeers();
2588
2817
  }, [open, loadPeers]);
2818
+ const eligiblePeers = eligibleRemoteCatalogPeers(peers);
2819
+ if (eligiblePeers.length === 0) return null;
2589
2820
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2590
2821
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: REMOTE_CATALOG_PANEL_STYLE }),
2591
2822
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
@@ -2615,7 +2846,7 @@ window.__ModuleLoader__.load({
2615
2846
  })
2616
2847
  }),
2617
2848
  open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CatalogPanel, {
2618
- peers,
2849
+ peers: eligiblePeers,
2619
2850
  onClose: () => setOpen(false)
2620
2851
  }) : null
2621
2852
  ] });
@@ -2637,7 +2868,7 @@ window.__ModuleLoader__.load({
2637
2868
  function wsKey(origin) {
2638
2869
  return origin ? `${origin.originInstanceId}/${origin.originEntityId}` : "";
2639
2870
  }
2640
- async function fetchJson(url, init) {
2871
+ async function fetchJson$1(url, init) {
2641
2872
  const res = await fetch(url, {
2642
2873
  cache: "no-store",
2643
2874
  ...init
@@ -2790,7 +3021,7 @@ window.__ModuleLoader__.load({
2790
3021
  const dismiss = showToast("正在导入远端会话…");
2791
3022
  (async () => {
2792
3023
  try {
2793
- const result = await fetchJson("/api/dshb/sync/open-session", {
3024
+ const result = await fetchJson$1("/api/dshb/sync/open-session", {
2794
3025
  method: "POST",
2795
3026
  headers: { "content-type": "application/json" },
2796
3027
  body: JSON.stringify({
@@ -2827,11 +3058,11 @@ window.__ModuleLoader__.load({
2827
3058
  };
2828
3059
  const load = async () => {
2829
3060
  try {
2830
- const { peers } = await fetchJson("/api/dshb/sync/peers");
3061
+ const { peers } = await fetchJson$1("/api/dshb/sync/peers");
2831
3062
  const targets = (peers ?? []).filter((p) => p.enabled && !(p.mode === "full" && p.syncSessions));
2832
3063
  const result = await Promise.all(targets.map(async (peer) => {
2833
3064
  try {
2834
- const { catalog } = await fetchJson(`/api/dshb/sync/peers/${encodeURIComponent(peer.id)}/catalog`);
3065
+ const { catalog } = await fetchJson$1(`/api/dshb/sync/peers/${encodeURIComponent(peer.id)}/catalog`);
2835
3066
  return {
2836
3067
  peer,
2837
3068
  catalog
@@ -2901,6 +3132,404 @@ window.__ModuleLoader__.load({
2901
3132
  };
2902
3133
  }
2903
3134
  //#endregion
3135
+ //#region src/client/workspace-node-badge-model.ts
3136
+ function isRemoteNodeType(type) {
3137
+ return type === "remote-ssh" || type === "remote-docker";
3138
+ }
3139
+ function normalizeWorkspacePath(path) {
3140
+ const collapsed = path.replace(/\\/g, "/").replace(/\/+/g, "/");
3141
+ const trimmed = collapsed.length > 1 ? collapsed.replace(/\/+$/, "") : collapsed;
3142
+ return /^[A-Za-z]:/.test(trimmed) ? trimmed[0].toLowerCase() + trimmed.slice(1) : trimmed;
3143
+ }
3144
+ function nodeTypeLabel(type) {
3145
+ switch (type) {
3146
+ case "local-host": return "本地宿主";
3147
+ case "local-docker": return "本地 Docker";
3148
+ case "remote-ssh": return "远程 SSH";
3149
+ case "remote-docker": return "远程 Docker";
3150
+ }
3151
+ }
3152
+ function nodeStatusLabel(node) {
3153
+ if (node.sync?.pendingRemoval) return "待删除";
3154
+ if (node.sync?.credentialsRequired) return "凭据不足";
3155
+ if (node.provision?.state === "failed") return "供给失败";
3156
+ if (node.provision?.state === "provisioning") return "供给中";
3157
+ if (node.status?.reachable === true) return "在线";
3158
+ if (node.status?.reachable === false) return "离线";
3159
+ return "未知";
3160
+ }
3161
+ function nodeBadgeTone(node) {
3162
+ if (node.sync?.pendingRemoval || node.sync?.credentialsRequired) return "warning";
3163
+ if (node.provision?.state === "failed" || node.status?.reachable === false) return "error";
3164
+ if (node.provision?.state === "provisioning" || node.status?.reachable === void 0) return "muted";
3165
+ return "normal";
3166
+ }
3167
+ function resolveWorkspaceNodeBadge(workspace, bindings, nodes) {
3168
+ const idMatches = workspace.workspaceId ? bindings.filter((binding) => binding.workspaceId === workspace.workspaceId) : [];
3169
+ const pathMatches = workspace.path ? bindings.filter((binding) => normalizeWorkspacePath(binding.mirrorPath) === normalizeWorkspacePath(workspace.path)) : [];
3170
+ const matches = idMatches.length > 0 ? idMatches : pathMatches;
3171
+ if (matches.length === 0) return { kind: "unbound" };
3172
+ if (matches.length > 1) return {
3173
+ kind: "conflict",
3174
+ bindings: matches.map((binding) => ({ ...binding })),
3175
+ nodes: matches.flatMap((binding) => {
3176
+ const node = nodes.find((candidate) => candidate.id === binding.nodeId);
3177
+ return node ? [node] : [];
3178
+ })
3179
+ };
3180
+ const binding = matches[0];
3181
+ const node = nodes.find((candidate) => candidate.id === binding.nodeId);
3182
+ return node ? {
3183
+ kind: "bound",
3184
+ node,
3185
+ binding: { ...binding }
3186
+ } : {
3187
+ kind: "missing-node",
3188
+ nodeId: binding.nodeId,
3189
+ binding: { ...binding }
3190
+ };
3191
+ }
3192
+ function nodeBadgeDetails(state) {
3193
+ if (state.kind === "unbound") return "";
3194
+ if (state.kind === "missing-node") return [
3195
+ "节点已失效",
3196
+ `节点 ID:${state.nodeId}`,
3197
+ `远端路径:${state.binding.remotePath}`
3198
+ ].join("\n");
3199
+ if (state.kind === "conflict") {
3200
+ const lines = ["绑定冲突", `匹配到 ${state.bindings.length} 条绑定`];
3201
+ state.bindings.forEach((binding, index) => {
3202
+ const node = state.nodes.find((candidate) => candidate.id === binding.nodeId);
3203
+ lines.push(`${index + 1}. ${node?.name ?? binding.nodeId} · ${binding.remotePath}`);
3204
+ });
3205
+ return lines.join("\n");
3206
+ }
3207
+ const lines = [
3208
+ state.node.name,
3209
+ `${nodeTypeLabel(state.node.type)} · ${nodeStatusLabel(state.node)}`,
3210
+ `远端路径:${state.binding.remotePath}`
3211
+ ];
3212
+ if (state.node.sync?.sourceName) lines.push(`来源:${state.node.sync.sourceName}`);
3213
+ if (state.node.status?.error) lines.push(`状态说明:${state.node.status.error}`);
3214
+ return lines.join("\n");
3215
+ }
3216
+ //#endregion
3217
+ //#region src/client/workspace-node-badge.ts
3218
+ const BADGE_ATTRIBUTE = "data-dshb-workspace-node-badge";
3219
+ const SIGNATURE_ATTRIBUTE = "data-dshb-workspace-node-badge-signature";
3220
+ const TOOLTIP_ID = "dshb-workspace-node-tooltip";
3221
+ 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>";
3222
+ 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>";
3223
+ function ensureStyle() {
3224
+ const existing = document.querySelector("style[data-dshb-workspace-node-badge-style]");
3225
+ if (existing) return existing;
3226
+ const style = document.createElement("style");
3227
+ style.dataset.dshbWorkspaceNodeBadgeStyle = "";
3228
+ style.textContent = `
3229
+ .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}
3230
+ .dshb-workspace-node-badge[data-node-type="local-host"]{--dshb-node-accent:var(--dsw-alias-label-tertiary)}
3231
+ .dshb-workspace-node-badge[data-node-type="local-docker"]{--dshb-node-accent:var(--dsw-alias-state-business-primary)}
3232
+ .dshb-workspace-node-badge[data-node-type="remote-ssh"]{--dshb-node-accent:var(--dsw-alias-state-success-primary)}
3233
+ .dshb-workspace-node-badge[data-node-type="remote-docker"]{--dshb-node-accent:var(--dsw-alias-brand-primary,var(--dsw-alias-state-business-primary))}
3234
+ .dshb-workspace-node-badge svg{width:15px;height:15px;flex:none}
3235
+ .dshb-workspace-node-badge:hover{opacity:1}
3236
+ .dshb-workspace-node-badge[data-tone="muted"]{--dshb-node-accent:var(--dsw-alias-label-tertiary)}
3237
+ .dshb-workspace-node-badge[data-tone="warning"]{--dshb-node-accent:var(--dsw-alias-state-warn-label)}
3238
+ .dshb-workspace-node-badge[data-tone="error"]{--dshb-node-accent:var(--dsw-alias-state-error-primary)}
3239
+ .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}
3240
+ .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}
3241
+ .dshb-workspace-node-tooltip[aria-hidden="false"]{display:block}
3242
+ `;
3243
+ document.head.appendChild(style);
3244
+ return style;
3245
+ }
3246
+ async function fetchJson(url) {
3247
+ try {
3248
+ const response = await fetch(url, { cache: "no-store" });
3249
+ if (!response.ok) return void 0;
3250
+ return await response.json();
3251
+ } catch {
3252
+ return;
3253
+ }
3254
+ }
3255
+ function isNode(value) {
3256
+ if (value === null || typeof value !== "object") return false;
3257
+ const node = value;
3258
+ 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");
3259
+ }
3260
+ function isBinding(value) {
3261
+ if (value === null || typeof value !== "object") return false;
3262
+ const binding = value;
3263
+ return typeof binding.mirrorPath === "string" && typeof binding.nodeId === "string" && typeof binding.remotePath === "string" && (binding.workspaceId === void 0 || typeof binding.workspaceId === "string");
3264
+ }
3265
+ function badgeTone(state) {
3266
+ if (state.kind === "bound") return nodeBadgeTone(state.node);
3267
+ if (state.kind === "conflict") return "warning";
3268
+ if (state.kind === "missing-node") return "error";
3269
+ return "muted";
3270
+ }
3271
+ function badgeContent(state) {
3272
+ if (state.kind === "bound") return {
3273
+ icon: NODE_ICON,
3274
+ label: ""
3275
+ };
3276
+ if (state.kind === "missing-node") return {
3277
+ icon: WARNING_ICON,
3278
+ label: ""
3279
+ };
3280
+ if (state.kind === "conflict") return {
3281
+ icon: WARNING_ICON,
3282
+ label: ""
3283
+ };
3284
+ return {
3285
+ icon: "",
3286
+ label: ""
3287
+ };
3288
+ }
3289
+ function directRowChild(row, classPart) {
3290
+ return Array.from(row.children).find((child) => child instanceof HTMLElement && child.className.includes(classPart));
3291
+ }
3292
+ function replaceWorkspaceFolder(state) {
3293
+ return state.kind === "bound" && isRemoteNodeType(state.node.type);
3294
+ }
3295
+ function hideWorkspaceFolder(row) {
3296
+ const folder = directRowChild(row, "folder");
3297
+ if (!folder) return;
3298
+ folder.setAttribute("data-dshb-workspace-folder-hidden", "");
3299
+ folder.style.setProperty("display", "none", "important");
3300
+ }
3301
+ function restoreWorkspaceFolder(row) {
3302
+ const folder = directRowChild(row, "folder");
3303
+ if (!folder) return;
3304
+ folder.removeAttribute("data-dshb-workspace-folder-hidden");
3305
+ folder.style.removeProperty("display");
3306
+ }
3307
+ function badgeSignature(state) {
3308
+ if (state.kind === "unbound") return "unbound";
3309
+ if (state.kind === "missing-node") return JSON.stringify([
3310
+ "missing-node",
3311
+ state.nodeId,
3312
+ state.binding.mirrorPath,
3313
+ state.binding.remotePath
3314
+ ]);
3315
+ if (state.kind === "conflict") return JSON.stringify([
3316
+ "conflict",
3317
+ state.bindings.map((binding) => [
3318
+ binding.nodeId,
3319
+ binding.mirrorPath,
3320
+ binding.remotePath,
3321
+ binding.workspaceId
3322
+ ]),
3323
+ state.nodes.map((node) => [node.id, node.name])
3324
+ ]);
3325
+ return JSON.stringify([
3326
+ "bound",
3327
+ state.node.id,
3328
+ state.node.name,
3329
+ state.node.type,
3330
+ state.node.status?.reachable,
3331
+ state.node.status?.error,
3332
+ state.node.sync?.pendingRemoval,
3333
+ state.node.sync?.credentialsRequired,
3334
+ state.node.sync?.sourceName,
3335
+ state.node.provision?.state,
3336
+ state.node.provision?.error,
3337
+ state.binding.mirrorPath,
3338
+ state.binding.remotePath,
3339
+ state.binding.workspaceId
3340
+ ]);
3341
+ }
3342
+ function installWorkspaceNodeBadges(ctx) {
3343
+ let disposed = false;
3344
+ let loaded = false;
3345
+ let nodes = [];
3346
+ let bindings = [];
3347
+ let refreshToken = 0;
3348
+ let raf = 0;
3349
+ let tooltip;
3350
+ let activeBadge;
3351
+ const style = ensureStyle();
3352
+ const workspaces = ctx.workspaces;
3353
+ const hideTooltip = () => {
3354
+ activeBadge?.removeAttribute("aria-describedby");
3355
+ tooltip?.setAttribute("aria-hidden", "true");
3356
+ activeBadge = void 0;
3357
+ };
3358
+ const positionTooltip = () => {
3359
+ if (!tooltip || !activeBadge) return;
3360
+ const anchor = activeBadge.getBoundingClientRect();
3361
+ const tip = tooltip.getBoundingClientRect();
3362
+ const margin = 8;
3363
+ let top = anchor.bottom + 6;
3364
+ if (top + tip.height > window.innerHeight - margin) top = anchor.top - tip.height - 6;
3365
+ if (top < margin) top = anchor.bottom + 6;
3366
+ const left = Math.max(margin, Math.min(anchor.left, window.innerWidth - tip.width - margin));
3367
+ tooltip.style.left = `${left}px`;
3368
+ tooltip.style.top = `${top}px`;
3369
+ };
3370
+ const showTooltip = (badge, text) => {
3371
+ if (!text) return;
3372
+ if (!tooltip) {
3373
+ tooltip = document.createElement("div");
3374
+ tooltip.id = TOOLTIP_ID;
3375
+ tooltip.className = "dshb-workspace-node-tooltip";
3376
+ tooltip.setAttribute("role", "tooltip");
3377
+ tooltip.setAttribute("aria-hidden", "true");
3378
+ document.body.appendChild(tooltip);
3379
+ }
3380
+ activeBadge = badge;
3381
+ tooltip.textContent = text;
3382
+ tooltip.setAttribute("aria-hidden", "false");
3383
+ badge.setAttribute("aria-describedby", TOOLTIP_ID);
3384
+ positionTooltip();
3385
+ };
3386
+ const applyRowBadge = (row, state) => {
3387
+ const existing = row.querySelector(`:scope > [${BADGE_ATTRIBUTE}]`);
3388
+ if (state.kind === "unbound") {
3389
+ restoreWorkspaceFolder(row);
3390
+ if (existing && activeBadge === existing) hideTooltip();
3391
+ existing?.remove();
3392
+ row.removeAttribute(SIGNATURE_ATTRIBUTE);
3393
+ return;
3394
+ }
3395
+ const anchor = row.querySelector("[class*=\"projectText\"]");
3396
+ if (!anchor || anchor.parentElement !== row) {
3397
+ restoreWorkspaceFolder(row);
3398
+ if (existing && activeBadge === existing) hideTooltip();
3399
+ existing?.remove();
3400
+ row.removeAttribute(SIGNATURE_ATTRIBUTE);
3401
+ return;
3402
+ }
3403
+ const replaceFolder = replaceWorkspaceFolder(state);
3404
+ const folder = directRowChild(row, "folder");
3405
+ const chevron = directRowChild(row, "chevron");
3406
+ const before = replaceFolder ? folder ?? chevron ?? anchor : anchor;
3407
+ if (replaceFolder) hideWorkspaceFolder(row);
3408
+ else restoreWorkspaceFolder(row);
3409
+ const signature = badgeSignature(state);
3410
+ if (existing && row.getAttribute(SIGNATURE_ATTRIBUTE) === signature) {
3411
+ if (existing.nextElementSibling !== before) row.insertBefore(existing, before);
3412
+ return;
3413
+ }
3414
+ const hadFocus = existing === document.activeElement;
3415
+ if (existing && activeBadge === existing) hideTooltip();
3416
+ existing?.remove();
3417
+ const details = nodeBadgeDetails(state);
3418
+ const content = badgeContent(state);
3419
+ const badge = document.createElement("span");
3420
+ badge.className = "dshb-workspace-node-badge";
3421
+ badge.setAttribute(BADGE_ATTRIBUTE, "");
3422
+ badge.setAttribute("role", "img");
3423
+ badge.setAttribute("aria-label", details);
3424
+ badge.dataset.state = state.kind;
3425
+ badge.dataset.tone = badgeTone(state);
3426
+ if (state.kind === "bound") badge.dataset.nodeType = state.node.type;
3427
+ badge.tabIndex = 0;
3428
+ const icon = document.createElement("span");
3429
+ icon.setAttribute("aria-hidden", "true");
3430
+ icon.innerHTML = content.icon;
3431
+ badge.append(icon);
3432
+ if (content.label) {
3433
+ const label = document.createElement("span");
3434
+ label.textContent = content.label;
3435
+ badge.append(label);
3436
+ }
3437
+ badge.addEventListener("click", (event) => event.stopPropagation());
3438
+ badge.addEventListener("mouseenter", () => showTooltip(badge, details));
3439
+ badge.addEventListener("mouseleave", () => {
3440
+ if (activeBadge === badge) hideTooltip();
3441
+ });
3442
+ badge.addEventListener("focus", () => showTooltip(badge, details));
3443
+ badge.addEventListener("blur", () => {
3444
+ if (activeBadge === badge) hideTooltip();
3445
+ });
3446
+ badge.addEventListener("keydown", (event) => {
3447
+ if (event.key === "Escape") {
3448
+ event.stopPropagation();
3449
+ hideTooltip();
3450
+ }
3451
+ });
3452
+ row.insertBefore(badge, before);
3453
+ row.setAttribute(SIGNATURE_ATTRIBUTE, signature);
3454
+ if (hadFocus) badge.focus();
3455
+ };
3456
+ const scan = () => {
3457
+ if (!loaded || !workspaces) return;
3458
+ if (activeBadge && !activeBadge.isConnected) hideTooltip();
3459
+ const items = workspaces.list.getSnapshot().items;
3460
+ const byId = new Map(items.map((workspace) => [workspace.workspaceId, workspace]));
3461
+ for (const row of Array.from(document.querySelectorAll("[data-row-key^=\"workspace:\"]"))) {
3462
+ if (row.closest("[data-dshb-remote-workspaces]")) continue;
3463
+ const workspaceId = (row.getAttribute("data-row-key") ?? "").slice(10);
3464
+ if (!workspaceId) continue;
3465
+ const workspace = byId.get(workspaceId);
3466
+ if (!workspace) continue;
3467
+ applyRowBadge(row, resolveWorkspaceNodeBadge(workspace, bindings, nodes));
3468
+ }
3469
+ };
3470
+ const schedule = () => {
3471
+ if (disposed || raf !== 0) return;
3472
+ raf = requestAnimationFrame(() => {
3473
+ raf = 0;
3474
+ scan();
3475
+ });
3476
+ };
3477
+ const refresh = async () => {
3478
+ const token = ++refreshToken;
3479
+ const [nodeBody, bindingBody] = await Promise.all([fetchJson("/api/dshb/nodes"), fetchJson("/api/dshb/workspaces")]);
3480
+ if (disposed || token !== refreshToken || !nodeBody || !bindingBody) return;
3481
+ if (!Array.isArray(nodeBody.nodes) || !Array.isArray(bindingBody.bindings)) return;
3482
+ nodes = nodeBody.nodes.filter(isNode);
3483
+ bindings = bindingBody.bindings.filter(isBinding);
3484
+ loaded = true;
3485
+ schedule();
3486
+ };
3487
+ const onRefresh = () => {
3488
+ refresh();
3489
+ };
3490
+ const onScroll = () => {
3491
+ hideTooltip();
3492
+ };
3493
+ const observer = new MutationObserver(schedule);
3494
+ observer.observe(document.body, {
3495
+ childList: true,
3496
+ subtree: true
3497
+ });
3498
+ const unsubscribe = workspaces?.list.subscribe(schedule);
3499
+ window.addEventListener("focus", onRefresh);
3500
+ window.addEventListener("dshb:nodes-changed", onRefresh);
3501
+ window.addEventListener("dshb:workspace-bindings-changed", onRefresh);
3502
+ window.addEventListener("dshb:sync-peers-changed", onRefresh);
3503
+ window.addEventListener("scroll", onScroll, true);
3504
+ window.addEventListener("resize", onScroll);
3505
+ const timer = setInterval(onRefresh, 6e4);
3506
+ schedule();
3507
+ refresh();
3508
+ return () => {
3509
+ disposed = true;
3510
+ refreshToken += 1;
3511
+ observer.disconnect();
3512
+ unsubscribe?.();
3513
+ if (raf !== 0) cancelAnimationFrame(raf);
3514
+ clearInterval(timer);
3515
+ window.removeEventListener("focus", onRefresh);
3516
+ window.removeEventListener("dshb:nodes-changed", onRefresh);
3517
+ window.removeEventListener("dshb:workspace-bindings-changed", onRefresh);
3518
+ window.removeEventListener("dshb:sync-peers-changed", onRefresh);
3519
+ window.removeEventListener("scroll", onScroll, true);
3520
+ window.removeEventListener("resize", onScroll);
3521
+ hideTooltip();
3522
+ tooltip?.remove();
3523
+ for (const badge of Array.from(document.querySelectorAll(`[${BADGE_ATTRIBUTE}]`))) badge.remove();
3524
+ for (const row of Array.from(document.querySelectorAll(`[${SIGNATURE_ATTRIBUTE}]`))) row.removeAttribute(SIGNATURE_ATTRIBUTE);
3525
+ for (const folder of Array.from(document.querySelectorAll("[data-dshb-workspace-folder-hidden]"))) {
3526
+ folder.removeAttribute("data-dshb-workspace-folder-hidden");
3527
+ folder.style.removeProperty("display");
3528
+ }
3529
+ style.remove();
3530
+ };
3531
+ }
3532
+ //#endregion
2904
3533
  //#region src/client/remote-session-bootstrap.ts
2905
3534
  /**
2906
3535
  * 远端会话定位引导:本地端经 relay 打开远端 DSH 时通过
@@ -5039,7 +5668,10 @@ window.__ModuleLoader__.load({
5039
5668
  setNotice(n);
5040
5669
  if (n) setTimeout(() => setNotice(void 0), 6e3);
5041
5670
  }, []);
5042
- const reload = (0, react.useCallback)(() => setReloadKey((k) => k + 1), []);
5671
+ const reload = (0, react.useCallback)(() => {
5672
+ setReloadKey((k) => k + 1);
5673
+ window.dispatchEvent(new Event("dshb:nodes-changed"));
5674
+ }, []);
5043
5675
  (0, react.useEffect)(() => {
5044
5676
  (async () => {
5045
5677
  try {
@@ -6002,8 +6634,10 @@ window.__ModuleLoader__.load({
6002
6634
  `;
6003
6635
  document.head.appendChild(globalStyle);
6004
6636
  installMobile(ctx);
6637
+ installMenuAnchorFallback();
6005
6638
  openRemoteSessionFromHash(ctx);
6006
6639
  registerWorkspaceInstructionMenu(ctx);
6640
+ installWorkspaceNodeBadges(ctx);
6007
6641
  ctx.plugin({
6008
6642
  inject: ["slots"],
6009
6643
  apply: (sub) => {