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/README.md +11 -8
- package/lib/client.cjs +307 -322
- package/package.json +2 -2
- package/src/client.js +412 -354
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
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* -
|
|
16
|
-
* -
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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:
|
|
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:
|
|
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
|
|
52
|
-
|
|
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);
|
|
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
|
|
58
|
-
|
|
59
|
-
.mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width:
|
|
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
|
-
/*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
.mdsl-
|
|
68
|
-
.mdsl-search-
|
|
69
|
-
.mdsl-search-icon {
|
|
70
|
-
.mdsl-search { width: 100%; height:
|
|
71
|
-
.mdsl-search::placeholder { color: var(--dsw-alias-label-
|
|
72
|
-
.mdsl-search
|
|
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
|
-
/*
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
.mdsl-group {
|
|
97
|
-
.mdsl-group + .mdsl-group { margin-top:
|
|
98
|
-
.mdsl-group-title { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap:
|
|
99
|
-
.mdsl-group-title
|
|
100
|
-
.mdsl-group-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
.mdsl-
|
|
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-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
.mdsl-
|
|
120
|
-
.mdsl-
|
|
121
|
-
.mdsl-chip {
|
|
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-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
.mdsl-
|
|
128
|
-
.mdsl-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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) =>
|
|
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
|
-
|
|
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
|
|
146
|
+
const check = () => h(
|
|
155
147
|
"svg",
|
|
156
|
-
{ width:
|
|
157
|
-
|
|
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 = () =>
|
|
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
|
-
|
|
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 = () =>
|
|
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
|
-
|
|
161
|
+
h("path", { d: "M3 3l6 6M9 3L3 9", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" }),
|
|
176
162
|
);
|
|
177
163
|
|
|
178
|
-
const searchIcon = () =>
|
|
164
|
+
const searchIcon = () => h(
|
|
179
165
|
"span",
|
|
180
166
|
{ className: "mdsl-search-icon" },
|
|
181
|
-
|
|
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
|
-
|
|
185
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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(
|
|
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(
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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 = () =>
|
|
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
|
-
|
|
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 = (
|
|
338
|
-
|
|
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
|
|
347
|
-
|
|
348
|
-
|
|
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
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
-
|
|
432
|
-
|
|
433
|
-
const
|
|
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
|
-
|
|
437
|
-
|
|
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 = (
|
|
451
|
-
const
|
|
452
|
-
const
|
|
453
|
-
const
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
return
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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 ?
|
|
516
|
-
open && placement !== null ?
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
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
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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-
|
|
550
|
-
"
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
))
|
|
557
|
-
|
|
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
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
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
|
);
|