dsh-ui-controller 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -1,17 +1,2065 @@
1
1
  /**
2
- * Browser half of `dsh-ui-controller` — placeholder.
2
+ * `dsh-ui-controller` — client half.
3
3
  *
4
- * Loaded by the harness module loader. It registers no slot entry and injects no
5
- * stylesheet, so installing this version is a no-op. Keep the module id equal to
6
- * the package name: the loader rejects a mismatch.
4
+ * What this plugin does: it *reads* the host's slot registry and shows you what
5
+ * every slot currently holds, lets you hide or re-order entries you did not
6
+ * write yourself, and stores those decisions as named presets.
7
+ *
8
+ * What it deliberately does NOT do — read this before "improving" it:
9
+ *
10
+ * - It never moves another plugin's entry. An entry's props come from the slot
11
+ * spec that declared it; re-registering it elsewhere loses that context.
12
+ * - It never unregisters or unmounts somebody else's entry. Hiding is a CSS
13
+ * class on the element plus an attribute we can remove again.
14
+ * - It never shadows a `single` slot. `sidebar.settings` taught us what
15
+ * happens: `TypeError: c is not a function` and the gear menu and the whole
16
+ * settings panel disappear together.
17
+ * - It never registers into `root`, the one slot in this build that says
18
+ * "DO NOT register".
19
+ * - It never mutates the array `slots.entries()` returns; that is the internal
20
+ * live array, and writing to it bypasses `markDirty`, so the UI never
21
+ * refreshes.
22
+ *
23
+ * Host facts this file depends on (verified against the shipped
24
+ * `dsh-client-ui-slots/lib/index.js`): `entriesOfSlot(key)` is the safe
25
+ * snapshot, sorted by `priority`; `spec(key)` gives `{kind, scope}`; an entry is
26
+ * `{ options: { id?, key?, order?, label?, priority? }, registrant? }`; `list`
27
+ * slots sort by `priority → order`, everything else by `priority` alone.
28
+ */
29
+
30
+ const VERSION = '0.1.1';
31
+
32
+ const NS = 'uiController';
33
+ const SECTION_ID = 'ui-controller';
34
+ const SECTION_ORDER = 45;
35
+
36
+ const SETTINGS_KEY = 'dsh.uiController.settings.v1';
37
+ const PRESERVED_KEY = 'dsh.uiController.preserved.v1';
38
+ const BACKUP_KEY = 'dsh.uiController.backup.v1';
39
+ const BACKUP_LIMIT = 5;
40
+ const SETTINGS_VERSION = 1;
41
+
42
+ const HIDDEN_ATTR = 'data-uic-hidden';
43
+ const STYLE_ID = 'ui-controller-style';
44
+ const ROW_ATTR = 'data-uic-row';
45
+
46
+ const HIDE_CSS = [
47
+ '[' + HIDDEN_ATTR + '="1"]{display:none !important}',
48
+ '[' + HIDDEN_ATTR + '="1"]:is(li,tr){display:none !important}',
49
+ ].join('\n');
50
+
51
+ const PAGE_CSS = [
52
+ '.uic-page{display:flex;flex-direction:column;gap:8px;font-size:13px;color:var(--dsw-alias-label-primary);contain:content}',
53
+ '.uic-title{margin:0;font-size:16px;font-weight:600;line-height:24px}',
54
+ '.uic-lead{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}',
55
+ '.uic-summary{margin:0;font-size:12px;line-height:18px}',
56
+ '.uic-dim{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px}',
57
+ '.uic-h3{margin:10px 0 0;font-size:13px;font-weight:600;line-height:20px}',
58
+ '.uic-mono{font-family:var(--ds-font-family-code);font-size:11px}',
59
+ '.uic-num{text-align:right}',
60
+ '.uic-ctl{display:inline-flex;gap:2px}',
61
+ '.uic-ctl .uic-btn{min-width:22px;padding:0 4px}',
62
+ '.uic-tag{display:inline-block;margin-right:4px;padding:0 5px;height:16px;line-height:16px;border-radius:4px;font-size:10px;border:1px solid var(--dsw-alias-border-l4);color:var(--dsw-alias-label-secondary)}',
63
+ '.uic-tag-on{color:var(--dsw-alias-state-business-primary);border-color:var(--dsw-alias-state-business-primary)}',
64
+ '.uic-tag-risk{color:var(--dsw-alias-state-error-primary);border-color:var(--dsw-alias-state-error-primary)}',
65
+ '.uic-btn{height:26px;padding:0 9px;border-radius:6px;font-size:11px;cursor:pointer;border:1px solid var(--dsw-alias-border-l4);background:transparent;color:var(--dsw-alias-label-primary)}',
66
+ '.uic-btn:hover{background:var(--dsw-alias-bg-layer-3)}',
67
+ '.uic-btn-quiet{color:var(--dsw-alias-label-secondary)}',
68
+ '.uic-why{display:inline-flex;align-items:center;gap:4px;font-size:10px;line-height:16px;color:var(--dsw-alias-label-tertiary)}',
69
+ '.uic-presets{display:flex;align-items:center;gap:6px;flex-wrap:wrap}',
70
+ '.uic-input{height:26px;min-width:120px;padding:0 7px;border-radius:6px;font-size:11px;border:1px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary)}',
71
+ '.uic-preset{display:inline-flex;align-items:center;gap:4px;padding:2px 6px;border-radius:6px;border:1px solid var(--dsw-alias-border-l4)}',
72
+ '.uic-preset-name{font-size:11px}',
73
+ '.uic-page{container-type:inline-size}',
74
+ '.uic-filters{display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:2px 0}',
75
+ '.uic-search{flex:1 1 180px;min-width:140px}',
76
+ '.uic-filterGroup{display:inline-flex;gap:2px}',
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
+ '.uic-filter[data-on="true"]{border-color:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-state-business-primary)}',
79
+ '.uic-navSection{display:flex;flex-direction:column;gap:6px;margin-top:12px;padding-top:10px;border-top:1px solid var(--dsw-alias-border-l2)}',
80
+ '.uic-navFollow{display:inline-flex;align-items:center;gap:6px;font-size:12px;cursor:pointer}',
81
+ '.uic-navStates{display:flex;gap:6px;flex-wrap:wrap}',
82
+ '.uic-zone{border-top:.5px solid var(--dsw-alias-border-l2);padding:2px 0}',
83
+ '.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
+ '.uic-zoneName{flex:none}',
85
+ '.uic-zoneHint{flex:1 1 auto;min-width:0;font-size:10px;font-weight:400;color:var(--dsw-alias-label-tertiary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
86
+ '.uic-zoneMeta{flex:none;font-size:10px;font-weight:400;color:var(--dsw-alias-label-tertiary)}',
87
+ '.uic-zone-risky{background:repeating-linear-gradient(45deg,rgba(146,64,14,.045) 0 6px,transparent 6px 12px)}',
88
+ '.uic-zoneBody{display:flex;flex-direction:column;gap:1px;padding:1px 0 4px}',
89
+ '.uic-slot{border-top:.5px solid var(--dsw-alias-border-l2)}',
90
+ '.uic-slotHead{display:grid;grid-template-columns:14px 12px minmax(0,1fr) 46px 58px 96px;align-items:center;gap:6px;width:100%;height:32px;padding:0 4px;border:0;background:transparent;color:var(--dsw-alias-label-primary);cursor:pointer;text-align:left;font-size:11px}',
91
+ '.uic-slotRisk{box-shadow:inset 3px 0 0 #b45309;color:#92400e}',
92
+ '.uic-slotKey{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
93
+ '.uic-kind{font-size:10px;color:var(--dsw-alias-label-tertiary)}',
94
+ '.uic-count{justify-self:end;font-size:10px;color:var(--dsw-alias-label-tertiary)}',
95
+ '.uic-mark{font-size:10px;text-align:center}',
96
+ '.uic-arrow{font-size:9px;text-align:center;color:var(--dsw-alias-label-tertiary)}',
97
+ '.uic-entries{display:flex;flex-direction:column;gap:1px;padding:1px 0 3px 26px}',
98
+ '.uic-entry{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr) 40px 40px 40px minmax(0,1fr) auto;align-items:center;gap:6px;min-height:32px;padding:0 4px;border-top:.5px solid var(--dsw-alias-border-l2)}',
99
+ '.uic-entryId{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
100
+ '.uic-entryLive{font-size:10px;color:var(--dsw-alias-label-tertiary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
101
+ '.uic-entryState{display:flex;gap:2px;flex-wrap:wrap}',
102
+ '.uic-entryActions{display:flex;align-items:center;gap:4px;justify-self:end}',
103
+ '@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}}',
104
+ ].join('\n');
105
+
106
+ /* ------------------------------------------------- settings page left rail */
107
+
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
+
114
+ /** Width of the settings rail, in px, for one of the three states. */
115
+ function navWidthOf(state) {
116
+ return hasOwn(NAV_WIDTHS, state) ? NAV_WIDTHS[state] : NAV_WIDTHS.expanded;
117
+ }
118
+
119
+ /**
120
+ * First grid track of the settings modal.
121
+ *
122
+ * Longhand on purpose: the host's shorthand also carries grid area names that
123
+ * are hashed per build, so copying the whole declaration would break on the
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.
138
+ */
139
+ const NAV_CSS = [
140
+ '@media (min-width:768px){',
141
+ ...PANEL_NAV_STATES.filter((state) => state !== 'expanded').map(
142
+ (state) =>
143
+ PANEL_SELECTOR + '[' + NAV_ATTR + '="' + state + '"]{grid-template-columns:' + navColumnsOf(state) + ' !important}',
144
+ ),
145
+ PANEL_SELECTOR + '[' + NAV_ATTR + '="rail"] > nav{padding:10px 6px 0;overflow:hidden}',
146
+ PANEL_SELECTOR + '[' + NAV_ATTR + '="rail"] > nav button{justify-content:center;padding:8px 0;gap:0}',
147
+ PANEL_SELECTOR +
148
+ '[' +
149
+ NAV_ATTR +
150
+ '="rail"] > nav button > span:nth-child(2){position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}',
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';
159
+ }
160
+
161
+ /**
162
+ * Whether the host's own session sidebar is currently a rail.
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.
7
170
  */
171
+ function hostSidebarCollapsed(doc) {
172
+ if (doc === null || doc === undefined || typeof doc.querySelector !== 'function') return false;
173
+ try {
174
+ if (doc.querySelector('[data-sidebar-collapsed]') !== null) return true;
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;
182
+ } catch {
183
+ return false;
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Which of the three states applies right now.
189
+ *
190
+ * `follow` on (the default) means the rail mirrors the host sidebar, and the
191
+ * stored three-way choice is deliberately not read at all — that is the whole
192
+ * point of following.
193
+ */
194
+ function resolveNavState(settings, doc) {
195
+ const nav = isPlainObject(settings) && isPlainObject(settings.nav) ? settings.nav : {};
196
+ if (nav.follow !== false) return stateOr(hostSidebarCollapsed(doc) ? 'rail' : 'expanded');
197
+ return stateOr(nav.state);
198
+ }
199
+
200
+ const PRESET_NAME_MAX = 40;
201
+ const SELECTOR_MAX = 240;
202
+ const LOCATOR_LIMIT = 400;
203
+
204
+ const SLOT_CATALOG = [
205
+ /* Generated from cangku/tmp/261114_p8v_slots_catalog.tsv (109 rows, 12 columns).
206
+ `registrant` is a runtime-only field (entry.registrant = options.registrant ?? fiber.name)
207
+ and no inspect channel exposes it, so the two static proxies below are what we can
208
+ honestly show: who declares the slot and who injects it, derived at build time. */
209
+ { key: 'contextMenu.content', kind: 'keyed', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Optional React rows for existing extension positions; data contributions need no renderer.', registrantStatic: 'dsh-client-ui-sidebar-right×1; dsh-client-ui-workspace×1', injectStatic: 'dsh-client-ui-sidebar-right×1; dsh-client-ui-workspace×1' },
210
+ { key: 'contextMenu.icon', kind: 'keyed', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Business-owned glyph or image selected by the action\'s icon key.', registrantStatic: 'dsh-client-ui-open-in-app×2; dsh-client-ui-file-actions×1; dsh-client-ui-sidebar-right×1; dsh-client-ui-workspace×1', injectStatic: 'dsh-client-ui-file-actions×1; dsh-client-ui-open-in-app×1; dsh-client-ui-sidebar-right×1; dsh-client-ui-workspace×1' },
211
+ { key: 'conversation.approval.detail', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Optional detail for the Tool call correlated with an approval request.', registrantStatic: 'dsh-client-ui-chat×1', injectStatic: 'dsh-client-ui-chat×1' },
212
+ { key: 'conversation.chat.assistant-actions', kind: 'list', scope: 'session', risk: 'none', purpose: 'Ordered actions for one finalized assistant message.', registrantStatic: 'dsh-client-ui-message-feedback×1', injectStatic: 'dsh-client-ui-message-feedback×1' },
213
+ { key: 'conversation.chat.commandview', kind: 'keyed', scope: 'session', risk: 'none', purpose: 'Command row keyed by the command name.', registrantStatic: '', injectStatic: '' },
214
+ { key: 'conversation.chat.flow', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Ordered Chat rows and local echoes with viewport-bound visibility hooks.', registrantStatic: 'dsh-client-ui-chat×1', injectStatic: 'dsh-client-ui-chat×1' },
215
+ { key: 'conversation.chat.message.images', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Renderer for one consecutive group of durable message images.', registrantStatic: 'dsh-client-ui-attachment×1', injectStatic: 'dsh-client-ui-attachment×1' },
216
+ { key: 'conversation.chat.node', kind: 'keyed', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Final Chat node renderer, keyed by `ChatNodeKind`.', registrantStatic: 'dsh-client-ui-chat×15; dsh-client-ui-goal×1; dsh-client-ui-tool×1; dsh-client-ui-user-questions×1; dsh-client-ui-workflow-run×1', injectStatic: 'dsh-client-ui-chat×15; dsh-client-ui-goal×1; dsh-client-ui-tool×1; dsh-client-ui-user-questions×1; dsh-client-ui-workflow-run×1' },
217
+ { key: 'conversation.chat.reasoning.body', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Expanded reasoning body with raw and display-ready text.', registrantStatic: 'dsh-client-ui-chat×1; dsh-experimental-client-ui-cot-translation×1', injectStatic: 'dsh-client-ui-chat×1; dsh-experimental-client-ui-cot-translation×1' },
218
+ { key: 'conversation.chat.text-interaction', kind: 'keyed', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Area-local text gestures and surfaces; each consumer registers its own synchronous admission.', registrantStatic: 'dsh-message-quotes×1', injectStatic: 'dsh-message-quotes×1' },
219
+ { key: 'conversation.chat.turnTail', kind: 'list', scope: 'session', risk: 'none', purpose: 'Ordered feature contributions before a completed Turn\'s action row.', registrantStatic: 'dsh-client-ui-action-cards×1; dsh-client-ui-deliverables×1; dsh-client-ui-plan×1; dsh-client-ui-schedule×1', injectStatic: 'dsh-client-ui-action-cards×1; dsh-client-ui-deliverables×1; dsh-client-ui-plan×1; dsh-client-ui-schedule×1' },
220
+ { key: 'conversation.chat.user.before', kind: 'chain', scope: 'session', risk: 'none', purpose: 'Message-source decoration owned and rendered by the user Node entry.', registrantStatic: 'dsh-experimental-liveshare×1', injectStatic: 'dsh-experimental-liveshare×1' },
221
+ { key: 'conversation.chat.user.images', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'User-message images, including pending and local-echo previews, independently replaceable from output images.', registrantStatic: 'dsh-client-ui-attachment×1', injectStatic: 'dsh-client-ui-attachment×1' },
222
+ { key: 'conversation.composer', kind: 'chain', scope: 'session', risk: 'none', purpose: 'Selector-routed replacements for the current Session\'s resident composer; fixed overlays must portal to the document body because the docked composer contains ', registrantStatic: 'dsh-client-ui-approval×1; dsh-client-ui-subagent×1; dsh-client-ui-user-questions×1', injectStatic: 'dsh-client-ui-approval×1; dsh-client-ui-subagent×1; dsh-client-ui-user-questions×1' },
223
+ { key: 'conversation.composer.bar', kind: 'single', scope: 'session-maybe', risk: 'shadows-shipped-ui', purpose: 'Resident composer body, including the no-Session inert state; fixed overlays must portal to the document body because the docked composer contains them.', registrantStatic: 'dsh-client-ui-conversation×1', injectStatic: '' },
224
+ { key: 'conversation.composer.dock', kind: 'list', scope: 'session', risk: 'none', purpose: 'Ambient entries below the composer card; fixed overlays must portal to the document body because the docked composer contains them.', registrantStatic: 'dsh-client-ui-chat×2', injectStatic: 'dsh-client-ui-chat×1' },
225
+ { key: 'conversation.header', kind: 'single', scope: 'session-maybe', risk: 'shadows-shipped-ui', purpose: 'Resident navigation container, including when no Session is selected.', registrantStatic: 'dsh-client-ui-conversation×1', injectStatic: '' },
226
+ { key: 'conversation.header.leading', kind: 'single', scope: 'root', risk: 'none', purpose: 'Global navigation before the Session title, available without a Session.', registrantStatic: '', injectStatic: '' },
227
+ { key: 'conversation.hero.agentPreset', kind: 'single', scope: 'session-maybe', risk: 'shadows-shipped-ui', purpose: 'Agent-preset control staged for a New Session.', registrantStatic: 'dsh-client-ui-agent-preset×1', injectStatic: '' },
228
+ { key: 'conversation.hero.brand.mark', kind: 'single', scope: 'root', risk: 'none', purpose: 'Brand mark shown before the blank-session headline.', registrantStatic: '', injectStatic: '' },
229
+ { key: 'conversation.hero.options', kind: 'list', scope: 'session', risk: 'none', purpose: 'Compact options right-aligned in the New Session row after the workspace and preset controls; rendered only with a Session.', registrantStatic: 'dsh-experimental-client-ui-forge×1', injectStatic: 'dsh-experimental-client-ui-forge×1' },
230
+ { key: 'conversation.hero.workspace', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Workspace picker shown by the blank-session Hero.', registrantStatic: 'dsh-client-ui-workspace×1', injectStatic: 'dsh-client-ui-workspace×1' },
231
+ { key: 'conversation.hero.workspace.directoryFlow', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Directory-flow hole under the conversation empty-state picker (declared by the WorkspacePicker entry).', registrantStatic: 'dsh-client-ui-directory-picker-browse×1; dsh-client-ui-directory-picker-native×1', injectStatic: 'dsh-client-ui-directory-picker-browse×1; dsh-client-ui-directory-picker-native×1' },
232
+ { key: 'conversation.input.activity', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Compact action after the model selector; it can expand across the toolbar while retaining the editor and submit action, and fixed overlays must portal to the do', registrantStatic: 'dsh-experimental-client-ui-voice-input×1', injectStatic: 'dsh-experimental-client-ui-voice-input×1' },
233
+ { key: 'conversation.input.attachments', kind: 'single', scope: 'session-maybe', risk: 'shadows-shipped-ui', purpose: 'Optional draft-attachment rail and drop target; fixed overlays must portal to the document body because the docked composer contains them.', registrantStatic: 'dsh-client-ui-attachment×1', injectStatic: 'dsh-client-ui-attachment×1' },
234
+ { key: 'conversation.input.dock', kind: 'list', scope: 'session', risk: 'none', purpose: 'Full-width entries above the composer card; fixed overlays must portal to the document body because the docked composer contains them.', registrantStatic: 'dsh-client-ui-conversation×2; dsh-client-ui-goal×1; dsh-experimental-client-ui-forge×1', injectStatic: 'dsh-client-ui-conversation×2; dsh-client-ui-goal×1; dsh-experimental-client-ui-forge×1' },
235
+ { key: 'conversation.input.left', kind: 'list', scope: 'session', risk: 'none', purpose: 'Compact controls at the left of the composer tool row; fixed overlays must portal to the document body because the docked composer contains them.', registrantStatic: '', injectStatic: '' },
236
+ { key: 'conversation.input.model', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Model selector inside the composer tool row.', registrantStatic: 'dsh-client-ui-model-selection×1; dsh-experimental-liveshare×1', injectStatic: 'dsh-client-ui-model-selection×1; dsh-experimental-liveshare×1' },
237
+ { key: 'conversation.input.model.label', kind: 'single', scope: 'session', risk: 'none', purpose: 'Non-interactive inline model label; selection controls remain owner-managed.', registrantStatic: '', injectStatic: '' },
238
+ { key: 'conversation.input.overlay', kind: 'list', scope: 'session', risk: 'none', purpose: 'Floating entries rendered inside the resident composer card; fixed overlays must portal to the document body because the docked composer contains them.', registrantStatic: 'dsh-client-ui-commands×1; dsh-client-ui-input-trigger×1; dsh-client-ui-message-feedback×1', injectStatic: 'dsh-client-ui-commands×1; dsh-client-ui-input-trigger×1; dsh-client-ui-message-feedback×1' },
239
+ { key: 'conversation.input.permission', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Current-session permission control inside the composer tool row; fixed overlays must portal to the document body because the docked composer contains them.', registrantStatic: 'dsh-client-ui-permission-presets×1; dsh-experimental-liveshare×1', injectStatic: 'dsh-client-ui-permission-presets×1; dsh-experimental-liveshare×1' },
240
+ { key: 'conversation.input.plan', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Plan control inside the composer tool row; fixed overlays must portal to the document body because the docked composer contains them.', registrantStatic: 'dsh-client-ui-plan×1', injectStatic: 'dsh-client-ui-plan×1' },
241
+ { key: 'conversation.input.right', kind: 'list', scope: 'session', risk: 'none', purpose: 'Compact controls before the composer submit action; fixed overlays must portal to the document body because the docked composer contains them.', registrantStatic: '', injectStatic: '' },
242
+ { key: 'conversation.plan-review.actions', kind: 'list', scope: 'session', risk: 'none', purpose: 'Actions for the exact plan under review; approval remains with the question composer.', registrantStatic: 'dsh-client-ui-plan×1', injectStatic: 'dsh-client-ui-plan×1' },
243
+ { key: 'conversation.session', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Strict per-Session Conversation body.', registrantStatic: 'dsh-client-ui-conversation×1', injectStatic: '' },
244
+ { key: 'conversation.session.header', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Strict per-Session title, actions, and View navigation.', registrantStatic: 'dsh-client-ui-conversation×1', injectStatic: '' },
245
+ { key: 'conversation.session.header.actions', kind: 'list', scope: 'session', risk: 'none', purpose: 'Title-adjacent Session actions in ascending order; overflow is clipped and faded before the utilities, so overlays must portal.', registrantStatic: 'dsh-client-ui-agent-preset×1; dsh-client-ui-jobs×1; dsh-client-ui-subagent×1; dsh-experimental-client-ui-agent-team×1', injectStatic: 'dsh-client-ui-jobs×1; dsh-client-ui-subagent×1; dsh-experimental-client-ui-agent-team×1' },
246
+ { key: 'conversation.session.header.corner', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'The header\'s far-right corner, past the utilities\' edge and into the header\'s own padding, for one control.', registrantStatic: 'dsh-client-ui-sidebar-right×1', injectStatic: 'dsh-client-ui-sidebar-right×1' },
247
+ { key: 'conversation.session.header.lineage', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Optional replacement for one Session breadcrumb title; overlays must portal because the title area clips overflow.', registrantStatic: 'dsh-client-ui-subagent×1', injectStatic: 'dsh-client-ui-subagent×1' },
248
+ { key: 'conversation.session.header.utilities', kind: 'list', scope: 'session', risk: 'none', purpose: 'Right-aligned Session utilities in ascending order.', registrantStatic: 'dsh-client-ui-open-in-app×1; dsh-client-ui-schedule×1; dsh-experimental-client-ui-forge×1; dsh-experimental-liveshare×1; dsh-session-log-export×1', injectStatic: 'dsh-client-ui-open-in-app×1; dsh-client-ui-schedule×1; dsh-experimental-client-ui-forge×1; dsh-experimental-liveshare×1; dsh-session-log-export×1' },
249
+ { key: 'conversation.session.header.views.actions', kind: 'list', scope: 'root', risk: 'none', purpose: 'Rows of the View tab row\'s More menu; the header shows More only while this list has registrations.', registrantStatic: 'dsh-client-ui-entry-customization×1', injectStatic: 'dsh-client-ui-entry-customization×1' },
250
+ { key: 'conversation.trajectory.images', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Renderer for one group of durable record images in the Trajectory ledger.', registrantStatic: 'dsh-client-ui-attachment×1', injectStatic: 'dsh-client-ui-attachment×1' },
251
+ { key: 'conversation.user.text.node', kind: 'keyed', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'One business-owned inline renderer for a pure JSON text node.', registrantStatic: 'dsh-client-ui-conversation×2; dsh-client-ui-reference×2; dsh-client-ui-goal×1; dsh-client-ui-secret-mask×1; dsh-client-ui-skill×1; dsh-message-quotes×1', injectStatic: 'dsh-client-ui-goal×1; dsh-client-ui-reference×1; dsh-client-ui-secret-mask×1; dsh-client-ui-skill×1; dsh-message-quotes×1' },
252
+ { key: 'conversation.view', kind: 'list', scope: 'session', risk: 'none', purpose: 'Registered Conversation target Views, rendered one at a time.', registrantStatic: 'dsh-client-ui-chat×1; dsh-client-ui-trajectory×1; dsh-experimental-client-ui-stats×1', injectStatic: 'dsh-client-ui-chat×1; dsh-client-ui-trajectory×1; dsh-experimental-client-ui-stats×1' },
253
+ { key: 'deliverables.file.actions', kind: 'list', scope: 'session', risk: 'none', purpose: 'Open one file through its authorized Session event coordinates.', registrantStatic: 'dsh-client-ui-open-in-app×1', injectStatic: 'dsh-client-ui-open-in-app×1' },
254
+ { key: 'deliverables.review.file.actions', kind: 'list', scope: 'session', risk: 'none', purpose: 'The same file actions owned by a changed-file review tab.', registrantStatic: 'dsh-client-ui-open-in-app×1', injectStatic: 'dsh-client-ui-open-in-app×1' },
255
+ { key: 'main', kind: 'keyed', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Central panel selected by sidebar entry id.', registrantStatic: 'dsh-client-ui-conversation×1; dsh-client-ui-plugin-manager×1; dsh-client-ui-schedule×1', injectStatic: 'dsh-client-ui-plugin-manager×1; dsh-client-ui-schedule×1' },
256
+ { key: 'main.conversation', kind: 'single', scope: 'session-maybe', risk: 'shadows-shipped-ui', purpose: 'Conversation shell beneath its root-scoped main-panel entry.', registrantStatic: 'dsh-client-ui-conversation×1', injectStatic: '' },
257
+ { key: 'plugins.add.actions', kind: 'list', scope: 'root', risk: 'none', purpose: 'Additional MenuItemButton rows after installation: 72px high, with a title and a description capped at two lines.', registrantStatic: 'dsh-client-ui-agent-preset×1', injectStatic: 'dsh-client-ui-agent-preset×1' },
258
+ { key: 'plugins.bundle.activation', kind: 'keyed', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Optional guidance after the user enables a bundle from the list, keyed by npm package name.', registrantStatic: 'dsh-experimental-client-ui-voice-input×1', injectStatic: 'dsh-experimental-client-ui-voice-input×1' },
259
+ { key: 'plugins.bundle.config', kind: 'keyed', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'A bundle\'s own configuration, keyed by the bundle\'s package name and rendered on the bundle\'s page between its description and its rows (`view: \'page\'` onl', registrantStatic: 'dsh-bridge-next×1; dsh-experimental-client-ui-cot-translation×1; dsh-experimental-client-ui-voice-input×1', injectStatic: 'dsh-experimental-client-ui-cot-translation×1; dsh-experimental-client-ui-voice-input×1' },
260
+ { key: 'plugins.detail.actions', kind: 'list', scope: 'root', risk: 'none', purpose: 'Controls at the head of a detail page, before the page\'s own switch and uninstall, rendered with the page\'s subject.', registrantStatic: 'dsh-bridge-next×1', injectStatic: '' },
261
+ { key: 'plugins.detail.badge', kind: 'list', scope: 'root', risk: 'none', purpose: 'Tags beside a detail page\'s title, after the version, beta, and problem tags the page draws itself, rendered with the page\'s subject.', registrantStatic: '', injectStatic: '' },
262
+ { key: 'plugins.detail.section', kind: 'list', scope: 'root', risk: 'none', purpose: 'Sections under a detail page\'s own content: after the source on a bundle\'s page, after the configuration on a row\'s or an official plugin\'s page.', registrantStatic: '', injectStatic: '' },
263
+ { key: 'plugins.item', kind: 'list', scope: 'root', risk: 'none', purpose: 'One official plugin the Plugins page lists in its Official group after the official bundles: `label` is the card\'s title and `order` its place.', registrantStatic: 'dsh-client-ui-settings-agent-loop×1; dsh-client-ui-settings-shell×1; dsh-client-ui-settings-subagent×1; dsh-client-ui-settings-web-search×1', injectStatic: 'dsh-client-ui-settings-agent-loop×1; dsh-client-ui-settings-shell×1; dsh-client-ui-settings-subagent×1; dsh-client-ui-settings-web-search×1' },
264
+ { key: 'plugins.row.config', kind: 'keyed', scope: 'root', risk: 'none', purpose: 'The configuration of one row a bundle declares, keyed by `<package name>#<row id>` with the row id as the bundle\'s patch declares it: the row on the bundle\'s ', registrantStatic: '', injectStatic: '' },
265
+ { key: 'plugins.tab', kind: 'list', scope: 'root', risk: 'none', purpose: 'Tabs after the page\'s own Installed tab, such as Discover: `label` names the tab and `order` places it.', registrantStatic: 'dsh-client-ui-plugin-market×1', injectStatic: 'dsh-client-ui-plugin-market×1' },
266
+ { key: 'rightbar', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'The right column: a track the centre makes room for, or nothing.', registrantStatic: 'dsh-client-ui-sidebar-right×1', injectStatic: 'dsh-client-ui-sidebar-right×1' },
267
+ { key: 'rightbar.session', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Session content selected by the root-scoped right Sidebar controller.', registrantStatic: 'dsh-client-ui-sidebar-right×1', injectStatic: '' },
268
+ { key: 'root', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'The built-in render-tree root hole (seeded by SlotCore): the one slot the shell itself renders, and the ancestor of every other seat.', registrantStatic: 'dsh-client-ui-layout×1', injectStatic: '' },
269
+ { key: 'settings.action', kind: 'list', scope: 'root', risk: 'none', purpose: 'Optional actions rendered in the content-column header before Close.', registrantStatic: 'dsh-client-ui-settings-general×1', injectStatic: 'dsh-client-ui-settings-general×1' },
270
+ { key: 'settings.close', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'The close button\'s visually-hidden label text (the button itself — icon, geometry, focus — is shell chrome).', registrantStatic: 'dsh-client-ui-settings-general×1', injectStatic: 'dsh-client-ui-settings-general×1' },
271
+ { key: 'settings.general.item', kind: 'list', scope: 'root', risk: 'none', purpose: 'One preference row inside the General section — the additive seat for a single setting that needs no page of its own (a whole page is `settings.section`), contr', registrantStatic: 'dsh-client-ui-chat×3; dsh-client-ui-settings-general×2; dsh-client-ui-theme×2; dsh-client-locale×1; dsh-client-ui-conversation×1; dsh-client-ui-permission-presets×1; dsh-client-ui-settings-session-log×1; dsh-client-ui-shortcuts×1', injectStatic: 'dsh-client-ui-chat×3; dsh-client-ui-settings-general×2; dsh-client-ui-theme×2; dsh-client-locale×1; dsh-client-ui-conversation×1; dsh-client-ui-permission-presets×1; dsh-client-ui-settings-session-log×1; dsh-client-ui-shortcuts×1' },
272
+ { key: 'settings.header', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'The panel title text seat.', registrantStatic: 'dsh-client-ui-settings-general×1', injectStatic: 'dsh-client-ui-settings-general×1' },
273
+ { key: 'settings.launcher', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Optional sidebar account launcher; opens the shell-owned settings panel.', registrantStatic: 'dsh-client-ui-settings-account×1', injectStatic: 'dsh-client-ui-settings-account×1' },
274
+ { key: 'settings.models.footer', kind: 'list', scope: 'root', risk: 'none', purpose: 'Ordered extension area after the provider rows and the add controls.', registrantStatic: '', injectStatic: '' },
275
+ { key: 'settings.models.provider-card', kind: 'keyed', scope: 'root', risk: 'none', purpose: 'One provider card\'s adapter extension area, dispatched with `entryKey = settingsNs` on every card that renders a directory row: a saved row\'s card (its first-', registrantStatic: '', injectStatic: '' },
276
+ { key: 'settings.models.sign-in', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Optional account login choice before the credential editor.', registrantStatic: 'dsh-client-ui-settings-account×1', injectStatic: 'dsh-client-ui-settings-account×1' },
277
+ { key: 'settings.onboarding', kind: 'list', scope: 'root', risk: 'none', purpose: 'Root-scoped onboarding steps contributed by settings features.', registrantStatic: 'dsh-client-ui-settings-models×2', injectStatic: 'dsh-client-ui-settings-models×2' },
278
+ { key: 'settings.plugins.tab', kind: 'list', scope: 'root', risk: 'none', purpose: 'One page inside the Plugins settings section.', registrantStatic: 'dsh-client-ui-settings-plugin-inventory×1; dsh-community-market×1', injectStatic: 'dsh-client-ui-settings-plugin-inventory×1; dsh-community-market×1' },
279
+ { key: 'settings.section', kind: 'list', scope: 'root', risk: 'none', purpose: 'One settings page per list entry.', registrantStatic: 'dsh-client-ui-agent-preset×1; dsh-client-ui-settings-account×1; dsh-client-ui-settings-general×1; dsh-client-ui-settings-models×1; dsh-client-ui-settings-plugins×1', injectStatic: 'dsh-client-ui-agent-preset×1; dsh-client-ui-settings-account×1; dsh-client-ui-settings-general×1; dsh-client-ui-settings-models×1; dsh-client-ui-settings-plugins×1' },
280
+ { key: 'settings.section.icon', kind: 'list', scope: 'root', risk: 'none', purpose: 'Optional navigation icons addressed by the matching settings.section id.', registrantStatic: '', injectStatic: '' },
281
+ { key: 'settings.trigger', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'The sidebar-foot trigger row content: icon + label, supplied as slot content (the accessible name comes from the content — rail state renders the label visually', registrantStatic: 'dsh-client-ui-settings-general×1', injectStatic: 'dsh-client-ui-settings-general×1' },
282
+ { key: 'shell.bottom', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Full-width bottom content below all three columns.', registrantStatic: 'dsh-experimental-inspector×1', injectStatic: 'dsh-experimental-inspector×1' },
283
+ { key: 'shell.leading', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Window-chrome seat at the frame\'s top-left, over every main panel.', registrantStatic: 'dsh-client-ui-sidebar×1', injectStatic: 'dsh-client-ui-sidebar×1' },
284
+ { key: 'shell.overlay', kind: 'list', scope: 'root', risk: 'none', purpose: 'Frame-wide floating layer, above every column and outside their scroll containers.', registrantStatic: 'dsh-client-ui-workspace×3; dsh-client-ui-settings-account×2; dsh-client-ui-chat×1; dsh-client-ui-context-menu×1; dsh-client-ui-file-drag×1; dsh-client-ui-open-in-app×1; dsh-client-ui-plugin-manager×1; dsh-client-ui-schedule×1; dsh-client-ui-settings-general×1; dsh-client-ui-settings-session-log×1; dsh-client-ui-shortcuts×1; dsh-community-market×1; dsh-experimental-client-ui-forge×1; dsh-session-log-export×1', injectStatic: 'dsh-client-ui-settings-account×2; dsh-client-ui-chat×1; dsh-client-ui-context-menu×1; dsh-client-ui-file-drag×1; dsh-client-ui-open-in-app×1; dsh-client-ui-plugin-manager×1; dsh-client-ui-schedule×1; dsh-client-ui-settings-general×1; dsh-client-ui-settings-session-log×1; dsh-client-ui-shortcuts×1; dsh-client-ui-workspace×1; dsh-community-market×1; dsh-experimental-client-ui-forge×1; dsh-session-log-export×1' },
285
+ { key: 'shell.quota-notice', kind: 'chain', scope: 'root', risk: 'none', purpose: 'Frame-wide quota notice chain.', registrantStatic: 'dsh-client-ui-settings-account×1', injectStatic: 'dsh-client-ui-settings-account×1' },
286
+ { key: 'sidebar', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'The whole left column.', registrantStatic: 'dsh-client-ui-sidebar×1', injectStatic: 'dsh-client-ui-sidebar×1' },
287
+ { key: 'sidebar.brand.mark', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Brand mark rendered in the expanded brand row and collapsed rail.', registrantStatic: 'dsh-client-ui-brand-official×1; dsh-experimental-liveshare×1', injectStatic: 'dsh-client-ui-brand-official×1; dsh-experimental-liveshare×1' },
288
+ { key: 'sidebar.brand.name', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Brand name rendered beside the expanded mark.', registrantStatic: 'dsh-client-ui-brand-official×1; dsh-experimental-liveshare×1', injectStatic: 'dsh-client-ui-brand-official×1; dsh-experimental-liveshare×1' },
289
+ { key: 'sidebar.chat.conversation', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Session-scoped Conversation occurrence hosted by one Sidebar chat tab.', registrantStatic: 'dsh-client-ui-subagent×1', injectStatic: 'dsh-client-ui-subagent×1' },
290
+ { key: 'sidebar.footer.action', kind: 'list', scope: 'root', risk: 'none', purpose: 'Optional actions beside Settings at the sidebar foot.', registrantStatic: 'dsh-bridge-next×1; dsh-client-ui-cordis×1; dsh-community-market×1', injectStatic: 'dsh-bridge-next×1; dsh-client-ui-cordis×1; dsh-community-market×1' },
291
+ { key: 'sidebar.panellist', kind: 'list', scope: 'root', risk: 'none', purpose: 'Global panel icons.', registrantStatic: 'dsh-client-ui-plugin-manager×1; dsh-client-ui-schedule×1', injectStatic: 'dsh-client-ui-plugin-manager×1; dsh-client-ui-schedule×1' },
292
+ { key: 'sidebar.panellist.actions', kind: 'list', scope: 'root', risk: 'none', purpose: 'Rows of the panel list\'s More menu; the sidebar shows More only while this list has registrations.', registrantStatic: 'dsh-client-ui-entry-customization×1', injectStatic: 'dsh-client-ui-entry-customization×1' },
293
+ { key: 'sidebar.right.pane.tab', kind: 'keyed', scope: 'session', risk: 'none', purpose: 'One tab\'s body, dispatched with the `id` of the type in force for `tab.kind`.', registrantStatic: 'dsh-experimental-client-ui-forge×2; dsh-client-ui-deliverables×1; dsh-client-ui-plan×1; dsh-client-ui-schedule×1; dsh-client-ui-sidebar-browser×1; dsh-client-ui-sidebar-documentpreview×1; dsh-client-ui-sidebar-files×1; dsh-client-ui-sidebar-right×1; dsh-client-ui-sidebar-terminal×1; dsh-client-ui-subagent×1; dsh-experimental-liveshare×1; dsh-experimental-session-inspector×1', injectStatic: 'dsh-experimental-client-ui-forge×2; dsh-client-ui-deliverables×1; dsh-client-ui-plan×1; dsh-client-ui-schedule×1; dsh-client-ui-sidebar-browser×1; dsh-client-ui-sidebar-documentpreview×1; dsh-client-ui-sidebar-files×1; dsh-client-ui-sidebar-right×1; dsh-client-ui-sidebar-terminal×1; dsh-client-ui-subagent×1; dsh-experimental-liveshare×1; dsh-experimental-session-inspector×1' },
294
+ { key: 'sidebar.right.pane.tab.title', kind: 'keyed', scope: 'session', risk: 'none', purpose: 'A tab\'s title as its chip (and a floating panel\'s header) shows it, dispatched with the same key and information hook as the body.', registrantStatic: 'dsh-experimental-client-ui-forge×2; dsh-client-ui-plan×1; dsh-client-ui-schedule×1; dsh-client-ui-sidebar-browser×1; dsh-client-ui-sidebar-documentpreview×1; dsh-client-ui-sidebar-files×1; dsh-client-ui-sidebar-right×1; dsh-client-ui-sidebar-terminal×1', injectStatic: 'dsh-experimental-client-ui-forge×2; dsh-client-ui-plan×1; dsh-client-ui-schedule×1; dsh-client-ui-sidebar-browser×1; dsh-client-ui-sidebar-documentpreview×1; dsh-client-ui-sidebar-files×1; dsh-client-ui-sidebar-right×1; dsh-client-ui-sidebar-terminal×1' },
295
+ { key: 'sidebar.right.tab.document', kind: 'keyed', scope: 'session', risk: 'none', purpose: 'Document body selected by a registered implementation id.', registrantStatic: 'dsh-client-ui-sidebar-documentpreview×8', injectStatic: 'dsh-client-ui-sidebar-documentpreview×8' },
296
+ { key: 'sidebar.right.tab.document.action', kind: 'keyed', scope: 'session', risk: 'none', purpose: 'Renderer-specific controls before the document toolbar\'s reload button.', registrantStatic: 'dsh-client-ui-sidebar-documentpreview×1', injectStatic: 'dsh-client-ui-sidebar-documentpreview×1' },
297
+ { key: 'sidebar.right.tab.document.actions', kind: 'list', scope: 'session', risk: 'none', purpose: 'Header toolbar contributions acting on the previewed file, rendered after the preview\'s own controls once the file\'s Host path is known.', registrantStatic: 'dsh-client-ui-open-in-app×1', injectStatic: 'dsh-client-ui-open-in-app×1' },
298
+ { key: 'sidebar.right.tab.document.office.pdf', kind: 'keyed', scope: 'session', risk: 'none', purpose: 'PDF presentation supplied with Office-owned converted bytes.', registrantStatic: 'dsh-client-ui-sidebar-documentpreview×1', injectStatic: 'dsh-client-ui-sidebar-documentpreview×1' },
299
+ { key: 'sidebar.right.tab.document.unpreviewable', kind: 'list', scope: 'session', risk: 'none', purpose: 'Empty-state contributions for a file this preview cannot render, offered where Retry would stand once the file\'s Host path is known.', registrantStatic: 'dsh-client-ui-open-in-app×1', injectStatic: 'dsh-client-ui-open-in-app×1' },
300
+ { key: 'sidebar.right.tab.files.actions', kind: 'list', scope: 'session', risk: 'none', purpose: 'Workspace directory actions after the `files` page\'s reload control.', registrantStatic: 'dsh-client-ui-open-in-app×1', injectStatic: 'dsh-client-ui-open-in-app×1' },
301
+ { key: 'sidebar.right.tab.guide', kind: 'chain', scope: 'session', risk: 'none', purpose: 'The guide tab\'s body.', registrantStatic: '', injectStatic: '' },
302
+ { key: 'sidebar.right.tab.guide.actions', kind: 'list', scope: 'root', risk: 'none', purpose: 'Rows of the guide\'s More menu; the guide shows More only while this list has registrations.', registrantStatic: 'dsh-client-ui-entry-customization×1', injectStatic: 'dsh-client-ui-entry-customization×1' },
303
+ { key: 'sidebar.right.tab.guide.entry', kind: 'keyed', scope: 'session', risk: 'none', purpose: 'One provider\'s guide card, with the standard card as the owner\'s fallback.', registrantStatic: 'dsh-client-ui-sidebar-terminal×1', injectStatic: 'dsh-client-ui-sidebar-terminal×1' },
304
+ { key: 'sidebar.right.tab.menu.item', kind: 'list', scope: 'session', risk: 'none', purpose: 'Extra items at the end of one tab\'s actions menu, in registration order.', registrantStatic: '', injectStatic: '' },
305
+ { key: 'sidebar.session.row.hover', kind: 'list', scope: 'root', risk: 'none', purpose: 'Section of the Session row\'s hover card between its relative time and its trailing status line.', registrantStatic: 'dsh-client-ui-schedule×1; dsh-experimental-client-ui-forge×1', injectStatic: 'dsh-client-ui-schedule×1; dsh-experimental-client-ui-forge×1' },
306
+ { key: 'sidebar.session.row.leading', kind: 'list', scope: 'root', risk: 'none', purpose: 'Leading decoration of one Session row, in the 16px cell before the title that the row\'s own state dot otherwise occupies.', registrantStatic: 'dsh-client-ui-schedule×1; dsh-experimental-liveshare×1', injectStatic: 'dsh-client-ui-schedule×1; dsh-experimental-liveshare×1' },
307
+ { key: 'sidebar.session.row.trailing', kind: 'list', scope: 'root', risk: 'none', purpose: 'Non-interactive icons after the row\'s time label, before its pin marker, in ascending `order`.', registrantStatic: 'dsh-experimental-client-ui-forge×1', injectStatic: 'dsh-experimental-client-ui-forge×1' },
308
+ { key: 'sidebar.settings', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'The settings seat at the sidebar foot.', registrantStatic: 'dsh-client-ui-settings-general×1', injectStatic: 'dsh-client-ui-settings-general×1' },
309
+ { key: 'sidebar.toggle.badge', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Non-interactive notification inside the collapsed sidebar expand button.', registrantStatic: 'dsh-client-ui-settings-general×1', injectStatic: 'dsh-client-ui-settings-general×1' },
310
+ { key: 'sidebar.workspaces', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'The workspace/session browsing region: section header, search, the grouped/flat session list, and every workspace dialog.', registrantStatic: 'dsh-client-ui-workspace×1', injectStatic: 'dsh-client-ui-workspace×1' },
311
+ { key: 'sidebar.workspaces.directoryFlow', kind: 'single', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Directory-flow hole under the sidebar browsing region (declared by the WorkspaceBrowser entry).', registrantStatic: 'dsh-client-ui-directory-picker-browse×1; dsh-client-ui-directory-picker-native×1', injectStatic: 'dsh-client-ui-directory-picker-browse×1; dsh-client-ui-directory-picker-native×1' },
312
+ { key: 'sidebar.workspaces.session.menu.item', kind: 'list', scope: 'root', risk: 'none', purpose: 'Legacy external Session menu rows, in ascending `order`, rendered together before the built-in Archive action.', registrantStatic: '', injectStatic: '' },
313
+ { key: 'sidebar.workspaces.session.row.action', kind: 'list', scope: 'root', risk: 'none', purpose: 'The hover buttons at the end of one Session row, in ascending `order`, after the "..." menu trigger.', registrantStatic: 'dsh-client-ui-workspace×2', injectStatic: 'dsh-client-ui-workspace×1' },
314
+ { key: 'tool.call.images', kind: 'single', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Durable images of a settled image-bearing Tool call, rendered through the attachment presentation plugin.', registrantStatic: 'dsh-client-ui-attachment×1', injectStatic: 'dsh-client-ui-attachment×1' },
315
+ { key: 'tool.call.toolview', kind: 'keyed', scope: 'session', risk: 'shadows-shipped-ui', purpose: 'Keyed Tool view dispatched by wire name, including custom tools.', registrantStatic: 'dsh-client-ui-tool×51; dsh-client-ui-cordis×4; dsh-client-ui-action-cards×1; dsh-client-ui-deliverables×1; dsh-client-ui-skill×1', injectStatic: 'dsh-client-ui-tool×9; dsh-client-ui-cordis×3; dsh-client-ui-action-cards×1; dsh-client-ui-deliverables×1; dsh-client-ui-skill×1' },
316
+ { key: 'tool.view.cordis', kind: 'keyed', scope: 'session', risk: 'none', purpose: 'Interactive Package-owned region rendered inside the latest eligible `cordis_run` card in the conversation flow.', registrantStatic: '', injectStatic: '' },
317
+ { key: 'workspace.toast', kind: 'keyed', scope: 'root', risk: 'shadows-shipped-ui', purpose: 'Workspace notices selected by their existing business discriminator.', registrantStatic: 'dsh-client-ui-workspace×11', injectStatic: 'dsh-client-ui-workspace×1' },
318
+ ];
319
+
320
+ const KIND_ORDER = ['single', 'list', 'keyed', 'chain'];
321
+
322
+ let React = null;
323
+
324
+ const SURFACE_KEYS = ['tab', 'sidebar', 'topbar'];
325
+
326
+ function hasOwn(target, key) {
327
+ return Object.prototype.hasOwnProperty.call(target, key);
328
+ }
329
+
330
+ function isPlainObject(value) {
331
+ return typeof value === 'object' && value !== null && Array.isArray(value) === false;
332
+ }
333
+
334
+ function clamp(value, min, max) {
335
+ return Math.min(max, Math.max(min, value));
336
+ }
337
+
338
+ function catalogByKey() {
339
+ const map = new Map();
340
+ for (const slot of SLOT_CATALOG) map.set(slot.key, slot);
341
+ return map;
342
+ }
343
+
344
+ const SLOTS_BY_KEY = catalogByKey();
345
+
346
+ /* ---------------------------------------------------------------- settings */
347
+
348
+ function defaultSettings() {
349
+ return {
350
+ version: SETTINGS_VERSION,
351
+ hidden: {},
352
+ locators: {},
353
+ visualOrder: {},
354
+ presets: {},
355
+ activePreset: null,
356
+ nav: { follow: true, state: 'expanded' },
357
+ };
358
+ }
359
+
360
+ function sanitizeName(raw) {
361
+ if (typeof raw !== 'string') return '';
362
+ return raw.replace(/\s+/g, ' ').trim().slice(0, PRESET_NAME_MAX);
363
+ }
364
+
365
+ function sanitizeLocatorKey(raw) {
366
+ if (typeof raw !== 'string') return '';
367
+ const [slotKey, ...rest] = raw.split('::');
368
+ if (SLOTS_BY_KEY.has(slotKey) === false) return '';
369
+ const entryId = rest.join('::');
370
+ if (entryId === '') return '';
371
+ return slotKey + '::' + entryId;
372
+ }
373
+
374
+ function sanitizeSelector(raw) {
375
+ if (typeof raw !== 'string') return '';
376
+ const value = raw.trim();
377
+ if (value === '' || value.length > SELECTOR_MAX) return '';
378
+ if (value.includes('{') || value.includes('}')) return '';
379
+ return value;
380
+ }
381
+
382
+ function sanitizeHidden(raw) {
383
+ const next = {};
384
+ if (isPlainObject(raw) === false) return next;
385
+ for (const [slotKey, entries] of Object.entries(raw)) {
386
+ if (SLOTS_BY_KEY.has(slotKey) === false || isPlainObject(entries) === false) continue;
387
+ const kept = {};
388
+ for (const [entryId, value] of Object.entries(entries)) {
389
+ if (value === true && entryId !== '') kept[entryId] = true;
390
+ }
391
+ if (Object.keys(kept).length > 0) next[slotKey] = kept;
392
+ }
393
+ return next;
394
+ }
395
+
396
+ function sanitizeLocators(raw) {
397
+ const next = {};
398
+ if (isPlainObject(raw) === false) return next;
399
+ let count = 0;
400
+ for (const [key, selector] of Object.entries(raw)) {
401
+ if (count >= LOCATOR_LIMIT) break;
402
+ const cleanKey = sanitizeLocatorKey(key);
403
+ const cleanSelector = sanitizeSelector(selector);
404
+ if (cleanKey === '' || cleanSelector === '') continue;
405
+ next[cleanKey] = cleanSelector;
406
+ count += 1;
407
+ }
408
+ return next;
409
+ }
410
+
411
+ /**
412
+ * CSS `order` is not the host's registration `order`: ours only changes paint
413
+ * order inside one flex/grid container, never the DOM and never anybody's entry.
414
+ * The old field was called `order`, which read like the host's — renamed, with
415
+ * an alias so existing saves keep working (no SETTINGS_VERSION bump).
416
+ */
417
+ function sanitizeVisualOrder(raw) {
418
+ const next = {};
419
+ if (isPlainObject(raw) === false) return next;
420
+ for (const [key, value] of Object.entries(raw)) {
421
+ const cleanKey = sanitizeLocatorKey(key);
422
+ if (cleanKey === '') continue;
423
+ const numeric = Number(value);
424
+ if (Number.isFinite(numeric) === false) continue;
425
+ next[cleanKey] = clamp(Math.round(numeric), -999, 999);
426
+ }
427
+ return next;
428
+ }
429
+
430
+ function sanitizePresets(raw) {
431
+ const next = {};
432
+ if (isPlainObject(raw) === false) return next;
433
+ for (const [name, preset] of Object.entries(raw)) {
434
+ const cleanName = sanitizeName(name);
435
+ if (cleanName === '' || isPlainObject(preset) === false) continue;
436
+ next[cleanName] = {
437
+ hidden: sanitizeHidden(preset.hidden),
438
+ visualOrder: sanitizeVisualOrder(preset.visualOrder ?? preset.order),
439
+ };
440
+ }
441
+ return next;
442
+ }
443
+
444
+ /** `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
+ function sanitizeSettings(raw) {
454
+ const base = defaultSettings();
455
+ if (isPlainObject(raw) === false) return base;
456
+ const next = base;
457
+ next.hidden = sanitizeHidden(raw.hidden);
458
+ next.locators = sanitizeLocators(raw.locators);
459
+ next.visualOrder = sanitizeVisualOrder(raw.visualOrder ?? raw.order);
460
+ next.presets = sanitizePresets(raw.presets);
461
+ next.activePreset = typeof raw.activePreset === 'string' && hasOwn(next.presets, raw.activePreset) ? raw.activePreset : null;
462
+ next.nav = sanitizeNav(raw.nav);
463
+ return next;
464
+ }
465
+
466
+ /* ------------------------------------------------------------------ storage */
467
+
468
+ let settingsCache = null;
469
+
470
+ function storage() {
471
+ try {
472
+ return typeof localStorage === 'undefined' ? null : localStorage;
473
+ } catch {
474
+ return null;
475
+ }
476
+ }
477
+
478
+ function readStored(key) {
479
+ const store = storage();
480
+ if (store === null) return undefined;
481
+ try {
482
+ const raw = store.getItem(key);
483
+ if (raw === null || raw === undefined || raw === '') return undefined;
484
+ return JSON.parse(raw);
485
+ } catch {
486
+ return undefined;
487
+ }
488
+ }
489
+
490
+ function writeStored(key, value) {
491
+ const store = storage();
492
+ if (store === null) return;
493
+ try {
494
+ store.setItem(key, JSON.stringify(value));
495
+ } catch {
496
+ /* a full quota must not take the page down */
497
+ }
498
+ }
499
+
500
+ function readPreserved() {
501
+ const raw = readStored(PRESERVED_KEY);
502
+ return isPlainObject(raw) ? raw : {};
503
+ }
504
+
505
+ function readBackups() {
506
+ const raw = readStored(BACKUP_KEY);
507
+ return Array.isArray(raw) ? raw.filter(isPlainObject).slice(0, BACKUP_LIMIT) : [];
508
+ }
509
+
510
+ function pushBackup(previous) {
511
+ writeStored(BACKUP_KEY, [{ at: Date.now(), settings: previous }, ...readBackups()].slice(0, BACKUP_LIMIT));
512
+ }
513
+
514
+ function readSettings() {
515
+ if (settingsCache !== null) return settingsCache;
516
+ const stored = readStored(SETTINGS_KEY);
517
+ const preserved = readPreserved();
518
+ const merged = isPlainObject(stored) ? { ...stored, ...preserved } : { ...preserved };
519
+ settingsCache = sanitizeSettings(merged);
520
+ return settingsCache;
521
+ }
522
+
523
+ function writeSettings(next) {
524
+ const previous = readStored(SETTINGS_KEY);
525
+ if (isPlainObject(previous)) pushBackup(previous);
526
+ settingsCache = sanitizeSettings(next);
527
+ writeStored(SETTINGS_KEY, settingsCache);
528
+ return settingsCache;
529
+ }
530
+
531
+ function patchSettings(patch) {
532
+ const base = readSettings();
533
+ const locators = { ...base.locators, ...(isPlainObject(patch.locators) ? patch.locators : {}) };
534
+ const requested = {
535
+ ...base.visualOrder,
536
+ ...(isPlainObject(patch.visualOrder) ? patch.visualOrder : isPlainObject(patch.order) ? patch.order : {}),
537
+ };
538
+ /* A number without a binding can never be applied: dropping the locator drops
539
+ its order in the same write, so no invisible leftovers survive. */
540
+ const visualOrder = {};
541
+ for (const [key, value] of Object.entries(requested)) {
542
+ if (typeof locators[key] === 'string' && locators[key] !== '') visualOrder[key] = value;
543
+ }
544
+ return writeSettings({
545
+ hidden: { ...base.hidden, ...(isPlainObject(patch.hidden) ? patch.hidden : {}) },
546
+ locators,
547
+ visualOrder,
548
+ presets: isPlainObject(patch.presets) ? patch.presets : base.presets,
549
+ activePreset: hasOwn(patch, 'activePreset') ? patch.activePreset : base.activePreset,
550
+ nav: { ...(isPlainObject(base.nav) ? base.nav : {}), ...(isPlainObject(patch.nav) ? patch.nav : {}) },
551
+ });
552
+ }
553
+
554
+ function resetSettings() {
555
+ settingsCache = null;
556
+ writeSettings(defaultSettings());
557
+ return readSettings();
558
+ }
559
+
560
+ /* --------------------------------------------------------------- inventory */
561
+
562
+ function entryIdOf(entry, index) {
563
+ const options = isPlainObject(entry) && isPlainObject(entry.options) ? entry.options : {};
564
+ if (typeof options.id === 'string' && options.id !== '') return options.id;
565
+ if (typeof options.key === 'string' && options.key !== '') return options.key;
566
+ if (typeof options.label === 'string' && options.label !== '') return 'label:' + options.label;
567
+ return 'priority:' + (Number(options.priority) || 0) + '#' + index;
568
+ }
569
+
570
+ function registrantOf(entry) {
571
+ if (isPlainObject(entry) === false) return '';
572
+ if (typeof entry.registrant === 'string') return entry.registrant;
573
+ if (isPlainObject(entry.options) && typeof entry.options.registrant === 'string') return entry.options.registrant;
574
+ return '';
575
+ }
576
+
577
+ function locatorKeyOf(slotKey, entryId) {
578
+ return slotKey + '::' + entryId;
579
+ }
580
+
581
+ /**
582
+ * Flatten the registry into rows a table can render.
583
+ *
584
+ * `entriesOf` is injected so this stays a pure function: the real caller passes
585
+ * `(key) => slots.entriesOfSlot(key)`, the unit test passes a plain object.
586
+ */
587
+ /**
588
+ * Normalise one registry entry into the shape the table expects.
589
+ *
590
+ * Live occupants from `slots.snapshot()` are flat (`{ id?, key?, order?, priority, active, registrant? }`);
591
+ * entries read through `entriesOfSlot()` carry the same fields under `options`.
592
+ */
593
+ /**
594
+ * Shipped UI, decided from the static entry id.
595
+ *
596
+ * The live registrant is useless here: every dynamically loaded plugin reports
597
+ * the same runner name (`tk`), so a comparison against it flags our own
598
+ * entries as shipped and misses the real ones. Shipped entries are the ones
599
+ * whose id *is* a package name — `@deepseek-ai/dsh-client-ui-deliverables` —
600
+ * and, in a `single` slot, the sole occupant of a slot whose static table
601
+ * names a shipped package.
602
+ */
603
+ function builtinOf(entryId, kind, registrantStatic) {
604
+ if (/^(?:@deepseek-ai\/dsh|dsh-(?:client-ui|experimental|cli|tool|api))/.test(entryId)) return true;
605
+ if (kind === 'single' && String(registrantStatic).includes('dsh-client-ui')) return true;
606
+ return false;
607
+ }
608
+
609
+ /**
610
+ * A slot whose every registrant is a shipped package — and which still cannot
611
+ * say *which* row came from where.
612
+ *
613
+ * Keyed slots register per key with no entry→registrar mapping, so a row there
614
+ * can be neither proven built-in nor cleared. The static column still tells us
615
+ * something useful: if every registrar listed for the slot is ours, the rows are
616
+ * almost certainly shipped chrome. That is a note, not a gate — the controls stay
617
+ * on, because cleaning up host menu items is the whole point.
618
+ */
619
+ function shippedSlotOf(kind, registrantStatic) {
620
+ if (kind === 'single') return false;
621
+ const parts = String(registrantStatic)
622
+ .split(';')
623
+ .map((part) => part.trim())
624
+ .filter((part) => part !== '');
625
+ if (parts.length === 0) return false;
626
+ return parts.every((part) => /^(?:@deepseek-ai\/|dsh-(?:client-ui|experimental|cli|tool|api))/.test(part));
627
+ }
628
+
629
+ function normalizeEntry(entry) {
630
+ if (isPlainObject(entry) === false) return { options: { priority: 0 }, registrant: '' };
631
+ const source = isPlainObject(entry.options) ? entry.options : entry;
632
+ return {
633
+ options: { ...source, priority: Number(source.priority) || 0 },
634
+ registrant: registrantOf(entry),
635
+ };
636
+ }
637
+
638
+ /** Flatten `snapshot()`'s declaration tree (slots + factory children) into one key→node map. */
639
+ function flattenSnapshot(nodes, into) {
640
+ for (const node of Array.isArray(nodes) ? nodes : []) {
641
+ if (isPlainObject(node) === false) continue;
642
+ if (node.type === 'slot' && typeof node.name === 'string') {
643
+ into.set(node.name, {
644
+ key: node.name,
645
+ kind: typeof node.kind === 'string' ? node.kind : 'single',
646
+ scope: typeof node.scope === 'string' ? node.scope : 'root',
647
+ occupants: Array.isArray(node.occupants) ? node.occupants : [],
648
+ });
649
+ }
650
+ flattenSnapshot(node.children, into);
651
+ }
652
+ return into;
653
+ }
654
+
655
+ /**
656
+ * The live slot directory, read from the registry itself.
657
+ *
658
+ * `snapshot()` is the authority: it lists exactly the slots declared in this
659
+ * process, with their current occupants. The static `SLOT_CATALOG` stays as the
660
+ * fallback (registry missing, or it throws) and as the only source of
661
+ * `risk`/`purpose`, which are documentation, not runtime state.
662
+ */
663
+ function runtimeCatalog(slots) {
664
+ if (slots === null || slots === undefined) return null;
665
+ if (typeof slots.snapshot !== 'function') return null;
666
+ let nodes = null;
667
+ try {
668
+ nodes = slots.snapshot();
669
+ } catch {
670
+ return null;
671
+ }
672
+ const map = flattenSnapshot(nodes, new Map());
673
+ return map.size === 0 ? null : map;
674
+ }
675
+
676
+ /**
677
+ * Flatten the registry into rows a table can render.
678
+ *
679
+ * `entriesOf` and `live` are injected so this stays a pure function: the real
680
+ * caller passes `(key) => slots.entriesOfSlot(key)` plus `runtimeCatalog(slots)`,
681
+ * the unit test passes a plain object and nothing.
682
+ */
683
+ function slotRows(entriesOf, settings, live) {
684
+ const rows = [];
685
+ const empty = [];
686
+ const liveMap = live instanceof Map ? live : null;
687
+ const keys = liveMap === null ? SLOT_CATALOG.map((slot) => slot.key) : [...liveMap.keys()];
688
+ const visual = isPlainObject(settings.visualOrder) ? settings.visualOrder : {};
689
+ for (const key of keys) {
690
+ const meta = SLOTS_BY_KEY.get(key);
691
+ const runtime = liveMap === null ? null : liveMap.get(key);
692
+ const kind = typeof runtime?.kind === 'string' ? runtime.kind : meta?.kind ?? 'single';
693
+ const scope = typeof runtime?.scope === 'string' ? runtime.scope : meta?.scope ?? 'root';
694
+ const risk = meta?.risk ?? 'none';
695
+ const purpose = meta?.purpose ?? '';
696
+ const registrantStatic = meta?.registrantStatic ?? '';
697
+ let entries = [];
698
+ if (liveMap === null) {
699
+ try {
700
+ entries = typeof entriesOf === 'function' ? entriesOf(key) ?? [] : [];
701
+ } catch {
702
+ entries = [];
703
+ }
704
+ } else {
705
+ entries = runtime?.occupants ?? [];
706
+ }
707
+ const list = Array.isArray(entries) ? entries.map(normalizeEntry) : [];
708
+ if (list.length === 0) {
709
+ empty.push({ key, kind, scope, risk, purpose, registrantStatic });
710
+ continue;
711
+ }
712
+ list.forEach((entry, index) => {
713
+ const entryId = entryIdOf(entry, index);
714
+ const rowKey = locatorKeyOf(key, entryId);
715
+ const options = entry.options;
716
+ rows.push({
717
+ key: rowKey,
718
+ slotKey: key,
719
+ kind,
720
+ scope,
721
+ risk,
722
+ purpose,
723
+ entryId,
724
+ label: typeof options.label === 'string' ? options.label : '',
725
+ registrant: registrantStatic,
726
+ registrantLive: entry.registrant,
727
+ priority: Number(options.priority) || 0,
728
+ order: Number(options.order) || 0,
729
+ visualOrder: hasOwn(visual, rowKey) ? visual[rowKey] : null,
730
+ hidden: isPlainObject(settings.hidden[key]) && settings.hidden[key][entryId] === true,
731
+ locator: typeof settings.locators[rowKey] === 'string' ? settings.locators[rowKey] : '',
732
+ risky: risk === 'shadows-shipped-ui',
733
+ builtin: builtinOf(entryId, kind, registrantStatic),
734
+ shippedSlot: shippedSlotOf(kind, registrantStatic),
735
+ });
736
+ });
737
+ }
738
+ rows.sort((a, b) => {
739
+ const bySlot = a.slotKey.localeCompare(b.slotKey);
740
+ if (bySlot !== 0) return bySlot;
741
+ const byPriority = a.priority - b.priority;
742
+ if (byPriority !== 0) return byPriority;
743
+ return a.entryId.localeCompare(b.entryId);
744
+ });
745
+ empty.sort((a, b) => a.key.localeCompare(b.key));
746
+ return {
747
+ rows,
748
+ empty,
749
+ totalSlots: keys.length,
750
+ occupiedSlots: keys.length - empty.length,
751
+ hiddenCount: rows.filter((row) => row.hidden).length,
752
+ riskyCount: rows.filter((row) => row.risk === 'shadows-shipped-ui').length,
753
+ builtinCount: rows.filter((row) => row.builtin).length,
754
+ shippedSlotCount: rows.filter((row) => row.shippedSlot).length,
755
+ locatorCount: rows.filter((row) => row.locator !== '').length,
756
+ orderedCount: rows.filter((row) => row.visualOrder !== null).length,
757
+ catalogSource: liveMap === null ? 'static' : 'runtime',
758
+ };
759
+ }
760
+
761
+ /**
762
+ * Which bound elements want a CSS `order`, and what number.
763
+ *
764
+ * Only bound entries have an element at all, and only entries inside the same
765
+ * flex/grid parent can be compared — the caller groups by `parentElement` at
766
+ * apply time and skips everything else. Nothing here touches an entry.
767
+ */
768
+ function visualTargets(settings) {
769
+ const targets = [];
770
+ for (const [key, value] of Object.entries(settings.visualOrder)) {
771
+ const selector = settings.locators[key];
772
+ if (typeof selector !== 'string' || selector === '') continue;
773
+ targets.push({ key, selector, value });
774
+ }
775
+ targets.sort((a, b) => a.value - b.value || a.key.localeCompare(b.key));
776
+ return targets;
777
+ }
778
+
779
+ /**
780
+ * The nearest ancestor that actually lays out flex/grid children.
781
+ *
782
+ * Slot entries are mounted inside a `[data-slot]` anchor whose own
783
+ * `display: contents` takes it out of the box tree: its children are laid out
784
+ * by the *grandparent*. Judging the anchor would refuse every entry the host
785
+ * renders, so walk outward until an element that generates a box.
786
+ */
787
+ function reorderHost(parent) {
788
+ if (parent === null || parent === undefined) return null;
789
+ const doc = typeof document === 'undefined' ? null : document;
790
+ if (doc === null || typeof doc.defaultView?.getComputedStyle !== 'function') return null;
791
+ let node = parent;
792
+ for (let depth = 0; node !== null && node !== undefined && depth < 32; depth += 1) {
793
+ let display = '';
794
+ try {
795
+ display = doc.defaultView.getComputedStyle(node).display;
796
+ } catch {
797
+ return null;
798
+ }
799
+ if (display === 'contents') {
800
+ node = node.parentElement;
801
+ continue;
802
+ }
803
+ return display === 'flex' || display === 'inline-flex' || display === 'grid' ? node : null;
804
+ }
805
+ return null;
806
+ }
807
+
808
+ /** Parents whose children CSS can actually re-order. */
809
+ function canReorder(parent) {
810
+ return reorderHost(parent) !== null;
811
+ }
812
+
813
+ /**
814
+ * Apply — or clear — `style.order` on every bound element.
815
+ *
816
+ * `touched` holds the nodes we wrote to, so the next pass and the teardown can
817
+ * clear exactly those. A stale `order` left on a node we no longer own is the
818
+ * one regression this feature invites.
819
+ */
820
+ function applyVisualOrder(doc, settings, touched) {
821
+ for (const element of touched) {
822
+ if (element.style !== undefined) element.style.order = '';
823
+ }
824
+ touched.length = 0;
825
+ if (doc === null || doc === undefined || typeof doc.querySelectorAll !== 'function') return touched;
826
+ for (const target of visualTargets(settings)) {
827
+ let found = [];
828
+ try {
829
+ found = Array.from(doc.querySelectorAll(target.selector));
830
+ } catch {
831
+ found = [];
832
+ }
833
+ for (const element of found) {
834
+ if (canReorder(element.parentElement) === false) continue;
835
+ if (element.style === undefined) continue;
836
+ element.style.order = String(target.value);
837
+ touched.push(element);
838
+ }
839
+ }
840
+ return touched;
841
+ }
842
+
843
+ function kindCounts() {
844
+ const counts = {};
845
+ for (const kind of KIND_ORDER) counts[kind] = 0;
846
+ for (const slot of SLOT_CATALOG) counts[slot.kind] = (counts[slot.kind] ?? 0) + 1;
847
+ return counts;
848
+ }
849
+
850
+ /* --------------------------------------------------------------- visibility */
851
+
852
+ function toggleHidden(settings, slotKey, entryId) {
853
+ const current = isPlainObject(settings.hidden[slotKey]) ? settings.hidden[slotKey] : {};
854
+ const next = { ...current };
855
+ if (next[entryId] === true) delete next[entryId];
856
+ else next[entryId] = true;
857
+ const hidden = { ...settings.hidden };
858
+ if (Object.keys(next).length === 0) delete hidden[slotKey];
859
+ else hidden[slotKey] = next;
860
+ return hidden;
861
+ }
862
+
863
+ function setLocator(settings, key, selector) {
864
+ const locators = { ...settings.locators };
865
+ if (selector === '') delete locators[key];
866
+ else locators[key] = selector;
867
+ return locators;
868
+ }
869
+
870
+ /** Dropping a key from a plain map, used when a binding goes away. */
871
+ function dropKey(map, key) {
872
+ const next = { ...map };
873
+ delete next[key];
874
+ return next;
875
+ }
876
+
877
+ function hiddenSelectors(settings) {
878
+ const out = [];
879
+ for (const [key, selector] of Object.entries(settings.locators)) {
880
+ const [slotKey, ...rest] = key.split('::');
881
+ const entryId = rest.join('::');
882
+ const entryHidden = isPlainObject(settings.hidden[slotKey]) && settings.hidden[slotKey][entryId] === true;
883
+ if (entryHidden) out.push({ key, selector });
884
+ }
885
+ return out;
886
+ }
887
+
888
+ /**
889
+ * Why a row cannot be toggled. Honest beats complete: an official entry has no
890
+ * toggle at all (hiding shipped chrome is what made us shadow the gear menu),
891
+ * and a third-party entry without a bound element has nothing to hide.
892
+ */
893
+ function locatorReason(settings, row) {
894
+ if (row !== undefined && row.builtin === true) return 'built-in UI — touching it would shadow shipped chrome';
895
+ if (settings.locators[row.key] !== undefined) return '';
896
+ return 'host does not expose an entry→DOM mapping; pick the element once to bind it';
897
+ }
898
+
899
+ /**
900
+ * Hiding is only offered where it can be undone and cannot blank shipped chrome:
901
+ * a third-party entry, in a repeatable slot, with a bound element. A `single`
902
+ * slot has one occupant by definition — hiding it is shadowing it.
903
+ */
904
+ function canHide(row) {
905
+ if (row.builtin === true) return false;
906
+ if (row.kind === 'single') return false;
907
+ return row.locator !== '';
908
+ }
909
+
910
+ /** Re-ordering is pure CSS inside one parent, so it works wherever an element is bound. */
911
+ function canReorderRow(row) {
912
+ return row.builtin !== true && row.locator !== '';
913
+ }
914
+
915
+ /** One step of the visual order, relative to the current value (absent means 0). */
916
+ function stepVisualOrder(settings, key, delta) {
917
+ const visual = isPlainObject(settings.visualOrder) ? settings.visualOrder : {};
918
+ const current = hasOwn(visual, key) ? visual[key] : 0;
919
+ const next = { ...visual };
920
+ const value = clamp(Math.round(current) + delta, -999, 999);
921
+ if (value === 0) delete next[key];
922
+ else next[key] = value;
923
+ return next;
924
+ }
925
+
926
+ /* ---------------------------------------------------------------- selectors */
927
+
928
+ function elementText(element) {
929
+ if (element === null || element === undefined) return '';
930
+ const text = typeof element.textContent === 'string' ? element.textContent : '';
931
+ return text.trim();
932
+ }
933
+
934
+ function isStableAttribute(name) {
935
+ if (typeof name !== 'string' || name.startsWith('data-uic') === true) return false;
936
+ return name.startsWith('data-') === true || name === 'role' || name === 'aria-label' || name === 'name' || name === 'id';
937
+ }
938
+
939
+ function attributeSelector(element) {
940
+ const attributes = element.attributes;
941
+ if (attributes === undefined || attributes === null) return '';
942
+ const names = typeof attributes.forEach === 'function' ? null : Object.keys(attributes);
943
+ const candidates = names === null ? [] : names;
944
+ if (names === null && typeof element.getAttributeNames === 'function') candidates.push(...element.getAttributeNames());
945
+ for (const name of candidates) {
946
+ if (isStableAttribute(name) === false) continue;
947
+ const value = typeof element.getAttribute === 'function' ? element.getAttribute(name) : attributes[name];
948
+ if (typeof value !== 'string' || value === '' || value.length > 60) continue;
949
+ return '[' + name + '="' + value.replace(/"/g, '\\"') + '"]';
950
+ }
951
+ return '';
952
+ }
953
+
954
+ function pathSelector(element, root) {
955
+ const parts = [];
956
+ let node = element;
957
+ let depth = 0;
958
+ while (node !== null && node !== undefined && node !== root && depth < 6) {
959
+ const tag = String(node.tagName ?? '').toLowerCase();
960
+ if (tag === '' || tag === 'html' || tag === 'body') break;
961
+ const parent = node.parentElement ?? null;
962
+ const siblings = parent === null ? [] : Array.from(parent.children ?? []).filter((child) => String(child.tagName ?? '').toLowerCase() === tag);
963
+ const index = siblings.indexOf(node);
964
+ parts.unshift(tag + (siblings.length > 1 && index >= 0 ? ':nth-of-type(' + (index + 1) + ')' : ''));
965
+ const own = attributeSelector(node);
966
+ if (own !== '') {
967
+ parts.unshift(own);
968
+ break;
969
+ }
970
+ node = parent;
971
+ depth += 1;
972
+ }
973
+ return parts.join(' > ');
974
+ }
975
+
976
+ function buildSelector(element, root) {
977
+ if (element === null || element === undefined) return '';
978
+ const direct = attributeSelector(element);
979
+ if (direct !== '' && documentMatches(direct, element)) return direct;
980
+ const path = pathSelector(element, root ?? null);
981
+ if (path === '' ) return '';
982
+ return documentMatches(path, element) ? path : '';
983
+ }
984
+
985
+ function documentMatches(selector, element) {
986
+ const doc = typeof document !== 'undefined' ? document : null;
987
+ if (doc === null || typeof doc.querySelectorAll !== 'function') return false;
988
+ try {
989
+ const found = doc.querySelectorAll(selector);
990
+ return Array.from(found).includes(element);
991
+ } catch {
992
+ return false;
993
+ }
994
+ }
995
+
996
+ /* ----------------------------------------------------------------- presets */
997
+
998
+ function capturePreset(settings) {
999
+ return {
1000
+ hidden: sanitizeHidden(settings.hidden),
1001
+ visualOrder: sanitizeVisualOrder(settings.visualOrder),
1002
+ };
1003
+ }
1004
+
1005
+ function savePreset(settings, name) {
1006
+ const cleanName = sanitizeName(name);
1007
+ if (cleanName === '') return { ok: false, reason: 'invalid' };
1008
+ const presets = { ...settings.presets, [cleanName]: capturePreset(settings) };
1009
+ return { ok: true, presets, activePreset: cleanName };
1010
+ }
1011
+
1012
+ function dropPreset(settings, name) {
1013
+ const cleanName = sanitizeName(name);
1014
+ if (hasOwn(settings.presets, cleanName) === false) return { ok: false, reason: 'missing' };
1015
+ const presets = { ...settings.presets };
1016
+ delete presets[cleanName];
1017
+ return { ok: true, presets, activePreset: settings.activePreset === cleanName ? null : settings.activePreset };
1018
+ }
1019
+
1020
+ function applyPreset(settings, name) {
1021
+ const cleanName = sanitizeName(name);
1022
+ if (hasOwn(settings.presets, cleanName) === false) return { ok: false, reason: 'missing' };
1023
+ const preset = settings.presets[cleanName];
1024
+ return {
1025
+ ok: true,
1026
+ hidden: sanitizeHidden(preset.hidden),
1027
+ visualOrder: sanitizeVisualOrder(preset.visualOrder),
1028
+ activePreset: cleanName,
1029
+ };
1030
+ }
1031
+
1032
+ /* --------------------------------------------------------------- the plugin */
1033
+
1034
+ const ZH = {
1035
+ 'settings.nav': '界面控制',
1036
+ 'settings.title': '界面控制 / UI controller',
1037
+ 'settings.lead': '这里列出宿主所有座位(slot)当前被谁占用。改动只影响显示,不卸载、不移动别人注册的 entry。',
1038
+ 'settings.summary': '共 {slots} 个座位,{occupied} 个有占用;{rows} 条 entry,其中 {builtin} 条来自内置 UI(不给控件,改了会顶掉官方那一块),{shippedSlot} 条在出厂包独占的槽里(分不清具体是哪一条,控件照给),{risky} 条坐在有风险的座位上,{hidden} 条已被隐藏,{located} 条已绑定 DOM。',
1039
+ 'settings.kinds': '座位类型:single {single} · list {list} · keyed {keyed} · chain {chain}',
1040
+ 'settings.emptyHint': '这些座位当前没有任何 entry。想「把某个入口挪到某处」时,先看这里哪里是空的。',
1041
+ 'settings.risk': '顶掉官方 UI 的风险',
1042
+ 'settings.shippedSlot': '出厂槽',
1043
+ 'settings.shippedSlotHint': '这个槽的注册方全是出厂包,但宿主不告诉我们具体哪一条是它注册的。',
1044
+ 'settings.unbind': '解绑',
1045
+ 'settings.unbindHint': '清除绑定,同时删掉这一条的视觉顺序。',
1046
+ 'settings.builtin': '内置 UI',
1047
+ 'settings.hide': '隐藏',
1048
+ 'settings.show': '恢复',
1049
+ 'settings.pick': '绑定元素',
1050
+ 'settings.picking': '点页面上要隐藏的那块…',
1051
+ 'settings.unbound': '无法定位:宿主不暴露 entry→DOM 映射',
1052
+ 'settings.hiddenTag': '已隐藏',
1053
+ 'settings.locatedTag': '已绑定',
1054
+ 'settings.presets': '预设',
1055
+ 'settings.presetName': '(预设名)',
1056
+ 'settings.savePreset': '保存当前',
1057
+ 'settings.applyPreset': '应用',
1058
+ 'settings.dropPreset': '删除',
1059
+ 'settings.reset': '全部恢复默认',
1060
+ 'settings.resetOnce': '再点一次确认',
1061
+ 'settings.noPresets': '还没有预设',
1062
+ 'settings.orderHint': '视觉顺序只改 CSS order,键盘 Tab 顺序不变。',
1063
+ 'settings.orderHint2': '别人插件的入口顺序由它自己注册时决定,宿主不提供运行时改写接口;这里只能改它们在同一父容器里的摆放次序。',
1064
+ 'settings.visualUp': '上移一位',
1065
+ 'settings.visualDown': '下移一位',
1066
+ 'settings.builtinOccupied': '内置 UI · 隐藏会顶掉官方那一块',
1067
+ 'settings.singleOccupied': '单占座位 · 不做操作(再注册会顶掉现有占用)',
1068
+ 'settings.catalogRuntime': '目录来自运行时:{count} 个座位。',
1069
+ 'settings.catalogStatic': '运行时目录不可用,回落到内置静态表:{count} 个座位。',
1070
+ 'settings.col.registrant': '注册方(静态推断)',
1071
+ 'settings.groupEntries': '{count} 条 entry',
1072
+ 'settings.zone.risky': '危险区',
1073
+ 'settings.zone.riskyHint': '顶掉这些槽位就等于官方那块 UI 没了',
1074
+ 'settings.zone.safe': '安全区',
1075
+ 'settings.zone.safeHint': '顶掉不伤官方 UI',
1076
+ 'settings.zone.empty': '空座位',
1077
+ 'settings.zoneMeta': '{slots} 槽 · {entries} entry',
1078
+ 'settings.search': '搜键名 / 说明 / 占用者',
1079
+ 'settings.filter.all': '全部',
1080
+ 'settings.filter.risky': '只看危险',
1081
+ 'settings.filter.safe': '只看安全',
1082
+ 'settings.filter.bound': '已绑定',
1083
+ 'settings.filter.unbound': '未绑定',
1084
+ 'settings.filterCount': '{slots} 槽 · {entries} entry',
1085
+ 'settings.noMatch': '没有匹配的座位。',
1086
+ 'settings.nav.title': '设置页左栏',
1087
+ 'settings.nav.hint': '只改设置页左侧分类栏的宽度:展开、56px 图标栏,或收起。键盘顺序与 DOM 顺序都不变。',
1088
+ 'settings.nav.follow': '跟随宿主侧栏',
1089
+ 'settings.nav.followOn': '跟随宿主侧栏时这三档不生效,先关掉跟随。',
1090
+ 'settings.nav.state.expanded': '展开',
1091
+ 'settings.nav.state.rail': '图标栏',
1092
+ 'settings.nav.state.hidden': '收起',
1093
+ 'settings.nav.now': '当前选择:{width}px。',
1094
+ };
1095
+
1096
+ const EN = {
1097
+ 'settings.nav': 'UI controller',
1098
+ 'settings.title': 'UI controller',
1099
+ 'settings.lead': 'Every host slot and who currently occupies it. Changes affect display only — nothing is unmounted and no entry is moved.',
1100
+ 'settings.summary': '{rows} entries across {slots} slots ({occupied} occupied). {builtin} come from the built-in UI (no controls: changing them removes shipped chrome), {shippedSlot} sit in a slot only shipped packages register into (the slot cannot say which row, so the controls stay), {risky} sit in a risky slot. {hidden} hidden, {located} bound to the DOM.',
1101
+ 'settings.kinds': 'Kinds: single {single} · list {list} · keyed {keyed} · chain {chain}',
1102
+ 'settings.emptyHint': 'Nothing occupies these right now. If you want to put something somewhere, this is where there is room.',
1103
+ 'settings.risk': 'shadows shipped UI',
1104
+ 'settings.shippedSlot': 'shipped slot',
1105
+ 'settings.shippedSlotHint': 'Every registrar of this slot is a shipped package, but the host does not say which row came from where.',
1106
+ 'settings.unbind': 'Unbind',
1107
+ 'settings.unbindHint': 'Clears the binding and the visual order stored for it.',
1108
+ 'settings.builtin': 'built-in UI',
1109
+ 'settings.hide': 'Hide',
1110
+ 'settings.show': 'Restore',
1111
+ 'settings.pick': 'Bind element',
1112
+ 'settings.picking': 'Click the block you want to hide…',
1113
+ 'settings.unbound': 'Cannot locate: the host exposes no entry→DOM mapping',
1114
+ 'settings.hiddenTag': 'hidden',
1115
+ 'settings.locatedTag': 'bound',
1116
+ 'settings.presets': 'Presets',
1117
+ 'settings.presetName': 'preset name',
1118
+ 'settings.savePreset': 'Save current',
1119
+ 'settings.applyPreset': 'Apply',
1120
+ 'settings.dropPreset': 'Delete',
1121
+ 'settings.reset': 'Restore defaults',
1122
+ 'settings.resetOnce': 'Click again to confirm',
1123
+ 'settings.noPresets': 'No presets yet',
1124
+ 'settings.orderHint': 'Visual order only changes CSS order; the keyboard Tab order stays exactly as it is.',
1125
+ 'settings.orderHint2': 'Another plugin decides where its own entry sits when it registers — the host offers no runtime hook for that. All we can change is paint order inside the same parent.',
1126
+ 'settings.visualUp': 'Move up one',
1127
+ 'settings.visualDown': 'Move down one',
1128
+ 'settings.builtinOccupied': 'Built-in UI \u00b7 hiding it removes shipped chrome',
1129
+ 'settings.singleOccupied': 'Single seat \u00b7 not offered (re-registering replaces the occupant)',
1130
+ 'settings.catalogRuntime': 'Directory from the live registry: {count} slots.',
1131
+ 'settings.catalogStatic': 'Live directory unavailable; using the bundled static table: {count} slots.',
1132
+ 'settings.col.registrant': 'Registrant (static)',
1133
+ 'settings.groupEntries': 'entries ({count})',
1134
+ 'settings.zone.risky': 'Risky',
1135
+ 'settings.zone.riskyHint': 'replacing these removes shipped UI',
1136
+ 'settings.zone.safe': 'Safe',
1137
+ 'settings.zone.safeHint': 'replacing these costs no shipped UI',
1138
+ 'settings.zone.empty': 'Empty seats',
1139
+ 'settings.zoneMeta': '{slots} slots · {entries} entries',
1140
+ 'settings.search': 'Search key, purpose or occupant',
1141
+ 'settings.filter.all': 'All',
1142
+ 'settings.filter.risky': 'Risky only',
1143
+ 'settings.filter.safe': 'Safe only',
1144
+ 'settings.filter.bound': 'Bound',
1145
+ 'settings.filter.unbound': 'Unbound',
1146
+ 'settings.filterCount': '{slots} slots · {entries} entries',
1147
+ 'settings.noMatch': 'No slot matches.',
1148
+ 'settings.nav.title': 'Settings rail',
1149
+ 'settings.nav.hint': 'Only the width of the settings rail changes: full, a 56px icon rail, or collapsed. Keyboard and DOM order never change.',
1150
+ 'settings.nav.follow': 'Follow the host sidebar',
1151
+ 'settings.nav.followOn': 'While following, these three do not apply — turn following off first.',
1152
+ 'settings.nav.state.expanded': 'Full',
1153
+ 'settings.nav.state.rail': 'Icon rail',
1154
+ 'settings.nav.state.hidden': 'Collapsed',
1155
+ 'settings.nav.now': 'Selected: {width}px.',
1156
+ };
1157
+
1158
+ const DICTS = { zh: ZH, en: EN };
1159
+
1160
+ function localeScope() {
1161
+ const doc = typeof document === 'undefined' ? null : document;
1162
+ const lang = String(doc?.documentElement?.getAttribute?.('lang') ?? '');
1163
+ return lang.toLowerCase().startsWith('zh') || lang === '' ? 'zh' : 'en';
1164
+ }
1165
+
1166
+ function translator(scope) {
1167
+ return (key, params) => {
1168
+ const dict = DICTS[scope] ?? EN;
1169
+ let text = hasOwn(dict, key) ? dict[key] : key;
1170
+ if (isPlainObject(params)) {
1171
+ for (const [name, value] of Object.entries(params)) text = text.split('{' + name + '}').join(String(value));
1172
+ }
1173
+ return text;
1174
+ };
1175
+ }
1176
+
1177
+ function h(type, props, children) {
1178
+ const rest = Array.prototype.slice.call(arguments, 3);
1179
+ const merged = children === undefined ? [] : Array.isArray(children) ? children : [children];
1180
+ return React.createElement(type, props, ...merged, ...rest);
1181
+ }
1182
+
1183
+ function node(tagName, props, children) {
1184
+ return h(tagName, props, children === undefined ? [] : children);
1185
+ }
1186
+
1187
+ function injectStyle(doc) {
1188
+ if (doc === null || doc === undefined) return;
1189
+ const css = HIDE_CSS + '\n' + PAGE_CSS + '\n' + NAV_CSS;
1190
+ const existing = typeof doc.getElementById === 'function' ? doc.getElementById(STYLE_ID) : null;
1191
+ /* A reloaded plugin can find the stylesheet its previous instance left behind.
1192
+ Rewriting it keeps the three rule groups from drifting apart. */
1193
+ if (existing !== null && existing !== undefined) {
1194
+ if (existing.textContent !== css) existing.textContent = css;
1195
+ return;
1196
+ }
1197
+ const style = doc.createElement('style');
1198
+ style.id = STYLE_ID;
1199
+ style.setAttribute('data-uic', 'style');
1200
+ style.textContent = css;
1201
+ const head = doc.head ?? doc.documentElement;
1202
+ if (head !== null && head !== undefined) head.appendChild(style);
1203
+ }
1204
+
1205
+ function removeStyle(doc) {
1206
+ if (doc === null || doc === undefined) return;
1207
+ const existing = typeof doc.getElementById === 'function' ? doc.getElementById(STYLE_ID) : null;
1208
+ if (existing !== null && existing !== undefined && typeof existing.remove === 'function') existing.remove();
1209
+ }
1210
+
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
+ /* ---------------------------------------------------------------- grouping */
1281
+
1282
+ const RISK_RISKY = 'shadows-shipped-ui';
1283
+
1284
+ /**
1285
+ * Slot rows -> two risk zones plus the empty slots.
1286
+ *
1287
+ * Pure: it only reads what `slotRows` already produced. Entries keep the order
1288
+ * `slotRows` sorted them into (priority, then id), so a re-render never
1289
+ * reshuffles a slot under the pointer.
1290
+ */
1291
+ function slotGroups(rows, empty) {
1292
+ const bySlot = new Map();
1293
+ for (const row of Array.isArray(rows) ? rows : []) {
1294
+ const existing = bySlot.get(row.slotKey);
1295
+ if (existing === undefined) {
1296
+ bySlot.set(row.slotKey, {
1297
+ slotKey: row.slotKey,
1298
+ kind: row.kind,
1299
+ scope: row.scope,
1300
+ risk: row.risk,
1301
+ purpose: row.purpose,
1302
+ entries: [row],
1303
+ });
1304
+ } else {
1305
+ existing.entries.push(row);
1306
+ }
1307
+ }
1308
+ const groups = [...bySlot.values()].sort((a, b) => a.slotKey.localeCompare(b.slotKey));
1309
+ const zones = { risky: [], safe: [], empty: [] };
1310
+ for (const group of groups) {
1311
+ if (group.risk === RISK_RISKY) zones.risky.push(group);
1312
+ else zones.safe.push(group);
1313
+ }
1314
+ const blanks = (Array.isArray(empty) ? [...empty] : []).sort((a, b) => a.key.localeCompare(b.key));
1315
+ for (const slot of blanks) {
1316
+ zones.empty.push({
1317
+ slotKey: slot.key,
1318
+ kind: slot.kind,
1319
+ scope: slot.scope,
1320
+ risk: slot.risk,
1321
+ purpose: slot.purpose,
1322
+ entries: [],
1323
+ });
1324
+ }
1325
+ return zones;
1326
+ }
1327
+
1328
+ /**
1329
+ * Apply the three filters and count what survived.
1330
+ *
1331
+ * A slot survives when its own key or purpose matches, or when any of its
1332
+ * entries does — the user searches for "the thing I can see", which may be a
1333
+ * slot name or an entry id. Counts are entry counts, because that is what the
1334
+ * user is hunting for; `slots` counts the slot rows that still have a hit.
1335
+ */
1336
+ function filterGroups(zones, filters) {
1337
+ const query = typeof filters?.query === 'string' ? filters.query.trim().toLowerCase() : '';
1338
+ const risk = filters?.risk ?? 'all';
1339
+ const bound = filters?.bound ?? 'all';
1340
+ const has = (text) => query === '' || String(text ?? '').toLowerCase().includes(query);
1341
+ const riskOk = (slot) => risk === 'all' || (risk === 'risky' ? slot.risk === RISK_RISKY : slot.risk !== RISK_RISKY);
1342
+ const boundOk = (row) => bound === 'all' || (bound === 'bound' ? row.locator !== '' : row.locator === '');
1343
+ const out = { risky: [], safe: [], empty: [] };
1344
+ for (const zone of ['risky', 'safe']) {
1345
+ for (const slot of zones?.[zone] ?? []) {
1346
+ if (riskOk(slot) === false) continue;
1347
+ const slotHit = has(slot.slotKey) || has(slot.purpose);
1348
+ const entries = slot.entries.filter(
1349
+ (row) => boundOk(row) && (slotHit || has(row.entryId) || has(row.registrant) || has(row.registrantLive)),
1350
+ );
1351
+ if (entries.length === 0) continue;
1352
+ out[zone].push({ ...slot, entries });
1353
+ }
1354
+ }
1355
+ for (const slot of zones?.empty ?? []) {
1356
+ if (riskOk(slot) === false) continue;
1357
+ if (bound === 'bound') continue;
1358
+ if (has(slot.slotKey) === false && has(slot.purpose) === false) continue;
1359
+ out.empty.push(slot);
1360
+ }
1361
+ const counts = { entries: 0, slots: 0, empty: out.empty.length };
1362
+ for (const zone of ['risky', 'safe']) {
1363
+ for (const slot of out[zone]) {
1364
+ counts.slots += 1;
1365
+ counts.entries += slot.entries.length;
1366
+ }
1367
+ }
1368
+ return { zones: out, counts };
1369
+ }
1370
+
1371
+ /**
1372
+ * Which zones and slots are unfolded.
1373
+ *
1374
+ * Deliberately module-level rather than component state: the host re-renders
1375
+ * this panel when the registry ticks, and the two-second inventory timer
1376
+ * re-renders it on its own. Collapse state kept in React state survives a
1377
+ * re-render but not a remount; keeping it here survives both, which is what
1378
+ * "it must not spring open again" actually requires.
1379
+ */
1380
+ const openNodes = new Set();
1381
+
1382
+ function isOpen(id) {
1383
+ return openNodes.has(id);
1384
+ }
1385
+
1386
+ function toggleOpen(id) {
1387
+ if (openNodes.has(id)) openNodes.delete(id);
1388
+ else openNodes.add(id);
1389
+ return openNodes.has(id);
1390
+ }
1391
+
1392
+ function resetOpen() {
1393
+ openNodes.clear();
1394
+ }
1395
+
1396
+ /* ------------------------------------------------------------- the page UI */
1397
+
1398
+ function settingsPage(props) {
1399
+ const t = props.t;
1400
+ const [snapshot, setSnapshot] = React.useState(null);
1401
+ const [state, setState] = React.useState(() => readSettings());
1402
+ const [armed, setArmed] = React.useState(false);
1403
+ const [pickKey, setPickKey] = React.useState(null);
1404
+ const [presetName, setPresetName] = React.useState('');
1405
+ const [query, setQuery] = React.useState('');
1406
+ const [riskFilter, setRiskFilter] = React.useState('all');
1407
+ const [boundFilter, setBoundFilter] = React.useState('all');
1408
+ const [, bump] = React.useState(0);
1409
+
1410
+ React.useEffect(() => {
1411
+ const refresh = () => setState(readSettings());
1412
+ const stop = typeof props.subscribe === 'function' ? props.subscribe(refresh) : () => {};
1413
+ refresh();
1414
+ return stop;
1415
+ }, []);
1416
+
1417
+ React.useEffect(() => {
1418
+ let cancelled = false;
1419
+ const read = typeof props.inventory === 'function' ? props.inventory : () => null;
1420
+ const update = () => {
1421
+ if (cancelled) return;
1422
+ try {
1423
+ setSnapshot(read());
1424
+ } catch {
1425
+ setSnapshot(null);
1426
+ }
1427
+ };
1428
+ update();
1429
+ const timer = setInterval(update, 2000);
1430
+ return () => {
1431
+ cancelled = true;
1432
+ clearInterval(timer);
1433
+ };
1434
+ }, []);
1435
+
1436
+ const fallbackInventory = {
1437
+ rows: [],
1438
+ empty: [],
1439
+ totalSlots: SLOT_CATALOG.length,
1440
+ occupiedSlots: 0,
1441
+ hiddenCount: 0,
1442
+ riskyCount: 0,
1443
+ builtinCount: 0,
1444
+ shippedSlotCount: 0,
1445
+ locatorCount: 0,
1446
+ orderedCount: 0,
1447
+ catalogSource: 'static',
1448
+ };
1449
+ const readInventory = () => {
1450
+ if (typeof props.inventory !== 'function') return fallbackInventory;
1451
+ try {
1452
+ return props.inventory() ?? fallbackInventory;
1453
+ } catch {
1454
+ return fallbackInventory;
1455
+ }
1456
+ };
1457
+ const inventory = snapshot ?? readInventory();
1458
+ const counts = kindCounts();
1459
+
1460
+ const commit = (next) => {
1461
+ writeSettings(next);
1462
+ setState(readSettings());
1463
+ if (typeof props.apply === 'function') props.apply();
1464
+ };
1465
+
1466
+ const onToggle = (row) => {
1467
+ commit({ ...state, hidden: toggleHidden(state, row.slotKey, row.entryId) });
1468
+ };
1469
+
1470
+ const onStepOrder = (row, delta) => {
1471
+ commit({ ...state, visualOrder: stepVisualOrder(state, row.key, delta) });
1472
+ };
1473
+
1474
+ const onUnbind = (row) => {
1475
+ commit({ ...state, locators: setLocator(state, row.key, ''), visualOrder: dropKey(state.visualOrder, row.key) });
1476
+ };
1477
+
1478
+ const onPick = (row) => {
1479
+ const next = pickKey === row.key ? null : row.key;
1480
+ setPickKey(next);
1481
+ if (next !== null && typeof props.pick === 'function') props.pick(next);
1482
+ };
1483
+
1484
+ const onSavePreset = () => {
1485
+ const result = savePreset(state, presetName);
1486
+ if (result.ok !== true) return;
1487
+ setPresetName('');
1488
+ commit({ ...state, presets: result.presets, activePreset: result.activePreset });
1489
+ };
1490
+
1491
+ const onApplyPreset = (name) => {
1492
+ const result = applyPreset(state, name);
1493
+ if (result.ok !== true) return;
1494
+ commit({ ...state, hidden: result.hidden, visualOrder: result.visualOrder, activePreset: result.activePreset });
1495
+ };
1496
+
1497
+ const onDropPreset = (name) => {
1498
+ const result = dropPreset(state, name);
1499
+ if (result.ok !== true) return;
1500
+ commit({ ...state, presets: result.presets, activePreset: result.activePreset });
1501
+ };
1502
+
1503
+ const onReset = () => {
1504
+ if (armed !== true) {
1505
+ setArmed(true);
1506
+ return;
1507
+ }
1508
+ setArmed(false);
1509
+ settingsCache = null;
1510
+ writeSettings(defaultSettings());
1511
+ setState(readSettings());
1512
+ if (typeof props.apply === 'function') props.apply();
1513
+ };
1514
+
1515
+ /* Collapse toggles: flip the module-level set and force one render. */
1516
+ const flipZone = (zone) => {
1517
+ toggleOpen('zone:' + zone);
1518
+ bump((value) => value + 1);
1519
+ };
1520
+ const flipSlot = (slotKey) => {
1521
+ toggleOpen('slot:' + slotKey);
1522
+ bump((value) => value + 1);
1523
+ };
1524
+
1525
+ const view = filterGroups(slotGroups(inventory.rows, inventory.empty), {
1526
+ query,
1527
+ risk: riskFilter,
1528
+ bound: boundFilter,
1529
+ });
1530
+
1531
+ const tag = (id, text, className, title) => node('span', { key: id, className: className ?? 'uic-tag', title: title ?? text }, text);
1532
+
1533
+ const entryRow = (row) => {
1534
+ const builtin = row.builtin === true;
1535
+ const bound = row.locator !== '';
1536
+ const toggleable = canHide(row);
1537
+ const reorderable = canReorderRow(row);
1538
+ const stateTags = [];
1539
+ if (row.hidden) stateTags.push(tag('hidden', t('settings.hiddenTag'), 'uic-tag uic-tag-on'));
1540
+ if (bound) stateTags.push(tag('bound', t('settings.locatedTag')));
1541
+ if (builtin) stateTags.push(tag('builtin', t('settings.builtin'), 'uic-tag uic-tag-risk'));
1542
+ else if (row.shippedSlot === true) stateTags.push(tag('shipped-slot', t('settings.shippedSlot'), 'uic-tag', t('settings.shippedSlotHint')));
1543
+ else if (row.risky === true) stateTags.push(tag('risky', t('settings.risk'), 'uic-tag uic-tag-risk'));
1544
+
1545
+ const stepper = reorderable
1546
+ ? node('span', { key: 'order-ctl', className: 'uic-ctl' }, [
1547
+ node(
1548
+ 'button',
1549
+ {
1550
+ key: 'up',
1551
+ className: 'uic-btn uic-btn-quiet',
1552
+ type: 'button',
1553
+ 'data-uic-order-up': row.key,
1554
+ 'aria-label': t('settings.visualUp'),
1555
+ title: t('settings.visualUp'),
1556
+ onClick: () => onStepOrder(row, 1),
1557
+ },
1558
+ '\u2191',
1559
+ ),
1560
+ node(
1561
+ 'button',
1562
+ {
1563
+ key: 'down',
1564
+ className: 'uic-btn uic-btn-quiet',
1565
+ type: 'button',
1566
+ 'data-uic-order-down': row.key,
1567
+ 'aria-label': t('settings.visualDown'),
1568
+ title: t('settings.visualDown'),
1569
+ onClick: () => onStepOrder(row, -1),
1570
+ },
1571
+ '\u2193',
1572
+ ),
1573
+ ])
1574
+ : null;
1575
+ const hideButton = toggleable
1576
+ ? node(
1577
+ 'button',
1578
+ {
1579
+ className: 'uic-btn',
1580
+ type: 'button',
1581
+ 'data-uic-toggle': row.key,
1582
+ onClick: () => onToggle(row),
1583
+ },
1584
+ row.hidden ? t('settings.show') : t('settings.hide'),
1585
+ )
1586
+ : null;
1587
+ const unbindButton = bound
1588
+ ? node(
1589
+ 'button',
1590
+ {
1591
+ key: 'unbind',
1592
+ className: 'uic-btn uic-btn-quiet',
1593
+ type: 'button',
1594
+ 'data-uic-unbind': row.key,
1595
+ title: t('settings.unbindHint'),
1596
+ onClick: () => onUnbind(row),
1597
+ },
1598
+ t('settings.unbind'),
1599
+ )
1600
+ : null;
1601
+ const why = builtin
1602
+ ? t('settings.builtinOccupied')
1603
+ : row.kind === 'single'
1604
+ ? t('settings.singleOccupied')
1605
+ : t('settings.unbound');
1606
+
1607
+ const controls =
1608
+ hideButton !== null || stepper !== null || unbindButton !== null
1609
+ ? node('span', { key: 'action', className: 'uic-entryActions' }, [hideButton, stepper, unbindButton])
1610
+ : node('span', { key: 'action', className: 'uic-entryActions' }, [
1611
+ node('span', { className: 'uic-why', title: locatorReason(state, row) }, [
1612
+ why,
1613
+ builtin || row.kind === 'single'
1614
+ ? null
1615
+ : node(
1616
+ 'button',
1617
+ {
1618
+ key: 'pick',
1619
+ className: 'uic-btn uic-btn-quiet',
1620
+ type: 'button',
1621
+ 'data-uic-pick': row.key,
1622
+ onClick: () => onPick(row),
1623
+ },
1624
+ pickKey === row.key ? t('settings.picking') : t('settings.pick'),
1625
+ ),
1626
+ ]),
1627
+ ]);
1628
+
1629
+ return node('div', { key: row.key, className: 'uic-entry', [ROW_ATTR]: row.key, 'data-uic-slot': row.slotKey }, [
1630
+ node('span', { key: 'entry', className: 'uic-entryId uic-mono', title: row.entryId }, row.entryId),
1631
+ node('span', { key: 'live', className: 'uic-entryLive', title: t('settings.col.registrant') }, [
1632
+ node('span', { key: 'name' }, row.registrantLive === '' ? '\u2014' : row.registrantLive),
1633
+ row.registrant === '' ? null : node('span', { key: 'static', className: 'uic-dim' }, ' \u00b7 ' + row.registrant),
1634
+ ]),
1635
+ node('span', { key: 'priority', className: 'uic-num' }, String(row.priority)),
1636
+ node('span', { key: 'order', className: 'uic-num' }, String(row.order)),
1637
+ node('span', { key: 'visual', className: 'uic-num' }, row.visualOrder === null ? '\u2014' : String(row.visualOrder)),
1638
+ node('span', { key: 'state', className: 'uic-entryState' }, stateTags.length === 0 ? node('span', { className: 'uic-dim' }, '\u2014') : stateTags),
1639
+ controls,
1640
+ ]);
1641
+ };
1642
+
1643
+ const slotRow = (slot) => {
1644
+ const open = isOpen('slot:' + slot.slotKey);
1645
+ const risky = slot.risk === RISK_RISKY;
1646
+ const hasEntries = slot.entries.length > 0;
1647
+ const head = node(
1648
+ hasEntries ? 'button' : 'div',
1649
+ {
1650
+ key: 'head',
1651
+ className: 'uic-slotHead' + (risky ? ' uic-slotRisk' : ''),
1652
+ type: hasEntries ? 'button' : undefined,
1653
+ 'data-uic-group': slot.slotKey,
1654
+ 'data-uic-group-open': open ? 'true' : 'false',
1655
+ 'data-uic-group-toggle': hasEntries ? slot.slotKey : undefined,
1656
+ 'data-uic-group-risk': risky ? 'risky' : 'safe',
1657
+ 'aria-expanded': hasEntries ? (open ? 'true' : 'false') : undefined,
1658
+ onClick: hasEntries ? () => flipSlot(slot.slotKey) : undefined,
1659
+ title: slot.purpose,
1660
+ },
1661
+ [
1662
+ node('span', { key: 'mark', className: 'uic-mark', 'aria-hidden': 'true' }, risky ? '\u26a0' : '\u00b7'),
1663
+ node('span', { key: 'arrow', className: 'uic-arrow' }, hasEntries ? (open ? '\u25be' : '\u25b8') : ''),
1664
+ node('span', { key: 'key', className: 'uic-slotKey uic-mono' }, slot.slotKey),
1665
+ node('span', { key: 'kind', className: 'uic-kind' }, slot.kind),
1666
+ node('span', { key: 'scope', className: 'uic-dim' }, slot.scope),
1667
+ node('span', { key: 'count', className: 'uic-count', 'data-uic-group-count': String(slot.entries.length) }, t('settings.groupEntries', { count: slot.entries.length })),
1668
+ ],
1669
+ );
1670
+ if (hasEntries === false) return node('div', { key: slot.slotKey, className: 'uic-slot', 'data-uic-empty-slot': slot.slotKey }, head);
1671
+ return node('div', { key: slot.slotKey, className: 'uic-slot' + (open ? ' uic-slotOpen' : ''), 'data-uic-slot-open': open ? 'true' : 'false' }, [
1672
+ head,
1673
+ open ? node('div', { key: 'entries', className: 'uic-entries' }, slot.entries.map(entryRow)) : null,
1674
+ ]);
1675
+ };
1676
+
1677
+ const zoneNames = { risky: t('settings.zone.risky'), safe: t('settings.zone.safe'), empty: t('settings.zone.empty') };
1678
+ const zoneHints = { risky: t('settings.zone.riskyHint'), safe: t('settings.zone.safeHint'), empty: t('settings.emptyHint') };
1679
+
1680
+ const zoneBlock = (zone) => {
1681
+ const groups = view.zones[zone];
1682
+ if (groups.length === 0) return null;
1683
+ const open = isOpen('zone:' + zone);
1684
+ const entries = groups.reduce((sum, slot) => sum + slot.entries.length, 0);
1685
+ return node('section', { key: zone, className: 'uic-zone uic-zone-' + zone, 'data-uic-zone': zone, 'data-uic-zone-open': open ? 'true' : 'false' }, [
1686
+ node(
1687
+ 'button',
1688
+ {
1689
+ key: 'head',
1690
+ className: 'uic-zoneHead',
1691
+ type: 'button',
1692
+ 'data-uic-zone-toggle': zone,
1693
+ 'aria-expanded': open ? 'true' : 'false',
1694
+ onClick: () => flipZone(zone),
1695
+ },
1696
+ [
1697
+ node('span', { key: 'mark', className: 'uic-mark', 'aria-hidden': 'true' }, zone === 'empty' ? '\u00b7' : '\u26a0'),
1698
+ node('span', { key: 'arrow', className: 'uic-arrow' }, open ? '\u25be' : '\u25b8'),
1699
+ node('span', { key: 'name', className: 'uic-zoneName' }, zoneNames[zone]),
1700
+ node('span', { key: 'hint', className: 'uic-zoneHint' }, zoneHints[zone]),
1701
+ node('span', { key: 'meta', className: 'uic-zoneMeta', 'data-uic-zone-count': String(groups.length) }, t('settings.zoneMeta', { slots: groups.length, entries })),
1702
+ ],
1703
+ ),
1704
+ open ? node('div', { key: 'body', className: 'uic-zoneBody' }, groups.map(slotRow)) : null,
1705
+ ]);
1706
+ };
1707
+
1708
+ const filterButton = (kind, value, label) => {
1709
+ const chosen = (kind === 'risk' ? riskFilter : boundFilter) === value;
1710
+ return node(
1711
+ 'button',
1712
+ {
1713
+ key: kind + ':' + value,
1714
+ className: 'uic-filter' + (chosen ? ' uic-filter-on' : ''),
1715
+ type: 'button',
1716
+ 'data-uic-filter': kind + ':' + value,
1717
+ 'data-on': chosen ? 'true' : 'false',
1718
+ onClick: () => {
1719
+ if (kind === 'risk') setRiskFilter(value);
1720
+ else setBoundFilter(value);
1721
+ bump((count) => count + 1);
1722
+ },
1723
+ },
1724
+ label,
1725
+ );
1726
+ };
1727
+
1728
+ const presetNames = Object.keys(state.presets).sort();
1729
+
1730
+ const navStored = isPlainObject(state.nav) ? state.nav : {};
1731
+ const followOn = navStored.follow !== false;
1732
+ const navChoice = PANEL_NAV_STATES.includes(navStored.state) ? navStored.state : 'expanded';
1733
+ /* While following, the three buttons are inert, so the selected mark and the
1734
+ width line show what the rail is actually doing right now. */
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' }, [
1742
+ node('input', {
1743
+ key: 'box',
1744
+ type: 'checkbox',
1745
+ 'data-uic-nav-follow': followOn ? 'true' : 'false',
1746
+ checked: followOn,
1747
+ onChange: (event) => navEdit({ follow: event.target.checked === true }),
1748
+ }),
1749
+ node('span', { key: 'text' }, t('settings.nav.follow')),
1750
+ ]),
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
+ ]);
1777
+
1778
+ return node('div', { className: 'uic-page', 'data-uic-page': '1' }, [
1779
+ node('h2', { key: 'title', className: 'uic-title' }, t('settings.title')),
1780
+ node('p', { key: 'lead', className: 'uic-lead' }, t('settings.lead')),
1781
+ node(
1782
+ 'p',
1783
+ { key: 'summary', className: 'uic-summary', 'data-uic-summary': '1' },
1784
+ t('settings.summary', {
1785
+ slots: inventory.totalSlots,
1786
+ occupied: inventory.occupiedSlots,
1787
+ rows: inventory.rows.length,
1788
+ builtin: inventory.builtinCount,
1789
+ shippedSlot: inventory.shippedSlotCount,
1790
+ risky: inventory.riskyCount,
1791
+ hidden: inventory.hiddenCount,
1792
+ located: inventory.locatorCount,
1793
+ }),
1794
+ ),
1795
+ node(
1796
+ 'p',
1797
+ { key: 'kinds', className: 'uic-dim' },
1798
+ t('settings.kinds', { single: counts.single ?? 0, list: counts.list ?? 0, keyed: counts.keyed ?? 0, chain: counts.chain ?? 0 }),
1799
+ ),
1800
+ node('div', { key: 'filters', className: 'uic-filters', 'data-uic-filters': '1' }, [
1801
+ node('input', {
1802
+ key: 'query',
1803
+ className: 'uic-input uic-search',
1804
+ type: 'search',
1805
+ 'data-uic-query': '1',
1806
+ placeholder: t('settings.search'),
1807
+ value: query,
1808
+ onChange: (event) => {
1809
+ setQuery(event.target.value);
1810
+ bump((count) => count + 1);
1811
+ },
1812
+ }),
1813
+ node('div', { key: 'risk', className: 'uic-filterGroup', 'data-uic-filter-group': 'risk' }, [
1814
+ filterButton('risk', 'all', t('settings.filter.all')),
1815
+ filterButton('risk', 'risky', t('settings.filter.risky')),
1816
+ filterButton('risk', 'safe', t('settings.filter.safe')),
1817
+ ]),
1818
+ node('div', { key: 'bound', className: 'uic-filterGroup', 'data-uic-filter-group': 'bound' }, [
1819
+ filterButton('bound', 'all', t('settings.filter.all')),
1820
+ filterButton('bound', 'bound', t('settings.filter.bound')),
1821
+ filterButton('bound', 'unbound', t('settings.filter.unbound')),
1822
+ ]),
1823
+ node(
1824
+ 'span',
1825
+ { key: 'count', className: 'uic-dim', 'data-uic-count': String(view.counts.entries) },
1826
+ t('settings.filterCount', { slots: view.counts.slots, entries: view.counts.entries }),
1827
+ ),
1828
+ ]),
1829
+ zoneBlock('risky'),
1830
+ zoneBlock('safe'),
1831
+ zoneBlock('empty'),
1832
+ view.counts.entries === 0 && view.counts.empty === 0
1833
+ ? node('p', { key: 'no-hit', className: 'uic-dim', 'data-uic-no-hit': '1' }, t('settings.noMatch'))
1834
+ : null,
1835
+ node('h3', { key: 'presets-h', className: 'uic-h3' }, t('settings.presets')),
1836
+ node('div', { key: 'presets', className: 'uic-presets', 'data-uic-presets': '1' }, [
1837
+ node('input', {
1838
+ key: 'name',
1839
+ className: 'uic-input',
1840
+ placeholder: t('settings.presetName'),
1841
+ value: presetName,
1842
+ onChange: (event) => setPresetName(event.target.value),
1843
+ }),
1844
+ node('button', { key: 'save', className: 'uic-btn', type: 'button', 'data-uic-preset-save': '1', onClick: onSavePreset }, t('settings.savePreset')),
1845
+ presetNames.length === 0
1846
+ ? node('span', { key: 'none', className: 'uic-dim' }, t('settings.noPresets'))
1847
+ : presetNames.map((name) =>
1848
+ node('span', { key: name, className: 'uic-preset' }, [
1849
+ node('span', { key: 'name', className: 'uic-preset-name' }, name),
1850
+ node('button', { key: 'apply', className: 'uic-btn uic-btn-quiet', type: 'button', 'data-uic-preset-apply': name, onClick: () => onApplyPreset(name) }, t('settings.applyPreset')),
1851
+ node('button', { key: 'drop', className: 'uic-btn uic-btn-quiet', type: 'button', 'data-uic-preset-drop': name, onClick: () => onDropPreset(name) }, t('settings.dropPreset')),
1852
+ ]),
1853
+ ),
1854
+ ]),
1855
+ node('p', { key: 'catalog', className: 'uic-dim', 'data-uic-catalog': inventory.catalogSource }, t(
1856
+ inventory.catalogSource === 'runtime' ? 'settings.catalogRuntime' : 'settings.catalogStatic',
1857
+ { count: inventory.totalSlots },
1858
+ )),
1859
+ node('p', { key: 'order-hint', className: 'uic-dim' }, t('settings.orderHint')),
1860
+ node('p', { key: 'order-hint-2', className: 'uic-dim' }, t('settings.orderHint2')),
1861
+ navBlock,
1862
+ 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
+ ]);
1864
+ }
1865
+
1866
+ function apply(ctx) {
1867
+ const doc = typeof document === 'undefined' ? null : document;
1868
+ const slots = ctx.get('slots');
1869
+ const t = translator(localeScope());
1870
+
1871
+ ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'ui-controller: dictionaries');
1872
+
1873
+ const entriesOf = (key) => (slots === undefined ? [] : slots.entriesOfSlot(key));
1874
+
1875
+ const inventory = () => slotRows(entriesOf, readSettings(), runtimeCatalog(slots));
1876
+
1877
+ let pickHandler = null;
1878
+
1879
+ const applyHidden = () => {
1880
+ if (doc === null) return;
1881
+ const current = readSettings();
1882
+ for (const element of Array.from(doc.querySelectorAll('[' + HIDDEN_ATTR + ']'))) element.removeAttribute(HIDDEN_ATTR);
1883
+ for (const item of hiddenSelectors(current)) {
1884
+ let found = [];
1885
+ try {
1886
+ found = Array.from(doc.querySelectorAll(item.selector));
1887
+ } catch {
1888
+ found = [];
1889
+ }
1890
+ for (const element of found) element.setAttribute(HIDDEN_ATTR, '1');
1891
+ }
1892
+ };
1893
+
1894
+ const pickElement = (key) => {
1895
+ if (doc === null) return;
1896
+ if (pickHandler !== null) {
1897
+ doc.removeEventListener('click', pickHandler, true);
1898
+ pickHandler = null;
1899
+ }
1900
+ const handler = (event) => {
1901
+ event.preventDefault();
1902
+ event.stopPropagation();
1903
+ doc.removeEventListener('click', handler, true);
1904
+ pickHandler = null;
1905
+ const target = event.target;
1906
+ const selector = buildSelector(target, doc.body ?? doc.documentElement ?? null);
1907
+ if (selector === '') return;
1908
+ writeSettings({ ...readSettings(), locators: setLocator(readSettings(), key, selector) });
1909
+ applyAll();
1910
+ };
1911
+ pickHandler = handler;
1912
+ doc.addEventListener('click', handler, true);
1913
+ };
1914
+
1915
+ const stopPicking = () => {
1916
+ if (doc !== null && pickHandler !== null) doc.removeEventListener('click', pickHandler, true);
1917
+ pickHandler = null;
1918
+ };
1919
+
1920
+ injectStyle(doc);
1921
+ ctx.effect(() => () => {
1922
+ stopPicking();
1923
+ clearNavState(doc);
1924
+ removeStyle(doc);
1925
+ if (doc !== null) {
1926
+ for (const element of Array.from(doc.querySelectorAll('[' + HIDDEN_ATTR + ']'))) element.removeAttribute(HIDDEN_ATTR);
1927
+ }
1928
+ }, 'ui-controller: style');
1929
+
1930
+ /** Elements we wrote `style.order` to; cleared before every pass and on teardown. */
1931
+ const ordered = [];
1932
+
1933
+ const applyAll = () => {
1934
+ const current = readSettings();
1935
+ applyHidden();
1936
+ applyVisualOrder(doc, current, ordered);
1937
+ applyNavStateTo(doc, current);
1938
+ };
1939
+
1940
+ applyAll();
1941
+ const timer = setInterval(applyAll, 2000);
1942
+ ctx.effect(() => () => clearInterval(timer), 'ui-controller: reapply timer');
1943
+ ctx.effect(
1944
+ () => () => {
1945
+ for (const element of ordered) {
1946
+ if (element.style !== undefined) element.style.order = '';
1947
+ }
1948
+ ordered.length = 0;
1949
+ },
1950
+ 'ui-controller: visual order cleanup',
1951
+ );
1952
+
1953
+ ctx.effect(
1954
+ () =>
1955
+ ctx.slots.inject('settings.section', () =>
1956
+ ctx.slots.register(
1957
+ {
1958
+ name: 'settings.section',
1959
+ id: SECTION_ID,
1960
+ order: SECTION_ORDER,
1961
+ locale: NS,
1962
+ label: () => t('settings.nav'),
1963
+ },
1964
+ (props) =>
1965
+ h(settingsPage, {
1966
+ t,
1967
+ inventory,
1968
+ apply: applyAll,
1969
+ subscribe: () => () => {},
1970
+ pick: pickElement,
1971
+ }),
1972
+ ),
1973
+ ),
1974
+ 'ui-controller: settings section',
1975
+ );
1976
+
1977
+ window.__UI_CONTROLLER__ = {
1978
+ version: VERSION,
1979
+ settings: {
1980
+ get: () => JSON.parse(JSON.stringify(readSettings())),
1981
+ set: (patch) => JSON.parse(JSON.stringify(patchSettings(isPlainObject(patch) ? patch : {}))),
1982
+ reset: () => JSON.parse(JSON.stringify(resetSettings())),
1983
+ presets: () => Object.keys(readSettings().presets).sort(),
1984
+ savePreset: (name) => savePreset(readSettings(), name),
1985
+ applyPreset: (name) => applyPreset(readSettings(), name),
1986
+ },
1987
+ inventory: () => inventory(),
1988
+ catalog: () => SLOT_CATALOG.map((slot) => ({ ...slot })),
1989
+ catalogSummary: () => ({ total: SLOT_CATALOG.length, kinds: kindCounts() }),
1990
+ apply: applyAll,
1991
+ };
1992
+
1993
+ return {
1994
+ version: VERSION,
1995
+ };
1996
+ }
1997
+
8
1998
  window.__ModuleLoader__.load({
9
1999
  id: 'dsh-ui-controller',
10
- factory() {
2000
+ factory(require) {
2001
+ React = require('react');
11
2002
  return {
12
- apply(ctx) {
13
- void ctx
14
- },
15
- }
2003
+ inject: ['slots', 'locale'],
2004
+ name: 'dsh-ui-controller',
2005
+ apply,
2006
+ VERSION,
2007
+ SETTINGS_KEY,
2008
+ PRESERVED_KEY,
2009
+ BACKUP_KEY,
2010
+ SETTINGS_VERSION,
2011
+ SLOT_CATALOG,
2012
+ KIND_ORDER,
2013
+ defaultSettings,
2014
+ sanitizeSettings,
2015
+ sanitizeLocatorKey,
2016
+ sanitizeSelector,
2017
+ slotRows,
2018
+ normalizeEntry,
2019
+ flattenSnapshot,
2020
+ runtimeCatalog,
2021
+ stepVisualOrder,
2022
+ canReorderRow,
2023
+ visualTargets,
2024
+ applyVisualOrder,
2025
+ reorderHost,
2026
+ canReorder,
2027
+ builtinOf,
2028
+ shippedSlotOf,
2029
+ dropKey,
2030
+ kindCounts,
2031
+ entryIdOf,
2032
+ locatorKeyOf,
2033
+ toggleHidden,
2034
+ canHide,
2035
+ setLocator,
2036
+ sanitizeVisualOrder,
2037
+ hiddenSelectors,
2038
+ locatorReason,
2039
+ buildSelector,
2040
+ capturePreset,
2041
+ savePreset,
2042
+ dropPreset,
2043
+ applyPreset,
2044
+ translator,
2045
+ slotGroups,
2046
+ filterGroups,
2047
+ isOpen,
2048
+ toggleOpen,
2049
+ resetOpen,
2050
+ NAV_ATTR,
2051
+ PANEL_SELECTOR,
2052
+ PANEL_NAV_STATES,
2053
+ NAV_WIDTHS,
2054
+ NAV_CSS,
2055
+ navWidthOf,
2056
+ navColumnsOf,
2057
+ hostSidebarCollapsed,
2058
+ resolveNavState,
2059
+ sanitizeNav,
2060
+ applyNavStateTo,
2061
+ clearNavState,
2062
+ DICTS,
2063
+ };
16
2064
  },
17
- })
2065
+ });