// The native features of RuneStone. Each feature has an off switch in Settings → Features. // This file is in the main bundle, so it holds only small static data: names, views, commands, and document types. // The code of a feature loads with a dynamic import at first need (see `loader.ts`), and never while its switch is off. import { message, tr } from "../i18n/index.ts"; import type { PluginCommand, PluginDocumentType, PluginView } from "../plugins/sdk.ts"; import { identifyPdf } from "./pdfDocument.ts"; export type FeatureId = "git" | "background" | "terminal" | "pdf"; /** A view of a feature. The workbench shows it as a tab or in the side pane, as it shows a plugin view. */ export interface FeatureViewInfo { id: string; /** Returns the title in the current language. */ title: () => string; placement: "editor" | "sidebar"; icon?: PluginView["icon"]; /** Show a navigation button for the view. */ navigation?: boolean; } /** A command of a feature. The command palette lists it. */ export interface FeatureCommandInfo { id: string; title: () => string; icon?: PluginCommand["icon"]; /** The view that the command opens. Without a view, the command loads the feature and calls `FeatureInstance.run`. */ view?: string; } /** * A document type of a feature. The file tree marks the files of the type, and a click opens them in a tab, * without the feature code. The first tab of the type loads the feature and calls `FeatureInstance.mountDocument`. */ export interface FeatureDocumentInfo { id: string; /** Returns the title in the current language. The file tree shows it as the tooltip of the file icon. */ title: () => string; icon: NonNullable; /** Lowercase file extensions without the dot. */ extensions: readonly string[]; /** "binary" when `identify` needs no file contents. */ content: "text" | "binary"; /** The document ID of a file, or null when the file is not of this type. */ identify(path: string, source: string): { id: string } | null; } export interface FeatureEntry { id: FeatureId; /** The ID of the old plugin package. Saved tabs and tab transfers keep it as the owner ID. */ owner: string; /** Catalog keys for Settings → Features. */ name: string; description: string; /** Extra words for the Settings search. */ keywords: string; /** The switch for a user who never installed the old package. */ defaultOn: boolean; /** True when the first start gives the switch the state of the old package. False when every user gets `defaultOn`. */ followsPackage: boolean; views: readonly FeatureViewInfo[]; commands: readonly FeatureCommandInfo[]; documentTypes: readonly FeatureDocumentInfo[]; } export const FEATURES: readonly FeatureEntry[] = [ { id: "git", owner: "runestone.git", name: message("Git"), description: message("Review changes, stage files, commit, and see the commit graph of the workspace repository."), keywords: "git source control commit stage diff graph branch push pull blame", defaultOn: true, followsPackage: true, views: [ { id: "source-control", title: () => tr("Source control"), placement: "sidebar", icon: "git", navigation: true }, { id: "diff", title: () => tr("Git diff"), placement: "editor", icon: "git" }, { id: "graph", title: () => tr("Git graph"), placement: "editor", icon: "git" }, ], commands: [{ id: "graph", title: () => tr("Show Git graph"), icon: "git", view: "graph" }], documentTypes: [], }, { // Background replaces the Background Slideshow plugin and the background image of Appearance. Its settings are in // Appearance → Background. It loads at the start only when a folder or an image is selected (see `launch.ts`). id: "background", owner: "runestone.bg-slideshow", name: message("Background"), description: message("Show a folder of images as a slideshow, or one image, behind the workspace and the boards."), keywords: "background image wallpaper slideshow folder picture photo overlay blur", defaultOn: true, followsPackage: false, views: [], commands: [ { id: "next", title: () => tr("Next background image"), icon: "image" }, { id: "pause", title: () => tr("Pause background"), icon: "pause" }, ], documentTypes: [], }, { // Terminal replaces the Terminal plugin. Its panel is not a view: the workbench and the terminal window show it // (`src/lib/features/TerminalHost.svelte`), and the first use loads the module. Its settings are in Settings → Terminal. id: "terminal", owner: "runestone.terminal", name: message("Terminal"), description: message("Run shells, tasks, and the active file in a panel below the editor or in a separate window."), keywords: "terminal shell console powershell bash cmd command prompt task run pty xterm", defaultOn: true, followsPackage: true, views: [], commands: [], documentTypes: [], }, { // PDF Viewer replaces the PDF Viewer plugin. It has no view: its document type opens each PDF file in its own tab. // The file tree marks PDF files without the module. The first PDF tab loads the module and PDF.js. id: "pdf", owner: "runestone.pdf-viewer", name: message("PDF Viewer"), description: message("Read PDF files of the workspace in tabs, with page controls, zoom, rotation, and text selection."), keywords: "pdf document viewer page zoom rotate password pdf.js", defaultOn: true, followsPackage: true, views: [], commands: [], documentTypes: [ { id: "pdf", title: () => tr("PDF document"), icon: "file", extensions: ["pdf"], content: "binary", identify: identifyPdf }, ], }, ]; export function featureEntry(id: FeatureId): FeatureEntry { const entry = FEATURES.find(item => item.id === id); if (!entry) throw new Error(`Unknown feature: ${id}`); return entry; } /** The feature that uses `owner` as its owner ID, if any. */ export function featureOfOwner(owner: string): FeatureEntry | undefined { return FEATURES.find(item => item.owner === owner); }