rowsMapper.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4. var _arrayMapper = require('./../../mixins/arrayMapper');
  5. var _arrayMapper2 = _interopRequireDefault(_arrayMapper);
  6. var _array = require('./../../helpers/array');
  7. var _object = require('./../../helpers/object');
  8. var _number = require('./../../helpers/number');
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11. /**
  12. * @class RowsMapper
  13. * @plugin ManualRowMove
  14. */
  15. var RowsMapper = function () {
  16. function RowsMapper(manualRowMove) {
  17. _classCallCheck(this, RowsMapper);
  18. /**
  19. * Instance of ManualRowMove plugin.
  20. *
  21. * @type {ManualRowMove}
  22. */
  23. this.manualRowMove = manualRowMove;
  24. }
  25. /**
  26. * Reset current map array and create new one.
  27. *
  28. * @param {Number} [length] Custom generated map length.
  29. */
  30. _createClass(RowsMapper, [{
  31. key: 'createMap',
  32. value: function createMap(length) {
  33. var _this = this;
  34. var originLength = length === void 0 ? this._arrayMap.length : length;
  35. this._arrayMap.length = 0;
  36. (0, _number.rangeEach)(originLength - 1, function (itemIndex) {
  37. _this._arrayMap[itemIndex] = itemIndex;
  38. });
  39. }
  40. /**
  41. * Destroy class.
  42. */
  43. }, {
  44. key: 'destroy',
  45. value: function destroy() {
  46. this._arrayMap = null;
  47. }
  48. /**
  49. * Moving elements in rowsMapper.
  50. *
  51. * @param {Number} from Row index to move.
  52. * @param {Number} to Target index.
  53. */
  54. }, {
  55. key: 'moveRow',
  56. value: function moveRow(from, to) {
  57. var indexToMove = this._arrayMap[from];
  58. this._arrayMap[from] = null;
  59. this._arrayMap.splice(to, 0, indexToMove);
  60. }
  61. /**
  62. * Clearing arrayMap from `null` entries.
  63. */
  64. }, {
  65. key: 'clearNull',
  66. value: function clearNull() {
  67. this._arrayMap = (0, _array.arrayFilter)(this._arrayMap, function (i) {
  68. return i !== null;
  69. });
  70. }
  71. }]);
  72. return RowsMapper;
  73. }();
  74. (0, _object.mixin)(RowsMapper, _arrayMapper2.default);
  75. exports.default = RowsMapper;