ui: Linting & Formatting scripts (#26819)
This commit is contained in:
@@ -63,11 +63,15 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions) {
|
||||
const order = options.orderedIds();
|
||||
const fromIdx = order.indexOf(fromId);
|
||||
const toIdx = order.indexOf(toId);
|
||||
|
||||
if (fromIdx === -1 || toIdx === -1) return;
|
||||
|
||||
const [lo, hi] = fromIdx < toIdx ? [fromIdx, toIdx] : [toIdx, fromIdx];
|
||||
const shouldSelect = !selected.has(toId);
|
||||
|
||||
for (let i = lo; i <= hi; i++) {
|
||||
const id = order[i];
|
||||
|
||||
if (shouldSelect) selected.add(id);
|
||||
else selected.delete(id);
|
||||
}
|
||||
@@ -77,22 +81,27 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions) {
|
||||
const attr = resolveAttributeName();
|
||||
const selector = `[data-${attr}]`;
|
||||
const key = datasetKey(attr);
|
||||
|
||||
let bestMatch: HTMLElement | null = null;
|
||||
let bestCenterDistance = Infinity;
|
||||
|
||||
for (const row of document.querySelectorAll<HTMLElement>(selector)) {
|
||||
const rect = row.getBoundingClientRect();
|
||||
|
||||
if (y >= rect.top && y <= rect.bottom && x >= rect.left && x <= rect.right) {
|
||||
return row.dataset[key] ?? null;
|
||||
}
|
||||
|
||||
if (x >= rect.left && x <= rect.right) {
|
||||
const centerDistance = Math.abs(y - (rect.top + rect.height / 2));
|
||||
|
||||
if (centerDistance < bestCenterDistance) {
|
||||
bestCenterDistance = centerDistance;
|
||||
bestMatch = row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bestMatch ? (bestMatch.dataset[key] ?? null) : null;
|
||||
}
|
||||
|
||||
@@ -109,6 +118,7 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions) {
|
||||
|
||||
for (const row of document.querySelectorAll<HTMLElement>(selector)) {
|
||||
const id = row.dataset[key];
|
||||
|
||||
if (!id || !visibleIds.has(id)) continue;
|
||||
|
||||
const rect = row.getBoundingClientRect();
|
||||
@@ -132,17 +142,22 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions) {
|
||||
|
||||
if (event.shiftKey && dragAnchorId !== null) {
|
||||
const target = findRowAtPoint(event.clientX, event.clientY);
|
||||
|
||||
if (target && target !== mousedownRowId) rangeSelect(dragAnchorId, target);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isMarqueeDragging) {
|
||||
const dx = event.clientX - dragStartX;
|
||||
const dy = event.clientY - dragStartY;
|
||||
|
||||
if (Math.hypot(dx, dy) < dragThresholdPx) return;
|
||||
|
||||
isMarqueeDragging = true;
|
||||
dragMode = decideDragMode(mousedownRowId, options.selectedIds());
|
||||
}
|
||||
|
||||
updateMarqueeRect(event.clientX, event.clientY);
|
||||
}
|
||||
|
||||
@@ -150,8 +165,10 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions) {
|
||||
if (isMarqueeDragging) {
|
||||
suppressNextClick = true;
|
||||
const target = findRowAtPoint(event.clientX, event.clientY);
|
||||
|
||||
if (target) dragAnchorId = target;
|
||||
}
|
||||
|
||||
isMarqueeDragging = false;
|
||||
mouseDownActive = false;
|
||||
mousedownRowId = null;
|
||||
@@ -171,11 +188,14 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions) {
|
||||
$effect(() => {
|
||||
if (!options.enabled()) {
|
||||
reset();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
document.addEventListener('mousemove', handleDocumentMouseMove);
|
||||
document.addEventListener('mouseup', handleDocumentMouseUp);
|
||||
document.addEventListener('click', handleClickCapture, { capture: true });
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('mousemove', handleDocumentMouseMove);
|
||||
document.removeEventListener('mouseup', handleDocumentMouseUp);
|
||||
@@ -185,7 +205,9 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions) {
|
||||
|
||||
function rowMouseDown(id: string, event: MouseEvent) {
|
||||
if (!options.enabled()) return;
|
||||
|
||||
if (event.button !== 0) return;
|
||||
|
||||
event.preventDefault();
|
||||
mouseDownActive = true;
|
||||
mousedownRowId = id;
|
||||
@@ -197,10 +219,12 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions) {
|
||||
|
||||
function rowClick(id: string, shiftKey: boolean) {
|
||||
if (!options.enabled()) return;
|
||||
|
||||
const selected = options.selectedIds();
|
||||
|
||||
if (shiftKey) {
|
||||
const anchor = dragAnchorId;
|
||||
|
||||
if (anchor !== null && anchor !== id) {
|
||||
rangeSelect(anchor, id);
|
||||
} else if (selected.has(id)) {
|
||||
@@ -208,12 +232,15 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions) {
|
||||
} else {
|
||||
selected.add(id);
|
||||
}
|
||||
|
||||
dragAnchorId = id;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (selected.has(id)) selected.delete(id);
|
||||
else selected.add(id);
|
||||
|
||||
dragAnchorId = id;
|
||||
}
|
||||
|
||||
@@ -229,11 +256,11 @@ export function useMarqueeSelection(options: UseMarqueeSelectionOptions) {
|
||||
}
|
||||
|
||||
return {
|
||||
rowMouseDown,
|
||||
rowClick,
|
||||
reset,
|
||||
get dragAnchorId() {
|
||||
return dragAnchorId;
|
||||
}
|
||||
},
|
||||
reset,
|
||||
rowClick,
|
||||
rowMouseDown
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user