dsh-model-select-plus 0.1.6 → 0.2.0

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/src/client.js CHANGED
@@ -9,14 +9,21 @@
9
9
  * host webserver via `fetch`, and the popup CSS is injected as a `<style>` tag
10
10
  * through `document` (the `plugin-dashboard` / `skin-material-you` pattern).
11
11
  *
12
- * SEO-free look intent (quiet / tight / truthful):
13
- * - quiet text-button trigger (no gray fill) on the white composer
14
- * - 336px panel, soft shadow, gentle entrance animation
15
- * - firm typography: panel base 12px, name 12px, desc 11px, chips 10px
16
- * - no per-row provider tag (the provider is the group heading)
17
- * - inline pill reasoning-effort chips (with 默认), tinted selected row,
18
- * icon'd search with a clear button, pinned favorites, thin scrollbar,
19
- * a vertically-centered SVG star
12
+ * Layout (one column, native menu measures):
13
+ * - card 320 x 440, the shipped menu material (translucent fill + blur +
14
+ * prominent elevation stroke) and 16px radius
15
+ * - one 34px search line with a 0.5px rule; no jump rail, no chips
16
+ * - nested rows at the native 34px height, 12px radius inside the 16px card
17
+ * - selection is a 6% fill plus the trailing check (a 10% block reads as a
18
+ * disabled row); the model name only gains weight
19
+ * - only the current row expands: its two-line description and a 26px effort
20
+ * segmented control share one block, so every other row keeps the baseline
21
+ * - provider headings are 11px labels that paint their group-header fill only
22
+ * while stuck to the top; static groups stay flat
23
+ * - favorites stay pinned in their own top group, and their rows carry the
24
+ * provider name because the same model exists under several providers
25
+ * - trigger shows the model name only; the provider lives in the tooltip
26
+ * (provider/model overflows the 220px chip under the monospace UI font)
20
27
  *
21
28
  * Data comes from the Host half at `/plugins/dsh-model-select-plus/api`.
22
29
  * The seat passes `locked` (owner prop) and we inject `sessionId`.
@@ -31,71 +38,89 @@ const API = "/plugins/dsh-model-select-plus/api";
31
38
  const STYLE_TAG = "dsh-model-select-plus/style";
32
39
  const FAVS_KEY = "__favorites__";
33
40
 
41
+ const h = React.createElement;
42
+
34
43
  const CSS = `
35
- .mdsl-root { position: relative; }
44
+ .mdsl-root, .mdsl-root *, .mdsl-root *::before, .mdsl-root *::after { box-sizing: border-box; }
45
+ .mdsl-root { position: relative; display: inline-flex; align-items: center; min-width: 0; max-width: 100%; }
36
46
  .mdsl-backdrop { position: fixed; inset: 0; z-index: 35; }
37
- .mdsl-menu { font-size: 12px; font-family: inherit; }
38
- .mdsl-trigger { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 8px; background: transparent; border: 1px solid transparent; color: var(--dsw-alias-label-secondary); cursor: pointer; font-family: inherit; font-size: 12px; transition: background .14s ease, border-color .14s ease, box-shadow .14s ease; }
39
- .mdsl-trigger:hover { background: var(--dsw-alias-interactive-bg-hover); }
40
- .mdsl-trigger:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-brand-primary); }
41
- .mdsl-trigger:disabled { opacity: .5; cursor: default; }
42
- .mdsl-label { font-weight: 550; color: var(--dsw-alias-label-primary); white-space: nowrap; }
43
- .mdsl-effort { color: var(--dsw-alias-label-tertiary); font-size: 11px; }
44
- .mdsl-sep { color: var(--dsw-alias-label-tertiary); opacity: .7; }
45
- .mdsl-chevron { transition: transform .16s ease; color: var(--dsw-alias-label-tertiary); font-size: 10px; }
47
+
48
+ /* Trigger: the composer's 28px chip, same as the sibling permission / plan
49
+ controls, so the row does not jump when this plugin replaces the seat. */
50
+ .mdsl-trigger { display: flex; align-items: center; gap: 4px; min-width: 0; max-width: 220px; max-width: min(360px, 45cqw); height: 28px; padding: 0 4px 0 8px; border: 0; border-radius: var(--dsw-radius-sm, 8px); background: transparent; color: var(--dsw-alias-label-secondary); font-family: inherit; font-size: 13px; line-height: 20px; font-weight: 400; cursor: pointer; outline: none; }
51
+ .mdsl-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
52
+ .mdsl-trigger:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
53
+ .mdsl-trigger:disabled { color: var(--dsw-alias-label-dimmed); cursor: default; }
54
+ .mdsl-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
55
+ /* The effort absorbs the deficit first: it ellipsizes to nothing before the
56
+ model name loses a pixel, and the chevron stays snug. */
57
+ .mdsl-effort { flex-shrink: 1000; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-caption); }
58
+ .mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); }
46
59
  .mdsl-chevron-open { transform: rotate(180deg); }
47
- .mdsl-menu { position: absolute; right: 0; bottom: calc(100% + 8px); width: 336px; max-height: min(440px, 62vh); display: flex; flex-direction: column; background: var(--dsw-alias-bg-overlay); border: 1px solid var(--dsw-alias-border-l1); border-radius: 14px; box-shadow: 0 10px 36px rgba(0,0,0,.14); overflow: hidden; z-index: 40; animation: mdsl-in .15s ease-out; transform-origin: bottom right; }
48
- @keyframes mdsl-in { from { opacity: 0; transform: translateY(5px) scale(.985); } to { opacity: 1; transform: none; } }
49
- .mdsl-header { padding: 10px 12px 8px; border-bottom: 1px solid var(--dsw-alias-border-l1); }
50
- .mdsl-summary { font-size: 11px; color: var(--dsw-alias-label-secondary); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
51
- .mdsl-summary-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dsw-alias-brand-primary); flex: none; }
52
- .mdsl-summary-lbl { color: var(--dsw-alias-label-tertiary); }
53
- .mdsl-summary-b { font-weight: 600; color: var(--dsw-alias-label-primary); }
54
- .mdsl-search-wrap { position: relative; display: flex; align-items: center; }
55
- .mdsl-search-icon { position: absolute; left: 9px; color: var(--dsw-alias-label-tertiary); display: flex; pointer-events: none; }
56
- .mdsl-search { width: 100%; padding: 6px 28px; border-radius: 9px; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 12px; outline: none; transition: border-color .16s ease, box-shadow .16s ease; }
57
- .mdsl-search::placeholder { color: var(--dsw-alias-label-tertiary); }
58
- .mdsl-search:focus { border-color: var(--dsw-alias-brand-primary); box-shadow: 0 0 0 3px var(--dsw-alias-interactive-bg-active); }
59
- .mdsl-search-clear { position: absolute; right: 7px; border: none; background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-secondary); border-radius: 50%; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-family: inherit; font-size: 12px; line-height: 1; }
60
- .mdsl-search-clear:hover { background: var(--dsw-alias-interactive-bg-active); color: var(--dsw-alias-label-primary); }
61
- .mdsl-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 8px; }
62
- .mdsl-tag { flex: none; display: inline-flex; align-items: center; gap: 4px; font-family: inherit; font-size: 11px; line-height: 1.3; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); border-radius: 999px; padding: 2px 8px; cursor: pointer; user-select: none; transition: border-color .12s, color .12s, background .12s; }
63
- .mdsl-tag:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); background: var(--dsw-alias-interactive-bg-hover); }
64
- .mdsl-tag:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-brand-primary); }
65
- .mdsl-tag-current { border-color: var(--dsw-alias-brand-primary); color: var(--dsw-alias-brand-primary); background: var(--dsw-alias-interactive-bg-active); font-weight: 550; }
66
- .mdsl-tag-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--dsw-alias-brand-primary); flex: none; }
67
- .mdsl-tag-count { color: var(--dsw-alias-label-tertiary); font-weight: 500; }
68
- .mdsl-body { flex: 1; min-height: 0; overflow-y: auto; padding: 5px; scrollbar-width: thin; scrollbar-color: var(--dsw-alias-scrollbar-bg-l1) transparent; }
69
- .mdsl-body::-webkit-scrollbar { width: 7px; }
70
- .mdsl-body::-webkit-scrollbar-thumb { background: var(--dsw-alias-scrollbar-bg-l1); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
71
- .mdsl-body::-webkit-scrollbar-thumb:hover { background: var(--dsw-alias-scrollbar-hover-l1); }
72
- .mdsl-group { display: flex; flex-direction: column; gap: 3px; margin-bottom: 4px; }
73
- .mdsl-group-collapsed { gap: 0; margin-bottom: 2px; }
74
- .mdsl-group-title { display: flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 600; color: var(--dsw-alias-label-tertiary); letter-spacing: .06em; text-transform: uppercase; padding: 5px 6px 3px; margin: 2px 2px 0; border-radius: 6px; cursor: pointer; user-select: none; transition: background .12s ease, color .12s ease; }
75
- .mdsl-group-title:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-secondary); }
76
- .mdsl-group-title:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-brand-primary); }
77
- .mdsl-group-chevron { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 10px; height: 10px; color: currentColor; transform: rotate(90deg); transition: transform .14s ease; }
78
- .mdsl-group-collapsed .mdsl-group-chevron { transform: none; }
79
- .mdsl-group-count { margin-left: auto; font-weight: 500; letter-spacing: 0; opacity: .85; }
80
- .mdsl-row { display: flex; align-items: flex-start; gap: 6px; padding: 6px 8px; border-radius: 10px; cursor: pointer; transition: background .12s ease; }
81
- .mdsl-row:hover { background: var(--dsw-alias-interactive-bg-hover); }
82
- .mdsl-row-current, .mdsl-row-current:hover { background: var(--dsw-alias-interactive-bg-active); }
83
- .mdsl-star { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; margin-top: 0; background: none; border: none; padding: 0; cursor: pointer; color: var(--dsw-alias-label-tertiary); border-radius: 6px; transition: color .12s, background .12s; }
84
- .mdsl-star:hover { color: var(--dsw-alias-label-primary); background: var(--dsw-alias-interactive-bg-hover); }
60
+
61
+ /* Card: the shipped menu material. 320px sits inside the native menu range
62
+ (240-420) and stays close to the trigger that opened it. */
63
+ .mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width: 320px; max-width: calc(100vw - 24px); max-height: min(440px, calc(100vh - 120px)); padding: 4px; background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-overlay)); -webkit-backdrop-filter: var(--dsw-menu-backdrop-filter, blur(20px) saturate(140%)); backdrop-filter: var(--dsw-menu-backdrop-filter, blur(20px) saturate(140%)); border: 0; border-radius: var(--dsw-radius-lg, 16px); --dsw-elevation-stroke-color: var(--dsw-alias-border-l1); box-shadow: var(--dsw-elevation-prominent, 0 10px 36px rgba(0,0,0,.14)); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2); --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2); overflow: hidden; animation: mdsl-in .16s cubic-bezier(.22, 1, .36, 1); transform-origin: bottom right; }
64
+ body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
65
+ @keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
66
+ @media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
67
+
68
+ /* One search line with a 0.5px rule. No jump rail: 18 models are cheap to
69
+ scroll, and the second navigation layer only repeated the headings. */
70
+ .mdsl-search-wrap { position: relative; flex: none; display: flex; align-items: center; height: 34px; border-bottom: 0.5px solid var(--dsw-alias-border-l1); }
71
+ .mdsl-search-wrap:focus-within { border-bottom-color: var(--dsw-alias-state-business-primary); }
72
+ .mdsl-search-icon { position: absolute; left: 8px; display: flex; color: var(--dsw-alias-label-tertiary); pointer-events: none; }
73
+ .mdsl-search-wrap:focus-within .mdsl-search-icon { color: var(--dsw-alias-label-primary); }
74
+ .mdsl-search { width: 100%; height: 100%; padding: 0 28px 0 30px; border: 0; border-radius: 0; background: transparent; color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; line-height: 20px; outline: none; }
75
+ .mdsl-search::placeholder { color: var(--dsw-alias-label-caption); }
76
+ .mdsl-search-clear { position: absolute; right: 4px; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--dsw-alias-label-secondary); cursor: pointer; }
77
+ .mdsl-search-clear:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
78
+ .mdsl-search-clear:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
79
+
80
+ .mdsl-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 0 2px 2px; scrollbar-width: thin; scrollbar-color: var(--dsh-scrollbar-thumb, var(--dsw-alias-scrollbar-bg-l2)) transparent; }
81
+ .mdsl-body::-webkit-scrollbar { width: 8px; }
82
+ .mdsl-body::-webkit-scrollbar-thumb { background: var(--dsh-scrollbar-thumb, var(--dsw-alias-scrollbar-bg-l2)); border: 2px solid transparent; border-radius: 999px; background-clip: content-box; }
83
+ .mdsl-body::-webkit-scrollbar-thumb:hover { background: var(--dsh-scrollbar-thumb-hover, var(--dsw-alias-scrollbar-hover-l2)); border: 2px solid transparent; background-clip: content-box; }
84
+
85
+ /* Sections: 10px of air between groups; a 22px heading that paints its
86
+ header fill only while stuck to the top, so static groups stay flat
87
+ instead of drawing a grey band each. */
88
+ .mdsl-group { position: relative; }
89
+ .mdsl-group + .mdsl-group { margin-top: 10px; }
90
+ .mdsl-group-title { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 4px; padding: 4px 8px 2px; background: transparent; color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; font-weight: 500; }
91
+ .mdsl-group-title[data-stuck] { background: var(--dsw-alias-menu-group-header-fill, var(--dsw-alias-bg-overlay)); box-shadow: 0 0.5px 0 var(--dsw-alias-border-l1); }
92
+ .mdsl-group-icon { display: inline-flex; color: var(--dsw-alias-brand-primary); }
93
+ .mdsl-group-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
94
+
95
+ /* Row: 34px, the native menu row height. Selection is a 6% fill plus the
96
+ trailing check; the 10% block read as a disabled row. */
97
+ .mdsl-item { border-radius: var(--dsw-radius-md, 12px); }
98
+ .mdsl-item:hover, .mdsl-item-current { background: var(--dsw-alias-interactive-bg-hover); }
99
+ .mdsl-row { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 8px; border-radius: var(--dsw-radius-md, 12px); cursor: pointer; }
100
+ .mdsl-row:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--dsw-alias-state-business-primary); }
101
+ .mdsl-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-primary); font-size: 13px; line-height: 20px; }
102
+ .mdsl-item-current .mdsl-name { font-weight: 500; }
103
+ .mdsl-prov { flex: none; color: var(--dsw-alias-label-caption); font-size: 11px; line-height: 16px; }
104
+ .mdsl-check { flex: none; display: inline-flex; color: var(--dsw-alias-label-primary); }
105
+ .mdsl-star { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--dsw-alias-label-tertiary); opacity: 0; cursor: pointer; }
106
+ .mdsl-item:hover .mdsl-star, .mdsl-star-on, .mdsl-star:focus-visible { opacity: 1; }
107
+ .mdsl-star:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
108
+ .mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
85
109
  .mdsl-star-on { color: var(--dsw-alias-brand-primary); }
86
- .mdsl-row-main { flex: 1; min-width: 0; }
87
- .mdsl-row-head { display: flex; align-items: center; gap: 6px; min-width: 0; min-height: 18px; }
88
- .mdsl-row-name { font-size: 12px; font-weight: 550; line-height: 18px; color: var(--dsw-alias-label-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
89
- .mdsl-check { color: var(--dsw-alias-brand-primary); font-weight: 600; font-size: 11px; flex: none; }
90
- .mdsl-row-desc { font-size: 11px; line-height: 1.4; color: var(--dsw-alias-label-secondary); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
91
- .mdsl-row-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
92
- .mdsl-chip { font-family: inherit; font-size: 10px; line-height: 1.4; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); border-radius: 999px; padding: 1px 7px; cursor: pointer; transition: border-color .12s, color .12s, background .12s; }
93
- .mdsl-chip:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
94
- .mdsl-chip-on { border-color: var(--dsw-alias-brand-primary); color: var(--dsw-alias-brand-primary); background: var(--dsw-alias-interactive-bg-active); }
95
- .mdsl-empty { font-size: 11px; color: var(--dsw-alias-label-tertiary); padding: 16px; text-align: center; }
96
- .mdsl-error { font-size: 11px; color: var(--dsw-alias-state-error-primary); padding: 9px 11px; }
97
- .mdsl-footer { padding: 8px 12px; border-top: 1px solid var(--dsw-alias-border-l1); font-size: 10.5px; color: var(--dsw-alias-label-tertiary); display: flex; align-items: center; gap: 6px; }
98
- .mdsl-footer-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--dsw-alias-label-tertiary); flex: none; }
110
+
111
+ /* Only the current row expands: description and effort belong to it, so
112
+ every other row keeps the same 34px baseline. */
113
+ .mdsl-sub { padding: 2px 8px 8px; }
114
+ .mdsl-desc { color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 16px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
115
+ .mdsl-track { display: flex; align-items: center; gap: 2px; height: 26px; margin-top: 6px; padding: 3px; border-radius: 8px; background: var(--dsw-alias-interactive-bg-hover); }
116
+ .mdsl-seg { flex: 1; height: 20px; padding: 0 4px; border: 0; border-radius: 6px; background: transparent; color: var(--dsw-alias-label-tertiary); font-family: inherit; font-size: 11px; line-height: 20px; text-align: center; cursor: pointer; }
117
+ .mdsl-seg:hover { color: var(--dsw-alias-label-primary); }
118
+ .mdsl-seg:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
119
+ .mdsl-seg-on { background: var(--dsw-alias-bg-base, #fff); color: var(--dsw-alias-label-primary); font-weight: 500; box-shadow: 0 0 0 0.5px var(--dsw-alias-border-l2), 0 1px 2px rgba(0, 0, 0, .05); }
120
+ body[data-ds-dark-theme] .mdsl-seg-on { background: var(--dsw-alias-interactive-bg-active); }
121
+
122
+ .mdsl-empty { padding: 16px 8px; text-align: center; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
123
+ .mdsl-error { margin: 4px 2px; padding: 6px 8px; border-radius: 8px; background: var(--dsw-alias-interactive-bg-hover-danger); color: var(--dsw-alias-state-error-primary); font-size: 11px; line-height: 16px; }
99
124
  `;
100
125
 
101
126
  function injectStyle() {
@@ -108,45 +133,58 @@ function injectStyle() {
108
133
  return () => { tag.remove(); };
109
134
  }
110
135
 
111
- const star = (filled) => React.createElement(
136
+ const star = (filled) => h(
137
+ "svg",
138
+ { width: 14, height: 14, viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
139
+ h("path", { d: "M12 2.6l2.86 5.8 6.4.94-4.63 4.5 1.1 6.37L12 17.02 6.27 20.2l1.1-6.37-4.63-4.5 6.4-.94L12 2.6z", stroke: "currentColor", strokeWidth: 1.5, strokeLinejoin: "round" }),
140
+ );
141
+
142
+ const check = () => h(
112
143
  "svg",
113
- { width: 14, height: 14, viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", xmlns: "http://www.w3.org/2000/svg" },
114
- React.createElement("path", { d: "M12 2.6l2.86 5.8 6.4.94-4.63 4.5 1.1 6.37L12 17.02 6.27 20.2l1.1-6.37-4.63-4.5 6.4-.94L12 2.6z", stroke: "currentColor", strokeWidth: 1.5, strokeLinejoin: "round" }),
144
+ { width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
145
+ h("path", { d: "M2.8 7.4l2.6 2.6 5.8-6.4", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" }),
115
146
  );
116
147
 
117
- const chevron = () => React.createElement(
148
+ const chevronDown = () => h(
118
149
  "svg",
119
- { width: 9, height: 9, viewBox: "0 0 8 8", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
120
- React.createElement("path", { d: "M2.2 1.6L5.4 4 2.2 6.4", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round" }),
150
+ { width: 12, height: 12, viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
151
+ h("path", { d: "M3 4.75L6 7.75l3-3", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round" }),
121
152
  );
122
153
 
123
- const searchIcon = () => React.createElement(
154
+ const closeIcon = () => h(
155
+ "svg",
156
+ { width: 12, height: 12, viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
157
+ h("path", { d: "M3 3l6 6M9 3L3 9", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" }),
158
+ );
159
+
160
+ const searchIcon = () => h(
124
161
  "span",
125
162
  { className: "mdsl-search-icon" },
126
- React.createElement(
163
+ h(
127
164
  "svg",
128
- { width: 13, height: 13, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
129
- React.createElement("circle", { cx: 7, cy: 7, r: 5, stroke: "currentColor", strokeWidth: 1.4 }),
130
- React.createElement("line", { x1: 10.8, y1: 10.8, x2: 14, y2: 14, stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" }),
165
+ { width: 14, height: 14, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
166
+ h("circle", { cx: 7, cy: 7, r: 5, stroke: "currentColor", strokeWidth: 1.4 }),
167
+ h("line", { x1: 10.8, y1: 10.8, x2: 14, y2: 14, stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" }),
131
168
  ),
132
169
  );
133
170
 
134
171
  function ModelSelectLite(props) {
135
172
  const sessionId = props.sessionId;
136
173
  const locked = props.locked === true;
174
+ const triggerRef = React.useRef(null);
137
175
  const bodyRef = React.useRef(null);
176
+ const searchRef = React.useRef(null);
177
+ const [placement, setPlacement] = React.useState(null);
138
178
  const [open, setOpen] = React.useState(false);
139
179
  const [data, setData] = React.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
140
180
  const [query, setQuery] = React.useState("");
141
181
  const [busy, setBusy] = React.useState(false);
142
182
  const [, bump] = React.useState(0);
143
- // Manual overrides for group fold state (id -> boolean). By default, only
144
- // the group containing the currently selected model is expanded; all other
145
- // groups default to collapsed. Searching force-expands every group.
146
- const [userToggled, setUserToggled] = React.useState(() => new Map());
147
183
 
148
184
  const load = () => {
149
- setData((d) => ({ ...d, status: "loading", error: null }));
185
+ // Keep the previous rows on screen while a re-open refreshes the catalog;
186
+ // only a cold load shows the loading state (no flash on every open).
187
+ setData((d) => (d.groups.length > 0 ? { ...d, error: null } : { ...d, status: "loading", error: null }));
150
188
  const url = `${API}/catalog?sessionId=${encodeURIComponent(sessionId)}`;
151
189
  fetch(url)
152
190
  .then((res) => res.json())
@@ -165,16 +203,125 @@ function ModelSelectLite(props) {
165
203
  // Load on mount (and when the session changes) so the trigger shows the
166
204
  // current model immediately instead of the "选择模型" placeholder.
167
205
  React.useEffect(() => {
168
- if (sessionId !== undefined) {
169
- setUserToggled(new Map());
170
- load();
171
- }
206
+ if (sessionId !== undefined) load();
172
207
  }, [sessionId]);
173
208
 
209
+ // Opening the menu focuses the search field: typing filters immediately and
210
+ // Escape lands on the menu's key handler for free. Focus lands once per open
211
+ // — a resize or page scroll that re-places the card must not pull the caret
212
+ // back out of the row the keyboard is on.
213
+ const focusedForOpen = React.useRef(false);
214
+ React.useEffect(() => {
215
+ if (!open) {
216
+ focusedForOpen.current = false;
217
+ return;
218
+ }
219
+ if (placement === null || focusedForOpen.current) return;
220
+ focusedForOpen.current = true;
221
+ const el = searchRef.current;
222
+ if (el) el.focus({ preventScroll: true });
223
+ }, [open, placement]);
224
+
225
+ // Measure the room around the trigger before painting: open upward while it
226
+ // fits, flip downward when the window is short, clamp inside the viewport,
227
+ // and cap the card height so the scrolling body always keeps its last row.
228
+ const placeMenu = () => {
229
+ const trigger = triggerRef.current;
230
+ if (!trigger) return;
231
+ const rect = trigger.getBoundingClientRect();
232
+ const margin = 12;
233
+ const gap = 6;
234
+ const width = Math.min(320, window.innerWidth - margin * 2);
235
+ const spaceAbove = rect.top - gap - margin;
236
+ const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
237
+ const side = spaceAbove >= spaceBelow ? "top" : "bottom";
238
+ const maxHeight = Math.max(180, Math.min(440, side === "top" ? spaceAbove : spaceBelow));
239
+ const left = Math.min(Math.max(margin, rect.right - width), window.innerWidth - width - margin);
240
+ // Keep the placement object stable when nothing moved: every identity change
241
+ // would re-run the sticky sync and could steal focus back to the search.
242
+ setPlacement((prev) => {
243
+ const next = {
244
+ side,
245
+ maxHeight,
246
+ width,
247
+ left,
248
+ bottom: window.innerHeight - rect.top + gap,
249
+ top: rect.bottom + gap,
250
+ };
251
+ if (
252
+ prev !== null
253
+ && prev.side === next.side
254
+ && prev.maxHeight === next.maxHeight
255
+ && prev.width === next.width
256
+ && prev.left === next.left
257
+ && prev.bottom === next.bottom
258
+ && prev.top === next.top
259
+ ) return prev;
260
+ return next;
261
+ });
262
+ };
263
+
264
+ React.useLayoutEffect(() => {
265
+ if (open) placeMenu();
266
+ }, [open]);
267
+
268
+ React.useEffect(() => {
269
+ if (!open) return;
270
+ const reposition = (ev) => {
271
+ // Scrolling the menu's own body must not re-anchor the card.
272
+ const body = bodyRef.current;
273
+ if (ev && ev.target instanceof Node && body !== null && body.contains(ev.target)) return;
274
+ placeMenu();
275
+ };
276
+ window.addEventListener("resize", reposition);
277
+ window.addEventListener("scroll", reposition, true);
278
+ return () => {
279
+ window.removeEventListener("resize", reposition);
280
+ window.removeEventListener("scroll", reposition, true);
281
+ };
282
+ }, [open]);
283
+
284
+ // Sticky headings paint their fill only while pinned to the top edge of the
285
+ // scrolling body; a heading that merely sits at the top of its group stays
286
+ // flat. rAF-throttled because the body scrolls at pointer speed.
287
+ React.useEffect(() => {
288
+ if (!open) return;
289
+ const body = bodyRef.current;
290
+ if (!body) return;
291
+ let raf = 0;
292
+ const sync = () => {
293
+ raf = 0;
294
+ const top = body.getBoundingClientRect().top;
295
+ const heads = body.querySelectorAll(".mdsl-group-title");
296
+ for (const head of heads) {
297
+ if (head.getBoundingClientRect().top <= top + 1) head.setAttribute("data-stuck", "");
298
+ else head.removeAttribute("data-stuck");
299
+ }
300
+ };
301
+ const schedule = () => { if (!raf) raf = requestAnimationFrame(sync); };
302
+ body.addEventListener("scroll", schedule, { passive: true });
303
+ window.addEventListener("resize", schedule);
304
+ schedule();
305
+ return () => {
306
+ body.removeEventListener("scroll", schedule);
307
+ window.removeEventListener("resize", schedule);
308
+ if (raf) cancelAnimationFrame(raf);
309
+ };
310
+ }, [open, placement, data.status, data.current, query]);
311
+
312
+ const focusTrigger = () => {
313
+ const el = triggerRef.current;
314
+ if (el) el.focus({ preventScroll: true });
315
+ };
174
316
  const openMenu = () => { setOpen(true); load(); };
175
- const closeMenu = () => { setOpen(false); setQuery(""); };
317
+ const closeMenu = () => {
318
+ setOpen(false);
319
+ setQuery("");
320
+ setPlacement(null);
321
+ focusTrigger();
322
+ };
176
323
 
177
- const selectSelection = (sel) => {
324
+ const selectSelection = (sel, keepOpen) => {
178
325
  if (busy) return;
179
326
  setBusy(true);
180
327
  fetch(`${API}/select`, {
@@ -191,8 +338,8 @@ function ModelSelectLite(props) {
191
338
  .then((res) => {
192
339
  setBusy(false);
193
340
  if (res && res.ok === true) {
194
- setData((d) => ({ ...d, current: res.selected, error: null }));
195
- setUserToggled(new Map());
341
+ setData((d) => ({ ...d, current: res.selected || null, error: null }));
342
+ if (keepOpen) return;
196
343
  closeMenu();
197
344
  } else {
198
345
  setData((d) => ({ ...d, error: (res && res.message) || "选择失败" }));
@@ -204,217 +351,269 @@ function ModelSelectLite(props) {
204
351
  });
205
352
  };
206
353
 
207
- const toggleFav = (g, m, ev) => {
208
- if (ev && ev.stopPropagation) ev.stopPropagation();
209
- const key = `${g}/${m}`;
354
+ const toggleFav = (gid, mid) => {
355
+ const key = `${gid}/${mid}`;
210
356
  const next = new Set(favorites);
211
357
  if (next.has(key)) next.delete(key); else next.add(key);
212
358
  favorites = next;
213
359
  bump((x) => x + 1);
214
360
  };
215
361
 
216
- const isGroupCollapsed = (gid) => {
217
- if (query.trim() !== "") return false;
218
- if (userToggled.has(gid)) return userToggled.get(gid);
219
- const cur = data.current;
220
- const isCurrentGroup = gid === FAVS_KEY
221
- ? (cur !== null && favorites.has(cur.provider + "/" + cur.model))
222
- : (cur !== null && cur.provider === gid);
223
- return !isCurrentGroup;
362
+ const choose = (g, m) => {
363
+ const effort = m.reasoning ? m.reasoning.defaultEffort : undefined;
364
+ selectSelection({ provider: g.id, model: m.id, ...(effort === undefined ? {} : { reasoningEffort: effort }) }, false);
224
365
  };
225
366
 
226
- const toggleCollapse = (gid) => {
227
- const nextState = !isGroupCollapsed(gid);
228
- setUserToggled((prev) => {
229
- const next = new Map(prev);
230
- next.set(gid, nextState);
231
- return next;
232
- });
233
- };
234
-
235
- const scrollToGroup = (gid) => {
236
- if (query !== "") setQuery("");
237
- setUserToggled((prev) => {
238
- // 点击 Tag:只展开目标组,收藏组与其余模型组全部折叠
239
- const next = new Map();
240
- if (data.groups) {
241
- for (const g of data.groups) next.set(g.id, true);
242
- }
243
- next.set(FAVS_KEY, true);
244
- next.set(gid, false);
245
- return next;
246
- });
247
- setTimeout(() => {
248
- if (!bodyRef.current) return;
249
- const el = bodyRef.current.querySelector('[data-group-id="' + gid + '"]');
250
- if (el) {
251
- const bodyRect = bodyRef.current.getBoundingClientRect();
252
- const elRect = el.getBoundingClientRect();
253
- const targetScrollTop = bodyRef.current.scrollTop + (elRect.top - bodyRect.top);
254
- bodyRef.current.scrollTo({ top: Math.max(0, targetScrollTop - 4), behavior: "smooth" });
255
- }
256
- }, 40);
367
+ const chooseEffort = (g, m, effort) => {
368
+ // Staying open lets the user try levels without re-opening the card; the
369
+ // current row's sub block re-renders with the new pin.
370
+ selectSelection({ provider: g.id, model: m.id, ...(effort === undefined ? {} : { reasoningEffort: effort }) }, true);
257
371
  };
258
372
 
259
373
  const current = data.current;
260
374
  const curGroup = current ? data.groups.find((g) => g.id === current.provider) : undefined;
261
375
  const curModel = curGroup ? curGroup.models.find((mm) => mm.id === current.model) : undefined;
262
- // trigger 按钮显示“供应商/模型”,供应商取组的显示名,找不到组时回退 provider id。
263
376
  const providerName = curGroup ? curGroup.name : (current ? current.provider : "");
264
- const modelName = (curModel && curModel.name) || (current ? current.model : "选择模型");
265
- const triggerLabel = current ? (providerName + "/" + modelName) : "选择模型";
266
- const effEffort = current
267
- ? (current.reasoningEffort !== undefined ? current.reasoningEffort : (curModel && curModel.reasoning ? curModel.reasoning.defaultEffort : undefined))
268
- : undefined;
269
- const effMatch = effEffort && curModel && curModel.reasoning ? curModel.reasoning.efforts.find((e) => e.id === effEffort) : undefined;
270
- const effLabel = effMatch ? effMatch.name : (effEffort ? effEffort : (curModel && curModel.reasoning ? "默认" : undefined));
271
-
272
- const allChoices = [];
273
- if (data.groups) {
274
- for (const g of data.groups) {
275
- for (const m of g.models) {
276
- allChoices.push({ g, m, selected: current !== null && current.provider === g.id && current.model === m.id });
277
- }
377
+ const modelName = (curModel && curModel.name) || (current ? current.model : "");
378
+ const pinnedEffort = current ? current.reasoningEffort : undefined;
379
+
380
+ // Trigger effort: the pinned level, else the provider default, else "默认".
381
+ let effortLabel;
382
+ if (curModel && curModel.reasoning) {
383
+ const shown = pinnedEffort !== undefined ? pinnedEffort : curModel.reasoning.defaultEffort;
384
+ if (shown !== undefined) {
385
+ const hit = (curModel.reasoning.efforts || []).find((e) => e.id === shown);
386
+ effortLabel = hit ? hit.name : shown;
387
+ } else {
388
+ effortLabel = "默认";
278
389
  }
279
390
  }
280
391
 
281
392
  const q = query.trim().toLowerCase();
282
- const filtered = q === "" ? allChoices : allChoices.filter((c) => (c.m.name + " " + (c.m.description || "") + " " + c.g.name).toLowerCase().includes(q));
283
- const favs = filtered.filter((c) => favorites.has(`${c.g.id}/${c.m.id}`));
284
- const nonFavs = filtered.filter((c) => !favorites.has(`${c.g.id}/${c.m.id}`));
285
- const favsCollapsed = isGroupCollapsed(FAVS_KEY);
286
-
287
- const tagList = [];
288
- if (favorites.size > 0) {
289
- const isCurrent = current !== null && favorites.has(current.provider + "/" + current.model);
290
- tagList.push({ id: FAVS_KEY, name: "★ 收藏", isCurrent, count: favorites.size });
291
- }
292
- if (data.groups) {
293
- for (const g of data.groups) {
294
- if (g.models && g.models.length > 0) {
295
- const isCurrent = current !== null && current.provider === g.id;
296
- tagList.push({ id: g.id, name: g.name, isCurrent, count: g.models.length });
297
- }
393
+ const matches = (g, m) => q === "" || (m.name + " " + (m.description || "") + " " + g.name).toLowerCase().includes(q);
394
+
395
+ let total = 0;
396
+ const favEntries = [];
397
+ const filteredGroups = [];
398
+ for (const g of data.groups || []) {
399
+ const models = [];
400
+ for (const m of g.models || []) {
401
+ total += 1;
402
+ if (!matches(g, m)) continue;
403
+ // Favorites move to the pinned top group instead of rendering twice.
404
+ if (favorites.has(`${g.id}/${m.id}`)) favEntries.push({ g, m });
405
+ else models.push(m);
298
406
  }
407
+ if (models.length > 0) filteredGroups.push({ id: g.id, name: g.name, models });
299
408
  }
409
+ const noMatch = data.status === "ready" && q !== "" && filteredGroups.length === 0 && favEntries.length === 0;
410
+
411
+ const isCurrentModel = (g, m) => current !== null && current !== undefined && current.provider === g.id && current.model === m.id;
300
412
 
301
- // Group header doubles as a collapse toggle (Enter/Space work too); while
302
- // searching it is inert and every group renders expanded.
303
- const groupTitle = (gid, name, count, isCollapsed, interactive) => React.createElement(
413
+ const heading = (label, icon) => h(
304
414
  "div",
305
- {
306
- className: "mdsl-group-title",
307
- role: "button",
308
- tabIndex: 0,
309
- "aria-expanded": isCollapsed ? false : true,
310
- title: (isCollapsed ? "展开:" : "折叠:") + name,
311
- onClick: interactive ? () => toggleCollapse(gid) : undefined,
312
- onKeyDown: interactive ? (ev) => { if (ev.key === "Enter" || ev.key === " ") { ev.preventDefault(); toggleCollapse(gid); } } : undefined,
313
- },
314
- React.createElement("span", { className: "mdsl-group-chevron" }, chevron()),
315
- React.createElement("span", null, name),
316
- React.createElement("span", { className: "mdsl-group-count" }, count),
415
+ { className: "mdsl-group-title" },
416
+ icon ? h("span", { className: "mdsl-group-icon" }, icon) : null,
417
+ h("span", { className: "mdsl-group-name" }, label),
317
418
  );
318
419
 
319
- const renderRow = (c) => {
320
- const hasEfforts = c.m.reasoning && c.m.reasoning.efforts && c.m.reasoning.efforts.length;
321
- const effEff = current !== null && current.provider === c.g.id && current.model === c.m.id ? effEffort : (hasEfforts ? c.m.reasoning.defaultEffort : undefined);
322
- const isFav = favorites.has(`${c.g.id}/${c.m.id}`);
323
- const chips = [];
324
- if (hasEfforts) {
325
- chips.push(React.createElement("button", { key: "default", className: "mdsl-chip" + (effEff === undefined ? " mdsl-chip-on" : ""), onClick: (ev) => { ev.stopPropagation(); selectSelection({ provider: c.g.id, model: c.m.id }); } }, "默认"));
326
- for (const e of c.m.reasoning.efforts) {
327
- chips.push(React.createElement("button", { key: e.id, className: "mdsl-chip" + (effEff === e.id ? " mdsl-chip-on" : ""), title: e.description || e.name, onClick: (ev) => { ev.stopPropagation(); selectSelection({ provider: c.g.id, model: c.m.id, reasoningEffort: e.id }); } }, e.name));
328
- }
329
- }
330
- return React.createElement("div", {
331
- key: `${c.g.id}/${c.m.id}`,
332
- className: "mdsl-row" + (c.selected ? " mdsl-row-current" : ""),
333
- onClick: () => selectSelection({ provider: c.g.id, model: c.m.id, ...(hasEfforts && c.m.reasoning.defaultEffort !== undefined ? { reasoningEffort: c.m.reasoning.defaultEffort } : {}) }),
334
- },
335
- React.createElement("button", { className: "mdsl-star" + (isFav ? " mdsl-star-on" : ""), "aria-label": isFav ? "取消收藏" : "收藏", onClick: (ev) => toggleFav(c.g.id, c.m.id, ev) }, star(isFav)),
336
- React.createElement("div", { className: "mdsl-row-main" },
337
- React.createElement("div", { className: "mdsl-row-head" },
338
- React.createElement("span", { className: "mdsl-row-name" }, c.m.name),
339
- c.selected ? React.createElement("span", { className: "mdsl-check" }, "✓") : null,
340
- ),
341
- c.m.description ? React.createElement("div", { className: "mdsl-row-desc" }, c.m.description) : null,
342
- chips.length ? React.createElement("div", { className: "mdsl-row-chips" }, chips) : null,
420
+ const renderRow = (g, m, showProvider) => {
421
+ const selected = isCurrentModel(g, m);
422
+ const fav = favorites.has(`${g.id}/${m.id}`);
423
+ const hasEfforts = !!(m.reasoning && m.reasoning.efforts && m.reasoning.efforts.length);
424
+ const desc = typeof m.description === "string" && m.description !== "" ? m.description : undefined;
425
+ const row = h(
426
+ "div",
427
+ {
428
+ className: "mdsl-row",
429
+ role: "button",
430
+ tabIndex: 0,
431
+ "aria-pressed": selected,
432
+ title: desc,
433
+ onClick: () => choose(g, m),
434
+ onKeyDown: (ev) => {
435
+ if (ev.key === "Enter" || ev.key === " ") {
436
+ ev.preventDefault();
437
+ choose(g, m);
438
+ }
439
+ },
440
+ },
441
+ h("span", { className: "mdsl-name" }, m.name),
442
+ showProvider ? h("span", { className: "mdsl-prov" }, g.name) : null,
443
+ h(
444
+ "button",
445
+ {
446
+ type: "button",
447
+ className: "mdsl-star" + (fav ? " mdsl-star-on" : ""),
448
+ "aria-label": fav ? "取消收藏" : "收藏",
449
+ "aria-pressed": fav,
450
+ onClick: (ev) => {
451
+ ev.stopPropagation();
452
+ toggleFav(g.id, m.id);
453
+ },
454
+ // A real button fires click on Enter/Space; keep the row's own
455
+ // keyboard handler out of the way so toggling does not select.
456
+ onKeyDown: (ev) => {
457
+ if (ev.key === "Enter" || ev.key === " ") ev.stopPropagation();
458
+ },
459
+ },
460
+ star(fav),
343
461
  ),
462
+ selected ? h("span", { className: "mdsl-check" }, check()) : null,
344
463
  );
345
- };
346
464
 
347
- const renderGroup = (g) => {
348
- const items = nonFavs.filter((c) => c.g.id === g.id);
349
- if (items.length === 0) return null;
350
- const isCollapsed = isGroupCollapsed(g.id);
351
- return React.createElement("div", {
352
- className: "mdsl-group" + (isCollapsed ? " mdsl-group-collapsed" : ""),
353
- key: g.id,
354
- "data-group-id": g.id,
355
- },
356
- groupTitle(g.id, g.name, items.length, isCollapsed, q === ""),
357
- isCollapsed ? null : items.map(renderRow),
465
+ const sub = selected && (desc !== undefined || hasEfforts)
466
+ ? h(
467
+ "div",
468
+ { className: "mdsl-sub" },
469
+ desc ? h("div", { className: "mdsl-desc" }, desc) : null,
470
+ hasEfforts
471
+ ? h(
472
+ "div",
473
+ { className: "mdsl-track", role: "group", "aria-label": "推理等级" },
474
+ h(
475
+ "button",
476
+ { type: "button", "aria-pressed": pinnedEffort === undefined, className: "mdsl-seg" + (pinnedEffort === undefined ? " mdsl-seg-on" : ""), onClick: () => chooseEffort(g, m, undefined) },
477
+ "默认",
478
+ ),
479
+ m.reasoning.efforts.map((e) => h(
480
+ "button",
481
+ {
482
+ key: e.id,
483
+ type: "button",
484
+ title: e.description || e.name,
485
+ "aria-pressed": pinnedEffort === e.id,
486
+ className: "mdsl-seg" + (pinnedEffort === e.id ? " mdsl-seg-on" : ""),
487
+ onClick: () => chooseEffort(g, m, e.id),
488
+ },
489
+ e.name,
490
+ )),
491
+ )
492
+ : null,
493
+ )
494
+ : null;
495
+
496
+ return h(
497
+ "div",
498
+ { key: `${g.id}/${m.id}`, className: "mdsl-item" + (selected ? " mdsl-item-current" : "") },
499
+ row,
500
+ sub,
358
501
  );
359
502
  };
360
503
 
361
- return React.createElement("div", { className: "mdsl-root" },
362
- React.createElement("button", {
363
- className: "mdsl-trigger",
364
- onClick: () => { if (open) closeMenu(); else openMenu(); },
365
- disabled: locked,
366
- title: triggerLabel + (effLabel ? " · " + effLabel : ""),
367
- },
368
- React.createElement("span", { className: "mdsl-label" }, triggerLabel),
369
- effLabel ? [React.createElement("span", { className: "mdsl-sep" }, "·"), React.createElement("span", { className: "mdsl-effort" }, effLabel)] : null,
370
- React.createElement("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, "▾"),
504
+ const onMenuKeyDown = (ev) => {
505
+ if (ev.key === "Escape") {
506
+ ev.preventDefault();
507
+ ev.stopPropagation();
508
+ closeMenu();
509
+ return;
510
+ }
511
+ if (ev.key !== "ArrowDown" && ev.key !== "ArrowUp") return;
512
+ const body = bodyRef.current;
513
+ if (!body) return;
514
+ const rows = Array.from(body.querySelectorAll(".mdsl-row"));
515
+ if (rows.length === 0) return;
516
+ ev.preventDefault();
517
+ const at = rows.indexOf(document.activeElement);
518
+ const step = ev.key === "ArrowDown" ? 1 : -1;
519
+ const next = at === -1
520
+ ? (step > 0 ? 0 : rows.length - 1)
521
+ : (at + step + rows.length) % rows.length;
522
+ rows[next].focus();
523
+ };
524
+
525
+ const triggerTitle = current
526
+ ? (providerName ? providerName + " / " + modelName : modelName) + (effortLabel ? " / " + effortLabel : "")
527
+ : "选择模型";
528
+
529
+ return h(
530
+ "div",
531
+ { className: "mdsl-root" },
532
+ h(
533
+ "button",
534
+ {
535
+ ref: triggerRef,
536
+ type: "button",
537
+ className: "mdsl-trigger",
538
+ onClick: () => { if (open) closeMenu(); else openMenu(); },
539
+ disabled: locked,
540
+ title: triggerTitle,
541
+ "aria-haspopup": "dialog",
542
+ "aria-expanded": open,
543
+ },
544
+ h("span", { className: "mdsl-label" }, current ? modelName : "选择模型"),
545
+ effortLabel ? h("span", { className: "mdsl-effort" }, effortLabel) : null,
546
+ h("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown()),
371
547
  ),
372
- open ? React.createElement("div", { className: "mdsl-backdrop", onClick: closeMenu }) : null,
373
- open ? React.createElement("div", { className: "mdsl-menu" },
374
- React.createElement("div", { className: "mdsl-header" },
375
- React.createElement("div", { className: "mdsl-summary" },
376
- React.createElement("span", { className: "mdsl-summary-dot" }),
377
- current
378
- ? [React.createElement("span", { className: "mdsl-summary-lbl" }, "当前"), React.createElement("span", { className: "mdsl-summary-b" }, modelName)]
379
- : React.createElement("span", { className: "mdsl-summary-lbl" }, "选择模型"),
380
- ),
381
- React.createElement("div", { className: "mdsl-search-wrap" },
382
- searchIcon(),
383
- React.createElement("input", { className: "mdsl-search", placeholder: "搜索模型 / 描述 / 提供商…", value: query, onChange: (ev) => setQuery(ev.target.value), onKeyDown: (ev) => { if (ev.key === "Escape") closeMenu(); } }),
384
- query !== "" ? React.createElement("button", { className: "mdsl-search-clear", onClick: () => setQuery("") }, "×") : null,
385
- ),
386
- tagList.length > 0 ? React.createElement("div", { className: "mdsl-tags" },
387
- tagList.map((tag) => React.createElement("button", {
388
- key: tag.id,
389
- type: "button",
390
- className: "mdsl-tag" + (tag.isCurrent ? " mdsl-tag-current" : ""),
391
- title: "跳转至 " + tag.name,
392
- onClick: () => scrollToGroup(tag.id),
393
- },
394
- tag.isCurrent ? React.createElement("span", { className: "mdsl-tag-dot" }) : null,
395
- React.createElement("span", null, tag.name),
396
- React.createElement("span", { className: "mdsl-tag-count" }, "(" + tag.count + ")"),
397
- )),
398
- ) : null,
399
- ),
400
- data.status === "error" ? React.createElement("div", { className: "mdsl-error" }, data.error || "加载失败") : null,
401
- data.failures && data.failures.length ? React.createElement("div", { className: "mdsl-error" }, data.failures.map((f) => f.name + ": " + f.message).join(";")) : null,
402
- React.createElement("div", { className: "mdsl-body", ref: bodyRef },
403
- data.status === "loading" ? React.createElement("div", { className: "mdsl-empty" }, "加载中…") : null,
404
- data.status === "ready" && allChoices.length === 0 ? React.createElement("div", { className: "mdsl-empty" }, "暂无可用模型") : null,
405
- favs.length ? React.createElement("div", {
406
- className: "mdsl-group" + (favsCollapsed ? " mdsl-group-collapsed" : ""),
407
- key: FAVS_KEY,
408
- "data-group-id": FAVS_KEY,
548
+ open ? h("div", { className: "mdsl-backdrop", onClick: closeMenu }) : null,
549
+ open && placement !== null ? h(
550
+ "div",
551
+ {
552
+ className: "mdsl-menu",
553
+ style: {
554
+ left: placement.left + "px",
555
+ width: placement.width + "px",
556
+ maxWidth: placement.width + "px",
557
+ maxHeight: placement.maxHeight + "px",
558
+ ...(placement.side === "top"
559
+ ? { top: "auto", bottom: placement.bottom + "px" }
560
+ : { top: placement.top + "px", bottom: "auto" }),
561
+ transformOrigin: placement.side === "top" ? "bottom right" : "top right",
409
562
  },
410
- groupTitle(FAVS_KEY, "收藏", favs.length, favsCollapsed, q === ""),
411
- favsCollapsed ? null : favs.map(renderRow),
412
- ) : null,
413
- (data.groups || []).map(renderGroup),
563
+ role: "dialog",
564
+ "aria-label": "选择模型",
565
+ onKeyDown: onMenuKeyDown,
566
+ },
567
+ h(
568
+ "div",
569
+ { className: "mdsl-search-wrap" },
570
+ searchIcon(),
571
+ h("input", {
572
+ ref: searchRef,
573
+ className: "mdsl-search",
574
+ type: "text",
575
+ "aria-label": "搜索模型",
576
+ placeholder: "搜索模型",
577
+ value: query,
578
+ onChange: (ev) => setQuery(ev.target.value),
579
+ }),
580
+ query !== ""
581
+ ? h("button", {
582
+ type: "button",
583
+ className: "mdsl-search-clear",
584
+ "aria-label": "清除搜索",
585
+ onClick: () => {
586
+ setQuery("");
587
+ const el = searchRef.current;
588
+ if (el) el.focus({ preventScroll: true });
589
+ },
590
+ }, closeIcon())
591
+ : null,
414
592
  ),
415
- React.createElement("div", { className: "mdsl-footer" },
416
- React.createElement("span", { className: "mdsl-footer-dot" }),
417
- React.createElement("span", null, "点击模型或推理等级即可切换 · 星标收藏会置顶"),
593
+ data.status === "error" ? h("div", { className: "mdsl-error" }, data.error || "加载失败") : null,
594
+ data.failures && data.failures.length
595
+ ? h("div", { className: "mdsl-error" }, data.failures.map((f) => f.name + ": " + f.message).join(";"))
596
+ : null,
597
+ h(
598
+ "div",
599
+ { className: "mdsl-body", ref: bodyRef, role: "group", "aria-label": "模型列表" },
600
+ data.status === "loading" ? h("div", { className: "mdsl-empty" }, "加载中…") : null,
601
+ data.status === "ready" && total === 0 ? h("div", { className: "mdsl-empty" }, "暂无可用模型") : null,
602
+ noMatch ? h("div", { className: "mdsl-empty" }, "没有匹配的模型") : null,
603
+ favEntries.length > 0
604
+ ? h(
605
+ "div",
606
+ { className: "mdsl-group", key: FAVS_KEY },
607
+ heading("收藏", star(true)),
608
+ favEntries.map(({ g, m }) => renderRow(g, m, true)),
609
+ )
610
+ : null,
611
+ filteredGroups.map((g) => h(
612
+ "div",
613
+ { className: "mdsl-group", key: g.id },
614
+ heading(g.name),
615
+ g.models.map((m) => renderRow(g, m, false)),
616
+ )),
418
617
  ),
419
618
  ) : null,
420
619
  );