dsh-ui-controller 0.2.7 → 0.2.8
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 +4 -0
- package/README.md +9 -57
- package/client.js +6 -739
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -65,29 +65,7 @@ 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
|
-
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.
|
|
90
|
-
7. **Chat scrolling: wheel damping.** A wheel over the chat pane is eased instead of
|
|
68
|
+
6. **Chat scrolling: wheel damping.** A wheel over the chat pane is eased instead of
|
|
91
69
|
jumping: each tick is normalised (`deltaMode` 0 px / 1 ×16 px per line / 2 ×90% of
|
|
92
70
|
the viewport), added to a target `scrollTop`, and stepped toward it in
|
|
93
71
|
`requestAnimationFrame` with an exponential factor. Strength 1–5 maps to
|
|
@@ -202,7 +180,7 @@ Two sentences that belong in any answer about ordering:
|
|
|
202
180
|
node --check client.js
|
|
203
181
|
node --check index.js
|
|
204
182
|
node --check test/classify.test.mjs
|
|
205
|
-
node test/classify.test.mjs # expect: PASS —
|
|
183
|
+
node test/classify.test.mjs # expect: PASS — 35 groups
|
|
206
184
|
node ..\..\cangku\tmp\261114_gate_ui_controller.mjs # static gate, separate script
|
|
207
185
|
```
|
|
208
186
|
|
|
@@ -216,51 +194,25 @@ with the old `order` alias, and the zh/en dictionary parity. The grouped page ha
|
|
|
216
194
|
its own groups: entries group under their slot with empty seats in their own zone,
|
|
217
195
|
the three filters count what they keep, folding starts closed and survives a
|
|
218
196
|
re-render, and the static fallback still draws slot heads when no live snapshot is
|
|
219
|
-
available.
|
|
220
|
-
what the record and `foldAll` ask for; the launcher carries no number at all — the counter is gone, and a
|
|
221
|
-
stale count painted by an older build is normalised back to the bare label on
|
|
222
|
-
every pass; the first frame of the menu already carries the host row look (the
|
|
223
|
-
sample is taken in the row ref, before the browser paints, so the fallback
|
|
224
|
-
class never reaches the screen and the old bordered fallback style is gone);
|
|
225
|
-
folding hides the live rows and restores them on the way out,
|
|
226
|
-
leaving rows it cannot identify alone; and
|
|
227
|
-
the menu borrows a live host item's class list and computed size instead of any
|
|
228
|
-
hardcoded name; each menu row copies the panel glyph from the live sidebar row
|
|
229
|
-
(runtime clone taken from the drawing inside the host's slot anchor, ids and
|
|
230
|
-
`data-slot` stripped, refilled on every mount, remembered per panel so a folded
|
|
231
|
-
panel keeps its icon after the host stops rendering its row) and folding hides
|
|
232
|
-
the wrapper that owns both the icon and the text, never `nav`.
|
|
197
|
+
available.
|
|
233
198
|
|
|
234
199
|
## Known limits
|
|
235
200
|
|
|
236
|
-
1. **
|
|
237
|
-
point of folding is to get back to the list quickly; persisting it would mean
|
|
238
|
-
another storage key to migrate, and the filters already narrow the page to
|
|
239
|
-
three or four rows.
|
|
240
|
-
2. **No entry→DOM mapping.** The slots core renders entries itself and marks
|
|
201
|
+
1. **No entry→DOM mapping.** The slots core renders entries itself and marks
|
|
241
202
|
nothing, so binding is manual. Rows without a binding show "cannot locate" with
|
|
242
203
|
the reason instead of a control that does nothing.
|
|
243
|
-
|
|
204
|
+
2. **Hiding is not unloading.** A hidden entry still runs. If it is expensive, this
|
|
244
205
|
plugin is not the tool — talk to the plugin's author.
|
|
245
|
-
|
|
206
|
+
3. **Visual order is CSS only.** It applies inside one flex/grid parent; a child of
|
|
246
207
|
a `display: contents` or block parent is skipped, and nothing outside our bound
|
|
247
208
|
elements is touched.
|
|
248
|
-
|
|
209
|
+
4. **Hash class names change every build.** Nothing here keys off them; only
|
|
249
210
|
`data-*`, `role`, `aria-label`, `name` and `id` are used to build selectors.
|
|
250
|
-
|
|
251
|
-
|
|
211
|
+
5. **`root` is off limits.** Listing it is fine; registering into it is not.
|
|
212
|
+
6. **`registrant` is an inference.** The live value (`entry.registrant`) is only
|
|
252
213
|
readable at runtime for entries present in the registry; the column shows the
|
|
253
214
|
static proxy scanned out of the shipped bundles, so an entry registered by code
|
|
254
215
|
that ships no literal key can read as "—".
|
|
255
|
-
8. **The More menu coexists with other action entries.** The host renders every
|
|
256
|
-
registration of `sidebar.panellist.actions` into the same menu; when another
|
|
257
|
-
plugin (for example the codex-ui skin on the desktop profile) also contributes
|
|
258
|
-
there, the two menus share the popup. This plugin does not remove or reorder
|
|
259
|
-
other entries.
|
|
260
|
-
9. **Replay is best-effort against the host's in-memory pins.** The host keeps its
|
|
261
|
-
own `unpinned` list only for the session; a folded id is re-hidden when the host
|
|
262
|
-
honours the pin callback, and a host restart resets the host list while this
|
|
263
|
-
plugin's record is replayed on the next menu open or panel-list change.
|
|
264
216
|
|
|
265
217
|
## License
|
|
266
218
|
|
package/client.js
CHANGED
|
@@ -30,7 +30,7 @@ window.__ModuleLoader__.load({
|
|
|
30
30
|
id: 'dsh-ui-controller',
|
|
31
31
|
factory(require) {
|
|
32
32
|
|
|
33
|
-
const VERSION = '0.2.
|
|
33
|
+
const VERSION = '0.2.8';
|
|
34
34
|
|
|
35
35
|
const NS = 'uiController';
|
|
36
36
|
const SECTION_ID = 'ui-controller';
|
|
@@ -103,15 +103,8 @@ window.__ModuleLoader__.load({
|
|
|
103
103
|
'.uic-filterGroup{display:inline-flex;gap:2px}',
|
|
104
104
|
'.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)}',
|
|
105
105
|
'.uic-filter[data-on="true"]{border-color:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-state-business-primary)}',
|
|
106
|
-
'.uic-
|
|
107
|
-
'.uic-
|
|
108
|
-
'.uic-moreRow{display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:34px;padding:0 8px;font-size:13px;line-height:20px}',
|
|
109
|
-
'.uic-moreRowName{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
110
|
-
'.uic-moreRowMain{display:flex;align-items:center;gap:8px;min-width:0;flex:1 1 auto}',
|
|
111
|
-
'.uic-moreGlyph{display:inline-flex;align-items:center;justify-content:center;flex:none;width:16px;height:16px;overflow:hidden}',
|
|
112
|
-
'.uic-moreGlyph>svg,.uic-moreGlyph>img{width:16px;height:16px;display:block}',
|
|
113
|
-
'.uic-moreAction{flex:none;padding:2px 8px;font-size:12px;border:1px solid var(--dsw-alias-border-l4);border-radius:6px;cursor:pointer}',
|
|
114
|
-
'.uic-moreAction:hover{background:var(--dsw-alias-bg-layer-2)}',
|
|
106
|
+
'.uic-settingsGroup{display:flex;flex-direction:column;gap:6px;margin-top:12px;padding-top:10px;border-top:1px solid var(--dsw-alias-border-l2)}',
|
|
107
|
+
'.uic-settingsRow{display:flex;align-items:center;gap:8px;font-size:13px;line-height:20px}',
|
|
115
108
|
'.uic-zone{border-top:.5px solid var(--dsw-alias-border-l2);padding:2px 0}',
|
|
116
109
|
'.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}',
|
|
117
110
|
'.uic-zoneName{flex:none}',
|
|
@@ -136,63 +129,6 @@ window.__ModuleLoader__.load({
|
|
|
136
129
|
'@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}}',
|
|
137
130
|
].join('\n');
|
|
138
131
|
|
|
139
|
-
/* ------------------------------------------------- settings page left rail */
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const SIDEBAR_MORE_KEY = 'dsh.uic.sidebarMore.v1';
|
|
143
|
-
const SIDEBAR_MORE_SLOT = 'sidebar.panellist.actions';
|
|
144
|
-
const SIDEBAR_MORE_ID = 'ui-controller.sidebar-more';
|
|
145
|
-
const SIDEBAR_MORE_ORDER = 0;
|
|
146
|
-
const SIDEBAR_MORE_MODAL = '[data-shortcut-modal="sidebar"]';
|
|
147
|
-
const MORE_TITLES = new Set(['更多', 'More']);
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* The folded record: which panel ids the More menu currently hides.
|
|
151
|
-
* The host keeps its pins in memory only (dsh-client-ui-sidebar
|
|
152
|
-
* createPanelPins), so a reload would put every panel back outside;
|
|
153
|
-
* this record is what a reload replays.
|
|
154
|
-
*/
|
|
155
|
-
function readSidebarMore(storage) {
|
|
156
|
-
const store = storage ?? null;
|
|
157
|
-
if (store === null || typeof store.getItem !== 'function') return { folded: [] };
|
|
158
|
-
try {
|
|
159
|
-
const raw = store.getItem(SIDEBAR_MORE_KEY);
|
|
160
|
-
if (raw === null || raw === undefined || raw === '') return { folded: [] };
|
|
161
|
-
const parsed = JSON.parse(raw);
|
|
162
|
-
if (isPlainObject(parsed) === false || Array.isArray(parsed.folded) === false) return { folded: [] };
|
|
163
|
-
return { folded: parsed.folded.filter((id) => typeof id === 'string' && id !== '') };
|
|
164
|
-
} catch {
|
|
165
|
-
return { folded: [] };
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function writeSidebarMore(storage, folded) {
|
|
170
|
-
const store = storage ?? null;
|
|
171
|
-
if (store === null || typeof store.setItem !== 'function') return;
|
|
172
|
-
try {
|
|
173
|
-
store.setItem(SIDEBAR_MORE_KEY, JSON.stringify({ folded }));
|
|
174
|
-
} catch {
|
|
175
|
-
/* a full quota must not take the page down */
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/** Folded ids that still name a live panel; the rest are stale and dropped. */
|
|
180
|
-
function cleanFolded(folded, panels) {
|
|
181
|
-
const live = new Set(panels);
|
|
182
|
-
return folded.filter((id) => live.has(id));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* What a fresh install looks like: with foldAll on, every panel except
|
|
187
|
-
* plugins goes behind the More button (the shape the user asked for).
|
|
188
|
-
* Off means nothing folds — but the stored record is never erased here, so
|
|
189
|
-
* turning the switch back on restores it (see the menu's replay).
|
|
190
|
-
*/
|
|
191
|
-
function computeFold(panels, settings) {
|
|
192
|
-
if (settings?.sidebarMore?.foldAll === true) return panels.filter((id) => id !== 'plugins');
|
|
193
|
-
return [];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
132
|
const PRESET_NAME_MAX = 40;
|
|
197
133
|
const SELECTOR_MAX = 240;
|
|
198
134
|
const LOCATOR_LIMIT = 400;
|
|
@@ -391,7 +327,6 @@ window.__ModuleLoader__.load({
|
|
|
391
327
|
visualOrder: {},
|
|
392
328
|
presets: {},
|
|
393
329
|
activePreset: null,
|
|
394
|
-
sidebarMore: { foldAll: true },
|
|
395
330
|
chatScroll: { damping: true, strength: CHAT_SCROLL_DEFAULT_STRENGTH },
|
|
396
331
|
};
|
|
397
332
|
}
|
|
@@ -490,7 +425,6 @@ window.__ModuleLoader__.load({
|
|
|
490
425
|
next.visualOrder = sanitizeVisualOrder(raw.visualOrder ?? raw.order);
|
|
491
426
|
next.presets = sanitizePresets(raw.presets);
|
|
492
427
|
next.activePreset = typeof raw.activePreset === 'string' && hasOwn(next.presets, raw.activePreset) ? raw.activePreset : null;
|
|
493
|
-
next.sidebarMore = isPlainObject(raw.sidebarMore) ? { foldAll: raw.sidebarMore.foldAll !== false } : { foldAll: true };
|
|
494
428
|
next.chatScroll = sanitizeChatScroll(raw.chatScroll);
|
|
495
429
|
return next;
|
|
496
430
|
}
|
|
@@ -579,7 +513,6 @@ window.__ModuleLoader__.load({
|
|
|
579
513
|
visualOrder,
|
|
580
514
|
presets: isPlainObject(patch.presets) ? patch.presets : base.presets,
|
|
581
515
|
activePreset: hasOwn(patch, 'activePreset') ? patch.activePreset : base.activePreset,
|
|
582
|
-
sidebarMore: { ...(isPlainObject(base.sidebarMore) ? base.sidebarMore : {}), ...(isPlainObject(patch.sidebarMore) ? patch.sidebarMore : {}) },
|
|
583
516
|
chatScroll: { ...(isPlainObject(base.chatScroll) ? base.chatScroll : {}), ...(isPlainObject(patch.chatScroll) ? patch.chatScroll : {}) },
|
|
584
517
|
});
|
|
585
518
|
}
|
|
@@ -1116,13 +1049,6 @@ window.__ModuleLoader__.load({
|
|
|
1116
1049
|
'settings.filter.unbound': '未绑定',
|
|
1117
1050
|
'settings.filterCount': '{slots} 槽 · {entries} entry',
|
|
1118
1051
|
'settings.noMatch': '没有匹配的座位。',
|
|
1119
|
-
'settings.sidebarMore.title': '左栏「更多」',
|
|
1120
|
-
'settings.sidebarMore.hint': '新装即把除「插件」外的面板都收进左侧「更多 (N)」;关掉 = 全部放回外面(记录保留,下次开回来还原)。',
|
|
1121
|
-
'settings.sidebarMore.foldAll': '新装即全部折叠',
|
|
1122
|
-
'settings.sidebarMore.fold': '收进更多',
|
|
1123
|
-
'settings.sidebarMore.unfold': '放到外面',
|
|
1124
|
-
'settings.sidebarMore.foldAllAction': '全部收进更多',
|
|
1125
|
-
'settings.sidebarMore.unfoldAllAction': '全部放回外面',
|
|
1126
1052
|
'settings.chatScroll.title': '对话区滚动',
|
|
1127
1053
|
'settings.chatScroll.hint': '给聊天区滚轮加一点惯性;侧栏和弹层不受影响。滚到顶或到底时照旧交给页面,原生回弹还在。',
|
|
1128
1054
|
'settings.chatScroll.damping': '滚轮阻尼',
|
|
@@ -1182,13 +1108,6 @@ window.__ModuleLoader__.load({
|
|
|
1182
1108
|
'settings.filter.unbound': 'Unbound',
|
|
1183
1109
|
'settings.filterCount': '{slots} slots · {entries} entries',
|
|
1184
1110
|
'settings.noMatch': 'No slot matches.',
|
|
1185
|
-
'settings.sidebarMore.title': 'Sidebar More',
|
|
1186
|
-
'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).',
|
|
1187
|
-
'settings.sidebarMore.foldAll': 'Fold everything on a fresh install',
|
|
1188
|
-
'settings.sidebarMore.fold': 'Fold into More',
|
|
1189
|
-
'settings.sidebarMore.unfold': 'Show outside',
|
|
1190
|
-
'settings.sidebarMore.foldAllAction': 'Fold all into More',
|
|
1191
|
-
'settings.sidebarMore.unfoldAllAction': 'Put all back outside',
|
|
1192
1111
|
'settings.chatScroll.title': 'Chat scrolling',
|
|
1193
1112
|
'settings.chatScroll.hint': 'Adds momentum to the wheel in the chat pane only — the sidebar and popouts are untouched. Top and bottom still belong to the page, so native overscroll stays.',
|
|
1194
1113
|
'settings.chatScroll.damping': 'Wheel damping',
|
|
@@ -1699,30 +1618,15 @@ window.__ModuleLoader__.load({
|
|
|
1699
1618
|
|
|
1700
1619
|
const presetNames = Object.keys(state.presets).sort();
|
|
1701
1620
|
|
|
1702
|
-
const foldAllOn = state.sidebarMore?.foldAll !== false;
|
|
1703
|
-
const sidebarMoreBlock = node('div', { key: 'sidebarMore', className: 'uic-sidebarMore', 'data-uic-sidebar-more': '1' }, [
|
|
1704
|
-
node('h3', { key: 'h', className: 'uic-h3' }, t('settings.sidebarMore.title')),
|
|
1705
|
-
node('p', { key: 'hint', className: 'uic-dim' }, t('settings.sidebarMore.hint')),
|
|
1706
|
-
node('label', { key: 'fold', className: 'uic-sidebarMoreRow' }, [
|
|
1707
|
-
node('input', {
|
|
1708
|
-
key: 'box',
|
|
1709
|
-
type: 'checkbox',
|
|
1710
|
-
'data-uic-sidebar-more-foldall': foldAllOn ? 'true' : 'false',
|
|
1711
|
-
checked: foldAllOn,
|
|
1712
|
-
onChange: (event) => commit({ ...state, sidebarMore: { ...(isPlainObject(state.sidebarMore) ? state.sidebarMore : {}), foldAll: event.target.checked === true } }),
|
|
1713
|
-
}),
|
|
1714
|
-
node('span', { key: 'text' }, t('settings.sidebarMore.foldAll')),
|
|
1715
|
-
]),
|
|
1716
|
-
]);
|
|
1717
1621
|
|
|
1718
1622
|
const dampingOn = state.chatScroll?.damping !== false;
|
|
1719
1623
|
const strength = clamp(Math.round(Number(state.chatScroll?.strength) || CHAT_SCROLL_DEFAULT_STRENGTH), 1, CHAT_SCROLL_K.length);
|
|
1720
1624
|
const setStrength = (value) =>
|
|
1721
1625
|
commit({ ...state, chatScroll: { ...(isPlainObject(state.chatScroll) ? state.chatScroll : {}), strength: clamp(value, 1, CHAT_SCROLL_K.length) } });
|
|
1722
|
-
const chatScrollBlock = node('div', { key: 'chatScroll', className: 'uic-
|
|
1626
|
+
const chatScrollBlock = node('div', { key: 'chatScroll', className: 'uic-settingsGroup', 'data-uic-chat-scroll': '1' }, [
|
|
1723
1627
|
node('h3', { key: 'h', className: 'uic-h3' }, t('settings.chatScroll.title')),
|
|
1724
1628
|
node('p', { key: 'hint', className: 'uic-dim' }, t('settings.chatScroll.hint')),
|
|
1725
|
-
node('label', { key: 'damping', className: 'uic-
|
|
1629
|
+
node('label', { key: 'damping', className: 'uic-settingsRow' }, [
|
|
1726
1630
|
node('input', {
|
|
1727
1631
|
key: 'box',
|
|
1728
1632
|
type: 'checkbox',
|
|
@@ -1732,7 +1636,7 @@ window.__ModuleLoader__.load({
|
|
|
1732
1636
|
}),
|
|
1733
1637
|
node('span', { key: 'text' }, t('settings.chatScroll.damping')),
|
|
1734
1638
|
]),
|
|
1735
|
-
node('div', { key: 'strength', className: 'uic-
|
|
1639
|
+
node('div', { key: 'strength', className: 'uic-settingsRow' }, [
|
|
1736
1640
|
node('span', { key: 'label' }, t('settings.chatScroll.strength')),
|
|
1737
1641
|
node('span', { key: 'ctl', className: 'uic-ctl' }, [
|
|
1738
1642
|
node(
|
|
@@ -1848,563 +1752,12 @@ window.__ModuleLoader__.load({
|
|
|
1848
1752
|
)),
|
|
1849
1753
|
node('p', { key: 'order-hint', className: 'uic-dim' }, t('settings.orderHint')),
|
|
1850
1754
|
node('p', { key: 'order-hint-2', className: 'uic-dim' }, t('settings.orderHint2')),
|
|
1851
|
-
sidebarMoreBlock,
|
|
1852
1755
|
chatScrollBlock,
|
|
1853
1756
|
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')),
|
|
1854
1757
|
]);
|
|
1855
1758
|
}
|
|
1856
1759
|
|
|
1857
1760
|
|
|
1858
|
-
/* -------------------------------------------------- sidebar More menu */
|
|
1859
|
-
|
|
1860
|
-
/** Module state shared by the menu and the replay paths. */
|
|
1861
|
-
let sidebarWrite = null;
|
|
1862
|
-
let sidebarPanels = [];
|
|
1863
|
-
let sidebarReplayQueued = false;
|
|
1864
|
-
|
|
1865
|
-
/** Elements this session hid and the launcher title it rewrote; both are restored on teardown. */
|
|
1866
|
-
const moreTouched = new Map();
|
|
1867
|
-
/* Cloned panel glyphs, remembered per panel id: the host stops rendering a
|
|
1868
|
-
panel's row once it is pinned away, so the icon has to be kept from the last
|
|
1869
|
-
time that row was on screen. */
|
|
1870
|
-
const moreGlyphs = new Map();
|
|
1871
|
-
/** Resolve a panel entry's label the way the host does (thunk first, then string, then id). */
|
|
1872
|
-
function entryLabelOf(entry) {
|
|
1873
|
-
const raw = entry?.options?.label ?? entry?.label;
|
|
1874
|
-
if (typeof raw === 'function') {
|
|
1875
|
-
try {
|
|
1876
|
-
const value = raw();
|
|
1877
|
-
if (typeof value === 'string' && value !== '') return value;
|
|
1878
|
-
} catch {
|
|
1879
|
-
/* a locale-bound thunk may throw before the host binds it; fall through */
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
if (typeof raw === 'string' && raw !== '') return raw;
|
|
1883
|
-
return String(entry?.options?.id ?? entry?.id ?? '');
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
/** ids that should be behind the More button right now (foldAll wins, plugins never folds). */
|
|
1887
|
-
function foldedIdsOf(panels, settings, storageRef) {
|
|
1888
|
-
const ids = panels.map((panel) => panel.id);
|
|
1889
|
-
return desiredFoldIds(
|
|
1890
|
-
panels.map((panel) => ({ id: panel.id })),
|
|
1891
|
-
settings,
|
|
1892
|
-
storageRef,
|
|
1893
|
-
).filter((id) => id !== 'plugins');
|
|
1894
|
-
}
|
|
1895
|
-
|
|
1896
|
-
/**
|
|
1897
|
-
* The host sidebar row for one panel: matched by its own aria-label first, then
|
|
1898
|
-
* by the rendered title. Returns null while the row is not on screen yet.
|
|
1899
|
-
*/
|
|
1900
|
-
function panelRowOf(doc, label) {
|
|
1901
|
-
if (doc === null || doc === undefined || typeof doc.querySelectorAll !== 'function') return null;
|
|
1902
|
-
let rows = [];
|
|
1903
|
-
try {
|
|
1904
|
-
rows = Array.from(doc.querySelectorAll('nav[class*="panelList"] button[class*="panelRow"]'));
|
|
1905
|
-
} catch {
|
|
1906
|
-
rows = [];
|
|
1907
|
-
}
|
|
1908
|
-
for (const row of rows) {
|
|
1909
|
-
const aria = row.getAttribute?.('aria-label') ?? '';
|
|
1910
|
-
if (aria !== '' && aria === label) return row;
|
|
1911
|
-
if (typeof row.querySelector !== 'function') continue;
|
|
1912
|
-
try {
|
|
1913
|
-
const title = row.querySelector('span[class*="panelTitle"]');
|
|
1914
|
-
if (title !== null && title !== undefined && (title.textContent ?? '') === label) return row;
|
|
1915
|
-
} catch {
|
|
1916
|
-
/* a row we cannot read is simply not a match */
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
return null;
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1922
|
-
/**
|
|
1923
|
-
* The element that has to disappear when a panel folds. Usually that is the row
|
|
1924
|
-
* button itself (the host draws the glyph inside it), but a panel whose icon is
|
|
1925
|
-
* rendered beside the button would leave the icon behind, so the wrapper that
|
|
1926
|
-
* holds both is hidden instead. `nav` is never a folding unit.
|
|
1927
|
-
*/
|
|
1928
|
-
function foldUnitOf(row) {
|
|
1929
|
-
if (row === null || row === undefined) return null;
|
|
1930
|
-
let glyph = null;
|
|
1931
|
-
try {
|
|
1932
|
-
glyph = typeof row.querySelector === 'function' ? row.querySelector('span[class*="panelGlyph"]') : null;
|
|
1933
|
-
} catch {
|
|
1934
|
-
glyph = null;
|
|
1935
|
-
}
|
|
1936
|
-
if (glyph !== null && glyph !== undefined) return row;
|
|
1937
|
-
const parent = row.parentElement ?? null;
|
|
1938
|
-
if (parent === null) return row;
|
|
1939
|
-
if (String(parent.tagName ?? '').toUpperCase() === 'NAV') return row;
|
|
1940
|
-
let parentGlyph = null;
|
|
1941
|
-
try {
|
|
1942
|
-
parentGlyph = typeof parent.querySelector === 'function' ? parent.querySelector('span[class*="panelGlyph"]') : null;
|
|
1943
|
-
} catch {
|
|
1944
|
-
parentGlyph = null;
|
|
1945
|
-
}
|
|
1946
|
-
return parentGlyph !== null && parentGlyph !== undefined ? parent : row;
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
/**
|
|
1950
|
-
* The node that actually draws the icon inside a host glyph span. The host puts
|
|
1951
|
-
* its slot anchor (`div[data-slot]` with `display: contents`) in between, so
|
|
1952
|
-
* the first child is a 0x0 wrapper; cloning that would duplicate a slot marker.
|
|
1953
|
-
* Returns the first svg / img / canvas inside it, or the first child itself when
|
|
1954
|
-
* the icon is drawn some other way.
|
|
1955
|
-
*/
|
|
1956
|
-
function glyphIconNodeOf(glyph) {
|
|
1957
|
-
if (glyph === null || glyph === undefined) return null;
|
|
1958
|
-
const start = glyph.firstElementChild ?? null;
|
|
1959
|
-
if (start === null) return null;
|
|
1960
|
-
if (typeof start.querySelector === 'function') {
|
|
1961
|
-
try {
|
|
1962
|
-
const drawing = start.querySelector('svg, img, canvas');
|
|
1963
|
-
if (drawing !== null && drawing !== undefined) return drawing;
|
|
1964
|
-
} catch {
|
|
1965
|
-
return start;
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
return start;
|
|
1969
|
-
}
|
|
1970
|
-
|
|
1971
|
-
/**
|
|
1972
|
-
* Deep-clone the glyph inside one live host row and strip ids (a second copy
|
|
1973
|
-
* would collide in the document). Returns null when the row draws no glyph.
|
|
1974
|
-
*/
|
|
1975
|
-
function glyphCloneOf(row) {
|
|
1976
|
-
if (row === null || row === undefined) return null;
|
|
1977
|
-
let glyph = null;
|
|
1978
|
-
try {
|
|
1979
|
-
glyph = typeof row.querySelector === 'function' ? row.querySelector('span[class*="panelGlyph"]') : null;
|
|
1980
|
-
} catch {
|
|
1981
|
-
glyph = null;
|
|
1982
|
-
}
|
|
1983
|
-
if (glyph === null || glyph === undefined) return null;
|
|
1984
|
-
const source = glyphIconNodeOf(glyph);
|
|
1985
|
-
if (source === null || source === undefined) return null;
|
|
1986
|
-
let clone = null;
|
|
1987
|
-
try {
|
|
1988
|
-
clone = typeof source.cloneNode === 'function' ? source.cloneNode(true) : null;
|
|
1989
|
-
} catch {
|
|
1990
|
-
clone = null;
|
|
1991
|
-
}
|
|
1992
|
-
if (clone === null) return null;
|
|
1993
|
-
/* A cloned wrapper must never name a host slot twice. Ids are different: an
|
|
1994
|
-
icon drawn by the host is usually an <svg> whose <use href="#name"> points
|
|
1995
|
-
at a symbol, and stripping that symbol's id turns the icon into an empty
|
|
1996
|
-
box - the broken glyphs seen in the More menu. Keep every id the drawing
|
|
1997
|
-
itself refers to and drop only the decorative ones. */
|
|
1998
|
-
try {
|
|
1999
|
-
clone.removeAttribute?.('data-slot');
|
|
2000
|
-
} catch {
|
|
2001
|
-
/* best effort */
|
|
2002
|
-
}
|
|
2003
|
-
const referenced = new Set();
|
|
2004
|
-
const rememberRefs = (element) => {
|
|
2005
|
-
if (element === null || element === undefined) return;
|
|
2006
|
-
const names = [];
|
|
2007
|
-
for (const key of ['href', 'xlink:href']) {
|
|
2008
|
-
const value = element.getAttribute?.(key);
|
|
2009
|
-
if (typeof value === 'string') names.push(value);
|
|
2010
|
-
}
|
|
2011
|
-
const style = element.getAttribute?.('style');
|
|
2012
|
-
if (typeof style === 'string') names.push(style);
|
|
2013
|
-
for (const value of element.getAttributeNames?.() ?? []) {
|
|
2014
|
-
if (value === 'href' || value === 'xlink:href' || value === 'style') continue;
|
|
2015
|
-
const raw = element.getAttribute?.(value);
|
|
2016
|
-
if (typeof raw === 'string') names.push(raw);
|
|
2017
|
-
}
|
|
2018
|
-
for (const raw of names) {
|
|
2019
|
-
for (const match of raw.matchAll(/(?:#|url\()["']?([A-Za-z_][\w.:-]*)/g)) referenced.add(match[1]);
|
|
2020
|
-
}
|
|
2021
|
-
};
|
|
2022
|
-
/* Walk children instead of querySelectorAll: the selector engine is not
|
|
2023
|
-
guaranteed on every node a browser hands back, and a missed child here
|
|
2024
|
-
would drop an id that an icon's <use> still points at. */
|
|
2025
|
-
const eachNode = (root, visit) => {
|
|
2026
|
-
const stack = [root];
|
|
2027
|
-
while (stack.length > 0) {
|
|
2028
|
-
const current = stack.pop();
|
|
2029
|
-
if (current === null || current === undefined) continue;
|
|
2030
|
-
visit(current);
|
|
2031
|
-
const kids = current.children;
|
|
2032
|
-
if (kids === undefined || kids === null) continue;
|
|
2033
|
-
for (const kid of Array.from(kids)) stack.push(kid);
|
|
2034
|
-
}
|
|
2035
|
-
};
|
|
2036
|
-
eachNode(clone, rememberRefs);
|
|
2037
|
-
const dropId = (element) => {
|
|
2038
|
-
const name = element?.getAttribute?.('id');
|
|
2039
|
-
if (typeof name !== 'string' || name === '') return;
|
|
2040
|
-
if (referenced.has(name)) return;
|
|
2041
|
-
try {
|
|
2042
|
-
element.removeAttribute('id');
|
|
2043
|
-
} catch {
|
|
2044
|
-
/* best effort */
|
|
2045
|
-
}
|
|
2046
|
-
};
|
|
2047
|
-
eachNode(clone, dropId);
|
|
2048
|
-
return clone;
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
/** Remember one panel's glyph while its row is still rendered. */
|
|
2052
|
-
function captureMoreGlyph(panelId, row) {
|
|
2053
|
-
const id = String(panelId ?? '');
|
|
2054
|
-
if (id === '') return null;
|
|
2055
|
-
const cached = moreGlyphs.get(id) ?? null;
|
|
2056
|
-
if (cached !== null) return cached;
|
|
2057
|
-
const clone = glyphCloneOf(row);
|
|
2058
|
-
if (clone === null) return null;
|
|
2059
|
-
moreGlyphs.set(id, clone);
|
|
2060
|
-
return clone;
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
|
-
/** Drop every remembered glyph (teardown, and tests). */
|
|
2064
|
-
function clearMoreGlyphs() {
|
|
2065
|
-
moreGlyphs.clear();
|
|
2066
|
-
}
|
|
2067
|
-
|
|
2068
|
-
/**
|
|
2069
|
-
* Copy the host's own panel glyph into one of our menu rows. The icon is the
|
|
2070
|
-
* first child of `span[class*="panelGlyph"]` inside the panel row — cloned at
|
|
2071
|
-
* runtime, never shipped here, so a host redesign keeps working. The
|
|
2072
|
-
* placeholder is emptied first, which makes the host remounting the menu
|
|
2073
|
-
* idempotent; a missing glyph leaves it empty and returns false (silent).
|
|
2074
|
-
*/
|
|
2075
|
-
function mountMoreGlyph(placeholder, doc, label, panelId) {
|
|
2076
|
-
if (placeholder === null || placeholder === undefined) return false;
|
|
2077
|
-
try {
|
|
2078
|
-
while (placeholder.firstChild !== null && placeholder.firstChild !== undefined) {
|
|
2079
|
-
placeholder.removeChild(placeholder.firstChild);
|
|
2080
|
-
}
|
|
2081
|
-
} catch {
|
|
2082
|
-
/* a placeholder we cannot clear is left as it is */
|
|
2083
|
-
}
|
|
2084
|
-
const row = panelRowOf(doc, label);
|
|
2085
|
-
/* A live row is the freshest source and also refreshes the memory; once the
|
|
2086
|
-
host pins a panel away its row disappears, so the remembered clone is what
|
|
2087
|
-
keeps the icon in our menu. */
|
|
2088
|
-
let source = null;
|
|
2089
|
-
if (row !== null) {
|
|
2090
|
-
const fresh = glyphCloneOf(row);
|
|
2091
|
-
if (fresh !== null) {
|
|
2092
|
-
moreGlyphs.set(String(panelId ?? label), fresh);
|
|
2093
|
-
source = fresh;
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2096
|
-
if (source === null) source = moreGlyphs.get(String(panelId ?? label)) ?? null;
|
|
2097
|
-
if (source === null) return false;
|
|
2098
|
-
let clone = null;
|
|
2099
|
-
try {
|
|
2100
|
-
clone = typeof source.cloneNode === 'function' ? source.cloneNode(true) : null;
|
|
2101
|
-
} catch {
|
|
2102
|
-
clone = null;
|
|
2103
|
-
}
|
|
2104
|
-
if (clone === null) return false;
|
|
2105
|
-
try {
|
|
2106
|
-
placeholder.appendChild(clone);
|
|
2107
|
-
} catch {
|
|
2108
|
-
return false;
|
|
2109
|
-
}
|
|
2110
|
-
return true;
|
|
2111
|
-
}
|
|
2112
|
-
|
|
2113
|
-
/**
|
|
2114
|
-
* Hide the panel rows that belong behind the More button. The host keeps its
|
|
2115
|
-
* pins in memory only and re-renders rows on every store change, so this pass
|
|
2116
|
-
* is idempotent, re-applied by the observer after every host redraw, and
|
|
2117
|
-
* undone on teardown. Rows are matched by the same aria-label / title the host
|
|
2118
|
-
* renders; a row we cannot identify is left alone (silent skip).
|
|
2119
|
-
*/
|
|
2120
|
-
function applyFoldState(doc, panels, settings, storageRef, touched) {
|
|
2121
|
-
if (doc === null || typeof doc.querySelectorAll !== 'function') return;
|
|
2122
|
-
const folded = new Set(foldedIdsOf(panels, settings, storageRef));
|
|
2123
|
-
const byLabel = new Map();
|
|
2124
|
-
for (const panel of panels) byLabel.set(panel.label, panel.id);
|
|
2125
|
-
let rows = [];
|
|
2126
|
-
try {
|
|
2127
|
-
rows = Array.from(doc.querySelectorAll('nav[class*="panelList"] button[class*="panelRow"]'));
|
|
2128
|
-
} catch {
|
|
2129
|
-
rows = [];
|
|
2130
|
-
}
|
|
2131
|
-
for (const row of rows) {
|
|
2132
|
-
const label = row.getAttribute?.('aria-label') ?? '';
|
|
2133
|
-
let titleText = '';
|
|
2134
|
-
if (typeof row.querySelector === 'function') {
|
|
2135
|
-
try {
|
|
2136
|
-
const title = row.querySelector('span[class*="panelTitle"]');
|
|
2137
|
-
if (title !== null && title !== undefined) titleText = title.textContent ?? '';
|
|
2138
|
-
} catch {
|
|
2139
|
-
titleText = '';
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
const id = byLabel.get(label) ?? byLabel.get(titleText) ?? null;
|
|
2143
|
-
if (id === null) continue;
|
|
2144
|
-
/* Remember the icon before this row can disappear from the sidebar. */
|
|
2145
|
-
captureMoreGlyph(id, row);
|
|
2146
|
-
const hide = folded.has(id);
|
|
2147
|
-
/* Hide whatever actually wraps both the icon and the text; a bare row button
|
|
2148
|
-
is the normal case, a wrapper is used when the host draws the glyph beside
|
|
2149
|
-
the button. `nav` is never hidden. */
|
|
2150
|
-
const unit = foldUnitOf(row);
|
|
2151
|
-
if (unit === null) continue;
|
|
2152
|
-
const current = unit.style?.display ?? '';
|
|
2153
|
-
if (hide === true && current !== 'none') {
|
|
2154
|
-
if (touched.has(unit) === false) touched.set(unit, current);
|
|
2155
|
-
unit.style.display = 'none';
|
|
2156
|
-
} else if (hide === false) {
|
|
2157
|
-
for (const candidate of [unit, row, row.parentElement ?? null]) {
|
|
2158
|
-
if (candidate === null || candidate === undefined) continue;
|
|
2159
|
-
if (touched.has(candidate) === true) {
|
|
2160
|
-
candidate.style.display = touched.get(candidate);
|
|
2161
|
-
touched.delete(candidate);
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
}
|
|
2165
|
-
}
|
|
2166
|
-
}
|
|
2167
|
-
|
|
2168
|
-
/**
|
|
2169
|
-
* Sample a real host menu item so our rows can borrow its look: the class list
|
|
2170
|
-
* is copied at runtime (never hardcoded) and the fixed dimensions are read from
|
|
2171
|
-
* getComputedStyle. Returns null when the menu is not open yet or the host item
|
|
2172
|
-
* is missing — callers fall back to their own class until it appears.
|
|
2173
|
-
*/
|
|
2174
|
-
function sampleMoreItem(doc) {
|
|
2175
|
-
if (doc === null || typeof doc.querySelectorAll !== 'function') return null;
|
|
2176
|
-
const view = doc.defaultView;
|
|
2177
|
-
if (view === undefined || view === null || typeof view.getComputedStyle !== 'function') return null;
|
|
2178
|
-
let menu = null;
|
|
2179
|
-
try {
|
|
2180
|
-
menu = doc.querySelector('[class*="moreMenu"]');
|
|
2181
|
-
} catch {
|
|
2182
|
-
menu = null;
|
|
2183
|
-
}
|
|
2184
|
-
if (menu === null || menu === undefined) return null;
|
|
2185
|
-
let host = null;
|
|
2186
|
-
try {
|
|
2187
|
-
host =
|
|
2188
|
-
Array.from(menu.querySelectorAll('button')).find((button) => {
|
|
2189
|
-
const cls = button.getAttribute?.('class') ?? '';
|
|
2190
|
-
return cls.includes('uic-') === false;
|
|
2191
|
-
}) ?? null;
|
|
2192
|
-
} catch {
|
|
2193
|
-
host = null;
|
|
2194
|
-
}
|
|
2195
|
-
if (host === null) return null;
|
|
2196
|
-
const cs = view.getComputedStyle(host);
|
|
2197
|
-
if (cs === null || cs === undefined) return null;
|
|
2198
|
-
const pick = (name) => {
|
|
2199
|
-
if (typeof cs.getPropertyValue === 'function') return cs.getPropertyValue(name) ?? '';
|
|
2200
|
-
return cs[name] ?? '';
|
|
2201
|
-
};
|
|
2202
|
-
return {
|
|
2203
|
-
className: host.getAttribute?.('class') ?? '',
|
|
2204
|
-
style: {
|
|
2205
|
-
height: pick('height'),
|
|
2206
|
-
lineHeight: pick('line-height'),
|
|
2207
|
-
paddingLeft: pick('padding-left'),
|
|
2208
|
-
paddingRight: pick('padding-right'),
|
|
2209
|
-
fontSize: pick('font-size'),
|
|
2210
|
-
borderRadius: pick('border-radius'),
|
|
2211
|
-
color: pick('color'),
|
|
2212
|
-
},
|
|
2213
|
-
};
|
|
2214
|
-
}
|
|
2215
|
-
|
|
2216
|
-
/** ids currently behind the More button: foldAll wins, else the record. */
|
|
2217
|
-
function desiredFoldIds(entries, settings, storage) {
|
|
2218
|
-
const ids = entries.map((entry) => entry.id);
|
|
2219
|
-
if (settings?.sidebarMore?.foldAll === true) return computeFold(ids, settings);
|
|
2220
|
-
return cleanFolded(readSidebarMore(storage).folded, ids);
|
|
2221
|
-
}
|
|
2222
|
-
|
|
2223
|
-
/**
|
|
2224
|
-
* The actions a replay would need to take: fold every live entry that is
|
|
2225
|
-
* currently pinned but should be behind More. The host's setPinned is
|
|
2226
|
-
* idempotent (it no-ops on an unchanged pin), so replay is safe to repeat.
|
|
2227
|
-
*/
|
|
2228
|
-
function sidebarMoreReplay(entries, settings, storage) {
|
|
2229
|
-
const wanted = new Set(desiredFoldIds(entries, settings, storage));
|
|
2230
|
-
return entries.filter((entry) => entry.pinned === true && wanted.has(entry.id)).map((entry) => entry.id);
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2233
|
-
/** Write one panel's pin through the host callback and keep the record honest. */
|
|
2234
|
-
function writeSidebarPin(id, pinned, entries, settings, storage) {
|
|
2235
|
-
if (sidebarWrite === null) return;
|
|
2236
|
-
sidebarWrite(id, pinned);
|
|
2237
|
-
const ids = entries.map((entry) => entry.id);
|
|
2238
|
-
const record = cleanFolded(readSidebarMore(storage).folded, ids);
|
|
2239
|
-
const next = pinned ? record.filter((entry) => entry !== id) : record.includes(id) ? record : [...record, id];
|
|
2240
|
-
writeSidebarMore(storage, next);
|
|
2241
|
-
}
|
|
2242
|
-
|
|
2243
|
-
/**
|
|
2244
|
-
* The More menu rows. Rendered by the host inside its own Menu portal; we own
|
|
2245
|
-
* nothing but these rows. position:fixed is forbidden here (the portal may
|
|
2246
|
-
* be anywhere); the host handles placement.
|
|
2247
|
-
*/
|
|
2248
|
-
function SidebarMoreMenu(props) {
|
|
2249
|
-
const entries = Array.isArray(props.entries) ? props.entries : [];
|
|
2250
|
-
const onOpen = typeof props.onOpen === 'function' ? props.onOpen : () => {};
|
|
2251
|
-
const onDismiss = typeof props.onDismiss === 'function' ? props.onDismiss : () => {};
|
|
2252
|
-
const write = typeof props.onPinnedChange === 'function' ? props.onPinnedChange : null;
|
|
2253
|
-
const t = translator(localeScope());
|
|
2254
|
-
sidebarWrite = write;
|
|
2255
|
-
sidebarPanels = entries.map((entry) => entry.id);
|
|
2256
|
-
const settings = readSettings();
|
|
2257
|
-
const storageRef = storage();
|
|
2258
|
-
const record = readSidebarMore(storageRef).folded;
|
|
2259
|
-
const ids = entries.map((entry) => entry.id);
|
|
2260
|
-
const doc = typeof document === 'undefined' ? null : document;
|
|
2261
|
-
const [sampled, setSampled] = React.useState(null);
|
|
2262
|
-
|
|
2263
|
-
/* First render: fold whatever the record / foldAll asks for. The host
|
|
2264
|
-
re-renders the menu with the new pins, and its guard makes the second
|
|
2265
|
-
pass a no-op, so deferring to a microtask keeps us out of the render
|
|
2266
|
-
cycle. */
|
|
2267
|
-
if (write !== null && sidebarReplayQueued === false) {
|
|
2268
|
-
sidebarReplayQueued = true;
|
|
2269
|
-
if (typeof setTimeout === 'function') {
|
|
2270
|
-
setTimeout(() => {
|
|
2271
|
-
for (const id of sidebarMoreReplay(entries, readSettings(), storageRef)) write(id, false);
|
|
2272
|
-
}, 0);
|
|
2273
|
-
} else {
|
|
2274
|
-
for (const id of sidebarMoreReplay(entries, settings, storageRef)) write(id, false);
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
|
|
2278
|
-
/* The host menu items share this list, so borrowing their class list is what
|
|
2279
|
-
makes our rows look host-drawn. The sample cannot wait for a setTimeout
|
|
2280
|
-
tick: that painted the fallback row for one frame and the switch was
|
|
2281
|
-
visible. React runs ref callbacks after the whole menu is in the DOM and
|
|
2282
|
-
before the browser paints, so the first row's ref takes the sample there
|
|
2283
|
-
and the fallback class never reaches the screen. */
|
|
2284
|
-
const ensureSample = () => {
|
|
2285
|
-
if (sampled !== null) return true;
|
|
2286
|
-
const taken = sampleMoreItem(doc);
|
|
2287
|
-
if (taken === null) return false;
|
|
2288
|
-
setSampled(taken);
|
|
2289
|
-
return true;
|
|
2290
|
-
};
|
|
2291
|
-
|
|
2292
|
-
/**
|
|
2293
|
-
* Flip one panel. `folded` is the state the row is showing: true means the
|
|
2294
|
-
* panel is behind More right now, which may be foldAll talking rather than
|
|
2295
|
-
* the record — so freeing it also has to switch foldAll off, and folding it
|
|
2296
|
-
* back is a plain record write. Both branches leave the record consistent
|
|
2297
|
-
* with what the row will show on the next pass.
|
|
2298
|
-
*/
|
|
2299
|
-
const flipPanel = (id, folded) => {
|
|
2300
|
-
const ids = entries.map((item) => item.id);
|
|
2301
|
-
if (folded === false) {
|
|
2302
|
-
writeSidebarPin(id, false, entries, settings, storageRef);
|
|
2303
|
-
return;
|
|
2304
|
-
}
|
|
2305
|
-
const onlyOutside = ids.filter((item) => item !== 'plugins' && item !== id);
|
|
2306
|
-
/* Ask the host to put this row outside first — folding is derived from
|
|
2307
|
-
foldAll and the record, so skipping the host call leaves the panel
|
|
2308
|
-
hidden by the host's own pin state and it never comes back. */
|
|
2309
|
-
writeSidebarPin(id, true, entries, settings, storageRef);
|
|
2310
|
-
writeSettings({ ...readSettings(), sidebarMore: { foldAll: false } });
|
|
2311
|
-
writeSidebarMore(storageRef, cleanFolded(onlyOutside, ids));
|
|
2312
|
-
};
|
|
2313
|
-
|
|
2314
|
-
const wanted = new Set(desiredFoldIds(entries, settings, storageRef));
|
|
2315
|
-
const rowClass = sampled !== null && sampled.className !== '' ? sampled.className : 'uic-moreRow';
|
|
2316
|
-
const rowStyle = sampled !== null
|
|
2317
|
-
? { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px', width: '100%', boxSizing: 'border-box' }
|
|
2318
|
-
: null;
|
|
2319
|
-
|
|
2320
|
-
return node('div', { key: 'more', 'data-uic-sidebar-more-menu': '1' }, [
|
|
2321
|
-
...entries.map((entry) => {
|
|
2322
|
-
const folded = wanted.has(entry.id);
|
|
2323
|
-
return node('button', {
|
|
2324
|
-
key: entry.id,
|
|
2325
|
-
type: 'button',
|
|
2326
|
-
className: rowClass,
|
|
2327
|
-
style: rowStyle,
|
|
2328
|
-
ref: ensureSample,
|
|
2329
|
-
'data-uic-more-row': entry.id,
|
|
2330
|
-
onClick: () => { onOpen(entry.id); onDismiss(); },
|
|
2331
|
-
}, [
|
|
2332
|
-
node('span', { key: 'main', className: 'uic-moreRowMain' }, [
|
|
2333
|
-
node('span', {
|
|
2334
|
-
key: 'glyph',
|
|
2335
|
-
className: 'uic-moreGlyph',
|
|
2336
|
-
'data-uic-more-glyph': entry.id,
|
|
2337
|
-
/* The host owns the icon: copy it from the live sidebar row once this
|
|
2338
|
-
placeholder is in the document. Refilled on every mount, so a host
|
|
2339
|
-
remount cannot stack copies. */
|
|
2340
|
-
ref: (element) => {
|
|
2341
|
-
if (element === null || element === undefined) return;
|
|
2342
|
-
mountMoreGlyph(element, doc, entry.label, entry.id);
|
|
2343
|
-
},
|
|
2344
|
-
}, []),
|
|
2345
|
-
node('span', { key: 'name', className: 'uic-moreRowName' }, entry.label),
|
|
2346
|
-
]),
|
|
2347
|
-
node('span', {
|
|
2348
|
-
key: 'toggle',
|
|
2349
|
-
className: 'uic-moreToggle',
|
|
2350
|
-
'data-uic-more-pin': entry.id,
|
|
2351
|
-
role: 'button',
|
|
2352
|
-
tabIndex: 0,
|
|
2353
|
-
onClick: (event) => {
|
|
2354
|
-
event.stopPropagation();
|
|
2355
|
-
flipPanel(entry.id, folded);
|
|
2356
|
-
},
|
|
2357
|
-
onKeyDown: (event) => {
|
|
2358
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
2359
|
-
event.preventDefault();
|
|
2360
|
-
event.stopPropagation();
|
|
2361
|
-
flipPanel(entry.id, folded);
|
|
2362
|
-
}
|
|
2363
|
-
},
|
|
2364
|
-
}, folded === true ? t('settings.sidebarMore.unfold') : t('settings.sidebarMore.fold')),
|
|
2365
|
-
]);
|
|
2366
|
-
}),
|
|
2367
|
-
]);
|
|
2368
|
-
}
|
|
2369
|
-
|
|
2370
|
-
/** Restore the host's own launcher label. Older builds painted a folded count
|
|
2371
|
-
* onto the title span ("更多 (2)"); the counter is gone now, so this pass makes
|
|
2372
|
-
* sure the span always reads exactly what the aria-label says. Idempotent: it
|
|
2373
|
-
* only writes when the text differs, and it never adds a number itself.
|
|
2374
|
-
*/
|
|
2375
|
-
function normalizeMoreTitle(doc) {
|
|
2376
|
-
if (doc === null || typeof doc.querySelectorAll !== 'function') return;
|
|
2377
|
-
let candidates = [];
|
|
2378
|
-
try {
|
|
2379
|
-
candidates = Array.from(doc.querySelectorAll('button[aria-label="更多"], button[aria-label="More"]'));
|
|
2380
|
-
} catch {
|
|
2381
|
-
candidates = [];
|
|
2382
|
-
}
|
|
2383
|
-
const launcher = candidates.find((button) => {
|
|
2384
|
-
if (button.getAttribute === undefined) return false;
|
|
2385
|
-
if (MORE_TITLES.has(button.getAttribute('aria-label')) === false) return false;
|
|
2386
|
-
let parent = button.parentElement ?? null;
|
|
2387
|
-
while (parent !== null) {
|
|
2388
|
-
const cls = parent.getAttribute?.('class') ?? '';
|
|
2389
|
-
if (cls.includes('panelList')) return true;
|
|
2390
|
-
parent = parent.parentElement;
|
|
2391
|
-
}
|
|
2392
|
-
return false;
|
|
2393
|
-
});
|
|
2394
|
-
if (launcher === undefined) return;
|
|
2395
|
-
let title = null;
|
|
2396
|
-
if (typeof launcher.querySelector === 'function') {
|
|
2397
|
-
try {
|
|
2398
|
-
title = launcher.querySelector('span[class*="panelTitle"]');
|
|
2399
|
-
} catch {
|
|
2400
|
-
title = null;
|
|
2401
|
-
}
|
|
2402
|
-
}
|
|
2403
|
-
if (title === null || title === undefined) return;
|
|
2404
|
-
const base = launcher.getAttribute('aria-label') ?? '';
|
|
2405
|
-
if (title.textContent !== base) title.textContent = base;
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
1761
|
/**
|
|
2409
1762
|
* Wheel damping for the chat scroller.
|
|
2410
1763
|
*
|
|
@@ -2625,61 +1978,6 @@ window.__ModuleLoader__.load({
|
|
|
2625
1978
|
|
|
2626
1979
|
const inventory = () => slotRows(entriesOf, readSettings(), runtimeCatalog(slots));
|
|
2627
1980
|
|
|
2628
|
-
const sidebarPanelsOf = () =>
|
|
2629
|
-
entriesOf('sidebar.panellist')
|
|
2630
|
-
.map((entry) => ({ id: String(entry?.options?.id ?? ''), label: entryLabelOf(entry) }))
|
|
2631
|
-
.filter((panel) => panel.id !== '');
|
|
2632
|
-
const normalizeTitle = () => normalizeMoreTitle(doc);
|
|
2633
|
-
const applyFold = () => applyFoldState(doc, sidebarPanelsOf(), readSettings(), storage(), moreTouched); ctx.effect(() => () => clearMoreGlyphs(), 'ui-controller: forget sampled glyphs');
|
|
2634
|
-
|
|
2635
|
-
/* One slot only, and only after it is declared: the inject callback itself
|
|
2636
|
-
only fires once the host declares the slot, so the guard is belt and
|
|
2637
|
-
braces (dsh-plugin-dev §13). */
|
|
2638
|
-
ctx.effect(
|
|
2639
|
-
() =>
|
|
2640
|
-
ctx.slots.inject(SIDEBAR_MORE_SLOT, () => {
|
|
2641
|
-
if (typeof ctx.slots.spec === 'function' && ctx.slots.spec(SIDEBAR_MORE_SLOT) === undefined) return () => {};
|
|
2642
|
-
return ctx.slots.register(
|
|
2643
|
-
{
|
|
2644
|
-
name: SIDEBAR_MORE_SLOT,
|
|
2645
|
-
id: SIDEBAR_MORE_ID,
|
|
2646
|
-
order: SIDEBAR_MORE_ORDER,
|
|
2647
|
-
locale: NS,
|
|
2648
|
-
label: () => t('settings.sidebarMore.title'),
|
|
2649
|
-
},
|
|
2650
|
-
(props) => h(SidebarMoreMenu, props),
|
|
2651
|
-
);
|
|
2652
|
-
}),
|
|
2653
|
-
'ui-controller: sidebar more',
|
|
2654
|
-
);
|
|
2655
|
-
|
|
2656
|
-
/* Host pins are memory-only; a reload loses them. The record replays through
|
|
2657
|
-
the write entry captured by the menu (null until the menu has rendered
|
|
2658
|
-
once), so subscribe on every panellist change and try. */
|
|
2659
|
-
if (typeof slots?.subscribe === 'function') {
|
|
2660
|
-
ctx.effect(() => slots.subscribe('sidebar.panellist', () => {
|
|
2661
|
-
const write = sidebarWrite;
|
|
2662
|
-
if (write === null) return;
|
|
2663
|
-
const settings = readSettings();
|
|
2664
|
-
const entries = sidebarPanels.map((panel) => ({ id: panel.id, pinned: true }));
|
|
2665
|
-
for (const id of sidebarMoreReplay(entries, settings, storage())) write(id, false);
|
|
2666
|
-
}), 'ui-controller: sidebar more replay');
|
|
2667
|
-
}
|
|
2668
|
-
|
|
2669
|
-
/* Count label: an observer catches the launcher appearing/re-rendering, and
|
|
2670
|
-
the 2s pass below is the fallback. */
|
|
2671
|
-
let moreObserver = null;
|
|
2672
|
-
if (doc !== null && typeof doc.body?.addEventListener === 'function' && typeof MutationObserver === 'function') {
|
|
2673
|
-
try {
|
|
2674
|
-
moreObserver = new MutationObserver(() => { applyFold(); normalizeTitle(); });
|
|
2675
|
-
moreObserver.observe(doc.body, { childList: true, subtree: true });
|
|
2676
|
-
} catch {
|
|
2677
|
-
moreObserver = null;
|
|
2678
|
-
}
|
|
2679
|
-
}
|
|
2680
|
-
applyFold();
|
|
2681
|
-
normalizeTitle();
|
|
2682
|
-
|
|
2683
1981
|
let pickHandler = null;
|
|
2684
1982
|
|
|
2685
1983
|
const applyHidden = () => {
|
|
@@ -2725,13 +2023,6 @@ window.__ModuleLoader__.load({
|
|
|
2725
2023
|
|
|
2726
2024
|
injectStyle(doc);
|
|
2727
2025
|
ctx.effect(() => () => {
|
|
2728
|
-
if (moreObserver !== null && typeof moreObserver.disconnect === 'function') moreObserver.disconnect(); for (const [row, original] of moreTouched) {
|
|
2729
|
-
if (row.style !== undefined) row.style.display = original;
|
|
2730
|
-
}
|
|
2731
|
-
moreTouched.clear();
|
|
2732
|
-
sidebarWrite = null;
|
|
2733
|
-
sidebarPanels = [];
|
|
2734
|
-
sidebarReplayQueued = false;
|
|
2735
2026
|
stopPicking();
|
|
2736
2027
|
chatDamping.stop('teardown');
|
|
2737
2028
|
removeStyle(doc);
|
|
@@ -2756,8 +2047,6 @@ window.__ModuleLoader__.load({
|
|
|
2756
2047
|
const current = readSettings();
|
|
2757
2048
|
applyHidden();
|
|
2758
2049
|
applyVisualOrder(doc, current, ordered);
|
|
2759
|
-
applyFold();
|
|
2760
|
-
normalizeTitle();
|
|
2761
2050
|
chatDamping.sync(current);
|
|
2762
2051
|
}; applyAll();
|
|
2763
2052
|
const timer = setInterval(applyAll, 2000);
|
|
@@ -2872,28 +2161,6 @@ window.__ModuleLoader__.load({
|
|
|
2872
2161
|
isOpen,
|
|
2873
2162
|
toggleOpen,
|
|
2874
2163
|
resetOpen,
|
|
2875
|
-
SIDEBAR_MORE_KEY,
|
|
2876
|
-
SIDEBAR_MORE_SLOT,
|
|
2877
|
-
SIDEBAR_MORE_ID,
|
|
2878
|
-
SIDEBAR_MORE_MODAL,
|
|
2879
|
-
readSidebarMore,
|
|
2880
|
-
writeSidebarMore,
|
|
2881
|
-
cleanFolded,
|
|
2882
|
-
computeFold,
|
|
2883
|
-
sidebarMoreReplay,
|
|
2884
|
-
normalizeMoreTitle,
|
|
2885
|
-
glyphCloneOf, glyphCloneOf,
|
|
2886
|
-
desiredFoldIds,
|
|
2887
|
-
foldedIdsOf,
|
|
2888
|
-
entryLabelOf,
|
|
2889
|
-
applyFoldState,
|
|
2890
|
-
clearMoreGlyphs,
|
|
2891
|
-
foldUnitOf,
|
|
2892
|
-
glyphIconNodeOf,
|
|
2893
|
-
mountMoreGlyph,
|
|
2894
|
-
panelRowOf,
|
|
2895
|
-
sampleMoreItem,
|
|
2896
|
-
SidebarMoreMenu,
|
|
2897
2164
|
DICTS,
|
|
2898
2165
|
CHAT_SCROLL_SELECTOR,
|
|
2899
2166
|
CHAT_SCROLL_K,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ui-controller",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Inspect and control the UI other plugins register into DeepSeek Harness slots (visibility, order, mirrored entries)
|
|
3
|
+
"version": "0.2.8",
|
|
4
|
+
"description": "Inspect and control the UI other plugins register into DeepSeek Harness slots (visibility, order, mirrored entries).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "MeruSu"
|