clavarium 0.2.176-beta.1 → 0.2.177-beta.1

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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.176-beta.1",
3
+ "version": "0.2.177-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.176-beta.1",
9
+ "version": "0.2.177-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.176-beta.1",
3
+ "version": "0.2.177-beta.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
@@ -87,6 +87,13 @@ export const SETTINGS_WORDS_FR = {
87
87
  'set-as-fold': 'Replier', 'set-as-unfold': 'Déplier', 'set-as-group-open': 'Réglages de {name}', 'set-as-group-gear': 'Donner, renommer, supprimer',
88
88
  'set-as-group-empty': 'Vide : glissez un asset ici', 'set-as-all-grouped': 'Chaque asset est dans un groupe',
89
89
  'set-as-no-groups': 'Créez un groupe, puis glissez-y un asset',
90
+ /* One asset opened (06-11, kit AssetPanel, AccessList): who has it, its kind, what a calendar's levels mean, delete. */
91
+ 'set-as-assets': 'Assets', 'set-acc-title': 'Qui y a accès', 'set-acc-give': 'Donner à…', 'set-acc-also': 'Aussi chez',
92
+ 'set-acc-device': 'Appareil', 'set-acc-what': 'Ce que {who} peut faire avec {name}',
93
+ 'set-acc-nobody': 'Aucune conversation ne l’utilise.', 'set-acc-everyone': 'Chaque conversation l’a.', 'set-acc-noready': 'Aucune conversation n’est prête.',
94
+ 'set-acc-delete': 'Supprimer…', 'set-acc-delete-yes': 'Supprimer',
95
+ 'set-acc-kind-folder': 'Dossier', 'set-acc-kind-git': 'Dépôt', 'set-acc-kind-mailbox': 'Boîte mail', 'set-acc-kind-agenda': 'Calendrier',
96
+ 'set-acc-kind-contacts': 'Contacts', 'set-acc-kind-secret': 'Secret', 'set-acc-kind-list': 'Binder', 'set-acc-kind-acces': 'Accès',
90
97
  /* A room's settings (06-11): each AI's own assets; one right given to each of them. */
91
98
  'set-room-assets': 'Leurs assets', 'set-room-give': '+ Donner…', 'set-room-give-all': 'Donner à toutes ses IA…',
92
99
  'set-room-assets-none': 'Rien encore', 'set-room-give-pick': 'Choisissez un asset', 'set-room-give-go': 'Donner à {n} IA',
package/web/app.js CHANGED
@@ -2193,7 +2193,7 @@
2193
2193
  $(errorId).textContent = error.message; $(errorId).hidden = false;
2194
2194
  if (error.kind === 'confirm-shared') {
2195
2195
  const yes = document.createElement('button'); yes.type = 'button'; yes.className = 'danger attach-shared'; yes.textContent = 'Confirm and attach';
2196
- yes.addEventListener('click', async () => { yes.disabled = true; await attachTo(conversation, name, access, errorId, true); if (errorId === 'panel-error') await paintPanel(); else await paintAssets(); });
2196
+ yes.addEventListener('click', async () => { yes.disabled = true; await attachTo(conversation, name, access, errorId, true); if (errorId === 'panel-error') await paintPanel(); else await repaintAsset(); });
2197
2197
  $(errorId).append(' ', yes);
2198
2198
  }
2199
2199
  }
@@ -3916,9 +3916,9 @@
3916
3916
  : item.target ? 'watch' : item.kind === 'secret' ? 'use' : 'read');
3917
3917
  async function applyMemberGrant(item, conversationName, value) {
3918
3918
  if (item.target) return grantTarget(item.target.id, conversationName, value);
3919
- if (item.kind === 'secret') return handTo(conversationName, item.name, value === 'use', 'assets-error');
3919
+ if (item.kind === 'secret') return handTo(conversationName, item.name, value === 'use', asErrId());
3920
3920
  if (item.kind === 'list') return grantList(item.list.id, conversationName, value);
3921
- return attachTo(conversationName, item.name, value, 'assets-error');
3921
+ return attachTo(conversationName, item.name, value, asErrId());
3922
3922
  }
3923
3923
  function memberCurrent(item, conversationName) {
3924
3924
  const id = `conversation:${conversationName}`;
@@ -4054,15 +4054,6 @@
4054
4054
  remove.append(del, el('p', 'hint', 'The assets stay; only the group is removed.'));
4055
4055
  detail.append(remove);
4056
4056
  }
4057
- /* The top of a detail: "All assets" (a phone), the icon, the name, a badge. */
4058
- function asTitle(item, back) {
4059
- const top = el('div', 'as-title');
4060
- const all = el('button', 'as-link as-back', '‹ Assets'); all.type = 'button'; all.addEventListener('click', () => { if (!nav.close('asset')) back(); });
4061
- const h = el('h2'); h.append(kindIcon(item.kind), el('span', '', item.name));
4062
- if (item.badge) h.append(el('span', `as-badge${item.badgeTone ? ` ${item.badgeTone}` : ''}`, item.badgeLong ?? item.badge));
4063
- top.append(all, h);
4064
- return top;
4065
- }
4066
4057
  const chapter = (title, ...extra) => { const head = el('div', 'as-chapter'); head.append(el('h3', '', title), ...extra); return head; };
4067
4058
  const boxSub = (box) => (!box ? 'mailbox' : box.failure ? box.failure : `${box.messages} message${box.messages === 1 ? '' : 's'}`);
4068
4059
  const gitSub = (r) => (r.from ? `from ${hostOf(r.from)}` : 'repository');
@@ -4092,7 +4083,8 @@
4092
4083
  const send = el('button', 'primary', 'Send...'); send.type = 'button'; send.dataset.act = 'send'; send.hidden = true;
4093
4084
  acts.append(review, send);
4094
4085
  /* In a conversation, its files too, below. */
4095
- if (!place) { const files = el('button', '', 'Files'); files.type = 'button'; files.dataset.act = 'files'; files.addEventListener('click', () => { embedFiles(holder, name); files.disabled = true; }); acts.prepend(files); }
4086
+ /* Its files too, below: in a conversation, through it; in the Assets menu, with the owner's rights. */
4087
+ { const files = el('button', '', 'Files'); files.type = 'button'; files.dataset.act = 'files'; files.addEventListener('click', () => { embedFiles(holder, name, { owner: place }); files.disabled = true; }); acts.prepend(files); }
4096
4088
  const diagram = el('div', 'as-graph'); diagram.append(el('p', 'hint busy', 'Drawing the branches...'));
4097
4089
  holder.append(facts, chapter('Branches', acts), diagram);
4098
4090
  const back = place ? { label: name, go: () => { void paintAssets(); } } : { label: name, go: () => { void paintRoomAssets(); } };
@@ -4552,10 +4544,14 @@
4552
4544
  }
4553
4545
  /* The files of a folder or a mailbox, in a conversation: the Files sheet, moved into the detail. */
4554
4546
  let filesHome = null;
4555
- function embedFiles(holder, name) {
4547
+ /* A folder browsed from the Assets menu ('' : from a conversation), and the asset whose files stay open there on a repaint. */
4548
+ let filesOwner = ''; let filesBrowsing = '';
4549
+ /* `owner`: opened from the Assets menu -- that folder alone, with the owner's own rights (no conversation in between). */
4550
+ function embedFiles(holder, name, { owner = false } = {}) {
4556
4551
  const f = $('files');
4557
4552
  if (!filesHome) filesHome = { parent: f.parentNode, next: f.nextSibling };
4558
4553
  holder.append(f); f.classList.add('embedded');
4554
+ filesOwner = owner ? name : '';
4559
4555
  if (filesOf !== name) { filesOf = name; filesAt = ''; }
4560
4556
  f.hidden = false;
4561
4557
  void paintFiles();
@@ -4563,7 +4559,7 @@
4563
4559
  function unembedFiles() {
4564
4560
  const f = $('files');
4565
4561
  if (!f.classList.contains('embedded') || !filesHome) return;
4566
- f.classList.remove('embedded'); f.hidden = true;
4562
+ f.classList.remove('embedded'); f.hidden = true; filesOwner = '';
4567
4563
  filesHome.parent.insertBefore(f, filesHome.next);
4568
4564
  }
4569
4565
 
@@ -4580,7 +4576,7 @@
4580
4576
  watchTether();
4581
4577
  const c = conversations.find((x) => x.name === current);
4582
4578
  roomSig = JSON.stringify([current, c?.resources, c?.secrets, c?.work]);
4583
- const [all, secrets, boxes, tether] = await Promise.all([getJson('/resources', []), getJson('/secrets', []), getJson('/mailboxes', []), getJson('/tether', {})]);
4579
+ const [all, secrets, boxes, tether, lists] = await Promise.all([getJson('/resources', []), getJson('/secrets', []), getJson('/mailboxes', []), getJson('/tether', {}), binderCall('lists', {}), readDevices()]);
4584
4580
  /* The calls this conversation's agent asked the owner to allow: validated here,
4585
4581
  in the parloir, without leaving for the Assets page. */
4586
4582
  const mineDemandes = (Array.isArray(tether.approvals) ? tether.approvals : []).filter((q) => (q.agent?.id ?? '') === `conversation:${current}`);
@@ -4597,6 +4593,18 @@
4597
4593
  }
4598
4594
  markSecrets(secrets);
4599
4595
  for (const s2 of secrets.filter((x) => x.conversations.includes(current))) items.push({ key: `secret:${s2.name}`, kind: 'secret', name: s2.name, secret: s2, right: { level: 'use' }, ...secretItem(s2, 'name only · used by its agent') });
4596
+ /* WHAT IT WAS GIVEN LIVE AND ITS BINDERS (06-11, assets step 3): a calendar, contacts, a mailbox or an access
4597
+ connected (Tether), its binders -- shown at last, the same rows, each with its right. */
4598
+ const allTargets = Array.isArray(tether.targets) ? tether.targets : [];
4599
+ for (const tgt of allTargets) {
4600
+ const level = tgt.grants?.[`conversation:${current}`]?.level;
4601
+ if (!level || level === 'none') continue;
4602
+ const acct = tetherAccount(tgt.id);
4603
+ const siblings = allTargets.filter((o) => o.id !== tgt.id && tetherAccount(o.id) === acct).map((o) => connexionSub(o.kind));
4604
+ items.push({ key: `connexion:${tgt.id}`, kind: tetherCat(tgt.kind), name: tgt.title, target: tgt, siblings, live: true, right: { key: 'connexion', value: level }, sub: connexionSub(tgt.kind) });
4605
+ }
4606
+ const givenLists = lists?.ok && Array.isArray(lists.data) ? lists.data.filter((l) => !l.archived && l.grants?.[`conversation:${current}`]) : [];
4607
+ for (const l of givenLists) items.push({ key: `list:${l.id}`, kind: 'list', name: l.title, list: l, right: { key: 'list', value: l.grants[`conversation:${current}`] }, sub: `${l.count} card${l.count === 1 ? '' : 's'}` });
4600
4608
  /* TO SEND, above them all, once it has a repository: every one of them on one screen. */
4601
4609
  const gits = items.filter((i) => i.kind === 'git').map((i) => i.name);
4602
4610
  const outbox = gits.length ? { key: 'send:all', kind: 'send', name: 'To send', sub: 'every repository, reviewed and sent at once' } : null;
@@ -4617,30 +4625,27 @@
4617
4625
  if (c?.work === 'disk') $('cassets-rows').append(el('p', 'hint as-disk', 'Its work is on the disk of its machine: nothing of it is kept here.'));
4618
4626
  const detail = $('cassets-detail');
4619
4627
  if (!chosen) { unembedFiles(); detail.replaceChildren(); if (items.length) detail.append(noAssetChosen()); return; }
4620
- const keepFiles = (chosen.kind === 'folder' || chosen.kind === 'mailbox') && $('files').classList.contains('embedded') && detail.contains($('files')) && detail.dataset.asset === chosen.key;
4628
+ /* The same folder still shown, nothing changed in who has it: only its files are read again (no blink). */
4629
+ const sig = JSON.stringify([chosen.key, chosen.own ? '' : chosen.kind === 'send' || chosen.kind === 'demandes' ? waitingCount : accessHolders(chosen)]);
4630
+ const keepFiles = (chosen.kind === 'folder' || chosen.kind === 'mailbox') && !chosen.target && $('files').classList.contains('embedded') && detail.contains($('files')) && detail.dataset.asset === chosen.key && detail.dataset.sig === sig;
4621
4631
  if (!keepFiles) { unembedFiles(); detail.replaceChildren(); }
4622
- detail.dataset.asset = chosen.key;
4632
+ detail.dataset.asset = chosen.key; detail.dataset.sig = sig;
4623
4633
  const back = () => { roomPick = ''; void paintRoomAssets(); };
4624
4634
  if (keepFiles) { void paintFiles(); return; }
4625
- detail.append(asTitle(chosen, back));
4626
- if (chosen.kind === 'demandes') {
4627
- for (const j of mineJobs) detail.append(jobCard(j, () => paintRoomAssets()));
4628
- if (mineDemandes.length) {
4629
- detail.append(el('p', 'hint', 'Its agent asked you to allow these Tether calls. Accept, and it runs; refuse, and it is told so.'));
4630
- detail.append(demandesList(mineDemandes, { withWho: false, after: () => paintRoomAssets() }));
4631
- }
4632
- } else if (chosen.kind === 'folder' || chosen.kind === 'mailbox') {
4633
- if (chosen.kind === 'mailbox' && !chosen.target) detail.append(el('p', chosen.box?.failure ? 'error' : 'hint', boxSub(chosen.box)));
4634
- embedFiles(detail, chosen.name);
4635
- } else if (chosen.kind === 'send') await sendDetail(detail, gits);
4636
- else if (chosen.kind === 'git') await gitDetail(detail, chosen.name, { others: gits.length > 1 });
4637
- else {
4638
- if (chosen.secret.expires) detail.append(secretLine(chosen.secret, 'not given to its tool'));
4639
- detail.append(el('p', 'hint', 'Handed to its tool as a variable and a file, the next time it starts. Its value is never shown.'), chapter('Used by'));
4640
- const list = el('div', 'as-chips');
4641
- for (const who of chosen.secret.conversations) list.append(el('span', 'as-chip', shownName(conversations.find((x) => x.name === who)) || who));
4642
- detail.append(list);
4635
+ if (chosen.kind === 'demandes' || chosen.kind === 'send') {
4636
+ /* What waits (To send, Demandes): the same head, its own content. */
4637
+ const body = el('div', 'as-waits');
4638
+ detail.append(KIT.AssetPanel({ key: chosen.key, kind: chosen.kind, name: chosen.name, sub: chosen.sub }, { back: { onBack: () => { if (!nav.close('asset')) back(); } }, parts: [body] }));
4639
+ if (chosen.kind === 'demandes') {
4640
+ for (const j of mineJobs) body.append(jobCard(j, () => paintRoomAssets()));
4641
+ if (mineDemandes.length) {
4642
+ body.append(el('p', 'hint', 'Its agent asked you to allow these Tether calls. Accept, and it runs; refuse, and it is told so.'));
4643
+ body.append(demandesList(mineDemandes, { withWho: false, after: () => paintRoomAssets() }));
4644
+ }
4645
+ } else await sendDetail(body, gits);
4646
+ return;
4643
4647
  }
4648
+ await assetPanel(detail, chosen, { from: current, back, tether, gits });
4644
4649
  }
4645
4650
  /* One asset opened: a step (another one opened takes its place); Back, the list. */
4646
4651
  const assetStep = () => { if (nav.last(['asset']) < 0) nav.push('asset', ({ quiet }) => { roomPick = ''; if (!quiet && assetsShown) void paintRoomAssets(); }); };
@@ -4741,9 +4746,9 @@
4741
4746
  /* A list given to a conversation, or taken back: a grant of Binder's. */
4742
4747
  const givenTo = (l) => Object.keys(l.grants ?? {}).filter((id) => id.startsWith('conversation:'));
4743
4748
  async function grantList(list, name, value) {
4744
- $('assets-error').hidden = true;
4749
+ $(asErrId()).hidden = true;
4745
4750
  const done = await binderCall('grant', { list, to: `conversation:${name}`, access: value === 'none' ? null : value });
4746
- if (!done.ok) { $('assets-error').textContent = done.text; $('assets-error').hidden = false; }
4751
+ if (!done.ok) sayAsErr(new Error(done.text));
4747
4752
  await refresh();
4748
4753
  }
4749
4754
  /* The plain word for a Tether target's kind, in a Connexion's sub-line. */
@@ -4751,18 +4756,18 @@
4751
4756
  const connexionSub = (kind) => CONNEXION_SUB[kind] ?? kind;
4752
4757
  /* Give a Tether target to a conversation at a level, or take it back (none). */
4753
4758
  async function grantTarget(id, name, level) {
4754
- $('assets-error').hidden = true;
4759
+ $(asErrId()).hidden = true;
4755
4760
  try { await post(`${API}/tether/level`, { target: id, agent: `conversation:${name}`, level }); }
4756
- catch (error) { $('assets-error').textContent = error.message; $('assets-error').hidden = false; }
4761
+ catch (error) { sayAsErr(error); }
4757
4762
  await refresh();
4758
4763
  }
4759
4764
  /* Accept or refuse a Tether call that is waiting for a person. `after` repaints the
4760
4765
  surface the row sits in (the Assets page by default; the room passes its own). */
4761
4766
  async function decideTether(id, decision, after) {
4762
- $('assets-error').hidden = true;
4767
+ $(asErrId()).hidden = true;
4763
4768
  try { await post(`${API}/tether/decide`, { id, decision }); }
4764
- catch (error) { $('assets-error').textContent = error.message; $('assets-error').hidden = false; }
4765
- if (after) await after(); else await paintAssets();
4769
+ catch (error) { sayAsErr(error); }
4770
+ if (after) await after(); else await repaintAsset();
4766
4771
  }
4767
4772
  /* Every call waiting for the owner, on one surface. `withWho`: name who asks. */
4768
4773
  /* A JOB: a call the owner approved that only this browser can do -- a device to flash
@@ -4928,100 +4933,54 @@
4928
4933
  }
4929
4934
  /* A Tether target given from Attach: Read watches, Write proposes (asks before each action). */
4930
4935
  const targetLevel = (level) => (level === 'write' ? 'propose' : 'watch');
4931
- let assetsPainting = 0;
4932
- async function paintAssets() {
4933
- if (place !== 'assets' || DEVICE) return;
4934
- watchTether();
4935
- const mine = ++assetsPainting;
4936
- const [all, boxes, secrets, keys, lists, tether, assetGroups] = await Promise.all([getJson('/resources', []), getJson('/mailboxes', []), getJson('/secrets', []), getJson('/git-keys', []), binderCall('lists', {}), getJson('/tether', {}), getJson('/asset-groups', []), readDevices()]);
4937
- /* A later paint asked meanwhile: it draws, with what it read (never this older reading over it). */
4938
- if (place !== 'assets' || mine !== assetsPainting) return;
4939
- paintKeys(keys);
4940
- markSecrets(secrets);
4941
- const items = [];
4942
- for (const r of all) {
4943
- const kind = kindOf(r);
4944
- const box = kind === 'mailbox' ? boxes.find((m) => m.name === r.name) : undefined;
4945
- items.push({ key: `${kind}:${r.name}`, kind, name: r.name, resource: r, box, ...usedBy(Object.keys(r.attachments ?? {}), `${kind}:${r.name}`),
4946
- sub: kind === 'git' ? `${gitSub(r)}${viaText(r.via)}` : kind === 'mailbox' ? boxSub(box) : 'folder', tone: box?.failure ? 'bad' : '' });
4947
- }
4948
- for (const s2 of secrets) items.push({ key: `secret:${s2.name}`, kind: 'secret', name: s2.name, secret: s2, ...usedBy(s2.conversations, `secret:${s2.name}`), ...secretItem(s2, 'name only') });
4949
- /* Tether targets ("Connexions"): a mailbox, calendar or address book connected
4950
- by token, given to a conversation at a level. The token lives on the server. */
4951
- const allTargets = Array.isArray(tether.targets) ? tether.targets : [];
4952
- for (const tgt of allTargets) {
4953
- const users = Object.keys(tgt.grants ?? {}).filter((id) => id.startsWith('conversation:')).map((id) => id.slice('conversation:'.length));
4954
- const acct = tetherAccount(tgt.id);
4955
- const siblings = allTargets.filter((o) => o.id !== tgt.id && tetherAccount(o.id) === acct).map((o) => connexionSub(o.kind));
4956
- items.push({ key: `connexion:${tgt.id}`, kind: tetherCat(tgt.kind), name: tgt.title, target: tgt, siblings, live: true, ...usedBy(users, `connexion:${tgt.id}`),
4957
- sub: siblings.length ? `linked: ${siblings.join(', ')}` : connexionSub(tgt.kind) });
4958
- }
4959
- /* Binder's lists: given to a conversation (read, write) in Binder itself. */
4960
- const shownLists = lists.ok && Array.isArray(lists.data) ? lists.data.filter((l) => !l.archived) : [];
4961
- listsSig = binderSig(lists.data);
4962
- for (const l of shownLists) {
4963
- items.push({ key: `list:${l.id}`, kind: 'list', name: l.title, list: l, ...usedBy(givenTo(l).map((id) => id.slice('conversation:'.length)), `list:${l.id}`), sub: `${l.count} card${l.count === 1 ? '' : 's'}` });
4964
- }
4965
- const chosen = assetsAdding ? null : items.find((i) => i.key === assetOpen) ?? null;
4966
- if (justMade && !justMade.to && justMade.key !== chosen?.key) justMade = null;
4967
- /* A group can be the open thing too (its own detail: give it, rename it). */
4968
- const chosenGroup = !assetsAdding && !chosen && assetOpen.startsWith('group:') ? assetGroups.find((g) => `group:${g.id}` === assetOpen) ?? null : null;
4969
- /* Every call waiting for the owner, across all the connexions, gathered in one place
4970
- (in a connexion's own detail they still show, but only that one's). */
4971
- const allApprovals = Array.isArray(tether.approvals) ? tether.approvals : [];
4972
- const onDemandes = !assetsAdding && !chosen && !chosenGroup && assetOpen === 'demandes:all';
4973
- $('assets-as').dataset.open = chosen || chosenGroup || assetsAdding || onDemandes ? 'detail' : 'list';
4974
- const choose = (key) => { placeAssetStep(); if (key !== assetOpen) { groupGiveShow.clear(); clearAssetDetail(); } assetOpen = key; assetsAdding = ''; remoteEditing = false; remember(); void paintAssets(); };
4975
- /* THE ONE LIST (kit AssetList), scope all: groups by default once one exists; who has each on its right. */
4976
- const model = KIT.assetListModel({ items: items.map(cardOf), groups: assetGroups, scope: 'all', by: assetsBy, query: assetsQuery, folded: [...groupsFolded], kinds: ASSET_KINDS });
4977
- paintAssetsView(model.view);
4978
- /* Above them all, once something waits: the owner reaches every call from here, not only by opening the
4979
- right connexion. Then, in the view by group, "+ New group". */
4980
- const pinned = [];
4981
- if (allApprovals.length && !assetsQuery) pinned.push(pinnedCard({ key: 'demandes:all', kind: 'demandes', name: 'Demandes', sub: `${allApprovals.length} waiting for you`, count: allApprovals.length }, { chosen: onDemandes ? 'demandes:all' : '', onOpen: choose, extra: 'demande-entry' }));
4982
- if (model.view === 'group') pinned.push(newGroupBar());
4983
- paintAssetList($('assets-rows'), model, { chosen: chosen?.key ?? (chosenGroup ? `group:${chosenGroup.id}` : onDemandes ? 'demandes:all' : ''), onOpen: choose, pinned,
4984
- onFold: (id) => { if (groupsFolded.has(id)) groupsFolded.delete(id); else groupsFolded.add(id); keepGroupsFolded(); void paintAssets(); },
4985
- onGroup: (id) => choose(`group:${id}`), noMatch: 'Nothing by that name.' });
4986
- if (model.view === 'group') dragToGroups($('assets-rows'));
4987
- const detail = clearAssetDetail();
4988
- const back = () => { assetOpen = ''; assetsAdding = ''; remember(); void paintAssets(); };
4989
- if (assetsAdding) {
4990
- /* The New asset box: from the map's "+" of Assets, which kind first ("<" goes back to the map);
4991
- from "+ New" of the list, which kind first too ("<" Assets). */
4992
- const out = assetsFromMap ? el('button', 'as-link', '‹ Access') : el('button', 'as-link as-back', '‹ Assets'); out.type = 'button';
4993
- out.addEventListener('click', () => { if (!nav.close(assetsFromMap ? 'compose' : 'asset')) back(); });
4994
- const kind = assetsAdding === 'choose' ? '' : assetsAdding;
4995
- detail.append(out, newAssetBox({ kind, onKind: (k) => { assetsAdding = k; void paintAssets(); }, boxHost: { where: '', repaint: () => { void paintAssets(); }, close: back } }));
4996
- if (kind) focusFirst(detail);
4997
- return;
4936
+ /* ONE ASSET OPENED (06-11, assets step 3): the same panel (kit AssetPanel, AccessList) in the Assets menu and in a
4937
+ conversation's tab. Seen from the menu (`from` ''), the asset itself is changed there too: its group, its name, its
4938
+ value, its settings, deleted. Seen from a conversation, what it is, who has it (its own row first, then "Also
4939
+ with"), what is in it (its files at once), and "Open in Assets" for the rest. */
4940
+ const asErrId = () => (place === 'assets' ? 'assets-error' : 'cassets-error');
4941
+ const sayAsErr = (error) => { const e = $(asErrId()); if (e) { e.textContent = error.message; e.hidden = false; } };
4942
+ const repaintAsset = () => (place === 'assets' ? paintAssets() : paintRoomAssets());
4943
+ /* Who has it: every conversation (the ready ones offered, any other that has it kept), then the devices given it. */
4944
+ function accessHolders(chosen) {
4945
+ const rows = [];
4946
+ for (const c of conversations) {
4947
+ const value = memberCurrent(chosen, c.name);
4948
+ if (c.phase !== 'ready' && ['none', 'off'].includes(value)) continue;
4949
+ rows.push({ id: `conversation:${c.name}`, name: shownName(c) || c.name, sub: c.toolLabel ?? '', value, ready: c.phase === 'ready' });
4998
4950
  }
4999
- if (chosenGroup) { groupDetail(detail, chosenGroup, items, back); return; }
5000
- if (onDemandes) {
5001
- detail.append(asTitle({ kind: 'send', name: 'Demandes', badge: String(allApprovals.length), badgeTone: 'count' }, back));
5002
- detail.append(el('p', 'hint', 'Each is a Tether call its agent asked you to allow. Accept, and it runs; refuse, and it is told so.'));
5003
- if (allApprovals.length) detail.append(demandesList(allApprovals, { withWho: true, after: () => paintAssets() }));
5004
- else detail.append(el('p', 'hint', 'Nothing is waiting now.'));
5005
- return;
4951
+ if (!chosen.target && ['folder', 'git', 'mailbox'].includes(chosen.kind)) {
4952
+ for (const d of sharedDevices) { const g = (d.grants ?? []).find((x) => x.asset === chosen.key); if (g) rows.push({ id: `device:${d.id}`, name: d.label ?? d.name ?? d.id, value: g.rights }); }
5006
4953
  }
5007
- if (!chosen) { if (items.length) detail.append(noAssetChosen()); return; }
5008
- /* Just made here: the box's ending above it -- Create another, or Done. */
5009
- if (justMade && !justMade.to && justMade.key === chosen.key) {
5010
- const made = justMade;
5011
- detail.append(newAssetBox({ kind: made.kind, made: { said: uiSaid('set-na-made', '{name} created', { name: made.name }), note: made.note },
5012
- onAnother: () => { justMade = null; placeAssetStep(); assetsAdding = made.kind || 'choose'; void paintAssets(); },
5013
- onDone: () => { justMade = null; void paintAssets(); } }));
5014
- }
5015
- detail.append(asTitle(chosen, back));
5016
- detail.append(groupPicker(chosen, assetGroups));
5017
- const ready = conversations.filter((c) => c.phase === 'ready');
4954
+ return rows;
4955
+ }
4956
+ async function setAccess(chosen, row, level, stored) {
4957
+ $(asErrId()).hidden = true;
4958
+ try {
4959
+ if (row.holder === 'device') {
4960
+ const id = String(row.id).slice('device:'.length);
4961
+ if (stored) await post(`${API}/devices/${id}/give`, { asset: chosen.key, rights: stored });
4962
+ else await post(`${API}/devices/${id}/take`, { asset: chosen.key });
4963
+ await readDevices();
4964
+ } else await applyMemberGrant(chosen, String(row.id).slice('conversation:'.length), stored ?? level);
4965
+ } catch (error) { sayAsErr(error); return false; }
4966
+ await repaintAsset();
4967
+ return true;
4968
+ }
4969
+ /* `detail`: where it is drawn. `from`: the conversation it is seen from ('' : the menu). `back`: the way back (a phone).
4970
+ `tether`, `groups`: as the page read them. `gits`: the conversation's repositories (To send, beside). */
4971
+ async function assetPanel(detail, chosen, { from = '', back, tether = {}, groups = [], gits = [] } = {}) {
4972
+ const inMenu = !from;
5018
4973
  const r = chosen.resource;
5019
- /* State, in a line. */
5020
- if (chosen.kind === 'mailbox' && !chosen.target) detail.append(el('p', chosen.box?.failure ? 'error' : 'hint', boxSub(chosen.box)));
4974
+ const parts = []; const foot = [];
4975
+ const t = chosen.target;
4976
+ const copyBox = (chosen.kind === 'mailbox' || chosen.kind === 'folder') && !t;
4977
+ /* WHAT IT IS. */
4978
+ if (chosen.kind === 'mailbox' && !t) parts.push(el('p', chosen.box?.failure ? 'error' : 'hint', boxSub(chosen.box)));
4979
+ if (inMenu && groups) parts.push(groupPicker(chosen, groups));
5021
4980
  /* ACTIONS TOO (02-11): a mailbox copied as files is read only; the same mailbox, connected live, can
5022
4981
  send, reply, move, flag -- within the rights given. Made here with its address and password (they
5023
4982
  stay on the server); only its sending server is asked, found from the address when known. */
5024
- if (chosen.kind === 'mailbox' && !chosen.target && chosen.box && !chosen.box.provider) {
4983
+ if (inMenu && chosen.kind === 'mailbox' && !t && chosen.box && !chosen.box.provider) {
5025
4984
  const live = el('div', 'as-live');
5026
4985
  const go = el('button', '', 'Also allow actions (send, move…)'); go.type = 'button';
5027
4986
  live.append(el('p', 'hint', 'Read only here. Connected live too, an agent can send, reply, move or flag its mail, each within the rights you give.'), go);
@@ -5040,24 +4999,23 @@
5040
4999
  email.addEventListener('change', () => void guess());
5041
5000
  make.addEventListener('click', async () => {
5042
5001
  make.disabled = true; make.textContent = 'Trying it…'; said.hidden = true;
5043
- try { await post(`${API}/mailboxes/${encodeURIComponent(box.name)}/live`, { email: email.value.trim(), smtp: smtp.value.trim() }); void paintAssets(); }
5002
+ try { await post(`${API}/mailboxes/${encodeURIComponent(box.name)}/live`, { email: email.value.trim(), smtp: smtp.value.trim() }); void repaintAsset(); }
5044
5003
  catch (error) { said.textContent = error.message; said.hidden = false; make.disabled = false; make.textContent = 'Connect'; }
5045
5004
  });
5046
5005
  focusField(smtp.value ? make : smtp);
5047
5006
  });
5048
- detail.append(live);
5007
+ parts.push(live);
5049
5008
  }
5050
5009
  /* A live link: what it is, and that it is associated with the same account's others. */
5051
- if (chosen.target) {
5052
- const t = chosen.target;
5053
- detail.append(el('p', 'hint', ['live', connexionSub(t.kind), t.config?.user].filter(Boolean).join(' · ')));
5010
+ if (t) {
5011
+ parts.push(el('p', 'hint', ['live', connexionSub(t.kind), t.config?.user].filter(Boolean).join(' · ')));
5054
5012
  /* The account's real permissions, read from the token (server-side) --
5055
5013
  shown here so they can be checked at any time, not only at connection.
5056
5014
  "Re-check" reads them live, to catch a permission removed since. */
5057
- if (['google', 'microsoft'].includes(t.config?.provider)) {
5015
+ if (inMenu && ['google', 'microsoft'].includes(t.config?.provider)) {
5058
5016
  const KINDS3 = ['mail', 'calendar', 'contacts'];
5059
5017
  const perms = el('div', 'as-perms');
5060
- detail.append(perms);
5018
+ parts.push(perms);
5061
5019
  const draw = (authorized) => {
5062
5020
  perms.replaceChildren();
5063
5021
  if (Array.isArray(authorized)) {
@@ -5070,7 +5028,7 @@
5070
5028
  btn.type = 'button';
5071
5029
  btn.addEventListener('click', async () => {
5072
5030
  btn.disabled = true; btn.textContent = 'Checking…';
5073
- try { const r = await post(`${API}/accounts/verify`, { id: t.id }); draw(r.authorized); }
5031
+ try { const got = await post(`${API}/accounts/verify`, { id: t.id }); draw(got.authorized); }
5074
5032
  catch (e) { perms.append(el('p', 'error', e.message)); btn.disabled = false; btn.textContent = 'Re-check'; }
5075
5033
  });
5076
5034
  perms.append(btn);
@@ -5078,7 +5036,7 @@
5078
5036
  draw(Array.isArray(t.config?.authorizedKinds) ? t.config.authorizedKinds : null);
5079
5037
  }
5080
5038
  /* A mailbox: its signature, in Markdown, added under what the agent sends. */
5081
- if (t.kind === 'mail') {
5039
+ if (inMenu && t.kind === 'mail') {
5082
5040
  const box = el('div', 'as-signature');
5083
5041
  const lab = el('label', '', 'Signature'); lab.htmlFor = `sig-${t.id}`;
5084
5042
  const ta = document.createElement('textarea'); ta.id = `sig-${t.id}`; ta.rows = 3; ta.value = t.config?.signature ?? ''; ta.placeholder = 'Added under every mail the agent sends from this mailbox (Markdown: **bold**, links…)';
@@ -5092,99 +5050,107 @@
5092
5050
  });
5093
5051
  const row = el('div', 'row'); row.append(save, said);
5094
5052
  box.append(lab, ta, row);
5095
- detail.append(box);
5053
+ parts.push(box);
5096
5054
  }
5097
5055
  if (chosen.siblings?.length) {
5098
5056
  const a = el('p', 'as-assoc hint');
5099
5057
  a.append(el('b', '', 'Linked'), document.createTextNode(` to the same account: ${chosen.siblings.join(', ')}. They share the account's sign-in (kept on the server); rights are given separately.`));
5100
- detail.append(a);
5058
+ parts.push(a);
5101
5059
  }
5102
5060
  }
5103
5061
  if (chosen.kind === 'secret') {
5104
- /* Renamed: its value and the conversations it is handed to go with it. */
5105
- const form = el('form', 'set-row secret-rename'); form.autocomplete = 'off';
5106
- 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');
5107
- const go = el('button', '', 'Rename'); go.type = 'submit';
5108
- const what = el('div', 'set-what'); what.append(el('span', '', 'Name'), el('small', '', 'Applies at next start'));
5109
- const control = el('div', 'set-control'); control.append(name, go);
5110
- form.append(what, control);
5111
- form.addEventListener('submit', async (event) => {
5112
- event.preventDefault();
5113
- $('assets-error').hidden = true;
5114
- try { const done = await post(`${API}/secrets/${chosen.name}/rename`, { name: name.value.trim() }); assetOpen = `secret:${done.name}`; }
5115
- catch (error) { $('assets-error').textContent = error.message; $('assets-error').hidden = false; }
5116
- await paintAssets();
5117
- });
5118
- detail.append(secretLine(chosen.secret, 'not given to machines'));
5119
- const replace = secretReplace(chosen);
5120
- const box = el('div', 'set-rows as-block'); box.append(form, ...replace.rows);
5121
- detail.append(box, ...replace.card);
5122
- }
5123
- /* Used by: each conversation that has it, what it may do; "+" offers the others. */
5124
- const options = chosen.target ? [['none', 'Off'], ['watch', 'Watch'], ['propose', 'Propose'], ['frame', 'Frame'], ['free', 'Free']]
5125
- : chosen.kind === 'secret' ? [['off', 'Off'], ['use', 'Use']] : chosen.kind === 'mailbox' ? [['none', 'Off'], ['read', 'Read']]
5126
- : [['none', 'Off'], ['read', 'Read'], ['write', 'Write']];
5127
- const has = (c) => (chosen.target ? chosen.target.grants?.[`conversation:${c.name}`]?.level ?? 'none'
5128
- : chosen.kind === 'secret' ? (chosen.secret.conversations.includes(c.name) ? 'use' : 'off') : chosen.kind === 'list' ? chosen.list.grants?.[`conversation:${c.name}`] ?? 'none'
5129
- : r.attachments?.[c.name] ?? 'none');
5130
- const using = ready.filter((c) => !['none', 'off'].includes(has(c)));
5131
- const others = ready.filter((c) => ['none', 'off'].includes(has(c)));
5132
- const users = el('div', 'as-users');
5133
- const picker = el('div', 'as-users as-picker'); picker.hidden = true;
5134
- const row = (c) => {
5135
- const line = el('div', 'given-row'); line.dataset.conversation = c.name;
5136
- line.append(el('span', '', shownName(c)), modes(options, has(c), async (value) => {
5137
- if (chosen.target) await grantTarget(chosen.target.id, c.name, value);
5138
- else if (chosen.kind === 'secret') await handTo(c.name, chosen.name, value === 'use', 'assets-error');
5139
- else if (chosen.kind === 'list') await grantList(chosen.list.id, c.name, value);
5140
- else await attachTo(c.name, chosen.name, value, 'assets-error');
5141
- await paintAssets();
5142
- }, `What ${c.name} may do with ${chosen.name}`));
5143
- return line;
5144
- };
5145
- for (const c of using) users.append(row(c));
5146
- if (using.length === 0) users.append(el('p', 'hint', 'No conversation uses it.'));
5147
- for (const c of others) picker.append(row(c));
5148
- if (others.length === 0) picker.append(el('p', 'hint', ready.length ? 'Every conversation has it.' : 'No conversation is ready.'));
5149
- detail.append(chapter('Used by', roundPlus('Give it to a conversation', () => { picker.hidden = !picker.hidden; })), users, picker);
5062
+ if (inMenu) {
5063
+ /* Renamed: its value and the conversations it is handed to go with it. */
5064
+ const form = el('form', 'set-row secret-rename'); form.autocomplete = 'off';
5065
+ 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');
5066
+ const go = el('button', '', 'Rename'); go.type = 'submit';
5067
+ const what = el('div', 'set-what'); what.append(el('span', '', 'Name'), el('small', '', 'Applies at next start'));
5068
+ const control = el('div', 'set-control'); control.append(name, go);
5069
+ form.append(what, control);
5070
+ form.addEventListener('submit', async (event) => {
5071
+ event.preventDefault();
5072
+ $('assets-error').hidden = true;
5073
+ try { const done = await post(`${API}/secrets/${chosen.name}/rename`, { name: name.value.trim() }); assetOpen = `secret:${done.name}`; }
5074
+ catch (error) { $('assets-error').textContent = error.message; $('assets-error').hidden = false; }
5075
+ await paintAssets();
5076
+ });
5077
+ parts.push(secretLine(chosen.secret, 'not given to machines'));
5078
+ const replace = secretReplace(chosen);
5079
+ const box = el('div', 'set-rows as-block'); box.append(form, ...replace.rows);
5080
+ parts.push(box, ...replace.card);
5081
+ } else {
5082
+ if (chosen.secret.expires) parts.push(secretLine(chosen.secret, 'not given to its tool'));
5083
+ parts.push(el('p', 'hint', 'Handed to its tool as a variable and a file, the next time it starts. Its value is never shown.'));
5084
+ }
5085
+ }
5086
+ /* WHO HAS IT: a row per conversation and device, its right set in place ("None" first). */
5087
+ const own = chosen.own;
5088
+ const model = own ? null : KIT.accessModel({ key: KIT.rightsKey(chosen), holders: accessHolders(chosen), from: from ? `conversation:${from}` : '' });
5089
+ if (model) {
5090
+ /* Given to a device: from here too (the map shows who has it). */
5091
+ const share = !t && ['folder', 'git', 'mailbox'].includes(chosen.kind) ? el('button', 'as-link', 'Share with a device...') : null;
5092
+ if (share) { share.type = 'button'; share.addEventListener('click', () => { void openCompose([[chosen.key, 'r']]); }); }
5093
+ parts.push(KIT.AccessList(model, { key: KIT.rightsKey(chosen), kind: chosen.kind, name: chosen.name, onChange: (row, level, stored) => setAccess(chosen, row, level, stored), actions: [share] }));
5094
+ }
5095
+ /* WHAT IS IN IT. */
5096
+ if (copyBox) {
5097
+ /* Its files: at once in a conversation; in the menu, a button opens them in the panel (the files sheet, moved in). */
5098
+ const holder = el('div', 'as-files');
5099
+ if (inMenu) {
5100
+ const browse = el('button', '', 'Browse'); browse.type = 'button'; browse.dataset.act = 'files';
5101
+ browse.addEventListener('click', () => { browse.disabled = true; filesBrowsing = chosen.key; embedFiles(holder, chosen.name, { owner: true }); });
5102
+ parts.push({ title: 'Files', extra: [browse], body: [holder], cls: 'as-files-menu' });
5103
+ if (filesBrowsing === chosen.key) queueMicrotask(() => browse.click());
5104
+ } else parts.push({ body: [holder], cls: 'as-files-part' });
5105
+ if (!inMenu) queueMicrotask(() => embedFiles(holder, chosen.name));
5106
+ }
5150
5107
  if (chosen.kind === 'list') {
5151
- /* The list itself, Binder's screen, here: that list alone. */
5152
- const open = el('button', '', listOpen === chosen.key ? 'Close' : 'Open'); open.type = 'button'; open.dataset.act = 'open-list';
5153
- const holder = el('div', 'binder-holder as-binder');
5154
- open.addEventListener('click', () => { listOpen = listOpen === chosen.key ? '' : chosen.key; void paintAssets(); });
5155
- detail.append(chapter('Cards', open), holder);
5156
- const id = chosen.list.id;
5157
- if (listOpen === chosen.key) {
5158
- /* Drawn again (the lists changed): on the card it showed, if it showed one; after a reload, the card of the address. */
5159
- const was = assetsView?.place;
5160
- const at = assetsAt?.list === id ? assetsAt : was?.list === id && was.page === 'card' ? { list: id, card: was.card } : null;
5161
- assetsAt = null;
5162
- void mountBinder(holder, (l) => l.id === id, { place: at, steps: assetsSteps, onLists: (data) => { if (place === 'assets' && binderSig(data) !== listsSig) void paintAssets(); } })
5163
- .then((view) => { if (view) assetsView = view; });
5108
+ if (inMenu) {
5109
+ /* The list itself, Binder's screen, here: that list alone. */
5110
+ const open = el('button', '', listOpen === chosen.key ? 'Close' : 'Open'); open.type = 'button'; open.dataset.act = 'open-list';
5111
+ const holder = el('div', 'binder-holder as-binder');
5112
+ open.addEventListener('click', () => { listOpen = listOpen === chosen.key ? '' : chosen.key; void paintAssets(); });
5113
+ parts.push({ title: 'Cards', extra: [open], body: [holder] });
5114
+ const id = chosen.list.id;
5115
+ if (listOpen === chosen.key) {
5116
+ /* Drawn again (the lists changed): on the card it showed, if it showed one; after a reload, the card of the address. */
5117
+ const was = assetsView?.place;
5118
+ const at = assetsAt?.list === id ? assetsAt : was?.list === id && was.page === 'card' ? { list: id, card: was.card } : null;
5119
+ assetsAt = null;
5120
+ queueMicrotask(() => void mountBinder(holder, (l) => l.id === id, { place: at, steps: assetsSteps, onLists: (data) => { if (place === 'assets' && binderSig(data) !== listsSig) void paintAssets(); } })
5121
+ .then((view) => { if (view) assetsView = view; }));
5122
+ }
5123
+ } else {
5124
+ /* In a conversation, its cards are in its Lists tab. */
5125
+ const open = el('button', '', 'Open'); open.type = 'button'; open.dataset.act = 'open-list';
5126
+ open.addEventListener('click', () => { goTab('lists'); });
5127
+ parts.push({ title: 'Cards', extra: [open], body: [el('p', 'hint', `${chosen.list.count} card${chosen.list.count === 1 ? '' : 's'}`)] });
5164
5128
  }
5165
5129
  }
5130
+ let gitHolder = null;
5166
5131
  if (chosen.kind === 'git') {
5167
- const holder = el('div', 'as-git'); detail.append(holder);
5168
5132
  /* Settings: where it is sent, with what. */
5169
5133
  const settings = await getJson(`/git/${chosen.name}`, {});
5170
5134
  const edit = el('button', 'as-edit', '✎ Edit'); edit.type = 'button';
5171
5135
  const table = el('dl', 'as-settings');
5172
5136
  const fact = (k, v) => { table.append(el('dt', '', k), el('dd', '', v)); };
5173
5137
  fact('Remote', settings.remote ?? 'none');
5174
- fact('Sent with', settings.hasKey ? 'a key kept for it' : settings.sshKey ? `SSH key ${settings.sshKey}` : r.via?.method && r.via.method !== 'none' ? viaText(r.via).replace(/^, with /, '') : 'what it was cloned with');
5175
- if (r.from && r.via?.hostKey) fact('Host key', `${hostOf(r.from)}: ${r.via.hostKey}`);
5176
- detail.append(chapter('Settings', edit), table);
5177
- const box = $('gitview-remote-box');
5178
- remoteShown = chosen.name;
5179
- await fillRemote(chosen.name, settings);
5180
- box.hidden = !remoteEditing; box.open = true;
5181
- detail.append(box);
5182
- edit.addEventListener('click', () => { remoteEditing = !remoteEditing; box.hidden = !remoteEditing; if (remoteEditing) focusField($('gitview-url')); });
5183
- void gitDetail(holder, chosen.name, { place: true });
5184
- }
5185
- if (chosen.target) {
5186
- const t = chosen.target;
5187
- detail.append(el('p', 'hint', 'A level is: watch (read only), propose (asks before each action), frame (acts within its rules, asks for the rest), free (acts, kept in the journal).'));
5138
+ fact('Sent with', settings.hasKey ? 'a key kept for it' : settings.sshKey ? `SSH key ${settings.sshKey}` : r?.via?.method && r.via.method !== 'none' ? viaText(r.via).replace(/^, with /, '') : 'what it was cloned with');
5139
+ if (r?.from && r.via?.hostKey) fact('Host key', `${hostOf(r.from)}: ${r.via.hostKey}`);
5140
+ const body = [table];
5141
+ if (inMenu) {
5142
+ const box = $('gitview-remote-box');
5143
+ remoteShown = chosen.name;
5144
+ await fillRemote(chosen.name, settings);
5145
+ box.hidden = !remoteEditing; box.open = true;
5146
+ body.push(box);
5147
+ edit.addEventListener('click', () => { remoteEditing = !remoteEditing; box.hidden = !remoteEditing; if (remoteEditing) focusField($('gitview-url')); });
5148
+ } else edit.addEventListener('click', () => { void openAssetsPlace(chosen.key, { remote: true }); });
5149
+ gitHolder = el('div', 'as-git');
5150
+ parts.push({ title: 'Settings', extra: [edit], body }, gitHolder);
5151
+ }
5152
+ if (t) {
5153
+ parts.push(el('p', 'hint', 'A level is: watch (read only), propose (asks before each action), frame (acts within its rules, asks for the rest), free (acts, kept in the journal).'));
5188
5154
  /* Calls waiting for a person (propose/frame). Accept or refuse each. */
5189
5155
  const waiting = (Array.isArray(tether.approvals) ? tether.approvals : []).filter((q) => (q.target?.id ?? q.target) === t.id);
5190
5156
  if (waiting.length) {
@@ -5193,44 +5159,134 @@
5193
5159
  const line = el('div', 'given-row');
5194
5160
  const what = el('span', ''); what.append(el('b', '', q.verb ?? 'action'), document.createTextNode(` ${q.detail ?? ''}`.trimEnd()));
5195
5161
  if (q.why) what.append(el('small', 'hint', ` — ${q.why}`));
5196
- const yes = el('button', 'primary', 'Accept'); yes.type = 'button'; yes.addEventListener('click', () => { yes.disabled = true; void decideTether(q.id, 'yes'); });
5197
- const no = el('button', 'danger', 'Refuse'); no.type = 'button'; no.addEventListener('click', () => { no.disabled = true; void decideTether(q.id, 'no'); });
5162
+ const yes = el('button', 'primary', 'Accept'); yes.type = 'button'; yes.addEventListener('click', () => { yes.disabled = true; void decideTether(q.id, 'yes', repaintAsset); });
5163
+ const no = el('button', 'danger', 'Refuse'); no.type = 'button'; no.addEventListener('click', () => { no.disabled = true; void decideTether(q.id, 'no', repaintAsset); });
5198
5164
  const acts = el('div', 'levels'); acts.append(yes, no);
5199
5165
  line.append(what, acts); box.append(line);
5200
5166
  }
5201
- detail.append(chapter('Waiting for you'), box);
5167
+ parts.push({ title: 'Waiting for you', body: [box] });
5202
5168
  }
5203
5169
  }
5204
- /* Delete, out of the way; refused while it is used, and why. */
5205
- const remove = el('button', 'as-link danger-link', 'Delete...'); remove.type = 'button';
5206
- const why = el('small', 'hint');
5207
- const inUse = chosen.kind !== 'secret' && using.length > 0;
5208
- const lost = chosen.target ? 'The connection is removed; the account token stays on the server.' : ({ secret: 'Its value is lost for good.', list: 'Its cards are lost for good.' }[chosen.kind] ?? 'Its files are kept aside on the server.');
5209
- 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`; }
5210
- remove.addEventListener('click', () => {
5211
- const sure = el('button', 'danger', chosen.kind === 'secret' || chosen.kind === 'list' ? `Yes, delete ${chosen.name}` : `Yes, remove ${chosen.name}`); sure.type = 'button';
5212
- const keep = el('button', '', 'Keep'); keep.type = 'button';
5213
- keep.addEventListener('click', () => { void paintAssets(); });
5214
- const ask = el('div', 'callout bad confirm'); ask.setAttribute('role', 'alertdialog');
5215
- ask.append(el('span', '', lost), keep, sure);
5216
- sure.addEventListener('click', async () => {
5217
- try {
5218
- if (chosen.kind === 'list') { const done = await binderCall('delete-list', { list: chosen.list.id }); if (!done.ok) throw new Error(done.text); }
5219
- else if (chosen.target) await post(`${API}/tether/remove-target`, { target: chosen.target.id });
5220
- else await post(chosen.kind === 'secret' ? `${API}/secrets/${chosen.name}/remove` : `${API}/resources/${chosen.name}/remove`);
5221
- assetOpen = '';
5222
- }
5223
- catch (error) { $('assets-error').textContent = error.message; $('assets-error').hidden = false; }
5224
- await paintAssets();
5225
- });
5226
- remove.replaceWith(ask); why.remove();
5227
- sure.focus();
5228
- });
5229
- /* Given to a device: from here too (the map shows who has it). */
5230
- const share = el('button', 'as-link', 'Share with a device...'); share.type = 'button';
5231
- share.addEventListener('click', () => { void openCompose([[chosen.key, 'r']]); });
5232
- const foot = el('div', 'as-foot'); foot.append(...(['secret', 'list'].includes(chosen.kind) || chosen.target ? [] : [share, el('br')]), remove, why);
5233
- detail.append(foot);
5170
+ if (inMenu && !own) {
5171
+ /* Delete, out of the way; refused while it is used, and why (a secret goes even used). */
5172
+ const using = model ? model.given.filter((x) => x.holder === 'conversation').length : 0;
5173
+ const inUse = chosen.kind !== 'secret' && using > 0;
5174
+ const lost = t ? 'The connection is removed; the account token stays on the server.' : ({ secret: 'Its value is lost for good.', list: 'Its cards are lost for good.' }[chosen.kind] ?? 'Its files are kept aside on the server.');
5175
+ foot.push(KIT.AssetDelete({ label: 'Delete...', lost,
5176
+ blocked: inUse ? `used by ${using} conversation${using > 1 ? 's' : ''}: set ${using > 1 ? 'them' : 'it'} to None first` : '',
5177
+ yes: chosen.kind === 'secret' || chosen.kind === 'list' ? `Yes, delete ${chosen.name}` : `Yes, remove ${chosen.name}`,
5178
+ onYes: async () => {
5179
+ try {
5180
+ if (chosen.kind === 'list') { const done = await binderCall('delete-list', { list: chosen.list.id }); if (!done.ok) throw new Error(done.text); }
5181
+ else if (t) await post(`${API}/tether/remove-target`, { target: t.id });
5182
+ else await post(chosen.kind === 'secret' ? `${API}/secrets/${chosen.name}/remove` : `${API}/resources/${chosen.name}/remove`);
5183
+ assetOpen = '';
5184
+ }
5185
+ catch (error) { $('assets-error').textContent = error.message; $('assets-error').hidden = false; }
5186
+ await paintAssets();
5187
+ } }));
5188
+ } else if (!inMenu && !own) {
5189
+ const there = el('button', 'as-link', 'Open in Assets'); there.type = 'button'; there.dataset.act = 'in-assets';
5190
+ there.addEventListener('click', () => { void openAssetsPlace(chosen.key); });
5191
+ foot.push(there);
5192
+ }
5193
+ const card = { ...cardOf(chosen), holders: undefined, right: inMenu ? undefined : chosen.right, chips: chipsOf(chosen) };
5194
+ detail.append(KIT.AssetPanel(card, { back: back ? { onBack: () => { if (!nav.close('asset')) back(); } } : null, parts, foot }));
5195
+ if (gitHolder) await gitDetail(gitHolder, chosen.name, { place: inMenu, others: gits.length > 1 });
5196
+ }
5197
+ const ASSET_WORD = { folder: 'Folder', git: 'Repository', mailbox: 'Mailbox', agenda: 'Calendar', contacts: 'Contacts', secret: 'Secret', list: LISTS_WORD.one, acces: 'Access' };
5198
+ /* Under its name: its kind (its group is the picker below it, in the menu). */
5199
+ function chipsOf(chosen) {
5200
+ const kind = chosen.target ? (TETHER_CAT[chosen.target.kind] ?? 'acces') : chosen.kind;
5201
+ const word = uiSaid(`set-acc-kind-${kind}`, ASSET_WORD[kind] ?? kind);
5202
+ /* Said once: not again when its line already says it ("folder"). */
5203
+ return String(chosen.sub ?? '').toLowerCase() === word.toLowerCase() ? [] : [{ text: word }];
5204
+ }
5205
+ let assetsPainting = 0;
5206
+ async function paintAssets() {
5207
+ if (place !== 'assets' || DEVICE) return;
5208
+ watchTether();
5209
+ const mine = ++assetsPainting;
5210
+ const [all, boxes, secrets, keys, lists, tether, assetGroups] = await Promise.all([getJson('/resources', []), getJson('/mailboxes', []), getJson('/secrets', []), getJson('/git-keys', []), binderCall('lists', {}), getJson('/tether', {}), getJson('/asset-groups', []), readDevices()]);
5211
+ /* A later paint asked meanwhile: it draws, with what it read (never this older reading over it). */
5212
+ if (place !== 'assets' || mine !== assetsPainting) return;
5213
+ paintKeys(keys);
5214
+ markSecrets(secrets);
5215
+ const items = [];
5216
+ for (const r of all) {
5217
+ const kind = kindOf(r);
5218
+ const box = kind === 'mailbox' ? boxes.find((m) => m.name === r.name) : undefined;
5219
+ items.push({ key: `${kind}:${r.name}`, kind, name: r.name, resource: r, box, ...usedBy(Object.keys(r.attachments ?? {}), `${kind}:${r.name}`),
5220
+ sub: kind === 'git' ? `${gitSub(r)}${viaText(r.via)}` : kind === 'mailbox' ? boxSub(box) : 'folder', tone: box?.failure ? 'bad' : '' });
5221
+ }
5222
+ for (const s2 of secrets) items.push({ key: `secret:${s2.name}`, kind: 'secret', name: s2.name, secret: s2, ...usedBy(s2.conversations, `secret:${s2.name}`), ...secretItem(s2, 'name only') });
5223
+ /* Tether targets ("Connexions"): a mailbox, calendar or address book connected
5224
+ by token, given to a conversation at a level. The token lives on the server. */
5225
+ const allTargets = Array.isArray(tether.targets) ? tether.targets : [];
5226
+ for (const tgt of allTargets) {
5227
+ const users = Object.keys(tgt.grants ?? {}).filter((id) => id.startsWith('conversation:')).map((id) => id.slice('conversation:'.length));
5228
+ const acct = tetherAccount(tgt.id);
5229
+ const siblings = allTargets.filter((o) => o.id !== tgt.id && tetherAccount(o.id) === acct).map((o) => connexionSub(o.kind));
5230
+ items.push({ key: `connexion:${tgt.id}`, kind: tetherCat(tgt.kind), name: tgt.title, target: tgt, siblings, live: true, ...usedBy(users, `connexion:${tgt.id}`),
5231
+ sub: siblings.length ? `linked: ${siblings.join(', ')}` : connexionSub(tgt.kind) });
5232
+ }
5233
+ /* Binder's lists: given to a conversation (read, write) in Binder itself. */
5234
+ const shownLists = lists.ok && Array.isArray(lists.data) ? lists.data.filter((l) => !l.archived) : [];
5235
+ listsSig = binderSig(lists.data);
5236
+ for (const l of shownLists) {
5237
+ items.push({ key: `list:${l.id}`, kind: 'list', name: l.title, list: l, ...usedBy(givenTo(l).map((id) => id.slice('conversation:'.length)), `list:${l.id}`), sub: `${l.count} card${l.count === 1 ? '' : 's'}` });
5238
+ }
5239
+ const chosen = assetsAdding ? null : items.find((i) => i.key === assetOpen) ?? null;
5240
+ if (justMade && !justMade.to && justMade.key !== chosen?.key) justMade = null;
5241
+ /* A group can be the open thing too (its own detail: give it, rename it). */
5242
+ const chosenGroup = !assetsAdding && !chosen && assetOpen.startsWith('group:') ? assetGroups.find((g) => `group:${g.id}` === assetOpen) ?? null : null;
5243
+ /* Every call waiting for the owner, across all the connexions, gathered in one place
5244
+ (in a connexion's own detail they still show, but only that one's). */
5245
+ const allApprovals = Array.isArray(tether.approvals) ? tether.approvals : [];
5246
+ const onDemandes = !assetsAdding && !chosen && !chosenGroup && assetOpen === 'demandes:all';
5247
+ $('assets-as').dataset.open = chosen || chosenGroup || assetsAdding || onDemandes ? 'detail' : 'list';
5248
+ const choose = (key) => { placeAssetStep(); if (key !== assetOpen) { groupGiveShow.clear(); clearAssetDetail(); } assetOpen = key; assetsAdding = ''; remoteEditing = false; remember(); void paintAssets(); };
5249
+ /* THE ONE LIST (kit AssetList), scope all: groups by default once one exists; who has each on its right. */
5250
+ const model = KIT.assetListModel({ items: items.map(cardOf), groups: assetGroups, scope: 'all', by: assetsBy, query: assetsQuery, folded: [...groupsFolded], kinds: ASSET_KINDS });
5251
+ paintAssetsView(model.view);
5252
+ /* Above them all, once something waits: the owner reaches every call from here, not only by opening the
5253
+ right connexion. Then, in the view by group, "+ New group". */
5254
+ const pinned = [];
5255
+ if (allApprovals.length && !assetsQuery) pinned.push(pinnedCard({ key: 'demandes:all', kind: 'demandes', name: 'Demandes', sub: `${allApprovals.length} waiting for you`, count: allApprovals.length }, { chosen: onDemandes ? 'demandes:all' : '', onOpen: choose, extra: 'demande-entry' }));
5256
+ if (model.view === 'group') pinned.push(newGroupBar());
5257
+ paintAssetList($('assets-rows'), model, { chosen: chosen?.key ?? (chosenGroup ? `group:${chosenGroup.id}` : onDemandes ? 'demandes:all' : ''), onOpen: choose, pinned,
5258
+ onFold: (id) => { if (groupsFolded.has(id)) groupsFolded.delete(id); else groupsFolded.add(id); keepGroupsFolded(); void paintAssets(); },
5259
+ onGroup: (id) => choose(`group:${id}`), noMatch: 'Nothing by that name.' });
5260
+ if (model.view === 'group') dragToGroups($('assets-rows'));
5261
+ const detail = clearAssetDetail();
5262
+ const back = () => { assetOpen = ''; assetsAdding = ''; remember(); void paintAssets(); };
5263
+ if (assetsAdding) {
5264
+ /* The New asset box: from the map's "+" of Assets, which kind first ("<" goes back to the map);
5265
+ from "+ New" of the list, which kind first too ("<" Assets). */
5266
+ const out = assetsFromMap ? el('button', 'as-link', '‹ Access') : el('button', 'as-link as-back', '‹ Assets'); out.type = 'button';
5267
+ out.addEventListener('click', () => { if (!nav.close(assetsFromMap ? 'compose' : 'asset')) back(); });
5268
+ const kind = assetsAdding === 'choose' ? '' : assetsAdding;
5269
+ detail.append(out, newAssetBox({ kind, onKind: (k) => { assetsAdding = k; void paintAssets(); }, boxHost: { where: '', repaint: () => { void paintAssets(); }, close: back } }));
5270
+ if (kind) focusFirst(detail);
5271
+ return;
5272
+ }
5273
+ if (chosenGroup) { groupDetail(detail, chosenGroup, items, back); return; }
5274
+ if (onDemandes) {
5275
+ const body = [el('p', 'hint', 'Each is a Tether call its agent asked you to allow. Accept, and it runs; refuse, and it is told so.'),
5276
+ allApprovals.length ? demandesList(allApprovals, { withWho: true, after: () => paintAssets() }) : el('p', 'hint', 'Nothing is waiting now.')];
5277
+ detail.append(KIT.AssetPanel({ key: 'demandes:all', kind: 'demandes', name: 'Demandes', count: allApprovals.length }, { back: { onBack: () => { if (!nav.close('asset')) back(); } }, parts: body }));
5278
+ return;
5279
+ }
5280
+ if (!chosen) { if (items.length) detail.append(noAssetChosen()); return; }
5281
+ /* Just made here: the box's ending above it -- Create another, or Done. */
5282
+ if (justMade && !justMade.to && justMade.key === chosen.key) {
5283
+ const made = justMade;
5284
+ detail.append(newAssetBox({ kind: made.kind, made: { said: uiSaid('set-na-made', '{name} created', { name: made.name }), note: made.note },
5285
+ onAnother: () => { justMade = null; placeAssetStep(); assetsAdding = made.kind || 'choose'; void paintAssets(); },
5286
+ onDone: () => { justMade = null; void paintAssets(); } }));
5287
+ }
5288
+ if (filesBrowsing && filesBrowsing !== chosen.key) filesBrowsing = '';
5289
+ await assetPanel(detail, chosen, { back, tether, groups: assetGroups });
5234
5290
  }
5235
5291
  /* From the map's "+" of Assets: the Assets page over the map, on "which kind"; Back, the map. */
5236
5292
  let assetsFromMap = false;
@@ -5250,6 +5306,7 @@
5250
5306
  /* The detail emptied (its forms back where they wait): another asset picked shows nothing of the one before while it is read. */
5251
5307
  function clearAssetDetail() {
5252
5308
  const detail = $('assets-detail');
5309
+ if (detail.contains($('files'))) unembedFiles();
5253
5310
  for (const form of detail.querySelectorAll('.as-form, #gitview-remote-box')) $('assets-forms').append(form);
5254
5311
  detail.replaceChildren();
5255
5312
  return detail;
@@ -8763,7 +8820,9 @@
8763
8820
  let editing = null; /* the text file being edited: { tab, inner, name, version, saved, area } */
8764
8821
  let filesChanged = false; /* edited: the list behind shows the new size and time */
8765
8822
  const sizeOf = (n) => (n >= 1048576 ? `${(n / 1048576).toFixed(1)} MB` : n >= 1024 ? `${Math.round(n / 1024)} KB` : n === 1 ? '1 byte' : `${n} bytes`);
8766
- const filesQuery = (extra = {}) => new URLSearchParams({ c: current, r: filesOf, p: filesAt, ...extra }).toString();
8823
+ /* The conversation the files are read through: none when browsed from the Assets menu (the owner's own rights). */
8824
+ const filesC = () => (filesOwner && place === 'assets' ? '' : current);
8825
+ const filesQuery = (extra = {}) => new URLSearchParams({ c: filesC(), r: filesOf, p: filesAt, ...extra }).toString();
8767
8826
  /* When it was last changed, short: the time today, the day otherwise. */
8768
8827
  const whenOf = (iso) => {
8769
8828
  const d = new Date(iso); if (Number.isNaN(d.getTime())) return '';
@@ -8848,6 +8907,8 @@
8848
8907
  ...deviceShared.filter((s) => !attachedHere.some((r) => r.name === s.name)).map((s) => ({ name: s.name, access: s.access, given: true })),
8849
8908
  /* For the owner: everything else that is kept here, attached to this conversation or not. */
8850
8909
  ...ownerOthers.filter((o) => !attachedHere.some((r) => r.name === o.name))];
8910
+ /* Browsed from the Assets menu: that folder alone, as the owner has it. */
8911
+ if (filesOwner && place === 'assets') mine.splice(0, mine.length, ...ownerOthers.filter((o) => o.name === filesOwner).map((o) => ({ ...o, yours: false })));
8851
8912
  /* Given to the device to write, attached to the conversation to read: the larger of the two holds. */
8852
8913
  for (const r of mine) if (deviceShared.some((s) => s.name === r.name && s.access === 'write')) r.access = 'write';
8853
8914
  filesTabs = mine;
@@ -8867,7 +8928,8 @@
8867
8928
  filesWritable = mine.find((r) => r.name === filesOf)?.access === 'write';
8868
8929
  $('files-actions').hidden = !filesOf || !filesWritable;
8869
8930
  $('files-readonly').hidden = !filesOf || filesWritable;
8870
- $('files-readonly').textContent = mine.find((r) => r.name === filesOf)?.given ? 'Read-only: given to this device to read. Nothing can be added or changed here.' : 'Read-only: attached to this conversation to read. Nothing can be added or changed here.';
8931
+ $('files-readonly').textContent = mine.find((r) => r.name === filesOf)?.given ? 'Read-only: given to this device to read. Nothing can be added or changed here.'
8932
+ : filesOwner && place === 'assets' ? 'Read-only: a copy of the mail. Nothing can be added or changed here.' : 'Read-only: attached to this conversation to read. Nothing can be added or changed here.';
8871
8933
  $('files-views').hidden = !filesOf;
8872
8934
  for (const b of $('files-views').querySelectorAll('button')) b.setAttribute('aria-pressed', String(b.dataset.view === filesView));
8873
8935
  if (!filesOf) { rows.replaceChildren(); path.replaceChildren(); $('files-empty').hidden = true; return; }
@@ -9167,7 +9229,7 @@
9167
9229
  if (total > DROP_BYTES) { filesFailed(`At most ${DROP_BYTES / 1073741824} GB at a time: this was ${sizeOf(total)}.`); return; }
9168
9230
  if (items.length === 0 && folders.length === 0) { filesFailed(notes.length ? `Nothing to upload: ${notes.join('; ')}.` : 'Nothing to upload.'); return; }
9169
9231
  /* Where it goes is fixed now: moving elsewhere meanwhile does not move the upload. */
9170
- const where = { c: current, r: filesOf, p: filesAt };
9232
+ const where = { c: filesC(), r: filesOf, p: filesAt };
9171
9233
  const at = (route, extra = {}) => `${API}/files/${route}?${new URLSearchParams({ ...where, ...extra })}`;
9172
9234
  uploading = { stopped: false, xhr: null };
9173
9235
  try {
@@ -9559,7 +9621,7 @@
9559
9621
  async function preview(tab, inner, name, size, from, opts = {}) {
9560
9622
  closePreview();
9561
9623
  if (opts.own) mdUrls.add(opts.own);
9562
- const address = from ?? `${API}/files/download?${new URLSearchParams({ c: current, r: tab, p: inner })}`;
9624
+ const address = from ?? `${API}/files/download?${new URLSearchParams({ c: filesC(), r: tab, p: inner })}`;
9563
9625
  $('preview-name').textContent = name;
9564
9626
  $('preview-download').href = address; $('preview-download').setAttribute('download', name);
9565
9627
  /* From the terminal, a way to the folder it sits in. */
@@ -9736,7 +9798,7 @@
9736
9798
  frame.setAttribute('sandbox', 'allow-scripts');
9737
9799
  frame.setAttribute('referrerpolicy', 'no-referrer');
9738
9800
  frame.title = `${name}, a page written by the tool`;
9739
- frame.src = `${API}/files/page?${new URLSearchParams({ c: current, r: tab, p: inner })}`;
9801
+ frame.src = `${API}/files/page?${new URLSearchParams({ c: filesC(), r: tab, p: inner })}`;
9740
9802
  const toggle = document.createElement('button'); toggle.type = 'button'; toggle.textContent = 'Show its source';
9741
9803
  let shown = 'page';
9742
9804
  toggle.addEventListener('click', () => {
@@ -9752,7 +9814,7 @@
9752
9814
  try {
9753
9815
  page = await markdownPage(text, {
9754
9816
  /* 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. */
9755
- 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; },
9817
+ 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: filesC(), r: tab, p })}` : null; },
9756
9818
  open: (href) => { const p = from ? null : besideFile(tab, inner, href); return p ? () => { void preview(tab, p, p.split('/').pop(), 0); } : null; },
9757
9819
  diagram: drawDiagram, highlight: colourCode,
9758
9820
  });
@@ -9843,7 +9905,7 @@
9843
9905
  /* A mail opened by its reference: the server's page of the same mail, read again then (asked for). */
9844
9906
  if ((ref || !from) && !offline) {
9845
9907
  const go = el('button', 'quiet mail-remote-show', uiSaid('set-mail-show-remote', 'Show them')); go.type = 'button';
9846
- const shown = ref ? `${API}/mail/page?${new URLSearchParams({ ref: ref.got?.ref || ref.ref, ...(ref.of ? { c: ref.of } : {}) })}` : `${API}/files/mail?${new URLSearchParams({ c: current, r: tab, p: inner })}`;
9908
+ const shown = ref ? `${API}/mail/page?${new URLSearchParams({ ref: ref.got?.ref || ref.ref, ...(ref.of ? { c: ref.of } : {}) })}` : `${API}/files/mail?${new URLSearchParams({ c: filesC(), r: tab, p: inner })}`;
9847
9909
  go.addEventListener('click', () => { const f = frameOf(); f.src = shown; frame.replaceWith(f); frame = f; bar.remove(); });
9848
9910
  bar.append(' · ', go);
9849
9911
  }
@@ -9931,7 +9993,7 @@
9931
9993
  }
9932
9994
  async function editFile(tab, inner, name) {
9933
9995
  closePreview();
9934
- const query = new URLSearchParams({ c: current, r: tab, p: inner });
9996
+ const query = new URLSearchParams({ c: filesC(), r: tab, p: inner });
9935
9997
  $('preview-name').textContent = name;
9936
9998
  $('preview-download').href = `${API}/files/download?${query}`; $('preview-download').setAttribute('download', name);
9937
9999
  $('preview-where').hidden = true; $('preview-edit').hidden = true;
@@ -9989,7 +10051,7 @@
9989
10051
  if (!editing) return;
9990
10052
  const e = editing;
9991
10053
  const text = e.area.value;
9992
- const query = new URLSearchParams({ c: current, r: e.tab, p: e.inner, ...(how === 'copy' ? { copy: '1' } : { version: how === 'any' ? 'any' : e.version }) });
10054
+ const query = new URLSearchParams({ c: filesC(), r: e.tab, p: e.inner, ...(how === 'copy' ? { copy: '1' } : { version: how === 'any' ? 'any' : e.version }) });
9993
10055
  e.ask.hidden = true;
9994
10056
  let j;
9995
10057
  try {
@@ -10004,7 +10066,7 @@
10004
10066
  /* Saved beside it: what is edited from now on is the copy. */
10005
10067
  e.inner = [...e.inner.split('/').slice(0, -1), j.name].join('/'); e.name = j.name;
10006
10068
  $('preview-name').textContent = j.name;
10007
- $('preview-download').href = `${API}/files/download?${new URLSearchParams({ c: current, r: e.tab, p: e.inner })}`; $('preview-download').setAttribute('download', j.name);
10069
+ $('preview-download').href = `${API}/files/download?${new URLSearchParams({ c: filesC(), r: e.tab, p: e.inner })}`; $('preview-download').setAttribute('download', j.name);
10008
10070
  }
10009
10071
  e.version = j.version; e.saved = text;
10010
10072
  e.tell(how === 'copy' ? `saved as "${j.name}"; the file the tool wrote is left as it was` : `saved at ${new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`);
@@ -10019,7 +10081,7 @@
10019
10081
  look.addEventListener('click', async () => {
10020
10082
  look.disabled = true;
10021
10083
  try {
10022
- const r = await fetch(`${API}/files/text?${new URLSearchParams({ c: current, r: e.tab, p: e.inner })}`);
10084
+ const r = await fetch(`${API}/files/text?${new URLSearchParams({ c: filesC(), r: e.tab, p: e.inner })}`);
10023
10085
  const theirs = await r.json();
10024
10086
  if (!r.ok) throw new Error(theirs.error || 'Its new version could not be read.');
10025
10087
  const when = document.createElement('small'); when.className = 'hint';
@@ -10169,7 +10231,7 @@
10169
10231
  });
10170
10232
 
10171
10233
  /* FILES, a sheet over the screen: on a device's page only (the owner's are in the Assets tab of a conversation). */
10172
- function showFiles() { nav.over('files', () => { if (!$('files').classList.contains('embedded')) { $('files').hidden = true; focusTerminal(); } }); $('files').hidden = false; }
10234
+ function showFiles() { if ($('assets-detail').contains($('files'))) unembedFiles(); nav.over('files', () => { if (!$('files').classList.contains('embedded')) { $('files').hidden = true; focusTerminal(); } }); $('files').hidden = false; }
10173
10235
  $('files-open').addEventListener('click', async () => { await paintFiles(); showFiles(); });
10174
10236
  $('files-close').addEventListener('click', () => { if (!nav.dropOver('files')) { $('files').hidden = true; focusTerminal(); } });
10175
10237
 
package/web/index.html CHANGED
@@ -104,6 +104,7 @@
104
104
  <!-- WHAT THIS CONVERSATION WAS GIVEN (G): the same list, its own, with
105
105
  each opened on the right (a folder: its files). -->
106
106
  <div id="cassets" class="sheet as-room" hidden>
107
+ <p id="cassets-error" class="error" role="alert" hidden></p>
107
108
  <div class="as" id="cassets-as">
108
109
  <div class="as-list"><div class="as-tools"><input type="search" id="cassets-search" placeholder="Search" aria-label="Search its assets" spellcheck="false" autocomplete="off"><button type="button" id="cassets-attach" class="as-new"><span aria-hidden="true">+ </span><span data-said="set-na-attach">Attach</span></button></div><div id="cassets-rows"></div></div>
109
110
  <div class="as-detail" id="cassets-detail"></div>
package/web/kit.js CHANGED
@@ -25,6 +25,9 @@
25
25
  * it (Holders) or, seen from one holder, its right (RightsBadge).
26
26
  * AssetList THE ONE LIST of assets (06-11, assets step 2): the Assets menu and a conversation's tab, only its
27
27
  * scope changes; by type or by group; an empty type not shown; assetListModel places the rows.
28
+ * AccessList WHO HAS IT (06-11, assets step 3): a row per conversation or device, its RightsPicker; seen from one
29
+ * conversation, its row first, then "Also with"; accessModel places the rows.
30
+ * AssetPanel ONE ASSET OPENED, the same in the Assets menu and a conversation's tab: head, parts, foot (AssetDelete).
28
31
  * RIGHTS THE ONE TABLE of what an asset can be given at, by its kind and by who gets it (a
29
32
  * conversation, a device); "none" first. RightsBadge reads a right, RightsPicker sets it.
30
33
  *
@@ -494,7 +497,9 @@
494
497
  /* A RIGHT, SET: the kind's levels from the table, "None" first, the one held pressed. `onChange(level,
495
498
  stored)`: the level, and as the server keeps it; the buttons wait while it works (a promise). Nothing
496
499
  to choose (a kind not given to that holder): null. */
497
- function RightsPicker({ key = '', holder = 'conversation', value, level, label = '', cls = '', onChange = () => {} } = {}) {
500
+ /* A CALENDAR, CONTACTS: given live, Read is Watch and Write is Propose (what Attach made of them) -- said on the picker. */
501
+ const RIGHT_SAME = { agenda: { watch: 'read', propose: 'write' }, contacts: { watch: 'read', propose: 'write' } };
502
+ function RightsPicker({ key = '', kind = '', holder = 'conversation', value, level, label = '', cls = '', onChange = () => {} } = {}) {
498
503
  const levels = rightsFor(key, holder);
499
504
  if (!levels.length) return null;
500
505
  const now = level ?? rightOf(key, value, holder);
@@ -509,7 +514,12 @@
509
514
  } });
510
515
  addClass(pick, `kit-rights-pick${cls ? ` ${cls}` : ''}`);
511
516
  pick.dataset.key = key; pick.dataset.holder = holder;
512
- for (const b of pick.children) b.title = rightWord(b.dataset.value, 'hint');
517
+ const same = key === 'connexion' ? RIGHT_SAME[kind] : null;
518
+ for (const b of pick.children) {
519
+ b.title = rightWord(b.dataset.value, 'hint');
520
+ const as = same?.[b.dataset.value];
521
+ if (as) { const w = rightWord(as, 'pick'); b.append(node('small', 'kit-rights-same', `= ${w}`)); b.title = `${b.title} (= ${w})`; }
522
+ }
513
523
  return pick;
514
524
  }
515
525
 
@@ -662,8 +672,125 @@
662
672
  return box;
663
673
  }
664
674
 
675
+ /* WHO HAS IT (06-11, assets step 3): ONE LIST of who was given an asset -- each conversation and each device on a
676
+ row, its right set in place (RightsPicker, "None" first). Seen from a conversation, its own row comes first, then
677
+ "Also with" the others. "+ Give to…" opens the conversations that do not have it yet, each at None.
678
+
679
+ accessModel: the rows placed, no page needed (tested alone).
680
+ key the table's key (rightsKey) from 'conversation:x' when seen from it ('' : the Assets menu)
681
+ holders [{ id: 'conversation:x' | 'device:y', name, sub?, value | level, ready?: false, hue? }]
682
+ -> { here, given: [rows], others: [rows], count, said: '' | 'nobody' | 'everyone' | 'noready' } -- a row with its
683
+ `holder` ('conversation' | 'device') and its `level`; a device is never offered (it is shared from its own sheet). */
684
+ const holderOf = (id) => (String(id ?? '').startsWith('device:') ? 'device' : 'conversation');
685
+ function accessModel({ key = '', holders = [], from = '' } = {}) {
686
+ const rows = (holders ?? []).filter((h) => h && h.id).map((h) => {
687
+ const holder = holderOf(h.id);
688
+ const level = h.level ?? rightOf(key, h.value, holder);
689
+ return { ...h, holder, level: level in RIGHT_LEVELS ? level : 'none' };
690
+ }).filter((r) => rightsFor(key, r.holder).length > 0);
691
+ const here = from ? rows.find((r) => r.id === from) ?? null : null;
692
+ const rest = rows.filter((r) => r !== here);
693
+ const given = [...rest.filter((r) => r.holder === 'conversation' && r.level !== 'none'), ...rest.filter((r) => r.holder === 'device' && r.level !== 'none')];
694
+ const others = rest.filter((r) => r.holder === 'conversation' && r.level === 'none' && r.ready !== false);
695
+ const count = given.length + (here && here.level !== 'none' ? 1 : 0);
696
+ const convs = rows.filter((r) => r.holder === 'conversation' && r.ready !== false);
697
+ const said = !convs.length && !count ? 'noready' : !count ? 'nobody' : !others.length && !here ? 'everyone' : '';
698
+ return { here, given, others, count, said };
699
+ }
700
+
701
+ /* The list drawn from its model. `onChange(row, level, stored)` sets one right (the picker waits on it); `kind`, the
702
+ asset's own kind (a calendar's levels say what they mean); `actions`, more gestures under it (Share with a device…).
703
+ Its old handles kept for the pages' tests: .as-chapter .as-add, .as-users, .as-picker, .given-row[data-conversation]. */
704
+ function AccessList(model, { key = '', kind = '', name = '', onChange = () => {}, actions = [] } = {}) {
705
+ const box = node('section', 'kit-access');
706
+ const head = node('div', 'as-chapter kit-access-head');
707
+ head.append(node('h3', '', say('set-acc-title', 'Who has it')));
708
+ const picker = node('div', 'as-users as-picker kit-access-pick'); picker.hidden = true;
709
+ const give = node('button', 'as-add kit-access-give', '+'); give.type = 'button';
710
+ const giveWord = say('set-acc-give', 'Give to…');
711
+ give.setAttribute('aria-label', giveWord); give.title = giveWord; give.setAttribute('aria-expanded', 'false');
712
+ give.addEventListener('click', () => { picker.hidden = !picker.hidden; give.setAttribute('aria-expanded', String(!picker.hidden)); });
713
+ head.append(give);
714
+ box.append(head);
715
+ const row = (r) => {
716
+ const line = node('div', 'given-row kit-access-row');
717
+ line.dataset[r.holder === 'device' ? 'device' : 'conversation'] = String(r.id).replace(/^[a-z]+:/, '');
718
+ line.dataset.level = r.level;
719
+ const who = node('span', 'kit-access-who');
720
+ who.append(Avatar({ name: r.name, hue: r.hue }));
721
+ const nm = node('span', 'kit-access-name', r.name);
722
+ const sub = r.sub ?? (r.holder === 'device' ? say('set-acc-device', 'Device') : '');
723
+ if (sub) nm.append(node('small', '', sub));
724
+ who.append(nm);
725
+ line.append(who);
726
+ const pick = RightsPicker({ key, kind, holder: r.holder, level: r.level, label: say('set-acc-what', 'What {who} may do with {name}').replace('{who}', r.name).replace('{name}', name),
727
+ onChange: (level, stored) => onChange(r, level, stored) });
728
+ if (pick) line.append(pick);
729
+ return line;
730
+ };
731
+ if (model.here) {
732
+ const mine = node('div', 'as-users kit-access-here');
733
+ mine.append(row(model.here));
734
+ box.append(mine);
735
+ }
736
+ const users = node('div', 'as-users kit-access-given');
737
+ if (model.here && model.given.length) users.append(node('h4', 'kit-access-also', say('set-acc-also', 'Also with')));
738
+ for (const r of model.given) users.append(row(r));
739
+ const said = { nobody: say('set-acc-nobody', 'No conversation uses it.'), everyone: '', noready: say('set-acc-noready', 'No conversation is ready.') }[model.said];
740
+ if (said && !model.here) users.append(node('p', 'hint', said));
741
+ if (users.children.length) box.append(users);
742
+ for (const r of model.others) picker.append(row(r));
743
+ if (!model.others.length) picker.append(node('p', 'hint', model.said === 'noready' ? say('set-acc-noready', 'No conversation is ready.') : say('set-acc-everyone', 'Every conversation has it.')));
744
+ box.append(picker);
745
+ const more = actions.filter(Boolean);
746
+ if (more.length) { const acts = node('div', 'kit-access-acts'); acts.append(...more); box.append(acts); }
747
+ return box;
748
+ }
749
+
750
+ /* ONE ASSET OPENED (06-11, assets step 3): the same panel in the Assets menu and in a conversation's tab. Its head (an
751
+ AssetCard head: sign, name, line, chips) under "‹ Assets" (a phone's way back), then its parts in order -- what it is,
752
+ who has it (AccessList), what is in it (files, branches, cards) -- then its foot (rename, delete…).
753
+ back { label?, onBack } the way back parts [node | { title, extra: [nodes], body: [nodes], cls }]
754
+ foot [nodes] before [nodes] above the head (an ending: "✓ created")
755
+ A part's title draws a chapter head (.as-chapter), its `extra` on its right. */
756
+ function AssetPanel(card, { back = null, parts = [], foot = [], before = [], cls = '' } = {}) {
757
+ const root = node('div', `kit-aspanel${cls ? ` ${cls}` : ''}`);
758
+ if (card?.key) root.dataset.asset = card.key;
759
+ root.append(...before.filter(Boolean));
760
+ const top = node('div', 'as-title kit-aspanel-top');
761
+ if (back) {
762
+ const b = node('button', 'as-link as-back', back.label ?? `‹ ${say('set-as-assets', 'Assets')}`); b.type = 'button';
763
+ b.addEventListener('click', () => back.onBack?.());
764
+ top.append(b);
765
+ }
766
+ top.append(AssetCard(card ?? {}, { size: 'head' }));
767
+ root.append(top);
768
+ for (const p of parts) {
769
+ if (!p) continue;
770
+ if (!p.title && !p.body) { root.append(p); continue; }
771
+ const part = node('section', `kit-aspanel-part${p.cls ? ` ${p.cls}` : ''}`);
772
+ if (p.title) { const h = node('div', 'as-chapter'); h.append(node('h3', '', p.title), ...(p.extra ?? []).filter(Boolean)); part.append(h); }
773
+ part.append(...(p.body ?? []).filter(Boolean));
774
+ root.append(part);
775
+ }
776
+ const f = foot.filter(Boolean);
777
+ if (f.length) { const box = node('div', 'as-foot kit-aspanel-foot'); box.append(...f); root.append(box); }
778
+ return root;
779
+ }
780
+
781
+ /* DELETE…, out of the way: refused while `blocked` (said why, beside it); else confirmed in place (InlineConfirm):
782
+ what is lost, Keep, then `yes`. */
783
+ function AssetDelete({ label, blocked = '', lost = '', yes = '', onYes = () => {} } = {}) {
784
+ const box = node('span', 'kit-asdelete');
785
+ const b = node('button', 'as-link danger-link', label ?? say('set-acc-delete', 'Delete…')); b.type = 'button';
786
+ box.append(b);
787
+ if (blocked) { b.disabled = true; box.append(node('small', 'hint', ` ${blocked}`)); return box; }
788
+ b.addEventListener('click', () => InlineConfirm(b, { question: lost, yes: yes || say('set-acc-delete-yes', 'Delete'), onYes }));
789
+ return box;
790
+ }
791
+
665
792
  window.clavariumKit = {
666
- AssetIcon, AssetCard, Holders, RightsBadge, RightsPicker, AssetList, assetListModel,
793
+ AssetIcon, AssetCard, Holders, RightsBadge, RightsPicker, AssetList, assetListModel, AccessList, accessModel, AssetPanel, AssetDelete, RIGHT_SAME,
667
794
  ASSET_ICONS, ASSET_KINDS, RIGHTS, RIGHT_LEVELS, rightsKey, rightsFor, rightOf, storedOf, lightest, rightWord,
668
795
  shareSlices, ShareDonut, ShareKey,
669
796
  STATES, STATE_WORDS, stateOf, hueOf, initialOf,
package/web/style.css CHANGED
@@ -2874,3 +2874,25 @@ button.kit-switch[aria-checked="true"]::after { left: 18px; background: var(--ok
2874
2874
  /* A line that asks for you keeps its shade: soon (warn), past or failing (bad). */
2875
2875
  .kit-asset-sub[data-tone="warn"] > .state-dot { background: var(--warn); }
2876
2876
  .kit-asset-sub[data-tone="bad"] { color: var(--danger); }
2877
+
2878
+ /* ONE ASSET OPENED (kit AssetPanel, AccessList; 06-11, assets step 3): the same panel in the Assets menu and in a
2879
+ conversation's tab -- its head, its parts, who has it (a row per conversation or device, its right set in place). */
2880
+ .kit-aspanel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
2881
+ .kit-aspanel > *, .kit-aspanel-part > * { flex-shrink: 0; }
2882
+ .kit-aspanel-part { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
2883
+ .kit-aspanel-top .kit-asset-head { width: 100%; }
2884
+ .kit-aspanel-top .kit-asset-head .kit-asset-main { flex: 1 1 auto; min-width: 0; }
2885
+ .kit-aspanel-top .kit-chips { margin-top: 6px; }
2886
+ .kit-access { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
2887
+ .kit-access-row { justify-content: space-between; }
2888
+ .kit-access-who { display: flex; align-items: center; gap: 10px; flex: 1 1 160px; min-width: 0; }
2889
+ .kit-access-who > .kit-av { --kc-av: 26px; border-radius: 50%; }
2890
+ .kit-access-name { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
2891
+ .kit-access-name > small { color: var(--ink2); font-size: .75rem; }
2892
+ .as-users.kit-access-here { border-color: color-mix(in srgb, var(--brass) 45%, var(--line)); background: color-mix(in srgb, var(--brass) 7%, var(--bar)); }
2893
+ .as-users > .kit-access-also { margin: 0; padding: 10px 16px 4px; border-top: 0; font-size: .6875rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink2); }
2894
+ .as-users > .kit-access-also + .given-row { border-top: 0; }
2895
+ .kit-access-acts { display: flex; gap: 14px; flex-wrap: wrap; }
2896
+ .kit-rights-pick > button > .kit-rights-same { display: block; font-size: .6875rem; font-weight: 500; opacity: .8; }
2897
+ .kit-asdelete { display: inline; }
2898
+ .as-files-menu #files.embedded > .panel-top { display: none; }