@dr.pogodin/react-utils 1.25.5 → 1.26.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.config.js +3 -1
- package/bin/build.js +25 -5
- package/build/development/client/getInj.js +9 -8
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +6 -3
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +4 -0
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +168 -42
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +13 -13
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +16 -24
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +56 -44
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +9 -5
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +12 -9
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +2 -2
- package/build/development/server/utils/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +8 -7
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +25 -28
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/Dropdown/index.js +25 -19
- package/build/development/shared/components/Dropdown/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +44 -37
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +8 -9
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +10 -9
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/MetaTags.js +22 -18
- package/build/development/shared/components/MetaTags.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +17 -18
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +10 -9
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +17 -20
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/ScalableRect/index.js +27 -7
- package/build/development/shared/components/ScalableRect/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +14 -23
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +20 -24
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +11 -11
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +16 -15
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +2 -2
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/utils/config.js +1 -2
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +15 -0
- package/build/development/shared/utils/globalState.js.map +1 -0
- package/build/development/shared/utils/index.js +13 -11
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +7 -3
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +2 -4
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +35 -28
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/global.js +17 -0
- package/build/development/shared/utils/jest/global.js.map +1 -0
- package/build/development/shared/utils/jest/index.js +18 -11
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +25 -34
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +16 -13
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +3 -3
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/development/web.bundle.js +92 -82
- package/build/production/client/getInj.js +1 -1
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js +4 -4
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js +3 -1
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js +7 -8
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +5 -4
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +32 -30
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +7 -5
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +9 -10
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/server/utils/index.js +1 -1
- package/build/production/server/utils/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +4 -4
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +12 -12
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/Dropdown/index.js +11 -11
- package/build/production/shared/components/Dropdown/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +25 -20
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +7 -7
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js +2 -2
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/MetaTags.js +10 -10
- package/build/production/shared/components/MetaTags.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +2 -2
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +1 -1
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -2
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/ScalableRect/index.js +7 -3
- package/build/production/shared/components/ScalableRect/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +2 -2
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +13 -13
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +3 -3
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +7 -7
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/utils/config.js +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/globalState.js +3 -0
- package/build/production/shared/utils/globalState.js.map +1 -0
- package/build/production/shared/utils/index.js +3 -3
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/buildInfo.js +7 -4
- package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/production/shared/utils/isomorphy/environment-check.js +2 -2
- package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +9 -9
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/global.js +2 -0
- package/build/production/shared/utils/jest/global.js.map +1 -0
- package/build/production/shared/utils/jest/index.js +6 -6
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +16 -16
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +12 -8
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js +3 -3
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/client/getInj.d.ts +3 -0
- package/build/types-code/client/index.d.ts +11 -0
- package/build/types-code/client/init.d.ts +9 -0
- package/build/types-code/index.d.ts +10 -0
- package/build/types-code/server/Cache.d.ts +37 -0
- package/build/types-code/server/index.d.ts +145 -0
- package/build/types-code/server/renderer.d.ts +106 -0
- package/build/types-code/server/server.d.ts +41 -0
- package/build/types-code/server/utils/errors.d.ts +104 -0
- package/build/types-code/server/utils/index.d.ts +1 -0
- package/build/types-code/shared/components/Button/index.d.ts +27 -0
- package/build/types-code/shared/components/Checkbox/index.d.ts +21 -0
- package/build/types-code/shared/components/Dropdown/index.d.ts +23 -0
- package/build/types-code/shared/components/GenericLink/index.d.ts +61 -0
- package/build/types-code/shared/components/Input/index.d.ts +11 -0
- package/build/types-code/shared/components/Link.d.ts +12 -0
- package/build/types-code/shared/components/MetaTags.d.ts +68 -0
- package/build/types-code/shared/components/Modal/index.d.ts +26 -0
- package/build/types-code/shared/components/NavLink.d.ts +5 -0
- package/build/types-code/shared/components/PageLayout/index.d.ts +16 -0
- package/build/types-code/shared/components/ScalableRect/index.d.ts +19 -0
- package/build/types-code/shared/components/Throbber/index.d.ts +9 -0
- package/build/types-code/shared/components/WithTooltip/Tooltip.d.ts +23 -0
- package/build/types-code/shared/components/WithTooltip/index.d.ts +17 -0
- package/build/types-code/shared/components/YouTubeVideo/index.d.ts +13 -0
- package/build/types-code/shared/components/index.d.ts +16 -0
- package/build/types-code/shared/utils/config.d.ts +2 -0
- package/build/types-code/shared/utils/globalState.d.ts +20 -0
- package/build/types-code/shared/utils/index.d.ts +52 -0
- package/build/types-code/shared/utils/isomorphy/buildInfo.d.ts +23 -0
- package/build/types-code/shared/utils/isomorphy/environment-check.d.ts +11 -0
- package/build/types-code/shared/utils/isomorphy/index.d.ts +20 -0
- package/build/types-code/shared/utils/jest/E2eSsrEnv.d.ts +31 -0
- package/build/types-code/shared/utils/jest/global.d.ts +12 -0
- package/build/types-code/shared/utils/jest/index.d.ts +85 -0
- package/build/types-code/shared/utils/splitComponent.d.ts +41 -0
- package/build/types-code/shared/utils/time.d.ts +62 -0
- package/build/types-code/shared/utils/webpack.d.ts +18 -0
- package/build/types-scss/__tests__/js/config/publicPath support/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/MockPackageA/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/MockPackageB/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/components/NavLink/styles.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentA/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentB/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentC/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/publicPath support/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/MockPackageA/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/MockPackageB/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/components/NavLink/styles.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentA/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentB/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentC/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/style.scss.d.ts +1 -0
- package/build/types-scss/src/shared/components/Button/style.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/Checkbox/theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/Dropdown/theme.scss.d.ts +9 -0
- package/build/types-scss/src/shared/components/GenericLink/style.scss.d.ts +1 -0
- package/build/types-scss/src/shared/components/Input/theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/Modal/base-theme.scss.d.ts +5 -0
- package/build/types-scss/src/shared/components/PageLayout/base-theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/ScalableRect/style.scss.d.ts +2 -0
- package/build/types-scss/src/shared/components/Throbber/theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/WithTooltip/default-theme.scss.d.ts +7 -0
- package/build/types-scss/src/shared/components/YouTubeVideo/base.scss.d.ts +5 -0
- package/build/types-scss/src/shared/components/YouTubeVideo/throbber.scss.d.ts +4 -0
- package/config/eslint/jest.json +3 -2
- package/config/eslint/typescript.js +34 -0
- package/config/jest/default.js +3 -3
- package/package.json +75 -33
- package/src/client/getInj.ts +43 -0
- package/src/client/index.tsx +40 -0
- package/src/client/init.ts +47 -0
- package/src/index.ts +58 -0
- package/src/server/Cache.ts +68 -0
- package/src/server/index.ts +230 -0
- package/src/server/renderer.tsx +604 -0
- package/src/server/server.ts +309 -0
- package/src/server/utils/errors.ts +135 -0
- package/src/server/utils/index.ts +3 -0
- package/src/shared/components/Button/index.tsx +146 -0
- package/src/shared/components/Button/style.scss +53 -0
- package/src/shared/components/Checkbox/index.tsx +71 -0
- package/src/shared/components/Checkbox/theme.scss +43 -0
- package/src/shared/components/Dropdown/index.tsx +144 -0
- package/src/shared/components/Dropdown/theme.scss +63 -0
- package/src/shared/components/GenericLink/index.tsx +157 -0
- package/src/shared/components/GenericLink/style.scss +3 -0
- package/src/shared/components/Input/index.tsx +59 -0
- package/src/shared/components/Input/theme.scss +27 -0
- package/src/shared/components/Link.tsx +21 -0
- package/src/shared/components/MetaTags.tsx +170 -0
- package/src/shared/components/Modal/base-theme.scss +38 -0
- package/src/shared/components/Modal/index.tsx +144 -0
- package/src/shared/components/Modal/styles.scss +5 -0
- package/src/shared/components/NavLink.tsx +13 -0
- package/src/shared/components/PageLayout/base-theme.scss +30 -0
- package/src/shared/components/PageLayout/index.tsx +76 -0
- package/src/shared/components/ScalableRect/index.tsx +84 -0
- package/src/shared/components/ScalableRect/style.scss +10 -0
- package/src/shared/components/Throbber/index.tsx +43 -0
- package/src/shared/components/Throbber/theme.scss +26 -0
- package/src/shared/components/WithTooltip/Tooltip.tsx +353 -0
- package/src/shared/components/WithTooltip/default-theme.scss +36 -0
- package/src/shared/components/WithTooltip/index.tsx +204 -0
- package/src/shared/components/YouTubeVideo/base.scss +13 -0
- package/src/shared/components/YouTubeVideo/index.tsx +96 -0
- package/src/shared/components/YouTubeVideo/throbber.scss +11 -0
- package/src/shared/components/index.ts +17 -0
- package/src/shared/utils/config.ts +21 -0
- package/src/shared/utils/globalState.ts +29 -0
- package/src/shared/utils/index.ts +105 -0
- package/src/shared/utils/isomorphy/buildInfo.ts +54 -0
- package/src/shared/utils/isomorphy/environment-check.ts +18 -0
- package/src/shared/utils/isomorphy/index.ts +38 -0
- package/src/shared/utils/jest/E2eSsrEnv.ts +250 -0
- package/src/shared/utils/jest/global.ts +19 -0
- package/src/shared/utils/jest/index.tsx +157 -0
- package/src/shared/utils/splitComponent.tsx +255 -0
- package/src/shared/utils/time.ts +118 -0
- package/src/shared/utils/webpack.ts +45 -0
- package/src/styles/_global/reset.css +52 -0
- package/src/styles/global.scss +11 -0
- package/tsconfig.configs.json +18 -0
- package/tsconfig.json +27 -0
- package/tsconfig.types.json +53 -0
- package/typed-scss-modules.config.ts +9 -0
- package/types.d.ts +37 -0
- package/{webpack.config.js → webpack.config.ts} +7 -3
- package/config/babel/node-ssr.js +0 -85
- package/config/babel/webpack.js +0 -122
- package/config/webpack/app-base.js +0 -330
- package/config/webpack/app-development.js +0 -80
- package/config/webpack/app-production.js +0 -60
- package/config/webpack/lib-base.js +0 -155
- package/config/webpack/lib-development.js +0 -45
- package/config/webpack/lib-production.js +0 -44
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* global expect, jest, document */
|
|
2
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
3
|
+
|
|
4
|
+
import mockdate from 'mockdate';
|
|
5
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
6
|
+
import { type Root, createRoot } from 'react-dom/client';
|
|
7
|
+
import TU, { act } from 'react-dom/test-utils';
|
|
8
|
+
|
|
9
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
10
|
+
import Renderer from 'react-test-renderer';
|
|
11
|
+
import { type ShallowRenderer, createRenderer } from 'react-test-renderer/shallow';
|
|
12
|
+
/* eslint-enable import/no-extraneous-dependencies */
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)
|
|
16
|
+
* from `react-dom/test-utils`.
|
|
17
|
+
* @param {function} action
|
|
18
|
+
*/
|
|
19
|
+
export { act };
|
|
20
|
+
|
|
21
|
+
export { default as getGlobal } from './global';
|
|
22
|
+
|
|
23
|
+
declare global {
|
|
24
|
+
// eslint-disable-next-line no-var, vars-on-top
|
|
25
|
+
var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
29
|
+
|
|
30
|
+
const originalProcessVersions = process.versions;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Tricks **react-utils** into thinking the test is running within client-side
|
|
34
|
+
* (browser) environment.
|
|
35
|
+
*/
|
|
36
|
+
export function mockClientSide() {
|
|
37
|
+
Object.defineProperty(process, 'versions', { value: null });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.
|
|
42
|
+
*/
|
|
43
|
+
export function unmockClientSide() {
|
|
44
|
+
Object.defineProperty(process, 'versions', {
|
|
45
|
+
value: originalProcessVersions,
|
|
46
|
+
writable: false,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Generates a mock UUID, or better said it determenistically transforms given
|
|
52
|
+
* `seed` number into a UUID-formatted string.
|
|
53
|
+
* @param {number} seed
|
|
54
|
+
* @return {string}
|
|
55
|
+
*/
|
|
56
|
+
export function getMockUuid(seed = 0) {
|
|
57
|
+
const x = seed.toString(16).padStart(32, '0');
|
|
58
|
+
return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Advances mock timers, and mock date by the specified time.
|
|
63
|
+
* @param {number} time Time step [ms].
|
|
64
|
+
* @returns {Promise} Wait for this to "jump after" any async code which should
|
|
65
|
+
* be executed because of the mock time movement.
|
|
66
|
+
*/
|
|
67
|
+
export async function mockTimer(time: number) {
|
|
68
|
+
mockdate.set(time + Date.now());
|
|
69
|
+
jest.advanceTimersByTime(time);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type MountedSceneT = HTMLElement & {
|
|
73
|
+
destroy: () => void;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Mounts `scene` to the DOM, and returns the root scene element.
|
|
78
|
+
* @param scene
|
|
79
|
+
* @return Created container DOM element with destroy() function
|
|
80
|
+
* attached.
|
|
81
|
+
*/
|
|
82
|
+
export function mount(scene: ReactNode): MountedSceneT {
|
|
83
|
+
let root: Root;
|
|
84
|
+
const element = document.createElement('div');
|
|
85
|
+
document.body.appendChild(element);
|
|
86
|
+
|
|
87
|
+
const res: MountedSceneT = (element as unknown) as MountedSceneT;
|
|
88
|
+
res.destroy = () => {
|
|
89
|
+
act(() => root.unmount());
|
|
90
|
+
res.remove();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
act(() => {
|
|
94
|
+
root = createRoot(res);
|
|
95
|
+
root.render(scene);
|
|
96
|
+
});
|
|
97
|
+
return res;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* OLD STUFF BELOW THIS MARK */
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Renders provided ReactJS component into JSON representation of the component
|
|
104
|
+
* tree, using [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).
|
|
105
|
+
* @param {object} component ReactJS component to render.
|
|
106
|
+
* @return {object} JSON representation of the rendered tree.
|
|
107
|
+
* @example
|
|
108
|
+
* import { JU } from '@dr.pogodin/react-utils';
|
|
109
|
+
* console.log(JU.render(<div>Example</div>));
|
|
110
|
+
*/
|
|
111
|
+
export function render(component: ReactElement) {
|
|
112
|
+
return Renderer.create(component).toJSON();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Generates a shallow render of given ReactJS component, using
|
|
117
|
+
* [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)
|
|
118
|
+
* and returns the result.
|
|
119
|
+
* @param {object} component ReactJS component to render.
|
|
120
|
+
* @return {object} JSON representation of the shallow component's render tree.
|
|
121
|
+
*/
|
|
122
|
+
export function shallowRender(component: ReactElement) {
|
|
123
|
+
const renderer: ShallowRenderer = createRenderer();
|
|
124
|
+
renderer.render(component);
|
|
125
|
+
return renderer.getRenderOutput();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Makes a shallow snapshot test of the given ReactJS component, and also
|
|
130
|
+
* returns JSON representation of the rendered component tree. Under the hood
|
|
131
|
+
* it uses {@link module:JU.shallowRender shallowRender(..)} to generate
|
|
132
|
+
* the render, then executes `expect(RENDER_RESULT).toMatchSnapshot()`,
|
|
133
|
+
* and finally returns the `RENDER_RESULT` to the caller.
|
|
134
|
+
* @param {object} component ReactJS component to render.
|
|
135
|
+
* @return {object} JSON representation of shallow render.
|
|
136
|
+
*/
|
|
137
|
+
export function shallowSnapshot(component: ReactElement) {
|
|
138
|
+
const res = shallowRender(component);
|
|
139
|
+
expect(res).toMatchSnapshot();
|
|
140
|
+
return res;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Makes snapshot test of the given ReactJS component, and also returns JSON
|
|
145
|
+
* representation of the rendered component tree. Under the hood, it uses
|
|
146
|
+
* {@link module:JU.render render(..)} to render it, then executes
|
|
147
|
+
* `expect(RENDER_RESULT).toMatchSnapshot()`, and then returns `RENDER_RESULT`.
|
|
148
|
+
* @param {object} component ReactJS component to render.
|
|
149
|
+
* @return {object} JSON render of the component.
|
|
150
|
+
*/
|
|
151
|
+
export function snapshot(component: ReactElement) {
|
|
152
|
+
const res = render(component);
|
|
153
|
+
expect(res).toMatchSnapshot();
|
|
154
|
+
return res;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export const simulate = TU.Simulate;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
2
|
+
/* global document */
|
|
3
|
+
|
|
4
|
+
import PT from 'prop-types';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
type ComponentType,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
forwardRef,
|
|
10
|
+
lazy,
|
|
11
|
+
Suspense,
|
|
12
|
+
useInsertionEffect,
|
|
13
|
+
} from 'react';
|
|
14
|
+
|
|
15
|
+
import { Barrier } from '@dr.pogodin/js-utils';
|
|
16
|
+
|
|
17
|
+
import { type ChunkGroupsT, getSsrContext } from './globalState';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
IS_CLIENT_SIDE,
|
|
21
|
+
IS_SERVER_SIDE,
|
|
22
|
+
getBuildInfo,
|
|
23
|
+
} from './isomorphy';
|
|
24
|
+
|
|
25
|
+
// Note: At the client side we can get chunk groups immediately when loading
|
|
26
|
+
// the module; at the server-side we only can get them within React render flow.
|
|
27
|
+
// Thus, we set and use the following variable at the client-side, and then when
|
|
28
|
+
// needed on the server side, we'll fetch it differently.
|
|
29
|
+
let clientChunkGroups: ChunkGroupsT;
|
|
30
|
+
|
|
31
|
+
if (IS_CLIENT_SIDE) {
|
|
32
|
+
// eslint-disable-next-line global-require
|
|
33
|
+
clientChunkGroups = require('client/getInj').default().CHUNK_GROUPS || {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const refCounts: { [path: string]: number } = {};
|
|
37
|
+
|
|
38
|
+
function getPublicPath() {
|
|
39
|
+
return getBuildInfo().publicPath;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Client-side only! Ensures the specified CSS stylesheet is loaded into
|
|
44
|
+
* the document; loads if it is missing; and does simple reference counting
|
|
45
|
+
* to facilitate future clean-up.
|
|
46
|
+
* @param name
|
|
47
|
+
* @param loadedSheets
|
|
48
|
+
* @param refCount
|
|
49
|
+
* @return
|
|
50
|
+
*/
|
|
51
|
+
function bookStyleSheet(
|
|
52
|
+
name: string,
|
|
53
|
+
loadedSheets: Set<string>,
|
|
54
|
+
refCount: boolean,
|
|
55
|
+
): Promise<void> | undefined {
|
|
56
|
+
let res: Barrier<void> | undefined;
|
|
57
|
+
const path = `${getPublicPath()}/${name}`;
|
|
58
|
+
const fullPath = `${document.location.origin}${path}`;
|
|
59
|
+
|
|
60
|
+
if (!loadedSheets.has(fullPath)) {
|
|
61
|
+
let link = document.querySelector(`link[href="${path}"]`);
|
|
62
|
+
|
|
63
|
+
if (!link) {
|
|
64
|
+
link = document.createElement('link');
|
|
65
|
+
link.setAttribute('rel', 'stylesheet');
|
|
66
|
+
link.setAttribute('href', path);
|
|
67
|
+
document.head.appendChild(link);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
res = new Barrier<void>();
|
|
71
|
+
link.addEventListener('load', () => res!.resolve());
|
|
72
|
+
link.addEventListener('error', () => res!.resolve());
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (refCount) {
|
|
76
|
+
const current = refCounts[path] || 0;
|
|
77
|
+
refCounts[path] = 1 + current;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return res;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Generates the set of URLs for currently loaded, linked stylesheets.
|
|
85
|
+
* @return
|
|
86
|
+
*/
|
|
87
|
+
function getLoadedStyleSheets(): Set<string> {
|
|
88
|
+
const res = new Set<string>();
|
|
89
|
+
const { styleSheets } = document;
|
|
90
|
+
for (let i = 0; i < styleSheets.length; ++i) {
|
|
91
|
+
const { href } = styleSheets[i];
|
|
92
|
+
if (href) res.add(href);
|
|
93
|
+
}
|
|
94
|
+
return res;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function assertChunkName(
|
|
98
|
+
chunkName: string,
|
|
99
|
+
chunkGroups: ChunkGroupsT,
|
|
100
|
+
) {
|
|
101
|
+
if (chunkGroups[chunkName]) return;
|
|
102
|
+
throw Error(`Unknown chunk name "${chunkName}"`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Client-side only! Ensures all CSS stylesheets required for the specified
|
|
107
|
+
* code chunk are loaded into the document; loads the missing ones; and does
|
|
108
|
+
* simple reference counting to facilitate future clean-up.
|
|
109
|
+
* @param chunkName Chunk name.
|
|
110
|
+
* @param refCount
|
|
111
|
+
* @return Resolves once all pending stylesheets, necessary for
|
|
112
|
+
* the chunk, are either loaded, or failed to load.
|
|
113
|
+
*/
|
|
114
|
+
export function bookStyleSheets(
|
|
115
|
+
chunkName: string,
|
|
116
|
+
chunkGroups: ChunkGroupsT,
|
|
117
|
+
refCount: boolean,
|
|
118
|
+
): Promise<void> {
|
|
119
|
+
const promises = [];
|
|
120
|
+
const assets = chunkGroups[chunkName];
|
|
121
|
+
const loadedSheets = getLoadedStyleSheets();
|
|
122
|
+
|
|
123
|
+
for (let i = 0; i < assets.length; ++i) {
|
|
124
|
+
const asset = assets[i];
|
|
125
|
+
if (asset.endsWith('.css')) {
|
|
126
|
+
const promise = bookStyleSheet(asset, loadedSheets, refCount);
|
|
127
|
+
if (promise) promises.push(promise);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return promises.length
|
|
132
|
+
? Promise.allSettled(promises).then()
|
|
133
|
+
: Promise.resolve();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Client-side only! Frees from the document all CSS stylesheets that are
|
|
138
|
+
* required by the specified chunk, and have reference counter equal to one
|
|
139
|
+
* (for chunks with larger reference counter values, it just decrements
|
|
140
|
+
* the reference counter).
|
|
141
|
+
* @param {string} chunkName
|
|
142
|
+
*/
|
|
143
|
+
export function freeStyleSheets(
|
|
144
|
+
chunkName: string,
|
|
145
|
+
chunkGroups: ChunkGroupsT,
|
|
146
|
+
) {
|
|
147
|
+
const assets = chunkGroups[chunkName];
|
|
148
|
+
for (let i = 0; i < assets.length; ++i) {
|
|
149
|
+
const asset = assets[i];
|
|
150
|
+
if (asset.endsWith('.css')) {
|
|
151
|
+
const path = `${getPublicPath()}/${asset}`;
|
|
152
|
+
if (--refCounts[path] <= 0) {
|
|
153
|
+
document.head.querySelector(`link[href="${path}"]`)!.remove();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Holds the set of chunk names already used for splitComponent() calls.
|
|
160
|
+
const usedChunkNames = new Set();
|
|
161
|
+
|
|
162
|
+
type ComponentOrModule<PropsT> = ComponentType<PropsT> | {
|
|
163
|
+
default: ComponentType<PropsT>,
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Given an async component retrieval function `getComponent()` it creates
|
|
168
|
+
* a special "code split" component, which uses <Suspense> to asynchronously
|
|
169
|
+
* load on demand the code required by `getComponent()`.
|
|
170
|
+
* @param options
|
|
171
|
+
* @param options.chunkName
|
|
172
|
+
* @param {function} options.getComponent
|
|
173
|
+
* @param {React.Element} [options.placeholder]
|
|
174
|
+
* @return {React.ElementType}
|
|
175
|
+
*/
|
|
176
|
+
export default function splitComponent<
|
|
177
|
+
ComponentPropsT extends { children?: ReactNode },
|
|
178
|
+
>({
|
|
179
|
+
chunkName,
|
|
180
|
+
getComponent,
|
|
181
|
+
placeholder,
|
|
182
|
+
}: {
|
|
183
|
+
chunkName: string;
|
|
184
|
+
getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>,
|
|
185
|
+
placeholder?: ReactNode,
|
|
186
|
+
}) {
|
|
187
|
+
// On the client side we can check right away if the chunk name is known.
|
|
188
|
+
if (IS_CLIENT_SIDE) assertChunkName(chunkName, clientChunkGroups);
|
|
189
|
+
|
|
190
|
+
// The correct usage of splitComponent() assumes a single call per chunk.
|
|
191
|
+
if (usedChunkNames.has(chunkName)) {
|
|
192
|
+
throw Error(`Repeated splitComponent() call for the chunk "${chunkName}"`);
|
|
193
|
+
} else usedChunkNames.add(chunkName);
|
|
194
|
+
|
|
195
|
+
const LazyComponent = lazy(async () => {
|
|
196
|
+
const resolved = await getComponent();
|
|
197
|
+
const Component = 'default' in resolved ? resolved.default : resolved;
|
|
198
|
+
|
|
199
|
+
// This pre-loads necessary stylesheets prior to the first mount of
|
|
200
|
+
// the component (the lazy load function is executed by React one at
|
|
201
|
+
// the frist mount).
|
|
202
|
+
if (IS_CLIENT_SIDE) {
|
|
203
|
+
await bookStyleSheets(chunkName, clientChunkGroups, false);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const Wrapper = forwardRef((
|
|
207
|
+
{ children, ...rest }: ComponentPropsT,
|
|
208
|
+
ref,
|
|
209
|
+
) => {
|
|
210
|
+
// On the server side we'll assert the chunk name here,
|
|
211
|
+
// and also push it to the SSR chunks array.
|
|
212
|
+
if (IS_SERVER_SIDE) {
|
|
213
|
+
const { chunkGroups, chunks } = getSsrContext()!;
|
|
214
|
+
assertChunkName(chunkName, chunkGroups);
|
|
215
|
+
if (!chunks.includes(chunkName)) chunks.push(chunkName);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// This takes care about stylesheets management every time an instance of
|
|
219
|
+
// this component is mounted / unmounted.
|
|
220
|
+
useInsertionEffect(() => {
|
|
221
|
+
bookStyleSheets(chunkName, clientChunkGroups, true);
|
|
222
|
+
return () => freeStyleSheets(chunkName, clientChunkGroups);
|
|
223
|
+
}, []);
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<Component ref={ref} {...rest as ComponentPropsT}>
|
|
227
|
+
{children}
|
|
228
|
+
</Component>
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
return { default: Wrapper };
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const CodeSplit: React.FunctionComponent<ComponentPropsT> = ({
|
|
236
|
+
children,
|
|
237
|
+
...rest
|
|
238
|
+
}: ComponentPropsT) => (
|
|
239
|
+
<Suspense fallback={placeholder}>
|
|
240
|
+
<LazyComponent {...rest as Parameters<typeof LazyComponent>[0]}>
|
|
241
|
+
{children}
|
|
242
|
+
</LazyComponent>
|
|
243
|
+
</Suspense>
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
CodeSplit.propTypes = {
|
|
247
|
+
children: PT.node,
|
|
248
|
+
} as React.WeakValidationMap<ComponentPropsT>;
|
|
249
|
+
|
|
250
|
+
CodeSplit.defaultProps = {
|
|
251
|
+
children: undefined,
|
|
252
|
+
} as Partial<ComponentPropsT>;
|
|
253
|
+
|
|
254
|
+
return CodeSplit;
|
|
255
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/* global document */
|
|
2
|
+
|
|
3
|
+
import Cookie from 'cookie';
|
|
4
|
+
import dayjs from 'dayjs';
|
|
5
|
+
import { useEffect } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
DAY_MS,
|
|
9
|
+
HOUR_MS,
|
|
10
|
+
MIN_MS,
|
|
11
|
+
SEC_MS,
|
|
12
|
+
YEAR_MS,
|
|
13
|
+
timer,
|
|
14
|
+
} from '@dr.pogodin/js-utils';
|
|
15
|
+
|
|
16
|
+
import { type ForceT, useGlobalState } from '@dr.pogodin/react-global-state';
|
|
17
|
+
|
|
18
|
+
import { getSsrContext } from './globalState';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This react hook wraps Date.now() function in a SSR friendly way,
|
|
22
|
+
* ensuring that all calls to useCurrent() within the same render return
|
|
23
|
+
* exactly the same time (which is retrieved from Date.now() first, and
|
|
24
|
+
* then stored in the global state to be reused in all other calls), which
|
|
25
|
+
* is also passed and used in the first client side render, and then updated
|
|
26
|
+
* with a finite precision to avoid infinite re-rendering loops.
|
|
27
|
+
* @param [options] Optional settings.
|
|
28
|
+
* @param [options.globalStatePath="currentTime"] Global state path
|
|
29
|
+
* to keep the current time value.
|
|
30
|
+
* @param [options.precision= 5 * time.SEC_MS] Current time precision.
|
|
31
|
+
* The hook won't update the current time stored in the global state unless it
|
|
32
|
+
* is different from Date.now() result by this number (in milliseconds).
|
|
33
|
+
* Default to 5 seconds.
|
|
34
|
+
* @param [options.autorefresh=false] Set `true` to automatically
|
|
35
|
+
* refresh time stored in the global state with the given `precision` (and
|
|
36
|
+
* thus automatically re-rendering components dependent on this hook, or
|
|
37
|
+
* the global state with the period equal to the `precision`.
|
|
38
|
+
* @return Unix timestamp in milliseconds.
|
|
39
|
+
*/
|
|
40
|
+
// TODO: Should we request the state type as generic parameter, to be able
|
|
41
|
+
// to verify the give globalStatePath is correct?
|
|
42
|
+
export function useCurrent({
|
|
43
|
+
autorefresh = false,
|
|
44
|
+
globalStatePath = 'currentTime',
|
|
45
|
+
precision = 5 * SEC_MS,
|
|
46
|
+
} = {}) {
|
|
47
|
+
const [now, setter] = useGlobalState<ForceT, number>(globalStatePath, Date.now);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
let timerId: NodeJS.Timeout;
|
|
50
|
+
const update = () => {
|
|
51
|
+
setter((old) => {
|
|
52
|
+
const neu = Date.now();
|
|
53
|
+
return Math.abs(neu - old) > precision ? neu : old;
|
|
54
|
+
});
|
|
55
|
+
if (autorefresh) timerId = setTimeout(update, precision);
|
|
56
|
+
};
|
|
57
|
+
update();
|
|
58
|
+
return () => {
|
|
59
|
+
if (timerId) clearTimeout(timerId);
|
|
60
|
+
};
|
|
61
|
+
}, [autorefresh, precision, setter]);
|
|
62
|
+
return now;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.
|
|
67
|
+
* This hook retrieves the offset value at the client side and uses a cookie
|
|
68
|
+
* to pass it to the server in subsequent requests from that user. At the server
|
|
69
|
+
* side the value from cookie is used in renders and passed back to the client
|
|
70
|
+
* via the global state. Prior to the value being known (in the very first
|
|
71
|
+
* request from the user, when the cookie is still missing), zero value is used
|
|
72
|
+
* as the default value.
|
|
73
|
+
*
|
|
74
|
+
* @param {object} [options] Optional settings.
|
|
75
|
+
* @param {string} [options.cookieName="timezoneOffset"] Optional. The name of
|
|
76
|
+
* cookie to use to store the timezone offset. Defaults "timezoneOffset". Set
|
|
77
|
+
* to a falsy value to forbid using cookies altogether (in that case the hook
|
|
78
|
+
* will always return zero value at the server-side, and in the first render
|
|
79
|
+
* at the client-side).
|
|
80
|
+
* @param {string} [options.timezoneOffset="timezoneOffset"] Optional.
|
|
81
|
+
* The global state path to store the offset. Defaults "timezoneOffset".
|
|
82
|
+
* @return {number} Timezone offset.
|
|
83
|
+
*/
|
|
84
|
+
// TODO: Should we request the state type as generic parameter, to be able
|
|
85
|
+
// to verify the give globalStatePath is correct?
|
|
86
|
+
export function useTimezoneOffset({
|
|
87
|
+
cookieName = 'timezoneOffset',
|
|
88
|
+
globalStatePath = 'timezoneOffset',
|
|
89
|
+
} = {}) {
|
|
90
|
+
const ssrContext = getSsrContext(false);
|
|
91
|
+
const [offset, setOffset] = useGlobalState<ForceT, number>(globalStatePath, () => {
|
|
92
|
+
const value = cookieName && ssrContext?.req?.cookies?.[cookieName];
|
|
93
|
+
return value ? parseInt(value, 10) : 0;
|
|
94
|
+
});
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
const date = new Date();
|
|
97
|
+
const value = date.getTimezoneOffset();
|
|
98
|
+
setOffset(value);
|
|
99
|
+
if (cookieName) {
|
|
100
|
+
document.cookie = Cookie.serialize(cookieName, value.toString(), { path: '/' });
|
|
101
|
+
}
|
|
102
|
+
}, [cookieName, setOffset]);
|
|
103
|
+
return offset;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const time = {
|
|
107
|
+
DAY_MS,
|
|
108
|
+
HOUR_MS,
|
|
109
|
+
MIN_MS,
|
|
110
|
+
SEC_MS,
|
|
111
|
+
YEAR_MS,
|
|
112
|
+
now: Date.now,
|
|
113
|
+
timer,
|
|
114
|
+
useCurrent,
|
|
115
|
+
useTimezoneOffset,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export default Object.assign(dayjs, time);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IS_CLIENT_SIDE } from './isomorphy';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Requires the specified module without including it into the bundle during
|
|
5
|
+
* Webpack build.
|
|
6
|
+
* @param modulePath
|
|
7
|
+
* @param [basePath]
|
|
8
|
+
* @return Required module.
|
|
9
|
+
*/
|
|
10
|
+
export function requireWeak(
|
|
11
|
+
modulePath: string,
|
|
12
|
+
basePath?: string,
|
|
13
|
+
): NodeJS.Module | null {
|
|
14
|
+
if (IS_CLIENT_SIDE) return null;
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
/* eslint-disable no-eval */
|
|
18
|
+
const { resolve } = eval('require')('path');
|
|
19
|
+
const path = basePath ? resolve(basePath, modulePath) : modulePath;
|
|
20
|
+
const { default: def, ...named } = eval('require')(path);
|
|
21
|
+
/* eslint-enable no-eval */
|
|
22
|
+
|
|
23
|
+
if (!def) return named;
|
|
24
|
+
|
|
25
|
+
Object.entries(named).forEach(([key, value]) => {
|
|
26
|
+
if (def[key]) throw Error('Conflict between default and named exports');
|
|
27
|
+
def[key] = value;
|
|
28
|
+
});
|
|
29
|
+
return def;
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Resolves specified module path with help of Babel's module resolver.
|
|
37
|
+
* Yes, the function itself just returns its argument to the caller, but Babel
|
|
38
|
+
* is configured to resolve the first argument of resolveWeak(..) function, thus
|
|
39
|
+
* the result will be the resolved path.
|
|
40
|
+
* @param {string} modulePath
|
|
41
|
+
* @return {string} Absolute or relative path to the module.
|
|
42
|
+
*/
|
|
43
|
+
export function resolveWeak(modulePath: string): string {
|
|
44
|
+
return modulePath;
|
|
45
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* Eric Meyer's "Reset CSS" 2.0 */
|
|
2
|
+
|
|
3
|
+
/* http://meyerweb.com/eric/tools/css/reset/
|
|
4
|
+
v2.0 | 20110126
|
|
5
|
+
License: none (public domain)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* Having all selectors at individual lines is unreadable in the case of this
|
|
9
|
+
* style reset sheet. */
|
|
10
|
+
/* stylelint-disable selector-list-comma-newline-after */
|
|
11
|
+
a, abbr, acronym, address, applet, article, aside, audio, b, big, blockquote,
|
|
12
|
+
body, canvas, caption, center, cite, code, dd, del, details, dfn, div, dl, dt,
|
|
13
|
+
em, embed, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6,
|
|
14
|
+
header, hgroup, html, i, iframe, img, ins, kbd, label, legend, li, mark, menu,
|
|
15
|
+
nav, object, ol, output, p, pre, q, ruby, s, samp, section, small, span,
|
|
16
|
+
strike, strong,sub, summary, sup, table, tbody, td, tfoot, th, thead, time, tr,
|
|
17
|
+
tt, u, ul, var, video {
|
|
18
|
+
margin: 0;
|
|
19
|
+
padding: 0;
|
|
20
|
+
border: 0;
|
|
21
|
+
font: inherit;
|
|
22
|
+
font-size: 100%;
|
|
23
|
+
vertical-align: baseline;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* HTML5 display-role reset for older browsers */
|
|
27
|
+
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav,
|
|
28
|
+
section {
|
|
29
|
+
display: block;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
body {
|
|
33
|
+
line-height: 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ol, ul {
|
|
37
|
+
list-style: none;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
blockquote, q {
|
|
41
|
+
quotes: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
blockquote::before, blockquote::after, q::before, q::after {
|
|
45
|
+
content: "";
|
|
46
|
+
content: none;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
table {
|
|
50
|
+
border-collapse: collapse;
|
|
51
|
+
border-spacing: 0;
|
|
52
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// TS configuration for configs pre-building from TS sources.
|
|
2
|
+
|
|
3
|
+
{
|
|
4
|
+
"extends": "@tsconfig/recommended",
|
|
5
|
+
"include": [
|
|
6
|
+
"config-ts-src",
|
|
7
|
+
],
|
|
8
|
+
"compilerOptions": {
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"jsx": "react-jsx",
|
|
11
|
+
"rootDir": "config-ts-src",
|
|
12
|
+
"outDir": "config",
|
|
13
|
+
"paths": {
|
|
14
|
+
"*": ["./src/shared/*", "./src/*", "./*"]
|
|
15
|
+
},
|
|
16
|
+
"strict": true
|
|
17
|
+
}
|
|
18
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// TS config for ESLint, editor plugins, and other tools that look-up and use
|
|
2
|
+
// the default tsconfig.json file.
|
|
3
|
+
{
|
|
4
|
+
// Note: Full relative paths, as some tools don't support Node module
|
|
5
|
+
// resolution mechanics.
|
|
6
|
+
"extends": "./node_modules/@tsconfig/recommended/tsconfig.json",
|
|
7
|
+
|
|
8
|
+
"compilerOptions": {
|
|
9
|
+
"jsx": "react-jsx",
|
|
10
|
+
|
|
11
|
+
// BEWARE: Different settings are likely to transform dynamic import()
|
|
12
|
+
// statements in the code, thus breaking Webpack's code splitting.
|
|
13
|
+
// See: https://davidea.st/articles/webpack-typescript-code-split-wont-work
|
|
14
|
+
"module": "ESNext",
|
|
15
|
+
"moduleResolution": "Node",
|
|
16
|
+
|
|
17
|
+
"paths": {
|
|
18
|
+
"*": ["./src/shared/*", "./src/*", "./*"]
|
|
19
|
+
},
|
|
20
|
+
"rootDirs": [".", "build/types-scss"],
|
|
21
|
+
"strict": true,
|
|
22
|
+
|
|
23
|
+
// This ensures TypeScript does not remove unused imports, which may cause
|
|
24
|
+
// troubles when we rely on some side-effects from imported modules.
|
|
25
|
+
"verbatimModuleSyntax": true,
|
|
26
|
+
}
|
|
27
|
+
}
|