clavarium 0.2.22 → 0.2.23-next.2
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/README.md +4 -1
- package/deploy/clavarium-host +2 -0
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/server/capacity.mjs +11 -2
- package/server/conversations.mjs +2 -1
- package/server/gitkeeper.mjs +29 -3
- package/server/main.mjs +1 -1
- package/server/shelf.mjs +2 -0
- package/server/talk.mjs +17 -5
- package/web/app.js +371 -65
- package/web/index.html +51 -47
- package/web/style.css +172 -25
package/web/app.js
CHANGED
|
@@ -354,6 +354,7 @@
|
|
|
354
354
|
document.documentElement.dataset.theme = light ? 'light' : 'dark';
|
|
355
355
|
/* The chat's colours of meaning (notes, warnings, code) follow the page's theme, not the device's. */
|
|
356
356
|
$('simple-thread').dataset.theme = light ? 'light' : 'dark';
|
|
357
|
+
for (const view of document.querySelectorAll('.md-view')) view.dataset.theme = light ? 'light' : 'dark';
|
|
357
358
|
terminal.options.theme = light ? LIGHT : DARK;
|
|
358
359
|
document.querySelector('meta[name=theme-color]')?.setAttribute('content', light ? LIGHT.background : DARK.background);
|
|
359
360
|
$('theme').textContent = light ? 'Dark' : 'Light';
|
|
@@ -1338,50 +1339,131 @@
|
|
|
1338
1339
|
if (home) pollTimer = setTimeout(refresh, conversations.some(holds) ? 1500 : conversations.some((c) => c.phase === 'building' || c.phase === 'moving' || c.phase === 'restarting') ? 2500 : 10000);
|
|
1339
1340
|
}
|
|
1340
1341
|
|
|
1341
|
-
/* ----------
|
|
1342
|
+
/* ---------- A NEW CONVERSATION: a page of its own, as Settings ----------
|
|
1343
|
+
"+ New" opens it beside the list (the whole screen on a phone), with an
|
|
1344
|
+
address of its own (?open=new); Back, Escape, Cancel and its "<" link
|
|
1345
|
+
close it. From the map's "+" it is a step over the map, and goes back
|
|
1346
|
+
to it. Its tools are the server's (GET /api/tools). */
|
|
1342
1347
|
let chosenTool = '';
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
for (const
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1348
|
+
let newTools = [];
|
|
1349
|
+
const ID_SHAPE = /^[a-z]([a-z0-9-]{0,30}[a-z0-9])?$/;
|
|
1350
|
+
const NEW_FIELDS = ['name', 'group', 'id', 'memory'];
|
|
1351
|
+
function newError(field, text) {
|
|
1352
|
+
const at = field && NEW_FIELDS.includes(field) ? field : '';
|
|
1353
|
+
for (const f of NEW_FIELDS) {
|
|
1354
|
+
const said = $(`newconv-${f}-error`); const box = $(`newconv-${f}`);
|
|
1355
|
+
const mine = f === at && Boolean(text);
|
|
1356
|
+
said.textContent = mine ? text : ''; said.hidden = !mine;
|
|
1357
|
+
if (mine) box.setAttribute('aria-invalid', 'true'); else box.removeAttribute('aria-invalid');
|
|
1358
|
+
}
|
|
1359
|
+
const status = $('newconv-status');
|
|
1360
|
+
const general = !at && Boolean(text);
|
|
1361
|
+
status.textContent = general ? text : 'Ready in a few minutes';
|
|
1362
|
+
status.classList.toggle('error', general);
|
|
1363
|
+
if (at === 'id' || at === 'memory') $('newconv-more').open = true;
|
|
1364
|
+
if (at) $(`newconv-${at}`).focus();
|
|
1365
|
+
}
|
|
1366
|
+
/* Which field a refusal of the server is about (names.mjs, conversations.mjs, capacity.mjs). */
|
|
1367
|
+
function fieldOf(message) {
|
|
1368
|
+
if (/folder name/i.test(message)) return 'group';
|
|
1369
|
+
if (/already has this name|^A name is 1 to 32/.test(message)) return 'id';
|
|
1370
|
+
if (/memory/i.test(message)) return 'memory';
|
|
1371
|
+
if (/^(Give a name|A name )/.test(message)) return 'name';
|
|
1372
|
+
return '';
|
|
1373
|
+
}
|
|
1374
|
+
/* Memory: from what the chosen tool needs up to what a machine may have (MEMORY_CHOICES). */
|
|
1375
|
+
function paintNewMemory() {
|
|
1376
|
+
const tool = newTools.find((t) => t.id === chosenTool);
|
|
1377
|
+
const least = tool?.memoryMb ?? 512;
|
|
1378
|
+
const select = $('newconv-memory');
|
|
1379
|
+
const was = Number(select.value) || least;
|
|
1380
|
+
const mems = [...new Set([least, ...MEMORY_CHOICES.filter((m) => m > least)])];
|
|
1381
|
+
select.replaceChildren(...mems.map((m) => { const o = document.createElement('option'); o.value = String(m); o.textContent = sizeWords(m); return o; }));
|
|
1382
|
+
select.value = String(mems.includes(was) ? was : least);
|
|
1383
|
+
$('newconv-memory-least').textContent = tool ? `${tool.label} needs ${sizeWords(least)} at least` : '';
|
|
1384
|
+
}
|
|
1385
|
+
function paintNewTools() {
|
|
1386
|
+
const box = $('newconv-tools');
|
|
1387
|
+
if (!newTools.some((t) => t.id === chosenTool)) chosenTool = newTools[0]?.id ?? '';
|
|
1388
|
+
box.replaceChildren(...newTools.map((t) => {
|
|
1389
|
+
const b = el('button'); b.type = 'button'; b.setAttribute('role', 'radio'); b.dataset.tool = t.id;
|
|
1390
|
+
b.setAttribute('aria-checked', String(t.id === chosenTool));
|
|
1391
|
+
b.append(el('b', '', t.label), el('small', '', t.ai ? 'AI agent' : 'A terminal, no AI'));
|
|
1352
1392
|
b.addEventListener('click', () => {
|
|
1353
1393
|
chosenTool = t.id;
|
|
1354
|
-
for (const other of box.children) other.setAttribute('aria-checked', other === b
|
|
1394
|
+
for (const other of box.children) other.setAttribute('aria-checked', String(other === b));
|
|
1395
|
+
paintNewMemory();
|
|
1355
1396
|
});
|
|
1356
|
-
|
|
1397
|
+
return b;
|
|
1398
|
+
}));
|
|
1399
|
+
paintNewMemory();
|
|
1400
|
+
}
|
|
1401
|
+
for (const b of $('newconv-work').querySelectorAll('[data-work]')) {
|
|
1402
|
+
b.addEventListener('click', () => { for (const other of $('newconv-work').querySelectorAll('[data-work]')) other.setAttribute('aria-checked', String(other === b)); });
|
|
1403
|
+
}
|
|
1404
|
+
const newOnDisk = () => $('newconv-work').querySelector('[data-work="disk"]').getAttribute('aria-checked') === 'true';
|
|
1405
|
+
async function openNew({ push = true } = {}) {
|
|
1406
|
+
if (DEVICE) return;
|
|
1407
|
+
newError('', '');
|
|
1408
|
+
if (place !== 'new') {
|
|
1409
|
+
/* From the map: a step over it, and back to it. Otherwise a place of its own. */
|
|
1410
|
+
if (place === 'access' && push) {
|
|
1411
|
+
showPlace('new');
|
|
1412
|
+
nav.push('create', ({ quiet }) => {
|
|
1413
|
+
if (quiet || place !== 'new') return;
|
|
1414
|
+
showPlace('access'); paintTabs(); remember();
|
|
1415
|
+
void (mapMode === 'flows' ? links?.openFlows() : links?.open({ pin: accessFor ? `conversation:${accessFor}` : null }));
|
|
1416
|
+
}, { address: placeAddress() });
|
|
1417
|
+
$('newconv-close').textContent = '‹ Access';
|
|
1418
|
+
} else {
|
|
1419
|
+
enterPlace('new', push);
|
|
1420
|
+
$('newconv-close').textContent = '‹ Conversations';
|
|
1421
|
+
}
|
|
1357
1422
|
}
|
|
1358
|
-
$('
|
|
1359
|
-
$('
|
|
1360
|
-
|
|
1423
|
+
$('newconv').scrollTop = 0;
|
|
1424
|
+
focusField($('newconv-name'));
|
|
1425
|
+
try { const r = await fetch(`${API}/tools`); if (r.ok) newTools = await r.json(); } catch { /* kept as it was */ }
|
|
1426
|
+
paintNewTools();
|
|
1361
1427
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
function createFromMap() {
|
|
1367
|
-
void openCreate();
|
|
1368
|
-
if (narrow()) view('list');
|
|
1369
|
-
if (nav.last(['create']) < 0) nav.push('create', ({ quiet }) => { $('create').hidden = true; if (!quiet && place !== 'conversations') view('room'); });
|
|
1428
|
+
/* Closed as any page is: the step on top (the place, or the step over the map). */
|
|
1429
|
+
function closeNew() {
|
|
1430
|
+
if (place !== 'new') return;
|
|
1431
|
+
if (!nav.close('create')) leavePlace();
|
|
1370
1432
|
}
|
|
1433
|
+
$('hidden-toggle').addEventListener('click', () => { showHidden = !showHidden; paint(); });
|
|
1434
|
+
$('new').addEventListener('click', () => { void openNew(); });
|
|
1435
|
+
$('newconv-cancel').addEventListener('click', closeNew);
|
|
1436
|
+
$('newconv-close').addEventListener('click', closeNew);
|
|
1437
|
+
/* From the map's "+" of Conversations: the same page. */
|
|
1438
|
+
function createFromMap() { void openNew(); }
|
|
1371
1439
|
/* The identifier drawn from the name, as the server draws it (names.mjs), shown before it is made; the server decides. */
|
|
1372
|
-
const identifierOf = (title) => String(title).normalize('NFKD').replace(/[
|
|
1373
|
-
$('
|
|
1374
|
-
$(
|
|
1440
|
+
const identifierOf = (title) => String(title).normalize('NFKD').replace(/[̀-ͯ]/g, '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^[^a-z]+/, '').replace(/-+$/, '').slice(0, 32).replace(/-+$/, '') || 'conversation';
|
|
1441
|
+
$('newconv-name').addEventListener('input', () => { $('newconv-id').placeholder = identifierOf($('newconv-name').value.trim()); });
|
|
1442
|
+
for (const f of NEW_FIELDS) $(`newconv-${f}`).addEventListener(f === 'memory' ? 'change' : 'input', () => { if (!$(`newconv-${f}-error`).hidden) newError('', ''); });
|
|
1443
|
+
let creating = false;
|
|
1444
|
+
$('newconv').addEventListener('submit', async (event) => {
|
|
1375
1445
|
event.preventDefault();
|
|
1376
|
-
|
|
1377
|
-
const
|
|
1446
|
+
if (creating) return;
|
|
1447
|
+
const title = $('newconv-name').value.trim();
|
|
1448
|
+
const id = $('newconv-id').value.trim();
|
|
1449
|
+
const group = $('newconv-group').value.trim();
|
|
1450
|
+
if (!title) { newError('name', 'Give a name.'); return; }
|
|
1451
|
+
if (id && !ID_SHAPE.test(id)) { newError('id', 'Lower-case letters, digits, hyphens'); return; }
|
|
1452
|
+
const least = newTools.find((t) => t.id === chosenTool)?.memoryMb;
|
|
1453
|
+
const memoryMb = Number($('newconv-memory').value);
|
|
1454
|
+
newError('', '');
|
|
1455
|
+
creating = true; $('newconv-create').disabled = true;
|
|
1378
1456
|
try {
|
|
1379
|
-
const
|
|
1380
|
-
|
|
1381
|
-
$('
|
|
1457
|
+
const made = await post(`${API}/conversations`, { title, ...(id ? { name: id } : {}), ...(group ? { group } : {}), tool: chosenTool, workOnDisk: newOnDisk(), ...(memoryMb && memoryMb !== least ? { memoryMb } : {}) });
|
|
1458
|
+
$('newconv-name').value = ''; $('newconv-id').value = ''; $('newconv-id').placeholder = 'website-redesign'; $('newconv-group').value = '';
|
|
1459
|
+
$('newconv-work').querySelector('[data-work="kept"]').click(); $('newconv-more').open = false;
|
|
1382
1460
|
await refresh();
|
|
1461
|
+
/* The new one is selected: the page gives way to it, with no step of it left behind. */
|
|
1383
1462
|
select(made.name);
|
|
1384
|
-
} catch (error) {
|
|
1463
|
+
} catch (error) {
|
|
1464
|
+
const field = fieldOf(error.message);
|
|
1465
|
+
newError(field, field === 'id' && /already has this name/.test(error.message) ? 'Already used by another conversation' : error.message);
|
|
1466
|
+
} finally { creating = false; $('newconv-create').disabled = false; }
|
|
1385
1467
|
});
|
|
1386
1468
|
|
|
1387
1469
|
/* ---------- shortcuts ---------- */
|
|
@@ -2959,21 +3041,22 @@
|
|
|
2959
3041
|
ticked, on a click; then Send. */
|
|
2960
3042
|
async function sendDetail(holder, names) {
|
|
2961
3043
|
const progress = el('p', 'status-line ts-progress'); progress.setAttribute('role', 'status');
|
|
3044
|
+
const meter = el('div', 'ts-meter'); const meterFill = el('i'); meter.append(meterFill); meter.setAttribute('aria-hidden', 'true');
|
|
2962
3045
|
const filters = el('div', 'levels ts-filters'); filters.setAttribute('role', 'group'); filters.setAttribute('aria-label', 'Show');
|
|
2963
3046
|
const list = el('div', 'ts-rows');
|
|
2964
|
-
const bar = el('div', '
|
|
3047
|
+
const bar = el('div', 'action-row ts-bar');
|
|
2965
3048
|
const together = el('button', '', 'Review together'); together.type = 'button'; together.dataset.act = 'send-review';
|
|
2966
3049
|
const go = el('button', 'primary', 'Check'); go.type = 'button'; go.dataset.act = 'send-all';
|
|
2967
|
-
const why = el('span', 'hint ts-why');
|
|
2968
|
-
bar.append(together, go
|
|
3050
|
+
const why = el('span', 'hint ts-why'); why.setAttribute('role', 'status');
|
|
3051
|
+
bar.append(why, together, go);
|
|
2969
3052
|
const said = el('p', 'ts-said'); said.hidden = true; said.setAttribute('role', 'status');
|
|
2970
3053
|
const review = el('div', 'ts-review'); review.hidden = true;
|
|
2971
|
-
holder.append(progress, filters, list, bar, said, review);
|
|
3054
|
+
holder.append(progress, meter, filters, list, bar, said, review);
|
|
2972
3055
|
const rows = [];
|
|
2973
3056
|
let filter = 'update';
|
|
2974
3057
|
let sending = false; let checking = false;
|
|
2975
3058
|
let sure = '';
|
|
2976
|
-
let
|
|
3059
|
+
let reposDone = 0; let reading = true;
|
|
2977
3060
|
const shownRow = (r) => filter === 'all' || kindOfRow(r.out) === filter;
|
|
2978
3061
|
const picked = () => rows.filter((r) => r.picked && r.out?.state === 'ahead' && shownRow(r));
|
|
2979
3062
|
const label = (r) => (rows.filter((x) => x.name === r.name).length > 1 ? `${r.name} (${r.branch})` : r.name);
|
|
@@ -2985,19 +3068,28 @@
|
|
|
2985
3068
|
r.out = out; r.keep = keep; r.branch = out.branch ?? r.branch; r.target = out.target ?? r.target; r.check = null;
|
|
2986
3069
|
if (out.state !== 'ahead') r.picked = false;
|
|
2987
3070
|
}
|
|
3071
|
+
/* The server keeps the run: a request hears "running" after a while, and asks again until it ends. */
|
|
2988
3072
|
async function checkRow(r) {
|
|
2989
3073
|
const { head, target } = r.out;
|
|
2990
|
-
r.check = { status: 'running' }; paint();
|
|
3074
|
+
r.check = { status: 'running' }; r.open = false; paint();
|
|
2991
3075
|
let result;
|
|
2992
|
-
|
|
2993
|
-
|
|
3076
|
+
for (let first = true; ; first = false) {
|
|
3077
|
+
try { result = await post(`${API}/git/${r.name}/check`, { head, target, ...(first ? {} : { join: true }) }); }
|
|
3078
|
+
catch (error) { result = { status: 'unavailable', output: `The page could not reach the server: ${error.message}` }; }
|
|
3079
|
+
if (result?.status !== 'running' || r.out?.head !== head || r.out?.target !== target) break;
|
|
3080
|
+
}
|
|
2994
3081
|
if (r.out?.head !== head || r.out?.target !== target) return;
|
|
2995
3082
|
r.check = result; paint();
|
|
2996
3083
|
}
|
|
3084
|
+
/* What its agent is told when checks did not pass: where, and the end of what they said. */
|
|
3085
|
+
const forAgent = (r) => `The checks of ${r.name} (${r.out.branch} → ${r.out.target}) did not pass before sending. Please fix it, commit, and tell me.\n\n\`\`\`\n${String(r.check?.output ?? '').slice(-3000)}\n\`\`\``;
|
|
2997
3086
|
const stopped = (r) => Boolean(r.keep?.settings?.requireForSend) && r.check?.status !== 'passed';
|
|
2998
3087
|
function paintProgress() {
|
|
2999
3088
|
const count = (k) => rows.filter((r) => kindOfRow(r.out) === k).length;
|
|
3000
|
-
|
|
3089
|
+
/* By repositories: how many there are is known from the start, how many branches each has is not. */
|
|
3090
|
+
meter.hidden = !reading; meterFill.style.width = `${names.length ? Math.round((reposDone / names.length) * 100) : 100}%`;
|
|
3091
|
+
progress.toggleAttribute('data-busy', reading);
|
|
3092
|
+
if (reading) { progress.dataset.tone = 'warn'; progress.textContent = `Reading the repositories: ${reposDone} of ${names.length}${rows.length ? ` · ${rows.length} branch${rows.length === 1 ? '' : 'es'} found` : ''}`; }
|
|
3001
3093
|
else { progress.dataset.tone = count('update') + count('new') ? 'ok' : ''; progress.textContent = count('update') + count('new') ? `${count('update')} to update · ${count('new')} new · all read` : 'Nothing to send · all read'; }
|
|
3002
3094
|
filters.replaceChildren(...TS_FILTERS.map(([key, word]) => {
|
|
3003
3095
|
const n = key === 'all' ? rows.length : count(key);
|
|
@@ -3067,9 +3159,36 @@
|
|
|
3067
3159
|
else if (r.check.status === 'running') state.append(el('span', 'warn', 'Checking...'));
|
|
3068
3160
|
else {
|
|
3069
3161
|
const [word, tone] = CHECK_WORDS[r.check.status] ?? [String(r.check.status), ''];
|
|
3070
|
-
|
|
3162
|
+
const text = r.check.status === 'passed' ? '✓ Checks passed' : r.check.status === 'failed' ? '✗ Checks failed' : word;
|
|
3163
|
+
/* What did not pass says why, one tap away: the reason, what they printed, and what to do. */
|
|
3164
|
+
if (r.check.status === 'failed' || r.check.status === 'unavailable') {
|
|
3165
|
+
const open = el('button', `ts-why-open ${tone}`, `${text} ${r.open ? '▴' : '▾'}`); open.type = 'button'; open.setAttribute('aria-expanded', String(Boolean(r.open)));
|
|
3166
|
+
open.addEventListener('click', () => { r.open = !r.open; paint(); });
|
|
3167
|
+
state.append(open);
|
|
3168
|
+
} else state.append(el('b', tone || 'quiet', text));
|
|
3071
3169
|
}
|
|
3072
3170
|
row.append(tick, who, way, size, state);
|
|
3171
|
+
if (!r.seen) { r.seen = true; if (reading) row.classList.add('ts-new'); }
|
|
3172
|
+
if (r.open && r.check && !r.sent) {
|
|
3173
|
+
const lines = String(r.check.output ?? '').split('\n').map((x) => x.trim()).filter(Boolean);
|
|
3174
|
+
const box = el('div', 'ts-why-box');
|
|
3175
|
+
box.append(el('p', '', lines[0] ?? 'Nothing was said.'));
|
|
3176
|
+
if (lines.length > 1) box.append(el('pre', 'ts-output', String(r.check.output).slice(-4000)));
|
|
3177
|
+
const acts = el('div', 'action-row');
|
|
3178
|
+
const again = el('button', '', 'Check again'); again.type = 'button'; again.dataset.act = 'check-again';
|
|
3179
|
+
again.disabled = checking || sending;
|
|
3180
|
+
again.addEventListener('click', async () => { checking = true; await checkRow(r); checking = false; paint(); });
|
|
3181
|
+
const tell = el('button', '', talk.on && talkOf === current ? 'Ask its agent to fix it' : 'Copy for its agent'); tell.type = 'button'; tell.dataset.act = 'tell-agent';
|
|
3182
|
+
tell.addEventListener('click', async () => {
|
|
3183
|
+
try {
|
|
3184
|
+
if (talk.on && talkOf === current) { await post(talkPath(current), { text: forAgent(r) }); tell.textContent = '✓ Sent to its chat'; }
|
|
3185
|
+
else { await navigator.clipboard.writeText(forAgent(r)); tell.textContent = '✓ Copied'; }
|
|
3186
|
+
tell.disabled = true;
|
|
3187
|
+
} catch (error) { tell.textContent = `Not done: ${error.message}`; }
|
|
3188
|
+
});
|
|
3189
|
+
acts.append(again, tell); box.append(acts);
|
|
3190
|
+
row.append(box);
|
|
3191
|
+
}
|
|
3073
3192
|
if (r.sent && !r.sent.ok) row.append(el('p', 'ts-note bad', r.sent.text));
|
|
3074
3193
|
list.append(row);
|
|
3075
3194
|
}
|
|
@@ -3174,7 +3293,7 @@
|
|
|
3174
3293
|
sending = false; paint();
|
|
3175
3294
|
const ok = p.filter((r) => r.sent?.ok).length;
|
|
3176
3295
|
said.textContent = ok === p.length ? `Sent: ${ok === 1 ? 'it went' : `all ${ok} went`}.` : `${ok} of ${p.length} sent; the others say why.`;
|
|
3177
|
-
said.className = `ts-said ${ok === p.length ? 'ok' : 'bad'}`; said.hidden = false;
|
|
3296
|
+
said.className = `status-line ts-said ${ok === p.length ? 'ok' : 'bad'}`; said.dataset.tone = ok === p.length ? 'ok' : 'bad'; said.hidden = false;
|
|
3178
3297
|
if (reviewStep) nav.drop(reviewStep);
|
|
3179
3298
|
/* What is left to send, read again; what became of each stays said. */
|
|
3180
3299
|
const kept = new Map(rows.map((r) => [r, r.sent]));
|
|
@@ -3188,18 +3307,18 @@
|
|
|
3188
3307
|
await Promise.all(names.map(async (name) => {
|
|
3189
3308
|
const first = { name, out: null, keep: null, branch: '', target: '', picked: false, check: null, sent: null };
|
|
3190
3309
|
rows.push(first);
|
|
3191
|
-
await look(first);
|
|
3310
|
+
await look(first);
|
|
3192
3311
|
first.movedAt = (first.out?.agentBranches ?? []).find((b) => b.name === first.branch)?.movedAt ?? null;
|
|
3193
3312
|
first.picked = kindOfRow(first.out) === 'update';
|
|
3194
3313
|
const others = (first.out?.agentBranches ?? []).filter((b) => b.name !== first.branch).slice(0, BRANCHES_MORE);
|
|
3195
|
-
planned += others.length;
|
|
3196
3314
|
paint();
|
|
3197
3315
|
await Promise.all(others.map(async (b) => {
|
|
3198
3316
|
const r = { name, out: null, keep: first.keep, branch: b.name, target: '', picked: false, check: null, sent: null, movedAt: b.movedAt };
|
|
3199
|
-
await look(r);
|
|
3317
|
+
await look(r);
|
|
3200
3318
|
if (r.out?.state === 'ahead') { r.picked = kindOfRow(r.out) === 'update' && lately(r); rows.splice(rows.findLastIndex((x) => x.name === name) + 1, 0, r); }
|
|
3201
3319
|
paint();
|
|
3202
3320
|
}));
|
|
3321
|
+
reposDone++; paint();
|
|
3203
3322
|
}));
|
|
3204
3323
|
reading = false;
|
|
3205
3324
|
paint();
|
|
@@ -3366,12 +3485,13 @@
|
|
|
3366
3485
|
/* State, in a line. */
|
|
3367
3486
|
if (chosen.kind === 'mailbox') detail.append(el('p', chosen.box?.failure ? 'error' : 'hint', boxSub(chosen.box)));
|
|
3368
3487
|
if (chosen.kind === 'secret') {
|
|
3369
|
-
detail.append(el('p', 'hint', 'Its value is never shown again. A change takes effect the next time the tool starts.'));
|
|
3370
3488
|
/* Renamed: its value and the conversations it is handed to go with it. */
|
|
3371
|
-
const form = el('form', 'row secret-rename'); form.autocomplete = 'off';
|
|
3489
|
+
const form = el('form', 'set-row secret-rename'); form.autocomplete = 'off';
|
|
3372
3490
|
const name = el('input'); name.id = 'secret-rename-name'; name.value = chosen.name; name.maxLength = 40; name.pattern = '[A-Z][A-Z0-9_]*'; name.spellcheck = false; name.autocapitalize = 'characters'; name.setAttribute('aria-label', 'New name');
|
|
3373
3491
|
const go = el('button', '', 'Rename'); go.type = 'submit';
|
|
3374
|
-
|
|
3492
|
+
const what = el('div', 'set-what'); what.append(el('span', '', 'Name'), el('small', '', 'Value never shown · applies at next start'));
|
|
3493
|
+
const control = el('div', 'set-control'); control.append(name, go);
|
|
3494
|
+
form.append(what, control);
|
|
3375
3495
|
form.addEventListener('submit', async (event) => {
|
|
3376
3496
|
event.preventDefault();
|
|
3377
3497
|
$('assets-error').hidden = true;
|
|
@@ -3379,7 +3499,8 @@
|
|
|
3379
3499
|
catch (error) { $('assets-error').textContent = error.message; $('assets-error').hidden = false; }
|
|
3380
3500
|
await paintAssets();
|
|
3381
3501
|
});
|
|
3382
|
-
|
|
3502
|
+
const box = el('div', 'set-rows as-block'); box.append(form);
|
|
3503
|
+
detail.append(box);
|
|
3383
3504
|
}
|
|
3384
3505
|
/* Used by: each conversation that has it, what it may do; "+" offers the others. */
|
|
3385
3506
|
const options = chosen.kind === 'secret' ? [['off', 'Off'], ['use', 'Use']] : chosen.kind === 'mailbox' ? [['none', 'Off'], ['read', 'Read']] : [['none', 'Off'], ['read', 'Read'], ['write', 'Write']];
|
|
@@ -3427,13 +3548,18 @@
|
|
|
3427
3548
|
const inUse = chosen.kind !== 'secret' && using.length > 0;
|
|
3428
3549
|
if (inUse) { remove.disabled = true; why.textContent = ` used by ${using.length} conversation${using.length > 1 ? 's' : ''}: set ${using.length > 1 ? 'them' : 'it'} to Off first`; }
|
|
3429
3550
|
remove.addEventListener('click', () => {
|
|
3430
|
-
const sure = el('button', 'danger', chosen.kind === 'secret' ? `Yes, delete ${chosen.name}` : `Yes, remove ${chosen.name}
|
|
3551
|
+
const sure = el('button', 'danger', chosen.kind === 'secret' ? `Yes, delete ${chosen.name}` : `Yes, remove ${chosen.name}`); sure.type = 'button';
|
|
3552
|
+
const keep = el('button', '', 'Keep'); keep.type = 'button';
|
|
3553
|
+
keep.addEventListener('click', () => { void paintAssets(); });
|
|
3554
|
+
const ask = el('div', 'callout bad confirm'); ask.setAttribute('role', 'alertdialog');
|
|
3555
|
+
ask.append(el('span', '', chosen.kind === 'secret' ? 'Its value is lost for good.' : 'Its files are kept aside on the server.'), keep, sure);
|
|
3431
3556
|
sure.addEventListener('click', async () => {
|
|
3432
3557
|
try { await post(chosen.kind === 'secret' ? `${API}/secrets/${chosen.name}/remove` : `${API}/resources/${chosen.name}/remove`); assetOpen = ''; }
|
|
3433
3558
|
catch (error) { $('assets-error').textContent = error.message; $('assets-error').hidden = false; }
|
|
3434
3559
|
await paintAssets();
|
|
3435
3560
|
});
|
|
3436
|
-
remove.replaceWith(
|
|
3561
|
+
remove.replaceWith(ask); why.remove();
|
|
3562
|
+
sure.focus();
|
|
3437
3563
|
});
|
|
3438
3564
|
/* Given to a device: from here too (the map shows who has it). */
|
|
3439
3565
|
const share = el('button', 'as-link', 'Share with a device...'); share.type = 'button';
|
|
@@ -3467,8 +3593,8 @@
|
|
|
3467
3593
|
const pick = $('gitview-sshkey'); pick.replaceChildren();
|
|
3468
3594
|
for (const [value, text] of [['', '(none)'], ...gitKeys.map((k) => [k.name, k.name])]) { const o = document.createElement('option'); o.value = value; o.textContent = text; pick.append(o); }
|
|
3469
3595
|
pick.value = settings.sshKey ?? '';
|
|
3470
|
-
$('gitview-key-state').textContent = settings.hasKey ? '
|
|
3471
|
-
: settings.sshKey ? `
|
|
3596
|
+
$('gitview-key-state').textContent = settings.hasKey ? 'Push key: kept here'
|
|
3597
|
+
: settings.sshKey ? `Push key: SSH key ${settings.sshKey}` : 'Push key: none · the clone\'s access, same server only';
|
|
3472
3598
|
}
|
|
3473
3599
|
$('assets-search').addEventListener('input', () => { assetsQuery = $('assets-search').value.trim(); void paintAssets(); });
|
|
3474
3600
|
$('assets-close').addEventListener('click', () => leavePlace());
|
|
@@ -3645,10 +3771,14 @@
|
|
|
3645
3771
|
place = which;
|
|
3646
3772
|
app.dataset.place = which;
|
|
3647
3773
|
app.dataset.current = current ? 'yes' : '';
|
|
3648
|
-
|
|
3774
|
+
/* A new conversation is made among the conversations: "+ New" stays marked while its page is open. */
|
|
3775
|
+
const marked = which === 'new' ? 'conversations' : which;
|
|
3776
|
+
for (const b of $('nav').querySelectorAll('button[data-place]')) { if (b.dataset.place === marked) b.setAttribute('aria-current', 'page'); else b.removeAttribute('aria-current'); }
|
|
3777
|
+
$('new').setAttribute('aria-pressed', String(which === 'new'));
|
|
3649
3778
|
$('access').hidden = which !== 'access';
|
|
3650
3779
|
$('settings').hidden = which !== 'settings';
|
|
3651
3780
|
$('assets').hidden = which !== 'assets';
|
|
3781
|
+
$('newconv').hidden = which !== 'new';
|
|
3652
3782
|
if (which !== 'access') composing = false;
|
|
3653
3783
|
/* What the conversation had open (its tab) waits under the place, as it was. */
|
|
3654
3784
|
if (which !== 'conversations') { for (const id of ['files', 'copy']) $(id).hidden = true; view('room'); }
|
|
@@ -3747,6 +3877,7 @@
|
|
|
3747
3877
|
const wanted = q.get('c') ?? '';
|
|
3748
3878
|
if (home && wanted !== current && conversations.some((c) => c.name === wanted)) select(wanted);
|
|
3749
3879
|
const open = q.get('open') ?? '';
|
|
3880
|
+
if (open === 'new') { await openNew({ push: false }); return; }
|
|
3750
3881
|
if (open === 'settings') {
|
|
3751
3882
|
await openSettings({ push: false });
|
|
3752
3883
|
/* A link to one chapter of Settings (?open=settings&at=resources): that one opened, and shown. */
|
|
@@ -4821,7 +4952,7 @@
|
|
|
4821
4952
|
$('gitview-alert').checked = s.alert; $('gitview-tellmoves').checked = s.tellMoves !== false;
|
|
4822
4953
|
/* Which conversations send by themselves: set in each one's Access panel. */
|
|
4823
4954
|
const senders = Object.entries(keep.auto ?? {});
|
|
4824
|
-
$('gitview-auto-where').textContent = `Automatic sending
|
|
4955
|
+
$('gitview-auto-where').textContent = `Automatic sending: set for each conversation, in its Access (Write). ${senders.length ? `Now: ${senders.map(([c, list]) => `${c} (${list.join(', ')})`).join('; ')}.` : 'Now: none.'}`;
|
|
4825
4956
|
$('gitview-origin').hidden = !keep.origin;
|
|
4826
4957
|
if (keep.origin) {
|
|
4827
4958
|
$('gitview-origin-where').textContent = `Its origin, kept up to date by this server, is at ${keep.origin.path} in the agent's machine, read-only, next to the repository. The tool brings it in itself, with no key, by running there:`;
|
|
@@ -5630,6 +5761,7 @@
|
|
|
5630
5761
|
}
|
|
5631
5762
|
function confirmDelete() {
|
|
5632
5763
|
acts.replaceChildren();
|
|
5764
|
+
acts.classList.add('confirm');
|
|
5633
5765
|
const p = document.createElement('p'); p.className = 'sure';
|
|
5634
5766
|
p.textContent = entry.folder ? `Delete the folder "${entry.name}" and everything in it? This cannot be undone.` : `Delete "${entry.name}"? This cannot be undone.`;
|
|
5635
5767
|
const yes = button(entry.folder ? 'Delete the folder' : 'Delete', async () => {
|
|
@@ -5940,13 +6072,17 @@
|
|
|
5940
6072
|
const PREVIEW_MAX = 25 * 1024 * 1024;
|
|
5941
6073
|
const TEXT_MAX = 1024 * 1024;
|
|
5942
6074
|
const PICTURES = { png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp' };
|
|
5943
|
-
const TEXTS = ['txt', 'md', 'csv', 'tsv', 'json', 'log', 'yaml', 'yml', 'toml', 'ini', 'xml', 'html', 'css', 'js', 'mjs', 'ts', 'py', 'sh', 'sql', 'c', 'h', 'go', 'rs', 'java', 'rb', 'php', 'tex', 'eml'];
|
|
6075
|
+
const TEXTS = ['txt', 'md', 'markdown', 'csv', 'tsv', 'json', 'log', 'yaml', 'yml', 'toml', 'ini', 'xml', 'html', 'css', 'js', 'mjs', 'ts', 'py', 'sh', 'sql', 'c', 'h', 'go', 'rs', 'java', 'rb', 'php', 'tex', 'eml'];
|
|
5944
6076
|
const PDF_PAGES = 30;
|
|
6077
|
+
/* Beyond this, a Markdown file is shown as its text: formatting it would hold the page. */
|
|
6078
|
+
const MD_MAX = 512 * 1024;
|
|
5945
6079
|
let shownUrl = null;
|
|
5946
6080
|
/* The file is shown in a WINDOW over the screen, wherever it was asked
|
|
5947
6081
|
from: closing it leaves the terminal, or the list, as it was. */
|
|
5948
6082
|
function closePreview() {
|
|
5949
6083
|
if (shownUrl) { URL.revokeObjectURL(shownUrl); shownUrl = null; }
|
|
6084
|
+
for (const url of mdUrls) URL.revokeObjectURL(url);
|
|
6085
|
+
mdUrls.clear();
|
|
5950
6086
|
editing = null;
|
|
5951
6087
|
delete $('viewer').dataset.editing;
|
|
5952
6088
|
$('preview-body').replaceChildren();
|
|
@@ -6011,6 +6147,142 @@
|
|
|
6011
6147
|
const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range);
|
|
6012
6148
|
return true;
|
|
6013
6149
|
}
|
|
6150
|
+
/* A MARKDOWN FILE, SHOWN FORMATTED, as the chat shows what the tool
|
|
6151
|
+
writes. Parley reads the text into plain data (its markdown()); the
|
|
6152
|
+
page is built from that data element by element, its text as text:
|
|
6153
|
+
never the file as markup. Parley does not export its painter yet: once
|
|
6154
|
+
it does (renderMarkdown, with these same slots), it is used instead of
|
|
6155
|
+
the one here. Slots: picture(src) the address of a picture this
|
|
6156
|
+
preview may show, or null (then its caption is shown); open(href) a
|
|
6157
|
+
function opening a file of the same folder, or null; diagram and
|
|
6158
|
+
highlight as for the chat. Blob addresses made go into `urls`. */
|
|
6159
|
+
const mdUrls = new Set();
|
|
6160
|
+
let mdWords = null;
|
|
6161
|
+
async function markdownPage(text, slots) {
|
|
6162
|
+
const P = await import(new URL('vendor/parley-ui.js', new URL(DEVICE ? '/c/' : '/', location.href)).href);
|
|
6163
|
+
if (!mdWords) mdWords = await readWords().catch(() => ({}));
|
|
6164
|
+
const all = { words: mdWords, urls: mdUrls, ...slots };
|
|
6165
|
+
if (typeof P.renderMarkdown === 'function') return P.renderMarkdown(text, all);
|
|
6166
|
+
return paintMarkdown(P.markdown(text), P.safeLink, all);
|
|
6167
|
+
}
|
|
6168
|
+
function paintMarkdown(data, safeLink, { words, picture, open, diagram, highlight, urls }) {
|
|
6169
|
+
const el = (tag, className, text) => { const e = document.createElement(tag); if (className) e.className = className; if (text !== undefined) e.textContent = text; return e; };
|
|
6170
|
+
const said = (key, fallback) => (typeof words?.[key] === 'string' ? words[key] : fallback);
|
|
6171
|
+
const KINDS = { note: 'Note', tip: 'Tip', important: 'Important', warning: 'Warning', caution: 'Caution' };
|
|
6172
|
+
const BADGES = { ok: 'ok', todo: 'todo', blocked: 'blocked', warn: 'warn' };
|
|
6173
|
+
function inlines(nodes, into) {
|
|
6174
|
+
for (const n of nodes) {
|
|
6175
|
+
if (n.t === 'text') into.append(n.v);
|
|
6176
|
+
else if (n.t === 'br') into.append(el('br'));
|
|
6177
|
+
else if (n.t === 'code') into.append(el('code', '', n.v));
|
|
6178
|
+
else if (n.t === 'em' || n.t === 'strong' || n.t === 'del' || n.t === 'mark') into.append(inlines(n.c, el(n.t === 'del' ? 's' : n.t)));
|
|
6179
|
+
else if (n.t === 'badge') { const b = el('span', 'parley-badge', said(`badge-${n.kind}`, BADGES[n.kind] ?? n.kind)); b.dataset.kind = n.kind; into.append(b); }
|
|
6180
|
+
else if (n.t === 'link') {
|
|
6181
|
+
const href = safeLink(n.href);
|
|
6182
|
+
const go = href ? null : open?.(n.href);
|
|
6183
|
+
if (href) { const a = el('a', 'parley-link'); a.href = href; a.target = '_blank'; a.rel = 'noopener noreferrer nofollow'; a.title = href; into.append(inlines(n.c, a)); }
|
|
6184
|
+
else if (go) { const b = el('button', 'parley-pathlink'); b.type = 'button'; b.title = n.href; b.addEventListener('click', go); into.append(inlines(n.c, b)); }
|
|
6185
|
+
else into.append(inlines(n.c, el('span')));
|
|
6186
|
+
} else if (n.t === 'img') {
|
|
6187
|
+
const url = picture?.(n.src);
|
|
6188
|
+
if (url) { const img = el('img'); img.src = url; img.alt = n.alt || n.src.split('/').pop(); img.loading = 'lazy'; img.decoding = 'async'; into.append(img); }
|
|
6189
|
+
else { const off = el('span', 'parley-noimg', n.alt || n.src.split('/').pop()); off.title = said('not-shown', 'Not shown here'); into.append(off); }
|
|
6190
|
+
}
|
|
6191
|
+
}
|
|
6192
|
+
return into;
|
|
6193
|
+
}
|
|
6194
|
+
function tokens(list, depth) {
|
|
6195
|
+
const out = [];
|
|
6196
|
+
for (const t of list) {
|
|
6197
|
+
if (typeof t === 'string') { out.push(t); continue; }
|
|
6198
|
+
if (!t || typeof t !== 'object' || depth > 12) continue;
|
|
6199
|
+
const span = el('span', 'parley-tok');
|
|
6200
|
+
for (const n of [t.type, ...(Array.isArray(t.alias) ? t.alias : [t.alias])]) if (typeof n === 'string' && /^[a-z][a-z-]{0,30}$/.test(n)) span.classList.add(`parley-tok-${n}`);
|
|
6201
|
+
span.append(...(Array.isArray(t.content) ? tokens(t.content, depth + 1) : [String(t.content ?? '')]));
|
|
6202
|
+
out.push(span);
|
|
6203
|
+
}
|
|
6204
|
+
return out;
|
|
6205
|
+
}
|
|
6206
|
+
function code(b) {
|
|
6207
|
+
const holder = el('div', 'parley-code');
|
|
6208
|
+
const bar = el('div', 'parley-code-bar');
|
|
6209
|
+
const c = el('code', '', b.text);
|
|
6210
|
+
const pre = el('pre'); pre.append(c);
|
|
6211
|
+
const copy = el('button', 'parley-copy', said('copy', 'Copy')); copy.type = 'button';
|
|
6212
|
+
copy.addEventListener('click', () => {
|
|
6213
|
+
const done = () => { copy.textContent = said('copied', 'Copied'); setTimeout(() => { copy.textContent = said('copy', 'Copy'); }, 1500); };
|
|
6214
|
+
try { void navigator.clipboard.writeText(b.text).then(done, () => selectAll(c)); } catch { selectAll(c); }
|
|
6215
|
+
});
|
|
6216
|
+
bar.append(el('span', 'parley-code-lang', b.lang), copy);
|
|
6217
|
+
holder.append(bar, pre);
|
|
6218
|
+
if (highlight && b.lang && b.text.length <= 40_000) Promise.resolve().then(() => highlight(b.text, b.lang)).then((tree) => { if (Array.isArray(tree)) c.replaceChildren(...tokens(tree, 0)); }, () => {});
|
|
6219
|
+
return holder;
|
|
6220
|
+
}
|
|
6221
|
+
function drawing(b) {
|
|
6222
|
+
if (!diagram || b.text.length > 20_000) return code(b);
|
|
6223
|
+
const fig = el('figure', 'parley-diagram');
|
|
6224
|
+
fig.append(el('span', 'parley-diagram-wait', said('diagram', 'Diagram')));
|
|
6225
|
+
Promise.resolve().then(() => diagram(b.text)).then((svg) => {
|
|
6226
|
+
if (typeof svg !== 'string' || !/^\s*(<\?xml[^>]*>\s*)?<svg[\s>]/i.test(svg)) throw new Error('not a drawing');
|
|
6227
|
+
/* A picture runs nothing and loads nothing: the drawing is shown as one. */
|
|
6228
|
+
const url = URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' }));
|
|
6229
|
+
urls?.add(url);
|
|
6230
|
+
const img = el('img'); img.src = url; img.alt = said('diagram', 'Diagram');
|
|
6231
|
+
fig.replaceChildren(img);
|
|
6232
|
+
}).catch(() => fig.replaceWith(code(b)));
|
|
6233
|
+
return fig;
|
|
6234
|
+
}
|
|
6235
|
+
function block(b) {
|
|
6236
|
+
if (b.t === 'p') return inlines(b.c, el('p'));
|
|
6237
|
+
if (b.t === 'h') return inlines(b.c, el(`h${Math.min(6, b.level + 1)}`, `parley-h parley-h${b.level}`));
|
|
6238
|
+
if (b.t === 'hr') return el('hr');
|
|
6239
|
+
if (b.t === 'code') return b.lang === 'mermaid' ? drawing(b) : code(b);
|
|
6240
|
+
if (b.t === 'quote') return blocks(b.c, el('blockquote'));
|
|
6241
|
+
if (b.t === 'alert') {
|
|
6242
|
+
const box = el('div', 'parley-callout'); box.dataset.kind = b.kind; box.setAttribute('role', 'note');
|
|
6243
|
+
box.append(el('p', 'parley-callout-head', said(b.kind, KINDS[b.kind] ?? b.kind)));
|
|
6244
|
+
return blocks(b.c, box);
|
|
6245
|
+
}
|
|
6246
|
+
if (b.t === 'list') {
|
|
6247
|
+
const list = el(b.ordered ? 'ol' : 'ul');
|
|
6248
|
+
if (Number.isInteger(b.start)) list.start = b.start;
|
|
6249
|
+
for (const item of b.items) {
|
|
6250
|
+
const li = el('li');
|
|
6251
|
+
if (item.task !== null) { li.className = 'parley-task'; const box = el('span', 'parley-check', item.task ? '☑' : '☐'); box.dataset.done = String(item.task); li.append(box); }
|
|
6252
|
+
if (item.c.length === 1 && item.c[0].t === 'p') inlines(item.c[0].c, li); else blocks(item.c, li);
|
|
6253
|
+
list.append(li);
|
|
6254
|
+
}
|
|
6255
|
+
return list;
|
|
6256
|
+
}
|
|
6257
|
+
if (b.t === 'table') {
|
|
6258
|
+
const wrap = el('div', 'parley-table'); wrap.tabIndex = 0;
|
|
6259
|
+
const table = el('table'); const head = el('thead'); const tr = el('tr'); const body = el('tbody');
|
|
6260
|
+
b.head.forEach((cell, k) => { const th = el('th'); if (b.align[k]) th.style.textAlign = b.align[k]; tr.append(inlines(cell, th)); });
|
|
6261
|
+
head.append(tr);
|
|
6262
|
+
for (const row of b.rows) { const r = el('tr'); row.forEach((cell, k) => { const td = el('td'); if (b.align[k]) td.style.textAlign = b.align[k]; r.append(inlines(cell, td)); }); body.append(r); }
|
|
6263
|
+
table.append(head, body); wrap.append(table);
|
|
6264
|
+
return wrap;
|
|
6265
|
+
}
|
|
6266
|
+
return el('span');
|
|
6267
|
+
}
|
|
6268
|
+
function blocks(list, into) { for (const b of list) into.append(block(b)); return into; }
|
|
6269
|
+
return blocks(data, el('div', 'parley-md'));
|
|
6270
|
+
}
|
|
6271
|
+
/* A path written in a Markdown file, as a place in the same folder kept
|
|
6272
|
+
here: relative to the file, or absolute under /work or the folder's own
|
|
6273
|
+
/resources/<name>. Never above the top of the folder; anything else: null. */
|
|
6274
|
+
function besideFile(tab, inner, href) {
|
|
6275
|
+
let raw = String(href ?? '').trim().replace(/[?#].*$/, '');
|
|
6276
|
+
if (!raw || /^[a-z][a-z0-9+.-]*:/i.test(raw) || raw.startsWith('//')) return null;
|
|
6277
|
+
try { raw = decodeURIComponent(raw); } catch { return null; }
|
|
6278
|
+
let parts;
|
|
6279
|
+
const top = tab === 'work' ? '/work/' : `/resources/${tab}/`;
|
|
6280
|
+
if (raw.startsWith('/')) { if (!raw.startsWith(top)) return null; parts = raw.slice(top.length).split('/'); }
|
|
6281
|
+
else parts = [...inner.split('/').slice(0, -1), ...raw.split('/')];
|
|
6282
|
+
const out = [];
|
|
6283
|
+
for (const p of parts) { if (p === '' || p === '.') continue; if (p === '..') { if (!out.length) return null; out.pop(); } else out.push(p); }
|
|
6284
|
+
return out.length ? out.join('/') : null;
|
|
6285
|
+
}
|
|
6014
6286
|
/* `tab`, `inner`: its place in a folder kept here. `from`: an address to
|
|
6015
6287
|
read it at instead (a file of the machine's own disk). */
|
|
6016
6288
|
async function preview(tab, inner, name, size, from) {
|
|
@@ -6085,9 +6357,9 @@
|
|
|
6085
6357
|
} catch { body.replaceChildren(); note('This PDF could not be shown here. Download it to open it.'); }
|
|
6086
6358
|
} else {
|
|
6087
6359
|
const text = new TextDecoder('utf-8', { fatal: false }).decode(bytes);
|
|
6088
|
-
const source = () => { const pre = document.createElement('pre'); pre.textContent = text; return pre; };
|
|
6360
|
+
const source = () => { const pre = document.createElement('pre'); pre.className = 'source'; pre.textContent = text; return pre; };
|
|
6089
6361
|
/* Copy: all its text, the source of a page too. Refused, the text is shown and selected. */
|
|
6090
|
-
offerCopy({ text }, { select: () => { if (!body.querySelector('pre')) body.querySelector('button')?.click(); return selectAll(body.querySelector('pre')); } });
|
|
6362
|
+
offerCopy({ text }, { select: () => { if (!body.querySelector('pre.source')) body.querySelector('button')?.click(); return selectAll(body.querySelector('pre.source')); } });
|
|
6091
6363
|
/* A page written by the tool is SHOWN AS A PAGE -- in a frame that is
|
|
6092
6364
|
nobody: no session, no network, nothing of this site (the server
|
|
6093
6365
|
answers it with those rules; see files.mjs). Its source is one
|
|
@@ -6109,6 +6381,38 @@
|
|
|
6109
6381
|
});
|
|
6110
6382
|
body.append(toggle, frame);
|
|
6111
6383
|
note('A page written by the tool, shown in a closed frame: it reaches nothing outside itself. Never type a password into it.');
|
|
6384
|
+
} else if ((kind === 'md' || kind === 'markdown') && text.length <= MD_MAX) {
|
|
6385
|
+
/* Markdown: formatted, its text one tap away (the choice kept on this device). */
|
|
6386
|
+
let page;
|
|
6387
|
+
try {
|
|
6388
|
+
page = await markdownPage(text, {
|
|
6389
|
+
/* Pictures as the thumbnails of Files allow them (the server checks the folder and the bytes); a file of the machine's disk shows none. */
|
|
6390
|
+
picture: (src) => { const p = from ? null : besideFile(tab, inner, src); return p && /\.(png|jpe?g|gif|webp)$/i.test(p) ? `${API}/files/thumb?${new URLSearchParams({ c: current, r: tab, p })}` : null; },
|
|
6391
|
+
open: (href) => { const p = from ? null : besideFile(tab, inner, href); return p ? () => { void preview(tab, p, p.split('/').pop(), 0); } : null; },
|
|
6392
|
+
diagram: drawDiagram, highlight: colourCode,
|
|
6393
|
+
});
|
|
6394
|
+
} catch { page = null; }
|
|
6395
|
+
if ($('viewer').hidden || $('preview-name').textContent !== name) return;
|
|
6396
|
+
if (!page) { body.append(source()); note(''); return; }
|
|
6397
|
+
const formatted = document.createElement('div'); formatted.className = 'parley md-view'; formatted.dataset.theme = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark';
|
|
6398
|
+
formatted.append(page);
|
|
6399
|
+
const raw = source();
|
|
6400
|
+
const switcher = document.createElement('div'); switcher.className = 'md-switch'; switcher.setAttribute('role', 'group'); switcher.setAttribute('aria-label', 'Show');
|
|
6401
|
+
const choice = (label, what) => { const b = document.createElement('button'); b.type = 'button'; b.textContent = label; b.dataset.show = what; b.addEventListener('click', () => show(what, true)); return b; };
|
|
6402
|
+
const asFormatted = choice('Formatted', 'formatted'); const asText = choice('Text', 'text');
|
|
6403
|
+
switcher.append(asFormatted, asText);
|
|
6404
|
+
const show = (what, keep) => {
|
|
6405
|
+
asFormatted.setAttribute('aria-pressed', String(what === 'formatted')); asText.setAttribute('aria-pressed', String(what === 'text'));
|
|
6406
|
+
formatted.dataset.theme = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark';
|
|
6407
|
+
body.replaceChildren(switcher, what === 'text' ? raw : formatted);
|
|
6408
|
+
if (keep) { try { localStorage.setItem('clavarium-md-show', what); } catch { /* a private window: not kept */ } }
|
|
6409
|
+
};
|
|
6410
|
+
let first = 'formatted';
|
|
6411
|
+
try { if (localStorage.getItem('clavarium-md-show') === 'text') first = 'text'; } catch { /* as above */ }
|
|
6412
|
+
show(first, false);
|
|
6413
|
+
/* Refused copy: the text is shown and selected. */
|
|
6414
|
+
offerCopy({ text }, { select: () => { show('text', false); return selectAll(raw); } });
|
|
6415
|
+
note('');
|
|
6112
6416
|
} else { body.append(source()); note(offline && (kind === 'html' || kind === 'htm') ? 'This conversation is offline: its page is shown as text, not run.' : ''); }
|
|
6113
6417
|
}
|
|
6114
6418
|
}
|
|
@@ -6147,7 +6451,7 @@
|
|
|
6147
6451
|
drop.addEventListener('click', () => { editing.saved = editing.area.value; then(); });
|
|
6148
6452
|
const stay = document.createElement('button'); stay.type = 'button'; stay.textContent = 'Keep editing';
|
|
6149
6453
|
stay.addEventListener('click', () => { box.hidden = true; editing.area.focus(); });
|
|
6150
|
-
const row = document.createElement('div'); row.className = 'row'; row.append(
|
|
6454
|
+
const row = document.createElement('div'); row.className = 'action-row'; row.append(stay, drop, save);
|
|
6151
6455
|
box.append(p, row); box.hidden = false;
|
|
6152
6456
|
save.focus();
|
|
6153
6457
|
}
|
|
@@ -6173,7 +6477,7 @@
|
|
|
6173
6477
|
area.className = 'editor'; area.value = read.text; area.spellcheck = false;
|
|
6174
6478
|
area.setAttribute('autocapitalize', 'off'); area.setAttribute('autocomplete', 'off'); area.setAttribute('wrap', 'off');
|
|
6175
6479
|
area.setAttribute('aria-label', `Text of ${name}`);
|
|
6176
|
-
const ask = document.createElement('div'); ask.className = 'edit-ask files-card'; ask.hidden = true; ask.setAttribute('role', 'alertdialog');
|
|
6480
|
+
const ask = document.createElement('div'); ask.className = 'edit-ask files-card callout confirm'; ask.hidden = true; ask.setAttribute('role', 'alertdialog');
|
|
6177
6481
|
const bar = document.createElement('div'); bar.className = 'row edit-bar';
|
|
6178
6482
|
const save = document.createElement('button'); save.type = 'button'; save.className = 'primary'; save.textContent = 'Save'; save.id = 'edit-save';
|
|
6179
6483
|
const cancel = document.createElement('button'); cancel.type = 'button'; cancel.textContent = 'Cancel'; cancel.id = 'edit-cancel';
|
|
@@ -6259,7 +6563,7 @@
|
|
|
6259
6563
|
over.addEventListener('click', () => { void saveEdit('any'); });
|
|
6260
6564
|
const copy = document.createElement('button'); copy.type = 'button'; copy.className = 'primary'; copy.textContent = 'Save mine as a copy';
|
|
6261
6565
|
copy.addEventListener('click', () => { void saveEdit('copy'); });
|
|
6262
|
-
const row = document.createElement('div'); row.className = 'row'; row.append(
|
|
6566
|
+
const row = document.createElement('div'); row.className = 'action-row'; row.append(reload, over, copy);
|
|
6263
6567
|
box.append(p, look, row); box.hidden = false;
|
|
6264
6568
|
copy.focus();
|
|
6265
6569
|
e.tell('not saved: changed meanwhile');
|
|
@@ -6638,7 +6942,8 @@
|
|
|
6638
6942
|
const keep = document.createElement('button'); keep.type = 'button'; keep.textContent = 'Keep';
|
|
6639
6943
|
keep.addEventListener('click', () => { void repaintDevices(); });
|
|
6640
6944
|
sure.addEventListener('click', async () => { await run().catch(() => {}); await repaintDevices(); void refresh(); });
|
|
6641
|
-
|
|
6945
|
+
const ask = document.createElement('span'); ask.className = 'callout bad confirm'; ask.setAttribute('role', 'alertdialog'); ask.append(keep, sure);
|
|
6946
|
+
button.replaceWith(ask); sure.focus();
|
|
6642
6947
|
}
|
|
6643
6948
|
function grantRow(device, g) {
|
|
6644
6949
|
const [type, name] = g.asset.split(':');
|
|
@@ -6707,7 +7012,7 @@
|
|
|
6707
7012
|
if (only && device.grants.length > mine.length) { const rest = document.createElement('p'); rest.className = 'hint'; rest.textContent = `It also has: ${device.grants.filter((g) => g.asset !== only).map((g) => { const [type, what] = g.asset.split(':'); return `${what} (${KIND_WORD[type] ?? type})`; }).join(', ')}.`; given.append(rest); }
|
|
6708
7013
|
const more = document.createElement('button'); more.type = 'button'; more.textContent = '+ Give more';
|
|
6709
7014
|
more.addEventListener('click', () => { void openCompose([], device.id); });
|
|
6710
|
-
const acts = document.createElement('div'); acts.className = 'row device-acts'; acts.append(more, rename, revoke);
|
|
7015
|
+
const acts = document.createElement('div'); acts.className = 'action-row device-acts'; acts.append(more, rename, revoke);
|
|
6711
7016
|
const body = document.createElement('div'); body.className = 'card-body'; body.hidden = shut; body.append(given, acts);
|
|
6712
7017
|
card.append(head, body);
|
|
6713
7018
|
return card;
|
|
@@ -6780,7 +7085,8 @@
|
|
|
6780
7085
|
const keep = document.createElement('button'); keep.type = 'button'; keep.textContent = 'Keep';
|
|
6781
7086
|
keep.addEventListener('click', () => { void paintShareHere(); });
|
|
6782
7087
|
sure.addEventListener('click', async () => { await post(`${API}/devices/${device.id}/take`, { asset }).catch(() => {}); await paintShareHere(); void refresh(); });
|
|
6783
|
-
|
|
7088
|
+
const ask = document.createElement('span'); ask.className = 'callout bad confirm'; ask.setAttribute('role', 'alertdialog'); ask.append(keep, sure);
|
|
7089
|
+
take.replaceWith(ask); sure.focus();
|
|
6784
7090
|
});
|
|
6785
7091
|
row.append(label, right, take); box.append(row);
|
|
6786
7092
|
}
|