UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

85 lines (84 loc) 2.78 kB
/** * DevExtreme (esm/__internal/ui/text_box/texteditor_button_collection/m_custom.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 _extends from "@babel/runtime/helpers/esm/extends"; import { name as clickEventName } from "../../../../common/core/events/click"; import eventsEngine from "../../../../common/core/events/core/events_engine"; import { end, start } from "../../../../common/core/events/hover"; import $ from "../../../../core/renderer"; import Button from "../../../../ui/button"; import TextEditorButton from "./m_button"; const CUSTOM_BUTTON_HOVERED_CLASS = "dx-custom-button-hovered"; export default class CustomButton extends TextEditorButton { _attachEvents(instance, $element) { const { editor: editor } = this; eventsEngine.on($element, start, (() => { editor.$element().addClass("dx-custom-button-hovered") })); eventsEngine.on($element, end, (() => { editor.$element().removeClass("dx-custom-button-hovered") })); eventsEngine.on($element, clickEventName, (e => { e.stopPropagation() })) } _create() { const { editor: editor } = this; const $element = $("<div>"); this._addToContainer($element); const instance = editor._createComponent($element, Button, _extends({}, this.options, { ignoreParentReadOnly: true, disabled: this._isDisabled(), integrationOptions: this._prepareIntegrationOptions(editor) })); return { $element: $element, instance: instance } } _prepareIntegrationOptions(editor) { return _extends({}, editor.option("integrationOptions"), { skipTemplates: ["content"] }) } update() { const isUpdated = super.update(); if (this.instance) { this.instance.option("disabled", this._isDisabled()) } return isUpdated } _isVisible() { const { visible: visible } = this.editor.option(); return !!visible } _isDisabled() { const isDefinedByUser = void 0 !== this.options.disabled; if (isDefinedByUser) { if (this.instance) { return this.instance.option("disabled") } return this.options.disabled } const { readOnly: readOnly } = this.editor.option(); return readOnly } }