diff --git a/README.md b/README.md index e54f5b6..888bd56 100644 --- a/README.md +++ b/README.md @@ -567,11 +567,12 @@ The widget uses the standard MCP Apps host bridge for tool results, theme variables, display-mode requests, model-context updates, and file downloads. It also reads ChatGPT's initial tool globals when present and uses ChatGPT's file APIs only as a download fallback. Its React UI uses semantic table markup, -global TanStack Table sorting, page-scoped row selection, 100-row client-side -pages, and fine-grained Shiki SQL highlighting for exact ADQL. The table uses a -capped two-axis scroll viewport. An icon-only control in +global TanStack Table sorting, page-scoped row selection, 100-row desktop pages, +10-row mobile pages, and fine-grained Shiki SQL highlighting for exact ADQL. +Desktop tables use a capped two-axis scroll viewport; mobile tables expand to +the page height and retain horizontal scrolling for wide results. An icon-only control in the action toolbar requests fullscreen or inline display mode. Another action -can expose selected rows or the current 100-row page to the model for the next +can expose selected rows or the current page to the model for the next turn; it does not expose the whole loaded table. The action remains available, and each press replaces the previously pending model-context snapshot. The resource declares no network or static-resource domains and requests only diff --git a/apps/mcp-app/web/src/host-ui.test.ts b/apps/mcp-app/web/src/host-ui.test.ts index 8a5792b..c876ca5 100644 --- a/apps/mcp-app/web/src/host-ui.test.ts +++ b/apps/mcp-app/web/src/host-ui.test.ts @@ -25,6 +25,7 @@ describe("StarfetchHostSession", () => { expect(session.getSnapshot()).toMatchObject({ canExpand: true, + isMobile: false, mode: "inline", }); await expect(session.setExpanded(true)).resolves.toBe(true); @@ -57,6 +58,7 @@ describe("StarfetchHostSession", () => { expect(onChange).toHaveBeenCalledOnce(); expect(session.getSnapshot()).toMatchObject({ canExpand: true, + isMobile: false, mode: "fullscreen", }); diff --git a/apps/mcp-app/web/src/host-ui.ts b/apps/mcp-app/web/src/host-ui.ts index 8304966..773a1b5 100644 --- a/apps/mcp-app/web/src/host-ui.ts +++ b/apps/mcp-app/web/src/host-ui.ts @@ -26,6 +26,7 @@ export type StarfetchHostBridge = Readonly<{ export type StarfetchHostSnapshot = Readonly<{ canAnalyze: boolean; canExpand: boolean; + isMobile: boolean; mode: StarfetchDisplayMode; }>; @@ -210,6 +211,7 @@ function createSnapshot( canExpand: context.platform !== "mobile" && (context.availableDisplayModes?.includes("fullscreen") ?? false), + isMobile: context.platform === "mobile", mode: context.displayMode ?? "inline", }; } diff --git a/apps/mcp-app/web/src/paged-results.tsx b/apps/mcp-app/web/src/paged-results.tsx index e4f3c3d..94fe6a9 100644 --- a/apps/mcp-app/web/src/paged-results.tsx +++ b/apps/mcp-app/web/src/paged-results.tsx @@ -29,7 +29,8 @@ import { ResultActions } from "./result-actions.js"; import { ResultNotices } from "./result-details.js"; type TableRow = StarfetchTableViewV1["rows"][number]; -const pageSize = 100; +const desktopPageSize = 100; +const mobilePageSize = 10; export function PagedResults({ host, @@ -50,6 +51,7 @@ export function PagedResults({ (listener) => host.subscribe(listener), () => host.getSnapshot(), ); + const pageSize = hostSnapshot.isMobile ? mobilePageSize : desktopPageSize; const columns = useMemo[]>( () => view.columns.map((column) => ({ @@ -130,6 +132,7 @@ export function PagedResults({
diff --git a/apps/mcp-app/web/src/results-table.test.tsx b/apps/mcp-app/web/src/results-table.test.tsx index 7af723e..94cf4af 100644 --- a/apps/mcp-app/web/src/results-table.test.tsx +++ b/apps/mcp-app/web/src/results-table.test.tsx @@ -239,6 +239,26 @@ describe("ResultsTable", () => { ).toBeNull(); }); + it("paginates mobile results in 10-row pages", async () => { + const user = userEvent.setup(); + render( + , + ); + + expect(screen.getAllByRole("row")).toHaveLength(11); + expect(screen.getByText("Page 1 of 3 · rows 1–10 of 25")).toBeTruthy(); + await user.click(screen.getByRole("button", { name: "Next page" })); + expect(screen.getByText("Page 2 of 3 · rows 11–20 of 25")).toBeTruthy(); + }); + it("paginates the globally sorted table in 100-row pages", async () => { const user = userEvent.setup(); render(); diff --git a/apps/mcp-app/web/src/styles.css b/apps/mcp-app/web/src/styles.css index 68c8806..6efe4a2 100644 --- a/apps/mcp-app/web/src/styles.css +++ b/apps/mcp-app/web/src/styles.css @@ -294,8 +294,10 @@ h3 { max-width: 100%; max-height: min(52vh, 420px); overflow: auto; + -webkit-overflow-scrolling: touch; overscroll-behavior: contain; scrollbar-gutter: stable; + touch-action: pan-x pan-y; border: 1px solid var(--sf-border); border-radius: var(--sf-radius); } @@ -305,6 +307,15 @@ h3 { overflow: auto; } +.table-scroll[data-mobile="true"] { + max-height: none; + overflow-x: auto; + overflow-y: clip; + overscroll-behavior-x: contain; + overscroll-behavior-y: auto; + scrollbar-gutter: auto; +} + table { width: max-content; min-width: 100%; diff --git a/apps/mcp-app/web/tests/widget.spec.ts b/apps/mcp-app/web/tests/widget.spec.ts index 9d97b5c..37bd365 100644 --- a/apps/mcp-app/web/tests/widget.spec.ts +++ b/apps/mcp-app/web/tests/widget.spec.ts @@ -128,6 +128,85 @@ test("keeps mobile hosts inline instead of exposing a broken fullscreen path", a ).toBeVisible(); }); +test("uses short pages and horizontal touch scrolling inside mobile hosts", async ({ + page, +}, testInfo) => { + test.skip(testInfo.project.name !== "mobile-chromium"); + + await page.goto("/test-host.html?mobile=1"); + const widget = page.frameLocator("iframe[title='Starfetch widget']"); + const scrollViewport = widget.locator(".table-scroll"); + await expect( + widget.getByRole("table", { name: "Gaia source results" }), + ).toBeVisible(); + await expect(widget.locator("tbody tr")).toHaveCount(10); + await expect( + widget.getByText("Page 1 of 10 · rows 1–10 of 100"), + ).toBeVisible(); + + const viewport = await scrollViewport.evaluate((element) => { + const computed = getComputedStyle(element); + return { + clientHeight: element.clientHeight, + overflowY: computed.overflowY, + scrollHeight: element.scrollHeight, + scrollWidth: element.scrollWidth, + clientWidth: element.clientWidth, + touchAction: computed.touchAction, + }; + }); + expect(viewport.touchAction).toBe("pan-x pan-y"); + expect(viewport.overflowY).toBe("hidden"); + expect(viewport.scrollHeight).toBe(viewport.clientHeight); + expect(viewport.scrollWidth).toBeGreaterThan(viewport.clientWidth); + const html = await readFile( + new URL("../dist/index.html", import.meta.url), + "utf8", + ); + expect(html).toContain("-webkit-overflow-scrolling:touch"); + + const bounds = await scrollViewport.boundingBox(); + expect(bounds).not.toBeNull(); + if (bounds === null) return; + + const touch = await page.context().newCDPSession(page); + const start = { + x: bounds.x + bounds.width * 0.75, + y: bounds.y + bounds.height * 0.5, + }; + await touch.send("Input.dispatchTouchEvent", { + touchPoints: [start], + type: "touchStart", + }); + await touch.send("Input.dispatchTouchEvent", { + touchPoints: [{ x: start.x - 80, y: start.y }], + type: "touchMove", + }); + await touch.send("Input.dispatchTouchEvent", { + touchPoints: [{ x: start.x - 160, y: start.y }], + type: "touchMove", + }); + await touch.send("Input.dispatchTouchEvent", { + touchPoints: [], + type: "touchEnd", + }); + + await expect + .poll(() => + scrollViewport.evaluate((element) => ({ + left: element.scrollLeft, + top: element.scrollTop, + })), + ) + .toMatchObject({ left: expect.any(Number), top: expect.any(Number) }); + const scrollPosition = await scrollViewport.evaluate((element) => ({ + left: element.scrollLeft, + top: element.scrollTop, + })); + expect(scrollPosition.left).toBeGreaterThan(0); + expect(scrollPosition.top).toBe(0); +}); + test("supports keyboard actions, host downloads, and table expansion", async ({ context, page,