@folo/auto-position
Version:
79 lines (64 loc) • 3.06 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.autoPosition = factory());
}(this, (function () {
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var AutoPositionCell = /*#__PURE__*/function () {
function AutoPositionCell() {
_classCallCheck(this, AutoPositionCell);
// store cells number according to its name
this.cellPositions = {};
this.biggestRowItem = 0;
}
/**
* Auto set the row number
* If we don't have row then take the highest value
* depending on biggestRowItem which updated with each grid item
* Otherwise set the row do you have and update biggestRowItem
*
* This helps to assign position value according to highest value
* If we start from 10, the next will be 11 and so on.
*
* @param {object} GridItem - GridItem that should be register and calculated
* @param {string} GridItem.key unique key generated in GridItem
* @param {number} GridItem.row
* @param {number} GridItem.toRow
* @return {number} row position
*/
_createClass(AutoPositionCell, [{
key: "autoPosition",
value: function autoPosition(_ref) {
var key = _ref.key,
row = _ref.row,
toRow = _ref.toRow;
var parseRow = parseInt(row, 10);
var parseToRow = parseInt(toRow, 10);
if (parseToRow && parseRow) {
this.cellPositions[key] = parseRow;
var bigger = parseToRow > parseRow ? parseToRow : parseRow;
if (bigger > this.biggestRowItem) {
this.biggestRowItem = bigger;
}
} else if (parseRow) {
this.cellPositions[key] = parseRow;
if (parseRow > this.biggestRowItem) {
this.biggestRowItem = parseRow;
}
} else {
this.biggestRowItem += 1;
this.cellPositions[key] = this.biggestRowItem;
if (parseToRow > this.biggestRowItem) {
this.biggestRowItem = parseToRow;
}
}
return this.cellPositions[key];
}
}]);
return AutoPositionCell;
}();
return AutoPositionCell;
})));
//# sourceMappingURL=autoPosition.umd.js.map