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);
},
});
private _handleTool4Keypress = (event: any) => {
const details = new NotifyMessageDetails(OutputMessagePriority.Info, "", this._tool4Detailed);
let changed = false;
switch (event.keyCode) {
case 37:
details.briefMessage = "Left pressed";
this._toolRelativePosition = RelativePosition.Left;
changed = true;
break;
case 38:
details.briefMessage = "Up pressed";
this._toolRelativePosition = RelativePosition.Top;
changed = true;
break;
case 39:
details.briefMessage = "Right pressed";
this._toolRelativePosition = RelativePosition.Right;
changed = true;
break;
case 40:
details.briefMessage = "Down pressed";
this._toolRelativePosition = RelativePosition.Bottom;
changed = true;
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;
}
public static getPopupRect(pt: PointProps, offset: PointProps, popupSize: SizeProps | undefined, relativePosition: RelativePosition): RectangleProps {
const popupRect = { top: 0, left: 0, right: 0, bottom: 0 };
if (popupSize === undefined)
return popupRect;
switch (relativePosition) {
case RelativePosition.Top:
popupRect.bottom = pt.y - offset.y;
popupRect.left = pt.x - (popupSize.width / 2);
popupRect.top = popupRect.bottom - popupSize.height;
popupRect.right = popupRect.left + popupSize.width;
break;
case RelativePosition.Left:
popupRect.right = pt.x - offset.x;
popupRect.top = pt.y - (popupSize.height / 2);
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;
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:
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) {
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:
outPos = RelativePosition.TopRight;
break;
case RelativePosition.Left:
case RelativePosition.TopRight:
offset = { x: adjustmentOffset, y: -adjustmentOffset };
break;
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());
public static getRelativePositionFromCursorDirection(cursorDirection: CursorDirection): RelativePosition {
let relativePosition: RelativePosition = RelativePosition.BottomRight;
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;
private renderPositions(): React.ReactNode[] {
const positions = new Array();
let renderedPosition: React.ReactNode;
const begin = RelativePosition.Left;
const end = RelativePosition.BottomRight;
for (let position = begin; position <= end; position++) {
renderedPosition = this.renderRelativePosition(position);
if (renderedPosition)
positions.push(renderedPosition);
}
return positions;
}
private adjustOffset(offset: Point, relativePosition: RelativePosition, dimension: number): Point {
let outOffset = Point.create(offset.toProps());
switch (relativePosition) {
case RelativePosition.Top:
case RelativePosition.Bottom:
case RelativePosition.TopLeft:
case RelativePosition.TopRight:
case RelativePosition.BottomLeft:
case RelativePosition.BottomRight:
outOffset = Point.create({ x: offset.x, y: offset.y + dimension });
break;
case RelativePosition.Left:
case RelativePosition.Right:
outOffset = Point.create({ x: offset.x + dimension, y: offset.y });
break;
}
return outOffset;
}