From ba6a949047017ddf1dde28f898adc990a1218b3f Mon Sep 17 00:00:00 2001 From: Atlas Development Worker Date: Tue, 1 Dec 2026 19:50:30 +0000 Subject: [PATCH] Refine Context Calendar panels, chapter chips and elapsed time --- .../Browser/context-calendar-development.cjs | 13 +++--- PlotLine.Tests/Browser/context-calendar.cjs | 11 +++-- .../Controllers/ContextCalendarController.cs | 2 +- .../Views/Writing/_ContextCalendar.cshtml | 11 ++++- PlotLine/wwwroot/css/context-calendar.css | 46 ++++++++++++------- PlotLine/wwwroot/js/context-calendar.js | 34 ++++++++++---- 6 files changed, 77 insertions(+), 40 deletions(-) diff --git a/PlotLine.Tests/Browser/context-calendar-development.cjs b/PlotLine.Tests/Browser/context-calendar-development.cjs index ac5193bc..b55a3810 100644 --- a/PlotLine.Tests/Browser/context-calendar-development.cjs +++ b/PlotLine.Tests/Browser/context-calendar-development.cjs @@ -5,16 +5,17 @@ let session,stage='login'; session=await open();let p=session.page;const project=await session.project(); const book=await session.create('Books','?projectId='+project,{BookTitle:'Calendar first',BookNumber:1}),otherBook=await session.create('Books','?projectId='+project,{BookTitle:'Calendar second',BookNumber:2}); const chapter=await session.create('Chapters','?bookId='+book,{ChapterTitle:'Same chapter',ChapterNumber:1}),otherChapter=await session.create('Chapters','?bookId='+otherBook,{ChapterTitle:'Other book chapter',ChapterNumber:1}),undatedChapter=await session.create('Chapters','?bookId='+book,{ChapterTitle:'Undated chapter',ChapterNumber:2}); - async function scene(ch,title,date){await session.goto('/Scenes/Create?chapterId='+ch);await p.locator('#SceneTitle').fill(title);if(date){const exact=await p.locator('#TimeModeID option').evaluateAll(ns=>ns.find(n=>/exact/i.test(n.textContent))?.value);assert(exact);await p.locator('#TimeModeID').selectOption(exact);await p.locator('#StartDateTime').fill(date+'T10:00');}await p.getByRole('button',{name:'Create scene',exact:true}).click();await p.waitForURL('**/Scenes/Edit/*');return Number(new URL(p.url()).pathname.split('/').at(-1));} + async function scene(ch,title,date){await session.goto('/Scenes/Create?chapterId='+ch);await p.locator('#SceneTitle').fill(title);await p.locator('[name=Summary]').fill('Saved calendar summary for '+title+'\n'+('Summary detail line.\n'.repeat(60)));if(date){const exact=await p.locator('#TimeModeID option').evaluateAll(ns=>ns.find(n=>/exact/i.test(n.textContent))?.value);assert(exact);await p.locator('#TimeModeID').selectOption(exact);await p.locator('#StartDateTime').fill(date+'T10:00');}await p.getByRole('button',{name:'Create scene',exact:true}).click();await p.waitForURL('**/Scenes/Edit/*');return Number(new URL(p.url()).pathname.split('/').at(-1));} stage='saved chronology';const first=await scene(chapter,'First dated scene','1983-11-19'),second=await scene(chapter,'Second dated scene','1983-11-19'),other=await scene(otherChapter,'Other book collision','1983-11-19'),undated=await scene(chapter,'Undated with chapter fallback'),empty=await scene(undatedChapter,'Undated without fallback'); const feature=`/Writing/Context?projectId=${project}&bookId=${book}&chapterId=${chapter}&sceneId=${first}&pinned=true`,ctx=await p.context().newPage();await ctx.setViewportSize({width:1280,height:800});await ctx.goto('https://dev.plotdirector.com'+feature);await ctx.selectOption('[data-context-pane="0"] [data-context-tab]','calendar');const pane=ctx.locator('[data-context-pane="0"]'),day=d=>pane.locator(`[data-calendar-date="${d}"]`); - stage='follow, deduplication and collision';await day('1983-11-19').waitFor();assert.equal(await day('1983-11-19').getAttribute('aria-current'),'date');assert.equal(await day('1983-11-19').locator('.context-calendar-chapter').textContent(),'Ch 1');assert.equal(await day('1983-11-19').locator('small').count(),0);await pane.locator('[data-calendar-books]').selectOption('all');assert.equal(await day('1983-11-19').locator('small').textContent(),' +1');await pane.locator('[data-calendar-details]>details').first().locator('summary').first().click();await pane.getByText('Scene 1 · First dated scene',{exact:true}).click();assert.equal(await pane.getByRole('link',{name:'Open scene in main window'}).count(),1); - await ctx.waitForFunction(()=>document.querySelector('[data-context-workspace]').contextController.connection?.state==='Connected');const posts=[];ctx.on('request',r=>{if(r.method()==='POST'&&/NarrativeFocus|NativeCompanion.*Navigate/.test(r.url())&&!r.url().endsWith('/NarrativeFocus/Shared/Validate'))posts.push(new URL(r.url()).pathname);});const focus=await ctx.evaluate(()=>({...document.querySelector('[data-context-workspace]').contextController.position}));const shared=()=>ctx.evaluate(async({project,book})=>(await(await fetch(`/NarrativeFocus/Shared?projectID=${project}&bookID=${book}`)).json()),{project,book});const before=await shared(); - stage='browse empty dates and six-row viewport';await day('1983-11-20').click();await pane.locator('[data-calendar-month]').fill('2020-08');await pane.locator('[data-calendar-month]').dispatchEvent('change');assert.equal(await pane.locator('[data-calendar-grid] button').count(),42);const geometry=await pane.locator('[data-calendar-grid]').evaluate(n=>({bottom:n.getBoundingClientRect().bottom,scroll:n.scrollHeight,height:n.clientHeight,viewport:innerHeight}));assert(geometry.bottom<=geometry.viewport);assert(geometry.scroll<=geometry.height+1);await day('2020-08-15').click();assert.match(await pane.locator('[data-calendar-details]').textContent(),/No dated/);await pane.locator('[data-calendar-from]').fill('2020-08-01');await pane.locator('[data-calendar-from]').dispatchEvent('change');assert.equal(await pane.locator('[data-calendar-elapsed]').textContent(),'14 days to selected date'); - stage='real saved date refresh while held';await session.goto('/Scenes/SceneDetailsEditor?sceneId='+first);const exact=await p.locator('[name=TimeModeID] option').evaluateAll(ns=>ns.find(n=>/exact/i.test(n.textContent))?.value);await p.locator('[name=TimeModeID]').selectOption(exact);await p.locator('[name=StartDateTime]').fill('1984-02-29T10:00');await Promise.all([p.waitForResponse(r=>r.url().includes('/Scenes/SaveSceneDetails')&&r.status()===200),p.getByRole('button',{name:'Save details',exact:true}).click()]);await ctx.waitForFunction(()=>document.querySelector('[data-calendar-status]').textContent.includes('29 February 1984'));assert.equal(await pane.locator('[data-calendar-month]').inputValue(),'2020-08');assert.equal(await day('2020-08-15').getAttribute('aria-pressed'),'true');assert.deepEqual(await ctx.evaluate(()=>({...document.querySelector('[data-context-workspace]').contextController.position})),focus);assert.deepEqual(posts,[]);const after=await shared();assert.equal(after.version,before.version);assert.equal(after.sceneID,before.sceneID); + stage='follow, deduplication and collision';await day('1983-11-19').waitFor();assert.equal(await day('1983-11-19').getAttribute('aria-current'),'date');assert.equal(await day('1983-11-19').locator('.context-calendar-chapter').textContent(),'Ch 1');assert.equal(await day('1983-11-19').locator('small').count(),0);await pane.locator('[data-calendar-books]').selectOption('all');assert.equal(await day('1983-11-19').locator('.context-calendar-chapter:visible').count(),2);assert.equal(await day('1983-11-19').locator('.context-calendar-more:visible').count(),0);await day('1983-11-19').locator('.context-calendar-chapter').first().click();await pane.getByText('Scene 1 · First dated scene',{exact:true}).click();assert.equal(await pane.getByRole('link',{name:'Open scene in main window'}).count(),1);assert.match(await pane.locator('.context-calendar-scene-summary').first().textContent(),/Saved calendar summary for First dated scene/); + await ctx.waitForFunction(()=>document.querySelector('[data-context-workspace]').contextController.connection?.state==='Connected');const posts=[];ctx.on('request',r=>{if(r.method()==='POST'&&/NarrativeFocus|NativeCompanion.*Navigate/.test(r.url())&&!r.url().endsWith('/NarrativeFocus/Shared/Validate'))posts.push(new URL(r.url()).pathname);});const focus=await ctx.evaluate(()=>({...document.querySelector('[data-context-workspace]').contextController.position}));const shared=()=>ctx.evaluate(async({project,book})=>(await(await fetch(`/NarrativeFocus/Shared?projectID=${project}&bookID=${book}`)).json()),{project,book});const before=await shared();await day('1983-11-19').locator('.context-calendar-chapter').last().click();assert.equal(await pane.locator('[data-calendar-details]>details').last().evaluate(n=>n.open),true);assert.deepEqual(posts,[]);assert.equal((await shared()).version,before.version); + const scroll=await pane.locator('[data-calendar-details]').evaluate(n=>{n.querySelectorAll('details').forEach(d=>d.open=true);n.scrollTop=100;return {top:n.scrollTop,height:n.clientHeight,scroll:n.scrollHeight};});assert(scroll.scroll>scroll.height&&scroll.top>0); + stage='browse empty dates and six-row viewport';await day('1983-11-20').locator('.context-calendar-day-number').click();await pane.locator('[data-calendar-month]').fill('2020-08');await pane.locator('[data-calendar-month]').dispatchEvent('change');assert.equal(await pane.locator('[data-calendar-grid] [data-calendar-date]').count(),42);const geometry=await pane.locator('[data-calendar-grid]').evaluate(n=>({bottom:n.getBoundingClientRect().bottom,scroll:n.scrollHeight,height:n.clientHeight,viewport:innerHeight}));assert(geometry.bottom<=geometry.viewport);assert(geometry.scroll<=geometry.height+1);await day('2020-08-15').locator('.context-calendar-day-number').click();assert.match(await pane.locator('[data-calendar-details]').textContent(),/No dated/);await pane.locator('[data-calendar-from]').fill('2020-08-01');await pane.locator('[data-calendar-from]').dispatchEvent('change');assert.equal(await pane.locator('[data-calendar-elapsed]').textContent(),'14 days · 2 weeks, 0 days'); + stage='real saved date refresh while held';await session.goto('/Scenes/SceneDetailsEditor?sceneId='+first);const exact=await p.locator('[name=TimeModeID] option').evaluateAll(ns=>ns.find(n=>/exact/i.test(n.textContent))?.value);await p.locator('[name=TimeModeID]').selectOption(exact);await p.locator('[name=StartDateTime]').fill('1984-02-29T10:00');await Promise.all([p.waitForResponse(r=>r.url().includes('/Scenes/SaveSceneDetails')&&r.status()===200),p.getByRole('button',{name:'Save details',exact:true}).click()]);await ctx.waitForFunction(()=>document.querySelector('[data-calendar-status]').textContent.includes('29 February 1984'));assert.equal(await pane.locator('[data-calendar-month]').inputValue(),'2020-08');assert.equal(await pane.locator('[data-calendar-from]').inputValue(),'2020-08-01');assert.equal(await day('2020-08-15').getAttribute('data-selected'),'true');assert.deepEqual(await ctx.evaluate(()=>({...document.querySelector('[data-context-workspace]').contextController.position})),focus);assert.deepEqual(posts,[]);const after=await shared();assert.equal(after.version,before.version);assert.equal(after.sceneID,before.sceneID); stage='sibling-book date save refresh';await session.goto('/Scenes/SceneDetailsEditor?sceneId='+other);const otherExact=await p.locator('[name=TimeModeID] option').evaluateAll(ns=>ns.find(n=>/exact/i.test(n.textContent))?.value);await p.locator('[name=TimeModeID]').selectOption(otherExact);await p.locator('[name=StartDateTime]').fill('1984-03-01T10:00');await Promise.all([ctx.waitForResponse(r=>r.url().includes('/Calendar/State')&&r.status()===200),p.getByRole('button',{name:'Save details',exact:true}).click()]);await pane.locator('[data-calendar-month]').fill('1984-03');await pane.locator('[data-calendar-month]').dispatchEvent('change');assert.match(await day('1984-03-01').textContent(),/Book 2/);assert.equal((await shared()).version,before.version);assert.deepEqual(posts,[]); stage='Return to Scene and leap day';await pane.locator('[data-calendar-return]').click();assert.equal(await pane.locator('[data-calendar-month]').inputValue(),'1984-02');assert.equal(await day('1984-02-29').getAttribute('aria-current'),'date'); - stage='main scene link retains focus';await session.goto('/Locations?projectId='+project);await p.waitForFunction(()=>window.PlotDirectorPresenceConnection?.state==='Connected');await pane.locator('[data-calendar-details]>details summary').first().click();await pane.getByText('Scene 1 · First dated scene',{exact:true}).click();const contextUrl=ctx.url();await pane.getByRole('link',{name:'Open scene in main window'}).click();await p.waitForURL('**/Scenes/Edit/'+first+'?retainNarrativeFocus=true');assert.equal(ctx.url(),contextUrl);assert.equal((await shared()).version,before.version);assert.deepEqual(posts,[]); + stage='main scene link retains focus';await session.goto('/Locations?projectId='+project);await p.waitForFunction(()=>window.PlotDirectorPresenceConnection?.state==='Connected');if(!await pane.locator('[data-calendar-details]>details').first().evaluate(n=>n.open))await pane.locator('[data-calendar-details]>details summary').first().click();if(!await pane.getByText('Scene 1 · First dated scene',{exact:true}).evaluate(n=>n.parentElement.open))await pane.getByText('Scene 1 · First dated scene',{exact:true}).click();const contextUrl=ctx.url();await pane.getByRole('link',{name:'Open scene in main window'}).click();await p.waitForURL('**/Scenes/Edit/'+first+'?retainNarrativeFocus=true');assert.equal(ctx.url(),contextUrl);assert.equal((await shared()).version,before.version);assert.deepEqual(posts,[]); stage='chapter fallback and completely undated retention';await ctx.selectOption('[data-context-scene]',String(undated));await ctx.waitForFunction(()=>document.querySelector('[data-calendar-status]').textContent.includes('chapter (first dated scene)'));assert.equal(await pane.locator('[data-calendar-month]').inputValue(),'1984-02');await ctx.selectOption('[data-context-scene]',String(empty));await ctx.waitForFunction(()=>document.querySelector('[data-calendar-status]').textContent.includes('undated; month retained'));assert.equal(await pane.locator('[data-calendar-month]').inputValue(),'1984-02'); stage='split panes and themes';await ctx.selectOption('[data-context-layout]','columns');await ctx.selectOption('[data-context-pane="1"] [data-context-tab]','calendar');await ctx.locator('[data-context-pane="1"] [data-calendar-grid] button').first().waitFor();await pane.locator('[data-calendar-month]').fill('1983-11');await pane.locator('[data-calendar-month]').dispatchEvent('change');assert.equal(await ctx.locator('[data-context-pane="1"] [data-calendar-month]').inputValue(),new Date().toISOString().slice(0,7));for(const layout of ['columns','rows']){await ctx.selectOption('[data-context-layout]',layout);for(const theme of ['plotdirector','modern-light','modern-dark','warm-light','warm-dark','rose-pink','baby-blue'])await ctx.evaluate(t=>{localStorage.setItem('plotdirector.applicationTheme',t);window.dispatchEvent(new StorageEvent('storage',{key:'plotdirector.applicationTheme',newValue:t}));},theme);}await ctx.setViewportSize({width:460,height:850});assert.equal(await ctx.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1),true); stage='fresh login persistence';await session.close();session=await open();p=session.page;await session.goto('/Scenes/SceneDetailsEditor?sceneId='+first);assert.match(await p.locator('[name=StartDateTime]').inputValue(),/^1984-02-29T10:00/);await session.goto(feature);await p.selectOption('[data-context-pane="0"] [data-context-tab]','calendar');await p.locator('[data-calendar-date="1984-02-29"]').waitFor();assert.equal(await p.locator('[data-calendar-month]').inputValue(),'1984-02'); diff --git a/PlotLine.Tests/Browser/context-calendar.cjs b/PlotLine.Tests/Browser/context-calendar.cjs index ead09f2a..cf738c9c 100644 --- a/PlotLine.Tests/Browser/context-calendar.cjs +++ b/PlotLine.Tests/Browser/context-calendar.cjs @@ -1,6 +1,9 @@ const{chromium}=require('playwright'),fs=require('fs'),assert=require('node:assert/strict'); -(async()=>{const browser=await chromium.launch();try{const page=await browser.newPage({viewport:{width:1200,height:800}});let date='1983-11-19',reads=0;await page.route('**/Writing/Context/Calendar/State*',r=>{reads++;return r.fulfill({json:{books:[],scenes:[{bookID:1,bookLabel:'Book 1',chapterID:1,chapterNumber:1,chapterTitle:'One',sceneID:1,sceneNumber:1,title:'First',date},{bookID:1,bookLabel:'Book 1',chapterID:1,chapterNumber:1,chapterTitle:'One',sceneID:2,sceneNumber:2,title:'Second',date},{bookID:2,bookLabel:'Book 2',chapterID:2,chapterNumber:1,chapterTitle:'Two',sceneID:3,sceneNumber:1,title:'Other book',date}]}});});await page.route('https://calendar.test/',r=>r.fulfill({body:'',contentType:'text/html'}));await page.goto('https://calendar.test'); -const partial=fs.readFileSync('PlotLine/Views/Writing/_ContextCalendar.cshtml','utf8').split('\n').slice(2).join('\n');await page.setContent('
'+partial+'
');await page.addStyleTag({content:fs.readFileSync('PlotLine/wwwroot/css/context-calendar.css','utf8')});for(const file of ['context-calendar-model.js','context-calendar.js'])await page.addScriptTag({path:'PlotLine/wwwroot/js/'+file});await page.evaluate(()=>{window.node=document.querySelector('[data-context-calendar]');window.life=PlotDirectorContextLifecycles.calendar;life.mount(node,{position:{bookId:1,chapterId:1,sceneId:1}});});await page.locator('[data-calendar-date="1983-11-19"]').waitFor();assert.equal(await page.locator('[data-calendar-date="1983-11-19"] .context-calendar-chapter').textContent(),'Ch 1');assert.equal(await page.locator('[data-calendar-date="1983-11-19"] small').count(),0); -await page.selectOption('[data-calendar-books]','all');assert.equal(await page.locator('[data-calendar-date="1983-11-19"] small').textContent(),' +1');await page.locator('[data-calendar-date="1983-11-20"]').click();await page.evaluate(()=>life.onPosition(node,{bookId:1,chapterId:2,sceneId:99}));assert.equal(await page.locator('[data-calendar-month]').inputValue(),'1983-11');assert.equal(await page.locator('[data-calendar-date="1983-11-20"]').getAttribute('aria-pressed'),'true'); -await page.locator('[data-calendar-month]').fill('2020-08');await page.locator('[data-calendar-month]').dispatchEvent('change');assert.equal(await page.locator('[data-calendar-grid] button').count(),42);assert((await page.locator('[data-calendar-grid]').boundingBox()).height<=400);await page.evaluate(()=>life.onPosition(node,{bookId:1,chapterId:1,sceneId:1}));assert.equal(await page.locator('[data-calendar-month]').inputValue(),'2020-08');date='1984-01-01';await page.evaluate(()=>life.onInvalidation(node));await page.waitForFunction(()=>document.querySelector('[data-calendar-status]').textContent.includes('1984'));assert.equal(await page.locator('[data-calendar-month]').inputValue(),'2020-08');await page.locator('[data-calendar-return]').click();assert.equal(await page.locator('[data-calendar-month]').inputValue(),'1984-01');assert.equal(await page.locator('[data-calendar-date="1984-01-01"]').getAttribute('aria-current'),'date');assert(reads>=2); +(async()=>{const browser=await chromium.launch();try{const page=await browser.newPage({viewport:{width:1200,height:800}});let date='1983-11-19',reads=0;await page.route('**/Writing/Context/Calendar/State*',r=>{reads++;return r.fulfill({json:{books:[],scenes:[{bookID:1,bookLabel:'Book 1',chapterID:1,chapterNumber:1,chapterTitle:'One',sceneID:1,sceneNumber:1,title:'First',summary:'Saved summary ',date},{bookID:1,bookLabel:'Book 1',chapterID:1,chapterNumber:1,chapterTitle:'One',sceneID:2,sceneNumber:2,title:'Second',date},{bookID:2,bookLabel:'Book 2',chapterID:2,chapterNumber:1,chapterTitle:'Two',sceneID:3,sceneNumber:1,title:'Other book',date},...Array.from({length:12},(_,i)=>({bookID:1,bookLabel:'Book 1',chapterID:10+i,chapterNumber:10+i,chapterTitle:'Busy date',sceneID:10+i,sceneNumber:1,title:'Busy scene',date:'1983-11-21'}))]}});});await page.route('https://calendar.test/',r=>r.fulfill({body:'',contentType:'text/html'}));await page.goto('https://calendar.test'); +const partial=fs.readFileSync('PlotLine/Views/Writing/_ContextCalendar.cshtml','utf8').split('\n').slice(2).join('\n');await page.setContent('
'+partial+'
');await page.addStyleTag({content:fs.readFileSync('PlotLine/wwwroot/css/context-calendar.css','utf8')});for(const file of ['context-calendar-model.js','context-calendar.js'])await page.addScriptTag({path:'PlotLine/wwwroot/js/'+file});await page.evaluate(()=>{window.node=document.querySelector('[data-context-calendar]');window.life=PlotDirectorContextLifecycles.calendar;life.mount(node,{position:{bookId:1,chapterId:1,sceneId:1}});});await page.locator('[data-calendar-date="1983-11-19"]').waitFor();assert.equal(await page.locator('[data-calendar-date="1983-11-19"] .context-calendar-chapter').textContent(),'Ch 1');assert.equal(await page.locator('[data-calendar-date="1983-11-19"] small').count(),0); +await page.selectOption('[data-calendar-books]','all');assert.equal(await page.locator('[data-calendar-date="1983-11-19"] .context-calendar-chapter:visible').count(),2);assert.equal(await page.locator('[data-calendar-date="1983-11-19"] .context-calendar-more:visible').count(),0); +await page.locator('[data-calendar-date="1983-11-19"] .context-calendar-chapter').first().click();assert.equal(await page.locator('[data-calendar-details]>details').first().getAttribute('open'),'');await page.locator('[data-calendar-details] details details summary').first().click();assert.equal(await page.locator('.context-calendar-scene-summary').first().textContent(),'Saved summary ');assert.equal(await page.locator('.context-calendar-scene-summary script').count(),0); +await page.locator('[data-calendar-from]').fill('1983-11-01');await page.locator('[data-calendar-from]').dispatchEvent('change');assert.equal(await page.locator('[data-calendar-elapsed]').textContent(),'18 days · 2 weeks, 4 days');const busy=page.locator('[data-calendar-date="1983-11-21"]');await page.waitForFunction(()=>!document.querySelector('[data-calendar-date="1983-11-21"] .context-calendar-more').hidden);const visible=await busy.locator('.context-calendar-chapter:visible').count();assert(visible>0&&visible<12);assert.equal(await busy.locator('.context-calendar-more').textContent(),'+'+(12-visible));await busy.locator('.context-calendar-more').click();assert.match(await page.locator('[data-calendar-details]').textContent(),/12 chapters · 12 scenes/); +await page.locator('[data-calendar-date="1983-11-20"] .context-calendar-day-number').click();await page.evaluate(()=>life.onPosition(node,{bookId:1,chapterId:2,sceneId:99}));assert.equal(await page.locator('[data-calendar-month]').inputValue(),'1983-11');assert.equal(await page.locator('[data-calendar-date="1983-11-20"]').getAttribute('data-selected'),'true'); +await page.locator('[data-calendar-month]').fill('2020-08');await page.locator('[data-calendar-month]').dispatchEvent('change');assert.equal(await page.locator('[data-calendar-grid] [data-calendar-date]').count(),42);assert((await page.locator('[data-calendar-grid]').boundingBox()).height>300);await page.evaluate(()=>life.onPosition(node,{bookId:1,chapterId:1,sceneId:1}));assert.equal(await page.locator('[data-calendar-month]').inputValue(),'2020-08');assert.equal(await page.locator('[data-calendar-from]').inputValue(),'1983-11-01');date='1984-01-01';await page.evaluate(()=>life.onInvalidation(node));await page.waitForFunction(()=>document.querySelector('[data-calendar-status]').textContent.includes('1984'));assert.equal(await page.locator('[data-calendar-month]').inputValue(),'2020-08');await page.locator('[data-calendar-return]').click();assert.equal(await page.locator('[data-calendar-month]').inputValue(),'1984-01');assert.equal(await page.locator('[data-calendar-date="1984-01-01"]').getAttribute('aria-current'),'date');assert(reads>=2); await page.evaluate(()=>{life.dispose(node);life.mount(node,{position:{bookId:1,chapterId:1,sceneId:1}});});await page.locator('[data-calendar-date="1984-01-01"]').waitFor();console.log('PASS Calendar lifecycle: deduplication, all-books collision, local hold, undated position, six-row geometry, saved refresh preserves browsing, Return to Scene and remount');}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine/Controllers/ContextCalendarController.cs b/PlotLine/Controllers/ContextCalendarController.cs index 7adf3b6a..d5b08792 100644 --- a/PlotLine/Controllers/ContextCalendarController.cs +++ b/PlotLine/Controllers/ContextCalendarController.cs @@ -44,7 +44,7 @@ public sealed class ContextCalendarController(IWordCompanionRepository access, I var chapter = chapters[s.ChapterID]; var book = projectBooks[chapter.BookID]; return new { book.BookID, bookLabel = $"Book {book.BookNumber}", bookTitle = book.BookDisplayTitle, - chapter.ChapterID, chapter.ChapterNumber, chapter.ChapterTitle, s.SceneID, s.SceneNumber, + chapter.ChapterID, chapter.ChapterNumber, chapter.ChapterTitle, s.SceneID, s.SceneNumber, s.Summary, title = string.IsNullOrWhiteSpace(s.SceneTitle) ? $"Scene {s.SceneNumber:g}" : s.SceneTitle, date = s.StartDateTime?.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }; }) }); diff --git a/PlotLine/Views/Writing/_ContextCalendar.cshtml b/PlotLine/Views/Writing/_ContextCalendar.cshtml index 953bf8a4..e403cd37 100644 --- a/PlotLine/Views/Writing/_ContextCalendar.cshtml +++ b/PlotLine/Views/Writing/_ContextCalendar.cshtml @@ -17,7 +17,14 @@
● Manuscript date · outlined date is your selection - +
+
+

Elapsed time

+ +

To Select a date

+ Choose a start date +
+ +
-
diff --git a/PlotLine/wwwroot/css/context-calendar.css b/PlotLine/wwwroot/css/context-calendar.css index 54d9caa8..ddfcf1a0 100644 --- a/PlotLine/wwwroot/css/context-calendar.css +++ b/PlotLine/wwwroot/css/context-calendar.css @@ -1,20 +1,32 @@ -.context-calendar{min-width:0;color:var(--plotline-ink);} -.context-calendar-controls{display:flex;flex-wrap:wrap;align-items:end;gap:.35rem;} -.context-calendar-controls label,.context-calendar-elapsed label{display:flex;gap:.3rem;align-items:center;min-width:0;} +.context-pane-content:has(>.context-calendar){display:flex;flex-direction:column;} +.context-calendar{flex:1;display:flex;flex-direction:column;min-height:24rem;min-width:0;color:var(--plotline-ink);} +.context-calendar-controls{display:flex;flex-wrap:wrap;align-items:center;gap:.4rem;} +.context-calendar-controls label,.context-calendar-elapsed label{display:flex;gap:.35rem;align-items:center;min-width:0;} .context-calendar input,.context-calendar select,.context-calendar button{font:inherit;color:var(--plotline-ink);background:var(--plotline-panel);border:1px solid var(--plotline-line);border-radius:.3rem;min-width:0;} -.context-calendar-controls button{padding:.2rem .45rem;}.context-calendar [data-calendar-status]{font-size:.8rem;margin:.4rem 0;} -.context-calendar-layout{display:grid;grid-template-columns:minmax(0,1fr) minmax(14rem,.65fr);gap:.75rem;align-items:start;} -.context-calendar-month{min-width:0;}.context-calendar-month>strong{display:block;text-align:center;} -.context-calendar-grid,.context-calendar-weekdays{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:2px;} +.context-calendar-controls :is(input,select,button){height:2rem;padding:.2rem .45rem;box-sizing:border-box;} +.context-calendar [data-calendar-status]{font-size:.8rem;margin:.5rem 0;} +.context-calendar-layout{flex:1;min-height:0;display:grid;grid-template-columns:minmax(0,1fr) minmax(14rem,.65fr);gap:.75rem;} +.context-calendar-month,.context-calendar-elapsed,.context-calendar [data-calendar-details]{border:1px solid var(--plotline-line);border-radius:.45rem;padding:.6rem;background:var(--plotline-panel);min-width:0;} +.context-calendar-month{display:flex;flex-direction:column;min-height:0;gap:.3rem;} +.context-calendar-month>strong{display:block;text-align:center;} +.context-calendar-grid,.context-calendar-weekdays{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:3px;} .context-calendar-weekdays{text-align:center;font-size:.75rem;} -.context-calendar-grid{height:clamp(15rem,calc(100dvh - 23rem),25rem);grid-template-rows:repeat(var(--calendar-weeks,6),minmax(0,1fr));} -.context-calendar-day{display:flex;flex-direction:column;align-items:stretch;text-align:left;padding:.15rem .2rem;overflow:hidden;font-size:.8rem!important;line-height:1.2;cursor:pointer;} -.context-calendar-day-number{display:flex;justify-content:space-between;font-weight:600;}.context-calendar-day-number small{font-weight:400;} -.context-calendar-chapter{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:.7rem;} +.context-calendar-grid{flex:1;min-height:0;grid-template-rows:repeat(var(--calendar-weeks,6),minmax(0,1fr));} +.context-calendar-day{display:flex;flex-direction:column;min-height:0;min-width:0;border:1px solid var(--plotline-line);border-radius:.3rem;padding:.15rem;overflow:hidden;font-size:.8rem;line-height:1.2;} +.context-calendar button{cursor:pointer;} +.context-calendar-day-number{flex:none;text-align:left;font-weight:600!important;border:0!important;padding:.15rem;} +.context-calendar-chips{display:flex;flex-wrap:wrap;align-content:start;gap:2px;min-height:0;overflow:hidden;} +.context-calendar-chapter{flex:0 1 auto;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:.7rem!important;padding:.15rem .2rem;} +.context-calendar-more{flex:none;font-size:.7rem!important;padding:0 .2rem;text-align:left;} +.context-calendar [hidden]{display:none!important;} .context-calendar-day.is-overflow{color:var(--plotline-muted);background:var(--plotline-surface);} -.context-calendar-day.is-manuscript{border-bottom:3px solid var(--plotline-accent);font-weight:700;} -.context-calendar-day[aria-pressed=true]{outline:2px solid var(--plotline-accent);outline-offset:-2px;background:var(--pd-selected,var(--plotline-surface));} -.context-calendar button:focus-visible,.context-calendar input:focus-visible,.context-calendar select:focus-visible{outline:3px solid var(--plotline-accent);outline-offset:1px;} -.context-calendar [data-calendar-details]{max-height:26rem;overflow:auto;overflow-wrap:anywhere;}.context-calendar h3{font-size:1rem;}.context-calendar details{margin:.4rem 0;}.context-calendar details details{margin-left:.6rem;}.context-calendar details a{display:block;margin:.3rem .6rem;} -.context-calendar-elapsed{display:flex;flex-wrap:wrap;gap:.5rem;font-size:.8rem;margin-top:.6rem;} -@container(max-width:760px){.context-calendar-layout{grid-template-columns:minmax(0,1fr);}.context-calendar [data-calendar-details]{max-height:16rem;}} +.context-calendar-day.is-manuscript{border-bottom:3px solid var(--plotline-accent);} +.context-calendar-day[data-selected=true]{outline:2px solid var(--plotline-accent);outline-offset:-2px;background:var(--pd-selected,var(--plotline-surface));} +.context-calendar :is(button,input,select):focus-visible{outline:3px solid var(--plotline-accent);outline-offset:1px;} +.context-calendar-day-column{display:flex;flex-direction:column;gap:.75rem;min-height:0;min-width:0;} +.context-calendar [data-calendar-details]{flex:1;min-height:0;overflow:auto;overflow-wrap:anywhere;} +.context-calendar h3{font-size:1rem;margin:0 0 .5rem;} +.context-calendar details{margin:.5rem 0;}.context-calendar details details{margin-left:.6rem;}.context-calendar details a{display:block;margin:.3rem .6rem;} +.context-calendar summary{cursor:pointer;}.context-calendar-scene-summary{white-space:pre-wrap;} +.context-calendar-elapsed{flex:none;font-size:.85rem;}.context-calendar-elapsed p{margin:.5rem 0;}.context-calendar-elapsed output{display:block;font-weight:600;} +@container(max-width:760px){.context-calendar{min-height:38rem;}.context-calendar-layout{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(18rem,1fr) minmax(16rem,1fr);}} diff --git a/PlotLine/wwwroot/js/context-calendar.js b/PlotLine/wwwroot/js/context-calendar.js index 3ad258e8..ef635b53 100644 --- a/PlotLine/wwwroot/js/context-calendar.js +++ b/PlotLine/wwwroot/js/context-calendar.js @@ -10,14 +10,15 @@ let position=context.position,data,epoch=0,disposed=false; const status=q('[data-calendar-status]'),grid=q('[data-calendar-grid]'),details=q('[data-calendar-details]'); const label=day=>model.date(day)?.toLocaleDateString('en-GB',{timeZone:'UTC',weekday:'long',day:'numeric',month:'long',year:'numeric'}); - function elapsed(){const n=model.elapsed(state.from,state.selected);q('[data-calendar-elapsed]').textContent=n==null?'':`${n} days to selected date`;} + function elapsed(){const n=model.elapsed(state.from,state.selected);q('[data-calendar-destination]').textContent=state.selected?label(state.selected):'Select a date';q('[data-calendar-elapsed]').textContent=n==null?'Choose a start date':`${n} days · ${n<0?'−':''}${Math.floor(Math.abs(n)/7)} weeks, ${Math.abs(n)%7} days`;} function drawDetails(){ details.replaceChildren(element('h3',state.selected?label(state.selected):'Select a date')); const scenes=data.scenes.filter(s=>state.books==='all'||s.bookID===position.bookId),groups=model.chapters(scenes,state.selected); + details.append(element('p',`${groups.length} chapters · ${groups.reduce((n,g)=>n+g.scenes.length,0)} scenes`)); if(!groups.length)details.append(element('p','No dated chapters or scenes on this date.')); - for(const group of groups){const key=state.selected+'/'+group.bookID+'/'+group.chapterID,section=element('details');section.open=state.expanded.has(key);section.addEventListener('toggle',()=>{if(section.open)state.expanded.add(key);else state.expanded.delete(key);}); + for(const group of groups){const key=state.selected+'/'+group.bookID+'/'+group.chapterID,section=element('details');section.open=state.expanded.has(key);section.addEventListener('toggle',()=>{if(!section.isConnected)return;if(section.open)state.expanded.add(key);else state.expanded.delete(key);}); section.append(element('summary',`${state.books==='all'?group.bookLabel+' · ':''}Ch ${group.chapterNumber} · ${group.chapterTitle} (${group.scenes.length} scenes)`)); - for(const scene of group.scenes){const sceneKey=key+'/'+scene.sceneID,row=element('details');row.open=state.expanded.has(sceneKey);row.addEventListener('toggle',()=>{if(row.open)state.expanded.add(sceneKey);else state.expanded.delete(sceneKey);});row.append(element('summary',`Scene ${scene.sceneNumber} · ${scene.title}`));const link=element('a','Open scene in main window');link.href=`/Scenes/Edit/${scene.sceneID}?retainNarrativeFocus=true`;link.dataset.contextNarrative='author';link.target='_blank';link.rel='noopener';row.append(link);section.append(row);} + for(const scene of group.scenes){const sceneKey=key+'/'+scene.sceneID,row=element('details');row.open=state.expanded.has(sceneKey);row.addEventListener('toggle',()=>{if(!row.isConnected)return;if(row.open)state.expanded.add(sceneKey);else state.expanded.delete(sceneKey);});row.append(element('summary',`Scene ${scene.sceneNumber} · ${scene.title}`));const link=element('a','Open scene in main window');link.href=`/Scenes/Edit/${scene.sceneID}?retainNarrativeFocus=true`;link.dataset.contextNarrative='author';link.target='_blank';link.rel='noopener';const summary=element('p',scene.summary?.trim()||'No saved scene summary.');summary.className='context-calendar-scene-summary';row.append(summary,link);section.append(row);} details.append(section); } elapsed(); @@ -32,22 +33,35 @@ q('[data-calendar-previous]').disabled=!model.shift(state.month,-1);q('[data-calendar-next]').disabled=!model.shift(state.month,1); grid.replaceChildren();const days=model.grid(state.month);grid.style.setProperty('--calendar-weeks',days.length/7); const scenes=data.scenes.filter(s=>state.books==='all'||s.bookID===position.bookId); - for(const day of days){if(!day){grid.append(element('span'));continue;}const groups=model.chapters(scenes,day),button=element('button');button.type='button';button.dataset.calendarDate=day;button.className='context-calendar-day'; - button.classList.toggle('is-overflow',day.slice(0,7)!==state.month);button.classList.toggle('is-manuscript',day===current.date);button.setAttribute('aria-pressed',String(day===state.selected));if(day===current.date)button.setAttribute('aria-current','date'); - button.setAttribute('aria-label',`${label(day)}${day===current.date?', manuscript date':''}, ${groups.length} chapters${groups.length?', '+groups.map(g=>g.bookLabel+' chapter '+g.chapterNumber).join(', '):''}`); - const head=element('span',`${Number(day.slice(-2))}${day===current.date?' ●':''}`);head.className='context-calendar-day-number';if(groups.length>1)head.append(element('small',` +${groups.length-1}`));button.append(head); - if(groups.length){const text=`${state.books==='all'?groups[0].bookLabel+' · ':''}Ch ${groups[0].chapterNumber}`,chip=element('span',text);chip.title=text;chip.className='context-calendar-chapter';button.append(chip);} - button.onclick=()=>{state.hold=true;state.selected=day;state.month=day.slice(0,7);draw();node.querySelector(`[data-calendar-date="${day}"]`)?.focus({preventScroll:true});};grid.append(button); + function select(day,group){state.hold=true;state.selected=day;state.month=day.slice(0,7);if(group)state.expanded.add(day+'/'+group.bookID+'/'+group.chapterID);draw();const cell=node.querySelector(`[data-calendar-date="${day}"]`);(group?cell?.querySelector(`[data-chapter-id="${group.chapterID}"]`):cell?.querySelector('button'))?.focus({preventScroll:true});} + for(const day of days){if(!day){grid.append(element('span'));continue;}const groups=model.chapters(scenes,day),cell=element('div');cell.dataset.calendarDate=day;cell.className='context-calendar-day'; + cell.classList.toggle('is-overflow',day.slice(0,7)!==state.month);cell.classList.toggle('is-manuscript',day===current.date);cell.dataset.selected=String(day===state.selected);if(day===current.date)cell.setAttribute('aria-current','date'); + const head=element('button',`${Number(day.slice(-2))}${day===current.date?' ●':''}`);head.type='button';head.className='context-calendar-day-number';head.setAttribute('aria-pressed',String(day===state.selected));head.setAttribute('aria-label',`${label(day)}, ${groups.length} chapters, ${groups.reduce((n,g)=>n+g.scenes.length,0)} scenes`);head.onclick=()=>select(day);cell.append(head); + const chips=element('div');chips.className='context-calendar-chips'; + for(const group of groups){const text=`${state.books==='all'?group.bookLabel+' · ':''}Ch ${group.chapterNumber}`,chip=element('button',text);chip.type='button';chip.title=`${text} · ${group.chapterTitle} (${group.scenes.length} scenes)`;chip.className='context-calendar-chapter';chip.dataset.chapterId=group.chapterID;chip.onclick=()=>select(day,group);chips.append(chip);} + cell.append(chips);const more=element('button');more.type='button';more.className='context-calendar-more';more.hidden=true;more.onclick=()=>select(day);cell.append(more);grid.append(cell); } + fitChips(); drawDetails(); } + function fitChips(){ + for(const cell of grid.querySelectorAll('.context-calendar-day')){ + const chips=cell.querySelector('.context-calendar-chips'),items=[...chips.children],more=cell.querySelector('.context-calendar-more'); + more.hidden=true;for(const chip of items)chip.hidden=false; + if(chips.scrollHeight<=chips.clientHeight+1)continue; + more.hidden=false;more.textContent=`+${items.length}`; + let hidden=0;for(let i=items.length-1;i>=0&&chips.scrollHeight>chips.clientHeight+1;i--){items[i].hidden=true;hidden++;} + more.hidden=!hidden;more.textContent=`+${hidden}`;more.setAttribute('aria-label',`${hidden} more chapters on ${label(cell.dataset.calendarDate)}`); + } + } + const resize=new ResizeObserver(()=>fitChips());resize.observe(grid); async function reload(refresh=false){const ticket=++epoch;try{const result=await load(position.bookId,refresh);if(disposed||ticket!==epoch)return;data=result;draw();}catch(e){if(!disposed&&ticket===epoch)status.textContent=e.message;}} q('[data-calendar-books]').onchange=e=>{state.books=e.target.value;draw();}; q('[data-calendar-month]').onchange=e=>{if(model.date(e.target.value+'-01')){state.hold=true;state.month=e.target.value;draw();}}; for(const [selector,step]of [['[data-calendar-previous]',-1],['[data-calendar-next]',1]])q(selector).onclick=()=>{const month=model.shift(state.month,step);if(month){state.hold=true;state.month=month;draw();}}; q('[data-calendar-hold]').onclick=()=>{state.hold=true;draw();};q('[data-calendar-return]').onclick=()=>{state.hold=false;draw();}; q('[data-calendar-from]').value=state.from;q('[data-calendar-from]').onchange=e=>{state.from=e.target.value;elapsed();}; - instances.set(node,{position(next){position=next;draw();},refresh(){void reload(true);},dispose(){disposed=true;epoch++;}});void reload(); + instances.set(node,{position(next){position=next;draw();},refresh(){void reload(true);},dispose(){disposed=true;epoch++;resize.disconnect();}});void reload(); } window.PlotDirectorContextLifecycles={...(window.PlotDirectorContextLifecycles||{}),calendar:{mount,dispose(node){instances.get(node)?.dispose();instances.delete(node);},onPosition(node,next){const instance=instances.get(node);if(!instance)return false;instance.position(next);return true;},onCacheInvalidation(){cache.clear();},onInvalidation(node){const instance=instances.get(node);if(!instance)return false;instance.refresh();return true;}}}; })();