dsh-ui-controller 0.1.0 → 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.
Files changed (4) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +43 -7
  3. package/client.js +514 -4
  4. package/package.json +46 -46
package/CHANGELOG.md CHANGED
@@ -2,6 +2,67 @@
2
2
 
3
3
  Notable changes to `dsh-ui-controller`.
4
4
 
5
+ ## 0.2.1 — 2026-11-15
6
+
7
+ ### Fixed
8
+
9
+ - **The More button now carries its count, and folding survives a reload.**
10
+ The launcher is found by its own `aria-label` under
11
+ `nav[class*="panelList"]` — the wide rail has no
12
+ `[data-shortcut-modal="sidebar"]` wrapper, so the previous lookup never
13
+ matched and the count was never painted (and the aria-label is left untouched).
14
+ - **Folded panels are actually hidden now.** Writing the host's pin only happens
15
+ while the menu is mounted, so a reload lost it; folding is now a
16
+ `display:none` pass over the live panel rows, matched by `aria-label` /
17
+ title, re-applied by a MutationObserver, and undone on teardown. A row we
18
+ cannot identify is left alone.
19
+ - **The More menu rows look host-drawn.** The row class list and fixed sizes are
20
+ sampled from a real host menu item at runtime (never a hardcoded hashed class);
21
+ our own class is used until one is on screen.
22
+
23
+ ### Removed
24
+
25
+ - **The two bulk buttons in the More menu.** Fold-all / unfold-all move to the
26
+ settings page only (`sidebarMore.foldAll`); the menu keeps one per-row toggle,
27
+ so the three conflicting controls the user saw cannot appear together.
28
+
29
+ ## 0.2.0 — 2026-11-15
30
+
31
+ ### Added
32
+
33
+ - **Left column folded behind the More button.** A new entry in
34
+ `sidebar.panellist.actions` renders rows for every panel: click jumps and
35
+ dismisses, a pin button per row folds/restores through the host's
36
+ `onPinnedChange`, and fold-all / unfold-all actions cover the whole list. The
37
+ folded ids are persisted (`dsh.uic.sidebarMore.v1`, `{ folded: string[] }`)
38
+ because the host's own pin state is in-memory only, cleaned against the live
39
+ panel set on every read, and replayed on every menu open / panel-list change.
40
+ `sidebarMore.foldAll` (default on) decides the shape for fresh installs. The
41
+ host's "More" launcher label gains a painted count (`更多 (3)`), only when the
42
+ number changes.
43
+ - `window.__UI_CONTROLLER__` additions: none — the menu is a slot entry, not an
44
+ API; the record lives under the normal settings storage.
45
+
46
+ ### Removed
47
+
48
+ - **Three-state settings rail** (0.1.1's `nav` field, its CSS, its settings-page
49
+ block and its i18n keys). The user chose the left column of the chat page over
50
+ the settings dialog, so the whole width block is gone; `SETTINGS_VERSION`
51
+ stays at 1 and the unknown-key preservation rules keep an old `nav` record
52
+ harmless if it was ever written.
53
+
54
+ ## 0.1.1 — 2026-11-14
55
+
56
+ ### Added
57
+
58
+ - **Three-state settings rail.** The left column of the settings dialog is now
59
+ `full` (188px), an `icon rail` (56px — labels hidden, each button keeps its
60
+ name as a tooltip) or `collapsed` (0px). It defaults to **following the host
61
+ sidebar**, using the same two readings the shipped code uses (an explicit
62
+ `data-sidebar-collapsed` marker, or a sidebar measured 1–64px wide); turn
63
+ following off to pick a state yourself. New settings field `nav`, stored with
64
+ the rest, with no settings-version bump.
65
+
5
66
  ## 0.1.0 — 2026-11-14
6
67
 
7
68
  First release with the inventory page.
package/README.md CHANGED
@@ -65,6 +65,28 @@ is missing, this is the plugin that answers that.
65
65
  5. **Presets.** Hide-marks and visual order can be captured as named presets, applied,
66
66
  and deleted; storage follows the same rules as `better-notice` (unknown keys are
67
67
  preserved, user changes are marked, upgrades do not overwrite).
68
+ 6. **Left column: folded panels behind the More button.** The session list on the
69
+ home page keeps only `plugins` and the "More" launcher in the left column; every
70
+ other panel is folded behind it. The host's own pin state is in-memory only, so
71
+ this plugin persists the folded ids itself (`dsh.uic.sidebarMore.v1` →
72
+ `{ folded: string[] }`) and replays them every time the menu opens or the panel
73
+ list changes. Folded ids are cleaned against the live panel set on every read,
74
+ and `sidebarMore.foldAll` (default **on**) decides the shape for fresh installs;
75
+ with it off, only the ids already in the record are folded. The "More" button
76
+ label gains a count (`更多 (3)`) painted in place, only when the number changes.
77
+ The menu itself is one entry in `sidebar.panellist.actions`: it renders one
78
+ row per panel with a single per-row toggle (folds / restores through the
79
+ host's `onPinnedChange` and mirrors the record). There are no bulk buttons in
80
+ the menu — `sidebarMore.foldAll` on the settings page is the only bulk switch.
81
+ Rows copy the look of a real host menu item at runtime (class list plus
82
+ `getComputedStyle` height / padding / font / radius / colour); nothing is
83
+ hardcoded, and if no host item is on screen our own class is used until one
84
+ appears. Folding itself is a `display:none` pass over
85
+ `nav[class*="panelList"] button[class*="panelRow"]`, matched by
86
+ `aria-label` / title, re-applied by a MutationObserver, and undone on
87
+ teardown; a row we cannot identify is left alone. Nothing else is touched: no
88
+ custom panel rows, no icon replacement, and the settings dialog's own nav
89
+ width is left alone.
68
90
 
69
91
  ## What it deliberately does **not** do
70
92
 
@@ -123,7 +145,7 @@ on it.
123
145
  ```js
124
146
  const api = window.__UI_CONTROLLER__;
125
147
 
126
- api.version // '0.1.0'
148
+ api.version // '0.2.1'
127
149
  api.catalog() // → [{ key, kind, scope, risk, purpose, registrantStatic, injectStatic }]
128
150
  api.catalogSummary() // → { total: 109, kinds: {...} }
129
151
  api.inventory() // → { rows, empty, totalSlots, occupiedSlots, hiddenCount,
@@ -164,7 +186,7 @@ Two sentences that belong in any answer about ordering:
164
186
  node --check client.js
165
187
  node --check index.js
166
188
  node --check test/classify.test.mjs
167
- node test/classify.test.mjs # expect: PASS — 26 groups
189
+ node test/classify.test.mjs # expect: PASS — 38 groups
168
190
  node ..\..\cangku\tmp\261114_gate_ui_controller.mjs # static gate, separate script
169
191
  ```
170
192
 
@@ -178,7 +200,12 @@ with the old `order` alias, and the zh/en dictionary parity. The grouped page ha
178
200
  its own groups: entries group under their slot with empty seats in their own zone,
179
201
  the three filters count what they keep, folding starts closed and survives a
180
202
  re-render, and the static fallback still draws slot heads when no live snapshot is
181
- available.
203
+ available. The sidebar-more behaviour has groups of its own: replay folds only
204
+ what the record and `foldAll` ask for; the count label repaints through the
205
+ `nav.panelList` ancestor and only when its text changes; folding hides the live
206
+ rows and restores them on the way out, leaving rows it cannot identify alone; and
207
+ the menu borrows a live host item's class list and computed size instead of any
208
+ hardcoded name.
182
209
 
183
210
  ## Known limits
184
211
 
@@ -191,16 +218,25 @@ available.
191
218
  the reason instead of a control that does nothing.
192
219
  3. **Hiding is not unloading.** A hidden entry still runs. If it is expensive, this
193
220
  plugin is not the tool — talk to the plugin's author.
194
- 3. **Visual order is CSS only.** It applies inside one flex/grid parent; a child of
221
+ 4. **Visual order is CSS only.** It applies inside one flex/grid parent; a child of
195
222
  a `display: contents` or block parent is skipped, and nothing outside our bound
196
223
  elements is touched.
197
- 4. **Hash class names change every build.** Nothing here keys off them; only
224
+ 5. **Hash class names change every build.** Nothing here keys off them; only
198
225
  `data-*`, `role`, `aria-label`, `name` and `id` are used to build selectors.
199
- 5. **`root` is off limits.** Listing it is fine; registering into it is not.
200
- 6. **`registrant` is an inference.** The live value (`entry.registrant`) is only
226
+ 6. **`root` is off limits.** Listing it is fine; registering into it is not.
227
+ 7. **`registrant` is an inference.** The live value (`entry.registrant`) is only
201
228
  readable at runtime for entries present in the registry; the column shows the
202
229
  static proxy scanned out of the shipped bundles, so an entry registered by code
203
230
  that ships no literal key can read as "—".
231
+ 8. **The More menu coexists with other action entries.** The host renders every
232
+ registration of `sidebar.panellist.actions` into the same menu; when another
233
+ plugin (for example the codex-ui skin on the desktop profile) also contributes
234
+ there, the two menus share the popup. This plugin does not remove or reorder
235
+ other entries.
236
+ 9. **Replay is best-effort against the host's in-memory pins.** The host keeps its
237
+ own `unpinned` list only for the session; a folded id is re-hidden when the host
238
+ honours the pin callback, and a host restart resets the host list while this
239
+ plugin's record is replayed on the next menu open or panel-list change.
204
240
 
205
241
  ## License
206
242
 
package/client.js CHANGED
@@ -27,7 +27,7 @@
27
27
  * slots sort by `priority → order`, everything else by `priority` alone.
28
28
  */
29
29
 
30
- const VERSION = '0.1.0';
30
+ const VERSION = '0.2.1';
31
31
 
32
32
  const NS = 'uiController';
33
33
  const SECTION_ID = 'ui-controller';
@@ -76,6 +76,13 @@ const PAGE_CSS = [
76
76
  '.uic-filterGroup{display:inline-flex;gap:2px}',
77
77
  '.uic-filter{height:26px;padding:0 8px;border-radius:6px;font-size:11px;cursor:pointer;border:1px solid var(--dsw-alias-border-l4);background:transparent;color:var(--dsw-alias-label-secondary)}',
78
78
  '.uic-filter[data-on="true"]{border-color:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-state-business-primary)}',
79
+ '.uic-sidebarMore{display:flex;flex-direction:column;gap:6px;margin-top:12px;padding-top:10px;border-top:1px solid var(--dsw-alias-border-l2)}',
80
+ '.uic-sidebarMoreRow{display:flex;align-items:center;gap:8px;font-size:13px;line-height:20px}',
81
+ '.uic-moreRow{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:4px 2px;font-size:13px;line-height:20px}',
82
+ '.uic-moreRow + .uic-moreRow{border-top:1px solid var(--dsw-alias-border-l2)}',
83
+ '.uic-moreRowName{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
84
+ '.uic-moreAction{flex:none;padding:2px 8px;font-size:12px;border:1px solid var(--dsw-alias-border-l4);border-radius:6px;cursor:pointer}',
85
+ '.uic-moreAction:hover{background:var(--dsw-alias-bg-layer-2)}',
79
86
  '.uic-zone{border-top:.5px solid var(--dsw-alias-border-l2);padding:2px 0}',
80
87
  '.uic-zoneHead{display:flex;align-items:center;gap:6px;width:100%;height:32px;padding:0 2px;border:0;background:transparent;color:var(--dsw-alias-label-primary);cursor:pointer;text-align:left;font-size:12px;font-weight:600}',
81
88
  '.uic-zoneName{flex:none}',
@@ -100,6 +107,68 @@ const PAGE_CSS = [
100
107
  '@container (max-width:620px){.uic-slotHead{grid-template-columns:14px 12px minmax(0,1fr) 46px minmax(0,1fr);height:auto;min-height:44px}.uic-slotHead .uic-kind{display:none}.uic-entry{grid-template-columns:minmax(0,1fr) auto auto;min-height:44px}.uic-entry .uic-entryLive,.uic-entry .uic-num{display:none}}',
101
108
  ].join('\n');
102
109
 
110
+ /* ------------------------------------------------- settings page left rail */
111
+
112
+
113
+ const SIDEBAR_MORE_KEY = 'dsh.uic.sidebarMore.v1';
114
+ const SIDEBAR_MORE_SLOT = 'sidebar.panellist.actions';
115
+ const SIDEBAR_MORE_ID = 'ui-controller.sidebar-more';
116
+ const SIDEBAR_MORE_ORDER = 0;
117
+ const SIDEBAR_MORE_MODAL = '[data-shortcut-modal="sidebar"]';
118
+ const MORE_TITLES = new Set(['更多', 'More']);
119
+
120
+ /**
121
+ * The folded record: which panel ids the More menu currently hides.
122
+ * The host keeps its pins in memory only (dsh-client-ui-sidebar
123
+ * createPanelPins), so a reload would put every panel back outside;
124
+ * this record is what a reload replays.
125
+ */
126
+ function readSidebarMore(storage) {
127
+ const store = storage ?? null;
128
+ if (store === null || typeof store.getItem !== 'function') return { folded: [] };
129
+ try {
130
+ const raw = store.getItem(SIDEBAR_MORE_KEY);
131
+ if (raw === null || raw === undefined || raw === '') return { folded: [] };
132
+ const parsed = JSON.parse(raw);
133
+ if (isPlainObject(parsed) === false || Array.isArray(parsed.folded) === false) return { folded: [] };
134
+ return { folded: parsed.folded.filter((id) => typeof id === 'string' && id !== '') };
135
+ } catch {
136
+ return { folded: [] };
137
+ }
138
+ }
139
+
140
+ function writeSidebarMore(storage, folded) {
141
+ const store = storage ?? null;
142
+ if (store === null || typeof store.setItem !== 'function') return;
143
+ try {
144
+ store.setItem(SIDEBAR_MORE_KEY, JSON.stringify({ folded }));
145
+ } catch {
146
+ /* a full quota must not take the page down */
147
+ }
148
+ }
149
+
150
+ /** Folded ids that still name a live panel; the rest are stale and dropped. */
151
+ function cleanFolded(folded, panels) {
152
+ const live = new Set(panels);
153
+ return folded.filter((id) => live.has(id));
154
+ }
155
+
156
+ /**
157
+ * What a fresh install looks like: with foldAll on, every panel except
158
+ * plugins goes behind the More button (the shape the user asked for).
159
+ * Off means nothing folds — but the stored record is never erased here, so
160
+ * turning the switch back on restores it (see the menu's replay).
161
+ */
162
+ function computeFold(panels, settings) {
163
+ if (settings?.sidebarMore?.foldAll === true) return panels.filter((id) => id !== 'plugins');
164
+ return [];
165
+ }
166
+
167
+ /** The More launcher's text: "更多 (3)", and the bare label at zero. */
168
+ function moreLabel(base, count) {
169
+ return count > 0 ? base + ' (' + count + ')' : base;
170
+ }
171
+
103
172
  const PRESET_NAME_MAX = 40;
104
173
  const SELECTOR_MAX = 240;
105
174
  const LOCATOR_LIMIT = 400;
@@ -256,6 +325,7 @@ function defaultSettings() {
256
325
  visualOrder: {},
257
326
  presets: {},
258
327
  activePreset: null,
328
+ sidebarMore: { foldAll: true },
259
329
  };
260
330
  }
261
331
 
@@ -343,6 +413,7 @@ function sanitizePresets(raw) {
343
413
  return next;
344
414
  }
345
415
 
416
+ /** `follow` defaults to on; the three-way choice only matters when it is off. */
346
417
  function sanitizeSettings(raw) {
347
418
  const base = defaultSettings();
348
419
  if (isPlainObject(raw) === false) return base;
@@ -352,6 +423,7 @@ function sanitizeSettings(raw) {
352
423
  next.visualOrder = sanitizeVisualOrder(raw.visualOrder ?? raw.order);
353
424
  next.presets = sanitizePresets(raw.presets);
354
425
  next.activePreset = typeof raw.activePreset === 'string' && hasOwn(next.presets, raw.activePreset) ? raw.activePreset : null;
426
+ next.sidebarMore = isPlainObject(raw.sidebarMore) ? { foldAll: raw.sidebarMore.foldAll !== false } : { foldAll: true };
355
427
  return next;
356
428
  }
357
429
 
@@ -439,6 +511,7 @@ function patchSettings(patch) {
439
511
  visualOrder,
440
512
  presets: isPlainObject(patch.presets) ? patch.presets : base.presets,
441
513
  activePreset: hasOwn(patch, 'activePreset') ? patch.activePreset : base.activePreset,
514
+ sidebarMore: { ...(isPlainObject(base.sidebarMore) ? base.sidebarMore : {}), ...(isPlainObject(patch.sidebarMore) ? patch.sidebarMore : {}) },
442
515
  });
443
516
  }
444
517
 
@@ -974,6 +1047,13 @@ const ZH = {
974
1047
  'settings.filter.unbound': '未绑定',
975
1048
  'settings.filterCount': '{slots} 槽 · {entries} entry',
976
1049
  'settings.noMatch': '没有匹配的座位。',
1050
+ 'settings.sidebarMore.title': '左栏「更多」',
1051
+ 'settings.sidebarMore.hint': '新装即把除「插件」外的面板都收进左侧「更多 (N)」;关掉 = 全部放回外面(记录保留,下次开回来还原)。',
1052
+ 'settings.sidebarMore.foldAll': '新装即全部折叠',
1053
+ 'settings.sidebarMore.fold': '收进更多',
1054
+ 'settings.sidebarMore.unfold': '放到外面',
1055
+ 'settings.sidebarMore.foldAllAction': '全部收进更多',
1056
+ 'settings.sidebarMore.unfoldAllAction': '全部放回外面',
977
1057
  };
978
1058
 
979
1059
  const EN = {
@@ -1028,6 +1108,13 @@ const EN = {
1028
1108
  'settings.filter.unbound': 'Unbound',
1029
1109
  'settings.filterCount': '{slots} slots · {entries} entries',
1030
1110
  'settings.noMatch': 'No slot matches.',
1111
+ 'settings.sidebarMore.title': 'Sidebar More',
1112
+ 'settings.sidebarMore.hint': 'A fresh install folds every panel except Plugins behind the More (N) button; off puts everything back outside (the record is kept, so turning it on restores it).',
1113
+ 'settings.sidebarMore.foldAll': 'Fold everything on a fresh install',
1114
+ 'settings.sidebarMore.fold': 'Fold into More',
1115
+ 'settings.sidebarMore.unfold': 'Show outside',
1116
+ 'settings.sidebarMore.foldAllAction': 'Fold all into More',
1117
+ 'settings.sidebarMore.unfoldAllAction': 'Put all back outside',
1031
1118
  };
1032
1119
 
1033
1120
  const DICTS = { zh: ZH, en: EN };
@@ -1061,12 +1148,18 @@ function node(tagName, props, children) {
1061
1148
 
1062
1149
  function injectStyle(doc) {
1063
1150
  if (doc === null || doc === undefined) return;
1151
+ const css = HIDE_CSS + '\n' + PAGE_CSS;
1064
1152
  const existing = typeof doc.getElementById === 'function' ? doc.getElementById(STYLE_ID) : null;
1065
- if (existing !== null && existing !== undefined) return;
1153
+ /* A reloaded plugin can find the stylesheet its previous instance left behind.
1154
+ Rewriting it keeps the three rule groups from drifting apart. */
1155
+ if (existing !== null && existing !== undefined) {
1156
+ if (existing.textContent !== css) existing.textContent = css;
1157
+ return;
1158
+ }
1066
1159
  const style = doc.createElement('style');
1067
1160
  style.id = STYLE_ID;
1068
1161
  style.setAttribute('data-uic', 'style');
1069
- style.textContent = HIDE_CSS + '\n' + PAGE_CSS;
1162
+ style.textContent = css;
1070
1163
  const head = doc.head ?? doc.documentElement;
1071
1164
  if (head !== null && head !== undefined) head.appendChild(style);
1072
1165
  }
@@ -1527,6 +1620,22 @@ function settingsPage(props) {
1527
1620
 
1528
1621
  const presetNames = Object.keys(state.presets).sort();
1529
1622
 
1623
+ const foldAllOn = state.sidebarMore?.foldAll !== false;
1624
+ const sidebarMoreBlock = node('div', { key: 'sidebarMore', className: 'uic-sidebarMore', 'data-uic-sidebar-more': '1' }, [
1625
+ node('h3', { key: 'h', className: 'uic-h3' }, t('settings.sidebarMore.title')),
1626
+ node('p', { key: 'hint', className: 'uic-dim' }, t('settings.sidebarMore.hint')),
1627
+ node('label', { key: 'fold', className: 'uic-sidebarMoreRow' }, [
1628
+ node('input', {
1629
+ key: 'box',
1630
+ type: 'checkbox',
1631
+ 'data-uic-sidebar-more-foldall': foldAllOn ? 'true' : 'false',
1632
+ checked: foldAllOn,
1633
+ onChange: (event) => commit({ ...state, sidebarMore: { ...(isPlainObject(state.sidebarMore) ? state.sidebarMore : {}), foldAll: event.target.checked === true } }),
1634
+ }),
1635
+ node('span', { key: 'text' }, t('settings.sidebarMore.foldAll')),
1636
+ ]),
1637
+ ]);
1638
+
1530
1639
  return node('div', { className: 'uic-page', 'data-uic-page': '1' }, [
1531
1640
  node('h2', { key: 'title', className: 'uic-title' }, t('settings.title')),
1532
1641
  node('p', { key: 'lead', className: 'uic-lead' }, t('settings.lead')),
@@ -1610,10 +1719,324 @@ function settingsPage(props) {
1610
1719
  )),
1611
1720
  node('p', { key: 'order-hint', className: 'uic-dim' }, t('settings.orderHint')),
1612
1721
  node('p', { key: 'order-hint-2', className: 'uic-dim' }, t('settings.orderHint2')),
1722
+ sidebarMoreBlock,
1613
1723
  node('button', { key: 'reset', className: 'uic-btn uic-btn-quiet', type: 'button', 'data-uic-reset': '1', onClick: onReset }, armed ? t('settings.resetOnce') : t('settings.reset')),
1614
1724
  ]);
1615
1725
  }
1616
1726
 
1727
+
1728
+ /* -------------------------------------------------- sidebar More menu */
1729
+
1730
+ /** Module state shared by the menu and the replay paths. */
1731
+ let sidebarWrite = null;
1732
+ let sidebarPanels = [];
1733
+ let sidebarReplayQueued = false;
1734
+
1735
+ /** Elements this session hid and the launcher title it rewrote; both are restored on teardown. */
1736
+ const moreTouched = new Map();
1737
+ const moreTitle = { title: null, original: null };
1738
+
1739
+ /** Resolve a panel entry's label the way the host does (thunk first, then string, then id). */
1740
+ function entryLabelOf(entry) {
1741
+ const raw = entry?.options?.label ?? entry?.label;
1742
+ if (typeof raw === 'function') {
1743
+ try {
1744
+ const value = raw();
1745
+ if (typeof value === 'string' && value !== '') return value;
1746
+ } catch {
1747
+ /* a locale-bound thunk may throw before the host binds it; fall through */
1748
+ }
1749
+ }
1750
+ if (typeof raw === 'string' && raw !== '') return raw;
1751
+ return String(entry?.options?.id ?? entry?.id ?? '');
1752
+ }
1753
+
1754
+ /** ids that should be behind the More button right now (foldAll wins, plugins never folds). */
1755
+ function foldedIdsOf(panels, settings, storageRef) {
1756
+ const ids = panels.map((panel) => panel.id);
1757
+ return desiredFoldIds(
1758
+ panels.map((panel) => ({ id: panel.id })),
1759
+ settings,
1760
+ storageRef,
1761
+ ).filter((id) => id !== 'plugins');
1762
+ }
1763
+
1764
+ /**
1765
+ * Hide the panel rows that belong behind the More button. The host keeps its
1766
+ * pins in memory only and re-renders rows on every store change, so this pass
1767
+ * is idempotent, re-applied by the observer after every host redraw, and
1768
+ * undone on teardown. Rows are matched by the same aria-label / title the host
1769
+ * renders; a row we cannot identify is left alone (silent skip).
1770
+ */
1771
+ function applyFoldState(doc, panels, settings, storageRef, touched) {
1772
+ if (doc === null || typeof doc.querySelectorAll !== 'function') return;
1773
+ const folded = new Set(foldedIdsOf(panels, settings, storageRef));
1774
+ const byLabel = new Map();
1775
+ for (const panel of panels) byLabel.set(panel.label, panel.id);
1776
+ let rows = [];
1777
+ try {
1778
+ rows = Array.from(doc.querySelectorAll('nav[class*="panelList"] button[class*="panelRow"]'));
1779
+ } catch {
1780
+ rows = [];
1781
+ }
1782
+ for (const row of rows) {
1783
+ const label = row.getAttribute?.('aria-label') ?? '';
1784
+ let titleText = '';
1785
+ if (typeof row.querySelector === 'function') {
1786
+ try {
1787
+ const title = row.querySelector('span[class*="panelTitle"]');
1788
+ if (title !== null && title !== undefined) titleText = title.textContent ?? '';
1789
+ } catch {
1790
+ titleText = '';
1791
+ }
1792
+ }
1793
+ const id = byLabel.get(label) ?? byLabel.get(titleText) ?? null;
1794
+ if (id === null) continue;
1795
+ const hide = folded.has(id);
1796
+ const current = row.style?.display ?? '';
1797
+ if (hide === true && current !== 'none') {
1798
+ if (touched.has(row) === false) touched.set(row, current);
1799
+ row.style.display = 'none';
1800
+ } else if (hide === false && touched.has(row) === true) {
1801
+ row.style.display = touched.get(row);
1802
+ touched.delete(row);
1803
+ }
1804
+ }
1805
+ }
1806
+
1807
+ /**
1808
+ * Sample a real host menu item so our rows can borrow its look: the class list
1809
+ * is copied at runtime (never hardcoded) and the fixed dimensions are read from
1810
+ * getComputedStyle. Returns null when the menu is not open yet or the host item
1811
+ * is missing — callers fall back to their own class until it appears.
1812
+ */
1813
+ function sampleMoreItem(doc) {
1814
+ if (doc === null || typeof doc.querySelectorAll !== 'function') return null;
1815
+ const view = doc.defaultView;
1816
+ if (view === undefined || view === null || typeof view.getComputedStyle !== 'function') return null;
1817
+ let menu = null;
1818
+ try {
1819
+ menu = doc.querySelector('[class*="moreMenu"]');
1820
+ } catch {
1821
+ menu = null;
1822
+ }
1823
+ if (menu === null || menu === undefined) return null;
1824
+ let host = null;
1825
+ try {
1826
+ host =
1827
+ Array.from(menu.querySelectorAll('button')).find((button) => {
1828
+ const cls = button.getAttribute?.('class') ?? '';
1829
+ return cls.includes('uic-') === false;
1830
+ }) ?? null;
1831
+ } catch {
1832
+ host = null;
1833
+ }
1834
+ if (host === null) return null;
1835
+ const cs = view.getComputedStyle(host);
1836
+ if (cs === null || cs === undefined) return null;
1837
+ const pick = (name) => {
1838
+ if (typeof cs.getPropertyValue === 'function') return cs.getPropertyValue(name) ?? '';
1839
+ return cs[name] ?? '';
1840
+ };
1841
+ return {
1842
+ className: host.getAttribute?.('class') ?? '',
1843
+ style: {
1844
+ height: pick('height'),
1845
+ lineHeight: pick('line-height'),
1846
+ paddingLeft: pick('padding-left'),
1847
+ paddingRight: pick('padding-right'),
1848
+ fontSize: pick('font-size'),
1849
+ borderRadius: pick('border-radius'),
1850
+ color: pick('color'),
1851
+ },
1852
+ };
1853
+ }
1854
+
1855
+ /** ids currently behind the More button: foldAll wins, else the record. */
1856
+ function desiredFoldIds(entries, settings, storage) {
1857
+ const ids = entries.map((entry) => entry.id);
1858
+ if (settings?.sidebarMore?.foldAll === true) return computeFold(ids, settings);
1859
+ return cleanFolded(readSidebarMore(storage).folded, ids);
1860
+ }
1861
+
1862
+ /**
1863
+ * The actions a replay would need to take: fold every live entry that is
1864
+ * currently pinned but should be behind More. The host's setPinned is
1865
+ * idempotent (it no-ops on an unchanged pin), so replay is safe to repeat.
1866
+ */
1867
+ function sidebarMoreReplay(entries, settings, storage) {
1868
+ const wanted = new Set(desiredFoldIds(entries, settings, storage));
1869
+ return entries.filter((entry) => entry.pinned === true && wanted.has(entry.id)).map((entry) => entry.id);
1870
+ }
1871
+
1872
+ /** The count the launcher shows: folded ids that still name a live panel. */
1873
+ function sidebarMoreCount(panels, settings, storage) {
1874
+ if (settings?.sidebarMore?.foldAll === true) return computeFold(panels, settings).length;
1875
+ return cleanFolded(readSidebarMore(storage).folded, panels).length;
1876
+ }
1877
+
1878
+ /** Write one panel's pin through the host callback and keep the record honest. */
1879
+ function writeSidebarPin(id, pinned, entries, settings, storage) {
1880
+ if (sidebarWrite === null) return;
1881
+ sidebarWrite(id, pinned);
1882
+ const ids = entries.map((entry) => entry.id);
1883
+ const record = cleanFolded(readSidebarMore(storage).folded, ids);
1884
+ const next = pinned ? record.filter((entry) => entry !== id) : record.includes(id) ? record : [...record, id];
1885
+ writeSidebarMore(storage, next);
1886
+ }
1887
+
1888
+ /**
1889
+ * The More menu rows. Rendered by the host inside its own Menu portal; we own
1890
+ * nothing but these rows. position:fixed is forbidden here (the portal may
1891
+ * be anywhere); the host handles placement.
1892
+ */
1893
+ function SidebarMoreMenu(props) {
1894
+ const entries = Array.isArray(props.entries) ? props.entries : [];
1895
+ const onOpen = typeof props.onOpen === 'function' ? props.onOpen : () => {};
1896
+ const onDismiss = typeof props.onDismiss === 'function' ? props.onDismiss : () => {};
1897
+ const write = typeof props.onPinnedChange === 'function' ? props.onPinnedChange : null;
1898
+ const t = translator(localeScope());
1899
+ sidebarWrite = write;
1900
+ sidebarPanels = entries.map((entry) => entry.id);
1901
+ const settings = readSettings();
1902
+ const storageRef = storage();
1903
+ const record = readSidebarMore(storageRef).folded;
1904
+ const ids = entries.map((entry) => entry.id);
1905
+ const doc = typeof document === 'undefined' ? null : document;
1906
+ const [sampled, setSampled] = React.useState(null);
1907
+
1908
+ /* First render: fold whatever the record / foldAll asks for. The host
1909
+ re-renders the menu with the new pins, and its guard makes the second
1910
+ pass a no-op, so deferring to a microtask keeps us out of the render
1911
+ cycle. */
1912
+ if (write !== null && sidebarReplayQueued === false) {
1913
+ sidebarReplayQueued = true;
1914
+ if (typeof setTimeout === 'function') {
1915
+ setTimeout(() => {
1916
+ for (const id of sidebarMoreReplay(entries, readSettings(), storageRef)) write(id, false);
1917
+ }, 0);
1918
+ } else {
1919
+ for (const id of sidebarMoreReplay(entries, settings, storageRef)) write(id, false);
1920
+ }
1921
+ }
1922
+
1923
+ /* The host menu items live in the same list as our rows; borrowing their
1924
+ class list and fixed dimensions makes every row look host-drawn. The
1925
+ sample is taken a tick later so the official items exist by then. */
1926
+ if (sampled === null && typeof setTimeout === 'function') {
1927
+ setTimeout(() => setSampled(sampleMoreItem(doc)), 0);
1928
+ }
1929
+
1930
+ /**
1931
+ * Flip one panel. `folded` is the state the row is showing: true means the
1932
+ * panel is behind More right now, which may be foldAll talking rather than
1933
+ * the record — so freeing it also has to switch foldAll off, and folding it
1934
+ * back is a plain record write. Both branches leave the record consistent
1935
+ * with what the row will show on the next pass.
1936
+ */
1937
+ const flipPanel = (id, folded) => {
1938
+ const ids = entries.map((item) => item.id);
1939
+ if (folded === false) {
1940
+ writeSidebarPin(id, false, entries, settings, storageRef);
1941
+ return;
1942
+ }
1943
+ const onlyOutside = ids.filter((item) => item !== 'plugins' && item !== id);
1944
+ /* Ask the host to put this row outside first — folding is derived from
1945
+ foldAll and the record, so skipping the host call leaves the panel
1946
+ hidden by the host's own pin state and it never comes back. */
1947
+ writeSidebarPin(id, true, entries, settings, storageRef);
1948
+ writeSettings({ ...readSettings(), sidebarMore: { foldAll: false } });
1949
+ writeSidebarMore(storageRef, cleanFolded(onlyOutside, ids));
1950
+ };
1951
+
1952
+ const wanted = new Set(desiredFoldIds(entries, settings, storageRef));
1953
+ const rowClass = sampled !== null && sampled.className !== '' ? sampled.className : 'uic-moreRow';
1954
+ const rowStyle = sampled !== null
1955
+ ? { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px', width: '100%', boxSizing: 'border-box' }
1956
+ : null;
1957
+
1958
+ return node('div', { key: 'more', 'data-uic-sidebar-more-menu': '1' }, [
1959
+ ...entries.map((entry) => {
1960
+ const folded = wanted.has(entry.id);
1961
+ return node('button', {
1962
+ key: entry.id,
1963
+ type: 'button',
1964
+ className: rowClass,
1965
+ style: rowStyle,
1966
+ 'data-uic-more-row': entry.id,
1967
+ onClick: () => { onOpen(entry.id); onDismiss(); },
1968
+ }, [
1969
+ node('span', { key: 'name', className: 'uic-moreRowName' }, entry.label),
1970
+ node('span', {
1971
+ key: 'toggle',
1972
+ className: 'uic-moreToggle',
1973
+ 'data-uic-more-pin': entry.id,
1974
+ role: 'button',
1975
+ tabIndex: 0,
1976
+ onClick: (event) => {
1977
+ event.stopPropagation();
1978
+ flipPanel(entry.id, folded);
1979
+ },
1980
+ onKeyDown: (event) => {
1981
+ if (event.key === 'Enter' || event.key === ' ') {
1982
+ event.preventDefault();
1983
+ event.stopPropagation();
1984
+ flipPanel(entry.id, folded);
1985
+ }
1986
+ },
1987
+ }, folded === true ? t('settings.sidebarMore.unfold') : t('settings.sidebarMore.fold')),
1988
+ ]);
1989
+ }),
1990
+ ]);
1991
+ }
1992
+
1993
+ /**
1994
+ * Paint the folded count onto the host's launcher row: find the More button by
1995
+ * its own aria-label, then rewrite only the title span. The aria-label stays
1996
+ * untouched (screen readers keep "更多"); a missing button is skipped
1997
+ * silently.
1998
+ */
1999
+ function paintMoreCount(doc, panels, settings, storageRef, titleInfo) {
2000
+ if (doc === null || typeof doc.querySelectorAll !== 'function') return;
2001
+ let candidates = [];
2002
+ try {
2003
+ candidates = Array.from(doc.querySelectorAll('button[aria-label="更多"], button[aria-label="More"]'));
2004
+ } catch {
2005
+ candidates = [];
2006
+ }
2007
+ const launcher = candidates.find((button) => {
2008
+ if (button.getAttribute === undefined) return false;
2009
+ if (MORE_TITLES.has(button.getAttribute('aria-label')) === false) return false;
2010
+ let parent = button.parentElement ?? null;
2011
+ while (parent !== null) {
2012
+ const cls = parent.getAttribute?.('class') ?? '';
2013
+ if (cls.includes('panelList')) return true;
2014
+ parent = parent.parentElement;
2015
+ }
2016
+ return false;
2017
+ });
2018
+ if (launcher === undefined) return;
2019
+ let title = null;
2020
+ if (typeof launcher.querySelector === 'function') {
2021
+ try {
2022
+ title = launcher.querySelector('span[class*="panelTitle"]');
2023
+ } catch {
2024
+ title = null;
2025
+ }
2026
+ }
2027
+ if (title === null || title === undefined) return;
2028
+ if (titleInfo.title !== null && titleInfo.title !== title) return;
2029
+ if (titleInfo.title === null) {
2030
+ titleInfo.title = title;
2031
+ titleInfo.original = title.textContent ?? '';
2032
+ }
2033
+ const count = sidebarMoreCount(panels.map((panel) => panel.id), settings, storageRef);
2034
+ /** The aria-label is the stable base; the title may already carry a painted count. */
2035
+ const base = launcher.getAttribute('aria-label') ?? '';
2036
+ const wanted = moreLabel(base, count);
2037
+ if (title.textContent !== wanted) title.textContent = wanted;
2038
+ }
2039
+
1617
2040
  function apply(ctx) {
1618
2041
  const doc = typeof document === 'undefined' ? null : document;
1619
2042
  const slots = ctx.get('slots');
@@ -1625,6 +2048,61 @@ function apply(ctx) {
1625
2048
 
1626
2049
  const inventory = () => slotRows(entriesOf, readSettings(), runtimeCatalog(slots));
1627
2050
 
2051
+ const sidebarPanelsOf = () =>
2052
+ entriesOf('sidebar.panellist')
2053
+ .map((entry) => ({ id: String(entry?.options?.id ?? ''), label: entryLabelOf(entry) }))
2054
+ .filter((panel) => panel.id !== '');
2055
+ const paintCount = () => paintMoreCount(doc, sidebarPanelsOf(), readSettings(), storage(), moreTitle);
2056
+ const applyFold = () => applyFoldState(doc, sidebarPanelsOf(), readSettings(), storage(), moreTouched);
2057
+
2058
+ /* One slot only, and only after it is declared: the inject callback itself
2059
+ only fires once the host declares the slot, so the guard is belt and
2060
+ braces (dsh-plugin-dev §13). */
2061
+ ctx.effect(
2062
+ () =>
2063
+ ctx.slots.inject(SIDEBAR_MORE_SLOT, () => {
2064
+ if (typeof ctx.slots.spec === 'function' && ctx.slots.spec(SIDEBAR_MORE_SLOT) === undefined) return () => {};
2065
+ return ctx.slots.register(
2066
+ {
2067
+ name: SIDEBAR_MORE_SLOT,
2068
+ id: SIDEBAR_MORE_ID,
2069
+ order: SIDEBAR_MORE_ORDER,
2070
+ locale: NS,
2071
+ label: () => t('settings.sidebarMore.title'),
2072
+ },
2073
+ (props) => h(SidebarMoreMenu, props),
2074
+ );
2075
+ }),
2076
+ 'ui-controller: sidebar more',
2077
+ );
2078
+
2079
+ /* Host pins are memory-only; a reload loses them. The record replays through
2080
+ the write entry captured by the menu (null until the menu has rendered
2081
+ once), so subscribe on every panellist change and try. */
2082
+ if (typeof slots?.subscribe === 'function') {
2083
+ ctx.effect(() => slots.subscribe('sidebar.panellist', () => {
2084
+ const write = sidebarWrite;
2085
+ if (write === null) return;
2086
+ const settings = readSettings();
2087
+ const entries = sidebarPanels.map((panel) => ({ id: panel.id, pinned: true }));
2088
+ for (const id of sidebarMoreReplay(entries, settings, storage())) write(id, false);
2089
+ }), 'ui-controller: sidebar more replay');
2090
+ }
2091
+
2092
+ /* Count label: an observer catches the launcher appearing/re-rendering, and
2093
+ the 2s pass below is the fallback. */
2094
+ let moreObserver = null;
2095
+ if (doc !== null && typeof doc.body?.addEventListener === 'function' && typeof MutationObserver === 'function') {
2096
+ try {
2097
+ moreObserver = new MutationObserver(() => { paintCount(); applyFold(); });
2098
+ moreObserver.observe(doc.body, { childList: true, subtree: true });
2099
+ } catch {
2100
+ moreObserver = null;
2101
+ }
2102
+ }
2103
+ paintCount();
2104
+ applyFold();
2105
+
1628
2106
  let pickHandler = null;
1629
2107
 
1630
2108
  const applyHidden = () => {
@@ -1670,6 +2148,17 @@ function apply(ctx) {
1670
2148
 
1671
2149
  injectStyle(doc);
1672
2150
  ctx.effect(() => () => {
2151
+ if (moreObserver !== null && typeof moreObserver.disconnect === 'function') moreObserver.disconnect();
2152
+ for (const [row, original] of moreTouched) {
2153
+ if (row.style !== undefined) row.style.display = original;
2154
+ }
2155
+ moreTouched.clear();
2156
+ if (moreTitle.title !== null) moreTitle.title.textContent = moreTitle.original;
2157
+ moreTitle.title = null;
2158
+ moreTitle.original = null;
2159
+ sidebarWrite = null;
2160
+ sidebarPanels = [];
2161
+ sidebarReplayQueued = false;
1673
2162
  stopPicking();
1674
2163
  removeStyle(doc);
1675
2164
  if (doc !== null) {
@@ -1681,8 +2170,11 @@ function apply(ctx) {
1681
2170
  const ordered = [];
1682
2171
 
1683
2172
  const applyAll = () => {
2173
+ const current = readSettings();
1684
2174
  applyHidden();
1685
- applyVisualOrder(doc, readSettings(), ordered);
2175
+ applyVisualOrder(doc, current, ordered);
2176
+ paintCount();
2177
+ applyFold();
1686
2178
  };
1687
2179
 
1688
2180
  applyAll();
@@ -1795,6 +2287,24 @@ window.__ModuleLoader__.load({
1795
2287
  isOpen,
1796
2288
  toggleOpen,
1797
2289
  resetOpen,
2290
+ SIDEBAR_MORE_KEY,
2291
+ SIDEBAR_MORE_SLOT,
2292
+ SIDEBAR_MORE_ID,
2293
+ SIDEBAR_MORE_MODAL,
2294
+ readSidebarMore,
2295
+ writeSidebarMore,
2296
+ cleanFolded,
2297
+ computeFold,
2298
+ moreLabel,
2299
+ sidebarMoreReplay,
2300
+ sidebarMoreCount,
2301
+ desiredFoldIds,
2302
+ foldedIdsOf,
2303
+ entryLabelOf,
2304
+ applyFoldState,
2305
+ sampleMoreItem,
2306
+ paintMoreCount,
2307
+ SidebarMoreMenu,
1798
2308
  DICTS,
1799
2309
  };
1800
2310
  },
package/package.json CHANGED
@@ -1,46 +1,46 @@
1
- {
2
- "name": "dsh-ui-controller",
3
- "version": "0.1.0",
4
- "description": "Placeholder release: inspect and control the UI that other plugins register into DeepSeek Harness slots (visibility, order, mirrored entries). The real implementation ships in a later version.",
5
- "license": "MIT",
6
- "author": {
7
- "name": "MeruSu"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/MeruSu/dsh-ui-controller.git"
12
- },
13
- "keywords": [
14
- "dsh",
15
- "deepseek-harness",
16
- "dsh-plugin",
17
- "ui"
18
- ],
19
- "type": "module",
20
- "exports": {
21
- ".": "./index.js",
22
- "./client": "./client.js",
23
- "./package.json": "./package.json",
24
- "./locale/*.json": "./locale/*.json",
25
- "./icon": "./icon.svg"
26
- },
27
- "files": [
28
- "index.js",
29
- "client.js",
30
- "cordis.patch.yml",
31
- "README.md",
32
- "LICENSE",
33
- "locale",
34
- "icon.svg",
35
- "CHANGELOG.md"
36
- ],
37
- "dsh": {
38
- "bundle": {
39
- "patch": "./cordis.patch.yml"
40
- },
41
- "client": {
42
- "platform": "web"
43
- }
44
- },
45
- "icon": "./icon.svg"
46
- }
1
+ {
2
+ "name": "dsh-ui-controller",
3
+ "version": "0.2.1",
4
+ "description": "Inspect and control the UI other plugins register into DeepSeek Harness slots (visibility, order, mirrored entries), and fold the sidebar's panels behind a single \"More (N)\" row.",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "MeruSu"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/MeruSu/dsh-ui-controller.git"
12
+ },
13
+ "keywords": [
14
+ "dsh",
15
+ "deepseek-harness",
16
+ "dsh-plugin",
17
+ "ui"
18
+ ],
19
+ "type": "module",
20
+ "exports": {
21
+ ".": "./index.js",
22
+ "./client": "./client.js",
23
+ "./package.json": "./package.json",
24
+ "./locale/*.json": "./locale/*.json",
25
+ "./icon": "./icon.svg"
26
+ },
27
+ "files": [
28
+ "index.js",
29
+ "client.js",
30
+ "cordis.patch.yml",
31
+ "README.md",
32
+ "LICENSE",
33
+ "locale",
34
+ "icon.svg",
35
+ "CHANGELOG.md"
36
+ ],
37
+ "dsh": {
38
+ "bundle": {
39
+ "patch": "./cordis.patch.yml"
40
+ },
41
+ "client": {
42
+ "platform": "web"
43
+ }
44
+ },
45
+ "icon": "./icon.svg"
46
+ }