dsh-ui-controller 0.1.1 → 0.2.2
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 +64 -0
- package/README.md +43 -34
- package/client.js +697 -234
- package/package.json +46 -46
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.2';
|
|
31
31
|
|
|
32
32
|
const NS = 'uiController';
|
|
33
33
|
const SECTION_ID = 'ui-controller';
|
|
@@ -76,9 +76,16 @@ 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-moreRowMain{display:flex;align-items:center;gap:8px;min-width:0;flex:1 1 auto}',
|
|
85
|
+
'.uic-moreGlyph{display:inline-flex;align-items:center;justify-content:center;flex:none;width:16px;height:16px;overflow:hidden}',
|
|
86
|
+
'.uic-moreGlyph>svg,.uic-moreGlyph>img{width:16px;height:16px;display:block}',
|
|
87
|
+
'.uic-moreAction{flex:none;padding:2px 8px;font-size:12px;border:1px solid var(--dsw-alias-border-l4);border-radius:6px;cursor:pointer}',
|
|
88
|
+
'.uic-moreAction:hover{background:var(--dsw-alias-bg-layer-2)}',
|
|
82
89
|
'.uic-zone{border-top:.5px solid var(--dsw-alias-border-l2);padding:2px 0}',
|
|
83
90
|
'.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
91
|
'.uic-zoneName{flex:none}',
|
|
@@ -105,96 +112,64 @@ const PAGE_CSS = [
|
|
|
105
112
|
|
|
106
113
|
/* ------------------------------------------------- settings page left rail */
|
|
107
114
|
|
|
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
115
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const SIDEBAR_MORE_KEY = 'dsh.uic.sidebarMore.v1';
|
|
117
|
+
const SIDEBAR_MORE_SLOT = 'sidebar.panellist.actions';
|
|
118
|
+
const SIDEBAR_MORE_ID = 'ui-controller.sidebar-more';
|
|
119
|
+
const SIDEBAR_MORE_ORDER = 0;
|
|
120
|
+
const SIDEBAR_MORE_MODAL = '[data-shortcut-modal="sidebar"]';
|
|
121
|
+
const MORE_TITLES = new Set(['更多', 'More']);
|
|
118
122
|
|
|
119
123
|
/**
|
|
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.
|
|
124
|
+
* The folded record: which panel ids the More menu currently hides.
|
|
125
|
+
* The host keeps its pins in memory only (dsh-client-ui-sidebar
|
|
126
|
+
* createPanelPins), so a reload would put every panel back outside;
|
|
127
|
+
* this record is what a reload replays.
|
|
138
128
|
*/
|
|
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';
|
|
129
|
+
function readSidebarMore(storage) {
|
|
130
|
+
const store = storage ?? null;
|
|
131
|
+
if (store === null || typeof store.getItem !== 'function') return { folded: [] };
|
|
132
|
+
try {
|
|
133
|
+
const raw = store.getItem(SIDEBAR_MORE_KEY);
|
|
134
|
+
if (raw === null || raw === undefined || raw === '') return { folded: [] };
|
|
135
|
+
const parsed = JSON.parse(raw);
|
|
136
|
+
if (isPlainObject(parsed) === false || Array.isArray(parsed.folded) === false) return { folded: [] };
|
|
137
|
+
return { folded: parsed.folded.filter((id) => typeof id === 'string' && id !== '') };
|
|
138
|
+
} catch {
|
|
139
|
+
return { folded: [] };
|
|
140
|
+
}
|
|
159
141
|
}
|
|
160
142
|
|
|
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;
|
|
143
|
+
function writeSidebarMore(storage, folded) {
|
|
144
|
+
const store = storage ?? null;
|
|
145
|
+
if (store === null || typeof store.setItem !== 'function') return;
|
|
173
146
|
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;
|
|
147
|
+
store.setItem(SIDEBAR_MORE_KEY, JSON.stringify({ folded }));
|
|
182
148
|
} catch {
|
|
183
|
-
|
|
149
|
+
/* a full quota must not take the page down */
|
|
184
150
|
}
|
|
185
151
|
}
|
|
186
152
|
|
|
153
|
+
/** Folded ids that still name a live panel; the rest are stale and dropped. */
|
|
154
|
+
function cleanFolded(folded, panels) {
|
|
155
|
+
const live = new Set(panels);
|
|
156
|
+
return folded.filter((id) => live.has(id));
|
|
157
|
+
}
|
|
158
|
+
|
|
187
159
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* point of following.
|
|
160
|
+
* What a fresh install looks like: with foldAll on, every panel except
|
|
161
|
+
* plugins goes behind the More button (the shape the user asked for).
|
|
162
|
+
* Off means nothing folds — but the stored record is never erased here, so
|
|
163
|
+
* turning the switch back on restores it (see the menu's replay).
|
|
193
164
|
*/
|
|
194
|
-
function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
165
|
+
function computeFold(panels, settings) {
|
|
166
|
+
if (settings?.sidebarMore?.foldAll === true) return panels.filter((id) => id !== 'plugins');
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** The More launcher's text: "更多 (3)", and the bare label at zero. */
|
|
171
|
+
function moreLabel(base, count) {
|
|
172
|
+
return count > 0 ? base + ' (' + count + ')' : base;
|
|
198
173
|
}
|
|
199
174
|
|
|
200
175
|
const PRESET_NAME_MAX = 40;
|
|
@@ -353,7 +328,7 @@ function defaultSettings() {
|
|
|
353
328
|
visualOrder: {},
|
|
354
329
|
presets: {},
|
|
355
330
|
activePreset: null,
|
|
356
|
-
|
|
331
|
+
sidebarMore: { foldAll: true },
|
|
357
332
|
};
|
|
358
333
|
}
|
|
359
334
|
|
|
@@ -442,14 +417,6 @@ function sanitizePresets(raw) {
|
|
|
442
417
|
}
|
|
443
418
|
|
|
444
419
|
/** `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
420
|
function sanitizeSettings(raw) {
|
|
454
421
|
const base = defaultSettings();
|
|
455
422
|
if (isPlainObject(raw) === false) return base;
|
|
@@ -459,7 +426,7 @@ function sanitizeSettings(raw) {
|
|
|
459
426
|
next.visualOrder = sanitizeVisualOrder(raw.visualOrder ?? raw.order);
|
|
460
427
|
next.presets = sanitizePresets(raw.presets);
|
|
461
428
|
next.activePreset = typeof raw.activePreset === 'string' && hasOwn(next.presets, raw.activePreset) ? raw.activePreset : null;
|
|
462
|
-
next.
|
|
429
|
+
next.sidebarMore = isPlainObject(raw.sidebarMore) ? { foldAll: raw.sidebarMore.foldAll !== false } : { foldAll: true };
|
|
463
430
|
return next;
|
|
464
431
|
}
|
|
465
432
|
|
|
@@ -547,7 +514,7 @@ function patchSettings(patch) {
|
|
|
547
514
|
visualOrder,
|
|
548
515
|
presets: isPlainObject(patch.presets) ? patch.presets : base.presets,
|
|
549
516
|
activePreset: hasOwn(patch, 'activePreset') ? patch.activePreset : base.activePreset,
|
|
550
|
-
|
|
517
|
+
sidebarMore: { ...(isPlainObject(base.sidebarMore) ? base.sidebarMore : {}), ...(isPlainObject(patch.sidebarMore) ? patch.sidebarMore : {}) },
|
|
551
518
|
});
|
|
552
519
|
}
|
|
553
520
|
|
|
@@ -1083,14 +1050,13 @@ const ZH = {
|
|
|
1083
1050
|
'settings.filter.unbound': '未绑定',
|
|
1084
1051
|
'settings.filterCount': '{slots} 槽 · {entries} entry',
|
|
1085
1052
|
'settings.noMatch': '没有匹配的座位。',
|
|
1086
|
-
'settings.
|
|
1087
|
-
'settings.
|
|
1088
|
-
'settings.
|
|
1089
|
-
'settings.
|
|
1090
|
-
'settings.
|
|
1091
|
-
'settings.
|
|
1092
|
-
'settings.
|
|
1093
|
-
'settings.nav.now': '当前选择:{width}px。',
|
|
1053
|
+
'settings.sidebarMore.title': '左栏「更多」',
|
|
1054
|
+
'settings.sidebarMore.hint': '新装即把除「插件」外的面板都收进左侧「更多 (N)」;关掉 = 全部放回外面(记录保留,下次开回来还原)。',
|
|
1055
|
+
'settings.sidebarMore.foldAll': '新装即全部折叠',
|
|
1056
|
+
'settings.sidebarMore.fold': '收进更多',
|
|
1057
|
+
'settings.sidebarMore.unfold': '放到外面',
|
|
1058
|
+
'settings.sidebarMore.foldAllAction': '全部收进更多',
|
|
1059
|
+
'settings.sidebarMore.unfoldAllAction': '全部放回外面',
|
|
1094
1060
|
};
|
|
1095
1061
|
|
|
1096
1062
|
const EN = {
|
|
@@ -1145,14 +1111,13 @@ const EN = {
|
|
|
1145
1111
|
'settings.filter.unbound': 'Unbound',
|
|
1146
1112
|
'settings.filterCount': '{slots} slots · {entries} entries',
|
|
1147
1113
|
'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.',
|
|
1114
|
+
'settings.sidebarMore.title': 'Sidebar More',
|
|
1115
|
+
'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).',
|
|
1116
|
+
'settings.sidebarMore.foldAll': 'Fold everything on a fresh install',
|
|
1117
|
+
'settings.sidebarMore.fold': 'Fold into More',
|
|
1118
|
+
'settings.sidebarMore.unfold': 'Show outside',
|
|
1119
|
+
'settings.sidebarMore.foldAllAction': 'Fold all into More',
|
|
1120
|
+
'settings.sidebarMore.unfoldAllAction': 'Put all back outside',
|
|
1156
1121
|
};
|
|
1157
1122
|
|
|
1158
1123
|
const DICTS = { zh: ZH, en: EN };
|
|
@@ -1186,7 +1151,7 @@ function node(tagName, props, children) {
|
|
|
1186
1151
|
|
|
1187
1152
|
function injectStyle(doc) {
|
|
1188
1153
|
if (doc === null || doc === undefined) return;
|
|
1189
|
-
const css = HIDE_CSS + '\n' + PAGE_CSS
|
|
1154
|
+
const css = HIDE_CSS + '\n' + PAGE_CSS;
|
|
1190
1155
|
const existing = typeof doc.getElementById === 'function' ? doc.getElementById(STYLE_ID) : null;
|
|
1191
1156
|
/* A reloaded plugin can find the stylesheet its previous instance left behind.
|
|
1192
1157
|
Rewriting it keeps the three rule groups from drifting apart. */
|
|
@@ -1208,75 +1173,6 @@ function removeStyle(doc) {
|
|
|
1208
1173
|
if (existing !== null && existing !== undefined && typeof existing.remove === 'function') existing.remove();
|
|
1209
1174
|
}
|
|
1210
1175
|
|
|
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
1176
|
/* ---------------------------------------------------------------- grouping */
|
|
1281
1177
|
|
|
1282
1178
|
const RISK_RISKY = 'shadows-shipped-ui';
|
|
@@ -1727,52 +1623,20 @@ function settingsPage(props) {
|
|
|
1727
1623
|
|
|
1728
1624
|
const presetNames = Object.keys(state.presets).sort();
|
|
1729
1625
|
|
|
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' }, [
|
|
1626
|
+
const foldAllOn = state.sidebarMore?.foldAll !== false;
|
|
1627
|
+
const sidebarMoreBlock = node('div', { key: 'sidebarMore', className: 'uic-sidebarMore', 'data-uic-sidebar-more': '1' }, [
|
|
1628
|
+
node('h3', { key: 'h', className: 'uic-h3' }, t('settings.sidebarMore.title')),
|
|
1629
|
+
node('p', { key: 'hint', className: 'uic-dim' }, t('settings.sidebarMore.hint')),
|
|
1630
|
+
node('label', { key: 'fold', className: 'uic-sidebarMoreRow' }, [
|
|
1742
1631
|
node('input', {
|
|
1743
1632
|
key: 'box',
|
|
1744
1633
|
type: 'checkbox',
|
|
1745
|
-
'data-uic-
|
|
1746
|
-
checked:
|
|
1747
|
-
onChange: (event) =>
|
|
1634
|
+
'data-uic-sidebar-more-foldall': foldAllOn ? 'true' : 'false',
|
|
1635
|
+
checked: foldAllOn,
|
|
1636
|
+
onChange: (event) => commit({ ...state, sidebarMore: { ...(isPlainObject(state.sidebarMore) ? state.sidebarMore : {}), foldAll: event.target.checked === true } }),
|
|
1748
1637
|
}),
|
|
1749
|
-
node('span', { key: 'text' }, t('settings.
|
|
1638
|
+
node('span', { key: 'text' }, t('settings.sidebarMore.foldAll')),
|
|
1750
1639
|
]),
|
|
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
1640
|
]);
|
|
1777
1641
|
|
|
1778
1642
|
return node('div', { className: 'uic-page', 'data-uic-page': '1' }, [
|
|
@@ -1858,11 +1722,532 @@ function settingsPage(props) {
|
|
|
1858
1722
|
)),
|
|
1859
1723
|
node('p', { key: 'order-hint', className: 'uic-dim' }, t('settings.orderHint')),
|
|
1860
1724
|
node('p', { key: 'order-hint-2', className: 'uic-dim' }, t('settings.orderHint2')),
|
|
1861
|
-
|
|
1725
|
+
sidebarMoreBlock,
|
|
1862
1726
|
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
1727
|
]);
|
|
1864
1728
|
}
|
|
1865
1729
|
|
|
1730
|
+
|
|
1731
|
+
/* -------------------------------------------------- sidebar More menu */
|
|
1732
|
+
|
|
1733
|
+
/** Module state shared by the menu and the replay paths. */
|
|
1734
|
+
let sidebarWrite = null;
|
|
1735
|
+
let sidebarPanels = [];
|
|
1736
|
+
let sidebarReplayQueued = false;
|
|
1737
|
+
|
|
1738
|
+
/** Elements this session hid and the launcher title it rewrote; both are restored on teardown. */
|
|
1739
|
+
const moreTouched = new Map();
|
|
1740
|
+
/* Cloned panel glyphs, remembered per panel id: the host stops rendering a
|
|
1741
|
+
panel's row once it is pinned away, so the icon has to be kept from the last
|
|
1742
|
+
time that row was on screen. */
|
|
1743
|
+
const moreGlyphs = new Map();
|
|
1744
|
+
const moreTitle = { title: null, original: null };
|
|
1745
|
+
|
|
1746
|
+
/** Resolve a panel entry's label the way the host does (thunk first, then string, then id). */
|
|
1747
|
+
function entryLabelOf(entry) {
|
|
1748
|
+
const raw = entry?.options?.label ?? entry?.label;
|
|
1749
|
+
if (typeof raw === 'function') {
|
|
1750
|
+
try {
|
|
1751
|
+
const value = raw();
|
|
1752
|
+
if (typeof value === 'string' && value !== '') return value;
|
|
1753
|
+
} catch {
|
|
1754
|
+
/* a locale-bound thunk may throw before the host binds it; fall through */
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
if (typeof raw === 'string' && raw !== '') return raw;
|
|
1758
|
+
return String(entry?.options?.id ?? entry?.id ?? '');
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
/** ids that should be behind the More button right now (foldAll wins, plugins never folds). */
|
|
1762
|
+
function foldedIdsOf(panels, settings, storageRef) {
|
|
1763
|
+
const ids = panels.map((panel) => panel.id);
|
|
1764
|
+
return desiredFoldIds(
|
|
1765
|
+
panels.map((panel) => ({ id: panel.id })),
|
|
1766
|
+
settings,
|
|
1767
|
+
storageRef,
|
|
1768
|
+
).filter((id) => id !== 'plugins');
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
/**
|
|
1772
|
+
* The host sidebar row for one panel: matched by its own aria-label first, then
|
|
1773
|
+
* by the rendered title. Returns null while the row is not on screen yet.
|
|
1774
|
+
*/
|
|
1775
|
+
function panelRowOf(doc, label) {
|
|
1776
|
+
if (doc === null || doc === undefined || typeof doc.querySelectorAll !== 'function') return null;
|
|
1777
|
+
let rows = [];
|
|
1778
|
+
try {
|
|
1779
|
+
rows = Array.from(doc.querySelectorAll('nav[class*="panelList"] button[class*="panelRow"]'));
|
|
1780
|
+
} catch {
|
|
1781
|
+
rows = [];
|
|
1782
|
+
}
|
|
1783
|
+
for (const row of rows) {
|
|
1784
|
+
const aria = row.getAttribute?.('aria-label') ?? '';
|
|
1785
|
+
if (aria !== '' && aria === label) return row;
|
|
1786
|
+
if (typeof row.querySelector !== 'function') continue;
|
|
1787
|
+
try {
|
|
1788
|
+
const title = row.querySelector('span[class*="panelTitle"]');
|
|
1789
|
+
if (title !== null && title !== undefined && (title.textContent ?? '') === label) return row;
|
|
1790
|
+
} catch {
|
|
1791
|
+
/* a row we cannot read is simply not a match */
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
return null;
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
/**
|
|
1798
|
+
* The element that has to disappear when a panel folds. Usually that is the row
|
|
1799
|
+
* button itself (the host draws the glyph inside it), but a panel whose icon is
|
|
1800
|
+
* rendered beside the button would leave the icon behind, so the wrapper that
|
|
1801
|
+
* holds both is hidden instead. `nav` is never a folding unit.
|
|
1802
|
+
*/
|
|
1803
|
+
function foldUnitOf(row) {
|
|
1804
|
+
if (row === null || row === undefined) return null;
|
|
1805
|
+
let glyph = null;
|
|
1806
|
+
try {
|
|
1807
|
+
glyph = typeof row.querySelector === 'function' ? row.querySelector('span[class*="panelGlyph"]') : null;
|
|
1808
|
+
} catch {
|
|
1809
|
+
glyph = null;
|
|
1810
|
+
}
|
|
1811
|
+
if (glyph !== null && glyph !== undefined) return row;
|
|
1812
|
+
const parent = row.parentElement ?? null;
|
|
1813
|
+
if (parent === null) return row;
|
|
1814
|
+
if (String(parent.tagName ?? '').toUpperCase() === 'NAV') return row;
|
|
1815
|
+
let parentGlyph = null;
|
|
1816
|
+
try {
|
|
1817
|
+
parentGlyph = typeof parent.querySelector === 'function' ? parent.querySelector('span[class*="panelGlyph"]') : null;
|
|
1818
|
+
} catch {
|
|
1819
|
+
parentGlyph = null;
|
|
1820
|
+
}
|
|
1821
|
+
return parentGlyph !== null && parentGlyph !== undefined ? parent : row;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
/**
|
|
1825
|
+
* The node that actually draws the icon inside a host glyph span. The host puts
|
|
1826
|
+
* its slot anchor (`div[data-slot]` with `display: contents`) in between, so
|
|
1827
|
+
* the first child is a 0x0 wrapper; cloning that would duplicate a slot marker.
|
|
1828
|
+
* Returns the first svg / img / canvas inside it, or the first child itself when
|
|
1829
|
+
* the icon is drawn some other way.
|
|
1830
|
+
*/
|
|
1831
|
+
function glyphIconNodeOf(glyph) {
|
|
1832
|
+
if (glyph === null || glyph === undefined) return null;
|
|
1833
|
+
const start = glyph.firstElementChild ?? null;
|
|
1834
|
+
if (start === null) return null;
|
|
1835
|
+
if (typeof start.querySelector === 'function') {
|
|
1836
|
+
try {
|
|
1837
|
+
const drawing = start.querySelector('svg, img, canvas');
|
|
1838
|
+
if (drawing !== null && drawing !== undefined) return drawing;
|
|
1839
|
+
} catch {
|
|
1840
|
+
return start;
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
return start;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
/**
|
|
1847
|
+
* Deep-clone the glyph inside one live host row and strip ids (a second copy
|
|
1848
|
+
* would collide in the document). Returns null when the row draws no glyph.
|
|
1849
|
+
*/
|
|
1850
|
+
function glyphCloneOf(row) {
|
|
1851
|
+
if (row === null || row === undefined) return null;
|
|
1852
|
+
let glyph = null;
|
|
1853
|
+
try {
|
|
1854
|
+
glyph = typeof row.querySelector === 'function' ? row.querySelector('span[class*="panelGlyph"]') : null;
|
|
1855
|
+
} catch {
|
|
1856
|
+
glyph = null;
|
|
1857
|
+
}
|
|
1858
|
+
if (glyph === null || glyph === undefined) return null;
|
|
1859
|
+
const source = glyphIconNodeOf(glyph);
|
|
1860
|
+
if (source === null || source === undefined) return null;
|
|
1861
|
+
let clone = null;
|
|
1862
|
+
try {
|
|
1863
|
+
clone = typeof source.cloneNode === 'function' ? source.cloneNode(true) : null;
|
|
1864
|
+
} catch {
|
|
1865
|
+
clone = null;
|
|
1866
|
+
}
|
|
1867
|
+
if (clone === null) return null;
|
|
1868
|
+
/* A cloned SVG can carry ids; the clone root counts as well, because
|
|
1869
|
+
querySelectorAll only sees descendants. A cloned wrapper could also still
|
|
1870
|
+
name a host slot, which must never be duplicated. */
|
|
1871
|
+
try {
|
|
1872
|
+
clone.removeAttribute?.('id');
|
|
1873
|
+
clone.removeAttribute?.('data-slot');
|
|
1874
|
+
} catch {
|
|
1875
|
+
/* ids are cosmetic in an icon */
|
|
1876
|
+
}
|
|
1877
|
+
if (typeof clone.querySelectorAll === 'function') {
|
|
1878
|
+
try {
|
|
1879
|
+
for (const tagged of Array.from(clone.querySelectorAll('[id]'))) tagged.removeAttribute?.('id');
|
|
1880
|
+
} catch {
|
|
1881
|
+
/* best effort */
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
return clone;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
/** Remember one panel's glyph while its row is still rendered. */
|
|
1888
|
+
function captureMoreGlyph(panelId, row) {
|
|
1889
|
+
const id = String(panelId ?? '');
|
|
1890
|
+
if (id === '') return null;
|
|
1891
|
+
const cached = moreGlyphs.get(id) ?? null;
|
|
1892
|
+
if (cached !== null) return cached;
|
|
1893
|
+
const clone = glyphCloneOf(row);
|
|
1894
|
+
if (clone === null) return null;
|
|
1895
|
+
moreGlyphs.set(id, clone);
|
|
1896
|
+
return clone;
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
/** Drop every remembered glyph (teardown, and tests). */
|
|
1900
|
+
function clearMoreGlyphs() {
|
|
1901
|
+
moreGlyphs.clear();
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
/**
|
|
1905
|
+
* Copy the host's own panel glyph into one of our menu rows. The icon is the
|
|
1906
|
+
* first child of `span[class*="panelGlyph"]` inside the panel row — cloned at
|
|
1907
|
+
* runtime, never shipped here, so a host redesign keeps working. The
|
|
1908
|
+
* placeholder is emptied first, which makes the host remounting the menu
|
|
1909
|
+
* idempotent; a missing glyph leaves it empty and returns false (silent).
|
|
1910
|
+
*/
|
|
1911
|
+
function mountMoreGlyph(placeholder, doc, label, panelId) {
|
|
1912
|
+
if (placeholder === null || placeholder === undefined) return false;
|
|
1913
|
+
try {
|
|
1914
|
+
while (placeholder.firstChild !== null && placeholder.firstChild !== undefined) {
|
|
1915
|
+
placeholder.removeChild(placeholder.firstChild);
|
|
1916
|
+
}
|
|
1917
|
+
} catch {
|
|
1918
|
+
/* a placeholder we cannot clear is left as it is */
|
|
1919
|
+
}
|
|
1920
|
+
const row = panelRowOf(doc, label);
|
|
1921
|
+
/* A live row is the freshest source and also refreshes the memory; once the
|
|
1922
|
+
host pins a panel away its row disappears, so the remembered clone is what
|
|
1923
|
+
keeps the icon in our menu. */
|
|
1924
|
+
let source = null;
|
|
1925
|
+
if (row !== null) {
|
|
1926
|
+
const fresh = glyphCloneOf(row);
|
|
1927
|
+
if (fresh !== null) {
|
|
1928
|
+
moreGlyphs.set(String(panelId ?? label), fresh);
|
|
1929
|
+
source = fresh;
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
if (source === null) source = moreGlyphs.get(String(panelId ?? label)) ?? null;
|
|
1933
|
+
if (source === null) return false;
|
|
1934
|
+
let clone = null;
|
|
1935
|
+
try {
|
|
1936
|
+
clone = typeof source.cloneNode === 'function' ? source.cloneNode(true) : null;
|
|
1937
|
+
} catch {
|
|
1938
|
+
clone = null;
|
|
1939
|
+
}
|
|
1940
|
+
if (clone === null) return false;
|
|
1941
|
+
try {
|
|
1942
|
+
placeholder.appendChild(clone);
|
|
1943
|
+
} catch {
|
|
1944
|
+
return false;
|
|
1945
|
+
}
|
|
1946
|
+
return true;
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
/**
|
|
1950
|
+
* Hide the panel rows that belong behind the More button. The host keeps its
|
|
1951
|
+
* pins in memory only and re-renders rows on every store change, so this pass
|
|
1952
|
+
* is idempotent, re-applied by the observer after every host redraw, and
|
|
1953
|
+
* undone on teardown. Rows are matched by the same aria-label / title the host
|
|
1954
|
+
* renders; a row we cannot identify is left alone (silent skip).
|
|
1955
|
+
*/
|
|
1956
|
+
function applyFoldState(doc, panels, settings, storageRef, touched) {
|
|
1957
|
+
if (doc === null || typeof doc.querySelectorAll !== 'function') return;
|
|
1958
|
+
const folded = new Set(foldedIdsOf(panels, settings, storageRef));
|
|
1959
|
+
const byLabel = new Map();
|
|
1960
|
+
for (const panel of panels) byLabel.set(panel.label, panel.id);
|
|
1961
|
+
let rows = [];
|
|
1962
|
+
try {
|
|
1963
|
+
rows = Array.from(doc.querySelectorAll('nav[class*="panelList"] button[class*="panelRow"]'));
|
|
1964
|
+
} catch {
|
|
1965
|
+
rows = [];
|
|
1966
|
+
}
|
|
1967
|
+
for (const row of rows) {
|
|
1968
|
+
const label = row.getAttribute?.('aria-label') ?? '';
|
|
1969
|
+
let titleText = '';
|
|
1970
|
+
if (typeof row.querySelector === 'function') {
|
|
1971
|
+
try {
|
|
1972
|
+
const title = row.querySelector('span[class*="panelTitle"]');
|
|
1973
|
+
if (title !== null && title !== undefined) titleText = title.textContent ?? '';
|
|
1974
|
+
} catch {
|
|
1975
|
+
titleText = '';
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
const id = byLabel.get(label) ?? byLabel.get(titleText) ?? null;
|
|
1979
|
+
if (id === null) continue;
|
|
1980
|
+
/* Remember the icon before this row can disappear from the sidebar. */
|
|
1981
|
+
captureMoreGlyph(id, row);
|
|
1982
|
+
const hide = folded.has(id);
|
|
1983
|
+
/* Hide whatever actually wraps both the icon and the text; a bare row button
|
|
1984
|
+
is the normal case, a wrapper is used when the host draws the glyph beside
|
|
1985
|
+
the button. `nav` is never hidden. */
|
|
1986
|
+
const unit = foldUnitOf(row);
|
|
1987
|
+
if (unit === null) continue;
|
|
1988
|
+
const current = unit.style?.display ?? '';
|
|
1989
|
+
if (hide === true && current !== 'none') {
|
|
1990
|
+
if (touched.has(unit) === false) touched.set(unit, current);
|
|
1991
|
+
unit.style.display = 'none';
|
|
1992
|
+
} else if (hide === false) {
|
|
1993
|
+
for (const candidate of [unit, row, row.parentElement ?? null]) {
|
|
1994
|
+
if (candidate === null || candidate === undefined) continue;
|
|
1995
|
+
if (touched.has(candidate) === true) {
|
|
1996
|
+
candidate.style.display = touched.get(candidate);
|
|
1997
|
+
touched.delete(candidate);
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
/**
|
|
2005
|
+
* Sample a real host menu item so our rows can borrow its look: the class list
|
|
2006
|
+
* is copied at runtime (never hardcoded) and the fixed dimensions are read from
|
|
2007
|
+
* getComputedStyle. Returns null when the menu is not open yet or the host item
|
|
2008
|
+
* is missing — callers fall back to their own class until it appears.
|
|
2009
|
+
*/
|
|
2010
|
+
function sampleMoreItem(doc) {
|
|
2011
|
+
if (doc === null || typeof doc.querySelectorAll !== 'function') return null;
|
|
2012
|
+
const view = doc.defaultView;
|
|
2013
|
+
if (view === undefined || view === null || typeof view.getComputedStyle !== 'function') return null;
|
|
2014
|
+
let menu = null;
|
|
2015
|
+
try {
|
|
2016
|
+
menu = doc.querySelector('[class*="moreMenu"]');
|
|
2017
|
+
} catch {
|
|
2018
|
+
menu = null;
|
|
2019
|
+
}
|
|
2020
|
+
if (menu === null || menu === undefined) return null;
|
|
2021
|
+
let host = null;
|
|
2022
|
+
try {
|
|
2023
|
+
host =
|
|
2024
|
+
Array.from(menu.querySelectorAll('button')).find((button) => {
|
|
2025
|
+
const cls = button.getAttribute?.('class') ?? '';
|
|
2026
|
+
return cls.includes('uic-') === false;
|
|
2027
|
+
}) ?? null;
|
|
2028
|
+
} catch {
|
|
2029
|
+
host = null;
|
|
2030
|
+
}
|
|
2031
|
+
if (host === null) return null;
|
|
2032
|
+
const cs = view.getComputedStyle(host);
|
|
2033
|
+
if (cs === null || cs === undefined) return null;
|
|
2034
|
+
const pick = (name) => {
|
|
2035
|
+
if (typeof cs.getPropertyValue === 'function') return cs.getPropertyValue(name) ?? '';
|
|
2036
|
+
return cs[name] ?? '';
|
|
2037
|
+
};
|
|
2038
|
+
return {
|
|
2039
|
+
className: host.getAttribute?.('class') ?? '',
|
|
2040
|
+
style: {
|
|
2041
|
+
height: pick('height'),
|
|
2042
|
+
lineHeight: pick('line-height'),
|
|
2043
|
+
paddingLeft: pick('padding-left'),
|
|
2044
|
+
paddingRight: pick('padding-right'),
|
|
2045
|
+
fontSize: pick('font-size'),
|
|
2046
|
+
borderRadius: pick('border-radius'),
|
|
2047
|
+
color: pick('color'),
|
|
2048
|
+
},
|
|
2049
|
+
};
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
/** ids currently behind the More button: foldAll wins, else the record. */
|
|
2053
|
+
function desiredFoldIds(entries, settings, storage) {
|
|
2054
|
+
const ids = entries.map((entry) => entry.id);
|
|
2055
|
+
if (settings?.sidebarMore?.foldAll === true) return computeFold(ids, settings);
|
|
2056
|
+
return cleanFolded(readSidebarMore(storage).folded, ids);
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
/**
|
|
2060
|
+
* The actions a replay would need to take: fold every live entry that is
|
|
2061
|
+
* currently pinned but should be behind More. The host's setPinned is
|
|
2062
|
+
* idempotent (it no-ops on an unchanged pin), so replay is safe to repeat.
|
|
2063
|
+
*/
|
|
2064
|
+
function sidebarMoreReplay(entries, settings, storage) {
|
|
2065
|
+
const wanted = new Set(desiredFoldIds(entries, settings, storage));
|
|
2066
|
+
return entries.filter((entry) => entry.pinned === true && wanted.has(entry.id)).map((entry) => entry.id);
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
/** The count the launcher shows: folded ids that still name a live panel. */
|
|
2070
|
+
function sidebarMoreCount(panels, settings, storage) {
|
|
2071
|
+
if (settings?.sidebarMore?.foldAll === true) return computeFold(panels, settings).length;
|
|
2072
|
+
return cleanFolded(readSidebarMore(storage).folded, panels).length;
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
/** Write one panel's pin through the host callback and keep the record honest. */
|
|
2076
|
+
function writeSidebarPin(id, pinned, entries, settings, storage) {
|
|
2077
|
+
if (sidebarWrite === null) return;
|
|
2078
|
+
sidebarWrite(id, pinned);
|
|
2079
|
+
const ids = entries.map((entry) => entry.id);
|
|
2080
|
+
const record = cleanFolded(readSidebarMore(storage).folded, ids);
|
|
2081
|
+
const next = pinned ? record.filter((entry) => entry !== id) : record.includes(id) ? record : [...record, id];
|
|
2082
|
+
writeSidebarMore(storage, next);
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
/**
|
|
2086
|
+
* The More menu rows. Rendered by the host inside its own Menu portal; we own
|
|
2087
|
+
* nothing but these rows. position:fixed is forbidden here (the portal may
|
|
2088
|
+
* be anywhere); the host handles placement.
|
|
2089
|
+
*/
|
|
2090
|
+
function SidebarMoreMenu(props) {
|
|
2091
|
+
const entries = Array.isArray(props.entries) ? props.entries : [];
|
|
2092
|
+
const onOpen = typeof props.onOpen === 'function' ? props.onOpen : () => {};
|
|
2093
|
+
const onDismiss = typeof props.onDismiss === 'function' ? props.onDismiss : () => {};
|
|
2094
|
+
const write = typeof props.onPinnedChange === 'function' ? props.onPinnedChange : null;
|
|
2095
|
+
const t = translator(localeScope());
|
|
2096
|
+
sidebarWrite = write;
|
|
2097
|
+
sidebarPanels = entries.map((entry) => entry.id);
|
|
2098
|
+
const settings = readSettings();
|
|
2099
|
+
const storageRef = storage();
|
|
2100
|
+
const record = readSidebarMore(storageRef).folded;
|
|
2101
|
+
const ids = entries.map((entry) => entry.id);
|
|
2102
|
+
const doc = typeof document === 'undefined' ? null : document;
|
|
2103
|
+
const [sampled, setSampled] = React.useState(null);
|
|
2104
|
+
|
|
2105
|
+
/* First render: fold whatever the record / foldAll asks for. The host
|
|
2106
|
+
re-renders the menu with the new pins, and its guard makes the second
|
|
2107
|
+
pass a no-op, so deferring to a microtask keeps us out of the render
|
|
2108
|
+
cycle. */
|
|
2109
|
+
if (write !== null && sidebarReplayQueued === false) {
|
|
2110
|
+
sidebarReplayQueued = true;
|
|
2111
|
+
if (typeof setTimeout === 'function') {
|
|
2112
|
+
setTimeout(() => {
|
|
2113
|
+
for (const id of sidebarMoreReplay(entries, readSettings(), storageRef)) write(id, false);
|
|
2114
|
+
}, 0);
|
|
2115
|
+
} else {
|
|
2116
|
+
for (const id of sidebarMoreReplay(entries, settings, storageRef)) write(id, false);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
/* The host menu items live in the same list as our rows; borrowing their
|
|
2121
|
+
class list and fixed dimensions makes every row look host-drawn. The
|
|
2122
|
+
sample is taken a tick later so the official items exist by then. */
|
|
2123
|
+
if (sampled === null && typeof setTimeout === 'function') {
|
|
2124
|
+
setTimeout(() => setSampled(sampleMoreItem(doc)), 0);
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
/**
|
|
2128
|
+
* Flip one panel. `folded` is the state the row is showing: true means the
|
|
2129
|
+
* panel is behind More right now, which may be foldAll talking rather than
|
|
2130
|
+
* the record — so freeing it also has to switch foldAll off, and folding it
|
|
2131
|
+
* back is a plain record write. Both branches leave the record consistent
|
|
2132
|
+
* with what the row will show on the next pass.
|
|
2133
|
+
*/
|
|
2134
|
+
const flipPanel = (id, folded) => {
|
|
2135
|
+
const ids = entries.map((item) => item.id);
|
|
2136
|
+
if (folded === false) {
|
|
2137
|
+
writeSidebarPin(id, false, entries, settings, storageRef);
|
|
2138
|
+
return;
|
|
2139
|
+
}
|
|
2140
|
+
const onlyOutside = ids.filter((item) => item !== 'plugins' && item !== id);
|
|
2141
|
+
/* Ask the host to put this row outside first — folding is derived from
|
|
2142
|
+
foldAll and the record, so skipping the host call leaves the panel
|
|
2143
|
+
hidden by the host's own pin state and it never comes back. */
|
|
2144
|
+
writeSidebarPin(id, true, entries, settings, storageRef);
|
|
2145
|
+
writeSettings({ ...readSettings(), sidebarMore: { foldAll: false } });
|
|
2146
|
+
writeSidebarMore(storageRef, cleanFolded(onlyOutside, ids));
|
|
2147
|
+
};
|
|
2148
|
+
|
|
2149
|
+
const wanted = new Set(desiredFoldIds(entries, settings, storageRef));
|
|
2150
|
+
const rowClass = sampled !== null && sampled.className !== '' ? sampled.className : 'uic-moreRow';
|
|
2151
|
+
const rowStyle = sampled !== null
|
|
2152
|
+
? { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px', width: '100%', boxSizing: 'border-box' }
|
|
2153
|
+
: null;
|
|
2154
|
+
|
|
2155
|
+
return node('div', { key: 'more', 'data-uic-sidebar-more-menu': '1' }, [
|
|
2156
|
+
...entries.map((entry) => {
|
|
2157
|
+
const folded = wanted.has(entry.id);
|
|
2158
|
+
return node('button', {
|
|
2159
|
+
key: entry.id,
|
|
2160
|
+
type: 'button',
|
|
2161
|
+
className: rowClass,
|
|
2162
|
+
style: rowStyle,
|
|
2163
|
+
'data-uic-more-row': entry.id,
|
|
2164
|
+
onClick: () => { onOpen(entry.id); onDismiss(); },
|
|
2165
|
+
}, [
|
|
2166
|
+
node('span', { key: 'main', className: 'uic-moreRowMain' }, [
|
|
2167
|
+
node('span', {
|
|
2168
|
+
key: 'glyph',
|
|
2169
|
+
className: 'uic-moreGlyph',
|
|
2170
|
+
'data-uic-more-glyph': entry.id,
|
|
2171
|
+
/* The host owns the icon: copy it from the live sidebar row once this
|
|
2172
|
+
placeholder is in the document. Refilled on every mount, so a host
|
|
2173
|
+
remount cannot stack copies. */
|
|
2174
|
+
ref: (element) => {
|
|
2175
|
+
if (element === null || element === undefined) return;
|
|
2176
|
+
mountMoreGlyph(element, doc, entry.label, entry.id);
|
|
2177
|
+
},
|
|
2178
|
+
}, []),
|
|
2179
|
+
node('span', { key: 'name', className: 'uic-moreRowName' }, entry.label),
|
|
2180
|
+
]),
|
|
2181
|
+
node('span', {
|
|
2182
|
+
key: 'toggle',
|
|
2183
|
+
className: 'uic-moreToggle',
|
|
2184
|
+
'data-uic-more-pin': entry.id,
|
|
2185
|
+
role: 'button',
|
|
2186
|
+
tabIndex: 0,
|
|
2187
|
+
onClick: (event) => {
|
|
2188
|
+
event.stopPropagation();
|
|
2189
|
+
flipPanel(entry.id, folded);
|
|
2190
|
+
},
|
|
2191
|
+
onKeyDown: (event) => {
|
|
2192
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
2193
|
+
event.preventDefault();
|
|
2194
|
+
event.stopPropagation();
|
|
2195
|
+
flipPanel(entry.id, folded);
|
|
2196
|
+
}
|
|
2197
|
+
},
|
|
2198
|
+
}, folded === true ? t('settings.sidebarMore.unfold') : t('settings.sidebarMore.fold')),
|
|
2199
|
+
]);
|
|
2200
|
+
}),
|
|
2201
|
+
]);
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
/**
|
|
2205
|
+
* Paint the folded count onto the host's launcher row: find the More button by
|
|
2206
|
+
* its own aria-label, then rewrite only the title span. The aria-label stays
|
|
2207
|
+
* untouched (screen readers keep "更多"); a missing button is skipped
|
|
2208
|
+
* silently.
|
|
2209
|
+
*/
|
|
2210
|
+
function paintMoreCount(doc, panels, settings, storageRef, titleInfo) {
|
|
2211
|
+
if (doc === null || typeof doc.querySelectorAll !== 'function') return;
|
|
2212
|
+
let candidates = [];
|
|
2213
|
+
try {
|
|
2214
|
+
candidates = Array.from(doc.querySelectorAll('button[aria-label="更多"], button[aria-label="More"]'));
|
|
2215
|
+
} catch {
|
|
2216
|
+
candidates = [];
|
|
2217
|
+
}
|
|
2218
|
+
const launcher = candidates.find((button) => {
|
|
2219
|
+
if (button.getAttribute === undefined) return false;
|
|
2220
|
+
if (MORE_TITLES.has(button.getAttribute('aria-label')) === false) return false;
|
|
2221
|
+
let parent = button.parentElement ?? null;
|
|
2222
|
+
while (parent !== null) {
|
|
2223
|
+
const cls = parent.getAttribute?.('class') ?? '';
|
|
2224
|
+
if (cls.includes('panelList')) return true;
|
|
2225
|
+
parent = parent.parentElement;
|
|
2226
|
+
}
|
|
2227
|
+
return false;
|
|
2228
|
+
});
|
|
2229
|
+
if (launcher === undefined) return;
|
|
2230
|
+
let title = null;
|
|
2231
|
+
if (typeof launcher.querySelector === 'function') {
|
|
2232
|
+
try {
|
|
2233
|
+
title = launcher.querySelector('span[class*="panelTitle"]');
|
|
2234
|
+
} catch {
|
|
2235
|
+
title = null;
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
if (title === null || title === undefined) return;
|
|
2239
|
+
if (titleInfo.title !== null && titleInfo.title !== title) return;
|
|
2240
|
+
if (titleInfo.title === null) {
|
|
2241
|
+
titleInfo.title = title;
|
|
2242
|
+
titleInfo.original = title.textContent ?? '';
|
|
2243
|
+
}
|
|
2244
|
+
const count = sidebarMoreCount(panels.map((panel) => panel.id), settings, storageRef);
|
|
2245
|
+
/** The aria-label is the stable base; the title may already carry a painted count. */
|
|
2246
|
+
const base = launcher.getAttribute('aria-label') ?? '';
|
|
2247
|
+
const wanted = moreLabel(base, count);
|
|
2248
|
+
if (title.textContent !== wanted) title.textContent = wanted;
|
|
2249
|
+
}
|
|
2250
|
+
|
|
1866
2251
|
function apply(ctx) {
|
|
1867
2252
|
const doc = typeof document === 'undefined' ? null : document;
|
|
1868
2253
|
const slots = ctx.get('slots');
|
|
@@ -1874,6 +2259,62 @@ function apply(ctx) {
|
|
|
1874
2259
|
|
|
1875
2260
|
const inventory = () => slotRows(entriesOf, readSettings(), runtimeCatalog(slots));
|
|
1876
2261
|
|
|
2262
|
+
const sidebarPanelsOf = () =>
|
|
2263
|
+
entriesOf('sidebar.panellist')
|
|
2264
|
+
.map((entry) => ({ id: String(entry?.options?.id ?? ''), label: entryLabelOf(entry) }))
|
|
2265
|
+
.filter((panel) => panel.id !== '');
|
|
2266
|
+
const paintCount = () => paintMoreCount(doc, sidebarPanelsOf(), readSettings(), storage(), moreTitle);
|
|
2267
|
+
const applyFold = () => applyFoldState(doc, sidebarPanelsOf(), readSettings(), storage(), moreTouched);
|
|
2268
|
+
ctx.effect(() => () => clearMoreGlyphs(), 'ui-controller: forget sampled glyphs');
|
|
2269
|
+
|
|
2270
|
+
/* One slot only, and only after it is declared: the inject callback itself
|
|
2271
|
+
only fires once the host declares the slot, so the guard is belt and
|
|
2272
|
+
braces (dsh-plugin-dev §13). */
|
|
2273
|
+
ctx.effect(
|
|
2274
|
+
() =>
|
|
2275
|
+
ctx.slots.inject(SIDEBAR_MORE_SLOT, () => {
|
|
2276
|
+
if (typeof ctx.slots.spec === 'function' && ctx.slots.spec(SIDEBAR_MORE_SLOT) === undefined) return () => {};
|
|
2277
|
+
return ctx.slots.register(
|
|
2278
|
+
{
|
|
2279
|
+
name: SIDEBAR_MORE_SLOT,
|
|
2280
|
+
id: SIDEBAR_MORE_ID,
|
|
2281
|
+
order: SIDEBAR_MORE_ORDER,
|
|
2282
|
+
locale: NS,
|
|
2283
|
+
label: () => t('settings.sidebarMore.title'),
|
|
2284
|
+
},
|
|
2285
|
+
(props) => h(SidebarMoreMenu, props),
|
|
2286
|
+
);
|
|
2287
|
+
}),
|
|
2288
|
+
'ui-controller: sidebar more',
|
|
2289
|
+
);
|
|
2290
|
+
|
|
2291
|
+
/* Host pins are memory-only; a reload loses them. The record replays through
|
|
2292
|
+
the write entry captured by the menu (null until the menu has rendered
|
|
2293
|
+
once), so subscribe on every panellist change and try. */
|
|
2294
|
+
if (typeof slots?.subscribe === 'function') {
|
|
2295
|
+
ctx.effect(() => slots.subscribe('sidebar.panellist', () => {
|
|
2296
|
+
const write = sidebarWrite;
|
|
2297
|
+
if (write === null) return;
|
|
2298
|
+
const settings = readSettings();
|
|
2299
|
+
const entries = sidebarPanels.map((panel) => ({ id: panel.id, pinned: true }));
|
|
2300
|
+
for (const id of sidebarMoreReplay(entries, settings, storage())) write(id, false);
|
|
2301
|
+
}), 'ui-controller: sidebar more replay');
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
/* Count label: an observer catches the launcher appearing/re-rendering, and
|
|
2305
|
+
the 2s pass below is the fallback. */
|
|
2306
|
+
let moreObserver = null;
|
|
2307
|
+
if (doc !== null && typeof doc.body?.addEventListener === 'function' && typeof MutationObserver === 'function') {
|
|
2308
|
+
try {
|
|
2309
|
+
moreObserver = new MutationObserver(() => { paintCount(); applyFold(); });
|
|
2310
|
+
moreObserver.observe(doc.body, { childList: true, subtree: true });
|
|
2311
|
+
} catch {
|
|
2312
|
+
moreObserver = null;
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
paintCount();
|
|
2316
|
+
applyFold();
|
|
2317
|
+
|
|
1877
2318
|
let pickHandler = null;
|
|
1878
2319
|
|
|
1879
2320
|
const applyHidden = () => {
|
|
@@ -1919,8 +2360,18 @@ function apply(ctx) {
|
|
|
1919
2360
|
|
|
1920
2361
|
injectStyle(doc);
|
|
1921
2362
|
ctx.effect(() => () => {
|
|
2363
|
+
if (moreObserver !== null && typeof moreObserver.disconnect === 'function') moreObserver.disconnect();
|
|
2364
|
+
for (const [row, original] of moreTouched) {
|
|
2365
|
+
if (row.style !== undefined) row.style.display = original;
|
|
2366
|
+
}
|
|
2367
|
+
moreTouched.clear();
|
|
2368
|
+
if (moreTitle.title !== null) moreTitle.title.textContent = moreTitle.original;
|
|
2369
|
+
moreTitle.title = null;
|
|
2370
|
+
moreTitle.original = null;
|
|
2371
|
+
sidebarWrite = null;
|
|
2372
|
+
sidebarPanels = [];
|
|
2373
|
+
sidebarReplayQueued = false;
|
|
1922
2374
|
stopPicking();
|
|
1923
|
-
clearNavState(doc);
|
|
1924
2375
|
removeStyle(doc);
|
|
1925
2376
|
if (doc !== null) {
|
|
1926
2377
|
for (const element of Array.from(doc.querySelectorAll('[' + HIDDEN_ATTR + ']'))) element.removeAttribute(HIDDEN_ATTR);
|
|
@@ -1934,7 +2385,8 @@ function apply(ctx) {
|
|
|
1934
2385
|
const current = readSettings();
|
|
1935
2386
|
applyHidden();
|
|
1936
2387
|
applyVisualOrder(doc, current, ordered);
|
|
1937
|
-
|
|
2388
|
+
paintCount();
|
|
2389
|
+
applyFold();
|
|
1938
2390
|
};
|
|
1939
2391
|
|
|
1940
2392
|
applyAll();
|
|
@@ -2047,18 +2499,29 @@ window.__ModuleLoader__.load({
|
|
|
2047
2499
|
isOpen,
|
|
2048
2500
|
toggleOpen,
|
|
2049
2501
|
resetOpen,
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2502
|
+
SIDEBAR_MORE_KEY,
|
|
2503
|
+
SIDEBAR_MORE_SLOT,
|
|
2504
|
+
SIDEBAR_MORE_ID,
|
|
2505
|
+
SIDEBAR_MORE_MODAL,
|
|
2506
|
+
readSidebarMore,
|
|
2507
|
+
writeSidebarMore,
|
|
2508
|
+
cleanFolded,
|
|
2509
|
+
computeFold,
|
|
2510
|
+
moreLabel,
|
|
2511
|
+
sidebarMoreReplay,
|
|
2512
|
+
sidebarMoreCount,
|
|
2513
|
+
desiredFoldIds,
|
|
2514
|
+
foldedIdsOf,
|
|
2515
|
+
entryLabelOf,
|
|
2516
|
+
applyFoldState,
|
|
2517
|
+
clearMoreGlyphs,
|
|
2518
|
+
foldUnitOf,
|
|
2519
|
+
glyphIconNodeOf,
|
|
2520
|
+
mountMoreGlyph,
|
|
2521
|
+
panelRowOf,
|
|
2522
|
+
sampleMoreItem,
|
|
2523
|
+
paintMoreCount,
|
|
2524
|
+
SidebarMoreMenu,
|
|
2062
2525
|
DICTS,
|
|
2063
2526
|
};
|
|
2064
2527
|
},
|