@dr.pogodin/react-utils 1.46.2 → 1.47.0-alpha.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.
- package/babel.config.js +1 -0
- package/babel.libweb.config.js +16 -0
- package/bin/build.js +16 -10
- package/bin/setup.js +11 -8
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +7 -1
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +13 -8
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +15 -8
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +7 -5
- package/build/development/server/server.js.map +1 -1
- package/build/development/shared/components/Button/index.js +6 -6
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +8 -8
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +5 -1
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +10 -9
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +8 -6
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +6 -6
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +13 -9
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +6 -6
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +1 -0
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +7 -7
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +9 -9
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +11 -11
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +12 -12
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +7 -7
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +14 -10
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +1 -0
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.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/client/init.js.map +1 -1
- package/build/production/index.js +4 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +5 -5
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +7 -7
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +4 -4
- package/build/production/server/server.js.map +1 -1
- package/build/production/shared/components/Button/index.js +1 -1
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +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 +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 +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 +1 -1
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +1 -1
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +1 -1
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +1 -1
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +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 +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js +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/globalState.js.map +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +8 -7
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/web/client/getInj.js +54 -0
- package/build/web/client/getInj.js.map +1 -0
- package/build/web/client/index.js +38 -0
- package/build/web/client/index.js.map +1 -0
- package/build/web/client/init.js +49 -0
- package/build/web/client/init.js.map +1 -0
- package/build/web/index.js +25 -0
- package/build/web/index.js.map +1 -0
- package/build/web/server/Cache.js +54 -0
- package/build/web/server/Cache.js.map +1 -0
- package/build/web/server/index.js +211 -0
- package/build/web/server/index.js.map +1 -0
- package/build/web/server/renderer.js +516 -0
- package/build/web/server/renderer.js.map +1 -0
- package/build/web/server/server.js +231 -0
- package/build/web/server/server.js.map +1 -0
- package/build/web/server/utils/errors.js +103 -0
- package/build/web/server/utils/errors.js.map +1 -0
- package/build/web/server/utils/index.js +4 -0
- package/build/web/server/utils/index.js.map +1 -0
- package/build/web/shared/components/Button/index.js +90 -0
- package/build/web/shared/components/Button/index.js.map +1 -0
- package/build/web/shared/components/Button/style.scss +54 -0
- package/build/web/shared/components/Checkbox/index.js +35 -0
- package/build/web/shared/components/Checkbox/index.js.map +1 -0
- package/build/web/shared/components/Checkbox/theme.scss +63 -0
- package/build/web/shared/components/GenericLink/index.js +107 -0
- package/build/web/shared/components/GenericLink/index.js.map +1 -0
- package/build/web/shared/components/GenericLink/style.scss +3 -0
- package/build/web/shared/components/Input/index.js +71 -0
- package/build/web/shared/components/Input/index.js.map +1 -0
- package/build/web/shared/components/Input/theme.scss +52 -0
- package/build/web/shared/components/Link.js +20 -0
- package/build/web/shared/components/Link.js.map +1 -0
- package/build/web/shared/components/Modal/base-theme.scss +38 -0
- package/build/web/shared/components/Modal/index.js +128 -0
- package/build/web/shared/components/Modal/index.js.map +1 -0
- package/build/web/shared/components/Modal/styles.scss +3 -0
- package/build/web/shared/components/NavLink.js +13 -0
- package/build/web/shared/components/NavLink.js.map +1 -0
- package/build/web/shared/components/PageLayout/base-theme.scss +30 -0
- package/build/web/shared/components/PageLayout/index.js +38 -0
- package/build/web/shared/components/PageLayout/index.js.map +1 -0
- package/build/web/shared/components/TextArea/index.js +106 -0
- package/build/web/shared/components/TextArea/index.js.map +1 -0
- package/build/web/shared/components/TextArea/style.scss +68 -0
- package/build/web/shared/components/Throbber/index.js +26 -0
- package/build/web/shared/components/Throbber/index.js.map +1 -0
- package/build/web/shared/components/Throbber/theme.scss +26 -0
- package/build/web/shared/components/WithTooltip/Tooltip.js +226 -0
- package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -0
- package/build/web/shared/components/WithTooltip/default-theme.scss +36 -0
- package/build/web/shared/components/WithTooltip/index.js +117 -0
- package/build/web/shared/components/WithTooltip/index.js.map +1 -0
- package/build/web/shared/components/YouTubeVideo/base.scss +15 -0
- package/build/web/shared/components/YouTubeVideo/index.js +56 -0
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -0
- package/build/web/shared/components/YouTubeVideo/throbber.scss +11 -0
- package/build/web/shared/components/index.js +18 -0
- package/build/web/shared/components/index.js.map +1 -0
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +79 -0
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -0
- package/build/web/shared/components/selectors/CustomDropdown/Options/style.scss +6 -0
- package/build/web/shared/components/selectors/CustomDropdown/index.js +120 -0
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -0
- package/build/web/shared/components/selectors/CustomDropdown/theme.scss +118 -0
- package/build/web/shared/components/selectors/NativeDropdown/index.js +82 -0
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -0
- package/build/web/shared/components/selectors/NativeDropdown/theme.scss +81 -0
- package/build/web/shared/components/selectors/Switch/index.js +49 -0
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -0
- package/build/web/shared/components/selectors/Switch/theme.scss +39 -0
- package/build/web/shared/components/selectors/common.js +12 -0
- package/build/web/shared/components/selectors/common.js.map +1 -0
- package/build/web/shared/components/selectors/index.js +4 -0
- package/build/web/shared/components/selectors/index.js.map +1 -0
- package/build/web/shared/utils/config.js +21 -0
- package/build/web/shared/utils/config.js.map +1 -0
- package/build/web/shared/utils/globalState.js +15 -0
- package/build/web/shared/utils/globalState.js.map +1 -0
- package/build/web/shared/utils/index.js +13 -0
- package/build/web/shared/utils/index.js.map +1 -0
- package/build/web/shared/utils/isomorphy/buildInfo.js +44 -0
- package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -0
- package/build/web/shared/utils/isomorphy/environment-check.js +17 -0
- package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -0
- package/build/web/shared/utils/isomorphy/index.js +36 -0
- package/build/web/shared/utils/isomorphy/index.js.map +1 -0
- package/build/web/shared/utils/jest/E2eSsrEnv.js +230 -0
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -0
- package/build/web/shared/utils/jest/global.js +4 -0
- package/build/web/shared/utils/jest/global.js.map +1 -0
- package/build/web/shared/utils/jest/index.js +165 -0
- package/build/web/shared/utils/jest/index.js.map +1 -0
- package/build/web/shared/utils/splitComponent.js +221 -0
- package/build/web/shared/utils/splitComponent.js.map +1 -0
- package/build/web/shared/utils/time.js +85 -0
- package/build/web/shared/utils/time.js.map +1 -0
- package/build/web/shared/utils/webpack.js +61 -0
- package/build/web/shared/utils/webpack.js.map +1 -0
- package/build/web/styles/_global/reset.css +52 -0
- package/build/web/styles/_mixins/fonts.scss +40 -0
- package/build/web/styles/_mixins/media.scss +150 -0
- package/build/web/styles/_mixins/typography.scss +83 -0
- package/build/web/styles/global.scss +11 -0
- package/build/web/styles/mixins.scss +6 -0
- package/config/babel/node-ssr.js +5 -2
- package/config/webpack/app-base.js +10 -7
- package/config/webpack/app-development.js +3 -2
- package/package.json +16 -27
- package/src/index.ts +7 -1
- package/src/server/index.ts +6 -8
- package/src/server/renderer.tsx +7 -9
- package/src/server/server.ts +3 -5
- package/src/shared/components/Modal/base-theme.scss +1 -1
- package/src/shared/components/PageLayout/base-theme.scss +1 -1
- package/src/shared/utils/jest/E2eSsrEnv.ts +8 -1
- package/build/development/__chunk_groups__.json +0 -6
- package/build/development/style.css +0 -909
- package/build/development/web.bundle.js +0 -752
- package/build/production/__chunk_groups__.json +0 -6
- package/build/production/style.css +0 -2
- package/build/production/style.css.map +0 -1
- package/build/production/web.bundle.js +0 -3
- package/build/production/web.bundle.js.LICENSE.txt +0 -9
- package/build/production/web.bundle.js.map +0 -1
- package/dev-styles.js +0 -1
- package/null.js +0 -1
- package/prod-styles.js +0 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
*,
|
|
2
|
+
.context,
|
|
3
|
+
.ad.hoc {
|
|
4
|
+
&.dropdown {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex: 1;
|
|
7
|
+
min-width: 5.5em;
|
|
8
|
+
overflow: hidden;
|
|
9
|
+
position: relative;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
&.arrow {
|
|
13
|
+
background-image: linear-gradient(to top, lightgray, white 50%, white);
|
|
14
|
+
border: 1px solid gray;
|
|
15
|
+
border-radius: 0 0.3em 0.3em 0;
|
|
16
|
+
bottom: 0;
|
|
17
|
+
padding: 0.3em 0.6em;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
position: absolute;
|
|
20
|
+
right: 0;
|
|
21
|
+
top: 0;
|
|
22
|
+
|
|
23
|
+
&::after {
|
|
24
|
+
content: '▼';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&.container {
|
|
29
|
+
align-items: center;
|
|
30
|
+
display: inline-flex;
|
|
31
|
+
margin: 0.1em;
|
|
32
|
+
position: relative;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.active + &.arrow,
|
|
36
|
+
:active + &.arrow {
|
|
37
|
+
background-image: linear-gradient(to bottom, lightgray, white 50%, white);
|
|
38
|
+
border-bottom-right-radius: 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
:focus + &.arrow {
|
|
42
|
+
border-color: blue;
|
|
43
|
+
border-left-color: gray;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
&.label {
|
|
47
|
+
margin: 0 0.6em 0 1.5em;
|
|
48
|
+
pointer-events: none;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&.option { color: black; }
|
|
52
|
+
&.hiddenOption { display: none; }
|
|
53
|
+
|
|
54
|
+
&.select {
|
|
55
|
+
appearance: none;
|
|
56
|
+
background: white;
|
|
57
|
+
border: 1px solid gray;
|
|
58
|
+
border-radius: 0.3em;
|
|
59
|
+
color: inherit;
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
display: inline-block;
|
|
62
|
+
flex: 1;
|
|
63
|
+
font: inherit;
|
|
64
|
+
max-width: 100%;
|
|
65
|
+
outline: none;
|
|
66
|
+
padding: 0.3em 3.3em calc(0.3em + 1px) 1.2em;
|
|
67
|
+
|
|
68
|
+
&:active {
|
|
69
|
+
background: white;
|
|
70
|
+
border-bottom-left-radius: 0;
|
|
71
|
+
border-bottom-right-radius: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&:focus {
|
|
75
|
+
border-color: blue;
|
|
76
|
+
box-shadow: 0 0 3px 1px lightblue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&.invalid { color: gray; }
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import themed from '@dr.pogodin/react-themes';
|
|
2
|
+
import { optionValueName } from "../common";
|
|
3
|
+
import defaultTheme from "./theme.scss";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
const BaseSwitch = ({
|
|
6
|
+
label,
|
|
7
|
+
onChange,
|
|
8
|
+
options,
|
|
9
|
+
theme,
|
|
10
|
+
value
|
|
11
|
+
}) => {
|
|
12
|
+
if (!options || !theme.option) throw Error('Internal error');
|
|
13
|
+
const optionNodes = [];
|
|
14
|
+
for (const option of options) {
|
|
15
|
+
const [iValue, iName] = optionValueName(option);
|
|
16
|
+
let className = theme.option;
|
|
17
|
+
let onPress;
|
|
18
|
+
if (iValue === value) className += ` ${theme.selected}`;else if (onChange) {
|
|
19
|
+
onPress = () => {
|
|
20
|
+
onChange(iValue);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
optionNodes.push(onPress ? /*#__PURE__*/_jsx("div", {
|
|
24
|
+
className: className,
|
|
25
|
+
onClick: onPress,
|
|
26
|
+
onKeyDown: e => {
|
|
27
|
+
if (e.key === 'Enter') onPress();
|
|
28
|
+
},
|
|
29
|
+
role: "button",
|
|
30
|
+
tabIndex: 0,
|
|
31
|
+
children: iName
|
|
32
|
+
}, iValue) : /*#__PURE__*/_jsx("div", {
|
|
33
|
+
className: className,
|
|
34
|
+
children: iName
|
|
35
|
+
}, iValue));
|
|
36
|
+
}
|
|
37
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
38
|
+
className: theme.container,
|
|
39
|
+
children: [label ? /*#__PURE__*/_jsx("div", {
|
|
40
|
+
className: theme.label,
|
|
41
|
+
children: label
|
|
42
|
+
}) : null, /*#__PURE__*/_jsx("div", {
|
|
43
|
+
className: theme.options,
|
|
44
|
+
children: optionNodes
|
|
45
|
+
})]
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
export default themed(BaseSwitch, 'Switch', defaultTheme);
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["themed","optionValueName","defaultTheme","jsx","_jsx","jsxs","_jsxs","BaseSwitch","label","onChange","options","theme","value","option","Error","optionNodes","iValue","iName","className","onPress","selected","push","onClick","onKeyDown","e","key","role","tabIndex","children","container"],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import themed, { type Theme } from '@dr.pogodin/react-themes';\n\nimport {\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../common';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeKeyT = 'container' | 'label' | 'option' | 'options' | 'selected';\n\ntype PropsT = {\n label?: React.ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<React.ReactNode>>;\n theme: Theme<ThemeKeyT>;\n value?: ValueT;\n};\n\nconst BaseSwitch: React.FunctionComponent<PropsT> = ({\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n if (!options || !theme.option) throw Error('Internal error');\n\n const optionNodes: React.ReactNode[] = [];\n for (const option of options) {\n const [iValue, iName] = optionValueName(option);\n\n let className: string = theme.option;\n let onPress: (() => void) | undefined;\n if (iValue === value) className += ` ${theme.selected}`;\n else if (onChange) {\n onPress = () => {\n onChange(iValue);\n };\n }\n\n optionNodes.push(\n onPress\n ? (\n <div\n className={className}\n key={iValue}\n onClick={onPress}\n onKeyDown={(e) => {\n if (e.key === 'Enter') onPress();\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>\n )\n : <div className={className} key={iValue}>{iName}</div>,\n );\n }\n\n return (\n <div className={theme.container}>\n {label ? <div className={theme.label}>{label}</div> : null}\n\n <div className={theme.options}>\n {optionNodes}\n </div>\n </div>\n );\n};\n\nexport default themed(BaseSwitch, 'Switch', defaultTheme);\n"],"mappings":"AAAA,OAAOA,MAAM,MAAsB,0BAA0B;AAE7D,SAGEC,eAAe;AAGjB,OAAOC,YAAY;AAAqB,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAYxC,MAAMC,UAA2C,GAAGA,CAAC;EACnDC,KAAK;EACLC,QAAQ;EACRC,OAAO;EACPC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,IAAI,CAACF,OAAO,IAAI,CAACC,KAAK,CAACE,MAAM,EAAE,MAAMC,KAAK,CAAC,gBAAgB,CAAC;EAE5D,MAAMC,WAA8B,GAAG,EAAE;EACzC,KAAK,MAAMF,MAAM,IAAIH,OAAO,EAAE;IAC5B,MAAM,CAACM,MAAM,EAAEC,KAAK,CAAC,GAAGhB,eAAe,CAACY,MAAM,CAAC;IAE/C,IAAIK,SAAiB,GAAGP,KAAK,CAACE,MAAM;IACpC,IAAIM,OAAiC;IACrC,IAAIH,MAAM,KAAKJ,KAAK,EAAEM,SAAS,IAAI,IAAIP,KAAK,CAACS,QAAQ,EAAE,CAAC,KACnD,IAAIX,QAAQ,EAAE;MACjBU,OAAO,GAAGA,CAAA,KAAM;QACdV,QAAQ,CAACO,MAAM,CAAC;MAClB,CAAC;IACH;IAEAD,WAAW,CAACM,IAAI,CACdF,OAAO,gBAEHf,IAAA;MACEc,SAAS,EAAEA,SAAU;MAErBI,OAAO,EAAEH,OAAQ;MACjBI,SAAS,EAAGC,CAAC,IAAK;QAChB,IAAIA,CAAC,CAACC,GAAG,KAAK,OAAO,EAAEN,OAAO,CAAC,CAAC;MAClC,CAAE;MACFO,IAAI,EAAC,QAAQ;MACbC,QAAQ,EAAE,CAAE;MAAAC,QAAA,EAEXX;IAAK,GARDD,MASF,CAAC,gBAENZ,IAAA;MAAKc,SAAS,EAAEA,SAAU;MAAAU,QAAA,EAAeX;IAAK,GAAdD,MAAoB,CAC1D,CAAC;EACH;EAEA,oBACEV,KAAA;IAAKY,SAAS,EAAEP,KAAK,CAACkB,SAAU;IAAAD,QAAA,GAC7BpB,KAAK,gBAAGJ,IAAA;MAAKc,SAAS,EAAEP,KAAK,CAACH,KAAM;MAAAoB,QAAA,EAAEpB;IAAK,CAAM,CAAC,GAAG,IAAI,eAE1DJ,IAAA;MAAKc,SAAS,EAAEP,KAAK,CAACD,OAAQ;MAAAkB,QAAA,EAC3Bb;IAAW,CACT,CAAC;EAAA,CACH,CAAC;AAEV,CAAC;AAED,eAAef,MAAM,CAACO,UAAU,EAAE,QAAQ,EAAEL,YAAY,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
*,
|
|
2
|
+
.context,
|
|
3
|
+
.ad.hoc {
|
|
4
|
+
&.container {
|
|
5
|
+
align-items: center;
|
|
6
|
+
display: flex;
|
|
7
|
+
gap: 0.6em;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&.option {
|
|
11
|
+
border: 1px solid transparent;
|
|
12
|
+
border-radius: 0.3em;
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
outline: none;
|
|
15
|
+
padding: 0 0.9em;
|
|
16
|
+
|
|
17
|
+
&:focus {
|
|
18
|
+
border-color: blue;
|
|
19
|
+
box-shadow: 0 0 3px 1px lightblue;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&.selected {
|
|
24
|
+
border: 1px solid gray;
|
|
25
|
+
background: white;
|
|
26
|
+
cursor: default;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&.options {
|
|
30
|
+
align-items: center;
|
|
31
|
+
background: whitesmoke;
|
|
32
|
+
border: 1px solid gray;
|
|
33
|
+
border-radius: 0.3em;
|
|
34
|
+
display: flex;
|
|
35
|
+
gap: 0.3em;
|
|
36
|
+
padding: 0.3em;
|
|
37
|
+
user-select: none;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The stuff common between different dropdown implementations.
|
|
2
|
+
|
|
3
|
+
function isValue(x) {
|
|
4
|
+
const type = typeof x;
|
|
5
|
+
return type === 'number' || type === 'string';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Returns option value and name as a tuple. */
|
|
9
|
+
export function optionValueName(option) {
|
|
10
|
+
return isValue(option) ? [option, option] : [option.value, option.name ?? option.value];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","names":["isValue","x","type","optionValueName","option","value","name"],"sources":["../../../../../src/shared/components/selectors/common.ts"],"sourcesContent":["// The stuff common between different dropdown implementations.\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\ntype ThemeKeyT = 'active'\n | 'arrow'\n | 'container'\n | 'dropdown'\n | 'hiddenOption'\n | 'label'\n | 'option'\n | 'select'\n\n // TODO: This is currently only valid for (native) <Dropdown>,\n // other kinds of selectors should be evaluated, and aligned with this\n // feature, if appropriate.\n | 'invalid'\n\n // TODO: This is only valid for <CustomDropdown>, thus we need to re-factor it\n // into a separate theme spec for that component.\n | 'upward';\n\nexport type ValueT = number | string;\n\nexport type OptionT<NameT> = {\n name?: NameT | null;\n value: ValueT;\n};\n\nexport type OptionsT<NameT> = Readonly<Array<OptionT<NameT> | ValueT>>;\n\nexport type PropsT<\n NameT,\n OnChangeT = React.ChangeEventHandler<HTMLSelectElement>,\n> = {\n filter?: (item: OptionT<NameT> | ValueT) => boolean;\n label?: React.ReactNode;\n onChange?: OnChangeT;\n options: Readonly<OptionsT<NameT>>;\n testId?: string;\n theme: Theme<ThemeKeyT>;\n value?: ValueT;\n};\n\nfunction isValue<T>(x: OptionT<T> | ValueT): x is ValueT {\n const type = typeof x;\n return type === 'number' || type === 'string';\n}\n\n/** Returns option value and name as a tuple. */\nexport function optionValueName<NameT>(\n option: OptionT<NameT> | ValueT,\n): [ValueT, NameT | ValueT] {\n return isValue(option)\n ? [option, option]\n : [option.value, option.name ?? option.value];\n}\n"],"mappings":"AAAA;;AA4CA,SAASA,OAAOA,CAAIC,CAAsB,EAAe;EACvD,MAAMC,IAAI,GAAG,OAAOD,CAAC;EACrB,OAAOC,IAAI,KAAK,QAAQ,IAAIA,IAAI,KAAK,QAAQ;AAC/C;;AAEA;AACA,OAAO,SAASC,eAAeA,CAC7BC,MAA+B,EACL;EAC1B,OAAOJ,OAAO,CAACI,MAAM,CAAC,GAClB,CAACA,MAAM,EAAEA,MAAM,CAAC,GAChB,CAACA,MAAM,CAACC,KAAK,EAAED,MAAM,CAACE,IAAI,IAAIF,MAAM,CAACC,KAAK,CAAC;AACjD","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","CustomDropdown","Dropdown","Switch"],"sources":["../../../../../src/shared/components/selectors/index.ts"],"sourcesContent":["export { default as CustomDropdown } from './CustomDropdown';\nexport { default as Dropdown } from './NativeDropdown';\nexport { default as Switch } from './Switch';\n\nexport {\n type OptionT,\n type OptionsT,\n} from './common';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,cAAc;AAClC,SAASD,OAAO,IAAIE,QAAQ;AAC5B,SAASF,OAAO,IAAIG,MAAM","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* global document */
|
|
2
|
+
|
|
3
|
+
import { IS_CLIENT_SIDE } from "./isomorphy/environment-check";
|
|
4
|
+
import { requireWeak } from "./webpack";
|
|
5
|
+
|
|
6
|
+
// TODO: The internal type casting is somewhat messed up here,
|
|
7
|
+
// to be corrected later.
|
|
8
|
+
const config = (IS_CLIENT_SIDE
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
10
|
+
? require("../../client/getInj").default().CONFIG : requireWeak('config')) ?? {};
|
|
11
|
+
|
|
12
|
+
// The safeguard for "document" is necessary because in non-Node environments,
|
|
13
|
+
// like React Native, IS_CLIENT_SIDE is "true", however "document" and a bunch
|
|
14
|
+
// of other browser-world features are not available.
|
|
15
|
+
if (IS_CLIENT_SIDE && typeof document !== 'undefined') {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
17
|
+
const cookie = require('cookie');
|
|
18
|
+
config.CSRF = cookie.parse(document.cookie).csrfToken;
|
|
19
|
+
}
|
|
20
|
+
export default config;
|
|
21
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","names":["IS_CLIENT_SIDE","requireWeak","config","require","default","CONFIG","document","cookie","CSRF","parse","csrfToken"],"sources":["../../../../src/shared/utils/config.ts"],"sourcesContent":["/* global document */\n\nimport type CookieM from 'cookie';\n\nimport { IS_CLIENT_SIDE } from './isomorphy/environment-check';\nimport { requireWeak } from './webpack';\n\n// TODO: The internal type casting is somewhat messed up here,\n// to be corrected later.\nconst config: Record<string, unknown> = (\n IS_CLIENT_SIDE\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n ? (require('client/getInj') as {\n default: () => Record<string, unknown>;\n }).default().CONFIG\n : requireWeak('config')\n) as (Record<string, unknown> | undefined) ?? ({} as Record<string, unknown>);\n\n// The safeguard for \"document\" is necessary because in non-Node environments,\n// like React Native, IS_CLIENT_SIDE is \"true\", however \"document\" and a bunch\n// of other browser-world features are not available.\nif (IS_CLIENT_SIDE && typeof document !== 'undefined') {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const cookie = require('cookie') as typeof CookieM;\n config.CSRF = cookie.parse(document.cookie).csrfToken;\n}\n\nexport default config;\n"],"mappings":"AAAA;;AAIA,SAASA,cAAc;AACvB,SAASC,WAAW;;AAEpB;AACA;AACA,MAAMC,MAA+B,GAAG,CACtCF;AACE;AAAA,EACGG,OAAO,sBAAgB,CAAC,CAExBC,OAAO,CAAC,CAAC,CAACC,MAAM,GACjBJ,WAAW,CAAC,QAAQ,CAAC,KACoB,CAAC,CAA6B;;AAE7E;AACA;AACA;AACA,IAAID,cAAc,IAAI,OAAOM,QAAQ,KAAK,WAAW,EAAE;EACrD;EACA,MAAMC,MAAM,GAAGJ,OAAO,CAAC,QAAQ,CAAmB;EAClDD,MAAM,CAACM,IAAI,GAAGD,MAAM,CAACE,KAAK,CAACH,QAAQ,CAACC,MAAM,CAAC,CAACG,SAAS;AACvD;AAEA,eAAeR,MAAM","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { withGlobalStateType } from '@dr.pogodin/react-global-state';
|
|
2
|
+
|
|
3
|
+
/** Mapping "chunkName" > array of asset paths. */
|
|
4
|
+
|
|
5
|
+
// The type of data object injected by server into generated markup.
|
|
6
|
+
|
|
7
|
+
// TODO: Not 100% sure now, whether it indeed can be replaced by type,
|
|
8
|
+
// or do we really need it to be an interface. Keeping the interface for now.
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
getSsrContext
|
|
13
|
+
} = withGlobalStateType();
|
|
14
|
+
export { getSsrContext };
|
|
15
|
+
//# sourceMappingURL=globalState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globalState.js","names":["withGlobalStateType","getSsrContext"],"sources":["../../../../src/shared/utils/globalState.ts"],"sourcesContent":["import type { Request } from 'express';\n\nimport { type SsrContext, withGlobalStateType } from '@dr.pogodin/react-global-state';\n\n/** Mapping \"chunkName\" > array of asset paths. */\nexport type ChunkGroupsT = Record<string, string[]>;\n\n// The type of data object injected by server into generated markup.\nexport type InjT = {\n CHUNK_GROUPS?: ChunkGroupsT;\n CONFIG?: Record<string, unknown>;\n ISTATE?: unknown;\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n REACT_UTILS_INJECTION?: InjT;\n }\n}\n\n// TODO: Not 100% sure now, whether it indeed can be replaced by type,\n// or do we really need it to be an interface. Keeping the interface for now.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface SsrContextT<StateT> extends SsrContext<StateT> {\n chunkGroups: ChunkGroupsT;\n chunks: string[];\n\n /** If set at the end of SSR, the rendered will trigger\n * server-side redirect to this URL (and use the status\n * code). */\n redirectTo?: string;\n\n req: Request;\n status: number;\n}\n\nconst {\n getSsrContext,\n} = withGlobalStateType<unknown, SsrContextT<unknown>>();\n\nexport {\n getSsrContext,\n};\n"],"mappings":"AAEA,SAA0BA,mBAAmB,QAAQ,gCAAgC;;AAErF;;AAGA;;AAcA;AACA;AACA;;AAcA,MAAM;EACJC;AACF,CAAC,GAAGD,mBAAmB,CAAgC,CAAC;AAExD,SACEC,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import themedImpl, { COMPOSE, PRIORITY, ThemeProvider } from '@dr.pogodin/react-themes';
|
|
2
|
+
import config from "./config";
|
|
3
|
+
import * as isomorphy from "./isomorphy";
|
|
4
|
+
import time from "./time";
|
|
5
|
+
import * as webpack from "./webpack";
|
|
6
|
+
export { assertEmptyObject, Barrier, Cached, Emitter, Semaphore, withRetries } from '@dr.pogodin/js-utils';
|
|
7
|
+
export { getSsrContext } from "./globalState";
|
|
8
|
+
export { default as splitComponent } from "./splitComponent";
|
|
9
|
+
const themed = themedImpl;
|
|
10
|
+
themed.COMPOSE = COMPOSE;
|
|
11
|
+
themed.PRIORITY = PRIORITY;
|
|
12
|
+
export { config, isomorphy, themed, ThemeProvider, time, webpack };
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["themedImpl","COMPOSE","PRIORITY","ThemeProvider","config","isomorphy","time","webpack","assertEmptyObject","Barrier","Cached","Emitter","Semaphore","withRetries","getSsrContext","default","splitComponent","themed"],"sources":["../../../../src/shared/utils/index.ts"],"sourcesContent":["import themedImpl, {\n COMPOSE,\n PRIORITY,\n type Theme,\n ThemeProvider,\n} from '@dr.pogodin/react-themes';\n\nimport config from './config';\nimport * as isomorphy from './isomorphy';\nimport time from './time';\nimport * as webpack from './webpack';\n\nexport {\n assertEmptyObject,\n type Listener,\n type ObjectKey,\n Barrier,\n Cached,\n Emitter,\n Semaphore,\n withRetries,\n} from '@dr.pogodin/js-utils';\n\nexport { getSsrContext } from './globalState';\nexport { default as splitComponent } from './splitComponent';\n\ntype ThemedT = typeof themedImpl & {\n COMPOSE: typeof COMPOSE;\n PRIORITY: typeof PRIORITY;\n};\n\nconst themed: ThemedT = themedImpl as ThemedT;\n\nthemed.COMPOSE = COMPOSE;\nthemed.PRIORITY = PRIORITY;\n\nexport {\n type Theme,\n config,\n isomorphy,\n themed,\n ThemeProvider,\n time,\n webpack,\n};\n"],"mappings":"AAAA,OAAOA,UAAU,IACfC,OAAO,EACPC,QAAQ,EAERC,aAAa,QACR,0BAA0B;AAEjC,OAAOC,MAAM;AACb,OAAO,KAAKC,SAAS;AACrB,OAAOC,IAAI;AACX,OAAO,KAAKC,OAAO;AAEnB,SACEC,iBAAiB,EAGjBC,OAAO,EACPC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,WAAW,QACN,sBAAsB;AAE7B,SAASC,aAAa;AACtB,SAASC,OAAO,IAAIC,cAAc;AAOlC,MAAMC,MAAe,GAAGjB,UAAqB;AAE7CiB,MAAM,CAAChB,OAAO,GAAGA,OAAO;AACxBgB,MAAM,CAACf,QAAQ,GAAGA,QAAQ;AAE1B,SAEEE,MAAM,EACNC,SAAS,EACTY,MAAM,EACNd,aAAa,EACbG,IAAI,EACJC,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Encapsulates access to "Build Info" data.
|
|
2
|
+
|
|
3
|
+
// BEWARE: This should match the type of build info object generated by
|
|
4
|
+
// Webpack build (see "/config/webpack/app-base.js"), and currently this
|
|
5
|
+
// match is not checked automatically.
|
|
6
|
+
|
|
7
|
+
// Depending on the build mode & environment, BUILD_INFO is either a global
|
|
8
|
+
// variable defined at the app launch, or it is replaced by the actual value
|
|
9
|
+
// by the Webpack build.
|
|
10
|
+
|
|
11
|
+
let buildInfo;
|
|
12
|
+
|
|
13
|
+
// On the client side "BUILD_INFO" should be injected by Webpack. Note, however,
|
|
14
|
+
// that in test environment we may need situations were environment is mocked as
|
|
15
|
+
// client-side, although no proper Webpack compilation is executed, thus no info
|
|
16
|
+
// injected; because of this we don't do a hard environment check here.
|
|
17
|
+
if (typeof BUILD_INFO !== 'undefined') buildInfo = BUILD_INFO;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* In scenarious where "BUILD_INFO" is not injected by Webpack (server-side,
|
|
21
|
+
* tests, etc.) we expect the host codebase to explicitly set it before it is
|
|
22
|
+
* ever requested. As a precaution, this function throws if build info has been
|
|
23
|
+
* set already, unless `force` flag is explicitly set.
|
|
24
|
+
* @param info
|
|
25
|
+
* @param force
|
|
26
|
+
*/
|
|
27
|
+
export function setBuildInfo(info, force = false) {
|
|
28
|
+
if (buildInfo !== undefined && !force) {
|
|
29
|
+
throw Error('"Build Info" is already initialized');
|
|
30
|
+
}
|
|
31
|
+
buildInfo = info;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Returns "Build Info" object; throws if it has not been initialized yet.
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export function getBuildInfo() {
|
|
39
|
+
if (buildInfo === undefined) {
|
|
40
|
+
throw Error('"Build Info" has not been initialized yet');
|
|
41
|
+
}
|
|
42
|
+
return buildInfo;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=buildInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildInfo.js","names":["buildInfo","BUILD_INFO","setBuildInfo","info","force","undefined","Error","getBuildInfo"],"sources":["../../../../../src/shared/utils/isomorphy/buildInfo.ts"],"sourcesContent":["// Encapsulates access to \"Build Info\" data.\n\n// BEWARE: This should match the type of build info object generated by\n// Webpack build (see \"/config/webpack/app-base.js\"), and currently this\n// match is not checked automatically.\nexport type BuildInfoT = {\n key: string;\n publicPath: string;\n timestamp: string;\n useServiceWorker: boolean;\n};\n\n// Depending on the build mode & environment, BUILD_INFO is either a global\n// variable defined at the app launch, or it is replaced by the actual value\n// by the Webpack build.\ndeclare const BUILD_INFO: BuildInfoT | undefined;\n\nlet buildInfo: BuildInfoT | undefined;\n\n// On the client side \"BUILD_INFO\" should be injected by Webpack. Note, however,\n// that in test environment we may need situations were environment is mocked as\n// client-side, although no proper Webpack compilation is executed, thus no info\n// injected; because of this we don't do a hard environment check here.\nif (typeof BUILD_INFO !== 'undefined') buildInfo = BUILD_INFO;\n\n/**\n * In scenarious where \"BUILD_INFO\" is not injected by Webpack (server-side,\n * tests, etc.) we expect the host codebase to explicitly set it before it is\n * ever requested. As a precaution, this function throws if build info has been\n * set already, unless `force` flag is explicitly set.\n * @param info\n * @param force\n */\nexport function setBuildInfo(info?: BuildInfoT, force = false): void {\n if (buildInfo !== undefined && !force) {\n throw Error('\"Build Info\" is already initialized');\n }\n buildInfo = info;\n}\n\n/**\n * Returns \"Build Info\" object; throws if it has not been initialized yet.\n * @returns\n */\nexport function getBuildInfo(): BuildInfoT {\n if (buildInfo === undefined) {\n throw Error('\"Build Info\" has not been initialized yet');\n }\n return buildInfo;\n}\n"],"mappings":"AAAA;;AAEA;AACA;AACA;;AAQA;AACA;AACA;;AAGA,IAAIA,SAAiC;;AAErC;AACA;AACA;AACA;AACA,IAAI,OAAOC,UAAU,KAAK,WAAW,EAAED,SAAS,GAAGC,UAAU;;AAE7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAACC,IAAiB,EAAEC,KAAK,GAAG,KAAK,EAAQ;EACnE,IAAIJ,SAAS,KAAKK,SAAS,IAAI,CAACD,KAAK,EAAE;IACrC,MAAME,KAAK,CAAC,qCAAqC,CAAC;EACpD;EACAN,SAAS,GAAGG,IAAI;AAClB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASI,YAAYA,CAAA,EAAe;EACzC,IAAIP,SAAS,KAAKK,SAAS,EAAE;IAC3B,MAAMC,KAAK,CAAC,2CAA2C,CAAC;EAC1D;EACA,OAAON,SAAS;AAClB","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Checks for client- vs. server-side environment detection.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `true` within client-side environment (browser), `false` at server-side.
|
|
5
|
+
*/
|
|
6
|
+
export const IS_CLIENT_SIDE = typeof process !== 'object'
|
|
7
|
+
// NOTE: Because in this case we assume the host environment might be partially
|
|
8
|
+
// polyfilled to emulate some Node interfaces, thus it might have global `process`
|
|
9
|
+
// object, but without `versions` sub-object inside it.
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
11
|
+
|| !process.versions?.node || !!global.REACT_UTILS_FORCE_CLIENT_SIDE || typeof REACT_UTILS_WEBPACK_BUNDLE !== 'undefined';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `true` within the server-side environment (node), `false` at client-side.
|
|
15
|
+
*/
|
|
16
|
+
export const IS_SERVER_SIDE = !IS_CLIENT_SIDE;
|
|
17
|
+
//# sourceMappingURL=environment-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-check.js","names":["IS_CLIENT_SIDE","process","versions","node","global","REACT_UTILS_FORCE_CLIENT_SIDE","REACT_UTILS_WEBPACK_BUNDLE","IS_SERVER_SIDE"],"sources":["../../../../../src/shared/utils/isomorphy/environment-check.ts"],"sourcesContent":["// Checks for client- vs. server-side environment detection.\n\n/**\n * `true` within client-side environment (browser), `false` at server-side.\n */\nexport const IS_CLIENT_SIDE: boolean = typeof process !== 'object'\n // NOTE: Because in this case we assume the host environment might be partially\n // polyfilled to emulate some Node interfaces, thus it might have global `process`\n // object, but without `versions` sub-object inside it.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n || !process.versions?.node\n || !!global.REACT_UTILS_FORCE_CLIENT_SIDE\n || typeof REACT_UTILS_WEBPACK_BUNDLE !== 'undefined';\n\n/**\n * `true` within the server-side environment (node), `false` at client-side.\n */\nexport const IS_SERVER_SIDE: boolean = !IS_CLIENT_SIDE;\n"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,cAAuB,GAAG,OAAOC,OAAO,KAAK;AACxD;AACA;AACA;AACA;AAAA,GACG,CAACA,OAAO,CAACC,QAAQ,EAAEC,IAAI,IACvB,CAAC,CAACC,MAAM,CAACC,6BAA6B,IACtC,OAAOC,0BAA0B,KAAK,WAAW;;AAEtD;AACA;AACA;AACA,OAAO,MAAMC,cAAuB,GAAG,CAACP,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getBuildInfo } from "./buildInfo";
|
|
2
|
+
import { IS_CLIENT_SIDE, IS_SERVER_SIDE } from "./environment-check";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
* @return {string} Code mode: "development" or "production".
|
|
7
|
+
*/
|
|
8
|
+
function getMode() {
|
|
9
|
+
return process.env.NODE_ENV;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns `true` if development version of the code is running;
|
|
14
|
+
* `false` otherwise.
|
|
15
|
+
*/
|
|
16
|
+
export function isDevBuild() {
|
|
17
|
+
return getMode() === 'development';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Returns `true` if production build of the code is running;
|
|
22
|
+
* `false` otherwise.
|
|
23
|
+
*/
|
|
24
|
+
export function isProdBuild() {
|
|
25
|
+
return getMode() === 'production';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns build timestamp of the front-end JS bundle.
|
|
30
|
+
* @return ISO date/time string.
|
|
31
|
+
*/
|
|
32
|
+
export function buildTimestamp() {
|
|
33
|
+
return getBuildInfo().timestamp;
|
|
34
|
+
}
|
|
35
|
+
export { IS_CLIENT_SIDE, IS_SERVER_SIDE, getBuildInfo };
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["getBuildInfo","IS_CLIENT_SIDE","IS_SERVER_SIDE","getMode","process","env","NODE_ENV","isDevBuild","isProdBuild","buildTimestamp","timestamp"],"sources":["../../../../../src/shared/utils/isomorphy/index.ts"],"sourcesContent":["import { getBuildInfo } from './buildInfo';\nimport { IS_CLIENT_SIDE, IS_SERVER_SIDE } from './environment-check';\n\n/**\n * @ignore\n * @return {string} Code mode: \"development\" or \"production\".\n */\nfunction getMode() {\n return process.env.NODE_ENV;\n}\n\n/**\n * Returns `true` if development version of the code is running;\n * `false` otherwise.\n */\nexport function isDevBuild(): boolean {\n return getMode() === 'development';\n}\n\n/**\n * Returns `true` if production build of the code is running;\n * `false` otherwise.\n */\nexport function isProdBuild(): boolean {\n return getMode() === 'production';\n}\n\n/**\n * Returns build timestamp of the front-end JS bundle.\n * @return ISO date/time string.\n */\nexport function buildTimestamp(): string {\n return getBuildInfo().timestamp;\n}\n\nexport { IS_CLIENT_SIDE, IS_SERVER_SIDE, getBuildInfo };\n"],"mappings":"AAAA,SAASA,YAAY;AACrB,SAASC,cAAc,EAAEC,cAAc;;AAEvC;AACA;AACA;AACA;AACA,SAASC,OAAOA,CAAA,EAAG;EACjB,OAAOC,OAAO,CAACC,GAAG,CAACC,QAAQ;AAC7B;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAAA,EAAY;EACpC,OAAOJ,OAAO,CAAC,CAAC,KAAK,aAAa;AACpC;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASK,WAAWA,CAAA,EAAY;EACrC,OAAOL,OAAO,CAAC,CAAC,KAAK,YAAY;AACnC;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASM,cAAcA,CAAA,EAAW;EACvC,OAAOT,YAAY,CAAC,CAAC,CAACU,SAAS;AACjC;AAEA,SAAST,cAAc,EAAEC,cAAc,EAAEF,YAAY","ignoreList":[]}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jest environment for end-to-end SSR and client-side testing. It relies on
|
|
3
|
+
* the standard react-utils mechanics to execute SSR of given scene, and also
|
|
4
|
+
* Webpack build of the code for client-side execution, it further exposes
|
|
5
|
+
* Jsdom environment for the client-side testing of the outcomes.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// BEWARE: The module is not imported into the JU module / the main assembly of
|
|
9
|
+
// the library, because doing so easily breaks stuff:
|
|
10
|
+
// 1) This module depends on Node-specific modules, which would make JU
|
|
11
|
+
// incompatible with JsDom if included into JU.
|
|
12
|
+
// 2) If this module is weakly imported from somewhere else in the lib,
|
|
13
|
+
// it seems to randomly break tests using it for a different reason,
|
|
14
|
+
// probably some sort of a require-loop, or some issues with weak
|
|
15
|
+
// require in that scenario.
|
|
16
|
+
|
|
17
|
+
// TODO: We need to add correct typing for environment options.
|
|
18
|
+
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
import defaults from 'lodash/defaults';
|
|
21
|
+
import set from 'lodash/set';
|
|
22
|
+
// As this environment is a part of the Jest testing utils,
|
|
23
|
+
// we assume development dependencies are available when it is used.
|
|
24
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
25
|
+
import register from '@babel/register/experimental-worker';
|
|
26
|
+
import JsdomEnv from 'jest-environment-jsdom';
|
|
27
|
+
import { Volume, createFsFromVolume } from 'memfs';
|
|
28
|
+
import webpack from 'webpack';
|
|
29
|
+
/* eslint-enable import/no-extraneous-dependencies */
|
|
30
|
+
|
|
31
|
+
import ssrFactory from "../../../server/renderer";
|
|
32
|
+
import { setBuildInfo } from "../isomorphy/buildInfo";
|
|
33
|
+
function noop() {
|
|
34
|
+
// NOOP
|
|
35
|
+
}
|
|
36
|
+
export default class E2eSsrEnv extends JsdomEnv {
|
|
37
|
+
/**
|
|
38
|
+
* Loads Webpack config, and exposes it to the environment via global
|
|
39
|
+
* webpackConfig object.
|
|
40
|
+
*/
|
|
41
|
+
loadWebpackConfig() {
|
|
42
|
+
const optionsString = this.pragmas['webpack-config-options'];
|
|
43
|
+
const options = optionsString ? JSON.parse(optionsString) : {};
|
|
44
|
+
defaults(options, {
|
|
45
|
+
context: this.testFolder,
|
|
46
|
+
fs: this.global.webpackOutputFs
|
|
47
|
+
});
|
|
48
|
+
const factoryPath = this.pragmas['webpack-config-factory'];
|
|
49
|
+
// eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-require-imports
|
|
50
|
+
let factory = require(path.resolve(this.rootDir, factoryPath));
|
|
51
|
+
factory = 'default' in factory ? factory.default : factory;
|
|
52
|
+
this.global.webpackConfig = factory(options);
|
|
53
|
+
const fs = this.global.webpackOutputFs;
|
|
54
|
+
let buildInfo = `${options.context}/.build-info`;
|
|
55
|
+
if (fs.existsSync(buildInfo)) {
|
|
56
|
+
buildInfo = fs.readFileSync(buildInfo, 'utf8');
|
|
57
|
+
this.global.buildInfo = JSON.parse(buildInfo);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Executes Webpack build.
|
|
63
|
+
* @return {Promise}
|
|
64
|
+
*/
|
|
65
|
+
async runWebpack() {
|
|
66
|
+
this.loadWebpackConfig();
|
|
67
|
+
if (!this.global.webpackConfig) throw Error('Failed to load Webpack config');
|
|
68
|
+
const compiler = webpack(this.global.webpackConfig);
|
|
69
|
+
if (!compiler) throw Error('Failed to construct Webpack compiler');
|
|
70
|
+
|
|
71
|
+
// TODO: The "as typeof compiler.outputFileSystem" piece below is
|
|
72
|
+
// a workaround for the Webpack regression:
|
|
73
|
+
// https://github.com/webpack/webpack/issues/18242
|
|
74
|
+
compiler.outputFileSystem = this.global.webpackOutputFs;
|
|
75
|
+
return new Promise((done, fail) => {
|
|
76
|
+
compiler.run((err, stats) => {
|
|
77
|
+
if (err) fail(err);
|
|
78
|
+
if (stats?.hasErrors()) {
|
|
79
|
+
// eslint-disable-next-line no-console
|
|
80
|
+
console.error(stats.toJson().errors);
|
|
81
|
+
fail(Error('Webpack compilation failed'));
|
|
82
|
+
}
|
|
83
|
+
this.global.webpackStats = stats?.toJson();
|
|
84
|
+
|
|
85
|
+
// Keeps reference to the raw Webpack stats object, which should be
|
|
86
|
+
// explicitly passed to the server-side renderer alongside the request,
|
|
87
|
+
// so that it can to pick up asset paths for different named chunks.
|
|
88
|
+
this.webpackStats = stats;
|
|
89
|
+
done();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async runSsr() {
|
|
94
|
+
const optionsString = this.pragmas['ssr-options'];
|
|
95
|
+
const options = optionsString ? JSON.parse(optionsString) : {};
|
|
96
|
+
|
|
97
|
+
// TODO: This is temporary to shortcut the logging added to SSR.
|
|
98
|
+
options.logger ??= {
|
|
99
|
+
debug: noop,
|
|
100
|
+
info: noop,
|
|
101
|
+
log: noop,
|
|
102
|
+
warn: noop
|
|
103
|
+
};
|
|
104
|
+
options.buildInfo ??= this.global.buildInfo;
|
|
105
|
+
let cleanup;
|
|
106
|
+
if (options.entry) {
|
|
107
|
+
const p = path.resolve(this.testFolder, options.entry);
|
|
108
|
+
// TODO: This sure can be replaced by a dynamic import().
|
|
109
|
+
// eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-require-imports
|
|
110
|
+
const module = require(p);
|
|
111
|
+
if ('cleanup' in module) cleanup = module.cleanup;
|
|
112
|
+
const exportName = options.entryExportName || 'default';
|
|
113
|
+
if (exportName in module) {
|
|
114
|
+
options.Application = module[exportName];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const renderer = ssrFactory(this.global.webpackConfig, options);
|
|
118
|
+
let status = 200; // OK
|
|
119
|
+
const markup = await new Promise((done, fail) => {
|
|
120
|
+
void renderer(this.ssrRequest,
|
|
121
|
+
// TODO: This will do for now, with the current implementation of
|
|
122
|
+
// the renderer, but it will require a rework once the renderer is
|
|
123
|
+
// updated to do streaming.
|
|
124
|
+
{
|
|
125
|
+
cookie: noop,
|
|
126
|
+
send: done,
|
|
127
|
+
set: noop,
|
|
128
|
+
status: value => {
|
|
129
|
+
status = value;
|
|
130
|
+
},
|
|
131
|
+
// This is how up-to-date Webpack stats are passed to the server in
|
|
132
|
+
// development mode, and we use this here always, instead of having
|
|
133
|
+
// to pass some information via filesystem.
|
|
134
|
+
locals: {
|
|
135
|
+
webpack: {
|
|
136
|
+
devMiddleware: {
|
|
137
|
+
stats: this.webpackStats
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}, error => {
|
|
142
|
+
// TODO: Strictly speaking, that error as Error casting is not all
|
|
143
|
+
// correct, but it works, so no need to spend time on it right now.
|
|
144
|
+
if (error) fail(error);else done('');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
this.global.ssrMarkup = markup;
|
|
148
|
+
this.global.ssrOptions = options;
|
|
149
|
+
this.global.ssrStatus = status;
|
|
150
|
+
if (cleanup) cleanup();
|
|
151
|
+
}
|
|
152
|
+
constructor(config, context) {
|
|
153
|
+
const pragmas = context.docblockPragmas;
|
|
154
|
+
const requestString = pragmas['ssr-request'];
|
|
155
|
+
const request = requestString ? JSON.parse(requestString) : {};
|
|
156
|
+
request.url ??= '/';
|
|
157
|
+
request.csrfToken = noop;
|
|
158
|
+
|
|
159
|
+
// This ensures the initial JsDom URL matches the value we use for SSR.
|
|
160
|
+
set(config.projectConfig, 'testEnvironmentOptions.url', `http://localhost${request.url}`);
|
|
161
|
+
super(config, context);
|
|
162
|
+
this.global.dom = this.dom;
|
|
163
|
+
this.global.webpackOutputFs = createFsFromVolume(new Volume());
|
|
164
|
+
|
|
165
|
+
// Extracts necessary settings from config and context.
|
|
166
|
+
const {
|
|
167
|
+
projectConfig
|
|
168
|
+
} = config;
|
|
169
|
+
this.rootDir = projectConfig.rootDir;
|
|
170
|
+
this.testFolder = path.dirname(context.testPath);
|
|
171
|
+
this.withSsr = !pragmas['no-ssr'];
|
|
172
|
+
this.ssrRequest = request;
|
|
173
|
+
this.pragmas = pragmas;
|
|
174
|
+
|
|
175
|
+
// The usual "babel-jest" transformation setup does not apply to
|
|
176
|
+
// the environment code and imports from it, this workaround enables it.
|
|
177
|
+
const optionsString = this.pragmas['ssr-options'];
|
|
178
|
+
const options = optionsString ? JSON.parse(optionsString) : {};
|
|
179
|
+
let root;
|
|
180
|
+
switch (options.root) {
|
|
181
|
+
case 'TEST':
|
|
182
|
+
root = this.testFolder;
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
root = process.cwd();
|
|
186
|
+
}
|
|
187
|
+
register({
|
|
188
|
+
envName: options.babelEnv,
|
|
189
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],
|
|
190
|
+
root
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
async setup() {
|
|
194
|
+
await super.setup();
|
|
195
|
+
await this.runWebpack();
|
|
196
|
+
|
|
197
|
+
// NOTE: It is possible that the Webpack run above, and the SSR run below
|
|
198
|
+
// load different versions of the same module (CommonJS, and ES), and it may
|
|
199
|
+
// cause very confusing problems (e.g. see:
|
|
200
|
+
// https://github.com/birdofpreyru/react-utils/issues/413).
|
|
201
|
+
// It seems we can't reset the cache of ES modules, and Jest's module reset
|
|
202
|
+
// does not reset modules loaded in this enviroment module, and also only
|
|
203
|
+
// replacing entire cache object by and empty {} seems to help (in contrast
|
|
204
|
+
// to deleting all entries by their keys, as it is done within .teardown()
|
|
205
|
+
// method below). Thus, for now we do this as a hotfix, and we also reset
|
|
206
|
+
// build info to undefined, because ES module version not beeing reset
|
|
207
|
+
// triggers an error on the subsequent test using the environment.
|
|
208
|
+
// TODO: Look for a cleaner solution.
|
|
209
|
+
require.cache = {};
|
|
210
|
+
setBuildInfo(undefined, true);
|
|
211
|
+
if (this.withSsr) await this.runSsr();
|
|
212
|
+
this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;
|
|
213
|
+
}
|
|
214
|
+
async teardown() {
|
|
215
|
+
delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;
|
|
216
|
+
|
|
217
|
+
// Resets module cache and @babel/register. Effectively this ensures that
|
|
218
|
+
// the next time an instance of this environment is set up, all modules are
|
|
219
|
+
// transformed by Babel from scratch, thus taking into account the latest
|
|
220
|
+
// Babel config (which may change between different environment instances,
|
|
221
|
+
// which does not seem to be taken into account by Babel / Node caches
|
|
222
|
+
// automatically).
|
|
223
|
+
Object.keys(require.cache).forEach(key => {
|
|
224
|
+
delete require.cache[key];
|
|
225
|
+
});
|
|
226
|
+
register.revert();
|
|
227
|
+
await super.teardown();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=E2eSsrEnv.js.map
|