dsh-model-select-plus 0.1.7 → 0.2.1

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,22 @@
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 420 x 440: the native menu ceiling, and the width a name plus its
14
+ * levels need on one line; shipped menu material, 16px radius
15
+ * - one 34px search line with a 0.5px rule; no jump rail, no chips
16
+ * - rows at the native 34px height: name, inline effort chips, star, check.
17
+ * A level chip commits model + level in one click; the name commits the
18
+ * provider default, which is the chip drawn in the weight-only state
19
+ * - selection is a 6% fill plus the trailing check; only the current row
20
+ * expands, and only for its two-line description
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
+ * - the trigger shows provider/model (the provider ellipsizes first); the
26
+ * effort level lives in the tooltip and on the row chips
27
+ * - re-opening centers the current model instead of resetting to the top
25
28
  *
26
29
  * Data comes from the Host half at `/plugins/dsh-model-select-plus/api`.
27
30
  * The seat passes `locked` (owner prop) and we inject `sessionId`.
@@ -36,103 +39,92 @@ const API = "/plugins/dsh-model-select-plus/api";
36
39
  const STYLE_TAG = "dsh-model-select-plus/style";
37
40
  const FAVS_KEY = "__favorites__";
38
41
 
42
+ const h = React.createElement;
43
+
39
44
  const CSS = `
40
45
  .mdsl-root, .mdsl-root *, .mdsl-root *::before, .mdsl-root *::after { box-sizing: border-box; }
41
46
  .mdsl-root { position: relative; display: inline-flex; align-items: center; min-width: 0; max-width: 100%; }
42
47
  .mdsl-backdrop { position: fixed; inset: 0; z-index: 35; }
43
48
 
44
- /* Trigger: same 28px chip as the composer's sibling permission / plan
49
+ /* Trigger: the composer's 28px chip, same as the sibling permission / plan
45
50
  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; }
51
+ .mdsl-trigger { display: flex; align-items: center; gap: 4px; min-width: 0; max-width: 260px; max-width: min(260px, 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
52
  .mdsl-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
48
53
  .mdsl-trigger:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
49
54
  .mdsl-trigger:disabled { color: var(--dsw-alias-label-dimmed); cursor: default; }
50
- .mdsl-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
51
- /* The effort absorbs the deficit first: it ellipsizes to nothing before the
52
- model name loses a pixel, and the chevron stays snug. */
55
+ .mdsl-label { flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
56
+ /* The provider is context, the model is the subject: on overflow the level
57
+ collapses first, then the provider, and the model name stays whole. */
58
+ .mdsl-trigger-provider { flex-shrink: 100; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-tertiary); }
53
59
  .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; }
60
+ .mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); }
55
61
  .mdsl-chevron-open { transform: rotate(180deg); }
56
62
 
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; }
63
+ /* Card: the shipped menu material. 420px is the native menu ceiling; the
64
+ extra width is what keeps names whole once every row carries its levels. */
65
+ .mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width: 420px; 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
66
  body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
61
67
  @keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
62
68
  @media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
63
69
 
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; }
70
+ /* One search line with a 0.5px rule. No jump rail: 18 models are cheap to
71
+ scroll, and the second navigation layer only repeated the headings. */
72
+ .mdsl-search-wrap { position: relative; flex: none; display: flex; align-items: center; height: 34px; border-bottom: 0.5px solid var(--dsw-alias-border-l1); }
73
+ .mdsl-search-wrap:focus-within { border-bottom-color: var(--dsw-alias-state-business-primary); }
74
+ .mdsl-search-icon { position: absolute; left: 8px; display: flex; color: var(--dsw-alias-label-tertiary); pointer-events: none; }
75
+ .mdsl-search-wrap:focus-within .mdsl-search-icon { color: var(--dsw-alias-label-primary); }
76
+ .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; }
77
+ .mdsl-search::placeholder { color: var(--dsw-alias-label-caption); }
78
+ .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
79
  .mdsl-search-clear:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
75
80
  .mdsl-search-clear:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
76
81
 
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
82
  .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
83
  .mdsl-body::-webkit-scrollbar { width: 8px; }
90
84
  .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
85
  .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
86
 
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); }
87
+ /* Sections: 10px of air between groups; a 22px heading that paints its
88
+ header fill only while stuck to the top, so static groups stay flat
89
+ instead of drawing a grey band each. */
90
+ .mdsl-group { position: relative; }
91
+ .mdsl-group + .mdsl-group { margin-top: 10px; }
92
+ .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; }
93
+ .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); }
94
+ .mdsl-group-icon { display: inline-flex; color: var(--dsw-alias-brand-primary); }
104
95
  .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
96
 
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); }
97
+ /* Row: 34px, the native menu row height. Selection is a 6% fill plus the
98
+ trailing check; the 10% block read as a disabled row. */
99
+ .mdsl-item { border-radius: var(--dsw-radius-md, 12px); }
100
+ .mdsl-item:hover, .mdsl-item-current { background: var(--dsw-alias-interactive-bg-hover); }
101
+ .mdsl-row { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 8px; border-radius: var(--dsw-radius-md, 12px); cursor: pointer; }
110
102
  .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; }
103
+ .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; }
104
+ .mdsl-item-current .mdsl-name { font-weight: 500; }
105
+ .mdsl-prov { flex: none; color: var(--dsw-alias-label-caption); font-size: 11px; line-height: 16px; }
106
+ .mdsl-check { flex: none; display: inline-flex; color: var(--dsw-alias-label-primary); }
107
+ .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; }
108
+ .mdsl-item:hover .mdsl-star, .mdsl-star-on, .mdsl-star:focus-visible { opacity: 1; }
112
109
  .mdsl-star:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
113
110
  .mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
114
111
  .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); }
112
+
113
+ /* Effort lives on the row: one click commits model + level. The provider
114
+ default is the weight-only chip; the current row's pinned level gets a
115
+ fill as well. Only the description still expands under the current row. */
116
+ .mdsl-chips { display: flex; align-items: center; gap: 2px; flex: none; }
117
+ .mdsl-chip { height: 20px; padding: 0 5px; border: 0; border-radius: 4px; background: transparent; color: var(--dsw-alias-label-tertiary); font-family: inherit; font-size: 11px; line-height: 20px; cursor: pointer; }
118
+ .mdsl-chip:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
123
119
  .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; }
120
+ .mdsl-chip-eff { color: var(--dsw-alias-label-secondary); font-weight: 500; }
121
+ .mdsl-chip-on { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); font-weight: 500; }
122
+
123
+ .mdsl-sub { padding: 2px 8px 8px; }
124
+ .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; }
125
+
126
+ .mdsl-empty { padding: 16px 8px; text-align: center; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
127
+ .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
128
  `;
137
129
 
138
130
  function injectStyle() {
@@ -145,67 +137,58 @@ function injectStyle() {
145
137
  return () => { tag.remove(); };
146
138
  }
147
139
 
148
- const star = (filled) => React.createElement(
140
+ const star = (filled) => h(
149
141
  "svg",
150
142
  { 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" }),
143
+ 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
144
  );
153
145
 
154
- const chevron = () => React.createElement(
146
+ const check = () => h(
155
147
  "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" }),
148
+ { width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
149
+ h("path", { d: "M2.8 7.4l2.6 2.6 5.8-6.4", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" }),
158
150
  );
159
151
 
160
- const chevronDown = () => React.createElement(
152
+ const chevronDown = () => h(
161
153
  "svg",
162
154
  { 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" }),
155
+ h("path", { d: "M3 4.75L6 7.75l3-3", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round" }),
170
156
  );
171
157
 
172
- const closeIcon = () => React.createElement(
158
+ const closeIcon = () => h(
173
159
  "svg",
174
160
  { 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" }),
161
+ h("path", { d: "M3 3l6 6M9 3L3 9", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" }),
176
162
  );
177
163
 
178
- const searchIcon = () => React.createElement(
164
+ const searchIcon = () => h(
179
165
  "span",
180
166
  { className: "mdsl-search-icon" },
181
- React.createElement(
167
+ h(
182
168
  "svg",
183
169
  { 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" }),
170
+ h("circle", { cx: 7, cy: 7, r: 5, stroke: "currentColor", strokeWidth: 1.4 }),
171
+ h("line", { x1: 10.8, y1: 10.8, x2: 14, y2: 14, stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" }),
186
172
  ),
187
173
  );
188
174
 
189
175
  function ModelSelectLite(props) {
190
176
  const sessionId = props.sessionId;
191
177
  const locked = props.locked === true;
192
- const bodyRef = React.useRef(null);
193
178
  const triggerRef = React.useRef(null);
179
+ const bodyRef = React.useRef(null);
194
180
  const searchRef = React.useRef(null);
195
- const tagRailRef = React.useRef(null);
196
181
  const [placement, setPlacement] = React.useState(null);
197
182
  const [open, setOpen] = React.useState(false);
198
183
  const [data, setData] = React.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
199
184
  const [query, setQuery] = React.useState("");
200
185
  const [busy, setBusy] = React.useState(false);
201
186
  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
187
 
207
188
  const load = () => {
208
- setData((d) => ({ ...d, status: "loading", error: null }));
189
+ // Keep the previous rows on screen while a re-open refreshes the catalog;
190
+ // only a cold load shows the loading state (no flash on every open).
191
+ setData((d) => (d.groups.length > 0 ? { ...d, error: null } : { ...d, status: "loading", error: null }));
209
192
  const url = `${API}/catalog?sessionId=${encodeURIComponent(sessionId)}`;
210
193
  fetch(url)
211
194
  .then((res) => res.json())
@@ -224,56 +207,61 @@ function ModelSelectLite(props) {
224
207
  // Load on mount (and when the session changes) so the trigger shows the
225
208
  // current model immediately instead of the "选择模型" placeholder.
226
209
  React.useEffect(() => {
227
- if (sessionId !== undefined) {
228
- setUserToggled(new Map());
229
- load();
230
- }
210
+ if (sessionId !== undefined) load();
231
211
  }, [sessionId]);
232
212
 
233
213
  // Opening the menu focuses the search field: typing filters immediately and
234
- // Escape lands on the menu's key handler for free.
214
+ // Escape lands on the menu's key handler for free. Focus lands once per open
215
+ // — a resize or page scroll that re-places the card must not pull the caret
216
+ // back out of the row the keyboard is on.
217
+ const focusedForOpen = React.useRef(false);
235
218
  React.useEffect(() => {
236
- if (!open || placement === null) return;
219
+ if (!open) {
220
+ focusedForOpen.current = false;
221
+ return;
222
+ }
223
+ if (placement === null || focusedForOpen.current) return;
224
+ focusedForOpen.current = true;
237
225
  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
226
  if (el) el.focus({ preventScroll: true });
242
227
  }, [open, placement]);
243
228
 
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
229
  // Measure the room around the trigger before painting: open upward while it
256
230
  // 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.
231
+ // and cap the card height so the scrolling body always keeps its last row.
258
232
  const placeMenu = () => {
259
233
  const trigger = triggerRef.current;
260
234
  if (!trigger) return;
261
235
  const rect = trigger.getBoundingClientRect();
262
236
  const margin = 12;
263
237
  const gap = 6;
264
- const width = Math.min(384, window.innerWidth - margin * 2);
238
+ const width = Math.min(420, window.innerWidth - margin * 2);
265
239
  const spaceAbove = rect.top - gap - margin;
266
240
  const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
267
241
  const side = spaceAbove >= spaceBelow ? "top" : "bottom";
268
- const maxHeight = Math.max(160, Math.min(480, side === "top" ? spaceAbove : spaceBelow));
242
+ const maxHeight = Math.max(180, Math.min(440, side === "top" ? spaceAbove : spaceBelow));
269
243
  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,
244
+ // Keep the placement object stable when nothing moved: every identity change
245
+ // would re-run the sticky sync and could steal focus back to the search.
246
+ setPlacement((prev) => {
247
+ const next = {
248
+ side,
249
+ maxHeight,
250
+ width,
251
+ left,
252
+ bottom: window.innerHeight - rect.top + gap,
253
+ top: rect.bottom + gap,
254
+ };
255
+ if (
256
+ prev !== null
257
+ && prev.side === next.side
258
+ && prev.maxHeight === next.maxHeight
259
+ && prev.width === next.width
260
+ && prev.left === next.left
261
+ && prev.bottom === next.bottom
262
+ && prev.top === next.top
263
+ ) return prev;
264
+ return next;
277
265
  });
278
266
  };
279
267
 
@@ -283,7 +271,12 @@ function ModelSelectLite(props) {
283
271
 
284
272
  React.useEffect(() => {
285
273
  if (!open) return;
286
- const reposition = () => placeMenu();
274
+ const reposition = (ev) => {
275
+ // Scrolling the menu's own body must not re-anchor the card.
276
+ const body = bodyRef.current;
277
+ if (ev && ev.target instanceof Node && body !== null && body.contains(ev.target)) return;
278
+ placeMenu();
279
+ };
287
280
  window.addEventListener("resize", reposition);
288
281
  window.addEventListener("scroll", reposition, true);
289
282
  return () => {
@@ -292,6 +285,52 @@ function ModelSelectLite(props) {
292
285
  };
293
286
  }, [open]);
294
287
 
288
+ // Sticky headings paint their fill only while pinned to the top edge of the
289
+ // scrolling body; a heading that merely sits at the top of its group stays
290
+ // flat. rAF-throttled because the body scrolls at pointer speed.
291
+ React.useEffect(() => {
292
+ if (!open) return;
293
+ const body = bodyRef.current;
294
+ if (!body) return;
295
+ let raf = 0;
296
+ const sync = () => {
297
+ raf = 0;
298
+ const top = body.getBoundingClientRect().top;
299
+ const heads = body.querySelectorAll(".mdsl-group-title");
300
+ for (const head of heads) {
301
+ if (head.getBoundingClientRect().top <= top + 1) head.setAttribute("data-stuck", "");
302
+ else head.removeAttribute("data-stuck");
303
+ }
304
+ };
305
+ const schedule = () => { if (!raf) raf = requestAnimationFrame(sync); };
306
+ body.addEventListener("scroll", schedule, { passive: true });
307
+ window.addEventListener("resize", schedule);
308
+ schedule();
309
+ return () => {
310
+ body.removeEventListener("scroll", schedule);
311
+ window.removeEventListener("resize", schedule);
312
+ if (raf) cancelAnimationFrame(raf);
313
+ };
314
+ }, [open, placement, data.status, data.current, query]);
315
+
316
+ // Re-opening lands on the current model instead of the top of the list.
317
+ // useLayoutEffect so the jump happens before the card is painted.
318
+ const locatedForOpen = React.useRef(false);
319
+ React.useLayoutEffect(() => {
320
+ if (!open) { locatedForOpen.current = false; return; }
321
+ if (locatedForOpen.current || placement === null) return;
322
+ if (data.status !== "ready" || query !== "") return;
323
+ const body = bodyRef.current;
324
+ if (!body) return;
325
+ const item = body.querySelector('[data-current="true"]');
326
+ if (item === null) { locatedForOpen.current = true; return; }
327
+ const bodyRect = body.getBoundingClientRect();
328
+ const itemRect = item.getBoundingClientRect();
329
+ const delta = itemRect.top - bodyRect.top - (body.clientHeight - itemRect.height) / 2;
330
+ body.scrollTop = Math.max(0, body.scrollTop + delta);
331
+ locatedForOpen.current = true;
332
+ }, [open, placement, data.status, query]);
333
+
295
334
  const focusTrigger = () => {
296
335
  const el = triggerRef.current;
297
336
  if (el) el.focus({ preventScroll: true });
@@ -304,7 +343,7 @@ function ModelSelectLite(props) {
304
343
  focusTrigger();
305
344
  };
306
345
 
307
- const selectSelection = (sel) => {
346
+ const selectSelection = (sel, keepOpen) => {
308
347
  if (busy) return;
309
348
  setBusy(true);
310
349
  fetch(`${API}/select`, {
@@ -321,8 +360,8 @@ function ModelSelectLite(props) {
321
360
  .then((res) => {
322
361
  setBusy(false);
323
362
  if (res && res.ok === true) {
324
- setData((d) => ({ ...d, current: res.selected, error: null }));
325
- setUserToggled(new Map());
363
+ setData((d) => ({ ...d, current: res.selected || null, error: null }));
364
+ if (keepOpen) return;
326
365
  closeMenu();
327
366
  } else {
328
367
  setData((d) => ({ ...d, error: (res && res.message) || "选择失败" }));
@@ -334,255 +373,274 @@ function ModelSelectLite(props) {
334
373
  });
335
374
  };
336
375
 
337
- const toggleFav = (g, m, ev) => {
338
- if (ev && ev.stopPropagation) ev.stopPropagation();
339
- const key = `${g}/${m}`;
376
+ const toggleFav = (gid, mid) => {
377
+ const key = `${gid}/${mid}`;
340
378
  const next = new Set(favorites);
341
379
  if (next.has(key)) next.delete(key); else next.add(key);
342
380
  favorites = next;
343
381
  bump((x) => x + 1);
344
382
  };
345
383
 
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;
384
+ const choose = (g, m) => {
385
+ const effort = m.reasoning ? m.reasoning.defaultEffort : undefined;
386
+ selectSelection({ provider: g.id, model: m.id, ...(effort === undefined ? {} : { reasoningEffort: effort }) }, false);
354
387
  };
355
388
 
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
- });
363
- };
364
-
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);
389
+ const chooseEffort = (g, m, effort) => {
390
+ // Changing the level of the model already in use keeps the card open so
391
+ // the user can compare levels; picking a level on another model commits
392
+ // model + level in one click and closes.
393
+ const sameModel = current !== null && current !== undefined
394
+ && current.provider === g.id && current.model === m.id;
395
+ selectSelection({ provider: g.id, model: m.id, ...(effort === undefined ? {} : { reasoningEffort: effort }) }, sameModel);
387
396
  };
388
397
 
389
398
  const current = data.current;
390
399
  const curGroup = current ? data.groups.find((g) => g.id === current.provider) : undefined;
391
400
  const curModel = curGroup ? curGroup.models.find((mm) => mm.id === current.model) : undefined;
392
- // trigger 按钮显示“供应商/模型”,供应商取组的显示名,找不到组时回退 provider id。
393
401
  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
- }
402
+ const modelName = (curModel && curModel.name) || (current ? current.model : "");
403
+ const pinnedEffort = current ? current.reasoningEffort : undefined;
404
+
405
+ // Trigger effort: the pinned level, else the provider default, else "默认".
406
+ let effortLabel;
407
+ if (curModel && curModel.reasoning) {
408
+ const shown = pinnedEffort !== undefined ? pinnedEffort : curModel.reasoning.defaultEffort;
409
+ if (shown !== undefined) {
410
+ const hit = (curModel.reasoning.efforts || []).find((e) => e.id === shown);
411
+ effortLabel = hit ? hit.name : shown;
412
+ } else {
413
+ effortLabel = "默认";
408
414
  }
409
415
  }
410
416
 
411
417
  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
- }
418
+ const matches = (g, m) => q === "" || (m.name + " " + (m.description || "") + " " + g.name).toLowerCase().includes(q);
419
+
420
+ let total = 0;
421
+ const favEntries = [];
422
+ const filteredGroups = [];
423
+ for (const g of data.groups || []) {
424
+ const models = [];
425
+ for (const m of g.models || []) {
426
+ total += 1;
427
+ if (!matches(g, m)) continue;
428
+ // Favorites move to the pinned top group instead of rendering twice.
429
+ if (favorites.has(`${g.id}/${m.id}`)) favEntries.push({ g, m });
430
+ else models.push(m);
428
431
  }
432
+ if (models.length > 0) filteredGroups.push({ id: g.id, name: g.name, models });
429
433
  }
434
+ const noMatch = data.status === "ready" && q !== "" && filteredGroups.length === 0 && favEntries.length === 0;
430
435
 
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(
436
+ const isCurrentModel = (g, m) => current !== null && current !== undefined && current.provider === g.id && current.model === m.id;
437
+
438
+ const heading = (label, icon) => h(
434
439
  "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),
440
+ { className: "mdsl-group-title" },
441
+ icon ? h("span", { className: "mdsl-group-icon" }, icon) : null,
442
+ h("span", { className: "mdsl-group-name" }, label),
448
443
  );
449
444
 
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,
445
+ const renderRow = (g, m, showProvider) => {
446
+ const selected = isCurrentModel(g, m);
447
+ const fav = favorites.has(`${g.id}/${m.id}`);
448
+ const hasEfforts = !!(m.reasoning && m.reasoning.efforts && m.reasoning.efforts.length);
449
+ const desc = typeof m.description === "string" && m.description !== "" ? m.description : undefined;
450
+ // The level a click would commit: the pinned one on the current row, the
451
+ // provider default on every other row.
452
+ const rowEffort = selected ? pinnedEffort : (m.reasoning ? m.reasoning.defaultEffort : undefined);
453
+ const stop = (ev) => { if (ev.key === "Enter" || ev.key === " ") ev.stopPropagation(); };
454
+ const row = h(
455
+ "div",
456
+ {
457
+ className: "mdsl-row",
458
+ role: "button",
459
+ tabIndex: 0,
460
+ "aria-pressed": selected,
461
+ title: desc,
462
+ onClick: () => choose(g, m),
463
+ onKeyDown: (ev) => {
464
+ if (ev.key === "Enter" || ev.key === " ") {
465
+ ev.preventDefault();
466
+ choose(g, m);
467
+ }
468
+ },
469
+ },
470
+ h("span", { className: "mdsl-name" }, m.name),
471
+ showProvider ? h("span", { className: "mdsl-prov" }, g.name) : null,
472
+ hasEfforts
473
+ ? h(
474
+ "span",
475
+ { className: "mdsl-chips", role: "group", "aria-label": "推理等级" },
476
+ m.reasoning.efforts.map((e) => h(
477
+ "button",
478
+ {
479
+ key: e.id,
480
+ type: "button",
481
+ title: e.description || e.name,
482
+ "aria-pressed": rowEffort === e.id,
483
+ className: "mdsl-chip" + (rowEffort === e.id ? (selected ? " mdsl-chip-on" : " mdsl-chip-eff") : ""),
484
+ onClick: (ev) => {
485
+ ev.stopPropagation();
486
+ chooseEffort(g, m, e.id);
487
+ },
488
+ // A real button fires click on Enter/Space; keep the row's own
489
+ // keyboard handler out of the way so the level wins.
490
+ onKeyDown: stop,
491
+ },
492
+ e.name,
493
+ )),
494
+ )
495
+ : null,
496
+ h(
497
+ "button",
498
+ {
499
+ type: "button",
500
+ className: "mdsl-star" + (fav ? " mdsl-star-on" : ""),
501
+ "aria-label": fav ? "取消收藏" : "收藏",
502
+ "aria-pressed": fav,
503
+ onClick: (ev) => {
504
+ ev.stopPropagation();
505
+ toggleFav(g.id, m.id);
506
+ },
507
+ onKeyDown: stop,
508
+ },
509
+ star(fav),
479
510
  ),
511
+ selected ? h("span", { className: "mdsl-check" }, check()) : null,
480
512
  );
481
- };
482
513
 
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),
514
+ const sub = selected && desc !== undefined
515
+ ? h("div", { className: "mdsl-sub" }, h("div", { className: "mdsl-desc" }, desc))
516
+ : null;
517
+
518
+ return h(
519
+ "div",
520
+ {
521
+ key: `${g.id}/${m.id}`,
522
+ className: "mdsl-item" + (selected ? " mdsl-item-current" : ""),
523
+ "data-current": selected ? "true" : undefined,
524
+ },
525
+ row,
526
+ sub,
494
527
  );
495
528
  };
496
529
 
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()),
530
+ const onMenuKeyDown = (ev) => {
531
+ if (ev.key === "Escape") {
532
+ ev.preventDefault();
533
+ ev.stopPropagation();
534
+ closeMenu();
535
+ return;
536
+ }
537
+ if (ev.key !== "ArrowDown" && ev.key !== "ArrowUp") return;
538
+ const body = bodyRef.current;
539
+ if (!body) return;
540
+ const rows = Array.from(body.querySelectorAll(".mdsl-row"));
541
+ if (rows.length === 0) return;
542
+ ev.preventDefault();
543
+ const at = rows.indexOf(document.activeElement);
544
+ const step = ev.key === "ArrowDown" ? 1 : -1;
545
+ const next = at === -1
546
+ ? (step > 0 ? 0 : rows.length - 1)
547
+ : (at + step + rows.length) % rows.length;
548
+ rows[next].focus();
549
+ };
550
+
551
+ const triggerTitle = current
552
+ ? (providerName ? providerName + " / " + modelName : modelName) + (effortLabel ? " / " + effortLabel : "")
553
+ : "选择模型";
554
+
555
+ return h(
556
+ "div",
557
+ { className: "mdsl-root" },
558
+ h(
559
+ "button",
560
+ {
561
+ ref: triggerRef,
562
+ type: "button",
563
+ className: "mdsl-trigger",
564
+ onClick: () => { if (open) closeMenu(); else openMenu(); },
565
+ disabled: locked,
566
+ title: triggerTitle,
567
+ "aria-haspopup": "dialog",
568
+ "aria-expanded": open,
569
+ },
570
+ current && providerName ? h("span", { className: "mdsl-trigger-provider" }, providerName + "/") : null,
571
+ h("span", { className: "mdsl-label" }, current ? modelName : "选择模型"),
572
+ effortLabel ? h("span", { className: "mdsl-effort" }, effortLabel) : null,
573
+ h("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown()),
514
574
  ),
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",
575
+ open ? h("div", { className: "mdsl-backdrop", onClick: closeMenu }) : null,
576
+ open && placement !== null ? h(
577
+ "div",
578
+ {
579
+ className: "mdsl-menu",
580
+ style: {
581
+ left: placement.left + "px",
582
+ width: placement.width + "px",
583
+ maxWidth: placement.width + "px",
584
+ maxHeight: placement.maxHeight + "px",
585
+ ...(placement.side === "top"
586
+ ? { top: "auto", bottom: placement.bottom + "px" }
587
+ : { top: placement.top + "px", bottom: "auto" }),
588
+ transformOrigin: placement.side === "top" ? "bottom right" : "top right",
589
+ },
590
+ role: "dialog",
591
+ "aria-label": "选择模型",
592
+ onKeyDown: onMenuKeyDown,
527
593
  },
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,
594
+ h(
595
+ "div",
596
+ { className: "mdsl-search-wrap" },
597
+ searchIcon(),
598
+ h("input", {
599
+ ref: searchRef,
600
+ className: "mdsl-search",
601
+ type: "text",
602
+ "aria-label": "搜索模型",
603
+ placeholder: "搜索模型",
604
+ value: query,
605
+ onChange: (ev) => setQuery(ev.target.value),
606
+ }),
607
+ query !== ""
608
+ ? h("button", {
548
609
  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),
610
+ className: "mdsl-search-clear",
611
+ "aria-label": "清除搜索",
612
+ onClick: () => {
613
+ setQuery("");
614
+ const el = searchRef.current;
615
+ if (el) el.focus({ preventScroll: true });
616
+ },
617
+ }, closeIcon())
618
+ : null,
579
619
  ),
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"),
620
+ data.status === "error" ? h("div", { className: "mdsl-error" }, data.error || "加载失败") : null,
621
+ data.failures && data.failures.length
622
+ ? h("div", { className: "mdsl-error" }, data.failures.map((f) => f.name + ": " + f.message).join(";"))
623
+ : null,
624
+ h(
625
+ "div",
626
+ { className: "mdsl-body", ref: bodyRef, role: "group", "aria-label": "模型列表" },
627
+ data.status === "loading" ? h("div", { className: "mdsl-empty" }, "加载中…") : null,
628
+ data.status === "ready" && total === 0 ? h("div", { className: "mdsl-empty" }, "暂无可用模型") : null,
629
+ noMatch ? h("div", { className: "mdsl-empty" }, "没有匹配的模型") : null,
630
+ favEntries.length > 0
631
+ ? h(
632
+ "div",
633
+ { className: "mdsl-group", key: FAVS_KEY },
634
+ heading("收藏", star(true)),
635
+ favEntries.map(({ g, m }) => renderRow(g, m, true)),
636
+ )
637
+ : null,
638
+ filteredGroups.map((g) => h(
639
+ "div",
640
+ { className: "mdsl-group", key: g.id },
641
+ heading(g.name),
642
+ g.models.map((m) => renderRow(g, m, false)),
643
+ )),
586
644
  ),
587
645
  ) : null,
588
646
  );