dsh-model-select-plus 0.1.6 → 0.1.7
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 +2 -2
- package/lib/client.cjs +239 -90
- package/package.json +5 -5
- package/src/client.js +261 -93
package/README.md
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
3. **搜索**:按模型名 / 描述 / provider 过滤,带放大镜图标与清除按钮。
|
|
10
10
|
4. **收藏置顶**:行首星标收藏,收藏项置顶为独立分组(插件生命周期内的浏览器内存保存)。
|
|
11
11
|
5. **分组折叠**:非当前模型选中组默认折叠,仅当前模型所在组默认展开;点击分组标题即可折叠 / 展开,行尾带数量指示;手动折叠状态在菜单开合间保留,切换模型后自动展开新组;搜索时自动展开全部,避免匹配项被隐藏。
|
|
12
|
-
6. **模型组快捷 Tag
|
|
12
|
+
6. **模型组快捷 Tag 导航**:搜索栏下方是单行横向滚动的模型组标签条(含“收藏”,星标图标),不再包裹成多行、也不再重复组内数量(数量只出现在分组标题右侧);当前模型所在组描边高亮并自动滚入视野;点击任意 Tag 只展开该组并折叠其余组,同时平滑滚动定位;输入搜索词时标签条自动收起,把高度让给结果。
|
|
13
13
|
7. **供应商/模型显示**:composer 触发按钮显示当前选择为 `供应商/模型` 格式,供应商取组显示名(缺失时回退 provider id)。
|
|
14
|
-
8.
|
|
14
|
+
8. **视觉与布局**:沿用 DSH 自带菜单/输入框的视觉语言——`--dsw-menu-surface-fill` + `--dsw-menu-backdrop-filter` 的半透明浮层、`--dsw-elevation-prominent` 描边投影、16px 卡片圆角、32px 搜索框;触发按钮对齐 composer 同排控件(13/20、28px 高、长名称省略),面板宽 384px。分组标题滚动时吸顶(不透明填充,行不会透出),底部常驻条显示当前模型 + `Esc` 提示。打开时按触发按钮在视口内的剩余空间决定向上/向下弹、收敛高度并把左右夹在视口内(短窗口不再被 composer 的滚动容器裁掉顶部),搜索框自动聚焦、`Esc` 关闭并把焦点还给触发按钮。浅/深色均走主题令牌;所有图标为手绘 SVG,不用文字字符充当图标。
|
|
15
15
|
|
|
16
16
|
## 安装
|
|
17
17
|
|
package/lib/client.cjs
CHANGED
|
@@ -47,70 +47,102 @@ var module = { exports: {} };
|
|
|
47
47
|
var STYLE_TAG = "dsh-model-select-plus/style";
|
|
48
48
|
var FAVS_KEY = "__favorites__";
|
|
49
49
|
var CSS = `
|
|
50
|
-
.mdsl-root {
|
|
50
|
+
.mdsl-root, .mdsl-root *, .mdsl-root *::before, .mdsl-root *::after { box-sizing: border-box; }
|
|
51
|
+
.mdsl-root { position: relative; display: inline-flex; align-items: center; min-width: 0; max-width: 100%; }
|
|
51
52
|
.mdsl-backdrop { position: fixed; inset: 0; z-index: 35; }
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
.mdsl-trigger:
|
|
56
|
-
.mdsl-trigger:disabled {
|
|
57
|
-
.mdsl-
|
|
58
|
-
.mdsl-
|
|
59
|
-
.mdsl-
|
|
60
|
-
|
|
53
|
+
|
|
54
|
+
/* Trigger: same 28px chip as the composer's sibling permission / plan
|
|
55
|
+
controls, so the row does not jump when this plugin replaces the seat. */
|
|
56
|
+
.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; }
|
|
57
|
+
.mdsl-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
58
|
+
.mdsl-trigger:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
|
|
59
|
+
.mdsl-trigger:disabled { color: var(--dsw-alias-label-dimmed); cursor: default; }
|
|
60
|
+
.mdsl-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
61
|
+
/* The effort absorbs the deficit first: it ellipsizes to nothing before the
|
|
62
|
+
model name loses a pixel, and the chevron stays snug. */
|
|
63
|
+
.mdsl-effort { flex-shrink: 1000; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-caption); }
|
|
64
|
+
.mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); transition: transform .12s ease; }
|
|
61
65
|
.mdsl-chevron-open { transform: rotate(180deg); }
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.mdsl-
|
|
66
|
-
.mdsl-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
|
|
67
|
+
/* Card: the shipped menu material (translucent fill + blur + prominent
|
|
68
|
+
elevation stroke) so every DSH dropdown reads the same. */
|
|
69
|
+
.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; }
|
|
70
|
+
body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
|
|
71
|
+
@keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
|
|
72
|
+
@media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
|
|
73
|
+
|
|
74
|
+
/* Header: one search field + one jump rail. Everything else belongs to the
|
|
75
|
+
scrolling body, so the fixed chrome stays ~74px instead of a wrapped tag
|
|
76
|
+
wall that ate a third of the card. */
|
|
77
|
+
.mdsl-header { flex: none; display: flex; flex-direction: column; gap: 6px; padding: 4px 4px 6px; }
|
|
69
78
|
.mdsl-search-wrap { position: relative; display: flex; align-items: center; }
|
|
70
|
-
.mdsl-search-icon { position: absolute; left: 9px; color: var(--dsw-alias-label-tertiary);
|
|
71
|
-
.mdsl-search { width: 100%;
|
|
79
|
+
.mdsl-search-icon { position: absolute; left: 9px; display: flex; color: var(--dsw-alias-label-tertiary); pointer-events: none; }
|
|
80
|
+
.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; }
|
|
72
81
|
.mdsl-search::placeholder { color: var(--dsw-alias-label-tertiary); }
|
|
73
|
-
.mdsl-search:focus { border-color: var(--dsw-alias-
|
|
74
|
-
.mdsl-search-clear { position: absolute; right:
|
|
75
|
-
.mdsl-search-clear:hover { background: var(--dsw-alias-interactive-bg-
|
|
76
|
-
.mdsl-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.mdsl-
|
|
81
|
-
.mdsl-
|
|
82
|
-
.mdsl-tag
|
|
83
|
-
.mdsl-
|
|
84
|
-
.mdsl-
|
|
85
|
-
.mdsl-
|
|
86
|
-
.mdsl-
|
|
87
|
-
.mdsl-
|
|
88
|
-
|
|
89
|
-
.mdsl-
|
|
90
|
-
.mdsl-
|
|
91
|
-
.mdsl-
|
|
82
|
+
.mdsl-search:focus { border-color: var(--dsw-alias-state-business-primary); }
|
|
83
|
+
.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; }
|
|
84
|
+
.mdsl-search-clear:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
|
|
85
|
+
.mdsl-search-clear:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
86
|
+
|
|
87
|
+
/* Provider jump rail: single row, horizontal scroll. Counts live on the
|
|
88
|
+
sticky group headings only \u2014 the old rail repeated them in parentheses. */
|
|
89
|
+
.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); }
|
|
90
|
+
.mdsl-tags::-webkit-scrollbar { display: none; }
|
|
91
|
+
.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; }
|
|
92
|
+
.mdsl-tag:hover { border-color: var(--dsw-alias-border-l2); background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
|
|
93
|
+
.mdsl-tag:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
94
|
+
.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; }
|
|
95
|
+
.mdsl-tag-icon { display: inline-flex; margin-left: -2px; color: var(--dsw-alias-brand-primary); }
|
|
96
|
+
.mdsl-tag-name { white-space: nowrap; }
|
|
97
|
+
|
|
98
|
+
.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; }
|
|
99
|
+
.mdsl-body::-webkit-scrollbar { width: 8px; }
|
|
100
|
+
.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; }
|
|
101
|
+
.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; }
|
|
102
|
+
|
|
103
|
+
/* Group headings stick while their rows scroll, painted with the shipped
|
|
104
|
+
menu-group fill so rows never bleed through. Normal case (text-transform:
|
|
105
|
+
uppercase mangles mixed CJK/Latin provider names). */
|
|
106
|
+
.mdsl-group { display: flex; flex-direction: column; gap: 1px; }
|
|
107
|
+
.mdsl-group + .mdsl-group { margin-top: 3px; }
|
|
108
|
+
.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; }
|
|
109
|
+
.mdsl-group-title:hover { color: var(--dsw-alias-label-secondary); }
|
|
110
|
+
.mdsl-group-title:focus-visible { outline: none; color: var(--dsw-alias-label-primary); }
|
|
92
111
|
.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; }
|
|
93
112
|
.mdsl-group-collapsed .mdsl-group-chevron { transform: none; }
|
|
94
|
-
.mdsl-group-
|
|
95
|
-
.mdsl-
|
|
113
|
+
.mdsl-group-icon { flex: none; display: inline-flex; color: var(--dsw-alias-brand-primary); }
|
|
114
|
+
.mdsl-group-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
115
|
+
.mdsl-group-count { flex: none; margin-left: auto; color: var(--dsw-alias-label-caption); font-variant-numeric: tabular-nums; }
|
|
116
|
+
|
|
117
|
+
.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; }
|
|
96
118
|
.mdsl-row:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
97
119
|
.mdsl-row-current, .mdsl-row-current:hover { background: var(--dsw-alias-interactive-bg-active); }
|
|
98
|
-
.mdsl-
|
|
99
|
-
.mdsl-star
|
|
120
|
+
.mdsl-row:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
121
|
+
.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; }
|
|
122
|
+
.mdsl-star:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
|
|
123
|
+
.mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
100
124
|
.mdsl-star-on { color: var(--dsw-alias-brand-primary); }
|
|
101
125
|
.mdsl-row-main { flex: 1; min-width: 0; }
|
|
102
|
-
.mdsl-row-head { display: flex; align-items: center; gap: 6px; min-width: 0; min-height:
|
|
103
|
-
.mdsl-row-name {
|
|
104
|
-
.mdsl-check {
|
|
105
|
-
.mdsl-row-desc {
|
|
126
|
+
.mdsl-row-head { display: flex; align-items: center; gap: 6px; min-width: 0; min-height: 20px; }
|
|
127
|
+
.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; }
|
|
128
|
+
.mdsl-check { flex: none; display: inline-flex; margin-left: auto; color: var(--dsw-alias-brand-primary); }
|
|
129
|
+
.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; }
|
|
106
130
|
.mdsl-row-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
|
|
107
|
-
.mdsl-chip {
|
|
131
|
+
.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; }
|
|
108
132
|
.mdsl-chip:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
|
|
109
|
-
.mdsl-chip-
|
|
110
|
-
.mdsl-
|
|
111
|
-
|
|
112
|
-
.mdsl-
|
|
113
|
-
.mdsl-
|
|
133
|
+
.mdsl-chip:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
134
|
+
.mdsl-chip-on { border-color: var(--dsw-alias-brand-primary); background: transparent; color: var(--dsw-alias-label-primary); font-weight: 500; }
|
|
135
|
+
|
|
136
|
+
.mdsl-empty { padding: 18px 10px; text-align: center; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
|
|
137
|
+
.mdsl-empty-sub { margin-top: 2px; color: var(--dsw-alias-label-caption); font-size: 11px; line-height: 16px; }
|
|
138
|
+
.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; }
|
|
139
|
+
|
|
140
|
+
/* Pinned footer: repeats the current selection while the body is scrolled
|
|
141
|
+
into some other provider, plus the only keyboard shortcut worth naming. */
|
|
142
|
+
.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; }
|
|
143
|
+
.mdsl-footer-dot { flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--dsw-alias-brand-primary); }
|
|
144
|
+
.mdsl-footer-current { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-secondary); }
|
|
145
|
+
.mdsl-footer-hint { flex: none; color: var(--dsw-alias-label-caption); font-variant-numeric: tabular-nums; }
|
|
114
146
|
`;
|
|
115
147
|
function injectStyle() {
|
|
116
148
|
if (typeof document === "undefined") return () => {
|
|
@@ -127,20 +159,35 @@ var module = { exports: {} };
|
|
|
127
159
|
}
|
|
128
160
|
var star = (filled) => import_react.default.createElement(
|
|
129
161
|
"svg",
|
|
130
|
-
{ width: 14, height: 14, viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", xmlns: "http://www.w3.org/2000/svg" },
|
|
162
|
+
{ width: 14, height: 14, viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
|
|
131
163
|
import_react.default.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" })
|
|
132
164
|
);
|
|
133
165
|
var chevron = () => import_react.default.createElement(
|
|
134
166
|
"svg",
|
|
135
|
-
{ width:
|
|
136
|
-
import_react.default.createElement("path", { d: "
|
|
167
|
+
{ width: 10, height: 10, viewBox: "0 0 10 10", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
|
|
168
|
+
import_react.default.createElement("path", { d: "M3.5 2.5L6.5 5l-3 2.5", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round" })
|
|
169
|
+
);
|
|
170
|
+
var chevronDown = () => import_react.default.createElement(
|
|
171
|
+
"svg",
|
|
172
|
+
{ width: 12, height: 12, viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
|
|
173
|
+
import_react.default.createElement("path", { d: "M3 4.75L6 7.75l3-3", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round" })
|
|
174
|
+
);
|
|
175
|
+
var check = () => import_react.default.createElement(
|
|
176
|
+
"svg",
|
|
177
|
+
{ width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
|
|
178
|
+
import_react.default.createElement("path", { d: "M2.8 7.4l2.6 2.6 5.8-6.4", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round" })
|
|
179
|
+
);
|
|
180
|
+
var closeIcon = () => import_react.default.createElement(
|
|
181
|
+
"svg",
|
|
182
|
+
{ width: 12, height: 12, viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
|
|
183
|
+
import_react.default.createElement("path", { d: "M3 3l6 6M9 3L3 9", stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" })
|
|
137
184
|
);
|
|
138
185
|
var searchIcon = () => import_react.default.createElement(
|
|
139
186
|
"span",
|
|
140
187
|
{ className: "mdsl-search-icon" },
|
|
141
188
|
import_react.default.createElement(
|
|
142
189
|
"svg",
|
|
143
|
-
{ width:
|
|
190
|
+
{ width: 14, height: 14, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
|
|
144
191
|
import_react.default.createElement("circle", { cx: 7, cy: 7, r: 5, stroke: "currentColor", strokeWidth: 1.4 }),
|
|
145
192
|
import_react.default.createElement("line", { x1: 10.8, y1: 10.8, x2: 14, y2: 14, stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" })
|
|
146
193
|
)
|
|
@@ -149,6 +196,10 @@ var module = { exports: {} };
|
|
|
149
196
|
const sessionId = props.sessionId;
|
|
150
197
|
const locked = props.locked === true;
|
|
151
198
|
const bodyRef = import_react.default.useRef(null);
|
|
199
|
+
const triggerRef = import_react.default.useRef(null);
|
|
200
|
+
const searchRef = import_react.default.useRef(null);
|
|
201
|
+
const tagRailRef = import_react.default.useRef(null);
|
|
202
|
+
const [placement, setPlacement] = import_react.default.useState(null);
|
|
152
203
|
const [open, setOpen] = import_react.default.useState(false);
|
|
153
204
|
const [data, setData] = import_react.default.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
|
|
154
205
|
const [query, setQuery] = import_react.default.useState("");
|
|
@@ -174,6 +225,58 @@ var module = { exports: {} };
|
|
|
174
225
|
load();
|
|
175
226
|
}
|
|
176
227
|
}, [sessionId]);
|
|
228
|
+
import_react.default.useEffect(() => {
|
|
229
|
+
if (!open || placement === null) return;
|
|
230
|
+
const el = searchRef.current;
|
|
231
|
+
if (el) el.focus({ preventScroll: true });
|
|
232
|
+
}, [open, placement]);
|
|
233
|
+
import_react.default.useEffect(() => {
|
|
234
|
+
if (!open) return;
|
|
235
|
+
const rail = tagRailRef.current;
|
|
236
|
+
if (!rail) return;
|
|
237
|
+
const current2 = rail.querySelector('[data-current="true"]');
|
|
238
|
+
if (!current2) return;
|
|
239
|
+
const left = current2.offsetLeft - (rail.clientWidth - current2.offsetWidth) / 2;
|
|
240
|
+
rail.scrollTo({ left: Math.max(0, left), behavior: "smooth" });
|
|
241
|
+
}, [open, data.current, data.status]);
|
|
242
|
+
const placeMenu = () => {
|
|
243
|
+
const trigger = triggerRef.current;
|
|
244
|
+
if (!trigger) return;
|
|
245
|
+
const rect = trigger.getBoundingClientRect();
|
|
246
|
+
const margin = 12;
|
|
247
|
+
const gap = 6;
|
|
248
|
+
const width = Math.min(384, window.innerWidth - margin * 2);
|
|
249
|
+
const spaceAbove = rect.top - gap - margin;
|
|
250
|
+
const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
|
|
251
|
+
const side = spaceAbove >= spaceBelow ? "top" : "bottom";
|
|
252
|
+
const maxHeight = Math.max(160, Math.min(480, side === "top" ? spaceAbove : spaceBelow));
|
|
253
|
+
const left = Math.min(Math.max(margin, rect.right - width), window.innerWidth - width - margin);
|
|
254
|
+
setPlacement({
|
|
255
|
+
side,
|
|
256
|
+
maxHeight,
|
|
257
|
+
width,
|
|
258
|
+
left,
|
|
259
|
+
bottom: window.innerHeight - rect.top + gap,
|
|
260
|
+
top: rect.bottom + gap
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
import_react.default.useLayoutEffect(() => {
|
|
264
|
+
if (open) placeMenu();
|
|
265
|
+
}, [open]);
|
|
266
|
+
import_react.default.useEffect(() => {
|
|
267
|
+
if (!open) return;
|
|
268
|
+
const reposition = () => placeMenu();
|
|
269
|
+
window.addEventListener("resize", reposition);
|
|
270
|
+
window.addEventListener("scroll", reposition, true);
|
|
271
|
+
return () => {
|
|
272
|
+
window.removeEventListener("resize", reposition);
|
|
273
|
+
window.removeEventListener("scroll", reposition, true);
|
|
274
|
+
};
|
|
275
|
+
}, [open]);
|
|
276
|
+
const focusTrigger = () => {
|
|
277
|
+
const el = triggerRef.current;
|
|
278
|
+
if (el) el.focus({ preventScroll: true });
|
|
279
|
+
};
|
|
177
280
|
const openMenu = () => {
|
|
178
281
|
setOpen(true);
|
|
179
282
|
load();
|
|
@@ -181,6 +284,8 @@ var module = { exports: {} };
|
|
|
181
284
|
const closeMenu = () => {
|
|
182
285
|
setOpen(false);
|
|
183
286
|
setQuery("");
|
|
287
|
+
setPlacement(null);
|
|
288
|
+
focusTrigger();
|
|
184
289
|
};
|
|
185
290
|
const selectSelection = (sel) => {
|
|
186
291
|
if (busy) return;
|
|
@@ -250,7 +355,7 @@ var module = { exports: {} };
|
|
|
250
355
|
const bodyRect = bodyRef.current.getBoundingClientRect();
|
|
251
356
|
const elRect = el.getBoundingClientRect();
|
|
252
357
|
const targetScrollTop = bodyRef.current.scrollTop + (elRect.top - bodyRect.top);
|
|
253
|
-
bodyRef.current.scrollTo({ top: Math.max(0, targetScrollTop -
|
|
358
|
+
bodyRef.current.scrollTo({ top: Math.max(0, targetScrollTop - 2), behavior: "smooth" });
|
|
254
359
|
}
|
|
255
360
|
}, 40);
|
|
256
361
|
};
|
|
@@ -279,17 +384,17 @@ var module = { exports: {} };
|
|
|
279
384
|
const tagList = [];
|
|
280
385
|
if (favorites.size > 0) {
|
|
281
386
|
const isCurrent = current !== null && favorites.has(current.provider + "/" + current.model);
|
|
282
|
-
tagList.push({ id: FAVS_KEY, name: "\
|
|
387
|
+
tagList.push({ id: FAVS_KEY, name: "\u6536\u85CF", isCurrent });
|
|
283
388
|
}
|
|
284
389
|
if (data.groups) {
|
|
285
390
|
for (const g of data.groups) {
|
|
286
391
|
if (g.models && g.models.length > 0) {
|
|
287
392
|
const isCurrent = current !== null && current.provider === g.id;
|
|
288
|
-
tagList.push({ id: g.id, name: g.name, isCurrent
|
|
393
|
+
tagList.push({ id: g.id, name: g.name, isCurrent });
|
|
289
394
|
}
|
|
290
395
|
}
|
|
291
396
|
}
|
|
292
|
-
const groupTitle = (gid, name2, count, isCollapsed, interactive) => import_react.default.createElement(
|
|
397
|
+
const groupTitle = (gid, name2, count, isCollapsed, interactive, icon) => import_react.default.createElement(
|
|
293
398
|
"div",
|
|
294
399
|
{
|
|
295
400
|
className: "mdsl-group-title",
|
|
@@ -306,7 +411,8 @@ var module = { exports: {} };
|
|
|
306
411
|
} : void 0
|
|
307
412
|
},
|
|
308
413
|
import_react.default.createElement("span", { className: "mdsl-group-chevron" }, chevron()),
|
|
309
|
-
import_react.default.createElement("span",
|
|
414
|
+
icon ? import_react.default.createElement("span", { className: "mdsl-group-icon" }, icon) : null,
|
|
415
|
+
import_react.default.createElement("span", { className: "mdsl-group-name" }, name2),
|
|
310
416
|
import_react.default.createElement("span", { className: "mdsl-group-count" }, count)
|
|
311
417
|
);
|
|
312
418
|
const renderRow = (c) => {
|
|
@@ -315,25 +421,35 @@ var module = { exports: {} };
|
|
|
315
421
|
const isFav = favorites.has(`${c.g.id}/${c.m.id}`);
|
|
316
422
|
const chips = [];
|
|
317
423
|
if (hasEfforts) {
|
|
318
|
-
chips.push(import_react.default.createElement("button", { key: "default", className: "mdsl-chip" + (effEff === void 0 ? " mdsl-chip-on" : ""), onClick: (ev) => {
|
|
424
|
+
chips.push(import_react.default.createElement("button", { key: "default", type: "button", className: "mdsl-chip" + (effEff === void 0 ? " mdsl-chip-on" : ""), "aria-pressed": effEff === void 0, onClick: (ev) => {
|
|
319
425
|
ev.stopPropagation();
|
|
320
426
|
selectSelection({ provider: c.g.id, model: c.m.id });
|
|
321
427
|
} }, "\u9ED8\u8BA4"));
|
|
322
428
|
for (const e of c.m.reasoning.efforts) {
|
|
323
|
-
chips.push(import_react.default.createElement("button", { key: e.id, className: "mdsl-chip" + (effEff === e.id ? " mdsl-chip-on" : ""), title: e.description || e.name, onClick: (ev) => {
|
|
429
|
+
chips.push(import_react.default.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) => {
|
|
324
430
|
ev.stopPropagation();
|
|
325
431
|
selectSelection({ provider: c.g.id, model: c.m.id, reasoningEffort: e.id });
|
|
326
432
|
} }, e.name));
|
|
327
433
|
}
|
|
328
434
|
}
|
|
435
|
+
const selectRow = () => selectSelection({ provider: c.g.id, model: c.m.id, ...hasEfforts && c.m.reasoning.defaultEffort !== void 0 ? { reasoningEffort: c.m.reasoning.defaultEffort } : {} });
|
|
329
436
|
return import_react.default.createElement(
|
|
330
437
|
"div",
|
|
331
438
|
{
|
|
332
439
|
key: `${c.g.id}/${c.m.id}`,
|
|
333
440
|
className: "mdsl-row" + (c.selected ? " mdsl-row-current" : ""),
|
|
334
|
-
|
|
441
|
+
role: "button",
|
|
442
|
+
tabIndex: 0,
|
|
443
|
+
"aria-pressed": c.selected,
|
|
444
|
+
onClick: selectRow,
|
|
445
|
+
onKeyDown: (ev) => {
|
|
446
|
+
if (ev.key === "Enter" || ev.key === " ") {
|
|
447
|
+
ev.preventDefault();
|
|
448
|
+
selectRow();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
335
451
|
},
|
|
336
|
-
import_react.default.createElement("button", { className: "mdsl-star" + (isFav ? " mdsl-star-on" : ""), "aria-label": isFav ? "\u53D6\u6D88\u6536\u85CF" : "\u6536\u85CF", onClick: (ev) => toggleFav(c.g.id, c.m.id, ev) }, star(isFav)),
|
|
452
|
+
import_react.default.createElement("button", { type: "button", className: "mdsl-star" + (isFav ? " mdsl-star-on" : ""), "aria-label": isFav ? "\u53D6\u6D88\u6536\u85CF" : "\u6536\u85CF", "aria-pressed": isFav, onClick: (ev) => toggleFav(c.g.id, c.m.id, ev) }, star(isFav)),
|
|
337
453
|
import_react.default.createElement(
|
|
338
454
|
"div",
|
|
339
455
|
{ className: "mdsl-row-main" },
|
|
@@ -341,7 +457,7 @@ var module = { exports: {} };
|
|
|
341
457
|
"div",
|
|
342
458
|
{ className: "mdsl-row-head" },
|
|
343
459
|
import_react.default.createElement("span", { className: "mdsl-row-name" }, c.m.name),
|
|
344
|
-
c.selected ? import_react.default.createElement("span", { className: "mdsl-check" },
|
|
460
|
+
c.selected ? import_react.default.createElement("span", { className: "mdsl-check" }, check()) : null
|
|
345
461
|
),
|
|
346
462
|
c.m.description ? import_react.default.createElement("div", { className: "mdsl-row-desc" }, c.m.description) : null,
|
|
347
463
|
chips.length ? import_react.default.createElement("div", { className: "mdsl-row-chips" }, chips) : null
|
|
@@ -363,61 +479,85 @@ var module = { exports: {} };
|
|
|
363
479
|
isCollapsed ? null : items.map(renderRow)
|
|
364
480
|
);
|
|
365
481
|
};
|
|
482
|
+
const noMatch = data.status === "ready" && q !== "" && filtered.length === 0;
|
|
483
|
+
const currentEffortText = effLabel && effLabel !== "\u9ED8\u8BA4" ? effLabel : "";
|
|
366
484
|
return import_react.default.createElement(
|
|
367
485
|
"div",
|
|
368
486
|
{ className: "mdsl-root" },
|
|
369
487
|
import_react.default.createElement(
|
|
370
488
|
"button",
|
|
371
489
|
{
|
|
490
|
+
ref: triggerRef,
|
|
491
|
+
type: "button",
|
|
372
492
|
className: "mdsl-trigger",
|
|
373
493
|
onClick: () => {
|
|
374
494
|
if (open) closeMenu();
|
|
375
495
|
else openMenu();
|
|
376
496
|
},
|
|
377
497
|
disabled: locked,
|
|
378
|
-
title: triggerLabel + (effLabel ? " \xB7 " + effLabel : "")
|
|
498
|
+
title: triggerLabel + (effLabel ? " \xB7 " + effLabel : ""),
|
|
499
|
+
"aria-haspopup": "dialog",
|
|
500
|
+
"aria-expanded": open
|
|
379
501
|
},
|
|
380
502
|
import_react.default.createElement("span", { className: "mdsl-label" }, triggerLabel),
|
|
381
|
-
effLabel ?
|
|
382
|
-
import_react.default.createElement("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") },
|
|
503
|
+
effLabel ? import_react.default.createElement("span", { className: "mdsl-effort" }, effLabel) : null,
|
|
504
|
+
import_react.default.createElement("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown())
|
|
383
505
|
),
|
|
384
506
|
open ? import_react.default.createElement("div", { className: "mdsl-backdrop", onClick: closeMenu }) : null,
|
|
385
|
-
open ? import_react.default.createElement(
|
|
507
|
+
open && placement !== null ? import_react.default.createElement(
|
|
386
508
|
"div",
|
|
387
|
-
{
|
|
509
|
+
{
|
|
510
|
+
className: "mdsl-menu",
|
|
511
|
+
style: {
|
|
512
|
+
left: placement.left + "px",
|
|
513
|
+
width: placement.width + "px",
|
|
514
|
+
maxWidth: placement.width + "px",
|
|
515
|
+
maxHeight: placement.maxHeight + "px",
|
|
516
|
+
...placement.side === "top" ? { top: "auto", bottom: placement.bottom + "px" } : { top: placement.top + "px", bottom: "auto" },
|
|
517
|
+
transformOrigin: placement.side === "top" ? "bottom right" : "top right"
|
|
518
|
+
},
|
|
519
|
+
role: "dialog",
|
|
520
|
+
"aria-label": "\u9009\u62E9\u6A21\u578B",
|
|
521
|
+
onKeyDown: (ev) => {
|
|
522
|
+
if (ev.key === "Escape") {
|
|
523
|
+
ev.preventDefault();
|
|
524
|
+
ev.stopPropagation();
|
|
525
|
+
closeMenu();
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
},
|
|
388
529
|
import_react.default.createElement(
|
|
389
530
|
"div",
|
|
390
531
|
{ className: "mdsl-header" },
|
|
391
|
-
import_react.default.createElement(
|
|
392
|
-
"div",
|
|
393
|
-
{ className: "mdsl-summary" },
|
|
394
|
-
import_react.default.createElement("span", { className: "mdsl-summary-dot" }),
|
|
395
|
-
current ? [import_react.default.createElement("span", { className: "mdsl-summary-lbl" }, "\u5F53\u524D"), import_react.default.createElement("span", { className: "mdsl-summary-b" }, modelName)] : import_react.default.createElement("span", { className: "mdsl-summary-lbl" }, "\u9009\u62E9\u6A21\u578B")
|
|
396
|
-
),
|
|
397
532
|
import_react.default.createElement(
|
|
398
533
|
"div",
|
|
399
534
|
{ className: "mdsl-search-wrap" },
|
|
400
535
|
searchIcon(),
|
|
401
|
-
import_react.default.createElement("input", {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
536
|
+
import_react.default.createElement("input", {
|
|
537
|
+
ref: searchRef,
|
|
538
|
+
className: "mdsl-search",
|
|
539
|
+
"aria-label": "\u641C\u7D22\u6A21\u578B",
|
|
540
|
+
placeholder: "\u641C\u7D22\u6A21\u578B\u3001\u63CF\u8FF0\u6216\u63D0\u4F9B\u5546\u2026",
|
|
541
|
+
value: query,
|
|
542
|
+
onChange: (ev) => setQuery(ev.target.value)
|
|
543
|
+
}),
|
|
544
|
+
query !== "" ? import_react.default.createElement("button", { type: "button", className: "mdsl-search-clear", "aria-label": "\u6E05\u9664\u641C\u7D22", onClick: () => setQuery("") }, closeIcon()) : null
|
|
405
545
|
),
|
|
406
|
-
tagList.length > 0 ? import_react.default.createElement(
|
|
546
|
+
q === "" && tagList.length > 0 ? import_react.default.createElement(
|
|
407
547
|
"div",
|
|
408
|
-
{ className: "mdsl-tags" },
|
|
548
|
+
{ className: "mdsl-tags", ref: tagRailRef },
|
|
409
549
|
tagList.map((tag) => import_react.default.createElement(
|
|
410
550
|
"button",
|
|
411
551
|
{
|
|
412
552
|
key: tag.id,
|
|
413
553
|
type: "button",
|
|
414
554
|
className: "mdsl-tag" + (tag.isCurrent ? " mdsl-tag-current" : ""),
|
|
555
|
+
"data-current": tag.isCurrent ? "true" : void 0,
|
|
415
556
|
title: "\u8DF3\u8F6C\u81F3 " + tag.name,
|
|
416
557
|
onClick: () => scrollToGroup(tag.id)
|
|
417
558
|
},
|
|
418
|
-
tag.
|
|
419
|
-
import_react.default.createElement("span",
|
|
420
|
-
import_react.default.createElement("span", { className: "mdsl-tag-count" }, "(" + tag.count + ")")
|
|
559
|
+
tag.id === FAVS_KEY ? import_react.default.createElement("span", { className: "mdsl-tag-icon" }, star(tag.isCurrent)) : null,
|
|
560
|
+
import_react.default.createElement("span", { className: "mdsl-tag-name" }, tag.name)
|
|
421
561
|
))
|
|
422
562
|
) : null
|
|
423
563
|
),
|
|
@@ -425,17 +565,25 @@ var module = { exports: {} };
|
|
|
425
565
|
data.failures && data.failures.length ? import_react.default.createElement("div", { className: "mdsl-error" }, data.failures.map((f) => f.name + ": " + f.message).join("\uFF1B")) : null,
|
|
426
566
|
import_react.default.createElement(
|
|
427
567
|
"div",
|
|
428
|
-
{ className: "mdsl-body", ref: bodyRef },
|
|
568
|
+
{ className: "mdsl-body", ref: bodyRef, role: "group", "aria-label": "\u6A21\u578B\u5217\u8868" },
|
|
429
569
|
data.status === "loading" ? import_react.default.createElement("div", { className: "mdsl-empty" }, "\u52A0\u8F7D\u4E2D\u2026") : null,
|
|
430
570
|
data.status === "ready" && allChoices.length === 0 ? import_react.default.createElement("div", { className: "mdsl-empty" }, "\u6682\u65E0\u53EF\u7528\u6A21\u578B") : null,
|
|
571
|
+
noMatch ? import_react.default.createElement(
|
|
572
|
+
"div",
|
|
573
|
+
{ className: "mdsl-empty" },
|
|
574
|
+
"\u6CA1\u6709\u5339\u914D\u7684\u6A21\u578B",
|
|
575
|
+
import_react.default.createElement("div", { className: "mdsl-empty-sub" }, "\u6362\u4E2A\u5173\u952E\u8BCD\u8BD5\u8BD5")
|
|
576
|
+
) : null,
|
|
431
577
|
favs.length ? import_react.default.createElement(
|
|
432
578
|
"div",
|
|
433
579
|
{
|
|
434
580
|
className: "mdsl-group" + (favsCollapsed ? " mdsl-group-collapsed" : ""),
|
|
435
581
|
key: FAVS_KEY,
|
|
436
|
-
"data-group-id": FAVS_KEY
|
|
582
|
+
"data-group-id": FAVS_KEY,
|
|
583
|
+
role: "group",
|
|
584
|
+
"aria-label": "\u6536\u85CF"
|
|
437
585
|
},
|
|
438
|
-
groupTitle(FAVS_KEY, "\u6536\u85CF", favs.length, favsCollapsed, q === ""),
|
|
586
|
+
groupTitle(FAVS_KEY, "\u6536\u85CF", favs.length, favsCollapsed, q === "", star(true)),
|
|
439
587
|
favsCollapsed ? null : favs.map(renderRow)
|
|
440
588
|
) : null,
|
|
441
589
|
(data.groups || []).map(renderGroup)
|
|
@@ -444,7 +592,8 @@ var module = { exports: {} };
|
|
|
444
592
|
"div",
|
|
445
593
|
{ className: "mdsl-footer" },
|
|
446
594
|
import_react.default.createElement("span", { className: "mdsl-footer-dot" }),
|
|
447
|
-
import_react.default.createElement("span",
|
|
595
|
+
import_react.default.createElement("span", { className: "mdsl-footer-current" }, current ? modelName + (currentEffortText ? " \xB7 " + currentEffortText : "") : "\u672A\u9009\u62E9\u6A21\u578B"),
|
|
596
|
+
import_react.default.createElement("span", { className: "mdsl-footer-hint" }, "Esc")
|
|
448
597
|
)
|
|
449
598
|
) : null
|
|
450
599
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-model-select-plus",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "A richer model-selection popup for DeepSeek Harness: provider-grouped models with descriptions, inline reasoning-effort chips, search and pinned favorites — replaces the composer's default ModelSelect.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/host.js",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"esbuild": "^0.25.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@deepseek-ai/cordis": "^4.0.
|
|
63
|
-
"@deepseek-ai/dsh-host-webserver": "^0.2.
|
|
64
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.
|
|
65
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.
|
|
62
|
+
"@deepseek-ai/cordis": "^4.0.5",
|
|
63
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.2",
|
|
64
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.1-rc.2",
|
|
65
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.1-rc.2",
|
|
66
66
|
"react": "^18.3.1"
|
|
67
67
|
},
|
|
68
68
|
"peerDependenciesMeta": {
|
package/src/client.js
CHANGED
|
@@ -9,14 +9,19 @@
|
|
|
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 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)
|
|
20
25
|
*
|
|
21
26
|
* Data comes from the Host half at `/plugins/dsh-model-select-plus/api`.
|
|
22
27
|
* The seat passes `locked` (owner prop) and we inject `sessionId`.
|
|
@@ -32,70 +37,102 @@ const STYLE_TAG = "dsh-model-select-plus/style";
|
|
|
32
37
|
const FAVS_KEY = "__favorites__";
|
|
33
38
|
|
|
34
39
|
const CSS = `
|
|
35
|
-
.mdsl-root {
|
|
40
|
+
.mdsl-root, .mdsl-root *, .mdsl-root *::before, .mdsl-root *::after { box-sizing: border-box; }
|
|
41
|
+
.mdsl-root { position: relative; display: inline-flex; align-items: center; min-width: 0; max-width: 100%; }
|
|
36
42
|
.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
|
-
|
|
43
|
+
|
|
44
|
+
/* Trigger: same 28px chip as the composer's sibling permission / plan
|
|
45
|
+
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; }
|
|
47
|
+
.mdsl-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
48
|
+
.mdsl-trigger:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
|
|
49
|
+
.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. */
|
|
53
|
+
.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; }
|
|
46
55
|
.mdsl-chevron-open { transform: rotate(180deg); }
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.mdsl-
|
|
51
|
-
.mdsl-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
|
|
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; }
|
|
60
|
+
body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
|
|
61
|
+
@keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
|
|
62
|
+
@media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
|
|
63
|
+
|
|
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; }
|
|
54
68
|
.mdsl-search-wrap { position: relative; display: flex; align-items: center; }
|
|
55
|
-
.mdsl-search-icon { position: absolute; left: 9px; color: var(--dsw-alias-label-tertiary);
|
|
56
|
-
.mdsl-search { width: 100%;
|
|
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; }
|
|
57
71
|
.mdsl-search::placeholder { color: var(--dsw-alias-label-tertiary); }
|
|
58
|
-
.mdsl-search:focus { border-color: var(--dsw-alias-
|
|
59
|
-
.mdsl-search-clear { position: absolute; right:
|
|
60
|
-
.mdsl-search-clear:hover { background: var(--dsw-alias-interactive-bg-
|
|
61
|
-
.mdsl-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.mdsl-
|
|
66
|
-
.mdsl-
|
|
67
|
-
.mdsl-tag
|
|
68
|
-
.mdsl-
|
|
69
|
-
.mdsl-
|
|
70
|
-
.mdsl-
|
|
71
|
-
.mdsl-
|
|
72
|
-
.mdsl-
|
|
73
|
-
|
|
74
|
-
.mdsl-
|
|
75
|
-
.mdsl-
|
|
76
|
-
.mdsl-
|
|
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; }
|
|
74
|
+
.mdsl-search-clear:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
|
|
75
|
+
.mdsl-search-clear:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
76
|
+
|
|
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
|
+
.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
|
+
.mdsl-body::-webkit-scrollbar { width: 8px; }
|
|
90
|
+
.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
|
+
.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
|
+
|
|
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); }
|
|
77
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; }
|
|
78
102
|
.mdsl-group-collapsed .mdsl-group-chevron { transform: none; }
|
|
79
|
-
.mdsl-group-
|
|
80
|
-
.mdsl-
|
|
103
|
+
.mdsl-group-icon { flex: none; display: inline-flex; color: var(--dsw-alias-brand-primary); }
|
|
104
|
+
.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
|
+
|
|
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; }
|
|
81
108
|
.mdsl-row:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
82
109
|
.mdsl-row-current, .mdsl-row-current:hover { background: var(--dsw-alias-interactive-bg-active); }
|
|
83
|
-
.mdsl-
|
|
84
|
-
.mdsl-star
|
|
110
|
+
.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; }
|
|
112
|
+
.mdsl-star:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
|
|
113
|
+
.mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
85
114
|
.mdsl-star-on { color: var(--dsw-alias-brand-primary); }
|
|
86
115
|
.mdsl-row-main { flex: 1; min-width: 0; }
|
|
87
|
-
.mdsl-row-head { display: flex; align-items: center; gap: 6px; min-width: 0; min-height:
|
|
88
|
-
.mdsl-row-name {
|
|
89
|
-
.mdsl-check {
|
|
90
|
-
.mdsl-row-desc {
|
|
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; }
|
|
91
120
|
.mdsl-row-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
|
|
92
|
-
.mdsl-chip {
|
|
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; }
|
|
93
122
|
.mdsl-chip:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
|
|
94
|
-
.mdsl-chip-
|
|
95
|
-
.mdsl-
|
|
96
|
-
|
|
97
|
-
.mdsl-
|
|
98
|
-
.mdsl-
|
|
123
|
+
.mdsl-chip:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
124
|
+
.mdsl-chip-on { border-color: var(--dsw-alias-brand-primary); background: transparent; color: var(--dsw-alias-label-primary); font-weight: 500; }
|
|
125
|
+
|
|
126
|
+
.mdsl-empty { padding: 18px 10px; text-align: center; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
|
|
127
|
+
.mdsl-empty-sub { margin-top: 2px; color: var(--dsw-alias-label-caption); font-size: 11px; line-height: 16px; }
|
|
128
|
+
.mdsl-error { margin: 4px 2px; padding: 6px 8px; border-radius: var(--dsw-radius-sm, 8px); background: var(--dsw-alias-interactive-bg-hover-danger); color: var(--dsw-alias-state-error-primary); font-size: 11px; line-height: 16px; }
|
|
129
|
+
|
|
130
|
+
/* Pinned footer: repeats the current selection while the body is scrolled
|
|
131
|
+
into some other provider, plus the only keyboard shortcut worth naming. */
|
|
132
|
+
.mdsl-footer { flex: none; display: flex; align-items: center; gap: 6px; margin-top: 2px; padding: 5px 6px 3px; border-top: 0.5px solid var(--dsw-alias-border-l2); color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; }
|
|
133
|
+
.mdsl-footer-dot { flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--dsw-alias-brand-primary); }
|
|
134
|
+
.mdsl-footer-current { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-secondary); }
|
|
135
|
+
.mdsl-footer-hint { flex: none; color: var(--dsw-alias-label-caption); font-variant-numeric: tabular-nums; }
|
|
99
136
|
`;
|
|
100
137
|
|
|
101
138
|
function injectStyle() {
|
|
@@ -110,14 +147,32 @@ function injectStyle() {
|
|
|
110
147
|
|
|
111
148
|
const star = (filled) => React.createElement(
|
|
112
149
|
"svg",
|
|
113
|
-
{ width: 14, height: 14, viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", xmlns: "http://www.w3.org/2000/svg" },
|
|
150
|
+
{ width: 14, height: 14, viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
|
|
114
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" }),
|
|
115
152
|
);
|
|
116
153
|
|
|
117
154
|
const chevron = () => React.createElement(
|
|
118
155
|
"svg",
|
|
119
|
-
{ width:
|
|
120
|
-
React.createElement("path", { d: "
|
|
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" }),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const chevronDown = () => React.createElement(
|
|
161
|
+
"svg",
|
|
162
|
+
{ 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" }),
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const closeIcon = () => React.createElement(
|
|
173
|
+
"svg",
|
|
174
|
+
{ 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" }),
|
|
121
176
|
);
|
|
122
177
|
|
|
123
178
|
const searchIcon = () => React.createElement(
|
|
@@ -125,7 +180,7 @@ const searchIcon = () => React.createElement(
|
|
|
125
180
|
{ className: "mdsl-search-icon" },
|
|
126
181
|
React.createElement(
|
|
127
182
|
"svg",
|
|
128
|
-
{ width:
|
|
183
|
+
{ width: 14, height: 14, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" },
|
|
129
184
|
React.createElement("circle", { cx: 7, cy: 7, r: 5, stroke: "currentColor", strokeWidth: 1.4 }),
|
|
130
185
|
React.createElement("line", { x1: 10.8, y1: 10.8, x2: 14, y2: 14, stroke: "currentColor", strokeWidth: 1.4, strokeLinecap: "round" }),
|
|
131
186
|
),
|
|
@@ -135,6 +190,10 @@ function ModelSelectLite(props) {
|
|
|
135
190
|
const sessionId = props.sessionId;
|
|
136
191
|
const locked = props.locked === true;
|
|
137
192
|
const bodyRef = React.useRef(null);
|
|
193
|
+
const triggerRef = React.useRef(null);
|
|
194
|
+
const searchRef = React.useRef(null);
|
|
195
|
+
const tagRailRef = React.useRef(null);
|
|
196
|
+
const [placement, setPlacement] = React.useState(null);
|
|
138
197
|
const [open, setOpen] = React.useState(false);
|
|
139
198
|
const [data, setData] = React.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
|
|
140
199
|
const [query, setQuery] = React.useState("");
|
|
@@ -171,8 +230,79 @@ function ModelSelectLite(props) {
|
|
|
171
230
|
}
|
|
172
231
|
}, [sessionId]);
|
|
173
232
|
|
|
233
|
+
// Opening the menu focuses the search field: typing filters immediately and
|
|
234
|
+
// Escape lands on the menu's key handler for free.
|
|
235
|
+
React.useEffect(() => {
|
|
236
|
+
if (!open || placement === null) return;
|
|
237
|
+
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
|
+
if (el) el.focus({ preventScroll: true });
|
|
242
|
+
}, [open, placement]);
|
|
243
|
+
|
|
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
|
+
// Measure the room around the trigger before painting: open upward while it
|
|
256
|
+
// 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.
|
|
258
|
+
const placeMenu = () => {
|
|
259
|
+
const trigger = triggerRef.current;
|
|
260
|
+
if (!trigger) return;
|
|
261
|
+
const rect = trigger.getBoundingClientRect();
|
|
262
|
+
const margin = 12;
|
|
263
|
+
const gap = 6;
|
|
264
|
+
const width = Math.min(384, window.innerWidth - margin * 2);
|
|
265
|
+
const spaceAbove = rect.top - gap - margin;
|
|
266
|
+
const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
|
|
267
|
+
const side = spaceAbove >= spaceBelow ? "top" : "bottom";
|
|
268
|
+
const maxHeight = Math.max(160, Math.min(480, side === "top" ? spaceAbove : spaceBelow));
|
|
269
|
+
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,
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
React.useLayoutEffect(() => {
|
|
281
|
+
if (open) placeMenu();
|
|
282
|
+
}, [open]);
|
|
283
|
+
|
|
284
|
+
React.useEffect(() => {
|
|
285
|
+
if (!open) return;
|
|
286
|
+
const reposition = () => placeMenu();
|
|
287
|
+
window.addEventListener("resize", reposition);
|
|
288
|
+
window.addEventListener("scroll", reposition, true);
|
|
289
|
+
return () => {
|
|
290
|
+
window.removeEventListener("resize", reposition);
|
|
291
|
+
window.removeEventListener("scroll", reposition, true);
|
|
292
|
+
};
|
|
293
|
+
}, [open]);
|
|
294
|
+
|
|
295
|
+
const focusTrigger = () => {
|
|
296
|
+
const el = triggerRef.current;
|
|
297
|
+
if (el) el.focus({ preventScroll: true });
|
|
298
|
+
};
|
|
174
299
|
const openMenu = () => { setOpen(true); load(); };
|
|
175
|
-
const closeMenu = () => {
|
|
300
|
+
const closeMenu = () => {
|
|
301
|
+
setOpen(false);
|
|
302
|
+
setQuery("");
|
|
303
|
+
setPlacement(null);
|
|
304
|
+
focusTrigger();
|
|
305
|
+
};
|
|
176
306
|
|
|
177
307
|
const selectSelection = (sel) => {
|
|
178
308
|
if (busy) return;
|
|
@@ -251,7 +381,7 @@ function ModelSelectLite(props) {
|
|
|
251
381
|
const bodyRect = bodyRef.current.getBoundingClientRect();
|
|
252
382
|
const elRect = el.getBoundingClientRect();
|
|
253
383
|
const targetScrollTop = bodyRef.current.scrollTop + (elRect.top - bodyRect.top);
|
|
254
|
-
bodyRef.current.scrollTo({ top: Math.max(0, targetScrollTop -
|
|
384
|
+
bodyRef.current.scrollTo({ top: Math.max(0, targetScrollTop - 2), behavior: "smooth" });
|
|
255
385
|
}
|
|
256
386
|
}, 40);
|
|
257
387
|
};
|
|
@@ -287,20 +417,20 @@ function ModelSelectLite(props) {
|
|
|
287
417
|
const tagList = [];
|
|
288
418
|
if (favorites.size > 0) {
|
|
289
419
|
const isCurrent = current !== null && favorites.has(current.provider + "/" + current.model);
|
|
290
|
-
tagList.push({ id: FAVS_KEY, name: "
|
|
420
|
+
tagList.push({ id: FAVS_KEY, name: "收藏", isCurrent });
|
|
291
421
|
}
|
|
292
422
|
if (data.groups) {
|
|
293
423
|
for (const g of data.groups) {
|
|
294
424
|
if (g.models && g.models.length > 0) {
|
|
295
425
|
const isCurrent = current !== null && current.provider === g.id;
|
|
296
|
-
tagList.push({ id: g.id, name: g.name, isCurrent
|
|
426
|
+
tagList.push({ id: g.id, name: g.name, isCurrent });
|
|
297
427
|
}
|
|
298
428
|
}
|
|
299
429
|
}
|
|
300
430
|
|
|
301
431
|
// Group header doubles as a collapse toggle (Enter/Space work too); while
|
|
302
432
|
// searching it is inert and every group renders expanded.
|
|
303
|
-
const groupTitle = (gid, name, count, isCollapsed, interactive) => React.createElement(
|
|
433
|
+
const groupTitle = (gid, name, count, isCollapsed, interactive, icon) => React.createElement(
|
|
304
434
|
"div",
|
|
305
435
|
{
|
|
306
436
|
className: "mdsl-group-title",
|
|
@@ -312,7 +442,8 @@ function ModelSelectLite(props) {
|
|
|
312
442
|
onKeyDown: interactive ? (ev) => { if (ev.key === "Enter" || ev.key === " ") { ev.preventDefault(); toggleCollapse(gid); } } : undefined,
|
|
313
443
|
},
|
|
314
444
|
React.createElement("span", { className: "mdsl-group-chevron" }, chevron()),
|
|
315
|
-
React.createElement("span",
|
|
445
|
+
icon ? React.createElement("span", { className: "mdsl-group-icon" }, icon) : null,
|
|
446
|
+
React.createElement("span", { className: "mdsl-group-name" }, name),
|
|
316
447
|
React.createElement("span", { className: "mdsl-group-count" }, count),
|
|
317
448
|
);
|
|
318
449
|
|
|
@@ -322,21 +453,26 @@ function ModelSelectLite(props) {
|
|
|
322
453
|
const isFav = favorites.has(`${c.g.id}/${c.m.id}`);
|
|
323
454
|
const chips = [];
|
|
324
455
|
if (hasEfforts) {
|
|
325
|
-
chips.push(React.createElement("button", { key: "default", className: "mdsl-chip" + (effEff === undefined ? " mdsl-chip-on" : ""), onClick: (ev) => { ev.stopPropagation(); selectSelection({ provider: c.g.id, model: c.m.id }); } }, "默认"));
|
|
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 }); } }, "默认"));
|
|
326
457
|
for (const e of c.m.reasoning.efforts) {
|
|
327
|
-
chips.push(React.createElement("button", { key: e.id, className: "mdsl-chip" + (effEff === e.id ? " mdsl-chip-on" : ""), title: e.description || e.name, onClick: (ev) => { ev.stopPropagation(); selectSelection({ provider: c.g.id, model: c.m.id, reasoningEffort: e.id }); } }, e.name));
|
|
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));
|
|
328
459
|
}
|
|
329
460
|
}
|
|
461
|
+
const selectRow = () => selectSelection({ provider: c.g.id, model: c.m.id, ...(hasEfforts && c.m.reasoning.defaultEffort !== undefined ? { reasoningEffort: c.m.reasoning.defaultEffort } : {}) });
|
|
330
462
|
return React.createElement("div", {
|
|
331
463
|
key: `${c.g.id}/${c.m.id}`,
|
|
332
464
|
className: "mdsl-row" + (c.selected ? " mdsl-row-current" : ""),
|
|
333
|
-
|
|
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(); } },
|
|
334
470
|
},
|
|
335
|
-
React.createElement("button", { className: "mdsl-star" + (isFav ? " mdsl-star-on" : ""), "aria-label": isFav ? "取消收藏" : "收藏", onClick: (ev) => toggleFav(c.g.id, c.m.id, ev) }, star(isFav)),
|
|
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)),
|
|
336
472
|
React.createElement("div", { className: "mdsl-row-main" },
|
|
337
473
|
React.createElement("div", { className: "mdsl-row-head" },
|
|
338
474
|
React.createElement("span", { className: "mdsl-row-name" }, c.m.name),
|
|
339
|
-
c.selected ? React.createElement("span", { className: "mdsl-check" },
|
|
475
|
+
c.selected ? React.createElement("span", { className: "mdsl-check" }, check()) : null,
|
|
340
476
|
),
|
|
341
477
|
c.m.description ? React.createElement("div", { className: "mdsl-row-desc" }, c.m.description) : null,
|
|
342
478
|
chips.length ? React.createElement("div", { className: "mdsl-row-chips" }, chips) : null,
|
|
@@ -358,63 +494,95 @@ function ModelSelectLite(props) {
|
|
|
358
494
|
);
|
|
359
495
|
};
|
|
360
496
|
|
|
497
|
+
const noMatch = data.status === "ready" && q !== "" && filtered.length === 0;
|
|
498
|
+
const currentEffortText = effLabel && effLabel !== "默认" ? effLabel : "";
|
|
499
|
+
|
|
361
500
|
return React.createElement("div", { className: "mdsl-root" },
|
|
362
501
|
React.createElement("button", {
|
|
502
|
+
ref: triggerRef,
|
|
503
|
+
type: "button",
|
|
363
504
|
className: "mdsl-trigger",
|
|
364
505
|
onClick: () => { if (open) closeMenu(); else openMenu(); },
|
|
365
506
|
disabled: locked,
|
|
366
507
|
title: triggerLabel + (effLabel ? " · " + effLabel : ""),
|
|
508
|
+
"aria-haspopup": "dialog",
|
|
509
|
+
"aria-expanded": open,
|
|
367
510
|
},
|
|
368
511
|
React.createElement("span", { className: "mdsl-label" }, triggerLabel),
|
|
369
|
-
effLabel ?
|
|
370
|
-
React.createElement("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") },
|
|
512
|
+
effLabel ? React.createElement("span", { className: "mdsl-effort" }, effLabel) : null,
|
|
513
|
+
React.createElement("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown()),
|
|
371
514
|
),
|
|
372
515
|
open ? React.createElement("div", { className: "mdsl-backdrop", onClick: closeMenu }) : null,
|
|
373
|
-
open ? React.createElement("div", {
|
|
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",
|
|
527
|
+
},
|
|
528
|
+
role: "dialog",
|
|
529
|
+
"aria-label": "选择模型",
|
|
530
|
+
onKeyDown: (ev) => { if (ev.key === "Escape") { ev.preventDefault(); ev.stopPropagation(); closeMenu(); } },
|
|
531
|
+
},
|
|
374
532
|
React.createElement("div", { className: "mdsl-header" },
|
|
375
|
-
React.createElement("div", { className: "mdsl-summary" },
|
|
376
|
-
React.createElement("span", { className: "mdsl-summary-dot" }),
|
|
377
|
-
current
|
|
378
|
-
? [React.createElement("span", { className: "mdsl-summary-lbl" }, "当前"), React.createElement("span", { className: "mdsl-summary-b" }, modelName)]
|
|
379
|
-
: React.createElement("span", { className: "mdsl-summary-lbl" }, "选择模型"),
|
|
380
|
-
),
|
|
381
533
|
React.createElement("div", { className: "mdsl-search-wrap" },
|
|
382
534
|
searchIcon(),
|
|
383
|
-
React.createElement("input", {
|
|
384
|
-
|
|
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,
|
|
385
544
|
),
|
|
386
|
-
tagList.length > 0 ? React.createElement("div", { className: "mdsl-tags" },
|
|
545
|
+
q === "" && tagList.length > 0 ? React.createElement("div", { className: "mdsl-tags", ref: tagRailRef },
|
|
387
546
|
tagList.map((tag) => React.createElement("button", {
|
|
388
547
|
key: tag.id,
|
|
389
548
|
type: "button",
|
|
390
549
|
className: "mdsl-tag" + (tag.isCurrent ? " mdsl-tag-current" : ""),
|
|
550
|
+
"data-current": tag.isCurrent ? "true" : undefined,
|
|
391
551
|
title: "跳转至 " + tag.name,
|
|
392
552
|
onClick: () => scrollToGroup(tag.id),
|
|
393
553
|
},
|
|
394
|
-
tag.
|
|
395
|
-
React.createElement("span",
|
|
396
|
-
React.createElement("span", { className: "mdsl-tag-count" }, "(" + tag.count + ")"),
|
|
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),
|
|
397
556
|
)),
|
|
398
557
|
) : null,
|
|
399
558
|
),
|
|
400
559
|
data.status === "error" ? React.createElement("div", { className: "mdsl-error" }, data.error || "加载失败") : null,
|
|
401
560
|
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 },
|
|
561
|
+
React.createElement("div", { className: "mdsl-body", ref: bodyRef, role: "group", "aria-label": "模型列表" },
|
|
403
562
|
data.status === "loading" ? React.createElement("div", { className: "mdsl-empty" }, "加载中…") : null,
|
|
404
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,
|
|
405
568
|
favs.length ? React.createElement("div", {
|
|
406
569
|
className: "mdsl-group" + (favsCollapsed ? " mdsl-group-collapsed" : ""),
|
|
407
570
|
key: FAVS_KEY,
|
|
408
571
|
"data-group-id": FAVS_KEY,
|
|
572
|
+
role: "group",
|
|
573
|
+
"aria-label": "收藏",
|
|
409
574
|
},
|
|
410
|
-
groupTitle(FAVS_KEY, "收藏", favs.length, favsCollapsed, q === ""),
|
|
575
|
+
groupTitle(FAVS_KEY, "收藏", favs.length, favsCollapsed, q === "", star(true)),
|
|
411
576
|
favsCollapsed ? null : favs.map(renderRow),
|
|
412
577
|
) : null,
|
|
413
578
|
(data.groups || []).map(renderGroup),
|
|
414
579
|
),
|
|
415
580
|
React.createElement("div", { className: "mdsl-footer" },
|
|
416
581
|
React.createElement("span", { className: "mdsl-footer-dot" }),
|
|
417
|
-
React.createElement("span",
|
|
582
|
+
React.createElement("span", { className: "mdsl-footer-current" }, current
|
|
583
|
+
? (modelName + (currentEffortText ? " · " + currentEffortText : ""))
|
|
584
|
+
: "未选择模型"),
|
|
585
|
+
React.createElement("span", { className: "mdsl-footer-hint" }, "Esc"),
|
|
418
586
|
),
|
|
419
587
|
) : null,
|
|
420
588
|
);
|