feat: add support for disabling specific features in the PDF Editor
This commit is contained in:
@@ -4,6 +4,7 @@ import { showAlert, showLoader, hideLoader } from '../ui.js';
|
||||
import { formatBytes, downloadFile } from '../utils/helpers.js';
|
||||
import { makeUniqueFileKey } from '../utils/deduplicate-filename.js';
|
||||
import { batchDecryptIfNeeded } from '../utils/password-prompt.js';
|
||||
import { getEditorDisabledCategories } from '../utils/disabled-tools.js';
|
||||
|
||||
const embedPdfWasmUrl = new URL(
|
||||
'embedpdf-snippet/dist/pdfium.wasm',
|
||||
@@ -130,7 +131,9 @@ async function handleFiles(files: FileList) {
|
||||
pdfWrapper.classList.remove('hidden');
|
||||
|
||||
const { default: EmbedPDF } = await import('embedpdf-snippet');
|
||||
const disabledCategories = getEditorDisabledCategories();
|
||||
viewerInstance = EmbedPDF.init({
|
||||
disabledCategories,
|
||||
type: 'container',
|
||||
target: pdfContainer,
|
||||
worker: true,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export interface AppConfig {
|
||||
disabledTools?: string[];
|
||||
editorDisabledCategories?: string[];
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { AppConfig } from '@/types';
|
||||
|
||||
const disabledToolsSet = new Set<string>(__DISABLED_TOOLS__);
|
||||
let runtimeConfigLoaded = false;
|
||||
let editorDisabledCategories: string[] = [];
|
||||
|
||||
export async function loadRuntimeConfig(): Promise<void> {
|
||||
if (runtimeConfigLoaded) return;
|
||||
@@ -21,6 +22,11 @@ export async function loadRuntimeConfig(): Promise<void> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(config.editorDisabledCategories)) {
|
||||
editorDisabledCategories = config.editorDisabledCategories.filter(
|
||||
(c): c is string => typeof c === 'string'
|
||||
);
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
@@ -36,6 +42,10 @@ export function getToolIdFromPath(): string | null {
|
||||
return withoutExt?.[1] ?? null;
|
||||
}
|
||||
|
||||
export function getEditorDisabledCategories(): string[] {
|
||||
return editorDisabledCategories;
|
||||
}
|
||||
|
||||
export function isCurrentPageDisabled(): boolean {
|
||||
const toolId = getToolIdFromPath();
|
||||
if (!toolId) return false;
|
||||
|
||||
Reference in New Issue
Block a user