@dr.pogodin/react-utils 1.49.1 → 1.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.scripts.config.js +19 -0
- package/build/development/client/getInj.js +18 -29
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +11 -14
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +9 -17
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +26 -4
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +15 -20
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +142 -160
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +150 -197
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +63 -86
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +72 -87
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/shared/components/Button/index.js +8 -17
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +4 -4
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +54 -58
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +16 -24
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +2 -5
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +28 -41
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +2 -3
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +19 -20
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +12 -28
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +11 -12
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +46 -68
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +21 -28
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +21 -25
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +1 -3
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +6 -7
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +7 -9
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +23 -27
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +4 -4
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +2 -5
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/utils/config.js +11 -15
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +1 -7
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +2 -2
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +15 -24
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +4 -9
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +17 -23
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +48 -77
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +48 -72
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +67 -74
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +25 -28
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +22 -29
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js.map +1 -1
- package/build/production/index.js +26 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js.map +1 -1
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +2 -2
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +20 -3
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/shared/components/GenericLink/index.d.ts +0 -1
- package/build/web/client/getInj.js +10 -70
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/client/index.js +2 -27
- package/build/web/client/index.js.map +1 -1
- package/build/web/client/init.js +10 -44
- package/build/web/client/init.js.map +1 -1
- package/build/web/index.js +26 -6
- package/build/web/index.js.map +1 -1
- package/build/web/server/Cache.js +3 -41
- package/build/web/server/Cache.js.map +1 -1
- package/build/web/server/index.js +7 -78
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/renderer.js +61 -420
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +38 -212
- package/build/web/server/server.js.map +1 -1
- package/build/web/server/utils/errors.js +9 -48
- package/build/web/server/utils/errors.js.map +1 -1
- package/build/web/server/utils/index.js +1 -2
- package/build/web/server/utils/index.js.map +1 -1
- package/build/web/shared/components/Button/index.js +12 -101
- package/build/web/shared/components/Button/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/index.js +1 -40
- package/build/web/shared/components/Checkbox/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/theme.scss +1 -0
- package/build/web/shared/components/GenericLink/index.js +12 -65
- package/build/web/shared/components/GenericLink/index.js.map +1 -1
- package/build/web/shared/components/GenericLink/style.scss +1 -0
- package/build/web/shared/components/Input/index.js +11 -69
- package/build/web/shared/components/Input/index.js.map +1 -1
- package/build/web/shared/components/Link.js +2 -12
- package/build/web/shared/components/Link.js.map +1 -1
- package/build/web/shared/components/Modal/index.js +10 -130
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/components/NavLink.js +2 -10
- package/build/web/shared/components/NavLink.js.map +1 -1
- package/build/web/shared/components/PageLayout/index.js +2 -27
- package/build/web/shared/components/PageLayout/index.js.map +1 -1
- package/build/web/shared/components/TextArea/index.js +21 -106
- package/build/web/shared/components/TextArea/index.js.map +1 -1
- package/build/web/shared/components/Throbber/index.js +2 -24
- package/build/web/shared/components/Throbber/index.js.map +1 -1
- package/build/web/shared/components/WithTooltip/Tooltip.js +16 -145
- package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/web/shared/components/WithTooltip/index.js +12 -104
- package/build/web/shared/components/WithTooltip/index.js.map +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js +5 -43
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/web/shared/components/index.js +1 -15
- package/build/web/shared/components/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +6 -81
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +7 -122
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js +7 -68
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +1 -49
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/web/shared/components/selectors/common.js +1 -10
- package/build/web/shared/components/selectors/common.js.map +1 -1
- package/build/web/shared/components/selectors/index.js +1 -3
- package/build/web/shared/components/selectors/index.js.map +1 -1
- package/build/web/shared/utils/config.js +6 -40
- package/build/web/shared/utils/config.js.map +1 -1
- package/build/web/shared/utils/globalState.js +2 -11
- package/build/web/shared/utils/globalState.js.map +1 -1
- package/build/web/shared/utils/index.js +1 -9
- package/build/web/shared/utils/index.js.map +1 -1
- package/build/web/shared/utils/isomorphy/buildInfo.js +4 -25
- package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/web/shared/utils/isomorphy/environment-check.js +3 -9
- package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/web/shared/utils/isomorphy/index.js +5 -27
- package/build/web/shared/utils/isomorphy/index.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv.js +51 -221
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/web/shared/utils/jest/global.js +1 -3
- package/build/web/shared/utils/jest/global.js.map +1 -1
- package/build/web/shared/utils/jest/index.js +27 -146
- package/build/web/shared/utils/jest/index.js.map +1 -1
- package/build/web/shared/utils/splitComponent.js +34 -197
- package/build/web/shared/utils/splitComponent.js.map +1 -1
- package/build/web/shared/utils/time.js +5 -69
- package/build/web/shared/utils/time.js.map +1 -1
- package/build/web/shared/utils/webpack.js +6 -53
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/webpack.js +1 -1
- package/eslint.config.mjs +1 -0
- package/package.json +5 -8
- package/bin/build.js +0 -236
- package/config/webpack/lib-base.d.ts +0 -22
- package/config/webpack/lib-base.js +0 -167
- package/config/webpack/lib-development.d.ts +0 -5
- package/config/webpack/lib-development.js +0 -35
- package/config/webpack/lib-production.d.ts +0 -5
- package/config/webpack/lib-production.js +0 -42
- package/webpack.config.ts +0 -49
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useTheme","defaultTheme","jsx","_jsx","jsxs","_jsxs","Throbber","theme","themePriority","custom","className","container","children","circle"],"sources":["../../../../../src/shared/components/Throbber/index.tsx"],"sourcesContent":["import type { FunctionComponent } from 'react';\n\nimport { type PRIORITY, type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeKeyT = 'bouncing' | 'circle' | 'container';\n\ntype PropsT = {\n theme?: Theme<ThemeKeyT>;\n themePriority?: PRIORITY;\n};\n\n/**\n * Throbber is an \"action in progress\" indicator, which renders\n * three bouncing circles as a simple pending activity indicator,\n * and can be further themed to a certain degree.\n * @param {object} [props] Component properties.\n * @param {ThrobberTheme} [props.theme] _Ad hoc_ theme.\n * @param {...any} [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Throbber: FunctionComponent<PropsT> = ({ theme, themePriority }) => {\n const custom = useTheme('Throbber', defaultTheme, theme, {\n themePriority,\n });\n\n return (\n <span className={custom.container}>\n <span className={custom.circle} />\n <span className={custom.circle} />\n <span className={custom.circle} />\n </span>\n );\n};\n\nexport default Throbber;\n"],"mappings":"AAEA,SAAoCA,QAAQ,QAAQ,0BAA0B;
|
|
1
|
+
{"version":3,"file":"index.js","names":["useTheme","defaultTheme","jsx","_jsx","jsxs","_jsxs","Throbber","theme","themePriority","custom","className","container","children","circle"],"sources":["../../../../../src/shared/components/Throbber/index.tsx"],"sourcesContent":["import type { FunctionComponent } from 'react';\n\nimport { type PRIORITY, type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeKeyT = 'bouncing' | 'circle' | 'container';\n\ntype PropsT = {\n theme?: Theme<ThemeKeyT>;\n themePriority?: PRIORITY;\n};\n\n/**\n * Throbber is an \"action in progress\" indicator, which renders\n * three bouncing circles as a simple pending activity indicator,\n * and can be further themed to a certain degree.\n * @param {object} [props] Component properties.\n * @param {ThrobberTheme} [props.theme] _Ad hoc_ theme.\n * @param {...any} [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Throbber: FunctionComponent<PropsT> = ({ theme, themePriority }) => {\n const custom = useTheme('Throbber', defaultTheme, theme, {\n themePriority,\n });\n\n return (\n <span className={custom.container}>\n <span className={custom.circle} />\n <span className={custom.circle} />\n <span className={custom.circle} />\n </span>\n );\n};\n\nexport default Throbber;\n"],"mappings":"AAEA,SAAoCA,QAAQ,QAAQ,0BAA0B;AAE9E,MAAAC,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA,4BASxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,QAAmC,GAAGA,CAAC;EAAEC,KAAK;EAAEC;AAAc,CAAC,KAAK;EACxE,MAAMC,MAAM,GAAGT,QAAQ,CAAC,UAAU,EAAEC,YAAY,EAAEM,KAAK,EAAE;IACvDC;EACF,CAAC,CAAC;EAEF,oBACEH,KAAA;IAAMK,SAAS,EAAED,MAAM,CAACE,SAAU;IAAAC,QAAA,gBAChCT,IAAA;MAAMO,SAAS,EAAED,MAAM,CAACI;IAAO,CAAE,CAAC,eAClCV,IAAA;MAAMO,SAAS,EAAED,MAAM,CAACI;IAAO,CAAE,CAAC,eAClCV,IAAA;MAAMO,SAAS,EAAED,MAAM,CAACI;IAAO,CAAE,CAAC;EAAA,CAC9B,CAAC;AAEX,CAAC;AAED,eAAeP,QAAQ","ignoreList":[]}
|
|
@@ -2,15 +2,12 @@
|
|
|
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 {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* Valid placements of the rendered tooltip. They will be overriden when
|
|
12
|
-
* necessary to fit the tooltip within the viewport.
|
|
13
|
-
*/
|
|
5
|
+
*/import { useImperativeHandle, useRef } from "react";
|
|
6
|
+
import { createPortal } from "react-dom";
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /**
|
|
8
|
+
* Valid placements of the rendered tooltip. They will be overriden when
|
|
9
|
+
* necessary to fit the tooltip within the viewport.
|
|
10
|
+
*/
|
|
14
11
|
export let PLACEMENTS = /*#__PURE__*/function (PLACEMENTS) {
|
|
15
12
|
PLACEMENTS["ABOVE_CURSOR"] = "ABOVE_CURSOR";
|
|
16
13
|
PLACEMENTS["ABOVE_ELEMENT"] = "ABOVE_ELEMENT";
|
|
@@ -18,29 +15,26 @@ export let PLACEMENTS = /*#__PURE__*/function (PLACEMENTS) {
|
|
|
18
15
|
PLACEMENTS["BELOW_ELEMENT"] = "BELOW_ELEMENT";
|
|
19
16
|
return PLACEMENTS;
|
|
20
17
|
}({});
|
|
21
|
-
const ARROW_STYLE_DOWN = [
|
|
22
|
-
const ARROW_STYLE_UP = [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*/
|
|
18
|
+
const ARROW_STYLE_DOWN = ["border-bottom-color:transparent", "border-left-color:transparent", "border-right-color:transparent"].join(";");
|
|
19
|
+
const ARROW_STYLE_UP = ["border-top-color:transparent", "border-left-color:transparent", "border-right-color:transparent"].join(";"); /**
|
|
20
|
+
* Generates bounding client rectangles for tooltip components.
|
|
21
|
+
* @ignore
|
|
22
|
+
* @param tooltip DOM references to the tooltip components.
|
|
23
|
+
* @param tooltip.arrow
|
|
24
|
+
* @param tooltip.container
|
|
25
|
+
* @return Object holding tooltip rectangles in
|
|
26
|
+
* two fields.
|
|
27
|
+
*/
|
|
32
28
|
function calcTooltipRects(tooltip) {
|
|
33
29
|
return {
|
|
34
30
|
arrow: tooltip.arrow.getBoundingClientRect(),
|
|
35
31
|
container: tooltip.container.getBoundingClientRect()
|
|
36
32
|
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* @return {{x, y, width, height}}
|
|
43
|
-
*/
|
|
33
|
+
} /**
|
|
34
|
+
* Calculates the document viewport size.
|
|
35
|
+
* @ignore
|
|
36
|
+
* @return {{x, y, width, height}}
|
|
37
|
+
*/
|
|
44
38
|
function calcViewportRect() {
|
|
45
39
|
const {
|
|
46
40
|
scrollX,
|
|
@@ -58,24 +52,22 @@ function calcViewportRect() {
|
|
|
58
52
|
right: scrollX + clientWidth,
|
|
59
53
|
top: scrollY
|
|
60
54
|
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
* - {string} baseArrowStyle
|
|
78
|
-
*/
|
|
55
|
+
} /**
|
|
56
|
+
* Calculates tooltip and arrow positions for the placement just above
|
|
57
|
+
* the cursor.
|
|
58
|
+
* @ignore
|
|
59
|
+
* @param {number} x Cursor page-x position.
|
|
60
|
+
* @param {number} y Cursor page-y position.
|
|
61
|
+
* @param {object} tooltipRects Bounding client rectangles of tooltip parts.
|
|
62
|
+
* @param {object} tooltipRects.arrow
|
|
63
|
+
* @param {object} tooltipRects.container
|
|
64
|
+
* @return {object} Contains the following fields:
|
|
65
|
+
* - {number} arrowX
|
|
66
|
+
* - {number} arrowY
|
|
67
|
+
* - {number} containerX
|
|
68
|
+
* - {number} containerY
|
|
69
|
+
* - {string} baseArrowStyle
|
|
70
|
+
*/
|
|
79
71
|
function calcPositionAboveXY(x, y, tooltipRects) {
|
|
80
72
|
const {
|
|
81
73
|
arrow,
|
|
@@ -91,30 +83,25 @@ function calcPositionAboveXY(x, y, tooltipRects) {
|
|
|
91
83
|
// to do checks dependant on the arrow direction.
|
|
92
84
|
baseArrowStyle: ARROW_STYLE_DOWN
|
|
93
85
|
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// const HIT = {
|
|
86
|
+
} // const HIT = {
|
|
97
87
|
// NONE: false,
|
|
98
88
|
// LEFT: 'LEFT',
|
|
99
89
|
// RIGHT: 'RIGHT',
|
|
100
90
|
// TOP: 'TOP',
|
|
101
91
|
// BOTTOM: 'BOTTOM',
|
|
102
92
|
// };
|
|
103
|
-
|
|
104
93
|
/**
|
|
105
94
|
* Checks whether
|
|
106
95
|
* @param {object} pos
|
|
107
96
|
* @param {object} tooltipRects
|
|
108
97
|
* @param {object} viewportRect
|
|
109
98
|
* @return {HIT}
|
|
110
|
-
*/
|
|
111
|
-
// function checkViewportFit(pos, tooltipRects, viewportRect) {
|
|
99
|
+
*/ // function checkViewportFit(pos, tooltipRects, viewportRect) {
|
|
112
100
|
// const { containerX, containerY } = pos;
|
|
113
101
|
// if (containerX < viewportRect.left + 6) return HIT.LEFT;
|
|
114
102
|
// if (containerX > viewportRect.right - 6) return HIT.RIGHT;
|
|
115
103
|
// return HIT.NONE;
|
|
116
104
|
// }
|
|
117
|
-
|
|
118
105
|
/**
|
|
119
106
|
* Shifts tooltip horizontally to fit into the viewport, while keeping
|
|
120
107
|
* the arrow pointed to the XY point.
|
|
@@ -123,8 +110,7 @@ function calcPositionAboveXY(x, y, tooltipRects) {
|
|
|
123
110
|
* @param {object} pos
|
|
124
111
|
* @param {number} pageXOffset
|
|
125
112
|
* @param {number} pageXWidth
|
|
126
|
-
*/
|
|
127
|
-
// function xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {
|
|
113
|
+
*/ // function xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {
|
|
128
114
|
// if (pos.containerX < pageXOffset + 6) {
|
|
129
115
|
// pos.containerX = pageXOffset + 6;
|
|
130
116
|
// pos.arrowX = Math.max(6, pageX - containerX - arrowRect.width / 2);
|
|
@@ -139,7 +125,6 @@ function calcPositionAboveXY(x, y, tooltipRects) {
|
|
|
139
125
|
// }
|
|
140
126
|
// }
|
|
141
127
|
// }
|
|
142
|
-
|
|
143
128
|
/**
|
|
144
129
|
* Sets positions of tooltip components to point the tooltip to the specified
|
|
145
130
|
* page point.
|
|
@@ -154,9 +139,7 @@ function calcPositionAboveXY(x, y, tooltipRects) {
|
|
|
154
139
|
*/
|
|
155
140
|
function setComponentPositions(pageX, pageY, placement, element, tooltip) {
|
|
156
141
|
const tooltipRects = calcTooltipRects(tooltip);
|
|
157
|
-
const viewportRect = calcViewportRect();
|
|
158
|
-
|
|
159
|
-
/* Default container coords: tooltip at the top. */
|
|
142
|
+
const viewportRect = calcViewportRect(); /* Default container coords: tooltip at the top. */
|
|
160
143
|
const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);
|
|
161
144
|
if (pos.containerX < viewportRect.left + 6) {
|
|
162
145
|
pos.containerX = viewportRect.left + 6;
|
|
@@ -167,21 +150,17 @@ function setComponentPositions(pageX, pageY, placement, element, tooltip) {
|
|
|
167
150
|
pos.containerX = maxX;
|
|
168
151
|
pos.arrowX = Math.min(tooltipRects.container.width - 6, pageX - pos.containerX - tooltipRects.arrow.width / 2);
|
|
169
152
|
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/* If tooltip has not enough space on top - make it bottom tooltip. */
|
|
153
|
+
} /* If tooltip has not enough space on top - make it bottom tooltip. */
|
|
173
154
|
if (pos.containerY < viewportRect.top + 6) {
|
|
174
155
|
pos.containerY += tooltipRects.container.height + 2 * tooltipRects.arrow.height;
|
|
175
156
|
pos.arrowY -= tooltipRects.container.height + tooltipRects.arrow.height;
|
|
176
157
|
pos.baseArrowStyle = ARROW_STYLE_UP;
|
|
177
158
|
}
|
|
178
159
|
const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;
|
|
179
|
-
tooltip.container.setAttribute(
|
|
160
|
+
tooltip.container.setAttribute("style", containerStyle);
|
|
180
161
|
const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;
|
|
181
|
-
tooltip.arrow.setAttribute(
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/* The Tooltip component itself. */
|
|
162
|
+
tooltip.arrow.setAttribute("style", arrowStyle);
|
|
163
|
+
} /* The Tooltip component itself. */
|
|
185
164
|
const Tooltip = ({
|
|
186
165
|
children,
|
|
187
166
|
ref,
|
|
@@ -192,13 +171,12 @@ const Tooltip = ({
|
|
|
192
171
|
// rendering cycles, and only then it can be correctly measured and positioned.
|
|
193
172
|
// Thus, when we create the <Tooltip> we have to record its target positioning
|
|
194
173
|
// details, and then apply them when it is created.
|
|
195
|
-
|
|
196
174
|
const arrowRef = useRef(null);
|
|
197
175
|
const containerRef = useRef(null);
|
|
198
176
|
const contentRef = useRef(null);
|
|
199
177
|
const pointTo = (pageX, pageY, placement, element) => {
|
|
200
178
|
if (!arrowRef.current || !containerRef.current || !contentRef.current) {
|
|
201
|
-
throw Error(
|
|
179
|
+
throw Error("Internal error");
|
|
202
180
|
}
|
|
203
181
|
setComponentPositions(pageX, pageY, placement, element, {
|
|
204
182
|
arrow: arrowRef.current,
|
|
@@ -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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AQ,GAAGxD,MAAM,CAAiB,IAAI,CAAC;EAC7C,MAAMyD,YAAY,GAAGzD,MAAM,CAAiB,IAAI,CAAC;EACjD,MAAM0D,UAAU,GAAG1D,MAAM,CAAiB,IAAI,CAAC;EAE/C,MAAM2D,OAAO,GAAGA,CACdpB,KAAa,EACbC,KAAa,EACbC,SAAqB,EACrBC,OAAoB,KACjB;IACH,IAAI,CAACc,QAAQ,CAACI,OAAO,IAAI,CAACH,YAAY,CAACG,OAAO,IAAI,CAACF,UAAU,CAACE,OAAO,EAAE;MACrE,MAAMC,KAAK,CAAC,gBAAgB,CAAC;IAC/B;IAEAvB,qBAAqB,CAACC,KAAK,EAAEC,KAAK,EAAEC,SAAS,EAAEC,OAAO,EAAE;MACtD9B,KAAK,EAAE4C,QAAQ,CAACI,OAAO;MACvB9C,SAAS,EAAE2C,YAAY,CAACG,OAAO;MAC/BE,OAAO,EAAEJ,UAAU,CAACE;IACtB,CAAC,CAAC;EACJ,CAAC;EACD7D,mBAAmB,CAACuD,GAAG,EAAE,OAAO;IAAEK;EAAQ,CAAC,CAAC,CAAC;EAE7C,oBAAO1D,YAAY,cAEfI,KAAA;IAAK0D,SAAS,EAAER,KAAK,CAACzC,SAAU;IAACwC,GAAG,EAAEG,YAAa;IAAAJ,QAAA,gBACjDlD,IAAA;MAAK4D,SAAS,EAAER,KAAK,CAAC3C,KAAM;MAAC0C,GAAG,EAAEE;IAAS,CAAE,CAAC,eAC9CrD,IAAA;MAAK4D,SAAS,EAAER,KAAK,CAACO,OAAQ;MAACR,GAAG,EAAEI,UAAW;MAAAL,QAAA,EAAEA;IAAQ,CAAM,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,SAIEA,mBAAmB,EACnBC,MAAM,QACD,OAAO;AAEd,SAASC,YAAY,QAAQ,WAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA,4BAIzC;AACA;AACA;AACA;AACA,WAAYC,UAAU,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EA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,KAAa,EACbC,KAAa,EACbC,SAAqB,EACrBC,OAAoB,KACjB;IACH,IAAI,CAACc,QAAQ,CAACI,OAAO,IAAI,CAACH,YAAY,CAACG,OAAO,IAAI,CAACF,UAAU,CAACE,OAAO,EAAE;MACrE,MAAMC,KAAK,CAAC,gBAAgB,CAAC;IAC/B;IAEAvB,qBAAqB,CAACC,KAAK,EAAEC,KAAK,EAAEC,SAAS,EAAEC,OAAO,EAAE;MACtD9B,KAAK,EAAE4C,QAAQ,CAACI,OAAO;MACvB9C,SAAS,EAAE2C,YAAY,CAACG,OAAO;MAC/BE,OAAO,EAAEJ,UAAU,CAACE;IACtB,CAAC,CAAC;EACJ,CAAC;EACD7D,mBAAmB,CAACuD,GAAG,EAAE,OAAO;IAAEK;EAAQ,CAAC,CAAC,CAAC;EAE7C,oBAAO1D,YAAY,cAEfI,KAAA;IAAK0D,SAAS,EAAER,KAAK,CAACzC,SAAU;IAACwC,GAAG,EAAEG,YAAa;IAAAJ,QAAA,gBACjDlD,IAAA;MAAK4D,SAAS,EAAER,KAAK,CAAC3C,KAAM;MAAC0C,GAAG,EAAEE;IAAS,CAAE,CAAC,eAC9CrD,IAAA;MAAK4D,SAAS,EAAER,KAAK,CAACO,OAAQ;MAACR,GAAG,EAAEI,UAAW;MAAAL,QAAA,EAAEA;IAAQ,CAAM,CAAC;EAAA,CAC7D,CAAC,EAER/B,QAAQ,CAAC0C,IACX,CAAC;AACH,CAAC;AAED,eAAeZ,OAAO","ignoreList":[]}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
/* global window */
|
|
2
|
-
|
|
3
|
-
import { useEffect, useRef, useState } from 'react';
|
|
4
|
-
import { useTheme } from '@dr.pogodin/react-themes';
|
|
1
|
+
/* global window */import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useTheme } from "@dr.pogodin/react-themes";
|
|
5
3
|
import Tooltip, { PLACEMENTS } from "./Tooltip.js";
|
|
6
4
|
const defaultTheme = {
|
|
7
5
|
"ad": "-dr-pogodin-react-utils___build-web-shared-components-WithTooltip-default-theme___ad___n6OiU9",
|
|
@@ -12,28 +10,27 @@ const defaultTheme = {
|
|
|
12
10
|
"container": "-dr-pogodin-react-utils___build-web-shared-components-WithTooltip-default-theme___container___uA1tHZ",
|
|
13
11
|
"wrapper": "-dr-pogodin-react-utils___build-web-shared-components-WithTooltip-default-theme___wrapper___JFVmGf"
|
|
14
12
|
};
|
|
15
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /**
|
|
14
|
+
* Implements a simple to use and themeable tooltip component, _e.g._
|
|
15
|
+
* ```js
|
|
16
|
+
* <WithTooltip tip="This is example tooltip.">
|
|
17
|
+
* <p>Hover to see the tooltip.</p>
|
|
18
|
+
* </WithTooltip>
|
|
19
|
+
* ```
|
|
20
|
+
* **Children:** Children are rendered in the place of `<WithTooltip>`,
|
|
21
|
+
* and when hovered the tooltip is shown. By default the wrapper itself is
|
|
22
|
+
* `<div>` block with `display: inline-block`.
|
|
23
|
+
* @param tip – Anything React is able to render,
|
|
24
|
+
* _e.g._ a tooltip text. This will be the tooltip content.
|
|
25
|
+
* @param {WithTooltipTheme} props.theme _Ad hoc_ theme.
|
|
26
|
+
*/
|
|
30
27
|
const WithTooltip = ({
|
|
31
28
|
children,
|
|
32
29
|
placement = PLACEMENTS.ABOVE_CURSOR,
|
|
33
30
|
theme,
|
|
34
31
|
tip
|
|
35
32
|
}) => {
|
|
36
|
-
const custom = useTheme(
|
|
33
|
+
const custom = useTheme("WithTooltip", defaultTheme, theme);
|
|
37
34
|
const {
|
|
38
35
|
current: heap
|
|
39
36
|
} = useRef({
|
|
@@ -55,9 +52,7 @@ const WithTooltip = ({
|
|
|
55
52
|
}
|
|
56
53
|
} else {
|
|
57
54
|
heap.lastCursorX = cursorX;
|
|
58
|
-
heap.lastCursorY = cursorY;
|
|
59
|
-
|
|
60
|
-
// If tooltip was triggered by a touch, we delay its opening by a bit,
|
|
55
|
+
heap.lastCursorY = cursorY; // If tooltip was triggered by a touch, we delay its opening by a bit,
|
|
61
56
|
// to ensure it was not a touch-click - in the case of touch click we
|
|
62
57
|
// want to do the click, rather than show the tooltip, and the delay
|
|
63
58
|
// gives click handler a chance to abort the tooltip openning.
|
|
@@ -66,9 +61,7 @@ const WithTooltip = ({
|
|
|
66
61
|
heap.triggeredByTouch = false;
|
|
67
62
|
heap.timerId = undefined;
|
|
68
63
|
setShowTooltip(true);
|
|
69
|
-
}, 300);
|
|
70
|
-
|
|
71
|
-
// Otherwise we can just open the tooltip right away.
|
|
64
|
+
}, 300); // Otherwise we can just open the tooltip right away.
|
|
72
65
|
} else setShowTooltip(true);
|
|
73
66
|
}
|
|
74
67
|
};
|
|
@@ -85,9 +78,9 @@ const WithTooltip = ({
|
|
|
85
78
|
const listener = () => {
|
|
86
79
|
setShowTooltip(false);
|
|
87
80
|
};
|
|
88
|
-
window.addEventListener(
|
|
81
|
+
window.addEventListener("scroll", listener);
|
|
89
82
|
return () => {
|
|
90
|
-
window.removeEventListener(
|
|
83
|
+
window.removeEventListener("scroll", listener);
|
|
91
84
|
};
|
|
92
85
|
}
|
|
93
86
|
return undefined;
|
|
@@ -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 – 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
|
|
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 – 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,mBAEA,SAGEA,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,4BAyBhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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AAO,CAAC;QAC1BH,IAAI,CAACG,OAAO,GAAGC,SAAS;QACxBJ,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,5 +1,5 @@
|
|
|
1
|
-
import qs from
|
|
2
|
-
import { useTheme } from
|
|
1
|
+
import qs from "qs";
|
|
2
|
+
import { useTheme } from "@dr.pogodin/react-themes";
|
|
3
3
|
import Throbber from "../Throbber/index.js";
|
|
4
4
|
const defaultTheme = {
|
|
5
5
|
"context": "-dr-pogodin-react-utils___build-web-shared-components-YouTubeVideo-base___context___Pa7GiX",
|
|
@@ -14,42 +14,38 @@ const throbberTheme = {
|
|
|
14
14
|
"hoc": "-dr-pogodin-react-utils___build-web-shared-components-YouTubeVideo-throbber___hoc___T5TGzT",
|
|
15
15
|
"container": "-dr-pogodin-react-utils___build-web-shared-components-YouTubeVideo-throbber___container___IgN6Uf"
|
|
16
16
|
};
|
|
17
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*/
|
|
17
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /**
|
|
18
|
+
* A component for embeding a YouTube video.
|
|
19
|
+
* @param [props] Component properties.
|
|
20
|
+
* @param [props.autoplay] If `true` the video will start to play
|
|
21
|
+
* automatically once loaded.
|
|
22
|
+
* @param [props.src] URL of the video to play. Can be in any of
|
|
23
|
+
* the following formats, and keeps any additional query parameters understood
|
|
24
|
+
* by the YouTube IFrame player:
|
|
25
|
+
* - `https://www.youtube.com/watch?v=NdF6Rmt6Ado`
|
|
26
|
+
* - `https://youtu.be/NdF6Rmt6Ado`
|
|
27
|
+
* - `https://www.youtube.com/embed/NdF6Rmt6Ado`
|
|
28
|
+
* @param [props.theme] _Ad hoc_ theme.
|
|
29
|
+
* @param [props.title] The `title` attribute to add to the player
|
|
30
|
+
* IFrame.
|
|
31
|
+
*/
|
|
33
32
|
const YouTubeVideo = ({
|
|
34
33
|
autoplay,
|
|
35
34
|
src,
|
|
36
35
|
theme,
|
|
37
36
|
title
|
|
38
37
|
}) => {
|
|
39
|
-
const custom = useTheme(
|
|
40
|
-
const srcParts = src.split(
|
|
38
|
+
const custom = useTheme("YouTubeVideo", defaultTheme, theme);
|
|
39
|
+
const srcParts = src.split("?");
|
|
41
40
|
let [url] = srcParts;
|
|
42
41
|
const [, queryString] = srcParts;
|
|
43
42
|
const query = queryString ? qs.parse(queryString) : {};
|
|
44
43
|
const videoId = query.v ?? url?.match(/\/([a-zA-Z0-9-_]*)$/)?.[1];
|
|
45
44
|
url = `https://www.youtube.com/embed/${videoId}`;
|
|
46
45
|
delete query.v;
|
|
47
|
-
query.autoplay = autoplay ?
|
|
48
|
-
url += `?${qs.stringify(query)}`;
|
|
49
|
-
|
|
50
|
-
// TODO: https://developers.google.com/youtube/player_parameters
|
|
46
|
+
query.autoplay = autoplay ? "1" : "0";
|
|
47
|
+
url += `?${qs.stringify(query)}`; // TODO: https://developers.google.com/youtube/player_parameters
|
|
51
48
|
// More query parameters can be exposed via the component props.
|
|
52
|
-
|
|
53
49
|
return /*#__PURE__*/_jsxs("div", {
|
|
54
50
|
className: custom.container,
|
|
55
51
|
children: [/*#__PURE__*/_jsx(Throbber, {
|
|
@@ -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;
|
|
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;AAAA,MAAAC,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAA,MAAAC,aAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAG6B,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA,4BAW5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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
-
|
|
5
|
-
export { MetaTags } from '@dr.pogodin/react-helmet';
|
|
3
|
+
*/export { MetaTags } from "@dr.pogodin/react-helmet";
|
|
6
4
|
export * from "./selectors/index.js";
|
|
7
5
|
export { BaseButton, default as Button } from "./Button/index.js";
|
|
8
6
|
export { default as Checkbox } from "./Checkbox/index.js";
|
|
@@ -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
|
|
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,SAASA,QAAQ,QAAQ,0BAA0B;AAEnD;AAAA,SAESC,UAAU,EAAEC,OAAO,IAAIC,MAAM;AAAA,SAC7BD,OAAO,IAAIE,QAAQ;AAAA,SACnBF,OAAO,IAAIG,KAAK;AAAA,SAChBH,OAAO,IAAII,IAAI;AAAA,SACfC,SAAS,EAAEL,OAAO,IAAIM,KAAK;AAAA,SAC3BN,OAAO,IAAIO,OAAO;AAAA,SAClBP,OAAO,IAAIQ,UAAU;AAAA,SACrBR,OAAO,IAAIS,QAAQ;AAAA,SACnBT,OAAO,IAAIU,WAAW;AAAA,SACtBV,OAAO,IAAIW,YAAY;AAAA,SAEvBX,OAAO,IAAIY,QAAQ","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@ import "core-js/modules/es.iterator.filter.js";
|
|
|
2
2
|
import "core-js/modules/es.array.push.js";
|
|
3
3
|
import "core-js/modules/es.iterator.constructor.js";
|
|
4
4
|
import "core-js/modules/es.iterator.filter.js";
|
|
5
|
-
import { useImperativeHandle, useRef } from
|
|
5
|
+
import { useImperativeHandle, useRef } from "react";
|
|
6
6
|
import { BaseModal } from "../../../Modal/index.js";
|
|
7
7
|
import { optionValueName } from "../../common.js";
|
|
8
8
|
const S = {
|
|
@@ -46,7 +46,7 @@ const Options = ({
|
|
|
46
46
|
e.stopPropagation();
|
|
47
47
|
},
|
|
48
48
|
onKeyDown: e => {
|
|
49
|
-
if (e.key ===
|
|
49
|
+
if (e.key === "Enter") {
|
|
50
50
|
onChange(iValue);
|
|
51
51
|
e.stopPropagation();
|
|
52
52
|
}
|
|
@@ -57,8 +57,7 @@ const Options = ({
|
|
|
57
57
|
}, iValue));
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
return /*#__PURE__*/_jsx(BaseModal
|
|
61
|
-
// Closes the dropdown (cancels the selection) on any page scrolling attempt.
|
|
60
|
+
return /*#__PURE__*/_jsx(BaseModal // Closes the dropdown (cancels the selection) on any page scrolling attempt.
|
|
62
61
|
// This is the same native <select> elements do on scrolling, and at least for
|
|
63
62
|
// now we have no reason to deal with complications needed to support open
|
|
64
63
|
// dropdowns during the scrolling (that would need to re-position it in
|
|
@@ -69,10 +68,10 @@ const Options = ({
|
|
|
69
68
|
onCancel: onCancel,
|
|
70
69
|
style: containerStyle,
|
|
71
70
|
theme: {
|
|
72
|
-
ad:
|
|
71
|
+
ad: "",
|
|
73
72
|
container: containerClass,
|
|
74
|
-
context:
|
|
75
|
-
hoc:
|
|
73
|
+
context: "",
|
|
74
|
+
hoc: "",
|
|
76
75
|
overlay: S.overlay
|
|
77
76
|
},
|
|
78
77
|
children: /*#__PURE__*/_jsx("div", {
|