@dr.pogodin/react-utils 1.47.0-alpha.1 → 1.47.0-alpha.11
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 -1
- package/babel.module.config.js +11 -0
- package/bin/build.js +8 -4
- package/bin/setup.js +2 -3
- package/build/development/client/getInj.js +57 -44
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +15 -21
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +2 -6
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +3 -183
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +1 -8
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +22 -50
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +83 -92
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +58 -62
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +8 -31
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +2 -9
- package/build/development/server/utils/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +9 -16
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +6 -13
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +4 -10
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +11 -18
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +6 -13
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +16 -22
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +6 -13
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +7 -14
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +15 -22
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +7 -14
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +12 -18
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +16 -23
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +10 -17
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +16 -130
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +18 -19
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +24 -28
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +19 -19
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +12 -17
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +1 -7
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/components/selectors/index.js +3 -27
- package/build/development/shared/components/selectors/index.js.map +1 -1
- package/build/development/shared/utils/config.js +40 -21
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +3 -8
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +12 -89
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +2 -9
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +2 -8
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +7 -32
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +24 -31
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/global.js +1 -7
- package/build/development/shared/utils/jest/global.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +20 -44
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +54 -46
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +22 -31
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +17 -16
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js +13 -11
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js +3 -3
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js +2 -2
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js +2 -6
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js +3 -3
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +8 -8
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +24 -25
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +9 -11
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +9 -9
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/server/utils/index.js +2 -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 +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +4 -4
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +5 -5
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js +3 -3
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +7 -7
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +2 -2
- 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/TextArea/index.js +5 -5
- package/build/production/shared/components/TextArea/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 +4 -4
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +4 -4
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +4 -4
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +3 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +4 -4
- 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/components/selectors/common.js +2 -2
- package/build/production/shared/components/selectors/common.js.map +1 -1
- package/build/production/shared/components/selectors/index.js +1 -1
- package/build/production/shared/components/selectors/index.js.map +1 -1
- package/build/production/shared/utils/config.js +8 -6
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/globalState.js +2 -2
- package/build/production/shared/utils/globalState.js.map +1 -1
- package/build/production/shared/utils/index.js +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/buildInfo.js +3 -3
- package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/production/shared/utils/isomorphy/environment-check.js +3 -3
- package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js +4 -4
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +14 -14
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/global.js +1 -1
- package/build/production/shared/utils/jest/global.js.map +1 -1
- package/build/production/shared/utils/jest/index.js +11 -11
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +11 -22
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +3 -3
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js +6 -6
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/client/getInj.d.ts +1 -2
- package/build/types-code/client/index.d.ts +1 -1
- package/build/types-code/index.d.ts +1 -7
- package/build/types-code/server/index.d.ts +6 -11
- package/build/types-code/server/utils/index.d.ts +1 -1
- package/build/types-code/shared/utils/config.d.ts +4 -2
- package/build/types-code/shared/utils/index.d.ts +2 -2
- package/build/types-code/shared/utils/splitComponent.d.ts +6 -4
- package/build/web/client/getInj.js +55 -44
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/client/index.js +15 -21
- package/build/web/client/index.js.map +1 -1
- package/build/web/client/init.js +2 -4
- package/build/web/client/init.js.map +1 -1
- package/build/web/index.js +1 -15
- package/build/web/index.js.map +1 -1
- package/build/web/server/index.js +12 -21
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/renderer.js +34 -40
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +14 -11
- package/build/web/server/server.js.map +1 -1
- package/build/web/server/utils/index.js +1 -1
- package/build/web/server/utils/index.js.map +1 -1
- package/build/web/shared/components/Button/index.js +1 -1
- package/build/web/shared/components/Button/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/index.js +1 -1
- package/build/web/shared/components/Checkbox/index.js.map +1 -1
- package/build/web/shared/components/Input/index.js +1 -1
- package/build/web/shared/components/Input/index.js.map +1 -1
- package/build/web/shared/components/Modal/index.js +3 -3
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/components/PageLayout/index.js +1 -1
- package/build/web/shared/components/PageLayout/index.js.map +1 -1
- package/build/web/shared/components/TextArea/index.js +1 -1
- package/build/web/shared/components/TextArea/index.js.map +1 -1
- package/build/web/shared/components/Throbber/index.js +1 -1
- package/build/web/shared/components/Throbber/index.js.map +1 -1
- package/build/web/shared/components/WithTooltip/index.js +1 -1
- package/build/web/shared/components/WithTooltip/index.js.map +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +3 -0
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +3 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js +4 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +2 -1
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/web/shared/utils/config.js +38 -14
- package/build/web/shared/utils/config.js.map +1 -1
- package/build/web/shared/utils/index.js +2 -2
- package/build/web/shared/utils/index.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv.js +3 -2
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/web/shared/utils/splitComponent.js +27 -20
- package/build/web/shared/utils/splitComponent.js.map +1 -1
- package/build/web/shared/utils/webpack.js +13 -7
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/node-ssr.js +12 -6
- package/config/babel/webpack.js +6 -1
- package/config/jest/default.js +8 -2
- package/config/jest/setup.js +8 -1
- package/config/webpack/app-base.js +23 -15
- package/config/webpack/app-development.js +2 -3
- package/config/webpack/lib-base.js +1 -2
- package/package.json +35 -25
- package/types.d.ts +1 -6
- package/node-entry.js +0 -15
- package/src/client/getInj.ts +0 -51
- package/src/client/index.tsx +0 -43
- package/src/client/init.ts +0 -52
- package/src/index.ts +0 -79
- package/src/server/Cache.ts +0 -61
- package/src/server/index.ts +0 -249
- package/src/server/renderer.tsx +0 -653
- package/src/server/server.ts +0 -332
- package/src/server/utils/errors.ts +0 -122
- package/src/server/utils/index.ts +0 -3
- package/src/shared/components/Button/index.tsx +0 -130
- package/src/shared/components/Button/style.scss +0 -54
- package/src/shared/components/Checkbox/index.tsx +0 -53
- package/src/shared/components/Checkbox/theme.scss +0 -63
- package/src/shared/components/GenericLink/index.tsx +0 -141
- package/src/shared/components/GenericLink/style.scss +0 -3
- package/src/shared/components/Input/index.tsx +0 -96
- package/src/shared/components/Input/theme.scss +0 -52
- package/src/shared/components/Link.tsx +0 -25
- package/src/shared/components/Modal/base-theme.scss +0 -38
- package/src/shared/components/Modal/index.tsx +0 -177
- package/src/shared/components/Modal/styles.scss +0 -3
- package/src/shared/components/NavLink.tsx +0 -18
- package/src/shared/components/PageLayout/base-theme.scss +0 -30
- package/src/shared/components/PageLayout/index.tsx +0 -51
- package/src/shared/components/TextArea/index.tsx +0 -139
- package/src/shared/components/TextArea/style.scss +0 -68
- package/src/shared/components/Throbber/index.tsx +0 -28
- package/src/shared/components/Throbber/theme.scss +0 -26
- package/src/shared/components/WithTooltip/Tooltip.tsx +0 -274
- package/src/shared/components/WithTooltip/default-theme.scss +0 -36
- package/src/shared/components/WithTooltip/index.tsx +0 -186
- package/src/shared/components/YouTubeVideo/base.scss +0 -15
- package/src/shared/components/YouTubeVideo/index.tsx +0 -73
- package/src/shared/components/YouTubeVideo/throbber.scss +0 -11
- package/src/shared/components/index.ts +0 -20
- package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -124
- package/src/shared/components/selectors/CustomDropdown/Options/style.scss +0 -6
- package/src/shared/components/selectors/CustomDropdown/index.tsx +0 -146
- package/src/shared/components/selectors/CustomDropdown/theme.scss +0 -118
- package/src/shared/components/selectors/NativeDropdown/index.tsx +0 -90
- package/src/shared/components/selectors/NativeDropdown/theme.scss +0 -81
- package/src/shared/components/selectors/Switch/index.tsx +0 -74
- package/src/shared/components/selectors/Switch/theme.scss +0 -39
- package/src/shared/components/selectors/common.ts +0 -57
- package/src/shared/components/selectors/index.ts +0 -8
- package/src/shared/utils/config.ts +0 -28
- package/src/shared/utils/globalState.ts +0 -44
- package/src/shared/utils/index.ts +0 -45
- package/src/shared/utils/isomorphy/buildInfo.ts +0 -50
- package/src/shared/utils/isomorphy/environment-check.ts +0 -18
- package/src/shared/utils/isomorphy/index.ts +0 -36
- package/src/shared/utils/jest/E2eSsrEnv.ts +0 -305
- package/src/shared/utils/jest/global.ts +0 -17
- package/src/shared/utils/jest/index.ts +0 -215
- package/src/shared/utils/splitComponent.tsx +0 -275
- package/src/shared/utils/time.ts +0 -101
- package/src/shared/utils/webpack.ts +0 -74
- package/src/styles/_global/reset.css +0 -52
- package/src/styles/_mixins/fonts.scss +0 -40
- package/src/styles/_mixins/media.scss +0 -150
- package/src/styles/_mixins/typography.scss +0 -83
- package/src/styles/global.scss +0 -11
- package/src/styles/mixins.scss +0 -6
package/src/server/server.ts
DELETED
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creation of standard ExpressJS server for ReactJS apps.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { sep } from 'node:path';
|
|
6
|
-
import { pathToFileURL } from 'node:url';
|
|
7
|
-
|
|
8
|
-
import cloneDeep from 'lodash/cloneDeep';
|
|
9
|
-
import mapValues from 'lodash/mapValues';
|
|
10
|
-
import pick from 'lodash/pick';
|
|
11
|
-
|
|
12
|
-
import compression from 'compression';
|
|
13
|
-
import cookieParser from 'cookie-parser';
|
|
14
|
-
import csrf from '@dr.pogodin/csurf';
|
|
15
|
-
|
|
16
|
-
import express, {
|
|
17
|
-
type Express,
|
|
18
|
-
type NextFunction,
|
|
19
|
-
type RequestHandler,
|
|
20
|
-
type Request,
|
|
21
|
-
type Response,
|
|
22
|
-
} from 'express';
|
|
23
|
-
|
|
24
|
-
import favicon from 'serve-favicon';
|
|
25
|
-
import helmet, { type HelmetOptions } from 'helmet';
|
|
26
|
-
import loggerMiddleware from 'morgan';
|
|
27
|
-
import requestIp from 'request-ip';
|
|
28
|
-
import { v4 as uuid } from 'uuid';
|
|
29
|
-
|
|
30
|
-
import type { Compiler, Configuration } from 'webpack';
|
|
31
|
-
|
|
32
|
-
import rendererFactory, {
|
|
33
|
-
type LoggerI,
|
|
34
|
-
type OptionsT as RendererOptionsT,
|
|
35
|
-
} from './renderer';
|
|
36
|
-
|
|
37
|
-
import {
|
|
38
|
-
CODES,
|
|
39
|
-
ERRORS,
|
|
40
|
-
getErrorForCode,
|
|
41
|
-
newError,
|
|
42
|
-
} from './utils/errors';
|
|
43
|
-
|
|
44
|
-
export type CspOptionsT = Exclude<HelmetOptions['contentSecurityPolicy'], boolean | undefined>;
|
|
45
|
-
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
47
|
-
interface RequestT extends Request {
|
|
48
|
-
cspNonce: string;
|
|
49
|
-
nonce: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Default Content Security Policy settings.
|
|
54
|
-
* @ignore
|
|
55
|
-
*/
|
|
56
|
-
const defaultCspSettings = {
|
|
57
|
-
directives: mapValues(
|
|
58
|
-
helmet.contentSecurityPolicy.getDefaultDirectives(),
|
|
59
|
-
|
|
60
|
-
// 'https:' options (automatic re-write of insecure URLs to secure ones)
|
|
61
|
-
// is removed to facilitate local development with HTTP server. In cloud
|
|
62
|
-
// deployments we assume Apache or Nginx server in front of out app takes
|
|
63
|
-
// care about such re-writes.
|
|
64
|
-
(array) => (array as string[]).filter((item: string) => item !== 'https:'),
|
|
65
|
-
),
|
|
66
|
-
};
|
|
67
|
-
defaultCspSettings.directives['frame-src'] = [
|
|
68
|
-
"'self'",
|
|
69
|
-
|
|
70
|
-
// YouTube domain is whitelisted to allow <YouTubeVideo> component to work
|
|
71
|
-
// out of box.
|
|
72
|
-
'https://*.youtube.com',
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
{
|
|
76
|
-
const directives = defaultCspSettings.directives['script-src'];
|
|
77
|
-
if (directives) directives.push("'unsafe-eval'");
|
|
78
|
-
else defaultCspSettings.directives['script-src'] = ["'unsafe-eval'"];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// No need for automatic re-writes via Content Security Policy settings:
|
|
82
|
-
// the forefront Apache or Nginx server is supposed to take care of this
|
|
83
|
-
// in production cloud deployments.
|
|
84
|
-
delete defaultCspSettings.directives['upgrade-insecure-requests'];
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @category Utilities
|
|
88
|
-
* @func server/getDefaultCspSettings
|
|
89
|
-
* @global
|
|
90
|
-
* @desc
|
|
91
|
-
* ```js
|
|
92
|
-
* import { server } from '@dr.pogodin/react-utils';
|
|
93
|
-
* const { getDefaultCspSettings } from '@dr.pogodin/react-utils';
|
|
94
|
-
* ```
|
|
95
|
-
* @return {{
|
|
96
|
-
* directives: object
|
|
97
|
-
* }} A deep copy of default CSP settings object used by `react-utils`,
|
|
98
|
-
* with the exception of `nonce-xxx` clause in `script-src` directive,
|
|
99
|
-
* which is added dynamically for each request.
|
|
100
|
-
*/
|
|
101
|
-
export function getDefaultCspSettings(): {
|
|
102
|
-
directives: Record<string, string[]>;
|
|
103
|
-
} {
|
|
104
|
-
return cloneDeep(defaultCspSettings);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export type ServerT = Express & {
|
|
108
|
-
logger: LoggerI;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export type OptionsT = RendererOptionsT & {
|
|
112
|
-
beforeExpressJsError?:
|
|
113
|
-
(server: ServerT) => boolean | Promise<boolean>;
|
|
114
|
-
|
|
115
|
-
beforeExpressJsSetup?: (server: ServerT) => Promise<void> | void;
|
|
116
|
-
cookieSignatureSecret?: string;
|
|
117
|
-
cspSettingsHook?: (
|
|
118
|
-
defaultOptions: CspOptionsT,
|
|
119
|
-
req: Request,
|
|
120
|
-
) => CspOptionsT;
|
|
121
|
-
devMode?: boolean;
|
|
122
|
-
httpsRedirect?: boolean;
|
|
123
|
-
onExpressJsSetup?: (server: ServerT) => Promise<void> | void;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export default async function factory(
|
|
127
|
-
webpackConfig: Configuration,
|
|
128
|
-
options: OptionsT,
|
|
129
|
-
): Promise<ServerT> {
|
|
130
|
-
const rendererOps: RendererOptionsT = pick(options, [
|
|
131
|
-
'Application',
|
|
132
|
-
'beforeRender',
|
|
133
|
-
'favicon',
|
|
134
|
-
'logger',
|
|
135
|
-
'maxSsrRounds',
|
|
136
|
-
'noCsp',
|
|
137
|
-
'ssrTimeout',
|
|
138
|
-
'staticCacheController',
|
|
139
|
-
'staticCacheSize',
|
|
140
|
-
]);
|
|
141
|
-
const renderer = rendererFactory(webpackConfig, rendererOps);
|
|
142
|
-
const { publicPath } = webpackConfig.output!;
|
|
143
|
-
|
|
144
|
-
const server = express() as ServerT;
|
|
145
|
-
|
|
146
|
-
if (options.beforeExpressJsSetup) {
|
|
147
|
-
await options.beforeExpressJsSetup(server);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (options.logger) server.logger = options.logger;
|
|
151
|
-
|
|
152
|
-
if (options.httpsRedirect) {
|
|
153
|
-
server.use((req, res, next) => {
|
|
154
|
-
const schema = req.headers['x-forwarded-proto'];
|
|
155
|
-
if (schema === 'http') {
|
|
156
|
-
let url = `https://${req.headers.host}`;
|
|
157
|
-
if (req.originalUrl !== '/') url += req.originalUrl;
|
|
158
|
-
res.redirect(url);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
next();
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
server.use(compression());
|
|
166
|
-
server.use(
|
|
167
|
-
helmet({
|
|
168
|
-
contentSecurityPolicy: false,
|
|
169
|
-
crossOriginEmbedderPolicy: false,
|
|
170
|
-
crossOriginOpenerPolicy: false,
|
|
171
|
-
crossOriginResourcePolicy: false,
|
|
172
|
-
}),
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
if (!options.noCsp) {
|
|
176
|
-
server.use(
|
|
177
|
-
(req: Request, res: Response, next: NextFunction) => {
|
|
178
|
-
const req2 = req as RequestT;
|
|
179
|
-
|
|
180
|
-
req2.nonce = uuid();
|
|
181
|
-
|
|
182
|
-
// TODO: This is deprecated, but it is kept for now for backward
|
|
183
|
-
// compatibility. Should be removed sometime later.
|
|
184
|
-
req2.cspNonce = req2.nonce;
|
|
185
|
-
|
|
186
|
-
// The deep clone is necessary here to ensure that default value can't be
|
|
187
|
-
// mutated during request processing.
|
|
188
|
-
let cspSettings: CspOptionsT = cloneDeep(defaultCspSettings);
|
|
189
|
-
(cspSettings.directives?.['script-src'] as string[]).push(`'nonce-${req2.nonce}'`);
|
|
190
|
-
if (options.cspSettingsHook) {
|
|
191
|
-
cspSettings = options.cspSettingsHook(cspSettings, req);
|
|
192
|
-
}
|
|
193
|
-
helmet.contentSecurityPolicy(cspSettings)(req, res, next);
|
|
194
|
-
},
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (options.favicon) {
|
|
199
|
-
server.use(favicon(options.favicon));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
server.use('/robots.txt', (req, res) => {
|
|
203
|
-
res.send('User-agent: *\nDisallow:');
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
server.use(express.json({ limit: '300kb' }));
|
|
207
|
-
server.use(express.urlencoded({ extended: false }));
|
|
208
|
-
server.use(cookieParser(options.cookieSignatureSecret));
|
|
209
|
-
server.use(requestIp.mw());
|
|
210
|
-
|
|
211
|
-
server.use(csrf({ cookie: true }));
|
|
212
|
-
|
|
213
|
-
loggerMiddleware.token(
|
|
214
|
-
'ip',
|
|
215
|
-
(req: Request & { clientIp: string }) => req.clientIp,
|
|
216
|
-
);
|
|
217
|
-
const FORMAT = ':ip > :status :method :url :response-time ms :res[content-length] :referrer :user-agent';
|
|
218
|
-
server.use(loggerMiddleware(FORMAT, {
|
|
219
|
-
stream: {
|
|
220
|
-
// TODO: This implies the logger is always set. Is it on a higher level?
|
|
221
|
-
// then mark it as always present.
|
|
222
|
-
write: options.logger!.info.bind(options.logger),
|
|
223
|
-
},
|
|
224
|
-
}));
|
|
225
|
-
|
|
226
|
-
// Note: no matter the "public path", we want the service worker, if any,
|
|
227
|
-
// to be served from the root, to have all web app pages in its scope.
|
|
228
|
-
// Thus, this setup to serve it. Probably, need some more configuration
|
|
229
|
-
// for special cases, but this will do for now.
|
|
230
|
-
server.get('/__service-worker.js', express.static(
|
|
231
|
-
webpackConfig.output?.path ?? '',
|
|
232
|
-
{
|
|
233
|
-
setHeaders: (res) => res.set('Cache-Control', 'no-cache'),
|
|
234
|
-
},
|
|
235
|
-
));
|
|
236
|
-
|
|
237
|
-
/* Setup of Hot Module Reloading for development environment.
|
|
238
|
-
* These dependencies are not used, nor installed for production use,
|
|
239
|
-
* hence we should violate some import-related lint rules. */
|
|
240
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
241
|
-
if (options.devMode) {
|
|
242
|
-
// This is a workaround for SASS bug:
|
|
243
|
-
// https://github.com/dart-lang/sdk/issues/27979
|
|
244
|
-
// which manifests itself sometimes when webpack dev middleware is used
|
|
245
|
-
// (in dev mode), and app modules are imported in some unfortunate ways.
|
|
246
|
-
// TODO: Double-check, what is going on here.
|
|
247
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
248
|
-
if (!global.location) {
|
|
249
|
-
global.location = {
|
|
250
|
-
href: `${pathToFileURL(process.cwd()).href}${sep}`,
|
|
251
|
-
} as Location;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
255
|
-
const webpack = require('webpack') as (ops: Configuration) => Compiler;
|
|
256
|
-
|
|
257
|
-
// TODO: Figure out the exact type for options, don't wanna waste time on it
|
|
258
|
-
// right now.
|
|
259
|
-
const webpackDevMiddleware = require('webpack-dev-middleware') as
|
|
260
|
-
(c: Compiler, ops: unknown) => RequestHandler;
|
|
261
|
-
|
|
262
|
-
const webpackHotMiddleware = require('webpack-hot-middleware') as
|
|
263
|
-
(c: Compiler) => RequestHandler;
|
|
264
|
-
|
|
265
|
-
const compiler = webpack(webpackConfig);
|
|
266
|
-
server.use(webpackDevMiddleware(compiler, {
|
|
267
|
-
publicPath,
|
|
268
|
-
serverSideRender: true,
|
|
269
|
-
}));
|
|
270
|
-
server.use(webpackHotMiddleware(compiler));
|
|
271
|
-
}
|
|
272
|
-
/* eslint-enable import/no-extraneous-dependencies */
|
|
273
|
-
|
|
274
|
-
server.use(publicPath as string, express.static(webpackConfig.output!.path!));
|
|
275
|
-
|
|
276
|
-
if (options.onExpressJsSetup) {
|
|
277
|
-
await options.onExpressJsSetup(server);
|
|
278
|
-
}
|
|
279
|
-
server.use(renderer);
|
|
280
|
-
|
|
281
|
-
/* Detects 404 errors, and forwards them to the error handler. */
|
|
282
|
-
server.use((req, res, next) => {
|
|
283
|
-
next(newError(ERRORS.NOT_FOUND, CODES.NOT_FOUND));
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
let dontAttachDefaultErrorHandler;
|
|
287
|
-
if (options.beforeExpressJsError) {
|
|
288
|
-
dontAttachDefaultErrorHandler = await options.beforeExpressJsError(server);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/* Error handler. */
|
|
292
|
-
if (!dontAttachDefaultErrorHandler) {
|
|
293
|
-
// TODO: Do we need this error handler at all? It actually seems to do
|
|
294
|
-
// what the default ExpressJS error handler does anyway, see:
|
|
295
|
-
// https://expressjs.com/en/guide/error-handling.html
|
|
296
|
-
//
|
|
297
|
-
// TODO: It is better to move the default error handler definition
|
|
298
|
-
// to a stand-alone function at top-level, but the use of options.logger
|
|
299
|
-
// prevents to do it without some extra refactoring. Should be done sometime
|
|
300
|
-
// though.
|
|
301
|
-
server.use((
|
|
302
|
-
error: Error & {
|
|
303
|
-
status?: number;
|
|
304
|
-
},
|
|
305
|
-
req: Request,
|
|
306
|
-
res: Response,
|
|
307
|
-
next: NextFunction,
|
|
308
|
-
) => {
|
|
309
|
-
// TODO: This is needed to correctly handled any errors thrown after
|
|
310
|
-
// sending initial response to the client.
|
|
311
|
-
if (res.headersSent) {
|
|
312
|
-
next(error);
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
const status = error.status ?? CODES.INTERNAL_SERVER_ERROR;
|
|
317
|
-
const serverSide = status >= (CODES.INTERNAL_SERVER_ERROR as number);
|
|
318
|
-
|
|
319
|
-
// Log server-side errors always, client-side at debug level only.
|
|
320
|
-
options.logger!.log(serverSide ? 'error' : 'debug', error.toString());
|
|
321
|
-
|
|
322
|
-
let message = error.message || getErrorForCode(status);
|
|
323
|
-
if (serverSide && process.env.NODE_ENV === 'production') {
|
|
324
|
-
message = ERRORS.INTERNAL_SERVER_ERROR;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
res.status(status).send(message);
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return server;
|
|
332
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @category Utilities
|
|
3
|
-
* @module server/errors
|
|
4
|
-
* @desc
|
|
5
|
-
* ```js
|
|
6
|
-
* import { server } from '@dr.pogodin/react-utils';
|
|
7
|
-
* const { errors } = server;
|
|
8
|
-
* ```
|
|
9
|
-
* Server-side helpers for error handling.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
StatusCodes as CODES,
|
|
14
|
-
ReasonPhrases as ERRORS,
|
|
15
|
-
getReasonPhrase as getErrorForCode,
|
|
16
|
-
} from 'http-status-codes';
|
|
17
|
-
|
|
18
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @static
|
|
22
|
-
* @const CODES
|
|
23
|
-
* @desc An alias for
|
|
24
|
-
* [StatusCodes object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).
|
|
25
|
-
* It is a map between HTTP status code names and corresponding numeric codes.
|
|
26
|
-
* @example
|
|
27
|
-
* import { server } from '@dr.pogodin/react-utils';
|
|
28
|
-
* const { CODES } = server.errors;
|
|
29
|
-
* console.log(CODES.BAD_REQUEST); // Prints: 400
|
|
30
|
-
*/
|
|
31
|
-
export { CODES };
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @static
|
|
35
|
-
* @const ERRORS
|
|
36
|
-
* @desc An alias for
|
|
37
|
-
* [ReasonPhrases object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).
|
|
38
|
-
* It is a map between HTTP status code names and their pretty-printed forms.
|
|
39
|
-
* @example
|
|
40
|
-
* import { server } from '@dr.pogodin/react-utils';
|
|
41
|
-
* const { ERRORS } = server.errors;
|
|
42
|
-
* console.log(ERRORS.BAD_REQUEST); // Prints: Bad Request
|
|
43
|
-
*/
|
|
44
|
-
export { ERRORS };
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @static
|
|
48
|
-
* @func getErrorForCode
|
|
49
|
-
* @desc An alias for
|
|
50
|
-
* [getReasonPhrase() function from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).
|
|
51
|
-
* Given an HTTP code it returns the corresponding error text.
|
|
52
|
-
* @param {number} code HTTP code.
|
|
53
|
-
* @return {string} HTTP error text.
|
|
54
|
-
* @example
|
|
55
|
-
* import { server } from '@dr.pogodin/react-utils';
|
|
56
|
-
* console.log(server.errors.getErrorForCode(400)); // Prints: Bad Request
|
|
57
|
-
*/
|
|
58
|
-
export { getErrorForCode };
|
|
59
|
-
|
|
60
|
-
// TODO: It could accept the status code as a constructor argument.
|
|
61
|
-
class ErrorWithStatus extends Error {
|
|
62
|
-
status: number = CODES.INTERNAL_SERVER_ERROR;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* ```js
|
|
67
|
-
* import { server } from '@dr.pogodin/react-utils';
|
|
68
|
-
* const { newError } = server.errors;
|
|
69
|
-
* ```
|
|
70
|
-
* Creates a new `Error` object with given message, and HTTP status code
|
|
71
|
-
* attached as `status` field.
|
|
72
|
-
* @param {string} message Error message.
|
|
73
|
-
* @param {number} [statusCode=500] HTTP status code. Defaults to 500 (Internal
|
|
74
|
-
* Server Error).
|
|
75
|
-
* @return {Error}
|
|
76
|
-
*/
|
|
77
|
-
export function newError(
|
|
78
|
-
message: string,
|
|
79
|
-
statusCode = CODES.INTERNAL_SERVER_ERROR,
|
|
80
|
-
): ErrorWithStatus {
|
|
81
|
-
const error = new ErrorWithStatus(message);
|
|
82
|
-
error.status = statusCode;
|
|
83
|
-
return error;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Throws an error with given message and HTTP status code.
|
|
88
|
-
*/
|
|
89
|
-
export function fail(
|
|
90
|
-
message: string,
|
|
91
|
-
statusCode: CODES = CODES.INTERNAL_SERVER_ERROR,
|
|
92
|
-
): Error {
|
|
93
|
-
throw newError(message, statusCode);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Validates the `value` against the given "standard" validation `schema`.
|
|
98
|
-
* Resolves to the correctly typed `value`, if it has passed the validation;
|
|
99
|
-
* otherwise throws an error.
|
|
100
|
-
* @param value The value to validate.
|
|
101
|
-
* @param schema The "standard" validation schema to use.
|
|
102
|
-
* @param [message] Optional error message, to prepend the validation error
|
|
103
|
-
* message.
|
|
104
|
-
* @param [statusCode=400] HTTP status code. Defaults to 400 (Bad Request).
|
|
105
|
-
*/
|
|
106
|
-
export async function assert<T extends StandardSchemaV1>(
|
|
107
|
-
value: unknown,
|
|
108
|
-
schema: T,
|
|
109
|
-
message = '',
|
|
110
|
-
statusCode = CODES.BAD_REQUEST,
|
|
111
|
-
): Promise<StandardSchemaV1.InferOutput<T>> {
|
|
112
|
-
let result = schema['~standard'].validate(value);
|
|
113
|
-
if (result instanceof Promise) result = await result;
|
|
114
|
-
|
|
115
|
-
if (result.issues) {
|
|
116
|
-
let error = JSON.stringify(result.issues, null, 2);
|
|
117
|
-
if (message) error = `${message}\n\n${error}`;
|
|
118
|
-
throw fail(error, statusCode);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return result.value;
|
|
122
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// The <Button> component implements a standard button / button-like link.
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
FunctionComponent,
|
|
5
|
-
KeyboardEventHandler,
|
|
6
|
-
MouseEventHandler,
|
|
7
|
-
PointerEventHandler,
|
|
8
|
-
ReactNode,
|
|
9
|
-
} from 'react';
|
|
10
|
-
|
|
11
|
-
import themed, { type Theme } from '@dr.pogodin/react-themes';
|
|
12
|
-
|
|
13
|
-
import Link from 'components/Link';
|
|
14
|
-
|
|
15
|
-
import defaultTheme from './style.scss';
|
|
16
|
-
|
|
17
|
-
type PropsT = {
|
|
18
|
-
active?: boolean;
|
|
19
|
-
children?: ReactNode;
|
|
20
|
-
disabled?: boolean;
|
|
21
|
-
enforceA?: boolean;
|
|
22
|
-
onClick?: MouseEventHandler & KeyboardEventHandler;
|
|
23
|
-
onKeyDown?: KeyboardEventHandler;
|
|
24
|
-
onKeyUp?: KeyboardEventHandler;
|
|
25
|
-
onMouseDown?: MouseEventHandler;
|
|
26
|
-
onMouseUp?: MouseEventHandler;
|
|
27
|
-
onPointerDown?: PointerEventHandler;
|
|
28
|
-
onPointerUp?: PointerEventHandler;
|
|
29
|
-
openNewTab?: boolean;
|
|
30
|
-
replace?: boolean;
|
|
31
|
-
testId?: string;
|
|
32
|
-
theme: Theme<'active' | 'button' | 'disabled'>;
|
|
33
|
-
// TODO: It needs a more precise typing of the object option.
|
|
34
|
-
to?: object | string;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const BaseButton: FunctionComponent<PropsT> = ({
|
|
38
|
-
active,
|
|
39
|
-
children,
|
|
40
|
-
disabled,
|
|
41
|
-
enforceA,
|
|
42
|
-
onClick,
|
|
43
|
-
onKeyDown: onKeyDownProp,
|
|
44
|
-
onKeyUp,
|
|
45
|
-
onMouseDown,
|
|
46
|
-
onMouseUp,
|
|
47
|
-
onPointerDown,
|
|
48
|
-
onPointerUp,
|
|
49
|
-
openNewTab,
|
|
50
|
-
replace,
|
|
51
|
-
testId,
|
|
52
|
-
theme,
|
|
53
|
-
to,
|
|
54
|
-
}) => {
|
|
55
|
-
let className = theme.button;
|
|
56
|
-
if (active && theme.active) className += ` ${theme.active}`;
|
|
57
|
-
if (disabled) {
|
|
58
|
-
if (theme.disabled) className += ` ${theme.disabled}`;
|
|
59
|
-
return (
|
|
60
|
-
<div
|
|
61
|
-
className={className}
|
|
62
|
-
data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}
|
|
63
|
-
>
|
|
64
|
-
{children}
|
|
65
|
-
</div>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
let onKeyDown = onKeyDownProp;
|
|
70
|
-
if (!onKeyDown && onClick) {
|
|
71
|
-
onKeyDown = (e) => {
|
|
72
|
-
if (e.key === 'Enter') onClick(e);
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (to) {
|
|
77
|
-
return (
|
|
78
|
-
<Link
|
|
79
|
-
className={className}
|
|
80
|
-
data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}
|
|
81
|
-
enforceA={enforceA}
|
|
82
|
-
onClick={onClick}
|
|
83
|
-
|
|
84
|
-
// TODO: For now, the `onKeyDown` handler is not passed to the <Link>,
|
|
85
|
-
// as <Link> component does not call it anyway, presumably due to
|
|
86
|
-
// the inner implementation details. We should look into supporting it:
|
|
87
|
-
// https://github.com/birdofpreyru/react-utils/issues/444
|
|
88
|
-
// onKeyDown={onKeyDown}
|
|
89
|
-
|
|
90
|
-
onKeyUp={onKeyUp}
|
|
91
|
-
onMouseDown={onMouseDown}
|
|
92
|
-
onMouseUp={onMouseUp}
|
|
93
|
-
onPointerDown={onPointerDown}
|
|
94
|
-
onPointerUp={onPointerUp}
|
|
95
|
-
openNewTab={openNewTab}
|
|
96
|
-
replace={replace}
|
|
97
|
-
to={to}
|
|
98
|
-
>
|
|
99
|
-
{children}
|
|
100
|
-
</Link>
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<div
|
|
106
|
-
className={className}
|
|
107
|
-
data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}
|
|
108
|
-
onClick={onClick}
|
|
109
|
-
onKeyDown={onKeyDown}
|
|
110
|
-
onKeyUp={onKeyUp}
|
|
111
|
-
onMouseDown={onMouseDown}
|
|
112
|
-
onMouseUp={onMouseUp}
|
|
113
|
-
onPointerDown={onPointerDown}
|
|
114
|
-
onPointerUp={onPointerUp}
|
|
115
|
-
role="button"
|
|
116
|
-
tabIndex={0}
|
|
117
|
-
>
|
|
118
|
-
{children}
|
|
119
|
-
</div>
|
|
120
|
-
);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Button component theme: a map of CSS
|
|
125
|
-
* class names to append to button elements:
|
|
126
|
-
* @prop {string} [active] to the root element of active button.
|
|
127
|
-
* @prop {string} [button] to the root element of any button.
|
|
128
|
-
* @prop {string} [disabled] to the root element of disabled button.
|
|
129
|
-
*/
|
|
130
|
-
export default themed(BaseButton, 'Button', defaultTheme);
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The default button theme.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
*,
|
|
6
|
-
.context,
|
|
7
|
-
.ad.hoc {
|
|
8
|
-
&.button {
|
|
9
|
-
background-image: linear-gradient(to top, lightgray, white 50%, white);
|
|
10
|
-
border: solid 1px gray;
|
|
11
|
-
border-radius: 0.3em;
|
|
12
|
-
color: inherit;
|
|
13
|
-
cursor: pointer;
|
|
14
|
-
display: inline-block;
|
|
15
|
-
font: inherit;
|
|
16
|
-
margin: 0.1em;
|
|
17
|
-
padding: 0.3em 1.2em;
|
|
18
|
-
text-align: center;
|
|
19
|
-
text-decoration: none;
|
|
20
|
-
user-select: none;
|
|
21
|
-
|
|
22
|
-
&:visited {
|
|
23
|
-
color: inherit;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
&.active,
|
|
27
|
-
&:active {
|
|
28
|
-
background-image: linear-gradient(to bottom, lightgray, white 50%, white);
|
|
29
|
-
box-shadow: inset 0 1px 3px 0 lightgray;
|
|
30
|
-
border-color: gray;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
&:focus {
|
|
34
|
-
box-shadow: 0 0 3px 1px lightblue;
|
|
35
|
-
border-color: blue;
|
|
36
|
-
outline: none;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/* Additional styling of disabled buttons. */
|
|
41
|
-
&.disabled {
|
|
42
|
-
cursor: not-allowed;
|
|
43
|
-
opacity: 0.33;
|
|
44
|
-
|
|
45
|
-
// Note: this "cancels out" the active state styling of an active button,
|
|
46
|
-
// which is defined above, thus ensuring a click on disabled button does
|
|
47
|
-
// not alter its appearance (does not result in visual press).
|
|
48
|
-
&.active,
|
|
49
|
-
&:active {
|
|
50
|
-
background-image: linear-gradient(to top, lightgray, white 50%, white);
|
|
51
|
-
box-shadow: none;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import themed, { type Theme } from '@dr.pogodin/react-themes';
|
|
2
|
-
|
|
3
|
-
import defaultTheme from './theme.scss';
|
|
4
|
-
|
|
5
|
-
type PropT<ValueT> = {
|
|
6
|
-
checked?: ValueT;
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
label?: React.ReactNode;
|
|
9
|
-
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
10
|
-
testId?: string;
|
|
11
|
-
theme: Theme<
|
|
12
|
-
| 'checkbox'
|
|
13
|
-
| 'container'
|
|
14
|
-
| 'disabled'
|
|
15
|
-
| 'indeterminate'
|
|
16
|
-
| 'label'
|
|
17
|
-
>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const Checkbox = <ValueT extends boolean | 'indeterminate' = boolean>({
|
|
21
|
-
checked,
|
|
22
|
-
disabled,
|
|
23
|
-
label,
|
|
24
|
-
onChange,
|
|
25
|
-
testId,
|
|
26
|
-
theme,
|
|
27
|
-
}: PropT<ValueT>) => {
|
|
28
|
-
let containerClassName = theme.container;
|
|
29
|
-
if (disabled) containerClassName += ` ${theme.disabled}`;
|
|
30
|
-
|
|
31
|
-
let checkboxClassName = theme.checkbox;
|
|
32
|
-
if (checked === 'indeterminate') checkboxClassName += ` ${theme.indeterminate}`;
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<div className={containerClassName}>
|
|
36
|
-
{ label === undefined
|
|
37
|
-
? null : <div className={theme.label}>{label}</div> }
|
|
38
|
-
<input
|
|
39
|
-
checked={checked === undefined ? undefined : checked === true}
|
|
40
|
-
className={checkboxClassName}
|
|
41
|
-
data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}
|
|
42
|
-
disabled={disabled}
|
|
43
|
-
onChange={onChange}
|
|
44
|
-
onClick={(e) => {
|
|
45
|
-
e.stopPropagation();
|
|
46
|
-
}}
|
|
47
|
-
type="checkbox"
|
|
48
|
-
/>
|
|
49
|
-
</div>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export default themed(Checkbox, 'Checkbox', defaultTheme);
|