source: imaps-frontend/node_modules/react-tiles-dnd/esm/tile-layout/table-utils/tiles-table.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import { __assign } from 'tslib';
2import { isEmptyRow, tableSize, newTable, findFirstFittingPosition, placeInTable } from './table.js';
3
4var interceptTiles = function (table, startRow, startCol, rowSpan, colSpan) {
5 var interceptTiles = [];
6 var _a = tableSize(table), rows = _a.rows, cols = _a.cols;
7 for (var row = startRow; row < startRow + rowSpan; row++) {
8 if (row >= rows)
9 continue;
10 var _loop_1 = function (col) {
11 if (col >= cols)
12 return "continue";
13 var cell = table[row][col];
14 if (cell && !interceptTiles.find(function (t) { return t.data === cell.data; })) {
15 interceptTiles.push(cell);
16 }
17 };
18 for (var col = startCol; col < startCol + colSpan; col++) {
19 _loop_1(col);
20 }
21 }
22 return interceptTiles.sort(function (a, b) { return a.col + a.row * cols - (b.col + b.row * cols); });
23};
24var tableToTilesList = function (table) {
25 var _a = tableSize(table), rows = _a.rows, cols = _a.cols;
26 return interceptTiles(table, 0, 0, rows, cols);
27};
28var tilesListToTable = function (tiles, columns) {
29 var maxRows = tiles.reduce(function (memo, tile) { return memo + tile.rowSpan; }, 0);
30 var table = newTable(maxRows, columns, undefined);
31 tiles.forEach(function (tile) {
32 var position = findFirstFittingPosition(tile, table);
33 if (position) {
34 var fittedTile = __assign(__assign({}, tile), position);
35 table = placeInTable(fittedTile, fittedTile, table);
36 }
37 });
38 //trim the table
39 return table.filter(function (row) { return !isEmptyRow(row); });
40};
41
42export { interceptTiles, tableToTilesList, tilesListToTable };
43//# sourceMappingURL=tiles-table.js.map
Note: See TracBrowser for help on using the repository browser.