@dr.pogodin/react-utils 1.47.5 → 1.48.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 (123) hide show
  1. package/build/development/index.js +1 -1
  2. package/build/development/index.js.map +1 -1
  3. package/build/development/server/server.js +0 -1
  4. package/build/development/server/server.js.map +1 -1
  5. package/build/development/shared/components/Button/index.js +13 -9
  6. package/build/development/shared/components/Button/index.js.map +1 -1
  7. package/build/development/shared/components/Checkbox/index.js +8 -7
  8. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  9. package/build/development/shared/components/Input/index.js +14 -12
  10. package/build/development/shared/components/Input/index.js.map +1 -1
  11. package/build/development/shared/components/Modal/index.js +15 -3
  12. package/build/development/shared/components/Modal/index.js.map +1 -1
  13. package/build/development/shared/components/PageLayout/index.js +18 -15
  14. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  15. package/build/development/shared/components/TextArea/index.js +9 -8
  16. package/build/development/shared/components/TextArea/index.js.map +1 -1
  17. package/build/development/shared/components/Throbber/index.js +15 -12
  18. package/build/development/shared/components/Throbber/index.js.map +1 -1
  19. package/build/development/shared/components/WithTooltip/index.js +6 -6
  20. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  21. package/build/development/shared/components/YouTubeVideo/index.js +6 -5
  22. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  23. package/build/development/shared/components/selectors/CustomDropdown/index.js +13 -12
  24. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  25. package/build/development/shared/components/selectors/NativeDropdown/index.js +11 -10
  26. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  27. package/build/development/shared/components/selectors/Switch/index.js +9 -9
  28. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  29. package/build/development/shared/components/selectors/common.js.map +1 -1
  30. package/build/development/shared/components/selectors/index.js +1 -1
  31. package/build/development/shared/components/selectors/index.js.map +1 -1
  32. package/build/development/shared/utils/index.js +2 -5
  33. package/build/development/shared/utils/index.js.map +1 -1
  34. package/build/development/shared/utils/jest/E2eSsrEnv.js +0 -1
  35. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  36. package/build/production/index.js +1 -1
  37. package/build/production/index.js.map +1 -1
  38. package/build/production/server/server.js +1 -1
  39. package/build/production/server/server.js.map +1 -1
  40. package/build/production/shared/components/Button/index.js +3 -8
  41. package/build/production/shared/components/Button/index.js.map +1 -1
  42. package/build/production/shared/components/Checkbox/index.js +1 -1
  43. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  44. package/build/production/shared/components/Input/index.js +6 -6
  45. package/build/production/shared/components/Input/index.js.map +1 -1
  46. package/build/production/shared/components/Modal/index.js +3 -2
  47. package/build/production/shared/components/Modal/index.js.map +1 -1
  48. package/build/production/shared/components/PageLayout/index.js +2 -2
  49. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  50. package/build/production/shared/components/TextArea/index.js +4 -4
  51. package/build/production/shared/components/TextArea/index.js.map +1 -1
  52. package/build/production/shared/components/Throbber/index.js +2 -2
  53. package/build/production/shared/components/Throbber/index.js.map +1 -1
  54. package/build/production/shared/components/WithTooltip/index.js +3 -3
  55. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  56. package/build/production/shared/components/YouTubeVideo/index.js +4 -4
  57. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  58. package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
  59. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  60. package/build/production/shared/components/selectors/NativeDropdown/index.js +3 -3
  61. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  62. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  63. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  64. package/build/production/shared/components/selectors/common.js.map +1 -1
  65. package/build/production/shared/components/selectors/index.js +1 -1
  66. package/build/production/shared/components/selectors/index.js.map +1 -1
  67. package/build/production/shared/utils/index.js +1 -1
  68. package/build/production/shared/utils/index.js.map +1 -1
  69. package/build/production/shared/utils/jest/E2eSsrEnv.js +1 -1
  70. package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  71. package/build/types-code/index.d.ts +1 -1
  72. package/build/types-code/shared/components/Button/index.d.ts +6 -10
  73. package/build/types-code/shared/components/Checkbox/index.d.ts +4 -3
  74. package/build/types-code/shared/components/Input/index.d.ts +12 -4
  75. package/build/types-code/shared/components/Modal/index.d.ts +6 -3
  76. package/build/types-code/shared/components/PageLayout/index.d.ts +19 -4
  77. package/build/types-code/shared/components/TextArea/index.d.ts +4 -4
  78. package/build/types-code/shared/components/Throbber/index.d.ts +13 -3
  79. package/build/types-code/shared/components/WithTooltip/index.d.ts +18 -4
  80. package/build/types-code/shared/components/YouTubeVideo/index.d.ts +20 -4
  81. package/build/types-code/shared/components/selectors/CustomDropdown/index.d.ts +3 -2
  82. package/build/types-code/shared/components/selectors/NativeDropdown/index.d.ts +22 -2
  83. package/build/types-code/shared/components/selectors/Switch/index.d.ts +7 -6
  84. package/build/types-code/shared/components/selectors/common.d.ts +2 -3
  85. package/build/types-code/shared/components/selectors/index.d.ts +2 -2
  86. package/build/types-code/shared/utils/index.d.ts +2 -7
  87. package/build/web/index.js +1 -1
  88. package/build/web/index.js.map +1 -1
  89. package/build/web/server/server.js +0 -1
  90. package/build/web/server/server.js.map +1 -1
  91. package/build/web/shared/components/Button/index.js +13 -9
  92. package/build/web/shared/components/Button/index.js.map +1 -1
  93. package/build/web/shared/components/Checkbox/index.js +8 -7
  94. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  95. package/build/web/shared/components/Input/index.js +14 -12
  96. package/build/web/shared/components/Input/index.js.map +1 -1
  97. package/build/web/shared/components/Modal/index.js +15 -3
  98. package/build/web/shared/components/Modal/index.js.map +1 -1
  99. package/build/web/shared/components/PageLayout/index.js +18 -15
  100. package/build/web/shared/components/PageLayout/index.js.map +1 -1
  101. package/build/web/shared/components/TextArea/index.js +9 -8
  102. package/build/web/shared/components/TextArea/index.js.map +1 -1
  103. package/build/web/shared/components/Throbber/index.js +15 -12
  104. package/build/web/shared/components/Throbber/index.js.map +1 -1
  105. package/build/web/shared/components/WithTooltip/index.js +6 -6
  106. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  107. package/build/web/shared/components/YouTubeVideo/index.js +6 -5
  108. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
  109. package/build/web/shared/components/selectors/CustomDropdown/index.js +13 -12
  110. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  111. package/build/web/shared/components/selectors/NativeDropdown/index.js +11 -10
  112. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  113. package/build/web/shared/components/selectors/Switch/index.js +9 -9
  114. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  115. package/build/web/shared/components/selectors/common.js.map +1 -1
  116. package/build/web/shared/components/selectors/index.js +1 -1
  117. package/build/web/shared/components/selectors/index.js.map +1 -1
  118. package/build/web/shared/utils/index.js +2 -5
  119. package/build/web/shared/utils/index.js.map +1 -1
  120. package/build/web/shared/utils/jest/E2eSsrEnv.js +0 -1
  121. package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  122. package/config/babel/webpack.js +1 -1
  123. package/package.json +15 -15
@@ -1 +1 @@
1
- {"version":3,"file":"E2eSsrEnv.js","names":["path","defaults","set","register","JsdomEnv","Volume","createFsFromVolume","webpack","noop","E2eSsrEnv","loadWebpackConfig","optionsString","pragmas","options","JSON","parse","context","testFolder","fs","global","webpackOutputFs","factoryPath","factory","resolve","rootDir","default","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","Error","compiler","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","webpackStats","runSsr","logger","debug","info","log","warn","cleanup","entry","p","module","exportName","entryExportName","Application","ssrFactory","renderer","status","markup","ssrRequest","cookie","send","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","requestString","request","url","csrfToken","projectConfig","dom","dirname","testPath","withSsr","root","process","cwd","envName","babelEnv","extensions","setup","require","cache","setBuildInfo","undefined","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","forEach","key","revert"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.ts"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\n// TODO: We need to add correct typing for environment options.\n\nimport path from 'node:path';\n\nimport type { Request, Response } from 'express';\n\nimport { defaults, set } from 'lodash-es';\n\nimport type { ReactNode } from 'react';\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\nimport register from '@babel/register/experimental-worker';\n\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { Volume, createFsFromVolume } from 'memfs';\nimport webpack, { type Configuration } from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nimport type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\n\nfunction noop() {\n // NOOP\n}\n\nexport default class E2eSsrEnv extends JsdomEnv {\n pragmas: Record<string, string | string[]>;\n\n ssrRequest: object;\n\n rootDir: string;\n\n testFolder: string;\n\n withSsr: boolean;\n\n webpackStats?: webpack.StatsCompilation;\n\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n private async loadWebpackConfig() {\n const optionsString = this.pragmas['webpack-config-options'] as string;\n\n const options = (optionsString ? JSON.parse(optionsString) : {}) as\n webpack.Configuration;\n\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n const factoryPath = this.pragmas['webpack-config-factory'] as string;\n\n let factory = await import(/* webpackChunkName: \"not-a-valid-chunk\" */\n path.resolve(this.rootDir, factoryPath)\n ) as (((ops: Configuration) => Configuration) | {\n default: (ops: Configuration) => Configuration;\n });\n\n factory = 'default' in factory ? factory.default : factory;\n\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8') as string;\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack(): Promise<void> {\n await this.loadWebpackConfig();\n\n if (!this.global.webpackConfig) throw Error('Failed to load Webpack config');\n const compiler = webpack(this.global.webpackConfig);\n if (!compiler) throw Error('Failed to construct Webpack compiler');\n\n // TODO: The \"as typeof compiler.outputFileSystem\" piece below is\n // a workaround for the Webpack regression:\n // https://github.com/webpack/webpack/issues/18242\n compiler.outputFileSystem = this.global.webpackOutputFs as\n typeof compiler.outputFileSystem;\n\n return new Promise<void>((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats?.hasErrors()) {\n // eslint-disable-next-line no-console\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats?.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr(): Promise<void> {\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n options.logger ??= {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n\n options.buildInfo ??= this.global.buildInfo;\n\n let cleanup: (() => void) | undefined;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry as string);\n const module = await import(/* webpackChunkName: \"not-a-valid-chunk\" */\n p\n ) as NodeJS.Module;\n\n if ('cleanup' in module) cleanup = module.cleanup as () => void;\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName] as ReactNode;\n }\n }\n\n const { default: ssrFactory } = await import(/* webpackChunkName: \"not-a-valid-chunk\" */ 'server/renderer');\n const renderer = ssrFactory(this.global.webpackConfig!, options);\n let status = 200; // OK\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n this.ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\n },\n } as unknown) as Response,\n\n (error) => {\n // TODO: Strictly speaking, that error as Error casting is not all\n // correct, but it works, so no need to spend time on it right now.\n if (error) fail(error as Error);\n else done('');\n },\n );\n });\n\n this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n\n if (cleanup) cleanup();\n }\n\n constructor(\n config: JestEnvironmentConfig,\n context: EnvironmentContext,\n ) {\n const pragmas = context.docblockPragmas;\n\n const requestString = pragmas['ssr-request'] as string;\n const request = requestString\n ? JSON.parse(requestString) as Record<string, unknown>\n : {};\n\n request.url ??= '/';\n request.csrfToken = noop;\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url as string}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n\n // The usual \"babel-jest\" transformation setup does not apply to\n // the environment code and imports from it, this workaround enables it.\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n let root;\n switch (options.root) {\n case 'TEST':\n root = this.testFolder;\n break;\n default: root = process.cwd();\n }\n\n // BEWARE: Anything imported prior to this register() call seems to be\n // transpiled again by Babel if loaded after this call. This causes very\n // confusing errors when testing the code dependent on some sort of contexts\n // (because loading a module again effectively creates a new context object,\n // which is not recognized by the code expecting another context instance).\n // That's why below we prefer dynamic imports for some React Utils methods.\n register({\n envName: options.babelEnv as string,\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],\n root,\n });\n }\n\n async setup(): Promise<void> {\n await super.setup();\n await this.runWebpack();\n\n // NOTE: It is possible that the Webpack run above, and the SSR run below\n // load different versions of the same module (CommonJS, and ES), and it may\n // cause very confusing problems (e.g. see:\n // https://github.com/birdofpreyru/react-utils/issues/413).\n // It seems we can't reset the cache of ES modules, and Jest's module reset\n // does not reset modules loaded in this enviroment module, and also only\n // replacing entire cache object by and empty {} seems to help (in contrast\n // to deleting all entries by their keys, as it is done within .teardown()\n // method below). Thus, for now we do this as a hotfix, and we also reset\n // build info to undefined, because ES module version not beeing reset\n // triggers an error on the subsequent test using the environment.\n // TODO: Look for a cleaner solution.\n require.cache = {};\n\n const { setBuildInfo } = await import(/* webpackChunkName: \"not-a-valid-chunk\" */'../isomorphy/buildInfo');\n setBuildInfo(undefined, true);\n\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown(): Promise<void> {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n await super.teardown();\n }\n}\n"],"mappings":"mJAAA;AACA;AACA;AACA;AACA;AACA,GAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA,MAAO,CAAAA,IAAI,KAAM,WAAW,CAI5B,OAASC,QAAQ,CAAEC,GAAG,KAAQ,WAAW,CAIzC;AACA;AACA,sDACA,MAAO,CAAAC,QAAQ,KAAM,qCAAqC,CAE1D,MAAO,CAAAC,QAAQ,KAAM,wBAAwB,CAC7C,OAASC,MAAM,CAAEC,kBAAkB,KAAQ,OAAO,CAClD,MAAO,CAAAC,OAAO,KAA8B,SAAS,CACrD,qDAOA,QAAS,CAAAC,IAAIA,CAAA,CAAG,CACd;AAAA,CAGF,cAAe,MAAM,CAAAC,SAAS,QAAS,CAAAL,QAAS,CAa9C;AACF;AACA;AACA,KACE,KAAc,CAAAM,iBAAiBA,CAAA,CAAG,CAChC,KAAM,CAAAC,aAAa,CAAG,IAAI,CAACC,OAAO,CAAC,wBAAwB,CAAW,CAEtE,KAAM,CAAAC,OAAO,CAAIF,aAAa,CAAGG,IAAI,CAACC,KAAK,CAACJ,aAAa,CAAC,CAAG,CAAC,CACvC,CAEvBV,QAAQ,CAACY,OAAO,CAAE,CAChBG,OAAO,CAAE,IAAI,CAACC,UAAU,CACxBC,EAAE,CAAE,IAAI,CAACC,MAAM,CAACC,eAClB,CAAC,CAAC,CAEF,KAAM,CAAAC,WAAW,CAAG,IAAI,CAACT,OAAO,CAAC,wBAAwB,CAAW,CAEpE,GAAI,CAAAU,OAAO,CAAG,KAAM,OAAM,CAAC,2CACzBtB,IAAI,CAACuB,OAAO,CAAC,IAAI,CAACC,OAAO,CAAEH,WAAW,CACxC,CAEE,CAEFC,OAAO,C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ACH,CAEA,KAAM,CAAAM,KAAKA,CAAA,CAAkB,CAC3B,KAAM,MAAK,CAACA,KAAK,CAAC,CAAC,CACnB,KAAM,KAAI,CAAC5D,UAAU,CAAC,CAAC,CAEvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA6D,OAAO,CAACC,KAAK,CAAG,CAAC,CAAC,CAElB,KAAM,CAAEC,YAAa,CAAC,CAAG,KAAM,OAAM,CAAC,mEAAmE,CAAC,CAC1GA,YAAY,CAACC,SAAS,CAAE,IAAI,CAAC,CAE7B,GAAI,IAAI,CAACX,OAAO,CAAE,KAAM,KAAI,CAACrC,MAAM,CAAC,CAAC,CACrC,IAAI,CAAC3B,MAAM,CAAC4E,6BAA6B,CAAG,IAC9C,CAEA,KAAM,CAAAC,QAAQA,CAAA,CAAkB,CAC9B,MAAO,KAAI,CAAC7E,MAAM,CAAC4E,6BAA6B,CAEhD;AACA;AACA;AACA;AACA;AACA;AACAE,MAAM,CAACC,IAAI,CAACP,OAAO,CAACC,KAAK,CAAC,CAACO,OAAO,CAAEC,GAAG,EAAK,CAC1C,MAAO,CAAAT,OAAO,CAACC,KAAK,CAACQ,GAAG,CAC1B,CAAC,CAAC,CACFjG,QAAQ,CAACkG,MAAM,CAAC,CAAC,CACjB,KAAM,MAAK,CAACL,QAAQ,CAAC,CACvB,CACF","ignoreList":[]}
1
+ {"version":3,"file":"E2eSsrEnv.js","names":["path","defaults","set","register","JsdomEnv","Volume","createFsFromVolume","webpack","noop","E2eSsrEnv","loadWebpackConfig","optionsString","pragmas","options","JSON","parse","context","testFolder","fs","global","webpackOutputFs","factoryPath","factory","resolve","rootDir","default","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","Error","compiler","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","webpackStats","runSsr","logger","debug","info","log","warn","cleanup","entry","p","module","exportName","entryExportName","Application","ssrFactory","renderer","status","markup","ssrRequest","cookie","send","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","requestString","request","url","csrfToken","projectConfig","dom","dirname","testPath","withSsr","root","process","cwd","envName","babelEnv","extensions","setup","require","cache","setBuildInfo","undefined","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","forEach","key","revert"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.ts"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\n// TODO: We need to add correct typing for environment options.\n\nimport path from 'node:path';\n\nimport type { Request, Response } from 'express';\n\nimport { defaults, set } from 'lodash-es';\n\nimport type { ReactNode } from 'react';\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\nimport register from '@babel/register/experimental-worker';\n\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { Volume, createFsFromVolume } from 'memfs';\nimport webpack, { type Configuration } from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nimport type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\n\nfunction noop() {\n // NOOP\n}\n\nexport default class E2eSsrEnv extends JsdomEnv {\n pragmas: Record<string, string | string[]>;\n\n ssrRequest: object;\n\n rootDir: string;\n\n testFolder: string;\n\n withSsr: boolean;\n\n webpackStats?: webpack.StatsCompilation;\n\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n private async loadWebpackConfig() {\n const optionsString = this.pragmas['webpack-config-options'] as string;\n\n const options = (optionsString ? JSON.parse(optionsString) : {}) as\n webpack.Configuration;\n\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n const factoryPath = this.pragmas['webpack-config-factory'] as string;\n\n let factory = await import(/* webpackChunkName: \"not-a-valid-chunk\" */\n path.resolve(this.rootDir, factoryPath)\n ) as (((ops: Configuration) => Configuration) | {\n default: (ops: Configuration) => Configuration;\n });\n\n factory = 'default' in factory ? factory.default : factory;\n\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8') as string;\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack(): Promise<void> {\n await this.loadWebpackConfig();\n\n if (!this.global.webpackConfig) throw Error('Failed to load Webpack config');\n const compiler = webpack(this.global.webpackConfig);\n\n // TODO: The \"as typeof compiler.outputFileSystem\" piece below is\n // a workaround for the Webpack regression:\n // https://github.com/webpack/webpack/issues/18242\n compiler.outputFileSystem = this.global.webpackOutputFs as\n typeof compiler.outputFileSystem;\n\n return new Promise<void>((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats?.hasErrors()) {\n // eslint-disable-next-line no-console\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats?.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr(): Promise<void> {\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n options.logger ??= {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n\n options.buildInfo ??= this.global.buildInfo;\n\n let cleanup: (() => void) | undefined;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry as string);\n const module = await import(/* webpackChunkName: \"not-a-valid-chunk\" */\n p\n ) as NodeJS.Module;\n\n if ('cleanup' in module) cleanup = module.cleanup as () => void;\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName] as ReactNode;\n }\n }\n\n const { default: ssrFactory } = await import(/* webpackChunkName: \"not-a-valid-chunk\" */ 'server/renderer');\n const renderer = ssrFactory(this.global.webpackConfig!, options);\n let status = 200; // OK\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n this.ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\n },\n } as unknown) as Response,\n\n (error) => {\n // TODO: Strictly speaking, that error as Error casting is not all\n // correct, but it works, so no need to spend time on it right now.\n if (error) fail(error as Error);\n else done('');\n },\n );\n });\n\n this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n\n if (cleanup) cleanup();\n }\n\n constructor(\n config: JestEnvironmentConfig,\n context: EnvironmentContext,\n ) {\n const pragmas = context.docblockPragmas;\n\n const requestString = pragmas['ssr-request'] as string;\n const request = requestString\n ? JSON.parse(requestString) as Record<string, unknown>\n : {};\n\n request.url ??= '/';\n request.csrfToken = noop;\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url as string}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n\n // The usual \"babel-jest\" transformation setup does not apply to\n // the environment code and imports from it, this workaround enables it.\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n let root;\n switch (options.root) {\n case 'TEST':\n root = this.testFolder;\n break;\n default: root = process.cwd();\n }\n\n // BEWARE: Anything imported prior to this register() call seems to be\n // transpiled again by Babel if loaded after this call. This causes very\n // confusing errors when testing the code dependent on some sort of contexts\n // (because loading a module again effectively creates a new context object,\n // which is not recognized by the code expecting another context instance).\n // That's why below we prefer dynamic imports for some React Utils methods.\n register({\n envName: options.babelEnv as string,\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],\n root,\n });\n }\n\n async setup(): Promise<void> {\n await super.setup();\n await this.runWebpack();\n\n // NOTE: It is possible that the Webpack run above, and the SSR run below\n // load different versions of the same module (CommonJS, and ES), and it may\n // cause very confusing problems (e.g. see:\n // https://github.com/birdofpreyru/react-utils/issues/413).\n // It seems we can't reset the cache of ES modules, and Jest's module reset\n // does not reset modules loaded in this enviroment module, and also only\n // replacing entire cache object by and empty {} seems to help (in contrast\n // to deleting all entries by their keys, as it is done within .teardown()\n // method below). Thus, for now we do this as a hotfix, and we also reset\n // build info to undefined, because ES module version not beeing reset\n // triggers an error on the subsequent test using the environment.\n // TODO: Look for a cleaner solution.\n require.cache = {};\n\n const { setBuildInfo } = await import(/* webpackChunkName: \"not-a-valid-chunk\" */'../isomorphy/buildInfo');\n setBuildInfo(undefined, true);\n\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown(): Promise<void> {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n await super.teardown();\n }\n}\n"],"mappings":"mJAAA;AACA;AACA;AACA;AACA;AACA,GAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA,MAAO,CAAAA,IAAI,KAAM,WAAW,CAI5B,OAASC,QAAQ,CAAEC,GAAG,KAAQ,WAAW,CAIzC;AACA;AACA,sDACA,MAAO,CAAAC,QAAQ,KAAM,qCAAqC,CAE1D,MAAO,CAAAC,QAAQ,KAAM,wBAAwB,CAC7C,OAASC,MAAM,CAAEC,kBAAkB,KAAQ,OAAO,CAClD,MAAO,CAAAC,OAAO,KAA8B,SAAS,CACrD,qDAOA,QAAS,CAAAC,IAAIA,CAAA,CAAG,CACd;AAAA,CAGF,cAAe,MAAM,CAAAC,SAAS,QAAS,CAAAL,QAAS,CAa9C;AACF;AACA;AACA,KACE,KAAc,CAAAM,iBAAiBA,CAAA,CAAG,CAChC,KAAM,CAAAC,aAAa,CAAG,IAAI,CAACC,OAAO,CAAC,wBAAwB,CAAW,CAEtE,KAAM,CAAAC,OAAO,CAAIF,aAAa,CAAGG,IAAI,CAACC,KAAK,CAACJ,aAAa,CAAC,CAAG,CAAC,CACvC,CAEvBV,QAAQ,CAACY,OAAO,CAAE,CAChBG,OAAO,CAAE,IAAI,CAACC,UAAU,CACxBC,EAAE,CAAE,IAAI,CAACC,MAAM,CAACC,eAClB,CAAC,CAAC,CAEF,KAAM,CAAAC,WAAW,CAAG,IAAI,CAACT,OAAO,CAAC,wBAAwB,CAAW,CAEpE,GAAI,CAAAU,OAAO,CAAG,KAAM,OAAM,CAAC,2CACzBtB,IAAI,CAACuB,OAAO,CAAC,IAAI,CAACC,OAAO,CAAEH,WAAW,CACxC,CAEE,CAEFC,OAAO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,KAAK,CAAC,CAAC,CACnB,KAAM,KAAI,CAAC5D,UAAU,CAAC,CAAC,CAEvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA6D,OAAO,CAACC,KAAK,CAAG,CAAC,CAAC,CAElB,KAAM,CAAEC,YAAa,CAAC,CAAG,KAAM,OAAM,CAAC,mEAAmE,CAAC,CAC1GA,YAAY,CAACC,SAAS,CAAE,IAAI,CAAC,CAE7B,GAAI,IAAI,CAACX,OAAO,CAAE,KAAM,KAAI,CAACrC,MAAM,CAAC,CAAC,CACrC,IAAI,CAAC3B,MAAM,CAAC4E,6BAA6B,CAAG,IAC9C,CAEA,KAAM,CAAAC,QAAQA,CAAA,CAAkB,CAC9B,MAAO,KAAI,CAAC7E,MAAM,CAAC4E,6BAA6B,CAEhD;AACA;AACA;AACA;AACA;AACA;AACAE,MAAM,CAACC,IAAI,CAACP,OAAO,CAACC,KAAK,CAAC,CAACO,OAAO,CAAEC,GAAG,EAAK,CAC1C,MAAO,CAAAT,OAAO,CAACC,KAAK,CAACQ,GAAG,CAC1B,CAAC,CAAC,CACFjG,QAAQ,CAACkG,MAAM,CAAC,CAAC,CACjB,KAAM,MAAK,CAACL,QAAQ,CAAC,CACvB,CACF","ignoreList":[]}
@@ -1,4 +1,4 @@
1
1
  export { type AsyncCollectionT, type AsyncCollectionLoaderT, type AsyncDataEnvelopeT, type AsyncDataLoaderT, type ForceT, type UseAsyncDataOptionsT, type UseAsyncDataResT, type UseGlobalStateResT, type ValueOrInitializerT, getGlobalState, GlobalStateProvider, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, withGlobalStateType, } from '@dr.pogodin/react-global-state';
2
2
  export * from './shared/components';
3
3
  export { type BeforeRenderResT, type BeforeRenderT, type ConfigT, type ServerSsrContext, type ServerT, } from './server';
4
- export { assertEmptyObject, Barrier, Cached, Emitter, getConfig, isomorphy, getSsrContext, type Listener, type ObjectKey, Semaphore, splitComponent, type Theme, themed, ThemeProvider, time, webpack, withRetries, } from './shared/utils';
4
+ export { assertEmptyObject, Barrier, Cached, Emitter, getConfig, isomorphy, getSsrContext, type Listener, type ObjectKey, Semaphore, splitComponent, type Theme, THEME_COMPOSE, THEME_PRIORITY, ThemeProvider, time, useTheme, webpack, withRetries, } from './shared/utils';
@@ -1,5 +1,6 @@
1
1
  import type { FunctionComponent, KeyboardEventHandler, MouseEventHandler, PointerEventHandler, ReactNode } from 'react';
2
2
  import { type Theme } from '@dr.pogodin/react-themes';
3
+ type ThemeT = Theme<'active' | 'button' | 'disabled'>;
3
4
  type PropsT = {
4
5
  active?: boolean;
5
6
  children?: ReactNode;
@@ -15,16 +16,11 @@ type PropsT = {
15
16
  openNewTab?: boolean;
16
17
  replace?: boolean;
17
18
  testId?: string;
18
- theme: Theme<'active' | 'button' | 'disabled'>;
19
+ theme: ThemeT;
19
20
  to?: object | string;
20
21
  };
21
22
  export declare const BaseButton: FunctionComponent<PropsT>;
22
- /**
23
- * Button component theme: a map of CSS
24
- * class names to append to button elements:
25
- * @prop {string} [active] to the root element of active button.
26
- * @prop {string} [button] to the root element of any button.
27
- * @prop {string} [disabled] to the root element of disabled button.
28
- */
29
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<PropsT>;
30
- export default _default;
23
+ declare const Button: FunctionComponent<Omit<PropsT, 'theme'> & {
24
+ theme?: ThemeT;
25
+ }>;
26
+ export default Button;
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from 'react';
1
2
  import { type Theme } from '@dr.pogodin/react-themes';
2
3
  type PropT<ValueT> = {
3
4
  checked?: ValueT;
@@ -5,7 +6,7 @@ type PropT<ValueT> = {
5
6
  label?: React.ReactNode;
6
7
  onChange?: React.ChangeEventHandler<HTMLInputElement>;
7
8
  testId?: string;
8
- theme: Theme<'checkbox' | 'container' | 'disabled' | 'indeterminate' | 'label'>;
9
+ theme?: Theme<'checkbox' | 'container' | 'disabled' | 'indeterminate' | 'label'>;
9
10
  };
10
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<PropT<boolean | "indeterminate">>;
11
- export default _default;
11
+ declare const Checkbox: <ValueT extends boolean | "indeterminate" = boolean>({ checked, disabled, label, onChange, testId, theme, }: PropT<ValueT>) => ReactNode;
12
+ export default Checkbox;
@@ -1,4 +1,4 @@
1
- import { type ReactNode, type Ref } from 'react';
1
+ import { type FunctionComponent, type ReactNode, type Ref } from 'react';
2
2
  import { type Theme } from '@dr.pogodin/react-themes';
3
3
  type ThemeKeyT = 'children' | 'container' | 'empty' | 'error' | 'errorMessage' | 'focused' | 'input' | 'label';
4
4
  type PropsT = React.InputHTMLAttributes<HTMLInputElement> & {
@@ -7,7 +7,15 @@ type PropsT = React.InputHTMLAttributes<HTMLInputElement> & {
7
7
  label?: React.ReactNode;
8
8
  ref?: Ref<HTMLInputElement>;
9
9
  testId?: string;
10
- theme: Theme<ThemeKeyT>;
10
+ theme?: Theme<ThemeKeyT>;
11
11
  };
12
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<PropsT>;
13
- export default _default;
12
+ /**
13
+ * Themeable input field, based on the standard HTML `<input>` element.
14
+ * @param [props.label] Input label.
15
+ * @param [props.theme] _Ad hoc_ theme.
16
+ * @param [props...] [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
17
+ * @param [props...] Any other properties are passed to the underlying
18
+ * `<input>` element.
19
+ */
20
+ declare const Input: FunctionComponent<PropsT>;
21
+ export default Input;
@@ -1,5 +1,6 @@
1
1
  import { type CSSProperties, type FunctionComponent, type ReactNode } from 'react';
2
2
  import { type Theme } from '@dr.pogodin/react-themes';
3
+ type ThemeT = Theme<'container' | 'overlay'>;
3
4
  type PropsT = {
4
5
  cancelOnScrolling?: boolean;
5
6
  children?: ReactNode;
@@ -9,7 +10,7 @@ type PropsT = {
9
10
  style?: CSSProperties;
10
11
  testId?: string;
11
12
  testIdForOverlay?: string;
12
- theme: Theme<'container' | 'overlay'>;
13
+ theme: ThemeT;
13
14
  /** @deprecated */
14
15
  containerStyle?: CSSProperties;
15
16
  };
@@ -25,6 +26,8 @@ type PropsT = {
25
26
  * @param {ModalTheme} [props.theme] _Ad hoc_ theme.
26
27
  */
27
28
  declare const BaseModal: FunctionComponent<PropsT>;
28
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<PropsT>;
29
- export default _default;
30
29
  export { BaseModal };
30
+ declare const Modal: FunctionComponent<Omit<PropsT, 'theme'> & {
31
+ theme?: ThemeT;
32
+ }>;
33
+ export default Modal;
@@ -1,11 +1,26 @@
1
- import type { ReactNode } from 'react';
1
+ import type { FunctionComponent, ReactNode } from 'react';
2
2
  import { type Theme } from '@dr.pogodin/react-themes';
3
3
  type ThemeKeyT = 'container' | 'leftSidePanel' | 'mainPanel' | 'rightSidePanel' | 'sidePanel';
4
4
  type PropsT = {
5
5
  children?: ReactNode;
6
6
  leftSidePanelContent?: ReactNode;
7
7
  rightSidePanelContent?: ReactNode;
8
- theme: Theme<ThemeKeyT>;
8
+ theme?: Theme<ThemeKeyT>;
9
9
  };
10
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<PropsT>;
11
- export default _default;
10
+ /**
11
+ * Simple and themeable page layout. It keeps the main content centered in
12
+ * a column of limited width, which fills entire viewport on small screens
13
+ * (under `$screen-md = 1024px` size). At larger screens the column keeps
14
+ * `$screen-md` size, and it is centered at the page, surrounded by side
15
+ * panels, where additional content can be displayed.
16
+ *
17
+ * **Children:** Component children are rendered as the content of main panel.
18
+ * @param {object} [props] Component properties.
19
+ * @param {Node} [props.leftSidePanelContent] The content for left side panel.
20
+ * @param {Node} [props.rightSidePanelContent] The content for right side panel.
21
+ * @param {PageLayoutTheme} [props.theme] _Ad hoc_ theme.
22
+ * @param {...any} [props....]
23
+ * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
24
+ */
25
+ declare const PageLayout: FunctionComponent<PropsT>;
26
+ export default PageLayout;
@@ -1,4 +1,4 @@
1
- import { type ChangeEventHandler, type FocusEventHandler, type KeyboardEventHandler, type ReactNode } from 'react';
1
+ import { type ChangeEventHandler, type FocusEventHandler, type FunctionComponent, type KeyboardEventHandler, type ReactNode } from 'react';
2
2
  import { type Theme } from '@dr.pogodin/react-themes';
3
3
  type ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label' | 'textarea';
4
4
  type Props = {
@@ -10,8 +10,8 @@ type Props = {
10
10
  onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;
11
11
  placeholder?: string;
12
12
  testId?: string;
13
- theme: Theme<ThemeKeyT>;
13
+ theme?: Theme<ThemeKeyT>;
14
14
  value?: string;
15
15
  };
16
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<Props>;
17
- export default _default;
16
+ declare const TextArea: FunctionComponent<Props>;
17
+ export default TextArea;
@@ -1,7 +1,17 @@
1
+ import type { FunctionComponent } from 'react';
1
2
  import { type Theme } from '@dr.pogodin/react-themes';
2
3
  type ThemeKeyT = 'bouncing' | 'circle' | 'container';
3
4
  type PropsT = {
4
- theme: Theme<ThemeKeyT>;
5
+ theme?: Theme<ThemeKeyT>;
5
6
  };
6
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<PropsT>;
7
- export default _default;
7
+ /**
8
+ * Throbber is an "action in progress" indicator, which renders
9
+ * three bouncing circles as a simple pending activity indicator,
10
+ * and can be further themed to a certain degree.
11
+ * @param {object} [props] Component properties.
12
+ * @param {ThrobberTheme} [props.theme] _Ad hoc_ theme.
13
+ * @param {...any} [props....]
14
+ * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
15
+ */
16
+ declare const Throbber: FunctionComponent<PropsT>;
17
+ export default Throbber;
@@ -1,14 +1,28 @@
1
- import { type ReactNode } from 'react';
1
+ import { type FunctionComponent, type ReactNode } from 'react';
2
2
  import { type Theme } from '@dr.pogodin/react-themes';
3
3
  import { type ThemeKeysT as TooltipThemeKeysT, PLACEMENTS } from './Tooltip';
4
4
  type PropsT = {
5
5
  children?: ReactNode;
6
6
  placement?: PLACEMENTS;
7
7
  tip?: ReactNode;
8
- theme: Theme<'wrapper' | TooltipThemeKeysT>;
8
+ theme?: Theme<'wrapper' | TooltipThemeKeysT>;
9
9
  };
10
- declare const ThemedWrapper: import("@dr.pogodin/react-themes").ThemedComponent<PropsT>;
11
- type ExportT = typeof ThemedWrapper & {
10
+ /**
11
+ * Implements a simple to use and themeable tooltip component, _e.g._
12
+ * ```js
13
+ * <WithTooltip tip="This is example tooltip.">
14
+ * <p>Hover to see the tooltip.</p>
15
+ * </WithTooltip>
16
+ * ```
17
+ * **Children:** Children are rendered in the place of `<WithTooltip>`,
18
+ * and when hovered the tooltip is shown. By default the wrapper itself is
19
+ * `<div>` block with `display: inline-block`.
20
+ * @param tip &ndash; Anything React is able to render,
21
+ * _e.g._ a tooltip text. This will be the tooltip content.
22
+ * @param {WithTooltipTheme} props.theme _Ad hoc_ theme.
23
+ */
24
+ declare const WithTooltip: FunctionComponent<PropsT>;
25
+ type ExportT = typeof WithTooltip & {
12
26
  PLACEMENTS: typeof PLACEMENTS;
13
27
  };
14
28
  declare const e: ExportT;
@@ -1,10 +1,26 @@
1
+ import type { FunctionComponent } from 'react';
1
2
  import { type Theme } from '@dr.pogodin/react-themes';
2
- type ComponentThemeT = Theme<'container' | 'video'>;
3
+ type ThemeT = Theme<'container' | 'video'>;
3
4
  type PropsT = {
4
5
  autoplay?: boolean;
5
6
  src: string;
6
- theme: ComponentThemeT;
7
+ theme?: ThemeT;
7
8
  title?: string;
8
9
  };
9
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<PropsT>;
10
- export default _default;
10
+ /**
11
+ * A component for embeding a YouTube video.
12
+ * @param [props] Component properties.
13
+ * @param [props.autoplay] If `true` the video will start to play
14
+ * automatically once loaded.
15
+ * @param [props.src] URL of the video to play. Can be in any of
16
+ * the following formats, and keeps any additional query parameters understood
17
+ * by the YouTube IFrame player:
18
+ * - `https://www.youtube.com/watch?v=NdF6Rmt6Ado`
19
+ * - `https://youtu.be/NdF6Rmt6Ado`
20
+ * - `https://www.youtube.com/embed/NdF6Rmt6Ado`
21
+ * @param [props.theme] _Ad hoc_ theme.
22
+ * @param [props.title] The `title` attribute to add to the player
23
+ * IFrame.
24
+ */
25
+ declare const YouTubeVideo: FunctionComponent<PropsT>;
26
+ export default YouTubeVideo;
@@ -1,3 +1,4 @@
1
+ import { type FunctionComponent, type ReactNode } from 'react';
1
2
  import { type PropsT, type ValueT } from '../common';
2
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<PropsT<import("react").ReactNode, (value: ValueT) => void>>;
3
- export default _default;
3
+ declare const CustomDropdown: FunctionComponent<PropsT<ReactNode, (value: ValueT) => void>>;
4
+ export default CustomDropdown;
@@ -1,3 +1,23 @@
1
+ import type { FunctionComponent } from 'react';
1
2
  import { type PropsT } from '../common';
2
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<PropsT<string>>;
3
- export default _default;
3
+ /**
4
+ * Implements a themeable dropdown list. Internally it is rendered with help of
5
+ * the standard HTML `<select>` element, thus the styling support is somewhat
6
+ * limited.
7
+ * @param [props] Component properties.
8
+ * @param [props.filter] Options filter function. If provided, only
9
+ * those elements of `options` list will be used by the dropdown, for which this
10
+ * filter returns `true`.
11
+ * @param [props.label] Dropdown label.
12
+ * @param [props.onChange] Selection event handler.
13
+ * @param [props.options=[]] Array of dropdown
14
+ * options. For string elements the option value and name will be the same.
15
+ * It is allowed to mix DropdownOption and string elements in the same option
16
+ * list.
17
+ * @param [props.theme] _Ad hoc_ theme.
18
+ * @param [props.value] Currently selected value.
19
+ * @param [props....]
20
+ * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
21
+ */
22
+ declare const Dropdown: FunctionComponent<PropsT<string>>;
23
+ export default Dropdown;
@@ -1,12 +1,13 @@
1
+ import type { FunctionComponent, ReactNode } from 'react';
1
2
  import { type Theme } from '@dr.pogodin/react-themes';
2
3
  import { type OptionsT, type ValueT } from '../common';
3
- type ThemeKeyT = 'container' | 'label' | 'option' | 'options' | 'selected';
4
+ type ThemeT = Theme<'container' | 'label' | 'option' | 'options' | 'selected'>;
4
5
  type PropsT = {
5
- label?: React.ReactNode;
6
+ label?: ReactNode;
6
7
  onChange?: (value: ValueT) => void;
7
- options?: Readonly<OptionsT<React.ReactNode>>;
8
- theme: Theme<ThemeKeyT>;
8
+ options?: Readonly<OptionsT<ReactNode>>;
9
+ theme?: ThemeT;
9
10
  value?: ValueT;
10
11
  };
11
- declare const _default: import("@dr.pogodin/react-themes").ThemedComponent<PropsT>;
12
- export default _default;
12
+ export declare const Switch: FunctionComponent<PropsT>;
13
+ export {};
@@ -1,5 +1,5 @@
1
1
  import type { Theme } from '@dr.pogodin/react-themes';
2
- type ThemeKeyT = 'active' | 'arrow' | 'container' | 'dropdown' | 'hiddenOption' | 'label' | 'option' | 'select' | 'invalid' | 'upward';
2
+ export type ThemeT = Theme<'active' | 'arrow' | 'container' | 'dropdown' | 'hiddenOption' | 'label' | 'option' | 'select' | 'invalid' | 'upward'>;
3
3
  export type ValueT = number | string;
4
4
  export type OptionT<NameT> = {
5
5
  name?: NameT | null;
@@ -12,9 +12,8 @@ export type PropsT<NameT, OnChangeT = React.ChangeEventHandler<HTMLSelectElement
12
12
  onChange?: OnChangeT;
13
13
  options: Readonly<OptionsT<NameT>>;
14
14
  testId?: string;
15
- theme: Theme<ThemeKeyT>;
15
+ theme?: ThemeT;
16
16
  value?: ValueT;
17
17
  };
18
18
  /** Returns option value and name as a tuple. */
19
19
  export declare function optionValueName<NameT>(option: OptionT<NameT> | ValueT): [ValueT, NameT | ValueT];
20
- export {};
@@ -1,4 +1,4 @@
1
1
  export { default as CustomDropdown } from './CustomDropdown';
2
2
  export { default as Dropdown } from './NativeDropdown';
3
- export { default as Switch } from './Switch';
4
- export { type OptionT, type OptionsT, } from './common';
3
+ export { Switch } from './Switch';
4
+ export type { OptionT, OptionsT } from './common';
@@ -1,14 +1,9 @@
1
- import themedImpl, { COMPOSE, PRIORITY, type Theme, ThemeProvider } from '@dr.pogodin/react-themes';
2
1
  import { getConfig } from './config';
3
2
  import * as isomorphy from './isomorphy';
4
3
  import time from './time';
5
4
  import * as webpack from './webpack';
6
5
  export { assertEmptyObject, type Listener, type ObjectKey, Barrier, Cached, Emitter, Semaphore, withRetries, } from '@dr.pogodin/js-utils';
6
+ export { COMPOSE as THEME_COMPOSE, PRIORITY as THEME_PRIORITY, type Theme, ThemeProvider, useTheme, } from '@dr.pogodin/react-themes';
7
7
  export { getSsrContext } from './globalState';
8
8
  export { default as splitComponent } from './splitComponent';
9
- type ThemedT = typeof themedImpl & {
10
- COMPOSE: typeof COMPOSE;
11
- PRIORITY: typeof PRIORITY;
12
- };
13
- declare const themed: ThemedT;
14
- export { type Theme, getConfig, isomorphy, themed, ThemeProvider, time, webpack, };
9
+ export { getConfig, isomorphy, time, webpack, };
@@ -7,5 +7,5 @@ if (global.REACT_UTILS_LIBRARY_LOADED) {
7
7
  } else global.REACT_UTILS_LIBRARY_LOADED = true;
8
8
  export { getGlobalState, GlobalStateProvider, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, withGlobalStateType } from '@dr.pogodin/react-global-state';
9
9
  export * from "./shared/components";
10
- export { assertEmptyObject, Barrier, Cached, Emitter, getConfig, isomorphy, getSsrContext, Semaphore, splitComponent, themed, ThemeProvider, time, webpack, withRetries } from "./shared/utils";
10
+ export { assertEmptyObject, Barrier, Cached, Emitter, getConfig, isomorphy, getSsrContext, Semaphore, splitComponent, THEME_COMPOSE, THEME_PRIORITY, ThemeProvider, time, useTheme, webpack, withRetries } from "./shared/utils";
11
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["global","REACT_UTILS_LIBRARY_LOADED","Error","getGlobalState","GlobalStateProvider","newAsyncDataEnvelope","useAsyncCollection","useAsyncData","useGlobalState","withGlobalStateType","assertEmptyObject","Barrier","Cached","Emitter","getConfig","isomorphy","getSsrContext","Semaphore","splitComponent","themed","ThemeProvider","time","webpack","withRetries"],"sources":["../../src/index.ts"],"sourcesContent":["// It is a safeguard against multiple instances / versions of the library\n// being loaded into environment by mistake (e.g. because of different\n// packages pinning down different exact versions of the lib, thus preventing\n// a proper dedupe and using a single common library version).\nif (global.REACT_UTILS_LIBRARY_LOADED) {\n throw Error('React utils library is already loaded');\n} else global.REACT_UTILS_LIBRARY_LOADED = true;\n\nexport {\n type AsyncCollectionT,\n type AsyncCollectionLoaderT,\n type AsyncDataEnvelopeT,\n type AsyncDataLoaderT,\n type ForceT,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n type UseGlobalStateResT,\n type ValueOrInitializerT,\n getGlobalState,\n GlobalStateProvider,\n newAsyncDataEnvelope,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\n withGlobalStateType,\n} from '@dr.pogodin/react-global-state';\n\nexport * from 'components';\n\nexport {\n type BeforeRenderResT,\n type BeforeRenderT,\n type ConfigT,\n type ServerSsrContext,\n type ServerT,\n} from './server';\n\nexport {\n assertEmptyObject,\n Barrier,\n Cached,\n Emitter,\n getConfig,\n isomorphy,\n getSsrContext,\n type Listener,\n type ObjectKey,\n Semaphore,\n splitComponent,\n type Theme,\n themed,\n ThemeProvider,\n time,\n webpack,\n withRetries,\n} from 'utils';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,IAAIA,MAAM,CAACC,0BAA0B,EAAE;EACrC,MAAMC,KAAK,CAAC,uCAAuC,CAAC;AACtD,CAAC,MAAMF,MAAM,CAACC,0BAA0B,GAAG,IAAI;AAE/C,SAUEE,cAAc,EACdC,mBAAmB,EACnBC,oBAAoB,EACpBC,kBAAkB,EAClBC,YAAY,EACZC,cAAc,EACdC,mBAAmB,QACd,gCAAgC;AAEvC;AAUA,SACEC,iBAAiB,EACjBC,OAAO,EACPC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,SAAS,EACTC,aAAa,EAGbC,SAAS,EACTC,cAAc,EAEdC,MAAM,EACNC,aAAa,EACbC,IAAI,EACJC,OAAO,EACPC,WAAW","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["global","REACT_UTILS_LIBRARY_LOADED","Error","getGlobalState","GlobalStateProvider","newAsyncDataEnvelope","useAsyncCollection","useAsyncData","useGlobalState","withGlobalStateType","assertEmptyObject","Barrier","Cached","Emitter","getConfig","isomorphy","getSsrContext","Semaphore","splitComponent","THEME_COMPOSE","THEME_PRIORITY","ThemeProvider","time","useTheme","webpack","withRetries"],"sources":["../../src/index.ts"],"sourcesContent":["// It is a safeguard against multiple instances / versions of the library\n// being loaded into environment by mistake (e.g. because of different\n// packages pinning down different exact versions of the lib, thus preventing\n// a proper dedupe and using a single common library version).\nif (global.REACT_UTILS_LIBRARY_LOADED) {\n throw Error('React utils library is already loaded');\n} else global.REACT_UTILS_LIBRARY_LOADED = true;\n\nexport {\n type AsyncCollectionT,\n type AsyncCollectionLoaderT,\n type AsyncDataEnvelopeT,\n type AsyncDataLoaderT,\n type ForceT,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n type UseGlobalStateResT,\n type ValueOrInitializerT,\n getGlobalState,\n GlobalStateProvider,\n newAsyncDataEnvelope,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\n withGlobalStateType,\n} from '@dr.pogodin/react-global-state';\n\nexport * from 'components';\n\nexport {\n type BeforeRenderResT,\n type BeforeRenderT,\n type ConfigT,\n type ServerSsrContext,\n type ServerT,\n} from './server';\n\nexport {\n assertEmptyObject,\n Barrier,\n Cached,\n Emitter,\n getConfig,\n isomorphy,\n getSsrContext,\n type Listener,\n type ObjectKey,\n Semaphore,\n splitComponent,\n type Theme,\n THEME_COMPOSE,\n THEME_PRIORITY,\n ThemeProvider,\n time,\n useTheme,\n webpack,\n withRetries,\n} from 'utils';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,IAAIA,MAAM,CAACC,0BAA0B,EAAE;EACrC,MAAMC,KAAK,CAAC,uCAAuC,CAAC;AACtD,CAAC,MAAMF,MAAM,CAACC,0BAA0B,GAAG,IAAI;AAE/C,SAUEE,cAAc,EACdC,mBAAmB,EACnBC,oBAAoB,EACpBC,kBAAkB,EAClBC,YAAY,EACZC,cAAc,EACdC,mBAAmB,QACd,gCAAgC;AAEvC;AAUA,SACEC,iBAAiB,EACjBC,OAAO,EACPC,MAAM,EACNC,OAAO,EACPC,SAAS,EACTC,SAAS,EACTC,aAAa,EAGbC,SAAS,EACTC,cAAc,EAEdC,aAAa,EACbC,cAAc,EACdC,aAAa,EACbC,IAAI,EACJC,QAAQ,EACRC,OAAO,EACPC,WAAW","ignoreList":[]}
@@ -176,7 +176,6 @@ export default async function factory(webpackConfig, options) {
176
176
  default: webpackHotMiddleware
177
177
  } = await import(/* webpackChunkName: "server-side-code" */'webpack-hot-middleware');
178
178
  const compiler = webpack(webpackConfig);
179
- if (!compiler) throw Error('Internal error');
180
179
  server.use(webpackDevMiddleware(compiler, {
181
180
  publicPath,
182
181
  serverSideRender: true
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","names":["sep","pathToFileURL","cloneDeep","mapValues","pick","compression","cookieParser","csrf","express","favicon","helmet","loggerMiddleware","requestIp","v4","uuid","rendererFactory","CODES","ERRORS","getErrorForCode","newError","defaultCspSettings","directives","contentSecurityPolicy","getDefaultDirectives","array","filter","item","push","getDefaultCspSettings","factory","webpackConfig","options","rendererOps","renderer","publicPath","output","server","beforeExpressJsSetup","logger","httpsRedirect","use","req","res","next","schema","headers","url","host","originalUrl","redirect","crossOriginEmbedderPolicy","crossOriginOpenerPolicy","crossOriginResourcePolicy","noCsp","req2","nonce","cspNonce","cspSettings","cspSettingsHook","send","json","limit","urlencoded","extended","cookieSignatureSecret","mw","cookie","token","clientIp","FORMAT","stream","write","info","bind","get","static","path","setHeaders","set","devMode","global","location","href","process","cwd","default","webpack","webpackDevMiddleware","webpackHotMiddleware","compiler","Error","serverSideRender","onExpressJsSetup","NOT_FOUND","dontAttachDefaultErrorHandler","beforeExpressJsError","error","headersSent","status","INTERNAL_SERVER_ERROR","serverSide","log","toString","message","env","NODE_ENV"],"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 { cloneDeep, mapValues, pick } from 'lodash-es';\n\nimport compression from 'compression';\nimport cookieParser from 'cookie-parser';\nimport csrf from '@dr.pogodin/csurf';\n\nimport express, {\n type Express,\n type NextFunction,\n type Request,\n type Response,\n} from 'express';\n\nimport favicon from 'serve-favicon';\nimport helmet, { type HelmetOptions } from 'helmet';\nimport loggerMiddleware from 'morgan';\nimport requestIp from 'request-ip';\nimport { v4 as uuid } from 'uuid';\n\nimport type { Configuration } from 'webpack';\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) => boolean | Promise<boolean>;\n\n beforeExpressJsSetup?: (server: ServerT) => Promise<void> | void;\n cookieSignatureSecret?: string;\n cspSettingsHook?: (\n defaultOptions: CspOptionsT,\n req: Request,\n ) => CspOptionsT;\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 = uuid();\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({ cookie: true }));\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 { default: webpackHotMiddleware } = await import(\n /* webpackChunkName: \"server-side-code\" */ 'webpack-hot-middleware'\n );\n\n const compiler = webpack(webpackConfig);\n if (!compiler) throw Error('Internal error');\n\n server.use(webpackDevMiddleware(compiler, {\n publicPath,\n serverSideRender: true,\n }));\n server.use(webpackHotMiddleware(compiler));\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 const serverSide = status >= (CODES.INTERNAL_SERVER_ERROR as number);\n\n // Log server-side errors always, client-side at debug level only.\n options.logger!.log(serverSide ? 'error' : 'debug', error.toString());\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":";;;AAAA;AACA;AACA;;AAEA,SAASA,GAAG,QAAQ,WAAW;AAC/B,SAASC,aAAa,QAAQ,UAAU;AAExC,SAASC,SAAS,EAAEC,SAAS,EAAEC,IAAI,QAAQ,WAAW;AAEtD,OAAOC,WAAW,MAAM,aAAa;AACrC,OAAOC,YAAY,MAAM,eAAe;AACxC,OAAOC,IAAI,MAAM,mBAAmB;AAEpC,OAAOC,OAAO,MAKP,SAAS;AAEhB,OAAOC,OAAO,MAAM,eAAe;AACnC,OAAOC,MAAM,MAA8B,QAAQ;AACnD,OAAOC,gBAAgB,MAAM,QAAQ;AACrC,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,EAAE,IAAIC,IAAI,QAAQ,MAAM;AAIjC,OAAOC,eAAe;AAKtB,SACEC,KAAK,EACLC,MAAM,EACNC,eAAe,EACfC,QAAQ;;AAKV;;AAMA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG;EACzBC,UAAU,EAAElB,SAAS,CACnBO,MAAM,CAACY,qBAAqB,CAACC,oBAAoB,CAAC,CAAC;EAEnD;EACA;EACA;EACA;EACCC,KAAK,IAAMA,KAAK,CAAcC,MAAM,CAAEC,IAAY,IAAKA,IAAI,KAAK,QAAQ,CAC3E;AACF,CAAC;AACDN,kBAAkB,CAACC,UAAU,CAAC,WAAW,CAAC,GAAG,CAC3C,QAAQ;AAER;AACA;AACA,uBAAuB,CACxB;AAED;EACE,MAAMA,UAAU,GAAGD,kBAAkB,CAACC,UAAU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AAI,CAACxB,QAAQ,CAACF,MAAM,CAAC4E,SAAS,EAAE7E,KAAK,CAAC6E,SAAS,CAAC,CAAC;EACnD,CAAC,CAAC;EAEF,IAAIC,6BAA6B;EACjC,IAAI/D,OAAO,CAACgE,oBAAoB,EAAE;IAChCD,6BAA6B,GAAG,MAAM/D,OAAO,CAACgE,oBAAoB,CAAC3D,MAAM,CAAC;EAC5E;;EAEA;EACA,IAAI,CAAC0D,6BAA6B,EAAE;IAClC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA1D,MAAM,CAACI,GAAG,CAAC,CACTwD,KAEC,EACDvD,GAAY,EACZC,GAAa,EACbC,IAAkB,KACf;MACH;MACA;MACA,IAAID,GAAG,CAACuD,WAAW,EAAE;QACnBtD,IAAI,CAACqD,KAAK,CAAC;QACX;MACF;MAEA,MAAME,MAAM,GAAGF,KAAK,CAACE,MAAM,IAAIlF,KAAK,CAACmF,qBAAqB;MAC1D,MAAMC,UAAU,GAAGF,MAAM,IAAKlF,KAAK,CAACmF,qBAAgC;;MAEpE;MACApE,OAAO,CAACO,MAAM,CAAE+D,GAAG,CAACD,UAAU,GAAG,OAAO,GAAG,OAAO,EAAEJ,KAAK,CAACM,QAAQ,CAAC,CAAC,CAAC;MAErE,IAAIC,OAAO,GAAGP,KAAK,CAACO,OAAO,IAAIrF,eAAe,CAACgF,MAAM,CAAC;MACtD,IAAIE,UAAU,IAAIjB,OAAO,CAACqB,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;QACvDF,OAAO,GAAGtF,MAAM,CAACkF,qBAAqB;MACxC;MAEAzD,GAAG,CAACwD,MAAM,CAACA,MAAM,CAAC,CAACvC,IAAI,CAAC4C,OAAO,CAAC;IAClC,CAAC,CAAC;EACJ;EAEA,OAAOnE,MAAM;AACf","ignoreList":[]}
1
+ {"version":3,"file":"server.js","names":["sep","pathToFileURL","cloneDeep","mapValues","pick","compression","cookieParser","csrf","express","favicon","helmet","loggerMiddleware","requestIp","v4","uuid","rendererFactory","CODES","ERRORS","getErrorForCode","newError","defaultCspSettings","directives","contentSecurityPolicy","getDefaultDirectives","array","filter","item","push","getDefaultCspSettings","factory","webpackConfig","options","rendererOps","renderer","publicPath","output","server","beforeExpressJsSetup","logger","httpsRedirect","use","req","res","next","schema","headers","url","host","originalUrl","redirect","crossOriginEmbedderPolicy","crossOriginOpenerPolicy","crossOriginResourcePolicy","noCsp","req2","nonce","cspNonce","cspSettings","cspSettingsHook","send","json","limit","urlencoded","extended","cookieSignatureSecret","mw","cookie","token","clientIp","FORMAT","stream","write","info","bind","get","static","path","setHeaders","set","devMode","global","location","href","process","cwd","default","webpack","webpackDevMiddleware","webpackHotMiddleware","compiler","serverSideRender","onExpressJsSetup","NOT_FOUND","dontAttachDefaultErrorHandler","beforeExpressJsError","error","headersSent","status","INTERNAL_SERVER_ERROR","serverSide","log","toString","message","env","NODE_ENV"],"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 { cloneDeep, mapValues, pick } from 'lodash-es';\n\nimport compression from 'compression';\nimport cookieParser from 'cookie-parser';\nimport csrf from '@dr.pogodin/csurf';\n\nimport express, {\n type Express,\n type NextFunction,\n type Request,\n type Response,\n} from 'express';\n\nimport favicon from 'serve-favicon';\nimport helmet, { type HelmetOptions } from 'helmet';\nimport loggerMiddleware from 'morgan';\nimport requestIp from 'request-ip';\nimport { v4 as uuid } from 'uuid';\n\nimport type { Configuration } from 'webpack';\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) => boolean | Promise<boolean>;\n\n beforeExpressJsSetup?: (server: ServerT) => Promise<void> | void;\n cookieSignatureSecret?: string;\n cspSettingsHook?: (\n defaultOptions: CspOptionsT,\n req: Request,\n ) => CspOptionsT;\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 = uuid();\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({ cookie: true }));\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 { default: webpackHotMiddleware } = await import(\n /* webpackChunkName: \"server-side-code\" */ 'webpack-hot-middleware'\n );\n\n const compiler = webpack(webpackConfig);\n\n server.use(webpackDevMiddleware(compiler, {\n publicPath,\n serverSideRender: true,\n }));\n server.use(webpackHotMiddleware(compiler));\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 const serverSide = status >= (CODES.INTERNAL_SERVER_ERROR as number);\n\n // Log server-side errors always, client-side at debug level only.\n options.logger!.log(serverSide ? 'error' : 'debug', error.toString());\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":";;;AAAA;AACA;AACA;;AAEA,SAASA,GAAG,QAAQ,WAAW;AAC/B,SAASC,aAAa,QAAQ,UAAU;AAExC,SAASC,SAAS,EAAEC,SAAS,EAAEC,IAAI,QAAQ,WAAW;AAEtD,OAAOC,WAAW,MAAM,aAAa;AACrC,OAAOC,YAAY,MAAM,eAAe;AACxC,OAAOC,IAAI,MAAM,mBAAmB;AAEpC,OAAOC,OAAO,MAKP,SAAS;AAEhB,OAAOC,OAAO,MAAM,eAAe;AACnC,OAAOC,MAAM,MAA8B,QAAQ;AACnD,OAAOC,gBAAgB,MAAM,QAAQ;AACrC,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,EAAE,IAAIC,IAAI,QAAQ,MAAM;AAIjC,OA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C+E,MAAM,CAAC;MACtD,IAAIE,UAAU,IAAIhB,OAAO,CAACoB,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;QACvDF,OAAO,GAAGrF,MAAM,CAACiF,qBAAqB;MACxC;MAEAxD,GAAG,CAACuD,MAAM,CAACA,MAAM,CAAC,CAACtC,IAAI,CAAC2C,OAAO,CAAC;IAClC,CAAC,CAAC;EACJ;EAEA,OAAOlE,MAAM;AACf","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  // The <Button> component implements a standard button / button-like link.
2
2
 
3
- import themed from '@dr.pogodin/react-themes';
3
+ import { useTheme } from '@dr.pogodin/react-themes';
4
4
  import Link from "../Link";
5
5
  import defaultTheme from "./style.scss";
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -78,13 +78,17 @@ export const BaseButton = ({
78
78
  children: children
79
79
  });
80
80
  };
81
+ const Button = ({
82
+ theme,
83
+ ...rest
84
+ }) => {
85
+ const composed = useTheme('Button', defaultTheme, theme);
81
86
 
82
- /**
83
- * Button component theme: a map of CSS
84
- * class names to append to button elements:
85
- * @prop {string} [active] to the root element of active button.
86
- * @prop {string} [button] to the root element of any button.
87
- * @prop {string} [disabled] to the root element of disabled button.
88
- */
89
- export default /* #__PURE__ */themed(BaseButton, 'Button', defaultTheme);
87
+ // eslint-disable-next-line react/jsx-props-no-spreading
88
+ return /*#__PURE__*/_jsx(BaseButton, {
89
+ ...rest,
90
+ theme: composed
91
+ });
92
+ };
93
+ export default Button;
90
94
  //# sourceMappingURL=index.js.map