| 79 | * @returns |
| 80 | */ |
| 81 | export const getGridPosition = (widget, gridContainer) => { |
| 82 | if (!widget || !gridContainer) return null; |
| 83 | |
| 84 | const widgets = Array.from(gridContainer.children); // Get all grid items |
| 85 | // const index = widgets.indexOf(widget); |
| 86 | const widgetIndex = widgets.indexOf(widget); |
| 87 | |
| 88 | if (widgetIndex === -1) return null; // Widget not found |
| 89 | |
| 90 | const gridStyles = getComputedStyle(gridContainer); |
| 91 | const columnCount = gridStyles.gridTemplateColumns.split(' ').length; |
| 92 | |
| 93 | const row = Math.floor(widgetIndex / columnCount) + 1; |
| 94 | const column = (widgetIndex % columnCount) + 1; |
| 95 | |
| 96 | return { row, column }; |
| 97 | } |