Extend project transfer and prepared document support

This commit is contained in:
Sander Grootendorst
2026-12-02 23:16:42 +01:00
parent c9493af951
commit 7e3780e500
12 changed files with 206 additions and 40 deletions
+84 -32
View File
@@ -1,7 +1,10 @@
import { workspaceElements } from './workspace-elements.js';
// A row identifies a folder accessible through the current launch's grants. Private
// recents supply the activity order only, never the inventory or a grant.
export function mountOverview(target, {client, extensionName, text, locale, onImport, onOverview}) {
export function mountOverview(target, {client, extensionName, text, locale, onImport, onOverview, showEmptyProjectMessage = true}) {
const document = target.ownerDocument;
const {icon} = workspaceElements(document);
function element(tag, label, className) {
const node = document.createElement(tag);
if (label) node.textContent = label;
@@ -20,35 +23,49 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
const actions = element('div', '', 'isa-project-toolbar');
const refreshButton = button(text.refresh, refresh);
refreshButton.className = 'isa-extension-button isa-extension-button--secondary';
refreshButton.prepend(icon('refresh'));
actions.append(refreshButton);
const pickFolder = button(text.pickFolder, () => run(async () => {
if (await client.pickFolder()) await refresh();
if (await client.pickFolder()) {
// An inventory requested before the picker grant may omit the new folder.
await pendingRefresh;
if (alive) await refresh();
}
}));
pickFolder.className = 'isa-extension-button isa-extension-button--secondary';
if (client.supports('pickFolder')) actions.append(pickFolder);
const importButton = button(text.import, () => run(onImport));
importButton.className = 'isa-extension-button isa-extension-button--secondary';
importButton.prepend(icon('import'));
if (onImport && client.supports('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 recentTitle = element('h2', text.recent);
const recentCount = element('span', '', 'isa-group-count');
recentTitle.append(recentCount);
activity.append(recentTitle, recent);
const panel = element('section', '', 'isa-group-projects');
const heading = element('header');
const create = button('+ ' + (client.groupFolder ? text.newProject : text.create), () => { name.value = ''; formError.textContent = ''; dialog.showModal(); name.focus(); });
const create = button(client.groupFolder ? text.newProject : text.create, () => { name.value = ''; formError.textContent = ''; dialog.showModal(); name.focus(); });
create.className = 'isa-extension-button isa-extension-button--primary';
create.prepend(icon('plus'));
const panelTitle = element('h2', text.projects);
const projectCount = element('span', '', 'isa-group-count');
panelTitle.append(projectCount);
panelTitle.id = 'isa-projects-' + crypto.randomUUID();
panel.setAttribute('aria-labelledby',panelTitle.id);
heading.append(panelTitle);
if (client.supports('create')) heading.append(create);
const controls = element('div', '', 'isa-project-toolbar');
const search = element('input');
search.className = 'isa-extension-input';
search.type = 'search';
search.placeholder = text.search;
search.setAttribute('aria-label',text.search);
const sort = element('select');
sort.className = 'isa-extension-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);
@@ -88,7 +105,9 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
root.append(grid,dialog);
target.append(root);
let projects = [], recents = [], loading = true, hasInventory = false, busy = false, alive = true, generation = 0;
let projects = [], recents = [], loading = true, hasInventory = false, busy = false, alive = true;
let pendingRefresh, openingId;
const byName = new Intl.Collator(locale);
const date = new Intl.DateTimeFormat(locale,{dateStyle:'medium'});
// The host focuses an extension iframe on pointer-down. Preserve matching
// buttons through that refresh so the subsequent click reaches the same row.
@@ -104,8 +123,8 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
}
}
existing.delete(project.id);
row.onclick = () => run(() => client.openListed(project));
row.disabled = busy;
row.onclick = () => openProject(project);
row.setAttribute('aria-busy', String(openingId === project.id));
const firstUse = project.hasInstance === false && project.canWrite && !project.archived;
if (detailed) {
row.querySelector('strong').textContent = project.name;
@@ -120,40 +139,73 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
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));
visible.sort((a,b) => (sort.value === 'updated' && (Date.parse(b.updatedAt) || 0) - (Date.parse(a.updatedAt) || 0)) || byName.compare(a.name,b.name));
list.setAttribute('aria-busy', String(loading));
columns.hidden = !visible.length;
updateRows(list, visible, true);
status.textContent = hasInventory && !visible.length ? (needle ? text.noMatches : text.noProjects) : '';
updateRows(recent, recents.map(item => projects.find(project => project.id === item.id)).filter(Boolean), false);
if (!recent.childElementCount && hasInventory) recent.append(element('p',text.noActivity));
pickFolder.disabled = busy; create.disabled = busy; importButton.disabled = busy; refreshButton.disabled = busy || loading;
}
async function refresh() {
const ticket = ++generation;
loading = true; alert.textContent = ''; draw();
try {
const inventory = await client.list();
if (alive && ticket === generation) {
projects = inventory.filter(p => !p.archived);
hasInventory = true;
if (!busy) {
let message = '';
if (loading) message = text.loading;
else if (hasInventory && !visible.length) {
if (needle) message = text.noMatches;
else if (showEmptyProjectMessage) message = text.noProjects;
}
} catch (error) {
if (alive && ticket === generation) {
if (client.sharedProjectsFolder) projects = [];
hasInventory = false;
alert.textContent = error.code === 'SHARED_GROUP_PROJECTS_UNAVAILABLE' ? text.updateHost : String(error.message ?? error);
}
} finally {
if (alive && ticket === generation) { loading = false; draw(); }
status.textContent = message;
}
const recentProjects = recents.map(item => projects.find(project => project.id === item.id)).filter(Boolean);
updateRows(recent, recentProjects, false);
projectCount.textContent = hasInventory ? String(visible.length) : '';
recentCount.textContent = hasInventory ? String(recentProjects.length) : '';
if (!recent.childElementCount && hasInventory) recent.append(element('p',text.noActivity));
syncControls();
}
async function run(action, notice = alert) {
function syncControls() {
pickFolder.disabled = create.disabled = importButton.disabled = busy;
refreshButton.disabled = busy || loading;
refreshButton.setAttribute('aria-busy', String(loading));
list.inert = recent.inert = busy;
}
function openProject(project) {
if (busy) return;
busy = true; notice.textContent = ''; form.inert = true; draw();
openingId = project.id;
for (const container of [list, recent]) {
const row = container.querySelector('[data-project-id="' + CSS.escape(project.id) + '"]');
row?.setAttribute('aria-busy', 'true');
}
void run(() => client.openListed(project), alert, text.opening + ' ' + project.name);
}
function refresh() {
if (pendingRefresh) return pendingRefresh;
loading = true;
alert.textContent = '';
if (!busy) status.textContent = text.loading;
list.setAttribute('aria-busy','true');
syncControls();
pendingRefresh = Promise.resolve().then(() => client.list()).then(inventory => {
if (!alive) return;
projects = inventory.filter(p => !p.archived);
hasInventory = true;
}).catch(error => {
if (!alive) return;
if (client.sharedProjectsFolder) projects = [];
hasInventory = false;
alert.textContent = error.code === 'SHARED_GROUP_PROJECTS_UNAVAILABLE' ? text.updateHost : String(error.message ?? error);
}).finally(() => {
pendingRefresh = null;
if (alive) { loading = false; draw(); }
});
return pendingRefresh;
}
async function run(action, notice = alert, message = text.loading) {
if (busy) return;
busy = true;
notice.textContent = '';
status.textContent = message;
form.inert = true;
syncControls();
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(); } }
finally { if (alive) { busy = false; openingId = null; form.inert = false; draw(); } }
}
dialog.oncancel = event => { if (busy) event.preventDefault(); };
form.onsubmit = event => {