mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-24 02:02:42 +00:00
* fix(app): give Markdown and HTML file tabs back their Preview and Source views The built-in Markdown and HTML panels own one toolbar again: file size, line count, save status, vim mode, cursor, and a Preview | Source control over a body that shows the rendered preview or the editor from the same loaded content and editor model. Plain text files keep the toolbar on top. The host no longer renders a panel switcher. Source is the built-in panel for text files no other built-in claims, so it is never offered beside Markdown or HTML in the picker, the Open with menu, or Settings > Files. A line target opens the file's built-in panel in its Source view. * refactor(app): name the shared text file panel TextFilePanel Markdown and HTML own a Source view; they are not Source panels. The composite in file-panels/source/panel.tsx is now TextFilePanel, and SourcePanel is TextFilePanel without a Preview. Names only.
77 lines
3.2 KiB
TypeScript
77 lines
3.2 KiB
TypeScript
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { expect, type Page } from "@playwright/test";
|
|
import { pluginRequirements } from "./plugin-fixture";
|
|
import { connectNewWorkspaceDaemonClient } from "./new-workspace";
|
|
import { expectFileTabOpen, openFileFromExplorer } from "./file-explorer";
|
|
|
|
/** A directory plugin whose "Rich Markdown" file panel claims `.md`, next to the built-in. */
|
|
export const MARKDOWN_PANEL_PLUGIN_ID = "file-panel-picker-e2e";
|
|
export const MARKDOWN_PANEL_ID = `plugin:${MARKDOWN_PANEL_PLUGIN_ID}/rich-markdown`;
|
|
export const BUILTIN_MARKDOWN_OPTION = "Markdown — Paseo";
|
|
export const PLUGIN_MARKDOWN_OPTION = `Rich Markdown — ${MARKDOWN_PANEL_PLUGIN_ID}`;
|
|
|
|
const SOURCE = `import React from "react";
|
|
import { Text, View } from "react-native";
|
|
function RichMarkdown({ file }) {
|
|
return <View><Text>Rich Markdown plugin: {file.name}</Text></View>;
|
|
}
|
|
export default function contribute(client) {
|
|
client.addFilePanel({ id: "rich-markdown", title: "Rich Markdown", icon: "FileType",
|
|
files: { extensions: ["md"] }, Component: RichMarkdown });
|
|
return () => {};
|
|
}`;
|
|
|
|
/** Enables plugins on the test daemon and installs the plugin; `uninstall` restores both. */
|
|
export async function installMarkdownPanelPlugin(): Promise<{ uninstall(): Promise<void> }> {
|
|
const directory = await mkdtemp(path.join(tmpdir(), "paseo-markdown-file-panel-"));
|
|
const client = await connectNewWorkspaceDaemonClient({ ownProjects: false });
|
|
const previousConfig = await client.getDaemonConfig();
|
|
const uninstall = async () => {
|
|
await client.removePlugin(MARKDOWN_PANEL_PLUGIN_ID);
|
|
await client.patchDaemonConfig({
|
|
pluginsEnabled: previousConfig.config.pluginsEnabled ?? false,
|
|
});
|
|
await client.close();
|
|
await rm(directory, { recursive: true, force: true });
|
|
};
|
|
try {
|
|
await writeFile(
|
|
path.join(directory, "paseo-plugin.json"),
|
|
JSON.stringify({ id: MARKDOWN_PANEL_PLUGIN_ID, requirements: pluginRequirements }),
|
|
);
|
|
await writeFile(path.join(directory, "index.client.tsx"), SOURCE);
|
|
await client.patchDaemonConfig({ pluginsEnabled: true });
|
|
await client.installDirectoryPlugin(directory);
|
|
} catch (error) {
|
|
await uninstall();
|
|
throw error;
|
|
}
|
|
return { uninstall };
|
|
}
|
|
|
|
export function filePanelPicker(page: Page) {
|
|
return page.getByText("Open .md files with", { exact: true });
|
|
}
|
|
|
|
export async function openMarkdown(page: Page, name: string): Promise<void> {
|
|
await openFileFromExplorer(page, name);
|
|
await expectFileTabOpen(page, name);
|
|
}
|
|
|
|
export async function expectBuiltinMarkdown(page: Page, heading: string): Promise<void> {
|
|
await expect(page.getByRole("heading", { name: heading, exact: true })).toBeVisible();
|
|
}
|
|
|
|
export async function expectPluginMarkdown(page: Page, name: string): Promise<void> {
|
|
await expect(page.getByText(`Rich Markdown plugin: ${name}`, { exact: true })).toBeVisible();
|
|
}
|
|
|
|
export async function storedFilePanelAssociations(page: Page): Promise<unknown> {
|
|
return page.evaluate(() => {
|
|
const settings = JSON.parse(localStorage.getItem("@paseo:app-settings") ?? "{}");
|
|
return settings.filePanelAssociations ?? {};
|
|
});
|
|
}
|