Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions apps/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,96 @@
background-repeat: repeat;
background-size: var(--surface-grain-size);
}
/* A narrow window, where T3's left panel is a modal sheet (sidebar.tsx, SIDEBAR_MOBILE_QUERY):
the conversation takes the whole width without the rail, the open left panel carries the
rail at its left edge, and the open right panel takes the whole width. The script below moves the rail into the panel while it is open, so
the rail is part of the dialog for the keyboard and screen readers and slides with it. */
@media (max-width: 767px) {
#root {
padding-left: 0;
}
body > lazurio-rail:defined:not([data-lazurio-dialog-open]) {
display: none;
}
/* The rail is no longer #root's sibling while it is in the panel; T3's fixed controls stay
contained all the same, below the panel. */
:root:has(lazurio-rail:defined) #root [data-slot="sidebar-wrapper"] {
contain: layout paint;
}
[data-mobile="true"][data-sidebar="sidebar"]:has(> lazurio-rail:defined) {
padding-left: var(--lazurio-rail-width, 0px);
}
/* The right panel (RightPanelSheet.tsx, the one other sheet) takes the whole screen: no
sliver of the conversation beside it. Its own toggle closes it, back to the conversation. */
:root:has(lazurio-rail:defined) [data-slot="sheet-popup"]:not([data-mobile]) {
width: 100vw;
min-width: 0;
max-width: none;
border-inline-start: 0;
padding-inline-start: env(safe-area-inset-left);
}
}
</style>
<script>
// The rail in a narrow window (see the style above): T3's open left panel is a modal dialog
// that keeps the focus inside and hides the rest of the page from screen readers, so the rail
// goes inside the panel, as its first child, while the panel is on the page (it fades out
// with it), and back before #root once the panel is gone, where a narrow window hides it.
// The panel marks the page outside when it opens, possibly before the move, so the rail
// drops those marks once inside. A dialog the rail opens (the Environment jump, ⌘⇧E) is
// drawn only where the rail is, so while one is open the rail is shown wherever it stands.
// The jump puts the focus into its search as it opens, so the rail is shown already when
// its shortcut comes, before the shell takes it, and settles once the key has passed: hidden
// again when the app took the key and no dialog opened. Outside Lazurio there is no rail
// and nothing runs.
document.addEventListener("DOMContentLoaded", () => {
const rail = document.querySelector("body > lazurio-rail");
if (!rail) return;
const body = document.body;
const place = () => {
const panel = body.querySelector('[data-mobile="true"][data-sidebar="sidebar"]');
if (panel) {
if (rail.parentElement !== panel) panel.prepend(rail);
rail.removeAttribute("aria-hidden");
rail.removeAttribute("data-base-ui-inert");
} else if (rail.parentElement !== body) {
body.insertBefore(rail, document.getElementById("root"));
}
rail.toggleAttribute(
"data-lazurio-dialog-open",
rail.shadowRoot?.querySelector("dialog[open]") != null,
);
};
new MutationObserver(place).observe(body, { childList: true });
new MutationObserver(place).observe(body, {
subtree: true,
attributeFilter: ["aria-hidden"],
});
window.addEventListener(
"keydown",
(event) => {
const jump =
event.shiftKey &&
!event.altKey &&
(event.metaKey || event.ctrlKey) &&
event.key.toLowerCase() === "e";
if (!jump || rail.parentElement !== body) return;
rail.setAttribute("data-lazurio-dialog-open", "");
window.addEventListener("keydown", place, { once: true });
setTimeout(place);
},
true,
);
customElements.whenDefined("lazurio-rail").then(() => {
if (!rail.shadowRoot) return;
new MutationObserver(place).observe(rail.shadowRoot, {
subtree: true,
attributeFilter: ["open"],
});
place();
});
});
</script>
</head>
<body>
<lazurio-rail data-app-sidebar app="chat"></lazurio-rail>
Expand Down
214 changes: 214 additions & 0 deletions apps/web/src/lazurio/narrowRail.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import { page, userEvent } from "vite-plus/test/browser";
import { describe, expect, it } from "vite-plus/test";

import "~/index.css";

import indexHtml from "../../index.html?raw";
import { render } from "../../test/render";
import { RightPanelSheet } from "../components/RightPanelSheet";
import { Sidebar, SidebarProvider, SidebarTrigger } from "../components/ui/sidebar";

// The rail in a narrow window (index.html, the Lazurio shell slot): hidden beside the
// conversation, inside T3's open left panel, and shown wherever it stands while a dialog of its
// own is open. The style and the script are index.html's own; the rail is a stand-in with the
// shape the shell's `<lazurio-rail>` has: an open shadow root, a control and a dialog.

const narrowStyle = (() => {
const match = indexHtml.match(/\n(\s*\/\* A narrow window[\s\S]*?)\n\s*<\/style>/);
if (!match?.[1]) throw new Error("Could not find the narrow rail style in index.html");
return match[1];
})();
const moverScript = (() => {
const match = indexHtml.match(/<script>\s*(\/\/ The rail in a narrow window[\s\S]*?)<\/script>/);
if (!match?.[1]) throw new Error("Could not find the rail mover in index.html");
return match[1];
})();

class StandInRail extends HTMLElement {
readonly dialog: HTMLDialogElement;
constructor() {
super();
const root = this.attachShadow({ mode: "open" });
root.innerHTML =
'<style>:host { position: fixed; inset: 0 auto 0 0; z-index: 40; display: block; width: 64px; }</style><nav aria-label="Organizations"><button type="button">Go to an Environment</button></nav><dialog><input aria-label="Environment or Organization" /></dialog>';
this.dialog = root.querySelector("dialog")!;
}
connectedCallback() {
document.documentElement.style.setProperty("--lazurio-rail-width", "64px");
}
/** As the shell's jump: opens its dialog and puts the focus into its search at once. */
openJump() {
this.dialog.showModal();
this.dialog.querySelector("input")!.focus();
}
}

// The shell answers ⌘⇧E / Ctrl+Shift+E on the document, unless the app took the key.
document.addEventListener("keydown", (event) => {
const rail = document.querySelector<StandInRail>("lazurio-rail");
if (
rail &&
!event.defaultPrevented &&
event.shiftKey &&
(event.metaKey || event.ctrlKey) &&
event.key.toLowerCase() === "e"
)
rail.openJump();
});

if (!customElements.get("lazurio-rail")) customElements.define("lazurio-rail", StandInRail);

const panel = () => document.querySelector('[data-mobile="true"][data-sidebar="sidebar"]');

/** index.html's narrow style and rail mover on this page, with a rail before #root as the slot
* has it; disposing removes them all, the mover's observers included. */
function narrowShell() {
const style = document.createElement("style");
style.textContent = narrowStyle;
document.head.append(style);
const root = document.createElement("div");
root.id = "root";
const rail = document.createElement("lazurio-rail") as StandInRail;
document.body.prepend(rail, root);
const observers: MutationObserver[] = [];
class TrackedObserver extends MutationObserver {
constructor(callback: MutationCallback) {
super(callback);
observers.push(this);
}
}
const events = new EventTarget();
const scopedDocument = new Proxy(document, {
get: (target, key) => {
if (key === "addEventListener") return events.addEventListener.bind(events);
const value: unknown = Reflect.get(target, key, target);
return typeof value === "function" ? value.bind(target) : value;
},
});
new Function("document", "MutationObserver", moverScript)(scopedDocument, TrackedObserver);
events.dispatchEvent(new Event("DOMContentLoaded"));
return {
rail,
[Symbol.dispose]() {
for (const observer of observers) observer.disconnect();
rail.remove();
root.remove();
style.remove();
},
};
}

const layout = () => (
<SidebarProvider storageKey="narrow_rail_test">
<Sidebar aria-label="Threads">
<a href="#thread">A thread</a>
</Sidebar>
<SidebarTrigger />
</SidebarProvider>
);

describe("the Lazurio rail in a narrow window", () => {
it("is hidden beside the conversation and part of the open panel's dialog", async () => {
await page.viewport(390, 844);
using shell = narrowShell();
const { rail } = shell;
await using screen = await render(layout(), { router: false /* no routes involved */ });
await expect.poll(() => rail.checkVisibility()).toBe(false);
expect(rail.parentElement).toBe(document.body);

await userEvent.click(screen.getByRole("button", { name: "Toggle Sidebar" }));
await expect.poll(() => rail.parentElement === panel() && panel() !== null).toBe(true);
expect(panel()!.firstElementChild).toBe(rail);
expect(rail.checkVisibility()).toBe(true);
await expect.poll(() => rail.getBoundingClientRect().left).toBe(0);
// The modal panel hides the page outside it from screen readers; the rail is not outside.
await expect.poll(() => rail.closest('[aria-hidden="true"], [inert]')).toBe(null);
const control = rail.shadowRoot!.querySelector("button")!;
control.focus();
expect(rail.shadowRoot!.activeElement).toBe(control);

await userEvent.keyboard("{Escape}");
await expect.poll(() => rail.parentElement).toBe(document.body);
expect(rail.checkVisibility()).toBe(false);
});

it("opens the jump visible and ready to type with the panel closed", async () => {
await page.viewport(390, 844);
using shell = narrowShell();
const { rail } = shell;
await using _screen = await render(layout(), { router: false /* no routes involved */ });
await expect.poll(() => rail.checkVisibility()).toBe(false);
expect(rail.parentElement).toBe(document.body);

await userEvent.keyboard("{Control>}{Shift>}E{/Shift}{/Control}");
expect(rail.dialog.open).toBe(true);
expect(rail.dialog.checkVisibility()).toBe(true);
expect(rail.dialog.getBoundingClientRect().width).toBeGreaterThan(0);
const search = rail.dialog.querySelector("input")!;
expect(rail.shadowRoot!.activeElement).toBe(search);
await userEvent.keyboard("Server");
expect(search.value).toBe("Server");

rail.dialog.close();
await expect.poll(() => rail.checkVisibility()).toBe(false);
});

it("stays hidden when the app takes the jump's keys", async () => {
await page.viewport(390, 844);
using shell = narrowShell();
const { rail } = shell;
await using _screen = await render(layout(), { router: false /* no routes involved */ });
await expect.poll(() => rail.checkVisibility()).toBe(false);
const take = (event: KeyboardEvent) => event.preventDefault();
window.addEventListener("keydown", take, true);
try {
await userEvent.keyboard("{Control>}{Shift>}E{/Shift}{/Control}");
} finally {
window.removeEventListener("keydown", take, true);
}
expect(rail.dialog.open).toBe(false);
expect(rail.checkVisibility()).toBe(false);
});

it("leaves the rail beside the app in a wide window", async () => {
await page.viewport(1280, 800);
using shell = narrowShell();
const { rail } = shell;
await using _screen = await render(layout(), { router: false /* no routes involved */ });
await expect.poll(() => rail.checkVisibility()).toBe(true);
expect(rail.parentElement).toBe(document.body);
});
});

describe("the right panel in a narrow window", () => {
const sheet = () => (
<RightPanelSheet animationDurationMs={0} open onClose={() => {}}>
<button type="button" aria-label="Toggle right panel">
×
</button>
</RightPanelSheet>
);
const box = () =>
document.querySelector('[data-slot="sheet-popup"]:not([data-mobile])')?.getBoundingClientRect();

it("takes the whole width, with its own toggle in reach", async () => {
await page.viewport(390, 844);
using _shell = narrowShell();
await using _screen = await render(sheet(), { router: false /* no routes involved */ });
await expect.poll(() => [box()?.left, box()?.width]).toEqual([0, 390]);
// The sheet is portalled out of the render's container.
await expect.element(page.getByRole("button", { name: "Toggle right panel" })).toBeVisible();
});

it("keeps T3's width in a wide window and outside Lazurio", async () => {
await page.viewport(900, 800);
{
using _shell = narrowShell();
await using _screen = await render(sheet(), { router: false /* no routes involved */ });
await expect.poll(() => box()?.width).toBeLessThan(900);
}
await page.viewport(390, 844);
await using _screen = await render(sheet(), { router: false /* no routes involved */ });
await expect.poll(() => box()?.width).toBeLessThan(390);
});
});
11 changes: 11 additions & 0 deletions docs/operations/lazurio-fork-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,17 @@ Slot jsou dva upstream soubory, každý jako vlastní řádek v
nechalo pod railem. Proto se při definovaném railu stane obal sidebaru
(`[data-slot="sidebar-wrapper"]`) jejich containing blockem
(`contain: layout paint`). Bez shellu pravidlo neplatí.
V úzkém okně (pod 768 px, kdy je levý panel T3 modální sheet, `SIDEBAR_MOBILE_QUERY`
v `sidebar.tsx`) má rozhovor celou šířku a rail není vidět. Ukáže se, až člověk otevře levý
panel: krátký skript v hlavičce `index.html` přesune rail do otevřeného panelu jako jeho první
prvek a panel mu nechá místo. Rail je tak součástí dialogu: klávesnice na něj dojde Tabem
a čtečka ho čte, i když modální sheet zbytek stránky skryje (`aria-hidden`) a drží fokus v sobě.
Po zavření panelu se rail vrátí před `#root`, kde zůstává cílem skoku ⌘⇧E. Dialog, který
rail otevře (skok ⌘⇧E), se kreslí jen tam, kde rail je, proto je rail při otevřeném dialogu vidět
i se zavřeným panelem (`data-lazurio-dialog-open`). Chování drží
`apps/web/src/lazurio/narrowRail.browser.test.tsx`. Pravý panel (`RightPanelSheet.tsx`, druhý
a jediný další sheet, bez `data-mobile`) má v úzkém okně celou šířku místo upstreamových
`min(88vw, 24rem)`. Zavírá ho jeho vlastní přepínač nebo Escape. Široké rozložení se nemění.
Buddyho spouštěč začíná 22 px od pravého a dolního okraje okna a uživatel ho přetáhne kamkoli
(LazurioPlatform F60, dodatek z 2026-11-14). Composer Chatu proto zůstává tam, kde ho kreslí T3,
a `--lazurio-buddy-clearance` nečte; kontraktní test hlídá, že se pravidlo nevrátí.
Expand Down
51 changes: 51 additions & 0 deletions scripts/lazurio-release-contract.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,57 @@ NodeTest.test("the Lazurio shell slot survives a rebuild on a new upstream tag",
/lazurio-rail:defined ~ #root \[data-slot="sidebar-wrapper"\] \{\s*contain: layout paint;\s*\}/,
);
NodeAssert.match(sidebarUi, /data-slot="sidebar-wrapper"/);
// A narrow window: the conversation takes the whole width without the rail, and the open left
// panel (T3's modal sheet) carries the rail inside it, so the dialog's focus trap and its
// aria-hidden on the page outside leave the rail reachable. The breakpoint and the sheet's
// attributes are T3's own.
const narrow = page.match(/@media \(max-width: 767px\) \{([\s\S]*?)\n \}\n/)?.[1] ?? "";
NodeAssert.match(sidebarUi, /const SIDEBAR_MOBILE_QUERY = "\(max-width: 767px\)";/);
NodeAssert.match(sidebarUi, /data-mobile="true"\s*data-sidebar="sidebar"/);
NodeAssert.match(narrow, /#root \{\s*padding-left: 0;\s*\}/);
NodeAssert.match(
narrow,
/body > lazurio-rail:defined:not\(\[data-lazurio-dialog-open\]\) \{\s*display: none;\s*\}/,
);
NodeAssert.match(
narrow,
/:root:has\(lazurio-rail:defined\) #root \[data-slot="sidebar-wrapper"\] \{\s*contain: layout paint;\s*\}/,
);
NodeAssert.match(
narrow,
/\[data-mobile="true"\]\[data-sidebar="sidebar"\]:has\(> lazurio-rail:defined\) \{\s*padding-left: var\(--lazurio-rail-width, 0px\);\s*\}/,
);
// The right panel (RightPanelSheet.tsx, the one sheet without data-mobile) takes the whole
// width in a narrow window with the shell present.
NodeAssert.match(
narrow,
/:root:has\(lazurio-rail:defined\) \[data-slot="sheet-popup"\]:not\(\[data-mobile\]\) \{\s*width: 100vw;\s*min-width: 0;\s*max-width: none;/,
);
NodeAssert.ok(
page.indexOf("@media (max-width: 767px)") > page.search(/#root \{\s*box-sizing: border-box;/),
"the narrow rule follows the rail's padding, so it wins",
);
const mover =
page.match(/<script>\s*\/\/ The rail in a narrow window[\s\S]*?<\/script>/)?.[0] ?? "";
NodeAssert.match(
mover,
/body\.querySelector\('\[data-mobile="true"\]\[data-sidebar="sidebar"\]'\)/,
);
NodeAssert.match(mover, /panel\.prepend\(rail\)/);
NodeAssert.match(mover, /rail\.removeAttribute\("aria-hidden"\)/);
NodeAssert.match(mover, /body\.insertBefore\(rail, document\.getElementById\("root"\)\)/);
// A dialog the rail opens (the Environment jump) is drawn only where the rail is: while one is
// open, the rail is shown wherever it stands (narrowRail.browser.test.tsx).
NodeAssert.match(
mover,
/"data-lazurio-dialog-open",\s*rail\.shadowRoot\?\.querySelector\("dialog\[open\]"\) != null/,
);
// The jump focuses its search as it opens: the rail is shown before the shell takes the key.
NodeAssert.match(
mover,
/window\.addEventListener\(\s*"keydown",[\s\S]*?rail\.setAttribute\("data-lazurio-dialog-open", ""\);[\s\S]*?true,\s*\);/,
);
NodeAssert.ok(page.indexOf(mover) < page.indexOf("<body>"), "the mover is in the head");
NodeAssert.match(
page,
/<body>\s*<lazurio-rail data-app-sidebar app="chat"><\/lazurio-rail>\s*<div id="root">/,
Expand Down
Loading