Make PDF Viewer a native feature
- Move the PDF Viewer plugin into src/lib/features/pdf/ with pdfjs-dist 6.4.299 (minified builds). - A static pdf document type marks PDF files and opens them as tabs. The first PDF tab loads the module. - The worker, the character maps, the fonts, and the decoders come from the app. One worker for each tab. - The toolbar uses IconButton and the shared tooltip, with the new zoom-in, zoom-out, fit-width, and rotate icons. - Add THIRD_PARTY_NOTICES.md for PDF.js and xterm. - Update the tests, the menu inventory, the docs, and UI-059.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
// 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, and commands.
|
||||
// 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, PluginView } from "../plugins/sdk.ts";
|
||||
import type { PluginCommand, PluginDocumentType, PluginView } from "../plugins/sdk.ts";
|
||||
import { identifyPdf } from "./pdfDocument.ts";
|
||||
|
||||
export type FeatureId = "git" | "background" | "terminal";
|
||||
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 {
|
||||
@@ -26,6 +27,23 @@ export interface FeatureCommandInfo {
|
||||
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<PluginDocumentType["icon"]>;
|
||||
/** 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. */
|
||||
@@ -41,6 +59,7 @@ export interface FeatureEntry {
|
||||
followsPackage: boolean;
|
||||
views: readonly FeatureViewInfo[];
|
||||
commands: readonly FeatureCommandInfo[];
|
||||
documentTypes: readonly FeatureDocumentInfo[];
|
||||
}
|
||||
|
||||
export const FEATURES: readonly FeatureEntry[] = [
|
||||
@@ -55,6 +74,7 @@ export const FEATURES: readonly FeatureEntry[] = [
|
||||
{ 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
|
||||
@@ -68,6 +88,7 @@ export const FEATURES: readonly FeatureEntry[] = [
|
||||
{ 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
|
||||
@@ -78,6 +99,20 @@ export const FEATURES: readonly FeatureEntry[] = [
|
||||
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 },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user