create-pmos 0.388.0 → 0.390.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 +25 -30
- package/payload/KIT-VERSION +2 -2
- 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/payload/state/log.md +1 -1
- package/workspace/briefing-premium-insights-test.js +22 -27
- package/workspace/changelog.json +24 -0
- package/workspace/guide/briefing-premium.md +38 -19
- package/workspace/lib/briefing-premium-agent.js +3 -0
- package/workspace/lib/insights-premium.js +10 -8
- package/workspace/lib/report-chat.js +37 -0
- package/workspace/lib/routes-insights-premium.js +3 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-chat-chart-tab-test.js +150 -0
- package/workspace/premium-chat-report-tab-test.js +127 -0
- package/workspace/premium-report-read-test.js +99 -59
- package/workspace/premium-vw-slides-test.js +17 -19
- package/workspace/public/pm/goal-chat.js +2 -1
- package/workspace/public/pm/premium-chart-draw.js +58 -0
- package/workspace/public/pm/premium-chart-tab.js +157 -0
- package/workspace/public/pm/premium-chat.js +8 -2
- package/workspace/public/pm/premium-insights.js +39 -85
- package/workspace/public/pm/premium-report-brief.js +132 -0
- package/workspace/public/pm/premium-report-read.js +276 -103
- package/workspace/public/pm/premium-report-tab.js +235 -0
- package/workspace/public/pm/premium-shell.js +35 -3
- package/workspace/public/pm/premium-vw-doc.js +9 -1
- package/workspace/public/pm/premium-vw-report.css +60 -0
- package/workspace/public/pm/premium-vw-slides.js +14 -5
- package/workspace/public/pm/premium.css +71 -122
- package/workspace/public/pm/report-chat.js +89 -0
- package/workspace/test-lists/premium-chat-chart-tab.json +12 -0
- package/workspace/test-lists/premium-chat-report-tab.json +12 -0
- package/workspace/premium-studio-chart-test.js +0 -193
- package/workspace/premium-studio-report-test.js +0 -277
- package/workspace/premium-studio-test.js +0 -185
- package/workspace/public/pm/premium-studio-design.js +0 -298
- package/workspace/public/pm/premium-studio-report.js +0 -291
- package/workspace/public/pm/premium-studio.js +0 -453
- package/workspace/test-lists/premium-studio-chart.json +0 -13
- package/workspace/test-lists/premium-studio-report.json +0 -9
- package/workspace/test-lists/premium-studio.json +0 -9
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
/* pm/premium-studio-design.js — the Design step of a set-up report in the Insight Studio (initiative premium-studio-design). The console's Design studio
|
|
2
|
-
* (c3-design-studio.js) on the premium page: the versions D1 to Dn of the report's look, the slides of the one shown, the samples the look follows, and
|
|
3
|
-
* This is it. premium-studio-report.js hands a set-up report's Design tab to this module: the brief, its tray, the preview, the checks, the footer and
|
|
4
|
-
* the conversation. A report's Structure (what it says) and its Design (how it looks) are two tabs of the same report.
|
|
5
|
-
*
|
|
6
|
-
* READS: GET /api/report-design (versions, samples, log, saved) and GET /api/report-design/version (one sanitized render).
|
|
7
|
-
* WRITES: the report-design describe, sample, unsample, turn, accept and revert routes only, each a press on the page behind the launch nonce.
|
|
8
|
-
* A render is HTML the server sanitized; it is shown in a frame with an empty sandbox, so nothing in it runs. Nothing is sent outward. */
|
|
9
|
-
import { $, esc } from './premium-shell.js';
|
|
10
|
-
import { splitRender, slideCard, fit } from './premium-report-read.js';
|
|
11
|
-
|
|
12
|
-
const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
|
|
13
|
-
const PREV = ICO('<path d="m15 6-6 6 6 6"/>'), NEXT = ICO('<path d="m9 6 6 6-6 6"/>'), PLUS = ICO('<path d="M12 5v14M5 12h14"/>'), CHK = ICO('<path d="M5 12.5l4.5 4.5L19 7.5"/>'), XI = ICO('<path d="M6 6l12 12M18 6 6 18"/>');
|
|
14
|
-
const KINDS = { pdf: 'pdf', pptx: 'pptx', docx: 'docx', png: 'image', jpg: 'image', jpeg: 'image' };
|
|
15
|
-
const SWORD = { pdf: 'PDF', pptx: 'PowerPoint', docx: 'Word', image: 'Image', pictures: 'Page pictures', link: 'Link', 'pmos-doc': 'Past PMOS document' };
|
|
16
|
-
const POLL_MS = 800, POLL_MAX = 240000;
|
|
17
|
-
const HELPD = 'Tell me how it should look, for example: use the theme of my picture, denser, like slide 3 of my sample. Add a sample first if you have one. PMOS makes the next version; nothing is kept until you press This is it.';
|
|
18
|
-
const q = (o) => Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
|
|
19
|
-
|
|
20
|
-
let X = null; // the Studio's hand, as premium-studio-report.js gets it
|
|
21
|
-
export function useStudio(x) { X = x; }
|
|
22
|
-
const hand = () => X.P.design;
|
|
23
|
-
|
|
24
|
-
/* ── the state of one report's design, kept on its draft: d.D = { design, err, loading, shown, ver: Map, i } ── */
|
|
25
|
-
export function fresh() { return { fmt: null, design: null, err: '', loading: false, shown: null, ver: new Map(), i: 0, working: false, link: '', points: [], point: true, cmp: false, cmpB: null }; }
|
|
26
|
-
const FMTN = { deck: 'Deck', doc: 'Document' };
|
|
27
|
-
const fmtOf = (z) => z.fmt || (z.design && z.design.format) || 'deck';
|
|
28
|
-
const saved = (z) => (z.design && z.design.saved ? z.design.saved.version : null);
|
|
29
|
-
const versions = (z) => (z.design && z.design.versions) || [];
|
|
30
|
-
const slidesAt = (z, n) => { const r = z.ver.get(n); return r ? r.slides.map((s) => ({ k: 'frame', h: s.h, id: ((/data-slide-id="([^"]*)"/.exec(s.html) || [])[1]) || '', html: s.html, css: r.style })) : []; };
|
|
31
|
-
const slidesOf = (z) => slidesAt(z, z.shown);
|
|
32
|
-
|
|
33
|
-
export async function load(d) {
|
|
34
|
-
const z = d.Z; z.loading = true;
|
|
35
|
-
const res = await hand().get(d.id);
|
|
36
|
-
if (X.r() !== d) return;
|
|
37
|
-
z.loading = false;
|
|
38
|
-
if (!res || res.ok !== true) { z.err = (res && res.error) || 'The design of this report could not be read.'; X.draw(); return; }
|
|
39
|
-
z.design = res.design; z.err = '';
|
|
40
|
-
if (!z.fmt || !versions(z).length) z.fmt = z.design.format || 'deck';
|
|
41
|
-
const cur = z.design.current != null ? z.design.current : saved(z);
|
|
42
|
-
if (z.shown == null) z.shown = cur;
|
|
43
|
-
if (z.shown != null) await read(z, z.shown);
|
|
44
|
-
X.restream(chat(d));
|
|
45
|
-
if (z.design.running) { z.working = true; X.draw(); wait(d, z.design.log.length).then((a) => { if (X.r() === d && d.tab === 'design') X.say(a); }); return; }
|
|
46
|
-
X.draw();
|
|
47
|
-
}
|
|
48
|
-
async function read(z, n) {
|
|
49
|
-
if (z.ver.has(n)) return;
|
|
50
|
-
try { const r = await fetch('/api/report-design/version?' + q({ ws: X.P.M.board.ws, id: X.r().id, n }), { credentials: 'same-origin' }); if (r.ok) z.ver.set(n, splitRender(await r.text())); } catch { /* shown as unread */ }
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/* ── the conversation: what the design log says, as the console shows it ── */
|
|
54
|
-
const GREET = (d) => 'This is the design of "' + d.name + '": how each cycle looks. Add a sample, or say what you want, and I make a version. Press This is it on the one you want. Nothing is sent.';
|
|
55
|
-
export function chat(d) {
|
|
56
|
-
const L = ((d.Z.design && d.Z.design.log) || []).map((l) => ({ who: l.who === 'pmos' ? 'a' : 'u', text: l.kind === 'sample' ? 'Added the sample "' + l.text + '".' : l.text }));
|
|
57
|
-
return [{ who: 'a', text: GREET(d) }].concat(L);
|
|
58
|
-
}
|
|
59
|
-
export const help = () => HELPD;
|
|
60
|
-
export const guide = (d) => 'Shape how ' + esc(d.name) + ' looks. <button type="button" class="lk" data-st="rtab|structure">Back to the structure</button>';
|
|
61
|
-
|
|
62
|
-
/* ── the tabs of a set-up report ── */
|
|
63
|
-
export const tabs = (d) => `<div class="stmd stsub" role="group" aria-label="Step of this report"><button type="button" data-st="rtab|structure" aria-pressed="${d.tab !== 'design'}">1 Structure</button><button type="button" data-st="rtab|design" aria-pressed="${d.tab === 'design'}">2 Design</button></div>`;
|
|
64
|
-
export async function openTab(d, tab) {
|
|
65
|
-
if (d.tab === tab) return;
|
|
66
|
-
d.tab = tab;
|
|
67
|
-
if (tab === 'design') {
|
|
68
|
-
X.restream([{ who: 'a', text: 'Reading the design.' }]);
|
|
69
|
-
X.draw(); await load(d);
|
|
70
|
-
} else {
|
|
71
|
-
X.restream([{ who: 'a', text: 'This is "' + d.name + '". ' }].concat(d.S ? d.S.log.map((l) => ({ who: l.who === 'pmos' ? 'a' : 'u', text: l.text })) : []));
|
|
72
|
-
X.draw();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/* ── the brief, tray, preview, checks, footer ── */
|
|
77
|
-
export function brief(d) {
|
|
78
|
-
const z = d.Z, c = X.chip, n = saved(z), v = versions(z);
|
|
79
|
-
return `<div class="stbr" role="group" aria-label="Brief">${tabs(d)}${c('dfmt', 'Format', z.loading ? 'Reading' : FMTN[fmtOf(z)])}${c('dsmp', 'Samples', z.loading ? 'Reading' : String(((z.design || {}).samples || []).length))}${n != null ? c('dbr', 'Design brief', 'D' + n) : ''}${c('dsv', 'Design', z.loading ? 'Reading' : n == null ? (v.length ? 'D' + (z.shown || v[v.length - 1].n) + ', not saved' : 'None yet') : 'D' + n + ', saved')}</div>`;
|
|
80
|
-
}
|
|
81
|
-
export function tray(d, p) {
|
|
82
|
-
const z = d.Z, S = (z.design || {}).samples || [];
|
|
83
|
-
if (p === 'dfmt') return `<div class="stmd" role="group" aria-label="Report type">${['deck', 'doc'].map((f) => `<button type="button" data-st="dzfmt|${f}" aria-pressed="${fmtOf(z) === f}"${z.working || z.loading ? ' disabled' : ''}>${FMTN[f]}</button>`).join('')}</div><p class="note">The next version is ${fmtOf(z) === 'deck' ? 'a slide deck' : 'a document'}. Versions you already made keep their form.</p>`;
|
|
84
|
-
if (p === 'dbr') return briefHtml(z);
|
|
85
|
-
if (p === 'dsmp') {
|
|
86
|
-
return (S.length ? `<ul class="sul">${S.map((s) => `<li><span>${esc(s.name)}<small>${esc(s.line || SWORD[s.kind] || s.kind)}${s.hint ? '. ' + esc(s.hint) : ''}</small>${s.took ? `<small>PMOS took: ${esc(s.took)}</small>` : s.readable === false ? '<small>PMOS could not read it with your tools. It is kept, but it does not shape the design.</small>' : '<small>PMOS reads it on the next version.</small>'}</span><span class="stlc"><button type="button" data-st="dzrm|${esc(s.id)}" aria-label="Remove the sample ${esc(s.name)}" title="Remove this sample"${z.working || X.st.busy ? ' disabled' : ''}>${XI}</button></span></li>`).join('')}</ul>` : '<p class="note">No sample yet. A sample is a deck, a document or a picture of how you want it to look.</p>')
|
|
87
|
-
+ `<div class="sor"><button type="button" class="dmcta alt" data-st="dzpick"${z.working ? ' disabled' : ''}>${PLUS}Add a file</button><input type="file" id="dzFile" hidden accept=".pdf,.pptx,.docx,.png,.jpg,.jpeg"></div>`
|
|
88
|
-
+ `<div class="stlk"><input class="sti" id="dzLink" placeholder="A Google Slides, Docs or Confluence link" maxlength="600" aria-label="A link to a sample" autocomplete="off" value="${esc(z.link)}"><button type="button" class="dmcta alt" data-st="dzlink"${z.working ? ' disabled' : ''}>Add the link</button></div><p class="note">PDF, PowerPoint, Word, PNG or JPG, up to 20 MB. A link is read with your own connectors.</p>`;
|
|
89
|
-
}
|
|
90
|
-
if (p === 'dsv') {
|
|
91
|
-
const v = versions(z);
|
|
92
|
-
return v.length ? `<ul class="sul">${v.slice().reverse().map((x) => `<li><span>D${x.n}${x.n === saved(z) ? ' · saved' : ''}${x.n === z.shown ? ' · shown' : ''}<small>${esc(x.turn || '')}</small></span></li>`).join('')}</ul><p class="note">Pick a version in the preview. This is it keeps the one shown. Undo goes back one version.</p>` : '<p class="note">No version yet. Say how it should look.</p>';
|
|
93
|
-
}
|
|
94
|
-
return '';
|
|
95
|
-
}
|
|
96
|
-
/* The saved design as a brief, not a template: what PMOS reads each cycle (the console's Design brief). Every line is a field of the saved design. */
|
|
97
|
-
function briefHtml(z) {
|
|
98
|
-
const g = z.design || {}, n = saved(z); if (n == null) return '';
|
|
99
|
-
const rules = g.rules || {}, S = g.samples || [];
|
|
100
|
-
const rule = (h, xs) => (xs && xs.length ? `<p class="note"><b>${h}</b></p><ul class="sul">${xs.map((x) => `<li><span>${esc(x)}</span></li>`).join('')}</ul>` : '');
|
|
101
|
-
return `<p class="note">Written by PMOS from your Studio session. It is not a template: PMOS reads it each cycle and drafts to match it. Saved ${esc(String(g.saved.at || '').slice(0, 10))}, version D${n}.</p>`
|
|
102
|
-
+ `<p class="note"><b>Your description</b></p><blockquote class="note">${esc(g.description || 'No description.')}</blockquote>`
|
|
103
|
-
+ `<p class="note"><b>Your samples</b></p>${S.length ? `<ul class="sul">${S.map((x) => `<li><span>${esc(x.name)}<small>${esc(x.line || SWORD[x.kind] || x.kind)}</small>${x.took ? `<small>PMOS took: ${esc(x.took)}</small>` : ''}</span></li>`).join('')}</ul>` : '<p class="note">No sample.</p>'}`
|
|
104
|
-
+ `<p class="note"><b>Reference version · D${n}</b></p><div class="sor"><button type="button" class="dmcta alt" data-st="dzver|${n}"${z.working ? ' disabled' : ''}>Show D${n}</button></div>`
|
|
105
|
-
+ (rule('Keeps the same each cycle', rules.same) + rule('Changes each cycle', rules.changes) + rule('Learned from your turns', rules.learned) || '<p class="note">PMOS has not written down what it learned yet.</p>')
|
|
106
|
-
+ '<p class="note">Cycles drafted to match it are checked on the report itself. Nothing is sent.</p>';
|
|
107
|
-
}
|
|
108
|
-
export function preview(d) {
|
|
109
|
-
const z = d.Z;
|
|
110
|
-
if (z.loading) return '<div class="stpvw"><p class="note">Reading the design of this report.</p></div>';
|
|
111
|
-
if (z.err) return `<div class="stpvw"><p class="note">${esc(z.err)}</p></div>`;
|
|
112
|
-
const v = versions(z), n = saved(z);
|
|
113
|
-
if (!v.length) return `<div class="stpvw"><p class="note">${z.working ? 'PMOS is making the first version.' : 'No version yet. Add a sample, or say how the report should look. PMOS makes D1.'}</p></div>`;
|
|
114
|
-
const L = slidesOf(z), i = z.i = Math.max(0, Math.min(z.i, L.length - 1));
|
|
115
|
-
const strip = `<span class="rdv" role="group" aria-label="Design versions">${v.map((x) => `<button type="button" data-st="dzver|${x.n}" aria-pressed="${x.n === z.shown}"${z.working ? ' disabled' : ''} title="${esc((x.n === n ? 'Saved. ' : '') + (x.turn || ''))}" aria-label="D${x.n}${x.n === n ? ', saved' : ''}">D${x.n}${x.n === n ? CHK : ''}</button>`).join('')}</span>`;
|
|
116
|
-
const tools = `<span class="dzact"><button type="button" class="dmcta alt" data-st="dzcmp" aria-pressed="${z.cmp}"${v.length < 2 ? ' disabled' : ''}>Compare two</button><button type="button" class="dmcta" data-st="dznext"${z.working ? ' disabled' : ''}>Make the next version</button></span>`;
|
|
117
|
-
const note = `<span class="note">${z.working ? 'PMOS is working on the next version.' : z.shown === n ? 'The saved design.' : 'Not saved. Press This is it to keep it.'}</span>`;
|
|
118
|
-
const nav = (len) => `<div class="rdnv"><button type="button" data-st="dzgo|${i - 1}" aria-label="Previous slide"${i === 0 ? ' disabled' : ''}>${PREV}</button><span>${i + 1} / ${len}</span><button type="button" data-st="dzgo|${i + 1}" aria-label="Next slide"${i >= len - 1 ? ' disabled' : ''}>${NEXT}</button></div>`;
|
|
119
|
-
if (z.cmp) return `<div class="stpvw dzpv"><div class="dzbar">${strip}${tools}${note}</div>${compare(z, i, nav)}</div>`;
|
|
120
|
-
const pins = z.points.filter((q) => L[i] && q.slide === L[i].id).map((q) => `<span class="dzpin" data-x="${q.x}" data-y="${q.y}" aria-hidden="true">${q.n}</span>`).join('');
|
|
121
|
-
const big = L.length ? `<div class="rdk"><div class="rdbig dzbig" id="dzSlide" tabindex="0" role="group" aria-roledescription="slide" aria-label="Slide ${i + 1} of ${L.length}: ${esc(L[i].h)}.${z.point ? ' Click a part of it to attach a request.' : ''}">${slideCard(L[i])}${pins}</div>${nav(L.length)}`
|
|
122
|
-
+ `<div class="rdt dzth" role="group" aria-label="Slides">${L.map((x, j) => `<button type="button" data-st="dzgo|${j}"${j === i ? ' aria-current="true"' : ''} aria-label="Slide ${j + 1}: ${esc(x.h)}">${slideCard(x, true)}<i>${j + 1}</i></button>`).join('')}</div></div>`
|
|
123
|
-
: '<p class="note">This version is not drawn as slides. It is a page.</p>';
|
|
124
|
-
const say = `<div class="dzsay"><div class="dzsh"><span class="label">Point and say <b>${z.points.length}</b></span><label class="dzon"><input type="checkbox" id="dzPoint"${z.point ? ' checked' : ''}> On</label></div>`
|
|
125
|
-
+ (z.points.length ? `<ul class="sul">${z.points.map((q) => `<li><span class="dzpn">${q.n}</span><input class="sti" data-dzp="${q.n}" value="${esc(q.text)}" placeholder="What should change here? Slide ${esc(q.slide)}" maxlength="1000" aria-label="Request ${q.n}, on slide ${esc(q.slide)}" autocomplete="off"><button type="button" class="lk" data-st="dzpx|${q.n}" aria-label="Remove request ${q.n}">Remove</button></li>`).join('')}</ul><p class="note">The next version carries these. Make the next version, or say it in the chat.</p>` : `<p class="note">${z.point ? 'Click any part of the preview to attach a request to it.' : 'Pointing is off.'}</p>`) + '</div>';
|
|
126
|
-
return `<div class="stpvw dzpv"><div class="dzbar">${strip}${tools}${note}</div>${big}${L.length ? say : ''}</div>`;
|
|
127
|
-
}
|
|
128
|
-
/* Compare two: the same slide of two versions side by side */
|
|
129
|
-
function compare(z, i, nav) {
|
|
130
|
-
const v = versions(z);
|
|
131
|
-
const B = z.cmpB != null && v.some((x) => x.n === z.cmpB) ? z.cmpB : ((v.filter((x) => x.n !== z.shown).pop() || {}).n);
|
|
132
|
-
z.cmpB = B;
|
|
133
|
-
const A = slidesOf(z), Bs = slidesAt(z, B), len = Math.max(A.length, Bs.length);
|
|
134
|
-
const pick = (k, cur) => `<span class="rdv" role="group" aria-label="${k === 'dzcl' ? 'Left' : 'Right'} version">${v.map((x) => `<button type="button" data-st="${k}|${x.n}" aria-pressed="${x.n === cur}">D${x.n}</button>`).join('')}</span>`;
|
|
135
|
-
const cell = (L, n, k) => `<div class="dzcc"><div class="dzch">${pick(k, n)}</div>${L[i] ? `<div class="rdbig" role="group" aria-label="D${n}, slide ${i + 1}: ${esc(L[i].h)}">${slideCard(L[i])}</div>` : `<p class="note">D${n} has no slide ${i + 1}.</p>`}</div>`;
|
|
136
|
-
return `<div class="dzcmp"><div class="dzcg">${cell(A, z.shown, 'dzcl')}${cell(Bs, B, 'dzcr')}</div>${nav(len)}<p class="note">Left is the version shown. Press Compare two again to go back to one.</p></div>`;
|
|
137
|
-
}
|
|
138
|
-
export function afterDraw() { const m = $('#stPv'); if (!m) return; fit(m); m.querySelectorAll('.dzpin').forEach((p) => { p.style.setProperty('--rp-pinx', p.dataset.x + '%'); p.style.setProperty('--rp-piny', p.dataset.y + '%'); }); }
|
|
139
|
-
export function checks(d) {
|
|
140
|
-
const z = d.Z, S = (z.design || {}).samples || [], n = saved(z), v = versions(z);
|
|
141
|
-
return [
|
|
142
|
-
{ ok: v.length > 0, l: 'A version exists', d: v.length ? v.length + ' version' + (v.length === 1 ? '' : 's') + ': D' + v[0].n + ' to D' + v[v.length - 1].n + '.' : 'There is no version yet. Say how it should look.' },
|
|
143
|
-
{ ok: S.length > 0 || !!(z.design && z.design.description), l: 'The look has something to follow', d: S.length ? 'It follows ' + S.map((s) => s.name).join(', ') + '.' : z.design && z.design.description ? 'It follows your description.' : 'There is no sample and no description.', fix: ['Add a sample', 'chip|dsmp'] },
|
|
144
|
-
{ ok: n != null, l: 'A design is saved', d: n != null ? 'D' + n + ' is the saved design. Each new cycle is drawn to it.' : 'No design is saved, so each cycle uses the standard look.', fix: z.shown != null ? ['This is it', 'dzkeep'] : null },
|
|
145
|
-
{ ok: n != null && n === z.shown, l: 'The version shown is the saved one', d: n == null ? 'Nothing is saved yet.' : n === z.shown ? 'D' + n + ' is shown and saved.' : 'D' + z.shown + ' is shown. The saved design is D' + n + '.', fix: z.shown != null && z.shown !== n ? ['This is it', 'dzkeep'] : null },
|
|
146
|
-
];
|
|
147
|
-
}
|
|
148
|
-
export function footer(d) {
|
|
149
|
-
const z = d.Z, n = z.shown;
|
|
150
|
-
return { undo: !z.working && n != null && versions(z).some((x) => x.n < n), cta: 'This is it', off: z.working || n == null || n === saved(z) };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/* ── presses ── */
|
|
154
|
-
async function refresh(d) { const res = await hand().get(d.id); if (res && res.ok === true) d.Z.design = res.design; return d.Z.design; }
|
|
155
|
-
export async function press(d, a) {
|
|
156
|
-
const [k, v] = a, z = d.Z;
|
|
157
|
-
if (k === 'dzgo') { z.i = +v; X.draw(['pv']); afterDraw(); const s = $('#dzSlide'); if (s) s.focus(); return; }
|
|
158
|
-
if (k === 'dzver') { await show(d, +v, true); return; }
|
|
159
|
-
if (k === 'dzcmp') { z.cmp = !z.cmp; if (z.cmp) { const V = versions(z).filter((x) => x.n !== z.shown); z.cmpB = (V.pop() || {}).n; await read(z, z.cmpB); } X.draw(['pv']); afterDraw(); return; }
|
|
160
|
-
if (k === 'dzcl') { z.shown = +v; await read(z, z.shown); X.draw(); afterDraw(); return; }
|
|
161
|
-
if (k === 'dzcr') { z.cmpB = +v; await read(z, z.cmpB); X.draw(['pv']); afterDraw(); return; }
|
|
162
|
-
if (k === 'dzpx') { z.points = z.points.filter((q) => q.n !== +v); X.draw(['pv']); afterDraw(); return; }
|
|
163
|
-
if (k === 'dznext') { const i = $('#stIn'), t = i ? i.value.trim() : ''; X.converse(t || (z.points.length ? 'Make the next version with the requests I pointed at.' : 'Make the next version.')); return; }
|
|
164
|
-
if (k === 'dzfmt') { await setFmt(d, v); return; }
|
|
165
|
-
if (k === 'dzkeep') { await keep(d); return; }
|
|
166
|
-
if (k === 'dzrm') { await unsample(d, v); return; }
|
|
167
|
-
if (k === 'dzpick') { const f = $('#dzFile'); if (f) f.click(); return; }
|
|
168
|
-
if (k === 'dzlink') { const i = $('#dzLink'); const link = i ? i.value.trim() : ''; if (!link) { X.st.msg = 'Paste a link first.'; X.draw(['ft']); return; } await sample(d, { link }); }
|
|
169
|
-
}
|
|
170
|
-
async function setFmt(d, f) {
|
|
171
|
-
const z = d.Z, g = z.design; if (z.working || z.fmt === f) return;
|
|
172
|
-
z.fmt = f;
|
|
173
|
-
if (g && g.description && g.format !== f) {
|
|
174
|
-
const r = await hand().post('describe', d.id, { text: g.description, format: f });
|
|
175
|
-
if (!r || r.ok !== true) { X.st.msg = 'The format was not changed: ' + ((r && r.error) || 'the press did not go through.'); X.draw(['br', 'tr', 'ft']); return; }
|
|
176
|
-
}
|
|
177
|
-
X.draw(['br', 'tr']);
|
|
178
|
-
X.say('The next version is ' + (f === 'deck' ? 'a slide deck' : 'a document') + '. Tell me what to change, and I make it.');
|
|
179
|
-
}
|
|
180
|
-
async function show(d, n, pick) {
|
|
181
|
-
const z = d.Z;
|
|
182
|
-
if (pick && z.design && z.design.current !== n) {
|
|
183
|
-
const r = await hand().post('revert', d.id, { n });
|
|
184
|
-
if (!r || r.ok !== true) { X.st.msg = (r && r.error) || 'D' + n + ' could not be picked.'; X.draw(['ft']); return; }
|
|
185
|
-
z.design = r.design; X.say('Back to D' + n + '. The next version builds on it.');
|
|
186
|
-
}
|
|
187
|
-
z.shown = n; z.i = 0; await read(z, n); X.draw(); afterDraw();
|
|
188
|
-
}
|
|
189
|
-
export async function undo(d) {
|
|
190
|
-
const z = d.Z, V = versions(z).filter((x) => x.n < z.shown);
|
|
191
|
-
if (!V.length || z.working) return null;
|
|
192
|
-
const to = V[V.length - 1].n;
|
|
193
|
-
await show(d, to, true);
|
|
194
|
-
return 'Done: back to D' + to + '. The next version builds on it.';
|
|
195
|
-
}
|
|
196
|
-
export async function keep(d) {
|
|
197
|
-
const z = d.Z, n = z.shown, s = X.st; if (n == null || n === saved(z) || z.working) return;
|
|
198
|
-
s.busy = true; s.msg = 'Saving the design.'; X.draw(['ft']);
|
|
199
|
-
const r = await hand().post('accept', d.id, { n });
|
|
200
|
-
s.busy = false;
|
|
201
|
-
if (!r || r.ok !== true) { s.msg = (r && r.error) || 'The design could not be saved.'; X.draw(); return; }
|
|
202
|
-
z.design = r.design; s.msg = 'D' + n + ' is saved as the design. ' + (r.redraw && r.redraw.started ? 'PMOS is drawing the current cycle to match it.' : 'Each new cycle is drawn to match it.');
|
|
203
|
-
X.draw(); afterDraw(); X.P.reportsChanged();
|
|
204
|
-
// the cycle is redrawn to the saved design by the one design job of this report; a turn waits for it
|
|
205
|
-
if (r.redraw && r.redraw.started) {
|
|
206
|
-
z.working = true; X.draw();
|
|
207
|
-
const t0 = Date.now();
|
|
208
|
-
for (;;) {
|
|
209
|
-
await new Promise((ok) => setTimeout(ok, POLL_MS));
|
|
210
|
-
if (X.r() !== d) return;
|
|
211
|
-
const g = await refresh(d);
|
|
212
|
-
if (!g || !g.running || Date.now() - t0 > POLL_MAX) break;
|
|
213
|
-
}
|
|
214
|
-
z.working = false; X.draw(); afterDraw();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
async function sample(d, body) {
|
|
218
|
-
const z = d.Z, s = X.st; s.msg = 'Adding the sample.'; X.draw(['ft']);
|
|
219
|
-
const r = await hand().post('sample', d.id, body);
|
|
220
|
-
if (!r || r.ok !== true) { s.msg = 'The sample was not added: ' + ((r && r.error) || 'the press did not go through.'); X.draw(['ft']); return; }
|
|
221
|
-
z.link = ''; await refresh(d); s.msg = '';
|
|
222
|
-
X.say('Added "' + ((r.sample && r.sample.name) || 'the sample') + '". Tell me what to take from it, and I make the next version follow it.');
|
|
223
|
-
}
|
|
224
|
-
/** Remove a sample: the next version, the brief and each cycle stop following it. */
|
|
225
|
-
async function unsample(d, id) {
|
|
226
|
-
const z = d.Z, s = X.st, smp = ((z.design || {}).samples || []).find((x) => x.id === id);
|
|
227
|
-
if (!smp || s.busy) return;
|
|
228
|
-
s.busy = true; s.msg = 'Removing the sample.'; X.draw(['tr', 'ft']);
|
|
229
|
-
const r = await hand().post('unsample', d.id, { sample: id });
|
|
230
|
-
s.busy = false;
|
|
231
|
-
if (!r || r.ok !== true) { s.msg = 'The sample was not removed: ' + ((r && r.error) || 'the press did not go through.'); X.draw(['tr', 'ft']); return; }
|
|
232
|
-
z.design = r.design; s.msg = ''; X.draw(); afterDraw();
|
|
233
|
-
X.say('Removed "' + smp.name + '". The next version and each new cycle no longer follow it.');
|
|
234
|
-
}
|
|
235
|
-
export async function addFile(d, file) {
|
|
236
|
-
const ext = (/\.([a-z0-9]+)$/i.exec(file.name) || [])[1], kind = KINDS[String(ext || '').toLowerCase()];
|
|
237
|
-
if (!kind) { X.st.msg = 'A sample is a PDF, PowerPoint, Word, PNG or JPG file.'; X.draw(['ft']); return; }
|
|
238
|
-
if (file.size > 20 * 1024 * 1024) { X.st.msg = 'A sample is 20 MB or less.'; X.draw(['ft']); return; }
|
|
239
|
-
const data = await new Promise((ok) => { const r = new FileReader(); r.onload = () => ok(String(r.result || '')); r.onerror = () => ok(''); r.readAsDataURL(file); });
|
|
240
|
-
if (!data) { X.st.msg = 'The file could not be read.'; X.draw(['ft']); return; }
|
|
241
|
-
await sample(d, { name: file.name, kind, data });
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/* ── a turn: one design job. Its answer is PMOS's own line from the design log. ── */
|
|
245
|
-
export async function turn(d, t, low) {
|
|
246
|
-
const z = d.Z;
|
|
247
|
-
if (/^(this is it|use this|save (it|this)|keep (it|this))\b/.test(low)) { await keep(d); return X.st.msg; }
|
|
248
|
-
if (/^undo\b/.test(low)) return (await undo(d)) || 'I changed nothing. There is no earlier version to go back to.';
|
|
249
|
-
if (z.working) return 'PMOS is still working on the last version. Wait for its answer.';
|
|
250
|
-
if (z.loading) return 'Reading the design. Try again in a moment.';
|
|
251
|
-
z.working = true; X.draw();
|
|
252
|
-
if (z.design && !z.design.description && !(z.design.versions || []).length) {
|
|
253
|
-
const r0 = await hand().post('describe', d.id, { text: t, format: fmtOf(z) });
|
|
254
|
-
if (!r0 || r0.ok !== true) { z.working = false; X.draw(); return 'The description was not saved: ' + ((r0 && r0.error) || 'the press did not go through.'); }
|
|
255
|
-
}
|
|
256
|
-
const before = ((z.design && z.design.log) || []).length;
|
|
257
|
-
const pts = z.points.filter((q) => q.text.trim() && q.slide).map((q) => ({ n: q.n, slide: q.slide, x: q.x, y: q.y, text: q.text.trim() }));
|
|
258
|
-
const r = await hand().post('turn', d.id, pts.length ? { text: t, points: pts } : { text: t });
|
|
259
|
-
if (!r || r.ok !== true) { z.working = false; X.draw(); return 'Nothing changed: ' + ((r && r.error) || 'the change could not start.'); }
|
|
260
|
-
z.points = []; X.draw(['pv']); afterDraw();
|
|
261
|
-
return wait(d, before);
|
|
262
|
-
}
|
|
263
|
-
async function wait(d, before) {
|
|
264
|
-
const z = d.Z, t0 = Date.now();
|
|
265
|
-
for (;;) {
|
|
266
|
-
await new Promise((ok) => setTimeout(ok, POLL_MS));
|
|
267
|
-
if (X.r() !== d || d.tab !== 'design') return 'The Studio moved on. The answer is in the report\'s design.';
|
|
268
|
-
const g = await refresh(d);
|
|
269
|
-
if (g && !g.running) {
|
|
270
|
-
z.working = false;
|
|
271
|
-
const L = (g.log || []).slice(before).filter((x) => x.kind === 'version' || x.kind === 'error'), last = L[L.length - 1];
|
|
272
|
-
if (last && last.kind === 'version' && last.version) { await show(d, last.version, false); return last.text + ' This is D' + last.version + '. Press This is it to keep it as the design.'; }
|
|
273
|
-
X.draw();
|
|
274
|
-
return last ? 'The change did not work: ' + last.text : 'PMOS ended without a new version. Say it again, or in other words.';
|
|
275
|
-
}
|
|
276
|
-
if (Date.now() - t0 > POLL_MAX) { z.working = false; X.draw(); return 'PMOS has not answered yet. The version shows when you open this report again.'; }
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/* Point and say: a click on the slide attaches a request to that spot; each request is typed under the preview. */
|
|
281
|
-
const inDesign = (e) => { const r = X && X.r && X.r(); return r && r.kind === 'setup' && r.tab === 'design' && $('#dlg').classList.contains('stud') && $('#dlg').classList.contains('on') && e.target.closest && e.target.closest('#oMain'); };
|
|
282
|
-
document.addEventListener('click', (e) => {
|
|
283
|
-
if (!inDesign(e)) return;
|
|
284
|
-
const big = e.target.closest('#dzSlide'); if (!big) return;
|
|
285
|
-
const d = X.r(), z = d.Z; if (!z.point || z.working || z.cmp) return;
|
|
286
|
-
const L = slidesOf(z), sl = L[Math.max(0, Math.min(z.i, L.length - 1))]; if (!sl || !sl.id) return;
|
|
287
|
-
const b = big.getBoundingClientRect(); if (!b.width) return;
|
|
288
|
-
if (z.points.length >= 20) return;
|
|
289
|
-
const n = z.points.reduce((m, q) => Math.max(m, q.n), 0) + 1;
|
|
290
|
-
z.points.push({ n, slide: sl.id, x: Math.round(((e.clientX - b.left) / b.width) * 1000) / 10, y: Math.round(((e.clientY - b.top) / b.height) * 1000) / 10, text: '' });
|
|
291
|
-
X.draw(['pv']); afterDraw();
|
|
292
|
-
const i = document.querySelector(`#stPv [data-dzp="${n}"]`); if (i) i.focus();
|
|
293
|
-
});
|
|
294
|
-
document.addEventListener('input', (e) => {
|
|
295
|
-
if (!inDesign(e) || !e.target.dataset || !e.target.dataset.dzp) return;
|
|
296
|
-
const q = X.r().Z.points.find((x) => x.n === +e.target.dataset.dzp); if (q) q.text = e.target.value;
|
|
297
|
-
});
|
|
298
|
-
document.addEventListener('change', (e) => { if (inDesign(e) && e.target.id === 'dzPoint') { X.r().Z.point = e.target.checked; X.draw(['pv']); afterDraw(); } });
|