dsh-vendor-quick-switch 1.0.1 → 1.0.3
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/CHANGELOG.md +17 -0
- package/client.js +71 -70
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.3
|
|
4
|
+
|
|
5
|
+
- Clicking a vendor now scrolls the shipped list's own scroll box just far
|
|
6
|
+
enough to show that vendor's group heading, so the vendor name and the models
|
|
7
|
+
under it are both on screen. It never forces the heading to the very top: a
|
|
8
|
+
vendor near the end of the list stops at the list's maximum scroll, and a
|
|
9
|
+
heading already in view is left where it is.
|
|
10
|
+
- The heading lookup accepts every name a provider may appear under, including
|
|
11
|
+
the host's localized account label.
|
|
12
|
+
|
|
13
|
+
## 1.0.2
|
|
14
|
+
|
|
15
|
+
- Revert the 1.0.1 attempt to bound the shipped menu. That change shortened the
|
|
16
|
+
host's default model list, which is the host's to decide. The plugin now only
|
|
17
|
+
bounds its own vendor column to the viewport and leaves the shipped menu's
|
|
18
|
+
height, offset, and list length untouched even when it renders past the window.
|
|
19
|
+
|
|
3
20
|
## 1.0.1
|
|
4
21
|
|
|
5
22
|
- Keep the shipped menu, and with it the vendor index and the model list, inside
|
package/client.js
CHANGED
|
@@ -229,24 +229,6 @@ window.__ModuleLoader__.load({
|
|
|
229
229
|
|
|
230
230
|
const clamp = (value, low, high) => Math.max(low, Math.min(high, value));
|
|
231
231
|
|
|
232
|
-
/**
|
|
233
|
-
* Put the shipped menu surface inside the safe band when it renders out of
|
|
234
|
-
* it (renderers without CSS anchor positioning fall back to the top-left
|
|
235
|
-
* corner and grow with their content).
|
|
236
|
-
* @returns true when the surface was adjusted.
|
|
237
|
-
*/
|
|
238
|
-
function boundSurface(surface, viewportHeight) {
|
|
239
|
-
if (surface === null || surface === undefined) return false;
|
|
240
|
-
const floor = viewportHeight - COLUMN_FLOOR;
|
|
241
|
-
const ceiling = COLUMN_INSET;
|
|
242
|
-
const box = surface.getBoundingClientRect();
|
|
243
|
-
if (box.bottom <= floor && box.top >= ceiling) return false;
|
|
244
|
-
surface.style.maxHeight = `${Math.max(160, floor - ceiling)}px`;
|
|
245
|
-
surface.style.bottom = `${COLUMN_FLOOR}px`;
|
|
246
|
-
surface.style.top = 'auto';
|
|
247
|
-
return true;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
232
|
/** Nearest fixed/absolute ancestor: the shipped menu surface. */
|
|
251
233
|
function surfaceOf(node) {
|
|
252
234
|
let current = node;
|
|
@@ -266,20 +248,62 @@ window.__ModuleLoader__.load({
|
|
|
266
248
|
}
|
|
267
249
|
|
|
268
250
|
/**
|
|
269
|
-
*
|
|
270
|
-
* @returns
|
|
251
|
+
* The scrollable box the shipped list scrolls inside, if any.
|
|
252
|
+
* @returns the nearest vertically scrollable ancestor, or null.
|
|
271
253
|
*/
|
|
272
|
-
function
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
254
|
+
function scrollerOf(node) {
|
|
255
|
+
let current = node.parentElement;
|
|
256
|
+
while (current !== null && current !== undefined && current !== document.body) {
|
|
257
|
+
const style = window.getComputedStyle(current);
|
|
258
|
+
if (/(auto|scroll)/.test(style.overflowY) && current.scrollHeight > current.clientHeight + 1) {
|
|
259
|
+
return current;
|
|
260
|
+
}
|
|
261
|
+
current = current.parentElement;
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Bring one vendor's group heading to the top of the shipped list, so the
|
|
268
|
+
* vendor name and the models under it are both on screen.
|
|
269
|
+
* @param names - every display name the vendor may appear under.
|
|
270
|
+
* @returns true when a heading was found and scrolled to.
|
|
271
|
+
*/
|
|
272
|
+
function revealVendor(surface, names) {
|
|
273
|
+
const list = listOf(surface) ?? surface;
|
|
274
|
+
if (list === null || list === undefined) return false;
|
|
275
|
+
if (typeof list.querySelectorAll !== 'function') return false;
|
|
276
|
+
const wanted = new Set((Array.isArray(names) ? names : [names])
|
|
277
|
+
.filter(name => typeof name === 'string' && name !== '')
|
|
278
|
+
.map(name => name.trim()));
|
|
279
|
+
if (wanted.size === 0) return false;
|
|
280
|
+
|
|
281
|
+
let heading = null;
|
|
282
|
+
for (const node of list.querySelectorAll('div,span,button,li,header')) {
|
|
277
283
|
if (node.children.length !== 0) continue;
|
|
278
|
-
|
|
279
|
-
|
|
284
|
+
const text = (node.textContent ?? '').trim();
|
|
285
|
+
if (text === '') continue;
|
|
286
|
+
if (!wanted.has(text)) continue;
|
|
287
|
+
heading = node;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
if (heading === null) return false;
|
|
291
|
+
|
|
292
|
+
/* Scroll only as far as needed to bring the heading into the box. A vendor
|
|
293
|
+
* near the end of the list stops at the maximum scroll instead of being
|
|
294
|
+
* forced to the top, which is what a short tail can actually reach. */
|
|
295
|
+
const scroller = scrollerOf(heading);
|
|
296
|
+
const box = heading.getBoundingClientRect();
|
|
297
|
+
if (scroller !== null && scroller !== undefined) {
|
|
298
|
+
const frame = scroller.getBoundingClientRect();
|
|
299
|
+
if (box.top >= frame.top && box.bottom <= frame.bottom) return true;
|
|
300
|
+
const maxScroll = Math.max(0, scroller.scrollHeight - scroller.clientHeight);
|
|
301
|
+
const delta = box.top - frame.top;
|
|
302
|
+
scroller.scrollTop = Math.min(maxScroll, Math.max(0, scroller.scrollTop + delta));
|
|
280
303
|
return true;
|
|
281
304
|
}
|
|
282
|
-
|
|
305
|
+
heading.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
306
|
+
return true;
|
|
283
307
|
}
|
|
284
308
|
|
|
285
309
|
/* ---------------------------------------------------------------- flyout */
|
|
@@ -300,38 +324,10 @@ window.__ModuleLoader__.load({
|
|
|
300
324
|
const { state: catalog } = useDirectory(getModels, state.sessionId);
|
|
301
325
|
|
|
302
326
|
/**
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* renderer does not support it, the menu falls back to the top-left
|
|
307
|
-
* corner and grows with its content, so a long model list runs past the
|
|
308
|
-
* bottom of the window — and a vendor index that follows that rectangle
|
|
309
|
-
* runs past it too. Only the out-of-band case is touched: the menu gets a
|
|
310
|
-
* bounded height, sits above the composer's tool row, and keeps its own
|
|
311
|
-
* internal scrolling. Original inline values are restored on close.
|
|
327
|
+
* The shipped menu is the host's: never touch its height, offset, or
|
|
328
|
+
* length. Only this column is bounded to the viewport, so the vendor
|
|
329
|
+
* index can never be the thing that spills past the window edge.
|
|
312
330
|
*/
|
|
313
|
-
React.useEffect(() => {
|
|
314
|
-
if (!state.open || state.surface === null) return undefined;
|
|
315
|
-
const surface = state.surface;
|
|
316
|
-
const saved = {
|
|
317
|
-
top: surface.style.top,
|
|
318
|
-
bottom: surface.style.bottom,
|
|
319
|
-
maxHeight: surface.style.maxHeight,
|
|
320
|
-
};
|
|
321
|
-
const apply = () => {
|
|
322
|
-
boundSurface(surface, window.innerHeight);
|
|
323
|
-
};
|
|
324
|
-
apply();
|
|
325
|
-
const frame = window.requestAnimationFrame(apply);
|
|
326
|
-
window.addEventListener('resize', apply);
|
|
327
|
-
return () => {
|
|
328
|
-
window.cancelAnimationFrame(frame);
|
|
329
|
-
window.removeEventListener('resize', apply);
|
|
330
|
-
surface.style.top = saved.top;
|
|
331
|
-
surface.style.bottom = saved.bottom;
|
|
332
|
-
surface.style.maxHeight = saved.maxHeight;
|
|
333
|
-
};
|
|
334
|
-
}, [state.open, state.surface]);
|
|
335
331
|
|
|
336
332
|
/* Follow the shipped menu every frame; a no-op frame writes no state. */
|
|
337
333
|
React.useEffect(() => {
|
|
@@ -402,12 +398,10 @@ window.__ModuleLoader__.load({
|
|
|
402
398
|
const viewportHeight = window.innerHeight;
|
|
403
399
|
const floor = viewportHeight - COLUMN_FLOOR;
|
|
404
400
|
const ceiling = COLUMN_INSET;
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
);
|
|
409
|
-
const menuBottom = Math.min(rect.bottom, floor);
|
|
410
|
-
const top = Math.max(ceiling, menuBottom - columnHeight);
|
|
401
|
+
/* Bound this column to the viewport only. The shipped menu keeps its own
|
|
402
|
+
* height and length untouched, even when it renders past the window. */
|
|
403
|
+
const columnHeight = Math.max(120, Math.min(COLUMN_MAX_HEIGHT, floor - ceiling));
|
|
404
|
+
const top = clamp(rect.top, ceiling, Math.max(ceiling, floor - columnHeight));
|
|
411
405
|
|
|
412
406
|
const rightRoom = viewportWidth - COLUMN_INSET - (rect.right + COLUMN_GAP);
|
|
413
407
|
const left = rightRoom >= COLUMN_WIDTH
|
|
@@ -420,20 +414,27 @@ window.__ModuleLoader__.load({
|
|
|
420
414
|
const jump = group => {
|
|
421
415
|
setActiveId(group.id);
|
|
422
416
|
const surface = state.surface;
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
417
|
+
/* The host localizes the account group, so try every name it can wear. */
|
|
418
|
+
const names = [group.name, 'DeepSeek 账号', 'DeepSeek Account', t('vendor.account')]
|
|
419
|
+
.filter(name => typeof name === 'string' && name !== '');
|
|
420
|
+
if (revealVendor(surface, names)) return;
|
|
421
|
+
|
|
422
|
+
// Still on the shipped root pane: open its model list, then reveal.
|
|
426
423
|
const cell = surface?.querySelector('button[role="menuitem"]');
|
|
427
424
|
if (cell === null || cell === undefined) return;
|
|
428
425
|
cell.click();
|
|
426
|
+
|
|
429
427
|
let tries = 0;
|
|
430
428
|
const tick = () => {
|
|
431
|
-
if (revealVendor(surface,
|
|
429
|
+
if (revealVendor(surface, names)) return;
|
|
432
430
|
tries += 1;
|
|
433
|
-
if (tries >=
|
|
431
|
+
if (tries >= 20) return;
|
|
434
432
|
window.requestAnimationFrame(tick);
|
|
435
433
|
};
|
|
436
434
|
window.requestAnimationFrame(tick);
|
|
435
|
+
// The model pane can mount after an animation frame; one late pass
|
|
436
|
+
// covers a list that was still empty on the first frames.
|
|
437
|
+
window.setTimeout(() => { revealVendor(surface, names); }, 120);
|
|
437
438
|
};
|
|
438
439
|
|
|
439
440
|
return h('div', {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vendor-quick-switch",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Vendor-first quick model switching for DeepSeek Harness: a side index beside the shipped model menu, plus an in-menu drill-down mode. · DSH 厂商快速切换:模型菜单旁常驻厂商索引,点厂商直接跳转,不改造原插件。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|