@dr.pogodin/react-utils 1.49.1 → 1.50.1

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 (210) hide show
  1. package/babel.scripts.config.js +19 -0
  2. package/bin/build.js +274 -164
  3. package/build/development/client/getInj.js +18 -29
  4. package/build/development/client/getInj.js.map +1 -1
  5. package/build/development/client/index.js +11 -14
  6. package/build/development/client/index.js.map +1 -1
  7. package/build/development/client/init.js +9 -17
  8. package/build/development/client/init.js.map +1 -1
  9. package/build/development/index.js +26 -4
  10. package/build/development/index.js.map +1 -1
  11. package/build/development/server/Cache.js +15 -20
  12. package/build/development/server/Cache.js.map +1 -1
  13. package/build/development/server/index.js +142 -160
  14. package/build/development/server/index.js.map +1 -1
  15. package/build/development/server/renderer.js +150 -197
  16. package/build/development/server/renderer.js.map +1 -1
  17. package/build/development/server/server.js +63 -86
  18. package/build/development/server/server.js.map +1 -1
  19. package/build/development/server/utils/errors.js +72 -87
  20. package/build/development/server/utils/errors.js.map +1 -1
  21. package/build/development/shared/components/Button/index.js +8 -17
  22. package/build/development/shared/components/Button/index.js.map +1 -1
  23. package/build/development/shared/components/Checkbox/index.js +4 -4
  24. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  25. package/build/development/shared/components/GenericLink/index.js +54 -58
  26. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  27. package/build/development/shared/components/Input/index.js +16 -24
  28. package/build/development/shared/components/Input/index.js.map +1 -1
  29. package/build/development/shared/components/Link.js +2 -5
  30. package/build/development/shared/components/Link.js.map +1 -1
  31. package/build/development/shared/components/Modal/index.js +28 -41
  32. package/build/development/shared/components/Modal/index.js.map +1 -1
  33. package/build/development/shared/components/NavLink.js +2 -3
  34. package/build/development/shared/components/NavLink.js.map +1 -1
  35. package/build/development/shared/components/PageLayout/index.js +19 -20
  36. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  37. package/build/development/shared/components/TextArea/index.js +12 -28
  38. package/build/development/shared/components/TextArea/index.js.map +1 -1
  39. package/build/development/shared/components/Throbber/index.js +11 -12
  40. package/build/development/shared/components/Throbber/index.js.map +1 -1
  41. package/build/development/shared/components/WithTooltip/Tooltip.js +46 -68
  42. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  43. package/build/development/shared/components/WithTooltip/index.js +21 -28
  44. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  45. package/build/development/shared/components/YouTubeVideo/index.js +21 -25
  46. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  47. package/build/development/shared/components/index.js +1 -3
  48. package/build/development/shared/components/index.js.map +1 -1
  49. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +6 -7
  50. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  51. package/build/development/shared/components/selectors/CustomDropdown/index.js +7 -9
  52. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  53. package/build/development/shared/components/selectors/NativeDropdown/index.js +23 -27
  54. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  55. package/build/development/shared/components/selectors/Switch/index.js +4 -4
  56. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  57. package/build/development/shared/components/selectors/common.js +2 -5
  58. package/build/development/shared/components/selectors/common.js.map +1 -1
  59. package/build/development/shared/utils/config.js +11 -15
  60. package/build/development/shared/utils/config.js.map +1 -1
  61. package/build/development/shared/utils/globalState.js +1 -7
  62. package/build/development/shared/utils/globalState.js.map +1 -1
  63. package/build/development/shared/utils/index.js +2 -2
  64. package/build/development/shared/utils/index.js.map +1 -1
  65. package/build/development/shared/utils/isomorphy/buildInfo.js +15 -24
  66. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  67. package/build/development/shared/utils/isomorphy/environment-check.js +4 -9
  68. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  69. package/build/development/shared/utils/isomorphy/index.js +17 -23
  70. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  71. package/build/development/shared/utils/jest/E2eSsrEnv.js +48 -77
  72. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  73. package/build/development/shared/utils/jest/index.js +48 -72
  74. package/build/development/shared/utils/jest/index.js.map +1 -1
  75. package/build/development/shared/utils/splitComponent.js +67 -74
  76. package/build/development/shared/utils/splitComponent.js.map +1 -1
  77. package/build/development/shared/utils/time.js +25 -28
  78. package/build/development/shared/utils/time.js.map +1 -1
  79. package/build/development/shared/utils/webpack.js +22 -29
  80. package/build/development/shared/utils/webpack.js.map +1 -1
  81. package/build/production/client/getInj.js.map +1 -1
  82. package/build/production/client/index.js.map +1 -1
  83. package/build/production/index.js +26 -1
  84. package/build/production/index.js.map +1 -1
  85. package/build/production/server/Cache.js.map +1 -1
  86. package/build/production/server/index.js.map +1 -1
  87. package/build/production/server/renderer.js.map +1 -1
  88. package/build/production/server/server.js.map +1 -1
  89. package/build/production/shared/components/Button/index.js.map +1 -1
  90. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  91. package/build/production/shared/components/GenericLink/index.js +2 -2
  92. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  93. package/build/production/shared/components/Input/index.js.map +1 -1
  94. package/build/production/shared/components/Link.js.map +1 -1
  95. package/build/production/shared/components/Modal/index.js.map +1 -1
  96. package/build/production/shared/components/NavLink.js.map +1 -1
  97. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  98. package/build/production/shared/components/TextArea/index.js.map +1 -1
  99. package/build/production/shared/components/Throbber/index.js.map +1 -1
  100. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  101. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  102. package/build/production/shared/components/index.js.map +1 -1
  103. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  104. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  105. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  106. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  107. package/build/production/shared/utils/config.js.map +1 -1
  108. package/build/production/shared/utils/index.js.map +1 -1
  109. package/build/production/shared/utils/jest/index.js.map +1 -1
  110. package/build/production/shared/utils/splitComponent.js +20 -3
  111. package/build/production/shared/utils/splitComponent.js.map +1 -1
  112. package/build/production/shared/utils/time.js.map +1 -1
  113. package/build/production/shared/utils/webpack.js.map +1 -1
  114. package/build/types-code/shared/components/GenericLink/index.d.ts +0 -1
  115. package/build/web/client/getInj.js +10 -70
  116. package/build/web/client/getInj.js.map +1 -1
  117. package/build/web/client/index.js +2 -27
  118. package/build/web/client/index.js.map +1 -1
  119. package/build/web/client/init.js +10 -44
  120. package/build/web/client/init.js.map +1 -1
  121. package/build/web/index.js +26 -6
  122. package/build/web/index.js.map +1 -1
  123. package/build/web/server/Cache.js +3 -41
  124. package/build/web/server/Cache.js.map +1 -1
  125. package/build/web/server/index.js +7 -78
  126. package/build/web/server/index.js.map +1 -1
  127. package/build/web/server/renderer.js +61 -420
  128. package/build/web/server/renderer.js.map +1 -1
  129. package/build/web/server/server.js +38 -212
  130. package/build/web/server/server.js.map +1 -1
  131. package/build/web/server/utils/errors.js +9 -48
  132. package/build/web/server/utils/errors.js.map +1 -1
  133. package/build/web/server/utils/index.js +1 -2
  134. package/build/web/server/utils/index.js.map +1 -1
  135. package/build/web/shared/components/Button/index.js +12 -101
  136. package/build/web/shared/components/Button/index.js.map +1 -1
  137. package/build/web/shared/components/Checkbox/index.js +1 -40
  138. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  139. package/build/web/shared/components/Checkbox/theme.scss +1 -0
  140. package/build/web/shared/components/GenericLink/index.js +12 -65
  141. package/build/web/shared/components/GenericLink/index.js.map +1 -1
  142. package/build/web/shared/components/GenericLink/style.scss +1 -0
  143. package/build/web/shared/components/Input/index.js +11 -69
  144. package/build/web/shared/components/Input/index.js.map +1 -1
  145. package/build/web/shared/components/Link.js +2 -12
  146. package/build/web/shared/components/Link.js.map +1 -1
  147. package/build/web/shared/components/Modal/index.js +10 -130
  148. package/build/web/shared/components/Modal/index.js.map +1 -1
  149. package/build/web/shared/components/NavLink.js +2 -10
  150. package/build/web/shared/components/NavLink.js.map +1 -1
  151. package/build/web/shared/components/PageLayout/index.js +2 -27
  152. package/build/web/shared/components/PageLayout/index.js.map +1 -1
  153. package/build/web/shared/components/TextArea/index.js +21 -106
  154. package/build/web/shared/components/TextArea/index.js.map +1 -1
  155. package/build/web/shared/components/Throbber/index.js +2 -24
  156. package/build/web/shared/components/Throbber/index.js.map +1 -1
  157. package/build/web/shared/components/WithTooltip/Tooltip.js +16 -145
  158. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  159. package/build/web/shared/components/WithTooltip/index.js +12 -104
  160. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  161. package/build/web/shared/components/YouTubeVideo/index.js +5 -43
  162. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
  163. package/build/web/shared/components/index.js +1 -15
  164. package/build/web/shared/components/index.js.map +1 -1
  165. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +6 -81
  166. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  167. package/build/web/shared/components/selectors/CustomDropdown/index.js +7 -122
  168. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  169. package/build/web/shared/components/selectors/NativeDropdown/index.js +7 -68
  170. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  171. package/build/web/shared/components/selectors/Switch/index.js +1 -49
  172. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  173. package/build/web/shared/components/selectors/common.js +1 -10
  174. package/build/web/shared/components/selectors/common.js.map +1 -1
  175. package/build/web/shared/components/selectors/index.js +1 -3
  176. package/build/web/shared/components/selectors/index.js.map +1 -1
  177. package/build/web/shared/utils/config.js +6 -40
  178. package/build/web/shared/utils/config.js.map +1 -1
  179. package/build/web/shared/utils/globalState.js +2 -11
  180. package/build/web/shared/utils/globalState.js.map +1 -1
  181. package/build/web/shared/utils/index.js +1 -9
  182. package/build/web/shared/utils/index.js.map +1 -1
  183. package/build/web/shared/utils/isomorphy/buildInfo.js +4 -25
  184. package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
  185. package/build/web/shared/utils/isomorphy/environment-check.js +3 -9
  186. package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
  187. package/build/web/shared/utils/isomorphy/index.js +5 -27
  188. package/build/web/shared/utils/isomorphy/index.js.map +1 -1
  189. package/build/web/shared/utils/jest/E2eSsrEnv.js +51 -221
  190. package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  191. package/build/web/shared/utils/jest/global.js +1 -3
  192. package/build/web/shared/utils/jest/global.js.map +1 -1
  193. package/build/web/shared/utils/jest/index.js +27 -146
  194. package/build/web/shared/utils/jest/index.js.map +1 -1
  195. package/build/web/shared/utils/splitComponent.js +34 -197
  196. package/build/web/shared/utils/splitComponent.js.map +1 -1
  197. package/build/web/shared/utils/time.js +5 -69
  198. package/build/web/shared/utils/time.js.map +1 -1
  199. package/build/web/shared/utils/webpack.js +6 -53
  200. package/build/web/shared/utils/webpack.js.map +1 -1
  201. package/config/babel/webpack.js +1 -1
  202. package/eslint.config.mjs +1 -0
  203. package/package.json +5 -8
  204. package/config/webpack/lib-base.d.ts +0 -22
  205. package/config/webpack/lib-base.js +0 -167
  206. package/config/webpack/lib-development.d.ts +0 -5
  207. package/config/webpack/lib-development.js +0 -35
  208. package/config/webpack/lib-production.d.ts +0 -5
  209. package/config/webpack/lib-production.js +0 -42
  210. package/webpack.config.ts +0 -49
@@ -2,25 +2,10 @@
2
2
  * The actual tooltip component. It is rendered outside the regular document
3
3
  * hierarchy, and with sub-components managed without React to achieve the best
4
4
  * performance during animation.
5
- */
6
-
7
- import { useImperativeHandle, useRef } from 'react';
8
- import { createPortal } from 'react-dom';
9
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
- /**
5
+ */import{useImperativeHandle,useRef}from"react";import{createPortal}from"react-dom";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";/**
11
6
  * Valid placements of the rendered tooltip. They will be overriden when
12
7
  * necessary to fit the tooltip within the viewport.
13
- */
14
- export let PLACEMENTS = /*#__PURE__*/function (PLACEMENTS) {
15
- PLACEMENTS["ABOVE_CURSOR"] = "ABOVE_CURSOR";
16
- PLACEMENTS["ABOVE_ELEMENT"] = "ABOVE_ELEMENT";
17
- PLACEMENTS["BELOW_CURSOR"] = "BELOW_CURSOR";
18
- PLACEMENTS["BELOW_ELEMENT"] = "BELOW_ELEMENT";
19
- return PLACEMENTS;
20
- }({});
21
- const ARROW_STYLE_DOWN = ['border-bottom-color:transparent', 'border-left-color:transparent', 'border-right-color:transparent'].join(';');
22
- const ARROW_STYLE_UP = ['border-top-color:transparent', 'border-left-color:transparent', 'border-right-color:transparent'].join(';');
23
- /**
8
+ */export let PLACEMENTS=/*#__PURE__*/function(PLACEMENTS){PLACEMENTS["ABOVE_CURSOR"]="ABOVE_CURSOR";PLACEMENTS["ABOVE_ELEMENT"]="ABOVE_ELEMENT";PLACEMENTS["BELOW_CURSOR"]="BELOW_CURSOR";PLACEMENTS["BELOW_ELEMENT"]="BELOW_ELEMENT";return PLACEMENTS}({});const ARROW_STYLE_DOWN=["border-bottom-color:transparent","border-left-color:transparent","border-right-color:transparent"].join(";");const ARROW_STYLE_UP=["border-top-color:transparent","border-left-color:transparent","border-right-color:transparent"].join(";");/**
24
9
  * Generates bounding client rectangles for tooltip components.
25
10
  * @ignore
26
11
  * @param tooltip DOM references to the tooltip components.
@@ -28,39 +13,11 @@ const ARROW_STYLE_UP = ['border-top-color:transparent', 'border-left-color:trans
28
13
  * @param tooltip.container
29
14
  * @return Object holding tooltip rectangles in
30
15
  * two fields.
31
- */
32
- function calcTooltipRects(tooltip) {
33
- return {
34
- arrow: tooltip.arrow.getBoundingClientRect(),
35
- container: tooltip.container.getBoundingClientRect()
36
- };
37
- }
38
-
39
- /**
16
+ */function calcTooltipRects(tooltip){return{arrow:tooltip.arrow.getBoundingClientRect(),container:tooltip.container.getBoundingClientRect()};}/**
40
17
  * Calculates the document viewport size.
41
18
  * @ignore
42
19
  * @return {{x, y, width, height}}
43
- */
44
- function calcViewportRect() {
45
- const {
46
- scrollX,
47
- scrollY
48
- } = window;
49
- const {
50
- documentElement: {
51
- clientHeight,
52
- clientWidth
53
- }
54
- } = document;
55
- return {
56
- bottom: scrollY + clientHeight,
57
- left: scrollX,
58
- right: scrollX + clientWidth,
59
- top: scrollY
60
- };
61
- }
62
-
63
- /**
20
+ */function calcViewportRect(){const{scrollX,scrollY}=window;const{documentElement:{clientHeight,clientWidth}}=document;return{bottom:scrollY+clientHeight,left:scrollX,right:scrollX+clientWidth,top:scrollY};}/**
64
21
  * Calculates tooltip and arrow positions for the placement just above
65
22
  * the cursor.
66
23
  * @ignore
@@ -75,46 +32,28 @@ function calcViewportRect() {
75
32
  * - {number} containerX
76
33
  * - {number} containerY
77
34
  * - {string} baseArrowStyle
78
- */
79
- function calcPositionAboveXY(x, y, tooltipRects) {
80
- const {
81
- arrow,
82
- container
83
- } = tooltipRects;
84
- return {
85
- arrowX: 0.5 * (container.width - arrow.width),
86
- arrowY: container.height,
87
- containerX: x - container.width / 2,
88
- containerY: y - container.height - arrow.height / 1.5,
89
- // TODO: Instead of already setting the base style here, we should
90
- // introduce a set of constants for arrow directions, which will help
91
- // to do checks dependant on the arrow direction.
92
- baseArrowStyle: ARROW_STYLE_DOWN
93
- };
94
- }
95
-
96
- // const HIT = {
35
+ */function calcPositionAboveXY(x,y,tooltipRects){const{arrow,container}=tooltipRects;return{arrowX:0.5*(container.width-arrow.width),arrowY:container.height,containerX:x-container.width/2,containerY:y-container.height-arrow.height/1.5,// TODO: Instead of already setting the base style here, we should
36
+ // introduce a set of constants for arrow directions, which will help
37
+ // to do checks dependant on the arrow direction.
38
+ baseArrowStyle:ARROW_STYLE_DOWN};}// const HIT = {
97
39
  // NONE: false,
98
40
  // LEFT: 'LEFT',
99
41
  // RIGHT: 'RIGHT',
100
42
  // TOP: 'TOP',
101
43
  // BOTTOM: 'BOTTOM',
102
44
  // };
103
-
104
45
  /**
105
46
  * Checks whether
106
47
  * @param {object} pos
107
48
  * @param {object} tooltipRects
108
49
  * @param {object} viewportRect
109
50
  * @return {HIT}
110
- */
111
- // function checkViewportFit(pos, tooltipRects, viewportRect) {
51
+ */// function checkViewportFit(pos, tooltipRects, viewportRect) {
112
52
  // const { containerX, containerY } = pos;
113
53
  // if (containerX < viewportRect.left + 6) return HIT.LEFT;
114
54
  // if (containerX > viewportRect.right - 6) return HIT.RIGHT;
115
55
  // return HIT.NONE;
116
56
  // }
117
-
118
57
  /**
119
58
  * Shifts tooltip horizontally to fit into the viewport, while keeping
120
59
  * the arrow pointed to the XY point.
@@ -123,8 +62,7 @@ function calcPositionAboveXY(x, y, tooltipRects) {
123
62
  * @param {object} pos
124
63
  * @param {number} pageXOffset
125
64
  * @param {number} pageXWidth
126
- */
127
- // function xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {
65
+ */// function xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {
128
66
  // if (pos.containerX < pageXOffset + 6) {
129
67
  // pos.containerX = pageXOffset + 6;
130
68
  // pos.arrowX = Math.max(6, pageX - containerX - arrowRect.width / 2);
@@ -139,7 +77,6 @@ function calcPositionAboveXY(x, y, tooltipRects) {
139
77
  // }
140
78
  // }
141
79
  // }
142
-
143
80
  /**
144
81
  * Sets positions of tooltip components to point the tooltip to the specified
145
82
  * page point.
@@ -151,76 +88,10 @@ function calcPositionAboveXY(x, y, tooltipRects) {
151
88
  * @param tooltip
152
89
  * @param tooltip.arrow DOM reference to the tooltip arrow.
153
90
  * @param tooltip.container DOM reference to the tooltip container.
154
- */
155
- function setComponentPositions(pageX, pageY, placement, element, tooltip) {
156
- const tooltipRects = calcTooltipRects(tooltip);
157
- const viewportRect = calcViewportRect();
158
-
159
- /* Default container coords: tooltip at the top. */
160
- const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);
161
- if (pos.containerX < viewportRect.left + 6) {
162
- pos.containerX = viewportRect.left + 6;
163
- pos.arrowX = Math.max(6, pageX - pos.containerX - tooltipRects.arrow.width / 2);
164
- } else {
165
- const maxX = viewportRect.right - 6 - tooltipRects.container.width;
166
- if (pos.containerX > maxX) {
167
- pos.containerX = maxX;
168
- pos.arrowX = Math.min(tooltipRects.container.width - 6, pageX - pos.containerX - tooltipRects.arrow.width / 2);
169
- }
170
- }
171
-
172
- /* If tooltip has not enough space on top - make it bottom tooltip. */
173
- if (pos.containerY < viewportRect.top + 6) {
174
- pos.containerY += tooltipRects.container.height + 2 * tooltipRects.arrow.height;
175
- pos.arrowY -= tooltipRects.container.height + tooltipRects.arrow.height;
176
- pos.baseArrowStyle = ARROW_STYLE_UP;
177
- }
178
- const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;
179
- tooltip.container.setAttribute('style', containerStyle);
180
- const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;
181
- tooltip.arrow.setAttribute('style', arrowStyle);
182
- }
183
-
184
- /* The Tooltip component itself. */
185
- const Tooltip = ({
186
- children,
187
- ref,
188
- theme
189
- }) => {
190
- // NOTE: The way it has to be implemented, for clean mounting and unmounting
191
- // at the client side, the <Tooltip> is fully mounted into DOM in the next
192
- // rendering cycles, and only then it can be correctly measured and positioned.
193
- // Thus, when we create the <Tooltip> we have to record its target positioning
194
- // details, and then apply them when it is created.
195
-
196
- const arrowRef = useRef(null);
197
- const containerRef = useRef(null);
198
- const contentRef = useRef(null);
199
- const pointTo = (pageX, pageY, placement, element) => {
200
- if (!arrowRef.current || !containerRef.current || !contentRef.current) {
201
- throw Error('Internal error');
202
- }
203
- setComponentPositions(pageX, pageY, placement, element, {
204
- arrow: arrowRef.current,
205
- container: containerRef.current,
206
- content: contentRef.current
207
- });
208
- };
209
- useImperativeHandle(ref, () => ({
210
- pointTo
211
- }));
212
- return /*#__PURE__*/createPortal(/*#__PURE__*/_jsxs("div", {
213
- className: theme.container,
214
- ref: containerRef,
215
- children: [/*#__PURE__*/_jsx("div", {
216
- className: theme.arrow,
217
- ref: arrowRef
218
- }), /*#__PURE__*/_jsx("div", {
219
- className: theme.content,
220
- ref: contentRef,
221
- children: children
222
- })]
223
- }), document.body);
224
- };
225
- export default Tooltip;
91
+ */function setComponentPositions(pageX,pageY,placement,element,tooltip){const tooltipRects=calcTooltipRects(tooltip);const viewportRect=calcViewportRect();/* Default container coords: tooltip at the top. */const pos=calcPositionAboveXY(pageX,pageY,tooltipRects);if(pos.containerX<viewportRect.left+6){pos.containerX=viewportRect.left+6;pos.arrowX=Math.max(6,pageX-pos.containerX-tooltipRects.arrow.width/2);}else{const maxX=viewportRect.right-6-tooltipRects.container.width;if(pos.containerX>maxX){pos.containerX=maxX;pos.arrowX=Math.min(tooltipRects.container.width-6,pageX-pos.containerX-tooltipRects.arrow.width/2);}}/* If tooltip has not enough space on top - make it bottom tooltip. */if(pos.containerY<viewportRect.top+6){pos.containerY+=tooltipRects.container.height+2*tooltipRects.arrow.height;pos.arrowY-=tooltipRects.container.height+tooltipRects.arrow.height;pos.baseArrowStyle=ARROW_STYLE_UP;}const containerStyle=`left:${pos.containerX}px;top:${pos.containerY}px`;tooltip.container.setAttribute("style",containerStyle);const arrowStyle=`${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;tooltip.arrow.setAttribute("style",arrowStyle);}/* The Tooltip component itself. */const Tooltip=({children,ref,theme})=>{// NOTE: The way it has to be implemented, for clean mounting and unmounting
92
+ // at the client side, the <Tooltip> is fully mounted into DOM in the next
93
+ // rendering cycles, and only then it can be correctly measured and positioned.
94
+ // Thus, when we create the <Tooltip> we have to record its target positioning
95
+ // details, and then apply them when it is created.
96
+ const arrowRef=useRef(null);const containerRef=useRef(null);const contentRef=useRef(null);const pointTo=(pageX,pageY,placement,element)=>{if(!arrowRef.current||!containerRef.current||!contentRef.current){throw Error("Internal error");}setComponentPositions(pageX,pageY,placement,element,{arrow:arrowRef.current,container:containerRef.current,content:contentRef.current});};useImperativeHandle(ref,()=>({pointTo}));return/*#__PURE__*/createPortal(/*#__PURE__*/_jsxs("div",{className:theme.container,ref:containerRef,children:[/*#__PURE__*/_jsx("div",{className:theme.arrow,ref:arrowRef}),/*#__PURE__*/_jsx("div",{className:theme.content,ref:contentRef,children:children})]}),document.body);};export default Tooltip;
226
97
  //# sourceMappingURL=Tooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","names":["useImperativeHandle","useRef","createPortal","jsx","_jsx","jsxs","_jsxs","PLACEMENTS","ARROW_STYLE_DOWN","join","ARROW_STYLE_UP","calcTooltipRects","tooltip","arrow","getBoundingClientRect","container","calcViewportRect","scrollX","scrollY","window","documentElement","clientHeight","clientWidth","document","bottom","left","right","top","calcPositionAboveXY","x","y","tooltipRects","arrowX","width","arrowY","height","containerX","containerY","baseArrowStyle","setComponentPositions","pageX","pageY","placement","element","viewportRect","pos","Math","max","maxX","min","containerStyle","setAttribute","arrowStyle","Tooltip","children","ref","theme","arrowRef","containerRef","contentRef","pointTo","current","Error","content","className","body"],"sources":["../../../../../src/shared/components/WithTooltip/Tooltip.tsx"],"sourcesContent":["/**\n * The actual tooltip component. It is rendered outside the regular document\n * hierarchy, and with sub-components managed without React to achieve the best\n * performance during animation.\n */\n\nimport {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\n/**\n * Valid placements of the rendered tooltip. They will be overriden when\n * necessary to fit the tooltip within the viewport.\n */\nexport enum PLACEMENTS {\n ABOVE_CURSOR = 'ABOVE_CURSOR',\n ABOVE_ELEMENT = 'ABOVE_ELEMENT',\n BELOW_CURSOR = 'BELOW_CURSOR',\n BELOW_ELEMENT = 'BELOW_ELEMENT',\n}\n\nconst ARROW_STYLE_DOWN = [\n 'border-bottom-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\nconst ARROW_STYLE_UP = [\n 'border-top-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\ntype ComponentsT = {\n arrow: HTMLDivElement;\n container: HTMLDivElement;\n content: HTMLDivElement;\n};\n\nexport type ThemeKeysT = 'appearance' | 'arrow' | 'container' | 'content';\n\ntype TooltipThemeT = Theme<ThemeKeysT>;\n\ntype TooltipRectsT = {\n arrow: DOMRect;\n container: DOMRect;\n};\n\n/**\n * Generates bounding client rectangles for tooltip components.\n * @ignore\n * @param tooltip DOM references to the tooltip components.\n * @param tooltip.arrow\n * @param tooltip.container\n * @return Object holding tooltip rectangles in\n * two fields.\n */\nfunction calcTooltipRects(tooltip: ComponentsT): TooltipRectsT {\n return {\n arrow: tooltip.arrow.getBoundingClientRect(),\n container: tooltip.container.getBoundingClientRect(),\n };\n}\n\n/**\n * Calculates the document viewport size.\n * @ignore\n * @return {{x, y, width, height}}\n */\nfunction calcViewportRect() {\n const { scrollX, scrollY } = window;\n const { documentElement: { clientHeight, clientWidth } } = document;\n return {\n bottom: scrollY + clientHeight,\n left: scrollX,\n right: scrollX + clientWidth,\n top: scrollY,\n };\n}\n\n/**\n * Calculates tooltip and arrow positions for the placement just above\n * the cursor.\n * @ignore\n * @param {number} x Cursor page-x position.\n * @param {number} y Cursor page-y position.\n * @param {object} tooltipRects Bounding client rectangles of tooltip parts.\n * @param {object} tooltipRects.arrow\n * @param {object} tooltipRects.container\n * @return {object} Contains the following fields:\n * - {number} arrowX\n * - {number} arrowY\n * - {number} containerX\n * - {number} containerY\n * - {string} baseArrowStyle\n */\nfunction calcPositionAboveXY(\n x: number,\n y: number,\n tooltipRects: TooltipRectsT,\n) {\n const { arrow, container } = tooltipRects;\n return {\n arrowX: 0.5 * (container.width - arrow.width),\n arrowY: container.height,\n containerX: x - container.width / 2,\n containerY: y - container.height - arrow.height / 1.5,\n\n // TODO: Instead of already setting the base style here, we should\n // introduce a set of constants for arrow directions, which will help\n // to do checks dependant on the arrow direction.\n baseArrowStyle: ARROW_STYLE_DOWN,\n };\n}\n\n// const HIT = {\n// NONE: false,\n// LEFT: 'LEFT',\n// RIGHT: 'RIGHT',\n// TOP: 'TOP',\n// BOTTOM: 'BOTTOM',\n// };\n\n/**\n * Checks whether\n * @param {object} pos\n * @param {object} tooltipRects\n * @param {object} viewportRect\n * @return {HIT}\n */\n// function checkViewportFit(pos, tooltipRects, viewportRect) {\n// const { containerX, containerY } = pos;\n// if (containerX < viewportRect.left + 6) return HIT.LEFT;\n// if (containerX > viewportRect.right - 6) return HIT.RIGHT;\n// return HIT.NONE;\n// }\n\n/**\n * Shifts tooltip horizontally to fit into the viewport, while keeping\n * the arrow pointed to the XY point.\n * @param {number} x\n * @param {number} y\n * @param {object} pos\n * @param {number} pageXOffset\n * @param {number} pageXWidth\n */\n// function xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {\n// if (pos.containerX < pageXOffset + 6) {\n// pos.containerX = pageXOffset + 6;\n// pos.arrowX = Math.max(6, pageX - containerX - arrowRect.width / 2);\n// } else {\n// const maxX = pageXOffset + docRect.width - containerRect.width - 6;\n// if (containerX > maxX) {\n// containerX = maxX;\n// arrowX = Math.min(\n// containerRect.width - 6,\n// pageX - containerX - arrowRect.width / 2,\n// );\n// }\n// }\n// }\n\n/**\n * Sets positions of tooltip components to point the tooltip to the specified\n * page point.\n * @ignore\n * @param pageX\n * @param pageY\n * @param placement\n * @param element DOM reference to the element wrapped by the tooltip.\n * @param tooltip\n * @param tooltip.arrow DOM reference to the tooltip arrow.\n * @param tooltip.container DOM reference to the tooltip container.\n */\nfunction setComponentPositions(\n pageX: number,\n pageY: number,\n placement: PLACEMENTS | undefined,\n element: HTMLElement | undefined,\n tooltip: ComponentsT,\n) {\n const tooltipRects = calcTooltipRects(tooltip);\n const viewportRect = calcViewportRect();\n\n /* Default container coords: tooltip at the top. */\n const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);\n\n if (pos.containerX < viewportRect.left + 6) {\n pos.containerX = viewportRect.left + 6;\n pos.arrowX = Math.max(\n 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n } else {\n const maxX = viewportRect.right - 6 - tooltipRects.container.width;\n if (pos.containerX > maxX) {\n pos.containerX = maxX;\n pos.arrowX = Math.min(\n tooltipRects.container.width - 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n }\n }\n\n /* If tooltip has not enough space on top - make it bottom tooltip. */\n if (pos.containerY < viewportRect.top + 6) {\n pos.containerY += tooltipRects.container.height\n + 2 * tooltipRects.arrow.height;\n pos.arrowY -= tooltipRects.container.height\n + tooltipRects.arrow.height;\n pos.baseArrowStyle = ARROW_STYLE_UP;\n }\n\n const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;\n tooltip.container.setAttribute('style', containerStyle);\n\n const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;\n tooltip.arrow.setAttribute('style', arrowStyle);\n}\n\n/* The Tooltip component itself. */\nconst Tooltip: FunctionComponent<{\n children?: ReactNode;\n ref?: RefObject<unknown>;\n theme: TooltipThemeT;\n}> = ({ children, ref, theme }) => {\n // NOTE: The way it has to be implemented, for clean mounting and unmounting\n // at the client side, the <Tooltip> is fully mounted into DOM in the next\n // rendering cycles, and only then it can be correctly measured and positioned.\n // Thus, when we create the <Tooltip> we have to record its target positioning\n // details, and then apply them when it is created.\n\n const arrowRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n\n const pointTo = (\n pageX: number,\n pageY: number,\n placement: PLACEMENTS,\n element: HTMLElement,\n ) => {\n if (!arrowRef.current || !containerRef.current || !contentRef.current) {\n throw Error('Internal error');\n }\n\n setComponentPositions(pageX, pageY, placement, element, {\n arrow: arrowRef.current,\n container: containerRef.current,\n content: contentRef.current,\n });\n };\n useImperativeHandle(ref, () => ({ pointTo }));\n\n return createPortal(\n (\n <div className={theme.container} ref={containerRef}>\n <div className={theme.arrow} ref={arrowRef} />\n <div className={theme.content} ref={contentRef}>{children}</div>\n </div>\n ),\n document.body,\n );\n};\n\nexport default Tooltip;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAIEA,mBAAmB,EACnBC,MAAM,QACD,OAAO;AAEd,SAASC,YAAY,QAAQ,WAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAIzC;AACA;AACA;AACA;AACA,WAAYC,UAAU,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAOtB,MAAMC,gBAAgB,GAAG,CACvB,iCAAiC,EACjC,+BAA+B,EAC/B,gCAAgC,CACjC,CAACC,IAAI,CAAC,GAAG,CAAC;AAEX,MAAMC,cAAc,GAAG,CACrB,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,CACjC,CAACD,IAAI,CAAC,GAAG,CAAC;AAiBX;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,gBAAgBA,CAACC,OAAoB,EAAiB;EAC7D,OAAO;IACLC,KAAK,EAAED,OAAO,CAACC,KAAK,CAACC,qBAAqB,CAAC,CAAC;IAC5CC,SAAS,EAAEH,OAAO,CAACG,SAAS,CAACD,qBAAqB,CAAC;EACrD,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASE,gBAAgBA,CAAA,EAAG;EAC1B,MAAM;IAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAGC,MAAM;EACnC,MAAM;IAAEC,eAAe,EAAE;MAAEC,YAAY;MAAEC;IAAY;EAAE,CAAC,GAAGC,QAAQ;EACnE,OAAO;IACLC,MAAM,EAAEN,OAAO,GAAGG,YAAY;IAC9BI,IAAI,EAAER,OAAO;IACbS,KAAK,EAAET,OAAO,GAAGK,WAAW;IAC5BK,GAAG,EAAET;EACP,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASU,mBAAmBA,CAC1BC,CAAS,EACTC,CAAS,EACTC,YAA2B,EAC3B;EACA,MAAM;IAAElB,KAAK;IAAEE;EAAU,CAAC,GAAGgB,YAAY;EACzC,OAAO;IACLC,MAAM,EAAE,GAAG,IAAIjB,SAAS,CAACkB,KAAK,GAAGpB,KAAK,CAACoB,KAAK,CAAC;IAC7CC,MAAM,EAAEnB,SAAS,CAACoB,MAAM;IACxBC,UAAU,EAAEP,CAAC,GAAGd,SAAS,CAACkB,KAAK,GAAG,CAAC;IACnCI,UAAU,EAAEP,CAAC,GAAGf,SAAS,CAACoB,MAAM,GAAGtB,KAAK,CAACsB,MAAM,GAAG,GAAG;IAErD;IACA;IACA;IACAG,cAAc,EAAE9B;EAClB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS+B,qBAAqBA,CAC5BC,KAAa,EACbC,KAAa,EACbC,SAAiC,EACjCC,OAAgC,EAChC/B,OAAoB,EACpB;EACA,MAAMmB,YAAY,GAAGpB,gBAAgB,CAACC,OAAO,CAAC;EAC9C,MAAMgC,YAAY,GAAG5B,gBAAgB,CAAC,CAAC;;EAEvC;EACA,MAAM6B,GAAG,GAAGjB,mBAAmB,CAACY,KAAK,EAAEC,KAAK,EAAEV,YAAY,CAAC;EAE3D,IAAIc,GAAG,CAACT,UAAU,GAAGQ,YAAY,CAACnB,IAAI,GAAG,CAAC,EAAE;IAC1C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M,CAAC;EAAA,CAC7D,CAAC,EAER/B,QAAQ,CAAC0C,IACX,CAAC;AACH,CAAC;AAED,eAAeZ,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"Tooltip.js","names":["useImperativeHandle","useRef","createPortal","jsx","_jsx","jsxs","_jsxs","PLACEMENTS","ARROW_STYLE_DOWN","join","ARROW_STYLE_UP","calcTooltipRects","tooltip","arrow","getBoundingClientRect","container","calcViewportRect","scrollX","scrollY","window","documentElement","clientHeight","clientWidth","document","bottom","left","right","top","calcPositionAboveXY","x","y","tooltipRects","arrowX","width","arrowY","height","containerX","containerY","baseArrowStyle","setComponentPositions","pageX","pageY","placement","element","viewportRect","pos","Math","max","maxX","min","containerStyle","setAttribute","arrowStyle","Tooltip","children","ref","theme","arrowRef","containerRef","contentRef","pointTo","current","Error","content","className","body"],"sources":["../../../../../src/shared/components/WithTooltip/Tooltip.tsx"],"sourcesContent":["/**\n * The actual tooltip component. It is rendered outside the regular document\n * hierarchy, and with sub-components managed without React to achieve the best\n * performance during animation.\n */\n\nimport {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\n/**\n * Valid placements of the rendered tooltip. They will be overriden when\n * necessary to fit the tooltip within the viewport.\n */\nexport enum PLACEMENTS {\n ABOVE_CURSOR = 'ABOVE_CURSOR',\n ABOVE_ELEMENT = 'ABOVE_ELEMENT',\n BELOW_CURSOR = 'BELOW_CURSOR',\n BELOW_ELEMENT = 'BELOW_ELEMENT',\n}\n\nconst ARROW_STYLE_DOWN = [\n 'border-bottom-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\nconst ARROW_STYLE_UP = [\n 'border-top-color:transparent',\n 'border-left-color:transparent',\n 'border-right-color:transparent',\n].join(';');\n\ntype ComponentsT = {\n arrow: HTMLDivElement;\n container: HTMLDivElement;\n content: HTMLDivElement;\n};\n\nexport type ThemeKeysT = 'appearance' | 'arrow' | 'container' | 'content';\n\ntype TooltipThemeT = Theme<ThemeKeysT>;\n\ntype TooltipRectsT = {\n arrow: DOMRect;\n container: DOMRect;\n};\n\n/**\n * Generates bounding client rectangles for tooltip components.\n * @ignore\n * @param tooltip DOM references to the tooltip components.\n * @param tooltip.arrow\n * @param tooltip.container\n * @return Object holding tooltip rectangles in\n * two fields.\n */\nfunction calcTooltipRects(tooltip: ComponentsT): TooltipRectsT {\n return {\n arrow: tooltip.arrow.getBoundingClientRect(),\n container: tooltip.container.getBoundingClientRect(),\n };\n}\n\n/**\n * Calculates the document viewport size.\n * @ignore\n * @return {{x, y, width, height}}\n */\nfunction calcViewportRect() {\n const { scrollX, scrollY } = window;\n const { documentElement: { clientHeight, clientWidth } } = document;\n return {\n bottom: scrollY + clientHeight,\n left: scrollX,\n right: scrollX + clientWidth,\n top: scrollY,\n };\n}\n\n/**\n * Calculates tooltip and arrow positions for the placement just above\n * the cursor.\n * @ignore\n * @param {number} x Cursor page-x position.\n * @param {number} y Cursor page-y position.\n * @param {object} tooltipRects Bounding client rectangles of tooltip parts.\n * @param {object} tooltipRects.arrow\n * @param {object} tooltipRects.container\n * @return {object} Contains the following fields:\n * - {number} arrowX\n * - {number} arrowY\n * - {number} containerX\n * - {number} containerY\n * - {string} baseArrowStyle\n */\nfunction calcPositionAboveXY(\n x: number,\n y: number,\n tooltipRects: TooltipRectsT,\n) {\n const { arrow, container } = tooltipRects;\n return {\n arrowX: 0.5 * (container.width - arrow.width),\n arrowY: container.height,\n containerX: x - container.width / 2,\n containerY: y - container.height - arrow.height / 1.5,\n\n // TODO: Instead of already setting the base style here, we should\n // introduce a set of constants for arrow directions, which will help\n // to do checks dependant on the arrow direction.\n baseArrowStyle: ARROW_STYLE_DOWN,\n };\n}\n\n// const HIT = {\n// NONE: false,\n// LEFT: 'LEFT',\n// RIGHT: 'RIGHT',\n// TOP: 'TOP',\n// BOTTOM: 'BOTTOM',\n// };\n\n/**\n * Checks whether\n * @param {object} pos\n * @param {object} tooltipRects\n * @param {object} viewportRect\n * @return {HIT}\n */\n// function checkViewportFit(pos, tooltipRects, viewportRect) {\n// const { containerX, containerY } = pos;\n// if (containerX < viewportRect.left + 6) return HIT.LEFT;\n// if (containerX > viewportRect.right - 6) return HIT.RIGHT;\n// return HIT.NONE;\n// }\n\n/**\n * Shifts tooltip horizontally to fit into the viewport, while keeping\n * the arrow pointed to the XY point.\n * @param {number} x\n * @param {number} y\n * @param {object} pos\n * @param {number} pageXOffset\n * @param {number} pageXWidth\n */\n// function xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {\n// if (pos.containerX < pageXOffset + 6) {\n// pos.containerX = pageXOffset + 6;\n// pos.arrowX = Math.max(6, pageX - containerX - arrowRect.width / 2);\n// } else {\n// const maxX = pageXOffset + docRect.width - containerRect.width - 6;\n// if (containerX > maxX) {\n// containerX = maxX;\n// arrowX = Math.min(\n// containerRect.width - 6,\n// pageX - containerX - arrowRect.width / 2,\n// );\n// }\n// }\n// }\n\n/**\n * Sets positions of tooltip components to point the tooltip to the specified\n * page point.\n * @ignore\n * @param pageX\n * @param pageY\n * @param placement\n * @param element DOM reference to the element wrapped by the tooltip.\n * @param tooltip\n * @param tooltip.arrow DOM reference to the tooltip arrow.\n * @param tooltip.container DOM reference to the tooltip container.\n */\nfunction setComponentPositions(\n pageX: number,\n pageY: number,\n placement: PLACEMENTS | undefined,\n element: HTMLElement | undefined,\n tooltip: ComponentsT,\n) {\n const tooltipRects = calcTooltipRects(tooltip);\n const viewportRect = calcViewportRect();\n\n /* Default container coords: tooltip at the top. */\n const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);\n\n if (pos.containerX < viewportRect.left + 6) {\n pos.containerX = viewportRect.left + 6;\n pos.arrowX = Math.max(\n 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n } else {\n const maxX = viewportRect.right - 6 - tooltipRects.container.width;\n if (pos.containerX > maxX) {\n pos.containerX = maxX;\n pos.arrowX = Math.min(\n tooltipRects.container.width - 6,\n pageX - pos.containerX - tooltipRects.arrow.width / 2,\n );\n }\n }\n\n /* If tooltip has not enough space on top - make it bottom tooltip. */\n if (pos.containerY < viewportRect.top + 6) {\n pos.containerY += tooltipRects.container.height\n + 2 * tooltipRects.arrow.height;\n pos.arrowY -= tooltipRects.container.height\n + tooltipRects.arrow.height;\n pos.baseArrowStyle = ARROW_STYLE_UP;\n }\n\n const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;\n tooltip.container.setAttribute('style', containerStyle);\n\n const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;\n tooltip.arrow.setAttribute('style', arrowStyle);\n}\n\n/* The Tooltip component itself. */\nconst Tooltip: FunctionComponent<{\n children?: ReactNode;\n ref?: RefObject<unknown>;\n theme: TooltipThemeT;\n}> = ({ children, ref, theme }) => {\n // NOTE: The way it has to be implemented, for clean mounting and unmounting\n // at the client side, the <Tooltip> is fully mounted into DOM in the next\n // rendering cycles, and only then it can be correctly measured and positioned.\n // Thus, when we create the <Tooltip> we have to record its target positioning\n // details, and then apply them when it is created.\n\n const arrowRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n\n const pointTo = (\n pageX: number,\n pageY: number,\n placement: PLACEMENTS,\n element: HTMLElement,\n ) => {\n if (!arrowRef.current || !containerRef.current || !contentRef.current) {\n throw Error('Internal error');\n }\n\n setComponentPositions(pageX, pageY, placement, element, {\n arrow: arrowRef.current,\n container: containerRef.current,\n content: contentRef.current,\n });\n };\n useImperativeHandle(ref, () => ({ pointTo }));\n\n return createPortal(\n (\n <div className={theme.container} ref={containerRef}>\n <div className={theme.arrow} ref={arrowRef} />\n <div className={theme.content} ref={contentRef}>{children}</div>\n </div>\n ),\n document.body,\n );\n};\n\nexport default Tooltip;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,GAEA,OAIEA,m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AAZ,OAAO","ignoreList":[]}
@@ -1,11 +1,4 @@
1
- /* global window */
2
-
3
- import { useEffect, useRef, useState } from 'react';
4
- import { useTheme } from '@dr.pogodin/react-themes';
5
- import Tooltip, { PLACEMENTS } from "./Tooltip";
6
- import defaultTheme from "./default-theme.scss";
7
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
- /**
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";/**
9
2
  * Implements a simple to use and themeable tooltip component, _e.g._
10
3
  * ```js
11
4
  * <WithTooltip tip="This is example tooltip.">
@@ -18,100 +11,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
11
  * @param tip &ndash; Anything React is able to render,
19
12
  * _e.g._ a tooltip text. This will be the tooltip content.
20
13
  * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.
21
- */
22
- const WithTooltip = ({
23
- children,
24
- placement = PLACEMENTS.ABOVE_CURSOR,
25
- theme,
26
- tip
27
- }) => {
28
- const custom = useTheme('WithTooltip', defaultTheme, theme);
29
- const {
30
- current: heap
31
- } = useRef({
32
- lastCursorX: 0,
33
- lastCursorY: 0,
34
- timerId: undefined,
35
- triggeredByTouch: false
36
- });
37
- const tooltipRef = useRef(null);
38
- const wrapperRef = useRef(null);
39
- const [showTooltip, setShowTooltip] = useState(false);
40
- const updatePortalPosition = (cursorX, cursorY) => {
41
- if (showTooltip) {
42
- const wrapperRect = wrapperRef.current.getBoundingClientRect();
43
- if (cursorX < wrapperRect.left || cursorX > wrapperRect.right || cursorY < wrapperRect.top || cursorY > wrapperRect.bottom) {
44
- setShowTooltip(false);
45
- } else if (tooltipRef.current) {
46
- tooltipRef.current.pointTo(cursorX + window.scrollX, cursorY + window.scrollY, placement, wrapperRef.current);
47
- }
48
- } else {
49
- heap.lastCursorX = cursorX;
50
- heap.lastCursorY = cursorY;
51
-
52
- // If tooltip was triggered by a touch, we delay its opening by a bit,
53
- // to ensure it was not a touch-click - in the case of touch click we
54
- // want to do the click, rather than show the tooltip, and the delay
55
- // gives click handler a chance to abort the tooltip openning.
56
- if (heap.triggeredByTouch) {
57
- heap.timerId ??= setTimeout(() => {
58
- heap.triggeredByTouch = false;
59
- heap.timerId = undefined;
60
- setShowTooltip(true);
61
- }, 300);
62
-
63
- // Otherwise we can just open the tooltip right away.
64
- } else setShowTooltip(true);
65
- }
66
- };
67
- useEffect(() => {
68
- if (showTooltip && tip !== null) {
69
- // This is necessary to ensure that even when a single mouse event
70
- // arrives to a tool-tipped component, the tooltip is correctly positioned
71
- // once opened (because similar call above does not have effect until
72
- // the tooltip is fully mounted, and that is delayed to future rendering
73
- // cycle due to the implementation).
74
- if (tooltipRef.current) {
75
- tooltipRef.current.pointTo(heap.lastCursorX + window.scrollX, heap.lastCursorY + window.scrollY, placement, wrapperRef.current);
76
- }
77
- const listener = () => {
78
- setShowTooltip(false);
79
- };
80
- window.addEventListener('scroll', listener);
81
- return () => {
82
- window.removeEventListener('scroll', listener);
83
- };
84
- }
85
- return undefined;
86
- }, [heap.lastCursorX, heap.lastCursorY, placement, showTooltip, tip]);
87
- return /*#__PURE__*/_jsxs("div", {
88
- className: custom.wrapper,
89
- onClick: () => {
90
- if (heap.timerId) {
91
- clearTimeout(heap.timerId);
92
- heap.timerId = undefined;
93
- heap.triggeredByTouch = false;
94
- }
95
- },
96
- onMouseLeave: () => {
97
- setShowTooltip(false);
98
- },
99
- onMouseMove: e => {
100
- updatePortalPosition(e.clientX, e.clientY);
101
- },
102
- onTouchStart: () => {
103
- heap.triggeredByTouch = true;
104
- },
105
- ref: wrapperRef,
106
- role: "presentation",
107
- children: [showTooltip && tip !== null ? /*#__PURE__*/_jsx(Tooltip, {
108
- ref: tooltipRef,
109
- theme: custom,
110
- children: tip
111
- }) : null, children]
112
- });
113
- };
114
- const e = WithTooltip;
115
- e.PLACEMENTS = PLACEMENTS;
116
- export default e;
14
+ */const WithTooltip=({children,placement=PLACEMENTS.ABOVE_CURSOR,theme,tip})=>{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 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,
15
+ // to ensure it was not a touch-click - in the case of touch click we
16
+ // want to do the click, rather than show the tooltip, and the delay
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(()=>{if(showTooltip&&tip!==null){// This is necessary to ensure that even when a single mouse event
20
+ // arrives to a tool-tipped component, the tooltip is correctly positioned
21
+ // once opened (because similar call above does not have effect until
22
+ // the tooltip is fully mounted, and that is delayed to future rendering
23
+ // cycle due to the implementation).
24
+ if(tooltipRef.current){tooltipRef.current.pointTo(heap.lastCursorX+window.scrollX,heap.lastCursorY+window.scrollY,placement,wrapperRef.current);}const listener=()=>{setShowTooltip(false);};window.addEventListener("scroll",listener);return()=>{window.removeEventListener("scroll",listener);};}return undefined;},[heap.lastCursorX,heap.lastCursorY,placement,showTooltip,tip]);return/*#__PURE__*/_jsxs("div",{className:custom.wrapper,onClick:()=>{if(heap.timerId){clearTimeout(heap.timerId);heap.timerId=undefined;heap.triggeredByTouch=false;}},onMouseLeave:()=>{setShowTooltip(false);},onMouseMove:e=>{updatePortalPosition(e.clientX,e.clientY);},onTouchStart:()=>{heap.triggeredByTouch=true;},ref:wrapperRef,role:"presentation",children:[showTooltip&&tip!==null?/*#__PURE__*/_jsx(Tooltip,{ref:tooltipRef,theme:custom,children:tip}):null,children]});};const e=WithTooltip;e.PLACEMENTS=PLACEMENTS;export default e;
117
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useEffect","useRef","useState","useTheme","Tooltip","PLACEMENTS","defaultTheme","jsx","_jsx","jsxs","_jsxs","WithTooltip","children","placement","ABOVE_CURSOR","theme","tip","custom","current","heap","lastCursorX","lastCursorY","timerId","undefined","triggeredByTouch","tooltipRef","wrapperRef","showTooltip","setShowTooltip","updatePortalPosition","cursorX","cursorY","wrapperRect","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","setTimeout","listener","addEventListener","removeEventListener","className","wrapper","onClick","clearTimeout","onMouseLeave","onMouseMove","e","clientX","clientY","onTouchStart","ref","role"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type ReactNode,\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 = {\n children?: ReactNode;\n placement?: PLACEMENTS;\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 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 placement = PLACEMENTS.ABOVE_CURSOR,\n theme,\n tip,\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 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 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 heap.lastCursorX + window.scrollX,\n heap.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 heap.lastCursorX,\n heap.lastCursorY,\n placement,\n showTooltip,\n tip,\n ]);\n\n return (\n <div\n className={custom.wrapper}\n onClick={() => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n }}\n onMouseLeave={() => {\n setShowTooltip(false);\n }}\n onMouseMove={(e) => {\n updatePortalPosition(e.clientX, e.clientY);\n }}\n onTouchStart={() => {\n heap.triggeredByTouch = true;\n }}\n ref={wrapperRef}\n role=\"presentation\"\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;;AAEA,SAGEA,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,SAAqBC,QAAQ,QAAQ,0BAA0B;AAE/D,OAAOC,OAAO,IACZC,UAAU;AAIZ,OAAOC,YAAY;AAA6B,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAyBhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAsC,GAAGA,CAAC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,IAAI,CAACK,gBAAgB,GAAG,KAAK;MAC/B;IACF,CAAE;IACF0B,YAAY,EAAEA,CAAA,KAAM;MAClBtB,cAAc,CAAC,KAAK,CAAC;IACvB,CAAE;IACFuB,WAAW,EAAGC,CAAC,IAAK;MAClBvB,oBAAoB,CAACuB,CAAC,CAACC,OAAO,EAAED,CAAC,CAACE,OAAO,CAAC;IAC5C,CAAE;IACFC,YAAY,EAAEA,CAAA,KAAM;MAClBpC,IAAI,CAACK,gBAAgB,GAAG,IAAI;IAC9B,CAAE;IACFgC,GAAG,EAAE9B,UAAW;IAChB+B,IAAI,EAAC,cAAc;IAAA7C,QAAA,GAGjBe,WAAW,IAAIX,GAAG,KAAK,IAAI,gBACvBR,IAAA,CAACJ,OAAO;MAACoD,GAAG,EAAE/B,UAAW;MAACV,KAAK,EAAEE,MAAO;MAAAL,QAAA,EAAEI;IAAG,CAAU,CAAC,GACxD,IAAI,EAETJ,QAAQ;EAAA,CACN,CAAC;AAEV,CAAC;AAMD,MAAMwC,CAAU,GAAGzC,WAAsB;AAEzCyC,CAAC,CAAC/C,UAAU,GAAGA,UAAU;AAEzB,eAAe+C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useEffect","useRef","useState","useTheme","Tooltip","PLACEMENTS","defaultTheme","jsx","_jsx","jsxs","_jsxs","WithTooltip","children","placement","ABOVE_CURSOR","theme","tip","custom","current","heap","lastCursorX","lastCursorY","timerId","undefined","triggeredByTouch","tooltipRef","wrapperRef","showTooltip","setShowTooltip","updatePortalPosition","cursorX","cursorY","wrapperRect","getBoundingClientRect","left","right","top","bottom","pointTo","window","scrollX","scrollY","setTimeout","listener","addEventListener","removeEventListener","className","wrapper","onClick","clearTimeout","onMouseLeave","onMouseMove","e","clientX","clientY","onTouchStart","ref","role"],"sources":["../../../../../src/shared/components/WithTooltip/index.tsx"],"sourcesContent":["/* global window */\n\nimport {\n type FunctionComponent,\n type ReactNode,\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 = {\n children?: ReactNode;\n placement?: PLACEMENTS;\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 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 placement = PLACEMENTS.ABOVE_CURSOR,\n theme,\n tip,\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 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 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 heap.lastCursorX + window.scrollX,\n heap.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 heap.lastCursorX,\n heap.lastCursorY,\n placement,\n showTooltip,\n tip,\n ]);\n\n return (\n <div\n className={custom.wrapper}\n onClick={() => {\n if (heap.timerId) {\n clearTimeout(heap.timerId);\n heap.timerId = undefined;\n heap.triggeredByTouch = false;\n }\n }}\n onMouseLeave={() => {\n setShowTooltip(false);\n }}\n onMouseMove={(e) => {\n updatePortalPosition(e.clientX, e.clientY);\n }}\n onTouchStart={() => {\n heap.triggeredByTouch = true;\n }}\n ref={wrapperRef}\n role=\"presentation\"\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} &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qs from 'qs';
2
- import { useTheme } from '@dr.pogodin/react-themes';
3
- import Throbber from "../Throbber";
4
- import defaultTheme from "./base.scss";
5
- import throbberTheme from "./throbber.scss";
6
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
- /**
1
+ import qs from"qs";import{useTheme}from"@dr.pogodin/react-themes";import Throbber from"../Throbber";import defaultTheme from"./base.scss";import throbberTheme from"./throbber.scss";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";/**
8
2
  * A component for embeding a YouTube video.
9
3
  * @param [props] Component properties.
10
4
  * @param [props.autoplay] If `true` the video will start to play
@@ -18,40 +12,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
12
  * @param [props.theme] _Ad hoc_ theme.
19
13
  * @param [props.title] The `title` attribute to add to the player
20
14
  * IFrame.
21
- */
22
- const YouTubeVideo = ({
23
- autoplay,
24
- src,
25
- theme,
26
- title
27
- }) => {
28
- const custom = useTheme('YouTubeVideo', defaultTheme, theme);
29
- const srcParts = src.split('?');
30
- let [url] = srcParts;
31
- const [, queryString] = srcParts;
32
- const query = queryString ? qs.parse(queryString) : {};
33
- const videoId = query.v ?? url?.match(/\/([a-zA-Z0-9-_]*)$/)?.[1];
34
- url = `https://www.youtube.com/embed/${videoId}`;
35
- delete query.v;
36
- query.autoplay = autoplay ? '1' : '0';
37
- url += `?${qs.stringify(query)}`;
38
-
39
- // TODO: https://developers.google.com/youtube/player_parameters
40
- // More query parameters can be exposed via the component props.
41
-
42
- return /*#__PURE__*/_jsxs("div", {
43
- className: custom.container,
44
- children: [/*#__PURE__*/_jsx(Throbber, {
45
- theme: throbberTheme
46
- }), /*#__PURE__*/_jsx("iframe", {
47
- // eslint-disable-line react/iframe-missing-sandbox
48
- allow: "autoplay",
49
- allowFullScreen: true,
50
- className: custom.video,
51
- src: url,
52
- title: title
53
- })]
54
- });
55
- };
56
- export default YouTubeVideo;
15
+ */const YouTubeVideo=({autoplay,src,theme,title})=>{const custom=useTheme("YouTubeVideo",defaultTheme,theme);const srcParts=src.split("?");let[url]=srcParts;const[,queryString]=srcParts;const query=queryString?qs.parse(queryString):{};const videoId=query.v??url?.match(/\/([a-zA-Z0-9-_]*)$/)?.[1];url=`https://www.youtube.com/embed/${videoId}`;delete query.v;query.autoplay=autoplay?"1":"0";url+=`?${qs.stringify(query)}`;// TODO: https://developers.google.com/youtube/player_parameters
16
+ // More query parameters can be exposed via the component props.
17
+ return/*#__PURE__*/_jsxs("div",{className:custom.container,children:[/*#__PURE__*/_jsx(Throbber,{theme:throbberTheme}),/*#__PURE__*/_jsx("iframe",{// eslint-disable-line react/iframe-missing-sandbox
18
+ allow:"autoplay",allowFullScreen:true,className:custom.video,src:url,title:title})]});};export default YouTubeVideo;
57
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["qs","useTheme","Throbber","defaultTheme","throbberTheme","jsx","_jsx","jsxs","_jsxs","YouTubeVideo","autoplay","src","theme","title","custom","srcParts","split","url","queryString","query","parse","videoId","v","match","stringify","className","container","children","allow","allowFullScreen","video"],"sources":["../../../../../src/shared/components/YouTubeVideo/index.tsx"],"sourcesContent":["import qs from 'qs';\nimport type { FunctionComponent } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Throbber from 'components/Throbber';\n\nimport defaultTheme from './base.scss';\nimport throbberTheme from './throbber.scss';\n\ntype ThemeT = Theme<'container' | 'video'>;\n\ntype PropsT = {\n autoplay?: boolean;\n src: string;\n theme?: ThemeT;\n title?: string;\n};\n\n/**\n * A component for embeding a YouTube video.\n * @param [props] Component properties.\n * @param [props.autoplay] If `true` the video will start to play\n * automatically once loaded.\n * @param [props.src] URL of the video to play. Can be in any of\n * the following formats, and keeps any additional query parameters understood\n * by the YouTube IFrame player:\n * - `https://www.youtube.com/watch?v=NdF6Rmt6Ado`\n * - `https://youtu.be/NdF6Rmt6Ado`\n * - `https://www.youtube.com/embed/NdF6Rmt6Ado`\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.title] The `title` attribute to add to the player\n * IFrame.\n */\nconst YouTubeVideo: FunctionComponent<PropsT> = ({\n autoplay,\n src,\n theme,\n title,\n}) => {\n const custom = useTheme('YouTubeVideo', defaultTheme, theme);\n\n const srcParts = src.split('?');\n let [url] = srcParts;\n const [, queryString] = srcParts;\n const query = queryString ? qs.parse(queryString) : {};\n\n const videoId = query.v ?? url?.match(/\\/([a-zA-Z0-9-_]*)$/)?.[1];\n url = `https://www.youtube.com/embed/${videoId as string}`;\n\n delete query.v;\n query.autoplay = autoplay ? '1' : '0';\n url += `?${qs.stringify(query)}`;\n\n // TODO: https://developers.google.com/youtube/player_parameters\n // More query parameters can be exposed via the component props.\n\n return (\n <div className={custom.container}>\n <Throbber theme={throbberTheme} />\n {/* TODO: I guess, we better add the sanbox, but right now I don't have\n time to carefully explore which restrictions should be lifted to allow\n embed YouTube player to work... sometime later we'll take care of it */\n }\n <iframe // eslint-disable-line react/iframe-missing-sandbox\n allow=\"autoplay\"\n allowFullScreen\n className={custom.video}\n src={url}\n title={title}\n />\n </div>\n );\n};\n\nexport default YouTubeVideo;\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AAGnB,SAAqBC,QAAQ,QAAQ,0BAA0B;AAE/D,OAAOC,QAAQ;AAEf,OAAOC,YAAY;AACnB,OAAOC,aAAa;AAAwB,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAW5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAuC,GAAGA,CAAC;EAC/CC,QAAQ;EACRC,GAAG;EACHC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,MAAMC,MAAM,GAAGb,QAAQ,CAAC,cAAc,EAAEE,YAAY,EAAES,KAAK,CAAC;EAE5D,MAAMG,QAAQ,GAAGJ,GAAG,CAACK,KAAK,CAAC,GAAG,CAAC;EAC/B,IAAI,CAACC,GAAG,CAAC,GAAGF,QAAQ;EACpB,MAAM,GAAGG,WAAW,CAAC,GAAGH,QAAQ;EAChC,MAAMI,KAAK,GAAGD,WAAW,GAAGlB,EAAE,CAACoB,KAAK,CAACF,WAAW,CAAC,GAAG,CAAC,CAAC;EAEtD,MAAMG,OAAO,GAAGF,KAAK,CAACG,CAAC,IAAIL,GAAG,EAAEM,KAAK,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;EACjEN,GAAG,GAAG,iCAAiCI,OAAO,EAAY;EAE1D,OAAOF,KAAK,CAACG,CAAC;EACdH,KAAK,CAACT,QAAQ,GAAGA,QAAQ,GAAG,GAAG,GAAG,GAAG;EACrCO,GAAG,IAAI,IAAIjB,EAAE,CAACwB,SAAS,CAACL,KAAK,CAAC,EAAE;;EAEhC;EACA;;EAEA,oBACEX,KAAA;IAAKiB,SAAS,EAAEX,MAAM,CAACY,SAAU;IAAAC,QAAA,gBAC/BrB,IAAA,CAACJ,QAAQ;MAACU,KAAK,EAAER;IAAc,CAAE,CAAC,eAKlCE,IAAA;MAAQ;MACNsB,KAAK,EAAC,UAAU;MAChBC,eAAe;MACfJ,SAAS,EAAEX,MAAM,CAACgB,KAAM;MACxBnB,GAAG,EAAEM,GAAI;MACTJ,KAAK,EAAEA;IAAM,CACd,CAAC;EAAA,CACC,CAAC;AAEV,CAAC;AAED,eAAeJ,YAAY","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["qs","useTheme","Throbber","defaultTheme","throbberTheme","jsx","_jsx","jsxs","_jsxs","YouTubeVideo","autoplay","src","theme","title","custom","srcParts","split","url","queryString","query","parse","videoId","v","match","stringify","className","container","children","allow","allowFullScreen","video"],"sources":["../../../../../src/shared/components/YouTubeVideo/index.tsx"],"sourcesContent":["import qs from 'qs';\nimport type { FunctionComponent } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Throbber from 'components/Throbber';\n\nimport defaultTheme from './base.scss';\nimport throbberTheme from './throbber.scss';\n\ntype ThemeT = Theme<'container' | 'video'>;\n\ntype PropsT = {\n autoplay?: boolean;\n src: string;\n theme?: ThemeT;\n title?: string;\n};\n\n/**\n * A component for embeding a YouTube video.\n * @param [props] Component properties.\n * @param [props.autoplay] If `true` the video will start to play\n * automatically once loaded.\n * @param [props.src] URL of the video to play. Can be in any of\n * the following formats, and keeps any additional query parameters understood\n * by the YouTube IFrame player:\n * - `https://www.youtube.com/watch?v=NdF6Rmt6Ado`\n * - `https://youtu.be/NdF6Rmt6Ado`\n * - `https://www.youtube.com/embed/NdF6Rmt6Ado`\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.title] The `title` attribute to add to the player\n * IFrame.\n */\nconst YouTubeVideo: FunctionComponent<PropsT> = ({\n autoplay,\n src,\n theme,\n title,\n}) => {\n const custom = useTheme('YouTubeVideo', defaultTheme, theme);\n\n const srcParts = src.split('?');\n let [url] = srcParts;\n const [, queryString] = srcParts;\n const query = queryString ? qs.parse(queryString) : {};\n\n const videoId = query.v ?? url?.match(/\\/([a-zA-Z0-9-_]*)$/)?.[1];\n url = `https://www.youtube.com/embed/${videoId as string}`;\n\n delete query.v;\n query.autoplay = autoplay ? '1' : '0';\n url += `?${qs.stringify(query)}`;\n\n // TODO: https://developers.google.com/youtube/player_parameters\n // More query parameters can be exposed via the component props.\n\n return (\n <div className={custom.container}>\n <Throbber theme={throbberTheme} />\n {/* TODO: I guess, we better add the sanbox, but right now I don't have\n time to carefully explore which restrictions should be lifted to allow\n embed YouTube player to work... sometime later we'll take care of it */\n }\n <iframe // eslint-disable-line react/iframe-missing-sandbox\n allow=\"autoplay\"\n allowFullScreen\n className={custom.video}\n src={url}\n title={title}\n />\n </div>\n );\n};\n\nexport default YouTubeVideo;\n"],"mappings":"AAAA,MAAO,CAAAA,EAAE,KAAM,IAAI,CAGnB,OAAqBC,QAAQ,KAAQ,0BAA0B,CAE/D,MAAO,CAAAC,QAAQ,mBAEf,MAAO,CAAAC,YAAY,mBAC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CAAEA,KAAM,CACd,CAAC,EACC,CAAC,CAEV,CAAC,CAED,cAAe,CAAAJ,YAAY","ignoreList":[]}
@@ -1,18 +1,4 @@
1
1
  /**
2
2
  * Just an aggregation of all exported components into a single module.
3
- */
4
-
5
- export { MetaTags } from '@dr.pogodin/react-helmet';
6
- export * from "./selectors";
7
- export { BaseButton, default as Button } from "./Button";
8
- export { default as Checkbox } from "./Checkbox";
9
- export { default as Input } from "./Input";
10
- export { default as Link } from "./Link";
11
- export { BaseModal, default as Modal } from "./Modal";
12
- export { default as NavLink } from "./NavLink";
13
- export { default as PageLayout } from "./PageLayout";
14
- export { default as Throbber } from "./Throbber";
15
- export { default as WithTooltip } from "./WithTooltip";
16
- export { default as YouTubeVideo } from "./YouTubeVideo";
17
- export { default as TextArea } from "./TextArea";
3
+ */export{MetaTags}from"@dr.pogodin/react-helmet";export*from"./selectors";export{BaseButton,default as Button}from"./Button";export{default as Checkbox}from"./Checkbox";export{default as Input}from"./Input";export{default as Link}from"./Link";export{BaseModal,default as Modal}from"./Modal";export{default as NavLink}from"./NavLink";export{default as PageLayout}from"./PageLayout";export{default as Throbber}from"./Throbber";export{default as WithTooltip}from"./WithTooltip";export{default as YouTubeVideo}from"./YouTubeVideo";export{default as TextArea}from"./TextArea";
18
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["MetaTags","BaseButton","default","Button","Checkbox","Input","Link","BaseModal","Modal","NavLink","PageLayout","Throbber","WithTooltip","YouTubeVideo","TextArea"],"sources":["../../../../src/shared/components/index.ts"],"sourcesContent":["/**\n * Just an aggregation of all exported components into a single module.\n */\n\nexport { MetaTags } from '@dr.pogodin/react-helmet';\n\nexport * from 'components/selectors';\n\nexport { BaseButton, default as Button } from 'components/Button';\nexport { default as Checkbox } from 'components/Checkbox';\nexport { default as Input } from 'components/Input';\nexport { default as Link } from 'components/Link';\nexport { BaseModal, default as Modal } from 'components/Modal';\nexport { default as NavLink } from 'components/NavLink';\nexport { default as PageLayout } from 'components/PageLayout';\nexport { default as Throbber } from 'components/Throbber';\nexport { default as WithTooltip } from 'components/WithTooltip';\nexport { default as YouTubeVideo } from 'components/YouTubeVideo';\n\nexport { default as TextArea } from './TextArea';\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,0BAA0B;AAEnD;AAEA,SAASC,UAAU,EAAEC,OAAO,IAAIC,MAAM;AACtC,SAASD,OAAO,IAAIE,QAAQ;AAC5B,SAASF,OAAO,IAAIG,KAAK;AACzB,SAASH,OAAO,IAAII,IAAI;AACxB,SAASC,SAAS,EAAEL,OAAO,IAAIM,KAAK;AACpC,SAASN,OAAO,IAAIO,OAAO;AAC3B,SAASP,OAAO,IAAIQ,UAAU;AAC9B,SAASR,OAAO,IAAIS,QAAQ;AAC5B,SAAST,OAAO,IAAIU,WAAW;AAC/B,SAASV,OAAO,IAAIW,YAAY;AAEhC,SAASX,OAAO,IAAIY,QAAQ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["MetaTags","BaseButton","default","Button","Checkbox","Input","Link","BaseModal","Modal","NavLink","PageLayout","Throbber","WithTooltip","YouTubeVideo","TextArea"],"sources":["../../../../src/shared/components/index.ts"],"sourcesContent":["/**\n * Just an aggregation of all exported components into a single module.\n */\n\nexport { MetaTags } from '@dr.pogodin/react-helmet';\n\nexport * from 'components/selectors';\n\nexport { BaseButton, default as Button } from 'components/Button';\nexport { default as Checkbox } from 'components/Checkbox';\nexport { default as Input } from 'components/Input';\nexport { default as Link } from 'components/Link';\nexport { BaseModal, default as Modal } from 'components/Modal';\nexport { default as NavLink } from 'components/NavLink';\nexport { default as PageLayout } from 'components/PageLayout';\nexport { default as Throbber } from 'components/Throbber';\nexport { default as WithTooltip } from 'components/WithTooltip';\nexport { default as YouTubeVideo } from 'components/YouTubeVideo';\n\nexport { default as TextArea } from './TextArea';\n"],"mappings":"AAAA;AACA;AACA,GAEA,OAASA,QAAQ,KAAQ,0BAA0B,CAEnD,yBAEA,OAASC,UAAU,CAAEC,OAAO,GAAI,CAAAC,MAAM,gBACtC,OAASD,OAAO,GAAI,CAAAE,QAAQ,kBAC5B,OAASF,OAAO,GAAI,CAAAG,KAAK,eACzB,OAASH,OAAO,GAAI,CAAAI,IAAI,cACxB,OAASC,SAAS,CAAEL,OAAO,GAAI,CAAAM,KAAK,eACpC,OAASN,OAAO,GAAI,CAAAO,OAAO,iBAC3B,OAASP,OAAO,GAAI,CAAAQ,UAAU,oBAC9B,OAASR,OAAO,GAAI,CAAAS,QAAQ,kBAC5B,OAAST,OAAO,GAAI,CAAAU,WAAW,qBAC/B,OAASV,OAAO,GAAI,CAAAW,YAAY,sBAEhC,OAASX,OAAO,GAAI,CAAAY,QAAQ","ignoreList":[]}