From 3881cbd61cc18c81052e9cedff7511376eaa5285 Mon Sep 17 00:00:00 2001 From: James Briggs <35938317+jamescalam@users.noreply.github.com> Date: Fri, 4 Dec 2026 18:04:56 +0800 Subject: [PATCH] Prototype panel: starts folded to its line on a phone (under 41.5rem) and open at the side on a wider window, set once by its script so a phone never shows it open first and a person's fold stays Co-authored-by: Pointman Co-authored-by: Claude --- design/assets/base.html | 7 +++++-- design/assets/shepherd.html | 5 +++-- design/assets/starter.html | 7 +++++-- test/check.test.js | 26 +++++++++++++++++++++----- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/design/assets/base.html b/design/assets/base.html index fcc4166..9be9c53 100644 --- a/design/assets/base.html +++ b/design/assets/base.html @@ -519,7 +519,7 @@ on each direction as data-viewer="1", data-dark="1": style its values with [data-ss-id="direction-"][data-viewer="1"] … Made-up numbers:

Sample what is made up

after the inputs, and a Sample beside each in the design. --> -
+
Prototype
@@ -1166,7 +1166,10 @@ if (e.key === 'Escape' && e.target.tagName !== 'SUMMARY') { e.preventDefault(); e.stopPropagation(); e.currentTarget.querySelector('summary').focus(); } else if (d && k >= 0) { e.preventDefault(); const n = all[(k + d + all.length) % all.length]; n.focus(); n.click(); } }); - const again = () => { wire(); ssMirror(); ssControls().forEach((i) => i.ssRead && i.ssRead()); keep(); sum(); }; + // open from the start at the side, folded to its line on a phone (under 41.5rem), so a phone never shows it open + // first. Once for each panel: a person's fold stays, and a fresh one from a live push starts the same way. + const start = () => { const t = document.querySelector('.tweaks'); if (t && !t.ssStarted) { t.ssStarted = true; t.open = matchMedia('(min-width: 41.51rem)').matches; } }; + const again = () => { wire(); ssMirror(); ssControls().forEach((i) => i.ssRead && i.ssRead()); keep(); sum(); start(); }; new MutationObserver(again).observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class', 'data-canvas-view'] }); again(); })(); diff --git a/design/assets/shepherd.html b/design/assets/shepherd.html index 357f188..4c32fbd 100644 --- a/design/assets/shepherd.html +++ b/design/assets/shepherd.html @@ -155,7 +155,7 @@

A few choices before I draw

-
+
Prototype
@@ -403,7 +403,8 @@

A few choices before I draw

if (e.key === 'Escape' && e.target.tagName !== 'SUMMARY') { e.preventDefault(); e.stopPropagation(); e.currentTarget.querySelector('summary').focus(); } else if (d && k >= 0) { e.preventDefault(); const n = all[(k + d + all.length) % all.length]; n.focus(); n.click(); } }); -const again = () => { wire(); ssMirror(); ssControls().forEach((i) => i.ssRead && i.ssRead()); keep(); sum(); }; +const start = () => { const t = document.querySelector('.tweaks'); if (t && !t.ssStarted) { t.ssStarted = true; t.open = matchMedia('(min-width: 41.51rem)').matches; } }; +const again = () => { wire(); ssMirror(); ssControls().forEach((i) => i.ssRead && i.ssRead()); keep(); sum(); start(); }; new MutationObserver(again).observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class', 'data-canvas-view'] }); again(); })(); diff --git a/design/assets/starter.html b/design/assets/starter.html index afbec53..295c2ef 100644 --- a/design/assets/starter.html +++ b/design/assets/starter.html @@ -519,7 +519,7 @@ on each direction as data-viewer="1", data-dark="1": style its values with [data-ss-id="direction-"][data-viewer="1"] … Made-up numbers:

Sample what is made up

after the inputs, and a Sample beside each in the design. --> -
+
Prototype
@@ -1139,7 +1139,10 @@ if (e.key === 'Escape' && e.target.tagName !== 'SUMMARY') { e.preventDefault(); e.stopPropagation(); e.currentTarget.querySelector('summary').focus(); } else if (d && k >= 0) { e.preventDefault(); const n = all[(k + d + all.length) % all.length]; n.focus(); n.click(); } }); - const again = () => { wire(); ssMirror(); ssControls().forEach((i) => i.ssRead && i.ssRead()); keep(); sum(); }; + // open from the start at the side, folded to its line on a phone (under 41.5rem), so a phone never shows it open + // first. Once for each panel: a person's fold stays, and a fresh one from a live push starts the same way. + const start = () => { const t = document.querySelector('.tweaks'); if (t && !t.ssStarted) { t.ssStarted = true; t.open = matchMedia('(min-width: 41.51rem)').matches; } }; + const again = () => { wire(); ssMirror(); ssControls().forEach((i) => i.ssRead && i.ssRead()); keep(); sum(); start(); }; new MutationObserver(again).observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class', 'data-canvas-view'] }); again(); })(); diff --git a/test/check.test.js b/test/check.test.js index 30ebbf7..c537592 100644 --- a/test/check.test.js +++ b/test/check.test.js @@ -681,7 +681,7 @@ test("Keep these names a change only where it was made: one direction's edit isn // The Prototype bar's script with one choice (Viewer) and a named switch (Activity), on a canvas of two directions // or with First open. -function barStates(canvas, swatches) { +function barStates(canvas, swatches, width) { const vm = require("vm"); const src = BASE.slice(BASE.indexOf("/* controls: the inputs"), BASE.indexOf("/* kit: the filters' fold button")); const el = (tag) => { const e = { tag, children: [], attrs: {}, on: {}, dataset: {}, isConnected: false, textContent: "" }; @@ -700,19 +700,23 @@ function barStates(canvas, swatches) { const keep = { dataset: { ssSay: "" }, title: "" }; keep.closest = (q) => (q === "[data-tweaks-keep]" ? keep : null); const document = { - querySelector: (q) => (q === "section.direction.on" ? first : q === "[data-tweaks-keep]" ? keep : q === ".switcher[data-canvas-view]" ? (canvas ? {} : null) : q === "section.direction" ? first : null), + querySelector: (q) => (q === ".tweaks" ? panel : q === "section.direction.on" ? first : q === "[data-tweaks-keep]" ? keep : q === ".switcher[data-canvas-view]" ? (canvas ? {} : null) : q === "section.direction" ? first : null), querySelectorAll: (q) => (q === ".tweaks input[data-var]" ? controls : q === "section.direction" ? [first, second] : []), addEventListener() {}, createElement: el, documentElement: attrs({}), }; - const win = { document, getComputedStyle: () => ({ getPropertyValue: () => "0" }), MutationObserver: class { observe() {} }, Event: class { constructor(t) { this.type = t; } } }; + // the panel, when a test gives the window's width: closed, as the markup has it; (min-width: 41.51rem) is 664 px + const panel = width ? { open: false, addEventListener() {} } : null; + let changed = () => {}; + const win = { document, getComputedStyle: () => ({ getPropertyValue: () => "0" }), MutationObserver: class { constructor(f) { changed = f; } observe() {} }, Event: class { constructor(t) { this.type = t; } }, + matchMedia: (q) => ({ matches: q === "(min-width: 41.51rem)" && width >= 664.16 }) }; win.window = win; win.parent = {}; vm.runInNewContext(src, win); // the tap on Keep these brings its line up to date first, as on the page - return { controls, first, second, keep, tap: () => win.ssKeep({ target: keep }) }; + return { controls, first, second, keep, panel, changed: () => changed(), tap: () => win.ssKeep({ target: keep }) }; } test("the Prototype panel draws a choice as labelled segments and a switch as a toggle, and a tap sets every direction on the canvas, or the open one", async () => { - assert.match(BASE, /
\n Prototype<\/summary>/, "the bar is open from the start, titled Prototype"); + assert.match(BASE, /
\n Prototype<\/summary>/, "the bar is titled Prototype, and its script opens it where there is room"); assert.ok(BASE.indexOf('
BASE.indexOf('
'), "it sits under the tabs' row, after Export"); const bar = barStates(true), [viewer, activity] = bar.controls; assert.deepEqual(viewer.seg.children.map((b) => b.textContent), ["Someone else", "The owner"]); @@ -734,6 +738,18 @@ test("the Prototype panel draws a choice as labelled segments and a switch as a assert.equal(open.keep.dataset.ssSay, "Keep these for First: Activity Hidden"); }); +test("the Prototype panel starts open at the side on a wide window and folded to its line on a phone, and a person's fold stays", () => { + assert.equal(barStates(true, undefined, 1440).panel.open, true, "at 1440 it is open"); + assert.equal(barStates(true, undefined, 390).panel.open, false, "at 390 it is one line at the top, not 300 px of rows over the design"); + assert.equal(barStates(true, undefined, 664).panel.open, false, "at 41.5rem the bar is still a phone's"); + const wide = barStates(false, undefined, 1440); + wide.panel.open = false; wide.changed(); + assert.equal(wide.panel.open, false, "folded by the person, it stays folded as the page changes"); + const phone = barStates(false, undefined, 390); + phone.panel.open = true; phone.changed(); + assert.equal(phone.panel.open, true, "opened on a phone, it stays open"); +}); + test("a choice of colours shows each option's colour as a ringed swatch before its name, which stays its label", () => { const rule = BASE.match(/^ \.tweaks \.seg i \{[^}]*\}$/m); assert.ok(rule && /height: 32px/.test(rule[0]) && /box-shadow: inset 0 0 0 1px var\(--tw-off\)/.test(rule[0]), "a tile with a ring at 3:1, so white or near-black shows on the panel");