mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-02 22:52:58 +00:00
* fix(files): report document MIME types for binary files File reads now carry the document's MIME type for binary files, so a file panel can hand the bytes to a viewer that needs the real type (application/pdf). * feat(plugins): file panels Plugins contribute file panels with addFilePanel. A file tab hosts the panels that claim the file: the built-in Markdown, HTML and image panels, plugin panels, and Source, Paseo's editor, which claims every text file and is always the last candidate. The panel is the tab body; the bar shows the document's status and a switcher between the file's panels (side by side up to three, two on a phone, a menu beyond that). Paseo asks which panel opens a file only when a plugin panel is among several candidates, once per open, and remembers the answer per extension or exact filename when told to. Open with in the tab menu and the switcher change the tab's panel; Always use remembers it. Opening a file at a line switches the tab to Source. Panels read and write the host's document, so dirty state, autosave and conflicts stay Paseo's. DocumentFrame shows bytes documents such as PDFs in the browser's viewer. Replaces the file tab's Preview/Source mode toggle. * feat(file-panels): choose and forget file panels in Settings > Files Settings > Files lists each extension or filename where a plugin panel competes with another candidate, or that has a remembered panel. Each row chooses the panel that opens it, or Ask every time; Ask again forgets the choice. Source appears as a candidate for text files. Panels no connected host offers can be forgotten but not chosen. * docs(plugins): file panel examples and author reference Adds the pdf-panel and markdown-panel examples, the File panels section of the plugin reference, and an e2e spec that installs both examples, opens a PDF in the browser viewer, and edits Markdown through Paseo's document across the switcher, Source, autosave and conflicts. * feat(file-panels): panels read and write through a file handle The file tab stats the file and mounts its panel without reading it. Every panel, built-in or plugin, gets a PluginFile handle: readText, readBytes, url, version-checked writeText/writeBytes (PluginFileConflictError unless force), and watch. useFileText, useFileBytes and useFileUrl read through it, and Loading joins @getpaseo/plugin/client/ui. Panels own their loading state. The host document pipeline, the explorer preview cache and the preview lifecycle are deleted. The daemon classifies a file version from a bounded sniff and writes base64 content as bytes behind fileByteWrites. A deleted file keeps its panel mounted; a read confirms the deletion first, so a remove-and-rewrite is not reported as one. Native Source decodes with builtins and highlights in idle-time slices, the lines around the opening line first, so a large file no longer blocks the JS thread. * fix(file-panels): Settings offers Source where the picker does, and review follow-ups - Settings > Files offers Source on every key except those a built-in panel of another kind (Image) claims, so a plugin that alone claims a text extension shows the same choices as the picker. - Delete the unused isSourceFilePanel. - The Markdown example warns with the file name when its unmount write fails, rather than dropping the edit silently. - Document that PluginFile stat fields are read at render time and that watch or the read hooks are how a panel learns they changed. * refactor(plugin): consolidate the client UI entrypoint
169 lines
6.3 KiB
TypeScript
169 lines
6.3 KiB
TypeScript
import { pluginRequirements } from "../support/helpers/plugin-fixture";
|
|
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { expect, test, type Page } from "../support/fixtures";
|
|
import { gotoAppShell } from "../support/helpers/app";
|
|
import { connectNewWorkspaceDaemonClient } from "../support/helpers/new-workspace";
|
|
|
|
const PLUGIN_ID = "plugin-host-ui-e2e";
|
|
|
|
const PLUGIN_SOURCE = `import { usePaseo } from "@getpaseo/plugin/client";
|
|
import { Icon, Modal, useToast } from "@getpaseo/plugin/client/ui";
|
|
import { useQueryClient } from "@tanstack/react-query";
|
|
import React, { useState } from "react";
|
|
import { Pressable, Text, View } from "react-native";
|
|
|
|
function ModalBody({ onSaved }) {
|
|
usePaseo();
|
|
useQueryClient();
|
|
const toast = useToast();
|
|
|
|
function save() {
|
|
toast.show("Issue saved", { variant: "success" });
|
|
onSaved();
|
|
}
|
|
|
|
return <View>
|
|
<Text>Plugin modal contexts ready</Text>
|
|
<Pressable accessibilityRole="button" onPress={save}>
|
|
<Text>Save issue</Text>
|
|
</Pressable>
|
|
</View>;
|
|
}
|
|
|
|
function Surface({ playAudio }) {
|
|
const [audioStatus, setAudioStatus] = useState("Audio ready");
|
|
async function play(base64) {
|
|
setAudioStatus("Playing audio");
|
|
try { await playAudio({ base64, mimeType: "audio/wav" }); setAudioStatus("Audio finished"); }
|
|
catch { setAudioStatus("Audio rejected"); }
|
|
}
|
|
const [open, setOpen] = useState(false);
|
|
return <View>
|
|
<Text>{audioStatus}</Text>
|
|
<Pressable accessibilityRole="button" onPress={() => play(AUDIO_BASE64)}><Text>Play plugin audio</Text></Pressable>
|
|
<Pressable accessibilityRole="button" onPress={() => play("UklGRg==")}><Text>Play invalid audio</Text></Pressable>
|
|
<Pressable accessibilityRole="button" onPress={() => setOpen(true)}>
|
|
<View style={{ flexDirection: "row" }}>
|
|
<Icon name="Pencil" size={18} />
|
|
<Text>Open plugin modal</Text>
|
|
</View>
|
|
</Pressable>
|
|
<Modal
|
|
title="Edit plugin issue"
|
|
icon={<Icon name="Pencil" size={18} />}
|
|
open={open}
|
|
onOpenChange={setOpen}
|
|
>
|
|
<Modal.Content>
|
|
<ModalBody onSaved={() => setOpen(false)} />
|
|
</Modal.Content>
|
|
</Modal>
|
|
</View>;
|
|
}
|
|
|
|
export default function contribute(plugin) {
|
|
plugin.addSurface("main", () => <Surface playAudio={plugin.playAudio} />);
|
|
plugin.addSidebarItem({
|
|
id: "main",
|
|
title: "Host UI",
|
|
icon: "PanelsTopLeft",
|
|
surface: "main",
|
|
});
|
|
return () => {};
|
|
}`;
|
|
|
|
async function openHostUiPlugin(page: Page): Promise<void> {
|
|
await gotoAppShell(page);
|
|
await page.getByRole("button", { name: "Host UI", exact: true }).click();
|
|
}
|
|
|
|
async function useNonCompactLayout(page: Page): Promise<void> {
|
|
await page.setViewportSize({ width: 1100, height: 800 });
|
|
}
|
|
|
|
async function useCompactLayout(page: Page): Promise<void> {
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
}
|
|
|
|
async function openPluginModal(page: Page): Promise<void> {
|
|
await page.getByRole("button", { name: "Open plugin modal", exact: true }).click();
|
|
}
|
|
|
|
async function expectCenteredPluginDialog(page: Page): Promise<void> {
|
|
const dialog = page.getByRole("dialog");
|
|
await expect(dialog.getByText("Edit plugin issue", { exact: true })).toBeVisible();
|
|
await expect(dialog.getByText("Plugin modal contexts ready", { exact: true })).toBeVisible();
|
|
}
|
|
|
|
async function closeCenteredPluginDialog(page: Page): Promise<void> {
|
|
const dialog = page.getByRole("dialog");
|
|
await dialog.getByRole("button", { name: "Close", exact: true }).click();
|
|
await expect(dialog).not.toBeVisible();
|
|
}
|
|
|
|
async function expectCompactPluginSheet(page: Page): Promise<void> {
|
|
await expect(page.getByText("Edit plugin issue", { exact: true })).toBeVisible();
|
|
await expect(page.getByText("Plugin modal contexts ready", { exact: true })).toBeVisible();
|
|
}
|
|
|
|
async function savePluginIssue(page: Page): Promise<void> {
|
|
await page.getByRole("button", { name: "Save issue", exact: true }).click();
|
|
await expect(page.getByText("Issue saved", { exact: true })).toBeVisible();
|
|
await expect(page.getByText("Plugin modal contexts ready", { exact: true })).not.toBeVisible();
|
|
}
|
|
|
|
test("plugin modal adapts its presentation and preserves host contexts", async ({ page }) => {
|
|
const directory = await mkdtemp(path.join(tmpdir(), "paseo-plugin-host-ui-e2e-"));
|
|
const client = await connectNewWorkspaceDaemonClient({ ownProjects: false });
|
|
const previousConfig = await client.getDaemonConfig();
|
|
await writeFile(
|
|
path.join(directory, "paseo-plugin.json"),
|
|
JSON.stringify({ id: PLUGIN_ID, requirements: pluginRequirements }),
|
|
);
|
|
const audio = await readFile(path.resolve(__dirname, "../../assets/audio/thinking-tone.wav"));
|
|
await writeFile(
|
|
path.join(directory, "index.client.tsx"),
|
|
`const AUDIO_BASE64 = ${JSON.stringify(audio.toString("base64"))};\n${PLUGIN_SOURCE}`,
|
|
);
|
|
|
|
try {
|
|
await client.patchDaemonConfig({ pluginsEnabled: true });
|
|
await client.installDirectoryPlugin(directory);
|
|
await useNonCompactLayout(page);
|
|
await openHostUiPlugin(page);
|
|
|
|
await test.step("plugin audio finishes, rejects corrupt files, and recovers", async () => {
|
|
await playPluginAudio(page, "Play plugin audio", "Audio finished");
|
|
await playPluginAudio(page, "Play invalid audio", "Audio rejected");
|
|
await playPluginAudio(page, "Play plugin audio", "Audio finished");
|
|
});
|
|
|
|
await test.step("non-compact layouts use a centered dialog", async () => {
|
|
await openPluginModal(page);
|
|
await expectCenteredPluginDialog(page);
|
|
await closeCenteredPluginDialog(page);
|
|
});
|
|
|
|
await test.step("compact layouts preserve host contexts inside a sheet", async () => {
|
|
await useCompactLayout(page);
|
|
await openPluginModal(page);
|
|
await expectCompactPluginSheet(page);
|
|
await savePluginIssue(page);
|
|
});
|
|
} finally {
|
|
await client.removePlugin(PLUGIN_ID).catch(() => undefined);
|
|
await client
|
|
.patchDaemonConfig({ pluginsEnabled: previousConfig.config.pluginsEnabled ?? false })
|
|
.catch(() => undefined);
|
|
await client.close().catch(() => undefined);
|
|
await rm(directory, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
async function playPluginAudio(page: Page, button: string, result: string) {
|
|
await page.getByRole("button", { name: button, exact: true }).click();
|
|
await expect(page.getByText(result, { exact: true })).toBeVisible();
|
|
}
|