UNPKG

handsontable

Version:

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

45 lines (43 loc) 1.36 kB
import "core-js/modules/es.error.cause.js"; /** * @param {Core} Handsontable The Handsontable instance. */ export default function jQueryWrapper(Handsontable) { // eslint-disable-next-line const jQuery = typeof window === 'undefined' ? false : window.jQuery; if (!jQuery) { return; } jQuery.fn.handsontable = function (action) { const $this = this.first(); // Use only first element from list let instance = $this.data('handsontable'); // Init case if (typeof action !== 'string') { const userSettings = action || {}; if (instance) { instance.updateSettings(userSettings); } else { instance = new Handsontable.Core($this[0], userSettings); $this.data('handsontable', instance); instance.init(); } return $this; } let output; // Action case if (instance) { if (typeof instance[action] !== 'undefined') { for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } output = instance[action].call(instance, ...args); if (action === 'destroy') { $this.removeData(); } } else { throw new Error(`Handsontable do not provide action: ${action}`); } } return output; }; }