dsh-vendor-quick-switch 1.0.2 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/client.js +64 -15
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
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
+
3
13
  ## 1.0.2
4
14
 
5
15
  - Revert the 1.0.1 attempt to bound the shipped menu. That change shortened the
package/client.js CHANGED
@@ -248,20 +248,62 @@ window.__ModuleLoader__.load({
248
248
  }
249
249
 
250
250
  /**
251
- * Bring one vendor's group heading into view inside the shipped list.
252
- * @returns true when the heading was found and scrolled to.
251
+ * The scrollable box the shipped list scrolls inside, if any.
252
+ * @returns the nearest vertically scrollable ancestor, or null.
253
253
  */
254
- function revealVendor(surface, name) {
255
- const list = listOf(surface);
256
- if (list === null) return false;
257
- const nodes = list.querySelectorAll('div,span');
258
- for (const node of nodes) {
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')) {
259
283
  if (node.children.length !== 0) continue;
260
- if ((node.textContent ?? '').trim() !== name) continue;
261
- node.scrollIntoView({ block: 'nearest' });
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));
262
303
  return true;
263
304
  }
264
- return false;
305
+ heading.scrollIntoView({ block: 'nearest', inline: 'nearest' });
306
+ return true;
265
307
  }
266
308
 
267
309
  /* ---------------------------------------------------------------- flyout */
@@ -372,20 +414,27 @@ window.__ModuleLoader__.load({
372
414
  const jump = group => {
373
415
  setActiveId(group.id);
374
416
  const surface = state.surface;
375
- const name = group.id === 'deepseek-account' ? t('vendor.account') : group.name;
376
- if (revealVendor(surface, name)) return;
377
- // The menu is on its root pane: open the shipped model list, then reveal.
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.
378
423
  const cell = surface?.querySelector('button[role="menuitem"]');
379
424
  if (cell === null || cell === undefined) return;
380
425
  cell.click();
426
+
381
427
  let tries = 0;
382
428
  const tick = () => {
383
- if (revealVendor(surface, name)) return;
429
+ if (revealVendor(surface, names)) return;
384
430
  tries += 1;
385
- if (tries >= 12) return;
431
+ if (tries >= 20) return;
386
432
  window.requestAnimationFrame(tick);
387
433
  };
388
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);
389
438
  };
390
439
 
391
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.2",
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",