UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

74 lines (73 loc) 3.07 kB
import { dataRectFromCellPosition } from "./data-rect-from-cell-position.js"; import { isOverlappingRect } from "./is-overlapping-rect.js"; import { isFullyWithinRect } from "./is-fully-within-rect.js"; export function expandSelectionStart(api, selections, setSelections, meta, position, excludeMarker, view) { const pos = dataRectFromCellPosition(position); const rect = selections.at(-1); if (!rect || !isOverlappingRect(rect, pos) || isFullyWithinRect(pos, rect)) return; const first = excludeMarker ? 1 : 0; if (meta) { const next = { ...rect, columnStart: first, columnEnd: pos.columnStart + 1 }; const nextSelections = [...selections]; nextSelections[nextSelections.length - 1] = next; setSelections(nextSelections); if (pos.columnStart !== view.visibleColumns.length - 1) api.scrollIntoView({ column: first }); return; } const isAtEdge = pos.columnStart == rect.columnStart || pos.columnEnd === rect.columnEnd; let pivotStart = pos.columnStart; let pivotEnd = pos.columnEnd; // Our cell some how is spanned over. so for the current rowIndex, find the maximum span along the columns if (!isAtEdge) { for (let i = rect.rowStart; i < rect.rowEnd; i++) { const cell = dataRectFromCellPosition(api.cellRoot(pos.columnStart, i)); pivotStart = Math.min(pivotStart, cell.columnStart); pivotEnd = Math.max(pivotEnd, cell.columnEnd); } } let next; if (rect.columnEnd <= pivotEnd) { if (rect.columnStart === first) return; let highestColEnd = -Infinity; let setCell = rect; for (let i = rect.rowStart; i < rect.rowEnd; i++) { const cell = dataRectFromCellPosition(api.cellRoot(i, rect.columnStart - 1)); if (cell.columnStart > highestColEnd) { highestColEnd = cell.columnStart; setCell = cell; } } next = { ...rect, columnStart: highestColEnd, rowStart: Math.min(setCell.rowStart, rect.rowStart), rowEnd: Math.max(setCell.rowEnd, rect.rowEnd), }; api.scrollIntoView({ column: highestColEnd }); } else { let highestColEnd = -Infinity; let setCell = rect; for (let i = rect.rowStart; i < rect.rowEnd; i++) { const cell = dataRectFromCellPosition(api.cellRoot(i, rect.columnEnd - 1)); if (cell.columnStart > highestColEnd) { highestColEnd = cell.columnStart; setCell = cell; } } next = { ...rect, columnEnd: highestColEnd, rowStart: Math.min(setCell.rowStart, rect.rowStart), rowEnd: Math.max(setCell.rowEnd, rect.rowEnd), }; api.scrollIntoView({ column: highestColEnd - 1 }); } const nextSelections = [...selections]; nextSelections[nextSelections.length - 1] = next; setSelections(nextSelections); return; }