87 lines
3 KiB
JavaScript
87 lines
3 KiB
JavaScript
|
|
/**
|
||
|
|
* ColumnDetectionUtils - Shared utility for column detection and caching
|
||
|
|
* Used by both DragDropManager and AllDayManager for consistent column detection
|
||
|
|
*/
|
||
|
|
export class ColumnDetectionUtils {
|
||
|
|
/**
|
||
|
|
* Update column bounds cache for coordinate-based column detection
|
||
|
|
*/
|
||
|
|
static updateColumnBoundsCache() {
|
||
|
|
// Reset cache
|
||
|
|
this.columnBoundsCache = [];
|
||
|
|
// Find alle kolonner
|
||
|
|
const columns = document.querySelectorAll('swp-day-column');
|
||
|
|
let index = 1;
|
||
|
|
// Cache hver kolonnes x-grænser
|
||
|
|
columns.forEach(column => {
|
||
|
|
const rect = column.getBoundingClientRect();
|
||
|
|
const date = column.dataset.date;
|
||
|
|
if (date) {
|
||
|
|
this.columnBoundsCache.push({
|
||
|
|
boundingClientRect: rect,
|
||
|
|
element: column,
|
||
|
|
date,
|
||
|
|
left: rect.left,
|
||
|
|
right: rect.right,
|
||
|
|
index: index++
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
// Sorter efter x-position (fra venstre til højre)
|
||
|
|
this.columnBoundsCache.sort((a, b) => a.left - b.left);
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Get column date from X coordinate using cached bounds
|
||
|
|
*/
|
||
|
|
static getColumnBounds(position) {
|
||
|
|
if (this.columnBoundsCache.length === 0) {
|
||
|
|
this.updateColumnBoundsCache();
|
||
|
|
}
|
||
|
|
// Find den kolonne hvor x-koordinaten er indenfor grænserne
|
||
|
|
let column = this.columnBoundsCache.find(col => position.x >= col.left && position.x <= col.right);
|
||
|
|
if (column)
|
||
|
|
return column;
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Get column bounds by Date
|
||
|
|
*/
|
||
|
|
static getColumnBoundsByDate(date) {
|
||
|
|
if (this.columnBoundsCache.length === 0) {
|
||
|
|
this.updateColumnBoundsCache();
|
||
|
|
}
|
||
|
|
// Convert Date to YYYY-MM-DD format
|
||
|
|
let dateString = date.toISOString().split('T')[0];
|
||
|
|
// Find column that matches the date
|
||
|
|
let column = this.columnBoundsCache.find(col => col.date === dateString);
|
||
|
|
return column || null;
|
||
|
|
}
|
||
|
|
static getColumns() {
|
||
|
|
return [...this.columnBoundsCache];
|
||
|
|
}
|
||
|
|
static getHeaderColumns() {
|
||
|
|
let dayHeaders = [];
|
||
|
|
const dayColumns = document.querySelectorAll('swp-calendar-header swp-day-header');
|
||
|
|
let index = 1;
|
||
|
|
// Cache hver kolonnes x-grænser
|
||
|
|
dayColumns.forEach(column => {
|
||
|
|
const rect = column.getBoundingClientRect();
|
||
|
|
const date = column.dataset.date;
|
||
|
|
if (date) {
|
||
|
|
dayHeaders.push({
|
||
|
|
boundingClientRect: rect,
|
||
|
|
element: column,
|
||
|
|
date,
|
||
|
|
left: rect.left,
|
||
|
|
right: rect.right,
|
||
|
|
index: index++
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
// Sorter efter x-position (fra venstre til højre)
|
||
|
|
dayHeaders.sort((a, b) => a.left - b.left);
|
||
|
|
return dayHeaders;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
ColumnDetectionUtils.columnBoundsCache = [];
|
||
|
|
//# sourceMappingURL=ColumnDetectionUtils.js.map
|