Correct Writer contextual ribbon icons and remove stray layout Help
This commit is contained in:
parent
5a0eba4570
commit
b5e4de2626
17
PlotLine.Tests/Browser/writer-icon-corrections.cjs
Normal file
17
PlotLine.Tests/Browser/writer-icon-corrections.cjs
Normal file
@ -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});
|
||||
@ -45,6 +45,11 @@ public static class RibbonPresentation
|
||||
return null;
|
||||
}
|
||||
public static IReadOnlyList<RibbonIcon> 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"),
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
@if(Model.IntegratedReview){<button type="button" class="btn btn-outline-primary" data-review-record data-pwa-context="Annotations" data-pwa-label="Add annotation" title="Record a chapter, verified scene or selected passage annotation">Record an observation</button>}
|
||||
<p class="reader-status" role="status" id="reader-loading" hidden>Loading chapter…</p>
|
||||
<div class="reader-status reader-live-controls" hidden>
|
||||
<input type="checkbox" id="reader-pause" hidden /><button type="button" id="reader-pause-toggle" class="btn btn-outline-secondary btn-sm" aria-pressed="false" data-pwa-context="Synchronisation" title="Pause automatic accepted manuscript updates">Pause updates</button>
|
||||
<input type="checkbox" id="reader-pause" hidden /><button type="button" id="reader-pause-toggle" class="btn btn-outline-secondary btn-sm" aria-pressed="false" data-pwa-context="Synchronisation" title="Pause automatic manuscript updates">Pause updates</button>
|
||||
<span role="status" aria-live="polite" id="reader-update-status"></span>
|
||||
<button type="button" id="reader-apply-update" data-pwa-context="Synchronisation" data-pwa-keep-visible="true" title="Show the newly accepted chapter" class="btn btn-outline-secondary btn-sm" hidden>Show updated chapter</button>
|
||||
</div>
|
||||
|
||||
@ -166,7 +166,7 @@
|
||||
}
|
||||
}
|
||||
@if(category.Key=="writer"&&group.Label=="Utilities"){
|
||||
<button type="button" class="pd-ribbon-command" data-writer-companion-toggle hidden aria-pressed="false"><svg class="pd-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="@ApplicationRibbon.Icon("threads").IconPath" /></svg><span>Companion</span></button><help-icon key="writer3.layout" />
|
||||
<button type="button" class="pd-ribbon-command" data-writer-companion-toggle hidden aria-pressed="false"><svg class="pd-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="@ApplicationRibbon.Icon("threads").IconPath" /></svg><span>Companion</span></button>
|
||||
}
|
||||
</div>
|
||||
<span class="pd-ribbon-group-label">@group.Label</span>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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.'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user