Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions design/assets/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@
on each direction as data-viewer="1", data-dark="1": style its values with [data-ss-id="direction-<slug>"][data-viewer="1"] …
Made-up numbers: <p class="sample-note"><b>Sample</b> what is made up</p> after the inputs, and a
<span class="k-sample">Sample</span> beside each in the design. -->
<details class="tweaks" open>
<details class="tweaks">
<summary>Prototype</summary>
<div class="tweaks-body">
<button type="button" data-tweaks-keep data-ss-say="">Keep these</button>
Expand Down Expand Up @@ -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();
})();
Expand Down
5 changes: 3 additions & 2 deletions design/assets/shepherd.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ <h2>A few choices before I draw</h2>
<button type="button" class="frame-use" data-ss-say="" hidden><span class="use">Use this</span><span class="chosen">✓ Chosen</span></button>
<button type="button" class="frame-round" data-ss-say="" hidden>Another round</button>
</div>
<details class="tweaks" open>
<details class="tweaks">
<summary>Prototype</summary>
<div class="tweaks-body">
<button type="button" data-tweaks-keep data-ss-say="">Keep these</button>
Expand Down Expand Up @@ -403,7 +403,8 @@ <h2>A few choices before I draw</h2>
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();
})();
Expand Down
7 changes: 5 additions & 2 deletions design/assets/starter.html
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@
on each direction as data-viewer="1", data-dark="1": style its values with [data-ss-id="direction-<slug>"][data-viewer="1"] …
Made-up numbers: <p class="sample-note"><b>Sample</b> what is made up</p> after the inputs, and a
<span class="k-sample">Sample</span> beside each in the design. -->
<details class="tweaks" open>
<details class="tweaks">
<summary>Prototype</summary>
<div class="tweaks-body">
<button type="button" data-tweaks-keep data-ss-say="">Keep these</button>
Expand Down Expand Up @@ -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();
})();
Expand Down
26 changes: 21 additions & 5 deletions test/check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" };
Expand All @@ -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, /<details class="tweaks" open>\n <summary>Prototype<\/summary>/, "the bar is open from the start, titled Prototype");
assert.match(BASE, /<details class="tweaks">\n <summary>Prototype<\/summary>/, "the bar is titled Prototype, and its script opens it where there is room");
assert.ok(BASE.indexOf('<details class="tweaks"') > BASE.indexOf('<div class="export no-print">'), "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"]);
Expand All @@ -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");
Expand Down