UNPKG

handsontable

Version:

Handsontable is a JavaScript Data Grid available for React, Angular and Vue.

101 lines (94 loc) 2.67 kB
"use strict"; exports.__esModule = true; var _object = require("../../../helpers/object"); var _localHooks = _interopRequireDefault(require("../../../mixins/localHooks")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); } function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); } function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); } /** * Controller for managing the input. * * @private * @class InputController */ var _InputController_brand = /*#__PURE__*/new WeakSet(); class InputController { /** * Creates a new InputController. * * @param {object} options Options object. * @param {HTMLInputElement} options.input Input element. * @param {EventManager} options.eventManager Event manager. */ constructor(_ref) { let { input, eventManager } = _ref; /** * Triggers the filtering. * * @param {string} value The value of the input. */ _classPrivateMethodInitSpec(this, _InputController_brand); this.input = input; this.eventManager = eventManager; this.enabled = true; this.onInput = this.onInput.bind(this); } /** * Gets the input element. * * @returns {HTMLInputElement} The input element. */ getInputElement() { return this.input; } /** * Sets the value of the input. * * @param {string} value The value to set. */ setValue(value) { this.input.value = value; } /** * Toggles the input. * * @param {boolean} enabled If true, the input will be enabled. */ toggle(enabled) { this.enabled = enabled; if (this.input) { if (enabled) { this.listen(); } else { this.unlisten(); } } } /** * Listens to the input keyup event. */ listen() { this.eventManager.addEventListener(this.input, 'input', this.onInput); } /** * Unlistens to the input keyup event. */ unlisten() { this.eventManager.removeEventListener(this.input, 'input', this.onInput); } /** * OnInput listener. */ onInput() { _assertClassBrand(_InputController_brand, this, _triggerFilter).call(this, this.input.value); } } exports.InputController = InputController; function _triggerFilter(value) { this.runLocalHooks('triggerFilter', value); } (0, _object.mixin)(InputController, _localHooks.default);