@dr.pogodin/react-utils 1.46.2 → 1.47.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/babel.config.js +1 -0
  2. package/babel.libweb.config.js +16 -0
  3. package/babel.module.config.js +11 -0
  4. package/bin/build.js +21 -11
  5. package/bin/setup.js +11 -9
  6. package/build/development/client/getInj.js +57 -44
  7. package/build/development/client/getInj.js.map +1 -1
  8. package/build/development/client/index.js +15 -21
  9. package/build/development/client/index.js.map +1 -1
  10. package/build/development/client/init.js +2 -6
  11. package/build/development/client/init.js.map +1 -1
  12. package/build/development/index.js +3 -177
  13. package/build/development/index.js.map +1 -1
  14. package/build/development/server/Cache.js +1 -8
  15. package/build/development/server/Cache.js.map +1 -1
  16. package/build/development/server/index.js +22 -45
  17. package/build/development/server/index.js.map +1 -1
  18. package/build/development/server/renderer.js +84 -86
  19. package/build/development/server/renderer.js.map +1 -1
  20. package/build/development/server/server.js +58 -60
  21. package/build/development/server/server.js.map +1 -1
  22. package/build/development/server/utils/errors.js +8 -31
  23. package/build/development/server/utils/errors.js.map +1 -1
  24. package/build/development/server/utils/index.js +2 -9
  25. package/build/development/server/utils/index.js.map +1 -1
  26. package/build/development/shared/components/Button/index.js +15 -22
  27. package/build/development/shared/components/Button/index.js.map +1 -1
  28. package/build/development/shared/components/Checkbox/index.js +14 -21
  29. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  30. package/build/development/shared/components/GenericLink/index.js +9 -11
  31. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  32. package/build/development/shared/components/Input/index.js +21 -27
  33. package/build/development/shared/components/Input/index.js.map +1 -1
  34. package/build/development/shared/components/Link.js +6 -13
  35. package/build/development/shared/components/Link.js.map +1 -1
  36. package/build/development/shared/components/Modal/index.js +24 -28
  37. package/build/development/shared/components/Modal/index.js.map +1 -1
  38. package/build/development/shared/components/NavLink.js +6 -13
  39. package/build/development/shared/components/NavLink.js.map +1 -1
  40. package/build/development/shared/components/PageLayout/index.js +13 -20
  41. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  42. package/build/development/shared/components/TextArea/index.js +28 -31
  43. package/build/development/shared/components/TextArea/index.js.map +1 -1
  44. package/build/development/shared/components/Throbber/index.js +13 -20
  45. package/build/development/shared/components/Throbber/index.js.map +1 -1
  46. package/build/development/shared/components/WithTooltip/Tooltip.js +13 -18
  47. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  48. package/build/development/shared/components/WithTooltip/index.js +23 -30
  49. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  50. package/build/development/shared/components/YouTubeVideo/index.js +19 -26
  51. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  52. package/build/development/shared/components/index.js +16 -130
  53. package/build/development/shared/components/index.js.map +1 -1
  54. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +19 -20
  55. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  56. package/build/development/shared/components/selectors/CustomDropdown/index.js +35 -39
  57. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  58. package/build/development/shared/components/selectors/NativeDropdown/index.js +31 -31
  59. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  60. package/build/development/shared/components/selectors/Switch/index.js +19 -24
  61. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  62. package/build/development/shared/components/selectors/common.js +1 -7
  63. package/build/development/shared/components/selectors/common.js.map +1 -1
  64. package/build/development/shared/components/selectors/index.js +3 -27
  65. package/build/development/shared/components/selectors/index.js.map +1 -1
  66. package/build/development/shared/utils/config.js +40 -21
  67. package/build/development/shared/utils/config.js.map +1 -1
  68. package/build/development/shared/utils/globalState.js +3 -8
  69. package/build/development/shared/utils/globalState.js.map +1 -1
  70. package/build/development/shared/utils/index.js +12 -89
  71. package/build/development/shared/utils/index.js.map +1 -1
  72. package/build/development/shared/utils/isomorphy/buildInfo.js +2 -9
  73. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  74. package/build/development/shared/utils/isomorphy/environment-check.js +2 -8
  75. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  76. package/build/development/shared/utils/isomorphy/index.js +7 -32
  77. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  78. package/build/development/shared/utils/jest/E2eSsrEnv.js +34 -37
  79. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  80. package/build/development/shared/utils/jest/global.js +1 -7
  81. package/build/development/shared/utils/jest/global.js.map +1 -1
  82. package/build/development/shared/utils/jest/index.js +20 -44
  83. package/build/development/shared/utils/jest/index.js.map +1 -1
  84. package/build/development/shared/utils/splitComponent.js +54 -45
  85. package/build/development/shared/utils/splitComponent.js.map +1 -1
  86. package/build/development/shared/utils/time.js +22 -31
  87. package/build/development/shared/utils/time.js.map +1 -1
  88. package/build/development/shared/utils/webpack.js +17 -16
  89. package/build/development/shared/utils/webpack.js.map +1 -1
  90. package/build/production/client/getInj.js +13 -11
  91. package/build/production/client/getInj.js.map +1 -1
  92. package/build/production/client/index.js +3 -3
  93. package/build/production/client/index.js.map +1 -1
  94. package/build/production/client/init.js +2 -2
  95. package/build/production/client/init.js.map +1 -1
  96. package/build/production/index.js +2 -3
  97. package/build/production/index.js.map +1 -1
  98. package/build/production/server/Cache.js +3 -3
  99. package/build/production/server/Cache.js.map +1 -1
  100. package/build/production/server/index.js +8 -8
  101. package/build/production/server/index.js.map +1 -1
  102. package/build/production/server/renderer.js +24 -25
  103. package/build/production/server/renderer.js.map +1 -1
  104. package/build/production/server/server.js +9 -11
  105. package/build/production/server/server.js.map +1 -1
  106. package/build/production/server/utils/errors.js +9 -9
  107. package/build/production/server/utils/errors.js.map +1 -1
  108. package/build/production/server/utils/index.js +2 -1
  109. package/build/production/server/utils/index.js.map +1 -1
  110. package/build/production/shared/components/Button/index.js +4 -4
  111. package/build/production/shared/components/Button/index.js.map +1 -1
  112. package/build/production/shared/components/Checkbox/index.js +1 -1
  113. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  114. package/build/production/shared/components/GenericLink/index.js +4 -4
  115. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  116. package/build/production/shared/components/Input/index.js +5 -5
  117. package/build/production/shared/components/Input/index.js.map +1 -1
  118. package/build/production/shared/components/Link.js +3 -3
  119. package/build/production/shared/components/Link.js.map +1 -1
  120. package/build/production/shared/components/Modal/index.js +7 -7
  121. package/build/production/shared/components/Modal/index.js.map +1 -1
  122. package/build/production/shared/components/NavLink.js +2 -2
  123. package/build/production/shared/components/NavLink.js.map +1 -1
  124. package/build/production/shared/components/PageLayout/index.js +2 -2
  125. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  126. package/build/production/shared/components/TextArea/index.js +5 -5
  127. package/build/production/shared/components/TextArea/index.js.map +1 -1
  128. package/build/production/shared/components/Throbber/index.js +2 -2
  129. package/build/production/shared/components/Throbber/index.js.map +1 -1
  130. package/build/production/shared/components/WithTooltip/Tooltip.js +4 -4
  131. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  132. package/build/production/shared/components/WithTooltip/index.js +4 -4
  133. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  134. package/build/production/shared/components/YouTubeVideo/index.js +4 -4
  135. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  136. package/build/production/shared/components/index.js +3 -1
  137. package/build/production/shared/components/index.js.map +1 -1
  138. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
  139. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  140. package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
  141. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  142. package/build/production/shared/components/selectors/NativeDropdown/index.js +4 -4
  143. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  144. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  145. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  146. package/build/production/shared/components/selectors/common.js +2 -2
  147. package/build/production/shared/components/selectors/common.js.map +1 -1
  148. package/build/production/shared/components/selectors/index.js +1 -1
  149. package/build/production/shared/components/selectors/index.js.map +1 -1
  150. package/build/production/shared/utils/config.js +8 -6
  151. package/build/production/shared/utils/config.js.map +1 -1
  152. package/build/production/shared/utils/globalState.js +2 -2
  153. package/build/production/shared/utils/globalState.js.map +1 -1
  154. package/build/production/shared/utils/index.js +1 -1
  155. package/build/production/shared/utils/index.js.map +1 -1
  156. package/build/production/shared/utils/isomorphy/buildInfo.js +3 -3
  157. package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
  158. package/build/production/shared/utils/isomorphy/environment-check.js +3 -3
  159. package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
  160. package/build/production/shared/utils/isomorphy/index.js +4 -4
  161. package/build/production/shared/utils/isomorphy/index.js.map +1 -1
  162. package/build/production/shared/utils/jest/E2eSsrEnv.js +16 -15
  163. package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  164. package/build/production/shared/utils/jest/global.js +1 -1
  165. package/build/production/shared/utils/jest/global.js.map +1 -1
  166. package/build/production/shared/utils/jest/index.js +11 -11
  167. package/build/production/shared/utils/jest/index.js.map +1 -1
  168. package/build/production/shared/utils/splitComponent.js +11 -22
  169. package/build/production/shared/utils/splitComponent.js.map +1 -1
  170. package/build/production/shared/utils/time.js +3 -3
  171. package/build/production/shared/utils/time.js.map +1 -1
  172. package/build/production/shared/utils/webpack.js +6 -6
  173. package/build/production/shared/utils/webpack.js.map +1 -1
  174. package/build/types-code/client/getInj.d.ts +1 -2
  175. package/build/types-code/client/index.d.ts +1 -1
  176. package/build/types-code/index.d.ts +1 -7
  177. package/build/types-code/server/index.d.ts +6 -11
  178. package/build/types-code/server/utils/index.d.ts +1 -1
  179. package/build/types-code/shared/utils/config.d.ts +4 -2
  180. package/build/types-code/shared/utils/index.d.ts +2 -2
  181. package/build/types-code/shared/utils/splitComponent.d.ts +6 -4
  182. package/build/web/client/getInj.js +65 -0
  183. package/build/web/client/getInj.js.map +1 -0
  184. package/{src/client/index.tsx → build/web/client/index.js} +13 -24
  185. package/build/web/client/index.js.map +1 -0
  186. package/{src/client/init.ts → build/web/client/init.js} +9 -14
  187. package/build/web/client/init.js.map +1 -0
  188. package/build/web/index.js +11 -0
  189. package/build/web/index.js.map +1 -0
  190. package/{src/server/Cache.ts → build/web/server/Cache.js} +15 -22
  191. package/build/web/server/Cache.js.map +1 -0
  192. package/{src/server/index.ts → build/web/server/index.js} +32 -81
  193. package/build/web/server/index.js.map +1 -0
  194. package/{src/server/renderer.tsx → build/web/server/renderer.js} +188 -333
  195. package/build/web/server/renderer.js.map +1 -0
  196. package/{src/server/server.ts → build/web/server/server.js} +82 -182
  197. package/build/web/server/server.js.map +1 -0
  198. package/{src/server/utils/errors.ts → build/web/server/utils/errors.js} +6 -25
  199. package/build/web/server/utils/errors.js.map +1 -0
  200. package/build/web/server/utils/index.js +4 -0
  201. package/build/web/server/utils/index.js.map +1 -0
  202. package/build/web/shared/components/Button/index.js +90 -0
  203. package/build/web/shared/components/Button/index.js.map +1 -0
  204. package/build/web/shared/components/Checkbox/index.js +35 -0
  205. package/build/web/shared/components/Checkbox/index.js.map +1 -0
  206. package/{src/shared/components/GenericLink/index.tsx → build/web/shared/components/GenericLink/index.js} +44 -78
  207. package/build/web/shared/components/GenericLink/index.js.map +1 -0
  208. package/build/web/shared/components/Input/index.js +71 -0
  209. package/build/web/shared/components/Input/index.js.map +1 -0
  210. package/build/web/shared/components/Link.js +20 -0
  211. package/build/web/shared/components/Link.js.map +1 -0
  212. package/{src → build/web}/shared/components/Modal/base-theme.scss +1 -1
  213. package/build/web/shared/components/Modal/index.js +128 -0
  214. package/build/web/shared/components/Modal/index.js.map +1 -0
  215. package/build/web/shared/components/NavLink.js +13 -0
  216. package/build/web/shared/components/NavLink.js.map +1 -0
  217. package/{src → build/web}/shared/components/PageLayout/base-theme.scss +1 -1
  218. package/{src/shared/components/PageLayout/index.tsx → build/web/shared/components/PageLayout/index.js} +20 -33
  219. package/build/web/shared/components/PageLayout/index.js.map +1 -0
  220. package/build/web/shared/components/TextArea/index.js +106 -0
  221. package/build/web/shared/components/TextArea/index.js.map +1 -0
  222. package/build/web/shared/components/Throbber/index.js +26 -0
  223. package/build/web/shared/components/Throbber/index.js.map +1 -0
  224. package/{src/shared/components/WithTooltip/Tooltip.tsx → build/web/shared/components/WithTooltip/Tooltip.js} +61 -109
  225. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -0
  226. package/build/web/shared/components/WithTooltip/index.js +117 -0
  227. package/build/web/shared/components/WithTooltip/index.js.map +1 -0
  228. package/{src/shared/components/YouTubeVideo/index.tsx → build/web/shared/components/YouTubeVideo/index.js} +23 -40
  229. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -0
  230. package/build/web/shared/components/index.js +18 -0
  231. package/build/web/shared/components/index.js.map +1 -0
  232. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +82 -0
  233. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -0
  234. package/{src/shared/components/selectors/CustomDropdown/index.tsx → build/web/shared/components/selectors/CustomDropdown/index.js} +56 -80
  235. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -0
  236. package/{src/shared/components/selectors/NativeDropdown/index.tsx → build/web/shared/components/selectors/NativeDropdown/index.js} +39 -44
  237. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -0
  238. package/build/web/shared/components/selectors/Switch/index.js +50 -0
  239. package/build/web/shared/components/selectors/Switch/index.js.map +1 -0
  240. package/build/web/shared/components/selectors/common.js +12 -0
  241. package/build/web/shared/components/selectors/common.js.map +1 -0
  242. package/build/web/shared/components/selectors/index.js +4 -0
  243. package/build/web/shared/components/selectors/index.js.map +1 -0
  244. package/build/web/shared/utils/config.js +45 -0
  245. package/build/web/shared/utils/config.js.map +1 -0
  246. package/build/web/shared/utils/globalState.js +15 -0
  247. package/build/web/shared/utils/globalState.js.map +1 -0
  248. package/build/web/shared/utils/index.js +13 -0
  249. package/build/web/shared/utils/index.js.map +1 -0
  250. package/{src/shared/utils/isomorphy/buildInfo.ts → build/web/shared/utils/isomorphy/buildInfo.js} +4 -10
  251. package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -0
  252. package/build/web/shared/utils/isomorphy/environment-check.js +17 -0
  253. package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -0
  254. package/{src/shared/utils/isomorphy/index.ts → build/web/shared/utils/isomorphy/index.js} +6 -6
  255. package/build/web/shared/utils/isomorphy/index.js.map +1 -0
  256. package/{src/shared/utils/jest/E2eSsrEnv.ts → build/web/shared/utils/jest/E2eSsrEnv.js} +73 -140
  257. package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -0
  258. package/build/web/shared/utils/jest/global.js +4 -0
  259. package/build/web/shared/utils/jest/global.js.map +1 -0
  260. package/{src/shared/utils/jest/index.ts → build/web/shared/utils/jest/index.js} +33 -83
  261. package/build/web/shared/utils/jest/index.js.map +1 -0
  262. package/{src/shared/utils/splitComponent.tsx → build/web/shared/utils/splitComponent.js} +77 -124
  263. package/build/web/shared/utils/splitComponent.js.map +1 -0
  264. package/{src/shared/utils/time.ts → build/web/shared/utils/time.js} +21 -37
  265. package/build/web/shared/utils/time.js.map +1 -0
  266. package/build/web/shared/utils/webpack.js +67 -0
  267. package/build/web/shared/utils/webpack.js.map +1 -0
  268. package/config/babel/node-ssr.js +12 -3
  269. package/config/babel/webpack.js +6 -1
  270. package/config/jest/default.js +8 -2
  271. package/config/jest/setup.js +8 -1
  272. package/config/webpack/app-base.js +25 -14
  273. package/config/webpack/app-development.js +2 -2
  274. package/config/webpack/lib-base.js +1 -2
  275. package/package.json +41 -42
  276. package/types.d.ts +1 -6
  277. package/build/development/__chunk_groups__.json +0 -6
  278. package/build/development/style.css +0 -909
  279. package/build/development/web.bundle.js +0 -752
  280. package/build/production/__chunk_groups__.json +0 -6
  281. package/build/production/style.css +0 -2
  282. package/build/production/style.css.map +0 -1
  283. package/build/production/web.bundle.js +0 -3
  284. package/build/production/web.bundle.js.LICENSE.txt +0 -9
  285. package/build/production/web.bundle.js.map +0 -1
  286. package/dev-styles.js +0 -1
  287. package/node-entry.js +0 -15
  288. package/null.js +0 -1
  289. package/prod-styles.js +0 -1
  290. package/src/client/getInj.ts +0 -51
  291. package/src/index.ts +0 -73
  292. package/src/server/utils/index.ts +0 -3
  293. package/src/shared/components/Button/index.tsx +0 -130
  294. package/src/shared/components/Checkbox/index.tsx +0 -53
  295. package/src/shared/components/Input/index.tsx +0 -96
  296. package/src/shared/components/Link.tsx +0 -25
  297. package/src/shared/components/Modal/index.tsx +0 -177
  298. package/src/shared/components/NavLink.tsx +0 -18
  299. package/src/shared/components/TextArea/index.tsx +0 -139
  300. package/src/shared/components/Throbber/index.tsx +0 -28
  301. package/src/shared/components/WithTooltip/index.tsx +0 -186
  302. package/src/shared/components/index.ts +0 -20
  303. package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -124
  304. package/src/shared/components/selectors/Switch/index.tsx +0 -74
  305. package/src/shared/components/selectors/common.ts +0 -57
  306. package/src/shared/components/selectors/index.ts +0 -8
  307. package/src/shared/utils/config.ts +0 -28
  308. package/src/shared/utils/globalState.ts +0 -44
  309. package/src/shared/utils/index.ts +0 -45
  310. package/src/shared/utils/isomorphy/environment-check.ts +0 -18
  311. package/src/shared/utils/jest/global.ts +0 -17
  312. package/src/shared/utils/webpack.ts +0 -74
  313. /package/{src → build/web}/shared/components/Button/style.scss +0 -0
  314. /package/{src → build/web}/shared/components/Checkbox/theme.scss +0 -0
  315. /package/{src → build/web}/shared/components/GenericLink/style.scss +0 -0
  316. /package/{src → build/web}/shared/components/Input/theme.scss +0 -0
  317. /package/{src → build/web}/shared/components/Modal/styles.scss +0 -0
  318. /package/{src → build/web}/shared/components/TextArea/style.scss +0 -0
  319. /package/{src → build/web}/shared/components/Throbber/theme.scss +0 -0
  320. /package/{src → build/web}/shared/components/WithTooltip/default-theme.scss +0 -0
  321. /package/{src → build/web}/shared/components/YouTubeVideo/base.scss +0 -0
  322. /package/{src → build/web}/shared/components/YouTubeVideo/throbber.scss +0 -0
  323. /package/{src → build/web}/shared/components/selectors/CustomDropdown/Options/style.scss +0 -0
  324. /package/{src → build/web}/shared/components/selectors/CustomDropdown/theme.scss +0 -0
  325. /package/{src → build/web}/shared/components/selectors/NativeDropdown/theme.scss +0 -0
  326. /package/{src → build/web}/shared/components/selectors/Switch/theme.scss +0 -0
  327. /package/{src → build/web}/styles/_global/reset.css +0 -0
  328. /package/{src → build/web}/styles/_mixins/fonts.scss +0 -0
  329. /package/{src → build/web}/styles/_mixins/media.scss +0 -0
  330. /package/{src → build/web}/styles/_mixins/typography.scss +0 -0
  331. /package/{src → build/web}/styles/global.scss +0 -0
  332. /package/{src → build/web}/styles/mixins.scss +0 -0
@@ -1,15 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.bookStyleSheets=bookStyleSheets;exports.default=splitComponent;exports.freeStyleSheets=freeStyleSheets;var _react=require("react");var _jsUtils=require("@dr.pogodin/js-utils");var _globalState=require("./globalState");var _isomorphy=require("./isomorphy");var _jsxRuntime=require("react/jsx-runtime");/* global document */// Note: At the client side we can get chunk groups immediately when loading
2
- // the module; at the server-side we only can get them within React render flow.
3
- // Thus, we set and use the following variable at the client-side, and then when
4
- // needed on the server side, we'll fetch it differently.
5
- let clientChunkGroups;if(_isomorphy.IS_CLIENT_SIDE){// TODO: Rewrite to avoid these overrides of ESLint rules.
6
- /* eslint-disable @typescript-eslint/no-unsafe-assignment,
7
- @typescript-eslint/no-require-imports,
8
- @typescript-eslint/no-unsafe-call,
9
- @typescript-eslint/no-unsafe-member-access */clientChunkGroups=require("../../client/getInj").default().CHUNK_GROUPS??{};/* eslint-enable @typescript-eslint/no-unsafe-assignment,
10
- @typescript-eslint/no-require-imports,
11
- @typescript-eslint/no-unsafe-call,
12
- @typescript-eslint/no-unsafe-member-access */}const refCounts={};function getPublicPath(){return(0,_isomorphy.getBuildInfo)().publicPath}/**
1
+ import"core-js/modules/es.array.push.js";import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.set.difference.v2.js";import"core-js/modules/es.set.intersection.v2.js";import"core-js/modules/es.set.is-disjoint-from.v2.js";import"core-js/modules/es.set.is-subset-of.v2.js";import"core-js/modules/es.set.is-superset-of.v2.js";import"core-js/modules/es.set.symmetric-difference.v2.js";import"core-js/modules/es.set.union.v2.js";import"core-js/modules/es.array.push.js";import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.set.difference.v2.js";import"core-js/modules/es.set.intersection.v2.js";import"core-js/modules/es.set.is-disjoint-from.v2.js";import"core-js/modules/es.set.is-subset-of.v2.js";import"core-js/modules/es.set.is-superset-of.v2.js";import"core-js/modules/es.set.symmetric-difference.v2.js";import"core-js/modules/es.set.union.v2.js";/* global document */import{Suspense,lazy,useInsertionEffect}from"react";import{Barrier}from"@dr.pogodin/js-utils";import{getSsrContext}from"./globalState.js";import{IS_CLIENT_SIDE,IS_SERVER_SIDE,getBuildInfo}from"./isomorphy/index.js";import{jsx as _jsx}from"react/jsx-runtime";function getClientChunkGroups(){if(!IS_CLIENT_SIDE)return undefined;return(async()=>{const{default:getInj}=await import(/* webpackChunkName: "react-utils-client-side-code" */"../../client/getInj");const inj=await getInj();return inj.CHUNK_GROUPS??{}})()}const refCounts={};function getPublicPath(){return getBuildInfo().publicPath}/**
13
2
  * Client-side only! Ensures the specified CSS stylesheet is loaded into
14
3
  * the document; loads if it is missing; and does simple reference counting
15
4
  * to facilitate future clean-up.
@@ -17,7 +6,7 @@ let clientChunkGroups;if(_isomorphy.IS_CLIENT_SIDE){// TODO: Rewrite to avoid th
17
6
  * @param loadedSheets
18
7
  * @param refCount
19
8
  * @return
20
- */function bookStyleSheet(name,loadedSheets,refCount){let res;const path=`${getPublicPath()}/${name}`;const fullPath=`${document.location.origin}${path}`;if(!loadedSheets.has(fullPath)){let link=document.querySelector(`link[href="${path}"]`);if(!link){link=document.createElement("link");link.setAttribute("rel","stylesheet");link.setAttribute("href",path);document.head.appendChild(link)}res=new _jsUtils.Barrier;link.addEventListener("load",()=>{if(!res)throw Error("Internal error");void res.resolve()});link.addEventListener("error",()=>{if(!res)throw Error("Internal error");void res.resolve()})}if(refCount){const current=refCounts[path]??0;refCounts[path]=1+current}return res}/**
9
+ */function bookStyleSheet(name,loadedSheets,refCount){let res;const path=`${getPublicPath()}/${name}`;const fullPath=`${document.location.origin}${path}`;if(!loadedSheets.has(fullPath)){let link=document.querySelector(`link[href="${path}"]`);if(!link){link=document.createElement("link");link.setAttribute("rel","stylesheet");link.setAttribute("href",path);document.head.appendChild(link)}res=new Barrier;link.addEventListener("load",()=>{if(!res)throw Error("Internal error");void res.resolve()});link.addEventListener("error",()=>{if(!res)throw Error("Internal error");void res.resolve()})}if(refCount){const current=refCounts[path]??0;refCounts[path]=1+current}return res}/**
21
10
  * Generates the set of URLs for currently loaded, linked stylesheets.
22
11
  * @return
23
12
  */function getLoadedStyleSheets(){const res=new Set;const{styleSheets}=document;for(const{href}of styleSheets){if(href)res.add(href)}return res}function assertChunkName(chunkName,chunkGroups){if(chunkGroups[chunkName])return;throw Error(`Unknown chunk name "${chunkName}"`)}/**
@@ -28,13 +17,13 @@ let clientChunkGroups;if(_isomorphy.IS_CLIENT_SIDE){// TODO: Rewrite to avoid th
28
17
  * @param refCount
29
18
  * @return Resolves once all pending stylesheets, necessary for
30
19
  * the chunk, are either loaded, or failed to load.
31
- */async function bookStyleSheets(chunkName,chunkGroups,refCount){const promises=[];const assets=chunkGroups[chunkName];if(!assets)return Promise.resolve();const loadedSheets=getLoadedStyleSheets();for(const asset of assets){if(asset.endsWith(".css")){const promise=bookStyleSheet(asset,loadedSheets,refCount);if(promise)promises.push(promise)}}return promises.length?Promise.allSettled(promises).then():Promise.resolve()}/**
20
+ */export async function bookStyleSheets(chunkName,chunkGroups,refCount){const promises=[];const assets=chunkGroups[chunkName];if(!assets)return Promise.resolve();const loadedSheets=getLoadedStyleSheets();for(const asset of assets){if(asset.endsWith(".css")){const promise=bookStyleSheet(asset,loadedSheets,refCount);if(promise)promises.push(promise)}}return promises.length?Promise.allSettled(promises).then():Promise.resolve()}/**
32
21
  * Client-side only! Frees from the document all CSS stylesheets that are
33
22
  * required by the specified chunk, and have reference counter equal to one
34
23
  * (for chunks with larger reference counter values, it just decrements
35
24
  * the reference counter).
36
25
  * @param {string} chunkName
37
- */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.
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.
38
27
  const usedChunkNames=new Set;/**
39
28
  * Given an async component retrieval function `getComponent()` it creates
40
29
  * a special "code split" component, which uses <Suspense> to asynchronously
@@ -44,16 +33,16 @@ const usedChunkNames=new Set;/**
44
33
  * @param {function} options.getComponent
45
34
  * @param {React.Element} [options.placeholder]
46
35
  * @return {React.ElementType}
47
- */function splitComponent({chunkName,getComponent,placeholder}){// On the client side we can check right away if the chunk name is known.
48
- if(_isomorphy.IS_CLIENT_SIDE)assertChunkName(chunkName,clientChunkGroups);// The correct usage of splitComponent() assumes a single call per chunk.
49
- if(usedChunkNames.has(chunkName)){throw Error(`Repeated splitComponent() call for the chunk "${chunkName}"`)}else usedChunkNames.add(chunkName);const LazyComponent=/*#__PURE__*/(0,_react.lazy)(async()=>{const resolved=await getComponent();const Component="default"in resolved?resolved.default:resolved;// This pre-loads necessary stylesheets prior to the first mount of
36
+ */export default function splitComponent({chunkName,getComponent,placeholder}){// The correct usage of splitComponent() assumes a single call per chunk.
37
+ if(usedChunkNames.has(chunkName)){throw Error(`Repeated splitComponent() call for the chunk "${chunkName}"`)}else usedChunkNames.add(chunkName);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
+ 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
50
39
  // the component (the lazy load function is executed by React one at
51
40
  // the frist mount).
52
- if(_isomorphy.IS_CLIENT_SIDE){await bookStyleSheets(chunkName,clientChunkGroups,false)}const Wrapper=({children,ref,...rest})=>{// On the server side we'll assert the chunk name here,
41
+ if(IS_CLIENT_SIDE){if(!clientChunkGroups)throw Error("Internal error");await bookStyleSheets(chunkName,clientChunkGroups,false)}const Wrapper=({children,ref,...rest})=>{// On the server side we'll assert the chunk name here,
53
42
  // and also push it to the SSR chunks array.
54
- if(_isomorphy.IS_SERVER_SIDE){const{chunkGroups,chunks}=(0,_globalState.getSsrContext)();assertChunkName(chunkName,chunkGroups);if(!chunks.includes(chunkName))chunks.push(chunkName)}// This takes care about stylesheets management every time an instance of
43
+ if(IS_SERVER_SIDE){const{chunkGroups,chunks}=getSsrContext();assertChunkName(chunkName,chunkGroups);if(!chunks.includes(chunkName))chunks.push(chunkName)}// This takes care about stylesheets management every time an instance of
55
44
  // this component is mounted / unmounted.
56
- (0,_react.useInsertionEffect)(()=>{void bookStyleSheets(chunkName,clientChunkGroups,true);return()=>{freeStyleSheets(chunkName,clientChunkGroups)}},[]);return/*#__PURE__*/(0,_jsxRuntime.jsx)(Component// eslint-disable-next-line react/jsx-props-no-spreading
57
- ,{...rest,ref:ref,children:children})};return{default:Wrapper}});const CodeSplit=({children,...rest})=>/*#__PURE__*/(0,_jsxRuntime.jsx)(_react.Suspense,{fallback:placeholder,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(LazyComponent// eslint-disable-next-line react/jsx-props-no-spreading
45
+ useInsertionEffect(()=>{if(!clientChunkGroups)throw Error("Internal error");void bookStyleSheets(chunkName,clientChunkGroups,true);return()=>{freeStyleSheets(chunkName,clientChunkGroups)}},[]);return/*#__PURE__*/_jsx(Component// eslint-disable-next-line react/jsx-props-no-spreading
46
+ ,{...rest,ref:ref,children:children})};return{default:Wrapper}});const CodeSplit=({children,...rest})=>/*#__PURE__*/_jsx(Suspense,{fallback:placeholder,children:/*#__PURE__*/_jsx(LazyComponent// eslint-disable-next-line react/jsx-props-no-spreading
58
47
  ,{...rest,children:children})});return CodeSplit}
59
48
  //# sourceMappingURL=splitComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"splitComponent.js","names":["_react","require","_jsUtils","_globalState","_isomorphy","_jsxRuntime","clientChunkGroups","IS_CLIENT_SIDE","default","CHUNK_GROUPS","refCounts","getPublicPath","getBuildInfo","publicPath","bookStyleSheet","name","loadedSheets","refCount","res","path","fullPath","document","location","origin","has","link","querySelector","createElement","setAttribute","head","appendChild","Barrier","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","lazy","resolved","Component","Wrapper","children","ref","rest","IS_SERVER_SIDE","chunks","getSsrContext","includes","useInsertionEffect","jsx","CodeSplit","Suspense","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\n// Note: At the client side we can get chunk groups immediately when loading\n// the module; at the server-side we only can get them within React render flow.\n// Thus, we set and use the following variable at the client-side, and then when\n// needed on the server side, we'll fetch it differently.\nlet clientChunkGroups: ChunkGroupsT;\n\nif (IS_CLIENT_SIDE) {\n // TODO: Rewrite to avoid these overrides of ESLint rules.\n /* eslint-disable @typescript-eslint/no-unsafe-assignment,\n @typescript-eslint/no-require-imports,\n @typescript-eslint/no-unsafe-call,\n @typescript-eslint/no-unsafe-member-access */\n clientChunkGroups = require('client/getInj').default().CHUNK_GROUPS ?? {};\n /* eslint-enable @typescript-eslint/no-unsafe-assignment,\n @typescript-eslint/no-require-imports,\n @typescript-eslint/no-unsafe-call,\n @typescript-eslint/no-unsafe-member-access */\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\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 { children?: ReactNode; ref?: RefObject<unknown> },\n>({\n chunkName,\n getComponent,\n placeholder,\n}: {\n chunkName: string;\n getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;\n placeholder?: ReactNode;\n}): FunctionComponent<ComponentPropsT> {\n // On the client side we can check right away if the chunk name is known.\n if (IS_CLIENT_SIDE) assertChunkName(chunkName, clientChunkGroups);\n\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 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 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 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":"qLAEA,IAAAA,MAAA,CAAAC,OAAA,UAUA,IAAAC,QAAA,CAAAD,OAAA,yBAEA,IAAAE,YAAA,CAAAF,OAAA,kBAEA,IAAAG,UAAA,CAAAH,OAAA,gBAIqB,IAAAI,WAAA,CAAAJ,OAAA,sBApBrB,qBAsBA;AACA;AACA;AACA;AACA,GAAI,CAAAK,iBAA+B,CAEnC,GAAIC,yBAAc,CAAE,CAClB;AACA;AACF;AACA;AACA,iDACED,iBAAiB,CAAGL,OAAO,sBAAgB,CAAC,CAACO,OAAO,CAAC,CAAC,CAACC,YAAY,EAAI,CAAC,CAAC,CACzE;AACF;AACA;AACA,iDACA,CAEA,KAAM,CAAAC,SAAiC,CAAG,CAAC,CAAC,CAE5C,QAAS,CAAAC,aAAaA,CAAA,CAAG,CACvB,MAAO,GAAAC,uBAAY,EAAC,CAAC,CAACC,UACxB,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,CAAAC,cAAcA,CACrBC,IAAY,CACZC,YAAyB,CACzBC,QAAiB,CACU,CAC3B,GAAI,CAAAC,GAA8B,CAClC,KAAM,CAAAC,IAAI,CAAG,GAAGR,aAAa,CAAC,CAAC,IAAII,IAAI,EAAE,CACzC,KAAM,CAAAK,QAAQ,CAAG,GAAGC,QAAQ,CAACC,QAAQ,CAACC,MAAM,GAAGJ,IAAI,EAAE,CAErD,GAAI,CAACH,YAAY,CAACQ,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EpC,iBAAiB,CAAE,KAAK,CAC3D,CAEA,KAAM,CAAA4D,OAA2C,CAAGA,CAAC,CACnDC,QAAQ,CACRC,GAAG,CACH,GAAGC,IACL,CAAC,GAAK,CACJ;AACA;AACA,GAAIC,yBAAc,CAAE,CAClB,KAAM,CAAE3B,WAAW,CAAE4B,MAAO,CAAC,CAAG,GAAAC,0BAAa,EAAC,CAAE,CAChD/B,eAAe,CAACC,SAAS,CAAEC,WAAW,CAAC,CACvC,GAAI,CAAC4B,MAAM,CAACE,QAAQ,CAAC/B,SAAS,CAAC,CAAE6B,MAAM,CAACpB,IAAI,CAACT,SAAS,CACxD,CAEA;AACA;AACA,GAAAgC,yBAAkB,EAAC,IAAM,CACvB,IAAK,CAAA9B,eAAe,CAACF,SAAS,CAAEpC,iBAAiB,CAAE,IAAI,CAAC,CACxD,MAAO,IAAM,CACXiD,eAAe,CAACb,SAAS,CAAEpC,iBAAiB,CAC9C,CACF,CAAC,CAAE,EAAE,CAAC,CAEN,mBACE,GAAAD,WAAA,CAAAsE,GAAA,EAACV,SACC;AAAA,KACKI,IAAI,CACTD,GAAG,CAAEA,GAAI,CAAAD,QAAA,CAERA,QAAQ,CACA,CAEf,CAAC,CAED,MAAO,CAAE3D,OAAO,CAAE0D,OAAQ,CAC5B,CAAC,CAAC,CAEF,KAAM,CAAAU,SAAmD,CAAGA,CAAC,CAC3DT,QAAQ,CACR,GAAGE,IACY,CAAC,gBAChB,GAAAhE,WAAA,CAAAsE,GAAA,EAAC3E,MAAA,CAAA6E,QAAQ,EAACC,QAAQ,CAAEjB,WAAY,CAAAM,QAAA,cAC9B,GAAA9D,WAAA,CAAAsE,GAAA,EAACb,aACC;AAAA,KACIO,IAAI,CAAAF,QAAA,CAEPA,QAAQ,CACI,CAAC,CACR,CACX,CAED,MAAO,CAAAS,SACT","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","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":"83BAAA,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,CAAE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ACC,QAAQ,CAAC7B,SAAS,CAAC,CAAE4B,MAAM,CAACnB,IAAI,CAACT,SAAS,CACxD,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,CAC9C,CACF,CAAC,CAAE,EAAE,CAAC,CAEN,mBACE1D,IAAA,CAAC4D,SACC;AAAA,KACKI,IAAI,CACTD,GAAG,CAAEA,GAAI,CAAAD,QAAA,CAERA,QAAQ,CACA,CAEf,CAAC,CAED,MAAO,CAAE3D,OAAO,CAAE0D,OAAQ,CAC5B,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,SACT","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;exports.useCurrent=useCurrent;exports.useTimezoneOffset=useTimezoneOffset;var _cookie=require("cookie");var _react=require("react");var _dayjs=_interopRequireDefault(require("dayjs"));var _jsUtils=require("@dr.pogodin/js-utils");var _reactGlobalState=require("@dr.pogodin/react-global-state");var _globalState=require("./globalState");/**
1
+ import{serialize}from"cookie";import{useEffect}from"react";import dayjs from"dayjs";import{DAY_MS,HOUR_MS,MIN_MS,SEC_MS,YEAR_MS,timer}from"@dr.pogodin/js-utils";import{useGlobalState}from"@dr.pogodin/react-global-state";import{getSsrContext}from"./globalState.js";/**
2
2
  * This react hook wraps Date.now() function in a SSR friendly way,
3
3
  * ensuring that all calls to useCurrent() within the same render return
4
4
  * exactly the same time (which is retrieved from Date.now() first, and
@@ -7,7 +7,7 @@
7
7
  * with a finite precision to avoid infinite re-rendering loops.
8
8
  */// TODO: Should we request the state type as generic parameter, to be able
9
9
  // to verify the give globalStatePath is correct?
10
- function useCurrent({autorefresh=false,globalStatePath="currentTime",precision=5*_jsUtils.SEC_MS}={}){const[now,setter]=(0,_reactGlobalState.useGlobalState)(globalStatePath,Date.now);(0,_react.useEffect)(()=>{let timerId;const update=()=>{setter(old=>{const neu=Date.now();return Math.abs(neu-old)>precision?neu:old});if(autorefresh)timerId=setTimeout(update,precision)};update();return()=>{if(timerId)clearTimeout(timerId)}},[autorefresh,precision,setter]);return now}/**
10
+ export function useCurrent({autorefresh=false,globalStatePath="currentTime",precision=5*SEC_MS}={}){const[now,setter]=useGlobalState(globalStatePath,Date.now);useEffect(()=>{let timerId;const update=()=>{setter(old=>{const neu=Date.now();return Math.abs(neu-old)>precision?neu:old});if(autorefresh)timerId=setTimeout(update,precision)};update();return()=>{if(timerId)clearTimeout(timerId)}},[autorefresh,precision,setter]);return now}/**
11
11
  * Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.
12
12
  * This hook retrieves the offset value at the client side and uses a cookie
13
13
  * to pass it to the server in subsequent requests from that user. At the server
@@ -17,5 +17,5 @@ function useCurrent({autorefresh=false,globalStatePath="currentTime",precision=5
17
17
  * as the default value.
18
18
  */// TODO: Should we request the state type as generic parameter, to be able
19
19
  // to verify the give globalStatePath is correct?
20
- function useTimezoneOffset({cookieName="timezoneOffset",globalStatePath="timezoneOffset"}={}){const ssrContext=(0,_globalState.getSsrContext)(false);const[offset,setOffset]=(0,_reactGlobalState.useGlobalState)(globalStatePath,()=>{const value=cookieName&&ssrContext?.req.cookies[cookieName];return value?parseInt(value):0});(0,_react.useEffect)(()=>{const date=new Date;const value=date.getTimezoneOffset();setOffset(value);if(cookieName){document.cookie=(0,_cookie.serialize)(cookieName,value.toString(),{path:"/"})}},[cookieName,setOffset]);return offset}const time={DAY_MS:_jsUtils.DAY_MS,HOUR_MS:_jsUtils.HOUR_MS,MIN_MS:_jsUtils.MIN_MS,SEC_MS:_jsUtils.SEC_MS,YEAR_MS:_jsUtils.YEAR_MS,now:Date.now,timer:_jsUtils.timer,useCurrent,useTimezoneOffset};var _default=exports.default=Object.assign(_dayjs.default,time);
20
+ export function useTimezoneOffset({cookieName="timezoneOffset",globalStatePath="timezoneOffset"}={}){const ssrContext=getSsrContext(false);const[offset,setOffset]=useGlobalState(globalStatePath,()=>{const value=cookieName&&ssrContext?.req.cookies[cookieName];return value?parseInt(value):0});useEffect(()=>{const date=new Date;const value=date.getTimezoneOffset();setOffset(value);if(cookieName){document.cookie=serialize(cookieName,value.toString(),{path:"/"})}},[cookieName,setOffset]);return offset}const time={DAY_MS,HOUR_MS,MIN_MS,SEC_MS,YEAR_MS,now:Date.now,timer,useCurrent,useTimezoneOffset};export default Object.assign(dayjs,time);
21
21
  //# sourceMappingURL=time.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"time.js","names":["_cookie","require","_react","_dayjs","_interopRequireDefault","_jsUtils","_reactGlobalState","_globalState","useCurrent","autorefresh","globalStatePath","precision","SEC_MS","now","setter","useGlobalState","Date","useEffect","timerId","update","old","neu","Math","abs","setTimeout","clearTimeout","useTimezoneOffset","cookieName","ssrContext","getSsrContext","offset","setOffset","value","req","cookies","parseInt","date","getTimezoneOffset","document","cookie","serialize","toString","path","time","DAY_MS","HOUR_MS","MIN_MS","YEAR_MS","timer","_default","exports","default","Object","assign","dayjs"],"sources":["../../../../src/shared/utils/time.ts"],"sourcesContent":["import { serialize } from 'cookie';\nimport { useEffect } from 'react';\nimport dayjs from 'dayjs';\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":"0PAAA,IAAAA,OAAA,CAAAC,OAAA,WACA,IAAAC,MAAA,CAAAD,OAAA,UACA,IAAAE,MAAA,CAAAC,sBAAA,CAAAH,OAAA,WAEA,IAAAI,QAAA,CAAAJ,OAAA,yBASA,IAAAK,iBAAA,CAAAL,OAAA,mCAEA,IAAAM,YAAA,CAAAN,OAAA,kBAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA;AACA;AACO,QAAS,CAAAO,UAAUA,CAAC,CACzBC,WAAW,CAAG,KAAK,CACnBC,eAAe,CAAG,aAAa,CAC/BC,SAAS,CAAG,CAAC,CAAGC,eAClB,CAAC,CAAG,CAAC,CAAC,CAAU,CACd,KAAM,CAACC,GAAG,CAAEC,MAAM,CAAC,CAAG,GAAAC,gCAAc,EAClCL,eAAe,CACfM,IAAI,CAACH,GACP,CAAC,CACD,GAAAI,gBAAS,EAAC,IAAM,CACd,GAAI,CAAAC,OAAmC,CACvC,KAAM,CAAAC,MAAM,CAAGA,CAAA,GAAY,CACzBL,MAAM,CAAEM,GAAG,EAAK,CACd,KAAM,CAAAC,GAAG,CAAGL,IAAI,CAACH,GAAG,CAAC,CAAC,CACtB,MAAO,CAAAS,IAAI,CAACC,GAAG,CAACF,GAAG,CAAGD,GAAG,CAAC,CAAGT,SAAS,CAAGU,GAAG,CAAGD,GACjD,CAAC,CAAC,CACF,GAAIX,WAAW,CAAES,OAAO,CAAGM,UAAU,CAACL,MAAM,CAAER,SAAS,CACzD,CAAC,CACDQ,MAAM,CAAC,CAAC,CACR,MAAO,IAAY,CACjB,GAAID,OAAO,CAAEO,YAAY,CAACP,OAAO,CACnC,CACF,CAAC,CAAE,CAACT,WAAW,CAAEE,SAAS,CAAEG,MAAM,CAAC,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,CAAAC,OAAA,CAAAC,OAAA,CAEaC,MAAM,CAACC,MAAM,CAACC,cAAK,CAAEX,IAAI,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"time.js","names":["serialize","useEffect","dayjs","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 { useEffect } from 'react';\nimport dayjs from 'dayjs';\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,OAASC,SAAS,KAAQ,OAAO,CACjC,MAAO,CAAAC,KAAK,KAAM,OAAO,CAEzB,OACEC,MAAM,CACNC,OAAO,CACPC,MAAM,CACNC,MAAM,CACNC,OAAO,CACPC,KAAK,KACA,sBAAsB,CAE7B,OAAsBC,cAAc,KAAQ,gCAAgC,QAEnEC,aAAa,wBAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA;AACA;AACA,MAAO,SAAS,CAAAC,UAAUA,CAAC,CACzBC,WAAW,CAAG,KAAK,CACnBC,eAAe,CAAG,aAAa,CAC/BC,SAAS,CAAG,CAAC,CAAGR,MAClB,CAAC,CAAG,CAAC,CAAC,CAAU,CACd,KAAM,CAACS,GAAG,CAAEC,MAAM,CAAC,CAAGP,cAAc,CAClCI,eAAe,CACfI,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AAC,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,CACzE,CACF,CAAC,CAAE,CAACb,UAAU,CAAEG,SAAS,CAAC,CAAC,CAC3B,MAAO,CAAAD,MACT,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,CAACzC,KAAK,CAAEuC,IAAI,CAAC","ignoreList":[]}
@@ -1,20 +1,20 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.requireWeak=requireWeak;exports.resolveWeak=resolveWeak;var _isomorphy=require("./isomorphy");/**
1
+ import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.iterator.for-each.js";import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.iterator.for-each.js";// eslint-disable-next-line import/enforce-node-protocol-usage
2
+ import{createRequire}from"module";import{IS_CLIENT_SIDE,IS_SERVER_SIDE}from"./isomorphy/index.js";let require;if(IS_SERVER_SIDE)require=createRequire(import.meta.url);/**
2
3
  * Requires the specified module without including it into the bundle during
3
4
  * Webpack build.
4
5
  * @param modulePath
5
6
  * @param [basePath]
6
7
  * @return Required module.
7
- */function requireWeak(modulePath,// TODO: For now `basePath` can be provided directly as a string here,
8
+ */export function requireWeak(modulePath,// TODO: For now `basePath` can be provided directly as a string here,
8
9
  // for backward compatibility. Deprecate it in future, if any other
9
10
  // breaking changes are done for requireWeak().
10
- basePathOrOptions){if(_isomorphy.IS_CLIENT_SIDE)return null;let basePath;let ops;if(typeof basePathOrOptions==="string"){basePath=basePathOrOptions}else{ops=basePathOrOptions??{};({basePath}=ops)}// eslint-disable-next-line no-eval
11
- const req=eval("require");// eslint-disable-next-line @typescript-eslint/unbound-method
12
- const{resolve}=req("path");const path=basePath?resolve(basePath,modulePath):modulePath;const module=req(path);if(!("default"in module)||!module.default)return module;const{default:def,...named}=module;const res=def;Object.entries(named).forEach(([name,value])=>{const assigned=res[name];if(assigned)res[name]=value;else if(assigned!==value){throw Error("Conflict between default and named exports")}});return res}/**
11
+ basePathOrOptions){if(IS_CLIENT_SIDE)return null;let basePath;let ops;if(typeof basePathOrOptions==="string"){basePath=basePathOrOptions}else{ops=basePathOrOptions??{};({basePath}=ops)}// eslint-disable-next-line @typescript-eslint/unbound-method
12
+ const{resolve}=require("node:path");const path=basePath?resolve(basePath,modulePath):modulePath;const module=require(path);if(!("default"in module)||!module.default)return module;const{default:def,...named}=module;const res=def;Object.entries(named).forEach(([name,value])=>{const assigned=res[name];if(assigned===undefined){res[name]=value}else if(assigned!==value){throw Error("Conflict between default and named exports")}});return res}/**
13
13
  * Resolves specified module path with help of Babel's module resolver.
14
14
  * Yes, the function itself just returns its argument to the caller, but Babel
15
15
  * is configured to resolve the first argument of resolveWeak(..) function, thus
16
16
  * the result will be the resolved path.
17
17
  * @param {string} modulePath
18
18
  * @return {string} Absolute or relative path to the module.
19
- */function resolveWeak(modulePath){return modulePath}
19
+ */export function resolveWeak(modulePath){return modulePath}
20
20
  //# sourceMappingURL=webpack.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webpack.js","names":["_isomorphy","require","requireWeak","modulePath","basePathOrOptions","IS_CLIENT_SIDE","basePath","ops","req","eval","resolve","path","module","default","def","named","res","Object","entries","forEach","name","value","assigned","Error","resolveWeak"],"sources":["../../../../src/shared/utils/webpack.ts"],"sourcesContent":["import type PathNS from 'node:path';\n\nimport { IS_CLIENT_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\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?: string | RequireWeakOptionsT,\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 no-eval\n const req = eval('require') as (path: string) => unknown;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const { resolve } = req('path') as typeof PathNS;\n\n const path = basePath ? resolve(basePath, modulePath) : modulePath;\n const module = req(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) (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":"sIAEA,IAAAA,UAAA,CAAAC,OAAA,gBAUA;AACA;AACA;AACA;AACA;AACA;AACA,GACO,QAAS,CAAAC,WAAWA,CACzBC,UAAkB,CAElB;AACA;AACA;AACAC,iBAAgD,CACrB,CAC3B,GAAIC,yBAAc,CAAE,MAAO,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AAAA,UACT","ignoreList":[]}
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\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?: string | RequireWeakOptionsT,\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":"sMAEA;AACA,OAASA,aAAa,KAAQ,QAAQ,QAE7BC,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,iBACb,CAAC,IAAM,CACLE,GAAG,CAAGF,iBAAiB,EAAI,CAAC,CAAC,CAC7B,CAAC,CAAEC,QAAS,CAAC,CAAGC,GAAG,CACrB,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,KACvD,CAAC,IAAM,IAAIC,QAAQ,GAAKD,KAAK,CAAE,CAC7B,KAAM,CAAAG,KAAK,CAAC,4CAA4C,CAC1D,CACF,CAAC,CAAC,CACF,MAAO,CAAAR,GACT,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAS,WAAWA,CAACnB,UAAkB,CAAU,CACtD,MAAO,CAAAA,UACT","ignoreList":[]}
@@ -1,3 +1,2 @@
1
- import 'node-forge/lib/aes';
2
1
  import type { InjT } from '../shared/utils/globalState';
3
- export default function getInj(): InjT;
2
+ export default function getInj(): InjT | Promise<InjT>;
@@ -8,5 +8,5 @@ type OptionsT = {
8
8
  * @param Application Root application component
9
9
  * @param [options={}] Optional. Additional settings.
10
10
  */
11
- export default function Launch(Application: ComponentType, options?: OptionsT): void;
11
+ export declare function launchClient(Application: ComponentType, options?: OptionsT): Promise<void>;
12
12
  export {};
@@ -1,10 +1,4 @@
1
- import 'styles/global.scss';
2
- import type * as ClientM from './client';
3
- import type * as ServerFactoryM from './server';
4
- declare const server: (typeof ServerFactoryM.default & Omit<typeof ServerFactoryM, "default">) | null;
5
- declare const client: typeof ClientM.default | undefined;
6
1
  export { type AsyncCollectionT, type AsyncCollectionLoaderT, type AsyncDataEnvelopeT, type AsyncDataLoaderT, type ForceT, type UseAsyncDataOptionsT, type UseAsyncDataResT, type UseGlobalStateResT, type ValueOrInitializerT, getGlobalState, GlobalStateProvider, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, withGlobalStateType, } from '@dr.pogodin/react-global-state';
7
2
  export * from './shared/components';
8
3
  export { type BeforeRenderResT, type BeforeRenderT, type ConfigT, type ServerSsrContext, type ServerT, } from './server';
9
- export { assertEmptyObject, config, Barrier, Cached, Emitter, isomorphy, getSsrContext, type Listener, type ObjectKey, Semaphore, splitComponent, type Theme, themed, ThemeProvider, time, webpack, withRetries, } from './shared/utils';
10
- export { client, server };
4
+ export { assertEmptyObject, Barrier, Cached, Emitter, getConfig, isomorphy, getSsrContext, type Listener, type ObjectKey, Semaphore, splitComponent, type Theme, themed, ThemeProvider, time, webpack, withRetries, } from './shared/utils';
@@ -1,11 +1,12 @@
1
- import 'source-map-support/register';
1
+ import 'source-map-support/register.js';
2
2
  import http from 'node:http';
3
- import 'raf/polyfill';
3
+ import 'raf/polyfill.js';
4
4
  import type { Configuration } from 'webpack';
5
5
  import { type OptionsT as ServerOptionsT, type ServerT, getDefaultCspSettings } from './server';
6
- import { errors } from './utils';
6
+ import { SCRIPT_LOCATIONS } from './renderer';
7
+ export * from './utils';
7
8
  export type { BeforeRenderResT, BeforeRenderT, ConfigT, ServerSsrContext, } from './renderer';
8
- export { errors, getDefaultCspSettings, type ServerT };
9
+ export { getDefaultCspSettings, SCRIPT_LOCATIONS, type ServerT, };
9
10
  type OptionsT = ServerOptionsT & {
10
11
  https?: {
11
12
  cert: string;
@@ -131,13 +132,7 @@ type OptionsT = ServerOptionsT & {
131
132
  * defaults to 1 second.
132
133
  * @return Resolves to an object with created Express and HTTP servers.
133
134
  */
134
- declare function launchServer(webpackConfig: Configuration, options?: OptionsT): Promise<{
135
+ export declare function launchServer(webpackConfig: Configuration, options?: OptionsT): Promise<{
135
136
  expressServer: ServerT;
136
137
  httpServer: http.Server;
137
138
  }>;
138
- declare namespace launchServer {
139
- var SCRIPT_LOCATIONS: typeof import("./renderer").SCRIPT_LOCATIONS;
140
- var getDefaultCspSettings: typeof import("./server").getDefaultCspSettings;
141
- var errors: typeof import("./utils/errors");
142
- }
143
- export default launchServer;
@@ -1 +1 @@
1
- export * as errors from './errors';
1
+ export * from './errors';
@@ -1,2 +1,4 @@
1
- declare const config: Record<string, unknown>;
2
- export default config;
1
+ type ConfigT = Record<string, unknown>;
2
+ export declare function getConfig(sync: true): ConfigT;
3
+ export declare function getConfig(sync?: boolean): ConfigT | Promise<ConfigT>;
4
+ export {};
@@ -1,5 +1,5 @@
1
1
  import themedImpl, { COMPOSE, PRIORITY, type Theme, ThemeProvider } from '@dr.pogodin/react-themes';
2
- import config from './config';
2
+ import { getConfig } from './config';
3
3
  import * as isomorphy from './isomorphy';
4
4
  import time from './time';
5
5
  import * as webpack from './webpack';
@@ -11,4 +11,4 @@ type ThemedT = typeof themedImpl & {
11
11
  PRIORITY: typeof PRIORITY;
12
12
  };
13
13
  declare const themed: ThemedT;
14
- export { type Theme, config, isomorphy, themed, ThemeProvider, time, webpack, };
14
+ export { type Theme, getConfig, isomorphy, themed, ThemeProvider, time, webpack, };
@@ -21,6 +21,11 @@ export declare function freeStyleSheets(chunkName: string, chunkGroups: ChunkGro
21
21
  type ComponentOrModule<PropsT> = ComponentType<PropsT> | {
22
22
  default: ComponentType<PropsT>;
23
23
  };
24
+ type GenericComponentPropsT = {
25
+ children?: ReactNode;
26
+ ref?: RefObject<unknown>;
27
+ [propName: string]: unknown;
28
+ };
24
29
  /**
25
30
  * Given an async component retrieval function `getComponent()` it creates
26
31
  * a special "code split" component, which uses <Suspense> to asynchronously
@@ -31,10 +36,7 @@ type ComponentOrModule<PropsT> = ComponentType<PropsT> | {
31
36
  * @param {React.Element} [options.placeholder]
32
37
  * @return {React.ElementType}
33
38
  */
34
- export default function splitComponent<ComponentPropsT extends {
35
- children?: ReactNode;
36
- ref?: RefObject<unknown>;
37
- }>({ chunkName, getComponent, placeholder, }: {
39
+ export default function splitComponent<ComponentPropsT extends GenericComponentPropsT>({ chunkName, getComponent, placeholder, }: {
38
40
  chunkName: string;
39
41
  getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;
40
42
  placeholder?: ReactNode;
@@ -0,0 +1,65 @@
1
+ import "core-js/modules/es.array-buffer.detached.js";
2
+ import "core-js/modules/es.array-buffer.transfer.js";
3
+ import "core-js/modules/es.array-buffer.transfer-to-fixed-length.js";
4
+ import "core-js/modules/es.typed-array.to-reversed.js";
5
+ import "core-js/modules/es.typed-array.to-sorted.js";
6
+ import "core-js/modules/es.typed-array.with.js";
7
+ import "core-js/modules/web.dom-exception.stack.js";
8
+ // Encapsulates retrieval of server-side data injection into HTML template.
9
+
10
+ /* global document */
11
+
12
+ import { getBuildInfo } from "../shared/utils/isomorphy/buildInfo";
13
+ let inj;
14
+ export default function getInj() {
15
+ inj ??= (async () => {
16
+ const metaElement = typeof document === 'undefined' ? null : document.querySelector('meta[itemprop="drpruinj"]');
17
+ if (metaElement) {
18
+ metaElement.remove();
19
+
20
+ // NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be
21
+ // preferred, but it is not supported by older environments yet.
22
+ const data = atob(metaElement.content);
23
+
24
+ // TODO: Our current handling of this encryption / decryption follows
25
+ // a legacy approach, and can be enhanced by using Crypto features.
26
+ // Though, this is not strictly intended to be secure (it is more
27
+ // to obfurscate injected data, rather than really keeping them
28
+ // secure), thus it is fine like this for now.
29
+ const {
30
+ key
31
+ } = getBuildInfo();
32
+ const code = x => x.charCodeAt(0);
33
+ const dataBuffer = Uint8Array.from(data.slice(16), code);
34
+ const ivBuffer = Uint8Array.from(data.slice(0, 16), code);
35
+ const keyBuffer = Uint8Array.from(atob(key), code);
36
+ const cKey = await window.crypto.subtle.importKey('raw', keyBuffer, {
37
+ name: 'AES-CBC'
38
+ }, false, ['decrypt']);
39
+ const buffer = await window.crypto.subtle.decrypt({
40
+ iv: ivBuffer,
41
+ name: 'AES-CBC'
42
+ }, cKey, dataBuffer);
43
+ const decoder = new TextDecoder();
44
+
45
+ // eslint-disable-next-line no-eval
46
+ const res = eval(`(${decoder.decode(buffer)})`);
47
+
48
+ // NOTE: This is important, to be able to return the injection
49
+ // synchronously once it is initialized.
50
+ inj = res;
51
+ return res;
52
+ } else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {
53
+ const res = window.REACT_UTILS_INJECTION;
54
+ delete window.REACT_UTILS_INJECTION;
55
+ return res;
56
+ }
57
+
58
+ // Otherwise, a bunch of dependent stuff will easily fail in non-standard
59
+ // environments, where no client-side initialization is performed. Like tests,
60
+ // Docusaurus examples, etc.
61
+ return {};
62
+ })();
63
+ return inj;
64
+ }
65
+ //# sourceMappingURL=getInj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getInj.js","names":["getBuildInfo","inj","getInj","metaElement","document","querySelector","remove","data","atob","content","key","code","x","charCodeAt","dataBuffer","Uint8Array","from","slice","ivBuffer","keyBuffer","cKey","window","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 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 // TODO: Our current handling of this encryption / decryption follows\n // a legacy approach, and can be enhanced by using Crypto features.\n // Though, this is not strictly intended to be secure (it is more\n // to obfurscate injected data, rather than really keeping them\n // secure), thus it is fine like this for now.\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":";;;;;;;AAAA;;AAEA;;AAIA,SAASA,YAAY;AAErB,IAAIC,GAAqC;AAEzC,eAAe,SAASC,MAAMA,CAAA,EAAyB;EACrDD,GAAG,KAAK,CAAC,YAAY;IACnB,MAAME,WAAmC,GAAG,OAAOC,QAAQ,KAAK,WAAW,GACvE,IAAI,GAAGA,QAAQ,CAACC,aAAa,CAAC,2BAA2B,CAAC;IAE9D,IAAIF,WAAW,EAAE;MACfA,WAAW,CAACG,MAAM,CAAC,CAAC;;MAEpB;MACA;MACA,MAAMC,IAAI,GAAGC,IAAI,CAACL,WAAW,CAACM,OAAO,CAAC;;MAEtC;MACA;MACA;MACA;MACA;MACA,MAAM;QAAEC;MAAI,CAAC,GAAGV,YAAY,CAAC,CAAC;MAE9B,MAAMW,IAAI,GAAIC,CAAS,IAAKA,CAAC,CAACC,UAAU,CAAC,CAAC,CAAC;MAC3C,MAAMC,UAAU,GAAGC,UAAU,CAACC,IAAI,CAACT,IAAI,CAACU,KAAK,CAAC,EAAE,CAAC,EAAEN,IAAI,CAAC;MACxD,MAAMO,QAAQ,GAAGH,UAAU,CAACC,IAAI,CAACT,IAAI,CAACU,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAEN,IAAI,CAAC;MACzD,MAAMQ,SAAS,GAAGJ,UAAU,CAACC,IAAI,CAACR,IAAI,CAACE,GAAG,CAAC,EAAEC,IAAI,CAAC;MAElD,MAAMS,IAAI,GAAG,MAAMC,MAAM,CAACC,MAAM,CAACC,MAAM,CAACC,SAAS,CAC/C,KAAK,EACLL,SAAS,EACT;QAAEM,IAAI,EAAE;MAAU,CAAC,EACnB,KAAK,EACL,CAAC,SAAS,CACZ,CAAC;MAED,MAAMC,MAAM,GAAG,MAAML,MAAM,CAACC,MAAM,CAACC,MAAM,CAACI,OAAO,CAAC;QAChDC,EAAE,EAAEV,QAAQ;QACZO,IAAI,EAAE;MACR,CAAC,EAAEL,IAAI,EAAEN,UAAU,CAAC;MAEpB,MAAMe,OAAO,GAAG,IAAIC,WAAW,CAAC,CAAC;;MAEjC;MACA,MAAMC,GAAG,GAAGC,IAAI,CAAC,IAAIH,OAAO,CAACI,MAAM,CAACP,MAAM,CAAC,GAAG,CAAS;;MAEvD;MACA;MACAzB,GAAG,GAAG8B,GAAG;MAET,OAAOA,GAAG;IACZ,CAAC,MAAM,IAAI,OAAOV,MAAM,KAAK,WAAW,IAAIA,MAAM,CAACa,qBAAqB,EAAE;MACxE,MAAMH,GAAG,GAAGV,MAAM,CAACa,qBAAqB;MACxC,OAAOb,MAAM,CAACa,qBAAqB;MACnC,OAAOH,GAAG;IACZ;;IAEA;IACA;IACA;IACA,OAAO,CAAC,CAAC;EACX,CAAC,EAAE,CAAC;EAEJ,OAAO9B,GAAG;AACZ","ignoreList":[]}
@@ -1,43 +1,32 @@
1
1
  // Initialization of client-side code.
2
2
  /* global document */
3
3
 
4
- import type { ComponentType } from 'react';
5
4
  import { createRoot, hydrateRoot } from 'react-dom/client';
6
5
  import { HelmetProvider } from '@dr.pogodin/react-helmet';
7
6
  import { BrowserRouter } from 'react-router';
8
-
9
7
  import { GlobalStateProvider } from '@dr.pogodin/react-global-state';
10
-
11
- import getInj from './getInj';
12
-
13
- type OptionsT = {
14
- dontHydrate?: boolean;
15
- initialState?: unknown;
16
- };
17
-
8
+ import getInj from "./getInj";
9
+ import { jsx as _jsx } from "react/jsx-runtime";
18
10
  /**
19
11
  * Prepares and launches the app at client side.
20
12
  * @param Application Root application component
21
13
  * @param [options={}] Optional. Additional settings.
22
14
  */
23
- export default function Launch(
24
- Application: ComponentType,
25
- options: OptionsT = {},
26
- ): void {
15
+ export async function launchClient(Application, options = {}) {
16
+ const inj = await getInj();
27
17
  const container = document.getElementById('react-view');
28
18
  if (!container) throw Error('Failed to find container for React app');
29
- const scene = (
30
- <GlobalStateProvider initialState={getInj().ISTATE ?? options.initialState}>
31
- <BrowserRouter>
32
- <HelmetProvider>
33
- <Application />
34
- </HelmetProvider>
35
- </BrowserRouter>
36
- </GlobalStateProvider>
37
- );
38
-
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
+ });
39
27
  if (options.dontHydrate) {
40
28
  const root = createRoot(container);
41
29
  root.render(scene);
42
30
  } else hydrateRoot(container, scene);
43
31
  }
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["createRoot","hydrateRoot","HelmetProvider","BrowserRouter","GlobalStateProvider","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 { HelmetProvider } from '@dr.pogodin/react-helmet';\nimport { BrowserRouter } from 'react-router';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\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;;AAGA,SAASA,UAAU,EAAEC,WAAW,QAAQ,kBAAkB;AAC1D,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,aAAa,QAAQ,cAAc;AAE5C,SAASC,mBAAmB,QAAQ,gCAAgC;AAEpE,OAAOC,MAAM;AAAiB,SAAAC,GAAA,IAAAC,IAAA;AAO9B;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAChCC,WAA0B,EAC1BC,OAAiB,GAAG,CAAC,CAAC,EACP;EACf,MAAMC,GAAG,GAAG,MAAMN,MAAM,CAAC,CAAC;EAE1B,MAAMO,SAAS,GAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC;EACvD,IAAI,CAACF,SAAS,EAAE,MAAMG,KAAK,CAAC,wCAAwC,CAAC;EACrE,MAAMC,KAAK,gBACTT,IAAA,CAACH,mBAAmB;IAACa,YAAY,EAAEN,GAAG,CAACO,MAAM,IAAIR,OAAO,CAACO,YAAa;IAAAE,QAAA,eACpEZ,IAAA,CAACJ,aAAa;MAAAgB,QAAA,eACZZ,IAAA,CAACL,cAAc;QAAAiB,QAAA,eACbZ,IAAA,CAACE,WAAW,IAAE;MAAC,CACD;IAAC,CACJ;EAAC,CACG,CACtB;EAED,IAAIC,OAAO,CAACU,WAAW,EAAE;IACvB,MAAMC,IAAI,GAAGrB,UAAU,CAACY,SAAS,CAAC;IAClCS,IAAI,CAACC,MAAM,CAACN,KAAK,CAAC;EACpB,CAAC,MAAMf,WAAW,CAACW,SAAS,EAAEI,KAAK,CAAC;AACtC","ignoreList":[]}
@@ -4,19 +4,10 @@
4
4
 
5
5
  /* global window */
6
6
 
7
- import { type BuildInfoT, getBuildInfo } from 'utils/isomorphy/buildInfo';
8
-
7
+ import { getBuildInfo } from "../shared/utils/isomorphy/buildInfo";
9
8
  const buildInfo = getBuildInfo();
10
9
 
11
10
  // TODO: Should be moved into buildInfo module?
12
- declare global {
13
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
14
- interface Window {
15
- __DEV_BUILD_INFO__: BuildInfoT | undefined;
16
- }
17
- }
18
-
19
- declare const BUILD_INFO: BuildInfoT | undefined;
20
11
 
21
12
  if (process.env.NODE_ENV !== 'production') {
22
13
  // eslint-disable-next-line no-console
@@ -27,9 +18,13 @@ if (process.env.NODE_ENV !== 'production') {
27
18
  }
28
19
 
29
20
  /* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */
30
- const { useServiceWorker } = buildInfo;
21
+ const {
22
+ useServiceWorker
23
+ } = buildInfo;
31
24
  if (useServiceWorker) {
32
- const { navigator } = window;
25
+ const {
26
+ navigator
27
+ } = window;
33
28
  if ('serviceWorker' in navigator) {
34
29
  window.addEventListener('load', () => {
35
30
  void (async () => {
@@ -38,8 +33,7 @@ if (useServiceWorker) {
38
33
  // from the web app root, to allow it control any and all pages of the
39
34
  // web app (otherwise, it will be restricted to the scope of its path).
40
35
  // The server takes it into account.
41
- const reg = await navigator
42
- .serviceWorker.register('/__service-worker.js');
36
+ const reg = await navigator.serviceWorker.register('/__service-worker.js');
43
37
  // eslint-disable-next-line no-console
44
38
  console.log('SW registered:', reg);
45
39
  } catch (err) {
@@ -50,3 +44,4 @@ if (useServiceWorker) {
50
44
  });
51
45
  }
52
46
  }
47
+ //# sourceMappingURL=init.js.map
@@ -0,0 +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;;AAEA;;AAEA,SAA0BA,YAAY;AAEtC,MAAMC,SAAS,GAAGD,YAAY,CAAC,CAAC;;AAEhC;;AAUA,IAAIE,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;EACzC;EACAC,OAAO,CAACC,IAAI,CAAC,wDAAwD,CAAC;;EAEtE;EACAC,MAAM,CAACC,kBAAkB,GAAGC,UAAU;AACxC;;AAEA;AACA,MAAM;EAAEC;AAAiB,CAAC,GAAGT,SAAS;AACtC,IAAIS,gBAAgB,EAAE;EACpB,MAAM;IAAEC;EAAU,CAAC,GAAGJ,MAAM;EAC5B,IAAI,eAAe,IAAII,SAAS,EAAE;IAChCJ,MAAM,CAACK,gBAAgB,CAAC,MAAM,EAAE,MAAM;MACpC,KAAK,CAAC,YAAY;QAChB,IAAI;UACF;UACA;UACA;UACA;UACA,MAAMC,GAAG,GAAG,MAAMF,SAAS,CACxBG,aAAa,CAACC,QAAQ,CAAC,sBAAsB,CAAC;UACjD;UACAV,OAAO,CAACW,GAAG,CAAC,gBAAgB,EAAEH,GAAG,CAAC;QACpC,CAAC,CAAC,OAAOI,GAAG,EAAE;UACZ;UACAZ,OAAO,CAACW,GAAG,CAAC,yBAAyB,EAAEC,GAAG,CAAC;QAC7C;MACF,CAAC,EAAE,CAAC;IACN,CAAC,CAAC;EACJ;AACF","ignoreList":[]}