@dr.pogodin/react-utils 1.58.0 → 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.
- package/build/development/client/getInj.js +17 -2
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/server/Cache.js +35 -3
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/renderer.js +53 -7
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +8 -6
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +11 -11
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/modules.js +35 -1
- package/build/development/server/utils/modules.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +5 -2
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +3 -0
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +5 -2
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +2 -2
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv/index.js +10 -10
- package/build/development/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +3 -3
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +77 -3
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/webpack.js +3 -1
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js +1 -1
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/server/Cache.js +1 -1
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/renderer.js +4 -4
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +4 -4
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +2 -2
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/server/utils/modules.js +1 -1
- package/build/production/server/utils/modules.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +2 -2
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv/index.js +3 -3
- package/build/production/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
- package/build/production/shared/utils/jest/index.js +3 -3
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +3 -3
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/webpack.js +1 -1
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/web/client/getInj.js +1 -1
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/server/Cache.js +1 -1
- package/build/web/server/Cache.js.map +1 -1
- package/build/web/server/renderer.js +4 -4
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +4 -4
- package/build/web/server/server.js.map +1 -1
- package/build/web/server/utils/errors.js +2 -2
- package/build/web/server/utils/errors.js.map +1 -1
- package/build/web/server/utils/modules.js +1 -1
- package/build/web/server/utils/modules.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js +2 -2
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +1 -1
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv/index.js +3 -3
- package/build/web/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
- package/build/web/shared/utils/jest/index.js +3 -3
- package/build/web/shared/utils/jest/index.js.map +1 -1
- package/build/web/shared/utils/splitComponent.js +3 -3
- package/build/web/shared/utils/splitComponent.js.map +1 -1
- package/build/web/shared/utils/webpack.js +1 -1
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/webpack.js +11 -2
- package/package.json +5 -5
|
@@ -1,4 +1,38 @@
|
|
|
1
|
-
|
|
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":"
|
|
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;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,QA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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":[]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
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";
|
|
2
5
|
import { c as _c } from "react/compiler-runtime";
|
|
3
6
|
import { useImperativeHandle, useRef } from "react";
|
|
4
7
|
import { BaseModal } from "../../../Modal/index.js";
|
|
@@ -57,7 +60,7 @@ const Options = t0 => {
|
|
|
57
60
|
for (const option of options) {
|
|
58
61
|
if (!filter || filter(option)) {
|
|
59
62
|
const [iValue, iName] = optionValueName(option);
|
|
60
|
-
|
|
63
|
+
optionNodes.push(/*#__PURE__*/_jsx("div", {
|
|
61
64
|
className: optionClass,
|
|
62
65
|
onClick: e_0 => {
|
|
63
66
|
onChange(iValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nimport S from './style.scss';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<ReactNode> | ValueT) => boolean;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n optionClass: string;\n options: Readonly<OptionsT<ReactNode>>;\n ref?: RefObject<RefT | null>;\n};\n\nconst Options: FunctionComponent<PropsT> = ({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n ref,\n}) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n if (!opsRef.current) throw Error('Missing reference');\n const rect = opsRef.current.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: ReactNode[] = [];\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n key={iValue}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n dontDisableScrolling\n onCancel={onCancel}\n style={containerStyle}\n theme={{\n ad: '',\n container: containerClass,\n context: '',\n hoc: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n};\n\nexport default Options;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../../src/shared/components/selectors/CustomDropdown/Options/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n useImperativeHandle,\n useRef,\n} from 'react';\n\nimport { BaseModal } from 'components/Modal';\n\nimport {\n type OptionT,\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../../common';\n\nimport S from './style.scss';\n\nexport type ContainerPosT = {\n left: number;\n top: number;\n width: number;\n};\n\nexport function areEqual(a?: ContainerPosT, b?: ContainerPosT): boolean {\n return a?.left === b?.left && a?.top === b?.top && a?.width === b?.width;\n}\n\nexport type RefT = {\n measure: () => DOMRect | undefined;\n};\n\ntype PropsT = {\n containerClass: string;\n containerStyle?: ContainerPosT;\n filter?: (item: OptionT<ReactNode> | ValueT) => boolean;\n onCancel: () => void;\n onChange: (value: ValueT) => void;\n optionClass: string;\n options: Readonly<OptionsT<ReactNode>>;\n ref?: RefObject<RefT | null>;\n};\n\nconst Options: FunctionComponent<PropsT> = ({\n containerClass,\n containerStyle,\n filter,\n onCancel,\n onChange,\n optionClass,\n options,\n ref,\n}) => {\n const opsRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => ({\n measure: () => {\n const e = opsRef.current?.parentElement;\n if (!e) return undefined;\n\n if (!opsRef.current) throw Error('Missing reference');\n const rect = opsRef.current.getBoundingClientRect();\n const style = window.getComputedStyle(e);\n const mBottom = parseFloat(style.marginBottom);\n const mTop = parseFloat(style.marginTop);\n\n rect.height += mBottom + mTop;\n\n return rect;\n },\n }), []);\n\n const optionNodes: ReactNode[] = [];\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n optionNodes.push(\n <div\n className={optionClass}\n key={iValue}\n onClick={(e) => {\n onChange(iValue);\n e.stopPropagation();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onChange(iValue);\n e.stopPropagation();\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>,\n );\n }\n }\n\n return (\n <BaseModal\n // Closes the dropdown (cancels the selection) on any page scrolling attempt.\n // This is the same native <select> elements do on scrolling, and at least for\n // now we have no reason to deal with complications needed to support open\n // dropdowns during the scrolling (that would need to re-position it in\n // response to the position changes of the root dropdown element).\n cancelOnScrolling\n dontDisableScrolling\n onCancel={onCancel}\n style={containerStyle}\n theme={{\n ad: '',\n container: containerClass,\n context: '',\n hoc: '',\n overlay: S.overlay,\n }}\n >\n <div ref={opsRef}>{optionNodes}</div>\n </BaseModal>\n );\n};\n\nexport default Options;\n"],"mappings":";;;;;AAAA,SAIE,mBAAmB,EACnB,MAAM,QACD,OAAO;AAAC,SAEN,SAAS;AAAA,SAMhB,eAAe;AAGjB;EAAA;AAAA;AAA6B;AAQ7B,OAAO,SAAS,QAAQ,CAAC,CAAiB,EAAE,CAAiB,EAAW;EACtE,OAAO,CAAC,EAAE,IAAI,KAAK,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,KAAK;AAC1E;AAiBA,MAAM,OAAkC,GAAG;EAAA;EAAC;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAS3C;EACC,eAAe,MAAM,CAAiB,IAAI,CAAC;EAAC;EAAA;EAAA;IAEnB,YAAO;MAAA,SACrB;QACP,UAAU,MAAM,QAAuB;QACvC,IAAI,CAAC,CAAC;UAAA;QAAA;QAEN,IAAI,CAAC,MAAM,QAAQ;UAAE,MAAM,KAAK,CAAC,mBAAmB,CA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;IAlBvC,uBAAC,SAAS;MAMR,iBAAiB,EAAjB,IAAiB;MACjB,oBAAoB,EAApB,IAAoB;MACV,QAAQ,EAAR,QAAQ;MACX,KAAc,EAAd,cAAc;MACd,KAMN,EANM,EAMN;MAAA,UAED;IAAqC,CAC5B,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAnBZ,EAmBY;AAAA,CAEf;AAED,eAAe,OAAO","ignoreList":[]}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import "core-js/modules/es.iterator.filter.js";
|
|
2
|
+
import "core-js/modules/es.iterator.constructor.js";
|
|
3
|
+
import "core-js/modules/es.iterator.filter.js";
|
|
1
4
|
import { c as _c } from "react/compiler-runtime";
|
|
2
5
|
import { useEffect, useRef, useState } from "react";
|
|
3
6
|
import { useTheme } from "@dr.pogodin/react-themes";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, type ValueT, optionValueName } from '../common';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nconst CustomDropdown: FunctionComponent<\n PropsT<ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const custom = useTheme('CustomDropdown', defaultTheme, theme);\n\n const [active, setActive] = useState(false);\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const opsRef = useRef<RefT>(null);\n\n const [opsPos, setOpsPos] = useState<ContainerPosT>();\n const [upward, setUpward] = useState(false);\n\n useEffect(() => {\n if (!active) return undefined;\n\n let id: number;\n const cb = () => {\n const anchor = dropdownRef.current?.getBoundingClientRect();\n const opsRect = opsRef.current?.measure();\n if (anchor && opsRect) {\n const fitsDown = anchor.bottom + opsRect.height\n < (window.visualViewport?.height ?? 0);\n const fitsUp = anchor.top - opsRect.height > 0;\n\n const up = !fitsDown && fitsUp;\n setUpward(up);\n\n const pos = up ? {\n left: anchor.left,\n top: anchor.top - opsRect.height - 1,\n width: anchor.width,\n } : {\n left: anchor.left,\n top: anchor.bottom,\n width: anchor.width,\n };\n\n setOpsPos((now) => (areEqual(now, pos) ? now : pos));\n }\n id = requestAnimationFrame(cb);\n };\n requestAnimationFrame(cb);\n\n return () => {\n cancelAnimationFrame(id);\n };\n }, [active]);\n\n const openList = (\n e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,\n ) => {\n const view = window.visualViewport;\n if (!dropdownRef.current) throw Error('Missing dropdown reference');\n const rect = dropdownRef.current.getBoundingClientRect();\n setActive(true);\n\n // NOTE: This first opens the dropdown off-screen, where it is measured\n // by an effect declared above, and then positioned below, or above\n // the original dropdown element, depending where it fits best\n // (if we first open it downward, it would flick if we immediately\n // move it above, at least with the current position update via local\n // react state, and not imperatively).\n setOpsPos({\n left: view?.width ?? 0,\n top: view?.height ?? 0,\n width: rect.width,\n });\n\n e.stopPropagation();\n };\n\n let selected: React.ReactNode = <>‌</>;\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n if (iValue === value) {\n selected = iName;\n break;\n }\n }\n }\n\n let containerClassName = custom.container ?? '';\n if (active) containerClassName += ` ${custom.active ?? ''}`;\n\n let opsContainerClass = custom.select ?? '';\n if (upward) {\n containerClassName += ` ${custom.upward ?? ''}`;\n opsContainerClass += ` ${custom.upward ?? ''}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null\n : <div className={custom.label}>{label}</div>}\n <div\n className={custom.dropdown}\n onClick={openList}\n onKeyDown={(e) => {\n if (e.key === 'Enter') openList(e);\n }}\n ref={dropdownRef}\n role=\"listbox\"\n tabIndex={0}\n >\n {selected}\n <div className={custom.arrow} />\n </div>\n {\n active ? (\n <Options\n containerClass={opsContainerClass}\n containerStyle={opsPos}\n onCancel={() => {\n setActive(false);\n }}\n onChange={(newValue) => {\n setActive(false);\n if (onChange) onChange(newValue);\n }}\n optionClass={custom.option ?? ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nexport default CustomDropdown;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/CustomDropdown/index.tsx"],"sourcesContent":["import {\n type FunctionComponent,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, type ValueT, optionValueName } from '../common';\n\nimport Options, { type ContainerPosT, type RefT, areEqual } from './Options';\n\nimport defaultTheme from './theme.scss';\n\nconst CustomDropdown: FunctionComponent<\n PropsT<ReactNode, (value: ValueT) => void>\n> = ({\n filter,\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const custom = useTheme('CustomDropdown', defaultTheme, theme);\n\n const [active, setActive] = useState(false);\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const opsRef = useRef<RefT>(null);\n\n const [opsPos, setOpsPos] = useState<ContainerPosT>();\n const [upward, setUpward] = useState(false);\n\n useEffect(() => {\n if (!active) return undefined;\n\n let id: number;\n const cb = () => {\n const anchor = dropdownRef.current?.getBoundingClientRect();\n const opsRect = opsRef.current?.measure();\n if (anchor && opsRect) {\n const fitsDown = anchor.bottom + opsRect.height\n < (window.visualViewport?.height ?? 0);\n const fitsUp = anchor.top - opsRect.height > 0;\n\n const up = !fitsDown && fitsUp;\n setUpward(up);\n\n const pos = up ? {\n left: anchor.left,\n top: anchor.top - opsRect.height - 1,\n width: anchor.width,\n } : {\n left: anchor.left,\n top: anchor.bottom,\n width: anchor.width,\n };\n\n setOpsPos((now) => (areEqual(now, pos) ? now : pos));\n }\n id = requestAnimationFrame(cb);\n };\n requestAnimationFrame(cb);\n\n return () => {\n cancelAnimationFrame(id);\n };\n }, [active]);\n\n const openList = (\n e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>,\n ) => {\n const view = window.visualViewport;\n if (!dropdownRef.current) throw Error('Missing dropdown reference');\n const rect = dropdownRef.current.getBoundingClientRect();\n setActive(true);\n\n // NOTE: This first opens the dropdown off-screen, where it is measured\n // by an effect declared above, and then positioned below, or above\n // the original dropdown element, depending where it fits best\n // (if we first open it downward, it would flick if we immediately\n // move it above, at least with the current position update via local\n // react state, and not imperatively).\n setOpsPos({\n left: view?.width ?? 0,\n top: view?.height ?? 0,\n width: rect.width,\n });\n\n e.stopPropagation();\n };\n\n let selected: React.ReactNode = <>‌</>;\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n if (iValue === value) {\n selected = iName;\n break;\n }\n }\n }\n\n let containerClassName = custom.container ?? '';\n if (active) containerClassName += ` ${custom.active ?? ''}`;\n\n let opsContainerClass = custom.select ?? '';\n if (upward) {\n containerClassName += ` ${custom.upward ?? ''}`;\n opsContainerClass += ` ${custom.upward ?? ''}`;\n }\n\n return (\n <div className={containerClassName}>\n {label === undefined ? null\n : <div className={custom.label}>{label}</div>}\n <div\n className={custom.dropdown}\n onClick={openList}\n onKeyDown={(e) => {\n if (e.key === 'Enter') openList(e);\n }}\n ref={dropdownRef}\n role=\"listbox\"\n tabIndex={0}\n >\n {selected}\n <div className={custom.arrow} />\n </div>\n {\n active ? (\n <Options\n containerClass={opsContainerClass}\n containerStyle={opsPos}\n onCancel={() => {\n setActive(false);\n }}\n onChange={(newValue) => {\n setActive(false);\n if (onChange) onChange(newValue);\n }}\n optionClass={custom.option ?? ''}\n options={options}\n ref={opsRef}\n />\n ) : null\n }\n </div>\n );\n};\n\nexport default CustomDropdown;\n"],"mappings":";;;;AAAA,SAGE,SAAS,EACT,MAAM,EACN,QAAQ,QACH,OAAO;AAEd,SAAS,QAAQ,QAAQ,0BAA0B;AAAC,SAEjB,eAAe;AAA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;IAAA,CAEP,CAAC;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OAlCN,GAkCM;AAAA,CAET;AAED,eAAe,cAAc","ignoreList":[]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
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"; // Implements dropdown based on the native HTML <select> element.
|
|
2
5
|
import { useTheme } from "@dr.pogodin/react-themes";
|
|
3
6
|
import { optionValueName } from "../common.js";
|
|
4
7
|
const defaultTheme = {
|
|
@@ -52,7 +55,7 @@ const Dropdown = ({
|
|
|
52
55
|
if (!filter || filter(option)) {
|
|
53
56
|
const [iValue, iName] = optionValueName(option);
|
|
54
57
|
isValidValue ||= iValue === value;
|
|
55
|
-
|
|
58
|
+
optionElements.push(/*#__PURE__*/_jsx("option", {
|
|
56
59
|
className: composed.option,
|
|
57
60
|
value: iValue,
|
|
58
61
|
children: iName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/NativeDropdown/index.tsx"],"sourcesContent":["// Implements dropdown based on the native HTML <select> element.\n\nimport type { FunctionComponent } from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, optionValueName } from '../common';\n\nimport defaultTheme from './theme.scss';\n\n/**\n * Implements a themeable dropdown list. Internally it is rendered with help of\n * the standard HTML `<select>` element, thus the styling support is somewhat\n * limited.\n * @param [props] Component properties.\n * @param [props.filter] Options filter function. If provided, only\n * those elements of `options` list will be used by the dropdown, for which this\n * filter returns `true`.\n * @param [props.label] Dropdown label.\n * @param [props.onChange] Selection event handler.\n * @param [props.options=[]] Array of dropdown\n * options. For string elements the option value and name will be the same.\n * It is allowed to mix DropdownOption and string elements in the same option\n * list.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.value] Currently selected value.\n * @param [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Dropdown: FunctionComponent<PropsT<string>> = ({\n filter,\n label,\n onChange,\n onClick,\n options,\n testId,\n theme,\n value,\n}) => {\n let isValidValue = false;\n const optionElements = [];\n\n const composed = useTheme('Dropdown', defaultTheme, theme);\n\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n isValidValue ||= iValue === value;\n optionElements.push(\n <option className={composed.option} key={iValue} value={iValue}>\n {iName}\n </option>,\n );\n }\n }\n\n // NOTE: This element represents the current `value` when it does not match\n // any valid option. In Chrome, and some other browsers, we are able to hide\n // it from the opened dropdown; in others, e.g. Safari, the best we can do is\n // to show it as disabled.\n const hiddenOption = isValidValue ? null : (\n <option\n className={composed.hiddenOption}\n disabled\n key=\"__reactUtilsHiddenOption\"\n value={value}\n >\n {value}\n </option>\n );\n\n let selectClassName = composed.select ?? '';\n if (!isValidValue) selectClassName += ` ${composed.invalid ?? ''}`;\n\n return (\n <div className={composed.container}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <div className={composed.dropdown}>\n <select\n className={selectClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onChange={onChange}\n onClick={onClick}\n value={value}\n >\n {hiddenOption}\n {optionElements}\n </select>\n <div className={composed.arrow} />\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/NativeDropdown/index.tsx"],"sourcesContent":["// Implements dropdown based on the native HTML <select> element.\n\nimport type { FunctionComponent } from 'react';\n\nimport { useTheme } from '@dr.pogodin/react-themes';\n\nimport { type PropsT, optionValueName } from '../common';\n\nimport defaultTheme from './theme.scss';\n\n/**\n * Implements a themeable dropdown list. Internally it is rendered with help of\n * the standard HTML `<select>` element, thus the styling support is somewhat\n * limited.\n * @param [props] Component properties.\n * @param [props.filter] Options filter function. If provided, only\n * those elements of `options` list will be used by the dropdown, for which this\n * filter returns `true`.\n * @param [props.label] Dropdown label.\n * @param [props.onChange] Selection event handler.\n * @param [props.options=[]] Array of dropdown\n * options. For string elements the option value and name will be the same.\n * It is allowed to mix DropdownOption and string elements in the same option\n * list.\n * @param [props.theme] _Ad hoc_ theme.\n * @param [props.value] Currently selected value.\n * @param [props....]\n * [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)\n */\nconst Dropdown: FunctionComponent<PropsT<string>> = ({\n filter,\n label,\n onChange,\n onClick,\n options,\n testId,\n theme,\n value,\n}) => {\n let isValidValue = false;\n const optionElements = [];\n\n const composed = useTheme('Dropdown', defaultTheme, theme);\n\n for (const option of options) {\n if (!filter || filter(option)) {\n const [iValue, iName] = optionValueName(option);\n isValidValue ||= iValue === value;\n optionElements.push(\n <option className={composed.option} key={iValue} value={iValue}>\n {iName}\n </option>,\n );\n }\n }\n\n // NOTE: This element represents the current `value` when it does not match\n // any valid option. In Chrome, and some other browsers, we are able to hide\n // it from the opened dropdown; in others, e.g. Safari, the best we can do is\n // to show it as disabled.\n const hiddenOption = isValidValue ? null : (\n <option\n className={composed.hiddenOption}\n disabled\n key=\"__reactUtilsHiddenOption\"\n value={value}\n >\n {value}\n </option>\n );\n\n let selectClassName = composed.select ?? '';\n if (!isValidValue) selectClassName += ` ${composed.invalid ?? ''}`;\n\n return (\n <div className={composed.container}>\n { label === undefined\n ? null : <div className={composed.label}>{label}</div> }\n <div className={composed.dropdown}>\n <select\n className={selectClassName}\n data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}\n onChange={onChange}\n onClick={onClick}\n value={value}\n >\n {hiddenOption}\n {optionElements}\n </select>\n <div className={composed.arrow} />\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"mappings":";;;+CAAA;AAIA,SAAS,QAAQ,QAAQ,0BAA0B;AAAC,SAE9B,eAAe;A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AAK,SAAS,EAAE,QAAQ,CAAC,KAAM;MAAA,UAAE;IAAK,CAAM,CAAC,eACxD;MAAK,SAAS,EAAE,QAAQ,CAAC,QAAS;MAAA,wBAChC;QACE,SAAS,EAAE,eAAgB;QAC3B,eAAa,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,GAAG,SAAS,GAAG,MAAO;QACxE,QAAQ,EAAE,QAAS;QACnB,OAAO,EAAE,OAAQ;QACjB,KAAK,EAAE,KAAM;QAAA,WAEZ,YAAY,EACZ,cAAc;MAAA,CACT,CAAC,eACT;QAAK,SAAS,EAAE,QAAQ,CAAC;MAAM,CAAE,CAAC;IAAA,CAC/B,CAAC;EAAA,CACH,CAAC;AAEV,CAAC;AAED,eAAe,QAAQ","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "core-js/modules/es.array.push.js";
|
|
2
2
|
import { c as _c } from "react/compiler-runtime";
|
|
3
3
|
import { useTheme } from "@dr.pogodin/react-themes";
|
|
4
4
|
import { optionValueName } from "../common.js";
|
|
@@ -41,7 +41,7 @@ export const Switch = t0 => {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
optionNodes.push(onPress ? /*#__PURE__*/_jsx("div", {
|
|
45
45
|
className: className,
|
|
46
46
|
onClick: onPress,
|
|
47
47
|
onKeyDown: e => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import type { FunctionComponent, ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport {\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../common';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeT = Theme<'container' | 'label' | 'option' | 'options' | 'selected'>;\n\ntype PropsT = {\n label?: ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<ReactNode>>;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nexport const Switch: FunctionComponent<PropsT> = ({\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const composed = useTheme('Switch', defaultTheme, theme);\n\n if (!options || !composed.option) throw Error('Internal error');\n\n const optionNodes: React.ReactNode[] = [];\n for (const option of options) {\n const [iValue, iName] = optionValueName(option);\n\n let className: string = composed.option;\n let onPress: (() => void) | undefined;\n if (iValue === value) className += ` ${composed.selected ?? ''}`;\n else if (onChange) {\n onPress = () => {\n onChange(iValue);\n };\n }\n\n optionNodes.push(\n onPress\n ? (\n <div\n className={className}\n key={iValue}\n onClick={onPress}\n onKeyDown={(e) => {\n if (e.key === 'Enter') onPress();\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>\n )\n : <div className={className} key={iValue}>{iName}</div>,\n );\n }\n\n return (\n <div className={composed.container}>\n {label ? <div className={composed.label}>{label}</div> : null}\n\n <div className={composed.options}>\n {optionNodes}\n </div>\n </div>\n );\n};\n"],"mappings":";;AAEA,SAAqB,QAAQ,QAAQ,0BAA0B;AAAC,SAK9D,eAAe;AAGjB;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AAYxC,OAAO,MAAM,MAAiC,GAAG;EAAA;EAAC;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA,MAMjD;EACC,iBAAiB,QAAQ,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC;EAExD,IAAI,CAAC,OAA2B,IAA5B,CAAa,QAAQ,OAAO;IAAE,MAAM,KAAK,CAAC,gBAAgB,CAAC;EAAC;EAAA;EAAA;IAEhE,cAAuC,EAAE;IACzC,KAAK,YAAY,IAAI,OAAO;MAC1B,wBAAwB,eAAe,CAAC,MAAM,CAAC;MAE/C,gBAAwB,QAAQ,OAAO;MACnC;MACJ,IAAI,MAAM,KAAK,KAAK;QAAE,qBAAS,GAAI,IAAI,QAAQ,SAAe,IAAvB,EAAuB,EAAE;MAAA;QAC3D,IAAI,QAAQ;UACf,UAAU;YACR,QAAQ,CAAC,MAAM,CAAC;UAAA,CACjB;QAFM;MAGR;MAED,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import type { FunctionComponent, ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport {\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../common';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeT = Theme<'container' | 'label' | 'option' | 'options' | 'selected'>;\n\ntype PropsT = {\n label?: ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<ReactNode>>;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nexport const Switch: FunctionComponent<PropsT> = ({\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const composed = useTheme('Switch', defaultTheme, theme);\n\n if (!options || !composed.option) throw Error('Internal error');\n\n const optionNodes: React.ReactNode[] = [];\n for (const option of options) {\n const [iValue, iName] = optionValueName(option);\n\n let className: string = composed.option;\n let onPress: (() => void) | undefined;\n if (iValue === value) className += ` ${composed.selected ?? ''}`;\n else if (onChange) {\n onPress = () => {\n onChange(iValue);\n };\n }\n\n optionNodes.push(\n onPress\n ? (\n <div\n className={className}\n key={iValue}\n onClick={onPress}\n onKeyDown={(e) => {\n if (e.key === 'Enter') onPress();\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>\n )\n : <div className={className} key={iValue}>{iName}</div>,\n );\n }\n\n return (\n <div className={composed.container}>\n {label ? <div className={composed.label}>{label}</div> : null}\n\n <div className={composed.options}>\n {optionNodes}\n </div>\n </div>\n );\n};\n"],"mappings":";;AAEA,SAAqB,QAAQ,QAAQ,0BAA0B;AAAC,SAK9D,eAAe;AAGjB;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAAwC;AAYxC,OAAO,MAAM,MAAiC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AkB,EAAlB,QAAQ,UAAU;MAAA,WAC/B,EAA4D,EAE7D,EAEM;IAAA,CACH,CAAC;IAAA;IAAA;IAAA;IAAA;EAAA;IAAA;EAAA;EAAA,OANN,EAMM;AAAA,CAET","ignoreList":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import "core-js/modules/es.json.parse.js"; /**
|
|
2
|
+
* Jest environment for end-to-end SSR and client-side testing. It relies on
|
|
3
|
+
* the standard react-utils mechanics to execute SSR of given scene, and also
|
|
4
|
+
* Webpack build of the code for client-side execution, it further exposes
|
|
5
|
+
* Jsdom environment for the client-side testing of the outcomes.
|
|
6
|
+
*/ // BEWARE: The module is not imported into the JU module / the main assembly of
|
|
7
7
|
// the library, because doing so easily breaks stuff:
|
|
8
8
|
// 1) This module depends on Node-specific modules, which would make JU
|
|
9
9
|
// incompatible with JsDom if included into JU.
|
|
@@ -51,7 +51,7 @@ export default class E2eSsrEnv extends JsdomEnv {
|
|
|
51
51
|
*/
|
|
52
52
|
async loadWebpackConfig() {
|
|
53
53
|
const optionsString = this.pragmas["webpack-config-options"];
|
|
54
|
-
const options = optionsString ?
|
|
54
|
+
const options = optionsString ? JSON.parse(optionsString) : {};
|
|
55
55
|
defaults(options, {
|
|
56
56
|
context: this.testFolder,
|
|
57
57
|
fs: this.global.webpackOutputFs
|
|
@@ -65,7 +65,7 @@ export default class E2eSsrEnv extends JsdomEnv {
|
|
|
65
65
|
let buildInfo = `${options.context}/.build-info`;
|
|
66
66
|
if (fs.existsSync(buildInfo)) {
|
|
67
67
|
buildInfo = fs.readFileSync(buildInfo, "utf8");
|
|
68
|
-
this.global.buildInfo =
|
|
68
|
+
this.global.buildInfo = JSON.parse(buildInfo);
|
|
69
69
|
}
|
|
70
70
|
} /**
|
|
71
71
|
* Executes Webpack build.
|
|
@@ -103,7 +103,7 @@ export default class E2eSsrEnv extends JsdomEnv {
|
|
|
103
103
|
const ssrModulePath = await findModule(`${import.meta.dirname}/ssr-preload`);
|
|
104
104
|
const cp = fork(ssrModulePath);
|
|
105
105
|
const optionsString = this.pragmas["ssr-options"];
|
|
106
|
-
const options = optionsString ?
|
|
106
|
+
const options = optionsString ? JSON.parse(optionsString) : {};
|
|
107
107
|
options.buildInfo ??= this.global.buildInfo;
|
|
108
108
|
if (!this.webpackStats) throw Error("Missing Webpack stats");
|
|
109
109
|
options.chunkGroups = deduceChunkGroups(this.webpackStats);
|
|
@@ -131,7 +131,7 @@ export default class E2eSsrEnv extends JsdomEnv {
|
|
|
131
131
|
constructor(config, context) {
|
|
132
132
|
const pragmas = context.docblockPragmas;
|
|
133
133
|
const requestString = pragmas["ssr-request"];
|
|
134
|
-
const request = requestString ?
|
|
134
|
+
const request = requestString ? JSON.parse(requestString) : {};
|
|
135
135
|
request.url ??= "/"; // This ensures the initial JsDom URL matches the value we use for SSR.
|
|
136
136
|
set(config.projectConfig, "testEnvironmentOptions.url", `http://localhost${request.url}`);
|
|
137
137
|
super(config, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/index.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\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 */\n\nimport { fork } from 'node:child_process';\nimport { access } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { defaults, set } from 'lodash-es';\nimport { Volume, createFsFromVolume } from 'memfs';\nimport webpack, { type Configuration, type Stats } from 'webpack';\n\nimport register, { revert } from '@babel/register';\n\nimport type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\n\nimport { deduceChunkGroups } from 'server/renderer';\n\nimport type { LaunchT, ResultT } from './ssr';\n\nasync function findModule(module: string): Promise<string> {\n try {\n const res = `${module}.ts`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n try {\n const res = `${module}.js`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n throw Error(`Module \"${module}\" was not found, neither as TS, nor as JS`);\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?: Stats;\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 if (!options.context) throw Error('Missing context');\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 // NOTE: This is a TS module in the source code, and it turn into JS\n // module in the distributed code, after Babel compilation. As we rely\n // on it for the forked NodeJS process, we need to resolve the correct\n // extention ourselves (as NodeJS will hit the given path, without any\n // additional resolutions / transformations).\n const ssrModulePath = await findModule(`${import.meta.dirname}/ssr-preload`);\n\n const cp = fork(ssrModulePath);\n\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n\n options.buildInfo ??= this.global.buildInfo;\n\n if (!this.webpackStats) throw Error('Missing Webpack stats');\n\n options.chunkGroups = deduceChunkGroups(this.webpackStats);\n\n return new Promise((resolve, reject) => {\n cp.on('exit', (code) => {\n if (code) reject(Error('SSR process crashed'));\n });\n\n cp.on('message', (message: ResultT) => {\n this.global.ssrMarkup = message.markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = message.status;\n cp.kill();\n resolve();\n });\n\n if (!this.global.webpackConfig) throw Error('Missing Webpack config');\n\n cp.send({\n options,\n root: options.root === 'TEST' ? this.testFolder : process.cwd(),\n ssrRequest: this.ssrRequest,\n testFolder: this.testFolder,\n webpackConfig: this.global.webpackConfig,\n } satisfies LaunchT);\n });\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\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 // 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 // BEWARE: Although we also do the registration inside SSR testing code,\n // we still need it here to correctly process imported Webpack configurations\n // (which are imported directly from this module).\n register({\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],\n });\n }\n\n async setup(): Promise<void> {\n await super.setup();\n await this.runWebpack();\n\n // eslint-disable-next-line import/dynamic-import-chunkname\n const { setBuildInfo } = await import('../../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 revert();\n\n await super.teardown();\n }\n}\n"],"mappings":"8DAAA;AACA;AACA;AACA;AACA;AACA,iEALA,CAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;A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,GAAG,OAAO;IACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAEtB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,QAAQ,CAAC;MACP,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM;IACnD,CAAC,CAAC;EACJ;EAEA,MAAM,KAAK,GAAkB;IAC3B,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;IACnB,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,CAEvB;IACA,MAAM;MAAE;IAAa,CAAC,GAAG,MAAM,MAAM,gCAA6B;IAClE,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC;IAE7B,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,6BAA6B,GAAG,IAAI;EAClD;EAEA,MAAM,QAAQ,GAAkB;IAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,6BAA6B;IAEhD,MAAM,CAAC,CAAC;IAER,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;EACxB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/index.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\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 */\n\nimport { fork } from 'node:child_process';\nimport { access } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { defaults, set } from 'lodash-es';\nimport { Volume, createFsFromVolume } from 'memfs';\nimport webpack, { type Configuration, type Stats } from 'webpack';\n\nimport register, { revert } from '@babel/register';\n\nimport type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\n\nimport { deduceChunkGroups } from 'server/renderer';\n\nimport type { LaunchT, ResultT } from './ssr';\n\nasync function findModule(module: string): Promise<string> {\n try {\n const res = `${module}.ts`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n try {\n const res = `${module}.js`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n throw Error(`Module \"${module}\" was not found, neither as TS, nor as JS`);\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?: Stats;\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 if (!options.context) throw Error('Missing context');\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 // NOTE: This is a TS module in the source code, and it turn into JS\n // module in the distributed code, after Babel compilation. As we rely\n // on it for the forked NodeJS process, we need to resolve the correct\n // extention ourselves (as NodeJS will hit the given path, without any\n // additional resolutions / transformations).\n const ssrModulePath = await findModule(`${import.meta.dirname}/ssr-preload`);\n\n const cp = fork(ssrModulePath);\n\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n\n options.buildInfo ??= this.global.buildInfo;\n\n if (!this.webpackStats) throw Error('Missing Webpack stats');\n\n options.chunkGroups = deduceChunkGroups(this.webpackStats);\n\n return new Promise((resolve, reject) => {\n cp.on('exit', (code) => {\n if (code) reject(Error('SSR process crashed'));\n });\n\n cp.on('message', (message: ResultT) => {\n this.global.ssrMarkup = message.markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = message.status;\n cp.kill();\n resolve();\n });\n\n if (!this.global.webpackConfig) throw Error('Missing Webpack config');\n\n cp.send({\n options,\n root: options.root === 'TEST' ? this.testFolder : process.cwd(),\n ssrRequest: this.ssrRequest,\n testFolder: this.testFolder,\n webpackConfig: this.global.webpackConfig,\n } satisfies LaunchT);\n });\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\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 // 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 // BEWARE: Although we also do the registration inside SSR testing code,\n // we still need it here to correctly process imported Webpack configurations\n // (which are imported directly from this module).\n register({\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],\n });\n }\n\n async setup(): Promise<void> {\n await super.setup();\n await this.runWebpack();\n\n // eslint-disable-next-line import/dynamic-import-chunkname\n const { setBuildInfo } = await import('../../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 revert();\n\n await super.teardown();\n }\n}\n"],"mappings":"0CAAA;AACA;AACA;AACA;AACA;AACA,6CALA,CAOA;AACA;AACA;AACA;A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CAAC,QAAQ,CAAC;IAChD,IAAI,CAAC,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IACjC,IAAI,CAAC,UAAU,GAAG,OAAO;IACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAEtB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,QAAQ,CAAC;MACP,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM;IACnD,CAAC,CAAC;EACJ;EAEA,MAAM,KAAK,GAAkB;IAC3B,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;IACnB,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,CAEvB;IACA,MAAM;MAAE;IAAa,CAAC,GAAG,MAAM,MAAM,gCAA6B;IAClE,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC;IAE7B,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,6BAA6B,GAAG,IAAI;EAClD;EAEA,MAAM,QAAQ,GAAkB;IAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,6BAA6B;IAEhD,MAAM,CAAC,CAAC;IAER,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;EACxB;AACF","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "core-js/modules/es.json.stringify.js"; /* global document */ /* eslint-disable import/no-extraneous-dependencies */
|
|
2
2
|
import mockdate from "mockdate";
|
|
3
3
|
import { act } from "react";
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
@@ -58,10 +58,10 @@ export function mockAxios(handlers) {
|
|
|
58
58
|
...config,
|
|
59
59
|
adapter: ["xhr", "http", "fetch"]
|
|
60
60
|
}); // eslint-disable-next-line no-console
|
|
61
|
-
console.warn("Network request has not been mocked for a test.\n\nConfig:\n", config, "\n\nResult:\n",
|
|
61
|
+
console.warn("Network request has not been mocked for a test.\n\nConfig:\n", config, "\n\nResult:\n", JSON.stringify(res, null, 2));
|
|
62
62
|
} catch (e) {
|
|
63
63
|
// eslint-disable-next-line no-console
|
|
64
|
-
console.warn("Network request has not been mocked for a test, and failed.\n\nConfig:\n", config, "\n\nError\n",
|
|
64
|
+
console.warn("Network request has not been mocked for a test, and failed.\n\nConfig:\n", config, "\n\nError\n", JSON.stringify(e, null, 2));
|
|
65
65
|
throw e;
|
|
66
66
|
}
|
|
67
67
|
return res;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/utils/jest/index.ts"],"sourcesContent":["/* global document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport type {\n AxiosRequestConfig,\n AxiosResponse,\n AxiosStatic,\n InternalAxiosRequestConfig,\n} from 'axios';\n\nimport mockdate from 'mockdate';\nimport { type ReactElement, type ReactNode, act } from 'react';\nimport { type Root, createRoot } from 'react-dom/client';\n\nimport { expect, jest } from '@jest/globals';\nimport { type RenderResult, render } from '@testing-library/react';\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react`.\n */\nexport { act };\n\nexport { default as getGlobal } from './global';\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide(): void {\n Object.defineProperty(process, 'versions', { value: undefined });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide(): void {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0): `${string}-${string}-${string}-${string}-${string}` {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\nexport type AxiosRequestHandlerT = (\n config: AxiosRequestConfig,\n) => Partial<AxiosResponse> | null | undefined;\n\nexport function mockAxios(handlers: AxiosRequestHandlerT[]): AxiosStatic {\n const axios: AxiosStatic = jest.requireActual('axios');\n\n axios.defaults.adapter = async (\n config: AxiosRequestConfig,\n ): Promise<AxiosResponse> => {\n for (const handler of handlers) {\n const res = handler(config);\n if (res) {\n return {\n config: config as InternalAxiosRequestConfig,\n data: null,\n headers: {},\n status: 200,\n statusText: 'OK',\n ...res,\n };\n }\n }\n\n // Fallback to the regular network request.\n let res: AxiosResponse;\n try {\n res = await axios({ ...config, adapter: ['xhr', 'http', 'fetch'] });\n // eslint-disable-next-line no-console\n console.warn(\n 'Network request has not been mocked for a test.\\n\\nConfig:\\n',\n config,\n '\\n\\nResult:\\n',\n JSON.stringify(res, null, 2),\n );\n } catch (e) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Network request has not been mocked for a test, and failed.\\n\\nConfig:\\n',\n config,\n '\\n\\nError\\n',\n JSON.stringify(e, null, 2),\n );\n throw e;\n }\n\n return res;\n };\n\n return axios;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time: number): Promise<void> {\n mockdate.set(time + Date.now());\n await jest.advanceTimersByTimeAsync(time);\n}\n\nexport type MountedSceneT = HTMLElement & {\n destroy: () => void;\n snapshot: () => void;\n};\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param scene\n * @return Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene: ReactNode): MountedSceneT {\n let root: Root;\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const res: MountedSceneT = (element as unknown) as MountedSceneT;\n res.destroy = () => {\n // NOTE: As it seems @testing-library may reset this flag to false\n // when it is simulating user events.\n global.IS_REACT_ACT_ENVIRONMENT = true;\n\n act(() => {\n root.unmount();\n });\n res.remove();\n };\n\n res.snapshot = () => {\n expect(res).toMatchSnapshot();\n };\n\n // NOTE: As it seems @testing-library may reset this flag to false\n // when it is simulating user events.\n global.IS_REACT_ACT_ENVIRONMENT = true;\n\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n// NOTE: If in future we have additional options here, they should be distributed\n// across two objects, depending whether they are applicable to the sync, or async\n// versions of snapshot(), or both.\ntype AsyncSnapshotOptionsT = {\n await?: Promise<void>;\n};\n\nexport function snapshot(element: ReactElement): RenderResult;\n\nexport async function snapshot(\n element: ReactElement,\n options: AsyncSnapshotOptionsT,\n): Promise<RenderResult>;\n\nexport function snapshot(\n element: ReactElement,\n options?: AsyncSnapshotOptionsT,\n): Promise<RenderResult> | RenderResult {\n let res: RenderResult | undefined;\n\n // TODO: Just adding async to the actor function breaks stuff, as it makes\n // act() asynchronous no matter the `options.await` value, thus breaking all\n // calls that do not await for snapshot() result... thus... perhaps we need\n // to have a more complex typing to ensure it all works as intended in all\n // cases, and while being correctly enforced by TypeScript.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const promise = act(() => {\n res = render(element);\n return options?.await;\n });\n\n if (res === undefined) throw Error('Render failed');\n if (options?.await) {\n // BEWARE: Although `promise` is thenable (i.e. it has .then() method),\n // it is not an instance of proper Promise class, and returning it directly\n // breaks some async logic in Jest test or React test functions... thus, we\n // wrap it into Promise instance here.\n return new Promise((resolve, reject) => {\n let rejected = false;\n\n // BEWARE: The \"promise\" returned by act() does not behave as a regular\n // Promise instance:\n // 1. In case of errors its .then() method both calls its \"reject\"\n // callback (first), and then its \"resolve\" callback second.\n // 2. It errors out if a rendering error happens, and there is no\n // \"reject\" argument provided.\n void promise.then(() => {\n if (!rejected) {\n // TODO: These lines are the same as the lines below for sync variant of\n // the function. We should split and reuse them in both places.\n if (!res) throw Error('Missing render result');\n const nodes = res.asFragment().childNodes;\n expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();\n resolve(res);\n }\n }, (error: unknown) => {\n rejected = true;\n\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error);\n });\n });\n }\n\n const nodes = res.asFragment().childNodes;\n expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();\n return res;\n}\n"],"mappings":"sEAAA,uBACA;AASA,OAAO,QAAQ,MAAM,UAAU;AAC/B,SAA4C,GAAG,QAAQ,OAAO;AAC9D,SAAoB,UAAU,QAAQ,kBAAkB;AAExD,SAAS,MAAM,EAAE,IAAI,QAAQ,eAAe;AAC5C,SAA4B,MAAM,QAAQ,wBAAwB,CAElE;AACA;AACA;AACA;AACA,SAAS,GAAG;AAAG,SAEN,OAAO,IAAI,SAAS;AAE7B,MAAM,CAAC,wBAAwB,GAAG,IAAI;AAEtC,MAAM,uBAAuB,GAAG,OAAO,CAAC,QAAQ,CAEhD;AACA;AACA;AACA;AACA,OAAO,SAAS,cAAc,GAAS;EACrC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE;IAAE,KAAK,EAAE;EAAU,CAAC,CAAC;AAClE,CAEA;AACA;AACA;AACA,OAAO,SAAS,gBAAgB,GAAS;EACvC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE;IACzC,KAAK,EAAE,uBAAuB;IAC9B,QAAQ,EAAE;EACZ,CAAC,CAAC;AACJ,CAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,WAAW,CAAC,IAAI,GAAG,CAAC,EAAuD;EACzF,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC;EAC7C,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,C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AO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;MACtC,IAAI,QAAQ,GAAG,KAAK,CAEpB;MACA;MACA;MACA;MACA;MACA;MACA,KAAK,OAAO,CAAC,IAAI,CAAC,MAAM;QACtB,IAAI,CAAC,QAAQ,EAAE;UACb;UACA;UACA,IAAI,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,uBAAuB,CAAC;UAC9C,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU;UACzC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;UAClE,OAAO,CAAC,GAAG,CAAC;QACd;MACF,CAAC,EAAG,KAAc,IAAK;QACrB,QAAQ,GAAG,IAAI,CAEf;QACA,MAAM,CAAC,KAAK,CAAC;MACf,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EAEA,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU;EACzC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;EAClE,OAAO,GAAG;AACZ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/utils/jest/index.ts"],"sourcesContent":["/* global document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport type {\n AxiosRequestConfig,\n AxiosResponse,\n AxiosStatic,\n InternalAxiosRequestConfig,\n} from 'axios';\n\nimport mockdate from 'mockdate';\nimport { type ReactElement, type ReactNode, act } from 'react';\nimport { type Root, createRoot } from 'react-dom/client';\n\nimport { expect, jest } from '@jest/globals';\nimport { type RenderResult, render } from '@testing-library/react';\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react`.\n */\nexport { act };\n\nexport { default as getGlobal } from './global';\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide(): void {\n Object.defineProperty(process, 'versions', { value: undefined });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide(): void {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0): `${string}-${string}-${string}-${string}-${string}` {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\nexport type AxiosRequestHandlerT = (\n config: AxiosRequestConfig,\n) => Partial<AxiosResponse> | null | undefined;\n\nexport function mockAxios(handlers: AxiosRequestHandlerT[]): AxiosStatic {\n const axios: AxiosStatic = jest.requireActual('axios');\n\n axios.defaults.adapter = async (\n config: AxiosRequestConfig,\n ): Promise<AxiosResponse> => {\n for (const handler of handlers) {\n const res = handler(config);\n if (res) {\n return {\n config: config as InternalAxiosRequestConfig,\n data: null,\n headers: {},\n status: 200,\n statusText: 'OK',\n ...res,\n };\n }\n }\n\n // Fallback to the regular network request.\n let res: AxiosResponse;\n try {\n res = await axios({ ...config, adapter: ['xhr', 'http', 'fetch'] });\n // eslint-disable-next-line no-console\n console.warn(\n 'Network request has not been mocked for a test.\\n\\nConfig:\\n',\n config,\n '\\n\\nResult:\\n',\n JSON.stringify(res, null, 2),\n );\n } catch (e) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Network request has not been mocked for a test, and failed.\\n\\nConfig:\\n',\n config,\n '\\n\\nError\\n',\n JSON.stringify(e, null, 2),\n );\n throw e;\n }\n\n return res;\n };\n\n return axios;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time: number): Promise<void> {\n mockdate.set(time + Date.now());\n await jest.advanceTimersByTimeAsync(time);\n}\n\nexport type MountedSceneT = HTMLElement & {\n destroy: () => void;\n snapshot: () => void;\n};\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param scene\n * @return Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene: ReactNode): MountedSceneT {\n let root: Root;\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const res: MountedSceneT = (element as unknown) as MountedSceneT;\n res.destroy = () => {\n // NOTE: As it seems @testing-library may reset this flag to false\n // when it is simulating user events.\n global.IS_REACT_ACT_ENVIRONMENT = true;\n\n act(() => {\n root.unmount();\n });\n res.remove();\n };\n\n res.snapshot = () => {\n expect(res).toMatchSnapshot();\n };\n\n // NOTE: As it seems @testing-library may reset this flag to false\n // when it is simulating user events.\n global.IS_REACT_ACT_ENVIRONMENT = true;\n\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n// NOTE: If in future we have additional options here, they should be distributed\n// across two objects, depending whether they are applicable to the sync, or async\n// versions of snapshot(), or both.\ntype AsyncSnapshotOptionsT = {\n await?: Promise<void>;\n};\n\nexport function snapshot(element: ReactElement): RenderResult;\n\nexport async function snapshot(\n element: ReactElement,\n options: AsyncSnapshotOptionsT,\n): Promise<RenderResult>;\n\nexport function snapshot(\n element: ReactElement,\n options?: AsyncSnapshotOptionsT,\n): Promise<RenderResult> | RenderResult {\n let res: RenderResult | undefined;\n\n // TODO: Just adding async to the actor function breaks stuff, as it makes\n // act() asynchronous no matter the `options.await` value, thus breaking all\n // calls that do not await for snapshot() result... thus... perhaps we need\n // to have a more complex typing to ensure it all works as intended in all\n // cases, and while being correctly enforced by TypeScript.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const promise = act(() => {\n res = render(element);\n return options?.await;\n });\n\n if (res === undefined) throw Error('Render failed');\n if (options?.await) {\n // BEWARE: Although `promise` is thenable (i.e. it has .then() method),\n // it is not an instance of proper Promise class, and returning it directly\n // breaks some async logic in Jest test or React test functions... thus, we\n // wrap it into Promise instance here.\n return new Promise((resolve, reject) => {\n let rejected = false;\n\n // BEWARE: The \"promise\" returned by act() does not behave as a regular\n // Promise instance:\n // 1. In case of errors its .then() method both calls its \"reject\"\n // callback (first), and then its \"resolve\" callback second.\n // 2. It errors out if a rendering error happens, and there is no\n // \"reject\" argument provided.\n void promise.then(() => {\n if (!rejected) {\n // TODO: These lines are the same as the lines below for sync variant of\n // the function. We should split and reuse them in both places.\n if (!res) throw Error('Missing render result');\n const nodes = res.asFragment().childNodes;\n expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();\n resolve(res);\n }\n }, (error: unknown) => {\n rejected = true;\n\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error);\n });\n });\n }\n\n const nodes = res.asFragment().childNodes;\n expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();\n return res;\n}\n"],"mappings":"8CAAA,uBACA;AASA,OAAO,QAAQ,MAAM,UAAU;AAC/B,SAA4C,GAAG,QAAQ,OAAO;AAC9D,SAAoB,UAAU,QAAQ,kBAAkB;AAExD,SAAS,MAAM,EAAE,IAAI,QAAQ,eAAe;AAC5C,SAA4B,MAAM,QAAQ,wBAAwB,CAElE;AACA;AACA;AACA;AACA,SAAS,GAAG;AAAG,SAEN,OAAO,IAAI,SAAS;AAE7B,MAAM,CAAC,wBAAwB,GAAG,IAAI;AAEtC,MAAM,uBAAuB,GAAG,OAAO,CAAC,QAAQ,CAEhD;AACA;AACA;AACA;AACA,OAAO,SAAS,cAAc,GAAS;EACrC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE;IAAE,KAAK,EAAE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AAU;EACzC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;EAClE,OAAO,GAAG;AACZ","ignoreList":[]}
|
|
@@ -1,4 +1,78 @@
|
|
|
1
|
-
import
|
|
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.iterator.chunks.js";
|
|
4
|
+
import "core-js/modules/esnext.map.delete-all.js";
|
|
5
|
+
import "core-js/modules/esnext.map.emplace.js";
|
|
6
|
+
import "core-js/modules/esnext.map.every.js";
|
|
7
|
+
import "core-js/modules/esnext.map.filter.js";
|
|
8
|
+
import "core-js/modules/esnext.map.find.js";
|
|
9
|
+
import "core-js/modules/esnext.map.find-key.js";
|
|
10
|
+
import "core-js/modules/esnext.map.includes.js";
|
|
11
|
+
import "core-js/modules/esnext.map.key-of.js";
|
|
12
|
+
import "core-js/modules/esnext.map.map-keys.js";
|
|
13
|
+
import "core-js/modules/esnext.map.map-values.js";
|
|
14
|
+
import "core-js/modules/esnext.map.merge.js";
|
|
15
|
+
import "core-js/modules/esnext.map.reduce.js";
|
|
16
|
+
import "core-js/modules/esnext.map.some.js";
|
|
17
|
+
import "core-js/modules/esnext.map.update.js";
|
|
18
|
+
import "core-js/modules/esnext.set.add-all.js";
|
|
19
|
+
import "core-js/modules/esnext.set.delete-all.js";
|
|
20
|
+
import "core-js/modules/esnext.set.difference.js";
|
|
21
|
+
import "core-js/modules/esnext.set.every.js";
|
|
22
|
+
import "core-js/modules/esnext.set.filter.js";
|
|
23
|
+
import "core-js/modules/esnext.set.find.js";
|
|
24
|
+
import "core-js/modules/esnext.set.intersection.js";
|
|
25
|
+
import "core-js/modules/esnext.set.is-disjoint-from.js";
|
|
26
|
+
import "core-js/modules/esnext.set.is-subset-of.js";
|
|
27
|
+
import "core-js/modules/esnext.set.is-superset-of.js";
|
|
28
|
+
import "core-js/modules/esnext.set.join.js";
|
|
29
|
+
import "core-js/modules/esnext.set.map.js";
|
|
30
|
+
import "core-js/modules/esnext.set.reduce.js";
|
|
31
|
+
import "core-js/modules/esnext.set.some.js";
|
|
32
|
+
import "core-js/modules/esnext.set.symmetric-difference.js";
|
|
33
|
+
import "core-js/modules/esnext.set.union.js";
|
|
34
|
+
import "core-js/modules/es.array.push.js";
|
|
35
|
+
import "core-js/modules/es.iterator.constructor.js";
|
|
36
|
+
import "core-js/modules/es.map.get-or-insert.js";
|
|
37
|
+
import "core-js/modules/es.map.get-or-insert-computed.js";
|
|
38
|
+
import "core-js/modules/es.set.difference.v2.js";
|
|
39
|
+
import "core-js/modules/es.set.intersection.v2.js";
|
|
40
|
+
import "core-js/modules/es.set.is-disjoint-from.v2.js";
|
|
41
|
+
import "core-js/modules/es.set.is-subset-of.v2.js";
|
|
42
|
+
import "core-js/modules/es.set.is-superset-of.v2.js";
|
|
43
|
+
import "core-js/modules/es.set.symmetric-difference.v2.js";
|
|
44
|
+
import "core-js/modules/es.set.union.v2.js";
|
|
45
|
+
import "core-js/modules/esnext.iterator.chunks.js";
|
|
46
|
+
import "core-js/modules/esnext.map.delete-all.js";
|
|
47
|
+
import "core-js/modules/esnext.map.emplace.js";
|
|
48
|
+
import "core-js/modules/esnext.map.every.js";
|
|
49
|
+
import "core-js/modules/esnext.map.filter.js";
|
|
50
|
+
import "core-js/modules/esnext.map.find.js";
|
|
51
|
+
import "core-js/modules/esnext.map.find-key.js";
|
|
52
|
+
import "core-js/modules/esnext.map.includes.js";
|
|
53
|
+
import "core-js/modules/esnext.map.key-of.js";
|
|
54
|
+
import "core-js/modules/esnext.map.map-keys.js";
|
|
55
|
+
import "core-js/modules/esnext.map.map-values.js";
|
|
56
|
+
import "core-js/modules/esnext.map.merge.js";
|
|
57
|
+
import "core-js/modules/esnext.map.reduce.js";
|
|
58
|
+
import "core-js/modules/esnext.map.some.js";
|
|
59
|
+
import "core-js/modules/esnext.map.update.js";
|
|
60
|
+
import "core-js/modules/esnext.set.add-all.js";
|
|
61
|
+
import "core-js/modules/esnext.set.delete-all.js";
|
|
62
|
+
import "core-js/modules/esnext.set.difference.js";
|
|
63
|
+
import "core-js/modules/esnext.set.every.js";
|
|
64
|
+
import "core-js/modules/esnext.set.filter.js";
|
|
65
|
+
import "core-js/modules/esnext.set.find.js";
|
|
66
|
+
import "core-js/modules/esnext.set.intersection.js";
|
|
67
|
+
import "core-js/modules/esnext.set.is-disjoint-from.js";
|
|
68
|
+
import "core-js/modules/esnext.set.is-subset-of.js";
|
|
69
|
+
import "core-js/modules/esnext.set.is-superset-of.js";
|
|
70
|
+
import "core-js/modules/esnext.set.join.js";
|
|
71
|
+
import "core-js/modules/esnext.set.map.js";
|
|
72
|
+
import "core-js/modules/esnext.set.reduce.js";
|
|
73
|
+
import "core-js/modules/esnext.set.some.js";
|
|
74
|
+
import "core-js/modules/esnext.set.symmetric-difference.js";
|
|
75
|
+
import "core-js/modules/esnext.set.union.js";
|
|
2
76
|
import { c as _c } from "react/compiler-runtime"; /* global document */
|
|
3
77
|
import { Suspense, lazy, useInsertionEffect } from "react";
|
|
4
78
|
import { Barrier } from "@dr.pogodin/js-utils";
|
|
@@ -85,7 +159,7 @@ export async function bookStyleSheets(chunkName, chunkGroups, refCount) {
|
|
|
85
159
|
for (const asset of assets) {
|
|
86
160
|
if (asset.endsWith(".css")) {
|
|
87
161
|
const promise = bookStyleSheet(asset, loadedSheets, refCount);
|
|
88
|
-
if (promise)
|
|
162
|
+
if (promise) promises.push(promise);
|
|
89
163
|
}
|
|
90
164
|
}
|
|
91
165
|
return promises.length ? Promise.allSettled(promises).then() : Promise.resolve();
|
|
@@ -241,7 +315,7 @@ export default function splitComponent({
|
|
|
241
315
|
chunks
|
|
242
316
|
} = ssrContext;
|
|
243
317
|
if (!chunks.includes(chunkName)) {
|
|
244
|
-
|
|
318
|
+
chunks.push(chunkName);
|
|
245
319
|
}
|
|
246
320
|
} else {
|
|
247
321
|
if (!clientChunkGroups) {
|