diff --git a/Docs/Writer/Spatial-Context.md b/Docs/Writer/Spatial-Context.md
index 6bac9f6d..15033166 100644
--- a/Docs/Writer/Spatial-Context.md
+++ b/Docs/Writer/Spatial-Context.md
@@ -48,7 +48,7 @@ viewport and Hold/Follow state intact. Context-local buttons (including Show on
Show floor plan, scene navigation and inline editing) remain local.
`context-main-window.js` is the shared delegation point. Its document-level handler
-covers same-origin page anchors inside the Context root, including dynamically
+covers same-origin page anchors in the Context document, including dynamically
loaded partials, dialogs and expanded sections. Existing
`data-context-workspace-target` commands retain their entity/story-point resolver.
Other page links retain their exact path, query and fragment through the optional
diff --git a/PlotLine.Tests/Browser/context-external-navigation.cjs b/PlotLine.Tests/Browser/context-external-navigation.cjs
index 29eafe40..4098260c 100644
--- a/PlotLine.Tests/Browser/context-external-navigation.cjs
+++ b/PlotLine.Tests/Browser/context-external-navigation.cjs
@@ -3,14 +3,14 @@ const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=r
const base='http://127.0.0.1:5238';
(async()=>{const browser=await chromium.launch();let step='setup';try{const c=await browser.newContext({viewport:{width:1500,height:1000}});const errors=[];c.on('page',p=>p.on('pageerror',e=>errors.push(e.message)));
for(const route of ['**/native-companion/status','**/native-companion/connection-state'])await c.route(route,r=>r.fulfill({json:[]}));await c.route('**/Writing/Context/Position?*',r=>r.fulfill({json:{connected:false}}));await c.route('**/Writing/Context/Tabs/*',r=>r.fulfill({body:'
Existing tool
',contentType:'text/html'}));
-for(const route of ['/Locations/**','/Characters/Details/**','/Characters/Edit/**','/FloorPlans/Edit/**','/StoryCalendar*','/PlotThreads/Edit/**','/RelationshipMap*'])await c.route(base+route,async r=>{if(r.request().isNavigationRequest())await r.fulfill({response:await r.fetch({url:base+'/fixture?layout=full'})});else await r.continue();});
+for(const route of ['/Locations/**','/Characters/Details/**','/Characters/Edit/**','/FloorPlans/Edit/**','/StoryCalendar*','/PlotThreads/Edit/**','/RelationshipMap*','/Books/Details/**','/manuscript/paragraphs*'])await c.route(base+route,async r=>{if(r.request().isNavigationRequest())await r.fulfill({response:await r.fetch({url:base+'/fixture?layout=full'})});else await r.continue();});
await c.route(base+'/Maps?*',async r=>{if(r.request().isNavigationRequest())await r.fulfill({response:await r.fetch({url:base+'/fixture?layout=full'})});else await r.continue();});
let main=await c.newPage();await main.goto(base+'/fixture?layout=full');const p=await c.newPage();await p.goto(base+'/Writing/Context?pinned=true');await p.selectOption('[data-context-pane="0"] [data-context-tab]','locations');await p.getByRole('heading',{name:'Bedroom',exact:true}).waitFor();await p.selectOption('[data-context-layout]','columns');await p.selectOption('[data-context-pane="1"] [data-context-tab]','maps');await p.waitForFunction(()=>document.querySelector('iframe')?.contentWindow?.PlotDirectorMapWorkspace?.document.features.length===2);await p.evaluate(()=>document.querySelector('iframe').contentWindow.PlotDirectorMapWorkspace.setView({x:50,y:60,w:900,h:700}));
const snapshot=()=>p.evaluate(()=>({url:location.href,layout:document.querySelector('[data-context-layout]').value,tabs:[...document.querySelectorAll('[data-context-tab]')].map(n=>n.value),position:document.querySelector('[data-context-workspace]').contextController.position,held:document.querySelector('[data-context-workspace]').contextController.held,heading:document.querySelector('[data-spatial-details] h2')?.textContent,view:document.querySelector('iframe')?.contentWindow?.PlotDirectorMapWorkspace?.view}));
const before=await snapshot(),count=c.pages().length;const ready=async()=>{await p.waitForFunction(()=>document.querySelector('[data-context-workspace]').contextController.connection?.state==='Connected'&&document.querySelector('[data-context-workspace]').contextController.connection.invoke('MyContextWindows',12).then(rows=>rows.some(r=>r.kind==='main')));await p.waitForTimeout(600);};
async function go(label,expected){console.log("CHECK",label,expected);await ready();await p.getByRole('link',{name:label,exact:true}).click();await main.waitForURL(u=>u.pathname+u.search===expected);assert.equal(c.pages().length,count);assert.deepEqual(await snapshot(),before);}
step='spatial exact URLs in existing main';await go('Location Details','/Locations/Details/103');await go('Edit Location','/Locations/Edit/103');const mapUrl=new URL(await p.getByRole('link',{name:'Open in Maps',exact:true}).getAttribute('href'),base);await go('Open in Maps',mapUrl.pathname+mapUrl.search);
-step='dynamic links, modifiers, keyboard and selected blocks';const links=[['Floor editor','/FloorPlans/Edit/9?selectedBlockId=51'],['Edit Character','/Characters/Edit/5'],['Character Details','/Characters/Details/5'],['Calendar','/StoryCalendar?projectId=7&bookId=12'],['Thread','/PlotThreads/Edit/6']];for(const [label,url] of links){await p.evaluate(([text,href])=>{const a=document.createElement('a');a.textContent=text;a.href=href;document.querySelector('[data-context-pane="1"]').append(a);},[label,url]);await go(label,url);}
+step='dynamic links, modifiers, keyboard and selected blocks';const links=[['Floor editor','/FloorPlans/Edit/9?selectedBlockId=51'],['Edit Character','/Characters/Edit/5'],['Character Details','/Characters/Details/5'],['Calendar','/StoryCalendar?projectId=7&bookId=12'],['Thread','/PlotThreads/Edit/6'],['Book','/Books/Details/12'],['Structure','/manuscript/paragraphs?bookId=12']];for(const [label,url] of links){await p.evaluate(([text,href])=>{const a=document.createElement('a');a.textContent=text;a.href=href;document.querySelector('[data-context-pane="1"]').append(a);},[label,url]);await go(label,url);}
step='multiple Context windows';const second=await c.newPage();await second.goto(base+'/Writing/Context?pinned=true');await second.selectOption('[data-context-pane="0"] [data-context-tab]','locations');await second.getByRole('heading',{name:'Bedroom',exact:true}).waitFor();await ready();await second.getByRole('link',{name:'Edit Location',exact:true}).click();await main.waitForURL('**/Locations/Edit/103');assert.deepEqual(await snapshot(),before);
step='closed main and rapid requests';await main.close();await p.waitForTimeout(600);await p.evaluate(()=>{const a=document.createElement('a');a.textContent='Fallback main';a.href='/Characters?projectId=7';document.querySelector('[data-spatial-details]').append(a);});const popup=p.waitForEvent('popup');await p.getByRole('link',{name:'Fallback main',exact:true}).click();main=await popup;await main.waitForURL('**/Characters?projectId=7');await p.getByRole('link',{name:'Open in Maps',exact:true}).click();await main.waitForURL(u=>u.pathname+u.search===mapUrl.pathname+mapUrl.search);assert.equal(c.pages().length,count+1);assert.deepEqual(await snapshot(),before);
step='blocked popup remains intercepted';await main.close();await p.waitForTimeout(600);await p.evaluate(()=>{window.open=()=>null;});await p.getByRole('link',{name:'Edit Location',exact:true}).click();await p.getByText('Your browser blocked the main window.',{exact:false}).waitFor();assert.deepEqual(await snapshot(),before);
diff --git a/PlotLine.Tests/ContextWorkspaceNavigationTests.cs b/PlotLine.Tests/ContextWorkspaceNavigationTests.cs
index 499c5160..08a8a140 100644
--- a/PlotLine.Tests/ContextWorkspaceNavigationTests.cs
+++ b/PlotLine.Tests/ContextWorkspaceNavigationTests.cs
@@ -3,14 +3,14 @@ internal static class ContextWorkspaceNavigationTests
{
public static void Run()
{
- foreach(var url in new[]{"/Locations/Details/15", "/Locations/Edit/15", "/Characters/Edit/8", "/Maps?projectId=7&id=12&featureId=one", "/FloorPlans/Edit/5?selectedBlockId=44", "/StoryCalendar?bookId=12", "/PlotThreads/Edit/8", "/RelationshipMap?sceneId=20"})
+ foreach(var url in new[]{"/Locations/Details/15", "/Locations/Edit/15", "/Characters/Edit/8", "/Maps?projectId=7&id=12&featureId=one", "/FloorPlans/Edit/5?selectedBlockId=44", "/StoryCalendar?bookId=12", "/Books/Details/12", "/manuscript/paragraphs?bookId=12", "/PlotThreads/Edit/8", "/RelationshipMap?sceneId=20"})
if(!ContextWorkspaceNavigation.IsAllowed(url))throw new Exception("Main page rejected: "+url);
foreach(var url in new[]{"https://example.com/Maps", "//example.com/Maps", "/\\example.com/Maps", "/Maps\r\n", "/Maps/Save", "/FloorPlans/Delete/5", "/Writing/Context", "/Maps/../Account/Logout", "/%4daps"})
if(ContextWorkspaceNavigation.IsAllowed(url))throw new Exception("Unsafe or non-page route accepted: "+url);
var root=Directory.GetCurrentDirectory();
while(!File.Exists(Path.Combine(root,"PlotLine.slnx")))root=Directory.GetParent(root)?.FullName??throw new Exception("Repository missing");
var script=File.ReadAllText(Path.Combine(root,"PlotLine/wwwroot/js/context-main-window.js"));
- if(!script.Contains("closest?.('a[href]')")||!script.Contains("root.contains(link)")||!script.Contains("/Writing\\/Context")||script.Contains("link.removeAttribute('data-context-workspace-target')"))
+ if(!script.Contains("closest?.('a[href]')")||!script.Contains("/Writing\\/Context")||script.Contains("link.removeAttribute('data-context-workspace-target')"))
throw new Exception("Context must delegate dynamically inserted main-page links and keep blocked links intercepted.");
}
}
diff --git a/PlotLine/Services/Context/ContextWorkspaceNavigation.cs b/PlotLine/Services/Context/ContextWorkspaceNavigation.cs
index 3158425e..8a96068e 100644
--- a/PlotLine/Services/Context/ContextWorkspaceNavigation.cs
+++ b/PlotLine/Services/Context/ContextWorkspaceNavigation.cs
@@ -13,6 +13,6 @@ public static partial class ContextWorkspaceNavigation
return MainPage().IsMatch(path);
}
- [GeneratedRegex(@"^/(?:Characters(?:/(?:Details|Edit)/[1-9][0-9]*)?|Locations(?:/(?:Details|Edit)/[1-9][0-9]*)?|Maps|FloorPlans(?:/Edit/[1-9][0-9]*)?|Scenes/Edit/[1-9][0-9]*|Names|RelationshipMap|StoryCalendar|PlotLineWorkspace|PlotThreads/Edit/[1-9][0-9]*|Writer)/?$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
+ [GeneratedRegex(@"^/(?:Characters(?:/(?:Details|Edit)/[1-9][0-9]*)?|Locations(?:/(?:Details|Edit)/[1-9][0-9]*)?|Maps|FloorPlans(?:/Edit/[1-9][0-9]*)?|Scenes/Edit/[1-9][0-9]*|Names|RelationshipMap|StoryCalendar|PlotLineWorkspace|PlotThreads/Edit/[1-9][0-9]*|Writer|Books/Details/[1-9][0-9]*|manuscript/paragraphs)/?$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
private static partial Regex MainPage();
}
diff --git a/PlotLine/wwwroot/js/context-main-window.js b/PlotLine/wwwroot/js/context-main-window.js
index 9c512edc..38fa84ad 100644
--- a/PlotLine/wwwroot/js/context-main-window.js
+++ b/PlotLine/wwwroot/js/context-main-window.js
@@ -52,7 +52,7 @@
finally{receipts.clear();setTimeout(()=>{sending=false;const next=queued;queued=null;if(next?.isConnected)void navigate(next);},500);}
}
function click(event){
- const link=event.target.closest?.('a[href]');if(!link||!root.contains(link)||!destination(link)||event.button>1)return;
+ const link=event.target.closest?.('a[href]');if(!link||!destination(link)||event.button>1)return;
event.preventDefault();void navigate(link);
}
document.addEventListener('click',click);