helpers.entry.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. /*!
  2. * (The MIT License)
  3. *
  4. * Copyright (c) 2012-2014 Marcin Warpechowski
  5. * Copyright (c) 2015 Handsoncode sp. z o.o. <hello@handsoncode.net>
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * 'Software'), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  22. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * Version: 0.32.0-beta2
  27. * Date: Tue May 30 2017 12:10:57 GMT+0200 (CEST)
  28. */
  29. /******/ (function(modules) { // webpackBootstrap
  30. /******/ // The module cache
  31. /******/ var installedModules = {};
  32. /******/
  33. /******/ // The require function
  34. /******/ function __webpack_require__(moduleId) {
  35. /******/
  36. /******/ // Check if module is in cache
  37. /******/ if(installedModules[moduleId]) {
  38. /******/ return installedModules[moduleId].exports;
  39. /******/ }
  40. /******/ // Create a new module (and put it into the cache)
  41. /******/ var module = installedModules[moduleId] = {
  42. /******/ i: moduleId,
  43. /******/ l: false,
  44. /******/ exports: {}
  45. /******/ };
  46. /******/
  47. /******/ // Execute the module function
  48. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  49. /******/
  50. /******/ // Flag the module as loaded
  51. /******/ module.l = true;
  52. /******/
  53. /******/ // Return the exports of the module
  54. /******/ return module.exports;
  55. /******/ }
  56. /******/
  57. /******/
  58. /******/ // expose the modules object (__webpack_modules__)
  59. /******/ __webpack_require__.m = modules;
  60. /******/
  61. /******/ // expose the module cache
  62. /******/ __webpack_require__.c = installedModules;
  63. /******/
  64. /******/ // identity function for calling harmony imports with the correct context
  65. /******/ __webpack_require__.i = function(value) { return value; };
  66. /******/
  67. /******/ // define getter function for harmony exports
  68. /******/ __webpack_require__.d = function(exports, name, getter) {
  69. /******/ if(!__webpack_require__.o(exports, name)) {
  70. /******/ Object.defineProperty(exports, name, {
  71. /******/ configurable: false,
  72. /******/ enumerable: true,
  73. /******/ get: getter
  74. /******/ });
  75. /******/ }
  76. /******/ };
  77. /******/
  78. /******/ // getDefaultExport function for compatibility with non-harmony modules
  79. /******/ __webpack_require__.n = function(module) {
  80. /******/ var getter = module && module.__esModule ?
  81. /******/ function getDefault() { return module['default']; } :
  82. /******/ function getModuleExports() { return module; };
  83. /******/ __webpack_require__.d(getter, 'a', getter);
  84. /******/ return getter;
  85. /******/ };
  86. /******/
  87. /******/ // Object.prototype.hasOwnProperty.call
  88. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  89. /******/
  90. /******/ // __webpack_public_path__
  91. /******/ __webpack_require__.p = "";
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = 245);
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ 125:
  99. /***/ (function(module, exports) {
  100. module.exports = window;
  101. /***/ }),
  102. /***/ 245:
  103. /***/ (function(module, exports, __webpack_require__) {
  104. "use strict";
  105. var _window = __webpack_require__(125);
  106. var _window2 = _interopRequireDefault(_window);
  107. var _common = __webpack_require__(76);
  108. var common = _interopRequireWildcard(_common);
  109. var _jasmine = __webpack_require__(77);
  110. var jasmine = _interopRequireWildcard(_jasmine);
  111. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  112. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  113. var exportToWindow = function exportToWindow(helpersHolder) {
  114. Object.keys(helpersHolder).forEach(function (key) {
  115. if (key === '__esModule') {
  116. return;
  117. }
  118. if (_window2.default[key] !== void 0) {
  119. throw Error('Cannot export "' + key + '" helper because this name is already assigned.');
  120. }
  121. _window2.default[key] = helpersHolder[key];
  122. });
  123. };
  124. // Export all helpers to the window.
  125. /* eslint-disable import/no-unresolved */
  126. exportToWindow(common);
  127. exportToWindow(jasmine);
  128. /***/ }),
  129. /***/ 76:
  130. /***/ (function(module, exports, __webpack_require__) {
  131. "use strict";
  132. exports.__esModule = true;
  133. exports.sleep = sleep;
  134. exports.hot = hot;
  135. exports.handsontable = handsontable;
  136. exports.getHtCore = getHtCore;
  137. exports.getTopClone = getTopClone;
  138. exports.getTopLeftClone = getTopLeftClone;
  139. exports.getLeftClone = getLeftClone;
  140. exports.getBottomClone = getBottomClone;
  141. exports.getBottomLeftClone = getBottomLeftClone;
  142. exports.countCells = countCells;
  143. exports.isEditorVisible = isEditorVisible;
  144. exports.isFillHandleVisible = isFillHandleVisible;
  145. exports.getCorrespondingOverlay = getCorrespondingOverlay;
  146. exports.contextMenu = contextMenu;
  147. exports.closeContextMenu = closeContextMenu;
  148. exports.dropdownMenu = dropdownMenu;
  149. exports.closeDropdownMenu = closeDropdownMenu;
  150. exports.dropdownMenuRootElement = dropdownMenuRootElement;
  151. exports.handsontableMouseTriggerFactory = handsontableMouseTriggerFactory;
  152. exports.mouseDoubleClick = mouseDoubleClick;
  153. exports.handsontableKeyTriggerFactory = handsontableKeyTriggerFactory;
  154. exports.keyDownUp = keyDownUp;
  155. exports.keyProxy = keyProxy;
  156. exports.serveImmediatePropagation = serveImmediatePropagation;
  157. exports.autocompleteEditor = autocompleteEditor;
  158. exports.setCaretPosition = setCaretPosition;
  159. exports.autocomplete = autocomplete;
  160. exports.triggerPaste = triggerPaste;
  161. exports.handsontableMethodFactory = handsontableMethodFactory;
  162. exports.colWidth = colWidth;
  163. exports.rowHeight = rowHeight;
  164. exports.getRenderedValue = getRenderedValue;
  165. exports.getRenderedContent = getRenderedContent;
  166. exports.createNumericData = createNumericData;
  167. exports.Model = Model;
  168. exports.createAccessorForProperty = createAccessorForProperty;
  169. exports.resizeColumn = resizeColumn;
  170. exports.resizeRow = resizeRow;
  171. exports.moveSecondDisplayedRowBeforeFirstRow = moveSecondDisplayedRowBeforeFirstRow;
  172. exports.moveFirstDisplayedRowAfterSecondRow = moveFirstDisplayedRowAfterSecondRow;
  173. exports.swapDisplayedColumns = swapDisplayedColumns;
  174. exports.triggerTouchEvent = triggerTouchEvent;
  175. function sleep() {
  176. var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
  177. return Promise.resolve({
  178. then: function then(resolve) {
  179. setTimeout(resolve, delay);
  180. }
  181. });
  182. };
  183. function hot() {
  184. return spec().$container.data('handsontable');
  185. };
  186. function handsontable(options) {
  187. var currentSpec = spec();
  188. currentSpec.$container.handsontable(options);
  189. currentSpec.$container[0].focus(); // otherwise TextEditor tests do not pass in IE8
  190. return currentSpec.$container.data('handsontable');
  191. };
  192. /**
  193. * As for v. 0.11 the only scrolling method is native scroll, which creates copies of main htCore table inside of the container.
  194. * Therefore, simple $(".htCore") will return more than one object. Most of the time, you're interested in the original
  195. * htCore, not the copies made by native scroll.
  196. *
  197. * This method returns the original htCore object
  198. *
  199. * @returns {jqObject} reference to the original htCore
  200. */
  201. function getHtCore() {
  202. return spec().$container.find('.htCore').first();
  203. };
  204. function getTopClone() {
  205. return spec().$container.find('.ht_clone_top');
  206. };
  207. function getTopLeftClone() {
  208. return spec().$container.find('.ht_clone_top_left_corner');
  209. };
  210. // for compatybility
  211. // var getCornerClone = getTopLeftClone;
  212. function getLeftClone() {
  213. return spec().$container.find('.ht_clone_left');
  214. };
  215. function getBottomClone() {
  216. return spec().$container.find('.ht_clone_bottom');
  217. };
  218. function getBottomLeftClone() {
  219. return spec().$container.find('.ht_clone_bottom_left_corner');
  220. };
  221. // Rename me to countTD
  222. function countCells() {
  223. return getHtCore().find('tbody td').length;
  224. };
  225. function isEditorVisible() {
  226. return !!(keyProxy().is(':visible') && keyProxy().parent().is(':visible') && !keyProxy().parent().is('.htHidden'));
  227. };
  228. function isFillHandleVisible() {
  229. return !!spec().$container.find('.wtBorder.corner:visible').length;
  230. };
  231. function getCorrespondingOverlay(cell, container) {
  232. var overlay = $(cell).parents('.handsontable');
  233. if (overlay[0] == container[0]) {
  234. return $('.ht_master');
  235. }
  236. return $(overlay[0]);
  237. };
  238. /**
  239. * Shows context menu
  240. */
  241. function contextMenu(cell) {
  242. var hot = spec().$container.data('handsontable');
  243. var selected = hot.getSelected();
  244. if (!selected) {
  245. hot.selectCell(0, 0);
  246. selected = hot.getSelected();
  247. }
  248. if (!cell) {
  249. cell = getCell(selected[0], selected[1]);
  250. }
  251. var cellOffset = $(cell).offset();
  252. $(cell).simulate('contextmenu', {
  253. clientX: cellOffset.left - Handsontable.dom.getWindowScrollLeft(),
  254. clientY: cellOffset.top - Handsontable.dom.getWindowScrollTop()
  255. });
  256. };
  257. function closeContextMenu() {
  258. $(document).simulate('mousedown');
  259. // $(document).trigger('mousedown');
  260. };
  261. /**
  262. * Shows dropdown menu
  263. */
  264. function dropdownMenu(columnIndex) {
  265. var hot = spec().$container.data('handsontable');
  266. var th = hot.view.wt.wtTable.getColumnHeader(columnIndex || 0);
  267. var button = th.querySelector('.changeType');
  268. if (button) {
  269. $(button).simulate('mousedown');
  270. $(button).simulate('click');
  271. }
  272. };
  273. function closeDropdownMenu() {
  274. $(document).simulate('mousedown');
  275. };
  276. function dropdownMenuRootElement() {
  277. var plugin = hot().getPlugin('dropdownMenu');
  278. var root;
  279. if (plugin && plugin.menu) {
  280. root = plugin.menu.container;
  281. }
  282. return root;
  283. };
  284. /**
  285. * Returns a function that triggers a mouse event
  286. * @param {String} type Event type
  287. * @return {Function}
  288. */
  289. function handsontableMouseTriggerFactory(type, button) {
  290. return function (element) {
  291. if (!(element instanceof jQuery)) {
  292. element = $(element);
  293. }
  294. var ev = $.Event(type);
  295. ev.which = button || 1; // left click by default
  296. element.simulate(type, ev);
  297. };
  298. };
  299. var mouseDown = exports.mouseDown = handsontableMouseTriggerFactory('mousedown');
  300. var mouseMove = exports.mouseMove = handsontableMouseTriggerFactory('mousemove');
  301. var mouseOver = exports.mouseOver = handsontableMouseTriggerFactory('mouseover');
  302. var mouseUp = exports.mouseUp = handsontableMouseTriggerFactory('mouseup');
  303. function mouseDoubleClick(element) {
  304. mouseDown(element);
  305. mouseUp(element);
  306. mouseDown(element);
  307. mouseUp(element);
  308. };
  309. var mouseRightDown = exports.mouseRightDown = handsontableMouseTriggerFactory('mousedown', 3);
  310. var mouseRightUp = exports.mouseRightUp = handsontableMouseTriggerFactory('mouseup', 3);
  311. /**
  312. * Returns a function that triggers a key event
  313. * @param {String} type Event type
  314. * @return {Function}
  315. */
  316. function handsontableKeyTriggerFactory(type) {
  317. return function (key, extend) {
  318. var ev = {}; // $.Event(type);
  319. if (typeof key === 'string') {
  320. if (key.indexOf('shift+') > -1) {
  321. key = key.substring(6);
  322. ev.shiftKey = true;
  323. }
  324. if (key.indexOf('ctrl+') > -1) {
  325. key = key.substring(5);
  326. ev.ctrlKey = true;
  327. ev.metaKey = true;
  328. }
  329. switch (key) {
  330. case 'tab':
  331. ev.keyCode = 9;
  332. break;
  333. case 'enter':
  334. ev.keyCode = 13;
  335. break;
  336. case 'esc':
  337. ev.keyCode = 27;
  338. break;
  339. case 'f2':
  340. ev.keyCode = 113;
  341. break;
  342. case 'arrow_left':
  343. ev.keyCode = 37;
  344. break;
  345. case 'arrow_up':
  346. ev.keyCode = 38;
  347. break;
  348. case 'arrow_right':
  349. ev.keyCode = 39;
  350. break;
  351. case 'arrow_down':
  352. ev.keyCode = 40;
  353. break;
  354. case 'ctrl':
  355. ev.keyCode = 17;
  356. break;
  357. case 'shift':
  358. ev.keyCode = 16;
  359. break;
  360. case 'backspace':
  361. ev.keyCode = 8;
  362. break;
  363. case 'delete':
  364. ev.keyCode = 46;
  365. break;
  366. case 'space':
  367. ev.keyCode = 32;
  368. break;
  369. case 'x':
  370. ev.keyCode = 88;
  371. break;
  372. case 'c':
  373. ev.keyCode = 67;
  374. break;
  375. case 'v':
  376. ev.keyCode = 86;
  377. break;
  378. default:
  379. throw new Error('Unrecognised key name: ' + key);
  380. }
  381. } else if (typeof key === 'number') {
  382. ev.keyCode = key;
  383. }
  384. // ev.originalEvent = {}; //needed as long Handsontable searches for event.originalEvent
  385. $.extend(ev, extend);
  386. $(document.activeElement).simulate(type, ev);
  387. };
  388. };
  389. var keyDown = exports.keyDown = handsontableKeyTriggerFactory('keydown');
  390. var keyUp = exports.keyUp = handsontableKeyTriggerFactory('keyup');
  391. /**
  392. * Presses keyDown, then keyUp
  393. */
  394. function keyDownUp(key, extend) {
  395. if (typeof key === 'string' && key.indexOf('shift+') > -1) {
  396. keyDown('shift');
  397. }
  398. keyDown(key, extend);
  399. keyUp(key, extend);
  400. if (typeof key === 'string' && key.indexOf('shift+') > -1) {
  401. keyUp('shift');
  402. }
  403. };
  404. /**
  405. * Returns current value of the keyboard proxy textarea
  406. * @return {String}
  407. */
  408. function keyProxy() {
  409. return spec().$container.find('textarea.handsontableInput');
  410. };
  411. function serveImmediatePropagation(event) {
  412. if (event != null && event.isImmediatePropagationEnabled == null) {
  413. event.stopImmediatePropagation = function () {
  414. this.isImmediatePropagationEnabled = false;
  415. this.cancelBubble = true;
  416. };
  417. event.isImmediatePropagationEnabled = true;
  418. event.isImmediatePropagationStopped = function () {
  419. return !this.isImmediatePropagationEnabled;
  420. };
  421. }
  422. return event;
  423. };
  424. function autocompleteEditor() {
  425. return spec().$container.find('.handsontableInput');
  426. };
  427. /**
  428. * Sets text cursor inside keyboard proxy
  429. */
  430. function setCaretPosition(pos) {
  431. var el = keyProxy()[0];
  432. if (el.setSelectionRange) {
  433. el.focus();
  434. el.setSelectionRange(pos, pos);
  435. } else if (el.createTextRange) {
  436. var range = el.createTextRange();
  437. range.collapse(true);
  438. range.moveEnd('character', pos);
  439. range.moveStart('character', pos);
  440. range.select();
  441. }
  442. };
  443. /**
  444. * Returns autocomplete instance
  445. */
  446. function autocomplete() {
  447. return spec().$container.find('.autocompleteEditor');
  448. };
  449. /**
  450. * Triggers paste string on current selection
  451. */
  452. function triggerPaste(str) {
  453. spec().$container.data('handsontable').copyPaste.triggerPaste(null, str);
  454. };
  455. /**
  456. * Calls a method in current Handsontable instance, returns its output
  457. * @param method
  458. * @return {Function}
  459. */
  460. function handsontableMethodFactory(method) {
  461. return function () {
  462. var _instance;
  463. var instance;
  464. try {
  465. instance = spec().$container.handsontable('getInstance');
  466. } catch (err) {
  467. console.error(err);
  468. }
  469. if (instance) {
  470. if (method === 'destroy') {
  471. spec().$container.removeData();
  472. }
  473. } else {
  474. if (method === 'destroy') {
  475. return; // we can forgive this... maybe it was destroyed in the test
  476. }
  477. throw new Error('Something wrong with the test spec: Handsontable instance not found');
  478. }
  479. return (_instance = instance)[method].apply(_instance, arguments);
  480. };
  481. };
  482. var addHook = exports.addHook = handsontableMethodFactory('addHook');
  483. var alter = exports.alter = handsontableMethodFactory('alter');
  484. var colToProp = exports.colToProp = handsontableMethodFactory('colToProp');
  485. var countCols = exports.countCols = handsontableMethodFactory('countCols');
  486. var countRows = exports.countRows = handsontableMethodFactory('countRows');
  487. var deselectCell = exports.deselectCell = handsontableMethodFactory('deselectCell');
  488. var destroy = exports.destroy = handsontableMethodFactory('destroy');
  489. var destroyEditor = exports.destroyEditor = handsontableMethodFactory('destroyEditor');
  490. var getActiveEditor = exports.getActiveEditor = handsontableMethodFactory('getActiveEditor');
  491. var getCell = exports.getCell = handsontableMethodFactory('getCell');
  492. var getCellEditor = exports.getCellEditor = handsontableMethodFactory('getCellEditor');
  493. var getCellMeta = exports.getCellMeta = handsontableMethodFactory('getCellMeta');
  494. var getCellMetaAtRow = exports.getCellMetaAtRow = handsontableMethodFactory('getCellMetaAtRow');
  495. var getCellRenderer = exports.getCellRenderer = handsontableMethodFactory('getCellRenderer');
  496. var getCellsMeta = exports.getCellsMeta = handsontableMethodFactory('getCellsMeta');
  497. var getCellValidator = exports.getCellValidator = handsontableMethodFactory('getCellValidator');
  498. var getColHeader = exports.getColHeader = handsontableMethodFactory('getColHeader');
  499. var getCopyableData = exports.getCopyableData = handsontableMethodFactory('getCopyableData');
  500. var getCopyableText = exports.getCopyableText = handsontableMethodFactory('getCopyableText');
  501. var getData = exports.getData = handsontableMethodFactory('getData');
  502. var getDataAtCell = exports.getDataAtCell = handsontableMethodFactory('getDataAtCell');
  503. var getDataAtCol = exports.getDataAtCol = handsontableMethodFactory('getDataAtCol');
  504. var getDataAtRow = exports.getDataAtRow = handsontableMethodFactory('getDataAtRow');
  505. var getDataAtRowProp = exports.getDataAtRowProp = handsontableMethodFactory('getDataAtRowProp');
  506. var getDataType = exports.getDataType = handsontableMethodFactory('getDataType');
  507. var getInstance = exports.getInstance = handsontableMethodFactory('getInstance');
  508. var getRowHeader = exports.getRowHeader = handsontableMethodFactory('getRowHeader');
  509. var getSelected = exports.getSelected = handsontableMethodFactory('getSelected');
  510. var getSourceData = exports.getSourceData = handsontableMethodFactory('getSourceData');
  511. var getSourceDataArray = exports.getSourceDataArray = handsontableMethodFactory('getSourceDataArray');
  512. var getSourceDataAtCell = exports.getSourceDataAtCell = handsontableMethodFactory('getSourceDataAtCell');
  513. var getSourceDataAtCol = exports.getSourceDataAtCol = handsontableMethodFactory('getSourceDataAtCol');
  514. var getSourceDataAtRow = exports.getSourceDataAtRow = handsontableMethodFactory('getSourceDataAtRow');
  515. var getValue = exports.getValue = handsontableMethodFactory('getValue');
  516. var loadData = exports.loadData = handsontableMethodFactory('loadData');
  517. var populateFromArray = exports.populateFromArray = handsontableMethodFactory('populateFromArray');
  518. var propToCol = exports.propToCol = handsontableMethodFactory('propToCol');
  519. var removeCellMeta = exports.removeCellMeta = handsontableMethodFactory('removeCellMeta');
  520. var render = exports.render = handsontableMethodFactory('render');
  521. var selectCell = exports.selectCell = handsontableMethodFactory('selectCell');
  522. var setCellMeta = exports.setCellMeta = handsontableMethodFactory('setCellMeta');
  523. var setDataAtCell = exports.setDataAtCell = handsontableMethodFactory('setDataAtCell');
  524. var setDataAtRowProp = exports.setDataAtRowProp = handsontableMethodFactory('setDataAtRowProp');
  525. var spliceCellsMeta = exports.spliceCellsMeta = handsontableMethodFactory('spliceCellsMeta');
  526. var spliceCol = exports.spliceCol = handsontableMethodFactory('spliceCol');
  527. var spliceRow = exports.spliceRow = handsontableMethodFactory('spliceRow');
  528. var updateSettings = exports.updateSettings = handsontableMethodFactory('updateSettings');
  529. var countSourceRows = exports.countSourceRows = handsontableMethodFactory('countSourceRows');
  530. var countSourceCols = exports.countSourceCols = handsontableMethodFactory('countSourceCols');
  531. var countEmptyRows = exports.countEmptyRows = handsontableMethodFactory('countEmptyRows');
  532. var countEmptyCols = exports.countEmptyCols = handsontableMethodFactory('countEmptyCols');
  533. /**
  534. * Returns column width for HOT container
  535. * @param $elem
  536. * @param col
  537. * @returns {Number}
  538. */
  539. function colWidth($elem, col) {
  540. var TR = $elem[0].querySelector('TBODY TR');
  541. var cell;
  542. if (TR) {
  543. cell = TR.querySelectorAll('TD')[col];
  544. } else {
  545. cell = $elem[0].querySelector('THEAD TR').querySelectorAll('TH')[col];
  546. }
  547. if (!cell) {
  548. throw new Error('Cannot find table column of index \'' + col + '\'');
  549. }
  550. return cell.offsetWidth;
  551. }
  552. /**
  553. * Returns row height for HOT container
  554. * @param $elem
  555. * @param row
  556. * @returns {Number}
  557. */
  558. function rowHeight($elem, row) {
  559. var TD;
  560. if (row >= 0) {
  561. TD = $elem[0].querySelector('tbody tr:nth-child(' + (row + 1) + ') td');
  562. } else {
  563. TD = $elem[0].querySelector('thead tr:nth-child(' + Math.abs(row) + ')');
  564. }
  565. if (!TD) {
  566. throw new Error('Cannot find table row of index \'' + row + '\'');
  567. }
  568. return Handsontable.dom.outerHeight(TD);
  569. }
  570. /**
  571. * Returns value that has been rendered in table cell
  572. * @param {Number} trIndex
  573. * @param {Number} tdIndex
  574. * @returns {String}
  575. */
  576. function getRenderedValue(trIndex, tdIndex) {
  577. return spec().$container.find('tbody tr').eq(trIndex).find('td').eq(tdIndex).html();
  578. }
  579. /**
  580. * Returns nodes that have been rendered in table cell
  581. * @param {Number} trIndex
  582. * @param {Number} tdIndex
  583. * @returns {String}
  584. */
  585. function getRenderedContent(trIndex, tdIndex) {
  586. return spec().$container.find('tbody tr').eq(trIndex).find('td').eq(tdIndex).children();
  587. }
  588. /**
  589. * Create numerical data values for the table
  590. * @param rowCount
  591. * @param colCount
  592. * @returns {Array}
  593. */
  594. function createNumericData(rowCount, colCount) {
  595. rowCount = typeof rowCount === 'number' ? rowCount : 100;
  596. colCount = typeof colCount === 'number' ? colCount : 4;
  597. var rows = [],
  598. i,
  599. j;
  600. for (i = 0; i < rowCount; i++) {
  601. var row = [];
  602. for (j = 0; j < colCount; j++) {
  603. row.push(i + 1);
  604. }
  605. rows.push(row);
  606. }
  607. return rows;
  608. }
  609. /**
  610. * Model factory, which creates object with private properties, accessible by setters and getters.
  611. * Created for the purpose of testing HOT with Backbone-like Models
  612. * @param opts
  613. * @returns {{}}
  614. * @constructor
  615. */
  616. function Model(opts) {
  617. var obj = {};
  618. var _data = $.extend({
  619. id: undefined,
  620. name: undefined,
  621. address: undefined
  622. }, opts);
  623. obj.attr = function (name, value) {
  624. if (typeof value === 'undefined') {
  625. return this.get(name);
  626. }
  627. return this.set(name, value);
  628. };
  629. obj.get = function (name) {
  630. return _data[name];
  631. };
  632. obj.set = function (name, value) {
  633. _data[name] = value;
  634. return this;
  635. };
  636. return obj;
  637. }
  638. /**
  639. * Factory which produces an accessor for objects of type "Model" (see above).
  640. * This function should be used to create accessor for a given property name and pass it as `data` option in column
  641. * configuration.
  642. *
  643. * @param name - name of the property for which an accessor function will be created
  644. * @returns {Function}
  645. */
  646. function createAccessorForProperty(name) {
  647. return function (obj, value) {
  648. return obj.attr(name, value);
  649. };
  650. }
  651. function resizeColumn(displayedColumnIndex, width) {
  652. var $container = spec().$container;
  653. var $th = $container.find('thead tr:eq(0) th:eq(' + displayedColumnIndex + ')');
  654. $th.simulate('mouseover');
  655. var $resizer = $container.find('.manualColumnResizer');
  656. var resizerPosition = $resizer.position();
  657. $resizer.simulate('mousedown', {
  658. clientX: resizerPosition.left
  659. });
  660. var delta = width - $th.width() - 2;
  661. var newPosition = resizerPosition.left + delta;
  662. $resizer.simulate('mousemove', {
  663. clientX: newPosition
  664. });
  665. $resizer.simulate('mouseup');
  666. }
  667. function resizeRow(displayedRowIndex, height) {
  668. var $container = spec().$container;
  669. var $th = $container.find('tbody tr:eq(' + displayedRowIndex + ') th:eq(0)');
  670. $th.simulate('mouseover');
  671. var $resizer = $container.find('.manualRowResizer');
  672. var resizerPosition = $resizer.position();
  673. $resizer.simulate('mousedown', {
  674. clientY: resizerPosition.top
  675. });
  676. var delta = height - $th.height() - 2;
  677. if (delta < 0) {
  678. delta = 0;
  679. }
  680. $resizer.simulate('mousemove', {
  681. clientY: resizerPosition.top + delta
  682. });
  683. $resizer.simulate('mouseup');
  684. }
  685. function moveSecondDisplayedRowBeforeFirstRow(container, secondDisplayedRowIndex) {
  686. var $mainContainer = container.parents('.handsontable').not('[class*=clone]').not('[class*=master]').first(),
  687. $rowHeaders = container.find('tbody tr th'),
  688. $firstRowHeader = $rowHeaders.eq(secondDisplayedRowIndex - 1),
  689. $secondRowHeader = $rowHeaders.eq(secondDisplayedRowIndex);
  690. $secondRowHeader.simulate('mouseover');
  691. var $manualRowMover = $mainContainer.find('.manualRowMover');
  692. if ($manualRowMover.length) {
  693. $manualRowMover.simulate('mousedown', {
  694. clientY: $manualRowMover[0].getBoundingClientRect().top
  695. });
  696. $manualRowMover.simulate('mousemove', {
  697. clientY: $manualRowMover[0].getBoundingClientRect().top - 20
  698. });
  699. $firstRowHeader.simulate('mouseover');
  700. $secondRowHeader.simulate('mouseup');
  701. }
  702. }
  703. function moveFirstDisplayedRowAfterSecondRow(container, firstDisplayedRowIndex) {
  704. var $mainContainer = container.parents('.handsontable').not('[class*=clone]').not('[class*=master]').first(),
  705. $rowHeaders = container.find('tbody tr th'),
  706. $firstRowHeader = $rowHeaders.eq(firstDisplayedRowIndex),
  707. $secondRowHeader = $rowHeaders.eq(firstDisplayedRowIndex + 1);
  708. $secondRowHeader.simulate('mouseover');
  709. var $manualRowMover = $mainContainer.find('.manualRowMover');
  710. if ($manualRowMover.length) {
  711. $manualRowMover.simulate('mousedown', {
  712. clientY: $manualRowMover[0].getBoundingClientRect().top
  713. });
  714. $manualRowMover.simulate('mousemove', {
  715. clientY: $manualRowMover[0].getBoundingClientRect().top + 20
  716. });
  717. $firstRowHeader.simulate('mouseover');
  718. $secondRowHeader.simulate('mouseup');
  719. }
  720. }
  721. function swapDisplayedColumns(container, from, to) {
  722. var $mainContainer = container.parents('.handsontable').not('[class*=clone]').not('[class*=master]').first();
  723. var $colHeaders = container.find('thead tr:eq(0) th');
  724. var $to = $colHeaders.eq(to);
  725. var $from = $colHeaders.eq(from);
  726. // Enter the second column header
  727. $from.simulate('mouseover');
  728. var $manualColumnMover = $mainContainer.find('.manualColumnMover');
  729. // Grab the second column
  730. $manualColumnMover.simulate('mousedown', {
  731. pageX: $manualColumnMover[0].getBoundingClientRect().left
  732. });
  733. // Drag the second column over the first column
  734. $manualColumnMover.simulate('mousemove', {
  735. pageX: $manualColumnMover[0].getBoundingClientRect().left - 20
  736. });
  737. $to.simulate('mouseover');
  738. // Drop the second column
  739. $from.simulate('mouseup');
  740. }
  741. function triggerTouchEvent(type, target, pageX, pageY) {
  742. var e = document.createEvent('TouchEvent');
  743. var targetCoords = target.getBoundingClientRect();
  744. var touches;
  745. var targetTouches;
  746. var changedTouches;
  747. if (!pageX && !pageY) {
  748. pageX = parseInt(targetCoords.left + 3, 10);
  749. pageY = parseInt(targetCoords.top + 3, 10);
  750. }
  751. var touch = document.createTouch(window, target, 0, pageX, pageY, pageX, pageY);
  752. if (type == 'touchend') {
  753. touches = document.createTouchList();
  754. targetTouches = document.createTouchList();
  755. changedTouches = document.createTouchList(touch);
  756. } else {
  757. touches = document.createTouchList(touch);
  758. targetTouches = document.createTouchList(touch);
  759. changedTouches = document.createTouchList(touch);
  760. }
  761. e.initTouchEvent(type, true, true, window, null, 0, 0, 0, 0, false, false, false, false, touches, targetTouches, changedTouches, 1, 0);
  762. target.dispatchEvent(e);
  763. };
  764. /***/ }),
  765. /***/ 77:
  766. /***/ (function(module, exports, __webpack_require__) {
  767. "use strict";
  768. exports.__esModule = true;
  769. exports.spec = spec;
  770. /* eslint-disable import/prefer-default-export */
  771. var currentSpec;
  772. function spec() {
  773. return currentSpec;
  774. };
  775. beforeEach(function () {
  776. currentSpec = this;
  777. var matchers = {
  778. toBeInArray: function toBeInArray() {
  779. return {
  780. compare: function compare(actual, expected) {
  781. return {
  782. pass: Array.isArray(expected) && expected.indexOf(actual) > -1
  783. };
  784. }
  785. };
  786. },
  787. toBeFunction: function toBeFunction() {
  788. return {
  789. compare: function compare(actual, expected) {
  790. return {
  791. pass: typeof actual === 'function'
  792. };
  793. }
  794. };
  795. },
  796. toBeAroundValue: function toBeAroundValue() {
  797. return {
  798. compare: function compare(actual, expected, diff) {
  799. diff = diff || 1;
  800. var pass = actual >= expected - diff && actual <= expected + diff;
  801. var message = 'Expected ' + actual + ' to be around ' + expected + ' (between ' + (expected - diff) + ' and ' + (expected + diff) + ')';
  802. if (!pass) {
  803. message = 'Expected ' + actual + ' NOT to be around ' + expected + ' (between ' + (expected - diff) + ' and ' + (expected + diff) + ')';
  804. }
  805. return {
  806. pass: pass,
  807. message: message
  808. };
  809. }
  810. };
  811. }
  812. };
  813. jasmine.addMatchers(matchers);
  814. if (document.activeElement && document.activeElement != document.body) {
  815. document.activeElement.blur();
  816. } else if (!document.activeElement) {
  817. // IE
  818. document.body.focus();
  819. }
  820. });
  821. afterEach(function () {
  822. window.scrollTo(0, 0);
  823. });
  824. /***/ })
  825. /******/ });
  826. //# sourceMappingURL=helpers.entry.js.map