Merge pull request #17030 from calixteman/editor_remove_editing_class
[Editor] Remove the class fooEditing from the layer when destroying it
This commit is contained in:
commit
5f75404bc3
@ -73,6 +73,13 @@ class AnnotationEditorLayer {
|
|||||||
|
|
||||||
static _initialized = false;
|
static _initialized = false;
|
||||||
|
|
||||||
|
static #editorTypes = new Map(
|
||||||
|
[FreeTextEditor, InkEditor, StampEditor].map(type => [
|
||||||
|
type._editorType,
|
||||||
|
type,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {AnnotationEditorLayerOptions} options
|
* @param {AnnotationEditorLayerOptions} options
|
||||||
*/
|
*/
|
||||||
@ -85,7 +92,7 @@ class AnnotationEditorLayer {
|
|||||||
viewport,
|
viewport,
|
||||||
l10n,
|
l10n,
|
||||||
}) {
|
}) {
|
||||||
const editorTypes = [FreeTextEditor, InkEditor, StampEditor];
|
const editorTypes = [...AnnotationEditorLayer.#editorTypes.values()];
|
||||||
if (!AnnotationEditorLayer._initialized) {
|
if (!AnnotationEditorLayer._initialized) {
|
||||||
AnnotationEditorLayer._initialized = true;
|
AnnotationEditorLayer._initialized = true;
|
||||||
for (const editorType of editorTypes) {
|
for (const editorType of editorTypes) {
|
||||||
@ -131,18 +138,13 @@ class AnnotationEditorLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mode !== AnnotationEditorType.NONE) {
|
if (mode !== AnnotationEditorType.NONE) {
|
||||||
this.div.classList.toggle(
|
const { classList } = this.div;
|
||||||
"freeTextEditing",
|
for (const editorType of AnnotationEditorLayer.#editorTypes.values()) {
|
||||||
mode === AnnotationEditorType.FREETEXT
|
classList.toggle(
|
||||||
);
|
`${editorType._type}Editing`,
|
||||||
this.div.classList.toggle(
|
mode === editorType._editorType
|
||||||
"inkEditing",
|
|
||||||
mode === AnnotationEditorType.INK
|
|
||||||
);
|
|
||||||
this.div.classList.toggle(
|
|
||||||
"stampEditing",
|
|
||||||
mode === AnnotationEditorType.STAMP
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
this.div.hidden = false;
|
this.div.hidden = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,6 +264,11 @@ class AnnotationEditorLayer {
|
|||||||
if (this.isEmpty) {
|
if (this.isEmpty) {
|
||||||
this.div.hidden = true;
|
this.div.hidden = true;
|
||||||
}
|
}
|
||||||
|
const { classList } = this.div;
|
||||||
|
for (const editorType of AnnotationEditorLayer.#editorTypes.values()) {
|
||||||
|
classList.remove(`${editorType._type}Editing`);
|
||||||
|
}
|
||||||
|
|
||||||
this.#isDisabling = false;
|
this.#isDisabling = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,15 +465,10 @@ class AnnotationEditorLayer {
|
|||||||
* @returns {AnnotationEditor}
|
* @returns {AnnotationEditor}
|
||||||
*/
|
*/
|
||||||
#createNewEditor(params) {
|
#createNewEditor(params) {
|
||||||
switch (this.#uiManager.getMode()) {
|
const editorType = AnnotationEditorLayer.#editorTypes.get(
|
||||||
case AnnotationEditorType.FREETEXT:
|
this.#uiManager.getMode()
|
||||||
return new FreeTextEditor(params);
|
);
|
||||||
case AnnotationEditorType.INK:
|
return editorType ? new editorType.prototype.constructor(params) : null;
|
||||||
return new InkEditor(params);
|
|
||||||
case AnnotationEditorType.STAMP:
|
|
||||||
return new StampEditor(params);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -497,18 +499,14 @@ class AnnotationEditorLayer {
|
|||||||
/**
|
/**
|
||||||
* Create a new editor
|
* Create a new editor
|
||||||
* @param {Object} data
|
* @param {Object} data
|
||||||
* @returns {AnnotationEditor}
|
* @returns {AnnotationEditor | null}
|
||||||
*/
|
*/
|
||||||
deserialize(data) {
|
deserialize(data) {
|
||||||
switch (data.annotationType ?? data.annotationEditorType) {
|
return (
|
||||||
case AnnotationEditorType.FREETEXT:
|
AnnotationEditorLayer.#editorTypes
|
||||||
return FreeTextEditor.deserialize(data, this, this.#uiManager);
|
.get(data.annotationType ?? data.annotationEditorType)
|
||||||
case AnnotationEditorType.INK:
|
?.deserialize(data, this, this.#uiManager) || null
|
||||||
return InkEditor.deserialize(data, this, this.#uiManager);
|
);
|
||||||
case AnnotationEditorType.STAMP:
|
|
||||||
return StampEditor.deserialize(data, this, this.#uiManager);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -943,7 +943,7 @@ class AnnotationEditor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Render this editor in a div.
|
* Render this editor in a div.
|
||||||
* @returns {HTMLDivElement}
|
* @returns {HTMLDivElement | null}
|
||||||
*/
|
*/
|
||||||
render() {
|
render() {
|
||||||
this.div = document.createElement("div");
|
this.div = document.createElement("div");
|
||||||
@ -1203,8 +1203,9 @@ class AnnotationEditor {
|
|||||||
* new annotation to add to the pdf document.
|
* new annotation to add to the pdf document.
|
||||||
*
|
*
|
||||||
* To implement in subclasses.
|
* To implement in subclasses.
|
||||||
* @param {boolean} isForCopying
|
* @param {boolean} [isForCopying]
|
||||||
* @param {Object} [context]
|
* @param {Object | null} [context]
|
||||||
|
* @returns {Object | null}
|
||||||
*/
|
*/
|
||||||
serialize(isForCopying = false, context = null) {
|
serialize(isForCopying = false, context = null) {
|
||||||
unreachable("An editor must be serializable");
|
unreachable("An editor must be serializable");
|
||||||
@ -1217,7 +1218,7 @@ class AnnotationEditor {
|
|||||||
* @param {Object} data
|
* @param {Object} data
|
||||||
* @param {AnnotationEditorLayer} parent
|
* @param {AnnotationEditorLayer} parent
|
||||||
* @param {AnnotationEditorUIManager} uiManager
|
* @param {AnnotationEditorUIManager} uiManager
|
||||||
* @returns {AnnotationEditor}
|
* @returns {AnnotationEditor | null}
|
||||||
*/
|
*/
|
||||||
static deserialize(data, parent, uiManager) {
|
static deserialize(data, parent, uiManager) {
|
||||||
const editor = new this.prototype.constructor({
|
const editor = new this.prototype.constructor({
|
||||||
@ -1342,6 +1343,7 @@ class AnnotationEditor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the div which really contains the displayed content.
|
* Get the div which really contains the displayed content.
|
||||||
|
* @returns {HTMLDivElement | undefined}
|
||||||
*/
|
*/
|
||||||
get contentDiv() {
|
get contentDiv() {
|
||||||
return this.div;
|
return this.div;
|
||||||
|
@ -132,6 +132,8 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
|
|
||||||
static _type = "freetext";
|
static _type = "freetext";
|
||||||
|
|
||||||
|
static _editorType = AnnotationEditorType.FREETEXT;
|
||||||
|
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
super({ ...params, name: "freeTextEditor" });
|
super({ ...params, name: "freeTextEditor" });
|
||||||
this.#color =
|
this.#color =
|
||||||
@ -335,7 +337,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
|
|
||||||
// In case the blur callback hasn't been called.
|
// In case the blur callback hasn't been called.
|
||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
this.parent.div.classList.add("freeTextEditing");
|
this.parent.div.classList.add("freetextEditing");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
@ -374,7 +376,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
if (this.parent) {
|
if (this.parent) {
|
||||||
this.parent.setEditingState(true);
|
this.parent.setEditingState(true);
|
||||||
this.parent.div.classList.add("freeTextEditing");
|
this.parent.div.classList.add("freetextEditing");
|
||||||
}
|
}
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
@ -508,7 +510,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
editorDivInput(event) {
|
editorDivInput(event) {
|
||||||
this.parent.div.classList.toggle("freeTextEditing", this.isEmpty());
|
this.parent.div.classList.toggle("freetextEditing", this.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
@ -649,6 +651,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @inheritdoc */
|
||||||
get contentDiv() {
|
get contentDiv() {
|
||||||
return this.editorDiv;
|
return this.editorDiv;
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,8 @@ class InkEditor extends AnnotationEditor {
|
|||||||
|
|
||||||
static _type = "ink";
|
static _type = "ink";
|
||||||
|
|
||||||
|
static _editorType = AnnotationEditorType.INK;
|
||||||
|
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
super({ ...params, name: "inkEditor" });
|
super({ ...params, name: "inkEditor" });
|
||||||
this.color = params.color || null;
|
this.color = params.color || null;
|
||||||
|
@ -44,6 +44,8 @@ class StampEditor extends AnnotationEditor {
|
|||||||
|
|
||||||
static _type = "stamp";
|
static _type = "stamp";
|
||||||
|
|
||||||
|
static _editorType = AnnotationEditorType.STAMP;
|
||||||
|
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
super({ ...params, name: "stampEditor" });
|
super({ ...params, name: "stampEditor" });
|
||||||
this.#bitmapUrl = params.bitmapUrl;
|
this.#bitmapUrl = params.bitmapUrl;
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.annotationEditorLayer.freeTextEditing {
|
.annotationEditorLayer.freetextEditing {
|
||||||
cursor: var(--editorFreeText-editing-cursor);
|
cursor: var(--editorFreeText-editing-cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user