fix: grid view count

This commit is contained in:
paul
2025-03-22 11:11:19 +05:30
parent 22718369e1
commit c2b0532e96
26 changed files with 122 additions and 62 deletions

View File

@@ -69,4 +69,29 @@ export function convertObjectToKeyValueString(obj){
return Object.entries(obj)
.map(([key, value]) => `${key}=${value}`)
.join(', ')
}
/**
*
* @param {HTMLElement} widget
* @param {HTMLElement} gridContainer
* @returns
*/
export const getGridPosition = (widget, gridContainer) => {
if (!widget || !gridContainer) return null;
const widgets = Array.from(gridContainer.children); // Get all grid items
// const index = widgets.indexOf(widget);
const widgetIndex = widgets.indexOf(widget);
if (widgetIndex === -1) return null; // Widget not found
const gridStyles = getComputedStyle(gridContainer);
const columnCount = gridStyles.gridTemplateColumns.split(' ').length;
const row = Math.floor(widgetIndex / columnCount) + 1;
const column = (widgetIndex % columnCount) + 1;
return { row, column };
}