Merge pull request #19993 from calixteman/editor_toolbar_simplification
Slightly simplify the way to create the editor toolbar
This commit is contained in:
commit
c7796c7f8d
@ -1049,6 +1049,14 @@ class AnnotationEditor {
|
|||||||
this.#altText?.finish();
|
this.#altText?.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the toolbar buttons for this editor.
|
||||||
|
* @returns {Array<Array<string|object>>|null}
|
||||||
|
*/
|
||||||
|
get toolbarButtons() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a toolbar for this editor.
|
* Add a toolbar for this editor.
|
||||||
* @returns {Promise<EditorToolbar|null>}
|
* @returns {Promise<EditorToolbar|null>}
|
||||||
@ -1059,9 +1067,13 @@ class AnnotationEditor {
|
|||||||
}
|
}
|
||||||
this._editToolbar = new EditorToolbar(this);
|
this._editToolbar = new EditorToolbar(this);
|
||||||
this.div.append(this._editToolbar.render());
|
this.div.append(this._editToolbar.render());
|
||||||
if (this.#altText) {
|
const { toolbarButtons } = this;
|
||||||
await this._editToolbar.addAltText(this.#altText);
|
if (toolbarButtons) {
|
||||||
|
for (const [name, tool] of toolbarButtons) {
|
||||||
|
await this._editToolbar.addButton(name, tool);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this._editToolbar.addButton("delete");
|
||||||
|
|
||||||
return this._editToolbar;
|
return this._editToolbar;
|
||||||
}
|
}
|
||||||
@ -1091,17 +1103,20 @@ class AnnotationEditor {
|
|||||||
return this.div.getBoundingClientRect();
|
return this.div.getBoundingClientRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
async addAltTextButton() {
|
/**
|
||||||
if (this.#altText) {
|
* Create the alt text for this editor.
|
||||||
return;
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
createAltText() {
|
||||||
|
if (!this.#altText) {
|
||||||
|
AltText.initialize(AnnotationEditor._l10n);
|
||||||
|
this.#altText = new AltText(this);
|
||||||
|
if (this.#accessibilityData) {
|
||||||
|
this.#altText.data = this.#accessibilityData;
|
||||||
|
this.#accessibilityData = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AltText.initialize(AnnotationEditor._l10n);
|
return this.#altText;
|
||||||
this.#altText = new AltText(this);
|
|
||||||
if (this.#accessibilityData) {
|
|
||||||
this.#altText.data = this.#accessibilityData;
|
|
||||||
this.#accessibilityData = null;
|
|
||||||
}
|
|
||||||
await this.addEditToolbar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get altTextData() {
|
get altTextData() {
|
||||||
|
|||||||
@ -398,16 +398,14 @@ class HighlightEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
async addEditToolbar() {
|
get toolbarButtons() {
|
||||||
const toolbar = await super.addEditToolbar();
|
|
||||||
if (!toolbar) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (this._uiManager.highlightColors) {
|
if (this._uiManager.highlightColors) {
|
||||||
this.#colorPicker = new ColorPicker({ editor: this });
|
const colorPicker = (this.#colorPicker = new ColorPicker({
|
||||||
toolbar.addColorPicker(this.#colorPicker);
|
editor: this,
|
||||||
|
}));
|
||||||
|
return [["colorPicker", colorPicker]];
|
||||||
}
|
}
|
||||||
return toolbar;
|
return super.toolbarButtons;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
|
|||||||
@ -244,27 +244,18 @@ class SignatureEditor extends DrawingEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
async addEditToolbar() {
|
get toolbarButtons() {
|
||||||
const toolbar = await super.addEditToolbar();
|
if (this._uiManager.signatureManager) {
|
||||||
if (!toolbar) {
|
return [["editSignature", this._uiManager.signatureManager]];
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
if (this._uiManager.signatureManager && this.#description !== null) {
|
return super.toolbarButtons;
|
||||||
await toolbar.addEditSignatureButton(
|
|
||||||
this._uiManager.signatureManager,
|
|
||||||
this.#signatureUUID,
|
|
||||||
this.#description
|
|
||||||
);
|
|
||||||
toolbar.show();
|
|
||||||
}
|
|
||||||
return toolbar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addSignature(data, heightInPage, description, uuid) {
|
addSignature(data, heightInPage, description, uuid) {
|
||||||
const { x: savedX, y: savedY } = this;
|
const { x: savedX, y: savedY } = this;
|
||||||
const { outline } = (this.#signatureData = data);
|
const { outline } = (this.#signatureData = data);
|
||||||
this.#isExtracted = outline instanceof ContourDrawOutline;
|
this.#isExtracted = outline instanceof ContourDrawOutline;
|
||||||
this.#description = description;
|
this.description = description;
|
||||||
this.div.setAttribute("data-l10n-args", JSON.stringify({ description }));
|
this.div.setAttribute("data-l10n-args", JSON.stringify({ description }));
|
||||||
let drawingOptions;
|
let drawingOptions;
|
||||||
if (this.#isExtracted) {
|
if (this.#isExtracted) {
|
||||||
|
|||||||
@ -128,8 +128,10 @@ class StampEditor extends AnnotationEditor {
|
|||||||
this._uiManager.useNewAltTextFlow &&
|
this._uiManager.useNewAltTextFlow &&
|
||||||
this.#bitmap
|
this.#bitmap
|
||||||
) {
|
) {
|
||||||
this._editToolbar.hide();
|
this.addEditToolbar().then(() => {
|
||||||
this._uiManager.editAltText(this, /* firstTime = */ true);
|
this._editToolbar.hide();
|
||||||
|
this._uiManager.editAltText(this, /* firstTime = */ true);
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,6 +338,11 @@ class StampEditor extends AnnotationEditor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @inheritdoc */
|
||||||
|
get toolbarButtons() {
|
||||||
|
return [["altText", this.createAltText()]];
|
||||||
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
get isResizable() {
|
get isResizable() {
|
||||||
return true;
|
return true;
|
||||||
@ -356,7 +363,7 @@ class StampEditor extends AnnotationEditor {
|
|||||||
super.render();
|
super.render();
|
||||||
this.div.hidden = true;
|
this.div.hidden = true;
|
||||||
|
|
||||||
this.addAltTextButton();
|
this.createAltText();
|
||||||
|
|
||||||
if (!this.#missingCanvas) {
|
if (!this.#missingCanvas) {
|
||||||
if (this.#bitmap) {
|
if (this.#bitmap) {
|
||||||
|
|||||||
@ -69,8 +69,6 @@ class EditorToolbar {
|
|||||||
}% + var(--editor-toolbar-vert-offset))`;
|
}% + var(--editor-toolbar-vert-offset))`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#addDeleteButton();
|
|
||||||
|
|
||||||
return editToolbar;
|
return editToolbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +116,7 @@ class EditorToolbar {
|
|||||||
this.#altText?.shown();
|
this.#altText?.shown();
|
||||||
}
|
}
|
||||||
|
|
||||||
#addDeleteButton() {
|
addDeleteButton() {
|
||||||
const { editorType, _uiManager } = this.#editor;
|
const { editorType, _uiManager } = this.#editor;
|
||||||
|
|
||||||
const button = document.createElement("button");
|
const button = document.createElement("button");
|
||||||
@ -145,7 +143,7 @@ class EditorToolbar {
|
|||||||
async addAltText(altText) {
|
async addAltText(altText) {
|
||||||
const button = await altText.render();
|
const button = await altText.render();
|
||||||
this.#addListenersToElement(button);
|
this.#addListenersToElement(button);
|
||||||
this.#buttons.prepend(button, this.#divider);
|
this.#buttons.append(button, this.#divider);
|
||||||
this.#altText = altText;
|
this.#altText = altText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,14 +151,31 @@ class EditorToolbar {
|
|||||||
this.#colorPicker = colorPicker;
|
this.#colorPicker = colorPicker;
|
||||||
const button = colorPicker.renderButton();
|
const button = colorPicker.renderButton();
|
||||||
this.#addListenersToElement(button);
|
this.#addListenersToElement(button);
|
||||||
this.#buttons.prepend(button, this.#divider);
|
this.#buttons.append(button, this.#divider);
|
||||||
}
|
}
|
||||||
|
|
||||||
async addEditSignatureButton(signatureManager) {
|
async addEditSignatureButton(signatureManager) {
|
||||||
const button = (this.#signatureDescriptionButton =
|
const button = (this.#signatureDescriptionButton =
|
||||||
await signatureManager.renderEditButton(this.#editor));
|
await signatureManager.renderEditButton(this.#editor));
|
||||||
this.#addListenersToElement(button);
|
this.#addListenersToElement(button);
|
||||||
this.#buttons.prepend(button, this.#divider);
|
this.#buttons.append(button, this.#divider);
|
||||||
|
}
|
||||||
|
|
||||||
|
async addButton(name, tool) {
|
||||||
|
switch (name) {
|
||||||
|
case "colorPicker":
|
||||||
|
this.addColorPicker(tool);
|
||||||
|
break;
|
||||||
|
case "altText":
|
||||||
|
await this.addAltText(tool);
|
||||||
|
break;
|
||||||
|
case "editSignature":
|
||||||
|
await this.addEditSignatureButton(tool);
|
||||||
|
break;
|
||||||
|
case "delete":
|
||||||
|
this.addDeleteButton();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateEditSignatureButton(description) {
|
updateEditSignatureButton(description) {
|
||||||
|
|||||||
@ -820,7 +820,9 @@ class SignatureManager {
|
|||||||
const button = document.createElement("button");
|
const button = document.createElement("button");
|
||||||
button.classList.add("altText", "editDescription");
|
button.classList.add("altText", "editDescription");
|
||||||
button.tabIndex = 0;
|
button.tabIndex = 0;
|
||||||
button.title = editor.description;
|
if (editor.description) {
|
||||||
|
button.title = editor.description;
|
||||||
|
}
|
||||||
const span = document.createElement("span");
|
const span = document.createElement("span");
|
||||||
button.append(span);
|
button.append(span);
|
||||||
span.setAttribute(
|
span.setAttribute(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user