diff --git a/PlotLine.Tests/Browser/sticky-shell.cjs b/PlotLine.Tests/Browser/sticky-shell.cjs new file mode 100644 index 00000000..636df61c --- /dev/null +++ b/PlotLine.Tests/Browser/sticky-shell.cjs @@ -0,0 +1,70 @@ +// Start the toolbar browser fixture, then: xvfb-run -a node sticky-shell.cjs +const { chromium } = require('playwright'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +async function checkScroll(page, installed) { + await page.evaluate(() => { + const main = document.querySelector('main'); + const spacer = document.createElement('div'); spacer.style.height = '1800px'; + const target = document.createElement('button'); target.id = 'scroll-test-target'; target.textContent = 'Focus target'; + main.append(spacer, target, spacer.cloneNode()); + }); + await page.evaluate(() => window.scrollTo(0, 650)); + await page.waitForFunction(() => scrollY > 600); + const header = page.locator('.pd-application-header'); + if (!installed) { assert((await header.boundingBox()).y < -400); return; } + assert(Math.abs((await header.boundingBox()).y) < 1); + const expanded = (await header.boundingBox()).height; + await page.locator('[data-ribbon-collapse]').click(); + await page.waitForFunction(() => !document.querySelector('[data-ribbon-collapse]').disabled); + const compact = (await header.boundingBox()).height; + assert(compact < expanded - 50); + assert(Math.abs((await header.boundingBox()).y) < 1); + await page.locator('[data-ribbon-tab=story]').click(); + assert((await header.boundingBox()).height > compact + 50); + await page.evaluate(() => document.getElementById('scroll-test-target').scrollIntoView()); + await page.waitForFunction(() => document.querySelector('#scroll-test-target').getBoundingClientRect().top >= document.querySelector('.pd-application-header').getBoundingClientRect().bottom); + for (const id of ['appProjectMenu', 'appBookMenu', 'accountMenuButton']) { + await page.locator('#' + id).click(); + const menu = page.locator(`[aria-labelledby="${id}"]`); + assert(await menu.isVisible()); + assert(await menu.evaluate(el => { const r = el.getBoundingClientRect(); return el.contains(document.elementFromPoint(r.x + 15, r.y + 15)); })); + await page.keyboard.press('Escape'); + } + await page.locator('.app-toolbar-customise').click(); + await page.waitForFunction(() => document.activeElement.closest('#customiseToolbar')); + assert.equal(await page.locator('#customiseToolbar').evaluate(el => el.parentElement.tagName), 'BODY'); + assert(await page.locator('#customiseToolbar .modal-content').evaluate(el => { const r=el.getBoundingClientRect(); return el.contains(document.elementFromPoint(r.x+25,r.y+25)); })); + await page.locator('#customiseToolbar .modal-footer').getByRole('button',{name:'Cancel',exact:true}).click(); + await page.locator('#customiseToolbar').waitFor({state:'hidden'}); + assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true); +} +module.exports = { checkScroll }; +if (require.main === module) (async () => { + const profile = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-sticky-')); + const context = await chromium.launchPersistentContext(profile, { headless: false, viewport: {width:1440,height:900} }); + const base = 'http://127.0.0.1:5238', manifestId = base + '/Projects'; + const cdp = await context.browser().newBrowserCDPSession(); + try { + const tab = context.pages()[0]; await tab.goto(base + '/fixture?dashboard=true'); + await checkScroll(tab, false); + await cdp.send('PWA.install',{manifestId,installUrlOrBundleUrl:base+'/fixture'}); + await cdp.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'}); + const opened = context.waitForEvent('page'); + await cdp.send('PWA.launch',{manifestId,url:base+'/fixture?dashboard=true'}); + const app = await opened; await app.waitForLoadState(); + assert(await app.evaluate(()=>matchMedia('(display-mode: standalone)').matches)); + for (const theme of ['modern-light','modern-dark','warm-light','warm-dark']) { + await app.goto(base + '/fixture?dashboard=true'); + await app.evaluate(theme => document.documentElement.dataset.appTheme=theme,theme); + if (await app.locator('#ribbon-surface').isHidden()) { + await app.locator('[data-ribbon-collapse]').click(); + await app.waitForFunction(()=>!document.querySelector('[data-ribbon-collapse]').disabled); + } + await checkScroll(app,true); + } + console.log('PASS sticky shell: real installed mode vs browser tab; all themes, expanded/collapsed height, scrolled categories, anchor offset, dropdown hit testing and modal/backdrop stacking.'); + } finally { await cdp.send('PWA.uninstall',{manifestId}).catch(()=>{}); await context.close(); fs.rmSync(profile,{recursive:true,force:true}); } +})().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine.Tests/ToolbarBrowserHost.cs b/PlotLine.Tests/ToolbarBrowserHost.cs index 4914b8d6..b35d6066 100644 --- a/PlotLine.Tests/ToolbarBrowserHost.cs +++ b/PlotLine.Tests/ToolbarBrowserHost.cs @@ -41,6 +41,7 @@ internal static class ToolbarBrowserHost app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); + app.MapGet("/Projects", () => Results.Redirect("/fixture")); app.MapGet("/fixture", async context => { var model = new ApplicationNavigationViewModel { ActiveSection = "Calendar", ShowCompanionPresence = true }; @@ -92,7 +93,7 @@ internal static class ToolbarBrowserHost var initialTheme = appearance.ThemeKey ?? "warm-light"; var appearanceScript = ""; context.Response.ContentType = "text/html; charset=utf-8"; - await context.Response.WriteAsync("
" + menu + toolbar + "
" + surface + "
" + appearanceScript + ""); + await context.Response.WriteAsync("
" + menu + toolbar + "
" + surface + "
" + appearanceScript + ""); }); await app.RunAsync(); } diff --git a/PlotLine/Views/Shared/_Layout.cshtml b/PlotLine/Views/Shared/_Layout.cshtml index b0163aa5..7b234672 100644 --- a/PlotLine/Views/Shared/_Layout.cshtml +++ b/PlotLine/Views/Shared/_Layout.cshtml @@ -153,7 +153,7 @@ } -
+
@if (User.Identity?.IsAuthenticated == true) { @if (isApplication) @@ -186,6 +186,7 @@ } +
@if (User.Identity?.IsAuthenticated == true) { var primaryBook = storyIntelligenceProgress.Books.FirstOrDefault(book => book.HasActiveRuns); @@ -260,7 +261,6 @@ } -
diff --git a/PlotLine/wwwroot/css/application-shell.css b/PlotLine/wwwroot/css/application-shell.css index 2281a645..7289ae3c 100644 --- a/PlotLine/wwwroot/css/application-shell.css +++ b/PlotLine/wwwroot/css/application-shell.css @@ -110,16 +110,17 @@ html[data-app-theme] .app-layout { .pd-theme-swatch { width: 13px; height: 13px; border-radius: 50%; border: 1px solid #8a8a8a; flex-shrink: 0; } [data-swatch="modern-light"] { background: #f4f5f7; } [data-swatch="modern-dark"] { background: #25282d; } [data-swatch="warm-light"] { background: #f4ebdd; } [data-swatch="warm-dark"] { background: #30271f; } -.pd-shell .modal-content { background: var(--pd-elevated) !important; color: var(--pd-text); border: 1px solid var(--pd-border); border-radius: 7px; } -.pd-shell .modal-title { font: 600 17px var(--pd-font-ui); } -.pd-shell .modal-dialog { max-width: 510px; } -.pd-shell .text-muted { color: var(--pd-muted) !important; } -.pd-shell .toolbar-choice { border-color: var(--pd-border-subtle); } -.pd-shell .btn, .pd-dashboard .btn { border-radius: 4px; font-family: var(--pd-font-ui); font-weight: 500; box-shadow: none; } -.pd-shell .btn-primary, .pd-dashboard .btn-primary { background: var(--pd-accent) !important; border-color: var(--pd-accent) !important; color: var(--pd-on-accent) !important; } -.pd-shell .btn-primary:hover, .pd-dashboard .btn-primary:hover { background: var(--pd-accent-hover) !important; } -.pd-shell .btn-outline-secondary, .pd-dashboard .btn-outline-secondary, .pd-dashboard .pw-actions__toggle { background: transparent !important; border-color: var(--pd-border) !important; color: var(--pd-text) !important; } -.pd-shell .btn-outline-secondary:hover, .pd-dashboard .btn-outline-secondary:hover { background: var(--pd-hover) !important; } +.pd-shell-dialog { font-family: var(--pd-font-ui); } +:is(.pd-shell, .pd-shell-dialog) .modal-content { background: var(--pd-elevated) !important; color: var(--pd-text); border: 1px solid var(--pd-border); border-radius: 7px; } +:is(.pd-shell, .pd-shell-dialog) .modal-title { font: 600 17px var(--pd-font-ui); } +:is(.pd-shell, .pd-shell-dialog) .modal-dialog { max-width: 510px; } +:is(.pd-shell, .pd-shell-dialog) .text-muted { color: var(--pd-muted) !important; } +:is(.pd-shell, .pd-shell-dialog) .toolbar-choice { border-color: var(--pd-border-subtle); } +:is(.pd-shell, .pd-shell-dialog) .btn, .pd-dashboard .btn { border-radius: 4px; font-family: var(--pd-font-ui); font-weight: 500; box-shadow: none; } +:is(.pd-shell, .pd-shell-dialog) .btn-primary, .pd-dashboard .btn-primary { background: var(--pd-accent) !important; border-color: var(--pd-accent) !important; color: var(--pd-on-accent) !important; } +:is(.pd-shell, .pd-shell-dialog) .btn-primary:hover, .pd-dashboard .btn-primary:hover { background: var(--pd-accent-hover) !important; } +:is(.pd-shell, .pd-shell-dialog) .btn-outline-secondary, .pd-dashboard .btn-outline-secondary, .pd-dashboard .pw-actions__toggle { background: transparent !important; border-color: var(--pd-border) !important; color: var(--pd-text) !important; } +:is(.pd-shell, .pd-shell-dialog) .btn-outline-secondary:hover, .pd-dashboard .btn-outline-secondary:hover { background: var(--pd-hover) !important; } /* Series Dashboard is the Phase 1 reference workspace. */ .app-layout .plotline-shell.pd-dashboard-shell { max-width: none; padding-inline: clamp(20px, 2.6vw, 54px); } .pd-dashboard { padding-bottom: 28px; font-family: var(--pd-font-ui); } @@ -183,3 +184,11 @@ html[data-app-theme] .app-layout { @media (prefers-reduced-motion: reduce) { .app-layout *, .app-layout *::before, .app-layout *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } } + +/* Bootstrap's sticky layer (1020) stays below backdrop/modal (1050/1055). + One natural-height header: no fixed rows or reserved expanded-ribbon space. */ +@media (display-mode: standalone) { + html[data-app-theme] { scroll-padding-top: calc(var(--pd-sticky-height, 0px) + 12px); } + .app-layout > .pd-application-header { position: sticky; top: 0; z-index: 1020; margin-bottom: 18px; } + .app-layout > .pd-application-header > .pd-shell { margin-bottom: 0; } +} diff --git a/PlotLine/wwwroot/js/application-pwa.js b/PlotLine/wwwroot/js/application-pwa.js index ecba40f3..9f292aef 100644 --- a/PlotLine/wwwroot/js/application-pwa.js +++ b/PlotLine/wwwroot/js/application-pwa.js @@ -4,6 +4,24 @@ const installButton = document.querySelector('[data-pwa-install]'); const status = document.querySelector('[data-pwa-status]'); const standalone = window.matchMedia('(display-mode: standalone)'); + const header = document.querySelector('.pd-application-header'); + function updateStickyOffset() { + if (header && standalone.matches) root.style.setProperty('--pd-sticky-height', `${header.getBoundingClientRect().height}px`); + else root.style.removeProperty('--pd-sticky-height'); + } + function prepareStickyChrome() { + if (header && standalone.matches) { + // Escape the sticky stacking context so dialogs stay above their backdrops. + header.querySelectorAll('.modal').forEach(dialog => { + if (dialog.closest('.pd-shell')) dialog.classList.add('pd-shell-dialog'); + document.body.appendChild(dialog); + }); + } + updateStickyOffset(); + } + if (header) new ResizeObserver(updateStickyOffset).observe(header); + standalone.addEventListener('change', prepareStickyChrome); + prepareStickyChrome(); let installPrompt = null; let installedThisSession = false; function updateMode() { diff --git a/docs/navigation/installable-application.md b/docs/navigation/installable-application.md index bf051408..19970a19 100644 --- a/docs/navigation/installable-application.md +++ b/docs/navigation/installable-application.md @@ -41,3 +41,13 @@ For stale visuals, navigate/reload after saving work and inspect the CSS/JS cont Reference: [Chromium installation debugging](https://developer.chrome.com/docs/devtools/progressive-web-apps) and [DevTools PWA automation](https://chromedevtools.github.io/devtools-protocol/tot/PWA/). Future candidates include opt-in notifications, badging and context-free shortcuts. File handlers, share targets and especially offline editing need separate security, lifecycle and product designs. + +## Standalone sticky chrome + +Only `@media (display-mode: standalone)` makes the single `.pd-application-header` sticky. The manifest does not request window-controls-overlay, so no extra display modes are inferred. Normal tabs retain document scrolling with a non-sticky header. The progress strip and workspace remain outside the sticky header. + +The existing expanded/collapsed ribbon determines natural header height; its persisted account preference is unchanged. A ResizeObserver in the existing PWA bootstrap measures that height for root scroll-padding, including resize and category changes, so anchor/scrollIntoView destinations clear the chrome. There are no fixed-height workspace panels or empty ribbon placeholders. + +The header uses Bootstrap's sticky layer (1020), below modal backdrops/modals (1050/1055). In standalone mode shell dialogs move to body before opening, retaining event handlers and editor styling through `.pd-shell-dialog`; dropdowns stay within the header above workspace content. No new theme or shadow is introduced. + +Focused sticky verification: start `dotnet run --project PlotLine.Tests -- --toolbar-browser-host`, then run `xvfb-run -a node PlotLine.Tests/Browser/sticky-shell.cjs` from the repository root (omit xvfb-run on a desktop). The test installs the loopback fixture in a temporary Chromium profile and removes it afterwards. It adds long synthetic workspace content to exercise document scroll without live manuscript data.