@dr.pogodin/react-utils 1.47.0-alpha.7 → 1.47.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/build/development/client/index.js +1 -1
  2. package/build/development/client/index.js.map +1 -1
  3. package/build/development/index.js +1 -11
  4. package/build/development/index.js.map +1 -1
  5. package/build/development/server/index.js +3 -6
  6. package/build/development/server/index.js.map +1 -1
  7. package/build/development/server/utils/index.js +1 -1
  8. package/build/development/server/utils/index.js.map +1 -1
  9. package/build/development/shared/components/Button/index.js +1 -1
  10. package/build/development/shared/components/Button/index.js.map +1 -1
  11. package/build/development/shared/components/Checkbox/index.js +1 -1
  12. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  13. package/build/development/shared/components/Input/index.js +1 -1
  14. package/build/development/shared/components/Input/index.js.map +1 -1
  15. package/build/development/shared/components/Modal/index.js +1 -1
  16. package/build/development/shared/components/Modal/index.js.map +1 -1
  17. package/build/development/shared/components/PageLayout/index.js +1 -1
  18. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  19. package/build/development/shared/components/TextArea/index.js +1 -1
  20. package/build/development/shared/components/TextArea/index.js.map +1 -1
  21. package/build/development/shared/components/Throbber/index.js +1 -1
  22. package/build/development/shared/components/Throbber/index.js.map +1 -1
  23. package/build/development/shared/components/WithTooltip/index.js +1 -1
  24. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  25. package/build/development/shared/components/YouTubeVideo/index.js +1 -1
  26. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  27. package/build/development/shared/components/selectors/CustomDropdown/index.js +1 -1
  28. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  29. package/build/development/shared/components/selectors/NativeDropdown/index.js +1 -1
  30. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  31. package/build/development/shared/components/selectors/Switch/index.js +1 -1
  32. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  33. package/build/production/client/index.js +1 -1
  34. package/build/production/client/index.js.map +1 -1
  35. package/build/production/index.js +2 -6
  36. package/build/production/index.js.map +1 -1
  37. package/build/production/server/index.js +3 -3
  38. package/build/production/server/index.js.map +1 -1
  39. package/build/production/server/utils/index.js +1 -1
  40. package/build/production/server/utils/index.js.map +1 -1
  41. package/build/production/shared/components/Button/index.js +1 -1
  42. package/build/production/shared/components/Button/index.js.map +1 -1
  43. package/build/production/shared/components/Checkbox/index.js +1 -1
  44. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  45. package/build/production/shared/components/Input/index.js +1 -1
  46. package/build/production/shared/components/Input/index.js.map +1 -1
  47. package/build/production/shared/components/Modal/index.js +1 -1
  48. package/build/production/shared/components/Modal/index.js.map +1 -1
  49. package/build/production/shared/components/PageLayout/index.js +1 -1
  50. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  51. package/build/production/shared/components/TextArea/index.js +1 -1
  52. package/build/production/shared/components/TextArea/index.js.map +1 -1
  53. package/build/production/shared/components/Throbber/index.js +1 -1
  54. package/build/production/shared/components/Throbber/index.js.map +1 -1
  55. package/build/production/shared/components/WithTooltip/index.js +1 -1
  56. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  57. package/build/production/shared/components/YouTubeVideo/index.js +1 -1
  58. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  59. package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
  60. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  61. package/build/production/shared/components/selectors/NativeDropdown/index.js +1 -1
  62. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  63. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  64. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  65. package/build/types-code/client/index.d.ts +1 -1
  66. package/build/types-code/index.d.ts +0 -6
  67. package/build/types-code/server/index.d.ts +4 -9
  68. package/build/types-code/server/utils/index.d.ts +1 -1
  69. package/build/web/client/index.js +1 -1
  70. package/build/web/client/index.js.map +1 -1
  71. package/build/web/index.js +0 -12
  72. package/build/web/index.js.map +1 -1
  73. package/build/web/server/index.js +3 -6
  74. package/build/web/server/index.js.map +1 -1
  75. package/build/web/server/utils/index.js +1 -1
  76. package/build/web/server/utils/index.js.map +1 -1
  77. package/build/web/shared/components/Button/index.js +1 -1
  78. package/build/web/shared/components/Button/index.js.map +1 -1
  79. package/build/web/shared/components/Checkbox/index.js +1 -1
  80. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  81. package/build/web/shared/components/Input/index.js +1 -1
  82. package/build/web/shared/components/Input/index.js.map +1 -1
  83. package/build/web/shared/components/Modal/index.js +1 -1
  84. package/build/web/shared/components/Modal/index.js.map +1 -1
  85. package/build/web/shared/components/PageLayout/index.js +1 -1
  86. package/build/web/shared/components/PageLayout/index.js.map +1 -1
  87. package/build/web/shared/components/TextArea/index.js +1 -1
  88. package/build/web/shared/components/TextArea/index.js.map +1 -1
  89. package/build/web/shared/components/Throbber/index.js +1 -1
  90. package/build/web/shared/components/Throbber/index.js.map +1 -1
  91. package/build/web/shared/components/WithTooltip/index.js +1 -1
  92. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  93. package/build/web/shared/components/YouTubeVideo/index.js +1 -1
  94. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
  95. package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -1
  96. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  97. package/build/web/shared/components/selectors/NativeDropdown/index.js +1 -1
  98. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  99. package/build/web/shared/components/selectors/Switch/index.js +1 -1
  100. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  101. package/package.json +17 -6
  102. package/src/client/getInj.ts +0 -71
  103. package/src/client/index.tsx +0 -45
  104. package/src/client/init.ts +0 -52
  105. package/src/index.ts +0 -75
  106. package/src/server/Cache.ts +0 -61
  107. package/src/server/index.ts +0 -243
  108. package/src/server/renderer.tsx +0 -635
  109. package/src/server/server.ts +0 -330
  110. package/src/server/utils/errors.ts +0 -122
  111. package/src/server/utils/index.ts +0 -3
  112. package/src/shared/components/Button/index.tsx +0 -130
  113. package/src/shared/components/Button/style.scss +0 -54
  114. package/src/shared/components/Checkbox/index.tsx +0 -53
  115. package/src/shared/components/Checkbox/theme.scss +0 -63
  116. package/src/shared/components/GenericLink/index.tsx +0 -141
  117. package/src/shared/components/GenericLink/style.scss +0 -3
  118. package/src/shared/components/Input/index.tsx +0 -96
  119. package/src/shared/components/Input/theme.scss +0 -52
  120. package/src/shared/components/Link.tsx +0 -25
  121. package/src/shared/components/Modal/base-theme.scss +0 -38
  122. package/src/shared/components/Modal/index.tsx +0 -177
  123. package/src/shared/components/Modal/styles.scss +0 -3
  124. package/src/shared/components/NavLink.tsx +0 -18
  125. package/src/shared/components/PageLayout/base-theme.scss +0 -30
  126. package/src/shared/components/PageLayout/index.tsx +0 -51
  127. package/src/shared/components/TextArea/index.tsx +0 -139
  128. package/src/shared/components/TextArea/style.scss +0 -68
  129. package/src/shared/components/Throbber/index.tsx +0 -28
  130. package/src/shared/components/Throbber/theme.scss +0 -26
  131. package/src/shared/components/WithTooltip/Tooltip.tsx +0 -274
  132. package/src/shared/components/WithTooltip/default-theme.scss +0 -36
  133. package/src/shared/components/WithTooltip/index.tsx +0 -186
  134. package/src/shared/components/YouTubeVideo/base.scss +0 -15
  135. package/src/shared/components/YouTubeVideo/index.tsx +0 -73
  136. package/src/shared/components/YouTubeVideo/throbber.scss +0 -11
  137. package/src/shared/components/index.ts +0 -20
  138. package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -124
  139. package/src/shared/components/selectors/CustomDropdown/Options/style.scss +0 -6
  140. package/src/shared/components/selectors/CustomDropdown/index.tsx +0 -146
  141. package/src/shared/components/selectors/CustomDropdown/theme.scss +0 -118
  142. package/src/shared/components/selectors/NativeDropdown/index.tsx +0 -90
  143. package/src/shared/components/selectors/NativeDropdown/theme.scss +0 -81
  144. package/src/shared/components/selectors/Switch/index.tsx +0 -74
  145. package/src/shared/components/selectors/Switch/theme.scss +0 -39
  146. package/src/shared/components/selectors/common.ts +0 -57
  147. package/src/shared/components/selectors/index.ts +0 -8
  148. package/src/shared/utils/config.ts +0 -59
  149. package/src/shared/utils/globalState.ts +0 -44
  150. package/src/shared/utils/index.ts +0 -45
  151. package/src/shared/utils/isomorphy/buildInfo.ts +0 -50
  152. package/src/shared/utils/isomorphy/environment-check.ts +0 -18
  153. package/src/shared/utils/isomorphy/index.ts +0 -36
  154. package/src/shared/utils/jest/E2eSsrEnv.ts +0 -304
  155. package/src/shared/utils/jest/global.ts +0 -17
  156. package/src/shared/utils/jest/index.ts +0 -215
  157. package/src/shared/utils/splitComponent.tsx +0 -284
  158. package/src/shared/utils/time.ts +0 -101
  159. package/src/shared/utils/webpack.ts +0 -80
  160. package/src/styles/_global/reset.css +0 -52
  161. package/src/styles/_mixins/fonts.scss +0 -40
  162. package/src/styles/_mixins/media.scss +0 -150
  163. package/src/styles/_mixins/typography.scss +0 -83
  164. package/src/styles/global.scss +0 -11
  165. package/src/styles/mixins.scss +0 -6
@@ -1,90 +0,0 @@
1
- // Implements dropdown based on the native HTML <select> element.
2
-
3
- import themed from '@dr.pogodin/react-themes';
4
-
5
- import { type PropsT, optionValueName } from '../common';
6
-
7
- import defaultTheme from './theme.scss';
8
-
9
- /**
10
- * Implements a themeable dropdown list. Internally it is rendered with help of
11
- * the standard HTML `<select>` element, thus the styling support is somewhat
12
- * limited.
13
- * @param [props] Component properties.
14
- * @param [props.filter] Options filter function. If provided, only
15
- * those elements of `options` list will be used by the dropdown, for which this
16
- * filter returns `true`.
17
- * @param [props.label] Dropdown label.
18
- * @param [props.onChange] Selection event handler.
19
- * @param [props.options=[]] Array of dropdown
20
- * options. For string elements the option value and name will be the same.
21
- * It is allowed to mix DropdownOption and string elements in the same option
22
- * list.
23
- * @param [props.theme] _Ad hoc_ theme.
24
- * @param [props.value] Currently selected value.
25
- * @param [props....]
26
- * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
27
- */
28
- const Dropdown: React.FunctionComponent<PropsT<string>> = ({
29
- filter,
30
- label,
31
- onChange,
32
- options,
33
- testId,
34
- theme,
35
- value,
36
- }) => {
37
- let isValidValue = false;
38
- const optionElements = [];
39
-
40
- for (const option of options) {
41
- if (!filter || filter(option)) {
42
- const [iValue, iName] = optionValueName(option);
43
- isValidValue ||= iValue === value;
44
- optionElements.push(
45
- <option className={theme.option} key={iValue} value={iValue}>
46
- {iName}
47
- </option>,
48
- );
49
- }
50
- }
51
-
52
- // NOTE: This element represents the current `value` when it does not match
53
- // any valid option. In Chrome, and some other browsers, we are able to hide
54
- // it from the opened dropdown; in others, e.g. Safari, the best we can do is
55
- // to show it as disabled.
56
- const hiddenOption = isValidValue ? null : (
57
- <option
58
- className={theme.hiddenOption}
59
- disabled
60
- key="__reactUtilsHiddenOption"
61
- value={value}
62
- >
63
- {value}
64
- </option>
65
- );
66
-
67
- let selectClassName = theme.select;
68
- if (!isValidValue) selectClassName += ` ${theme.invalid}`;
69
-
70
- return (
71
- <div className={theme.container}>
72
- { label === undefined
73
- ? null : <div className={theme.label}>{label}</div> }
74
- <div className={theme.dropdown}>
75
- <select
76
- className={selectClassName}
77
- data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}
78
- onChange={onChange}
79
- value={value}
80
- >
81
- {hiddenOption}
82
- {optionElements}
83
- </select>
84
- <div className={theme.arrow} />
85
- </div>
86
- </div>
87
- );
88
- };
89
-
90
- export default themed(Dropdown, 'Dropdown', defaultTheme);
@@ -1,81 +0,0 @@
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
- }
@@ -1,74 +0,0 @@
1
- import themed, { type Theme } from '@dr.pogodin/react-themes';
2
-
3
- import {
4
- type OptionsT,
5
- type ValueT,
6
- optionValueName,
7
- } from '../common';
8
-
9
- import defaultTheme from './theme.scss';
10
-
11
- type ThemeKeyT = 'container' | 'label' | 'option' | 'options' | 'selected';
12
-
13
- type PropsT = {
14
- label?: React.ReactNode;
15
- onChange?: (value: ValueT) => void;
16
- options?: Readonly<OptionsT<React.ReactNode>>;
17
- theme: Theme<ThemeKeyT>;
18
- value?: ValueT;
19
- };
20
-
21
- const BaseSwitch: React.FunctionComponent<PropsT> = ({
22
- label,
23
- onChange,
24
- options,
25
- theme,
26
- value,
27
- }) => {
28
- if (!options || !theme.option) throw Error('Internal error');
29
-
30
- const optionNodes: React.ReactNode[] = [];
31
- for (const option of options) {
32
- const [iValue, iName] = optionValueName(option);
33
-
34
- let className: string = theme.option;
35
- let onPress: (() => void) | undefined;
36
- if (iValue === value) className += ` ${theme.selected}`;
37
- else if (onChange) {
38
- onPress = () => {
39
- onChange(iValue);
40
- };
41
- }
42
-
43
- optionNodes.push(
44
- onPress
45
- ? (
46
- <div
47
- className={className}
48
- key={iValue}
49
- onClick={onPress}
50
- onKeyDown={(e) => {
51
- if (e.key === 'Enter') onPress();
52
- }}
53
- role="button"
54
- tabIndex={0}
55
- >
56
- {iName}
57
- </div>
58
- )
59
- : <div className={className} key={iValue}>{iName}</div>,
60
- );
61
- }
62
-
63
- return (
64
- <div className={theme.container}>
65
- {label ? <div className={theme.label}>{label}</div> : null}
66
-
67
- <div className={theme.options}>
68
- {optionNodes}
69
- </div>
70
- </div>
71
- );
72
- };
73
-
74
- export default themed(BaseSwitch, 'Switch', defaultTheme);
@@ -1,39 +0,0 @@
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
- }
@@ -1,57 +0,0 @@
1
- // The stuff common between different dropdown implementations.
2
-
3
- import type { Theme } from '@dr.pogodin/react-themes';
4
-
5
- type ThemeKeyT = 'active'
6
- | 'arrow'
7
- | 'container'
8
- | 'dropdown'
9
- | 'hiddenOption'
10
- | 'label'
11
- | 'option'
12
- | 'select'
13
-
14
- // TODO: This is currently only valid for (native) <Dropdown>,
15
- // other kinds of selectors should be evaluated, and aligned with this
16
- // feature, if appropriate.
17
- | 'invalid'
18
-
19
- // TODO: This is only valid for <CustomDropdown>, thus we need to re-factor it
20
- // into a separate theme spec for that component.
21
- | 'upward';
22
-
23
- export type ValueT = number | string;
24
-
25
- export type OptionT<NameT> = {
26
- name?: NameT | null;
27
- value: ValueT;
28
- };
29
-
30
- export type OptionsT<NameT> = Readonly<Array<OptionT<NameT> | ValueT>>;
31
-
32
- export type PropsT<
33
- NameT,
34
- OnChangeT = React.ChangeEventHandler<HTMLSelectElement>,
35
- > = {
36
- filter?: (item: OptionT<NameT> | ValueT) => boolean;
37
- label?: React.ReactNode;
38
- onChange?: OnChangeT;
39
- options: Readonly<OptionsT<NameT>>;
40
- testId?: string;
41
- theme: Theme<ThemeKeyT>;
42
- value?: ValueT;
43
- };
44
-
45
- function isValue<T>(x: OptionT<T> | ValueT): x is ValueT {
46
- const type = typeof x;
47
- return type === 'number' || type === 'string';
48
- }
49
-
50
- /** Returns option value and name as a tuple. */
51
- export function optionValueName<NameT>(
52
- option: OptionT<NameT> | ValueT,
53
- ): [ValueT, NameT | ValueT] {
54
- return isValue(option)
55
- ? [option, option]
56
- : [option.value, option.name ?? option.value];
57
- }
@@ -1,8 +0,0 @@
1
- export { default as CustomDropdown } from './CustomDropdown';
2
- export { default as Dropdown } from './NativeDropdown';
3
- export { default as Switch } from './Switch';
4
-
5
- export {
6
- type OptionT,
7
- type OptionsT,
8
- } from './common';
@@ -1,59 +0,0 @@
1
- /* global document */
2
-
3
- import { parse } from 'cookie';
4
-
5
- import clientGetInj from '../../client/getInj';
6
-
7
- import { IS_CLIENT_SIDE } from './isomorphy/environment-check';
8
- import { requireWeak } from './webpack';
9
-
10
- type ConfigT = Record<string, unknown>;
11
-
12
- let config: ConfigT | Promise<ConfigT> | undefined;
13
-
14
- /**
15
- * Injects CSRF token into config (on client-side only).
16
- *
17
- * BEWARE: It mutates the argument, and also returns it as the result,
18
- * for chaining.
19
- */
20
- function injectCsrfToken(cfg: ConfigT): ConfigT {
21
- // The safeguard for "document" is necessary because in non-Node environments,
22
- // like React Native, IS_CLIENT_SIDE is "true", however "document" and a bunch
23
- // of other browser-world features are not available.
24
- if (IS_CLIENT_SIDE && typeof document !== 'undefined') {
25
- // eslint-disable-next-line no-param-reassign
26
- cfg.CSRF = parse(document.cookie).csrfToken;
27
- }
28
-
29
- return cfg;
30
- }
31
-
32
- export function getConfig(sync: true): ConfigT;
33
-
34
- export function getConfig(sync?: boolean): ConfigT | Promise<ConfigT>;
35
-
36
- export function getConfig(sync?: boolean): ConfigT | Promise<ConfigT> {
37
- if (!config) {
38
- if (IS_CLIENT_SIDE) {
39
- const inj = clientGetInj();
40
- config = inj instanceof Promise
41
- ? inj.then((injection) => {
42
- const res = injectCsrfToken(injection.CONFIG ?? {});
43
- config = res;
44
- return res;
45
- })
46
- : injectCsrfToken(inj.CONFIG ?? {});
47
- } else {
48
- const weak = requireWeak<ConfigT>('config');
49
- if (!weak) throw Error('Internal error');
50
- config = weak;
51
- }
52
- }
53
-
54
- if (sync && (config instanceof Promise)) {
55
- throw Error('The config is not available yet');
56
- }
57
-
58
- return config;
59
- }
@@ -1,44 +0,0 @@
1
- import type { Request } from 'express';
2
-
3
- import { type SsrContext, withGlobalStateType } from '@dr.pogodin/react-global-state';
4
-
5
- /** Mapping "chunkName" > array of asset paths. */
6
- export type ChunkGroupsT = Record<string, string[]>;
7
-
8
- // The type of data object injected by server into generated markup.
9
- export type InjT = {
10
- CHUNK_GROUPS?: ChunkGroupsT;
11
- CONFIG?: Record<string, unknown>;
12
- ISTATE?: unknown;
13
- };
14
-
15
- declare global {
16
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
17
- interface Window {
18
- REACT_UTILS_INJECTION?: InjT;
19
- }
20
- }
21
-
22
- // TODO: Not 100% sure now, whether it indeed can be replaced by type,
23
- // or do we really need it to be an interface. Keeping the interface for now.
24
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
25
- export interface SsrContextT<StateT> extends SsrContext<StateT> {
26
- chunkGroups: ChunkGroupsT;
27
- chunks: string[];
28
-
29
- /** If set at the end of SSR, the rendered will trigger
30
- * server-side redirect to this URL (and use the status
31
- * code). */
32
- redirectTo?: string;
33
-
34
- req: Request;
35
- status: number;
36
- }
37
-
38
- const {
39
- getSsrContext,
40
- } = withGlobalStateType<unknown, SsrContextT<unknown>>();
41
-
42
- export {
43
- getSsrContext,
44
- };
@@ -1,45 +0,0 @@
1
- import themedImpl, {
2
- COMPOSE,
3
- PRIORITY,
4
- type Theme,
5
- ThemeProvider,
6
- } from '@dr.pogodin/react-themes';
7
-
8
- import { getConfig } from './config';
9
- import * as isomorphy from './isomorphy';
10
- import time from './time';
11
- import * as webpack from './webpack';
12
-
13
- export {
14
- assertEmptyObject,
15
- type Listener,
16
- type ObjectKey,
17
- Barrier,
18
- Cached,
19
- Emitter,
20
- Semaphore,
21
- withRetries,
22
- } from '@dr.pogodin/js-utils';
23
-
24
- export { getSsrContext } from './globalState';
25
- export { default as splitComponent } from './splitComponent';
26
-
27
- type ThemedT = typeof themedImpl & {
28
- COMPOSE: typeof COMPOSE;
29
- PRIORITY: typeof PRIORITY;
30
- };
31
-
32
- const themed: ThemedT = themedImpl as ThemedT;
33
-
34
- themed.COMPOSE = COMPOSE;
35
- themed.PRIORITY = PRIORITY;
36
-
37
- export {
38
- type Theme,
39
- getConfig,
40
- isomorphy,
41
- themed,
42
- ThemeProvider,
43
- time,
44
- webpack,
45
- };
@@ -1,50 +0,0 @@
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
- export type BuildInfoT = {
7
- key: string;
8
- publicPath: string;
9
- timestamp: string;
10
- useServiceWorker: boolean;
11
- };
12
-
13
- // Depending on the build mode & environment, BUILD_INFO is either a global
14
- // variable defined at the app launch, or it is replaced by the actual value
15
- // by the Webpack build.
16
- declare const BUILD_INFO: BuildInfoT | undefined;
17
-
18
- let buildInfo: BuildInfoT | undefined;
19
-
20
- // On the client side "BUILD_INFO" should be injected by Webpack. Note, however,
21
- // that in test environment we may need situations were environment is mocked as
22
- // client-side, although no proper Webpack compilation is executed, thus no info
23
- // injected; because of this we don't do a hard environment check here.
24
- if (typeof BUILD_INFO !== 'undefined') buildInfo = BUILD_INFO;
25
-
26
- /**
27
- * In scenarious where "BUILD_INFO" is not injected by Webpack (server-side,
28
- * tests, etc.) we expect the host codebase to explicitly set it before it is
29
- * ever requested. As a precaution, this function throws if build info has been
30
- * set already, unless `force` flag is explicitly set.
31
- * @param info
32
- * @param force
33
- */
34
- export function setBuildInfo(info?: BuildInfoT, force = false): void {
35
- if (buildInfo !== undefined && !force) {
36
- throw Error('"Build Info" is already initialized');
37
- }
38
- buildInfo = info;
39
- }
40
-
41
- /**
42
- * Returns "Build Info" object; throws if it has not been initialized yet.
43
- * @returns
44
- */
45
- export function getBuildInfo(): BuildInfoT {
46
- if (buildInfo === undefined) {
47
- throw Error('"Build Info" has not been initialized yet');
48
- }
49
- return buildInfo;
50
- }
@@ -1,18 +0,0 @@
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: boolean = 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
12
- || !!global.REACT_UTILS_FORCE_CLIENT_SIDE
13
- || typeof REACT_UTILS_WEBPACK_BUNDLE !== 'undefined';
14
-
15
- /**
16
- * `true` within the server-side environment (node), `false` at client-side.
17
- */
18
- export const IS_SERVER_SIDE: boolean = !IS_CLIENT_SIDE;
@@ -1,36 +0,0 @@
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(): boolean {
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(): boolean {
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(): string {
33
- return getBuildInfo().timestamp;
34
- }
35
-
36
- export { IS_CLIENT_SIDE, IS_SERVER_SIDE, getBuildInfo };