@redsift/table 9.2.2 → 9.2.3
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
|
@@ -20976,6 +20976,182 @@ const useRole = function (_ref, _temp) {
|
|
|
20976
20976
|
}, [enabled, role, open, rootId, referenceId]);
|
|
20977
20977
|
};
|
|
20978
20978
|
|
|
20979
|
+
function isPointInPolygon(point, polygon) {
|
|
20980
|
+
const [x, y] = point;
|
|
20981
|
+
let isInside = false;
|
|
20982
|
+
const length = polygon.length;
|
|
20983
|
+
for (let i = 0, j = length - 1; i < length; j = i++) {
|
|
20984
|
+
const [xi, yi] = polygon[i] || [0, 0];
|
|
20985
|
+
const [xj, yj] = polygon[j] || [0, 0];
|
|
20986
|
+
const intersect = yi >= y !== yj >= y && x <= (xj - xi) * (y - yi) / (yj - yi) + xi;
|
|
20987
|
+
if (intersect) {
|
|
20988
|
+
isInside = !isInside;
|
|
20989
|
+
}
|
|
20990
|
+
}
|
|
20991
|
+
return isInside;
|
|
20992
|
+
}
|
|
20993
|
+
function isInside(point, rect) {
|
|
20994
|
+
return point[0] >= rect.x && point[0] <= rect.x + rect.width && point[1] >= rect.y && point[1] <= rect.y + rect.height;
|
|
20995
|
+
}
|
|
20996
|
+
function safePolygon(_temp) {
|
|
20997
|
+
let {
|
|
20998
|
+
restMs = 0,
|
|
20999
|
+
buffer = 0.5,
|
|
21000
|
+
blockPointerEvents = false
|
|
21001
|
+
} = _temp === void 0 ? {} : _temp;
|
|
21002
|
+
let timeoutId;
|
|
21003
|
+
let isInsideRect = false;
|
|
21004
|
+
let hasLanded = false;
|
|
21005
|
+
const fn = _ref => {
|
|
21006
|
+
let {
|
|
21007
|
+
x,
|
|
21008
|
+
y,
|
|
21009
|
+
placement,
|
|
21010
|
+
elements,
|
|
21011
|
+
onClose,
|
|
21012
|
+
nodeId,
|
|
21013
|
+
tree
|
|
21014
|
+
} = _ref;
|
|
21015
|
+
return function onMouseMove(event) {
|
|
21016
|
+
function close() {
|
|
21017
|
+
clearTimeout(timeoutId);
|
|
21018
|
+
onClose();
|
|
21019
|
+
}
|
|
21020
|
+
clearTimeout(timeoutId);
|
|
21021
|
+
if (!elements.domReference || !elements.floating || placement == null || x == null || y == null) {
|
|
21022
|
+
return;
|
|
21023
|
+
}
|
|
21024
|
+
const {
|
|
21025
|
+
clientX,
|
|
21026
|
+
clientY
|
|
21027
|
+
} = event;
|
|
21028
|
+
const clientPoint = [clientX, clientY];
|
|
21029
|
+
const target = getTarget(event);
|
|
21030
|
+
const isLeave = event.type === 'mouseleave';
|
|
21031
|
+
const isOverFloatingEl = contains(elements.floating, target);
|
|
21032
|
+
const isOverReferenceEl = contains(elements.domReference, target);
|
|
21033
|
+
const refRect = elements.domReference.getBoundingClientRect();
|
|
21034
|
+
const rect = elements.floating.getBoundingClientRect();
|
|
21035
|
+
const side = placement.split('-')[0];
|
|
21036
|
+
const cursorLeaveFromRight = x > rect.right - rect.width / 2;
|
|
21037
|
+
const cursorLeaveFromBottom = y > rect.bottom - rect.height / 2;
|
|
21038
|
+
const isOverReferenceRect = isInside(clientPoint, refRect);
|
|
21039
|
+
if (isOverFloatingEl) {
|
|
21040
|
+
hasLanded = true;
|
|
21041
|
+
if (!isLeave) {
|
|
21042
|
+
return;
|
|
21043
|
+
}
|
|
21044
|
+
}
|
|
21045
|
+
if (isOverReferenceEl) {
|
|
21046
|
+
hasLanded = false;
|
|
21047
|
+
}
|
|
21048
|
+
if (isOverReferenceEl && !isLeave) {
|
|
21049
|
+
hasLanded = true;
|
|
21050
|
+
return;
|
|
21051
|
+
}
|
|
21052
|
+
|
|
21053
|
+
// Prevent overlapping floating element from being stuck in an open-close
|
|
21054
|
+
// loop: https://github.com/floating-ui/floating-ui/issues/1910
|
|
21055
|
+
if (isLeave && isElement(event.relatedTarget) && contains(elements.floating, event.relatedTarget)) {
|
|
21056
|
+
return;
|
|
21057
|
+
}
|
|
21058
|
+
|
|
21059
|
+
// If any nested child is open, abort.
|
|
21060
|
+
if (tree && getChildren(tree.nodesRef.current, nodeId).some(_ref2 => {
|
|
21061
|
+
let {
|
|
21062
|
+
context
|
|
21063
|
+
} = _ref2;
|
|
21064
|
+
return context == null ? void 0 : context.open;
|
|
21065
|
+
})) {
|
|
21066
|
+
return;
|
|
21067
|
+
}
|
|
21068
|
+
|
|
21069
|
+
// If the pointer is leaving from the opposite side, the "buffer" logic
|
|
21070
|
+
// creates a point where the floating element remains open, but should be
|
|
21071
|
+
// ignored.
|
|
21072
|
+
// A constant of 1 handles floating point rounding errors.
|
|
21073
|
+
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) {
|
|
21074
|
+
return close();
|
|
21075
|
+
}
|
|
21076
|
+
|
|
21077
|
+
// Ignore when the cursor is within the rectangular trough between the
|
|
21078
|
+
// two elements. Since the triangle is created from the cursor point,
|
|
21079
|
+
// which can start beyond the ref element's edge, traversing back and
|
|
21080
|
+
// forth from the ref to the floating element can cause it to close. This
|
|
21081
|
+
// ensures it always remains open in that case.
|
|
21082
|
+
let rectPoly = [];
|
|
21083
|
+
switch (side) {
|
|
21084
|
+
case 'top':
|
|
21085
|
+
rectPoly = [[rect.left, refRect.top + 1], [rect.left, rect.bottom - 1], [rect.right, rect.bottom - 1], [rect.right, refRect.top + 1]];
|
|
21086
|
+
isInsideRect = clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= refRect.top + 1;
|
|
21087
|
+
break;
|
|
21088
|
+
case 'bottom':
|
|
21089
|
+
rectPoly = [[rect.left, rect.top + 1], [rect.left, refRect.bottom - 1], [rect.right, refRect.bottom - 1], [rect.right, rect.top + 1]];
|
|
21090
|
+
isInsideRect = clientX >= rect.left && clientX <= rect.right && clientY >= refRect.bottom - 1 && clientY <= rect.bottom;
|
|
21091
|
+
break;
|
|
21092
|
+
case 'left':
|
|
21093
|
+
rectPoly = [[rect.right - 1, rect.bottom], [rect.right - 1, rect.top], [refRect.left + 1, rect.top], [refRect.left + 1, rect.bottom]];
|
|
21094
|
+
isInsideRect = clientX >= rect.left && clientX <= refRect.left + 1 && clientY >= rect.top && clientY <= rect.bottom;
|
|
21095
|
+
break;
|
|
21096
|
+
case 'right':
|
|
21097
|
+
rectPoly = [[refRect.right - 1, rect.bottom], [refRect.right - 1, rect.top], [rect.left + 1, rect.top], [rect.left + 1, rect.bottom]];
|
|
21098
|
+
isInsideRect = clientX >= refRect.right - 1 && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
|
|
21099
|
+
break;
|
|
21100
|
+
}
|
|
21101
|
+
function getPolygon(_ref3) {
|
|
21102
|
+
let [x, y] = _ref3;
|
|
21103
|
+
const isFloatingWider = rect.width > refRect.width;
|
|
21104
|
+
const isFloatingTaller = rect.height > refRect.height;
|
|
21105
|
+
switch (side) {
|
|
21106
|
+
case 'top':
|
|
21107
|
+
{
|
|
21108
|
+
const cursorPointOne = [isFloatingWider ? x + buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y + buffer + 1];
|
|
21109
|
+
const cursorPointTwo = [isFloatingWider ? x - buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y + buffer + 1];
|
|
21110
|
+
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]];
|
|
21111
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
21112
|
+
}
|
|
21113
|
+
case 'bottom':
|
|
21114
|
+
{
|
|
21115
|
+
const cursorPointOne = [isFloatingWider ? x + buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y - buffer];
|
|
21116
|
+
const cursorPointTwo = [isFloatingWider ? x - buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y - buffer];
|
|
21117
|
+
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]];
|
|
21118
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
21119
|
+
}
|
|
21120
|
+
case 'left':
|
|
21121
|
+
{
|
|
21122
|
+
const cursorPointOne = [x + buffer + 1, isFloatingTaller ? y + buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
21123
|
+
const cursorPointTwo = [x + buffer + 1, isFloatingTaller ? y - buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
21124
|
+
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]];
|
|
21125
|
+
return [...commonPoints, cursorPointOne, cursorPointTwo];
|
|
21126
|
+
}
|
|
21127
|
+
case 'right':
|
|
21128
|
+
{
|
|
21129
|
+
const cursorPointOne = [x - buffer, isFloatingTaller ? y + buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
21130
|
+
const cursorPointTwo = [x - buffer, isFloatingTaller ? y - buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
21131
|
+
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]];
|
|
21132
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
21133
|
+
}
|
|
21134
|
+
}
|
|
21135
|
+
}
|
|
21136
|
+
const poly = isInsideRect ? rectPoly : getPolygon([x, y]);
|
|
21137
|
+
if (isInsideRect) {
|
|
21138
|
+
return;
|
|
21139
|
+
} else if (hasLanded && !isOverReferenceRect) {
|
|
21140
|
+
return close();
|
|
21141
|
+
}
|
|
21142
|
+
if (!isPointInPolygon([clientX, clientY], poly)) {
|
|
21143
|
+
close();
|
|
21144
|
+
} else if (restMs && !hasLanded) {
|
|
21145
|
+
timeoutId = setTimeout(close, restMs);
|
|
21146
|
+
}
|
|
21147
|
+
};
|
|
21148
|
+
};
|
|
21149
|
+
fn.__options = {
|
|
21150
|
+
blockPointerEvents
|
|
21151
|
+
};
|
|
21152
|
+
return fn;
|
|
21153
|
+
}
|
|
21154
|
+
|
|
20979
21155
|
/**
|
|
20980
21156
|
* Provides data to position a floating element and context to add interactions.
|
|
20981
21157
|
* @see https://floating-ui.com/docs/react
|
|
@@ -21374,7 +21550,8 @@ function useTooltip(_ref) {
|
|
|
21374
21550
|
delay: {
|
|
21375
21551
|
open: delay,
|
|
21376
21552
|
close: 0
|
|
21377
|
-
}
|
|
21553
|
+
},
|
|
21554
|
+
handleClose: safePolygon()
|
|
21378
21555
|
});
|
|
21379
21556
|
const focus = useFocus(context);
|
|
21380
21557
|
const dismiss = useDismiss(context);
|