bnstooltips 1.5.0 → 1.5.6

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/build/index.js CHANGED
@@ -4948,6 +4948,184 @@ Object.assign({}, applyStyles$1, {
4948
4948
  }
4949
4949
  });
4950
4950
 
4951
+ var mouseCoords = {
4952
+ clientX: 0,
4953
+ clientY: 0
4954
+ };
4955
+ var activeInstances = [];
4956
+
4957
+ function storeMouseCoords(_ref) {
4958
+ var clientX = _ref.clientX,
4959
+ clientY = _ref.clientY;
4960
+ mouseCoords = {
4961
+ clientX: clientX,
4962
+ clientY: clientY
4963
+ };
4964
+ }
4965
+
4966
+ function addMouseCoordsListener(doc) {
4967
+ doc.addEventListener('mousemove', storeMouseCoords);
4968
+ }
4969
+
4970
+ function removeMouseCoordsListener(doc) {
4971
+ doc.removeEventListener('mousemove', storeMouseCoords);
4972
+ }
4973
+
4974
+ var followCursor = {
4975
+ name: 'followCursor',
4976
+ defaultValue: false,
4977
+ fn: function fn(instance) {
4978
+ var reference = instance.reference;
4979
+ var doc = getOwnerDocument(instance.props.triggerTarget || reference);
4980
+ var isInternalUpdate = false;
4981
+ var wasFocusEvent = false;
4982
+ var isUnmounted = true;
4983
+ var prevProps = instance.props;
4984
+
4985
+ function getIsInitialBehavior() {
4986
+ return instance.props.followCursor === 'initial' && instance.state.isVisible;
4987
+ }
4988
+
4989
+ function addListener() {
4990
+ doc.addEventListener('mousemove', onMouseMove);
4991
+ }
4992
+
4993
+ function removeListener() {
4994
+ doc.removeEventListener('mousemove', onMouseMove);
4995
+ }
4996
+
4997
+ function unsetGetReferenceClientRect() {
4998
+ isInternalUpdate = true;
4999
+ instance.setProps({
5000
+ getReferenceClientRect: null
5001
+ });
5002
+ isInternalUpdate = false;
5003
+ }
5004
+
5005
+ function onMouseMove(event) {
5006
+ // If the instance is interactive, avoid updating the position unless it's
5007
+ // over the reference element
5008
+ var isCursorOverReference = event.target ? reference.contains(event.target) : true;
5009
+ var followCursor = instance.props.followCursor;
5010
+ var clientX = event.clientX,
5011
+ clientY = event.clientY;
5012
+ var rect = reference.getBoundingClientRect();
5013
+ var relativeX = clientX - rect.left;
5014
+ var relativeY = clientY - rect.top;
5015
+
5016
+ if (isCursorOverReference || !instance.props.interactive) {
5017
+ instance.setProps({
5018
+ // @ts-ignore - unneeded DOMRect properties
5019
+ getReferenceClientRect: function getReferenceClientRect() {
5020
+ var rect = reference.getBoundingClientRect();
5021
+ var x = clientX;
5022
+ var y = clientY;
5023
+
5024
+ if (followCursor === 'initial') {
5025
+ x = rect.left + relativeX;
5026
+ y = rect.top + relativeY;
5027
+ }
5028
+
5029
+ var top = followCursor === 'horizontal' ? rect.top : y;
5030
+ var right = followCursor === 'vertical' ? rect.right : x;
5031
+ var bottom = followCursor === 'horizontal' ? rect.bottom : y;
5032
+ var left = followCursor === 'vertical' ? rect.left : x;
5033
+ return {
5034
+ width: right - left,
5035
+ height: bottom - top,
5036
+ top: top,
5037
+ right: right,
5038
+ bottom: bottom,
5039
+ left: left
5040
+ };
5041
+ }
5042
+ });
5043
+ }
5044
+ }
5045
+
5046
+ function create() {
5047
+ if (instance.props.followCursor) {
5048
+ activeInstances.push({
5049
+ instance: instance,
5050
+ doc: doc
5051
+ });
5052
+ addMouseCoordsListener(doc);
5053
+ }
5054
+ }
5055
+
5056
+ function destroy() {
5057
+ activeInstances = activeInstances.filter(function (data) {
5058
+ return data.instance !== instance;
5059
+ });
5060
+
5061
+ if (activeInstances.filter(function (data) {
5062
+ return data.doc === doc;
5063
+ }).length === 0) {
5064
+ removeMouseCoordsListener(doc);
5065
+ }
5066
+ }
5067
+
5068
+ return {
5069
+ onCreate: create,
5070
+ onDestroy: destroy,
5071
+ onBeforeUpdate: function onBeforeUpdate() {
5072
+ prevProps = instance.props;
5073
+ },
5074
+ onAfterUpdate: function onAfterUpdate(_, _ref2) {
5075
+ var followCursor = _ref2.followCursor;
5076
+
5077
+ if (isInternalUpdate) {
5078
+ return;
5079
+ }
5080
+
5081
+ if (followCursor !== undefined && prevProps.followCursor !== followCursor) {
5082
+ destroy();
5083
+
5084
+ if (followCursor) {
5085
+ create();
5086
+
5087
+ if (instance.state.isMounted && !wasFocusEvent && !getIsInitialBehavior()) {
5088
+ addListener();
5089
+ }
5090
+ } else {
5091
+ removeListener();
5092
+ unsetGetReferenceClientRect();
5093
+ }
5094
+ }
5095
+ },
5096
+ onMount: function onMount() {
5097
+ if (instance.props.followCursor && !wasFocusEvent) {
5098
+ if (isUnmounted) {
5099
+ onMouseMove(mouseCoords);
5100
+ isUnmounted = false;
5101
+ }
5102
+
5103
+ if (!getIsInitialBehavior()) {
5104
+ addListener();
5105
+ }
5106
+ }
5107
+ },
5108
+ onTrigger: function onTrigger(_, event) {
5109
+ if (isMouseEvent(event)) {
5110
+ mouseCoords = {
5111
+ clientX: event.clientX,
5112
+ clientY: event.clientY
5113
+ };
5114
+ }
5115
+
5116
+ wasFocusEvent = event.type === 'focus';
5117
+ },
5118
+ onHidden: function onHidden() {
5119
+ if (instance.props.followCursor) {
5120
+ unsetGetReferenceClientRect();
5121
+ removeListener();
5122
+ isUnmounted = true;
5123
+ }
5124
+ }
5125
+ };
5126
+ }
5127
+ };
5128
+
4951
5129
  tippy.setDefaultProps({
4952
5130
  render: render
4953
5131
  });
@@ -5340,9 +5518,9 @@ var css_248z$3 = ".tippy-box[data-animation=fade][data-state=hidden]{opacity:0}[
5340
5518
  styleInject(css_248z$3);
5341
5519
 
5342
5520
  var ItemTooltipWrapper = function (_a) {
5343
- var data = _a.data, region = _a.region, children = _a.children, client = _a.client, _b = _a.offline, offline = _b === void 0 ? false : _b, _c = _a.interactive, interactive = _c === void 0 ? true : _c, _d = _a.placement, placement = _d === void 0 ? "right" : _d, _e = _a.debug, debug = _e === void 0 ? false : _e, jobstyleOverride = _a.jobstyleOverride;
5521
+ var data = _a.data, region = _a.region, children = _a.children, client = _a.client, _b = _a.offline, offline = _b === void 0 ? false : _b, _c = _a.interactive, interactive = _c === void 0 ? true : _c, _d = _a.placement, placement = _d === void 0 ? "right" : _d, _e = _a.debug, debug = _e === void 0 ? false : _e, jobstyleOverride = _a.jobstyleOverride, _f = _a.followCursor, followCursor$1 = _f === void 0 ? false : _f, _g = _a.trigger, trigger = _g === void 0 ? "mouseenter focus" : _g, _h = _a.showArrow, showArrow = _h === void 0 ? true : _h;
5344
5522
  var spanRef = React.useRef(null);
5345
- var _f = React.useState(null), childRef = _f[0], setChildRef = _f[1];
5523
+ var _j = React.useState(null), childRef = _j[0], setChildRef = _j[1];
5346
5524
  /**
5347
5525
  * Mount the temporary span element.
5348
5526
  * retrieve and store the target element's reference.
@@ -5353,10 +5531,10 @@ var ItemTooltipWrapper = function (_a) {
5353
5531
  }
5354
5532
  return function () { return setChildRef(null); };
5355
5533
  }, []);
5356
- var _g = React.useState(true), isOffline = _g[0], setIsOffline = _g[1];
5534
+ var _k = React.useState(true), isOffline = _k[0], setIsOffline = _k[1];
5357
5535
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
5358
5536
  children,
5359
- childRef ? (React__default["default"].createElement(Tippy, { appendTo: document.body, onMount: function () { return setIsOffline(offline); }, placement: placement, animation: "fade", interactive: interactive, content: React__default["default"].createElement(ItemTooltip, { region: region, jobstyleOverride: jobstyleOverride, data: data, offline: isOffline, client: client, debug: debug }), theme: "grade" + data.grade, reference: childRef })) : (React__default["default"].createElement("span", { ref: spanRef, style: { display: "none" } }))));
5537
+ childRef ? (React__default["default"].createElement(Tippy, { arrow: showArrow, trigger: trigger, plugins: [followCursor], followCursor: followCursor$1 && !interactive, appendTo: document.body, onMount: function () { return setIsOffline(offline); }, placement: placement, animation: "fade", interactive: interactive, content: React__default["default"].createElement(ItemTooltip, { region: region, jobstyleOverride: jobstyleOverride, data: data, offline: isOffline, client: client, debug: debug }), theme: "grade" + data.grade, reference: childRef })) : (React__default["default"].createElement("span", { ref: spanRef, style: { display: "none" } }))));
5360
5538
  };
5361
5539
 
5362
5540
  function ItemIconNameDiv(_a) {
@@ -6098,9 +6276,9 @@ var css_248z = ".tippy-box {\n max-width: none !important;\n background-color:
6098
6276
  styleInject(css_248z);
6099
6277
 
6100
6278
  var SkillTooltipWrapper = function (_a) {
6101
- var data = _a.data, children = _a.children, _b = _a.interactive, interactive = _b === void 0 ? false : _b, _c = _a.placement, placement = _c === void 0 ? "right" : _c;
6279
+ var data = _a.data, children = _a.children, _b = _a.interactive, interactive = _b === void 0 ? false : _b, _c = _a.placement, placement = _c === void 0 ? "right" : _c, _d = _a.followCursor, followCursor$1 = _d === void 0 ? false : _d, _e = _a.trigger, trigger = _e === void 0 ? "mouseenter focus" : _e, _f = _a.showArrow, showArrow = _f === void 0 ? true : _f;
6102
6280
  var spanRef = React.useRef(null);
6103
- var _d = React.useState(null), childRef = _d[0], setChildRef = _d[1];
6281
+ var _g = React.useState(null), childRef = _g[0], setChildRef = _g[1];
6104
6282
  /**
6105
6283
  * Mount the temporary span element.
6106
6284
  * retrieve and store the target element's reference.
@@ -6113,7 +6291,7 @@ var SkillTooltipWrapper = function (_a) {
6113
6291
  }, []);
6114
6292
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
6115
6293
  children,
6116
- childRef ? (React__default["default"].createElement(Tippy, { appendTo: document.body, placement: placement, animation: "fade", interactive: interactive, content: React__default["default"].createElement(SkillTooltip, { data: data, debug: false }), theme: "grade" + 4, reference: childRef })) : (React__default["default"].createElement("span", { ref: spanRef, style: { display: "none" } }))));
6294
+ childRef ? (React__default["default"].createElement(Tippy, { arrow: showArrow, trigger: trigger, plugins: [followCursor], followCursor: followCursor$1 && !interactive, appendTo: document.body, placement: placement, animation: "fade", interactive: interactive, content: React__default["default"].createElement(SkillTooltip, { data: data, debug: false }), theme: "grade" + 4, reference: childRef })) : (React__default["default"].createElement("span", { ref: spanRef, style: { display: "none" } }))));
6117
6295
  };
6118
6296
 
6119
6297
  exports.ServerRegion = void 0;