@floless/app 0.156.0 → 0.158.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/cli-actions.mjs +28 -5
- package/dist/floless-server.cjs +110947 -67461
- package/dist/schemas/drawing-check.profile.v1.schema.json +15 -2
- package/dist/schemas/steel.model.v2.schema.json +25 -1
- package/dist/skills/floless-app-actions/SKILL.md +82 -17
- package/dist/skills/floless-app-knowledge/SKILL.md +34 -2
- package/dist/skills/floless-app-knowledge/references/schema.md +4 -1
- package/dist/skills/floless-app-new-workflow/SKILL.md +23 -7
- package/dist/skills/floless-app-onboarding/SKILL.md +31 -1
- package/dist/skills/floless-app-report-issue/SKILL.md +3 -3
- package/dist/skills/floless-app-rfi/SKILL.md +40 -6
- package/dist/skills/floless-app-routines/SKILL.md +9 -2
- package/dist/skills/floless-app-steel-model/SKILL.md +35 -1
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +4 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +51 -1
- package/dist/skills/floless-app-tweak-contract/SKILL.md +25 -5
- package/dist/skills/floless-app-workflows/SKILL.md +46 -10
- package/dist/skills/floless-app-workflows/references/agent-steps.md +119 -0
- package/dist/web/agent-steps.js +864 -47
- package/dist/web/agents.js +28 -8
- package/dist/web/app.css +620 -17
- package/dist/web/app.js +110 -11
- package/dist/web/aware-update-client.js +1 -0
- package/dist/web/aware.js +921 -220
- package/dist/web/chat-landing-scene.js +372 -0
- package/dist/web/chat.css +263 -1
- package/dist/web/chat.js +2660 -86
- package/dist/web/commands-drawing-check.js +17 -0
- package/dist/web/commands-shell.js +1059 -8
- package/dist/web/commands-steel.js +6 -0
- package/dist/web/connections.js +1 -0
- package/dist/web/drawing-check-editor.html +33 -5
- package/dist/web/drawing-check-editor.js +538 -22
- package/dist/web/drawing-check-overlay.js +13 -0
- package/dist/web/flo-avatar.js +28 -3
- package/dist/web/guide.js +7 -2
- package/dist/web/index.html +143 -8
- package/dist/web/instructor.js +4 -4
- package/dist/web/kb-categories.js +351 -0
- package/dist/web/kb-graph-worker.js +73 -0
- package/dist/web/model-view-query.js +12 -2
- package/dist/web/pages.js +978 -39
- package/dist/web/panels.js +5 -2
- package/dist/web/parser-setup-recovery.js +12 -4
- package/dist/web/project-access.js +549 -0
- package/dist/web/run-page-view.js +353 -0
- package/dist/web/startup-admission.js +132 -0
- package/dist/web/steel-3d-core.js +9 -0
- package/dist/web/steel-editor.html +681 -22
- package/dist/web/steel-model-v2-commands.js +63 -5
- package/dist/web/step-rename.js +287 -0
- package/dist/web/tab-signal.js +323 -0
- package/dist/web/terminal-requests.js +103 -13
- package/dist/web/tool-updates.js +1 -0
- package/dist/web/workspace-root-management.js +39 -0
- package/dist/web/workspaces.js +2883 -146
- package/launch-starting-page.mjs +181 -0
- package/launch.mjs +97 -12
- package/package.json +5 -1
package/dist/web/pages.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
(() => {
|
|
16
16
|
const bridge = window.flolessBridge || {};
|
|
17
17
|
const api = bridge.api || (async (path, opts = {}) => {
|
|
18
|
+
await globalThis.flolessStartupAdmission?.admit(path, { method: opts?.method, signal: opts?.signal });
|
|
18
19
|
const res = await fetch(path, { ...opts, headers: { 'Content-Type': 'application/json', ...(opts.headers || {}) } });
|
|
19
20
|
const body = await res.json().catch(() => ({}));
|
|
20
21
|
if (!res.ok || body.ok === false) { const err = new Error(body.error || `HTTP ${res.status}`); err.status = res.status; err.body = body; throw err; }
|
|
@@ -51,12 +52,43 @@
|
|
|
51
52
|
}
|
|
52
53
|
const versionsText = (n) => `${n} version${n === 1 ? '' : 's'}`;
|
|
53
54
|
|
|
55
|
+
// #2262 slice 6: where a version's sequence order came from. FloLess's claim, drawn outside the Page's frame; it says
|
|
56
|
+
// where the order DATA came from, and never that the Page plays it faithfully.
|
|
57
|
+
const SEQ_LABEL = { read: 'Order read', assumed: 'Order assumed', unverified: 'Order not checked', unreadable: 'Order unreadable' };
|
|
58
|
+
// A read that stopped at a limit covers only part of its source; a state FloLess does not know claims nothing.
|
|
59
|
+
const seqLabel = (seq) => (seq?.order === 'read' && seq.partial ? 'Order partly read' : SEQ_LABEL[seq?.order] || 'Order not checked');
|
|
60
|
+
const num = (n) => Number(n || 0).toLocaleString('en');
|
|
61
|
+
function sequenceSentence(seq, source) {
|
|
62
|
+
if (!seq) return '';
|
|
63
|
+
if (seq.order === 'unreadable') return `${seq.reason} The Page may still play an order, but FloLess can’t say where it came from.`;
|
|
64
|
+
const parts = [];
|
|
65
|
+
const c = seq.counts || {};
|
|
66
|
+
if (seq.order === 'read') parts.push(`FloLess read this order from ${seq.from}${seq.partial ? ', but only part of it: the read stopped at a limit' : ''}.`, ...(seq.notes || []));
|
|
67
|
+
else if (seq.order === 'assumed') {
|
|
68
|
+
const by = seq.by === 'ai' ? 'the AI' : source?.kind === 'workflow' ? 'the workflow that made this Page' : 'whoever made this Page';
|
|
69
|
+
parts.push(`This order was assumed by ${by}, not read from a source: ${seq.why}`);
|
|
70
|
+
} else parts.push('This Page says its order was read from a source, but FloLess did not build its sequence file, so treat the order as assumed.');
|
|
71
|
+
parts.push(`${num(c.steps)} step${c.steps === 1 ? '' : 's'}, ${num(c.ids)} item${c.ids === 1 ? '' : 's'}.`);
|
|
72
|
+
// The file's own reasons (its sample), never a reason assumed for all of them.
|
|
73
|
+
const reasons = Array.isArray(seq.leftOutWhy) ? seq.leftOutWhy : [];
|
|
74
|
+
const why = !reasons.length ? '' : c.leftOut === 1 ? ` (${reasons[0]})` : ` (reasons include: ${reasons.join('; ')})`;
|
|
75
|
+
if (c.leftOut) parts.push(`${c.leftOut === 1 ? '1 item was' : `${num(c.leftOut)} items were`} left out${why}.`);
|
|
76
|
+
if (c.conflicts) parts.push(c.conflicts === 1 ? '1 item had more than one value and was placed by the first.' : `${num(c.conflicts)} items had more than one value and were placed by the first.`);
|
|
77
|
+
const m = seq.match;
|
|
78
|
+
if (m && m.files.length) parts.push(`${num(m.found)} of ${num(m.found + m.missing + m.ambiguous)} step items match a named part in ${m.files.join(', ')} (by name only)${m.ambiguous ? `; ${num(m.ambiguous)} match more than one` : ''}.`);
|
|
79
|
+
if (m?.unreadable?.length) parts.push(`FloLess could not read ${m.unreadable.join(', ')}, so nothing was matched against ${m.unreadable.length === 1 ? 'it' : 'them'}.`);
|
|
80
|
+
parts.push('FloLess doesn’t check how the Page plays it.');
|
|
81
|
+
return parts.join(' ');
|
|
82
|
+
}
|
|
83
|
+
|
|
54
84
|
// ── Lists ────────────────────────────────────────────────────────────────────────────────────────
|
|
55
85
|
|
|
56
86
|
/** Live lists, re-read when a Page changes (deleted from the viewer, etc.). */
|
|
57
87
|
const lists = new Set();
|
|
58
88
|
|
|
59
|
-
|
|
89
|
+
// #2262 slice 4: a list row says where its link stands — never "Shared" for a link that isn't open yet or is going.
|
|
90
|
+
const LIST_CHIP = { live: 'Shared', 'pending-publish': 'Publishing…', 'pending-revoke': 'Revoke waiting' };
|
|
91
|
+
function rowHtml(home, p, view = {}) {
|
|
60
92
|
if (p.damaged) {
|
|
61
93
|
// Delete is offered only where deleting loses nothing good: a broken or record-less Page. A Page saved
|
|
62
94
|
// by a newer FloLess is fine (update to open it), and a shortcut folder points somewhere else.
|
|
@@ -71,10 +103,12 @@
|
|
|
71
103
|
${canDelete ? `<button type="button" class="ghost pg-row-delete" data-command-id="shell.page-delete-unreadable#${esc(p.id)}" data-home="${esc(home)}" data-page="${esc(p.id)}">Delete</button>` : ''}
|
|
72
104
|
</div>`;
|
|
73
105
|
}
|
|
74
|
-
const meta = [sourceText(p.source), versionsText(p.versionCount), `Updated ${ago(p.updatedAt)}`].filter(Boolean).join(' · ');
|
|
106
|
+
const meta = [...(view.lead || [sourceText(p.source)]), versionsText(p.versionCount), p.sequence ? 'Has an order' : '', `Updated ${ago(p.updatedAt)}`].filter(Boolean).join(' · ');
|
|
107
|
+
// Only an order FloLess did not read is flagged on the row; a read one is the plain "Has an order".
|
|
108
|
+
const seqChip = p.sequence && (p.sequence !== 'read' || p.sequencePartial) ? `<span class="pg-seq-chip is-warn">${esc(seqLabel({ order: p.sequence, partial: p.sequencePartial }))}</span>` : '';
|
|
75
109
|
return `<div class="pg-row" role="listitem">
|
|
76
110
|
<button type="button" class="pg-row-open" data-command-id="shell.page-open#${esc(p.id)}" data-command-instance-label="${esc(p.title)}" data-home="${esc(home)}" data-page="${esc(p.id)}">
|
|
77
|
-
<span class="pg-row-line"><span class="pg-row-title">${esc(p.title)}</span>${p.aiMade ? '<span class="pg-ai-badge">AI-made</span>' : ''}</span>
|
|
111
|
+
<span class="pg-row-line"><span class="pg-row-title">${esc(p.title)}</span>${p.aiMade ? '<span class="pg-ai-badge">AI-made</span>' : ''}${seqChip}${p.shareState && p.shareState !== 'revoked' ? `<span class="sl-chip" data-state="${esc(p.shareState)}">${esc(LIST_CHIP[p.shareState] || 'Shared')}</span>` : ''}</span>
|
|
78
112
|
<span class="pg-row-meta" data-tip="${esc(when(p.updatedAt))}">${esc(meta)}</span>
|
|
79
113
|
</button>
|
|
80
114
|
</div>`;
|
|
@@ -86,7 +120,7 @@
|
|
|
86
120
|
if (w.page && typeof w.home === 'string') return rowHtml(w.home, w.page);
|
|
87
121
|
return `<div class="pg-row pg-row-damaged" role="listitem">
|
|
88
122
|
<div class="pg-row-text"><span class="pg-row-title">${esc(w.workflowName)}: its Page can’t be opened</span>
|
|
89
|
-
<span class="pg-row-meta">${esc(w.note || 'FloLess couldn’t read this workflow’s Page.')}
|
|
123
|
+
<span class="pg-row-meta">${esc(w.note || 'FloLess couldn’t read this workflow’s Page.')} Run the workflow again to save a new version; if this keeps happening, use Report an issue.</span></div>
|
|
90
124
|
</div>`;
|
|
91
125
|
}
|
|
92
126
|
|
|
@@ -117,8 +151,11 @@
|
|
|
117
151
|
// The Pages this home's workflows keep in their own folders (each names its own home).
|
|
118
152
|
const fromWorkflows = Array.isArray(body.workflowPages) ? body.workflowPages.filter((w) => w && typeof w.workflowName === 'string') : [];
|
|
119
153
|
const workflowsNote = typeof body.workflowPagesNote === 'string' ? body.workflowPagesNote : '';
|
|
154
|
+
// My shared links lists the account's links, not this home's Pages, so an empty list still offers it.
|
|
155
|
+
const tools = '<div class="pg-tools"><button type="button" class="ghost pg-shared-links" data-command-id="shell.shared-links-open">My shared links</button></div>';
|
|
120
156
|
if (!pages.length && !fromWorkflows.length && !workflowsNote) {
|
|
121
|
-
|
|
157
|
+
// The landing hides an empty Pages section entirely; the AI chat still opens My shared links there.
|
|
158
|
+
container.innerHTML = opts.hideWhenEmpty ? '' : `${opts.headHtml || ''}${tools}<div class="pg-empty">
|
|
122
159
|
<p class="pg-empty-title">No Pages yet</p>
|
|
123
160
|
<p>Reports, dashboards and summaries saved in this home appear here with their versions.</p>
|
|
124
161
|
</div>`;
|
|
@@ -131,12 +168,112 @@
|
|
|
131
168
|
const workflows = fromWorkflows.length || workflowsNote ? `<div class="pg-group-label">From workflows</div>
|
|
132
169
|
${workflowsNote ? `<p class="pg-empty">${esc(workflowsNote)}</p>` : ''}
|
|
133
170
|
${fromWorkflows.length ? `<div class="pg-list" role="list" aria-label="Pages from workflows">${fromWorkflows.map(workflowRowHtml).join('')}</div>` : ''}` : '';
|
|
134
|
-
container.innerHTML = `${opts.headHtml || ''}${own}${workflows}`;
|
|
171
|
+
container.innerHTML = `${opts.headHtml || ''}${tools}${own}${workflows}`;
|
|
135
172
|
if (focusedPageCommand && document.activeElement === document.body && container.isConnected) {
|
|
136
173
|
[...container.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === focusedPageCommand)?.focus({ preventScroll: true });
|
|
137
174
|
}
|
|
138
175
|
}
|
|
139
176
|
|
|
177
|
+
// ── The Workflows landing's Pages tab (#2568): every workflow's Page, wherever it is kept ─────────────────────────
|
|
178
|
+
|
|
179
|
+
/** The last list read, so a landing repaint shows it at once while the fresh one loads — for this workspace only. */
|
|
180
|
+
let wfRowsCache = null;
|
|
181
|
+
let wfNote = '';
|
|
182
|
+
let wfRoot = null;
|
|
183
|
+
// A change of workspace (the first word about it included) drops what was read and redraws each open list ONCE; an
|
|
184
|
+
// answer still out for the workspace that was open before is simply dropped (see renderWorkflowsList), never re-asked.
|
|
185
|
+
window.addEventListener('floless:workspace-root-state', (event) => {
|
|
186
|
+
const root = event.detail && event.detail.root;
|
|
187
|
+
const id = root ? `${root.rootId}#${root.generation}` : null;
|
|
188
|
+
if (id === wfRoot) return;
|
|
189
|
+
wfRoot = id;
|
|
190
|
+
wfRowsCache = null; wfNote = '';
|
|
191
|
+
for (const e of [...lists]) {
|
|
192
|
+
if (e.kind !== 'workflows') continue;
|
|
193
|
+
if (!e.container.isConnected) { lists.delete(e); continue; }
|
|
194
|
+
void renderWorkflowsList(e.container, e.opts);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
const cachedRows = () => wfRowsCache;
|
|
198
|
+
const ownerText = (w) => (w.owner?.kind === 'project' ? (w.owner.name || 'A project') : 'Workspace');
|
|
199
|
+
|
|
200
|
+
function workflowPageRowHtml(w) {
|
|
201
|
+
if (!(w.page && typeof w.home === 'string')) return workflowRowHtml(w);
|
|
202
|
+
// A workflow's Page is titled after the workflow, so its name is repeated only when the two differ.
|
|
203
|
+
const named = w.page?.title && w.page.title.trim() === String(w.workflowName).trim() ? [] : [w.workflowName];
|
|
204
|
+
return rowHtml(w.home, w.page, { lead: [...named, ownerText(w), ...(w.archived ? ['Archived'] : [])] });
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function wfMatches(w, terms) {
|
|
208
|
+
const hay = `${w.workflowName} ${w.page?.title || ''} ${ownerText(w)}`.toLowerCase();
|
|
209
|
+
return terms.every((t) => hay.includes(t));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function paintWorkflowsList(container, rows, opts) {
|
|
213
|
+
const query = String(opts?.getQuery?.() ?? '').trim();
|
|
214
|
+
const focused = container.contains(document.activeElement) ? document.activeElement?.getAttribute('data-command-id') : null;
|
|
215
|
+
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
216
|
+
const shown = rows.filter((w) => wfMatches(w, terms));
|
|
217
|
+
container.dataset.pgwfState = 'ready';
|
|
218
|
+
if (!rows.length) {
|
|
219
|
+
container.innerHTML = `<div class="pg-empty"><p>No workflow has a Page yet. Every successful run of a workflow that makes a report adds a version to its Page.</p>
|
|
220
|
+
<p><button type="button" class="ghost pg-wf-act" data-act="show-workflows" data-command-id="shell.workflows-landing-pages-show-workflows">Show workflows</button></p></div>`;
|
|
221
|
+
} else if (!shown.length) {
|
|
222
|
+
container.innerHTML = '<div class="pg-empty" role="status"><p class="pg-wf-nomatch"></p><p><button type="button" class="ghost pg-wf-act" data-act="clear-search" data-command-id="shell.workflows-landing-pages-clear-search">Clear search</button></p></div>';
|
|
223
|
+
container.querySelector('.pg-wf-nomatch').textContent = `No Page matches “${query}”.`; // text, never markup: it echoes what was typed
|
|
224
|
+
} else {
|
|
225
|
+
container.innerHTML = `<div class="pg-list" role="list" aria-label="Pages from workflows">${shown.map(workflowPageRowHtml).join('')}</div>`;
|
|
226
|
+
}
|
|
227
|
+
if (wfNote) {
|
|
228
|
+
const note = document.createElement('p');
|
|
229
|
+
note.className = 'pg-wf-note';
|
|
230
|
+
note.setAttribute('role', 'status');
|
|
231
|
+
note.textContent = wfNote;
|
|
232
|
+
container.prepend(note);
|
|
233
|
+
}
|
|
234
|
+
if (focused && document.activeElement === document.body && container.isConnected) {
|
|
235
|
+
[...container.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === focused)?.focus({ preventScroll: true });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Draw the list again from what was last read (a search, a tab switch back): nothing is fetched. */
|
|
240
|
+
function repaintWorkflowsList(container) {
|
|
241
|
+
const entry = [...lists].find((e) => e.kind === 'workflows' && e.container === container);
|
|
242
|
+
if (entry && cachedRows() && container.dataset.pgwfState === 'ready') paintWorkflowsList(container, cachedRows(), entry.opts);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Render every workflow's Page into `container`. `opts.getQuery()` is the landing's search text; `opts.onAction(act)`
|
|
247
|
+
* hears the buttons that leave this list ('show-workflows', 'clear-search'). Registered with the live lists, so a
|
|
248
|
+
* Page that changes re-reads it.
|
|
249
|
+
*/
|
|
250
|
+
async function renderWorkflowsList(container, opts = {}) {
|
|
251
|
+
if (!container) return;
|
|
252
|
+
const entry = { container, kind: 'workflows', opts };
|
|
253
|
+
for (const e of [...lists]) if (e.container === container) lists.delete(e);
|
|
254
|
+
lists.add(entry);
|
|
255
|
+
const token = (container.dataset.pagesToken = String(Math.random()));
|
|
256
|
+
if (cachedRows()) paintWorkflowsList(container, cachedRows(), opts);
|
|
257
|
+
else { container.dataset.pgwfState = 'loading'; container.innerHTML = '<p class="pg-loading-line">Loading Pages…</p>'; }
|
|
258
|
+
// An answer is used only by the request still current for this list, while the list is on screen. A workspace change
|
|
259
|
+
// redraws every open list (a new token), so an answer read for the workspace that was open before is dropped here.
|
|
260
|
+
const current = () => container.dataset.pagesToken === token && container.isConnected;
|
|
261
|
+
let body;
|
|
262
|
+
try { body = await api('/api/pages/workflows'); } catch (err) {
|
|
263
|
+
if (!current()) return;
|
|
264
|
+
console.warn('The workflows’ Pages could not be read', err);
|
|
265
|
+
wfRowsCache = null; wfNote = '';
|
|
266
|
+
container.dataset.pgwfState = 'error';
|
|
267
|
+
container.innerHTML = `<div class="pg-empty" role="alert"><p>FloLess couldn’t load the workflows’ Pages. Check that FloLess is running, then try again.</p>
|
|
268
|
+
<p><button type="button" class="ghost pg-wf-act" data-act="retry" data-command-id="shell.workflows-landing-pages-retry">Try again</button></p></div>`;
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (!current()) return;
|
|
272
|
+
wfRowsCache = (Array.isArray(body.workflowPages) ? body.workflowPages : []).filter((w) => w && typeof w.workflowName === 'string');
|
|
273
|
+
wfNote = typeof body.note === 'string' ? body.note : '';
|
|
274
|
+
paintWorkflowsList(container, wfRowsCache, opts);
|
|
275
|
+
}
|
|
276
|
+
|
|
140
277
|
/** Tell the rest of the window a Page is gone, so nothing keeps offering to open it (the report viewer's links). */
|
|
141
278
|
function announceDeleted(home, id) {
|
|
142
279
|
window.dispatchEvent(new CustomEvent('floless:page-deleted', { detail: { home, id } }));
|
|
@@ -145,7 +282,8 @@
|
|
|
145
282
|
function refreshLists() {
|
|
146
283
|
for (const e of [...lists]) {
|
|
147
284
|
if (!e.container.isConnected) { lists.delete(e); continue; }
|
|
148
|
-
|
|
285
|
+
if (e.kind === 'workflows') renderWorkflowsList(e.container, e.opts);
|
|
286
|
+
else renderList(e.container, e.home, e.opts);
|
|
149
287
|
}
|
|
150
288
|
}
|
|
151
289
|
|
|
@@ -153,7 +291,12 @@
|
|
|
153
291
|
const open = event.target.closest?.('.pg-row-open');
|
|
154
292
|
if (open) { openViewer(open.dataset.home, open.dataset.page, null, open); return; }
|
|
155
293
|
const del = event.target.closest?.('.pg-row-delete');
|
|
156
|
-
if (del) deleteUnreadable(del.dataset.home, del.dataset.page, del);
|
|
294
|
+
if (del) { deleteUnreadable(del.dataset.home, del.dataset.page, del); return; }
|
|
295
|
+
const act = event.target.closest?.('.pg-wf-act');
|
|
296
|
+
const owner = act && [...lists].find((e) => e.kind === 'workflows' && e.container.contains(act));
|
|
297
|
+
if (!owner) return;
|
|
298
|
+
if (act.dataset.act === 'retry') void renderWorkflowsList(owner.container, owner.opts);
|
|
299
|
+
else owner.opts.onAction?.(act.dataset.act);
|
|
157
300
|
});
|
|
158
301
|
|
|
159
302
|
async function deleteUnreadable(home, id, button) {
|
|
@@ -176,17 +319,20 @@
|
|
|
176
319
|
// ── Viewer ───────────────────────────────────────────────────────────────────────────────────────
|
|
177
320
|
|
|
178
321
|
const $modal = document.getElementById('page-viewer');
|
|
179
|
-
if (!$modal) { window.flolessPages = { renderList, open: () => {}, refresh: refreshLists }; return; }
|
|
322
|
+
if (!$modal) { window.flolessPages = { renderList, renderWorkflowsList, repaintWorkflowsList, open: () => {}, refresh: refreshLists }; return; }
|
|
180
323
|
const $ = (id) => document.getElementById(id);
|
|
181
324
|
const $title = $('pv-title');
|
|
182
325
|
const $sub = $('pv-sub');
|
|
183
326
|
const $ai = $('pv-ai');
|
|
327
|
+
const $seq = $('pv-seq');
|
|
328
|
+
const $seqText = $('pv-seq-text');
|
|
184
329
|
const $version = $('pv-version');
|
|
185
330
|
const $versionPop = $('pv-version-pop');
|
|
186
331
|
const $sites = $('pv-sites');
|
|
187
332
|
const $sitesPop = $('pv-sites-pop');
|
|
188
333
|
const $allowed = $('pv-allowed');
|
|
189
334
|
const $full = $('pv-full');
|
|
335
|
+
const $fullReport = $('pv-full-report');
|
|
190
336
|
const $delete = $('pv-delete');
|
|
191
337
|
const $close = $('pv-close');
|
|
192
338
|
const $banner = $('pv-banner');
|
|
@@ -196,6 +342,9 @@
|
|
|
196
342
|
|
|
197
343
|
const view = {
|
|
198
344
|
home: null, page: null, n: null, returnFocus: null,
|
|
345
|
+
known: [], // the versions loaded so far: a contiguous run of the newest, oldest first (#2291)
|
|
346
|
+
pagingOlder: false, // a "Show older versions" request is in flight
|
|
347
|
+
openSeq: 0, // each open counts up, so an earlier open's late answer never replaces a newer one
|
|
199
348
|
linkAsk: null, // { href }
|
|
200
349
|
blocked: new Map(), // host → origin, waiting for a decision
|
|
201
350
|
note: null, // a one-line explanation with nothing to decide (a link or load FloLess can never allow)
|
|
@@ -203,28 +352,146 @@
|
|
|
203
352
|
kept: new Set(), // origins kept blocked for this Page this session
|
|
204
353
|
reviewOpen: false,
|
|
205
354
|
loadTimer: null,
|
|
355
|
+
frameKeys: {}, // version → the key its frame address carries so the version's files load (slice 5)
|
|
356
|
+
shareProgress: null, // { files, filesDone, bytes, bytesDone } while a publish uploads the version's files (slice 5)
|
|
357
|
+
stopWatch: null, // stops the one progress poll running for the open Page (slice 5)
|
|
358
|
+
share: null, // { share, eligibility, error } — the Page's link (slice 4)
|
|
359
|
+
shareBannerDismissed: false,
|
|
360
|
+
shareSeq: 0, // status reads: each read, and each share action, takes the next number; only the newest read is applied
|
|
361
|
+
actionSeq: 0, // share actions: only the newest action's answer is applied (slice 5)
|
|
206
362
|
};
|
|
207
363
|
|
|
208
364
|
function isOpen() { return $modal.classList.contains('show'); }
|
|
209
365
|
|
|
366
|
+
/** The frame address. With its version's key it is folder-shaped, so the Page's `assets/…` files resolve (slice 5);
|
|
367
|
+
* without one (an older server) it is the plain address, which shows the HTML alone. */
|
|
210
368
|
function contentUrl() {
|
|
211
|
-
|
|
369
|
+
const base = `/pages-content/${encodeURIComponent(view.home)}/${encodeURIComponent(view.page.id)}/${view.n}`;
|
|
370
|
+
const key = view.frameKeys[view.n];
|
|
371
|
+
return key ? `${base}/${encodeURIComponent(key)}/` : base;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** Learn version `n`'s frame key when no answer so far carried it (a record a share or site change returned). */
|
|
375
|
+
async function ensureFrameKey(n) {
|
|
376
|
+
if (view.frameKeys[n]) return;
|
|
377
|
+
const home = view.home;
|
|
378
|
+
const id = view.page?.id;
|
|
379
|
+
try {
|
|
380
|
+
const body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}/versions?before=${n + 1}&limit=1`);
|
|
381
|
+
if (view.home === home && view.page?.id === id) Object.assign(view.frameKeys, body.frameKeys || {});
|
|
382
|
+
} catch { /* the plain address still shows the HTML */ }
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// #2291: a Page record carries its newest versions (the window) and `history.count`; older ones are paged in on
|
|
386
|
+
// demand. `view.known` is always a contiguous run of the newest versions, oldest first, so a version's place in the
|
|
387
|
+
// whole history is count minus the versions newer than it — never its position in what happens to be loaded.
|
|
388
|
+
function totalVersions() { return view.page?.history?.count ?? view.known.length; }
|
|
389
|
+
function position(v) { return totalVersions() - view.known.filter((x) => x.n > v.n).length; }
|
|
390
|
+
function currentVersion() { return view.known.find((v) => v.n === view.n) || null; }
|
|
391
|
+
const CAPTURE_TEXT = { live: 'Captured during a live session', 'live-failed': 'Captured during a live session that later failed' };
|
|
392
|
+
|
|
393
|
+
// #2262 slice 3c: what a workflow version holds when it is more than an HTML report.
|
|
394
|
+
function contentText(v) {
|
|
395
|
+
const c = v?.content;
|
|
396
|
+
if (!c) return '';
|
|
397
|
+
if (c.kind === 'complete-report') return c.whole ? 'Complete model report' : 'Complete model report · summary only';
|
|
398
|
+
if (c.kind === '3d-view') return c.tooBig ? '3D view · summary only' : '3D view';
|
|
399
|
+
return '';
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** Page older versions in until `n` is known (or the history is exhausted). Answers 'known', 'gone' (the history has
|
|
403
|
+
* no such version) or 'moved' (the viewer switched to another Page meanwhile); a failed request throws. */
|
|
404
|
+
async function ensureKnown(n) {
|
|
405
|
+
const home = view.home;
|
|
406
|
+
const id = view.page?.id;
|
|
407
|
+
while (!view.known.some((v) => v.n === n) && view.known.length < totalVersions() && view.known[0] && view.known[0].n > n) {
|
|
408
|
+
const before = view.known[0].n;
|
|
409
|
+
const body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}/versions?before=${before}&limit=200`);
|
|
410
|
+
const older = Array.isArray(body.versions) ? [...body.versions].reverse() : [];
|
|
411
|
+
if (view.home !== home || view.page?.id !== id) return 'moved';
|
|
412
|
+
// Another page-in (or a refreshed record) may have moved the oldest known version while this one was in flight;
|
|
413
|
+
// its answer would then repeat versions or leave a gap, so drop it and ask again from where the run now starts.
|
|
414
|
+
if (view.known[0]?.n !== before) continue;
|
|
415
|
+
if (!older.length) break;
|
|
416
|
+
Object.assign(view.frameKeys, body.frameKeys || {});
|
|
417
|
+
view.known = [...older, ...view.known];
|
|
418
|
+
}
|
|
419
|
+
return view.known.some((v) => v.n === n) ? 'known' : 'gone';
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** Why version `n` is not the one on screen, in the person's terms: a workflow's Page drops its oldest versions; any
|
|
423
|
+
* other Page keeps them, so a missing one there is not retention. */
|
|
424
|
+
function goneNote(n) {
|
|
425
|
+
return view.page?.source?.kind === 'workflow'
|
|
426
|
+
? `Version ${n} is no longer kept. A workflow's Page keeps its newest twenty versions, so you're now seeing the latest.`
|
|
427
|
+
: `Version ${n} isn't in this Page's history any more, so you're now seeing the latest.`;
|
|
428
|
+
}
|
|
429
|
+
function failedNote(n, err) {
|
|
430
|
+
return `FloLess couldn’t load version ${n}, so you're seeing the latest. ${err?.body?.error || 'The Page could not be read just now.'} Choose the version again from the list to retry.`;
|
|
212
431
|
}
|
|
213
432
|
|
|
214
|
-
|
|
433
|
+
/** A response replaced the record (a site change, a refresh): keep the person's version selected and its labels —
|
|
434
|
+
* paging it in again if it fell outside the new window — or, when it is no longer kept, say so and show the latest. */
|
|
435
|
+
async function adoptRecord(page) {
|
|
436
|
+
view.page = page;
|
|
437
|
+
view.known = [...page.versions];
|
|
438
|
+
const latest = view.known[view.known.length - 1].n;
|
|
439
|
+
if (view.n === latest) return true;
|
|
440
|
+
const wanted = view.n;
|
|
441
|
+
const seq = view.openSeq;
|
|
442
|
+
let found;
|
|
443
|
+
try { found = await ensureKnown(wanted); }
|
|
444
|
+
catch (err) { found = err; }
|
|
445
|
+
if (seq !== view.openSeq) return false; // the viewer was opened again meanwhile: that open owns it now
|
|
446
|
+
if (found === 'known' || found === 'moved') return found === 'known';
|
|
447
|
+
view.note = found === 'gone' ? goneNote(wanted) : failedNote(wanted, found);
|
|
448
|
+
view.n = latest;
|
|
449
|
+
paintBanner();
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/** "3 files · 41.2 MB" for a version that carries files beside its HTML (slice 5); nothing otherwise. */
|
|
454
|
+
function filesText(v) {
|
|
455
|
+
const files = Array.isArray(v?.assets) ? v.assets : [];
|
|
456
|
+
if (!files.length) return '';
|
|
457
|
+
const bytes = files.reduce((sum, f) => sum + (f.bytes || 0), 0) + (v.bytes || 0);
|
|
458
|
+
const size = bytes >= 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`;
|
|
459
|
+
return `${files.length === 1 ? '1 file' : `${files.length} files`} · ${size}`;
|
|
460
|
+
}
|
|
215
461
|
|
|
216
462
|
function paintHeader() {
|
|
217
463
|
const p = view.page;
|
|
218
464
|
const v = currentVersion();
|
|
219
|
-
const
|
|
220
|
-
const
|
|
221
|
-
const
|
|
465
|
+
const latest = view.known[view.known.length - 1].n;
|
|
466
|
+
const index = v ? position(v) : totalVersions();
|
|
467
|
+
const total = totalVersions();
|
|
222
468
|
$title.textContent = p.title;
|
|
223
469
|
$ai.hidden = !v?.aiMade;
|
|
224
470
|
$ai.setAttribute('data-tip', AI_TIP);
|
|
225
|
-
|
|
226
|
-
$
|
|
227
|
-
$
|
|
471
|
+
const seq = v?.sequence;
|
|
472
|
+
$seq.hidden = !seq;
|
|
473
|
+
$seqText.hidden = !seq;
|
|
474
|
+
if (seq) {
|
|
475
|
+
const sentence = sequenceSentence(seq, p.source);
|
|
476
|
+
$seq.textContent = seqLabel(seq);
|
|
477
|
+
$seq.classList.toggle('is-warn', seq.order !== 'read' || !!seq.partial);
|
|
478
|
+
$seq.setAttribute('data-tip', sentence);
|
|
479
|
+
$seq.setAttribute('aria-label', `${$seq.textContent}.`);
|
|
480
|
+
$seqText.textContent = sentence;
|
|
481
|
+
} else {
|
|
482
|
+
$seq.removeAttribute('data-tip');
|
|
483
|
+
$seqText.textContent = '';
|
|
484
|
+
}
|
|
485
|
+
$sub.textContent = [sourceText(p.source), v ? `Saved ${when(v.createdAt)}` : '', v?.capture ? CAPTURE_TEXT[v.capture] : '', contentText(v), filesText(v)].filter(Boolean).join(' · ');
|
|
486
|
+
// The full report is opened by FloLess, outside the frame, and only for a version that is a complete report.
|
|
487
|
+
if ($fullReport) {
|
|
488
|
+
$fullReport.hidden = !(p.source?.kind === 'workflow' && v?.content?.kind === 'complete-report');
|
|
489
|
+
$fullReport.setAttribute('data-tip', v?.content?.kind === 'complete-report' && !v.content.whole
|
|
490
|
+
? 'This version is only a summary. Open the whole report FloLess keeps on this computer, in its report viewer'
|
|
491
|
+
: 'Open the whole report FloLess keeps on this computer, in its report viewer');
|
|
492
|
+
}
|
|
493
|
+
$version.textContent = `Version ${index} of ${total}${view.n === latest ? ' · latest' : ''}`;
|
|
494
|
+
$version.setAttribute('aria-label', `Version ${index} of ${total}. Choose another version`);
|
|
228
495
|
const allowed = p.allowedOrigins.length;
|
|
229
496
|
$allowed.hidden = allowed === 0;
|
|
230
497
|
$allowed.textContent = allowed === 1 ? '1 site allowed' : `${allowed} sites allowed`;
|
|
@@ -232,12 +499,20 @@
|
|
|
232
499
|
$frame.setAttribute('title', `Page: ${p.title}, version ${index}`);
|
|
233
500
|
}
|
|
234
501
|
|
|
235
|
-
function loadFrame() {
|
|
502
|
+
async function loadFrame() {
|
|
236
503
|
clearTimeout(view.loadTimer);
|
|
237
504
|
$stage.classList.add('is-loading');
|
|
238
505
|
$loading.hidden = false;
|
|
239
506
|
$loading.textContent = 'Opening Page…';
|
|
240
507
|
view.loadTimer = setTimeout(() => { $loading.textContent = 'Still opening this Page… Large Pages can take a moment.'; }, 8000);
|
|
508
|
+
// Only a version with files needs its key (the plain address shows a version without files exactly the same), and
|
|
509
|
+
// only when no answer so far carried it.
|
|
510
|
+
if (currentVersion()?.assets?.length && !view.frameKeys[view.n]) {
|
|
511
|
+
const want = { seq: view.openSeq, id: view.page?.id, n: view.n };
|
|
512
|
+
await ensureFrameKey(want.n);
|
|
513
|
+
// Another open or version choice took over while the key was fetched: that one loads its own frame.
|
|
514
|
+
if (want.seq !== view.openSeq || want.id !== view.page?.id || want.n !== view.n || !isOpen()) return;
|
|
515
|
+
}
|
|
241
516
|
$frame.src = contentUrl();
|
|
242
517
|
}
|
|
243
518
|
$frame.addEventListener('load', () => {
|
|
@@ -248,34 +523,59 @@
|
|
|
248
523
|
});
|
|
249
524
|
|
|
250
525
|
async function openViewer(home, id, n, returnFocus) {
|
|
526
|
+
const seq = ++view.openSeq;
|
|
251
527
|
let body;
|
|
252
528
|
try {
|
|
253
529
|
body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}`);
|
|
530
|
+
if (seq !== view.openSeq) return false; // a newer open (even of this same Page) owns the viewer now
|
|
254
531
|
} catch (err) {
|
|
532
|
+
if (seq !== view.openSeq) return false;
|
|
255
533
|
if (['page-damaged', 'page-not-found'].includes(err?.body?.code) && typeof window.flolessWorkspaces?.openPagesHome === 'function') {
|
|
256
534
|
if (await window.flolessWorkspaces.openPagesHome(home, id, closeViewer)) return true;
|
|
257
535
|
}
|
|
258
536
|
toast(`FloLess couldn’t open this Page. ${err?.body?.error || 'Try again in a moment.'}`, 'warn');
|
|
259
537
|
return false;
|
|
260
538
|
}
|
|
539
|
+
// Another Page: a share action still out for the previous one no longer owns the Share button.
|
|
540
|
+
if (view.page?.id !== body.page?.id || view.home !== (body.home || home)) {
|
|
541
|
+
view.actionSeq += 1;
|
|
542
|
+
$share.removeAttribute('aria-busy');
|
|
543
|
+
view.stopWatch?.(); // its progress poll too, so this Page can start its own
|
|
544
|
+
}
|
|
261
545
|
view.home = body.home || home;
|
|
262
546
|
view.page = body.page;
|
|
263
|
-
|
|
264
|
-
view.
|
|
547
|
+
view.frameKeys = { ...(body.frameKeys || {}) };
|
|
548
|
+
view.known = [...view.page.versions];
|
|
549
|
+
const newest = view.known[view.known.length - 1].n;
|
|
550
|
+
// A version older than the window (a link to version 3 of 900) is paged in first; one that can't be is said.
|
|
551
|
+
let note = null;
|
|
552
|
+
view.n = newest;
|
|
553
|
+
if (n && n !== newest) {
|
|
554
|
+
let found;
|
|
555
|
+
try { found = await ensureKnown(n); }
|
|
556
|
+
catch (err) { found = err; }
|
|
557
|
+
if (found === 'moved' || seq !== view.openSeq) return false;
|
|
558
|
+
if (found === 'known') view.n = n;
|
|
559
|
+
else note = found === 'gone' ? goneNote(n) : failedNote(n, found);
|
|
560
|
+
}
|
|
265
561
|
view.returnFocus = returnFocus instanceof HTMLElement ? returnFocus : document.activeElement;
|
|
266
562
|
view.linkAsk = null;
|
|
267
563
|
view.blocked.clear();
|
|
268
564
|
view.kept.clear();
|
|
269
|
-
view.note =
|
|
565
|
+
view.note = note;
|
|
270
566
|
view.limitHit = false;
|
|
271
567
|
view.reviewOpen = false;
|
|
568
|
+
view.share = { share: view.page.share ?? null, eligibility: null, error: null };
|
|
569
|
+
view.shareBannerDismissed = false;
|
|
272
570
|
closePopovers();
|
|
273
571
|
paintHeader();
|
|
572
|
+
paintShareButton();
|
|
274
573
|
paintBanner();
|
|
275
574
|
setFullscreen(false);
|
|
276
575
|
$modal.classList.add('show');
|
|
277
576
|
loadFrame();
|
|
278
577
|
$close.focus();
|
|
578
|
+
void loadShare();
|
|
279
579
|
return true;
|
|
280
580
|
}
|
|
281
581
|
|
|
@@ -284,6 +584,7 @@
|
|
|
284
584
|
closePopovers();
|
|
285
585
|
$modal.classList.remove('show');
|
|
286
586
|
clearTimeout(view.loadTimer);
|
|
587
|
+
view.stopWatch?.();
|
|
287
588
|
$frame.src = 'about:blank';
|
|
288
589
|
view.linkAsk = null;
|
|
289
590
|
view.blocked.clear();
|
|
@@ -293,11 +594,28 @@
|
|
|
293
594
|
if (back?.isConnected) back.focus();
|
|
294
595
|
}
|
|
295
596
|
|
|
597
|
+
/** Re-read the open Page's record (its labels changed on the server). An answer that arrives after the person
|
|
598
|
+
* closed it or opened another — even this same Page again — is dropped; one that moved the shown version moves the
|
|
599
|
+
* frame with it, so header and content never disagree. */
|
|
296
600
|
async function reloadRecord() {
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
601
|
+
const seq = view.openSeq;
|
|
602
|
+
const home = view.home;
|
|
603
|
+
const id = view.page?.id;
|
|
604
|
+
const stale = () => seq !== view.openSeq || !isOpen() || view.home !== home || view.page?.id !== id;
|
|
605
|
+
let body;
|
|
606
|
+
try { body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}`); }
|
|
607
|
+
catch {
|
|
608
|
+
if (stale()) return;
|
|
609
|
+
view.note = 'This Page was updated, but FloLess couldn’t read the new version labels. Close the Page and open it again to see them.';
|
|
610
|
+
paintBanner();
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (stale()) return;
|
|
614
|
+
const shown = view.n;
|
|
615
|
+
await adoptRecord(body.page);
|
|
616
|
+
if (stale()) return;
|
|
300
617
|
paintHeader();
|
|
618
|
+
if (view.n !== shown) loadFrame();
|
|
301
619
|
}
|
|
302
620
|
|
|
303
621
|
// ── Version picker ──
|
|
@@ -307,23 +625,37 @@
|
|
|
307
625
|
$version.setAttribute('aria-expanded', 'false');
|
|
308
626
|
$sitesPop.hidden = true;
|
|
309
627
|
$sites.setAttribute('aria-expanded', 'false');
|
|
628
|
+
if (typeof closeSharePop === 'function') closeSharePop();
|
|
310
629
|
}
|
|
311
630
|
|
|
312
|
-
function openVersionPicker() {
|
|
313
|
-
const versions = [...view.
|
|
631
|
+
function openVersionPicker(focusN) {
|
|
632
|
+
const versions = [...view.known].reverse();
|
|
314
633
|
const latest = versions[0].n;
|
|
315
|
-
const total =
|
|
316
|
-
|
|
317
|
-
|
|
634
|
+
const total = totalVersions();
|
|
635
|
+
const older = total - view.known.length;
|
|
636
|
+
const next = Math.min(200, older);
|
|
637
|
+
const options = versions.map((v) => {
|
|
638
|
+
const label = `Version ${position(v)}${v.n === latest ? ' · latest' : ''}`;
|
|
639
|
+
const meta = [when(v.createdAt), v.aiMade ? 'AI-made' : '', v.capture ? CAPTURE_TEXT[v.capture] : '', v.sequence ? seqLabel(v.sequence) : ''].filter(Boolean).join(' · ');
|
|
318
640
|
return `<button type="button" class="wf-option pv-version-option${v.n === view.n ? ' selected' : ''}" role="option" aria-selected="${v.n === view.n}"
|
|
319
|
-
data-command-id="shell.page-version-choose#${esc(label)}" data-n="${v.n}">
|
|
641
|
+
aria-posinset="${position(v)}" aria-setsize="${total}" data-command-id="shell.page-version-choose#${esc(label)}" data-n="${v.n}">
|
|
320
642
|
<span class="pv-option-main">${esc(label)}</span>
|
|
321
|
-
<span class="pv-option-meta">${esc(
|
|
643
|
+
<span class="pv-option-meta">${esc(meta)}</span>
|
|
322
644
|
</button>`;
|
|
323
645
|
}).join('');
|
|
646
|
+
// The "older" control is a plain button BELOW the listbox (a listbox may hold only options), kept in view.
|
|
647
|
+
const footer = older > 0
|
|
648
|
+
? `<div class="pv-version-footer"><button type="button" class="wf-option pv-version-older" data-command-id="shell.page-versions-older" data-older="1">
|
|
649
|
+
<span class="pv-option-main">${older > 200 ? `Show ${next} older versions` : `Show the last ${older} version${older === 1 ? '' : 's'}`}</span>
|
|
650
|
+
<span class="pv-option-meta">${older} more not shown</span></button></div>`
|
|
651
|
+
: '';
|
|
652
|
+
$versionPop.innerHTML = `<div role="listbox" id="pv-version-list" aria-label="Versions of this Page">${options}</div>${footer}
|
|
653
|
+
<span class="pv-version-announce" role="status" aria-live="polite">${esc(view.announce || '')}</span>`;
|
|
654
|
+
view.announce = '';
|
|
324
655
|
$versionPop.hidden = false;
|
|
325
656
|
$version.setAttribute('aria-expanded', 'true');
|
|
326
|
-
|
|
657
|
+
const focus = focusN ? $versionPop.querySelector(`button[data-n="${focusN}"]`) : null;
|
|
658
|
+
(focus || $versionPop.querySelector('.selected') || $versionPop.querySelector('button'))?.focus();
|
|
327
659
|
}
|
|
328
660
|
|
|
329
661
|
$version.addEventListener('click', () => {
|
|
@@ -331,7 +663,35 @@
|
|
|
331
663
|
closePopovers();
|
|
332
664
|
openVersionPicker();
|
|
333
665
|
});
|
|
334
|
-
$versionPop.addEventListener('click', (event) => {
|
|
666
|
+
$versionPop.addEventListener('click', async (event) => {
|
|
667
|
+
const olderButton = event.target.closest('button[data-older]');
|
|
668
|
+
if (olderButton) {
|
|
669
|
+
// Page in the next older two hundred and keep the list open, focus on the first newly shown version. A click
|
|
670
|
+
// while that is still loading is the same request, so it waits rather than asking twice.
|
|
671
|
+
if (view.pagingOlder) return;
|
|
672
|
+
view.pagingOlder = true;
|
|
673
|
+
olderButton.setAttribute('aria-busy', 'true');
|
|
674
|
+
olderButton.querySelector('.pv-option-main').textContent = 'Loading older versions…';
|
|
675
|
+
const before = view.known[0].n;
|
|
676
|
+
let found;
|
|
677
|
+
try { found = await ensureKnown(Math.max(1, before - 200)); }
|
|
678
|
+
catch (err) {
|
|
679
|
+
toast(`FloLess couldn’t show older versions. ${err?.body?.error || 'Try again in a moment.'}`, 'warn');
|
|
680
|
+
if (!$versionPop.hidden) openVersionPicker();
|
|
681
|
+
return;
|
|
682
|
+
} finally { view.pagingOlder = false; }
|
|
683
|
+
if (found === 'moved' || $versionPop.hidden) return; // another Page, or closed: the list opens fresh next time
|
|
684
|
+
const below = view.known.filter((v) => v.n < before);
|
|
685
|
+
if (!below.length) {
|
|
686
|
+
toast(`FloLess couldn’t find the older versions this Page lists. Close the Page and open it again; if they are still missing, use Report an issue at the bottom of the window.`, 'warn');
|
|
687
|
+
openVersionPicker();
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const remaining = totalVersions() - view.known.length;
|
|
691
|
+
view.announce = `${below.length} more version${below.length === 1 ? '' : 's'} shown.${remaining ? ` ${remaining} older remain.` : ''}`;
|
|
692
|
+
openVersionPicker(below.length ? below[below.length - 1].n : null);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
335
695
|
const option = event.target.closest('button[data-n]');
|
|
336
696
|
if (!option) return;
|
|
337
697
|
const n = Number(option.dataset.n);
|
|
@@ -348,7 +708,7 @@
|
|
|
348
708
|
loadFrame();
|
|
349
709
|
});
|
|
350
710
|
$versionPop.addEventListener('keydown', (event) => {
|
|
351
|
-
const options = [...$versionPop.querySelectorAll('
|
|
711
|
+
const options = [...$versionPop.querySelectorAll('[role="option"]')];
|
|
352
712
|
const i = options.indexOf(document.activeElement);
|
|
353
713
|
if (event.key === 'ArrowDown') { event.preventDefault(); options[Math.min(options.length - 1, i + 1)]?.focus(); }
|
|
354
714
|
if (event.key === 'ArrowUp') { event.preventDefault(); options[Math.max(0, i - 1)]?.focus(); }
|
|
@@ -386,7 +746,7 @@
|
|
|
386
746
|
const body = await api(`/api/pages/${encodeURIComponent(view.home)}/${encodeURIComponent(view.page.id)}/allowed-origins`, {
|
|
387
747
|
method: 'PUT', body: JSON.stringify({ origin, allow }),
|
|
388
748
|
});
|
|
389
|
-
|
|
749
|
+
await adoptRecord(body.page);
|
|
390
750
|
paintHeader();
|
|
391
751
|
loadFrame();
|
|
392
752
|
return true;
|
|
@@ -420,6 +780,7 @@
|
|
|
420
780
|
$banner.hidden = false;
|
|
421
781
|
return;
|
|
422
782
|
}
|
|
783
|
+
if (!hosts.length && typeof paintShareBanner === 'function' && paintShareBanner()) return;
|
|
423
784
|
if (!hosts.length) { $banner.hidden = true; $banner.innerHTML = ''; delete $banner.dataset.kind; return; }
|
|
424
785
|
$banner.dataset.kind = 'blocked';
|
|
425
786
|
const explain = 'If you allow it, that site can see that you opened this Page and can add its own code to it.'
|
|
@@ -566,22 +927,575 @@
|
|
|
566
927
|
const p = view.page;
|
|
567
928
|
const ok = await bridge.formModal?.({
|
|
568
929
|
title: 'Delete this Page?',
|
|
569
|
-
sub: `“${p.title}” and all ${versionsText(p.versions.length)} will be removed. This can’t be undone
|
|
930
|
+
sub: `“${p.title}” and all ${versionsText(p.history?.count ?? p.versions.length)} will be removed. This can’t be undone.${view.share?.share && view.share.share.state !== 'revoked' ? ' Its share link is revoked too, so it stops opening for everyone.' : ''}`,
|
|
570
931
|
fields: [], okLabel: 'Delete Page', danger: true, returnFocusTo: $delete,
|
|
571
932
|
});
|
|
572
933
|
if (!ok) return;
|
|
934
|
+
let revokePending = false;
|
|
573
935
|
try {
|
|
574
|
-
await api(`/api/pages/${encodeURIComponent(view.home)}/${encodeURIComponent(p.id)}`, { method: 'DELETE' });
|
|
936
|
+
const body = await api(`/api/pages/${encodeURIComponent(view.home)}/${encodeURIComponent(p.id)}`, { method: 'DELETE' });
|
|
937
|
+
revokePending = body?.revokePending === true;
|
|
575
938
|
} catch (err) {
|
|
576
939
|
toast(`FloLess couldn’t delete this Page. ${err?.body?.error || 'Try again in a moment.'}`, 'warn');
|
|
577
940
|
return;
|
|
578
941
|
}
|
|
579
942
|
announceDeleted(view.home, p.id);
|
|
580
943
|
closeViewer();
|
|
581
|
-
toast(
|
|
944
|
+
toast(revokePending
|
|
945
|
+
? `Deleted “${p.title}”. Its link will be revoked as soon as FloLess can reach floless.io; you can see it in My shared links.`
|
|
946
|
+
: `Deleted “${p.title}”.`, revokePending ? 'warn' : 'ok');
|
|
582
947
|
refreshLists();
|
|
583
948
|
});
|
|
584
949
|
|
|
950
|
+
// ── Share link (#2262 slice 4) ──
|
|
951
|
+
// One button in the header says where the link stands; its popover holds the link and the everyday actions. Anything
|
|
952
|
+
// that needs a decision (a newer version not published, a link updated elsewhere, a failure) is said in the banner,
|
|
953
|
+
// so the popover is never the only place a choice lives.
|
|
954
|
+
|
|
955
|
+
const $share = $('pv-share');
|
|
956
|
+
const $shareLabel = $('pv-share-label');
|
|
957
|
+
const $sharePop = $('pv-share-pop');
|
|
958
|
+
const PLANS_URL = 'https://floless.io/pricing';
|
|
959
|
+
|
|
960
|
+
function verLabel(n) {
|
|
961
|
+
const v = view.known.find((x) => x.n === n);
|
|
962
|
+
return v ? `version ${position(v)}` : `version ${n}`;
|
|
963
|
+
}
|
|
964
|
+
function latestN() { return view.known[view.known.length - 1]?.n ?? null; }
|
|
965
|
+
|
|
966
|
+
/** The words for where the link stands: the button label, its tip, and the popover's first line. */
|
|
967
|
+
function shareWords() {
|
|
968
|
+
const s = view.share?.share;
|
|
969
|
+
if (!s) return { label: 'Share', dot: '', status: 'Not shared. A link lets anyone who has it open this Page; it shows each version you publish.' };
|
|
970
|
+
if (s.state === 'pending-publish') {
|
|
971
|
+
const waiting = s.lastError ? ' FloLess will keep trying by itself.' : '';
|
|
972
|
+
return { label: 'Sharing…', dot: 'wait', status: `Publishing ${verLabel(s.pending?.pageVersion)}…${waiting}` };
|
|
973
|
+
}
|
|
974
|
+
if (s.state === 'pending-revoke') return { label: 'Revoking…', dot: 'wait', status: 'This link will be revoked as soon as FloLess can reach floless.io. Until then it still opens.' };
|
|
975
|
+
if (s.state === 'revoked') return { label: 'Link revoked', dot: 'off', status: 'This link was revoked and no longer opens. Sharing again makes a new link.' };
|
|
976
|
+
const published = s.publishedPageVersion;
|
|
977
|
+
if (s.conflict) return { label: 'Shared · needs you', dot: 'warn', status: `This link was updated from another computer and now shows its link version ${s.conflict.remoteVersion}.` };
|
|
978
|
+
if (published !== null && latestN() !== null && published < latestN()) {
|
|
979
|
+
return { label: 'Shared · update', dot: 'warn', status: `The link shows ${verLabel(published)}. A newer version isn’t published yet.` };
|
|
980
|
+
}
|
|
981
|
+
return { label: 'Shared', dot: 'live', status: `The link is live and shows ${verLabel(published)}.` };
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
function paintShareButton() {
|
|
985
|
+
const w = shareWords();
|
|
986
|
+
$shareLabel.textContent = w.label;
|
|
987
|
+
$share.dataset.state = w.dot || 'none';
|
|
988
|
+
// No tooltip: it would sit over the open menu and the banner below. The menu and the accessible name say it all.
|
|
989
|
+
$share.removeAttribute('data-tip');
|
|
990
|
+
$share.setAttribute('aria-label', `Share link: ${w.label}. ${w.status}`);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
function paintSharePop() {
|
|
995
|
+
const s = view.share?.share;
|
|
996
|
+
const w = shareWords();
|
|
997
|
+
const parts = [`<div class="pv-pop-head">Share link</div><p class="pv-pop-note pv-share-status">${esc(w.status)}</p>`];
|
|
998
|
+
if (s?.url && s.state !== 'revoked') {
|
|
999
|
+
parts.push(`<div class="pv-share-link"><input class="pv-share-url" type="text" readonly value="${esc(s.url)}" aria-label="The share link"
|
|
1000
|
+
data-command-id="shell.page-share-link-field">${`<button type="button" class="ghost" data-command-id="shell.page-share-copy" data-share-act="copy">${esc('Copy')}</button>`}</div>`);
|
|
1001
|
+
parts.push(`<div class="pv-share-row">${`<button type="button" class="ghost" data-command-id="shell.page-share-open-link" data-share-act="open">${esc('Open link')}</button>`}</div>`);
|
|
1002
|
+
}
|
|
1003
|
+
const shown = view.n;
|
|
1004
|
+
// floless.io can't draw the order label yet, so a version whose order FloLess did not read carries it in the title.
|
|
1005
|
+
const shownVersion = view.known.find((x) => x.n === shown);
|
|
1006
|
+
const shownSeq = shownVersion?.sequence;
|
|
1007
|
+
// #2262 slice 3c: a whole complete report says what leaves the computer before it is shared.
|
|
1008
|
+
if (shownVersion?.content?.kind === 'complete-report') {
|
|
1009
|
+
parts.push(shownVersion.content.whole
|
|
1010
|
+
? '<p class="pv-pop-note pv-share-whole-report">This version holds the whole model property report — every property in it will be on the link.</p>'
|
|
1011
|
+
: '<p class="pv-pop-note pv-share-whole-report">This version is only a summary of the report, so only the summary will be on the link.</p>');
|
|
1012
|
+
}
|
|
1013
|
+
if (shownSeq && (shownSeq.order !== 'read' || shownSeq.partial)) {
|
|
1014
|
+
const suffix = shownSeq.order === 'read' ? 'order partly read' : shownSeq.order === 'assumed' ? 'order assumed' : shownSeq.order === 'unverified' ? 'order not checked' : 'order unreadable';
|
|
1015
|
+
parts.push(`<p class="pv-pop-note pv-share-seq">The shared link’s title will end with “ · ${esc(suffix)}”, because floless.io can’t show the order label yet.</p>`);
|
|
1016
|
+
}
|
|
1017
|
+
if (!s || s.state === 'revoked') {
|
|
1018
|
+
parts.push(`<div class="pv-share-row">${`<button type="button" class="pv-share-primary" data-command-id="shell.page-share-create" data-share-act="create">${esc(s ? `Share ${verLabel(shown)} again` : `Share ${verLabel(shown)}`)}</button>`}</div>`);
|
|
1019
|
+
if (s) parts.push('<p class="pv-pop-note">This makes a new link. The old one stays revoked.</p>');
|
|
1020
|
+
else if (view.share?.eligibility && !view.share.eligibility.ok && shown === latestN()) parts.push(`<p class="pv-pop-note">${esc(view.share.eligibility.reason)}</p>`);
|
|
1021
|
+
} else if (s.state === 'pending-publish') {
|
|
1022
|
+
parts.push(`<div class="pv-share-row">${`<button type="button" class="ghost" data-command-id="shell.page-share-cancel" data-share-act="cancel">${esc('Cancel publishing')}</button>`}</div>`);
|
|
1023
|
+
} else if (s.state === 'live' && shown !== s.publishedPageVersion) {
|
|
1024
|
+
parts.push(`<div class="pv-share-row">${`<button type="button" class="pv-share-primary" data-command-id="shell.page-share-publish" data-share-act="publish"${` data-n="${shown}"`}>${esc(`Publish ${verLabel(shown)} on this link`)}</button>`}</div>`);
|
|
1025
|
+
}
|
|
1026
|
+
if (s && (s.state === 'live' || s.state === 'pending-publish')) {
|
|
1027
|
+
parts.push(`<div class="pv-share-row pv-share-quiet">${`<button type="button" class="ghost" data-command-id="shell.page-share-revoke" data-share-act="revoke">${esc('Revoke link…')}</button>`}</div>`);
|
|
1028
|
+
}
|
|
1029
|
+
parts.push(`<div class="pv-share-row pv-share-quiet">${`<button type="button" class="ghost" data-command-id="shell.shared-links-open" data-share-act="mine">${esc('My shared links')}</button>`}</div>`);
|
|
1030
|
+
$sharePop.innerHTML = parts.join('');
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/** The banner for the link, when nothing the Page itself asked about is waiting. Returns false when there is none. */
|
|
1034
|
+
function paintShareBanner() {
|
|
1035
|
+
const st = view.share;
|
|
1036
|
+
if (!st || view.shareBannerDismissed) return false;
|
|
1037
|
+
const s = st.share;
|
|
1038
|
+
let text = '';
|
|
1039
|
+
let actions = '';
|
|
1040
|
+
let kind = 'share';
|
|
1041
|
+
// Only while the link is really being published: a cancelled or settled publish shows no upload.
|
|
1042
|
+
const up = s?.state === 'pending-publish' ? view.shareProgress : null;
|
|
1043
|
+
if (up && !st.error) {
|
|
1044
|
+
// Drawn once; each later tick changes only this text (watchPublish), so Cancel keeps focus and a screen reader
|
|
1045
|
+
// hears the banner arrive, not a count every second.
|
|
1046
|
+
$banner.dataset.kind = 'share-progress';
|
|
1047
|
+
$banner.innerHTML = `<p class="pv-banner-text" data-share-progress aria-live="off">${esc(progressText(up))}</p><div class="pv-banner-actions">`
|
|
1048
|
+
+ `<button type="button" class="ghost" data-command-id="shell.page-share-cancel" data-share-act="cancel">${esc('Cancel publishing')}</button></div>`;
|
|
1049
|
+
$banner.hidden = false;
|
|
1050
|
+
return true;
|
|
1051
|
+
} else if (st.error) {
|
|
1052
|
+
kind = 'blocked';
|
|
1053
|
+
text = esc(st.error.message);
|
|
1054
|
+
if (st.error.code === 'quota') actions = `<button type="button" class="ghost" data-command-id="shell.shared-links-open" data-share-act="mine">${esc('My shared links')}</button>`;
|
|
1055
|
+
else if (st.error.code === 'no_subscription') actions = `<button type="button" class="ghost" data-command-id="shell.page-share-plans" data-share-act="plans">${esc('See plans')}</button>`;
|
|
1056
|
+
else if (st.error.code === 'share-too-large' && st.error.path) actions = `<button type="button" class="ghost" data-command-id="shell.page-share-reveal" data-share-act="reveal">${esc('Reveal in folder')}</button>`;
|
|
1057
|
+
else if (['offline', 'rate_limited', 'in_progress', 'signed_out'].includes(st.error.code)) actions = `<button type="button" class="ghost" data-command-id="shell.page-share-retry" data-share-act="retry">${esc('Try again')}</button>`;
|
|
1058
|
+
actions += `<button type="button" class="ghost" data-command-id="shell.page-note-dismiss" data-share-act="dismiss">${esc('OK')}</button>`;
|
|
1059
|
+
} else if (s?.state === 'pending-publish' && s.lastError) {
|
|
1060
|
+
kind = 'blocked';
|
|
1061
|
+
text = s.lastError.code === 'signed_out'
|
|
1062
|
+
? 'FloLess is waiting to publish this link because you’re signed out. Sign in to FloLess and it will carry on by itself.'
|
|
1063
|
+
: 'FloLess couldn’t reach floless.io to publish this link. It will try again by itself, or you can try now.';
|
|
1064
|
+
actions = `<button type="button" class="ghost" data-command-id="shell.page-share-retry" data-share-act="retry">${esc('Try now')}</button>` + `<button type="button" class="ghost" data-command-id="shell.page-share-cancel" data-share-act="cancel">${esc('Cancel publishing')}</button>`;
|
|
1065
|
+
} else if (s?.state === 'pending-revoke') {
|
|
1066
|
+
text = 'This link will be revoked as soon as FloLess can reach floless.io. Until then it still opens.';
|
|
1067
|
+
actions = `<button type="button" class="ghost" data-command-id="shell.page-share-retry" data-share-act="retry-revoke">${esc('Try now')}</button>` + `<button type="button" class="ghost" data-command-id="shell.page-note-dismiss" data-share-act="dismiss">${esc('OK')}</button>`;
|
|
1068
|
+
} else if (s?.state === 'live' && s.conflict) {
|
|
1069
|
+
kind = 'blocked';
|
|
1070
|
+
const theirs = s.conflict.remoteVersion;
|
|
1071
|
+
text = `This link was updated from another computer and now shows its link version <strong>${theirs}</strong>. Publish yours as link version ${theirs + 1}, or keep theirs?`;
|
|
1072
|
+
// "Mine" is the version that publish tried to put on the link, not whatever is latest now (older records: the latest).
|
|
1073
|
+
const mine = s.conflict.pageVersion ?? latestN();
|
|
1074
|
+
actions = `<button type="button" class="pv-share-primary" data-command-id="shell.page-share-replace" data-share-act="replace"${` data-expected="${theirs}" data-n="${mine}"`}>${esc(`Publish ${verLabel(mine)} as v${theirs + 1}`)}</button>`
|
|
1075
|
+
+ `<button type="button" class="ghost" data-command-id="shell.page-share-keep" data-share-act="keep-theirs">${esc(`Keep v${theirs}`)}</button>`;
|
|
1076
|
+
} else if (s?.state === 'live' && s.publishedPageVersion !== null && latestN() !== null && s.publishedPageVersion < latestN()) {
|
|
1077
|
+
text = `Shared: the link shows ${esc(verLabel(s.publishedPageVersion))}. A newer version isn’t published yet.`;
|
|
1078
|
+
actions = `<button type="button" class="pv-share-primary" data-command-id="shell.page-share-publish" data-share-act="publish"${` data-n="${latestN()}"`}>${esc(`Publish ${verLabel(latestN())}`)}</button>`
|
|
1079
|
+
+ `<button type="button" class="ghost" data-command-id="shell.page-note-dismiss" data-share-act="dismiss">${esc('Not now')}</button>`;
|
|
1080
|
+
} else if (s?.note) {
|
|
1081
|
+
text = esc(s.note);
|
|
1082
|
+
actions = `<button type="button" class="ghost" data-command-id="shell.page-note-dismiss" data-share-act="dismiss">${esc('OK')}</button>`;
|
|
1083
|
+
} else return false;
|
|
1084
|
+
$banner.dataset.kind = kind;
|
|
1085
|
+
$banner.innerHTML = `<p class="pv-banner-text">${text}</p><div class="pv-banner-actions">${actions}</div>`;
|
|
1086
|
+
$banner.hidden = false;
|
|
1087
|
+
return true;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
async function loadShare() {
|
|
1091
|
+
const seq = view.openSeq;
|
|
1092
|
+
// A share action that answers first is newer than this read: its answer is never overwritten by this one.
|
|
1093
|
+
const shareSeq = ++view.shareSeq;
|
|
1094
|
+
const home = view.home;
|
|
1095
|
+
const id = view.page?.id;
|
|
1096
|
+
try {
|
|
1097
|
+
const body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}/share`);
|
|
1098
|
+
if (seq !== view.openSeq || shareSeq !== view.shareSeq) return;
|
|
1099
|
+
view.share = { share: body.share, eligibility: body.eligibility, error: null };
|
|
1100
|
+
view.shareProgress = body.progress || null;
|
|
1101
|
+
// A publish FloLess resumed by itself (after a restart, or the hourly catch-up) is still running: follow it until
|
|
1102
|
+
// it settles, so the Page shows its upload and then its live link without being reopened.
|
|
1103
|
+
if (body.share?.state === 'pending-publish' && !view.stopWatch) watchPublish({ untilSettled: true });
|
|
1104
|
+
} catch (err) {
|
|
1105
|
+
if (seq !== view.openSeq || shareSeq !== view.shareSeq) return;
|
|
1106
|
+
// Said, not swallowed: the Page's own record still shows its link, and the banner says why the rest is missing.
|
|
1107
|
+
view.share = { share: view.page?.share ?? null, eligibility: null,
|
|
1108
|
+
error: { code: err?.body?.code || 'offline', message: err?.body?.error || 'FloLess couldn’t check this Page’s link just now. Close the Page and open it again to retry.', path: null } };
|
|
1109
|
+
}
|
|
1110
|
+
paintShareButton();
|
|
1111
|
+
// Painted while closed too: the Instructor reaches Revoke, Copy and the rest by opening this menu (data-reveal-by).
|
|
1112
|
+
paintSharePop();
|
|
1113
|
+
paintBanner();
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/** "Uploading this version's files to floless.io: 3 of 12 files (18.0 of 41.2 MB)…" — the share's upload, in words. */
|
|
1117
|
+
function progressText(up) {
|
|
1118
|
+
const mb = (b) => (b / 1024 / 1024).toFixed(1);
|
|
1119
|
+
return `Uploading this version’s files to floless.io: ${up.filesDone} of ${up.files} ${up.files === 1 ? 'file' : 'files'} (${mb(up.bytesDone)} of ${mb(up.bytes)} MB). The link goes live when all of them are uploaded.`;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/** The words for a failure the server answered with, in the person's terms. */
|
|
1123
|
+
function outcomeSentence(code) {
|
|
1124
|
+
return ({
|
|
1125
|
+
signed_out: 'You’re signed out of FloLess, so the link wasn’t published. Sign in, then try again; FloLess keeps the request until then.',
|
|
1126
|
+
no_subscription: 'Sharing a link needs a FloLess plan, so this Page wasn’t shared. Your Page is unchanged.',
|
|
1127
|
+
too_large: 'floless.io said this version is too large to share. Make a smaller version and share that.',
|
|
1128
|
+
rate_limited: 'You’ve shared a lot in a short time, so floless.io asked FloLess to wait. It will try again by itself in a few minutes.',
|
|
1129
|
+
offline: 'FloLess couldn’t reach floless.io. It will try again by itself, or you can try now.',
|
|
1130
|
+
in_progress: 'floless.io is still finishing this link. FloLess will check again by itself.',
|
|
1131
|
+
cancelled: 'Publishing was cancelled. The link is as it was.',
|
|
1132
|
+
reused: 'FloLess couldn’t publish this attempt. Share the Page again.',
|
|
1133
|
+
unsupported: 'floless.io isn’t ready for links that update yet, so FloLess stopped instead of making a new link each time. Update FloLess, or try again later.',
|
|
1134
|
+
revoked: 'This link was revoked from somewhere else, so it can’t show new versions. Share the Page again to make a new link.',
|
|
1135
|
+
not_found: 'floless.io no longer has this link. Share the Page again to make a new link.',
|
|
1136
|
+
damaged: 'One of this version’s files is damaged on this computer, so nothing was published. Share another version, or save this one again with its files.',
|
|
1137
|
+
quota: 'floless.io’s space for your shared links’ files is full (1 GB), so this link wasn’t published. Revoke links you no longer need in My shared links, then share again.',
|
|
1138
|
+
})[code] || '';
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* Two rules keep the share display true (slice 5, rebuilt after review):
|
|
1143
|
+
* - Actions (share, publish, cancel, revoke, retry) are numbered; only the NEWEST action's answer is applied. An
|
|
1144
|
+
* answer that lost to a newer action is dropped and asks the server for where things stand, so the display never
|
|
1145
|
+
* stays on what an older action left (a publish superseded by a Cancel, or by the Page being opened again).
|
|
1146
|
+
* - Status reads (opening, the progress poll) are applied only when no action started or answered since they began.
|
|
1147
|
+
* A share answer changes only the Page's share record (versions, title and sites are not touched by sharing), so
|
|
1148
|
+
* applying it never waits.
|
|
1149
|
+
*/
|
|
1150
|
+
async function shareCall(path, method, payload) {
|
|
1151
|
+
const home = view.home;
|
|
1152
|
+
const id = view.page.id;
|
|
1153
|
+
view.shareBannerDismissed = false;
|
|
1154
|
+
const ticket = ++view.actionSeq;
|
|
1155
|
+
view.shareSeq += 1; // a status read already out is older than this action
|
|
1156
|
+
const current = () => view.page?.id === id && view.home === home && ticket === view.actionSeq;
|
|
1157
|
+
const adoptShare = (page) => { if (page) view.page = { ...view.page, share: page.share ?? null }; };
|
|
1158
|
+
$share.setAttribute('aria-busy', 'true');
|
|
1159
|
+
try {
|
|
1160
|
+
const body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}/share${path}`, {
|
|
1161
|
+
method, ...(payload ? { body: JSON.stringify(payload) } : {}),
|
|
1162
|
+
});
|
|
1163
|
+
if (!current()) { if (view.page?.id === id && isOpen()) void loadShare(); return null; }
|
|
1164
|
+
view.shareSeq += 1;
|
|
1165
|
+
adoptShare(body.page);
|
|
1166
|
+
view.share = { ...(view.share || {}), share: body.share, error: null };
|
|
1167
|
+
return body.outcome;
|
|
1168
|
+
} catch (err) {
|
|
1169
|
+
if (!current()) { if (view.page?.id === id && isOpen()) void loadShare(); return null; }
|
|
1170
|
+
view.shareSeq += 1;
|
|
1171
|
+
const answer = err?.body;
|
|
1172
|
+
if (answer?.outcome && answer.page) {
|
|
1173
|
+
// An answer, not a failure: the share published nothing and says why (needs a plan, too large, …), with the Page's record.
|
|
1174
|
+
adoptShare(answer.page);
|
|
1175
|
+
view.share = { ...(view.share || {}), share: answer.share,
|
|
1176
|
+
error: answer.outcome === 'share-too-large' ? { code: 'share-too-large', message: answer.reason, path: answer.path || null } : null };
|
|
1177
|
+
return answer.outcome;
|
|
1178
|
+
}
|
|
1179
|
+
const code = err?.body?.code || 'offline';
|
|
1180
|
+
const path = code === 'share-too-large' && (payload?.version ?? latestN()) === latestN() ? view.share?.eligibility?.path || null : null;
|
|
1181
|
+
view.share = { ...(view.share || {}), error: { code, message: err?.body?.error || outcomeSentence('offline'), path } };
|
|
1182
|
+
return null;
|
|
1183
|
+
} finally {
|
|
1184
|
+
// Only the newest action owns the busy mark (even after the viewer moved to another Page, so nothing is left busy),
|
|
1185
|
+
// and only the newest action on the Page still open repaints.
|
|
1186
|
+
if (ticket === view.actionSeq) $share.removeAttribute('aria-busy');
|
|
1187
|
+
if (current()) {
|
|
1188
|
+
paintHeader();
|
|
1189
|
+
paintShareButton();
|
|
1190
|
+
paintSharePop();
|
|
1191
|
+
paintBanner();
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
/**
|
|
1197
|
+
* While a publish runs, read its progress every second (slice 5): a version with files uploads them first, which can
|
|
1198
|
+
* take minutes, and the record turns "publishing" on the server at once — so Cancel is reachable and the banner counts
|
|
1199
|
+
* up. Returns the function that stops it; nothing it read after that is used.
|
|
1200
|
+
*/
|
|
1201
|
+
function watchPublish({ untilSettled = false } = {}) {
|
|
1202
|
+
const home = view.home;
|
|
1203
|
+
const id = view.page?.id;
|
|
1204
|
+
let live = true;
|
|
1205
|
+
let busy = false;
|
|
1206
|
+
let timer = null;
|
|
1207
|
+
view.stopWatch?.();
|
|
1208
|
+
const stop = () => {
|
|
1209
|
+
live = false;
|
|
1210
|
+
clearTimeout(timer);
|
|
1211
|
+
if (view.stopWatch === stop) { view.stopWatch = null; view.shareProgress = null; }
|
|
1212
|
+
};
|
|
1213
|
+
const tick = async () => {
|
|
1214
|
+
if (!live || busy) return;
|
|
1215
|
+
if (!isOpen() || view.home !== home || view.page?.id !== id) { stop(); return; }
|
|
1216
|
+
busy = true;
|
|
1217
|
+
// Any action that started or answered while this read was out (a Cancel, the publish's own answer) makes it old.
|
|
1218
|
+
const seq = view.shareSeq;
|
|
1219
|
+
try {
|
|
1220
|
+
const body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}/share`);
|
|
1221
|
+
if (!live || seq !== view.shareSeq || view.home !== home || view.page?.id !== id) return;
|
|
1222
|
+
const changed = JSON.stringify(body.share?.state) !== JSON.stringify(view.share?.share?.state) || !!body.progress !== !!view.shareProgress;
|
|
1223
|
+
view.share = { ...(view.share || {}), share: body.share };
|
|
1224
|
+
view.shareProgress = body.progress || null;
|
|
1225
|
+
if (untilSettled && body.share?.state !== 'pending-publish') {
|
|
1226
|
+
// Settled by the run FloLess resumed: show where the link stands now, and stop asking.
|
|
1227
|
+
stop();
|
|
1228
|
+
paintShareButton(); paintSharePop(); paintBanner();
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
const line = $banner.dataset.kind === 'share-progress' && view.shareProgress ? $banner.querySelector('[data-share-progress]') : null;
|
|
1232
|
+
if (line && !changed) { line.textContent = progressText(view.shareProgress); return; }
|
|
1233
|
+
paintShareButton();
|
|
1234
|
+
paintSharePop();
|
|
1235
|
+
paintBanner();
|
|
1236
|
+
} catch { /* the publish's own answer says what happened */ } finally { busy = false; }
|
|
1237
|
+
};
|
|
1238
|
+
const loop = () => { timer = setTimeout(async () => { await tick(); if (live) loop(); }, 1000); };
|
|
1239
|
+
view.stopWatch = stop;
|
|
1240
|
+
loop();
|
|
1241
|
+
return stop;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
async function publish(payload, first) {
|
|
1245
|
+
const watch = watchPublish();
|
|
1246
|
+
let outcome;
|
|
1247
|
+
// null: a newer action (the person's Cancel) superseded this publish and has already said what happened.
|
|
1248
|
+
try { outcome = await shareCall('', 'POST', payload); }
|
|
1249
|
+
finally { watch(); paintBanner(); }
|
|
1250
|
+
if (outcome === null) return;
|
|
1251
|
+
// Another run (FloLess catching up in the background) settled this publish: the record says what happened.
|
|
1252
|
+
if (outcome === 'settled-elsewhere') { void loadShare(); return; }
|
|
1253
|
+
const s = view.share?.share;
|
|
1254
|
+
if (outcome === 'published' && s?.url) {
|
|
1255
|
+
let copied = false;
|
|
1256
|
+
if (first) { try { await navigator.clipboard.writeText(s.url); copied = true; } catch { copied = false; } }
|
|
1257
|
+
toast(first ? (copied ? 'Link created and copied. Anyone with it can open this Page.' : 'Link created. Copy it from the Share menu.')
|
|
1258
|
+
: `Published. Everyone with the link now sees ${verLabel(s.publishedPageVersion)}.`, 'ok');
|
|
1259
|
+
} else if (outcome === 'stale') {
|
|
1260
|
+
// Said in the banner, with the choice.
|
|
1261
|
+
} else if (outcome === 'revoke-pending') {
|
|
1262
|
+
toast('This link is being revoked, so the new version wasn’t published.', 'warn');
|
|
1263
|
+
} else if (outcome && outcome !== 'published') {
|
|
1264
|
+
const sentence = outcomeSentence(outcome);
|
|
1265
|
+
if (['no_subscription', 'too_large', 'quota', 'damaged', 'cancelled', 'reused', 'unsupported', 'revoked', 'not_found'].includes(outcome)) {
|
|
1266
|
+
view.share = { ...(view.share || {}), error: { code: outcome, message: sentence, path: null } };
|
|
1267
|
+
paintBanner();
|
|
1268
|
+
} else if (sentence) toast(sentence, 'warn');
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
function closeSharePop() {
|
|
1273
|
+
$sharePop.hidden = true;
|
|
1274
|
+
$share.setAttribute('aria-expanded', 'false');
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
$share.addEventListener('click', () => {
|
|
1278
|
+
if (!$sharePop.hidden) { closePopovers(); return; }
|
|
1279
|
+
closePopovers();
|
|
1280
|
+
paintSharePop();
|
|
1281
|
+
$sharePop.hidden = false;
|
|
1282
|
+
$share.setAttribute('aria-expanded', 'true');
|
|
1283
|
+
($sharePop.querySelector('.pv-share-primary') || $sharePop.querySelector('button'))?.focus();
|
|
1284
|
+
});
|
|
1285
|
+
|
|
1286
|
+
async function onShareAct(act, button) {
|
|
1287
|
+
const s = view.share?.share;
|
|
1288
|
+
if (act === 'create') { closePopovers(); $share.focus(); await publish({ version: view.n }, true); return; }
|
|
1289
|
+
if (act === 'publish') { closePopovers(); await publish({ version: Number(button.dataset.n) }, false); return; }
|
|
1290
|
+
if (act === 'replace') { await publish({ expectedRemoteVersion: Number(button.dataset.expected), version: Number(button.dataset.n) || latestN() }, false); return; }
|
|
1291
|
+
if (act === 'keep-theirs') { view.shareBannerDismissed = true; paintBanner(); toast('Kept the link as it is.', 'ok'); return; }
|
|
1292
|
+
if (act === 'cancel') {
|
|
1293
|
+
closePopovers();
|
|
1294
|
+
view.shareProgress = null;
|
|
1295
|
+
const outcome = await shareCall('/cancel', 'POST');
|
|
1296
|
+
if (outcome === 'cancelled') toast('Publishing cancelled. The link is as it was.', 'ok');
|
|
1297
|
+
else if (outcome === 'published') toast('It had already been published, so the link shows it.', 'ok');
|
|
1298
|
+
else if (outcome && outcome !== 'nothing-to-do') toast(outcomeSentence(outcome), 'warn');
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
if (act === 'revoke') {
|
|
1302
|
+
closePopovers();
|
|
1303
|
+
const ok = await bridge.formModal?.({
|
|
1304
|
+
title: 'Revoke this link?',
|
|
1305
|
+
sub: 'Anyone with the link will no longer be able to open it. A copy someone has already opened or saved can’t be taken back. Sharing the Page again makes a new link.',
|
|
1306
|
+
fields: [], okLabel: 'Revoke link', danger: true, safeDefault: true, returnFocusTo: $share,
|
|
1307
|
+
});
|
|
1308
|
+
if (!ok) return;
|
|
1309
|
+
const outcome = await shareCall('', 'DELETE');
|
|
1310
|
+
if (outcome === 'revoked') toast('Link revoked. It no longer opens.', 'ok');
|
|
1311
|
+
else if (outcome === 'revoke-pending') toast('FloLess will revoke the link as soon as it can reach floless.io.', 'warn');
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
if (act === 'retry') { await publish({}, false); return; }
|
|
1315
|
+
if (act === 'retry-revoke') { await shareCall('', 'DELETE'); return; }
|
|
1316
|
+
if (act === 'copy') {
|
|
1317
|
+
try { await navigator.clipboard.writeText(s?.url || ''); toast('Link copied.', 'ok'); }
|
|
1318
|
+
catch { $sharePop.querySelector('.pv-share-url')?.select(); toast('FloLess couldn’t copy the link. It’s selected, so copy it with Ctrl+C.', 'warn'); }
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
if (act === 'open') { if (s?.url) window.open(s.url, '_blank', 'noopener'); return; }
|
|
1322
|
+
if (act === 'plans') { window.open(PLANS_URL, '_blank', 'noopener'); return; }
|
|
1323
|
+
if (act === 'reveal') {
|
|
1324
|
+
const path = view.share?.error?.path;
|
|
1325
|
+
if (!path) return;
|
|
1326
|
+
try { await api('/api/reveal', { method: 'POST', body: JSON.stringify({ path }) }); }
|
|
1327
|
+
catch (err) { toast(`FloLess couldn’t show the file. ${err?.body?.error || 'Try again in a moment.'}`, 'warn'); }
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1330
|
+
if (act === 'dismiss') { view.share = { ...(view.share || {}), error: null }; view.shareBannerDismissed = true; paintBanner(); $frame.focus(); return; }
|
|
1331
|
+
if (act === 'mine') { closePopovers(); openSharedLinks($share); }
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
$sharePop.addEventListener('click', (event) => {
|
|
1335
|
+
const button = event.target.closest('button[data-share-act]');
|
|
1336
|
+
if (button) void onShareAct(button.dataset.shareAct, button);
|
|
1337
|
+
});
|
|
1338
|
+
$banner.addEventListener('click', (event) => {
|
|
1339
|
+
const button = event.target.closest('button[data-share-act]');
|
|
1340
|
+
if (button) void onShareAct(button.dataset.shareAct, button);
|
|
1341
|
+
});
|
|
1342
|
+
|
|
1343
|
+
// ── My shared links (#2262 slice 4) ──
|
|
1344
|
+
|
|
1345
|
+
const $sl = document.getElementById('shared-links-modal');
|
|
1346
|
+
const $slList = document.getElementById('sl-list');
|
|
1347
|
+
const $slNote = document.getElementById('sl-note');
|
|
1348
|
+
const $slMore = document.getElementById('sl-more');
|
|
1349
|
+
const $slClose = document.getElementById('sl-close');
|
|
1350
|
+
const sl = { next: null, rows: [], local: [], returnFocus: null, loading: false };
|
|
1351
|
+
|
|
1352
|
+
const CHIP = { live: 'Live', 'pending-publish': 'Publishing', 'pending-revoke': 'Revoke waiting', revoked: 'Revoked' };
|
|
1353
|
+
|
|
1354
|
+
function slRowHtml(row) {
|
|
1355
|
+
const chip = row.state ? `<span class="sl-chip" data-state="${esc(row.state)}">${esc(CHIP[row.state] || '')}</span>` : '';
|
|
1356
|
+
const ai = row.aiMade ? '<span class="pg-ai-badge" tabindex="0" data-tip="Made by AI. FloLess doesn’t check its figures or statements.">AI-made</span>' : '';
|
|
1357
|
+
const titleCell = row.page && !row.deleted
|
|
1358
|
+
? `<button type="button" class="sl-title-open" data-command-id="shell.shared-link-page#${esc(row.title)}" data-sl-act="page" data-home="${esc(row.page.home)}" data-page="${esc(row.page.pageId)}">${esc(row.title || 'Untitled Page')}</button>`
|
|
1359
|
+
: `<span class="pg-row-title">${esc(row.title || 'Untitled')}</span>`;
|
|
1360
|
+
const canAct = row.token && row.url && row.state !== 'revoked' && row.state !== 'pending-revoke';
|
|
1361
|
+
const actions = canAct ? `
|
|
1362
|
+
<button type="button" class="ghost" data-command-id="shell.shared-link-copy#${esc(row.title)}" data-sl-act="copy" data-url="${esc(row.url)}">Copy</button>
|
|
1363
|
+
<button type="button" class="ghost" data-command-id="shell.shared-link-open#${esc(row.title)}" data-sl-act="open" data-url="${esc(row.url)}">Open</button>
|
|
1364
|
+
<button type="button" class="ghost sl-revoke" data-command-id="shell.shared-link-revoke#${esc(row.title)}" data-sl-act="revoke" data-token="${esc(row.token)}" data-title="${esc(row.title)}">Revoke</button>` : '';
|
|
1365
|
+
return `<div class="pg-row sl-row" role="listitem">
|
|
1366
|
+
<div class="pg-row-text sl-row-text"><span class="pg-row-line">${titleCell}${ai}${chip}</span>
|
|
1367
|
+
<span class="pg-row-meta" ${row.when ? `data-tip="${esc(when(row.when))}"` : ''}>${esc(row.meta)}</span></div>
|
|
1368
|
+
<div class="sl-actions">${actions}</div></div>`;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/** floless.io's list joined with what this computer holds, so a Page's link shows its Page and a waiting revoke shows. */
|
|
1372
|
+
function slRows(remote, local) {
|
|
1373
|
+
const byToken = new Map();
|
|
1374
|
+
for (const l of local) if (l.share?.token) byToken.set(l.share.token, l);
|
|
1375
|
+
const rows = remote.map((r) => {
|
|
1376
|
+
const mine = byToken.get(r.token);
|
|
1377
|
+
byToken.delete(r.token);
|
|
1378
|
+
const state = r.revoked ? 'revoked' : (mine?.share?.state === 'pending-revoke' ? 'pending-revoke' : 'live');
|
|
1379
|
+
const kind = r.kind === 'page' ? `Page link · link version ${r.remoteVersion}` : 'Report link';
|
|
1380
|
+
return { token: r.token, url: r.url, title: mine?.title || r.title, aiMade: r.aiMade, state, page: mine ? { home: mine.home, pageId: mine.pageId } : null,
|
|
1381
|
+
deleted: !!mine?.deleted, when: r.updatedAt || r.createdAt, meta: `${kind} · updated ${ago(r.updatedAt || r.createdAt)}` };
|
|
1382
|
+
});
|
|
1383
|
+
return rows;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
function slLocalOnly(local, remoteTokens) {
|
|
1387
|
+
return local.filter((l) => l.deleted || l.share?.state === 'pending-publish' || (l.share?.token && !remoteTokens.has(l.share.token))).map((l) => {
|
|
1388
|
+
const state = l.deleted ? 'pending-revoke' : l.share?.state || null;
|
|
1389
|
+
const meta = l.deleted ? 'Page deleted · its link will be revoked when FloLess can reach floless.io'
|
|
1390
|
+
: l.share?.state === 'pending-publish' ? 'Waiting to publish'
|
|
1391
|
+
: `Page link · link version ${l.share?.remoteVersion ?? 1}`;
|
|
1392
|
+
return { token: l.share?.token || null, url: l.share?.url || null, title: l.title, aiMade: false, state, page: { home: l.home, pageId: l.pageId }, deleted: l.deleted, when: l.share?.updatedAt || null, meta };
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
async function slLoad(more) {
|
|
1397
|
+
if (sl.loading) return;
|
|
1398
|
+
sl.loading = true;
|
|
1399
|
+
$slMore.setAttribute('aria-busy', 'true');
|
|
1400
|
+
try {
|
|
1401
|
+
const q = more && sl.next ? `?before=${encodeURIComponent(sl.next)}` : '';
|
|
1402
|
+
const body = await api(`/api/pages/shared-links${q}`);
|
|
1403
|
+
if (!more) { sl.rows = []; sl.local = body.local || []; }
|
|
1404
|
+
const remote = body.remote?.ok ? body.remote.links : [];
|
|
1405
|
+
sl.next = body.remote?.ok ? body.remote.next : null;
|
|
1406
|
+
sl.rows.push(...slRows(remote, sl.local));
|
|
1407
|
+
const tokens = new Set(sl.rows.map((r) => r.token));
|
|
1408
|
+
const localOnly = !body.remote?.ok || !sl.next ? slLocalOnly(sl.local, tokens) : [];
|
|
1409
|
+
// Slice 5: how much of the person's space for shared files is used (revoking a link frees what only it used).
|
|
1410
|
+
const usage = body.remote?.ok ? body.remote.usage : null;
|
|
1411
|
+
const size = (b) => (b >= 1024 ** 3 ? `${(b / 1024 ** 3).toFixed(1)} GB` : `${Math.round(b / 1024 ** 2)} MB`);
|
|
1412
|
+
$slNote.hidden = !!body.remote?.ok && !usage;
|
|
1413
|
+
$slNote.textContent = body.remote?.ok ? (usage ? `${usage.usedBytes >= usage.quotaBytes * 0.9 ? 'Almost full. ' : ''}Files kept on floless.io for your shared links: ${size(usage.usedBytes)} of ${size(usage.quotaBytes)}. Space a revoked link used alone is freed within a day.` : '') : (body.remote?.error === 'signed_out'
|
|
1414
|
+
? 'You’re signed out, so FloLess can’t check floless.io. This shows the links this computer knows about. Sign in to see all of them.'
|
|
1415
|
+
: 'FloLess couldn’t reach floless.io, so this shows the links this computer knows about.');
|
|
1416
|
+
const all = [...sl.rows, ...localOnly];
|
|
1417
|
+
$slList.innerHTML = all.length ? all.map(slRowHtml).join('')
|
|
1418
|
+
: '<p class="pg-empty sl-empty">No shared links yet. Share a Page from its viewer with the Share button.</p>';
|
|
1419
|
+
$slMore.hidden = !sl.next;
|
|
1420
|
+
} catch (err) {
|
|
1421
|
+
$slNote.hidden = false;
|
|
1422
|
+
$slNote.textContent = `FloLess couldn’t list your shared links. ${err?.body?.error || 'Try again in a moment.'}`;
|
|
1423
|
+
} finally {
|
|
1424
|
+
sl.loading = false;
|
|
1425
|
+
$slMore.removeAttribute('aria-busy');
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
function openSharedLinks(returnFocus) {
|
|
1430
|
+
if (!$sl) return;
|
|
1431
|
+
sl.returnFocus = returnFocus instanceof HTMLElement ? returnFocus : document.activeElement;
|
|
1432
|
+
$slList.innerHTML = '<p class="pg-loading-line">Loading your shared links…</p>';
|
|
1433
|
+
$slMore.hidden = true;
|
|
1434
|
+
$sl.classList.add('show');
|
|
1435
|
+
$slClose.focus();
|
|
1436
|
+
void slLoad(false);
|
|
1437
|
+
}
|
|
1438
|
+
function closeSharedLinks() {
|
|
1439
|
+
if (!$sl?.classList.contains('show')) return;
|
|
1440
|
+
$sl.classList.remove('show');
|
|
1441
|
+
const back = sl.returnFocus;
|
|
1442
|
+
sl.returnFocus = null;
|
|
1443
|
+
if (back?.isConnected) back.focus();
|
|
1444
|
+
}
|
|
1445
|
+
if ($sl) {
|
|
1446
|
+
$slClose.addEventListener('click', closeSharedLinks);
|
|
1447
|
+
$slMore.addEventListener('click', () => { void slLoad(true); });
|
|
1448
|
+
if (typeof window.onBackdropDismiss === 'function') window.onBackdropDismiss($sl, closeSharedLinks);
|
|
1449
|
+
$sl.addEventListener('keydown', (event) => {
|
|
1450
|
+
if (event.key === 'Escape') { event.stopPropagation(); closeSharedLinks(); return; }
|
|
1451
|
+
if (event.key !== 'Tab') return;
|
|
1452
|
+
const focusables = [...$sl.querySelectorAll('button, [tabindex="0"]')].filter((el) => !el.disabled && el.offsetParent !== null);
|
|
1453
|
+
if (!focusables.length) return;
|
|
1454
|
+
const first = focusables[0];
|
|
1455
|
+
const last = focusables[focusables.length - 1];
|
|
1456
|
+
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
|
1457
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
|
1458
|
+
});
|
|
1459
|
+
$slList.addEventListener('click', async (event) => {
|
|
1460
|
+
const button = event.target.closest('button[data-sl-act]');
|
|
1461
|
+
if (!button) return;
|
|
1462
|
+
const act = button.dataset.slAct;
|
|
1463
|
+
if (act === 'copy') {
|
|
1464
|
+
try { await navigator.clipboard.writeText(button.dataset.url); toast('Link copied.', 'ok'); }
|
|
1465
|
+
catch { toast('FloLess couldn’t copy the link. Open it and copy it from the address bar.', 'warn'); }
|
|
1466
|
+
} else if (act === 'open') {
|
|
1467
|
+
window.open(button.dataset.url, '_blank', 'noopener');
|
|
1468
|
+
} else if (act === 'page') {
|
|
1469
|
+
closeSharedLinks();
|
|
1470
|
+
void openViewer(button.dataset.home, button.dataset.page, null, document.activeElement);
|
|
1471
|
+
} else if (act === 'revoke') {
|
|
1472
|
+
const ok = await bridge.formModal?.({
|
|
1473
|
+
title: `Revoke the link to “${button.dataset.title || 'this Page'}”?`,
|
|
1474
|
+
sub: 'Anyone with the link will no longer be able to open it. A copy someone has already opened or saved can’t be taken back.',
|
|
1475
|
+
fields: [], okLabel: 'Revoke link', danger: true, safeDefault: true, returnFocusTo: button,
|
|
1476
|
+
});
|
|
1477
|
+
if (!ok) return;
|
|
1478
|
+
try {
|
|
1479
|
+
const body = await api('/api/pages/shared-links/revoke', { method: 'POST', body: JSON.stringify({ token: button.dataset.token }) });
|
|
1480
|
+
if (body.outcome === 'revoked') toast('Link revoked. It no longer opens.', 'ok');
|
|
1481
|
+
else if (body.outcome === 'revoke-pending') toast('FloLess will revoke the link as soon as it can reach floless.io.', 'warn');
|
|
1482
|
+
else toast(outcomeSentence(body.outcome) || 'FloLess couldn’t revoke the link just now. Try again in a moment.', 'warn');
|
|
1483
|
+
} catch (err) {
|
|
1484
|
+
toast(`FloLess couldn’t revoke the link. ${err?.body?.error || 'Try again in a moment.'}`, 'warn');
|
|
1485
|
+
}
|
|
1486
|
+
await slLoad(false);
|
|
1487
|
+
// The Pages lists' chips and an open viewer's Share button read the same link: repaint them too.
|
|
1488
|
+
refreshLists();
|
|
1489
|
+
if (isOpen()) void loadShare();
|
|
1490
|
+
$slClose.focus();
|
|
1491
|
+
}
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
document.addEventListener('click', (event) => {
|
|
1495
|
+
const opener = event.target.closest('[data-command-id="shell.shared-links-open"]');
|
|
1496
|
+
if (opener && !opener.closest('#pv-share-pop')) openSharedLinks(opener);
|
|
1497
|
+
});
|
|
1498
|
+
|
|
585
1499
|
$close.addEventListener('click', closeViewer);
|
|
586
1500
|
if (typeof window.onBackdropDismiss === 'function') window.onBackdropDismiss($modal, closeViewer);
|
|
587
1501
|
|
|
@@ -590,11 +1504,12 @@
|
|
|
590
1504
|
event.stopPropagation();
|
|
591
1505
|
if (!$versionPop.hidden) { closePopovers(); $version.focus(); return; }
|
|
592
1506
|
if (!$sitesPop.hidden) { closePopovers(); $sites.focus(); return; }
|
|
1507
|
+
if (!$sharePop.hidden) { closePopovers(); $share.focus(); return; }
|
|
593
1508
|
closeViewer();
|
|
594
1509
|
return;
|
|
595
1510
|
}
|
|
596
1511
|
if (event.key !== 'Tab') return;
|
|
597
|
-
const focusables = [...$modal.querySelectorAll('button, [tabindex="0"], iframe')]
|
|
1512
|
+
const focusables = [...$modal.querySelectorAll('button, input, [tabindex="0"], iframe')]
|
|
598
1513
|
.filter((el) => !el.disabled && el.offsetParent !== null);
|
|
599
1514
|
if (!focusables.length) return;
|
|
600
1515
|
const first = focusables[0];
|
|
@@ -606,11 +1521,35 @@
|
|
|
606
1521
|
if (!isOpen()) return;
|
|
607
1522
|
if (!$versionPop.hidden && !event.target.closest('#pv-version, #pv-version-pop')) closePopovers();
|
|
608
1523
|
if (!$sitesPop.hidden && !event.target.closest('#pv-sites, #pv-sites-pop')) closePopovers();
|
|
1524
|
+
if (!$sharePop.hidden && !event.target.closest('#pv-share, #pv-share-pop')) closePopovers();
|
|
1525
|
+
});
|
|
1526
|
+
|
|
1527
|
+
// #2262 slice 3c: the version's complete report, opened in FloLess's report viewer. The server finds it from the
|
|
1528
|
+
// version's run; the Page's frame can't ask for it and its record never holds the report's handle.
|
|
1529
|
+
$fullReport?.addEventListener('click', async () => {
|
|
1530
|
+
const v = currentVersion();
|
|
1531
|
+
if (!view.page || !v || v.content?.kind !== 'complete-report') return;
|
|
1532
|
+
const host = window.FlolessReports;
|
|
1533
|
+
if (!host?.openPageVersionReport) return;
|
|
1534
|
+
// Busy, not disabled: the button keeps its focus while FloLess asks for the report.
|
|
1535
|
+
if ($fullReport.getAttribute('aria-busy') === 'true') return;
|
|
1536
|
+
$fullReport.setAttribute('aria-busy', 'true');
|
|
1537
|
+
try {
|
|
1538
|
+
await host.openPageVersionReport({ home: view.home, id: view.page.id, n: v.n, title: view.page.title, beforeShow: () => closeViewer() });
|
|
1539
|
+
} finally { $fullReport.removeAttribute('aria-busy'); }
|
|
609
1540
|
});
|
|
610
1541
|
|
|
611
1542
|
window.flolessPages = {
|
|
612
1543
|
renderList,
|
|
1544
|
+
renderWorkflowsList,
|
|
1545
|
+
repaintWorkflowsList,
|
|
1546
|
+
openSharedLinks: (returnFocus) => openSharedLinks(returnFocus),
|
|
613
1547
|
open: (home, id, n) => openViewer(home, id, n ?? null, document.activeElement),
|
|
614
1548
|
refresh: refreshLists,
|
|
1549
|
+
/** The server changed this Page's record (a failed live session's labels): an open copy re-reads it. */
|
|
1550
|
+
reloadIfOpen: (home, id) => {
|
|
1551
|
+
if (!isOpen() || view.home !== home || view.page?.id !== id) return;
|
|
1552
|
+
void reloadRecord();
|
|
1553
|
+
},
|
|
615
1554
|
};
|
|
616
1555
|
})();
|