@dr.pogodin/react-utils 1.49.0 → 1.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.scripts.config.js +19 -0
- package/build/development/client/getInj.js +18 -29
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +11 -14
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +9 -17
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +26 -4
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +15 -20
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +142 -160
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +150 -197
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +63 -86
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +72 -87
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/shared/components/Button/index.js +8 -17
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +12 -5
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +54 -58
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +16 -24
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +2 -5
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +28 -41
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +2 -3
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +19 -20
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +12 -28
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +11 -12
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +46 -68
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +21 -28
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +21 -25
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +1 -3
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +6 -7
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +7 -9
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +23 -27
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +4 -4
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +2 -5
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/utils/config.js +11 -15
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +1 -7
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +2 -2
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +15 -24
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +4 -9
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +17 -23
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +48 -77
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +48 -72
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +67 -74
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +25 -28
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +22 -29
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js.map +1 -1
- package/build/production/index.js +26 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js.map +1 -1
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +2 -2
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +20 -3
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/shared/components/Checkbox/index.d.ts +3 -2
- package/build/types-code/shared/components/GenericLink/index.d.ts +0 -1
- package/build/types-scss/src/shared/components/Checkbox/theme.scss.d.ts +2 -0
- package/build/web/client/getInj.js +10 -70
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/client/index.js +2 -27
- package/build/web/client/index.js.map +1 -1
- package/build/web/client/init.js +10 -44
- package/build/web/client/init.js.map +1 -1
- package/build/web/index.js +26 -6
- package/build/web/index.js.map +1 -1
- package/build/web/server/Cache.js +3 -41
- package/build/web/server/Cache.js.map +1 -1
- package/build/web/server/index.js +7 -78
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/renderer.js +61 -420
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +38 -212
- package/build/web/server/server.js.map +1 -1
- package/build/web/server/utils/errors.js +9 -48
- package/build/web/server/utils/errors.js.map +1 -1
- package/build/web/server/utils/index.js +1 -2
- package/build/web/server/utils/index.js.map +1 -1
- package/build/web/shared/components/Button/index.js +12 -101
- package/build/web/shared/components/Button/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/index.js +1 -35
- package/build/web/shared/components/Checkbox/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/theme.scss +22 -0
- package/build/web/shared/components/GenericLink/index.js +12 -65
- package/build/web/shared/components/GenericLink/index.js.map +1 -1
- package/build/web/shared/components/GenericLink/style.scss +1 -0
- package/build/web/shared/components/Input/index.js +11 -69
- package/build/web/shared/components/Input/index.js.map +1 -1
- package/build/web/shared/components/Link.js +2 -12
- package/build/web/shared/components/Link.js.map +1 -1
- package/build/web/shared/components/Modal/index.js +10 -130
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/components/NavLink.js +2 -10
- package/build/web/shared/components/NavLink.js.map +1 -1
- package/build/web/shared/components/PageLayout/index.js +2 -27
- package/build/web/shared/components/PageLayout/index.js.map +1 -1
- package/build/web/shared/components/TextArea/index.js +21 -106
- package/build/web/shared/components/TextArea/index.js.map +1 -1
- package/build/web/shared/components/Throbber/index.js +2 -24
- package/build/web/shared/components/Throbber/index.js.map +1 -1
- package/build/web/shared/components/WithTooltip/Tooltip.js +16 -145
- package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/web/shared/components/WithTooltip/index.js +12 -104
- package/build/web/shared/components/WithTooltip/index.js.map +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js +5 -43
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/web/shared/components/index.js +1 -15
- package/build/web/shared/components/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +6 -81
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +7 -122
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js +7 -68
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +1 -49
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/web/shared/components/selectors/common.js +1 -10
- package/build/web/shared/components/selectors/common.js.map +1 -1
- package/build/web/shared/components/selectors/index.js +1 -3
- package/build/web/shared/components/selectors/index.js.map +1 -1
- package/build/web/shared/utils/config.js +6 -40
- package/build/web/shared/utils/config.js.map +1 -1
- package/build/web/shared/utils/globalState.js +2 -11
- package/build/web/shared/utils/globalState.js.map +1 -1
- package/build/web/shared/utils/index.js +1 -9
- package/build/web/shared/utils/index.js.map +1 -1
- package/build/web/shared/utils/isomorphy/buildInfo.js +4 -25
- package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/web/shared/utils/isomorphy/environment-check.js +3 -9
- package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/web/shared/utils/isomorphy/index.js +5 -27
- package/build/web/shared/utils/isomorphy/index.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv.js +51 -221
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/web/shared/utils/jest/global.js +1 -3
- package/build/web/shared/utils/jest/global.js.map +1 -1
- package/build/web/shared/utils/jest/index.js +27 -146
- package/build/web/shared/utils/jest/index.js.map +1 -1
- package/build/web/shared/utils/splitComponent.js +34 -197
- package/build/web/shared/utils/splitComponent.js.map +1 -1
- package/build/web/shared/utils/time.js +5 -69
- package/build/web/shared/utils/time.js.map +1 -1
- package/build/web/shared/utils/webpack.js +6 -53
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/webpack.js +1 -1
- package/eslint.config.mjs +1 -0
- package/package.json +10 -13
- package/bin/build.js +0 -236
- package/config/webpack/lib-base.d.ts +0 -22
- package/config/webpack/lib-base.js +0 -167
- package/config/webpack/lib-development.d.ts +0 -5
- package/config/webpack/lib-development.js +0 -35
- package/config/webpack/lib-production.d.ts +0 -5
- package/config/webpack/lib-production.js +0 -42
- package/webpack.config.ts +0 -49
|
@@ -24,7 +24,8 @@ import"core-js/modules/es.set.difference.v2.js";import"core-js/modules/es.set.in
|
|
|
24
24
|
* the reference counter).
|
|
25
25
|
* @param {string} chunkName
|
|
26
26
|
*/export function freeStyleSheets(chunkName,chunkGroups){const assets=chunkGroups[chunkName];if(!assets)return;for(const asset of assets){if(asset.endsWith(".css")){const path=`${getPublicPath()}/${asset}`;const pathRefCount=refCounts[path];if(pathRefCount){if(pathRefCount<=1){document.head.querySelector(`link[href="${path}"]`).remove();delete refCounts[path];}else refCounts[path]=pathRefCount-1;}}}}// Holds the set of chunk names already used for splitComponent() calls.
|
|
27
|
-
const usedChunkNames=new Set
|
|
27
|
+
// const usedChunkNames = new Set();
|
|
28
|
+
/**
|
|
28
29
|
* Given an async component retrieval function `getComponent()` it creates
|
|
29
30
|
* a special "code split" component, which uses <Suspense> to asynchronously
|
|
30
31
|
* load on demand the code required by `getComponent()`.
|
|
@@ -33,8 +34,24 @@ const usedChunkNames=new Set;/**
|
|
|
33
34
|
* @param {function} options.getComponent
|
|
34
35
|
* @param {React.Element} [options.placeholder]
|
|
35
36
|
* @return {React.ElementType}
|
|
36
|
-
*/export default function splitComponent({chunkName,getComponent,placeholder}){//
|
|
37
|
-
|
|
37
|
+
*/export default function splitComponent({chunkName,getComponent,placeholder}){// TODO: For now I commented out this safeguard check, as I am not sure how
|
|
38
|
+
// to easily make it work: it should not be triggered in HMR mode, but if I
|
|
39
|
+
// add the code relying on import.meta, it fails in Jest environment, because
|
|
40
|
+
// Jest does not support ES modules yet, and import.meta is not support in
|
|
41
|
+
// CommonJS modules, and the "babel-plugin-transform-import-meta" plugin
|
|
42
|
+
// we use to workaround this issue for import.meta.dirname, etc. does not
|
|
43
|
+
// transform import.meta.webpackHot
|
|
44
|
+
// The correct usage of splitComponent() assumes a single call per chunk.
|
|
45
|
+
// if (usedChunkNames.has(chunkName)
|
|
46
|
+
// When HMR happens splitComponent() ends up getting called again for some
|
|
47
|
+
// chunks, thus we should not throw this error. Not sure, if we need to do
|
|
48
|
+
// some additional handling in that case, or just not throwing is all we
|
|
49
|
+
// need.
|
|
50
|
+
// && !import.meta.webpackHot
|
|
51
|
+
// ) {
|
|
52
|
+
// throw Error(`Repeated splitComponent() call for the chunk "${chunkName}"`);
|
|
53
|
+
// } else usedChunkNames.add(chunkName);
|
|
54
|
+
const LazyComponent=/*#__PURE__*/lazy(async()=>{const clientChunkGroups=await getClientChunkGroups();// On the client side we can check right away if the chunk name is known.
|
|
38
55
|
if(IS_CLIENT_SIDE){if(!clientChunkGroups)throw Error("Internal error");assertChunkName(chunkName,clientChunkGroups);}const resolved=await getComponent();const Component="default"in resolved?resolved.default:resolved;// This pre-loads necessary stylesheets prior to the first mount of
|
|
39
56
|
// the component (the lazy load function is executed by React one at
|
|
40
57
|
// the frist mount).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitComponent.js","names":["Suspense","lazy","useInsertionEffect","Barrier","getSsrContext","IS_CLIENT_SIDE","IS_SERVER_SIDE","getBuildInfo","jsx","_jsx","getClientChunkGroups","undefined","default","getInj","inj","CHUNK_GROUPS","refCounts","getPublicPath","publicPath","bookStyleSheet","name","loadedSheets","refCount","res","path","fullPath","document","location","origin","has","link","querySelector","createElement","setAttribute","head","appendChild","addEventListener","Error","resolve","current","getLoadedStyleSheets","Set","styleSheets","href","add","assertChunkName","chunkName","chunkGroups","bookStyleSheets","promises","assets","Promise","asset","endsWith","promise","push","length","allSettled","then","freeStyleSheets","pathRefCount","remove","usedChunkNames","splitComponent","getComponent","placeholder","LazyComponent","clientChunkGroups","resolved","Component","Wrapper","children","ref","rest","chunks","includes","CodeSplit","fallback"],"sources":["../../../../src/shared/utils/splitComponent.tsx"],"sourcesContent":["/* global document */\n\nimport {\n type ComponentType,\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n Suspense,\n lazy,\n useInsertionEffect,\n} from 'react';\n\nimport { Barrier } from '@dr.pogodin/js-utils';\n\nimport { type ChunkGroupsT, getSsrContext } from './globalState';\n\nimport {\n IS_CLIENT_SIDE,\n IS_SERVER_SIDE,\n getBuildInfo,\n} from './isomorphy';\n\nfunction getClientChunkGroups(): Promise<ChunkGroupsT> | undefined {\n if (!IS_CLIENT_SIDE) return undefined;\n\n return (async () => {\n const { default: getInj } = await import(/* webpackChunkName: \"react-utils-client-side-code\" */ '../../client/getInj');\n\n const inj = await getInj();\n return inj.CHUNK_GROUPS ?? {};\n })();\n}\n\nconst refCounts: Record<string, number> = {};\n\nfunction getPublicPath() {\n return getBuildInfo().publicPath;\n}\n\n/**\n * Client-side only! Ensures the specified CSS stylesheet is loaded into\n * the document; loads if it is missing; and does simple reference counting\n * to facilitate future clean-up.\n * @param name\n * @param loadedSheets\n * @param refCount\n * @return\n */\nfunction bookStyleSheet(\n name: string,\n loadedSheets: Set<string>,\n refCount: boolean,\n): Promise<void> | undefined {\n let res: Barrier<void> | undefined;\n const path = `${getPublicPath()}/${name}`;\n const fullPath = `${document.location.origin}${path}`;\n\n if (!loadedSheets.has(fullPath)) {\n let link = document.querySelector(`link[href=\"${path}\"]`);\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', path);\n document.head.appendChild(link);\n }\n\n res = new Barrier<void>();\n link.addEventListener('load', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n link.addEventListener('error', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n }\n\n if (refCount) {\n const current = refCounts[path] ?? 0;\n refCounts[path] = 1 + current;\n }\n\n return res;\n}\n\n/**\n * Generates the set of URLs for currently loaded, linked stylesheets.\n * @return\n */\nfunction getLoadedStyleSheets(): Set<string> {\n const res = new Set<string>();\n const { styleSheets } = document;\n for (const { href } of styleSheets) {\n if (href) res.add(href);\n }\n return res;\n}\n\nfunction assertChunkName(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n if (chunkGroups[chunkName]) return;\n throw Error(`Unknown chunk name \"${chunkName}\"`);\n}\n\n/**\n * Client-side only! Ensures all CSS stylesheets required for the specified\n * code chunk are loaded into the document; loads the missing ones; and does\n * simple reference counting to facilitate future clean-up.\n * @param chunkName Chunk name.\n * @param refCount\n * @return Resolves once all pending stylesheets, necessary for\n * the chunk, are either loaded, or failed to load.\n */\nexport async function bookStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n refCount: boolean,\n): Promise<void> {\n const promises = [];\n const assets = chunkGroups[chunkName];\n if (!assets) return Promise.resolve();\n\n const loadedSheets = getLoadedStyleSheets();\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const promise = bookStyleSheet(asset, loadedSheets, refCount);\n if (promise) promises.push(promise);\n }\n }\n\n return promises.length\n ? Promise.allSettled(promises).then()\n : Promise.resolve();\n}\n\n/**\n * Client-side only! Frees from the document all CSS stylesheets that are\n * required by the specified chunk, and have reference counter equal to one\n * (for chunks with larger reference counter values, it just decrements\n * the reference counter).\n * @param {string} chunkName\n */\nexport function freeStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n): void {\n const assets = chunkGroups[chunkName];\n if (!assets) return;\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const path = `${getPublicPath()}/${asset}`;\n\n const pathRefCount = refCounts[path];\n if (pathRefCount) {\n if (pathRefCount <= 1) {\n document.head.querySelector(`link[href=\"${path}\"]`)!.remove();\n delete refCounts[path];\n } else refCounts[path] = pathRefCount - 1;\n }\n }\n }\n}\n\n// Holds the set of chunk names already used for splitComponent() calls.\nconst usedChunkNames = new Set();\n\ntype ComponentOrModule<PropsT> = ComponentType<PropsT> | {\n default: ComponentType<PropsT>;\n};\n\ntype GenericComponentPropsT = {\n children?: ReactNode;\n ref?: RefObject<unknown>;\n\n // NOTE: This is necessary, as without it this type (with only optional\n // fields) will be conisdered as \"weak\" by TypeScript, and it will be\n // a error to assign to it any type that does not use \"children\", or \"ref\".\n [propName: string]: unknown;\n};\n\n/**\n * Given an async component retrieval function `getComponent()` it creates\n * a special \"code split\" component, which uses <Suspense> to asynchronously\n * load on demand the code required by `getComponent()`.\n * @param options\n * @param options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent<\n ComponentPropsT extends GenericComponentPropsT,\n>({\n chunkName,\n getComponent,\n placeholder,\n}: {\n chunkName: string;\n getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;\n placeholder?: ReactNode;\n}): FunctionComponent<ComponentPropsT> {\n // The correct usage of splitComponent() assumes a single call per chunk.\n if (usedChunkNames.has(chunkName)) {\n throw Error(`Repeated splitComponent() call for the chunk \"${chunkName}\"`);\n } else usedChunkNames.add(chunkName);\n\n const LazyComponent = lazy(async () => {\n const clientChunkGroups = await getClientChunkGroups();\n\n // On the client side we can check right away if the chunk name is known.\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n assertChunkName(chunkName, clientChunkGroups);\n }\n\n const resolved = await getComponent();\n const Component = 'default' in resolved ? resolved.default : resolved;\n\n // This pre-loads necessary stylesheets prior to the first mount of\n // the component (the lazy load function is executed by React one at\n // the frist mount).\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n await bookStyleSheets(chunkName, clientChunkGroups, false);\n }\n\n const Wrapper: FunctionComponent<ComponentPropsT> = ({\n children,\n ref,\n ...rest\n }) => {\n // On the server side we'll assert the chunk name here,\n // and also push it to the SSR chunks array.\n if (IS_SERVER_SIDE) {\n const { chunkGroups, chunks } = getSsrContext()!;\n assertChunkName(chunkName, chunkGroups);\n if (!chunks.includes(chunkName)) chunks.push(chunkName);\n }\n\n // This takes care about stylesheets management every time an instance of\n // this component is mounted / unmounted.\n useInsertionEffect(() => {\n if (!clientChunkGroups) throw Error('Internal error');\n void bookStyleSheets(chunkName, clientChunkGroups, true);\n return () => {\n freeStyleSheets(chunkName, clientChunkGroups);\n };\n }, []);\n\n return (\n <Component\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...(rest as unknown as ComponentPropsT)}\n ref={ref}\n >\n {children}\n </Component>\n );\n };\n\n return { default: Wrapper };\n });\n\n const CodeSplit: React.FunctionComponent<ComponentPropsT> = ({\n children,\n ...rest\n }: ComponentPropsT) => (\n <Suspense fallback={placeholder}>\n <LazyComponent\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest as Parameters<typeof LazyComponent>[0]}\n >\n {children}\n </LazyComponent>\n </Suspense>\n );\n\n return CodeSplit;\n}\n"],"mappings":"6rBAAA,qBAEA,OAKEA,QAAQ,CACRC,IAAI,CACJC,kBAAkB,KACb,OAAO,CAEd,OAASC,OAAO,KAAQ,sBAAsB,QAElBC,aAAa,+BAGvCC,cAAc,CACdC,cAAc,CACdC,YAAY,4BACO,OAAAC,GAAA,IAAAC,IAAA,yBAErB,QAAS,CAAAC,oBAAoBA,CAAA,CAAsC,CACjE,GAAI,CAACL,cAAc,CAAE,MAAO,CAAAM,SAAS,CAErC,MAAO,CAAC,SAAY,CAClB,KAAM,CAAEC,OAAO,CAAEC,MAAO,CAAC,CAAG,KAAM,O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AE,CAChDyC,eAAe,CAACC,SAAS,CAAEC,WAAW,CAAC,CACvC,GAAI,CAAC2B,MAAM,CAACC,QAAQ,CAAC7B,SAAS,CAAC,CAAE4B,MAAM,CAACnB,IAAI,CAACT,SAAS,CAAC,CACzD,CAEA;AACA;AACA5C,kBAAkB,CAAC,IAAM,CACvB,GAAI,CAACiE,iBAAiB,CAAE,KAAM,CAAA9B,KAAK,CAAC,gBAAgB,CAAC,CACrD,IAAK,CAAAW,eAAe,CAACF,SAAS,CAAEqB,iBAAiB,CAAE,IAAI,CAAC,CACxD,MAAO,IAAM,CACXR,eAAe,CAACb,SAAS,CAAEqB,iBAAiB,CAAC,CAC/C,CAAC,CACH,CAAC,CAAE,EAAE,CAAC,CAEN,mBACE1D,IAAA,CAAC4D,SACC;AAAA,KACKI,IAAI,CACTD,GAAG,CAAEA,GAAI,CAAAD,QAAA,CAERA,QAAQ,CACA,CAAC,CAEhB,CAAC,CAED,MAAO,CAAE3D,OAAO,CAAE0D,OAAQ,CAAC,CAC7B,CAAC,CAAC,CAEF,KAAM,CAAAM,SAAmD,CAAGA,CAAC,CAC3DL,QAAQ,CACR,GAAGE,IACY,CAAC,gBAChBhE,IAAA,CAACT,QAAQ,EAAC6E,QAAQ,CAAEZ,WAAY,CAAAM,QAAA,cAC9B9D,IAAA,CAACyD,aACC;AAAA,KACIO,IAAI,CAAAF,QAAA,CAEPA,QAAQ,CACI,CAAC,CACR,CACX,CAED,MAAO,CAAAK,SAAS,CAClB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"splitComponent.js","names":["Suspense","lazy","useInsertionEffect","Barrier","getSsrContext","IS_CLIENT_SIDE","IS_SERVER_SIDE","getBuildInfo","jsx","_jsx","getClientChunkGroups","undefined","default","getInj","inj","CHUNK_GROUPS","refCounts","getPublicPath","publicPath","bookStyleSheet","name","loadedSheets","refCount","res","path","fullPath","document","location","origin","has","link","querySelector","createElement","setAttribute","head","appendChild","addEventListener","Error","resolve","current","getLoadedStyleSheets","Set","styleSheets","href","add","assertChunkName","chunkName","chunkGroups","bookStyleSheets","promises","assets","Promise","asset","endsWith","promise","push","length","allSettled","then","freeStyleSheets","pathRefCount","remove","splitComponent","getComponent","placeholder","LazyComponent","clientChunkGroups","resolved","Component","Wrapper","children","ref","rest","chunks","includes","CodeSplit","fallback"],"sources":["../../../../src/shared/utils/splitComponent.tsx"],"sourcesContent":["/* global document */\n\nimport {\n type ComponentType,\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n Suspense,\n lazy,\n useInsertionEffect,\n} from 'react';\n\nimport { Barrier } from '@dr.pogodin/js-utils';\n\nimport { type ChunkGroupsT, getSsrContext } from './globalState';\n\nimport {\n IS_CLIENT_SIDE,\n IS_SERVER_SIDE,\n getBuildInfo,\n} from './isomorphy';\n\nfunction getClientChunkGroups(): Promise<ChunkGroupsT> | undefined {\n if (!IS_CLIENT_SIDE) return undefined;\n\n return (async () => {\n const { default: getInj } = await import(/* webpackChunkName: \"react-utils-client-side-code\" */ '../../client/getInj');\n\n const inj = await getInj();\n return inj.CHUNK_GROUPS ?? {};\n })();\n}\n\nconst refCounts: Record<string, number> = {};\n\nfunction getPublicPath() {\n return getBuildInfo().publicPath;\n}\n\n/**\n * Client-side only! Ensures the specified CSS stylesheet is loaded into\n * the document; loads if it is missing; and does simple reference counting\n * to facilitate future clean-up.\n * @param name\n * @param loadedSheets\n * @param refCount\n * @return\n */\nfunction bookStyleSheet(\n name: string,\n loadedSheets: Set<string>,\n refCount: boolean,\n): Promise<void> | undefined {\n let res: Barrier<void> | undefined;\n const path = `${getPublicPath()}/${name}`;\n const fullPath = `${document.location.origin}${path}`;\n\n if (!loadedSheets.has(fullPath)) {\n let link = document.querySelector(`link[href=\"${path}\"]`);\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', path);\n document.head.appendChild(link);\n }\n\n res = new Barrier<void>();\n link.addEventListener('load', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n link.addEventListener('error', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n }\n\n if (refCount) {\n const current = refCounts[path] ?? 0;\n refCounts[path] = 1 + current;\n }\n\n return res;\n}\n\n/**\n * Generates the set of URLs for currently loaded, linked stylesheets.\n * @return\n */\nfunction getLoadedStyleSheets(): Set<string> {\n const res = new Set<string>();\n const { styleSheets } = document;\n for (const { href } of styleSheets) {\n if (href) res.add(href);\n }\n return res;\n}\n\nfunction assertChunkName(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n if (chunkGroups[chunkName]) return;\n throw Error(`Unknown chunk name \"${chunkName}\"`);\n}\n\n/**\n * Client-side only! Ensures all CSS stylesheets required for the specified\n * code chunk are loaded into the document; loads the missing ones; and does\n * simple reference counting to facilitate future clean-up.\n * @param chunkName Chunk name.\n * @param refCount\n * @return Resolves once all pending stylesheets, necessary for\n * the chunk, are either loaded, or failed to load.\n */\nexport async function bookStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n refCount: boolean,\n): Promise<void> {\n const promises = [];\n const assets = chunkGroups[chunkName];\n if (!assets) return Promise.resolve();\n\n const loadedSheets = getLoadedStyleSheets();\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const promise = bookStyleSheet(asset, loadedSheets, refCount);\n if (promise) promises.push(promise);\n }\n }\n\n return promises.length\n ? Promise.allSettled(promises).then()\n : Promise.resolve();\n}\n\n/**\n * Client-side only! Frees from the document all CSS stylesheets that are\n * required by the specified chunk, and have reference counter equal to one\n * (for chunks with larger reference counter values, it just decrements\n * the reference counter).\n * @param {string} chunkName\n */\nexport function freeStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n): void {\n const assets = chunkGroups[chunkName];\n if (!assets) return;\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const path = `${getPublicPath()}/${asset}`;\n\n const pathRefCount = refCounts[path];\n if (pathRefCount) {\n if (pathRefCount <= 1) {\n document.head.querySelector(`link[href=\"${path}\"]`)!.remove();\n delete refCounts[path];\n } else refCounts[path] = pathRefCount - 1;\n }\n }\n }\n}\n\n// Holds the set of chunk names already used for splitComponent() calls.\n// const usedChunkNames = new Set();\n\ntype ComponentOrModule<PropsT> = ComponentType<PropsT> | {\n default: ComponentType<PropsT>;\n};\n\ntype GenericComponentPropsT = {\n children?: ReactNode;\n ref?: RefObject<unknown>;\n\n // NOTE: This is necessary, as without it this type (with only optional\n // fields) will be conisdered as \"weak\" by TypeScript, and it will be\n // a error to assign to it any type that does not use \"children\", or \"ref\".\n [propName: string]: unknown;\n};\n\n/**\n * Given an async component retrieval function `getComponent()` it creates\n * a special \"code split\" component, which uses <Suspense> to asynchronously\n * load on demand the code required by `getComponent()`.\n * @param options\n * @param options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent<\n ComponentPropsT extends GenericComponentPropsT,\n>({\n chunkName,\n getComponent,\n placeholder,\n}: {\n chunkName: string;\n getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;\n placeholder?: ReactNode;\n}): FunctionComponent<ComponentPropsT> {\n // TODO: For now I commented out this safeguard check, as I am not sure how\n // to easily make it work: it should not be triggered in HMR mode, but if I\n // add the code relying on import.meta, it fails in Jest environment, because\n // Jest does not support ES modules yet, and import.meta is not support in\n // CommonJS modules, and the \"babel-plugin-transform-import-meta\" plugin\n // we use to workaround this issue for import.meta.dirname, etc. does not\n // transform import.meta.webpackHot\n\n // The correct usage of splitComponent() assumes a single call per chunk.\n // if (usedChunkNames.has(chunkName)\n\n // When HMR happens splitComponent() ends up getting called again for some\n // chunks, thus we should not throw this error. Not sure, if we need to do\n // some additional handling in that case, or just not throwing is all we\n // need.\n // && !import.meta.webpackHot\n // ) {\n // throw Error(`Repeated splitComponent() call for the chunk \"${chunkName}\"`);\n // } else usedChunkNames.add(chunkName);\n\n const LazyComponent = lazy(async () => {\n const clientChunkGroups = await getClientChunkGroups();\n\n // On the client side we can check right away if the chunk name is known.\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n assertChunkName(chunkName, clientChunkGroups);\n }\n\n const resolved = await getComponent();\n const Component = 'default' in resolved ? resolved.default : resolved;\n\n // This pre-loads necessary stylesheets prior to the first mount of\n // the component (the lazy load function is executed by React one at\n // the frist mount).\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n await bookStyleSheets(chunkName, clientChunkGroups, false);\n }\n\n const Wrapper: FunctionComponent<ComponentPropsT> = ({\n children,\n ref,\n ...rest\n }) => {\n // On the server side we'll assert the chunk name here,\n // and also push it to the SSR chunks array.\n if (IS_SERVER_SIDE) {\n const { chunkGroups, chunks } = getSsrContext()!;\n assertChunkName(chunkName, chunkGroups);\n if (!chunks.includes(chunkName)) chunks.push(chunkName);\n }\n\n // This takes care about stylesheets management every time an instance of\n // this component is mounted / unmounted.\n useInsertionEffect(() => {\n if (!clientChunkGroups) throw Error('Internal error');\n void bookStyleSheets(chunkName, clientChunkGroups, true);\n return () => {\n freeStyleSheets(chunkName, clientChunkGroups);\n };\n }, []);\n\n return (\n <Component\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...(rest as unknown as ComponentPropsT)}\n ref={ref}\n >\n {children}\n </Component>\n );\n };\n\n return { default: Wrapper };\n });\n\n const CodeSplit: React.FunctionComponent<ComponentPropsT> = ({\n children,\n ...rest\n }: ComponentPropsT) => (\n <Suspense fallback={placeholder}>\n <LazyComponent\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest as Parameters<typeof LazyComponent>[0]}\n >\n {children}\n </LazyComponent>\n </Suspense>\n );\n\n return CodeSplit;\n}\n"],"mappings":"6rBAAA,qBAEA,OAKEA,QAAQ,CACRC,IAAI,CACJC,kBAAkB,KACb,OAAO,CAEd,OAASC,OAAO,KAAQ,sBAAsB,CAE9C,OAA4BC,aAAa,+BAGvCC,cAAc,CACdC,cAAc,CACdC,YAAY,4BACO,OAAAC,GAAA,IAAAC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AO,CAAC,CAAGrE,aAAa,CAAC,CAAE,CAChDyC,eAAe,CAACC,SAAS,CAAEC,WAAW,CAAC,CACvC,GAAI,CAAC0B,MAAM,CAACC,QAAQ,CAAC5B,SAAS,CAAC,CAAE2B,MAAM,CAAClB,IAAI,CAACT,SAAS,CAAC,CACzD,CAEA;AACA;AACA5C,kBAAkB,CAAC,IAAM,CACvB,GAAI,CAACgE,iBAAiB,CAAE,KAAM,CAAA7B,KAAK,CAAC,gBAAgB,CAAC,CACrD,IAAK,CAAAW,eAAe,CAACF,SAAS,CAAEoB,iBAAiB,CAAE,IAAI,CAAC,CACxD,MAAO,IAAM,CACXP,eAAe,CAACb,SAAS,CAAEoB,iBAAiB,CAAC,CAC/C,CAAC,CACH,CAAC,CAAE,EAAE,CAAC,CAEN,mBACEzD,IAAA,CAAC2D,SACC;AAAA,KACKI,IAAI,CACTD,GAAG,CAAEA,GAAI,CAAAD,QAAA,CAERA,QAAQ,CACA,CAAC,CAEhB,CAAC,CAED,MAAO,CAAE1D,OAAO,CAAEyD,OAAQ,CAAC,CAC7B,CAAC,CAAC,CAEF,KAAM,CAAAM,SAAmD,CAAGA,CAAC,CAC3DL,QAAQ,CACR,GAAGE,IACY,CAAC,gBAChB/D,IAAA,CAACT,QAAQ,EAAC4E,QAAQ,CAAEZ,WAAY,CAAAM,QAAA,cAC9B7D,IAAA,CAACwD,aACC;AAAA,KACIO,IAAI,CAAAF,QAAA,CAEPA,QAAQ,CACI,CAAC,CACR,CACX,CAED,MAAO,CAAAK,SAAS,CAClB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","names":["serialize","dayjs","useEffect","DAY_MS","HOUR_MS","MIN_MS","SEC_MS","YEAR_MS","timer","useGlobalState","getSsrContext","useCurrent","autorefresh","globalStatePath","precision","now","setter","Date","timerId","update","old","neu","Math","abs","setTimeout","clearTimeout","useTimezoneOffset","cookieName","ssrContext","offset","setOffset","value","req","cookies","parseInt","date","getTimezoneOffset","document","cookie","toString","path","time","Object","assign"],"sources":["../../../../src/shared/utils/time.ts"],"sourcesContent":["import { serialize } from 'cookie';\nimport dayjs from 'dayjs';\nimport { useEffect } from 'react';\n\nimport {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n timer,\n} from '@dr.pogodin/js-utils';\n\nimport { type ForceT, useGlobalState } from '@dr.pogodin/react-global-state';\n\nimport { getSsrContext } from './globalState';\n\n/**\n * This react hook wraps Date.now() function in a SSR friendly way,\n * ensuring that all calls to useCurrent() within the same render return\n * exactly the same time (which is retrieved from Date.now() first, and\n * then stored in the global state to be reused in all other calls), which\n * is also passed and used in the first client side render, and then updated\n * with a finite precision to avoid infinite re-rendering loops.\n */\n// TODO: Should we request the state type as generic parameter, to be able\n// to verify the give globalStatePath is correct?\nexport function useCurrent({\n autorefresh = false,\n globalStatePath = 'currentTime',\n precision = 5 * SEC_MS,\n} = {}): number {\n const [now, setter] = useGlobalState<ForceT, number>(\n globalStatePath,\n Date.now,\n );\n useEffect(() => {\n let timerId: NodeJS.Timeout | undefined;\n const update = (): void => {\n setter((old) => {\n const neu = Date.now();\n return Math.abs(neu - old) > precision ? neu : old;\n });\n if (autorefresh) timerId = setTimeout(update, precision);\n };\n update();\n return (): void => {\n if (timerId) clearTimeout(timerId);\n };\n }, [autorefresh, precision, setter]);\n return now;\n}\n\n/**\n * Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.\n * This hook retrieves the offset value at the client side and uses a cookie\n * to pass it to the server in subsequent requests from that user. At the server\n * side the value from cookie is used in renders and passed back to the client\n * via the global state. Prior to the value being known (in the very first\n * request from the user, when the cookie is still missing), zero value is used\n * as the default value.\n */\n// TODO: Should we request the state type as generic parameter, to be able\n// to verify the give globalStatePath is correct?\nexport function useTimezoneOffset({\n cookieName = 'timezoneOffset',\n globalStatePath = 'timezoneOffset',\n} = {}): number {\n const ssrContext = getSsrContext(false);\n const [offset, setOffset] = useGlobalState<ForceT, number>(\n globalStatePath,\n () => {\n const value = cookieName\n && ssrContext?.req.cookies[cookieName] as string;\n return value ? parseInt(value) : 0;\n },\n );\n useEffect(() => {\n const date = new Date();\n const value = date.getTimezoneOffset();\n setOffset(value);\n if (cookieName) {\n document.cookie = serialize(cookieName, value.toString(), { path: '/' });\n }\n }, [cookieName, setOffset]);\n return offset;\n}\n\nconst time = {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n now: Date.now,\n timer,\n useCurrent,\n useTimezoneOffset,\n};\n\nexport default Object.assign(dayjs, time);\n"],"mappings":"AAAA,OAASA,SAAS,KAAQ,QAAQ,CAClC,MAAO,CAAAC,KAAK,KAAM,OAAO,CACzB,OAASC,SAAS,KAAQ,OAAO,CAEjC,OACEC,MAAM,CACNC,OAAO,CACPC,MAAM,CACNC,MAAM,CACNC,OAAO,CACPC,KAAK,KACA,sBAAsB,CAE7B,OAAsBC,cAAc,KAAQ,gCAAgC,
|
|
1
|
+
{"version":3,"file":"time.js","names":["serialize","dayjs","useEffect","DAY_MS","HOUR_MS","MIN_MS","SEC_MS","YEAR_MS","timer","useGlobalState","getSsrContext","useCurrent","autorefresh","globalStatePath","precision","now","setter","Date","timerId","update","old","neu","Math","abs","setTimeout","clearTimeout","useTimezoneOffset","cookieName","ssrContext","offset","setOffset","value","req","cookies","parseInt","date","getTimezoneOffset","document","cookie","toString","path","time","Object","assign"],"sources":["../../../../src/shared/utils/time.ts"],"sourcesContent":["import { serialize } from 'cookie';\nimport dayjs from 'dayjs';\nimport { useEffect } from 'react';\n\nimport {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n timer,\n} from '@dr.pogodin/js-utils';\n\nimport { type ForceT, useGlobalState } from '@dr.pogodin/react-global-state';\n\nimport { getSsrContext } from './globalState';\n\n/**\n * This react hook wraps Date.now() function in a SSR friendly way,\n * ensuring that all calls to useCurrent() within the same render return\n * exactly the same time (which is retrieved from Date.now() first, and\n * then stored in the global state to be reused in all other calls), which\n * is also passed and used in the first client side render, and then updated\n * with a finite precision to avoid infinite re-rendering loops.\n */\n// TODO: Should we request the state type as generic parameter, to be able\n// to verify the give globalStatePath is correct?\nexport function useCurrent({\n autorefresh = false,\n globalStatePath = 'currentTime',\n precision = 5 * SEC_MS,\n} = {}): number {\n const [now, setter] = useGlobalState<ForceT, number>(\n globalStatePath,\n Date.now,\n );\n useEffect(() => {\n let timerId: NodeJS.Timeout | undefined;\n const update = (): void => {\n setter((old) => {\n const neu = Date.now();\n return Math.abs(neu - old) > precision ? neu : old;\n });\n if (autorefresh) timerId = setTimeout(update, precision);\n };\n update();\n return (): void => {\n if (timerId) clearTimeout(timerId);\n };\n }, [autorefresh, precision, setter]);\n return now;\n}\n\n/**\n * Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.\n * This hook retrieves the offset value at the client side and uses a cookie\n * to pass it to the server in subsequent requests from that user. At the server\n * side the value from cookie is used in renders and passed back to the client\n * via the global state. Prior to the value being known (in the very first\n * request from the user, when the cookie is still missing), zero value is used\n * as the default value.\n */\n// TODO: Should we request the state type as generic parameter, to be able\n// to verify the give globalStatePath is correct?\nexport function useTimezoneOffset({\n cookieName = 'timezoneOffset',\n globalStatePath = 'timezoneOffset',\n} = {}): number {\n const ssrContext = getSsrContext(false);\n const [offset, setOffset] = useGlobalState<ForceT, number>(\n globalStatePath,\n () => {\n const value = cookieName\n && ssrContext?.req.cookies[cookieName] as string;\n return value ? parseInt(value) : 0;\n },\n );\n useEffect(() => {\n const date = new Date();\n const value = date.getTimezoneOffset();\n setOffset(value);\n if (cookieName) {\n document.cookie = serialize(cookieName, value.toString(), { path: '/' });\n }\n }, [cookieName, setOffset]);\n return offset;\n}\n\nconst time = {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n now: Date.now,\n timer,\n useCurrent,\n useTimezoneOffset,\n};\n\nexport default Object.assign(dayjs, time);\n"],"mappings":"AAAA,OAASA,SAAS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A,CAAC,CAChCC,UAAU,CAAG,gBAAgB,CAC7Bd,eAAe,CAAG,gBACpB,CAAC,CAAG,CAAC,CAAC,CAAU,CACd,KAAM,CAAAe,UAAU,CAAGlB,aAAa,CAAC,KAAK,CAAC,CACvC,KAAM,CAACmB,MAAM,CAAEC,SAAS,CAAC,CAAGrB,cAAc,CACxCI,eAAe,CACf,IAAM,CACJ,KAAM,CAAAkB,KAAK,CAAGJ,UAAU,EACnBC,UAAU,EAAEI,GAAG,CAACC,OAAO,CAACN,UAAU,CAAW,CAClD,MAAO,CAAAI,KAAK,CAAGG,QAAQ,CAACH,KAAK,CAAC,CAAG,CAAC,CACpC,CACF,CAAC,CACD7B,SAAS,CAAC,IAAM,CACd,KAAM,CAAAiC,IAAI,CAAG,GAAI,CAAAlB,IAAM,CACvB,KAAM,CAAAc,KAAK,CAAGI,IAAI,CAACC,iBAAiB,CAAC,CAAC,CACtCN,SAAS,CAACC,KAAK,CAAC,CAChB,GAAIJ,UAAU,CAAE,CACdU,QAAQ,CAACC,MAAM,CAAGtC,SAAS,CAAC2B,UAAU,CAAEI,KAAK,CAACQ,QAAQ,CAAC,CAAC,CAAE,CAAEC,IAAI,CAAE,GAAI,CAAC,CAAC,CAC1E,CACF,CAAC,CAAE,CAACb,UAAU,CAAEG,SAAS,CAAC,CAAC,CAC3B,MAAO,CAAAD,MAAM,CACf,CAEA,KAAM,CAAAY,IAAI,CAAG,CACXtC,MAAM,CACNC,OAAO,CACPC,MAAM,CACNC,MAAM,CACNC,OAAO,CACPQ,GAAG,CAAEE,IAAI,CAACF,GAAG,CACbP,KAAK,CACLG,UAAU,CACVe,iBACF,CAAC,CAED,cAAe,CAAAgB,MAAM,CAACC,MAAM,CAAC1C,KAAK,CAAEwC,IAAI,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack.js","names":["createRequire","IS_CLIENT_SIDE","IS_SERVER_SIDE","require","import","meta","url","requireWeak","modulePath","basePathOrOptions","basePath","ops","resolve","path","module","default","def","named","res","Object","entries","forEach","name","value","assigned","undefined","Error","resolveWeak"],"sources":["../../../../src/shared/utils/webpack.ts"],"sourcesContent":["import type PathNS from 'node:path';\n\n// eslint-disable-next-line import/enforce-node-protocol-usage, perfectionist/sort-imports\nimport { createRequire } from 'module';\n\nimport { IS_CLIENT_SIDE, IS_SERVER_SIDE } from './isomorphy';\n\ntype RequireWeakOptionsT = {\n basePath?: string;\n};\n\ntype RequireWeakResT<T> = T extends { default: infer D }\n ? (D extends null | undefined ? T : D & Omit<T, 'default'>)\n : T;\n\nlet require: ((url: string) => unknown) | undefined;\n\nif (IS_SERVER_SIDE) require = createRequire(import.meta.url);\n\n/**\n * Requires the specified module without including it into the bundle during\n * Webpack build.\n * @param modulePath\n * @param [basePath]\n * @return Required module.\n */\nexport function requireWeak<T extends object>(\n modulePath: string,\n\n // TODO: For now `basePath` can be provided directly as a string here,\n // for backward compatibility. Deprecate it in future, if any other\n // breaking changes are done for requireWeak().\n basePathOrOptions?: RequireWeakOptionsT | string,\n): RequireWeakResT<T> | null {\n if (IS_CLIENT_SIDE) return null;\n\n let basePath: string | undefined;\n let ops: RequireWeakOptionsT;\n if (typeof basePathOrOptions === 'string') {\n basePath = basePathOrOptions;\n } else {\n ops = basePathOrOptions ?? {};\n ({ basePath } = ops);\n }\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const { resolve } = require!('node:path') as typeof PathNS;\n\n const path = basePath ? resolve(basePath, modulePath) : modulePath;\n\n const module = require!(path) as T;\n\n if (!('default' in module) || !module.default) return module as RequireWeakResT<T>;\n\n const { default: def, ...named } = module;\n\n const res = def as RequireWeakResT<T>;\n\n Object.entries(named).forEach(([name, value]) => {\n const assigned = res[name as keyof RequireWeakResT<T>];\n if (assigned === undefined) {\n (res[name as keyof RequireWeakResT<T>] as unknown) = value;\n } else if (assigned !== value) {\n throw Error('Conflict between default and named exports');\n }\n });\n return res;\n}\n\n/**\n * Resolves specified module path with help of Babel's module resolver.\n * Yes, the function itself just returns its argument to the caller, but Babel\n * is configured to resolve the first argument of resolveWeak(..) function, thus\n * the result will be the resolved path.\n * @param {string} modulePath\n * @return {string} Absolute or relative path to the module.\n */\nexport function resolveWeak(modulePath: string): string {\n return modulePath;\n}\n"],"mappings":"mJAEA;AACA,OAASA,aAAa,KAAQ,QAAQ,
|
|
1
|
+
{"version":3,"file":"webpack.js","names":["createRequire","IS_CLIENT_SIDE","IS_SERVER_SIDE","require","import","meta","url","requireWeak","modulePath","basePathOrOptions","basePath","ops","resolve","path","module","default","def","named","res","Object","entries","forEach","name","value","assigned","undefined","Error","resolveWeak"],"sources":["../../../../src/shared/utils/webpack.ts"],"sourcesContent":["import type PathNS from 'node:path';\n\n// eslint-disable-next-line import/enforce-node-protocol-usage, perfectionist/sort-imports\nimport { createRequire } from 'module';\n\nimport { IS_CLIENT_SIDE, IS_SERVER_SIDE } from './isomorphy';\n\ntype RequireWeakOptionsT = {\n basePath?: string;\n};\n\ntype RequireWeakResT<T> = T extends { default: infer D }\n ? (D extends null | undefined ? T : D & Omit<T, 'default'>)\n : T;\n\nlet require: ((url: string) => unknown) | undefined;\n\nif (IS_SERVER_SIDE) require = createRequire(import.meta.url);\n\n/**\n * Requires the specified module without including it into the bundle during\n * Webpack build.\n * @param modulePath\n * @param [basePath]\n * @return Required module.\n */\nexport function requireWeak<T extends object>(\n modulePath: string,\n\n // TODO: For now `basePath` can be provided directly as a string here,\n // for backward compatibility. Deprecate it in future, if any other\n // breaking changes are done for requireWeak().\n basePathOrOptions?: RequireWeakOptionsT | string,\n): RequireWeakResT<T> | null {\n if (IS_CLIENT_SIDE) return null;\n\n let basePath: string | undefined;\n let ops: RequireWeakOptionsT;\n if (typeof basePathOrOptions === 'string') {\n basePath = basePathOrOptions;\n } else {\n ops = basePathOrOptions ?? {};\n ({ basePath } = ops);\n }\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const { resolve } = require!('node:path') as typeof PathNS;\n\n const path = basePath ? resolve(basePath, modulePath) : modulePath;\n\n const module = require!(path) as T;\n\n if (!('default' in module) || !module.default) return module as RequireWeakResT<T>;\n\n const { default: def, ...named } = module;\n\n const res = def as RequireWeakResT<T>;\n\n Object.entries(named).forEach(([name, value]) => {\n const assigned = res[name as keyof RequireWeakResT<T>];\n if (assigned === undefined) {\n (res[name as keyof RequireWeakResT<T>] as unknown) = value;\n } else if (assigned !== value) {\n throw Error('Conflict between default and named exports');\n }\n });\n return res;\n}\n\n/**\n * Resolves specified module path with help of Babel's module resolver.\n * Yes, the function itself just returns its argument to the caller, but Babel\n * is configured to resolve the first argument of resolveWeak(..) function, thus\n * the result will be the resolved path.\n * @param {string} modulePath\n * @return {string} Absolute or relative path to the module.\n */\nexport function resolveWeak(modulePath: string): string {\n return modulePath;\n}\n"],"mappings":"mJAEA;AACA,OAASA,aAAa,KAAQ,QAAQ,CAEtC,OAASC,cAAc,CAAEC,cAAc,4BAUvC,GAAI,CAAAC,OAA+C,CAEnD,GAAID,cAAc,CAAEC,OAAO,CAAGH,aAAa,CAACI,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAE5D;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAC,WAAWA,CACzBC,UAAkB,CAElB;AACA;AACA;AACAC,iBAAgD,CACrB,CAC3B,GAAIR,cAAc,CAAE,MAAO,KAAI,CAE/B,GAAI,CAAAS,QAA4B,CAChC,GAAI,CAAAC,GAAwB,CAC5B,GAAI,MAAO,CAAAF,iBAAiB,GAAK,QAAQ,CAAE,CACzCC,QAAQ,CAAGD,iBAAiB,CAC9B,CAAC,IAAM,CACLE,GAAG,CAAGF,iBAAiB,EAAI,CAAC,CAAC,CAC7B,CAAC,CAAEC,QAAS,CAAC,CAAGC,GAAG,EACrB,CAEA;AACA,KAAM,CAAEC,OAAQ,CAAC,CAAGT,OAAO,CAAE,WAAW,CAAkB,CAE1D,KAAM,CAAAU,IAAI,CAAGH,QAAQ,CAAGE,OAAO,CAACF,QAAQ,CAAEF,UAAU,CAAC,CAAGA,UAAU,CAElE,KAAM,CAAAM,MAAM,CAAGX,OAAO,CAAEU,IAAI,CAAM,CAElC,GAAI,EAAE,SAAS,EAAI,CAAAC,MAAM,CAAC,EAAI,CAACA,MAAM,CAACC,OAAO,CAAE,MAAO,CAAAD,MAAM,CAE5D,KAAM,CAAEC,OAAO,CAAEC,GAAG,CAAE,GAAGC,KAAM,CAAC,CAAGH,MAAM,CAEzC,KAAM,CAAAI,GAAG,CAAGF,GAAyB,CAErCG,MAAM,CAACC,OAAO,CAACH,KAAK,CAAC,CAACI,OAAO,CAAC,CAAC,CAACC,IAAI,CAAEC,KAAK,CAAC,GAAK,CAC/C,KAAM,CAAAC,QAAQ,CAAGN,GAAG,CAACI,IAAI,CAA6B,CACtD,GAAIE,QAAQ,GAAKC,SAAS,CAAE,CACzBP,GAAG,CAACI,IAAI,CAA6B,CAAeC,KAAK,CAC5D,CAAC,IAAM,IAAIC,QAAQ,GAAKD,KAAK,CAAE,CAC7B,KAAM,CAAAG,KAAK,CAAC,4CAA4C,CAAC,CAC3D,CACF,CAAC,CAAC,CACF,MAAO,CAAAR,GAAG,CACZ,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAS,WAAWA,CAACnB,UAAkB,CAAU,CACtD,MAAO,CAAAA,UAAU,CACnB","ignoreList":[]}
|
|
@@ -3,10 +3,11 @@ import { type Theme } from '@dr.pogodin/react-themes';
|
|
|
3
3
|
type PropT<ValueT> = {
|
|
4
4
|
checked?: ValueT;
|
|
5
5
|
disabled?: boolean;
|
|
6
|
+
error?: ReactNode;
|
|
6
7
|
label?: React.ReactNode;
|
|
7
8
|
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
8
9
|
testId?: string;
|
|
9
|
-
theme?: Theme<'checkbox' | 'container' | 'disabled' | 'indeterminate' | 'label'>;
|
|
10
|
+
theme?: Theme<'checkbox' | 'container' | 'disabled' | 'error' | 'errorMessage' | 'indeterminate' | 'label'>;
|
|
10
11
|
};
|
|
11
|
-
declare const Checkbox: <ValueT extends "indeterminate" | boolean = boolean>({ checked, disabled, label, onChange, testId, theme, }: PropT<ValueT>) => ReactNode;
|
|
12
|
+
declare const Checkbox: <ValueT extends "indeterminate" | boolean = boolean>({ checked, disabled, error, label, onChange, testId, theme, }: PropT<ValueT>) => ReactNode;
|
|
12
13
|
export default Checkbox;
|
|
@@ -3,6 +3,8 @@ export declare const checkbox: string;
|
|
|
3
3
|
export declare const container: string;
|
|
4
4
|
export declare const context: string;
|
|
5
5
|
export declare const disabled: string;
|
|
6
|
+
export declare const error: string;
|
|
7
|
+
export declare const errorMessage: string;
|
|
6
8
|
export declare const hoc: string;
|
|
7
9
|
export declare const indeterminate: string;
|
|
8
10
|
export declare const label: string;
|
|
@@ -1,71 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { SEC_MS, timer } from '@dr.pogodin/js-utils';
|
|
13
|
-
import { getBuildInfo } from "../shared/utils/isomorphy/buildInfo";
|
|
14
|
-
let inj;
|
|
15
|
-
export default function getInj() {
|
|
16
|
-
inj ??= (async () => {
|
|
17
|
-
const metaElement = typeof document === 'undefined' ? null : document.querySelector('meta[itemprop="drpruinj"]');
|
|
18
|
-
if (metaElement) {
|
|
19
|
-
metaElement.remove();
|
|
20
|
-
|
|
21
|
-
// NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be
|
|
22
|
-
// preferred, but it is not supported by older environments yet.
|
|
23
|
-
const data = atob(metaElement.content);
|
|
24
|
-
if (!window.isSecureContext) {
|
|
25
|
-
if (window.location.protocol === 'https:') {
|
|
26
|
-
throw Error('Loaded via HTTPS, but it is not considered a secure context');
|
|
27
|
-
} else if (window.location.protocol !== 'http:') {
|
|
28
|
-
throw Error('Unexpected protocol');
|
|
29
|
-
}
|
|
30
|
-
const target = window.location.href.replace(/^http:/, 'https:');
|
|
31
|
-
window.location.replace(target);
|
|
32
|
-
await timer(3 * SEC_MS);
|
|
33
|
-
throw Error('Failed to move into secure context');
|
|
34
|
-
}
|
|
35
|
-
const {
|
|
36
|
-
key
|
|
37
|
-
} = getBuildInfo();
|
|
38
|
-
const code = x => x.charCodeAt(0);
|
|
39
|
-
const dataBuffer = Uint8Array.from(data.slice(16), code);
|
|
40
|
-
const ivBuffer = Uint8Array.from(data.slice(0, 16), code);
|
|
41
|
-
const keyBuffer = Uint8Array.from(atob(key), code);
|
|
42
|
-
const cKey = await window.crypto.subtle.importKey('raw', keyBuffer, {
|
|
43
|
-
name: 'AES-CBC'
|
|
44
|
-
}, false, ['decrypt']);
|
|
45
|
-
const buffer = await window.crypto.subtle.decrypt({
|
|
46
|
-
iv: ivBuffer,
|
|
47
|
-
name: 'AES-CBC'
|
|
48
|
-
}, cKey, dataBuffer);
|
|
49
|
-
const decoder = new TextDecoder();
|
|
50
|
-
|
|
51
|
-
// eslint-disable-next-line no-eval
|
|
52
|
-
const res = eval(`(${decoder.decode(buffer)})`);
|
|
53
|
-
|
|
54
|
-
// NOTE: This is important, to be able to return the injection
|
|
55
|
-
// synchronously once it is initialized.
|
|
56
|
-
inj = res;
|
|
57
|
-
return res;
|
|
58
|
-
} else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {
|
|
59
|
-
const res = window.REACT_UTILS_INJECTION;
|
|
60
|
-
delete window.REACT_UTILS_INJECTION;
|
|
61
|
-
return res;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Otherwise, a bunch of dependent stuff will easily fail in non-standard
|
|
65
|
-
// environments, where no client-side initialization is performed. Like tests,
|
|
66
|
-
// Docusaurus examples, etc.
|
|
67
|
-
return {};
|
|
68
|
-
})();
|
|
69
|
-
return inj;
|
|
70
|
-
}
|
|
1
|
+
import"core-js/modules/es.array-buffer.detached.js";import"core-js/modules/es.array-buffer.transfer.js";import"core-js/modules/es.array-buffer.transfer-to-fixed-length.js";import"core-js/modules/es.typed-array.to-reversed.js";import"core-js/modules/es.typed-array.to-sorted.js";import"core-js/modules/es.typed-array.with.js";import"core-js/modules/web.dom-exception.stack.js";// Encapsulates retrieval of server-side data injection into HTML template.
|
|
2
|
+
/* global document */import{SEC_MS,timer}from"@dr.pogodin/js-utils";import{getBuildInfo}from"../shared/utils/isomorphy/buildInfo";let inj;export default function getInj(){inj??=(async()=>{const metaElement=typeof document==="undefined"?null:document.querySelector("meta[itemprop=\"drpruinj\"]");if(metaElement){metaElement.remove();// NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be
|
|
3
|
+
// preferred, but it is not supported by older environments yet.
|
|
4
|
+
const data=atob(metaElement.content);if(!window.isSecureContext){if(window.location.protocol==="https:"){throw Error("Loaded via HTTPS, but it is not considered a secure context");}else if(window.location.protocol!=="http:"){throw Error("Unexpected protocol");}const target=window.location.href.replace(/^http:/,"https:");window.location.replace(target);await timer(3*SEC_MS);throw Error("Failed to move into secure context");}const{key}=getBuildInfo();const code=x=>x.charCodeAt(0);const dataBuffer=Uint8Array.from(data.slice(16),code);const ivBuffer=Uint8Array.from(data.slice(0,16),code);const keyBuffer=Uint8Array.from(atob(key),code);const cKey=await window.crypto.subtle.importKey("raw",keyBuffer,{name:"AES-CBC"},false,["decrypt"]);const buffer=await window.crypto.subtle.decrypt({iv:ivBuffer,name:"AES-CBC"},cKey,dataBuffer);const decoder=new TextDecoder;// eslint-disable-next-line no-eval
|
|
5
|
+
const res=eval(`(${decoder.decode(buffer)})`);// NOTE: This is important, to be able to return the injection
|
|
6
|
+
// synchronously once it is initialized.
|
|
7
|
+
inj=res;return res;}else if(typeof window!=="undefined"&&window.REACT_UTILS_INJECTION){const res=window.REACT_UTILS_INJECTION;delete window.REACT_UTILS_INJECTION;return res;}// Otherwise, a bunch of dependent stuff will easily fail in non-standard
|
|
8
|
+
// environments, where no client-side initialization is performed. Like tests,
|
|
9
|
+
// Docusaurus examples, etc.
|
|
10
|
+
return{};})();return inj;}
|
|
71
11
|
//# sourceMappingURL=getInj.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInj.js","names":["SEC_MS","timer","getBuildInfo","inj","getInj","metaElement","document","querySelector","remove","data","atob","content","window","isSecureContext","location","protocol","Error","target","href","replace","key","code","x","charCodeAt","dataBuffer","Uint8Array","from","slice","ivBuffer","keyBuffer","cKey","crypto","subtle","importKey","name","buffer","decrypt","iv","decoder","TextDecoder","res","eval","decode","REACT_UTILS_INJECTION"],"sources":["../../../src/client/getInj.ts"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\nimport { SEC_MS, timer } from '@dr.pogodin/js-utils';\n\nimport type { InjT } from 'utils/globalState';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nlet inj: InjT | Promise<InjT> | undefined;\n\nexport default function getInj(): InjT | Promise<InjT> {\n inj ??= (async () => {\n const metaElement: HTMLMetaElement | null = typeof document === 'undefined'\n ? null : document.querySelector('meta[itemprop=\"drpruinj\"]');\n\n if (metaElement) {\n metaElement.remove();\n\n // NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be\n // preferred, but it is not supported by older environments yet.\n const data = atob(metaElement.content);\n\n if (!window.isSecureContext) {\n if (window.location.protocol === 'https:') {\n throw Error('Loaded via HTTPS, but it is not considered a secure context');\n } else if (window.location.protocol !== 'http:') {\n throw Error('Unexpected protocol');\n }\n\n const target = window.location.href.replace(/^http:/, 'https:');\n window.location.replace(target);\n\n await timer(3 * SEC_MS);\n throw Error('Failed to move into secure context');\n }\n\n const { key } = getBuildInfo();\n\n const code = (x: string) => x.charCodeAt(0);\n const dataBuffer = Uint8Array.from(data.slice(16), code);\n const ivBuffer = Uint8Array.from(data.slice(0, 16), code);\n const keyBuffer = Uint8Array.from(atob(key), code);\n\n const cKey = await window.crypto.subtle.importKey(\n 'raw',\n keyBuffer,\n { name: 'AES-CBC' },\n false,\n ['decrypt'],\n );\n\n const buffer = await window.crypto.subtle.decrypt({\n iv: ivBuffer,\n name: 'AES-CBC',\n }, cKey, dataBuffer);\n\n const decoder = new TextDecoder();\n\n // eslint-disable-next-line no-eval\n const res = eval(`(${decoder.decode(buffer)})`) as InjT;\n\n // NOTE: This is important, to be able to return the injection\n // synchronously once it is initialized.\n inj = res;\n\n return res;\n } else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {\n const res = window.REACT_UTILS_INJECTION;\n delete window.REACT_UTILS_INJECTION;\n return res;\n }\n\n // Otherwise, a bunch of dependent stuff will easily fail in non-standard\n // environments, where no client-side initialization is performed. Like tests,\n // Docusaurus examples, etc.\n return {};\n })();\n\n return inj;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getInj.js","names":["SEC_MS","timer","getBuildInfo","inj","getInj","metaElement","document","querySelector","remove","data","atob","content","window","isSecureContext","location","protocol","Error","target","href","replace","key","code","x","charCodeAt","dataBuffer","Uint8Array","from","slice","ivBuffer","keyBuffer","cKey","crypto","subtle","importKey","name","buffer","decrypt","iv","decoder","TextDecoder","res","eval","decode","REACT_UTILS_INJECTION"],"sources":["../../../src/client/getInj.ts"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\nimport { SEC_MS, timer } from '@dr.pogodin/js-utils';\n\nimport type { InjT } from 'utils/globalState';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nlet inj: InjT | Promise<InjT> | undefined;\n\nexport default function getInj(): InjT | Promise<InjT> {\n inj ??= (async () => {\n const metaElement: HTMLMetaElement | null = typeof document === 'undefined'\n ? null : document.querySelector('meta[itemprop=\"drpruinj\"]');\n\n if (metaElement) {\n metaElement.remove();\n\n // NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be\n // preferred, but it is not supported by older environments yet.\n const data = atob(metaElement.content);\n\n if (!window.isSecureContext) {\n if (window.location.protocol === 'https:') {\n throw Error('Loaded via HTTPS, but it is not considered a secure context');\n } else if (window.location.protocol !== 'http:') {\n throw Error('Unexpected protocol');\n }\n\n const target = window.location.href.replace(/^http:/, 'https:');\n window.location.replace(target);\n\n await timer(3 * SEC_MS);\n throw Error('Failed to move into secure context');\n }\n\n const { key } = getBuildInfo();\n\n const code = (x: string) => x.charCodeAt(0);\n const dataBuffer = Uint8Array.from(data.slice(16), code);\n const ivBuffer = Uint8Array.from(data.slice(0, 16), code);\n const keyBuffer = Uint8Array.from(atob(key), code);\n\n const cKey = await window.crypto.subtle.importKey(\n 'raw',\n keyBuffer,\n { name: 'AES-CBC' },\n false,\n ['decrypt'],\n );\n\n const buffer = await window.crypto.subtle.decrypt({\n iv: ivBuffer,\n name: 'AES-CBC',\n }, cKey, dataBuffer);\n\n const decoder = new TextDecoder();\n\n // eslint-disable-next-line no-eval\n const res = eval(`(${decoder.decode(buffer)})`) as InjT;\n\n // NOTE: This is important, to be able to return the injection\n // synchronously once it is initialized.\n inj = res;\n\n return res;\n } else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {\n const res = window.REACT_UTILS_INJECTION;\n delete window.REACT_UTILS_INJECTION;\n return res;\n }\n\n // Otherwise, a bunch of dependent stuff will easily fail in non-standard\n // environments, where no client-side initialization is performed. Like tests,\n // Docusaurus examples, etc.\n return {};\n })();\n\n return inj;\n}\n"],"mappings":"wXAAA;AAEA,qBAEA,OAASA,MAAM,CAAEC,KAAK,KAAQ,sBAAsB,CAIpD,OAASC,YAAY,2CAErB,GAAI,CAAAC,GAAqC,CAEzC,cAAe,SAAS,CAAAC,MAAMA,CAAA,CAAyB,CACrDD,GAAG,GAAK,CAAC,SAAY,CACnB,KAAM,CAAAE,WAAmC,CAAG,MAAO,CAAAC,QAAQ,GAAK,WAAW,CACvE,IAAI,CAAGA,QAAQ,CAACC,aAAa,CAAC,6BAA2B,CAAC,CAE9D,GAAIF,WAAW,CAAE,CACfA,WAAW,CAACG,MAAM,CAAC,CAAC,CAEpB;AACA;AACA,KAAM,CAA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IAAI,CAAE,SAAU,CAAC,CACnB,KAAK,CACL,CAAC,SAAS,CACZ,CAAC,CAED,KAAM,CAAAC,MAAM,CAAG,KAAM,CAAAvB,MAAM,CAACmB,MAAM,CAACC,MAAM,CAACI,OAAO,CAAC,CAChDC,EAAE,CAAET,QAAQ,CACZM,IAAI,CAAE,SACR,CAAC,CAAEJ,IAAI,CAAEN,UAAU,CAAC,CAEpB,KAAM,CAAAc,OAAO,CAAG,GAAI,CAAAC,WAAa,CAEjC;AACA,KAAM,CAAAC,GAAG,CAAGC,IAAI,CAAC,IAAIH,OAAO,CAACI,MAAM,CAACP,MAAM,CAAC,GAAG,CAAS,CAEvD;AACA;AACAhC,GAAG,CAAGqC,GAAG,CAET,MAAO,CAAAA,GAAG,CACZ,CAAC,IAAM,IAAI,MAAO,CAAA5B,MAAM,GAAK,WAAW,EAAIA,MAAM,CAAC+B,qBAAqB,CAAE,CACxE,KAAM,CAAAH,GAAG,CAAG5B,MAAM,CAAC+B,qBAAqB,CACxC,MAAO,CAAA/B,MAAM,CAAC+B,qBAAqB,CACnC,MAAO,CAAAH,GAAG,CACZ,CAEA;AACA;AACA;AACA,MAAO,CAAC,CAAC,CACX,CAAC,EAAE,CAAC,CAEJ,MAAO,CAAArC,GAAG,CACZ","ignoreList":[]}
|
|
@@ -1,32 +1,7 @@
|
|
|
1
1
|
// Initialization of client-side code.
|
|
2
|
-
/* global document */
|
|
3
|
-
|
|
4
|
-
import { createRoot, hydrateRoot } from 'react-dom/client';
|
|
5
|
-
import { BrowserRouter } from 'react-router';
|
|
6
|
-
import { GlobalStateProvider } from '@dr.pogodin/react-global-state';
|
|
7
|
-
import { HelmetProvider } from '@dr.pogodin/react-helmet';
|
|
8
|
-
import getInj from "./getInj";
|
|
9
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
-
/**
|
|
2
|
+
/* global document */import{createRoot,hydrateRoot}from"react-dom/client";import{BrowserRouter}from"react-router";import{GlobalStateProvider}from"@dr.pogodin/react-global-state";import{HelmetProvider}from"@dr.pogodin/react-helmet";import getInj from"./getInj";import{jsx as _jsx}from"react/jsx-runtime";/**
|
|
11
3
|
* Prepares and launches the app at client side.
|
|
12
4
|
* @param Application Root application component
|
|
13
5
|
* @param [options={}] Optional. Additional settings.
|
|
14
|
-
*/
|
|
15
|
-
export async function launchClient(Application, options = {}) {
|
|
16
|
-
const inj = await getInj();
|
|
17
|
-
const container = document.getElementById('react-view');
|
|
18
|
-
if (!container) throw Error('Failed to find container for React app');
|
|
19
|
-
const scene = /*#__PURE__*/_jsx(GlobalStateProvider, {
|
|
20
|
-
initialState: inj.ISTATE ?? options.initialState,
|
|
21
|
-
children: /*#__PURE__*/_jsx(BrowserRouter, {
|
|
22
|
-
children: /*#__PURE__*/_jsx(HelmetProvider, {
|
|
23
|
-
children: /*#__PURE__*/_jsx(Application, {})
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
});
|
|
27
|
-
if (options.dontHydrate) {
|
|
28
|
-
const root = createRoot(container);
|
|
29
|
-
root.render(scene);
|
|
30
|
-
} else hydrateRoot(container, scene);
|
|
31
|
-
}
|
|
6
|
+
*/export async function launchClient(Application,options={}){const inj=await getInj();const container=document.getElementById("react-view");if(!container)throw Error("Failed to find container for React app");const scene=/*#__PURE__*/_jsx(GlobalStateProvider,{initialState:inj.ISTATE??options.initialState,children:/*#__PURE__*/_jsx(BrowserRouter,{children:/*#__PURE__*/_jsx(HelmetProvider,{children:/*#__PURE__*/_jsx(Application,{})})})});if(options.dontHydrate){const root=createRoot(container);root.render(scene);}else hydrateRoot(container,scene);}
|
|
32
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createRoot","hydrateRoot","BrowserRouter","GlobalStateProvider","HelmetProvider","getInj","jsx","_jsx","launchClient","Application","options","inj","container","document","getElementById","Error","scene","initialState","ISTATE","children","dontHydrate","root","render"],"sources":["../../../src/client/index.tsx"],"sourcesContent":["// Initialization of client-side code.\n/* global document */\n\nimport type { ComponentType } from 'react';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport { BrowserRouter } from 'react-router';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\nimport { HelmetProvider } from '@dr.pogodin/react-helmet';\n\nimport getInj from './getInj';\n\ntype OptionsT = {\n dontHydrate?: boolean;\n initialState?: unknown;\n};\n\n/**\n * Prepares and launches the app at client side.\n * @param Application Root application component\n * @param [options={}] Optional. Additional settings.\n */\nexport async function launchClient(\n Application: ComponentType,\n options: OptionsT = {},\n): Promise<void> {\n const inj = await getInj();\n\n const container = document.getElementById('react-view');\n if (!container) throw Error('Failed to find container for React app');\n const scene = (\n <GlobalStateProvider initialState={inj.ISTATE ?? options.initialState}>\n <BrowserRouter>\n <HelmetProvider>\n <Application />\n </HelmetProvider>\n </BrowserRouter>\n </GlobalStateProvider>\n );\n\n if (options.dontHydrate) {\n const root = createRoot(container);\n root.render(scene);\n } else hydrateRoot(container, scene);\n}\n"],"mappings":"AAAA;AACA
|
|
1
|
+
{"version":3,"file":"index.js","names":["createRoot","hydrateRoot","BrowserRouter","GlobalStateProvider","HelmetProvider","getInj","jsx","_jsx","launchClient","Application","options","inj","container","document","getElementById","Error","scene","initialState","ISTATE","children","dontHydrate","root","render"],"sources":["../../../src/client/index.tsx"],"sourcesContent":["// Initialization of client-side code.\n/* global document */\n\nimport type { ComponentType } from 'react';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport { BrowserRouter } from 'react-router';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\nimport { HelmetProvider } from '@dr.pogodin/react-helmet';\n\nimport getInj from './getInj';\n\ntype OptionsT = {\n dontHydrate?: boolean;\n initialState?: unknown;\n};\n\n/**\n * Prepares and launches the app at client side.\n * @param Application Root application component\n * @param [options={}] Optional. Additional settings.\n */\nexport async function launchClient(\n Application: ComponentType,\n options: OptionsT = {},\n): Promise<void> {\n const inj = await getInj();\n\n const container = document.getElementById('react-view');\n if (!container) throw Error('Failed to find container for React app');\n const scene = (\n <GlobalStateProvider initialState={inj.ISTATE ?? options.initialState}>\n <BrowserRouter>\n <HelmetProvider>\n <Application />\n </HelmetProvider>\n </BrowserRouter>\n </GlobalStateProvider>\n );\n\n if (options.dontHydrate) {\n const root = createRoot(container);\n root.render(scene);\n } else hydrateRoot(container, scene);\n}\n"],"mappings":"AAAA;AACA,qBAGA,OAASA,UAAU,CAAEC,WAAW,KAAQ,kBAAkB,CAC1D,OAASC,aAAa,KAAQ,cAAc,CAE5C,OAASC,mBAAmB,KAAQ,gCAAgC,CACpE,OAASC,cAAc,KAAQ,0BAA0B,CAEzD,MAAO,CAAAC,MAAM,gBAAiB,OAAAC,GAAA,IAAAC,IAAA,yBAO9B;AACA;AACA;AACA;AACA,GACA,MAAO,eAAe,CAAAC,YAAYA,CAChCC,WAA0B,CAC1BC,OAAiB,CAAG,CAAC,CAAC,CACP,CACf,KAAM,CAAAC,GAAG,CAAG,KAAM,CAAAN,MAAM,CAAC,CAAC,CAE1B,KAAM,CAAAO,SAAS,CAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC,CACvD,GAAI,CAACF,SAAS,CAAE,KAAM,CAAAG,KAAK,CAAC,wCAAwC,CAAC,CACrE,KAAM,CAAAC,KAAK,cACTT,IAAA,CAACJ,mBAAmB,EAACc,YAAY,CAAEN,GAAG,CAACO,MAAM,EAAIR,OAAO,CAACO,YAAa,CAAAE,QAAA,cACpEZ,IAAA,CAACL,aAAa,EAAAiB,QAAA,cACZZ,IAAA,CAACH,cAAc,EAAAe,QAAA,cACbZ,IAAA,CAACE,WAAW,GAAE,CAAC,CACD,CAAC,CACJ,CAAC,CACG,CACtB,CAED,GAAIC,OAAO,CAACU,WAAW,CAAE,CACvB,KAAM,CAAAC,IAAI,CAAGrB,UAAU,CAACY,SAAS,CAAC,CAClCS,IAAI,CAACC,MAAM,CAACN,KAAK,CAAC,CACpB,CAAC,IAAM,CAAAf,WAAW,CAACW,SAAS,CAAEI,KAAK,CAAC,CACtC","ignoreList":[]}
|
package/build/web/client/init.js
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Initialization of client-side environment.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// eslint-disable-next-line no-console
|
|
14
|
-
console.warn('Dev mode: "BUILD_INFO" attached to the global "window"');
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
17
|
-
window.__DEV_BUILD_INFO__ = BUILD_INFO;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */
|
|
21
|
-
const {
|
|
22
|
-
useServiceWorker
|
|
23
|
-
} = buildInfo;
|
|
24
|
-
if (useServiceWorker) {
|
|
25
|
-
const {
|
|
26
|
-
navigator
|
|
27
|
-
} = window;
|
|
28
|
-
if ('serviceWorker' in navigator) {
|
|
29
|
-
window.addEventListener('load', () => {
|
|
30
|
-
void (async () => {
|
|
31
|
-
try {
|
|
32
|
-
// Note: no matter the "publicPath", we want to serve the service worker
|
|
33
|
-
// from the web app root, to allow it control any and all pages of the
|
|
34
|
-
// web app (otherwise, it will be restricted to the scope of its path).
|
|
35
|
-
// The server takes it into account.
|
|
36
|
-
const reg = await navigator.serviceWorker.register('/__service-worker.js');
|
|
37
|
-
// eslint-disable-next-line no-console
|
|
38
|
-
console.log('SW registered:', reg);
|
|
39
|
-
} catch (err) {
|
|
40
|
-
// eslint-disable-next-line no-console
|
|
41
|
-
console.log('SW registration failed:', err);
|
|
42
|
-
}
|
|
43
|
-
})();
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
3
|
+
*//* global window */import{getBuildInfo}from"../shared/utils/isomorphy/buildInfo";const buildInfo=getBuildInfo();// TODO: Should be moved into buildInfo module?
|
|
4
|
+
if(process.env.NODE_ENV!=="production"){// eslint-disable-next-line no-console
|
|
5
|
+
console.warn("Dev mode: \"BUILD_INFO\" attached to the global \"window\"");// eslint-disable-next-line no-underscore-dangle
|
|
6
|
+
window.__DEV_BUILD_INFO__=BUILD_INFO;}/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */const{useServiceWorker}=buildInfo;if(useServiceWorker){const{navigator}=window;if("serviceWorker"in navigator){window.addEventListener("load",()=>{void(async()=>{try{// Note: no matter the "publicPath", we want to serve the service worker
|
|
7
|
+
// from the web app root, to allow it control any and all pages of the
|
|
8
|
+
// web app (otherwise, it will be restricted to the scope of its path).
|
|
9
|
+
// The server takes it into account.
|
|
10
|
+
const reg=await navigator.serviceWorker.register("/__service-worker.js");// eslint-disable-next-line no-console
|
|
11
|
+
console.log("SW registered:",reg);}catch(err){// eslint-disable-next-line no-console
|
|
12
|
+
console.log("SW registration failed:",err);}})();});}}
|
|
47
13
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","names":["getBuildInfo","buildInfo","process","env","NODE_ENV","console","warn","window","__DEV_BUILD_INFO__","BUILD_INFO","useServiceWorker","navigator","addEventListener","reg","serviceWorker","register","log","err"],"sources":["../../../src/client/init.ts"],"sourcesContent":["/**\n * Initialization of client-side environment.\n */\n\n/* global window */\n\nimport { type BuildInfoT, getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nconst buildInfo = getBuildInfo();\n\n// TODO: Should be moved into buildInfo module?\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n __DEV_BUILD_INFO__: BuildInfoT | undefined;\n }\n}\n\ndeclare const BUILD_INFO: BuildInfoT | undefined;\n\nif (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('Dev mode: \"BUILD_INFO\" attached to the global \"window\"');\n\n // eslint-disable-next-line no-underscore-dangle\n window.__DEV_BUILD_INFO__ = BUILD_INFO;\n}\n\n/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */\nconst { useServiceWorker } = buildInfo;\nif (useServiceWorker) {\n const { navigator } = window;\n if ('serviceWorker' in navigator) {\n window.addEventListener('load', () => {\n void (async () => {\n try {\n // Note: no matter the \"publicPath\", we want to serve the service worker\n // from the web app root, to allow it control any and all pages of the\n // web app (otherwise, it will be restricted to the scope of its path).\n // The server takes it into account.\n const reg = await navigator\n .serviceWorker.register('/__service-worker.js');\n // eslint-disable-next-line no-console\n console.log('SW registered:', reg);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.log('SW registration failed:', err);\n }\n })();\n });\n }\n}\n"],"mappings":"AAAA;AACA;AACA
|
|
1
|
+
{"version":3,"file":"init.js","names":["getBuildInfo","buildInfo","process","env","NODE_ENV","console","warn","window","__DEV_BUILD_INFO__","BUILD_INFO","useServiceWorker","navigator","addEventListener","reg","serviceWorker","register","log","err"],"sources":["../../../src/client/init.ts"],"sourcesContent":["/**\n * Initialization of client-side environment.\n */\n\n/* global window */\n\nimport { type BuildInfoT, getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nconst buildInfo = getBuildInfo();\n\n// TODO: Should be moved into buildInfo module?\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n __DEV_BUILD_INFO__: BuildInfoT | undefined;\n }\n}\n\ndeclare const BUILD_INFO: BuildInfoT | undefined;\n\nif (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('Dev mode: \"BUILD_INFO\" attached to the global \"window\"');\n\n // eslint-disable-next-line no-underscore-dangle\n window.__DEV_BUILD_INFO__ = BUILD_INFO;\n}\n\n/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */\nconst { useServiceWorker } = buildInfo;\nif (useServiceWorker) {\n const { navigator } = window;\n if ('serviceWorker' in navigator) {\n window.addEventListener('load', () => {\n void (async () => {\n try {\n // Note: no matter the \"publicPath\", we want to serve the service worker\n // from the web app root, to allow it control any and all pages of the\n // web app (otherwise, it will be restricted to the scope of its path).\n // The server takes it into account.\n const reg = await navigator\n .serviceWorker.register('/__service-worker.js');\n // eslint-disable-next-line no-console\n console.log('SW registered:', reg);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.log('SW registration failed:', err);\n }\n })();\n });\n }\n}\n"],"mappings":"AAAA;AACA;AACA,GAEA,mBAEA,OAA0BA,YAAY,2CAEtC,KAAM,CAAAC,SAAS,CAAGD,YAAY,CAAC,CAAC,CAEhC;AAUA,GAAIE,OAAO,CAACC,GAAG,CAACC,QAAQ,GAAK,YAAY,CAAE,CACzC;AACAC,OAAO,CAACC,IAAI,CAAC,4DAAwD,CAAC,CAEtE;AACAC,MAAM,CAACC,kBAAkB,CAAGC,UAAU,CACxC,CAEA,yEACA,KAAM,CAAEC,gBAAiB,CAAC,CAAGT,SAAS,CACtC,GAAIS,gBAAgB,CAAE,CACpB,KAAM,CAAEC,SAAU,CAAC,CAAGJ,MAAM,CAC5B,GAAI,eAAe,EAAI,CAAAI,SAAS,CAAE,CAChCJ,MAAM,CAACK,gBAAgB,CAAC,MAAM,CAAE,IAAM,CACpC,IAAK,CAAC,SAAY,CAChB,GAAI,CACF;AACA;AACA;AACA;AACA,KAAM,CAAAC,GAAG,CAAG,KAAM,CAAAF,SAAS,CACxBG,aAAa,CAACC,QAAQ,CAAC,sBAAsB,CAAC,CACjD;AACAV,OAAO,CAACW,GAAG,CAAC,gBAAgB,CAAEH,GAAG,CAAC,CACpC,CAAE,MAAOI,GAAG,CAAE,CACZ;AACAZ,OAAO,CAACW,GAAG,CAAC,yBAAyB,CAAEC,GAAG,CAAC,CAC7C,CACF,CAAC,EAAE,CAAC,CACN,CAAC,CAAC,CACJ,CACF","ignoreList":[]}
|
package/build/web/index.js
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
|
+
// TODO: For now I commented out this safeguard check, as I am not sure how
|
|
2
|
+
// to easily make it work: it should not be triggered in HMR mode, but if I
|
|
3
|
+
// add the code relying on import.meta, it fails in Jest environment, because
|
|
4
|
+
// Jest does not support ES modules yet, and import.meta is not support in
|
|
5
|
+
// CommonJS modules, and the "babel-plugin-transform-import-meta" plugin
|
|
6
|
+
// we use to workaround this issue for import.meta.dirname, etc. does not
|
|
7
|
+
// transform import.meta.webpackHot
|
|
1
8
|
// It is a safeguard against multiple instances / versions of the library
|
|
2
9
|
// being loaded into environment by mistake (e.g. because of different
|
|
3
10
|
// packages pinning down different exact versions of the lib, thus preventing
|
|
4
11
|
// a proper dedupe and using a single common library version).
|
|
5
|
-
if (global.REACT_UTILS_LIBRARY_LOADED) {
|
|
6
|
-
throw Error('React utils library is already loaded');
|
|
7
|
-
} else global.REACT_UTILS_LIBRARY_LOADED = true;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
// if (global.REACT_UTILS_LIBRARY_LOADED) {
|
|
13
|
+
// throw Error('React utils library is already loaded');
|
|
14
|
+
// } else global.REACT_UTILS_LIBRARY_LOADED = true;
|
|
15
|
+
/*
|
|
16
|
+
declare global {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
18
|
+
interface ImportMeta {
|
|
19
|
+
webpackHot?: {
|
|
20
|
+
dispose(cb: () => void): void;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (import.meta.webpackHot) {
|
|
26
|
+
import.meta.webpackHot.dispose(() => {
|
|
27
|
+
delete global.REACT_UTILS_LIBRARY_LOADED;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
*/export{GlobalStateProvider,getGlobalState,newAsyncDataEnvelope,useAsyncCollection,useAsyncData,useGlobalState,withGlobalStateType}from"@dr.pogodin/react-global-state";export*from"./shared/components";export{Barrier,Cached,Emitter,Semaphore,THEME_COMPOSE,THEME_PRIORITY,ThemeProvider,assertEmptyObject,getConfig,getSsrContext,isomorphy,splitComponent,time,useTheme,webpack,withRetries}from"./shared/utils";
|
|
11
31
|
//# sourceMappingURL=index.js.map
|
package/build/web/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["GlobalStateProvider","getGlobalState","newAsyncDataEnvelope","useAsyncCollection","useAsyncData","useGlobalState","withGlobalStateType","Barrier","Cached","Emitter","Semaphore","THEME_COMPOSE","THEME_PRIORITY","ThemeProvider","assertEmptyObject","getConfig","getSsrContext","isomorphy","splitComponent","time","useTheme","webpack","withRetries"],"sources":["../../src/index.ts"],"sourcesContent":["// TODO: For now I commented out this safeguard check, as I am not sure how\n// to easily make it work: it should not be triggered in HMR mode, but if I\n// add the code relying on import.meta, it fails in Jest environment, because\n// Jest does not support ES modules yet, and import.meta is not support in\n// CommonJS modules, and the \"babel-plugin-transform-import-meta\" plugin\n// we use to workaround this issue for import.meta.dirname, etc. does not\n// transform import.meta.webpackHot\n\n// 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).\n// if (global.REACT_UTILS_LIBRARY_LOADED) {\n// throw Error('React utils library is already loaded');\n// } else global.REACT_UTILS_LIBRARY_LOADED = true;\n\n/*\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface ImportMeta {\n webpackHot?: {\n dispose(cb: () => void): void;\n };\n }\n}\n\nif (import.meta.webpackHot) {\n import.meta.webpackHot.dispose(() => {\n delete global.REACT_UTILS_LIBRARY_LOADED;\n });\n}\n*/\n\nexport {\n type AsyncCollectionLoaderT,\n type AsyncCollectionT,\n type AsyncDataEnvelopeT,\n type AsyncDataLoaderT,\n type ForceT,\n GlobalStateProvider,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n type UseGlobalStateResT,\n type ValueOrInitializerT,\n getGlobalState,\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 Barrier,\n Cached,\n Emitter,\n type Listener,\n type ObjectKey,\n Semaphore,\n THEME_COMPOSE,\n THEME_PRIORITY,\n type Theme,\n ThemeProvider,\n assertEmptyObject,\n getConfig,\n getSsrContext,\n isomorphy,\n splitComponent,\n time,\n useTheme,\n webpack,\n withRetries,\n} from 'utils';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAEA,OAMEA,mBAAmB,CAKnBC,cAAc,CACdC,oBAAoB,CACpBC,kBAAkB,CAClBC,YAAY,CACZC,cAAc,CACdC,mBAAmB,KACd,gCAAgC,CAEvC,iCAUA,OACEC,OAAO,CACPC,MAAM,CACNC,OAAO,CAGPC,SAAS,CACTC,aAAa,CACbC,cAAc,CAEdC,aAAa,CACbC,iBAAiB,CACjBC,SAAS,CACTC,aAAa,CACbC,SAAS,CACTC,cAAc,CACdC,IAAI,CACJC,QAAQ,CACRC,OAAO,CACPC,WAAW","ignoreList":[]}
|
|
@@ -1,54 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Implements the static cache.
|
|
3
|
-
*/
|
|
4
|
-
export default class Cache {
|
|
5
|
-
items = {};
|
|
6
|
-
size = 0;
|
|
7
|
-
constructor(maxSize) {
|
|
8
|
-
this.maxSize = maxSize;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
3
|
+
*/export default class Cache{items={};size=0;constructor(maxSize){this.maxSize=maxSize}/**
|
|
12
4
|
* Cache lookup.
|
|
13
5
|
* @param key Item key to look for.
|
|
14
6
|
* @param [maxage=Number.MAX_VALUE] Optional. The maximum age of
|
|
15
7
|
* cached item to serve. Default to infinite.
|
|
16
8
|
* @returns Cached item, or null if the item is absent in cache,
|
|
17
9
|
* or stale.
|
|
18
|
-
*/
|
|
19
|
-
get({
|
|
20
|
-
key,
|
|
21
|
-
maxage = Number.MAX_VALUE
|
|
22
|
-
}) {
|
|
23
|
-
const item = this.items[key];
|
|
24
|
-
return item && Date.now() - item.timestamp < maxage ? item.data : null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
10
|
+
*/get({key,maxage=Number.MAX_VALUE}){const item=this.items[key];return item&&Date.now()-item.timestamp<maxage?item.data:null;}/**
|
|
28
11
|
* Adds item to cache.
|
|
29
12
|
* @param data Item to add.
|
|
30
13
|
* @param key Key to store the item at.
|
|
31
14
|
* @param size Byte size of the item.
|
|
32
|
-
*/
|
|
33
|
-
add(data, key, size) {
|
|
34
|
-
const cached = this.items[key];
|
|
35
|
-
if (cached) this.size -= cached.size;
|
|
36
|
-
this.items[key] = {
|
|
37
|
-
data,
|
|
38
|
-
size,
|
|
39
|
-
timestamp: Date.now()
|
|
40
|
-
};
|
|
41
|
-
this.size += size;
|
|
42
|
-
if (this.size > this.maxSize) {
|
|
43
|
-
const entries = Object.entries(this.items);
|
|
44
|
-
entries.sort((a, b) => a[1].timestamp - b[1].timestamp);
|
|
45
|
-
for (const entry of entries) {
|
|
46
|
-
const [itemKey, item] = entry;
|
|
47
|
-
delete this.items[itemKey];
|
|
48
|
-
this.size -= item.size;
|
|
49
|
-
if (this.size < this.maxSize / 2) break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
15
|
+
*/add(data,key,size){const cached=this.items[key];if(cached)this.size-=cached.size;this.items[key]={data,size,timestamp:Date.now()};this.size+=size;if(this.size>this.maxSize){const entries=Object.entries(this.items);entries.sort((a,b)=>a[1].timestamp-b[1].timestamp);for(const entry of entries){const[itemKey,item]=entry;delete this.items[itemKey];this.size-=item.size;if(this.size<this.maxSize/2)break;}}}}
|
|
54
16
|
//# sourceMappingURL=Cache.js.map
|