From 6a84d0e5b32ee9e18ac34a5a57de80581e6700b5 Mon Sep 17 00:00:00 2001 From: Atlas Development Worker Date: Tue, 1 Dec 2026 20:01:50 +0000 Subject: [PATCH] Add resizable Context spatial information and drawing panels --- .../context-spatial-layout-development.cjs | 31 +++++++++++++++++++ PlotLine/Views/Writing/_ContextSpatial.cshtml | 16 +++++++--- PlotLine/wwwroot/css/context-spatial.css | 19 ++++++++++++ PlotLine/wwwroot/js/context-spatial.js | 21 +++++++++++++ 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 PlotLine.Tests/Browser/context-spatial-layout-development.cjs diff --git a/PlotLine.Tests/Browser/context-spatial-layout-development.cjs b/PlotLine.Tests/Browser/context-spatial-layout-development.cjs new file mode 100644 index 00000000..6414b913 --- /dev/null +++ b/PlotLine.Tests/Browser/context-spatial-layout-development.cjs @@ -0,0 +1,31 @@ +// Genuine Development layout interactions; server records use ordinary forms. +const assert=require('node:assert/strict'),{open}=require('./dev-acceptance.cjs'); +let session,stage='login'; +(async()=>{try{ + session=await open();const p=session.page,project=await session.project(); + const place=await session.create('Locations','?projectId='+project,{LocationName:'Layout harbour',Description:'Scrollable saved detail.\n'.repeat(150)}); + const book=await session.create('Books','?projectId='+project,{BookTitle:'Spatial layout acceptance',BookNumber:1}); + const chapter=await session.create('Chapters','?bookId='+book,{ChapterTitle:'Layout chapter',ChapterNumber:1}); + await session.goto('/Scenes/Create?chapterId='+chapter);await p.locator('#SceneTitle').fill('Layout scene');await p.locator('#PrimaryLocationID').selectOption(String(place));await p.getByRole('button',{name:'Create scene',exact:true}).click();await p.waitForURL('**/Scenes/Edit/*');const scene=Number(new URL(p.url()).pathname.split('/').at(-1)); + const feature=`/Writing/Context?projectId=${project}&bookId=${book}&chapterId=${chapter}&sceneId=${scene}&pinned=true`; + await session.goto(feature);await p.setViewportSize({width:1280,height:850}); + const pane=p.locator('[data-context-pane="0"]'),tab=pane.locator('[data-context-tab]'),handle=pane.getByRole('separator'),layout=pane.locator('[data-spatial-layout]'),orientation=pane.locator('[data-spatial-orientation]'); + const initial=await p.evaluate(()=>({...document.querySelector('[data-context-workspace]').contextController.position})); + for(const kind of ['locations','maps','floorplans']){ + stage=kind+' resize';await tab.selectOption(kind);await handle.waitFor();assert.equal(await handle.getAttribute('aria-valuenow'),'30'); + if(kind==='locations'){await pane.getByRole('heading',{name:'Layout harbour',exact:true}).waitFor();const scroll=await pane.locator('[data-spatial-details]').evaluate(n=>{n.scrollTop=100;return {top:n.scrollTop,scroll:n.scrollHeight,height:n.clientHeight};});assert(scroll.top>0&&scroll.scroll>scroll.height);assert.equal(await pane.locator('[data-spatial-scenes]').evaluate(n=>n.scrollTop),0);} + await handle.focus();await handle.press('ArrowRight');assert.equal(await handle.getAttribute('aria-valuenow'),'32'); + await orientation.selectOption('vertical');assert.equal(await handle.getAttribute('aria-valuenow'),'30');await handle.focus();await handle.press('ArrowDown');assert.equal(await handle.getAttribute('aria-valuenow'),'32'); + const box=await layout.boundingBox(),grip=await handle.boundingBox();await p.mouse.move(grip.x+grip.width/2,grip.y+grip.height/2);await p.mouse.down();await p.mouse.move(box.x+box.width/2,box.y+box.height*.45,{steps:10});await p.mouse.up();const stacked=Number(await handle.getAttribute('aria-valuenow'));assert(stacked>=43&&stacked<=47); + await orientation.selectOption('horizontal');assert.equal(await handle.getAttribute('aria-valuenow'),'32'); + const horizontal=await layout.boundingBox(),h=await handle.boundingBox();await p.mouse.move(h.x+h.width/2,h.y+h.height/2);await p.mouse.down();await p.mouse.move(horizontal.x+horizontal.width*.4,h.y+h.height/2,{steps:10});await p.mouse.up();assert(Number(await handle.getAttribute('aria-valuenow'))>=38); + await p.reload();await handle.waitFor();assert.equal(await tab.inputValue(),kind);assert.equal(await orientation.inputValue(),'horizontal');assert(Number(await handle.getAttribute('aria-valuenow'))>=38);await orientation.selectOption('vertical');assert.equal(Number(await handle.getAttribute('aria-valuenow')),stacked); + await p.setViewportSize({width:460,height:850});assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1));const panels=await layout.evaluate(n=>[...n.children].filter(x=>x.tagName!=='DIV').map(x=>({w:x.clientWidth,h:x.clientHeight})));assert(panels.every(x=>x.w>0&&x.h>0));await p.setViewportSize({width:1280,height:850}); + } + stage='window isolation';const other=await p.context().newPage();await other.goto('https://dev.plotdirector.com'+feature);await other.selectOption('[data-context-pane="0"] [data-context-tab]','floorplans');assert.equal(await other.locator('[data-spatial-splitter]').getAttribute('aria-valuenow'),'30');await other.close(); + stage='pane isolation';await p.selectOption('[data-context-layout]','columns');await p.selectOption('[data-context-pane="1"] [data-context-tab]','floorplans');assert.equal(await p.locator('[data-context-pane="1"] [data-spatial-orientation]').inputValue(),'horizontal');assert.equal(await p.locator('[data-context-pane="1"] [data-spatial-splitter]').getAttribute('aria-valuenow'),'30');assert.equal(await orientation.inputValue(),'vertical'); + assert.deepEqual(await p.evaluate(()=>({...document.querySelector('[data-context-workspace]').contextController.position})),initial); + console.log(JSON.stringify({passed:true,checks:['all three tools pointer and keyboard resizing in both orientations','independent proportions restored on reload','narrow viewport boundaries','pane isolation','manuscript focus preserved'],featureUrl:'https://dev.plotdirector.com'+feature})); + }catch(e){console.error('Spatial layout acceptance failed at '+stage+' ('+e.name+').');if(e.name==='AssertionError')console.error(e.message);process.exitCode=1;} + finally{if(session){try{await session.cleanup();console.log('PASS disposable project cleanup');}finally{await session.close();}}} +})(); diff --git a/PlotLine/Views/Writing/_ContextSpatial.cshtml b/PlotLine/Views/Writing/_ContextSpatial.cshtml index dc7476f3..ecddfa00 100644 --- a/PlotLine/Views/Writing/_ContextSpatial.cshtml +++ b/PlotLine/Views/Writing/_ContextSpatial.cshtml @@ -2,14 +2,22 @@ @model PlotLine.Services.Context.SpatialFragment
-
+
@if(Model.Kind=="locations"){ -

Loading recorded locations…

+

Loading recorded locations…

}else{ -
Open in @(Model.Kind=="maps"?"Maps":"Floor Plans")
-

+
+
+
+

+
+
+
+
+
+
} diff --git a/PlotLine/wwwroot/css/context-spatial.css b/PlotLine/wwwroot/css/context-spatial.css index 285d8bbd..8ec084e7 100644 --- a/PlotLine/wwwroot/css/context-spatial.css +++ b/PlotLine/wwwroot/css/context-spatial.css @@ -17,3 +17,22 @@ .spatial-character-marker{display:inline-flex;position:relative;z-index:9;align-items:center;justify-content:center;min-width:24px;height:24px;border:1px solid var(--plotline-ink);border-radius:50%;background:var(--plotline-surface);color:var(--plotline-ink);font-size:11px;margin:2px} .context-spatial [data-spatial-characters]{max-height:8rem;overflow:auto;flex:none} .spatial-sensory-legend{padding:.25rem;max-width:55rem} + +/* Shared spatial split: each pane scrolls without changing the drawing viewport. */ +.context-spatial .spatial-split-layout{display:grid;grid-template-columns:minmax(0,var(--spatial-split,30%)) .65rem minmax(0,1fr);grid-template-rows:minmax(0,1fr);flex:1;min-height:0;min-width:0;overflow:hidden;gap:0} +.context-spatial .spatial-split-layout[data-orientation="vertical"]{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,var(--spatial-split,30%)) .65rem minmax(0,1fr)} +.spatial-split-layout>nav,.spatial-split-layout>section{min-width:0;min-height:0;overflow:auto;border:1px solid var(--plotline-border-soft);border-radius:.2rem;padding:.35rem;overscroll-behavior:contain} +.spatial-splitter{cursor:col-resize;touch-action:none;position:relative;background:var(--plotline-surface)} +.spatial-splitter:after{content:'';position:absolute;inset:25% 35%;border-radius:2px;background:var(--plotline-border-soft)} +[data-orientation="vertical"]>.spatial-splitter{cursor:row-resize} +[data-orientation="vertical"]>.spatial-splitter:after{inset:35% 25%} +.spatial-splitter:focus-visible{outline:2px solid var(--bs-primary);outline-offset:-2px;z-index:1} +.spatial-split-layout>.spatial-drawing{display:flex;flex-direction:column;padding:0;overflow:hidden} +.spatial-drawing .spatial-canvas{min-height:0;min-width:0} +.spatial-information [data-spatial-characters]{max-height:none;overflow:visible} +.spatial-information h3{font-size:.95rem;margin:.65rem 0 .35rem} +.spatial-resizing{user-select:none} +.spatial-resizing iframe{pointer-events:none} +.context-spatial .spatial-toolbar{min-height:2.2rem;gap:.35rem} +.context-spatial .spatial-toolbar button,.context-spatial .spatial-toolbar select{min-height:2rem} +@container(max-width:580px){.spatial-split-layout>nav,.spatial-split-layout>section{padding:.2rem}.spatial-toolbar label{flex-wrap:wrap}.spatial-toolbar select{min-width:0;max-width:100%}.spatial-scene button{font-size:.8rem}} diff --git a/PlotLine/wwwroot/js/context-spatial.js b/PlotLine/wwwroot/js/context-spatial.js index 0d0f8df5..3eae096c 100644 --- a/PlotLine/wwwroot/js/context-spatial.js +++ b/PlotLine/wwwroot/js/context-spatial.js @@ -14,9 +14,30 @@ function path(data,location){return ancestors(data,location).reverse().map(l=>l.locationName).join(' / ');} function resolution(data,location,kind){const links=kind==='maps'?data.maps:data.plans;for(const [depth,l]of ancestors(data,location).entries()){const found=links.filter(x=>x.locationID===id(l)&&(kind!=='maps'||x.isPlaced));if(found.length)return found.map(link=>({...link,depth,represented:id(l)})).sort((a,b)=>Number(!!b.blockID)-Number(!!a.blockID)||Number(!!b.floorID)-Number(!!a.floorID));}return [];} function icon(data,location){const t=data.types.find(t=>t.assignable!==false&&String(t.value)===String(location?.locationTypeID??''));const n=el('span',null,`spatial-type text-${t?.tone||'secondary'}`);if(t?.path){const svg=document.createElementNS('http://www.w3.org/2000/svg','svg');svg.setAttribute('viewBox','0 0 24 24');svg.setAttribute('aria-hidden','true');const p=document.createElementNS(svg.namespaceURI,'path');p.setAttribute('d',t.path);p.setAttribute('fill',t.filled?'currentColor':'none');svg.append(p);n.append(svg);}n.title=t?.label||'Unclassified';return n;} + // One splitter implementation for all spatial tools. Layout preferences belong to a pane, + // independently of renderer preferences and of the currently inspected scene. + function spatialLayout(node,key,signal){ + const layout=node.querySelector('[data-spatial-layout]'),handle=node.querySelector('[data-spatial-splitter]'),menu=node.querySelector('[data-spatial-orientation]'); + let saved={};try{saved=JSON.parse(localStorage.getItem(key))||{};}catch{} + let orientation=saved.orientation==='vertical'?'vertical':'horizontal'; + const clamp=n=>Math.max(10,Math.min(90,n)); + const ratio=()=>Number.isFinite(saved[orientation])?clamp(saved[orientation]):30; + const persist=()=>{try{localStorage.setItem(key,JSON.stringify({...saved,orientation}));}catch{}}; + function apply(){layout.dataset.orientation=orientation;layout.style.setProperty('--spatial-split',`${ratio()}%`);menu.value=orientation;handle.setAttribute('aria-orientation',orientation==='horizontal'?'vertical':'horizontal');handle.setAttribute('aria-valuenow',String(Math.round(ratio())));handle.setAttribute('aria-valuetext',`${Math.round(ratio())}% information, ${Math.round(100-ratio())}% detail`);} + handle.className='spatial-splitter';handle.tabIndex=0;handle.setAttribute('role','separator');handle.setAttribute('aria-label','Resize information and detail panels');handle.setAttribute('aria-valuemin','10');handle.setAttribute('aria-valuemax','90'); + menu.addEventListener('change',()=>{orientation=menu.value;apply();persist();},{signal}); + handle.addEventListener('keydown',e=>{const back=orientation==='horizontal'?'ArrowLeft':'ArrowUp',forward=orientation==='horizontal'?'ArrowRight':'ArrowDown';if(![back,forward,'Home','End'].includes(e.key))return;e.preventDefault();saved[orientation]=e.key==='Home'?10:e.key==='End'?90:clamp(ratio()+(e.key===back?-1:1)*(e.shiftKey?10:2));apply();persist();},{signal}); + let pointer=null; + handle.addEventListener('pointerdown',e=>{if(e.button!==0)return;e.preventDefault();pointer=e.pointerId;handle.setPointerCapture(pointer);handle.focus({preventScroll:true});layout.classList.add('spatial-resizing');},{signal}); + handle.addEventListener('pointermove',e=>{if(e.pointerId!==pointer)return;const box=layout.getBoundingClientRect(),size=orientation==='horizontal'?box.width:box.height;if(size<=0)return;saved[orientation]=clamp(100*(orientation==='horizontal'?e.clientX-box.left:e.clientY-box.top)/size);apply();},{signal}); + const end=e=>{if(e.pointerId!==pointer)return;pointer=null;layout.classList.remove('spatial-resizing');persist();}; + for(const event of ['pointerup','pointercancel','lostpointercapture'])handle.addEventListener(event,end,{signal}); + apply(); + } function mount(node,context){if(instances.has(node))return;const root=node.closest('[data-context-workspace]'),bus=session(root),kind=node.dataset.spatialContext,abort=new AbortController();let position=context.position,data,selection,loadedInspection,epoch=0,disposed=false,busy=false,resource=null,renderer=null,floorSnapshot=null,floorRoom=null,visibility=false,audibility=false,operation=null,undo=null; const q=s=>node.querySelector(s),status=q('[data-spatial-status]'),error=q('[data-spatial-error]'),canvas=q('[data-spatial-canvas]'); const pref=`plotdirector.spatial.v1.${root.dataset.user}.${context.windowId}.${position.projectId}.${kind}`;let preferences={};try{preferences=JSON.parse(localStorage.getItem(pref))||{};}catch{} + spatialLayout(node,`${pref}.pane.${context.paneId}.layout`,abort.signal); const save=()=>{try{localStorage.setItem(pref,JSON.stringify(preferences));}catch{}}; const guard=(value,deferRefresh=false)=>{busy=value;node.dispatchEvent(new CustomEvent('context-panel-state',{bubbles:true,detail:{dirty:value,busy:false,deferRefresh}}));}; const fail=e=>{if(!disposed){error.textContent=e.message;if(data)q('[data-spatial-return]').disabled=false;}};