Match Current Focus header dropdown and dismiss after navigation

This commit is contained in:
Nick Beckley 2026-11-20 14:54:47 +00:00
parent 6d2c51a651
commit 42f8769162
5 changed files with 71 additions and 17 deletions

View File

@ -0,0 +1,49 @@
const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs');
const base=process.env.PD_NARRATIVE_TEST_URL||'http://127.0.0.1:5238';
(async()=>{
const installed=process.argv.includes('--installed'),profile=fs.mkdtempSync('/tmp/pd-narrative-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}}),b=c.browser();
try{
await c.route('**/Writer/Work/State?*',r=>r.fulfill({json:{session:null,defaultPauseOnEdit:true}}));
await c.route('**/native-companion/connection-state',r=>r.fulfill({json:{known:false,state:'Disconnected',wordConnected:false}}));
await c.route('**/native-companion/status*',r=>r.fulfill({json:{leases:[]}}));
await c.route('**/signalr.min.js',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(require.resolve('@microsoft/signalr/dist/browser/signalr.min.js'),'utf8')}));
await c.route('**/hubs/**',r=>r.abort());
await c.addInitScript(()=>localStorage.setItem('plotdirector.desktop.v1.4',JSON.stringify({dismissedAt:Date.now()})));
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/Write?projectId=7&bookId=12&objective=true');
await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);
const toggle=p.locator('[data-focus-toggle]'),popup=p.locator('.pd-focus-picker');
const open=async()=>{if(await toggle.getAttribute('aria-expanded')!=='true')await toggle.click();await expectOpen();};
const expectOpen=async()=>assert.equal(await toggle.getAttribute('aria-expanded'),'true');
const closed=async()=>{await p.waitForFunction(()=>document.querySelector('[data-focus-toggle]').getAttribute('aria-expanded')==='false');assert(!await popup.isVisible());};
const set=t=>p.evaluate(t=>window.PlotDirectorNarrativeFocus.set(t),t);
await set({chapterID:21,sceneID:31});
const styles=await p.evaluate(()=>['appProjectMenu','appBookMenu','appNarrativeFocusMenu'].map(id=>{const n=document.getElementById(id),s=getComputedStyle(n),a=getComputedStyle(n,'::after');return [s.fontSize,s.padding,s.gap,s.color,s.borderRadius,a.borderTop,a.borderRight,a.borderLeft,a.marginLeft];}));
assert.deepEqual(styles[2],styles[1]);assert.deepEqual(styles[2].filter((_,i)=>i!==1),styles[0].filter((_,i)=>i!==1));
await open();await p.locator('[data-focus-search]').fill('Departure');await expectOpen();assert.equal(await p.locator('[data-focus-position] option').count(),2);
let release;const gate=new Promise(r=>release=r);await p.route('**/NarrativeFocus/Set',async r=>{await gate;await r.continue();});
await p.locator('[data-focus-position]').selectOption('22/32');await expectOpen();assert.match(await p.locator('[data-narrative-status]').textContent(),/Updating/);release();await closed();await p.unroute('**/NarrativeFocus/Set');assert.match(await toggle.textContent(),/Departure/);
await open();await p.locator('[data-focus-search]').fill('');await p.locator('[data-focus-step="-1"]').click();await closed();
await open();await p.locator('[data-focus-step="1"]').click();await closed();
await open();await p.locator('[data-focus-recent]').selectOption('21/101');await closed();
await open();await p.locator('[data-focus-position]').selectOption('21/');await closed();
await open();await p.route('**/NarrativeFocus/Set',r=>r.fulfill({status:503,json:{message:'Temporary navigation failure. Please retry.'}}));await p.locator('[data-focus-step="1"]').click();await p.waitForFunction(()=>document.querySelector('[data-narrative-status]').textContent.includes('Temporary'));await expectOpen();assert(await p.locator('[data-focus-step="1"]').isEnabled());await p.unroute('**/NarrativeFocus/Set');await p.locator('[data-focus-step="1"]').click();await closed();
assert(await toggle.evaluate(n=>n===document.activeElement),'successful selection returns keyboard focus');
await open();await p.locator('[data-focus-search]').focus();await p.keyboard.press('Escape');await closed();assert(await toggle.evaluate(n=>n===document.activeElement));
await open();await toggle.click();await closed();
await open();await p.locator('main').click({position:{x:5,y:150}});await closed();
for(const width of [1666,950,650])for(const theme of ['modern-light','modern-dark']){
await p.setViewportSize({width,height:1050});await p.evaluate(t=>window.PlotDirectorApplyApplicationTheme?.(t),theme);
const before=await toggle.boundingBox();await p.locator('[data-focus-label]').evaluate(n=>n.textContent='Current Focus: Chapter with a very long title '.repeat(12));
const after=await toggle.boundingBox();assert.equal(after.height,before.height);assert.equal(after.width,before.width);
assert(await p.locator('[data-focus-label]').evaluate(n=>n.scrollWidth>n.clientWidth&&getComputedStyle(n).textOverflow==='ellipsis'));
await open();const box=await popup.boundingBox();assert(box.x>=0&&box.x+box.width<=width+1,'popup fits viewport');
await p.screenshot({path:`/tmp/pd-focus-popup-${installed?'pwa':'browser'}-${width}-${theme}.png`});await p.keyboard.press('Escape');await closed();
}
await open();await p.goto(base+'/Timeline/Index?ProjectID=7&BookID=12');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);await closed();
console.log(`PASS ${installed?'installed PWA':'Chromium'}: matching selector styles; confirmed scene/chapter/previous/next/recent dismissal; pending/failure/retry; search; outside/Escape/toggle/section dismissal; keyboard focus; long-label truncation; light/dark at 1666/950/650px.`);
}finally{await c.close();await b?.close();fs.rmSync(profile,{recursive:true,force:true});}
})().catch(e=>{console.error(e.stack);process.exitCode=1;});

View File

@ -19,6 +19,7 @@ const base=process.env.PD_NARRATIVE_TEST_URL||'http://127.0.0.1:5238';
const url=base+'/Writer/Write?projectId=7&bookId=12&objective=true';await p.goto(url+'&setup=true');
await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);
assert.equal(await p.evaluate(()=>window.PlotDirectorNarrativeFocus.state.sceneID),32,'Writer shares the scene explicitly opened in Timeline');
const openFocus=async()=>{if(await p.locator('[data-focus-toggle]').getAttribute('aria-expanded')!=='true')await p.locator('[data-focus-toggle]').click();};
const state=()=>p.evaluate(()=>window.PlotDirectorNarrativeFocus.state);
const set=t=>p.evaluate(t=>window.PlotDirectorNarrativeFocus.set(t),t);
assert(await set({chapterID:21,sceneID:31}));
@ -33,10 +34,10 @@ const base=process.env.PD_NARRATIVE_TEST_URL||'http://127.0.0.1:5238';
await p.locator('#appBookMenu').click();const leaveDialog=p.waitForEvent('dialog');const leaveClick=p.locator('[data-app-book-choice="13"]').click().catch(error=>{if(!error.message.includes('ERR_ABORTED'))throw error;});const dialog=await leaveDialog;assert.equal(dialog.type(),'beforeunload');await dialog.dismiss();await leaveClick;assert.equal(new URL(p.url()).searchParams.get('bookId'),'12','unsaved objective protects a full book switch');assert.deepEqual(await p.locator('[data-focus-wizard]').evaluate(f=>Object.fromEntries(new FormData(f))),beforeEditor);
await p.locator('[data-focus-cancel]').click();await p.locator('[data-go-objective]').click();await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===31);
assert.equal(await p.locator('[data-objective-location]').textContent(),original);
await p.locator('[data-narrative-focus]>summary').click();await p.locator('button[data-focus-step="1"]').click();await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===101);await p.locator('button[data-focus-step="1"]').click();await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===32,'cross-chapter forward');
await p.locator('button[data-focus-step="-1"]').click();await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===101);
await p.locator('[data-focus-search]').fill('Departure');assert.equal(await p.locator('[data-focus-position] option').count(),2);await p.locator('[data-focus-position]').selectOption('22/32');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===32);await p.locator('[data-focus-search]').fill('');
await p.locator('[data-focus-recent]').selectOption('21/101');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===101);
await p.locator('[data-focus-toggle]').click();await openFocus();await p.locator('button[data-focus-step="1"]').click();await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===101);await openFocus();await p.locator('button[data-focus-step="1"]').click();await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===32,'cross-chapter forward');
await openFocus();await p.locator('button[data-focus-step="-1"]').click();await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===101);
await openFocus();await p.locator('[data-focus-search]').fill('Departure');assert.equal(await p.locator('[data-focus-position] option').count(),2);await p.locator('[data-focus-position]').selectOption('22/32');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===32);await openFocus();await p.locator('[data-focus-search]').fill('');
await openFocus();await p.locator('[data-focus-recent]').selectOption('21/101');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===101);
const other=await c.newPage();await other.goto(url);await other.waitForFunction(()=>window.PlotDirectorNarrativeFocus);await other.evaluate(()=>window.PlotDirectorNarrativeFocus.set({chapterID:22,sceneID:32}));await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===32);
const stale=await state(),token=await p.locator('[data-narrative-focus] [name=__RequestVerificationToken]').inputValue();
const staleResponse=await c.request.post(base+'/NarrativeFocus/Set',{form:{projectId:7,bookId:12,chapterId:21,sceneId:31,version:stale.version-1,__RequestVerificationToken:token}});assert.equal(staleResponse.status(),409);
@ -90,8 +91,8 @@ const base=process.env.PD_NARRATIVE_TEST_URL||'http://127.0.0.1:5238';
const mapScene=await p.locator('#mapStoryScene').inputValue();await set({chapterID:21,sceneID:31});assert.equal(await p.locator('#mapStoryScene').inputValue(),mapScene,'global focus retains map position and journey context');
assert.match(await p.locator('#mapsDetailContent').innerText(),/Harbour morning/);
await p.screenshot({path:`/tmp/pd-narrative-${installed?'pwa':'browser'}-Maps.png`});
await p.goto(base+'/Timeline/Index?ProjectID=7');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus?.state.bookID===12);assert.match(await p.locator('[data-focus-label]').textContent(),/A Distant Shore/);await p.locator('[data-narrative-focus]>summary').click();await p.locator('[data-focus-book]').selectOption('13');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.bookID===13);assert.equal((await state()).sceneID,null);assert.equal(await p.locator('.timeline-scene-card').count(),3,'focus book selection preserves project-wide Timeline');assert(!new URL(p.url()).searchParams.has('BookID'));await p.locator('[data-focus-book]').selectOption('12');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.bookID===12);
await p.locator('[data-focus-position]').selectOption('23/');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.chapterID===23);assert(await p.locator('button[data-focus-step="1"]').isDisabled(),'no following scene after the final empty chapter');assert(await p.locator('button[data-focus-step="-1"]').isEnabled());await p.locator('button[data-focus-step="-1"]').click();await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===32);await set({chapterID:21,sceneID:31});
await p.goto(base+'/Timeline/Index?ProjectID=7');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus?.state.bookID===12);assert.match(await p.locator('[data-focus-label]').textContent(),/A Distant Shore/);await p.locator('[data-focus-toggle]').click();await p.locator('[data-focus-book]').selectOption('13');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.bookID===13);assert.equal((await state()).sceneID,null);assert.equal(await p.locator('.timeline-scene-card').count(),3,'focus book selection preserves project-wide Timeline');assert(!new URL(p.url()).searchParams.has('BookID'));await p.locator('[data-focus-book]').selectOption('12');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.bookID===12);
await p.locator('[data-focus-position]').selectOption('23/');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.chapterID===23);assert(await p.locator('button[data-focus-step="1"]').isDisabled(),'no following scene after the final empty chapter');assert(await p.locator('button[data-focus-step="-1"]').isEnabled());await openFocus();await p.locator('button[data-focus-step="-1"]').click();await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===32);await set({chapterID:21,sceneID:31});
let reopened;if(installed){const d=await b.newBrowserCDPSession(),opened=c.waitForEvent('page');await d.send('PWA.launch',{manifestId:base+'/Projects',url:base+'/Timeline/Index?ProjectID=7'});reopened=await opened;await reopened.waitForLoadState();assert(await reopened.evaluate(()=>matchMedia('(display-mode: standalone)').matches));}else{reopened=await c.newPage();await reopened.goto(base+'/Timeline/Index?ProjectID=7');}await reopened.waitForFunction(()=>window.PlotDirectorNarrativeFocus?.state.bookID===12);assert.equal(await reopened.evaluate(()=>window.PlotDirectorNarrativeFocus.state.sceneID),31,'reopened workspace restores its authorised focus book and location');await reopened.close();
const searchMilliseconds=await p.evaluate(()=>{const focus=window.PlotDirectorNarrativeFocus.state,original=focus.positions,input=document.querySelector('[data-focus-search]');focus.positions=Array.from({length:5000},(_,i)=>({chapterID:Math.floor(i/50)+1,chapterNumber:Math.floor(i/50)+1,chapterTitle:'Synthetic chapter',sceneID:20000+i,sceneNumber:i%50+1,label:`Chapter ${Math.floor(i/50)+1} · Scene ${i+1}`}));const start=performance.now();for(const value of ['Scene 499','']){input.value=value;input.dispatchEvent(new Event('input'));}const elapsed=performance.now()-start;focus.positions=original;input.value='';input.dispatchEvent(new Event('input'));return elapsed;});assert(searchMilliseconds<1500,'5000-scene header search remains responsive');console.log(`Focus search, 5000 scenes: ${searchMilliseconds.toFixed(1)}ms`);
assert.deepEqual(errors,[]);console.log(`PASS ${installed?'installed Chromium PWA':'Chromium'} narrative focus: independent objective/editor, Go to objective, manuscript neighbours across chapters, search, recency, windows, persistence, book/security scope, antiforgery, floor-plan local isolation/promotion/persistence unsaved inline/Review editor protection, stable Review refresh, local Relationships/Maps positions, keyboard scene stepping and themed responsive rendering`);

View File

@ -1,8 +1,8 @@
@model ApplicationNavigationViewModel
@{var focus=Model.NarrativeFocus??new PlotLine.Services.NarrativeFocusState{ProjectID=Model.Project!.ProjectID};}
<details class="pd-narrative-focus" data-narrative-focus data-project="@focus.ProjectID" data-book="@focus.BookID">
<summary title="Current narrative focus" data-focus-label>Current Focus: @focus.Label</summary>
<div class="pd-focus-picker">
<div class="nav-item dropdown pd-narrative-focus" data-narrative-focus data-project="@focus.ProjectID" data-book="@focus.BookID">
<button class="nav-link dropdown-toggle" type="button" id="appNarrativeFocusMenu" data-focus-toggle data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false" title="Current narrative focus"><span class="app-context-label" data-focus-label>Current Focus: @focus.Label</span></button>
<div class="dropdown-menu pd-focus-picker" aria-labelledby="appNarrativeFocusMenu">
@if(Model.Book==null){<label>Focus book<select data-focus-book><option value="">Choose a book…</option>@foreach(var book in Model.Books){<option value="@book.BookID">@book.BookDisplayTitle</option>}</select></label>}
<p class="small">Current narrative location. Saved objectives and local Scene Explorers keep their own targets.</p>
<label>Find chapter or scene<input type="search" data-focus-search placeholder="Search this book" autocomplete="off" /></label>
@ -13,4 +13,4 @@
@Html.AntiForgeryToken()
</div>
<script type="application/json" data-narrative-initial>@Html.Raw(System.Text.Json.JsonSerializer.Serialize(focus,new System.Text.Json.JsonSerializerOptions(System.Text.Json.JsonSerializerDefaults.Web)))</script>
</details>
</div>

View File

@ -4,10 +4,12 @@
.pd-scene-explorer input[type=range]{flex:1 1 12rem;min-width:0}
.pd-scene-explorer small{flex-basis:100%;color:var(--pd-muted)}
.pd-narrative-focus{position:relative;width:clamp(10rem,26vw,28rem);min-width:10rem;max-width:28rem;font-size:.82rem;margin-inline:.4rem;}
.pd-narrative-focus>summary{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:pointer;}
.pd-focus-picker{position:absolute;z-index:1100;inset-block-start:100%;inset-inline-start:0;width:min(32rem,88vw);padding:1rem;background:var(--bs-body-bg);color:var(--bs-body-color);border:1px solid var(--bs-border-color);border-radius:.4rem;box-shadow:0 .4rem 1rem #0003;}
.pd-narrative-focus>.dropdown-toggle{width:100%;min-width:0;}
.pd-shell .pd-narrative-focus .app-context-label{flex:1;min-width:0;max-width:none;text-align:start;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.pd-narrative-focus>.dropdown-toggle::after{flex-shrink:0;}
.pd-focus-picker{width:min(32rem,88vw);padding:1rem;}
.pd-focus-picker label{display:block;margin-block:.5rem;}
.pd-focus-picker select,.pd-focus-picker input{display:block;width:100%;min-width:0;background:var(--bs-body-bg);color:var(--bs-body-color);border:1px solid var(--bs-border-color);border-radius:.25rem;padding:.3rem;}
@media(max-width:900px){.pd-narrative-focus{max-width:12rem;}.pd-focus-picker{position:fixed;inset-inline-start:1rem;inset-block-start:4rem;}}
@media(max-width:900px){.pd-narrative-focus{max-width:12rem;}}
.timeline-scene-card.pd-current-narrative-focus{outline:2px solid var(--pd-accent);outline-offset:2px;}

View File

@ -4,7 +4,8 @@
const root=document.querySelector('[data-narrative-focus]');if(!root)return;
let state=JSON.parse(root.querySelector('[data-narrative-initial]').textContent),busy=false,epoch=0,refreshQueued=false;
const select=root.querySelector('[data-focus-position]'),recent=root.querySelector('[data-focus-recent]'),search=root.querySelector('[data-focus-search]'),status=root.querySelector('[data-narrative-status]');
const bookPicker=root.querySelector('[data-focus-book]');
const bookPicker=root.querySelector('[data-focus-book]'),toggle=root.querySelector('[data-focus-toggle]');
const dismiss=(restore=false)=>{restore=restore===true||root.querySelector('.pd-focus-picker').contains(document.activeElement);bootstrap.Dropdown.getOrCreateInstance(toggle).hide();if(restore)toggle.focus();};
const scopeKey=`pd-narrative-book:${document.body.dataset.pdUserId}:${state.projectID}`;
const notificationKey=()=>`pd-narrative-focus:${document.body.dataset.pdUserId}:${state.projectID}:${state.bookID}`;
async function loadScope(book){if(!book){render();return;}const mine=++epoch;busy=true;render();try{const response=await fetch(`/NarrativeFocus/Read?projectId=${state.projectID}&bookId=${book}`,{cache:'no-store'});if(!response.ok||response.redirected)throw Error();const result=await response.json();if(mine!==epoch)return;state=result;publish();status.textContent='';}catch{status.textContent='This focus book is unavailable. Your workspace is unchanged.';}finally{busy=false;render();if(refreshQueued){refreshQueued=false;void refresh();}}}
@ -31,6 +32,7 @@
async function set(target={}){
if(busy||!state.bookID){status.textContent='Choose a focus book first.';return false;}
if(target.bookID&&Number(target.bookID)!==state.bookID||target.projectID&&Number(target.projectID)!==state.projectID){status.textContent='Choose this book in the header before setting its focus.';return false;}
const fromPicker=root.querySelector('.pd-focus-picker').contains(document.activeElement);
busy=true;++epoch;render();status.textContent='Updating current focus…';
const body=new URLSearchParams({projectId:state.projectID,bookId:state.bookID,version:state.version,__RequestVerificationToken:root.querySelector('[name=__RequestVerificationToken]').value});
if(target.chapterID)body.set('chapterId',target.chapterID);if(target.sceneID)body.set('sceneId',target.sceneID);if(target.direction)body.set('direction',target.direction);
@ -39,15 +41,15 @@
if(!response.ok||response.redirected){if(response.status===409){busy=false;await refresh();}throw Error(result?.message||'Current focus could not be changed.');}
state=result;publish();status.textContent='Current focus updated. Your workspace and saved targets are retained.';
try{localStorage.setItem(notificationKey(),String(state.version));}catch{}
return true;
dismiss(fromPicker&&document.activeElement===document.body);return true;
}catch(error){status.textContent=error.message;return false;}finally{busy=false;render();if(refreshQueued){refreshQueued=false;void refresh();}}
}
const choose=value=>{const p=entries().find(p=>key(p)===value);if(p)void set(p);else render();};
search.addEventListener('input',render);select.addEventListener('change',()=>choose(select.value));recent.addEventListener('change',()=>choose(recent.value));
root.querySelectorAll('[data-focus-step]').forEach(b=>b.addEventListener('click',()=>void set({direction:Number(b.dataset.focusStep)})));
root.addEventListener('keydown',e=>{if(e.key==='Escape'){root.open=false;root.querySelector('summary').focus();}});
window.addEventListener('pagehide',dismiss);
document.addEventListener('click',e=>{const b=e.target.closest('[data-go-objective],[data-narrative-scene]');if(!b)return;void set({bookID:Number(b.dataset.narrativeBook)||state.bookID,chapterID:Number(b.dataset.chapter||b.dataset.narrativeChapter)||null,sceneID:Number(b.dataset.scene||b.dataset.narrativeScene)||null});});
window.addEventListener('storage',e=>{if(e.key===notificationKey())void refresh();});window.addEventListener('focus',()=>void refresh());window.addEventListener('pageshow',e=>{if(e.persisted)void refresh();});root.addEventListener('toggle',()=>{if(root.open)void refresh();});
window.addEventListener('storage',e=>{if(e.key===notificationKey())void refresh();});window.addEventListener('focus',()=>void refresh());window.addEventListener('pageshow',e=>{if(e.persisted)void refresh();});root.addEventListener('shown.bs.dropdown',()=>void refresh());
window.PlotDirectorNarrativeFocus={set,refresh,get state(){return state;}};
publish();
if(!state.bookID&&bookPicker){try{const book=localStorage.getItem(scopeKey);if([...bookPicker.options].some(o=>o.value===book))void loadScope(Number(book));}catch{}}