Refresh held Intent checklist without interrupting edits
This commit is contained in:
parent
7f440d09ac
commit
8201a780e7
@ -123,20 +123,24 @@ let session, stage = 'login';
|
||||
await panel.locator('[data-entity-key="character:'+person+'"]').waitFor();
|
||||
assert.equal(await search.evaluate(input=>input===document.activeElement),true);
|
||||
assert.equal(session.page.url().endsWith(contextUrl),true,'Palette browsing preserves Context position');
|
||||
stage='held checklist Story Element link and coverage';
|
||||
stage='select and link Story Element in held Context';
|
||||
await panel.locator('[data-entity-key="character:'+person+'"]').getByRole('button',{name:'Select Palette shared name to link'}).click();
|
||||
await items.first().getByRole('button',{name:'Link Palette shared name'}).click();
|
||||
assert.equal(await items.first().getByLabel('Complete',{exact:true}).isChecked(),false);
|
||||
stage='mark Story Element covered independently of completion';
|
||||
await items.first().getByLabel('Palette shared name covered').check();
|
||||
assert.equal(await items.first().getByLabel('Complete',{exact:true}).isChecked(),false);
|
||||
stage='save and read back held checklist coverage';
|
||||
await checklist.getByRole('button',{name:'Save checklist'}).click();
|
||||
await session.page.waitForFunction(() => document.querySelector('[data-checklist-save]').disabled &&
|
||||
!document.querySelector('[data-checklist-items]').inert);
|
||||
assert.deepEqual((await getChecklist()).items[0].links,[{key:'character:'+person,name,covered:true}]);
|
||||
stage='switch to scene checklist and return to chapter';
|
||||
await checklist.getByLabel('Scene checklist').check();
|
||||
await checklist.getByText('No checklist items',{exact:true}).waitFor();
|
||||
await checklist.getByLabel('Scene checklist').uncheck();
|
||||
await items.first().getByLabel('Palette shared name covered').waitFor();
|
||||
stage='collapse Story Elements';
|
||||
await panel.getByText('Story Elements',{exact:true}).click();
|
||||
assert.equal(await panel.locator('[data-intent-palette]').evaluate(details=>details.open),false);
|
||||
stage='invalid and mismatched scope denial';
|
||||
|
||||
@ -13,8 +13,8 @@
|
||||
const paste = get('paste');
|
||||
const events = new AbortController();
|
||||
const listen = (node, event, callback) => node.addEventListener(event, callback, { signal: events.signal });
|
||||
let frame, items = [], prepared = [], busy = false, dirty = false, dragged;
|
||||
let pending, readingPassages, selectedElement, selectedPassage;
|
||||
let frame, items = [], prepared = [], busy = false, dirty = false, dragged, refreshAfterSave = false;
|
||||
let pending, readingPassages, selectedElement, selectedPassage, loadedScope;
|
||||
const passageType = "application/x-plotdirector-intent-passage";
|
||||
const entityType = "application/x-plotdirector-intent-element";
|
||||
|
||||
@ -292,32 +292,47 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function load() {
|
||||
if (busy || dirty) return;
|
||||
readingPassages?.abort();
|
||||
get('passages').hidden = true;
|
||||
selectedPassage = undefined;
|
||||
async function load(preserve = false) {
|
||||
if (busy || dirty) {
|
||||
refreshAfterSave ||= preserve;
|
||||
return;
|
||||
}
|
||||
refreshAfterSave = false;
|
||||
const url = new URL(root.dataset.url, location.origin);
|
||||
for (const [key, value] of Object.entries(scope())) if (value) url.searchParams.set(key, value);
|
||||
const keepVisible = preserve && loadedScope === url.href;
|
||||
// A live invalidation must not cancel a chapter or scene switch.
|
||||
if (preserve && !keepVisible && pending) return;
|
||||
pending?.abort();
|
||||
const controller = new AbortController();
|
||||
pending = controller;
|
||||
const url = new URL(root.dataset.url, location.origin);
|
||||
for (const [key, value] of Object.entries(scope())) if (value) url.searchParams.set(key, value);
|
||||
controls.hidden = true;
|
||||
rows.replaceChildren();
|
||||
get('objective').hidden = true;
|
||||
get('outcome').hidden = true;
|
||||
status.textContent = 'Loading checklist…';
|
||||
if (!keepVisible) {
|
||||
loadedScope = undefined;
|
||||
readingPassages?.abort();
|
||||
get('passages').hidden = true;
|
||||
selectedPassage = undefined;
|
||||
controls.hidden = true;
|
||||
rows.replaceChildren();
|
||||
get('objective').hidden = true;
|
||||
get('outcome').hidden = true;
|
||||
status.textContent = 'Loading checklist…';
|
||||
}
|
||||
try {
|
||||
const next = await request(url, undefined, controller.signal);
|
||||
if (!controller.signal.aborted && root.isConnected) {
|
||||
accept(next);
|
||||
readingPassages?.abort();
|
||||
if (next.canEdit) void loadPassages();
|
||||
}
|
||||
if (controller.signal.aborted || !root.isConnected || busy || dirty) return;
|
||||
if (!keepVisible || next.version !== frame.version || next.canEdit !== frame.canEdit ||
|
||||
next.objective !== frame.objective || next.outcome !== frame.outcome) accept(next);
|
||||
loadedScope = url.href;
|
||||
readingPassages?.abort();
|
||||
if (next.canEdit) void loadPassages();
|
||||
else get('passages').hidden = true;
|
||||
} catch (error) {
|
||||
if (!controller.signal.aborted) status.textContent = error.message;
|
||||
if (!controller.signal.aborted && !dirty && !busy) status.textContent = error.message;
|
||||
} finally {
|
||||
if (!controller.signal.aborted) updateControls();
|
||||
if (pending === controller) {
|
||||
pending = undefined;
|
||||
if (!controller.signal.aborted && !busy && !dirty) updateControls();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -354,6 +369,7 @@
|
||||
status.textContent = 'Fill in each item and add or clear the pasted text before saving.';
|
||||
return;
|
||||
}
|
||||
pending?.abort();
|
||||
busy = true;
|
||||
updateControls();
|
||||
try {
|
||||
@ -366,6 +382,7 @@
|
||||
} finally {
|
||||
busy = false;
|
||||
updateControls();
|
||||
if (!dirty && refreshAfterSave && root.isConnected) void load(true);
|
||||
}
|
||||
});
|
||||
listen(get('preview'), 'click', async () => {
|
||||
@ -406,7 +423,7 @@
|
||||
});
|
||||
|
||||
const instance = {
|
||||
load,
|
||||
refresh: () => load(true),
|
||||
guarded: () => dirty || busy,
|
||||
selectElement(entity) {
|
||||
if (!frame?.canEdit || busy) return;
|
||||
|
||||
@ -104,7 +104,7 @@
|
||||
if (!hint?.projectId || Number(hint.projectId) === projectId) {
|
||||
void refresh();
|
||||
if (!hint?.chapterId || Number(hint.chapterId) === Number(root.dataset.chapterId))
|
||||
void checklist(root.parentElement)?.load();
|
||||
void checklist(root.parentElement)?.refresh();
|
||||
}
|
||||
};
|
||||
connection.on('ContextInvalidated', invalidate);
|
||||
@ -157,12 +157,10 @@
|
||||
checklist(node)?.setScene(next.sceneId);
|
||||
return true;
|
||||
},
|
||||
onCacheInvalidation(hint, node) {
|
||||
if (node && checklist(node)?.guarded()) void instances.get(palette(node))?.refresh();
|
||||
},
|
||||
refreshWhileGuarded: true,
|
||||
onInvalidation(node) {
|
||||
void instances.get(palette(node))?.refresh();
|
||||
void checklist(node)?.load();
|
||||
void checklist(node)?.refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +164,8 @@
|
||||
const relevant=hints.filter(h=>affects(record.tab,h)),hint={...relevant[0],kinds:[...new Set(relevant.map(h=>h.kind))]};
|
||||
lifecycles[record.tab.lifecycle]?.onCacheInvalidation?.(hint,record.node);
|
||||
const customInvalidation=lifecycles[record.tab.lifecycle]?.onInvalidation;
|
||||
if(customInvalidation&&record.mounted&&visible(pane)&&!guarded(record)&&!scopeChanged(record.tab,record.position||position,position)&&customInvalidation(record.node,hint)===true){record.stale=false;continue;}
|
||||
if(customInvalidation&&record.mounted&&visible(pane)&&!scopeChanged(record.tab,record.position||position,position)&&
|
||||
(!guarded(record)||lifecycles[record.tab.lifecycle].refreshWhileGuarded)&&customInvalidation(record.node,hint)===true){record.stale=false;continue;}
|
||||
record.stale=true;
|
||||
}
|
||||
if(affected.has(state.panes[pane.index].tab)){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user