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,9 +1,9 @@
|
||||
// A feature in the workbench of one window. Its views and commands come from the static catalog, so the
|
||||
// navigation buttons and the command palette show them without the feature code. The first mount,
|
||||
// A feature in the workbench of one window. Its views, commands, and document types come from the static catalog, so the
|
||||
// navigation buttons, the command palette, and the file tree show them without the feature code. The first mount,
|
||||
// restore, or action command loads the feature module and starts one instance for this window.
|
||||
// A launch rule (`launch.ts`) can also start the instance at once.
|
||||
import { tr } from "../i18n/index.ts";
|
||||
import type { Dispose, PluginCommand, PluginDocumentType, PluginView } from "../plugins/sdk.ts";
|
||||
import type { Dispose, PluginCommand, PluginDocumentContext, PluginDocumentType, PluginView } from "../plugins/sdk.ts";
|
||||
import type { FeatureEntry } from "./catalog.ts";
|
||||
import { loadFeature } from "./loader.ts";
|
||||
import type { FeatureContext, FeatureInstance, FeatureModule } from "./types.ts";
|
||||
@@ -32,6 +32,13 @@ export class FeatureSession {
|
||||
restoreTabState: async state => { await (await this.running()).restoreTabState?.(info.id, state); },
|
||||
});
|
||||
}
|
||||
for (const info of entry.documentTypes) {
|
||||
this.documentTypes.set(info.id, {
|
||||
id: info.id, get title() { return info.title(); }, icon: info.icon, extensions: [...info.extensions], content: info.content,
|
||||
identify: (path, source) => info.identify(path, source),
|
||||
mount: (element, document) => this.mountDocument(info.id, element, document),
|
||||
});
|
||||
}
|
||||
for (const info of entry.commands) {
|
||||
const view = info.view;
|
||||
this.commands.set(info.id, { id: info.id, get title() { return info.title(); }, icon: info.icon,
|
||||
@@ -53,10 +60,17 @@ export class FeatureSession {
|
||||
return (await this.running()).mount(id, element);
|
||||
}
|
||||
|
||||
async mount(id: string, element: HTMLElement): Promise<Dispose> {
|
||||
const view = this.views.get(id);
|
||||
private async mountDocument(type: string, element: HTMLElement, document: PluginDocumentContext): Promise<Dispose> {
|
||||
const instance = await this.running();
|
||||
if (!instance.mountDocument) throw new Error(tr("This view is unavailable."));
|
||||
return instance.mountDocument(type, element, document);
|
||||
}
|
||||
|
||||
/** Mount a view, or with `document`, a document of the document type `id`. */
|
||||
async mount(id: string, element: HTMLElement, document?: PluginDocumentContext): Promise<Dispose> {
|
||||
const view = document ? this.documentTypes.get(id) : this.views.get(id);
|
||||
if (!view) throw new Error(tr("This view is unavailable."));
|
||||
const dispose = await view.mount(element);
|
||||
const dispose = document ? await (view as PluginDocumentType).mount(element, document) : await (view as PluginView).mount(element, { surface: "view" });
|
||||
return async () => {
|
||||
if (typeof dispose === "function") await dispose();
|
||||
element.replaceChildren();
|
||||
|
||||
Reference in New Issue
Block a user