diff --git a/PlotLine.Tests/Browser/maps-detached.cjs b/PlotLine.Tests/Browser/maps-detached.cjs index ed77f939..33c67ecd 100644 --- a/PlotLine.Tests/Browser/maps-detached.cjs +++ b/PlotLine.Tests/Browser/maps-detached.cjs @@ -11,18 +11,18 @@ const base=process.env.PD_MAPS_STAGE3_URL||'http://127.0.0.1:5251'; await main.goto(base+'/fixture?page=maps&story=true');await main.evaluate(()=>window.PlotDirectorMapWorkspace.setMode('story'));await main.waitForFunction(()=>!!window.PlotDirectorStoryOverlay?.data); await main.evaluate(()=>{document.getElementById('mapStoryLens').value='scene';document.getElementById('mapStoryLens').dispatchEvent(new Event('change',{bubbles:true}));window.PlotDirectorStoryOverlay.chooseScene(70);}); const popup=main.waitForEvent('popup');await main.evaluate(()=>document.getElementById('mapsDetach').click());const detached=await popup;detached.on('pageerror',e=>errors.push(e.message));detached.setDefaultTimeout(10000); - await detached.waitForFunction(()=>!!window.PlotDirectorStoryOverlay?.data);await detached.waitForFunction(()=>window.PlotDirectorStoryOverlay.state.sceneID===70); + await detached.waitForFunction(()=>!!window.PlotDirectorStoryOverlay?.data);await detached.waitForFunction(()=>!!window.PlotDirectorStoryOverlay?.data); assert.equal(new URL(detached.url()).searchParams.get('detached'),'true');assert(await detached.evaluate(()=>window.PlotDirectorWorkspaceBridge.mainAvailable)); - await main.evaluate(()=>window.PlotDirectorStoryOverlay.chooseScene(20));await detached.waitForFunction(()=>window.PlotDirectorStoryOverlay.state.sceneID===20); - await detached.evaluate(()=>window.PlotDirectorStoryOverlay.chooseScene(80));await main.waitForFunction(()=>window.PlotDirectorStoryOverlay.state.sceneID===80); - await main.evaluate(()=>document.dispatchEvent(new CustomEvent('plotdirector:story-position-changed',{detail:{projectId:7,sceneId:10}})));await detached.waitForFunction(()=>window.PlotDirectorStoryOverlay.state.sceneID===10); - await main.evaluate(()=>{document.getElementById('mapStoryLens').value='character';document.getElementById('mapStoryCharacter1').value='1';document.getElementById('mapStoryCharacter1').dispatchEvent(new Event('change',{bubbles:true}));});await detached.waitForFunction(()=>window.PlotDirectorStoryOverlay.state.lens==='character'&&window.PlotDirectorStoryOverlay.state.characterIDs[0]===1); + await main.evaluate(()=>window.PlotDirectorStoryOverlay.chooseScene(20));await detached.waitForTimeout(100);assert.notEqual(await detached.evaluate(()=>window.PlotDirectorStoryOverlay.state.sceneID),20); + await detached.evaluate(()=>window.PlotDirectorStoryOverlay.chooseScene(80));await main.waitForTimeout(100);assert.equal(await main.evaluate(()=>window.PlotDirectorStoryOverlay.state.sceneID),20); + await main.evaluate(()=>document.dispatchEvent(new CustomEvent('plotdirector:story-position-changed',{detail:{projectId:7,sceneId:10}})));await detached.waitForTimeout(100);assert.equal(await detached.evaluate(()=>window.PlotDirectorStoryOverlay.state.sceneID),80); + await main.evaluate(()=>{document.getElementById('mapStoryLens').value='character';document.getElementById('mapStoryCharacter1').value='1';document.getElementById('mapStoryCharacter1').dispatchEvent(new Event('change',{bubbles:true}));});await detached.waitForTimeout(100);assert.notEqual(await detached.evaluate(()=>window.PlotDirectorStoryOverlay.state.lens),'character'); assert.equal(saves,0);assert.equal(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.dirty),false); // A forged envelope from another user cannot change the paired view. await detached.evaluate(()=>{const token=new URLSearchParams(location.search).get('workspace'),c=new BroadcastChannel('pd-workspace:1:7:'+token);c.postMessage({uid:999,projectID:7,sender:crypto.randomUUID(),sequence:1,type:'scene-selected',payload:{sceneID:30}});c.close();}); await main.evaluate(()=>new Promise(resolve=>setTimeout(resolve,100)));assert.equal(await main.evaluate(()=>window.PlotDirectorStoryOverlay.state.lens),'character'); async function edit(page,name){await page.evaluate(()=>{const w=window.PlotDirectorMapWorkspace;w.setMode('create');w.select(w.document.features[0].featureID);});await page.locator('[data-field=name]').fill(name);await page.locator('[data-field=name]').blur();} - await edit(detached,'Detached unsaved geography');const windows=context.pages().length;await main.evaluate(()=>document.getElementById('mapsDetach').click());assert.equal(context.pages().length,windows,'Repeated Detach focuses the existing dirty workspace');assert(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.dirty));await main.evaluate(()=>window.PlotDirectorStoryOverlay.chooseScene(30));assert.equal(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.mode),'create');assert.equal(await detached.locator('[data-field=name]').inputValue(),'Detached unsaved geography'); + await edit(detached,'Detached unsaved geography');const windows=context.pages().length;const anotherPopup=main.waitForEvent('popup');await main.evaluate(()=>document.getElementById('mapsDetach').click());const another=await anotherPopup;assert.equal(context.pages().length,windows+1,'Each detach creates an independent workspace');await another.close();assert(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.dirty));await main.evaluate(()=>window.PlotDirectorStoryOverlay.chooseScene(30));assert.equal(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.mode),'create');assert.equal(await detached.locator('[data-field=name]').inputValue(),'Detached unsaved geography'); await edit(main,'Main saved geography');assert(await main.evaluate(()=>window.PlotDirectorMapWorkspace.save()));await detached.waitForFunction(()=>document.getElementById('mapsStatus').textContent.includes('another window')); assert.equal(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.save()),false);assert.equal(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.dirty),true);assert.equal(await detached.locator('[data-field=name]').inputValue(),'Detached unsaved geography');assert.equal(revision,13); await detached.evaluate(()=>{void window.PlotDirectorMapWorkspace.requestLeave(()=>{});});await detached.getByRole('button',{name:'Discard changes',exact:true}).click();await main.close(); @@ -30,6 +30,6 @@ const base=process.env.PD_MAPS_STAGE3_URL||'http://127.0.0.1:5251'; // An explicit Open scene still works when its former main window has closed. await context.route('**/Scenes/Edit/*',r=>r.fulfill({contentType:'text/html',body:'

Scene editor

'})); await detached.getByRole('link',{name:'Open / edit scene',exact:true}).click();await detached.waitForURL('**/Scenes/Edit/90'); - assert.deepEqual(errors,[]);console.log(`PASS Maps detached ${pwa?'PWA':'web'}: explicit popup, paired scenes/lens/characters, canonical scene event, envelope scope, dirty peer protection, optimistic conflict, closed-opener fallback`);await context.close(); + assert.deepEqual(errors,[]);console.log(`PASS Maps detached ${pwa?'PWA':'web'}: explicit popup, independent scenes/lens/characters and modes, envelope scope, dirty peer protection, optimistic conflict, closed-opener fallback`);await context.close(); } }finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine.Tests/Browser/maps-workspace.cjs b/PlotLine.Tests/Browser/maps-workspace.cjs index decaef8e..782c9f8f 100644 --- a/PlotLine.Tests/Browser/maps-workspace.cjs +++ b/PlotLine.Tests/Browser/maps-workspace.cjs @@ -13,7 +13,7 @@ const base=process.env.PD_MAPS_TEST_URL||'http://127.0.0.1:5246'; const canvas=page.locator('#mapsCanvas'); async function sourceClick(id){ const proxy=page.locator(`[data-pwa-context-controls] [data-command-identity="handler:${id}"]`); - if(pwa&&await proxy.count()){ + if(pwa&&await proxy.count()&&!await page.locator('#mapsApp').evaluate(n=>n.classList.contains('pd-workspace-maximised'))){ const menu=proxy.locator('xpath=ancestor::details[1]'); if(await menu.count()&&await menu.getAttribute('data-compact')==='true'&&await menu.getAttribute('open')===null)await menu.locator(':scope > summary').click(); await proxy.click(); @@ -62,8 +62,7 @@ const base=process.env.PD_MAPS_TEST_URL||'http://127.0.0.1:5246'; await page.evaluate(async()=>{window.PlotDirectorMapWorkspace.setMode('create');await window.PlotDirectorMapWorkspace.save();}); await page.evaluate(()=>document.querySelector('button[data-mode="story"]').click());assert(await page.locator('#mapsStory').isVisible()); await page.evaluate(()=>document.querySelector('button[data-mode="create"]').click()); - if(pwa){assert(await page.locator('#mapsMaximise').isHidden());assert(await page.locator('.maps-toolbar').isHidden());} - else{await sourceClick('mapsMaximise');assert(await page.locator('#mapsApp').evaluate(el=>el.classList.contains('maps-maximised')));await sourceClick('mapsMaximise');} + {await sourceClick('mapsMaximise');assert(await page.locator('#mapsApp').evaluate(el=>el.classList.contains('maps-maximised')));await sourceClick('mapsMaximise');} // Pan is stable under repeated pointer moves; zoom and selection do not replace the SVG. const same=await page.evaluate(()=>{window.__mapCanvas=document.getElementById('mapsCanvas');return true;}); await sourceClick('mapsZoomIn');await sourceClick('mapsZoomOut');assert(await page.evaluate(()=>window.__mapCanvas===document.getElementById('mapsCanvas'))); diff --git a/PlotLine.Tests/Browser/workspace-refinements-dev.cjs b/PlotLine.Tests/Browser/workspace-refinements-dev.cjs new file mode 100644 index 00000000..6c186ef7 --- /dev/null +++ b/PlotLine.Tests/Browser/workspace-refinements-dev.cjs @@ -0,0 +1,62 @@ +// Development acceptance against real authenticated routes and a disposable owned fixture. +const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs'); +const [identityPath,fixturePath]=process.argv.slice(2); +if(![identityPath,fixturePath].every(p=>p?.startsWith('/tmp/pd-dev-browser-')))throw Error('Dedicated Development fixture files required'); +const identity=JSON.parse(fs.readFileSync(identityPath)),f=JSON.parse(fs.readFileSync(fixturePath)); +if(identity.Database!=='PlotDirector_Development'||!identity.Email.startsWith('pwa-browser-'))throw Error('Development identity required'); +const base='https://dev.plotdirector.com',root=`${base}/Maps?projectId=${f.ProjectID}&id=${f.MapID}`; +(async()=>{const browser=await chromium.launch();try{ + const login=await browser.newContext(),lp=await login.newPage();await lp.goto(base+'/Account/Login');await lp.locator('#Email').fill(identity.Email);await lp.locator('#Password').fill(identity.Password);await Promise.all([lp.waitForURL('**/Projects'),lp.locator('form[action="/Account/Login"] button[type=submit]').click()]); + for(const pwa of [false,true]){ + const context=await browser.newContext({storageState:await login.storageState(),viewport:{width:1800,height:1100}}),errors=[]; + if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true})); + const page=await context.newPage();page.on('pageerror',e=>errors.push(e.message));page.setDefaultTimeout(15000); + const ready=p=>p.waitForFunction(()=>!!window.PlotDirectorMapWorkspace); + async function command(id){ + const source=page.locator('#'+id);if(await source.isVisible()){await source.click();return;} + const proxy=page.locator(`[data-pwa-context-controls] [data-command-identity="handler:${id}"]`); + for(const menu of await proxy.locator('xpath=ancestor::details').all())if(await menu.getAttribute('open')===null)await menu.locator(':scope > summary').click();await proxy.click(); + } + async function maximise(selector,id,snapshot){ + const before=await page.evaluate(snapshot),box=await page.locator(selector).boundingBox();await command(id); + await page.waitForFunction(s=>document.querySelector(s).classList.contains('pd-workspace-maximised'),selector); + await page.waitForTimeout(150);const full=await page.locator(selector).boundingBox();assert(full.x<=5&&full.y<=5&&full.width>=1790);assert(full.height>box.height); + assert.equal(await page.locator('.pd-application-header').evaluate(n=>getComputedStyle(n).visibility),'hidden'); + assert.deepEqual(await page.evaluate(snapshot),before); + await page.screenshot({path:`/tmp/workspace-${id}-${pwa?'pwa':'web'}-max.png`}); + await page.locator('#'+id).click();await page.waitForTimeout(150);assert.deepEqual(await page.evaluate(snapshot),before);assert.equal(await page.locator('.pd-application-header').evaluate(n=>getComputedStyle(n).visibility),'visible'); + } + await page.goto(`${base}/FloorPlans?projectId=${f.ProjectID}`);const index=await page.locator('.floor-plan-index-shell').boundingBox();assert(index.width<=1201);assert(Math.abs(index.x-(1800-index.width)/2)<2); + await page.screenshot({path:`/tmp/workspace-floor-index-${pwa?'pwa':'web'}.png`}); + await page.goto(`${base}/FloorPlans/Edit/${f.FloorPlanID}`);await page.waitForFunction(()=>document.querySelector('[data-floor-plan-editor]')?.dataset.floorPlanInitialized==='true'); + assert((await page.locator('[data-floor-plan-workspace]').boundingBox()).width>1750); + for(const tab of ['add','transitions'])assert(await page.locator(`.floor-plan-build [data-toolbox-tab=${tab}]`).count()); + for(const tab of ['selected','floors','background'])assert(await page.locator(`.floor-plan-inspector [data-toolbox-tab=${tab}]`).count()); + await page.locator('[data-toolbox-tab=floors]').click();assert(await page.locator('.floor-plan-inspector [data-toolbox-panel=floors]').isVisible()); + const block=page.locator('.floor-plan-floor.active [data-block]').first();await block.click();assert(await page.locator('[data-toolbox-panel=selected]').isVisible()); + await maximise('[data-floor-plan-workspace]','floorPlanMaximise',()=>({selected:document.querySelector('[data-block].selected')?.dataset.block, floor:document.querySelector('.floor-plan-floor.active')?.dataset.floorPanel,scroll:[...document.querySelectorAll('.floor-plan-floor.active .floor-plan-grid-wrap')].map(n=>[n.scrollLeft,n.scrollTop])})); + await page.screenshot({path:`/tmp/workspace-floor-${pwa?'pwa':'web'}.png`}); + await page.goto(`${base}/Maps?projectId=${f.ProjectID}`);await ready(page);assert.equal(await page.locator('#mapsWelcomeNew').textContent(),'Create new map'); + await page.goto(root);await ready(page);assert.equal(await page.locator('#mapsContext').count(),0);assert.equal(await page.locator('[data-command-identity="handler:mapsContext"]').count(),0); + assert(Math.abs((await page.locator('#mapsDefine').boundingBox()).width-(await page.locator('#mapsAssets').boundingBox()).width)<2); + await page.evaluate(()=>{const w=window.PlotDirectorMapWorkspace;w.select(w.document.features[0].featureID);});await command('mapsZoomIn'); + await maximise('#mapsApp','mapsMaximise',()=>({view:{...window.PlotDirectorMapWorkspace.view},selected:window.PlotDirectorMapWorkspace.selected,mode:window.PlotDirectorMapWorkspace.mode})); + await page.locator('#mapsCanvas').click({button:'right',position:{x:30,y:30}});await page.locator('.pd-context-popup').waitFor();await page.keyboard.press('Escape'); + const firstPromise=page.waitForEvent('popup');await command('mapsDetach');const first=await firstPromise;await ready(first); + const secondPromise=page.waitForEvent('popup');await command('mapsDetach');const second=await secondPromise;await ready(second);assert.notEqual(first,second); + await first.locator('#mapsSelect').selectOption(String(f.ChildMapID));await first.waitForURL(u=>u.searchParams.get('id')===String(f.ChildMapID));await ready(first);await page.waitForTimeout(200); + assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.document.map.mapID),f.MapID);assert.equal(await second.evaluate(()=>window.PlotDirectorMapWorkspace.document.map.mapID),f.MapID); + const retained=await page.evaluate(()=>({view:{...window.PlotDirectorMapWorkspace.view},selected:window.PlotDirectorMapWorkspace.selected,mode:window.PlotDirectorMapWorkspace.mode})); + await first.evaluate(()=>window.PlotDirectorMapWorkspace.setMode('explore'));await first.locator('#mapsZoomIn').click();assert.deepEqual(await page.evaluate(()=>({view:{...window.PlotDirectorMapWorkspace.view},selected:window.PlotDirectorMapWorkspace.selected,mode:window.PlotDirectorMapWorkspace.mode})),retained); + // Both clients hold the same revision. The server must accept one and reject the stale write. + const original=await page.evaluate(()=>window.PlotDirectorMapWorkspace.document.features[0].name); + await second.evaluate(()=>{const w=window.PlotDirectorMapWorkspace;w.edit(()=>w.document.features[0].name='Stale window acceptance edit');}); + await page.evaluate(()=>{const w=window.PlotDirectorMapWorkspace;w.edit(()=>w.document.features[0].name+=' acceptance saved');});assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.save()),true); + const rejected=second.waitForResponse(r=>r.url().endsWith('/Maps/Save')&&r.status()===409);assert.equal(await second.evaluate(()=>window.PlotDirectorMapWorkspace.save()),false);await rejected; + assert.equal(await second.evaluate(()=>window.PlotDirectorMapWorkspace.dirty),true);assert.equal(await second.evaluate(()=>window.PlotDirectorMapWorkspace.document.features[0].name),'Stale window acceptance edit'); + const stored=await(await context.request.get(`${base}/Maps/State?projectId=${f.ProjectID}&id=${f.MapID}`)).json();assert.equal(stored.features[0].name,original+' acceptance saved'); + await page.evaluate(name=>{const w=window.PlotDirectorMapWorkspace;w.edit(()=>w.document.features[0].name=name);},original);assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.save()),true); + await first.screenshot({path:`/tmp/workspace-independent-child-${pwa?'pwa':'web'}.png`});await page.screenshot({path:`/tmp/workspace-independent-main-${pwa?'pwa':'web'}.png`}); + assert.deepEqual(errors,[]);console.log(`PASS Development ${pwa?'PWA':'web'}: centred index, full-width floor editor, panel arrangement, maximise/restore and retained state, Maps palette/context, three independent windows, real HTTP 409 conflict with retained edits`);await context.close(); + } +}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine/Help/Articles/FloorPlans/Overview.md b/PlotLine/Help/Articles/FloorPlans/Overview.md index f2aa29c0..3023a35c 100644 --- a/PlotLine/Help/Articles/FloorPlans/Overview.md +++ b/PlotLine/Help/Articles/FloorPlans/Overview.md @@ -27,6 +27,12 @@ Floor Plans are especially useful when: - different floors need to line up - you want to check where everyone and everything is at a specific point in the story +# Editor workspace + +The editor fills the available width. Add block and Transitions are on the left. Selected block, Floors and Plan / background are on the right; choose a tab to inspect or edit those settings. + +Use **Maximise workspace** to hide application chrome and expand the editor in a browser or installed app. **Restore workspace** returns to the usual layout. Zoom, pan and selection remain in place. + # Structure Mode And Occupancy Mode Structure mode is where you build and edit the plan. You add floors, place room blocks, resize them, connect locations with doors or passages, and use grid guides or background images. diff --git a/PlotLine/Help/Articles/Maps/Workspace.md b/PlotLine/Help/Articles/Maps/Workspace.md new file mode 100644 index 00000000..30daaa56 --- /dev/null +++ b/PlotLine/Help/Articles/Maps/Workspace.md @@ -0,0 +1,20 @@ +--- +title: Maps Workspace +category: Maps +tags: maps, workspace, separate windows, saving +contextKey: maps.workspace +micro: Arrange your story geography and open independent map windows. +quickTitle: Maps workspace +quickSummary: Maximise the workspace or open several maps in separate windows. Save checks protect against conflicting edits. +screenshot: +--- + +# Workspace controls + +Use **Maximise workspace** to hide the application chrome in a browser or installed app. **Restore workspace** returns to the usual layout, retaining your view and selection. Right-click the canvas or a map piece for its context menu. + +# Separate map windows + +**Open in separate window** opens a new map workspace each time. Each window has its own map, zoom, pan, selected object, editing tool and panels. Navigating or changing Story mode in one window leaves the others where they are. + +Saved map data is shared. If another window saves the same map first, your older save is rejected and your unsaved edits stay visible. Copy or record any edits you need before reloading the newer map, then reapply them. Changes are never merged automatically. diff --git a/PlotLine/Views/FloorPlans/Edit.cshtml b/PlotLine/Views/FloorPlans/Edit.cshtml index 2faa1944..9a3d43f1 100644 --- a/PlotLine/Views/FloorPlans/Edit.cshtml +++ b/PlotLine/Views/FloorPlans/Edit.cshtml @@ -2,6 +2,7 @@ @{ ViewData["Title"] = Model.FloorPlan.FloorPlanID == 0 ? "New Floor Plan" : Model.FloorPlan.Name; ViewData["ProjectSection"] = "Floor Plans"; + ViewData["ShellClass"] = "plotline-shell-wide floor-plan-editor-shell"; var activeFloor = Model.Floors.OrderBy(x => x.SortOrder).ThenBy(x => x.Name).FirstOrDefault(); var blocksByFloor = Model.Blocks.GroupBy(x => x.FloorPlanFloorID).ToDictionary(x => x.Key, x => x.ToList()); var transitionsByFloor = Model.Transitions.GroupBy(x => x.FloorPlanFloorID).ToDictionary(x => x.Key, x => x.ToList()); @@ -195,7 +196,7 @@ - + @@ -617,8 +548,83 @@