create-pmos 0.600.0 → 0.602.0
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/package.json +33 -27
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +32 -0
- package/workspace/guide/agent-capabilities.md +7 -7
- package/workspace/guide/settings-and-switches.md +24 -0
- package/workspace/lib/bg-queue.js +1 -0
- package/workspace/lib/event-relay.js +202 -0
- package/workspace/lib/job-graph.js +1 -0
- package/workspace/lib/live-round.js +30 -8
- package/workspace/lib/proto-runtime.js +39 -5
- package/workspace/lib/refresh-run.js +171 -30
- package/workspace/lib/refresh.js +107 -20
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-lab.js +10 -6
- package/workspace/lib/routes-refresh.js +12 -4
- package/workspace/lib/routes-relay.js +29 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-ev.css +9 -0
- package/workspace/public/pm/cozy-evmodel.js +14 -0
- package/workspace/public/pm/cozy-proto.css +66 -17
- package/workspace/public/pm/cozy-proto.js +224 -56
- package/workspace/public/pm/cozy-relay.js +80 -0
- package/workspace/public/pm/cozy-schedwork.js +52 -19
- package/workspace/public/pm/cozy-settings.js +11 -3
- package/workspace/public/pm/home-chat.js +4 -0
- package/workspace/server.js +15 -6
- package/workspace/skills/sources-read.skill +1 -1
- package/workspace/test-lists/event-relay.json +9 -0
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
* 2026-11-17). The initiative chat sits on the left; this draws the right side for a live round (lib/live-round.js), from the compare view
|
|
4
4
|
* pm/cozy-lab.js reads (GET /api/lab/compare: the version's file and its companions as data, lib/live-round.js partsAt).
|
|
5
5
|
*
|
|
6
|
-
* The toolbar:
|
|
7
|
-
*
|
|
6
|
+
* The toolbar: Select (V), Comment (C), Draw (D) · pages and layers ([), the inspector (]) · Page copy, The flow, Who does what (side
|
|
7
|
+
* panels, closed by default: Wawan 2026-11-18) · Latest · version n (‹ to earlier ones; an older one has › , Back to latest, Continue from
|
|
8
|
+
* version n) · zoom −, +, fit · Play. Icon-only presses with aria-labels.
|
|
9
|
+
* Design mode (design "Prototype like Figma", Exploring 2 page pgFp, Wawan "build" 2026-11-18): Pages > Screens > Layers on the left (a
|
|
10
|
+
* page is a data-page, its screens are its states, its layers are the data-el blocks of the screen shown); the inspector on the right
|
|
11
|
+
* (Exact values: text, font, size, weight, line height, spacing, colour, fill, corner, padding, align), saved with the version in
|
|
12
|
+
* edits.json (styles) and kept by the next version; a change says "You set … Kept as yours." once in the chat ('pmos:note').
|
|
8
13
|
* The cards, which update together: the prototype in a phone or desktop frame (Tweaks under it for the element pointed at, the comments,
|
|
9
14
|
* the ✦ test-link suggestion); the flow (screens as cards, decisions as diamonds, drawn as SVG from flow.json: a screen shows that moment
|
|
10
15
|
* on the prototype, a branch plays its scenario); the page copy, in its side panel (copy.json, edited in place: the prototype changes as the PM types and
|
|
@@ -31,7 +36,8 @@ const I = {
|
|
|
31
36
|
prev: 'M15 6l-6 6 6 6', next: 'M9 6l6 6-6 6', latest: 'M5 12h14M13 6l6 6-6 6', cont: 'M4 12a8 8 0 1 0 2.3-5.6L4 9M4 4v5h5',
|
|
32
37
|
restart: 'M4 12a8 8 0 1 0 2.3-5.6L4 9M4 4v5h5', x: 'M6 6l12 12M18 6L6 18', check: 'M5 12l5 5 9-10', send: 'M12 19V5M6 11l6-6 6 6',
|
|
33
38
|
keep: 'M6 4h12v16l-6-4-6 4z', link: 'M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1',
|
|
34
|
-
text: 'M4 7V5h16v2M12 5v14M9 19h6',
|
|
39
|
+
text: 'M4 7V5h16v2M12 5v14M9 19h6', flow: 'M3 4h6v5H3zM15 4h6v5h-6zM9 15h6v5H9zM9 6.5h6M18 9v3h-6v3', lanes: 'M3 6h18M3 12h18M3 18h18M6 4h4v4H6zM13 10h4v4h-4z',
|
|
40
|
+
left: 'M3 4h18v16H3zM9 4v16', right: 'M3 4h18v16H3zM15 4v16', own: 'M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5', undo: 'M3 7v6h6M21 17a9 9 0 0 0-15-6.7L3 13', select: 'M4 3l7 18 2.5-7.5L21 11z',
|
|
35
41
|
attach: 'M20 11l-8.5 8.5a5 5 0 0 1-7-7L13 4a3.5 3.5 0 0 1 5 5l-8.5 8.5a2 2 0 0 1-3-3L14 7', star: 'M12 3l2.2 6.3H21l-5.4 4 2 6.4L12 15.8 6.4 19.7l2-6.4L3 9.3h6.8z',
|
|
36
42
|
};
|
|
37
43
|
const ib = (attr, label, icon, cls = '') => `<button type="button" class="pc-ib${cls ? ' ' + cls : ''}" ${attr} aria-label="${esc(label)}" title="${esc(label)}">${SVG(icon, 16)}</button>`;
|
|
@@ -143,9 +149,12 @@ export function lanesLayout(lanes) {
|
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
/* ── state ── */
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
/* Design mode is the default (design "Prototype like Figma", Wawan "build" 2026-11-18): Select is on, Pages > Screens > Layers on the left,
|
|
153
|
+
* the inspector (Exact values) on the right; both hide ([ and ]). Page copy, The flow and Who does what are side panels behind toolbar
|
|
154
|
+
* presses, closed by default; one shows at a time, in the inspector's place. The device switch is only for Play. */
|
|
155
|
+
const V = { body: null, c: null, at: null, H: null, last: null, mode: 'point', pdev: store.get('pmos.pc.pdev') || 'own', zoom: Number(store.get('pmos.pc.zoom')) || 0,
|
|
156
|
+
sel: null, looks: null, screen: '', frameUrl: '', ready: null, edits: { copy: {}, vars: {}, styles: {} }, pend: null, saveT: null, draft: null, drawing: false, strokes: 0,
|
|
157
|
+
play: null, sig: '', side: null, left: store.get('pmos.pc.left') !== '0', insp: store.get('pmos.pc.insp') !== '0', noteT: null };
|
|
149
158
|
const ARROW = '<marker id="pcArr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" fill="currentColor"/></marker>';
|
|
150
159
|
const frameUrl = (c) => (c && c.url ? c.url + '&rt=1' : '');
|
|
151
160
|
const toFrame = (m, f) => { const fr = f || (V.body && V.body.querySelector('.pc-frame iframe')); if (fr && fr.contentWindow) fr.contentWindow.postMessage({ pmos: 1, ...m }, '*'); };
|
|
@@ -162,20 +171,22 @@ function shown(c) {
|
|
|
162
171
|
|
|
163
172
|
/* ── the parts ── */
|
|
164
173
|
function barHtml(c, v) {
|
|
165
|
-
const H = (c.history || []).filter((h) => h.round)
|
|
174
|
+
const H = (c.history || []).filter((h) => h.round);
|
|
166
175
|
const at = H.findIndex((h) => h.current), newest = H[0];
|
|
167
176
|
const older = at >= 0 && at + 1 < H.length ? H[at + 1] : null, newer = at > 0 ? H[at - 1] : null;
|
|
168
177
|
const old = at > 0 && newest;
|
|
169
178
|
const tool = (m, label, icon, key) => `<button type="button" class="pc-ib" data-pc-mode="${m}" aria-pressed="${V.mode === m}" aria-label="${esc(label + ' (' + key + ')')}" title="${esc(label + ' (' + key + ')')}">${SVG(icon, 16)}</button>`;
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
: `<span class="pc-ver"
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
+ `<span class="pc-grp">${
|
|
178
|
-
|
|
179
|
+
const tog = (attr, on, label, icon, extra = '') => `<button type="button" class="pc-ib${extra}" ${attr} aria-pressed="${on}" aria-label="${esc(label)}" title="${esc(label)}">${SVG(icon, 16)}</button>`;
|
|
180
|
+
// the design opens on the latest version (Wawan 2026-11-18: "default should show the latest version"); an older one says so, with the way back
|
|
181
|
+
const ver = !old ? `<span class="pc-ver">${older ? ib(`data-lab-round="${esc(older.id)}"`, 'Earlier version', I.prev) : ''}<b>Latest · version ${c.round || 1}</b></span>`
|
|
182
|
+
: `<span class="pc-ver">${ib(`data-lab-round="${esc(older ? older.id : '')}"${older ? '' : ' disabled'}`, 'Earlier version', I.prev)}<b>Version ${c.round}</b>${ib(`data-lab-round="${esc(newer ? newer.id : '')}"`, 'Later version', I.next)}`
|
|
183
|
+
+ ib(`data-lab-round="${esc(newest.id)}"`, 'Back to latest', I.latest) + ib(`data-pc-from="${c.round}"`, 'Continue from version ' + c.round, I.cont) + '</span>';
|
|
184
|
+
const z = Math.round((V.zoom || 1) * 100), u = c.updated || {};
|
|
185
|
+
return `<div class="pc-bar" role="toolbar" aria-label="Prototype tools"><span class="pc-grp">${tool('point', 'Select a layer', I.select, 'V')}${tool('comment', 'Comment', I.comment, 'C')}${tool('draw', 'Draw a sketch', I.draw, 'D')}</span>`
|
|
186
|
+
+ `<span class="pc-grp" aria-label="Show or hide panels">${tog('data-pc-left', V.left, (V.left ? 'Hide' : 'Show') + ' pages and layers ([)', I.left)}${tog('data-pc-insp', V.insp && !V.side, (V.insp ? 'Hide' : 'Show') + ' the inspector (])', I.right)}</span>`
|
|
187
|
+
// the page copy, the flow and who does what each sit behind one press, closed by default (Wawan 2026-11-18), like the page copy before
|
|
188
|
+
+ `<span class="pc-grp" aria-label="Side panels">${tog('data-pc-side="copy"', V.side === 'copy', 'Page copy', I.text, u.copy ? ' upd' : '')}${tog('data-pc-side="flow"', V.side === 'flow', 'The flow', I.flow, u.flow ? ' upd' : '')}${tog('data-pc-side="lanes"', V.side === 'lanes', 'Who does what', I.lanes, u.lanes ? ' upd' : '')}</span>`
|
|
189
|
+
+ `${ver}<span class="pc-sp"></span>`
|
|
179
190
|
+ `<span class="pc-grp">${ib('data-pc-zoom="-1"', 'Zoom out', I.minus)}<span class="pc-z" aria-live="polite">${z}%</span>${ib('data-pc-zoom="1"', 'Zoom in', I.plus)}${ib('data-pc-zoom="0"', 'Fit to the Viewer', I.fit)}</span>`
|
|
180
191
|
+ `${ib('data-pc-play', 'Play the prototype', I.play, 'blue')}</div>`;
|
|
181
192
|
}
|
|
@@ -201,15 +212,14 @@ if (typeof document !== 'undefined' && typeof setInterval === 'function') setInt
|
|
|
201
212
|
function protoCard(c, v, making) {
|
|
202
213
|
const data = v.data || {}, tw = ((data.tweaks && data.tweaks.tweaks) || []).filter((t) => !t.el || (V.sel && t.el === V.sel.el));
|
|
203
214
|
const tweaks = tw.length ? `<div class="pc-tw" aria-label="Tweaks">${tw.map((t) => { const val = parseFloat(V.edits.vars[t.var]) || t.value; return `<label><span>${esc(t.label)}</span><input type="range" min="${t.min}" max="${t.max}" step="${t.step}" value="${val}" data-pc-var="${esc(t.var)}" data-pc-unit="${esc(t.unit)}"><em>${esc(val + t.unit)}</em></label>`; }).join('')}</div>` : '';
|
|
204
|
-
const sel = V.sel ? `<p class="pc-sel">${SVG(I.point, 14)}<b>${esc(V.sel.label || V.sel.el)}</b> is in the chat box: say the change.${ib('data-pc-unsel', 'Clear the element', I.x)}</p>` : '';
|
|
215
|
+
const sel = V.sel && !(V.insp && !V.side) ? `<p class="pc-sel">${SVG(I.point, 14)}<b>${esc(V.sel.label || V.sel.el)}</b> is in the chat box: say the change.${ib('data-pc-unsel', 'Clear the element', I.x)}</p>` : '';
|
|
205
216
|
const cm = (c.comments || []).filter((x) => !x.send);
|
|
206
217
|
const draft = V.draft ? `<div class="pc-cdraft"><label for="pcCm">Comment${V.draft.label ? ' on ' + esc(V.draft.label) : ''}</label><textarea id="pcCm" rows="2" maxlength="500" placeholder="Say what should change"></textarea><span>${ib('data-pc-cm="send"', 'Send to PMOS as the next change', I.send, 'blue')}${ib('data-pc-cm="keep"', 'Keep for the team', I.keep)}${ib('data-pc-cm="x"', 'Cancel', I.x)}</span></div>` : '';
|
|
207
218
|
const list = cm.length ? `<ol class="pc-cms">${cm.map((x, i) => `<li><span class="pc-pin">${i + 1}</span><span class="w">${x.label ? `<small>on ${esc(x.label)}</small>` : ''}${esc(x.text)}</span>${ib(`data-pc-make="${esc(x.id)}"`, 'Make this change', I.star)}</li>`).join('')}</ol>` : '';
|
|
208
219
|
const sug = suggestion(c);
|
|
209
220
|
const draw = V.mode === 'draw' ? `<canvas class="pc-ink" aria-label="Sketch over the prototype"></canvas><span class="pc-inkacts">${ib('data-pc-ink="attach"', 'Attach the sketch to your next message', I.attach, 'blue')}${ib('data-pc-ink="clear"', 'Clear the sketch', I.x)}</span>` : '';
|
|
210
221
|
const lost = c.notMade ? `<p class="pc-making pc-lost">Version ${c.round} was not made: ${esc(c.notMade)}.${c.fallbackN ? ` This is version ${c.fallbackN}.` : ''} Ask in the chat for it in smaller steps, one screen or format at a time.</p>` : '';
|
|
211
|
-
return `<
|
|
212
|
-
+ `<div class="pc-dev ${V.device}"><div class="pc-frame" data-pc-frame>${v.url ? '' : '<p class="pc-none">PMOS is making it.</p>'}</div>${draw}</div>${sel}${tweaks}${draft}${list}${sug}</section>`;
|
|
222
|
+
return { pre: lost + (making ? progressHtml(c) : ''), dev: `<div class="pc-frame" data-pc-frame>${v.url ? '' : '<p class="pc-none">PMOS is making it.</p>'}</div>${draw}`, post: sel + tweaks + draft + list + sug };
|
|
213
223
|
}
|
|
214
224
|
function suggestion(c) {
|
|
215
225
|
// the design sprint runs silently: PMOS recommends good practice as ONE ✦ (canvas PbcChat), here: test it with people once it settles
|
|
@@ -219,8 +229,10 @@ function suggestion(c) {
|
|
|
219
229
|
return `<div class="pc-sug"><span class="pc-star" aria-hidden="true">✦</span><p>Version ${c.round} answers the brief. Try it on 3 to 5 people it is for before more polish.</p>${ib(`data-pc-sug="link" data-pc-sugk="${esc(key)}"`, 'Get a test link', I.link, 'blue')}${ib(`data-pc-sug="no" data-pc-sugk="${esc(key)}"`, 'Not now', I.x)}</div>`;
|
|
220
230
|
}
|
|
221
231
|
function flowCard(c, v) {
|
|
232
|
+
if (V.side !== 'flow') return '';
|
|
233
|
+
const close = ib('data-pc-side="flow"', 'Close the flow', I.x);
|
|
222
234
|
const f = (v.data || {}).flow, st = (c.parts || {}).flow;
|
|
223
|
-
if (!f) return `<section class="pc-card pc-flowc" aria-label="The flow"><h3>The flow</h3><p class="pc-none">${esc(st === 'working' ? 'PMOS is drawing it.' : st && st !== 'ok' ? 'Not made this time: ' + st.replace(/^not made: /, '') : 'No flow for this version.')}</p></section>`;
|
|
235
|
+
if (!f) return `<section class="pc-card pc-flowc pc-side" aria-label="The flow"><h3>The flow ${close}</h3><p class="pc-none">${esc(st === 'working' ? 'PMOS is drawing it.' : st && st !== 'ok' ? 'Not made this time: ' + st.replace(/^not made: /, '') : 'No flow for this version.')}</p></section>`;
|
|
224
236
|
const L = flowLayout(f), scen = f.scenarios || [];
|
|
225
237
|
const branchOf = (to) => { for (let i = 1; i < scen.length; i += 1) if (scen[i].steps.some((s) => s.screen === to)) return scen[i].id; return ''; };
|
|
226
238
|
const nodes = L.nodes.map((n) => n.kind === 'decision'
|
|
@@ -228,12 +240,12 @@ function flowCard(c, v) {
|
|
|
228
240
|
: `<g class="pc-sn${n.main ? '' : ' br'}${V.screen === n.id ? ' on' : ''}" data-pc-screen="${esc(n.id)}" role="button" tabindex="0" aria-label="${esc('Show ' + n.title + ' on the prototype')}"><rect x="${n.x}" y="${n.y}" width="${n.w}" height="${n.h}" rx="8"/><text x="${n.x + 10}" y="${n.y + 15}" class="k">SCREEN</text><text>${lines(n.title, n.x + 10, n.y + 31, 21)}</text></g>`).join('');
|
|
229
241
|
const edges = L.edges.map((e) => { const sc = e.main ? '' : branchOf(e.to); return `<g class="pc-e${e.main ? '' : ' br'}"${sc ? ` data-pc-scen="${esc(sc)}" role="button" tabindex="0" aria-label="${esc('Play ' + (scen.find((x) => x.id === sc) || {}).name)}"` : ''}><path d="${e.d}" marker-end="url(#pcArr)"/>${sc ? `<path class="hit" d="${e.d}"/>` : ''}${e.label ? `<text x="${e.lx}" y="${e.ly}" text-anchor="${e.anchor || 'middle'}">${esc(e.label)}</text>` : ''}</g>`; }).join('');
|
|
230
242
|
const chips = scen.length ? `<div class="pc-scens">${scen.map((s, i) => `<button type="button" class="pc-chip" data-pc-scen="${esc(s.id)}" title="${esc(s.description || '')}">${SVG(I.play, 12)}${esc(i === 0 ? s.name : s.name)}</button>`).join('')}</div>` : '';
|
|
231
|
-
return `<section class="pc-card pc-flowc" aria-label="The flow"><h3>The flow ${upd(c, 'flow')}</h3><div class="pc-svgw"><svg class="pc-flow" width="100%" style="max-width:${L.w}px" viewBox="0 0 ${L.w} ${L.h}" preserveAspectRatio="xMinYMin meet"><defs>${ARROW}</defs>${edges}${nodes}</svg></div>`
|
|
243
|
+
return `<section class="pc-card pc-flowc pc-side" aria-label="The flow"><h3>The flow ${upd(c, 'flow')}${close}</h3><div class="pc-svgw"><svg class="pc-flow" width="100%" style="max-width:${L.w}px" viewBox="0 0 ${L.w} ${L.h}" preserveAspectRatio="xMinYMin meet"><defs>${ARROW}</defs>${edges}${nodes}</svg></div>`
|
|
232
244
|
+ `<p class="pc-hint">Tap a screen to see it on the prototype. Tap a side branch to play that scenario.</p>${chips}</section>`;
|
|
233
245
|
}
|
|
234
246
|
function copyCard(c, v) {
|
|
235
|
-
if (
|
|
236
|
-
const close = ib('data-pc-
|
|
247
|
+
if (V.side !== 'copy') return '';
|
|
248
|
+
const close = ib('data-pc-side="copy"', 'Close the page copy', I.x);
|
|
237
249
|
const copy = (v.data || {}).copy || {}, keys = Object.keys(copy);
|
|
238
250
|
if (!keys.length) return `<section class="pc-card pc-copyc pc-side" aria-label="Page copy"><h3>Page copy ${close}</h3><p class="pc-none">${esc(v.url ? 'This version has no editable copy.' : 'PMOS is writing it.')}</p></section>`;
|
|
239
251
|
const changed = new Set((c.updated && c.updated.keys) || []);
|
|
@@ -241,15 +253,75 @@ function copyCard(c, v) {
|
|
|
241
253
|
+ '<p class="pc-hint">Edit any line: the prototype changes as you type, and the next version keeps it.</p></section>';
|
|
242
254
|
}
|
|
243
255
|
function lanesCard(c, v) {
|
|
256
|
+
if (V.side !== 'lanes') return '';
|
|
257
|
+
const close = ib('data-pc-side="lanes"', 'Close who does what', I.x);
|
|
244
258
|
const l = (v.data || {}).lanes, st = (c.parts || {}).lanes;
|
|
245
|
-
if (!l) return `<section class="pc-card pc-lanesc" aria-label="Who does what"><h3>Who does what</h3><p class="pc-none">${esc(st === 'working' ? 'PMOS is drawing it.' : st && st !== 'ok' ? 'Not made this time: ' + st.replace(/^not made: /, '') : 'No swimlane for this version.')}</p></section>`;
|
|
259
|
+
if (!l) return `<section class="pc-card pc-lanesc pc-side" aria-label="Who does what"><h3>Who does what ${close}</h3><p class="pc-none">${esc(st === 'working' ? 'PMOS is drawing it.' : st && st !== 'ok' ? 'Not made this time: ' + st.replace(/^not made: /, '') : 'No swimlane for this version.')}</p></section>`;
|
|
246
260
|
const L = lanesLayout(l), chg = new Set((c.updated && c.updated.steps) || []);
|
|
247
261
|
const lanes = L.lanes.map((x, i) => `<g class="pc-ln${i % 2 ? ' alt' : ''}"><rect x="0" y="${x.y}" width="${L.w}" height="${LH}"/><text x="12" y="${x.y + LH / 2 + 4}">${esc(x.name.slice(0, 14))}</text></g>`).join('');
|
|
248
262
|
const boxes = L.boxes.map((b) => `<g class="pc-bx${chg.has(b.n) ? ' ch' : ''}${b.screen ? '' : ' ns'}"${b.screen ? ` data-pc-screen="${esc(b.screen)}" role="button" tabindex="0" aria-label="${esc('Show step ' + b.n + ' on the prototype')}"` : ''}><rect x="${b.x}" y="${b.y}" width="${BW}" height="${BH}" rx="8"/><text text-anchor="middle">${lines(b.title, b.x + BW / 2, b.y + (b.title.length > 21 ? 17 : 24), 21, 12)}</text><circle cx="${b.x}" cy="${b.y}" r="9"/><text class="n" x="${b.x}" y="${b.y + 3.5}" text-anchor="middle">${b.n}</text></g>`).join('');
|
|
249
263
|
const arrows = L.arrows.map((a) => `<path class="pc-ar" d="${a.d}" marker-end="url(#pcArr)"/>`).join('');
|
|
250
|
-
return `<section class="pc-card pc-lanesc" aria-label="Who does what"><h3>Who does what ${upd(c, 'lanes')}</h3><div class="pc-svgw"><svg class="pc-lanes" width="100%" style="max-width:${L.w}px" viewBox="0 0 ${L.w} ${L.h}" preserveAspectRatio="xMinYMin meet"><defs>${ARROW}</defs>${lanes}${arrows}${boxes}</svg></div><p class="pc-hint">Tap a step to see it on the prototype.</p></section>`;
|
|
264
|
+
return `<section class="pc-card pc-lanesc pc-side" aria-label="Who does what"><h3>Who does what ${upd(c, 'lanes')}${close}</h3><div class="pc-svgw"><svg class="pc-lanes" width="100%" style="max-width:${L.w}px" viewBox="0 0 ${L.w} ${L.h}" preserveAspectRatio="xMinYMin meet"><defs>${ARROW}</defs>${lanes}${arrows}${boxes}</svg></div><p class="pc-hint">Tap a step to see it on the prototype.</p></section>`;
|
|
251
265
|
}
|
|
252
266
|
|
|
267
|
+
|
|
268
|
+
/* ── design mode: Pages > Screens > Layers, and the inspector ── */
|
|
269
|
+
/** PURE. The left panel's lists from the frame's ready message: pages (data-page, when the run wrote them), the screens of the page shown,
|
|
270
|
+
* and the layers (data-el) of the screen shown. */
|
|
271
|
+
export function layersOf(ready, screen) {
|
|
272
|
+
const S = (ready && ready.screens) || [], E = (ready && ready.els) || [];
|
|
273
|
+
const cur = S.find((x) => x.id === screen) || S[0] || null;
|
|
274
|
+
const pages = [...new Set(S.map((x) => x.page).filter(Boolean))];
|
|
275
|
+
const page = cur && cur.page ? cur.page : '';
|
|
276
|
+
const screens = page ? S.filter((x) => x.page === page) : S;
|
|
277
|
+
const els = E.filter((e) => e.el && (!e.screen || !cur || e.screen === cur.id));
|
|
278
|
+
return { pages, page, screens, screen: cur ? cur.id : '', screenLabel: cur ? cur.label || human(cur.id) : '', els };
|
|
279
|
+
}
|
|
280
|
+
function leftHtml() {
|
|
281
|
+
if (!V.left) return '';
|
|
282
|
+
const hide = ib('data-pc-left', 'Hide pages and layers', I.left);
|
|
283
|
+
if (!V.ready) return `<aside class="pc-left" aria-label="Pages and layers"><div class="pc-lh"><span>Layers</span>${hide}</div><p class="pc-hint">Reading the layers…</p></aside>`;
|
|
284
|
+
const L = layersOf(V.ready, V.screen), row = (attr, on, text, cls = '') => `<button type="button" class="pc-lrow${cls}" ${attr} aria-pressed="${on}">${esc(text)}</button>`;
|
|
285
|
+
const pages = L.pages.length ? `<div class="pc-lh"><span>Pages</span>${hide}</div>${L.pages.map((pg) => row(`data-pc-page="${esc(pg)}"`, pg === L.page, pg)).join('')}` : '';
|
|
286
|
+
const scr = `<div class="pc-lh"><span>Screens${L.page ? ' · ' + esc(L.page) : ''}</span>${L.pages.length ? '' : hide}</div>${L.screens.map((x) => row(`data-pc-screen="${esc(x.id)}"`, x.id === L.screen, x.label || human(x.id))).join('')}`;
|
|
287
|
+
const lay = `<div class="pc-lh"><span>Layers · ${esc(L.screenLabel)}</span></div>${L.els.length ? L.els.map((e) => row(`data-pc-layer="${esc(e.el)}"`, !!(V.sel && V.sel.el === e.el), e.label || human(e.el), ' in')).join('') : '<p class="pc-hint">This screen has no marked layers. Ask in the chat to mark them.</p>'}`;
|
|
288
|
+
return `<aside class="pc-left" aria-label="Pages and layers">${pages}${scr}${lay}</aside>`;
|
|
289
|
+
}
|
|
290
|
+
const FONTS = ['Plus Jakarta Sans', 'Inter', 'Space Grotesk', 'Space Mono', 'IBM Plex Sans', 'Georgia', 'system-ui'];
|
|
291
|
+
const WEIGHTS = [['300', 'Light'], ['400', 'Regular'], ['500', 'Medium'], ['600', 'Semibold'], ['700', 'Bold'], ['800', 'Extra bold']];
|
|
292
|
+
/** PURE. What one layer's styles say in the chat: "56px · Bold" (lib/live-round.js styleWords says the same). */
|
|
293
|
+
export function styleWords(ps) {
|
|
294
|
+
const W = Object.fromEntries(WEIGHTS);
|
|
295
|
+
return Object.entries(ps || {}).map(([k, v]) => (k === 'weight' ? W[v] || v : k === 'size' || k === 'color' ? v : k + ' ' + v)).join(' · ');
|
|
296
|
+
}
|
|
297
|
+
function inspHtml() {
|
|
298
|
+
if (V.side || !V.insp) return '';
|
|
299
|
+
const hide = ib('data-pc-insp', 'Hide the inspector', I.right);
|
|
300
|
+
if (!V.sel) return `<aside class="pc-insp" aria-label="Exact values"><div class="pc-lh"><span>Exact values</span>${hide}</div><p class="pc-hint">Select a layer on the prototype, or in Layers, to set its exact values. For anything else, say it in the chat.</p></aside>`;
|
|
301
|
+
const el = V.sel.el, mine = V.edits.styles[el] || {}, lk = V.looks || {}, val = (k, d = '') => (k in mine ? mine[k] : k in lk ? lk[k] : d);
|
|
302
|
+
const num = (v) => String(parseFloat(v) || 0), colr = (v) => (/^#[0-9a-f]{6}$/i.test(v) ? v : lk.fillPick || '');
|
|
303
|
+
const id = (k) => 'pcS-' + k;
|
|
304
|
+
const fld = (k, label, inner) => `<label class="pc-ir" for="${id(k)}"><span>${label}</span>${inner}</label>`;
|
|
305
|
+
const nIn = (k, unit, step = '1', min = '0', max = '400', part = '') => `<input type="number" id="${id(k + part)}" data-pc-style="${k}"${part ? ` data-pc-part="${part}"` : ''} data-pc-unit="${unit}" step="${step}" min="${min}" max="${max}" value="${esc(num(part ? String(val(k, '0px 0px')).split(' ')[Number(part)] : val(k)))}">`;
|
|
306
|
+
const sel = (k, opts, cur) => `<select id="${id(k)}" data-pc-style="${k}">${opts.map(([v, t]) => `<option value="${esc(v)}"${String(v) === String(cur) ? ' selected' : ''}>${esc(t)}</option>`).join('')}</select>`;
|
|
307
|
+
const fam = val('family'), fonts = FONTS.includes(fam) || !fam ? FONTS : [fam, ...FONTS];
|
|
308
|
+
const copyKey = V.sel.copy || '', copyVal = copyKey ? (copyKey in V.edits.copy ? V.edits.copy[copyKey] : ((V.ready && V.ready.copy) || {})[copyKey] || '') : '';
|
|
309
|
+
const changed = Object.keys(mine).length;
|
|
310
|
+
return `<aside class="pc-insp" aria-label="Exact values"><div class="pc-lh"><span>Exact values · ${esc(V.sel.label || el)}</span>${hide}</div>`
|
|
311
|
+
+ (copyKey ? `<div class="pc-isec">${fld('text', 'Text', `<input type="text" id="${id('text')}" data-pc-copy-in="${esc(copyKey)}" value="${esc(copyVal)}">`)}</div>` : '')
|
|
312
|
+
+ `<div class="pc-isec"><b>Type</b>${fld('family', 'Font', sel('family', fonts.map((f) => [f, f]), fam))}`
|
|
313
|
+
+ `${fld('size', 'Size', nIn('size', 'px', '1', '6', '400'))}${fld('weight', 'Weight', sel('weight', WEIGHTS, val('weight', '400')))}`
|
|
314
|
+
+ `${fld('line', 'Line height', nIn('line', '', '0.05', '0.8', '3'))}${fld('spacing', 'Spacing', nIn('spacing', 'px', '0.1', '-5', '20'))}`
|
|
315
|
+
+ `${fld('color', 'Colour', `<input type="color" id="${id('color')}" data-pc-style="color" value="${esc(colr(val('color')))}">`)}</div>`
|
|
316
|
+
+ `<div class="pc-isec"><b>Box</b>${fld('fill', 'Fill', `<input type="color" id="${id('fill')}" data-pc-style="fill" value="${esc(colr(val('fill')))}">`)}`
|
|
317
|
+
+ `${fld('corner', 'Corner', nIn('corner', 'px', '1', '0', '200'))}`
|
|
318
|
+
+ `<div class="pc-ir"><span>Padding</span><span class="pc-two">${nIn('padding', 'px', '1', '0', '200', '0')}${nIn('padding', 'px', '1', '0', '200', '1')}</span></div>`
|
|
319
|
+
+ `${fld('align', 'Align', sel('align', [['left', 'Left'], ['center', 'Centre'], ['right', 'Right']], val('align', 'left')))}</div>`
|
|
320
|
+
+ `<p class="pc-ifoot">${changed ? `Saved with version ${esc((V.v && V.v.round) || (V.c && V.c.round) || 1)}. The next version keeps it.` : 'Your changes are saved with this version.'}${changed ? ib(`data-pc-unstyle="${esc(el)}"`, 'Undo this layer\'s changes', I.undo) : ''}</p>`
|
|
321
|
+
+ '</aside>';
|
|
322
|
+
}
|
|
323
|
+
function rightHtml(c, v) { return copyCard(c, v) + flowCard(c, v) + lanesCard(c, v) + inspHtml(); }
|
|
324
|
+
|
|
253
325
|
/* ── draw ── */
|
|
254
326
|
/** Draw or update the canvas. body: the Viewer's body; c: GET /api/lab/compare's compare (live); o: { at, H } */
|
|
255
327
|
export function draw(body, c, o = {}) {
|
|
@@ -258,26 +330,35 @@ export function draw(body, c, o = {}) {
|
|
|
258
330
|
if (c.file && c.data) V.last = c;
|
|
259
331
|
const { v, making } = shown(c), prevFile = V.v && V.v.file;
|
|
260
332
|
// a new version: its own edits, nothing pointed at
|
|
261
|
-
if (prevFile !== v.file) {
|
|
333
|
+
if (prevFile !== v.file) { const e = (v.data && v.data.edits) || {}; V.edits = { copy: { ...(e.copy || {}) }, vars: { ...(e.vars || {}) }, styles: { ...(e.styles || {}) } }; V.sel = null; V.looks = null; V.ready = null; }
|
|
262
334
|
V.c = c; V.v = v;
|
|
263
335
|
let root = body.querySelector(':scope > .pc');
|
|
264
336
|
if (!root) { body.innerHTML = '<div class="pc"></div>'; root = body.querySelector('.pc'); wire(root); }
|
|
265
337
|
V.body = body;
|
|
266
338
|
// keep the frame (and what the PM typed) while the canvas reads again every 2 seconds
|
|
267
|
-
const sig = JSON.stringify([c.id, c.key, c.round, c.file, v.file, c.working, c.progress, c.notMade, c.updated, c.parts, (c.comments || []).length, V.mode, V.
|
|
268
|
-
const focus = document.activeElement && root.contains(document.activeElement) && document.activeElement.matches('[data-pc-copy],textarea,input');
|
|
339
|
+
const sig = JSON.stringify([c.id, c.key, c.round, c.file, v.file, c.working, c.progress, c.notMade, c.updated, c.parts, (c.comments || []).length, V.mode, V.sel && V.sel.el, V.looks, !!V.ready, V.screen, V.left, V.insp, V.side, !!V.draft, (c.history || []).length, c.state]);
|
|
340
|
+
const focus = document.activeElement && root.contains(document.activeElement) && document.activeElement.matches('[data-pc-copy],textarea,input,select');
|
|
269
341
|
if (sig === V.sig && root.firstChild) return;
|
|
270
342
|
if (focus && prevFile === v.file) return; // the PM is typing in this version: draw on a later read
|
|
271
343
|
V.sig = sig;
|
|
272
344
|
const frame = root.querySelector('.pc-frame iframe'), keepFrame = frame && V.frameUrl === frameUrl(v);
|
|
273
345
|
const draftText = root.querySelector('#pcCm') ? root.querySelector('#pcCm').value : '';
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
346
|
+
const P = protoCard(c, v, making);
|
|
347
|
+
if (keepFrame) {
|
|
348
|
+
// everything around the frame is drawn again; the frame stays where it is (moving an iframe reloads it)
|
|
349
|
+
const put = (sel, html) => { const n = root.querySelector(sel); if (n) n.innerHTML = html; };
|
|
350
|
+
put('.pc-barw', barHtml(c, v)); put('.pc-trayw', trayHtml(c)); put('.pc-leftw', leftHtml()); put('.pc-rightw', rightHtml(c, v));
|
|
351
|
+
put('.pc-pre', P.pre); put('.pc-post', P.post);
|
|
352
|
+
root.querySelectorAll('.pc-dev > :not(.pc-frame)').forEach((n) => n.remove());
|
|
353
|
+
const dv = root.querySelector('.pc-dev'); if (dv) dv.insertAdjacentHTML('beforeend', P.dev.slice(P.dev.indexOf('</div>') + 6));
|
|
354
|
+
} else {
|
|
355
|
+
root.innerHTML = `<div class="pc-barw">${barHtml(c, v)}</div><div class="pc-trayw">${trayHtml(c)}</div><div class="pc-dbody"><div class="pc-leftw">${leftHtml()}</div>`
|
|
356
|
+
+ `<div class="pc-vp"><div class="pc-board"><section class="pc-card pc-proto" aria-label="The prototype"><div class="pc-pre">${P.pre}</div><div class="pc-dev desktop">${P.dev}</div><div class="pc-post">${P.post}</div></section></div></div>`
|
|
357
|
+
+ `<div class="pc-rightw">${rightHtml(c, v)}</div></div>`;
|
|
358
|
+
const slot = root.querySelector('[data-pc-frame]');
|
|
359
|
+
if (slot && v.url) { V.frameUrl = frameUrl(v); V.ready = null; slot.innerHTML = `<iframe src="${esc(V.frameUrl)}" sandbox="allow-scripts" title="${esc('The prototype, version ' + (v.round || 1))}"></iframe>`; }
|
|
280
360
|
}
|
|
361
|
+
if (!V.play) { const op = root.querySelector('.pc-play'); if (op) op.remove(); }
|
|
281
362
|
if (draftText && root.querySelector('#pcCm')) root.querySelector('#pcCm').value = draftText;
|
|
282
363
|
applyZoom(root);
|
|
283
364
|
if (V.mode === 'draw') ink(root);
|
|
@@ -307,18 +388,24 @@ if (typeof window !== 'undefined') window.addEventListener('message', (e) => {
|
|
|
307
388
|
V.ready = m;
|
|
308
389
|
if (Object.keys(V.edits.copy).length) toFrame({ t: 'copyAll', copy: V.edits.copy });
|
|
309
390
|
if (Object.keys(V.edits.vars).length) toFrame({ t: 'vars', vars: V.edits.vars });
|
|
391
|
+
if (Object.keys(V.edits.styles).length) toFrame({ t: 'styles', styles: V.edits.styles });
|
|
310
392
|
toFrame({ t: 'mode', mode: V.mode === 'draw' ? 'view' : V.mode });
|
|
311
393
|
if (V.screen) toFrame({ t: 'screen', id: V.screen });
|
|
312
394
|
if (V.sel) toFrame({ t: 'sel', el: V.sel.el });
|
|
313
395
|
pins();
|
|
396
|
+
V.sig = ''; draw(V.body, V.c);
|
|
314
397
|
} else if (m.t === 'screen') {
|
|
315
398
|
V.screen = String(m.id || '');
|
|
316
|
-
V.
|
|
399
|
+
V.sig = ''; draw(V.body, V.c);
|
|
317
400
|
} else if (m.t === 'point') {
|
|
318
|
-
//
|
|
319
|
-
V.sel = { el: String(m.el || ''), label: String(m.label || '').slice(0, 80) };
|
|
320
|
-
|
|
401
|
+
// Select (canvas FpA): the layer shows in the inspector with its exact values, and goes in the chat box as the subject of the next words
|
|
402
|
+
V.sel = { el: String(m.el || ''), label: String(m.label || '').slice(0, 80), copy: String(m.copy || '') };
|
|
403
|
+
V.looks = m.looks && typeof m.looks === 'object' ? m.looks : null;
|
|
404
|
+
if (m.screen) V.screen = String(m.screen);
|
|
405
|
+
fire('pmos:point', { ini: V.c && V.c.ini, el: V.sel.el, label: V.sel.label });
|
|
321
406
|
V.sig = ''; draw(V.body, V.c);
|
|
407
|
+
} else if (m.t === 'looks') {
|
|
408
|
+
if (V.sel && m.el === V.sel.el && m.looks && typeof m.looks === 'object') { V.looks = m.looks; V.sig = ''; draw(V.body, V.c); }
|
|
322
409
|
} else if (m.t === 'pin') {
|
|
323
410
|
V.draft = { el: String(m.el || ''), label: String(m.label || '').slice(0, 80), x: m.x, y: m.y };
|
|
324
411
|
V.sig = ''; draw(V.body, V.c);
|
|
@@ -331,12 +418,20 @@ function wire(root) {
|
|
|
331
418
|
const b = e.target.closest('button, [data-pc-screen], [data-pc-scen]'); if (!b || !root.contains(b)) return;
|
|
332
419
|
const d = b.dataset;
|
|
333
420
|
if (d.pcMode) { setMode(V.mode === d.pcMode ? 'view' : d.pcMode); return; }
|
|
334
|
-
if (
|
|
335
|
-
if (d
|
|
421
|
+
if (d.pcSide) { V.side = V.side === d.pcSide ? null : d.pcSide; V.sig = ''; draw(V.body, V.c); return; }
|
|
422
|
+
if ('pcLeft' in d) { panel('left'); return; }
|
|
423
|
+
if ('pcInsp' in d) { panel('insp'); return; }
|
|
424
|
+
if (d.pcPage) { const L = layersOf(V.ready, V.screen), first = ((V.ready && V.ready.screens) || []).find((x) => x.page === d.pcPage); if (first && first.id !== L.screen) { V.screen = first.id; toFrame({ t: 'screen', id: first.id }); } return; }
|
|
425
|
+
if (d.pcLayer) { pick(d.pcLayer); return; }
|
|
426
|
+
if (d.pcUnstyle) { unstyle(d.pcUnstyle); return; }
|
|
427
|
+
if (d.pcPdev) { V.pdev = d.pcPdev; store.set('pmos.pc.pdev', V.pdev); startPlay(V.play.id, V.play.i); return; }
|
|
428
|
+
if ('pcPflow' in d) { V.play.flow = !V.play.flow; startPlay(V.play.id, V.play.i); return; }
|
|
429
|
+
if (d.pcPstep != null) { startPlay(V.play.id, Number(d.pcPstep)); return; }
|
|
430
|
+
if (d.pcPnav) { playStep(Number(d.pcPnav)); return; }
|
|
336
431
|
if (d.pcZoom != null) { const k = Number(d.pcZoom); V.zoom = k === 0 ? 0 : Math.max(0.4, Math.min(1.6, Math.round(((V.zoom || currentZoom()) + k * 0.1) * 10) / 10)); store.set('pmos.pc.zoom', V.zoom ? String(V.zoom) : null); applyZoom(root); return; }
|
|
337
432
|
if ('pcPlay' in d) { const sc = ((V.v.data || {}).flow || {}).scenarios || []; startPlay(sc.length ? sc[0].id : '', 0, true); return; }
|
|
338
433
|
if (d.pcFrom) { fire('pmos:from', { ini: V.c.ini, n: Number(d.pcFrom) }); say('The next change you send continues from version ' + d.pcFrom + '.'); return; }
|
|
339
|
-
if (d.pcScreen) { V.screen = d.pcScreen; toFrame({ t: 'screen', id: d.pcScreen }); return; }
|
|
434
|
+
if (d.pcScreen) { V.screen = d.pcScreen; toFrame({ t: 'screen', id: d.pcScreen }); V.sig = ''; draw(V.body, V.c); return; }
|
|
340
435
|
if (d.pcScen) { startPlay(d.pcScen, 0, true); return; }
|
|
341
436
|
if ('pcStop' in d) { pmPost('/api/lab/stop', { ws: (V.at || {}).ws, run: d.pcStop }).then((r) => { if (!r || !r.ok) say((r && r.error) || 'It did not stop.'); }).catch(() => say('It did not stop.')); return; }
|
|
342
437
|
if ('pcUnsel' in d) { V.sel = null; toFrame({ t: 'sel', el: '' }); fire('pmos:point', { ini: V.c.ini, el: '', label: '' }); V.sig = ''; draw(V.body, V.c); return; }
|
|
@@ -346,12 +441,15 @@ function wire(root) {
|
|
|
346
441
|
if (d.pcInk) { if (d.pcInk === 'clear') clearInk(); else attachInk(); return; }
|
|
347
442
|
if (d.pcTray) { tray(d.pcTray); return; }
|
|
348
443
|
if (d.pcPlayx) { if (d.pcPlayx === 'close') { V.play = null; const p = root.querySelector('.pc-play'); if (p) p.remove(); } else startPlay(V.play.id, 0); return; }
|
|
349
|
-
if (d.pcPlaysc) { startPlay(d.pcPlaysc, 0, true); }
|
|
350
444
|
});
|
|
445
|
+
// a number or a list takes effect when it is changed (an arrow press, Enter, leaving the field), not on every key
|
|
446
|
+
root.addEventListener('change', (e) => { const t = e.target; if (t.matches('[data-pc-style]') && (t.type === 'number' || t.tagName === 'SELECT')) style(t); else if (t.matches('[data-pc-playsel]')) startPlay(t.value, 0, false); });
|
|
351
447
|
root.addEventListener('keydown', (e) => { if ((e.key === 'Enter' || e.key === ' ') && e.target.matches('[data-pc-screen],[data-pc-scen]') && e.target.tagName !== 'BUTTON') { e.preventDefault(); e.target.dispatchEvent(new MouseEvent('click', { bubbles: true })); } });
|
|
352
448
|
root.addEventListener('input', (e) => {
|
|
353
449
|
const t = e.target;
|
|
354
450
|
if (t.matches('[data-pc-copy]')) { const k = t.dataset.pcCopy, text = t.textContent; V.edits.copy[k] = text; toFrame({ t: 'copy', key: k, text }); save({ copy: { [k]: text } }); }
|
|
451
|
+
else if (t.matches('[data-pc-copy-in]')) { const k = t.dataset.pcCopyIn, text = t.value; V.edits.copy[k] = text; toFrame({ t: 'copy', key: k, text }); save({ copy: { [k]: text } }); }
|
|
452
|
+
else if (t.matches('[data-pc-style]') && t.type !== 'number' && t.tagName !== 'SELECT') style(t);
|
|
355
453
|
else if (t.matches('[data-pc-var]')) { const val = t.value + (t.dataset.pcUnit || ''); V.edits.vars[t.dataset.pcVar] = val; toFrame({ t: 'vars', vars: { [t.dataset.pcVar]: val } }); const em = t.parentElement.querySelector('em'); if (em) em.textContent = val; save({ vars: { [t.dataset.pcVar]: val } }); }
|
|
356
454
|
});
|
|
357
455
|
}
|
|
@@ -361,9 +459,49 @@ function setMode(m) {
|
|
|
361
459
|
toFrame({ t: 'mode', mode: m === 'draw' ? 'view' : m });
|
|
362
460
|
V.sig = ''; draw(V.body, V.c);
|
|
363
461
|
}
|
|
364
|
-
|
|
462
|
+
function panel(k) {
|
|
463
|
+
if (k === 'insp' && V.side) { V.side = null; V.insp = true; } else V[k] = !V[k];
|
|
464
|
+
store.set(k === 'left' ? 'pmos.pc.left' : 'pmos.pc.insp', V[k] ? null : '0');
|
|
465
|
+
V.sig = ''; draw(V.body, V.c);
|
|
466
|
+
}
|
|
467
|
+
/** A layer picked in Layers: selected on the prototype, its looks read back, and in the chat box as the subject. */
|
|
468
|
+
function pick(el) {
|
|
469
|
+
const e = ((V.ready && V.ready.els) || []).find((x) => x.el === el); if (!e) return;
|
|
470
|
+
V.sel = { el, label: String(e.label || '').slice(0, 80), copy: String(e.copy || '') }; V.looks = null;
|
|
471
|
+
toFrame({ t: 'sel', el }); toFrame({ t: 'styles', styles: V.edits.styles });
|
|
472
|
+
fire('pmos:point', { ini: V.c && V.c.ini, el, label: V.sel.label });
|
|
473
|
+
V.sig = ''; draw(V.body, V.c);
|
|
474
|
+
}
|
|
475
|
+
/** One inspector field changed: the prototype changes at once, the value is kept with the version, and the chat hears it once. */
|
|
476
|
+
function style(t) {
|
|
477
|
+
if (!V.sel) return;
|
|
478
|
+
const el = V.sel.el, k = t.dataset.pcStyle, unit = t.dataset.pcUnit || '';
|
|
479
|
+
let val = t.type === 'number' ? (Number.isFinite(parseFloat(t.value)) ? String(Math.round(parseFloat(t.value) * 100) / 100) + unit : '') : t.value;
|
|
480
|
+
if (k === 'padding') {
|
|
481
|
+
const two = [...V.body.querySelectorAll('[data-pc-style="padding"]')].map((x) => Math.max(0, Math.round(parseFloat(x.value) || 0)) + 'px');
|
|
482
|
+
val = two.join(' ');
|
|
483
|
+
}
|
|
484
|
+
if (k === 'size' || k === 'corner') val = Math.max(0, Math.round(parseFloat(val) || 0)) + 'px';
|
|
485
|
+
if (!val) return;
|
|
486
|
+
V.edits.styles[el] = { ...(V.edits.styles[el] || {}), [k]: val };
|
|
487
|
+
toFrame({ t: 'styles', styles: V.edits.styles });
|
|
488
|
+
save({ styles: { [el]: { [k]: val } } });
|
|
489
|
+
clearTimeout(V.noteT);
|
|
490
|
+
const label = V.sel.label || el;
|
|
491
|
+
V.noteT = setTimeout(() => fire('pmos:note', { ini: V.c && V.c.ini, text: `You set ${label} to ${styleWords(V.edits.styles[el])}. Kept as yours.` }), 1500);
|
|
492
|
+
const f = V.body.querySelector('.pc-ifoot'); if (f && !f.querySelector('[data-pc-unstyle]')) { V.sig = ''; setTimeout(() => draw(V.body, V.c), 0); }
|
|
493
|
+
}
|
|
494
|
+
function unstyle(el) {
|
|
495
|
+
delete V.edits.styles[el];
|
|
496
|
+
toFrame({ t: 'styles', styles: V.edits.styles });
|
|
497
|
+
save({ styles: { [el]: null } });
|
|
498
|
+
V.sig = ''; draw(V.body, V.c);
|
|
499
|
+
}
|
|
500
|
+
// the PM's copy edits, tweaks and inspector styles are kept with the version (edits.json), so the next version reads them
|
|
365
501
|
function save(part) {
|
|
366
|
-
|
|
502
|
+
const st = { ...((V.pend && V.pend.styles) || {}) };
|
|
503
|
+
for (const [el, ps] of Object.entries(part.styles || {})) st[el] = ps === null ? null : { ...(st[el] || {}), ...ps };
|
|
504
|
+
V.pend = { copy: { ...((V.pend && V.pend.copy) || {}), ...(part.copy || {}) }, vars: { ...((V.pend && V.pend.vars) || {}), ...(part.vars || {}) }, styles: st };
|
|
367
505
|
clearTimeout(V.saveT);
|
|
368
506
|
const file = V.v && V.v.file;
|
|
369
507
|
V.saveT = setTimeout(async () => {
|
|
@@ -429,22 +567,49 @@ async function attachInk() {
|
|
|
429
567
|
clearInk(); setMode('view');
|
|
430
568
|
}
|
|
431
569
|
|
|
432
|
-
/* ── Play (canvas
|
|
570
|
+
/* ── Play (canvas FpC): the prototype bare, the device switch, the flow beside it as steps you can tap, ← → ── */
|
|
433
571
|
function playHtml(v) {
|
|
434
|
-
const
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
+ `<
|
|
572
|
+
const f = (v.data || {}).flow || {}, sc = f.scenarios || [], p = V.play, s = sc.find((x) => x.id === p.id) || null;
|
|
573
|
+
const n = s ? s.steps.length : 0, i = Math.min(p.i, Math.max(0, n - 1)), step = s ? s.steps[i] : null;
|
|
574
|
+
const title = (id) => { const x = (f.screens || []).find((y) => y.id === id); return x ? x.title : human(id); };
|
|
575
|
+
const dev = (d, label, icon) => `<button type="button" class="pc-ib" data-pc-pdev="${d}" aria-pressed="${V.pdev === d}" aria-label="${esc(label)}" title="${esc(label)}">${SVG(icon, 16)}</button>`;
|
|
576
|
+
const flow = p.flow === false ? '' : `<aside class="pc-pflow" aria-label="The flow"><div class="pc-lh"><span>The flow</span></div>`
|
|
577
|
+
+ (sc.length ? `<label class="pc-psel"><span class="pc-vh">Path</span><select data-pc-playsel aria-label="Pick a path">${sc.map((x) => `<option value="${esc(x.id)}"${x.id === p.id ? ' selected' : ''}>${esc(x.name)}</option>`).join('')}</select></label>`
|
|
578
|
+
+ `<span class="pc-bar2" aria-hidden="true"><i style="width:${n ? Math.round(((i + 1) / n) * 100) : 0}%"></i></span>`
|
|
579
|
+
+ `<ol class="pc-psteps">${(s ? s.steps : []).map((x, k) => `<li><button type="button" class="pc-pst${k < i ? ' done' : ''}${k === i ? ' on' : ''}" data-pc-pstep="${k}"${k === i ? ' aria-current="step"' : ''}><span class="pc-pn">${k < i ? SVG(I.check, 12, 3) : k + 1}</span><span>${esc(title(x.screen))}</span></button></li>`).join('')}</ol>`
|
|
580
|
+
: '<p class="pc-hint">This version has no flow yet. Ask for one in the chat.</p>') + '</aside>';
|
|
581
|
+
return `<div class="pc-play" role="dialog" aria-label="Play the prototype"><div class="pc-pbar"><b>Playing · Version ${esc(v.round || 1)}</b><small>${step ? esc(title(step.screen)) : ''}</small><span class="pc-sp"></span>`
|
|
582
|
+
+ `<span class="pc-grp" aria-label="Play on">${dev('phone', 'Play on a phone', I.phone)}${dev('desktop', 'Play on a desktop', I.desk)}${dev('own', 'Play at its own size', I.own)}</span>`
|
|
583
|
+
+ `${ib(`data-pc-pflow aria-pressed="${p.flow !== false}"`, (p.flow === false ? 'Show' : 'Hide') + ' the flow', I.right)}${ib('data-pc-playx="close"', 'Stop playing (Esc)', I.x)}</div>`
|
|
584
|
+
+ `<div class="pc-pmain"><div class="pc-pstage"><div class="pc-pframe ${V.pdev}">${v.url ? `<iframe src="${esc(frameUrl(v))}" sandbox="allow-scripts" title="Play the prototype"></iframe>` : ''}</div>`
|
|
585
|
+
+ `<div class="pc-pctl">${ib('data-pc-pnav="-1"' + (i > 0 ? '' : ' disabled'), 'Previous step (←)', I.prev)}<span>${s ? `Step ${i + 1} of ${n}` : 'No steps'}</span>${ib('data-pc-pnav="1"' + (s && i < n - 1 ? '' : ' disabled'), 'Next step (→)', I.next, 'blue')}${ib('data-pc-playx="restart"', 'Restart', I.restart)}</div>`
|
|
586
|
+
+ `<p class="pc-hint">${step && step.say ? esc(step.say) + ' ' : ''}← → to move. On a screen with taps, a tap that misses shows where to tap.</p></div>${flow}</div></div>`;
|
|
440
587
|
}
|
|
441
588
|
function startPlay(id, i = 0, fresh = false) {
|
|
442
589
|
const root = V.body && V.body.querySelector('.pc'); if (!root) return;
|
|
443
|
-
const
|
|
444
|
-
V.play = { id, i };
|
|
445
|
-
const old = root.querySelector('.pc-play');
|
|
590
|
+
const keepF = !fresh && V.play ? root.querySelector('.pc-pframe iframe') : null;
|
|
591
|
+
V.play = { id, i: Math.max(0, i), flow: V.play ? V.play.flow : true };
|
|
592
|
+
const old = root.querySelector('.pc-play');
|
|
593
|
+
if (old && keepF) {
|
|
594
|
+
// the frame stays where it is (moving an iframe reloads it): only the bar, the controls and the flow are drawn again
|
|
595
|
+
const tmp = document.createElement('div'); tmp.innerHTML = playHtml(V.v);
|
|
596
|
+
const nu = tmp.firstElementChild;
|
|
597
|
+
old.querySelector('.pc-pbar').replaceWith(nu.querySelector('.pc-pbar'));
|
|
598
|
+
old.querySelector('.pc-pctl').replaceWith(nu.querySelector('.pc-pctl'));
|
|
599
|
+
old.querySelector('.pc-pstage > .pc-hint').replaceWith(nu.querySelector('.pc-pstage > .pc-hint'));
|
|
600
|
+
const of = old.querySelector('.pc-pflow'), nf = nu.querySelector('.pc-pflow');
|
|
601
|
+
if (of && nf) of.replaceWith(nf); else if (of) of.remove(); else if (nf) old.querySelector('.pc-pmain').appendChild(nf);
|
|
602
|
+
old.querySelector('.pc-pframe').className = 'pc-pframe ' + V.pdev;
|
|
603
|
+
playGo(keepF);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (old) old.remove();
|
|
446
607
|
root.insertAdjacentHTML('beforeend', playHtml(V.v));
|
|
447
|
-
|
|
608
|
+
}
|
|
609
|
+
function playStep(d) {
|
|
610
|
+
if (!V.play) return;
|
|
611
|
+
const s = (((V.v.data || {}).flow || {}).scenarios || []).find((x) => x.id === V.play.id); if (!s) return;
|
|
612
|
+
const i = Math.max(0, Math.min(s.steps.length - 1, V.play.i + d)); if (i !== V.play.i) startPlay(V.play.id, i);
|
|
448
613
|
}
|
|
449
614
|
function playGo(fr) {
|
|
450
615
|
const sc = ((V.v.data || {}).flow || {}).scenarios || [], s = sc.find((x) => x.id === (V.play || {}).id);
|
|
@@ -480,7 +645,10 @@ if (typeof window !== 'undefined') {
|
|
|
480
645
|
if (!V.body || !V.body.isConnected || !V.body.querySelector('.pc') || e.metaKey || e.ctrlKey || e.altKey) return;
|
|
481
646
|
const t = e.target; if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return;
|
|
482
647
|
const k = e.key.toLowerCase();
|
|
483
|
-
if (k === '
|
|
648
|
+
if (V.play && (k === 'arrowleft' || k === 'arrowright')) { e.preventDefault(); playStep(k === 'arrowright' ? 1 : -1); return; }
|
|
649
|
+
if (k === '[' && !V.play) { panel('left'); return; }
|
|
650
|
+
if (k === ']' && !V.play) { panel('insp'); return; }
|
|
651
|
+
if (k === 'v' || k === 's') setMode(V.mode === 'point' ? 'view' : 'point');
|
|
484
652
|
else if (k === 'c') setMode(V.mode === 'comment' ? 'view' : 'comment');
|
|
485
653
|
else if (k === 'd') setMode(V.mode === 'draw' ? 'view' : 'draw');
|
|
486
654
|
else if (k === 'escape' && (V.mode !== 'view' || V.play)) { if (V.play) { V.play = null; const p = V.body.querySelector('.pc-play'); if (p) p.remove(); } else setMode('view'); }
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/* cozy-relay.js — Settings › Connectors › Listening (initiative event-relay; D110; design "Connectors directory and events", board CnC).
|
|
2
|
+
*
|
|
3
|
+
* GitHub and Jira can send events to the central host; PMOS pulls them each minute and starts a read of that service. An event only starts a
|
|
4
|
+
* read: it never changes a record. Each row: the service, what it does now (Listening · the last event, or Reads on its schedule), and icon
|
|
5
|
+
* buttons: listen, show the steps again, stop. The steps show the address and the secret with a copy button each, for the PM to paste into
|
|
6
|
+
* GitHub or Jira; PMOS sends nothing to those services.
|
|
7
|
+
*
|
|
8
|
+
* relayState() -> a fresh state object for one Settings dialog
|
|
9
|
+
* relayLoad(R) GET /api/relay
|
|
10
|
+
* relayHtml(R) -> the Listening block (a slot under the Connectors rows)
|
|
11
|
+
* relayClick(e, R, redraw, toast) -> true when the press was one of this block's; runs the press
|
|
12
|
+
* Routes: lib/routes-relay.js. UI copy says PMOS. */
|
|
13
|
+
import { pmGet, pmPost } from './http.js';
|
|
14
|
+
import { esc, svg } from './cozy-evui.js';
|
|
15
|
+
|
|
16
|
+
const LABEL = { github: 'GitHub', jira: 'Jira' };
|
|
17
|
+
const BELL = 'M6 16V11a6 6 0 0 1 12 0v5l2 2H4zM10 20a2 2 0 0 0 4 0';
|
|
18
|
+
const OFF = 'M6 16V11a6 6 0 0 1 9.5-4.9M18 11v5l2 2H8M10 20a2 2 0 0 0 4 0M3 3l18 18';
|
|
19
|
+
const STEPS = 'M9 6h11M9 12h11M9 18h11M4 6h.01M4 12h.01M4 18h.01';
|
|
20
|
+
const COPY = 'M9 9h11v11H9zM5 15V5a1 1 0 0 1 1-1h10';
|
|
21
|
+
function ago(iso) {
|
|
22
|
+
const t = Date.parse(iso); if (!Number.isFinite(t)) return '';
|
|
23
|
+
const m = Math.round((Date.now() - t) / 60000);
|
|
24
|
+
if (m < 1) return 'just now'; if (m < 60) return m + ' min ago';
|
|
25
|
+
const h = Math.round(m / 60); if (h < 24) return h + ' h ago';
|
|
26
|
+
return Math.round(h / 24) + ' d ago';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function relayState() { return { st: null, open: null, steps: null, busy: false }; }
|
|
30
|
+
|
|
31
|
+
export async function relayLoad(R) {
|
|
32
|
+
const r = await pmGet('/api/relay');
|
|
33
|
+
R.st = r && r.ok ? r : { ok: false };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ib = (act, src, icon, label) => `<button type="button" class="ev-ib" data-rl="${act}" data-rls="${esc(src)}" aria-label="${esc(label)}" title="${esc(label)}">${svg(icon, 18)}</button>`;
|
|
37
|
+
|
|
38
|
+
export function relayHtml(R) {
|
|
39
|
+
const st = R.st;
|
|
40
|
+
if (st === null) return '';
|
|
41
|
+
const head = '<h4 id="evListen">Listening</h4>';
|
|
42
|
+
if (!st.ok) return `<div data-relay>${head}<p class="ev-small ev-mut">The listening settings could not be read.</p></div>`;
|
|
43
|
+
const rows = Object.keys(LABEL).map((k) => {
|
|
44
|
+
const s = (st.sources && st.sources[k]) || { listening: false };
|
|
45
|
+
const what = s.listening ? 'Listening · ' + (s.last ? 'last event ' + ago(s.last) : 'no event yet') : 'Reads on its schedule';
|
|
46
|
+
const acts = s.listening ? ib('steps', k, STEPS, 'Show the ' + LABEL[k] + ' steps') + ib('stop', k, OFF, 'Stop listening to ' + LABEL[k]) : ib('setup', k, BELL, 'Listen for ' + LABEL[k] + ' events');
|
|
47
|
+
let panel = '';
|
|
48
|
+
if (R.open === k && R.steps && R.steps.source === k) {
|
|
49
|
+
panel = `<div class="ev-rl-steps ev-small" data-rl-panel="${esc(k)}"><ol>${R.steps.steps.map((x) => `<li>${esc(x)}</li>`).join('')}</ol>`
|
|
50
|
+
+ `<div class="ev-rl-kv"><b>Address</b><code>${esc(R.steps.url)}</code>${ib('copy-url', k, COPY, 'Copy the address')}</div>`
|
|
51
|
+
+ `<div class="ev-rl-kv"><b>Secret</b><code>${esc(R.steps.secret)}</code>${ib('copy-secret', k, COPY, 'Copy the secret')}</div></div>`;
|
|
52
|
+
}
|
|
53
|
+
return `<div class="ev-trow ev-fr" data-rl-row="${esc(k)}"><span class="ev-gut">${s.listening ? '<i class="ev-dot ok" aria-hidden="true"></i>' : ''}</span><div class="ev-tx ev-grow"><span>${esc(LABEL[k])}</span><p class="ev-small ev-mut">${esc(what)}</p></div><span class="ev-rl-acts">${acts}</span></div>${panel}`;
|
|
54
|
+
}).join('');
|
|
55
|
+
const recent = (st.recent || []).slice(0, 5);
|
|
56
|
+
const ev = recent.length ? `<ul class="ev-rl-ev ev-small ev-mut" aria-label="Recent events">${recent.map((e) => `<li>${esc(LABEL[e.source] || e.source)} · ${esc(e.kind)}${e.key ? ' · ' + esc(e.key) : ''} · ${esc(ago(e.at))}</li>`).join('')}</ul>` : '';
|
|
57
|
+
const host = st.host ? '' : '<p class="ev-small ev-late">Listening needs the central host. Set its address in Board › Publish first.</p>';
|
|
58
|
+
return `<div data-relay>${head}<p class="ev-small ev-mut">A service that sends events is read within a minute of a change, even while this computer sleeps. An event only starts a read; it never changes your records.</p>${host}${rows}${ev}</div>`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function relayClick(e, R, redraw, toast) {
|
|
62
|
+
const b = e.target.closest('[data-rl]'); if (!b) return false;
|
|
63
|
+
if (R.busy) return true;
|
|
64
|
+
const act = b.dataset.rl, src = b.dataset.rls, name = LABEL[src] || src;
|
|
65
|
+
const say = (t) => { if (toast) toast(t); };
|
|
66
|
+
if (act === 'copy-url' || act === 'copy-secret') {
|
|
67
|
+
const v = R.steps ? (act === 'copy-url' ? R.steps.url : R.steps.secret) : '';
|
|
68
|
+
try { await navigator.clipboard.writeText(v); say(act === 'copy-url' ? 'Address copied.' : 'Secret copied.'); } catch { say('Select it and copy it by hand.'); }
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (act === 'steps' && R.open === src) { R.open = null; R.steps = null; redraw(); return true; }
|
|
72
|
+
R.busy = true;
|
|
73
|
+
const r = await pmPost('/api/relay/' + (act === 'setup' ? 'setup' : act === 'stop' ? 'stop' : 'steps'), { source: src });
|
|
74
|
+
R.busy = false;
|
|
75
|
+
if (!r || r.ok === false) { say((r && r.error) || 'Not done.'); return true; }
|
|
76
|
+
if (act === 'stop') { R.open = null; R.steps = null; say('PMOS stopped listening to ' + name + '. It reads it on its schedule.'); }
|
|
77
|
+
else { R.open = src; R.steps = r; if (act === 'setup') say('Paste the address and the secret into ' + name + '.'); }
|
|
78
|
+
await relayLoad(R); redraw();
|
|
79
|
+
return true;
|
|
80
|
+
}
|