@dr.pogodin/react-utils 1.52.7 → 1.52.9

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.
@@ -1,4 +1,4 @@
1
- /* global window */import { useEffect, useEffectEvent, useRef, useState } from "react";
1
+ /* global window */import { useEffect, useRef, useState } from "react";
2
2
  import { useTheme } from "@dr.pogodin/react-themes";
3
3
  import Tooltip, { PLACEMENTS } from "./Tooltip.js";
4
4
  const defaultTheme = {
@@ -40,9 +40,7 @@ const WithTooltip = ({
40
40
  ...htmlAttributes
41
41
  }) => {
42
42
  const custom = useTheme("WithTooltip", defaultTheme, theme);
43
- const {
44
- current: heap
45
- } = useRef({
43
+ const [heap, setHeap] = useState({
46
44
  lastCursorX: 0,
47
45
  lastCursorY: 0,
48
46
  timerId: undefined,
@@ -51,7 +49,6 @@ const WithTooltip = ({
51
49
  const tooltipRef = useRef(null);
52
50
  const wrapperRef = useRef(null);
53
51
  const [showTooltip, setShowTooltip] = useState(false);
54
- const getHeap = useEffectEvent(() => heap);
55
52
  const updatePortalPosition = (cursorX, cursorY) => {
56
53
  if (showTooltip) {
57
54
  const wrapperRect = wrapperRef.current.getBoundingClientRect();
@@ -61,22 +58,30 @@ const WithTooltip = ({
61
58
  tooltipRef.current.pointTo(cursorX + window.scrollX, cursorY + window.scrollY, placement, wrapperRef.current);
62
59
  }
63
60
  } else {
64
- heap.lastCursorX = cursorX;
65
- heap.lastCursorY = cursorY; // If tooltip was triggered by a touch, we delay its opening by a bit,
66
- // to ensure it was not a touch-click - in the case of touch click we
67
- // want to do the click, rather than show the tooltip, and the delay
68
- // gives click handler a chance to abort the tooltip openning.
69
- if (heap.triggeredByTouch) {
70
- heap.timerId ??= setTimeout(() => {
71
- heap.triggeredByTouch = false;
72
- heap.timerId = undefined;
73
- setShowTooltip(true);
74
- }, 300); // Otherwise we can just open the tooltip right away.
75
- } else setShowTooltip(true);
61
+ setHeap(prev => {
62
+ const res = {
63
+ ...prev,
64
+ lastCursorX: cursorX,
65
+ lastCursorY: cursorY
66
+ }; // If tooltip was triggered by a touch, we delay its opening by a bit,
67
+ // to ensure it was not a touch-click - in the case of touch click we
68
+ // want to do the click, rather than show the tooltip, and the delay
69
+ // gives click handler a chance to abort the tooltip openning.
70
+ if (res.triggeredByTouch) {
71
+ res.timerId ??= setTimeout(() => {
72
+ setHeap(p => ({
73
+ ...p,
74
+ timerId: undefined,
75
+ triggeredByTouch: false
76
+ }));
77
+ setShowTooltip(true);
78
+ }, 300); // Otherwise we can just open the tooltip right away.
79
+ } else setShowTooltip(true);
80
+ return res;
81
+ });
76
82
  }
77
83
  };
78
84
  useEffect(() => {
79
- const heap2 = getHeap();
80
85
  if (showTooltip && tip !== null) {
81
86
  // This is necessary to ensure that even when a single mouse event
82
87
  // arrives to a tool-tipped component, the tooltip is correctly positioned
@@ -84,7 +89,10 @@ const WithTooltip = ({
84
89
  // the tooltip is fully mounted, and that is delayed to future rendering
85
90
  // cycle due to the implementation).
86
91
  if (tooltipRef.current) {
87
- tooltipRef.current.pointTo(heap2.lastCursorX + window.scrollX, heap2.lastCursorY + window.scrollY, placement, wrapperRef.current);
92
+ setHeap(prev => {
93
+ tooltipRef.current?.pointTo(prev.lastCursorX + window.scrollX, prev.lastCursorY + window.scrollY, placement, wrapperRef.current);
94
+ return prev;
95
+ });
88
96
  }
89
97
  const listener = () => {
90
98
  setShowTooltip(false);
@@ -114,14 +122,17 @@ const WithTooltip = ({
114
122
  window.removeEventListener("touchcancel", listener);
115
123
  window.removeEventListener("touchend", listener);
116
124
  };
117
- }, []);
125
+ }, [heap]);
118
126
  return /*#__PURE__*/_jsxs("div", {
119
127
  className: container,
120
128
  onClick: e => {
121
129
  if (heap.timerId) {
122
130
  clearTimeout(heap.timerId);
123
- heap.timerId = undefined;
124
- heap.triggeredByTouch = false;
131
+ setHeap({
132
+ ...heap,
133
+ timerId: undefined,
134
+ triggeredByTouch: false
135
+ });
125
136
  }
126
137
  onClick?.(e);
127
138
  },
@@ -144,8 +155,11 @@ const WithTooltip = ({
144
155
  onMouseMove?.(e);
145
156
  },
146
157
  onTouchStart: e => {
147
- heap.ignoreMouseMove = true;
148
- heap.triggeredByTouch = true; // TODO: I guess, it should be something more complex here,
158
+ setHeap({
159
+ ...heap,
160
+ ignoreMouseMove: true,
161
+ triggeredByTouch: true
162
+ }); // TODO: I guess, it should be something more complex here,
149
163
  // to actually respond to the first / whatever touch we need.
150
164
  const touch = e.targetTouches.item(0);
151
165
  updatePortalPosition(touch.clientX, touch.clientY);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useEffect","useEffectEvent","useRef","useState","useTheme","Tooltip","PLACEMENTS","defaultTheme","jsx","_jsx","jsxs","_jsxs","WithTooltip","children","className","classNameProp","onClick","onContextMenu","onMouseLeave","onMouseMove","onTouchStart","placement","ABOVE_CURSOR","ref","style","theme","tip","htmlAttributes","custom","current","heap","lastCursorX","lastCursorY","timerId","undefined","triggeredByTouch","tooltipRef","wrapperRef","showTooltip","setShowTooltip","getHeap","updatePortalPosition","cursorX","cursorY","wrapperRect","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","setTimeout","heap2","listener","addEventListener","removeEventListener","container","wrapper","clearTimeout","e","preventDefault","ignoreMouseMove","clientX","clientY","touch","targetTouches","item","node","role"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n useEffect,\n useEffectEvent,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n type ThemeKeysT as TooltipThemeKeysT,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = HTMLAttributes<HTMLDivElement> & {\n children?: ReactNode;\n placement?: PLACEMENTS;\n ref?: RefObject<HTMLDivElement | null>;\n theme?: Theme<'wrapper' | TooltipThemeKeysT>;\n tip?: ReactNode;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n ignoreMouseMove?: boolean;\n lastCursorX: number;\n lastCursorY: number;\n timerId?: NodeJS.Timeout;\n triggeredByTouch: boolean;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param tip &ndash; Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst WithTooltip: FunctionComponent<PropsT> = ({\n children,\n className: classNameProp,\n onClick,\n onContextMenu,\n onMouseLeave,\n onMouseMove,\n onTouchStart,\n placement = PLACEMENTS.ABOVE_CURSOR,\n ref,\n style,\n theme,\n tip,\n ...htmlAttributes\n}) => {\n const custom = useTheme('WithTooltip', defaultTheme, theme);\n\n const { current: heap } = useRef<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n timerId: undefined,\n triggeredByTouch: false,\n });\n const tooltipRef = useRef<TooltipRefT>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const getHeap = useEffectEvent(() => heap);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (showTooltip) {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n }\n } else {\n heap.lastCursorX = cursorX;\n heap.lastCursorY = cursorY;\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (heap.triggeredByTouch) {\n heap.timerId ??= setTimeout(() => {\n heap.triggeredByTouch = false;\n heap.timerId = undefined;\n setShowTooltip(true);\n }, 300);\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n }\n };\n\n useEffect(() => {\n const heap2 = getHeap();\n\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n heap2.lastCursorX + window.scrollX,\n heap2.lastCursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n }\n\n const listener = () => {\n setShowTooltip(false);\n };\n window.addEventListener('scroll', listener);\n return () => {\n window.removeEventListener('scroll', listener);\n };\n }\n return undefined;\n }, [\n placement,\n showTooltip,\n tip,\n ]);\n\n let container = custom.wrapper;\n if (classNameProp) container += ` ${classNameProp}`;\n\n useEffect(() => {\n const listener = () => {\n setShowTooltip(false);\n heap.triggeredByTouch = false;\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n };\n window.addEventListener('touchcancel', listener);\n window.addEventListener('touchend', listener);\n return () => {\n window.removeEventListener('touchcancel', listener);\n window.removeEventListener('touchend', listener);\n };\n }, []);\n\n return (\n <div\n className={container}\n onClick={(e) => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n onClick?.(e);\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n onContextMenu?.(e);\n }}\n onMouseLeave={(e) => {\n setShowTooltip(false);\n onMouseLeave?.(e);\n }}\n onMouseMove={(e) => {\n // NOTE: Because on touch devices mouse move events are still fired\n // after touch is released, to emulate mouse clicks for old websites.\n // If we don't ignore it here, the tooltip will appear after the touch\n // is released.\n if (!heap.ignoreMouseMove) {\n updatePortalPosition(e.clientX, e.clientY);\n }\n onMouseMove?.(e);\n }}\n onTouchStart={(e) => {\n heap.ignoreMouseMove = true;\n heap.triggeredByTouch = true;\n\n // TODO: I guess, it should be something more complex here,\n // to actually respond to the first / whatever touch we need.\n const touch = e.targetTouches.item(0);\n updatePortalPosition(touch.clientX, touch.clientY);\n\n onTouchStart?.(e);\n }}\n ref={(node) => {\n wrapperRef.current = node;\n\n // eslint-disable-next-line no-param-reassign\n if (ref) ref.current = node;\n }}\n role=\"presentation\"\n style={style}\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...htmlAttributes}\n >\n {\n showTooltip && tip !== null\n ? <Tooltip ref={tooltipRef} theme={custom}>{tip}</Tooltip>\n : null\n }\n {children}\n </div>\n );\n};\n\ntype ExportT = {\n PLACEMENTS: typeof PLACEMENTS;\n} & typeof WithTooltip;\n\nconst e: ExportT = WithTooltip as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":"AAAA,mBAEA,SAKEA,SAAS,EACTC,cAAc,EACdC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,SAAqBC,QAAQ,QAAQ,0BAA0B;AAE/D,OAAOC,OAAO,IACZC,UAAU;AAAA,MAAAC,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAIoC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA,4BA2BhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAsC,GAAGA,CAAC;EAC9CC,QAAQ;EACRC,SAAS,EAAEC,aAAa;EACxBC,OAAO;EACPC,aAAa;EACbC,YAAY;EACZ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EAAE;QACzBvB,oBAAoB,CAACqB,CAAC,CAACG,OAAO,EAAEH,CAAC,CAACI,OAAO,CAAC;MAC5C;MACA/C,WAAW,GAAG2C,CAAC,CAAC;IAClB,CAAE;IACF1C,YAAY,EAAG0C,CAAC,IAAK;MACnBhC,IAAI,CAACkC,eAAe,GAAG,IAAI;MAC3BlC,IAAI,CAACK,gBAAgB,GAAG,IAAI,CAE5B;MACA;MACA,MAAMgC,KAAK,GAAGL,CAAC,CAACM,aAAa,CAACC,IAAI,CAAC,CAAC,CAAC;MACrC5B,oBAAoB,CAAC0B,KAAK,CAACF,OAAO,EAAEE,KAAK,CAACD,OAAO,CAAC;MAElD9C,YAAY,GAAG0C,CAAC,CAAC;IACnB,CAAE;IACFvC,GAAG,EAAG+C,IAAI,IAAK;MACbjC,UAAU,CAACR,OAAO,GAAGyC,IAAI,CAEzB;MACA,IAAI/C,GAAG,EAAEA,GAAG,CAACM,OAAO,GAAGyC,IAAI;IAC7B,CAAE;IACFC,IAAI,EAAC,cAAc;IACnB/C,KAAK,EAAEA,KAEP;IAAA;IAAA,GACIG,cAAc;IAAAd,QAAA,GAGhByB,WAAW,IAAIZ,GAAG,KAAK,IAAI,gBACvBjB,IAAA,CAACJ,OAAO;MAACkB,GAAG,EAAEa,UAAW;MAACX,KAAK,EAAEG,MAAO;MAAAf,QAAA,EAAEa;IAAG,CAAU,CAAC,GACxD,IAAI,EAETb,QAAQ;EAAA,CACN,CAAC;AAEV,CAAC;AAMD,MAAMiD,CAAU,GAAGlD,WAAsB;AAEzCkD,CAAC,CAACxD,UAAU,GAAGA,UAAU;AAEzB,eAAewD,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useEffect","useRef","useState","useTheme","Tooltip","PLACEMENTS","defaultTheme","jsx","_jsx","jsxs","_jsxs","WithTooltip","children","className","classNameProp","onClick","onContextMenu","onMouseLeave","onMouseMove","onTouchStart","placement","ABOVE_CURSOR","ref","style","theme","tip","htmlAttributes","custom","heap","setHeap","lastCursorX","lastCursorY","timerId","undefined","triggeredByTouch","tooltipRef","wrapperRef","showTooltip","setShowTooltip","updatePortalPosition","cursorX","cursorY","wrapperRect","current","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","prev","res","setTimeout","p","listener","addEventListener","removeEventListener","container","wrapper","clearTimeout","e","preventDefault","ignoreMouseMove","clientX","clientY","touch","targetTouches","item","node","role"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n type ThemeKeysT as TooltipThemeKeysT,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = HTMLAttributes<HTMLDivElement> & {\n children?: ReactNode;\n placement?: PLACEMENTS;\n ref?: RefObject<HTMLDivElement | null>;\n theme?: Theme<'wrapper' | TooltipThemeKeysT>;\n tip?: ReactNode;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n ignoreMouseMove?: boolean;\n lastCursorX: number;\n lastCursorY: number;\n timerId?: NodeJS.Timeout;\n triggeredByTouch: boolean;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param tip &ndash; Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst WithTooltip: FunctionComponent<PropsT> = ({\n children,\n className: classNameProp,\n onClick,\n onContextMenu,\n onMouseLeave,\n onMouseMove,\n onTouchStart,\n placement = PLACEMENTS.ABOVE_CURSOR,\n ref,\n style,\n theme,\n tip,\n ...htmlAttributes\n}) => {\n const custom = useTheme('WithTooltip', defaultTheme, theme);\n\n const [heap, setHeap] = useState<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n timerId: undefined,\n triggeredByTouch: false,\n });\n\n const tooltipRef = useRef<TooltipRefT>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (showTooltip) {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n }\n } else {\n setHeap((prev) => {\n const res: HeapT = {\n ...prev,\n lastCursorX: cursorX,\n lastCursorY: cursorY,\n };\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (res.triggeredByTouch) {\n res.timerId ??= setTimeout(() => {\n setHeap((p) => ({\n ...p,\n timerId: undefined,\n triggeredByTouch: false,\n }));\n\n setShowTooltip(true);\n }, 300);\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n\n return res;\n });\n }\n };\n\n useEffect(() => {\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n setHeap((prev) => {\n tooltipRef.current?.pointTo(\n prev.lastCursorX + window.scrollX,\n prev.lastCursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n return prev;\n });\n }\n\n const listener = () => {\n setShowTooltip(false);\n };\n window.addEventListener('scroll', listener);\n return () => {\n window.removeEventListener('scroll', listener);\n };\n }\n return undefined;\n }, [\n placement,\n showTooltip,\n tip,\n ]);\n\n let container = custom.wrapper;\n if (classNameProp) container += ` ${classNameProp}`;\n\n useEffect(() => {\n const listener = () => {\n setShowTooltip(false);\n heap.triggeredByTouch = false;\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n };\n window.addEventListener('touchcancel', listener);\n window.addEventListener('touchend', listener);\n return () => {\n window.removeEventListener('touchcancel', listener);\n window.removeEventListener('touchend', listener);\n };\n }, [heap]);\n\n return (\n <div\n className={container}\n onClick={(e) => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n\n setHeap({\n ...heap,\n timerId: undefined,\n triggeredByTouch: false,\n });\n }\n onClick?.(e);\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n onContextMenu?.(e);\n }}\n onMouseLeave={(e) => {\n setShowTooltip(false);\n onMouseLeave?.(e);\n }}\n onMouseMove={(e) => {\n // NOTE: Because on touch devices mouse move events are still fired\n // after touch is released, to emulate mouse clicks for old websites.\n // If we don't ignore it here, the tooltip will appear after the touch\n // is released.\n if (!heap.ignoreMouseMove) {\n updatePortalPosition(e.clientX, e.clientY);\n }\n onMouseMove?.(e);\n }}\n onTouchStart={(e) => {\n setHeap({\n ...heap,\n ignoreMouseMove: true,\n triggeredByTouch: true,\n });\n\n // TODO: I guess, it should be something more complex here,\n // to actually respond to the first / whatever touch we need.\n const touch = e.targetTouches.item(0);\n updatePortalPosition(touch.clientX, touch.clientY);\n\n onTouchStart?.(e);\n }}\n ref={(node) => {\n wrapperRef.current = node;\n\n // eslint-disable-next-line no-param-reassign\n if (ref) ref.current = node;\n }}\n role=\"presentation\"\n style={style}\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...htmlAttributes}\n >\n {\n showTooltip && tip !== null\n ? <Tooltip ref={tooltipRef} theme={custom}>{tip}</Tooltip>\n : null\n }\n {children}\n </div>\n );\n};\n\ntype ExportT = {\n PLACEMENTS: typeof PLACEMENTS;\n} & typeof WithTooltip;\n\nconst e: ExportT = WithTooltip as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":"AAAA,mBAEA,SAKEA,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,SAAqBC,QAAQ,QAAQ,0BAA0B;AAE/D,OAAOC,OAAO,IACZC,UAAU;AAAA,MAAAC,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAIoC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA,4BA2BhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAsC,GAAGA,CAAC;EAC9CC,QAAQ;EACRC,SAAS,EAAEC,aAAa;EACxBC,OAAO;EACPC,aAAa;EACbC,YAAY;EACZC,WAAW;EACXC,YAAY;EACZC,SAAS,GAAGf,UAAU,CAACgB,YAAY;EACnCC,GAAG;EACHC,KAAK;EACLC,KAAK;EACLC,GAAG;EACH,GAAGC;AACL,CAAC,KAAK;EACJ,MAAMC,MAAM,GAAGxB,QAAQ,CAAC,aAAa,EAAEG,YAAY,EAAEkB,KAAK,CAAC;EAE3D,MAAM,CAACI,IAAI,EAAEC,OAAO,CAAC,GAAG3B,QAAQ,CAAQ;IACtC4B,WAAW,EAAE,CAAC;IACdC,WAAW,EAAE,CAAC;IACdC,OAAO,EAAEC,SAAS;IAClBC,gBAAgB,EAAE;EACpB,CAAC,CAAC;EAEF,MAAMC,UAAU,GAAGlC,MAAM,CAAc,IAAI,CAAC;EAC5C,MAAMmC,UAAU,GAAGnC,MAAM,CAAiB,IAAI,CAAC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BAAoB,CAAC6B,KAAK,CAACF,OAAO,EAAEE,KAAK,CAACD,OAAO,CAAC;MAElDhD,YAAY,GAAG4C,CAAC,CAAC;IACnB,CAAE;IACFzC,GAAG,EAAGiD,IAAI,IAAK;MACbnC,UAAU,CAACO,OAAO,GAAG4B,IAAI,CAEzB;MACA,IAAIjD,GAAG,EAAEA,GAAG,CAACqB,OAAO,GAAG4B,IAAI;IAC7B,CAAE;IACFC,IAAI,EAAC,cAAc;IACnBjD,KAAK,EAAEA,KAEP;IAAA;IAAA,GACIG,cAAc;IAAAd,QAAA,GAGhByB,WAAW,IAAIZ,GAAG,KAAK,IAAI,gBACvBjB,IAAA,CAACJ,OAAO;MAACkB,GAAG,EAAEa,UAAW;MAACX,KAAK,EAAEG,MAAO;MAAAf,QAAA,EAAEa;IAAG,CAAU,CAAC,GACxD,IAAI,EAETb,QAAQ;EAAA,CACN,CAAC;AAEV,CAAC;AAMD,MAAMmD,CAAU,GAAGpD,WAAsB;AAEzCoD,CAAC,CAAC1D,UAAU,GAAGA,UAAU;AAEzB,eAAe0D,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- /* global window */import{useEffect,useEffectEvent,useRef,useState}from"react";import{useTheme}from"@dr.pogodin/react-themes";import Tooltip,{PLACEMENTS}from"./Tooltip.js";const defaultTheme={"ad":"n6OiU9","hoc":"zwsjGc","context":"JVJPcU","appearance":"_9U4YiR","arrow":"_9n65k-","container":"uA1tHZ","wrapper":"JFVmGf"};import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";/**
1
+ /* global window */import{useEffect,useRef,useState}from"react";import{useTheme}from"@dr.pogodin/react-themes";import Tooltip,{PLACEMENTS}from"./Tooltip.js";const defaultTheme={"ad":"n6OiU9","hoc":"zwsjGc","context":"JVJPcU","appearance":"_9U4YiR","arrow":"_9n65k-","container":"uA1tHZ","wrapper":"JFVmGf"};import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";/**
2
2
  * Implements a simple to use and themeable tooltip component, _e.g._
3
3
  * ```js
4
4
  * <WithTooltip tip="This is example tooltip.">
@@ -11,21 +11,21 @@
11
11
  * @param tip &ndash; Anything React is able to render,
12
12
  * _e.g._ a tooltip text. This will be the tooltip content.
13
13
  * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.
14
- */const WithTooltip=({children,className:classNameProp,onClick,onContextMenu,onMouseLeave,onMouseMove,onTouchStart,placement=PLACEMENTS.ABOVE_CURSOR,ref,style,theme,tip,...htmlAttributes})=>{const custom=useTheme("WithTooltip",defaultTheme,theme);const{current:heap}=useRef({lastCursorX:0,lastCursorY:0,timerId:undefined,triggeredByTouch:false});const tooltipRef=useRef(null);const wrapperRef=useRef(null);const[showTooltip,setShowTooltip]=useState(false);const getHeap=useEffectEvent(()=>heap);const updatePortalPosition=(cursorX,cursorY)=>{if(showTooltip){const wrapperRect=wrapperRef.current.getBoundingClientRect();if(cursorX<wrapperRect.left||cursorX>wrapperRect.right||cursorY<wrapperRect.top||cursorY>wrapperRect.bottom){setShowTooltip(false);}else if(tooltipRef.current){tooltipRef.current.pointTo(cursorX+window.scrollX,cursorY+window.scrollY,placement,wrapperRef.current);}}else{heap.lastCursorX=cursorX;heap.lastCursorY=cursorY;// If tooltip was triggered by a touch, we delay its opening by a bit,
14
+ */const WithTooltip=({children,className:classNameProp,onClick,onContextMenu,onMouseLeave,onMouseMove,onTouchStart,placement=PLACEMENTS.ABOVE_CURSOR,ref,style,theme,tip,...htmlAttributes})=>{const custom=useTheme("WithTooltip",defaultTheme,theme);const[heap,setHeap]=useState({lastCursorX:0,lastCursorY:0,timerId:undefined,triggeredByTouch:false});const tooltipRef=useRef(null);const wrapperRef=useRef(null);const[showTooltip,setShowTooltip]=useState(false);const updatePortalPosition=(cursorX,cursorY)=>{if(showTooltip){const wrapperRect=wrapperRef.current.getBoundingClientRect();if(cursorX<wrapperRect.left||cursorX>wrapperRect.right||cursorY<wrapperRect.top||cursorY>wrapperRect.bottom){setShowTooltip(false);}else if(tooltipRef.current){tooltipRef.current.pointTo(cursorX+window.scrollX,cursorY+window.scrollY,placement,wrapperRef.current);}}else{setHeap(prev=>{const res={...prev,lastCursorX:cursorX,lastCursorY:cursorY};// If tooltip was triggered by a touch, we delay its opening by a bit,
15
15
  // to ensure it was not a touch-click - in the case of touch click we
16
16
  // want to do the click, rather than show the tooltip, and the delay
17
17
  // gives click handler a chance to abort the tooltip openning.
18
- if(heap.triggeredByTouch){heap.timerId??=setTimeout(()=>{heap.triggeredByTouch=false;heap.timerId=undefined;setShowTooltip(true);},300);// Otherwise we can just open the tooltip right away.
19
- }else setShowTooltip(true);}};useEffect(()=>{const heap2=getHeap();if(showTooltip&&tip!==null){// This is necessary to ensure that even when a single mouse event
18
+ if(res.triggeredByTouch){res.timerId??=setTimeout(()=>{setHeap(p=>({...p,timerId:undefined,triggeredByTouch:false}));setShowTooltip(true);},300);// Otherwise we can just open the tooltip right away.
19
+ }else setShowTooltip(true);return res;});}};useEffect(()=>{if(showTooltip&&tip!==null){// This is necessary to ensure that even when a single mouse event
20
20
  // arrives to a tool-tipped component, the tooltip is correctly positioned
21
21
  // once opened (because similar call above does not have effect until
22
22
  // the tooltip is fully mounted, and that is delayed to future rendering
23
23
  // cycle due to the implementation).
24
- if(tooltipRef.current){tooltipRef.current.pointTo(heap2.lastCursorX+window.scrollX,heap2.lastCursorY+window.scrollY,placement,wrapperRef.current);}const listener=()=>{setShowTooltip(false);};window.addEventListener("scroll",listener);return()=>{window.removeEventListener("scroll",listener);};}return undefined;},[placement,showTooltip,tip]);let container=custom.wrapper;if(classNameProp)container+=` ${classNameProp}`;useEffect(()=>{const listener=()=>{setShowTooltip(false);heap.triggeredByTouch=false;if(heap.timerId){clearTimeout(heap.timerId);heap.timerId=undefined;heap.triggeredByTouch=false;}};window.addEventListener("touchcancel",listener);window.addEventListener("touchend",listener);return()=>{window.removeEventListener("touchcancel",listener);window.removeEventListener("touchend",listener);};},[]);return/*#__PURE__*/_jsxs("div",{className:container,onClick:e=>{if(heap.timerId){clearTimeout(heap.timerId);heap.timerId=undefined;heap.triggeredByTouch=false;}onClick?.(e);},onContextMenu:e=>{e.preventDefault();onContextMenu?.(e);},onMouseLeave:e=>{setShowTooltip(false);onMouseLeave?.(e);},onMouseMove:e=>{// NOTE: Because on touch devices mouse move events are still fired
24
+ if(tooltipRef.current){setHeap(prev=>{tooltipRef.current?.pointTo(prev.lastCursorX+window.scrollX,prev.lastCursorY+window.scrollY,placement,wrapperRef.current);return prev;});}const listener=()=>{setShowTooltip(false);};window.addEventListener("scroll",listener);return()=>{window.removeEventListener("scroll",listener);};}return undefined;},[placement,showTooltip,tip]);let container=custom.wrapper;if(classNameProp)container+=` ${classNameProp}`;useEffect(()=>{const listener=()=>{setShowTooltip(false);heap.triggeredByTouch=false;if(heap.timerId){clearTimeout(heap.timerId);heap.timerId=undefined;heap.triggeredByTouch=false;}};window.addEventListener("touchcancel",listener);window.addEventListener("touchend",listener);return()=>{window.removeEventListener("touchcancel",listener);window.removeEventListener("touchend",listener);};},[heap]);return/*#__PURE__*/_jsxs("div",{className:container,onClick:e=>{if(heap.timerId){clearTimeout(heap.timerId);setHeap({...heap,timerId:undefined,triggeredByTouch:false});}onClick?.(e);},onContextMenu:e=>{e.preventDefault();onContextMenu?.(e);},onMouseLeave:e=>{setShowTooltip(false);onMouseLeave?.(e);},onMouseMove:e=>{// NOTE: Because on touch devices mouse move events are still fired
25
25
  // after touch is released, to emulate mouse clicks for old websites.
26
26
  // If we don't ignore it here, the tooltip will appear after the touch
27
27
  // is released.
28
- if(!heap.ignoreMouseMove){updatePortalPosition(e.clientX,e.clientY);}onMouseMove?.(e);},onTouchStart:e=>{heap.ignoreMouseMove=true;heap.triggeredByTouch=true;// TODO: I guess, it should be something more complex here,
28
+ if(!heap.ignoreMouseMove){updatePortalPosition(e.clientX,e.clientY);}onMouseMove?.(e);},onTouchStart:e=>{setHeap({...heap,ignoreMouseMove:true,triggeredByTouch:true});// TODO: I guess, it should be something more complex here,
29
29
  // to actually respond to the first / whatever touch we need.
30
30
  const touch=e.targetTouches.item(0);updatePortalPosition(touch.clientX,touch.clientY);onTouchStart?.(e);},ref:node=>{wrapperRef.current=node;// eslint-disable-next-line no-param-reassign
31
31
  if(ref)ref.current=node;},role:"presentation",style:style// eslint-disable-next-line react/jsx-props-no-spreading
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useEffect","useEffectEvent","useRef","useState","useTheme","Tooltip","PLACEMENTS","defaultTheme","jsx","_jsx","jsxs","_jsxs","WithTooltip","children","className","classNameProp","onClick","onContextMenu","onMouseLeave","onMouseMove","onTouchStart","placement","ABOVE_CURSOR","ref","style","theme","tip","htmlAttributes","custom","current","heap","lastCursorX","lastCursorY","timerId","undefined","triggeredByTouch","tooltipRef","wrapperRef","showTooltip","setShowTooltip","getHeap","updatePortalPosition","cursorX","cursorY","wrapperRect","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","setTimeout","heap2","listener","addEventListener","removeEventListener","container","wrapper","clearTimeout","e","preventDefault","ignoreMouseMove","clientX","clientY","touch","targetTouches","item","node","role"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n useEffect,\n useEffectEvent,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n type ThemeKeysT as TooltipThemeKeysT,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = HTMLAttributes<HTMLDivElement> & {\n children?: ReactNode;\n placement?: PLACEMENTS;\n ref?: RefObject<HTMLDivElement | null>;\n theme?: Theme<'wrapper' | TooltipThemeKeysT>;\n tip?: ReactNode;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n ignoreMouseMove?: boolean;\n lastCursorX: number;\n lastCursorY: number;\n timerId?: NodeJS.Timeout;\n triggeredByTouch: boolean;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param tip &ndash; Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst WithTooltip: FunctionComponent<PropsT> = ({\n children,\n className: classNameProp,\n onClick,\n onContextMenu,\n onMouseLeave,\n onMouseMove,\n onTouchStart,\n placement = PLACEMENTS.ABOVE_CURSOR,\n ref,\n style,\n theme,\n tip,\n ...htmlAttributes\n}) => {\n const custom = useTheme('WithTooltip', defaultTheme, theme);\n\n const { current: heap } = useRef<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n timerId: undefined,\n triggeredByTouch: false,\n });\n const tooltipRef = useRef<TooltipRefT>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const getHeap = useEffectEvent(() => heap);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (showTooltip) {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n }\n } else {\n heap.lastCursorX = cursorX;\n heap.lastCursorY = cursorY;\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (heap.triggeredByTouch) {\n heap.timerId ??= setTimeout(() => {\n heap.triggeredByTouch = false;\n heap.timerId = undefined;\n setShowTooltip(true);\n }, 300);\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n }\n };\n\n useEffect(() => {\n const heap2 = getHeap();\n\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n heap2.lastCursorX + window.scrollX,\n heap2.lastCursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n }\n\n const listener = () => {\n setShowTooltip(false);\n };\n window.addEventListener('scroll', listener);\n return () => {\n window.removeEventListener('scroll', listener);\n };\n }\n return undefined;\n }, [\n placement,\n showTooltip,\n tip,\n ]);\n\n let container = custom.wrapper;\n if (classNameProp) container += ` ${classNameProp}`;\n\n useEffect(() => {\n const listener = () => {\n setShowTooltip(false);\n heap.triggeredByTouch = false;\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n };\n window.addEventListener('touchcancel', listener);\n window.addEventListener('touchend', listener);\n return () => {\n window.removeEventListener('touchcancel', listener);\n window.removeEventListener('touchend', listener);\n };\n }, []);\n\n return (\n <div\n className={container}\n onClick={(e) => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n onClick?.(e);\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n onContextMenu?.(e);\n }}\n onMouseLeave={(e) => {\n setShowTooltip(false);\n onMouseLeave?.(e);\n }}\n onMouseMove={(e) => {\n // NOTE: Because on touch devices mouse move events are still fired\n // after touch is released, to emulate mouse clicks for old websites.\n // If we don't ignore it here, the tooltip will appear after the touch\n // is released.\n if (!heap.ignoreMouseMove) {\n updatePortalPosition(e.clientX, e.clientY);\n }\n onMouseMove?.(e);\n }}\n onTouchStart={(e) => {\n heap.ignoreMouseMove = true;\n heap.triggeredByTouch = true;\n\n // TODO: I guess, it should be something more complex here,\n // to actually respond to the first / whatever touch we need.\n const touch = e.targetTouches.item(0);\n updatePortalPosition(touch.clientX, touch.clientY);\n\n onTouchStart?.(e);\n }}\n ref={(node) => {\n wrapperRef.current = node;\n\n // eslint-disable-next-line no-param-reassign\n if (ref) ref.current = node;\n }}\n role=\"presentation\"\n style={style}\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...htmlAttributes}\n >\n {\n showTooltip && tip !== null\n ? <Tooltip ref={tooltipRef} theme={custom}>{tip}</Tooltip>\n : null\n }\n {children}\n </div>\n );\n};\n\ntype ExportT = {\n PLACEMENTS: typeof PLACEMENTS;\n} & typeof WithTooltip;\n\nconst e: ExportT = WithTooltip as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":"AAAA,mBAEA,OAKEA,SAAS,CACTC,cAAc,CACdC,MAAM,CACNC,QAAQ,KACH,OAAO,CAEd,OAAqBC,QAAQ,KAAQ,0BAA0B,CAE/D,MAAO,CAAAC,OAAO,EACZC,UAAU,0BAAAC,YAAA,oIAIoC,OAAAC,GAAA,IAAAC,IAAA,CAAAC,IAAA,IAAAC,KAAA,yBA2BhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,KAAM,CAAAC,WAAsC,CAAGA,CAAC,CAC9CC,QAAQ,CACRC,SAAS,CAAEC,aAAa,CACxBC,OAAO,CACPC,aAAa,CACbC,YAAY,CACZC,WAAW,CACXC,YAAY,CACZC,SAAS,CAAGf,UAAU,CAACgB,YAAY,CACnCC,GAAG,CACHC,KAAK,CACLC,KAAK,CACLC,GAAG,CACH,GAAGC,cACL,CAAC,GAAK,CACJ,KAAM,CAAAC,MAAM,CAAGxB,QAAQ,CAA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AAC,CAAC,CAClB,CAAE,CACF1C,YAAY,CAAG0C,CAAC,EAAK,CACnBhC,IAAI,CAACkC,eAAe,CAAG,IAAI,CAC3BlC,IAAI,CAACK,gBAAgB,CAAG,IAAI,CAE5B;AACA;AACA,KAAM,CAAAgC,KAAK,CAAGL,CAAC,CAACM,aAAa,CAACC,IAAI,CAAC,CAAC,CAAC,CACrC5B,oBAAoB,CAAC0B,KAAK,CAACF,OAAO,CAAEE,KAAK,CAACD,OAAO,CAAC,CAElD9C,YAAY,GAAG0C,CAAC,CAAC,CACnB,CAAE,CACFvC,GAAG,CAAG+C,IAAI,EAAK,CACbjC,UAAU,CAACR,OAAO,CAAGyC,IAAI,CAEzB;AACA,GAAI/C,GAAG,CAAEA,GAAG,CAACM,OAAO,CAAGyC,IAAI,CAC7B,CAAE,CACFC,IAAI,CAAC,cAAc,CACnB/C,KAAK,CAAEA,KAEP;AAAA,IACIG,cAAc,CAAAd,QAAA,EAGhByB,WAAW,EAAIZ,GAAG,GAAK,IAAI,cACvBjB,IAAA,CAACJ,OAAO,EAACkB,GAAG,CAAEa,UAAW,CAACX,KAAK,CAAEG,MAAO,CAAAf,QAAA,CAAEa,GAAG,CAAU,CAAC,CACxD,IAAI,CAETb,QAAQ,EACN,CAAC,CAEV,CAAC,CAMD,KAAM,CAAAiD,CAAU,CAAGlD,WAAsB,CAEzCkD,CAAC,CAACxD,UAAU,CAAGA,UAAU,CAEzB,cAAe,CAAAwD,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useEffect","useRef","useState","useTheme","Tooltip","PLACEMENTS","defaultTheme","jsx","_jsx","jsxs","_jsxs","WithTooltip","children","className","classNameProp","onClick","onContextMenu","onMouseLeave","onMouseMove","onTouchStart","placement","ABOVE_CURSOR","ref","style","theme","tip","htmlAttributes","custom","heap","setHeap","lastCursorX","lastCursorY","timerId","undefined","triggeredByTouch","tooltipRef","wrapperRef","showTooltip","setShowTooltip","updatePortalPosition","cursorX","cursorY","wrapperRect","current","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","prev","res","setTimeout","p","listener","addEventListener","removeEventListener","container","wrapper","clearTimeout","e","preventDefault","ignoreMouseMove","clientX","clientY","touch","targetTouches","item","node","role"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n type ThemeKeysT as TooltipThemeKeysT,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = HTMLAttributes<HTMLDivElement> & {\n children?: ReactNode;\n placement?: PLACEMENTS;\n ref?: RefObject<HTMLDivElement | null>;\n theme?: Theme<'wrapper' | TooltipThemeKeysT>;\n tip?: ReactNode;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n ignoreMouseMove?: boolean;\n lastCursorX: number;\n lastCursorY: number;\n timerId?: NodeJS.Timeout;\n triggeredByTouch: boolean;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param tip &ndash; Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst WithTooltip: FunctionComponent<PropsT> = ({\n children,\n className: classNameProp,\n onClick,\n onContextMenu,\n onMouseLeave,\n onMouseMove,\n onTouchStart,\n placement = PLACEMENTS.ABOVE_CURSOR,\n ref,\n style,\n theme,\n tip,\n ...htmlAttributes\n}) => {\n const custom = useTheme('WithTooltip', defaultTheme, theme);\n\n const [heap, setHeap] = useState<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n timerId: undefined,\n triggeredByTouch: false,\n });\n\n const tooltipRef = useRef<TooltipRefT>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (showTooltip) {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n }\n } else {\n setHeap((prev) => {\n const res: HeapT = {\n ...prev,\n lastCursorX: cursorX,\n lastCursorY: cursorY,\n };\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (res.triggeredByTouch) {\n res.timerId ??= setTimeout(() => {\n setHeap((p) => ({\n ...p,\n timerId: undefined,\n triggeredByTouch: false,\n }));\n\n setShowTooltip(true);\n }, 300);\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n\n return res;\n });\n }\n };\n\n useEffect(() => {\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n setHeap((prev) => {\n tooltipRef.current?.pointTo(\n prev.lastCursorX + window.scrollX,\n prev.lastCursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n return prev;\n });\n }\n\n const listener = () => {\n setShowTooltip(false);\n };\n window.addEventListener('scroll', listener);\n return () => {\n window.removeEventListener('scroll', listener);\n };\n }\n return undefined;\n }, [\n placement,\n showTooltip,\n tip,\n ]);\n\n let container = custom.wrapper;\n if (classNameProp) container += ` ${classNameProp}`;\n\n useEffect(() => {\n const listener = () => {\n setShowTooltip(false);\n heap.triggeredByTouch = false;\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n };\n window.addEventListener('touchcancel', listener);\n window.addEventListener('touchend', listener);\n return () => {\n window.removeEventListener('touchcancel', listener);\n window.removeEventListener('touchend', listener);\n };\n }, [heap]);\n\n return (\n <div\n className={container}\n onClick={(e) => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n\n setHeap({\n ...heap,\n timerId: undefined,\n triggeredByTouch: false,\n });\n }\n onClick?.(e);\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n onContextMenu?.(e);\n }}\n onMouseLeave={(e) => {\n setShowTooltip(false);\n onMouseLeave?.(e);\n }}\n onMouseMove={(e) => {\n // NOTE: Because on touch devices mouse move events are still fired\n // after touch is released, to emulate mouse clicks for old websites.\n // If we don't ignore it here, the tooltip will appear after the touch\n // is released.\n if (!heap.ignoreMouseMove) {\n updatePortalPosition(e.clientX, e.clientY);\n }\n onMouseMove?.(e);\n }}\n onTouchStart={(e) => {\n setHeap({\n ...heap,\n ignoreMouseMove: true,\n triggeredByTouch: true,\n });\n\n // TODO: I guess, it should be something more complex here,\n // to actually respond to the first / whatever touch we need.\n const touch = e.targetTouches.item(0);\n updatePortalPosition(touch.clientX, touch.clientY);\n\n onTouchStart?.(e);\n }}\n ref={(node) => {\n wrapperRef.current = node;\n\n // eslint-disable-next-line no-param-reassign\n if (ref) ref.current = node;\n }}\n role=\"presentation\"\n style={style}\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...htmlAttributes}\n >\n {\n showTooltip && tip !== null\n ? <Tooltip ref={tooltipRef} theme={custom}>{tip}</Tooltip>\n : null\n }\n {children}\n </div>\n );\n};\n\ntype ExportT = {\n PLACEMENTS: typeof PLACEMENTS;\n} & typeof WithTooltip;\n\nconst e: ExportT = WithTooltip as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":"AAAA,mBAEA,OAKEA,SAAS,CACTC,MAAM,CACNC,QAAQ,KACH,OAAO,CAEd,OAAqBC,QAAQ,KAAQ,0BAA0B,CAE/D,MAAO,CAAAC,OAAO,EACZC,UAAU,0BAAAC,YAAA,oIAIoC,OAAAC,GAAA,IAAAC,IAAA,CAAAC,IAAA,IAAAC,KAAA,yBA2BhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,KAAM,CAAAC,WAAsC,CAAGA,CAAC,CAC9CC,QAAQ,CACRC,SAAS,CAAEC,aAAa,CACxBC,OAAO,CACPC,aAAa,CACbC,YAAY,CACZC,WAAW,CACXC,YAAY,CACZC,SAAS,CAAGf,UAAU,CAACgB,YAAY,CACnCC,GAAG,CACHC,KAAK,CACLC,KAAK,CACLC,GAAG,CACH,GAAGC,cACL,CAAC,GAAK,CACJ,KAAM,CAAAC,MAAM,CAAGxB,QAAQ,CAAC,aAAa,CAAEG,YAAY,CAAEkB,KAAK,CAAC,CAE3D,KAAM,CAACI,IAAI,CAAEC,OAAO,CAAC,CAAG3B,QAAQ,CAAQ,CACtC4B,WAAW,CAAE,CAAC,CACdC,WAAW,CAAE,CAAC,CACdC,OAAO,CAAEC,SAAS,CAClBC,gBAAgB,CAAE,KACpB,CAAC,CAAC,CAEF,KAAM,CAAAC,UAAU,CAAGlC,MAAM,CAAc,IAAI,CAAC,CAC5C,KAAM,CAAAmC,UAAU,CAAGnC,MAAM,CAAiB,IAAI,CAAC,CAC/C,KAAM,CAACoC,WAAW,CAAEC,cAAc,CAAC,CAAGpC,QAAQ,CAAC,KAAK,CAAC,CAErD,KAAM,CAAAqC,oBAAoB,CAAGA,CAACC,OA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,CAAC,CAElDhD,YAAY,GAAG4C,CAAC,CAAC,CACnB,CAAE,CACFzC,GAAG,CAAGiD,IAAI,EAAK,CACbnC,UAAU,CAACO,OAAO,CAAG4B,IAAI,CAEzB;AACA,GAAIjD,GAAG,CAAEA,GAAG,CAACqB,OAAO,CAAG4B,IAAI,CAC7B,CAAE,CACFC,IAAI,CAAC,cAAc,CACnBjD,KAAK,CAAEA,KAEP;AAAA,IACIG,cAAc,CAAAd,QAAA,EAGhByB,WAAW,EAAIZ,GAAG,GAAK,IAAI,cACvBjB,IAAA,CAACJ,OAAO,EAACkB,GAAG,CAAEa,UAAW,CAACX,KAAK,CAAEG,MAAO,CAAAf,QAAA,CAAEa,GAAG,CAAU,CAAC,CACxD,IAAI,CAETb,QAAQ,EACN,CAAC,CAEV,CAAC,CAMD,KAAM,CAAAmD,CAAU,CAAGpD,WAAsB,CAEzCoD,CAAC,CAAC1D,UAAU,CAAGA,UAAU,CAEzB,cAAe,CAAA0D,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- /* global window */import{useEffect,useEffectEvent,useRef,useState}from"react";import{useTheme}from"@dr.pogodin/react-themes";import Tooltip,{PLACEMENTS}from"./Tooltip";import defaultTheme from"./default-theme.scss";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";/**
1
+ /* global window */import{useEffect,useRef,useState}from"react";import{useTheme}from"@dr.pogodin/react-themes";import Tooltip,{PLACEMENTS}from"./Tooltip";import defaultTheme from"./default-theme.scss";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";/**
2
2
  * Implements a simple to use and themeable tooltip component, _e.g._
3
3
  * ```js
4
4
  * <WithTooltip tip="This is example tooltip.">
@@ -11,21 +11,21 @@
11
11
  * @param tip &ndash; Anything React is able to render,
12
12
  * _e.g._ a tooltip text. This will be the tooltip content.
13
13
  * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.
14
- */const WithTooltip=({children,className:classNameProp,onClick,onContextMenu,onMouseLeave,onMouseMove,onTouchStart,placement=PLACEMENTS.ABOVE_CURSOR,ref,style,theme,tip,...htmlAttributes})=>{const custom=useTheme("WithTooltip",defaultTheme,theme);const{current:heap}=useRef({lastCursorX:0,lastCursorY:0,timerId:undefined,triggeredByTouch:false});const tooltipRef=useRef(null);const wrapperRef=useRef(null);const[showTooltip,setShowTooltip]=useState(false);const getHeap=useEffectEvent(()=>heap);const updatePortalPosition=(cursorX,cursorY)=>{if(showTooltip){const wrapperRect=wrapperRef.current.getBoundingClientRect();if(cursorX<wrapperRect.left||cursorX>wrapperRect.right||cursorY<wrapperRect.top||cursorY>wrapperRect.bottom){setShowTooltip(false);}else if(tooltipRef.current){tooltipRef.current.pointTo(cursorX+window.scrollX,cursorY+window.scrollY,placement,wrapperRef.current);}}else{heap.lastCursorX=cursorX;heap.lastCursorY=cursorY;// If tooltip was triggered by a touch, we delay its opening by a bit,
14
+ */const WithTooltip=({children,className:classNameProp,onClick,onContextMenu,onMouseLeave,onMouseMove,onTouchStart,placement=PLACEMENTS.ABOVE_CURSOR,ref,style,theme,tip,...htmlAttributes})=>{const custom=useTheme("WithTooltip",defaultTheme,theme);const[heap,setHeap]=useState({lastCursorX:0,lastCursorY:0,timerId:undefined,triggeredByTouch:false});const tooltipRef=useRef(null);const wrapperRef=useRef(null);const[showTooltip,setShowTooltip]=useState(false);const updatePortalPosition=(cursorX,cursorY)=>{if(showTooltip){const wrapperRect=wrapperRef.current.getBoundingClientRect();if(cursorX<wrapperRect.left||cursorX>wrapperRect.right||cursorY<wrapperRect.top||cursorY>wrapperRect.bottom){setShowTooltip(false);}else if(tooltipRef.current){tooltipRef.current.pointTo(cursorX+window.scrollX,cursorY+window.scrollY,placement,wrapperRef.current);}}else{setHeap(prev=>{const res={...prev,lastCursorX:cursorX,lastCursorY:cursorY};// If tooltip was triggered by a touch, we delay its opening by a bit,
15
15
  // to ensure it was not a touch-click - in the case of touch click we
16
16
  // want to do the click, rather than show the tooltip, and the delay
17
17
  // gives click handler a chance to abort the tooltip openning.
18
- if(heap.triggeredByTouch){heap.timerId??=setTimeout(()=>{heap.triggeredByTouch=false;heap.timerId=undefined;setShowTooltip(true);},300);// Otherwise we can just open the tooltip right away.
19
- }else setShowTooltip(true);}};useEffect(()=>{const heap2=getHeap();if(showTooltip&&tip!==null){// This is necessary to ensure that even when a single mouse event
18
+ if(res.triggeredByTouch){res.timerId??=setTimeout(()=>{setHeap(p=>({...p,timerId:undefined,triggeredByTouch:false}));setShowTooltip(true);},300);// Otherwise we can just open the tooltip right away.
19
+ }else setShowTooltip(true);return res;});}};useEffect(()=>{if(showTooltip&&tip!==null){// This is necessary to ensure that even when a single mouse event
20
20
  // arrives to a tool-tipped component, the tooltip is correctly positioned
21
21
  // once opened (because similar call above does not have effect until
22
22
  // the tooltip is fully mounted, and that is delayed to future rendering
23
23
  // cycle due to the implementation).
24
- if(tooltipRef.current){tooltipRef.current.pointTo(heap2.lastCursorX+window.scrollX,heap2.lastCursorY+window.scrollY,placement,wrapperRef.current);}const listener=()=>{setShowTooltip(false);};window.addEventListener("scroll",listener);return()=>{window.removeEventListener("scroll",listener);};}return undefined;},[placement,showTooltip,tip]);let container=custom.wrapper;if(classNameProp)container+=` ${classNameProp}`;useEffect(()=>{const listener=()=>{setShowTooltip(false);heap.triggeredByTouch=false;if(heap.timerId){clearTimeout(heap.timerId);heap.timerId=undefined;heap.triggeredByTouch=false;}};window.addEventListener("touchcancel",listener);window.addEventListener("touchend",listener);return()=>{window.removeEventListener("touchcancel",listener);window.removeEventListener("touchend",listener);};},[]);return/*#__PURE__*/_jsxs("div",{className:container,onClick:e=>{if(heap.timerId){clearTimeout(heap.timerId);heap.timerId=undefined;heap.triggeredByTouch=false;}onClick?.(e);},onContextMenu:e=>{e.preventDefault();onContextMenu?.(e);},onMouseLeave:e=>{setShowTooltip(false);onMouseLeave?.(e);},onMouseMove:e=>{// NOTE: Because on touch devices mouse move events are still fired
24
+ if(tooltipRef.current){setHeap(prev=>{tooltipRef.current?.pointTo(prev.lastCursorX+window.scrollX,prev.lastCursorY+window.scrollY,placement,wrapperRef.current);return prev;});}const listener=()=>{setShowTooltip(false);};window.addEventListener("scroll",listener);return()=>{window.removeEventListener("scroll",listener);};}return undefined;},[placement,showTooltip,tip]);let container=custom.wrapper;if(classNameProp)container+=` ${classNameProp}`;useEffect(()=>{const listener=()=>{setShowTooltip(false);heap.triggeredByTouch=false;if(heap.timerId){clearTimeout(heap.timerId);heap.timerId=undefined;heap.triggeredByTouch=false;}};window.addEventListener("touchcancel",listener);window.addEventListener("touchend",listener);return()=>{window.removeEventListener("touchcancel",listener);window.removeEventListener("touchend",listener);};},[heap]);return/*#__PURE__*/_jsxs("div",{className:container,onClick:e=>{if(heap.timerId){clearTimeout(heap.timerId);setHeap({...heap,timerId:undefined,triggeredByTouch:false});}onClick?.(e);},onContextMenu:e=>{e.preventDefault();onContextMenu?.(e);},onMouseLeave:e=>{setShowTooltip(false);onMouseLeave?.(e);},onMouseMove:e=>{// NOTE: Because on touch devices mouse move events are still fired
25
25
  // after touch is released, to emulate mouse clicks for old websites.
26
26
  // If we don't ignore it here, the tooltip will appear after the touch
27
27
  // is released.
28
- if(!heap.ignoreMouseMove){updatePortalPosition(e.clientX,e.clientY);}onMouseMove?.(e);},onTouchStart:e=>{heap.ignoreMouseMove=true;heap.triggeredByTouch=true;// TODO: I guess, it should be something more complex here,
28
+ if(!heap.ignoreMouseMove){updatePortalPosition(e.clientX,e.clientY);}onMouseMove?.(e);},onTouchStart:e=>{setHeap({...heap,ignoreMouseMove:true,triggeredByTouch:true});// TODO: I guess, it should be something more complex here,
29
29
  // to actually respond to the first / whatever touch we need.
30
30
  const touch=e.targetTouches.item(0);updatePortalPosition(touch.clientX,touch.clientY);onTouchStart?.(e);},ref:node=>{wrapperRef.current=node;// eslint-disable-next-line no-param-reassign
31
31
  if(ref)ref.current=node;},role:"presentation",style:style// eslint-disable-next-line react/jsx-props-no-spreading
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useEffect","useEffectEvent","useRef","useState","useTheme","Tooltip","PLACEMENTS","defaultTheme","jsx","_jsx","jsxs","_jsxs","WithTooltip","children","className","classNameProp","onClick","onContextMenu","onMouseLeave","onMouseMove","onTouchStart","placement","ABOVE_CURSOR","ref","style","theme","tip","htmlAttributes","custom","current","heap","lastCursorX","lastCursorY","timerId","undefined","triggeredByTouch","tooltipRef","wrapperRef","showTooltip","setShowTooltip","getHeap","updatePortalPosition","cursorX","cursorY","wrapperRect","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","setTimeout","heap2","listener","addEventListener","removeEventListener","container","wrapper","clearTimeout","e","preventDefault","ignoreMouseMove","clientX","clientY","touch","targetTouches","item","node","role"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n useEffect,\n useEffectEvent,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n type ThemeKeysT as TooltipThemeKeysT,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = HTMLAttributes<HTMLDivElement> & {\n children?: ReactNode;\n placement?: PLACEMENTS;\n ref?: RefObject<HTMLDivElement | null>;\n theme?: Theme<'wrapper' | TooltipThemeKeysT>;\n tip?: ReactNode;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n ignoreMouseMove?: boolean;\n lastCursorX: number;\n lastCursorY: number;\n timerId?: NodeJS.Timeout;\n triggeredByTouch: boolean;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param tip &ndash; Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst WithTooltip: FunctionComponent<PropsT> = ({\n children,\n className: classNameProp,\n onClick,\n onContextMenu,\n onMouseLeave,\n onMouseMove,\n onTouchStart,\n placement = PLACEMENTS.ABOVE_CURSOR,\n ref,\n style,\n theme,\n tip,\n ...htmlAttributes\n}) => {\n const custom = useTheme('WithTooltip', defaultTheme, theme);\n\n const { current: heap } = useRef<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n timerId: undefined,\n triggeredByTouch: false,\n });\n const tooltipRef = useRef<TooltipRefT>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const getHeap = useEffectEvent(() => heap);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (showTooltip) {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n }\n } else {\n heap.lastCursorX = cursorX;\n heap.lastCursorY = cursorY;\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (heap.triggeredByTouch) {\n heap.timerId ??= setTimeout(() => {\n heap.triggeredByTouch = false;\n heap.timerId = undefined;\n setShowTooltip(true);\n }, 300);\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n }\n };\n\n useEffect(() => {\n const heap2 = getHeap();\n\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n heap2.lastCursorX + window.scrollX,\n heap2.lastCursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n }\n\n const listener = () => {\n setShowTooltip(false);\n };\n window.addEventListener('scroll', listener);\n return () => {\n window.removeEventListener('scroll', listener);\n };\n }\n return undefined;\n }, [\n placement,\n showTooltip,\n tip,\n ]);\n\n let container = custom.wrapper;\n if (classNameProp) container += ` ${classNameProp}`;\n\n useEffect(() => {\n const listener = () => {\n setShowTooltip(false);\n heap.triggeredByTouch = false;\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n };\n window.addEventListener('touchcancel', listener);\n window.addEventListener('touchend', listener);\n return () => {\n window.removeEventListener('touchcancel', listener);\n window.removeEventListener('touchend', listener);\n };\n }, []);\n\n return (\n <div\n className={container}\n onClick={(e) => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n onClick?.(e);\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n onContextMenu?.(e);\n }}\n onMouseLeave={(e) => {\n setShowTooltip(false);\n onMouseLeave?.(e);\n }}\n onMouseMove={(e) => {\n // NOTE: Because on touch devices mouse move events are still fired\n // after touch is released, to emulate mouse clicks for old websites.\n // If we don't ignore it here, the tooltip will appear after the touch\n // is released.\n if (!heap.ignoreMouseMove) {\n updatePortalPosition(e.clientX, e.clientY);\n }\n onMouseMove?.(e);\n }}\n onTouchStart={(e) => {\n heap.ignoreMouseMove = true;\n heap.triggeredByTouch = true;\n\n // TODO: I guess, it should be something more complex here,\n // to actually respond to the first / whatever touch we need.\n const touch = e.targetTouches.item(0);\n updatePortalPosition(touch.clientX, touch.clientY);\n\n onTouchStart?.(e);\n }}\n ref={(node) => {\n wrapperRef.current = node;\n\n // eslint-disable-next-line no-param-reassign\n if (ref) ref.current = node;\n }}\n role=\"presentation\"\n style={style}\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...htmlAttributes}\n >\n {\n showTooltip && tip !== null\n ? <Tooltip ref={tooltipRef} theme={custom}>{tip}</Tooltip>\n : null\n }\n {children}\n </div>\n );\n};\n\ntype ExportT = {\n PLACEMENTS: typeof PLACEMENTS;\n} & typeof WithTooltip;\n\nconst e: ExportT = WithTooltip as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":"AAAA,mBAEA,OAKEA,SAAS,CACTC,cAAc,CACdC,MAAM,CACNC,QAAQ,KACH,OAAO,CAEd,OAAqBC,QAAQ,KAAQ,0BAA0B,CAE/D,MAAO,CAAAC,OAAO,EACZC,UAAU,iBAIZ,MAAO,CAAAC,YAAY,4BAA6B,OAAAC,GAAA,IAAAC,IAAA,CAAAC,IAAA,IAAAC,KAAA,yBA2BhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,KAAM,CAAAC,WAAsC,CAAGA,CAAC,CAC9CC,QAAQ,CACRC,SAAS,CAAEC,aAAa,CACxBC,OAAO,CACPC,aAAa,CACbC,YAAY,CACZC,WAAW,CACXC,YAAY,CACZC,SAAS,CAAGf,UAAU,CAACgB,YAAY,CACnCC,GAAG,CACHC,KAAK,CACLC,KAAK,CACLC,GAAG,CACH,GAAGC,cACL,CAAC,GAAK,CACJ,KAAM,CAAAC,MAAM,CAAGxB,QAAQ,CAAC,aAAa,CAAEG,YAAY,CAAEkB,KAAK,CAAC,CAE3D,KAAM,CAAEI,OAAO,CAAEC,IAAK,CAAC,CAAG5B,MAAM,CAAQ,CACtC6B,WAAW,CAAE,CAAC,CACdC,WAAW,CAAE,CAAC,CACdC,OAAO,CAAEC,SAAS,CAClBC,gBAAgB,CAAE,KACpB,CAAC,CAAC,CACF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C,CACrC5B,oBAAoB,CAAC0B,KAAK,CAACF,OAAO,CAAEE,KAAK,CAACD,OAAO,CAAC,CAElD9C,YAAY,GAAG0C,CAAC,CAAC,CACnB,CAAE,CACFvC,GAAG,CAAG+C,IAAI,EAAK,CACbjC,UAAU,CAACR,OAAO,CAAGyC,IAAI,CAEzB;AACA,GAAI/C,GAAG,CAAEA,GAAG,CAACM,OAAO,CAAGyC,IAAI,CAC7B,CAAE,CACFC,IAAI,CAAC,cAAc,CACnB/C,KAAK,CAAEA,KAEP;AAAA,IACIG,cAAc,CAAAd,QAAA,EAGhByB,WAAW,EAAIZ,GAAG,GAAK,IAAI,cACvBjB,IAAA,CAACJ,OAAO,EAACkB,GAAG,CAAEa,UAAW,CAACX,KAAK,CAAEG,MAAO,CAAAf,QAAA,CAAEa,GAAG,CAAU,CAAC,CACxD,IAAI,CAETb,QAAQ,EACN,CAAC,CAEV,CAAC,CAMD,KAAM,CAAAiD,CAAU,CAAGlD,WAAsB,CAEzCkD,CAAC,CAACxD,UAAU,CAAGA,UAAU,CAEzB,cAAe,CAAAwD,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useEffect","useRef","useState","useTheme","Tooltip","PLACEMENTS","defaultTheme","jsx","_jsx","jsxs","_jsxs","WithTooltip","children","className","classNameProp","onClick","onContextMenu","onMouseLeave","onMouseMove","onTouchStart","placement","ABOVE_CURSOR","ref","style","theme","tip","htmlAttributes","custom","heap","setHeap","lastCursorX","lastCursorY","timerId","undefined","triggeredByTouch","tooltipRef","wrapperRef","showTooltip","setShowTooltip","updatePortalPosition","cursorX","cursorY","wrapperRect","current","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","prev","res","setTimeout","p","listener","addEventListener","removeEventListener","container","wrapper","clearTimeout","e","preventDefault","ignoreMouseMove","clientX","clientY","touch","targetTouches","item","node","role"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Tooltip, {\n PLACEMENTS,\n type ThemeKeysT as TooltipThemeKeysT,\n} from './Tooltip';\n\nimport defaultTheme from './default-theme.scss';\n\ntype PropsT = HTMLAttributes<HTMLDivElement> & {\n children?: ReactNode;\n placement?: PLACEMENTS;\n ref?: RefObject<HTMLDivElement | null>;\n theme?: Theme<'wrapper' | TooltipThemeKeysT>;\n tip?: ReactNode;\n};\n\ntype TooltipRefT = {\n pointTo: (\n x: number,\n y: number,\n placement: PLACEMENTS,\n wrapperRef: HTMLDivElement,\n ) => void;\n};\n\ntype HeapT = {\n ignoreMouseMove?: boolean;\n lastCursorX: number;\n lastCursorY: number;\n timerId?: NodeJS.Timeout;\n triggeredByTouch: boolean;\n};\n\n/**\n * Implements a simple to use and themeable tooltip component, _e.g._\n * ```js\n * <WithTooltip tip=\"This is example tooltip.\">\n * <p>Hover to see the tooltip.</p>\n * </WithTooltip>\n * ```\n * **Children:** Children are rendered in the place of `<WithTooltip>`,\n * and when hovered the tooltip is shown. By default the wrapper itself is\n * `<div>` block with `display: inline-block`.\n * @param tip &ndash; Anything React is able to render,\n * _e.g._ a tooltip text. This will be the tooltip content.\n * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.\n */\nconst WithTooltip: FunctionComponent<PropsT> = ({\n children,\n className: classNameProp,\n onClick,\n onContextMenu,\n onMouseLeave,\n onMouseMove,\n onTouchStart,\n placement = PLACEMENTS.ABOVE_CURSOR,\n ref,\n style,\n theme,\n tip,\n ...htmlAttributes\n}) => {\n const custom = useTheme('WithTooltip', defaultTheme, theme);\n\n const [heap, setHeap] = useState<HeapT>({\n lastCursorX: 0,\n lastCursorY: 0,\n timerId: undefined,\n triggeredByTouch: false,\n });\n\n const tooltipRef = useRef<TooltipRefT>(null);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const [showTooltip, setShowTooltip] = useState(false);\n\n const updatePortalPosition = (cursorX: number, cursorY: number) => {\n if (showTooltip) {\n const wrapperRect = wrapperRef.current!.getBoundingClientRect();\n if (\n cursorX < wrapperRect.left\n || cursorX > wrapperRect.right\n || cursorY < wrapperRect.top\n || cursorY > wrapperRect.bottom\n ) {\n setShowTooltip(false);\n } else if (tooltipRef.current) {\n tooltipRef.current.pointTo(\n cursorX + window.scrollX,\n cursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n }\n } else {\n setHeap((prev) => {\n const res: HeapT = {\n ...prev,\n lastCursorX: cursorX,\n lastCursorY: cursorY,\n };\n\n // If tooltip was triggered by a touch, we delay its opening by a bit,\n // to ensure it was not a touch-click - in the case of touch click we\n // want to do the click, rather than show the tooltip, and the delay\n // gives click handler a chance to abort the tooltip openning.\n if (res.triggeredByTouch) {\n res.timerId ??= setTimeout(() => {\n setHeap((p) => ({\n ...p,\n timerId: undefined,\n triggeredByTouch: false,\n }));\n\n setShowTooltip(true);\n }, 300);\n\n // Otherwise we can just open the tooltip right away.\n } else setShowTooltip(true);\n\n return res;\n });\n }\n };\n\n useEffect(() => {\n if (showTooltip && tip !== null) {\n // This is necessary to ensure that even when a single mouse event\n // arrives to a tool-tipped component, the tooltip is correctly positioned\n // once opened (because similar call above does not have effect until\n // the tooltip is fully mounted, and that is delayed to future rendering\n // cycle due to the implementation).\n if (tooltipRef.current) {\n setHeap((prev) => {\n tooltipRef.current?.pointTo(\n prev.lastCursorX + window.scrollX,\n prev.lastCursorY + window.scrollY,\n placement,\n wrapperRef.current!,\n );\n return prev;\n });\n }\n\n const listener = () => {\n setShowTooltip(false);\n };\n window.addEventListener('scroll', listener);\n return () => {\n window.removeEventListener('scroll', listener);\n };\n }\n return undefined;\n }, [\n placement,\n showTooltip,\n tip,\n ]);\n\n let container = custom.wrapper;\n if (classNameProp) container += ` ${classNameProp}`;\n\n useEffect(() => {\n const listener = () => {\n setShowTooltip(false);\n heap.triggeredByTouch = false;\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n };\n window.addEventListener('touchcancel', listener);\n window.addEventListener('touchend', listener);\n return () => {\n window.removeEventListener('touchcancel', listener);\n window.removeEventListener('touchend', listener);\n };\n }, [heap]);\n\n return (\n <div\n className={container}\n onClick={(e) => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n\n setHeap({\n ...heap,\n timerId: undefined,\n triggeredByTouch: false,\n });\n }\n onClick?.(e);\n }}\n onContextMenu={(e) => {\n e.preventDefault();\n onContextMenu?.(e);\n }}\n onMouseLeave={(e) => {\n setShowTooltip(false);\n onMouseLeave?.(e);\n }}\n onMouseMove={(e) => {\n // NOTE: Because on touch devices mouse move events are still fired\n // after touch is released, to emulate mouse clicks for old websites.\n // If we don't ignore it here, the tooltip will appear after the touch\n // is released.\n if (!heap.ignoreMouseMove) {\n updatePortalPosition(e.clientX, e.clientY);\n }\n onMouseMove?.(e);\n }}\n onTouchStart={(e) => {\n setHeap({\n ...heap,\n ignoreMouseMove: true,\n triggeredByTouch: true,\n });\n\n // TODO: I guess, it should be something more complex here,\n // to actually respond to the first / whatever touch we need.\n const touch = e.targetTouches.item(0);\n updatePortalPosition(touch.clientX, touch.clientY);\n\n onTouchStart?.(e);\n }}\n ref={(node) => {\n wrapperRef.current = node;\n\n // eslint-disable-next-line no-param-reassign\n if (ref) ref.current = node;\n }}\n role=\"presentation\"\n style={style}\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...htmlAttributes}\n >\n {\n showTooltip && tip !== null\n ? <Tooltip ref={tooltipRef} theme={custom}>{tip}</Tooltip>\n : null\n }\n {children}\n </div>\n );\n};\n\ntype ExportT = {\n PLACEMENTS: typeof PLACEMENTS;\n} & typeof WithTooltip;\n\nconst e: ExportT = WithTooltip as ExportT;\n\ne.PLACEMENTS = PLACEMENTS;\n\nexport default e;\n"],"mappings":"AAAA,mBAEA,OAKEA,SAAS,CACTC,MAAM,CACNC,QAAQ,K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AAI,CAAC,cAAc,CACnBjD,KAAK,CAAEA,KAEP;AAAA,IACIG,cAAc,CAAAd,QAAA,EAGhByB,WAAW,EAAIZ,GAAG,GAAK,IAAI,cACvBjB,IAAA,CAACJ,OAAO,EAACkB,GAAG,CAAEa,UAAW,CAACX,KAAK,CAAEG,MAAO,CAAAf,QAAA,CAAEa,GAAG,CAAU,CAAC,CACxD,IAAI,CAETb,QAAQ,EACN,CAAC,CAEV,CAAC,CAMD,KAAM,CAAAmD,CAAU,CAAGpD,WAAsB,CAEzCoD,CAAC,CAAC1D,UAAU,CAAGA,UAAU,CAEzB,cAAe,CAAA0D,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.52.7",
2
+ "version": "1.52.9",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -8,14 +8,14 @@
8
8
  "url": "https://github.com/birdofpreyru/react-utils/issues"
9
9
  },
10
10
  "dependencies": {
11
- "@babel/runtime": "^7.29.2",
11
+ "@babel/runtime": "^7.29.7",
12
12
  "@commander-js/extra-typings": "^14.0.0",
13
13
  "@dr.pogodin/babel-plugin-react-css-modules": "^6.13.9",
14
14
  "@dr.pogodin/csurf": "^1.16.9",
15
15
  "@dr.pogodin/js-utils": "^0.1.8",
16
16
  "@dr.pogodin/react-global-state": "^0.23.0",
17
17
  "@dr.pogodin/react-helmet": "^3.2.2",
18
- "@dr.pogodin/react-themes": "^1.10.3",
18
+ "@dr.pogodin/react-themes": "^1.10.4",
19
19
  "@jest/environment": "^30.4.1",
20
20
  "axios": "^1.16.1",
21
21
  "commander": "^14.0.3",
@@ -25,9 +25,9 @@
25
25
  "cookie-parser": "^1.4.7",
26
26
  "core-js": "^3.49.0",
27
27
  "cross-env": "^10.1.0",
28
- "dayjs": "^1.11.20",
28
+ "dayjs": "^1.11.21",
29
29
  "express": "^5.2.1",
30
- "helmet": "^8.1.0",
30
+ "helmet": "^8.2.0",
31
31
  "http-status-codes": "^2.3.0",
32
32
  "lodash-es": "^4.18.1",
33
33
  "morgan": "^1.10.1",
@@ -45,17 +45,17 @@
45
45
  },
46
46
  "description": "Collection of generic ReactJS components and utils",
47
47
  "devDependencies": {
48
- "@babel/cli": "^7.28.6",
49
- "@babel/core": "^7.29.0",
50
- "@babel/node": "^7.29.0",
51
- "@babel/plugin-transform-runtime": "^7.29.0",
52
- "@babel/preset-env": "^7.29.5",
53
- "@babel/preset-react": "^7.28.5",
54
- "@babel/preset-typescript": "^7.28.5",
55
- "@babel/register": "^7.29.3",
48
+ "@babel/cli": "^7.29.7",
49
+ "@babel/core": "^7.29.7",
50
+ "@babel/node": "^7.29.7",
51
+ "@babel/plugin-transform-runtime": "^7.29.7",
52
+ "@babel/preset-env": "^7.29.7",
53
+ "@babel/preset-react": "^7.29.7",
54
+ "@babel/preset-typescript": "^7.29.7",
55
+ "@babel/register": "^7.29.7",
56
56
  "@dr.pogodin/babel-plugin-transform-assets": "^1.2.6",
57
57
  "@dr.pogodin/babel-preset-svgr": "^1.9.3",
58
- "@dr.pogodin/eslint-configs": "^0.2.13",
58
+ "@dr.pogodin/eslint-configs": "^0.2.14",
59
59
  "@pmmmwh/react-refresh-webpack-plugin": "^0.6.2",
60
60
  "@standard-schema/spec": "^1.1.0",
61
61
  "@testing-library/dom": "^10.4.1",
@@ -102,7 +102,7 @@
102
102
  "pretty": "^2.0.0",
103
103
  "react-refresh": "^0.18.0",
104
104
  "resolve-url-loader": "^5.0.0",
105
- "sass": "^1.99.0",
105
+ "sass": "^1.100.0",
106
106
  "sass-loader": "^17.0.0",
107
107
  "sitemap": "^9.0.1",
108
108
  "source-map-loader": "^5.0.0",
@@ -110,10 +110,10 @@
110
110
  "stylelint-config-standard-scss": "^17.0.0",
111
111
  "supertest": "^7.2.2",
112
112
  "tsc-alias": "1.8.17",
113
- "tstyche": "^7.1.0",
113
+ "tstyche": "^7.2.1",
114
114
  "typed-scss-modules": "^8.1.1",
115
115
  "typescript": "^5.9.3",
116
- "webpack": "^5.107.1",
116
+ "webpack": "^5.107.2",
117
117
  "webpack-dev-middleware": "^8.0.3",
118
118
  "webpack-hot-middleware": "^2.26.1",
119
119
  "webpack-merge": "^6.0.1",