From b5e4de262680c1c9034cfbdcf7c68d45baee83d7 Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Fri, 20 Nov 2026 10:15:48 +0000 Subject: [PATCH] Correct Writer contextual ribbon icons and remove stray layout Help --- .../Browser/writer-icon-corrections.cjs | 17 +++++++++++++++++ PlotLine/Services/RibbonPresentation.cs | 5 +++++ PlotLine/Views/ManuscriptReader/_Reader.cshtml | 2 +- PlotLine/Views/Shared/_ApplicationShell.cshtml | 2 +- PlotLine/wwwroot/js/application-page-context.js | 7 +++++++ PlotLine/wwwroot/js/manuscript-reader.js | 2 +- 6 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 PlotLine.Tests/Browser/writer-icon-corrections.cjs diff --git a/PlotLine.Tests/Browser/writer-icon-corrections.cjs b/PlotLine.Tests/Browser/writer-icon-corrections.cjs new file mode 100644 index 00000000..3a9a349f --- /dev/null +++ b/PlotLine.Tests/Browser/writer-icon-corrections.cjs @@ -0,0 +1,17 @@ +const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs'); +(async()=>{const installed=process.argv.includes('--installed'),profile=fs.mkdtempSync('/tmp/pd-icon-pwa-');const c=installed?await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1666,height:1050}}):await(await chromium.launch()).newContext({viewport:{width:1666,height:1050}});const b=c.browser(),base='http://127.0.0.1:5238';try{ +await c.addInitScript(()=>localStorage.setItem('plotdirector.desktop.v1.4',JSON.stringify({dismissedAt:Date.now()}))); +await c.route('**/native-companion/status*',r=>r.fulfill({json:{leases:[]}})); +let p;if(installed){const tab=c.pages()[0];await tab.goto(base+'/fixture');const d=await b.newBrowserCDPSession(),manifestId=base+'/Projects';await d.send('PWA.install',{manifestId,installUrlOrBundleUrl:base+'/fixture'});await d.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'});const opened=c.waitForEvent('page');await d.send('PWA.launch',{manifestId,url:base+'/fixture'});p=await opened;await p.waitForLoadState();assert(await p.evaluate(()=>matchMedia('(display-mode: standalone)').matches));}else p=await c.newPage(); +await p.goto(base+'/Writer/Review?projectId=7&bookId=12&chapterId=21'); +assert.equal(await p.locator('#ribbon-panel-writer [data-help-key="writer3.layout"]').count(),0); +assert(await p.locator('#ribbon-tab-help').isVisible());assert.equal(await p.locator('[data-ribbon-word] .pd-destination-badge').count(),3); +const mappings={'reader-prev':'back','reader-next':'next','reader-focus':'maximise','reader-audio':'headphones','reader-pause-toggle':'pause-circle','reader-apply-update':'refresh'}; +for(const [id,key]of Object.entries(mappings))assert.equal(await p.locator('#'+id).evaluate(n=>window.PlotDirectorCommands.iconKey(n)),key); +for(const [id,key]of [['reader-focus','minimise'],['reader-pause-toggle','play-circle']]){await p.locator('#'+id).evaluate(n=>{n.click()});assert.equal(await p.locator('#'+id).evaluate(n=>window.PlotDirectorCommands.iconKey(n)),key);} +await p.locator('#reader-focus').evaluate(n=>n.click()); +assert.equal(await p.locator('[data-review-record]').evaluate(n=>window.PlotDirectorCommands.iconKey(n)),'comment-add'); +if(installed)await p.locator('#ribbon-panel-writer [data-ribbon-icon=comment-add]').waitFor(); +for(const theme of ['modern-light','modern-dark'])for(const width of [1666,800]){await p.setViewportSize({width,height:1050});await p.evaluate(t=>window.PlotDirectorApplyApplicationTheme(t),theme);assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));fs.mkdirSync('/tmp/pd-icon-evidence',{recursive:true});await p.locator('[data-ribbon-shell]').screenshot({path:`/tmp/pd-icon-evidence/${installed?'pwa':'browser'}-${theme}-${width}.png`});} +console.log('PASS '+(installed?'installed PWA':'browser')+' icon mappings, stateful icons, scoped Help removal, Word badges, themes and widths'); +}finally{await c.close();await b.close();fs.rmSync(profile,{recursive:true,force:true});}})().catch(e=>{console.error(e);process.exitCode=1}); diff --git a/PlotLine/Services/RibbonPresentation.cs b/PlotLine/Services/RibbonPresentation.cs index 211ff329..503e160b 100644 --- a/PlotLine/Services/RibbonPresentation.cs +++ b/PlotLine/Services/RibbonPresentation.cs @@ -45,6 +45,11 @@ public static class RibbonPresentation return null; } public static IReadOnlyList AdditionalIcons { get; } = [ + new("minimise", "M3 9h6V3 M21 9h-6V3 M3 15h6v6 M21 15h-6v6", "planning"), + new("headphones", "M4 14v-3a8 8 0 0 1 16 0v3 M4 12H2v8h5v-8z M20 12h2v8h-5v-8z", "review"), + new("comment-add", "M21 14V3H3v14h5l4 4v-4h9z M8 10h8 M12 6v8", "review"), + new("pause-circle", "M21 12a9 9 0 1 0-18 0 9 9 0 0 0 18 0 M9 8v8 M15 8v8", "review"), + new("play-circle", "M21 12a9 9 0 1 0-18 0 9 9 0 0 0 18 0 M10 7l7 5-7 5z", "review"), new("back", "M19 12H5m7-7-7 7 7 7", "planning"), new("undo", "M9 4L3 10l6 6 M3 10h10a7 7 0 0 1 7 7v3", "planning"), new("redo", "M15 4l6 6-6 6 M21 10H11a7 7 0 0 0-7 7v3", "planning"), diff --git a/PlotLine/Views/ManuscriptReader/_Reader.cshtml b/PlotLine/Views/ManuscriptReader/_Reader.cshtml index e86ab0c7..855b0eb3 100644 --- a/PlotLine/Views/ManuscriptReader/_Reader.cshtml +++ b/PlotLine/Views/ManuscriptReader/_Reader.cshtml @@ -44,7 +44,7 @@ @if(Model.IntegratedReview){} diff --git a/PlotLine/Views/Shared/_ApplicationShell.cshtml b/PlotLine/Views/Shared/_ApplicationShell.cshtml index 743f04cd..1f1378f1 100644 --- a/PlotLine/Views/Shared/_ApplicationShell.cshtml +++ b/PlotLine/Views/Shared/_ApplicationShell.cshtml @@ -166,7 +166,7 @@ } } @if(category.Key=="writer"&&group.Label=="Utilities"){ - + } @group.Label diff --git a/PlotLine/wwwroot/js/application-page-context.js b/PlotLine/wwwroot/js/application-page-context.js index 28b523ca..6f53c60b 100644 --- a/PlotLine/wwwroot/js/application-page-context.js +++ b/PlotLine/wwwroot/js/application-page-context.js @@ -59,6 +59,10 @@ return `${operation || 'navigate'}:${url.origin}:${path}:${JSON.stringify(values)}:${url.hash}`; } function iconKey(source) { + const readerIcons = { 'reader-prev':'back', 'reader-next':'next', 'reader-focus':source.getAttribute('aria-pressed')==='true'?'minimise':'maximise', 'reader-audio':'headphones', 'reader-pause-toggle':source.getAttribute('aria-pressed')==='true'?'play-circle':'pause-circle', 'reader-apply-update':'refresh' }; + if (readerIcons[source.id]) return readerIcons[source.id]; + if (source.matches('[data-review-new],[data-review-record]')) return 'comment-add'; + if (source.matches('[data-pwa-label="Reading mode"]')) return 'bible'; if (source.dataset.ribbonIcon) return source.dataset.ribbonIcon; if (source.dataset.pwaIcon) return source.dataset.pwaIcon; if (source.closest('form')?.dataset.pwaIcon) return source.closest('form').dataset.pwaIcon; @@ -190,6 +194,9 @@ if (source.hasAttribute(attribute)) target.setAttribute(attribute, source.getAttribute(attribute)); else target.removeAttribute(attribute); } + const key = iconKey(source); + if (target.dataset.ribbonIcon !== key) { target.querySelector('svg')?.remove(); const svg = icons?.querySelector(`[data-icon-key="${key}"]`)?.cloneNode(true); if(svg){svg.removeAttribute('data-icon-key');target.prepend(svg);} target.dataset.ribbonIcon=key; } + target.setAttribute('aria-label', source.getAttribute('aria-label') || source.title || caption(source)); target.classList.toggle('is-active', source.getAttribute('aria-pressed') === 'true'); if (source.matches('button')) { const label = caption(source); diff --git a/PlotLine/wwwroot/js/manuscript-reader.js b/PlotLine/wwwroot/js/manuscript-reader.js index bc9976dd..74611176 100644 --- a/PlotLine/wwwroot/js/manuscript-reader.js +++ b/PlotLine/wwwroot/js/manuscript-reader.js @@ -62,7 +62,7 @@ }; const pending = () => observedVersion !== displayedVersion; const indicate = () => { - apply.hidden = !pending();if(pauseToggle){pauseToggle.setAttribute('aria-pressed',String(pause.checked));pauseToggle.textContent=pause.checked?'Resume updates':'Pause updates';pauseToggle.title=pause.checked?'Resume automatic accepted manuscript updates':'Pause automatic accepted manuscript updates';} + apply.hidden = !pending();if(pauseToggle){pauseToggle.setAttribute('aria-pressed',String(pause.checked));pauseToggle.textContent=pause.checked?'Resume updates':'Pause updates';pauseToggle.title=pause.checked?'Resume automatic manuscript updates':'Pause automatic manuscript updates';} if (!pending()) message.textContent = pause.checked ? "Automatic updates paused." : "Checking for accepted chapter changes automatically."; else message.textContent = hasSelection() ? 'Updated chapter available. It will appear after you clear the text selection.'