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