UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

57 lines (56 loc) 1.95 kB
/** * DevExtreme (esm/__internal/ui/html_editor/modules/m_imageCursor.js) * Version: 24.2.6 * Build date: Mon Mar 17 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import eventsEngine from "../../../../common/core/events/core/events_engine"; import { addNamespace } from "../../../../common/core/events/utils/index"; import Quill from "devextreme-quill"; import BaseModule from "./m_base"; const MODULE_NAMESPACE = "dxHtmlEditorImageCursor"; const clickEvent = addNamespace("dxclick", MODULE_NAMESPACE); let ImageCursorModule = BaseModule; if (Quill) { ImageCursorModule = class extends BaseModule { constructor(quill, options) { super(quill, options); this.addCleanCallback(this.clean.bind(this)); this._attachEvents() } _attachEvents() { eventsEngine.on(this.quill.root, clickEvent, this._clickHandler.bind(this)) } _detachEvents() { eventsEngine.off(this.quill.root, clickEvent) } _clickHandler(e) { if (this._isAllowedTarget(e.target)) { this._adjustSelection(e) } } _isAllowedTarget(targetElement) { return this._isImage(targetElement) } _isImage(targetElement) { return "IMG" === targetElement.tagName.toUpperCase() } _adjustSelection(e) { const blot = this.quill.scroll.find(e.target); if (blot) { const index = blot.offset(this.quill.scroll); this.quill.setSelection(index + 1, 0) } else { this.quill.setSelection(0, 0) } } clean() { this._detachEvents() } } } export default ImageCursorModule;