dsh-desktop-statusbar 3.0.5 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -76,7 +76,7 @@ window.__ModuleLoader__.load({
76
76
  */
77
77
  const CONFIG_VERSION = 6;
78
78
  /** 插件版本:显示在设置页底部,用来确认页面加载的是哪一版客户端代码。 */
79
- const VERSION = "3.0.5";
79
+ const VERSION = "3.0.6";
80
80
  /** 官方参考价的版本:官方调价时改这个数字,老价格库会自动并入新参考价。
81
81
  * v4:官方模型目录(MODEL_PRESENTATION)**默认全部加入价格表**(按官网价播种),
82
82
  * 不再需要「点名字加入」;用户删掉的模型可用「恢复默认」找回。
@@ -578,6 +578,22 @@ function normalizePlatforms(raw) {
578
578
  });
579
579
  return out;
580
580
  }
581
+ /**
582
+ * 平台显示顺序:显式数组优先(只认仍存在的平台、去重);
583
+ * 数组里没有的平台(旧配置迁移 / 手改配置)按对象键序补在末尾,保证不丢平台。
584
+ * 不能直接用 Object.keys 当显示顺序:纯数字平台名会被 JS 对象按数值排到最前。
585
+ */
586
+ function normalizePlatformOrder(raw, platforms) {
587
+ const table = platforms === null || platforms === undefined || typeof platforms !== "object" ? {} : platforms;
588
+ const out = [];
589
+ (Array.isArray(raw) ? raw : []).forEach((name) => {
590
+ if (typeof name === "string" && Object.prototype.hasOwnProperty.call(table, name) && out.indexOf(name) === -1) out.push(name);
591
+ });
592
+ Object.keys(table).forEach((name) => {
593
+ if (out.indexOf(name) === -1) out.push(name);
594
+ });
595
+ return out;
596
+ }
581
597
  /**
582
598
  * 平台档案里的模型名 ↔ 价格条目键:**宽容匹配**(同名或归一化紧凑串相同,与 pickPriceKey 同一套口径)。
583
599
  * 平台里存的是价格库键,但迁移 / 手改配置来的名字可能带 provider 前缀或不同分隔符。
@@ -2075,6 +2091,7 @@ function platformOfBook(book, platforms, model) {
2075
2091
  platformEmpty: "还没有第三方平台。",
2076
2092
  platformModels: "适用模型",
2077
2093
  platformModelSelectPh: "请选择模型",
2094
+ platformModelNoMatch: "无匹配模型",
2078
2095
  platformFeePh: "如 0.02",
2079
2096
  platformAddModel: "添加模型",
2080
2097
  platformNameRequired: "平台名称不能为空。",
@@ -2248,6 +2265,7 @@ function platformOfBook(book, platforms, model) {
2248
2265
  platformEmpty: "No third-party platforms yet.",
2249
2266
  platformModels: "Applicable models",
2250
2267
  platformModelSelectPh: "Select a model",
2268
+ platformModelNoMatch: "No matching models",
2251
2269
  platformFeePh: "e.g. 0.02",
2252
2270
  platformAddModel: "Add model",
2253
2271
  platformNameRequired: "Platform name is required.",
@@ -2412,6 +2430,7 @@ function platformOfBook(book, platforms, model) {
2412
2430
  "platformEmpty": "サードパーティプラットフォームはまだありません。",
2413
2431
  "platformModels": "対象モデル",
2414
2432
  "platformModelSelectPh": "モデルを選択",
2433
+ "platformModelNoMatch": "一致するモデルがありません",
2415
2434
  "platformFeePh": "例:0.02",
2416
2435
  "platformAddModel": "モデルを追加",
2417
2436
  "platformNameRequired": "プラットフォーム名は必須です。",
@@ -2572,6 +2591,7 @@ function platformOfBook(book, platforms, model) {
2572
2591
  "platformEmpty": "Aún no hay plataformas de terceros.",
2573
2592
  "platformModels": "Modelos aplicables",
2574
2593
  "platformModelSelectPh": "Selecciona un modelo",
2594
+ "platformModelNoMatch": "No hay modelos coincidentes",
2575
2595
  "platformFeePh": "p. ej. 0.02",
2576
2596
  "platformAddModel": "Añadir modelo",
2577
2597
  "platformNameRequired": "El nombre de la plataforma es obligatorio.",
@@ -2732,6 +2752,7 @@ function platformOfBook(book, platforms, model) {
2732
2752
  "platformEmpty": "Aucune plateforme tierce pour le moment.",
2733
2753
  "platformModels": "Modèles applicables",
2734
2754
  "platformModelSelectPh": "Sélectionner un modèle",
2755
+ "platformModelNoMatch": "Aucun modèle correspondant",
2735
2756
  "platformFeePh": "ex. 0.02",
2736
2757
  "platformAddModel": "Ajouter un modèle",
2737
2758
  "platformNameRequired": "Le nom de la plateforme est obligatoire.",
@@ -2892,6 +2913,7 @@ function platformOfBook(book, platforms, model) {
2892
2913
  "platformEmpty": "Noch keine Drittanbieter-Plattformen.",
2893
2914
  "platformModels": "Passende Modelle",
2894
2915
  "platformModelSelectPh": "Modell auswählen",
2916
+ "platformModelNoMatch": "Keine passenden Modelle",
2895
2917
  "platformFeePh": "z. B. 0.02",
2896
2918
  "platformAddModel": "Modell hinzufügen",
2897
2919
  "platformNameRequired": "Der Plattformname ist erforderlich.",
@@ -3052,6 +3074,7 @@ function platformOfBook(book, platforms, model) {
3052
3074
  "platformEmpty": "Сторонних платформ пока нет.",
3053
3075
  "platformModels": "Подходящие модели",
3054
3076
  "platformModelSelectPh": "Выберите модель",
3077
+ "platformModelNoMatch": "Нет подходящих моделей",
3055
3078
  "platformFeePh": "напр. 0.02",
3056
3079
  "platformAddModel": "Добавить модель",
3057
3080
  "platformNameRequired": "Укажите название платформы.",
@@ -3212,6 +3235,7 @@ function platformOfBook(book, platforms, model) {
3212
3235
  "platformEmpty": "Ainda não há plataformas de terceiros.",
3213
3236
  "platformModels": "Modelos aplicáveis",
3214
3237
  "platformModelSelectPh": "Selecionar um modelo",
3238
+ "platformModelNoMatch": "Nenhum modelo correspondente",
3215
3239
  "platformFeePh": "ex.: 0.02",
3216
3240
  "platformAddModel": "Adicionar modelo",
3217
3241
  "platformNameRequired": "O nome da plataforma é obrigatório.",
@@ -3326,6 +3350,8 @@ function platformOfBook(book, platforms, model) {
3326
3350
  holidayDays: [],
3327
3351
  /* 第三方平台档案(非密):平台名 → { endpoint, userIdHeader, balancePath, currency, balanceDivisor, models } */
3328
3352
  relayPlatforms: {},
3353
+ /* 平台显示顺序(平台名数组)。JS 对象对纯数字键按数值排序,不能靠 Object.keys 保序。 */
3354
+ relayPlatformOrder: [],
3329
3355
  catalogOrder: DEFAULT_CATALOG_ORDER.slice()
3330
3356
  };
3331
3357
  try {
@@ -3427,6 +3453,9 @@ function platformOfBook(book, platforms, model) {
3427
3453
  models: [{ model: name, feeMultiplier: models[name].feeMultiplier }]
3428
3454
  });
3429
3455
  });
3456
+ /* 平台显示顺序:显式数组优先;旧配置没有该数组时按当前 Object.keys(relayPlatforms)
3457
+ 初始化(保留既有显示顺序),数组里缺的平台按对象键序补在末尾,绝不丢平台。 */
3458
+ const relayPlatformOrder = normalizePlatformOrder(parsed.relayPlatformOrder, relayPlatforms);
3430
3459
  /* 旧版取消勾选「峰谷计价」时会把空闲价写成高峰价的副本,再勾回来也回不去。
3431
3460
  这里按参考价补回:只修"勾着峰谷计价、两档却完全相同"的官方模型。 */
3432
3461
  Object.keys(reference).forEach((name) => {
@@ -3456,6 +3485,7 @@ function platformOfBook(book, platforms, model) {
3456
3485
  models: Object.keys(models).length > 0 ? models : normalizeModels(officialDefaultModels(currency), currency),
3457
3486
  modelOrder: modelOrder.length > 0 ? modelOrder : Object.keys(officialDefaultModels(currency)),
3458
3487
  relayPlatforms: relayPlatforms,
3488
+ relayPlatformOrder: relayPlatformOrder,
3459
3489
  catalogOrder: catalogOrder,
3460
3490
  /* 抓来的放假日历:字符串数组,按年分组在 refreshHolidays() 里做 */
3461
3491
  holidayDays: Array.isArray(parsed.holidayDays)
@@ -3477,6 +3507,8 @@ function platformOfBook(book, platforms, model) {
3477
3507
  function snapshot() { return config; }
3478
3508
  function setConfig(patch) {
3479
3509
  config = Object.assign({ version: CONFIG_VERSION }, config, patch);
3510
+ /* 平台顺序不变量:保留既有顺序;已删平台剔除;数组里缺的平台按对象键序补到末尾。 */
3511
+ config.relayPlatformOrder = normalizePlatformOrder(config.relayPlatformOrder, config.relayPlatforms);
3480
3512
  refreshHolidays();
3481
3513
  try { window.localStorage.setItem(STORAGE_KEY, JSON.stringify(config)); } catch (error) { /* 隐私模式下仅内存生效 */ }
3482
3514
  listeners.forEach((fn) => { try { fn(); } catch (error) { /* 单个订阅者失败不影响其余 */ } });
@@ -3489,6 +3521,9 @@ function platformOfBook(book, platforms, model) {
3489
3521
  绝不写进 localStorage / config。 */
3490
3522
  let relayState = { loaded: false, models: {} };
3491
3523
  let relayLoading = null;
3524
+ let relayLoadSeq = 0;
3525
+ /* 最近一次 loadRelayState 是否真正拿到 Host 新快照(ok:true)。force 刷新失败时为 false。 */
3526
+ let relayLoadOk = false;
3492
3527
  const relayListeners = new Set();
3493
3528
  function relaySnapshot() { return relayState; }
3494
3529
  function subscribeRelayState(fn) {
@@ -3507,23 +3542,37 @@ function publishRelayState(channels) {
3507
3542
  relayState = { loaded: true, models: models };
3508
3543
  relayListeners.forEach((fn) => { try { fn(); } catch (error) { /* 单个订阅者失败不影响其余 */ } });
3509
3544
  }
3510
- /** 首次需要时 GET 一次(模块级缓存)。 */
3511
- function ensureRelayState() {
3512
- if (relayState.loaded === true) return Promise.resolve(relayState);
3513
- if (relayLoading !== null) return relayLoading;
3514
- relayLoading = window.fetch(RELAY_URL, { cache: "no-store" })
3545
+ /**
3546
+ * 拉取 Host relay-balance-config。force=true 时忽略已加载缓存与在途请求,强制重新 GET。
3547
+ * 用单调序号保证只有**最新一次**请求的结果能 publish:并发 / 强制刷新时旧的空结果不会覆盖新快照
3548
+ * (后台自动探测可能随时写回真实 endpoint/解析字段,陈旧空快照会让编辑区回显/保存用默认值覆盖)。
3549
+ */
3550
+ function loadRelayState(force) {
3551
+ if (force !== true && relayState.loaded === true) return Promise.resolve(relayState);
3552
+ if (force !== true && relayLoading !== null) return relayLoading;
3553
+ const seq = ++relayLoadSeq;
3554
+ const run = window.fetch(RELAY_URL, { cache: "no-store" })
3515
3555
  .then((response) => response.json())
3516
3556
  .then((data) => {
3517
- if (data !== null && data !== undefined && data.ok === true) publishRelayState(data.channels);
3557
+ const ok = data !== null && data !== undefined && data.ok === true;
3558
+ if (seq === relayLoadSeq) {
3559
+ relayLoadOk = ok;
3560
+ if (ok) publishRelayState(data.channels);
3561
+ }
3518
3562
  return relayState;
3519
3563
  })
3520
- .catch(() => relayState)
3564
+ .catch(() => { if (seq === relayLoadSeq) relayLoadOk = false; return relayState; })
3521
3565
  .then((result) => {
3522
- relayLoading = null;
3566
+ if (seq === relayLoadSeq) relayLoading = null;
3523
3567
  return result;
3524
3568
  });
3525
- return relayLoading;
3569
+ relayLoading = run;
3570
+ return run;
3526
3571
  }
3572
+ /** 首次需要时 GET 一次(模块级缓存)。 */
3573
+ function ensureRelayState() { return loadRelayState(false); }
3574
+ /** 打开平台编辑区前强制刷新,避免复用旧的空 in-flight/loaded 快照。 */
3575
+ function refreshRelayState() { return loadRelayState(true); }
3527
3576
  /** 保存 / 移除某个模型的中转站配置;响应里的布尔状态刷新本地缓存。 */
3528
3577
  function postRelayState(payload) {
3529
3578
  return window.fetch(RELAY_URL, {
@@ -3535,6 +3584,12 @@ function postRelayState(payload) {
3535
3584
  return data;
3536
3585
  });
3537
3586
  }
3587
+ /** 宿主当前快照里该平台的记录(没有则 null):判断 Host 是否已有可用地址 / 运行时默认值。 */
3588
+ function relayChannelOf(name) {
3589
+ return relayState.models === null || relayState.models === undefined
3590
+ ? null
3591
+ : (relayState.models[name] === undefined ? null : relayState.models[name]);
3592
+ }
3538
3593
  function useRelayState() {
3539
3594
  return react.useSyncExternalStore(subscribeRelayState, relaySnapshot, relaySnapshot);
3540
3595
  }
@@ -7148,7 +7203,7 @@ function setModelCurrency(name, code, draftNow) {
7148
7203
  ".dsb-settings .dsb-modelrow-fee{flex:1 1 0;min-width:0;display:flex;align-items:center;gap:8px}",
7149
7204
  ".dsb-settings .dsb-modelrow-fee .dsb-action{margin-left:auto;flex:none}",
7150
7205
  ".dsb-settings .dsb-select-empty .dsb-select-btn{color:var(--dsw-alias-label-tertiary);opacity:1;background:color-mix(in srgb, var(--dsw-specific-menu,#f8f9fa) 55%, var(--dsw-alias-bg-layer-1,#fff))}",
7151
- ".dsb-settings .dsb-select-placeholder{opacity:.5}",
7206
+
7152
7207
  ".dsb-settings .dsb-modelrow-fee input[type=number]{width:calc(5ch + 18px);min-width:calc(5ch + 18px);text-align:left}",
7153
7208
  ".dsb-settings .dsb-relay-fields .dsb-action{flex:none}",
7154
7209
  /* 价格行不换行:档位名与后面那组价格框始终同一行;空间不够时由 .dsb-fields 内部换行 */
@@ -7204,12 +7259,17 @@ function setModelCurrency(name, code, draftNow) {
7204
7259
  ".dsb-settings .dsb-select-item-on{color:var(--dsw-alias-brand-primary,#4d6bfe)}",
7205
7260
  /* 已被本平台其他行选中的模型:灰显、不可点 */
7206
7261
  ".dsb-settings .dsb-select-item-disabled{opacity:.45;cursor:not-allowed}",
7207
- /* 平台「适用模型」下拉:占满左侧列,菜单强制向下、限制在设置页内 */
7262
+ /* 平台「适用模型」下拉:portal 到 body + fixed 定位,最多 3 项完整可见、始终向下并按实际空间限高、不超出视口 */
7208
7263
  ".dsb-settings .dsb-modelrow-select{flex:1 1 0;min-width:0}",
7209
7264
  ".dsb-settings .dsb-modelrow-select .dsb-select-btn{display:flex;width:100%;height:28px;box-sizing:border-box;font-size:13px;justify-content:flex-start;text-align:left;white-space:nowrap;overflow:hidden}",
7210
- ".dsb-settings .dsb-modelrow-menu{box-sizing:border-box;max-width:100%;max-height:calc(3 * 30px + 8px);overflow-y:auto;overscroll-behavior:contain;scrollbar-width:none;background:rgb(from var(--dsw-specific-menu,var(--dsw-alias-bg-layer-1,#1f1f1f)) r g b / .382);backdrop-filter:var(--dsw-menu-backdrop-filter,blur(40px) saturate(150%));-webkit-backdrop-filter:var(--dsw-menu-backdrop-filter,blur(40px) saturate(150%))}",
7211
- ".dsb-settings .dsb-modelrow-menu::-webkit-scrollbar{display:none;width:0;height:0}",
7212
- ".dsb-settings .dsb-modelrow-menu .dsb-select-item{display:flex;align-items:center;height:30px;box-sizing:border-box;padding:0 10px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
7265
+ ".dsb-settings .dsb-modelrow-select .dsb-select-btn{cursor:text}",
7266
+ /* 菜单 portal 到 body、fixed 定位,样式不能再只挂 .dsb-settings 作用域(脱离设置区后会丢磨砂/宽度/高度约束) */
7267
+ ".dsb-modelrow-menu{box-sizing:border-box;position:fixed;padding:4px;border-radius:var(--dsw-radius-lg,16px);background:rgb(from var(--dsw-specific-menu,var(--dsw-alias-bg-layer-1,#1f1f1f)) r g b / .382);backdrop-filter:var(--dsw-menu-backdrop-filter,blur(40px) saturate(150%));-webkit-backdrop-filter:var(--dsw-menu-backdrop-filter,blur(40px) saturate(150%));box-shadow:0 0 0 .5px var(--dsw-alias-border-l1,rgba(127,127,127,.3));z-index:1100;max-width:100%;max-height:calc(3 * 30px + 8px);overflow-y:auto;overscroll-behavior:contain;scrollbar-width:none}",
7268
+ ".dsb-modelrow-menu::-webkit-scrollbar{display:none;width:0;height:0}",
7269
+ ".dsb-modelrow-menu .dsb-select-item{display:flex;align-items:center;width:100%;height:30px;box-sizing:border-box;padding:0 10px;border:0;border-radius:var(--dsw-radius-sm,8px);background:transparent;font:inherit;font-size:12px;color:var(--dsw-alias-label-primary);text-align:left;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
7270
+ ".dsb-modelrow-menu .dsb-select-item:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}",
7271
+ ".dsb-modelrow-menu .dsb-select-item-on{color:var(--dsw-alias-brand-primary,#4d6bfe)}",
7272
+ ".dsb-modelrow-menu .dsb-select-item-disabled{opacity:.45;cursor:not-allowed}",
7213
7273
  /* 三组字段整体贴右边缘:左边留给时段名,右边一列对齐。
7214
7274
  未勾选「峰谷计价」时那行也走同一套 —— 左边是「全时段」标签,
7215
7275
  不再用"单档那行没有档位名"时的那条双边对齐规则(用户嫌它跟勾选后的两行不一致)。 */
@@ -10792,7 +10852,7 @@ function setModelCurrency(name, code, draftNow) {
10792
10852
  不新增 useState 是为了保持 tools/shot.cjs 截图 presets 的 hook 下标不变(有测试盯着那张表)。
10793
10853
  true = 展开;addModel 自动置 true,用户手动开合时同步。 */
10794
10854
  const [catalogNotice, setCatalogNotice] = react.useState(false);
10795
- /* platformModelOpen 状态槽:平台「适用模型」下拉展开行号。 */
10855
+ /* platformModelOpen 状态槽:平台「适用模型」下拉的展开状态;打开时为 { index, filter }(筛选文本),收起为 null。不新增 hook。 */
10796
10856
  const [platformModelOpen, setPlatformModelOpen] = react.useState(null);
10797
10857
  const [currencyOpen, setCurrencyOpen] = react.useState(false);
10798
10858
  /* 第三方平台区块:平台名(编辑中)/ 草稿 / 校验提示 / 新平台名输入框。
@@ -10807,37 +10867,133 @@ function setModelCurrency(name, code, draftNow) {
10807
10867
  const editPopRef = react.useRef(null);
10808
10868
  /* 币种下拉的**菜单节点**(不是那个按钮):展开后要把它滚进视野 */
10809
10869
  const currencyMenuRef = react.useRef(null);
10810
- /* 平台编辑区节点:点「添加平台」/加模型行后把它的底边带进视野 */
10870
+ /* 平台编辑区节点:仅当用户点「添加模型」增加行时才把它的底边带进视野(打开编辑区本身不滚) */
10811
10871
  const platformEditRef = react.useRef(null);
10872
+ /* task-14:记录上次的平台名 + 模型行数,仅用于判断「同一平台是否新增了模型行」;
10873
+ 同一平台行数增加才补滚,打开 / 切换平台都不滚(原地展开,不跳到固定位置)。 */
10874
+ const platformRevealLenRef = react.useRef(null);
10875
+ /* task-31:平台打开时代次,用于丢弃过期的强制刷新回调(切平台 / 保存后不再回填)。 */
10876
+ const platformRefreshSeqRef = react.useRef(0);
10877
+ /* task-33:当前平台强制刷新的进行中 promise(用于把过早的自动保存延后到刷新完成)。 */
10878
+ const platformRefreshPendingRef = react.useRef(null);
10879
+ /* task-35:最近一次强制刷新是否成功(false = GET 失败/5xx,快照可能已陈旧)。 */
10880
+ const platformRefreshOkRef = react.useRef(true);
10812
10881
  /* 当前展开平台行的头部节点:外部点击保存时,头部内的点击(保存/删除/平台名)不在此处重复处理 */
10813
10882
  const platformHeadRef = react.useRef(null);
10814
10883
  /* 平台「适用模型」下拉的菜单节点:用于外部点击判定 */
10815
10884
  const platformModelMenuRef = react.useRef(null);
10816
- /* 模型下拉打开那一下算好的定位(相对最近的 .dsb-model)与菜单挂载目标节点 */
10885
+ /* 模型下拉打开那一下算好的定位(fixed 视口坐标:left/宽度/maxHeight/top) */
10817
10886
  const platformModelMenuPosRef = react.useRef(null);
10818
- const platformModelMenuTargetRef = react.useRef(null);
10819
10887
  /* 模型下拉的锚点按钮:打开期间靠它找内部滚动容器 */
10820
10888
  const platformModelAnchorRef = react.useRef(null);
10821
- /* 模型下拉打开期间:监听内部容器与外层的滚动/滚轮并立即收起。
10822
- 外层设置页的实际滚动可能不在菜单内部容器上,所以再用 window 捕获阶段兜底。 */
10889
+ /* 模型下拉打开期间:菜单内部滚动放行;只有落在设置区(.dsb-settings 内部或包住它的真实滚动祖先)
10890
+ 的滚动/滚轮才收起;输入框上的 wheel 改滚候选菜单;DSH 对话区自身的程序滚动不收起。 */
10823
10891
  react.useEffect(() => {
10824
10892
  if (platformModelOpen === null) return undefined;
10825
10893
  const anchor = platformModelAnchorRef.current;
10826
- const close = () => setPlatformModelOpen(null);
10827
- const closeNow = () => { const m = platformModelMenuRef.current; if (m !== null && m !== undefined && m.style !== undefined) m.style.display = "none"; setPlatformModelOpen(null); };
10894
+ const menu = platformModelMenuRef.current;
10895
+ const closeNow = () => {
10896
+ const state = platformModelOpen;
10897
+ if (state !== null && state !== undefined && state.dirty === true) {
10898
+ const index = state.index;
10899
+ const model = typeof state.filter === "string" ? state.filter : "";
10900
+ setPlatformModelRow(index, { model: model });
10901
+ }
10902
+ const m = platformModelMenuRef.current;
10903
+ if (m !== null && m !== undefined && m.style !== undefined) m.style.display = "none";
10904
+ setPlatformModelOpen(null);
10905
+ };
10906
+ /* 设置区归属:以 input 锚点所属的 .dsb-settings 为准,再找真正包住设置 root 的滚动祖先。
10907
+ menu 可能被 portal 到别处,不能拿 menu 反推设置区;滚动来源只有落在设置 root 内部
10908
+ 或那个真实滚动祖先上才算“设置滚动”,DSH 对话区自身(message-list 等)的程序滚动一律放行。 */
10909
+ const isNode = (value) => value !== null && value !== undefined;
10910
+ const containsNode = (parent, child) => isNode(parent) && isNode(child) && typeof parent.contains === "function" && parent.contains(child) === true;
10911
+ const settingsRoot = isNode(anchor) && typeof anchor.closest === "function" ? anchor.closest(".dsb-settings") : null;
10912
+ const findScrollAncestor = (start) => {
10913
+ let node = isNode(start) ? start.parentElement : null;
10914
+ while (isNode(node)) {
10915
+ let scrollable = false;
10916
+ try {
10917
+ if (typeof getComputedStyle === "function") {
10918
+ const cs = getComputedStyle(node);
10919
+ scrollable = isNode(cs) && (cs.overflowY === "auto" || cs.overflowY === "scroll");
10920
+ }
10921
+ } catch (err) { scrollable = false; }
10922
+ if (scrollable !== true && typeof node.scrollHeight === "number" && typeof node.clientHeight === "number") scrollable = node.scrollHeight > node.clientHeight + 2;
10923
+ if (scrollable === true) return node;
10924
+ node = node.parentElement;
10925
+ }
10926
+ return null;
10927
+ };
10928
+ const settingsScroller = findScrollAncestor(isNode(settingsRoot) ? settingsRoot : anchor);
10929
+ const isOuterPageScroll = (target) => typeof document !== "undefined" && isNode(document) && (target === document || target === document.documentElement || target === document.body);
10930
+ const isSettingsScroll = (event) => {
10931
+ const target = isNode(event) ? event.target : null;
10932
+ if (isNode(target) !== true) return false;
10933
+ if (containsNode(settingsRoot, target)) return true;
10934
+ if (containsNode(target, settingsRoot)) return true; /* target 是包住设置 root 的实际滚动祖先 */
10935
+ if (isNode(settingsScroller) && (target === settingsScroller || containsNode(settingsScroller, target))) return true;
10936
+ if (isOuterPageScroll(target)) return true;
10937
+ /* 解析不到设置 root 时退回旧行为(非菜单就关),避免漏关;解析得到时只认设置区。 */
10938
+ return isNode(settingsRoot) !== true;
10939
+ };
10940
+ const isInputWheel = (event) => isNode(event) && event.type === "wheel" && containsNode(anchor, event.target);
10941
+ const menuCanScroll = (node, deltaY) => {
10942
+ if (!isNode(node) || typeof node.scrollTop !== "number" || typeof node.scrollHeight !== "number"
10943
+ || typeof node.clientHeight !== "number" || typeof deltaY !== "number"
10944
+ || Number.isFinite(deltaY) !== true || deltaY === 0) return false;
10945
+ const maxScroll = Math.max(0, node.scrollHeight - node.clientHeight);
10946
+ const top = Math.max(0, Math.min(maxScroll, node.scrollTop));
10947
+ return deltaY > 0 ? top < maxScroll : top > 0;
10948
+ };
10949
+ const routeWheelToMenu = (event) => {
10950
+ const m = platformModelMenuRef.current;
10951
+ const deltaY = event !== null && event !== undefined ? event.deltaY : undefined;
10952
+ if (menuCanScroll(m, deltaY) !== true) return false;
10953
+ const maxScroll = Math.max(0, m.scrollHeight - m.clientHeight);
10954
+ m.scrollTop = Math.max(0, Math.min(maxScroll, m.scrollTop + deltaY));
10955
+ if (typeof event.preventDefault === "function") event.preventDefault();
10956
+ if (typeof event.stopPropagation === "function") event.stopPropagation();
10957
+ return true;
10958
+ };
10959
+ /* 菜单内部滚动不关闭:下拉自身就是 overflow-y:auto 的滚动容器,滚它时事件目标在菜单里。
10960
+ window 的捕获监听先于菜单自身的监听触发,所以必须在这里用 contains 放行;
10961
+ 菜单再拦一层 wheel/touchmove 冒泡,别让外层 document 的关闭逻辑看到。
10962
+ window 的 wheel 捕获监听必须非 passive:输入框滚轮要 preventDefault 把 deltaY 改滚候选菜单、不传给背景;
10963
+ 菜单自身的 wheel/touchmove 仍只 stopPropagation、不 preventDefault,照常滚动。 */
10964
+ const isMenuEvent = (event) => {
10965
+ const node = platformModelMenuRef.current;
10966
+ const target = event !== null && event !== undefined ? event.target : null;
10967
+ return node !== null && node !== undefined && target !== null && target !== undefined
10968
+ && typeof node.contains === "function" && node.contains(target) === true;
10969
+ };
10970
+ const closeOnScroll = (event) => {
10971
+ if (isMenuEvent(event) === true) return; /* B:菜单内部滚动不关闭 */
10972
+ if (isInputWheel(event) === true && routeWheelToMenu(event) === true) return; /* A:仅菜单能沿 delta 方向滚动时接管输入框滚轮 */
10973
+ if (isSettingsScroll(event) === true) closeNow(); /* C/E:只有真实设置区滚动才关闭 */
10974
+ };
10975
+ const stopMenuScroll = (event) => { if (event !== null && event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation(); };
10828
10976
  const pop = anchor !== null && anchor !== undefined && typeof anchor.closest === "function" ? anchor.closest(".dsb-platform-pop") : null;
10829
10977
  const list = anchor !== null && anchor !== undefined && typeof anchor.closest === "function" ? anchor.closest(".dsb-platform-model-list") : null;
10830
- if (pop !== null && pop !== undefined) pop.addEventListener("scroll", close, { passive: true });
10831
- if (list !== null && list !== undefined) list.addEventListener("scroll", close, { passive: true });
10832
- window.addEventListener("scroll", closeNow, true);
10833
- window.addEventListener("wheel", closeNow, { passive: true, capture: true });
10834
- window.addEventListener("touchmove", closeNow, { passive: true, capture: true });
10978
+ if (pop !== null && pop !== undefined) pop.addEventListener("scroll", closeOnScroll, { passive: true });
10979
+ if (list !== null && list !== undefined) list.addEventListener("scroll", closeOnScroll, { passive: true });
10980
+ if (menu !== null && menu !== undefined && typeof menu.addEventListener === "function") {
10981
+ menu.addEventListener("wheel", stopMenuScroll, { passive: true });
10982
+ menu.addEventListener("touchmove", stopMenuScroll, { passive: true });
10983
+ }
10984
+ window.addEventListener("scroll", closeOnScroll, true);
10985
+ window.addEventListener("wheel", closeOnScroll, { passive: false, capture: true });
10986
+ window.addEventListener("touchmove", closeOnScroll, { passive: true, capture: true });
10835
10987
  return () => {
10836
- if (pop !== null && pop !== undefined) pop.removeEventListener("scroll", close);
10837
- if (list !== null && list !== undefined) list.removeEventListener("scroll", close);
10838
- window.removeEventListener("scroll", closeNow, true);
10839
- window.removeEventListener("wheel", closeNow, { passive: true, capture: true });
10840
- window.removeEventListener("touchmove", closeNow, { passive: true, capture: true });
10988
+ if (pop !== null && pop !== undefined) pop.removeEventListener("scroll", closeOnScroll);
10989
+ if (list !== null && list !== undefined) list.removeEventListener("scroll", closeOnScroll);
10990
+ if (menu !== null && menu !== undefined && typeof menu.removeEventListener === "function") {
10991
+ menu.removeEventListener("wheel", stopMenuScroll);
10992
+ menu.removeEventListener("touchmove", stopMenuScroll);
10993
+ }
10994
+ window.removeEventListener("scroll", closeOnScroll, true);
10995
+ window.removeEventListener("wheel", closeOnScroll, { passive: false, capture: true });
10996
+ window.removeEventListener("touchmove", closeOnScroll, { passive: true, capture: true });
10841
10997
  };
10842
10998
  }, [platformModelOpen]);
10843
10999
  /* 平台编辑气泡:绘制前按实际高度决定向上/向下弹 */
@@ -10897,9 +11053,31 @@ function setModelCurrency(name, code, draftNow) {
10897
11053
  /* 币种下拉菜单(CNY/USD):展开后同样按底部溢出量滚进视野。
10898
11054
  用户实测反馈"还要手动滚一下"的就是它 —— 上一轮只接到了价格编辑浮层。 */
10899
11055
  useRevealBottom(currencyMenuRef, currencyOpen === true, null);
10900
- /* 平台编辑区(行内展开):点「添加平台」后、以及加适用模型行后,把编辑区底边带进视野 */
10901
- useRevealBottom(platformEditRef, platformEditing !== null,
10902
- platformDraft === null ? null : String(platformEditing) + "|" + String(platformDraft.modelRows.length));
11056
+ /* 平台编辑区(行内展开):task-14 — 打开编辑区**不再**平白滚动(用户要求原地展开、
11057
+ 不跳到固定位置);只有用户点「添加模型」让行数增加时,才把编辑区底边带进视野
11058
+ (保留原来的自动露出行为)。用 prev 记录上次「平台名 + 行数」:首次进入 / 换平台
11059
+ 都视为打开、不滚;同一平台行数增加才补滚。 */
11060
+ react.useEffect(() => {
11061
+ if (platformEditing === null || platformDraft === null) {
11062
+ platformRevealLenRef.current = null;
11063
+ return undefined;
11064
+ }
11065
+ const rows = Array.isArray(platformDraft.modelRows) ? platformDraft.modelRows : [];
11066
+ const prev = platformRevealLenRef.current;
11067
+ platformRevealLenRef.current = { name: platformEditing, len: rows.length };
11068
+ if (prev === null || prev.name !== platformEditing || rows.length <= prev.len) return undefined;
11069
+ const retry = () => revealBottom(platformEditRef.current);
11070
+ retry();
11071
+ let frame = 0;
11072
+ if (typeof window !== "undefined" && typeof window.requestAnimationFrame === "function") {
11073
+ frame = window.requestAnimationFrame(retry);
11074
+ }
11075
+ return () => {
11076
+ if (frame !== 0 && typeof window !== "undefined" && typeof window.cancelAnimationFrame === "function") {
11077
+ window.cancelAnimationFrame(frame);
11078
+ }
11079
+ };
11080
+ }, [platformEditing, platformDraft === null ? null : platformDraft.modelRows.length]);
10903
11081
  /**
10904
11082
  * 币种下拉控件(**只在条目的编辑浮层里用一处**:与三个价格框同一处、无文字标签)。
10905
11083
  *
@@ -11082,7 +11260,7 @@ function setModelCurrency(name, code, draftNow) {
11082
11260
  };
11083
11261
  document.addEventListener("pointerdown", onDocPointerDown, true);
11084
11262
  return () => document.removeEventListener("pointerdown", onDocPointerDown, true);
11085
- }, [platformEditing, platformDraft, cfg]);
11263
+ }, [platformEditing, platformDraft, platformModelOpen, cfg]);
11086
11264
  /* 厂商目录:点目录外收起所有展开的厂商分组(自定义组是受控的,另同步 catalogNotice=false) */
11087
11265
  react.useEffect(() => {
11088
11266
  if (typeof document === "undefined" || document === null || typeof document.addEventListener !== "function") return undefined;
@@ -11284,43 +11462,43 @@ function setDraftTiered(on) {
11284
11462
  });
11285
11463
  }
11286
11464
  /* ---- 第三方平台档案:平台列表 / 编辑 / 保存 / 删除(费用倍率与余额查询都挂在这里) ---- */
11287
- const platformNames = Object.keys(cfg.relayPlatforms === undefined || cfg.relayPlatforms === null ? {} : cfg.relayPlatforms);
11465
+ /* 平台列表顺序以 relayPlatformOrder 为准:不能直接用 Object.keys ——
11466
+ 纯数字平台名(如 35326)会被 JS 对象按数值排到最前,看起来像"夹在中间"。
11467
+ relayPlatformOrder 里没有的平台(旧配置迁移 / 手改配置)按对象键序补在末尾,保证不丢平台。 */
11468
+ const platformBook = cfg.relayPlatforms === undefined || cfg.relayPlatforms === null ? {} : cfg.relayPlatforms;
11469
+ const platformNames = normalizePlatformOrder(cfg.relayPlatformOrder, platformBook);
11288
11470
  /* 平台编辑的六个输入:按 Enter 后立即失焦,不残留输入光标 */
11289
11471
  const blurOnEnter = (event) => {
11290
11472
  if (event === null || event === undefined || event.key !== "Enter") return;
11291
11473
  if (typeof event.preventDefault === "function") event.preventDefault();
11292
11474
  if (event.target !== null && event.target !== undefined && typeof event.target.blur === "function") event.target.blur();
11293
11475
  };
11294
- /* 适用模型按钮:先按 13px 排满,只有实际超宽才按 0.5px 递减(最低 10px);重渲染从 13px 重测 */
11295
- const fitModelSelectLabel = (button) => {
11296
- if (button === null || button === undefined || button.style === undefined) return;
11297
- button.style.fontSize = "13px";
11298
- let size = 13;
11299
- while (size > 10 && button.scrollWidth > button.clientWidth) {
11300
- size -= 0.5;
11301
- button.style.fontSize = size + "px";
11302
- }
11303
- };
11304
- const platformOf = (name) => normalizePlatform((cfg.relayPlatforms === undefined || cfg.relayPlatforms === null ? {} : cfg.relayPlatforms)[name]);
11305
- /** 打开平台编辑:优先回显宿主已保存的真实值(含密文令牌 / 用户 ID);无快照时回退平台档案。 */
11306
- function startPlatform(name) {
11307
- cancelEdit();
11476
+
11477
+ const platformOf = (name) => normalizePlatform(platformBook[name]);
11478
+ /** 打开平台编辑:非密字段优先本地平台档案;令牌 / 用户 ID 从宿主快照回显。 */
11479
+ /** 依据当前 Host 快照 + 本地档案构造编辑草稿(token / userId 仅来自 Host 回显)。 */
11480
+ function platformDraftOf(name) {
11308
11481
  const platform = platformOf(name);
11309
- const saved = relayState.models === null || relayState.models === undefined
11310
- ? null
11311
- : (relayState.models[name] === undefined ? null : relayState.models[name]);
11312
- setPlatformDraft({
11313
- userIdHeader: saved !== null && typeof saved.userIdHeader === "string" && saved.userIdHeader.length > 0
11314
- ? saved.userIdHeader
11315
- : (platform === null ? "" : platform.userIdHeader),
11316
- endpoint: saved !== null && typeof saved.endpoint === "string" && saved.endpoint.length > 0
11317
- ? saved.endpoint
11318
- : (platform === null ? "" : platform.endpoint),
11319
- balanceField: saved !== null && typeof saved.balancePath === "string" && saved.balancePath.length > 0
11320
- ? balanceFieldText({ balancePath: saved.balancePath, balanceDivisor: saved.balanceDivisor, currency: saved.currency })
11321
- : (platform === null ? "" : balanceFieldText(platform)),
11482
+ const saved = relayChannelOf(name);
11483
+ /* 宿主 relayConfigView 会回传运行时默认值(New-Api-User / data.quota 等)。
11484
+ 只有 saved.endpoint 非空(该平台已有可用地址 / 首次探测成功已写回)时,才认为
11485
+ 这些默认值确实能查到余额并回填;地址为空时只显示本地档案里用户显式填过的值,
11486
+ 空就是空,绝不把默认值塞进输入框。令牌 / 用户 ID 只存在宿主凭据,仍从 saved 回显。 */
11487
+ const savedEndpoint = saved !== null && typeof saved.endpoint === "string" ? saved.endpoint.trim() : "";
11488
+ const savedReady = savedEndpoint.length > 0;
11489
+ const platformText = (key) => (platform === null || typeof platform[key] !== "string" ? "" : platform[key]);
11490
+ const platformBalance = platform === null ? "" : balanceFieldText(platform);
11491
+ const savedText = (key) => (saved !== null && typeof saved[key] === "string" && saved[key].length > 0 ? saved[key] : platformText(key));
11492
+ const savedBalance = saved !== null && typeof saved.balancePath === "string" && saved.balancePath.length > 0
11493
+ ? balanceFieldText(saved)
11494
+ : platformBalance;
11495
+ return {
11496
+ userIdHeader: savedReady ? savedText("userIdHeader") : platformText("userIdHeader"),
11497
+ endpoint: savedReady ? savedEndpoint : platformText("endpoint"),
11498
+ balanceField: savedReady ? savedBalance : platformBalance,
11322
11499
  token: saved !== null && typeof saved.token === "string" ? saved.token : "",
11323
11500
  userId: saved !== null && typeof saved.userId === "string" ? saved.userId : "",
11501
+ touched: {},
11324
11502
  /* 适用模型 = 价格库下拉行;档案里有几行就回填几行,
11325
11503
  **永远至少一行**(新建 / 已存档案模型为空都补一行空白,用户要求固定常驻) */
11326
11504
  modelRows: (platform === null || platform.models.length === 0)
@@ -11331,10 +11509,35 @@ function setDraftTiered(on) {
11331
11509
  ? (one.feeConfigured === true ? "1" : "")
11332
11510
  : String(one.feeMultiplier)
11333
11511
  }))
11334
- });
11512
+ };
11513
+ }
11514
+ function startPlatform(name) {
11515
+ cancelEdit();
11516
+ /* task-31:打开平台先用当前快照填草稿(同步,避免交互等待),随后强制刷新
11517
+ relay-balance-config,再用最新快照重填(仅当用户尚未触碰任何字段)。这样后台自动
11518
+ 探测写入的 endpoint / balanceKind / 解析字段不会因陈旧空快照被默认 data.quota/500000 覆盖。 */
11519
+ const seq = ++platformRefreshSeqRef.current;
11520
+ platformRefreshOkRef.current = true;
11521
+ setPlatformDraft(platformDraftOf(name));
11335
11522
  setPlatformEditing(name);
11336
11523
  setPlatformNotice(null);
11337
11524
  setPlatformModelOpen(null);
11525
+ if (devOn === true) return;
11526
+ /* task-33:把这次强制刷新挂到 pendingRef,让“刷新还没回来就点外部保存”的 savePlatform
11527
+ 先等它完成,避免用旧空快照/空草稿把自动探测结果覆盖成空地址 + data.quota/500000。 */
11528
+ const pending = refreshRelayState().then(() => {
11529
+ if (seq !== platformRefreshSeqRef.current) return;
11530
+ setPlatformDraft((prev) => {
11531
+ if (prev === null) return prev;
11532
+ if (prev.touched !== undefined && prev.touched !== null && Object.keys(prev.touched).length > 0) return prev;
11533
+ return platformDraftOf(name);
11534
+ });
11535
+ }).catch(() => { /* 拿不到最新快照就沿用当前快照 */ });
11536
+ platformRefreshPendingRef.current = pending;
11537
+ pending.then(() => {
11538
+ platformRefreshOkRef.current = relayLoadOk;
11539
+ if (platformRefreshPendingRef.current === pending) platformRefreshPendingRef.current = null;
11540
+ });
11338
11541
  }
11339
11542
  /** 新平台:名称只做「非空白 + 不重名」两项校验(数字/英文/符号都允许);**添加即落库**再进编辑。 */
11340
11543
  function addPlatform() {
@@ -11353,9 +11556,14 @@ function setDraftTiered(on) {
11353
11556
  档案必须在添加那一刻就存在,后续编辑只是补充字段。 */
11354
11557
  const platforms = Object.assign({}, cfg.relayPlatforms);
11355
11558
  platforms[name] = normalizePlatform({});
11356
- setConfig({ relayPlatforms: platforms });
11559
+ /* 新平台追加到显示顺序末尾(纯数字名也不会被 JS 键序提前) */
11560
+ const order = normalizePlatformOrder(cfg.relayPlatformOrder, platforms).filter((one) => one !== name);
11561
+ order.push(name);
11562
+ setConfig({ relayPlatforms: platforms, relayPlatformOrder: order });
11357
11563
  }
11358
11564
  function cancelPlatformEdit() {
11565
+ platformRefreshSeqRef.current += 1;
11566
+ platformRefreshPendingRef.current = null;
11359
11567
  setPlatformEditing(null);
11360
11568
  setPlatformDraft(null);
11361
11569
  setPlatformNotice(null);
@@ -11363,7 +11571,11 @@ function setDraftTiered(on) {
11363
11571
  setPlatformPopUp(false);
11364
11572
  }
11365
11573
  function setPlatformField(key, value) {
11366
- setPlatformDraft((prev) => (prev === null ? prev : Object.assign({}, prev, { [key]: value })));
11574
+ setPlatformDraft((prev) => (prev === null ? prev : Object.assign({}, prev, {
11575
+ [key]: value,
11576
+ /* 记下用户亲手改过的字段:即使填的值恰好等于 Host 默认值,也要当显式值保留。 */
11577
+ touched: Object.assign({}, prev.touched, { [key]: true })
11578
+ })));
11367
11579
  }
11368
11580
  /** 适用模型下拉行:增行 / 改行 / 删行(行索引只在本次草稿里有效) */
11369
11581
  function addPlatformModelRow() {
@@ -11391,15 +11603,50 @@ function setDraftTiered(on) {
11391
11603
  });
11392
11604
  }
11393
11605
  /** 平台保存:写 config → 按适用模型行把倍率写进价格条目 → 同步宿主余额查询配置(直接保存、不校验不拦截)。 */
11394
- function savePlatform() {
11606
+ async function savePlatform() {
11395
11607
  if (platformEditing === null || platformDraft === null) return;
11396
11608
  const name = platformEditing;
11397
- const draftNow = platformDraft;
11609
+ let draftNow = platformDraft;
11610
+ if (platformModelOpen !== null && platformModelOpen !== undefined && platformModelOpen.dirty === true) {
11611
+ const rows = Array.isArray(draftNow.modelRows) ? draftNow.modelRows : [];
11612
+ const index = platformModelOpen.index;
11613
+ if (Number.isInteger(index) && index >= 0 && index < rows.length && rows[index] !== null && rows[index] !== undefined) {
11614
+ const model = typeof platformModelOpen.filter === "string" ? platformModelOpen.filter : "";
11615
+ draftNow = Object.assign({}, draftNow, { modelRows: rows.map((one, at) => at === index ? Object.assign({}, one, { model: model }) : one) });
11616
+ }
11617
+ }
11618
+ /* task-33:刷新还没回来就点外部/保存时,先等强制刷新完成,避免用旧空快照下的空草稿
11619
+ 把 Host 自动探测出的 endpoint/解析字段覆盖成空地址 + data.quota/500000。 */
11620
+ const pendingRefresh = platformRefreshPendingRef.current;
11621
+ if (pendingRefresh !== null && pendingRefresh !== undefined) {
11622
+ try { await pendingRefresh; } catch (error) { /* 刷新失败沿用当前快照 */ }
11623
+ }
11624
+ /* 按字段合并:仅对「用户没触碰过」的字段用刷新后的最新快照值,显式输入一律保留;
11625
+ 模型行来自草稿不受影响。这样未动字段的自动保存不会退回 data.quota/500000。 */
11626
+ const touchedNow = draftNow.touched === undefined || draftNow.touched === null ? {} : draftNow.touched;
11627
+ const freshDraft = platformDraftOf(name);
11628
+ draftNow = Object.assign({}, draftNow, {
11629
+ userIdHeader: touchedNow.userIdHeader === true ? draftNow.userIdHeader : freshDraft.userIdHeader,
11630
+ endpoint: touchedNow.endpoint === true ? draftNow.endpoint : freshDraft.endpoint,
11631
+ balanceField: touchedNow.balanceField === true ? draftNow.balanceField : freshDraft.balanceField,
11632
+ token: touchedNow.token === true ? draftNow.token : freshDraft.token,
11633
+ userId: touchedNow.userId === true ? draftNow.userId : freshDraft.userId
11634
+ });
11398
11635
  const oldPlatform = platformOf(name);
11636
+ /* Host 当前快照:Host 可能已自动探测写入地址,而本地旧档案的 endpoint 本来就是空的。 */
11637
+ const hostChannel = relayChannelOf(name);
11638
+ const hostEndpoint = hostChannel !== null && typeof hostChannel.endpoint === "string" ? hostChannel.endpoint.trim() : "";
11399
11639
  const endpoint = typeof draftNow.endpoint === "string" ? draftNow.endpoint.trim() : "";
11400
11640
  const endpointValid = endpoint.length > 0 && /^https?:\/\//i.test(endpoint);
11641
+ const refreshTrusted = platformRefreshOkRef.current === true;
11642
+ /* task-35/37/39:强制刷新不可信(refreshTrusted=false)且快照里该平台 endpoint 为空
11643
+ (含 channel 不存在、已存在但 endpoint 仍空、以及首次 GET 从未成功三种常见情况)、
11644
+ 本地地址也为空、用户未改地址 → 进入「existing 合并」模式:不发送通用 fallback 字段,
11645
+ 交给 Host updateRelayConfig 用 existing 合并,避免把自动探测的 endpoint / balancePath /
11646
+ currency / divisor / balanceKind 覆盖。本地已有的显式请求头 / 解析字段仍照常发出。 */
11647
+ const mergeExistingHost = refreshTrusted !== true && hostEndpoint.length === 0
11648
+ && endpoint.length === 0 && touchedNow.endpoint !== true;
11401
11649
  let noticeKey = null;
11402
- if (endpoint.length > 0 && endpointValid !== true) noticeKey = noticeKey || "priceEndpointInvalid";
11403
11650
  let balance = {};
11404
11651
  if (typeof draftNow.balanceField === "string" && draftNow.balanceField.trim().length > 0) {
11405
11652
  const parsed = parseBalanceField(draftNow.balanceField);
@@ -11434,13 +11681,32 @@ function setDraftTiered(on) {
11434
11681
  });
11435
11682
  /* 地址非法就只存空地址(不报错不拦截),其它字段照常保存 */
11436
11683
  const endpointOk = endpointValid ? endpoint : "";
11684
+ /* Host 运行时预填值(New-Api-User / data.quota 等)不是用户填的:本地档案原本没有、草稿又与 Host 回显一字不差 → 不写进本地,避免清空地址后变成永久本地值;用户明确改过的值(与回显不同)照常保留。 */
11685
+ const touched = draftNow.touched === undefined || draftNow.touched === null ? {} : draftNow.touched;
11686
+ const localUserIdHeader = oldPlatform === null ? "" : oldPlatform.userIdHeader;
11687
+ const hostUserIdHeader = hostChannel !== null && typeof hostChannel.userIdHeader === "string" ? hostChannel.userIdHeader : "";
11688
+ const draftUserIdHeader = typeof draftNow.userIdHeader === "string" ? draftNow.userIdHeader : "";
11689
+ const userIdHeaderValue = localUserIdHeader.length === 0 && touched.userIdHeader !== true && hostEndpoint.length > 0 && draftUserIdHeader === hostUserIdHeader ? "" : draftUserIdHeader;
11690
+ const localBalanceEmpty = oldPlatform === null || oldPlatform.balancePath.length === 0;
11691
+ const hostBalanceField = hostChannel === null ? "" : balanceFieldText(hostChannel);
11692
+ const draftBalanceField = typeof draftNow.balanceField === "string" ? draftNow.balanceField.trim() : "";
11693
+ const autoHostBalance = localBalanceEmpty && touched.balanceField !== true && hostEndpoint.length > 0 && hostBalanceField.length > 0 && draftBalanceField === hostBalanceField;
11694
+ const effectiveBalance = autoHostBalance ? {} : balance;
11695
+ /* task-29:自动保存(未触碰解析字段、地址未变、草稿只是 Host 回显)时,向 Host 沿用其精确
11696
+ balancePath/currency/balanceDivisor,避免用 data.quota/500000 覆盖自动探测结果(否则 Server
11697
+ 视为解析字段变化会清 balanceKind,后续同 endpoint 查询永久 invalid-balance)。不把 balanceKind
11698
+ 写本地/写 Host:字段不变,服务端自然保留现有 kind。 */
11699
+ const hostBalancePathRaw = hostChannel !== null && typeof hostChannel.balancePath === "string" ? hostChannel.balancePath : "";
11700
+ const hostCurrencyRaw = hostChannel !== null && typeof hostChannel.currency === "string" ? hostChannel.currency : "";
11701
+ const hostBalanceDivisorRaw = hostChannel !== null && typeof hostChannel.balanceDivisor === "number" && Number.isFinite(hostChannel.balanceDivisor) && hostChannel.balanceDivisor > 0 ? hostChannel.balanceDivisor : null;
11702
+ const useHostBalanceFields = autoHostBalance && endpointValid === true && endpoint === hostEndpoint;
11437
11703
  const platform = normalizePlatform({
11438
11704
  endpoint: endpointOk,
11439
- userIdHeader: draftNow.userIdHeader,
11705
+ userIdHeader: userIdHeaderValue,
11440
11706
  /* 没填就存空(normalizePlatform 不再塞默认值);默认值只在向宿主 POST 时补 */
11441
- balancePath: balance.balancePath,
11442
- currency: balance.currency,
11443
- balanceDivisor: balance.balanceDivisor,
11707
+ balancePath: effectiveBalance.balancePath,
11708
+ currency: effectiveBalance.currency,
11709
+ balanceDivisor: effectiveBalance.balanceDivisor,
11444
11710
  models: picked.map((one) => Object.assign({ model: one[0], feeMultiplier: one[1] },
11445
11711
  one[1] === 1 && one[2] === true ? { feeConfigured: true } : {}))
11446
11712
  }) || normalizePlatform({});
@@ -11468,34 +11734,49 @@ function setDraftTiered(on) {
11468
11734
  setConfig({ models: next, relayPlatforms: platforms });
11469
11735
  const secretToken = typeof draftNow.token === "string" ? draftNow.token : "";
11470
11736
  const secretUserId = typeof draftNow.userId === "string" ? draftNow.userId : "";
11471
- /* 同步宿主:地址合法且非空 → 保存余额查询配置;否则旧平台有地址 → 移除旧配置。
11737
+ /* 同步宿主:地址合法且非空 → 保存余额查询配置;地址为空且旧平台也没有地址
11738
+ (新平台 / 还没配过)→ 仍要 POST:令牌 / 用户 ID 只随 POST 走,不能因为地址没填
11739
+ 就整条丢掉;endpoint 传空串,由 Host 按模型页 provider baseURL 推导默认地址。
11740
+ 旧平台原本有地址、这次清空 → 移除旧配置。
11472
11741
  feeMultiplier 固定 1:计费倍率已随价格库上报,避免 Host 二次相乘。 */
11473
11742
  const relayFailure = (data) => {
11474
11743
  const reason = data !== null && data !== undefined && typeof data.reason === "string" ? data.reason : "failed";
11475
- setPlatformNotice(t("priceRelaySyncFailed", { reason: reason }));
11744
+ console.warn("[dsh-desktop-statusbar] " + t("priceRelaySyncFailed", { reason: reason }));
11476
11745
  };
11477
- if (endpointValid === true) {
11478
- const payload = {
11479
- channelKey: name,
11480
- feeMultiplier: 1,
11481
- endpoint: platform.endpoint,
11482
- tokenHeader: platform.tokenHeader,
11483
- tokenPrefix: "Bearer ",
11746
+ /* 是否存在可移除的旧地址:本地档案有地址,或 Host 自动探测已写入(本地可能为空)。 */
11747
+ const hadEndpoint = (oldPlatform !== null && oldPlatform.endpoint.length > 0) || hostEndpoint.length > 0;
11748
+ const blankEndpointNew = endpoint.length === 0 && hadEndpoint !== true;
11749
+ if (endpointValid === true || blankEndpointNew === true) {
11750
+ /* task-35/37:mergeExistingHost 时不发通用 fallback 字段,交给 Host existing 合并;
11751
+ 但本地已有的显式请求头 / 余额解析字段必须照常发出,不能丢用户配置。 */
11752
+ const payload = { channelKey: name, feeMultiplier: 1 };
11753
+ if (mergeExistingHost !== true) {
11754
+ payload.endpoint = platform.endpoint;
11755
+ payload.tokenHeader = platform.tokenHeader;
11756
+ payload.tokenPrefix = "Bearer ";
11484
11757
  /* 档案里空 = 用户没填,但**运行时就按默认值跑**(用户确认的口径):
11485
11758
  请求头 New-Api-User、余额字段 ¥data.quota / 500000(CNY,除数 500000)。
11486
11759
  默认值只在这里补,不写回档案 —— 再打开编辑仍是空的。 */
11487
- userIdHeader: platform.userIdHeader.length > 0 ? platform.userIdHeader : "New-Api-User",
11488
- balancePath: platform.balancePath.length > 0 ? platform.balancePath : "data.quota",
11489
- currency: platform.currency.length > 0 ? platform.currency : "CNY",
11490
- balanceDivisor: platform.balanceDivisor === null ? 500000 : platform.balanceDivisor
11491
- };
11760
+ payload.userIdHeader = platform.userIdHeader.length > 0 ? platform.userIdHeader : "New-Api-User";
11761
+ payload.balancePath = useHostBalanceFields && hostBalancePathRaw.length > 0 ? hostBalancePathRaw : (platform.balancePath.length > 0 ? platform.balancePath : "data.quota");
11762
+ payload.currency = useHostBalanceFields && hostCurrencyRaw.length > 0 ? hostCurrencyRaw : (platform.currency.length > 0 ? platform.currency : "CNY");
11763
+ payload.balanceDivisor = useHostBalanceFields && hostBalanceDivisorRaw !== null ? hostBalanceDivisorRaw : (platform.balanceDivisor === null ? 500000 : platform.balanceDivisor);
11764
+ } else {
11765
+ /* 本地显式请求头 / parser 照发(空则不覆盖 Host 现有值,避免 relaySettings 判非法)。 */
11766
+ if (platform.userIdHeader.length > 0) payload.userIdHeader = platform.userIdHeader;
11767
+ if (platform.balancePath.length > 0) {
11768
+ payload.balancePath = platform.balancePath;
11769
+ if (platform.currency.length > 0) payload.currency = platform.currency;
11770
+ if (platform.balanceDivisor !== null) payload.balanceDivisor = platform.balanceDivisor;
11771
+ }
11772
+ }
11492
11773
  /* 密文只在本次输入时带上:空 = 保留宿主原值(提交后本地不保留) */
11493
11774
  if (secretToken.length > 0) payload.token = secretToken;
11494
11775
  if (secretUserId.length > 0) payload.userId = secretUserId;
11495
11776
  postRelayState(payload).then((data) => {
11496
11777
  if (data === null || data === undefined || data.ok !== true) relayFailure(data);
11497
11778
  }).catch(() => { relayFailure(null); });
11498
- } else if (oldPlatform !== null && oldPlatform.endpoint.length > 0) {
11779
+ } else if (hadEndpoint === true) {
11499
11780
  postRelayState({ remove: true, channelKey: name }).then((data) => {
11500
11781
  if (data === null || data === undefined || data.ok !== true) relayFailure(data);
11501
11782
  }).catch(() => { relayFailure(null); });
@@ -11517,11 +11798,13 @@ function setDraftTiered(on) {
11517
11798
  delete entry.feeConfigured;
11518
11799
  next[one.model] = entry;
11519
11800
  });
11520
- setConfig({ models: next, relayPlatforms: platforms });
11801
+ const order = normalizePlatformOrder(cfg.relayPlatformOrder, platforms);
11802
+ setConfig({ models: next, relayPlatforms: platforms, relayPlatformOrder: order });
11521
11803
  if (platformEditing === name) cancelPlatformEdit();
11522
- if (oldPlatform !== null && oldPlatform.endpoint.length > 0) {
11523
- postRelayState({ remove: true, channelKey: name }).catch(() => { /* 移除失败不影响本地删除 */ });
11524
- }
11804
+ /* 删除任何已存在的平台都发幂等 remove:即使没有 endpoint,也可能存过
11805
+ token/userId/header,必须让 Host 清掉 credential envelope,否则同名重建会残留
11806
+ (Host 的 remove 对不存在 / 无地址的 channel 是幂等的)。 */
11807
+ postRelayState({ remove: true, channelKey: name }).catch(() => { /* 移除失败不影响本地删除 */ });
11525
11808
  }
11526
11809
  function saveDraft() {
11527
11810
  if (editing === null || draft === null) return;
@@ -12112,7 +12395,7 @@ function setDraftTiered(on) {
12112
12395
  })),
12113
12396
  /* 适用模型 = 价格库下拉选择(按 modelOrder)。每行自带标签(像「请求头 / 用户 ID」
12114
12397
  那样:标签在左、输入框紧随其后),不再单独做整行表头。
12115
- 旧档案里不在价格库的模型名也并进该行选项,保证老配置可回显、可保存。 */
12398
+ 旧档案里不在价格库的模型名仍由输入框回显,但不并入候选。 */
12116
12399
  h("div", { className: "dsb-relay-fields", key: "__models" }, [
12117
12400
  h("div", { className: "dsb-platform-model-list", key: "__modellist" }, platformModelRows.map((one, index) => {
12118
12401
  const current = typeof one.model === "string" ? one.model : "";
@@ -12127,80 +12410,154 @@ function setDraftTiered(on) {
12127
12410
  modelNames.forEach((name) => {
12128
12411
  if (MODEL_PRESENTATION[name] === undefined && names.indexOf(name) === -1) names.push(name);
12129
12412
  });
12130
- if (current.length > 0 && names.indexOf(current) === -1) names.push(current);
12131
12413
  /* 已被本平台其他行选中的模型:本行灰显、不可点;当前行自己的已选模型正常显示 */
12132
12414
  const chosenByOthers = (modelName) => platformModelRows.some((other, at) => at !== index
12133
12415
  && typeof other.model === "string" && other.model.length > 0
12134
12416
  && sameModelName(other.model, modelName) === true);
12135
- const menuOpen = platformModelOpen === index;
12136
12417
  const modelRowItems = names.filter(function(modelName){ return modelName === current || chosenByOthers(modelName) !== true; }).map(function(modelName){ return { name: modelName, disabled: modelName.length>0 && chosenByOthers(modelName)===true, selected: modelName===current }; });
12418
+ /* 可输入筛选:候选仍取自 modelRowItems;按显示名或原始名做大小写无关包含匹配。
12419
+ 筛选文本挂在 platformModelOpen;dirty 输入仅在保存时写回对应模型行。 */
12420
+ const platformMenuState = platformModelOpen !== null && platformModelOpen !== undefined && typeof platformModelOpen === "object" ? platformModelOpen : null;
12421
+ const menuOpen = platformMenuState !== null && platformMenuState.index === index;
12422
+ const filterText = platformMenuState !== null && typeof platformMenuState.filter === "string" ? platformMenuState.filter : "";
12423
+ const loweredFilter = filterText.trim().toLowerCase();
12424
+ const visibleItems = loweredFilter.length === 0 ? modelRowItems : modelRowItems.filter(function (one) {
12425
+ return one.name.toLowerCase().indexOf(loweredFilter) !== -1 || displayModelName(one.name).toLowerCase().indexOf(loweredFilter) !== -1;
12426
+ });
12427
+ const menuPos = platformModelMenuPosRef.current;
12428
+ const menuVisible = menuOpen === true && visibleItems.length > 0 && menuPos !== null && menuPos !== undefined;
12429
+ const listboxId = "modelrow-list-" + index;
12430
+ const optionId = function (at) { return listboxId + "-" + at; };
12431
+ const closeModelMenu = function () {
12432
+ platformModelAnchorRef.current = null;
12433
+ platformModelMenuPosRef.current = null;
12434
+ setPlatformModelOpen(null);
12435
+ };
12436
+ /* 打开时用 fixed 视口坐标量一次锚点:菜单 portal 到 body,脱离设置卡片的 overflow 裁切。
12437
+ 最多 3 个候选;菜单固定从输入框下方展开,maxHeight 不超过视口剩余空间。 */
12438
+
12439
+ const openModelMenu = function (anchorEl) {
12440
+ const anchor = anchorEl !== null && anchorEl !== undefined && typeof anchorEl.closest === "function" ? anchorEl.closest(".dsb-select") : null;
12441
+ if (anchor === null || anchor === undefined || typeof anchor.getBoundingClientRect !== "function") return;
12442
+ const ar = anchor.getBoundingClientRect();
12443
+ const viewportW = typeof window !== "undefined" && typeof window.innerWidth === "number" ? window.innerWidth : 1024;
12444
+ const viewportH = typeof window !== "undefined" && typeof window.innerHeight === "number" ? window.innerHeight : 768;
12445
+ const gap = 4;
12446
+ const margin = 4;
12447
+ const itemH = 30;
12448
+ const count = modelRowItems.length;
12449
+ const desired = count <= 0 ? 0 : 8 + Math.min(count, 3) * itemH;
12450
+ const spaceBelow = Math.max(0, viewportH - ar.bottom - gap - margin);
12451
+ const maxHeight = Math.min(desired, spaceBelow);
12452
+ let left = ar.left;
12453
+ if (left + ar.width > viewportW - margin) left = viewportW - margin - ar.width;
12454
+ if (left < 0) left = 0;
12455
+ let originLeft = 0;
12456
+ let originTop = 0;
12457
+ const portalReady = typeof document !== "undefined" && document !== null && document.body !== undefined && document.body !== null && canPortal === true;
12458
+ if (portalReady !== true && typeof anchor.closest === "function") {
12459
+ const editPop = anchor.closest(".dsb-edit-pop");
12460
+ if (editPop !== null && editPop !== undefined && typeof editPop.getBoundingClientRect === "function") {
12461
+ const editPopRect = editPop.getBoundingClientRect();
12462
+ originLeft = typeof editPopRect.left === "number" ? editPopRect.left : 0;
12463
+ originTop = typeof editPopRect.top === "number" ? editPopRect.top : 0;
12464
+ }
12465
+ }
12466
+ platformModelAnchorRef.current = anchor;
12467
+ platformModelMenuPosRef.current = {
12468
+ left: left - originLeft,
12469
+ width: ar.width,
12470
+ maxHeight: maxHeight,
12471
+ top: ar.bottom + gap - originTop,
12472
+ };
12473
+ setPlatformModelOpen({ index: index, filter: current.length > 0 ? displayModelName(current) : "", dirty: false });
12474
+ };
12475
+ const chooseModel = function (name) {
12476
+ if (typeof name !== "string") return;
12477
+ setPlatformModelRow(index, { model: name });
12478
+ closeModelMenu();
12479
+ };
12480
+ /* 键盘只负责输入筛选,不参与浏览/选择候选:方向键与 Enter 一律不改变选择,仅保留 Escape 关闭气泡(用户要求)。 */
12481
+ const onModelKeyDown = function (event) {
12482
+ const key = event === null || event === undefined ? undefined : event.key;
12483
+ if (key === "Escape" && menuOpen === true) {
12484
+ if (typeof event.preventDefault === "function") event.preventDefault();
12485
+ closeModelMenu();
12486
+ }
12487
+ };
12488
+ const onModelFocus = function (event) {
12489
+ if (menuOpen !== true) {
12490
+ openModelMenu(event.currentTarget);
12491
+
12492
+ }
12493
+ };
12494
+ /* D:菜单已关闭但 input 仍聚焦时,click 不会触发 focus,需要点击主动重开气泡。 */
12495
+ const onModelClick = function (event) {
12496
+ if (menuOpen !== true) openModelMenu(event.currentTarget);
12497
+ };
12498
+ const onModelChange = function (event) {
12499
+ const value = event !== null && event !== undefined && event.target !== null && event.target !== undefined ? event.target.value : "";
12500
+ if (menuOpen !== true) openModelMenu(event.currentTarget);
12501
+ setPlatformModelOpen({ index: index, filter: typeof value === "string" ? value : "", dirty: true });
12502
+ };
12503
+ const onModelBlur = function (event) {
12504
+ if (menuOpen === true && platformMenuState !== null && platformMenuState.dirty === true) {
12505
+ const value = event !== null && event !== undefined && event.currentTarget !== null && event.currentTarget !== undefined ? event.currentTarget.value : "";
12506
+ setPlatformModelRow(index, { model: typeof value === "string" ? value : "" });
12507
+ }
12508
+ closeModelMenu();
12509
+ };
12137
12510
  const stop = (event) => {
12511
+ if (event !== null && event !== undefined && typeof event.preventDefault === "function") event.preventDefault();
12138
12512
  if (event !== null && event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
12139
12513
  };
12140
12514
  return h("div", { className: "dsb-relay-row dsb-modelrow", key: "__row" + index }, [
12141
12515
  relayLine(t("platformModels"), "__modelline", h("div", { className: "dsb-select dsb-modelrow-select" + (current.length > 0 ? "" : " dsb-select-empty"), key: "__model" }, [
12142
- h("button", {
12143
- type: "button", key: "__modelbtn", className: "dsb-select-btn",
12516
+ h("input", {
12517
+ type: "text", key: "__modelinput",
12518
+ className: "dsb-select-btn",
12519
+ role: "combobox",
12520
+ "aria-autocomplete": "list",
12144
12521
  "aria-haspopup": "listbox",
12145
- "aria-expanded": menuOpen === true ? "true" : "false",
12146
- ref: fitModelSelectLabel,
12147
- onClick: (event) => {
12148
- stop(event);
12149
- if (menuOpen !== true) {
12150
- const anchor = event.currentTarget !== null && event.currentTarget !== undefined && typeof event.currentTarget.closest === "function" ? event.currentTarget.closest(".dsb-select") : null;
12151
- const target = anchor !== null && anchor !== undefined && typeof anchor.closest === "function" ? anchor.closest(".dsb-model") : null;
12152
- if (anchor !== null && anchor !== undefined && target !== null && target !== undefined) {
12153
- const ar = anchor.getBoundingClientRect();
12154
- const tr = target.getBoundingClientRect();
12155
- const pageEl = typeof document !== "undefined" && document !== null && typeof document.querySelector === "function" ? document.querySelector(".dsb-settings") : null;
12156
- const pageBottom = Math.min(pageEl !== null && pageEl !== undefined && typeof pageEl.getBoundingClientRect === "function" ? pageEl.getBoundingClientRect().bottom : window.innerHeight, window.innerHeight);
12157
- const top = ar.bottom + 4;
12158
- const avail = Math.max(40, pageBottom - 4 - top);
12159
- const maxHeight = Math.min(8 + Math.min(modelRowItems.length, 3) * 30, avail);
12160
- platformModelAnchorRef.current = anchor;
12161
- platformModelMenuTargetRef.current = target;
12162
- platformModelMenuPosRef.current = {
12163
- left: ar.left - tr.left - (target.clientLeft || 0),
12164
- top: top - tr.top - (target.clientTop || 0),
12165
- width: ar.width,
12166
- maxHeight: maxHeight
12167
- };
12168
- setPlatformModelOpen(index);
12169
- }
12170
- } else {
12171
- platformModelAnchorRef.current = null;
12172
- platformModelMenuTargetRef.current = null;
12173
- platformModelMenuPosRef.current = null;
12174
- setPlatformModelOpen(null);
12175
- }
12176
- }
12177
- }, current.length > 0 ? displayModelName(current) : h("span", { className: "dsb-select-placeholder" }, t("platformModelSelectPh"))),
12178
- menuOpen === true
12522
+ "aria-expanded": menuVisible === true ? "true" : "false",
12523
+ "aria-controls": listboxId,
12524
+ "aria-label": t("platformModels"),
12525
+ autoComplete: "off", spellCheck: false, autoCorrect: "off",
12526
+ style: { display: "block", width: "100%", flex: "1 1 auto", minWidth: 0, height: "28px", boxSizing: "border-box" },
12527
+ value: menuOpen === true ? filterText : (current.length > 0 ? displayModelName(current) : ""),
12528
+ placeholder: t("platformModelSelectPh"),
12529
+ onFocus: onModelFocus,
12530
+ onBlur: onModelBlur,
12531
+ onChange: onModelChange,
12532
+ onKeyDown: onModelKeyDown,
12533
+ onClick: onModelClick
12534
+ }),
12535
+ menuVisible === true
12179
12536
  ? (function () {
12180
12537
  const pos = platformModelMenuPosRef.current;
12181
- if (pos === null || pos === undefined) return null;
12182
- const menuNode = h("div", { className: "dsb-select-menu dsb-modelrow-menu", role: "listbox", ref: platformModelMenuRef, style: { position: "absolute", left: pos.left + "px", top: pos.top + "px", width: pos.width + "px", maxHeight: pos.maxHeight + "px", overflowY: "auto", boxSizing: "border-box" } },
12183
- modelRowItems.map(function (one) {
12184
- return h("button", {
12185
- type: "button", key: one.name === "" ? "__empty" : one.name, role: "option",
12186
- "aria-selected": one.selected ? "true" : "false",
12187
- "aria-disabled": one.disabled ? "true" : "false",
12188
- disabled: one.disabled,
12189
- className: "dsb-select-item" + (one.selected ? " dsb-select-item-on" : "") + (one.disabled ? " dsb-select-item-disabled" : ""),
12190
- onMouseDown: stop,
12191
- onClick: function (event) {
12192
- stop(event);
12193
- if (one.disabled) return;
12194
- setPlatformModelRow(index, { model: one.name });
12195
- setPlatformModelOpen(null);
12196
- platformModelAnchorRef.current = null;
12197
- platformModelMenuTargetRef.current = null;
12198
- platformModelMenuPosRef.current = null;
12199
- }
12200
- }, displayModelName(one.name));
12201
- }));
12202
- const target = platformModelMenuTargetRef.current;
12203
- if (target !== null && target !== undefined && canPortal === true && reactDom !== null && reactDom !== undefined) return reactDom.createPortal(menuNode, target);
12538
+ if (visibleItems.length === 0 || pos === null || pos === undefined) return null;
12539
+ const menuStyle = { position: "fixed", left: pos.left + "px", width: pos.width + "px", maxHeight: pos.maxHeight + "px", overflowY: "auto", boxSizing: "border-box" };
12540
+ menuStyle.top = pos.top + "px";
12541
+ menuStyle.bottom = "auto";
12542
+ const menuNode = h("div", { className: "dsb-select-menu dsb-modelrow-menu", role: "listbox", id: listboxId, ref: platformModelMenuRef, style: menuStyle },
12543
+ visibleItems.map(function (one, itemIndex) {
12544
+ return h("button", {
12545
+ type: "button", key: one.name === "" ? "__empty" : one.name, role: "option", id: optionId(itemIndex),
12546
+ "aria-selected": one.selected ? "true" : "false",
12547
+ "aria-disabled": one.disabled ? "true" : "false",
12548
+ disabled: one.disabled,
12549
+ className: "dsb-select-item" + (one.selected ? " dsb-select-item-on" : "") + (one.disabled ? " dsb-select-item-disabled" : ""),
12550
+ onMouseDown: stop,
12551
+ onClick: function (event) {
12552
+ stop(event);
12553
+ if (one.disabled) return;
12554
+ chooseModel(one.name);
12555
+ }
12556
+ }, displayModelName(one.name));
12557
+ }));
12558
+ /* portal 到 body:脱离 .dsb-edit-pop / .dsb-settings 的 overflow 裁切;fixed 坐标贴输入框 */
12559
+ const portalTarget = typeof document !== "undefined" && document !== null && document.body !== undefined ? document.body : null;
12560
+ if (portalTarget !== null && canPortal === true && reactDom !== null && reactDom !== undefined) return reactDom.createPortal(menuNode, portalTarget);
12204
12561
  return menuNode;
12205
12562
  })()
12206
12563
  : null