[editor] Introduce a proper annotationEditorMode
option/preference (PR 15075 follow-up)
This replaces the boolean `annotationEditorEnabled` option/preference with a "proper" `annotationEditorMode` one. This way it's not only possible for the user to control if Editing is enabled/disabled, but also which *specific* Editing-mode should become enabled upon PDF document load. Given that Editing is not enabled/released yet, I cannot imagine that changing the name and type of the option/preference should be an issue.
This commit is contained in:
parent
f1d4015508
commit
4a4c6b9851
@ -160,9 +160,9 @@
|
||||
],
|
||||
"default": 2
|
||||
},
|
||||
"annotationEditorEnabled": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
"annotationEditorMode": {
|
||||
"type": "integer",
|
||||
"default": -1
|
||||
},
|
||||
"enablePermissions": {
|
||||
"type": "boolean",
|
||||
|
@ -55,6 +55,7 @@ const AnnotationMode = {
|
||||
const AnnotationEditorPrefix = "pdfjs_internal_editor_";
|
||||
|
||||
const AnnotationEditorType = {
|
||||
DISABLE: -1,
|
||||
NONE: 0,
|
||||
FREETEXT: 3,
|
||||
INK: 15,
|
||||
|
11
web/app.js
11
web/app.js
@ -34,9 +34,8 @@ import {
|
||||
SpreadMode,
|
||||
TextLayerMode,
|
||||
} from "./ui_utils.js";
|
||||
import { AppOptions, OptionKind } from "./app_options.js";
|
||||
import { AutomationEventBus, EventBus } from "./event_utils.js";
|
||||
import {
|
||||
AnnotationEditorType,
|
||||
build,
|
||||
createPromiseCapability,
|
||||
getDocument,
|
||||
@ -54,6 +53,8 @@ import {
|
||||
UNSUPPORTED_FEATURES,
|
||||
version,
|
||||
} from "pdfjs-lib";
|
||||
import { AppOptions, OptionKind } from "./app_options.js";
|
||||
import { AutomationEventBus, EventBus } from "./event_utils.js";
|
||||
import { CursorTool, PDFCursorTools } from "./pdf_cursor_tools.js";
|
||||
import { LinkTarget, PDFLinkService } from "./pdf_link_service.js";
|
||||
import { AnnotationEditorParams } from "./annotation_editor_params.js";
|
||||
@ -510,7 +511,7 @@ const PDFViewerApplication = {
|
||||
|
||||
const container = appConfig.mainContainer,
|
||||
viewer = appConfig.viewerContainer;
|
||||
const annotationEditorEnabled = AppOptions.get("annotationEditorEnabled");
|
||||
const annotationEditorMode = AppOptions.get("annotationEditorMode");
|
||||
const pageColors = {
|
||||
background: AppOptions.get("pageColorsBackground"),
|
||||
foreground: AppOptions.get("pageColorsForeground"),
|
||||
@ -534,7 +535,7 @@ const PDFViewerApplication = {
|
||||
l10n: this.l10n,
|
||||
textLayerMode: AppOptions.get("textLayerMode"),
|
||||
annotationMode: AppOptions.get("annotationMode"),
|
||||
annotationEditorEnabled,
|
||||
annotationEditorMode,
|
||||
imageResourcesPath: AppOptions.get("imageResourcesPath"),
|
||||
enablePrintAutoRotate: AppOptions.get("enablePrintAutoRotate"),
|
||||
useOnlyCssZoom: AppOptions.get("useOnlyCssZoom"),
|
||||
@ -570,7 +571,7 @@ const PDFViewerApplication = {
|
||||
this.findBar = new PDFFindBar(appConfig.findBar, eventBus, this.l10n);
|
||||
}
|
||||
|
||||
if (annotationEditorEnabled) {
|
||||
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
|
||||
this.annotationEditorParams = new AnnotationEditorParams(
|
||||
appConfig.annotationEditorParams,
|
||||
eventBus
|
||||
|
@ -59,11 +59,12 @@ const OptionKind = {
|
||||
* primitive types and cannot rely on any imported types.
|
||||
*/
|
||||
const defaultOptions = {
|
||||
annotationEditorEnabled: {
|
||||
annotationEditorMode: {
|
||||
/** @type {boolean} */
|
||||
value:
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING"),
|
||||
typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || TESTING")
|
||||
? 0
|
||||
: -1,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
annotationMode: {
|
||||
|
@ -86,7 +86,10 @@ const PagesCountLimit = {
|
||||
};
|
||||
|
||||
function isValidAnnotationEditorMode(mode) {
|
||||
return Object.values(AnnotationEditorType).includes(mode);
|
||||
return (
|
||||
Object.values(AnnotationEditorType).includes(mode) &&
|
||||
mode !== AnnotationEditorType.DISABLE
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,8 +116,9 @@ function isValidAnnotationEditorMode(mode) {
|
||||
* being rendered. The constants from {@link AnnotationMode} should be used;
|
||||
* see also {@link RenderParameters} and {@link GetOperatorListParameters}.
|
||||
* The default value is `AnnotationMode.ENABLE_FORMS`.
|
||||
* @property {boolean} [annotationEditorEnabled] - Enables the creation and
|
||||
* editing of new Annotations.
|
||||
* @property {boolean} [annotationEditorMode] - Enables the creation and editing
|
||||
* of new Annotations. The constants from {@link AnnotationEditorType} should
|
||||
* be used. The default value is `AnnotationEditorType.DISABLE`.
|
||||
* @property {string} [imageResourcesPath] - Path for image resources, mainly
|
||||
* mainly for annotation icons. Include trailing slash.
|
||||
* @property {boolean} [enablePrintAutoRotate] - Enables automatic rotation of
|
||||
@ -213,7 +217,7 @@ class PDFPageViewBuffer {
|
||||
class BaseViewer {
|
||||
#buffer = null;
|
||||
|
||||
#annotationEditorMode = AnnotationEditorType.NONE;
|
||||
#annotationEditorMode = AnnotationEditorType.DISABLE;
|
||||
|
||||
#annotationEditorUIManager = null;
|
||||
|
||||
@ -273,9 +277,8 @@ class BaseViewer {
|
||||
this.textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
|
||||
this.#annotationMode =
|
||||
options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
|
||||
this.#annotationEditorMode = options.annotationEditorEnabled
|
||||
? AnnotationEditorType.NONE
|
||||
: null;
|
||||
this.#annotationEditorMode =
|
||||
options.annotationEditorMode ?? AnnotationEditorType.DISABLE;
|
||||
this.imageResourcesPath = options.imageResourcesPath || "";
|
||||
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
|
||||
this.renderer = options.renderer || RendererType.CANVAS;
|
||||
@ -560,7 +563,7 @@ class BaseViewer {
|
||||
}
|
||||
|
||||
if (!permissions.includes(PermissionFlag.MODIFY_CONTENTS)) {
|
||||
params.annotationEditorMode = null;
|
||||
params.annotationEditorMode = AnnotationEditorType.DISABLE;
|
||||
}
|
||||
|
||||
if (
|
||||
@ -710,19 +713,26 @@ class BaseViewer {
|
||||
const { annotationEditorMode, annotationMode, textLayerMode } =
|
||||
this.#initializePermissions(permissions);
|
||||
|
||||
if (annotationEditorMode !== null) {
|
||||
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
|
||||
const mode = annotationEditorMode;
|
||||
|
||||
if (isPureXfa) {
|
||||
console.warn("Warning: XFA-editing is not implemented.");
|
||||
} else {
|
||||
} else if (isValidAnnotationEditorMode(mode)) {
|
||||
// Ensure that the Editor buttons, in the toolbar, are updated.
|
||||
this.eventBus.dispatch("annotationeditormodechanged", {
|
||||
source: this,
|
||||
mode: annotationEditorMode,
|
||||
mode,
|
||||
});
|
||||
|
||||
this.#annotationEditorUIManager = new AnnotationEditorUIManager(
|
||||
this.eventBus
|
||||
);
|
||||
if (mode !== AnnotationEditorType.NONE) {
|
||||
this.#annotationEditorUIManager.updateMode(mode);
|
||||
}
|
||||
} else {
|
||||
console.error(`Invalid AnnotationEditor mode: ${mode}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -885,9 +895,6 @@ class BaseViewer {
|
||||
}
|
||||
|
||||
_resetView() {
|
||||
if (this.#annotationEditorMode !== null) {
|
||||
this.#annotationEditorMode = AnnotationEditorType.NONE;
|
||||
}
|
||||
this.#annotationEditorUIManager = null;
|
||||
this._pages = [];
|
||||
this._currentPageNumber = 1;
|
||||
@ -2142,7 +2149,7 @@ class BaseViewer {
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {number | null}
|
||||
* @type {number}
|
||||
*/
|
||||
get annotationEditorMode() {
|
||||
return this.#annotationEditorMode;
|
||||
|
Loading…
Reference in New Issue
Block a user