dsh-ui-controller 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/README.md +39 -34
- package/client.js +480 -234
- package/package.json +46 -46
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,55 @@
|
|
|
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
|
+
|
|
5
54
|
## 0.1.1 — 2026-11-14
|
|
6
55
|
|
|
7
56
|
### Added
|
package/README.md
CHANGED
|
@@ -65,19 +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. **
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
The
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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.
|
|
81
90
|
|
|
82
91
|
## What it deliberately does **not** do
|
|
83
92
|
|
|
@@ -136,7 +145,7 @@ on it.
|
|
|
136
145
|
```js
|
|
137
146
|
const api = window.__UI_CONTROLLER__;
|
|
138
147
|
|
|
139
|
-
api.version // '0.
|
|
148
|
+
api.version // '0.2.1'
|
|
140
149
|
api.catalog() // → [{ key, kind, scope, risk, purpose, registrantStatic, injectStatic }]
|
|
141
150
|
api.catalogSummary() // → { total: 109, kinds: {...} }
|
|
142
151
|
api.inventory() // → { rows, empty, totalSlots, occupiedSlots, hiddenCount,
|
|
@@ -177,7 +186,7 @@ Two sentences that belong in any answer about ordering:
|
|
|
177
186
|
node --check client.js
|
|
178
187
|
node --check index.js
|
|
179
188
|
node --check test/classify.test.mjs
|
|
180
|
-
node test/classify.test.mjs # expect: PASS —
|
|
189
|
+
node test/classify.test.mjs # expect: PASS — 38 groups
|
|
181
190
|
node ..\..\cangku\tmp\261114_gate_ui_controller.mjs # static gate, separate script
|
|
182
191
|
```
|
|
183
192
|
|
|
@@ -191,12 +200,12 @@ with the old `order` alias, and the zh/en dictionary parity. The grouped page ha
|
|
|
191
200
|
its own groups: entries group under their slot with empty seats in their own zone,
|
|
192
201
|
the three filters count what they keep, folding starts closed and survives a
|
|
193
202
|
re-render, and the static fallback still draws slot heads when no live snapshot is
|
|
194
|
-
available. The
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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.
|
|
200
209
|
|
|
201
210
|
## Known limits
|
|
202
211
|
|
|
@@ -219,19 +228,15 @@ following while the follow switch writes it straight back.
|
|
|
219
228
|
readable at runtime for entries present in the registry; the column shows the
|
|
220
229
|
static proxy scanned out of the shipped bundles, so an entry registered by code
|
|
221
230
|
that ships no literal key can read as "—".
|
|
222
|
-
8. **The
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
Turn it back on from this page, or run
|
|
232
|
-
`__UI_CONTROLLER__.settings.set({ nav: { follow: false, state: 'rail' } })` in
|
|
233
|
-
the console. `Follow the host sidebar` (the default) never lands you there on
|
|
234
|
-
its own — only an explicit choice does.
|
|
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.
|
|
235
240
|
|
|
236
241
|
## License
|
|
237
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.
|
|
30
|
+
const VERSION = '0.2.1';
|
|
31
31
|
|
|
32
32
|
const NS = 'uiController';
|
|
33
33
|
const SECTION_ID = 'ui-controller';
|
|
@@ -76,9 +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-
|
|
80
|
-
'.uic-
|
|
81
|
-
'.uic-
|
|
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)}',
|
|
82
86
|
'.uic-zone{border-top:.5px solid var(--dsw-alias-border-l2);padding:2px 0}',
|
|
83
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}',
|
|
84
88
|
'.uic-zoneName{flex:none}',
|
|
@@ -105,96 +109,64 @@ const PAGE_CSS = [
|
|
|
105
109
|
|
|
106
110
|
/* ------------------------------------------------- settings page left rail */
|
|
107
111
|
|
|
108
|
-
const NAV_ATTR = 'data-uic-nav';
|
|
109
|
-
const PANEL_SELECTOR = 'div[data-shortcut-modal="settings"]';
|
|
110
|
-
const PANEL_NAV_STATES = ['expanded', 'rail', 'hidden'];
|
|
111
|
-
const NAV_WIDTHS = { expanded: 188, rail: 56, hidden: 0 };
|
|
112
|
-
const HOST_SIDEBAR_RAIL_MAX = 64;
|
|
113
112
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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']);
|
|
118
119
|
|
|
119
120
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* next release. Only the first track belongs to us.
|
|
125
|
-
*/
|
|
126
|
-
function navColumnsOf(state) {
|
|
127
|
-
return navWidthOf(state) + 'px minmax(0, 1fr)';
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/*
|
|
131
|
-
* Collapsing only means something while the host draws the rail as a vertical
|
|
132
|
-
* column; below 768px it becomes a horizontal tab strip, where hiding the
|
|
133
|
-
* labels would leave an unlabelled bar. Same breakpoint the host uses.
|
|
134
|
-
*
|
|
135
|
-
* Only the two collapsed states claim a track. Leaving `expanded` untouched
|
|
136
|
-
* means the host keeps ownership of its own width: if a later build widens the
|
|
137
|
-
* rail, we inherit it instead of pinning an old number.
|
|
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.
|
|
138
125
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
PANEL_SELECTOR + '[' + NAV_ATTR + '="hidden"]{overflow:hidden}',
|
|
152
|
-
PANEL_SELECTOR + '[' + NAV_ATTR + '="hidden"] > nav{display:none}',
|
|
153
|
-
'}',
|
|
154
|
-
].join('\n');
|
|
155
|
-
|
|
156
|
-
/** Only the three stored states are meaningful; anything else is "expanded". */
|
|
157
|
-
function stateOr(value) {
|
|
158
|
-
return PANEL_NAV_STATES.includes(value) ? value : 'expanded';
|
|
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
|
+
}
|
|
159
138
|
}
|
|
160
139
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
* Two readings, both taken from the shipped behaviour rather than invented
|
|
165
|
-
* here: an explicit `data-sidebar-collapsed` marker anywhere in the document,
|
|
166
|
-
* or a sidebar element measured between 1px and 64px. The three sidebar
|
|
167
|
-
* selectors are the ones the shipped code probes, in the same order; a
|
|
168
|
-
* different threshold would make the two disagree the moment the host changes
|
|
169
|
-
* its width.
|
|
170
|
-
*/
|
|
171
|
-
function hostSidebarCollapsed(doc) {
|
|
172
|
-
if (doc === null || doc === undefined || typeof doc.querySelector !== 'function') return false;
|
|
140
|
+
function writeSidebarMore(storage, folded) {
|
|
141
|
+
const store = storage ?? null;
|
|
142
|
+
if (store === null || typeof store.setItem !== 'function') return;
|
|
173
143
|
try {
|
|
174
|
-
|
|
175
|
-
const sidebar =
|
|
176
|
-
doc.querySelector('[data-slot="sidebar"]') ??
|
|
177
|
-
doc.querySelector('div[class*="sidebarCol"]') ??
|
|
178
|
-
doc.querySelector('div[class*="hHd-Xa_root"]');
|
|
179
|
-
if (sidebar === null || sidebar === undefined || typeof sidebar.getBoundingClientRect !== 'function') return false;
|
|
180
|
-
const measured = sidebar.getBoundingClientRect().width;
|
|
181
|
-
return Number.isFinite(measured) && measured > 0 && measured <= HOST_SIDEBAR_RAIL_MAX;
|
|
144
|
+
store.setItem(SIDEBAR_MORE_KEY, JSON.stringify({ folded }));
|
|
182
145
|
} catch {
|
|
183
|
-
|
|
146
|
+
/* a full quota must not take the page down */
|
|
184
147
|
}
|
|
185
148
|
}
|
|
186
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
|
+
|
|
187
156
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* point of following.
|
|
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).
|
|
193
161
|
*/
|
|
194
|
-
function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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;
|
|
198
170
|
}
|
|
199
171
|
|
|
200
172
|
const PRESET_NAME_MAX = 40;
|
|
@@ -353,7 +325,7 @@ function defaultSettings() {
|
|
|
353
325
|
visualOrder: {},
|
|
354
326
|
presets: {},
|
|
355
327
|
activePreset: null,
|
|
356
|
-
|
|
328
|
+
sidebarMore: { foldAll: true },
|
|
357
329
|
};
|
|
358
330
|
}
|
|
359
331
|
|
|
@@ -442,14 +414,6 @@ function sanitizePresets(raw) {
|
|
|
442
414
|
}
|
|
443
415
|
|
|
444
416
|
/** `follow` defaults to on; the three-way choice only matters when it is off. */
|
|
445
|
-
function sanitizeNav(raw) {
|
|
446
|
-
const next = { follow: true, state: 'expanded' };
|
|
447
|
-
if (isPlainObject(raw) === false) return next;
|
|
448
|
-
if (raw.follow === false) next.follow = false;
|
|
449
|
-
if (PANEL_NAV_STATES.includes(raw.state)) next.state = raw.state;
|
|
450
|
-
return next;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
417
|
function sanitizeSettings(raw) {
|
|
454
418
|
const base = defaultSettings();
|
|
455
419
|
if (isPlainObject(raw) === false) return base;
|
|
@@ -459,7 +423,7 @@ function sanitizeSettings(raw) {
|
|
|
459
423
|
next.visualOrder = sanitizeVisualOrder(raw.visualOrder ?? raw.order);
|
|
460
424
|
next.presets = sanitizePresets(raw.presets);
|
|
461
425
|
next.activePreset = typeof raw.activePreset === 'string' && hasOwn(next.presets, raw.activePreset) ? raw.activePreset : null;
|
|
462
|
-
next.
|
|
426
|
+
next.sidebarMore = isPlainObject(raw.sidebarMore) ? { foldAll: raw.sidebarMore.foldAll !== false } : { foldAll: true };
|
|
463
427
|
return next;
|
|
464
428
|
}
|
|
465
429
|
|
|
@@ -547,7 +511,7 @@ function patchSettings(patch) {
|
|
|
547
511
|
visualOrder,
|
|
548
512
|
presets: isPlainObject(patch.presets) ? patch.presets : base.presets,
|
|
549
513
|
activePreset: hasOwn(patch, 'activePreset') ? patch.activePreset : base.activePreset,
|
|
550
|
-
|
|
514
|
+
sidebarMore: { ...(isPlainObject(base.sidebarMore) ? base.sidebarMore : {}), ...(isPlainObject(patch.sidebarMore) ? patch.sidebarMore : {}) },
|
|
551
515
|
});
|
|
552
516
|
}
|
|
553
517
|
|
|
@@ -1083,14 +1047,13 @@ const ZH = {
|
|
|
1083
1047
|
'settings.filter.unbound': '未绑定',
|
|
1084
1048
|
'settings.filterCount': '{slots} 槽 · {entries} entry',
|
|
1085
1049
|
'settings.noMatch': '没有匹配的座位。',
|
|
1086
|
-
'settings.
|
|
1087
|
-
'settings.
|
|
1088
|
-
'settings.
|
|
1089
|
-
'settings.
|
|
1090
|
-
'settings.
|
|
1091
|
-
'settings.
|
|
1092
|
-
'settings.
|
|
1093
|
-
'settings.nav.now': '当前选择:{width}px。',
|
|
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': '全部放回外面',
|
|
1094
1057
|
};
|
|
1095
1058
|
|
|
1096
1059
|
const EN = {
|
|
@@ -1145,14 +1108,13 @@ const EN = {
|
|
|
1145
1108
|
'settings.filter.unbound': 'Unbound',
|
|
1146
1109
|
'settings.filterCount': '{slots} slots · {entries} entries',
|
|
1147
1110
|
'settings.noMatch': 'No slot matches.',
|
|
1148
|
-
'settings.
|
|
1149
|
-
'settings.
|
|
1150
|
-
'settings.
|
|
1151
|
-
'settings.
|
|
1152
|
-
'settings.
|
|
1153
|
-
'settings.
|
|
1154
|
-
'settings.
|
|
1155
|
-
'settings.nav.now': 'Selected: {width}px.',
|
|
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',
|
|
1156
1118
|
};
|
|
1157
1119
|
|
|
1158
1120
|
const DICTS = { zh: ZH, en: EN };
|
|
@@ -1186,7 +1148,7 @@ function node(tagName, props, children) {
|
|
|
1186
1148
|
|
|
1187
1149
|
function injectStyle(doc) {
|
|
1188
1150
|
if (doc === null || doc === undefined) return;
|
|
1189
|
-
const css = HIDE_CSS + '\n' + PAGE_CSS
|
|
1151
|
+
const css = HIDE_CSS + '\n' + PAGE_CSS;
|
|
1190
1152
|
const existing = typeof doc.getElementById === 'function' ? doc.getElementById(STYLE_ID) : null;
|
|
1191
1153
|
/* A reloaded plugin can find the stylesheet its previous instance left behind.
|
|
1192
1154
|
Rewriting it keeps the three rule groups from drifting apart. */
|
|
@@ -1208,75 +1170,6 @@ function removeStyle(doc) {
|
|
|
1208
1170
|
if (existing !== null && existing !== undefined && typeof existing.remove === 'function') existing.remove();
|
|
1209
1171
|
}
|
|
1210
1172
|
|
|
1211
|
-
/* ------------------------------------------------------------- nav DOM */
|
|
1212
|
-
|
|
1213
|
-
/** Buttons we put a `title` on, so leaving rail state can undo exactly those. */
|
|
1214
|
-
const navTitled = [];
|
|
1215
|
-
|
|
1216
|
-
/**
|
|
1217
|
-
* Put captured `title` attributes back, then forget them.
|
|
1218
|
-
*
|
|
1219
|
-
* `keep` is the set of buttons that should stay titled: the two-second paint
|
|
1220
|
-
* pass calls this with the buttons it just found, so a host re-render that
|
|
1221
|
-
* replaces the nav nodes drops the stale entries and nothing is written twice.
|
|
1222
|
-
*/
|
|
1223
|
-
function releaseNavTitles(keep) {
|
|
1224
|
-
for (let index = navTitled.length - 1; index >= 0; index -= 1) {
|
|
1225
|
-
const item = navTitled[index];
|
|
1226
|
-
if (keep !== undefined && keep.has(item.element) === true) continue;
|
|
1227
|
-
if (item.previous === null) item.element.removeAttribute('title');
|
|
1228
|
-
else item.element.setAttribute('title', item.previous);
|
|
1229
|
-
navTitled.splice(index, 1);
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
/**
|
|
1234
|
-
* Paint one of the three states onto the settings modal.
|
|
1235
|
-
*
|
|
1236
|
-
* Only the panel attribute and a handful of `title` attributes are written:
|
|
1237
|
-
* the nav markup belongs to the host and is never moved, re-registered or
|
|
1238
|
-
* re-rendered by us. Rail state hides the labels with CSS, so nothing has to
|
|
1239
|
-
* be remembered across a host re-render beyond the attribute itself. Called
|
|
1240
|
-
* every two seconds, so every write is guarded — an unchanged attribute or
|
|
1241
|
-
* tooltip is left alone instead of being re-set in a loop.
|
|
1242
|
-
*/
|
|
1243
|
-
function applyNavStateTo(doc, settings) {
|
|
1244
|
-
const state = resolveNavState(settings, doc);
|
|
1245
|
-
if (doc === null || doc === undefined || typeof doc.querySelector !== 'function') return state;
|
|
1246
|
-
const panel = doc.querySelector(PANEL_SELECTOR);
|
|
1247
|
-
if (panel === null || panel === undefined) {
|
|
1248
|
-
releaseNavTitles();
|
|
1249
|
-
return state;
|
|
1250
|
-
}
|
|
1251
|
-
if (panel.getAttribute(NAV_ATTR) !== state) panel.setAttribute(NAV_ATTR, state);
|
|
1252
|
-
const nav = state === 'rail' && typeof panel.querySelector === 'function' ? panel.querySelector('nav') : null;
|
|
1253
|
-
if (nav === null || nav === undefined || typeof nav.querySelectorAll !== 'function') {
|
|
1254
|
-
releaseNavTitles();
|
|
1255
|
-
return state;
|
|
1256
|
-
}
|
|
1257
|
-
const wanted = new Set();
|
|
1258
|
-
for (const button of Array.from(nav.querySelectorAll('button'))) {
|
|
1259
|
-
const spans = typeof button.querySelectorAll === 'function' ? Array.from(button.querySelectorAll('span')) : [];
|
|
1260
|
-
const label = elementText(spans.length > 1 ? spans[1] : button);
|
|
1261
|
-
if (label === '') continue;
|
|
1262
|
-
wanted.add(button);
|
|
1263
|
-
if (button.getAttribute('title') === label) continue;
|
|
1264
|
-
if (navTitled.some((item) => item.element === button) === false) {
|
|
1265
|
-
navTitled.push({ element: button, previous: button.getAttribute('title') });
|
|
1266
|
-
}
|
|
1267
|
-
button.setAttribute('title', label);
|
|
1268
|
-
}
|
|
1269
|
-
releaseNavTitles(wanted);
|
|
1270
|
-
return state;
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
/** Take the attribute and every `title` back off, e.g. when the plugin unloads. */
|
|
1274
|
-
function clearNavState(doc) {
|
|
1275
|
-
releaseNavTitles();
|
|
1276
|
-
if (doc === null || doc === undefined || typeof doc.querySelectorAll !== 'function') return;
|
|
1277
|
-
for (const panel of Array.from(doc.querySelectorAll(PANEL_SELECTOR))) panel.removeAttribute(NAV_ATTR);
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
1173
|
/* ---------------------------------------------------------------- grouping */
|
|
1281
1174
|
|
|
1282
1175
|
const RISK_RISKY = 'shadows-shipped-ui';
|
|
@@ -1727,52 +1620,20 @@ function settingsPage(props) {
|
|
|
1727
1620
|
|
|
1728
1621
|
const presetNames = Object.keys(state.presets).sort();
|
|
1729
1622
|
|
|
1730
|
-
const
|
|
1731
|
-
const
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
const navNow = followOn ? resolveNavState({ nav: navStored }, typeof document === 'undefined' ? null : document) : navChoice;
|
|
1736
|
-
const navEdit = (change) => commit({ ...state, nav: { ...navStored, ...change } });
|
|
1737
|
-
|
|
1738
|
-
const navBlock = node('div', { key: 'nav', className: 'uic-navSection', 'data-uic-nav-section': '1' }, [
|
|
1739
|
-
node('h3', { key: 'h', className: 'uic-h3' }, t('settings.nav.title')),
|
|
1740
|
-
node('p', { key: 'hint', className: 'uic-dim' }, t('settings.nav.hint')),
|
|
1741
|
-
node('label', { key: 'follow', className: 'uic-navFollow' }, [
|
|
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' }, [
|
|
1742
1628
|
node('input', {
|
|
1743
1629
|
key: 'box',
|
|
1744
1630
|
type: 'checkbox',
|
|
1745
|
-
'data-uic-
|
|
1746
|
-
checked:
|
|
1747
|
-
onChange: (event) =>
|
|
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 } }),
|
|
1748
1634
|
}),
|
|
1749
|
-
node('span', { key: 'text' }, t('settings.
|
|
1635
|
+
node('span', { key: 'text' }, t('settings.sidebarMore.foldAll')),
|
|
1750
1636
|
]),
|
|
1751
|
-
node(
|
|
1752
|
-
'div',
|
|
1753
|
-
{ key: 'states', className: 'uic-navStates' },
|
|
1754
|
-
PANEL_NAV_STATES.map((option) =>
|
|
1755
|
-
node(
|
|
1756
|
-
'button',
|
|
1757
|
-
{
|
|
1758
|
-
key: option,
|
|
1759
|
-
className: 'uic-filter' + (navChoice === option ? ' uic-filter-on' : ''),
|
|
1760
|
-
type: 'button',
|
|
1761
|
-
'data-uic-nav-pick': option,
|
|
1762
|
-
'data-on': navNow === option ? 'true' : 'false',
|
|
1763
|
-
disabled: followOn,
|
|
1764
|
-
title: followOn ? t('settings.nav.followOn') : undefined,
|
|
1765
|
-
onClick: () => navEdit({ follow: false, state: option }),
|
|
1766
|
-
},
|
|
1767
|
-
t('settings.nav.state.' + option),
|
|
1768
|
-
),
|
|
1769
|
-
),
|
|
1770
|
-
),
|
|
1771
|
-
node(
|
|
1772
|
-
'p',
|
|
1773
|
-
{ key: 'now', className: 'uic-dim', 'data-uic-nav-now': navNow },
|
|
1774
|
-
t('settings.nav.now', { width: navWidthOf(navNow) }),
|
|
1775
|
-
),
|
|
1776
1637
|
]);
|
|
1777
1638
|
|
|
1778
1639
|
return node('div', { className: 'uic-page', 'data-uic-page': '1' }, [
|
|
@@ -1858,11 +1719,324 @@ function settingsPage(props) {
|
|
|
1858
1719
|
)),
|
|
1859
1720
|
node('p', { key: 'order-hint', className: 'uic-dim' }, t('settings.orderHint')),
|
|
1860
1721
|
node('p', { key: 'order-hint-2', className: 'uic-dim' }, t('settings.orderHint2')),
|
|
1861
|
-
|
|
1722
|
+
sidebarMoreBlock,
|
|
1862
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')),
|
|
1863
1724
|
]);
|
|
1864
1725
|
}
|
|
1865
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
|
+
|
|
1866
2040
|
function apply(ctx) {
|
|
1867
2041
|
const doc = typeof document === 'undefined' ? null : document;
|
|
1868
2042
|
const slots = ctx.get('slots');
|
|
@@ -1874,6 +2048,61 @@ function apply(ctx) {
|
|
|
1874
2048
|
|
|
1875
2049
|
const inventory = () => slotRows(entriesOf, readSettings(), runtimeCatalog(slots));
|
|
1876
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
|
+
|
|
1877
2106
|
let pickHandler = null;
|
|
1878
2107
|
|
|
1879
2108
|
const applyHidden = () => {
|
|
@@ -1919,8 +2148,18 @@ function apply(ctx) {
|
|
|
1919
2148
|
|
|
1920
2149
|
injectStyle(doc);
|
|
1921
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;
|
|
1922
2162
|
stopPicking();
|
|
1923
|
-
clearNavState(doc);
|
|
1924
2163
|
removeStyle(doc);
|
|
1925
2164
|
if (doc !== null) {
|
|
1926
2165
|
for (const element of Array.from(doc.querySelectorAll('[' + HIDDEN_ATTR + ']'))) element.removeAttribute(HIDDEN_ATTR);
|
|
@@ -1934,7 +2173,8 @@ function apply(ctx) {
|
|
|
1934
2173
|
const current = readSettings();
|
|
1935
2174
|
applyHidden();
|
|
1936
2175
|
applyVisualOrder(doc, current, ordered);
|
|
1937
|
-
|
|
2176
|
+
paintCount();
|
|
2177
|
+
applyFold();
|
|
1938
2178
|
};
|
|
1939
2179
|
|
|
1940
2180
|
applyAll();
|
|
@@ -2047,18 +2287,24 @@ window.__ModuleLoader__.load({
|
|
|
2047
2287
|
isOpen,
|
|
2048
2288
|
toggleOpen,
|
|
2049
2289
|
resetOpen,
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
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,
|
|
2062
2308
|
DICTS,
|
|
2063
2309
|
};
|
|
2064
2310
|
},
|
package/package.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-ui-controller",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
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
|
+
}
|