UNPKG

handsontable

Version:

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

96 lines (90 loc) 2.47 kB
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"); } import { mixin } from "../../../helpers/object.mjs"; import localHooks from "../../../mixins/localHooks.mjs"; /** * Controller for managing the input. * * @private * @class InputController */ var _InputController_brand = /*#__PURE__*/new WeakSet(); export 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); } } function _triggerFilter(value) { this.runLocalHooks('triggerFilter', value); } mixin(InputController, localHooks);