UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

134 lines (132 loc) • 5.25 kB
/** * DevExtreme (cjs/__internal/ui/number_box/number_box.spins.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _events_engine = _interopRequireDefault(require("../../../common/core/events/core/events_engine")); var _pointer = _interopRequireDefault(require("../../../common/core/events/pointer")); var _index = require("../../../common/core/events/utils/index"); var _renderer = _interopRequireDefault(require("../../../core/renderer")); var _button = _interopRequireDefault(require("../../ui/text_box/texteditor_button_collection/button")); var _number_box = _interopRequireDefault(require("./number_box.spin")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const SPIN_CLASS = "dx-numberbox-spin"; const SPIN_CONTAINER_CLASS = "dx-numberbox-spin-container"; const SPIN_TOUCH_FRIENDLY_CLASS = "dx-numberbox-spin-touch-friendly"; class SpinButtons extends _button.default { _attachEvents(instance, $spinContainer) { const { editor: editor } = this; if (!editor) { return } const eventName = (0, _index.addNamespace)(_pointer.default.down, editor.NAME ?? ""); const $spinContainerChildren = $spinContainer.children(); const pointerDownAction = editor._createAction(() => { var _this$editor; null === (_this$editor = this.editor) || void 0 === _this$editor || _this$editor._spinButtonsPointerDownHandler() }); _events_engine.default.off($spinContainer, eventName); _events_engine.default.on($spinContainer, eventName, e => pointerDownAction({ event: e })); _number_box.default.getInstance($spinContainerChildren.eq(0)).option("onChange", e => { var _this$editor2; null === (_this$editor2 = this.editor) || void 0 === _this$editor2 || _this$editor2._spinUpChangeHandler(e) }); _number_box.default.getInstance($spinContainerChildren.eq(1)).option("onChange", e => { var _this$editor3; null === (_this$editor3 = this.editor) || void 0 === _this$editor3 || _this$editor3._spinDownChangeHandler(e) }) } _create() { const { editor: editor } = this; if (!editor) { return } const $spinContainer = (0, _renderer.default)("<div>").addClass(SPIN_CONTAINER_CLASS); const $spinUp = (0, _renderer.default)("<div>").appendTo($spinContainer); const $spinDown = (0, _renderer.default)("<div>").appendTo($spinContainer); const options = this._getOptions(); this._addToContainer($spinContainer); editor._createComponent($spinUp, _number_box.default, Object.assign({ direction: "up" }, options)); editor._createComponent($spinDown, _number_box.default, Object.assign({ direction: "down" }, options)); this._legacyRender(editor.$element(), this._isTouchFriendly(), options.visible); return { instance: $spinContainer, $element: $spinContainer } } _getOptions() { const { editor: editor } = this; const { disabled: disabled } = (null === editor || void 0 === editor ? void 0 : editor.option()) ?? {}; return { visible: this._isVisible(), disabled: !!disabled } } _isVisible() { const { editor: editor } = this; const { showSpinButtons: showSpinButtons } = (null === editor || void 0 === editor ? void 0 : editor.option()) ?? {}; return super._isVisible() && !!showSpinButtons } _isTouchFriendly() { const { editor: editor } = this; const { showSpinButtons: showSpinButtons, useLargeSpinButtons: useLargeSpinButtons } = (null === editor || void 0 === editor ? void 0 : editor.option()) ?? {}; return !!showSpinButtons && !!useLargeSpinButtons } _legacyRender($editor, isTouchFriendly, isVisible) { $editor.toggleClass(SPIN_TOUCH_FRIENDLY_CLASS, isTouchFriendly); $editor.toggleClass(SPIN_CLASS, isVisible) } update() { const shouldUpdate = super.update(); const { editor: editor, instance: instance } = this; if (shouldUpdate && instance && editor) { const $spinButtons = instance.children(); const spinUp = _number_box.default.getInstance($spinButtons.eq(0)); const spinDown = _number_box.default.getInstance($spinButtons.eq(1)); const options = this._getOptions(); spinUp.option(options); spinDown.option(options); this._legacyRender(editor.$element(), this._isTouchFriendly(), options.visible) } return shouldUpdate } } exports.default = SpinButtons;