columnsMapper.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 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; }; }();
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. import arrayMapper from './../../mixins/arrayMapper';
  4. import { arrayFilter } from './../../helpers/array';
  5. import { mixin } from './../../helpers/object';
  6. import { rangeEach } from './../../helpers/number';
  7. /**
  8. * @class ColumnsMapper
  9. * @plugin ManualColumnMove
  10. */
  11. var ColumnsMapper = function () {
  12. function ColumnsMapper(manualColumnMove) {
  13. _classCallCheck(this, ColumnsMapper);
  14. /**
  15. * Instance of ManualColumnMove plugin.
  16. *
  17. * @type {ManualColumnMove}
  18. */
  19. this.manualColumnMove = manualColumnMove;
  20. }
  21. /**
  22. * Reset current map array and create new one.
  23. *
  24. * @param {Number} [length] Custom generated map length.
  25. */
  26. _createClass(ColumnsMapper, [{
  27. key: 'createMap',
  28. value: function createMap(length) {
  29. var _this = this;
  30. var originLength = length === void 0 ? this._arrayMap.length : length;
  31. this._arrayMap.length = 0;
  32. rangeEach(originLength - 1, function (itemIndex) {
  33. _this._arrayMap[itemIndex] = itemIndex;
  34. });
  35. }
  36. /**
  37. * Destroy class.
  38. */
  39. }, {
  40. key: 'destroy',
  41. value: function destroy() {
  42. this._arrayMap = null;
  43. }
  44. /**
  45. * Moving elements in columnsMapper.
  46. *
  47. * @param {Number} from Column index to move.
  48. * @param {Number} to Target index.
  49. */
  50. }, {
  51. key: 'moveColumn',
  52. value: function moveColumn(from, to) {
  53. var indexToMove = this._arrayMap[from];
  54. this._arrayMap[from] = null;
  55. this._arrayMap.splice(to, 0, indexToMove);
  56. }
  57. /**
  58. * Clearing arrayMap from `null` entries.
  59. */
  60. }, {
  61. key: 'clearNull',
  62. value: function clearNull() {
  63. this._arrayMap = arrayFilter(this._arrayMap, function (i) {
  64. return i !== null;
  65. });
  66. }
  67. }]);
  68. return ColumnsMapper;
  69. }();
  70. mixin(ColumnsMapper, arrayMapper);
  71. export default ColumnsMapper;