source: imaps-frontend/node_modules/react-tiles-dnd/esm/tile-layout/strategies/move.js.map

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 9.7 KB
Line 
1{"version":3,"file":"move.js","sources":["../../../../src/tile-layout/strategies/move.ts"],"sourcesContent":["import { StrategyInterface, TilePositionInfo } from '../model';\nimport * as TilesTableUtils from '../table-utils/tiles-table';\nimport * as TableUtils from '../table-utils/table';\nimport * as TilesUtils from '../table-utils/tiles';\n\n/**\n * Calculates the new table configuration while the tiles are moving\n * @param offsetX\n * @param offsetY\n * @returns\n */\nconst dragMove: StrategyInterface = {\n onDragMove: ({ offsetX, offsetY, config, state, table, canAcceptDrop }) => {\n const { elementHeight, elementWidth, columns } = config;\n const {\n draggingTile,\n dragPosition,\n dropTargetTile,\n droppable,\n start,\n tiles,\n } = state;\n\n if (!draggingTile || !dragPosition || !start || !tiles) return;\n\n const x = start.col * elementWidth + offsetX + dragPosition.x;\n const y = start.row * elementHeight + offsetY + dragPosition.y;\n\n //find the position of the tile in the grid\n const cell = TableUtils.pointToLocation(table, x, y, config);\n const tsize = TableUtils.tableSize(table);\n\n //console.log('data:', { x, y, cell, start, draggingTile });\n\n //try to see if we're touching a hot point\n if (cell.col <= tsize.cols && cell.row <= tsize.rows) {\n //find the touched tile within the move\n\n const touchedTile = table[cell.row][cell.col];\n if (!touchedTile || touchedTile.data === draggingTile.data) return;\n\n //get the touchpoint of the touched tile\n const touchPoint = TilesUtils.getTileTouchPoint(\n draggingTile,\n touchedTile,\n {\n x,\n y,\n },\n config\n );\n if (!touchPoint) return;\n\n //console.log('HIT TOUCHPOINT', { table, tiles });\n\n if (touchPoint === 'center') {\n if (touchedTile === dropTargetTile)\n return {\n dropTargetTile,\n droppable,\n };\n if (canAcceptDrop(draggingTile, touchedTile))\n return { dropTargetTile: touchedTile, droppable: true };\n return;\n }\n\n //a touchpoint has been identified\n\n const rowDisplacement = Math.floor(dragPosition.y / elementHeight);\n const colDisplacement = Math.floor(dragPosition.x / elementWidth);\n\n //calculate the new dragged tile location. This depends on the touched side.\n const newDragTileLocation = TableUtils.trimLocation(\n table,\n touchPoint === 'right'\n ? {\n col: cell.col - (draggingTile.colSpan - 1),\n row: cell.row - rowDisplacement,\n }\n : touchPoint === 'left'\n ? {\n col: cell.col,\n row: cell.row - rowDisplacement,\n }\n : touchPoint === 'top'\n ? {\n col: cell.col - colDisplacement,\n row: cell.row,\n }\n : /*touchPoint === 'bottom'*/ {\n col: cell.col - colDisplacement,\n row: cell.row - (draggingTile.rowSpan - 1),\n }\n );\n\n /*\n console.log(\n 'Effective location:',\n newDragTileLocation,\n touchedTile,\n touchPoint,\n state\n );\n */\n\n //identify all hover tiles (excluding ourselves)\n const hoverTiles = TilesTableUtils.interceptTiles(\n table,\n newDragTileLocation.row,\n newDragTileLocation.col,\n draggingTile.rowSpan,\n draggingTile.colSpan\n ).filter(tiles => tiles.data !== draggingTile.data);\n\n if (!hoverTiles.length) {\n return;\n }\n\n //console.log('hover tiles:', hoverTiles);\n\n //create a table with the remaining tiles\n const otherTiles = tiles.filter(\n tile =>\n tile.data !== draggingTile.data &&\n !hoverTiles.find(t => t.data === tile.data)\n );\n const newDraggingTile = {\n ...draggingTile,\n ...newDragTileLocation,\n };\n\n let checkTable = TableUtils.newTable(\n tsize.rows + draggingTile.rowSpan - 1,\n tsize.cols,\n 0\n );\n otherTiles.forEach(tile => {\n checkTable = TableUtils.placeInTable(tile, 1, checkTable);\n });\n\n /*\n console.log('checktable dump:');\n checkTable.forEach(row => {\n console.log(row.join(''));\n });\n */\n\n //try to fit the dragging tile in the current location\n if (!TableUtils.fitsInTable(newDraggingTile, checkTable)) {\n //console.log('new drag tile does not fit');\n return;\n }\n checkTable = TableUtils.placeInTable(newDraggingTile, 1, checkTable);\n\n /*\n console.log('checktable dump with drag tile:');\n checkTable.forEach(row => {\n console.log(row.join(''));\n });\n */\n\n const repositionedHoverTiles: TilePositionInfo<any>[] = [];\n if (\n hoverTiles.find(tile => {\n const newPosition = TableUtils.findFirstFittingPosition(\n tile,\n checkTable\n );\n //console.log('fitting', { tile, newPosition });\n if (!newPosition) return true;\n const repositionedTile = { ...tile, ...newPosition };\n repositionedHoverTiles.push(repositionedTile);\n checkTable = TableUtils.placeInTable(repositionedTile, 1, checkTable);\n return false;\n })\n ) {\n //console.log('repositioning failed');\n return;\n }\n\n const reorderedTiles = [\n ...repositionedHoverTiles,\n ...otherTiles,\n newDraggingTile,\n ].sort((a, b) => a.col + a.row * columns - (b.col + b.row * columns));\n return {\n draggingTile: newDraggingTile,\n tiles: reorderedTiles,\n };\n }\n },\n onDragEnd: () => undefined,\n};\n\nexport default dragMove;\n"],"names":["TableUtils.pointToLocation","TableUtils.tableSize","TilesUtils.getTileTouchPoint","TableUtils.trimLocation","TilesTableUtils.interceptTiles","TableUtils.newTable","TableUtils.placeInTable","TableUtils.fitsInTable","TableUtils.findFirstFittingPosition"],"mappings":";;;;;AAKA;;;;;;IAMM,QAAQ,GAAsB;IAClC,UAAU,EAAE,UAAC,EAAyD;YAAvD,OAAO,aAAA,EAAE,OAAO,aAAA,EAAE,MAAM,YAAA,EAAE,KAAK,WAAA,EAAE,KAAK,WAAA,EAAE,aAAa,mBAAA;QAC1D,IAAA,aAAa,GAA4B,MAAM,cAAlC,EAAE,YAAY,GAAc,MAAM,aAApB,EAAE,OAAO,GAAK,MAAM,QAAX,CAAY;QAEtD,IAAA,YAAY,GAMV,KAAK,aANK,EACZ,YAAY,GAKV,KAAK,aALK,EACZ,cAAc,GAIZ,KAAK,eAJO,EACd,SAAS,GAGP,KAAK,UAHE,EACT,KAAK,GAEH,KAAK,MAFF,EACL,KAAK,GACH,KAAK,MADF,CACG;QAEV,IAAI,CAAC,YAAY,IAAI,CAAC,YAAY,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK;YAAE,OAAO;QAE/D,IAAM,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,YAAY,GAAG,OAAO,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