UNPKG

handsontable

Version:

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

118 lines (113 loc) 4.48 kB
"use strict"; exports.__esModule = true; require("core-js/modules/es.error.cause.js"); require("core-js/modules/es.array.push.js"); var _element = require("../../../helpers/dom/element"); var _array = require("../../../helpers/array"); var C = _interopRequireWildcard(require("../../../i18n/constants")); var _base = require("./_base"); var _input = require("../ui/input"); var _ActionBarComponent; function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } 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 _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } 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"); } /** * @private * @class ActionBarComponent */ var _ActionBarComponent_brand = /*#__PURE__*/new WeakSet(); class ActionBarComponent extends _base.BaseComponent { static get BUTTON_OK() { return 'ok'; } static get BUTTON_CANCEL() { return 'cancel'; } constructor(hotInstance, options) { super(hotInstance, { id: options.id, stateless: true }); /** * On button click listener. * * @param {Event} event DOM event. * @param {InputUI} button InputUI object. */ _classPrivateMethodInitSpec(this, _ActionBarComponent_brand); /** * The name of the component. * * @type {string} */ _defineProperty(this, "name", ''); this.name = options.name; this.elements.push(new _input.InputUI(this.hot, { type: 'button', value: C.FILTERS_BUTTONS_OK, className: 'htUIButton htUIButtonOK', identifier: ActionBarComponent.BUTTON_OK })); this.elements.push(new _input.InputUI(this.hot, { type: 'button', value: C.FILTERS_BUTTONS_CANCEL, className: 'htUIButton htUIButtonCancel', identifier: ActionBarComponent.BUTTON_CANCEL })); this.registerHooks(); } /** * Register all necessary hooks. * * @private */ registerHooks() { (0, _array.arrayEach)(this.elements, element => { element.addLocalHook('click', (event, button) => _assertClassBrand(_ActionBarComponent_brand, this, _onButtonClick).call(this, event, button)); }); } /** * Get menu object descriptor. * * @returns {object} */ getMenuItemDescriptor() { return { key: this.id, name: this.name, isCommand: false, disableSelection: true, hidden: () => this.isHidden(), renderer: (hot, wrapper) => { (0, _element.addClass)(wrapper.parentNode, 'htFiltersMenuActionBar'); (0, _array.arrayEach)(this.elements, ui => wrapper.appendChild(ui.element)); return wrapper; } }; } /** * Fire accept event. */ accept() { this.runLocalHooks('accept'); } /** * Fire cancel event. */ cancel() { this.runLocalHooks('cancel'); } } exports.ActionBarComponent = ActionBarComponent; _ActionBarComponent = ActionBarComponent; function _onButtonClick(event, button) { if (button.options.identifier === _ActionBarComponent.BUTTON_OK) { this.accept(); } else { this.cancel(); } }