Import ISA Project Format 1.1.0

This commit is contained in:
Peter Willemsen
2026-11-30 12:07:49 +00:00
commit 563d1992a2
32 changed files with 2308 additions and 0 deletions
+131
View File
@@ -0,0 +1,131 @@
// A row always identifies a folder in the current group inventory. Private
// recents supply the activity order only, never the inventory or a grant.
export function mountOverview(target, {client, extensionName, text, locale, onImport}) {
const document = target.ownerDocument;
function element(tag, label, className) {
const node = document.createElement(tag);
if (label) node.textContent = label;
if (className) node.className = className;
return node;
}
function button(label, action) {
const node = element('button', label);
node.type = 'button';
node.onclick = action;
return node;
}
const root = element('section', '', 'isa-group-home');
const header = element('header');
header.append(element('h1', extensionName || text.projects));
const actions = element('div', '', 'isa-project-toolbar');
const refreshButton = button(text.refresh, refresh);
actions.append(refreshButton);
const importButton = button(text.import, () => run(onImport));
if (onImport && client.supports('projects_create')) actions.append(importButton);
header.append(actions);
const grid = element('div', '', 'isa-group-grid');
const activity = element('aside');
const recent = element('div');
activity.append(element('h2', text.activity), recent);
const panel = element('section', '', 'isa-group-projects');
const heading = element('header');
const create = button('+ ' + text.create, () => { name.value = ''; formError.textContent = ''; dialog.showModal(); name.focus(); });
create.className = 'isa-group-create';
const panelTitle = element('h2', text.projects);
panelTitle.id = 'isa-projects-' + crypto.randomUUID();
panel.setAttribute('aria-labelledby',panelTitle.id);
heading.append(panelTitle);
if (client.supports('projects_create')) heading.append(create);
const controls = element('div', '', 'isa-project-toolbar');
const search = element('input');
search.type = 'search';
search.placeholder = text.search;
search.setAttribute('aria-label',text.search);
const sort = element('select');
sort.setAttribute('aria-label',text.sort);
for (const [value,label] of [['updated',text.updated],['name',text.name]]) {
const option = element('option',label); option.value = value; sort.append(option);
}
controls.append(search,sort);
const alert = element('p');
alert.setAttribute('role','alert');
const list = element('div', '', 'isa-group-rows');
const status = element('p');
status.setAttribute('role','status');
panel.append(heading,controls,alert,status,list);
grid.append(activity,panel);
const dialog = element('dialog');
const title = element('h2', text.create);
title.id = 'project-create-' + crypto.randomUUID();
dialog.setAttribute('aria-labelledby',title.id);
const form = element('form');
const label = element('label', text.name);
const name = element('input');
name.required = true; name.maxLength = 160; label.append(name);
const formError = element('p'); formError.setAttribute('role','alert');
const cancel = button(text.cancel, () => dialog.close());
const submit = element('button',text.create); submit.type = 'submit';
const footer = element('div', '', 'isa-project-toolbar'); footer.append(cancel,submit);
form.append(label,formError,footer);
dialog.append(title,form);
root.append(header,grid,dialog);
target.append(root);
let projects = [], recents = [], loading = true, failed = false, busy = false, alive = true, generation = 0;
const date = new Intl.DateTimeFormat(locale,{dateStyle:'medium'});
function draw() {
const needle = search.value.trim().toLocaleLowerCase(locale);
const visible = projects.filter(p => p.name.toLocaleLowerCase(locale).includes(needle));
visible.sort((a,b) => (sort.value === 'updated' && (Date.parse(b.updatedAt) || 0) - (Date.parse(a.updatedAt) || 0)) || a.name.localeCompare(b.name,locale));
list.replaceChildren();
for (const project of visible) {
const row = button('', () => run(() => client.openListed(project)));
const info = element('span'); info.append(element('strong',project.name),element('small',project.path));
row.append(info);
if (Number.isFinite(Date.parse(project.updatedAt))) row.append(element('time',date.format(new Date(project.updatedAt))));
row.disabled = busy;
list.append(row);
}
status.textContent = loading ? text.loading : visible.length || failed ? '' : needle ? text.noMatches : text.noProjects;
recent.replaceChildren();
for (const item of recents) {
const project = projects.find(p => p.id === item.id);
if (project) {
const row = button(project.name, () => run(() => client.openListed(project)));
row.disabled = busy; recent.append(row);
}
}
if (!recent.childElementCount && !loading && !failed) recent.append(element('p',text.noActivity));
create.disabled = busy; importButton.disabled = busy; refreshButton.disabled = busy || loading;
}
async function refresh() {
const ticket = ++generation;
loading = true; failed = false; alert.textContent = ''; draw();
try {
const inventory = await client.list();
if (alive && ticket === generation) projects = inventory.filter(p => !p.archived);
} catch (error) {
if (alive && ticket === generation) { failed = true; alert.textContent = String(error.message ?? error); }
} finally {
if (alive && ticket === generation) { loading = false; draw(); }
}
}
async function run(action, notice = alert) {
if (busy) return;
busy = true; notice.textContent = ''; form.inert = true; draw();
try { await action(); }
catch (error) { if (alive && error?.name !== 'AbortError') notice.textContent = String(error.message ?? error); }
finally { if (alive) { busy = false; form.inert = false; draw(); } }
}
dialog.oncancel = event => { if (busy) event.preventDefault(); };
form.onsubmit = event => {
event.preventDefault();
if (name.value.trim()) void run(() => client.create(name.value.trim()), formError);
};
search.oninput = sort.onchange = draw;
const unsubscribe = client.subscribe(state => { recents = state.recents; draw(); });
void refresh();
const onVisible = () => { if (!document.hidden && !busy) void refresh(); };
document.addEventListener('visibilitychange',onVisible);
return () => { alive = false; unsubscribe(); document.removeEventListener('visibilitychange',onVisible); root.remove(); };
}