/**
* Dashboard Manager
*
* Orchestrates the complete dashboard system by integrating:
* - GridEngine (positioning)
* - WidgetRegistry (widget definitions)
* - TabManager (multi-tab support)
* - DragDropHandler (drag widgets)
* - ResizeHandler (resize widgets)
* - EditModeManager (edit/view modes)
* - LayoutPersistence (save/load)
*
* Provides high-level API for widget and tab management.
*/
// Performance: Disable console logging (console.error still active)
// Temporarily enabled for debugging auto-arrange onResize issue
const DEBUG = true;
const console = DEBUG ? window.console : {
log: () => {},
warn: () => {},
error: window.console.error.bind(window.console)
};
import { GridEngine } from './gridEngine.js';
import { WidgetRegistry } from './widgetRegistry.js';
import { TabManager } from './tabManager.js';
import { DragDropHandler } from './dragDrop.js';
import { ResizeHandler } from './resizeHandler.js';
import { EditModeManager } from './editModeManager.js';
import { LayoutPersistence } from './layoutPersistence.js';
import { generateDefaultDashboard } from './defaultLayout.js';
/**
* @typedef {Object} DashboardConfig
* @property {number} columns - Grid column count (default: 12)
* @property {number} rowHeight - Grid row height in pixels (default: 80)
* @property {number} gap - Gap between widgets in pixels (default: 12)
* @property {number} debounceMs - Auto-save debounce delay (default: 500)
* @property {Function} onSave - Callback when layout saved
* @property {Function} onLoad - Callback when layout loaded
* @property {Function} onError - Callback on errors
*/
/**
* DashboardManager - Complete dashboard system orchestrator
*/
export class DashboardManager {
/**
* @param {HTMLElement} container - Main dashboard container element
* @param {DashboardConfig} config - Configuration options
*/
constructor(container, config = {}) {
if (!container) {
throw new Error('[DashboardManager] Container element is required');
}
this.container = container;
this.config = {
columns: config.columns || 12,
rowHeight: config.rowHeight || 5, // rem units for responsive scaling
gap: config.gap || 0.75, // rem units for responsive scaling
debounceMs: config.debounceMs || 500,
onSave: config.onSave,
onLoad: config.onLoad,
onError: config.onError,
...config
};
console.log('[DashboardManager] Constructor config:', {
rowHeight: this.config.rowHeight,
gap: this.config.gap,
columns: this.config.columns
});
// Dashboard state
this.currentTabId = null;
this.widgets = new Map(); // widgetId => { widget data, element, tab }
this.defaultLayout = null;
this.previousTrackerConfig = null; // For detecting config changes
// Dashboard data structure (for TabManager)
this.dashboard = {
tabs: [],
defaultTab: null
};
// System instances
this.gridEngine = null;
this.registry = null;
this.tabManager = null;
this.dragHandler = null;
this.resizeHandler = null;
this.editManager = null;
this.persistence = null;
// Container elements
this.gridContainer = null;
this.tabContainer = null;
this.resizeHandlesOverlay = null;
this.editControlsOverlay = null;
this.changeListeners = new Set();
console.log('[DashboardManager] Initialized');
}
/**
* Initialize all dashboard systems
*/
async init() {
console.log('[DashboardManager] Initializing systems...');
// Create container structure
this.createContainerStructure();
// Initialize Widget Registry (use provided registry or create new one)
this.registry = this.config.registry || new WidgetRegistry();
// Initialize Grid Engine (columns calculated dynamically)
this.gridEngine = new GridEngine({
rowHeight: this.config.rowHeight,
gap: this.config.gap,
container: this.gridContainer,
registry: this.registry, // Pass registry for maxAutoSize lookups
onColumnsChange: (newCols, oldCols) => {
console.log('[DashboardManager] Grid columns changed:', oldCols, '→', newCols);
// Auto-reflow current tab to optimize for new column count
const currentTab = this.tabManager.getTab(this.currentTabId);
if (currentTab && currentTab.widgets && currentTab.widgets.length > 0) {
console.log(`[DashboardManager] Auto-reflowing ${currentTab.widgets.length} widgets for ${newCols} columns`);
// Store current widget dimensions before auto-layout
const dimensionsBefore = new Map();
currentTab.widgets.forEach(widget => {
dimensionsBefore.set(widget.id, { w: widget.w, h: widget.h });
});
// Run auto-layout to reflow and expand widgets for new grid
// This prevents overlap and optimizes space usage
this.gridEngine.autoLayout(currentTab.widgets, { preserveOrder: true });
// Call onResize handlers for widgets whose dimensions changed
// This allows widgets to update internal layouts (e.g., User Attributes grid columns)
currentTab.widgets.forEach(widget => {
const before = dimensionsBefore.get(widget.id);
if (before && (before.w !== widget.w || before.h !== widget.h)) {
const widgetData = this.widgets.get(widget.id);
if (widgetData?.definition?.onResize && widgetData.element) {
console.log(`[DashboardManager] Calling onResize for ${widget.type} (${before.w}x${before.h} → ${widget.w}x${widget.h})`);
widgetData.definition.onResize(widgetData.element, widget.w, widget.h);
}
}
});
// Save changes
this.triggerAutoSave();
}
// Re-render all widgets with new layout
this.renderAllWidgets();
}
});
// Initialize Tab Manager with dashboard data structure
// Create default tab if no tabs exist
if (this.dashboard.tabs.length === 0) {
this.dashboard.tabs.push({
id: 'main',
name: 'Main',
icon: 'fa-solid fa-house',
order: 0,
widgets: []
});
this.dashboard.defaultTab = 'main';
}
this.tabManager = new TabManager(this.dashboard);
// Set current tab to active tab from TabManager
this.currentTabId = this.tabManager.activeTabId;
// Register tab change listener
this.tabManager.onChange((event, data) => {
if (event === 'activeTabChanged') {
this.onTabChange(data.tabId);
}
});
// Initialize Edit Mode Manager first (needed by drag/resize handlers)
this.editManager = new EditModeManager({
container: this.container,
editControlsOverlay: this.editControlsOverlay,
onSave: () => this.handleEditSave(),
onCancel: (originalLayout) => this.handleEditCancel(originalLayout),
onWidgetAdd: (type) => this.addWidget(type),
onWidgetDelete: (widgetId) => this.removeWidget(widgetId),
onWidgetSettings: (widgetId) => this.openWidgetSettings(widgetId)
});
// Initialize Drag & Drop (with editManager and dashboardManager references)
this.dragHandler = new DragDropHandler(this.gridEngine, {
showGrid: true,
enableSnap: true,
editManager: this.editManager,
dashboardManager: this
});
// Initialize Resize Handler (with editManager and overlay references)
this.resizeHandler = new ResizeHandler(this.gridEngine, {
minWidth: 1,
minHeight: 2,
maxWidth: 4, // Max 4 columns (will be clamped to actual column count)
maxHeight: 10,
editManager: this.editManager,
resizeHandlesOverlay: this.resizeHandlesOverlay
});
// Initialize Layout Persistence
this.persistence = new LayoutPersistence({
debounceMs: this.config.debounceMs,
onSave: (layout) => {
console.log('[DashboardManager] Layout saved');
if (this.config.onSave) this.config.onSave(layout);
},
onLoad: (layout) => {
console.log('[DashboardManager] Layout loaded');
if (this.config.onLoad) this.config.onLoad(layout);
},
onError: (error) => {
console.error('[DashboardManager] Error:', error);
if (this.config.onError) this.config.onError(error);
}
});
// Try to load saved layout
await this.loadLayout();
// Measure container width and set up responsive sizing
this.setupContainerSizing();
// Listen for tracker config changes (reactive integration)
document.addEventListener('rpg:trackerConfigChanged', (e) => {
console.log('[DashboardManager] Tracker config changed, refreshing widgets');
this.onTrackerConfigChanged(e.detail.config);
});
// Render tab navigation
this.renderTabs();
console.log('[DashboardManager] All systems initialized');
this.notifyChange('initialized');
}
/**
* Create dashboard container structure
*/
createContainerStructure() {
// Check if tabs and grid containers already exist (from template)
this.tabContainer = this.container.querySelector('#rpg-dashboard-tabs');
this.gridContainer = this.container.querySelector('#rpg-dashboard-grid');
// If they don't exist, create them (fallback for legacy/minimal setup)
if (!this.tabContainer) {
console.warn('[DashboardManager] Tab container not found in template, creating...');
this.tabContainer = document.createElement('div');
this.tabContainer.className = 'rpg-dashboard-tabs';
this.tabContainer.id = 'rpg-dashboard-tabs';
this.container.appendChild(this.tabContainer);
}
if (!this.gridContainer) {
console.warn('[DashboardManager] Grid container not found in template, creating...');
this.gridContainer = document.createElement('div');
this.gridContainer.className = 'rpg-dashboard-grid';
this.gridContainer.id = 'rpg-dashboard-grid';
this.gridContainer.style.position = 'relative';
this.gridContainer.style.minHeight = '600px';
this.container.appendChild(this.gridContainer);
}
// Create overlay containers for resize handles and edit controls
// These are positioned outside the widget DOM to prevent overflow/scrollbar issues
this.resizeHandlesOverlay = document.createElement('div');
this.resizeHandlesOverlay.id = 'rpg-resize-handles-overlay';
this.resizeHandlesOverlay.className = 'rpg-overlay-container';
this.resizeHandlesOverlay.style.cssText = 'position: absolute; inset: 0; pointer-events: none; z-index: 9999;';
this.gridContainer.appendChild(this.resizeHandlesOverlay);
this.editControlsOverlay = document.createElement('div');
this.editControlsOverlay.id = 'rpg-edit-controls-overlay';
this.editControlsOverlay.className = 'rpg-overlay-container';
this.editControlsOverlay.style.cssText = 'position: absolute; inset: 0; pointer-events: none; z-index: 10000;';
this.gridContainer.appendChild(this.editControlsOverlay);
console.log('[DashboardManager] Container structure ready (including overlays)');
}
/**
* Set up container sizing and responsive behavior
* Measures container width and sets up ResizeObserver
* Also listens for viewport resize to recalculate vw/vh positions
*/
setupContainerSizing() {
// Measure actual container width
const width = this.gridContainer.clientWidth || this.gridContainer.offsetWidth || 350;
console.log('[DashboardManager] Measured container width:', width);
// Set container width in GridEngine (triggers column calculation)
this.gridEngine.setContainerWidth(width);
// Set up ResizeObserver to track container width changes
if (typeof ResizeObserver !== 'undefined') {
this.resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
const newWidth = entry.contentRect.width;
console.log('[DashboardManager] Container resized to:', newWidth);
this.gridEngine.setContainerWidth(newWidth);
}
});
this.resizeObserver.observe(this.gridContainer);
console.log('[DashboardManager] ResizeObserver set up');
} else {
console.warn('[DashboardManager] ResizeObserver not supported, responsive sizing disabled');
}
// Listen for window resize to recalculate vh positions
// Viewport height changes affect vh calculations for vertical positioning
// Horizontal (%) automatically adapts to container width changes via ResizeObserver
this.viewportResizeHandler = () => {
console.log('[DashboardManager] Viewport resized, recalculating vh positions');
this.renderAllWidgets(); // Re-render with new vh values
};
window.addEventListener('resize', this.viewportResizeHandler);
console.log('[DashboardManager] Viewport resize listener added');
}
/**
* Migrate old 12-column layouts to new responsive grid
* Detects if any widgets have widths exceeding current column count
* and automatically runs auto-layout to fix them
*/
migrateOldLayouts() {
console.log('[DashboardManager] Checking for old layouts to migrate...');
let needsMigration = false;
// Check all tabs
this.dashboard.tabs.forEach(tab => {
if (!tab.widgets || tab.widgets.length === 0) return;
// Check if any widget has width exceeding current column count
tab.widgets.forEach(widget => {
if (widget.w > this.gridEngine.columns) {
console.warn(`[DashboardManager] Widget ${widget.id} has width ${widget.w} exceeding column count ${this.gridEngine.columns}`);
needsMigration = true;
}
});
if (needsMigration) {
console.log(`[DashboardManager] Migrating tab ${tab.id} to new responsive grid...`);
// Run auto-layout on this tab's widgets
this.gridEngine.autoLayout(tab.widgets, { preferFullWidth: true });
console.log(`[DashboardManager] Tab ${tab.id} migrated successfully`);
}
});
if (needsMigration) {
// Save migrated layout
this.triggerAutoSave();
// Re-render current tab with new positions
this.clearGrid();
const currentTab = this.tabManager.getTab(this.currentTabId);
if (currentTab && currentTab.widgets) {
currentTab.widgets.forEach(widget => {
const definition = this.registry.get(widget.type);
if (definition) {
this.renderWidget(widget, definition);
}
});
}
console.log('[DashboardManager] Old layouts migrated, saved, and re-rendered');
} else {
console.log('[DashboardManager] No migration needed');
}
}
/**
* Render tab navigation UI
*/
renderTabs() {
if (!this.tabContainer) {
console.warn('[DashboardManager] Tab container not found');
return;
}
// Clear existing tabs
this.tabContainer.innerHTML = '';
// Get all tabs sorted by order
const tabs = this.tabManager.getTabs();
if (tabs.length === 0) {
console.warn('[DashboardManager] No tabs to render');
return;
}
// Create tab buttons
tabs.forEach(tab => {
const button = document.createElement('button');
button.className = 'rpg-dashboard-tab';
button.dataset.tabId = tab.id;
button.innerHTML = `
${tab.name}
`;
// Mark active tab
if (tab.id === this.currentTabId) {
button.classList.add('active');
}
// Tab click handler
button.addEventListener('click', () => {
this.switchTab(tab.id);
});
this.tabContainer.appendChild(button);
});
// Icon-only mode when 4+ tabs to prevent header wrapping on hover
if (tabs.length > 3) {
this.tabContainer.classList.add('rpg-tabs-icon-only');
} else {
this.tabContainer.classList.remove('rpg-tabs-icon-only');
}
console.log(`[DashboardManager] Rendered ${tabs.length} tabs`);
}
/**
* Add a new widget to the dashboard
* @param {string} type - Widget type (must be registered)
* @param {string} [tabId] - Tab ID (default: current tab)
* @param {Object} [config] - Widget configuration
* @returns {string} Widget ID
*/
addWidget(type, tabId = null, config = {}) {
const targetTabId = tabId || this.currentTabId;
if (!targetTabId) {
throw new Error('[DashboardManager] No tab selected');
}
// Get widget definition from registry
const definition = this.registry.get(type);
if (!definition) {
throw new Error(`[DashboardManager] Widget type "${type}" not registered`);
}
// Generate unique widget ID
const widgetId = `widget-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
// Find available position in grid
const position = this.findAvailablePosition(definition.defaultSize);
// Create widget data
const widget = {
id: widgetId,
type,
x: position.x,
y: position.y,
w: definition.defaultSize.w,
h: definition.defaultSize.h,
config: config || {}
};
// Add to tab
const tab = this.tabManager.getTab(targetTabId);
if (!tab) {
throw new Error(`[DashboardManager] Tab "${targetTabId}" not found`);
}
if (!tab.widgets) {
tab.widgets = [];
}
tab.widgets.push(widget);
// Render widget if on current tab
if (targetTabId === this.currentTabId) {
this.renderWidget(widget, definition);
}
// Trigger auto-save
this.triggerAutoSave();
console.log(`[DashboardManager] Added widget: ${widgetId} (${type}) to tab: ${targetTabId}`);
this.notifyChange('widgetAdded', { widgetId, type, tabId: targetTabId });
return widgetId;
}
/**
* Remove a widget from the dashboard
* @param {string} widgetId - Widget ID to remove
*/
removeWidget(widgetId) {
// Find widget in current tab
const tab = this.tabManager.getTab(this.currentTabId);
if (!tab || !tab.widgets) {
console.warn(`[DashboardManager] Widget ${widgetId} not found in current tab`);
return;
}
const index = tab.widgets.findIndex(w => w.id === widgetId);
if (index === -1) {
console.warn(`[DashboardManager] Widget ${widgetId} not found`);
return;
}
// Get widget element and definition
const widgetData = this.widgets.get(widgetId);
if (widgetData) {
// Call widget cleanup
const definition = this.registry.get(widgetData.widget.type);
if (definition && definition.onRemove) {
definition.onRemove(widgetData.element, widgetData.widget.config);
}
// Destroy drag/resize handlers
this.dragHandler.destroyWidget(widgetData.element);
this.resizeHandler.destroyWidget(widgetData.element);
// Remove element
widgetData.element.remove();
// Remove from map
this.widgets.delete(widgetId);
}
// Remove from tab
tab.widgets.splice(index, 1);
// Trigger auto-save
this.triggerAutoSave();
console.log(`[DashboardManager] Removed widget: ${widgetId}`);
this.notifyChange('widgetRemoved', { widgetId });
}
/**
* Move a widget from one tab to another
* @param {string} widgetId - Widget ID to move
* @param {string} targetTabId - Target tab ID
*/
moveWidgetToTab(widgetId, targetTabId) {
console.log(`[DashboardManager] Moving widget ${widgetId} to tab ${targetTabId}`);
// Find which tab currently contains the widget
let sourceTab = null;
let widgetData = null;
for (const tab of this.dashboard.tabs) {
if (tab.widgets) {
const index = tab.widgets.findIndex(w => w.id === widgetId);
if (index !== -1) {
sourceTab = tab;
widgetData = tab.widgets[index];
break;
}
}
}
if (!sourceTab || !widgetData) {
console.warn(`[DashboardManager] Widget ${widgetId} not found in any tab`);
return;
}
// Get target tab
const targetTab = this.tabManager.getTab(targetTabId);
if (!targetTab) {
console.warn(`[DashboardManager] Target tab ${targetTabId} not found`);
return;
}
// Don't move if already in target tab
if (sourceTab.id === targetTabId) {
console.log(`[DashboardManager] Widget ${widgetId} already in tab ${targetTabId}`);
return;
}
// Remove from source tab
const index = sourceTab.widgets.findIndex(w => w.id === widgetId);
sourceTab.widgets.splice(index, 1);
// Find available position in target tab (collision detection)
if (!targetTab.widgets) {
targetTab.widgets = [];
}
// Find available position explicitly checking against target tab widgets
const availablePosition = this.findAvailablePositionInWidgets(
{ w: widgetData.w, h: widgetData.h },
targetTab.widgets
);
widgetData.x = availablePosition.x;
widgetData.y = availablePosition.y;
console.log(`[DashboardManager] Found available position in target tab: (${availablePosition.x}, ${availablePosition.y})`);
// Add to target tab
targetTab.widgets.push(widgetData);
// Update runtime widget data if it exists
const runtimeData = this.widgets.get(widgetId);
if (runtimeData) {
runtimeData.tabId = targetTabId;
}
// Update DOM if source or target is current tab
if (sourceTab.id === this.currentTabId || targetTabId === this.currentTabId) {
// If widget is being moved from current tab, remove its element
if (sourceTab.id === this.currentTabId && runtimeData) {
const definition = this.registry.get(widgetData.type);
if (definition && definition.onRemove) {
definition.onRemove(runtimeData.element, widgetData.config);
}
this.dragHandler.destroyWidget(runtimeData.element);
this.resizeHandler.destroyWidget(runtimeData.element);
runtimeData.element.remove();
this.widgets.delete(widgetId);
}
// If widget is being moved to current tab, render it
if (targetTabId === this.currentTabId) {
const definition = this.registry.get(widgetData.type);
if (definition) {
this.renderWidget(widgetData, definition);
}
}
}
// Trigger auto-save
this.triggerAutoSave();
console.log(`[DashboardManager] Moved widget ${widgetId} from ${sourceTab.id} to ${targetTabId} at position (${widgetData.x}, ${widgetData.y})`);
this.notifyChange('widgetMoved', { widgetId, sourceTabId: sourceTab.id, targetTabId });
}
/**
* Update a widget's configuration
* @param {string} widgetId - Widget ID
* @param {Object} updates - Configuration updates
*/
updateWidget(widgetId, updates) {
const widgetData = this.widgets.get(widgetId);
if (!widgetData) {
console.warn(`[DashboardManager] Widget ${widgetId} not found`);
return;
}
// Update widget config
Object.assign(widgetData.widget.config, updates);
// Get widget definition
const definition = this.registry.get(widgetData.widget.type);
// Call onConfigChange if defined
if (definition && definition.onConfigChange) {
definition.onConfigChange(widgetData.element, widgetData.widget.config);
}
// Re-render widget
this.renderWidgetContent(widgetData.element, widgetData.widget, definition);
// Trigger auto-save
this.triggerAutoSave();
console.log(`[DashboardManager] Updated widget: ${widgetId}`);
this.notifyChange('widgetUpdated', { widgetId, updates });
}
/**
* Render a single widget
* @param {Object} widget - Widget data
* @param {Object} definition - Widget definition
*/
renderWidget(widget, definition) {
// Create widget element
const element = document.createElement('div');
element.className = 'rpg-widget';
element.id = `widget-${widget.id}`;
element.dataset.widgetId = widget.id;
element.dataset.widgetType = widget.type;
// Validate widget dimensions (defensive check - shouldn't be needed if onColumnsChange works)
const validated = this.gridEngine.validateWidget(widget, definition.minSize || { w: 1, h: 1 });
// Position widget using validated dimensions
const pos = this.gridEngine.getWidgetPosition(validated);
element.style.position = 'absolute';
element.style.left = pos.left; // % of container (e.g., "5.23%")
element.style.top = pos.top; // vh units (e.g., "10.45vh")
element.style.width = pos.width; // % of container (e.g., "45.67%")
element.style.height = pos.height; // vh units (e.g., "20.12vh")
// Add to grid
this.gridContainer.appendChild(element);
// Render widget content
this.renderWidgetContent(element, widget, definition);
// Get current tab's widgets for collision detection
const currentTab = this.tabManager.getTab(this.currentTabId);
const allWidgets = currentTab ? currentTab.widgets : [];
// Initialize drag & drop
this.dragHandler.initWidget(element, widget, (updated, newX, newY) => {
widget.x = newX;
widget.y = newY;
// After drag (which may have triggered reflow), reposition ALL widgets
// because reflow may have moved other widgets
this.repositionAllWidgetsInCurrentTab();
this.triggerAutoSave();
}, allWidgets);
// Initialize resize
this.resizeHandler.initWidget(element, widget, (updated, newW, newH, newX, newY) => {
widget.w = newW;
widget.h = newH;
widget.x = newX;
widget.y = newY;
this.repositionWidget(element, widget);
// Call onResize if defined
if (definition.onResize) {
definition.onResize(element, newW, newH);
}
this.triggerAutoSave();
}, {
minW: definition.minSize.w,
minH: definition.minSize.h
}, allWidgets);
// Add edit mode controls
if (this.editManager) {
this.editManager.addWidgetControls(element, widget.id);
}
// Store widget data
this.widgets.set(widget.id, {
widget,
element,
definition,
tabId: this.currentTabId
});
}
/**
* Render widget content (called by widget render function)
* @param {HTMLElement} element - Widget element
* @param {Object} widget - Widget data
* @param {Object} definition - Widget definition
*/
renderWidgetContent(element, widget, definition) {
console.log(`[DashboardManager] renderWidgetContent called for ${widget.type}`);
// Clear existing content (except resize handles and controls)
const handles = element.querySelector('.resize-handles');
const controls = element.querySelector('.widget-edit-controls');
element.innerHTML = '';
if (handles) element.appendChild(handles);
if (controls) element.appendChild(controls);
// Call widget render function
if (definition && definition.render) {
console.log(`[DashboardManager] Calling render for ${widget.type}`, element);
// Pass widget dimensions along with config for layout calculations
definition.render(element, {
...widget.config,
_width: widget.w,
_height: widget.h
});
console.log(`[DashboardManager] After render, element children:`, element.children.length);
} else {
console.warn(`[DashboardManager] No render function for ${widget.type}`);
}
// Note: Content editing will be disabled in bulk after all widgets are rendered
// (see onTabChange for global disable pass)
}
/**
* Reposition widget element
* @param {HTMLElement} element - Widget element
* @param {Object} widget - Widget data
*/
repositionWidget(element, widget) {
const pos = this.gridEngine.getWidgetPosition(widget);
element.style.left = pos.left;
element.style.top = pos.top;
element.style.width = pos.width;
element.style.height = pos.height;
// Update overlay positions (resize handles and edit controls) to match new widget position
this.syncOverlaysForWidget(element, widget.id);
}
/**
* Sync overlay elements (handles and controls) for a specific widget
* @param {HTMLElement} element - Widget element
* @param {string} widgetId - Widget ID
*/
syncOverlaysForWidget(element, widgetId) {
// Update resize handles position
if (this.resizeHandler) {
const handlerData = this.resizeHandler.resizeHandlers.get(element);
if (handlerData && handlerData.handles) {
this.resizeHandler.updateHandlePosition(handlerData.handles, element);
}
}
// Update edit controls position
if (this.editManager && this.editManager.isEditMode) {
const controlData = this.editManager.widgetControlsMap.get(widgetId);
if (controlData && controlData.controls) {
this.editManager.updateControlPosition(controlData.controls, element);
}
}
}
/**
* Re-render all widgets (repositions all widgets with current grid calculations)
*/
renderAllWidgets() {
this.widgets.forEach((widgetData) => {
this.repositionWidget(widgetData.element, widgetData.widget);
});
console.log('[DashboardManager] Repositioned all widgets');
}
/**
* Reposition all widgets in the current tab
* Used after drag/drop reflow to update positions of all affected widgets
*/
repositionAllWidgetsInCurrentTab() {
const currentTab = this.tabManager.getTab(this.currentTabId);
if (!currentTab) return;
// Reposition each widget in the current tab
currentTab.widgets.forEach((widget) => {
const widgetData = this.widgets.get(widget.id);
if (widgetData && widgetData.element) {
this.repositionWidget(widgetData.element, widget);
}
});
console.log('[DashboardManager] Repositioned all widgets in current tab after reflow');
}
/**
* Estimate total height needed for widgets if laid out
* Simple estimation: sum all widget heights + gaps
*
* @param {Array