@floless/app 0.156.0 → 0.157.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 +21 -5
- package/dist/floless-server.cjs +70965 -43326
- 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 +79 -17
- package/dist/skills/floless-app-knowledge/SKILL.md +21 -2
- 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 +1 -1
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +4 -2
- 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 +478 -3
- package/dist/web/app.js +110 -11
- package/dist/web/aware-update-client.js +1 -0
- package/dist/web/aware.js +685 -170
- package/dist/web/chat-landing-scene.js +372 -0
- package/dist/web/chat.css +245 -1
- package/dist/web/chat.js +2466 -78
- package/dist/web/commands-drawing-check.js +17 -0
- package/dist/web/commands-shell.js +820 -3
- 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 +119 -6
- package/dist/web/instructor.js +3 -3
- package/dist/web/model-view-query.js +12 -2
- package/dist/web/pages.js +865 -34
- 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/report-files.js +50 -0
- package/dist/web/startup-admission.js +132 -0
- package/dist/web/steel-3d-core.js +9 -0
- package/dist/web/steel-editor.html +642 -22
- package/dist/web/steel-model-v2-commands.js +63 -5
- package/dist/web/step-rename.js +287 -0
- package/dist/web/terminal-requests.js +59 -10
- package/dist/web/tool-updates.js +1 -0
- package/dist/web/workspace-root-management.js +39 -0
- package/dist/web/workspaces.js +1667 -63
- package/launch.mjs +9 -7
- package/package.json +3 -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,11 +52,42 @@
|
|
|
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
|
|
|
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' };
|
|
59
91
|
function rowHtml(home, p) {
|
|
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
|
|
@@ -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 = [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>`;
|
|
@@ -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,7 +168,7 @@
|
|
|
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
|
}
|
|
@@ -181,12 +218,15 @@
|
|
|
181
218
|
const $title = $('pv-title');
|
|
182
219
|
const $sub = $('pv-sub');
|
|
183
220
|
const $ai = $('pv-ai');
|
|
221
|
+
const $seq = $('pv-seq');
|
|
222
|
+
const $seqText = $('pv-seq-text');
|
|
184
223
|
const $version = $('pv-version');
|
|
185
224
|
const $versionPop = $('pv-version-pop');
|
|
186
225
|
const $sites = $('pv-sites');
|
|
187
226
|
const $sitesPop = $('pv-sites-pop');
|
|
188
227
|
const $allowed = $('pv-allowed');
|
|
189
228
|
const $full = $('pv-full');
|
|
229
|
+
const $fullReport = $('pv-full-report');
|
|
190
230
|
const $delete = $('pv-delete');
|
|
191
231
|
const $close = $('pv-close');
|
|
192
232
|
const $banner = $('pv-banner');
|
|
@@ -196,6 +236,9 @@
|
|
|
196
236
|
|
|
197
237
|
const view = {
|
|
198
238
|
home: null, page: null, n: null, returnFocus: null,
|
|
239
|
+
known: [], // the versions loaded so far: a contiguous run of the newest, oldest first (#2291)
|
|
240
|
+
pagingOlder: false, // a "Show older versions" request is in flight
|
|
241
|
+
openSeq: 0, // each open counts up, so an earlier open's late answer never replaces a newer one
|
|
199
242
|
linkAsk: null, // { href }
|
|
200
243
|
blocked: new Map(), // host → origin, waiting for a decision
|
|
201
244
|
note: null, // a one-line explanation with nothing to decide (a link or load FloLess can never allow)
|
|
@@ -203,28 +246,146 @@
|
|
|
203
246
|
kept: new Set(), // origins kept blocked for this Page this session
|
|
204
247
|
reviewOpen: false,
|
|
205
248
|
loadTimer: null,
|
|
249
|
+
frameKeys: {}, // version → the key its frame address carries so the version's files load (slice 5)
|
|
250
|
+
shareProgress: null, // { files, filesDone, bytes, bytesDone } while a publish uploads the version's files (slice 5)
|
|
251
|
+
stopWatch: null, // stops the one progress poll running for the open Page (slice 5)
|
|
252
|
+
share: null, // { share, eligibility, error } — the Page's link (slice 4)
|
|
253
|
+
shareBannerDismissed: false,
|
|
254
|
+
shareSeq: 0, // status reads: each read, and each share action, takes the next number; only the newest read is applied
|
|
255
|
+
actionSeq: 0, // share actions: only the newest action's answer is applied (slice 5)
|
|
206
256
|
};
|
|
207
257
|
|
|
208
258
|
function isOpen() { return $modal.classList.contains('show'); }
|
|
209
259
|
|
|
260
|
+
/** The frame address. With its version's key it is folder-shaped, so the Page's `assets/…` files resolve (slice 5);
|
|
261
|
+
* without one (an older server) it is the plain address, which shows the HTML alone. */
|
|
210
262
|
function contentUrl() {
|
|
211
|
-
|
|
263
|
+
const base = `/pages-content/${encodeURIComponent(view.home)}/${encodeURIComponent(view.page.id)}/${view.n}`;
|
|
264
|
+
const key = view.frameKeys[view.n];
|
|
265
|
+
return key ? `${base}/${encodeURIComponent(key)}/` : base;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Learn version `n`'s frame key when no answer so far carried it (a record a share or site change returned). */
|
|
269
|
+
async function ensureFrameKey(n) {
|
|
270
|
+
if (view.frameKeys[n]) return;
|
|
271
|
+
const home = view.home;
|
|
272
|
+
const id = view.page?.id;
|
|
273
|
+
try {
|
|
274
|
+
const body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}/versions?before=${n + 1}&limit=1`);
|
|
275
|
+
if (view.home === home && view.page?.id === id) Object.assign(view.frameKeys, body.frameKeys || {});
|
|
276
|
+
} catch { /* the plain address still shows the HTML */ }
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// #2291: a Page record carries its newest versions (the window) and `history.count`; older ones are paged in on
|
|
280
|
+
// demand. `view.known` is always a contiguous run of the newest versions, oldest first, so a version's place in the
|
|
281
|
+
// whole history is count minus the versions newer than it — never its position in what happens to be loaded.
|
|
282
|
+
function totalVersions() { return view.page?.history?.count ?? view.known.length; }
|
|
283
|
+
function position(v) { return totalVersions() - view.known.filter((x) => x.n > v.n).length; }
|
|
284
|
+
function currentVersion() { return view.known.find((v) => v.n === view.n) || null; }
|
|
285
|
+
const CAPTURE_TEXT = { live: 'Captured during a live session', 'live-failed': 'Captured during a live session that later failed' };
|
|
286
|
+
|
|
287
|
+
// #2262 slice 3c: what a workflow version holds when it is more than an HTML report.
|
|
288
|
+
function contentText(v) {
|
|
289
|
+
const c = v?.content;
|
|
290
|
+
if (!c) return '';
|
|
291
|
+
if (c.kind === 'complete-report') return c.whole ? 'Complete model report' : 'Complete model report · summary only';
|
|
292
|
+
if (c.kind === '3d-view') return c.tooBig ? '3D view · summary only' : '3D view';
|
|
293
|
+
return '';
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Page older versions in until `n` is known (or the history is exhausted). Answers 'known', 'gone' (the history has
|
|
297
|
+
* no such version) or 'moved' (the viewer switched to another Page meanwhile); a failed request throws. */
|
|
298
|
+
async function ensureKnown(n) {
|
|
299
|
+
const home = view.home;
|
|
300
|
+
const id = view.page?.id;
|
|
301
|
+
while (!view.known.some((v) => v.n === n) && view.known.length < totalVersions() && view.known[0] && view.known[0].n > n) {
|
|
302
|
+
const before = view.known[0].n;
|
|
303
|
+
const body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}/versions?before=${before}&limit=200`);
|
|
304
|
+
const older = Array.isArray(body.versions) ? [...body.versions].reverse() : [];
|
|
305
|
+
if (view.home !== home || view.page?.id !== id) return 'moved';
|
|
306
|
+
// Another page-in (or a refreshed record) may have moved the oldest known version while this one was in flight;
|
|
307
|
+
// its answer would then repeat versions or leave a gap, so drop it and ask again from where the run now starts.
|
|
308
|
+
if (view.known[0]?.n !== before) continue;
|
|
309
|
+
if (!older.length) break;
|
|
310
|
+
Object.assign(view.frameKeys, body.frameKeys || {});
|
|
311
|
+
view.known = [...older, ...view.known];
|
|
312
|
+
}
|
|
313
|
+
return view.known.some((v) => v.n === n) ? 'known' : 'gone';
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Why version `n` is not the one on screen, in the person's terms: a workflow's Page drops its oldest versions; any
|
|
317
|
+
* other Page keeps them, so a missing one there is not retention. */
|
|
318
|
+
function goneNote(n) {
|
|
319
|
+
return view.page?.source?.kind === 'workflow'
|
|
320
|
+
? `Version ${n} is no longer kept. A workflow's Page keeps its newest twenty versions, so you're now seeing the latest.`
|
|
321
|
+
: `Version ${n} isn't in this Page's history any more, so you're now seeing the latest.`;
|
|
322
|
+
}
|
|
323
|
+
function failedNote(n, err) {
|
|
324
|
+
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
325
|
}
|
|
213
326
|
|
|
214
|
-
|
|
327
|
+
/** A response replaced the record (a site change, a refresh): keep the person's version selected and its labels —
|
|
328
|
+
* paging it in again if it fell outside the new window — or, when it is no longer kept, say so and show the latest. */
|
|
329
|
+
async function adoptRecord(page) {
|
|
330
|
+
view.page = page;
|
|
331
|
+
view.known = [...page.versions];
|
|
332
|
+
const latest = view.known[view.known.length - 1].n;
|
|
333
|
+
if (view.n === latest) return true;
|
|
334
|
+
const wanted = view.n;
|
|
335
|
+
const seq = view.openSeq;
|
|
336
|
+
let found;
|
|
337
|
+
try { found = await ensureKnown(wanted); }
|
|
338
|
+
catch (err) { found = err; }
|
|
339
|
+
if (seq !== view.openSeq) return false; // the viewer was opened again meanwhile: that open owns it now
|
|
340
|
+
if (found === 'known' || found === 'moved') return found === 'known';
|
|
341
|
+
view.note = found === 'gone' ? goneNote(wanted) : failedNote(wanted, found);
|
|
342
|
+
view.n = latest;
|
|
343
|
+
paintBanner();
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** "3 files · 41.2 MB" for a version that carries files beside its HTML (slice 5); nothing otherwise. */
|
|
348
|
+
function filesText(v) {
|
|
349
|
+
const files = Array.isArray(v?.assets) ? v.assets : [];
|
|
350
|
+
if (!files.length) return '';
|
|
351
|
+
const bytes = files.reduce((sum, f) => sum + (f.bytes || 0), 0) + (v.bytes || 0);
|
|
352
|
+
const size = bytes >= 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`;
|
|
353
|
+
return `${files.length === 1 ? '1 file' : `${files.length} files`} · ${size}`;
|
|
354
|
+
}
|
|
215
355
|
|
|
216
356
|
function paintHeader() {
|
|
217
357
|
const p = view.page;
|
|
218
358
|
const v = currentVersion();
|
|
219
|
-
const
|
|
220
|
-
const
|
|
221
|
-
const
|
|
359
|
+
const latest = view.known[view.known.length - 1].n;
|
|
360
|
+
const index = v ? position(v) : totalVersions();
|
|
361
|
+
const total = totalVersions();
|
|
222
362
|
$title.textContent = p.title;
|
|
223
363
|
$ai.hidden = !v?.aiMade;
|
|
224
364
|
$ai.setAttribute('data-tip', AI_TIP);
|
|
225
|
-
|
|
226
|
-
$
|
|
227
|
-
$
|
|
365
|
+
const seq = v?.sequence;
|
|
366
|
+
$seq.hidden = !seq;
|
|
367
|
+
$seqText.hidden = !seq;
|
|
368
|
+
if (seq) {
|
|
369
|
+
const sentence = sequenceSentence(seq, p.source);
|
|
370
|
+
$seq.textContent = seqLabel(seq);
|
|
371
|
+
$seq.classList.toggle('is-warn', seq.order !== 'read' || !!seq.partial);
|
|
372
|
+
$seq.setAttribute('data-tip', sentence);
|
|
373
|
+
$seq.setAttribute('aria-label', `${$seq.textContent}.`);
|
|
374
|
+
$seqText.textContent = sentence;
|
|
375
|
+
} else {
|
|
376
|
+
$seq.removeAttribute('data-tip');
|
|
377
|
+
$seqText.textContent = '';
|
|
378
|
+
}
|
|
379
|
+
$sub.textContent = [sourceText(p.source), v ? `Saved ${when(v.createdAt)}` : '', v?.capture ? CAPTURE_TEXT[v.capture] : '', contentText(v), filesText(v)].filter(Boolean).join(' · ');
|
|
380
|
+
// The full report is opened by FloLess, outside the frame, and only for a version that is a complete report.
|
|
381
|
+
if ($fullReport) {
|
|
382
|
+
$fullReport.hidden = !(p.source?.kind === 'workflow' && v?.content?.kind === 'complete-report');
|
|
383
|
+
$fullReport.setAttribute('data-tip', v?.content?.kind === 'complete-report' && !v.content.whole
|
|
384
|
+
? 'This version is only a summary. Open the whole report FloLess keeps on this computer, in its report viewer'
|
|
385
|
+
: 'Open the whole report FloLess keeps on this computer, in its report viewer');
|
|
386
|
+
}
|
|
387
|
+
$version.textContent = `Version ${index} of ${total}${view.n === latest ? ' · latest' : ''}`;
|
|
388
|
+
$version.setAttribute('aria-label', `Version ${index} of ${total}. Choose another version`);
|
|
228
389
|
const allowed = p.allowedOrigins.length;
|
|
229
390
|
$allowed.hidden = allowed === 0;
|
|
230
391
|
$allowed.textContent = allowed === 1 ? '1 site allowed' : `${allowed} sites allowed`;
|
|
@@ -232,12 +393,20 @@
|
|
|
232
393
|
$frame.setAttribute('title', `Page: ${p.title}, version ${index}`);
|
|
233
394
|
}
|
|
234
395
|
|
|
235
|
-
function loadFrame() {
|
|
396
|
+
async function loadFrame() {
|
|
236
397
|
clearTimeout(view.loadTimer);
|
|
237
398
|
$stage.classList.add('is-loading');
|
|
238
399
|
$loading.hidden = false;
|
|
239
400
|
$loading.textContent = 'Opening Page…';
|
|
240
401
|
view.loadTimer = setTimeout(() => { $loading.textContent = 'Still opening this Page… Large Pages can take a moment.'; }, 8000);
|
|
402
|
+
// Only a version with files needs its key (the plain address shows a version without files exactly the same), and
|
|
403
|
+
// only when no answer so far carried it.
|
|
404
|
+
if (currentVersion()?.assets?.length && !view.frameKeys[view.n]) {
|
|
405
|
+
const want = { seq: view.openSeq, id: view.page?.id, n: view.n };
|
|
406
|
+
await ensureFrameKey(want.n);
|
|
407
|
+
// Another open or version choice took over while the key was fetched: that one loads its own frame.
|
|
408
|
+
if (want.seq !== view.openSeq || want.id !== view.page?.id || want.n !== view.n || !isOpen()) return;
|
|
409
|
+
}
|
|
241
410
|
$frame.src = contentUrl();
|
|
242
411
|
}
|
|
243
412
|
$frame.addEventListener('load', () => {
|
|
@@ -248,34 +417,59 @@
|
|
|
248
417
|
});
|
|
249
418
|
|
|
250
419
|
async function openViewer(home, id, n, returnFocus) {
|
|
420
|
+
const seq = ++view.openSeq;
|
|
251
421
|
let body;
|
|
252
422
|
try {
|
|
253
423
|
body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}`);
|
|
424
|
+
if (seq !== view.openSeq) return false; // a newer open (even of this same Page) owns the viewer now
|
|
254
425
|
} catch (err) {
|
|
426
|
+
if (seq !== view.openSeq) return false;
|
|
255
427
|
if (['page-damaged', 'page-not-found'].includes(err?.body?.code) && typeof window.flolessWorkspaces?.openPagesHome === 'function') {
|
|
256
428
|
if (await window.flolessWorkspaces.openPagesHome(home, id, closeViewer)) return true;
|
|
257
429
|
}
|
|
258
430
|
toast(`FloLess couldn’t open this Page. ${err?.body?.error || 'Try again in a moment.'}`, 'warn');
|
|
259
431
|
return false;
|
|
260
432
|
}
|
|
433
|
+
// Another Page: a share action still out for the previous one no longer owns the Share button.
|
|
434
|
+
if (view.page?.id !== body.page?.id || view.home !== (body.home || home)) {
|
|
435
|
+
view.actionSeq += 1;
|
|
436
|
+
$share.removeAttribute('aria-busy');
|
|
437
|
+
view.stopWatch?.(); // its progress poll too, so this Page can start its own
|
|
438
|
+
}
|
|
261
439
|
view.home = body.home || home;
|
|
262
440
|
view.page = body.page;
|
|
263
|
-
|
|
264
|
-
view.
|
|
441
|
+
view.frameKeys = { ...(body.frameKeys || {}) };
|
|
442
|
+
view.known = [...view.page.versions];
|
|
443
|
+
const newest = view.known[view.known.length - 1].n;
|
|
444
|
+
// A version older than the window (a link to version 3 of 900) is paged in first; one that can't be is said.
|
|
445
|
+
let note = null;
|
|
446
|
+
view.n = newest;
|
|
447
|
+
if (n && n !== newest) {
|
|
448
|
+
let found;
|
|
449
|
+
try { found = await ensureKnown(n); }
|
|
450
|
+
catch (err) { found = err; }
|
|
451
|
+
if (found === 'moved' || seq !== view.openSeq) return false;
|
|
452
|
+
if (found === 'known') view.n = n;
|
|
453
|
+
else note = found === 'gone' ? goneNote(n) : failedNote(n, found);
|
|
454
|
+
}
|
|
265
455
|
view.returnFocus = returnFocus instanceof HTMLElement ? returnFocus : document.activeElement;
|
|
266
456
|
view.linkAsk = null;
|
|
267
457
|
view.blocked.clear();
|
|
268
458
|
view.kept.clear();
|
|
269
|
-
view.note =
|
|
459
|
+
view.note = note;
|
|
270
460
|
view.limitHit = false;
|
|
271
461
|
view.reviewOpen = false;
|
|
462
|
+
view.share = { share: view.page.share ?? null, eligibility: null, error: null };
|
|
463
|
+
view.shareBannerDismissed = false;
|
|
272
464
|
closePopovers();
|
|
273
465
|
paintHeader();
|
|
466
|
+
paintShareButton();
|
|
274
467
|
paintBanner();
|
|
275
468
|
setFullscreen(false);
|
|
276
469
|
$modal.classList.add('show');
|
|
277
470
|
loadFrame();
|
|
278
471
|
$close.focus();
|
|
472
|
+
void loadShare();
|
|
279
473
|
return true;
|
|
280
474
|
}
|
|
281
475
|
|
|
@@ -284,6 +478,7 @@
|
|
|
284
478
|
closePopovers();
|
|
285
479
|
$modal.classList.remove('show');
|
|
286
480
|
clearTimeout(view.loadTimer);
|
|
481
|
+
view.stopWatch?.();
|
|
287
482
|
$frame.src = 'about:blank';
|
|
288
483
|
view.linkAsk = null;
|
|
289
484
|
view.blocked.clear();
|
|
@@ -293,11 +488,28 @@
|
|
|
293
488
|
if (back?.isConnected) back.focus();
|
|
294
489
|
}
|
|
295
490
|
|
|
491
|
+
/** Re-read the open Page's record (its labels changed on the server). An answer that arrives after the person
|
|
492
|
+
* closed it or opened another — even this same Page again — is dropped; one that moved the shown version moves the
|
|
493
|
+
* frame with it, so header and content never disagree. */
|
|
296
494
|
async function reloadRecord() {
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
495
|
+
const seq = view.openSeq;
|
|
496
|
+
const home = view.home;
|
|
497
|
+
const id = view.page?.id;
|
|
498
|
+
const stale = () => seq !== view.openSeq || !isOpen() || view.home !== home || view.page?.id !== id;
|
|
499
|
+
let body;
|
|
500
|
+
try { body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}`); }
|
|
501
|
+
catch {
|
|
502
|
+
if (stale()) return;
|
|
503
|
+
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.';
|
|
504
|
+
paintBanner();
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (stale()) return;
|
|
508
|
+
const shown = view.n;
|
|
509
|
+
await adoptRecord(body.page);
|
|
510
|
+
if (stale()) return;
|
|
300
511
|
paintHeader();
|
|
512
|
+
if (view.n !== shown) loadFrame();
|
|
301
513
|
}
|
|
302
514
|
|
|
303
515
|
// ── Version picker ──
|
|
@@ -307,23 +519,37 @@
|
|
|
307
519
|
$version.setAttribute('aria-expanded', 'false');
|
|
308
520
|
$sitesPop.hidden = true;
|
|
309
521
|
$sites.setAttribute('aria-expanded', 'false');
|
|
522
|
+
if (typeof closeSharePop === 'function') closeSharePop();
|
|
310
523
|
}
|
|
311
524
|
|
|
312
|
-
function openVersionPicker() {
|
|
313
|
-
const versions = [...view.
|
|
525
|
+
function openVersionPicker(focusN) {
|
|
526
|
+
const versions = [...view.known].reverse();
|
|
314
527
|
const latest = versions[0].n;
|
|
315
|
-
const total =
|
|
316
|
-
|
|
317
|
-
|
|
528
|
+
const total = totalVersions();
|
|
529
|
+
const older = total - view.known.length;
|
|
530
|
+
const next = Math.min(200, older);
|
|
531
|
+
const options = versions.map((v) => {
|
|
532
|
+
const label = `Version ${position(v)}${v.n === latest ? ' · latest' : ''}`;
|
|
533
|
+
const meta = [when(v.createdAt), v.aiMade ? 'AI-made' : '', v.capture ? CAPTURE_TEXT[v.capture] : '', v.sequence ? seqLabel(v.sequence) : ''].filter(Boolean).join(' · ');
|
|
318
534
|
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}">
|
|
535
|
+
aria-posinset="${position(v)}" aria-setsize="${total}" data-command-id="shell.page-version-choose#${esc(label)}" data-n="${v.n}">
|
|
320
536
|
<span class="pv-option-main">${esc(label)}</span>
|
|
321
|
-
<span class="pv-option-meta">${esc(
|
|
537
|
+
<span class="pv-option-meta">${esc(meta)}</span>
|
|
322
538
|
</button>`;
|
|
323
539
|
}).join('');
|
|
540
|
+
// The "older" control is a plain button BELOW the listbox (a listbox may hold only options), kept in view.
|
|
541
|
+
const footer = older > 0
|
|
542
|
+
? `<div class="pv-version-footer"><button type="button" class="wf-option pv-version-older" data-command-id="shell.page-versions-older" data-older="1">
|
|
543
|
+
<span class="pv-option-main">${older > 200 ? `Show ${next} older versions` : `Show the last ${older} version${older === 1 ? '' : 's'}`}</span>
|
|
544
|
+
<span class="pv-option-meta">${older} more not shown</span></button></div>`
|
|
545
|
+
: '';
|
|
546
|
+
$versionPop.innerHTML = `<div role="listbox" id="pv-version-list" aria-label="Versions of this Page">${options}</div>${footer}
|
|
547
|
+
<span class="pv-version-announce" role="status" aria-live="polite">${esc(view.announce || '')}</span>`;
|
|
548
|
+
view.announce = '';
|
|
324
549
|
$versionPop.hidden = false;
|
|
325
550
|
$version.setAttribute('aria-expanded', 'true');
|
|
326
|
-
|
|
551
|
+
const focus = focusN ? $versionPop.querySelector(`button[data-n="${focusN}"]`) : null;
|
|
552
|
+
(focus || $versionPop.querySelector('.selected') || $versionPop.querySelector('button'))?.focus();
|
|
327
553
|
}
|
|
328
554
|
|
|
329
555
|
$version.addEventListener('click', () => {
|
|
@@ -331,7 +557,35 @@
|
|
|
331
557
|
closePopovers();
|
|
332
558
|
openVersionPicker();
|
|
333
559
|
});
|
|
334
|
-
$versionPop.addEventListener('click', (event) => {
|
|
560
|
+
$versionPop.addEventListener('click', async (event) => {
|
|
561
|
+
const olderButton = event.target.closest('button[data-older]');
|
|
562
|
+
if (olderButton) {
|
|
563
|
+
// Page in the next older two hundred and keep the list open, focus on the first newly shown version. A click
|
|
564
|
+
// while that is still loading is the same request, so it waits rather than asking twice.
|
|
565
|
+
if (view.pagingOlder) return;
|
|
566
|
+
view.pagingOlder = true;
|
|
567
|
+
olderButton.setAttribute('aria-busy', 'true');
|
|
568
|
+
olderButton.querySelector('.pv-option-main').textContent = 'Loading older versions…';
|
|
569
|
+
const before = view.known[0].n;
|
|
570
|
+
let found;
|
|
571
|
+
try { found = await ensureKnown(Math.max(1, before - 200)); }
|
|
572
|
+
catch (err) {
|
|
573
|
+
toast(`FloLess couldn’t show older versions. ${err?.body?.error || 'Try again in a moment.'}`, 'warn');
|
|
574
|
+
if (!$versionPop.hidden) openVersionPicker();
|
|
575
|
+
return;
|
|
576
|
+
} finally { view.pagingOlder = false; }
|
|
577
|
+
if (found === 'moved' || $versionPop.hidden) return; // another Page, or closed: the list opens fresh next time
|
|
578
|
+
const below = view.known.filter((v) => v.n < before);
|
|
579
|
+
if (!below.length) {
|
|
580
|
+
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');
|
|
581
|
+
openVersionPicker();
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
const remaining = totalVersions() - view.known.length;
|
|
585
|
+
view.announce = `${below.length} more version${below.length === 1 ? '' : 's'} shown.${remaining ? ` ${remaining} older remain.` : ''}`;
|
|
586
|
+
openVersionPicker(below.length ? below[below.length - 1].n : null);
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
335
589
|
const option = event.target.closest('button[data-n]');
|
|
336
590
|
if (!option) return;
|
|
337
591
|
const n = Number(option.dataset.n);
|
|
@@ -348,7 +602,7 @@
|
|
|
348
602
|
loadFrame();
|
|
349
603
|
});
|
|
350
604
|
$versionPop.addEventListener('keydown', (event) => {
|
|
351
|
-
const options = [...$versionPop.querySelectorAll('
|
|
605
|
+
const options = [...$versionPop.querySelectorAll('[role="option"]')];
|
|
352
606
|
const i = options.indexOf(document.activeElement);
|
|
353
607
|
if (event.key === 'ArrowDown') { event.preventDefault(); options[Math.min(options.length - 1, i + 1)]?.focus(); }
|
|
354
608
|
if (event.key === 'ArrowUp') { event.preventDefault(); options[Math.max(0, i - 1)]?.focus(); }
|
|
@@ -386,7 +640,7 @@
|
|
|
386
640
|
const body = await api(`/api/pages/${encodeURIComponent(view.home)}/${encodeURIComponent(view.page.id)}/allowed-origins`, {
|
|
387
641
|
method: 'PUT', body: JSON.stringify({ origin, allow }),
|
|
388
642
|
});
|
|
389
|
-
|
|
643
|
+
await adoptRecord(body.page);
|
|
390
644
|
paintHeader();
|
|
391
645
|
loadFrame();
|
|
392
646
|
return true;
|
|
@@ -420,6 +674,7 @@
|
|
|
420
674
|
$banner.hidden = false;
|
|
421
675
|
return;
|
|
422
676
|
}
|
|
677
|
+
if (!hosts.length && typeof paintShareBanner === 'function' && paintShareBanner()) return;
|
|
423
678
|
if (!hosts.length) { $banner.hidden = true; $banner.innerHTML = ''; delete $banner.dataset.kind; return; }
|
|
424
679
|
$banner.dataset.kind = 'blocked';
|
|
425
680
|
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 +821,575 @@
|
|
|
566
821
|
const p = view.page;
|
|
567
822
|
const ok = await bridge.formModal?.({
|
|
568
823
|
title: 'Delete this Page?',
|
|
569
|
-
sub: `“${p.title}” and all ${versionsText(p.versions.length)} will be removed. This can’t be undone
|
|
824
|
+
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
825
|
fields: [], okLabel: 'Delete Page', danger: true, returnFocusTo: $delete,
|
|
571
826
|
});
|
|
572
827
|
if (!ok) return;
|
|
828
|
+
let revokePending = false;
|
|
573
829
|
try {
|
|
574
|
-
await api(`/api/pages/${encodeURIComponent(view.home)}/${encodeURIComponent(p.id)}`, { method: 'DELETE' });
|
|
830
|
+
const body = await api(`/api/pages/${encodeURIComponent(view.home)}/${encodeURIComponent(p.id)}`, { method: 'DELETE' });
|
|
831
|
+
revokePending = body?.revokePending === true;
|
|
575
832
|
} catch (err) {
|
|
576
833
|
toast(`FloLess couldn’t delete this Page. ${err?.body?.error || 'Try again in a moment.'}`, 'warn');
|
|
577
834
|
return;
|
|
578
835
|
}
|
|
579
836
|
announceDeleted(view.home, p.id);
|
|
580
837
|
closeViewer();
|
|
581
|
-
toast(
|
|
838
|
+
toast(revokePending
|
|
839
|
+
? `Deleted “${p.title}”. Its link will be revoked as soon as FloLess can reach floless.io; you can see it in My shared links.`
|
|
840
|
+
: `Deleted “${p.title}”.`, revokePending ? 'warn' : 'ok');
|
|
582
841
|
refreshLists();
|
|
583
842
|
});
|
|
584
843
|
|
|
844
|
+
// ── Share link (#2262 slice 4) ──
|
|
845
|
+
// One button in the header says where the link stands; its popover holds the link and the everyday actions. Anything
|
|
846
|
+
// that needs a decision (a newer version not published, a link updated elsewhere, a failure) is said in the banner,
|
|
847
|
+
// so the popover is never the only place a choice lives.
|
|
848
|
+
|
|
849
|
+
const $share = $('pv-share');
|
|
850
|
+
const $shareLabel = $('pv-share-label');
|
|
851
|
+
const $sharePop = $('pv-share-pop');
|
|
852
|
+
const PLANS_URL = 'https://floless.io/pricing';
|
|
853
|
+
|
|
854
|
+
function verLabel(n) {
|
|
855
|
+
const v = view.known.find((x) => x.n === n);
|
|
856
|
+
return v ? `version ${position(v)}` : `version ${n}`;
|
|
857
|
+
}
|
|
858
|
+
function latestN() { return view.known[view.known.length - 1]?.n ?? null; }
|
|
859
|
+
|
|
860
|
+
/** The words for where the link stands: the button label, its tip, and the popover's first line. */
|
|
861
|
+
function shareWords() {
|
|
862
|
+
const s = view.share?.share;
|
|
863
|
+
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.' };
|
|
864
|
+
if (s.state === 'pending-publish') {
|
|
865
|
+
const waiting = s.lastError ? ' FloLess will keep trying by itself.' : '';
|
|
866
|
+
return { label: 'Sharing…', dot: 'wait', status: `Publishing ${verLabel(s.pending?.pageVersion)}…${waiting}` };
|
|
867
|
+
}
|
|
868
|
+
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.' };
|
|
869
|
+
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.' };
|
|
870
|
+
const published = s.publishedPageVersion;
|
|
871
|
+
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}.` };
|
|
872
|
+
if (published !== null && latestN() !== null && published < latestN()) {
|
|
873
|
+
return { label: 'Shared · update', dot: 'warn', status: `The link shows ${verLabel(published)}. A newer version isn’t published yet.` };
|
|
874
|
+
}
|
|
875
|
+
return { label: 'Shared', dot: 'live', status: `The link is live and shows ${verLabel(published)}.` };
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
function paintShareButton() {
|
|
879
|
+
const w = shareWords();
|
|
880
|
+
$shareLabel.textContent = w.label;
|
|
881
|
+
$share.dataset.state = w.dot || 'none';
|
|
882
|
+
// No tooltip: it would sit over the open menu and the banner below. The menu and the accessible name say it all.
|
|
883
|
+
$share.removeAttribute('data-tip');
|
|
884
|
+
$share.setAttribute('aria-label', `Share link: ${w.label}. ${w.status}`);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
function paintSharePop() {
|
|
889
|
+
const s = view.share?.share;
|
|
890
|
+
const w = shareWords();
|
|
891
|
+
const parts = [`<div class="pv-pop-head">Share link</div><p class="pv-pop-note pv-share-status">${esc(w.status)}</p>`];
|
|
892
|
+
if (s?.url && s.state !== 'revoked') {
|
|
893
|
+
parts.push(`<div class="pv-share-link"><input class="pv-share-url" type="text" readonly value="${esc(s.url)}" aria-label="The share link"
|
|
894
|
+
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>`);
|
|
895
|
+
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>`);
|
|
896
|
+
}
|
|
897
|
+
const shown = view.n;
|
|
898
|
+
// floless.io can't draw the order label yet, so a version whose order FloLess did not read carries it in the title.
|
|
899
|
+
const shownVersion = view.known.find((x) => x.n === shown);
|
|
900
|
+
const shownSeq = shownVersion?.sequence;
|
|
901
|
+
// #2262 slice 3c: a whole complete report says what leaves the computer before it is shared.
|
|
902
|
+
if (shownVersion?.content?.kind === 'complete-report') {
|
|
903
|
+
parts.push(shownVersion.content.whole
|
|
904
|
+
? '<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>'
|
|
905
|
+
: '<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>');
|
|
906
|
+
}
|
|
907
|
+
if (shownSeq && (shownSeq.order !== 'read' || shownSeq.partial)) {
|
|
908
|
+
const suffix = shownSeq.order === 'read' ? 'order partly read' : shownSeq.order === 'assumed' ? 'order assumed' : shownSeq.order === 'unverified' ? 'order not checked' : 'order unreadable';
|
|
909
|
+
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>`);
|
|
910
|
+
}
|
|
911
|
+
if (!s || s.state === 'revoked') {
|
|
912
|
+
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>`);
|
|
913
|
+
if (s) parts.push('<p class="pv-pop-note">This makes a new link. The old one stays revoked.</p>');
|
|
914
|
+
else if (view.share?.eligibility && !view.share.eligibility.ok && shown === latestN()) parts.push(`<p class="pv-pop-note">${esc(view.share.eligibility.reason)}</p>`);
|
|
915
|
+
} else if (s.state === 'pending-publish') {
|
|
916
|
+
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>`);
|
|
917
|
+
} else if (s.state === 'live' && shown !== s.publishedPageVersion) {
|
|
918
|
+
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>`);
|
|
919
|
+
}
|
|
920
|
+
if (s && (s.state === 'live' || s.state === 'pending-publish')) {
|
|
921
|
+
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>`);
|
|
922
|
+
}
|
|
923
|
+
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>`);
|
|
924
|
+
$sharePop.innerHTML = parts.join('');
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/** The banner for the link, when nothing the Page itself asked about is waiting. Returns false when there is none. */
|
|
928
|
+
function paintShareBanner() {
|
|
929
|
+
const st = view.share;
|
|
930
|
+
if (!st || view.shareBannerDismissed) return false;
|
|
931
|
+
const s = st.share;
|
|
932
|
+
let text = '';
|
|
933
|
+
let actions = '';
|
|
934
|
+
let kind = 'share';
|
|
935
|
+
// Only while the link is really being published: a cancelled or settled publish shows no upload.
|
|
936
|
+
const up = s?.state === 'pending-publish' ? view.shareProgress : null;
|
|
937
|
+
if (up && !st.error) {
|
|
938
|
+
// Drawn once; each later tick changes only this text (watchPublish), so Cancel keeps focus and a screen reader
|
|
939
|
+
// hears the banner arrive, not a count every second.
|
|
940
|
+
$banner.dataset.kind = 'share-progress';
|
|
941
|
+
$banner.innerHTML = `<p class="pv-banner-text" data-share-progress aria-live="off">${esc(progressText(up))}</p><div class="pv-banner-actions">`
|
|
942
|
+
+ `<button type="button" class="ghost" data-command-id="shell.page-share-cancel" data-share-act="cancel">${esc('Cancel publishing')}</button></div>`;
|
|
943
|
+
$banner.hidden = false;
|
|
944
|
+
return true;
|
|
945
|
+
} else if (st.error) {
|
|
946
|
+
kind = 'blocked';
|
|
947
|
+
text = esc(st.error.message);
|
|
948
|
+
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>`;
|
|
949
|
+
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>`;
|
|
950
|
+
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>`;
|
|
951
|
+
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>`;
|
|
952
|
+
actions += `<button type="button" class="ghost" data-command-id="shell.page-note-dismiss" data-share-act="dismiss">${esc('OK')}</button>`;
|
|
953
|
+
} else if (s?.state === 'pending-publish' && s.lastError) {
|
|
954
|
+
kind = 'blocked';
|
|
955
|
+
text = s.lastError.code === 'signed_out'
|
|
956
|
+
? 'FloLess is waiting to publish this link because you’re signed out. Sign in to FloLess and it will carry on by itself.'
|
|
957
|
+
: 'FloLess couldn’t reach floless.io to publish this link. It will try again by itself, or you can try now.';
|
|
958
|
+
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>`;
|
|
959
|
+
} else if (s?.state === 'pending-revoke') {
|
|
960
|
+
text = 'This link will be revoked as soon as FloLess can reach floless.io. Until then it still opens.';
|
|
961
|
+
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>`;
|
|
962
|
+
} else if (s?.state === 'live' && s.conflict) {
|
|
963
|
+
kind = 'blocked';
|
|
964
|
+
const theirs = s.conflict.remoteVersion;
|
|
965
|
+
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?`;
|
|
966
|
+
// "Mine" is the version that publish tried to put on the link, not whatever is latest now (older records: the latest).
|
|
967
|
+
const mine = s.conflict.pageVersion ?? latestN();
|
|
968
|
+
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>`
|
|
969
|
+
+ `<button type="button" class="ghost" data-command-id="shell.page-share-keep" data-share-act="keep-theirs">${esc(`Keep v${theirs}`)}</button>`;
|
|
970
|
+
} else if (s?.state === 'live' && s.publishedPageVersion !== null && latestN() !== null && s.publishedPageVersion < latestN()) {
|
|
971
|
+
text = `Shared: the link shows ${esc(verLabel(s.publishedPageVersion))}. A newer version isn’t published yet.`;
|
|
972
|
+
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>`
|
|
973
|
+
+ `<button type="button" class="ghost" data-command-id="shell.page-note-dismiss" data-share-act="dismiss">${esc('Not now')}</button>`;
|
|
974
|
+
} else if (s?.note) {
|
|
975
|
+
text = esc(s.note);
|
|
976
|
+
actions = `<button type="button" class="ghost" data-command-id="shell.page-note-dismiss" data-share-act="dismiss">${esc('OK')}</button>`;
|
|
977
|
+
} else return false;
|
|
978
|
+
$banner.dataset.kind = kind;
|
|
979
|
+
$banner.innerHTML = `<p class="pv-banner-text">${text}</p><div class="pv-banner-actions">${actions}</div>`;
|
|
980
|
+
$banner.hidden = false;
|
|
981
|
+
return true;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
async function loadShare() {
|
|
985
|
+
const seq = view.openSeq;
|
|
986
|
+
// A share action that answers first is newer than this read: its answer is never overwritten by this one.
|
|
987
|
+
const shareSeq = ++view.shareSeq;
|
|
988
|
+
const home = view.home;
|
|
989
|
+
const id = view.page?.id;
|
|
990
|
+
try {
|
|
991
|
+
const body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}/share`);
|
|
992
|
+
if (seq !== view.openSeq || shareSeq !== view.shareSeq) return;
|
|
993
|
+
view.share = { share: body.share, eligibility: body.eligibility, error: null };
|
|
994
|
+
view.shareProgress = body.progress || null;
|
|
995
|
+
// A publish FloLess resumed by itself (after a restart, or the hourly catch-up) is still running: follow it until
|
|
996
|
+
// it settles, so the Page shows its upload and then its live link without being reopened.
|
|
997
|
+
if (body.share?.state === 'pending-publish' && !view.stopWatch) watchPublish({ untilSettled: true });
|
|
998
|
+
} catch (err) {
|
|
999
|
+
if (seq !== view.openSeq || shareSeq !== view.shareSeq) return;
|
|
1000
|
+
// Said, not swallowed: the Page's own record still shows its link, and the banner says why the rest is missing.
|
|
1001
|
+
view.share = { share: view.page?.share ?? null, eligibility: null,
|
|
1002
|
+
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 } };
|
|
1003
|
+
}
|
|
1004
|
+
paintShareButton();
|
|
1005
|
+
// Painted while closed too: the Instructor reaches Revoke, Copy and the rest by opening this menu (data-reveal-by).
|
|
1006
|
+
paintSharePop();
|
|
1007
|
+
paintBanner();
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
/** "Uploading this version's files to floless.io: 3 of 12 files (18.0 of 41.2 MB)…" — the share's upload, in words. */
|
|
1011
|
+
function progressText(up) {
|
|
1012
|
+
const mb = (b) => (b / 1024 / 1024).toFixed(1);
|
|
1013
|
+
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.`;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/** The words for a failure the server answered with, in the person's terms. */
|
|
1017
|
+
function outcomeSentence(code) {
|
|
1018
|
+
return ({
|
|
1019
|
+
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.',
|
|
1020
|
+
no_subscription: 'Sharing a link needs a FloLess plan, so this Page wasn’t shared. Your Page is unchanged.',
|
|
1021
|
+
too_large: 'floless.io said this version is too large to share. Make a smaller version and share that.',
|
|
1022
|
+
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.',
|
|
1023
|
+
offline: 'FloLess couldn’t reach floless.io. It will try again by itself, or you can try now.',
|
|
1024
|
+
in_progress: 'floless.io is still finishing this link. FloLess will check again by itself.',
|
|
1025
|
+
cancelled: 'Publishing was cancelled. The link is as it was.',
|
|
1026
|
+
reused: 'FloLess couldn’t publish this attempt. Share the Page again.',
|
|
1027
|
+
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.',
|
|
1028
|
+
revoked: 'This link was revoked from somewhere else, so it can’t show new versions. Share the Page again to make a new link.',
|
|
1029
|
+
not_found: 'floless.io no longer has this link. Share the Page again to make a new link.',
|
|
1030
|
+
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.',
|
|
1031
|
+
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.',
|
|
1032
|
+
})[code] || '';
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* Two rules keep the share display true (slice 5, rebuilt after review):
|
|
1037
|
+
* - Actions (share, publish, cancel, revoke, retry) are numbered; only the NEWEST action's answer is applied. An
|
|
1038
|
+
* answer that lost to a newer action is dropped and asks the server for where things stand, so the display never
|
|
1039
|
+
* stays on what an older action left (a publish superseded by a Cancel, or by the Page being opened again).
|
|
1040
|
+
* - Status reads (opening, the progress poll) are applied only when no action started or answered since they began.
|
|
1041
|
+
* A share answer changes only the Page's share record (versions, title and sites are not touched by sharing), so
|
|
1042
|
+
* applying it never waits.
|
|
1043
|
+
*/
|
|
1044
|
+
async function shareCall(path, method, payload) {
|
|
1045
|
+
const home = view.home;
|
|
1046
|
+
const id = view.page.id;
|
|
1047
|
+
view.shareBannerDismissed = false;
|
|
1048
|
+
const ticket = ++view.actionSeq;
|
|
1049
|
+
view.shareSeq += 1; // a status read already out is older than this action
|
|
1050
|
+
const current = () => view.page?.id === id && view.home === home && ticket === view.actionSeq;
|
|
1051
|
+
const adoptShare = (page) => { if (page) view.page = { ...view.page, share: page.share ?? null }; };
|
|
1052
|
+
$share.setAttribute('aria-busy', 'true');
|
|
1053
|
+
try {
|
|
1054
|
+
const body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}/share${path}`, {
|
|
1055
|
+
method, ...(payload ? { body: JSON.stringify(payload) } : {}),
|
|
1056
|
+
});
|
|
1057
|
+
if (!current()) { if (view.page?.id === id && isOpen()) void loadShare(); return null; }
|
|
1058
|
+
view.shareSeq += 1;
|
|
1059
|
+
adoptShare(body.page);
|
|
1060
|
+
view.share = { ...(view.share || {}), share: body.share, error: null };
|
|
1061
|
+
return body.outcome;
|
|
1062
|
+
} catch (err) {
|
|
1063
|
+
if (!current()) { if (view.page?.id === id && isOpen()) void loadShare(); return null; }
|
|
1064
|
+
view.shareSeq += 1;
|
|
1065
|
+
const answer = err?.body;
|
|
1066
|
+
if (answer?.outcome && answer.page) {
|
|
1067
|
+
// An answer, not a failure: the share published nothing and says why (needs a plan, too large, …), with the Page's record.
|
|
1068
|
+
adoptShare(answer.page);
|
|
1069
|
+
view.share = { ...(view.share || {}), share: answer.share,
|
|
1070
|
+
error: answer.outcome === 'share-too-large' ? { code: 'share-too-large', message: answer.reason, path: answer.path || null } : null };
|
|
1071
|
+
return answer.outcome;
|
|
1072
|
+
}
|
|
1073
|
+
const code = err?.body?.code || 'offline';
|
|
1074
|
+
const path = code === 'share-too-large' && (payload?.version ?? latestN()) === latestN() ? view.share?.eligibility?.path || null : null;
|
|
1075
|
+
view.share = { ...(view.share || {}), error: { code, message: err?.body?.error || outcomeSentence('offline'), path } };
|
|
1076
|
+
return null;
|
|
1077
|
+
} finally {
|
|
1078
|
+
// Only the newest action owns the busy mark (even after the viewer moved to another Page, so nothing is left busy),
|
|
1079
|
+
// and only the newest action on the Page still open repaints.
|
|
1080
|
+
if (ticket === view.actionSeq) $share.removeAttribute('aria-busy');
|
|
1081
|
+
if (current()) {
|
|
1082
|
+
paintHeader();
|
|
1083
|
+
paintShareButton();
|
|
1084
|
+
paintSharePop();
|
|
1085
|
+
paintBanner();
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* While a publish runs, read its progress every second (slice 5): a version with files uploads them first, which can
|
|
1092
|
+
* take minutes, and the record turns "publishing" on the server at once — so Cancel is reachable and the banner counts
|
|
1093
|
+
* up. Returns the function that stops it; nothing it read after that is used.
|
|
1094
|
+
*/
|
|
1095
|
+
function watchPublish({ untilSettled = false } = {}) {
|
|
1096
|
+
const home = view.home;
|
|
1097
|
+
const id = view.page?.id;
|
|
1098
|
+
let live = true;
|
|
1099
|
+
let busy = false;
|
|
1100
|
+
let timer = null;
|
|
1101
|
+
view.stopWatch?.();
|
|
1102
|
+
const stop = () => {
|
|
1103
|
+
live = false;
|
|
1104
|
+
clearTimeout(timer);
|
|
1105
|
+
if (view.stopWatch === stop) { view.stopWatch = null; view.shareProgress = null; }
|
|
1106
|
+
};
|
|
1107
|
+
const tick = async () => {
|
|
1108
|
+
if (!live || busy) return;
|
|
1109
|
+
if (!isOpen() || view.home !== home || view.page?.id !== id) { stop(); return; }
|
|
1110
|
+
busy = true;
|
|
1111
|
+
// Any action that started or answered while this read was out (a Cancel, the publish's own answer) makes it old.
|
|
1112
|
+
const seq = view.shareSeq;
|
|
1113
|
+
try {
|
|
1114
|
+
const body = await api(`/api/pages/${encodeURIComponent(home)}/${encodeURIComponent(id)}/share`);
|
|
1115
|
+
if (!live || seq !== view.shareSeq || view.home !== home || view.page?.id !== id) return;
|
|
1116
|
+
const changed = JSON.stringify(body.share?.state) !== JSON.stringify(view.share?.share?.state) || !!body.progress !== !!view.shareProgress;
|
|
1117
|
+
view.share = { ...(view.share || {}), share: body.share };
|
|
1118
|
+
view.shareProgress = body.progress || null;
|
|
1119
|
+
if (untilSettled && body.share?.state !== 'pending-publish') {
|
|
1120
|
+
// Settled by the run FloLess resumed: show where the link stands now, and stop asking.
|
|
1121
|
+
stop();
|
|
1122
|
+
paintShareButton(); paintSharePop(); paintBanner();
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
const line = $banner.dataset.kind === 'share-progress' && view.shareProgress ? $banner.querySelector('[data-share-progress]') : null;
|
|
1126
|
+
if (line && !changed) { line.textContent = progressText(view.shareProgress); return; }
|
|
1127
|
+
paintShareButton();
|
|
1128
|
+
paintSharePop();
|
|
1129
|
+
paintBanner();
|
|
1130
|
+
} catch { /* the publish's own answer says what happened */ } finally { busy = false; }
|
|
1131
|
+
};
|
|
1132
|
+
const loop = () => { timer = setTimeout(async () => { await tick(); if (live) loop(); }, 1000); };
|
|
1133
|
+
view.stopWatch = stop;
|
|
1134
|
+
loop();
|
|
1135
|
+
return stop;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
async function publish(payload, first) {
|
|
1139
|
+
const watch = watchPublish();
|
|
1140
|
+
let outcome;
|
|
1141
|
+
// null: a newer action (the person's Cancel) superseded this publish and has already said what happened.
|
|
1142
|
+
try { outcome = await shareCall('', 'POST', payload); }
|
|
1143
|
+
finally { watch(); paintBanner(); }
|
|
1144
|
+
if (outcome === null) return;
|
|
1145
|
+
// Another run (FloLess catching up in the background) settled this publish: the record says what happened.
|
|
1146
|
+
if (outcome === 'settled-elsewhere') { void loadShare(); return; }
|
|
1147
|
+
const s = view.share?.share;
|
|
1148
|
+
if (outcome === 'published' && s?.url) {
|
|
1149
|
+
let copied = false;
|
|
1150
|
+
if (first) { try { await navigator.clipboard.writeText(s.url); copied = true; } catch { copied = false; } }
|
|
1151
|
+
toast(first ? (copied ? 'Link created and copied. Anyone with it can open this Page.' : 'Link created. Copy it from the Share menu.')
|
|
1152
|
+
: `Published. Everyone with the link now sees ${verLabel(s.publishedPageVersion)}.`, 'ok');
|
|
1153
|
+
} else if (outcome === 'stale') {
|
|
1154
|
+
// Said in the banner, with the choice.
|
|
1155
|
+
} else if (outcome === 'revoke-pending') {
|
|
1156
|
+
toast('This link is being revoked, so the new version wasn’t published.', 'warn');
|
|
1157
|
+
} else if (outcome && outcome !== 'published') {
|
|
1158
|
+
const sentence = outcomeSentence(outcome);
|
|
1159
|
+
if (['no_subscription', 'too_large', 'quota', 'damaged', 'cancelled', 'reused', 'unsupported', 'revoked', 'not_found'].includes(outcome)) {
|
|
1160
|
+
view.share = { ...(view.share || {}), error: { code: outcome, message: sentence, path: null } };
|
|
1161
|
+
paintBanner();
|
|
1162
|
+
} else if (sentence) toast(sentence, 'warn');
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
function closeSharePop() {
|
|
1167
|
+
$sharePop.hidden = true;
|
|
1168
|
+
$share.setAttribute('aria-expanded', 'false');
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
$share.addEventListener('click', () => {
|
|
1172
|
+
if (!$sharePop.hidden) { closePopovers(); return; }
|
|
1173
|
+
closePopovers();
|
|
1174
|
+
paintSharePop();
|
|
1175
|
+
$sharePop.hidden = false;
|
|
1176
|
+
$share.setAttribute('aria-expanded', 'true');
|
|
1177
|
+
($sharePop.querySelector('.pv-share-primary') || $sharePop.querySelector('button'))?.focus();
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1180
|
+
async function onShareAct(act, button) {
|
|
1181
|
+
const s = view.share?.share;
|
|
1182
|
+
if (act === 'create') { closePopovers(); $share.focus(); await publish({ version: view.n }, true); return; }
|
|
1183
|
+
if (act === 'publish') { closePopovers(); await publish({ version: Number(button.dataset.n) }, false); return; }
|
|
1184
|
+
if (act === 'replace') { await publish({ expectedRemoteVersion: Number(button.dataset.expected), version: Number(button.dataset.n) || latestN() }, false); return; }
|
|
1185
|
+
if (act === 'keep-theirs') { view.shareBannerDismissed = true; paintBanner(); toast('Kept the link as it is.', 'ok'); return; }
|
|
1186
|
+
if (act === 'cancel') {
|
|
1187
|
+
closePopovers();
|
|
1188
|
+
view.shareProgress = null;
|
|
1189
|
+
const outcome = await shareCall('/cancel', 'POST');
|
|
1190
|
+
if (outcome === 'cancelled') toast('Publishing cancelled. The link is as it was.', 'ok');
|
|
1191
|
+
else if (outcome === 'published') toast('It had already been published, so the link shows it.', 'ok');
|
|
1192
|
+
else if (outcome && outcome !== 'nothing-to-do') toast(outcomeSentence(outcome), 'warn');
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
if (act === 'revoke') {
|
|
1196
|
+
closePopovers();
|
|
1197
|
+
const ok = await bridge.formModal?.({
|
|
1198
|
+
title: 'Revoke this link?',
|
|
1199
|
+
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.',
|
|
1200
|
+
fields: [], okLabel: 'Revoke link', danger: true, safeDefault: true, returnFocusTo: $share,
|
|
1201
|
+
});
|
|
1202
|
+
if (!ok) return;
|
|
1203
|
+
const outcome = await shareCall('', 'DELETE');
|
|
1204
|
+
if (outcome === 'revoked') toast('Link revoked. It no longer opens.', 'ok');
|
|
1205
|
+
else if (outcome === 'revoke-pending') toast('FloLess will revoke the link as soon as it can reach floless.io.', 'warn');
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
if (act === 'retry') { await publish({}, false); return; }
|
|
1209
|
+
if (act === 'retry-revoke') { await shareCall('', 'DELETE'); return; }
|
|
1210
|
+
if (act === 'copy') {
|
|
1211
|
+
try { await navigator.clipboard.writeText(s?.url || ''); toast('Link copied.', 'ok'); }
|
|
1212
|
+
catch { $sharePop.querySelector('.pv-share-url')?.select(); toast('FloLess couldn’t copy the link. It’s selected, so copy it with Ctrl+C.', 'warn'); }
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
if (act === 'open') { if (s?.url) window.open(s.url, '_blank', 'noopener'); return; }
|
|
1216
|
+
if (act === 'plans') { window.open(PLANS_URL, '_blank', 'noopener'); return; }
|
|
1217
|
+
if (act === 'reveal') {
|
|
1218
|
+
const path = view.share?.error?.path;
|
|
1219
|
+
if (!path) return;
|
|
1220
|
+
try { await api('/api/reveal', { method: 'POST', body: JSON.stringify({ path }) }); }
|
|
1221
|
+
catch (err) { toast(`FloLess couldn’t show the file. ${err?.body?.error || 'Try again in a moment.'}`, 'warn'); }
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
if (act === 'dismiss') { view.share = { ...(view.share || {}), error: null }; view.shareBannerDismissed = true; paintBanner(); $frame.focus(); return; }
|
|
1225
|
+
if (act === 'mine') { closePopovers(); openSharedLinks($share); }
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
$sharePop.addEventListener('click', (event) => {
|
|
1229
|
+
const button = event.target.closest('button[data-share-act]');
|
|
1230
|
+
if (button) void onShareAct(button.dataset.shareAct, button);
|
|
1231
|
+
});
|
|
1232
|
+
$banner.addEventListener('click', (event) => {
|
|
1233
|
+
const button = event.target.closest('button[data-share-act]');
|
|
1234
|
+
if (button) void onShareAct(button.dataset.shareAct, button);
|
|
1235
|
+
});
|
|
1236
|
+
|
|
1237
|
+
// ── My shared links (#2262 slice 4) ──
|
|
1238
|
+
|
|
1239
|
+
const $sl = document.getElementById('shared-links-modal');
|
|
1240
|
+
const $slList = document.getElementById('sl-list');
|
|
1241
|
+
const $slNote = document.getElementById('sl-note');
|
|
1242
|
+
const $slMore = document.getElementById('sl-more');
|
|
1243
|
+
const $slClose = document.getElementById('sl-close');
|
|
1244
|
+
const sl = { next: null, rows: [], local: [], returnFocus: null, loading: false };
|
|
1245
|
+
|
|
1246
|
+
const CHIP = { live: 'Live', 'pending-publish': 'Publishing', 'pending-revoke': 'Revoke waiting', revoked: 'Revoked' };
|
|
1247
|
+
|
|
1248
|
+
function slRowHtml(row) {
|
|
1249
|
+
const chip = row.state ? `<span class="sl-chip" data-state="${esc(row.state)}">${esc(CHIP[row.state] || '')}</span>` : '';
|
|
1250
|
+
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>' : '';
|
|
1251
|
+
const titleCell = row.page && !row.deleted
|
|
1252
|
+
? `<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>`
|
|
1253
|
+
: `<span class="pg-row-title">${esc(row.title || 'Untitled')}</span>`;
|
|
1254
|
+
const canAct = row.token && row.url && row.state !== 'revoked' && row.state !== 'pending-revoke';
|
|
1255
|
+
const actions = canAct ? `
|
|
1256
|
+
<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>
|
|
1257
|
+
<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>
|
|
1258
|
+
<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>` : '';
|
|
1259
|
+
return `<div class="pg-row sl-row" role="listitem">
|
|
1260
|
+
<div class="pg-row-text sl-row-text"><span class="pg-row-line">${titleCell}${ai}${chip}</span>
|
|
1261
|
+
<span class="pg-row-meta" ${row.when ? `data-tip="${esc(when(row.when))}"` : ''}>${esc(row.meta)}</span></div>
|
|
1262
|
+
<div class="sl-actions">${actions}</div></div>`;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
/** floless.io's list joined with what this computer holds, so a Page's link shows its Page and a waiting revoke shows. */
|
|
1266
|
+
function slRows(remote, local) {
|
|
1267
|
+
const byToken = new Map();
|
|
1268
|
+
for (const l of local) if (l.share?.token) byToken.set(l.share.token, l);
|
|
1269
|
+
const rows = remote.map((r) => {
|
|
1270
|
+
const mine = byToken.get(r.token);
|
|
1271
|
+
byToken.delete(r.token);
|
|
1272
|
+
const state = r.revoked ? 'revoked' : (mine?.share?.state === 'pending-revoke' ? 'pending-revoke' : 'live');
|
|
1273
|
+
const kind = r.kind === 'page' ? `Page link · link version ${r.remoteVersion}` : 'Report link';
|
|
1274
|
+
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,
|
|
1275
|
+
deleted: !!mine?.deleted, when: r.updatedAt || r.createdAt, meta: `${kind} · updated ${ago(r.updatedAt || r.createdAt)}` };
|
|
1276
|
+
});
|
|
1277
|
+
return rows;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
function slLocalOnly(local, remoteTokens) {
|
|
1281
|
+
return local.filter((l) => l.deleted || l.share?.state === 'pending-publish' || (l.share?.token && !remoteTokens.has(l.share.token))).map((l) => {
|
|
1282
|
+
const state = l.deleted ? 'pending-revoke' : l.share?.state || null;
|
|
1283
|
+
const meta = l.deleted ? 'Page deleted · its link will be revoked when FloLess can reach floless.io'
|
|
1284
|
+
: l.share?.state === 'pending-publish' ? 'Waiting to publish'
|
|
1285
|
+
: `Page link · link version ${l.share?.remoteVersion ?? 1}`;
|
|
1286
|
+
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 };
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
async function slLoad(more) {
|
|
1291
|
+
if (sl.loading) return;
|
|
1292
|
+
sl.loading = true;
|
|
1293
|
+
$slMore.setAttribute('aria-busy', 'true');
|
|
1294
|
+
try {
|
|
1295
|
+
const q = more && sl.next ? `?before=${encodeURIComponent(sl.next)}` : '';
|
|
1296
|
+
const body = await api(`/api/pages/shared-links${q}`);
|
|
1297
|
+
if (!more) { sl.rows = []; sl.local = body.local || []; }
|
|
1298
|
+
const remote = body.remote?.ok ? body.remote.links : [];
|
|
1299
|
+
sl.next = body.remote?.ok ? body.remote.next : null;
|
|
1300
|
+
sl.rows.push(...slRows(remote, sl.local));
|
|
1301
|
+
const tokens = new Set(sl.rows.map((r) => r.token));
|
|
1302
|
+
const localOnly = !body.remote?.ok || !sl.next ? slLocalOnly(sl.local, tokens) : [];
|
|
1303
|
+
// Slice 5: how much of the person's space for shared files is used (revoking a link frees what only it used).
|
|
1304
|
+
const usage = body.remote?.ok ? body.remote.usage : null;
|
|
1305
|
+
const size = (b) => (b >= 1024 ** 3 ? `${(b / 1024 ** 3).toFixed(1)} GB` : `${Math.round(b / 1024 ** 2)} MB`);
|
|
1306
|
+
$slNote.hidden = !!body.remote?.ok && !usage;
|
|
1307
|
+
$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'
|
|
1308
|
+
? '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.'
|
|
1309
|
+
: 'FloLess couldn’t reach floless.io, so this shows the links this computer knows about.');
|
|
1310
|
+
const all = [...sl.rows, ...localOnly];
|
|
1311
|
+
$slList.innerHTML = all.length ? all.map(slRowHtml).join('')
|
|
1312
|
+
: '<p class="pg-empty sl-empty">No shared links yet. Share a Page from its viewer with the Share button.</p>';
|
|
1313
|
+
$slMore.hidden = !sl.next;
|
|
1314
|
+
} catch (err) {
|
|
1315
|
+
$slNote.hidden = false;
|
|
1316
|
+
$slNote.textContent = `FloLess couldn’t list your shared links. ${err?.body?.error || 'Try again in a moment.'}`;
|
|
1317
|
+
} finally {
|
|
1318
|
+
sl.loading = false;
|
|
1319
|
+
$slMore.removeAttribute('aria-busy');
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
function openSharedLinks(returnFocus) {
|
|
1324
|
+
if (!$sl) return;
|
|
1325
|
+
sl.returnFocus = returnFocus instanceof HTMLElement ? returnFocus : document.activeElement;
|
|
1326
|
+
$slList.innerHTML = '<p class="pg-loading-line">Loading your shared links…</p>';
|
|
1327
|
+
$slMore.hidden = true;
|
|
1328
|
+
$sl.classList.add('show');
|
|
1329
|
+
$slClose.focus();
|
|
1330
|
+
void slLoad(false);
|
|
1331
|
+
}
|
|
1332
|
+
function closeSharedLinks() {
|
|
1333
|
+
if (!$sl?.classList.contains('show')) return;
|
|
1334
|
+
$sl.classList.remove('show');
|
|
1335
|
+
const back = sl.returnFocus;
|
|
1336
|
+
sl.returnFocus = null;
|
|
1337
|
+
if (back?.isConnected) back.focus();
|
|
1338
|
+
}
|
|
1339
|
+
if ($sl) {
|
|
1340
|
+
$slClose.addEventListener('click', closeSharedLinks);
|
|
1341
|
+
$slMore.addEventListener('click', () => { void slLoad(true); });
|
|
1342
|
+
if (typeof window.onBackdropDismiss === 'function') window.onBackdropDismiss($sl, closeSharedLinks);
|
|
1343
|
+
$sl.addEventListener('keydown', (event) => {
|
|
1344
|
+
if (event.key === 'Escape') { event.stopPropagation(); closeSharedLinks(); return; }
|
|
1345
|
+
if (event.key !== 'Tab') return;
|
|
1346
|
+
const focusables = [...$sl.querySelectorAll('button, [tabindex="0"]')].filter((el) => !el.disabled && el.offsetParent !== null);
|
|
1347
|
+
if (!focusables.length) return;
|
|
1348
|
+
const first = focusables[0];
|
|
1349
|
+
const last = focusables[focusables.length - 1];
|
|
1350
|
+
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
|
1351
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
|
1352
|
+
});
|
|
1353
|
+
$slList.addEventListener('click', async (event) => {
|
|
1354
|
+
const button = event.target.closest('button[data-sl-act]');
|
|
1355
|
+
if (!button) return;
|
|
1356
|
+
const act = button.dataset.slAct;
|
|
1357
|
+
if (act === 'copy') {
|
|
1358
|
+
try { await navigator.clipboard.writeText(button.dataset.url); toast('Link copied.', 'ok'); }
|
|
1359
|
+
catch { toast('FloLess couldn’t copy the link. Open it and copy it from the address bar.', 'warn'); }
|
|
1360
|
+
} else if (act === 'open') {
|
|
1361
|
+
window.open(button.dataset.url, '_blank', 'noopener');
|
|
1362
|
+
} else if (act === 'page') {
|
|
1363
|
+
closeSharedLinks();
|
|
1364
|
+
void openViewer(button.dataset.home, button.dataset.page, null, document.activeElement);
|
|
1365
|
+
} else if (act === 'revoke') {
|
|
1366
|
+
const ok = await bridge.formModal?.({
|
|
1367
|
+
title: `Revoke the link to “${button.dataset.title || 'this Page'}”?`,
|
|
1368
|
+
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.',
|
|
1369
|
+
fields: [], okLabel: 'Revoke link', danger: true, safeDefault: true, returnFocusTo: button,
|
|
1370
|
+
});
|
|
1371
|
+
if (!ok) return;
|
|
1372
|
+
try {
|
|
1373
|
+
const body = await api('/api/pages/shared-links/revoke', { method: 'POST', body: JSON.stringify({ token: button.dataset.token }) });
|
|
1374
|
+
if (body.outcome === 'revoked') toast('Link revoked. It no longer opens.', 'ok');
|
|
1375
|
+
else if (body.outcome === 'revoke-pending') toast('FloLess will revoke the link as soon as it can reach floless.io.', 'warn');
|
|
1376
|
+
else toast(outcomeSentence(body.outcome) || 'FloLess couldn’t revoke the link just now. Try again in a moment.', 'warn');
|
|
1377
|
+
} catch (err) {
|
|
1378
|
+
toast(`FloLess couldn’t revoke the link. ${err?.body?.error || 'Try again in a moment.'}`, 'warn');
|
|
1379
|
+
}
|
|
1380
|
+
await slLoad(false);
|
|
1381
|
+
// The Pages lists' chips and an open viewer's Share button read the same link: repaint them too.
|
|
1382
|
+
refreshLists();
|
|
1383
|
+
if (isOpen()) void loadShare();
|
|
1384
|
+
$slClose.focus();
|
|
1385
|
+
}
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
document.addEventListener('click', (event) => {
|
|
1389
|
+
const opener = event.target.closest('[data-command-id="shell.shared-links-open"]');
|
|
1390
|
+
if (opener && !opener.closest('#pv-share-pop')) openSharedLinks(opener);
|
|
1391
|
+
});
|
|
1392
|
+
|
|
585
1393
|
$close.addEventListener('click', closeViewer);
|
|
586
1394
|
if (typeof window.onBackdropDismiss === 'function') window.onBackdropDismiss($modal, closeViewer);
|
|
587
1395
|
|
|
@@ -590,11 +1398,12 @@
|
|
|
590
1398
|
event.stopPropagation();
|
|
591
1399
|
if (!$versionPop.hidden) { closePopovers(); $version.focus(); return; }
|
|
592
1400
|
if (!$sitesPop.hidden) { closePopovers(); $sites.focus(); return; }
|
|
1401
|
+
if (!$sharePop.hidden) { closePopovers(); $share.focus(); return; }
|
|
593
1402
|
closeViewer();
|
|
594
1403
|
return;
|
|
595
1404
|
}
|
|
596
1405
|
if (event.key !== 'Tab') return;
|
|
597
|
-
const focusables = [...$modal.querySelectorAll('button, [tabindex="0"], iframe')]
|
|
1406
|
+
const focusables = [...$modal.querySelectorAll('button, input, [tabindex="0"], iframe')]
|
|
598
1407
|
.filter((el) => !el.disabled && el.offsetParent !== null);
|
|
599
1408
|
if (!focusables.length) return;
|
|
600
1409
|
const first = focusables[0];
|
|
@@ -606,11 +1415,33 @@
|
|
|
606
1415
|
if (!isOpen()) return;
|
|
607
1416
|
if (!$versionPop.hidden && !event.target.closest('#pv-version, #pv-version-pop')) closePopovers();
|
|
608
1417
|
if (!$sitesPop.hidden && !event.target.closest('#pv-sites, #pv-sites-pop')) closePopovers();
|
|
1418
|
+
if (!$sharePop.hidden && !event.target.closest('#pv-share, #pv-share-pop')) closePopovers();
|
|
1419
|
+
});
|
|
1420
|
+
|
|
1421
|
+
// #2262 slice 3c: the version's complete report, opened in FloLess's report viewer. The server finds it from the
|
|
1422
|
+
// version's run; the Page's frame can't ask for it and its record never holds the report's handle.
|
|
1423
|
+
$fullReport?.addEventListener('click', async () => {
|
|
1424
|
+
const v = currentVersion();
|
|
1425
|
+
if (!view.page || !v || v.content?.kind !== 'complete-report') return;
|
|
1426
|
+
const host = window.FlolessReports;
|
|
1427
|
+
if (!host?.openPageVersionReport) return;
|
|
1428
|
+
// Busy, not disabled: the button keeps its focus while FloLess asks for the report.
|
|
1429
|
+
if ($fullReport.getAttribute('aria-busy') === 'true') return;
|
|
1430
|
+
$fullReport.setAttribute('aria-busy', 'true');
|
|
1431
|
+
try {
|
|
1432
|
+
await host.openPageVersionReport({ home: view.home, id: view.page.id, n: v.n, title: view.page.title, beforeShow: () => closeViewer() });
|
|
1433
|
+
} finally { $fullReport.removeAttribute('aria-busy'); }
|
|
609
1434
|
});
|
|
610
1435
|
|
|
611
1436
|
window.flolessPages = {
|
|
612
1437
|
renderList,
|
|
1438
|
+
openSharedLinks: (returnFocus) => openSharedLinks(returnFocus),
|
|
613
1439
|
open: (home, id, n) => openViewer(home, id, n ?? null, document.activeElement),
|
|
614
1440
|
refresh: refreshLists,
|
|
1441
|
+
/** The server changed this Page's record (a failed live session's labels): an open copy re-reads it. */
|
|
1442
|
+
reloadIfOpen: (home, id) => {
|
|
1443
|
+
if (!isOpen() || view.home !== home || view.page?.id !== id) return;
|
|
1444
|
+
void reloadRecord();
|
|
1445
|
+
},
|
|
615
1446
|
};
|
|
616
1447
|
})();
|