dsh-ui-controller 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  Notable changes to `dsh-ui-controller`.
4
4
 
5
+ ## 0.2.2 — 2026-11-15
6
+
7
+ ### Fixed
8
+
9
+ - **The More menu rows carry the panel's own icon.** The icon is cloned at
10
+ runtime from the live sidebar row — the first child of
11
+ `span[class*="panelGlyph"]` — into a reserved slot left of the name, so no
12
+ SVG is shipped here and no host class name is hardcoded. The slot is emptied
13
+ before each fill (a host remount cannot stack copies), ids are stripped from
14
+ the clone, and a panel without a readable glyph keeps an empty slot silently.
15
+ - **Folding takes the icon with the text.** `applyFoldState` now hides the
16
+ element that actually wraps both: the row button normally, or the wrapper when
17
+ the host draws the glyph beside the button. `nav` is never hidden, and
18
+ unfolding restores every element it touched.
19
+
5
20
  ## 0.2.1 — 2026-11-15
6
21
 
7
22
  ### Fixed
package/README.md CHANGED
@@ -186,7 +186,7 @@ Two sentences that belong in any answer about ordering:
186
186
  node --check client.js
187
187
  node --check index.js
188
188
  node --check test/classify.test.mjs
189
- node test/classify.test.mjs # expect: PASS — 38 groups
189
+ node test/classify.test.mjs # expect: PASS — 40 groups
190
190
  node ..\..\cangku\tmp\261114_gate_ui_controller.mjs # static gate, separate script
191
191
  ```
192
192
 
@@ -205,7 +205,11 @@ what the record and `foldAll` ask for; the count label repaints through the
205
205
  `nav.panelList` ancestor and only when its text changes; folding hides the live
206
206
  rows and restores them on the way out, leaving rows it cannot identify alone; and
207
207
  the menu borrows a live host item's class list and computed size instead of any
208
- hardcoded name.
208
+ hardcoded name; each menu row copies the panel glyph from the live sidebar row
209
+ (runtime clone taken from the drawing inside the host's slot anchor, ids and
210
+ `data-slot` stripped, refilled on every mount, remembered per panel so a folded
211
+ panel keeps its icon after the host stops rendering its row) and folding hides
212
+ the wrapper that owns both the icon and the text, never `nav`.
209
213
 
210
214
  ## Known limits
211
215
 
package/client.js CHANGED
@@ -27,7 +27,7 @@
27
27
  * slots sort by `priority → order`, everything else by `priority` alone.
28
28
  */
29
29
 
30
- const VERSION = '0.2.1';
30
+ const VERSION = '0.2.2';
31
31
 
32
32
  const NS = 'uiController';
33
33
  const SECTION_ID = 'ui-controller';
@@ -81,6 +81,9 @@ const PAGE_CSS = [
81
81
  '.uic-moreRow{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:4px 2px;font-size:13px;line-height:20px}',
82
82
  '.uic-moreRow + .uic-moreRow{border-top:1px solid var(--dsw-alias-border-l2)}',
83
83
  '.uic-moreRowName{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
84
+ '.uic-moreRowMain{display:flex;align-items:center;gap:8px;min-width:0;flex:1 1 auto}',
85
+ '.uic-moreGlyph{display:inline-flex;align-items:center;justify-content:center;flex:none;width:16px;height:16px;overflow:hidden}',
86
+ '.uic-moreGlyph>svg,.uic-moreGlyph>img{width:16px;height:16px;display:block}',
84
87
  '.uic-moreAction{flex:none;padding:2px 8px;font-size:12px;border:1px solid var(--dsw-alias-border-l4);border-radius:6px;cursor:pointer}',
85
88
  '.uic-moreAction:hover{background:var(--dsw-alias-bg-layer-2)}',
86
89
  '.uic-zone{border-top:.5px solid var(--dsw-alias-border-l2);padding:2px 0}',
@@ -1734,6 +1737,10 @@ let sidebarReplayQueued = false;
1734
1737
 
1735
1738
  /** Elements this session hid and the launcher title it rewrote; both are restored on teardown. */
1736
1739
  const moreTouched = new Map();
1740
+ /* Cloned panel glyphs, remembered per panel id: the host stops rendering a
1741
+ panel's row once it is pinned away, so the icon has to be kept from the last
1742
+ time that row was on screen. */
1743
+ const moreGlyphs = new Map();
1737
1744
  const moreTitle = { title: null, original: null };
1738
1745
 
1739
1746
  /** Resolve a panel entry's label the way the host does (thunk first, then string, then id). */
@@ -1761,6 +1768,184 @@ function foldedIdsOf(panels, settings, storageRef) {
1761
1768
  ).filter((id) => id !== 'plugins');
1762
1769
  }
1763
1770
 
1771
+ /**
1772
+ * The host sidebar row for one panel: matched by its own aria-label first, then
1773
+ * by the rendered title. Returns null while the row is not on screen yet.
1774
+ */
1775
+ function panelRowOf(doc, label) {
1776
+ if (doc === null || doc === undefined || typeof doc.querySelectorAll !== 'function') return null;
1777
+ let rows = [];
1778
+ try {
1779
+ rows = Array.from(doc.querySelectorAll('nav[class*="panelList"] button[class*="panelRow"]'));
1780
+ } catch {
1781
+ rows = [];
1782
+ }
1783
+ for (const row of rows) {
1784
+ const aria = row.getAttribute?.('aria-label') ?? '';
1785
+ if (aria !== '' && aria === label) return row;
1786
+ if (typeof row.querySelector !== 'function') continue;
1787
+ try {
1788
+ const title = row.querySelector('span[class*="panelTitle"]');
1789
+ if (title !== null && title !== undefined && (title.textContent ?? '') === label) return row;
1790
+ } catch {
1791
+ /* a row we cannot read is simply not a match */
1792
+ }
1793
+ }
1794
+ return null;
1795
+ }
1796
+
1797
+ /**
1798
+ * The element that has to disappear when a panel folds. Usually that is the row
1799
+ * button itself (the host draws the glyph inside it), but a panel whose icon is
1800
+ * rendered beside the button would leave the icon behind, so the wrapper that
1801
+ * holds both is hidden instead. `nav` is never a folding unit.
1802
+ */
1803
+ function foldUnitOf(row) {
1804
+ if (row === null || row === undefined) return null;
1805
+ let glyph = null;
1806
+ try {
1807
+ glyph = typeof row.querySelector === 'function' ? row.querySelector('span[class*="panelGlyph"]') : null;
1808
+ } catch {
1809
+ glyph = null;
1810
+ }
1811
+ if (glyph !== null && glyph !== undefined) return row;
1812
+ const parent = row.parentElement ?? null;
1813
+ if (parent === null) return row;
1814
+ if (String(parent.tagName ?? '').toUpperCase() === 'NAV') return row;
1815
+ let parentGlyph = null;
1816
+ try {
1817
+ parentGlyph = typeof parent.querySelector === 'function' ? parent.querySelector('span[class*="panelGlyph"]') : null;
1818
+ } catch {
1819
+ parentGlyph = null;
1820
+ }
1821
+ return parentGlyph !== null && parentGlyph !== undefined ? parent : row;
1822
+ }
1823
+
1824
+ /**
1825
+ * The node that actually draws the icon inside a host glyph span. The host puts
1826
+ * its slot anchor (`div[data-slot]` with `display: contents`) in between, so
1827
+ * the first child is a 0x0 wrapper; cloning that would duplicate a slot marker.
1828
+ * Returns the first svg / img / canvas inside it, or the first child itself when
1829
+ * the icon is drawn some other way.
1830
+ */
1831
+ function glyphIconNodeOf(glyph) {
1832
+ if (glyph === null || glyph === undefined) return null;
1833
+ const start = glyph.firstElementChild ?? null;
1834
+ if (start === null) return null;
1835
+ if (typeof start.querySelector === 'function') {
1836
+ try {
1837
+ const drawing = start.querySelector('svg, img, canvas');
1838
+ if (drawing !== null && drawing !== undefined) return drawing;
1839
+ } catch {
1840
+ return start;
1841
+ }
1842
+ }
1843
+ return start;
1844
+ }
1845
+
1846
+ /**
1847
+ * Deep-clone the glyph inside one live host row and strip ids (a second copy
1848
+ * would collide in the document). Returns null when the row draws no glyph.
1849
+ */
1850
+ function glyphCloneOf(row) {
1851
+ if (row === null || row === undefined) return null;
1852
+ let glyph = null;
1853
+ try {
1854
+ glyph = typeof row.querySelector === 'function' ? row.querySelector('span[class*="panelGlyph"]') : null;
1855
+ } catch {
1856
+ glyph = null;
1857
+ }
1858
+ if (glyph === null || glyph === undefined) return null;
1859
+ const source = glyphIconNodeOf(glyph);
1860
+ if (source === null || source === undefined) return null;
1861
+ let clone = null;
1862
+ try {
1863
+ clone = typeof source.cloneNode === 'function' ? source.cloneNode(true) : null;
1864
+ } catch {
1865
+ clone = null;
1866
+ }
1867
+ if (clone === null) return null;
1868
+ /* A cloned SVG can carry ids; the clone root counts as well, because
1869
+ querySelectorAll only sees descendants. A cloned wrapper could also still
1870
+ name a host slot, which must never be duplicated. */
1871
+ try {
1872
+ clone.removeAttribute?.('id');
1873
+ clone.removeAttribute?.('data-slot');
1874
+ } catch {
1875
+ /* ids are cosmetic in an icon */
1876
+ }
1877
+ if (typeof clone.querySelectorAll === 'function') {
1878
+ try {
1879
+ for (const tagged of Array.from(clone.querySelectorAll('[id]'))) tagged.removeAttribute?.('id');
1880
+ } catch {
1881
+ /* best effort */
1882
+ }
1883
+ }
1884
+ return clone;
1885
+ }
1886
+
1887
+ /** Remember one panel's glyph while its row is still rendered. */
1888
+ function captureMoreGlyph(panelId, row) {
1889
+ const id = String(panelId ?? '');
1890
+ if (id === '') return null;
1891
+ const cached = moreGlyphs.get(id) ?? null;
1892
+ if (cached !== null) return cached;
1893
+ const clone = glyphCloneOf(row);
1894
+ if (clone === null) return null;
1895
+ moreGlyphs.set(id, clone);
1896
+ return clone;
1897
+ }
1898
+
1899
+ /** Drop every remembered glyph (teardown, and tests). */
1900
+ function clearMoreGlyphs() {
1901
+ moreGlyphs.clear();
1902
+ }
1903
+
1904
+ /**
1905
+ * Copy the host's own panel glyph into one of our menu rows. The icon is the
1906
+ * first child of `span[class*="panelGlyph"]` inside the panel row — cloned at
1907
+ * runtime, never shipped here, so a host redesign keeps working. The
1908
+ * placeholder is emptied first, which makes the host remounting the menu
1909
+ * idempotent; a missing glyph leaves it empty and returns false (silent).
1910
+ */
1911
+ function mountMoreGlyph(placeholder, doc, label, panelId) {
1912
+ if (placeholder === null || placeholder === undefined) return false;
1913
+ try {
1914
+ while (placeholder.firstChild !== null && placeholder.firstChild !== undefined) {
1915
+ placeholder.removeChild(placeholder.firstChild);
1916
+ }
1917
+ } catch {
1918
+ /* a placeholder we cannot clear is left as it is */
1919
+ }
1920
+ const row = panelRowOf(doc, label);
1921
+ /* A live row is the freshest source and also refreshes the memory; once the
1922
+ host pins a panel away its row disappears, so the remembered clone is what
1923
+ keeps the icon in our menu. */
1924
+ let source = null;
1925
+ if (row !== null) {
1926
+ const fresh = glyphCloneOf(row);
1927
+ if (fresh !== null) {
1928
+ moreGlyphs.set(String(panelId ?? label), fresh);
1929
+ source = fresh;
1930
+ }
1931
+ }
1932
+ if (source === null) source = moreGlyphs.get(String(panelId ?? label)) ?? null;
1933
+ if (source === null) return false;
1934
+ let clone = null;
1935
+ try {
1936
+ clone = typeof source.cloneNode === 'function' ? source.cloneNode(true) : null;
1937
+ } catch {
1938
+ clone = null;
1939
+ }
1940
+ if (clone === null) return false;
1941
+ try {
1942
+ placeholder.appendChild(clone);
1943
+ } catch {
1944
+ return false;
1945
+ }
1946
+ return true;
1947
+ }
1948
+
1764
1949
  /**
1765
1950
  * Hide the panel rows that belong behind the More button. The host keeps its
1766
1951
  * pins in memory only and re-renders rows on every store change, so this pass
@@ -1792,14 +1977,26 @@ function applyFoldState(doc, panels, settings, storageRef, touched) {
1792
1977
  }
1793
1978
  const id = byLabel.get(label) ?? byLabel.get(titleText) ?? null;
1794
1979
  if (id === null) continue;
1980
+ /* Remember the icon before this row can disappear from the sidebar. */
1981
+ captureMoreGlyph(id, row);
1795
1982
  const hide = folded.has(id);
1796
- const current = row.style?.display ?? '';
1983
+ /* Hide whatever actually wraps both the icon and the text; a bare row button
1984
+ is the normal case, a wrapper is used when the host draws the glyph beside
1985
+ the button. `nav` is never hidden. */
1986
+ const unit = foldUnitOf(row);
1987
+ if (unit === null) continue;
1988
+ const current = unit.style?.display ?? '';
1797
1989
  if (hide === true && current !== 'none') {
1798
- if (touched.has(row) === false) touched.set(row, current);
1799
- row.style.display = 'none';
1800
- } else if (hide === false && touched.has(row) === true) {
1801
- row.style.display = touched.get(row);
1802
- touched.delete(row);
1990
+ if (touched.has(unit) === false) touched.set(unit, current);
1991
+ unit.style.display = 'none';
1992
+ } else if (hide === false) {
1993
+ for (const candidate of [unit, row, row.parentElement ?? null]) {
1994
+ if (candidate === null || candidate === undefined) continue;
1995
+ if (touched.has(candidate) === true) {
1996
+ candidate.style.display = touched.get(candidate);
1997
+ touched.delete(candidate);
1998
+ }
1999
+ }
1803
2000
  }
1804
2001
  }
1805
2002
  }
@@ -1966,7 +2163,21 @@ function SidebarMoreMenu(props) {
1966
2163
  'data-uic-more-row': entry.id,
1967
2164
  onClick: () => { onOpen(entry.id); onDismiss(); },
1968
2165
  }, [
1969
- node('span', { key: 'name', className: 'uic-moreRowName' }, entry.label),
2166
+ node('span', { key: 'main', className: 'uic-moreRowMain' }, [
2167
+ node('span', {
2168
+ key: 'glyph',
2169
+ className: 'uic-moreGlyph',
2170
+ 'data-uic-more-glyph': entry.id,
2171
+ /* The host owns the icon: copy it from the live sidebar row once this
2172
+ placeholder is in the document. Refilled on every mount, so a host
2173
+ remount cannot stack copies. */
2174
+ ref: (element) => {
2175
+ if (element === null || element === undefined) return;
2176
+ mountMoreGlyph(element, doc, entry.label, entry.id);
2177
+ },
2178
+ }, []),
2179
+ node('span', { key: 'name', className: 'uic-moreRowName' }, entry.label),
2180
+ ]),
1970
2181
  node('span', {
1971
2182
  key: 'toggle',
1972
2183
  className: 'uic-moreToggle',
@@ -2054,6 +2265,7 @@ function apply(ctx) {
2054
2265
  .filter((panel) => panel.id !== '');
2055
2266
  const paintCount = () => paintMoreCount(doc, sidebarPanelsOf(), readSettings(), storage(), moreTitle);
2056
2267
  const applyFold = () => applyFoldState(doc, sidebarPanelsOf(), readSettings(), storage(), moreTouched);
2268
+ ctx.effect(() => () => clearMoreGlyphs(), 'ui-controller: forget sampled glyphs');
2057
2269
 
2058
2270
  /* One slot only, and only after it is declared: the inject callback itself
2059
2271
  only fires once the host declares the slot, so the guard is belt and
@@ -2302,6 +2514,11 @@ window.__ModuleLoader__.load({
2302
2514
  foldedIdsOf,
2303
2515
  entryLabelOf,
2304
2516
  applyFoldState,
2517
+ clearMoreGlyphs,
2518
+ foldUnitOf,
2519
+ glyphIconNodeOf,
2520
+ mountMoreGlyph,
2521
+ panelRowOf,
2305
2522
  sampleMoreItem,
2306
2523
  paintMoreCount,
2307
2524
  SidebarMoreMenu,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ui-controller",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Inspect and control the UI other plugins register into DeepSeek Harness slots (visibility, order, mirrored entries), and fold the sidebar's panels behind a single \"More (N)\" row.",
5
5
  "license": "MIT",
6
6
  "author": {