Integrate Relationships workspace controls with the PWA ribbon

This commit is contained in:
Nick Beckley 2026-10-31 20:51:51 +00:00
parent 6a9b79e6be
commit a9ec410406
8 changed files with 94 additions and 17 deletions

View File

@ -39,3 +39,9 @@ The timeline retains its existing state resolver, range keyboard navigation and
At 800px and below, the four permanent palettes become one drawer: existing character entries move into it and return to their desktop homes on resize. No repeated portrait lists are introduced. Selecting a character dismisses the drawer; Details is independently available. The v1 position/pan/zoom/focus storage and canonical server/save code are unchanged in this pass.
Browser regression coverage additionally checks viewport bounds, complete mobile cast access, Map/List replacement, focus clearing, select/pan controls, maximise/restore and all four principal themes (True Light/Dark use `modern-light`/`modern-dark` theme keys). The normal 75-character/300-scene interactions remain covered. Visual checks use the isolated compiled-Razor fixture; live authenticated author data has not been changed. No schema work or automatic importance inference was added.
## PWA ribbon integration
Relationships declares its existing toolbar controls as normal `data-pwa-context` contributions. The shell binds commands and form fields to their live sources; there is no second focus, view or maximise state. Layout and Display request the existing compact ribbon menus. A small shared renderer extension honours `data-pwa-compact` for such contributions and copies explicitly declared passive legend content without IDs or interactive controls. Help uses the standard page-help contribution.
Only in standalone mode, accounted contributions suppress the entire secondary toolbar and remove its grid row. The existing viewport measurement gives the space to the canvas. Browser presentation and all importance thresholds, cast assignment, graph, timeline, dialog and persistence logic remain unchanged. PWA maximise keeps the ribbon reachable so its Restore command remains available. `relationships-ribbon.cjs` covers command/state binding, menus, recovered height, mobile overflow and navigation cleanup; the existing relationship and PWA browser suites remain regression gates.

View File

@ -15,7 +15,8 @@
"test:scene-workspace": "xvfb-run -a node scene-workspace.cjs",
"test:desktop-promotion": "node desktop-promotion.cjs",
"test:record-workspaces": "node record-workspaces.cjs",
"test:relationships": "node relationship-workspace.cjs"
"test:relationships": "node relationship-workspace.cjs",
"test:relationships-ribbon": "node relationships-ribbon.cjs"
},
"devDependencies": {
"chart.js": "4.4.9",

View File

@ -0,0 +1,50 @@
const {chromium}=require('playwright');
const assert=require('node:assert/strict');
const base='http://127.0.0.1:5238';
(async()=>{
const browser=await chromium.launch(); const errors=[];
try {
const context=await browser.newContext({viewport:{width:1700,height:1000}});
const web=await context.newPage();web.on('pageerror',e=>errors.push(e.message));
await web.goto(base+'/fixture?page=relationships');await web.waitForFunction(()=>!!window.PlotDirectorRelationshipWorkspace);
assert(await web.locator('.rw-toolbar').isVisible(),'browser toolbar remains');
const webRow=await web.locator('#rwApp').evaluate(e=>getComputedStyle(e).gridTemplateRows.split(' ')[0]);assert.equal(webRow,'44px');
const appContext=await browser.newContext({viewport:{width:1700,height:1000}});
await appContext.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));
const app=await appContext.newPage();app.on('pageerror',e=>errors.push(e.message));
await app.goto(base+'/fixture?page=relationships');await app.waitForFunction(()=>!!window.PlotDirectorRelationshipWorkspace);
assert(await app.locator('.rw-toolbar').isHidden(),'PWA has no second toolbar');
const shell=app.locator('[data-pwa-context-controls]');
async function command(name){
const target=shell.getByRole('button',{name,exact:true,includeHidden:true});assert.equal(await target.count(),1,'single ribbon command '+name);
await target.evaluate(e=>{for(let n=e.parentElement;n;n=n.parentElement)if(n.tagName==='DETAILS')n.open=true;});
return target;
}
for(const name of ['Map','List','Full cast','Details','Add relationship','Auto-arrange','Remove focused from map','Reset layout','Characters','Maximise workspace']) await command(name);
for(const name of ['View','Focus','Relationship','Arrange','Layout','Display']) assert(await shell.locator(`.pd-context-group[aria-label="${name}"]`).count(),name+' group');
assert(await shell.locator('[data-help-open]').count(),'Help uses ribbon help');
assert(await shell.locator('.relationship-map-legend-grid').count(),'Display includes existing legend');
assert(await shell.locator('select').count()>=4,'Display retains story selectors');
const geometry=await app.locator('#rwApp').evaluate(e=>({top:e.getBoundingClientRect().top,board:document.getElementById('rwBoard').getBoundingClientRect().top,rows:getComputedStyle(e).gridTemplateRows.split(' ').length}));
assert.equal(geometry.rows,1,'no reserved toolbar grid row');assert(Math.abs(geometry.board-geometry.top)<2,'palettes start immediately, recovered space used');
await (await command('List')).click();assert(await app.locator('#rwListPanel').isVisible());assert.equal(await (await command('List')).getAttribute('aria-pressed'),'true');
await (await command('Map')).click();assert(await app.locator('#rwBoard').isVisible());
await app.locator('[data-rw-character="1"]').click();
await app.waitForFunction(()=>[...document.querySelectorAll('[data-pwa-context-controls] button')].some(b=>b.textContent.includes('Focus: Élan Vale')));
assert.equal(await (await command('Focus: Élan Vale')).count(),1);
await (await command('Clear character focus')).click();await app.waitForFunction(()=>document.getElementById('rwFocusName').textContent==='Full cast');
assert.equal(await (await command('Full cast')).count(),1);
await (await command('Details')).click();assert(await app.locator('#rwDetailPanel').isVisible());
await (await command('Add relationship')).click();assert(await app.locator('#rwDialog').evaluate(e=>e.open));await app.keyboard.press('Escape');
await app.evaluate(()=>{window.__layouts=0;window.PlotDirectorRelationshipWorkspace.cy.on('layoutstop',()=>window.__layouts++);});
await (await command('Auto-arrange')).click();assert(await app.evaluate(()=>window.__layouts>0),'original auto-arrange handler');
await (await command('Characters')).click();assert(await app.locator('#rwBoard').evaluate(e=>e.classList.contains('palettes-hidden')));await (await command('Characters')).click();
await (await command('Maximise workspace')).click();assert(await app.locator('#rwApp').evaluate(e=>e.classList.contains('rw-maximised')));
assert(await shell.isVisible(),'ribbon remains reachable while maximised');
await (await command('Restore workspace')).click();assert(!(await app.locator('#rwApp').evaluate(e=>e.classList.contains('rw-maximised'))));
await app.setViewportSize({width:390,height:900});await (await command('Characters')).click();assert(await app.locator('.rw-navigation').isVisible(),'mobile cast opens via existing ribbon overflow');
assert(await app.locator('.rw-toolbar').isHidden());
await app.goto(base+'/fixture');assert.equal(await app.locator('[data-pwa-context-controls]').getByRole('button',{name:'Add relationship',exact:true}).count(),0,'navigation clears relationship contributions');
assert.deepEqual(errors,[]);console.log('PASS Relationships ribbon: browser fallback, PWA controls/state/menus, recovered height, mobile overflow and navigation cleanup');
} finally {await browser.close();}
})().catch(e=>{console.error(e);process.exitCode=1});

View File

@ -19,6 +19,8 @@ Use it when you want to see family, friendship, romance, conflict, professional
# How To Use It
In the installed PWA, workspace commands appear in the existing ribbon: **View**, **Focus**, **Relationship**, **Arrange**, **Layout** and **Display**. The Focus command shows the current character and offers Clear focus. Layout and Display retain their existing options; narrower windows use the ribbon’s standard overflow menus. The browser version keeps its workspace toolbar. Both presentations control the same map, list, focus and maximise state.
The map sits between four independently scrolling character palettes. **Major** characters appear at the top, **Supporting** characters at the sides, and **Minor / unset** characters at the bottom. These groups preserve the existing importance thresholds (8+, 4–7 and below 4). Search ignores case and accents; the importance filter narrows the palettes immediately. **Layout → Characters** collapses the palettes to give the canvas more room.
Click or tap a character to bring them to the centre and activate Focus Mode. With **Show full network** off, the map shows their immediate connections; with it on, unrelated connections are dimmed. The focus chip in the toolbar names the current character; click it or the canvas target control to centre them, or **×** to clear focus.

View File

@ -7,23 +7,23 @@
<link rel="stylesheet" href="~/css/relationship-workspace.css" asp-append-version="true" />
<section id="rwApp" class="rw-app" aria-label="Relationships workspace">
<header class="rw-toolbar" data-pd-context="workspace">
<h1>Relationships <help-icon key="relationshipMap.overview" /></h1>
<div class="rw-view-switch" role="group" aria-label="Workspace view">
<h1 data-pwa-help>Relationships <help-icon key="relationshipMap.overview" /></h1>
<div class="rw-view-switch" data-pwa-context="View" role="group" aria-label="Workspace view">
<button type="button" class="btn btn-sm" id="rwMapView" aria-pressed="true">Map</button>
<button type="button" class="btn btn-sm" id="rwListView" aria-pressed="false">List</button>
</div>
<div class="rw-focus-chip"><button type="button" id="rwFocusName" title="Centre focused character">Full cast</button><button type="button" id="rwClearFocus" aria-label="Clear character focus" hidden>×</button></div>
<div class="rw-focus-chip" data-pwa-context="Focus"><button type="button" id="rwFocusName" title="Centre focused character">Full cast</button><button type="button" id="rwClearFocus" aria-label="Clear character focus" hidden>×</button></div>
<div class="rw-toolbar-actions">
<button type="button" class="btn btn-outline-secondary btn-sm rw-mobile-only" id="rwCharacters" aria-expanded="false">Characters</button>
<button type="button" class="btn btn-outline-secondary btn-sm" id="rwInfo" aria-expanded="false">Details</button>
<button type="button" class="btn btn-outline-secondary btn-sm" id="rwConnect">Add relationship</button>
<button class="btn btn-outline-secondary btn-sm rw-arrange" type="button" data-map-reset>Auto-arrange</button>
<details class="rw-menu"><summary class="btn btn-outline-secondary btn-sm">Layout</summary><div class="rw-menu-panel">
<button type="button" class="btn btn-outline-secondary btn-sm" data-pwa-context="Relationship" id="rwInfo" aria-expanded="false">Details</button>
<button type="button" class="btn btn-outline-secondary btn-sm" data-pwa-context="Relationship" id="rwConnect">Add relationship</button>
<button class="btn btn-outline-secondary btn-sm rw-arrange" type="button" data-map-reset data-pwa-context="Arrange">Auto-arrange</button>
<details class="rw-menu" data-pwa-context="Layout" data-pwa-compact="true"><summary class="btn btn-outline-secondary btn-sm">Layout</summary><div class="rw-menu-panel">
<button class="btn btn-outline-secondary btn-sm" type="button" id="rwRemove">Remove focused from map</button>
<button class="btn btn-outline-secondary btn-sm" type="button" id="rwReset">Reset layout</button>
<button type="button" class="btn btn-outline-secondary btn-sm" id="rwPalettes" aria-expanded="true">Characters</button>
</div></details>
<details class="rw-menu rw-display"><summary class="btn btn-outline-secondary btn-sm">Display</summary><div class="rw-menu-panel">
<details class="rw-menu rw-display" data-pwa-context="Display" data-pwa-scope="Display" data-pwa-compact="true"><summary class="btn btn-outline-secondary btn-sm">Display</summary><div class="rw-menu-panel">
<form class="relationship-map-controls" method="get" asp-action="Index">
<input type="hidden" name="projectId" value="@Model.Project.ProjectID" />
<div>
@ -57,7 +57,7 @@
<button class="btn btn-primary btn-sm" type="submit">Update Map</button>
<a class="btn btn-outline-secondary btn-sm" asp-action="Index" asp-route-projectId="@Model.Project.ProjectID">Project Start</a>
</form>
<div class="relationship-map-legend-grid">
<div class="relationship-map-legend-grid" data-pwa-ribbon-content>
@foreach (var category in Model.Categories)
{
<span class="relationship-map-legend-item @category.CssClass">
@ -68,7 +68,7 @@
</div>
</div></details>
<button type="button" id="rwMaximise" class="btn btn-outline-secondary btn-sm" aria-label="Maximise workspace" aria-pressed="false" title="Maximise workspace">⛶</button>
<button type="button" data-pwa-context="Display" data-pwa-compact="true" id="rwMaximise" class="btn btn-outline-secondary btn-sm" aria-label="Maximise workspace" aria-pressed="false" title="Maximise workspace">⛶</button>
</div>
</header>
<partial name="_Workspace" model="Model" />

View File

@ -129,3 +129,12 @@ body.app-layout.rw-page .plotline-shell, .plotline-shell.rw-shell { max-width: n
body.app-layout.rw-page .plotline-help-layout{margin-top:0;padding-top:0}body.app-layout.rw-page .plotline-help-main{padding-top:0}
body.app-layout.rw-page > .pd-application-header,
body.app-layout.rw-page .pd-application-header .pd-shell { margin-bottom: 0; }
/* Accounted source controls remain canonical; the shell owns their PWA bindings. */
html[data-standalone="true"] .rw-toolbar:has([data-pwa-accounted="true"]) { display: none; }
html[data-standalone="true"] .rw-app:has(.rw-toolbar [data-pwa-accounted="true"]) { grid-template-rows: minmax(0,1fr); }
html[data-standalone="true"] .rw-app:has(.rw-toolbar [data-pwa-accounted="true"]) .rw-list-panel { grid-row: 1; }
html[data-standalone="true"] .rw-app.rw-maximised { top: var(--rw-ribbon-bottom,4px); }
[data-pwa-context-controls] .relationship-map-legend-grid { display:flex; flex-wrap:wrap; gap:8px; max-width:310px; padding:8px; }
/* Ribbon dropdowns must stay above the maximised application surface. */
html[data-standalone="true"] .rw-app.rw-maximised { z-index: 1010; }

View File

@ -180,7 +180,7 @@
target.setAttribute('aria-disabled', String(disabled));
target.tabIndex = disabled ? -1 : 0;
target.hidden = !!source.closest('[hidden]');
for (const attribute of ['aria-pressed', 'aria-current', 'aria-selected']) {
for (const attribute of ['aria-pressed', 'aria-current', 'aria-selected', 'aria-expanded']) {
if (source.hasAttribute(attribute)) target.setAttribute(attribute, source.getAttribute(attribute));
else target.removeAttribute(attribute);
}
@ -344,17 +344,17 @@
for (const region of contributions) {
if (region.parentElement?.closest('[data-pwa-header], [data-pwa-context]')) continue;
const label = region.dataset.pwaContext || region.dataset.pwaTools || 'Page tools';
if (region.matches('[data-pwa-help]')) { helpSource ||= region.querySelector('h1 [data-help-icon]'); continue; }
if (region.matches('[data-pwa-help]')) { helpSource ||= region.querySelector(region.matches('h1') ? '[data-help-icon]' : 'h1 [data-help-icon]'); continue; }
const commands = region.matches('a, button') ? [region] : region.matches('[data-pwa-context]') ? [...region.querySelectorAll('a, button')] : [...region.querySelectorAll('a.btn, a.dropdown-item, button.btn, button.dropdown-item')];
const supported = commands.filter(node => !node.matches('[data-bs-toggle="dropdown"]'));
const forms = region.matches('form') ? [region] : [...region.querySelectorAll('form')];
// Validate before hiding anything; unsupported editors remain fully usable in the page.
if (forms.some(form => form.querySelector('textarea, select[multiple], input[type="file"], input[type="range"]'))) continue;
helpSource ||= region.querySelector('h1 [data-help-icon]');
helpSource ||= region.querySelector(region.matches('h1') ? '[data-help-icon]' : 'h1 [data-help-icon]');
const formFields = new Set(forms.filter(form => {
if (!form.querySelector('select, input:not([type="hidden"]), textarea')) return false;
const scopeLabel = form.querySelector('select') ? region.dataset.pwaScope || 'Scope' : 'Find';
const target = group(scopeLabel, 10).element;
const target = group(scopeLabel, 10, region.dataset.pwaCompact === 'true').element;
target.parentElement.dataset.essential = 'true';
return renderForm(form, target);
}));
@ -367,8 +367,16 @@
if (command.closest('[data-help-icon]') || formFields.has(command.closest('form'))) continue;
const destructive = command.matches('.text-danger, .btn-outline-danger') || /\/(Archive|Delete)(?:[/?]|$)/i.test(command.closest('form')?.action || '');
const commandGroup = destructive ? 'Manage' : command.dataset.pwaGroup || label;
renderCommand(command, group(commandGroup, Number(region.dataset.pwaPriority ?? (commandGroup === 'Jump to' ? 90 : commandGroup === 'Export' || /management/i.test(commandGroup) ? 80 : 50)), destructive), equivalents, composed);
renderCommand(command, group(commandGroup, Number(region.dataset.pwaPriority ?? (commandGroup === 'Jump to' ? 90 : commandGroup === 'Export' || /management/i.test(commandGroup) ? 80 : 50)), destructive || region.dataset.pwaCompact === 'true'), equivalents, composed);
}
region.querySelectorAll('[data-pwa-ribbon-content]').forEach(source => {
// Explicitly declared, passive content (for example a category legend).
// Interactive fields must use renderForm / renderCommand and their live bindings.
if (source.matches('a,button,input,select,textarea') || source.querySelector('a,button,input,select,textarea')) return;
const copy = source.cloneNode(true);
copy.removeAttribute('id'); copy.querySelectorAll('[id]').forEach(node => node.removeAttribute('id'));
group(label, Number(region.dataset.pwaPriority || 50), region.dataset.pwaCompact === 'true').element.append(copy);
});
if (region.hasAttribute('data-pwa-task')) {
supported.forEach(command => command.dataset.pwaAccounted = 'true');
region.querySelectorAll('.dropdown, .button-row, h1 [data-help-icon], .eyebrow').forEach(node => node.dataset.pwaAccounted = 'true');
@ -396,7 +404,7 @@
if (records.some(record => record.type === 'childList' && (record.target.closest?.(sourceSelector) || [...record.addedNodes, ...record.removedNodes].some(node => node.nodeType === 1 && (node.matches(sourceSelector) || node.querySelector(sourceSelector)))))) { sourceRoots = [main]; queueRefresh(); }
else bindings.forEach(update => update());
});
function observe() { observer.observe(main, { childList: true, subtree: true, attributes: true, attributeFilter: ['disabled', 'hidden', 'aria-disabled', 'aria-pressed', 'aria-current', 'aria-selected', 'class'] }); }
function observe() { observer.observe(main, { childList: true, subtree: true, attributes: true, attributeFilter: ['disabled', 'hidden', 'aria-disabled', 'aria-pressed', 'aria-current', 'aria-selected', 'aria-expanded', 'class'] }); }
window.addEventListener('plotdirector:pwa-mode-changed', () => { refresh(); prepareInitialPresentation(); });
window.addEventListener('plotdirector:context-changed', refresh);
document.addEventListener('click', event => {

View File

@ -4,6 +4,7 @@
document.body.classList.add('rw-page');
let resizeGraph = () => {};
const sizeWorkspace = () => {
app.style.setProperty('--rw-ribbon-bottom', `${(document.querySelector('.pd-application-header')?.getBoundingClientRect().bottom || 0) + 4}px`);
if (!app.classList.contains('rw-maximised')) app.style.height = `${Math.max(260, window.innerHeight - app.getBoundingClientRect().top - 5)}px`;
resizeGraph();
};