From 6ba409220aa3d8071d447c722e5ecdb7fc342427 Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Sun, 22 Nov 2026 20:09:38 +0000 Subject: [PATCH] Retain family exploration when recentering and resolving character lookup --- Docs/Writer/Context-Family-Tree-Redesign-20261122.md | 2 ++ PlotLine.Tests/Browser/context-family.cjs | 4 ++-- PlotLine.Tests/Browser/context-relationships.cjs | 2 +- PlotLine/wwwroot/js/context-relationships.js | 6 ++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Docs/Writer/Context-Family-Tree-Redesign-20261122.md b/Docs/Writer/Context-Family-Tree-Redesign-20261122.md index 11e6d178..4826db4a 100644 --- a/Docs/Writer/Context-Family-Tree-Redesign-20261122.md +++ b/Docs/Writer/Context-Family-Tree-Redesign-20261122.md @@ -59,3 +59,5 @@ Predeployment evidence: `/tmp/context-family-final-build2.log`, `/tmp/context-fa - Membership metadata is bounded at 8,192 project family records, a visible tree at 128 people/256 links and retained state at 12 families/64 expansions. Larger structures require recentering or the full editor; metadata beyond the hard limit needs future incremental membership infrastructure. - Author-reference truth is independent of POV knowledge. No new viewpoint-knowledge, biological inference or first-meeting logic is provided. - Physical phones/tablets, installed PWA windowing and screen-reader review remain manual acceptance. Editorial review of representative author-owned complex families is recommended; those records were not modified for testing. + +Final exploration-state acceptance also verified re-centring on a visible relative and searching back into a previously visited family: zoom and expanded branches are retained, with at most one bounded restoration retry after the server resolves the canonical component. Evidence: `/tmp/context-family-state-browser.log`, `/tmp/context-family-state-story.log`, `/tmp/context-family-state-touch.log`. The Story regression uses normal keyboard pan to reach an offscreen branch at the restored zoom. No .NET domain changes followed the 770-PASS run. diff --git a/PlotLine.Tests/Browser/context-family.cjs b/PlotLine.Tests/Browser/context-family.cjs index 3fb46597..00274d7e 100644 --- a/PlotLine.Tests/Browser/context-family.cjs +++ b/PlotLine.Tests/Browser/context-family.cjs @@ -1,10 +1,10 @@ const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path');const base=process.env.PD_BROWSER_BASE||'http://127.0.0.1:5238'; -(async()=>{const b=await chromium.launch();let step='setup';try{const c=await b.newContext({viewport:{width:1366,height:1000}});await c.route('**/cdn.jsdelivr.net/**signalr*',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(path.join(__dirname,'node_modules/@microsoft/signalr/dist/browser/signalr.min.js'))}));for(const url of ['**/native-companion/status','**/native-companion/connection-state','**/Writing/Context/Position?*'])await c.route(url,r=>r.fulfill({json:url.endsWith('status')?[]:{known:false,connected:false}}));await c.route('**/Writing/Context/Tabs/*',async r=>{const u=new URL(r.request().url());await r.fulfill({response:await r.fetch({url:base+'/context-tab-fixture/'+u.pathname.split('/').at(-1)+u.search})});});let merged=false,split=false,many=false,trees=0;for(const [route,fixture]of [['FamilyIndex','index'],['FamilyTree','tree']])await c.route('**/Writing/Context/Relationships/'+route+'?*',async r=>{if(route==='FamilyTree')trees++;const u=new URL(r.request().url());await r.fulfill({response:await r.fetch({url:base+'/context-family-'+fixture+'-fixture'+u.search+'&large=true&merge='+merged+'&many='+many+'&split='+split})});});const p=await c.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));await p.goto(base+'/Writing/Context');await p.selectOption('[data-context-tab]','relationships');const pane=p.locator('[data-context-pane="0"]');await pane.locator('[data-graph-node="5"]').waitFor(); +(async()=>{const b=await chromium.launch();let step='setup';try{const c=await b.newContext({viewport:{width:1366,height:1000}});await c.route('**/cdn.jsdelivr.net/**signalr*',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(path.join(__dirname,'node_modules/@microsoft/signalr/dist/browser/signalr.min.js'))}));for(const url of ['**/native-companion/status','**/native-companion/connection-state','**/Writing/Context/Position?*'])await c.route(url,r=>r.fulfill({json:url.endsWith('status')?[]:{known:false,connected:false}}));await c.route('**/Writing/Context/Tabs/*',async r=>{const u=new URL(r.request().url());await r.fulfill({response:await r.fetch({url:base+'/context-tab-fixture/'+u.pathname.split('/').at(-1)+u.search})});});await c.route('**/Writing/Context/Relationships/Lookup?*',async r=>r.fulfill({response:await r.fetch({url:base+'/context-lenses-lookup-fixture'})}));let merged=false,split=false,many=false,trees=0;for(const [route,fixture]of [['FamilyIndex','index'],['FamilyTree','tree']])await c.route('**/Writing/Context/Relationships/'+route+'?*',async r=>{if(route==='FamilyTree')trees++;const u=new URL(r.request().url());await r.fulfill({response:await r.fetch({url:base+'/context-family-'+fixture+'-fixture'+u.search+'&large=true&merge='+merged+'&many='+many+'&split='+split})});});const p=await c.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));await p.goto(base+'/Writing/Context');await p.selectOption('[data-context-tab]','relationships');const pane=p.locator('[data-context-pane="0"]');await pane.locator('[data-graph-node="5"]').waitFor(); const index=()=>pane.locator('[data-family-key]');const visibleIDs=()=>pane.locator('[data-graph-node]').evaluateAll(ns=>ns.map(n=>Number(n.dataset.graphNode))); step='scene family index and one tree';assert.equal(await index().count(),5);assert.equal(await pane.locator('[data-family-key][aria-pressed=true]').getAttribute('data-family-key'),'1');assert((await visibleIDs()).includes(8));assert(!(await visibleIDs()).includes(22));assert(!(await visibleIDs()).includes(25));assert(!(await visibleIDs()).includes(30));assert.equal(await pane.locator('[data-family-index] details').count(),1);await p.screenshot({path:'/tmp/context-family-initial-desktop.png',fullPage:true}); step='real genealogical connector inspection';await pane.locator('[data-relationship-svg]').scrollIntoViewIfNeeded();const point=await pane.locator('[data-graph-connection="7"]').evaluate(n=>{const p=n.getPointAtLength(n.getTotalLength()-12),m=n.getScreenCTM();return{x:m.a*p.x+m.c*p.y+m.e,y:m.b*p.x+m.d*p.y+m.f};});await p.mouse.click(point.x,point.y);await pane.locator('[data-graph-edge="7"].is-selected').waitFor({state:'attached'});assert.match(await pane.locator('[data-relationship-details]').innerText(),/Recorded person 3/);await pane.locator('[data-graph-node="5"]').click(); step='per-family view and unrelated notification stability';await pane.locator('[data-graph-zoom=in]').click();const zoom=await pane.locator('[data-relationship-viewport]').getAttribute('transform');await pane.locator('[data-family-key="21"]').click();await pane.locator('[data-graph-node="22"]').waitFor();assert(!(await visibleIDs()).includes(5));const before=trees;await p.evaluate(()=>document.querySelector('[data-context-workspace]').contextController.invalidate({bookId:12}));await p.waitForFunction(()=>document.querySelector('[data-family-key="21"]')?.getAttribute('aria-pressed')==='true');await p.waitForTimeout(180);assert(trees>before);assert((await visibleIDs()).includes(22));await pane.locator('[data-family-key="1"]').click();await pane.locator('[data-graph-node="5"]').waitFor();assert.equal(await pane.locator('[data-relationship-viewport]').getAttribute('transform'),zoom); - step='branch expand/collapse, exact recorded relatives and no edit';await pane.locator('[data-family-branch="3"]').click();await pane.locator('[data-graph-node="1"]').waitFor();assert.equal(await p.locator('[data-context-edit-dialog][open]').count(),0);await pane.locator('[data-family-branch="7"]').click();await pane.locator('[data-graph-node="11"]').waitFor();assert((await visibleIDs()).includes(12));assert((await visibleIDs()).includes(16));assert(!(await visibleIDs()).includes(100));assert.equal(await pane.locator('[data-family-branch="7"]').getAttribute('aria-expanded'),'true');await pane.locator('[data-family-branch="7"]').click();await p.waitForFunction(()=>!document.querySelector('[data-graph-node="11"]'));await pane.locator('[data-family-branch="3"]').focus();await p.keyboard.press('Enter');await p.waitForFunction(()=>!document.querySelector('[data-graph-node="1"]')); + step='branch expand/collapse, exact recorded relatives and no edit';await pane.locator('[data-family-branch="3"]').click();await pane.locator('[data-graph-node="1"]').waitFor();assert.equal(await p.locator('[data-context-edit-dialog][open]').count(),0);await pane.locator('[data-family-branch="7"]').click();await pane.locator('[data-graph-node="11"]').waitFor();assert((await visibleIDs()).includes(12));assert((await visibleIDs()).includes(16));assert(!(await visibleIDs()).includes(100));assert.equal(await pane.locator('[data-family-branch="7"]').getAttribute('aria-expanded'),'true');await pane.locator('[data-family-key="21"]').click();await pane.locator('[data-graph-node="22"]').waitFor();await pane.locator('[data-relationship-person]').fill('relative 7');await pane.locator('[data-relationship-matches] button').click();await pane.locator('[data-graph-node="7"].is-selected').waitFor();assert.equal(await pane.locator('[data-family-key="1"]').getAttribute('aria-pressed'),'true');assert.match(await pane.locator('[data-relationship-viewport]').getAttribute('transform'),/scale\(1.2\)/);for(const id of [7,5]){await pane.locator(`[data-graph-node="${id}"]`).click();await pane.getByRole('button',{name:'Centre tree / network on this person',exact:true}).click();await pane.locator(`[data-graph-node="${id}"].is-selected`).waitFor();assert.match(await pane.locator('[data-relationship-viewport]').getAttribute('transform'),/scale\(1.2\)/);}await pane.locator('[data-graph-node="1"]').waitFor();await pane.locator('[data-graph-node="11"]').waitFor();await pane.locator('[data-family-branch="7"]').click();await p.waitForFunction(()=>!document.querySelector('[data-graph-node="11"]'));await pane.locator('[data-family-branch="3"]').focus();await p.keyboard.press('Enter');await p.waitForFunction(()=>!document.querySelector('[data-graph-node="1"]')); step='split membership prunes obsolete expansions';await pane.locator('[data-family-branch="3"]').click();await pane.locator('[data-graph-node="1"]').waitFor();split=true;await p.evaluate(()=>document.querySelector('[data-context-workspace]').contextController.invalidate({bookId:12}));await p.waitForFunction(()=>document.querySelector('[data-family-key="5"]')?.getAttribute('aria-pressed')==='true');assert(!(await visibleIDs()).includes(3));assert(!(await visibleIDs()).includes(15));split=false;await p.evaluate(()=>document.querySelector('[data-context-workspace]').contextController.invalidate({bookId:12}));await p.waitForFunction(()=>document.querySelector('[data-family-key="1"]')?.getAttribute('aria-pressed')==='true'); step='isolated and cyclic entries';await pane.locator('[data-family-index] details summary').click();await pane.locator('[data-family-key="40"]').click();await pane.locator('[data-graph-node="40"]').waitFor();assert.deepEqual(await visibleIDs(),[40]);assert.match(await pane.locator('[data-relationship-status]').innerText(),/cyclic/);await pane.locator('[data-family-key="30"]').click();await pane.locator('[data-graph-node="30"]').waitFor();assert.deepEqual(await visibleIDs(),[30]); step='independent family selection in two panes';await p.selectOption('[data-context-layout]','columns');await p.locator('[data-context-pane="1"] [data-context-tab]').selectOption('relationships');await p.locator('[data-context-pane="1"] [data-graph-node="5"]').waitFor();assert((await visibleIDs()).includes(30));await pane.locator('[data-family-key="21"]').click();await pane.locator('[data-graph-node="22"]').waitFor();assert.equal(await p.locator('[data-context-pane="1"] [data-family-key="1"]').getAttribute('aria-pressed'),'true'); diff --git a/PlotLine.Tests/Browser/context-relationships.cjs b/PlotLine.Tests/Browser/context-relationships.cjs index 12643560..46765280 100644 --- a/PlotLine.Tests/Browser/context-relationships.cjs +++ b/PlotLine.Tests/Browser/context-relationships.cjs @@ -5,7 +5,7 @@ const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=r step='pan zoom and unchanged-family notification stability';await p.click('[data-graph-zoom="in"]');await p.locator('[data-relationship-svg]').focus();await p.keyboard.press('ArrowRight');const transform=await p.locator('[data-relationship-viewport]').getAttribute('transform');await p.evaluate(()=>{window.familyLayouts=0;const original=window.PlotDirectorContextRelationshipLayout.family;window.PlotDirectorContextRelationshipLayout.family=(...a)=>{familyLayouts++;return original(...a);};});const before=graphReads;await p.evaluate(()=>document.querySelector('[data-context-workspace]').contextController.invalidate({bookId:12}));await p.waitForFunction(()=>document.querySelector('[data-graph-node="5"]'));await p.waitForTimeout(200);assert(graphReads>before);assert.equal(await p.evaluate(()=>familyLayouts),0);assert.equal(await p.locator('[data-relationship-viewport]').getAttribute('transform'),transform); step='Story network and recorded point';await p.click('[data-relationship-lens="story"]');await p.waitForFunction(()=>document.querySelector('[data-relationship-caption]').textContent.includes('Later developments are excluded'));assert(await p.locator('[data-graph-edge]').count()>30);assert.equal(await p.locator('[data-graph-node] rect.is-physical').count(),2);assert.equal(await p.locator('[data-relationship-details] [data-context-edit="life-status"]').count(),0);assert.doesNotMatch(await p.locator('[data-graph-node="6"]').getAttribute('aria-label'),/deceased/);await selectEdge(1);await p.waitForFunction(()=>document.querySelector('[data-relationship-details]').textContent.includes('Rival'));assert.match(await p.locator('[data-relationship-details]').innerText(),/does not prove a first meeting/);await p.evaluate(()=>document.querySelector('[data-context-workspace]').contextController.setPosition({projectId:7,bookId:12,chapterId:11,sceneId:23}));await p.waitForFunction(()=>document.querySelector('[data-relationship-details]')?.textContent.includes('Later established'));await p.click('[data-relationship-lens="family"]');await p.waitForFunction(()=>document.querySelector('[data-relationship-caption]').textContent.includes('Author-established'));assert.equal(await p.locator('[data-family-key="21"]').getAttribute('aria-pressed'),'true'); step='lookup and recenter';await p.locator('[data-relationship-person]').fill('relative 7');await p.locator('[data-relationship-matches] button').waitFor();await p.locator('[data-relationship-matches] button').click();await p.waitForFunction(()=>document.querySelector('[data-relationship-details]').textContent.includes('Recorded person 7')); - step='large family and independent panes';large=true;await p.locator('[data-family-branch="5"]').click();await p.waitForSelector('[data-graph-node="3"]');await p.selectOption('[data-context-layout]','columns');await p.selectOption('[data-context-pane="1"] [data-context-tab]','relationships');await p.locator('[data-context-pane="1"] [data-graph-node="22"]').waitFor();await p.locator('[data-context-pane="1"] [data-relationship-lens="story"]').click();await p.waitForTimeout(120);assert.equal(await p.locator('[data-context-pane="0"] [data-relationship-lens="family"]').getAttribute('aria-pressed'),'true'); + step='large family and independent panes';large=true;await p.locator('[data-relationship-svg]').focus();await p.keyboard.press('ArrowRight');await p.keyboard.press('ArrowRight');await p.locator('[data-family-branch="5"]').click();await p.waitForSelector('[data-graph-node="3"]');await p.selectOption('[data-context-layout]','columns');await p.selectOption('[data-context-pane="1"] [data-context-tab]','relationships');await p.locator('[data-context-pane="1"] [data-graph-node="22"]').waitFor();await p.locator('[data-context-pane="1"] [data-relationship-lens="story"]').click();await p.waitForTimeout(120);assert.equal(await p.locator('[data-context-pane="0"] [data-relationship-lens="family"]').getAttribute('aria-pressed'),'true'); step='container widths and keyboard navigation';for(const width of [1366,760,390]){await p.setViewportSize({width,height:900});for(const layout of ['single','columns','rows']){await p.selectOption('[data-context-layout]',layout);await p.waitForTimeout(50);assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2),width+'/'+layout);}}await p.selectOption('[data-context-layout]','single');await p.locator('[data-context-pane="0"] [data-relationship-svg]').focus();await p.keyboard.press('Home');await p.keyboard.press('+'); step='read-only graph removes edit controls';readOnly=true;await p.evaluate(()=>document.querySelector('[data-context-workspace]').contextController.invalidate({bookId:12}));await p.waitForTimeout(350);assert.equal(await p.locator('[data-context-pane="0"] [data-relationship-add]:visible').count(),0);assert.deepEqual(errors,[]);console.log('PASS visual Relationships browser: Family and Story lenses, real SVG hit selection/edit, pan/zoom/keyboard, stable family layout through notifications, scene changes, lookup/recentre, compact family branches, dense Story network, independent panes, full/half/stacked/mobile and read-only controls.'); }catch(e){console.error('FAILED '+step+': '+e.stack);process.exitCode=1;}finally{await b.close();}})(); diff --git a/PlotLine/wwwroot/js/context-relationships.js b/PlotLine/wwwroot/js/context-relationships.js index 509a946f..4574e6c2 100644 --- a/PlotLine/wwwroot/js/context-relationships.js +++ b/PlotLine/wwwroot/js/context-relationships.js @@ -27,7 +27,7 @@ for(const [i,g]of groups.entries()){const b=button(g.label,()=>choose(g));b.dataset.familyKey=g.key;b.setAttribute('aria-pressed',String(g.key===state.familyKey));b.title=g.label+(g.isPov?' · POV family':'');(i<3?tabs:rest).append(b);}if(groups.length>3)tabs.append(more);box.append(tabs); const label=html('label','Family in this scene','context-family-compact'),select=html('select',null,'form-select');select.dataset.familySelect='';for(const g of groups){const option=html('option',g.label+(g.isPov?' · POV':''));option.value=g.key;option.selected=g.key===state.familyKey;select.append(option);}listen(select,'change',()=>choose(groups.find(g=>String(g.key)===select.value)));label.append(select);box.append(label);for(const warning of state.index.warnings)box.append(html('p',warning,'small context-family-warning')); } - async function loadFamily(force,epoch,requestSignal){ + async function loadFamily(force,epoch,requestSignal,restored=false){ const read=async(path,params)=>{const response=await fetch('/Writing/Context/Relationships/'+path+'?'+params,{cache:'no-store',signal:requestSignal});if(!response.ok||response.redirected){const payload=await response.json().catch(()=>null),error=Error(payload?.message||'Family reference is unavailable. Check access and retry.');error.status=response.status;throw error;}return response.json();}; const common={bookId:host.dataset.book,sceneId:host.dataset.scene},refreshed=force||!state.index;if(refreshed)state.index=await read('FamilyIndex',new URLSearchParams(common));if(epoch!==state.epoch)return; if(state.familyKey==null){const group=state.index.groups.find(g=>g.key===state.index.defaultKey);if(group)familyView(group.key,group.focusID,state.newScene);state.newScene=false;} @@ -36,10 +36,12 @@ const params=new URLSearchParams({...common,focusId:v.focusID});for(const id of v.expanded||[])params.append('expanded',id); let result;try{result=await read('FamilyTree',params);}catch(error){if(refreshed&&error.status===400&&v.expanded?.length){v.expanded=[];params.delete('expanded');result=await read('FamilyTree',params);}else throw error;}if(epoch!==state.epoch||!node.isConnected)return; // A membership edit may merge/split the component; retain this focus and reconcile its key. + const remembered=state.families.get(result.familyKey); + if(result.familyKey!==state.familyKey&&remembered&&remembered!==v&&!restored){const oldKey=state.familyKey;remembered.focusID=v.focusID;remembered.selected={kind:'node',id:v.focusID};remembered.initialised=false;state.views.family=remembered;state.familyKey=result.familyKey;state.families.delete(oldKey);state.families.delete(result.familyKey);state.families.set(result.familyKey,remembered);state.cache.family=null;return loadFamily(true,epoch,requestSignal,true);} if(result.familyKey!==state.familyKey){state.families.delete(state.familyKey);state.familyKey=result.familyKey;state.families.set(result.familyKey,v);} state.cache.family=result;state.data=result.graph;state.branches=result.branches;state.familyWarnings=result.warnings;familyIndex();render(); } - function familyFocus(id){const matching=state.index?.groups.find(g=>g.sceneMembers?.includes(id));familyView(matching?.key??id,id,true).initialised=false;state.cache.family=null;void state.load();} + function familyFocus(id){const matching=state.index?.groups.find(g=>g.sceneMembers?.includes(id));const key=matching?.key??(state.data?.lens==='family'&&state.data.nodes.some(n=>n.id===id)?state.familyKey:id);familyView(key,id,true).initialised=false;state.cache.family=null;void state.load();} function editorLink(link){const a=html('a','Open in Relationships Editor');a.href='/RelationshipMap?bookId='+host.dataset.book;a.target='_blank';a.rel='noopener';a.dataset.contextWorkspaceTarget='relationships';if(link)a.dataset.contextEntity=link.id;if(state.lens==='family')a.dataset.contextNarrative='author';if(link?.editSceneID&&!link.initial)a.dataset.contextOpenScene=link.editSceneID;return a;} function highlights(){const selected=view().selected;viewport.querySelectorAll('[data-graph-node]').forEach(n=>{const on=selected?.kind==='node'&&Number(n.dataset.graphNode)===selected.id;n.classList.toggle('is-selected',on);n.setAttribute('aria-pressed',String(on));});viewport.querySelectorAll('[data-graph-edge]').forEach(n=>{const link=state.data.links.find(l=>l.id===Number(n.dataset.graphEdge));const active=!selected||selected.kind==='link'&&selected.id===link.id||selected.kind==='node'&&(link.a===selected.id||link.b===selected.id);n.style.opacity=active?'1':state.lens==='family'?'.8':'.16';n.classList.toggle('is-selected',selected?.kind==='link'&&selected.id===link.id);n.querySelector('[data-graph-connection]')?.setAttribute('pointer-events',state.lens==='story'&&!active?'none':'stroke');});} function describe(){details.replaceChildren();const selected=view().selected,data=state.data;if(!data)return;