mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-16 05:14:50 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e83ac3225 | ||
|
|
e47c44b166 | ||
|
|
2209155b6f | ||
|
|
5037f7daf2 | ||
|
|
4293292d00 | ||
|
|
c94c3c47fe | ||
|
|
158032ac40 | ||
|
|
437fb8af0b | ||
|
|
2ef65f7691 | ||
|
|
79620eeea4 |
@@ -126,8 +126,12 @@ keeps Explorer underneath and closing the sheet uncovers it. Semantic navigation
|
||||
actual destination before revealing it, including deduplicated targets.
|
||||
|
||||
Compact overlay selection and saved dock visibility are independent. Folding changes geometry,
|
||||
not either mode’s visibility intent. Native workspace retention remains one workspace; web retains
|
||||
up to ten with its existing inactive TTL.
|
||||
not either mode’s visibility intent. Native retains up to three recent workspaces; web retains
|
||||
up to ten. Both use the existing inactive TTL. A native workspace with an open file sheet still
|
||||
unmounts on navigation because its sheet stack uses the app-wide host. Other sheets close when
|
||||
their retained owner becomes inactive, unless the owner already hides them on focus loss.
|
||||
Import-session and tab-rename forms retain their open state on return. Review drafts survive
|
||||
presentation unmounts.
|
||||
|
||||
PR discovery belongs to the active workspace: split layouts discover while active, and other
|
||||
layouts discover while Explorer is active. The rail requests summary status; selected visible PR
|
||||
|
||||
@@ -58,7 +58,9 @@ cannot deliver them.
|
||||
Register keyboard handling with `useOverlayRegistration` from `@/keyboard`.
|
||||
Pass the surface's open state, layer, handled keys and `onKeyDown`. The highest
|
||||
layer gets first refusal; the latest registration wins a tie. Native registration
|
||||
does not need a DOM ref. Web adds focus trapping and restoration through its adapter.
|
||||
does not need a DOM ref. The native adapter releases overlay keyboard ownership when a retained
|
||||
panel hides, even if the owner keeps its open state. Web releases ownership when the scope
|
||||
detaches, preserving the original focus-return target across a hide.
|
||||
Declaring Tab takes it from the web focus trap and hands it to `onKeyDown`; the command
|
||||
center rotates its tabs with it. Native sources drop Tab from the declarations.
|
||||
|
||||
|
||||
@@ -148,3 +148,51 @@ test.describe("mobile bottom sheet reopen", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
async function switchToNextWorkspace(page: Page, workspaceId: string) {
|
||||
await page.keyboard.press("Alt+]");
|
||||
await page.waitForURL((url) => url.pathname.endsWith(`/workspace/${workspaceId}`));
|
||||
}
|
||||
|
||||
test("leaving a retained workspace dismisses its model sheet", async ({ page }) => {
|
||||
const first = await openMockAgentAtMobileBreakpoint(page);
|
||||
const second = await seedMockAgentWorkspace({
|
||||
repoPrefix: "sheet-other-workspace-",
|
||||
title: "Other workspace",
|
||||
initialPrompt: "Prepare another workspace.",
|
||||
});
|
||||
try {
|
||||
await openModelSelector(page);
|
||||
await switchToNextWorkspace(page, second.workspaceId);
|
||||
await expect(page.getByTestId("agent-controls-model-sheet")).not.toBeInViewport();
|
||||
await expectComposerVisible(page);
|
||||
await switchToNextWorkspace(page, first.workspaceId);
|
||||
await expect(page.getByTestId("agent-controls-model-sheet")).not.toBeInViewport();
|
||||
await expectComposerVisible(page);
|
||||
} finally {
|
||||
await second.cleanup();
|
||||
await first.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("leaving a retained workspace closes its context window sheet", async ({ page }) => {
|
||||
const first = await openMockAgentAtMobileBreakpoint(page);
|
||||
const second = await seedMockAgentWorkspace({
|
||||
repoPrefix: "context-sheet-other-",
|
||||
title: "Other workspace",
|
||||
});
|
||||
try {
|
||||
await page.getByRole("button", { name: /Context window.*used/ }).click();
|
||||
const sheet = page.getByRole("dialog", { name: "Context window", exact: true });
|
||||
await expect(sheet).toBeInViewport();
|
||||
await switchToNextWorkspace(page, second.workspaceId);
|
||||
await expect(sheet).not.toBeInViewport();
|
||||
await expectComposerVisible(page);
|
||||
await switchToNextWorkspace(page, first.workspaceId);
|
||||
await expect(sheet).not.toBeInViewport();
|
||||
await expectComposerVisible(page);
|
||||
} finally {
|
||||
await second.cleanup();
|
||||
await first.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { openAgentRoute, seedMockAgentWorkspace } from "../support/helpers/mock-agent";
|
||||
import { expect, test } from "../support/fixtures";
|
||||
import { clickNewChat } from "../support/helpers/launcher";
|
||||
import { expectComposerVisible } from "../support/helpers/composer";
|
||||
@@ -310,3 +311,32 @@ test.describe("Composer attachments", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("image lightbox hides when its retained workspace becomes inactive", async ({ page }) => {
|
||||
const first = await seedMockAgentWorkspace({
|
||||
repoPrefix: "image-owner-",
|
||||
title: "Image workspace",
|
||||
});
|
||||
const second = await seedMockAgentWorkspace({
|
||||
repoPrefix: "image-other-",
|
||||
title: "Other workspace",
|
||||
});
|
||||
try {
|
||||
await openAgentRoute(page, first);
|
||||
await expectComposerVisible(page);
|
||||
await attachImageFromMenu(page, TEST_IMAGE);
|
||||
await openImageLightbox(page);
|
||||
await page.keyboard.press("Alt+]");
|
||||
await page.waitForURL((url) => url.pathname.endsWith(`/workspace/${second.workspaceId}`));
|
||||
await expect(page.getByTestId("attachment-lightbox-close")).not.toBeVisible();
|
||||
await expectComposerVisible(page);
|
||||
await page.keyboard.press("Alt+]");
|
||||
await page.waitForURL((url) => url.pathname.endsWith(`/workspace/${first.workspaceId}`));
|
||||
await expect(page.getByTestId("attachment-lightbox-close")).toBeVisible();
|
||||
await closeImageLightbox(page);
|
||||
await expect(page.getByRole("button", { name: "Open image attachment" }).first()).toBeFocused();
|
||||
} finally {
|
||||
await second.cleanup();
|
||||
await first.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -248,6 +248,33 @@ test.describe("review comments", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("compact review draft survives a workspace switch", async ({ page }) => {
|
||||
const workspace = await seedChangedAgent("retained-review-draft-");
|
||||
const other = await seedMockAgentWorkspace({
|
||||
repoPrefix: "review-other-",
|
||||
title: "Other workspace",
|
||||
});
|
||||
try {
|
||||
await openReviewDiff(page, workspace);
|
||||
await showCompactLayout(page);
|
||||
await tapFirstAddedDiffLine(page);
|
||||
await expectCompactCommentSheet(page);
|
||||
await fillReviewComment(page, "Keep this unsaved review");
|
||||
await page.keyboard.press("Alt+]");
|
||||
await page.waitForURL((url) => url.pathname.endsWith(`/workspace/${other.workspaceId}`));
|
||||
await expect(page.getByTestId("review-comment-sheet")).not.toBeInViewport();
|
||||
await page.keyboard.press("Alt+]");
|
||||
await page.waitForURL((url) => url.pathname.endsWith(`/workspace/${workspace.workspaceId}`));
|
||||
await expect(page.getByRole("textbox", { name: "Review comment" })).toHaveValue(
|
||||
"Keep this unsaved review",
|
||||
);
|
||||
await cancelReviewComment(page);
|
||||
} finally {
|
||||
await other.cleanup();
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("wide review comments retain inline editing", async ({ page }) => {
|
||||
const workspace = await seedChangedAgent("wide-review-comment-");
|
||||
try {
|
||||
|
||||
@@ -70,6 +70,8 @@ function enableDictationCapability(message: WebSocketMessage): WebSocketMessage
|
||||
async function installSyntheticMicrophone(page: Page): Promise<void> {
|
||||
await page.addInitScript(() => {
|
||||
const mediaDevices = navigator.mediaDevices;
|
||||
const tracks: MediaStreamTrack[] = [];
|
||||
Object.defineProperty(window, "dictationTestTracks", { value: tracks });
|
||||
Object.defineProperty(mediaDevices, "getUserMedia", {
|
||||
configurable: true,
|
||||
value: async () => {
|
||||
@@ -78,13 +80,15 @@ async function installSyntheticMicrophone(page: Page): Promise<void> {
|
||||
const destination = context.createMediaStreamDestination();
|
||||
oscillator.connect(destination);
|
||||
oscillator.start();
|
||||
tracks.push(...destination.stream.getTracks());
|
||||
return destination.stream;
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function installDictationFailureHarness(page: Page) {
|
||||
async function installDictationFailureHarness(page: Page, holdTranscript = false) {
|
||||
let deliverTranscript: (() => void) | null = null;
|
||||
let resolveAudioChunk!: () => void;
|
||||
let resolveCreateRequest!: () => void;
|
||||
const audioChunk = new Promise<void>((resolve) => {
|
||||
@@ -122,12 +126,14 @@ async function installDictationFailureHarness(page: Page) {
|
||||
if (type === "dictation_stream_finish" && dictationId) {
|
||||
sendSessionMessage(ws, {
|
||||
type: "dictation_stream_finish_accepted",
|
||||
payload: { dictationId, timeoutMs: 5_000 },
|
||||
});
|
||||
sendSessionMessage(ws, {
|
||||
type: "dictation_stream_final",
|
||||
payload: { dictationId, text: TRANSCRIPT },
|
||||
payload: { dictationId, timeoutMs: holdTranscript ? 60_000 : 5_000 },
|
||||
});
|
||||
deliverTranscript = () =>
|
||||
sendSessionMessage(ws, {
|
||||
type: "dictation_stream_final",
|
||||
payload: { dictationId, text: TRANSCRIPT },
|
||||
});
|
||||
if (!holdTranscript) deliverTranscript();
|
||||
return;
|
||||
}
|
||||
if (request && type === "workspace.create.request" && typeof request.requestId === "string") {
|
||||
@@ -155,6 +161,11 @@ async function installDictationFailureHarness(page: Page) {
|
||||
|
||||
return {
|
||||
waitForAudio: () => audioChunk,
|
||||
hasPendingTranscript: () => deliverTranscript !== null,
|
||||
deliverTranscript: () => {
|
||||
if (!deliverTranscript) throw new Error("No pending transcript");
|
||||
deliverTranscript();
|
||||
},
|
||||
waitForCreateRequest: () => createRequest,
|
||||
failWorkspaceCreation: () => {
|
||||
if (!failCreate) {
|
||||
@@ -254,3 +265,75 @@ test("dictation shortcut leaves retained fullscreen and exposes recording contro
|
||||
await agent.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("leaving a retained workspace stops dictation and preserves its draft", async ({ page }) => {
|
||||
const first = await seedMockAgentWorkspace({
|
||||
repoPrefix: "dictation-owner-",
|
||||
title: "Recording workspace",
|
||||
});
|
||||
const second = await seedMockAgentWorkspace({
|
||||
repoPrefix: "dictation-other-",
|
||||
title: "Other workspace",
|
||||
});
|
||||
await installSyntheticMicrophone(page);
|
||||
const harness = await installDictationFailureHarness(page);
|
||||
try {
|
||||
await openAgentRoute(page, first);
|
||||
await expectComposerVisible(page);
|
||||
await fillComposerDraft(page, "Keep this draft");
|
||||
await page.getByRole("button", { name: "Start dictation", exact: true }).click();
|
||||
await harness.waitForAudio();
|
||||
await page.keyboard.press("Alt+]");
|
||||
await page.waitForURL((url) => url.pathname.endsWith(`/workspace/${second.workspaceId}`));
|
||||
await expect.poll(() => microphoneTracksEnded(page)).toBe(true);
|
||||
await page.keyboard.press("Alt+]");
|
||||
await page.waitForURL((url) => url.pathname.endsWith(`/workspace/${first.workspaceId}`));
|
||||
await expect(composerLocator(page)).toHaveValue("Keep this draft");
|
||||
await expect(page.getByRole("button", { name: "Cancel dictation", exact: true })).toHaveCount(
|
||||
0,
|
||||
);
|
||||
} finally {
|
||||
await second.cleanup();
|
||||
await first.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
function microphoneTracksEnded(page: Page): Promise<boolean> {
|
||||
return page.evaluate(() => {
|
||||
const tracks = (window as unknown as { dictationTestTracks: MediaStreamTrack[] })
|
||||
.dictationTestTracks;
|
||||
return tracks.length > 0 && tracks.every((track) => track.readyState === "ended");
|
||||
});
|
||||
}
|
||||
|
||||
test("confirmed dictation survives leaving and returning while pending", async ({ page }) => {
|
||||
const first = await seedMockAgentWorkspace({
|
||||
repoPrefix: "dictation-processing-",
|
||||
title: "Processing workspace",
|
||||
});
|
||||
const second = await seedMockAgentWorkspace({
|
||||
repoPrefix: "dictation-other-",
|
||||
title: "Other workspace",
|
||||
});
|
||||
await installSyntheticMicrophone(page);
|
||||
const harness = await installDictationFailureHarness(page, true);
|
||||
try {
|
||||
await openAgentRoute(page, first);
|
||||
await expectComposerVisible(page);
|
||||
await page.getByRole("button", { name: "Start dictation", exact: true }).click();
|
||||
await harness.waitForAudio();
|
||||
await page.getByRole("button", { name: "Insert transcription", exact: true }).click();
|
||||
await expect.poll(harness.hasPendingTranscript).toBe(true);
|
||||
await page.keyboard.press("Alt+]");
|
||||
await page.waitForURL((url) => url.pathname.endsWith(`/workspace/${second.workspaceId}`));
|
||||
await expect.poll(() => microphoneTracksEnded(page)).toBe(true);
|
||||
await page.keyboard.press("Alt+]");
|
||||
await page.waitForURL((url) => url.pathname.endsWith(`/workspace/${first.workspaceId}`));
|
||||
await expect(page.getByRole("button", { name: "Cancel dictation", exact: true })).toBeVisible();
|
||||
harness.deliverTranscript();
|
||||
await expect(composerLocator(page)).toHaveValue(TRANSCRIPT);
|
||||
} finally {
|
||||
await second.cleanup();
|
||||
await first.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -237,7 +237,12 @@ function WorkspaceDeckEntry({
|
||||
}) {
|
||||
const hasHydratedWorkspaces = useHasHydratedWorkspaces(selection.serverId);
|
||||
const workspaceExists = useWorkspaceExists(selection.serverId, selection.workspaceId);
|
||||
const hasOpenNativeSheets = useWorkspaceLayoutStore(
|
||||
(state) =>
|
||||
isNative && (state.sheetsByWorkspace[getWorkspaceSelectionKey(selection)]?.length ?? 0) > 0,
|
||||
);
|
||||
const shouldKeepMounted = shouldKeepWorkspaceDeckEntryMounted({
|
||||
hasOpenNativeSheets,
|
||||
isActive: active,
|
||||
hasHydratedWorkspaces,
|
||||
workspaceExists,
|
||||
|
||||
@@ -662,7 +662,7 @@ function CompactSheetBody({
|
||||
|
||||
export function AdaptiveModalSheet({
|
||||
header,
|
||||
visible,
|
||||
visible: requestedVisible,
|
||||
onClose,
|
||||
onDismiss,
|
||||
children,
|
||||
@@ -680,9 +680,15 @@ export function AdaptiveModalSheet({
|
||||
}: AdaptiveModalSheetProps) {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsCompactFormFactor();
|
||||
const isKeyboardVisible = useKeyboardVisibility(visible);
|
||||
const resolvedSnapPoints = useMemo(() => snapPoints ?? ["65%", "90%"], [snapPoints]);
|
||||
const isSheet = isMobile || !isWeb;
|
||||
const { visible, sheetRef, handleSheetChange, handleSheetDismiss } =
|
||||
useIsolatedBottomSheetVisibility({
|
||||
visible: requestedVisible,
|
||||
isEnabled: isSheet,
|
||||
onClose,
|
||||
});
|
||||
const isKeyboardVisible = useKeyboardVisibility(visible);
|
||||
// The sheet registers itself; the desktop dialog does not use it.
|
||||
useDismissibleOverlay(visible && !isSheet, onClose);
|
||||
const footerView = useMemo(
|
||||
@@ -697,11 +703,6 @@ export function AdaptiveModalSheet({
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
const { sheetRef, handleSheetChange, handleSheetDismiss } = useIsolatedBottomSheetVisibility({
|
||||
visible,
|
||||
isEnabled: isSheet,
|
||||
onClose,
|
||||
});
|
||||
const [shouldRenderWeb, setShouldRenderWeb] = useState(visible);
|
||||
const [isWebClosing, setIsWebClosing] = useState(false);
|
||||
const modalLayer = useGlobalOverlayLayer("modal", visible || shouldRenderWeb);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useRetainedPanelActive } from "@/components/retained-panel";
|
||||
import {
|
||||
BottomSheetModal as GorhomBottomSheetModal,
|
||||
type BottomSheetModalProps,
|
||||
@@ -160,7 +161,7 @@ export const IsolatedBottomSheetModal = forwardRef<
|
||||
});
|
||||
|
||||
export function useIsolatedBottomSheetVisibility({
|
||||
visible,
|
||||
visible: requestedVisible,
|
||||
isEnabled,
|
||||
onClose,
|
||||
onBack,
|
||||
@@ -171,6 +172,8 @@ export function useIsolatedBottomSheetVisibility({
|
||||
/** Offered Android Back before it closes the sheet; returns true when it handled the press. */
|
||||
onBack?: () => boolean;
|
||||
}) {
|
||||
const active = useRetainedPanelActive();
|
||||
const visible = requestedVisible && active;
|
||||
const onCloseRef = useRef(onClose);
|
||||
onCloseRef.current = onClose;
|
||||
const onBackRef = useRef(onBack);
|
||||
@@ -201,11 +204,12 @@ export function useIsolatedBottomSheetVisibility({
|
||||
const handleSheetDismiss = useCallback(() => tracker.handleSheetDismiss(), [tracker]);
|
||||
|
||||
useEffect(() => {
|
||||
tracker.syncDesired({ visible, isEnabled });
|
||||
}, [isEnabled, tracker, visible]);
|
||||
tracker.syncDesired({ visible: requestedVisible, active, isEnabled });
|
||||
}, [active, isEnabled, tracker, requestedVisible]);
|
||||
useDismissibleOverlay(visible && isEnabled !== false, onClose);
|
||||
|
||||
return {
|
||||
visible,
|
||||
sheetRef: setSheetRef,
|
||||
handleSheetChange,
|
||||
handleSheetDismiss,
|
||||
|
||||
@@ -291,3 +291,46 @@ it("does not cancel the owner's editor when the compact sheet leaves the tree on
|
||||
expect(context.closeCount()).toBe(0);
|
||||
expect(context.backPress.press()).toBe(false);
|
||||
});
|
||||
|
||||
it("closes a retained owner's sheet and releases Back when the owner becomes inactive", () => {
|
||||
const { sheet, tracker, backPress, closeCount } = setup();
|
||||
tracker.attachController(sheet);
|
||||
tracker.syncDesired({ visible: true, active: true });
|
||||
tracker.handleSheetIndexChange(0);
|
||||
tracker.syncDesired({ visible: true, active: false });
|
||||
expect(sheet.events).toEqual([{ type: "present" }, { type: "dismiss" }]);
|
||||
expect(closeCount()).toBe(1);
|
||||
expect(backPress.press()).toBe(false);
|
||||
tracker.syncDesired({ visible: false, active: false });
|
||||
tracker.handleSheetDismiss();
|
||||
tracker.syncDesired({ visible: false, active: true });
|
||||
expect(sheet.events).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("dismisses a late opening after the inactive owner acknowledges closure", () => {
|
||||
const { sheet, tracker, backPress, closeCount } = setup();
|
||||
tracker.attachController(sheet);
|
||||
tracker.syncDesired({ visible: true, active: true });
|
||||
tracker.syncDesired({ visible: true, active: false });
|
||||
expect(closeCount()).toBe(1);
|
||||
tracker.syncDesired({ visible: false, active: false });
|
||||
// Gorhom can drop an early dismiss before its first layout measurement.
|
||||
tracker.handleSheetIndexChange(0);
|
||||
expect(sheet.events).toEqual([{ type: "present" }, { type: "dismiss" }, { type: "dismiss" }]);
|
||||
expect(backPress.press()).toBe(false);
|
||||
tracker.handleSheetDismiss();
|
||||
tracker.syncDesired({ visible: false, active: true });
|
||||
expect(sheet.events).toHaveLength(3);
|
||||
});
|
||||
|
||||
it("closes a disabled presentation on every departure after owner acknowledgement", () => {
|
||||
const { tracker, closeCount } = setup();
|
||||
for (let departure = 1; departure <= 2; departure++) {
|
||||
tracker.syncDesired({ visible: true, active: true, isEnabled: false });
|
||||
tracker.syncDesired({ visible: true, active: false, isEnabled: false });
|
||||
tracker.syncDesired({ visible: true, active: false, isEnabled: false });
|
||||
expect(closeCount()).toBe(departure);
|
||||
tracker.syncDesired({ visible: false, active: false, isEnabled: false });
|
||||
tracker.syncDesired({ visible: false, active: true, isEnabled: false });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface BottomSheetController {
|
||||
|
||||
export interface BottomSheetVisibilityInput {
|
||||
visible: boolean;
|
||||
active?: boolean;
|
||||
isEnabled?: boolean;
|
||||
}
|
||||
|
||||
@@ -101,8 +102,16 @@ export function createBottomSheetVisibilityTracker(opts: {
|
||||
}
|
||||
},
|
||||
syncDesired(next) {
|
||||
visible = next.visible;
|
||||
visible = next.visible && next.active !== false;
|
||||
isEnabled = next.isEnabled;
|
||||
if (!next.visible) hasNotifiedClose = false;
|
||||
// Leaving a retained owner is a close, not a temporary presentation pause.
|
||||
// Clear its desired state so returning does not reopen the old sheet.
|
||||
if (next.visible && next.active === false) {
|
||||
dismiss();
|
||||
notifyClose();
|
||||
return;
|
||||
}
|
||||
if (isEnabled === false) return;
|
||||
if (visible) {
|
||||
present();
|
||||
@@ -117,9 +126,7 @@ export function createBottomSheetVisibilityTracker(opts: {
|
||||
},
|
||||
handleSheetIndexChange(index) {
|
||||
if (index !== -1) {
|
||||
if (phase === "presenting" || phase === "dismissing") {
|
||||
setPhase("presented");
|
||||
}
|
||||
setPhase("presented");
|
||||
// A dismiss sent before the sheet measured its layout is dropped, and the sheet still
|
||||
// finishes opening. The owner wants it hidden, so it goes again.
|
||||
if (!visible && isEnabled !== false) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useRetainedPanelActive } from "@/components/retained-panel";
|
||||
import { useMemo } from "react";
|
||||
import {
|
||||
Modal as NativeModal,
|
||||
@@ -23,11 +24,23 @@ type ModalProps = Omit<NativeModalProps, "onRequestClose"> & {
|
||||
function noClose() {}
|
||||
|
||||
export function Modal(props: ModalProps) {
|
||||
const { visible = true, onRequestClose, style } = props;
|
||||
const { visible: requestedVisible = true, onRequestClose, style } = props;
|
||||
const active = useRetainedPanelActive();
|
||||
const visible = requestedVisible && active;
|
||||
useDismissibleOverlay(visible && onRequestClose !== undefined, onRequestClose ?? noClose);
|
||||
const windowFrame = useAndroidWindowFrame();
|
||||
const containerStyle = useMemo(() => [windowFrame, style], [windowFrame, style]);
|
||||
return <NativeModal supportedOrientations={orientations} {...props} style={containerStyle} />;
|
||||
// Hidden web chats freeze before a modal exit animation can finish.
|
||||
// Remove the portal while its owner is inactive.
|
||||
if (!active) return null;
|
||||
return (
|
||||
<NativeModal
|
||||
supportedOrientations={orientations}
|
||||
{...props}
|
||||
visible={visible}
|
||||
style={containerStyle}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useRetainedPanelActive } from "@/components/retained-panel";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
|
||||
export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
const { t } = useTranslation();
|
||||
const active = useRetainedPanelActive();
|
||||
const {
|
||||
client,
|
||||
onTranscript,
|
||||
@@ -336,6 +338,10 @@ export function useDictation(options: UseDictationOptions): UseDictationResult {
|
||||
}
|
||||
}, [audio, clearStreamingState, reportError, stopDurationTracking]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!active && isRecording && !isProcessing) void cancelDictation();
|
||||
}, [active, cancelDictation, isRecording, isProcessing]);
|
||||
|
||||
const confirmDictation = useCallback(async () => {
|
||||
if (actionGateRef.current.confirming) {
|
||||
return;
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
import { useRetainedPanelActive } from "@/components/retained-panel";
|
||||
import type { OverlayRegistration } from "./overlay-contract";
|
||||
import { useLayoutEffect, useRef } from "react";
|
||||
import { overlays } from "./overlays";
|
||||
|
||||
const setScope = (_node: unknown) => {};
|
||||
export function useOverlayRegistration(input: OverlayRegistration) {
|
||||
const ownerActive = useRetainedPanelActive();
|
||||
const active = input.active && ownerActive;
|
||||
const current = useRef(input);
|
||||
current.current = input;
|
||||
useLayoutEffect(() => {
|
||||
if (!input.active) return;
|
||||
if (!active) return;
|
||||
return overlays.register({
|
||||
getLayer: () => current.current.layer,
|
||||
getKeys: () => current.current.keys,
|
||||
onKeyDown: (event) => current.current.onKeyDown(event),
|
||||
});
|
||||
}, [input.active]);
|
||||
}, [active]);
|
||||
return setScope;
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildEffectiveBindings } from "./keyboard-shortcuts";
|
||||
import { createKeyboardPipeline } from "./internal/pipeline";
|
||||
import { createOverlayRegistry } from "./internal/overlays";
|
||||
describe("DOM source adapter", () => {
|
||||
it("runs DOM input through the same resolver, preserving cancellation and cleanup", async () => {
|
||||
const { attachDomKeyboardSource } = await import("./internal/sources/dom.web");
|
||||
const actions: string[] = [];
|
||||
const input = document.createElement("textarea");
|
||||
input.dataset.testid = "message-input";
|
||||
document.body.append(input);
|
||||
input.focus();
|
||||
const pipeline = createKeyboardPipeline({
|
||||
getContext: () => ({ isMac: true, usesDesktopBindings: false, commandCenterOpen: false }),
|
||||
getBindings: () => buildEffectiveBindings({ "command-center-toggle-cmd-k-mac": "Cmd+J" }),
|
||||
isCapturing: () => false,
|
||||
dispatch: (match) => {
|
||||
actions.push(match.action);
|
||||
return true;
|
||||
},
|
||||
overlays: createOverlayRegistry(),
|
||||
});
|
||||
const detach = attachDomKeyboardSource({
|
||||
keyDown: pipeline.keyDown,
|
||||
keyUp() {},
|
||||
blur() {},
|
||||
commandCenterOpen: () => false,
|
||||
subscribeCommandCenter: () => () => {},
|
||||
});
|
||||
const event = new KeyboardEvent("keydown", {
|
||||
key: "j",
|
||||
code: "KeyJ",
|
||||
metaKey: true,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
});
|
||||
input.dispatchEvent(event);
|
||||
expect(actions).toEqual(["command-center.toggle"]);
|
||||
expect(event.defaultPrevented).toBe(true);
|
||||
detach();
|
||||
input.dispatchEvent(
|
||||
new KeyboardEvent("keydown", { key: "j", code: "KeyJ", metaKey: true, bubbles: true }),
|
||||
);
|
||||
expect(actions).toHaveLength(1);
|
||||
input.remove();
|
||||
pipeline.dispose();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
import React from "react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildEffectiveBindings } from "./keyboard-shortcuts";
|
||||
import { createKeyboardPipeline } from "./internal/pipeline";
|
||||
import { createOverlayRegistry } from "./internal/overlays";
|
||||
describe("DOM source adapter", () => {
|
||||
it("runs DOM input through the same resolver, preserving cancellation and cleanup", async () => {
|
||||
const { attachDomKeyboardSource } = await import("./internal/sources/dom.web");
|
||||
const actions: string[] = [];
|
||||
const input = document.createElement("textarea");
|
||||
input.dataset.testid = "message-input";
|
||||
document.body.append(input);
|
||||
input.focus();
|
||||
const pipeline = createKeyboardPipeline({
|
||||
getContext: () => ({ isMac: true, usesDesktopBindings: false, commandCenterOpen: false }),
|
||||
getBindings: () => buildEffectiveBindings({ "command-center-toggle-cmd-k-mac": "Cmd+J" }),
|
||||
isCapturing: () => false,
|
||||
dispatch: (match) => {
|
||||
actions.push(match.action);
|
||||
return true;
|
||||
},
|
||||
overlays: createOverlayRegistry(),
|
||||
});
|
||||
const detach = attachDomKeyboardSource({
|
||||
keyDown: pipeline.keyDown,
|
||||
keyUp() {},
|
||||
blur() {},
|
||||
commandCenterOpen: () => false,
|
||||
subscribeCommandCenter: () => () => {},
|
||||
});
|
||||
const event = new KeyboardEvent("keydown", {
|
||||
key: "j",
|
||||
code: "KeyJ",
|
||||
metaKey: true,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
});
|
||||
input.dispatchEvent(event);
|
||||
expect(actions).toEqual(["command-center.toggle"]);
|
||||
expect(event.defaultPrevented).toBe(true);
|
||||
detach();
|
||||
input.dispatchEvent(
|
||||
new KeyboardEvent("keydown", { key: "j", code: "KeyJ", metaKey: true, bubbles: true }),
|
||||
);
|
||||
expect(actions).toHaveLength(1);
|
||||
input.remove();
|
||||
pipeline.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
it("releases a hidden retained owner's overlay keys while its scope stays mounted", async () => {
|
||||
const { createElement, act } = await import("react");
|
||||
const { createRoot } = await import("react-dom/client");
|
||||
const { RetainedPanelActivity } = await import("@/components/retained-panel");
|
||||
const { getTopOverlayKeys, hasActiveOverlay } = await import("./index");
|
||||
// Exercise the native adapter itself in a real React renderer, bypassing Vite's .web resolution.
|
||||
const nativeAdapterPath = "./internal/overlay-registration.ts";
|
||||
const { useOverlayRegistration } = (await import(
|
||||
/* @vite-ignore */ nativeAdapterPath
|
||||
)) as typeof import("./internal/overlay-registration");
|
||||
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
||||
const container = document.createElement("div");
|
||||
document.body.append(container);
|
||||
const root = createRoot(container);
|
||||
function Viewer() {
|
||||
const scope = useOverlayRegistration({
|
||||
active: true,
|
||||
layer: 100,
|
||||
keys: ["Escape"],
|
||||
manageFocus: false,
|
||||
onKeyDown: () => true,
|
||||
});
|
||||
return createElement("button", { ref: scope, type: "button" }, "Viewer");
|
||||
}
|
||||
async function render(active: boolean) {
|
||||
await act(async () =>
|
||||
root.render(
|
||||
<RetainedPanelActivity active={active}>
|
||||
<Viewer />
|
||||
</RetainedPanelActivity>,
|
||||
),
|
||||
);
|
||||
}
|
||||
try {
|
||||
await render(true);
|
||||
expect(getTopOverlayKeys()).toEqual(["Escape"]);
|
||||
await render(false);
|
||||
expect(container.querySelector("button")).not.toBeNull();
|
||||
expect(hasActiveOverlay()).toBe(false);
|
||||
expect(getTopOverlayKeys()).toEqual([]);
|
||||
await render(true);
|
||||
expect(getTopOverlayKeys()).toEqual(["Escape"]);
|
||||
} finally {
|
||||
await act(async () => root.unmount());
|
||||
container.remove();
|
||||
}
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import { useKeyboardAnimation } from "react-native-keyboard-controller";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { KeyboardTranslationContext } from "./context";
|
||||
import { useKeyboardTranslationScope } from "./measure";
|
||||
import { useRetainedPanelActive } from "@/components/retained-panel";
|
||||
|
||||
interface KeyboardTranslateViewProps extends ViewProps {
|
||||
children: ReactNode;
|
||||
@@ -25,6 +26,7 @@ export function KeyboardTranslateView({
|
||||
style,
|
||||
...props
|
||||
}: KeyboardTranslateViewProps) {
|
||||
const active = useRetainedPanelActive();
|
||||
const insets = useSafeAreaInsets();
|
||||
const { height, progress } = useKeyboardAnimation();
|
||||
// Mirrors resolveKeyboardLift on the native driver: `overlap` is the negated shift.
|
||||
@@ -50,7 +52,9 @@ export function KeyboardTranslateView({
|
||||
// setValue during the React commit gets overwritten by the resize. A rebuilt
|
||||
// graph (a new bottomClearance after rotation) starts from JS-side keyboard
|
||||
// values, so run it on the native frame too or it stays stale until the
|
||||
// keyboard next moves.
|
||||
// keyboard next moves. Reactivating a retained panel also reapplies Fabric's
|
||||
// last transform, including keyboard motion that happened while it was hidden.
|
||||
// Refresh the native graph when panel activity changes as well.
|
||||
const enabledValue = useAnimatedValue(enabled ? 1 : 0);
|
||||
useEffect(() => {
|
||||
const animation = Animated.timing(enabledValue, {
|
||||
@@ -60,7 +64,7 @@ export function KeyboardTranslateView({
|
||||
});
|
||||
animation.start();
|
||||
return () => animation.stop();
|
||||
}, [enabled, enabledValue, translateY]);
|
||||
}, [active, enabled, enabledValue, translateY]);
|
||||
const keyboardStyle = useMemo(
|
||||
() => ({ transform: [{ translateY: Animated.multiply(translateY, enabledValue) }] }),
|
||||
[enabledValue, translateY],
|
||||
|
||||
@@ -30,15 +30,24 @@ function retainedWorkspaceIds(
|
||||
}
|
||||
|
||||
describe("reconcileRetainedWorkspaceSelections", () => {
|
||||
it("retains only the active workspace on native", () => {
|
||||
const entries = reconcileRetainedWorkspaceSelections({
|
||||
currentEntries: [retained("A", null)],
|
||||
activeSelection: workspace("B"),
|
||||
now: 2,
|
||||
maxMountedWorkspaces: resolveWorkspaceDeckRetentionLimit({ isNative: true }),
|
||||
});
|
||||
it("keeps recent native workspaces warm and evicts the least recently used workspace", () => {
|
||||
let entries = [retained("A", null)];
|
||||
const visit = (workspaceId: string, now: number) => {
|
||||
entries = reconcileRetainedWorkspaceSelections({
|
||||
currentEntries: entries,
|
||||
activeSelection: workspace(workspaceId),
|
||||
now,
|
||||
maxMountedWorkspaces: resolveWorkspaceDeckRetentionLimit({ isNative: true }),
|
||||
});
|
||||
return retainedWorkspaceIds(entries);
|
||||
};
|
||||
|
||||
expect(retainedWorkspaceIds(entries)).toEqual(["B"]);
|
||||
expect(visit("B", 1)).toEqual(["B", "A"]);
|
||||
expect(visit("C", 2)).toEqual(["C", "B", "A"]);
|
||||
expect(visit("A", 3)).toEqual(["A", "C", "B"]);
|
||||
expect(visit("D", 4)).toEqual(["D", "A", "C"]);
|
||||
expect(visit("A", 5)).toEqual(["A", "D", "C"]);
|
||||
expect(visit("E", 6)).toEqual(["E", "A", "D"]);
|
||||
});
|
||||
|
||||
it("retains the desktop deck limit on web", () => {
|
||||
@@ -179,9 +188,23 @@ describe("resolveWorkspaceDeckEntries", () => {
|
||||
});
|
||||
|
||||
describe("shouldKeepWorkspaceDeckEntryMounted", () => {
|
||||
it("tears down native sheet owners when leaving, while keeping the active sheet mounted", () => {
|
||||
for (const isActive of [true, false]) {
|
||||
expect(
|
||||
shouldKeepWorkspaceDeckEntryMounted({
|
||||
isActive,
|
||||
hasOpenNativeSheets: true,
|
||||
hasHydratedWorkspaces: true,
|
||||
workspaceExists: true,
|
||||
}),
|
||||
).toBe(isActive);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps the active workspace mounted even when it is missing from hydrated workspaces", () => {
|
||||
expect(
|
||||
shouldKeepWorkspaceDeckEntryMounted({
|
||||
hasOpenNativeSheets: false,
|
||||
isActive: true,
|
||||
hasHydratedWorkspaces: true,
|
||||
workspaceExists: false,
|
||||
@@ -192,6 +215,7 @@ describe("shouldKeepWorkspaceDeckEntryMounted", () => {
|
||||
it("keeps inactive workspaces mounted until workspace hydration finishes", () => {
|
||||
expect(
|
||||
shouldKeepWorkspaceDeckEntryMounted({
|
||||
hasOpenNativeSheets: false,
|
||||
isActive: false,
|
||||
hasHydratedWorkspaces: false,
|
||||
workspaceExists: false,
|
||||
@@ -202,6 +226,7 @@ describe("shouldKeepWorkspaceDeckEntryMounted", () => {
|
||||
it("unmounts inactive workspaces that are gone after hydration", () => {
|
||||
expect(
|
||||
shouldKeepWorkspaceDeckEntryMounted({
|
||||
hasOpenNativeSheets: false,
|
||||
isActive: false,
|
||||
hasHydratedWorkspaces: true,
|
||||
workspaceExists: false,
|
||||
@@ -212,6 +237,7 @@ describe("shouldKeepWorkspaceDeckEntryMounted", () => {
|
||||
it("keeps inactive workspaces that still exist after hydration", () => {
|
||||
expect(
|
||||
shouldKeepWorkspaceDeckEntryMounted({
|
||||
hasOpenNativeSheets: false,
|
||||
isActive: false,
|
||||
hasHydratedWorkspaces: true,
|
||||
workspaceExists: true,
|
||||
|
||||
@@ -9,7 +9,9 @@ export interface RetainedWorkspaceSelection {
|
||||
}
|
||||
|
||||
export function resolveWorkspaceDeckRetentionLimit(input: { isNative: boolean }): number {
|
||||
return input.isNative ? 1 : WORKSPACE_DECK_MAX_MOUNTED_WORKSPACES;
|
||||
// Keep recent switches warm without retaining the desktop-sized set of
|
||||
// native chat trees. Reconciliation evicts the least recently used entry.
|
||||
return input.isNative ? 3 : WORKSPACE_DECK_MAX_MOUNTED_WORKSPACES;
|
||||
}
|
||||
|
||||
interface ReconcileRetainedWorkspaceSelectionsInput {
|
||||
@@ -28,6 +30,7 @@ interface GetNextWorkspaceDeckExpirationDelayInput {
|
||||
}
|
||||
|
||||
interface WorkspaceDeckEntryMountInput {
|
||||
hasOpenNativeSheets: boolean;
|
||||
isActive: boolean;
|
||||
hasHydratedWorkspaces: boolean;
|
||||
workspaceExists: boolean;
|
||||
@@ -159,6 +162,7 @@ export function resolveWorkspaceDeckEntries({
|
||||
}
|
||||
|
||||
export function shouldKeepWorkspaceDeckEntryMounted({
|
||||
hasOpenNativeSheets,
|
||||
isActive,
|
||||
hasHydratedWorkspaces,
|
||||
workspaceExists,
|
||||
@@ -166,6 +170,9 @@ export function shouldKeepWorkspaceDeckEntryMounted({
|
||||
if (isActive) {
|
||||
return true;
|
||||
}
|
||||
// Native sheets can present on the app-wide host. Preserve their existing
|
||||
// teardown on navigation until the sheet stack supports inactive owners.
|
||||
if (hasOpenNativeSheets) return false;
|
||||
if (!hasHydratedWorkspaces) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user