@redsift/design-system 9.2.2 → 9.2.3-patch
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +178 -1
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -9311,6 +9311,182 @@ const useRole = function (_ref, _temp) {
|
|
|
9311
9311
|
}, [enabled, role, open, rootId, referenceId]);
|
|
9312
9312
|
};
|
|
9313
9313
|
|
|
9314
|
+
function isPointInPolygon(point, polygon) {
|
|
9315
|
+
const [x, y] = point;
|
|
9316
|
+
let isInside = false;
|
|
9317
|
+
const length = polygon.length;
|
|
9318
|
+
for (let i = 0, j = length - 1; i < length; j = i++) {
|
|
9319
|
+
const [xi, yi] = polygon[i] || [0, 0];
|
|
9320
|
+
const [xj, yj] = polygon[j] || [0, 0];
|
|
9321
|
+
const intersect = yi >= y !== yj >= y && x <= (xj - xi) * (y - yi) / (yj - yi) + xi;
|
|
9322
|
+
if (intersect) {
|
|
9323
|
+
isInside = !isInside;
|
|
9324
|
+
}
|
|
9325
|
+
}
|
|
9326
|
+
return isInside;
|
|
9327
|
+
}
|
|
9328
|
+
function isInside(point, rect) {
|
|
9329
|
+
return point[0] >= rect.x && point[0] <= rect.x + rect.width && point[1] >= rect.y && point[1] <= rect.y + rect.height;
|
|
9330
|
+
}
|
|
9331
|
+
function safePolygon(_temp) {
|
|
9332
|
+
let {
|
|
9333
|
+
restMs = 0,
|
|
9334
|
+
buffer = 0.5,
|
|
9335
|
+
blockPointerEvents = false
|
|
9336
|
+
} = _temp === void 0 ? {} : _temp;
|
|
9337
|
+
let timeoutId;
|
|
9338
|
+
let isInsideRect = false;
|
|
9339
|
+
let hasLanded = false;
|
|
9340
|
+
const fn = _ref => {
|
|
9341
|
+
let {
|
|
9342
|
+
x,
|
|
9343
|
+
y,
|
|
9344
|
+
placement,
|
|
9345
|
+
elements,
|
|
9346
|
+
onClose,
|
|
9347
|
+
nodeId,
|
|
9348
|
+
tree
|
|
9349
|
+
} = _ref;
|
|
9350
|
+
return function onMouseMove(event) {
|
|
9351
|
+
function close() {
|
|
9352
|
+
clearTimeout(timeoutId);
|
|
9353
|
+
onClose();
|
|
9354
|
+
}
|
|
9355
|
+
clearTimeout(timeoutId);
|
|
9356
|
+
if (!elements.domReference || !elements.floating || placement == null || x == null || y == null) {
|
|
9357
|
+
return;
|
|
9358
|
+
}
|
|
9359
|
+
const {
|
|
9360
|
+
clientX,
|
|
9361
|
+
clientY
|
|
9362
|
+
} = event;
|
|
9363
|
+
const clientPoint = [clientX, clientY];
|
|
9364
|
+
const target = getTarget(event);
|
|
9365
|
+
const isLeave = event.type === 'mouseleave';
|
|
9366
|
+
const isOverFloatingEl = contains(elements.floating, target);
|
|
9367
|
+
const isOverReferenceEl = contains(elements.domReference, target);
|
|
9368
|
+
const refRect = elements.domReference.getBoundingClientRect();
|
|
9369
|
+
const rect = elements.floating.getBoundingClientRect();
|
|
9370
|
+
const side = placement.split('-')[0];
|
|
9371
|
+
const cursorLeaveFromRight = x > rect.right - rect.width / 2;
|
|
9372
|
+
const cursorLeaveFromBottom = y > rect.bottom - rect.height / 2;
|
|
9373
|
+
const isOverReferenceRect = isInside(clientPoint, refRect);
|
|
9374
|
+
if (isOverFloatingEl) {
|
|
9375
|
+
hasLanded = true;
|
|
9376
|
+
if (!isLeave) {
|
|
9377
|
+
return;
|
|
9378
|
+
}
|
|
9379
|
+
}
|
|
9380
|
+
if (isOverReferenceEl) {
|
|
9381
|
+
hasLanded = false;
|
|
9382
|
+
}
|
|
9383
|
+
if (isOverReferenceEl && !isLeave) {
|
|
9384
|
+
hasLanded = true;
|
|
9385
|
+
return;
|
|
9386
|
+
}
|
|
9387
|
+
|
|
9388
|
+
// Prevent overlapping floating element from being stuck in an open-close
|
|
9389
|
+
// loop: https://github.com/floating-ui/floating-ui/issues/1910
|
|
9390
|
+
if (isLeave && isElement(event.relatedTarget) && contains(elements.floating, event.relatedTarget)) {
|
|
9391
|
+
return;
|
|
9392
|
+
}
|
|
9393
|
+
|
|
9394
|
+
// If any nested child is open, abort.
|
|
9395
|
+
if (tree && getChildren(tree.nodesRef.current, nodeId).some(_ref2 => {
|
|
9396
|
+
let {
|
|
9397
|
+
context
|
|
9398
|
+
} = _ref2;
|
|
9399
|
+
return context == null ? void 0 : context.open;
|
|
9400
|
+
})) {
|
|
9401
|
+
return;
|
|
9402
|
+
}
|
|
9403
|
+
|
|
9404
|
+
// If the pointer is leaving from the opposite side, the "buffer" logic
|
|
9405
|
+
// creates a point where the floating element remains open, but should be
|
|
9406
|
+
// ignored.
|
|
9407
|
+
// A constant of 1 handles floating point rounding errors.
|
|
9408
|
+
if (side === 'top' && y >= refRect.bottom - 1 || side === 'bottom' && y <= refRect.top + 1 || side === 'left' && x >= refRect.right - 1 || side === 'right' && x <= refRect.left + 1) {
|
|
9409
|
+
return close();
|
|
9410
|
+
}
|
|
9411
|
+
|
|
9412
|
+
// Ignore when the cursor is within the rectangular trough between the
|
|
9413
|
+
// two elements. Since the triangle is created from the cursor point,
|
|
9414
|
+
// which can start beyond the ref element's edge, traversing back and
|
|
9415
|
+
// forth from the ref to the floating element can cause it to close. This
|
|
9416
|
+
// ensures it always remains open in that case.
|
|
9417
|
+
let rectPoly = [];
|
|
9418
|
+
switch (side) {
|
|
9419
|
+
case 'top':
|
|
9420
|
+
rectPoly = [[rect.left, refRect.top + 1], [rect.left, rect.bottom - 1], [rect.right, rect.bottom - 1], [rect.right, refRect.top + 1]];
|
|
9421
|
+
isInsideRect = clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= refRect.top + 1;
|
|
9422
|
+
break;
|
|
9423
|
+
case 'bottom':
|
|
9424
|
+
rectPoly = [[rect.left, rect.top + 1], [rect.left, refRect.bottom - 1], [rect.right, refRect.bottom - 1], [rect.right, rect.top + 1]];
|
|
9425
|
+
isInsideRect = clientX >= rect.left && clientX <= rect.right && clientY >= refRect.bottom - 1 && clientY <= rect.bottom;
|
|
9426
|
+
break;
|
|
9427
|
+
case 'left':
|
|
9428
|
+
rectPoly = [[rect.right - 1, rect.bottom], [rect.right - 1, rect.top], [refRect.left + 1, rect.top], [refRect.left + 1, rect.bottom]];
|
|
9429
|
+
isInsideRect = clientX >= rect.left && clientX <= refRect.left + 1 && clientY >= rect.top && clientY <= rect.bottom;
|
|
9430
|
+
break;
|
|
9431
|
+
case 'right':
|
|
9432
|
+
rectPoly = [[refRect.right - 1, rect.bottom], [refRect.right - 1, rect.top], [rect.left + 1, rect.top], [rect.left + 1, rect.bottom]];
|
|
9433
|
+
isInsideRect = clientX >= refRect.right - 1 && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
|
|
9434
|
+
break;
|
|
9435
|
+
}
|
|
9436
|
+
function getPolygon(_ref3) {
|
|
9437
|
+
let [x, y] = _ref3;
|
|
9438
|
+
const isFloatingWider = rect.width > refRect.width;
|
|
9439
|
+
const isFloatingTaller = rect.height > refRect.height;
|
|
9440
|
+
switch (side) {
|
|
9441
|
+
case 'top':
|
|
9442
|
+
{
|
|
9443
|
+
const cursorPointOne = [isFloatingWider ? x + buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y + buffer + 1];
|
|
9444
|
+
const cursorPointTwo = [isFloatingWider ? x - buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y + buffer + 1];
|
|
9445
|
+
const commonPoints = [[rect.left, cursorLeaveFromRight ? rect.bottom - buffer : isFloatingWider ? rect.bottom - buffer : rect.top], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.bottom - buffer : rect.top : rect.bottom - buffer]];
|
|
9446
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
9447
|
+
}
|
|
9448
|
+
case 'bottom':
|
|
9449
|
+
{
|
|
9450
|
+
const cursorPointOne = [isFloatingWider ? x + buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y - buffer];
|
|
9451
|
+
const cursorPointTwo = [isFloatingWider ? x - buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y - buffer];
|
|
9452
|
+
const commonPoints = [[rect.left, cursorLeaveFromRight ? rect.top + buffer : isFloatingWider ? rect.top + buffer : rect.bottom], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.top + buffer : rect.bottom : rect.top + buffer]];
|
|
9453
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
9454
|
+
}
|
|
9455
|
+
case 'left':
|
|
9456
|
+
{
|
|
9457
|
+
const cursorPointOne = [x + buffer + 1, isFloatingTaller ? y + buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
9458
|
+
const cursorPointTwo = [x + buffer + 1, isFloatingTaller ? y - buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
9459
|
+
const commonPoints = [[cursorLeaveFromBottom ? rect.right - buffer : isFloatingTaller ? rect.right - buffer : rect.left, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.right - buffer : rect.left : rect.right - buffer, rect.bottom]];
|
|
9460
|
+
return [...commonPoints, cursorPointOne, cursorPointTwo];
|
|
9461
|
+
}
|
|
9462
|
+
case 'right':
|
|
9463
|
+
{
|
|
9464
|
+
const cursorPointOne = [x - buffer, isFloatingTaller ? y + buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
9465
|
+
const cursorPointTwo = [x - buffer, isFloatingTaller ? y - buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
9466
|
+
const commonPoints = [[cursorLeaveFromBottom ? rect.left + buffer : isFloatingTaller ? rect.left + buffer : rect.right, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.left + buffer : rect.right : rect.left + buffer, rect.bottom]];
|
|
9467
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
9468
|
+
}
|
|
9469
|
+
}
|
|
9470
|
+
}
|
|
9471
|
+
const poly = isInsideRect ? rectPoly : getPolygon([x, y]);
|
|
9472
|
+
if (isInsideRect) {
|
|
9473
|
+
return;
|
|
9474
|
+
} else if (hasLanded && !isOverReferenceRect) {
|
|
9475
|
+
return close();
|
|
9476
|
+
}
|
|
9477
|
+
if (!isPointInPolygon([clientX, clientY], poly)) {
|
|
9478
|
+
close();
|
|
9479
|
+
} else if (restMs && !hasLanded) {
|
|
9480
|
+
timeoutId = setTimeout(close, restMs);
|
|
9481
|
+
}
|
|
9482
|
+
};
|
|
9483
|
+
};
|
|
9484
|
+
fn.__options = {
|
|
9485
|
+
blockPointerEvents
|
|
9486
|
+
};
|
|
9487
|
+
return fn;
|
|
9488
|
+
}
|
|
9489
|
+
|
|
9314
9490
|
/**
|
|
9315
9491
|
* Provides data to position a floating element and context to add interactions.
|
|
9316
9492
|
* @see https://floating-ui.com/docs/react
|
|
@@ -9709,7 +9885,8 @@ function useTooltip(_ref) {
|
|
|
9709
9885
|
delay: {
|
|
9710
9886
|
open: delay,
|
|
9711
9887
|
close: 0
|
|
9712
|
-
}
|
|
9888
|
+
},
|
|
9889
|
+
handleClose: safePolygon()
|
|
9713
9890
|
});
|
|
9714
9891
|
const focus = useFocus(context);
|
|
9715
9892
|
const dismiss = useDismiss(context);
|