@dr.pogodin/react-utils 1.49.1 → 1.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.scripts.config.js +19 -0
- package/build/development/client/getInj.js +18 -29
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +11 -14
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +9 -17
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +26 -4
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +15 -20
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +142 -160
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +150 -197
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +63 -86
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +72 -87
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/shared/components/Button/index.js +8 -17
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +4 -4
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +54 -58
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +16 -24
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +2 -5
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +28 -41
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +2 -3
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +19 -20
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +12 -28
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +11 -12
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +46 -68
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +21 -28
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +21 -25
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +1 -3
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +6 -7
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +7 -9
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +23 -27
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +4 -4
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +2 -5
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/utils/config.js +11 -15
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +1 -7
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +2 -2
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +15 -24
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +4 -9
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +17 -23
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +48 -77
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +48 -72
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +67 -74
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +25 -28
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +22 -29
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js.map +1 -1
- package/build/production/index.js +26 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js.map +1 -1
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +2 -2
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +20 -3
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/shared/components/GenericLink/index.d.ts +0 -1
- package/build/web/client/getInj.js +10 -70
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/client/index.js +2 -27
- package/build/web/client/index.js.map +1 -1
- package/build/web/client/init.js +10 -44
- package/build/web/client/init.js.map +1 -1
- package/build/web/index.js +26 -6
- package/build/web/index.js.map +1 -1
- package/build/web/server/Cache.js +3 -41
- package/build/web/server/Cache.js.map +1 -1
- package/build/web/server/index.js +7 -78
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/renderer.js +61 -420
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +38 -212
- package/build/web/server/server.js.map +1 -1
- package/build/web/server/utils/errors.js +9 -48
- package/build/web/server/utils/errors.js.map +1 -1
- package/build/web/server/utils/index.js +1 -2
- package/build/web/server/utils/index.js.map +1 -1
- package/build/web/shared/components/Button/index.js +12 -101
- package/build/web/shared/components/Button/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/index.js +1 -40
- package/build/web/shared/components/Checkbox/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/theme.scss +1 -0
- package/build/web/shared/components/GenericLink/index.js +12 -65
- package/build/web/shared/components/GenericLink/index.js.map +1 -1
- package/build/web/shared/components/GenericLink/style.scss +1 -0
- package/build/web/shared/components/Input/index.js +11 -69
- package/build/web/shared/components/Input/index.js.map +1 -1
- package/build/web/shared/components/Link.js +2 -12
- package/build/web/shared/components/Link.js.map +1 -1
- package/build/web/shared/components/Modal/index.js +10 -130
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/components/NavLink.js +2 -10
- package/build/web/shared/components/NavLink.js.map +1 -1
- package/build/web/shared/components/PageLayout/index.js +2 -27
- package/build/web/shared/components/PageLayout/index.js.map +1 -1
- package/build/web/shared/components/TextArea/index.js +21 -106
- package/build/web/shared/components/TextArea/index.js.map +1 -1
- package/build/web/shared/components/Throbber/index.js +2 -24
- package/build/web/shared/components/Throbber/index.js.map +1 -1
- package/build/web/shared/components/WithTooltip/Tooltip.js +16 -145
- package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/web/shared/components/WithTooltip/index.js +12 -104
- package/build/web/shared/components/WithTooltip/index.js.map +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js +5 -43
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/web/shared/components/index.js +1 -15
- package/build/web/shared/components/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +6 -81
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +7 -122
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js +7 -68
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +1 -49
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/web/shared/components/selectors/common.js +1 -10
- package/build/web/shared/components/selectors/common.js.map +1 -1
- package/build/web/shared/components/selectors/index.js +1 -3
- package/build/web/shared/components/selectors/index.js.map +1 -1
- package/build/web/shared/utils/config.js +6 -40
- package/build/web/shared/utils/config.js.map +1 -1
- package/build/web/shared/utils/globalState.js +2 -11
- package/build/web/shared/utils/globalState.js.map +1 -1
- package/build/web/shared/utils/index.js +1 -9
- package/build/web/shared/utils/index.js.map +1 -1
- package/build/web/shared/utils/isomorphy/buildInfo.js +4 -25
- package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/web/shared/utils/isomorphy/environment-check.js +3 -9
- package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/web/shared/utils/isomorphy/index.js +5 -27
- package/build/web/shared/utils/isomorphy/index.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv.js +51 -221
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/web/shared/utils/jest/global.js +1 -3
- package/build/web/shared/utils/jest/global.js.map +1 -1
- package/build/web/shared/utils/jest/index.js +27 -146
- package/build/web/shared/utils/jest/index.js.map +1 -1
- package/build/web/shared/utils/splitComponent.js +34 -197
- package/build/web/shared/utils/splitComponent.js.map +1 -1
- package/build/web/shared/utils/time.js +5 -69
- package/build/web/shared/utils/time.js.map +1 -1
- package/build/web/shared/utils/webpack.js +6 -53
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/webpack.js +1 -1
- package/eslint.config.mjs +1 -0
- package/package.json +5 -8
- package/bin/build.js +0 -236
- package/config/webpack/lib-base.d.ts +0 -22
- package/config/webpack/lib-base.js +0 -167
- package/config/webpack/lib-development.d.ts +0 -5
- package/config/webpack/lib-development.js +0 -35
- package/config/webpack/lib-production.d.ts +0 -5
- package/config/webpack/lib-production.js +0 -42
- package/webpack.config.ts +0 -49
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
/**
|
|
1
|
+
import"core-js/modules/es.json.stringify.js";/**
|
|
3
2
|
* @category Utilities
|
|
4
3
|
* @module server/errors
|
|
5
4
|
* @desc
|
|
@@ -8,10 +7,7 @@ import "core-js/modules/es.json.stringify.js";
|
|
|
8
7
|
* const { errors } = server;
|
|
9
8
|
* ```
|
|
10
9
|
* Server-side helpers for error handling.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { StatusCodes as CODES, ReasonPhrases as ERRORS, getReasonPhrase as getErrorForCode } from 'http-status-codes';
|
|
14
|
-
/**
|
|
10
|
+
*/import{StatusCodes as CODES,ReasonPhrases as ERRORS,getReasonPhrase as getErrorForCode}from"http-status-codes";/**
|
|
15
11
|
* @static
|
|
16
12
|
* @const CODES
|
|
17
13
|
* @desc An alias for
|
|
@@ -21,10 +17,7 @@ import { StatusCodes as CODES, ReasonPhrases as ERRORS, getReasonPhrase as getEr
|
|
|
21
17
|
* import { server } from '@dr.pogodin/react-utils';
|
|
22
18
|
* const { CODES } = server.errors;
|
|
23
19
|
* console.log(CODES.BAD_REQUEST); // Prints: 400
|
|
24
|
-
*/
|
|
25
|
-
export { CODES };
|
|
26
|
-
|
|
27
|
-
/**
|
|
20
|
+
*/export{CODES};/**
|
|
28
21
|
* @static
|
|
29
22
|
* @const ERRORS
|
|
30
23
|
* @desc An alias for
|
|
@@ -34,10 +27,7 @@ export { CODES };
|
|
|
34
27
|
* import { server } from '@dr.pogodin/react-utils';
|
|
35
28
|
* const { ERRORS } = server.errors;
|
|
36
29
|
* console.log(ERRORS.BAD_REQUEST); // Prints: Bad Request
|
|
37
|
-
*/
|
|
38
|
-
export { ERRORS };
|
|
39
|
-
|
|
40
|
-
/**
|
|
30
|
+
*/export{ERRORS};/**
|
|
41
31
|
* @static
|
|
42
32
|
* @func getErrorForCode
|
|
43
33
|
* @desc An alias for
|
|
@@ -48,15 +38,8 @@ export { ERRORS };
|
|
|
48
38
|
* @example
|
|
49
39
|
* import { server } from '@dr.pogodin/react-utils';
|
|
50
40
|
* console.log(server.errors.getErrorForCode(400)); // Prints: Bad Request
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// TODO: It could accept the status code as a constructor argument.
|
|
55
|
-
class ErrorWithStatus extends Error {
|
|
56
|
-
status = CODES.INTERNAL_SERVER_ERROR;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
41
|
+
*/export{getErrorForCode};// TODO: It could accept the status code as a constructor argument.
|
|
42
|
+
class ErrorWithStatus extends Error{status=CODES.INTERNAL_SERVER_ERROR;}/**
|
|
60
43
|
* ```js
|
|
61
44
|
* import { server } from '@dr.pogodin/react-utils';
|
|
62
45
|
* const { newError } = server.errors;
|
|
@@ -67,21 +50,9 @@ class ErrorWithStatus extends Error {
|
|
|
67
50
|
* @param {number} [statusCode=500] HTTP status code. Defaults to 500 (Internal
|
|
68
51
|
* Server Error).
|
|
69
52
|
* @return {Error}
|
|
70
|
-
*/
|
|
71
|
-
export function newError(message, statusCode = CODES.INTERNAL_SERVER_ERROR) {
|
|
72
|
-
const error = new ErrorWithStatus(message);
|
|
73
|
-
error.status = statusCode;
|
|
74
|
-
return error;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
53
|
+
*/export function newError(message,statusCode=CODES.INTERNAL_SERVER_ERROR){const error=new ErrorWithStatus(message);error.status=statusCode;return error;}/**
|
|
78
54
|
* Throws an error with given message and HTTP status code.
|
|
79
|
-
*/
|
|
80
|
-
export function fail(message, statusCode = CODES.INTERNAL_SERVER_ERROR) {
|
|
81
|
-
throw newError(message, statusCode);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
55
|
+
*/export function fail(message,statusCode=CODES.INTERNAL_SERVER_ERROR){throw newError(message,statusCode);}/**
|
|
85
56
|
* Validates the `value` against the given "standard" validation `schema`.
|
|
86
57
|
* Resolves to the correctly typed `value`, if it has passed the validation;
|
|
87
58
|
* otherwise throws an error.
|
|
@@ -90,15 +61,5 @@ export function fail(message, statusCode = CODES.INTERNAL_SERVER_ERROR) {
|
|
|
90
61
|
* @param [message] Optional error message, to prepend the validation error
|
|
91
62
|
* message.
|
|
92
63
|
* @param [statusCode=400] HTTP status code. Defaults to 400 (Bad Request).
|
|
93
|
-
*/
|
|
94
|
-
export async function assert(value, schema, message = '', statusCode = CODES.BAD_REQUEST) {
|
|
95
|
-
let result = schema['~standard'].validate(value);
|
|
96
|
-
if (result instanceof Promise) result = await result;
|
|
97
|
-
if (result.issues) {
|
|
98
|
-
let error = JSON.stringify(result.issues, null, 2);
|
|
99
|
-
if (message) error = `${message}\n\n${error}`;
|
|
100
|
-
throw fail(error, statusCode);
|
|
101
|
-
}
|
|
102
|
-
return result.value;
|
|
103
|
-
}
|
|
64
|
+
*/export async function assert(value,schema,message="",statusCode=CODES.BAD_REQUEST){let result=schema["~standard"].validate(value);if(result instanceof Promise)result=await result;if(result.issues){let error=JSON.stringify(result.issues,null,2);if(message)error=`${message}\n\n${error}`;throw fail(error,statusCode);}return result.value;}
|
|
104
65
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["StatusCodes","CODES","ReasonPhrases","ERRORS","getReasonPhrase","getErrorForCode","ErrorWithStatus","Error","status","INTERNAL_SERVER_ERROR","newError","message","statusCode","error","fail","assert","value","schema","BAD_REQUEST","result","validate","Promise","issues","JSON","stringify"],"sources":["../../../../src/server/utils/errors.ts"],"sourcesContent":["/**\n * @category Utilities\n * @module server/errors\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { errors } = server;\n * ```\n * Server-side helpers for error handling.\n */\n\nimport {\n StatusCodes as CODES,\n ReasonPhrases as ERRORS,\n getReasonPhrase as getErrorForCode,\n} from 'http-status-codes';\n\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\n\n/**\n * @static\n * @const CODES\n * @desc An alias for\n * [StatusCodes object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and corresponding numeric codes.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { CODES } = server.errors;\n * console.log(CODES.BAD_REQUEST); // Prints: 400\n */\nexport { CODES };\n\n/**\n * @static\n * @const ERRORS\n * @desc An alias for\n * [ReasonPhrases object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and their pretty-printed forms.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { ERRORS } = server.errors;\n * console.log(ERRORS.BAD_REQUEST); // Prints: Bad Request\n */\nexport { ERRORS };\n\n/**\n * @static\n * @func getErrorForCode\n * @desc An alias for\n * [getReasonPhrase() function from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * Given an HTTP code it returns the corresponding error text.\n * @param {number} code HTTP code.\n * @return {string} HTTP error text.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * console.log(server.errors.getErrorForCode(400)); // Prints: Bad Request\n */\nexport { getErrorForCode };\n\n// TODO: It could accept the status code as a constructor argument.\nclass ErrorWithStatus extends Error {\n status: number = CODES.INTERNAL_SERVER_ERROR;\n}\n\n/**\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { newError } = server.errors;\n * ```\n * Creates a new `Error` object with given message, and HTTP status code\n * attached as `status` field.\n * @param {string} message Error message.\n * @param {number} [statusCode=500] HTTP status code. Defaults to 500 (Internal\n * Server Error).\n * @return {Error}\n */\nexport function newError(\n message: string,\n statusCode = CODES.INTERNAL_SERVER_ERROR,\n): ErrorWithStatus {\n const error = new ErrorWithStatus(message);\n error.status = statusCode;\n return error;\n}\n\n/**\n * Throws an error with given message and HTTP status code.\n */\nexport function fail(\n message: string,\n statusCode: CODES = CODES.INTERNAL_SERVER_ERROR,\n): Error {\n throw newError(message, statusCode);\n}\n\n/**\n * Validates the `value` against the given \"standard\" validation `schema`.\n * Resolves to the correctly typed `value`, if it has passed the validation;\n * otherwise throws an error.\n * @param value The value to validate.\n * @param schema The \"standard\" validation schema to use.\n * @param [message] Optional error message, to prepend the validation error\n * message.\n * @param [statusCode=400] HTTP status code. Defaults to 400 (Bad Request).\n */\nexport async function assert<T extends StandardSchemaV1>(\n value: unknown,\n schema: T,\n message = '',\n statusCode = CODES.BAD_REQUEST,\n): Promise<StandardSchemaV1.InferOutput<T>> {\n let result = schema['~standard'].validate(value);\n if (result instanceof Promise) result = await result;\n\n if (result.issues) {\n let error = JSON.stringify(result.issues, null, 2);\n if (message) error = `${message}\\n\\n${error}`;\n throw fail(error, statusCode);\n }\n\n return result.value;\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"errors.js","names":["StatusCodes","CODES","ReasonPhrases","ERRORS","getReasonPhrase","getErrorForCode","ErrorWithStatus","Error","status","INTERNAL_SERVER_ERROR","newError","message","statusCode","error","fail","assert","value","schema","BAD_REQUEST","result","validate","Promise","issues","JSON","stringify"],"sources":["../../../../src/server/utils/errors.ts"],"sourcesContent":["/**\n * @category Utilities\n * @module server/errors\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { errors } = server;\n * ```\n * Server-side helpers for error handling.\n */\n\nimport {\n StatusCodes as CODES,\n ReasonPhrases as ERRORS,\n getReasonPhrase as getErrorForCode,\n} from 'http-status-codes';\n\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\n\n/**\n * @static\n * @const CODES\n * @desc An alias for\n * [StatusCodes object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and corresponding numeric codes.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { CODES } = server.errors;\n * console.log(CODES.BAD_REQUEST); // Prints: 400\n */\nexport { CODES };\n\n/**\n * @static\n * @const ERRORS\n * @desc An alias for\n * [ReasonPhrases object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * It is a map between HTTP status code names and their pretty-printed forms.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * const { ERRORS } = server.errors;\n * console.log(ERRORS.BAD_REQUEST); // Prints: Bad Request\n */\nexport { ERRORS };\n\n/**\n * @static\n * @func getErrorForCode\n * @desc An alias for\n * [getReasonPhrase() function from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).\n * Given an HTTP code it returns the corresponding error text.\n * @param {number} code HTTP code.\n * @return {string} HTTP error text.\n * @example\n * import { server } from '@dr.pogodin/react-utils';\n * console.log(server.errors.getErrorForCode(400)); // Prints: Bad Request\n */\nexport { getErrorForCode };\n\n// TODO: It could accept the status code as a constructor argument.\nclass ErrorWithStatus extends Error {\n status: number = CODES.INTERNAL_SERVER_ERROR;\n}\n\n/**\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { newError } = server.errors;\n * ```\n * Creates a new `Error` object with given message, and HTTP status code\n * attached as `status` field.\n * @param {string} message Error message.\n * @param {number} [statusCode=500] HTTP status code. Defaults to 500 (Internal\n * Server Error).\n * @return {Error}\n */\nexport function newError(\n message: string,\n statusCode = CODES.INTERNAL_SERVER_ERROR,\n): ErrorWithStatus {\n const error = new ErrorWithStatus(message);\n error.status = statusCode;\n return error;\n}\n\n/**\n * Throws an error with given message and HTTP status code.\n */\nexport function fail(\n message: string,\n statusCode: CODES = CODES.INTERNAL_SERVER_ERROR,\n): Error {\n throw newError(message, statusCode);\n}\n\n/**\n * Validates the `value` against the given \"standard\" validation `schema`.\n * Resolves to the correctly typed `value`, if it has passed the validation;\n * otherwise throws an error.\n * @param value The value to validate.\n * @param schema The \"standard\" validation schema to use.\n * @param [message] Optional error message, to prepend the validation error\n * message.\n * @param [statusCode=400] HTTP status code. Defaults to 400 (Bad Request).\n */\nexport async function assert<T extends StandardSchemaV1>(\n value: unknown,\n schema: T,\n message = '',\n statusCode = CODES.BAD_REQUEST,\n): Promise<StandardSchemaV1.InferOutput<T>> {\n let result = schema['~standard'].validate(value);\n if (result instanceof Promise) result = await result;\n\n if (result.issues) {\n let error = JSON.stringify(result.issues, null, 2);\n if (message) error = `${message}\\n\\n${error}`;\n throw fail(error, statusCode);\n }\n\n return result.value;\n}\n"],"mappings":"6CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAEA,OACEA,WAAW,GAAI,CAAAC,KAAK,CACpBC,aAAa,GAAI,CAAAC,MAAM,CACvBC,eAAe,GAAI,CAAAC,eAAe,KAC7B,mBAAmB,CAI1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,OAASJ,KAAK,EAEd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,OAASE,MAAM,EAEf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,OAASE,eAAe,EAExB;AACA,KAAM,CAAAC,eAAe,QAAS,CAAAC,KAAM,CAClCC,MAAM,CAAWP,KAAK,CAACQ,qBAAqB,CAC9C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAC,QAAQA,CACtBC,OAAe,CACfC,UAAU,CAAGX,KAAK,CAACQ,qBAAqB,CACvB,CACjB,KAAM,CAAAI,KAAK,CAAG,GAAI,CAAAP,eAAe,CAACK,OAAO,CAAC,CAC1CE,KAAK,CAACL,MAAM,CAAGI,UAAU,CACzB,MAAO,CAAAC,KAAK,CACd,CAEA;AACA;AACA,GACA,MAAO,SAAS,CAAAC,IAAIA,CAClBH,OAAe,CACfC,UAAiB,CAAGX,KAAK,CAACQ,qBAAqB,CACxC,CACP,KAAM,CAAAC,QAAQ,CAACC,OAAO,CAAEC,UAAU,CAAC,CACrC,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,eAAe,CAAAG,MAAMA,CAC1BC,KAAc,CACdC,MAAS,CACTN,OAAO,CAAG,EAAE,CACZC,UAAU,CAAGX,KAAK,CAACiB,WAAW,CACY,CAC1C,GAAI,CAAAC,MAAM,CAAGF,MAAM,CAAC,WAAW,CAAC,CAACG,QAAQ,CAACJ,KAAK,CAAC,CAChD,GAAIG,MAAM,WAAY,CAAAE,OAAO,CAAEF,MAAM,CAAG,KAAM,CAAAA,MAAM,CAEpD,GAAIA,MAAM,CAACG,MAAM,CAAE,CACjB,GAAI,CAAAT,KAAK,CAAGU,IAAI,CAACC,SAAS,CAACL,MAAM,CAACG,MAAM,CAAE,IAAI,CAAE,CAAC,CAAC,CAClD,GAAIX,OAAO,CAAEE,KAAK,CAAG,GAAGF,OAAO,OAAOE,KAAK,EAAE,CAC7C,KAAM,CAAAC,IAAI,CAACD,KAAK,CAAED,UAAU,CAAC,CAC/B,CAEA,MAAO,CAAAO,MAAM,CAACH,KAAK,CACrB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/server/utils/index.ts"],"sourcesContent":["// Aggregates utility modules together.\n\nexport * from './errors';\n"],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/server/utils/index.ts"],"sourcesContent":["// Aggregates utility modules together.\n\nexport * from './errors';\n"],"mappings":"AAAA;AAEA","ignoreList":[]}
|
|
@@ -1,103 +1,14 @@
|
|
|
1
1
|
// The <Button> component implements a standard button / button-like link.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
onKeyDown: onKeyDownProp,
|
|
15
|
-
onKeyUp,
|
|
16
|
-
onMouseDown,
|
|
17
|
-
onMouseUp,
|
|
18
|
-
onPointerDown,
|
|
19
|
-
onPointerUp,
|
|
20
|
-
openNewTab,
|
|
21
|
-
replace,
|
|
22
|
-
testId,
|
|
23
|
-
theme,
|
|
24
|
-
to
|
|
25
|
-
}) => {
|
|
26
|
-
let className = theme.button;
|
|
27
|
-
if (active && theme.active) className += ` ${theme.active}`;
|
|
28
|
-
if (disabled) {
|
|
29
|
-
if (theme.disabled) className += ` ${theme.disabled}`;
|
|
30
|
-
return /*#__PURE__*/_jsx("div", {
|
|
31
|
-
className: className,
|
|
32
|
-
"data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
|
|
33
|
-
children: children
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
let onKeyDown = onKeyDownProp;
|
|
37
|
-
if (!onKeyDown && onClick) {
|
|
38
|
-
onKeyDown = e => {
|
|
39
|
-
if (e.key === 'Enter') onClick(e);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
if (to) {
|
|
43
|
-
return /*#__PURE__*/_jsx(Link, {
|
|
44
|
-
className: className,
|
|
45
|
-
"data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
|
|
46
|
-
enforceA: enforceA
|
|
47
|
-
|
|
48
|
-
// TODO: This was exposed as a hotifx... however, I guess we better want
|
|
49
|
-
// to check if the `to` URL contains an anchor (#), and if it does we should
|
|
50
|
-
// automatically opt to keep the position here; and enforce <a> (as
|
|
51
|
-
// react-router link does not seem to respect the hash tag either,
|
|
52
|
-
// at least not without some additional settings).
|
|
53
|
-
,
|
|
54
|
-
keepScrollPosition: keepScrollPosition,
|
|
55
|
-
onClick: onClick
|
|
56
|
-
|
|
57
|
-
// TODO: For now, the `onKeyDown` handler is not passed to the <Link>,
|
|
58
|
-
// as <Link> component does not call it anyway, presumably due to
|
|
59
|
-
// the inner implementation details. We should look into supporting it:
|
|
60
|
-
// https://github.com/birdofpreyru/react-utils/issues/444
|
|
61
|
-
// onKeyDown={onKeyDown}
|
|
62
|
-
,
|
|
63
|
-
|
|
64
|
-
onKeyUp: onKeyUp,
|
|
65
|
-
onMouseDown: onMouseDown,
|
|
66
|
-
onMouseUp: onMouseUp,
|
|
67
|
-
onPointerDown: onPointerDown,
|
|
68
|
-
onPointerUp: onPointerUp,
|
|
69
|
-
openNewTab: openNewTab,
|
|
70
|
-
replace: replace,
|
|
71
|
-
to: to,
|
|
72
|
-
children: children
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return /*#__PURE__*/_jsx("div", {
|
|
76
|
-
className: className,
|
|
77
|
-
"data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
|
|
78
|
-
onClick: onClick,
|
|
79
|
-
onKeyDown: onKeyDown,
|
|
80
|
-
onKeyUp: onKeyUp,
|
|
81
|
-
onMouseDown: onMouseDown,
|
|
82
|
-
onMouseUp: onMouseUp,
|
|
83
|
-
onPointerDown: onPointerDown,
|
|
84
|
-
onPointerUp: onPointerUp,
|
|
85
|
-
role: "button",
|
|
86
|
-
tabIndex: 0,
|
|
87
|
-
children: children
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
const Button = ({
|
|
91
|
-
theme,
|
|
92
|
-
...rest
|
|
93
|
-
}) => {
|
|
94
|
-
const composed = useTheme('Button', defaultTheme, theme);
|
|
95
|
-
|
|
96
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
97
|
-
return /*#__PURE__*/_jsx(BaseButton, {
|
|
98
|
-
...rest,
|
|
99
|
-
theme: composed
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
export default Button;
|
|
2
|
+
import{useTheme}from"@dr.pogodin/react-themes";import Link from"../Link";import defaultTheme from"./style.scss";import{jsx as _jsx}from"react/jsx-runtime";export const BaseButton=({active,children,disabled,enforceA,keepScrollPosition,onClick,onKeyDown:onKeyDownProp,onKeyUp,onMouseDown,onMouseUp,onPointerDown,onPointerUp,openNewTab,replace,testId,theme,to})=>{let className=theme.button;if(active&&theme.active)className+=` ${theme.active}`;if(disabled){if(theme.disabled)className+=` ${theme.disabled}`;return/*#__PURE__*/_jsx("div",{className:className,"data-testid":process.env.NODE_ENV==="production"?undefined:testId,children:children});}let onKeyDown=onKeyDownProp;if(!onKeyDown&&onClick){onKeyDown=e=>{if(e.key==="Enter")onClick(e);};}if(to){return/*#__PURE__*/_jsx(Link,{className:className,"data-testid":process.env.NODE_ENV==="production"?undefined:testId,enforceA:enforceA// TODO: This was exposed as a hotifx... however, I guess we better want
|
|
3
|
+
// to check if the `to` URL contains an anchor (#), and if it does we should
|
|
4
|
+
// automatically opt to keep the position here; and enforce <a> (as
|
|
5
|
+
// react-router link does not seem to respect the hash tag either,
|
|
6
|
+
// at least not without some additional settings).
|
|
7
|
+
,keepScrollPosition:keepScrollPosition,onClick:onClick// TODO: For now, the `onKeyDown` handler is not passed to the <Link>,
|
|
8
|
+
// as <Link> component does not call it anyway, presumably due to
|
|
9
|
+
// the inner implementation details. We should look into supporting it:
|
|
10
|
+
// https://github.com/birdofpreyru/react-utils/issues/444
|
|
11
|
+
// onKeyDown={onKeyDown}
|
|
12
|
+
,onKeyUp:onKeyUp,onMouseDown:onMouseDown,onMouseUp:onMouseUp,onPointerDown:onPointerDown,onPointerUp:onPointerUp,openNewTab:openNewTab,replace:replace,to:to,children:children});}return/*#__PURE__*/_jsx("div",{className:className,"data-testid":process.env.NODE_ENV==="production"?undefined:testId,onClick:onClick,onKeyDown:onKeyDown,onKeyUp:onKeyUp,onMouseDown:onMouseDown,onMouseUp:onMouseUp,onPointerDown:onPointerDown,onPointerUp:onPointerUp,role:"button",tabIndex:0,children:children});};const Button=({theme,...rest})=>{const composed=useTheme("Button",defaultTheme,theme);// eslint-disable-next-line react/jsx-props-no-spreading
|
|
13
|
+
return/*#__PURE__*/_jsx(BaseButton,{...rest,theme:composed});};export default Button;
|
|
103
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useTheme","Link","defaultTheme","jsx","_jsx","BaseButton","active","children","disabled","enforceA","keepScrollPosition","onClick","onKeyDown","onKeyDownProp","onKeyUp","onMouseDown","onMouseUp","onPointerDown","onPointerUp","openNewTab","replace","testId","theme","to","className","button","process","env","NODE_ENV","undefined","e","key","role","tabIndex","Button","rest","composed"],"sources":["../../../../../src/shared/components/Button/index.tsx"],"sourcesContent":["// The <Button> component implements a standard button / button-like link.\n\nimport type {\n FunctionComponent,\n KeyboardEventHandler,\n MouseEventHandler,\n PointerEventHandler,\n ReactNode,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Link from 'components/Link';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeT = Theme<'active' | 'button' | 'disabled'>;\n\ntype PropsT = {\n active?: boolean;\n children?: ReactNode;\n disabled?: boolean;\n enforceA?: boolean;\n keepScrollPosition?: boolean;\n onClick?: KeyboardEventHandler & MouseEventHandler;\n onKeyDown?: KeyboardEventHandler;\n onKeyUp?: KeyboardEventHandler;\n onMouseDown?: MouseEventHandler;\n onMouseUp?: MouseEventHandler;\n onPointerDown?: PointerEventHandler;\n onPointerUp?: PointerEventHandler;\n openNewTab?: boolean;\n replace?: boolean;\n testId?: string;\n theme: ThemeT;\n\n // TODO: It needs a more precise typing of the object option.\n to?: object | string;\n};\n\nexport const BaseButton: FunctionComponent<PropsT> = ({\n active,\n children,\n disabled,\n enforceA,\n keepScrollPosition,\n onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onPointerDown,\n onPointerUp,\n openNewTab,\n replace,\n testId,\n theme,\n to,\n}) => {\n let className = theme.button;\n if (active && theme.active) className += ` ${theme.active}`;\n if (disabled) {\n if (theme.disabled) className += ` ${theme.disabled}`;\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n >\n {children}\n </div>\n );\n }\n\n let onKeyDown = onKeyDownProp;\n if (!onKeyDown && onClick) {\n onKeyDown = (e) => {\n if (e.key === 'Enter') onClick(e);\n };\n }\n\n if (to) {\n return (\n <Link\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n enforceA={enforceA}\n\n // TODO: This was exposed as a hotifx... however, I guess we better want\n // to check if the `to` URL contains an anchor (#), and if it does we should\n // automatically opt to keep the position here; and enforce <a> (as\n // react-router link does not seem to respect the hash tag either,\n // at least not without some additional settings).\n keepScrollPosition={keepScrollPosition}\n\n onClick={onClick}\n\n // TODO: For now, the `onKeyDown` handler is not passed to the <Link>,\n // as <Link> component does not call it anyway, presumably due to\n // the inner implementation details. We should look into supporting it:\n // https://github.com/birdofpreyru/react-utils/issues/444\n // onKeyDown={onKeyDown}\n\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n openNewTab={openNewTab}\n replace={replace}\n to={to}\n >\n {children}\n </Link>\n );\n }\n\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={onClick}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n role=\"button\"\n tabIndex={0}\n >\n {children}\n </div>\n );\n};\n\nconst Button: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Button', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseButton {...rest} theme={composed} />;\n};\n\nexport default Button;\n"],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","names":["useTheme","Link","defaultTheme","jsx","_jsx","BaseButton","active","children","disabled","enforceA","keepScrollPosition","onClick","onKeyDown","onKeyDownProp","onKeyUp","onMouseDown","onMouseUp","onPointerDown","onPointerUp","openNewTab","replace","testId","theme","to","className","button","process","env","NODE_ENV","undefined","e","key","role","tabIndex","Button","rest","composed"],"sources":["../../../../../src/shared/components/Button/index.tsx"],"sourcesContent":["// The <Button> component implements a standard button / button-like link.\n\nimport type {\n FunctionComponent,\n KeyboardEventHandler,\n MouseEventHandler,\n PointerEventHandler,\n ReactNode,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport Link from 'components/Link';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeT = Theme<'active' | 'button' | 'disabled'>;\n\ntype PropsT = {\n active?: boolean;\n children?: ReactNode;\n disabled?: boolean;\n enforceA?: boolean;\n keepScrollPosition?: boolean;\n onClick?: KeyboardEventHandler & MouseEventHandler;\n onKeyDown?: KeyboardEventHandler;\n onKeyUp?: KeyboardEventHandler;\n onMouseDown?: MouseEventHandler;\n onMouseUp?: MouseEventHandler;\n onPointerDown?: PointerEventHandler;\n onPointerUp?: PointerEventHandler;\n openNewTab?: boolean;\n replace?: boolean;\n testId?: string;\n theme: ThemeT;\n\n // TODO: It needs a more precise typing of the object option.\n to?: object | string;\n};\n\nexport const BaseButton: FunctionComponent<PropsT> = ({\n active,\n children,\n disabled,\n enforceA,\n keepScrollPosition,\n onClick,\n onKeyDown: onKeyDownProp,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onPointerDown,\n onPointerUp,\n openNewTab,\n replace,\n testId,\n theme,\n to,\n}) => {\n let className = theme.button;\n if (active && theme.active) className += ` ${theme.active}`;\n if (disabled) {\n if (theme.disabled) className += ` ${theme.disabled}`;\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n >\n {children}\n </div>\n );\n }\n\n let onKeyDown = onKeyDownProp;\n if (!onKeyDown && onClick) {\n onKeyDown = (e) => {\n if (e.key === 'Enter') onClick(e);\n };\n }\n\n if (to) {\n return (\n <Link\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n enforceA={enforceA}\n\n // TODO: This was exposed as a hotifx... however, I guess we better want\n // to check if the `to` URL contains an anchor (#), and if it does we should\n // automatically opt to keep the position here; and enforce <a> (as\n // react-router link does not seem to respect the hash tag either,\n // at least not without some additional settings).\n keepScrollPosition={keepScrollPosition}\n\n onClick={onClick}\n\n // TODO: For now, the `onKeyDown` handler is not passed to the <Link>,\n // as <Link> component does not call it anyway, presumably due to\n // the inner implementation details. We should look into supporting it:\n // https://github.com/birdofpreyru/react-utils/issues/444\n // onKeyDown={onKeyDown}\n\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n openNewTab={openNewTab}\n replace={replace}\n to={to}\n >\n {children}\n </Link>\n );\n }\n\n return (\n <div\n className={className}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={onClick}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n onMouseDown={onMouseDown}\n onMouseUp={onMouseUp}\n onPointerDown={onPointerDown}\n onPointerUp={onPointerUp}\n role=\"button\"\n tabIndex={0}\n >\n {children}\n </div>\n );\n};\n\nconst Button: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Button', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseButton {...rest} theme={composed} />;\n};\n\nexport default Button;\n"],"mappings":"AAAA;AAUA,OAAqBA,QAAQ,KAAQ,0BAA0B,CAE/D,MAAO,CAAAC,IAAI,eAEX,MAAO,CAAAC,YAAY,oBAAqB,OAAAC,GAAA,IAAAC,IAAA,yBA0BxC,MAAO,MAAM,CAAAC,UAAqC,CAAGA,CAAC,CACpDC,MAAM,CACNC,QAAQ,CACRC,QAAQ,CACRC,QAAQ,CACRC,kBAAkB,CAClBC,OAAO,CACPC,SAAS,CAAEC,aAAa,CACxBC,OAAO,CACPC,WAAW,CACXC,SAAS,CACTC,aAAa,CACbC,WAAW,CACXC,UAAU,CACVC,OAAO,CACPC,MAAM,CACNC,KAAK,CACLC,EACF,CAAC,GAAK,CACJ,GAAI,CAAAC,SAAS,CAAGF,KAAK,CAACG,MAAM,CAC5B,GAAInB,MAAM,EAAIgB,KAAK,CAAChB,MAAM,CAAEkB,SAAS,EAAI,IAAIF,KAAK,CAAChB,MAAM,EAAE,CAC3D,GAAIE,QAAQ,CAAE,CACZ,GAAIc,KAAK,CAACd,QAAQ,CAAEgB,SAAS,EAAI,IAAIF,KAAK,CAACd,QAAQ,EAAE,CACrD,mBACEJ,IAAA,QACEoB,SAAS,CAAEA,SAAU,CACrB,cAAaE,OAAO,CAACC,GAAG,CAACC,QAAQ,GAAK,YAAY,CAAGC,SAAS,CAAGR,MAAO,CAAAd,QAAA,CAEvEA,QAAQ,CACN,CAAC,CAEV,CAEA,GAAI,CAAAK,SAAS,CAAGC,aAAa,CAC7B,GAAI,CAACD,SAAS,EAAID,OAAO,CAAE,CACzBC,SAAS,CAAIkB,CAAC,EAAK,CACjB,GAAIA,CAAC,CAACC,GAAG,GAAK,OAAO,CAAEpB,OAAO,CAACmB,CAAC,CAAC,CACnC,CAAC,CACH,CAEA,GAAIP,EAAE,CAAE,CACN,mBACEnB,IAAA,CAACH,IAAI,EACHuB,SAAS,CAAEA,SAAU,CACrB,cAAaE,OAAO,CAACC,GAAG,CAACC,QAAQ,GAAK,YAAY,CAAGC,SAAS,CAAGR,MAAO,CACxEZ,QAAQ,CAAEA,QAEV;AACA;AACA;AACA;AACA;AAAA,CACAC,kBAAkB,CAAEA,kBAAmB,CAEvCC,OAAO,CAAEA,OAET;AACA;AACA;AACA;AACA;AAAA,CAEAG,OAAO,CAAEA,OAAQ,CACjBC,WAAW,CAAEA,WAAY,CACzBC,SAAS,CAAEA,SAAU,CACrBC,aAAa,CAAEA,aAAc,CAC7BC,WAAW,CAAEA,WAAY,CACzBC,UAAU,CAAEA,UAAW,CACvBC,OAAO,CAAEA,OAAQ,CACjBG,EAAE,CAAEA,EAAG,CAAAhB,QAAA,CAENA,QAAQ,CACL,CAAC,CAEX,CAEA,mBACEH,IAAA,QACEoB,SAAS,CAAEA,SAAU,CACrB,cAAaE,OAAO,CAACC,GAAG,CAACC,QAAQ,GAAK,YAAY,CAAGC,SAAS,CAAGR,MAAO,CACxEV,OAAO,CAAEA,OAAQ,CACjBC,SAAS,CAAEA,SAAU,CACrBE,OAAO,CAAEA,OAAQ,CACjBC,WAAW,CAAEA,WAAY,CACzBC,SAAS,CAAEA,SAAU,CACrBC,aAAa,CAAEA,aAAc,CAC7BC,WAAW,CAAEA,WAAY,CACzBc,IAAI,CAAC,QAAQ,CACbC,QAAQ,CAAE,CAAE,CAAA1B,QAAA,CAEXA,QAAQ,CACN,CAAC,CAEV,CAAC,CAED,KAAM,CAAA2B,MAEL,CAAGA,CAAC,CAAEZ,KAAK,CAAE,GAAGa,IAAK,CAAC,GAAK,CAC1B,KAAM,CAAAC,QAAQ,CAAGpC,QAAQ,CAAC,QAAQ,CAAEE,YAAY,CAAEoB,KAAK,CAAC,CAExD;AACA,mBAAOlB,IAAA,CAACC,UAAU,KAAK8B,IAAI,CAAEb,KAAK,CAAEc,QAAS,CAAE,CAAC,CAClD,CAAC,CAED,cAAe,CAAAF,MAAM","ignoreList":[]}
|
|
@@ -1,41 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import defaultTheme from "./theme.scss";
|
|
3
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
-
const Checkbox = ({
|
|
5
|
-
checked,
|
|
6
|
-
disabled,
|
|
7
|
-
error,
|
|
8
|
-
label,
|
|
9
|
-
onChange,
|
|
10
|
-
testId,
|
|
11
|
-
theme
|
|
12
|
-
}) => {
|
|
13
|
-
const composed = useTheme('Checkbox', defaultTheme, theme);
|
|
14
|
-
let containerClassName = composed.container;
|
|
15
|
-
if (disabled) containerClassName += ` ${composed.disabled}`;
|
|
16
|
-
let checkboxClassName = composed.checkbox;
|
|
17
|
-
if (checked === 'indeterminate') checkboxClassName += ` ${composed.indeterminate}`;
|
|
18
|
-
if (error) containerClassName += ` ${composed.error}`;
|
|
19
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
20
|
-
className: containerClassName,
|
|
21
|
-
children: [label === undefined ? null : /*#__PURE__*/_jsx("div", {
|
|
22
|
-
className: composed.label,
|
|
23
|
-
children: label
|
|
24
|
-
}), /*#__PURE__*/_jsx("input", {
|
|
25
|
-
checked: checked === undefined ? undefined : checked === true,
|
|
26
|
-
className: checkboxClassName,
|
|
27
|
-
"data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
|
|
28
|
-
disabled: disabled,
|
|
29
|
-
onChange: onChange,
|
|
30
|
-
onClick: e => {
|
|
31
|
-
e.stopPropagation();
|
|
32
|
-
},
|
|
33
|
-
type: "checkbox"
|
|
34
|
-
}), error && error !== true ? /*#__PURE__*/_jsx("div", {
|
|
35
|
-
className: composed.errorMessage,
|
|
36
|
-
children: error
|
|
37
|
-
}) : null]
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
export default Checkbox;
|
|
1
|
+
import{useTheme}from"@dr.pogodin/react-themes";import defaultTheme from"./theme.scss";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const Checkbox=({checked,disabled,error,label,onChange,testId,theme})=>{const composed=useTheme("Checkbox",defaultTheme,theme);let containerClassName=composed.container;if(disabled)containerClassName+=` ${composed.disabled}`;let checkboxClassName=composed.checkbox;if(checked==="indeterminate")checkboxClassName+=` ${composed.indeterminate}`;if(error)containerClassName+=` ${composed.error}`;return/*#__PURE__*/_jsxs("div",{className:containerClassName,children:[label===undefined?null:/*#__PURE__*/_jsx("div",{className:composed.label,children:label}),/*#__PURE__*/_jsx("input",{checked:checked===undefined?undefined:checked===true,className:checkboxClassName,"data-testid":process.env.NODE_ENV==="production"?undefined:testId,disabled:disabled,onChange:onChange,onClick:e=>{e.stopPropagation();},type:"checkbox"}),error&&error!==true?/*#__PURE__*/_jsx("div",{className:composed.errorMessage,children:error}):null]});};export default Checkbox;
|
|
41
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useTheme","defaultTheme","jsx","_jsx","jsxs","_jsxs","Checkbox","checked","disabled","error","label","onChange","testId","theme","composed","containerClassName","container","checkboxClassName","checkbox","indeterminate","className","children","undefined","process","env","NODE_ENV","onClick","e","stopPropagation","type","errorMessage"],"sources":["../../../../../src/shared/components/Checkbox/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype PropT<ValueT> = {\n checked?: ValueT;\n disabled?: boolean;\n error?: ReactNode;\n label?: React.ReactNode;\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\n testId?: string;\n theme?: Theme<\n | 'checkbox'\n | 'container'\n | 'disabled'\n | 'error'\n | 'errorMessage'\n | 'indeterminate'\n | 'label'\n >;\n};\n\nconst Checkbox = <ValueT extends 'indeterminate' | boolean = boolean>({\n checked,\n disabled,\n error,\n label,\n onChange,\n testId,\n theme,\n}: PropT<ValueT>): ReactNode => {\n const composed = useTheme('Checkbox', defaultTheme, theme);\n\n let containerClassName = composed.container;\n if (disabled) containerClassName += ` ${composed.disabled}`;\n\n let checkboxClassName = composed.checkbox;\n if (checked === 'indeterminate') checkboxClassName += ` ${composed.indeterminate}`;\n\n if (error) containerClassName += ` ${composed.error}`;\n\n return (\n <div className={containerClassName}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <input\n checked={checked === undefined ? undefined : checked === true}\n className={checkboxClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onChange={onChange}\n onClick={(e) => {\n e.stopPropagation();\n }}\n type=\"checkbox\"\n />\n {error && error !== true\n ? <div className={composed.errorMessage}>{error}</div>\n : null}\n </div>\n );\n};\n\nexport default Checkbox;\n"],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["useTheme","defaultTheme","jsx","_jsx","jsxs","_jsxs","Checkbox","checked","disabled","error","label","onChange","testId","theme","composed","containerClassName","container","checkboxClassName","checkbox","indeterminate","className","children","undefined","process","env","NODE_ENV","onClick","e","stopPropagation","type","errorMessage"],"sources":["../../../../../src/shared/components/Checkbox/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype PropT<ValueT> = {\n checked?: ValueT;\n disabled?: boolean;\n error?: ReactNode;\n label?: React.ReactNode;\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\n testId?: string;\n theme?: Theme<\n | 'checkbox'\n | 'container'\n | 'disabled'\n | 'error'\n | 'errorMessage'\n | 'indeterminate'\n | 'label'\n >;\n};\n\nconst Checkbox = <ValueT extends 'indeterminate' | boolean = boolean>({\n checked,\n disabled,\n error,\n label,\n onChange,\n testId,\n theme,\n}: PropT<ValueT>): ReactNode => {\n const composed = useTheme('Checkbox', defaultTheme, theme);\n\n let containerClassName = composed.container;\n if (disabled) containerClassName += ` ${composed.disabled}`;\n\n let checkboxClassName = composed.checkbox;\n if (checked === 'indeterminate') checkboxClassName += ` ${composed.indeterminate}`;\n\n if (error) containerClassName += ` ${composed.error}`;\n\n return (\n <div className={containerClassName}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <input\n checked={checked === undefined ? undefined : checked === true}\n className={checkboxClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onChange={onChange}\n onClick={(e) => {\n e.stopPropagation();\n }}\n type=\"checkbox\"\n />\n {error && error !== true\n ? <div className={composed.errorMessage}>{error}</div>\n : null}\n </div>\n );\n};\n\nexport default Checkbox;\n"],"mappings":"AAEA,OAAqBA,QAAQ,KAAQ,0BAA0B,CAE/D,MAAO,CAAAC,YAAY,oBAAqB,OAAAC,GAAA,IAAAC,IAAA,CAAAC,IAAA,IAAAC,KAAA,yBAoBxC,KAAM,CAAAC,QAAQ,CAAGA,CAAqD,CACpEC,OAAO,CACPC,QAAQ,CACRC,KAAK,CACLC,KAAK,CACLC,QAAQ,CACRC,MAAM,CACNC,KACa,CAAC,GAAgB,CAC9B,KAAM,CAAAC,QAAQ,CAAGd,QAAQ,CAAC,UAAU,CAAEC,YAAY,CAAEY,KAAK,CAAC,CAE1D,GAAI,CAAAE,kBAAkB,CAAGD,QAAQ,CAACE,SAAS,CAC3C,GAAIR,QAAQ,CAAEO,kBAAkB,EAAI,IAAID,QAAQ,CAACN,QAAQ,EAAE,CAE3D,GAAI,CAAAS,iBAAiB,CAAGH,QAAQ,CAACI,QAAQ,CACzC,GAAIX,OAAO,GAAK,eAAe,CAAEU,iBAAiB,EAAI,IAAIH,QAAQ,CAACK,aAAa,EAAE,CAElF,GAAIV,KAAK,CAAEM,kBAAkB,EAAI,IAAID,QAAQ,CAACL,KAAK,EAAE,CAErD,mBACEJ,KAAA,QAAKe,SAAS,CAAEL,kBAAmB,CAAAM,QAAA,EAC/BX,KAAK,GAAKY,SAAS,CACjB,IAAI,cAAGnB,IAAA,QAAKiB,SAAS,CAAEN,QAAQ,CAACJ,KAAM,CAAAW,QAAA,CAAEX,KAAK,CAAM,CAAC,cACxDP,IAAA,UACEI,OAAO,CAAEA,OAAO,GAAKe,SAAS,CAAGA,SAAS,CAAGf,OAAO,GAAK,IAAK,CAC9Da,SAAS,CAAEH,iBAAkB,CAC7B,cAAaM,OAAO,CAACC,GAAG,CAACC,QAAQ,GAAK,YAAY,CAAGH,SAAS,CAAGV,MAAO,CACxEJ,QAAQ,CAAEA,QAAS,CACnBG,QAAQ,CAAEA,QAAS,CACnBe,OAAO,CAAGC,CAAC,EAAK,CACdA,CAAC,CAACC,eAAe,CAAC,CAAC,CACrB,CAAE,CACFC,IAAI,CAAC,UAAU,CAChB,CAAC,CACDpB,KAAK,EAAIA,KAAK,GAAK,IAAI,cACpBN,IAAA,QAAKiB,SAAS,CAAEN,QAAQ,CAACgB,YAAa,CAAAT,QAAA,CAAEZ,KAAK,CAAM,CAAC,CACpD,IAAI,EACL,CAAC,CAEV,CAAC,CAED,cAAe,CAAAH,QAAQ","ignoreList":[]}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import "./style.scss";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
/**
|
|
1
|
+
import S from"./style.scss";import{jsx as _jsx}from"react/jsx-runtime";/**
|
|
4
2
|
* The `<Link>` component, and almost identical `<NavLink>` component, are
|
|
5
3
|
* auxiliary wrappers around
|
|
6
4
|
* [React Router](https://github.com/ReactTraining/react-router)'s
|
|
@@ -39,69 +37,18 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
39
37
|
* slash on a location’s pathname will be taken into consideration when
|
|
40
38
|
* determining if the location matches the current URL. See the `<Route strict>`
|
|
41
39
|
* documentation for more information.
|
|
42
|
-
*/
|
|
43
|
-
const GenericLink = ({
|
|
44
|
-
children,
|
|
45
|
-
className,
|
|
46
|
-
disabled,
|
|
47
|
-
enforceA,
|
|
48
|
-
keepScrollPosition,
|
|
49
|
-
onClick,
|
|
50
|
-
onMouseDown,
|
|
51
|
-
openNewTab,
|
|
52
|
-
replace,
|
|
53
|
-
routerLinkType,
|
|
54
|
-
to,
|
|
55
|
-
...rest
|
|
56
|
-
}) => {
|
|
57
|
-
/* Renders Link as <a> element if:
|
|
40
|
+
*/const GenericLink=({children,className,disabled,enforceA,keepScrollPosition,onClick,onMouseDown,openNewTab,replace,routerLinkType,to,...rest})=>{/* Renders Link as <a> element if:
|
|
58
41
|
* - It is opted explicitely by `enforceA` prop;
|
|
59
42
|
* - It should be opened in a new tab;
|
|
60
43
|
* - It is an absolte URL (starts with http:// or https://);
|
|
61
|
-
* - It is anchor link (starts with #). */
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
onClick: disabled ? e => {
|
|
72
|
-
e.preventDefault();
|
|
73
|
-
} : onClick,
|
|
74
|
-
onMouseDown: disabled ? e => {
|
|
75
|
-
e.preventDefault();
|
|
76
|
-
} : onMouseDown,
|
|
77
|
-
rel: "noopener noreferrer",
|
|
78
|
-
styleName: "link",
|
|
79
|
-
target: openNewTab ? '_blank' : '',
|
|
80
|
-
children: children
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
const L = routerLinkType;
|
|
84
|
-
return /*#__PURE__*/_jsx(L, {
|
|
85
|
-
className: className,
|
|
86
|
-
discover: "none"
|
|
87
|
-
// disabled
|
|
88
|
-
,
|
|
89
|
-
onClick: e => {
|
|
90
|
-
// Executes the user-provided event handler, if any.
|
|
91
|
-
if (onClick) onClick(e);
|
|
92
|
-
|
|
93
|
-
// By default, clicking the link scrolls the page to beginning.
|
|
94
|
-
if (!keepScrollPosition) window.scroll(0, 0);
|
|
95
|
-
},
|
|
96
|
-
onMouseDown: onMouseDown,
|
|
97
|
-
replace: replace,
|
|
98
|
-
to: to
|
|
99
|
-
// TODO: Refactor it later.
|
|
100
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
101
|
-
,
|
|
102
|
-
...rest,
|
|
103
|
-
children: children
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
export default GenericLink;
|
|
44
|
+
* - It is anchor link (starts with #). */if(disabled||enforceA||openNewTab||to.match(/^(#|(https?|mailto):)/)){let aClassName=S.link;if(className)aClassName+=` ${className}`;return/*#__PURE__*/_jsx("a",{className:aClassName// TODO: This requires a fix: disabled is not really an attribute of <a>
|
|
45
|
+
// tag, thus for disabled option we rather should render a plain text
|
|
46
|
+
// styled as a link.
|
|
47
|
+
// disabled={disabled}
|
|
48
|
+
,href:to,onClick:disabled?e=>{e.preventDefault();}:onClick,onMouseDown:disabled?e=>{e.preventDefault();}:onMouseDown,rel:"noopener noreferrer",styleName:"link",target:openNewTab?"_blank":"",children:children});}const L=routerLinkType;return/*#__PURE__*/_jsx(L,{className:className,discover:"none"// disabled
|
|
49
|
+
,onClick:e=>{// Executes the user-provided event handler, if any.
|
|
50
|
+
if(onClick)onClick(e);// By default, clicking the link scrolls the page to beginning.
|
|
51
|
+
if(!keepScrollPosition)window.scroll(0,0);},onMouseDown:onMouseDown,replace:replace,to:to// TODO: Refactor it later.
|
|
52
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
53
|
+
,...rest,children:children});};export default GenericLink;
|
|
107
54
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["jsx","_jsx","GenericLink","children","className","disabled","enforceA","keepScrollPosition","onClick","onMouseDown","openNewTab","replace","routerLinkType","to","rest","match","href","e","preventDefault","rel","styleName","target","L","discover","window","scroll"],"sources":["../../../../../src/shared/components/GenericLink/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport type {\n Link,\n LinkProps,\n NavLink,\n NavLinkProps,\n} from 'react-router';\n\nimport './style.scss';\n\ntype LinkT = typeof Link;\ntype NavLinkT = typeof NavLink;\n\ntype ToT = Parameters<typeof Link>[0]['to'];\n\nexport type PropsT = {\n children?: ReactNode;\n className?: string;\n disabled?: boolean;\n enforceA?: boolean;\n keepScrollPosition?: boolean;\n onClick?: React.MouseEventHandler<HTMLAnchorElement>;\n onMouseDown?: React.MouseEventHandler<HTMLAnchorElement>;\n openNewTab?: boolean;\n replace?: boolean;\n routerLinkType: LinkT | NavLinkT;\n to: ToT;\n};\n\n/**\n * The `<Link>` component, and almost identical `<NavLink>` component, are\n * auxiliary wrappers around\n * [React Router](https://github.com/ReactTraining/react-router)'s\n * `<Link>` and `<NavLink>` components; they help to handle external and\n * internal links in uniform manner.\n *\n * @param [props] Component properties.\n * @param [props.className] CSS classes to apply to the link.\n * @param [props.disabled] Disables the link.\n * @param [props.enforceA] `true` enforces rendering of the link as\n * a simple `<a>` element.\n * @param [props.keepScrollPosition] If `true`, and the link is\n * rendered as a React Router's component, it won't reset the viewport scrolling\n * position to the origin when clicked.\n * @param [props.onClick] Event handler to trigger upon click.\n * @param [props.onMouseDown] Event handler to trigger on MouseDown\n * event.\n * @param [props.openNewTab] If `true` the link opens in a new tab.\n * @param [props.replace] When `true`, the link will replace current\n * entry in the history stack instead of adding a new one.\n * @param [props.to] Link URL.\n * @param [props.activeClassName] **`<NavLink>`** only: CSS class(es)\n * to apply to rendered link when it is active.\n * @param [props.activeStyle] **`<NavLink>`** only: CSS styles\n * to apply to the rendered link when it is active.\n * @param [props.exact] **`<NavLink>`** only: if `true`, the active\n * class/style will only be applied if the location is matched exactly.\n * @param [props.isActive] **`<NavLink>`** only: Add extra\n * logic for determining whether the link is active. This should be used if you\n * want to do more than verify that the link’s pathname matches the current URL\n * pathname.\n * @param [props.location] **`<NavLink>`** only: `isActive` compares\n * current history location (usually the current browser URL). To compare to\n * a different location, a custom `location` can be passed.\n * @param [props.strict] **`<NavLink>`** only: . When `true`, trailing\n * slash on a location’s pathname will be taken into consideration when\n * determining if the location matches the current URL. See the `<Route strict>`\n * documentation for more information.\n */\nconst GenericLink = ({\n children,\n className,\n disabled,\n enforceA,\n keepScrollPosition,\n onClick,\n onMouseDown,\n openNewTab,\n replace,\n routerLinkType,\n to,\n ...rest\n}: (LinkProps | NavLinkProps) & PropsT): ReactNode => {\n /* Renders Link as <a> element if:\n * - It is opted explicitely by `enforceA` prop;\n * - It should be opened in a new tab;\n * - It is an absolte URL (starts with http:// or https://);\n * - It is anchor link (starts with #). */\n if (disabled || enforceA || openNewTab\n || (to as string).match(/^(#|(https?|mailto):)/)) {\n return (\n <a\n className={
|
|
1
|
+
{"version":3,"file":"index.js","names":["S","jsx","_jsx","GenericLink","children","className","disabled","enforceA","keepScrollPosition","onClick","onMouseDown","openNewTab","replace","routerLinkType","to","rest","match","aClassName","link","href","e","preventDefault","rel","styleName","target","L","discover","window","scroll"],"sources":["../../../../../src/shared/components/GenericLink/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport type {\n Link,\n LinkProps,\n NavLink,\n NavLinkProps,\n} from 'react-router';\n\nimport S from './style.scss';\n\ntype LinkT = typeof Link;\ntype NavLinkT = typeof NavLink;\n\ntype ToT = Parameters<typeof Link>[0]['to'];\n\nexport type PropsT = {\n children?: ReactNode;\n className?: string;\n disabled?: boolean;\n enforceA?: boolean;\n keepScrollPosition?: boolean;\n onClick?: React.MouseEventHandler<HTMLAnchorElement>;\n onMouseDown?: React.MouseEventHandler<HTMLAnchorElement>;\n openNewTab?: boolean;\n replace?: boolean;\n routerLinkType: LinkT | NavLinkT;\n to: ToT;\n};\n\n/**\n * The `<Link>` component, and almost identical `<NavLink>` component, are\n * auxiliary wrappers around\n * [React Router](https://github.com/ReactTraining/react-router)'s\n * `<Link>` and `<NavLink>` components; they help to handle external and\n * internal links in uniform manner.\n *\n * @param [props] Component properties.\n * @param [props.className] CSS classes to apply to the link.\n * @param [props.disabled] Disables the link.\n * @param [props.enforceA] `true` enforces rendering of the link as\n * a simple `<a>` element.\n * @param [props.keepScrollPosition] If `true`, and the link is\n * rendered as a React Router's component, it won't reset the viewport scrolling\n * position to the origin when clicked.\n * @param [props.onClick] Event handler to trigger upon click.\n * @param [props.onMouseDown] Event handler to trigger on MouseDown\n * event.\n * @param [props.openNewTab] If `true` the link opens in a new tab.\n * @param [props.replace] When `true`, the link will replace current\n * entry in the history stack instead of adding a new one.\n * @param [props.to] Link URL.\n * @param [props.activeClassName] **`<NavLink>`** only: CSS class(es)\n * to apply to rendered link when it is active.\n * @param [props.activeStyle] **`<NavLink>`** only: CSS styles\n * to apply to the rendered link when it is active.\n * @param [props.exact] **`<NavLink>`** only: if `true`, the active\n * class/style will only be applied if the location is matched exactly.\n * @param [props.isActive] **`<NavLink>`** only: Add extra\n * logic for determining whether the link is active. This should be used if you\n * want to do more than verify that the link’s pathname matches the current URL\n * pathname.\n * @param [props.location] **`<NavLink>`** only: `isActive` compares\n * current history location (usually the current browser URL). To compare to\n * a different location, a custom `location` can be passed.\n * @param [props.strict] **`<NavLink>`** only: . When `true`, trailing\n * slash on a location’s pathname will be taken into consideration when\n * determining if the location matches the current URL. See the `<Route strict>`\n * documentation for more information.\n */\nconst GenericLink = ({\n children,\n className,\n disabled,\n enforceA,\n keepScrollPosition,\n onClick,\n onMouseDown,\n openNewTab,\n replace,\n routerLinkType,\n to,\n ...rest\n}: (LinkProps | NavLinkProps) & PropsT): ReactNode => {\n /* Renders Link as <a> element if:\n * - It is opted explicitely by `enforceA` prop;\n * - It should be opened in a new tab;\n * - It is an absolte URL (starts with http:// or https://);\n * - It is anchor link (starts with #). */\n if (disabled || enforceA || openNewTab\n || (to as string).match(/^(#|(https?|mailto):)/)) {\n let aClassName: string = S.link;\n if (className) aClassName += ` ${className}`;\n\n return (\n <a\n className={aClassName}\n // TODO: This requires a fix: disabled is not really an attribute of <a>\n // tag, thus for disabled option we rather should render a plain text\n // styled as a link.\n // disabled={disabled}\n href={to as string}\n onClick={disabled ? (e) => {\n e.preventDefault();\n } : onClick}\n onMouseDown={disabled ? (e) => {\n e.preventDefault();\n } : onMouseDown}\n rel=\"noopener noreferrer\"\n styleName=\"link\"\n target={openNewTab ? '_blank' : ''}\n >\n {children}\n </a>\n );\n }\n\n const L = routerLinkType;\n\n return (\n <L\n className={className}\n discover=\"none\"\n // disabled\n onClick={(e: React.MouseEvent<HTMLAnchorElement>) => {\n // Executes the user-provided event handler, if any.\n if (onClick) onClick(e);\n\n // By default, clicking the link scrolls the page to beginning.\n if (!keepScrollPosition) window.scroll(0, 0);\n }}\n onMouseDown={onMouseDown}\n replace={replace}\n to={to}\n // TODO: Refactor it later.\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest}\n >\n {children}\n </L>\n );\n};\n\nexport default GenericLink;\n"],"mappings":"AASA,MAAO,CAAAA,CAAC,oBAAqB,OAAAC,GAAA,IAAAC,IAAA,yBAqB7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,KAAM,CAAAC,WAAW,CAAGA,CAAC,CACnBC,QAAQ,CACRC,SAAS,CACTC,QAAQ,CACRC,QAAQ,CACRC,kBAAkB,CAClBC,OAAO,CACPC,WAAW,CACXC,UAAU,CACVC,OAAO,CACPC,cAAc,CACdC,EAAE,CACF,GAAGC,IACgC,CAAC,GAAgB,CACpD;AACF;AACA;AACA;AACA,4CACE,GAAIT,QAAQ,EAAIC,QAAQ,EAAII,UAAU,EAChCG,EAAE,CAAYE,KAAK,CAAC,uBAAuB,CAAC,CAAE,CAClD,GAAI,CAAAC,UAAkB,CAAGjB,CAAC,CAACkB,IAAI,CAC/B,GAAIb,SAAS,CAAEY,UAAU,EAAI,IAAIZ,SAAS,EAAE,CAE5C,mBACEH,IAAA,MACEG,SAAS,CAAEY,UACX;AACA;AACA;AACA;AAAA,CACAE,IAAI,CAAEL,EAAa,CACnBL,OAAO,CAAEH,QAAQ,CAAIc,CAAC,EAAK,CACzBA,CAAC,CAACC,cAAc,CAAC,CAAC,CACpB,CAAC,CAAGZ,OAAQ,CACZC,WAAW,CAAEJ,QAAQ,CAAIc,CAAC,EAAK,CAC7BA,CAAC,CAACC,cAAc,CAAC,CAAC,CACpB,CAAC,CAAGX,WAAY,CAChBY,GAAG,CAAC,qBAAqB,CACzBC,SAAS,CAAC,MAAM,CAChBC,MAAM,CAAEb,UAAU,CAAG,QAAQ,CAAG,EAAG,CAAAP,QAAA,CAElCA,QAAQ,CACR,CAAC,CAER,CAEA,KAAM,CAAAqB,CAAC,CAAGZ,cAAc,CAExB,mBACEX,IAAA,CAACuB,CAAC,EACApB,SAAS,CAAEA,SAAU,CACrBqB,QAAQ,CAAC,MACT;AAAA,CACAjB,OAAO,CAAGW,CAAsC,EAAK,CACnD;AACA,GAAIX,OAAO,CAAEA,OAAO,CAACW,CAAC,CAAC,CAEvB;AACA,GAAI,CAACZ,kBAAkB,CAAEmB,MAAM,CAACC,MAAM,CAAC,CAAC,CAAE,CAAC,CAAC,CAC9C,CAAE,CACFlB,WAAW,CAAEA,WAAY,CACzBE,OAAO,CAAEA,OAAQ,CACjBE,EAAE,CAAEA,EACJ;AACA;AAAA,IACIC,IAAI,CAAAX,QAAA,CAEPA,QAAQ,CACR,CAAC,CAER,CAAC,CAED,cAAe,CAAAD,WAAW","ignoreList":[]}
|
|
@@ -1,76 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useTheme } from '@dr.pogodin/react-themes';
|
|
3
|
-
import defaultTheme from "./theme.scss";
|
|
4
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
-
/**
|
|
1
|
+
import{useRef,useState}from"react";import{useTheme}from"@dr.pogodin/react-themes";import defaultTheme from"./theme.scss";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";/**
|
|
6
2
|
* Themeable input field, based on the standard HTML `<input>` element.
|
|
7
3
|
* @param [props.label] Input label.
|
|
8
4
|
* @param [props.theme] _Ad hoc_ theme.
|
|
9
5
|
* @param [props...] [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
|
|
10
6
|
* @param [props...] Any other properties are passed to the underlying
|
|
11
7
|
* `<input>` element.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}) => {
|
|
23
|
-
const composed = useTheme('Input', defaultTheme, theme, {
|
|
24
|
-
composeAdhocTheme
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// NOTE: As of now, it is only updated when "theme.focused" is defined,
|
|
28
|
-
// as otherwise its value is not used.
|
|
29
|
-
const [focused, setFocused] = useState(false);
|
|
30
|
-
const localRef = useRef(null);
|
|
31
|
-
let containerClassName = composed.container;
|
|
32
|
-
|
|
33
|
-
// NOTE: As of now, "focused" can be true only when "theme.focused"
|
|
34
|
-
// is provided.
|
|
35
|
-
if (focused /* && theme.focused */) containerClassName += ` ${composed.focused}`;
|
|
36
|
-
if (!rest.value && composed.empty) containerClassName += ` ${composed.empty}`;
|
|
37
|
-
if (error) containerClassName += ` ${composed.error}`;
|
|
38
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
39
|
-
className: containerClassName,
|
|
40
|
-
onFocus: () => {
|
|
41
|
-
// TODO: It does not really work if a callback-style `ref` is passed in,
|
|
42
|
-
// we need a more complex logic to cover that case, but for now this serves
|
|
43
|
-
// the case we need it for.
|
|
44
|
-
if (typeof ref === 'object') ref?.current?.focus();else localRef.current?.focus();
|
|
45
|
-
},
|
|
46
|
-
children: [label === undefined ? null : /*#__PURE__*/_jsx("div", {
|
|
47
|
-
className: composed.label,
|
|
48
|
-
children: label
|
|
49
|
-
}), /*#__PURE__*/_jsx("input", {
|
|
50
|
-
className: composed.input,
|
|
51
|
-
"data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
|
|
52
|
-
ref: ref ?? localRef
|
|
53
|
-
|
|
54
|
-
// TODO: Avoid the spreading later.
|
|
55
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
56
|
-
,
|
|
57
|
-
...rest,
|
|
58
|
-
onBlur: composed.focused ? e => {
|
|
59
|
-
setFocused(false);
|
|
60
|
-
rest.onBlur?.(e);
|
|
61
|
-
} : rest.onBlur,
|
|
62
|
-
onFocus: composed.focused ? e => {
|
|
63
|
-
setFocused(true);
|
|
64
|
-
rest.onFocus?.(e);
|
|
65
|
-
} : rest.onFocus
|
|
66
|
-
}), error && error !== true ? /*#__PURE__*/_jsx("div", {
|
|
67
|
-
className: composed.errorMessage,
|
|
68
|
-
children: error
|
|
69
|
-
}) : null, children ? /*#__PURE__*/_jsx("div", {
|
|
70
|
-
className: composed.children,
|
|
71
|
-
children: children
|
|
72
|
-
}) : null]
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
export default Input;
|
|
8
|
+
*/const Input=({children,composeAdhocTheme,error,label,ref,testId,theme,...rest})=>{const composed=useTheme("Input",defaultTheme,theme,{composeAdhocTheme});// NOTE: As of now, it is only updated when "theme.focused" is defined,
|
|
9
|
+
// as otherwise its value is not used.
|
|
10
|
+
const[focused,setFocused]=useState(false);const localRef=useRef(null);let containerClassName=composed.container;// NOTE: As of now, "focused" can be true only when "theme.focused"
|
|
11
|
+
// is provided.
|
|
12
|
+
if(focused/* && theme.focused */)containerClassName+=` ${composed.focused}`;if(!rest.value&&composed.empty)containerClassName+=` ${composed.empty}`;if(error)containerClassName+=` ${composed.error}`;return/*#__PURE__*/_jsxs("div",{className:containerClassName,onFocus:()=>{// TODO: It does not really work if a callback-style `ref` is passed in,
|
|
13
|
+
// we need a more complex logic to cover that case, but for now this serves
|
|
14
|
+
// the case we need it for.
|
|
15
|
+
if(typeof ref==="object")ref?.current?.focus();else localRef.current?.focus();},children:[label===undefined?null:/*#__PURE__*/_jsx("div",{className:composed.label,children:label}),/*#__PURE__*/_jsx("input",{className:composed.input,"data-testid":process.env.NODE_ENV==="production"?undefined:testId,ref:ref??localRef// TODO: Avoid the spreading later.
|
|
16
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
17
|
+
,...rest,onBlur:composed.focused?e=>{setFocused(false);rest.onBlur?.(e);}:rest.onBlur,onFocus:composed.focused?e=>{setFocused(true);rest.onFocus?.(e);}:rest.onFocus}),error&&error!==true?/*#__PURE__*/_jsx("div",{className:composed.errorMessage,children:error}):null,children?/*#__PURE__*/_jsx("div",{className:composed.children,children:children}):null]});};export default Input;
|
|
76
18
|
//# sourceMappingURL=index.js.map
|