@redsift/table 9.2.2-muiv5 → 9.2.3-muiv5

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