Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
iconSpec: "icon-placeholder", labelKey: "SampleApp:buttons.addCursorPopups", execute: async () => {
CursorPopupManager.open("testR1", Hello World!, CursorInformation.cursorPosition, new Point(40, 20), RelativePosition.Right, 10);
CursorPopupManager.open("testBR1", Hello World!, CursorInformation.cursorPosition, new Point(20, 20), RelativePosition.BottomRight, 10);
CursorPopupManager.open("testB1", Hello World!, CursorInformation.cursorPosition, new Point(20, 85), RelativePosition.Bottom, 10);
CursorPopupManager.open("testBL1", Hello World!, CursorInformation.cursorPosition, new Point(20, 20), RelativePosition.BottomLeft, 10);
CursorPopupManager.open("testL1", Hello World!, CursorInformation.cursorPosition, new Point(40, 20), RelativePosition.Left, 10);
CursorPopupManager.open("testTL1", Hello World!, CursorInformation.cursorPosition, new Point(20, 20), RelativePosition.TopLeft, 10);
CursorPopupManager.open("testT1", Hello World!, CursorInformation.cursorPosition, new Point(20, 100), RelativePosition.Top, 10);
},
});
case RelativePosition.Left:
outPos = RelativePosition.Right;
break;
case RelativePosition.Bottom:
case RelativePosition.BottomLeft:
outPos = RelativePosition.BottomRight;
break;
}
}
if (rect.bottom > windowHeight) {
flipped = true;
switch (inPos) {
case RelativePosition.Left:
case RelativePosition.BottomLeft:
outPos = RelativePosition.TopLeft;
break;
case RelativePosition.Bottom:
outPos = RelativePosition.Top;
break;
case RelativePosition.Right:
case RelativePosition.BottomRight:
outPos = RelativePosition.TopRight;
break;
}
}
if (rect.top < 0) {
flipped = true;
switch (inPos) {
case RelativePosition.Left:
case RelativePosition.TopLeft:
popupRect.left = popupRect.right - popupSize.width;
popupRect.bottom = popupRect.top + popupSize.height;
break;
case RelativePosition.Right:
popupRect.left = pt.x + offset.x;
popupRect.top = pt.y - (popupSize.height / 2);
popupRect.right = popupRect.left + popupSize.width;
popupRect.bottom = popupRect.top + popupSize.height;
break;
case RelativePosition.Bottom:
popupRect.top = pt.y + offset.y;
popupRect.left = pt.x - (popupSize.width / 2);
popupRect.bottom = popupRect.top + popupSize.height;
popupRect.right = popupRect.left + popupSize.width;
break;
case RelativePosition.TopLeft:
popupRect.bottom = pt.y - offset.y;
popupRect.right = pt.x - offset.x;
popupRect.top = popupRect.bottom - popupSize.height;
popupRect.left = popupRect.right - popupSize.width;
break;
case RelativePosition.TopRight:
popupRect.bottom = pt.y - offset.y;
popupRect.left = pt.x + offset.x;
popupRect.top = popupRect.bottom - popupSize.height;
popupRect.right = popupRect.left + popupSize.width;
break;
case RelativePosition.BottomLeft:
popupRect.top = pt.y + offset.y;
popupRect.right = pt.x - offset.x;
popupRect.bottom = popupRect.top + popupSize.height;
popupRect.left = popupRect.right - popupSize.width;
break;
case RelativePosition.Bottom:
outPos = RelativePosition.Top;
break;
case RelativePosition.Right:
case RelativePosition.BottomRight:
outPos = RelativePosition.TopRight;
break;
}
}
if (rect.top < 0) {
flipped = true;
switch (inPos) {
case RelativePosition.Left:
case RelativePosition.TopLeft:
outPos = RelativePosition.BottomLeft;
break;
case RelativePosition.Top:
outPos = RelativePosition.Bottom;
break;
case RelativePosition.Right:
case RelativePosition.TopRight:
outPos = RelativePosition.BottomRight;
break;
}
}
return { outPos, flipped };
}
private static autoFlip(inPos: RelativePosition, rect: RectangleProps, windowWidth: number, windowHeight: number): { outPos: RelativePosition, flipped: boolean } {
let flipped = false;
let outPos = inPos;
if (rect.right > windowWidth) {
flipped = true;
switch (inPos) {
case RelativePosition.Top:
case RelativePosition.TopRight:
outPos = RelativePosition.TopLeft;
break;
case RelativePosition.Right:
outPos = RelativePosition.Left;
break;
case RelativePosition.Bottom:
case RelativePosition.BottomRight:
outPos = RelativePosition.BottomLeft;
break;
}
}
if (rect.left < 0) {
flipped = true;
switch (inPos) {
case RelativePosition.Top:
case RelativePosition.TopLeft:
case RelativePosition.Right:
offset = { x: adjustmentOffset, y: 0 };
break;
case RelativePosition.BottomRight:
offset = { x: adjustmentOffset, y: adjustmentOffset };
break;
case RelativePosition.Bottom:
offset = { x: 0, y: adjustmentOffset };
break;
case RelativePosition.BottomLeft:
offset = { x: -adjustmentOffset, y: adjustmentOffset };
break;
case RelativePosition.Left:
offset = { x: -adjustmentOffset, y: 0 };
break;
case RelativePosition.TopLeft:
offset = { x: -adjustmentOffset, y: -adjustmentOffset };
break;
}
this.setState((prevState) => {
if (!this._viewport)
return null;
if (!this._position)
return null;
const containerBounds = Rectangle.create(this._viewport.getBoundingClientRect());
const relativeBounds = Rectangle.createFromSize(this._size).offset(this._position);
const viewportOffset = new Point().getOffsetTo(containerBounds.topLeft());
const adjustedPosition = offsetAndContainInContainer(relativeBounds, containerBounds.getSize(), offset);
const position = adjustedPosition.offset(viewportOffset);
break;
case RelativePosition.Right:
outPos = RelativePosition.Left;
break;
case RelativePosition.Bottom:
case RelativePosition.BottomRight:
outPos = RelativePosition.BottomLeft;
break;
}
}
if (rect.left < 0) {
flipped = true;
switch (inPos) {
case RelativePosition.Top:
case RelativePosition.TopLeft:
outPos = RelativePosition.TopRight;
break;
case RelativePosition.Left:
outPos = RelativePosition.Right;
break;
case RelativePosition.Bottom:
case RelativePosition.BottomLeft:
outPos = RelativePosition.BottomRight;
break;
}
}
if (rect.bottom > windowHeight) {
flipped = true;
switch (inPos) {
case RelativePosition.Left:
switch (cursorDirection) {
case CursorDirection.Top:
relativePosition = RelativePosition.Top;
break;
case CursorDirection.Left:
relativePosition = RelativePosition.Left;
break;
case CursorDirection.Right:
relativePosition = RelativePosition.Right;
break;
case CursorDirection.Bottom:
relativePosition = RelativePosition.Bottom;
break;
case CursorDirection.TopLeft:
relativePosition = RelativePosition.TopLeft;
break;
case CursorDirection.TopRight:
relativePosition = RelativePosition.TopRight;
break;
case CursorDirection.BottomLeft:
relativePosition = RelativePosition.BottomLeft;
break;
case CursorDirection.BottomRight:
relativePosition = RelativePosition.BottomRight;
break;
}
return relativePosition;
}
private getDimension(popupSize: Size, relativePosition: RelativePosition): number {
let dimension = 0;
switch (relativePosition) {
case RelativePosition.Top:
case RelativePosition.Bottom:
case RelativePosition.TopLeft:
case RelativePosition.TopRight:
case RelativePosition.BottomLeft:
case RelativePosition.BottomRight:
dimension = popupSize.height;
break;
case RelativePosition.Left:
case RelativePosition.Right:
dimension = popupSize.width;
break;
}
return dimension;
}