@floless/app 0.159.0 → 0.160.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/dist/floless-server.cjs +29576 -23804
- package/dist/schemas/steel.model.v2.schema.json +1 -0
- package/dist/skills/floless-app-onboarding/SKILL.md +4 -3
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +1 -2
- package/dist/skills/floless-app-rfi/SKILL.md +29 -1
- package/dist/skills/floless-app-steel-model/SKILL.md +2 -2
- package/dist/web/app.css +184 -151
- package/dist/web/app.js +17 -51
- package/dist/web/aware.js +504 -542
- package/dist/web/chat-question-card.js +24 -1
- package/dist/web/chat.css +131 -29
- package/dist/web/chat.js +1225 -178
- package/dist/web/commands-shell.js +676 -50
- package/dist/web/commands-steel.js +1 -0
- package/dist/web/guide.js +8 -0
- package/dist/web/index.html +23 -41
- package/dist/web/instructor.js +14 -5
- package/dist/web/pages.js +115 -18
- package/dist/web/panels.js +19 -1
- package/dist/web/project-rfis.js +715 -0
- package/dist/web/project-workflows.js +236 -4
- package/dist/web/run-history.js +198 -0
- package/dist/web/run-page-view.js +12 -2
- package/dist/web/steel-3d-core.js +29 -1
- package/dist/web/steel-editor.html +71 -10
- package/dist/web/steel-model-v2-projection.js +7 -0
- package/dist/web/workspaces.js +136 -48
- package/package.json +2 -1
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A General project's RFIs step (#2470 R6.6): the project's questions for the engineer, client or architect. Each RFI
|
|
3
|
+
* may cite a page of this project's Knowledge or a saved sheet of a project linked on its Modules step; FloLess gives
|
|
4
|
+
* the email text to send and keeps what was sent, answered and closed. It sends nothing itself (Gmail is R6.6b).
|
|
5
|
+
*
|
|
6
|
+
* It renders GET /api/projects/:id/correspondence-rfis and changes RFIs only through that route family. Every write
|
|
7
|
+
* names the Workspace and project it was shown (rootId + project uuid from the read). Spec:
|
|
8
|
+
* docs/superpowers/specs/2026-10-23-2470-r6-6-rfis-tab-PLAN.md.
|
|
9
|
+
*/
|
|
10
|
+
(() => {
|
|
11
|
+
const bridge = () => window.flolessBridge || {};
|
|
12
|
+
const api = (path, init) => {
|
|
13
|
+
if (typeof bridge().api === 'function') return bridge().api(path, init);
|
|
14
|
+
return fetch(path, { headers: { 'Content-Type': 'application/json' }, ...init }).then(async (res) => {
|
|
15
|
+
const body = await res.json().catch(() => ({}));
|
|
16
|
+
if (!res.ok || body.ok === false) { const err = new Error(body.error || `HTTP ${res.status}`); err.status = res.status; err.body = body; throw err; }
|
|
17
|
+
return body;
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
21
|
+
const toast = (msg, kind, options) => (typeof window.showToast === 'function' ? window.showToast(msg, kind, options) : null);
|
|
22
|
+
const said = (error, fallback) => (typeof error?.body?.error === 'string' && error.body.error ? error.body.error : fallback);
|
|
23
|
+
/** A refusal the server wrote (a 4xx with a sentence) — as opposed to an outcome nobody confirmed. */
|
|
24
|
+
const refused = (error) => !!error?.status && error.status >= 400 && error.status < 500 && typeof error?.body?.error === 'string';
|
|
25
|
+
const newKey = () => `rfi-${crypto.randomUUID()}`;
|
|
26
|
+
const MAX_CITES = 5;
|
|
27
|
+
|
|
28
|
+
function ago(iso, now = Date.now()) {
|
|
29
|
+
const t = Date.parse(iso);
|
|
30
|
+
if (!Number.isFinite(t)) return '';
|
|
31
|
+
const m = Math.round(Math.max(0, now - t) / 60000);
|
|
32
|
+
if (m < 1) return 'just now';
|
|
33
|
+
if (m < 60) return `${m} min ago`;
|
|
34
|
+
const h = Math.round(m / 60);
|
|
35
|
+
if (h < 24) return `${h} h ago`;
|
|
36
|
+
const d = Math.round(h / 24);
|
|
37
|
+
return d === 1 ? 'yesterday' : `${d} days ago`;
|
|
38
|
+
}
|
|
39
|
+
const exact = (iso) => { const t = Date.parse(iso); return Number.isFinite(t) ? new Date(t).toLocaleString() : ''; };
|
|
40
|
+
|
|
41
|
+
const STATUS = { open: 'Open', sent: 'Sent', answered: 'Answered', closed: 'Closed' };
|
|
42
|
+
const DISPOSITIONS = [
|
|
43
|
+
{ key: 'answered', label: 'Answered', help: 'The question was answered.' },
|
|
44
|
+
{ key: 'withdrawn', label: 'Withdrawn', help: 'You no longer need an answer.' },
|
|
45
|
+
{ key: 'superseded', label: 'Superseded', help: 'A newer RFI replaces this one.' },
|
|
46
|
+
{ key: 'wont-fix', label: 'Won’t fix', help: 'It won’t be acted on.' },
|
|
47
|
+
];
|
|
48
|
+
const dispositionLabel = (key) => DISPOSITIONS.find((d) => d.key === key)?.label || key;
|
|
49
|
+
|
|
50
|
+
/** How a citation's state reads on its chip and in its tip (the server's reason first, when it gave one). */
|
|
51
|
+
const CITE_STATE = {
|
|
52
|
+
current: { word: '', tip: 'Still matches what was cited.' },
|
|
53
|
+
changed: { word: 'changed', tip: 'This page was re-published with other text. The RFI keeps the text as it was when you cited it.' },
|
|
54
|
+
unavailable: { word: 'unavailable', tip: 'That version of the page is gone, or it was cited in another project (this RFI was copied).' },
|
|
55
|
+
'link-removed': { word: 'link removed', tip: 'This project no longer links to that project. Link it again on the Modules step to check this sheet.' },
|
|
56
|
+
'project-unavailable': { word: 'project unavailable', tip: 'The linked project can’t be read just now.' },
|
|
57
|
+
'sheet-missing': { word: 'sheet not found', tip: 'The linked project has no saved sheet matching this one. It may have been re-saved or removed.' },
|
|
58
|
+
'sheet-ambiguous': { word: 'sheet unclear', tip: 'The linked project has two saved sheets that match, so FloLess can’t tell which was meant.' },
|
|
59
|
+
'sheet-unusable': { word: 'sheet unreadable', tip: 'FloLess couldn’t read this sheet just now.' },
|
|
60
|
+
detached: { word: 'from a copy', tip: 'This came with a copy of the project and is not checked against the current links. File it again to cite a sheet here.' },
|
|
61
|
+
'not-checked': { word: 'not checked', tip: 'Not looked at from this chat.' },
|
|
62
|
+
};
|
|
63
|
+
const citeLabel = (c) => (c.kind === 'knowledge-page' ? `Knowledge · ${c.title}` : `Drawing · ${c.sheet} · ${c.linkedProjectName}`);
|
|
64
|
+
function chipHtml(c) {
|
|
65
|
+
const st = CITE_STATE[c.state] || CITE_STATE.current;
|
|
66
|
+
const word = st.word ? ` · ${st.word}` : '';
|
|
67
|
+
return `<span class="pw-chip pr-cite${st.word ? ' is-muted' : ''}" role="listitem" tabindex="0" data-tip="${esc(c.reason || st.tip)}">${esc(citeLabel(c))}${esc(word)}</span>`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ── the step ───────────────────────────────────────────────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
let state = null; // { pane, project, generation, view, filter, form, drafts, inflight, again, focusAfter }
|
|
73
|
+
const ownChild = (pane, cls) => [...pane.children].find((el) => el.classList.contains(cls)) || null;
|
|
74
|
+
const announce = (text) => { const live = state && ownChild(state.pane, 'pr-live'); if (live) live.textContent = text; };
|
|
75
|
+
const target = () => {
|
|
76
|
+
const d = state?.view?.data;
|
|
77
|
+
return d ? { rootId: d.rootId, projectUuid: d.project.uuid, projectId: d.project.id, name: d.project.name } : null;
|
|
78
|
+
};
|
|
79
|
+
const identity = () => { const t = target(); return { expectedRootId: t.rootId, expectedProjectUuid: t.projectUuid }; };
|
|
80
|
+
|
|
81
|
+
const visible = (rfis, filter) => rfis.filter((r) => (filter === 'all' ? true : filter === 'closed' ? r.status === 'closed' : r.status !== 'closed'));
|
|
82
|
+
|
|
83
|
+
/** One inline verb form (one open at a time; its text survives a repaint). */
|
|
84
|
+
function formHtml(rfi, form) {
|
|
85
|
+
const id = esc(rfi.id);
|
|
86
|
+
const draft = form.draft || {};
|
|
87
|
+
const busy = form.busy ? ' disabled' : '';
|
|
88
|
+
// While FloLess can't confirm a save, the form is frozen: Try again resends exactly what was sent, and Edit makes it a new change.
|
|
89
|
+
const ro = form.uncertain ? ' readonly' : '';
|
|
90
|
+
const alert = form.error ? `<p class="pm-note pr-alert" role="alert">${esc(form.error)}</p>` : '';
|
|
91
|
+
const uncertain = form.uncertain ? '<p class="pm-note pr-alert" role="alert">FloLess couldn’t confirm that was saved. Try again sends the same thing again, and it can’t be saved twice. To change it, choose Edit.</p>' : '';
|
|
92
|
+
let fields = '';
|
|
93
|
+
let primary = '';
|
|
94
|
+
switch (form.verb) {
|
|
95
|
+
case 'mark-sent':
|
|
96
|
+
fields = `<label class="pr-field">Who did you send it to?<input type="email" class="pr-input" data-pr-input="to" value="${esc(draft.to || '')}" autocomplete="email"
|
|
97
|
+
data-command-id="shell.project-rfi-sent-to#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}${ro}></label>`;
|
|
98
|
+
primary = 'Mark as sent'; break;
|
|
99
|
+
case 'answer':
|
|
100
|
+
fields = `<label class="pr-field">What was the answer?<textarea class="pr-input pr-text" data-pr-input="text" rows="4" maxlength="4000"
|
|
101
|
+
data-command-id="shell.project-rfi-answer-text#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}${ro}>${esc(draft.text || '')}</textarea></label>
|
|
102
|
+
<p class="pg-row-meta">Paste or type what you were told.</p>`;
|
|
103
|
+
primary = 'Save answer'; break;
|
|
104
|
+
case 'close': {
|
|
105
|
+
const options = DISPOSITIONS.filter((d) => d.key !== 'answered' || rfi.status === 'answered');
|
|
106
|
+
const chosen = draft.disposition || (rfi.status === 'answered' ? 'answered' : '');
|
|
107
|
+
fields = `<div class="pr-radios" role="radiogroup" aria-label="Why is it closing?">${options.map((d, i) => {
|
|
108
|
+
const on = chosen === d.key;
|
|
109
|
+
return `<button type="button" class="pr-radio" role="radio" aria-checked="${on}" tabindex="${on || (!chosen && i === 0) ? 0 : -1}" data-pr-disposition="${esc(d.key)}"
|
|
110
|
+
data-command-id="shell.project-rfi-close-reason#${esc(d.key)}" data-command-instance-label="${esc(d.label)}"${busy || (form.uncertain ? ' disabled' : '')}><span class="pr-radio-dot" aria-hidden="true"></span>
|
|
111
|
+
<span><span class="pr-radio-label">${esc(d.label)}</span><span class="pg-row-meta">${esc(d.help)}</span></span></button>`;
|
|
112
|
+
}).join('')}</div>
|
|
113
|
+
<label class="pr-field">${chosen === 'answered' ? 'Note (optional)' : 'Note'}<textarea class="pr-input pr-text" data-pr-input="note" rows="2" maxlength="1000"
|
|
114
|
+
data-command-id="shell.project-rfi-close-note#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}${ro}>${esc(draft.note || '')}</textarea></label>`;
|
|
115
|
+
primary = 'Close RFI'; break;
|
|
116
|
+
}
|
|
117
|
+
case 'reopen':
|
|
118
|
+
fields = `<label class="pr-field">Why is this open again?<textarea class="pr-input pr-text" data-pr-input="why" rows="2" maxlength="1000"
|
|
119
|
+
data-command-id="shell.project-rfi-reopen-why#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}${ro}>${esc(draft.why || '')}</textarea></label>`;
|
|
120
|
+
primary = 'Reopen'; break;
|
|
121
|
+
}
|
|
122
|
+
const verbName = { 'mark-sent': 'Mark sent', answer: 'Answer', close: 'Close', reopen: 'Reopen' }[form.verb];
|
|
123
|
+
return `<div class="pr-form" role="group" aria-label="${esc(`${verbName} ${rfi.id}`)}"${form.busy ? ' aria-busy="true"' : ''}>${fields}${alert}${uncertain}
|
|
124
|
+
<div class="pm-strip-acts pr-form-acts">
|
|
125
|
+
<button type="button" class="ghost" data-pr-form-cancel="1" data-command-id="shell.project-rfi-form-cancel#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}>Cancel</button>
|
|
126
|
+
${form.uncertain ? `<button type="button" class="ghost" data-pr-form-edit="1" data-command-id="shell.project-rfi-form-edit#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}>Edit</button>` : ''}
|
|
127
|
+
${form.stale ? `<button type="button" class="ghost" data-pr-form-again="1" data-command-id="shell.project-rfi-look-again#${esc(rfi.id)}" data-command-instance-label="${id}">Look again</button>` : ''}
|
|
128
|
+
<button type="button" class="primary" data-pr-form-submit="1" data-command-id="shell.project-rfi-form-submit#${esc(rfi.id)}" data-command-instance-label="${id}"${busy}>${form.uncertain ? 'Try again' : form.busy ? 'Saving…' : esc(primary)}</button>
|
|
129
|
+
</div></div>`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function rowHtml(rfi, now) {
|
|
133
|
+
const id = esc(rfi.id);
|
|
134
|
+
const label = `data-command-instance-label="${id}"`;
|
|
135
|
+
const meta = [];
|
|
136
|
+
if (rfi.sent) meta.push(`<span data-tip="${esc(exact(rfi.sent.at))}">Marked sent to ${esc(rfi.sent.to)} · ${esc(ago(rfi.sent.at, now))}</span>`);
|
|
137
|
+
else meta.push(`<span data-tip="${esc(exact(rfi.raisedAt))}">Filed ${esc(ago(rfi.raisedAt, now))}${rfi.raisedBy === 'ai' ? ' by AI Chat' : ''}</span>`);
|
|
138
|
+
if (rfi.reopens) meta.push(`Reopened ${rfi.reopens === 1 ? 'once' : `${rfi.reopens} times`}`);
|
|
139
|
+
const answer = rfi.answer ? `<blockquote class="pr-answer"><span class="pr-answer-label">Answer</span> ${esc(rfi.answer.text)}</blockquote>` : '';
|
|
140
|
+
const closed = rfi.closed ? `<p class="pg-row-meta">Closed: ${esc(dispositionLabel(rfi.closed.disposition))}${rfi.closed.note ? `. ${esc(rfi.closed.note)}` : '.'}</p>` : '';
|
|
141
|
+
const provenance = rfi.provenance ? `<p class="pm-note">${esc(rfi.provenance)}</p>` : '';
|
|
142
|
+
const cites = rfi.citations.length ? `<div class="pr-cites" role="list" aria-label="Cited in ${id}">${rfi.citations.map(chipHtml).join('')}</div>` : '';
|
|
143
|
+
const drifted = rfi.citations.some((c) => c.state !== 'current');
|
|
144
|
+
const driftNote = drifted ? '<p class="pg-row-meta">One cited item no longer matches. You can send the RFI as it was, or File again from this… with the current items.</p>' : '';
|
|
145
|
+
const form = state.form && state.form.rfiId === rfi.id ? formHtml(rfi, state.form) : '';
|
|
146
|
+
const verbButtons = form ? '' : [
|
|
147
|
+
rfi.status !== 'closed' ? `<button type="button" class="ghost" data-pr-copy="${id}" data-command-id="shell.project-rfi-copy#${esc(rfi.id)}" ${label} aria-label="Copy the email text of ${id}"
|
|
148
|
+
data-tip="Copies the subject and the question, with what it cites, to paste into your email">Copy email text</button>` : '',
|
|
149
|
+
...rfi.verbs.map((verb) => {
|
|
150
|
+
const text = { 'mark-sent': 'Mark sent…', answer: 'Answer…', close: 'Close…', reopen: 'Reopen…' }[verb];
|
|
151
|
+
const tip = { 'mark-sent': 'Records who you sent it to. FloLess doesn’t send the email.', answer: 'Records the answer that came back',
|
|
152
|
+
close: 'Closes the RFI, with why', reopen: 'Opens the RFI again, with why' }[verb];
|
|
153
|
+
// Each command id is written whole; only the instance after "#" varies.
|
|
154
|
+
const carrier = verb === 'mark-sent' ? `data-command-id="shell.project-rfi-mark-sent#${esc(rfi.id)}"`
|
|
155
|
+
: verb === 'answer' ? `data-command-id="shell.project-rfi-answer#${esc(rfi.id)}"`
|
|
156
|
+
: verb === 'close' ? `data-command-id="shell.project-rfi-close#${esc(rfi.id)}"`
|
|
157
|
+
: `data-command-id="shell.project-rfi-reopen#${esc(rfi.id)}"`;
|
|
158
|
+
return `<button type="button" class="ghost" data-pr-verb="${esc(verb)}" data-pr-rfi="${id}" ${carrier} ${label}
|
|
159
|
+
aria-label="${esc(`${text.replace('…', '')} ${rfi.id}`)}" data-tip="${esc(tip)}">${esc(text)}</button>`;
|
|
160
|
+
}),
|
|
161
|
+
drifted ? `<button type="button" class="ghost" data-pr-again="${id}" data-command-id="shell.project-rfi-file-again#${esc(rfi.id)}" ${label}
|
|
162
|
+
data-tip="Opens New RFI with this title and question and the items that still match">File again from this…</button>` : '',
|
|
163
|
+
].join('');
|
|
164
|
+
return `<div class="pg-row pr-row" role="listitem">
|
|
165
|
+
<div class="pg-row-line"><span class="pg-row-title" tabindex="-1" data-pr-title="${id}">${id} · ${esc(rfi.title)}</span>
|
|
166
|
+
<span class="pw-chip${rfi.status === 'closed' ? ' is-muted' : ''}">${esc(STATUS[rfi.status] || rfi.status)}</span></div>
|
|
167
|
+
<span class="pg-row-meta">${meta.join(' · ')}</span>
|
|
168
|
+
<p class="pr-question">${esc(rfi.question)}</p>${answer}${closed}${provenance}${cites}${driftNote}
|
|
169
|
+
${form || `<div class="pm-strip-acts pr-acts">${verbButtons}</div>`}
|
|
170
|
+
${state.copied?.rfiId === rfi.id ? `<textarea class="pr-input pr-text pr-copied" data-pr-copied="1" readonly rows="6" data-command-id="shell.project-rfi-copied-text#${esc(rfi.id)}" data-command-instance-label="${id}" aria-label="${esc(`Email text of ${rfi.id}`)}">${esc(state.copied.text)}</textarea>` : ''}</div>`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const newButton = (cls) => `<button type="button" class="ghost ${cls}" data-pr-new="1" aria-haspopup="dialog" data-command-id="shell.project-rfis-new"
|
|
174
|
+
data-tip="File a question for the engineer, client or architect">New RFI…</button>`;
|
|
175
|
+
|
|
176
|
+
function html(view, now = Date.now()) {
|
|
177
|
+
const data = view.data;
|
|
178
|
+
const rfis = data?.rfis || [];
|
|
179
|
+
const ready = view.status === 'ready' && data?.store === 'ok';
|
|
180
|
+
const head = `<div class="step-head"><span tabindex="-1" data-pr-heading="1">RFIs</span>${ready && rfis.length ? newButton('pr-new') : ''}</div>
|
|
181
|
+
<p class="pg-sub">Questions for the engineer, client or architect. FloLess gives you the email text to send and keeps the answer. It doesn’t send anything itself.</p>`;
|
|
182
|
+
if (view.status === 'loading') return `${head}<p class="pg-loading-line">Loading this project’s RFIs…</p>`;
|
|
183
|
+
if (view.status === 'gone') return `${head}<div class="pg-empty pr-failed"><p class="pg-empty-title">FloLess couldn’t find this project any more.</p><p>It may have been archived or removed. Go back to your projects to open it again.</p></div>`;
|
|
184
|
+
if (view.status === 'failed') {
|
|
185
|
+
return `${head}<div class="pg-empty pr-failed"><p class="pg-empty-title">FloLess couldn’t load this project’s RFIs.</p><p>${esc(view.error)}</p>
|
|
186
|
+
<p><button type="button" class="ghost" data-pr-retry="1" data-command-id="shell.project-rfis-retry">Try again</button></p></div>`;
|
|
187
|
+
}
|
|
188
|
+
if (data.store === 'newer') {
|
|
189
|
+
return `${head}<div class="pg-empty pr-failed"><p class="pg-empty-title">These RFIs were made by a newer FloLess.</p><p>Update FloLess to see and change them. Nothing has been changed or lost.</p></div>`;
|
|
190
|
+
}
|
|
191
|
+
if (data.store === 'quarantined') {
|
|
192
|
+
return `${head}<div class="pg-empty pr-failed"><p class="pg-empty-title">FloLess can’t read this project’s RFI file.</p><p>${esc(data.message)}</p>
|
|
193
|
+
<p><button type="button" class="ghost" data-pr-repair="1" data-command-id="shell.project-rfis-repair">I restored it — check again</button></p>
|
|
194
|
+
${view.repairError ? `<p class="pm-note pr-alert" role="alert">${esc(view.repairError)}</p>` : ''}</div>`;
|
|
195
|
+
}
|
|
196
|
+
if (data.store === 'transport') {
|
|
197
|
+
return `${head}<div class="pg-empty pr-failed"><p class="pg-empty-title">FloLess couldn’t load this project’s RFIs.</p><p>${esc(data.message)}</p>
|
|
198
|
+
<p><button type="button" class="ghost" data-pr-retry="1" data-command-id="shell.project-rfis-retry">Try again</button></p></div>`;
|
|
199
|
+
}
|
|
200
|
+
if (!rfis.length) {
|
|
201
|
+
return `${head}<div class="pg-empty pr-empty"><p class="pg-empty-title">No RFIs in this project yet</p>
|
|
202
|
+
<p>File a question for the engineer, client or architect. FloLess keeps it, gives you the email text, and records the answer.</p><p>${newButton('pr-new-empty')}</p></div>`;
|
|
203
|
+
}
|
|
204
|
+
const counts = { open: visible(rfis, 'open').length, closed: visible(rfis, 'closed').length, all: rfis.length };
|
|
205
|
+
const filters = `<div class="pr-filters" role="group" aria-label="Show RFIs">${['open', 'closed', 'all'].map((f) => `<button type="button" class="ghost pr-filter"
|
|
206
|
+
aria-pressed="${state.filter === f}" data-pr-filter="${f}" data-command-id="shell.project-rfis-filter#${esc(f)}">${{ open: 'Open', closed: 'Closed', all: 'All' }[f]} ${counts[f]}</button>`).join('')}</div>`;
|
|
207
|
+
const shownRfis = visible(rfis, state.filter);
|
|
208
|
+
const list = shownRfis.length
|
|
209
|
+
? `<div class="pg-list pr-list" role="list" aria-label="RFIs in this project">${shownRfis.map((r) => rowHtml(r, now)).join('')}</div>`
|
|
210
|
+
: `<div class="pg-empty pr-empty"><p class="pg-empty-title">${state.filter === 'closed' ? 'No closed RFIs yet.' : 'No open RFIs.'}</p>
|
|
211
|
+
<p><button type="button" class="ghost" data-pr-filter="all" data-command-id="shell.project-rfis-filter#all">Show all</button></p></div>`;
|
|
212
|
+
return head + filters + list;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function paint() {
|
|
216
|
+
const { pane, view } = state;
|
|
217
|
+
const active = pane.contains(document.activeElement) && document.activeElement !== document.body ? document.activeElement : null;
|
|
218
|
+
const focusedId = active?.getAttribute('data-command-id') ?? null;
|
|
219
|
+
const focusedInput = active?.getAttribute('data-pr-input') ?? null;
|
|
220
|
+
let body = ownChild(pane, 'pr-body');
|
|
221
|
+
if (!body) {
|
|
222
|
+
pane.innerHTML = '<span class="sr-only pr-live" role="status" aria-live="polite"></span><div class="pr-body"></div>';
|
|
223
|
+
body = ownChild(pane, 'pr-body');
|
|
224
|
+
}
|
|
225
|
+
body.innerHTML = html(view);
|
|
226
|
+
const after = state.focusAfter; state.focusAfter = null;
|
|
227
|
+
const find = (sel) => body.querySelector(sel);
|
|
228
|
+
if (after) { (find(after) || find('[data-pr-heading]'))?.focus({ preventScroll: true }); return; }
|
|
229
|
+
if (focusedInput) { const el = find(`[data-pr-input="${focusedInput}"]`); if (el) { el.focus({ preventScroll: true }); return; } }
|
|
230
|
+
if (focusedId) [...body.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === focusedId)?.focus({ preventScroll: true });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function load() {
|
|
234
|
+
if (!state) return;
|
|
235
|
+
if (state.inflight) { state.again = true; return; }
|
|
236
|
+
const mine = state;
|
|
237
|
+
const generation = mine.generation;
|
|
238
|
+
mine.inflight = true;
|
|
239
|
+
try {
|
|
240
|
+
const data = await api(`/api/projects/${encodeURIComponent(mine.project.id)}/correspondence-rfis`);
|
|
241
|
+
if (state !== mine || mine.generation !== generation) return;
|
|
242
|
+
mine.view = { status: 'ready', data, error: null };
|
|
243
|
+
if (mine.form && !data.rfis.some((r) => r.id === mine.form.rfiId)) mine.form = null;
|
|
244
|
+
paint();
|
|
245
|
+
if (data.store === 'ok') {
|
|
246
|
+
const n = data.rfis.length;
|
|
247
|
+
if (!mine.quietLoad) announce(n === 0 ? 'No RFIs in this project yet' : `${n} RFI${n === 1 ? '' : 's'}`);
|
|
248
|
+
} else announce(data.message || 'FloLess couldn’t load this project’s RFIs.');
|
|
249
|
+
mine.quietLoad = false;
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (state !== mine || mine.generation !== generation) return;
|
|
252
|
+
const gone = error?.status === 404;
|
|
253
|
+
mine.view = { status: gone ? 'gone' : 'failed', data: null,
|
|
254
|
+
error: said(error, 'FloLess couldn’t read them just now. Check that FloLess is still running, then try again.') };
|
|
255
|
+
paint();
|
|
256
|
+
announce(gone ? 'FloLess couldn’t find this project any more.' : 'FloLess couldn’t load this project’s RFIs.');
|
|
257
|
+
} finally {
|
|
258
|
+
mine.inflight = false;
|
|
259
|
+
if (state === mine && mine.again) { mine.again = false; void load(); }
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function render(pane, project) {
|
|
264
|
+
if (!pane || !project) return;
|
|
265
|
+
const same = state && state.pane === pane && state.project.id === project.id;
|
|
266
|
+
state = { pane, project, generation: (state?.generation || 0) + 1, view: { status: 'loading', data: null },
|
|
267
|
+
filter: same ? state.filter : 'open', form: null, inflight: false, again: false, focusAfter: null };
|
|
268
|
+
paint();
|
|
269
|
+
void load();
|
|
270
|
+
}
|
|
271
|
+
const shown = (pane) => !pane.hidden && (typeof pane.checkVisibility === 'function' ? pane.checkVisibility() : pane.offsetParent !== null);
|
|
272
|
+
/** Something changed elsewhere: re-read while shown — but never under an open form (its text would be lost). */
|
|
273
|
+
function refresh() { if (state && shown(state.pane) && !state.form && !sheet) void load(); }
|
|
274
|
+
|
|
275
|
+
// ── verbs ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
276
|
+
|
|
277
|
+
function openForm(rfiId, verb) {
|
|
278
|
+
state.form = { rfiId, verb, key: newKey(), draft: {}, error: null, busy: false, uncertain: false, stale: false };
|
|
279
|
+
state.focusAfter = verb === 'close' ? '.pr-form [data-pr-disposition]' : '.pr-form [data-pr-input]';
|
|
280
|
+
paint();
|
|
281
|
+
}
|
|
282
|
+
function closeForm() {
|
|
283
|
+
const f = state.form;
|
|
284
|
+
state.form = null;
|
|
285
|
+
state.focusAfter = f ? `[data-pr-verb="${f.verb}"][data-pr-rfi="${CSS.escape(f.rfiId)}"]` : null;
|
|
286
|
+
paint();
|
|
287
|
+
}
|
|
288
|
+
function readDraft() {
|
|
289
|
+
const f = state.form;
|
|
290
|
+
if (!f) return;
|
|
291
|
+
for (const el of state.pane.querySelectorAll('.pr-form [data-pr-input]')) f.draft[el.getAttribute('data-pr-input')] = el.value;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function submitForm() {
|
|
295
|
+
const mine = state;
|
|
296
|
+
const f = mine.form;
|
|
297
|
+
if (!f || f.busy) return;
|
|
298
|
+
if (f.uncertain) { void sendForm(mine, f, f.sent); return; }
|
|
299
|
+
readDraft();
|
|
300
|
+
const rfi = mine.view.data.rfis.find((r) => r.id === f.rfiId);
|
|
301
|
+
const d = f.draft;
|
|
302
|
+
// Asked, not refused: the button stays live and says what is missing.
|
|
303
|
+
const missing = f.verb === 'mark-sent' && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(d.to || '').trim()) ? 'Give one email address, like name@company.com.'
|
|
304
|
+
: f.verb === 'answer' && !String(d.text || '').trim() ? 'Write the answer that came back.'
|
|
305
|
+
: f.verb === 'close' && !d.disposition && rfi.status !== 'answered' ? 'Choose why it’s closing.'
|
|
306
|
+
: f.verb === 'close' && (d.disposition || 'answered') !== 'answered' && !String(d.note || '').trim() ? 'Say why it’s being closed.'
|
|
307
|
+
: f.verb === 'reopen' && !String(d.why || '').trim() ? 'Say why it’s open again.' : null;
|
|
308
|
+
if (missing) { f.error = missing; paint(); announce(missing); return; }
|
|
309
|
+
const body = { ...identity(), operationKey: f.key, recordRevision: rfi.recordRevision };
|
|
310
|
+
if (f.verb === 'mark-sent') body.to = String(d.to).trim();
|
|
311
|
+
if (f.verb === 'answer') body.text = String(d.text).trim();
|
|
312
|
+
if (f.verb === 'close') { body.disposition = d.disposition || 'answered'; if (String(d.note || '').trim()) body.note = String(d.note).trim(); }
|
|
313
|
+
if (f.verb === 'reopen') body.why = String(d.why).trim();
|
|
314
|
+
f.sent = body; // what Try again resends, unchanged, under the same key
|
|
315
|
+
await sendForm(mine, f, body);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async function sendForm(mine, f, body) {
|
|
319
|
+
f.busy = true; f.error = null; f.stale = false; paint();
|
|
320
|
+
try {
|
|
321
|
+
const res = await api(`/api/projects/${encodeURIComponent(target().projectId)}/correspondence-rfis/${encodeURIComponent(f.rfiId)}/${f.verb}`,
|
|
322
|
+
{ method: 'POST', body: JSON.stringify(body) });
|
|
323
|
+
if (state !== mine) return;
|
|
324
|
+
const status = res.rfi.status;
|
|
325
|
+
const msg = { 'mark-sent': `${f.rfiId} marked as sent to ${body.to}.`, answer: `Answer saved for ${f.rfiId}.`,
|
|
326
|
+
close: `${f.rfiId} closed as ${dispositionLabel(body.disposition)}.`, reopen: `${f.rfiId} is open again.` }[f.verb];
|
|
327
|
+
const hidden = mine.filter === 'open' && status === 'closed' || mine.filter === 'closed' && status !== 'closed';
|
|
328
|
+
toast(hidden ? `${msg} It’s under ${status === 'closed' ? 'Closed' : 'Open'}.` : msg, 'ok');
|
|
329
|
+
mine.form = null;
|
|
330
|
+
mine.quietLoad = true;
|
|
331
|
+
await load();
|
|
332
|
+
if (state !== mine) return;
|
|
333
|
+
// Focus: the row's title, or (when the filter now hides it) the next row's title, else the heading.
|
|
334
|
+
const titles = [...mine.pane.querySelectorAll('[data-pr-title]')];
|
|
335
|
+
const own = titles.find((t) => t.getAttribute('data-pr-title') === f.rfiId);
|
|
336
|
+
(own || titles[0] || mine.pane.querySelector('[data-pr-heading]'))?.focus({ preventScroll: true });
|
|
337
|
+
announce(hidden ? `${msg} Moved to ${status === 'closed' ? 'Closed' : 'Open'}.` : `${f.rfiId} is ${STATUS[status].toLowerCase()}.`);
|
|
338
|
+
} catch (error) {
|
|
339
|
+
if (state !== mine) return;
|
|
340
|
+
f.busy = false;
|
|
341
|
+
if (refused(error)) {
|
|
342
|
+
f.error = said(error, 'FloLess couldn’t do that just now. Try again.');
|
|
343
|
+
f.stale = error.body.code === 'rfi-revision-stale' || error.body.code === 'project-changed';
|
|
344
|
+
f.uncertain = false; f.sent = null;
|
|
345
|
+
f.key = newKey(); // a refusal: the next send is a new intent, from what the form now holds
|
|
346
|
+
} else {
|
|
347
|
+
f.uncertain = true; // keep the key and the exact payload: Try again resends it unchanged
|
|
348
|
+
}
|
|
349
|
+
paint();
|
|
350
|
+
announce(f.uncertain ? 'FloLess couldn’t confirm that was saved.' : f.error);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
async function copyText(rfiId) {
|
|
355
|
+
try {
|
|
356
|
+
const text = await api(`/api/projects/${encodeURIComponent(target().projectId)}/correspondence-rfis/${encodeURIComponent(rfiId)}/text`);
|
|
357
|
+
const full = `${text.subject}\n\n${text.body}`;
|
|
358
|
+
try { await navigator.clipboard.writeText(full); toast('Email text copied. Paste it into your email.', 'ok'); }
|
|
359
|
+
catch {
|
|
360
|
+
// No clipboard here: the text is shown in the row, selected, to copy by hand.
|
|
361
|
+
if (!state) return;
|
|
362
|
+
state.copied = { rfiId, text: full };
|
|
363
|
+
state.focusAfter = '[data-pr-copied]';
|
|
364
|
+
paint();
|
|
365
|
+
const box = state.pane.querySelector('[data-pr-copied]');
|
|
366
|
+
box?.select?.();
|
|
367
|
+
toast('Select and copy this text.', 'info');
|
|
368
|
+
}
|
|
369
|
+
} catch (error) { toast(said(error, 'FloLess couldn’t put the email text together just now. Try again.'), 'warn'); }
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
async function repair() {
|
|
373
|
+
const mine = state;
|
|
374
|
+
try {
|
|
375
|
+
const res = await api(`/api/projects/${encodeURIComponent(target().projectId)}/correspondence-rfis/repair`, { method: 'POST', body: JSON.stringify(identity()) });
|
|
376
|
+
if (state !== mine) return;
|
|
377
|
+
if (res.outcome === 'still-quarantined') {
|
|
378
|
+
// Checked, and still not a file FloLess can read: say why, and keep it set aside.
|
|
379
|
+
mine.view = { ...mine.view, repairError: res.message || 'The file there still isn’t a valid RFI file.' };
|
|
380
|
+
mine.focusAfter = '[data-pr-repair]';
|
|
381
|
+
paint();
|
|
382
|
+
announce(mine.view.repairError);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
toast('The RFI file reads correctly now.', 'ok');
|
|
386
|
+
mine.view.repairError = null;
|
|
387
|
+
mine.focusAfter = '[data-pr-heading]';
|
|
388
|
+
await load();
|
|
389
|
+
} catch (error) {
|
|
390
|
+
if (state !== mine) return;
|
|
391
|
+
mine.view = { ...mine.view, repairError: said(error, 'FloLess couldn’t check the file just now. Try again.') };
|
|
392
|
+
mine.focusAfter = '[data-pr-repair]';
|
|
393
|
+
paint();
|
|
394
|
+
announce(mine.view.repairError);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// ── New RFI (the sheet: the form, or the Cite picker in its place) ──────────────────────────────────────────────
|
|
399
|
+
|
|
400
|
+
const $sheet = document.getElementById('project-rfi-sheet');
|
|
401
|
+
const $panel = $sheet?.querySelector('.pa-sheet');
|
|
402
|
+
const $title = document.getElementById('pr-title');
|
|
403
|
+
const $sub = document.getElementById('pr-sub');
|
|
404
|
+
const $body = document.getElementById('pr-body');
|
|
405
|
+
const $foot = document.getElementById('pr-foot');
|
|
406
|
+
let sheet = null; // { returnFocus, mode, key, title, question, to, cites, error, uncertain, busy, citable, query, picks, pickerError }
|
|
407
|
+
|
|
408
|
+
function openSheet(returnFocus, prefill = null) {
|
|
409
|
+
if (!$sheet || !target()) return;
|
|
410
|
+
sheet = { returnFocus: returnFocus || document.activeElement, mode: 'form', key: newKey(), title: prefill?.title || '', question: prefill?.question || '',
|
|
411
|
+
to: '', cites: prefill?.cites || [], error: null, uncertain: false, busy: false, citable: null, query: '', picks: null };
|
|
412
|
+
paintSheet();
|
|
413
|
+
$sheet.classList.add('show');
|
|
414
|
+
requestAnimationFrame(() => $body?.querySelector('[data-pr-field="title"]')?.focus());
|
|
415
|
+
}
|
|
416
|
+
function closeSheet({ restoreFocus = true } = {}) {
|
|
417
|
+
if (!$sheet?.classList.contains('show')) return;
|
|
418
|
+
$sheet.classList.remove('show');
|
|
419
|
+
const back = sheet?.returnFocus;
|
|
420
|
+
sheet = null;
|
|
421
|
+
if (restoreFocus) {
|
|
422
|
+
const id = back?.getAttribute?.('data-command-id');
|
|
423
|
+
(back && document.contains(back) ? back : id ? [...document.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === id) : null)?.focus?.();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function readSheet() {
|
|
427
|
+
if (!sheet || sheet.mode !== 'form' || sheet.uncertain) return;
|
|
428
|
+
for (const el of $body.querySelectorAll('[data-pr-field]')) sheet[el.getAttribute('data-pr-field')] = el.value;
|
|
429
|
+
}
|
|
430
|
+
const citeKey = (c) => (c.kind === 'knowledge-page' ? `k:${c.slug}` : `d:${c.linkedProjectUuid}:${c.pageId}:${c.sourceHash}`);
|
|
431
|
+
|
|
432
|
+
function paintSheet() {
|
|
433
|
+
const t = target();
|
|
434
|
+
if (!sheet || !t) return;
|
|
435
|
+
if (sheet.mode === 'pick') { paintPicker(); return; }
|
|
436
|
+
$title.textContent = 'New RFI';
|
|
437
|
+
$sub.textContent = `A question from “${t.name}”. FloLess keeps it and gives you the email text. It doesn’t send anything itself.`;
|
|
438
|
+
const ro = sheet.uncertain || sheet.busy ? ' readonly' : '';
|
|
439
|
+
const chips = sheet.cites.map((c, i) => `<span class="pw-chip pr-cite${c.changed ? ' is-muted' : ''}" role="listitem">${esc(citeLabel(c))}${c.changed ? ' · changed' : ''}
|
|
440
|
+
<button type="button" class="pr-chip-x" data-pr-uncite="${i}" aria-label="${esc(`Remove ${citeLabel(c)}`)}" data-command-id="shell.project-rfi-cite-remove#${esc(citeKey(c))}"
|
|
441
|
+
data-command-instance-label="${esc(citeLabel(c))}"${sheet.uncertain ? ' disabled' : ''}>✕</button></span>`).join('');
|
|
442
|
+
const full = sheet.cites.length >= MAX_CITES;
|
|
443
|
+
const banner = sheet.uncertain
|
|
444
|
+
? `<div class="pm-note pr-alert" role="alert">FloLess couldn’t confirm it was filed. It may already be in the list. To change something, choose Edit; FloLess will treat it as a new RFI.</div>`
|
|
445
|
+
: sheet.error ? `<div class="pm-note pr-alert" role="alert">${esc(sheet.error)}</div>` : '';
|
|
446
|
+
$body.innerHTML = `${banner}
|
|
447
|
+
<label class="pr-field">Title<input class="pr-input" data-pr-field="title" maxlength="120" value="${esc(sheet.title)}" data-command-id="shell.project-rfi-title"${ro}></label>
|
|
448
|
+
<label class="pr-field">Question<textarea class="pr-input pr-text" data-pr-field="question" rows="6" maxlength="4000" data-command-id="shell.project-rfi-question"${ro}>${esc(sheet.question)}</textarea></label>
|
|
449
|
+
<div class="pr-field"><span>Cited</span>
|
|
450
|
+
<div class="pr-cites" role="list" aria-label="Cited items">${chips || '<span class="pg-row-meta">Nothing cited yet. You can cite up to 5 items.</span>'}</div>
|
|
451
|
+
<p><button type="button" class="ghost" data-pr-cite="1" aria-haspopup="listbox" data-command-id="shell.project-rfi-cite"
|
|
452
|
+
data-tip="${full ? 'You can cite up to 5 items. Remove one to cite another.' : 'Cite a page of this project’s Knowledge or a saved sheet of a linked project'}"${full || sheet.uncertain ? ' aria-disabled="true"' : ''}>Cite…</button></p></div>
|
|
453
|
+
<label class="pr-field">To (optional)<input type="email" class="pr-input" data-pr-field="to" value="${esc(sheet.to)}" autocomplete="email" data-command-id="shell.project-rfi-to"${ro}>
|
|
454
|
+
<span class="pg-row-meta">Only needed to record who you sent it to.</span></label>`;
|
|
455
|
+
$foot.innerHTML = sheet.uncertain
|
|
456
|
+
? `<button type="button" class="ghost" data-pr-sheet-edit="1" data-command-id="shell.project-rfi-edit">Edit</button>
|
|
457
|
+
<button type="button" class="ghost" data-pr-sheet-check="1" data-command-id="shell.project-rfi-check-list">Check the list</button>
|
|
458
|
+
<button type="button" class="primary" data-pr-sheet-retry="1" data-command-id="shell.project-rfi-retry">Try again</button>`
|
|
459
|
+
: `<button type="button" class="ghost" data-pr-sheet-cancel="1" data-command-id="shell.project-rfi-cancel">Cancel</button>
|
|
460
|
+
<button type="button" class="ghost" data-pr-sheet-file="sent" data-command-id="shell.project-rfi-file-and-mark-sent"
|
|
461
|
+
data-tip="Files the RFI and records that you’ve sent it to this person. FloLess doesn’t send the email."${sheet.busy ? ' disabled' : ''}>File and mark sent</button>
|
|
462
|
+
<button type="button" class="primary" data-pr-sheet-file="file" data-command-id="shell.project-rfi-file"${sheet.busy ? ' disabled' : ''}>${sheet.busy ? 'Filing…' : 'File'}</button>`;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
async function loadCitable() {
|
|
466
|
+
const mine = sheet;
|
|
467
|
+
const t = target();
|
|
468
|
+
if (!mine || !t) return;
|
|
469
|
+
const generation = (mine.pickGeneration = (mine.pickGeneration || 0) + 1);
|
|
470
|
+
try {
|
|
471
|
+
const q = mine.query ? `?q=${encodeURIComponent(mine.query)}` : '';
|
|
472
|
+
const data = await api(`/api/projects/${encodeURIComponent(t.projectId)}/correspondence-rfis/citable${q}`);
|
|
473
|
+
if (sheet !== mine || mine.pickGeneration !== generation) return;
|
|
474
|
+
mine.citable = data; mine.pickerError = null;
|
|
475
|
+
} catch (error) {
|
|
476
|
+
if (sheet !== mine || mine.pickGeneration !== generation) return;
|
|
477
|
+
mine.pickerError = said(error, 'FloLess couldn’t list what can be cited just now. Try again.');
|
|
478
|
+
}
|
|
479
|
+
if (sheet === mine && mine.mode === 'pick') paintPicker();
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function optionHtml(c, picked) {
|
|
483
|
+
const k = citeKey(c);
|
|
484
|
+
return `<button type="button" class="pr-option" role="option" aria-selected="${picked}" data-pr-option="${esc(k)}"
|
|
485
|
+
data-command-id="shell.project-rfi-cite-option#${esc(k)}" data-command-instance-label="${esc(citeLabel(c))}">
|
|
486
|
+
<span class="pr-check" aria-hidden="true">${picked ? '✓' : ''}</span><span class="pg-row-title">${esc(c.kind === 'knowledge-page' ? c.title : c.sheet)}</span>
|
|
487
|
+
${c.kind === 'linked-drawing' && c.pageNumber ? `<span class="pg-row-meta">page ${esc(c.pageNumber)}</span>` : ''}</button>`;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function paintPicker() {
|
|
491
|
+
const mine = sheet;
|
|
492
|
+
$title.textContent = 'Cite';
|
|
493
|
+
$sub.textContent = 'A page of this project’s Knowledge, or a saved sheet of a project linked on its Modules step.';
|
|
494
|
+
const picks = mine.picks;
|
|
495
|
+
const search = `<input type="search" class="ws-landing-search pr-search" data-pr-search="1" placeholder="Filter" aria-label="Filter what can be cited" value="${esc(mine.query)}" data-command-id="shell.project-rfi-cite-search">`;
|
|
496
|
+
let groups = '';
|
|
497
|
+
if (mine.pickerError) groups = `<p class="pm-note pr-alert" role="alert">${esc(mine.pickerError)}</p>`;
|
|
498
|
+
else if (!mine.citable) groups = '<p class="pg-loading-line">Loading…</p>';
|
|
499
|
+
else {
|
|
500
|
+
const k = mine.citable.knowledge;
|
|
501
|
+
const kOptions = k.state === 'ok' ? k.pages.map((p) => ({ kind: 'knowledge-page', generationId: k.generationId, slug: p.slug, title: p.title })) : [];
|
|
502
|
+
const kBody = k.state === 'ok' ? (kOptions.length ? kOptions.map((c) => optionHtml(c, picks.has(citeKey(c)))).join('') : '<p class="pm-note">No page matches.</p>')
|
|
503
|
+
: k.state === 'none' ? '<p class="pm-note">This project has no published Knowledge pages yet.</p>'
|
|
504
|
+
: '<p class="pm-note">FloLess couldn’t list this project’s Knowledge just now.</p>';
|
|
505
|
+
groups = `<div role="group" aria-labelledby="pr-g-k"><p class="pr-group" id="pr-g-k">This project’s Knowledge</p>${kBody}</div>`;
|
|
506
|
+
mine.citable.linked.forEach((l, i) => {
|
|
507
|
+
const options = (l.sheets || []).map((s) => ({ kind: 'linked-drawing', linkedProjectUuid: l.projectUuid, linkedProjectName: l.name, pageId: s.pageId, sourceHash: s.sourceHash, sheet: s.sheet, pageNumber: s.pageNumber }));
|
|
508
|
+
const body = l.state === 'ok' ? (options.length ? options.map((c) => optionHtml(c, picks.has(citeKey(c)))).join('') : '<p class="pm-note">No sheet matches.</p>')
|
|
509
|
+
: l.state === 'empty' ? '<p class="pm-note">No saved sheets to cite yet. Open it and save its Drawing Filter.</p>'
|
|
510
|
+
: `<p class="pm-note">${esc(l.reason || 'Its sheets can’t be read just now.')}</p>${l.state === 'unavailable' ? `<p><button type="button" class="ghost" data-pr-cite-retry="1"
|
|
511
|
+
data-command-id="shell.project-rfi-cite-retry#${esc(l.projectUuid)}" data-command-instance-label="${esc(l.name)}">Try again</button></p>` : ''}`;
|
|
512
|
+
groups += `<div role="group" aria-labelledby="pr-g-${i}"><p class="pr-group" id="pr-g-${i}">Saved sheets in ${esc(l.name)}</p>${body}</div>`;
|
|
513
|
+
});
|
|
514
|
+
mine.options = new Map([...kOptions, ...mine.citable.linked.flatMap((l) => (l.sheets || []).map((s) => ({ kind: 'linked-drawing', linkedProjectUuid: l.projectUuid, linkedProjectName: l.name, pageId: s.pageId, sourceHash: s.sourceHash, sheet: s.sheet, pageNumber: s.pageNumber })))].map((c) => [citeKey(c), c]));
|
|
515
|
+
}
|
|
516
|
+
const hadFocus = document.activeElement?.hasAttribute?.('data-pr-search');
|
|
517
|
+
$body.innerHTML = `${search}<p class="sr-only pr-pick-live" role="status" aria-live="polite"></p><div class="pr-options" role="listbox" aria-multiselectable="true" aria-label="What can be cited">${groups}</div>`;
|
|
518
|
+
if (hadFocus) { const input = $body.querySelector('[data-pr-search]'); input?.focus(); input?.setSelectionRange?.(mine.query.length, mine.query.length); }
|
|
519
|
+
$foot.innerHTML = `<button type="button" class="ghost" data-pr-pick-back="1" data-command-id="shell.project-rfi-cite-back">← Back to the RFI</button>
|
|
520
|
+
<button type="button" class="primary" data-pr-pick-done="1" data-command-id="shell.project-rfi-cite-done">${picks.size ? `Cite ${picks.size}` : 'Cite none'}</button>`;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function openPicker() {
|
|
524
|
+
readSheet();
|
|
525
|
+
sheet.mode = 'pick';
|
|
526
|
+
sheet.picks = new Map(sheet.cites.map((c) => [citeKey(c), c]));
|
|
527
|
+
paintPicker();
|
|
528
|
+
requestAnimationFrame(() => $body.querySelector('[data-pr-search]')?.focus());
|
|
529
|
+
void loadCitable();
|
|
530
|
+
}
|
|
531
|
+
function closePicker(apply) {
|
|
532
|
+
if (apply) sheet.cites = [...sheet.picks.values()].map((c) => ({ ...c, changed: false }));
|
|
533
|
+
sheet.mode = 'form';
|
|
534
|
+
paintSheet();
|
|
535
|
+
requestAnimationFrame(() => $body.querySelector('[data-pr-cite]')?.focus());
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
async function fileRfi(markSent) {
|
|
539
|
+
const mine = sheet;
|
|
540
|
+
const t = target();
|
|
541
|
+
if (!mine || mine.busy || !t) return;
|
|
542
|
+
readSheet();
|
|
543
|
+
const title = mine.title.trim(), question = mine.question.trim(), to = mine.to.trim();
|
|
544
|
+
const problem = !title ? ['title', 'Give the RFI a title.'] : !question ? ['question', 'Write the question.']
|
|
545
|
+
: markSent && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(to) ? ['to', 'Add who you sent it to, or use File.'] : null;
|
|
546
|
+
if (problem) {
|
|
547
|
+
mine.error = problem[1]; paintSheet();
|
|
548
|
+
const field = $body.querySelector(`[data-pr-field="${problem[0]}"]`);
|
|
549
|
+
field?.setAttribute('aria-invalid', 'true'); field?.focus();
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
if (!mine.uncertain) mine.payload = { ...identity(), operationKey: mine.key, title, question,
|
|
553
|
+
citations: mine.cites.map((c) => (c.kind === 'knowledge-page' ? { kind: c.kind, generationId: c.generationId, slug: c.slug }
|
|
554
|
+
: { kind: c.kind, linkedProjectUuid: c.linkedProjectUuid, pageId: c.pageId, sourceHash: c.sourceHash })),
|
|
555
|
+
...(markSent ? { markSentTo: to } : {}) };
|
|
556
|
+
mine.busy = true; mine.error = null; paintSheet();
|
|
557
|
+
try {
|
|
558
|
+
const res = await api(`/api/projects/${encodeURIComponent(t.projectId)}/correspondence-rfis`, { method: 'POST', body: JSON.stringify(mine.payload) });
|
|
559
|
+
if (sheet !== mine) return;
|
|
560
|
+
const id = res.rfi.id;
|
|
561
|
+
closeSheet({ restoreFocus: false });
|
|
562
|
+
toast(mine.payload.markSentTo ? `${id} filed and marked as sent to ${mine.payload.markSentTo}. FloLess hasn’t sent anything.` : `${id} filed. Copy its email text to send it.`, 'ok');
|
|
563
|
+
if (state) {
|
|
564
|
+
if (state.filter === 'closed') state.filter = 'open';
|
|
565
|
+
state.quietLoad = true;
|
|
566
|
+
state.focusAfter = `[data-pr-title="${id}"]`;
|
|
567
|
+
await load();
|
|
568
|
+
announce(`${id} filed.`);
|
|
569
|
+
}
|
|
570
|
+
} catch (error) {
|
|
571
|
+
if (sheet !== mine) return;
|
|
572
|
+
mine.busy = false;
|
|
573
|
+
if (refused(error)) {
|
|
574
|
+
mine.error = said(error, 'FloLess couldn’t file it just now. Try again.');
|
|
575
|
+
mine.uncertain = false;
|
|
576
|
+
mine.key = newKey(); // the next send after a refusal is a new intent
|
|
577
|
+
if (/^citation-/.test(error.body.code || '')) mine.cites = mine.cites.map((c) => ({ ...c, changed: true }));
|
|
578
|
+
} else {
|
|
579
|
+
mine.uncertain = true; // same key, same payload on Try again
|
|
580
|
+
}
|
|
581
|
+
paintSheet();
|
|
582
|
+
($foot.querySelector(mine.uncertain ? '[data-pr-sheet-retry]' : '[data-pr-sheet-file="file"]'))?.focus();
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// ── events ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
587
|
+
|
|
588
|
+
document.addEventListener('click', (event) => {
|
|
589
|
+
const t = event.target;
|
|
590
|
+
if (sheet && $sheet?.contains(t)) {
|
|
591
|
+
if (t.closest('#pr-close') || t.closest('[data-pr-sheet-cancel]')) { closeSheet(); return; }
|
|
592
|
+
if (t === $sheet) { closeSheet(); return; }
|
|
593
|
+
const file = t.closest('[data-pr-sheet-file]');
|
|
594
|
+
if (file) { void fileRfi(file.getAttribute('data-pr-sheet-file') === 'sent'); return; }
|
|
595
|
+
if (t.closest('[data-pr-sheet-retry]')) { void fileRfi(!!sheet.payload?.markSentTo); return; }
|
|
596
|
+
if (t.closest('[data-pr-sheet-edit]')) { sheet.uncertain = false; sheet.key = newKey(); paintSheet(); $body.querySelector('[data-pr-field="title"]')?.focus(); return; }
|
|
597
|
+
if (t.closest('[data-pr-sheet-check]')) { closeSheet(); if (state) void load(); return; }
|
|
598
|
+
const cite = t.closest('[data-pr-cite]');
|
|
599
|
+
if (cite) { if (cite.getAttribute('aria-disabled') === 'true') { toast('You can cite up to 5 items. Remove one to cite another.', 'info'); return; } openPicker(); return; }
|
|
600
|
+
const uncite = t.closest('[data-pr-uncite]');
|
|
601
|
+
if (uncite) { readSheet(); sheet.cites.splice(Number(uncite.getAttribute('data-pr-uncite')), 1); paintSheet(); $body.querySelector('[data-pr-cite]')?.focus(); return; }
|
|
602
|
+
const option = t.closest('[data-pr-option]');
|
|
603
|
+
if (option) {
|
|
604
|
+
const k = option.getAttribute('data-pr-option');
|
|
605
|
+
if (sheet.picks.has(k)) sheet.picks.delete(k);
|
|
606
|
+
else if (sheet.picks.size >= MAX_CITES) { const live = $body.querySelector('.pr-pick-live'); if (live) live.textContent = 'You can cite up to 5 items.'; return; }
|
|
607
|
+
else sheet.picks.set(k, sheet.options.get(k));
|
|
608
|
+
paintPicker();
|
|
609
|
+
$body.querySelector(`[data-pr-option="${CSS.escape(k)}"]`)?.focus();
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
if (t.closest('[data-pr-cite-retry]')) { sheet.citable = null; paintPicker(); void loadCitable(); return; }
|
|
613
|
+
if (t.closest('[data-pr-pick-back]')) { closePicker(false); return; }
|
|
614
|
+
if (t.closest('[data-pr-pick-done]')) { closePicker(true); return; }
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
if (!state || !state.pane.contains(t)) return;
|
|
618
|
+
if (t.closest('[data-pr-new]')) { event.preventDefault(); openSheet(t.closest('[data-pr-new]')); return; }
|
|
619
|
+
const filter = t.closest('[data-pr-filter]');
|
|
620
|
+
if (filter) {
|
|
621
|
+
readDraft(); // an open form keeps what was typed across the repaint
|
|
622
|
+
state.filter = filter.getAttribute('data-pr-filter');
|
|
623
|
+
state.focusAfter = `[data-pr-filter="${state.filter}"][aria-pressed]`;
|
|
624
|
+
paint();
|
|
625
|
+
const n = visible(state.view.data.rfis, state.filter).length;
|
|
626
|
+
announce(`Showing ${n} ${state.filter === 'all' ? '' : `${state.filter} `}RFI${n === 1 ? '' : 's'}`);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
const verb = t.closest('[data-pr-verb]');
|
|
630
|
+
if (verb) { openForm(verb.getAttribute('data-pr-rfi'), verb.getAttribute('data-pr-verb')); return; }
|
|
631
|
+
if (t.closest('[data-pr-form-cancel]')) { closeForm(); return; }
|
|
632
|
+
if (t.closest('[data-pr-form-submit]')) { void submitForm(); return; }
|
|
633
|
+
if (t.closest('[data-pr-form-edit]')) { const f = state.form; f.uncertain = false; f.sent = null; f.key = newKey(); f.error = null;
|
|
634
|
+
state.focusAfter = f.verb === 'close' ? '.pr-form [data-pr-disposition]' : '.pr-form [data-pr-input]'; paint(); return; }
|
|
635
|
+
if (t.closest('[data-pr-form-again]')) { readDraft(); const f = state.form; f.stale = false; f.error = null; void load().then(() => { if (state?.form === f) paint(); }); return; }
|
|
636
|
+
const radio = t.closest('[data-pr-disposition]');
|
|
637
|
+
if (radio) { if (state.form.uncertain || radio.disabled) return; readDraft(); state.form.draft.disposition = radio.getAttribute('data-pr-disposition'); state.form.error = null;
|
|
638
|
+
state.focusAfter = `[data-pr-disposition="${state.form.draft.disposition}"]`; paint(); return; }
|
|
639
|
+
const copy = t.closest('[data-pr-copy]');
|
|
640
|
+
if (copy) { void copyText(copy.getAttribute('data-pr-copy')); return; }
|
|
641
|
+
const again = t.closest('[data-pr-again]');
|
|
642
|
+
if (again) {
|
|
643
|
+
const rfi = state.view.data.rfis.find((r) => r.id === again.getAttribute('data-pr-again'));
|
|
644
|
+
if (rfi) openSheet(again, { title: rfi.title, question: rfi.question,
|
|
645
|
+
// A page that reads current in a newer Knowledge version is cited there: a filing names the version published now.
|
|
646
|
+
cites: rfi.citations.filter((c) => c.state === 'current').map(({ state: _s, reason: _r, refileGenerationId, ...c }) => (
|
|
647
|
+
c.kind === 'knowledge-page' && refileGenerationId ? { ...c, generationId: refileGenerationId } : c)) });
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
if (t.closest('[data-pr-retry]')) { state.view = { status: 'loading', data: null }; paint(); void load(); return; }
|
|
651
|
+
if (t.closest('[data-pr-repair]')) { void repair(); }
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
document.addEventListener('input', (event) => {
|
|
655
|
+
const search = event.target.closest?.('[data-pr-search]');
|
|
656
|
+
if (search && sheet) {
|
|
657
|
+
sheet.query = search.value;
|
|
658
|
+
clearTimeout(sheet.timer);
|
|
659
|
+
sheet.timer = setTimeout(() => void loadCitable(), 200);
|
|
660
|
+
}
|
|
661
|
+
if (sheet && event.target.closest?.('[data-pr-field]')) event.target.removeAttribute('aria-invalid');
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
document.addEventListener('keydown', (event) => {
|
|
665
|
+
if (sheet && $sheet?.classList.contains('show')) {
|
|
666
|
+
if (event.key === 'Escape') { event.preventDefault(); if (sheet.mode === 'pick') closePicker(false); else closeSheet(); return; }
|
|
667
|
+
if (event.key === 'Tab' && $panel) {
|
|
668
|
+
// Keep the keyboard inside the sheet.
|
|
669
|
+
const focusables = [...$panel.querySelectorAll('button:not([disabled]), input, textarea, [tabindex="0"]')].filter((el) => el.offsetParent !== null || el === document.activeElement);
|
|
670
|
+
if (!focusables.length) return;
|
|
671
|
+
const first = focusables[0], last = focusables[focusables.length - 1];
|
|
672
|
+
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
|
673
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
|
674
|
+
}
|
|
675
|
+
if ((event.key === 'ArrowDown' || event.key === 'ArrowUp') && event.target.closest?.('[data-pr-option], [data-pr-search]')) {
|
|
676
|
+
const options = [...$body.querySelectorAll('[data-pr-option]')];
|
|
677
|
+
const i = options.indexOf(document.activeElement);
|
|
678
|
+
const next = event.key === 'ArrowDown' ? options[Math.min(options.length - 1, i + 1)] : options[Math.max(0, i - 1)];
|
|
679
|
+
if (next) { event.preventDefault(); next.focus(); }
|
|
680
|
+
}
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (!state || !state.pane.contains(event.target)) return;
|
|
684
|
+
if (event.key === 'Escape' && state.form && event.target.closest('.pr-form')) { event.preventDefault(); closeForm(); return; }
|
|
685
|
+
// The disposition choice is a radio group: arrows move and choose.
|
|
686
|
+
const radio = event.target.closest?.('[data-pr-disposition]');
|
|
687
|
+
if (radio && ['ArrowDown', 'ArrowRight', 'ArrowUp', 'ArrowLeft'].includes(event.key)) {
|
|
688
|
+
const radios = [...state.pane.querySelectorAll('[data-pr-disposition]')];
|
|
689
|
+
const i = radios.indexOf(radio);
|
|
690
|
+
const next = radios[(i + (event.key === 'ArrowDown' || event.key === 'ArrowRight' ? 1 : radios.length - 1)) % radios.length];
|
|
691
|
+
event.preventDefault();
|
|
692
|
+
next.click();
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* The sentence a Duplicate or Import adds about a General project's RFIs (#2470 R6.6). Null when there is nothing to
|
|
698
|
+
* say. A source that could not be carried is said, never turned into silence.
|
|
699
|
+
*/
|
|
700
|
+
function transferNote(raw, operation = 'duplicate') {
|
|
701
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
702
|
+
if (raw.outcome === 'complete' && raw.carried > 0) {
|
|
703
|
+
return { text: `${raw.carried} RFI${raw.carried === 1 ? '' : 's'} came with it, open again; ${raw.carried === 1 ? 'its' : 'their'} sends and answers stay with the original.`, warn: false };
|
|
704
|
+
}
|
|
705
|
+
if (raw.outcome === 'refused') {
|
|
706
|
+
const where = operation === 'import' ? 'They are still in the archive.' : 'The original keeps them.';
|
|
707
|
+
const why = raw.reason === 'newer-version' ? 'they were saved by a newer FloLess' : raw.reason === 'poisoned' ? 'the RFI file was set aside as unreadable' : 'the RFI file couldn’t be read';
|
|
708
|
+
return { text: `Its RFIs didn’t come with it: ${why}. ${where}`, warn: true };
|
|
709
|
+
}
|
|
710
|
+
return null;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
window.addEventListener('floless:projects-changed', refresh);
|
|
714
|
+
window.flolessProjectRfis = { render, refresh, html, transferNote };
|
|
715
|
+
})();
|