@dr.pogodin/react-utils 1.57.1 → 1.58.1

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 (138) hide show
  1. package/build/development/client/getInj.js +17 -2
  2. package/build/development/client/getInj.js.map +1 -1
  3. package/build/development/server/Cache.js +42 -10
  4. package/build/development/server/Cache.js.map +1 -1
  5. package/build/development/server/index.js +6 -3
  6. package/build/development/server/index.js.map +1 -1
  7. package/build/development/server/renderer.js +67 -10
  8. package/build/development/server/renderer.js.map +1 -1
  9. package/build/development/server/server.js +17 -9
  10. package/build/development/server/server.js.map +1 -1
  11. package/build/development/server/utils/errors.js +11 -11
  12. package/build/development/server/utils/errors.js.map +1 -1
  13. package/build/development/server/utils/modules.js +35 -1
  14. package/build/development/server/utils/modules.js.map +1 -1
  15. package/build/development/shared/components/Button/index.js +1 -1
  16. package/build/development/shared/components/Button/index.js.map +1 -1
  17. package/build/development/shared/components/Checkbox/index.js +5 -5
  18. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  19. package/build/development/shared/components/Input/index.js +3 -3
  20. package/build/development/shared/components/Input/index.js.map +1 -1
  21. package/build/development/shared/components/Modal/index.js +3 -0
  22. package/build/development/shared/components/Modal/index.js.map +1 -1
  23. package/build/development/shared/components/TextArea/index.js +3 -3
  24. package/build/development/shared/components/TextArea/index.js.map +1 -1
  25. package/build/development/shared/components/WithTooltip/Tooltip.js +2 -2
  26. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  27. package/build/development/shared/components/WithTooltip/index.js +3 -1
  28. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  29. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +8 -2
  30. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  31. package/build/development/shared/components/selectors/CustomDropdown/index.js +10 -4
  32. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  33. package/build/development/shared/components/selectors/NativeDropdown/index.js +7 -4
  34. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  35. package/build/development/shared/components/selectors/Switch/index.js +3 -3
  36. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  37. package/build/development/shared/utils/config.js.map +1 -1
  38. package/build/development/shared/utils/jest/E2eSsrEnv/index.js +11 -10
  39. package/build/development/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  40. package/build/development/shared/utils/jest/index.js +4 -3
  41. package/build/development/shared/utils/jest/index.js.map +1 -1
  42. package/build/development/shared/utils/splitComponent.js +86 -10
  43. package/build/development/shared/utils/splitComponent.js.map +1 -1
  44. package/build/development/shared/utils/webpack.js +5 -2
  45. package/build/development/shared/utils/webpack.js.map +1 -1
  46. package/build/production/client/getInj.js +1 -1
  47. package/build/production/client/getInj.js.map +1 -1
  48. package/build/production/server/Cache.js +4 -4
  49. package/build/production/server/Cache.js.map +1 -1
  50. package/build/production/server/index.js +1 -1
  51. package/build/production/server/index.js.map +1 -1
  52. package/build/production/server/renderer.js +12 -12
  53. package/build/production/server/renderer.js.map +1 -1
  54. package/build/production/server/server.js +7 -7
  55. package/build/production/server/server.js.map +1 -1
  56. package/build/production/server/utils/errors.js +2 -2
  57. package/build/production/server/utils/errors.js.map +1 -1
  58. package/build/production/server/utils/modules.js +1 -1
  59. package/build/production/server/utils/modules.js.map +1 -1
  60. package/build/production/shared/components/Button/index.js +1 -1
  61. package/build/production/shared/components/Button/index.js.map +1 -1
  62. package/build/production/shared/components/Checkbox/index.js +1 -1
  63. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  64. package/build/production/shared/components/Input/index.js +1 -1
  65. package/build/production/shared/components/Input/index.js.map +1 -1
  66. package/build/production/shared/components/Modal/index.js +1 -1
  67. package/build/production/shared/components/Modal/index.js.map +1 -1
  68. package/build/production/shared/components/TextArea/index.js +1 -1
  69. package/build/production/shared/components/TextArea/index.js.map +1 -1
  70. package/build/production/shared/components/WithTooltip/Tooltip.js +1 -1
  71. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  72. package/build/production/shared/components/WithTooltip/index.js +2 -2
  73. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  74. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  75. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  76. package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
  77. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  78. package/build/production/shared/components/selectors/NativeDropdown/index.js +3 -3
  79. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  80. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  81. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  82. package/build/production/shared/utils/config.js.map +1 -1
  83. package/build/production/shared/utils/jest/E2eSsrEnv/index.js +3 -3
  84. package/build/production/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  85. package/build/production/shared/utils/jest/index.js +4 -4
  86. package/build/production/shared/utils/jest/index.js.map +1 -1
  87. package/build/production/shared/utils/splitComponent.js +5 -5
  88. package/build/production/shared/utils/splitComponent.js.map +1 -1
  89. package/build/production/shared/utils/webpack.js +4 -3
  90. package/build/production/shared/utils/webpack.js.map +1 -1
  91. package/build/types-code/shared/utils/config.d.ts +1 -1
  92. package/build/web/client/getInj.js +1 -1
  93. package/build/web/client/getInj.js.map +1 -1
  94. package/build/web/server/Cache.js +4 -4
  95. package/build/web/server/Cache.js.map +1 -1
  96. package/build/web/server/index.js +1 -1
  97. package/build/web/server/index.js.map +1 -1
  98. package/build/web/server/renderer.js +12 -12
  99. package/build/web/server/renderer.js.map +1 -1
  100. package/build/web/server/server.js +7 -7
  101. package/build/web/server/server.js.map +1 -1
  102. package/build/web/server/utils/errors.js +2 -2
  103. package/build/web/server/utils/errors.js.map +1 -1
  104. package/build/web/server/utils/modules.js +1 -1
  105. package/build/web/server/utils/modules.js.map +1 -1
  106. package/build/web/shared/components/Button/index.js +1 -1
  107. package/build/web/shared/components/Button/index.js.map +1 -1
  108. package/build/web/shared/components/Checkbox/index.js +1 -1
  109. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  110. package/build/web/shared/components/Input/index.js +1 -1
  111. package/build/web/shared/components/Input/index.js.map +1 -1
  112. package/build/web/shared/components/Modal/index.js +1 -1
  113. package/build/web/shared/components/Modal/index.js.map +1 -1
  114. package/build/web/shared/components/TextArea/index.js +1 -1
  115. package/build/web/shared/components/TextArea/index.js.map +1 -1
  116. package/build/web/shared/components/WithTooltip/Tooltip.js +1 -1
  117. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  118. package/build/web/shared/components/WithTooltip/index.js +2 -2
  119. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  120. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  121. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  122. package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -1
  123. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  124. package/build/web/shared/components/selectors/NativeDropdown/index.js +3 -3
  125. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  126. package/build/web/shared/components/selectors/Switch/index.js +1 -1
  127. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  128. package/build/web/shared/utils/config.js.map +1 -1
  129. package/build/web/shared/utils/jest/E2eSsrEnv/index.js +3 -3
  130. package/build/web/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  131. package/build/web/shared/utils/jest/index.js +4 -4
  132. package/build/web/shared/utils/jest/index.js.map +1 -1
  133. package/build/web/shared/utils/splitComponent.js +5 -5
  134. package/build/web/shared/utils/splitComponent.js.map +1 -1
  135. package/build/web/shared/utils/webpack.js +4 -3
  136. package/build/web/shared/utils/webpack.js.map +1 -1
  137. package/config/babel/webpack.js +15 -1
  138. package/package.json +21 -21
@@ -1,6 +1,9 @@
1
- import _pushInstanceProperty from "core-js-pure/stable/instance/push.js"; /**
2
- * Creation of standard ExpressJS server for ReactJS apps.
3
- */
1
+ import "core-js/modules/es.iterator.filter.js";
2
+ import "core-js/modules/es.array.push.js";
3
+ import "core-js/modules/es.iterator.constructor.js";
4
+ import "core-js/modules/es.iterator.filter.js"; /**
5
+ * Creation of standard ExpressJS server for ReactJS apps.
6
+ */
4
7
  import { sep } from "node:path";
5
8
  import { pathToFileURL } from "node:url";
6
9
  import compression from "compression";
@@ -32,7 +35,7 @@ defaultCspSettings.directives["frame-src"] = ["'self'",
32
35
  "https://*.youtube.com"];
33
36
  {
34
37
  const directives = defaultCspSettings.directives["script-src"];
35
- if (directives) _pushInstanceProperty(directives).call(directives, "'unsafe-eval'");else defaultCspSettings.directives["script-src"] = ["'unsafe-eval'"];
38
+ if (directives) directives.push("'unsafe-eval'");else defaultCspSettings.directives["script-src"] = ["'unsafe-eval'"];
36
39
  } // No need for automatic re-writes via Content Security Policy settings:
37
40
  // the forefront Apache or Nginx server is supposed to take care of this
38
41
  // in production cloud deployments.
@@ -57,6 +60,7 @@ export function getDefaultCspSettings() {
57
60
  export default async function factory(webpackConfig, options) {
58
61
  const rendererOps = pick(options, ["Application", "beforeRender", "favicon", "logger", "maxSsrRounds", "noCsp", "ssrTimeout", "staticCacheController", "staticCacheSize"]);
59
62
  const renderer = rendererFactory(webpackConfig, rendererOps);
63
+ if (!webpackConfig.output) throw Error("Missing output config");
60
64
  const {
61
65
  publicPath
62
66
  } = webpackConfig.output;
@@ -69,6 +73,7 @@ export default async function factory(webpackConfig, options) {
69
73
  server.use((req, res, next) => {
70
74
  const schema = req.headers["x-forwarded-proto"];
71
75
  if (schema === "http") {
76
+ if (!req.headers.host) throw Error("Missing host name");
72
77
  let url = `https://${req.headers.host}`;
73
78
  if (req.originalUrl !== "/") url += req.originalUrl;
74
79
  res.redirect(url);
@@ -86,14 +91,13 @@ export default async function factory(webpackConfig, options) {
86
91
  }));
87
92
  if (!options.noCsp) {
88
93
  server.use((req, res, next) => {
89
- var _context;
90
94
  const req2 = req;
91
95
  req2.nonce = globalThis.crypto.randomUUID(); // TODO: This is deprecated, but it is kept for now for backward
92
96
  // compatibility. Should be removed sometime later.
93
97
  req2.cspNonce = req2.nonce; // The deep clone is necessary here to ensure that default value can't be
94
98
  // mutated during request processing.
95
99
  let cspSettings = cloneDeep(defaultCspSettings);
96
- _pushInstanceProperty(_context = cspSettings.directives?.["script-src"]).call(_context, `'nonce-${req2.nonce}'`);
100
+ (cspSettings.directives?.["script-src"]).push(`'nonce-${req2.nonce}'`);
97
101
  if (options.cspSettingsHook) {
98
102
  cspSettings = options.cspSettingsHook(cspSettings, req);
99
103
  }
@@ -119,6 +123,7 @@ export default async function factory(webpackConfig, options) {
119
123
  ignoreRequest: options.csrfIgnoreRequest
120
124
  }));
121
125
  loggerMiddleware.token("ip", req => req.clientIp);
126
+ if (!options.logger) throw Error("Missing logger");
122
127
  const FORMAT = ":ip > :status :method :url :response-time ms :res[content-length] :referrer :user-agent";
123
128
  server.use(loggerMiddleware(FORMAT, {
124
129
  stream: {
@@ -130,7 +135,7 @@ export default async function factory(webpackConfig, options) {
130
135
  // to be served from the root, to have all web app pages in its scope.
131
136
  // Thus, this setup to serve it. Probably, need some more configuration
132
137
  // for special cases, but this will do for now.
133
- server.get("/__service-worker.js", express.static(webpackConfig.output?.path ?? "", {
138
+ server.get("/__service-worker.js", express.static(webpackConfig.output.path ?? "", {
134
139
  setHeaders: res => res.set("Cache-Control", "no-cache")
135
140
  })); /* Setup of Hot Module Reloading for development environment.
136
141
  * These dependencies are not used, nor installed for production use,
@@ -160,7 +165,9 @@ export default async function factory(webpackConfig, options) {
160
165
  serverSideRender: true
161
166
  }));
162
167
  } /* eslint-enable import/no-extraneous-dependencies */
163
- server.use(publicPath, express.static(webpackConfig.output.path));
168
+ const outputPath = webpackConfig.output.path;
169
+ if (!outputPath) throw Error("Missing output path");
170
+ server.use(publicPath, express.static(outputPath));
164
171
  if (options.onExpressJsSetup) {
165
172
  await options.onExpressJsSetup(server);
166
173
  }
@@ -189,7 +196,8 @@ export default async function factory(webpackConfig, options) {
189
196
  return;
190
197
  }
191
198
  const status = error.status ?? CODES.INTERNAL_SERVER_ERROR; // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
192
- const serverSide = status >= CODES.INTERNAL_SERVER_ERROR; // Log server-side errors always, client-side at debug level only.
199
+ const serverSide = status >= CODES.INTERNAL_SERVER_ERROR;
200
+ if (!options.logger) throw Error("Missing logger"); // Log server-side errors always, client-side at debug level only.
193
201
  options.logger.log(serverSide ? "error" : "debug", error.stack ?? error.toString());
194
202
  let message = error.message || getErrorForCode(status);
195
203
  if (serverSide && process.env.NODE_ENV === "production") {
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","names":[],"sources":["../../../src/server/server.ts"],"sourcesContent":["/**\n * Creation of standard ExpressJS server for ReactJS apps.\n */\n\nimport { sep } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport compression from 'compression';\nimport cookieParser from 'cookie-parser';\n\nimport express, {\n type Express,\n type NextFunction,\n type Request,\n type Response,\n} from 'express';\n\nimport helmet, { type HelmetOptions } from 'helmet';\nimport { cloneDeep, mapValues, pick } from 'lodash-es';\nimport loggerMiddleware from 'morgan';\nimport requestIp from 'request-ip';\nimport favicon from 'serve-favicon';\n\nimport type { Configuration } from 'webpack';\n\nimport csrf from '@dr.pogodin/csurf';\n\nimport rendererFactory, {\n type LoggerI,\n type OptionsT as RendererOptionsT,\n} from './renderer';\n\nimport {\n CODES,\n ERRORS,\n getErrorForCode,\n newError,\n} from './utils/errors';\n\nexport type CspOptionsT = Exclude<HelmetOptions['contentSecurityPolicy'], boolean | undefined>;\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface RequestT extends Request {\n cspNonce: string;\n nonce: string;\n}\n\n/**\n * Default Content Security Policy settings.\n * @ignore\n */\nconst defaultCspSettings = {\n directives: mapValues(\n helmet.contentSecurityPolicy.getDefaultDirectives(),\n\n // 'https:' options (automatic re-write of insecure URLs to secure ones)\n // is removed to facilitate local development with HTTP server. In cloud\n // deployments we assume Apache or Nginx server in front of out app takes\n // care about such re-writes.\n (array) => (array as string[]).filter((item: string) => item !== 'https:'),\n ),\n};\ndefaultCspSettings.directives['frame-src'] = [\n \"'self'\",\n\n // YouTube domain is whitelisted to allow <YouTubeVideo> component to work\n // out of box.\n 'https://*.youtube.com',\n];\n\n{\n const directives = defaultCspSettings.directives['script-src'];\n if (directives) directives.push(\"'unsafe-eval'\");\n else defaultCspSettings.directives['script-src'] = [\"'unsafe-eval'\"];\n}\n\n// No need for automatic re-writes via Content Security Policy settings:\n// the forefront Apache or Nginx server is supposed to take care of this\n// in production cloud deployments.\ndelete defaultCspSettings.directives['upgrade-insecure-requests'];\n\n/**\n * @category Utilities\n * @func server/getDefaultCspSettings\n * @global\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { getDefaultCspSettings } from '@dr.pogodin/react-utils';\n * ```\n * @return {{\n * directives: object\n * }} A deep copy of default CSP settings object used by `react-utils`,\n * with the exception of `nonce-xxx` clause in `script-src` directive,\n * which is added dynamically for each request.\n */\nexport function getDefaultCspSettings(): {\n directives: Record<string, string[]>;\n} {\n return cloneDeep(defaultCspSettings);\n}\n\nexport type ServerT = Express & {\n logger: LoggerI;\n};\n\nexport type OptionsT = RendererOptionsT & {\n beforeExpressJsError?:\n (server: ServerT) => Promise<boolean> | boolean;\n\n beforeExpressJsSetup?: (server: ServerT) => Promise<void> | void;\n cookieSignatureSecret?: string;\n cspSettingsHook?: (\n defaultOptions: CspOptionsT,\n req: Request,\n ) => CspOptionsT;\n csrfIgnoreRequest?: (req: Request) => boolean;\n devMode?: boolean;\n httpsRedirect?: boolean;\n onExpressJsSetup?: (server: ServerT) => Promise<void> | void;\n};\n\nexport default async function factory(\n webpackConfig: Configuration,\n options: OptionsT,\n): Promise<ServerT> {\n const rendererOps: RendererOptionsT = pick(options, [\n 'Application',\n 'beforeRender',\n 'favicon',\n 'logger',\n 'maxSsrRounds',\n 'noCsp',\n 'ssrTimeout',\n 'staticCacheController',\n 'staticCacheSize',\n ]);\n const renderer = rendererFactory(webpackConfig, rendererOps);\n const { publicPath } = webpackConfig.output!;\n\n const server = express() as ServerT;\n\n if (options.beforeExpressJsSetup) {\n await options.beforeExpressJsSetup(server);\n }\n\n if (options.logger) server.logger = options.logger;\n\n if (options.httpsRedirect) {\n server.use((req, res, next) => {\n const schema = req.headers['x-forwarded-proto'];\n if (schema === 'http') {\n let url = `https://${req.headers.host}`;\n if (req.originalUrl !== '/') url += req.originalUrl;\n res.redirect(url);\n return;\n }\n next();\n });\n }\n\n server.use(compression());\n server.use(\n helmet({\n contentSecurityPolicy: false,\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n }),\n );\n\n if (!options.noCsp) {\n server.use(\n (req: Request, res: Response, next: NextFunction) => {\n const req2 = req as RequestT;\n\n req2.nonce = globalThis.crypto.randomUUID();\n\n // TODO: This is deprecated, but it is kept for now for backward\n // compatibility. Should be removed sometime later.\n req2.cspNonce = req2.nonce;\n\n // The deep clone is necessary here to ensure that default value can't be\n // mutated during request processing.\n let cspSettings: CspOptionsT = cloneDeep(defaultCspSettings);\n (cspSettings.directives?.['script-src'] as string[]).push(`'nonce-${req2.nonce}'`);\n if (options.cspSettingsHook) {\n cspSettings = options.cspSettingsHook(cspSettings, req);\n }\n helmet.contentSecurityPolicy(cspSettings)(req, res, next);\n },\n );\n }\n\n if (options.favicon) {\n server.use(favicon(options.favicon));\n }\n\n server.use('/robots.txt', (req, res) => {\n res.send('User-agent: *\\nDisallow:');\n });\n\n server.use(express.json({ limit: '300kb' }));\n server.use(express.urlencoded({ extended: false }));\n server.use(cookieParser(options.cookieSignatureSecret));\n server.use(requestIp.mw());\n\n server.use(csrf({\n cookie: true,\n ignoreRequest: options.csrfIgnoreRequest,\n }));\n\n loggerMiddleware.token(\n 'ip',\n (req: Request & { clientIp: string }) => req.clientIp,\n );\n const FORMAT = ':ip > :status :method :url :response-time ms :res[content-length] :referrer :user-agent';\n server.use(loggerMiddleware(FORMAT, {\n stream: {\n // TODO: This implies the logger is always set. Is it on a higher level?\n // then mark it as always present.\n write: options.logger!.info.bind(options.logger),\n },\n }));\n\n // Note: no matter the \"public path\", we want the service worker, if any,\n // to be served from the root, to have all web app pages in its scope.\n // Thus, this setup to serve it. Probably, need some more configuration\n // for special cases, but this will do for now.\n server.get('/__service-worker.js', express.static(\n webpackConfig.output?.path ?? '',\n {\n setHeaders: (res) => res.set('Cache-Control', 'no-cache'),\n },\n ));\n\n /* Setup of Hot Module Reloading for development environment.\n * These dependencies are not used, nor installed for production use,\n * hence we should violate some import-related lint rules. */\n /* eslint-disable import/no-extraneous-dependencies */\n if (options.devMode) {\n // This is a workaround for SASS bug:\n // https://github.com/dart-lang/sdk/issues/27979\n // which manifests itself sometimes when webpack dev middleware is used\n // (in dev mode), and app modules are imported in some unfortunate ways.\n // TODO: Double-check, what is going on here.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!global.location) {\n global.location = {\n href: `${pathToFileURL(process.cwd()).href}${sep}`,\n } as Location;\n }\n\n const { default: webpack } = await import(/* webpackChunkName: \"server-side-code\" */ 'webpack');\n\n const { default: webpackDevMiddleware } = await import(\n /* webpackChunkName: \"server-side-code\" */ 'webpack-dev-middleware'\n );\n\n const compiler = webpack(webpackConfig);\n\n server.use(webpackDevMiddleware(compiler, {\n hot: true,\n publicPath,\n serverSideRender: true,\n }));\n }\n /* eslint-enable import/no-extraneous-dependencies */\n\n server.use(publicPath as string, express.static(webpackConfig.output!.path!));\n\n if (options.onExpressJsSetup) {\n await options.onExpressJsSetup(server);\n }\n server.use(renderer);\n\n /* Detects 404 errors, and forwards them to the error handler. */\n server.use((req, res, next) => {\n next(newError(ERRORS.NOT_FOUND, CODES.NOT_FOUND));\n });\n\n let dontAttachDefaultErrorHandler;\n if (options.beforeExpressJsError) {\n dontAttachDefaultErrorHandler = await options.beforeExpressJsError(server);\n }\n\n /* Error handler. */\n if (!dontAttachDefaultErrorHandler) {\n // TODO: Do we need this error handler at all? It actually seems to do\n // what the default ExpressJS error handler does anyway, see:\n // https://expressjs.com/en/guide/error-handling.html\n //\n // TODO: It is better to move the default error handler definition\n // to a stand-alone function at top-level, but the use of options.logger\n // prevents to do it without some extra refactoring. Should be done sometime\n // though.\n server.use((\n error: Error & {\n status?: number;\n },\n req: Request,\n res: Response,\n next: NextFunction,\n ) => {\n // TODO: This is needed to correctly handled any errors thrown after\n // sending initial response to the client.\n if (res.headersSent) {\n next(error);\n return;\n }\n\n const status = error.status ?? CODES.INTERNAL_SERVER_ERROR;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n const serverSide = status >= CODES.INTERNAL_SERVER_ERROR;\n\n // Log server-side errors always, client-side at debug level only.\n options.logger!.log(\n serverSide ? 'error' : 'debug',\n error.stack ?? error.toString(),\n );\n\n let message = error.message || getErrorForCode(status);\n if (serverSide && process.env.NODE_ENV === 'production') {\n message = ERRORS.INTERNAL_SERVER_ERROR;\n }\n\n res.status(status).send(message);\n });\n }\n\n return server;\n}\n"],"mappings":"yEAAA;AACA;AACA;AAEA,SAAS,GAAG,QAAQ,WAAW;AAC/B,SAAS,aAAa,QAAQ,UAAU;AAExC,OAAO,WAAW,MAAM,aAAa;AACrC,OAAO,YAAY,MAAM,eAAe;AAExC,OAAO,OAAO,MAKP,SAAS;AAEhB,OAAO,MAAM,MAA8B,QAAQ;AACnD,SAAS,SAAS,EAAE,SAAS,EAAE,IAAI,QAAQ,WAAW;AACtD,OAAO,gBAAgB,MAAM,QAAQ;AACrC,OAAO,SAAS,MAAM,YAAY;AAClC,OAAO,OAAO,MAAM,eAAe;AAInC,OAAO,IAAI,MAAM,mBAAmB;AAAC,OAE9B,eAAe;AAAA,SAMpB,KAAK,EACL,MAAM,EACN,eAAe,EACf,QAAQ,4BAKV;AAMA;AACA;AACA;AACA;AACA,MAAM,kBAAkB,GAAG;EACzB,UAAU,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,IAAI,6BAA6B;EACjC,IAAI,OAAO,CAAC,oBAAoB,EAAE;IAChC,6BAA6B,GAAG,MAAM,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC;EAC5E,CAEA;EACA,IAAI,CAAC,6BAA6B,EAAE;IAClC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,MAAM,CAAC,GAAG,CAAC,CACT,KAEC,EACD,GAAY,EACZ,GAAa,EACb,IAAkB,KACf;MACH;MACA;MACA,IAAI,GAAG,CAAC,WAAW,EAAE;QACnB,IAAI,CAAC,KAAK,CAAC;QACX;MACF;MAEA,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAE1D;MACA,MAAM,UAAU,GAAG,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAExD;MACA,OAAO,CAAC,MAAM,CAAE,GAAG,CACjB,UAAU,GAAG,OAAO,GAAG,OAAO,EAC9B,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,CAChC,CAAC;MAED,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC;MACtD,IAAI,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACvD,OAAO,GAAG,MAAM,CAAC,qBAAqB;MACxC;MAEA,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IAClC,CAAC,CAAC;EACJ;EAEA,OAAO,MAAM;AACf","ignoreList":[]}
1
+ {"version":3,"file":"server.js","names":[],"sources":["../../../src/server/server.ts"],"sourcesContent":["/**\n * Creation of standard ExpressJS server for ReactJS apps.\n */\n\nimport { sep } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport compression from 'compression';\nimport cookieParser from 'cookie-parser';\n\nimport express, {\n type Express,\n type NextFunction,\n type Request,\n type Response,\n} from 'express';\n\nimport helmet, { type HelmetOptions } from 'helmet';\nimport { cloneDeep, mapValues, pick } from 'lodash-es';\nimport loggerMiddleware from 'morgan';\nimport requestIp from 'request-ip';\nimport favicon from 'serve-favicon';\n\nimport type { Configuration } from 'webpack';\n\nimport csrf from '@dr.pogodin/csurf';\n\nimport rendererFactory, {\n type LoggerI,\n type OptionsT as RendererOptionsT,\n} from './renderer';\n\nimport {\n CODES,\n ERRORS,\n getErrorForCode,\n newError,\n} from './utils/errors';\n\nexport type CspOptionsT = Exclude<HelmetOptions['contentSecurityPolicy'], boolean | undefined>;\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface RequestT extends Request {\n cspNonce: string;\n nonce: string;\n}\n\n/**\n * Default Content Security Policy settings.\n * @ignore\n */\nconst defaultCspSettings = {\n directives: mapValues(\n helmet.contentSecurityPolicy.getDefaultDirectives(),\n\n // 'https:' options (automatic re-write of insecure URLs to secure ones)\n // is removed to facilitate local development with HTTP server. In cloud\n // deployments we assume Apache or Nginx server in front of out app takes\n // care about such re-writes.\n (array) => (array as string[]).filter((item: string) => item !== 'https:'),\n ),\n};\ndefaultCspSettings.directives['frame-src'] = [\n \"'self'\",\n\n // YouTube domain is whitelisted to allow <YouTubeVideo> component to work\n // out of box.\n 'https://*.youtube.com',\n];\n\n{\n const directives = defaultCspSettings.directives['script-src'];\n if (directives) directives.push(\"'unsafe-eval'\");\n else defaultCspSettings.directives['script-src'] = [\"'unsafe-eval'\"];\n}\n\n// No need for automatic re-writes via Content Security Policy settings:\n// the forefront Apache or Nginx server is supposed to take care of this\n// in production cloud deployments.\ndelete defaultCspSettings.directives['upgrade-insecure-requests'];\n\n/**\n * @category Utilities\n * @func server/getDefaultCspSettings\n * @global\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils';\n * const { getDefaultCspSettings } from '@dr.pogodin/react-utils';\n * ```\n * @return {{\n * directives: object\n * }} A deep copy of default CSP settings object used by `react-utils`,\n * with the exception of `nonce-xxx` clause in `script-src` directive,\n * which is added dynamically for each request.\n */\nexport function getDefaultCspSettings(): {\n directives: Record<string, string[]>;\n} {\n return cloneDeep(defaultCspSettings);\n}\n\nexport type ServerT = Express & {\n logger: LoggerI;\n};\n\nexport type OptionsT = RendererOptionsT & {\n beforeExpressJsError?:\n (server: ServerT) => Promise<boolean> | boolean;\n\n beforeExpressJsSetup?: (server: ServerT) => Promise<void> | void;\n cookieSignatureSecret?: string;\n cspSettingsHook?: (\n defaultOptions: CspOptionsT,\n req: Request,\n ) => CspOptionsT;\n csrfIgnoreRequest?: (req: Request) => boolean;\n devMode?: boolean;\n httpsRedirect?: boolean;\n onExpressJsSetup?: (server: ServerT) => Promise<void> | void;\n};\n\nexport default async function factory(\n webpackConfig: Configuration,\n options: OptionsT,\n): Promise<ServerT> {\n const rendererOps: RendererOptionsT = pick(options, [\n 'Application',\n 'beforeRender',\n 'favicon',\n 'logger',\n 'maxSsrRounds',\n 'noCsp',\n 'ssrTimeout',\n 'staticCacheController',\n 'staticCacheSize',\n ]);\n const renderer = rendererFactory(webpackConfig, rendererOps);\n if (!webpackConfig.output) throw Error('Missing output config');\n const { publicPath } = webpackConfig.output;\n\n const server = express() as ServerT;\n\n if (options.beforeExpressJsSetup) {\n await options.beforeExpressJsSetup(server);\n }\n\n if (options.logger) server.logger = options.logger;\n\n if (options.httpsRedirect) {\n server.use((req, res, next) => {\n const schema = req.headers['x-forwarded-proto'];\n if (schema === 'http') {\n if (!req.headers.host) throw Error('Missing host name');\n let url = `https://${req.headers.host}`;\n if (req.originalUrl !== '/') url += req.originalUrl;\n res.redirect(url);\n return;\n }\n next();\n });\n }\n\n server.use(compression());\n server.use(\n helmet({\n contentSecurityPolicy: false,\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n }),\n );\n\n if (!options.noCsp) {\n server.use(\n (req: Request, res: Response, next: NextFunction) => {\n const req2 = req as RequestT;\n\n req2.nonce = globalThis.crypto.randomUUID();\n\n // TODO: This is deprecated, but it is kept for now for backward\n // compatibility. Should be removed sometime later.\n req2.cspNonce = req2.nonce;\n\n // The deep clone is necessary here to ensure that default value can't be\n // mutated during request processing.\n let cspSettings: CspOptionsT = cloneDeep(defaultCspSettings);\n (cspSettings.directives?.['script-src'] as string[]).push(`'nonce-${req2.nonce}'`);\n if (options.cspSettingsHook) {\n cspSettings = options.cspSettingsHook(cspSettings, req);\n }\n helmet.contentSecurityPolicy(cspSettings)(req, res, next);\n },\n );\n }\n\n if (options.favicon) {\n server.use(favicon(options.favicon));\n }\n\n server.use('/robots.txt', (req, res) => {\n res.send('User-agent: *\\nDisallow:');\n });\n\n server.use(express.json({ limit: '300kb' }));\n server.use(express.urlencoded({ extended: false }));\n server.use(cookieParser(options.cookieSignatureSecret));\n server.use(requestIp.mw());\n\n server.use(csrf({\n cookie: true,\n ignoreRequest: options.csrfIgnoreRequest,\n }));\n\n loggerMiddleware.token(\n 'ip',\n (req: Request & { clientIp: string }) => req.clientIp,\n );\n if (!options.logger) throw Error('Missing logger');\n const FORMAT = ':ip > :status :method :url :response-time ms :res[content-length] :referrer :user-agent';\n server.use(loggerMiddleware(FORMAT, {\n stream: {\n // TODO: This implies the logger is always set. Is it on a higher level?\n // then mark it as always present.\n write: options.logger.info.bind(options.logger),\n },\n }));\n\n // Note: no matter the \"public path\", we want the service worker, if any,\n // to be served from the root, to have all web app pages in its scope.\n // Thus, this setup to serve it. Probably, need some more configuration\n // for special cases, but this will do for now.\n server.get('/__service-worker.js', express.static(\n webpackConfig.output.path ?? '',\n {\n setHeaders: (res) => res.set('Cache-Control', 'no-cache'),\n },\n ));\n\n /* Setup of Hot Module Reloading for development environment.\n * These dependencies are not used, nor installed for production use,\n * hence we should violate some import-related lint rules. */\n /* eslint-disable import/no-extraneous-dependencies */\n if (options.devMode) {\n // This is a workaround for SASS bug:\n // https://github.com/dart-lang/sdk/issues/27979\n // which manifests itself sometimes when webpack dev middleware is used\n // (in dev mode), and app modules are imported in some unfortunate ways.\n // TODO: Double-check, what is going on here.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!global.location) {\n global.location = {\n href: `${pathToFileURL(process.cwd()).href}${sep}`,\n } as Location;\n }\n\n const { default: webpack } = await import(/* webpackChunkName: \"server-side-code\" */ 'webpack');\n\n const { default: webpackDevMiddleware } = await import(\n /* webpackChunkName: \"server-side-code\" */ 'webpack-dev-middleware'\n );\n\n const compiler = webpack(webpackConfig);\n\n server.use(webpackDevMiddleware(compiler, {\n hot: true,\n publicPath,\n serverSideRender: true,\n }));\n }\n /* eslint-enable import/no-extraneous-dependencies */\n\n const outputPath = webpackConfig.output.path;\n if (!outputPath) throw Error('Missing output path');\n server.use(publicPath as string, express.static(outputPath));\n\n if (options.onExpressJsSetup) {\n await options.onExpressJsSetup(server);\n }\n server.use(renderer);\n\n /* Detects 404 errors, and forwards them to the error handler. */\n server.use((req, res, next) => {\n next(newError(ERRORS.NOT_FOUND, CODES.NOT_FOUND));\n });\n\n let dontAttachDefaultErrorHandler;\n if (options.beforeExpressJsError) {\n dontAttachDefaultErrorHandler = await options.beforeExpressJsError(server);\n }\n\n /* Error handler. */\n if (!dontAttachDefaultErrorHandler) {\n // TODO: Do we need this error handler at all? It actually seems to do\n // what the default ExpressJS error handler does anyway, see:\n // https://expressjs.com/en/guide/error-handling.html\n //\n // TODO: It is better to move the default error handler definition\n // to a stand-alone function at top-level, but the use of options.logger\n // prevents to do it without some extra refactoring. Should be done sometime\n // though.\n server.use((\n error: Error & {\n status?: number;\n },\n req: Request,\n res: Response,\n next: NextFunction,\n ) => {\n // TODO: This is needed to correctly handled any errors thrown after\n // sending initial response to the client.\n if (res.headersSent) {\n next(error);\n return;\n }\n\n const status = error.status ?? CODES.INTERNAL_SERVER_ERROR;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n const serverSide = status >= CODES.INTERNAL_SERVER_ERROR;\n\n if (!options.logger) throw Error('Missing logger');\n // Log server-side errors always, client-side at debug level only.\n options.logger.log(\n serverSide ? 'error' : 'debug',\n error.stack ?? error.toString(),\n );\n\n let message = error.message || getErrorForCode(status);\n if (serverSide && process.env.NODE_ENV === 'production') {\n message = ERRORS.INTERNAL_SERVER_ERROR;\n }\n\n res.status(status).send(message);\n });\n }\n\n return server;\n}\n"],"mappings":";;;+CAAA;AACA;AACA;AAEA,SAAS,GAAG,QAAQ,WAAW;AAC/B,SAAS,aAAa,QAAQ,UAAU;AAExC,OAAO,WAAW,MAAM,aAAa;AACrC,OAAO,YAAY,MAAM,eAAe;AAExC,OAAO,OAAO,MAKP,SAAS;AAEhB,OAAO,MAAM,MAA8B,QAAQ;AACnD,SAAS,SAAS,EAAE,SAAS,EAAE,IAAI,QAAQ,WAAW;AACtD,OAAO,gBAAgB,MAAM,QAAQ;AACrC,OAAO,SAAS,MAAM,YAAY;AAClC,OAAO,OAAO,MAAM,eAAe;AAInC,OAAO,IAAI,MAAM,mBAAmB;AAAC,OAE9B,eAAe;AAAA,SAMpB,KAAK,EACL,MAAM,EACN,eAAe,EACf,QAAQ,4BAKV;AAMA;AACA;AACA;AACA;AACA,MAAM,kBAAkB,GAAG;EACzB,UAAU,EAAE,SAAS,CACnB,MAAM,CAAC,qBAAqB,CAAC,oBAAoB,CAAC,CAAC;EAEnD;EACA;EACA;EACA;EACC,KAAK,IAAM,KAAK,CAAc,MAAM,CAAE,IAAY,IAAK,IAAI,KAAK,QAAQ,CAC3E;AACF,CAAC;AACD,kBAAkB,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,CAC3C,QAAQ;AAER;AACA;AACA,uBAAuB,CACxB;AAED;EACE,MAAM,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,YAAY,CAAC;EAC9D,IAAI,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,KAC5C,kBAAkB,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,eAAe,CAAC;AACtE,CAEA;AACA;AACA;AACA,OAAO,kBAAkB,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAEjE;AAC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AG,CAAC,CACT,KAEC,EACD,GAAY,EACZ,GAAa,EACb,IAAkB,KACf;MACH;MACA;MACA,IAAI,GAAG,CAAC,WAAW,EAAE;QACnB,IAAI,CAAC,KAAK,CAAC;QACX;MACF;MAEA,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAE1D;MACA,MAAM,UAAU,GAAG,MAAM,IAAI,KAAK,CAAC,qBAAqB;MAExD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,gBAAgB,CAAC,CAClD;MACA,OAAO,CAAC,MAAM,CAAC,GAAG,CAChB,UAAU,GAAG,OAAO,GAAG,OAAO,EAC9B,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,CAChC,CAAC;MAED,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC;MACtD,IAAI,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACvD,OAAO,GAAG,MAAM,CAAC,qBAAqB;MACxC;MAEA,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IAClC,CAAC,CAAC;EACJ;EAEA,OAAO,MAAM;AACf","ignoreList":[]}
@@ -1,13 +1,13 @@
1
- import _JSON$stringify from "core-js-pure/stable/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
- */
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
11
  import { StatusCodes as CODES, ReasonPhrases as ERRORS, getReasonPhrase as getErrorForCode } from "http-status-codes"; /**
12
12
  * @static
13
13
  * @const CODES
@@ -80,7 +80,7 @@ export async function assert(value, schema, message = "", statusCode = CODES.BAD
80
80
  let result = schema["~standard"].validate(value);
81
81
  if (result instanceof Promise) result = await result;
82
82
  if (result.issues) {
83
- let error = _JSON$stringify(result.issues, null, 2);
83
+ let error = JSON.stringify(result.issues, null, 2);
84
84
  if (message) error = `${message}\n\n${error}`;
85
85
  throw fail(error, statusCode);
86
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"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":"oEAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SACE,WAAW,IAAI,KAAK,EACpB,aAAa,IAAI,MAAM,EACvB,eAAe,IAAI,eAAe,QAC7B,mBAAmB,CAI1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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List":[]}
1
+ {"version":3,"file":"errors.js","names":[],"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,SACE,WAAW,IAAI,KAAK,EACpB,aAAa,IAAI,MAAM,EACvB,eAAe,IAAI,eAAe,QAC7B,mBAAmB,CAI1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,KAAK,GAEd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,MAAM,GAEf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,GAExB;AACA,MAAM,eAAe,SAAS,KAAM;EAClC,MAAM,GAAW,KAAK,CAAC,qBAAqB;AAC9C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,QAAQ,CACtB,OAAe,EACf,UAAU,GAAG,KAAK,CAAC,qBAAqB,EACvB;EACjB,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC;EAC1C,KAAK,CAAC,MAAM,GAAG,UAAU;EACzB,OAAO,KAAK;AACd,CAEA;AACA;AACA;AACA,OAAO,SAAS,IAAI,CAClB,OAAe,EACf,UAAiB,GAAG,KAAK,CAAC,qBAAqB,EACxC;EACP,MAAM,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;AACrC,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAe,MAAM,CAC1B,KAAc,EACd,MAAS,EACT,OAAO,GAAG,EAAE,EACZ,UAAU,GAAG,KAAK,CAAC,WAAW,EACY;EAC1C,IAAI,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;EAChD,IAAI,MAAM,YAAY,OAAO,EAAE,MAAM,GAAG,MAAM,MAAM;EAEpD,IAAI,MAAM,CAAC,MAAM,EAAE;IACjB,IAAI,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,IAAI,OAAO,EAAE,KAAK,GAAG,GAAG,OAAO,OAAO,KAAK,EAAE;IAC7C,MAAM,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC;EAC/B;EAEA,OAAO,MAAM,CAAC,KAAK;AACrB","ignoreList":[]}
@@ -1,4 +1,38 @@
1
- // TODO: It makes sense to move these to more generic JS Utils,
1
+ import "core-js/modules/es.map.get-or-insert.js";
2
+ import "core-js/modules/es.map.get-or-insert-computed.js";
3
+ import "core-js/modules/esnext.map.delete-all.js";
4
+ import "core-js/modules/esnext.map.emplace.js";
5
+ import "core-js/modules/esnext.map.every.js";
6
+ import "core-js/modules/esnext.map.filter.js";
7
+ import "core-js/modules/esnext.map.find.js";
8
+ import "core-js/modules/esnext.map.find-key.js";
9
+ import "core-js/modules/esnext.map.includes.js";
10
+ import "core-js/modules/esnext.map.key-of.js";
11
+ import "core-js/modules/esnext.map.map-keys.js";
12
+ import "core-js/modules/esnext.map.map-values.js";
13
+ import "core-js/modules/esnext.map.merge.js";
14
+ import "core-js/modules/esnext.map.reduce.js";
15
+ import "core-js/modules/esnext.map.some.js";
16
+ import "core-js/modules/esnext.map.update.js";
17
+ import "core-js/modules/es.map.get-or-insert.js";
18
+ import "core-js/modules/es.map.get-or-insert-computed.js";
19
+ import "core-js/modules/esnext.map.delete-all.js";
20
+ import "core-js/modules/esnext.map.emplace.js";
21
+ import "core-js/modules/esnext.map.every.js";
22
+ import "core-js/modules/esnext.map.filter.js";
23
+ import "core-js/modules/esnext.map.find.js";
24
+ import "core-js/modules/esnext.map.find-key.js";
25
+ import "core-js/modules/esnext.map.includes.js";
26
+ import "core-js/modules/esnext.map.key-of.js";
27
+ import "core-js/modules/esnext.map.map-keys.js";
28
+ import "core-js/modules/esnext.map.map-values.js";
29
+ import "core-js/modules/esnext.map.merge.js";
30
+ import "core-js/modules/esnext.map.reduce.js";
31
+ import "core-js/modules/esnext.map.some.js";
32
+ import "core-js/modules/esnext.map.update.js";
33
+ import "core-js/modules/web.url-search-params.delete.js";
34
+ import "core-js/modules/web.url-search-params.has.js";
35
+ import "core-js/modules/web.url-search-params.size.js"; // TODO: It makes sense to move these to more generic JS Utils,
2
36
  // but it will probably require some rework of exports there, as these
3
37
  // are strictly for NodeJS environment, while current JS Utils are
4
38
  // generic JavaScript, environment-agnostic... thus, for now let's
@@ -1 +1 @@
1
- {"version":3,"file":"modules.js","names":[],"sources":["../../../../src/server/utils/modules.ts"],"sourcesContent":["// TODO: It makes sense to move these to more generic JS Utils,\n// but it will probably require some rework of exports there, as these\n// are strictly for NodeJS environment, while current JS Utils are\n// generic JavaScript, environment-agnostic... thus, for now let's\n// keep it here, until we really need these outside a React app.\n\nimport { existsSync, readFileSync, statSync } from 'node:fs';\nimport { type LoadFnOutput, createRequire, registerHooks } from 'node:module';\nimport { basename, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type * as BabelCore from '@babel/core';\n\nconst require = createRequire(import.meta.url);\n\ntype RegisterBabelLoaderArgT = {\n envName?: string;\n root?: string;\n};\n\n/**\n * It looks like, as of Babel v8, @babel/node does not quite work with ES module\n * codebase. This function registers a Node module API hook that customizes ES\n * module loading, to run Babel transformation on them.\n *{(\n * BEWARE: It is intended for development environments only.\n */\nexport function registerBabelLoader({\n envName = 'development',\n root = process.cwd(),\n}: RegisterBabelLoaderArgT = {}): void {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { transformSync } = require('@babel/core') as typeof BabelCore;\n\n const cache = new Map<string, LoadFnOutput>();\n\n registerHooks({\n load(url, context, next) {\n const cached = cache.get(url);\n if (cached !== undefined) return cached;\n\n if (\n url.startsWith('file://')\n && !url.includes('/node_modules/')\n && !url.includes('/config/babel/')\n && url.match(/.(js|jsx|svg|ts|tsx)$/)\n ) {\n const path = fileURLToPath(url);\n const source = readFileSync(path, 'utf8');\n\n const transformed = transformSync(source, {\n cwd: dirname(path),\n envName,\n filename: basename(path),\n root,\n });\n\n const res: LoadFnOutput = {\n format: 'module',\n shortCircuit: true,\n source: transformed?.code ?? '',\n };\n\n cache.set(url, res);\n return res;\n }\n\n return next(url, context);\n },\n });\n}\n\nconst CANDIDATE_EXTENSIONS = [\n '.js',\n '.jsx',\n '.ts',\n '.tsx',\n];\n\nfunction resolveExtension(base: string): null | string {\n for (const ext of CANDIDATE_EXTENSIONS) {\n const path = base + ext;\n if (existsSync(path)) return path;\n }\n\n return null;\n}\n\n/**\n * Registers a Node module API hook that customizes ES module resolution\n * to make mandatory file extensions optional.\n */\nexport function registerResolver(): void {\n registerHooks({\n resolve(specifier, context, next) {\n let path = specifier;\n\n const isAbsolute = path.startsWith('/');\n const isRelative = path.startsWith('.');\n\n if (isAbsolute || isRelative) {\n if (isRelative) path = new URL(path, context.parentURL).pathname;\n const stat = statSync(path, { throwIfNoEntry: false });\n if (!stat?.isFile()) {\n path = resolveExtension(path)\n ?? (stat?.isDirectory() ? resolveExtension(`${path}/index`) : null)\n ?? specifier;\n }\n }\n\n return next(path, context);\n },\n });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAAS,UAAU,EAAE,YAAY,EAAE,QAAQ,QAAQ,SAAS;AAC5D,SAA4B,aAAa,EAAE,aAAa,QAAQ,aAAa;AAC7E,SAAS,QAAQ,EAAE,OAAO,QAAQ,WAAW;AAC7C,SAAS,aAAa,QAAQ,UAAU;AAIxC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAO9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,mBAAmB,CAAC;EAClC,OAAO,GAAG,aAAa;EACvB,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;AACI,CAAC,GAAG,CAAC,CAAC,EAAQ;EACrC;EACA,MAAM;IAAE;EAAc,CAAC,GAAG,OAAO,CAAC,aAAa,CAAqB;EAEpE,MAAM,KAAK,GAAG,IAAI,GAA2B,CAA3B,CAA2B;EAE7C,aAAa,CAAC;IACZ,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE;MACvB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;MAC7B,IAAI,MAAM,KAAK,SAAS,EAAE,OAAO,MAAM;MAEvC,IACE,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,IACtB,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAC/B,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAC/B,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,EACrC;QACA,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC;QAC/B,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,M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AE;QAAM,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,EAAE;UACnB,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,KACvB,IAAI,EAAE,WAAW,CAAC,CAAC,GAAG,gBAAgB,CAAC,GAAG,IAAI,QAAQ,CAAC,GAAG,IAAI,CAAC,IAChE,SAAS;QAChB;MACF;MAEA,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;IAC5B;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"modules.js","names":[],"sources":["../../../../src/server/utils/modules.ts"],"sourcesContent":["// TODO: It makes sense to move these to more generic JS Utils,\n// but it will probably require some rework of exports there, as these\n// are strictly for NodeJS environment, while current JS Utils are\n// generic JavaScript, environment-agnostic... thus, for now let's\n// keep it here, until we really need these outside a React app.\n\nimport { existsSync, readFileSync, statSync } from 'node:fs';\nimport { type LoadFnOutput, createRequire, registerHooks } from 'node:module';\nimport { basename, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type * as BabelCore from '@babel/core';\n\nconst require = createRequire(import.meta.url);\n\ntype RegisterBabelLoaderArgT = {\n envName?: string;\n root?: string;\n};\n\n/**\n * It looks like, as of Babel v8, @babel/node does not quite work with ES module\n * codebase. This function registers a Node module API hook that customizes ES\n * module loading, to run Babel transformation on them.\n *{(\n * BEWARE: It is intended for development environments only.\n */\nexport function registerBabelLoader({\n envName = 'development',\n root = process.cwd(),\n}: RegisterBabelLoaderArgT = {}): void {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { transformSync } = require('@babel/core') as typeof BabelCore;\n\n const cache = new Map<string, LoadFnOutput>();\n\n registerHooks({\n load(url, context, next) {\n const cached = cache.get(url);\n if (cached !== undefined) return cached;\n\n if (\n url.startsWith('file://')\n && !url.includes('/node_modules/')\n && !url.includes('/config/babel/')\n && url.match(/.(js|jsx|svg|ts|tsx)$/)\n ) {\n const path = fileURLToPath(url);\n const source = readFileSync(path, 'utf8');\n\n const transformed = transformSync(source, {\n cwd: dirname(path),\n envName,\n filename: basename(path),\n root,\n });\n\n const res: LoadFnOutput = {\n format: 'module',\n shortCircuit: true,\n source: transformed?.code ?? '',\n };\n\n cache.set(url, res);\n return res;\n }\n\n return next(url, context);\n },\n });\n}\n\nconst CANDIDATE_EXTENSIONS = [\n '.js',\n '.jsx',\n '.ts',\n '.tsx',\n];\n\nfunction resolveExtension(base: string): null | string {\n for (const ext of CANDIDATE_EXTENSIONS) {\n const path = base + ext;\n if (existsSync(path)) return path;\n }\n\n return null;\n}\n\n/**\n * Registers a Node module API hook that customizes ES module resolution\n * to make mandatory file extensions optional.\n */\nexport function registerResolver(): void {\n registerHooks({\n resolve(specifier, context, next) {\n let path = specifier;\n\n const isAbsolute = path.startsWith('/');\n const isRelative = path.startsWith('.');\n\n if (isAbsolute || isRelative) {\n if (isRelative) path = new URL(path, context.parentURL).pathname;\n const stat = statSync(path, { throwIfNoEntry: false });\n if (!stat?.isFile()) {\n path = resolveExtension(path)\n ?? (stat?.isDirectory() ? resolveExtension(`${path}/index`) : null)\n ?? specifier;\n }\n }\n\n return next(path, context);\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uDAAA;AACA;AACA;AACA;AACA;AAEA,SAAS,UAAU,EAAE,YAAY,EAAE,QAAQ,QAAQ,SAAS;AAC5D,SAA4B,aAAa,EAAE,aAAa,QAAQ,aAAa;AAC7E,SAAS,QAAQ,EAAE,OAAO,QAAQ,WAAW;AAC7C,SAAS,aAAa,QAAQ,UAAU;AAIxC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAO9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,mBAAmB,CAAC;EAClC,OAAO,GAAG,aAAa;EACvB,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;AACI,CAAC,GAAG,CAAC,CAAC,EAAQ;EACrC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AAM,IAAI,GAAG,IAAI,GAAG,GAAG;IACvB,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,IAAI;EACnC;EAEA,OAAO,IAAI;AACb,CAEA;AACA;AACA;AACA;AACA,OAAO,SAAS,gBAAgB,GAAS;EACvC,aAAa,CAAC;IACZ,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;MAChC,IAAI,IAAI,GAAG,SAAS;MAEpB,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;MACvC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;MAEvC,IAAI,UAAU,IAAI,UAAU,EAAE;QAC5B,IAAI,UAAU,EAAE,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ;QAChE,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE;UAAE,cAAc,EAAE;QAAM,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,EAAE;UACnB,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,KACvB,IAAI,EAAE,WAAW,CAAC,CAAC,GAAG,gBAAgB,CAAC,GAAG,IAAI,QAAQ,CAAC,GAAG,IAAI,CAAC,IAChE,SAAS;QAChB;MACF;MAEA,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;IAC5B;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -31,7 +31,7 @@ export const BaseButton = t0 => {
31
31
  theme,
32
32
  to
33
33
  } = t0;
34
- let className = theme.button;
34
+ let className = theme.button ?? "";
35
35
  if (active && theme.active) {
36
36
  className = className + ` ${theme.active}`;
37
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"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":"iDAAA;AAUA,SAAqB,QAAQ,QAAQ,0BAA0B;AAAC,OAEzD,IAAI;AAEX;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AA0BxC,OAAO,MAAM,UAAqC,GAAG;EAAA;EAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAkBrD;EACC,gBAAgB,KAAK,OAAO;EAC5B,IAAI,MAAsB,IAAZ,KAAK,OAAO;IAAE,qBAAS,GAAI,IAAI,KAAK,OAAO,EAAE;EAAA;EAC3D,IAAI,QAAQ;IACV,IAAI,KAAK,SAAS;MAAE,qBAAS,GAAI,IAAI,KAAK,SAAS,EAAE;IAAA;IAIpC,kBAAO,IAAI,SAA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T,SAAS;MACL,aAAa,EAAb,aAAa;MACf,WAAW,EAAX,WAAW;MACnB,IAAQ,EAAR,QAAQ;MACH,QAAC,EAAD,CAAC;MAAA,UAEV;IAAQ,CACN,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAdN,EAcM;AAAA,CAET;AAED,MAAM,MAEL,GAAG;EAAA;EAAA;EAAA;EAAA;IAAC;MAAA;MAAA;IAAA,MAAkB;IAAA;IAAA;IAAA;EAAA;IAAA;IAAA;EAAA;EACrB,iBAAiB,QAAQ,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC;EAAC;EAAA;IAGlD,uBAAC,UAAU;MAAA,GAAK,IAAI;MAAS,KAAQ,EAAR;IAAQ,CAAG,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAAzC,EAAyC;AAAA,CACjD;AAED,eAAe,MAAM","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"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":"iDAAA;AAUA,SAAqB,QAAQ,QAAQ,0BAA0B;AAAC,OAEzD,IAAI;AAEX;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AA0BxC,OAAO,MAAM,UAAqC,GAAG;EAAA;EAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAkBrD;EACC,gBAAgB,KAAK,OAAa,IAAlB,EAAkB;EAClC,IAAI,MAAsB,IAAZ,KAAK,OAAO;IAAE,qBAAS,GAAI,IAAI,KAAK,OAAO,EAAE;EAAA;EAC3D,IAAI,QAAQ;IACV,IAAI,KAAK,SAAS;MAAE,qBAAS,GAAI,IAAI,KAAK,SAAS,EAAE;IAAA;IAIpC,kBAAO,IAAI,SAAS,KAAK,YAAiC,GAA1D,SAA0D,GAA1D,MAA0D;IAAA;IAAA;MAFzE;QACa,SAAS,EAAT,SAAS;QACP,iBAA0D;QAAA,UAEtE;MAAQ,CACN,CAAC;MAAA;MAAA;MAAA;MAAA;IAAA;MAAA;IAAA;IAAA,OALN,EAKM;EAAA;EAIV,gBAAgB,aAAa;EAC7B,IAAI,CAAC,SAAoB,IAArB,OAAqB;IAAA;IAAA;MACX;QACV,IAAI,CAAC,IAAI,KAAK,OAAO;UAAE,OAAO,CAAC,CAAC,CAAC;QAAA;MAAC,CACnC;MAAA;MAAA;IAAA;MAAA;IAAA;IAFD,YAAY,EAEX;EAFQ;EAKX,IAAI,EAAE;IAIa,kBAAO,IAAI,SAAS,KAAK,YAAi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AAA,GAAK,IAAI;MAAS,KAAQ,EAAR;IAAQ,CAAG,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAAzC,EAAyC;AAAA,CACjD;AAED,eAAe,MAAM","ignoreList":[]}
@@ -25,16 +25,16 @@ const Checkbox = t0 => {
25
25
  theme
26
26
  } = t0;
27
27
  const composed = useTheme("Checkbox", defaultTheme, theme);
28
- let containerClassName = composed.container;
28
+ let containerClassName = composed.container ?? "";
29
29
  if (disabled) {
30
- containerClassName = containerClassName + ` ${composed.disabled}`;
30
+ containerClassName = containerClassName + ` ${composed.disabled ?? ""}`;
31
31
  }
32
- let checkboxClassName = composed.checkbox;
32
+ let checkboxClassName = composed.checkbox ?? "";
33
33
  if (checked === "indeterminate") {
34
- checkboxClassName = checkboxClassName + ` ${composed.indeterminate}`;
34
+ checkboxClassName = checkboxClassName + ` ${composed.indeterminate ?? ""}`;
35
35
  }
36
36
  if (error) {
37
- containerClassName = containerClassName + ` ${composed.error}`;
37
+ containerClassName = containerClassName + ` ${composed.error ?? ""}`;
38
38
  }
39
39
  let t1;
40
40
  if ($[0] !== composed.label || $[1] !== label) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"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,SAAqB,QAAQ,QAAQ,0BAA0B;AAE/D;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AAoBxC,MAAM,QAAQ,GAAG;EAAA;EAAqD;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAQtD;EACd,iBAAiB,QAAQ,CAAC,UAAU,EAAE,YAAY,EAAE,KAAK,CAAC;EAE1D,yBAAyB,QAAQ,UAAU;EAC3C,IAAI,QAAQ;IAAE,uCAAkB,GAAI,IAAI,QAAQ,SAAS,EAAE;EAAA;EAE3D,wBAAwB,QAAQ,SAAS;EACzC,IAAI,OAAO,KAAK,eAAe;IAAE,qCAAiB,GAAI,IAAI,QAAQ,cAAc,EAAE;EAAA;EAElF,IAAI,KAAK;IAAE,uCAAkB,GAAI,IAAI,QAAQ,MAAM,EAAE;EAAA;EAAC;EAAA;IAIhD,UAAK,KAAK,SAC4C,GADtD,IACsD,gBADtD;MACyB,SAAc,EAAd,QAAQ,MAAM;MAAA,UAAG;IAAK,CAAM,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAE7C,kBAAO,KAAK,SAAwC,GAApD,SAAoD,GAAhB,OAAO,KAAK,IAAI;EAEhD,kBAAO,IAAI,SAAS,KAAK,YAAiC,GAA1D,SAA0D,GAA1D,MAA0D;EAAA;EAAA;IAHzE;MACW,OAAoD,EAApD,EAAoD;MAClD,SAAiB,EAAjB,iBAAiB;MACf,iBAA0D;MAC7D,QAAQ,EAAR,QAAQ;MACR,QAAQ,EAAR,QAAQ;MACT,OAER,EAFQ,KAER;MACI,IAAU,EAAV;IAAU,CAChB,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IACD,UAAuB,IAAd,KAAK,KAAK,IAEZ,gBAFP;MACmB,SAAqB,EAArB,QAAQ,aAAa;MAAA,UAAG;IAAK,CAC1C,CAAC,GAFP,IAEO;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAhBV;MAAgB,SAAkB,EAAlB,kBAAkB;MAAA,WAC9B,EACsD,EACxD,EAUE,EACD,EAEO;IAAA,CACL,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAjBN,EAiBM;AAAA,CAET;AAED,eAAe,QAAQ;AAzCN;EA8BP,CAAC,gBAAgB,CAAC,CAAC;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"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,SAAqB,QAAQ,QAAQ,0BAA0B;AAE/D;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AAoBxC,MAAM,QAAQ,GAAG;EAAA;EAAqD;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAQtD;EACd,iBAAiB,QAAQ,CAAC,UAAU,EAAE,YAAY,EAAE,KAAK,CAAC;EAE1D,yBAAyB,QAAQ,UAAgB,IAAxB,EAAwB;EACjD,IAAI,QAAQ;IAAE,uCAAkB,GAAI,IAAI,QAAQ,SAAe,IAAvB,EAAuB,EAAE;EAAA;EAEjE,wBAAwB,QAAQ,SAAe,IAAvB,EAAuB;EAC/C,IAAI,OAAO,KAAK,eAAe;IAAE,qCAAiB,GAAI,IAAI,QAAQ,cAAoB,IAA5B,EAA4B,EAAE;EAAA;EAExF,IAAI,KAAK;IAAE,uCAAkB,GAAI,IAAI,QAAQ,MAAY,IAApB,EAAoB,EAAE;EAAA;EAAC;EAAA;IAItD,UAAK,KAAK,SAC4C,GADtD,IACsD,gBADtD;MACyB,SAAc,EAAd,QAAQ,MAAM;MAAA,UAAG;IAAK,CAAM,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAE7C,kBAAO,KAAK,SAAwC,GAApD,SAAoD,GAAhB,OAAO,KAAK,IAAI;EAEhD,kBAAO,IAAI,SAAS,KAAK,YAAiC,GAA1D,SAA0D,GAA1D,MAA0D;EAAA;EAAA;IAHzE;MACW,OAAoD,EAApD,EAAoD;MAClD,SAAiB,EAAjB,iBAAiB;MACf,iBAA0D;MAC7D,QAAQ,EAAR,QAAQ;MACR,QAAQ,EAAR,QAAQ;MACT,OAER,EAFQ,KAER;MACI,IAAU,EAAV;IAAU,CAChB,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IACD,UAAuB,IAAd,KAAK,KAAK,IAEZ,gBAFP;MACmB,SAAqB,EAArB,QAAQ,aAAa;MAAA,UAAG;IAAK,CAC1C,CAAC,GAFP,IAEO;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAhBV;MAAgB,SAAkB,EAAlB,kBAAkB;MAAA,WAC9B,EACsD,EACxD,EAUE,EACD,EAEO;IAAA,CACL,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAjBN,EAiBM;AAAA,CAET;AAED,eAAe,QAAQ;AAzCN;EA8BP,CAAC,gBAAgB,CAAC,CAAC;AAAA","ignoreList":[]}
@@ -73,15 +73,15 @@ const Input = t0 => {
73
73
  const composed = useTheme("Input", defaultTheme, theme, t1);
74
74
  const [focused, setFocused] = useState(false);
75
75
  const localRef = useRef(null);
76
- let containerClassName = composed.container;
76
+ let containerClassName = composed.container ?? "";
77
77
  if (focused) {
78
- containerClassName = containerClassName + ` ${composed.focused}`;
78
+ containerClassName = containerClassName + ` ${composed.focused ?? ""}`;
79
79
  }
80
80
  if (!rest.value && composed.empty) {
81
81
  containerClassName = containerClassName + ` ${composed.empty}`;
82
82
  }
83
83
  if (error) {
84
- containerClassName = containerClassName + ` ${composed.error}`;
84
+ containerClassName = containerClassName + ` ${composed.error ?? ""}`;
85
85
  }
86
86
  let t2;
87
87
  if ($[11] !== ref) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Input/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type Ref,\n useRef,\n useState,\n} from 'react';\n\nimport { type COMPOSE, type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeKeyT = 'children' | 'container' | 'empty' | 'error' | 'errorMessage'\n | 'focused' | 'input' | 'label';\n\ntype PropsT = React.InputHTMLAttributes<HTMLInputElement> & {\n children?: ReactNode;\n composeAdhocTheme?: COMPOSE;\n error?: ReactNode;\n label?: React.ReactNode;\n ref?: Ref<HTMLInputElement>;\n testId?: string;\n theme?: Theme<ThemeKeyT>;\n};\n\n/**\n * Themeable input field, based on the standard HTML `<input>` element.\n * @param [props.label] Input label.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props...] [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n * @param [props...] Any other properties are passed to the underlying\n * `<input>` element.\n */\nconst Input: FunctionComponent<PropsT> = ({\n children,\n composeAdhocTheme,\n error,\n label,\n ref,\n testId,\n theme,\n ...rest\n}) => {\n const composed = useTheme('Input', defaultTheme, theme, {\n composeAdhocTheme,\n });\n\n // NOTE: As of now, it is only updated when \"theme.focused\" is defined,\n // as otherwise its value is not used.\n const [focused, setFocused] = useState(false);\n\n const localRef = useRef<HTMLInputElement>(null);\n\n let containerClassName = composed.container;\n\n // NOTE: As of now, \"focused\" can be true only when \"theme.focused\"\n // is provided.\n if (focused /* && theme.focused */) containerClassName += ` ${composed.focused}`;\n\n if (!rest.value && composed.empty) containerClassName += ` ${composed.empty}`;\n\n if (error) containerClassName += ` ${composed.error}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n // TODO: It does not really work if a callback-style `ref` is passed in,\n // we need a more complex logic to cover that case, but for now this serves\n // the case we need it for.\n if (typeof ref === 'object') ref?.current?.focus();\n else localRef.current?.focus();\n }}\n >\n {label === undefined\n ? null : <div className={composed.label}>{label}</div>}\n <input\n className={composed.input}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n ref={ref ?? localRef}\n\n // TODO: Avoid the spreading later.\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest}\n\n onBlur={composed.focused ? (e) => {\n setFocused(false);\n rest.onBlur?.(e);\n } : rest.onBlur}\n onFocus={composed.focused ? (e) => {\n setFocused(true);\n rest.onFocus?.(e);\n } : rest.onFocus}\n />\n {error && error !== true\n ? <div className={composed.errorMessage}>{error}</div>\n : null}\n {children ? <div className={composed.children}>{children}</div> : null}\n </div>\n );\n};\n\nexport default Input;\n"],"mappings":";AAAA,SAIE,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAmC,QAAQ,QAAQ,0BAA0B;AAE7E;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC,+DAexC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,KAAgC,GAAG;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;IAAC;MAAA;MAAA;MAAA;MAAA;MAAA;MAAA;MAAA;MAAA;IAAA,MASzC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;EAAA;IACyD;MAAA;IAExD,CAAC;IAAA;IAAA;EAAA;IAAA;EAAA;EAFD,iBAAiB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,EAEvD,CAAC;EAIF,8BAA8B,QAAQ,CAAC,KAAK,CAAC;EAE7C,iBAAiB,MAAM,CAAmB,IAAI,CAAC;EAE/C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;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IACD,UAAuB,IAAd,KAAK,KAAK,IAEZ,gBAFP;MACmB,SAAqB,EAArB,QAAQ,aAAa;MAAA,UAAG;IAAK,CAC1C,CAAC,GAFP,IAEO;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IACP,cAAQ,gBAAR;MAA2B,SAAiB,EAAjB,QAAQ,SAAS;MAAA,UAAG;IAAQ,CAAa,CAAC,GAArE,IAAqE;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAjCxE;MACa,SAAkB,EAAlB,kBAAkB;MACpB,OAMR,EANQ,EAMR;MAAA,WAEA,EACuD,EACxD,EAiBE,EACD,EAEO,EACP,GAAqE;IAAA,CACnE,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAlCN,GAkCM;AAAA,CAET;AAED,eAAe,KAAK","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Input/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type Ref,\n useRef,\n useState,\n} from 'react';\n\nimport { type COMPOSE, type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeKeyT = 'children' | 'container' | 'empty' | 'error' | 'errorMessage'\n | 'focused' | 'input' | 'label';\n\ntype PropsT = React.InputHTMLAttributes<HTMLInputElement> & {\n children?: ReactNode;\n composeAdhocTheme?: COMPOSE;\n error?: ReactNode;\n label?: React.ReactNode;\n ref?: Ref<HTMLInputElement>;\n testId?: string;\n theme?: Theme<ThemeKeyT>;\n};\n\n/**\n * Themeable input field, based on the standard HTML `<input>` element.\n * @param [props.label] Input label.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props...] [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n * @param [props...] Any other properties are passed to the underlying\n * `<input>` element.\n */\nconst Input: FunctionComponent<PropsT> = ({\n children,\n composeAdhocTheme,\n error,\n label,\n ref,\n testId,\n theme,\n ...rest\n}) => {\n const composed = useTheme('Input', defaultTheme, theme, {\n composeAdhocTheme,\n });\n\n // NOTE: As of now, it is only updated when \"theme.focused\" is defined,\n // as otherwise its value is not used.\n const [focused, setFocused] = useState(false);\n\n const localRef = useRef<HTMLInputElement>(null);\n\n let containerClassName = composed.container ?? '';\n\n // NOTE: As of now, \"focused\" can be true only when \"theme.focused\"\n // is provided.\n if (focused /* && theme.focused */) containerClassName += ` ${composed.focused ?? ''}`;\n\n if (!rest.value && composed.empty) containerClassName += ` ${composed.empty}`;\n\n if (error) containerClassName += ` ${composed.error ?? ''}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n // TODO: It does not really work if a callback-style `ref` is passed in,\n // we need a more complex logic to cover that case, but for now this serves\n // the case we need it for.\n if (typeof ref === 'object') ref?.current?.focus();\n else localRef.current?.focus();\n }}\n >\n {label === undefined\n ? null : <div className={composed.label}>{label}</div>}\n <input\n className={composed.input}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n ref={ref ?? localRef}\n\n // TODO: Avoid the spreading later.\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest}\n\n onBlur={composed.focused ? (e) => {\n setFocused(false);\n rest.onBlur?.(e);\n } : rest.onBlur}\n onFocus={composed.focused ? (e) => {\n setFocused(true);\n rest.onFocus?.(e);\n } : rest.onFocus}\n />\n {error && error !== true\n ? <div className={composed.errorMessage}>{error}</div>\n : null}\n {children ? <div className={composed.children}>{children}</div> : null}\n </div>\n );\n};\n\nexport default Input;\n"],"mappings":";AAAA,SAIE,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAmC,QAAQ,QAAQ,0BAA0B;AAE7E;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC,+DAexC;AACA;AACA;AACA;AACA;AACA;AACA;A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{
91
91
  t5 = /*#__PURE__*/_jsx("div", {
92
92
  onFocus: () => {
93
+ if (!containerRef.current) {
94
+ throw Error("Missing container reference");
95
+ }
93
96
  const elems = containerRef.current.querySelectorAll("*");
94
97
  for (let i = elems.length - 1; i >= 0; --i) {
95
98
  elems[i].focus();
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Modal/index.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './base-theme.scss';\nimport S from './styles.scss';\n\ntype ThemeT = Theme<'container' | 'overlay'>;\n\ntype PropsT = {\n cancelOnScrolling?: boolean;\n children?: ReactNode;\n dontDisableScrolling?: boolean;\n onCancel?: () => void;\n overlayStyle?: CSSProperties;\n style?: CSSProperties;\n testId?: string;\n testIdForOverlay?: string;\n theme: ThemeT;\n\n /** @deprecated */\n containerStyle?: CSSProperties;\n};\n\n/**\n * The `<Modal>` component implements a simple themeable modal window, wrapped\n * into the default theme. `<BaseModal>` exposes the base non-themed component.\n * **Children:** Component children are rendered as the modal content.\n * @param {object} props Component properties. Beside props documented below,\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties) are supported as well.\n * @param {function} [props.onCancel] The callback to trigger when user\n * clicks outside the modal, or presses Escape. It is expected to hide the\n * modal.\n * @param {ModalTheme} [props.theme] _Ad hoc_ theme.\n */\nconst BaseModal: FunctionComponent<PropsT> = ({\n cancelOnScrolling,\n children,\n containerStyle,\n dontDisableScrolling,\n onCancel,\n overlayStyle,\n style,\n testId,\n testIdForOverlay,\n theme,\n}) => {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const overlayRef = useRef<HTMLDivElement | null>(null);\n\n // Sets up modal cancellation of scrolling, if opted-in.\n useEffect(() => {\n if (cancelOnScrolling && onCancel) {\n window.addEventListener('scroll', onCancel);\n window.addEventListener('wheel', onCancel);\n }\n return () => {\n if (cancelOnScrolling && onCancel) {\n window.removeEventListener('scroll', onCancel);\n window.removeEventListener('wheel', onCancel);\n }\n };\n }, [cancelOnScrolling, onCancel]);\n\n // Disables window scrolling, if it is not opted-out.\n useEffect(() => {\n if (!dontDisableScrolling) {\n document.body.classList.add(S.scrollingDisabledByModal);\n }\n return () => {\n if (!dontDisableScrolling) {\n document.body.classList.remove(S.scrollingDisabledByModal);\n }\n };\n }, [dontDisableScrolling]);\n\n const focusLast = useMemo(() => (\n <div\n onFocus={() => {\n const elems = containerRef.current!.querySelectorAll('*');\n for (let i = elems.length - 1; i >= 0; --i) {\n (elems[i] as HTMLElement).focus();\n if (document.activeElement === elems[i]) return;\n }\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n ), []);\n\n return createPortal(\n (\n <div>\n {focusLast}\n <div\n aria-label=\"Cancel\"\n className={theme.overlay}\n data-testid={\n process.env.NODE_ENV === 'production'\n ? undefined : testIdForOverlay\n }\n onClick={(e) => {\n if (onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n onKeyDown={(e) => {\n if (e.key === 'Escape' && onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n ref={(node) => {\n if (node && node !== overlayRef.current) {\n overlayRef.current = node;\n node.focus();\n }\n }}\n role=\"button\"\n style={overlayStyle}\n tabIndex={0}\n />\n {\n // NOTE: These rules are disabled because our intention is to keep\n // the element non-interactive (thus not on the keyboard focus chain),\n // and it has `onClick` handler merely to stop propagation of click\n // events to its parent container. This is needed because, for example\n // when the modal is wrapped into an interactive element we don't want\n // any clicks inside the modal to bubble-up to that parent element\n // (because visually and logically the modal dialog does not belong\n // to its parent container, where it technically belongs from\n // the HTML mark-up perpective).\n }\n <div // eslint-disable-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n aria-modal=\"true\"\n className={theme.container}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={(e) => {\n e.stopPropagation();\n }}\n onWheel={(event) => {\n event.stopPropagation();\n }}\n ref={containerRef}\n role=\"dialog\"\n style={style ?? containerStyle}\n >\n {children}\n </div>\n <div\n onFocus={() => {\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n {focusLast}\n </div>\n ),\n document.body,\n );\n};\n\n/* Non-themed version of the Modal. */\nexport { BaseModal };\n\nconst Modal: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Modal', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseModal {...rest} theme={composed} />;\n};\n\nexport default Modal;\n"],"mappings":";AAAA,SAIE,SAAS,EACT,OAAO,EACP,MAAM,QACD,OAAO;AAEd,SAAS,YAAY,QAAQ,WAAW;AAExC,SAAqB,QAAQ,QAAQ,0BAA0B;AAE/D;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAA;EAAA;AAAA;AAC8B,+DAmB9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,SAAoC,GAAG;EAAA;EAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAW7C;EACC,qBAAqB,MAAM,CAAwB,IAAI,CAAC;EACxD,mBAAmB,MAAM,CAAwB,IAAI,CAAC;EAAC;EAAA;EAAA;IAG7C;MACR,IAAI,iBAA6B,IAA7B,QAA6B;QAC/B,MAAM,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC;QAC3C,MAAM,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC;MAAA;MAC3C,OACM;QACL,IAAI,iBAA6B,IAA7B,QAA6B;UAC/B,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,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAxEM,GAwEN;AAAA,CACF,CAED;AACA,SAAS,SAAS;AAElB,MAAM,KAEL,GAAG;EAAA;EAAA;EAAA;EAAA;IAAC;MAAA;MAAA;IAAA,MAAkB;IAAA;IAAA;IAAA;EAAA;IAAA;IAAA;EAAA;EACrB,iBAAiB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC;EAAC;EAAA;IAGjD,uBAAC,SAAS;MAAA,GAAK,IAAI;MAAS,KAAQ,EAAR;IAAQ,CAAG,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAAxC,EAAwC;AAAA,CAChD;AAED,eAAe,KAAK;AAhJyB;EA0GjC,GAAC,gBAAgB,CAAC,CAAC;AAAA;AA1Gc;EA6GjC,KAAK,gBAAgB,CAAC,CAAC;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/Modal/index.tsx"],"sourcesContent":["import {\n type CSSProperties,\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './base-theme.scss';\nimport S from './styles.scss';\n\ntype ThemeT = Theme<'container' | 'overlay'>;\n\ntype PropsT = {\n cancelOnScrolling?: boolean;\n children?: ReactNode;\n dontDisableScrolling?: boolean;\n onCancel?: () => void;\n overlayStyle?: CSSProperties;\n style?: CSSProperties;\n testId?: string;\n testIdForOverlay?: string;\n theme: ThemeT;\n\n /** @deprecated */\n containerStyle?: CSSProperties;\n};\n\n/**\n * The `<Modal>` component implements a simple themeable modal window, wrapped\n * into the default theme. `<BaseModal>` exposes the base non-themed component.\n * **Children:** Component children are rendered as the modal content.\n * @param {object} props Component properties. Beside props documented below,\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties) are supported as well.\n * @param {function} [props.onCancel] The callback to trigger when user\n * clicks outside the modal, or presses Escape. It is expected to hide the\n * modal.\n * @param {ModalTheme} [props.theme] _Ad hoc_ theme.\n */\nconst BaseModal: FunctionComponent<PropsT> = ({\n cancelOnScrolling,\n children,\n containerStyle,\n dontDisableScrolling,\n onCancel,\n overlayStyle,\n style,\n testId,\n testIdForOverlay,\n theme,\n}) => {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const overlayRef = useRef<HTMLDivElement | null>(null);\n\n // Sets up modal cancellation of scrolling, if opted-in.\n useEffect(() => {\n if (cancelOnScrolling && onCancel) {\n window.addEventListener('scroll', onCancel);\n window.addEventListener('wheel', onCancel);\n }\n return () => {\n if (cancelOnScrolling && onCancel) {\n window.removeEventListener('scroll', onCancel);\n window.removeEventListener('wheel', onCancel);\n }\n };\n }, [cancelOnScrolling, onCancel]);\n\n // Disables window scrolling, if it is not opted-out.\n useEffect(() => {\n if (!dontDisableScrolling) {\n document.body.classList.add(S.scrollingDisabledByModal);\n }\n return () => {\n if (!dontDisableScrolling) {\n document.body.classList.remove(S.scrollingDisabledByModal);\n }\n };\n }, [dontDisableScrolling]);\n\n const focusLast = useMemo(() => (\n <div\n onFocus={() => {\n if (!containerRef.current) throw Error('Missing container reference');\n const elems = containerRef.current.querySelectorAll('*');\n for (let i = elems.length - 1; i >= 0; --i) {\n (elems[i] as HTMLElement).focus();\n if (document.activeElement === elems[i]) return;\n }\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n ), []);\n\n return createPortal(\n (\n <div>\n {focusLast}\n <div\n aria-label=\"Cancel\"\n className={theme.overlay}\n data-testid={\n process.env.NODE_ENV === 'production'\n ? undefined : testIdForOverlay\n }\n onClick={(e) => {\n if (onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n onKeyDown={(e) => {\n if (e.key === 'Escape' && onCancel) {\n onCancel();\n e.stopPropagation();\n }\n }}\n ref={(node) => {\n if (node && node !== overlayRef.current) {\n overlayRef.current = node;\n node.focus();\n }\n }}\n role=\"button\"\n style={overlayStyle}\n tabIndex={0}\n />\n {\n // NOTE: These rules are disabled because our intention is to keep\n // the element non-interactive (thus not on the keyboard focus chain),\n // and it has `onClick` handler merely to stop propagation of click\n // events to its parent container. This is needed because, for example\n // when the modal is wrapped into an interactive element we don't want\n // any clicks inside the modal to bubble-up to that parent element\n // (because visually and logically the modal dialog does not belong\n // to its parent container, where it technically belongs from\n // the HTML mark-up perpective).\n }\n <div // eslint-disable-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n aria-modal=\"true\"\n className={theme.container}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onClick={(e) => {\n e.stopPropagation();\n }}\n onWheel={(event) => {\n event.stopPropagation();\n }}\n ref={containerRef}\n role=\"dialog\"\n style={style ?? containerStyle}\n >\n {children}\n </div>\n <div\n onFocus={() => {\n overlayRef.current?.focus();\n }}\n // TODO: Have a look at this later.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n />\n {focusLast}\n </div>\n ),\n document.body,\n );\n};\n\n/* Non-themed version of the Modal. */\nexport { BaseModal };\n\nconst Modal: FunctionComponent<\n Omit<PropsT, 'theme'> & { theme?: ThemeT }\n> = ({ theme, ...rest }) => {\n const composed = useTheme('Modal', defaultTheme, theme);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <BaseModal {...rest} theme={composed} />;\n};\n\nexport default Modal;\n"],"mappings":";AAAA,SAIE,SAAS,EACT,OAAO,EACP,MAAM,QACD,OAAO;AAEd,SAAS,YAAY,QAAQ,WAAW;AAExC,SAAqB,QAAQ,QAAQ,0BAA0B;AAE/D;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAA;EAAA;AAAA;AAC8B,+DAmB9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,SAAo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MAC9D,OAER,EAFQ,KAER;MACQ,OAER,EAFQ,MAER;MACI,GAAY,EAAZ,YAAY;MACZ,IAAQ,EAAR,QAAQ;MACN,KAAuB,EAAvB,GAAuB;MAAA,UAE7B;IAAQ,CACN,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IACN;MACW,OAER,EAFQ;QACP,UAAU,QAAe,OAAE,CAAD,CAAC;MAAA,CAC5B;MAGS,QAAC,EAAD;IAAC,CACZ,CAAC;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IAnED,+BAAY,cAEf;MAAA,WACG,SAAS,EACV,GA4BE,EAYF,GAeM,EACN,GAOE,EACD,SAAS;IAAA,CACP,CAAC,EAER,QAAQ,KACV,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAxEM,GAwEN;AAAA,CACF,CAED;AACA,SAAS,SAAS;AAElB,MAAM,KAEL,GAAG;EAAA;EAAA;EAAA;EAAA;IAAC;MAAA;MAAA;IAAA,MAAkB;IAAA;IAAA;IAAA;EAAA;IAAA;IAAA;EAAA;EACrB,iBAAiB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC;EAAC;EAAA;IAGjD,uBAAC,SAAS;MAAA,GAAK,IAAI;MAAS,KAAQ,EAAR;IAAQ,CAAG,CAAC;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAAxC,EAAwC;AAAA,CAChD;AAED,eAAe,KAAK;AAjJyB;EA2GjC,GAAC,gBAAgB,CAAC,CAAC;AAAA;AA3Gc;EA8GjC,KAAK,gBAAgB,CAAC,CAAC;AAAA","ignoreList":[]}
@@ -82,9 +82,9 @@ const TextArea = t0 => {
82
82
  t4 = $[4];
83
83
  }
84
84
  useLayoutEffect(t3, t4);
85
- let containerClassName = custom.container;
85
+ let containerClassName = custom.container ?? "";
86
86
  if (error) {
87
- containerClassName = containerClassName + ` ${custom.error}`;
87
+ containerClassName = containerClassName + ` ${custom.error ?? ""}`;
88
88
  }
89
89
  let t5;
90
90
  if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
@@ -107,7 +107,7 @@ const TextArea = t0 => {
107
107
  } else {
108
108
  t6 = $[8];
109
109
  }
110
- const t7 = `${custom.textarea} ${custom.hidden}`;
110
+ const t7 = `${custom.textarea ?? ""} ${custom.hidden ?? ""}`;
111
111
  const t8 = localValue || " ";
112
112
  let t9;
113
113
  if ($[9] !== t7 || $[10] !== t8) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/TextArea/index.tsx"],"sourcesContent":["import {\n type ChangeEventHandler,\n type FocusEventHandler,\n type FunctionComponent,\n type KeyboardEventHandler,\n type ReactNode,\n type Ref,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label'\n | 'textarea';\n\ntype Props = {\n disabled?: boolean;\n error?: ReactNode;\n label?: string;\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n placeholder?: string;\n ref?: Ref<HTMLTextAreaElement>;\n testId?: string;\n theme?: Theme<ThemeKeyT>;\n value?: string;\n};\n\nconst TextArea: FunctionComponent<Props> = ({\n disabled,\n error,\n label,\n onBlur,\n onChange,\n onKeyDown,\n placeholder,\n ref,\n testId,\n theme,\n value,\n}) => {\n const custom = useTheme('TextArea', defaultTheme, theme);\n\n const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);\n const [height, setHeight] = useState<number | undefined>();\n\n const textAreaRef = useRef<HTMLTextAreaElement>(null);\n\n const [localValue, setLocalValue] = useState(value ?? '');\n if (value !== undefined && localValue !== value) setLocalValue(value);\n\n // This resizes text area's height when its width is changed for any reason.\n useEffect(() => {\n const el = hiddenAreaRef.current;\n if (!el) return undefined;\n\n const cb = () => {\n setHeight(el.scrollHeight);\n };\n const observer = new ResizeObserver(cb);\n observer.observe(el);\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n // Resizes the text area when its content is modified.\n //\n // NOTE: useLayoutEffect() instead of useEffect() makes difference here,\n // as it helps to avoid visible \"content/height\" jumps (i.e. with just\n // useEffect() it becomes visible how the content is modified first,\n // and then input height is incremented, if necessary).\n // See: https://github.com/birdofpreyru/react-utils/issues/313\n useLayoutEffect(() => {\n const el = hiddenAreaRef.current;\n if (el) setHeight(el.scrollHeight);\n }, [localValue]);\n\n let containerClassName = custom.container;\n if (error) containerClassName += ` ${custom.error}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n textAreaRef.current?.focus();\n }}\n >\n {label === undefined ? null : <div className={custom.label}>{label}</div>}\n <textarea\n className={`${custom.textarea} ${custom.hidden}`}\n\n // This text area is hidden underneath the primary one below,\n // and it is used for text measurements, to implement auto-scaling\n // of the primary textarea's height.\n readOnly\n ref={hiddenAreaRef}\n\n // The \"-1\" value of \"tabIndex\" removes this hidden text area from\n // the tab-focus-chain.\n tabIndex={-1}\n\n // NOTE: With empty string value (\"\") the scrolling height of this text\n // area is zero, thus collapsing <TextArea> height below the single line\n // input height. To avoid it we fallback to whitespace (\" \") character\n // here.\n value={localValue || ' '}\n />\n <textarea\n className={custom.textarea}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onBlur={onBlur}\n\n // When value is \"undefined\" the text area is not-managed, and we should\n // manage it internally for the measurement / resizing functionality\n // to work.\n onChange={\n value === undefined\n ? (e) => {\n setLocalValue(e.target.value);\n } : onChange\n }\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n\n ref={(node) => {\n textAreaRef.current = node;\n\n if (typeof ref === 'function') ref(node);\n\n // eslint-disable-next-line no-param-reassign\n else if (ref) ref.current = node;\n }}\n\n style={{ height }}\n value={localValue}\n />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SAAe,EAAf,MAAM,SAAS;MACb,kBAA0D;MAC7D,QAAQ,EAAR,QAAQ;MACV,MAAM,EAAN,MAAM;MAMZ,QAGc,EAHd,GAGc;MAEL,SAAS,EAAT,SAAS;MACP,WAAW,EAAX,WAAW;MAEnB,GAOJ,EAPI,GAOJ;MAEM,KAAU,EAAV,GAAU;MACV,KAAU,EAAV;IAAU,CAClB,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IACD,WAAuB,IAAd,KAAK,KAAK,IAEZ,gBAFP;MACmB,SAAmB,EAAnB,MAAM,aAAa;MAAA,UAAG;IAAK,CACxC,CAAC,GAFP,IAEO;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA;EAAA;IA1DV;MACa,SAAkB,EAAlB,kBAAkB;MACpB,OAER,EAFQ,EAER;MAAA,WAEA,EAAwE,EACzE,EAkBE,EACF,GA6BE,EACD,GAEO;IAAA,CACL,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OA3DN,GA2DM;AAAA,CAET;AAED,eAAe,QAAQ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/TextArea/index.tsx"],"sourcesContent":["import {\n type ChangeEventHandler,\n type FocusEventHandler,\n type FunctionComponent,\n type KeyboardEventHandler,\n type ReactNode,\n type Ref,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport defaultTheme from './style.scss';\n\ntype ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label'\n | 'textarea';\n\ntype Props = {\n disabled?: boolean;\n error?: ReactNode;\n label?: string;\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n placeholder?: string;\n ref?: Ref<HTMLTextAreaElement>;\n testId?: string;\n theme?: Theme<ThemeKeyT>;\n value?: string;\n};\n\nconst TextArea: FunctionComponent<Props> = ({\n disabled,\n error,\n label,\n onBlur,\n onChange,\n onKeyDown,\n placeholder,\n ref,\n testId,\n theme,\n value,\n}) => {\n const custom = useTheme('TextArea', defaultTheme, theme);\n\n const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);\n const [height, setHeight] = useState<number | undefined>();\n\n const textAreaRef = useRef<HTMLTextAreaElement>(null);\n\n const [localValue, setLocalValue] = useState(value ?? '');\n if (value !== undefined && localValue !== value) setLocalValue(value);\n\n // This resizes text area's height when its width is changed for any reason.\n useEffect(() => {\n const el = hiddenAreaRef.current;\n if (!el) return undefined;\n\n const cb = () => {\n setHeight(el.scrollHeight);\n };\n const observer = new ResizeObserver(cb);\n observer.observe(el);\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n // Resizes the text area when its content is modified.\n //\n // NOTE: useLayoutEffect() instead of useEffect() makes difference here,\n // as it helps to avoid visible \"content/height\" jumps (i.e. with just\n // useEffect() it becomes visible how the content is modified first,\n // and then input height is incremented, if necessary).\n // See: https://github.com/birdofpreyru/react-utils/issues/313\n useLayoutEffect(() => {\n const el = hiddenAreaRef.current;\n if (el) setHeight(el.scrollHeight);\n }, [localValue]);\n\n let containerClassName = custom.container ?? '';\n if (error) containerClassName += ` ${custom.error ?? ''}`;\n\n return (\n <div\n className={containerClassName}\n onFocus={() => {\n textAreaRef.current?.focus();\n }}\n >\n {label === undefined ? null : <div className={custom.label}>{label}</div>}\n <textarea\n className={`${custom.textarea ?? ''} ${custom.hidden ?? ''}`}\n\n // This text area is hidden underneath the primary one below,\n // and it is used for text measurements, to implement auto-scaling\n // of the primary textarea's height.\n readOnly\n ref={hiddenAreaRef}\n\n // The \"-1\" value of \"tabIndex\" removes this hidden text area from\n // the tab-focus-chain.\n tabIndex={-1}\n\n // NOTE: With empty string value (\"\") the scrolling height of this text\n // area is zero, thus collapsing <TextArea> height below the single line\n // input height. To avoid it we fallback to whitespace (\" \") character\n // here.\n value={localValue || ' '}\n />\n <textarea\n className={custom.textarea}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n disabled={disabled}\n onBlur={onBlur}\n\n // When value is \"undefined\" the text area is not-managed, and we should\n // manage it internally for the measurement / resizing functionality\n // to work.\n onChange={\n value === undefined\n ? (e) => {\n setLocalValue(e.target.value);\n } : onChange\n }\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n\n ref={(node) => {\n textAreaRef.current = node;\n\n if (typeof ref === 'function') ref(node);\n\n // eslint-disable-next-line no-param-reassign\n else if (ref) ref.current = node;\n }}\n\n style={{ height }}\n value={localValue}\n />\n {error && error !== true\n ? <div className={custom.errorMessage}>{error}</div>\n : null}\n </div>\n );\n};\n\nexport default TextArea;\n"],"mappings":";AAAA,SAOE,SAAS,EACT,eAAe,EACf,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAqB,QAAQ,QAAQ,0BAA0B;AAE/D;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AAmBxC,MAAM,QAAkC,GAAG;EAAA;EAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAY3C;EACC,eAAe,QAAQ,CAAC,UAAU,EAAE,YAAY,EAAE,KAAK,CAAC;EAExD,sBAAsB,MAAM,CAAsB,IAAI,CAAC;EACvD,4BAA4B,QAAQ,CAAqB,CAAC;EAE1D,oBAAoB,MAAM,CAAsB,IAAI,CAAC;EAErD,oCAAoC,QAAQ,CAAC,KAAW,IAAX,EAAW,CAAC;EACzD,IAAI,KAAK,KAAK,SAAiC,IAApB,UAAU,KAAK,KAAK;IAAE,aAAa,CAAC,KAAK,CAAC;EAAA;EAAC;EAAA;EAAA;IAG5D;MACR,WAAW,aAAa,QAAQ;MAChC,IAAI,CAAC,EAAE;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2DM;AAAA,CAET;AAED,eAAe,QAAQ","ignoreList":[]}
@@ -157,9 +157,9 @@ function setComponentPositions(pageX, pageY, placement, element, tooltip) {
157
157
  pos.arrowY -= tooltipRects.container.height + tooltipRects.arrow.height;
158
158
  pos.baseArrowStyle = ARROW_STYLE_UP;
159
159
  }
160
- const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;
160
+ const containerStyle = `left:${pos.containerX.toString()}px;top:${pos.containerY.toString()}px`;
161
161
  tooltip.container.setAttribute("style", containerStyle);
162
- const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;
162
+ const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX.toString()}px;top:${pos.arrowY.toString()}px`;
163
163
  tooltip.arrow.setAttribute("style", arrowStyle);
164
164
  } /* The Tooltip component itself. */
165
165
  const Tooltip = t0 => {