dsh-model-select-plus 0.1.7 → 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,19 +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
- * Layout intent (quiet / native / scannable): the popup borrows the shipped
13
- * Menu / Input vocabulary from `dsh-client-ui-primitives` so it reads as the
14
- * same material as every other DSH dropdown:
15
- * - translucent menu surface + prominent elevation, 16px card radius, 4px pad
16
- * - 13/20 trigger with ellipsis label and a caption-tone effort, 28px tall
17
- * (matches the sibling permission / plan controls in the composer row)
18
- * - one 32px search field; provider jump tags ride a single horizontally
19
- * scrolling rail (no wrapped wall of chips, no duplicated counts)
20
- * - sticky 11/16 provider headings; the scanning order is search → jump →
21
- * grouped models, with the current model repeated in a pinned footer
22
- * - model row: 20px star column, 13/20 name + trailing check, 12/16
23
- * two-line description, 20px reasoning-effort chips
24
- * - all icons are authored SVG (no text glyphs standing in for icons)
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)
25
27
  *
26
28
  * Data comes from the Host half at `/plugins/dsh-model-select-plus/api`.
27
29
  * The seat passes `locked` (owner prop) and we inject `sessionId`.
@@ -36,14 +38,16 @@ const API = "/plugins/dsh-model-select-plus/api";
36
38
  const STYLE_TAG = "dsh-model-select-plus/style";
37
39
  const FAVS_KEY = "__favorites__";
38
40
 
41
+ const h = React.createElement;
42
+
39
43
  const CSS = `
40
44
  .mdsl-root, .mdsl-root *, .mdsl-root *::before, .mdsl-root *::after { box-sizing: border-box; }
41
45
  .mdsl-root { position: relative; display: inline-flex; align-items: center; min-width: 0; max-width: 100%; }
42
46
  .mdsl-backdrop { position: fixed; inset: 0; z-index: 35; }
43
47
 
44
- /* Trigger: same 28px chip as the composer's sibling permission / plan
48
+ /* Trigger: the composer's 28px chip, same as the sibling permission / plan
45
49
  controls, so the row does not jump when this plugin replaces the seat. */
46
- .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; transition: background .14s ease; }
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; }
47
51
  .mdsl-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
48
52
  .mdsl-trigger:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
49
53
  .mdsl-trigger:disabled { color: var(--dsw-alias-label-dimmed); cursor: default; }
@@ -51,88 +55,72 @@ const CSS = `
51
55
  /* The effort absorbs the deficit first: it ellipsizes to nothing before the
52
56
  model name loses a pixel, and the chevron stays snug. */
53
57
  .mdsl-effort { flex-shrink: 1000; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-caption); }
54
- .mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); transition: transform .12s ease; }
58
+ .mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); }
55
59
  .mdsl-chevron-open { transform: rotate(180deg); }
56
60
 
57
- /* Card: the shipped menu material (translucent fill + blur + prominent
58
- elevation stroke) so every DSH dropdown reads the same. */
59
- .mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width: 384px; max-width: calc(100vw - 24px); max-height: min(480px, 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; }
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; }
60
64
  body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
61
65
  @keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
62
66
  @media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
63
67
 
64
- /* Header: one search field + one jump rail. Everything else belongs to the
65
- scrolling body, so the fixed chrome stays ~74px instead of a wrapped tag
66
- wall that ate a third of the card. */
67
- .mdsl-header { flex: none; display: flex; flex-direction: column; gap: 6px; padding: 4px 4px 6px; }
68
- .mdsl-search-wrap { position: relative; display: flex; align-items: center; }
69
- .mdsl-search-icon { position: absolute; left: 9px; display: flex; color: var(--dsw-alias-label-tertiary); pointer-events: none; }
70
- .mdsl-search { width: 100%; height: 32px; padding: 0 30px 0 29px; border: 0.5px solid var(--dsw-alias-border-l4); border-radius: var(--dsw-radius-md, 12px); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; line-height: 20px; outline: none; transition: border-color .14s ease; }
71
- .mdsl-search::placeholder { color: var(--dsw-alias-label-tertiary); }
72
- .mdsl-search:focus { border-color: var(--dsw-alias-state-business-primary); }
73
- .mdsl-search-clear { position: absolute; right: 5px; 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; }
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; }
74
77
  .mdsl-search-clear:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
75
78
  .mdsl-search-clear:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
76
79
 
77
- /* Provider jump rail: single row, horizontal scroll. Counts live on the
78
- sticky group headings only — the old rail repeated them in parentheses. */
79
- .mdsl-tags { display: flex; align-items: center; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 1px 0; scrollbar-width: none; -ms-overflow-style: none; -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent); }
80
- .mdsl-tags::-webkit-scrollbar { display: none; }
81
- .mdsl-tag { flex: none; display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 9px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px; background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); font-family: inherit; font-size: 11px; line-height: 16px; cursor: pointer; user-select: none; transition: border-color .12s ease, color .12s ease, background .12s ease; }
82
- .mdsl-tag:hover { border-color: var(--dsw-alias-border-l2); background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
83
- .mdsl-tag:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
84
- .mdsl-tag-current { border-color: var(--dsw-alias-brand-primary); background: var(--dsw-alias-interactive-bg-active); color: var(--dsw-alias-label-primary); font-weight: 500; }
85
- .mdsl-tag-icon { display: inline-flex; margin-left: -2px; color: var(--dsw-alias-brand-primary); }
86
- .mdsl-tag-name { white-space: nowrap; }
87
-
88
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; }
89
81
  .mdsl-body::-webkit-scrollbar { width: 8px; }
90
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; }
91
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; }
92
84
 
93
- /* Group headings stick while their rows scroll, painted with the shipped
94
- menu-group fill so rows never bleed through. Normal case (text-transform:
95
- uppercase mangles mixed CJK/Latin provider names). */
96
- .mdsl-group { display: flex; flex-direction: column; gap: 1px; }
97
- .mdsl-group + .mdsl-group { margin-top: 3px; }
98
- .mdsl-group-title { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 5px; padding: 4px 7px 3px; background-color: var(--dsw-alias-bg-overlay); background-image: linear-gradient(var(--dsw-alias-menu-group-header-fill, transparent), var(--dsw-alias-menu-group-header-fill, transparent)); color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; font-weight: 500; cursor: pointer; user-select: none; transition: color .12s ease; }
99
- .mdsl-group-title:hover { color: var(--dsw-alias-label-secondary); }
100
- .mdsl-group-title:focus-visible { outline: none; color: var(--dsw-alias-label-primary); }
101
- .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; }
102
- .mdsl-group-collapsed .mdsl-group-chevron { transform: none; }
103
- .mdsl-group-icon { flex: none; display: inline-flex; color: var(--dsw-alias-brand-primary); }
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); }
104
93
  .mdsl-group-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
105
- .mdsl-group-count { flex: none; margin-left: auto; color: var(--dsw-alias-label-caption); font-variant-numeric: tabular-nums; }
106
94
 
107
- .mdsl-row { display: flex; align-items: flex-start; gap: 7px; padding: 6px 8px; border-radius: var(--dsw-radius-md, 12px); cursor: pointer; transition: background .12s ease; }
108
- .mdsl-row:hover { background: var(--dsw-alias-interactive-bg-hover); }
109
- .mdsl-row-current, .mdsl-row-current:hover { background: var(--dsw-alias-interactive-bg-active); }
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; }
110
100
  .mdsl-row:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--dsw-alias-state-business-primary); }
111
- .mdsl-star { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; margin: 0 0 0 -2px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--dsw-alias-label-tertiary); cursor: pointer; transition: color .12s ease, background .12s ease; }
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; }
112
107
  .mdsl-star:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
113
108
  .mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
114
109
  .mdsl-star-on { color: var(--dsw-alias-brand-primary); }
115
- .mdsl-row-main { flex: 1; min-width: 0; }
116
- .mdsl-row-head { display: flex; align-items: center; gap: 6px; min-width: 0; min-height: 20px; }
117
- .mdsl-row-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-primary); font-size: 13px; line-height: 20px; font-weight: 500; }
118
- .mdsl-check { flex: none; display: inline-flex; margin-left: auto; color: var(--dsw-alias-brand-primary); }
119
- .mdsl-row-desc { margin-top: 1px; 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; }
120
- .mdsl-row-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
121
- .mdsl-chip { height: 20px; padding: 0 8px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px; background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); font-family: inherit; font-size: 11px; line-height: 18px; cursor: pointer; transition: border-color .12s ease, color .12s ease, background .12s ease; }
122
- .mdsl-chip:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
123
- .mdsl-chip:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
124
- .mdsl-chip-on { border-color: var(--dsw-alias-brand-primary); background: transparent; color: var(--dsw-alias-label-primary); font-weight: 500; }
125
-
126
- .mdsl-empty { padding: 18px 10px; text-align: center; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
127
- .mdsl-empty-sub { margin-top: 2px; color: var(--dsw-alias-label-caption); font-size: 11px; line-height: 16px; }
128
- .mdsl-error { margin: 4px 2px; padding: 6px 8px; border-radius: var(--dsw-radius-sm, 8px); background: var(--dsw-alias-interactive-bg-hover-danger); color: var(--dsw-alias-state-error-primary); font-size: 11px; line-height: 16px; }
129
-
130
- /* Pinned footer: repeats the current selection while the body is scrolled
131
- into some other provider, plus the only keyboard shortcut worth naming. */
132
- .mdsl-footer { flex: none; display: flex; align-items: center; gap: 6px; margin-top: 2px; padding: 5px 6px 3px; border-top: 0.5px solid var(--dsw-alias-border-l2); color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; }
133
- .mdsl-footer-dot { flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--dsw-alias-brand-primary); }
134
- .mdsl-footer-current { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-secondary); }
135
- .mdsl-footer-hint { flex: none; color: var(--dsw-alias-label-caption); font-variant-numeric: tabular-nums; }
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; }
136
124
  `;
137
125
 
138
126
  function injectStyle() {
@@ -145,67 +133,58 @@ function injectStyle() {
145
133
  return () => { tag.remove(); };
146
134
  }
147
135
 
148
- const star = (filled) => React.createElement(
136
+ const star = (filled) => h(
149
137
  "svg",
150
138
  { width: 14, height: 14, viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
151
- 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" }),
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" }),
152
140
  );
153
141
 
154
- const chevron = () => React.createElement(
142
+ const check = () => h(
155
143
  "svg",
156
- { width: 10, height: 10, viewBox: "0 0 10 10", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
157
- React.createElement("path", { d: "M3.5 2.5L6.5 5l-3 2.5", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", 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" }),
158
146
  );
159
147
 
160
- const chevronDown = () => React.createElement(
148
+ const chevronDown = () => h(
161
149
  "svg",
162
150
  { width: 12, height: 12, viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
163
- React.createElement("path", { d: "M3 4.75L6 7.75l3-3", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round" }),
164
- );
165
-
166
- const check = () => React.createElement(
167
- "svg",
168
- { width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
169
- React.createElement("path", { d: "M2.8 7.4l2.6 2.6 5.8-6.4", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" }),
151
+ h("path", { d: "M3 4.75L6 7.75l3-3", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round" }),
170
152
  );
171
153
 
172
- const closeIcon = () => React.createElement(
154
+ const closeIcon = () => h(
173
155
  "svg",
174
156
  { width: 12, height: 12, viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
175
- React.createElement("path", { d: "M3 3l6 6M9 3L3 9", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" }),
157
+ h("path", { d: "M3 3l6 6M9 3L3 9", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" }),
176
158
  );
177
159
 
178
- const searchIcon = () => React.createElement(
160
+ const searchIcon = () => h(
179
161
  "span",
180
162
  { className: "mdsl-search-icon" },
181
- React.createElement(
163
+ h(
182
164
  "svg",
183
165
  { width: 14, height: 14, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
184
- React.createElement("circle", { cx: 7, cy: 7, r: 5, stroke: "currentColor", strokeWidth: 1.4 }),
185
- React.createElement("line", { x1: 10.8, y1: 10.8, x2: 14, y2: 14, stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" }),
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" }),
186
168
  ),
187
169
  );
188
170
 
189
171
  function ModelSelectLite(props) {
190
172
  const sessionId = props.sessionId;
191
173
  const locked = props.locked === true;
192
- const bodyRef = React.useRef(null);
193
174
  const triggerRef = React.useRef(null);
175
+ const bodyRef = React.useRef(null);
194
176
  const searchRef = React.useRef(null);
195
- const tagRailRef = React.useRef(null);
196
177
  const [placement, setPlacement] = React.useState(null);
197
178
  const [open, setOpen] = React.useState(false);
198
179
  const [data, setData] = React.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
199
180
  const [query, setQuery] = React.useState("");
200
181
  const [busy, setBusy] = React.useState(false);
201
182
  const [, bump] = React.useState(0);
202
- // Manual overrides for group fold state (id -> boolean). By default, only
203
- // the group containing the currently selected model is expanded; all other
204
- // groups default to collapsed. Searching force-expands every group.
205
- const [userToggled, setUserToggled] = React.useState(() => new Map());
206
183
 
207
184
  const load = () => {
208
- 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 }));
209
188
  const url = `${API}/catalog?sessionId=${encodeURIComponent(sessionId)}`;
210
189
  fetch(url)
211
190
  .then((res) => res.json())
@@ -224,56 +203,61 @@ function ModelSelectLite(props) {
224
203
  // Load on mount (and when the session changes) so the trigger shows the
225
204
  // current model immediately instead of the "选择模型" placeholder.
226
205
  React.useEffect(() => {
227
- if (sessionId !== undefined) {
228
- setUserToggled(new Map());
229
- load();
230
- }
206
+ if (sessionId !== undefined) load();
231
207
  }, [sessionId]);
232
208
 
233
209
  // Opening the menu focuses the search field: typing filters immediately and
234
- // Escape lands on the menu's key handler for free.
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);
235
214
  React.useEffect(() => {
236
- if (!open || placement === null) return;
215
+ if (!open) {
216
+ focusedForOpen.current = false;
217
+ return;
218
+ }
219
+ if (placement === null || focusedForOpen.current) return;
220
+ focusedForOpen.current = true;
237
221
  const el = searchRef.current;
238
- // preventScroll: the card is already placed inside the viewport; letting
239
- // focus chase the input would scroll the page and push the card's top row
240
- // out of view on short windows.
241
222
  if (el) el.focus({ preventScroll: true });
242
223
  }, [open, placement]);
243
224
 
244
- // Keep the current provider's jump tag in view inside the scroll rail.
245
- React.useEffect(() => {
246
- if (!open) return;
247
- const rail = tagRailRef.current;
248
- if (!rail) return;
249
- const current = rail.querySelector('[data-current="true"]');
250
- if (!current) return;
251
- const left = current.offsetLeft - (rail.clientWidth - current.offsetWidth) / 2;
252
- rail.scrollTo({ left: Math.max(0, left), behavior: "smooth" });
253
- }, [open, data.current, data.status]);
254
-
255
225
  // Measure the room around the trigger before painting: open upward while it
256
226
  // fits, flip downward when the window is short, clamp inside the viewport,
257
- // and cap the card height so the scrolling body always keeps the footer.
227
+ // and cap the card height so the scrolling body always keeps its last row.
258
228
  const placeMenu = () => {
259
229
  const trigger = triggerRef.current;
260
230
  if (!trigger) return;
261
231
  const rect = trigger.getBoundingClientRect();
262
232
  const margin = 12;
263
233
  const gap = 6;
264
- const width = Math.min(384, window.innerWidth - margin * 2);
234
+ const width = Math.min(320, window.innerWidth - margin * 2);
265
235
  const spaceAbove = rect.top - gap - margin;
266
236
  const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
267
237
  const side = spaceAbove >= spaceBelow ? "top" : "bottom";
268
- const maxHeight = Math.max(160, Math.min(480, side === "top" ? spaceAbove : spaceBelow));
238
+ const maxHeight = Math.max(180, Math.min(440, side === "top" ? spaceAbove : spaceBelow));
269
239
  const left = Math.min(Math.max(margin, rect.right - width), window.innerWidth - width - margin);
270
- setPlacement({
271
- side,
272
- maxHeight,
273
- width,
274
- left,
275
- bottom: window.innerHeight - rect.top + gap,
276
- top: rect.bottom + gap,
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;
277
261
  });
278
262
  };
279
263
 
@@ -283,7 +267,12 @@ function ModelSelectLite(props) {
283
267
 
284
268
  React.useEffect(() => {
285
269
  if (!open) return;
286
- const reposition = () => placeMenu();
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
+ };
287
276
  window.addEventListener("resize", reposition);
288
277
  window.addEventListener("scroll", reposition, true);
289
278
  return () => {
@@ -292,6 +281,34 @@ function ModelSelectLite(props) {
292
281
  };
293
282
  }, [open]);
294
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
+
295
312
  const focusTrigger = () => {
296
313
  const el = triggerRef.current;
297
314
  if (el) el.focus({ preventScroll: true });
@@ -304,7 +321,7 @@ function ModelSelectLite(props) {
304
321
  focusTrigger();
305
322
  };
306
323
 
307
- const selectSelection = (sel) => {
324
+ const selectSelection = (sel, keepOpen) => {
308
325
  if (busy) return;
309
326
  setBusy(true);
310
327
  fetch(`${API}/select`, {
@@ -321,8 +338,8 @@ function ModelSelectLite(props) {
321
338
  .then((res) => {
322
339
  setBusy(false);
323
340
  if (res && res.ok === true) {
324
- setData((d) => ({ ...d, current: res.selected, error: null }));
325
- setUserToggled(new Map());
341
+ setData((d) => ({ ...d, current: res.selected || null, error: null }));
342
+ if (keepOpen) return;
326
343
  closeMenu();
327
344
  } else {
328
345
  setData((d) => ({ ...d, error: (res && res.message) || "选择失败" }));
@@ -334,255 +351,269 @@ function ModelSelectLite(props) {
334
351
  });
335
352
  };
336
353
 
337
- const toggleFav = (g, m, ev) => {
338
- if (ev && ev.stopPropagation) ev.stopPropagation();
339
- const key = `${g}/${m}`;
354
+ const toggleFav = (gid, mid) => {
355
+ const key = `${gid}/${mid}`;
340
356
  const next = new Set(favorites);
341
357
  if (next.has(key)) next.delete(key); else next.add(key);
342
358
  favorites = next;
343
359
  bump((x) => x + 1);
344
360
  };
345
361
 
346
- const isGroupCollapsed = (gid) => {
347
- if (query.trim() !== "") return false;
348
- if (userToggled.has(gid)) return userToggled.get(gid);
349
- const cur = data.current;
350
- const isCurrentGroup = gid === FAVS_KEY
351
- ? (cur !== null && favorites.has(cur.provider + "/" + cur.model))
352
- : (cur !== null && cur.provider === gid);
353
- return !isCurrentGroup;
354
- };
355
-
356
- const toggleCollapse = (gid) => {
357
- const nextState = !isGroupCollapsed(gid);
358
- setUserToggled((prev) => {
359
- const next = new Map(prev);
360
- next.set(gid, nextState);
361
- return next;
362
- });
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);
363
365
  };
364
366
 
365
- const scrollToGroup = (gid) => {
366
- if (query !== "") setQuery("");
367
- setUserToggled((prev) => {
368
- // 点击 Tag:只展开目标组,收藏组与其余模型组全部折叠
369
- const next = new Map();
370
- if (data.groups) {
371
- for (const g of data.groups) next.set(g.id, true);
372
- }
373
- next.set(FAVS_KEY, true);
374
- next.set(gid, false);
375
- return next;
376
- });
377
- setTimeout(() => {
378
- if (!bodyRef.current) return;
379
- const el = bodyRef.current.querySelector('[data-group-id="' + gid + '"]');
380
- if (el) {
381
- const bodyRect = bodyRef.current.getBoundingClientRect();
382
- const elRect = el.getBoundingClientRect();
383
- const targetScrollTop = bodyRef.current.scrollTop + (elRect.top - bodyRect.top);
384
- bodyRef.current.scrollTo({ top: Math.max(0, targetScrollTop - 2), behavior: "smooth" });
385
- }
386
- }, 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);
387
371
  };
388
372
 
389
373
  const current = data.current;
390
374
  const curGroup = current ? data.groups.find((g) => g.id === current.provider) : undefined;
391
375
  const curModel = curGroup ? curGroup.models.find((mm) => mm.id === current.model) : undefined;
392
- // trigger 按钮显示“供应商/模型”,供应商取组的显示名,找不到组时回退 provider id。
393
376
  const providerName = curGroup ? curGroup.name : (current ? current.provider : "");
394
- const modelName = (curModel && curModel.name) || (current ? current.model : "选择模型");
395
- const triggerLabel = current ? (providerName + "/" + modelName) : "选择模型";
396
- const effEffort = current
397
- ? (current.reasoningEffort !== undefined ? current.reasoningEffort : (curModel && curModel.reasoning ? curModel.reasoning.defaultEffort : undefined))
398
- : undefined;
399
- const effMatch = effEffort && curModel && curModel.reasoning ? curModel.reasoning.efforts.find((e) => e.id === effEffort) : undefined;
400
- const effLabel = effMatch ? effMatch.name : (effEffort ? effEffort : (curModel && curModel.reasoning ? "默认" : undefined));
401
-
402
- const allChoices = [];
403
- if (data.groups) {
404
- for (const g of data.groups) {
405
- for (const m of g.models) {
406
- allChoices.push({ g, m, selected: current !== null && current.provider === g.id && current.model === m.id });
407
- }
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 = "默认";
408
389
  }
409
390
  }
410
391
 
411
392
  const q = query.trim().toLowerCase();
412
- const filtered = q === "" ? allChoices : allChoices.filter((c) => (c.m.name + " " + (c.m.description || "") + " " + c.g.name).toLowerCase().includes(q));
413
- const favs = filtered.filter((c) => favorites.has(`${c.g.id}/${c.m.id}`));
414
- const nonFavs = filtered.filter((c) => !favorites.has(`${c.g.id}/${c.m.id}`));
415
- const favsCollapsed = isGroupCollapsed(FAVS_KEY);
416
-
417
- const tagList = [];
418
- if (favorites.size > 0) {
419
- const isCurrent = current !== null && favorites.has(current.provider + "/" + current.model);
420
- tagList.push({ id: FAVS_KEY, name: "收藏", isCurrent });
421
- }
422
- if (data.groups) {
423
- for (const g of data.groups) {
424
- if (g.models && g.models.length > 0) {
425
- const isCurrent = current !== null && current.provider === g.id;
426
- tagList.push({ id: g.id, name: g.name, isCurrent });
427
- }
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);
428
406
  }
407
+ if (models.length > 0) filteredGroups.push({ id: g.id, name: g.name, models });
429
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;
430
412
 
431
- // Group header doubles as a collapse toggle (Enter/Space work too); while
432
- // searching it is inert and every group renders expanded.
433
- const groupTitle = (gid, name, count, isCollapsed, interactive, icon) => React.createElement(
413
+ const heading = (label, icon) => h(
434
414
  "div",
435
- {
436
- className: "mdsl-group-title",
437
- role: "button",
438
- tabIndex: 0,
439
- "aria-expanded": isCollapsed ? false : true,
440
- title: (isCollapsed ? "展开:" : "折叠:") + name,
441
- onClick: interactive ? () => toggleCollapse(gid) : undefined,
442
- onKeyDown: interactive ? (ev) => { if (ev.key === "Enter" || ev.key === " ") { ev.preventDefault(); toggleCollapse(gid); } } : undefined,
443
- },
444
- React.createElement("span", { className: "mdsl-group-chevron" }, chevron()),
445
- icon ? React.createElement("span", { className: "mdsl-group-icon" }, icon) : null,
446
- React.createElement("span", { className: "mdsl-group-name" }, name),
447
- 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),
448
418
  );
449
419
 
450
- const renderRow = (c) => {
451
- const hasEfforts = c.m.reasoning && c.m.reasoning.efforts && c.m.reasoning.efforts.length;
452
- const effEff = current !== null && current.provider === c.g.id && current.model === c.m.id ? effEffort : (hasEfforts ? c.m.reasoning.defaultEffort : undefined);
453
- const isFav = favorites.has(`${c.g.id}/${c.m.id}`);
454
- const chips = [];
455
- if (hasEfforts) {
456
- chips.push(React.createElement("button", { key: "default", type: "button", className: "mdsl-chip" + (effEff === undefined ? " mdsl-chip-on" : ""), "aria-pressed": effEff === undefined, onClick: (ev) => { ev.stopPropagation(); selectSelection({ provider: c.g.id, model: c.m.id }); } }, "默认"));
457
- for (const e of c.m.reasoning.efforts) {
458
- chips.push(React.createElement("button", { key: e.id, type: "button", className: "mdsl-chip" + (effEff === e.id ? " mdsl-chip-on" : ""), "aria-pressed": effEff === e.id, title: e.description || e.name, onClick: (ev) => { ev.stopPropagation(); selectSelection({ provider: c.g.id, model: c.m.id, reasoningEffort: e.id }); } }, e.name));
459
- }
460
- }
461
- const selectRow = () => selectSelection({ provider: c.g.id, model: c.m.id, ...(hasEfforts && c.m.reasoning.defaultEffort !== undefined ? { reasoningEffort: c.m.reasoning.defaultEffort } : {}) });
462
- return React.createElement("div", {
463
- key: `${c.g.id}/${c.m.id}`,
464
- className: "mdsl-row" + (c.selected ? " mdsl-row-current" : ""),
465
- role: "button",
466
- tabIndex: 0,
467
- "aria-pressed": c.selected,
468
- onClick: selectRow,
469
- onKeyDown: (ev) => { if (ev.key === "Enter" || ev.key === " ") { ev.preventDefault(); selectRow(); } },
470
- },
471
- React.createElement("button", { type: "button", className: "mdsl-star" + (isFav ? " mdsl-star-on" : ""), "aria-label": isFav ? "取消收藏" : "收藏", "aria-pressed": isFav, onClick: (ev) => toggleFav(c.g.id, c.m.id, ev) }, star(isFav)),
472
- React.createElement("div", { className: "mdsl-row-main" },
473
- React.createElement("div", { className: "mdsl-row-head" },
474
- React.createElement("span", { className: "mdsl-row-name" }, c.m.name),
475
- c.selected ? React.createElement("span", { className: "mdsl-check" }, check()) : null,
476
- ),
477
- c.m.description ? React.createElement("div", { className: "mdsl-row-desc" }, c.m.description) : null,
478
- 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),
479
461
  ),
462
+ selected ? h("span", { className: "mdsl-check" }, check()) : null,
480
463
  );
481
- };
482
464
 
483
- const renderGroup = (g) => {
484
- const items = nonFavs.filter((c) => c.g.id === g.id);
485
- if (items.length === 0) return null;
486
- const isCollapsed = isGroupCollapsed(g.id);
487
- return React.createElement("div", {
488
- className: "mdsl-group" + (isCollapsed ? " mdsl-group-collapsed" : ""),
489
- key: g.id,
490
- "data-group-id": g.id,
491
- },
492
- groupTitle(g.id, g.name, items.length, isCollapsed, q === ""),
493
- 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,
494
501
  );
495
502
  };
496
503
 
497
- const noMatch = data.status === "ready" && q !== "" && filtered.length === 0;
498
- const currentEffortText = effLabel && effLabel !== "默认" ? effLabel : "";
499
-
500
- return React.createElement("div", { className: "mdsl-root" },
501
- React.createElement("button", {
502
- ref: triggerRef,
503
- type: "button",
504
- className: "mdsl-trigger",
505
- onClick: () => { if (open) closeMenu(); else openMenu(); },
506
- disabled: locked,
507
- title: triggerLabel + (effLabel ? " · " + effLabel : ""),
508
- "aria-haspopup": "dialog",
509
- "aria-expanded": open,
510
- },
511
- React.createElement("span", { className: "mdsl-label" }, triggerLabel),
512
- effLabel ? React.createElement("span", { className: "mdsl-effort" }, effLabel) : null,
513
- React.createElement("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown()),
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()),
514
547
  ),
515
- open ? React.createElement("div", { className: "mdsl-backdrop", onClick: closeMenu }) : null,
516
- open && placement !== null ? React.createElement("div", {
517
- className: "mdsl-menu",
518
- style: {
519
- left: placement.left + "px",
520
- width: placement.width + "px",
521
- maxWidth: placement.width + "px",
522
- maxHeight: placement.maxHeight + "px",
523
- ...(placement.side === "top"
524
- ? { top: "auto", bottom: placement.bottom + "px" }
525
- : { top: placement.top + "px", bottom: "auto" }),
526
- transformOrigin: placement.side === "top" ? "bottom right" : "top right",
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",
562
+ },
563
+ role: "dialog",
564
+ "aria-label": "选择模型",
565
+ onKeyDown: onMenuKeyDown,
527
566
  },
528
- role: "dialog",
529
- "aria-label": "选择模型",
530
- onKeyDown: (ev) => { if (ev.key === "Escape") { ev.preventDefault(); ev.stopPropagation(); closeMenu(); } },
531
- },
532
- React.createElement("div", { className: "mdsl-header" },
533
- React.createElement("div", { className: "mdsl-search-wrap" },
534
- searchIcon(),
535
- React.createElement("input", {
536
- ref: searchRef,
537
- className: "mdsl-search",
538
- "aria-label": "搜索模型",
539
- placeholder: "搜索模型、描述或提供商…",
540
- value: query,
541
- onChange: (ev) => setQuery(ev.target.value),
542
- }),
543
- query !== "" ? React.createElement("button", { type: "button", className: "mdsl-search-clear", "aria-label": "清除搜索", onClick: () => setQuery("") }, closeIcon()) : null,
544
- ),
545
- q === "" && tagList.length > 0 ? React.createElement("div", { className: "mdsl-tags", ref: tagRailRef },
546
- tagList.map((tag) => React.createElement("button", {
547
- key: tag.id,
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", {
548
582
  type: "button",
549
- className: "mdsl-tag" + (tag.isCurrent ? " mdsl-tag-current" : ""),
550
- "data-current": tag.isCurrent ? "true" : undefined,
551
- title: "跳转至 " + tag.name,
552
- onClick: () => scrollToGroup(tag.id),
553
- },
554
- tag.id === FAVS_KEY ? React.createElement("span", { className: "mdsl-tag-icon" }, star(tag.isCurrent)) : null,
555
- React.createElement("span", { className: "mdsl-tag-name" }, tag.name),
556
- )),
557
- ) : null,
558
- ),
559
- data.status === "error" ? React.createElement("div", { className: "mdsl-error" }, data.error || "加载失败") : null,
560
- data.failures && data.failures.length ? React.createElement("div", { className: "mdsl-error" }, data.failures.map((f) => f.name + ": " + f.message).join(";")) : null,
561
- React.createElement("div", { className: "mdsl-body", ref: bodyRef, role: "group", "aria-label": "模型列表" },
562
- data.status === "loading" ? React.createElement("div", { className: "mdsl-empty" }, "加载中…") : null,
563
- data.status === "ready" && allChoices.length === 0 ? React.createElement("div", { className: "mdsl-empty" }, "暂无可用模型") : null,
564
- noMatch ? React.createElement("div", { className: "mdsl-empty" },
565
- "没有匹配的模型",
566
- React.createElement("div", { className: "mdsl-empty-sub" }, "换个关键词试试"),
567
- ) : null,
568
- favs.length ? React.createElement("div", {
569
- className: "mdsl-group" + (favsCollapsed ? " mdsl-group-collapsed" : ""),
570
- key: FAVS_KEY,
571
- "data-group-id": FAVS_KEY,
572
- role: "group",
573
- "aria-label": "收藏",
574
- },
575
- groupTitle(FAVS_KEY, "收藏", favs.length, favsCollapsed, q === "", star(true)),
576
- favsCollapsed ? null : favs.map(renderRow),
577
- ) : null,
578
- (data.groups || []).map(renderGroup),
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,
579
592
  ),
580
- React.createElement("div", { className: "mdsl-footer" },
581
- React.createElement("span", { className: "mdsl-footer-dot" }),
582
- React.createElement("span", { className: "mdsl-footer-current" }, current
583
- ? (modelName + (currentEffortText ? " · " + currentEffortText : ""))
584
- : "未选择模型"),
585
- React.createElement("span", { className: "mdsl-footer-hint" }, "Esc"),
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
+ )),
586
617
  ),
587
618
  ) : null,
588
619
  );