@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.
Files changed (210) hide show
  1. package/babel.scripts.config.js +19 -0
  2. package/build/development/client/getInj.js +18 -29
  3. package/build/development/client/getInj.js.map +1 -1
  4. package/build/development/client/index.js +11 -14
  5. package/build/development/client/index.js.map +1 -1
  6. package/build/development/client/init.js +9 -17
  7. package/build/development/client/init.js.map +1 -1
  8. package/build/development/index.js +26 -4
  9. package/build/development/index.js.map +1 -1
  10. package/build/development/server/Cache.js +15 -20
  11. package/build/development/server/Cache.js.map +1 -1
  12. package/build/development/server/index.js +142 -160
  13. package/build/development/server/index.js.map +1 -1
  14. package/build/development/server/renderer.js +150 -197
  15. package/build/development/server/renderer.js.map +1 -1
  16. package/build/development/server/server.js +63 -86
  17. package/build/development/server/server.js.map +1 -1
  18. package/build/development/server/utils/errors.js +72 -87
  19. package/build/development/server/utils/errors.js.map +1 -1
  20. package/build/development/shared/components/Button/index.js +8 -17
  21. package/build/development/shared/components/Button/index.js.map +1 -1
  22. package/build/development/shared/components/Checkbox/index.js +4 -4
  23. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  24. package/build/development/shared/components/GenericLink/index.js +54 -58
  25. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  26. package/build/development/shared/components/Input/index.js +16 -24
  27. package/build/development/shared/components/Input/index.js.map +1 -1
  28. package/build/development/shared/components/Link.js +2 -5
  29. package/build/development/shared/components/Link.js.map +1 -1
  30. package/build/development/shared/components/Modal/index.js +28 -41
  31. package/build/development/shared/components/Modal/index.js.map +1 -1
  32. package/build/development/shared/components/NavLink.js +2 -3
  33. package/build/development/shared/components/NavLink.js.map +1 -1
  34. package/build/development/shared/components/PageLayout/index.js +19 -20
  35. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  36. package/build/development/shared/components/TextArea/index.js +12 -28
  37. package/build/development/shared/components/TextArea/index.js.map +1 -1
  38. package/build/development/shared/components/Throbber/index.js +11 -12
  39. package/build/development/shared/components/Throbber/index.js.map +1 -1
  40. package/build/development/shared/components/WithTooltip/Tooltip.js +46 -68
  41. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  42. package/build/development/shared/components/WithTooltip/index.js +21 -28
  43. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  44. package/build/development/shared/components/YouTubeVideo/index.js +21 -25
  45. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  46. package/build/development/shared/components/index.js +1 -3
  47. package/build/development/shared/components/index.js.map +1 -1
  48. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +6 -7
  49. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  50. package/build/development/shared/components/selectors/CustomDropdown/index.js +7 -9
  51. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  52. package/build/development/shared/components/selectors/NativeDropdown/index.js +23 -27
  53. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  54. package/build/development/shared/components/selectors/Switch/index.js +4 -4
  55. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  56. package/build/development/shared/components/selectors/common.js +2 -5
  57. package/build/development/shared/components/selectors/common.js.map +1 -1
  58. package/build/development/shared/utils/config.js +11 -15
  59. package/build/development/shared/utils/config.js.map +1 -1
  60. package/build/development/shared/utils/globalState.js +1 -7
  61. package/build/development/shared/utils/globalState.js.map +1 -1
  62. package/build/development/shared/utils/index.js +2 -2
  63. package/build/development/shared/utils/index.js.map +1 -1
  64. package/build/development/shared/utils/isomorphy/buildInfo.js +15 -24
  65. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  66. package/build/development/shared/utils/isomorphy/environment-check.js +4 -9
  67. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  68. package/build/development/shared/utils/isomorphy/index.js +17 -23
  69. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  70. package/build/development/shared/utils/jest/E2eSsrEnv.js +48 -77
  71. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  72. package/build/development/shared/utils/jest/index.js +48 -72
  73. package/build/development/shared/utils/jest/index.js.map +1 -1
  74. package/build/development/shared/utils/splitComponent.js +67 -74
  75. package/build/development/shared/utils/splitComponent.js.map +1 -1
  76. package/build/development/shared/utils/time.js +25 -28
  77. package/build/development/shared/utils/time.js.map +1 -1
  78. package/build/development/shared/utils/webpack.js +22 -29
  79. package/build/development/shared/utils/webpack.js.map +1 -1
  80. package/build/production/client/getInj.js.map +1 -1
  81. package/build/production/client/index.js.map +1 -1
  82. package/build/production/index.js +26 -1
  83. package/build/production/index.js.map +1 -1
  84. package/build/production/server/Cache.js.map +1 -1
  85. package/build/production/server/index.js.map +1 -1
  86. package/build/production/server/renderer.js.map +1 -1
  87. package/build/production/server/server.js.map +1 -1
  88. package/build/production/shared/components/Button/index.js.map +1 -1
  89. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  90. package/build/production/shared/components/GenericLink/index.js +2 -2
  91. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  92. package/build/production/shared/components/Input/index.js.map +1 -1
  93. package/build/production/shared/components/Link.js.map +1 -1
  94. package/build/production/shared/components/Modal/index.js.map +1 -1
  95. package/build/production/shared/components/NavLink.js.map +1 -1
  96. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  97. package/build/production/shared/components/TextArea/index.js.map +1 -1
  98. package/build/production/shared/components/Throbber/index.js.map +1 -1
  99. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  100. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  101. package/build/production/shared/components/index.js.map +1 -1
  102. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  103. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  104. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  105. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  106. package/build/production/shared/utils/config.js.map +1 -1
  107. package/build/production/shared/utils/index.js.map +1 -1
  108. package/build/production/shared/utils/jest/index.js.map +1 -1
  109. package/build/production/shared/utils/splitComponent.js +20 -3
  110. package/build/production/shared/utils/splitComponent.js.map +1 -1
  111. package/build/production/shared/utils/time.js.map +1 -1
  112. package/build/production/shared/utils/webpack.js.map +1 -1
  113. package/build/types-code/shared/components/GenericLink/index.d.ts +0 -1
  114. package/build/web/client/getInj.js +10 -70
  115. package/build/web/client/getInj.js.map +1 -1
  116. package/build/web/client/index.js +2 -27
  117. package/build/web/client/index.js.map +1 -1
  118. package/build/web/client/init.js +10 -44
  119. package/build/web/client/init.js.map +1 -1
  120. package/build/web/index.js +26 -6
  121. package/build/web/index.js.map +1 -1
  122. package/build/web/server/Cache.js +3 -41
  123. package/build/web/server/Cache.js.map +1 -1
  124. package/build/web/server/index.js +7 -78
  125. package/build/web/server/index.js.map +1 -1
  126. package/build/web/server/renderer.js +61 -420
  127. package/build/web/server/renderer.js.map +1 -1
  128. package/build/web/server/server.js +38 -212
  129. package/build/web/server/server.js.map +1 -1
  130. package/build/web/server/utils/errors.js +9 -48
  131. package/build/web/server/utils/errors.js.map +1 -1
  132. package/build/web/server/utils/index.js +1 -2
  133. package/build/web/server/utils/index.js.map +1 -1
  134. package/build/web/shared/components/Button/index.js +12 -101
  135. package/build/web/shared/components/Button/index.js.map +1 -1
  136. package/build/web/shared/components/Checkbox/index.js +1 -40
  137. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  138. package/build/web/shared/components/Checkbox/theme.scss +1 -0
  139. package/build/web/shared/components/GenericLink/index.js +12 -65
  140. package/build/web/shared/components/GenericLink/index.js.map +1 -1
  141. package/build/web/shared/components/GenericLink/style.scss +1 -0
  142. package/build/web/shared/components/Input/index.js +11 -69
  143. package/build/web/shared/components/Input/index.js.map +1 -1
  144. package/build/web/shared/components/Link.js +2 -12
  145. package/build/web/shared/components/Link.js.map +1 -1
  146. package/build/web/shared/components/Modal/index.js +10 -130
  147. package/build/web/shared/components/Modal/index.js.map +1 -1
  148. package/build/web/shared/components/NavLink.js +2 -10
  149. package/build/web/shared/components/NavLink.js.map +1 -1
  150. package/build/web/shared/components/PageLayout/index.js +2 -27
  151. package/build/web/shared/components/PageLayout/index.js.map +1 -1
  152. package/build/web/shared/components/TextArea/index.js +21 -106
  153. package/build/web/shared/components/TextArea/index.js.map +1 -1
  154. package/build/web/shared/components/Throbber/index.js +2 -24
  155. package/build/web/shared/components/Throbber/index.js.map +1 -1
  156. package/build/web/shared/components/WithTooltip/Tooltip.js +16 -145
  157. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  158. package/build/web/shared/components/WithTooltip/index.js +12 -104
  159. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  160. package/build/web/shared/components/YouTubeVideo/index.js +5 -43
  161. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
  162. package/build/web/shared/components/index.js +1 -15
  163. package/build/web/shared/components/index.js.map +1 -1
  164. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +6 -81
  165. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  166. package/build/web/shared/components/selectors/CustomDropdown/index.js +7 -122
  167. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  168. package/build/web/shared/components/selectors/NativeDropdown/index.js +7 -68
  169. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  170. package/build/web/shared/components/selectors/Switch/index.js +1 -49
  171. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  172. package/build/web/shared/components/selectors/common.js +1 -10
  173. package/build/web/shared/components/selectors/common.js.map +1 -1
  174. package/build/web/shared/components/selectors/index.js +1 -3
  175. package/build/web/shared/components/selectors/index.js.map +1 -1
  176. package/build/web/shared/utils/config.js +6 -40
  177. package/build/web/shared/utils/config.js.map +1 -1
  178. package/build/web/shared/utils/globalState.js +2 -11
  179. package/build/web/shared/utils/globalState.js.map +1 -1
  180. package/build/web/shared/utils/index.js +1 -9
  181. package/build/web/shared/utils/index.js.map +1 -1
  182. package/build/web/shared/utils/isomorphy/buildInfo.js +4 -25
  183. package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
  184. package/build/web/shared/utils/isomorphy/environment-check.js +3 -9
  185. package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
  186. package/build/web/shared/utils/isomorphy/index.js +5 -27
  187. package/build/web/shared/utils/isomorphy/index.js.map +1 -1
  188. package/build/web/shared/utils/jest/E2eSsrEnv.js +51 -221
  189. package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  190. package/build/web/shared/utils/jest/global.js +1 -3
  191. package/build/web/shared/utils/jest/global.js.map +1 -1
  192. package/build/web/shared/utils/jest/index.js +27 -146
  193. package/build/web/shared/utils/jest/index.js.map +1 -1
  194. package/build/web/shared/utils/splitComponent.js +34 -197
  195. package/build/web/shared/utils/splitComponent.js.map +1 -1
  196. package/build/web/shared/utils/time.js +5 -69
  197. package/build/web/shared/utils/time.js.map +1 -1
  198. package/build/web/shared/utils/webpack.js +6 -53
  199. package/build/web/shared/utils/webpack.js.map +1 -1
  200. package/config/babel/webpack.js +1 -1
  201. package/eslint.config.mjs +1 -0
  202. package/package.json +5 -8
  203. package/bin/build.js +0 -236
  204. package/config/webpack/lib-base.d.ts +0 -22
  205. package/config/webpack/lib-base.js +0 -167
  206. package/config/webpack/lib-development.d.ts +0 -5
  207. package/config/webpack/lib-development.js +0 -35
  208. package/config/webpack/lib-production.d.ts +0 -5
  209. package/config/webpack/lib-production.js +0 -42
  210. package/webpack.config.ts +0 -49
@@ -1,98 +1,83 @@
1
- import "core-js/modules/es.json.stringify.js";
2
- /**
3
- * @category Utilities
4
- * @module server/errors
5
- * @desc
6
- * ```js
7
- * import { server } from '@dr.pogodin/react-utils';
8
- * const { errors } = server;
9
- * ```
10
- * Server-side helpers for error handling.
11
- */
12
-
13
- import { StatusCodes as CODES, ReasonPhrases as ERRORS, getReasonPhrase as getErrorForCode } from 'http-status-codes';
14
- /**
15
- * @static
16
- * @const CODES
17
- * @desc An alias for
18
- * [StatusCodes object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).
19
- * It is a map between HTTP status code names and corresponding numeric codes.
20
- * @example
21
- * import { server } from '@dr.pogodin/react-utils';
22
- * const { CODES } = server.errors;
23
- * console.log(CODES.BAD_REQUEST); // Prints: 400
24
- */
25
- export { CODES };
26
-
27
- /**
28
- * @static
29
- * @const ERRORS
30
- * @desc An alias for
31
- * [ReasonPhrases object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).
32
- * It is a map between HTTP status code names and their pretty-printed forms.
33
- * @example
34
- * import { server } from '@dr.pogodin/react-utils';
35
- * const { ERRORS } = server.errors;
36
- * console.log(ERRORS.BAD_REQUEST); // Prints: Bad Request
37
- */
38
- export { ERRORS };
39
-
40
- /**
41
- * @static
42
- * @func getErrorForCode
43
- * @desc An alias for
44
- * [getReasonPhrase() function from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).
45
- * Given an HTTP code it returns the corresponding error text.
46
- * @param {number} code HTTP code.
47
- * @return {string} HTTP error text.
48
- * @example
49
- * import { server } from '@dr.pogodin/react-utils';
50
- * console.log(server.errors.getErrorForCode(400)); // Prints: Bad Request
51
- */
52
- export { getErrorForCode };
53
-
54
- // TODO: It could accept the status code as a constructor argument.
1
+ import "core-js/modules/es.json.stringify.js"; /**
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
+ import { StatusCodes as CODES, ReasonPhrases as ERRORS, getReasonPhrase as getErrorForCode } from "http-status-codes"; /**
12
+ * @static
13
+ * @const CODES
14
+ * @desc An alias for
15
+ * [StatusCodes object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).
16
+ * It is a map between HTTP status code names and corresponding numeric codes.
17
+ * @example
18
+ * import { server } from '@dr.pogodin/react-utils';
19
+ * const { CODES } = server.errors;
20
+ * console.log(CODES.BAD_REQUEST); // Prints: 400
21
+ */
22
+ export { CODES }; /**
23
+ * @static
24
+ * @const ERRORS
25
+ * @desc An alias for
26
+ * [ReasonPhrases object from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).
27
+ * It is a map between HTTP status code names and their pretty-printed forms.
28
+ * @example
29
+ * import { server } from '@dr.pogodin/react-utils';
30
+ * const { ERRORS } = server.errors;
31
+ * console.log(ERRORS.BAD_REQUEST); // Prints: Bad Request
32
+ */
33
+ export { ERRORS }; /**
34
+ * @static
35
+ * @func getErrorForCode
36
+ * @desc An alias for
37
+ * [getReasonPhrase() function from **http-status-codes** library](https://www.npmjs.com/package/http-status-codes).
38
+ * Given an HTTP code it returns the corresponding error text.
39
+ * @param {number} code HTTP code.
40
+ * @return {string} HTTP error text.
41
+ * @example
42
+ * import { server } from '@dr.pogodin/react-utils';
43
+ * console.log(server.errors.getErrorForCode(400)); // Prints: Bad Request
44
+ */
45
+ export { getErrorForCode }; // TODO: It could accept the status code as a constructor argument.
55
46
  class ErrorWithStatus extends Error {
56
47
  status = CODES.INTERNAL_SERVER_ERROR;
57
- }
58
-
59
- /**
60
- * ```js
61
- * import { server } from '@dr.pogodin/react-utils';
62
- * const { newError } = server.errors;
63
- * ```
64
- * Creates a new `Error` object with given message, and HTTP status code
65
- * attached as `status` field.
66
- * @param {string} message Error message.
67
- * @param {number} [statusCode=500] HTTP status code. Defaults to 500 (Internal
68
- * Server Error).
69
- * @return {Error}
70
- */
48
+ } /**
49
+ * ```js
50
+ * import { server } from '@dr.pogodin/react-utils';
51
+ * const { newError } = server.errors;
52
+ * ```
53
+ * Creates a new `Error` object with given message, and HTTP status code
54
+ * attached as `status` field.
55
+ * @param {string} message Error message.
56
+ * @param {number} [statusCode=500] HTTP status code. Defaults to 500 (Internal
57
+ * Server Error).
58
+ * @return {Error}
59
+ */
71
60
  export function newError(message, statusCode = CODES.INTERNAL_SERVER_ERROR) {
72
61
  const error = new ErrorWithStatus(message);
73
62
  error.status = statusCode;
74
63
  return error;
75
- }
76
-
77
- /**
78
- * Throws an error with given message and HTTP status code.
79
- */
64
+ } /**
65
+ * Throws an error with given message and HTTP status code.
66
+ */
80
67
  export function fail(message, statusCode = CODES.INTERNAL_SERVER_ERROR) {
81
68
  throw newError(message, statusCode);
82
- }
83
-
84
- /**
85
- * Validates the `value` against the given "standard" validation `schema`.
86
- * Resolves to the correctly typed `value`, if it has passed the validation;
87
- * otherwise throws an error.
88
- * @param value The value to validate.
89
- * @param schema The "standard" validation schema to use.
90
- * @param [message] Optional error message, to prepend the validation error
91
- * message.
92
- * @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);
69
+ } /**
70
+ * Validates the `value` against the given "standard" validation `schema`.
71
+ * Resolves to the correctly typed `value`, if it has passed the validation;
72
+ * otherwise throws an error.
73
+ * @param value The value to validate.
74
+ * @param schema The "standard" validation schema to use.
75
+ * @param [message] Optional error message, to prepend the validation error
76
+ * message.
77
+ * @param [statusCode=400] HTTP status code. Defaults to 400 (Bad Request).
78
+ */
79
+ export async function assert(value, schema, message = "", statusCode = CODES.BAD_REQUEST) {
80
+ let result = schema["~standard"].validate(value);
96
81
  if (result instanceof Promise) result = await result;
97
82
  if (result.issues) {
98
83
  let error = JSON.stringify(result.issues, null, 2);
@@ -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":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,WAAW,IAAIC,KAAK,EACpBC,aAAa,IAAIC,MAAM,EACvBC,eAAe,IAAIC,eAAe,QAC7B,mBAAmB;AAI1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASJ,KAAK;;AAEd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,MAAM;;AAEf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,eAAe;;AAExB;AACA,MAAMC,eAAe,SAASC,KAAK,CAAC;EAClCC,MAAM,GAAWP,KAAK,CAACQ,qBAAqB;AAC9C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CACtBC,OAAe,EACfC,UAAU,GAAGX,KAAK,CAACQ,qBAAqB,EACvB;EACjB,MAAMI,KAAK,GAAG,IAAIP,eAAe,CAACK,OAAO,CAAC;EAC1CE,KAAK,CAACL,MAAM,GAAGI,UAAU;EACzB,OAAOC,KAAK;AACd;;AAEA;AACA;AACA;AACA,OAAO,SAASC,IAAIA,CAClBH,OAAe,EACfC,UAAiB,GAAGX,KAAK,CAACQ,qBAAqB,EACxC;EACP,MAAMC,QAAQ,CAACC,OAAO,EAAEC,UAAU,CAAC;AACrC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeG,MAAMA,CAC1BC,KAAc,EACdC,MAAS,EACTN,OAAO,GAAG,EAAE,EACZC,UAAU,GAAGX,KAAK,CAACiB,WAAW,EACY;EAC1C,IAAIC,MAAM,GAAGF,MAAM,CAAC,WAAW,CAAC,CAACG,QAAQ,CAACJ,KAAK,CAAC;EAChD,IAAIG,MAAM,YAAYE,OAAO,EAAEF,MAAM,GAAG,MAAMA,MAAM;EAEpD,IAAIA,MAAM,CAACG,MAAM,EAAE;IACjB,IAAIT,KAAK,GAAGU,IAAI,CAACC,SAAS,CAACL,MAAM,CAACG,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,IAAIX,OAAO,EAAEE,KAAK,GAAG,GAAGF,OAAO,OAAOE,KAAK,EAAE;IAC7C,MAAMC,IAAI,CAACD,KAAK,EAAED,UAAU,CAAC;EAC/B;EAEA,OAAOO,MAAM,CAACH,KAAK;AACrB","ignoreList":[]}
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":"8CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SACEA,WAAW,IAAIC,KAAK,EACpBC,aAAa,IAAIC,MAAM,EACvBC,eAAe,IAAIC,eAAe,QAC7B,mBAAmB,CAI1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASJ,KAAK,GAEd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,MAAM,GAEf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,eAAe,GAExB;AACA,MAAMC,eAAe,SAASC,KAAM;EAClCC,MAAM,GAAWP,KAAK,CAACQ,qBAAqB;AAC9C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CACtBC,OAAe,EACfC,UAAU,GAAGX,KAAK,CAACQ,qBAAqB,EACvB;EACjB,MAAMI,KAAK,GAAG,IAAIP,eAAe,CAACK,OAAO,CAAC;EAC1CE,KAAK,CAACL,MAAM,GAAGI,UAAU;EACzB,OAAOC,KAAK;AACd,CAEA;AACA;AACA;AACA,OAAO,SAASC,IAAIA,CAClBH,OAAe,EACfC,UAAiB,GAAGX,KAAK,CAACQ,qBAAqB,EACxC;EACP,MAAMC,QAAQ,CAACC,OAAO,EAAEC,UAAU,CAAC;AACrC,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeG,MAAMA,CAC1BC,KAAc,EACdC,MAAS,EACTN,OAAO,GAAG,EAAE,EACZC,UAAU,GAAGX,KAAK,CAACiB,WAAW,EACY;EAC1C,IAAIC,MAAM,GAAGF,MAAM,CAAC,WAAW,CAAC,CAACG,QAAQ,CAACJ,KAAK,CAAC;EAChD,IAAIG,MAAM,YAAYE,OAAO,EAAEF,MAAM,GAAG,MAAMA,MAAM;EAEpD,IAAIA,MAAM,CAACG,MAAM,EAAE;IACjB,IAAIT,KAAK,GAAGU,IAAI,CAACC,SAAS,CAACL,MAAM,CAACG,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,IAAIX,OAAO,EAAEE,KAAK,GAAG,GAAGF,OAAO,OAAOE,KAAK,EAAE;IAC7C,MAAMC,IAAI,CAACD,KAAK,EAAED,UAAU,CAAC;EAC/B;EAEA,OAAOO,MAAM,CAACH,KAAK;AACrB","ignoreList":[]}
@@ -1,6 +1,5 @@
1
1
  // The <Button> component implements a standard button / button-like link.
2
-
3
- import { useTheme } from '@dr.pogodin/react-themes';
2
+ import { useTheme } from "@dr.pogodin/react-themes";
4
3
  import Link from "../Link.js";
5
4
  const defaultTheme = {
6
5
  "context": "-dr-pogodin-react-utils___build-web-shared-components-Button-style___context___0S7CYa",
@@ -36,39 +35,33 @@ export const BaseButton = ({
36
35
  if (theme.disabled) className += ` ${theme.disabled}`;
37
36
  return /*#__PURE__*/_jsx("div", {
38
37
  className: className,
39
- "data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
38
+ "data-testid": process.env.NODE_ENV === "production" ? undefined : testId,
40
39
  children: children
41
40
  });
42
41
  }
43
42
  let onKeyDown = onKeyDownProp;
44
43
  if (!onKeyDown && onClick) {
45
44
  onKeyDown = e => {
46
- if (e.key === 'Enter') onClick(e);
45
+ if (e.key === "Enter") onClick(e);
47
46
  };
48
47
  }
49
48
  if (to) {
50
49
  return /*#__PURE__*/_jsx(Link, {
51
50
  className: className,
52
- "data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
53
- enforceA: enforceA
54
-
55
- // TODO: This was exposed as a hotifx... however, I guess we better want
51
+ "data-testid": process.env.NODE_ENV === "production" ? undefined : testId,
52
+ enforceA: enforceA // TODO: This was exposed as a hotifx... however, I guess we better want
56
53
  // to check if the `to` URL contains an anchor (#), and if it does we should
57
54
  // automatically opt to keep the position here; and enforce <a> (as
58
55
  // react-router link does not seem to respect the hash tag either,
59
56
  // at least not without some additional settings).
60
57
  ,
61
-
62
58
  keepScrollPosition: keepScrollPosition,
63
- onClick: onClick
64
-
65
- // TODO: For now, the `onKeyDown` handler is not passed to the <Link>,
59
+ onClick: onClick // TODO: For now, the `onKeyDown` handler is not passed to the <Link>,
66
60
  // as <Link> component does not call it anyway, presumably due to
67
61
  // the inner implementation details. We should look into supporting it:
68
62
  // https://github.com/birdofpreyru/react-utils/issues/444
69
63
  // onKeyDown={onKeyDown}
70
64
  ,
71
-
72
65
  onKeyUp: onKeyUp,
73
66
  onMouseDown: onMouseDown,
74
67
  onMouseUp: onMouseUp,
@@ -82,7 +75,7 @@ export const BaseButton = ({
82
75
  }
83
76
  return /*#__PURE__*/_jsx("div", {
84
77
  className: className,
85
- "data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
78
+ "data-testid": process.env.NODE_ENV === "production" ? undefined : testId,
86
79
  onClick: onClick,
87
80
  onKeyDown: onKeyDown,
88
81
  onKeyUp: onKeyUp,
@@ -99,9 +92,7 @@ const Button = ({
99
92
  theme,
100
93
  ...rest
101
94
  }) => {
102
- const composed = useTheme('Button', defaultTheme, theme);
103
-
104
- // eslint-disable-next-line react/jsx-props-no-spreading
95
+ const composed = useTheme("Button", defaultTheme, theme); // eslint-disable-next-line react/jsx-props-no-spreading
105
96
  return /*#__PURE__*/_jsx(BaseButton, {
106
97
  ...rest,
107
98
  theme: composed
@@ -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":"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","ignoreList":[]}
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":"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","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { useTheme } from '@dr.pogodin/react-themes';
1
+ import { useTheme } from "@dr.pogodin/react-themes";
2
2
  const defaultTheme = {
3
3
  "context": "-dr-pogodin-react-utils___build-web-shared-components-Checkbox-theme___context___08mmmo",
4
4
  "ad": "-dr-pogodin-react-utils___build-web-shared-components-Checkbox-theme___ad___Hc06MV",
@@ -21,11 +21,11 @@ const Checkbox = ({
21
21
  testId,
22
22
  theme
23
23
  }) => {
24
- const composed = useTheme('Checkbox', defaultTheme, theme);
24
+ const composed = useTheme("Checkbox", defaultTheme, theme);
25
25
  let containerClassName = composed.container;
26
26
  if (disabled) containerClassName += ` ${composed.disabled}`;
27
27
  let checkboxClassName = composed.checkbox;
28
- if (checked === 'indeterminate') checkboxClassName += ` ${composed.indeterminate}`;
28
+ if (checked === "indeterminate") checkboxClassName += ` ${composed.indeterminate}`;
29
29
  if (error) containerClassName += ` ${composed.error}`;
30
30
  return /*#__PURE__*/_jsxs("div", {
31
31
  className: containerClassName,
@@ -35,7 +35,7 @@ const Checkbox = ({
35
35
  }), /*#__PURE__*/_jsx("input", {
36
36
  checked: checked === undefined ? undefined : checked === true,
37
37
  className: checkboxClassName,
38
- "data-testid": process.env.NODE_ENV === 'production' ? undefined : testId,
38
+ "data-testid": process.env.NODE_ENV === "production" ? undefined : testId,
39
39
  disabled: disabled,
40
40
  onChange: onChange,
41
41
  onClick: e => {
@@ -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,SAAqBA,QAAQ,QAAQ,0BAA0B;AAAA,MAAAC,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAEvB,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAoBxC,MAAMC,QAAQ,GAAGA,CAAqD;EACpEC,OAAO;EACPC,QAAQ;EACRC,KAAK;EACLC,KAAK;EACLC,QAAQ;EACRC,MAAM;EACNC;AACa,CAAC,KAAgB;EAC9B,MAAMC,QAAQ,GAAGd,QAAQ,CAAC,UAAU,EAAEC,YAAY,EAAEY,KAAK,CAAC;EAE1D,IAAIE,kBAAkB,GAAGD,QAAQ,CAACE,SAAS;EAC3C,IAAIR,QAAQ,EAAEO,kBAAkB,IAAI,IAAID,QAAQ,CAACN,QAAQ,EAAE;EAE3D,IAAIS,iBAAiB,GAAGH,QAAQ,CAACI,QAAQ;EACzC,IAAIX,OAAO,KAAK,eAAe,EAAEU,iBAAiB,IAAI,IAAIH,QAAQ,CAACK,aAAa,EAAE;EAElF,IAAIV,KAAK,EAAEM,kBAAkB,IAAI,IAAID,QAAQ,CAACL,KAAK,EAAE;EAErD,oBACEJ,KAAA;IAAKe,SAAS,EAAEL,kBAAmB;IAAAM,QAAA,GAC/BX,KAAK,KAAKY,SAAS,GACjB,IAAI,gBAAGnB,IAAA;MAAKiB,SAAS,EAAEN,QAAQ,CAACJ,KAAM;MAAAW,QAAA,EAAEX;IAAK,CAAM,CAAC,eACxDP,IAAA;MACEI,OAAO,EAAEA,OAAO,KAAKe,SAAS,GAAGA,SAAS,GAAGf,OAAO,KAAK,IAAK;MAC9Da,SAAS,EAAEH,iBAAkB;MAC7B,eAAaM,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAAGH,SAAS,GAAGV,MAAO;MACxEJ,QAAQ,EAAEA,QAAS;MACnBG,QAAQ,EAAEA,QAAS;MACnBe,OAAO,EAAGC,CAAC,IAAK;QACdA,CAAC,CAACC,eAAe,CAAC,CAAC;MACrB,CAAE;MACFC,IAAI,EAAC;IAAU,CAChB,CAAC,EACDpB,KAAK,IAAIA,KAAK,KAAK,IAAI,gBACpBN,IAAA;MAAKiB,SAAS,EAAEN,QAAQ,CAACgB,YAAa;MAAAT,QAAA,EAAEZ;IAAK,CAAM,CAAC,GACpD,IAAI;EAAA,CACL,CAAC;AAEV,CAAC;AAED,eAAeH,QAAQ","ignoreList":[]}
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,SAAqBA,QAAQ,QAAQ,0BAA0B;AAE/D,MAAAC,YAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAoBxC,MAAMC,QAAQ,GAAGA,CAAqD;EACpEC,OAAO;EACPC,QAAQ;EACRC,KAAK;EACLC,KAAK;EACLC,QAAQ;EACRC,MAAM;EACNC;AACa,CAAC,KAAgB;EAC9B,MAAMC,QAAQ,GAAGd,QAAQ,CAAC,UAAU,EAAEC,YAAY,EAAEY,KAAK,CAAC;EAE1D,IAAIE,kBAAkB,GAAGD,QAAQ,CAACE,SAAS;EAC3C,IAAIR,QAAQ,EAAEO,kBAAkB,IAAI,IAAID,QAAQ,CAACN,QAAQ,EAAE;EAE3D,IAAIS,iBAAiB,GAAGH,QAAQ,CAACI,QAAQ;EACzC,IAAIX,OAAO,KAAK,eAAe,EAAEU,iBAAiB,IAAI,IAAIH,QAAQ,CAACK,aAAa,EAAE;EAElF,IAAIV,KAAK,EAAEM,kBAAkB,IAAI,IAAID,QAAQ,CAACL,KAAK,EAAE;EAErD,oBACEJ,KAAA;IAAKe,SAAS,EAAEL,kBAAmB;IAAAM,QAAA,GAC/BX,KAAK,KAAKY,SAAS,GACjB,IAAI,gBAAGnB,IAAA;MAAKiB,SAAS,EAAEN,QAAQ,CAACJ,KAAM;MAAAW,QAAA,EAAEX;IAAK,CAAM,CAAC,eACxDP,IAAA;MACEI,OAAO,EAAEA,OAAO,KAAKe,SAAS,GAAGA,SAAS,GAAGf,OAAO,KAAK,IAAK;MAC9Da,SAAS,EAAEH,iBAAkB;MAC7B,eAAaM,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAAGH,SAAS,GAAGV,MAAO;MACxEJ,QAAQ,EAAEA,QAAS;MACnBG,QAAQ,EAAEA,QAAS;MACnBe,OAAO,EAAGC,CAAC,IAAK;QACdA,CAAC,CAACC,eAAe,CAAC,CAAC;MACrB,CAAE;MACFC,IAAI,EAAC;IAAU,CAChB,CAAC,EACDpB,KAAK,IAAIA,KAAK,KAAK,IAAI,gBACpBN,IAAA;MAAKiB,SAAS,EAAEN,QAAQ,CAACgB,YAAa;MAAAT,QAAA,EAAEZ;IAAK,CAAM,CAAC,GACpD,IAAI;EAAA,CACL,CAAC;AAEV,CAAC;AAED,eAAeH,QAAQ","ignoreList":[]}
@@ -1,44 +1,46 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- /**
3
- * The `<Link>` component, and almost identical `<NavLink>` component, are
4
- * auxiliary wrappers around
5
- * [React Router](https://github.com/ReactTraining/react-router)'s
6
- * `<Link>` and `<NavLink>` components; they help to handle external and
7
- * internal links in uniform manner.
8
- *
9
- * @param [props] Component properties.
10
- * @param [props.className] CSS classes to apply to the link.
11
- * @param [props.disabled] Disables the link.
12
- * @param [props.enforceA] `true` enforces rendering of the link as
13
- * a simple `<a>` element.
14
- * @param [props.keepScrollPosition] If `true`, and the link is
15
- * rendered as a React Router's component, it won't reset the viewport scrolling
16
- * position to the origin when clicked.
17
- * @param [props.onClick] Event handler to trigger upon click.
18
- * @param [props.onMouseDown] Event handler to trigger on MouseDown
19
- * event.
20
- * @param [props.openNewTab] If `true` the link opens in a new tab.
21
- * @param [props.replace] When `true`, the link will replace current
22
- * entry in the history stack instead of adding a new one.
23
- * @param [props.to] Link URL.
24
- * @param [props.activeClassName] **`<NavLink>`** only: CSS class(es)
25
- * to apply to rendered link when it is active.
26
- * @param [props.activeStyle] **`<NavLink>`** only: CSS styles
27
- * to apply to the rendered link when it is active.
28
- * @param [props.exact] **`<NavLink>`** only: if `true`, the active
29
- * class/style will only be applied if the location is matched exactly.
30
- * @param [props.isActive] **`<NavLink>`** only: Add extra
31
- * logic for determining whether the link is active. This should be used if you
32
- * want to do more than verify that the link’s pathname matches the current URL
33
- * pathname.
34
- * @param [props.location] **`<NavLink>`** only: `isActive` compares
35
- * current history location (usually the current browser URL). To compare to
36
- * a different location, a custom `location` can be passed.
37
- * @param [props.strict] **`<NavLink>`** only: . When `true`, trailing
38
- * slash on a location’s pathname will be taken into consideration when
39
- * determining if the location matches the current URL. See the `<Route strict>`
40
- * documentation for more information.
41
- */
1
+ const S = {
2
+ "link": "-dr-pogodin-react-utils___build-web-shared-components-GenericLink-style___link___hXmkf-"
3
+ };
4
+ import { jsx as _jsx } from "react/jsx-runtime"; /**
5
+ * The `<Link>` component, and almost identical `<NavLink>` component, are
6
+ * auxiliary wrappers around
7
+ * [React Router](https://github.com/ReactTraining/react-router)'s
8
+ * `<Link>` and `<NavLink>` components; they help to handle external and
9
+ * internal links in uniform manner.
10
+ *
11
+ * @param [props] Component properties.
12
+ * @param [props.className] CSS classes to apply to the link.
13
+ * @param [props.disabled] Disables the link.
14
+ * @param [props.enforceA] `true` enforces rendering of the link as
15
+ * a simple `<a>` element.
16
+ * @param [props.keepScrollPosition] If `true`, and the link is
17
+ * rendered as a React Router's component, it won't reset the viewport scrolling
18
+ * position to the origin when clicked.
19
+ * @param [props.onClick] Event handler to trigger upon click.
20
+ * @param [props.onMouseDown] Event handler to trigger on MouseDown
21
+ * event.
22
+ * @param [props.openNewTab] If `true` the link opens in a new tab.
23
+ * @param [props.replace] When `true`, the link will replace current
24
+ * entry in the history stack instead of adding a new one.
25
+ * @param [props.to] Link URL.
26
+ * @param [props.activeClassName] **`<NavLink>`** only: CSS class(es)
27
+ * to apply to rendered link when it is active.
28
+ * @param [props.activeStyle] **`<NavLink>`** only: CSS styles
29
+ * to apply to the rendered link when it is active.
30
+ * @param [props.exact] **`<NavLink>`** only: if `true`, the active
31
+ * class/style will only be applied if the location is matched exactly.
32
+ * @param [props.isActive] **`<NavLink>`** only: Add extra
33
+ * logic for determining whether the link is active. This should be used if you
34
+ * want to do more than verify that the link’s pathname matches the current URL
35
+ * pathname.
36
+ * @param [props.location] **`<NavLink>`** only: `isActive` compares
37
+ * current history location (usually the current browser URL). To compare to
38
+ * a different location, a custom `location` can be passed.
39
+ * @param [props.strict] **`<NavLink>`** only: . When `true`, trailing
40
+ * slash on a location’s pathname will be taken into consideration when
41
+ * determining if the location matches the current URL. See the `<Route strict>`
42
+ * documentation for more information.
43
+ */
42
44
  const GenericLink = ({
43
45
  children,
44
46
  className,
@@ -54,19 +56,19 @@ const GenericLink = ({
54
56
  ...rest
55
57
  }) => {
56
58
  /* Renders Link as <a> element if:
57
- * - It is opted explicitely by `enforceA` prop;
58
- * - It should be opened in a new tab;
59
- * - It is an absolte URL (starts with http:// or https://);
60
- * - It is anchor link (starts with #). */
59
+ * - It is opted explicitely by `enforceA` prop;
60
+ * - It should be opened in a new tab;
61
+ * - It is an absolte URL (starts with http:// or https://);
62
+ * - It is anchor link (starts with #). */
61
63
  if (disabled || enforceA || openNewTab || to.match(/^(#|(https?|mailto):)/)) {
64
+ let aClassName = S.link;
65
+ if (className) aClassName += ` ${className}`;
62
66
  return /*#__PURE__*/_jsx("a", {
63
- className: className
64
- // TODO: This requires a fix: disabled is not really an attribute of <a>
67
+ className: aClassName // TODO: This requires a fix: disabled is not really an attribute of <a>
65
68
  // tag, thus for disabled option we rather should render a plain text
66
69
  // styled as a link.
67
70
  // disabled={disabled}
68
71
  ,
69
-
70
72
  href: to,
71
73
  onClick: disabled ? e => {
72
74
  e.preventDefault();
@@ -76,31 +78,25 @@ const GenericLink = ({
76
78
  } : onMouseDown,
77
79
  rel: "noopener noreferrer",
78
80
  styleName: "link",
79
- target: openNewTab ? '_blank' : '',
81
+ target: openNewTab ? "_blank" : "",
80
82
  children: children
81
83
  });
82
84
  }
83
85
  const L = routerLinkType;
84
86
  return /*#__PURE__*/_jsx(L, {
85
87
  className: className,
86
- discover: "none"
87
- // disabled
88
+ discover: "none" // disabled
88
89
  ,
89
-
90
90
  onClick: e => {
91
91
  // Executes the user-provided event handler, if any.
92
- if (onClick) onClick(e);
93
-
94
- // By default, clicking the link scrolls the page to beginning.
92
+ if (onClick) onClick(e); // By default, clicking the link scrolls the page to beginning.
95
93
  if (!keepScrollPosition) window.scroll(0, 0);
96
94
  },
97
95
  onMouseDown: onMouseDown,
98
96
  replace: replace,
99
- to: to
100
- // TODO: Refactor it later.
97
+ to: to // TODO: Refactor it later.
101
98
  // eslint-disable-next-line react/jsx-props-no-spreading
102
99
  ,
103
-
104
100
  ...rest,
105
101
  children: children
106
102
  });
@@ -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={className}\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":"AASsB,SAAAA,GAAA,IAAAC,IAAA;AAqBtB;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;AACA,MAAMC,WAAW,GAAGA,CAAC;EACnBC,QAAQ;EACRC,SAAS;EACTC,QAAQ;EACRC,QAAQ;EACRC,kBAAkB;EAClBC,OAAO;EACPC,WAAW;EACXC,UAAU;EACVC,OAAO;EACPC,cAAc;EACdC,EAAE;EACF,GAAGC;AACgC,CAAC,KAAgB;EACpD;AACF;AACA;AACA;AACA;EACE,IAAIT,QAAQ,IAAIC,QAAQ,IAAII,UAAU,IAChCG,EAAE,CAAYE,KAAK,CAAC,uBAAuB,CAAC,EAAE;IAClD,oBACEd,IAAA;MACEG,SAAS,EAAEA;MACX;MACA;MACA;MACA;MAAA;;MACAY,IAAI,EAAEH,EAAa;MACnBL,OAAO,EAAEH,QAAQ,GAAIY,CAAC,IAAK;QACzBA,CAAC,CAACC,cAAc,CAAC,CAAC;MACpB,CAAC,GAAGV,OAAQ;MACZC,WAAW,EAAEJ,QAAQ,GAAIY,CAAC,IAAK;QAC7BA,CAAC,CAACC,cAAc,CAAC,CAAC;MACpB,CAAC,GAAGT,WAAY;MAChBU,GAAG,EAAC,qBAAqB;MACzBC,SAAS,EAAC,MAAM;MAChBC,MAAM,EAAEX,UAAU,GAAG,QAAQ,GAAG,EAAG;MAAAP,QAAA,EAElCA;IAAQ,CACR,CAAC;EAER;EAEA,MAAMmB,CAAC,GAAGV,cAAc;EAExB,oBACEX,IAAA,CAACqB,CAAC;IACAlB,SAAS,EAAEA,SAAU;IACrBmB,QAAQ,EAAC;IACT;IAAA;;IACAf,OAAO,EAAGS,CAAsC,IAAK;MACnD;MACA,IAAIT,OAAO,EAAEA,OAAO,CAACS,CAAC,CAAC;;MAEvB;MACA,IAAI,CAACV,kBAAkB,EAAEiB,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAE;IACFhB,WAAW,EAAEA,WAAY;IACzBE,OAAO,EAAEA,OAAQ;IACjBE,EAAE,EAAEA;IACJ;IACA;IAAA;;IAAA,GACIC,IAAI;IAAAX,QAAA,EAEPA;EAAQ,CACR,CAAC;AAER,CAAC;AAED,eAAeD,WAAW","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["jsx","_jsx","GenericLink","children","className","disabled","enforceA","keepScrollPosition","onClick","onMouseDown","openNewTab","replace","routerLinkType","to","rest","match","aClassName","S","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":";;;AAS6B,SAAAA,GAAA,IAAAC,IAAA,4BAqB7B;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;AACA,MAAMC,WAAW,GAAGA,CAAC;EACnBC,QAAQ;EACRC,SAAS;EACTC,QAAQ;EACRC,QAAQ;EACRC,kBAAkB;EAClBC,OAAO;EACPC,WAAW;EACXC,UAAU;EACVC,OAAO;EACPC,cAAc;EACdC,EAAE;EACF,GAAGC;AACgC,CAAC,KAAgB;EACpD;AACF;AACA;AACA;AACA;EACE,IAAIT,QAAQ,IAAIC,QAAQ,IAAII,UAAU,IAChCG,EAAE,CAAYE,KAAK,CAAC,uBAAuB,CAAC,EAAE;IAClD,IAAIC,UAAkB,GAAGC,CAAC,CAACC,IAAI;IAC/B,IAAId,SAAS,EAAEY,UAAU,IAAI,IAAIZ,SAAS,EAAE;IAE5C,oBACEH,IAAA;MACEG,SAAS,EAAEY,UACX;MACA;MACA;MACA;MAAA;MACAG,IAAI,EAAEN,EAAa;MACnBL,OAAO,EAAEH,QAAQ,GAAIe,CAAC,IAAK;QACzBA,CAAC,CAACC,cAAc,CAAC,CAAC;MACpB,CAAC,GAAGb,OAAQ;MACZC,WAAW,EAAEJ,QAAQ,GAAIe,CAAC,IAAK;QAC7BA,CAAC,CAACC,cAAc,CAAC,CAAC;MACpB,CAAC,GAAGZ,WAAY;MAChBa,GAAG,EAAC,qBAAqB;MACzBC,SAAS,EAAC,MAAM;MAChBC,MAAM,EAAEd,UAAU,GAAG,QAAQ,GAAG,EAAG;MAAAP,QAAA,EAElCA;IAAQ,CACR,CAAC;EAER;EAEA,MAAMsB,CAAC,GAAGb,cAAc;EAExB,oBACEX,IAAA,CAACwB,CAAC;IACArB,SAAS,EAAEA,SAAU;IACrBsB,QAAQ,EAAC,MACT;IAAA;IACAlB,OAAO,EAAGY,CAAsC,IAAK;MACnD;MACA,IAAIZ,OAAO,EAAEA,OAAO,CAACY,CAAC,CAAC,CAEvB;MACA,IAAI,CAACb,kBAAkB,EAAEoB,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAE;IACFnB,WAAW,EAAEA,WAAY;IACzBE,OAAO,EAAEA,OAAQ;IACjBE,EAAE,EAAEA,EACJ;IACA;IAAA;IAAA,GACIC,IAAI;IAAAX,QAAA,EAEPA;EAAQ,CACR,CAAC;AAER,CAAC;AAED,eAAeD,WAAW","ignoreList":[]}