@carbon/ibm-products
Version:
Carbon for IBM Products
48 lines (46 loc) • 2.66 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
require("../../../_virtual/_rolldown/runtime.js");
const require_settings = require("../../../settings.js");
let _carbon_layout = require("@carbon/layout");
//#region src/components/DataSpreadsheet/utils/moveColumnIndicatorLine.js
/**
* Copyright IBM Corp. 2022, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const moveColumnIndicatorLine = ({ blockClass = `${require_settings.pkg.prefix}--data-spreadsheet`, clonedSelectionElement, ref, spreadsheetCoords, leftScrollAmount }) => {
const closestCell = event.target.closest(`.${blockClass}--interactive-cell-element`);
const newColumnIndex = closestCell?.getAttribute("data-column-index");
const originalColumnIndex = clonedSelectionElement?.getAttribute("data-column-index-original");
const closestCellCoords = closestCell.getBoundingClientRect();
const indicatorLineElement = ref.current.querySelector(`.${blockClass}__reorder-indicator-line`);
const matcherId = clonedSelectionElement?.getAttribute("data-matcher-id");
const selectionAreaOrigin = ref.current.querySelector(`[data-matcher-id="${matcherId}"]`);
const listContainer = ref.current.querySelector(`.${blockClass}__list--container`);
const scrollSpeed = 10;
const leftEdgeThreshold = 120;
const rightEdgeThreshold = 100;
const { clientX } = event;
const { left, right } = listContainer.getBoundingClientRect();
if (clientX < leftEdgeThreshold) window.scrollBy(-scrollSpeed, 0);
if (clientX > window.innerWidth - rightEdgeThreshold) window.scrollBy(scrollSpeed, 0);
if (clientX > left && clientX < left + leftEdgeThreshold) listContainer.scrollBy(-scrollSpeed, 0);
if (clientX < right && clientX > right - rightEdgeThreshold) listContainer.scrollBy(scrollSpeed, 0);
if (Number(newColumnIndex) > Number(originalColumnIndex)) {
const leftPosition = closestCellCoords.left - spreadsheetCoords.left + closestCell.offsetWidth - 2 + leftScrollAmount;
indicatorLineElement.style.left = (0, _carbon_layout.px)(leftPosition);
}
if (Number(newColumnIndex) < Number(originalColumnIndex)) {
const leftPosition = closestCellCoords.left - spreadsheetCoords.left + leftScrollAmount;
indicatorLineElement.style.left = (0, _carbon_layout.px)(leftPosition);
}
if (Number(newColumnIndex) === Number(originalColumnIndex)) indicatorLineElement.style.left = selectionAreaOrigin.style.left;
};
//#endregion
exports.moveColumnIndicatorLine = moveColumnIndicatorLine;