Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
document.addEventListener('keydown', this, true);
document.addEventListener('contextmenu', this, true);
// Compute the offset delta for the handle press.
let delta: number;
let handle = layout.handles[index];
let rect = handle.getBoundingClientRect();
if (layout.orientation === 'horizontal') {
delta = event.clientX - rect.left;
} else {
delta = event.clientY - rect.top;
}
// Override the cursor and store the press data.
let style = window.getComputedStyle(handle);
let override = Drag.overrideCursor(style.cursor!);
this._pressData = { index, delta, override };
}
event.stopPropagation();
// Add the extra document listeners.
document.addEventListener('keydown', this, true);
document.addEventListener('mouseup', this, true);
document.addEventListener('mousemove', this, true);
document.addEventListener('contextmenu', this, true);
// Compute the offset deltas for the handle press.
let rect = handle.getBoundingClientRect();
let deltaX = event.clientX - rect.left;
let deltaY = event.clientY - rect.top;
// Override the cursor and store the press data.
let style = window.getComputedStyle(handle);
let override = Drag.overrideCursor(style.cursor!);
this._pressData = { handle, deltaX, deltaY, override };
}
// Fetch the modifier flags.
let shift = event.shiftKey;
let accel = Platform.accelKey(event);
// If the hit test is the body region, the only option is select.
if (region === 'body') {
// Fetch the selection model.
let model = grid.selectionModel;
// Bail early if there is no selection model.
if (!model) {
return;
}
// Override the document cursor.
let override = Drag.overrideCursor('default');
// Set up the press data.
this._pressData = {
type: 'select', region, row, column, override,
localX: -1, localY: -1, timeout: -1
};
// Set up the selection variables.
let r1: number;
let c1: number;
let r2: number;
let c2: number;
let cursorRow: number;
let cursorColumn: number;
let clear: SelectionModel.ClearMode;
// Activate the drag if necessary.
if (!data.dragActive) {
// Fill in the rest of the drag data measurements.
let tabRect = data.tab.getBoundingClientRect();
if (this._orientation === 'horizontal') {
data.tabPos = data.tab.offsetLeft;
data.tabSize = tabRect.width;
data.tabPressPos = data.pressX - tabRect.left;
} else {
data.tabPos = data.tab.offsetTop;
data.tabSize = tabRect.height;
data.tabPressPos = data.pressY - tabRect.top;
}
data.tabLayout = Private.snapTabLayout(tabs, this._orientation);
data.contentRect = this.contentNode.getBoundingClientRect();
data.override = Drag.overrideCursor('default');
// Add the dragging style classes.
data.tab.classList.add('p-mod-dragging');
this.addClass('p-mod-dragging');
// Mark the drag as active.
data.dragActive = true;
}
// Emit the detach requested signal if the threshold is exceeded.
if (!data.detachRequested && Private.detachExceeded(data, event)) {
// Only emit the signal once per drag cycle.
data.detachRequested = true;
// Setup the arguments for the signal.
let index = data.index;
// Set up the resize data type.
let type: 'row-resize' = 'row-resize';
// Determine the row region.
let rgn: DataModel.RowRegion = (
region === 'row-header' ? 'body' : 'column-header'
);
// Determine the section index.
let index = handle === 'top' ? row - 1 : row;
// Fetch the section size.
let size = grid.rowSize(rgn, index);
// Override the document cursor.
let override = Drag.overrideCursor(cursor);
// Create the temporary press data.
this._pressData = { type, region: rgn, index, size, clientY, override };
// Done.
return;
}
// Otherwise, the only option is select.
// Fetch the selection model.
let model = grid.selectionModel;
// Bail if there is no selection model.
if (!model) {
return;
}
// Find the pressed scroll bar part.
let part = Private.findPart(this, event.target as HTMLElement);
// Do nothing if the part is not of interest.
if (!part) {
return;
}
// Stop the event propagation.
event.preventDefault();
event.stopPropagation();
// Override the mouse cursor.
let override = Drag.overrideCursor('default');
// Set up the press data.
this._pressData = {
part, override,
delta: -1, value: -1,
mouseX: event.clientX,
mouseY: event.clientY
};
// Add the extra event listeners.
document.addEventListener('mousemove', this, true);
document.addEventListener('mouseup', this, true);
document.addEventListener('keydown', this, true);
document.addEventListener('contextmenu', this, true);
// Handle a thumb press.