diff --git a/Docs/Relationships/Workspace.md b/Docs/Relationships/Workspace.md index d06bb304..cf330234 100644 --- a/Docs/Relationships/Workspace.md +++ b/Docs/Relationships/Workspace.md @@ -65,3 +65,7 @@ The observer now distinguishes text/decorative caption updates on already bound Maximise retains its existing PWA ribbon placement and behaviour; the browser control is also unchanged. `relationship-focus-stability.cjs` exercises diagram-node focus changes, short/long captions, rapid sequences and clearing focus in browser/PWA presentation at 1440px and 1700px. It samples the header, workspace, four palettes/panels, canvas and timeline on every animation frame, asserts the ribbon nodes remain identical with zero rebuilds, and checks graph instance, node positions, zoom, Details and Focus updates. Existing ribbon, workspace and shared-toolbar tests remain regression gates. + +### Focus action spacing + +The initial stability styling reserved unequal 150px/65px slots, leaving an uneven group and clipping the long Clear caption. Expanded PWA Focus actions now use equal compact widths with the normal ribbon gap. The label is explicitly Clear focus. Its ribbon binding stays visible but disabled while its canonical source is hidden (no character focused), avoiding an empty reserved slot or a width change. The web control retains its existing hiding behaviour. Regression checks cover balanced geometry, the complete Clear label, enabling/disabling and unchanged workspace bounds at 1440/1700/1920px. diff --git a/PlotLine.Tests/Browser/relationship-focus-stability.cjs b/PlotLine.Tests/Browser/relationship-focus-stability.cjs index 483073df..17f47818 100644 --- a/PlotLine.Tests/Browser/relationship-focus-stability.cjs +++ b/PlotLine.Tests/Browser/relationship-focus-stability.cjs @@ -4,12 +4,21 @@ const base='http://127.0.0.1:5238'; (async()=>{ const browser=await chromium.launch(); try { - for(const pwa of [false,true]) for(const width of [1440,1700]) { + for(const pwa of [false,true]) for(const width of [1440,1700,1920]) { const context=await browser.newContext({viewport:{width,height:1000}}); if(pwa) await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true})); const page=await context.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message)); await page.goto(base+'/fixture?page=relationships',{waitUntil:'domcontentloaded'}); await page.waitForFunction(()=>!!window.PlotDirectorRelationshipWorkspace); + if(pwa && width===1920) { + await page.getByRole('tab',{name:'Characters',exact:true}).click(); + await page.waitForFunction(()=>document.querySelector('[data-pwa-context-controls] .pd-context-group[aria-label="Focus"] details')?.dataset.compact==='false'); + const spacing=await page.evaluate(()=>{const group=document.querySelector('[data-pwa-context-controls] .pd-context-group[aria-label="Focus"]');const buttons=[...group.querySelectorAll('button')];return {compact:group.querySelector('details').dataset.compact,rects:buttons.map(b=>b.getBoundingClientRect().toJSON()),clear:buttons[1].textContent.trim(),disabled:buttons[1].disabled,clipped:buttons[1].querySelector('span').scrollWidth>buttons[1].querySelector('span').clientWidth+1}}); + assert.equal(spacing.compact,'false');assert.equal(spacing.clear,'Clear focus');assert(spacing.disabled,'Clear focus is disabled without a focus'); + assert(spacing.rects.every(r=>r.width>0&&r.height>0),'both actions present without an empty slot'); + assert(Math.abs(spacing.rects[0].width-spacing.rects[1].width)<1,'balanced action widths'); + assert(spacing.rects[1].x-spacing.rects[0].right<=8,'normal compact ribbon gap');assert(!spacing.clipped,'Clear focus is not truncated'); + } const result=await page.evaluate(async()=>{ const frame=()=>new Promise(r=>requestAnimationFrame(r)); await frame();await frame();await frame(); const w=window.PlotDirectorRelationshipWorkspace, cy=w.cy, canvas=document.getElementById('relationshipMapGraph'); @@ -30,6 +39,8 @@ const base='http://127.0.0.1:5238'; for(const id of [1,2,3,2,1,3]) { cy.$id(`c-${id}`).emit('tap');samples.push(bounds()); for(let f=0;f<5;f++){await frame();samples.push(bounds())} + const clearProxy=controls.querySelector('[data-command-identity="handler:rwClearFocus"]'); + if(clearProxy && clearProxy.disabled) throw new Error('Clear action did not enable on focus'); if(document.querySelector('[data-map-detail-title]').textContent!==w.cast.find(c=>c.characterID===id).characterName) throw new Error('Details did not track focus'); if(!cy.$id(`c-${id}`).hasClass('is-focus'))throw new Error('Graph focus did not update'); } @@ -39,6 +50,8 @@ const base='http://127.0.0.1:5238'; document.getElementById('rwClearFocus').click(); for(let f=0;f<5;f++){await frame();samples.push(bounds())} observer.disconnect(); + const clearProxy=controls.querySelector('[data-command-identity="handler:rwClearFocus"]'); + if(clearProxy && !clearProxy.disabled) throw new Error('Clear action did not disable after clearing'); const sameNodes=nodes.length===controls.children.length&&nodes.every((n,i)=>n===controls.children[i]); return {baseline,samples,rebuilds,sameNodes,caption,tooltip,long,positionsUnchanged:positions.every(({id,p})=>Math.abs(cy.$id(id).position().x-p.x)<.01&&Math.abs(cy.$id(id).position().y-p.y)<.01),sameGraph:w.cy===cy&&document.getElementById('relationshipMapGraph')===canvas,zoom:cy.zoom(),clearLabel:focusButton?.textContent.trim()}; }); diff --git a/PlotLine.Tests/Browser/relationships-ribbon.cjs b/PlotLine.Tests/Browser/relationships-ribbon.cjs index 0b4482bb..945c3efb 100644 --- a/PlotLine.Tests/Browser/relationships-ribbon.cjs +++ b/PlotLine.Tests/Browser/relationships-ribbon.cjs @@ -52,7 +52,7 @@ const base='http://127.0.0.1:5238'; 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'); + await (await command('Clear 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'); diff --git a/PlotLine/Views/RelationshipMap/Index.cshtml b/PlotLine/Views/RelationshipMap/Index.cshtml index ee771ea1..32b4bcbe 100644 --- a/PlotLine/Views/RelationshipMap/Index.cshtml +++ b/PlotLine/Views/RelationshipMap/Index.cshtml @@ -12,7 +12,7 @@ -
+
diff --git a/PlotLine/wwwroot/css/relationship-workspace.css b/PlotLine/wwwroot/css/relationship-workspace.css index 91614cc3..b76fff77 100644 --- a/PlotLine/wwwroot/css/relationship-workspace.css +++ b/PlotLine/wwwroot/css/relationship-workspace.css @@ -158,12 +158,12 @@ body.rw-page [data-pwa-context-controls] .pd-context-form[data-pwa-fields="stack html[data-standalone="true"] body.rw-page:has(#rwApp.rw-maximised) .pd-application-header .pd-titlebar, html[data-standalone="true"] body.rw-page:has(#rwApp.rw-maximised) .pd-application-header .pd-ribbon-heading { display: none; } -/* Reserve focus and clear-action space across short/long captions and clear state. */ +/* Equal compact actions keep Focus balanced and stable in both focus states. */ body.rw-page [data-pwa-context-controls] .pd-context-group[aria-label="Focus"] details[data-compact="false"] > .pd-ribbon-commands { - display: grid; grid-template-columns: 150px 65px; gap: 4px; width: 219px; + width: 196px; } -body.rw-page [data-pwa-context-controls] .pd-context-group[aria-label="Focus"] .pd-context-command { - width: 100%; min-width: 0; max-width: 100%; +body.rw-page [data-pwa-context-controls] .pd-context-group[aria-label="Focus"] details[data-compact="false"] > .pd-ribbon-commands > .pd-context-command { + flex: 0 0 96px; width: 96px; min-width: 0; } body.rw-page [data-pwa-context-controls] .pd-context-group[aria-label="Focus"] .pd-context-command > span { display: block; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; diff --git a/PlotLine/wwwroot/js/application-page-context.js b/PlotLine/wwwroot/js/application-page-context.js index e6eba377..2cc1684f 100644 --- a/PlotLine/wwwroot/js/application-page-context.js +++ b/PlotLine/wwwroot/js/application-page-context.js @@ -177,11 +177,13 @@ function bindState(source, target) { boundCommands.add(source); const update = () => { - const disabled = source.matches(':disabled, .disabled, [aria-disabled="true"]'); + const sourceHidden = !!source.closest('[hidden]'); + const keepVisible = source.dataset.pwaKeepVisible === 'true'; + const disabled = source.matches(':disabled, .disabled, [aria-disabled="true"]') || (keepVisible && sourceHidden); if ('disabled' in target) target.disabled = disabled; target.setAttribute('aria-disabled', String(disabled)); target.tabIndex = disabled ? -1 : 0; - target.hidden = !!source.closest('[hidden]'); + target.hidden = sourceHidden && !keepVisible; 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);